text stringlengths 1 1.05M |
|---|
; A295890: a(n) = 1 if binary weights of n and 3n have different parity, 0 otherwise; a(n) = A010060(n) XOR A010060(3n).
; 0,1,1,0,1,0,0,0,1,0,0,1,0,1,0,0,1,0,0,1,0,1,1,1,0,1,1,1,0,1,0,0,1,0,0,1,0,1,1,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,1,1,0,1,0,0,1,0,0,1,0,1,1,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,0,0,1,0,0,0,1,0,1,1,0,1,1,0,1,0,0,0,1,0,0,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,1,1,0,1,0,0,1,0,0,1,0,1,1,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,0,0,1,0,0,0,1,0,1,1,0,1,1,0,1,0,0,0,1,0,0,1,0,1,0,0,1,0,0,1,0,1,0,0,1,0,0,0,1,0,1,1,0,1,1,0,1,0,0,0,1,0,0,1,0,1,0,0,1,0,0,1,0,1,0,0,1,0,0,0,1,0,1,1,0,1,1,0,1,0,0,0,1,0,0,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1
mov $1,$0
mul $0,2042
mul $1,4072
mov $2,2
lpb $1,1
div $0,$2
sub $1,$2
sub $1,$0
lpe
|
; A184119: Upper s(n)-Wythoff sequence, where s(n) = 2n - 1; complement of A136119.
; 2,6,9,12,16,19,23,26,30,33,36,40,43,47,50,53,57,60,64,67,70,74,77,81,84,88,91,94,98,101,105,108,111,115,118,122,125,129,132,135,139,142,146,149,152,156,159,163,166,170,173,176,180,183,187,190,193,197,200,204,207,210,214,217,221,224,228,231,234,238,241,245,248,251,255,258,262,265,269,272,275,279,282,286,289,292,296,299,303,306,309,313,316,320,323,327,330,333,337,340,344,347,350,354,357,361,364,368,371,374,378,381,385,388,391,395,398,402,405,408,412,415,419,422,426,429,432,436,439,443,446,449,453,456,460,463,467,470,473,477,480,484,487,490,494,497,501,504,508,511,514,518,521,525,528,531,535,538,542,545,548,552,555,559,562,566,569,572,576,579,583,586,589,593,596,600,603,607,610,613,617,620,624,627,630,634,637,641,644,647,651,654,658,661,665,668,671,675,678,682,685,688,692,695,699,702,706,709,712,716,719,723,726,729,733,736,740,743,747,750,753,757,760,764,767,770,774,777,781,784,787,791,794,798,801,805,808,811,815,818,822,825,828,832,835,839,842,846,849,852
mov $2,8
mov $4,$0
add $4,$0
add $4,1
mov $5,$0
mov $6,$0
mul $6,$0
lpb $2,1
add $0,$2
lpb $6,1
add $0,2
add $4,2
trn $6,$4
lpe
mov $2,1
lpe
add $0,5
mov $1,$0
sub $1,10
mov $3,$5
mul $3,5
add $1,$3
sub $1,3
div $1,2
add $1,2
|
GLOBAL _run_app
_run_app:
; Pulando para o endereços 0x2000
MOV EAX, 0x2000
;MOV EAX, 0x10AFB8
JMP EAX
global isr_config
isr_config:
;Configurando IRQ 0...15 [Reprogramando o PIC 8259A]
MOV AL,0x11
OUT 0xA0,AL
OUT 0x20,AL
;Configurando as IRQs 0x0...0x7 para 0x20...0x27
MOV AL,0x20
OUT 0x21,AL
;Configurando as IRQs 0x8...0x15 para 0x28...0x2F
MOV AL,0x28
OUT 0xA1,AL
MOV AL,0x4
OUT 0x21,AL
MOV AL,0x2
OUT 0xA1,AL
MOV AL,0x1
OUT 0x21,AL
OUT 0xA1,AL
;Notei que em alguns computadores as interrupções ficam desativadas. Limpando a porta 0x21
; e 0xA1 para ativar as interrupções.
XOR AL,AL
OUT 0x21,AL
OUT 0xA1,AL
STI
RET
GDT:
NULL EQU $ - GDT
DW 0,0
DB 0,0,0,0
REAL_CODE EQU $ - GDT ; 16bits Protected Mode "Real Mode"
DW 0xFFFF,0
DB 0,0x98,0x0F,0
REAL_DATA EQU $ - GDT ; 16bits Protected Mode "Real Mode"
DW 0xFFFF,0
DB 0,0x92,0x0F,0
KERNEL_CODE EQU $ - GDT ; 32bits Protected Mode "Kernel Ring0"
DW 0xFFFF,0
DB 0,0x9A,0xCF,0
KERNEL_DATA EQU $ - GDT ; 32bits Protected Mode "Kernel Ring0"
DW 0xFFFF,0
DB 0,0x92,0xCF,0
USER_CODE EQU $ - GDT ; 32bits Protected Mode "Users Ring0"
DW 0xFFFF,0
DB 0,0x98,0xCF,0
USER_DATA EQU $ - GDT ; 32bits Protected Mode "Users Ring0"
DW 0xFFFF,0
DB 0,0x92,0xCF,0
PGDT DW PGDT - GDT ; GDT SIZE
DD GDT ; GDT OFFSET
; Macro to configure the kernel mode;
global gdt_config
gdt_config:
; Load GDT
LGDT [PGDT]
; Enable 32bits protected mode
MOV EAX,KERNEL_DATA
MOV DS,EAX
MOV ES,EAX
MOV SS,EAX
MOV FS,EAX
MOV GS,EAX
;MOV ESP,_stack_top
JMP KERNEL_CODE: KERNEL_MODE
KERNEL_MODE:
RET
; ---------------------------------------------------------------------------*
; Copyright (C) 2015 Alisson Linhares de Carvalho. *
; All rights reserved. *
; *
; This file is part of the Native Kit. *
; *
; The Native Kit is free software: you can redistribute it and/or *
; modify it under the terms of the GNU Lesser General Public License as *
; published by the Free Software Foundation, either version 3 of the *
; License, or (at your option) any later version. *
; *
; The Native Kit is distributed in the hope that it will be useful, *
; but WITHOUT ANY WARRANTY; without even the implied warranty of *
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
; GNU Lesser General Public License for more details. *
; *
; You should have received a copy of the GNU Lesser General Public License *
; along with the Native Kit. If not, see <http://www.gnu.org/licenses/>. *
; ---------------------------------------------------------------------------*
MASTER_ISR_SIZE EQU isr.l33 - isr.l32
SLAVE_ISR_SIZE EQU isr.l41 - isr.l40
DEFAULT_ISR_SIZE EQU isr.l1 - isr.l0
[extern handler]
%macro interrupt 1
PUSHAD
PUSH DWORD ESP
PUSH DWORD %1
CALL handler
%if %1 >= 0x20
%if %1 <= 0x2F
MOV AL,0x20
%if %1 >= 0x28
OUT 0xA0,AL
%endif
OUT 0x20,AL
%endif
%endif
ADD ESP,8
POPAD
IRET
%endmacro
isr:
.l0 : interrupt 0x0
.l1 : interrupt 0x1
.l2 : interrupt 0x2
.l3 : interrupt 0x3
.l4 : interrupt 0x4
.l5 : interrupt 0x5
.l6 : interrupt 0x6
.l7 : interrupt 0x7
.l8 : interrupt 0x8
.l9 : interrupt 0x9
.l10 : interrupt 0xa
.l11 : interrupt 0xb
.l12 : interrupt 0xc
.l13 : interrupt 0xd
.l14 : interrupt 0xe
.l15 : interrupt 0xf
.l16 : interrupt 0x10
.l17 : interrupt 0x11
.l18 : interrupt 0x12
.l19 : interrupt 0x13
.l20 : interrupt 0x14
.l21 : interrupt 0x15
.l22 : interrupt 0x16
.l23 : interrupt 0x17
.l24 : interrupt 0x18
.l25 : interrupt 0x19
.l26 : interrupt 0x1a
.l27 : interrupt 0x1b
.l28 : interrupt 0x1c
.l29 : interrupt 0x1d
.l30 : interrupt 0x1e
.l31 : interrupt 0x1f
.master:
.l32 : interrupt 0x20
.l33 : interrupt 0x21
.l34 : interrupt 0x22
.l35 : interrupt 0x23
.l36 : interrupt 0x24
.l37 : interrupt 0x25
.l38 : interrupt 0x26
.l39 : interrupt 0x27
.slave:
.l40 : interrupt 0x28
.l41 : interrupt 0x29
.l42 : interrupt 0x2a
.l43 : interrupt 0x2b
.l44 : interrupt 0x2c
.l45 : interrupt 0x2d
.l46 : interrupt 0x2e
.l47 : interrupt 0x2f
.service:
.l48 : interrupt 0x30
.l49 : interrupt 0x31
.l50 : interrupt 0x32
.l51 : interrupt 0x33
.l52 : interrupt 0x34
.l53 : interrupt 0x35
.l54 : interrupt 0x36
.l55 : interrupt 0x37
.l56 : interrupt 0x38
.l57 : interrupt 0x39
.l58 : interrupt 0x3a
.l59 : interrupt 0x3b
.l60 : interrupt 0x3c
.l61 : interrupt 0x3d
.l62 : interrupt 0x3e
.l63 : interrupt 0x3f
.l64 : interrupt 0x40
.l65 : interrupt 0x41
.l66 : interrupt 0x42
.l67 : interrupt 0x43
.l68 : interrupt 0x44
.l69 : interrupt 0x45
.l70 : interrupt 0x46
.l71 : interrupt 0x47
.l72 : interrupt 0x48
.l73 : interrupt 0x49
.l74 : interrupt 0x4a
.l75 : interrupt 0x4b
.l76 : interrupt 0x4c
.l77 : interrupt 0x4d
.l78 : interrupt 0x4e
.l79 : interrupt 0x4f
.l80 : interrupt 0x50
.l81 : interrupt 0x51
.l82 : interrupt 0x52
.l83 : interrupt 0x53
.l84 : interrupt 0x54
.l85 : interrupt 0x55
.l86 : interrupt 0x56
.l87 : interrupt 0x57
.l88 : interrupt 0x58
.l89 : interrupt 0x59
.l90 : interrupt 0x5a
.l91 : interrupt 0x5b
.l92 : interrupt 0x5c
.l93 : interrupt 0x5d
.l94 : interrupt 0x5e
.l95 : interrupt 0x5f
.l96 : interrupt 0x60
.l97 : interrupt 0x61
.l98 : interrupt 0x62
.l99 : interrupt 0x63
.l100 : interrupt 0x64
.l101 : interrupt 0x65
.l102 : interrupt 0x66
.l103 : interrupt 0x67
.l104 : interrupt 0x68
.l105 : interrupt 0x69
.l106 : interrupt 0x6a
.l107 : interrupt 0x6b
.l108 : interrupt 0x6c
.l109 : interrupt 0x6d
.l110 : interrupt 0x6e
.l111 : interrupt 0x6f
.l112 : interrupt 0x70
.l113 : interrupt 0x71
.l114 : interrupt 0x72
.l115 : interrupt 0x73
.l116 : interrupt 0x74
.l117 : interrupt 0x75
.l118 : interrupt 0x76
.l119 : interrupt 0x77
.l120 : interrupt 0x78
.l121 : interrupt 0x79
.l122 : interrupt 0x7a
.l123 : interrupt 0x7b
.l124 : interrupt 0x7c
.l125 : interrupt 0x7d
.l126 : interrupt 0x7e
.l127 : interrupt 0x7f
.l128 : interrupt 0x80
.l129 : interrupt 0x81
.l130 : interrupt 0x82
.l131 : interrupt 0x83
.l132 : interrupt 0x84
.l133 : interrupt 0x85
.l134 : interrupt 0x86
.l135 : interrupt 0x87
.l136 : interrupt 0x88
.l137 : interrupt 0x89
.l138 : interrupt 0x8a
.l139 : interrupt 0x8b
.l140 : interrupt 0x8c
.l141 : interrupt 0x8d
.l142 : interrupt 0x8e
.l143 : interrupt 0x8f
.l144 : interrupt 0x90
.l145 : interrupt 0x91
.l146 : interrupt 0x92
.l147 : interrupt 0x93
.l148 : interrupt 0x94
.l149 : interrupt 0x95
.l150 : interrupt 0x96
.l151 : interrupt 0x97
.l152 : interrupt 0x98
.l153 : interrupt 0x99
.l154 : interrupt 0x9a
.l155 : interrupt 0x9b
.l156 : interrupt 0x9c
.l157 : interrupt 0x9d
.l158 : interrupt 0x9e
.l159 : interrupt 0x9f
.l160 : interrupt 0xa0
.l161 : interrupt 0xa1
.l162 : interrupt 0xa2
.l163 : interrupt 0xa3
.l164 : interrupt 0xa4
.l165 : interrupt 0xa5
.l166 : interrupt 0xa6
.l167 : interrupt 0xa7
.l168 : interrupt 0xa8
.l169 : interrupt 0xa9
.l170 : interrupt 0xaa
.l171 : interrupt 0xab
.l172 : interrupt 0xac
.l173 : interrupt 0xad
.l174 : interrupt 0xae
.l175 : interrupt 0xaf
.l176 : interrupt 0xb0
.l177 : interrupt 0xb1
.l178 : interrupt 0xb2
.l179 : interrupt 0xb3
.l180 : interrupt 0xb4
.l181 : interrupt 0xb5
.l182 : interrupt 0xb6
.l183 : interrupt 0xb7
.l184 : interrupt 0xb8
.l185 : interrupt 0xb9
.l186 : interrupt 0xba
.l187 : interrupt 0xbb
.l188 : interrupt 0xbc
.l189 : interrupt 0xbd
.l190 : interrupt 0xbe
.l191 : interrupt 0xbf
.l192 : interrupt 0xc0
.l193 : interrupt 0xc1
.l194 : interrupt 0xc2
.l195 : interrupt 0xc3
.l196 : interrupt 0xc4
.l197 : interrupt 0xc5
.l198 : interrupt 0xc6
.l199 : interrupt 0xc7
.l200 : interrupt 0xc8
.l201 : interrupt 0xc9
.l202 : interrupt 0xca
.l203 : interrupt 0xcb
.l204 : interrupt 0xcc
.l205 : interrupt 0xcd
.l206 : interrupt 0xce
.l207 : interrupt 0xcf
.l208 : interrupt 0xd0
.l209 : interrupt 0xd1
.l210 : interrupt 0xd2
.l211 : interrupt 0xd3
.l212 : interrupt 0xd4
.l213 : interrupt 0xd5
.l214 : interrupt 0xd6
.l215 : interrupt 0xd7
.l216 : interrupt 0xd8
.l217 : interrupt 0xd9
.l218 : interrupt 0xda
.l219 : interrupt 0xdb
.l220 : interrupt 0xdc
.l221 : interrupt 0xdd
.l222 : interrupt 0xde
.l223 : interrupt 0xdf
.l224 : interrupt 0xe0
.l225 : interrupt 0xe1
.l226 : interrupt 0xe2
.l227 : interrupt 0xe3
.l228 : interrupt 0xe4
.l229 : interrupt 0xe5
.l230 : interrupt 0xe6
.l231 : interrupt 0xe7
.l232 : interrupt 0xe8
.l233 : interrupt 0xe9
.l234 : interrupt 0xea
.l235 : interrupt 0xeb
.l236 : interrupt 0xec
.l237 : interrupt 0xed
.l238 : interrupt 0xee
.l239 : interrupt 0xef
.l240 : interrupt 0xf0
.l241 : interrupt 0xf1
.l242 : interrupt 0xf2
.l243 : interrupt 0xf3
.l244 : interrupt 0xf4
.l245 : interrupt 0xf5
.l246 : interrupt 0xf6
.l247 : interrupt 0xf7
.l248 : interrupt 0xf8
.l249 : interrupt 0xf9
.l250 : interrupt 0xfa
.l251 : interrupt 0xfb
.l252 : interrupt 0xfc
.l253 : interrupt 0xfd
.l254 : interrupt 0xfe
.l255 : interrupt 0xff
.end:
; ---------------------------------------------------------------------------*
; Copyright (C) 2015 Alisson Linhares de Carvalho. *
; All rights reserved. *
; *
; This file is part of the Native Kit. *
; *
; The Native Kit is free software: you can redistribute it and/or *
; modify it under the terms of the GNU Lesser General Public License as *
; published by the Free Software Foundation, either version 3 of the *
; License, or (at your option) any later version. *
; *
; The Native Kit is distributed in the hope that it will be useful, *
; but WITHOUT ANY WARRANTY; without even the implied warranty of *
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
; GNU Lesser General Public License for more details. *
; *
; You should have received a copy of the GNU Lesser General Public License *
; along with the Native Kit. If not, see <http://www.gnu.org/licenses/>. *
; ---------------------------------------------------------------------------*
IDT:
DW 0,KERNEL_CODE,0x8F00,0 ;Divide error
DW 0,KERNEL_CODE,0x8F00,0 ;Debug exceptions
DW 0,KERNEL_CODE,0x8F00,0 ;Nonmaskable interrupt exception
DW 0,KERNEL_CODE,0x8F00,0 ;Breakpoint exception
DW 0,KERNEL_CODE,0x8F00,0 ;Overflow exception
DW 0,KERNEL_CODE,0x8F00,0 ;Bounds check exception
DW 0,KERNEL_CODE,0x8F00,0 ;Invalid opcode exception
DW 0,KERNEL_CODE,0x8F00,0 ;Coprocessor not available exception
DW 0,KERNEL_CODE,0x8F00,0 ;Double fault exception
DW 0,KERNEL_CODE,0x8F00,0 ;Coprocessor segment overrun exception
DW 0,KERNEL_CODE,0x8F00,0 ;Invalid TSS exception
DW 0,KERNEL_CODE,0x8F00,0 ;Segment not present
DW 0,KERNEL_CODE,0x8F00,0 ;Stack exception
DW 0,KERNEL_CODE,0x8F00,0 ;General protection exception
DW 0,KERNEL_CODE,0x8F00,0 ;Page fault exception
DW 0,KERNEL_CODE,0x8F00,0 ;Intel reserved
DW 0,KERNEL_CODE,0x8F00,0 ;Coprocessor error
DW 0,KERNEL_CODE,0x8F00,0 ;Intel reserved
DW 0,KERNEL_CODE,0x8F00,0 ;Intel reserved
DW 0,KERNEL_CODE,0x8F00,0 ;Intel reserved
DW 0,KERNEL_CODE,0x8F00,0 ;Intel reserved
DW 0,KERNEL_CODE,0x8F00,0 ;Intel reserved
DW 0,KERNEL_CODE,0x8F00,0 ;Intel reserved
DW 0,KERNEL_CODE,0x8F00,0 ;Intel reserved
DW 0,KERNEL_CODE,0x8F00,0 ;Intel reserved
DW 0,KERNEL_CODE,0x8F00,0 ;Intel reserved
DW 0,KERNEL_CODE,0x8F00,0 ;Intel reserved
DW 0,KERNEL_CODE,0x8F00,0 ;Intel reserved
DW 0,KERNEL_CODE,0x8F00,0 ;Intel reserved
DW 0,KERNEL_CODE,0x8F00,0 ;Intel reserved
DW 0,KERNEL_CODE,0x8F00,0 ;Intel reserved
DW 0,KERNEL_CODE,0x8F00,0 ;Intel reserved
DW 0,KERNEL_CODE,0x8F00,0 ;System Timer
DW 0,KERNEL_CODE,0x8F00,0 ;Keyboard
DW 0,KERNEL_CODE,0x8F00,0 ;Intel reserved
DW 0,KERNEL_CODE,0x8F00,0 ;COM2
DW 0,KERNEL_CODE,0x8F00,0 ;COM1
DW 0,KERNEL_CODE,0x8F00,0 ;LPT2
DW 0,KERNEL_CODE,0x8F00,0 ;Floppy disk drive
DW 0,KERNEL_CODE,0x8F00,0 ;LPT1
DW 0,KERNEL_CODE,0x8F00,0 ;CMOS Real Time Clock
DW 0,KERNEL_CODE,0x8F00,0 ;Intel reserved
DW 0,KERNEL_CODE,0x8F00,0 ;Intel reserved
DW 0,KERNEL_CODE,0x8F00,0 ;Intel reserved
DW 0,KERNEL_CODE,0x8F00,0 ;PS/2 Mouse
DW 0,KERNEL_CODE,0x8F00,0 ;Numeric coprocessor
DW 0,KERNEL_CODE,0x8F00,0 ;Hard disk drive IDE1
DW 0,KERNEL_CODE,0x8F00,0 ;Hard disk drive IDE2
DW 0,KERNEL_CODE,0x8E00,0 ;Neutrino System Calls
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Linux syscalls
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
DW 0,KERNEL_CODE,0x8E00,0 ;Reserved
PIDT DW PIDT - IDT
DD IDT
global idt_config
idt_config:
MOV EDI, IDT
MOV ESI, isr.l0
loop:
MOV EAX,ESI
MOV WORD[EDI ],AX
SHR EAX,16
MOV WORD[EDI + 6],AX
ADD EDI,8
CMP ESI,isr.master
JB defautMap
CMP ESI,isr.slave
JB masterPicMap
CMP ESI,isr.service
JAE defautMap
slavePicMap:
ADD ESI,SLAVE_ISR_SIZE
JMP continue
masterPicMap:
ADD ESI,MASTER_ISR_SIZE
JMP continue
defautMap:
ADD ESI,DEFAULT_ISR_SIZE
continue:
CMP EDI, PIDT
JB loop
LIDT [PIDT]
RET
|
// Copyright 2009 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/log-utils.h"
#include "src/assert-scope.h"
#include "src/base/platform/platform.h"
#include "src/objects-inl.h"
#include "src/string-stream.h"
#include "src/utils.h"
#include "src/version.h"
namespace v8 {
namespace internal {
const char* const Log::kLogToTemporaryFile = "&";
const char* const Log::kLogToConsole = "-";
Log::Log(Logger* logger)
: is_stopped_(false),
output_handle_(NULL),
message_buffer_(NULL),
logger_(logger) {
}
void Log::Initialize(const char* log_file_name) {
message_buffer_ = NewArray<char>(kMessageBufferSize);
// --log-all enables all the log flags.
if (FLAG_log_all) {
FLAG_log_api = true;
FLAG_log_code = true;
FLAG_log_gc = true;
FLAG_log_suspect = true;
FLAG_log_handles = true;
FLAG_log_regexp = true;
FLAG_log_internal_timer_events = true;
}
// --prof implies --log-code.
if (FLAG_prof) FLAG_log_code = true;
// If we're logging anything, we need to open the log file.
if (Log::InitLogAtStart()) {
if (strcmp(log_file_name, kLogToConsole) == 0) {
OpenStdout();
} else if (strcmp(log_file_name, kLogToTemporaryFile) == 0) {
OpenTemporaryFile();
} else {
OpenFile(log_file_name);
}
if (output_handle_ != nullptr) {
Log::MessageBuilder msg(this);
msg.Append("v8-version,%d,%d,%d,%d,%d", Version::GetMajor(),
Version::GetMinor(), Version::GetBuild(), Version::GetPatch(),
Version::IsCandidate());
msg.WriteToLogFile();
}
}
}
void Log::OpenStdout() {
DCHECK(!IsEnabled());
output_handle_ = stdout;
}
void Log::OpenTemporaryFile() {
DCHECK(!IsEnabled());
output_handle_ = base::OS::OpenTemporaryFile();
}
void Log::OpenFile(const char* name) {
DCHECK(!IsEnabled());
output_handle_ = base::OS::FOpen(name, base::OS::LogFileOpenMode);
}
FILE* Log::Close() {
FILE* result = NULL;
if (output_handle_ != NULL) {
if (strcmp(FLAG_logfile, kLogToTemporaryFile) != 0) {
fclose(output_handle_);
} else {
result = output_handle_;
}
}
output_handle_ = NULL;
DeleteArray(message_buffer_);
message_buffer_ = NULL;
is_stopped_ = false;
return result;
}
Log::MessageBuilder::MessageBuilder(Log* log)
: log_(log),
lock_guard_(&log_->mutex_),
pos_(0) {
DCHECK(log_->message_buffer_ != NULL);
}
void Log::MessageBuilder::Append(const char* format, ...) {
Vector<char> buf(log_->message_buffer_ + pos_,
Log::kMessageBufferSize - pos_);
va_list args;
va_start(args, format);
AppendVA(format, args);
va_end(args);
DCHECK(pos_ <= Log::kMessageBufferSize);
}
void Log::MessageBuilder::AppendVA(const char* format, va_list args) {
Vector<char> buf(log_->message_buffer_ + pos_,
Log::kMessageBufferSize - pos_);
int result = v8::internal::VSNPrintF(buf, format, args);
// Result is -1 if output was truncated.
if (result >= 0) {
pos_ += result;
} else {
pos_ = Log::kMessageBufferSize;
}
DCHECK(pos_ <= Log::kMessageBufferSize);
}
void Log::MessageBuilder::Append(const char c) {
if (pos_ < Log::kMessageBufferSize) {
log_->message_buffer_[pos_++] = c;
}
DCHECK(pos_ <= Log::kMessageBufferSize);
}
void Log::MessageBuilder::AppendDoubleQuotedString(const char* string) {
Append('"');
for (const char* p = string; *p != '\0'; p++) {
if (*p == '"') {
Append('\\');
}
Append(*p);
}
Append('"');
}
void Log::MessageBuilder::Append(String* str) {
DisallowHeapAllocation no_gc; // Ensure string stay valid.
int length = str->length();
for (int i = 0; i < length; i++) {
Append(static_cast<char>(str->Get(i)));
}
}
void Log::MessageBuilder::AppendAddress(Address addr) {
Append("0x%" V8PRIxPTR, addr);
}
void Log::MessageBuilder::AppendSymbolName(Symbol* symbol) {
DCHECK(symbol);
Append("symbol(");
if (!symbol->name()->IsUndefined()) {
Append("\"");
AppendDetailed(String::cast(symbol->name()), false);
Append("\" ");
}
Append("hash %x)", symbol->Hash());
}
void Log::MessageBuilder::AppendDetailed(String* str, bool show_impl_info) {
if (str == NULL) return;
DisallowHeapAllocation no_gc; // Ensure string stay valid.
int len = str->length();
if (len > 0x1000)
len = 0x1000;
if (show_impl_info) {
Append(str->IsOneByteRepresentation() ? 'a' : '2');
if (StringShape(str).IsExternal())
Append('e');
if (StringShape(str).IsInternalized())
Append('#');
Append(":%i:", str->length());
}
for (int i = 0; i < len; i++) {
uc32 c = str->Get(i);
if (c > 0xff) {
Append("\\u%04x", c);
} else if (c < 32 || c > 126) {
Append("\\x%02x", c);
} else if (c == ',') {
Append("\\,");
} else if (c == '\\') {
Append("\\\\");
} else if (c == '\"') {
Append("\"\"");
} else {
Append("%lc", c);
}
}
}
void Log::MessageBuilder::AppendStringPart(const char* str, int len) {
if (pos_ + len > Log::kMessageBufferSize) {
len = Log::kMessageBufferSize - pos_;
DCHECK(len >= 0);
if (len == 0) return;
}
Vector<char> buf(log_->message_buffer_ + pos_,
Log::kMessageBufferSize - pos_);
StrNCpy(buf, str, len);
pos_ += len;
DCHECK(pos_ <= Log::kMessageBufferSize);
}
void Log::MessageBuilder::WriteToLogFile() {
DCHECK(pos_ <= Log::kMessageBufferSize);
// Assert that we do not already have a new line at the end.
DCHECK(pos_ == 0 || log_->message_buffer_[pos_ - 1] != '\n');
if (pos_ == Log::kMessageBufferSize) pos_--;
log_->message_buffer_[pos_++] = '\n';
const int written = log_->WriteToFile(log_->message_buffer_, pos_);
if (written != pos_) {
log_->stop();
log_->logger_->LogFailure();
}
}
} // namespace internal
} // namespace v8
|
// -*- C++ -*-
//
// Package: ElectronProducers
// Class: ElectronSeedProducer
//
/**\class ElectronSeedProducer RecoEgamma/ElectronProducers/src/ElectronSeedProducer.cc
Description: EDProducer of ElectronSeed objects
Implementation:
<Notes on implementation>
*/
//
// Original Author: Ursula Berthon, Claude Charlot
// Created: Mon Mar 27 13:22:06 CEST 2006
//
//
#include <vector>
#include "ElectronSeedProducer.h"
#include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaHcalIsolation.h"
#include "RecoEgamma/EgammaElectronAlgos/interface/ElectronSeedGenerator.h"
#include "RecoEgamma/EgammaElectronAlgos/interface/ElectronHcalHelper.h"
#include "RecoEgamma/EgammaElectronAlgos/interface/SeedFilter.h"
#include "RecoEgamma/EgammaElectronAlgos/interface/ElectronUtilities.h"
#include "RecoTracker/MeasurementDet/interface/MeasurementTrackerEvent.h"
#include "Geometry/Records/interface/CaloGeometryRecord.h"
#include "Geometry/Records/interface/CaloTopologyRecord.h"
#include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
#include "RecoCaloTools/Selectors/interface/CaloConeSelector.h"
#include "DataFormats/EgammaReco/interface/ElectronSeed.h"
#include "DataFormats/EgammaReco/interface/ElectronSeedFwd.h"
#include "DataFormats/EcalDetId/interface/EBDetId.h"
#include "DataFormats/EcalDetId/interface/EEDetId.h"
#include "DataFormats/ForwardDetId/interface/ForwardSubdetector.h"
#include "DataFormats/ForwardDetId/interface/HGCalDetId.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/isFinite.h"
#include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
#include "RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h"
#include <string>
using namespace reco ;
ElectronSeedProducer::ElectronSeedProducer( const edm::ParameterSet& iConfig )
: //conf_(iConfig),
applyHOverECut_(true), hcalHelper_(0),
caloGeom_(0), caloGeomCacheId_(0), caloTopo_(0), caloTopoCacheId_(0)
{
conf_ = iConfig.getParameter<edm::ParameterSet>("SeedConfiguration") ;
initialSeeds_ = consumes<TrajectorySeedCollection>(conf_.getParameter<edm::InputTag>("initialSeeds")) ;
SCEtCut_ = conf_.getParameter<double>("SCEtCut");
fromTrackerSeeds_ = conf_.getParameter<bool>("fromTrackerSeeds") ;
prefilteredSeeds_ = conf_.getParameter<bool>("preFilteredSeeds") ;
auto theconsumes = consumesCollector();
// new beamSpot tag
beamSpotTag_ = consumes<reco::BeamSpot>(conf_.getParameter<edm::InputTag>("beamSpot"));
// for H/E
applyHOverECut_ = conf_.getParameter<bool>("applyHOverECut") ;
if (applyHOverECut_)
{
ElectronHcalHelper::Configuration hcalCfg ;
hcalCfg.hOverEConeSize = conf_.getParameter<double>("hOverEConeSize") ;
if (hcalCfg.hOverEConeSize>0)
{
hcalCfg.useTowers = true ;
hcalCfg.hcalTowers =
consumes<CaloTowerCollection>(conf_.getParameter<edm::InputTag>("hcalTowers")) ;
hcalCfg.hOverEPtMin = conf_.getParameter<double>("hOverEPtMin") ;
}
hcalHelper_ = new ElectronHcalHelper(hcalCfg) ;
allowHGCal_ = conf_.getParameter<bool>("allowHGCal");
if( allowHGCal_ ) {
const edm::ParameterSet& hgcCfg = conf_.getParameterSet("HGCalConfig");
hgcClusterTools_.reset( new hgcal::ClusterTools(hgcCfg, theconsumes) );
}
maxHOverEBarrel_=conf_.getParameter<double>("maxHOverEBarrel") ;
maxHOverEEndcaps_=conf_.getParameter<double>("maxHOverEEndcaps") ;
maxHBarrel_=conf_.getParameter<double>("maxHBarrel") ;
maxHEndcaps_=conf_.getParameter<double>("maxHEndcaps") ;
}
applySigmaIEtaIEtaCut_ = conf_.getParameter<bool>("applySigmaIEtaIEtaCut");
// apply sigma_ieta_ieta cut
if (applySigmaIEtaIEtaCut_ == true)
{
maxSigmaIEtaIEtaBarrel_ = conf_.getParameter<double>("maxSigmaIEtaIEtaBarrel");
maxSigmaIEtaIEtaEndcaps_ = conf_.getParameter<double>("maxSigmaIEtaIEtaEndcaps");
}
edm::ParameterSet rpset = conf_.getParameter<edm::ParameterSet>("RegionPSet");
filterVtxTag_ = consumes<std::vector<reco::Vertex> >(rpset.getParameter<edm::InputTag> ("VertexProducer"));
ElectronSeedGenerator::Tokens esg_tokens;
esg_tokens.token_bs = beamSpotTag_;
esg_tokens.token_vtx = mayConsume<reco::VertexCollection>(conf_.getParameter<edm::InputTag>("vertices"));
esg_tokens.token_measTrkEvt= consumes<MeasurementTrackerEvent>(conf_.getParameter<edm::InputTag>("measurementTrackerEvent"));
matcher_ = new ElectronSeedGenerator(conf_,esg_tokens) ;
// get collections from config
if (applySigmaIEtaIEtaCut_ == true) {
ebRecHitCollection_ = consumes<EcalRecHitCollection> (iConfig.getParameter<edm::InputTag>("ebRecHitCollection"));
eeRecHitCollection_ = consumes<EcalRecHitCollection> (iConfig.getParameter<edm::InputTag>("eeRecHitCollection"));
}
superClusters_[0]=
consumes<reco::SuperClusterCollection>(iConfig.getParameter<edm::InputTag>("barrelSuperClusters")) ;
superClusters_[1]=
consumes<reco::SuperClusterCollection>(iConfig.getParameter<edm::InputTag>("endcapSuperClusters")) ;
// Construction of SeedFilter was in beginRun() with the comment
// below, but it has to be done here because of ConsumesCollector
//
// FIXME: because of a bug presumably in tracker seeding,
// perhaps in CombinedHitPairGenerator, badly caching some EventSetup product,
// we must redo the SeedFilter for each run.
if (prefilteredSeeds_) {
SeedFilter::Tokens sf_tokens;
sf_tokens.token_bs = beamSpotTag_;
sf_tokens.token_vtx = filterVtxTag_;
edm::ConsumesCollector iC = consumesCollector();
seedFilter_.reset(new SeedFilter(conf_, sf_tokens, iC));
}
//register your products
produces<ElectronSeedCollection>() ;
}
void ElectronSeedProducer::beginRun(edm::Run const&, edm::EventSetup const&)
{}
void ElectronSeedProducer::endRun(edm::Run const&, edm::EventSetup const&)
{}
ElectronSeedProducer::~ElectronSeedProducer()
{
delete hcalHelper_ ;
delete matcher_ ;
}
void ElectronSeedProducer::produce(edm::Event& e, const edm::EventSetup& iSetup)
{
LogDebug("ElectronSeedProducer") <<"[ElectronSeedProducer::produce] entering " ;
edm::Handle<reco::BeamSpot> theBeamSpot ;
e.getByToken(beamSpotTag_,theBeamSpot) ;
if (hcalHelper_)
{
hcalHelper_->checkSetup(iSetup) ;
hcalHelper_->readEvent(e) ;
if( allowHGCal_ ) {
hgcClusterTools_->getEventSetup(iSetup);
hgcClusterTools_->getEvent(e);
}
}
// get calo geometry
if (caloGeomCacheId_!=iSetup.get<CaloGeometryRecord>().cacheIdentifier()) {
iSetup.get<CaloGeometryRecord>().get(caloGeom_);
caloGeomCacheId_=iSetup.get<CaloGeometryRecord>().cacheIdentifier();
}
if (caloTopoCacheId_!=iSetup.get<CaloTopologyRecord>().cacheIdentifier()){
caloTopoCacheId_=iSetup.get<CaloTopologyRecord>().cacheIdentifier();
iSetup.get<CaloTopologyRecord>().get(caloTopo_);
}
matcher_->setupES(iSetup);
// get initial TrajectorySeeds if necessary
if (fromTrackerSeeds_)
{
if (!prefilteredSeeds_)
{
edm::Handle<TrajectorySeedCollection> hSeeds;
e.getByToken(initialSeeds_, hSeeds);
theInitialSeedColl = const_cast<TrajectorySeedCollection *> (hSeeds.product());
}
else
{ theInitialSeedColl = new TrajectorySeedCollection ; }
}
else
{ theInitialSeedColl = 0 ; } // not needed in this case
ElectronSeedCollection * seeds = new ElectronSeedCollection ;
// loop over barrel + endcap
for (unsigned int i=0; i<2; i++) {
edm::Handle<SuperClusterCollection> clusters ;
e.getByToken(superClusters_[i],clusters);
SuperClusterRefVector clusterRefs ;
std::vector<float> hoe1s, hoe2s ;
filterClusters(*theBeamSpot,clusters,/*mhbhe_,*/clusterRefs,hoe1s,hoe2s,e, iSetup);
if ((fromTrackerSeeds_) && (prefilteredSeeds_))
{ filterSeeds(e,iSetup,clusterRefs) ; }
matcher_->run(e,iSetup,clusterRefs,hoe1s,hoe2s,theInitialSeedColl,*seeds);
}
// store the accumulated result
std::unique_ptr<ElectronSeedCollection> pSeeds(seeds);
ElectronSeedCollection::iterator is ;
for ( is=pSeeds->begin() ; is!=pSeeds->end() ; is++ ) {
edm::RefToBase<CaloCluster> caloCluster = is->caloCluster() ;
SuperClusterRef superCluster = caloCluster.castTo<SuperClusterRef>() ;
LogDebug("ElectronSeedProducer")
<< "new seed with "
<< (*is).nHits() << " hits"
<< ", charge " << (*is).getCharge()
<< " and cluster energy " << superCluster->energy()
<< " PID "<<superCluster.id() ;
}
e.put(std::move(pSeeds));
if (fromTrackerSeeds_ && prefilteredSeeds_) delete theInitialSeedColl;
}
//===============================
// Filter the superclusters
// - with EtCut
// - with HoE using calo cone
//===============================
void ElectronSeedProducer::filterClusters
( const reco::BeamSpot & bs,
const edm::Handle<reco::SuperClusterCollection> & superClusters,
SuperClusterRefVector & sclRefs,
std::vector<float> & hoe1s, std::vector<float> & hoe2s,
edm::Event & event, const edm::EventSetup & setup)
{
std::vector<float> sigmaIEtaIEtaEB_;
std::vector<float> sigmaIEtaIEtaEE_;
for (unsigned int i=0;i<superClusters->size();++i)
{
const SuperCluster & scl = (*superClusters)[i] ;
double sclEta = EleRelPoint(scl.position(),bs.position()).eta() ;
if (scl.energy()/cosh(sclEta)>SCEtCut_)
{
// if ((applyHOverECut_==true)&&((hcalHelper_->hcalESum(scl)/scl.energy()) > maxHOverE_))
// { continue ; }
// sclRefs.push_back(edm::Ref<reco::SuperClusterCollection>(superClusters,i)) ;
double had1, had2, had, scle ;
bool HoeVeto = false ;
if (applyHOverECut_==true)
{
had1 = hcalHelper_->hcalESumDepth1(scl);
had2 = hcalHelper_->hcalESumDepth2(scl);
had = had1+had2 ;
scle = scl.energy() ;
int det_group = scl.seed()->hitsAndFractions()[0].first.det() ;
int detector = scl.seed()->hitsAndFractions()[0].first.subdetId() ;
if (detector==EcalBarrel && (had<maxHBarrel_ || had/scle<maxHOverEBarrel_)) HoeVeto=true;
else if( detector==EcalEndcap && (had<maxHEndcaps_ || had/scle<maxHOverEEndcaps_) ) HoeVeto=true;
else if( allowHGCal_ && (detector==HcalEndcap || det_group == DetId::Forward) ) {
float had_fraction = hgcClusterTools_->getClusterHadronFraction(*(scl.seed()));
had1 = had_fraction*scl.seed()->energy();
had2 = 0.;
HoeVeto= ( had_fraction >= 0.f && had_fraction < maxHOverEEndcaps_ );
}
if (HoeVeto)
{
sclRefs.push_back(edm::Ref<reco::SuperClusterCollection>(superClusters,i)) ;
hoe1s.push_back(had1/scle) ;
hoe2s.push_back(had2/scle) ;
}
}
else
{
sclRefs.push_back(edm::Ref<reco::SuperClusterCollection>(superClusters,i)) ;
hoe1s.push_back(std::numeric_limits<float>::infinity()) ;
hoe2s.push_back(std::numeric_limits<float>::infinity()) ;
}
}
if (applySigmaIEtaIEtaCut_ == true)
{
noZS::EcalClusterLazyTools lazyTool_noZS(event, setup, ebRecHitCollection_, eeRecHitCollection_);
std::vector<float> vCov = lazyTool_noZS.localCovariances(*(scl.seed()));
int detector = scl.seed()->hitsAndFractions()[0].first.subdetId() ;
if (detector==EcalBarrel) sigmaIEtaIEtaEB_ .push_back(edm::isNotFinite(vCov[0]) ? 0. : sqrt(vCov[0]));
if (detector==EcalEndcap) sigmaIEtaIEtaEE_ .push_back(edm::isNotFinite(vCov[0]) ? 0. : sqrt(vCov[0]));
}
}
LogDebug("ElectronSeedProducer")<<"Filtered out "<<sclRefs.size()<<" superclusters from "<<superClusters->size() ;
}
void ElectronSeedProducer::filterSeeds
( edm::Event & event, const edm::EventSetup & setup,
reco::SuperClusterRefVector & sclRefs )
{
for ( unsigned int i=0 ; i<sclRefs.size() ; ++i )
{
seedFilter_->seeds(event,setup,sclRefs[i],theInitialSeedColl) ;
LogDebug("ElectronSeedProducer")<<"Number of Seeds: "<<theInitialSeedColl->size() ;
}
}
void
ElectronSeedProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("endcapSuperClusters",edm::InputTag("particleFlowSuperClusterECAL","particleFlowSuperClusterECALEndcapWithPreshower"));
{
edm::ParameterSetDescription psd0, psd1, psd2, psd3, psd4;
psd1.add<unsigned int>("maxElement", 0);
psd1.add<std::string>("ComponentName", std::string("StandardHitPairGenerator"));
psd1.addUntracked<int>("useOnDemandTracker", 0);
psd1.add<edm::InputTag>("SeedingLayers", edm::InputTag("hltMixedLayerPairs"));
psd0.add<edm::ParameterSetDescription>("OrderedHitsFactoryPSet", psd1);
psd2.add<double>("deltaPhiRegion", 0.4);
psd2.add<double>("originHalfLength", 15.0);
psd2.add<bool>("useZInVertex", true);
psd2.add<double>("deltaEtaRegion", 0.1);
psd2.add<double>("ptMin", 1.5 );
psd2.add<double>("originRadius", 0.2);
psd2.add<edm::InputTag>("VertexProducer", edm::InputTag("dummyVertices"));
psd0.add<edm::ParameterSetDescription>("RegionPSet", psd2);
psd0.add<double>("PhiMax2B",0.002);
psd0.add<double>("hOverEPtMin",0.0);
psd0.add<double>("PhiMax2F",0.003);
psd0.add<bool>("searchInTIDTEC",true);
psd0.add<double>("pPhiMax1",0.125);
psd0.add<double>("HighPtThreshold",35.0);
psd0.add<double>("r2MinF",-0.15);
psd0.add<double>("maxHBarrel",0.0);
psd0.add<double>("DeltaPhi1Low",0.23);
psd0.add<double>("DeltaPhi1High",0.08);
psd0.add<double>("ePhiMin1",-0.125);
psd0.add<edm::InputTag>("hcalTowers",edm::InputTag("towerMaker"));
psd0.add<double>("LowPtThreshold",5.0);
psd0.add<double>("maxHOverEBarrel",0.15);
psd0.add<double>("maxSigmaIEtaIEtaBarrel", 0.5);
psd0.add<double>("maxSigmaIEtaIEtaEndcaps", 0.5);
psd0.add<bool>("dynamicPhiRoad",true);
psd0.add<double>("ePhiMax1",0.075);
psd0.add<std::string>("measurementTrackerName","");
psd0.add<double>("SizeWindowENeg",0.675);
psd0.add<double>("nSigmasDeltaZ1",5.0);
psd0.add<double>("rMaxI",0.2);
psd0.add<double>("maxHEndcaps",0.0);
psd0.add<bool>("preFilteredSeeds",false);
psd0.add<double>("r2MaxF",0.15);
psd0.add<double>("hOverEConeSize",0.15);
psd0.add<double>("pPhiMin1",-0.075);
psd0.add<edm::InputTag>("initialSeeds",edm::InputTag("newCombinedSeeds"));
psd0.add<double>("deltaZ1WithVertex",25.0);
psd0.add<double>("SCEtCut",0.0);
psd0.add<double>("z2MaxB",0.09);
psd0.add<bool>("fromTrackerSeeds",true);
psd0.add<edm::InputTag>("hcalRecHits",edm::InputTag("hbhereco"));
psd0.add<double>("z2MinB",-0.09);
psd0.add<double>("rMinI",-0.2);
psd0.add<double>("maxHOverEEndcaps",0.15);
psd0.add<double>("hOverEHBMinE",0.7);
psd0.add<bool>("useRecoVertex",false);
psd0.add<edm::InputTag>("beamSpot",edm::InputTag("offlineBeamSpot"));
psd0.add<edm::InputTag>("measurementTrackerEvent",edm::InputTag("MeasurementTrackerEvent"));
psd0.add<edm::InputTag>("vertices",edm::InputTag("offlinePrimaryVerticesWithBS"));
psd0.add<bool>("applyHOverECut",true);
psd0.add<edm::InputTag>("ebRecHitCollection", edm::InputTag("ecalRecHit", "EcalRecHitsEB"));
psd0.add<edm::InputTag>("eeRecHitCollection", edm::InputTag("ecalRecHit", "EcalRecHitsEE"));
psd0.add<bool>("applySigmaIEtaIEtaCut", false);
psd0.add<double>("DeltaPhi2F",0.012);
psd0.add<double>("PhiMin2F",-0.003);
psd0.add<double>("hOverEHFMinE",0.8);
psd0.add<double>("DeltaPhi2B",0.008);
psd0.add<double>("PhiMin2B",-0.002);
psd0.add<bool>("allowHGCal",false);
psd3.add<std::string>("ComponentName",std::string("SeedFromConsecutiveHitsCreator"));
psd3.add<std::string>("propagator",std::string("PropagatorWithMaterial"));
psd3.add<double>("SeedMomentumForBOFF",5.0);
psd3.add<double>("OriginTransverseErrorMultiplier",1.0);
psd3.add<double>("MinOneOverPtError",1.0);
psd3.add<std::string>("magneticField",std::string(""));
psd3.add<std::string>("TTRHBuilder",std::string("WithTrackAngle"));
psd3.add<bool>("forceKinematicWithRegionDirection",false);
psd4.add<edm::InputTag>("HGCEEInput",edm::InputTag("HGCalRecHit","HGCEERecHits"));
psd4.add<edm::InputTag>("HGCFHInput",edm::InputTag("HGCalRecHit","HGCHEFRecHits"));
psd4.add<edm::InputTag>("HGCBHInput",edm::InputTag("HGCalRecHit","HGCHEBRecHits"));
psd0.add<edm::ParameterSetDescription>("HGCalConfig",psd4);
psd0.add<edm::ParameterSetDescription>("SeedCreatorPSet",psd3);
desc.add<edm::ParameterSetDescription>("SeedConfiguration",psd0);
}
desc.add<edm::InputTag>("barrelSuperClusters",edm::InputTag("particleFlowSuperClusterECAL","particleFlowSuperClusterECALBarrel"));
descriptions.add("ecalDrivenElectronSeeds",desc);
}
|
// license:BSD-3-Clause
// copyright-holders:R. Belmont,Ryan Holtz,Fabio Priuli
/***********************************************************************************************************
Game Boy Advance cart emulation
We support carts with several kind of Save RAM (actual SRAM, Flash RAM or EEPROM)
***********************************************************************************************************/
#include "emu.h"
#include "rom.h"
//-------------------------------------------------
// gba_rom_device - constructor
//-------------------------------------------------
DEFINE_DEVICE_TYPE(GBA_ROM_STD, gba_rom_device, "gba_rom", "GBA Carts")
DEFINE_DEVICE_TYPE(GBA_ROM_SRAM, gba_rom_sram_device, "gba_rom_sram", "GBA Carts + SRAM")
DEFINE_DEVICE_TYPE(GBA_ROM_DRILLDOZ, gba_rom_drilldoz_device, "gba_rom_drilldoz", "GBA Carts + SRAM + Rumble")
DEFINE_DEVICE_TYPE(GBA_ROM_WARIOTWS, gba_rom_wariotws_device, "gba_rom_wariotws", "GBA Carts + SRAM + Rumble + Gyroscope")
DEFINE_DEVICE_TYPE(GBA_ROM_EEPROM, gba_rom_eeprom_device, "gba_rom_eeprom", "GBA Carts + EEPROM")
DEFINE_DEVICE_TYPE(GBA_ROM_YOSHIUG, gba_rom_yoshiug_device, "gba_rom_yoshiug", "GBA Carts + EEPROM + Tilt Sensor")
DEFINE_DEVICE_TYPE(GBA_ROM_EEPROM64, gba_rom_eeprom64_device, "gba_rom_eeprom64", "GBA Carts + EEPROM 64K")
DEFINE_DEVICE_TYPE(GBA_ROM_BOKTAI, gba_rom_boktai_device, "gba_rom_boktai", "GBA Carts + EEPROM 64K + RTC + Light Sensor")
DEFINE_DEVICE_TYPE(GBA_ROM_FLASH, gba_rom_flash_device, "gba_rom_flash", "GBA Carts + Panasonic Flash")
DEFINE_DEVICE_TYPE(GBA_ROM_FLASH_RTC, gba_rom_flash_rtc_device, "gba_rom_flash_rtc", "GBA Carts + Panasonic Flash + RTC")
DEFINE_DEVICE_TYPE(GBA_ROM_FLASH1M, gba_rom_flash1m_device, "gba_rom_flash1m", "GBA Carts + Sanyo Flash")
DEFINE_DEVICE_TYPE(GBA_ROM_FLASH1M_RTC, gba_rom_flash1m_rtc_device, "gba_rom_flash1m_rtc", "GBA Carts + Sanyo Flash + RTC")
DEFINE_DEVICE_TYPE(GBA_ROM_3DMATRIX, gba_rom_3dmatrix_device, "gba_rom_3dmatrix", "3D Matrix Memory Mapper")
gba_rom_device::gba_rom_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock)
: device_t(mconfig, type, tag, owner, clock)
, device_gba_cart_interface(mconfig, *this)
{
}
gba_rom_device::gba_rom_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: gba_rom_device(mconfig, GBA_ROM_STD, tag, owner, clock)
{
}
gba_rom_sram_device::gba_rom_sram_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock)
: gba_rom_device(mconfig, type, tag, owner, clock)
{
}
gba_rom_sram_device::gba_rom_sram_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: gba_rom_sram_device(mconfig, GBA_ROM_SRAM, tag, owner, clock)
{
}
gba_rom_drilldoz_device::gba_rom_drilldoz_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: gba_rom_sram_device(mconfig, GBA_ROM_DRILLDOZ, tag, owner, clock)
{
}
gba_rom_wariotws_device::gba_rom_wariotws_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: gba_rom_sram_device(mconfig, GBA_ROM_WARIOTWS, tag, owner, clock)
, m_gyro_z(*this, "GYROZ")
{
}
gba_rom_eeprom_device::gba_rom_eeprom_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock)
: gba_rom_device(mconfig, type, tag, owner, clock)
{
}
gba_rom_eeprom_device::gba_rom_eeprom_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: gba_rom_eeprom_device(mconfig, GBA_ROM_EEPROM, tag, owner, clock)
{
}
gba_rom_yoshiug_device::gba_rom_yoshiug_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: gba_rom_eeprom_device(mconfig, GBA_ROM_YOSHIUG, tag, owner, clock)
, m_tilt_x(*this, "TILTX")
, m_tilt_y(*this, "TILTY")
{
}
gba_rom_eeprom64_device::gba_rom_eeprom64_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock)
: gba_rom_device(mconfig, type, tag, owner, clock)
{
}
gba_rom_eeprom64_device::gba_rom_eeprom64_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: gba_rom_eeprom64_device(mconfig, GBA_ROM_EEPROM64, tag, owner, clock)
{
}
gba_rom_boktai_device::gba_rom_boktai_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: gba_rom_eeprom64_device(mconfig, GBA_ROM_BOKTAI, tag, owner, clock)
, m_sensor(*this, "LIGHTSENSE")
{
}
gba_rom_flash_device::gba_rom_flash_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock)
: gba_rom_device(mconfig, type, tag, owner, clock)
, m_flash_mask(0)
, m_flash(*this, "flash")
{
}
gba_rom_flash_device::gba_rom_flash_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: gba_rom_flash_device(mconfig, GBA_ROM_FLASH, tag, owner, clock)
{
}
gba_rom_flash_rtc_device::gba_rom_flash_rtc_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: gba_rom_flash_device(mconfig, GBA_ROM_FLASH_RTC, tag, owner, clock)
{
}
gba_rom_flash1m_device::gba_rom_flash1m_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock)
: gba_rom_device(mconfig, type, tag, owner, clock)
, m_flash_mask(0)
, m_flash(*this, "flash")
{
}
gba_rom_flash1m_device::gba_rom_flash1m_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: gba_rom_flash1m_device(mconfig, GBA_ROM_FLASH1M, tag, owner, clock)
{
}
gba_rom_flash1m_rtc_device::gba_rom_flash1m_rtc_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: gba_rom_flash1m_device(mconfig, GBA_ROM_FLASH1M_RTC, tag, owner, clock)
{
}
gba_rom_3dmatrix_device::gba_rom_3dmatrix_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: gba_rom_device(mconfig, GBA_ROM_3DMATRIX, tag, owner, clock)
{
}
//-------------------------------------------------
// mapper specific start/reset
//-------------------------------------------------
void gba_rom_device::device_start()
{
save_item(NAME(m_gpio_regs));
save_item(NAME(m_gpio_write_only));
save_item(NAME(m_gpio_dirs));
}
void gba_rom_device::device_reset()
{
m_gpio_regs[0] = 0;
m_gpio_regs[1] = 0;
m_gpio_regs[2] = 0;
m_gpio_regs[3] = 0;
m_gpio_write_only = 1;
m_gpio_dirs = 0;
}
void gba_rom_wariotws_device::device_start()
{
save_item(NAME(m_last_val));
save_item(NAME(m_counter));
}
void gba_rom_wariotws_device::device_reset()
{
m_last_val = 0;
m_counter = 0;
}
void gba_rom_flash_device::device_reset()
{
m_flash_mask = 0xffff/4;
}
void gba_rom_flash1m_device::device_reset()
{
m_flash_mask = 0x1ffff/4;
}
void gba_rom_eeprom_device::device_start()
{
// for the moment we use a custom eeprom implementation, so we alloc/save it as nvram
nvram_alloc(0x200);
m_eeprom = std::make_unique<gba_eeprom_device>(machine(), (uint8_t*)get_nvram_base(), get_nvram_size(), 6);
}
void gba_rom_yoshiug_device::device_start()
{
gba_rom_eeprom_device::device_start();
save_item(NAME(m_tilt_ready));
save_item(NAME(m_xpos));
save_item(NAME(m_ypos));
}
void gba_rom_yoshiug_device::device_reset()
{
m_tilt_ready = 0;
m_xpos = 0;
m_ypos = 0;
}
void gba_rom_eeprom64_device::device_start()
{
// for the moment we use a custom eeprom implementation, so we alloc/save it as nvram
nvram_alloc(0x2000);
m_eeprom = std::make_unique<gba_eeprom_device>(machine(), (uint8_t*)get_nvram_base(), get_nvram_size(), 14);
}
void gba_rom_boktai_device::device_start()
{
gba_rom_eeprom64_device::device_start();
m_rtc = std::make_unique<gba_s3511_device>(machine());
save_item(NAME(m_last_val));
save_item(NAME(m_counter));
}
void gba_rom_boktai_device::device_reset()
{
m_last_val = 0;
m_counter = 0;
}
void gba_rom_flash_rtc_device::device_start()
{
m_rtc = std::make_unique<gba_s3511_device>(machine());
}
void gba_rom_flash1m_rtc_device::device_start()
{
m_rtc = std::make_unique<gba_s3511_device>(machine());
}
void gba_rom_3dmatrix_device::device_start()
{
save_item(NAME(m_src));
save_item(NAME(m_dst));
save_item(NAME(m_nblock));
}
void gba_rom_3dmatrix_device::device_reset()
{
m_src = 0;
m_dst = 0;
m_nblock = 0;
}
/*-------------------------------------------------
mapper specific handlers
-------------------------------------------------*/
/*-------------------------------------------------
This is a preliminary implementation of the
General Purpose I/O Port embedded in the GBA PCBs
as described at : http://problemkaputt.de/gbatek.htm#gbacartioportgpio
Functions read_gpio/write_gpio only give the
I/O interface while the actual on-cart devices
are read and written through gpio_dev_read/gpio_dev_write
which are virtual methods defined in the specific
cart types.
-------------------------------------------------*/
READ32_MEMBER(gba_rom_device::read_gpio)
{
if (!m_gpio_write_only)
{
switch (offset)
{
case 0:
default:
if (ACCESSING_BITS_0_15)
{
uint16_t ret = gpio_dev_read(m_gpio_dirs);
return ret;
}
if (ACCESSING_BITS_16_31)
return m_gpio_regs[1] << 16;
case 1:
if (ACCESSING_BITS_0_15)
return m_gpio_regs[2];
if (ACCESSING_BITS_16_31)
return m_gpio_regs[3] << 16;
}
return 0;
}
else
return m_rom[offset + 0xc4/4];
}
WRITE32_MEMBER(gba_rom_device::write_gpio)
{
switch (offset)
{
case 0:
default:
if (ACCESSING_BITS_0_15)
{
gpio_dev_write(data & 0xffff, m_gpio_dirs);
}
if (ACCESSING_BITS_16_31)
{
m_gpio_dirs = (data >> 16) & 0x0f;
m_gpio_regs[1] = (data >> 16) & 0xffff;
}
break;
case 1:
if (ACCESSING_BITS_0_15)
{
m_gpio_write_only = BIT(data, 0) ? 0 : 1;
m_gpio_regs[2] = data & 0xffff;
}
if (ACCESSING_BITS_16_31)
m_gpio_regs[3] = (data >> 16) & 0xffff;
break;
}
}
/*-------------------------------------------------
Carts with SRAM
-------------------------------------------------*/
READ32_MEMBER(gba_rom_sram_device::read_ram)
{
if (!m_nvram.empty() && offset < m_nvram.size())
return m_nvram[offset];
else // this cannot actually happen...
return 0xffffffff;
}
WRITE32_MEMBER(gba_rom_sram_device::write_ram)
{
if (!m_nvram.empty() && offset < m_nvram.size())
COMBINE_DATA(&m_nvram[offset]);
}
// SRAM cart variant with additional Rumble motor (used by Drill Dozer)
void gba_rom_drilldoz_device::gpio_dev_write(uint16_t data, int gpio_dirs)
{
if ((gpio_dirs & 0x08))
{
// send impulse to Rumble sensor
machine().output().set_value("Rumble", BIT(data, 3));
}
}
// SRAM cart variant with additional Rumble motor + Gyroscope (used by Warioware Twist)
static INPUT_PORTS_START( wariotws_gyroscope )
PORT_START("GYROZ")
PORT_BIT( 0xfff, 0x6c0, IPT_AD_STICK_Z ) PORT_MINMAX(0x354,0x9e3) PORT_SENSITIVITY(0x10) PORT_KEYDELTA(0x50)
INPUT_PORTS_END
ioport_constructor gba_rom_wariotws_device::device_input_ports() const
{
return INPUT_PORTS_NAME( wariotws_gyroscope );
}
uint16_t gba_rom_wariotws_device::gpio_dev_read(int gpio_dirs)
{
int gyro = 0;
if (gpio_dirs == 0x0b)
gyro = BIT(m_gyro_z->read(), m_counter);
return (gyro << 2);
}
void gba_rom_wariotws_device::gpio_dev_write(uint16_t data, int gpio_dirs)
{
if ((gpio_dirs & 0x08))
{
// send impulse to Rumble sensor
machine().output().set_value("Rumble", BIT(data, 3));
}
if (gpio_dirs == 0x0b)
{
if ((data & 2) && (m_counter > 0))
m_counter--;
if (data & 1)
m_counter = 15;
m_last_val = data & 0x0b;
}
}
/*-------------------------------------------------
Carts with Flash RAM
-------------------------------------------------*/
MACHINE_CONFIG_START(gba_rom_flash_device::device_add_mconfig)
MCFG_PANASONIC_MN63F805MNP_ADD("flash")
MACHINE_CONFIG_END
READ32_MEMBER(gba_rom_flash_device::read_ram)
{
uint32_t rv = 0;
offset &= m_flash_mask;
if (mem_mask & 0xff)
rv |= m_flash->read(offset * 4);
if (mem_mask & 0xff00)
rv |= m_flash->read((offset * 4) + 1) << 8;
if (mem_mask & 0xff0000)
rv |= m_flash->read((offset * 4) + 2) << 16;
if (mem_mask & 0xff000000)
rv |= m_flash->read((offset * 4) + 3) << 24;
return rv;
}
WRITE32_MEMBER(gba_rom_flash_device::write_ram)
{
offset &= m_flash_mask;
switch (mem_mask)
{
case 0xff:
m_flash->write(offset * 4, data & 0xff);
break;
case 0xff00:
m_flash->write((offset * 4) + 1, (data >> 8) & 0xff);
break;
case 0xff0000:
m_flash->write((offset * 4) + 2, (data >> 16) & 0xff);
break;
case 0xff000000:
m_flash->write((offset * 4) + 3, (data >> 24) & 0xff);
break;
default:
fatalerror("Unknown mem_mask for GBA flash write %x\n", mem_mask);
}
}
MACHINE_CONFIG_START(gba_rom_flash1m_device::device_add_mconfig)
MCFG_SANYO_LE26FV10N1TS_ADD("flash")
MACHINE_CONFIG_END
READ32_MEMBER(gba_rom_flash1m_device::read_ram)
{
uint32_t rv = 0;
offset &= m_flash_mask;
if (mem_mask & 0xff)
rv |= m_flash->read(offset * 4);
if (mem_mask & 0xff00)
rv |= m_flash->read((offset * 4) + 1) << 8;
if (mem_mask & 0xff0000)
rv |= m_flash->read((offset * 4) + 2) << 16;
if (mem_mask & 0xff000000)
rv |= m_flash->read((offset * 4) + 3) << 24;
return rv;
}
WRITE32_MEMBER(gba_rom_flash1m_device::write_ram)
{
offset &= m_flash_mask;
switch (mem_mask)
{
case 0xff:
m_flash->write(offset * 4, data & 0xff);
break;
case 0xff00:
m_flash->write((offset * 4) + 1, (data >> 8) & 0xff);
break;
case 0xff0000:
m_flash->write((offset * 4) + 2, (data >> 16) & 0xff);
break;
case 0xff000000:
m_flash->write((offset * 4) + 3, (data >> 24) & 0xff);
break;
default:
fatalerror("Unknown mem_mask for GBA flash write %x\n", mem_mask);
}
}
// cart variants with additional S3511 RTC
uint16_t gba_rom_flash_rtc_device::gpio_dev_read(int gpio_dirs)
{
return 5 | (m_rtc->read_line() << 1);
}
void gba_rom_flash_rtc_device::gpio_dev_write(uint16_t data, int gpio_dirs)
{
m_rtc->write(data, gpio_dirs);
}
uint16_t gba_rom_flash1m_rtc_device::gpio_dev_read(int gpio_dirs)
{
return 5 | (m_rtc->read_line() << 1);
}
void gba_rom_flash1m_rtc_device::gpio_dev_write(uint16_t data, int gpio_dirs)
{
m_rtc->write(data, gpio_dirs);
}
/*-------------------------------------------------
Carts with EEPROM
-------------------------------------------------*/
READ32_MEMBER(gba_rom_eeprom_device::read_ram)
{
// Larger games have smaller access to EERPOM content
if (m_rom_size > (16 * 1024 * 1024) && offset < 0xffff00/4)
return 0xffffffff;
return m_eeprom->read();
}
WRITE32_MEMBER(gba_rom_eeprom_device::write_ram)
{
// Larger games have smaller access to EEPROM content
if (m_rom_size > (16 * 1024 * 1024) && offset < 0xffff00/4)
return;
if (~mem_mask == 0x0000ffff)
data >>= 16;
m_eeprom->write(data);
}
READ32_MEMBER(gba_rom_eeprom64_device::read_ram)
{
// Larger games have smaller access to EERPOM content
if (m_rom_size > (16 * 1024 * 1024) && offset < 0xffff00/4)
return 0xffffffff;
return m_eeprom->read();
}
WRITE32_MEMBER(gba_rom_eeprom64_device::write_ram)
{
// Larger games have smaller access to EEPROM content
if (m_rom_size > (16 * 1024 * 1024) && offset < 0xffff00/4)
return;
if (~mem_mask == 0x0000ffff)
data >>= 16;
m_eeprom->write(data);
}
/*-------------------------------------------------
Carts with EEPROM + Tilt Sensor
Note about the calibration: this can seem a bit
tricky at first, because the emulated screen
does not turn as the GBA would...
In order to properly calibrate the sensor, just
keep pressed right for a few seconds when requested
to calibrate right inclination (first calibration
screen in Yoshi Universal Gravitation) so to get the
full right range; then keep pressed for left for a
few seconds when requested to calibrate left
inclination (second calibration screen in Yoshi
Universal Gravitation) so to get the full left range
-------------------------------------------------*/
static INPUT_PORTS_START( yoshiug_tilt )
PORT_START("TILTX")
PORT_BIT( 0xfff, 0x3a0, IPT_AD_STICK_X ) PORT_MINMAX(0x2af,0x477) PORT_SENSITIVITY(0x30) PORT_KEYDELTA(0x50)
PORT_START("TILTY")
PORT_BIT( 0xfff, 0x3a0, IPT_AD_STICK_Y ) PORT_MINMAX(0x2c3,0x480) PORT_SENSITIVITY(0x30) PORT_KEYDELTA(0x50)
INPUT_PORTS_END
ioport_constructor gba_rom_yoshiug_device::device_input_ports() const
{
return INPUT_PORTS_NAME( yoshiug_tilt );
}
READ32_MEMBER(gba_rom_yoshiug_device::read_tilt)
{
switch (offset)
{
case 0x200/4:
if (ACCESSING_BITS_0_15)
return (m_xpos & 0xff);
break;
case 0x300/4:
if (ACCESSING_BITS_0_15)
return ((m_xpos >> 8) & 0x0f) | 0x80;
break;
case 0x400/4:
if (ACCESSING_BITS_0_15)
return (m_ypos & 0xff);
break;
case 0x500/4:
if (ACCESSING_BITS_0_15)
return ((m_ypos >> 8) & 0x0f);
break;
default:
break;
}
return 0xffffffff;
}
WRITE32_MEMBER(gba_rom_yoshiug_device::write_tilt)
{
switch (offset)
{
case 0x000/4:
if (data == 0x55) m_tilt_ready = 1;
break;
case 0x100/4:
if (data == 0xaa)
{
m_xpos = m_tilt_x->read();
m_ypos = m_tilt_y->read();
m_tilt_ready = 0;
}
break;
default:
break;
}
}
/*-------------------------------------------------
Carts with EEPROM + S3511 RTC + Light Sensor
-------------------------------------------------*/
static INPUT_PORTS_START( boktai_sensor )
PORT_START("LIGHTSENSE")
PORT_CONFNAME( 0xff, 0xe8, "Light Sensor" )
PORT_CONFSETTING( 0xe8, "Complete Darkness" )
PORT_CONFSETTING( 0xe4, "10%" )
PORT_CONFSETTING( 0xdc, "20%" )
PORT_CONFSETTING( 0xd4, "30%" )
PORT_CONFSETTING( 0xc8, "40%" )
PORT_CONFSETTING( 0xb8, "50%" )
PORT_CONFSETTING( 0xa8, "60%" )
PORT_CONFSETTING( 0x98, "70%" )
PORT_CONFSETTING( 0x88, "80%" )
PORT_CONFSETTING( 0x68, "90%" )
PORT_CONFSETTING( 0x48, "Very Bright" )
INPUT_PORTS_END
ioport_constructor gba_rom_boktai_device::device_input_ports() const
{
return INPUT_PORTS_NAME( boktai_sensor );
}
uint16_t gba_rom_boktai_device::gpio_dev_read(int gpio_dirs)
{
int light = (gpio_dirs == 7 && m_counter >= m_sensor->read()) ? 1 : 0;
return 5 | (m_rtc->read_line() << 1) | (light << 3);
}
void gba_rom_boktai_device::gpio_dev_write(uint16_t data, int gpio_dirs)
{
m_rtc->write(data, gpio_dirs);
if (gpio_dirs == 7)
{
if (data & 2)
m_counter = 0;
if ((data & 1) && !(m_last_val & 1))
{
m_counter++;
if (m_counter == 0x100)
m_counter = 0;
}
m_last_val = data & 7;
}
}
/*-------------------------------------------------
Carts with 3D Matrix Memory controller
Used by Video carts with 64MB ROM chips
Emulation based on the reverse engineering efforts
by endrift
The Memory controller basically behaves like a DMA
chip by writing first source and destination address,
then the number of 512K blocks to copy and finally
by issuing the transfer command.
Disney Collection 2 carts uses command 0x01 to start
the transfer, other carts might use 0x11 but currently
they die before getting to the mapper communication
(CPU emulation issue? cart mapping issue? still unknown)
To investigate:
- why the other carts fail
- which addresses might be used by the mapper
(Disney Collection 2 uses 0x08800180-0x0880018f
but it might well be possible to issue commands
in an extended range...)
- which bus addresses can be used by the mapper
(currently we restrict the mapping in the range
0x08000000-0x09ffffff but maybe also the rest of
the cart "range" is accessible...)
-------------------------------------------------*/
WRITE32_MEMBER(gba_rom_3dmatrix_device::write_mapper)
{
//printf("mapper write 0x%.8X - 0x%X\n", offset, data); fflush(stdout);
switch (offset & 3)
{
case 0:
//printf("command: %08x\n", data); fflush(stdout);
if (data & 0x01) // transfer data
memcpy((uint8_t *)m_romhlp + m_dst, (uint8_t *)m_rom + m_src, m_nblock * 0x200);
else
printf("Unknown mapper command 0x%X\n", data);
break;
case 1:
//printf("m_src: %08x\n", data); fflush(stdout);
m_src = data & 0x3ffffff;
break;
case 2:
//printf("m_dst: %08x\n", data); fflush(stdout);
if (data >= 0xa000000)
{
printf("Unknown transfer destination 0x%X\n", data);
fflush(stdout);
}
m_dst = (data & 0x1ffffff);
break;
case 3:
default:
//printf("m_nblock: %08x\n", data); fflush(stdout);
m_nblock = data;
break;
}
}
// Additional devices, to be moved to separate source files at a later stage
/*-------------------------------------------------
Seiko S-3511 RTC implementation
TODO: transform this into a separate device, using
also dirtc.cpp!
-------------------------------------------------*/
gba_s3511_device::gba_s3511_device(running_machine &machine) :
m_phase(S3511_RTC_IDLE),
m_machine(machine)
{
m_last_val = 0;
m_bits = 0;
m_command = 0;
m_data_len = 1;
m_data[0] = 0;
m_machine.save().save_item(m_phase, "GBA_RTC/m_phase");
m_machine.save().save_item(m_data, "GBA_RTC/m_data");
m_machine.save().save_item(m_last_val, "GBA_RTC/m_last_val");
m_machine.save().save_item(m_bits, "GBA_RTC/m_bits");
m_machine.save().save_item(m_command, "GBA_RTC/m_command");
m_machine.save().save_item(m_data_len, "GBA_RTC/m_data_len");
}
uint8_t gba_s3511_device::convert_to_bcd(int val)
{
return (((val % 100) / 10) << 4) | (val % 10);
}
void gba_s3511_device::update_time(int len)
{
system_time curtime;
m_machine.current_datetime(curtime);
if (len == 7)
{
m_data[0] = convert_to_bcd(curtime.local_time.year);
m_data[1] = convert_to_bcd(curtime.local_time.month + 1);
m_data[2] = convert_to_bcd(curtime.local_time.mday);
m_data[3] = convert_to_bcd(curtime.local_time.weekday);
m_data[4] = convert_to_bcd(curtime.local_time.hour);
m_data[5] = convert_to_bcd(curtime.local_time.minute);
m_data[6] = convert_to_bcd(curtime.local_time.second);
}
else if (len == 3)
{
m_data[0] = convert_to_bcd(curtime.local_time.hour);
m_data[1] = convert_to_bcd(curtime.local_time.minute);
m_data[2] = convert_to_bcd(curtime.local_time.second);
}
}
int gba_s3511_device::read_line()
{
int pin = 0;
switch (m_phase)
{
case S3511_RTC_DATAOUT:
//printf("mmm %d - %X - %d - %d\n", m_bits, m_data[m_bits >> 3], m_bits >> 3, BIT(m_data[m_bits >> 3], (m_bits & 7)));
pin = BIT(m_data[m_bits >> 3], (m_bits & 7));
m_bits++;
if (m_bits == 8 * m_data_len)
{
//for (int i = 0; i < m_data_len; i++)
// printf("RTC DATA OUT COMPLETE %X (reg %d) \n", m_data[i], i);
m_bits = 0;
m_phase = S3511_RTC_IDLE;
}
break;
}
return pin;
}
void gba_s3511_device::write(uint16_t data, int gpio_dirs)
{
// printf("gpio_dev_write data %X\n", data);
if (m_phase == S3511_RTC_IDLE && (m_last_val & 5) == 1 && (data & 5) == 5)
{
m_phase = S3511_RTC_COMMAND;
m_bits = 0;
m_command = 0;
}
else
{
// if (m_phase == 3)
// printf("RTC command OK\n");
if (!(m_last_val & 1) && (data & 1))
{
// bit transfer
m_last_val = data & 0xff;
switch (m_phase)
{
case S3511_RTC_DATAIN:
if (!BIT(gpio_dirs, 1))
{
m_data[m_bits >> 3] = (m_data[m_bits >> 3] >> 1) | ((data << 6) & 0x80);
m_bits++;
if (m_bits == 8 * m_data_len)
{
//for (int i = 0; i < m_data_len; i++)
// printf("RTC DATA IN COMPLETE %X (reg %d) \n", m_data[i], i);
m_bits = 0;
m_phase = S3511_RTC_IDLE;
}
}
break;
case S3511_RTC_DATAOUT:
break;
case S3511_RTC_COMMAND:
m_command |= (BIT(data, 1) << (7 - m_bits));
m_bits++;
if (m_bits == 8)
{
m_bits = 0;
//printf("RTC command %X ENTERED!!!\n", m_command);
switch (m_command)
{
case 0x60:
// reset?
m_phase = S3511_RTC_IDLE;
m_bits = 0;
break;
case 0x62:
m_phase = S3511_RTC_DATAIN;
m_data_len = 1;
break;
case 0x63:
m_data_len = 1;
m_data[0] = 0x40;
m_phase = S3511_RTC_DATAOUT;
break;
case 0x64:
break;
case 0x65:
m_data_len = 7;
update_time(m_data_len);
m_phase = S3511_RTC_DATAOUT;
break;
case 0x67:
m_data_len = 3;
update_time(m_data_len);
m_phase = S3511_RTC_DATAOUT;
break;
default:
printf("Unknown RTC command %02X\n", m_command);
m_phase = S3511_RTC_IDLE;
break;
}
}
break;
case S3511_RTC_IDLE:
default:
break;
}
}
else
m_last_val = data & 0xff;
}
}
/*-------------------------------------------------
GBA EEPROM Device
TODO: can this sketchy EEPROM device be merged
with the core implementation?
-------------------------------------------------*/
//
gba_eeprom_device::gba_eeprom_device(running_machine &machine, uint8_t *eeprom, uint32_t size, int addr_bits) :
m_state(EEP_IDLE),
m_machine(machine)
{
m_data = eeprom;
m_data_size = size;
m_addr_bits = addr_bits;
m_machine.save().save_item(m_state, "GBA_EEPROM/m_state");
m_machine.save().save_item(m_command, "GBA_EEPROM/m_command");
m_machine.save().save_item(m_count, "GBA_EEPROM/m_count");
m_machine.save().save_item(m_addr, "GBA_EEPROM/m_addr");
m_machine.save().save_item(m_bits, "GBA_EEPROM/m_bits");
m_machine.save().save_item(m_eep_data, "GBA_EEPROM/m_eep_data");
}
uint32_t gba_eeprom_device::read()
{
uint32_t out;
switch (m_state)
{
case EEP_IDLE:
return 0x00010001; // "ready"
case EEP_READFIRST:
m_count--;
if (!m_count)
{
m_count = 64;
m_bits = 0;
m_eep_data = 0;
m_state = EEP_READ;
}
break;
case EEP_READ:
if ((m_bits == 0) && (m_count))
{
if (m_addr >= m_data_size)
{
fatalerror("eeprom: invalid address (%x)\n", m_addr);
}
m_eep_data = m_data[m_addr];
//printf("EEPROM read @ %x = %x (%x)\n", m_addr, m_eep_data, (m_eep_data & 0x80) ? 1 : 0);
m_addr++;
m_bits = 8;
}
out = (m_eep_data & 0x80) ? 1 : 0;
out |= (out<<16);
m_eep_data <<= 1;
m_bits--;
m_count--;
if (!m_count)
{
m_state = EEP_IDLE;
}
return out;
}
return 0;
}
void gba_eeprom_device::write(uint32_t data)
{
switch (m_state)
{
case EEP_IDLE:
if (data == 1)
m_state++;
break;
case EEP_COMMAND:
if (data == 1)
m_command = EEP_READFIRST;
else
m_command = EEP_WRITE;
m_state = EEP_ADDR;
m_count = m_addr_bits;
m_addr = 0;
break;
case EEP_ADDR:
m_addr <<= 1;
m_addr |= (data & 1);
m_count--;
if (!m_count)
{
m_addr *= 8; // each address points to 8 bytes
if (m_command == EEP_READFIRST)
m_state = EEP_AFTERADDR;
else
{
m_count = 64;
m_bits = 8;
m_state = EEP_WRITE;
m_eep_data = 0;
}
}
break;
case EEP_AFTERADDR:
m_state = m_command;
m_count = 64;
m_bits = 0;
m_eep_data = 0;
if (m_state == EEP_READFIRST)
m_count = 4;
break;
case EEP_WRITE:
m_eep_data <<= 1;
m_eep_data |= (data & 1);
m_bits--;
m_count--;
if (m_bits == 0)
{
osd_printf_verbose("%08x: EEPROM: %02x to %x\n", machine().device("maincpu")->safe_pc(), m_eep_data, m_addr);
if (m_addr >= m_data_size)
fatalerror("eeprom: invalid address (%x)\n", m_addr);
m_data[m_addr] = m_eep_data;
m_addr++;
m_eep_data = 0;
m_bits = 8;
}
if (!m_count)
m_state = EEP_AFTERWRITE;
break;
case EEP_AFTERWRITE:
m_state = EEP_IDLE;
break;
}
}
|
lda ({z2}),y
sta {m1}
iny
lda ({z2}),y
sta {m1}+1
cpx #0
beq !e+
!:
lda {m1}+1
cmp #$80
ror {m1}+1
ror {m1}
dex
bne !-
!e:
|
// --------------------------------------------------------------------------
// OpenMS -- Open-Source Mass Spectrometry
// --------------------------------------------------------------------------
// Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
// ETH Zurich, and Freie Universitaet Berlin 2002-2020.
//
// This software is released under a three-clause BSD license:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of any author or any participating institution
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
// For a full list of authors, refer to the file AUTHORS.
// --------------------------------------------------------------------------
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
// INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// --------------------------------------------------------------------------
// $Maintainer: Chris Bielow $
// $Authors: Chris Bielow $
// --------------------------------------------------------------------------
//
#include <OpenMS/CONCEPT/ClassTest.h>
#include <OpenMS/test_config.h>
///////////////////////////
#include <OpenMS/IONMOBILITY/IMTypes.h>
#include <OpenMS/IONMOBILITY/IMDataConverter.h>
#include <OpenMS/KERNEL/MSExperiment.h>
#include <OpenMS/FORMAT/MzMLFile.h>
using namespace OpenMS;
using namespace std;
///////////////////////////
START_TEST(MSRunIMSplitter, "$Id$")
/////////////////////////////////////////////////////////////
IMTypes* e_ptr = nullptr;
IMTypes* e_nullPointer = nullptr;
START_SECTION((IMTypes()))
e_ptr = new IMTypes;
TEST_NOT_EQUAL(e_ptr, e_nullPointer)
END_SECTION
START_SECTION((~IMTypes()))
delete e_ptr;
END_SECTION
START_SECTION((DriftTimeUnit toDriftTimeUnit(const String& dtu_string)))
TEST_EQUAL(toDriftTimeUnit("<NONE>") == DriftTimeUnit::NONE, true)
for (size_t i = 0; i < (size_t)DriftTimeUnit::SIZE_OF_DRIFTTIMEUNIT; ++i)
{
TEST_EQUAL((size_t)toDriftTimeUnit(NamesOfDriftTimeUnit[i]), i)
}
TEST_EXCEPTION(Exception::InvalidValue, toDriftTimeUnit("haha"));
END_SECTION
START_SECTION(const String& toString(const DriftTimeUnit value))
TEST_EQUAL(toString(DriftTimeUnit::NONE), "<NONE>")
for (size_t i = 0; i < (size_t)DriftTimeUnit::SIZE_OF_DRIFTTIMEUNIT; ++i)
{
TEST_EQUAL(toString(DriftTimeUnit(i)), NamesOfDriftTimeUnit[i])
}
TEST_EXCEPTION(Exception::InvalidValue, toString(DriftTimeUnit::SIZE_OF_DRIFTTIMEUNIT));
END_SECTION
START_SECTION((IMFormat toIMFormat(const String& IM_format)))
TEST_EQUAL(toIMFormat("none") == IMFormat::NONE, true)
for (size_t i = 0; i < (size_t) IMFormat::SIZE_OF_IMFORMAT; ++i)
{
TEST_EQUAL((size_t) toIMFormat(NamesOfIMFormat[i]), i)
}
TEST_EXCEPTION(Exception::InvalidValue, toIMFormat("haha"));
END_SECTION
START_SECTION(const String& toString(const IMFormat value))
TEST_EQUAL(toString(IMFormat::NONE), "none")
for (size_t i = 0; i < (size_t)IMFormat::SIZE_OF_IMFORMAT; ++i)
{
TEST_EQUAL(toString(IMFormat(i)), NamesOfIMFormat[i])
}
TEST_EXCEPTION(Exception::InvalidValue, toString(IMFormat::SIZE_OF_IMFORMAT));
END_SECTION
// single IM value for whole spec
const MSSpectrum IMwithDrift = [&]() {
MSSpectrum spec;
spec.setDriftTime(123.4);
spec.setDriftTimeUnit(DriftTimeUnit::VSSC);
return spec;
}();
// convert to IM-Frame with float meta-data array
const MSSpectrum IMwithFDA = [&]() {
MSExperiment exp;
exp.addSpectrum(IMwithDrift);
auto single = IMDataConverter::collapseFramesToSingle(exp);
return single[0];
}();
START_SECTION(static IMFormat determineIMFormat(const MSExperiment& exp))
TEST_EQUAL(IMTypes::determineIMFormat(MSExperiment()) == IMFormat::NONE, true)
{
MSExperiment exp;
exp.addSpectrum(MSSpectrum());
exp.addSpectrum(MSSpectrum());
TEST_EQUAL(IMTypes::determineIMFormat(exp) == IMFormat::NONE, true)
}
{
MSExperiment exp;
exp.addSpectrum(MSSpectrum());
exp.addSpectrum(IMwithDrift);
TEST_EQUAL(IMTypes::determineIMFormat(exp) == IMFormat::MULTIPLE_SPECTRA, true)
}
{
MSExperiment exp;
exp.addSpectrum(MSSpectrum());
exp.addSpectrum(IMwithFDA);
TEST_EQUAL(IMTypes::determineIMFormat(exp) == IMFormat::CONCATENATED, true)
}
{
MSExperiment exp;
exp.addSpectrum(IMwithDrift);
exp.addSpectrum(IMwithFDA);
TEST_EQUAL(IMTypes::determineIMFormat(exp) == IMFormat::MIXED, true)
}
{
// set both ... invalid!
auto IMwithFDA2 = IMwithFDA;
IMwithFDA2.setDriftTime(123.4);
MSExperiment exp;
exp.addSpectrum(IMwithDrift);
exp.addSpectrum(IMwithFDA);
exp.addSpectrum(IMwithFDA2);
TEST_EXCEPTION(Exception::InvalidValue, IMTypes::determineIMFormat(exp))
}
END_SECTION
START_SECTION(static IMFormat determineIMFormat(const MSSpectrum& spec))
TEST_EQUAL(IMTypes::determineIMFormat(MSSpectrum()) == IMFormat::NONE, true)
// single IM value for whole spec
TEST_EQUAL(IMTypes::determineIMFormat(IMwithDrift) == IMFormat::MULTIPLE_SPECTRA, true)
// convert to IM-Frame with float meta-data array
TEST_EQUAL(IMTypes::determineIMFormat(IMwithFDA) == IMFormat::CONCATENATED, true)
// set both ... invalid!
auto IMwithFDA2 = IMwithFDA;
IMwithFDA2.setDriftTime(123.4);
TEST_EXCEPTION(Exception::InvalidValue, IMTypes::determineIMFormat(IMwithFDA2))
END_SECTION
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
END_TEST
|
SECTION code_fp_math48
PUBLIC _log
EXTERN cm48_sdcciy_log
defc _log = cm48_sdcciy_log
|
;------------------------------------------------------------------------------
;
; Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
; This program and the accompanying materials
; are licensed and made available under the terms and conditions of the BSD License
; which accompanies this distribution. The full text of the license may be found at
; http://opensource.org/licenses/bsd-license.php.
;
; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
;
; Module Name:
;
; SetMem32.Asm
;
; Abstract:
;
; SetMem32 function
;
; Notes:
;
;------------------------------------------------------------------------------
.code
;------------------------------------------------------------------------------
; VOID *
; EFIAPI
; InternalMemSetMem32 (
; IN VOID *Buffer,
; IN UINTN Count,
; IN UINT32 Value
; );
;------------------------------------------------------------------------------
InternalMemSetMem32 PROC USES rdi
push rcx
mov rdi, rcx
mov rax, r8
xchg rcx, rdx
rep stosd
pop rax
ret
InternalMemSetMem32 ENDP
END
|
; ===============================================================
; Jan 2014
; ===============================================================
;
; int vsprintf(char *s, const char *format, void *arg)
;
; As vfprintf but output is directed to a string.
;
; ===============================================================
SECTION code_stdio
PUBLIC asm_vsprintf
EXTERN STDIO_MSG_PUTC
EXTERN asm0_vfprintf_unlocked, asm_memset
asm_vsprintf:
; enter : de = char *format
; bc = void *stack_param = arg
; de' = char *s
;
; exit : de = char *format (next unexamined char)
; hl' = char *s (address of terminating '\0')
;
; success
;
; hl = number of chars output to string not including '\0'
; carry reset
;
; fail
;
; hl = - (chars output + 1) < 0
; carry set, errno set as below
;
; erange = width or precision out of range
; einval = unknown printf conversion
;
; note : High level stdio uses hl' to track number of chars
; written to the stream but modifies no other exx registers
;
; uses : all
; create a fake FILE structure on the stack
ld hl,0
push hl
ld hl,$8000 + (vsprintf_outchar / 256)
push hl
ld hl,195 + ((vsprintf_outchar % 256) * 256)
push hl
ld ix,0
add ix,sp ; ix = vsprintf_file *
; print to string
call asm0_vfprintf_unlocked
; repair stack
pop bc
pop bc
pop bc
; terminate string
exx
ex de,hl
ld (hl),0
exx
ret
vsprintf_outchar:
; vfprintf will generate two messages here
; STDIO_MSG_PUTC and STDIO_MSG_WRIT
cp STDIO_MSG_PUTC
jr z, _putc
_writ:
; de = char *s
; hl = length > 0
; hl' = void *buffer
; bc' = length > 0
push de
exx
pop de
ldir
push de
exx
pop de
or a
ret
_putc:
; de = char *s
; hl = number > 0
; e' = char
; bc' = number > 0
dec hl
ld a,h
or l
inc hl
jr nz, _putc_many
exx
ld a,e
exx
ld (de),a
inc de
ret
_putc_many:
push de
exx
pop hl
call asm_memset
push de
exx
pop de
ret
|
; A066294: a(n) = A000203(n)^2 - A001157(n) - 2n = sigma(n)^2 - sigma_2(n) - 2n.
; Submitted by Jamie Morken(s3)
; -2,0,0,20,0,82,0,124,60,174,0,550,0,298,286,588,0,1030,0,1178,482,642,0,2702,260,862,726,2030,0,3824,0,2540,1018,1398,934,6298,0,1714,1358,5810,0,6632,0,4406,3628,2442,0,11870,700,5294,2182,5930,0,10192,1902,10038,2666,3774,0,22644,0,4282,6140,10540,2506,14504,0,9650,3778,14096,0,30146,0,5998,8716,11846,2962,19568,0,25570,7098,7302,0,39508,3954,8002,5806,21854,0,42746,3862,16910,6578,9498,4798,49662,0,16790,13036,33218
mov $2,$0
seq $0,119616 ; Second elementary symmetric function of divisors of n.
sub $0,$2
sub $0,1
mul $0,2
|
;
; Sprite Rendering Routine
; original code by Patrick Davidson (TI 85)
; modified by Stefano Bodrato - Jan 2001
;
; VZ200/300 version
;
;
; $Id: putsprite.asm,v 1.5 2015/01/19 01:32:52 pauloscustodio Exp $
;
PUBLIC putsprite
EXTERN cpygraph
EXTERN pixeladdress
; coords: d,e (vert-horz)
; sprite: (ix)
.offsets_table
defb 128,64,32,16,8,4,2,1
.putsprite
ld hl,2
add hl,sp
ld e,(hl)
inc hl
ld d,(hl) ;sprite address
push de
pop ix
inc hl
ld e,(hl)
inc hl
inc hl
ld d,(hl) ; x and y coords
inc hl
inc hl
ld a,(hl) ; and/or/xor mode
ld (ortype+1),a ; Self modifying code
ld (ortype2+1),a ; Self modifying code
inc hl
ld a,(hl)
ld (ortype),a ; Self modifying code
ld (ortype2),a ; Self modifying code
ld h,d
ld l,e
call pixeladdress
xor 7
ld hl,offsets_table
ld c,a
ld b,0
add hl,bc
ld a,(hl)
ld (wsmc1+1),a
ld (wsmc2+1),a
ld (_smc1+1),a
ld h,d
ld l,e
ld a,(ix+0)
cp 9
jr nc,putspritew
ld d,(ix+0)
ld b,(ix+1)
._oloop push bc ;Save # of rows
push hl ;Save screen address
ld b,d ;Load width
ld c,(ix+2) ;Load one line of image
inc ix
._smc1 ld a,1 ;Load pixel mask
._iloop sla c ;Test leftmost pixel
jr nc,_noplot ;See if a plot is needed
ld e,a
.ortype
nop ; changed into nop / cpl
nop ; changed into and/or/xor (hl)
ld (hl),a
ld a,e
._noplot rrca
rrca
jr nc,_notedge ;Test if edge of byte reached
inc hl ;Go to next byte
._notedge djnz _iloop
pop hl ;Restore address
ld bc,32 ;Go to next line
add hl,bc
pop bc ;Restore data
djnz _oloop
ret
.putspritew
ld d,(ix+0)
ld b,(ix+1)
.woloop push bc ;Save # of rows
push hl ;Save screen address
ld b,d ;Load width
push de
ld c,(ix+2) ;Load one line of image
inc ix
ld d,2
.wsmc1
ld a,1
.wiloop sla c ;Test leftmost pixel
jr nc,wnoplot ;See if a plot is needed
ld e,a
.ortype2
nop ; changed into nop / cpl
nop ; changed into and/or/xor (hl)
ld (hl),a
ld a,e
.wnoplot rrca
rrca
jr nc,wnotedge ;Test if edge of byte reached
inc hl ;Go to next byte
.wnotedge
.wsmc2
cp 1
jr nz,nowover_1
dec d
jr z,wover_1
.nowover_1
djnz wiloop
pop de
pop hl ;Restore address
ld bc,32 ;Go to next line
add hl,bc
pop bc ;Restore data
djnz woloop
ret
.wover_1
ld c,(ix+2)
inc ix
djnz wiloop
dec ix
pop hl
ld bc,32
add hl,bc
pop bc
djnz woloop
ret
|
#include "scientific_module.hpp"
#include <algorithm>
#include <iostream>
#include <math.h>
#include <random>
#include <thread>
namespace py = pybind11;
double compute_pi_cpp(int samples) {
// Take random x and y cartesian coordinates
auto xs = create_random_vector(samples);
auto ys = create_random_vector(samples);
auto inside = 0.0;
for (auto i = 0; i < samples; i++) {
auto x = sqrt(pow(xs[i], 2.0) + pow(ys[i], 2.0));
if (x < 1.0) {
inside += 1.0;
}
}
// return approx_pi
return 4 * inside / static_cast<double>(samples);
}
std::vector<double> create_random_vector(int samples) {
// Will be used to obtain a seed for the random number engine
std::random_device rd;
// Standard mersenne_twister_engine seeded with rd()
std::mt19937 gen(rd());
std::uniform_real_distribution<> dist(0.0, 1.0);
std::vector<double> xs(samples);
std::generate(xs.begin(), xs.end(), [&]() { return dist(gen); });
return xs;
}
// Python interface definition
PYBIND11_MODULE(compute_pi_cpp, m) {
m.doc() = "Compute the pi number using the Monte Carlo method";
m.def("compute_pi_cpp", &compute_pi_cpp,
R"pdoc(Compute pi using the Monte Carlo method
Args:
samples (int): Number of samples
)pdoc",
py::arg("samples"));
}
|
#include "PID.h"
#include <iostream>
using namespace std;
/*
* TODO: Complete the PID class.
*/
PID::PID()
{
best_err = 10000.0;//std::numeric_limits<double>::max();
converged = false;
}
PID::~PID() {}
void PID::Init(double Kp, double Ki, double Kd) {
this->Kp = Kp;
this->Ki = Ki;
this->Kd = Kd;
p[0] = Kp;
p[1] = Kd;
p[2] = Ki;
p_error = 0;
d_error = 0;
i_error = 0;
}
void PID::UpdateError(double cte) {
d_error = cte - p_error;
p_error = cte;
i_error += cte;
// errQ.push(cte);
// if (errQ.size() > 6)
// updateParamWithTwiddle();
}
double PID::TotalError() {
return (p_error + d_error + i_error);
}
void PID::updateParamWithTwiddle()
{
int it=0;
for (int i=0; i < 3; i++)
{
p[i] += dp[i];
// need to do something x_trajectory, y_trajectory, err = run(robot, p)
double err = errQ.front();// need to find out
errQ.pop();
if (err < best_err)
{
best_err = err;
dp[i] *= 1.1;
}
else
{
p[i] -= 2*dp[i];
//x_trajectory, y_trajectory, err = run(robot, p)
err = errQ.front();
errQ.pop();
if (err < best_err)
{
best_err = err;
dp[i] *= 1.1;
}
else
{
p[i] += dp[i];
dp[i] *= 0.9;
}
}
it +=1;
}
double dpTotal = dp[0]+dp[1]+dp[2];
//if (dpTotal < 0.0001)
//{
Kp = p[0];
Kd = p[1];
Ki = p[2];
converged = true;
//}
std::cout<<" Kp " << Kp << " Kd " << Kd << " Ki " << Ki << " best err " << best_err<< " dp total " << dpTotal << " P0 " << p[0] << " P1 " << p[1] << " P2 " << p[2] << endl;
}
|
/*
* Copyright (c) 2020 - 2022 Samsung Electronics Co., Ltd. All rights reserved.
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "Common.h"
#include <fstream>
/************************************************************************/
/* Drawing Commands */
/************************************************************************/
void tvgDrawCmds(tvg::Canvas* canvas)
{
if (!canvas) return;
//Duplicate Shapes
{
//Original Shape
auto shape1 = tvg::Shape::gen();
shape1->appendRect(10, 10, 200, 200, 0, 0);
shape1->appendRect(220, 10, 100, 100, 0, 0);
shape1->stroke(3);
shape1->stroke(0, 255, 0, 255);
float dashPattern[2] = {4, 4};
shape1->stroke(dashPattern, 2);
shape1->fill(255, 0, 0, 255);
//Duplicate Shape, Switch fill method
auto shape2 = unique_ptr<tvg::Shape>(static_cast<tvg::Shape*>(shape1->duplicate()));
shape2->translate(0, 220);
auto fill = tvg::LinearGradient::gen();
fill->linear(10, 10, 440, 200);
tvg::Fill::ColorStop colorStops[2];
colorStops[0] = {0, 0, 0, 0, 255};
colorStops[1] = {1, 255, 255, 255, 255};
fill->colorStops(colorStops, 2);
shape2->fill(move(fill));
//Duplicate Shape 2
auto shape3 = unique_ptr<tvg::Shape>(static_cast<tvg::Shape*>(shape2->duplicate()));
shape3->translate(0, 440);
canvas->push(move(shape1));
canvas->push(move(shape2));
canvas->push(move(shape3));
}
//Duplicate Scene
{
//Create a Scene1
auto scene1 = tvg::Scene::gen();
scene1->reserve(3);
auto shape1 = tvg::Shape::gen();
shape1->appendRect(0, 0, 400, 400, 50, 50);
shape1->fill(0, 255, 0, 255);
scene1->push(move(shape1));
auto shape2 = tvg::Shape::gen();
shape2->appendCircle(400, 400, 200, 200);
shape2->fill(255, 255, 0, 255);
scene1->push(move(shape2));
auto shape3 = tvg::Shape::gen();
shape3->appendCircle(600, 600, 150, 100);
shape3->fill(0, 255, 255, 255);
scene1->push(move(shape3));
scene1->scale(0.25);
scene1->translate(400, 0);
//Duplicate Scene1
auto scene2 = unique_ptr<tvg::Scene>(static_cast<tvg::Scene*>(scene1->duplicate()));
scene2->translate(600, 0);
canvas->push(move(scene1));
canvas->push(move(scene2));
}
//Duplicate Picture - svg
{
auto picture1 = tvg::Picture::gen();
picture1->load(EXAMPLE_DIR"/tiger.svg");
picture1->translate(350, 200);
picture1->scale(0.25);
auto picture2 = unique_ptr<tvg::Picture>(static_cast<tvg::Picture*>(picture1->duplicate()));
picture2->translate(550, 250);
canvas->push(move(picture1));
canvas->push(move(picture2));
}
//Duplicate Picture - raw
{
string path(EXAMPLE_DIR"/rawimage_200x300.raw");
ifstream file(path);
if (!file.is_open()) return ;
uint32_t* data = (uint32_t*)malloc(sizeof(uint32_t) * 200 * 300);
file.read(reinterpret_cast<char*>(data), sizeof(uint32_t) * 200 * 300);
file.close();
auto picture1 = tvg::Picture::gen();
if (picture1->load(data, 200, 300, true) != tvg::Result::Success) return;
picture1->scale(0.8);
picture1->translate(400, 450);
auto picture2 = unique_ptr<tvg::Picture>(static_cast<tvg::Picture*>(picture1->duplicate()));
picture2->translate(600, 550);
picture2->scale(0.7);
picture2->rotate(8);
canvas->push(move(picture1));
canvas->push(move(picture2));
free(data);
}
}
/************************************************************************/
/* Sw Engine Test Code */
/************************************************************************/
static unique_ptr<tvg::SwCanvas> swCanvas;
void tvgSwTest(uint32_t* buffer)
{
//Create a Canvas
swCanvas = tvg::SwCanvas::gen();
swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
/* Push the shape into the Canvas drawing list
When this shape is into the canvas list, the shape could update & prepare
internal data asynchronously for coming rendering.
Canvas keeps this shape node unless user call canvas->clear() */
tvgDrawCmds(swCanvas.get());
}
void drawSwView(void* data, Eo* obj)
{
if (swCanvas->draw() == tvg::Result::Success) {
swCanvas->sync();
}
}
/************************************************************************/
/* GL Engine Test Code */
/************************************************************************/
static unique_ptr<tvg::GlCanvas> glCanvas;
void initGLview(Evas_Object *obj)
{
static constexpr auto BPP = 4;
//Create a Canvas
glCanvas = tvg::GlCanvas::gen();
glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
/* Push the shape into the Canvas drawing list
When this shape is into the canvas list, the shape could update & prepare
internal data asynchronously for coming rendering.
Canvas keeps this shape node unless user call canvas->clear() */
tvgDrawCmds(glCanvas.get());
}
void drawGLview(Evas_Object *obj)
{
auto gl = elm_glview_gl_api_get(obj);
gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
gl->glClear(GL_COLOR_BUFFER_BIT);
if (glCanvas->draw() == tvg::Result::Success) {
glCanvas->sync();
}
}
/************************************************************************/
/* Main Code */
/************************************************************************/
int main(int argc, char **argv)
{
tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
if (argc > 1) {
if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
}
//Initialize ThorVG Engine
if (tvgEngine == tvg::CanvasEngine::Sw) {
cout << "tvg engine: software" << endl;
} else {
cout << "tvg engine: opengl" << endl;
}
//Threads Count
auto threads = std::thread::hardware_concurrency();
if (threads > 0) --threads; //Allow the designated main thread capacity
//Initialize ThorVG Engine
if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
elm_init(argc, argv);
if (tvgEngine == tvg::CanvasEngine::Sw) {
createSwView();
} else {
createGlView();
}
elm_run();
elm_shutdown();
//Terminate ThorVG Engine
tvg::Initializer::term(tvgEngine);
} else {
cout << "engine is not supported" << endl;
}
return 0;
}
|
; set cursor stuff:
ldi xr #0E ; Display on, cursor on, blink off : 00001110
stw xr #FE ; store to port B
ldi xr #0 ; clear RS/RW/E bits
stw xr #FF ; store to port A
ldw xr enable ; enable write to lcd
stw xr #FF ; store to port A
ldi xr #0 ; clear RS/RW/E bits
stw xr #FF ; store to port A
; entry mode set
ldi xr #06 ; Increment and shift curosr, don't shift display, 00000110
stw xr #FE ; store to port B
ldi xr #0 ; clear RS/RW/E bits
stw xr #FF ; store to port A
ldw xr enable ; enable write to lcd
stw xr #FF ; store to port A
ldi xr #0 ; clear RS/RW/E bits
stw xr #FF ; store to port A
; write Hello,world to lcd
ldw xr charH ;
stw xr #FE ; store to port B
jmp writeChar
ldw xr chari ;
stw xr #FE ; store to port B
jmp writeChar
ldw xr char, ;
stw xr #FE ; store to port B
jmp writeChar
ldw xr charW ;
stw xr #FE ; store to port B
jmp writeChar
ldw xr charo ;
stw xr #FE ; store to port B
jmp writeChar
ldw xr charr ;
stw xr #FE ; store to port B
jmp writeChar
ldw xr charl ;
stw xr #FE ; store to port B
jmp writeChar
ldw xr chard
stw xr #FE ; store to port B
jmp writeChar
ldw xr char!
stw xr #FE ; store to port B
jmp writeChar
loop:
jmp loop
writeChar:
ldw xr rs ; set register select
stw xr #FF ; store to port A
ldw xr enrs ; enable write to lcd
stw xr #FF ; store to port A
ldw xr rs ; clear RS/RW/E bits
stw xr #FF ; store to port A
ret
.org #$70 ; place following code at address 0x1E
porta:
.word #FF ; place literal 0x5 at this address
portb:
.word #FE ; place literal 15 at this address
enable:
.word #80 ; store 10000000
rw:
.word #40 ; store 01000000
rs:
.word #20 ; store 00100000
enrs:
.word #A0
charH:
.word 'H'
chari:
.word 'i'
charl:
.word 'l'
char,:
.word ','
charW:
.word 'W'
charo:
.word 'o'
charr:
.word 'r'
chard:
.word 'd'
char!:
.word '!'
|
.global s_prepare_buffers
s_prepare_buffers:
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r8
push %r9
push %rbp
push %rbx
push %rdx
push %rsi
// Store
lea addresses_normal+0x3583, %r9
nop
nop
nop
nop
nop
cmp $40226, %r11
movw $0x5152, (%r9)
nop
sub $30780, %rdx
// Store
lea addresses_US+0x17903, %r11
nop
and $7911, %rbp
movl $0x51525354, (%r11)
add %r9, %r9
// Store
lea addresses_A+0x1f538, %r8
nop
nop
nop
inc %rsi
movb $0x51, (%r8)
sub %rbx, %rbx
// Faulty Load
lea addresses_UC+0x1903, %rsi
nop
nop
nop
nop
nop
cmp %rdx, %rdx
vmovups (%rsi), %ymm7
vextracti128 $0, %ymm7, %xmm7
vpextrq $0, %xmm7, %r9
lea oracles, %rsi
and $0xff, %r9
shlq $12, %r9
mov (%rsi,%r9,1), %r9
pop %rsi
pop %rdx
pop %rbx
pop %rbp
pop %r9
pop %r8
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'src': {'NT': False, 'same': False, 'congruent': 0, 'type': 'addresses_UC', 'AVXalign': False, 'size': 32}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 4, 'type': 'addresses_normal', 'AVXalign': False, 'size': 2}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 10, 'type': 'addresses_US', 'AVXalign': False, 'size': 4}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 0, 'type': 'addresses_A', 'AVXalign': False, 'size': 1}}
[Faulty Load]
{'src': {'NT': False, 'same': True, 'congruent': 0, 'type': 'addresses_UC', 'AVXalign': False, 'size': 32}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'54': 1}
54
*/
|
//-----------------------------------------------------------------------------
// boost variant/static_visitor.hpp header file
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2002-2003
// Eric Friedman
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_VARIANT_STATIC_VISITOR_HPP
#define BOOST_VARIANT_STATIC_VISITOR_HPP
#include "boost/config.hpp"
#include "boost/detail/workaround.hpp"
#include "boost/mpl/if.hpp"
#include "boost/type_traits/is_base_and_derived.hpp"
#include <boost/type_traits/integral_constant.hpp>
#include <boost/mpl/aux_/lambda_support.hpp>
namespace geofeatures_boost {} namespace boost = geofeatures_boost; namespace geofeatures_boost {
//////////////////////////////////////////////////////////////////////////
// class template static_visitor
//
// An empty base class that typedefs the return type of a deriving static
// visitor. The class is analogous to std::unary_function in this role.
//
namespace detail {
struct is_static_visitor_tag { };
typedef void static_visitor_default_return;
} // namespace detail
template <typename R = ::geofeatures_boost::detail::static_visitor_default_return>
class static_visitor
: public detail::is_static_visitor_tag
{
public: // typedefs
typedef R result_type;
protected: // for use as base class only
#if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) && !defined(BOOST_NO_CXX11_NON_PUBLIC_DEFAULTED_FUNCTIONS)
static_visitor() = default;
~static_visitor() = default;
#else
static_visitor() BOOST_NOEXCEPT { }
~static_visitor() BOOST_NOEXCEPT { }
#endif
};
//////////////////////////////////////////////////////////////////////////
// metafunction is_static_visitor
//
// Value metafunction indicates whether the specified type derives from
// static_visitor<...>.
//
// NOTE #1: This metafunction does NOT check whether the specified type
// fulfills the requirements of the StaticVisitor concept.
//
// NOTE #2: This template never needs to be specialized!
//
namespace detail {
template <typename T>
struct is_static_visitor_impl
{
BOOST_STATIC_CONSTANT(bool, value =
(::geofeatures_boost::is_base_and_derived<
detail::is_static_visitor_tag,
T
>::value));
};
} // namespace detail
template< typename T > struct is_static_visitor
: public ::geofeatures_boost::integral_constant<bool,(::geofeatures_boost::detail::is_static_visitor_impl<T>::value)>
{
public:
BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_static_visitor,(T))
};
} // namespace geofeatures_boost
#endif // BOOST_VARIANT_STATIC_VISITOR_HPP
|
; void SMS_setClippingWindow(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1)
SECTION code_clib
SECTION code_SMSlib
PUBLIC SMS_setClippingWindow_callee
EXTERN asm_SMSlib_setClippingWindow
SMS_setClippingWindow_callee:
pop af
pop de
pop hl
ld h,e
pop bc
pop de
ld d,c
push af
jp asm_SMSlib_setClippingWindow
|
;******************************************************************************
.define uart_baud, 0x0A
.define uart_ctrl, 0x0B
.define uart_buffer, 0x0C
.define motor_control, 0x0D
.define motor_enable, 0x0E
.define motor_pwm0, 0x0F
.define motor_pwm1, 0x10
.define motor_speed0, 0x11
.define motor_speed1, 0x12
.define gpu_addr, 0x2000
.define gpu_ctrl_reg, 0x80
;******************************************************************************
.code
ldi r0, 103 ; set the baud rate to 9600
out r0, uart_baud
ldi r0, 0xff
out r0, motor_enable
ldi r1, 0b00000110
out r1, motor_control
ldi r0, 10
out r0, motor_pwm0
out r0, motor_pwm1
loop: in r1, uart_ctrl
ani r1, 2
bz loop ; poll for empty buffer
in r0, motor_speed0
out r0, uart_buffer
br loop |
/*
This file is part of Corrade.
Copyright © 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016,
2017, 2018, 2019, 2020 Vladimír Vondruš <mosra@centrum.cz>
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 <map>
#include <sstream>
#include <vector>
#include "Corrade/Containers/ArrayView.h"
#include "Corrade/Containers/Optional.h"
#include "Corrade/TestSuite/Tester.h"
#include "Corrade/TestSuite/Compare/Container.h"
#include "Corrade/TestSuite/Compare/StringToFile.h"
#include "Corrade/Utility/DebugStl.h" /** @todo remove when <sstream> is gone */
#include "Corrade/Utility/Directory.h"
#include "Corrade/Utility/Resource.h"
#include "Corrade/Utility/Implementation/Resource.h"
#include "configure.h"
namespace Corrade { namespace Utility { namespace Test { namespace {
struct ResourceTest: TestSuite::Tester {
explicit ResourceTest();
void resourceFilenameAt();
void resourceDataAt();
void resourceLookup();
void benchmarkLookupInPlace();
void benchmarkLookupStdMap();
void compile();
void compileNotSorted();
void compileNothing();
void compileEmptyFile();
void compileFrom();
void compileFromUtf8Filenames();
void compileFromNonexistentResource();
void compileFromNonexistentFile();
void compileFromEmptyGroup();
void compileFromEmptyFilename();
void compileFromEmptyAlias();
void hasGroup();
void list();
void get();
void getEmptyFile();
void getNonexistent();
void getNothing();
void overrideGroup();
void overrideGroupFallback();
void overrideNonexistentFile();
void overrideNonexistentGroup();
void overrideDifferentGroup();
};
ResourceTest::ResourceTest() {
addTests({&ResourceTest::resourceFilenameAt,
&ResourceTest::resourceDataAt,
&ResourceTest::resourceLookup});
addBenchmarks({&ResourceTest::benchmarkLookupInPlace,
&ResourceTest::benchmarkLookupStdMap}, 100);
addTests({&ResourceTest::compile,
&ResourceTest::compileNotSorted,
&ResourceTest::compileNothing,
&ResourceTest::compileEmptyFile,
&ResourceTest::compileFrom,
&ResourceTest::compileFromUtf8Filenames,
&ResourceTest::compileFromNonexistentResource,
&ResourceTest::compileFromNonexistentFile,
&ResourceTest::compileFromEmptyGroup,
&ResourceTest::compileFromEmptyFilename,
&ResourceTest::compileFromEmptyAlias,
&ResourceTest::hasGroup,
&ResourceTest::list,
&ResourceTest::get,
&ResourceTest::getEmptyFile,
&ResourceTest::getNonexistent,
&ResourceTest::getNothing,
&ResourceTest::overrideGroup,
&ResourceTest::overrideGroupFallback,
&ResourceTest::overrideNonexistentFile,
&ResourceTest::overrideNonexistentGroup,
&ResourceTest::overrideDifferentGroup});
}
constexpr unsigned int Positions[] {
3, 6,
11, 17,
20, 21,
30, 25,
40, 44
};
constexpr unsigned char Filenames[] =
"TOC" // 3 3
"data.txt" // 8 11
"image.png" // 9 20
"image2.png" // 10 30
"license.md" // 10 40
;
constexpr unsigned char Data[] =
"Don't." // 6 6
"hello world" // 11 17
"!PNG" // 4 21
"!PNG" // 4 25
"GPL?!\n#####\n\nDon't." // 19 44
;
inline std::string asString(Containers::ArrayView<const char> view) {
return {view.data(), view.size()};
}
void ResourceTest::resourceFilenameAt() {
/* Last position says how large the filenames are */
CORRADE_COMPARE(sizeof(Filenames) - 1, Positions[4*2]);
/* First is a special case */
CORRADE_COMPARE(asString(Implementation::resourceFilenameAt(Positions, Filenames, 0)), "TOC");
CORRADE_COMPARE(asString(Implementation::resourceFilenameAt(Positions, Filenames, 2)), "image.png");
}
void ResourceTest::resourceDataAt() {
/* Last position says how large the filenames are */
CORRADE_COMPARE(sizeof(Data) - 1, Positions[4*2 + 1]);
/* First is a special case */
CORRADE_COMPARE(asString(Implementation::resourceDataAt(Positions, Data, 0)), "Don't.");
CORRADE_COMPARE(asString(Implementation::resourceDataAt(Positions, Data, 4)), "GPL?!\n#####\n\nDon't.");
}
void ResourceTest::resourceLookup() {
/* The filenames should be sorted */
CORRADE_VERIFY(
asString(Implementation::resourceFilenameAt(Positions, Filenames, 0)) <
asString(Implementation::resourceFilenameAt(Positions, Filenames, 1)));
CORRADE_VERIFY(
asString(Implementation::resourceFilenameAt(Positions, Filenames, 1)) <
asString(Implementation::resourceFilenameAt(Positions, Filenames, 2)));
CORRADE_VERIFY(
asString(Implementation::resourceFilenameAt(Positions, Filenames, 2)) <
asString(Implementation::resourceFilenameAt(Positions, Filenames, 3)));
CORRADE_VERIFY(
asString(Implementation::resourceFilenameAt(Positions, Filenames, 3)) <
asString(Implementation::resourceFilenameAt(Positions, Filenames, 4)));
/* Those exist. Cutting off the null terminator of the filename. */
CORRADE_COMPARE(Implementation::resourceLookup(5, Positions, Filenames,
Containers::arrayView("TOC").except(1)), 0);
CORRADE_COMPARE(Implementation::resourceLookup(5, Positions, Filenames,
Containers::arrayView("data.txt").except(1)), 1);
CORRADE_COMPARE(Implementation::resourceLookup(5, Positions, Filenames,
Containers::arrayView("image.png").except(1)), 2);
CORRADE_COMPARE(Implementation::resourceLookup(5, Positions, Filenames,
Containers::arrayView("image2.png").except(1)), 3);
CORRADE_COMPARE(Implementation::resourceLookup(5, Positions, Filenames,
Containers::arrayView("license.md").except(1)), 4);
/* An extra null terminator won't match */
CORRADE_COMPARE(Implementation::resourceLookup(5, Positions, Filenames, "TOC"), 5);
/* Lower bound returns license.md, but filename match discards that */
CORRADE_COMPARE(Implementation::resourceLookup(5, Positions, Filenames, "image3.png"), 5);
/* Last name is license.md, this is after, so lower bound returns end */
CORRADE_COMPARE(Implementation::resourceLookup(5, Positions, Filenames, "termcap.info"), 5);
}
CORRADE_NEVER_INLINE unsigned int lookupInPlace(Containers::ArrayView<const char> key) {
return Implementation::resourceLookup(5, Positions, Filenames, key);
}
CORRADE_NEVER_INLINE unsigned int lookupStdMap(const std::map<std::string, unsigned int>& map, const std::string& key) {
return map.at(key);
}
void ResourceTest::benchmarkLookupInPlace() {
const auto key = Containers::arrayView("license.md").except(1);
unsigned int out = 0;
CORRADE_BENCHMARK(10)
out += lookupInPlace(key);
CORRADE_COMPARE(out, 40);
}
void ResourceTest::benchmarkLookupStdMap() {
std::map<std::string, unsigned int> map{
{"TOC", 0},
{"data.txt", 1},
{"image.png", 2},
{"image2.png", 3},
{"license.md", 4},
};
std::string key = "license.md";
unsigned int out = 0;
CORRADE_BENCHMARK(10)
out += lookupStdMap(map, key);
CORRADE_COMPARE(out, 40);
}
void ResourceTest::compile() {
/* Testing also null bytes and signed overflow, don't change binaries */
std::vector<std::pair<std::string, std::string>> input{
{"consequence.bin", Directory::readString(Directory::join(RESOURCE_TEST_DIR, "consequence.bin"))},
{"predisposition.bin", Directory::readString(Directory::join(RESOURCE_TEST_DIR, "predisposition.bin"))}};
CORRADE_COMPARE_AS(Resource::compile("ResourceTestData", "test", input),
Directory::join(RESOURCE_TEST_DIR, "compiled.cpp"),
TestSuite::Compare::StringToFile);
}
void ResourceTest::compileNotSorted() {
#ifdef CORRADE_NO_ASSERT
CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions");
#endif
std::vector<std::pair<std::string, std::string>> input{
{"predisposition.bin", {}},
{"consequence.bin",{}}};
std::ostringstream out;
Error redirectError{&out};
Resource::compile("ResourceTestData", "test", input);
CORRADE_COMPARE(out.str(), "Utility::Resource::compile(): the file list is not sorted\n");
}
void ResourceTest::compileNothing() {
CORRADE_COMPARE_AS(Resource::compile("ResourceTestNothingData", "nothing", {}),
Directory::join(RESOURCE_TEST_DIR, "compiled-nothing.cpp"),
TestSuite::Compare::StringToFile);
}
void ResourceTest::compileEmptyFile() {
std::vector<std::pair<std::string, std::string>> input{
{"empty.bin", ""}};
CORRADE_COMPARE_AS(Resource::compile("ResourceTestData", "test", input),
Directory::join(RESOURCE_TEST_DIR, "compiled-empty.cpp"),
TestSuite::Compare::StringToFile);
}
void ResourceTest::compileFrom() {
const std::string compiled = Resource::compileFrom("ResourceTestData",
Directory::join(RESOURCE_TEST_DIR, "resources.conf"));
CORRADE_COMPARE_AS(compiled, Directory::join(RESOURCE_TEST_DIR, "compiled.cpp"),
TestSuite::Compare::StringToFile);
}
void ResourceTest::compileFromUtf8Filenames() {
const std::string compiled = Resource::compileFrom("ResourceTestUtf8Data",
Directory::join(RESOURCE_TEST_DIR, "hýždě.conf"));
CORRADE_COMPARE_AS(compiled, Directory::join(RESOURCE_TEST_DIR, "compiled-unicode.cpp"),
TestSuite::Compare::StringToFile);
}
void ResourceTest::compileFromNonexistentResource() {
std::ostringstream out;
Error redirectError{&out};
CORRADE_VERIFY(Resource::compileFrom("ResourceTestData", "nonexistent.conf").empty());
CORRADE_COMPARE(out.str(), " Error: file nonexistent.conf does not exist\n");
}
void ResourceTest::compileFromNonexistentFile() {
std::ostringstream out;
Error redirectError{&out};
CORRADE_VERIFY(Resource::compileFrom("ResourceTestData",
Directory::join(RESOURCE_TEST_DIR, "resources-nonexistent.conf")).empty());
CORRADE_COMPARE(out.str(), " Error: cannot open file /nonexistent.dat of file 1 in group name\n");
}
void ResourceTest::compileFromEmptyGroup() {
std::ostringstream out;
Error redirectError{&out};
/* Empty group name is allowed */
CORRADE_VERIFY(!Resource::compileFrom("ResourceTestData",
Directory::join(RESOURCE_TEST_DIR, "resources-empty-group.conf")).empty());
CORRADE_COMPARE(out.str(), "");
/* Missing group entry is not allowed */
CORRADE_VERIFY(Resource::compileFrom("ResourceTestData",
Directory::join(RESOURCE_TEST_DIR, "resources-no-group.conf")).empty());
CORRADE_COMPARE(out.str(), " Error: group name is not specified\n");
}
void ResourceTest::compileFromEmptyFilename() {
std::ostringstream out;
Error redirectError{&out};
CORRADE_VERIFY(Resource::compileFrom("ResourceTestData",
Directory::join(RESOURCE_TEST_DIR, "resources-empty-filename.conf")).empty());
CORRADE_COMPARE(out.str(), " Error: filename or alias of file 1 in group name is empty\n");
}
void ResourceTest::compileFromEmptyAlias() {
std::ostringstream out;
Error redirectError{&out};
CORRADE_VERIFY(Resource::compileFrom("ResourceTestData",
Directory::join(RESOURCE_TEST_DIR, "resources-empty-alias.conf")).empty());
CORRADE_COMPARE(out.str(), " Error: filename or alias of file 1 in group name is empty\n");
}
void ResourceTest::hasGroup() {
CORRADE_VERIFY(Resource::hasGroup("test"));
CORRADE_VERIFY(Resource::hasGroup(std::string{"test"}));
CORRADE_VERIFY(!Resource::hasGroup("nonexistent"));
CORRADE_VERIFY(!Resource::hasGroup(std::string{"nonexistent"}));
}
void ResourceTest::list() {
{
Resource r{"test"};
CORRADE_COMPARE_AS(r.list(),
(std::vector<std::string>{"consequence.bin", "predisposition.bin"}),
TestSuite::Compare::Container);
} {
Resource r{std::string{"test"}};
CORRADE_COMPARE_AS(r.list(),
(std::vector<std::string>{"consequence.bin", "predisposition.bin"}),
TestSuite::Compare::Container);
}
}
void ResourceTest::get() {
Resource r("test");
CORRADE_COMPARE_AS(r.get("predisposition.bin"),
Directory::join(RESOURCE_TEST_DIR, "predisposition.bin"),
TestSuite::Compare::StringToFile);
CORRADE_COMPARE_AS(r.get("consequence.bin"),
Directory::join(RESOURCE_TEST_DIR, "consequence.bin"),
TestSuite::Compare::StringToFile);
{
Containers::ArrayView<const char> data = r.getRaw("consequence.bin");
CORRADE_COMPARE_AS((std::string{data, data.size()}),
Directory::join(RESOURCE_TEST_DIR, "consequence.bin"),
TestSuite::Compare::StringToFile);
} {
Containers::ArrayView<const char> data = r.getRaw(std::string{"consequence.bin"});
CORRADE_COMPARE_AS((std::string{data, data.size()}),
Directory::join(RESOURCE_TEST_DIR, "consequence.bin"),
TestSuite::Compare::StringToFile);
}
}
void ResourceTest::getEmptyFile() {
Resource r("empty");
CORRADE_VERIFY(!r.getRaw("empty.bin"));
CORRADE_COMPARE(r.get("empty.bin"), "");
}
void ResourceTest::getNonexistent() {
#ifdef CORRADE_NO_ASSERT
CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions");
#endif
std::ostringstream out;
Error redirectError{&out};
{
Resource r("nonexistentGroup");
CORRADE_COMPARE(out.str(), "Utility::Resource: group 'nonexistentGroup' was not found\n");
}
out.str({});
{
Resource r("test");
CORRADE_VERIFY(r.get("nonexistentFile").empty());
CORRADE_COMPARE(out.str(), "Utility::Resource::get(): file 'nonexistentFile' was not found in group 'test'\n");
}
Resource r("test");
const auto data = r.getRaw("nonexistentFile");
CORRADE_VERIFY(!data);
CORRADE_VERIFY(!data.size());
}
void ResourceTest::getNothing() {
Containers::Optional<Resource> r;
{
std::ostringstream out;
Error redirectError{&out};
r.emplace("nothing");
CORRADE_VERIFY(out.str().empty());
}
CORRADE_COMPARE(r->list(), std::vector<std::string>{});
}
void ResourceTest::overrideGroup() {
std::ostringstream out;
Debug redirectDebug{&out};
Resource::overrideGroup("test", Directory::join(RESOURCE_TEST_DIR, "resources-overriden.conf"));
Resource r("test");
CORRADE_COMPARE(out.str(), "Utility::Resource: group 'test' overriden with '" + Directory::join(RESOURCE_TEST_DIR, "resources-overriden.conf") + "'\n");
CORRADE_COMPARE(r.get("predisposition.bin"), "overriden predisposition\n");
CORRADE_COMPARE(r.get("consequence2.txt"), "overriden consequence\n");
/* Test that two subsequent r.getRaw() point to the same location */
const auto ptr = r.getRaw("predisposition.bin").begin();
CORRADE_VERIFY(r.getRaw("predisposition.bin").begin() == ptr);
}
void ResourceTest::overrideGroupFallback() {
#ifdef CORRADE_NO_ASSERT
CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions");
#endif
std::ostringstream out;
Warning redirectWarning{&out};
Resource::overrideGroup("test", Directory::join(RESOURCE_TEST_DIR, "resources-overriden-none.conf"));
Resource r("test");
CORRADE_COMPARE_AS(r.get("consequence.bin"),
Directory::join(RESOURCE_TEST_DIR, "consequence.bin"),
TestSuite::Compare::StringToFile);
CORRADE_COMPARE(out.str(), "Utility::Resource::get(): file 'consequence.bin' was not found in overriden group, fallback to compiled-in resources\n");
}
void ResourceTest::overrideNonexistentFile() {
#ifdef CORRADE_NO_ASSERT
CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions");
#endif
std::ostringstream out;
Error redirectError{&out};
Warning redirectWarning(&out);
Resource::overrideGroup("test", Directory::join(RESOURCE_TEST_DIR, "resources-overriden-nonexistent-file.conf"));
Resource r("test");
CORRADE_COMPARE_AS(r.get("consequence.bin"),
Directory::join(RESOURCE_TEST_DIR, "consequence.bin"),
TestSuite::Compare::StringToFile);
CORRADE_COMPARE(out.str(),
"Utility::Resource::get(): cannot open file path/to/nonexistent.bin from overriden group\n"
"Utility::Resource::get(): file 'consequence.bin' was not found in overriden group, fallback to compiled-in resources\n");
}
void ResourceTest::overrideNonexistentGroup() {
#ifdef CORRADE_NO_ASSERT
CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions");
#endif
std::ostringstream out;
Error redirectError{&out};
/* Nonexistent group */
Resource::overrideGroup("nonexistentGroup", {});
CORRADE_COMPARE(out.str(), "Utility::Resource::overrideGroup(): group 'nonexistentGroup' was not found\n");
}
void ResourceTest::overrideDifferentGroup() {
std::ostringstream out;
Resource::overrideGroup("test", Directory::join(RESOURCE_TEST_DIR, "resources-overriden-different.conf"));
Warning redirectWarning{&out};
Resource r("test");
CORRADE_COMPARE(out.str(), "Utility::Resource: overriden with different group, found 'wat' but expected 'test'\n");
}
}}}}
CORRADE_TEST_MAIN(Corrade::Utility::Test::ResourceTest)
|
; A038707: a(n) = floor(n*(n+1/2)/2).
; 0,0,2,5,9,13,19,26,34,42,52,63,75,87,101,116,132,148,166,185,205,225,247,270,294,318,344,371,399,427,457,488,520,552,586,621,657,693,731,770,810,850,892,935,979,1023,1069,1116,1164,1212,1262,1313,1365,1417,1471,1526,1582,1638,1696,1755,1815,1875,1937,2000,2064,2128,2194,2261,2329,2397,2467,2538,2610,2682,2756,2831,2907,2983,3061,3140,3220,3300,3382,3465,3549,3633,3719,3806,3894,3982,4072,4163,4255,4347,4441,4536,4632,4728,4826,4925
mul $0,-2
bin $0,2
div $0,4
|
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long llu;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
//template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
// Add defines here ...
#define endl '\n'
#define F0R(i, a) for (int i = 0; i < (a); ++i)
//#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (b)-1; i >= a; --i)
#define F0RR(i, a) for (int i = (a)-1; i >= 0; --i)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define REPeste(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define FOR(it,c) for ( auto it=(c).begin(); it!=(c).end(); it++ )
#define mp make_pair
#define pback push_back
#define lbound lower_bound
#define ubound upper_bound
const int MAXN = 100000 + 5, MAXNLOG = 22;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int BASE = 31;
const long double EPS = 1e-9;
const double PI = 4*atan(1);
// Input
#define LCHILD(x) ((x)<<1)
#define RCHILD(x) (((x)<<1)+1)
#define RPARENT(x) ((x)>>1)
int N, M, K;
int color[MAXN], maxFreq[MAXN];
ll sum[MAXN], ans[MAXN];
map<int, ll> colorFreq[MAXN];
vi G[MAXN];
void dfs(int p, int u) {
for(auto v : G[u]) {
if(v != p) {
dfs(u, v);
}
}
// init
colorFreq[u][color[u]] = maxFreq[u] = 1;
sum[u] = color[u];
// merge
for(auto v : G[u]) {
if(v != p) {
// Small-To-Large technique
if( colorFreq[u].size() < colorFreq[v].size() ) {
swap(colorFreq[u], colorFreq[v]);
swap(sum[u], sum[v]);
swap(maxFreq[u], maxFreq[v]);
}
// Merge to larger set
for(auto it : colorFreq[v]) {
int col; ll cnt; tie(col, cnt) = it;
colorFreq[u][col] += cnt;
ll newFreq = colorFreq[u][col];
if(newFreq == maxFreq[u]) {
sum[u] += col;
}
else if(newFreq > maxFreq[u]) {
maxFreq[u] = newFreq;
sum[u] = col;
}
}
}
}
// ans
ans[u] = sum[u];
//cout << u << " -> " << colorFreq[u].size() << endl;
}
int main() {
//Input region
#ifdef GHOST
system("subl name.in");
freopen("name.in", "r", stdin);
FILE * FILE_NAME = freopen("name.out", "w", stdout);
int TIME = clock();
#endif
std::ios::sync_with_stdio(false); cin.tie(0);
//Add your code here...
cin >> N;
for (int i = 1; i <= N; ++i) {
cin >> color[i];
}
int u, v;
for (int i = 1; i < N; ++i) {
cin >> u >> v;
G[u].pback(v);
G[v].pback(u);
}
dfs(-1, 1);
for (int i = 1; i <= N; ++i) {
cout << ans[i] << " ";
}
//Output region
#ifdef GHOST
cout << "\n\nTIME: " << (clock() - TIME) << " MS" << endl;
cout.flush();
fclose(FILE_NAME);
system("subl name.out");
#endif
return 0;
} |
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012-2015 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include <ripple/app/ledger/LedgerToJson.h>
#include <ripple/basics/base_uint.h>
namespace ripple {
namespace {
bool isFull(LedgerFill const& fill)
{
return fill.options & LedgerFill::full;
}
bool isExpanded(LedgerFill const& fill)
{
return isFull(fill) || (fill.options & LedgerFill::expand);
}
bool isBinary(LedgerFill const& fill)
{
return fill.options & LedgerFill::binary;
}
template <class Object>
void fillJson(Object& json, bool closed, LedgerInfo const& info, bool bFull)
{
json[jss::parent_hash] = to_string (info.parentHash);
json[jss::ledger_index] = to_string (info.seq);
json[jss::seqNum] = to_string (info.seq); // DEPRECATED
if (closed)
{
json[jss::closed] = true;
}
else if (!bFull)
{
json[jss::closed] = false;
return;
}
json[jss::ledger_hash] = to_string (info.hash);
json[jss::transaction_hash] = to_string (info.txHash);
json[jss::account_hash] = to_string (info.accountHash);
json[jss::total_coins] = to_string (info.drops);
// These next three are DEPRECATED.
json[jss::hash] = to_string (info.hash);
json[jss::totalCoins] = to_string (info.drops);
json[jss::accepted] = closed;
json[jss::close_flags] = info.closeFlags;
// Always show fields that contribute to the ledger hash
json[jss::parent_close_time] = info.parentCloseTime.time_since_epoch().count();
json[jss::close_time] = info.closeTime.time_since_epoch().count();
json[jss::close_time_resolution] = info.closeTimeResolution.count();
if (info.closeTime != NetClock::time_point{})
{
json[jss::close_time_human] = to_string(info.closeTime);
if (! getCloseAgree(info))
json[jss::close_time_estimated] = true;
}
}
template <class Object>
void fillJsonBinary(Object& json, bool closed, LedgerInfo const& info)
{
if (! closed)
json[jss::closed] = false;
else
{
json[jss::closed] = true;
Serializer s;
addRaw (info, s);
json[jss::ledger_data] = strHex (s.peekData ());
}
}
template <class Object>
void fillJsonTx (Object& json, LedgerFill const& fill)
{
auto&& txns = setArray (json, jss::transactions);
auto bBinary = isBinary(fill);
auto bExpanded = isExpanded(fill);
try
{
for (auto& i: fill.ledger.txs)
{
if (! bExpanded)
{
txns.append(to_string(i.first->getTransactionID()));
}
else
{
auto&& txJson = appendObject(txns);
if (bBinary)
{
txJson[jss::tx_blob] = serializeHex(*i.first);
if (i.second)
txJson[jss::meta] = serializeHex(*i.second);
}
else
{
copyFrom(txJson, i.first->getJson(0));
if (i.second)
txJson[jss::metaData] = i.second->getJson(0);
}
if ((fill.options & LedgerFill::ownerFunds) &&
i.first->getTxnType() == ttOFFER_CREATE)
{
auto const account = i.first->getAccountID(sfAccount);
auto const amount = i.first->getFieldAmount(sfTakerGets);
// If the offer create is not self funded then add the
// owner balance
if (account != amount.getIssuer())
{
auto const ownerFunds = accountFunds(fill.ledger,
account, amount, fhIGNORE_FREEZE, beast::Journal());
txJson[jss::owner_funds] = ownerFunds.getText ();
}
}
}
}
}
catch (std::exception const&)
{
// Nothing the user can do about this.
}
}
template <class Object>
void fillJsonState(Object& json, LedgerFill const& fill)
{
auto& ledger = fill.ledger;
auto&& array = Json::setArray (json, jss::accountState);
auto expanded = isExpanded(fill);
auto binary = isBinary(fill);
for(auto const& sle : ledger.sles)
{
if (binary)
{
auto&& obj = appendObject(array);
obj[jss::hash] = to_string(sle->key());
obj[jss::tx_blob] = serializeHex(*sle);
}
else if (expanded)
array.append(sle->getJson(0));
else
array.append(to_string(sle->key()));
}
}
template <class Object>
void fillJson (Object& json, LedgerFill const& fill)
{
// TODO: what happens if bBinary and bExtracted are both set?
// Is there a way to report this back?
auto bFull = isFull(fill);
if (isBinary(fill))
fillJsonBinary(json, !fill.ledger.open(), fill.ledger.info());
else
fillJson(json, !fill.ledger.open(), fill.ledger.info(), bFull);
if (bFull || fill.options & LedgerFill::dumpTzxc)
fillJsonTx(json, fill);
if (bFull || fill.options & LedgerFill::dumpState)
fillJsonState(json, fill);
}
} // namespace
void addJson (Json::Object& json, LedgerFill const& fill)
{
auto&& object = Json::addObject (json, jss::ledger);
fillJson (object, fill);
}
void addJson (Json::Value& json, LedgerFill const& fill)
{
auto&& object = Json::addObject (json, jss::ledger);
fillJson (object, fill);
}
Json::Value getJson (LedgerFill const& fill)
{
Json::Value json;
fillJson (json, fill);
return json;
}
} // ripple
|
; A220700: a(0)=0, a(1)=0; for n>1, a(n) = a(n-1) + (n+3)*a(n-2) + 1
; Submitted by Jon Maiga
; 0,0,1,2,10,27,118,389,1688,6357,28302,117301,541832,2418649,11629794,55165477,276131564,1379441105,7178203950,37525908261,202624599112,1103246397377,6168861375178,34853267706981,201412524836788,1177304020632257,7018267240899110,42337387859866821,259903672327739232,1614700083843477505,10191521270658872162,65091324121337107333,421794568594397633004,2765082236962533496993,18371481274955245918142,123444606279531518803877,839932376002786109611416,5777716627184046861766497,40214944043298277355834554
mov $1,1
mov $2,4
lpb $0
mov $3,1
lpb $3
add $2,1
sub $2,$3
mov $4,$1
cmp $4,1
cmp $4,0
sub $3,$4
add $6,1
add $7,$1
lpe
sub $0,1
mov $1,$6
add $2,1
mul $1,$2
mul $7,$5
mov $5,-1
sub $6,$7
add $7,$6
lpe
mov $0,$7
|
;
; z88dk RS232 Function
;
; OSCA version
;
; unsigned char rs232_init()
;
; $Id: rs232_init.asm,v 1.3 2016-06-23 20:15:37 dom Exp $
SECTION code_clib
PUBLIC rs232_init
PUBLIC _rs232_init
INCLUDE "target/osca/def/osca.def"
rs232_init:
_rs232_init:
xor a
out (sys_timer),a ; timer to overflow every 0.004 secconds
in a,(sys_serial_port) ; clear serial buffer flag by reading port
ld hl,0 ;RS_ERR_OK;
ret
|
.global s_prepare_buffers
s_prepare_buffers:
push %r13
push %r15
push %r8
push %rax
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_D_ht+0x12087, %rsi
lea addresses_WC_ht+0x19163, %rdi
clflush (%rdi)
nop
nop
nop
dec %r8
mov $31, %rcx
rep movsl
nop
nop
nop
dec %rbx
lea addresses_D_ht+0x12649, %rcx
clflush (%rcx)
nop
nop
nop
nop
cmp $59398, %rax
movb (%rcx), %r15b
lfence
lea addresses_D_ht+0x12e37, %r8
xor %r15, %r15
mov (%r8), %esi
nop
nop
nop
nop
nop
inc %rsi
lea addresses_WC_ht+0x195e7, %rdi
nop
add %rsi, %rsi
movb (%rdi), %r15b
cmp %rbx, %rbx
lea addresses_WT_ht+0x4f87, %rax
nop
nop
nop
nop
nop
sub $23949, %rbx
mov $0x6162636465666768, %rsi
movq %rsi, %xmm3
movups %xmm3, (%rax)
nop
nop
nop
nop
xor $56803, %r8
lea addresses_A_ht+0x12da9, %rsi
lea addresses_D_ht+0xa47, %rdi
nop
xor %r15, %r15
mov $58, %rcx
rep movsq
nop
nop
sub %r8, %r8
lea addresses_UC_ht+0x8be7, %rsi
lea addresses_UC_ht+0x18e7, %rdi
nop
nop
nop
nop
nop
sub %r13, %r13
mov $104, %rcx
rep movsl
nop
nop
dec %r13
lea addresses_normal_ht+0xcc87, %rsi
lea addresses_normal_ht+0x2aaf, %rdi
nop
nop
nop
add %r15, %r15
mov $105, %rcx
rep movsw
add %rcx, %rcx
lea addresses_D_ht+0x1dda7, %rsi
lea addresses_UC_ht+0x1666f, %rdi
nop
nop
nop
nop
nop
sub %rbx, %rbx
mov $45, %rcx
rep movsb
nop
cmp %r15, %r15
lea addresses_A_ht+0x19a33, %r13
nop
nop
nop
nop
nop
sub $38789, %rdi
mov $0x6162636465666768, %r8
movq %r8, %xmm5
and $0xffffffffffffffc0, %r13
movaps %xmm5, (%r13)
nop
nop
nop
nop
nop
xor %rcx, %rcx
lea addresses_D_ht+0xade7, %r8
nop
nop
add %rbx, %rbx
movw $0x6162, (%r8)
nop
nop
nop
and $59605, %rax
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rax
pop %r8
pop %r15
pop %r13
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r11
push %r12
push %r9
push %rbx
push %rdi
// Faulty Load
lea addresses_RW+0xa5e7, %r12
nop
nop
nop
nop
nop
xor %rdi, %rdi
movb (%r12), %r10b
lea oracles, %r12
and $0xff, %r10
shlq $12, %r10
mov (%r12,%r10,1), %r10
pop %rdi
pop %rbx
pop %r9
pop %r12
pop %r11
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_RW', 'AVXalign': False, 'congruent': 0, 'size': 4, 'same': False, 'NT': True}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_RW', 'AVXalign': False, 'congruent': 0, 'size': 1, 'same': True, 'NT': True}}
<gen_prepare_buffer>
{'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 3, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 0, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'AVXalign': False, 'congruent': 1, 'size': 1, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'AVXalign': True, 'congruent': 3, 'size': 4, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 10, 'size': 1, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'AVXalign': False, 'congruent': 2, 'size': 16, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 0, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 5, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 9, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 7, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 5, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 2, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 5, 'same': True}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 2, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'AVXalign': True, 'congruent': 0, 'size': 16, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'AVXalign': False, 'congruent': 11, 'size': 2, 'same': False, 'NT': False}}
{'32': 21829}
32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32
*/
|
<%
from pwnlib.shellcraft.powerpc.linux import syscall
%>
<%page args="fd, offset, count, flags"/>
<%docstring>
Invokes the syscall sync_file_range. See 'man 2 sync_file_range' for more information.
Arguments:
fd(int): fd
offset(off64_t): offset
count(off64_t): count
flags(unsigned): flags
</%docstring>
${syscall('SYS_sync_file_range', fd, offset, count, flags)}
|
// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*************************************************************************
* @file FlowControlExampleSubscriber.cpp
* This file contains the implementation of the subscriber functions.
*
* This file was generated by the tool fastcdrgen.
*/
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/subscriber/qos/DataReaderQos.hpp>
#include <fastdds/dds/subscriber/SampleInfo.hpp>
#include "FlowControlExampleSubscriber.h"
using namespace eprosima::fastdds::dds;
using namespace eprosima::fastrtps::rtps;
FlowControlExampleSubscriber::FlowControlExampleSubscriber()
: participant_(nullptr)
, subscriber_(nullptr)
, topic_(nullptr)
, reader_(nullptr)
, myType(new FlowControlExamplePubSubType())
{
}
FlowControlExampleSubscriber::~FlowControlExampleSubscriber()
{
if (reader_ != nullptr)
{
subscriber_->delete_datareader(reader_);
}
if (topic_ != nullptr)
{
participant_->delete_topic(topic_);
}
if (subscriber_ != nullptr)
{
participant_->delete_subscriber(subscriber_);
}
DomainParticipantFactory::get_instance()->delete_participant(participant_);
}
bool FlowControlExampleSubscriber::init()
{
// Create Participant
DomainParticipantQos pqos;
pqos.wire_protocol().builtin.discovery_config.leaseDuration = eprosima::fastrtps::c_TimeInfinite;
pqos.name("Participant_subscriber"); //You can put the name you want
participant_ = DomainParticipantFactory::get_instance()->create_participant(0, pqos);
if (participant_ == nullptr)
{
return false;
}
//Register the type
myType.register_type(participant_);
// Create Subscriber
subscriber_ = participant_->create_subscriber(SUBSCRIBER_QOS_DEFAULT);
if (subscriber_ == nullptr)
{
return false;
}
// Create Topic
topic_ = participant_->create_topic("FlowControlExamplePubSubTopic", myType.get_type_name(), TOPIC_QOS_DEFAULT);
if (topic_ == nullptr)
{
return false;
}
// Create DataReader
reader_ = subscriber_->create_datareader(topic_, DATAREADER_QOS_DEFAULT, &m_listener);
if (reader_ == nullptr)
{
return false;
}
return true;
}
void FlowControlExampleSubscriber::SubListener::on_subscription_matched(
DataReader*,
const SubscriptionMatchedStatus& info)
{
if (info.current_count_change == 1)
{
n_matched = info.total_count;
std::cout << "Subscriber matched." << std::endl;
}
else if (info.current_count_change == -1)
{
n_matched = info.total_count;
std::cout << "Subscriber unmatched." << std::endl;
}
else
{
std::cout << info.current_count_change
<< " is not a valid value for SubscriptionMatchedStatus current count change" << std::endl;
}
}
void FlowControlExampleSubscriber::SubListener::on_data_available(
DataReader* reader)
{
SampleInfo info;
FlowControlExample st;
if (reader->take_next_sample(&st, &info) == ReturnCode_t::RETCODE_OK)
{
if (info.valid_data)
{
++n_msg;
static unsigned int fastMessages = 0;
static unsigned int slowMessages = 0;
// Print your structure data here.
if (st.wasFast())
{
fastMessages++;
std::cout << "Sample received from fast writer, count=" << fastMessages << std::endl;
}
else
{
slowMessages++;
std::cout << "Sample received from slow writer, count=" << slowMessages << std::endl;
}
}
}
}
void FlowControlExampleSubscriber::run()
{
std::cout << "Waiting for Data, press Enter to stop the Subscriber. " << std::endl;
std::cin.ignore();
std::cout << "Shutting down the Subscriber." << std::endl;
}
|
MODULE __printf_get_flags_impl
SECTION code_clib
PUBLIC __printf_get_flags_impl
EXTERN atoi
EXTERN get_16bit_ap_parameter
__printf_get_flags_impl:
ld c,0
flags_again:
push hl ;save fmt
ld b,5
ld hl,flags
flag_loop:
cp (hl)
inc hl
jr nz,no_flag
; We've found a flag
ld a,(hl) ;pick up flags
or c
ld c,a
pop hl ;get fmt back
ld a,(hl) ;pick up next character
inc hl
jr flags_again
flags:
defb '-', 0x01
defb '+', 0x02
defb ' ', 0x08
defb '#', 0x10
defb '0', 0x04
no_flag:
inc hl
djnz flag_loop
pop hl
ld (ix-4),c ;save flags
check_width:
ld (ix-5),0 ;default width=0
ld (ix-6),0
cp '*'
jr nz,check_width_from_format
starred_width:
; width comes from a parameter, later...
push hl ;save format (points to '*'+1)
call get_16bit_ap_parameter ;de=next ap pointer, hl=value
ex de,hl ;de=value, hl=ap
ex (sp),hl ;ap on stack, hl=fmt
;de = value, hl=format
jr save_width
check_width_from_format:
; hl = format
; de = ap
cp '0'
jr c,check_precision
cp '9'+1
jr nc,check_precision
push de ;save ap
dec hl
call atoi ;exits hl=number, de=non numeric in fmt
;TODO, check < 0
ex de,hl ;hl=next format
save_width:
ld (ix-5),d ;store width
ld (ix-6),e
pop de ;get ap back
ld a,(hl)
inc hl
check_precision:
ld (ix-7),255 ;precision = undefined
ld (ix-8),255
cp '.'
jr nz,no_precision
ld a,(hl)
cp '*'
jr nz,check_precision_from_format
; Precision comes from parameter
inc hl
push hl ;save format
call get_16bit_ap_parameter ;de=next ap pointer, hl=value
ex de,hl
ex (sp),hl
;de = value, hl=format
jr save_precision
check_precision_from_format:
;hl=format, de=ap
push de ;save ap
call atoi ;exits hl=number, de=next arg
;TODO, check <0
ex de,hl ;hl=next format acharacter
save_precision:
ld (ix-7),d
ld (ix-8),e
ld a,(hl) ;next character
inc hl
pop de ;restore ap
no_precision:
ret
|
PalletTown_Script:
CheckEvent EVENT_GOT_POKEBALLS_FROM_OAK
jr z, .next
SetEvent EVENT_PALLET_AFTER_GETTING_POKEBALLS
.next
call EnableAutoTextBoxDrawing
ld hl, PalletTown_ScriptPointers
ld a, [wPalletTownCurScript]
jp CallFunctionInTable
PalletTown_ScriptPointers:
dw PalletTownScript0
dw PalletTownScript1
dw PalletTownScript2
dw PalletTownScript3
dw PalletTownScript4
dw PalletTownScript5
dw PalletTownScript6
PalletTownScript0:
CheckEvent EVENT_FOLLOWED_OAK_INTO_LAB
ret nz
ld a, [wYCoord]
cp 1 ; is player near north exit?
ret nz
xor a
ldh [hJoyHeld], a
ld a, PLAYER_DIR_DOWN
ld [wPlayerMovingDirection], a
ld a, SFX_STOP_ALL_MUSIC
call PlaySound
ld a, BANK(Music_MeetProfOak)
ld c, a
ld a, MUSIC_MEET_PROF_OAK ; "oak appears" music
call PlayMusic
ld a, $FC
ld [wJoyIgnore], a
SetEvent EVENT_OAK_APPEARED_IN_PALLET
; trigger the next script
ld a, 1
ld [wPalletTownCurScript], a
ret
PalletTownScript1:
xor a
ld [wcf0d], a
ld a, 1
ldh [hSpriteIndexOrTextID], a
call DisplayTextID
ld a, $FF
ld [wJoyIgnore], a
ld a, HS_PALLET_TOWN_OAK
ld [wMissableObjectIndex], a
predef ShowObject
; trigger the next script
ld a, 2
ld [wPalletTownCurScript], a
ret
PalletTownScript2:
ld a, 1
ldh [hSpriteIndex], a
ld a, SPRITE_FACING_UP
ldh [hSpriteFacingDirection], a
call SetSpriteFacingDirectionAndDelay
call Delay3
ld a, 1
ld [wYCoord], a
ld a, 1
ldh [hNPCPlayerRelativePosPerspective], a
ld a, 1
swap a
ldh [hNPCSpriteOffset], a
predef CalcPositionOfPlayerRelativeToNPC
ld hl, hNPCPlayerYDistance
dec [hl]
predef FindPathToPlayer ; load Oak's movement into wNPCMovementDirections2
ld de, wNPCMovementDirections2
ld a, 1 ; oak
ldh [hSpriteIndex], a
call MoveSprite
ld a, $FF
ld [wJoyIgnore], a
; trigger the next script
ld a, 3
ld [wPalletTownCurScript], a
ret
PalletTownScript3:
ld a, [wd730]
bit 0, a
ret nz
xor a ; ld a, SPRITE_FACING_DOWN
ld [wSpritePlayerStateData1FacingDirection], a
ld a, 1
ld [wcf0d], a
ld a, $FC
ld [wJoyIgnore], a
ld a, 1
ldh [hSpriteIndexOrTextID], a
call DisplayTextID
; set up movement script that causes the player to follow Oak to his lab
ld a, $FF
ld [wJoyIgnore], a
ld a, 1
ld [wSpriteIndex], a
xor a
ld [wNPCMovementScriptFunctionNum], a
ld a, 1
ld [wNPCMovementScriptPointerTableNum], a
ldh a, [hLoadedROMBank]
ld [wNPCMovementScriptBank], a
; trigger the next script
ld a, 4
ld [wPalletTownCurScript], a
ret
PalletTownScript4:
ld a, [wNPCMovementScriptPointerTableNum]
and a ; is the movement script over?
ret nz
; trigger the next script
ld a, 5
ld [wPalletTownCurScript], a
ret
PalletTownScript5:
CheckEvent EVENT_DAISY_WALKING
jr nz, .next
CheckBothEventsSet EVENT_GOT_TOWN_MAP, EVENT_ENTERED_BLUES_HOUSE, 1
jr nz, .next
SetEvent EVENT_DAISY_WALKING
ld a, HS_DAISY_SITTING
ld [wMissableObjectIndex], a
predef HideObject
ld a, HS_DAISY_WALKING
ld [wMissableObjectIndex], a
predef_jump ShowObject
.next
CheckEvent EVENT_GOT_POKEBALLS_FROM_OAK
ret z
SetEvent EVENT_PALLET_AFTER_GETTING_POKEBALLS_2
PalletTownScript6:
ret
PalletTown_TextPointers:
dw PalletTownText1
dw PalletTownText2
dw PalletTownText3
dw PalletTownText4
dw PalletTownText5
dw PalletTownText6
dw PalletTownText7
PalletTownText1:
text_asm
ld a, [wcf0d]
and a
jr nz, .next
ld a, 1
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
ld hl, OakAppearsText
jr .done
.next
ld hl, OakWalksUpText
.done
call PrintText
jp TextScriptEnd
OakAppearsText:
text_far _OakAppearsText
text_asm
ld c, 10
call DelayFrames
xor a
ld [wEmotionBubbleSpriteIndex], a ; player's sprite
ld [wWhichEmotionBubble], a ; EXCLAMATION_BUBBLE
predef EmotionBubble
ld a, PLAYER_DIR_DOWN
ld [wPlayerMovingDirection], a
jp TextScriptEnd
OakWalksUpText:
text_far _OakWalksUpText
text_end
PalletTownText2: ; girl
text_far _PalletTownText2
text_end
PalletTownText3: ; fat man
text_far _PalletTownText3
text_end
PalletTownText4: ; sign by lab
text_far _PalletTownText4
text_end
PalletTownText5: ; sign by fence
text_far _PalletTownText5
text_end
PalletTownText6: ; sign by Red's house
text_far _PalletTownText6
text_end
PalletTownText7: ; sign by Blue's house
text_far _PalletTownText7
text_end
|
/*********************************************************\
* File: Theme.cpp *
*
* Copyright (C) 2002-2013 The PixelLight Team (http://www.pixellight.org/)
*
* This file is part of PixelLight.
*
* 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.
\*********************************************************/
//[-------------------------------------------------------]
//[ Includes ]
//[-------------------------------------------------------]
#include <PLCore/Base/Class.h>
#include "PLGui/Themes/Theme.h"
//[-------------------------------------------------------]
//[ Namespace ]
//[-------------------------------------------------------]
using namespace PLCore;
using namespace PLGraphics;
namespace PLGui {
//[-------------------------------------------------------]
//[ Class implementation ]
//[-------------------------------------------------------]
pl_class_metadata(Theme, "PLGui", PLCore::Object, "GUI theme class")
pl_class_metadata_end(Theme)
//[-------------------------------------------------------]
//[ Public functions ]
//[-------------------------------------------------------]
/**
* @brief
* Constructor
*/
Theme::Theme(Gui &cGui, const String &sName) :
m_pGui(&cGui),
m_sName(sName),
m_cDefaultFont(cGui),
m_cDefaultIcon(cGui),
m_nWindowBorderSize(2),
m_nWindowTitleBarHeight(20),
m_nMenuBarHeight(20),
m_cWindowColor(Color4::White),
m_nPanelBorderSize(2),
m_cPanelColor(0.83f, 0.82f, 0.78f, 1.0f),
m_vSysButtonSize(16, 16)
{
}
/**
* @brief
* Destructor
*/
Theme::~Theme()
{
}
/**
* @brief
* Get owner GUI
*/
Gui *Theme::GetGui() const
{
// Return GUI
return m_pGui;
}
/**
* @brief
* Get name of theme
*/
String Theme::GetName() const
{
// Return name
return m_sName;
}
/**
* @brief
* Get default font
*/
const Font &Theme::GetDefaultFont() const
{
// Return default font
return m_cDefaultFont;
}
/**
* @brief
* Get default icon
*/
const Image &Theme::GetDefaultIcon() const
{
// Return default icon
return m_cDefaultIcon;
}
/**
* @brief
* Get window border size
*/
int Theme::GetWindowBorderSize() const
{
// Return border size
return m_nWindowBorderSize;
}
/**
* @brief
* Get window title bar height
*/
int Theme::GetWindowTitleBarHeight() const
{
// Return title bar height
return m_nWindowTitleBarHeight;
}
/**
* @brief
* Get menu bar height
*/
int Theme::GetMenuBarHeight() const
{
// Return menu bar height
return m_nMenuBarHeight;
}
/**
* @brief
* Get default window color
*/
Color4 Theme::GetWindowColor() const
{
// Return window color
return m_cWindowColor;
}
/**
* @brief
* Get panel border size
*/
int Theme::GetPanelBorderSize() const
{
// Return border size
return m_nPanelBorderSize;
}
/**
* @brief
* Get default panel color
*/
Color4 Theme::GetPanelColor() const
{
// Return panel color
return m_cPanelColor;
}
/**
* @brief
* Get system button size
*/
PLMath::Vector2i Theme::GetSysButtonSize() const
{
// Return system button size
return m_vSysButtonSize;
}
//[-------------------------------------------------------]
//[ Namespace ]
//[-------------------------------------------------------]
} // PLGui
|
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "server.h"
#include <cstdio>
#include <cstring>
#include <sstream>
#include "session.h"
#include "uri_info.h"
#include "logging.h"
#define SERVER_DEFAULT_PAGE "<html><head><title>WebDriver</title></head><body><p id='main'>This is the initial start page for the WebDriver server.</p></body></html>"
#define SERVER_DEFAULT_WHITELIST "127.0.0.1"
#define SERVER_DEFAULT_BLACKLIST "-0.0.0.0/0"
#define HTML_CONTENT_TYPE "text/html"
#define JSON_CONTENT_TYPE "application/json"
#if defined(WINDOWS)
#include <cstdarg>
inline int wd_snprintf(char* str, size_t size, const char* format, ...) {
va_list args;
va_start(args, format);
int count = _vscprintf(format, args);
if (str != NULL && size > 0) {
count = _vsnprintf_s(str, size, _TRUNCATE, format, args);
}
va_end(args);
return count;
}
#define snprintf wd_snprintf
#endif
namespace webdriver {
Server::Server(const int port) {
this->Initialize(port, "", "", "", SERVER_DEFAULT_WHITELIST);
}
Server::Server(const int port, const std::string& host) {
this->Initialize(port, host, "", "", SERVER_DEFAULT_WHITELIST);
}
Server::Server(const int port,
const std::string& host,
const std::string& log_level,
const std::string& log_file) {
this->Initialize(port, host, log_level, log_file, SERVER_DEFAULT_WHITELIST);
}
Server::Server(const int port,
const std::string& host,
const std::string& log_level,
const std::string& log_file,
const std::string& acl) {
this->Initialize(port, host, log_level, log_file, acl);
}
Server::~Server(void) {
SessionMap::iterator it = this->sessions_.begin();
for (; it != this->sessions_.end(); ++it) {
std::string session_id = it->first;
this->ShutDownSession(session_id);
}
}
void Server::Initialize(const int port,
const std::string& host,
const std::string& log_level,
const std::string& log_file,
const std::string& acl) {
LOG::Level(log_level);
LOG::File(log_file);
LOG(INFO) << "Starting WebDriver server on port: '"
<< port << "' on host: '" << host << "'";
this->port_ = port;
this->host_ = host;
if (acl.size() > 0) {
this->ProcessWhitelist(acl);
} else {
this->whitelist_.push_back(SERVER_DEFAULT_WHITELIST);
}
this->PopulateCommandRepository();
}
void Server::ProcessWhitelist(const std::string& whitelist) {
std::string input_copy = whitelist;
while (input_copy.size() > 0) {
size_t delimiter_pos = input_copy.find(",");
std::string token = input_copy.substr(0, delimiter_pos);
if (delimiter_pos == std::string::npos) {
input_copy = "";
} else {
input_copy = input_copy.substr(delimiter_pos + 1);
}
this->whitelist_.push_back(token);
}
}
int Server::OnNewHttpRequest(struct mg_connection* conn) {
mg_context* context = mg_get_context(conn);
Server* current_server = reinterpret_cast<Server*>(mg_get_user_data(context));
mg_request_info* request_info = mg_get_request_info(conn);
int handler_result_code = current_server->ProcessRequest(conn, request_info);
return handler_result_code;
}
bool Server::Start() {
LOG(TRACE) << "Entering Server::Start";
std::string port_format_string = "%s:%d";
if (this->host_.size() == 0) {
// If the host name is an empty string, then we don't want the colon
// in the listening ports string. Remove it from the format string,
// and when we use printf to format, the %s will be replaced by an
// empty string.
port_format_string = "%s%d";
}
int formatted_string_size = snprintf(NULL,
0,
port_format_string.c_str(),
this->host_.c_str(),
this->port_) + 1;
char* listening_ports_buffer = new char[formatted_string_size];
snprintf(listening_ports_buffer,
formatted_string_size,
port_format_string.c_str(),
this->host_.c_str(),
this->port_);
std::string acl = SERVER_DEFAULT_BLACKLIST;
for (std::vector<std::string>::const_iterator it = this->whitelist_.begin();
it < this->whitelist_.end();
++it) {
acl.append(",+").append(*it);
}
LOG(DEBUG) << "Civetweb ACL is " << acl;
const char* options[] = { "listening_ports", listening_ports_buffer,
"access_control_list", acl.c_str(),
// "enable_keep_alive", "yes",
NULL };
mg_callbacks callbacks = {};
callbacks.begin_request = &OnNewHttpRequest;
context_ = mg_start(&callbacks, this, options);
if (context_ == NULL) {
LOG(WARN) << "Failed to start Civetweb";
return false;
}
return true;
}
void Server::Stop() {
LOG(TRACE) << "Entering Server::Stop";
if (context_) {
mg_stop(context_);
context_ = NULL;
}
}
int Server::ProcessRequest(struct mg_connection* conn,
const struct mg_request_info* request_info) {
LOG(TRACE) << "Entering Server::ProcessRequest";
int http_response_code = 0;
std::string http_verb = request_info->request_method;
std::string request_body = "{}";
if (http_verb == "POST") {
request_body = this->ReadRequestBody(conn, request_info);
}
LOG(TRACE) << "Process request with:"
<< " URI: " << request_info->uri
<< " HTTP verb: " << http_verb << std::endl
<< "body: " << request_body;
if (strcmp(request_info->uri, "/") == 0) {
this->SendHttpOk(conn,
request_info,
SERVER_DEFAULT_PAGE,
HTML_CONTENT_TYPE);
http_response_code = 0;
} else if (strcmp(request_info->uri, "/shutdown") == 0) {
this->SendHttpOk(conn,
request_info,
SERVER_DEFAULT_PAGE,
HTML_CONTENT_TYPE);
http_response_code = 0;
this->ShutDown();
} else {
std::string serialized_response = this->DispatchCommand(request_info->uri,
http_verb,
request_body);
http_response_code = this->SendResponseToClient(conn,
request_info,
serialized_response);
}
return http_response_code;
}
void Server::AddCommand(const std::string& url,
const std::string& http_verb,
const std::string& command_name) {
if (this->commands_.find(url) == this->commands_.end()) {
this->commands_[url] = std::tr1::shared_ptr<UriInfo>(
new UriInfo(url, http_verb, command_name));
} else {
this->commands_[url]->AddHttpVerb(http_verb, command_name);
}
}
void Server::ShutDownSession(const std::string& session_id) {
LOG(TRACE) << "Entering Server::ShutDownSession";
SessionMap::iterator it = this->sessions_.find(session_id);
if (it != this->sessions_.end()) {
it->second->ShutDown();
this->sessions_.erase(session_id);
} else {
LOG(DEBUG) << "Shutdown session is not found";
}
}
std::string Server::ReadRequestBody(struct mg_connection* conn,
const struct mg_request_info* request_info) {
LOG(TRACE) << "Entering Server::ReadRequestBody";
std::string request_body = "";
int content_length = 0;
for (int header_index = 0; header_index < 64; ++header_index) {
if (request_info->http_headers[header_index].name == NULL) {
break;
}
if (strcmp(request_info->http_headers[header_index].name,
"Content-Length") == 0) {
content_length = atoi(request_info->http_headers[header_index].value);
break;
}
}
if (content_length == 0) {
request_body = "{}";
} else {
std::vector<char> buffer(content_length + 1);
int bytes_read = 0;
while (bytes_read < content_length) {
bytes_read += mg_read(conn,
&buffer[bytes_read],
content_length - bytes_read);
}
buffer[content_length] = '\0';
request_body.append(&buffer[0]);
}
return request_body;
}
std::string Server::DispatchCommand(const std::string& uri,
const std::string& http_verb,
const std::string& command_body) {
LOG(TRACE) << "Entering Server::DispatchCommand";
std::string session_id = "";
std::string locator_parameters = "";
std::string serialized_response = "";
std::string command = this->LookupCommand(uri,
http_verb,
&session_id,
&locator_parameters);
LOG(DEBUG) << "Command: " << http_verb << " " << uri << " " << command_body;
if (command == webdriver::CommandType::NoCommand) {
// Hand-code the response for an unknown URL
serialized_response.append("{ \"error\" : \"unknown method\", ");
serialized_response.append("\"message\" : \"Command not found: ");
serialized_response.append(http_verb);
serialized_response.append(" ");
serialized_response.append(uri);
serialized_response.append("\" }");
} else if (command == webdriver::CommandType::Status) {
// Status command must be handled by the server, not by the session.
serialized_response = this->GetStatus();
} else if (command == webdriver::CommandType::GetSessionList) {
// GetSessionList command must be handled by the server,
// not by the session.
serialized_response = this->ListSessions();
} else {
SessionHandle session_handle;
if (command != webdriver::CommandType::NewSession &&
!this->LookupSession(session_id, &session_handle)) {
if (command == webdriver::CommandType::Quit) {
// Calling quit on an invalid session should be a no-op.
// Hand-code the response for quit on an invalid (already
// quit) session.
serialized_response.append("{ \"value\" : null }");
} else {
// Hand-code the response for an invalid session id
serialized_response.append("{ \"error\" : \"invalid session id\", ");
serialized_response.append("\"message\" : \"session ");
serialized_response.append(session_id);
serialized_response.append(" does not exist\" }");
}
} else {
// Compile the serialized JSON representation of the command by hand.
std::string serialized_command = "{ \"name\" : \"" + command + "\"";
serialized_command.append(", \"locator\" : ");
serialized_command.append(locator_parameters);
serialized_command.append(", \"parameters\" : ");
serialized_command.append(command_body);
serialized_command.append(" }");
if (command == webdriver::CommandType::NewSession) {
session_handle = this->InitializeSession();
}
bool session_is_valid = session_handle->ExecuteCommand(
serialized_command,
&serialized_response);
if (command == webdriver::CommandType::NewSession) {
Response new_session_response;
new_session_response.Deserialize(serialized_response);
this->sessions_[new_session_response.GetSessionId()] = session_handle;
}
if (!session_is_valid) {
this->ShutDownSession(session_id);
}
}
}
LOG(DEBUG) << "Response: " << serialized_response;
return serialized_response;
}
std::string Server::ListSessions() {
LOG(TRACE) << "Entering Server::ListSessions";
// Manually construct the serialized command for getting
// session capabilities.
std::string get_caps_command = "{ \"name\" : \"" +
webdriver::CommandType::GetSessionCapabilities
+ "\"" +
", \"locator\" : {}, \"parameters\" : {} }";
Json::Value sessions(Json::arrayValue);
SessionMap::iterator it = this->sessions_.begin();
for (; it != this->sessions_.end(); ++it) {
// Each element of the GetSessionList command is an object with two
// named properties, "id" and "capabilities". We already know the
// ID, so we execute the GetSessionCapabilities command on each session
// to be able to return the capabilities.
Json::Value session_descriptor;
session_descriptor["id"] = it->first;
SessionHandle session = it->second;
std::string serialized_session_response;
session->ExecuteCommand(get_caps_command, &serialized_session_response);
Response session_response;
session_response.Deserialize(serialized_session_response);
session_descriptor["capabilities"] = session_response.value();
sessions.append(session_descriptor);
}
Response response;
response.SetSuccessResponse(sessions);
return response.Serialize();
}
bool Server::LookupSession(const std::string& session_id,
SessionHandle* session_handle) {
LOG(TRACE) << "Entering Server::LookupSession";
SessionMap::iterator it = this->sessions_.find(session_id);
if (it == this->sessions_.end()) {
return false;
}
*session_handle = it->second;
return true;
}
int Server::SendResponseToClient(struct mg_connection* conn,
const struct mg_request_info* request_info,
const std::string& serialized_response) {
LOG(TRACE) << "Entering Server::SendResponseToClient";
int return_code = 0;
if (serialized_response.size() > 0) {
Response response;
response.Deserialize(serialized_response);
return_code = response.GetHttpResponseCode();
if (return_code == 0) {
this->SendHttpOk(conn,
request_info,
serialized_response,
HTML_CONTENT_TYPE);
return_code = 200;
} else if (return_code == 200) {
this->SendHttpOk(conn,
request_info,
serialized_response,
JSON_CONTENT_TYPE);
} else if (return_code == 303) {
std::string location = response.value().asString();
response.SetSuccessResponse(response.value());
this->SendHttpSeeOther(conn, request_info, location);
return_code = 303;
} else if (return_code == 400) {
this->SendHttpBadRequest(conn, request_info, serialized_response);
return_code = 400;
} else if (return_code == 404) {
this->SendHttpNotFound(conn, request_info, serialized_response);
return_code = 404;
} else if (return_code == 405) {
std::string parameters = response.value().asString();
this->SendHttpMethodNotAllowed(conn, request_info, parameters);
return_code = 405;
} else if (return_code == 501) {
this->SendHttpNotImplemented(conn,
request_info,
"");
return_code = 501;
} else {
this->SendHttpInternalError(conn, request_info, serialized_response);
return_code = 500;
}
}
return return_code;
}
// The standard HTTP Status codes are implemented below. Chrome uses
// OK, See Other, Not Found, Method Not Allowed, and Internal Error.
// Internal Error, HTTP 500, is used as a catch all for any issue
// not covered in the JSON protocol.
void Server::SendHttpOk(struct mg_connection* connection,
const struct mg_request_info* request_info,
const std::string& body,
const std::string& content_type) {
LOG(TRACE) << "Entering Server::SendHttpOk";
std::ostringstream out;
out << "HTTP/1.1 200 OK\r\n"
<< "Content-Length: " << strlen(body.c_str()) << "\r\n"
<< "Content-Type: " << content_type << "; charset=UTF-8\r\n"
<< "Cache-Control: no-cache\r\n"
<< "Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept\r\n"
<< "Accept-Ranges: bytes\r\n"
<< "Connection: close\r\n\r\n";
if (strcmp(request_info->request_method, "HEAD") != 0) {
out << body << "\r\n";
}
mg_write(connection, out.str().c_str(), out.str().size());
}
void Server::SendHttpBadRequest(struct mg_connection* const connection,
const struct mg_request_info* request_info,
const std::string& body) {
LOG(TRACE) << "Entering Server::SendHttpBadRequest";
std::ostringstream out;
out << "HTTP/1.1 400 Bad Request\r\n"
<< "Content-Length: " << strlen(body.c_str()) << "\r\n"
<< "Content-Type: application/json; charset=UTF-8\r\n"
<< "Cache-Control: no-cache\r\n"
<< "Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept\r\n"
<< "Accept-Ranges: bytes\r\n"
<< "Connection: close\r\n\r\n";
if (strcmp(request_info->request_method, "HEAD") != 0) {
out << body << "\r\n";
}
mg_printf(connection, "%s", out.str().c_str());
}
void Server::SendHttpInternalError(struct mg_connection* connection,
const struct mg_request_info* request_info,
const std::string& body) {
LOG(TRACE) << "Entering Server::SendHttpInternalError";
std::ostringstream out;
out << "HTTP/1.1 500 Internal Server Error\r\n"
<< "Content-Length: " << strlen(body.c_str()) << "\r\n"
<< "Content-Type: application/json; charset=UTF-8\r\n"
<< "Cache-Control: no-cache\r\n"
<< "Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept\r\n"
<< "Accept-Ranges: bytes\r\n"
<< "Connection: close\r\n\r\n";
if (strcmp(request_info->request_method, "HEAD") != 0) {
out << body << "\r\n";
}
mg_write(connection, out.str().c_str(), out.str().size());
}
void Server::SendHttpNotFound(struct mg_connection* const connection,
const struct mg_request_info* request_info,
const std::string& body) {
LOG(TRACE) << "Entering Server::SendHttpNotFound";
std::ostringstream out;
out << "HTTP/1.1 404 Not Found\r\n"
<< "Content-Length: " << strlen(body.c_str()) << "\r\n"
<< "Content-Type: application/json; charset=UTF-8\r\n"
<< "Cache-Control: no-cache\r\n"
<< "Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept\r\n"
<< "Accept-Ranges: bytes\r\n"
<< "Connection: close\r\n\r\n";
if (strcmp(request_info->request_method, "HEAD") != 0) {
out << body << "\r\n";
}
mg_printf(connection, "%s", out.str().c_str());
}
void Server::SendHttpMethodNotAllowed(
struct mg_connection* connection,
const struct mg_request_info* request_info,
const std::string& allowed_methods) {
LOG(TRACE) << "Entering Server::SendHttpMethodNotAllowed";
std::ostringstream out;
out << "HTTP/1.1 405 Method Not Allowed\r\n"
<< "Content-Type: text/html\r\n"
<< "Content-Length: 0\r\n"
<< "Allow: " << allowed_methods << "\r\n\r\n";
mg_write(connection, out.str().c_str(), out.str().size());
}
void Server::SendHttpTimeout(struct mg_connection* connection,
const struct mg_request_info* request_info,
const std::string& body) {
LOG(TRACE) << "Entering Server::SendHttpTimeout";
std::ostringstream out;
out << "HTTP/1.1 408 Timeout\r\n\r\n"
<< "Content-Length: " << strlen(body.c_str()) << "\r\n"
<< "Content-Type: application/json; charset=UTF-8\r\n"
<< "Cache-Control: no-cache\r\n"
<< "Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept\r\n"
<< "Accept-Ranges: bytes\r\n"
<< "Connection: close\r\n\r\n";
mg_write(connection, out.str().c_str(), out.str().size());
}
void Server::SendHttpNotImplemented(struct mg_connection* connection,
const struct mg_request_info* request_info,
const std::string& body) {
LOG(TRACE) << "Entering Server::SendHttpNotImplemented";
std::ostringstream out;
out << "HTTP/1.1 501 Not Implemented\r\n\r\n";
mg_write(connection, out.str().c_str(), out.str().size());
}
void Server::SendHttpSeeOther(struct mg_connection* connection,
const struct mg_request_info* request_info,
const std::string& location) {
LOG(TRACE) << "Entering Server::SendHttpSeeOther";
std::ostringstream out;
out << "HTTP/1.1 303 See Other\r\n"
<< "Location: " << location << "\r\n"
<< "Content-Type: text/html\r\n"
<< "Content-Length: 0\r\n\r\n";
mg_write(connection, out.str().c_str(), out.str().size());
}
std::string Server::LookupCommand(const std::string& uri,
const std::string& http_verb,
std::string* session_id,
std::string* locator) {
LOG(TRACE) << "Entering Server::LookupCommand";
std::string value = webdriver::CommandType::NoCommand;
std::vector<std::string> url_fragments;
UriInfo::ParseUri(uri, &url_fragments, NULL);
UrlMap::const_iterator it = this->commands_.begin();
for (; it != this->commands_.end(); ++it) {
std::vector<std::string> locator_param_names;
std::vector<std::string> locator_param_values;
if (it->second->IsUriMatch(url_fragments,
&locator_param_names,
&locator_param_values)) {
if (it->second->HasHttpVerb(http_verb, &value)) {
std::string param = this->ConstructLocatorParameterJson(
locator_param_names, locator_param_values, session_id);
locator->append(param);
} else {
locator->append(it->second->GetSupportedVerbs());
}
break;
}
}
return value;
}
std::string Server::ConstructLocatorParameterJson(
std::vector<std::string> locator_param_names,
std::vector<std::string> locator_param_values,
std::string* session_id) {
std::string param = "{";
size_t param_count = locator_param_names.size();
for (unsigned int i = 0; i < param_count; i++) {
if (i != 0) {
param.append(",");
}
param.append(" \"");
param.append(locator_param_names[i]);
param.append("\" : \"");
param.append(locator_param_values[i]);
param.append("\"");
if (locator_param_names[i] == "sessionid") {
session_id->append(locator_param_values[i]);
}
}
param.append(" }");
return param;
}
void Server::PopulateCommandRepository() {
LOG(TRACE) << "Entering Server::PopulateCommandRepository";
this->AddCommand("/session", "POST", webdriver::CommandType::NewSession);
this->AddCommand("/session/:sessionid", "DELETE", webdriver::CommandType::Quit);
this->AddCommand("/status", "GET", webdriver::CommandType::Status);
this->AddCommand("/session/:sessionid/timeouts", "GET", webdriver::CommandType::GetTimeouts);
this->AddCommand("/session/:sessionid/timeouts", "POST", webdriver::CommandType::SetTimeouts);
this->AddCommand("/session/:sessionid/url", "GET", webdriver::CommandType::GetCurrentUrl);
this->AddCommand("/session/:sessionid/url", "POST", webdriver::CommandType::Get);
this->AddCommand("/session/:sessionid/back", "POST", webdriver::CommandType::GoBack);
this->AddCommand("/session/:sessionid/forward", "POST", webdriver::CommandType::GoForward);
this->AddCommand("/session/:sessionid/refresh", "POST", webdriver::CommandType::Refresh);
this->AddCommand("/session/:sessionid/title", "GET", webdriver::CommandType::GetTitle);
this->AddCommand("/session/:sessionid/window", "GET", webdriver::CommandType::GetCurrentWindowHandle);
this->AddCommand("/session/:sessionid/window", "POST", webdriver::CommandType::SwitchToWindow);
this->AddCommand("/session/:sessionid/window", "DELETE", webdriver::CommandType::CloseWindow);
this->AddCommand("/session/:sessionid/window/handles", "GET", webdriver::CommandType::GetWindowHandles);
this->AddCommand("/session/:sessionid/frame", "POST", webdriver::CommandType::SwitchToFrame);
this->AddCommand("/session/:sessionid/frame/parent", "POST", webdriver::CommandType::SwitchToParentFrame);
this->AddCommand("/session/:sessionid/window/rect", "GET", webdriver::CommandType::GetWindowRect);
this->AddCommand("/session/:sessionid/window/rect", "POST", webdriver::CommandType::SetWindowRect);
this->AddCommand("/session/:sessionid/window/maximize", "POST", webdriver::CommandType::MaximizeWindow);
this->AddCommand("/session/:sessionid/window/minimize", "POST", webdriver::CommandType::MinimizeWindow);
this->AddCommand("/session/:sessionid/window/fullscreen", "POST", webdriver::CommandType::FullscreenWindow);
this->AddCommand("/session/:sessionid/element/active", "GET", webdriver::CommandType::GetActiveElement);
this->AddCommand("/session/:sessionid/element", "POST", webdriver::CommandType::FindElement);
this->AddCommand("/session/:sessionid/elements", "POST", webdriver::CommandType::FindElements);
this->AddCommand("/session/:sessionid/element/:id/element", "POST", webdriver::CommandType::FindChildElement);
this->AddCommand("/session/:sessionid/element/:id/elements", "POST", webdriver::CommandType::FindChildElements);
this->AddCommand("/session/:sessionid/element/:id/selected", "GET", webdriver::CommandType::IsElementSelected);
this->AddCommand("/session/:sessionid/element/:id/attribute/:name", "GET", webdriver::CommandType::GetElementAttribute);
this->AddCommand("/session/:sessionid/element/:id/property/:name", "GET", webdriver::CommandType::GetElementProperty);
this->AddCommand("/session/:sessionid/element/:id/css/:propertyName", "GET", webdriver::CommandType::GetElementValueOfCssProperty);
this->AddCommand("/session/:sessionid/element/:id/text", "GET", webdriver::CommandType::GetElementText);
this->AddCommand("/session/:sessionid/element/:id/name", "GET", webdriver::CommandType::GetElementTagName);
this->AddCommand("/session/:sessionid/element/:id/rect", "GET", webdriver::CommandType::GetElementRect);
this->AddCommand("/session/:sessionid/element/:id/enabled", "GET", webdriver::CommandType::IsElementEnabled);
this->AddCommand("/session/:sessionid/element/:id/click", "POST", webdriver::CommandType::ClickElement);
this->AddCommand("/session/:sessionid/element/:id/clear", "POST", webdriver::CommandType::ClearElement);
this->AddCommand("/session/:sessionid/element/:id/value", "POST", webdriver::CommandType::SendKeysToElement);
this->AddCommand("/session/:sessionid/source", "GET", webdriver::CommandType::GetPageSource);
this->AddCommand("/session/:sessionid/execute/sync", "POST", webdriver::CommandType::ExecuteScript);
this->AddCommand("/session/:sessionid/execute/async", "POST", webdriver::CommandType::ExecuteAsyncScript);
this->AddCommand("/session/:sessionid/cookie", "GET", webdriver::CommandType::GetAllCookies);
this->AddCommand("/session/:sessionid/cookie/:name", "GET", webdriver::CommandType::GetNamedCookie);
this->AddCommand("/session/:sessionid/cookie", "POST", webdriver::CommandType::AddCookie);
this->AddCommand("/session/:sessionid/cookie", "DELETE", webdriver::CommandType::DeleteAllCookies);
this->AddCommand("/session/:sessionid/cookie/:name", "DELETE", webdriver::CommandType::DeleteNamedCookie);
this->AddCommand("/session/:sessionid/actions", "POST", webdriver::CommandType::Actions);
this->AddCommand("/session/:sessionid/actions", "DELETE", webdriver::CommandType::ReleaseActions);
this->AddCommand("/session/:sessionid/alert/dismiss", "POST", webdriver::CommandType::DismissAlert);
this->AddCommand("/session/:sessionid/alert/accept", "POST", webdriver::CommandType::AcceptAlert);
this->AddCommand("/session/:sessionid/alert/text", "GET", webdriver::CommandType::GetAlertText);
this->AddCommand("/session/:sessionid/alert/text", "POST", webdriver::CommandType::SendKeysToAlert);
this->AddCommand("/session/:sessionid/screenshot", "GET", webdriver::CommandType::Screenshot);
this->AddCommand("/session/:sessionid/element/:id/screenshot", "GET", webdriver::CommandType::ElementScreenshot);
// Additional commands required to be supported, but not defined
// in the specification.
this->AddCommand("/session/:sessionid/alert/credentials", "POST", webdriver::CommandType::SetAlertCredentials);
this->AddCommand("/session/:sessionid/element/:id/displayed", "GET", webdriver::CommandType::IsElementDisplayed);
this->AddCommand("/session/:sessionid/element/:id/equals/:other", "GET", webdriver::CommandType::ElementEquals);
this->AddCommand("/sessions", "GET", webdriver::CommandType::GetSessionList);
this->AddCommand("/session/:sessionid", "GET", webdriver::CommandType::GetSessionCapabilities);
this->AddCommand("/session/:sessionid/ime/available_engines", "GET", webdriver::CommandType::ListAvailableImeEngines);
this->AddCommand("/session/:sessionid/ime/active_engines", "GET", webdriver::CommandType::GetActiveImeEngine);
this->AddCommand("/session/:sessionid/ime/activated", "GET", webdriver::CommandType::IsImeActivated);
this->AddCommand("/session/:sessionid/ime/activate", "POST", webdriver::CommandType::ActivateImeEngine);
this->AddCommand("/session/:sessionid/ime/deactivate", "POST", webdriver::CommandType::DeactivateImeEngine);
}
} // namespace webdriver
|
; A178525: The sum of the costs of all nodes in the Fibonacci tree of order n.
; 0,0,3,8,22,49,104,208,403,760,1406,2561,4608,8208,14499,25432,44342,76913,132808,228416,391475,668840,1139518,1936513,3283392,5555424,9381699,15815528,26618518,44733745,75073256,125827696,210642643
mov $2,$0
lpb $0,1
sub $0,1
add $3,$0
mov $1,$3
add $3,$2
mov $2,$1
lpe
|
; void *tshc_saddrpleft(void *saddr, uchar bitmask)
SECTION code_clib
SECTION code_arch
PUBLIC tshc_saddrpleft
EXTERN zx_saddrpleft
defc tshc_saddrpleft = zx_saddrpleft
; SDCC bridge for Classic
IF __CLASSIC
PUBLIC _tshc_saddrpleft
defc _tshc_saddrpleft = tshc_saddrpleft
ENDIF
|
; A022370: Fibonacci sequence beginning 2, 16.
; 2,16,18,34,52,86,138,224,362,586,948,1534,2482,4016,6498,10514,17012,27526,44538,72064,116602,188666,305268,493934,799202,1293136,2092338,3385474,5477812,8863286,14341098,23204384,37545482,60749866,98295348,159045214,257340562,416385776,673726338,1090112114,1763838452,2853950566,4617789018,7471739584,12089528602,19561268186,31650796788,51212064974,82862861762,134074926736,216937788498,351012715234,567950503732,918963218966,1486913722698,2405876941664,3892790664362,6298667606026,10191458270388,16490125876414,26681584146802,43171710023216,69853294170018,113025004193234,182878298363252,295903302556486,478781600919738,774684903476224,1253466504395962,2028151407872186,3281617912268148,5309769320140334,8591387232408482
mov $1,1
mov $3,8
lpb $0
sub $0,1
mov $2,$1
mov $1,$3
add $3,$2
lpe
mul $1,2
|
; A165229: a(n) = 12*a(n-1) - 6*a(n-2), with a(0)=1, a(1)=6.
; Submitted by Jon Maiga
; 1,6,66,756,8676,99576,1142856,13116816,150544656,1727834976,19830751776,227602011456,2612239626816,29981263453056,344101723675776,3949333103390976,45327386898637056,520232644163298816,5970827408567763456,68528533037833368576,786517432002593842176,9027037985804125894656,103605351237633947682816,1189101986936782616825856,13647591735815587715813376,156636488908166356888805376,1797752316483102756370784256,20633208864348234935116578816,236811992473280202683174240256,2717944656493273022587391410176
mov $3,1
lpb $0
sub $0,1
mul $1,5
add $3,$1
add $2,$3
mov $1,$2
mul $3,6
lpe
mov $0,$3
|
; A266155: Triangle read by rows giving successive states of cellular automaton generated by "Rule 19" initiated with a single ON (black) cell.
; 1,1,0,1,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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
sub $0,2
lpb $0
mov $1,$0
cal $1,266253 ; Triangle read by rows giving successive states of cellular automaton generated by "Rule 11" initiated with a single ON (black) cell.
mov $0,0
lpe
|
.global s_prepare_buffers
s_prepare_buffers:
push %r13
push %r14
push %r8
push %r9
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_A_ht+0x1de10, %r9
nop
nop
nop
cmp $49453, %rdx
mov $0x6162636465666768, %r14
movq %r14, %xmm5
vmovups %ymm5, (%r9)
nop
nop
nop
nop
nop
and $63277, %r9
lea addresses_WT_ht+0x1572c, %rdi
nop
inc %r13
mov (%rdi), %cx
nop
nop
nop
nop
nop
dec %rcx
lea addresses_WT_ht+0x10924, %r14
nop
nop
and $50794, %r9
movb $0x61, (%r14)
nop
nop
nop
nop
add $55181, %rdx
lea addresses_D_ht+0x3330, %r9
nop
add $58375, %r8
mov (%r9), %edi
xor %r14, %r14
lea addresses_normal_ht+0x1ab30, %rdi
nop
add %rcx, %rcx
mov (%rdi), %edx
nop
and %r13, %r13
lea addresses_D_ht+0x2345, %rdx
clflush (%rdx)
nop
nop
nop
dec %r9
mov (%rdx), %r13d
nop
nop
cmp $38026, %rcx
lea addresses_WT_ht+0x6330, %rsi
lea addresses_normal_ht+0x13e78, %rdi
clflush (%rdi)
nop
nop
nop
cmp $37901, %r9
mov $18, %rcx
rep movsw
nop
nop
nop
nop
nop
add $22844, %r8
lea addresses_A_ht+0x1ef30, %r14
nop
nop
nop
nop
nop
xor $6962, %rdx
mov (%r14), %rcx
nop
nop
nop
nop
nop
cmp %rcx, %rcx
lea addresses_normal_ht+0x16130, %r13
nop
nop
nop
nop
nop
and $42903, %rcx
movl $0x61626364, (%r13)
nop
nop
nop
nop
nop
cmp %rcx, %rcx
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %r9
pop %r8
pop %r14
pop %r13
ret
.global s_faulty_load
s_faulty_load:
push %r13
push %r8
push %r9
push %rax
push %rbx
push %rcx
push %rdi
push %rsi
// Load
lea addresses_D+0x9330, %rsi
nop
nop
nop
nop
nop
and %rax, %rax
movups (%rsi), %xmm2
vpextrq $1, %xmm2, %r8
nop
nop
add %rbx, %rbx
// Store
lea addresses_PSE+0x17f30, %r13
clflush (%r13)
nop
nop
and %rcx, %rcx
mov $0x5152535455565758, %r8
movq %r8, %xmm7
movups %xmm7, (%r13)
nop
nop
nop
add $64372, %rax
// REPMOV
lea addresses_A+0x17330, %rsi
lea addresses_UC+0x1163, %rdi
nop
nop
sub $2897, %rbx
mov $65, %rcx
rep movsb
nop
nop
nop
xor $63208, %r9
// Faulty Load
lea addresses_D+0x9330, %rbx
nop
inc %r13
mov (%rbx), %r8w
lea oracles, %rcx
and $0xff, %r8
shlq $12, %r8
mov (%rcx,%r8,1), %r8
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rax
pop %r9
pop %r8
pop %r13
ret
/*
<gen_faulty_load>
[REF]
{'src': {'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 0, 'same': False, 'type': 'addresses_D'}, 'OP': 'LOAD'}
{'src': {'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 0, 'same': True, 'type': 'addresses_D'}, 'OP': 'LOAD'}
{'dst': {'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 10, 'same': False, 'type': 'addresses_PSE'}, 'OP': 'STOR'}
{'src': {'congruent': 8, 'same': False, 'type': 'addresses_A'}, 'dst': {'congruent': 0, 'same': False, 'type': 'addresses_UC'}, 'OP': 'REPM'}
[Faulty Load]
{'src': {'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 0, 'same': True, 'type': 'addresses_D'}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'dst': {'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 4, 'same': True, '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': 2, 'same': False, 'type': 'addresses_WT_ht'}, 'OP': 'STOR'}
{'src': {'NT': True, 'AVXalign': False, 'size': 4, 'congruent': 9, 'same': False, 'type': 'addresses_D_ht'}, 'OP': 'LOAD'}
{'src': {'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 11, 'same': False, 'type': 'addresses_normal_ht'}, 'OP': 'LOAD'}
{'src': {'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 0, 'same': False, 'type': 'addresses_D_ht'}, 'OP': 'LOAD'}
{'src': {'congruent': 9, 'same': False, 'type': 'addresses_WT_ht'}, 'dst': {'congruent': 2, 'same': False, 'type': 'addresses_normal_ht'}, 'OP': 'REPM'}
{'src': {'NT': False, 'AVXalign': True, 'size': 8, 'congruent': 9, 'same': False, 'type': 'addresses_A_ht'}, 'OP': 'LOAD'}
{'dst': {'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 9, 'same': False, 'type': 'addresses_normal_ht'}, 'OP': 'STOR'}
{'36': 21829}
36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36
*/
|
/*
* Copyright 2011-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//
// Author: andrei.alexandrescu@fb.com
#include <folly/FBString.h>
#include <atomic>
#include <cstdlib>
#include <iomanip>
#include <list>
#include <sstream>
#include <boost/algorithm/string.hpp>
#include <boost/random.hpp>
#include <folly/Conv.h>
#include <folly/Portability.h>
#include <folly/Random.h>
#include <folly/container/Foreach.h>
#include <folly/portability/GTest.h>
using namespace std;
using namespace folly;
namespace {
static const int seed = folly::randomNumberSeed();
typedef boost::mt19937 RandomT;
static RandomT rng(seed);
static const size_t maxString = 100;
static const bool avoidAliasing = true;
template <class Integral1, class Integral2>
Integral2 random(Integral1 low, Integral2 up) {
boost::uniform_int<> range(low, up);
return range(rng);
}
template <class String>
void randomString(String* toFill, unsigned int maxSize = 1000) {
assert(toFill);
toFill->resize(random(0, maxSize));
FOR_EACH (i, *toFill) {
*i = random('a', 'z');
}
}
template <class String, class Integral>
void Num2String(String& str, Integral n) {
std::string tmp = folly::to<std::string>(n);
str = String(tmp.begin(), tmp.end());
}
std::list<char> RandomList(unsigned int maxSize) {
std::list<char> lst(random(0u, maxSize));
std::list<char>::iterator i = lst.begin();
for (; i != lst.end(); ++i) {
*i = random('a', 'z');
}
return lst;
}
} // namespace
////////////////////////////////////////////////////////////////////////////////
// Tests begin here
////////////////////////////////////////////////////////////////////////////////
template <class String> void clause11_21_4_2_a(String & test) {
test.String::~String();
new(&test) String();
}
template <class String> void clause11_21_4_2_b(String & test) {
String test2(test);
assert(test2 == test);
}
template <class String> void clause11_21_4_2_c(String & test) {
// Test move constructor. There is a more specialized test, see
// TEST(FBString, testMoveCtor)
String donor(test);
String test2(std::move(donor));
EXPECT_EQ(test2, test);
// Technically not required, but all implementations that actually
// support move will move large strings. Make a guess for 128 as the
// maximum small string optimization that's reasonable.
EXPECT_LE(donor.size(), 128);
}
template <class String> void clause11_21_4_2_d(String & test) {
// Copy constructor with position and length
const size_t pos = random(0, test.size());
String s(test, pos, random(0, 9)
? random(0, (size_t)(test.size() - pos))
: String::npos); // test for npos, too, in 10% of the cases
test = s;
}
template <class String> void clause11_21_4_2_e(String & test) {
// Constructor from char*, size_t
const size_t
pos = random(0, test.size()),
n = random(0, test.size() - pos);
String before(test.data(), test.size());
String s(test.c_str() + pos, n);
String after(test.data(), test.size());
EXPECT_EQ(before, after);
test.swap(s);
}
template <class String> void clause11_21_4_2_f(String & test) {
// Constructor from char*
const size_t pos = random(0, test.size());
String before(test.data(), test.size());
String s(test.c_str() + pos);
String after(test.data(), test.size());
EXPECT_EQ(before, after);
test.swap(s);
}
template <class String> void clause11_21_4_2_g(String & test) {
// Constructor from size_t, char
const size_t n = random(0, test.size());
const auto c = test.front();
test = String(n, c);
}
template <class String> void clause11_21_4_2_h(String & test) {
// Constructors from various iterator pairs
// Constructor from char*, char*
String s1(test.begin(), test.end());
EXPECT_EQ(test, s1);
String s2(test.data(), test.data() + test.size());
EXPECT_EQ(test, s2);
// Constructor from other iterators
std::list<char> lst;
for (auto c : test) {
lst.push_back(c);
}
String s3(lst.begin(), lst.end());
EXPECT_EQ(test, s3);
// Constructor from wchar_t iterators
std::list<wchar_t> lst1;
for (auto c : test) {
lst1.push_back(c);
}
String s4(lst1.begin(), lst1.end());
EXPECT_EQ(test, s4);
// Constructor from wchar_t pointers
wchar_t t[20];
t[0] = 'a';
t[1] = 'b';
fbstring s5(t, t + 2);;
EXPECT_EQ("ab", s5);
}
template <class String> void clause11_21_4_2_i(String & test) {
// From initializer_list<char>
std::initializer_list<typename String::value_type>
il = { 'h', 'e', 'l', 'l', 'o' };
String s(il);
test.swap(s);
}
template <class String> void clause11_21_4_2_j(String & test) {
// Assignment from const String&
auto size = random(0, 2000);
String s(size, '\0');
EXPECT_EQ(s.size(), size);
FOR_EACH_RANGE (i, 0, s.size()) {
s[i] = random('a', 'z');
}
test = s;
}
template <class String> void clause11_21_4_2_k(String & test) {
// Assignment from String&&
auto size = random(0, 2000);
String s(size, '\0');
EXPECT_EQ(s.size(), size);
FOR_EACH_RANGE (i, 0, s.size()) {
s[i] = random('a', 'z');
}
test = std::move(s);
if (typeid(String) == typeid(fbstring)) {
EXPECT_LE(s.size(), 128);
}
}
template <class String> void clause11_21_4_2_l(String & test) {
// Assignment from char*
String s(random(0, 1000), '\0');
size_t i = 0;
for (; i != s.size(); ++i) {
s[i] = random('a', 'z');
}
test = s.c_str();
}
template <class String> void clause11_21_4_2_lprime(String & test) {
// Aliased assign
const size_t pos = random(0, test.size());
if (avoidAliasing) {
test = String(test.c_str() + pos);
} else {
test = test.c_str() + pos;
}
}
template <class String> void clause11_21_4_2_m(String & test) {
// Assignment from char
using value_type = typename String::value_type;
test = random(static_cast<value_type>('a'), static_cast<value_type>('z'));
}
template <class String> void clause11_21_4_2_n(String & test) {
// Assignment from initializer_list<char>
initializer_list<typename String::value_type>
il = { 'h', 'e', 'l', 'l', 'o' };
test = il;
}
template <class String> void clause11_21_4_3(String & test) {
// Iterators. The code below should leave test unchanged
EXPECT_EQ(test.size(), test.end() - test.begin());
EXPECT_EQ(test.size(), test.rend() - test.rbegin());
EXPECT_EQ(test.size(), test.cend() - test.cbegin());
EXPECT_EQ(test.size(), test.crend() - test.crbegin());
auto s = test.size();
test.resize(test.end() - test.begin());
EXPECT_EQ(s, test.size());
test.resize(test.rend() - test.rbegin());
EXPECT_EQ(s, test.size());
}
template <class String> void clause11_21_4_4(String & test) {
// exercise capacity, size, max_size
EXPECT_EQ(test.size(), test.length());
EXPECT_LE(test.size(), test.max_size());
EXPECT_LE(test.capacity(), test.max_size());
EXPECT_LE(test.size(), test.capacity());
// exercise shrink_to_fit. Nonbinding request so we can't really do
// much beyond calling it.
auto copy = test;
copy.reserve(copy.capacity() * 3);
copy.shrink_to_fit();
EXPECT_EQ(copy, test);
// exercise empty
string empty("empty");
string notempty("not empty");
if (test.empty()) {
test = String(empty.begin(), empty.end());
} else {
test = String(notempty.begin(), notempty.end());
}
}
template <class String> void clause11_21_4_5(String & test) {
// exercise element access
if (!test.empty()) {
EXPECT_EQ(test[0], test.front());
EXPECT_EQ(test[test.size() - 1], test.back());
auto const i = random(0, test.size() - 1);
EXPECT_EQ(test[i], test.at(i));
test = test[i];
}
}
template <class String> void clause11_21_4_6_1(String & test) {
// 21.3.5 modifiers (+=)
String test1;
randomString(&test1);
assert(test1.size() == char_traits
<typename String::value_type>::length(test1.c_str()));
auto len = test.size();
test += test1;
EXPECT_EQ(test.size(), test1.size() + len);
FOR_EACH_RANGE (i, 0, test1.size()) {
EXPECT_EQ(test[len + i], test1[i]);
}
// aliasing modifiers
String test2 = test;
auto dt = test2.data();
auto sz = test.c_str();
len = test.size();
EXPECT_EQ(memcmp(sz, dt, len), 0);
String copy(test.data(), test.size());
EXPECT_EQ(char_traits
<typename String::value_type>::length(test.c_str()), len);
test += test;
//test.append(test);
EXPECT_EQ(test.size(), 2 * len);
EXPECT_EQ(char_traits
<typename String::value_type>::length(test.c_str()), 2 * len);
FOR_EACH_RANGE (i, 0, len) {
EXPECT_EQ(test[i], copy[i]);
EXPECT_EQ(test[i], test[len + i]);
}
len = test.size();
EXPECT_EQ(char_traits
<typename String::value_type>::length(test.c_str()), len);
// more aliasing
auto const pos = random(0, test.size());
EXPECT_EQ(char_traits
<typename String::value_type>::length(test.c_str() + pos), len - pos);
if (avoidAliasing) {
String addMe(test.c_str() + pos);
EXPECT_EQ(addMe.size(), len - pos);
test += addMe;
} else {
test += test.c_str() + pos;
}
EXPECT_EQ(test.size(), 2 * len - pos);
// single char
len = test.size();
test += random('a', 'z');
EXPECT_EQ(test.size(), len + 1);
// initializer_list
initializer_list<typename String::value_type> il { 'a', 'b', 'c' };
test += il;
}
template <class String> void clause11_21_4_6_2(String & test) {
// 21.3.5 modifiers (append, push_back)
String s;
// Test with a small string first
char c = random('a', 'z');
s.push_back(c);
EXPECT_EQ(s[s.size() - 1], c);
EXPECT_EQ(s.size(), 1);
s.resize(s.size() - 1);
randomString(&s, maxString);
test.append(s);
randomString(&s, maxString);
test.append(s, random(0, s.size()), random(0, maxString));
randomString(&s, maxString);
test.append(s.c_str(), random(0, s.size()));
randomString(&s, maxString);
test.append(s.c_str());
test.append(random(0, maxString), random('a', 'z'));
std::list<char> lst(RandomList(maxString));
test.append(lst.begin(), lst.end());
c = random('a', 'z');
test.push_back(c);
EXPECT_EQ(test[test.size() - 1], c);
// initializer_list
initializer_list<typename String::value_type> il { 'a', 'b', 'c' };
test.append(il);
}
template <class String> void clause11_21_4_6_3_a(String & test) {
// assign
String s;
randomString(&s);
test.assign(s);
EXPECT_EQ(test, s);
// move assign
test.assign(std::move(s));
if (typeid(String) == typeid(fbstring)) {
EXPECT_LE(s.size(), 128);
}
}
template <class String> void clause11_21_4_6_3_b(String & test) {
// assign
String s;
randomString(&s, maxString);
test.assign(s, random(0, s.size()), random(0, maxString));
}
template <class String> void clause11_21_4_6_3_c(String & test) {
// assign
String s;
randomString(&s, maxString);
test.assign(s.c_str(), random(0, s.size()));
}
template <class String> void clause11_21_4_6_3_d(String & test) {
// assign
String s;
randomString(&s, maxString);
test.assign(s.c_str());
}
template <class String> void clause11_21_4_6_3_e(String & test) {
// assign
String s;
randomString(&s, maxString);
test.assign(random(0, maxString), random('a', 'z'));
}
template <class String> void clause11_21_4_6_3_f(String & test) {
// assign from bidirectional iterator
std::list<char> lst(RandomList(maxString));
test.assign(lst.begin(), lst.end());
}
template <class String> void clause11_21_4_6_3_g(String & test) {
// assign from aliased source
test.assign(test);
}
template <class String> void clause11_21_4_6_3_h(String & test) {
// assign from aliased source
test.assign(test, random(0, test.size()), random(0, maxString));
}
template <class String> void clause11_21_4_6_3_i(String & test) {
// assign from aliased source
test.assign(test.c_str(), random(0, test.size()));
}
template <class String> void clause11_21_4_6_3_j(String & test) {
// assign from aliased source
test.assign(test.c_str());
}
template <class String> void clause11_21_4_6_3_k(String & test) {
// assign from initializer_list
initializer_list<typename String::value_type> il { 'a', 'b', 'c' };
test.assign(il);
}
template <class String> void clause11_21_4_6_4(String & test) {
// insert
String s;
randomString(&s, maxString);
test.insert(random(0, test.size()), s);
randomString(&s, maxString);
test.insert(random(0, test.size()),
s, random(0, s.size()),
random(0, maxString));
randomString(&s, maxString);
test.insert(random(0, test.size()),
s.c_str(), random(0, s.size()));
randomString(&s, maxString);
test.insert(random(0, test.size()), s.c_str());
test.insert(random(0, test.size()),
random(0, maxString), random('a', 'z'));
typename String::size_type pos = random(0, test.size());
typename String::iterator res =
test.insert(test.begin() + pos, random('a', 'z'));
EXPECT_EQ(res - test.begin(), pos);
std::list<char> lst(RandomList(maxString));
pos = random(0, test.size());
// Uncomment below to see a bug in gcc
/*res = */test.insert(test.begin() + pos, lst.begin(), lst.end());
// insert from initializer_list
initializer_list<typename String::value_type> il { 'a', 'b', 'c' };
pos = random(0, test.size());
// Uncomment below to see a bug in gcc
/*res = */test.insert(test.begin() + pos, il);
// Test with actual input iterators
stringstream ss;
ss << "hello cruel world";
auto i = istream_iterator<char>(ss);
test.insert(test.begin(), i, istream_iterator<char>());
}
template <class String> void clause11_21_4_6_5(String & test) {
// erase and pop_back
if (!test.empty()) {
test.erase(random(0, test.size()), random(0, maxString));
}
if (!test.empty()) {
// TODO: is erase(end()) allowed?
test.erase(test.begin() + random(0, test.size() - 1));
}
if (!test.empty()) {
auto const i = test.begin() + random(0, test.size());
if (i != test.end()) {
test.erase(i, i + random(0, size_t(test.end() - i)));
}
}
if (!test.empty()) {
// Can't test pop_back with std::string, doesn't support it yet.
//test.pop_back();
}
}
template <class String> void clause11_21_4_6_6(String & test) {
auto pos = random(0, test.size());
if (avoidAliasing) {
test.replace(pos, random(0, test.size() - pos),
String(test));
} else {
test.replace(pos, random(0, test.size() - pos), test);
}
pos = random(0, test.size());
String s;
randomString(&s, maxString);
test.replace(pos, pos + random(0, test.size() - pos), s);
auto pos1 = random(0, test.size());
auto pos2 = random(0, test.size());
if (avoidAliasing) {
test.replace(pos1, pos1 + random(0, test.size() - pos1),
String(test),
pos2, pos2 + random(0, test.size() - pos2));
} else {
test.replace(pos1, pos1 + random(0, test.size() - pos1),
test, pos2, pos2 + random(0, test.size() - pos2));
}
pos1 = random(0, test.size());
String str;
randomString(&str, maxString);
pos2 = random(0, str.size());
test.replace(pos1, pos1 + random(0, test.size() - pos1),
str, pos2, pos2 + random(0, str.size() - pos2));
pos = random(0, test.size());
if (avoidAliasing) {
test.replace(pos, random(0, test.size() - pos),
String(test).c_str(), test.size());
} else {
test.replace(pos, random(0, test.size() - pos),
test.c_str(), test.size());
}
pos = random(0, test.size());
randomString(&str, maxString);
test.replace(pos, pos + random(0, test.size() - pos),
str.c_str(), str.size());
pos = random(0, test.size());
randomString(&str, maxString);
test.replace(pos, pos + random(0, test.size() - pos),
str.c_str());
pos = random(0, test.size());
test.replace(pos, random(0, test.size() - pos),
random(0, maxString), random('a', 'z'));
pos = random(0, test.size());
if (avoidAliasing) {
auto newString = String(test);
test.replace(
test.begin() + pos,
test.begin() + pos + random(0, test.size() - pos),
newString);
} else {
test.replace(
test.begin() + pos,
test.begin() + pos + random(0, test.size() - pos),
test);
}
pos = random(0, test.size());
if (avoidAliasing) {
auto newString = String(test);
test.replace(
test.begin() + pos,
test.begin() + pos + random(0, test.size() - pos),
newString.c_str(),
test.size() - random(0, test.size()));
} else {
test.replace(
test.begin() + pos,
test.begin() + pos + random(0, test.size() - pos),
test.c_str(),
test.size() - random(0, test.size()));
}
pos = random(0, test.size());
auto const n = random(0, test.size() - pos);
typename String::iterator b = test.begin();
String str1;
randomString(&str1, maxString);
const String & str3 = str1;
const typename String::value_type* ss = str3.c_str();
test.replace(
b + pos,
b + pos + n,
ss);
pos = random(0, test.size());
test.replace(
test.begin() + pos,
test.begin() + pos + random(0, test.size() - pos),
random(0, maxString), random('a', 'z'));
}
template <class String> void clause11_21_4_6_7(String & test) {
std::vector<typename String::value_type>
vec(random(0, maxString));
if (vec.empty()) {
return;
}
test.copy(vec.data(), vec.size(), random(0, test.size()));
}
template <class String> void clause11_21_4_6_8(String & test) {
String s;
randomString(&s, maxString);
s.swap(test);
}
template <class String> void clause11_21_4_7_1(String & test) {
// 21.3.6 string operations
// exercise c_str() and data()
assert(test.c_str() == test.data());
// exercise get_allocator()
String s;
randomString(&s, maxString);
DCHECK(test.get_allocator() == s.get_allocator());
}
template <class String> void clause11_21_4_7_2_a(String & test) {
String str = test.substr(
random(0, test.size()),
random(0, test.size()));
Num2String(test, test.find(str, random(0, test.size())));
}
template <class String> void clause11_21_4_7_2_a1(String & test) {
String str = String(test).substr(
random(0, test.size()),
random(0, test.size()));
Num2String(test, test.find(str, random(0, test.size())));
}
template <class String> void clause11_21_4_7_2_a2(String & test) {
auto const& cTest = test;
String str = cTest.substr(
random(0, test.size()),
random(0, test.size()));
Num2String(test, test.find(str, random(0, test.size())));
}
template <class String> void clause11_21_4_7_2_b(String & test) {
auto from = random(0, test.size());
auto length = random(0, test.size() - from);
String str = test.substr(from, length);
Num2String(test, test.find(str.c_str(),
random(0, test.size()),
random(0, str.size())));
}
template <class String> void clause11_21_4_7_2_b1(String & test) {
auto from = random(0, test.size());
auto length = random(0, test.size() - from);
String str = String(test).substr(from, length);
Num2String(test, test.find(str.c_str(),
random(0, test.size()),
random(0, str.size())));
}
template <class String> void clause11_21_4_7_2_b2(String & test) {
auto from = random(0, test.size());
auto length = random(0, test.size() - from);
const auto& cTest = test;
String str = cTest.substr(from, length);
Num2String(test, test.find(str.c_str(),
random(0, test.size()),
random(0, str.size())));
}
template <class String> void clause11_21_4_7_2_c(String & test) {
String str = test.substr(
random(0, test.size()),
random(0, test.size()));
Num2String(test, test.find(str.c_str(),
random(0, test.size())));
}
template <class String> void clause11_21_4_7_2_c1(String & test) {
String str = String(test).substr(
random(0, test.size()),
random(0, test.size()));
Num2String(test, test.find(str.c_str(),
random(0, test.size())));
}
template <class String> void clause11_21_4_7_2_c2(String & test) {
const auto& cTest = test;
String str = cTest.substr(
random(0, test.size()),
random(0, test.size()));
Num2String(test, test.find(str.c_str(),
random(0, test.size())));
}
template <class String> void clause11_21_4_7_2_d(String & test) {
Num2String(test, test.find(
random('a', 'z'),
random(0, test.size())));
}
template <class String> void clause11_21_4_7_3_a(String & test) {
String str = test.substr(
random(0, test.size()),
random(0, test.size()));
Num2String(test, test.rfind(str, random(0, test.size())));
}
template <class String> void clause11_21_4_7_3_b(String & test) {
String str = test.substr(
random(0, test.size()),
random(0, test.size()));
Num2String(test, test.rfind(str.c_str(),
random(0, test.size()),
random(0, str.size())));
}
template <class String> void clause11_21_4_7_3_c(String & test) {
String str = test.substr(
random(0, test.size()),
random(0, test.size()));
Num2String(test, test.rfind(str.c_str(),
random(0, test.size())));
}
template <class String> void clause11_21_4_7_3_d(String & test) {
Num2String(test, test.rfind(
random('a', 'z'),
random(0, test.size())));
}
template <class String> void clause11_21_4_7_4_a(String & test) {
String str;
randomString(&str, maxString);
Num2String(test, test.find_first_of(str,
random(0, test.size())));
}
template <class String> void clause11_21_4_7_4_b(String & test) {
String str;
randomString(&str, maxString);
Num2String(test, test.find_first_of(str.c_str(),
random(0, test.size()),
random(0, str.size())));
}
template <class String> void clause11_21_4_7_4_c(String & test) {
String str;
randomString(&str, maxString);
Num2String(test, test.find_first_of(str.c_str(),
random(0, test.size())));
}
template <class String> void clause11_21_4_7_4_d(String & test) {
Num2String(test, test.find_first_of(
random('a', 'z'),
random(0, test.size())));
}
template <class String> void clause11_21_4_7_5_a(String & test) {
String str;
randomString(&str, maxString);
Num2String(test, test.find_last_of(str,
random(0, test.size())));
}
template <class String> void clause11_21_4_7_5_b(String & test) {
String str;
randomString(&str, maxString);
Num2String(test, test.find_last_of(str.c_str(),
random(0, test.size()),
random(0, str.size())));
}
template <class String> void clause11_21_4_7_5_c(String & test) {
String str;
randomString(&str, maxString);
Num2String(test, test.find_last_of(str.c_str(),
random(0, test.size())));
}
template <class String> void clause11_21_4_7_5_d(String & test) {
Num2String(test, test.find_last_of(
random('a', 'z'),
random(0, test.size())));
}
template <class String> void clause11_21_4_7_6_a(String & test) {
String str;
randomString(&str, maxString);
Num2String(test, test.find_first_not_of(str,
random(0, test.size())));
}
template <class String> void clause11_21_4_7_6_b(String & test) {
String str;
randomString(&str, maxString);
Num2String(test, test.find_first_not_of(str.c_str(),
random(0, test.size()),
random(0, str.size())));
}
template <class String> void clause11_21_4_7_6_c(String & test) {
String str;
randomString(&str, maxString);
Num2String(test, test.find_first_not_of(str.c_str(),
random(0, test.size())));
}
template <class String> void clause11_21_4_7_6_d(String & test) {
Num2String(test, test.find_first_not_of(
random('a', 'z'),
random(0, test.size())));
}
template <class String> void clause11_21_4_7_7_a(String & test) {
String str;
randomString(&str, maxString);
Num2String(test, test.find_last_not_of(str,
random(0, test.size())));
}
template <class String> void clause11_21_4_7_7_b(String & test) {
String str;
randomString(&str, maxString);
Num2String(test, test.find_last_not_of(str.c_str(),
random(0, test.size()),
random(0, str.size())));
}
template <class String> void clause11_21_4_7_7_c(String & test) {
String str;
randomString(&str, maxString);
Num2String(test, test.find_last_not_of(str.c_str(),
random(0, test.size())));
}
template <class String> void clause11_21_4_7_7_d(String & test) {
Num2String(test, test.find_last_not_of(
random('a', 'z'),
random(0, test.size())));
}
template <class String> void clause11_21_4_7_8(String & test) {
test = test.substr(random(0, test.size()), random(0, test.size()));
}
template <class String> void clause11_21_4_7_9_a(String & test) {
String s;
randomString(&s, maxString);
int tristate = test.compare(s);
if (tristate > 0) {
tristate = 1;
} else if (tristate < 0) {
tristate = 2;
}
Num2String(test, tristate);
}
template <class String> void clause11_21_4_7_9_b(String & test) {
String s;
randomString(&s, maxString);
int tristate = test.compare(
random(0, test.size()),
random(0, test.size()),
s);
if (tristate > 0) {
tristate = 1;
} else if (tristate < 0) {
tristate = 2;
}
Num2String(test, tristate);
}
template <class String> void clause11_21_4_7_9_c(String & test) {
String str;
randomString(&str, maxString);
int tristate = test.compare(
random(0, test.size()),
random(0, test.size()),
str,
random(0, str.size()),
random(0, str.size()));
if (tristate > 0) {
tristate = 1;
} else if (tristate < 0) {
tristate = 2;
}
Num2String(test, tristate);
}
template <class String> void clause11_21_4_7_9_d(String & test) {
String s;
randomString(&s, maxString);
int tristate = test.compare(s.c_str());
if (tristate > 0) {
tristate = 1;
} else if (tristate < 0) {
tristate = 2;
}
Num2String(test, tristate);
}
template <class String> void clause11_21_4_7_9_e(String & test) {
String str;
randomString(&str, maxString);
int tristate = test.compare(
random(0, test.size()),
random(0, test.size()),
str.c_str(),
random(0, str.size()));
if (tristate > 0) {
tristate = 1;
} else if (tristate < 0) {
tristate = 2;
}
Num2String(test, tristate);
}
template <class String> void clause11_21_4_8_1_a(String & test) {
String s1;
randomString(&s1, maxString);
String s2;
randomString(&s2, maxString);
test = s1 + s2;
}
template <class String> void clause11_21_4_8_1_b(String & test) {
String s1;
randomString(&s1, maxString);
String s2;
randomString(&s2, maxString);
test = move(s1) + s2;
}
template <class String> void clause11_21_4_8_1_c(String & test) {
String s1;
randomString(&s1, maxString);
String s2;
randomString(&s2, maxString);
test = s1 + move(s2);
}
template <class String> void clause11_21_4_8_1_d(String & test) {
String s1;
randomString(&s1, maxString);
String s2;
randomString(&s2, maxString);
test = move(s1) + move(s2);
}
template <class String> void clause11_21_4_8_1_e(String & test) {
String s;
randomString(&s, maxString);
String s1;
randomString(&s1, maxString);
test = s.c_str() + s1;
}
template <class String> void clause11_21_4_8_1_f(String & test) {
String s;
randomString(&s, maxString);
String s1;
randomString(&s1, maxString);
test = s.c_str() + move(s1);
}
template <class String> void clause11_21_4_8_1_g(String & test) {
String s;
randomString(&s, maxString);
test = typename String::value_type(random('a', 'z')) + s;
}
template <class String> void clause11_21_4_8_1_h(String & test) {
String s;
randomString(&s, maxString);
test = typename String::value_type(random('a', 'z')) + move(s);
}
template <class String> void clause11_21_4_8_1_i(String & test) {
String s;
randomString(&s, maxString);
String s1;
randomString(&s1, maxString);
test = s + s1.c_str();
}
template <class String> void clause11_21_4_8_1_j(String & test) {
String s;
randomString(&s, maxString);
String s1;
randomString(&s1, maxString);
test = move(s) + s1.c_str();
}
template <class String> void clause11_21_4_8_1_k(String & test) {
String s;
randomString(&s, maxString);
test = s + typename String::value_type(random('a', 'z'));
}
template <class String> void clause11_21_4_8_1_l(String & test) {
String s;
randomString(&s, maxString);
String s1;
randomString(&s1, maxString);
test = move(s) + s1.c_str();
}
// Numbering here is from C++11
template <class String> void clause11_21_4_8_9_a(String & test) {
basic_stringstream<typename String::value_type> stst(test.c_str());
String str;
while (stst) {
stst >> str;
test += str + test;
}
}
TEST(FBString, testAllClauses) {
EXPECT_TRUE(1) << "Starting with seed: " << seed;
std::string r;
folly::fbstring c;
#if FOLLY_HAVE_WCHAR_SUPPORT
std::wstring wr;
folly::basic_fbstring<wchar_t> wc;
#endif
int count = 0;
auto l = [&](const char * const clause,
void(*f_string)(std::string&),
void(*f_fbstring)(folly::fbstring&),
void(*f_wfbstring)(folly::basic_fbstring<wchar_t>&)) {
do {
if (true) {
} else {
EXPECT_TRUE(1) << "Testing clause " << clause;
}
randomString(&r);
c = r;
EXPECT_EQ(c, r);
#if FOLLY_HAVE_WCHAR_SUPPORT
wr = std::wstring(r.begin(), r.end());
wc = folly::basic_fbstring<wchar_t>(wr.c_str());
#endif
auto localSeed = seed + count;
rng = RandomT(localSeed);
f_string(r);
rng = RandomT(localSeed);
f_fbstring(c);
EXPECT_EQ(r, c)
<< "Lengths: " << r.size() << " vs. " << c.size()
<< "\nReference: '" << r << "'"
<< "\nActual: '" << c.data()[0] << "'";
#if FOLLY_HAVE_WCHAR_SUPPORT
rng = RandomT(localSeed);
f_wfbstring(wc);
int wret = wcslen(wc.c_str());
auto mbv = std::vector<char>(wret + 1);
auto mb = mbv.data();
int ret = wcstombs(mb, wc.c_str(), wret + 1);
if (ret == wret) {
mb[wret] = '\0';
}
const char *mc = c.c_str();
std::string one(mb);
std::string two(mc);
EXPECT_EQ(one, two);
#endif
} while (++count % 100 != 0);
};
#define TEST_CLAUSE(x) \
l(#x, \
clause11_##x<std::string>, \
clause11_##x<folly::fbstring>, \
clause11_##x<folly::basic_fbstring<wchar_t>>);
TEST_CLAUSE(21_4_2_a);
TEST_CLAUSE(21_4_2_b);
TEST_CLAUSE(21_4_2_c);
TEST_CLAUSE(21_4_2_d);
TEST_CLAUSE(21_4_2_e);
TEST_CLAUSE(21_4_2_f);
TEST_CLAUSE(21_4_2_g);
TEST_CLAUSE(21_4_2_h);
TEST_CLAUSE(21_4_2_i);
TEST_CLAUSE(21_4_2_j);
TEST_CLAUSE(21_4_2_k);
TEST_CLAUSE(21_4_2_l);
TEST_CLAUSE(21_4_2_lprime);
TEST_CLAUSE(21_4_2_m);
TEST_CLAUSE(21_4_2_n);
TEST_CLAUSE(21_4_3);
TEST_CLAUSE(21_4_4);
TEST_CLAUSE(21_4_5);
TEST_CLAUSE(21_4_6_1);
TEST_CLAUSE(21_4_6_2);
TEST_CLAUSE(21_4_6_3_a);
TEST_CLAUSE(21_4_6_3_b);
TEST_CLAUSE(21_4_6_3_c);
TEST_CLAUSE(21_4_6_3_d);
TEST_CLAUSE(21_4_6_3_e);
TEST_CLAUSE(21_4_6_3_f);
TEST_CLAUSE(21_4_6_3_g);
TEST_CLAUSE(21_4_6_3_h);
TEST_CLAUSE(21_4_6_3_i);
TEST_CLAUSE(21_4_6_3_j);
TEST_CLAUSE(21_4_6_3_k);
TEST_CLAUSE(21_4_6_4);
TEST_CLAUSE(21_4_6_5);
TEST_CLAUSE(21_4_6_6);
TEST_CLAUSE(21_4_6_7);
TEST_CLAUSE(21_4_6_8);
TEST_CLAUSE(21_4_7_1);
TEST_CLAUSE(21_4_7_2_a);
TEST_CLAUSE(21_4_7_2_a1);
TEST_CLAUSE(21_4_7_2_a2);
TEST_CLAUSE(21_4_7_2_b);
TEST_CLAUSE(21_4_7_2_b1);
TEST_CLAUSE(21_4_7_2_b2);
TEST_CLAUSE(21_4_7_2_c);
TEST_CLAUSE(21_4_7_2_c1);
TEST_CLAUSE(21_4_7_2_c2);
TEST_CLAUSE(21_4_7_2_d);
TEST_CLAUSE(21_4_7_3_a);
TEST_CLAUSE(21_4_7_3_b);
TEST_CLAUSE(21_4_7_3_c);
TEST_CLAUSE(21_4_7_3_d);
TEST_CLAUSE(21_4_7_4_a);
TEST_CLAUSE(21_4_7_4_b);
TEST_CLAUSE(21_4_7_4_c);
TEST_CLAUSE(21_4_7_4_d);
TEST_CLAUSE(21_4_7_5_a);
TEST_CLAUSE(21_4_7_5_b);
TEST_CLAUSE(21_4_7_5_c);
TEST_CLAUSE(21_4_7_5_d);
TEST_CLAUSE(21_4_7_6_a);
TEST_CLAUSE(21_4_7_6_b);
TEST_CLAUSE(21_4_7_6_c);
TEST_CLAUSE(21_4_7_6_d);
TEST_CLAUSE(21_4_7_7_a);
TEST_CLAUSE(21_4_7_7_b);
TEST_CLAUSE(21_4_7_7_c);
TEST_CLAUSE(21_4_7_7_d);
TEST_CLAUSE(21_4_7_8);
TEST_CLAUSE(21_4_7_9_a);
TEST_CLAUSE(21_4_7_9_b);
TEST_CLAUSE(21_4_7_9_c);
TEST_CLAUSE(21_4_7_9_d);
TEST_CLAUSE(21_4_7_9_e);
TEST_CLAUSE(21_4_8_1_a);
TEST_CLAUSE(21_4_8_1_b);
TEST_CLAUSE(21_4_8_1_c);
TEST_CLAUSE(21_4_8_1_d);
TEST_CLAUSE(21_4_8_1_e);
TEST_CLAUSE(21_4_8_1_f);
TEST_CLAUSE(21_4_8_1_g);
TEST_CLAUSE(21_4_8_1_h);
TEST_CLAUSE(21_4_8_1_i);
TEST_CLAUSE(21_4_8_1_j);
TEST_CLAUSE(21_4_8_1_k);
TEST_CLAUSE(21_4_8_1_l);
TEST_CLAUSE(21_4_8_9_a);
}
TEST(FBString, testGetline) {
string s1 = "\
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras accumsan \n\
elit ut urna consectetur in sagittis mi auctor. Nulla facilisi. In nec \n\
dolor leo, vitae imperdiet neque. Donec ut erat mauris, a faucibus \n\
elit. Integer consectetur gravida augue, sit amet mattis mauris auctor \n\
sed. Morbi congue libero eu nunc sodales adipiscing. In lectus nunc, \n\
vulputate a fringilla at, venenatis quis justo. Proin eu velit \n\
nibh. Maecenas vitae tellus eros. Pellentesque habitant morbi \n\
tristique senectus et netus et malesuada fames ac turpis \n\
egestas. Vivamus faucibus feugiat consequat. Donec fermentum neque sit \n\
amet ligula suscipit porta. Phasellus facilisis felis in purus luctus \n\
quis posuere leo tempor. Nam nunc purus, luctus a pharetra ut, \n\
placerat at dui. Donec imperdiet, diam quis convallis pulvinar, dui \n\
est commodo lorem, ut tincidunt diam nibh et nibh. Maecenas nec velit \n\
massa, ut accumsan magna. Donec imperdiet tempor nisi et \n\
laoreet. Phasellus lectus quam, ultricies ut tincidunt in, dignissim \n\
id eros. Mauris vulputate tortor nec neque pellentesque sagittis quis \n\
sed nisl. In diam lacus, lobortis ut posuere nec, ornare id quam.";
vector<fbstring> v;
boost::split(v, s1, boost::is_any_of("\n"));
{
istringstream input(s1);
fbstring line;
FOR_EACH (i, v) {
EXPECT_TRUE(!getline(input, line).fail());
EXPECT_EQ(line, *i);
}
}
}
TEST(FBString, testMoveCtor) {
// Move constructor. Make sure we allocate a large string, so the
// small string optimization doesn't kick in.
auto size = random(100, 2000);
fbstring s(size, 'a');
fbstring test = std::move(s);
EXPECT_TRUE(s.empty());
EXPECT_EQ(size, test.size());
}
TEST(FBString, testMoveAssign) {
// Move constructor. Make sure we allocate a large string, so the
// small string optimization doesn't kick in.
auto size = random(100, 2000);
fbstring s(size, 'a');
fbstring test;
test = std::move(s);
EXPECT_TRUE(s.empty());
EXPECT_EQ(size, test.size());
}
TEST(FBString, testMoveOperatorPlusLhs) {
// Make sure we allocate a large string, so the
// small string optimization doesn't kick in.
auto size1 = random(100, 2000);
auto size2 = random(100, 2000);
fbstring s1(size1, 'a');
fbstring s2(size2, 'b');
fbstring test;
test = std::move(s1) + s2;
EXPECT_TRUE(s1.empty());
EXPECT_EQ(size1 + size2, test.size());
}
TEST(FBString, testMoveOperatorPlusRhs) {
// Make sure we allocate a large string, so the
// small string optimization doesn't kick in.
auto size1 = random(100, 2000);
auto size2 = random(100, 2000);
fbstring s1(size1, 'a');
fbstring s2(size2, 'b');
fbstring test;
test = s1 + std::move(s2);
EXPECT_EQ(size1 + size2, test.size());
}
// The GNU C++ standard library throws an std::logic_error when an std::string
// is constructed with a null pointer. Verify that we mirror this behavior.
//
// N.B. We behave this way even if the C++ library being used is something
// other than libstdc++. Someday if we deem it important to present
// identical undefined behavior for other platforms, we can re-visit this.
TEST(FBString, testConstructionFromLiteralZero) {
EXPECT_THROW(fbstring s(nullptr), std::logic_error);
}
TEST(FBString, testFixedBugs) {
{ // D479397
fbstring str(1337, 'f');
fbstring cp = str;
cp.clear();
cp.c_str();
EXPECT_EQ(str.front(), 'f');
}
{ // D481173
fbstring str(1337, 'f');
for (int i = 0; i < 2; ++i) {
fbstring cp = str;
cp[1] = 'b';
EXPECT_EQ(cp.c_str()[cp.size()], '\0');
cp.push_back('?');
}
}
{ // D580267
{
fbstring str(1337, 'f');
fbstring cp = str;
cp.push_back('f');
}
{
fbstring str(1337, 'f');
fbstring cp = str;
cp += "bb";
}
}
{ // D661622
folly::basic_fbstring<wchar_t> s;
EXPECT_EQ(0, s.size());
}
{ // D785057
fbstring str(1337, 'f');
std::swap(str, str);
EXPECT_EQ(1337, str.size());
}
{ // D1012196, --allocator=malloc
fbstring str(128, 'f');
str.clear(); // Empty medium string.
fbstring copy(str); // Medium string of 0 capacity.
copy.push_back('b');
EXPECT_GE(copy.capacity(), 1);
}
{ // D2813713
fbstring s1("a");
s1.reserve(8); // Trigger the optimized code path.
auto test1 = '\0' + std::move(s1);
EXPECT_EQ(2, test1.size());
fbstring s2(1, '\0');
s2.reserve(8);
auto test2 = "a" + std::move(s2);
EXPECT_EQ(2, test2.size());
}
{ // D3698862
EXPECT_EQ(fbstring().find(fbstring(), 4), fbstring::npos);
}
if (usingJEMalloc()) { // D4355440
fbstring str(1337, 'f');
str.reserve(3840);
EXPECT_NE(str.capacity(), 3840);
struct {
std::atomic<size_t> refCount_;
} dummyRefCounted;
EXPECT_EQ(
str.capacity(),
goodMallocSize(3840) - sizeof(dummyRefCounted) - sizeof(char));
}
}
TEST(FBString, findWithNpos) {
fbstring fbstr("localhost:80");
EXPECT_EQ(fbstring::npos, fbstr.find(":", fbstring::npos));
}
TEST(FBString, testHash) {
fbstring a;
fbstring b;
a.push_back(0);
a.push_back(1);
b.push_back(0);
b.push_back(2);
std::hash<fbstring> hashfunc;
EXPECT_NE(hashfunc(a), hashfunc(b));
}
#if FOLLY_HAVE_WCHAR_SUPPORT
TEST(FBString, testHashChar16) {
using u16fbstring = folly::basic_fbstring<char16_t>;
u16fbstring a;
u16fbstring b;
a.push_back(0);
a.push_back(1);
b.push_back(0);
b.push_back(2);
std::hash<u16fbstring> hashfunc;
EXPECT_NE(hashfunc(a), hashfunc(b));
}
#endif
TEST(FBString, testFrontBack) {
fbstring str("hello");
EXPECT_EQ(str.front(), 'h');
EXPECT_EQ(str.back(), 'o');
str.front() = 'H';
EXPECT_EQ(str.front(), 'H');
str.back() = 'O';
EXPECT_EQ(str.back(), 'O');
EXPECT_EQ(str, "HellO");
}
TEST(FBString, noexcept) {
EXPECT_TRUE(noexcept(fbstring()));
fbstring x;
EXPECT_FALSE(noexcept(fbstring(x)));
EXPECT_TRUE(noexcept(fbstring(std::move(x))));
fbstring y;
EXPECT_FALSE(noexcept(y = x));
EXPECT_TRUE(noexcept(y = std::move(x)));
}
TEST(FBString, iomanip) {
stringstream ss;
fbstring fbstr("Hello");
ss << setw(6) << fbstr;
EXPECT_EQ(ss.str(), " Hello");
ss.str("");
ss << left << setw(6) << fbstr;
EXPECT_EQ(ss.str(), "Hello ");
ss.str("");
ss << right << setw(6) << fbstr;
EXPECT_EQ(ss.str(), " Hello");
ss.str("");
ss << setw(4) << fbstr;
EXPECT_EQ(ss.str(), "Hello");
ss.str("");
ss << setfill('^') << setw(6) << fbstr;
EXPECT_EQ(ss.str(), "^Hello");
ss.str("");
}
TEST(FBString, rvalueIterators) {
// you cannot take &* of a move-iterator, so use that for testing
fbstring s = "base";
fbstring r = "hello";
r.replace(r.begin(), r.end(),
make_move_iterator(s.begin()), make_move_iterator(s.end()));
EXPECT_EQ("base", r);
// The following test is probably not required by the standard.
// i.e. this could be in the realm of undefined behavior.
fbstring b = "123abcXYZ";
auto ait = b.begin() + 3;
auto Xit = b.begin() + 6;
b.replace(ait, b.end(), b.begin(), Xit);
EXPECT_EQ("123123abc", b); // if things go wrong, you'd get "123123123"
}
TEST(FBString, moveTerminator) {
// The source of a move must remain in a valid state
fbstring s(100, 'x'); // too big to be in-situ
fbstring k;
k = std::move(s);
EXPECT_EQ(0, s.size());
EXPECT_EQ('\0', *s.c_str());
}
namespace {
/*
* t8968589: Clang 3.7 refused to compile w/ certain constructors (specifically
* those that were "explicit" and had a defaulted parameter, if they were used
* in structs which were default-initialized). Exercise these just to ensure
* they compile.
*
* In diff D2632953 the old constructor:
* explicit basic_fbstring(const A& a = A()) noexcept;
*
* was split into these two, as a workaround:
* basic_fbstring() noexcept;
* explicit basic_fbstring(const A& a) noexcept;
*/
struct TestStructDefaultAllocator {
folly::basic_fbstring<char> stringMember;
};
template <class A>
struct TestStructWithAllocator {
folly::basic_fbstring<char, std::char_traits<char>, A> stringMember;
};
std::atomic<size_t> allocatorConstructedCount(0);
struct TestStructStringAllocator : std::allocator<char> {
TestStructStringAllocator() {
++ allocatorConstructedCount;
}
};
} // namespace
TEST(FBStringCtorTest, DefaultInitStructDefaultAlloc) {
TestStructDefaultAllocator t1 { };
EXPECT_TRUE(t1.stringMember.empty());
}
TEST(FBStringCtorTest, DefaultInitStructAlloc) {
EXPECT_EQ(allocatorConstructedCount.load(), 0);
TestStructWithAllocator<TestStructStringAllocator> t2;
EXPECT_TRUE(t2.stringMember.empty());
EXPECT_EQ(allocatorConstructedCount.load(), 1);
}
TEST(FBStringCtorTest, NullZeroConstruction) {
char* p = nullptr;
int n = 0;
folly::fbstring f(p, n);
EXPECT_EQ(f.size(), 0);
}
// Tests for the comparison operators. I use EXPECT_TRUE rather than EXPECT_LE
// because what's under test is the operator rather than the relation between
// the objects.
TEST(FBString, compareToStdString) {
using folly::fbstring;
using namespace std::string_literals;
auto stdA = "a"s;
auto stdB = "b"s;
fbstring fbA("a");
fbstring fbB("b");
EXPECT_TRUE(stdA == fbA);
EXPECT_TRUE(fbB == stdB);
EXPECT_TRUE(stdA != fbB);
EXPECT_TRUE(fbA != stdB);
EXPECT_TRUE(stdA < fbB);
EXPECT_TRUE(fbA < stdB);
EXPECT_TRUE(stdB > fbA);
EXPECT_TRUE(fbB > stdA);
EXPECT_TRUE(stdA <= fbB);
EXPECT_TRUE(fbA <= stdB);
EXPECT_TRUE(stdA <= fbA);
EXPECT_TRUE(fbA <= stdA);
EXPECT_TRUE(stdB >= fbA);
EXPECT_TRUE(fbB >= stdA);
EXPECT_TRUE(stdB >= fbB);
EXPECT_TRUE(fbB >= stdB);
}
TEST(U16FBString, compareToStdU16String) {
using folly::basic_fbstring;
using namespace std::string_literals;
auto stdA = u"a"s;
auto stdB = u"b"s;
basic_fbstring<char16_t> fbA(u"a");
basic_fbstring<char16_t> fbB(u"b");
EXPECT_TRUE(stdA == fbA);
EXPECT_TRUE(fbB == stdB);
EXPECT_TRUE(stdA != fbB);
EXPECT_TRUE(fbA != stdB);
EXPECT_TRUE(stdA < fbB);
EXPECT_TRUE(fbA < stdB);
EXPECT_TRUE(stdB > fbA);
EXPECT_TRUE(fbB > stdA);
EXPECT_TRUE(stdA <= fbB);
EXPECT_TRUE(fbA <= stdB);
EXPECT_TRUE(stdA <= fbA);
EXPECT_TRUE(fbA <= stdA);
EXPECT_TRUE(stdB >= fbA);
EXPECT_TRUE(fbB >= stdA);
EXPECT_TRUE(stdB >= fbB);
EXPECT_TRUE(fbB >= stdB);
}
TEST(U32FBString, compareToStdU32String) {
using folly::basic_fbstring;
using namespace std::string_literals;
auto stdA = U"a"s;
auto stdB = U"b"s;
basic_fbstring<char32_t> fbA(U"a");
basic_fbstring<char32_t> fbB(U"b");
EXPECT_TRUE(stdA == fbA);
EXPECT_TRUE(fbB == stdB);
EXPECT_TRUE(stdA != fbB);
EXPECT_TRUE(fbA != stdB);
EXPECT_TRUE(stdA < fbB);
EXPECT_TRUE(fbA < stdB);
EXPECT_TRUE(stdB > fbA);
EXPECT_TRUE(fbB > stdA);
EXPECT_TRUE(stdA <= fbB);
EXPECT_TRUE(fbA <= stdB);
EXPECT_TRUE(stdA <= fbA);
EXPECT_TRUE(fbA <= stdA);
EXPECT_TRUE(stdB >= fbA);
EXPECT_TRUE(fbB >= stdA);
EXPECT_TRUE(stdB >= fbB);
EXPECT_TRUE(fbB >= stdB);
}
TEST(WFBString, compareToStdWString) {
using folly::basic_fbstring;
using namespace std::string_literals;
auto stdA = L"a"s;
auto stdB = L"b"s;
basic_fbstring<wchar_t> fbA(L"a");
basic_fbstring<wchar_t> fbB(L"b");
EXPECT_TRUE(stdA == fbA);
EXPECT_TRUE(fbB == stdB);
EXPECT_TRUE(stdA != fbB);
EXPECT_TRUE(fbA != stdB);
EXPECT_TRUE(stdA < fbB);
EXPECT_TRUE(fbA < stdB);
EXPECT_TRUE(stdB > fbA);
EXPECT_TRUE(fbB > stdA);
EXPECT_TRUE(stdA <= fbB);
EXPECT_TRUE(fbA <= stdB);
EXPECT_TRUE(stdA <= fbA);
EXPECT_TRUE(fbA <= stdA);
EXPECT_TRUE(stdB >= fbA);
EXPECT_TRUE(fbB >= stdA);
EXPECT_TRUE(stdB >= fbB);
EXPECT_TRUE(fbB >= stdB);
}
// Same again, but with a more challenging input - a common prefix and different
// lengths.
TEST(FBString, compareToStdStringLong) {
using folly::fbstring;
using namespace std::string_literals;
auto stdA = "1234567890a"s;
auto stdB = "1234567890ab"s;
fbstring fbA("1234567890a");
fbstring fbB("1234567890ab");
EXPECT_TRUE(stdA == fbA);
EXPECT_TRUE(fbB == stdB);
EXPECT_TRUE(stdA != fbB);
EXPECT_TRUE(fbA != stdB);
EXPECT_TRUE(stdA < fbB);
EXPECT_TRUE(fbA < stdB);
EXPECT_TRUE(stdB > fbA);
EXPECT_TRUE(fbB > stdA);
EXPECT_TRUE(stdA <= fbB);
EXPECT_TRUE(fbA <= stdB);
EXPECT_TRUE(stdA <= fbA);
EXPECT_TRUE(fbA <= stdA);
EXPECT_TRUE(stdB >= fbA);
EXPECT_TRUE(fbB >= stdA);
EXPECT_TRUE(stdB >= fbB);
EXPECT_TRUE(fbB >= stdB);
}
TEST(U16FBString, compareToStdU16StringLong) {
using folly::basic_fbstring;
using namespace std::string_literals;
auto stdA = u"1234567890a"s;
auto stdB = u"1234567890ab"s;
basic_fbstring<char16_t> fbA(u"1234567890a");
basic_fbstring<char16_t> fbB(u"1234567890ab");
EXPECT_TRUE(stdA == fbA);
EXPECT_TRUE(fbB == stdB);
EXPECT_TRUE(stdA != fbB);
EXPECT_TRUE(fbA != stdB);
EXPECT_TRUE(stdA < fbB);
EXPECT_TRUE(fbA < stdB);
EXPECT_TRUE(stdB > fbA);
EXPECT_TRUE(fbB > stdA);
EXPECT_TRUE(stdA <= fbB);
EXPECT_TRUE(fbA <= stdB);
EXPECT_TRUE(stdA <= fbA);
EXPECT_TRUE(fbA <= stdA);
EXPECT_TRUE(stdB >= fbA);
EXPECT_TRUE(fbB >= stdA);
EXPECT_TRUE(stdB >= fbB);
EXPECT_TRUE(fbB >= stdB);
}
#if FOLLY_HAVE_WCHAR_SUPPORT
TEST(U32FBString, compareToStdU32StringLong) {
using folly::basic_fbstring;
using namespace std::string_literals;
auto stdA = U"1234567890a"s;
auto stdB = U"1234567890ab"s;
basic_fbstring<char32_t> fbA(U"1234567890a");
basic_fbstring<char32_t> fbB(U"1234567890ab");
EXPECT_TRUE(stdA == fbA);
EXPECT_TRUE(fbB == stdB);
EXPECT_TRUE(stdA != fbB);
EXPECT_TRUE(fbA != stdB);
EXPECT_TRUE(stdA < fbB);
EXPECT_TRUE(fbA < stdB);
EXPECT_TRUE(stdB > fbA);
EXPECT_TRUE(fbB > stdA);
EXPECT_TRUE(stdA <= fbB);
EXPECT_TRUE(fbA <= stdB);
EXPECT_TRUE(stdA <= fbA);
EXPECT_TRUE(fbA <= stdA);
EXPECT_TRUE(stdB >= fbA);
EXPECT_TRUE(fbB >= stdA);
EXPECT_TRUE(stdB >= fbB);
EXPECT_TRUE(fbB >= stdB);
}
TEST(WFBString, compareToStdWStringLong) {
using folly::basic_fbstring;
using namespace std::string_literals;
auto stdA = L"1234567890a"s;
auto stdB = L"1234567890ab"s;
basic_fbstring<wchar_t> fbA(L"1234567890a");
basic_fbstring<wchar_t> fbB(L"1234567890ab");
EXPECT_TRUE(stdA == fbA);
EXPECT_TRUE(fbB == stdB);
EXPECT_TRUE(stdA != fbB);
EXPECT_TRUE(fbA != stdB);
EXPECT_TRUE(stdA < fbB);
EXPECT_TRUE(fbA < stdB);
EXPECT_TRUE(stdB > fbA);
EXPECT_TRUE(fbB > stdA);
EXPECT_TRUE(stdA <= fbB);
EXPECT_TRUE(fbA <= stdB);
EXPECT_TRUE(stdA <= fbA);
EXPECT_TRUE(fbA <= stdA);
EXPECT_TRUE(stdB >= fbA);
EXPECT_TRUE(fbB >= stdA);
EXPECT_TRUE(stdB >= fbB);
EXPECT_TRUE(fbB >= stdB);
}
#endif
|
; CRT0 stub for the Jupiter ACE
;
; Stefano Bodrato - Feb 2001
;
; $Id: ace_crt0.asm,v 1.10 2010/05/24 14:48:57 stefano Exp $
;
MODULE ace_crt0
;
; Initially include the zcc_opt.def file to find out lots of lovely
; information about what we should do..
;
INCLUDE "zcc_opt.def"
; No matter what set up we have, main is always, always external to
; this file
XREF _main
XDEF snd_tick
;
; Some variables which are needed for both app and basic startup
;
XDEF cleanup
XDEF l_dcal
; Integer rnd seed
XDEF _std_seed
; vprintf is internal to this file so we only ever include one of the set
; of routines
XDEF _vfprintf
;Exit variables
XDEF exitsp
XDEF exitcount
;For stdin, stdout, stder
XDEF __sgoioblk
XDEF heaplast ;Near malloc heap variables
XDEF heapblocks
; Graphics stuff
XDEF base_graphics
XDEF coords
; Now, getting to the real stuff now!
;--------
; Set an origin for the application (-zorg=) default to $4000
;--------
IF !myzorg
defc myzorg = $4000
ENDIF
org myzorg
org myzorg
start:
ld hl,0
add hl,sp
ld (start1+1),hl
ld hl,-64
add hl,sp
ld sp,hl
ld (exitsp),sp
IF !DEFINED_nostreams
IF DEFINED_ANSIstdio
; Set up the std* stuff so we can be called again
ld hl,__sgoioblk+2
ld (hl),19 ;stdin
ld hl,__sgoioblk+6
ld (hl),21 ;stdout
ld hl,__sgoioblk+10
ld (hl),21 ;stderr
ENDIF
ENDIF
call _main
cleanup:
;
; Deallocate memory which has been allocated here!
;
push hl
IF !DEFINED_nostreams
IF DEFINED_ANSIstdio
LIB closeall
call closeall
ENDIF
ENDIF
pop bc
start1:
ld sp,0
jp (iy) ; To the Jupiter ACE FORTH system
l_dcal:
jp (hl)
; Now, define some values for stdin, stdout, stderr
__sgoioblk:
IF DEFINED_ANSIstdio
INCLUDE "stdio_fp.asm"
ELSE
defw -11,-12,-10
ENDIF
; Now, which of the vfprintf routines do we need?
_vfprintf:
IF DEFINED_floatstdio
LIB vfprintf_fp
jp vfprintf_fp
ELSE
IF DEFINED_complexstdio
LIB vfprintf_comp
jp vfprintf_comp
ELSE
IF DEFINED_ministdio
LIB vfprintf_mini
jp vfprintf_mini
ENDIF
ENDIF
ENDIF
;Seed for integer rand() routines
_std_seed: defw 0
;Atexit routine
exitsp:
defw 0
exitcount:
defb 0
; Heap stuff
heaplast: defw 0
heapblocks: defw 0
; mem stuff
base_graphics:
defw $2400
coords: defw 0
snd_tick: defb 0
defm "Small C+ J.ACE"
defb 0
;All the float stuff is kept in a different file...for ease of altering!
;It will eventually be integrated into the library
;
;Here we have a minor (minor!) problem, we've no idea if we need the
;float package if this is separated from main (we had this problem before
;but it wasn't critical..so, now we will have to read in a file from
;the directory (this will be produced by zcc) which tells us if we need
;the floatpackage, and if so what it is..kludgey, but it might just work!
;
;Brainwave time! The zcc_opt file could actually be written by the
;compiler as it goes through the modules, appending as necessary - this
;way we only include the package if we *really* need it!
IF NEED_floatpack
INCLUDE "float.asm"
;seed for random number generator - not used yet..
fp_seed: defb $80,$80,0,0,0,0
;Floating point registers...
extra: defs 6
fa: defs 6
fasign: defb 0
ENDIF
|
; Listing generated by Microsoft (R) Optimizing Compiler Version 16.00.30319.01
TITLE C:\JitenderN\REBook\HelloWorld\HelloWorld\HelloWorld.cpp
.686P
.XMM
include listing.inc
.model flat
INCLUDELIB LIBCMT
INCLUDELIB OLDNAMES
CONST SEGMENT
$SG4677 DB 'hello, world', 0aH, 00H
CONST ENDS
PUBLIC _main
EXTRN _printf:PROC
; Function compile flags: /Ogtpy
_TEXT SEGMENT
_main PROC
; File c:\jitendern\rebook\helloworld\helloworld\helloworld.cpp
; Line 9
push OFFSET $SG4677
call _printf
add esp, 4
; Line 10
xor eax, eax
; Line 11
ret 0
_main ENDP
_TEXT ENDS
END
|
db 0 ; species ID placeholder
db 60, 85, 60, 55, 85, 60
; hp atk def spd sat sdf
db FIRE, FIGHTING ; type
db 45 ; catch rate
db 142 ; base exp
db NO_ITEM, NO_ITEM ; items
db GENDER_F12_5 ; gender ratio
db 100 ; unknown 1
db 20 ; step cycles to hatch
db 5 ; unknown 2
INCBIN "gfx/pokemon/combusken/front.dimensions"
db 0, 0, 0, 0 ; padding
db GROWTH_MEDIUM_SLOW ; growth rate
dn EGG_GROUND, EGG_GROUND ; egg groups
; tm/hm learnset
tmhm DYNAMICPUNCH, HEADBUTT, CURSE, TOXIC, ZAP_CANNON, PSYCH_UP, HIDDEN_POWER, SUNNY_DAY, SNORE, PROTECT, RAIN_DANCE, ENDURE, FRUSTRATION, RETURN, PSYCHIC_M, SHADOW_BALL, DOUBLE_TEAM, ICE_PUNCH, SWAGGER, SLEEP_TALK, THUNDERPUNCH, DREAM_EATER, REST, ATTRACT, THIEF, FIRE_PUNCH, NIGHTMARE, FLASH
; end
|
; $Id: bit_open.asm,v 1.8 2016-06-16 19:33:59 dom Exp $
;
; ZX Spectrum 1 bit sound functions
;
; void bit_open();
;
; Stefano Bodrato - 28/9/2001
;
INCLUDE "games/games.inc"
SECTION code_clib
PUBLIC bit_open
PUBLIC _bit_open
EXTERN __snd_tick
.bit_open
._bit_open
ld a,(23624)
rra
rra
rra
and 7
or 8
push de
ld e,a
ld a,(__snd_tick)
and sndbit_mask
or e
pop de
ld (__snd_tick),a
ret
|
; 0xf0 = a
; 0xf1 = b
; ret to 0xff
udiv:
lda $0
sta 0xe0
.loop:
lda 0xf0
sub 0xf1
js .end ; a - b was negative, a < b
sta 0xf0 ; a -= b
lda 0xe0 ; out += 1
add $1
sta 0xe0
jmp .loop
.end:
lda 0xe0
jmp #0xff ; ret
|
; all of these should fail on i8080
add ix,bc ; #DD09
add ix,de ; #DD19
ld ix,#100 ; #DD210001
ld (#100),ix ; #DD220001
inc ix ; #DD23
inc ixh ; #DD24
dec ixh ; #DD25
ld ixh,0 ; #DD2600
add ix,ix ; #DD29
ld ix,(#100) ; #DD2A0001
dec ix ; #DD2B
inc ixl ; #DD2C
dec ixl ; #DD2D
ld ixl,0 ; #DD2E00
inc (ix+17) ; #DD3411
dec (ix+17) ; #DD3511
ld (ix+17),0 ; #DD361100
add ix,sp ; #DD39
ld b,ixh ; #DD44
ld b,ixl ; #DD45
ld b,(ix+17) ; #DD4611
ld c,ixh ; #DD4C
ld c,ixl ; #DD4D
ld c,(ix+17) ; #DD4E11
ld d,ixh ; #DD54
ld d,ixl ; #DD55
ld d,(ix+17) ; #DD5611
ld e,ixh ; #DD5C
ld e,ixl ; #DD5D
ld e,(ix+17) ; #DD5E11
ld ixh,b ; #DD60
ld ixh,c ; #DD61
ld ixh,d ; #DD62
ld ixh,e ; #DD63
ld ixh,ixh ; #DD64
ld ixh,ixl ; #DD65
ld h,(ix+17) ; #DD6611
ld ixh,a ; #DD67
ld ixl,b ; #DD68
ld ixl,c ; #DD69
ld ixl,d ; #DD6A
ld ixl,e ; #DD6B
ld ixl,ixh ; #DD6C
ld ixl,ixl ; #DD6D
ld l,(ix+17) ; #DD6E11
ld ixl,a ; #DD6F
ld (ix+17),b ; #DD7011
ld (ix+17),c ; #DD7111
ld (ix+17),d ; #DD7211
ld (ix+17),e ; #DD7311
ld (ix+17),h ; #DD7411
ld (ix+17),l ; #DD7511
ld (ix+17),a ; #DD7711
ld a,ixh ; #DD7C
ld a,ixl ; #DD7D
ld a,(ix+17) ; #DD7E11
add a,ixh ; #DD84
add a,ixl ; #DD85
add a,(ix+17) ; #DD8611
adc a,ixh ; #DD8C
adc a,ixl ; #DD8D
adc a,(ix+17) ; #DD8E11
sub ixh ; #DD94
sub ixl ; #DD95
sub (ix+17) ; #DD9611
sbc a,ixh ; #DD9C
sbc a,ixl ; #DD9D
sbc a,(ix+17) ; #DD9E11
and ixh ; #DDA4
and ixl ; #DDA5
and (ix+17) ; #DDA611
xor ixh ; #DDAC
xor ixl ; #DDAD
xor (ix+17) ; #DDAE11
or ixh ; #DDB4
or ixl ; #DDB5
or (ix+17) ; #DDB611
cp ixh ; #DDBC
cp ixl ; #DDBD
cp (ix+17) ; #DDBE11
pop ix ; #DDE1
ex (sp),ix ; #DDE3
push ix ; #DDE5
jp (ix) ; #DDE9
ld sp,ix ; #DDF9
|
//door asm of bt/animal room during escape
arch snes.cpu
lorom
org $838BCC
db $20, $ff
org $8FFF20
LDA $7ED820 //loads event flags
BIT #$4000 //checks for escape flag set
BEQ quit
LDA #$0020
STA $7E0946 //stores 15 to escape timer in seconds
quit:
RTS |
//------------------------------------------------------------------------------
//
// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
//
// This program and the accompanying materials
// are licensed and made available under the terms and conditions of the BSD License
// which accompanies this distribution. The full text of the license may be found at
// http://opensource.org/licenses/bsd-license.php
//
// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
//
//------------------------------------------------------------------------------
EXPORT __aeabi_uwrite4
EXPORT __aeabi_uwrite8
AREA Uwrite4, CODE, READONLY
;
;UINT32
;EFIAPI
;__aeabi_uwrite4 (
; IN UINT32 Data,
; IN VOID *Pointer
; );
;
;
__aeabi_uwrite4
mov r2, r0, lsr #8
strb r0, [r1]
strb r2, [r1, #1]
mov r2, r0, lsr #16
strb r2, [r1, #2]
mov r2, r0, lsr #24
strb r2, [r1, #3]
bx lr
;
;UINT64
;EFIAPI
;__aeabi_uwrite8 (
; IN UINT64 Data, //r0-r1
; IN VOID *Pointer //r2
; );
;
;
__aeabi_uwrite8
mov r3, r0, lsr #8
strb r0, [r2]
strb r3, [r2, #1]
mov r3, r0, lsr #16
strb r3, [r2, #2]
mov r3, r0, lsr #24
strb r3, [r2, #3]
mov r3, r1, lsr #8
strb r1, [r2, #4]
strb r3, [r2, #5]
mov r3, r1, lsr #16
strb r3, [r2, #6]
mov r3, r1, lsr #24
strb r3, [r2, #7]
bx lr
END
|
#pragma once
// The sole purpose of this file is to give a clear and early error
// message to anyone trying to compile fs123 with a too-old compiler.
// It's #include-ed in a few source files that give wide coverage.
// See docs/Notes.compilers for more info
#if defined(__clang__)
# if __clang_major__ < 7
# error "fs123 requires at least clang-7 or gcc-7 and -std=c++17"
# include "Compilation stopped because fs123 requires at least clang-7 or gcc-8 and -std=c++17"
# endif
#elif defined(__ICC) // N.B. icpc also defines __GNUC__, so this must come first
# if __ICC < 1900
# error "fs123 requires at least icc-19 or clang-7 or gcc-7 and -std=c++17"
# include "Compilation stopped because fs123 requires at least icc-19 clang-7 or gcc-8 and -std=c++17"
# endif
#elif defined(__GNUC__)
# if __GNUC__ < 7
# error "fs123 requires at least clang-7 or gcc-7 and -std=c++17"
# include "Compilation stopped because fs123 requires at least clang-7 or gcc-7 and -std=c++17"
# endif
#endif
|
; PROLOGUE(mpn_addmul_2)
; Copyright 2008 Jason Moxham
;
; Windows Conversion Copyright 2008 Brian Gladman
;
; This file is part of the MPIR Library.
; The MPIR Library is free software; you can redistribute it and/or modify
; it under the terms of the GNU Lesser General Public License as published
; by the Free Software Foundation; either version 2.2 of the License, or (at
; your option) any later version.
; The MPIR Library is distributed in the hope that it will be useful, but
; WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
; License for more details.
; You should have received a copy of the GNU Lesser General Public License
; along with the MPIR Library; see the file COPYING.LIB. If not, write
; to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
; Boston, MA 02110-1301, USA.
;
; mp_limb_t mpn_addmul_2(mp_ptr, mp_ptr, mp_size_t, mp_ptr)
; rax rdi rsi rdx rcx
; rax rcx rdx r8 r9
%include "yasm_mac.inc"
CPU Athlon64
BITS 64
%define reg_save_list rbx, rsi, rdi, r12
FRAME_PROC mpn_addmul_2, 0, reg_save_list
mov rdi, rcx
mov rsi, rdx
mov rax, r8
mov rcx, [r9]
mov r8, [r9+8]
mov rbx, 4
sub rbx, rax
lea rsi, [rsi+rax*8-32]
lea rdi, [rdi+rax*8-32]
mov r10, 0
mov rax, [rsi+rbx*8]
mul rcx
mov r12, rax
mov r9, rdx
cmp rbx, 0
jge .2
xalign 16
.1: mov rax, [rsi+rbx*8]
mul r8
add r9, rax
mov rax, [rsi+rbx*8+8]
adc r10, rdx
mov r11, 0
mul rcx
add [rdi+rbx*8], r12
adc r9, rax
mov r12, 0
adc r10, rdx
mov rax, [rsi+rbx*8+8]
adc r11, 0
mul r8
add [rdi+rbx*8+8], r9
adc r10, rax
adc r11, rdx
mov rax, [rsi+rbx*8+16]
mul rcx
add r10, rax
mov rax, [rsi+rbx*8+16]
adc r11, rdx
adc r12, 0
mul r8
add [rdi+rbx*8+16], r10
mov r9, 0
adc r11, rax
mov r10, 0
mov rax, [rsi+rbx*8+24]
adc r12, rdx
mov r15, r15
mul rcx
add r11, rax
mov rax, [rsi+rbx*8+24]
adc r12, rdx
adc r9, 0
mul r8
add [rdi+rbx*8+24], r11
adc r12, rax
adc r9, rdx
mov rax, [rsi+rbx*8+32]
mul rcx
add r12, rax
adc r9, rdx
adc r10, 0
add rbx, 4
jnc .1
.2: mov rax, [rsi+rbx*8]
mul r8
cmp rbx, 2
ja .6
jz .5
jp .4
.3: add r9, rax
mov rax, [rsi+rbx*8+8]
adc r10, rdx
mov r11, 0
mul rcx
add [rdi+rbx*8], r12
adc r9, rax
mov r12, 0
adc r10, rdx
mov rax, [rsi+rbx*8+8]
adc r11, 0
mul r8
add [rdi+rbx*8+8], r9
adc r10, rax
adc r11, rdx
mov rax, [rsi+rbx*8+16]
mul rcx
add r10, rax
mov rax, [rsi+rbx*8+16]
adc r11, rdx
adc r12, 0
mul r8
add [rdi+rbx*8+16], r10
mov r9, 0
adc r11, rax
; padding
mov r10, 0
mov rax, [rsi+rbx*8+24]
adc r12, rdx
; padding
mov r15, r15
mul rcx
add r11, rax
mov rax, [rsi+rbx*8+24]
adc r12, rdx
adc r9, 0
mul r8
add [rdi+rbx*8+24], r11
adc r12, rax
adc r9, rdx
mov [rdi+rbx*8+32], r12
mov rax, r9
EXIT_PROC reg_save_list
xalign 16
.4: add r9, rax
mov rax, [rsi+rbx*8+8]
adc r10, rdx
mov r11, 0
mul rcx
add [rdi+rbx*8], r12
adc r9, rax
mov r12, 0
adc r10, rdx
mov rax, [rsi+rbx*8+8]
adc r11, 0
mul r8
add [rdi+rbx*8+8], r9
adc r10, rax
adc r11, rdx
mov rax, [rsi+rbx*8+16]
mul rcx
add r10, rax
mov rax, [rsi+rbx*8+16]
adc r11, rdx
adc r12, 0
mul r8
add [rdi+rbx*8+16], r10
adc r11, rax
adc r12, rdx
mov [rdi+rbx*8+24], r11
mov rax, r12
EXIT_PROC reg_save_list
xalign 16
.5: add r9, rax
mov rax, [rsi+rbx*8+8]
adc r10, rdx
mov r11, 0
mul rcx
add [rdi+rbx*8], r12
adc r9, rax
mov r12, 0
adc r10, rdx
mov rax, [rsi+rbx*8+8]
adc r11, 0
mul r8
add [rdi+rbx*8+8], r9
adc r10, rax
adc r11, rdx
mov [rdi+rbx*8+16], r10
mov rax, r11
EXIT_PROC reg_save_list
xalign 16
.6: add [rdi+rbx*8], r12
adc r9, rax
adc r10, rdx
mov [rdi+rbx*8+8], r9
mov rax, r10
.7: END_PROC reg_save_list
end
|
; int __CALLEE__ fputs(const char *s, FILE *stream)
; 07.2009 aralbrec
XLIB fputs_callee
XDEF ASMDISP_FPUTS_CALLEE
LIB strlen, l_jpix
LIB stdio_error_mc, stdio_success_znc, stdio_error_eacces_mc
INCLUDE "../stdio.def"
.fputs_callee
pop hl
pop ix
ex (sp),hl
.asmentry
; enter : hl = char *s
; ix = FILE *stream
; exit : hl = 0 and carry reset for success
; hl = -1 and carry set for fail
; uses : af, bc, de, hl, ix
bit 1,(ix+3) ; open for output?
jp z, stdio_error_eacces_mc
ld e,l
ld d,h ; de = char *s
call strlen ; hl = length
jp z, stdio_success_znc ; 0 len = success already!
; de = char *s
; hl = length
; ix = FILE *
push hl ; save length
ld a,STDIO_MSG_WRIT
call l_jpix ; write buffer
pop de ; de = original length
jp c, stdio_error_mc
sbc hl,de ; amount of buffer not written
jp z, stdio_success_znc
jp stdio_error_mc
defc ASMDISP_FPUTS_CALLEE = asmentry - fputs_callee
|
dnl AMD64 mpn_addmul_1 and mpn_submul_1.
dnl Copyright 2003, 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
dnl This file is part of the GNU MP Library.
dnl The GNU MP Library is free software; you can redistribute it and/or modify
dnl it under the terms of the GNU Lesser General Public License as published
dnl by the Free Software Foundation; either version 3 of the License, or (at
dnl your option) any later version.
dnl The GNU MP Library is distributed in the hope that it will be useful, but
dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
dnl License for more details.
dnl You should have received a copy of the GNU Lesser General Public License
dnl along with the GNU MP Library. If not, see http://www.gnu.org/licenses/.
include(`../config.m4')
C cycles/limb
C K8,K9: 2.5
C K10: 2.5
C P4: 14.9
C P6-15 (Core2): 5.09
C P6-28 (Atom): 21.3
C The inner loop of this code is the result of running a code generation and
C optimization tool suite written by David Harvey and Torbjorn Granlund.
C TODO:
C * The inner loop is great, but the prologue and epilogue code was
C quickly written. Tune it!
C INPUT PARAMETERS
define(`rp', `%rdi')
define(`up', `%rsi')
define(`n_param',`%rdx')
define(`vl', `%rcx')
define(`n', `%r11')
ifdef(`OPERATION_addmul_1',`
define(`ADDSUB', `add')
define(`func', `mpn_addmul_1')
')
ifdef(`OPERATION_submul_1',`
define(`ADDSUB', `sub')
define(`func', `mpn_submul_1')
')
MULFUNC_PROLOGUE(mpn_addmul_1 mpn_submul_1)
ASM_START()
TEXT
ALIGN(16)
PROLOGUE(func)
mov (up), %rax C read first u limb early
push %rbx
mov n_param, %rbx C move away n from rdx, mul uses it
mul vl
mov %rbx, %r11
and $3, R32(%rbx)
jz L(b0)
cmp $2, R32(%rbx)
jz L(b2)
jg L(b3)
L(b1): dec n
jne L(gt1)
ADDSUB %rax, (rp)
jmp L(ret)
L(gt1): lea 8(up,n,8), up
lea -8(rp,n,8), rp
neg n
xor %r10, %r10
xor R32(%rbx), R32(%rbx)
mov %rax, %r9
mov (up,n,8), %rax
mov %rdx, %r8
jmp L(L1)
L(b0): lea (up,n,8), up
lea -16(rp,n,8), rp
neg n
xor %r10, %r10
mov %rax, %r8
mov %rdx, %rbx
jmp L(L0)
L(b3): lea -8(up,n,8), up
lea -24(rp,n,8), rp
neg n
mov %rax, %rbx
mov %rdx, %r10
jmp L(L3)
L(b2): lea -16(up,n,8), up
lea -32(rp,n,8), rp
neg n
xor %r8, %r8
xor R32(%rbx), R32(%rbx)
mov %rax, %r10
mov 24(up,n,8), %rax
mov %rdx, %r9
jmp L(L2)
ALIGN(16)
L(top): ADDSUB %r10, (rp,n,8)
adc %rax, %r9
mov (up,n,8), %rax
adc %rdx, %r8
mov $0, %r10d
L(L1): mul vl
ADDSUB %r9, 8(rp,n,8)
adc %rax, %r8
adc %rdx, %rbx
L(L0): mov 8(up,n,8), %rax
mul vl
ADDSUB %r8, 16(rp,n,8)
adc %rax, %rbx
adc %rdx, %r10
L(L3): mov 16(up,n,8), %rax
mul vl
ADDSUB %rbx, 24(rp,n,8)
mov $0, %r8d # zero
mov %r8, %rbx # zero
adc %rax, %r10
mov 24(up,n,8), %rax
mov %r8, %r9 # zero
adc %rdx, %r9
L(L2): mul vl
add $4, n
js L(top)
ADDSUB %r10, (rp,n,8)
adc %rax, %r9
adc %r8, %rdx
ADDSUB %r9, 8(rp,n,8)
L(ret): adc $0, %rdx
mov %rdx, %rax
pop %rbx
ret
EPILOGUE()
|
/**************************************************************************/
/* */
/* WWIV Version 5.x */
/* Copyright (C)1998-2022, WWIV Software Services */
/* */
/* 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 "bbs/readmail.h"
#include "bbs/acs.h"
#include "bbs/bbs.h"
#include "bbs/bbsovl1.h"
#include "bbs/bbsutl.h"
#include "bbs/bbsutl1.h"
#include "bbs/conf.h"
#include "bbs/connect1.h"
#include "bbs/email.h"
#include "bbs/execexternal.h"
#include "bbs/extract.h"
#include "bbs/instmsg.h"
#include "bbs/message_file.h"
#include "bbs/mmkey.h"
#include "bbs/msgbase1.h"
#include "bbs/read_message.h"
#include "bbs/shortmsg.h"
#include "bbs/showfiles.h"
#include "bbs/sr.h"
#include "bbs/subacc.h"
#include "bbs/sublist.h"
#include "bbs/sysopf.h"
#include "bbs/sysoplog.h"
#include "bbs/utility.h"
#include "bbs/xfer.h"
#include "common/com.h"
#include "common/datetime.h"
#include "common/input.h"
#include "common/output.h"
#include "common/quote.h"
#include "common/workspace.h"
#include "core/stl.h"
#include "core/strings.h"
#include "core/textfile.h"
#include "fmt/printf.h"
#include "local_io/wconstants.h"
#include "sdk/filenames.h"
#include "sdk/names.h"
#include "sdk/status.h"
#include "sdk/msgapi/message_utils_wwiv.h"
#include "sdk/net/networks.h"
#include <cstdint>
#include <memory>
#include <string>
#include <vector>
using namespace wwiv::common;
using namespace wwiv::core;
using namespace wwiv::sdk;
using namespace wwiv::sdk::msgapi;
using namespace wwiv::sdk::net;
using namespace wwiv::stl;
using namespace wwiv::strings;
// Implementation
static bool same_email(tmpmailrec& tm, const mailrec& m) {
if (tm.fromsys != m.fromsys || tm.fromuser != m.fromuser || m.tosys != 0 ||
m.touser != a()->sess().user_num() || tm.daten != m.daten || tm.index == -1 ||
memcmp(&tm.msg, &m.msg, sizeof(messagerec)) != 0) {
return false;
}
return true;
}
static void purgemail(std::vector<tmpmailrec>& mloc, int mw, int* curmail, mailrec* m1, slrec* sl) {
mailrec m{};
if (m1->anony & anony_sender && (sl->ability & ability_read_email_anony) == 0) {
bout << "|#5Delete all mail to you from this user? ";
} else {
bout << "|#5Delete all mail to you from ";
if (m1->fromsys) {
bout << "#" << m1->fromuser << " @" << m1->fromsys << "? ";
} else {
if (m1->fromuser == 65535) {
bout << "Networks? ";
} else {
bout << "#" << m1->fromuser << "? ";
}
}
}
if (bin.yesno()) {
auto pFileEmail(OpenEmailFile(true));
if (!pFileEmail->IsOpen()) {
return;
}
for (int i = 0; i < mw; i++) {
if (mloc[i].index >= 0) {
pFileEmail->Seek(mloc[i].index * sizeof(mailrec), File::Whence::begin);
pFileEmail->Read(&m, sizeof(mailrec));
if (same_email(mloc[i], m)) {
if (m.fromuser == m1->fromuser && m.fromsys == m1->fromsys) {
bout << "Deleting mail msg #" << i + 1 << wwiv::endl;
delmail(*pFileEmail, mloc[i].index);
mloc[i].index = -1;
if (*curmail == i) {
++(*curmail);
}
}
}
} else {
if (*curmail == i) {
++(*curmail);
}
}
}
pFileEmail->Close();
}
}
static void resynch_email(std::vector<tmpmailrec>& mloc, int mw, int rec, mailrec* m, bool del,
unsigned short stat) {
int i;
mailrec m1{};
auto pFileEmail(OpenEmailFile(del || stat));
if (pFileEmail->IsOpen()) {
const auto mfl = static_cast<File::size_type>(pFileEmail->length() / sizeof(mailrec));
for (i = 0; i < mw; i++) {
if (mloc[i].index >= 0) {
mloc[i].index = -2;
}
}
int mp = 0;
for (i = 0; i < mfl; i++) {
pFileEmail->Seek(i * sizeof(mailrec), File::Whence::begin);
pFileEmail->Read(&m1, sizeof(mailrec));
if (m1.tosys == 0 && m1.touser == a()->sess().user_num()) {
for (int i1 = mp; i1 < mw; i1++) {
if (same_email(mloc[i1], m1)) {
mloc[i1].index = static_cast<int16_t>(i);
mp = i1 + 1;
if (i1 == rec) {
*m = m1;
}
break;
}
}
}
}
for (i = 0; i < mw; i++) {
if (mloc[i].index == -2) {
mloc[i].index = -1;
}
}
if (stat && !del && (mloc[rec].index >= 0)) {
m->status |= stat;
pFileEmail->Seek(mloc[rec].index * sizeof(mailrec), File::Whence::begin);
pFileEmail->Write(m, sizeof(mailrec));
}
if (del && (mloc[rec].index >= 0)) {
delmail(*pFileEmail, mloc[rec].index);
mloc[rec].index = -1;
}
pFileEmail->Close();
} else {
mloc[rec].index = -1;
}
}
// used in qwk1.cpp
bool read_same_email(std::vector<tmpmailrec>& mloc, int mw, int rec, mailrec& m, bool del,
uint16_t stat) {
if (at(mloc, rec).index < 0) {
return false;
}
auto file = OpenEmailFile(del || stat);
if (!file->IsOpen()) {
LOG(ERROR) << "read_same_email: Failed to open email file.";
return false;
}
file->Seek(mloc[rec].index * sizeof(mailrec), File::Whence::begin);
file->Read(&m, sizeof(mailrec));
if (!same_email(mloc[rec], m)) {
file->Close();
a()->status_manager()->reload_status();
if (a()->emchg_) {
resynch_email(mloc, mw, rec, &m, del, stat);
} else {
mloc[rec].index = -1;
}
} else {
if (stat && !del && mloc[rec].index >= 0) {
m.status |= stat;
file->Seek(mloc[rec].index * sizeof(mailrec), File::Whence::begin);
file->Write(&m, sizeof(mailrec));
}
if (del) {
delmail(*file, mloc[rec].index);
mloc[rec].index = -1;
}
file->Close();
}
return mloc[rec].index != -1;
}
static void add_netsubscriber(const Network& net, int network_number, int system_number) {
if (!valid_system(system_number)) {
system_number = 0;
}
bout.nl();
bout << "|#1Adding subscriber to subscriber list...\r\n\n";
bout << "|#2SubType: ";
const auto subtype = bin.input(7, true);
if (subtype.empty()) {
return;
}
const auto fn = StrCat(net.dir, "n", subtype, ".net");
if (!File::Exists(fn)) {
bout.nl();
bout << "|#6Subscriber file not found: " << fn << wwiv::endl;
return;
}
bout.nl();
if (system_number) {
bout << "Add @" << system_number << "." << net.name << " to subtype " << subtype << "? ";
}
if (!system_number || !bin.noyes()) {
bout << "|#2System Number: ";
const auto s = bin.input(5, true);
if (s.empty()) {
return;
}
system_number = to_number<int>(s);
if (!valid_system(system_number)) {
bout << "@" << system_number << " is not a valid system in " << net.name << ".\r\n\n";
return;
}
}
TextFile host_file(fn, "a+t");
if (host_file.IsOpen()) {
host_file.Write(fmt::sprintf("%u\n", system_number));
host_file.Close();
// TODO find replacement for autosend.exe
if (File::Exists("autosend.exe")) {
bout << "AutoSend starter messages? ";
if (bin.yesno()) {
const auto autosend = FilePath(a()->bindir(), "autosend");
const auto cmd = StrCat(autosend.string(), " ", subtype, " ", system_number, " .", network_number);
wwiv::bbs::CommandLine cl(cmd);
ExecuteExternalProgram(cl, EFLAG_NONE);
}
}
}
}
void delete_attachment(unsigned long daten, int forceit) {
filestatusrec fsr{};
auto found = false;
File fileAttach(FilePath(a()->config()->datadir(), ATTACH_DAT));
if (fileAttach.Open(File::modeBinary | File::modeReadWrite)) {
auto l = fileAttach.Read(&fsr, sizeof(fsr));
while (l > 0 && !found) {
if (daten == static_cast<unsigned long>(fsr.id)) {
found = true;
fsr.id = 0;
fileAttach.Seek(static_cast<long>(sizeof(filestatusrec)) * -1L, File::Whence::current);
fileAttach.Write(&fsr, sizeof(filestatusrec));
auto delfile = true;
if (!forceit) {
if (so()) {
bout << "|#5Delete attached file? ";
delfile = bin.yesno();
}
}
if (delfile) {
File::Remove(FilePath(a()->GetAttachmentDirectory(), fsr.filename));
} else {
bout << "\r\nOrphaned attach " << fsr.filename << " remains in "
<< a()->GetAttachmentDirectory() << wwiv::endl;
bout.pausescr();
}
} else {
l = fileAttach.Read(&fsr, sizeof(filestatusrec));
}
}
fileAttach.Close();
}
}
static std::string from_name(const mailrec& m, const Network& net, const slrec& sl, int nn) {
if (m.anony & anony_sender && (sl.ability & ability_read_email_anony) == 0) {
return ">UNKNOWN<";
}
auto csne = next_system(m.fromsys);
const std::string system_name = csne ? csne->name : "Unknown System";
if (m.fromsys == 0) {
if (m.fromuser == 65535) {
if (nn != 255) {
return net.name;
}
} else {
return a()->names()->UserName(m.fromuser);
}
} else {
if (nn == 255) {
return fmt::format("#{} @{}.", m.fromuser, m.fromsys, net.name);
}
if (auto o = readfile(&m.msg, "email")) {
if (const auto idx = o.value().find('\r'); idx != std::string::npos) {
const std::string from = o.value().substr(0, idx);
if (m.fromsys == INTERNET_EMAIL_FAKE_OUTBOUND_NODE || m.fromsys == FTN_FAKE_OUTBOUND_NODE) {
return stripcolors(from);
}
return fmt::format("{} {}@{}.{} ({})", stripcolors(wwiv::common::strip_to_node(from)),
m.fromuser, m.fromsys, net.name, system_name);
}
} else {
if (ssize(a()->nets()) > 1) {
return fmt::format("#{} @{}.{} ({})", m.fromuser, m.fromsys, net.name, system_name);
}
}
}
return fmt::format("#{} @{} ({})", m.fromuser, m.fromsys, system_name);
}
static std::tuple<Network, int> network_and_num(const mailrec& m) {
Network net{};
auto nn = network_number_from(&m);
if (nn <= a()->nets().size()) {
net = a()->nets()[nn];
} else {
net.sysnum = static_cast<uint16_t>(-1);
net.type = network_type_t::unknown;
net.name = fmt::format("<deleted network #{}>", nn);
nn = 255;
}
return std::make_tuple(net, nn);
}
void readmail(bool newmail_only) {
constexpr auto mail_who_field_len = 45;
int i1, curmail = 0;
bool done;
mailrec m{};
mailrec m1{};
char ch;
filestatusrec fsr{};
a()->emchg_ = false;
bool next = false, abort = false;
std::vector<tmpmailrec> mloc;
write_inst(INST_LOC_RMAIL, 0, INST_FLAGS_NONE);
auto sl = a()->config()->sl(a()->sess().effective_sl());
auto mw = 0;
{
auto file(OpenEmailFile(false));
if (!file->IsOpen()) {
bout << "\r\n\nNo mail file exists!\r\n\n";
return;
}
auto mfl = static_cast<File::size_type>(file->length() / sizeof(mailrec));
for (int i = 0; i < mfl && mw < MAXMAIL; i++) {
file->Seek(i * sizeof(mailrec), File::Whence::begin);
file->Read(&m, sizeof(mailrec));
if (m.tosys == 0 && m.touser == a()->sess().user_num()) {
tmpmailrec r = {};
r.index = static_cast<int16_t>(i);
r.fromsys = m.fromsys;
r.fromuser = m.fromuser;
r.daten = m.daten;
r.msg = m.msg;
mloc.emplace_back(r);
mw++;
}
}
file->Close();
}
a()->user()->email_waiting(mw);
if (mloc.empty()) {
bout << "\r\n\n|#3You have no mail.\r\n\n";
return;
}
if (mloc.size() == 1) {
curmail = 0;
} else {
bout << "\r\n\n|#2You have mail from:\r\n";
bout << "|#9" << std::string(a()->user()->screen_width() - 1, '-') << wwiv::endl;
for (auto i = 0; i < mw && !abort; i++) {
if (!read_same_email(mloc, mw, i, m, false, 0)) {
continue;
}
if (newmail_only && (m.status & status_seen)) {
++curmail;
continue;
}
auto [net, nn] = network_and_num(m);
set_net_num(nn);
const auto current_line =
fmt::format("|#2{:>3}{}|#1{:<45.45}|#7| |#1{:<25.25}", i + 1, (m.status & status_seen ? " " : "|#3*"),
from_name(m, net, sl, nn), stripcolors(m.title));
bout.bpla(current_line, &abort);
}
bout << "|#9" << std::string(a()->user()->screen_width() - 1, '-') << wwiv::endl;
bout.bputs("|#9(|#2Q|#9=|#2Quit|#9, |#2Enter|#9=|#2First Message|#9) \r\n|#9Enter message number: ");
// TODO: use input numberor hotkey for number 1-mw, or Q
auto res = bin.input_number_hotkey(1, {'Q'}, 1, mw);
if (res.key == 'Q') {
return;
}
if (res.num > 0 && !newmail_only) {
if (res.num <= mw) {
curmail = res.num - 1;
} else {
curmail = 0;
}
}
}
done = false;
do {
bool okmail;
auto attach_exists = false;
auto found = false;
abort = false;
bout.nl(2);
next = false;
if (std::string title = m.title; !read_same_email(mloc, mw, curmail, m, false, 0)) {
title += ">>> MAIL DELETED <<<";
okmail = false;
bout.nl(3);
} else {
strcpy(a()->sess().irt_, m.title);
abort = false;
auto readit = ((ability_read_email_anony & sl.ability) != 0);
okmail = true;
if (m.fromsys && !m.fromuser) {
grab_user_name(&(m.msg), "email", network_number_from(&m));
} else {
a()->net_email_name.clear();
}
if (m.status & status_source_verified) {
if (int sv_type = source_verfied_type(&m); sv_type > 0) {
title += StrCat("-=> Source Verified Type ", sv_type);
if (sv_type == 1) {
title += " (From NC)";
} else if (sv_type > 256 && sv_type < 512) {
title += StrCat(" (From GC-", sv_type - 256, ")");
}
} else {
title += "-=> Source Verified (unknown type)";
}
}
auto [net, nn] = network_and_num(m);
set_net_num(nn);
int nFromSystem = 0;
int nFromUser = 0;
if (nn != 255) {
nFromSystem = m.fromsys;
nFromUser = m.fromuser;
}
if (!abort) {
// read_type2_message will parse out the title and other fields of the
// message, including sender name (which is all we have for FTN messages).
// We need to get the full header before that and pass it into this
// method to display it.
auto msg = read_type2_message(&m.msg, m.anony & 0x0f, readit ? true : false, "email",
nFromSystem, nFromUser);
msg.message_area = "Personal E-Mail";
msg.title = m.title;
msg.message_number = curmail + 1;
msg.total_messages = mw;
// We set this to false since we do *not* want to use the
// command handling from the full screen reader.
msg.use_msg_command_handler = false;
if (a()->current_net().type == network_type_t::ftn) {
// Set email name to be the to address.
// This is also done above in grab_user_name, but we should stop using
// a()->net_email_name
a()->net_email_name = msg.from_user_name;
}
int fake_msgno = -1;
display_type2_message(fake_msgno, msg, &next);
if (!(m.status & status_seen)) {
read_same_email(mloc, mw, curmail, m, false, status_seen);
}
}
found = false;
attach_exists = false;
if (m.status & status_file) {
File fileAttach(FilePath(a()->config()->datadir(), ATTACH_DAT));
if (fileAttach.Open(File::modeBinary | File::modeReadOnly)) {
auto l1 = fileAttach.Read(&fsr, sizeof(fsr));
while (l1 > 0 && !found) {
if (m.daten == static_cast<uint32_t>(fsr.id)) {
found = true;
if (File::Exists(FilePath(a()->GetAttachmentDirectory(), fsr.filename))) {
bout << "'T' to download attached file \"" << fsr.filename << "\" (" << fsr.numbytes
<< " bytes).\r\n";
attach_exists = true;
} else {
bout << "Attached file \"" << fsr.filename << "\" (" << fsr.numbytes
<< " bytes) is missing!\r\n";
}
}
if (!found) {
l1 = fileAttach.Read(&fsr, sizeof(fsr));
}
}
if (!found) {
bout << "File attached but attachment data missing. Alert sysop!\r\n";
}
} else {
bout << "File attached but attachment data missing. Alert sysop!\r\n";
}
fileAttach.Close();
}
}
do {
char mnu[81];
int delme;
std::string allowable;
write_inst(INST_LOC_RMAIL, 0, INST_FLAGS_NONE);
auto [net, nn] = network_and_num(m);
set_net_num(nn);
i1 = 1;
if (!a()->HasConfigFlag(OP_FLAGS_MAIL_PROMPT)) {
strcpy(mnu, EMAIL_NOEXT);
bout << "|#2Mail {?} : ";
}
if (so()) {
strcpy(mnu, SY_EMAIL_NOEXT);
if (a()->HasConfigFlag(OP_FLAGS_MAIL_PROMPT)) {
bout << "|#2Mail |#7{|#1QSRIDAF?-+GEMZPVUOLCNY@|#7} |#2: ";
}
allowable = "QSRIDAF?-+GEMZPVUOLCNY@";
} else {
if (cs()) {
strcpy(mnu, CS_EMAIL_NOEXT);
if (a()->HasConfigFlag(OP_FLAGS_MAIL_PROMPT)) {
bout << "|#2Mail |#7{|#1QSRIDAF?-+GZPVUOCY@|#7} |#2: ";
}
allowable = "QSRIDAF?-+GZPVUOCY@";
} else {
if (!okmail) {
strcpy(mnu, RS_EMAIL_NOEXT);
if (a()->HasConfigFlag(OP_FLAGS_MAIL_PROMPT)) {
bout << "|#2Mail |#7{|#1QI?-+GY|#7} |#2: ";
}
allowable = "QI?-+G";
} else {
strcpy(mnu, EMAIL_NOEXT);
if (a()->HasConfigFlag(OP_FLAGS_MAIL_PROMPT)) {
bout << "|#2Mail |#7{|#1QSRIDAF?+-GY@|#7} |#2: ";
}
allowable = "QSRIDAF?-+GY@";
}
}
}
if ((m.status & status_file) && found && attach_exists) {
if (a()->HasConfigFlag(OP_FLAGS_MAIL_PROMPT)) {
bout << "\b\b|#7{|#1T|#7} |#2: |#0";
}
allowable += "T";
}
ch = onek(allowable);
if (okmail && !read_same_email(mloc, mw, curmail, m, false, 0)) {
bout << "\r\nMail got deleted.\r\n\n";
ch = 'R';
}
delme = 0;
switch (ch) {
int num_mail1;
int num_mail;
case 'T': {
bout.nl();
auto fn = FilePath(a()->GetAttachmentDirectory(), fsr.filename);
bool sentt;
bool abortt;
send_file(fn.string(), &sentt, &abortt, fsr.filename, -1, fsr.numbytes);
if (sentt) {
bout << "\r\nAttached file sent.\r\n";
sysoplog() << fmt::sprintf("Downloaded %ldk of attached file %s.",
(fsr.numbytes + 1023) / 1024, fsr.filename);
} else {
bout << "\r\nAttached file not completely sent.\r\n";
sysoplog() << fmt::sprintf("Tried to download attached file %s.", fsr.filename);
}
bout.nl();
} break;
case 'N':
if (m.fromuser == 1) {
add_netsubscriber(net, nn, m.fromsys);
} else {
add_netsubscriber(net, nn, 0);
}
break;
case 'E':
if (so() && okmail) {
if (auto o = readfile(&(m.msg), "email")) {
auto b = o.value();
extract_out(b, m.title);
}
}
i1 = 0;
break;
case 'Q':
done = true;
break;
case 'O': {
if (cs() && okmail && m.fromuser != 65535 && nn != 255) {
show_files("*.frm", a()->config()->gfilesdir().c_str());
bout << "|#2Which form letter: ";
auto user_input = bin.input(8, true);
if (user_input.empty()) {
break;
}
auto fn = FilePath(a()->config()->gfilesdir(), StrCat(user_input, ".frm"));
if (!File::Exists(fn)) {
fn = FilePath(a()->config()->gfilesdir(), StrCat("form", user_input, ".msg"));
}
if (File::Exists(fn)) {
LoadFileIntoWorkspace(a()->context(), fn, true);
num_mail = a()->user()->feedback_sent() + a()->user()->email_sent() +
a()->user()->email_net();
clear_quotes(a()->sess());
if (m.fromuser != 65535) {
email(m.title, m.fromuser, m.fromsys, false, m.anony);
}
num_mail1 = static_cast<long>(a()->user()->feedback_sent()) +
static_cast<long>(a()->user()->email_sent()) +
static_cast<long>(a()->user()->email_net());
if (num_mail != num_mail1) {
const auto userandnet =
a()->names()->UserName(a()->sess().user_num(), a()->current_net().sysnum);
std::string msg;
if (m.fromsys != 0) {
msg = StrCat(a()->network_name(), ": ", userandnet);
} else {
msg = userandnet;
}
if (m.anony & anony_receiver) {
msg += ">UNKNOWN<";
}
msg += " read your mail on ";
msg += fulldate();
if (!(m.status & status_source_verified)) {
ssm(m.fromuser, m.fromsys, &net) << msg;
}
read_same_email(mloc, mw, curmail, m, true, 0);
++curmail;
if (curmail >= mw) {
done = true;
}
} else {
// need instance
File::Remove(FilePath(a()->sess().dirs().temp_directory(), INPUT_MSG));
}
} else {
bout << "\r\nFile not found.\r\n\n";
i1 = 0;
}
}
} break;
case 'G': {
bout << "|#2Go to which (1-" << mw << ") ? |#0";
auto user_input = bin.input(3);
i1 = to_number<int>(user_input);
if (i1 > 0 && i1 <= mw) {
curmail = i1 - 1;
i1 = 1;
} else {
i1 = 0;
}
} break;
case 'I':
case '+':
++curmail;
if (curmail >= mw) {
done = true;
}
break;
case '-':
if (curmail) {
--curmail;
}
break;
case 'R':
break;
case '?':
bout.printfile(mnu);
i1 = 0;
break;
case 'M':
if (!okmail) {
break;
}
if (so()) {
if (!a()->sess().IsUserOnline()) {
a()->set_current_user_sub_num(0);
a()->sess().SetCurrentReadMessageArea(0);
a()->sess().set_current_user_sub_conf_num(0);
}
tmp_disable_conf(true);
bout.nl();
std::string ss1;
do {
bout << "|#2Move to which sub? ";
ss1 = mmkey(MMKeyAreaType::subs);
if (ss1[0] == '?') {
old_sublist();
}
} while ((!a()->sess().hangup()) && (ss1[0] == '?'));
auto i = -1;
if ((ss1[0] == 0) || a()->sess().hangup()) {
i1 = 0;
bout.nl();
tmp_disable_conf(false);
break;
}
for (i1 = 0; i1 < size_int(a()->usub); i1++) {
if (ss1 == a()->usub[i1].keys) {
i = i1;
}
}
if (i != -1) {
const auto& sub = a()->subs().sub(a()->usub[i].subnum);
if (!wwiv::bbs::check_acs(sub.post_acs)) {
bout << "\r\nSorry, you don't have post access on that sub.\r\n\n";
i = -1;
}
}
if (i != -1) {
auto o = readfile(&(m.msg), "email");
if (!o) {
break;
}
const auto& b = o.value();
postrec p{};
strcpy(p.title, m.title);
p.anony = m.anony;
p.ownersys = m.fromsys;
a()->SetNumMessagesInCurrentMessageArea(p.owneruser);
p.owneruser = static_cast<uint16_t>(a()->sess().user_num());
p.msg = m.msg;
p.daten = m.daten;
p.status = 0;
iscan(i);
open_sub(true);
if (!a()->current_sub().nets.empty()) {
p.status |= status_pending_net;
}
p.msg.storage_type = static_cast<uint8_t>(a()->current_sub().storage_type);
savefile(b, &(p.msg), a()->current_sub().filename);
a()->status_manager()->Run([&](Status& status) {
p.qscan = status.next_qscanptr();
});
if (a()->GetNumMessagesInCurrentMessageArea() >= a()->current_sub().maxmsgs) {
int i2;
i1 = 1;
i2 = 0;
while (i2 == 0 && i1 <= a()->GetNumMessagesInCurrentMessageArea()) {
if ((get_post(i1)->status & status_no_delete) == 0) {
i2 = i1;
}
++i1;
}
if (i2 == 0) {
i2 = 1;
}
delete_message(i2);
}
add_post(&p);
a()->status_manager()->Run([&](Status& status) {
status.increment_msgs_today();
status.IncrementNumLocalPosts();
});
close_sub();
tmp_disable_conf(false);
iscan(a()->current_user_sub_num());
bout << "\r\n\n|#9Message moved.\r\n\n";
auto temp_num_msgs = a()->GetNumMessagesInCurrentMessageArea();
resynch(&temp_num_msgs, &p);
a()->SetNumMessagesInCurrentMessageArea(temp_num_msgs);
} else {
tmp_disable_conf(false);
}
} break;
case 'D': {
std::string message;
if (!okmail) {
break;
}
bout << "|#5Delete this message? ";
if (!bin.noyes()) {
break;
}
if (m.fromsys != 0) {
message = StrCat(a()->network_name(), ": ",
a()->names()->UserName(a()->sess().user_num(), a()->current_net().sysnum));
} else {
message = a()->names()->UserName(a()->sess().user_num(), a()->current_net().sysnum);
}
if (m.anony & anony_receiver) {
message = ">UNKNOWN<";
}
message += " read your mail on ";
message += fulldate();
if (!(m.status & status_source_verified) && nn != 255) {
ssm(m.fromuser, m.fromsys, &net) << message;
}
}
[[fallthrough]];
case 'Z':
if (!okmail) {
break;
}
read_same_email(mloc, mw, curmail, m, true, 0);
++curmail;
if (curmail >= mw) {
done = true;
}
found = false;
if (m.status & status_file) {
delete_attachment(m.daten, 1);
}
break;
case 'P':
if (!okmail) {
break;
}
purgemail(mloc, mw, &curmail, &m, &sl);
if (curmail >= mw) {
done = true;
}
break;
case 'F': {
if (!okmail) {
break;
}
if (m.status & status_multimail) {
bout << "\r\nCan't forward multimail.\r\n\n";
break;
}
bout.nl(2);
if (okfsed() && a()->user()->auto_quote()) {
// TODO: optimize this since we also call readfile in grab_user_name
auto reply_to_name = grab_user_name(&(m.msg), "email", network_number_from(&m));
if (auto o = readfile(&(m.msg), "email")) {
auto_quote(o.value(), reply_to_name, quote_date_format_t::forward, m.daten,
a()->context());
send_email();
}
break;
}
bout << "|#2Forward to: ";
auto user_input = fixup_user_entered_email(bin.input(75));
auto [un, sn] = parse_email_info(user_input);
if (un || sn) {
if (ForwardMessage(&un, &sn)) {
bout << "Mail forwarded.\r\n";
}
if (un == a()->sess().user_num() && sn == 0 && !cs()) {
bout << "Can't forward to yourself.\r\n";
un = 0;
}
if (un || sn) {
std::string fwd_email_name;
if (sn) {
if (sn == 1 && un == 0 &&
a()->current_net().type == network_type_t::internet) {
fwd_email_name = a()->net_email_name;
} else {
auto netname = size_int(a()->nets()) > 1 ? a()->network_name() : "";
fwd_email_name = username_system_net_as_string(un, a()->net_email_name,
sn, netname);
}
} else {
set_net_num(nn);
fwd_email_name = a()->names()->UserName(un, a()->current_net().sysnum);
}
if (ok_to_mail(un, sn, false)) {
bout << "|#5Forward to " << fwd_email_name << "? ";
if (bin.yesno()) {
auto file = OpenEmailFile(true);
if (!file->IsOpen()) {
break;
}
file->Seek(mloc[curmail].index * sizeof(mailrec), File::Whence::begin);
file->Read(&m, sizeof(mailrec));
if (!same_email(mloc[curmail], m)) {
bout << "Error, mail moved.\r\n";
break;
}
bout << "|#5Delete this message? ";
if (bin.yesno()) {
if (m.status & status_file) {
delete_attachment(m.daten, 0);
}
delme = 1;
m1.touser = 0;
m1.tosys = 0;
m1.daten = 0xffffffff;
m1.msg.storage_type = 0;
m1.msg.stored_as = 0xffffffff;
file->Seek(mloc[curmail].index * sizeof(mailrec), File::Whence::begin);
file->Write(&m1, sizeof(mailrec));
} else {
std::string b;
if (auto o = readfile(&(m.msg), "email")) {
savefile(o.value(), &(m.msg), "email");
}
}
m.status |= status_forwarded;
m.status |= status_seen;
file->Close();
auto net_num = a()->net_num();
const auto fwd_user_name =
a()->names()->UserName(a()->sess().user_num(), a()->current_net().sysnum);
auto s = fmt::sprintf("\r\nForwarded to %s from %s.", fwd_email_name, fwd_user_name);
set_net_num(nn);
net = a()->nets()[nn];
lineadd(&m.msg, s, "email");
s = StrCat(fwd_user_name, " forwarded your mail to ", fwd_email_name);
if (!(m.status & status_source_verified)) {
ssm(m.fromuser, m.fromsys, &net) << s;
}
set_net_num(net_num);
s = StrCat("Forwarded mail to ", fwd_email_name);
if (delme) {
a()->user()->email_waiting(a()->user()->email_waiting() - 1);
}
bout << "Forwarding: ";
::EmailData email;
email.title = m.title;
email.msg = &m.msg;
email.anony = m.anony;
email.user_number = un;
email.system_number = sn;
email.an = true;
email.forwarded_code = delme; // this looks totally wrong to me...
email.silent_mode = false;
if (nn != 255 && nn == a()->net_num()) {
email.from_user = m.fromuser;
email.from_system = m.fromsys ? m.fromsys : a()->nets()[nn].sysnum;
email.from_network_number = nn;
sendout_email(email);
} else {
email.set_from_user(a()->sess().user_num());
email.from_system = a()->current_net().sysnum;
email.from_network_number = a()->net_num();
sendout_email(email);
}
++curmail;
if (curmail >= mw) {
done = true;
}
}
}
}
}
delme = 0;
} break;
case 'A':
case 'S':
case '@': {
if (!okmail) {
break;
}
num_mail = static_cast<long>(a()->user()->feedback_sent()) +
static_cast<long>(a()->user()->email_sent()) +
static_cast<long>(a()->user()->email_net());
if (nn == 255) {
bout << "|#6Deleted network.\r\n";
i1 = 0;
break;
}
if (m.fromuser != 65535) {
std::string reply_to_name;
// TODO: optimize this since we also call readfile in grab_user_name
reply_to_name = grab_user_name(&(m.msg), "email", network_number_from(&m));
if (auto o = readfile(&(m.msg), "email")) {
if (okfsed() && a()->user()->auto_quote()) {
// used to be 1 or 2 depending on s[0] == '@', but
// that's allowable now and @ was never in the beginning.
auto_quote(o.value(), reply_to_name, quote_date_format_t::email, m.daten,
a()->context());
}
grab_quotes(o.value(), reply_to_name, a()->context());
}
if (ch == '@') {
bout << "\r\n|#9Enter user name or number:\r\n:";
auto user_email = fixup_user_entered_email(bin.input(75, true));
auto [un, sy] = parse_email_info(user_email);
if (un || sy) {
email("", un, sy, false, 0);
}
} else {
email("", m.fromuser, m.fromsys, false, m.anony);
}
clear_quotes(a()->sess());
}
num_mail1 = static_cast<long>(a()->user()->feedback_sent()) +
static_cast<long>(a()->user()->email_sent()) +
static_cast<long>(a()->user()->email_net());
if (ch == 'A' || ch == '@') {
if (num_mail != num_mail1) {
std::string message;
const auto name = a()->names()->UserName(a()->sess().user_num(), a()->current_net().sysnum);
if (m.fromsys != 0) {
message = a()->network_name();
message += ": ";
message += name;
} else {
message = name;
}
if (m.anony & anony_receiver) {
message = ">UNKNOWN<";
}
message += " read your mail on ";
message += fulldate();
if (!(m.status & status_source_verified)) {
ssm(m.fromuser, m.fromsys, &net) << message;
}
read_same_email(mloc, mw, curmail, m, true, 0);
++curmail;
if (curmail >= mw) {
done = true;
}
found = false;
if (m.status & status_file) {
delete_attachment(m.daten, 0);
}
} else {
bout << "\r\nNo mail sent.\r\n\n";
i1 = 0;
}
} else {
if (num_mail != num_mail1) {
if (!(m.status & status_replied)) {
read_same_email(mloc, mw, curmail, m, false, status_replied);
}
++curmail;
if (curmail >= mw) {
done = true;
}
}
}
} break;
case 'U':
case 'V':
case 'C':
if (!okmail) {
break;
}
if (m.fromsys == 0 && cs() && m.fromuser != 65535) {
if (ch == 'V') {
valuser(m.fromuser);
}
} else if (cs()) {
bout << "\r\nMail from another system.\r\n\n";
}
i1 = 0;
break;
case 'L': {
if (!so()) {
break;
}
bout << "\r\n|#2Filename: ";
auto fileName = bin.input_path(50);
if (!fileName.empty()) {
bout.nl();
bout << "|#5Allow editing? ";
if (bin.yesno()) {
bout.nl();
LoadFileIntoWorkspace(a()->context(), fileName, false);
} else {
bout.nl();
LoadFileIntoWorkspace(a()->context(), fileName, true);
}
}
} break;
case 'Y': // Add from here
if (curmail >= 0) {
auto o = readfile(&(m.msg), "email");
if (!o) {
break;
}
auto b = o.value();
bout << "E-mail download -\r\n\n|#2Filename: ";
auto downloadFileName = bin.input(12);
if (!okfn(downloadFileName)) {
break;
}
const auto fn = FilePath(a()->sess().dirs().temp_directory(), downloadFileName);
File::Remove(fn);
TextFile tf(fn, "w");
tf.Write(b);
tf.Close();
bool bSent;
bool bAbort;
send_file(fn.string(), &bSent, &bAbort, fn.string(), -1, ssize(b));
if (bSent) {
bout << "E-mail download successful.\r\n";
sysoplog() << "Downloaded E-mail";
} else {
bout << "E-mail download aborted.\r\n";
}
}
break;
}
} while (!i1 && !a()->sess().hangup());
} while (!a()->sess().hangup() && !done);
}
int check_new_mail(int user_number) {
auto new_messages = 0; // number of new mail
if (auto file(OpenEmailFile(false)); file->Exists() && file->IsOpen()) {
const auto mfLength = static_cast<int>(file->length() / sizeof(mailrec));
for (auto i = 0; i < mfLength; i++) {
mailrec m{};
file->Seek(i * sizeof(mailrec), File::Whence::begin);
file->Read(&m, sizeof(mailrec));
if (m.tosys == 0 && m.touser == user_number) {
if (!(m.status & status_seen)) {
++new_messages;
}
}
}
file->Close();
}
return new_messages;
}
|
SECTION code_clib
SECTION code_sound_bit
PUBLIC _bitfx_19
INCLUDE "config_private.inc"
_bitfx_19:
; blurp
ld b,255
blurp2:
push af
ld a,__SOUND_BIT_TOGGLE
ld h,0
ld l,b
and (hl)
ld l,a
pop af
xor l
INCLUDE "sound/bit/z80/output_bit_device_2.inc"
push af
ld a,(hl)
dblurp:
dec a
jr nz, dblurp
pop af
djnz blurp2
ret
|
// Copyright (c) 2009-2012, Andre Caron (andre.l.caron@gmail.com)
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <w32.gdi/MouseCapture.hpp>
#include <w32/Error.hpp>
namespace w32 { namespace gdi {
MouseCapture::MouseCapture ( Window& window )
: myPredecessor(::SetCapture(window.handle()))
{
}
MouseCapture::~MouseCapture ()
{
::SetCapture(myPredecessor);
}
void MouseCapture::release ()
{
if ( ::ReleaseCapture() == 0 ) {
const ::DWORD error = ::GetLastError();
UNCHECKED_WIN32C_ERROR(ReleaseCapture, error);
}
}
} }
|
include "titlescreen/asm/layoutmacros.asm"
include "titlescreen/asm/dpcfix.asm"
include "titlescreen/titlescreen_layout.asm"
.titledrawscreen
title_eat_overscan
;bB runs in overscan. Wait for the overscan to run out...
clc
lda INTIM
bmi title_eat_overscan
jmp title_do_vertical_sync
title_do_vertical_sync
lda #2
sta WSYNC ;one line with VSYNC
sta VSYNC ;enable VSYNC
sta WSYNC ;one line with VSYNC
lda #0
sta WSYNC ;one line with VSYNC
sta VSYNC ;turn off VSYNC
;lda #42+128
ifnconst vblank_time
lda #42+128
else
lda #vblank_time+128
endif
sta TIM64T
titleframe = missile0x
inc titleframe ; increment the frame counter
#ifconst .title_vblank
jsr .title_vblank
#endif
title_vblank_loop
lda INTIM
bmi title_vblank_loop
lda #0
sta WSYNC
sta VBLANK
sta ENAM0
sta ENABL
title_playfield
; ======== BEGIN of the custom kernel!!!!! All of the work is done in the playfield.
lda #230
sta TIM64T
lda #1
sta CTRLPF
clc
lda #0
sta REFP0
sta REFP1
sta WSYNC
lda titlescreencolor
sta COLUBK
titlescreenlayout
jmp PFWAIT ; kernel is done. Finish off the screen
include "titlescreen/asm/position48.asm"
include "titlescreen/titlescreen_color.asm"
#ifconst mk_48x1_1_on
include "titlescreen/asm/48x1_1_kernel.asm"
#endif ;mk_48x1_1_on
#ifconst mk_48x1_2_on
include "titlescreen/asm/48x1_2_kernel.asm"
#endif ;mk_48x1_2_on
#ifconst mk_48x1_3_on
include "titlescreen/asm/48x1_3_kernel.asm"
#endif ;mk_48x1_3_on
#ifconst mk_48x1_4_on
include "titlescreen/asm/48x1_4_kernel.asm"
#endif ;mk_48x1_4_on
#ifconst mk_48x1_5_on
include "titlescreen/asm/48x1_5_kernel.asm"
#endif ;mk_48x1_5_on
#ifconst mk_48x1_6_on
include "titlescreen/asm/48x1_6_kernel.asm"
#endif ;mk_48x1_6_on
#ifconst mk_48x1_7_on
include "titlescreen/asm/48x1_7_kernel.asm"
#endif ;mk_48x1_7_on
#ifconst mk_48x1_8_on
include "titlescreen/asm/48x1_8_kernel.asm"
#endif ;mk_48x1_8_on
#ifconst mk_48x2_1_on
include "titlescreen/asm/48x2_1_kernel.asm"
#endif ;mk_48x2_1_on
#ifconst mk_48x2_2_on
include "titlescreen/asm/48x2_2_kernel.asm"
#endif ;mk_48x2_2_on
#ifconst mk_48x2_3_on
include "titlescreen/asm/48x2_3_kernel.asm"
#endif ;mk_48x2_3_on
#ifconst mk_48x2_4_on
include "titlescreen/asm/48x2_4_kernel.asm"
#endif ;mk_48x2_4_on
#ifconst mk_48x2_5_on
include "titlescreen/asm/48x2_5_kernel.asm"
#endif ;mk_48x2_5_on
#ifconst mk_48x2_6_on
include "titlescreen/asm/48x2_6_kernel.asm"
#endif ;mk_48x2_6_on
#ifconst mk_48x2_7_on
include "titlescreen/asm/48x2_7_kernel.asm"
#endif ;mk_48x2_7_on
#ifconst mk_48x2_8_on
include "titlescreen/asm/48x2_8_kernel.asm"
#endif ;mk_48x2_8_on
#ifconst mk_48x1_X_on
include "titlescreen/asm/48x1_X_kernel.asm"
#endif ;mk_48x1_X_on
#ifconst mk_48x2_X_on
include "titlescreen/asm/48x2_X_kernel.asm"
#endif ;mk_48x2_X_on
#ifconst mk_96x2_1_on
include "titlescreen/asm/96x2_1_kernel.asm"
#endif ;mk_96x2_1_on
#ifconst mk_96x2_2_on
include "titlescreen/asm/96x2_2_kernel.asm"
#endif ;mk_96x2_2_on
#ifconst mk_96x2_3_on
include "titlescreen/asm/96x2_3_kernel.asm"
#endif ;mk_96x2_3_on
#ifconst mk_96x2_4_on
include "titlescreen/asm/96x2_4_kernel.asm"
#endif ;mk_96x2_4_on
#ifconst mk_96x2_5_on
include "titlescreen/asm/96x2_5_kernel.asm"
#endif ;mk_96x2_5_on
#ifconst mk_96x2_6_on
include "titlescreen/asm/96x2_6_kernel.asm"
#endif ;mk_96x2_6_on
#ifconst mk_96x2_7_on
include "titlescreen/asm/96x2_7_kernel.asm"
#endif ;mk_96x2_7_on
#ifconst mk_96x2_8_on
include "titlescreen/asm/96x2_8_kernel.asm"
#endif ;mk_96x2_8_on
#ifconst mk_score_on
include "titlescreen/asm/score_kernel.asm"
#endif ;mk_score_on
#ifconst mk_gameselect_on
include "titlescreen/asm/gameselect_kernel.asm"
#endif ;mk_gameselect_on
PFWAIT
lda INTIM
bne PFWAIT
sta WSYNC
OVERSCAN
ifnconst overscan_time
lda #34+128
else
lda #overscan_time+128-5
endif
sta TIM64T
;fix height variables we borrowed, so DPC doesn't crash on drawscreen...
ifconst player9height
ldy #8
lda #0
sta player0height
.playerheightfixloop
sta player1height,y
ifconst _NUSIZ1
sta _NUSIZ1,y
endif
dey
bpl .playerheightfixloop
endif
lda #%11000010
sta WSYNC
sta VBLANK
RETURN
#ifconst mk_48x1_1_on
include "titlescreen/48x1_1_image.asm"
#endif
#ifconst mk_48x1_2_on
include "titlescreen/48x1_2_image.asm"
#endif
#ifconst mk_48x1_3_on
include "titlescreen/48x1_3_image.asm"
#endif
#ifconst mk_48x1_4_on
include "titlescreen/48x1_4_image.asm"
#endif
#ifconst mk_48x1_5_on
include "titlescreen/48x1_5_image.asm"
#endif
#ifconst mk_48x1_6_on
include "titlescreen/48x1_6_image.asm"
#endif
#ifconst mk_48x1_7_on
include "titlescreen/48x1_7_image.asm"
#endif
#ifconst mk_48x1_8_on
include "titlescreen/48x1_8_image.asm"
#endif
#ifconst mk_48x2_1_on
include "titlescreen/48x2_1_image.asm"
#endif
#ifconst mk_48x2_2_on
include "titlescreen/48x2_2_image.asm"
#endif
#ifconst mk_48x2_3_on
include "titlescreen/48x2_3_image.asm"
#endif
#ifconst mk_48x2_4_on
include "titlescreen/48x2_4_image.asm"
#endif
#ifconst mk_48x2_5_on
include "titlescreen/48x2_5_image.asm"
#endif
#ifconst mk_48x2_6_on
include "titlescreen/48x2_6_image.asm"
#endif
#ifconst mk_48x2_7_on
include "titlescreen/48x2_7_image.asm"
#endif
#ifconst mk_48x2_8_on
include "titlescreen/48x2_8_image.asm"
#endif
#ifconst mk_96x2_1_on
include "titlescreen/96x2_1_image.asm"
#endif
#ifconst mk_96x2_2_on
include "titlescreen/96x2_2_image.asm"
#endif
#ifconst mk_96x2_3_on
include "titlescreen/96x2_3_image.asm"
#endif
#ifconst mk_96x2_4_on
include "titlescreen/96x2_4_image.asm"
#endif
#ifconst mk_96x2_5_on
include "titlescreen/96x2_5_image.asm"
#endif
#ifconst mk_96x2_6_on
include "titlescreen/96x2_6_image.asm"
#endif
#ifconst mk_96x2_7_on
include "titlescreen/96x2_7_image.asm"
#endif
#ifconst mk_96x2_8_on
include "titlescreen/96x2_8_image.asm"
#endif
#ifconst mk_player_on
include "titlescreen/player_image.asm"
#endif
#ifconst mk_score_on
include "titlescreen/score_image.asm"
#endif
#ifconst mk_gameselect_on
include "titlescreen/gameselect_image.asm"
#endif
#ifconst mk_player_on
include "titlescreen/asm/player_kernel.asm"
#endif ;mk_player_on
|
; A249997: Expansion of 1/((1-x)*(1+3*x)*(1-4*x)).
; Submitted by Jon Maiga
; 1,2,15,40,221,702,3355,11780,52041,193402,817895,3138720,12953461,50618102,206059635,813476860,3286192481,13047914802,52482224575,209057202200,838843897101,3347530323502,13413657088715,53584020970740,214547906035321,857556157684202
lpb $0
sub $0,1
mul $2,12
mov $3,$2
add $4,1
mov $2,$4
add $4,$3
lpe
mov $0,$4
add $0,1
|
; Licensed to the .NET Foundation under one or more agreements.
; The .NET Foundation licenses this file to you under the MIT license.
; See the LICENSE file in the project root for more information.
; ***********************************************************************
; File: PInvokeStubs.asm
;
; ***********************************************************************
;
; *** NOTE: If you make changes to this file, propagate the changes to
; PInvokeStubs.s in this directory
; This contains JITinterface routines that are 100% x86 assembly
.586
.model flat
include asmconstants.inc
include asmmacros.inc
option casemap:none
.code
extern _s_gsCookie:DWORD
extern ??_7InlinedCallFrame@@6B@:DWORD
extern _g_TrapReturningThreads:DWORD
extern @JIT_PInvokeEndRarePath@0:proc
.686P
.XMM
;
; in:
; InlinedCallFrame (ecx) = pointer to the InlinedCallFrame data, including the GS cookie slot (GS cookie right
; before actual InlinedCallFrame data)
;
;
_JIT_PInvokeBegin@4 PROC public
mov eax, dword ptr [_s_gsCookie]
mov dword ptr [ecx], eax
add ecx, SIZEOF_GSCookie
;; set first slot to the value of InlinedCallFrame::`vftable' (checked by runtime code)
lea eax,[??_7InlinedCallFrame@@6B@]
mov dword ptr [ecx], eax
mov dword ptr [ecx + InlinedCallFrame__m_Datum], 0
mov eax, esp
add eax, 4
mov dword ptr [ecx + InlinedCallFrame__m_pCallSiteSP], eax
mov dword ptr [ecx + InlinedCallFrame__m_pCalleeSavedFP], ebp
mov eax, [esp]
mov dword ptr [ecx + InlinedCallFrame__m_pCallerReturnAddress], eax
;; edx = GetThread(). Trashes eax
INLINE_GETTHREAD edx, eax
;; pFrame->m_Next = pThread->m_pFrame;
mov eax, dword ptr [edx + Thread_m_pFrame]
mov dword ptr [ecx + Frame__m_Next], eax
;; pThread->m_pFrame = pFrame;
mov dword ptr [edx + Thread_m_pFrame], ecx
;; pThread->m_fPreemptiveGCDisabled = 0
mov dword ptr [edx + Thread_m_fPreemptiveGCDisabled], 0
ret
_JIT_PInvokeBegin@4 ENDP
;
; in:
; InlinedCallFrame (ecx) = pointer to the InlinedCallFrame data, including the GS cookie slot (GS cookie right
; before actual InlinedCallFrame data)
;
;
_JIT_PInvokeEnd@4 PROC public
add ecx, SIZEOF_GSCookie
;; edx = GetThread(). Trashes eax
INLINE_GETTHREAD edx, eax
;; ecx = pFrame
;; edx = pThread
;; pThread->m_fPreemptiveGCDisabled = 1
mov dword ptr [edx + Thread_m_fPreemptiveGCDisabled], 1
;; Check return trap
cmp [_g_TrapReturningThreads], 0
jnz RarePath
;; pThread->m_pFrame = pFrame->m_Next
mov eax, dword ptr [ecx + Frame__m_Next]
mov dword ptr [edx + Thread_m_pFrame], eax
ret
RarePath:
jmp @JIT_PInvokeEndRarePath@0
_JIT_PInvokeEnd@4 ENDP
end
|
; A273692: a(n) is the denominator of 2*O(n+1) - O(n+2) where O(n) = n/2^n, the n-th Oresme number.
; Submitted by Jamie Morken(s3)
; 2,8,2,32,32,128,64,512,512,2048,128,8192,8192,32768,16384,131072,131072,524288,131072,2097152,2097152,8388608,4194304,33554432,33554432,134217728,16777216,536870912,536870912,2147483648,1073741824,8589934592,8589934592,34359738368,8589934592,137438953472,137438953472,549755813888,274877906944,2199023255552,2199023255552,8796093022208,137438953472,35184372088832,35184372088832,140737488355328,70368744177664,562949953421312,562949953421312,2251799813685248,562949953421312,9007199254740992
add $0,1
mov $2,2
mov $3,$0
div $3,$0
mov $4,$0
lpb $3
mov $5,$4
lpb $5
sub $0,1
mul $0,-1
mov $6,$0
div $0,$2
mod $6,$2
cmp $6,0
sub $5,$6
lpe
div $3,2
lpe
pow $2,$5
mov $0,$2
mul $0,2
|
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's 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.
//
// * The name of the copyright holders may not 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 Intel Corporation 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.
//
//M*/
#include "precomp.hpp"
using namespace cv;
using namespace cv::cuda;
#if !defined (HAVE_HIP) || defined (CUDA_DISABLER)
void cv::cuda::merge(const GpuMat*, size_t, OutputArray, Stream&) { throw_no_cuda(); }
void cv::cuda::merge(const std::vector<GpuMat>&, OutputArray, Stream&) { throw_no_cuda(); }
void cv::cuda::split(InputArray, GpuMat*, Stream&) { throw_no_cuda(); }
void cv::cuda::split(InputArray, std::vector<GpuMat>&, Stream&) { throw_no_cuda(); }
void cv::cuda::transpose(InputArray, OutputArray, Stream&) { throw_no_cuda(); }
void cv::cuda::flip(InputArray, OutputArray, int, Stream&) { throw_no_cuda(); }
Ptr<LookUpTable> cv::cuda::createLookUpTable(InputArray) { throw_no_cuda(); return Ptr<LookUpTable>(); }
void cv::cuda::copyMakeBorder(InputArray, OutputArray, int, int, int, int, int, Scalar, Stream&) { throw_no_cuda(); }
#else /* !defined (HAVE_HIP) */
////////////////////////////////////////////////////////////////////////
// flip
namespace
{
#ifdef NPP_ENABLE
template<int DEPTH> struct NppTypeTraits;
template<> struct NppTypeTraits<CV_8U> { typedef Npp8u npp_t; };
template<> struct NppTypeTraits<CV_8S> { typedef Npp8s npp_t; };
template<> struct NppTypeTraits<CV_16U> { typedef Npp16u npp_t; };
template<> struct NppTypeTraits<CV_16S> { typedef Npp16s npp_t; };
template<> struct NppTypeTraits<CV_32S> { typedef Npp32s npp_t; };
template<> struct NppTypeTraits<CV_32F> { typedef Npp32f npp_t; };
template<> struct NppTypeTraits<CV_64F> { typedef Npp64f npp_t; };
template <int DEPTH> struct NppMirrorFunc
{
typedef typename NppTypeTraits<DEPTH>::npp_t npp_t;
typedef NppStatus (*func_t)(const npp_t* pSrc, int nSrcStep, npp_t* pDst, int nDstStep, NppiSize oROI, NppiAxis flip);
};
template <int DEPTH, typename NppMirrorFunc<DEPTH>::func_t func> struct NppMirror
{
typedef typename NppMirrorFunc<DEPTH>::npp_t npp_t;
static void call(const GpuMat& src, GpuMat& dst, int flipCode, hipStream_t stream)
{
NppStreamHandler h(stream);
NppiSize sz;
sz.width = src.cols;
sz.height = src.rows;
nppSafeCall( func(src.ptr<npp_t>(), static_cast<int>(src.step),
dst.ptr<npp_t>(), static_cast<int>(dst.step), sz,
(flipCode == 0 ? NPP_HORIZONTAL_AXIS : (flipCode > 0 ? NPP_VERTICAL_AXIS : NPP_BOTH_AXIS))) );
if (stream == 0)
cudaSafeCall( hipDeviceSynchronize() );
}
};
#endif //NPP_ENABLE
}
void cv::cuda::flip(InputArray _src, OutputArray _dst, int flipCode, Stream& stream)
{
typedef void (*func_t)(const GpuMat& src, GpuMat& dst, int flipCode, hipStream_t stream);
static const func_t funcs[6][4] =
{
#ifdef NPP_ENABLE
{NppMirror<CV_8U, nppiMirror_8u_C1R>::call, 0, NppMirror<CV_8U, nppiMirror_8u_C3R>::call, NppMirror<CV_8U, nppiMirror_8u_C4R>::call},
{0,0,0,0},
{NppMirror<CV_16U, nppiMirror_16u_C1R>::call, 0, NppMirror<CV_16U, nppiMirror_16u_C3R>::call, NppMirror<CV_16U, nppiMirror_16u_C4R>::call},
{0,0,0,0},
{NppMirror<CV_32S, nppiMirror_32s_C1R>::call, 0, NppMirror<CV_32S, nppiMirror_32s_C3R>::call, NppMirror<CV_32S, nppiMirror_32s_C4R>::call},
{NppMirror<CV_32F, nppiMirror_32f_C1R>::call, 0, NppMirror<CV_32F, nppiMirror_32f_C3R>::call, NppMirror<CV_32F, nppiMirror_32f_C4R>::call}
#endif //NPP_ENABLE
};
GpuMat src = getInputMat(_src, stream);
CV_Assert(src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32S || src.depth() == CV_32F);
CV_Assert(src.channels() == 1 || src.channels() == 3 || src.channels() == 4);
_dst.create(src.size(), src.type());
GpuMat dst = getOutputMat(_dst, src.size(), src.type(), stream);
funcs[src.depth()][src.channels() - 1](src, dst, flipCode, StreamAccessor::getStream(stream));
syncOutput(dst, _dst, stream);
}
#endif /* !defined (HAVE_HIP) */
|
; A134486: a(0)=1; for n>=1, a(n) = the largest prime dividing n*a(n-1) + 1.
; Submitted by Christian Krause
; 1,2,5,2,3,2,13,23,37,167,557,383,4597,29881,167,179,191,29,523,4969,211,277,53,61,293,37,107,17,53,769,23071,661,641,1511,137,109,157,83,631,107,1427,14627,122867,103,1511,191,101,1187,251,41,293,467,1619
mov $6,$0
mov $7,$0
add $7,1
lpb $7
mov $0,$6
sub $7,1
sub $0,$7
mul $0,$2
add $0,1
mov $2,1
lpb $0
mov $3,$0
lpb $3
mov $4,$0
mod $4,$2
cmp $4,0
cmp $4,0
mov $5,$2
add $2,1
cmp $5,1
max $4,$5
sub $3,$4
lpe
lpb $0
dif $0,$2
lpe
lpe
lpe
mov $0,$2
|
INCLUDE "graphics/grafix.inc"
SECTION code_graphics
PUBLIC respixel
EXTERN pixeladdress
EXTERN __gfx_coords
;
; $Id: respixl.asm,v 1.7 2016-07-02 09:01:35 dom Exp $
;
; ******************************************************************
;
; Reset pixel at (x,y) coordinate
;
; Design & programming by Gunther Strube, Copyright (C) InterLogic 1995
;
; in: hl = (x,y) coordinate of pixel (h,l)
;
; registers changed after return:
; ..bc..../ixiy same
; af..dehl/.... different
;
.respixel
IF maxx <> 256
ld a,h
cp maxx
ret nc
ENDIF
IF maxy <> 256
ld a,l
cp maxy
ret nc ; y0 out of range
ENDIF
ld (__gfx_coords),hl
push bc
call pixeladdress
ld b,a
ld a,1
jr z, reset_pixel
.reset_position rlca
djnz reset_position
.reset_pixel ex de,hl
cpl
and (hl)
ld (hl),a
pop bc
ret
|
; A331322: a(n) = (3*n + 1)!/(n!)^3.
; Submitted by Jon Maiga
; 1,24,630,16800,450450,12108096,325909584,8779605120,236637794250,6380456082000,172080900531540,4641917845743360,125235075213284400,3379123922914656000,91184624634161304000,2460769070127233057280,66411927755894739034170,1792432652235221330334000
mov $1,$0
mul $0,2
bin $0,$1
mul $0,2
seq $1,90816 ; a(n) = (3*n+1)!/((2*n)! * n!).
mul $0,$1
div $0,2
|
.global s_prepare_buffers
s_prepare_buffers:
push %r12
push %r14
push %rax
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_A_ht+0x157a1, %rax
nop
nop
nop
and $16397, %r14
mov (%rax), %r12
nop
nop
add %rsi, %rsi
lea addresses_WC_ht+0x14717, %rsi
lea addresses_WT_ht+0xa2fd, %rdi
nop
nop
nop
nop
and %rax, %rax
mov $101, %rcx
rep movsb
sub %r12, %r12
lea addresses_WT_ht+0x1df37, %rsi
lea addresses_D_ht+0x1c9a1, %rdi
clflush (%rsi)
nop
nop
sub $28030, %rdx
mov $79, %rcx
rep movsw
nop
nop
nop
nop
cmp %r12, %r12
lea addresses_UC_ht+0x1ce21, %rdi
nop
nop
nop
add $36211, %rax
mov $0x6162636465666768, %rcx
movq %rcx, %xmm4
movups %xmm4, (%rdi)
nop
nop
nop
nop
nop
cmp $26666, %rdx
lea addresses_WT_ht+0x16981, %rdi
nop
nop
nop
cmp $14815, %r14
movups (%rdi), %xmm5
vpextrq $1, %xmm5, %rax
nop
nop
and $7397, %rcx
lea addresses_UC_ht+0xecc1, %r12
nop
nop
nop
dec %rdx
movl $0x61626364, (%r12)
nop
nop
add %r12, %r12
lea addresses_normal_ht+0xdba1, %rcx
clflush (%rcx)
nop
nop
add $26248, %rax
movb $0x61, (%rcx)
nop
nop
nop
nop
nop
add %rdi, %rdi
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rax
pop %r14
pop %r12
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r11
push %r12
push %r13
push %r15
push %rbx
push %rdx
// Store
lea addresses_UC+0x69a1, %r10
nop
nop
nop
nop
xor %r13, %r13
mov $0x5152535455565758, %r15
movq %r15, (%r10)
nop
nop
xor %r13, %r13
// Store
lea addresses_normal+0x1b7a1, %r10
sub %r12, %r12
movb $0x51, (%r10)
nop
nop
xor $3894, %r15
// Load
lea addresses_normal+0x17ec5, %rdx
inc %r13
movb (%rdx), %bl
nop
nop
xor %r15, %r15
// Store
lea addresses_normal+0x13ea1, %rbx
nop
nop
nop
nop
nop
xor $59950, %rdx
movl $0x51525354, (%rbx)
nop
nop
xor %r13, %r13
// Store
lea addresses_PSE+0xf9a1, %r15
nop
mfence
movw $0x5152, (%r15)
nop
nop
nop
nop
dec %r10
// Store
lea addresses_RW+0x2b21, %rbx
add %r11, %r11
mov $0x5152535455565758, %r12
movq %r12, (%rbx)
nop
nop
nop
add %r12, %r12
// Store
mov $0xea3ca00000002a1, %r15
nop
inc %r11
movw $0x5152, (%r15)
nop
nop
sub %r15, %r15
// Store
lea addresses_A+0x106b1, %r15
nop
nop
nop
nop
nop
sub $38661, %r11
movl $0x51525354, (%r15)
nop
inc %r11
// Store
lea addresses_A+0x12a0d, %r13
nop
add $61282, %rbx
movw $0x5152, (%r13)
nop
nop
nop
cmp $57217, %r12
// Store
lea addresses_D+0x16b0d, %rdx
nop
nop
nop
cmp $37806, %r10
mov $0x5152535455565758, %rbx
movq %rbx, (%rdx)
nop
nop
nop
cmp $33563, %rbx
// Store
lea addresses_normal+0x1a561, %rbx
and $50562, %r10
movl $0x51525354, (%rbx)
nop
nop
nop
nop
nop
sub %r11, %r11
// Faulty Load
lea addresses_UC+0x69a1, %r10
nop
nop
and $33200, %r13
vmovntdqa (%r10), %ymm5
vextracti128 $0, %ymm5, %xmm5
vpextrq $0, %xmm5, %r11
lea oracles, %r10
and $0xff, %r11
shlq $12, %r11
mov (%r10,%r11,1), %r11
pop %rdx
pop %rbx
pop %r15
pop %r13
pop %r12
pop %r11
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'src': {'type': 'addresses_UC', 'same': True, 'size': 2, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'dst': {'type': 'addresses_UC', 'same': True, 'size': 8, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'dst': {'type': 'addresses_normal', 'same': False, 'size': 1, 'congruent': 9, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'src': {'type': 'addresses_normal', 'same': False, 'size': 1, 'congruent': 1, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'dst': {'type': 'addresses_normal', 'same': False, 'size': 4, 'congruent': 4, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'dst': {'type': 'addresses_PSE', 'same': False, 'size': 2, 'congruent': 10, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'dst': {'type': 'addresses_RW', 'same': False, 'size': 8, 'congruent': 5, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'dst': {'type': 'addresses_NC', 'same': False, 'size': 2, 'congruent': 8, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'dst': {'type': 'addresses_A', 'same': False, 'size': 4, 'congruent': 3, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'dst': {'type': 'addresses_A', 'same': False, 'size': 2, 'congruent': 2, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'dst': {'type': 'addresses_D', 'same': False, 'size': 8, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'dst': {'type': 'addresses_normal', 'same': False, 'size': 4, 'congruent': 5, 'NT': True, 'AVXalign': False}, 'OP': 'STOR'}
[Faulty Load]
{'src': {'type': 'addresses_UC', 'same': True, 'size': 32, 'congruent': 0, 'NT': True, 'AVXalign': False}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'type': 'addresses_A_ht', 'same': False, 'size': 8, 'congruent': 9, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_WC_ht', 'congruent': 1, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 1, 'same': False}, 'OP': 'REPM'}
{'src': {'type': 'addresses_WT_ht', 'congruent': 0, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 7, 'same': True}, 'OP': 'REPM'}
{'dst': {'type': 'addresses_UC_ht', 'same': False, 'size': 16, 'congruent': 6, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'src': {'type': 'addresses_WT_ht', 'same': False, 'size': 16, 'congruent': 5, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'dst': {'type': 'addresses_UC_ht', 'same': False, 'size': 4, 'congruent': 5, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'dst': {'type': 'addresses_normal_ht', 'same': False, 'size': 1, 'congruent': 9, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'00': 16802, '52': 5027}
52 52 00 00 00 00 00 52 00 00 00 52 52 00 00 52 00 00 00 00 00 00 00 00 00 00 00 52 00 00 00 00 00 00 52 00 00 00 00 00 00 00 00 52 00 52 52 52 00 00 52 52 52 52 52 00 00 52 00 00 00 00 00 00 00 00 52 00 00 52 00 52 00 00 00 52 52 52 52 52 00 00 00 52 52 52 00 52 00 00 52 00 00 52 52 00 52 00 00 00 00 00 00 00 00 00 00 00 00 52 00 00 52 00 00 52 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 52 52 52 52 52 00 00 52 00 00 00 00 00 00 00 00 00 00 52 00 52 00 00 00 00 52 00 00 00 00 00 52 52 00 00 00 00 00 00 00 00 00 52 52 52 00 00 00 00 00 00 00 00 00 00 00 00 52 00 00 52 00 00 00 00 52 52 00 00 00 00 00 52 52 00 52 52 00 00 00 00 52 00 00 52 00 00 52 00 00 00 52 00 00 00 52 52 00 00 00 52 52 00 00 00 00 00 00 00 00 00 00 52 52 52 00 00 00 52 52 52 00 00 00 52 00 52 52 00 00 00 52 00 52 00 52 00 52 00 52 52 00 00 00 00 52 52 52 52 00 00 00 00 00 00 00 00 00 00 00 00 00 00 52 00 00 00 00 00 00 00 00 00 52 00 00 00 00 00 00 00 00 00 00 52 00 52 00 00 52 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 52 00 00 52 00 52 00 52 00 00 52 00 00 00 52 00 00 52 52 00 52 52 52 00 00 00 00 52 52 00 00 00 52 00 00 00 00 00 00 52 52 52 52 00 00 00 00 00 52 52 00 00 00 00 00 00 00 00 00 52 52 52 52 00 00 00 00 52 00 52 52 00 00 00 00 52 00 52 00 00 00 00 00 00 52 00 00 52 00 00 52 00 00 52 00 00 00 00 52 00 00 52 00 00 52 52 00 00 00 00 00 00 00 00 00 00 52 52 00 00 00 00 00 00 00 00 00 00 00 00 52 00 00 00 00 00 52 00 00 00 00 00 00 00 00 00 52 00 52 00 52 52 00 52 52 52 00 00 00 52 00 52 00 00 52 00 52 00 00 00 52 00 00 00 00 52 00 00 00 00 00 00 00 00 00 00 00 00 00 00 52 00 00 00 00 52 00 52 00 52 00 52 00 52 52 00 00 52 52 00 52 00 00 00 52 00 52 00 00 00 00 00 00 52 00 00 00 00 00 52 00 00 00 00 00 00 00 52 00 00 00 00 00 00 52 00 00 00 00 00 00 52 00 00 00 00 00 00 00 00 52 52 00 00 52 52 00 00 52 00 00 00 00 00 00 00 00 00 00 00 00 00 00 52 52 00 00 52 00 52 52 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 52 00 00 00 00 00 00 00 00 52 52 00 00 52 00 00 00 00 00 00 00 00 00 00 00 00 52 00 00 52 00 00 52 52 00 52 52 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 52 00 00 52 00 00 00 00 00 00 00 52 00 00 00 00 00 52 00 52 00 00 52 00 00 00 52 00 52 52 52 52 00 00 00 00 00 00 52 00 52 00 00 00 00 00 00 00 00 00 00 52 00 00 00 00 00 00 00 00 00 52 52 00 00 52 00 00 00 00 00 00 00 52 52 52 00 00 52 00 00 52 00 00 00 00 52 00 00 00 00 52 52 00 00 52 00 00 00 00 00 00 00 00 00 00 00 52 00 00 00 00 00 00 00 00 00 00 52 00 00 00 00 52 00 00 52 52 00 00 52 00 00 00 00 00 00 00 52 52 00 52 52 00 52 00 00 00 00 00 52 00 00 00 00 00 52 52 00 00 00 00 00 00 00 00 52 00 00 00 52 00 00 00 52 00 00 00 52 00 00 52 00 52 00 00 00 00 00 00 00 00 52 00 00 00 00 00 00 00 00 52 52 52 52 52 00 00 52 00 00 00 00 00 00 00 00 00 52 00 00 00 00 00 00 00 00 00 52 00 00 00 00 00 00 52 00 52 52 00 00 00 00 00 00 00 00 00 52 00 00 00 52 00 00 00 00 00 00 52 00 00 00 52 00 00 00 00 00 52 00 00 00 00 00 52 52 52
*/
|
; PLAY68 Sine Wave
;
; by Robin Grosset
;
OUTCH equ $e1d1
INCH equ $e1ac
CONTRL equ $e0e3
OUT4HS equ $e0c8
OUT2HS equ $e0ca
LF equ $0a
CR equ $0d
MIKBUG equ $e0d0
PDATA1 equ $e07e
code
org $1EE0
ldx #GREET
jsr PDATA1 ; say hello
start ldx #WAVE64
loop ldaa 0,x
beq start
staa $8010 ; output to sound card
inx
bra loop ; keep going
GREET db CR,LF,LF,LF,LF
fcc "M68 Audio Board Sine Wave Play!"
db CR,LF,LF,4
; 633 Hz
WAVE64 fcb $DC,$28,$38,$A0,$AC,$B8,$64,$6C,$78,$E0,$E4,$EC,$F0,$F4,$F8,$F8
fcb $F8,$F8,$F8,$F4,$F0,$EC,$E4,$E0,$78,$6C,$64,$B8,$AC,$A0,$38,$28
fcb $DC,$D0,$C4,$58,$4C,$44,$98,$90,$84,$1C,$14,$10,$08,$04,$04,$01
fcb $01,$01,$04,$04,$08,$10,$14,$1C,$84,$90,$98,$44,$4C,$58,$C4,$00
fcb $00
; 1.25 Khz
WAVE32 fcb $DC,$38,$AC,$64,$78,$E4,$F0,$F8,$F8,$F8,$F0,$E4,$78,$64,$AC,$38
fcb $DC,$C4,$4C,$98,$84,$14,$08,$04,$01,$04,$08,$14,$84,$98,$4C,$C4
fcb $00
|
/*
* abstractAI.hpp
*
* Created on: 16.01.2015
* Author: helvete
*/
#ifndef ABSTRACTAI_HPP_
#define ABSTRACTAI_HPP_
#include <QObject>
using namespace bb::system;
//Auch wenn es eine abstrakte klasse ist, muss es von QObjects erben
class Ai : public QObject {
public:
virtual ~Ai() {}
virtual void openGmap(const QVariantMap&)=0;
virtual void openBing(const QVariantMap&)=0;
virtual void openOpenMap(const QVariantMap&)=0;
virtual void openHereMap(const QVariantMap&)=0;
};
#endif /* ABSTRACTAI_HPP_ */
|
; A157325: a(n) = 1728*n + 24.
; 1752,3480,5208,6936,8664,10392,12120,13848,15576,17304,19032,20760,22488,24216,25944,27672,29400,31128,32856,34584,36312,38040,39768,41496,43224,44952,46680,48408,50136,51864,53592,55320,57048,58776,60504,62232,63960,65688,67416,69144,70872,72600,74328,76056,77784,79512,81240,82968,84696,86424,88152,89880,91608,93336,95064,96792,98520,100248,101976,103704,105432,107160,108888,110616,112344,114072,115800,117528,119256,120984,122712,124440,126168,127896,129624,131352,133080,134808,136536,138264,139992,141720,143448,145176,146904,148632,150360,152088,153816,155544,157272,159000,160728,162456,164184,165912,167640,169368,171096,172824,174552,176280,178008,179736,181464,183192,184920,186648,188376,190104,191832,193560,195288,197016,198744,200472,202200,203928,205656,207384,209112,210840,212568,214296,216024,217752,219480,221208,222936,224664,226392,228120,229848,231576,233304,235032,236760,238488,240216,241944,243672,245400,247128,248856,250584,252312,254040,255768,257496,259224,260952,262680,264408,266136,267864,269592,271320,273048,274776,276504,278232,279960,281688,283416,285144,286872,288600,290328,292056,293784,295512,297240,298968,300696,302424,304152,305880,307608,309336,311064,312792,314520,316248,317976,319704,321432,323160,324888,326616,328344,330072,331800,333528,335256,336984,338712,340440,342168,343896,345624,347352,349080,350808,352536,354264,355992,357720,359448,361176,362904,364632,366360,368088,369816,371544,373272,375000,376728,378456,380184,381912,383640,385368,387096,388824,390552,392280,394008,395736,397464,399192,400920,402648,404376,406104,407832,409560,411288,413016,414744,416472,418200,419928,421656,423384,425112,426840,428568,430296,432024
mov $1,$0
mul $1,1728
add $1,1752
|
.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_WC_ht+0x197f8, %r10
nop
add $38741, %rcx
movups (%r10), %xmm0
vpextrq $1, %xmm0, %rsi
nop
and $40286, %r13
lea addresses_UC_ht+0xcff8, %rsi
lea addresses_WT_ht+0xcaa8, %rdi
dec %rdx
mov $14, %rcx
rep movsw
nop
nop
nop
nop
and %rcx, %rcx
lea addresses_A_ht+0x1d038, %rdi
clflush (%rdi)
nop
nop
nop
nop
nop
inc %r15
movw $0x6162, (%rdi)
nop
nop
nop
cmp %rcx, %rcx
lea addresses_UC_ht+0x7298, %r13
nop
nop
inc %r15
movups (%r13), %xmm1
vpextrq $0, %xmm1, %rdx
nop
nop
nop
nop
xor %r13, %r13
lea addresses_UC_ht+0x15038, %r13
nop
nop
xor $4856, %rdi
mov $0x6162636465666768, %rdx
movq %rdx, %xmm5
vmovups %ymm5, (%r13)
nop
nop
nop
sub %r15, %r15
lea addresses_WC_ht+0x738, %r13
cmp %rdx, %rdx
mov (%r13), %di
nop
nop
nop
add $12412, %r13
lea addresses_WT_ht+0x5f8, %rsi
lea addresses_WT_ht+0x11bb8, %rdi
nop
and $16958, %rbx
mov $110, %rcx
rep movsl
nop
nop
nop
nop
nop
inc %r13
lea addresses_UC_ht+0x16ec4, %rsi
nop
and %r13, %r13
mov $0x6162636465666768, %r10
movq %r10, %xmm1
movups %xmm1, (%rsi)
nop
inc %r13
lea addresses_WC_ht+0x6e38, %rdi
nop
cmp %r13, %r13
movb (%rdi), %r10b
sub %rdx, %rdx
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 %r10
push %r13
push %r14
push %rbx
push %rcx
push %rdi
push %rsi
// REPMOV
lea addresses_UC+0xfd78, %rsi
lea addresses_PSE+0x1e838, %rdi
clflush (%rdi)
nop
nop
nop
nop
nop
sub $63570, %r10
mov $56, %rcx
rep movsw
lfence
// Load
lea addresses_RW+0x2238, %r14
nop
nop
dec %rbx
vmovups (%r14), %ymm0
vextracti128 $1, %ymm0, %xmm0
vpextrq $1, %xmm0, %r10
nop
nop
nop
xor $39065, %rdi
// Store
lea addresses_normal+0x2e48, %rbx
nop
nop
nop
nop
xor %r10, %r10
mov $0x5152535455565758, %r13
movq %r13, %xmm4
vmovups %ymm4, (%rbx)
nop
and $53316, %r13
// Faulty Load
lea addresses_PSE+0x1e838, %r13
nop
nop
nop
cmp $25575, %r14
movb (%r13), %r10b
lea oracles, %r13
and $0xff, %r10
shlq $12, %r10
mov (%r13,%r10,1), %r10
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %r14
pop %r13
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_PSE', 'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 0}}
{'OP': 'REPM', 'src': {'same': False, 'congruent': 5, 'type': 'addresses_UC'}, 'dst': {'same': True, 'congruent': 0, 'type': 'addresses_PSE'}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_RW', 'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 9}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_normal', 'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 3}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'same': True, 'type': 'addresses_PSE', 'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 0}}
<gen_prepare_buffer>
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_WC_ht', 'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 6}}
{'OP': 'REPM', 'src': {'same': False, 'congruent': 5, 'type': 'addresses_UC_ht'}, 'dst': {'same': False, 'congruent': 3, 'type': 'addresses_WT_ht'}}
{'OP': 'STOR', 'dst': {'same': False, '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': 16, 'congruent': 4}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_UC_ht', 'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 9}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_WC_ht', 'NT': False, 'AVXalign': True, 'size': 2, 'congruent': 8}}
{'OP': 'REPM', 'src': {'same': False, 'congruent': 4, 'type': 'addresses_WT_ht'}, 'dst': {'same': False, 'congruent': 6, 'type': 'addresses_WT_ht'}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_UC_ht', 'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 2}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_WC_ht', 'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 2}}
{'37': 21829}
37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37
*/
|
; void *p_list_front(p_list_t *list)
SECTION code_clib
SECTION code_adt_p_list
PUBLIC p_list_front
EXTERN asm_p_list_front
defc p_list_front = asm_p_list_front
|
; A022091: Fibonacci sequence beginning 0, 8.
; Submitted by Jon Maiga
; 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,$3
add $3,$1
mov $1,$2
lpe
mov $0,$1
mul $0,8
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r14
push %r9
push %rax
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_D_ht+0x31f2, %rdi
nop
dec %rax
vmovups (%rdi), %ymm0
vextracti128 $1, %ymm0, %xmm0
vpextrq $0, %xmm0, %rbx
nop
nop
nop
and %rdi, %rdi
lea addresses_WT_ht+0xf921, %rsi
nop
nop
nop
nop
nop
add %r10, %r10
mov (%rsi), %r14
add $1495, %rsi
lea addresses_WT_ht+0xd933, %rdi
nop
cmp %r9, %r9
movb (%rdi), %r10b
nop
nop
nop
nop
nop
cmp %rsi, %rsi
lea addresses_A_ht+0x5ee3, %r10
and %rdi, %rdi
movb $0x61, (%r10)
nop
nop
nop
nop
dec %rax
lea addresses_normal_ht+0x1da93, %r14
nop
nop
xor %rax, %rax
movw $0x6162, (%r14)
nop
nop
nop
nop
nop
add $660, %rbx
lea addresses_WT_ht+0x147f9, %rsi
lea addresses_A_ht+0x1b9a5, %rdi
nop
nop
nop
cmp %r9, %r9
mov $73, %rcx
rep movsb
nop
nop
nop
and %rbx, %rbx
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rax
pop %r9
pop %r14
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r12
push %r13
push %rbx
push %rcx
push %rdi
push %rsi
// Store
lea addresses_WT+0x1adfd, %rdi
nop
nop
nop
nop
nop
xor %r11, %r11
mov $0x5152535455565758, %r13
movq %r13, (%rdi)
and $40067, %rdi
// Store
lea addresses_D+0x10ffd, %r12
nop
sub $48117, %rcx
movb $0x51, (%r12)
xor $62659, %rcx
// Faulty Load
lea addresses_D+0x3afd, %rbx
nop
nop
dec %rsi
mov (%rbx), %r11
lea oracles, %r12
and $0xff, %r11
shlq $12, %r11
mov (%r12,%r11,1), %r11
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %r13
pop %r12
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'size': 2, 'NT': False, 'type': 'addresses_D', 'same': False, 'AVXalign': False, 'congruent': 0}}
{'OP': 'STOR', 'dst': {'size': 8, 'NT': False, 'type': 'addresses_WT', 'same': False, 'AVXalign': False, 'congruent': 8}}
{'OP': 'STOR', 'dst': {'size': 1, 'NT': False, 'type': 'addresses_D', 'same': False, 'AVXalign': False, 'congruent': 8}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'size': 8, 'NT': False, 'type': 'addresses_D', 'same': True, 'AVXalign': True, 'congruent': 0}}
<gen_prepare_buffer>
{'OP': 'LOAD', 'src': {'size': 32, 'NT': False, 'type': 'addresses_D_ht', 'same': False, 'AVXalign': False, 'congruent': 0}}
{'OP': 'LOAD', 'src': {'size': 8, 'NT': False, 'type': 'addresses_WT_ht', 'same': False, 'AVXalign': False, 'congruent': 2}}
{'OP': 'LOAD', 'src': {'size': 1, 'NT': False, 'type': 'addresses_WT_ht', 'same': False, 'AVXalign': False, 'congruent': 0}}
{'OP': 'STOR', 'dst': {'size': 1, 'NT': False, 'type': 'addresses_A_ht', 'same': False, 'AVXalign': False, 'congruent': 1}}
{'OP': 'STOR', 'dst': {'size': 2, 'NT': False, 'type': 'addresses_normal_ht', 'same': False, 'AVXalign': False, 'congruent': 0}}
{'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_WT_ht', 'congruent': 1}, 'dst': {'same': False, 'type': 'addresses_A_ht', 'congruent': 3}}
{'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
*/
|
; A097140: Interleave n and 1-n.
; 0,1,1,0,2,-1,3,-2,4,-3,5,-4,6,-5,7,-6,8,-7,9,-8,10,-9,11,-10,12,-11,13,-12,14,-13,15,-14,16,-15,17,-16,18,-17,19,-18,20,-19,21,-20,22,-21,23,-22,24,-23,25,-24,26,-25,27,-26,28,-27,29,-28,30,-29,31,-30,32,-31,33,-32,34,-33,35,-34,36,-35,37,-36,38,-37,39,-38,40,-39,41,-40,42,-41,43,-42,44,-43,45,-44,46,-45,47,-46,48,-47,49,-48
mov $1,$0
sub $0,2
dif $0,2
sub $1,1
dif $1,2
sub $1,$0
mov $0,$1
|
/*
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#include <osquery/config.h>
#include <osquery/core.h>
#include <osquery/extensions.h>
#include <osquery/events.h>
#include <osquery/flags.h>
#include <osquery/logger.h>
#include <osquery/registry.h>
#include <osquery/sql.h>
#include <osquery/tables.h>
#include <osquery/filesystem.h>
namespace osquery {
namespace tables {
QueryData genOsqueryEvents(QueryContext& context) {
QueryData results;
auto publishers = EventFactory::publisherTypes();
for (const auto& publisher : publishers) {
Row r;
r["name"] = publisher;
r["publisher"] = publisher;
r["type"] = "publisher";
auto pubref = EventFactory::getEventPublisher(publisher);
if (pubref != nullptr) {
r["subscriptions"] = INTEGER(pubref->numSubscriptions());
r["events"] = INTEGER(pubref->numEvents());
r["restarts"] = INTEGER(pubref->restartCount());
r["active"] = (pubref->hasStarted() && !pubref->isEnding()) ? "1" : "0";
} else {
r["subscriptions"] = "0";
r["events"] = "0";
r["restarts"] = "0";
r["active"] = "-1";
}
results.push_back(r);
}
auto subscribers = EventFactory::subscriberNames();
for (const auto& subscriber : subscribers) {
Row r;
r["name"] = subscriber;
r["type"] = "subscriber";
// Subscribers will never 'restart'.
r["restarts"] = "0";
auto subref = EventFactory::getEventSubscriber(subscriber);
if (subref != nullptr) {
r["publisher"] = subref->getType();
r["subscriptions"] = INTEGER(subref->numSubscriptions());
r["events"] = INTEGER(subref->numEvents());
// Subscribers are always active, even if their publisher is not.
r["active"] = (subref->state() == SUBSCRIBER_RUNNING) ? "1" : "0";
} else {
r["subscriptions"] = "0";
r["events"] = "0";
r["active"] = "-1";
}
results.push_back(r);
}
return results;
}
QueryData genOsqueryPacks(QueryContext& context) {
QueryData results;
Config::getInstance().packs([&results](Pack& pack) {
Row r;
r["name"] = pack.getName();
r["version"] = pack.getVersion();
r["platform"] = pack.getPlatform();
auto stats = pack.getStats();
r["discovery_cache_hits"] = INTEGER(stats.hits);
r["discovery_executions"] = INTEGER(stats.misses);
results.push_back(r);
});
return results;
}
void genFlag(const std::string& name,
const FlagInfo& flag,
QueryData& results) {
Row r;
r["name"] = name;
r["type"] = flag.type;
r["description"] = flag.description;
r["default_value"] = flag.default_value;
r["value"] = flag.value;
r["shell_only"] = (flag.detail.shell) ? "1" : "0";
results.push_back(r);
}
QueryData genOsqueryFlags(QueryContext& context) {
QueryData results;
auto flags = Flag::flags();
for (const auto& flag : flags) {
if (flag.first.size() > 2) {
// Skip single-character flags.
genFlag(flag.first, flag.second, results);
}
}
return results;
}
QueryData genOsqueryRegistry(QueryContext& context) {
QueryData results;
const auto& registries = RegistryFactory::all();
for (const auto& registry : registries) {
const auto& plugins = registry.second->all();
for (const auto& plugin : plugins) {
Row r;
r["registry"] = registry.first;
r["name"] = plugin.first;
r["owner_uuid"] = "0";
r["internal"] = (registry.second->isInternal(plugin.first)) ? "1" : "0";
r["active"] = "1";
results.push_back(r);
}
for (const auto& route : registry.second->getExternal()) {
Row r;
r["registry"] = registry.first;
r["name"] = route.first;
r["owner_uuid"] = INTEGER(route.second);
r["internal"] = "0";
r["active"] = "1";
results.push_back(r);
}
}
return results;
}
QueryData genOsqueryExtensions(QueryContext& context) {
QueryData results;
ExtensionList extensions;
if (getExtensions(extensions).ok()) {
for (const auto& extenion : extensions) {
Row r;
r["uuid"] = TEXT(extenion.first);
r["name"] = extenion.second.name;
r["version"] = extenion.second.version;
r["sdk_version"] = extenion.second.sdk_version;
r["path"] = getExtensionSocket(extenion.first);
r["type"] = "extension";
results.push_back(r);
}
}
const auto& modules = RegistryFactory::getModules();
for (const auto& module : modules) {
Row r;
r["uuid"] = TEXT(module.first);
r["name"] = module.second.name;
r["version"] = module.second.version;
r["sdk_version"] = module.second.sdk_version;
r["path"] = module.second.path;
r["type"] = "module";
results.push_back(r);
}
return results;
}
QueryData genOsqueryInfo(QueryContext& context) {
QueryData results;
Row r;
r["pid"] = INTEGER(getpid());
r["version"] = kVersion;
std::string hash_string;
auto s = Config::getInstance().getMD5(hash_string);
if (s.ok()) {
r["config_md5"] = TEXT(hash_string);
} else {
r["config_md5"] = "";
VLOG(1) << "Could not retrieve config hash: " << s.toString();
}
r["config_valid"] = Config::getInstance().isValid() ? INTEGER(1) : INTEGER(0);
r["config_path"] = Flag::getValue("config_path");
r["extensions"] =
(pingExtension(FLAGS_extensions_socket).ok()) ? "active" : "inactive";
r["build_platform"] = STR(OSQUERY_BUILD_PLATFORM);
r["build_distro"] = STR(OSQUERY_BUILD_DISTRO);
results.push_back(r);
return results;
}
QueryData genOsquerySchedule(QueryContext& context) {
QueryData results;
Config::getInstance().scheduledQueries(
[&results](const std::string& name, const ScheduledQuery& query) {
Row r;
r["name"] = TEXT(name);
r["query"] = TEXT(query.query);
r["interval"] = INTEGER(query.interval);
// Set default (0) values for each query if it has not yet executed.
r["executions"] = "0";
r["output_size"] = "0";
r["wall_time"] = "0";
r["user_time"] = "0";
r["system_time"] = "0";
r["average_memory"] = "0";
// Report optional performance information.
Config::getInstance().getPerformanceStats(
name,
[&r](const QueryPerformance& perf) {
r["executions"] = BIGINT(perf.executions);
r["output_size"] = BIGINT(perf.output_size);
r["wall_time"] = BIGINT(perf.wall_time);
r["user_time"] = BIGINT(perf.user_time);
r["system_time"] = BIGINT(perf.system_time);
r["average_memory"] = BIGINT(perf.average_memory);
});
results.push_back(r);
});
return results;
}
}
}
|
;********************************************************************************************************
; uC/LIB
; CUSTOM LIBRARY MODULES
;
; (c) Copyright 2004-2011; Micrium, Inc.; Weston, FL
;
; All rights reserved. Protected by international copyright laws.
;
; uC/LIB is provided in source form to registered licensees ONLY. It is
; illegal to distribute this source code to any third party unless you receive
; written permission by an authorized Micrium representative. Knowledge of
; the source code may NOT be used to develop a similar product.
;
; Please help us continue to provide the Embedded community with the finest
; software available. Your honesty is greatly appreciated.
;
; You can contact us at www.micrium.com.
;********************************************************************************************************
;********************************************************************************************************
;
; STANDARD MEMORY OPERATIONS
;
; ARM-Cortex-M4
; IAR Compiler
;
; Filename : lib_mem_a.asm
; Version : V1.37.02.00
; Programmer(s) : JDH
; BAN
;********************************************************************************************************
; Note(s) : (1) NO compiler-supplied standard library functions are used in library or product software.
;
; (a) ALL standard library functions are implemented in the custom library modules :
;
; (1) \<Custom Library Directory>\lib*.*
;
; (2) \<Custom Library Directory>\Ports\<cpu>\<compiler>\lib*_a.*
;
; where
; <Custom Library Directory> directory path for custom library software
; <cpu> directory name for specific processor (CPU)
; <compiler> directory name for specific compiler
;
; (b) Product-specific library functions are implemented in individual products.
;
; (2) Assumes ARM CPU mode configured for Little Endian.
;********************************************************************************************************
;********************************************************************************************************
; PUBLIC FUNCTIONS
;********************************************************************************************************
PUBLIC Mem_Copy
;********************************************************************************************************
; CODE GENERATION DIRECTIVES
;********************************************************************************************************
RSEG CODE:CODE:NOROOT(2)
;$PAGE
;********************************************************************************************************
; Mem_Copy()
;
; Description : Copy data octets from one buffer to another buffer.
;
; Argument(s) : pdest Pointer to destination memory buffer.
;
; psrc Pointer to source memory buffer.
;
; size Number of data buffer octets to copy.
;
; Return(s) : none.
;
; Caller(s) : Application.
;
; Note(s) : (1) Null copies allowed (i.e. 0-octet size).
;
; (2) Memory buffers NOT checked for overlapping.
;
; (3) Modulo arithmetic is used to determine whether a memory buffer starts on a 'CPU_ALIGN'
; address boundary.
;
; (4) ARM Cortex-M3 processors use a subset of the ARM Thumb-2 instruction set which does
; NOT support 16-bit conditional branch instructions but ONLY supports 8-bit conditional
; branch instructions.
;
; Therefore, branches exceeding 8-bit, signed, relative offsets :
;
; (a) CANNOT be implemented with conditional branches; but ...
; (b) MUST be implemented with non-conditional branches.
;********************************************************************************************************
; void Mem_Copy (void *pdest, ; ==> R0
; void *psrc, ; ==> R1
; CPU_SIZE_T size) ; ==> R2
Mem_Copy:
CMP R0, #0
BNE Mem_Copy_1
BX LR ; return if pdest == NULL
Mem_Copy_1:
CMP R1, #0
BNE Mem_Copy_2
BX LR ; return if psrc == NULL
Mem_Copy_2:
CMP R2, #0
BNE Mem_Copy_3
BX LR ; return if size == 0
Mem_Copy_3:
STMFD SP!, {R3-R12} ; save registers on stack
;$PAGE
Chk_Align_32: ; check if both dest & src 32-bit aligned
AND R3, R0, #0x03
AND R4, R1, #0x03
CMP R3, R4
BNE Chk_Align_16 ; not 32-bit aligned, check for 16-bit alignment
RSB R3, R3, #0x04 ; compute 1-2-3 pre-copy bytes (to align to the next 32-bit boundary)
AND R3, R3, #0x03
Pre_Copy_1:
CMP R3, #1 ; copy 1-2-3 bytes (to align to the next 32-bit boundary)
BCC Copy_32_1 ; start real 32-bit copy
CMP R2, #1 ; check if any more data to copy
BCS Pre_Copy_1_Cont
B Mem_Copy_END ; no more data to copy (see Note #4b)
Pre_Copy_1_Cont:
LDRB R4, [R1], #1
STRB R4, [R0], #1
SUB R3, R3, #1
SUB R2, R2, #1
B Pre_Copy_1
Chk_Align_16: ; check if both dest & src 16-bit aligned
AND R3, R0, #0x01
AND R4, R1, #0x01
CMP R3, R4
BEQ Pre_Copy_2
B Copy_08_1 ; not 16-bit aligned, start 8-bit copy (see Note #4b)
Pre_Copy_2:
CMP R3, #1 ; copy 1 byte (to align to the next 16-bit boundary)
BCC Copy_16_1 ; start real 16-bit copy
LDRB R4, [R1], #1
STRB R4, [R0], #1
SUB R3, R3, #1
SUB R2, R2, #1
B Pre_Copy_2
Copy_32_1:
CMP R2, #(04*10*09) ; Copy 9 chunks of 10 32-bit words (360 octets per loop)
BCC Copy_32_2
LDMIA R1!, {R3-R12}
STMIA R0!, {R3-R12}
LDMIA R1!, {R3-R12}
STMIA R0!, {R3-R12}
LDMIA R1!, {R3-R12}
STMIA R0!, {R3-R12}
LDMIA R1!, {R3-R12}
STMIA R0!, {R3-R12}
LDMIA R1!, {R3-R12}
STMIA R0!, {R3-R12}
LDMIA R1!, {R3-R12}
STMIA R0!, {R3-R12}
LDMIA R1!, {R3-R12}
STMIA R0!, {R3-R12}
LDMIA R1!, {R3-R12}
STMIA R0!, {R3-R12}
LDMIA R1!, {R3-R12}
STMIA R0!, {R3-R12}
SUB R2, R2, #(04*10*09)
B Copy_32_1
Copy_32_2:
CMP R2, #(04*10*01) ; Copy chunks of 10 32-bit words (40 octets per loop)
BCC Copy_32_3
LDMIA R1!, {R3-R12}
STMIA R0!, {R3-R12}
SUB R2, R2, #(04*10*01)
B Copy_32_2
Copy_32_3:
CMP R2, #(04*01*01) ; Copy remaining 32-bit words
BCC Copy_16_1
LDR R3, [R1], #4
STR R3, [R0], #4
SUB R2, R2, #(04*01*01)
B Copy_32_3
;$PAGE
Copy_16_1:
CMP R2, #(02*01*16) ; Copy chunks of 16 16-bit words (32 bytes per loop)
BCC Copy_16_2
LDRH R3, [R1], #2
STRH R3, [R0], #2
LDRH R3, [R1], #2
STRH R3, [R0], #2
LDRH R3, [R1], #2
STRH R3, [R0], #2
LDRH R3, [R1], #2
STRH R3, [R0], #2
LDRH R3, [R1], #2
STRH R3, [R0], #2
LDRH R3, [R1], #2
STRH R3, [R0], #2
LDRH R3, [R1], #2
STRH R3, [R0], #2
LDRH R3, [R1], #2
STRH R3, [R0], #2
LDRH R3, [R1], #2
STRH R3, [R0], #2
LDRH R3, [R1], #2
STRH R3, [R0], #2
LDRH R3, [R1], #2
STRH R3, [R0], #2
LDRH R3, [R1], #2
STRH R3, [R0], #2
LDRH R3, [R1], #2
STRH R3, [R0], #2
LDRH R3, [R1], #2
STRH R3, [R0], #2
LDRH R3, [R1], #2
STRH R3, [R0], #2
LDRH R3, [R1], #2
STRH R3, [R0], #2
SUB R2, R2, #(02*01*16)
B Copy_16_1
Copy_16_2:
CMP R2, #(02*01*01) ; Copy remaining 16-bit words
BCC Copy_08_1
LDRH R3, [R1], #2
STRH R3, [R0], #2
SUB R2, R2, #(02*01*01)
B Copy_16_2
;$PAGE
Copy_08_1:
CMP R2, #(01*01*16) ; Copy chunks of 16 8-bit words (16 bytes per loop)
BCC Copy_08_2
LDRB R3, [R1], #1
STRB R3, [R0], #1
LDRB R3, [R1], #1
STRB R3, [R0], #1
LDRB R3, [R1], #1
STRB R3, [R0], #1
LDRB R3, [R1], #1
STRB R3, [R0], #1
LDRB R3, [R1], #1
STRB R3, [R0], #1
LDRB R3, [R1], #1
STRB R3, [R0], #1
LDRB R3, [R1], #1
STRB R3, [R0], #1
LDRB R3, [R1], #1
STRB R3, [R0], #1
LDRB R3, [R1], #1
STRB R3, [R0], #1
LDRB R3, [R1], #1
STRB R3, [R0], #1
LDRB R3, [R1], #1
STRB R3, [R0], #1
LDRB R3, [R1], #1
STRB R3, [R0], #1
LDRB R3, [R1], #1
STRB R3, [R0], #1
LDRB R3, [R1], #1
STRB R3, [R0], #1
LDRB R3, [R1], #1
STRB R3, [R0], #1
LDRB R3, [R1], #1
STRB R3, [R0], #1
SUB R2, R2, #(01*01*16)
B Copy_08_1
Copy_08_2:
CMP R2, #(01*01*01) ; Copy remaining 8-bit words
BCC Mem_Copy_END
LDRB R3, [R1], #1
STRB R3, [R0], #1
SUB R2, R2, #(01*01*01)
B Copy_08_2
Mem_Copy_END:
LDMFD SP!, {R3-R12} ; restore registers from stack
BX LR ; return
END
|
format ELF executable 3
entry start
include 'procs.inc'
segment readable
fizz db 'fizz', 0h
buzz db 'buzz', 0h
segment readable executable
start:
mov esi, 0
mov edx, 0
mov ecx, 0
.nextNumber:
inc ecx
.checkFizz:
mov edx, 0
mov eax, ecx
mov ebx, 3
div ebx
mov edi, edx
cmp edi, 0
jne .checkBuzz
mov eax, fizz
call sprint
.checkBuzz:
mov edx, 0
mov eax, ecx
mov ebx, 5
div ebx
mov esi, edx
cmp esi, 0
jne .printInteger
mov eax, buzz
call sprint
.printInteger:
cmp edi, 0
je .continue
cmp esi, 0
je .continue
mov eax, ecx
call iprint
.continue:
mov eax, 0Ah
push eax
mov eax, esp
call sprint
pop eax
cmp ecx, 100
jb .nextNumber
call quitProgram
|
// Copyright (C) 2015 SRG Technology, LLC
//
// 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 "anyrpc/api.h"
#include "anyrpc/logger.h"
#include "anyrpc/error.h"
#include "anyrpc/value.h"
#include "anyrpc/method.h"
namespace anyrpc
{
void ListMethod::Execute(Value& params, Value& result)
{
if (manager_)
manager_->ListMethods(params, result);
}
////////////////////////////////////////////////////////////////////////////////
void HelpMethod::Execute(Value& params, Value& result)
{
if (manager_)
manager_->FindHelpMethod(params, result);
}
////////////////////////////////////////////////////////////////////////////////
MethodManager::MethodManager()
{
methods_[LIST_METHODS] = new ListMethod(this,LIST_METHODS,LIST_METHODS_HELP);
methods_[METHOD_HELP] = new HelpMethod(this,METHOD_HELP,METHOD_HELP_HELP);
}
MethodManager::~MethodManager()
{
MethodMap::iterator it = methods_.begin();
for (MethodMap::iterator it = methods_.begin(); it != methods_.end(); it++)
{
if (it->second->DeleteOnRemove())
delete it->second; // free the method pointer data
}
methods_.clear();
}
void MethodManager::AddFunction(Function* function, std::string const& name, std::string const& help)
{
std::lock_guard<std::mutex> lock(mutex_);
MethodMap::const_iterator it = methods_.find(name);
if (it == methods_.end())
{
// not found so add new method
methods_[name] = new MethodFunction(function,name,help);
}
else
{
// function already defined, throw exception
// the user can catch and ignore the exception if this behavior is desired
anyrpc_throw(AnyRpcErrorFunctionRedefine, "Attempt to redefine function name: " + name);
}
}
void MethodManager::AddMethod(Method* method)
{
std::lock_guard<std::mutex> lock(mutex_);
MethodMap::const_iterator it = methods_.find(method->Name());
if (it == methods_.end())
{
// not found so add new method
methods_[method->Name()] = method;
}
else
{
std::string nameStr = method->Name();
// method already defined, clean up then throw exception
// the user can catch and ignore the exception if this behavior is desired
if (method->DeleteOnRemove())
delete method;
anyrpc_throw(AnyRpcErrorMethodRedefine, "Attempt to redefine method name: " + nameStr);
}
}
bool MethodManager::RemoveMethod(std::string const& name, bool WaitForDelayedRemove /* = false */)
{
std::unique_lock<std::mutex> lock(mutex_);
MethodMap::const_iterator it = methods_.find(name);
if (it == methods_.end())
return false; // no such method exists
Method *method = it->second;
if (method->ActiveThreads() > 0)
{
method->SetDelayedRemove();
if (WaitForDelayedRemove)
{
// wait for method "name" being actually deleted
while (methods_.find(name) != methods_.end())
condVarDelayedRemove_.wait(lock);
}
}
else
{
if (method->DeleteOnRemove())
delete method; // free the method pointer data
methods_.erase(it);
}
return true;
}
bool MethodManager::ExecuteMethod(std::string const& name, Value& params, Value& result)
{
std::unique_lock<std::mutex> lock(mutex_);
MethodMap::const_iterator it = methods_.find(name);
if ((it == methods_.end()) || it->second->DelayedRemove())
return false;
// Add this thread to the list of users for this method
Method *method = it->second;
method->AddThread();
lock.unlock();
try
{
it->second->Execute(params, result);
}
catch (...)
{
ExecuteMethod_FollowUpOperations(method);
throw; // rethrow exception
}
ExecuteMethod_FollowUpOperations(method);
return true;
}
void MethodManager::ExecuteMethod_FollowUpOperations(Method *method)
{
std::lock_guard<std::mutex> lock(mutex_);
// Finish with this thread using this method
method->RemoveThread();
// Check if we should remove the method - must have no active threads
if (method->DelayedRemove() && (method->ActiveThreads() == 0))
{
// Find the method again in case other changes to the list have occurred
MethodMap::const_iterator it = methods_.find(method->Name());
if (it == methods_.end())
anyrpc_throw(AnyRpcErrorInternalError, "Method not found for delayed remove: " + method->Name());
if (method->DeleteOnRemove())
delete method; // free the method pointer data
methods_.erase(it);
condVarDelayedRemove_.notify_all(); // notify waiting calls of remove method (if any)
}
}
void MethodManager::ListMethods(Value& params, Value& result)
{
int i=0;
result.SetArray();
std::lock_guard<std::mutex> lock(mutex_);
result.SetSize(methods_.size());
for (MethodMap::const_iterator it = methods_.begin(); it != methods_.end(); ++it)
result[i++] = it->first;
}
void MethodManager::FindHelpMethod(Value& params, Value& result)
{
if (!params.IsArray() || (params.Size() != 1) || !params[0].IsString())
anyrpc_throw(AnyRpcErrorInvalidParams, "Invalid parameters");
std::lock_guard<std::mutex> lock(mutex_);
MethodMap::const_iterator it = methods_.find(params[0].GetString());
if (it == methods_.end())
anyrpc_throw(AnyRpcErrorMethodNotFound, "Unknown method name: " + std::string(params[0].GetString()));
result = it->second->Help();
}
}
|
; Copyright 2015-2020 Matt "MateoConLechuga" Waltz
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are met:
;
; 1. Redistributions of source code must retain the above copyright notice,
; this list of conditions and the following disclaimer.
;
; 2. Redistributions in binary form must reproduce the above copyright notice,
; this list of conditions and the following disclaimer in the documentation
; and/or other materials provided with the distribution.
;
; 3. Neither the name of the copyright holder nor the names of its contributors
; may be used to endorse or promote products derived from this software
; without specific prior written permission.
;
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
; POSSIBILITY OF SUCH DAMAGE.
; main cesium process routines
main_cesium:
call port_setup
or a,a
jq z,.okay
.invalid_os:
call ti.ClrScrn
jp ti.HomeUp
ld hl,str_invalid_os
call ti.PutS
call ti.GetKey
call ti.ClrScrn
jp ti.HomeUp
.okay:
call lcd_init
call main_init
main_settings:
call settings_load
main_find:
call find_files
main_start:
call gui_main
call util_setup_apd
main_loop:
call util_get_key
cp a,ti.skClear
jp z,.check_exit
cp a,ti.skMode
jp z,settings_show
cp a,ti.skUp
jp z,main_move_up_return
cp a,ti.skDown
jp z,main_move_down_return
;cp a,ti.skPrgm
;jp z,fat_file_transfer_from_device
cp a,ti.sk2nd
jp z,execute_item
cp a,ti.skEnter
jp z,execute_item_alternate
cp a,ti.skGraph
jp z,feature_item_rename
cp a,ti.skYequ
jp z,feature_item_new
cp a,ti.skAlpha
jp z,feature_item_attributes
cp a,ti.skZoom
jp z,feature_item_edit
cp a,ti.skDel
jp z,feature_item_delete
sub a,ti.skAdd
jp c,main_loop
cp a,ti.skMath - ti.skAdd + 1
jp nc,main_loop
call search_alpha_item
jp z,main_loop
jp main_start
.check_exit:
ld a,(current_screen)
cp a,screen_usb
jp z,usb_detach
jp exit_full
main_move_up_return:
ld hl,main_start
push hl
main_move_up:
ld hl,(current_selection_absolute)
compare_hl_zero
ret z ; check if we are at the top
dec hl
ld (current_selection_absolute),hl
ld a,(current_selection)
or a,a
jr nz,.dont_scroll
ld hl,(scroll_amount)
dec hl
ld (scroll_amount),hl
ret
.dont_scroll:
dec a
ld (current_selection),a
ret
main_move_down_return:
ld hl,main_start
push hl
main_move_down:
ld hl,(current_selection_absolute)
ld de,(number_of_items)
dec de
compare_hl_de
ret z
inc hl
ld (current_selection_absolute),hl
ld a,(current_selection)
cp a,9 ; limit items per screen
jr nz,dont_scroll
ld hl,(scroll_amount)
inc hl
ld (scroll_amount),hl
ret
dont_scroll:
inc a
ld (current_selection),a
ret
main_init:
call ti.ClrGetKeyHook ; clear key hooks
ld a,screen_programs
ld (current_screen),a ; start on the programs screen
ld hl,util_get_battery
push hl ; return here
ld a,(return_info) ; let's check if returned from execution
cp a,return_goto
ret nz
ld hl,ti.basic_prog
ld a,(hl) ; check if correct program
cp a,ti.ProtProgObj
ret z
pop bc ; pop return location
inc hl
call util_get_archived_name
call ti.Mov9ToOP1
call ti.ChkFindSym
jp nc,edit_basic_program_goto
jp util_get_battery
|
; A267866: Triangle read by rows giving successive states of cellular automaton generated by "Rule 231" initiated with a single ON (black) cell.
; 1,1,1,0,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,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,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,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,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,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,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
sub $0,3
lpb $0,1
add $2,2
sub $0,$2
sub $0,3
lpe
lpb $0,1
div $0,5
mov $1,1
lpe
|
;########################################################################
;
; Copyright 2019-2020 0x8BitDev ( MIT license )
;
;########################################################################
;
; Sprite related functions
;
.define SPR_BUFF_X_CHR_OFFSET $c080
.define SPR_BUFF_SIZE $ff
; *** push a sprite to the characters "pool" ***
; IN: HL - data addr
; B - data size
; DE - X/Y
spr_push:
exx
ld hl, SPR_BUFF ; Y data addr
ld de, SPR_BUFF_X_CHR_OFFSET ; X, CHR_ind offset
ld bc, SPR_NUM_ATTRS
ld a, (bc)
exx
cp 64
ret z ; buffer overflows!
_push_sprite_loop:
ld a, (hl) ; A - Y
add a, e
; save a / Y
exx
ld (hl), a
inc hl
exx
inc hl
ld a, (hl) ; A - X
add a, d
; save a / X
exx
ld (de), a
inc de
exx
inc hl
ld a, (hl) ; A - CHR index
; save a / CHR_ind
exx
ld (de), a
inc de
ld a, (bc)
inc a
ld (bc), a
exx
inc hl
cp 64
jr z, _exit
dec b
dec b
djnz _push_sprite_loop
_exit:
exx
ld a, $d0 ; the end!
ld (hl), a
exx
ret
; *** characters "pool" initialization ***
spr_buff_init:
ld hl, SPR_BUFF
ld a, $d0 ; the end!
ld (hl), a
ld hl, SPR_NUM_ATTRS
xor a
ld (hl), a
ret |
; A109106: a(n) = (1/sqrt(5))*((sqrt(5) + 1)*((15 + 5*sqrt(5))/2)^(n-1) + (sqrt(5) - 1)*((15 - 5*sqrt(5))/2)^(n-1)).
; Submitted by Jon Maiga
; 2,20,250,3250,42500,556250,7281250,95312500,1247656250,16332031250,213789062500,2798535156250,36633300781250,479536132812500,6277209472656250,82169738769531250,1075615844726562500
mov $2,5
pow $2,$0
lpb $0
sub $0,1
add $1,$2
add $2,$1
lpe
mov $0,$2
mul $0,2
|
; int ba_priority_queue_pop(ba_priority_queue_t *q)
SECTION code_adt_ba_priority_queue
PUBLIC _ba_priority_queue_pop
EXTERN _ba_priority_queue_pop_fastcall
_ba_priority_queue_pop:
pop af
pop hl
push hl
push af
jp _ba_priority_queue_pop_fastcall
|
;
; MIT License
;
; Copyright (c) 2020 Alexander Brandt
;
; 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.
; [io.asm]
; - Alexander Brandt 2020
include "macros.asm"
;==============================
PrintLogString:
; ds:dx - String to print
push ax
push bx
push cx
push dx
push ds
mov ax, seg_data ; Log filename lives here
mov ds, ax
; Open existing file (Int 21/AH=3Dh)
; http://www.ctyme.com/intr/rb-2779.htm
mov ah, 0x3D
mov al, 0x01 ; Write mode
mov dx, str_log_filename
int 0x21
jnc near PrintLogString_file_exists
; Create file (Int 21/AH=3Ch)
; http://www.ctyme.com/intr/rb-2778.htm
mov ah, 0x3C
mov cx, 0x0000 ; Attributes, all bits to zero
mov dx, str_log_filename
int 0x21
jc near PrintLogString_failure
PrintLogString_file_exists:
; Seek (Int 21/AH=42h)
; http://www.ctyme.com/intr/rb-2799.htm
mov bx, ax ; File handle, both Open() and Create() returns it on AX
mov ah, 0x42
mov al, 0x02 ; From EOF
mov cx, 0x0000 ; Origin (signed) HI
mov dx, 0x0000 ; Origin (signed) LO
int 0x21
jc near PrintLogString_failure
; Calculate length in CX
pop ds
pop dx
push bx ; File handler is here and we need the register
mov cx, 0
mov bx, dx
mov al, [bx]
cmp al, 0x00
jz near PrintLogString_write
PrintLog_len:
inc cx
inc bx
mov al, [bx]
cmp al, 0x00
jnz near PrintLog_len
; Write to file (Int 21/AH=40h)
; http://www.ctyme.com/intr/rb-2791.htm
PrintLogString_write:
mov ah, 0x40
pop bx
int 0x21
jc near PrintLogString_failure
; Close file (Int 21/AH=3Eh)
; http://www.ctyme.com/intr/rb-2782.htm
mov ah, 0x3E
int 0x21 ; File handle still on BX
; Bye!
pop cx
pop bx
pop ax
ret
PrintLogString_failure:
mov al, EXIT_FAILURE
call near Exit ; (al)
;==============================
PrintLogNumber:
; ax - Number to print
push bx
push cx
push dx
push ds
mov bx, seg_data ; HEX table
mov ds, bx
; Create the string termination
mov cx, 0x000A ; Unix NL + NULL
push cx ; Push Alpha
; Create the number string
mov bh, 0x00
mov bl, al ; Bits 0-3
and bl, 00001111b
mov ch, [hex_table + bx]
mov bl, al ; Bits 4-7
shr bl, 4
mov cl, [hex_table + bx]
push cx ; Push Beta
mov bl, ah ; Bits 8-11
and bl, 00001111b
mov ch, [hex_table + bx]
mov bl, ah ; Bits 12-15
shr bl, 4
mov cl, [hex_table + bx]
push cx ; Push Gamma
; Point DS to SS, and DX to SP
SetDsDx ss, sp
; Print it
call near PrintLogString
pop cx ; Pushes' Alpha, Beta and Gamma
pop cx
pop cx
; Bye!
pop ds
pop dx
pop cx
pop bx
ret
;==============================
PrintOut:
; ds:dx - Text to print ('$' terminated)
push ax
; Print an error message to stdout (Int 21/AH=09h)
; http://www.ctyme.com/intr/rb-2562.htm
mov ah, 0x09
int 0x21
; Bye!
pop ax
ret
;==============================
FileOpen:
; ds:dx - Filename
push cx ; Following interrupt uses it
; Open existing file (Int 21/AH=3Dh)
; http://www.ctyme.com/intr/rb-2779.htm
mov ah, 0x3D
mov al, 0x00 ; Read mode
int 0x21
jc near FileOpen_failure
; Bye!
pop cx
ret
FileOpen_failure:
; Print error in the log
push ds
push dx
push bx
mov bx, ax ; Open() error code
SetDsDx seg_data, str_file_open_error
call near PrintLogString ; (ds:dx)
mov ax, bx
call near PrintLogNumber ; (ax)
pop bx
pop dx
pop ds
pop cx
mov ax, 0x0000
ret
;==============================
FileClose:
; ax - File handler
cmp ax, 0x0000
jz near FileClose_invalid
push bx
mov bx, ax
; Close file (Int 21/AH=3Eh)
; http://www.ctyme.com/intr/rb-2782.htm
mov ah, 0x3E
int 0x21
; Bye!
pop bx
ret
FileClose_invalid:
ret
;==============================
FileRead:
; ax - File handler
; ds:dx - Destination
; cx - Size
cmp ax, 0x0000
jz near FileRead_invalid
push bx
push ax
mov bx, ax
; Read From File or Device (Int 21/AH=3Fh)
; http://www.ctyme.com/intr/rb-2783.htm
mov ah, 0x3F
int 0x21
; Bye!
pop ax
pop bx
ret
FileRead_invalid:
ret
;==============================
Exit:
; al - Exit status
; Terminate program (Int 21/AH=4Ch)
; http://www.ctyme.com/intr/rb-2974.htm
mov ah, 0x4C
int 0x21
|
; A199689: 8*10^n+1
; 9,81,801,8001,80001,800001,8000001,80000001,800000001,8000000001,80000000001,800000000001,8000000000001,80000000000001,800000000000001,8000000000000001,80000000000000001,800000000000000001,8000000000000000001,80000000000000000001,800000000000000000001,8000000000000000000001,80000000000000000000001,800000000000000000000001,8000000000000000000000001,80000000000000000000000001,800000000000000000000000001,8000000000000000000000000001,80000000000000000000000000001,800000000000000000000000000001,8000000000000000000000000000001,80000000000000000000000000000001,800000000000000000000000000000001,8000000000000000000000000000000001,80000000000000000000000000000000001,800000000000000000000000000000000001
mov $1,10
pow $1,$0
mul $1,8
add $1,1
mov $0,$1
|
POWERON_DELAY EQU 40 ; *20ms, for ps/2 keyboard initialization
MENU_ENTER_DELAY EQU 40 ; 400ms
MENU_LEAVE_DELAY EQU 2 ; 20ms
INPUT_REPEAT EQU 2
INPUT_REPEAT_FIRST EQU 11
INPUT_BEEP_DELAY EQU 255
MENU_HEADER_ATTR EQU #47
MENU_BODY_ATTR EQU #78
MENU_SELECT_ATTR EQU #68
PAUSE_WIDTH EQU 7
PAUSE_HEIGHT EQU 3 ; see pause.asm to really change
PAUSE_X EQU (32-PAUSE_WIDTH)/2
PAUSE_Y EQU (24-PAUSE_HEIGHT)/2
PAUSE_BODY_ATTR EQU #00
PAUSE_TEXT_ATTR EQU #C7
STRUCT CFG_T
_reserv0 DB 0
_reserv1 DB 0
machine DB 3
clock DB 0
panning DB 1
_reserv2 DB 0
_reserv3 DB 0
joystick DB 0
ay DB 1
sd DB 2
ulaplus DB 1
dac DB 3
ENDS
CFG_DEFAULT CFG_T
|
/**
* Copyright (c) 2016-2017 Netflix, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <crypto/Key.h>
#include <crypto/RsaCryptoContext.h>
#include <crypto/SymmetricCryptoContext.h>
#include <entityauth/RsaAuthenticationData.h>
#include <entityauth/RsaAuthenticationFactory.h>
#include <entityauth/RsaStore.h>
#include <Macros.h>
#include <MslEntityAuthException.h>
#include <MslError.h>
#include <MslInternalException.h>
#include <io/MslEncoderFormat.h>
#include <util/AuthenticationUtils.h>
#include <sstream>
#include <typeinfo>
using namespace std;
using namespace netflix::msl;
using namespace netflix::msl::crypto;
using namespace netflix::msl::io;
using namespace netflix::msl::util;
namespace netflix {
namespace msl {
namespace entityauth {
RsaAuthenticationFactory::RsaAuthenticationFactory(shared_ptr<RsaStore> store,
shared_ptr<AuthenticationUtils> authutils)
: EntityAuthenticationFactory(EntityAuthenticationScheme::RSA)
, store_(store)
, authutils_(authutils)
{}
/**
* <p>Construct a new RSA asymmetric keys authentication factory
* instance.</p>
*
* @param store RSA key store.
* @param authutils authentication utilities.
*/
RsaAuthenticationFactory::RsaAuthenticationFactory(const string keyPairId,
shared_ptr<RsaStore> store,
shared_ptr<AuthenticationUtils> authutils)
: EntityAuthenticationFactory(EntityAuthenticationScheme::RSA)
, keyPairId_(keyPairId)
, store_(store)
, authutils_(authutils)
{}
shared_ptr<EntityAuthenticationData> RsaAuthenticationFactory::createData(
shared_ptr<MslContext>, shared_ptr<MslObject> entityAuthMo)
{
return make_shared<RsaAuthenticationData>(entityAuthMo);
}
/* (non-Javadoc)
* @see com.netflix.msl.entityauth.EntityAuthenticationFactory#getCryptoContext(com.netflix.msl.util.MslContext, com.netflix.msl.entityauth.EntityAuthenticationData)
*/
shared_ptr<ICryptoContext> RsaAuthenticationFactory::getCryptoContext(
shared_ptr<MslContext> ctx, shared_ptr<EntityAuthenticationData> authdata)
{
// Make sure we have the right kind of entity authentication data.
if (!instanceof<RsaAuthenticationData>(authdata.get())) {
stringstream ss;
ss << "Incorrect authentication data type " << typeid(authdata).name() << ".";
throw MslInternalException(ss.str());
}
shared_ptr<RsaAuthenticationData> rad = dynamic_pointer_cast<RsaAuthenticationData>(authdata);
// Check for revocation.
const string identity = rad->getIdentity();
if (authutils_->isEntityRevoked(identity))
throw MslEntityAuthException(MslError::ENTITY_REVOKED, "rsa " + identity).setEntityAuthenticationData(rad);
// Verify the scheme is permitted.
if (!authutils_->isSchemePermitted(identity, getScheme()))
throw MslEntityAuthException(MslError::INCORRECT_ENTITYAUTH_DATA, "Authentication Scheme for Device Type Not Supported " +
identity + ":" + getScheme().name()).setEntityAuthenticationData(rad);
// Extract RSA authentication data.
const string pubkeyid = rad->getPublicKeyId();
const PublicKey publicKey = store_->getPublicKey(pubkeyid);
const PrivateKey privateKey = store_->getPrivateKey(pubkeyid);
// The local entity must have a private key.
if (pubkeyid == keyPairId_ && privateKey.isNull())
throw MslEntityAuthException(MslError::RSA_PRIVATEKEY_NOT_FOUND, pubkeyid).setEntityAuthenticationData(rad);
// Remote entities must have a public key.
else if (pubkeyid != keyPairId_ && publicKey.isNull())
throw MslEntityAuthException(MslError::RSA_PUBLICKEY_NOT_FOUND, pubkeyid).setEntityAuthenticationData(rad);
// Return the crypto context.
return make_shared<RsaCryptoContext>(ctx, identity, privateKey, publicKey, RsaCryptoContext::Mode::SIGN_VERIFY);
}
}}} // namespace netflix::msl::entityauth
|
###############################################################################
# Copyright 2019 Intel Corporation
# All Rights Reserved.
#
# If this software was obtained under the Intel Simplified Software License,
# the following terms apply:
#
# The source code, information and material ("Material") contained herein is
# owned by Intel Corporation or its suppliers or licensors, and title to such
# Material remains with Intel Corporation or its suppliers or licensors. The
# Material contains proprietary information of Intel or its suppliers and
# licensors. The Material is protected by worldwide copyright laws and treaty
# provisions. No part of the Material may be used, copied, reproduced,
# modified, published, uploaded, posted, transmitted, distributed or disclosed
# in any way without Intel's prior express written permission. No license under
# any patent, copyright or other intellectual property rights in the Material
# is granted to or conferred upon you, either expressly, by implication,
# inducement, estoppel or otherwise. Any license under such intellectual
# property rights must be express and approved by Intel in writing.
#
# Unless otherwise agreed by Intel in writing, you may not remove or alter this
# notice or any other notice embedded in Materials by Intel or Intel's
# suppliers or licensors in any way.
#
#
# If this software was obtained under the Apache License, Version 2.0 (the
# "License"), the following terms apply:
#
# You may not use this file except in compliance with the License. You may
# obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
# See the License for the specific language governing permissions and
# limitations under the License.
###############################################################################
.section .note.GNU-stack,"",%progbits
.text
.p2align 4, 0x90
.globl w7_Touch_SubsDword_8uT
.type w7_Touch_SubsDword_8uT, @function
w7_Touch_SubsDword_8uT:
push %ebp
mov %esp, %ebp
push %ebx
push %esi
push %edi
movl (12)(%ebp), %esi
movl (16)(%ebp), %edx
xor %ecx, %ecx
.Ltouch_tblgas_1:
mov (%esi,%ecx), %eax
add $(64), %ecx
cmp %edx, %ecx
jl .Ltouch_tblgas_1
movl (8)(%ebp), %edx
mov %edx, %eax
and $(255), %eax
movzbl (%esi,%eax), %eax
shr $(8), %edx
mov %edx, %ebx
and $(255), %ebx
movzbl (%esi,%ebx), %ebx
shl $(8), %ebx
shr $(8), %edx
mov %edx, %ecx
and $(255), %ecx
movzbl (%esi,%ecx), %ecx
shl $(16), %ecx
shr $(8), %edx
movzbl (%esi,%edx), %edx
shl $(24), %edx
or %ebx, %eax
or %ecx, %eax
or %edx, %eax
pop %edi
pop %esi
pop %ebx
pop %ebp
ret
.Lfe1:
.size w7_Touch_SubsDword_8uT, .Lfe1-(w7_Touch_SubsDword_8uT)
|
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#ifndef SHARE_VM_RUNTIME_STUBROUTINES_HPP
#define SHARE_VM_RUNTIME_STUBROUTINES_HPP
#include "code/codeBlob.hpp"
#include "memory/allocation.hpp"
#include "runtime/frame.hpp"
#include "runtime/mutexLocker.hpp"
#include "runtime/stubCodeGenerator.hpp"
#include "utilities/top.hpp"
#ifdef TARGET_ARCH_x86
# include "nativeInst_x86.hpp"
#endif
#ifdef TARGET_ARCH_sparc
# include "nativeInst_sparc.hpp"
#endif
#ifdef TARGET_ARCH_zero
# include "nativeInst_zero.hpp"
#endif
#ifdef TARGET_ARCH_arm
# include "nativeInst_arm.hpp"
#endif
#ifdef TARGET_ARCH_ppc
# include "nativeInst_ppc.hpp"
#endif
// StubRoutines provides entry points to assembly routines used by
// compiled code and the run-time system. Platform-specific entry
// points are defined in the platform-specific inner class.
//
// Class scheme:
//
// platform-independent platform-dependent
//
// stubRoutines.hpp <-- included -- stubRoutines_<arch>.hpp
// ^ ^
// | |
// implements implements
// | |
// | |
// stubRoutines.cpp stubRoutines_<arch>.cpp
// stubRoutines_<os_family>.cpp stubGenerator_<arch>.cpp
// stubRoutines_<os_arch>.cpp
//
// Note 1: The important thing is a clean decoupling between stub
// entry points (interfacing to the whole vm; i.e., 1-to-n
// relationship) and stub generators (interfacing only to
// the entry points implementation; i.e., 1-to-1 relationship).
// This significantly simplifies changes in the generator
// structure since the rest of the vm is not affected.
//
// Note 2: stubGenerator_<arch>.cpp contains a minimal portion of
// machine-independent code; namely the generator calls of
// the generator functions that are used platform-independently.
// However, it comes with the advantage of having a 1-file
// implementation of the generator. It should be fairly easy
// to change, should it become a problem later.
//
// Scheme for adding a new entry point:
//
// 1. determine if it's a platform-dependent or independent entry point
// a) if platform independent: make subsequent changes in the independent files
// b) if platform dependent: make subsequent changes in the dependent files
// 2. add a private instance variable holding the entry point address
// 3. add a public accessor function to the instance variable
// 4. implement the corresponding generator function in the platform-dependent
// stubGenerator_<arch>.cpp file and call the function in generate_all() of that file
class StubRoutines: AllStatic {
public:
enum platform_independent_constants {
max_size_of_parameters = 256 // max. parameter size supported by megamorphic lookups
};
// Dependencies
friend class StubGenerator;
#ifdef TARGET_ARCH_MODEL_x86_32
# include "stubRoutines_x86_32.hpp"
#endif
#ifdef TARGET_ARCH_MODEL_x86_64
# include "stubRoutines_x86_64.hpp"
#endif
#ifdef TARGET_ARCH_MODEL_sparc
# include "stubRoutines_sparc.hpp"
#endif
#ifdef TARGET_ARCH_MODEL_zero
# include "stubRoutines_zero.hpp"
#endif
#ifdef TARGET_ARCH_MODEL_arm
# include "stubRoutines_arm.hpp"
#endif
#ifdef TARGET_ARCH_MODEL_ppc
# include "stubRoutines_ppc.hpp"
#endif
static jint _verify_oop_count;
static address _verify_oop_subroutine_entry;
static address _call_stub_return_address; // the return PC, when returning to a call stub
static address _call_stub_entry;
static address _forward_exception_entry;
static address _catch_exception_entry;
static address _throw_AbstractMethodError_entry;
static address _throw_IncompatibleClassChangeError_entry;
static address _throw_ArithmeticException_entry;
static address _throw_NullPointerException_entry;
static address _throw_NullPointerException_at_call_entry;
static address _throw_StackOverflowError_entry;
static address _throw_WrongMethodTypeException_entry;
static address _handler_for_unsafe_access_entry;
static address _atomic_xchg_entry;
static address _atomic_xchg_ptr_entry;
static address _atomic_store_entry;
static address _atomic_store_ptr_entry;
static address _atomic_cmpxchg_entry;
static address _atomic_cmpxchg_ptr_entry;
static address _atomic_cmpxchg_long_entry;
static address _atomic_add_entry;
static address _atomic_add_ptr_entry;
static address _fence_entry;
static address _d2i_wrapper;
static address _d2l_wrapper;
static jint _fpu_cntrl_wrd_std;
static jint _fpu_cntrl_wrd_24;
static jint _fpu_cntrl_wrd_64;
static jint _fpu_cntrl_wrd_trunc;
static jint _mxcsr_std;
static jint _fpu_subnormal_bias1[3];
static jint _fpu_subnormal_bias2[3];
static BufferBlob* _code1; // code buffer for initial routines
static BufferBlob* _code2; // code buffer for all other routines
// Leaf routines which implement arraycopy and their addresses
// arraycopy operands aligned on element type boundary
static address _jbyte_arraycopy;
static address _jshort_arraycopy;
static address _jint_arraycopy;
static address _jlong_arraycopy;
static address _oop_arraycopy, _oop_arraycopy_uninit;
static address _jbyte_disjoint_arraycopy;
static address _jshort_disjoint_arraycopy;
static address _jint_disjoint_arraycopy;
static address _jlong_disjoint_arraycopy;
static address _oop_disjoint_arraycopy, _oop_disjoint_arraycopy_uninit;
// arraycopy operands aligned on zero'th element boundary
// These are identical to the ones aligned aligned on an
// element type boundary, except that they assume that both
// source and destination are HeapWord aligned.
static address _arrayof_jbyte_arraycopy;
static address _arrayof_jshort_arraycopy;
static address _arrayof_jint_arraycopy;
static address _arrayof_jlong_arraycopy;
static address _arrayof_oop_arraycopy, _arrayof_oop_arraycopy_uninit;
static address _arrayof_jbyte_disjoint_arraycopy;
static address _arrayof_jshort_disjoint_arraycopy;
static address _arrayof_jint_disjoint_arraycopy;
static address _arrayof_jlong_disjoint_arraycopy;
static address _arrayof_oop_disjoint_arraycopy, _arrayof_oop_disjoint_arraycopy_uninit;
// these are recommended but optional:
static address _checkcast_arraycopy, _checkcast_arraycopy_uninit;
static address _unsafe_arraycopy;
static address _generic_arraycopy;
static address _jbyte_fill;
static address _jshort_fill;
static address _jint_fill;
static address _arrayof_jbyte_fill;
static address _arrayof_jshort_fill;
static address _arrayof_jint_fill;
// These are versions of the java.lang.Math methods which perform
// the same operations as the intrinsic version. They are used for
// constant folding in the compiler to ensure equivalence. If the
// intrinsic version returns the same result as the strict version
// then they can be set to the appropriate function from
// SharedRuntime.
static double (*_intrinsic_log)(double);
static double (*_intrinsic_log10)(double);
static double (*_intrinsic_exp)(double);
static double (*_intrinsic_pow)(double, double);
static double (*_intrinsic_sin)(double);
static double (*_intrinsic_cos)(double);
static double (*_intrinsic_tan)(double);
public:
// Initialization/Testing
static void initialize1(); // must happen before universe::genesis
static void initialize2(); // must happen after universe::genesis
static bool contains(address addr) {
return
(_code1 != NULL && _code1->blob_contains(addr)) ||
(_code2 != NULL && _code2->blob_contains(addr)) ;
}
// Debugging
static jint verify_oop_count() { return _verify_oop_count; }
static jint* verify_oop_count_addr() { return &_verify_oop_count; }
// a subroutine for debugging the GC
static address verify_oop_subroutine_entry_address() { return (address)&_verify_oop_subroutine_entry; }
static address catch_exception_entry() { return _catch_exception_entry; }
// Calls to Java
typedef void (*CallStub)(
address link,
intptr_t* result,
BasicType result_type,
methodOopDesc* method,
address entry_point,
intptr_t* parameters,
int size_of_parameters,
TRAPS
);
static CallStub call_stub() { return CAST_TO_FN_PTR(CallStub, _call_stub_entry); }
// Exceptions
static address forward_exception_entry() { return _forward_exception_entry; }
// Implicit exceptions
static address throw_AbstractMethodError_entry() { return _throw_AbstractMethodError_entry; }
static address throw_IncompatibleClassChangeError_entry(){ return _throw_IncompatibleClassChangeError_entry; }
static address throw_ArithmeticException_entry() { return _throw_ArithmeticException_entry; }
static address throw_NullPointerException_entry() { return _throw_NullPointerException_entry; }
static address throw_NullPointerException_at_call_entry(){ return _throw_NullPointerException_at_call_entry; }
static address throw_StackOverflowError_entry() { return _throw_StackOverflowError_entry; }
static address throw_WrongMethodTypeException_entry() { return _throw_WrongMethodTypeException_entry; }
// Exceptions during unsafe access - should throw Java exception rather
// than crash.
static address handler_for_unsafe_access() { return _handler_for_unsafe_access_entry; }
static address atomic_xchg_entry() { return _atomic_xchg_entry; }
static address atomic_xchg_ptr_entry() { return _atomic_xchg_ptr_entry; }
static address atomic_store_entry() { return _atomic_store_entry; }
static address atomic_store_ptr_entry() { return _atomic_store_ptr_entry; }
static address atomic_cmpxchg_entry() { return _atomic_cmpxchg_entry; }
static address atomic_cmpxchg_ptr_entry() { return _atomic_cmpxchg_ptr_entry; }
static address atomic_cmpxchg_long_entry() { return _atomic_cmpxchg_long_entry; }
static address atomic_add_entry() { return _atomic_add_entry; }
static address atomic_add_ptr_entry() { return _atomic_add_ptr_entry; }
static address fence_entry() { return _fence_entry; }
static address d2i_wrapper() { return _d2i_wrapper; }
static address d2l_wrapper() { return _d2l_wrapper; }
static jint fpu_cntrl_wrd_std() { return _fpu_cntrl_wrd_std; }
static address addr_fpu_cntrl_wrd_std() { return (address)&_fpu_cntrl_wrd_std; }
static address addr_fpu_cntrl_wrd_24() { return (address)&_fpu_cntrl_wrd_24; }
static address addr_fpu_cntrl_wrd_64() { return (address)&_fpu_cntrl_wrd_64; }
static address addr_fpu_cntrl_wrd_trunc() { return (address)&_fpu_cntrl_wrd_trunc; }
static address addr_mxcsr_std() { return (address)&_mxcsr_std; }
static address addr_fpu_subnormal_bias1() { return (address)&_fpu_subnormal_bias1; }
static address addr_fpu_subnormal_bias2() { return (address)&_fpu_subnormal_bias2; }
static address select_arraycopy_function(BasicType t, bool aligned, bool disjoint, const char* &name, bool dest_uninitialized);
static address jbyte_arraycopy() { return _jbyte_arraycopy; }
static address jshort_arraycopy() { return _jshort_arraycopy; }
static address jint_arraycopy() { return _jint_arraycopy; }
static address jlong_arraycopy() { return _jlong_arraycopy; }
static address oop_arraycopy(bool dest_uninitialized = false) {
return dest_uninitialized ? _oop_arraycopy_uninit : _oop_arraycopy;
}
static address jbyte_disjoint_arraycopy() { return _jbyte_disjoint_arraycopy; }
static address jshort_disjoint_arraycopy() { return _jshort_disjoint_arraycopy; }
static address jint_disjoint_arraycopy() { return _jint_disjoint_arraycopy; }
static address jlong_disjoint_arraycopy() { return _jlong_disjoint_arraycopy; }
static address oop_disjoint_arraycopy(bool dest_uninitialized = false) {
return dest_uninitialized ? _oop_disjoint_arraycopy_uninit : _oop_disjoint_arraycopy;
}
static address arrayof_jbyte_arraycopy() { return _arrayof_jbyte_arraycopy; }
static address arrayof_jshort_arraycopy() { return _arrayof_jshort_arraycopy; }
static address arrayof_jint_arraycopy() { return _arrayof_jint_arraycopy; }
static address arrayof_jlong_arraycopy() { return _arrayof_jlong_arraycopy; }
static address arrayof_oop_arraycopy(bool dest_uninitialized = false) {
return dest_uninitialized ? _arrayof_oop_arraycopy_uninit : _arrayof_oop_arraycopy;
}
static address arrayof_jbyte_disjoint_arraycopy() { return _arrayof_jbyte_disjoint_arraycopy; }
static address arrayof_jshort_disjoint_arraycopy() { return _arrayof_jshort_disjoint_arraycopy; }
static address arrayof_jint_disjoint_arraycopy() { return _arrayof_jint_disjoint_arraycopy; }
static address arrayof_jlong_disjoint_arraycopy() { return _arrayof_jlong_disjoint_arraycopy; }
static address arrayof_oop_disjoint_arraycopy(bool dest_uninitialized = false) {
return dest_uninitialized ? _arrayof_oop_disjoint_arraycopy_uninit : _arrayof_oop_disjoint_arraycopy;
}
static address checkcast_arraycopy(bool dest_uninitialized = false) {
return dest_uninitialized ? _checkcast_arraycopy_uninit : _checkcast_arraycopy;
}
static address unsafe_arraycopy() { return _unsafe_arraycopy; }
static address generic_arraycopy() { return _generic_arraycopy; }
static address jbyte_fill() { return _jbyte_fill; }
static address jshort_fill() { return _jshort_fill; }
static address jint_fill() { return _jint_fill; }
static address arrayof_jbyte_fill() { return _arrayof_jbyte_fill; }
static address arrayof_jshort_fill() { return _arrayof_jshort_fill; }
static address arrayof_jint_fill() { return _arrayof_jint_fill; }
static address select_fill_function(BasicType t, bool aligned, const char* &name);
static double intrinsic_log(double d) {
assert(_intrinsic_log != NULL, "must be defined");
return _intrinsic_log(d);
}
static double intrinsic_log10(double d) {
assert(_intrinsic_log != NULL, "must be defined");
return _intrinsic_log10(d);
}
static double intrinsic_exp(double d) {
assert(_intrinsic_exp != NULL, "must be defined");
return _intrinsic_exp(d);
}
static double intrinsic_pow(double d, double d2) {
assert(_intrinsic_pow != NULL, "must be defined");
return _intrinsic_pow(d, d2);
}
static double intrinsic_sin(double d) {
assert(_intrinsic_sin != NULL, "must be defined");
return _intrinsic_sin(d);
}
static double intrinsic_cos(double d) {
assert(_intrinsic_cos != NULL, "must be defined");
return _intrinsic_cos(d);
}
static double intrinsic_tan(double d) {
assert(_intrinsic_tan != NULL, "must be defined");
return _intrinsic_tan(d);
}
//
// Default versions of the above arraycopy functions for platforms which do
// not have specialized versions
//
static void jbyte_copy (jbyte* src, jbyte* dest, size_t count);
static void jshort_copy (jshort* src, jshort* dest, size_t count);
static void jint_copy (jint* src, jint* dest, size_t count);
static void jlong_copy (jlong* src, jlong* dest, size_t count);
static void oop_copy (oop* src, oop* dest, size_t count);
static void oop_copy_uninit(oop* src, oop* dest, size_t count);
static void arrayof_jbyte_copy (HeapWord* src, HeapWord* dest, size_t count);
static void arrayof_jshort_copy (HeapWord* src, HeapWord* dest, size_t count);
static void arrayof_jint_copy (HeapWord* src, HeapWord* dest, size_t count);
static void arrayof_jlong_copy (HeapWord* src, HeapWord* dest, size_t count);
static void arrayof_oop_copy (HeapWord* src, HeapWord* dest, size_t count);
static void arrayof_oop_copy_uninit(HeapWord* src, HeapWord* dest, size_t count);
};
#endif // SHARE_VM_RUNTIME_STUBROUTINES_HPP
|
; A267802: Decimal representation of the n-th iteration of the "Rule 213" elementary cellular automaton starting with a single ON (black) cell.
; 1,3,19,115,499,2035,8179,32755,131059,524275,2097139,8388595,33554419,134217715,536870899,2147483635,8589934579,34359738355,137438953459,549755813875,2199023255539,8796093022195,35184372088819,140737488355315,562949953421299,2251799813685235,9007199254740979
mov $1,4
pow $1,$0
mov $2,$0
sub $2,3
lpb $2,1
mov $1,$0
add $1,7
mov $2,$0
lpe
mul $1,2
sub $1,13
|
/*
* GridTools
*
* Copyright (c) 2014-2019, ETH Zurich
* All rights reserved.
*
* Please, refer to the LICENSE file in the root directory.
* SPDX-License-Identifier: BSD-3-Clause
*/
#pragma once
#include "../../common/hymap.hpp"
#include "../../meta.hpp"
#include "concept.hpp"
#include "delegate.hpp"
#include "multi_shift.hpp"
namespace gridtools {
namespace sid {
namespace shift_sid_origin_impl_ {
template <class Offsets>
struct add_offset_f {
Offsets const &m_offsets;
template <class Dim, class Bound, std::enable_if_t<has_key<Offsets, Dim>::value, int> = 0>
auto operator()(Bound &&bound) const {
return std::forward<Bound>(bound) - at_key<Dim>(m_offsets);
}
template <class Dim, class Bound, std::enable_if_t<!has_key<Offsets, Dim>::value, int> = 0>
std::decay_t<Bound> operator()(Bound &&bound) const {
return bound;
}
};
template <class Bounds, class Offsets>
auto add_offsets(Bounds &&bounds, Offsets const &offsets) {
return hymap::transform(add_offset_f<Offsets>{offsets}, std::forward<Bounds>(bounds));
}
template <class Sid, class LowerBounds, class UpperBounds>
class shifted_sid : public delegate<Sid> {
sid::ptr_holder_type<Sid> m_origin;
LowerBounds m_lower_bounds;
UpperBounds m_upper_bounds;
friend sid::ptr_holder_type<Sid> sid_get_origin(shifted_sid &obj) { return obj.m_origin; }
friend LowerBounds const &sid_get_lower_bounds(shifted_sid const &obj) { return obj.m_lower_bounds; }
friend UpperBounds const &sid_get_upper_bounds(shifted_sid const &obj) { return obj.m_upper_bounds; }
public:
template <class Arg, class Offsets>
shifted_sid(Arg &&original_sid, Offsets &&offsets) noexcept
: delegate<Sid>(std::forward<Arg>(original_sid)), m_origin{[this, &offsets]() {
auto &&strides = sid::get_strides(this->impl());
sid::ptr_diff_type<Sid> ptr_offset{};
multi_shift(ptr_offset, strides, offsets);
return sid::get_origin(this->impl()) + ptr_offset;
}()},
m_lower_bounds(add_offsets(sid::get_lower_bounds(original_sid), offsets)),
m_upper_bounds(add_offsets(sid::get_upper_bounds(original_sid), offsets)) {}
};
template <class Sid, class Offsets>
using shifted_sid_type = shifted_sid<Sid,
decltype(add_offsets(sid::get_lower_bounds(std::declval<Sid const &>()), std::declval<Offsets>())),
decltype(add_offsets(sid::get_upper_bounds(std::declval<Sid const &>()), std::declval<Offsets>()))>;
} // namespace shift_sid_origin_impl_
template <class Sid, class Offset>
shift_sid_origin_impl_::shifted_sid_type<std::decay_t<Sid>, Offset> shift_sid_origin(
Sid &&sid, Offset &&offset) {
return {std::forward<Sid>(sid), std::forward<Offset>(offset)};
}
template <class Sid, class Offset>
shift_sid_origin_impl_::shifted_sid_type<Sid &, Offset> shift_sid_origin(
std::reference_wrapper<Sid> sid, Offset &&offset) {
return {sid.get(), std::forward<Offset>(offset)};
}
} // namespace sid
} // namespace gridtools
|
; stdio_longzeroonstream
; 05.2008 aralbrec
PUBLIC stdio_longzeroonstream
; more common code from %li and %lx scan converters
.stdio_longzeroonstream
; we've read a 0 but have no way of pushing it back on the stream
; so take care of things here rather than in the common code
xor a ; clear carry (no error)
bit 3,c ; return if assignment is suppressed
jr nz, skip
ld (de),a ; integer = 0
inc de
ld (de),a
bit 1,c
jr z, notlong
inc de
ld (de),a
inc de
ld (de),a
.notlong
exx
inc de ; number of conversions increased by one
exx
.skip
ld e,a
ld d,a ; %lI requires de = 0
ret
|
// Copyright (c) 2017 Samsung Electronics Co., LTD
// Distributed under the MIT License.
// See the LICENSE file in the project root for more information.
#include "metadata/modules.h"
#include <string>
#include <vector>
#include <list>
#include <unordered_set>
#include "metadata/typeprinter.h"
#include "platform.h"
#include "managed/interop.h"
#include "utils/utf.h"
namespace netcoredbg
{
static const char *g_nonUserCode = "System.Diagnostics.DebuggerNonUserCodeAttribute..ctor";
static const char *g_stepThrough = "System.Diagnostics.DebuggerStepThroughAttribute..ctor";
// TODO: DebuggerStepThroughAttribute also affects breakpoints when JMC is enabled
// From ECMA-335
static const std::unordered_set<std::string> g_operatorMethodNames
{
// Unary operators
"op_Decrement", // --
"op_Increment", // ++
"op_UnaryNegation", // - (unary)
"op_UnaryPlus", // + (unary)
"op_LogicalNot", // !
"op_True", // Not defined
"op_False", // Not defined
"op_AddressOf", // & (unary)
"op_OnesComplement", // ~
"op_PointerDereference", // * (unary)
// Binary operators
"op_Addition", // + (binary)
"op_Subtraction", // - (binary)
"op_Multiply", // * (binary)
"op_Division", // /
"op_Modulus", // %
"op_ExclusiveOr", // ^
"op_BitwiseAnd", // & (binary)
"op_BitwiseOr", // |
"op_LogicalAnd", // &&
"op_LogicalOr", // ||
"op_Assign", // Not defined (= is not the same)
"op_LeftShift", // <<
"op_RightShift", // >>
"op_SignedRightShift", // Not defined
"op_UnsignedRightShift", // Not defined
"op_Equality", // ==
"op_GreaterThan", // >
"op_LessThan", // <
"op_Inequality", // !=
"op_GreaterThanOrEqual", // >=
"op_LessThanOrEqual", // <=
"op_UnsignedRightShiftAssignment", // Not defined
"op_MemberSelection", // ->
"op_RightShiftAssignment", // >>=
"op_MultiplicationAssignment", // *=
"op_PointerToMemberSelection", // ->*
"op_SubtractionAssignment", // -=
"op_ExclusiveOrAssignment", // ^=
"op_LeftShiftAssignment", // <<=
"op_ModulusAssignment", // %=
"op_AdditionAssignment", // +=
"op_BitwiseAndAssignment", // &=
"op_BitwiseOrAssignment", // |=
"op_Comma", // ,
"op_DivisionAssignment" // /=
};
static bool HasAttribute(IMetaDataImport *pMD, mdToken tok, const std::string &attrName)
{
bool found = false;
ULONG numAttributes = 0;
HCORENUM fEnum = NULL;
mdCustomAttribute attr;
while(SUCCEEDED(pMD->EnumCustomAttributes(&fEnum, tok, 0, &attr, 1, &numAttributes)) && numAttributes != 0)
{
mdToken ptkObj = mdTokenNil;
mdToken ptkType = mdTokenNil;
pMD->GetCustomAttributeProps(attr, &ptkObj, &ptkType, nullptr, nullptr);
std::string mdName;
TypePrinter::NameForToken(ptkType, pMD, mdName, true, nullptr);
if (mdName == attrName)
{
found = true;
break;
}
}
pMD->CloseEnum(fEnum);
return found;
}
static bool HasSourceLocation(PVOID pSymbolReaderHandle, mdMethodDef methodDef)
{
std::vector<Interop::SequencePoint> points;
if (FAILED(Interop::GetSequencePoints(pSymbolReaderHandle, methodDef, points)))
return false;
for (auto &p : points)
{
if (p.startLine != 0 && p.startLine != Interop::HiddenLine)
return true;
}
return false;
}
static HRESULT GetNonJMCMethodsForTypeDef(
IMetaDataImport *pMD,
PVOID pSymbolReaderHandle,
mdTypeDef typeDef,
std::vector<mdToken> &excludeMethods)
{
HRESULT Status;
ULONG numMethods = 0;
HCORENUM fEnum = NULL;
mdMethodDef methodDef;
while(SUCCEEDED(pMD->EnumMethods(&fEnum, typeDef, &methodDef, 1, &numMethods)) && numMethods != 0)
{
mdTypeDef memTypeDef;
ULONG nameLen;
WCHAR szFunctionName[mdNameLen] = {0};
Status = pMD->GetMethodProps(methodDef, &memTypeDef,
szFunctionName, _countof(szFunctionName), &nameLen,
nullptr, nullptr, nullptr, nullptr, nullptr);
if (FAILED(Status))
continue;
if ((g_operatorMethodNames.find(to_utf8(szFunctionName)) != g_operatorMethodNames.end())
|| HasAttribute(pMD, methodDef, g_nonUserCode)
|| HasAttribute(pMD, methodDef, g_stepThrough)
|| !HasSourceLocation(pSymbolReaderHandle, methodDef))
{
excludeMethods.push_back(methodDef);
}
}
pMD->CloseEnum(fEnum);
mdProperty propertyDef;
ULONG numProperties = 0;
HCORENUM propEnum = NULL;
while(SUCCEEDED(pMD->EnumProperties(&propEnum, typeDef, &propertyDef, 1, &numProperties)) && numProperties != 0)
{
mdMethodDef mdSetter;
mdMethodDef mdGetter;
if (SUCCEEDED(pMD->GetPropertyProps(propertyDef,
nullptr,
nullptr,
0,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
&mdSetter,
&mdGetter,
nullptr,
0,
nullptr)))
{
if (mdSetter != mdMethodDefNil)
excludeMethods.push_back(mdSetter);
if (mdGetter != mdMethodDefNil)
excludeMethods.push_back(mdGetter);
}
}
pMD->CloseEnum(propEnum);
return S_OK;
}
static HRESULT GetNonJMCClassesAndMethods(ICorDebugModule *pModule, PVOID pSymbolReaderHandle, std::vector<mdToken> &excludeTokens)
{
HRESULT Status;
ToRelease<IUnknown> pMDUnknown;
ToRelease<IMetaDataImport> pMD;
IfFailRet(pModule->GetMetaDataInterface(IID_IMetaDataImport, &pMDUnknown));
IfFailRet(pMDUnknown->QueryInterface(IID_IMetaDataImport, (LPVOID*) &pMD));
ULONG numTypedefs = 0;
HCORENUM fEnum = NULL;
mdTypeDef typeDef;
while(SUCCEEDED(pMD->EnumTypeDefs(&fEnum, &typeDef, 1, &numTypedefs)) && numTypedefs != 0)
{
if (HasAttribute(pMD, typeDef, g_nonUserCode))
excludeTokens.push_back(typeDef);
else
GetNonJMCMethodsForTypeDef(pMD, pSymbolReaderHandle, typeDef, excludeTokens);
}
pMD->CloseEnum(fEnum);
return S_OK;
}
HRESULT Modules::SetJMCFromAttributes(ICorDebugModule *pModule, PVOID pSymbolReaderHandle)
{
std::vector<mdToken> excludeTokens;
GetNonJMCClassesAndMethods(pModule, pSymbolReaderHandle, excludeTokens);
for (mdToken token : excludeTokens)
{
if (TypeFromToken(token) == mdtMethodDef)
{
ToRelease<ICorDebugFunction> pFunction;
ToRelease<ICorDebugFunction2> pFunction2;
if (FAILED(pModule->GetFunctionFromToken(token, &pFunction)))
continue;
if (FAILED(pFunction->QueryInterface(IID_ICorDebugFunction2, (LPVOID *)&pFunction2)))
continue;
pFunction2->SetJMCStatus(FALSE);
}
else if (TypeFromToken(token) == mdtTypeDef)
{
ToRelease<ICorDebugClass> pClass;
ToRelease<ICorDebugClass2> pClass2;
if (FAILED(pModule->GetClassFromToken(token, &pClass)))
continue;
if (FAILED(pClass->QueryInterface(IID_ICorDebugClass2, (LPVOID *)&pClass2)))
continue;
pClass2->SetJMCStatus(FALSE);
}
}
return S_OK;
}
} // namespace netcoredbg
|
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <algorithm>
#include <cinttypes>
#include <cmath>
#include <cstdlib>
#include <random>
#include <string>
// clang-format off
#ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
#define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
#endif
#ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
#define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
#endif
// clang-format on
#include "gtest/gtest.h"
#include "util/type_prop.hpp"
#include "runtime/backend.hpp"
#include "ngraph/runtime/tensor.hpp"
#include "ngraph/ngraph.hpp"
#include "util/all_close.hpp"
#include "util/all_close_f.hpp"
#include "util/ndarray.hpp"
#include "util/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
NGRAPH_TEST(${BACKEND_NAME}, divide)
{
Shape shape{2, 2};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto B = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(make_shared<op::v1::Divide>(A, B), ParameterVector{A, B});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto a = backend->create_tensor(element::f32, shape);
copy_data(a, vector<float>{2, 4, 8, 16});
auto b = backend->create_tensor(element::f32, shape);
copy_data(b, vector<float>{1, 2, 4, 8});
auto result = backend->create_tensor(element::f32, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_TRUE(test::all_close_f((vector<float>{2, 2, 2, 2}), read_vector<float>(result)));
}
NGRAPH_TEST(${BACKEND_NAME}, divide_int32)
{
Shape shape{2, 2};
auto A = make_shared<op::Parameter>(element::i32, shape);
auto B = make_shared<op::Parameter>(element::i32, shape);
auto f = make_shared<Function>(make_shared<op::v1::Divide>(A, B), ParameterVector{A, B});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto a = backend->create_tensor(element::i32, shape);
copy_data(a, vector<int32_t>{0x40000140, 0x40000001, 8, 16});
auto b = backend->create_tensor(element::i32, shape);
copy_data(b, vector<int32_t>{2, 5, 4, 8});
auto result = backend->create_tensor(element::i32, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<int32_t>{536871072, 214748365, 2, 2}), read_vector<int32_t>(result));
}
NGRAPH_TEST(${BACKEND_NAME}, divide_cpp_rounding_int32)
{
Shape shape{2, 2};
auto A = make_shared<op::Parameter>(element::i32, shape);
auto B = make_shared<op::Parameter>(element::i32, shape);
auto f = make_shared<Function>(make_shared<op::v1::Divide>(A, B, false), ParameterVector{A, B});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto a = backend->create_tensor(element::i32, shape);
copy_data(a, vector<int32_t>{-10, -10, 10, 10});
auto b = backend->create_tensor(element::i32, shape);
copy_data(b, vector<int32_t>{-3, 3, -3, 3});
auto result = backend->create_tensor(element::i32, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<int32_t>{3, -3, -3, 3}), read_vector<int32_t>(result));
}
NGRAPH_TEST(${BACKEND_NAME}, divide_python_rounding_int32)
{
Shape shape{2, 2};
auto A = make_shared<op::Parameter>(element::i32, shape);
auto B = make_shared<op::Parameter>(element::i32, shape);
auto f = make_shared<Function>(make_shared<op::v1::Divide>(A, B), ParameterVector{A, B});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto a = backend->create_tensor(element::i32, shape);
copy_data(a, vector<int32_t>{-10, -10, 10, 10});
auto b = backend->create_tensor(element::i32, shape);
copy_data(b, vector<int32_t>{-3, 3, -3, 3});
auto result = backend->create_tensor(element::i32, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<int32_t>{3, -4, -4, 3}), read_vector<int32_t>(result));
}
NGRAPH_TEST(${BACKEND_NAME}, divide_overload)
{
Shape shape{2, 2};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto B = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(make_shared<op::v1::Divide>(A, B), ParameterVector{A, B});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto a = backend->create_tensor(element::f32, shape);
copy_data(a, vector<float>{2, 4, 8, 16});
auto b = backend->create_tensor(element::f32, shape);
copy_data(b, vector<float>{1, 2, 4, 8});
auto result = backend->create_tensor(element::f32, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_TRUE(test::all_close_f((vector<float>{2, 2, 2, 2}), read_vector<float>(result)));
}
namespace
{
template <typename Value>
void divide_broadcast()
{
const auto element_type = ngraph::element::from<Value>();
const Shape shape_a{3, 2, 1};
const Shape shape_b{1, 6};
const Shape shape_o{3, 2, 6};
std::vector<Value> in_a{12, 24, 36, 48, 60, 72};
std::vector<Value> in_b{1, 2, 3, 4, 6, 1};
// clang-format off
std::vector<Value> out{12, 6, 4, 3, 2, 12,
24, 12, 8, 6, 4, 24,
36, 18, 12, 9, 6, 36,
48, 24, 16, 12, 8, 48,
60, 30, 20, 15, 10, 60,
72, 36, 24, 18, 12, 72};
// clang-format on
auto A = make_shared<op::Parameter>(element_type, shape_a);
auto B = make_shared<op::Parameter>(element_type, shape_b);
auto f = make_shared<Function>(make_shared<op::v1::Divide>(A, B), ParameterVector{A, B});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto a = backend->create_tensor(element_type, shape_a, in_a.data());
auto b = backend->create_tensor(element_type, shape_b, in_b.data());
auto result = backend->create_tensor(element_type, shape_o);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ(out, read_vector<Value>(result));
}
} // namespace
NGRAPH_TEST(${BACKEND_NAME}, divide_int32_broadcast)
{
divide_broadcast<int32_t>();
}
NGRAPH_TEST(${BACKEND_NAME}, divide_f32_broadcast)
{
divide_broadcast<float>();
}
NGRAPH_TEST(${BACKEND_NAME}, divide_int32_scalar)
{
Shape shape{};
auto A = make_shared<op::Parameter>(element::i32, shape);
auto B = make_shared<op::Parameter>(element::i32, shape);
auto f = make_shared<Function>(make_shared<op::v1::Divide>(A, B), ParameterVector{A, B});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto a = backend->create_tensor(element::i32, shape);
copy_data(a, vector<int32_t>{18});
auto b = backend->create_tensor(element::i32, shape);
copy_data(b, vector<int32_t>{8});
auto result = backend->create_tensor(element::i32, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ(vector<int32_t>{2}, read_vector<int32_t>(result));
}
NGRAPH_TEST(${BACKEND_NAME}, divide_f32_scalar)
{
Shape shape{};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto B = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(make_shared<op::v1::Divide>(A, B), ParameterVector{A, B});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto a = backend->create_tensor(element::f32, shape);
copy_data(a, vector<float>{18});
auto b = backend->create_tensor(element::f32, shape);
copy_data(b, vector<float>{8});
auto result = backend->create_tensor(element::f32, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_TRUE(test::all_close_f((vector<float>{2.25}), read_vector<float>(result)));
}
NGRAPH_TEST(${BACKEND_NAME}, divide_by_zero_float32)
{
Shape shape{2, 2};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto B = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(make_shared<op::v1::Divide>(A, B), ParameterVector{A, B});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto a = backend->create_tensor(element::f32, shape);
copy_data(a, vector<float>{2, 4, 8, 16});
auto b = backend->create_tensor(element::f32, shape);
copy_data(b, vector<float>{0, 0, 0, 0});
auto result = backend->create_tensor(element::f32, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<float>{std::numeric_limits<float>::infinity(),
std::numeric_limits<float>::infinity(),
std::numeric_limits<float>::infinity(),
std::numeric_limits<float>::infinity()}),
read_vector<float>(result));
}
|
; A209721: 1/4 the number of (n+1) X 3 0..2 arrays with every 2 X 2 subblock having distinct clockwise edge differences.
; 3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,32769,49153,65537,98305,131073,196609,262145,393217,524289,786433,1048577,1572865,2097153,3145729,4194305,6291457,8388609,12582913,16777217,25165825,33554433,50331649,67108865,100663297,134217729,201326593,268435457,402653185,536870913,805306369,1073741825,1610612737,2147483649,3221225473,4294967297,6442450945,8589934593,12884901889,17179869185,25769803777,34359738369,51539607553,68719476737,103079215105,137438953473,206158430209,274877906945,412316860417,549755813889,824633720833,1099511627777,1649267441665,2199023255553,3298534883329,4398046511105,6597069766657,8796093022209,13194139533313,17592186044417,26388279066625,35184372088833,52776558133249,70368744177665,105553116266497,140737488355329,211106232532993,281474976710657,422212465065985,562949953421313,844424930131969,1125899906842625,1688849860263937,2251799813685249,3377699720527873,4503599627370497,6755399441055745,9007199254740993
mov $2,$0
mod $0,2
mul $2,2
add $2,4
mov $3,$0
mov $0,$2
add $0,15
lpb $0
sub $0,4
mov $1,$3
mul $3,2
add $3,2
lpe
div $1,16
add $1,2
|
include raster.i
CGROUP group code
code segment dword 'CODE'
assume cs:CGROUP,ds:CGROUP
public pj_bli2
;extern void pj_bli2(Vscreen *dv, int w, int h, int sx, int sy, int dx, dy,
; UBYTE *sp, int sbpr, int color, int bcolor);
;Blit a bitplane into memory byte-a-pixel plane.
pj_bli2 proc near
bli2p struc ;pj_bli2 parameter structure
bli2_edi dd ? ;what's there from pushad
bli2_esi dd ?
bli2_ebp dd ?
bli2_esp dd ?
bli2_ebx dd ?
bli2_edx dd ?
bli2_ecx dd ?
bli2_eax dd ?
bli2_ret dd ? ;return address for function
bli2_dv dd ? ;1st parameter - destination screen
bli2_dx dd ?
bli2_dy dd ?
bli2_w dd ?
bli2_h dd ?
bli2_sx dd ?
bli2_sy dd ?
bli2_sp dd ?
bli2_sbpr dd ?
bli2_color dd ?
bli2_bcolor dd ?
bli2p ends
pushad
mov ebp,esp
push es
lvarspace equ 16
pushspace equ 4
spt equ dword ptr [ebp-pushspace-4]
dpt equ dword ptr [ebp-pushspace-8]
dbpr equ dword ptr [ebp-pushspace-12]
sub esp,lvarspace ;space for local variables
mov edi,[ebp].bli2_dv ;get dest screen structure
;get starting source address in spt
mov eax,[ebp].bli2_sy
mul [ebp].bli2_sbpr ;y line offset in ax
mov ebx,[ebp].bli2_sx
shr ebx,3 ; += (sx>>3)
add eax,ebx ;start source offset in ax
add eax,[ebp].bli2_sp
mov spt,eax
;get starting destination address in es:dpt
mov eax,[edi].bym_bpr
mov dbpr,eax ;save a handy copy of dest bpr in local variable
mul [ebp].bli2_dy
add eax,[edi].bym_p
add eax,[ebp].bli2_dx
mov dpt,eax
mov ax,[edi].bym_pseg
mov es,ax
;calculate start mask for line into dl
mov ecx,[ebp].bli2_sx
and ecx,7
mov dl,80h
shr dl,cl ;and devote dl to it...
mov eax,[ebp].bli2_color
mov ebx,[ebp].bli2_bcolor
jmp zabline
abline:
mov ecx,[ebp].bli2_w ;dot count in ecx
mov dh,dl ;get mask into dh
mov esi,spt
mov edi,dpt
mov ah,[esi] ;fetch 1st byte of source into ah
inc esi
abpix:
test ah,dh
jnz abset
mov es:[edi],bl
inc edi ;skip pixel in dest
shr dh,1
jz newsrc
loop abpix
jmp zline
abset: stosb ;set pixel in dest
shr dh,1
jz newsrc
loop abpix
zline: mov ecx,[ebp].bli2_sbpr
add spt,ecx
mov ecx,dbpr
add dpt,ecx
zabline: dec [ebp].bli2_h
js za2
jmp abline
newsrc: ;get next byte of source
mov ah,[esi] ;fetch byte of source into ah
inc esi
mov dh,80h ;mask to 1st pixel in byte
loop abpix
jmp zline
za2:
add esp,lvarspace ;clear off local variables
pop es
popad
ret
pj_bli2 endp
code ends
end
|
#include "FurSimApp.h"
#include "TextureLoader.h"
#define LOG(_log, ...) { printf(_log, __VA_ARGS__); }
FurSim::FurSim()
{
}
FurSim::~FurSim()
{
}
static inline float FloatRand()
{
return rand() / (float)RAND_MAX;
}
GLuint CreateNoiseText2D(int a_iW, int a_iH, GLint a_uiInternalFormat, bool a_bMipmap = false)
{
float* _data = new float[a_iW * a_iH];
for (int y = 0; y < a_iH; ++y)
{
for (int x = 0; x < a_iW; ++x)
{
_data[y * a_iW + x] = FloatRand();
}
}
GLuint _outTex = NULL;
glGenTextures(1, &_outTex);
glBindTexture(GL_TEXTURE_2D, _outTex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, a_bMipmap ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, a_uiInternalFormat, a_iW, a_iH, 0, GL_RED, GL_FLOAT, _data);
if (a_bMipmap)
{
glGenerateMipmap(GL_TEXTURE_2D);
}
delete[] _data;
return _outTex;
}
bool TexCoordShape(MeshData& a_oShape)
{
return false;
}
//void FurSim::InitUniform()
//{
// m_oProgram.Use();
// const char* _uniformNames[] =
// {
// "u_projectionMatrix",
// "u_modelViewMatrix",
// "u_normalMatrix",
// "u_light.direction",
// "u_light.ambientColor",
// "u_light.diffuseColor",
// "u_light.specularColor",
// "u_textureFurColor",
// "a_vertex",
// "a_normal",
// "a_texCoord"
// };
//
// for (unsigned int i = 0; i < 11; ++i)
// {
// switch (i)
// {
// case 0:
// m_oProgram.SetUniform(_uniformNames[i], DATA.TRANSFORM.m_mProjection);
// break;
// case 1:
// //m_oProgram.SetUniform(_uniformNames[i], DATA.TRANSFORM.m);
// break;
// case 2:
// m_oProgram.SetUniform(_uniformNames[i], DATA.TRANSFORM.m_mProjection);
// break;
// case 3:
// m_oProgram.SetUniform(_uniformNames[i], DATA.TRANSFORM.m_mProjection);
// break;
// case 4:
// m_oProgram.SetUniform(_uniformNames[i], DATA.TRANSFORM.m_mProjection);
// break;
// case 5:
// m_oProgram.SetUniform(_uniformNames[i], DATA.TRANSFORM.m_mProjection);
// break;
// case 6:
// m_oProgram.SetUniform(_uniformNames[i], DATA.TRANSFORM.m_mProjection);
// break;
// case 7:
// m_oProgram.SetUniform(_uniformNames[i], DATA.TRANSFORM.m_mProjection);
// break;
// case 8:
// m_oProgram.SetUniform(_uniformNames[i], DATA.TRANSFORM.m_mProjection);
// break;
// case 9:
// m_oProgram.SetUniform(_uniformNames[i], DATA.TRANSFORM.m_mProjection);
// break;
// case 10:
// m_oProgram.SetUniform(_uniformNames[i], DATA.TRANSFORM.m_mProjection);
// break;
// }
// }
//}
void FurSim::Render()
{
}
void FurSim::Update(float a_fDeltaT)
{
}
void FurSim::OnResize(GLint a_iWidth, GLint a_iHeight)
{
}
void FurSim::OnKey(GLint a_iKey, GLint a_iAction)
{
}
void FurSim::OnMouseButton(GLint a_iButton, GLint a_iAction)
{
}
void FurSim::OnMouseMove(GLdouble a_dMouseX, GLdouble a_dMouseY)
{
}
void FurSim::OnMouseWheel(GLdouble a_dPosition)
{
}
void FurSim::Shutdown()
{
}
void FurSim::Init(BaseApplication* a_oCurrApp, vec3 a_vCamPos, ivec2 a_vScreenSize, const char* a_pccWinName, bool a_bFullScreen)
{
m_oMyLights = { { vec3(1.0f, 1.0f, 1.0f) }, { vec4(0.3f, 0.3f, 0.3f, 1.0f) }, { vec4(1.0f) }, { vec4(1.0f) } };
DATA.TRANSFORM.m_mProjection = DATA.m_oCurrCamera->GetProjectionTransform(APPINFO.m_viWinSize.xy(), 1.0f, 10000.0f);
m_uiTextureFurColour = TEXLOADER::LoadTexture("./textures/tiger.tga", false, true);
int _noiseSize = 64;
m_uiTexFurStrength = CreateNoiseText2D(_noiseSize, _noiseSize, GL_R16F, true);
}
void FurSim::LoadShaders()
{
vector<const char*> _shrSource;
LOG("Compiling ambient diffuse texture shaders...");
_shrSource.push_back(AMBIENT_VERT);
_shrSource.push_back(AMBIENT_FRAG);
m_oProgram.CreateProgram(_shrSource);
_shrSource.clear();
LOG("Compiling fur simulation shaders...");
_shrSource.push_back(FUR_VERTEX);
_shrSource.push_back(FUR_GEOM);
_shrSource.push_back(FUR_FRAG);
m_oFurProgram.CreateProgram(_shrSource);
_shrSource.clear();
}
MeshData* FurSim::LoadMesh(FBXFile* a_oFile)
{
MeshData* _result = new MeshData();
unsigned int _meshCount = a_oFile->getMeshCount();
for (unsigned int meshIndx = 0; meshIndx < _meshCount; ++meshIndx)
{
FBXMeshNode* _currMesh = a_oFile->getMeshByIndex(meshIndx);
_result->m_uiVertexCount = _currMesh->m_vertices.size();
_result->m_uiIndexCount = _currMesh->m_indices.size();
glGenBuffers(1, &_result->m_uiVBO);
glGenBuffers(1, &_result->m_uiIBO);
glGenVertexArrays(1, &_result->m_uiVAO);
glBindVertexArray(_result->m_uiVAO);
glBindBuffer(GL_ARRAY_BUFFER, _result->m_uiVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(FBXVertex)* _currMesh->m_vertices.size(),
_currMesh->m_vertices.data(), GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _result->m_uiIBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint)* _currMesh->m_indices.size(),
_currMesh->m_indices.data(), GL_STATIC_DRAW);
glEnableVertexAttribArray(0); //Position
glEnableVertexAttribArray(1); //Normal
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(FBXVertex), (void*)FBXVertex::PositionOffset);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(FBXVertex), (void*)FBXVertex::NormalOffset);
glBindVertexArray(NULL);
glBindBuffer(GL_ARRAY_BUFFER, NULL);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, NULL);
}
return _result;
} |
; A141827: a(n) = (n^3*a(n-1) - 1)/(n - 1) for n >= 2, with a(0) = 1, a(1) = 4.
; Submitted by Jon Maiga
; 1,4,31,418,8917,278656,12037939,688168846,50334635593,4586743668412,509638185379111,67832842473959674,10655922890454756061,1950921882527424922168,411794588127327229725307
mov $2,$0
add $2,1
mov $4,$0
lpb $2
sub $2,1
mov $3,2
lpb $3
sub $3,1
mul $4,$2
add $1,$4
lpe
add $1,1
lpe
mov $0,$1
|
SECTION code_graphics
PUBLIC getmaxx
PUBLIC _getmaxx
EXTERN generic_console_get_mode
getmaxx:
_getmaxx:
call generic_console_get_mode
ld hl,255
cp 3
ret z
ld hl,511
cp 2
ret z
ld hl,1023
ret
|
; A177747: Convolution of A008805 (triangular numbers repeated) with itself.
; 1,2,7,12,27,42,77,112,182,252,378,504,714,924,1254,1584,2079,2574,3289,4004,5005,6006,7371,8736,10556,12376,14756,17136,20196,23256,27132,31008,35853,40698,46683,52668,59983,67298,76153,85008,95634,106260,118910,131560,146510,161460,179010,196560,217035,237510,261261,285012,312417,339822,371287,402752,438712,474672,515592,556512,602888,649264,701624,753984,812889,871794,937839,1003884,1077699,1151514,1233765,1316016,1407406,1498796,1600066,1701336,1813266,1925196,2048606,2172016,2307767,2443518,2592513,2741508,2904693,3067878,3246243,3424608,3619188,3813768,4025644,4237520,4467820,4698120,4948020,5197920,5468645,5739370,6032195,6325020
mov $2,$0
add $2,1
mov $3,$0
lpb $2
mov $0,$3
sub $2,1
sub $0,$2
add $0,8
div $0,2
bin $0,4
add $1,$0
lpe
mov $0,$1
|
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit,printf,scanf ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll
import printf msvcrt.dll
import scanf msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
; ...
a dd 0
b dd 0
result dd 0
format1 db 'Insert a value for a=', 0
format2 db 'Insert a value for b=', 0
readformat db '%d', 0
printformat db '%d + %d = %x', 0
; our code starts here
segment code use32 class=code
start:
; ...
push dword format1
call [printf]
add esp, 4*1
push dword a
push dword readformat
call [scanf]
add esp, 4*2
push dword format2
call [printf]
add esp, 4*1
push dword b
push dword readformat
call [scanf]
add esp, 4*2
mov eax, [a]
add eax, [b]
mov [result], eax
push dword [result]
push dword [b]
push dword [a]
push dword printformat
call [printf]
add esp, 4*4
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.