text
stringlengths
1
1.05M
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r13 push %r8 push %rbp push %rcx push %rdi push %rsi lea addresses_A_ht+0xb64e, %rsi lea addresses_UC_ht+0x72ff, %rdi nop nop cmp $4921, %r8 mov $11, %rcx rep movsq nop nop nop cmp $21518, %rcx lea addresses_WT_ht+0xcf4f, %r10 nop nop nop nop dec %rbp mov $0x6162636465666768, %r13 movq %r13, %xmm1 movups %xmm1, (%r10) nop nop nop nop nop cmp $26701, %r13 lea addresses_WC_ht+0x14f7f, %r13 nop nop and $40090, %rcx vmovups (%r13), %ymm5 vextracti128 $1, %ymm5, %xmm5 vpextrq $1, %xmm5, %r10 nop sub %rcx, %rcx lea addresses_UC_ht+0x10aff, %r13 xor $25444, %rdi movb $0x61, (%r13) nop nop nop sub $8796, %r8 lea addresses_WT_ht+0x66ff, %rcx and %rdi, %rdi movb (%rcx), %r13b nop xor %rcx, %rcx lea addresses_WC_ht+0x9aff, %rcx nop nop nop nop sub %rsi, %rsi movb (%rcx), %r8b nop and $28803, %rcx lea addresses_UC_ht+0x1d9e7, %rdi nop xor $42443, %r10 mov (%rdi), %r13w cmp %rcx, %rcx lea addresses_WT_ht+0x10aff, %r8 nop nop nop nop sub $37879, %rsi movb $0x61, (%r8) inc %r8 pop %rsi pop %rdi pop %rcx pop %rbp pop %r8 pop %r13 pop %r10 ret .global s_faulty_load s_faulty_load: push %r13 push %r14 push %r15 push %r8 push %rax push %rbx push %rsi // Store lea addresses_UC+0x1529f, %r14 nop nop nop nop nop sub %r15, %r15 mov $0x5152535455565758, %rax movq %rax, (%r14) add $14945, %rax // Load lea addresses_WC+0x557f, %r15 nop and $21839, %r13 vmovups (%r15), %ymm7 vextracti128 $1, %ymm7, %xmm7 vpextrq $1, %xmm7, %rax nop nop nop nop xor $4072, %rsi // Faulty Load lea addresses_D+0x122ff, %r13 nop nop nop nop nop and $52625, %r8 movups (%r13), %xmm5 vpextrq $1, %xmm5, %r14 lea oracles, %rsi and $0xff, %r14 shlq $12, %r14 mov (%rsi,%r14,1), %r14 pop %rsi pop %rbx pop %rax pop %r8 pop %r15 pop %r14 pop %r13 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 1, 'type': 'addresses_D', 'congruent': 0}} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 8, 'type': 'addresses_UC', 'congruent': 5}, 'OP': 'STOR'} {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_WC', 'congruent': 4}} [Faulty Load] {'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_D', 'congruent': 0}} <gen_prepare_buffer> {'dst': {'same': False, 'congruent': 9, 'type': 'addresses_UC_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 0, 'type': 'addresses_A_ht'}} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_WT_ht', 'congruent': 4}, 'OP': 'STOR'} {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_WC_ht', 'congruent': 7}} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 1, 'type': 'addresses_UC_ht', 'congruent': 11}, 'OP': 'STOR'} {'OP': 'LOAD', 'src': {'same': False, 'NT': True, 'AVXalign': False, 'size': 1, 'type': 'addresses_WT_ht', 'congruent': 10}} {'OP': 'LOAD', 'src': {'same': False, 'NT': True, 'AVXalign': False, 'size': 1, 'type': 'addresses_WC_ht', 'congruent': 10}} {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_UC_ht', 'congruent': 2}} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 1, 'type': 'addresses_WT_ht', 'congruent': 11}, '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 */
.def counter_x r0 .def counter_y r1 .def comp r2 .def s_zero r3 .def s_one r4 .label setup .label entry_addr loadi counter_x, vram_width loadi counter_y, vram_height rst s_zero loadi s_one, 1 sub counter_x, s_one sub counter_y, s_one push dword, msg_welcome push dword, 29 push word, sys_write syscall push dword, msg_sleep push dword, 26 push word, sys_write syscall push float, 3.0 push word, sys_sleep syscall jmp main .label main rpush counter_x rpush counter_y push byte, 0b11100011 push dword, 9 call gfx_draw_pixel jmp check_zero_reached1 .label check_zero_reached1 cmp counter_x, s_zero jz check_zero_reached2 jmp loop .label check_zero_reached2 cmp counter_y, s_zero jz quit_program jmp loop .label loop cmp counter_x, s_zero jz br1 sub counter_x, s_one jmp br2 .label br1 sub counter_y, s_one loadi counter_x, vram_width sub counter_x, s_one .label br2 jmp main .label quit_program push byte, 0 push word, sys_exit syscall .db msg_welcome 29 "welcome to the graphics demo\n" .db msg_sleep 26 "sleeping for 3 seconds...\n" .include "graphics.asm"
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma // de Barcelona (UAB). // // This work is licensed under the terms of the MIT license. // For a copy, see <https://opensource.org/licenses/MIT>. #include "carla/server/CarlaMeasurements.h" #include "carla/Logging.h" namespace carla { namespace server { void CarlaMeasurements::Write(const carla_measurements &measurements) { _measurements = measurements; const auto size = measurements.number_of_non_player_agents * sizeof(carla_agent); if (_agents_buffer_size < size) { log_info("allocating agents buffer of", size, "bytes"); _agents_buffer = std::make_unique<unsigned char[]>(size); _agents_buffer_size = size; } std::memcpy(_agents_buffer.get(), measurements.non_player_agents, size); _measurements.non_player_agents = reinterpret_cast<const carla_agent *>(_agents_buffer.get()); } } // namespace server } // namespace carla
; this is a list of the sprites that can be enabled/disabled during the game ; there may be unused sprites, but these will remain unmarked until ; the disassembly is complete const_def const HS_PALLET_TOWN_OAK ; 00 const HS_LYING_OLD_MAN ; 01 const HS_OLD_MAN_1 ; 02 const HS_OLD_MAN ; 03 const HS_MUSEUM_GUY ; 04 const HS_GYM_GUY ; 05 const HS_CERULEAN_RIVAL ; 06 const HS_CERULEAN_ROCKET ; 07 const HS_CERULEAN_GUARD_1 ; 08 const HS_UNKNOWN_DUNGEON_GUY ; 09 const HS_CERULEAN_GUARD_2 ; 0A const HS_SAFFRON_CITY_1 ; 0B const HS_SAFFRON_CITY_2 ; 0C const HS_SAFFRON_CITY_3 ; 0D const HS_SAFFRON_CITY_4 ; 0E const HS_SAFFRON_CITY_5 ; 0F const HS_SAFFRON_CITY_6 ; 10 const HS_SAFFRON_CITY_7 ; 11 const HS_SAFFRON_CITY_8 ; 12 const HS_SAFFRON_CITY_9 ; 13 const HS_SAFFRON_CITY_A ; 14 const HS_SAFFRON_CITY_B ; 15 const HS_SAFFRON_CITY_C ; 16 const HS_SAFFRON_CITY_D ; 17 const HS_SAFFRON_CITY_E ; 18 const HS_SAFFRON_CITY_F ; 19 const HS_ROUTE_2_ITEM_1 ; 1A const HS_ROUTE_2_ITEM_2 ; 1B const HS_ROUTE_4_ITEM ; 1C const HS_ROUTE_9_ITEM ; 1D const HS_ROUTE_12_SNORLAX ; 1E const HS_ROUTE_12_ITEM_1 ; 1F const HS_ROUTE_12_ITEM_2 ; 20 const HS_ROUTE_15_ITEM ; 21 const HS_ROUTE_16_SNORLAX ; 22 const HS_ROUTE_22_RIVAL_1 ; 23 const HS_ROUTE_22_RIVAL_2 ; 24 const HS_NUGGET_BRIDGE_GUY ; 25 const HS_ROUTE_24_ITEM ; 26 const HS_ROUTE_25_ITEM ; 27 const HS_DAISY_SITTING ; 28 const HS_DAISY_WALKING ; 29 const HS_TOWN_MAP ; 2A const HS_OAKS_LAB_RIVAL ; 2B const HS_STARTER_BALL_1 ; 2C const HS_OAKS_LAB_OAK_1 ; 2D const HS_POKEDEX_1 ; 2E const HS_POKEDEX_2 ; 2F const HS_OAKS_LAB_OAK_2 ; 30 const HS_VIRIDIAN_GYM_GIOVANNI ; 31 const HS_VIRIDIAN_GYM_ITEM ; 32 const HS_OLD_AMBER ; 33 const HS_CERULEAN_BULBASAUR ; 34 const HS_UNKNOWN_DUNGEON_1_ITEM_1 ; 35 const HS_UNKNOWN_DUNGEON_1_ITEM_2 ; 36 const HS_UNKNOWN_DUNGEON_1_ITEM_3 ; 37 const HS_UNKNOWN_DUNGEON_1_ITEM_4 ; 38 const HS_POKEMONTOWER_2_RIVAL ; 39 const HS_POKEMONTOWER_3_ITEM ; 3A const HS_POKEMONTOWER_4_ITEM_1 ; 3B const HS_POKEMONTOWER_4_ITEM_2 ; 3C const HS_POKEMONTOWER_4_ITEM_3 ; 3D const HS_POKEMONTOWER_5_ITEM ; 3E const HS_POKEMONTOWER_6_ITEM_1 ; 3F const HS_POKEMONTOWER_6_ITEM_2 ; 40 const HS_POKEMONTOWER_7_JESSIE ; 41 const HS_POKEMONTOWER_7_JAMES ; 42 const HS_POKEMONTOWER_7_MR_FUJI ; 43 const HS_LAVENDER_HOUSE_1_MR_FUJI ; 44 const HS_CELADON_MANSION_5_GIFT ; 45 const HS_GAME_CORNER_ROCKET ; 46 const HS_FUCHSIA_HOUSE_2_ITEM ; 47 const HS_MANSION_1_ITEM_1 ; 48 const HS_MANSION_1_ITEM_2 ; 49 const HS_FIGHTING_DOJO_GIFT_1 ; 4A const HS_FIGHTING_DOJO_GIFT_2 ; 4B const HS_SILPH_CO_1F_RECEPTIONIST ; 4C const HS_VOLTORB_1 ; 4D const HS_VOLTORB_2 ; 4E const HS_VOLTORB_3 ; 4F const HS_ELECTRODE_1 ; 50 const HS_VOLTORB_4 ; 51 const HS_VOLTORB_5 ; 52 const HS_ELECTRODE_2 ; 53 const HS_VOLTORB_6 ; 54 const HS_ZAPDOS ; 55 const HS_POWER_PLANT_ITEM_1 ; 56 const HS_POWER_PLANT_ITEM_2 ; 57 const HS_POWER_PLANT_ITEM_3 ; 58 const HS_POWER_PLANT_ITEM_4 ; 59 const HS_POWER_PLANT_ITEM_5 ; 5A const HS_MOLTRES ; 5B const HS_VICTORY_ROAD_2_ITEM_1 ; 5C const HS_VICTORY_ROAD_2_ITEM_2 ; 5D const HS_VICTORY_ROAD_2_ITEM_3 ; 5E const HS_VICTORY_ROAD_2_ITEM_4 ; 5F const HS_VICTORY_ROAD_2_BOULDER ; 60 const HS_BILL_POKEMON ; 61 const HS_BILL_1 ; 62 const HS_BILL_2 ; 63 const HS_VIRIDIAN_FOREST_ITEM_1 ; 64 const HS_VIRIDIAN_FOREST_ITEM_2 ; 65 const HS_VIRIDIAN_FOREST_ITEM_3 ; 66 const HS_MT_MOON_1_ITEM_1 ; 67 const HS_MT_MOON_1_ITEM_2 ; 68 const HS_MT_MOON_1_ITEM_3 ; 69 const HS_MT_MOON_1_ITEM_4 ; 6A const HS_MT_MOON_1_ITEM_5 ; 6B const HS_MT_MOON_1_ITEM_6 ; 6C const HS_MT_MOON_JESSIE ; 6D const HS_MT_MOON_JAMES ; 6E const HS_MT_MOON_3_FOSSIL_1 ; 6F const HS_MT_MOON_3_FOSSIL_2 ; 70 const HS_MT_MOON_3_ITEM_1 ; 71 const HS_MT_MOON_3_ITEM_2 ; 72 const HS_SS_ANNE_2_RIVAL ; 73 const HS_SS_ANNE_8_ITEM ; 74 const HS_SS_ANNE_9_ITEM_1 ; 75 const HS_SS_ANNE_9_ITEM_2 ; 76 const HS_SS_ANNE_10_ITEM_1 ; 77 const HS_SS_ANNE_10_ITEM_2 ; 78 const HS_SS_ANNE_10_ITEM_3 ; 79 const HS_VICTORY_ROAD_3_ITEM_1 ; 7A const HS_VICTORY_ROAD_3_ITEM_2 ; 7B const HS_VICTORY_ROAD_3_BOULDER ; 7C const HS_ROCKET_HIDEOUT_1_ITEM_1 ; 7D const HS_ROCKET_HIDEOUT_1_ITEM_2 ; 7E const HS_ROCKET_HIDEOUT_2_ITEM_1 ; 7F const HS_ROCKET_HIDEOUT_2_ITEM_2 ; 80 const HS_ROCKET_HIDEOUT_2_ITEM_3 ; 81 const HS_ROCKET_HIDEOUT_2_ITEM_4 ; 82 const HS_ROCKET_HIDEOUT_3_ITEM_1 ; 83 const HS_ROCKET_HIDEOUT_3_ITEM_2 ; 84 const HS_ROCKET_HIDEOUT_4_GIOVANNI ; 85 const HS_ROCKET_HIDEOUT_4_JAMES ; 86 const HS_ROCKET_HIDEOUT_4_JESSIE ; 87 const HS_ROCKET_HIDEOUT_4_ITEM_1 ; 88 const HS_ROCKET_HIDEOUT_4_ITEM_2 ; 89 const HS_ROCKET_HIDEOUT_4_ITEM_3 ; 8A const HS_ROCKET_HIDEOUT_4_ITEM_4 ; 8B const HS_ROCKET_HIDEOUT_4_ITEM_5 ; 8C const HS_SILPH_CO_2F_1 ; 8D const HS_SILPH_CO_2F_2 ; 8E const HS_SILPH_CO_2F_3 ; 8F const HS_SILPH_CO_2F_4 ; 90 const HS_SILPH_CO_2F_5 ; 91 const HS_SILPH_CO_3F_1 ; 92 const HS_SILPH_CO_3F_2 ; 93 const HS_SILPH_CO_3F_ITEM ; 94 const HS_SILPH_CO_4F_1 ; 95 const HS_SILPH_CO_4F_2 ; 96 const HS_SILPH_CO_4F_3 ; 97 const HS_SILPH_CO_4F_ITEM_1 ; 98 const HS_SILPH_CO_4F_ITEM_2 ; 99 const HS_SILPH_CO_4F_ITEM_3 ; 9A const HS_SILPH_CO_5F_1 ; 9B const HS_SILPH_CO_5F_2 ; 9C const HS_SILPH_CO_5F_3 ; 9D const HS_SILPH_CO_5F_4 ; 9E const HS_SILPH_CO_5F_ITEM_1 ; 9F const HS_SILPH_CO_5F_ITEM_2 ; A0 const HS_SILPH_CO_5F_ITEM_3 ; A1 const HS_SILPH_CO_6F_1 ; A2 const HS_SILPH_CO_6F_2 ; A3 const HS_SILPH_CO_6F_3 ; A4 const HS_SILPH_CO_6F_ITEM_1 ; A5 const HS_SILPH_CO_6F_ITEM_2 ; A6 const HS_SILPH_CO_7F_1 ; A7 const HS_SILPH_CO_7F_2 ; A8 const HS_SILPH_CO_7F_3 ; A9 const HS_SILPH_CO_7F_4 ; AA const HS_SILPH_CO_7F_RIVAL ; AB const HS_SILPH_CO_7F_ITEM_1 ; AC const HS_SILPH_CO_7F_ITEM_2 ; AD const HS_SILPH_CO_7F_8 ; AE const HS_SILPH_CO_8F_1 ; AF const HS_SILPH_CO_8F_2 ; B0 const HS_SILPH_CO_8F_3 ; B1 const HS_SILPH_CO_9F_1 ; B2 const HS_SILPH_CO_9F_2 ; B3 const HS_SILPH_CO_9F_3 ; B4 const HS_SILPH_CO_10F_1 ; B5 const HS_SILPH_CO_10F_2 ; B6 const HS_SILPH_CO_10F_3 ; B7 const HS_SILPH_CO_10F_ITEM_1 ; B8 const HS_SILPH_CO_10F_ITEM_2 ; B9 const HS_SILPH_CO_10F_ITEM_3 ; BA const HS_SILPH_CO_11F_1 ; BB const HS_SILPH_CO_11F_JAMES ; BC const HS_SILPH_CO_11F_2 ; BD const HS_SILPH_CO_11F_JESSIE ; BE const HS_MAP_F4_1 ; BF const HS_MANSION_2_ITEM ; C0 const HS_MANSION_3_ITEM_1 ; C1 const HS_MANSION_3_ITEM_2 ; C2 const HS_MANSION_4_ITEM_1 ; C3 const HS_MANSION_4_ITEM_2 ; C4 const HS_MANSION_4_ITEM_3 ; C5 const HS_MANSION_4_ITEM_4 ; C6 const HS_MANSION_4_ITEM_5 ; C7 const HS_SAFARI_ZONE_EAST_ITEM_1 ; C8 const HS_SAFARI_ZONE_EAST_ITEM_2 ; C9 const HS_SAFARI_ZONE_EAST_ITEM_3 ; CA const HS_SAFARI_ZONE_EAST_ITEM_4 ; CB const HS_SAFARI_ZONE_NORTH_ITEM_1 ; CC const HS_SAFARI_ZONE_NORTH_ITEM_2 ; CD const HS_SAFARI_ZONE_WEST_ITEM_1 ; CE const HS_SAFARI_ZONE_WEST_ITEM_2 ; CF const HS_SAFARI_ZONE_WEST_ITEM_3 ; D0 const HS_SAFARI_ZONE_WEST_ITEM_4 ; D1 const HS_SAFARI_ZONE_CENTER_ITEM ; D2 const HS_UNKNOWN_DUNGEON_2_ITEM_1 ; D3 const HS_UNKNOWN_DUNGEON_2_ITEM_2 ; D4 const HS_UNKNOWN_DUNGEON_2_ITEM_3 ; D5 const HS_UNKNOWN_DUNGEON_2_ITEM_4 ; D6 const HS_MEWTWO ; D7 const HS_UNKNOWN_DUNGEON_3_ITEM_1 ; D8 const HS_UNKNOWN_DUNGEON_3_ITEM_2 ; D9 const HS_UNKNOWN_DUNGEON_3_ITEM_3 ; DA const HS_UNKNOWN_DUNGEON_3_ITEM_4 ; DB const HS_VICTORY_ROAD_1_ITEM_1 ; DC const HS_VICTORY_ROAD_1_ITEM_2 ; DD const HS_CHAMPIONS_ROOM_OAK ; DE const HS_SEAFOAM_ISLANDS_1_BOULDER_1 ; DF const HS_SEAFOAM_ISLANDS_1_BOULDER_2 ; E0 const HS_SEAFOAM_ISLANDS_2_BOULDER_1 ; E1 const HS_SEAFOAM_ISLANDS_2_BOULDER_2 ; E2 const HS_SEAFOAM_ISLANDS_3_BOULDER_1 ; E3 const HS_SEAFOAM_ISLANDS_3_BOULDER_2 ; E4 const HS_SEAFOAM_ISLANDS_4_BOULDER_1 ; E5 const HS_SEAFOAM_ISLANDS_4_BOULDER_2 ; E6 const HS_SEAFOAM_ISLANDS_4_BOULDER_3 ; E7 const HS_SEAFOAM_ISLANDS_4_BOULDER_4 ; E8 const HS_SEAFOAM_ISLANDS_5_BOULDER_1 ; E9 const HS_SEAFOAM_ISLANDS_5_BOULDER_2 ; EA const HS_ARTICUNO const HS_UNUSED const HS_UNUSED2 const HS_TOWN_MAP_COPY ; EB const HS_MEOWTH ; EC const HS_MART_JESSIE ; ED const HS_MART_JAMES ; EE
#include "Engine.h" #include <regression/tframe.h> #include <spine/Options.h> #include <spine/Reactor.h> using namespace std; SmartMet::Engine::Authentication::Engine *authengine; std::string apikey = "testkey"; std::string apikey2 = "testkey2"; std::string apikey_wildcard = "testkey_wildcard"; namespace Tests { // ---------------------------------------------------------------------- void access_single() { bool has_access; has_access = authengine->authorize(apikey, "value1", "testservice"); if (!has_access) TEST_FAILED("No access to 'value1' token value"); has_access = authengine->authorize(apikey, "value2", "testservice"); if (!has_access) TEST_FAILED("No access to 'value2' token value"); has_access = authengine->authorize(apikey, "value3", "testservice"); if (!has_access) TEST_FAILED("No access to 'value3' token value"); has_access = authengine->authorize(apikey2, "value3", "testservice"); if (!has_access) TEST_FAILED("No access to 'value3' token value"); has_access = authengine->authorize(apikey2, "value1", "testservice2"); if (!has_access) TEST_FAILED("No access to 'value1' token value for 'testservice2'"); has_access = authengine->authorize(apikey2, "value1", "testservice"); if (has_access) TEST_FAILED("Incorrectly granted access to 'value1' token value"); has_access = authengine->authorize(apikey2, "value2", "testservice2"); if (has_access) TEST_FAILED("Incorrectly granted access to 'value1' token value"); TEST_PASSED(); } void access_wildcard() { std::vector<std::string> values = {"value1", "value2", "value3"}; bool has_access; for (const auto &value : values) { has_access = authengine->authorize(apikey_wildcard, value, "testservice"); if (!has_access) TEST_FAILED("No access with wildcard apikey to value '" + value + "'"); } has_access = authengine->authorize(apikey_wildcard, values, "testservice"); if (!has_access) TEST_FAILED("No access with wildcard apikey to valueset 'value1,value2,value3'"); TEST_PASSED(); } void access_multiple() { std::vector<std::string> values = {"value1", "value2", "value3"}; bool has_access; has_access = authengine->authorize(apikey, values, "testservice"); if (!has_access) TEST_FAILED("No access to valueset 'value1,value2,value3'"); has_access = authengine->authorize(apikey2, values, "testservice"); if (has_access) TEST_FAILED("Incorrectly granted access to valueset 'value1,value2,value3'"); TEST_PASSED(); } void unknown_apikey() { bool has_access; has_access = authengine->authorize("foobar", "value1", "testservice"); if (has_access) TEST_FAILED("Unknown 'foobar_apikey' should not have access (default policy is DENY)"); TEST_PASSED(); } void access_denied() { std::vector<std::string> values = {"value1", "value2", "value4"}; // value4 not found in tokens bool has_access; has_access = authengine->authorize(apikey, values, "testservice"); if (has_access) TEST_FAILED("Incorrectly has access to 'value4' token value"); has_access = authengine->authorize(apikey, "value4", "testservice"); if (has_access) TEST_FAILED("Incorrectly has access to 'value4' token value"); has_access = authengine->authorize(apikey, "value1", "nonexistent_service"); if (!has_access) TEST_FAILED("Incorrectly no access to 'nonexistent_service' service"); TEST_PASSED(); } // Test driver class tests : public tframe::tests { // Overridden message separator virtual const char *error_message_prefix() const { return "\n\t"; } // Main test suite void test() { TEST(access_single); TEST(access_multiple); TEST(access_denied); TEST(access_wildcard); TEST(unknown_apikey); } }; // class tests } // namespace Tests int main(void) { SmartMet::Spine::Options opts; opts.configfile = "cnf/reactor.conf"; opts.parseConfig(); SmartMet::Spine::Reactor reactor(opts); reactor.init(); authengine = reinterpret_cast<SmartMet::Engine::Authentication::Engine *>( reactor.getSingleton("Authentication", NULL)); cout << endl << "Engine tester" << endl << "=============" << endl; Tests::tests t; return t.run(); }
/** * * Author: Juarez Paulino(coderemite) * Email: juarez.paulino@gmail.com * */ #include <cstdio> #include <cstdlib> #include <cctype> #include <algorithm> #include <iostream> using namespace std; bool is_vowel(char c) { c = tolower(c); return c=='a'||c=='e'||c=='i'||c=='o'||c=='u'; } int main() { int N; scanf("%d", &N); while (N--) { string a, b; cin >> a >> b; if (a.size() != b.size()) { puts("No"); continue; } bool ok = 1; for (int i = 0; i < a.size() && ok; i++) { if (is_vowel(a[i])) { if (!is_vowel(b[i])) ok = 0; } else if (a[i] != b[i]) ok = 0; } if (ok) puts("Yes"); else puts("No"); } return 0; }
#include "include/MMVII_all.h" #include "include/MMVII_2Include_Serial_Tpl.h" #include "LearnDM.h" //#include "include/MMVII_Tpl_Images.h" namespace MMVII { class cAppliCalcHistoCarac : public cAppliLearningMatch { public : cAppliCalcHistoCarac(const std::vector<std::string> & aVArgs,const cSpecMMVII_Appli & aSpec); private : int Exe() override; cCollecSpecArg2007 & ArgObl(cCollecSpecArg2007 & anArgObl) override ; cCollecSpecArg2007 & ArgOpt(cCollecSpecArg2007 & anArgOpt) override ; void AddOneFile(const std::string&,int aKFile,int aNbFile); // -- Mandatory args ---- std::string mPatHom0; std::string mNameResult; // -- Optionnal args ---- std::string mPatShowSep; bool mWithCr; // -- Internal variables ---- cStatAllVecCarac* mStats; }; cAppliCalcHistoCarac::cAppliCalcHistoCarac(const std::vector<std::string> & aVArgs,const cSpecMMVII_Appli & aSpec) : cAppliLearningMatch (aVArgs,aSpec), mWithCr (true), mStats (nullptr) { } cCollecSpecArg2007 & cAppliCalcHistoCarac::ArgObl(cCollecSpecArg2007 & anArgObl) { return anArgObl << Arg2007(mPatHom0,"Name of input(s) file(s)",{{eTA2007::MPatFile,"0"}}) << Arg2007(mNameResult,"Name used for results") ; } cCollecSpecArg2007 & cAppliCalcHistoCarac::ArgOpt(cCollecSpecArg2007 & anArgOpt) { return anArgOpt << AOpt2007(mPatShowSep, "ShowSep","Pattern for show separation") /* << AOpt2007(mSzTile, "TileSz","Size of tile for spliting computation",{eTA2007::HDV}) << AOpt2007(mOverlap,"TileOL","Overlap of tile to limit sides effects",{eTA2007::HDV}) << AOpt2007(mPatShowCarac,"PSC","Pattern for Showing Caracteristics") << AOpt2007(mNb2Select,"Nb2S","Number of point to select, def=all in masq") << AOpt2007(mSaveImFilter,"SIF","Save Image Filter",{eTA2007::HDV,eTA2007::Tuning}) << AOpt2007(mFlagRand,"FlagRand","Images to randomizes, bit of flag [0-3]",{eTA2007::HDV,eTA2007::Tuning}) // << AOpt2007(mSaveImFilter,"SIF","Save Image Filter",{eTA2007::HDV}) */ ; } void cAppliCalcHistoCarac::AddOneFile(const std::string& aStr0,int aKFile,int aNbFile) { StdOut() << "****** " << aStr0 << " : " << aKFile << "/" << aNbFile << " *******\n"; cFileVecCaracMatch aFCV0(HomFromHom0(aStr0,0)); mStats->AddOneFile(0,aFCV0); StdOut() << " -------------------------------\n"; cFileVecCaracMatch aFCV1(HomFromHom0(aStr0,1)); mStats->AddOneFile(1,aFCV1); StdOut() << " -------------------------------\n"; cFileVecCaracMatch aFCV2(HomFromHom0(aStr0,2)); mStats->AddOneFile(2,aFCV2); StdOut() << " -------------------------------\n"; if (mWithCr) { mStats->AddCr(aFCV0,aFCV1,true); mStats->AddCr(aFCV0,aFCV2,false); StdOut() << " ------------ DONE CR-------------------\n"; } if (IsInit(&mPatShowSep)) { mStats->ShowSepar(mPatShowSep,StdOut()); } } int cAppliCalcHistoCarac::Exe() { SetNamesProject("",mNameResult); CreateDirectories(DirVisu(),true); CreateDirectories(DirResult(),true); mStats = new cStatAllVecCarac(mWithCr); int aKFile=0; int aNbFile = MainSet0().size(); for (const auto & aStr : ToVect(MainSet0())) { AddOneFile(aStr,aKFile,aNbFile); aKFile++; } mStats->SaveHisto(250,DirVisu()); if (mWithCr) { mStats->SaveCr(10,DirVisu()); } mStats->MakeCumul(); { cMultipleOfs aMulOfs(NameReport()); aMulOfs << "COM=[" << Command() << "]\n\n"; mStats->ShowSepar(".*",aMulOfs); } mStats->PackForSave(); SaveInFile(*mStats,FileHisto1Carac(false)); delete mStats; return EXIT_SUCCESS; } /* =============================================== */ /* */ /* :: */ /* */ /* =============================================== */ tMMVII_UnikPApli Alloc_CalcHistoCarac(const std::vector<std::string> & aVArgs,const cSpecMMVII_Appli & aSpec) { return tMMVII_UnikPApli(new cAppliCalcHistoCarac(aVArgs,aSpec)); } cSpecMMVII_Appli TheSpecCalcHistoCarac ( "DM2CalcHistoCarac", Alloc_CalcHistoCarac, "Compute and save histogramm on single caracteristics", {eApF::Match}, {eApDT::FileSys}, {eApDT::FileSys}, __FILE__ ); };
; ; New stdio functions for Small C+ ; ; gets(char *s) - get string from console ; ; ; $Id: gets.asm,v 1.8 2015/01/19 01:33:20 pauloscustodio Exp $ ; PUBLIC gets EXTERN fgetc_cons EXTERN fputc_cons DEFINE EMULATECURSOR ; Enter in with hl holding the address of string to print .gets ; we don't __FASTCALL__, z88 version of gets needs parameters pop bc pop hl push hl push bc ld d,h ; keep the start of buffer ld e,l IF EMULATECURSOR call cursor ENDIF .getloop push de push hl ; preserve buffer location call fgetc_cons ld a,l pop hl pop de and a jr z,getloop cp 8 jr z,bs cp 12 jr nz,nobs .bs push hl and a sbc hl,de pop hl jr z,getloop dec hl IF EMULATECURSOR .dobs call wipecursor ; ' ' + BS ld a,8 call conout call wipecursor ; ' ' + BS call cursor ELSE ld a,8 call conout ld a,' ' call conout ld a,8 call conout ENDIF jr getloop .nobs cp 12 jr z,getloop cp 13 jr z,getend ld (hl),a inc hl call conout IF EMULATECURSOR call cursor ENDIF jr getloop .getend IF EMULATECURSOR call wipecursor ENDIF xor a ld (hl),a ld a,13 ; end with CR call conout ld h,d ; set ptr to string ld l,e ret .conout push hl push de ld c,a push bc call fputc_cons pop bc pop de pop hl ret IF EMULATECURSOR .wipecursor ld a,' ' jr cursor+2 .cursor ld a,'_' call conout .chr8 ld a,8 call conout ret ENDIF
// Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #if defined(HAVE_CONFIG_H) #include "config/bitcoin-config.h" #endif #include "init.h" #include "addrman.h" #include "amount.h" #include "checkpoints.h" #include "compat/sanity.h" #include "key.h" #include "main.h" #include "miner.h" #include "net.h" #include "rpcserver.h" #include "script/standard.h" #include "txdb.h" #include "ui_interface.h" #include "util.h" #include "utilmoneystr.h" #ifdef ENABLE_WALLET #include "db.h" #include "wallet.h" #include "walletdb.h" #endif #include <stdint.h> #include <stdio.h> #ifndef WIN32 #include <signal.h> #endif #include <boost/algorithm/string/predicate.hpp> #include <boost/algorithm/string/replace.hpp> #include <boost/filesystem.hpp> #include <boost/interprocess/sync/file_lock.hpp> #include <boost/thread.hpp> #include <openssl/crypto.h> using namespace boost; using namespace std; #ifdef ENABLE_WALLET CWallet* pwalletMain = NULL; #endif bool fFeeEstimatesInitialized = false; #ifdef WIN32 // Win32 LevelDB doesn't use filedescriptors, and the ones used for // accessing block files, don't count towards to fd_set size limit // anyway. #define MIN_CORE_FILEDESCRIPTORS 0 #else #define MIN_CORE_FILEDESCRIPTORS 150 #endif /** Used to pass flags to the Bind() function */ enum BindFlags { BF_NONE = 0, BF_EXPLICIT = (1U << 0), BF_REPORT_ERROR = (1U << 1), BF_WHITELIST = (1U << 2), }; static const char* FEE_ESTIMATES_FILENAME="fee_estimates.dat"; CClientUIInterface uiInterface; ////////////////////////////////////////////////////////////////////////////// // // Shutdown // // // Thread management and startup/shutdown: // // The network-processing threads are all part of a thread group // created by AppInit() or the Qt main() function. // // A clean exit happens when StartShutdown() or the SIGTERM // signal handler sets fRequestShutdown, which triggers // the DetectShutdownThread(), which interrupts the main thread group. // DetectShutdownThread() then exits, which causes AppInit() to // continue (it .joins the shutdown thread). // Shutdown() is then // called to clean up database connections, and stop other // threads that should only be stopped after the main network-processing // threads have exited. // // Note that if running -daemon the parent process returns from AppInit2 // before adding any threads to the threadGroup, so .join_all() returns // immediately and the parent exits from main(). // // Shutdown for Qt is very similar, only it uses a QTimer to detect // fRequestShutdown getting set, and then does the normal Qt // shutdown thing. // volatile bool fRequestShutdown = false; void StartShutdown() { fRequestShutdown = true; } bool ShutdownRequested() { return fRequestShutdown; } class CCoinsViewErrorCatcher : public CCoinsViewBacked { public: CCoinsViewErrorCatcher(CCoinsView* view) : CCoinsViewBacked(view) {} bool GetCoins(const uint256 &txid, CCoins &coins) const { try { return CCoinsViewBacked::GetCoins(txid, coins); } catch(const std::runtime_error& e) { uiInterface.ThreadSafeMessageBox(_("Error reading from database, shutting down."), "", CClientUIInterface::MSG_ERROR); LogPrintf("Error reading from database: %s\n", e.what()); // Starting the shutdown sequence and returning false to the caller would be // interpreted as 'entry not found' (as opposed to unable to read data), and // could lead to invalid interpration. Just exit immediately, as we can't // continue anyway, and all writes should be atomic. abort(); } } // Writes do not need similar protection, as failure to write is handled by the caller. }; static CCoinsViewDB *pcoinsdbview = NULL; static CCoinsViewErrorCatcher *pcoinscatcher = NULL; void Shutdown() { LogPrintf("%s: In progress...\n", __func__); static CCriticalSection cs_Shutdown; TRY_LOCK(cs_Shutdown, lockShutdown); if (!lockShutdown) return; /// Note: Shutdown() must be able to handle cases in which AppInit2() failed part of the way, /// for example if the data directory was found to be locked. /// Be sure that anything that writes files or flushes caches only does this if the respective /// module was initialized. RenameThread("veroclassic-shutoff"); mempool.AddTransactionsUpdated(1); StopRPCThreads(); #ifdef ENABLE_WALLET if (pwalletMain) bitdb.Flush(false); GenerateBitcoins(false, NULL, 0); #endif StopNode(); UnregisterNodeSignals(GetNodeSignals()); if (fFeeEstimatesInitialized) { boost::filesystem::path est_path = GetDataDir() / FEE_ESTIMATES_FILENAME; CAutoFile est_fileout(fopen(est_path.string().c_str(), "wb"), SER_DISK, CLIENT_VERSION); if (!est_fileout.IsNull()) mempool.WriteFeeEstimates(est_fileout); else LogPrintf("%s: Failed to write fee estimates to %s\n", __func__, est_path.string()); fFeeEstimatesInitialized = false; } { LOCK(cs_main); if (pcoinsTip != NULL) { FlushStateToDisk(); } delete pcoinsTip; pcoinsTip = NULL; delete pcoinscatcher; pcoinscatcher = NULL; delete pcoinsdbview; pcoinsdbview = NULL; delete pblocktree; pblocktree = NULL; } #ifdef ENABLE_WALLET if (pwalletMain) bitdb.Flush(true); #endif #ifndef WIN32 boost::filesystem::remove(GetPidFile()); #endif UnregisterAllValidationInterfaces(); #ifdef ENABLE_WALLET delete pwalletMain; pwalletMain = NULL; #endif LogPrintf("%s: done\n", __func__); } /** * Signal handlers are very limited in what they are allowed to do, so: */ void HandleSIGTERM(int) { fRequestShutdown = true; } void HandleSIGHUP(int) { fReopenDebugLog = true; } bool static InitError(const std::string &str) { uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_ERROR); return false; } bool static InitWarning(const std::string &str) { uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_WARNING); return true; } bool static Bind(const CService &addr, unsigned int flags) { if (!(flags & BF_EXPLICIT) && IsLimited(addr)) return false; std::string strError; if (!BindListenPort(addr, strError, (flags & BF_WHITELIST) != 0)) { if (flags & BF_REPORT_ERROR) return InitError(strError); return false; } return true; } std::string HelpMessage(HelpMessageMode mode) { // When adding new options to the categories, please keep and ensure alphabetical ordering. string strUsage = _("Options:") + "\n"; strUsage += " -? " + _("This help message") + "\n"; strUsage += " -alertnotify=<cmd> " + _("Execute command when a relevant alert is received or we see a really long fork (%s in cmd is replaced by message)") + "\n"; strUsage += " -alerts " + strprintf(_("Receive and display P2P network alerts (default: %u)"), DEFAULT_ALERTS); strUsage += " -blocknotify=<cmd> " + _("Execute command when the best block changes (%s in cmd is replaced by block hash)") + "\n"; strUsage += " -checkblocks=<n> " + strprintf(_("How many blocks to check at startup (default: %u, 0 = all)"), 288) + "\n"; strUsage += " -checklevel=<n> " + strprintf(_("How thorough the block verification of -checkblocks is (0-4, default: %u)"), 3) + "\n"; strUsage += " -conf=<file> " + strprintf(_("Specify configuration file (default: %s)"), "veroclassic.conf") + "\n"; if (mode == HMM_BITCOIND) { #if !defined(WIN32) strUsage += " -daemon " + _("Run in the background as a daemon and accept commands") + "\n"; #endif } strUsage += " -datadir=<dir> " + _("Specify data directory") + "\n"; strUsage += " -dbcache=<n> " + strprintf(_("Set database cache size in megabytes (%d to %d, default: %d)"), nMinDbCache, nMaxDbCache, nDefaultDbCache) + "\n"; strUsage += " -loadblock=<file> " + _("Imports blocks from external blk000??.dat file") + " " + _("on startup") + "\n"; strUsage += " -maxorphantx=<n> " + strprintf(_("Keep at most <n> unconnectable transactions in memory (default: %u)"), DEFAULT_MAX_ORPHAN_TRANSACTIONS) + "\n"; strUsage += " -par=<n> " + strprintf(_("Set the number of script verification threads (%u to %d, 0 = auto, <0 = leave that many cores free, default: %d)"), -(int)boost::thread::hardware_concurrency(), MAX_SCRIPTCHECK_THREADS, DEFAULT_SCRIPTCHECK_THREADS) + "\n"; #ifndef WIN32 strUsage += " -pid=<file> " + strprintf(_("Specify pid file (default: %s)"), "veroclassicd.pid") + "\n"; #endif strUsage += " -reindex " + _("Rebuild block chain index from current blk000??.dat files") + " " + _("on startup") + "\n"; #if !defined(WIN32) strUsage += " -sysperms " + _("Create new files with system default permissions, instead of umask 077 (only effective with disabled wallet functionality)") + "\n"; #endif strUsage += " -txindex " + strprintf(_("Maintain a full transaction index, used by the getrawtransaction rpc call (default: %u)"), 0) + "\n"; strUsage += "\n" + _("Connection options:") + "\n"; strUsage += " -addnode=<ip> " + _("Add a node to connect to and attempt to keep the connection open") + "\n"; strUsage += " -banscore=<n> " + strprintf(_("Threshold for disconnecting misbehaving peers (default: %u)"), 100) + "\n"; strUsage += " -bantime=<n> " + strprintf(_("Number of seconds to keep misbehaving peers from reconnecting (default: %u)"), 86400) + "\n"; strUsage += " -bind=<addr> " + _("Bind to given address and always listen on it. Use [host]:port notation for IPv6") + "\n"; strUsage += " -connect=<ip> " + _("Connect only to the specified node(s)") + "\n"; strUsage += " -discover " + _("Discover own IP address (default: 1 when listening and no -externalip)") + "\n"; strUsage += " -dns " + _("Allow DNS lookups for -addnode, -seednode and -connect") + " " + _("(default: 1)") + "\n"; strUsage += " -dnsseed " + _("Query for peer addresses via DNS lookup, if low on addresses (default: 1 unless -connect)") + "\n"; strUsage += " -externalip=<ip> " + _("Specify your own public address") + "\n"; strUsage += " -forcednsseed " + strprintf(_("Always query for peer addresses via DNS lookup (default: %u)"), 0) + "\n"; strUsage += " -listen " + _("Accept connections from outside (default: 1 if no -proxy or -connect)") + "\n"; strUsage += " -maxconnections=<n> " + strprintf(_("Maintain at most <n> connections to peers (default: %u)"), 125) + "\n"; strUsage += " -maxreceivebuffer=<n> " + strprintf(_("Maximum per-connection receive buffer, <n>*1000 bytes (default: %u)"), 5000) + "\n"; strUsage += " -maxsendbuffer=<n> " + strprintf(_("Maximum per-connection send buffer, <n>*1000 bytes (default: %u)"), 1000) + "\n"; strUsage += " -onion=<ip:port> " + strprintf(_("Use separate SOCKS5 proxy to reach peers via Tor hidden services (default: %s)"), "-proxy") + "\n"; strUsage += " -onlynet=<net> " + _("Only connect to nodes in network <net> (ipv4, ipv6 or onion)") + "\n"; strUsage += " -permitbaremultisig " + strprintf(_("Relay non-P2SH multisig (default: %u)"), 1) + "\n"; strUsage += " -port=<port> " + strprintf(_("Listen for connections on <port> (default: %u or testnet: %u)"), 35153, 45153) + "\n"; strUsage += " -proxy=<ip:port> " + _("Connect through SOCKS5 proxy") + "\n"; strUsage += " -seednode=<ip> " + _("Connect to a node to retrieve peer addresses, and disconnect") + "\n"; strUsage += " -timeout=<n> " + strprintf(_("Specify connection timeout in milliseconds (minimum: 1, default: %d)"), DEFAULT_CONNECT_TIMEOUT) + "\n"; #ifdef USE_UPNP #if USE_UPNP strUsage += " -upnp " + _("Use UPnP to map the listening port (default: 1 when listening)") + "\n"; #else strUsage += " -upnp " + strprintf(_("Use UPnP to map the listening port (default: %u)"), 0) + "\n"; #endif #endif strUsage += " -whitebind=<addr> " + _("Bind to given address and whitelist peers connecting to it. Use [host]:port notation for IPv6") + "\n"; strUsage += " -whitelist=<netmask> " + _("Whitelist peers connecting from the given netmask or IP address. Can be specified multiple times.") + "\n"; strUsage += " " + _("Whitelisted peers cannot be DoS banned and their transactions are always relayed, even if they are already in the mempool, useful e.g. for a gateway") + "\n"; #ifdef ENABLE_WALLET strUsage += "\n" + _("Wallet options:") + "\n"; strUsage += " -disablewallet " + _("Do not load the wallet and disable wallet RPC calls") + "\n"; strUsage += " -keypool=<n> " + strprintf(_("Set key pool size to <n> (default: %u)"), 100) + "\n"; if (GetBoolArg("-help-debug", false)) strUsage += " -mintxfee=<amt> " + strprintf(_("Fees (in VER/Kb) smaller than this are considered zero fee for transaction creation (default: %s)"), FormatMoney(CWallet::minTxFee.GetFeePerK())) + "\n"; strUsage += " -paytxfee=<amt> " + strprintf(_("Fee (in VER/kB) to add to transactions you send (default: %s)"), FormatMoney(payTxFee.GetFeePerK())) + "\n"; strUsage += " -mininput=<amt> " + _("Wallet ignores inputs with value less than this (default: 0.0001)") + "\n"; strUsage += " -rescan " + _("Rescan the block chain for missing wallet transactions") + " " + _("on startup") + "\n"; strUsage += " -salvagewallet " + _("Attempt to recover private keys from a corrupt wallet.dat") + " " + _("on startup") + "\n"; strUsage += " -sendfreetransactions " + strprintf(_("Send transactions as zero-fee transactions if possible (default: %u)"), 0) + "\n"; strUsage += " -spendzeroconfchange " + strprintf(_("Spend unconfirmed change when sending transactions (default: %u)"), 1) + "\n"; strUsage += " -txconfirmtarget=<n> " + strprintf(_("If paytxfee is not set, include enough fee so transactions begin confirmation on average within n blocks (default: %u)"), 1) + "\n"; strUsage += " -maxtxfee=<amt> " + strprintf(_("Maximum total fees to use in a single wallet transaction, setting too low may abort large transactions (default: %s)"), FormatMoney(maxTxFee)) + "\n"; strUsage += " -upgradewallet " + _("Upgrade wallet to latest format") + " " + _("on startup") + "\n"; strUsage += " -wallet=<file> " + _("Specify wallet file (within data directory)") + " " + strprintf(_("(default: %s)"), "wallet.dat") + "\n"; strUsage += " -walletnotify=<cmd> " + _("Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)") + "\n"; strUsage += " -zapwallettxes=<mode> " + _("Delete all wallet transactions and only recover those parts of the blockchain through -rescan on startup") + "\n"; strUsage += " " + _("(1 = keep tx meta data e.g. account owner and payment request information, 2 = drop tx meta data)") + "\n"; #endif strUsage += "\n" + _("Debugging/Testing options:") + "\n"; if (GetBoolArg("-help-debug", false)) { strUsage += " -checkpoints " + strprintf(_("Only accept block chain matching built-in checkpoints (default: %u)"), 1) + "\n"; strUsage += " -dblogsize=<n> " + strprintf(_("Flush database activity from memory pool to disk log every <n> megabytes (default: %u)"), 100) + "\n"; strUsage += " -disablesafemode " + strprintf(_("Disable safemode, override a real safe mode event (default: %u)"), 0) + "\n"; strUsage += " -testsafemode " + strprintf(_("Force safe mode (default: %u)"), 0) + "\n"; strUsage += " -dropmessagestest=<n> " + _("Randomly drop 1 of every <n> network messages") + "\n"; strUsage += " -fuzzmessagestest=<n> " + _("Randomly fuzz 1 of every <n> network messages") + "\n"; strUsage += " -flushwallet " + strprintf(_("Run a thread to flush wallet periodically (default: %u)"), 1) + "\n"; strUsage += " -stopafterblockimport " + strprintf(_("Stop running after importing blocks from disk (default: %u)"), 0) + "\n"; } strUsage += " -debug=<category> " + strprintf(_("Output debugging information (default: %u, supplying <category> is optional)"), 0) + "\n"; strUsage += " " + _("If <category> is not supplied, output all debugging information.") + "\n"; strUsage += " " + _("<category> can be:"); strUsage += " addrman, alert, bench, coindb, db, lock, rand, rpc, selectcoins, mempool, net"; // Don't translate these and qt below if (mode == HMM_BITCOIN_QT) strUsage += ", qt"; strUsage += ".\n"; #ifdef ENABLE_WALLET strUsage += " -gen " + strprintf(_("Generate coins (default: %u)"), 0) + "\n"; strUsage += " -genproclimit=<n> " + strprintf(_("Set the number of threads for coin generation if enabled (-1 = all cores, default: %d)"), 1) + "\n"; #endif strUsage += " -help-debug " + _("Show all debugging options (usage: --help -help-debug)") + "\n"; strUsage += " -logips " + strprintf(_("Include IP addresses in debug output (default: %u)"), 0) + "\n"; strUsage += " -logtimestamps " + strprintf(_("Prepend debug output with timestamp (default: %u)"), 1) + "\n"; if (GetBoolArg("-help-debug", false)) { strUsage += " -limitfreerelay=<n> " + strprintf(_("Continuously rate-limit free transactions to <n>*1000 bytes per minute (default:%u)"), 15) + "\n"; strUsage += " -relaypriority " + strprintf(_("Require high priority for relaying free or low-fee transactions (default:%u)"), 1) + "\n"; strUsage += " -maxsigcachesize=<n> " + strprintf(_("Limit size of signature cache to <n> entries (default: %u)"), 50000) + "\n"; } strUsage += " -minrelaytxfee=<amt> " + strprintf(_("Fees (in VER/Kb) smaller than this are considered zero fee for relaying (default: %s)"), FormatMoney(::minRelayTxFee.GetFeePerK())) + "\n"; strUsage += " -printtoconsole " + _("Send trace/debug info to console instead of debug.log file") + "\n"; if (GetBoolArg("-help-debug", false)) { strUsage += " -printpriority " + strprintf(_("Log transaction priority and fee per kB when mining blocks (default: %u)"), 0) + "\n"; strUsage += " -privdb " + strprintf(_("Sets the DB_PRIVATE flag in the wallet db environment (default: %u)"), 1) + "\n"; strUsage += " -regtest " + _("Enter regression test mode, which uses a special chain in which blocks can be solved instantly.") + "\n"; strUsage += " " + _("This is intended for regression testing tools and app development.") + "\n"; strUsage += " " + _("In this mode -genproclimit controls how many blocks are generated immediately.") + "\n"; } strUsage += " -shrinkdebugfile " + _("Shrink debug.log file on client startup (default: 1 when no -debug)") + "\n"; strUsage += " -testnet " + _("Use the test network") + "\n"; strUsage += "\n" + _("Node relay options:") + "\n"; strUsage += " -datacarrier " + strprintf(_("Relay and mine data carrier transactions (default: %u)"), 1) + "\n"; strUsage += " -datacarriersize " + strprintf(_("Maximum size of data in data carrier transactions we relay and mine (default: %u)"), MAX_OP_RETURN_RELAY) + "\n"; strUsage += "\n" + _("Block creation options:") + "\n"; strUsage += " -blockminsize=<n> " + strprintf(_("Set minimum block size in bytes (default: %u)"), 0) + "\n"; strUsage += " -blockmaxsize=<n> " + strprintf(_("Set maximum block size in bytes (default: %d)"), DEFAULT_BLOCK_MAX_SIZE) + "\n"; strUsage += " -blockprioritysize=<n> " + strprintf(_("Set maximum size of high-priority/low-fee transactions in bytes (default: %d)"), DEFAULT_BLOCK_PRIORITY_SIZE) + "\n"; strUsage += "\n" + _("RPC server options:") + "\n"; strUsage += " -server " + _("Accept command line and JSON-RPC commands") + "\n"; strUsage += " -rest " + strprintf(_("Accept public REST requests (default: %u)"), 0) + "\n"; strUsage += " -rpcbind=<addr> " + _("Bind to given address to listen for JSON-RPC connections. Use [host]:port notation for IPv6. This option can be specified multiple times (default: bind to all interfaces)") + "\n"; strUsage += " -rpcuser=<user> " + _("Username for JSON-RPC connections") + "\n"; strUsage += " -rpcpassword=<pw> " + _("Password for JSON-RPC connections") + "\n"; strUsage += " -rpcport=<port> " + strprintf(_("Listen for JSON-RPC connections on <port> (default: %u or testnet: %u)"), 8332, 18332) + "\n"; strUsage += " -rpcallowip=<ip> " + _("Allow JSON-RPC connections from specified source. Valid for <ip> are a single IP (e.g. 1.2.3.4), a network/netmask (e.g. 1.2.3.4/255.255.255.0) or a network/CIDR (e.g. 1.2.3.4/24). This option can be specified multiple times") + "\n"; strUsage += " -rpcthreads=<n> " + strprintf(_("Set the number of threads to service RPC calls (default: %d)"), 4) + "\n"; strUsage += " -rpckeepalive " + strprintf(_("RPC support for HTTP persistent connections (default: %d)"), 0) + "\n"; strUsage += "\n" + _("RPC SSL options: (see the Veroclassic Wiki for SSL setup instructions)") + "\n"; strUsage += " -rpcssl " + _("Use OpenSSL (https) for JSON-RPC connections") + "\n"; strUsage += " -rpcsslcertificatechainfile=<file.cert> " + strprintf(_("Server certificate file (default: %s)"), "server.cert") + "\n"; strUsage += " -rpcsslprivatekeyfile=<file.pem> " + strprintf(_("Server private key (default: %s)"), "server.pem") + "\n"; strUsage += " -rpcsslciphers=<ciphers> " + strprintf(_("Acceptable ciphers (default: %s)"), "TLSv1.2+HIGH:TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!3DES:@STRENGTH") + "\n"; return strUsage; } std::string LicenseInfo() { // return FormatParagraph(strprintf(_("Copyright (C) 2009-%i The Bitcoin Core Developers"), COPYRIGHT_YEAR)) + "\n" + // "\n" + // FormatParagraph(strprintf(_("Copyright (C) 2011-%i The Veroclassic Core Developers"), COPYRIGHT_YEAR)) + "\n" + // "\n" + // FormatParagraph(_("This is experimental software.")) + "\n" + // "\n" + // FormatParagraph(_("Distributed under the MIT software license, see the accompanying file COPYING or <http://www.opensource.org/licenses/mit-license.php>.")) + "\n" + // "\n" + // FormatParagraph(_("This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit <https://www.openssl.org/> and cryptographic software written by Eric Young and UPnP software written by Thomas Bernard.")) + // "\n"; return FormatParagraph(strprintf(_("Copyright (C) %i The Veroclassic Core Developers"), COPYRIGHT_YEAR)); } static void BlockNotifyCallback(const uint256& hashNewTip) { std::string strCmd = GetArg("-blocknotify", ""); boost::replace_all(strCmd, "%s", hashNewTip.GetHex()); boost::thread t(runCommand, strCmd); // thread runs free } struct CImportingNow { CImportingNow() { assert(fImporting == false); fImporting = true; } ~CImportingNow() { assert(fImporting == true); fImporting = false; } }; void ThreadImport(std::vector<boost::filesystem::path> vImportFiles) { RenameThread("veroclassic-loadblk"); // -reindex if (fReindex) { CImportingNow imp; int nFile = 0; while (true) { CDiskBlockPos pos(nFile, 0); if (!boost::filesystem::exists(GetBlockPosFilename(pos, "blk"))) break; // No block files left to reindex FILE *file = OpenBlockFile(pos, true); if (!file) break; // This error is logged in OpenBlockFile LogPrintf("Reindexing block file blk%05u.dat...\n", (unsigned int)nFile); LoadExternalBlockFile(file, &pos); nFile++; } pblocktree->WriteReindexing(false); fReindex = false; LogPrintf("Reindexing finished\n"); // To avoid ending up in a situation without genesis block, re-try initializing (no-op if reindexing worked): InitBlockIndex(); } // hardcoded $DATADIR/bootstrap.dat filesystem::path pathBootstrap = GetDataDir() / "bootstrap.dat"; if (filesystem::exists(pathBootstrap)) { FILE *file = fopen(pathBootstrap.string().c_str(), "rb"); if (file) { CImportingNow imp; filesystem::path pathBootstrapOld = GetDataDir() / "bootstrap.dat.old"; LogPrintf("Importing bootstrap.dat...\n"); LoadExternalBlockFile(file); RenameOver(pathBootstrap, pathBootstrapOld); } else { LogPrintf("Warning: Could not open bootstrap file %s\n", pathBootstrap.string()); } } // -loadblock= BOOST_FOREACH(boost::filesystem::path &path, vImportFiles) { FILE *file = fopen(path.string().c_str(), "rb"); if (file) { CImportingNow imp; LogPrintf("Importing blocks file %s...\n", path.string()); LoadExternalBlockFile(file); } else { LogPrintf("Warning: Could not open blocks file %s\n", path.string()); } } if (GetBoolArg("-stopafterblockimport", false)) { LogPrintf("Stopping after block import\n"); StartShutdown(); } } /** Sanity checks * Ensure that Bitcoin is running in a usable environment with all * necessary library support. */ bool InitSanityCheck(void) { if(!ECC_InitSanityCheck()) { InitError("OpenSSL appears to lack support for elliptic curve cryptography. For more " "information, visit https://en.bitcoin.it/wiki/OpenSSL_and_EC_Libraries"); return false; } if (!glibc_sanity_test() || !glibcxx_sanity_test()) return false; return true; } /** Initialize bitcoin. * @pre Parameters should be parsed and config file should be read. */ bool AppInit2(boost::thread_group& threadGroup) { // ********************************************************* Step 1: setup #ifdef _MSC_VER // Turn off Microsoft heap dump noise _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); _CrtSetReportFile(_CRT_WARN, CreateFileA("NUL", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0)); #endif #if _MSC_VER >= 1400 // Disable confusing "helpful" text message on abort, Ctrl-C _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT); #endif #ifdef WIN32 // Enable Data Execution Prevention (DEP) // Minimum supported OS versions: WinXP SP3, WinVista >= SP1, Win Server 2008 // A failure is non-critical and needs no further attention! #ifndef PROCESS_DEP_ENABLE // We define this here, because GCCs winbase.h limits this to _WIN32_WINNT >= 0x0601 (Windows 7), // which is not correct. Can be removed, when GCCs winbase.h is fixed! #define PROCESS_DEP_ENABLE 0x00000001 #endif typedef BOOL (WINAPI *PSETPROCDEPPOL)(DWORD); PSETPROCDEPPOL setProcDEPPol = (PSETPROCDEPPOL)GetProcAddress(GetModuleHandleA("Kernel32.dll"), "SetProcessDEPPolicy"); if (setProcDEPPol != NULL) setProcDEPPol(PROCESS_DEP_ENABLE); // Initialize Windows Sockets WSADATA wsadata; int ret = WSAStartup(MAKEWORD(2,2), &wsadata); if (ret != NO_ERROR || LOBYTE(wsadata.wVersion ) != 2 || HIBYTE(wsadata.wVersion) != 2) { return InitError(strprintf("Error: Winsock library failed to start (WSAStartup returned error %d)", ret)); } #endif #ifndef WIN32 if (GetBoolArg("-sysperms", false)) { #ifdef ENABLE_WALLET if (!GetBoolArg("-disablewallet", false)) return InitError("Error: -sysperms is not allowed in combination with enabled wallet functionality"); #endif } else { umask(077); } // Clean shutdown on SIGTERM struct sigaction sa; sa.sa_handler = HandleSIGTERM; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; sigaction(SIGTERM, &sa, NULL); sigaction(SIGINT, &sa, NULL); // Reopen debug.log on SIGHUP struct sigaction sa_hup; sa_hup.sa_handler = HandleSIGHUP; sigemptyset(&sa_hup.sa_mask); sa_hup.sa_flags = 0; sigaction(SIGHUP, &sa_hup, NULL); #if defined (__SVR4) && defined (__sun) // ignore SIGPIPE on Solaris signal(SIGPIPE, SIG_IGN); #endif #endif // ********************************************************* Step 2: parameter interactions // Set this early so that parameter interactions go to console fPrintToConsole = GetBoolArg("-printtoconsole", false); fLogTimestamps = GetBoolArg("-logtimestamps", true); fLogIPs = GetBoolArg("-logips", false); if (mapArgs.count("-bind") || mapArgs.count("-whitebind")) { // when specifying an explicit binding address, you want to listen on it // even when -connect or -proxy is specified if (SoftSetBoolArg("-listen", true)) LogPrintf("AppInit2 : parameter interaction: -bind or -whitebind set -> setting -listen=1\n"); } if (mapArgs.count("-connect") && mapMultiArgs["-connect"].size() > 0) { // when only connecting to trusted nodes, do not seed via DNS, or listen by default if (SoftSetBoolArg("-dnsseed", false)) LogPrintf("AppInit2 : parameter interaction: -connect set -> setting -dnsseed=0\n"); if (SoftSetBoolArg("-listen", false)) LogPrintf("AppInit2 : parameter interaction: -connect set -> setting -listen=0\n"); } if (mapArgs.count("-proxy")) { // to protect privacy, do not listen by default if a default proxy server is specified if (SoftSetBoolArg("-listen", false)) LogPrintf("%s: parameter interaction: -proxy set -> setting -listen=0\n", __func__); // to protect privacy, do not use UPNP when a proxy is set. The user may still specify -listen=1 // to listen locally, so don't rely on this happening through -listen below. if (SoftSetBoolArg("-upnp", false)) LogPrintf("%s: parameter interaction: -proxy set -> setting -upnp=0\n", __func__); // to protect privacy, do not discover addresses by default if (SoftSetBoolArg("-discover", false)) LogPrintf("AppInit2 : parameter interaction: -proxy set -> setting -discover=0\n"); } if (!GetBoolArg("-listen", true)) { // do not map ports or try to retrieve public IP when not listening (pointless) if (SoftSetBoolArg("-upnp", false)) LogPrintf("AppInit2 : parameter interaction: -listen=0 -> setting -upnp=0\n"); if (SoftSetBoolArg("-discover", false)) LogPrintf("AppInit2 : parameter interaction: -listen=0 -> setting -discover=0\n"); } if (mapArgs.count("-externalip")) { // if an explicit public IP is specified, do not try to find others if (SoftSetBoolArg("-discover", false)) LogPrintf("AppInit2 : parameter interaction: -externalip set -> setting -discover=0\n"); } if (GetBoolArg("-salvagewallet", false)) { // Rewrite just private keys: rescan to find transactions if (SoftSetBoolArg("-rescan", true)) LogPrintf("AppInit2 : parameter interaction: -salvagewallet=1 -> setting -rescan=1\n"); } // -zapwallettx implies a rescan if (GetBoolArg("-zapwallettxes", false)) { if (SoftSetBoolArg("-rescan", true)) LogPrintf("AppInit2 : parameter interaction: -zapwallettxes=<mode> -> setting -rescan=1\n"); } // Make sure enough file descriptors are available int nBind = std::max((int)mapArgs.count("-bind") + (int)mapArgs.count("-whitebind"), 1); nMaxConnections = GetArg("-maxconnections", 125); nMaxConnections = std::max(std::min(nMaxConnections, (int)(FD_SETSIZE - nBind - MIN_CORE_FILEDESCRIPTORS)), 0); int nFD = RaiseFileDescriptorLimit(nMaxConnections + MIN_CORE_FILEDESCRIPTORS); if (nFD < MIN_CORE_FILEDESCRIPTORS) return InitError(_("Not enough file descriptors available.")); if (nFD - MIN_CORE_FILEDESCRIPTORS < nMaxConnections) nMaxConnections = nFD - MIN_CORE_FILEDESCRIPTORS; // ********************************************************* Step 3: parameter-to-internal-flags fDebug = !mapMultiArgs["-debug"].empty(); // Special-case: if -debug=0/-nodebug is set, turn off debugging messages const vector<string>& categories = mapMultiArgs["-debug"]; if (GetBoolArg("-nodebug", false) || find(categories.begin(), categories.end(), string("0")) != categories.end()) fDebug = false; // Check for -debugnet if (GetBoolArg("-debugnet", false)) InitWarning(_("Warning: Unsupported argument -debugnet ignored, use -debug=net.")); // Check for -socks - as this is a privacy risk to continue, exit here if (mapArgs.count("-socks")) return InitError(_("Error: Unsupported argument -socks found. Setting SOCKS version isn't possible anymore, only SOCKS5 proxies are supported.")); // Check for -tor - as this is a privacy risk to continue, exit here if (GetBoolArg("-tor", false)) return InitError(_("Error: Unsupported argument -tor found, use -onion.")); if (GetBoolArg("-benchmark", false)) InitWarning(_("Warning: Unsupported argument -benchmark ignored, use -debug=bench.")); // Checkmempool and checkblockindex default to true in regtest mode mempool.setSanityCheck(GetBoolArg("-checkmempool", Params().DefaultConsistencyChecks())); fCheckBlockIndex = GetBoolArg("-checkblockindex", Params().DefaultConsistencyChecks()); Checkpoints::fEnabled = GetBoolArg("-checkpoints", true); // -par=0 means autodetect, but nScriptCheckThreads==0 means no concurrency nScriptCheckThreads = GetArg("-par", DEFAULT_SCRIPTCHECK_THREADS); if (nScriptCheckThreads <= 0) nScriptCheckThreads += boost::thread::hardware_concurrency(); if (nScriptCheckThreads <= 1) nScriptCheckThreads = 0; else if (nScriptCheckThreads > MAX_SCRIPTCHECK_THREADS) nScriptCheckThreads = MAX_SCRIPTCHECK_THREADS; fServer = GetBoolArg("-server", false); #ifdef ENABLE_WALLET bool fDisableWallet = GetBoolArg("-disablewallet", false); #endif nConnectTimeout = GetArg("-timeout", DEFAULT_CONNECT_TIMEOUT); if (nConnectTimeout <= 0) nConnectTimeout = DEFAULT_CONNECT_TIMEOUT; // Fee-per-kilobyte amount considered the same as "free" // If you are mining, be careful setting this: // if you set it to zero then // a transaction spammer can cheaply fill blocks using // 1-satoshi-fee transactions. It should be set above the real // cost to you of processing a transaction. if (mapArgs.count("-minrelaytxfee")) { CAmount n = 0; if (ParseMoney(mapArgs["-minrelaytxfee"], n) && n > 0) ::minRelayTxFee = CFeeRate(n); else return InitError(strprintf(_("Invalid amount for -minrelaytxfee=<amount>: '%s'"), mapArgs["-minrelaytxfee"])); } #ifdef ENABLE_WALLET if (mapArgs.count("-mintxfee")) { CAmount n = 0; if (ParseMoney(mapArgs["-mintxfee"], n) && n > 0) CWallet::minTxFee = CFeeRate(n); else return InitError(strprintf(_("Invalid amount for -mintxfee=<amount>: '%s'"), mapArgs["-mintxfee"])); } if (mapArgs.count("-paytxfee")) { CAmount nFeePerK = 0; if (!ParseMoney(mapArgs["-paytxfee"], nFeePerK)) return InitError(strprintf(_("Invalid amount for -paytxfee=<amount>: '%s'"), mapArgs["-paytxfee"])); if (nFeePerK > nHighTransactionFeeWarning) InitWarning(_("Warning: -paytxfee is set very high! This is the transaction fee you will pay if you send a transaction.")); payTxFee = CFeeRate(nFeePerK, 1000); if (payTxFee < ::minRelayTxFee) { return InitError(strprintf(_("Invalid amount for -paytxfee=<amount>: '%s' (must be at least %s)"), mapArgs["-paytxfee"], ::minRelayTxFee.ToString())); } } if (mapArgs.count("-maxtxfee")) { CAmount nMaxFee = 0; if (!ParseMoney(mapArgs["-maxtxfee"], nMaxFee)) return InitError(strprintf(_("Invalid amount for -maxtxfee=<amount>: '%s'"), mapArgs["-maptxfee"])); if (nMaxFee > nHighTransactionMaxFeeWarning) InitWarning(_("Warning: -maxtxfee is set very high! Fees this large could be paid on a single transaction.")); maxTxFee = nMaxFee; if (CFeeRate(maxTxFee, 1000) < ::minRelayTxFee) { return InitError(strprintf(_("Invalid amount for -maxtxfee=<amount>: '%s' (must be at least the minrelay fee of %s to prevent stuck transactions)"), mapArgs["-maxtxfee"], ::minRelayTxFee.ToString())); } } nTxConfirmTarget = GetArg("-txconfirmtarget", 1); bSpendZeroConfChange = GetArg("-spendzeroconfchange", true); fSendFreeTransactions = GetArg("-sendfreetransactions", false); std::string strWalletFile = GetArg("-wallet", "wallet.dat"); if (mapArgs.count("-mininput")) { if (!ParseMoney(mapArgs["-mininput"], nMinimumInputThreshold)) return InitError(strprintf(_("Invalid amount for -mininput=<amount>: '%s'"), mapArgs["-mininput"])); } #endif // ENABLE_WALLET fIsBareMultisigStd = GetArg("-permitbaremultisig", true) != 0; nMaxDatacarrierBytes = GetArg("-datacarriersize", nMaxDatacarrierBytes); fAlerts = GetBoolArg("-alerts", DEFAULT_ALERTS); // ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log // Sanity check if (!InitSanityCheck()) return InitError(_("Initialization sanity check failed. Veroclassic Core is shutting down.")); std::string strDataDir = GetDataDir().string(); #ifdef ENABLE_WALLET // Wallet file must be a plain filename without a directory if (strWalletFile != boost::filesystem::basename(strWalletFile) + boost::filesystem::extension(strWalletFile)) return InitError(strprintf(_("Wallet %s resides outside data directory %s"), strWalletFile, strDataDir)); #endif // Make sure only a single Bitcoin process is using the data directory. boost::filesystem::path pathLockFile = GetDataDir() / ".lock"; FILE* file = fopen(pathLockFile.string().c_str(), "a"); // empty lock file; created if it doesn't exist. if (file) fclose(file); static boost::interprocess::file_lock lock(pathLockFile.string().c_str()); if (!lock.try_lock()) return InitError(strprintf(_("Cannot obtain a lock on data directory %s. Veroclassic Core is probably already running."), strDataDir)); #ifndef WIN32 CreatePidFile(GetPidFile(), getpid()); #endif if (GetBoolArg("-shrinkdebugfile", !fDebug)) ShrinkDebugFile(); LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); LogPrintf("Veroclassic version %s (%s)\n", FormatFullVersion(), CLIENT_DATE); LogPrintf("Using OpenSSL version %s\n", SSLeay_version(SSLEAY_VERSION)); #ifdef ENABLE_WALLET LogPrintf("Using BerkeleyDB version %s\n", DbEnv::version(0, 0, 0)); #endif if (!fLogTimestamps) LogPrintf("Startup time: %s\n", DateTimeStrFormat("%Y-%m-%d %H:%M:%S", GetTime())); LogPrintf("Default data directory %s\n", GetDefaultDataDir().string()); LogPrintf("Using data directory %s\n", strDataDir); LogPrintf("Using config file %s\n", GetConfigFile().string()); LogPrintf("Using at most %i connections (%i file descriptors available)\n", nMaxConnections, nFD); std::ostringstream strErrors; LogPrintf("Using %u threads for script verification\n", nScriptCheckThreads); if (nScriptCheckThreads) { for (int i=0; i<nScriptCheckThreads-1; i++) threadGroup.create_thread(&ThreadScriptCheck); } /* Start the RPC server already. It will be started in "warmup" mode * and not really process calls already (but it will signify connections * that the server is there and will be ready later). Warmup mode will * be disabled when initialisation is finished. */ if (fServer) { uiInterface.InitMessage.connect(SetRPCWarmupStatus); StartRPCThreads(); } int64_t nStart; #if defined(USE_SSE2) scrypt_detect_sse2(); #endif // ********************************************************* Step 5: verify wallet database integrity #ifdef ENABLE_WALLET if (!fDisableWallet) { LogPrintf("Using wallet %s\n", strWalletFile); uiInterface.InitMessage(_("Verifying wallet...")); if (!bitdb.Open(GetDataDir())) { // try moving the database env out of the way boost::filesystem::path pathDatabase = GetDataDir() / "database"; boost::filesystem::path pathDatabaseBak = GetDataDir() / strprintf("database.%d.bak", GetTime()); try { boost::filesystem::rename(pathDatabase, pathDatabaseBak); LogPrintf("Moved old %s to %s. Retrying.\n", pathDatabase.string(), pathDatabaseBak.string()); } catch(boost::filesystem::filesystem_error &error) { // failure is ok (well, not really, but it's not worse than what we started with) } // try again if (!bitdb.Open(GetDataDir())) { // if it still fails, it probably means we can't even create the database env string msg = strprintf(_("Error initializing wallet database environment %s!"), strDataDir); return InitError(msg); } } if (GetBoolArg("-salvagewallet", false)) { // Recover readable keypairs: if (!CWalletDB::Recover(bitdb, strWalletFile, true)) return false; } if (filesystem::exists(GetDataDir() / strWalletFile)) { CDBEnv::VerifyResult r = bitdb.Verify(strWalletFile, CWalletDB::Recover); if (r == CDBEnv::RECOVER_OK) { string msg = strprintf(_("Warning: wallet.dat corrupt, data salvaged!" " Original wallet.dat saved as wallet.{timestamp}.bak in %s; if" " your balance or transactions are incorrect you should" " restore from a backup."), strDataDir); InitWarning(msg); } if (r == CDBEnv::RECOVER_FAIL) return InitError(_("wallet.dat corrupt, salvage failed")); } } // (!fDisableWallet) #endif // ENABLE_WALLET // ********************************************************* Step 6: network initialization RegisterNodeSignals(GetNodeSignals()); if (mapArgs.count("-onlynet")) { std::set<enum Network> nets; BOOST_FOREACH(std::string snet, mapMultiArgs["-onlynet"]) { enum Network net = ParseNetwork(snet); if (net == NET_UNROUTABLE) return InitError(strprintf(_("Unknown network specified in -onlynet: '%s'"), snet)); nets.insert(net); } for (int n = 0; n < NET_MAX; n++) { enum Network net = (enum Network)n; if (!nets.count(net)) SetLimited(net); } } if (mapArgs.count("-whitelist")) { BOOST_FOREACH(const std::string& net, mapMultiArgs["-whitelist"]) { CSubNet subnet(net); if (!subnet.IsValid()) return InitError(strprintf(_("Invalid netmask specified in -whitelist: '%s'"), net)); CNode::AddWhitelistedRange(subnet); } } CService addrProxy; bool fProxy = false; if (mapArgs.count("-proxy")) { addrProxy = CService(mapArgs["-proxy"], 9050); if (!addrProxy.IsValid()) return InitError(strprintf(_("Invalid -proxy address: '%s'"), mapArgs["-proxy"])); SetProxy(NET_IPV4, addrProxy); SetProxy(NET_IPV6, addrProxy); SetNameProxy(addrProxy); fProxy = true; } // -onion can override normal proxy, -noonion disables tor entirely if (!(mapArgs.count("-onion") && mapArgs["-onion"] == "0") && (fProxy || mapArgs.count("-onion"))) { CService addrOnion; if (!mapArgs.count("-onion")) addrOnion = addrProxy; else addrOnion = CService(mapArgs["-onion"], 9050); if (!addrOnion.IsValid()) return InitError(strprintf(_("Invalid -onion address: '%s'"), mapArgs["-onion"])); SetProxy(NET_TOR, addrOnion); SetReachable(NET_TOR); } // see Step 2: parameter interactions for more information about these fListen = GetBoolArg("-listen", DEFAULT_LISTEN); fDiscover = GetBoolArg("-discover", true); fNameLookup = GetBoolArg("-dns", true); bool fBound = false; if (fListen) { if (mapArgs.count("-bind") || mapArgs.count("-whitebind")) { BOOST_FOREACH(std::string strBind, mapMultiArgs["-bind"]) { CService addrBind; if (!Lookup(strBind.c_str(), addrBind, GetListenPort(), false)) return InitError(strprintf(_("Cannot resolve -bind address: '%s'"), strBind)); fBound |= Bind(addrBind, (BF_EXPLICIT | BF_REPORT_ERROR)); } BOOST_FOREACH(std::string strBind, mapMultiArgs["-whitebind"]) { CService addrBind; if (!Lookup(strBind.c_str(), addrBind, 0, false)) return InitError(strprintf(_("Cannot resolve -whitebind address: '%s'"), strBind)); if (addrBind.GetPort() == 0) return InitError(strprintf(_("Need to specify a port with -whitebind: '%s'"), strBind)); fBound |= Bind(addrBind, (BF_EXPLICIT | BF_REPORT_ERROR | BF_WHITELIST)); } } else { struct in_addr inaddr_any; inaddr_any.s_addr = INADDR_ANY; fBound |= Bind(CService(in6addr_any, GetListenPort()), BF_NONE); fBound |= Bind(CService(inaddr_any, GetListenPort()), !fBound ? BF_REPORT_ERROR : BF_NONE); } if (!fBound) return InitError(_("Failed to listen on any port. Use -listen=0 if you want this.")); } if (mapArgs.count("-externalip")) { BOOST_FOREACH(string strAddr, mapMultiArgs["-externalip"]) { CService addrLocal(strAddr, GetListenPort(), fNameLookup); if (!addrLocal.IsValid()) return InitError(strprintf(_("Cannot resolve -externalip address: '%s'"), strAddr)); AddLocal(CService(strAddr, GetListenPort(), fNameLookup), LOCAL_MANUAL); } } BOOST_FOREACH(string strDest, mapMultiArgs["-seednode"]) AddOneShot(strDest); // ********************************************************* Step 7: load block chain fReindex = GetBoolArg("-reindex", false); // Upgrading to 0.8; hard-link the old blknnnn.dat files into /blocks/ filesystem::path blocksDir = GetDataDir() / "blocks"; if (!filesystem::exists(blocksDir)) { filesystem::create_directories(blocksDir); bool linked = false; for (unsigned int i = 1; i < 10000; i++) { filesystem::path source = GetDataDir() / strprintf("blk%04u.dat", i); if (!filesystem::exists(source)) break; filesystem::path dest = blocksDir / strprintf("blk%05u.dat", i-1); try { filesystem::create_hard_link(source, dest); LogPrintf("Hardlinked %s -> %s\n", source.string(), dest.string()); linked = true; } catch (filesystem::filesystem_error & e) { // Note: hardlink creation failing is not a disaster, it just means // blocks will get re-downloaded from peers. LogPrintf("Error hardlinking blk%04u.dat : %s\n", i, e.what()); break; } } if (linked) { fReindex = true; } } // cache size calculations size_t nTotalCache = (GetArg("-dbcache", nDefaultDbCache) << 20); if (nTotalCache < (nMinDbCache << 20)) nTotalCache = (nMinDbCache << 20); // total cache cannot be less than nMinDbCache else if (nTotalCache > (nMaxDbCache << 20)) nTotalCache = (nMaxDbCache << 20); // total cache cannot be greater than nMaxDbCache size_t nBlockTreeDBCache = nTotalCache / 8; if (nBlockTreeDBCache > (1 << 21) && !GetBoolArg("-txindex", false)) nBlockTreeDBCache = (1 << 21); // block tree db cache shouldn't be larger than 2 MiB nTotalCache -= nBlockTreeDBCache; size_t nCoinDBCache = nTotalCache / 2; // use half of the remaining cache for coindb cache nTotalCache -= nCoinDBCache; nCoinCacheSize = nTotalCache / 300; // coins in memory require around 300 bytes bool fLoaded = false; while (!fLoaded) { bool fReset = fReindex; std::string strLoadError; uiInterface.InitMessage(_("Loading block index...")); nStart = GetTimeMillis(); do { try { UnloadBlockIndex(); delete pcoinsTip; delete pcoinsdbview; delete pcoinscatcher; delete pblocktree; pblocktree = new CBlockTreeDB(nBlockTreeDBCache, false, fReindex); pcoinsdbview = new CCoinsViewDB(nCoinDBCache, false, fReindex); pcoinscatcher = new CCoinsViewErrorCatcher(pcoinsdbview); pcoinsTip = new CCoinsViewCache(pcoinscatcher); if (fReindex) pblocktree->WriteReindexing(true); if (!LoadBlockIndex()) { strLoadError = _("Error loading block database"); break; } // If the loaded chain has a wrong genesis, bail out immediately // (we're likely using a testnet datadir, or the other way around). if (!mapBlockIndex.empty() && mapBlockIndex.count(Params().HashGenesisBlock()) == 0) return InitError(_("Incorrect or no genesis block found. Wrong datadir for network?")); // Initialize the block index (no-op if non-empty database was already loaded) if (!InitBlockIndex()) { strLoadError = _("Error initializing block database"); break; } // Check for changed -txindex state if (fTxIndex != GetBoolArg("-txindex", false)) { strLoadError = _("You need to rebuild the database using -reindex to change -txindex"); break; } uiInterface.InitMessage(_("Verifying blocks...")); if (!CVerifyDB().VerifyDB(pcoinsdbview, GetArg("-checklevel", 3), GetArg("-checkblocks", 288))) { strLoadError = _("Corrupted block database detected"); break; } } catch(std::exception &e) { if (fDebug) LogPrintf("%s\n", e.what()); strLoadError = _("Error opening block database"); break; } fLoaded = true; } while(false); if (!fLoaded) { // first suggest a reindex if (!fReset) { bool fRet = uiInterface.ThreadSafeMessageBox( strLoadError + ".\n\n" + _("Do you want to rebuild the block database now?"), "", CClientUIInterface::MSG_ERROR | CClientUIInterface::BTN_ABORT); if (fRet) { fReindex = true; fRequestShutdown = false; } else { LogPrintf("Aborted block database rebuild. Exiting.\n"); return false; } } else { return InitError(strLoadError); } } } // As LoadBlockIndex can take several minutes, it's possible the user // requested to kill the GUI during the last operation. If so, exit. // As the program has not fully started yet, Shutdown() is possibly overkill. if (fRequestShutdown) { LogPrintf("Shutdown requested. Exiting.\n"); return false; } LogPrintf(" block index %15dms\n", GetTimeMillis() - nStart); boost::filesystem::path est_path = GetDataDir() / FEE_ESTIMATES_FILENAME; CAutoFile est_filein(fopen(est_path.string().c_str(), "rb"), SER_DISK, CLIENT_VERSION); // Allowed to fail as this file IS missing on first startup. if (!est_filein.IsNull()) mempool.ReadFeeEstimates(est_filein); fFeeEstimatesInitialized = true; // ********************************************************* Step 8: load wallet #ifdef ENABLE_WALLET if (fDisableWallet) { pwalletMain = NULL; LogPrintf("Wallet disabled!\n"); } else { // needed to restore wallet transaction meta data after -zapwallettxes std::vector<CWalletTx> vWtx; if (GetBoolArg("-zapwallettxes", false)) { uiInterface.InitMessage(_("Zapping all transactions from wallet...")); pwalletMain = new CWallet(strWalletFile); DBErrors nZapWalletRet = pwalletMain->ZapWalletTx(vWtx); if (nZapWalletRet != DB_LOAD_OK) { uiInterface.InitMessage(_("Error loading wallet.dat: Wallet corrupted")); return false; } delete pwalletMain; pwalletMain = NULL; } uiInterface.InitMessage(_("Loading wallet...")); nStart = GetTimeMillis(); bool fFirstRun = true; pwalletMain = new CWallet(strWalletFile); DBErrors nLoadWalletRet = pwalletMain->LoadWallet(fFirstRun); if (nLoadWalletRet != DB_LOAD_OK) { if (nLoadWalletRet == DB_CORRUPT) strErrors << _("Error loading wallet.dat: Wallet corrupted") << "\n"; else if (nLoadWalletRet == DB_NONCRITICAL_ERROR) { string msg(_("Warning: error reading wallet.dat! All keys read correctly, but transaction data" " or address book entries might be missing or incorrect.")); InitWarning(msg); } else if (nLoadWalletRet == DB_TOO_NEW) strErrors << _("Error loading wallet.dat: Wallet requires newer version of Veroclassic Core") << "\n"; else if (nLoadWalletRet == DB_NEED_REWRITE) { strErrors << _("Wallet needed to be rewritten: restart Veroclassic Core to complete") << "\n"; LogPrintf("%s", strErrors.str()); return InitError(strErrors.str()); } else strErrors << _("Error loading wallet.dat") << "\n"; } if (GetBoolArg("-upgradewallet", fFirstRun)) { int nMaxVersion = GetArg("-upgradewallet", 0); if (nMaxVersion == 0) // the -upgradewallet without argument case { LogPrintf("Performing wallet upgrade to %i\n", FEATURE_LATEST); nMaxVersion = CLIENT_VERSION; pwalletMain->SetMinVersion(FEATURE_LATEST); // permanently upgrade the wallet immediately } else LogPrintf("Allowing wallet upgrade up to %i\n", nMaxVersion); if (nMaxVersion < pwalletMain->GetVersion()) strErrors << _("Cannot downgrade wallet") << "\n"; pwalletMain->SetMaxVersion(nMaxVersion); } if (fFirstRun) { // Create new keyUser and set as default key RandAddSeedPerfmon(); CPubKey newDefaultKey; if (pwalletMain->GetKeyFromPool(newDefaultKey)) { pwalletMain->SetDefaultKey(newDefaultKey); if (!pwalletMain->SetAddressBook(pwalletMain->vchDefaultKey.GetID(), "", "receive")) strErrors << _("Cannot write default address") << "\n"; } pwalletMain->SetBestChain(chainActive.GetLocator()); } LogPrintf("%s", strErrors.str()); LogPrintf(" wallet %15dms\n", GetTimeMillis() - nStart); RegisterValidationInterface(pwalletMain); CBlockIndex *pindexRescan = chainActive.Tip(); if (GetBoolArg("-rescan", false)) pindexRescan = chainActive.Genesis(); else { CWalletDB walletdb(strWalletFile); CBlockLocator locator; if (walletdb.ReadBestBlock(locator)) pindexRescan = FindForkInGlobalIndex(chainActive, locator); else pindexRescan = chainActive.Genesis(); } if (chainActive.Tip() && chainActive.Tip() != pindexRescan) { uiInterface.InitMessage(_("Rescanning...")); LogPrintf("Rescanning last %i blocks (from block %i)...\n", chainActive.Height() - pindexRescan->nHeight, pindexRescan->nHeight); nStart = GetTimeMillis(); pwalletMain->ScanForWalletTransactions(pindexRescan, true); LogPrintf(" rescan %15dms\n", GetTimeMillis() - nStart); pwalletMain->SetBestChain(chainActive.GetLocator()); nWalletDBUpdated++; // Restore wallet transaction metadata after -zapwallettxes=1 if (GetBoolArg("-zapwallettxes", false) && GetArg("-zapwallettxes", "1") != "2") { BOOST_FOREACH(const CWalletTx& wtxOld, vWtx) { uint256 hash = wtxOld.GetHash(); std::map<uint256, CWalletTx>::iterator mi = pwalletMain->mapWallet.find(hash); if (mi != pwalletMain->mapWallet.end()) { const CWalletTx* copyFrom = &wtxOld; CWalletTx* copyTo = &mi->second; copyTo->mapValue = copyFrom->mapValue; copyTo->vOrderForm = copyFrom->vOrderForm; copyTo->nTimeReceived = copyFrom->nTimeReceived; copyTo->nTimeSmart = copyFrom->nTimeSmart; copyTo->fFromMe = copyFrom->fFromMe; copyTo->strFromAccount = copyFrom->strFromAccount; copyTo->nOrderPos = copyFrom->nOrderPos; copyTo->WriteToDisk(); } } } } } // (!fDisableWallet) #else // ENABLE_WALLET LogPrintf("No wallet compiled in!\n"); #endif // !ENABLE_WALLET // ********************************************************* Step 9: import blocks if (mapArgs.count("-blocknotify")) uiInterface.NotifyBlockTip.connect(BlockNotifyCallback); // scan for better chains in the block chain database, that are not yet connected in the active best chain CValidationState state; if (!ActivateBestChain(state)) strErrors << "Failed to connect best block"; std::vector<boost::filesystem::path> vImportFiles; if (mapArgs.count("-loadblock")) { BOOST_FOREACH(string strFile, mapMultiArgs["-loadblock"]) vImportFiles.push_back(strFile); } threadGroup.create_thread(boost::bind(&ThreadImport, vImportFiles)); if (chainActive.Tip() == NULL) { LogPrintf("Waiting for genesis block to be imported...\n"); while (!fRequestShutdown && chainActive.Tip() == NULL) MilliSleep(10); } // ********************************************************* Step 10: start node if (!CheckDiskSpace()) return false; if (!strErrors.str().empty()) return InitError(strErrors.str()); RandAddSeedPerfmon(); //// debug print LogPrintf("mapBlockIndex.size() = %u\n", mapBlockIndex.size()); LogPrintf("nBestHeight = %d\n", chainActive.Height()); #ifdef ENABLE_WALLET LogPrintf("setKeyPool.size() = %u\n", pwalletMain ? pwalletMain->setKeyPool.size() : 0); LogPrintf("mapWallet.size() = %u\n", pwalletMain ? pwalletMain->mapWallet.size() : 0); LogPrintf("mapAddressBook.size() = %u\n", pwalletMain ? pwalletMain->mapAddressBook.size() : 0); #endif StartNode(threadGroup); #ifdef ENABLE_WALLET // Generate coins in the background if (pwalletMain) GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain, GetArg("-genproclimit", 1)); #endif // ********************************************************* Step 11: finished SetRPCWarmupFinished(); uiInterface.InitMessage(_("Done loading")); #ifdef ENABLE_WALLET if (pwalletMain) { // Add wallet transactions that aren't already in a block to mapTransactions pwalletMain->ReacceptWalletTransactions(); // Run a thread to flush wallet periodically threadGroup.create_thread(boost::bind(&ThreadFlushWalletDB, boost::ref(pwalletMain->strWalletFile))); } #endif return !fRequestShutdown; }
; Listing generated by Microsoft (R) Optimizing Compiler Version 17.00.50727.1 include listing.inc INCLUDELIB LIBCMT INCLUDELIB OLDNAMES PUBLIC ?timer_head@@3PEAU_timer_@@EA ; timer_head PUBLIC ?timer_last@@3PEAU_timer_@@EA ; timer_last PUBLIC ?utimer_id@@3IA ; utimer_id _BSS SEGMENT ?timer_head@@3PEAU_timer_@@EA DQ 01H DUP (?) ; timer_head ?timer_last@@3PEAU_timer_@@EA DQ 01H DUP (?) ; timer_last ?utimer_id@@3IA DD 01H DUP (?) ; utimer_id _BSS ENDS PUBLIC ?create_timer@@YAHIG@Z ; create_timer PUBLIC ?destroy_timer@@YAXH@Z ; destroy_timer PUBLIC ?pause_timer@@YAXH@Z ; pause_timer PUBLIC ?start_timer@@YAXH@Z ; start_timer PUBLIC ?timer_fire@@YAXXZ ; timer_fire PUBLIC ?find_timer_id@@YAHG@Z ; find_timer_id PUBLIC ?timer_insert@@YAXPEAU_timer_@@@Z ; timer_insert PUBLIC ?timer_delete@@YAXPEAU_timer_@@@Z ; timer_delete EXTRN ?pmmngr_alloc@@YAPEAXXZ:PROC ; pmmngr_alloc EXTRN ?pmmngr_free@@YAXPEAX@Z:PROC ; pmmngr_free EXTRN x64_cli:PROC EXTRN ?post_box_put_msg@@YAXPEAU_post_box_message_@@G@Z:PROC ; post_box_put_msg pdata SEGMENT $pdata$?create_timer@@YAHIG@Z DD imagerel $LN3 DD imagerel $LN3+118 DD imagerel $unwind$?create_timer@@YAHIG@Z $pdata$?destroy_timer@@YAXH@Z DD imagerel $LN7 DD imagerel $LN7+87 DD imagerel $unwind$?destroy_timer@@YAXH@Z $pdata$?pause_timer@@YAXH@Z DD imagerel $LN7 DD imagerel $LN7+70 DD imagerel $unwind$?pause_timer@@YAXH@Z $pdata$?start_timer@@YAXH@Z DD imagerel $LN7 DD imagerel $LN7+70 DD imagerel $unwind$?start_timer@@YAXH@Z $pdata$?timer_fire@@YAXXZ DD imagerel $LN9 DD imagerel $LN9+166 DD imagerel $unwind$?timer_fire@@YAXXZ $pdata$?find_timer_id@@YAHG@Z DD imagerel $LN7 DD imagerel $LN7+81 DD imagerel $unwind$?find_timer_id@@YAHG@Z $pdata$?timer_delete@@YAXPEAU_timer_@@@Z DD imagerel $LN8 DD imagerel $LN8+146 DD imagerel $unwind$?timer_delete@@YAXPEAU_timer_@@@Z pdata ENDS xdata SEGMENT $unwind$?create_timer@@YAHIG@Z DD 010d01H DD 0620dH $unwind$?destroy_timer@@YAXH@Z DD 010801H DD 06208H $unwind$?pause_timer@@YAXH@Z DD 010801H DD 02208H $unwind$?start_timer@@YAXH@Z DD 010801H DD 02208H $unwind$?timer_fire@@YAXXZ DD 010401H DD 0a204H $unwind$?find_timer_id@@YAHG@Z DD 010901H DD 02209H $unwind$?timer_delete@@YAXPEAU_timer_@@@Z DD 010901H DD 04209H xdata ENDS ; Function compile flags: /Odtpy ; File e:\xeneva project\xeneva\aurora\aurora\timer.cpp _TEXT SEGMENT new_timer$ = 48 ?timer_delete@@YAXPEAU_timer_@@@Z PROC ; timer_delete ; 38 : void timer_delete (timer_t* new_timer) { $LN8: mov QWORD PTR [rsp+8], rcx sub rsp, 40 ; 00000028H ; 39 : ; 40 : if (timer_head == NULL) cmp QWORD PTR ?timer_head@@3PEAU_timer_@@EA, 0 ; timer_head jne SHORT $LN5@timer_dele ; 41 : return; jmp SHORT $LN6@timer_dele $LN5@timer_dele: ; 42 : ; 43 : if (new_timer == timer_head) { mov rax, QWORD PTR ?timer_head@@3PEAU_timer_@@EA ; timer_head cmp QWORD PTR new_timer$[rsp], rax jne SHORT $LN4@timer_dele ; 44 : timer_head = timer_head->next; mov rax, QWORD PTR ?timer_head@@3PEAU_timer_@@EA ; timer_head mov rax, QWORD PTR [rax+24] mov QWORD PTR ?timer_head@@3PEAU_timer_@@EA, rax ; timer_head ; 45 : } else { jmp SHORT $LN3@timer_dele $LN4@timer_dele: ; 46 : new_timer->prev->next = new_timer->next; mov rax, QWORD PTR new_timer$[rsp] mov rax, QWORD PTR [rax+32] mov rcx, QWORD PTR new_timer$[rsp] mov rcx, QWORD PTR [rcx+24] mov QWORD PTR [rax+24], rcx $LN3@timer_dele: ; 47 : } ; 48 : ; 49 : if (new_timer == timer_last) { mov rax, QWORD PTR ?timer_last@@3PEAU_timer_@@EA ; timer_last cmp QWORD PTR new_timer$[rsp], rax jne SHORT $LN2@timer_dele ; 50 : timer_last = new_timer->prev; mov rax, QWORD PTR new_timer$[rsp] mov rax, QWORD PTR [rax+32] mov QWORD PTR ?timer_last@@3PEAU_timer_@@EA, rax ; timer_last ; 51 : } else { jmp SHORT $LN1@timer_dele $LN2@timer_dele: ; 52 : new_timer->next->prev = new_timer->prev; mov rax, QWORD PTR new_timer$[rsp] mov rax, QWORD PTR [rax+24] mov rcx, QWORD PTR new_timer$[rsp] mov rcx, QWORD PTR [rcx+32] mov QWORD PTR [rax+32], rcx $LN1@timer_dele: ; 53 : } ; 54 : pmmngr_free(new_timer); mov rcx, QWORD PTR new_timer$[rsp] call ?pmmngr_free@@YAXPEAX@Z ; pmmngr_free $LN6@timer_dele: ; 55 : } add rsp, 40 ; 00000028H ret 0 ?timer_delete@@YAXPEAU_timer_@@@Z ENDP ; timer_delete _TEXT ENDS ; Function compile flags: /Odtpy ; File e:\xeneva project\xeneva\aurora\aurora\timer.cpp _TEXT SEGMENT new_timer$ = 8 ?timer_insert@@YAXPEAU_timer_@@@Z PROC ; timer_insert ; 23 : void timer_insert (timer_t* new_timer ) { mov QWORD PTR [rsp+8], rcx ; 24 : new_timer->next = NULL; mov rax, QWORD PTR new_timer$[rsp] mov QWORD PTR [rax+24], 0 ; 25 : new_timer->prev = NULL; mov rax, QWORD PTR new_timer$[rsp] mov QWORD PTR [rax+32], 0 ; 26 : ; 27 : if (timer_head == NULL) { cmp QWORD PTR ?timer_head@@3PEAU_timer_@@EA, 0 ; timer_head jne SHORT $LN2@timer_inse ; 28 : timer_last = new_timer; mov rax, QWORD PTR new_timer$[rsp] mov QWORD PTR ?timer_last@@3PEAU_timer_@@EA, rax ; timer_last ; 29 : timer_head = new_timer; mov rax, QWORD PTR new_timer$[rsp] mov QWORD PTR ?timer_head@@3PEAU_timer_@@EA, rax ; timer_head ; 30 : } else { jmp SHORT $LN1@timer_inse $LN2@timer_inse: ; 31 : timer_last->next = new_timer; mov rax, QWORD PTR ?timer_last@@3PEAU_timer_@@EA ; timer_last mov rcx, QWORD PTR new_timer$[rsp] mov QWORD PTR [rax+24], rcx ; 32 : new_timer->prev = timer_last; mov rax, QWORD PTR new_timer$[rsp] mov rcx, QWORD PTR ?timer_last@@3PEAU_timer_@@EA ; timer_last mov QWORD PTR [rax+32], rcx $LN1@timer_inse: ; 33 : } ; 34 : timer_last = new_timer; mov rax, QWORD PTR new_timer$[rsp] mov QWORD PTR ?timer_last@@3PEAU_timer_@@EA, rax ; timer_last ; 35 : } ret 0 ?timer_insert@@YAXPEAU_timer_@@@Z ENDP ; timer_insert _TEXT ENDS ; Function compile flags: /Odtpy ; File e:\xeneva project\xeneva\aurora\aurora\timer.cpp _TEXT SEGMENT t$1 = 0 id$ = 32 ?find_timer_id@@YAHG@Z PROC ; find_timer_id ; 127 : int find_timer_id (uint16_t id) { $LN7: mov WORD PTR [rsp+8], cx sub rsp, 24 ; 128 : for (timer_t *t = timer_head; t != NULL; t = t->next) { mov rax, QWORD PTR ?timer_head@@3PEAU_timer_@@EA ; timer_head mov QWORD PTR t$1[rsp], rax jmp SHORT $LN4@find_timer $LN3@find_timer: mov rax, QWORD PTR t$1[rsp] mov rax, QWORD PTR [rax+24] mov QWORD PTR t$1[rsp], rax $LN4@find_timer: cmp QWORD PTR t$1[rsp], 0 je SHORT $LN2@find_timer ; 129 : if (t->task_id == id) { mov rax, QWORD PTR t$1[rsp] movzx eax, WORD PTR [rax+8] movzx ecx, WORD PTR id$[rsp] cmp eax, ecx jne SHORT $LN1@find_timer ; 130 : return t->utimer_id; mov rax, QWORD PTR t$1[rsp] mov eax, DWORD PTR [rax+12] jmp SHORT $LN5@find_timer ; 131 : break; jmp SHORT $LN2@find_timer $LN1@find_timer: ; 132 : } ; 133 : } jmp SHORT $LN3@find_timer $LN2@find_timer: ; 134 : ; 135 : return -1; mov eax, -1 $LN5@find_timer: ; 136 : } add rsp, 24 ret 0 ?find_timer_id@@YAHG@Z ENDP ; find_timer_id _TEXT ENDS ; Function compile flags: /Odtpy ; File e:\xeneva project\xeneva\aurora\aurora\timer.cpp _TEXT SEGMENT t$1 = 32 msg$2 = 40 ?timer_fire@@YAXXZ PROC ; timer_fire ; 144 : void timer_fire () { $LN9: sub rsp, 88 ; 00000058H ; 145 : x64_cli(); call x64_cli ; 146 : if (timer_head != NULL) { cmp QWORD PTR ?timer_head@@3PEAU_timer_@@EA, 0 ; timer_head je $LN6@timer_fire ; 147 : for (timer_t *t = timer_head; t != NULL; t = t->next) { mov rax, QWORD PTR ?timer_head@@3PEAU_timer_@@EA ; timer_head mov QWORD PTR t$1[rsp], rax jmp SHORT $LN5@timer_fire $LN4@timer_fire: mov rax, QWORD PTR t$1[rsp] mov rax, QWORD PTR [rax+24] mov QWORD PTR t$1[rsp], rax $LN5@timer_fire: cmp QWORD PTR t$1[rsp], 0 je SHORT $LN3@timer_fire ; 148 : if (t->start) { mov rax, QWORD PTR t$1[rsp] movzx eax, BYTE PTR [rax+16] test eax, eax je SHORT $LN2@timer_fire ; 149 : if (t->timer_count == t->interval ) { mov rax, QWORD PTR t$1[rsp] mov rcx, QWORD PTR t$1[rsp] mov ecx, DWORD PTR [rcx+4] cmp DWORD PTR [rax], ecx jne SHORT $LN1@timer_fire ; 150 : postmsg_t msg; ; 151 : msg.type = SYSTEM_MESSAGE_TIMER_EVENT; mov eax, 1 mov WORD PTR msg$2[rsp], ax ; 152 : msg.to_id = t->task_id; mov rax, QWORD PTR t$1[rsp] movzx eax, WORD PTR [rax+8] mov WORD PTR msg$2[rsp+28], ax ; 153 : post_box_put_msg (&msg,t->task_id); mov rax, QWORD PTR t$1[rsp] movzx edx, WORD PTR [rax+8] lea rcx, QWORD PTR msg$2[rsp] call ?post_box_put_msg@@YAXPEAU_post_box_message_@@G@Z ; post_box_put_msg ; 154 : t->timer_count = 0; mov rax, QWORD PTR t$1[rsp] mov DWORD PTR [rax], 0 $LN1@timer_fire: ; 155 : } ; 156 : t->timer_count++; mov rax, QWORD PTR t$1[rsp] mov eax, DWORD PTR [rax] inc eax mov rcx, QWORD PTR t$1[rsp] mov DWORD PTR [rcx], eax $LN2@timer_fire: ; 157 : } ; 158 : } jmp SHORT $LN4@timer_fire $LN3@timer_fire: $LN6@timer_fire: ; 159 : } ; 160 : } add rsp, 88 ; 00000058H ret 0 ?timer_fire@@YAXXZ ENDP ; timer_fire _TEXT ENDS ; Function compile flags: /Odtpy ; File e:\xeneva project\xeneva\aurora\aurora\timer.cpp _TEXT SEGMENT t$1 = 0 utimer_id$ = 32 ?start_timer@@YAXH@Z PROC ; start_timer ; 97 : void start_timer (int utimer_id ) { $LN7: mov DWORD PTR [rsp+8], ecx sub rsp, 24 ; 98 : for (timer_t *t = timer_head; t != NULL; t = t->next) { mov rax, QWORD PTR ?timer_head@@3PEAU_timer_@@EA ; timer_head mov QWORD PTR t$1[rsp], rax jmp SHORT $LN4@start_time $LN3@start_time: mov rax, QWORD PTR t$1[rsp] mov rax, QWORD PTR [rax+24] mov QWORD PTR t$1[rsp], rax $LN4@start_time: cmp QWORD PTR t$1[rsp], 0 je SHORT $LN2@start_time ; 99 : if (t->utimer_id == utimer_id) { mov rax, QWORD PTR t$1[rsp] mov ecx, DWORD PTR utimer_id$[rsp] cmp DWORD PTR [rax+12], ecx jne SHORT $LN1@start_time ; 100 : t->start = true; mov rax, QWORD PTR t$1[rsp] mov BYTE PTR [rax+16], 1 ; 101 : break; jmp SHORT $LN2@start_time $LN1@start_time: ; 102 : } ; 103 : } jmp SHORT $LN3@start_time $LN2@start_time: ; 104 : } add rsp, 24 ret 0 ?start_timer@@YAXH@Z ENDP ; start_timer _TEXT ENDS ; Function compile flags: /Odtpy ; File e:\xeneva project\xeneva\aurora\aurora\timer.cpp _TEXT SEGMENT t$1 = 0 utimer_id$ = 32 ?pause_timer@@YAXH@Z PROC ; pause_timer ; 82 : void pause_timer (int utimer_id) { $LN7: mov DWORD PTR [rsp+8], ecx sub rsp, 24 ; 83 : for (timer_t *t = timer_head; t != NULL; t = t->next) { mov rax, QWORD PTR ?timer_head@@3PEAU_timer_@@EA ; timer_head mov QWORD PTR t$1[rsp], rax jmp SHORT $LN4@pause_time $LN3@pause_time: mov rax, QWORD PTR t$1[rsp] mov rax, QWORD PTR [rax+24] mov QWORD PTR t$1[rsp], rax $LN4@pause_time: cmp QWORD PTR t$1[rsp], 0 je SHORT $LN2@pause_time ; 84 : if (t->utimer_id == utimer_id) { mov rax, QWORD PTR t$1[rsp] mov ecx, DWORD PTR utimer_id$[rsp] cmp DWORD PTR [rax+12], ecx jne SHORT $LN1@pause_time ; 85 : t->start = false; mov rax, QWORD PTR t$1[rsp] mov BYTE PTR [rax+16], 0 ; 86 : break; jmp SHORT $LN2@pause_time $LN1@pause_time: ; 87 : } ; 88 : } jmp SHORT $LN3@pause_time $LN2@pause_time: ; 89 : } add rsp, 24 ret 0 ?pause_timer@@YAXH@Z ENDP ; pause_timer _TEXT ENDS ; Function compile flags: /Odtpy ; File e:\xeneva project\xeneva\aurora\aurora\timer.cpp _TEXT SEGMENT t$1 = 32 utimer_id$ = 64 ?destroy_timer@@YAXH@Z PROC ; destroy_timer ; 111 : void destroy_timer (int utimer_id) { $LN7: mov DWORD PTR [rsp+8], ecx sub rsp, 56 ; 00000038H ; 112 : for (timer_t *t = timer_head; t != NULL; t = t->next) { mov rax, QWORD PTR ?timer_head@@3PEAU_timer_@@EA ; timer_head mov QWORD PTR t$1[rsp], rax jmp SHORT $LN4@destroy_ti $LN3@destroy_ti: mov rax, QWORD PTR t$1[rsp] mov rax, QWORD PTR [rax+24] mov QWORD PTR t$1[rsp], rax $LN4@destroy_ti: cmp QWORD PTR t$1[rsp], 0 je SHORT $LN2@destroy_ti ; 113 : if (t->utimer_id == utimer_id) { mov rax, QWORD PTR t$1[rsp] mov ecx, DWORD PTR utimer_id$[rsp] cmp DWORD PTR [rax+12], ecx jne SHORT $LN1@destroy_ti ; 114 : timer_delete (t); mov rcx, QWORD PTR t$1[rsp] call ?timer_delete@@YAXPEAU_timer_@@@Z ; timer_delete ; 115 : utimer_id--; mov eax, DWORD PTR utimer_id$[rsp] dec eax mov DWORD PTR utimer_id$[rsp], eax ; 116 : break; jmp SHORT $LN2@destroy_ti $LN1@destroy_ti: ; 117 : } ; 118 : } jmp SHORT $LN3@destroy_ti $LN2@destroy_ti: ; 119 : ; 120 : } add rsp, 56 ; 00000038H ret 0 ?destroy_timer@@YAXH@Z ENDP ; destroy_timer _TEXT ENDS ; Function compile flags: /Odtpy ; File e:\xeneva project\xeneva\aurora\aurora\timer.cpp _TEXT SEGMENT t$ = 32 interval$ = 64 id$ = 72 ?create_timer@@YAHIG@Z PROC ; create_timer ; 65 : int create_timer (uint32_t interval, uint16_t id) { $LN3: mov WORD PTR [rsp+16], dx mov DWORD PTR [rsp+8], ecx sub rsp, 56 ; 00000038H ; 66 : utimer_id++; mov eax, DWORD PTR ?utimer_id@@3IA ; utimer_id inc eax mov DWORD PTR ?utimer_id@@3IA, eax ; utimer_id ; 67 : timer_t *t = (timer_t*)pmmngr_alloc(); call ?pmmngr_alloc@@YAPEAXXZ ; pmmngr_alloc mov QWORD PTR t$[rsp], rax ; 68 : t->timer_count = 0; mov rax, QWORD PTR t$[rsp] mov DWORD PTR [rax], 0 ; 69 : t->task_id = id; mov rax, QWORD PTR t$[rsp] movzx ecx, WORD PTR id$[rsp] mov WORD PTR [rax+8], cx ; 70 : t->interval = interval; mov rax, QWORD PTR t$[rsp] mov ecx, DWORD PTR interval$[rsp] mov DWORD PTR [rax+4], ecx ; 71 : t->utimer_id = utimer_id; mov rax, QWORD PTR t$[rsp] mov ecx, DWORD PTR ?utimer_id@@3IA ; utimer_id mov DWORD PTR [rax+12], ecx ; 72 : t->start = false; mov rax, QWORD PTR t$[rsp] mov BYTE PTR [rax+16], 0 ; 73 : timer_insert (t); mov rcx, QWORD PTR t$[rsp] call ?timer_insert@@YAXPEAU_timer_@@@Z ; timer_insert ; 74 : return utimer_id; mov eax, DWORD PTR ?utimer_id@@3IA ; utimer_id ; 75 : } add rsp, 56 ; 00000038H ret 0 ?create_timer@@YAHIG@Z ENDP ; create_timer _TEXT ENDS END
bits 16 cpu 386 section .cmike_init global _start _start: mov word [old_stack], sp mov sp, stack_top extern main call main mov sp, word [old_stack] ret old_stack: dw 0 section .bss resb 3072 stack_top:
; A313611: Coordination sequence Gal.6.337.4 where G.u.t.v denotes the coordination sequence for a vertex of type v in tiling number t in the Galebach list of u-uniform tilings. ; 1,5,10,14,20,24,29,34,38,44,48,53,58,63,68,72,78,82,87,92,96,102,106,111,116,121,126,130,136,140,145,150,154,160,164,169,174,179,184,188,194,198,203,208,212,218,222,227,232,237 mov $2,1 mul $2,$0 mov $4,$0 mov $5,$0 add $0,1 div $0,3 sub $0,$2 sub $4,$0 lpb $0 mov $0,1 sub $4,2 add $0,$4 div $0,4 add $4,1 lpe div $4,2 mov $1,$4 add $1,1 mov $3,$5 mul $3,4 add $1,$3
; A073554: Number of Fibonacci numbers F(k), k <= 10^n, which end in 7. ; 0,14,134,1334,13334,133334,1333334,13333334,133333334,1333333334,13333333334,133333333334,1333333333334,13333333333334,133333333333334,1333333333333334,13333333333333334,133333333333333334,1333333333333333334,13333333333333333334,133333333333333333334,1333333333333333333334,13333333333333333333334 mov $1,10 pow $1,$0 div $1,9 mul $1,12 add $1,2 lpb $1 pow $1,2 div $1,7 lpe mov $0,$1
/** * Copyright (c) 2006-2020 LOVE Development Team * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. * * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: * * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be * appreciated but is not required. * 2. Altered source versions must be plainly marked as such, and must not be * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. **/ #include "wrap_RevoluteJoint.h" #include "wrap_Physics.h" namespace love { namespace physics { namespace box2d { RevoluteJoint *luax_checkrevolutejoint(lua_State *L, int idx) { RevoluteJoint *j = luax_checktype<RevoluteJoint>(L, idx); if (!j->isValid()) luaL_error(L, "Attempt to use destroyed joint."); return j; } int w_RevoluteJoint_getJointAngle(lua_State *L) { RevoluteJoint *t = luax_checkrevolutejoint(L, 1); lua_pushnumber(L, t->getJointAngle()); return 1; } int w_RevoluteJoint_getJointSpeed(lua_State *L) { RevoluteJoint *t = luax_checkrevolutejoint(L, 1); lua_pushnumber(L, t->getJointSpeed()); return 1; } int w_RevoluteJoint_setMotorEnabled(lua_State *L) { RevoluteJoint *t = luax_checkrevolutejoint(L, 1); bool arg1 = luax_checkboolean(L, 2); t->setMotorEnabled(arg1); return 0; } int w_RevoluteJoint_isMotorEnabled(lua_State *L) { RevoluteJoint *t = luax_checkrevolutejoint(L, 1); luax_pushboolean(L, t->isMotorEnabled()); return 1; } int w_RevoluteJoint_setMaxMotorTorque(lua_State *L) { RevoluteJoint *t = luax_checkrevolutejoint(L, 1); float arg1 = (float)luaL_checknumber(L, 2); t->setMaxMotorTorque(arg1); return 0; } int w_RevoluteJoint_setMotorSpeed(lua_State *L) { RevoluteJoint *t = luax_checkrevolutejoint(L, 1); float arg1 = (float)luaL_checknumber(L, 2); t->setMotorSpeed(arg1); return 0; } int w_RevoluteJoint_getMotorSpeed(lua_State *L) { RevoluteJoint *t = luax_checkrevolutejoint(L, 1); lua_pushnumber(L, t->getMotorSpeed()); return 1; } int w_RevoluteJoint_getMotorTorque(lua_State *L) { RevoluteJoint *t = luax_checkrevolutejoint(L, 1); float inv_dt = (float)luaL_checknumber(L, 2); lua_pushnumber(L, t->getMotorTorque(inv_dt)); return 1; } int w_RevoluteJoint_getMaxMotorTorque(lua_State *L) { RevoluteJoint *t = luax_checkrevolutejoint(L, 1); lua_pushnumber(L, t->getMaxMotorTorque()); return 1; } int w_RevoluteJoint_setLimitsEnabled(lua_State *L) { RevoluteJoint *t = luax_checkrevolutejoint(L, 1); bool arg1 = luax_checkboolean(L, 2); t->setLimitsEnabled(arg1); return 0; } int w_RevoluteJoint_areLimitsEnabled(lua_State *L) { RevoluteJoint *t = luax_checkrevolutejoint(L, 1); luax_pushboolean(L, t->areLimitsEnabled()); return 1; } int w_RevoluteJoint_setUpperLimit(lua_State *L) { RevoluteJoint *t = luax_checkrevolutejoint(L, 1); float arg1 = (float)luaL_checknumber(L, 2); luax_catchexcept(L, [&](){ t->setUpperLimit(arg1); }); return 0; } int w_RevoluteJoint_setLowerLimit(lua_State *L) { RevoluteJoint *t = luax_checkrevolutejoint(L, 1); float arg1 = (float)luaL_checknumber(L, 2); luax_catchexcept(L, [&](){ t->setLowerLimit(arg1); }); return 0; } int w_RevoluteJoint_setLimits(lua_State *L) { RevoluteJoint *t = luax_checkrevolutejoint(L, 1); float arg1 = (float)luaL_checknumber(L, 2); float arg2 = (float)luaL_checknumber(L, 3); luax_catchexcept(L, [&](){ t->setLimits(arg1, arg2); }); return 0; } int w_RevoluteJoint_getLowerLimit(lua_State *L) { RevoluteJoint *t = luax_checkrevolutejoint(L, 1); lua_pushnumber(L, t->getLowerLimit()); return 1; } int w_RevoluteJoint_getUpperLimit(lua_State *L) { RevoluteJoint *t = luax_checkrevolutejoint(L, 1); lua_pushnumber(L, t->getUpperLimit()); return 1; } int w_RevoluteJoint_getLimits(lua_State *L) { RevoluteJoint *t = luax_checkrevolutejoint(L, 1); lua_remove(L, 1); return t->getLimits(L); } int w_RevoluteJoint_getReferenceAngle(lua_State *L) { RevoluteJoint *t = luax_checkrevolutejoint(L, 1); lua_pushnumber(L, t->getReferenceAngle()); return 1; } int w_RevoluteJoint_hasLimitsEnabled(lua_State *L) { luax_markdeprecated(L, "RevoluteJoint:hasLimitsEnabled", API_METHOD, DEPRECATED_RENAMED, "RevoluteJoint:areLimitsEnabled"); return w_RevoluteJoint_areLimitsEnabled(L); } static const luaL_Reg w_RevoluteJoint_functions[] = { { "getJointAngle", w_RevoluteJoint_getJointAngle }, { "getJointSpeed", w_RevoluteJoint_getJointSpeed }, { "setMotorEnabled", w_RevoluteJoint_setMotorEnabled }, { "isMotorEnabled", w_RevoluteJoint_isMotorEnabled }, { "setMaxMotorTorque", w_RevoluteJoint_setMaxMotorTorque }, { "setMotorSpeed", w_RevoluteJoint_setMotorSpeed }, { "getMotorSpeed", w_RevoluteJoint_getMotorSpeed }, { "getMotorTorque", w_RevoluteJoint_getMotorTorque }, { "getMaxMotorTorque", w_RevoluteJoint_getMaxMotorTorque }, { "setLimitsEnabled", w_RevoluteJoint_setLimitsEnabled }, { "areLimitsEnabled", w_RevoluteJoint_areLimitsEnabled }, { "setUpperLimit", w_RevoluteJoint_setUpperLimit }, { "setLowerLimit", w_RevoluteJoint_setLowerLimit }, { "setLimits", w_RevoluteJoint_setLimits }, { "getLowerLimit", w_RevoluteJoint_getLowerLimit }, { "getUpperLimit", w_RevoluteJoint_getUpperLimit }, { "getLimits", w_RevoluteJoint_getLimits }, { "getReferenceAngle", w_RevoluteJoint_getReferenceAngle }, // Deprecated { "hasLimitsEnabled", w_RevoluteJoint_hasLimitsEnabled }, { 0, 0 } }; extern "C" int luaopen_revolutejoint(lua_State *L) { return luax_register_type(L, &RevoluteJoint::type, w_Joint_functions, w_RevoluteJoint_functions, nullptr); } } // box2d } // physics } // love
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright (c) GeoWorks 1989 -- All Rights Reserved PROJECT: PC GEOS MODULE: FILE: graphicsPolyline.asm AUTHOR: Steve Scholl, Oct 23, 1989 ROUTINES: Name Description ---- ----------- EXT GrDrawPolyline Draws a polyline EXT GrDrawPolygon Draws a polgon outline INT GrPolyLineLow DrawPolyline DrawPolylineLow CreateSeparatorFormat DrawSeparatorFormat REVISION HISTORY: Name Date Description ---- ---- ----------- ted 4/89 Initial revision srs 4/89 Lots of stuff Steve 10/23/89 Initial revision (klib file) jim 1/91 moved everything back to kernel DESCRIPTION: Routines for drawing polylines $Id: graphicsPolyline.asm,v 1.1 97/04/05 01:12:54 newdeal Exp $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GraphicsLine segment resource COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrDrawPolyline %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Draws a simple poly line CALLED BY: GLOBAL PASS: cx - number of points in array ds:si - array of points defining the connected lines di - handle of graphics state block RETURN: nothing DESTROYED: nothing PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- Ted 4/89 Initial version srs 4/24/89 Broke into two routines jim 10/89 gstring support, name change %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ if FULL_EXECUTE_IN_PLACE CopyStackCodeXIP segment resource GrDrawPolyline proc far ; ; Compute size of data at DS:SI. (Point is 4 bytes) ; push cx shl cx, 1 shl cx, 1 mov ss:[TPD_callVector].segment, cx pop cx mov ss:[TPD_dataBX], handle GrDrawPolylineReal mov ss:[TPD_dataAX], offset GrDrawPolylineReal GOTO SysCallMovableXIPWithDSSIBlock GrDrawPolyline endp CopyStackCodeXIP ends else GrDrawPolyline proc far FALL_THRU GrDrawPolylineReal GrDrawPolyline endp endif GrDrawPolylineReal proc far call EnterGraphics call SetPolyPenPos ; set pen position jc dplGString clr dl ;not connected ; common code used by draw polygon too polylineCommon label near ; first make sure we have a reasonable window handle call TrivialRejectFar ; chunk null window, clip mov di, GS_lineAttr ; use line attributes mov bp, ss:[bp].EG_ds ; set up old ds call DrawPolyline jmp ExitGraphics ; handle drawing to graphics string dplGString: mov al, GR_DRAW_POLYLINE ; write first part polylineGSCommon label near mov bx, cx ; set up word to write mov cl, 2 ; count is a word mov ch, GSSC_DONT_FLUSH call GSStoreBytes ; store header mov cx, bx mov bp, sp mov ds, [bp].EG_ds ; restore ds (trashed by EG) shl cx, 1 ; 4 bytes per coordinate point shl cx, 1 mov ax, (GSSC_FLUSH shl 8) or 0ffh ; no code, flush buff call GSStore ; store the data jmp ExitGraphicsGseg GrDrawPolylineReal endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SetPolyPenPos %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Utility routine used by Polyline, Polygon, Spline to get the last point in a passed buffer in order to set the current position CALLED BY: INTERNAL GrDrawPolyline, GrDrawPolygon, GrFillPolygon, GrDrawSpline PASS: si - offset to coordinate buffer ss:bp - EGframe cx - # points in buffer ds - gstate segment RETURN: penPos is set in gstate to the last point in the buffer flags preserved DESTROYED: bx PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- Jim 02/90 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ SetPolyPenPos proc near pushf uses es, ax .enter ; find the last point so we can set the new penPos mov bx, ss:[bp].EG_ds ; recover old ds mov es, bx ; es:si -> coordinate buffer mov bx, cx ; bx = # points dec bx shl bx, 1 ; 4 bytes/coordinate pair shl bx, 1 mov ax, es:[si][bx].P_x ; get x coordinate of last pt mov bx, es:[si][bx].P_y ; get y coordinate of last pt call SetDocPenPos .leave popf ; restore gstring flags ret SetPolyPenPos endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrDrawPolygon %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Draws a connected poly line CALLED BY: GLOBAL PASS: cx - number of points in array ds:si - array of points defining the connected lines di - handle of graphics state block RETURN: nothing DESTROYED: nothing PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- jim 2/90 Initial version, mostly copied from GrDrawPolyline %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ if FULL_EXECUTE_IN_PLACE CopyStackCodeXIP segment resource GrDrawPolygon proc far ; ; Compute size of data at DS:SI. (Point is 4 bytes) ; push cx shl cx, 1 shl cx, 1 mov ss:[TPD_callVector].segment, cx pop cx mov ss:[TPD_dataBX], handle GrDrawPolygonReal mov ss:[TPD_dataAX], offset GrDrawPolygonReal GOTO SysCallMovableXIPWithDSSIBlock GrDrawPolygon endp CopyStackCodeXIP ends else GrDrawPolygon proc far FALL_THRU GrDrawPolygonReal GrDrawPolygon endp endif GrDrawPolygonReal proc far call EnterGraphics push ds ; save GState mov ds, ss:[bp].EG_ds mov ax, ds:[si] ; set curPos to first point mov bx, ds:[si+2] pop ds ; restore GState call SetDocPenPos ; set new current position jc dpgGString mov dl, 1 ;connected jmp polylineCommon ; handle drawing to graphics string dpgGString: mov al, GR_DRAW_POLYGON ; write first part jmp polylineGSCommon GrDrawPolygonReal endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrBrushPolyline %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Draws a brushed connected poly line CALLED BY: GLOBAL PASS: cx - number of points in array ds:si - array of points defining the connected lines di - handle of graphics state block al - rectangular brush width, in pixels ah - rectangular brush height, in pixels RETURN: nothing DESTROYED: nothing PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- jim 11/91 Initial version, mostly copied from GrDrawPolyline don 4/95 Small code-size optimizations %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ if FULL_EXECUTE_IN_PLACE CopyStackCodeXIP segment resource GrBrushPolyline proc far ; ; Compute size of data at DS:SI. (Point is 4 bytes.) ; push cx shl cx, 1 shl cx, 1 mov ss:[TPD_callVector].segment, cx pop cx mov ss:[TPD_dataBX], handle GrBrushPolylineReal mov ss:[TPD_dataAX], offset GrBrushPolylineReal GOTO SysCallMovableXIPWithDSSIBlock GrBrushPolyline endp CopyStackCodeXIP ends else GrBrushPolyline proc far FALL_THRU GrBrushPolylineReal GrBrushPolyline endp endif GrBrushPolylineReal proc far ; these locals are only used in the case of the optimized draw ; for two points optSep local Point optPoint2 local Point optPoint1 local Point call EnterGraphics call SetPolyPenPos ; set new current position jc bplGString ; first make sure we have a reasonable window handle call TrivialRejectFar jcxz done ; jmp if no points push ss:[bp].EG_ax ; get brush width/height mov bp, ss:[bp].EG_ds ; set up old ds ; see if there are only 2 points, and optimize for that case ; (this helps out drawing ink in pen-systems) cmp cx, 2 LONG je helpInk clr al call CreateSeparatorFormat pop ax ; restore brush size jc freeBlock push bx ; save SEPARATOR handle clr si ; offset into SEPARATOR block mov bp,1 ; num disjoint polylines push dx push ax ; save brush size call GetPolylineBounds pop bp ; bp = brush size xchg ax, bp add cl, al adc ch, 0 add dl, ah adc dh, 0 xchg bp, ax call TrivialRejectRect ; if outside bounds of window mov ax, bp ; ax = brush shape pop bx jc freePopBlock ; ...do nothing clr si ; bx:si -> point buffer mov di, DR_VID_POLYLINE ; load up function number call es:[W_driverStrategy] ; call video driver freePopBlock: pop bx ; recover SEPARATOR handle freeBlock: call MemFree done: jmp ExitGraphics ; handle drawing to graphics string bplGString: mov dx, ax ; store brush size info mov al, GR_BRUSH_POLYLINE ; write first part mov bx, cx ; set up word to write mov cl, size OpBrushPolyline - 1 ; #databytes to write mov ch, GSSC_DONT_FLUSH call GSStoreBytes ; store header mov cx, bx mov bp, sp mov ds, [bp].EG_ds ; restore ds (trashed by EG) shl cx, 1 ; 4 bytes per coordinate point shl cx, 1 mov ax, (GSSC_FLUSH shl 8) or 0ffh ; no code, flush buff call GSStore ; store the data jmp ExitGraphicsGseg ; if only two points, brush a line helpInk: pop ax ; restore brush size mov bx, bp ; ax -> point buffer .enter ; create local vars push ax ; save brush size push ds ; save GState segment mov ds, bx ; ds -> points lodsw ; get first x coord mov cx, ax lodsw ; get first y coord mov dx, ax lodsw mov bx, ax lodsw xchg ax, bx call GrTransCoord2Far mov optPoint1.P_x, cx mov optPoint1.P_y, dx mov optPoint2.P_x, ax mov optPoint2.P_y, bx mov optSep.P_x, 8000h ; add separator mov optSep.P_y, 8000h pop ds ; restore GState segment pop ax ; restore brush size mov bx, ss lea si, optPoint1 ; bx:si -> point buffer mov di, DR_VID_POLYLINE ; load up function number push bp call es:[W_driverStrategy] ; call video driver pop bp .leave jmp done GrBrushPolylineReal endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DrawPolyline %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Draws a poly line CALLED BY: GLOBAL PASS: ds - gstate es - window bp:si - segment and offset to points cx - number of points in array di - offset to attributes to use dl - 0 if not connected, 1 if connect first and last RETURN: nothing DESTROYED: bx,bp,si PSEUDO CODE/STRATEGY: Set scaledLineWidth - must be at least one Convert points to translated separator format Pass point onto next polyline routine KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- srs 10/17/89 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ DrawPolylineFar proc far call DrawPolyline ret DrawPolylineFar endp DrawPolyline proc near call ScaleLineWidth ;set scaled line width jcxz done ;jmp if no points mov al,dl ;pass connected flag call CreateSeparatorFormat jc freeBlock push bx ;save SEPARATOR handle clr si ;offset into SEPARATOR block mov bp,1 ;num disjoint polylines call DrawPolylineMed pop bx ;recover SEPARATOR handle freeBlock: call MemFree done: ret DrawPolyline endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DrawPolylineMed %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Does a trivial reject on the polyline information. If the rejected it just returns, otherwise calls DrawPolylineLow CALLED BY: INTERNAL DrawPolyline PASS: dx:si - segment and offset to points in separator format ds - gstate cx - number of points bp - number of disjoint polylines es - window al - connected flag di - offset to attributes to draw with RETURN: nothing DESTROYED: ax,bx,cx,dx,bp,di,si PSEUDO CODE/STRATEGY: none KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- srs 1/22/90 Initial version don 4/ 7/95 Optimized to always check window's mask rect and saved a few bytes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ DrawPolylineMed proc near .enter ; To try to speed things along, we see if the passed polyline will ; fall anywhere inside of the current Window. If the scaled line ; width is anything other than 1, then we need to bump the polyline's ; bounds out to account for the extra width. For line joins, be ; aware that a mitered line can extend far beyond the end of the ; line (imagine a join of two lines that are nearly parallel). We ; can ignore this problem if there are only two point in the polyline ; (i.e. we are just drawing a single line, which is the most common ; case). ; cmp cx, 2 ;if only two point jbe doTest ;...don't care about LineJoin cmp ds:[GS_lineJoin], LJ_MITERED je draw doTest: push ax,cx,dx,si call GetPolylineBounds ;bounds -> ax,bx,cx,dx mov si,ds:[GS_scaledLineWid] cmp si,1 jbe notFat shr si,1 ;half line width inc si sub ax,si ;extend bounds to include sub bx,si ;fatness add cx,si add dx,si notFat: call TrivialRejectRect ;if outside of window pop ax,cx,dx,si jc done ;...we're done draw: call DrawPolylineLow done: .leave ret DrawPolylineMed endp DrawPolylineMedFar proc far call DrawPolylineMed ret DrawPolylineMedFar endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GetPolylineBounds %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Finds X min, X max, Y min, and Y max of the polyline CALLED BY: INTERNAL DrawPolylineMed PASS: dx:si - segment and offset to points in separator format ds - gstate cx - number of points bp - number of disjoint polylines RETURN: ax,bx -upper left cx,dx - lower right DESTROYED: si PSEUDO CODE/STRATEGY: none KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GetPolylineBounds proc near uses ds,di .enter mov ds,dx ; get 1st coordinate and initialize X min/max, Y min/max ;di = xMin bx = yMin cx = xMax dx = yMax lodsw ; get X coordinate mov di,ax ; initialize X min mov cx,ax ; initialize X max lodsw ; get Y coordinate mov bx,ax ; initialize Y min mov dx,ax ; initialize Y max nextX: lodsw ; get X coordinate cmp ax,SEPARATOR je separator ; jmp if hit SEPARATOR cmp ax,di ; compare X value with X min jl newXMin ; if less, store the new X min cmp ax, cx ; if not, compare X value with X max jg newXMax ; if greater, store the new X max nextY: lodsw ; get Y coordinate cmp ax,bx ; compare Y value with Y min jl newYMin ; if less, store the new Y min cmp ax,dx ; if not, compare Y value with Y max jle nextX ; if less or equal, jmp to continue mov dx,ax ; store the new Y max jmp short nextX ; check next vertex separator: ;HIT SEPARATOR cmp ds:[si],SEPARATOR jne nextX ; jmp if didn't hit 2nd SEPARATOR mov ax,di .leave ret newXMin: mov di, ax ; store the new X min jmp short nextY ; check Y coordinate newXMax: mov cx, ax ; store the new X max jmp short nextY ; check Y coordinate newYMin: mov bx, ax ; store the new Y min jmp short nextX ; check next vertex GetPolylineBounds endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DrawPolylineLow %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Low level routine for drawing polylines CALLED BY: INTERNAL DrawPolylineMed PASS: dx:si - array of points in terminated separator format ds - segment of graphics state es - segment of window cx - number of points bp - number of disjoint polylines al - connected flag - only used by fatlines di - offset to attributes RETURN: es - window segement - may have moved DESTROYED: ax,bx,cx,dx,bp,di,si PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- srs 10/17/89 Initial version don 12/11/91 Always recalculates the scaled width %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ DrawPolylineLow proc far ; See which polyline draw code we need to use - regular, ; dashed lines, or fat-lines ; call ScaleLineWidth ;update the scaled line width cmp ds:[GS_lineStyle], LS_SOLID jnz dashes ;jmp if do dashes drawBuffer: cmp ds:[GS_scaledLineWid],1 ja fatLines ;jmp if fat call DrawSeparatorFormat freeBuffer: cmp ds:[GS_lineStyle], LS_SOLID jz done ;jmp if no dash block pop bx ;dashes handle call MemFree done: ret ; Deal with dashes ; dashes: push ax, di ;save connected flag call PolyDashedLineLow pop ax, di ;recover connected flag tst bx jz done ;jmp if nothing returned clr si ;offset to dashes push bx ;save dashes block handle jmp drawBuffer ; Deal with fat-lines ; fatLines: clr ah mov cx, ax ;pass connected flag call DoFatLines jmp freeBuffer DrawPolylineLow endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CreateSeparatorFormat %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Converts a buffer of coordinates into Separator Format CALLED BY: INTERNAL GrPolyline PASS: cx - number of points in array bp:si - array of points in document coordinates es - window al - 0 if not connected, 1 of connected RETURN: bx - handle of Separator Format block dx - segment of Separator Format block ds,es unchanged cx - number of points ax - unchanged carry - set if there was some overflow problem with coords DESTROYED: si,bp PSEUDO CODE/STRATEGY: The passed coordinates are in document coordinates. The new buffer in Separator Format contains screen coordinates and the coordinates are followed by two SEPARATOR constants. 3fffh - maximum number of points that can be passed ??? should this return 0 for block handle in certain situation like 0 or 1 points KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- srs 10/17/89 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ CreateSeparatorFormat proc far uses ax, di, ds .enter cmp cx, 1 ; if only one point, force conn flag jne 5$ mov al, 1 5$: mov dx,cx ;save number of points tst al jz 10$ ;jmp if not connected inc cx ;number of points including connected 10$: push cx ;save point count push ax ;connected flag mov ax,cx ;number of points, including connected inc ax ;bytes for two SEPARATOR constants shl ax,1 shl ax,1 ;number of bytes EC < ERROR_C GRAPHICS_BLOCK_TOO_BIG_TO_ALLOC > mov cx,ALLOC_DYNAMIC_NO_ERR or (mask HAF_LOCK shl 8) call MemAllocFar push bx ;save handle mov cx,dx ;number of points excluding connected mov ds,bp ;segment of src points mov bp,ax ;segment of dest buffer clr di ;offset to store separator format mov dx,es ;save window segment CSF_10: lodsw ;get a point mov bx,ax lodsw xchg ax,bx call GrTransCoordFar ;translate it jnc checkCoords ; we're way out of bounds. restore the stack and bail outOfBounds: pop bx ;restore handle pop ax ;restore connected flag pop cx ;restore point count (to be destroyed) clr cx ;return zero points stc ;return error jmp done checkCoords: cmp ax, MAX_COORD ; if too big, bail jg outOfBounds cmp bx, MAX_COORD jg outOfBounds EC < call CheckCoordFar > EC < push ax > EC < mov ax,bx > EC < call CheckCoordFar > EC < pop ax > mov es,bp ;seg of separator format stosw ;store translated x mov ax,bx stosw ;store translated y mov es,dx ;recover window dec cx ;number of points left jne CSF_10 ;jmp if still points pop bx ;handle of separator format to return mov es,bp ;seg of separator format pop ax ;connected flag tst al jz 20$ ;jmp if not connected ;STORE FIRST POINT AT END mov ax,es:0 ;first x of separator format stosw ;store at end mov ax,es:2 ;first y of separator format stosw ;STORE TWO SEPARATORS 20$: mov ax,SEPARATOR stosw ;store SEPARATORs stosw mov es,dx ;window mov dx,bp ;segment of separator format pop cx ;restore point count clc ;signal OK done: .leave ret CreateSeparatorFormat endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DrawSeparatorFormat %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Will eventually become a driver routine. CALLED BY: PASS: dx:si - segment and offset points buffer es - window segment ds - gstate segment di - offset to attributes to use RETURN: es - window segment - may have moved DESTROYED: ax,bx,cx,dx,bp,si,di PSEUDO CODE/STRATEGY: passed buffer must be in screen coordinates and terminated separator format (SCTSF) KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- srs 10/17/89 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ DrawSeparatorFormat proc far uses ds .enter mov bx, dx ; bx:si -> points mov di, DR_VID_POLYLINE ; load up function number clr ax ; draw with 1x1 pixel brush call es:[W_driverStrategy] ; call video driver .leave ret DrawSeparatorFormat endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ScaleLineWidth %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Computes the scaled line width, and stored in in the GState CALLED BY: GLOBAL PASS: DS = GState segment ES = Window segment RETURN: Nothing DESTROYED: Nothing PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- Don 12/11/91 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ ScaleLineWidth proc near uses dx, ax .enter movwwf dxax, ds:[GS_lineWidth] call ScaleScalar ; scaled width => AX tst ax jnz storeScaled inc ax ; make it at one storeScaled: mov ds:[GS_scaledLineWid], ax .leave ret ScaleLineWidth endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ScaleScalar %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Scales a scalar quantity based on the x and y scale factor CALLED BY: GLOBAL PASS: dxax - scalar quantity (WWFixed) ds - GState segment if ds:GS_window != NULL, then es - window segment (may not be RETURN: ax - scaled scalar DESTROYED: nothing PSEUDO CODE/STRATEGY: A scalar quantitiy cannot always be correctly scaled when there are idependent scaling factors. So I scale the quantity by both factors and take an average. This value will be correct if both the scale factors are the same, otherwise it will off a bit. However, the scale factors in the transformation matrix are not independent of the rotation. So we can't always get the scale factor directly from the matrix. Also, all the routines we have apply the whole matrix to a value at once. So our scalar quantitiy will get translated too. All this is overcomeable in some way or another. What we do is transform 0,0 and scalar,0. The distance between these two points is our value scaled in x. We then transform 0,scalar. The distance between it and 0,0 tranformed is our value scaled in y. When the average these two values and we are set. The distance calculation used in only an approximation. It is exact when the distance is along a horizontal or vertical line (which is the case if no rotation is involved) and it gets slowly worse as the distance is measured along a diagonal line. But not too bad. KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- srs 10/19/89 Initial version jim 12/92 added support for no window don 2/95 Optimized %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ ScaleScalar proc far uses bx,cx,dx,ds,si,di point0 local PointWWFixed point1 local PointWWFixed .enter ; first figure out if we're gonna use the window or the GState mov cx, ax ; dxcx = scalar tst ds:[GS_window] ; check for no window jz round segmov ds, es, si mov si, offset W_TMatrix ; ds:si -> window matrix ; ds:si -> matrix to use. Transform the coords and take the average ; distance. pushwwf dxcx ; save for later clrwwf bxax call TransCoordFixed ; transform (scalar,0) movwwf point1.PF_x, dxcx ; save result movwwf point1.PF_y, bxax clrwwf bxax clrwwf dxcx call TransCoordFixed ;transform (0,0) movwwf point0.PF_x, dxcx movwwf point0.PF_y, bxax push si lea si, point0 lea di, point1 call DistanceApprox ; calc scaled in x pop si popwwf bxax ; restore scalar line width pushwwf dxcx ; save first distance clrwwf dxcx call TransCoordFixed ;transform (0,scalar) movwwf point1.PF_x, dxcx ; save result movwwf point1.PF_y, bxax lea si, point0 call DistanceApprox ; calc scaled in y popwwf bxax ; restore saved scaled-in-X addwwf dxcx, bxax ; add.. shrwwf dxcx ; ..average.. round: rnduwwf dxcx ; ..round mov ax, dx .leave ret ScaleScalar endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DistanceApprox %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Calculates the distance between two points using an approximation of the distance formula CALLED BY: INTERNAL ScaleScalar PASS: ss:si - point1 (WWFixed) ss:di - point2 (WWFixed) RETURN: dxcx - WWFixed distance DESTROYED: ax, bx PSEUDO CODE/STRATEGY: (abs(dx) + abs(dy) + max(abs(dx),abs(dy)))/2 KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- srs 10/23/89 Initial version jim 2/93 Changed to do WWFixed math %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ DistanceApprox proc near movwwf dxcx, <ss:[si].PF_x> subwwf dxcx, <ss:[di].PF_x> ; calculate delta X tst dx ; take abs value jns haveAbsX negwwf dxcx haveAbsX: movwwf bxax, <ss:[si].PF_y> subwwf bxax, <ss:[di].PF_y> ; calculate delta X tst bx ; take abs value jns haveAbsY negwwf bxax haveAbsY: jgewwf dxcx, bxax, haveMax xchgwwf dxcx, bxax ; have maximum, so double it, add other, halve... haveMax: shlwwf dxcx addwwf dxcx, bxax ; deltaX*2 + deltaY sarwwf dxcx ; final divide by 2 ret DistanceApprox endp GraphicsLine ends
.global s_prepare_buffers s_prepare_buffers: ret .global s_faulty_load s_faulty_load: push %r11 push %r12 push %r14 push %rbp push %rbx push %rcx // Faulty Load lea addresses_WC+0x269b, %r11 nop nop nop nop inc %rbp movups (%r11), %xmm5 vpextrq $1, %xmm5, %rcx lea oracles, %r12 and $0xff, %rcx shlq $12, %rcx mov (%r12,%rcx,1), %rcx pop %rcx pop %rbx pop %rbp pop %r14 pop %r12 pop %r11 ret /* <gen_faulty_load> [REF] {'src': {'same': False, 'congruent': 0, 'NT': False, 'type': 'addresses_WC', 'size': 1, 'AVXalign': False}, 'OP': 'LOAD'} [Faulty Load] {'src': {'same': True, 'congruent': 0, 'NT': False, 'type': 'addresses_WC', 'size': 16, 'AVXalign': False}, 'OP': 'LOAD'} <gen_prepare_buffer> {'38': 21829} 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 */
;================================================================================ ; New Item Handlers ;-------------------------------------------------------------------------------- ; REMEMBER TO UPDATE THE TABLES IN UTILITIES.ASM! ;-------------------------------------------------------------------------------- ; #$4C - Bomb Capacity (50) ; #$4D - Arrow Capacity (70) ; #$4E - 1/2 Magic ; #$4F - 1/4 Magic ; #$50 - Safe Master Sword ; #$51 - Bomb Capacity (+5) ; #$52 - Bomb Capacity (+10) ; #$53 - Arrow Capacity (+5) ; #$54 - Arrow Capacity (+10) ; #$55 - Programmable Item 1 ; #$56 - Programmable Item 2 ; #$57 - Programmable Item 3 ; #$58 - Upgrade-Only Silver Arrows ; #$59 - Rupoor ; #$5A - Null Item ; #$5B - Red Clock ; #$5C - Blue Clock ; #$5D - Green Clock ; #$5E - Progressive Sword ; #$5F - Progressive Shield ; #$60 - Progressive Armor ; #$61 - Progressive Lifting Glove ; #$62 - RNG Pool Item (Single) ; #$63 - RNG Pool Item (Multi) ; #$6A - Goal Item (Single/Triforce) ; #$6B - Goal Item (Multi/Power Star) ; #$70 - Maps ; #$80 - Compasses ; #$90 - Big Keys ; #$A0 - Small Keys ; #$B0+ - Super Metroid Items ;-------------------------------------------------------------------------------- ;GetAnimatedSpriteGfxFile: ; LDY.b #$32 ; CMP.b #$39 : BCS + ; If tile index >= 0x39, use sprite file 0x32 (Blank file) ; ; LDY.b #$5D ; ; CMP.b #$23 : BEQ + ; If tile index is 0x23 (Pendant)... ; CMP.b #$37 : BCS + ; ...or tile index >= 0x37, use sprite file 0x5D (Pendant, Boots, 20 Rupees) ; ; LDY.b #$5C ; ; CMP.b #$0C : BEQ + ; If tile index is 0x0C (Flute)... ; CMP.b #$24 : BCS + ; ...or tile index >= 24, use sprite file 0x5C (Rupees, Crystal, Heart Piece ... ...) ; ; ; Otherwise, use sprite file 0x5B (Medallions, Mirror, Flippers, Lantern, Compass...) ; LDY.b #$5B ;+ ;JML GetAnimatedSpriteGfxFile_return ;-------------------------------------------------------------------------------- GetAnimatedSpriteGfxFile: CMP.b #$0C : BNE + LDY.b #$5C : JML GetAnimatedSpriteGfxFile_return + CMP.b #$23 : BNE + LDY.b #$5D : JML GetAnimatedSpriteGfxFile_return + CMP.b #$48 : BNE + LDY.b #$60 : JML GetAnimatedSpriteGfxFile_return + CMP.b #$24 : !BGE + LDY.b #$5B : JML GetAnimatedSpriteGfxFile_return + CMP.b #$37 : !BGE + LDY.b #$5C : JML GetAnimatedSpriteGfxFile_return + CMP.b #$39 : !BGE + LDY.b #$5D : JML GetAnimatedSpriteGfxFile_return + CMP.b #$50 : !BLT + LDY.b #$F0 : JML GetAnimatedSpriteGfxFile_return + LDY.b #$32 JML GetAnimatedSpriteGfxFile_return ;-------------------------------------------------------------------------------- GetAnimatedSpriteBufferPointer_table: ; Original data: dw $09C0, $0030, $0060, $0090, $00C0, $0300, $0318, $0330 dw $0348, $0360, $0378, $0390, $0930, $03F0, $0420, $0450 dw $0468, $0600, $0630, $0660, $0690, $06C0, $06F0, $0720 ; disassembly (incorrectly?) says this is $0270 dw $0750, $0768, $0900, $0930, $0960, $0990, $09F0, $0000 dw $00F0, $0A20, $0A50, $0660, $0600, $0618, $0630, $0648 dw $0678, $06D8, $06A8, $0708, $0738, $0768, $0960, $0900 dw $03C0, $0990, $09A8, $09C0, $09D8, $0A08, $0A38, $0600 dw $0630 ; New data: dw $0600, $0630, $0660, $0690 ; 50 Bombs / 70 Arrows / Half Magic / Quarter Magic dw $06C0, $06F0, $0720 ; +5/+10 Bomb Arrows ;#$4x dw $0750 ; +10 Arrows dw $0900 ; Upgrade-Only Silver Arrows dw $09D8 ; Unused dw $0930, $0960, $0990, $09C0 ; Lvl 1/2/3/4 Sword (Freestanding) dw $09F0 ; Null-Item dw $09C0 ; Clock dw $0A20 ; Triforce dw $0A50 ; Power Star ;#$4b dw $0000, $0000, $0000, $0000, $0000 ;#$50 - Super Metroid Item pointers dw $0600, $0630, $0660, $0690, $06C0, $06F0, $0720, $0750 dw $0900, $0930, $0960, $0990, $09C0, $09F0, $0A20, $0A50 dw $0C00, $0C30, $0C60, $0C90, $0CC0, $0CF0, $0D20, $0D50 GetAnimatedSpriteBufferPointer: ;PHB : PHK : PLB LDA.b $00 : ADC.l GetAnimatedSpriteBufferPointer_table, X ;PLB RTL ;-------------------------------------------------------------------------------- macro ProgrammableItemLogic(index) LDA.l ProgrammableItemLogicPointer_<index> : BNE ?jump LDA.l ProgrammableItemLogicPointer_<index>+1 : BNE ?jump LDA.l ProgrammableItemLogicPointer_<index>+2 : BNE ?jump BRA ?end ?jump: JSL.l ProgrammableItemLogicJump_<index> ?end: endmacro macro ValueShift() TAX : LDA.b #$01 ?start: CPX #$00 : BEQ ?end ASL DEX BRA ?start : ?end: endmacro ;-------------------------------------------------------------------------------- !CHALLENGE_TIMER = "$7EF454" !GOAL_COUNTER = "$7EF418" !INVENTORY_SWAP_2 = "$7EF38E" ;-------------------------------------------------------------------------------- ;carry clear if pass ;carry set if caught ;incsrc eventdata.asm ; ProcessEventItems: ; ;STA $FFFFFF ; LDA $00 : PHA ; LDA $01 : PHA ; LDA $02 : PHA ; PHY : PHP ; PHB : LDA.b #$AF : PHA : PLB ; LDA $02D8 ; CMP.b #$E0 : BNE + ; REP #$30 ; set 16-bit accumulator & index registers ; LDA $7EF450 : ASL : TAX ; LDA.l EventDataOffsets, X : !ADD #EventDataTable : STA $00 ; SEP #$20 ; set 8-bit accumulator ; LDA.b #$AF : STA $02 ; JSL.l LoadDialogAddressIndirect ; LDA $7EF450 : INC : STA $7EF450 ; SEP #$10 ; set 8-bit index registers ; LDA GoalItemRequirement : BEQ ++ ; LDA !GOAL_COUNTER : INC : STA !GOAL_COUNTER ; CMP GoalItemRequirement : !BLT ++ : JSL.l ActivateGoal : ++ ; LDX.b #$01 : BRA .done ; + ; LDX.b #$00 ; .done ; PLB ; PLP : PLY ; PLA : STA $02 ; PLA : STA $01 ; PLA : STA $00 ; RTS ;-------------------------------------------------------------------------------- AddReceivedItemExpandedGetItem: PHX ;JSR.w ProcessEventItems : CPX.b #$00 : BEQ ++ ; ;JSL.l Main_ShowTextMessage ; LDA !GOAL_COUNTER : INC : STA !GOAL_COUNTER ; LDA.b #$01 : STA $7F50A0 ; BRL .done ;++ ;STA $FFFFFF lda.l config_multiworld beq + ; If this is a multiworld item for someone else, skip picking the item up and just play ; the animation, also, write this item to the outgoing queue lda !MULTIWORLD_PICKUP cmp #$01 bne + plx pla : pla : pla ; Align the stack by popping the return value off it (so we can JML instead of RTL) lda $02e9 : cmp #$01 : bne .notChest lda $72 : pha lda $73 : pha .notChest ldy #$01 lda $02d8 : cmp #$20 : bne .notCrystal ldy #$02 .notCrystal tya : sta $02e4 jsl alttp_mw_send_item ; Item ID is already stored in !MULTIWORLD_ITEM phx jml $098763 ; Skip all code that gives Link the item and just show the graphics + LDA $02D8 ; check inventory JSL.l FreeDungeonItemNotice CMP.b #$0B : BNE + ; Bow LDA !INVENTORY_SWAP_2 : AND.b #$40 : BEQ ++ LDA.l SilverArrowsUseRestriction : BNE ++ LDA.b #03 : STA $7EF340 ; set bow to silver ++ BRL .done + CMP.b #$4C : BNE + ; 50 bombs ;LDA.b #$07 : STA $7EF370 ; upgrade bombs LDA.b #50 : !SUB.l StartingMaxBombs : STA $7EF370 ; upgrade bombs LDA.b #50 : STA $7EF375 ; fill bombs BRL .done + CMP.b #$4D : BNE + ; 70 arrows ;LDA #$07 : STA $7EF371 ; upgrade arrows LDA.b #70 : !SUB.l StartingMaxArrows : STA $7EF371 ; upgrade arrows LDA.b #70 : STA $7EF376 ; fill arrows BRL .done + CMP.b #$4E : BNE + ; 1/2 magic LDA $7EF37B : CMP #$02 : !BGE ++ INC : STA $7EF37B ; upgrade magic ++ LDA.b #$80 : STA $7EF373 ; fill magic BRL .done + CMP.b #$4F : BNE + ; 1/4 magic LDA.b #$02 : STA $7EF37B ; upgrade magic LDA.b #$80 : STA $7EF373 ; fill magic BRL .done + CMP.b #$50 : BNE + ; Master Sword (Safe) LDA $7EF359 : CMP.b #$02 : !BGE + ; skip if we have a better sword LDA.b #$02 : STA $7EF359 ; set master sword BRL .done + CMP.b #$51 : BNE + ; +5 Bombs LDA $7EF370 : !ADD.b #$05 : STA $7EF370 ; upgrade bombs +5 LDA.l Upgrade5BombsRefill : STA $7EF375 ; fill bombs BRL .done + CMP.b #$52 : BNE + ; +10 Bombs LDA $7EF370 : !ADD.b #$0A : STA $7EF370 ; upgrade bombs +10 LDA.l Upgrade10BombsRefill : STA $7EF375 ; fill bombs BRL .done + CMP.b #$53 : BNE + ; +5 Arrows LDA $7EF371 : !ADD.b #$05 : STA $7EF371 ; upgrade arrows +5 LDA.l Upgrade5ArrowsRefill : STA $7EF376 ; fill arrows BRL .done + CMP.b #$54 : BNE + ; +10 Arrows LDA $7EF371 : !ADD.b #$0A : STA $7EF371 ; upgrade arrows +10 LDA.l Upgrade10ArrowsRefill : STA $7EF376 ; fill arrows BRL .done + CMP.b #$58 : BNE + ; Upgrade-Only Sivler Arrows LDA.l SilverArrowsUseRestriction : BNE +++ LDA.l SilverArrowsAutoEquip : AND.b #$01 : BEQ +++ LDA $7EF340 : BEQ ++ : CMP.b #$03 : !BGE ++ !ADD.b #$02 : STA $7EF340 ; switch to silver bow ++ +++ LDA.l ArrowMode : BEQ ++ LDA.b #$01 : STA $7EF376 ++ + CMP.b #$59 : BNE + ; 1 Rupoor REP #$20 : LDA $7EF360 : !SUB RupoorDeduction : STA $7EF360 : SEP #$20 ; Take 1 rupee BRL .done + CMP.b #$5A : BNE + ; Null Item BRL .done + CMP.b #$5E : BNE + ; Progressive Sword BRL .done + CMP.b #$5F : BNE + ; Progressive Shield BRL .done + CMP.b #$60 : BNE + ; Progressive Armor BRL .done + CMP.b #$61 : BNE + ; Progressive Lifting Glove BRL .done + CMP.b #$62 : BNE + ; RNG Pool Item (Single) BRL .done + CMP.b #$63 : BNE + ; RNG Pool Item (Multi) BRL .done + CMP.b #$70 : !BLT + : CMP.b #$80 : !BGE + ; Free Map AND #$0F : CMP #$08 : !BGE ++ %ValueShift() ORA $7EF368 : STA $7EF368 ; Map 1 BRL .done ++ !SUB #$08 %ValueShift() BIT.b #$C0 : BEQ +++ : LDA.b #$C0 : +++ ; Make Hyrule Castle / Sewers Count for Both ORA $7EF369 : STA $7EF369 ; Map 2 BRL .done + CMP.b #$80 : !BLT + : CMP.b #$90 : !BGE + ; Free Compass AND #$0F : CMP #$08 : !BGE ++ %ValueShift() ORA $7EF364 : STA $7EF364 ; Compass 1 BRL .done ++ !SUB #$08 %ValueShift() BIT.b #$C0 : BEQ +++ : LDA.b #$C0 : +++ ; Make Hyrule Castle / Sewers Count for Both ORA $7EF365 : STA $7EF365 ; Compass 2 BRL .done + CMP.b #$90 : !BLT + : CMP.b #$A0 : !BGE + ; Free Big Key AND #$0F : CMP #$08 : !BGE ++ %ValueShift() ORA $7EF366 : STA $7EF366 ; Big Key 1 BRL .done ++ !SUB #$08 %ValueShift() BIT.b #$C0 : BEQ +++ : LDA.b #$C0 : +++ ; Make Hyrule Castle / Sewers Count for Both ORA $7EF367 : STA $7EF367 ; Big Key 2 BRL .done + CMP.b #$A0 : !BLT .done : CMP.b #$B0 : !BGE .done ; Free Small Key AND #$0F : TAX LDA $7EF37C, X : INC : STA $7EF37C, X ; Increment Key Count CPX.b #$00 : BNE ++ STA $7EF37D ; copy HC to sewers ++ : CPX.b #$01 : BNE ++ STA $7EF37C ; copy sewers to HC ++ LDA.l GenericKeys : BEQ + .generic LDA $7EF36F : INC : STA $7EF36F BRL .done .normal TXA : ASL : CMP $040C : BNE ++ LDA $7EF36F : INC : STA $7EF36F ++ BRL .done + ; Check if we got a key for the dungeon we're currently in, and increment the dungeon key count LDA $40C : CMP #$FF : BEQ .done TXA : ASL : CMP $40C : BNE .done LDA.l $7EF36F : INC : STA.l $7EF36F .done jsl alttp_receive_sm_item ; Check for SM items PLX LDA $02E9 : CMP.b #$01 ; thing we wrote over RTL ; #$70 - Maps ; #$80 - Compasses ; #$90 - Big Keys ; #$A0 - Small Keys ;-------------------------------------------------------------------------------- !PROGRESSIVE_SHIELD = "$7EF416" ; ss-- ---- !RNG_ITEM = "$7EF450" !SCRATCH_AREA = "$7F5020" !SINGLE_INDEX_TEMP = "$7F5020" !SINGLE_INDEX_OFFSET_TEMP = "$7F5021" !SINGLE_INDEX_BITMASK_TEMP = "$7F5022" !LOCK_IN = "$7F5090" !ITEM_BUSY = "$7F5091" ;2B:Bottle Already Filled w/ Red Potion ;2C:Bottle Already Filled w/ Green Potion ;2D:Bottle Already Filled w/ Blue Potion ;3C:Bottle Already Filled w/ Bee ;3D:Bottle Already Filled w/ Fairy ;48:Bottle Already Filled w/ Gold Bee AddReceivedItemExpanded: { PHA : PHX ;JSL.l PreItemGet JSR EnableTemporaryCone LDA $02D8 ; Item Value JSR AttemptItemSubstitution STA $02D8 JSR IncrementItemCounters CMP.b #$16 : BNE ++ ; Bottle JSR.w CountBottles : CMP.l BottleLimit : !BLT +++ LDA.l BottleLimitReplacement : STA $02D8 +++ : BRL .done ++ : CMP.b #$2B : BNE ++ ; Red Potion w/bottle JSR.w CountBottles : CMP.l BottleLimit : !BLT +++ LDA.l BottleLimitReplacement : STA $02D8 +++ : BRL .done ++ : CMP.b #$2C : BNE ++ ; Green Potion w/bottle JSR.w CountBottles : CMP.l BottleLimit : !BLT +++ LDA.l BottleLimitReplacement : STA $02D8 +++ : BRL .done ++ : CMP.b #$2D : BNE ++ ; Blue Potion w/bottle JSR.w CountBottles : CMP.l BottleLimit : !BLT +++ LDA.l BottleLimitReplacement : STA $02D8 +++ : BRL .done ++ : CMP.b #$3C : BNE ++ ; Bee w/bottle JSR.w CountBottles : CMP.l BottleLimit : !BLT +++ LDA.l BottleLimitReplacement : STA $02D8 +++ : BRL .done ++ : CMP.b #$3D : BNE ++ ; Fairy w/bottle JSR.w CountBottles : CMP.l BottleLimit : !BLT +++ LDA.l BottleLimitReplacement : STA $02D8 +++ : BRL .done ++ : CMP.b #$48 : BNE ++ ; Gold Bee w/bottle JSR.w CountBottles : CMP.l BottleLimit : !BLT +++ LDA.l BottleLimitReplacement : STA $02D8 +++ : BRL .done ++ : CMP.b #$4E : BNE ++ ; Progressive Magic LDA $7EF37B : BEQ +++ LDA.b #$4F : STA $02D8 +++ : BRL .done ++ : CMP.b #$5E : BNE ++ ; Progressive Sword LDA $7EF359 : CMP.l ProgressiveSwordLimit : !BLT + LDA.l ProgressiveSwordReplacement : STA $02D8 : BRL .done + : CMP.b #$00 : BNE + ; No Sword LDA.b #$49 : STA $02D8 : BRL .done + : CMP.b #$01 : BNE + ; Fighter Sword LDA.b #$50 : STA $02D8 : BRL .done + : CMP.b #$02 : BNE + ; Master Sword LDA.b #$02 : STA $02D8 : BRL .done + ; Everything Else LDA.b #$03 : STA $02D8 : BRL .done ++ : CMP.b #$5F : BNE ++ ; Progressive Shield LDA !PROGRESSIVE_SHIELD : LSR #6 : CMP.l ProgressiveShieldLimit : !BLT + LDA.l ProgressiveShieldReplacement : STA $02D8 : BRL .done + LDA !PROGRESSIVE_SHIELD : AND.b #$C0 : BNE + ; No Shield LDA.b #$04 : STA $02D8 LDA !PROGRESSIVE_SHIELD : !ADD.b #$40 : STA !PROGRESSIVE_SHIELD : BRL .done + : CMP.b #$40 : BNE + ; Fighter Shield LDA.b #$05 : STA $02D8 LDA !PROGRESSIVE_SHIELD : !ADD.b #$40 : STA !PROGRESSIVE_SHIELD : BRA .done + ; Everything Else LDA.b #$06 : STA $02D8 LDA !PROGRESSIVE_SHIELD : !ADD.b #$40 : STA !PROGRESSIVE_SHIELD : BRA .done ++ : CMP.b #$60 : BNE ++ ; Progressive Armor LDA $7EF35B : CMP.l ProgressiveArmorLimit : !BLT + LDA.l ProgressiveArmorReplacement : STA $02D8 : BRL .done + : CMP.b #$00 : BNE + ; No Armor LDA.b #$22 : STA $02D8 : BRA .done + ; Everything Else LDA.b #$23 : STA $02D8 : BRA .done ++ : CMP.b #$61 : BNE ++ ; Progressive Lifting Glove LDA $7EF354 : BNE + ; No Lift LDA.b #$1B : STA $02D8 : BRA .done + ; Everything Else LDA.b #$1C : STA $02D8 : BRA .done ++ : CMP.b #$62 : BNE ++ ; RNG Item (Single) JSL.l GetRNGItemSingle : STA $02D8 XBA : JSR.w MarkRNGItemSingle LDA #$FF : STA !LOCK_IN ; clear lock-in BRA .done ++ : CMP.b #$63 : BNE ++ ; RNG Item (Multi) JSL.l GetRNGItemMulti : STA $02D8 LDA #$FF : STA !LOCK_IN ; clear lock-in BRA .done ++ .done PLX : PLA PHB : PHK ; we're skipping the corresponding instructions to grab the data bank JML.l AddReceivedItem+2 } ;-------------------------------------------------------------------------------- ;DATA AddReceivedItemExpanded { .y_offsets db -5, -5, -5, -5, -5, -4, -4, -5 db -5, -4, -4, -4, -2, -4, -4, -4 db -4, -4, -4, -4, -4, -4, -4, -4 db -4, -4, -4, -4, -4, -4, -4, -4 db -4, -4, -4, -5, -4, -4, -4, -4 db -4, -4, -2, -4, -4, -4, -4, -4 db -4, -4, -4, -4, -2, -2, -2, -4 db -4, -4, -4, -4, -4, -4, -4, -4 db -4, -4, -2, -2, -4, -2, -4, -4 db -4, -5, -4, -4 ;new db -4, -4, -4, -4 db -5 ; Master Sword (Safe) db -4, -4, -4, -4 ; +5/+10 Bomb Arrows db -4, -4, -4 ; 3x Programmable Item db -4 ; Upgrade-Only Sivler Arrows db -4 ; 1 Rupoor db -4 ; Null Item db -4, -4, -4 ; Red, Blue & Green Clocks db -4, -4, -4, -4 ; Progressive Sword, Shield, Armor & Gloves db -4, -4 ; RNG Single & Multi db -4, -4, -4, -4, -4, -4 ; Unused db -4, -4, -4 ; Goal Item Single, Multi & Alt Multi db -4, -4, -4 ; Unused db -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4 ; Free Map db -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4 ; Free Compass db -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4 ; Free Big Key db -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4 ; Free Small Key ; $B0 - SM Items db -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4 ; Unused db -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4 ; Unused db -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4 ; Unused db -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4 ; Unused .x_offsets db 4, 4, 4, 4, 4, 0, 0, 4 db 4, 4, 4, 4, 5, 0, 0, 0 db 0, 0, 0, 4, 0, 4, 0, 0 db 4, 0, 0, 0, 0, 0, 0, 0 db 0, 0, 0, 0, 4, 0, 0, 0 db 0, 0, 5, 0, 0, 0, 0, 0 db 0, 0, 0, 0, 4, 4, 4, 0 db 0, 0, 0, 0, 0, 0, 0, 0 db 0, 0, 4, 4, 0, 4, 0, 0 db 0, 4, 0, 0 ;new db 0, 0, 0, 0 db 4 ; Master Sword (Safe) db 0, 0, 0, 0 ; +5/+10 Bomb Arrows db 0, 0, 0 ; 3x Programmable Item db 0 ; Upgrade-Only Sivler Arrows db 4 ; 1 Rupoor db 0 ; Null Item db 0, 0, 0 ; Red, Blue & Green Clocks db 0, 0, 0, 0 ; Progressive Sword, Shield, Armor & Gloves db 0, 0 ; RNG Single & Multi db 0, 0, 0, 0, 0, 0 ; Unused db 0, 0, 0 ; Goal Item Single, Multi & Alt Multi db 0, 0, 0 ; Unused db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ; Free Map db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ; Free Compass db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ; Free Big Key ;db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ; *EVENT* db 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 ; Free Small Key ; $B0 - SM items db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ; Unused db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ; Unused db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ; Unused db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ; Unused .item_graphics_indices db $06, $18, $18, $18, $2D, $20, $2E, $09 db $09, $0A, $08, $05, $10, $0B, $2C, $1B db $1A, $1C, $14, $19, $0C, $07, $1D, $2F db $07, $15, $12, $0D, $0D, $0E, $11, $17 db $28, $27, $04, $04, $0F, $16, $03, $13 db $01, $1E, $10, $00, $00, $00, $00, $00 db $00, $30, $22, $21, $24, $24, $24, $23 db $23, $23, $29, $2A, $2C, $2B, $03, $03 db $34, $35, $31, $33, $02, $32, $36, $37 db $2C, $06, $0C, $38 ;new db $39, $3A, $3B, $3C db $18 ; Master Sword (Safe) db $3D, $3E, $3F, $40 ; +5/+10 Bomb Arrows db $00, $00, $00 ; 3x Programmable Item db $41 ; Upgrade-Only Sivler Arrows db $24 ; 1 Rupoor db $47 ; Null Item db $48, $48, $48 ; Red, Blue & Green Clocks db $FF, $FF, $04, $0D ; Progressive Sword, Shield, Armor & Gloves db $FF, $FF ; RNG Single & Multi db $FF, $FF, $FF, $FF, $FF, $FF ; Unused db $49, $4A, $49 ; Goal Item Single, Multi & Alt Multi db $FF, $FF, $FF ; Unused db $21, $21, $21, $21, $21, $21, $21, $21, $21, $21, $21, $21, $21, $21, $21, $21 ; Free Map db $16, $16, $16, $16, $16, $16, $16, $16, $16, $16, $16, $16, $16, $16, $16, $16 ; Free Compass db $22, $22, $22, $22, $22, $22, $22, $22, $22, $22, $22, $22, $22, $22, $22, $22 ; Free Big Key db $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F ; Free Small Key ;db $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49 ; *EVENT* ;db $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49 ; *EVENT* ;db $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49 ; *EVENT* ;db $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49 ; *EVENT* ; #$B0 - SM Items db $50, $51, $52, $53, $54, $55, $56, $57, $58, $59, $5A, $5B, $5C, $5D, $5E, $5F ; Super Metroid ; #$C0 - SM Items db $60, $61, $62, $63, $64, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49 ; Super Metroid ; #$D0 - SM Items (Keycards) db $65, $66, $67, $65, $66, $67, $65, $66, $67, $65, $66, $67, $65, $67, $65, $67 ; Super Metroid db $48, $48, $48, $48, $48, $48, $48, $48, $48, $48, $48, $48, $48, $48, $48, $48 ; Unused .wide_item_flag db $00, $00, $00, $00, $00, $02, $02, $00 db $00, $00, $00, $00, $00, $02, $02, $02 db $02, $02, $02, $00, $02, $00, $02, $02 db $00, $02, $02, $02, $02, $02, $02, $02 db $02, $02, $02, $02, $00, $02, $02, $02 db $02, $02, $00, $02, $02, $02, $02, $02 db $02, $02, $02, $02, $00, $00, $00, $02 db $02, $02, $02, $02, $02, $02, $02, $02 db $02, $02, $00, $00, $02, $00, $02, $02 db $02, $00, $02, $02 ;new db $02, $02, $02, $02 db $00 ; Master Sword (Safe) db $02, $02, $02, $02 ; +5/+10 Bomb Arrows db $02, $02, $02 ; 3x Programmable Item db $02 ; Upgrade-Only Sivler Arrows db $00 ; 1 Rupoor db $02 ; Null Item db $02, $02, $02 ; Red, Blue & Green Clocks db $02, $02, $02, $02 ; Progressive Sword, Shield, Armor & Gloves db $02, $02 ; RNG Single & Multi db $02, $02, $02, $02, $02, $02 ; Unused db $02, $02, $02 ; Goal Item Single, Multi & Alt Multi db $02, $02, $02 ; Unused db $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02 ; Free Map db $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02 ; Free Compass db $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02 ; Free Big Key db $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00 ; Free Small Key ; #$B0 - SM Items db $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02 ; Unused db $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02 ; Unused db $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02 ; Unused db $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02 ; Unused db $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02 ; Unused .properties db 5, -1, 5, 5, 5, 5, 5, 1 db 2, 1, 1, 1, 2, 2, 2, 4 db 4, 4, 1, 1, 2, 1, 1, 1 db 2, 1, 2, 1, 4, 4, 2, 1 db 6, 1, 2, 1, 2, 2, 1, 2 db 2, 4, 1, 1, 4, 2, 1, 4 db 2, 2, 4, 4, 4, 2, 1, 4 db 1, 2, 2, 1, 2, 2, 1, 1 db 4, 4, 1, 2, 2, 4, 4, 4 db 2, 5, 2, 1 ;new db 4, 4, 4, 4 db 5 ; Master Sword (Safe) db 4, 4, 4, 4 ; +5/+10 Bomb Arrows db 4, 4, 4 ; 3x Programmable Item db 1 ; Upgrade-Only Sivler Arrows db 3 ; 1 Rupoor db 1 ; Null Item db 1, 2, 4 ; Red, Blue & Green Clocks db $FF, $FF, $FF, $FF ; Progressive Sword, Shield, Armor & Gloves db $FF, $FF ; RNG Single & Multi db 0, 0, 0, 0, 0, 0 ; Unused db 4, 4, 4 ; Goal Item Single, Multi & Alt Multi db 0, 0, 0 ; Unused db 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 ; Free Map db 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ; Free Compass db 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 ; Free Big Key db 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 ; Free Small Key ; #$B0 - SM Items db 1, 5, 1, 2, 2, 4, 2, 2, 2, 1, 4, 1, 2, 2, 2, 4 ; SM Items #1 db 1, 1, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 ; SM Items #2 db 2, 1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2 ; Keycards db 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 ; Unused db 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 ; Unused ; \item Target SRAM addresses for items you receive .item_target_addr dw $F359, $F359, $F359, $F359, $F35A, $F35A, $F35A, $F345 dw $F346, $F34B, $F342, $F340, $F341, $F344, $F35C, $F347 dw $F348, $F349, $F34A, $F34C, $F34C, $F350, $F35C, $F36B dw $F351, $F352, $F353, $F354, $F354, $F34E, $F356, $F357 dw $F37A, $F34D, $F35B, $F35B, $F36F, $F364, $F36C, $F375 dw $F375, $F344, $F341, $F35C, $F35C, $F35C, $F36D, $F36E dw $F36E, $F375, $F366, $F368, $F360, $F360, $F360, $F374 dw $F374, $F374, $F340, $F340, $F35C, $F35C, $F36C, $F36C dw $F360, $F360, $F372, $F376, $F376, $F373, $F360, $F360 dw $F35C, $F359, $F34C, $F355 ;new dw $F375, $F376, $F373, $F373 dw $F359 ; Master Sword (Safe) dw $F375, $F375, $F376, $F376 ; +5/+10 Bomb Arrows dw $F41A, $F41C, $F41E ; 3x Programmable Item dw $F340 ; Upgrade-Only Sivler Arrows dw $F360 ; 1 Rupoor dw $F36A ; Null Item dw $F454, $F454, $F454 ; Red, Blue & Green Clocks dw $F359, $F35A, $F35B, $F354 ; Progressive Sword, Shield, Armor & Gloves dw $F36A, $F36A ; RNG Single & Multi dw $F36A, $F36A, $F36A, $F36A, $F36A, $F36A ; Unused dw $F36A, $F36A, $F36A ; Goal Item Single, Multi & Alt Multi dw $F36A, $F36A, $F36A ; Unused dw $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A ; Free Map dw $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A ; Free Compass dw $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A ; Free Big Key dw $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A ; Free Small Key dw $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A ; Unused dw $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A ; Unused dw $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A ; Unused dw $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A ; Unused dw $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A, $F36A ; Unused } ; DATA Values to write to the above SRAM locations. { .item_values db $01, $02, $03, $04, $01, $02, $03, $01 db $01, $01, $01, $01, $01, $02, $FF, $01 db $01, $01, $01, $01, $02, $01, $FF, $FF db $01, $01, $02, $01, $02, $01, $01, $01 db $FF, $01, $FF, $02, $FF, $FF, $FF, $FF db $FF, $FF, $02, $FF, $FF, $FF, $FF, $FF db $FF, $FF, $FF, $FF, $FF, $FB, $EC, $FF db $FF, $FF, $01, $03, $FF, $FF, $FF, $FF db $9C, $CE, $FF, $01, $0A, $FF, $FF, $FF db $FF, $01, $03, $01 ;new db $32, $46, $80, $80 db $02 ; Master Sword (Safe) db $FF, $FF, $FF, $FF ; +5/+10 Bomb Arrows db $FF, $FF, $FF ; 3x Programmable Item db $FF ; Upgrade-Only Sivler Arrows db $FF ; 1 Rupoor db $FF ; Null Item db $FF, $FF, $FF ; Red, Blue & Green Clocks db $FF, $FF, $FF, $FF ; Progressive Sword, Shield, Armor & Gloves db $FF, $FF ; RNG Single & Multi db $FF, $FF, $FF, $FF, $FF, $FF ; Unused db $FF, $FF, $FF ; Goal Item Single, Multi & Alt Multi db $FF, $FF, $FF ; Unused db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF ; Free Map db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF ; Free Compass db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF ; Free Big Key db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF ; Free Small Key db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF ; Unused db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF ; Unused db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF ; Unused db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF ; Unused db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF ; Unused ;0x00 - Sewer Passage ;0x02 - Hyrule Castle ;0x04 - Eastern Palace ;0x06 - Desert Palace ;0x08 - Hyrule Castle 2 ;0x0A - Swamp Palace ;0x0C - Dark Palace ;0x0E - Misery Mire ;0x10 - Skull Woods ;0x12 - Ice Palace ;0x14 - Tower of Hera ;0x16 - Gargoyle's Domain ;0x18 - Turtle Rock ;0x1A - Ganon's Tower .item_masks ; these are dungeon correlations to $7EF364 - $7EF369 so it knows where to store compasses, etc dw $8000, $4000, $2000, $1000, $0800, $0400, $0200, $0100 dw $0080, $0040, $0020, $0010, $0008, $0004, $0000, $0000 dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000 dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000 dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000 dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000 dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000 dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000 dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000 dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000 dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000 dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000 dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000 dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000 dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000 dw $0000, $0000, $0000, $0000, $0000, $0000, $0000 db $00 dw $0000 ; Caves } ;-------------------------------------------------------------------------------- BottleListExpanded: db $16, $2B, $2C, $2D, $3D, $3C, $48 PotionListExpanded: db $2E, $2F, $30, $FF, $0E ;-------------------------------------------------------------------------------- Link_ReceiveItemAlternatesExpanded: { db -1, -1, -1, -1, -1, -1, -1, -1 db -1, -1, -1, -1, -1, -1, -1, -1 ; db -1, -1, -1, -1, $44, -1, -1, -1 db -1, -1, $35, -1, -1, -1, -1, -1 db -1, -1, -1, -1, -1, -1, -1, -1 db -1, -1, -1, -1, -1, -1, -1, -1 db -1, -1, -1, -1, -1, -1, -1, -1 ; db -1, -1, $46, -1, -1, -1, -1, -1 db -1, -1, -1, -1, -1, -1, -1, -1 db -1, -1, -1, -1, -1, -1, -1, -1 db -1, -1, -1, -1, -1, -1, -1, -1 db -1, -1, -1, -1 db -1, -1, -1, -1 db -1 ; Master Sword (Safe) db -1, -1, -1, -1 ; +5/+10 Bomb Arrows db -1, -1, -1 ; 3x Programmable Item db -1 ; Upgrade-Only Silver Arrows db -1 ; 1 Rupoor db -1 ; Null Item db -1, -1, -1 ; Red, Blue & Green Clocks db -1, -1, -1, -1 ; Progressive Sword, Shield, Armor & Gloves db -1, -1 ; RNG Single & Multi db -1, -1, -1, -1, -1, -1 ; Unused db -1, -1 ; Goal Item Single, Multi & Alt Multi db -1, -1, -1, -1 ; Unused db -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 ; Free Map db -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 ; Free Compass db -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 ; Free Big Key db -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 ; Free Small Key db -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 ; Unused db -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 ; Unused db -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 ; Unused db -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 ; Unused db -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 ; Unused } ;-------------------------------------------------------------------------------- .loadAlternate PHB : PHK : PLB ;TYA : JSR IncrementItemCounters ;LDA Link_ReceiveItemAlternatesExpanded, Y : STA $03 ;TYA : JSR AttemptItemSubstitution : STA $03 ;CPY $03 : BNE + : LDA.b #$FF : STA $03 : + lda.b #$ff : sta $03 PLB RTL ;-------------------------------------------------------------------------------- ;DrawHUDSilverArrows: ; LDA $7EF340 : AND.w #$00FF : BNE + ; LDA !INVENTORY_SWAP_2 : AND.w #$0040 : BEQ + ; LDA.w #$2810 : STA $11C8 ; LDA.w #$2811 : STA $11CA ; LDA.w #$2820 : STA $1208 ; LDA.w #$2821 : STA $120A ; + ; LDA.w #$11CE : STA $00 ; thing we wrote over ;RTL ;-------------------------------------------------------------------------------- ;Return $7EF340 but also draw silver arrows if you have the upgrade even if you don't have the bow CheckHUDSilverArrows: LDA.l ArrowMode : BEQ .normal .rupee_arrows JSL.l DrawHUDArrows LDA $7EF340 RTL .normal LDA $7EF340 : BNE + LDA !INVENTORY_SWAP_2 : AND.b #$40 : BEQ ++ JSL.l DrawHUDArrows ++ LDA $7EF340 + RTL ;-------------------------------------------------------------------------------- DrawHUDArrows: LDA.l ArrowMode : BEQ .normal .rupee_arrows LDA $7EF377 : BEQ .none ; assuming silvers will increment this. if we go with something else, reorder these checks LDA $7EF340 : BNE + LDA !INVENTORY_SWAP_2 : AND.b #$40 : BNE .silver BRA .wooden + CMP.b #03 : !BGE .silver .wooden LDA.b #$A7 : STA $7EC720 ; draw wooden arrow marker LDA.b #$20 : STA $7EC721 LDA.b #$A9 : STA $7EC722 LDA.b #$20 : STA $7EC723 RTL .normal ; in normal arrow mode this function is only ever called for silvers .silver LDA.b #$86 : STA $7EC720 ; draw silver arrow marker LDA.b #$24 : STA $7EC721 LDA.b #$87 : STA $7EC722 LDA.b #$24 : STA $7EC723 RTL .none LDA.b #$7F : STA $7EC720 ; draw no arrow marker LDA.b #$24 : STA $7EC721 LDA.b #$7F : STA $7EC722 LDA.b #$24 : STA $7EC723 RTL ;-------------------------------------------------------------------------------- !RNG_ITEM = "$7EF450" !SCRATCH_AREA = "$7F5020" !SINGLE_INDEX_TEMP = "$7F5020" !SINGLE_INDEX_OFFSET_TEMP = "$7F5021" !SINGLE_INDEX_BITMASK_TEMP = "$7F5022" !LOCK_IN = "$7F5090" GetRNGItemSingle: PHY LDA !LOCK_IN : CMP.b #$FF : BEQ + : TAX : XBA : LDA.l RNGSingleItemTable, X : RTL : + LDX.b #$00 .single_reroll JSL.l GetRandomInt : AND.b #$7F ; select random value INX : CPX #$7F : !BLT + : LDA.b #$00 : BRA +++ : + ; default to 0 if too many attempts CMP.l RNGSingleTableSize : !BGE .single_reroll +++ STA !SINGLE_INDEX_TEMP ; put our index value here LDX #$00 TAY .recheck TYA JSR.w CheckSingleItem : BEQ .single_unused ; already used LDA !SINGLE_INDEX_TEMP : INC ; increment index CMP.l RNGSingleTableSize : !BLT +++ : LDA.b #$00 : +++ ; rollover index if needed STA !SINGLE_INDEX_TEMP ; store index INX : TAY : TXA : CMP.l RNGSingleTableSize : !BLT .recheck LDA.b #$5A ; everything is gone, default to null item - MAKE THIS AN OPTION FOR THIS AND THE OTHER ONE BRA .single_done .single_unused LDA !SINGLE_INDEX_TEMP .single_done TAX : LDA.l RNGSingleItemTable, X XBA : LDA.l !SINGLE_INDEX_TEMP : STA !LOCK_IN : XBA PLY RTL ;-------------------------------------------------------------------------------- CheckSingleItem: LSR #3 : TAX LDA.l !RNG_ITEM, X : STA !SINGLE_INDEX_BITMASK_TEMP ; load value to temporary PHX LDA !SINGLE_INDEX_TEMP : AND #$07 : TAX ; load 0-7 part into X LDA !SINGLE_INDEX_BITMASK_TEMP --- CPX.b #$00 : BEQ +++ LSR DEX BRA --- +++ PLX AND.b #$01 RTS ;-------------------------------------------------------------------------------- MarkRNGItemSingle: ;STA !SINGLE_INDEX_TEMP LSR #3 : STA !SINGLE_INDEX_OFFSET_TEMP : TAX LDA.l !RNG_ITEM, X STA.l !SINGLE_INDEX_BITMASK_TEMP LDA.l !SINGLE_INDEX_TEMP : AND #$07 : TAX ; load 0-7 part into X LDA.b #01 --- CPX.b #$00 : BEQ +++ ASL DEX BRA --- +++ PHA LDA.l !SINGLE_INDEX_OFFSET_TEMP : TAX PLA ORA.l !SINGLE_INDEX_BITMASK_TEMP STA.l !RNG_ITEM, X RTS ;-------------------------------------------------------------------------------- GetRNGItemMulti: LDA !LOCK_IN : CMP #$FF : BEQ + : TAX : XBA : LDA.l RNGMultiItemTable, X : RTL : + LDX.b #$00 - ; reroll JSL.l GetRandomInt : AND.b #$7F ; select random value INX : CPX #$7F : !BLT + : LDA.b 00 : BRA .done : + ; default to 0 if too many attempts CMP.l RNGMultiTableSize : !BGE - .done STA !LOCK_IN TAX : XBA : LDA.l RNGMultiItemTable, X RTL ;-------------------------------------------------------------------------------- IncrementItemCounters: PHX : PHA LDX.b #$00 - LDA.l ItemSubstitutionRules, X CMP.b #$FF : BEQ .exit CMP 1,s : BNE .noMatch .match PHX TXA : LSR #2 : TAX LDA.l !ITEM_LIMIT_COUNTS, X : INC : STA.l !ITEM_LIMIT_COUNTS, X PLX BEQ .exit .noMatch INX #4 BRA - .exit PLA : PLX RTS ;-------------------------------------------------------------------------------- AttemptItemSubstitution: PHX : PHA LDA.l config_multiworld BEQ + PLA : JSL alttp_multiworld_replace_item ; Replace item from multiworld table if needed BRA .exit + PLA ; PHA ; LDX.b #$00 ; - ; LDA.l ItemSubstitutionRules, X ; CMP.b #$FF : BEQ .exit ; CMP 1,s : BNE .noMatch ; .match ; PHX ; TXA : LSR #2 : TAX ; LDA.l !ITEM_LIMIT_COUNTS, X ; PLX ; CMP.l ItemSubstitutionRules+1, X : !BLT + ; LDA.l ItemSubstitutionRules+2, X : STA 1,s ; + ; BEQ .exit ; .noMatch ; INX #4 ; BRA - .exit PLX RTS AttemptItemSubstitutionLong: ;JSR AttemptItemSubstitution PHA : LDA config_multiworld : BEQ + PLA JSL alttp_multiworld_replace_graphics BRA .end + PLA .end RTL ; ; Enables the light cone temporarily when picking up items in a dark room without the lamp ; EnableTemporaryCone: LDA $7EC005 ; Check if dark room BEQ + LDA $7EF34A ; Check if we have lamp BNE + LDA $045A ; Check if torches are lit BNE + REP #$20 LDA $7E00A0 CMP #$0055 ; Check if we're in secret passage BEQ + CMP #$0109 ; Check if we're in the potion shop BEQ + ; (check both bytes or problems will happen in PoD) CMP #$00E4 ; Check if we're in old man's cave (the save location) BEQ + CMP #$010A ; Check if we're in aginah's cave BEQ + SEP #$20 LDA #$01 STA $1D ; Enable color math for BG1 STA $0458 ; Set the "Lamp in dark room flag" temporarily JSL $00F568 ; JSL OrientLampBg - Updates BG1 scroll positions for the lamp cone ; Write the scroll positions to the PPU registers LDA $E0 : STA $120 : STA $210D LDA $E6 : STA $124 : STA $210E + SEP #$20 RTS DisableTemporaryCone: PHA LDA $7EC005 ; Check if dark room BEQ + LDA $7EF34A ; Check if we have lamp BNE + LDA #$00 STA $1D STA $458 ; Disable the light cone while picking up an item + PLA CMP #$02 : BEQ + STZ $02E4 + RTL ;-------------------------------------------------------------------------------- CountBottles: LDX.b #$00 LDA $7EF35C : BEQ ++ : INX ++ : LDA $7EF35D : BEQ ++ : INX ++ : LDA $7EF35E : BEQ ++ : INX ++ : LDA $7EF35F : BEQ ++ : INX ++ TXA RTS CountBottlesLong: JSR CountBottles RTL ;-------------------------------------------------------------------------------- ;ActivateGoal: ; STZ $11 ; STZ $B0 ;JML.l StatsFinalPrep ;-------------------------------------------------------------------------------- Decomp_spr_high_extended: cpy #$f0 bcs .extended lda $d033,y : sta $ca lda $d112,y : sta $c9 lda $d1f1,y : sta $c8 jml Decomp_spr_high_extended_return .extended tya and #$0f phx tax lda.l .bank,x : sta $ca lda.l .high,x : sta $c9 lda.l .low,x : sta $c8 plx jml Decomp_spr_high_extended_return .bank db GFX_SM_Items>>16, $00, $00, $00, $00, $00, $00, $00 .high db GFX_SM_Items>>8, $00, $00, $00, $00, $00, $00, $00 .low db GFX_SM_Items, $00, $00, $00, $00, $00, $00, $00
; ; .. X. .X XX ; .. .. .. .. ; ; .. X. .X XX ; X. X. X. X. ; ; .. X. .X XX ; .X .X .X .X ; ; .. X. .X XX ; XX XX XX XX SECTION rodata_driver PUBLIC textpixl .textpixl defb 0x00, 0x05, 0x06, 0x07 defb 0x08, 0x09, 0x0a, 0x0b defb 0x0c, 0x10, 0x11, 0x12 defb 0x13, 0x14, 0x15, 0x16
// Version information for the "UsageEnvironment" library // Copyright (c) 1996-2020 Live Networks, Inc. All rights reserved. #ifndef _USAGEENVIRONMENT_VERSION_HH #define _USAGEENVIRONMENT_VERSION_HH #define USAGEENVIRONMENT_LIBRARY_VERSION_STRING "2020.03.06" #define USAGEENVIRONMENT_LIBRARY_VERSION_INT 1583452800 #endif
SECTION code_clib SECTION code_fp_math48 PUBLIC cm48_sccz80p_dldpsh cm48_sccz80p_dldpsh: ; sccz80 float primitive ; Push float pointed to by HL onto stack. ; ; enter : HL = double * (sccz80 format) ; ; exit : stack = double (sccz80 format) ; ; uses : af, bc, de, hl ld c,(hl) inc hl ld b,(hl) inc hl ld e,(hl) inc hl ld d,(hl) inc hl ld a,(hl) inc hl ld h,(hl) ld l,a ; hldebc = six bytes sccz80 float pop af push hl push de push bc push af ret
/*************************************************************************/ /* audio_stream_player_2d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ /* "Software"), to deal in the Software without restriction, including */ /* without limitation the rights to use, copy, modify, merge, publish, */ /* distribute, sublicense, and/or sell copies of the Software, and to */ /* permit persons to whom the Software is furnished to do so, subject to */ /* the following conditions: */ /* */ /* The above copyright notice and this permission notice shall be */ /* included in all copies or substantial portions of the Software. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "audio_stream_player_2d.h" #include "core/engine.h" #include "scene/2d/area_2d.h" #include "scene/main/viewport.h" void AudioStreamPlayer2D::_mix_audio() { if (!stream_playback.is_valid() || !active || (stream_paused && !stream_paused_fade_out)) { return; } if (setseek >= 0.0) { stream_playback->start(setseek); setseek = -1.0; //reset seek } //get data AudioFrame *buffer = mix_buffer.data(); auto buffer_size = mix_buffer.size(); if (stream_paused_fade_out) { // Short fadeout ramp buffer_size = MIN(buffer_size, 128); } stream_playback->mix(buffer, pitch_scale, buffer_size); //write all outputs for (int i = 0; i < output_count; i++) { Output current = outputs[i]; //see if current output exists, to keep volume ramp bool found = false; for (int j = i; j < prev_output_count; j++) { if (prev_outputs[j].viewport == current.viewport) { if (j != i) { SWAP(prev_outputs[j], prev_outputs[i]); } found = true; break; } } if (!found) { //create new if was not used before if (prev_output_count < MAX_OUTPUTS) { prev_outputs[prev_output_count] = prev_outputs[i]; //may be owned by another viewport prev_output_count++; } prev_outputs[i] = current; } //mix! AudioFrame target_volume = stream_paused_fade_out ? AudioFrame(0.f, 0.f) : current.vol; AudioFrame vol_prev = stream_paused_fade_in ? AudioFrame(0.f, 0.f) : prev_outputs[i].vol; AudioFrame vol_inc = (target_volume - vol_prev) / float(buffer_size); AudioFrame vol = stream_paused_fade_in ? AudioFrame(0.f, 0.f) : current.vol; int cc = AudioServer::get_singleton()->get_channel_count(); if (cc == 1) { if (!AudioServer::get_singleton()->thread_has_channel_mix_buffer(current.bus_index, 0)) continue; //may have been removed AudioFrame *target = AudioServer::get_singleton()->thread_get_channel_mix_buffer(current.bus_index, 0); for (decltype(buffer_size) j = 0; j < buffer_size; ++j) { target[j] += buffer[j] * vol; vol += vol_inc; } } else { AudioFrame *targets[4]; bool valid = true; for (int k = 0; k < cc; k++) { if (!AudioServer::get_singleton()->thread_has_channel_mix_buffer(current.bus_index, k)) { valid = false; //may have been removed break; } targets[k] = AudioServer::get_singleton()->thread_get_channel_mix_buffer(current.bus_index, k); } if (!valid) continue; for (decltype(buffer_size) j = 0; j < buffer_size; ++j) { AudioFrame frame = buffer[j] * vol; for (int k = 0; k < cc; k++) { targets[k][j] += frame; } vol += vol_inc; } } prev_outputs[i] = current; } prev_output_count = output_count; //stream is no longer active, disable this. if (!stream_playback->is_playing()) { active = false; } output_ready = false; stream_paused_fade_in = false; stream_paused_fade_out = false; } void AudioStreamPlayer2D::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { AudioServer::get_singleton()->add_callback(_mix_audios, this); if (autoplay && !Engine::get_singleton()->is_editor_hint()) { play(); } } if (p_what == NOTIFICATION_EXIT_TREE) { AudioServer::get_singleton()->remove_callback(_mix_audios, this); } if (p_what == NOTIFICATION_PAUSED) { if (!can_process()) { // Node can't process so we start fading out to silence set_stream_paused(true); } } if (p_what == NOTIFICATION_UNPAUSED) { set_stream_paused(false); } if (p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) { //update anything related to position first, if possible of course if (!output_ready) { List<Viewport *> viewports; Ref<World2D> world_2d = get_world_2d(); ERR_FAIL_COND(world_2d.is_null()); int new_output_count = 0; Vector2 global_pos = get_global_position(); int bus_index = AudioServer::get_singleton()->thread_find_bus_index(bus); //check if any area is diverting sound into a bus Physics2DDirectSpaceState *space_state = Physics2DServer::get_singleton()->space_get_direct_state(world_2d->get_space()); Physics2DDirectSpaceState::ShapeResult sr[MAX_INTERSECT_AREAS]; int areas = space_state->intersect_point(global_pos, sr, MAX_INTERSECT_AREAS, Set<RID>(), area_mask, false, true); for (int i = 0; i < areas; i++) { Area2D *area2d = Object::cast_to<Area2D>(sr[i].collider); if (!area2d) continue; if (!area2d->is_overriding_audio_bus()) continue; StringName bus_name = area2d->get_audio_bus_name(); bus_index = AudioServer::get_singleton()->thread_find_bus_index(bus_name); break; } world_2d->get_viewport_list(&viewports); for (List<Viewport *>::Element *E = viewports.front(); E; E = E->next()) { Viewport *vp = E->get(); if (vp->is_audio_listener_2d()) { //compute matrix to convert to screen Transform2D to_screen = vp->get_global_canvas_transform() * vp->get_canvas_transform(); Vector2 screen_size = vp->get_visible_rect().size; //screen in global is used for attenuation Vector2 screen_in_global = to_screen.affine_inverse().xform(screen_size * 0.5); float dist = global_pos.distance_to(screen_in_global); //distance to screen center if (dist > max_distance) continue; //can't hear this sound in this viewport float multiplier = Math::pow(1.0f - dist / max_distance, attenuation); multiplier *= Math::db2linear(volume_db); //also apply player volume! //point in screen is used for panning Vector2 point_in_screen = to_screen.xform(global_pos); float pan = CLAMP(point_in_screen.x / screen_size.width, 0.0, 1.0); float l = 1.0 - pan; float r = pan; outputs[new_output_count].vol = AudioFrame(l, r) * multiplier; outputs[new_output_count].bus_index = bus_index; outputs[new_output_count].viewport = vp; //keep pointer only for reference new_output_count++; if (new_output_count == MAX_OUTPUTS) break; } } output_count = new_output_count; output_ready = true; } //start playing if requested if (setplay >= 0.0) { setseek = setplay; active = true; setplay = -1; //do not update, this makes it easier to animate (will shut off otherwise) //_change_notify("playing"); //update property in editor } //stop playing if no longer active if (!active) { set_physics_process_internal(false); //do not update, this makes it easier to animate (will shut off otherwise) //_change_notify("playing"); //update property in editor emit_signal("finished"); } } } void AudioStreamPlayer2D::set_stream(Ref<AudioStream> p_stream) { AudioServer::get_singleton()->lock(); mix_buffer.resize(AudioServer::get_singleton()->thread_get_mix_buffer_size()); if (stream_playback.is_valid()) { stream_playback.unref(); stream.unref(); active = false; setseek = -1; } if (p_stream.is_valid()) { stream = p_stream; stream_playback = p_stream->instance_playback(); } AudioServer::get_singleton()->unlock(); if (p_stream.is_valid() && stream_playback.is_null()) { stream.unref(); } } Ref<AudioStream> AudioStreamPlayer2D::get_stream() const { return stream; } void AudioStreamPlayer2D::set_volume_db(float p_volume) { volume_db = p_volume; } float AudioStreamPlayer2D::get_volume_db() const { return volume_db; } void AudioStreamPlayer2D::set_pitch_scale(float p_pitch_scale) { ERR_FAIL_COND(p_pitch_scale <= 0.0); pitch_scale = p_pitch_scale; } float AudioStreamPlayer2D::get_pitch_scale() const { return pitch_scale; } void AudioStreamPlayer2D::play(float p_from_pos) { if (!is_playing()) { // Reset the prev_output_count if the stream is stopped prev_output_count = 0; } if (stream_playback.is_valid()) { active = true; setplay = p_from_pos; output_ready = false; set_physics_process_internal(true); } } void AudioStreamPlayer2D::seek(float p_seconds) { if (stream_playback.is_valid()) { setseek = p_seconds; } } void AudioStreamPlayer2D::stop() { if (stream_playback.is_valid()) { active = false; set_physics_process_internal(false); setplay = -1; } } bool AudioStreamPlayer2D::is_playing() const { if (stream_playback.is_valid()) { return active; // && stream_playback->is_playing(); } return false; } float AudioStreamPlayer2D::get_playback_position() { if (stream_playback.is_valid()) { return stream_playback->get_playback_position(); } return 0; } void AudioStreamPlayer2D::set_bus(const StringName &p_bus) { //if audio is active, must lock this AudioServer::get_singleton()->lock(); bus = p_bus; AudioServer::get_singleton()->unlock(); } StringName AudioStreamPlayer2D::get_bus() const { for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) { if (AudioServer::get_singleton()->get_bus_name(i) == bus) { return bus; } } return "Master"; } void AudioStreamPlayer2D::set_autoplay(bool p_enable) { autoplay = p_enable; } bool AudioStreamPlayer2D::is_autoplay_enabled() { return autoplay; } void AudioStreamPlayer2D::_set_playing(bool p_enable) { if (p_enable) play(); else stop(); } bool AudioStreamPlayer2D::_is_active() const { return active; } void AudioStreamPlayer2D::_validate_property(PropertyInfo &property) const { if (property.name == "bus") { String options; for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) { if (i > 0) options += ","; String name = AudioServer::get_singleton()->get_bus_name(i); options += name; } property.hint_string = options; } } void AudioStreamPlayer2D::_bus_layout_changed() { _change_notify(); } void AudioStreamPlayer2D::set_max_distance(float p_pixels) { ERR_FAIL_COND(p_pixels <= 0.0); max_distance = p_pixels; } float AudioStreamPlayer2D::get_max_distance() const { return max_distance; } void AudioStreamPlayer2D::set_attenuation(float p_curve) { attenuation = p_curve; } float AudioStreamPlayer2D::get_attenuation() const { return attenuation; } void AudioStreamPlayer2D::set_area_mask(uint32_t p_mask) { area_mask = p_mask; } uint32_t AudioStreamPlayer2D::get_area_mask() const { return area_mask; } void AudioStreamPlayer2D::set_stream_paused(bool p_pause) { if (p_pause != stream_paused) { stream_paused = p_pause; stream_paused_fade_in = !p_pause; stream_paused_fade_out = p_pause; } } bool AudioStreamPlayer2D::get_stream_paused() const { return stream_paused; } Ref<AudioStreamPlayback> AudioStreamPlayer2D::get_stream_playback() { return stream_playback; } void AudioStreamPlayer2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_stream", "stream"), &AudioStreamPlayer2D::set_stream); ClassDB::bind_method(D_METHOD("get_stream"), &AudioStreamPlayer2D::get_stream); ClassDB::bind_method(D_METHOD("set_volume_db", "volume_db"), &AudioStreamPlayer2D::set_volume_db); ClassDB::bind_method(D_METHOD("get_volume_db"), &AudioStreamPlayer2D::get_volume_db); ClassDB::bind_method(D_METHOD("set_pitch_scale", "pitch_scale"), &AudioStreamPlayer2D::set_pitch_scale); ClassDB::bind_method(D_METHOD("get_pitch_scale"), &AudioStreamPlayer2D::get_pitch_scale); ClassDB::bind_method(D_METHOD("play", "from_position"), &AudioStreamPlayer2D::play, DEFVAL(0.0)); ClassDB::bind_method(D_METHOD("seek", "to_position"), &AudioStreamPlayer2D::seek); ClassDB::bind_method(D_METHOD("stop"), &AudioStreamPlayer2D::stop); ClassDB::bind_method(D_METHOD("is_playing"), &AudioStreamPlayer2D::is_playing); ClassDB::bind_method(D_METHOD("get_playback_position"), &AudioStreamPlayer2D::get_playback_position); ClassDB::bind_method(D_METHOD("set_bus", "bus"), &AudioStreamPlayer2D::set_bus); ClassDB::bind_method(D_METHOD("get_bus"), &AudioStreamPlayer2D::get_bus); ClassDB::bind_method(D_METHOD("set_autoplay", "enable"), &AudioStreamPlayer2D::set_autoplay); ClassDB::bind_method(D_METHOD("is_autoplay_enabled"), &AudioStreamPlayer2D::is_autoplay_enabled); ClassDB::bind_method(D_METHOD("_set_playing", "enable"), &AudioStreamPlayer2D::_set_playing); ClassDB::bind_method(D_METHOD("_is_active"), &AudioStreamPlayer2D::_is_active); ClassDB::bind_method(D_METHOD("set_max_distance", "pixels"), &AudioStreamPlayer2D::set_max_distance); ClassDB::bind_method(D_METHOD("get_max_distance"), &AudioStreamPlayer2D::get_max_distance); ClassDB::bind_method(D_METHOD("set_attenuation", "curve"), &AudioStreamPlayer2D::set_attenuation); ClassDB::bind_method(D_METHOD("get_attenuation"), &AudioStreamPlayer2D::get_attenuation); ClassDB::bind_method(D_METHOD("set_area_mask", "mask"), &AudioStreamPlayer2D::set_area_mask); ClassDB::bind_method(D_METHOD("get_area_mask"), &AudioStreamPlayer2D::get_area_mask); ClassDB::bind_method(D_METHOD("set_stream_paused", "pause"), &AudioStreamPlayer2D::set_stream_paused); ClassDB::bind_method(D_METHOD("get_stream_paused"), &AudioStreamPlayer2D::get_stream_paused); ClassDB::bind_method(D_METHOD("get_stream_playback"), &AudioStreamPlayer2D::get_stream_playback); ClassDB::bind_method(D_METHOD("_bus_layout_changed"), &AudioStreamPlayer2D::_bus_layout_changed); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "stream", PROPERTY_HINT_RESOURCE_TYPE, "AudioStream"), "set_stream", "get_stream"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "volume_db", PROPERTY_HINT_RANGE, "-80,24"), "set_volume_db", "get_volume_db"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "pitch_scale", PROPERTY_HINT_RANGE, "0.01,32,0.01"), "set_pitch_scale", "get_pitch_scale"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "playing", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "_set_playing", "is_playing"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "autoplay"), "set_autoplay", "is_autoplay_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "stream_paused", PROPERTY_HINT_NONE, ""), "set_stream_paused", "get_stream_paused"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "max_distance", PROPERTY_HINT_EXP_RANGE, "1,4096,1,or_greater"), "set_max_distance", "get_max_distance"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "attenuation", PROPERTY_HINT_EXP_EASING, "attenuation"), "set_attenuation", "get_attenuation"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "bus", PROPERTY_HINT_ENUM, ""), "set_bus", "get_bus"); ADD_PROPERTY(PropertyInfo(Variant::INT, "area_mask", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_area_mask", "get_area_mask"); ADD_SIGNAL(MethodInfo("finished")); } AudioStreamPlayer2D::AudioStreamPlayer2D() { volume_db = 0; pitch_scale = 1.0; autoplay = false; setseek = -1; active = false; output_count = 0; prev_output_count = 0; max_distance = 2000; attenuation = 1; setplay = -1; output_ready = false; area_mask = 1; stream_paused = false; stream_paused_fade_in = false; stream_paused_fade_out = false; AudioServer::get_singleton()->connect("bus_layout_changed", this, "_bus_layout_changed"); } AudioStreamPlayer2D::~AudioStreamPlayer2D() { }
; A060783: Number of conics which pass through 3 points and are bitangent to a general curve of order n. ; 0,0,4,36,132,340,720,1344,2296,3672,5580,8140,11484,15756,21112,27720,35760,45424,56916,70452,86260,104580,125664,149776,177192,208200,243100,282204,325836,374332,428040,487320,552544,624096,702372,787780,880740,981684,1091056,1209312,1336920,1474360,1622124,1780716,1950652,2132460,2326680,2533864,2754576,2989392,3238900,3503700,3784404,4081636,4396032,4728240,5078920,5448744,5838396,6248572,6679980,7133340,7609384,8108856,8632512,9181120,9755460,10356324,10984516,11640852,12326160,13041280,13787064,14564376,15374092,16217100,17094300,18006604,18954936,19940232,20963440,22025520,23127444,24270196,25454772,26682180,27953440,29269584,30631656,32040712,33497820,35004060,36560524,38168316,39828552,41542360,43310880,45135264,47016676,48956292,50955300,53014900,55136304,57320736,59569432,61883640,64264620,66713644,69231996,71820972,74481880,77216040,80024784,82909456,85871412,88912020,92032660,95234724,98519616,101888752,105343560,108885480,112515964,116236476,120048492,123953500,127953000,132048504,136241536,140533632,144926340,149421220,154019844,158723796,163534672,168454080,173483640,178624984,183879756,189249612,194736220,200341260,206066424,211913416,217883952,223979760,230202580,236554164,243036276,249650692,256399200,263283600,270305704,277467336,284770332,292216540,299807820,307546044,315433096,323470872,331661280,340006240,348507684,357167556,365987812,374970420,384117360,393430624,402912216,412564152,422388460,432387180,442562364,452916076,463450392,474167400,485069200,496157904,507435636,518904532,530566740,542424420,554479744,566734896,579192072,591853480,604721340,617797884,631085356,644586012,658302120,672235960,686389824,700766016,715366852,730194660,745251780,760540564,776063376,791822592,807820600,824059800,840542604,857271436,874248732,891476940,908958520,926695944,944691696,962948272,981468180,1000253940,1019308084,1038633156,1058231712,1078106320,1098259560,1118694024,1139412316,1160417052,1181710860,1203296380,1225176264,1247353176,1269829792,1292608800,1315692900,1339084804,1362787236,1386802932,1411134640,1435785120,1460757144,1486053496,1511676972,1537630380,1563916540,1590538284,1617498456,1644799912,1672445520,1700438160,1728780724,1757476116,1786527252,1815937060,1845708480,1875844464,1906347976,1937221992 sub $0,1 mov $3,$0 lpb $0 sub $0,1 add $3,$0 add $2,$3 add $1,$2 lpe mul $1,4
/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ #include <cstdio> #include <cstdlib> #include <gtest/gtest.h> #include <faiss/IndexBinaryFlat.h> #include <faiss/utils/hamming.h> TEST(BinaryFlat, accuracy) { // dimension of the vectors to index int d = 64; // size of the database we plan to index size_t nb = 1000; // make the index object and train it faiss::IndexBinaryFlat index(d); srand(35); std::vector<uint8_t> database(nb * (d / 8)); for (size_t i = 0; i < nb * (d / 8); i++) { database[i] = rand() % 0x100; } { // populating the database index.add(nb, database.data()); } size_t nq = 200; { // searching the database std::vector<uint8_t> queries(nq * (d / 8)); for (size_t i = 0; i < nq * (d / 8); i++) { queries[i] = rand() % 0x100; } int k = 5; std::vector<faiss::IndexBinary::idx_t> nns(k * nq); std::vector<int> dis(k * nq); index.search(nq, queries.data(), k, dis.data(), nns.data()); for (size_t i = 0; i < nq; ++i) { faiss::HammingComputer8 hc(queries.data() + i * (d / 8), d / 8); hamdis_t dist_min = hc.compute(database.data()); for (size_t j = 1; j < nb; ++j) { hamdis_t dist = hc.compute(database.data() + j * (d / 8)); if (dist < dist_min) { dist_min = dist; } } EXPECT_EQ(dist_min, dis[k * i]); } } }
SECTION bss_fp_mbf32 PUBLIC MULVAL MULVAL: defb 0,0,0
SECTION .text GLOBAL test test: pmuludq xmm0, xmm0 pmuludq xmm0, xmm1 pmuludq xmm0, xmm2 pmuludq xmm0, xmm3 pmuludq xmm0, xmm4 pmuludq xmm0, xmm5 pmuludq xmm0, xmm6 pmuludq xmm0, xmm7 pmuludq xmm0, xmm8 pmuludq xmm0, xmm9 pmuludq xmm0, xmm10 pmuludq xmm0, xmm11 pmuludq xmm0, xmm12 pmuludq xmm0, xmm13 pmuludq xmm0, xmm14 pmuludq xmm0, xmm15 pmuludq xmm1, xmm0 pmuludq xmm1, xmm1 pmuludq xmm1, xmm2 pmuludq xmm1, xmm3 pmuludq xmm1, xmm4 pmuludq xmm1, xmm5 pmuludq xmm1, xmm6 pmuludq xmm1, xmm7 pmuludq xmm1, xmm8 pmuludq xmm1, xmm9 pmuludq xmm1, xmm10 pmuludq xmm1, xmm11 pmuludq xmm1, xmm12 pmuludq xmm1, xmm13 pmuludq xmm1, xmm14 pmuludq xmm1, xmm15 pmuludq xmm2, xmm0 pmuludq xmm2, xmm1 pmuludq xmm2, xmm2 pmuludq xmm2, xmm3 pmuludq xmm2, xmm4 pmuludq xmm2, xmm5 pmuludq xmm2, xmm6 pmuludq xmm2, xmm7 pmuludq xmm2, xmm8 pmuludq xmm2, xmm9 pmuludq xmm2, xmm10 pmuludq xmm2, xmm11 pmuludq xmm2, xmm12 pmuludq xmm2, xmm13 pmuludq xmm2, xmm14 pmuludq xmm2, xmm15 pmuludq xmm3, xmm0 pmuludq xmm3, xmm1 pmuludq xmm3, xmm2 pmuludq xmm3, xmm3 pmuludq xmm3, xmm4 pmuludq xmm3, xmm5 pmuludq xmm3, xmm6 pmuludq xmm3, xmm7 pmuludq xmm3, xmm8 pmuludq xmm3, xmm9 pmuludq xmm3, xmm10 pmuludq xmm3, xmm11 pmuludq xmm3, xmm12 pmuludq xmm3, xmm13 pmuludq xmm3, xmm14 pmuludq xmm3, xmm15 pmuludq xmm4, xmm0 pmuludq xmm4, xmm1 pmuludq xmm4, xmm2 pmuludq xmm4, xmm3 pmuludq xmm4, xmm4 pmuludq xmm4, xmm5 pmuludq xmm4, xmm6 pmuludq xmm4, xmm7 pmuludq xmm4, xmm8 pmuludq xmm4, xmm9 pmuludq xmm4, xmm10 pmuludq xmm4, xmm11 pmuludq xmm4, xmm12 pmuludq xmm4, xmm13 pmuludq xmm4, xmm14 pmuludq xmm4, xmm15 pmuludq xmm5, xmm0 pmuludq xmm5, xmm1 pmuludq xmm5, xmm2 pmuludq xmm5, xmm3 pmuludq xmm5, xmm4 pmuludq xmm5, xmm5 pmuludq xmm5, xmm6 pmuludq xmm5, xmm7 pmuludq xmm5, xmm8 pmuludq xmm5, xmm9 pmuludq xmm5, xmm10 pmuludq xmm5, xmm11 pmuludq xmm5, xmm12 pmuludq xmm5, xmm13 pmuludq xmm5, xmm14 pmuludq xmm5, xmm15 pmuludq xmm6, xmm0 pmuludq xmm6, xmm1 pmuludq xmm6, xmm2 pmuludq xmm6, xmm3 pmuludq xmm6, xmm4 pmuludq xmm6, xmm5 pmuludq xmm6, xmm6 pmuludq xmm6, xmm7 pmuludq xmm6, xmm8 pmuludq xmm6, xmm9 pmuludq xmm6, xmm10 pmuludq xmm6, xmm11 pmuludq xmm6, xmm12 pmuludq xmm6, xmm13 pmuludq xmm6, xmm14 pmuludq xmm6, xmm15 pmuludq xmm7, xmm0 pmuludq xmm7, xmm1 pmuludq xmm7, xmm2 pmuludq xmm7, xmm3 pmuludq xmm7, xmm4 pmuludq xmm7, xmm5 pmuludq xmm7, xmm6 pmuludq xmm7, xmm7 pmuludq xmm7, xmm8 pmuludq xmm7, xmm9 pmuludq xmm7, xmm10 pmuludq xmm7, xmm11 pmuludq xmm7, xmm12 pmuludq xmm7, xmm13 pmuludq xmm7, xmm14 pmuludq xmm7, xmm15 pmuludq xmm8, xmm0 pmuludq xmm8, xmm1 pmuludq xmm8, xmm2 pmuludq xmm8, xmm3 pmuludq xmm8, xmm4 pmuludq xmm8, xmm5 pmuludq xmm8, xmm6 pmuludq xmm8, xmm7 pmuludq xmm8, xmm8 pmuludq xmm8, xmm9 pmuludq xmm8, xmm10 pmuludq xmm8, xmm11 pmuludq xmm8, xmm12 pmuludq xmm8, xmm13 pmuludq xmm8, xmm14 pmuludq xmm8, xmm15 pmuludq xmm9, xmm0 pmuludq xmm9, xmm1 pmuludq xmm9, xmm2 pmuludq xmm9, xmm3 pmuludq xmm9, xmm4 pmuludq xmm9, xmm5 pmuludq xmm9, xmm6 pmuludq xmm9, xmm7 pmuludq xmm9, xmm8 pmuludq xmm9, xmm9 pmuludq xmm9, xmm10 pmuludq xmm9, xmm11 pmuludq xmm9, xmm12 pmuludq xmm9, xmm13 pmuludq xmm9, xmm14 pmuludq xmm9, xmm15 pmuludq xmm10, xmm0 pmuludq xmm10, xmm1 pmuludq xmm10, xmm2 pmuludq xmm10, xmm3 pmuludq xmm10, xmm4 pmuludq xmm10, xmm5 pmuludq xmm10, xmm6 pmuludq xmm10, xmm7 pmuludq xmm10, xmm8 pmuludq xmm10, xmm9 pmuludq xmm10, xmm10 pmuludq xmm10, xmm11 pmuludq xmm10, xmm12 pmuludq xmm10, xmm13 pmuludq xmm10, xmm14 pmuludq xmm10, xmm15 pmuludq xmm11, xmm0 pmuludq xmm11, xmm1 pmuludq xmm11, xmm2 pmuludq xmm11, xmm3 pmuludq xmm11, xmm4 pmuludq xmm11, xmm5 pmuludq xmm11, xmm6 pmuludq xmm11, xmm7 pmuludq xmm11, xmm8 pmuludq xmm11, xmm9 pmuludq xmm11, xmm10 pmuludq xmm11, xmm11 pmuludq xmm11, xmm12 pmuludq xmm11, xmm13 pmuludq xmm11, xmm14 pmuludq xmm11, xmm15 pmuludq xmm12, xmm0 pmuludq xmm12, xmm1 pmuludq xmm12, xmm2 pmuludq xmm12, xmm3 pmuludq xmm12, xmm4 pmuludq xmm12, xmm5 pmuludq xmm12, xmm6 pmuludq xmm12, xmm7 pmuludq xmm12, xmm8 pmuludq xmm12, xmm9 pmuludq xmm12, xmm10 pmuludq xmm12, xmm11 pmuludq xmm12, xmm12 pmuludq xmm12, xmm13 pmuludq xmm12, xmm14 pmuludq xmm12, xmm15 pmuludq xmm13, xmm0 pmuludq xmm13, xmm1 pmuludq xmm13, xmm2 pmuludq xmm13, xmm3 pmuludq xmm13, xmm4 pmuludq xmm13, xmm5 pmuludq xmm13, xmm6 pmuludq xmm13, xmm7 pmuludq xmm13, xmm8 pmuludq xmm13, xmm9 pmuludq xmm13, xmm10 pmuludq xmm13, xmm11 pmuludq xmm13, xmm12 pmuludq xmm13, xmm13 pmuludq xmm13, xmm14 pmuludq xmm13, xmm15 pmuludq xmm14, xmm0 pmuludq xmm14, xmm1 pmuludq xmm14, xmm2 pmuludq xmm14, xmm3 pmuludq xmm14, xmm4 pmuludq xmm14, xmm5 pmuludq xmm14, xmm6 pmuludq xmm14, xmm7 pmuludq xmm14, xmm8 pmuludq xmm14, xmm9 pmuludq xmm14, xmm10 pmuludq xmm14, xmm11 pmuludq xmm14, xmm12 pmuludq xmm14, xmm13 pmuludq xmm14, xmm14 pmuludq xmm14, xmm15 pmuludq xmm0, xmm0 pmuludq xmm0, xmm1 pmuludq xmm0, xmm2 pmuludq xmm0, xmm3 pmuludq xmm0, xmm4 pmuludq xmm0, xmm5 pmuludq xmm0, xmm6 pmuludq xmm0, xmm7 pmuludq xmm0, xmm8 pmuludq xmm0, xmm9 pmuludq xmm0, xmm10 pmuludq xmm0, xmm11 pmuludq xmm0, xmm12 pmuludq xmm0, xmm13 pmuludq xmm0, xmm14 pmuludq xmm0, xmm15
;------------------- ; test for ldd/std ;------------------- .def yl = r28 .def yh = r29 .def zl = r30 .def zh = r31 ;------------------- ldi r16,0xff ldi r24,0x10 mov r7 ,r16 mov r8 ,r24 ldi r16,0x20 ldi r24,0x30 ;------------------- ldi yh,0x01 ldi yl,0x10 std y+0,r7 std y+1,r8 std y+2,r16 std y+3,r24 ldd r6 ,y+0 ldd r9 ,y+1 ldd r17,y+2 ldd r25,y+3 dec r6 inc r9 inc r17 inc r25 ;------------------- std y+60,r6 std y+61,r9 std y+62,r17 std y+63,r25 ldd r5 ,y+60 ldd r10,y+61 ldd r18,y+62 ldd r26,y+63 dec r5 inc r10 inc r18 inc r26 ;------------------- ldi zh,0x00 ldi zl,0xff std z+21,r5 std z+22,r10 std z+23,r18 std z+24,r26 ldd r4 ,z+21 ldd r11,z+22 ldd r19,z+23 ldd r27,z+24 dec r4 inc r11 inc r19 inc r27 ;------------------- std z+41,r4 std z+42,r11 std z+43,r19 std z+44,r27 ldd r3 ,z+41 ldd r12,z+42 ldd r20,z+43 ldd r28,z+44 dec r3 inc r12 inc r20 inc r28 ;------------------- std z+60,r3 std z+61,r12 std z+62,r20 std z+63,r28 ;------------------- ldi r16,0xff sts 0xffff,r16 halt: rjmp halt
############################################################################### # 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. ############################################################################### .text .p2align 4, 0x90 .globl _y8_cpDiv_BNU32 _y8_cpDiv_BNU32: push %rbx push %rbp push %r12 push %r13 push %r14 push %r15 sub $(40), %rsp movslq %ecx, %rcx movslq %r9d, %r9 .L__000Dgas_1: mov (-4)(%rdx,%rcx,4), %eax test %eax, %eax jnz .L__000Egas_1 sub $(1), %rcx jg .L__000Dgas_1 add $(1), %rcx .L__000Egas_1: .L__000Fgas_1: mov (-4)(%r8,%r9,4), %eax test %eax, %eax jnz .L__0010gas_1 sub $(1), %r9 jg .L__000Fgas_1 add $(1), %r9 .L__0010gas_1: mov %rdx, %r10 mov %rcx, %r11 .Lspec_case1gas_1: cmp %r9, %rcx jae .Lspec_case2gas_1 test %rdi, %rdi jz .Lspec_case1_quitgas_1 movl $(0), (%rdi) movl $(1), (%rsi) .Lspec_case1_quitgas_1: mov %rcx, %rax add $(40), %rsp pop %r15 pop %r14 pop %r13 pop %r12 pop %rbp pop %rbx ret .Lspec_case2gas_1: cmp $(1), %r9 jnz .Lcommon_casegas_1 mov (%r8), %ebx xor %edx, %edx .Lspec_case2_loopgas_1: mov (-4)(%r10,%r11,4), %eax div %ebx test %rdi, %rdi je .Lspec_case2_contgas_1 mov %eax, (-4)(%rdi,%r11,4) .Lspec_case2_contgas_1: sub $(1), %r11 jg .Lspec_case2_loopgas_1 test %rdi, %rdi je .Lspec_case2_quitgas_1 .L__001Cgas_1: mov (-4)(%rdi,%rcx,4), %eax test %eax, %eax jnz .L__001Dgas_1 sub $(1), %rcx jg .L__001Cgas_1 add $(1), %rcx .L__001Dgas_1: movl %ecx, (%rsi) .Lspec_case2_quitgas_1: movl %edx, (%r10) mov $(1), %rax add $(40), %rsp pop %r15 pop %r14 pop %r13 pop %r12 pop %rbp pop %rbx ret .Lcommon_casegas_1: xor %eax, %eax mov %eax, (%r10,%r11,4) mov (-4)(%r8,%r9,4), %eax mov $(32), %ecx test %eax, %eax jz .L__002Egas_1 xor %ecx, %ecx .L__0029gas_1: test $(4294901760), %eax jnz .L__002Agas_1 shl $(16), %eax add $(16), %ecx .L__002Agas_1: test $(4278190080), %eax jnz .L__002Bgas_1 shl $(8), %eax add $(8), %ecx .L__002Bgas_1: test $(4026531840), %eax jnz .L__002Cgas_1 shl $(4), %eax add $(4), %ecx .L__002Cgas_1: test $(3221225472), %eax jnz .L__002Dgas_1 shl $(2), %eax add $(2), %ecx .L__002Dgas_1: test $(2147483648), %eax jnz .L__002Egas_1 add $(1), %ecx .L__002Egas_1: test %ecx, %ecx jz .Ldivisiongas_1 mov %r9, %r15 mov (-4)(%r8,%r15,4), %r12d sub $(1), %r15 jz .L__0030gas_1 .L__002Fgas_1: mov (-4)(%r8,%r15,4), %r13d shld %cl, %r13d, %r12d mov %r12d, (%r8,%r15,4) mov %r13d, %r12d sub $(1), %r15 jg .L__002Fgas_1 .L__0030gas_1: shl %cl, %r12d mov %r12d, (%r8) lea (1)(%r11), %r15 mov (-4)(%r10,%r15,4), %r12d sub $(1), %r15 jz .L__0032gas_1 .L__0031gas_1: mov (-4)(%r10,%r15,4), %r13d shld %cl, %r13d, %r12d mov %r12d, (%r10,%r15,4) mov %r13d, %r12d sub $(1), %r15 jg .L__0031gas_1 .L__0032gas_1: shl %cl, %r12d mov %r12d, (%r10) .Ldivisiongas_1: mov (-4)(%r8,%r9,4), %ebx mov %r10, (%rsp) mov %r11, (8)(%rsp) sub %r9, %r11 mov %r11, (16)(%rsp) lea (%r10,%r11,4), %r10 .Ldivision_loopgas_1: mov (-4)(%r10,%r9,4), %rax xor %rdx, %rdx div %rbx mov %rax, %r12 mov %rdx, %r13 mov (-8)(%r8,%r9,4), %ebp .Ltune_loopgas_1: mov $(18446744069414584320), %r15 and %rax, %r15 jne .Ltunegas_1 mul %rbp mov %r13, %r14 shl $(32), %r14 mov (-8)(%r10,%r9,4), %edx or %r14, %rdx cmp %rdx, %rax jbe .Lmul_and_subgas_1 .Ltunegas_1: sub $(1), %r12 add %ebx, %r13d mov %r12, %rax jnc .Ltune_loopgas_1 .Lmul_and_subgas_1: mov %r9, %r15 mov %r12d, %ebp xor %r13, %r13 xor %r14, %r14 sub $(2), %r15 jl .L__0034gas_1 .L__0033gas_1: mov (%r13,%r8), %rax mul %rbp add %r14, %rax adc $(0), %rdx xor %r14, %r14 sub %rax, (%r13,%r10) sbb %rdx, %r14 neg %r14 add $(8), %r13 sub $(2), %r15 jge .L__0033gas_1 add $(2), %r15 jz .L__0035gas_1 .L__0034gas_1: mov (%r13,%r8), %eax mul %ebp add %r14d, %eax adc $(0), %edx xor %r14d, %r14d sub %eax, (%r13,%r10) sbb %edx, %r14d neg %r14d .L__0035gas_1: mov %r14, %rbp sub %ebp, (%r10,%r9,4) jnc .Lstore_duotationgas_1 sub $(1), %r12d mov %r9, %r15 xor %rax, %rax xor %r13, %r13 sub $(2), %r15 jl .L__0037gas_1 clc .L__0036gas_1: mov (%r10,%r13,8), %r14 mov (%r8,%r13,8), %rdx adc %rdx, %r14 mov %r14, (%r10,%r13,8) inc %r13 dec %r15 dec %r15 jge .L__0036gas_1 setc %al add %r13, %r13 add $(2), %r15 jz .L__0038gas_1 .L__0037gas_1: shr $(1), %eax mov (%r10,%r13,4), %r14d mov (%r8,%r13,4), %edx adc %edx, %r14d mov %r14d, (%r10,%r13,4) setc %al add $(1), %r13 .L__0038gas_1: add %eax, (%r10,%r9,4) .Lstore_duotationgas_1: test %rdi, %rdi jz .Lcont_division_loopgas_1 movl %r12d, (%rdi,%r11,4) .Lcont_division_loopgas_1: sub $(4), %r10 sub $(1), %r11 jge .Ldivision_loopgas_1 mov (%rsp), %r10 mov (8)(%rsp), %r11 test %ecx, %ecx jz .Lstore_resultsgas_1 mov %r9, %r15 push %r8 mov (%r8), %r13d sub $(1), %r15 jz .L__003Agas_1 .L__0039gas_1: mov (4)(%r8), %r12d shrd %cl, %r12d, %r13d mov %r13d, (%r8) add $(4), %r8 mov %r12d, %r13d sub $(1), %r15 jg .L__0039gas_1 .L__003Agas_1: shr %cl, %r13d mov %r13d, (%r8) pop %r8 mov %r11, %r15 push %r10 mov (%r10), %r13d sub $(1), %r15 jz .L__003Cgas_1 .L__003Bgas_1: mov (4)(%r10), %r12d shrd %cl, %r12d, %r13d mov %r13d, (%r10) add $(4), %r10 mov %r12d, %r13d sub $(1), %r15 jg .L__003Bgas_1 .L__003Cgas_1: shr %cl, %r13d mov %r13d, (%r10) pop %r10 .Lstore_resultsgas_1: test %rdi, %rdi jz .Lquitgas_1 mov (16)(%rsp), %rcx add $(1), %rcx .L__003Dgas_1: mov (-4)(%rdi,%rcx,4), %eax test %eax, %eax jnz .L__003Egas_1 sub $(1), %rcx jg .L__003Dgas_1 add $(1), %rcx .L__003Egas_1: movl %ecx, (%rsi) .Lquitgas_1: .L__003Fgas_1: mov (-4)(%r10,%r11,4), %eax test %eax, %eax jnz .L__0040gas_1 sub $(1), %r11 jg .L__003Fgas_1 add $(1), %r11 .L__0040gas_1: mov %r11, %rax add $(40), %rsp pop %r15 pop %r14 pop %r13 pop %r12 pop %rbp pop %rbx ret
//======================================================================== // // Splash.cc // // Copyright 2003-2013 Glyph & Cog, LLC // //======================================================================== #include <aconf.h> #ifdef USE_GCC_PRAGMAS #pragma implementation #endif #include <stdlib.h> #include <string.h> #include <limits.h> #include <math.h> #include "gmem.h" #include "gmempp.h" #include "SplashErrorCodes.h" #include "SplashMath.h" #include "SplashBitmap.h" #include "SplashState.h" #include "SplashPath.h" #include "SplashXPath.h" #include "SplashXPathScanner.h" #include "SplashPattern.h" #include "SplashScreen.h" #include "SplashFont.h" #include "SplashGlyphBitmap.h" #include "Splash.h" // the MSVC math.h doesn't define this #ifndef M_PI #define M_PI 3.14159265358979323846 #endif //------------------------------------------------------------------------ // distance of Bezier control point from center for circle approximation // = (4 * (sqrt(2) - 1) / 3) * r #define bezierCircle ((SplashCoord)0.55228475) #define bezierCircle2 ((SplashCoord)(0.5 * 0.55228475)) // Divide a 16-bit value (in [0, 255*255]) by 255, returning an 8-bit result. static inline Guchar div255(int x) { return (Guchar)((x + (x >> 8) + 0x80) >> 8); } // Clip x to lie in [0, 255]. static inline Guchar clip255(int x) { return x < 0 ? 0 : x > 255 ? 255 : x; } // Used by drawImage and fillImageMask to divide the target // quadrilateral into sections. struct ImageSection { int y0, y1; // actual y range int ia0, ia1; // vertex indices for edge A int ib0, ib1; // vertex indices for edge B SplashCoord xa0, ya0, xa1, ya1; // edge A SplashCoord dxdya; // slope of edge A SplashCoord xb0, yb0, xb1, yb1; // edge B SplashCoord dxdyb; // slope of edge B }; //------------------------------------------------------------------------ // SplashPipe //------------------------------------------------------------------------ #define splashPipeMaxStages 9 struct SplashPipe { // source pattern SplashPattern *pattern; // source alpha and color Guchar aInput; SplashColor cSrcVal; // special cases and result color GBool noTransparency; GBool shapeOnly; SplashPipeResultColorCtrl resultColorCtrl; // non-isolated group correction // (this is only used when Splash::composite() is called to composite // a non-isolated group onto the backdrop) GBool nonIsolatedGroup; // the "run" function void (Splash::*run)(SplashPipe *pipe, int x0, int x1, int y, Guchar *shapePtr, SplashColorPtr cSrcPtr); }; SplashPipeResultColorCtrl Splash::pipeResultColorNoAlphaBlend[] = { splashPipeResultColorNoAlphaBlendMono, splashPipeResultColorNoAlphaBlendMono, splashPipeResultColorNoAlphaBlendRGB, splashPipeResultColorNoAlphaBlendRGB #if SPLASH_CMYK , splashPipeResultColorNoAlphaBlendCMYK #endif }; SplashPipeResultColorCtrl Splash::pipeResultColorAlphaNoBlend[] = { splashPipeResultColorAlphaNoBlendMono, splashPipeResultColorAlphaNoBlendMono, splashPipeResultColorAlphaNoBlendRGB, splashPipeResultColorAlphaNoBlendRGB #if SPLASH_CMYK , splashPipeResultColorAlphaNoBlendCMYK #endif }; SplashPipeResultColorCtrl Splash::pipeResultColorAlphaBlend[] = { splashPipeResultColorAlphaBlendMono, splashPipeResultColorAlphaBlendMono, splashPipeResultColorAlphaBlendRGB, splashPipeResultColorAlphaBlendRGB #if SPLASH_CMYK , splashPipeResultColorAlphaBlendCMYK #endif }; //------------------------------------------------------------------------ // modified region //------------------------------------------------------------------------ void Splash::clearModRegion() { modXMin = bitmap->getWidth(); modYMin = bitmap->getHeight(); modXMax = -1; modYMax = -1; } inline void Splash::updateModX(int x) { if (x < modXMin) { modXMin = x; } if (x > modXMax) { modXMax = x; } } inline void Splash::updateModY(int y) { if (y < modYMin) { modYMin = y; } if (y > modYMax) { modYMax = y; } } //------------------------------------------------------------------------ // pipeline //------------------------------------------------------------------------ inline void Splash::pipeInit(SplashPipe *pipe, SplashPattern *pattern, Guchar aInput, GBool usesShape, GBool nonIsolatedGroup) { pipe->pattern = NULL; // source color if (pattern && pattern->isStatic()) { pattern->getColor(0, 0, pipe->cSrcVal); pipe->pattern = NULL; } else { pipe->pattern = pattern; } // source alpha pipe->aInput = aInput; // special cases pipe->noTransparency = aInput == 255 && !state->softMask && !usesShape && !state->inNonIsolatedGroup && !state->inKnockoutGroup && !nonIsolatedGroup && state->overprintMask == 0xffffffff; pipe->shapeOnly = aInput == 255 && !state->softMask && usesShape && !state->inNonIsolatedGroup && !state->inKnockoutGroup && !nonIsolatedGroup && state->overprintMask == 0xffffffff; // result color if (pipe->noTransparency) { // the !state->blendFunc case is handled separately in pipeRun pipe->resultColorCtrl = pipeResultColorNoAlphaBlend[bitmap->mode]; } else if (!state->blendFunc) { pipe->resultColorCtrl = pipeResultColorAlphaNoBlend[bitmap->mode]; } else { pipe->resultColorCtrl = pipeResultColorAlphaBlend[bitmap->mode]; } // non-isolated group correction pipe->nonIsolatedGroup = nonIsolatedGroup; // select the 'run' function pipe->run = &Splash::pipeRun; if (!pipe->pattern && pipe->noTransparency && !state->blendFunc) { if (bitmap->mode == splashModeMono1 && !bitmap->alpha) { pipe->run = &Splash::pipeRunSimpleMono1; } else if (bitmap->mode == splashModeMono8 && bitmap->alpha) { pipe->run = &Splash::pipeRunSimpleMono8; } else if (bitmap->mode == splashModeRGB8 && bitmap->alpha) { pipe->run = &Splash::pipeRunSimpleRGB8; } else if (bitmap->mode == splashModeBGR8 && bitmap->alpha) { pipe->run = &Splash::pipeRunSimpleBGR8; #if SPLASH_CMYK } else if (bitmap->mode == splashModeCMYK8 && bitmap->alpha) { pipe->run = &Splash::pipeRunSimpleCMYK8; #endif } } else if (!pipe->pattern && pipe->shapeOnly && !state->blendFunc) { if (bitmap->mode == splashModeMono1 && !bitmap->alpha) { pipe->run = &Splash::pipeRunShapeMono1; } else if (bitmap->mode == splashModeMono8 && bitmap->alpha) { pipe->run = &Splash::pipeRunShapeMono8; } else if (bitmap->mode == splashModeRGB8 && bitmap->alpha) { pipe->run = &Splash::pipeRunShapeRGB8; } else if (bitmap->mode == splashModeBGR8 && bitmap->alpha) { pipe->run = &Splash::pipeRunShapeBGR8; #if SPLASH_CMYK } else if (bitmap->mode == splashModeCMYK8 && bitmap->alpha) { pipe->run = &Splash::pipeRunShapeCMYK8; #endif } } else if (!pipe->pattern && !pipe->noTransparency && !state->softMask && usesShape && !(state->inNonIsolatedGroup && groupBackBitmap->alpha) && !state->inKnockoutGroup && !state->blendFunc && !pipe->nonIsolatedGroup) { if (bitmap->mode == splashModeMono1 && !bitmap->alpha) { pipe->run = &Splash::pipeRunAAMono1; } else if (bitmap->mode == splashModeMono8 && bitmap->alpha) { pipe->run = &Splash::pipeRunAAMono8; } else if (bitmap->mode == splashModeRGB8 && bitmap->alpha) { pipe->run = &Splash::pipeRunAARGB8; } else if (bitmap->mode == splashModeBGR8 && bitmap->alpha) { pipe->run = &Splash::pipeRunAABGR8; #if SPLASH_CMYK } else if (bitmap->mode == splashModeCMYK8 && bitmap->alpha) { pipe->run = &Splash::pipeRunAACMYK8; #endif } } } // general case void Splash::pipeRun(SplashPipe *pipe, int x0, int x1, int y, Guchar *shapePtr, SplashColorPtr cSrcPtr) { Guchar *shapePtr2; Guchar shape, aSrc, aDest, alphaI, alphaIm1, alpha0, aResult; SplashColor cSrc, cDest, cBlend; Guchar shapeVal, cResult0, cResult1, cResult2, cResult3; int cSrcStride, shapeStride, x, lastX, t; SplashColorPtr destColorPtr; Guchar destColorMask; Guchar *destAlphaPtr; SplashColorPtr color0Ptr; Guchar color0Mask; Guchar *alpha0Ptr; SplashColorPtr softMaskPtr; #if SPLASH_CMYK SplashColor cSrc2, cDest2; #endif if (cSrcPtr && !pipe->pattern) { cSrcStride = bitmapComps; } else { cSrcPtr = pipe->cSrcVal; cSrcStride = 0; } if (shapePtr) { shapePtr2 = shapePtr; shapeStride = 1; for (; x0 <= x1; ++x0) { if (*shapePtr2) { break; } cSrcPtr += cSrcStride; ++shapePtr2; } } else { shapeVal = 0xff; shapePtr2 = &shapeVal; shapeStride = 0; } if (x0 > x1) { return; } updateModX(x0); updateModY(y); lastX = x0; if (bitmap->mode == splashModeMono1) { destColorPtr = &bitmap->data[y * bitmap->rowSize + (x0 >> 3)]; destColorMask = 0x80 >> (x0 & 7); } else { destColorPtr = &bitmap->data[y * bitmap->rowSize + x0 * bitmapComps]; destColorMask = 0; // make gcc happy } if (bitmap->alpha) { destAlphaPtr = &bitmap->alpha[y * bitmap->width + x0]; } else { destAlphaPtr = NULL; } if (state->softMask) { softMaskPtr = &state->softMask->data[y * state->softMask->rowSize + x0]; } else { softMaskPtr = NULL; } if (state->inKnockoutGroup) { if (bitmap->mode == splashModeMono1) { color0Ptr = &groupBackBitmap->data[(groupBackY + y) * groupBackBitmap->rowSize + ((groupBackX + x0) >> 3)]; color0Mask = 0x80 >> ((groupBackX + x0) & 7); } else { color0Ptr = &groupBackBitmap->data[(groupBackY + y) * groupBackBitmap->rowSize + (groupBackX + x0) * bitmapComps]; color0Mask = 0; // make gcc happy } } else { color0Ptr = NULL; color0Mask = 0; // make gcc happy } if (state->inNonIsolatedGroup && groupBackBitmap->alpha) { alpha0Ptr = &groupBackBitmap->alpha[(groupBackY + y) * groupBackBitmap->width + (groupBackX + x0)]; } else { alpha0Ptr = NULL; } for (x = x0; x <= x1; ++x) { //----- shape shape = *shapePtr2; if (!shape) { if (bitmap->mode == splashModeMono1) { destColorPtr += destColorMask & 1; destColorMask = (destColorMask << 7) | (destColorMask >> 1); } else { destColorPtr += bitmapComps; } if (destAlphaPtr) { ++destAlphaPtr; } if (softMaskPtr) { ++softMaskPtr; } if (color0Ptr) { if (bitmap->mode == splashModeMono1) { color0Ptr += color0Mask & 1; color0Mask = (color0Mask << 7) | (color0Mask >> 1); } else { color0Ptr += bitmapComps; } } if (alpha0Ptr) { ++alpha0Ptr; } cSrcPtr += cSrcStride; shapePtr2 += shapeStride; continue; } lastX = x; //----- source color // static pattern: handled in pipeInit // fixed color: handled in pipeInit // dynamic pattern if (pipe->pattern) { pipe->pattern->getColor(x, y, pipe->cSrcVal); } cResult0 = cResult1 = cResult2 = cResult3 = 0; // make gcc happy if (pipe->noTransparency && !state->blendFunc) { //----- result color switch (bitmap->mode) { case splashModeMono1: case splashModeMono8: cResult0 = state->grayTransfer[cSrcPtr[0]]; break; case splashModeRGB8: case splashModeBGR8: cResult0 = state->rgbTransferR[cSrcPtr[0]]; cResult1 = state->rgbTransferG[cSrcPtr[1]]; cResult2 = state->rgbTransferB[cSrcPtr[2]]; break; #if SPLASH_CMYK case splashModeCMYK8: cResult0 = state->cmykTransferC[cSrcPtr[0]]; cResult1 = state->cmykTransferM[cSrcPtr[1]]; cResult2 = state->cmykTransferY[cSrcPtr[2]]; cResult3 = state->cmykTransferK[cSrcPtr[3]]; break; #endif } aResult = 255; } else { // if (noTransparency && !blendFunc) //----- read destination pixel // (or backdrop color, for knockout groups) if (color0Ptr) { switch (bitmap->mode) { case splashModeMono1: cDest[0] = (*color0Ptr & color0Mask) ? 0xff : 0x00; color0Ptr += color0Mask & 1; color0Mask = (color0Mask << 7) | (color0Mask >> 1); break; case splashModeMono8: cDest[0] = *color0Ptr++; break; case splashModeRGB8: cDest[0] = color0Ptr[0]; cDest[1] = color0Ptr[1]; cDest[2] = color0Ptr[2]; color0Ptr += 3; break; case splashModeBGR8: cDest[2] = color0Ptr[0]; cDest[1] = color0Ptr[1]; cDest[0] = color0Ptr[2]; color0Ptr += 3; break; #if SPLASH_CMYK case splashModeCMYK8: cDest[0] = color0Ptr[0]; cDest[1] = color0Ptr[1]; cDest[2] = color0Ptr[2]; cDest[3] = color0Ptr[3]; color0Ptr += 4; break; #endif } } else { switch (bitmap->mode) { case splashModeMono1: cDest[0] = (*destColorPtr & destColorMask) ? 0xff : 0x00; break; case splashModeMono8: cDest[0] = *destColorPtr; break; case splashModeRGB8: cDest[0] = destColorPtr[0]; cDest[1] = destColorPtr[1]; cDest[2] = destColorPtr[2]; break; case splashModeBGR8: cDest[0] = destColorPtr[2]; cDest[1] = destColorPtr[1]; cDest[2] = destColorPtr[0]; break; #if SPLASH_CMYK case splashModeCMYK8: cDest[0] = destColorPtr[0]; cDest[1] = destColorPtr[1]; cDest[2] = destColorPtr[2]; cDest[3] = destColorPtr[3]; break; #endif } } if (destAlphaPtr) { aDest = *destAlphaPtr; } else { aDest = 0xff; } //----- read source color; handle overprint switch (bitmap->mode) { case splashModeMono1: case splashModeMono8: cSrc[0] = state->grayTransfer[cSrcPtr[0]]; break; case splashModeRGB8: case splashModeBGR8: cSrc[0] = state->rgbTransferR[cSrcPtr[0]]; cSrc[1] = state->rgbTransferG[cSrcPtr[1]]; cSrc[2] = state->rgbTransferB[cSrcPtr[2]]; break; #if SPLASH_CMYK case splashModeCMYK8: if (state->overprintMask & 0x01) { cSrc[0] = state->cmykTransferC[cSrcPtr[0]]; } else { cSrc[0] = div255(aDest * cDest[0]); } if (state->overprintMask & 0x02) { cSrc[1] = state->cmykTransferM[cSrcPtr[1]]; } else { cSrc[1] = div255(aDest * cDest[1]); } if (state->overprintMask & 0x04) { cSrc[2] = state->cmykTransferY[cSrcPtr[2]]; } else { cSrc[2] = div255(aDest * cDest[2]); } if (state->overprintMask & 0x08) { cSrc[3] = state->cmykTransferK[cSrcPtr[3]]; } else { cSrc[3] = div255(aDest * cDest[3]); } break; #endif } //----- source alpha if (softMaskPtr) { if (shapePtr) { aSrc = div255(div255(pipe->aInput * *softMaskPtr++) * shape); } else { aSrc = div255(pipe->aInput * *softMaskPtr++); } } else if (shapePtr) { aSrc = div255(pipe->aInput * shape); } else { aSrc = pipe->aInput; } //----- non-isolated group correction if (pipe->nonIsolatedGroup) { // This path is only used when Splash::composite() is called to // composite a non-isolated group onto the backdrop. In this // case, shape is the source (group) alpha. t = (aDest * 255) / shape - aDest; switch (bitmap->mode) { #if SPLASH_CMYK case splashModeCMYK8: cSrc[3] = clip255(cSrc[3] + ((cSrc[3] - cDest[3]) * t) / 255); #endif case splashModeRGB8: case splashModeBGR8: cSrc[2] = clip255(cSrc[2] + ((cSrc[2] - cDest[2]) * t) / 255); cSrc[1] = clip255(cSrc[1] + ((cSrc[1] - cDest[1]) * t) / 255); case splashModeMono1: case splashModeMono8: cSrc[0] = clip255(cSrc[0] + ((cSrc[0] - cDest[0]) * t) / 255); break; } } //----- blend function if (state->blendFunc) { #if SPLASH_CMYK if (bitmap->mode == splashModeCMYK8) { // convert colors to additive cSrc2[0] = 0xff - cSrc[0]; cSrc2[1] = 0xff - cSrc[1]; cSrc2[2] = 0xff - cSrc[2]; cSrc2[3] = 0xff - cSrc[3]; cDest2[0] = 0xff - cDest[0]; cDest2[1] = 0xff - cDest[1]; cDest2[2] = 0xff - cDest[2]; cDest2[3] = 0xff - cDest[3]; (*state->blendFunc)(cSrc2, cDest2, cBlend, bitmap->mode); // convert result back to subtractive cBlend[0] = 0xff - cBlend[0]; cBlend[1] = 0xff - cBlend[1]; cBlend[2] = 0xff - cBlend[2]; cBlend[3] = 0xff - cBlend[3]; } else #endif (*state->blendFunc)(cSrc, cDest, cBlend, bitmap->mode); } //----- result alpha and non-isolated group element correction // alphaI = alpha_i // alphaIm1 = alpha_(i-1) if (pipe->noTransparency) { alphaI = alphaIm1 = aResult = 255; } else if (alpha0Ptr) { if (color0Ptr) { // non-isolated, knockout aResult = aSrc; alpha0 = *alpha0Ptr++; alphaI = aSrc + alpha0 - div255(aSrc * alpha0); alphaIm1 = alpha0; } else { // non-isolated, non-knockout aResult = aSrc + aDest - div255(aSrc * aDest); alpha0 = *alpha0Ptr++; alphaI = aResult + alpha0 - div255(aResult * alpha0); alphaIm1 = alpha0 + aDest - div255(alpha0 * aDest); } } else { if (color0Ptr) { // isolated, knockout aResult = aSrc; alphaI = aSrc; alphaIm1 = 0; } else { // isolated, non-knockout aResult = aSrc + aDest - div255(aSrc * aDest); alphaI = aResult; alphaIm1 = aDest; } } //----- result color switch (pipe->resultColorCtrl) { case splashPipeResultColorNoAlphaBlendMono: cResult0 = div255((255 - aDest) * cSrc[0] + aDest * cBlend[0]); break; case splashPipeResultColorNoAlphaBlendRGB: cResult0 = div255((255 - aDest) * cSrc[0] + aDest * cBlend[0]); cResult1 = div255((255 - aDest) * cSrc[1] + aDest * cBlend[1]); cResult2 = div255((255 - aDest) * cSrc[2] + aDest * cBlend[2]); break; #if SPLASH_CMYK case splashPipeResultColorNoAlphaBlendCMYK: cResult0 = div255((255 - aDest) * cSrc[0] + aDest * cBlend[0]); cResult1 = div255((255 - aDest) * cSrc[1] + aDest * cBlend[1]); cResult2 = div255((255 - aDest) * cSrc[2] + aDest * cBlend[2]); cResult3 = div255((255 - aDest) * cSrc[3] + aDest * cBlend[3]); break; #endif case splashPipeResultColorAlphaNoBlendMono: if (alphaI == 0) { cResult0 = 0; } else { cResult0 = ((alphaI - aSrc) * cDest[0] + aSrc * cSrc[0]) / alphaI; } break; case splashPipeResultColorAlphaNoBlendRGB: if (alphaI == 0) { cResult0 = 0; cResult1 = 0; cResult2 = 0; } else { cResult0 = ((alphaI - aSrc) * cDest[0] + aSrc * cSrc[0]) / alphaI; cResult1 = ((alphaI - aSrc) * cDest[1] + aSrc * cSrc[1]) / alphaI; cResult2 = ((alphaI - aSrc) * cDest[2] + aSrc * cSrc[2]) / alphaI; } break; #if SPLASH_CMYK case splashPipeResultColorAlphaNoBlendCMYK: if (alphaI == 0) { cResult0 = 0; cResult1 = 0; cResult2 = 0; cResult3 = 0; } else { cResult0 = ((alphaI - aSrc) * cDest[0] + aSrc * cSrc[0]) / alphaI; cResult1 = ((alphaI - aSrc) * cDest[1] + aSrc * cSrc[1]) / alphaI; cResult2 = ((alphaI - aSrc) * cDest[2] + aSrc * cSrc[2]) / alphaI; cResult3 = ((alphaI - aSrc) * cDest[3] + aSrc * cSrc[3]) / alphaI; } break; #endif case splashPipeResultColorAlphaBlendMono: if (alphaI == 0) { cResult0 = 0; } else { cResult0 = ((alphaI - aSrc) * cDest[0] + aSrc * ((255 - alphaIm1) * cSrc[0] + alphaIm1 * cBlend[0]) / 255) / alphaI; } break; case splashPipeResultColorAlphaBlendRGB: if (alphaI == 0) { cResult0 = 0; cResult1 = 0; cResult2 = 0; } else { cResult0 = ((alphaI - aSrc) * cDest[0] + aSrc * ((255 - alphaIm1) * cSrc[0] + alphaIm1 * cBlend[0]) / 255) / alphaI; cResult1 = ((alphaI - aSrc) * cDest[1] + aSrc * ((255 - alphaIm1) * cSrc[1] + alphaIm1 * cBlend[1]) / 255) / alphaI; cResult2 = ((alphaI - aSrc) * cDest[2] + aSrc * ((255 - alphaIm1) * cSrc[2] + alphaIm1 * cBlend[2]) / 255) / alphaI; } break; #if SPLASH_CMYK case splashPipeResultColorAlphaBlendCMYK: if (alphaI == 0) { cResult0 = 0; cResult1 = 0; cResult2 = 0; cResult3 = 0; } else { cResult0 = ((alphaI - aSrc) * cDest[0] + aSrc * ((255 - alphaIm1) * cSrc[0] + alphaIm1 * cBlend[0]) / 255) / alphaI; cResult1 = ((alphaI - aSrc) * cDest[1] + aSrc * ((255 - alphaIm1) * cSrc[1] + alphaIm1 * cBlend[1]) / 255) / alphaI; cResult2 = ((alphaI - aSrc) * cDest[2] + aSrc * ((255 - alphaIm1) * cSrc[2] + alphaIm1 * cBlend[2]) / 255) / alphaI; cResult3 = ((alphaI - aSrc) * cDest[3] + aSrc * ((255 - alphaIm1) * cSrc[3] + alphaIm1 * cBlend[3]) / 255) / alphaI; } break; #endif } } // if (noTransparency && !blendFunc) //----- write destination pixel switch (bitmap->mode) { case splashModeMono1: if (state->screen->test(x, y, cResult0)) { *destColorPtr |= destColorMask; } else { *destColorPtr &= ~destColorMask; } destColorPtr += destColorMask & 1; destColorMask = (destColorMask << 7) | (destColorMask >> 1); break; case splashModeMono8: *destColorPtr++ = cResult0; break; case splashModeRGB8: destColorPtr[0] = cResult0; destColorPtr[1] = cResult1; destColorPtr[2] = cResult2; destColorPtr += 3; break; case splashModeBGR8: destColorPtr[0] = cResult2; destColorPtr[1] = cResult1; destColorPtr[2] = cResult0; destColorPtr += 3; break; #if SPLASH_CMYK case splashModeCMYK8: destColorPtr[0] = cResult0; destColorPtr[1] = cResult1; destColorPtr[2] = cResult2; destColorPtr[3] = cResult3; destColorPtr += 4; break; #endif } if (destAlphaPtr) { *destAlphaPtr++ = aResult; } cSrcPtr += cSrcStride; shapePtr2 += shapeStride; } // for (x ...) updateModX(lastX); } // special case: // !pipe->pattern && pipe->noTransparency && !state->blendFunc && // bitmap->mode == splashModeMono1 && !bitmap->alpha) { void Splash::pipeRunSimpleMono1(SplashPipe *pipe, int x0, int x1, int y, Guchar *shapePtr, SplashColorPtr cSrcPtr) { Guchar cResult0; SplashColorPtr destColorPtr; Guchar destColorMask; SplashScreenCursor screenCursor; int cSrcStride, x; if (cSrcPtr) { cSrcStride = 1; } else { cSrcPtr = pipe->cSrcVal; cSrcStride = 0; } if (x0 > x1) { return; } updateModX(x0); updateModX(x1); updateModY(y); destColorPtr = &bitmap->data[y * bitmap->rowSize + (x0 >> 3)]; destColorMask = 0x80 >> (x0 & 7); screenCursor = state->screen->getTestCursor(y); for (x = x0; x <= x1; ++x) { //----- write destination pixel cResult0 = state->grayTransfer[cSrcPtr[0]]; if (state->screen->testWithCursor(screenCursor, x, cResult0)) { *destColorPtr |= destColorMask; } else { *destColorPtr &= ~destColorMask; } destColorPtr += destColorMask & 1; destColorMask = (destColorMask << 7) | (destColorMask >> 1); cSrcPtr += cSrcStride; } } // special case: // !pipe->pattern && pipe->noTransparency && !state->blendFunc && // bitmap->mode == splashModeMono8 && bitmap->alpha) { void Splash::pipeRunSimpleMono8(SplashPipe *pipe, int x0, int x1, int y, Guchar *shapePtr, SplashColorPtr cSrcPtr) { SplashColorPtr destColorPtr; Guchar *destAlphaPtr; int cSrcStride, x; if (cSrcPtr) { cSrcStride = 1; } else { cSrcPtr = pipe->cSrcVal; cSrcStride = 0; } if (x0 > x1) { return; } updateModX(x0); updateModX(x1); updateModY(y); destColorPtr = &bitmap->data[y * bitmap->rowSize + x0]; destAlphaPtr = &bitmap->alpha[y * bitmap->width + x0]; for (x = x0; x <= x1; ++x) { //----- write destination pixel *destColorPtr++ = state->grayTransfer[cSrcPtr[0]]; *destAlphaPtr++ = 255; cSrcPtr += cSrcStride; } } // special case: // !pipe->pattern && pipe->noTransparency && !state->blendFunc && // bitmap->mode == splashModeRGB8 && bitmap->alpha) { void Splash::pipeRunSimpleRGB8(SplashPipe *pipe, int x0, int x1, int y, Guchar *shapePtr, SplashColorPtr cSrcPtr) { SplashColorPtr destColorPtr; Guchar *destAlphaPtr; int cSrcStride, x; if (cSrcPtr) { cSrcStride = 3; } else { cSrcPtr = pipe->cSrcVal; cSrcStride = 0; } if (x0 > x1) { return; } updateModX(x0); updateModX(x1); updateModY(y); destColorPtr = &bitmap->data[y * bitmap->rowSize + 3 * x0]; destAlphaPtr = &bitmap->alpha[y * bitmap->width + x0]; for (x = x0; x <= x1; ++x) { //----- write destination pixel destColorPtr[0] = state->rgbTransferR[cSrcPtr[0]]; destColorPtr[1] = state->rgbTransferG[cSrcPtr[1]]; destColorPtr[2] = state->rgbTransferB[cSrcPtr[2]]; destColorPtr += 3; *destAlphaPtr++ = 255; cSrcPtr += cSrcStride; } } // special case: // !pipe->pattern && pipe->noTransparency && !state->blendFunc && // bitmap->mode == splashModeBGR8 && bitmap->alpha) { void Splash::pipeRunSimpleBGR8(SplashPipe *pipe, int x0, int x1, int y, Guchar *shapePtr, SplashColorPtr cSrcPtr) { SplashColorPtr destColorPtr; Guchar *destAlphaPtr; int cSrcStride, x; if (cSrcPtr) { cSrcStride = 3; } else { cSrcPtr = pipe->cSrcVal; cSrcStride = 0; } if (x0 > x1) { return; } updateModX(x0); updateModX(x1); updateModY(y); destColorPtr = &bitmap->data[y * bitmap->rowSize + 3 * x0]; destAlphaPtr = &bitmap->alpha[y * bitmap->width + x0]; for (x = x0; x <= x1; ++x) { //----- write destination pixel destColorPtr[0] = state->rgbTransferB[cSrcPtr[2]]; destColorPtr[1] = state->rgbTransferG[cSrcPtr[1]]; destColorPtr[2] = state->rgbTransferR[cSrcPtr[0]]; destColorPtr += 3; *destAlphaPtr++ = 255; cSrcPtr += cSrcStride; } } #if SPLASH_CMYK // special case: // !pipe->pattern && pipe->noTransparency && !state->blendFunc && // bitmap->mode == splashModeCMYK8 && bitmap->alpha) { void Splash::pipeRunSimpleCMYK8(SplashPipe *pipe, int x0, int x1, int y, Guchar *shapePtr, SplashColorPtr cSrcPtr) { SplashColorPtr destColorPtr; Guchar *destAlphaPtr; int cSrcStride, x; if (cSrcPtr) { cSrcStride = 4; } else { cSrcPtr = pipe->cSrcVal; cSrcStride = 0; } if (x0 > x1) { return; } updateModX(x0); updateModX(x1); updateModY(y); destColorPtr = &bitmap->data[y * bitmap->rowSize + 4 * x0]; destAlphaPtr = &bitmap->alpha[y * bitmap->width + x0]; for (x = x0; x <= x1; ++x) { //----- write destination pixel destColorPtr[0] = state->cmykTransferC[cSrcPtr[0]]; destColorPtr[1] = state->cmykTransferM[cSrcPtr[1]]; destColorPtr[2] = state->cmykTransferY[cSrcPtr[2]]; destColorPtr[3] = state->cmykTransferK[cSrcPtr[3]]; destColorPtr += 4; *destAlphaPtr++ = 255; cSrcPtr += cSrcStride; } } #endif // special case: // !pipe->pattern && pipe->shapeOnly && !state->blendFunc && // bitmap->mode == splashModeMono1 && !bitmap->alpha void Splash::pipeRunShapeMono1(SplashPipe *pipe, int x0, int x1, int y, Guchar *shapePtr, SplashColorPtr cSrcPtr) { Guchar shape, aSrc, cSrc0, cDest0, cResult0; SplashColorPtr destColorPtr; Guchar destColorMask; SplashScreenCursor screenCursor; int cSrcStride, x, lastX; if (cSrcPtr) { cSrcStride = 1; } else { cSrcPtr = pipe->cSrcVal; cSrcStride = 0; } for (; x0 <= x1; ++x0) { if (*shapePtr) { break; } cSrcPtr += cSrcStride; ++shapePtr; } if (x0 > x1) { return; } updateModX(x0); updateModY(y); lastX = x0; destColorPtr = &bitmap->data[y * bitmap->rowSize + (x0 >> 3)]; destColorMask = 0x80 >> (x0 & 7); screenCursor = state->screen->getTestCursor(y); for (x = x0; x <= x1; ++x) { //----- shape shape = *shapePtr; if (!shape) { destColorPtr += destColorMask & 1; destColorMask = (destColorMask << 7) | (destColorMask >> 1); cSrcPtr += cSrcStride; ++shapePtr; continue; } lastX = x; //----- source color cSrc0 = state->grayTransfer[cSrcPtr[0]]; //----- source alpha aSrc = shape; //----- special case for aSrc = 255 if (aSrc == 255) { cResult0 = cSrc0; } else { //----- read destination pixel cDest0 = (*destColorPtr & destColorMask) ? 0xff : 0x00; //----- result color // note: aDest = alphaI = aResult = 0xff cResult0 = (Guchar)div255((0xff - aSrc) * cDest0 + aSrc * cSrc0); } //----- write destination pixel if (state->screen->testWithCursor(screenCursor, x, cResult0)) { *destColorPtr |= destColorMask; } else { *destColorPtr &= ~destColorMask; } destColorPtr += destColorMask & 1; destColorMask = (destColorMask << 7) | (destColorMask >> 1); cSrcPtr += cSrcStride; ++shapePtr; } updateModX(lastX); } // special case: // !pipe->pattern && pipe->shapeOnly && !state->blendFunc && // bitmap->mode == splashModeMono8 && bitmap->alpha void Splash::pipeRunShapeMono8(SplashPipe *pipe, int x0, int x1, int y, Guchar *shapePtr, SplashColorPtr cSrcPtr) { Guchar shape, aSrc, aDest, alphaI, aResult, cSrc0, cDest0, cResult0; SplashColorPtr destColorPtr; Guchar *destAlphaPtr; int cSrcStride, x, lastX; if (cSrcPtr) { cSrcStride = 1; } else { cSrcPtr = pipe->cSrcVal; cSrcStride = 0; } for (; x0 <= x1; ++x0) { if (*shapePtr) { break; } cSrcPtr += cSrcStride; ++shapePtr; } if (x0 > x1) { return; } updateModX(x0); updateModY(y); lastX = x0; destColorPtr = &bitmap->data[y * bitmap->rowSize + x0]; destAlphaPtr = &bitmap->alpha[y * bitmap->width + x0]; for (x = x0; x <= x1; ++x) { //----- shape shape = *shapePtr; if (!shape) { ++destColorPtr; ++destAlphaPtr; cSrcPtr += cSrcStride; ++shapePtr; continue; } lastX = x; //----- source color cSrc0 = state->grayTransfer[cSrcPtr[0]]; //----- source alpha aSrc = shape; //----- special case for aSrc = 255 if (aSrc == 255) { aResult = 255; cResult0 = cSrc0; } else { //----- read destination alpha aDest = *destAlphaPtr; //----- special case for aDest = 0 if (aDest == 0) { aResult = aSrc; cResult0 = cSrc0; } else { //----- read destination pixel cDest0 = *destColorPtr; //----- result alpha and non-isolated group element correction aResult = aSrc + aDest - div255(aSrc * aDest); alphaI = aResult; //----- result color cResult0 = (Guchar)(((alphaI - aSrc) * cDest0 + aSrc * cSrc0) / alphaI); } } //----- write destination pixel *destColorPtr++ = cResult0; *destAlphaPtr++ = aResult; cSrcPtr += cSrcStride; ++shapePtr; } updateModX(lastX); } // special case: // !pipe->pattern && pipe->shapeOnly && !state->blendFunc && // bitmap->mode == splashModeRGB8 && bitmap->alpha void Splash::pipeRunShapeRGB8(SplashPipe *pipe, int x0, int x1, int y, Guchar *shapePtr, SplashColorPtr cSrcPtr) { Guchar shape, aSrc, aDest, alphaI, aResult; Guchar cSrc0, cSrc1, cSrc2; Guchar cDest0, cDest1, cDest2; Guchar cResult0, cResult1, cResult2; SplashColorPtr destColorPtr; Guchar *destAlphaPtr; int cSrcStride, x, lastX; if (cSrcPtr) { cSrcStride = 3; } else { cSrcPtr = pipe->cSrcVal; cSrcStride = 0; } for (; x0 <= x1; ++x0) { if (*shapePtr) { break; } cSrcPtr += cSrcStride; ++shapePtr; } if (x0 > x1) { return; } updateModX(x0); updateModY(y); lastX = x0; destColorPtr = &bitmap->data[y * bitmap->rowSize + 3 * x0]; destAlphaPtr = &bitmap->alpha[y * bitmap->width + x0]; for (x = x0; x <= x1; ++x) { //----- shape shape = *shapePtr; if (!shape) { destColorPtr += 3; ++destAlphaPtr; cSrcPtr += cSrcStride; ++shapePtr; continue; } lastX = x; //----- source color cSrc0 = state->rgbTransferR[cSrcPtr[0]]; cSrc1 = state->rgbTransferG[cSrcPtr[1]]; cSrc2 = state->rgbTransferB[cSrcPtr[2]]; //----- source alpha aSrc = shape; //----- special case for aSrc = 255 if (aSrc == 255) { aResult = 255; cResult0 = cSrc0; cResult1 = cSrc1; cResult2 = cSrc2; } else { //----- read destination alpha aDest = *destAlphaPtr; //----- special case for aDest = 0 if (aDest == 0) { aResult = aSrc; cResult0 = cSrc0; cResult1 = cSrc1; cResult2 = cSrc2; } else { //----- read destination pixel cDest0 = destColorPtr[0]; cDest1 = destColorPtr[1]; cDest2 = destColorPtr[2]; //----- result alpha and non-isolated group element correction aResult = aSrc + aDest - div255(aSrc * aDest); alphaI = aResult; //----- result color cResult0 = (Guchar)(((alphaI - aSrc) * cDest0 + aSrc * cSrc0) / alphaI); cResult1 = (Guchar)(((alphaI - aSrc) * cDest1 + aSrc * cSrc1) / alphaI); cResult2 = (Guchar)(((alphaI - aSrc) * cDest2 + aSrc * cSrc2) / alphaI); } } //----- write destination pixel destColorPtr[0] = cResult0; destColorPtr[1] = cResult1; destColorPtr[2] = cResult2; destColorPtr += 3; *destAlphaPtr++ = aResult; cSrcPtr += cSrcStride; ++shapePtr; } updateModX(lastX); } // special case: // !pipe->pattern && pipe->shapeOnly && !state->blendFunc && // bitmap->mode == splashModeBGR8 && bitmap->alpha void Splash::pipeRunShapeBGR8(SplashPipe *pipe, int x0, int x1, int y, Guchar *shapePtr, SplashColorPtr cSrcPtr) { Guchar shape, aSrc, aDest, alphaI, aResult; Guchar cSrc0, cSrc1, cSrc2; Guchar cDest0, cDest1, cDest2; Guchar cResult0, cResult1, cResult2; SplashColorPtr destColorPtr; Guchar *destAlphaPtr; int cSrcStride, x, lastX; if (cSrcPtr) { cSrcStride = 3; } else { cSrcPtr = pipe->cSrcVal; cSrcStride = 0; } for (; x0 <= x1; ++x0) { if (*shapePtr) { break; } cSrcPtr += cSrcStride; ++shapePtr; } if (x0 > x1) { return; } updateModX(x0); updateModY(y); lastX = x0; destColorPtr = &bitmap->data[y * bitmap->rowSize + 3 * x0]; destAlphaPtr = &bitmap->alpha[y * bitmap->width + x0]; for (x = x0; x <= x1; ++x) { //----- shape shape = *shapePtr; if (!shape) { destColorPtr += 3; ++destAlphaPtr; cSrcPtr += cSrcStride; ++shapePtr; continue; } lastX = x; //----- source color cSrc0 = state->rgbTransferR[cSrcPtr[0]]; cSrc1 = state->rgbTransferG[cSrcPtr[1]]; cSrc2 = state->rgbTransferB[cSrcPtr[2]]; //----- source alpha aSrc = shape; //----- special case for aSrc = 255 if (aSrc == 255) { aResult = 255; cResult0 = cSrc0; cResult1 = cSrc1; cResult2 = cSrc2; } else { //----- read destination alpha aDest = *destAlphaPtr; //----- special case for aDest = 0 if (aDest == 0) { aResult = aSrc; cResult0 = cSrc0; cResult1 = cSrc1; cResult2 = cSrc2; } else { //----- read destination pixel cDest0 = destColorPtr[2]; cDest1 = destColorPtr[1]; cDest2 = destColorPtr[0]; //----- result alpha and non-isolated group element correction aResult = aSrc + aDest - div255(aSrc * aDest); alphaI = aResult; //----- result color cResult0 = (Guchar)(((alphaI - aSrc) * cDest0 + aSrc * cSrc0) / alphaI); cResult1 = (Guchar)(((alphaI - aSrc) * cDest1 + aSrc * cSrc1) / alphaI); cResult2 = (Guchar)(((alphaI - aSrc) * cDest2 + aSrc * cSrc2) / alphaI); } } //----- write destination pixel destColorPtr[0] = cResult2; destColorPtr[1] = cResult1; destColorPtr[2] = cResult0; destColorPtr += 3; *destAlphaPtr++ = aResult; cSrcPtr += cSrcStride; ++shapePtr; } updateModX(lastX); } #if SPLASH_CMYK // special case: // !pipe->pattern && pipe->shapeOnly && !state->blendFunc && // bitmap->mode == splashModeCMYK8 && bitmap->alpha void Splash::pipeRunShapeCMYK8(SplashPipe *pipe, int x0, int x1, int y, Guchar *shapePtr, SplashColorPtr cSrcPtr) { Guchar shape, aSrc, aDest, alphaI, aResult; Guchar cSrc0, cSrc1, cSrc2, cSrc3; Guchar cDest0, cDest1, cDest2, cDest3; Guchar cResult0, cResult1, cResult2, cResult3; SplashColorPtr destColorPtr; Guchar *destAlphaPtr; int cSrcStride, x, lastX; if (cSrcPtr) { cSrcStride = 4; } else { cSrcPtr = pipe->cSrcVal; cSrcStride = 0; } for (; x0 <= x1; ++x0) { if (*shapePtr) { break; } cSrcPtr += cSrcStride; ++shapePtr; } if (x0 > x1) { return; } updateModX(x0); updateModY(y); lastX = x0; destColorPtr = &bitmap->data[y * bitmap->rowSize + 4 * x0]; destAlphaPtr = &bitmap->alpha[y * bitmap->width + x0]; for (x = x0; x <= x1; ++x) { //----- shape shape = *shapePtr; if (!shape) { destColorPtr += 4; ++destAlphaPtr; cSrcPtr += cSrcStride; ++shapePtr; continue; } lastX = x; //----- read destination pixel cDest0 = destColorPtr[0]; cDest1 = destColorPtr[1]; cDest2 = destColorPtr[2]; cDest3 = destColorPtr[3]; aDest = *destAlphaPtr; //----- overprint if (state->overprintMask & 1) { cSrc0 = state->cmykTransferC[cSrcPtr[0]]; } else { cSrc0 = div255(aDest * cDest0); } if (state->overprintMask & 2) { cSrc1 = state->cmykTransferM[cSrcPtr[1]]; } else { cSrc1 = div255(aDest * cDest1); } if (state->overprintMask & 4) { cSrc2 = state->cmykTransferY[cSrcPtr[2]]; } else { cSrc2 = div255(aDest * cDest2); } if (state->overprintMask & 8) { cSrc3 = state->cmykTransferK[cSrcPtr[3]]; } else { cSrc3 = div255(aDest * cDest3); } //----- source alpha aSrc = shape; //----- special case for aSrc = 255 if (aSrc == 255) { aResult = 255; cResult0 = cSrc0; cResult1 = cSrc1; cResult2 = cSrc2; cResult3 = cSrc3; } else { //----- special case for aDest = 0 if (aDest == 0) { aResult = aSrc; cResult0 = cSrc0; cResult1 = cSrc1; cResult2 = cSrc2; cResult3 = cSrc3; } else { //----- result alpha and non-isolated group element correction aResult = aSrc + aDest - div255(aSrc * aDest); alphaI = aResult; //----- result color cResult0 = (Guchar)(((alphaI - aSrc) * cDest0 + aSrc * cSrc0) / alphaI); cResult1 = (Guchar)(((alphaI - aSrc) * cDest1 + aSrc * cSrc1) / alphaI); cResult2 = (Guchar)(((alphaI - aSrc) * cDest2 + aSrc * cSrc2) / alphaI); cResult3 = (Guchar)(((alphaI - aSrc) * cDest3 + aSrc * cSrc3) / alphaI); } } //----- write destination pixel destColorPtr[0] = cResult0; destColorPtr[1] = cResult1; destColorPtr[2] = cResult2; destColorPtr[3] = cResult3; destColorPtr += 4; *destAlphaPtr++ = aResult; cSrcPtr += cSrcStride; ++shapePtr; } updateModX(lastX); } #endif // special case: // !pipe->pattern && !pipe->noTransparency && !state->softMask && // pipe->usesShape && !pipe->alpha0Ptr && !state->blendFunc && // !pipe->nonIsolatedGroup && // bitmap->mode == splashModeMono1 && !bitmap->alpha void Splash::pipeRunAAMono1(SplashPipe *pipe, int x0, int x1, int y, Guchar *shapePtr, SplashColorPtr cSrcPtr) { Guchar shape, aSrc, cSrc0, cDest0, cResult0; SplashColorPtr destColorPtr; Guchar destColorMask; SplashScreenCursor screenCursor; int cSrcStride, x, lastX; if (cSrcPtr) { cSrcStride = 1; } else { cSrcPtr = pipe->cSrcVal; cSrcStride = 0; } for (; x0 <= x1; ++x0) { if (*shapePtr) { break; } cSrcPtr += cSrcStride; ++shapePtr; } if (x0 > x1) { return; } updateModX(x0); updateModY(y); lastX = x0; destColorPtr = &bitmap->data[y * bitmap->rowSize + (x0 >> 3)]; destColorMask = 0x80 >> (x0 & 7); screenCursor = state->screen->getTestCursor(y); for (x = x0; x <= x1; ++x) { //----- shape shape = *shapePtr; if (!shape) { destColorPtr += destColorMask & 1; destColorMask = (destColorMask << 7) | (destColorMask >> 1); cSrcPtr += cSrcStride; ++shapePtr; continue; } lastX = x; //----- read destination pixel cDest0 = (*destColorPtr & destColorMask) ? 0xff : 0x00; //----- source color cSrc0 = state->grayTransfer[cSrcPtr[0]]; //----- source alpha aSrc = div255(pipe->aInput * shape); //----- result color // note: aDest = alphaI = aResult = 0xff cResult0 = (Guchar)div255((0xff - aSrc) * cDest0 + aSrc * cSrc0); //----- write destination pixel if (state->screen->testWithCursor(screenCursor, x, cResult0)) { *destColorPtr |= destColorMask; } else { *destColorPtr &= ~destColorMask; } destColorPtr += destColorMask & 1; destColorMask = (destColorMask << 7) | (destColorMask >> 1); cSrcPtr += cSrcStride; ++shapePtr; } updateModX(lastX); } // special case: // !pipe->pattern && !pipe->noTransparency && !state->softMask && // pipe->usesShape && !pipe->alpha0Ptr && !state->blendFunc && // !pipe->nonIsolatedGroup && // bitmap->mode == splashModeMono8 && bitmap->alpha void Splash::pipeRunAAMono8(SplashPipe *pipe, int x0, int x1, int y, Guchar *shapePtr, SplashColorPtr cSrcPtr) { Guchar shape, aSrc, aDest, alphaI, aResult, cSrc0, cDest0, cResult0; SplashColorPtr destColorPtr; Guchar *destAlphaPtr; int cSrcStride, x, lastX; if (cSrcPtr) { cSrcStride = 1; } else { cSrcPtr = pipe->cSrcVal; cSrcStride = 0; } for (; x0 <= x1; ++x0) { if (*shapePtr) { break; } cSrcPtr += cSrcStride; ++shapePtr; } if (x0 > x1) { return; } updateModX(x0); updateModY(y); lastX = x0; destColorPtr = &bitmap->data[y * bitmap->rowSize + x0]; destAlphaPtr = &bitmap->alpha[y * bitmap->width + x0]; for (x = x0; x <= x1; ++x) { //----- shape shape = *shapePtr; if (!shape) { ++destColorPtr; ++destAlphaPtr; cSrcPtr += cSrcStride; ++shapePtr; continue; } lastX = x; //----- read destination pixel cDest0 = *destColorPtr; aDest = *destAlphaPtr; //----- source color cSrc0 = state->grayTransfer[cSrcPtr[0]]; //----- source alpha aSrc = div255(pipe->aInput * shape); //----- result alpha and non-isolated group element correction aResult = aSrc + aDest - div255(aSrc * aDest); alphaI = aResult; //----- result color if (alphaI == 0) { cResult0 = 0; } else { cResult0 = (Guchar)(((alphaI - aSrc) * cDest0 + aSrc * cSrc0) / alphaI); } //----- write destination pixel *destColorPtr++ = cResult0; *destAlphaPtr++ = aResult; cSrcPtr += cSrcStride; ++shapePtr; } updateModX(lastX); } // special case: // !pipe->pattern && !pipe->noTransparency && !state->softMask && // pipe->usesShape && !pipe->alpha0Ptr && !state->blendFunc && // !pipe->nonIsolatedGroup && // bitmap->mode == splashModeRGB8 && bitmap->alpha void Splash::pipeRunAARGB8(SplashPipe *pipe, int x0, int x1, int y, Guchar *shapePtr, SplashColorPtr cSrcPtr) { Guchar shape, aSrc, aDest, alphaI, aResult; Guchar cSrc0, cSrc1, cSrc2; Guchar cDest0, cDest1, cDest2; Guchar cResult0, cResult1, cResult2; SplashColorPtr destColorPtr; Guchar *destAlphaPtr; int cSrcStride, x, lastX; if (cSrcPtr) { cSrcStride = 3; } else { cSrcPtr = pipe->cSrcVal; cSrcStride = 0; } for (; x0 <= x1; ++x0) { if (*shapePtr) { break; } cSrcPtr += cSrcStride; ++shapePtr; } if (x0 > x1) { return; } updateModX(x0); updateModY(y); lastX = x0; destColorPtr = &bitmap->data[y * bitmap->rowSize + 3 * x0]; destAlphaPtr = &bitmap->alpha[y * bitmap->width + x0]; for (x = x0; x <= x1; ++x) { //----- shape shape = *shapePtr; if (!shape) { destColorPtr += 3; ++destAlphaPtr; cSrcPtr += cSrcStride; ++shapePtr; continue; } lastX = x; //----- read destination pixel cDest0 = destColorPtr[0]; cDest1 = destColorPtr[1]; cDest2 = destColorPtr[2]; aDest = *destAlphaPtr; //----- source color cSrc0 = state->rgbTransferR[cSrcPtr[0]]; cSrc1 = state->rgbTransferG[cSrcPtr[1]]; cSrc2 = state->rgbTransferB[cSrcPtr[2]]; //----- source alpha aSrc = div255(pipe->aInput * shape); //----- result alpha and non-isolated group element correction aResult = aSrc + aDest - div255(aSrc * aDest); alphaI = aResult; //----- result color if (alphaI == 0) { cResult0 = 0; cResult1 = 0; cResult2 = 0; } else { cResult0 = (Guchar)(((alphaI - aSrc) * cDest0 + aSrc * cSrc0) / alphaI); cResult1 = (Guchar)(((alphaI - aSrc) * cDest1 + aSrc * cSrc1) / alphaI); cResult2 = (Guchar)(((alphaI - aSrc) * cDest2 + aSrc * cSrc2) / alphaI); } //----- write destination pixel destColorPtr[0] = cResult0; destColorPtr[1] = cResult1; destColorPtr[2] = cResult2; destColorPtr += 3; *destAlphaPtr++ = aResult; cSrcPtr += cSrcStride; ++shapePtr; } updateModX(lastX); } // special case: // !pipe->pattern && !pipe->noTransparency && !state->softMask && // pipe->usesShape && !pipe->alpha0Ptr && !state->blendFunc && // !pipe->nonIsolatedGroup && // bitmap->mode == splashModeBGR8 && bitmap->alpha void Splash::pipeRunAABGR8(SplashPipe *pipe, int x0, int x1, int y, Guchar *shapePtr, SplashColorPtr cSrcPtr) { Guchar shape, aSrc, aDest, alphaI, aResult; Guchar cSrc0, cSrc1, cSrc2; Guchar cDest0, cDest1, cDest2; Guchar cResult0, cResult1, cResult2; SplashColorPtr destColorPtr; Guchar *destAlphaPtr; int cSrcStride, x, lastX; if (cSrcPtr) { cSrcStride = 3; } else { cSrcPtr = pipe->cSrcVal; cSrcStride = 0; } for (; x0 <= x1; ++x0) { if (*shapePtr) { break; } cSrcPtr += cSrcStride; ++shapePtr; } if (x0 > x1) { return; } updateModX(x0); updateModY(y); lastX = x0; destColorPtr = &bitmap->data[y * bitmap->rowSize + 3 * x0]; destAlphaPtr = &bitmap->alpha[y * bitmap->width + x0]; for (x = x0; x <= x1; ++x) { //----- shape shape = *shapePtr; if (!shape) { destColorPtr += 3; ++destAlphaPtr; cSrcPtr += cSrcStride; ++shapePtr; continue; } lastX = x; //----- read destination pixel cDest0 = destColorPtr[2]; cDest1 = destColorPtr[1]; cDest2 = destColorPtr[0]; aDest = *destAlphaPtr; //----- source color cSrc0 = state->rgbTransferR[cSrcPtr[0]]; cSrc1 = state->rgbTransferG[cSrcPtr[1]]; cSrc2 = state->rgbTransferB[cSrcPtr[2]]; //----- source alpha aSrc = div255(pipe->aInput * shape); //----- result alpha and non-isolated group element correction aResult = aSrc + aDest - div255(aSrc * aDest); alphaI = aResult; //----- result color if (alphaI == 0) { cResult0 = 0; cResult1 = 0; cResult2 = 0; } else { cResult0 = (Guchar)(((alphaI - aSrc) * cDest0 + aSrc * cSrc0) / alphaI); cResult1 = (Guchar)(((alphaI - aSrc) * cDest1 + aSrc * cSrc1) / alphaI); cResult2 = (Guchar)(((alphaI - aSrc) * cDest2 + aSrc * cSrc2) / alphaI); } //----- write destination pixel destColorPtr[0] = cResult2; destColorPtr[1] = cResult1; destColorPtr[2] = cResult0; destColorPtr += 3; *destAlphaPtr++ = aResult; cSrcPtr += cSrcStride; ++shapePtr; } updateModX(lastX); } #if SPLASH_CMYK // special case: // !pipe->pattern && !pipe->noTransparency && !state->softMask && // pipe->usesShape && !pipe->alpha0Ptr && !state->blendFunc && // !pipe->nonIsolatedGroup && // bitmap->mode == splashModeCMYK8 && bitmap->alpha void Splash::pipeRunAACMYK8(SplashPipe *pipe, int x0, int x1, int y, Guchar *shapePtr, SplashColorPtr cSrcPtr) { Guchar shape, aSrc, aDest, alphaI, aResult; Guchar cSrc0, cSrc1, cSrc2, cSrc3; Guchar cDest0, cDest1, cDest2, cDest3; Guchar cResult0, cResult1, cResult2, cResult3; SplashColorPtr destColorPtr; Guchar *destAlphaPtr; int cSrcStride, x, lastX; if (cSrcPtr) { cSrcStride = 4; } else { cSrcPtr = pipe->cSrcVal; cSrcStride = 0; } for (; x0 <= x1; ++x0) { if (*shapePtr) { break; } cSrcPtr += cSrcStride; ++shapePtr; } if (x0 > x1) { return; } updateModX(x0); updateModY(y); lastX = x0; destColorPtr = &bitmap->data[y * bitmap->rowSize + 4 * x0]; destAlphaPtr = &bitmap->alpha[y * bitmap->width + x0]; for (x = x0; x <= x1; ++x) { //----- shape shape = *shapePtr; if (!shape) { destColorPtr += 4; ++destAlphaPtr; cSrcPtr += cSrcStride; ++shapePtr; continue; } lastX = x; //----- read destination pixel cDest0 = destColorPtr[0]; cDest1 = destColorPtr[1]; cDest2 = destColorPtr[2]; cDest3 = destColorPtr[3]; aDest = *destAlphaPtr; //----- overprint if (state->overprintMask & 1) { cSrc0 = state->cmykTransferC[cSrcPtr[0]]; } else { cSrc0 = div255(aDest * cDest0); } if (state->overprintMask & 2) { cSrc1 = state->cmykTransferM[cSrcPtr[1]]; } else { cSrc1 = div255(aDest * cDest1); } if (state->overprintMask & 4) { cSrc2 = state->cmykTransferY[cSrcPtr[2]]; } else { cSrc2 = div255(aDest * cDest2); } if (state->overprintMask & 8) { cSrc3 = state->cmykTransferK[cSrcPtr[3]]; } else { cSrc3 = div255(aDest * cDest3); } //----- source alpha aSrc = div255(pipe->aInput * shape); //----- result alpha and non-isolated group element correction aResult = aSrc + aDest - div255(aSrc * aDest); alphaI = aResult; //----- result color if (alphaI == 0) { cResult0 = 0; cResult1 = 0; cResult2 = 0; cResult3 = 0; } else { cResult0 = (Guchar)(((alphaI - aSrc) * cDest0 + aSrc * cSrc0) / alphaI); cResult1 = (Guchar)(((alphaI - aSrc) * cDest1 + aSrc * cSrc1) / alphaI); cResult2 = (Guchar)(((alphaI - aSrc) * cDest2 + aSrc * cSrc2) / alphaI); cResult3 = (Guchar)(((alphaI - aSrc) * cDest3 + aSrc * cSrc3) / alphaI); } //----- write destination pixel destColorPtr[0] = cResult0; destColorPtr[1] = cResult1; destColorPtr[2] = cResult2; destColorPtr[3] = cResult3; destColorPtr += 4; *destAlphaPtr++ = aResult; cSrcPtr += cSrcStride; ++shapePtr; } updateModX(lastX); } #endif //------------------------------------------------------------------------ // Transform a point from user space to device space. inline void Splash::transform(SplashCoord *matrix, SplashCoord xi, SplashCoord yi, SplashCoord *xo, SplashCoord *yo) { // [ m[0] m[1] 0 ] // [xo yo 1] = [xi yi 1] * [ m[2] m[3] 0 ] // [ m[4] m[5] 1 ] *xo = xi * matrix[0] + yi * matrix[2] + matrix[4]; *yo = xi * matrix[1] + yi * matrix[3] + matrix[5]; } //------------------------------------------------------------------------ // Splash //------------------------------------------------------------------------ Splash::Splash(SplashBitmap *bitmapA, GBool vectorAntialiasA, SplashScreenParams *screenParams) { bitmap = bitmapA; bitmapComps = splashColorModeNComps[bitmap->mode]; vectorAntialias = vectorAntialiasA; inShading = gFalse; state = new SplashState(bitmap->width, bitmap->height, vectorAntialias, screenParams); scanBuf = (Guchar *)gmalloc(bitmap->width); if (bitmap->mode == splashModeMono1) { scanBuf2 = (Guchar *)gmalloc(bitmap->width); } else { scanBuf2 = NULL; } groupBackBitmap = NULL; minLineWidth = 0; clearModRegion(); debugMode = gFalse; } Splash::Splash(SplashBitmap *bitmapA, GBool vectorAntialiasA, SplashScreen *screenA) { bitmap = bitmapA; bitmapComps = splashColorModeNComps[bitmap->mode]; vectorAntialias = vectorAntialiasA; inShading = gFalse; state = new SplashState(bitmap->width, bitmap->height, vectorAntialias, screenA); scanBuf = (Guchar *)gmalloc(bitmap->width); if (bitmap->mode == splashModeMono1) { scanBuf2 = (Guchar *)gmalloc(bitmap->width); } else { scanBuf2 = NULL; } groupBackBitmap = NULL; minLineWidth = 0; clearModRegion(); debugMode = gFalse; } Splash::~Splash() { while (state->next) { restoreState(); } delete state; gfree(scanBuf); gfree(scanBuf2); } //------------------------------------------------------------------------ // state read //------------------------------------------------------------------------ SplashCoord *Splash::getMatrix() { return state->matrix; } SplashPattern *Splash::getStrokePattern() { return state->strokePattern; } SplashPattern *Splash::getFillPattern() { return state->fillPattern; } SplashScreen *Splash::getScreen() { return state->screen; } SplashBlendFunc Splash::getBlendFunc() { return state->blendFunc; } SplashCoord Splash::getStrokeAlpha() { return state->strokeAlpha; } SplashCoord Splash::getFillAlpha() { return state->fillAlpha; } SplashCoord Splash::getLineWidth() { return state->lineWidth; } int Splash::getLineCap() { return state->lineCap; } int Splash::getLineJoin() { return state->lineJoin; } SplashCoord Splash::getMiterLimit() { return state->miterLimit; } SplashCoord Splash::getFlatness() { return state->flatness; } SplashCoord *Splash::getLineDash() { return state->lineDash; } int Splash::getLineDashLength() { return state->lineDashLength; } SplashCoord Splash::getLineDashPhase() { return state->lineDashPhase; } SplashStrokeAdjustMode Splash::getStrokeAdjust() { return state->strokeAdjust; } SplashClip *Splash::getClip() { return state->clip; } SplashBitmap *Splash::getSoftMask() { return state->softMask; } GBool Splash::getInNonIsolatedGroup() { return state->inNonIsolatedGroup; } GBool Splash::getInKnockoutGroup() { return state->inKnockoutGroup; } //------------------------------------------------------------------------ // state write //------------------------------------------------------------------------ void Splash::setMatrix(SplashCoord *matrix) { memcpy(state->matrix, matrix, 6 * sizeof(SplashCoord)); } void Splash::setStrokePattern(SplashPattern *strokePattern) { state->setStrokePattern(strokePattern); } void Splash::setFillPattern(SplashPattern *fillPattern) { state->setFillPattern(fillPattern); } void Splash::setScreen(SplashScreen *screen) { state->setScreen(screen); } void Splash::setBlendFunc(SplashBlendFunc func) { state->blendFunc = func; } void Splash::setStrokeAlpha(SplashCoord alpha) { state->strokeAlpha = alpha; } void Splash::setFillAlpha(SplashCoord alpha) { state->fillAlpha = alpha; } void Splash::setLineWidth(SplashCoord lineWidth) { state->lineWidth = lineWidth; } void Splash::setLineCap(int lineCap) { state->lineCap = lineCap; } void Splash::setLineJoin(int lineJoin) { state->lineJoin = lineJoin; } void Splash::setMiterLimit(SplashCoord miterLimit) { state->miterLimit = miterLimit; } void Splash::setFlatness(SplashCoord flatness) { if (flatness < 1) { state->flatness = 1; } else { state->flatness = flatness; } } void Splash::setLineDash(SplashCoord *lineDash, int lineDashLength, SplashCoord lineDashPhase) { state->setLineDash(lineDash, lineDashLength, lineDashPhase); } void Splash::setStrokeAdjust(SplashStrokeAdjustMode strokeAdjust) { state->strokeAdjust = strokeAdjust; } void Splash::clipResetToRect(SplashCoord x0, SplashCoord y0, SplashCoord x1, SplashCoord y1) { state->clipResetToRect(x0, y0, x1, y1); } SplashError Splash::clipToRect(SplashCoord x0, SplashCoord y0, SplashCoord x1, SplashCoord y1) { return state->clipToRect(x0, y0, x1, y1); } SplashError Splash::clipToPath(SplashPath *path, GBool eo) { return state->clipToPath(path, eo); } void Splash::setSoftMask(SplashBitmap *softMask) { state->setSoftMask(softMask); } void Splash::setInTransparencyGroup(SplashBitmap *groupBackBitmapA, int groupBackXA, int groupBackYA, GBool nonIsolated, GBool knockout) { groupBackBitmap = groupBackBitmapA; groupBackX = groupBackXA; groupBackY = groupBackYA; state->inNonIsolatedGroup = nonIsolated; state->inKnockoutGroup = knockout; } void Splash::setTransfer(Guchar *red, Guchar *green, Guchar *blue, Guchar *gray) { state->setTransfer(red, green, blue, gray); } void Splash::setOverprintMask(Guint overprintMask) { state->overprintMask = overprintMask; } void Splash::setEnablePathSimplification(GBool en) { state->enablePathSimplification = en; } //------------------------------------------------------------------------ // state save/restore //------------------------------------------------------------------------ void Splash::saveState() { SplashState *newState; newState = state->copy(); newState->next = state; state = newState; } SplashError Splash::restoreState() { SplashState *oldState; if (!state->next) { return splashErrNoSave; } oldState = state; state = state->next; delete oldState; return splashOk; } //------------------------------------------------------------------------ // drawing operations //------------------------------------------------------------------------ void Splash::clear(SplashColorPtr color, Guchar alpha) { SplashColorPtr row, p; Guchar mono; int x, y; switch (bitmap->mode) { case splashModeMono1: mono = (color[0] & 0x80) ? 0xff : 0x00; if (bitmap->rowSize < 0) { memset(bitmap->data + bitmap->rowSize * (bitmap->height - 1), mono, -bitmap->rowSize * bitmap->height); } else { memset(bitmap->data, mono, bitmap->rowSize * bitmap->height); } break; case splashModeMono8: if (bitmap->rowSize < 0) { memset(bitmap->data + bitmap->rowSize * (bitmap->height - 1), color[0], -bitmap->rowSize * bitmap->height); } else { memset(bitmap->data, color[0], bitmap->rowSize * bitmap->height); } break; case splashModeRGB8: if (color[0] == color[1] && color[1] == color[2]) { if (bitmap->rowSize < 0) { memset(bitmap->data + bitmap->rowSize * (bitmap->height - 1), color[0], -bitmap->rowSize * bitmap->height); } else { memset(bitmap->data, color[0], bitmap->rowSize * bitmap->height); } } else { row = bitmap->data; for (y = 0; y < bitmap->height; ++y) { p = row; for (x = 0; x < bitmap->width; ++x) { *p++ = color[0]; *p++ = color[1]; *p++ = color[2]; } row += bitmap->rowSize; } } break; case splashModeBGR8: if (color[0] == color[1] && color[1] == color[2]) { if (bitmap->rowSize < 0) { memset(bitmap->data + bitmap->rowSize * (bitmap->height - 1), color[0], -bitmap->rowSize * bitmap->height); } else { memset(bitmap->data, color[0], bitmap->rowSize * bitmap->height); } } else { row = bitmap->data; for (y = 0; y < bitmap->height; ++y) { p = row; for (x = 0; x < bitmap->width; ++x) { *p++ = color[2]; *p++ = color[1]; *p++ = color[0]; } row += bitmap->rowSize; } } break; #if SPLASH_CMYK case splashModeCMYK8: if (color[0] == color[1] && color[1] == color[2] && color[2] == color[3]) { if (bitmap->rowSize < 0) { memset(bitmap->data + bitmap->rowSize * (bitmap->height - 1), color[0], -bitmap->rowSize * bitmap->height); } else { memset(bitmap->data, color[0], bitmap->rowSize * bitmap->height); } } else { row = bitmap->data; for (y = 0; y < bitmap->height; ++y) { p = row; for (x = 0; x < bitmap->width; ++x) { *p++ = color[0]; *p++ = color[1]; *p++ = color[2]; *p++ = color[3]; } row += bitmap->rowSize; } } break; #endif } if (bitmap->alpha) { memset(bitmap->alpha, alpha, bitmap->width * bitmap->height); } updateModX(0); updateModY(0); updateModX(bitmap->width - 1); updateModY(bitmap->height - 1); } SplashError Splash::stroke(SplashPath *path) { SplashPath *path2, *dPath; SplashCoord t0, t1, t2, t3, w, w2, lineDashMax, lineDashTotal; int lineCap, lineJoin, i; if (debugMode) { printf("stroke [dash:%d] [width:%.2f]:\n", state->lineDashLength, (double)state->lineWidth); dumpPath(path); } opClipRes = splashClipAllOutside; if (path->length == 0) { return splashErrEmptyPath; } path2 = flattenPath(path, state->matrix, state->flatness); // Compute an approximation of the transformed line width. // Given a CTM of [m0 m1], // [m2 m3] // if |m0|*|m3| >= |m1|*|m2| then use min{|m0|,|m3|}, else // use min{|m1|,|m2|}. // This handles the common cases -- [s 0 ] and [0 s] -- // [0 +/-s] [+/-s 0] // well, and still does something reasonable for the uncommon // case transforms. t0 = splashAbs(state->matrix[0]); t1 = splashAbs(state->matrix[1]); t2 = splashAbs(state->matrix[2]); t3 = splashAbs(state->matrix[3]); if (t0 * t3 >= t1 * t2) { w = (t0 < t3) ? t0 : t3; } else { w = (t1 < t2) ? t1 : t2; } w2 = w * state->lineWidth; // construct the dashed path if (state->lineDashLength > 0) { // check the maximum transformed dash element length (using the // same approximation as for line width) -- if it's less than 0.1 // pixel, don't apply the dash pattern; this avoids a huge // performance/memory hit with PDF files that use absurd dash // patterns like [0.0007 0.0003] lineDashTotal = 0; lineDashMax = 0; for (i = 0; i < state->lineDashLength; ++i) { lineDashTotal += state->lineDash[i]; if (state->lineDash[i] > lineDashMax) { lineDashMax = state->lineDash[i]; } } // Acrobat simply draws nothing if the dash array is [0] if (lineDashTotal == 0) { delete path2; return splashOk; } if (w * lineDashMax > 0.1) { dPath = makeDashedPath(path2); delete path2; path2 = dPath; if (path2->length == 0) { delete path2; return splashErrEmptyPath; } } } // round caps on narrow lines look bad, and can't be // stroke-adjusted, so use projecting caps instead (but we can't do // this if there are zero-length dashes or segments, because those // turn into round dots) lineCap = state->lineCap; lineJoin = state->lineJoin; if (state->strokeAdjust == splashStrokeAdjustCAD && w2 < 3.5) { if (lineCap == splashLineCapRound && !state->lineDashContainsZeroLengthDashes() && !path->containsZeroLengthSubpaths()) { lineCap = splashLineCapProjecting; } if (lineJoin == splashLineJoinRound) { lineJoin = splashLineJoinBevel; } } // if there is a min line width set, and the transformed line width // is smaller, use the min line width if (w > 0 && w2 < minLineWidth) { strokeWide(path2, minLineWidth / w, splashLineCapButt, splashLineJoinBevel); } else if (bitmap->mode == splashModeMono1) { // in monochrome mode, use 0-width lines for any transformed line // width <= 1 -- lines less than 1 pixel wide look too fat without // antialiasing if (w2 < 1.001) { strokeNarrow(path2); } else { strokeWide(path2, state->lineWidth, lineCap, lineJoin); } } else { // in gray and color modes, only use 0-width lines if the line // width is explicitly set to 0 if (state->lineWidth == 0) { strokeNarrow(path2); } else { strokeWide(path2, state->lineWidth, lineCap, lineJoin); } } delete path2; return splashOk; } void Splash::strokeNarrow(SplashPath *path) { SplashPipe pipe; SplashXPath *xPath; SplashXPathSeg *seg; int x0, x1, y0, y1, xa, xb, y; SplashCoord dxdy; SplashClipResult clipRes; int nClipRes[3]; int i; nClipRes[0] = nClipRes[1] = nClipRes[2] = 0; xPath = new SplashXPath(path, state->matrix, state->flatness, gFalse, state->enablePathSimplification, state->strokeAdjust); pipeInit(&pipe, state->strokePattern, (Guchar)splashRound(state->strokeAlpha * 255), gTrue, gFalse); for (i = 0, seg = xPath->segs; i < xPath->length; ++i, ++seg) { if (seg->y0 <= seg->y1) { y0 = splashFloor(seg->y0); y1 = splashFloor(seg->y1); x0 = splashFloor(seg->x0); x1 = splashFloor(seg->x1); } else { y0 = splashFloor(seg->y1); y1 = splashFloor(seg->y0); x0 = splashFloor(seg->x1); x1 = splashFloor(seg->x0); } if ((clipRes = state->clip->testRect(x0 <= x1 ? x0 : x1, y0, x0 <= x1 ? x1 : x0, y1, state->strokeAdjust)) != splashClipAllOutside) { if (y0 == y1) { if (x0 <= x1) { drawStrokeSpan(&pipe, x0, x1, y0, clipRes == splashClipAllInside); } else { drawStrokeSpan(&pipe, x1, x0, y0, clipRes == splashClipAllInside); } } else { dxdy = seg->dxdy; y = state->clip->getYMinI(state->strokeAdjust); if (y0 < y) { y0 = y; x0 = splashFloor(seg->x0 + ((SplashCoord)y0 - seg->y0) * dxdy); } y = state->clip->getYMaxI(state->strokeAdjust); if (y1 > y) { y1 = y; x1 = splashFloor(seg->x0 + ((SplashCoord)y1 - seg->y0) * dxdy); } if (x0 <= x1) { xa = x0; for (y = y0; y <= y1; ++y) { if (y < y1) { xb = splashFloor(seg->x0 + ((SplashCoord)y + 1 - seg->y0) * dxdy); } else { xb = x1 + 1; } if (xa == xb) { drawStrokeSpan(&pipe, xa, xa, y, clipRes == splashClipAllInside); } else { drawStrokeSpan(&pipe, xa, xb - 1, y, clipRes == splashClipAllInside); } xa = xb; } } else { xa = x0; for (y = y0; y <= y1; ++y) { if (y < y1) { xb = splashFloor(seg->x0 + ((SplashCoord)y + 1 - seg->y0) * dxdy); } else { xb = x1 - 1; } if (xa == xb) { drawStrokeSpan(&pipe, xa, xa, y, clipRes == splashClipAllInside); } else { drawStrokeSpan(&pipe, xb + 1, xa, y, clipRes == splashClipAllInside); } xa = xb; } } } } ++nClipRes[clipRes]; } if (nClipRes[splashClipPartial] || (nClipRes[splashClipAllInside] && nClipRes[splashClipAllOutside])) { opClipRes = splashClipPartial; } else if (nClipRes[splashClipAllInside]) { opClipRes = splashClipAllInside; } else { opClipRes = splashClipAllOutside; } delete xPath; } void Splash::drawStrokeSpan(SplashPipe *pipe, int x0, int x1, int y, GBool noClip) { int x; x = state->clip->getXMinI(state->strokeAdjust); if (x > x0) { x0 = x; } x = state->clip->getXMaxI(state->strokeAdjust); if (x < x1) { x1 = x; } if (x0 > x1) { return; } for (x = x0; x <= x1; ++x) { scanBuf[x] = 0xff; } if (!noClip) { if (!state->clip->clipSpanBinary(scanBuf, y, x0, x1, state->strokeAdjust)) { return; } } (this->*pipe->run)(pipe, x0, x1, y, scanBuf + x0, NULL); } void Splash::strokeWide(SplashPath *path, SplashCoord w, int lineCap, int lineJoin) { SplashPath *path2; path2 = makeStrokePath(path, w, lineCap, lineJoin, gFalse); fillWithPattern(path2, gFalse, state->strokePattern, state->strokeAlpha); delete path2; } SplashPath *Splash::flattenPath(SplashPath *path, SplashCoord *matrix, SplashCoord flatness) { SplashPath *fPath; SplashCoord flatness2; Guchar flag; int i; fPath = new SplashPath(); #if USE_FIXEDPOINT flatness2 = flatness; #else flatness2 = flatness * flatness; #endif i = 0; while (i < path->length) { flag = path->flags[i]; if (flag & splashPathFirst) { fPath->moveTo(path->pts[i].x, path->pts[i].y); ++i; } else { if (flag & splashPathCurve) { flattenCurve(path->pts[i-1].x, path->pts[i-1].y, path->pts[i ].x, path->pts[i ].y, path->pts[i+1].x, path->pts[i+1].y, path->pts[i+2].x, path->pts[i+2].y, matrix, flatness2, fPath); i += 3; } else { fPath->lineTo(path->pts[i].x, path->pts[i].y); ++i; } if (path->flags[i-1] & splashPathClosed) { fPath->close(); } } } return fPath; } void Splash::flattenCurve(SplashCoord x0, SplashCoord y0, SplashCoord x1, SplashCoord y1, SplashCoord x2, SplashCoord y2, SplashCoord x3, SplashCoord y3, SplashCoord *matrix, SplashCoord flatness2, SplashPath *fPath) { SplashCoord cx[splashMaxCurveSplits + 1][3]; SplashCoord cy[splashMaxCurveSplits + 1][3]; int cNext[splashMaxCurveSplits + 1]; SplashCoord xl0, xl1, xl2, xr0, xr1, xr2, xr3, xx1, xx2, xh; SplashCoord yl0, yl1, yl2, yr0, yr1, yr2, yr3, yy1, yy2, yh; SplashCoord dx, dy, mx, my, tx, ty, d1, d2; int p1, p2, p3; // initial segment p1 = 0; p2 = splashMaxCurveSplits; cx[p1][0] = x0; cy[p1][0] = y0; cx[p1][1] = x1; cy[p1][1] = y1; cx[p1][2] = x2; cy[p1][2] = y2; cx[p2][0] = x3; cy[p2][0] = y3; cNext[p1] = p2; while (p1 < splashMaxCurveSplits) { // get the next segment xl0 = cx[p1][0]; yl0 = cy[p1][0]; xx1 = cx[p1][1]; yy1 = cy[p1][1]; xx2 = cx[p1][2]; yy2 = cy[p1][2]; p2 = cNext[p1]; xr3 = cx[p2][0]; yr3 = cy[p2][0]; // compute the distances (in device space) from the control points // to the midpoint of the straight line (this is a bit of a hack, // but it's much faster than computing the actual distances to the // line) transform(matrix, (xl0 + xr3) * 0.5, (yl0 + yr3) * 0.5, &mx, &my); transform(matrix, xx1, yy1, &tx, &ty); #if USE_FIXEDPOINT d1 = splashDist(tx, ty, mx, my); #else dx = tx - mx; dy = ty - my; d1 = dx*dx + dy*dy; #endif transform(matrix, xx2, yy2, &tx, &ty); #if USE_FIXEDPOINT d2 = splashDist(tx, ty, mx, my); #else dx = tx - mx; dy = ty - my; d2 = dx*dx + dy*dy; #endif // if the curve is flat enough, or no more subdivisions are // allowed, add the straight line segment if (p2 - p1 == 1 || (d1 <= flatness2 && d2 <= flatness2)) { fPath->lineTo(xr3, yr3); p1 = p2; // otherwise, subdivide the curve } else { xl1 = splashAvg(xl0, xx1); yl1 = splashAvg(yl0, yy1); xh = splashAvg(xx1, xx2); yh = splashAvg(yy1, yy2); xl2 = splashAvg(xl1, xh); yl2 = splashAvg(yl1, yh); xr2 = splashAvg(xx2, xr3); yr2 = splashAvg(yy2, yr3); xr1 = splashAvg(xh, xr2); yr1 = splashAvg(yh, yr2); xr0 = splashAvg(xl2, xr1); yr0 = splashAvg(yl2, yr1); // add the new subdivision points p3 = (p1 + p2) / 2; cx[p1][1] = xl1; cy[p1][1] = yl1; cx[p1][2] = xl2; cy[p1][2] = yl2; cNext[p1] = p3; cx[p3][0] = xr0; cy[p3][0] = yr0; cx[p3][1] = xr1; cy[p3][1] = yr1; cx[p3][2] = xr2; cy[p3][2] = yr2; cNext[p3] = p2; } } } SplashPath *Splash::makeDashedPath(SplashPath *path) { SplashPath *dPath; SplashCoord lineDashTotal; SplashCoord lineDashStartPhase, lineDashDist, segLen; SplashCoord x0, y0, x1, y1, xa, ya; GBool lineDashStartOn, lineDashEndOn, lineDashOn, newPath; int lineDashStartIdx, lineDashIdx, subpathStart, nDashes; int i, j, k; lineDashTotal = 0; for (i = 0; i < state->lineDashLength; ++i) { lineDashTotal += state->lineDash[i]; } // Acrobat simply draws nothing if the dash array is [0] if (lineDashTotal == 0) { return new SplashPath(); } lineDashStartPhase = state->lineDashPhase; if (lineDashStartPhase > lineDashTotal * 2) { i = splashFloor(lineDashStartPhase / (lineDashTotal * 2)); lineDashStartPhase -= lineDashTotal * i * 2; } else if (lineDashStartPhase < 0) { i = splashCeil(-lineDashStartPhase / (lineDashTotal * 2)); lineDashStartPhase += lineDashTotal * i * 2; } i = splashFloor(lineDashStartPhase / lineDashTotal); lineDashStartPhase -= (SplashCoord)i * lineDashTotal; lineDashStartOn = gTrue; lineDashStartIdx = 0; if (lineDashStartPhase > 0) { while (lineDashStartPhase >= state->lineDash[lineDashStartIdx]) { lineDashStartOn = !lineDashStartOn; lineDashStartPhase -= state->lineDash[lineDashStartIdx]; if (++lineDashStartIdx == state->lineDashLength) { lineDashStartIdx = 0; } } } dPath = new SplashPath(); // process each subpath i = 0; while (i < path->length) { // find the end of the subpath for (j = i; j < path->length - 1 && !(path->flags[j] & splashPathLast); ++j) ; // initialize the dash parameters lineDashOn = lineDashStartOn; lineDashEndOn = lineDashStartOn; lineDashIdx = lineDashStartIdx; lineDashDist = state->lineDash[lineDashIdx] - lineDashStartPhase; subpathStart = dPath->length; nDashes = 0; // process each segment of the subpath newPath = gTrue; for (k = i; k < j; ++k) { // grab the segment x0 = path->pts[k].x; y0 = path->pts[k].y; x1 = path->pts[k+1].x; y1 = path->pts[k+1].y; segLen = splashDist(x0, y0, x1, y1); // process the segment while (segLen > 0) { // Special case for zero-length dash segments: draw a very // short -- but not zero-length -- segment. This ensures that // we get the correct behavior with butt and projecting line // caps. The PS/PDF specs imply that zero-length segments are // not drawn unless the line cap is round, but Acrobat and // Ghostscript both draw very short segments (for butt caps) // and squares (for projecting caps). if (lineDashDist == 0) { if (lineDashOn) { if (newPath) { dPath->moveTo(x0, y0); newPath = gFalse; ++nDashes; } xa = x0 + ((SplashCoord)0.001 / segLen) * (x1 - x0); ya = y0 + ((SplashCoord)0.001 / segLen) * (y1 - y0); dPath->lineTo(xa, ya); } } else if (lineDashDist >= segLen) { if (lineDashOn) { if (newPath) { dPath->moveTo(x0, y0); newPath = gFalse; ++nDashes; } dPath->lineTo(x1, y1); } lineDashDist -= segLen; segLen = 0; } else { xa = x0 + (lineDashDist / segLen) * (x1 - x0); ya = y0 + (lineDashDist / segLen) * (y1 - y0); if (lineDashOn) { if (newPath) { dPath->moveTo(x0, y0); newPath = gFalse; ++nDashes; } dPath->lineTo(xa, ya); } x0 = xa; y0 = ya; segLen -= lineDashDist; lineDashDist = 0; } lineDashEndOn = lineDashOn; // get the next entry in the dash array if (lineDashDist <= 0) { lineDashOn = !lineDashOn; if (++lineDashIdx == state->lineDashLength) { lineDashIdx = 0; } lineDashDist = state->lineDash[lineDashIdx]; newPath = gTrue; } } } // in a closed subpath, where the dash pattern is "on" at both the // start and end of the subpath, we need to merge the start and // end to get a proper line join if ((path->flags[j] & splashPathClosed) && lineDashStartOn && lineDashEndOn) { if (nDashes == 1) { dPath->close(); } else if (nDashes > 1) { k = subpathStart; do { ++k; dPath->lineTo(dPath->pts[k].x, dPath->pts[k].y); } while (!(dPath->flags[k] & splashPathLast)); ++k; memmove(&dPath->pts[subpathStart], &dPath->pts[k], (dPath->length - k) * sizeof(SplashPathPoint)); memmove(&dPath->flags[subpathStart], &dPath->flags[k], (dPath->length - k) * sizeof(Guchar)); dPath->length -= k - subpathStart; dPath->curSubpath -= k - subpathStart; } } i = j + 1; } return dPath; } SplashError Splash::fill(SplashPath *path, GBool eo) { if (debugMode) { printf("fill [eo:%d]:\n", eo); dumpPath(path); } return fillWithPattern(path, eo, state->fillPattern, state->fillAlpha); } SplashError Splash::fillWithPattern(SplashPath *path, GBool eo, SplashPattern *pattern, SplashCoord alpha) { SplashPipe pipe; SplashPath *path2; SplashXPath *xPath; SplashXPathScanner *scanner; int xMin, yMin, xMax, xMin2, xMax2, yMax, y, t; SplashClipResult clipRes; if (path->length == 0) { return splashErrEmptyPath; } if (pathAllOutside(path)) { opClipRes = splashClipAllOutside; return splashOk; } path2 = tweakFillPath(path); xPath = new SplashXPath(path2, state->matrix, state->flatness, gTrue, state->enablePathSimplification, state->strokeAdjust); if (path2 != path) { delete path2; } xMin = xPath->getXMin(); yMin = xPath->getYMin(); xMax = xPath->getXMax(); yMax = xPath->getYMax(); if (xMin > xMax || yMin > yMax) { delete xPath; return splashOk; } scanner = new SplashXPathScanner(xPath, eo, yMin, yMax); // check clipping if ((clipRes = state->clip->testRect(xMin, yMin, xMax, yMax, state->strokeAdjust)) != splashClipAllOutside) { if ((t = state->clip->getXMinI(state->strokeAdjust)) > xMin) { xMin = t; } if ((t = state->clip->getXMaxI(state->strokeAdjust)) < xMax) { xMax = t; } if ((t = state->clip->getYMinI(state->strokeAdjust)) > yMin) { yMin = t; } if ((t = state->clip->getYMaxI(state->strokeAdjust)) < yMax) { yMax = t; } if (xMin > xMax || yMin > yMax) { delete scanner; delete xPath; return splashOk; } pipeInit(&pipe, pattern, (Guchar)splashRound(alpha * 255), gTrue, gFalse); // draw the spans if (vectorAntialias && !inShading) { for (y = yMin; y <= yMax; ++y) { scanner->getSpan(scanBuf, y, xMin, xMax, &xMin2, &xMax2); if (xMin2 <= xMax2) { if (clipRes != splashClipAllInside) { state->clip->clipSpan(scanBuf, y, xMin2, xMax2, state->strokeAdjust); } (this->*pipe.run)(&pipe, xMin2, xMax2, y, scanBuf + xMin2, NULL); } } } else { for (y = yMin; y <= yMax; ++y) { scanner->getSpanBinary(scanBuf, y, xMin, xMax, &xMin2, &xMax2); if (xMin2 <= xMax2) { if (clipRes != splashClipAllInside) { state->clip->clipSpanBinary(scanBuf, y, xMin2, xMax2, state->strokeAdjust); } (this->*pipe.run)(&pipe, xMin2, xMax2, y, scanBuf + xMin2, NULL); } } } } opClipRes = clipRes; delete scanner; delete xPath; return splashOk; } // Applies various tweaks to a fill path: // (1) add stroke adjust hints to a filled rectangle // (2) applies a minimum width to a zero-width filled rectangle (so // stroke adjustment works correctly // (3) convert a degenerate fill ('moveto lineto fill' and 'moveto // lineto closepath fill') to a minimum-width filled rectangle // // These tweaks only apply to paths with a single subpath. // // Returns either the unchanged input path or a new path (in which // case the returned path must be deleted by the caller). SplashPath *Splash::tweakFillPath(SplashPath *path) { SplashPath *path2; SplashCoord xx0, yy0, xx1, yy1, dx, dy, d, wx, wy, w; int n; if (state->strokeAdjust == splashStrokeAdjustOff || path->hints) { return path; } n = path->getLength(); if (!((n == 2) || (n == 3 && path->flags[1] == 0) || (n == 4 && path->flags[1] == 0 && path->flags[2] == 0) || (n == 5 && path->flags[1] == 0 && path->flags[2] == 0 && path->flags[3] == 0))) { return path; } path2 = path; // degenerate fill (2 or 3 points) or rectangle of (nearly) zero // width --> replace with a min-width rectangle and hint if (n == 2 || (n == 3 && (path->flags[0] & splashPathClosed)) || (n == 3 && (splashAbs(path->pts[0].x - path->pts[2].x) < 0.001 && splashAbs(path->pts[0].y - path->pts[2].y) < 0.001)) || ((n == 4 || (n == 5 && (path->flags[0] & splashPathClosed))) && ((splashAbs(path->pts[0].x - path->pts[1].x) < 0.001 && splashAbs(path->pts[0].y - path->pts[1].y) < 0.001 && splashAbs(path->pts[2].x - path->pts[3].x) < 0.001 && splashAbs(path->pts[2].y - path->pts[3].y) < 0.001) || (splashAbs(path->pts[0].x - path->pts[3].x) < 0.001 && splashAbs(path->pts[0].y - path->pts[3].y) < 0.001 && splashAbs(path->pts[1].x - path->pts[2].x) < 0.001 && splashAbs(path->pts[1].y - path->pts[2].y) < 0.001)))) { wx = state->matrix[0] + state->matrix[2]; wy = state->matrix[1] + state->matrix[3]; w = splashSqrt(wx*wx + wy*wy); if (w < 0.001) { w = 0; } else { // min width is 0.1 -- this constant is minWidth * sqrt(2) w = (SplashCoord)0.1414 / w; } xx0 = path->pts[0].x; yy0 = path->pts[0].y; if (n <= 3) { xx1 = path->pts[1].x; yy1 = path->pts[1].y; } else { xx1 = path->pts[2].x; yy1 = path->pts[2].y; } dx = xx1 - xx0; dy = yy1 - yy0; d = splashSqrt(dx * dx + dy * dy); if (d < 0.001) { d = 0; } else { d = w / d; } dx *= d; dy *= d; path2 = new SplashPath(); path2->moveTo(xx0 + dy, yy0 - dx); path2->lineTo(xx1 + dy, yy1 - dx); path2->lineTo(xx1 - dy, yy1 + dx); path2->lineTo(xx0 - dy, yy0 + dx); path2->close(gTrue); path2->addStrokeAdjustHint(0, 2, 0, 4); path2->addStrokeAdjustHint(1, 3, 0, 4); // unclosed rectangle --> close and hint } else if (n == 4 && !(path->flags[0] & splashPathClosed)) { path2->close(gTrue); path2->addStrokeAdjustHint(0, 2, 0, 4); path2->addStrokeAdjustHint(1, 3, 0, 4); // closed rectangle --> hint } else if (n == 5 && (path->flags[0] & splashPathClosed)) { path2->addStrokeAdjustHint(0, 2, 0, 4); path2->addStrokeAdjustHint(1, 3, 0, 4); } return path2; } GBool Splash::pathAllOutside(SplashPath *path) { SplashCoord xMin1, yMin1, xMax1, yMax1; SplashCoord xMin2, yMin2, xMax2, yMax2; SplashCoord x, y; int xMinI, yMinI, xMaxI, yMaxI; int i; xMin1 = xMax1 = path->pts[0].x; yMin1 = yMax1 = path->pts[0].y; for (i = 1; i < path->length; ++i) { if (path->pts[i].x < xMin1) { xMin1 = path->pts[i].x; } else if (path->pts[i].x > xMax1) { xMax1 = path->pts[i].x; } if (path->pts[i].y < yMin1) { yMin1 = path->pts[i].y; } else if (path->pts[i].y > yMax1) { yMax1 = path->pts[i].y; } } transform(state->matrix, xMin1, yMin1, &x, &y); xMin2 = xMax2 = x; yMin2 = yMax2 = y; transform(state->matrix, xMin1, yMax1, &x, &y); if (x < xMin2) { xMin2 = x; } else if (x > xMax2) { xMax2 = x; } if (y < yMin2) { yMin2 = y; } else if (y > yMax2) { yMax2 = y; } transform(state->matrix, xMax1, yMin1, &x, &y); if (x < xMin2) { xMin2 = x; } else if (x > xMax2) { xMax2 = x; } if (y < yMin2) { yMin2 = y; } else if (y > yMax2) { yMax2 = y; } transform(state->matrix, xMax1, yMax1, &x, &y); if (x < xMin2) { xMin2 = x; } else if (x > xMax2) { xMax2 = x; } if (y < yMin2) { yMin2 = y; } else if (y > yMax2) { yMax2 = y; } // sanity-check the coordinates - xMinI/yMinI/xMaxI/yMaxI are // 32-bit integers, so coords need to be < 2^31 SplashXPath::clampCoords(&xMin2, &yMin2); SplashXPath::clampCoords(&xMax2, &yMax2); xMinI = splashFloor(xMin2); yMinI = splashFloor(yMin2); xMaxI = splashFloor(xMax2); yMaxI = splashFloor(yMax2); return state->clip->testRect(xMinI, yMinI, xMaxI, yMaxI, state->strokeAdjust) == splashClipAllOutside; } SplashError Splash::fillChar(SplashCoord x, SplashCoord y, int c, SplashFont *font) { SplashGlyphBitmap glyph; SplashCoord xt, yt; int x0, y0, xFrac, yFrac; SplashError err; if (debugMode) { printf("fillChar: x=%.2f y=%.2f c=%3d=0x%02x='%c'\n", (double)x, (double)y, c, c, c); } transform(state->matrix, x, y, &xt, &yt); x0 = splashFloor(xt); xFrac = splashFloor((xt - x0) * splashFontFraction); y0 = splashFloor(yt); yFrac = splashFloor((yt - y0) * splashFontFraction); if (!font->getGlyph(c, xFrac, yFrac, &glyph)) { return splashErrNoGlyph; } err = fillGlyph2(x0, y0, &glyph); if (glyph.freeData) { gfree(glyph.data); } return err; } SplashError Splash::fillGlyph(SplashCoord x, SplashCoord y, SplashGlyphBitmap *glyph) { SplashCoord xt, yt; int x0, y0; transform(state->matrix, x, y, &xt, &yt); x0 = splashFloor(xt); y0 = splashFloor(yt); return fillGlyph2(x0, y0, glyph); } SplashError Splash::fillGlyph2(int x0, int y0, SplashGlyphBitmap *glyph) { SplashPipe pipe; SplashClipResult clipRes; Guchar alpha; Guchar *p; int xMin, yMin, xMax, yMax; int x, y, xg, yg, xx, t; xg = x0 - glyph->x; yg = y0 - glyph->y; xMin = xg; xMax = xg + glyph->w - 1; yMin = yg; yMax = yg + glyph->h - 1; if ((clipRes = state->clip->testRect(xMin, yMin, xMax, yMax, state->strokeAdjust)) != splashClipAllOutside) { pipeInit(&pipe, state->fillPattern, (Guchar)splashRound(state->fillAlpha * 255), gTrue, gFalse); if (clipRes == splashClipAllInside) { if (glyph->aa) { p = glyph->data; for (y = yMin; y <= yMax; ++y) { (this->*pipe.run)(&pipe, xMin, xMax, y, glyph->data + (y - yMin) * glyph->w, NULL); } } else { p = glyph->data; for (y = yMin; y <= yMax; ++y) { for (x = xMin; x <= xMax; x += 8) { alpha = *p++; for (xx = 0; xx < 8 && x + xx <= xMax; ++xx) { scanBuf[x + xx] = (alpha & 0x80) ? 0xff : 0x00; alpha <<= 1; } } (this->*pipe.run)(&pipe, xMin, xMax, y, scanBuf + xMin, NULL); } } } else { if ((t = state->clip->getXMinI(state->strokeAdjust)) > xMin) { xMin = t; } if ((t = state->clip->getXMaxI(state->strokeAdjust)) < xMax) { xMax = t; } if ((t = state->clip->getYMinI(state->strokeAdjust)) > yMin) { yMin = t; } if ((t = state->clip->getYMaxI(state->strokeAdjust)) < yMax) { yMax = t; } if (xMin <= xMax && yMin <= yMax) { if (glyph->aa) { for (y = yMin; y <= yMax; ++y) { p = glyph->data + (y - yg) * glyph->w + (xMin - xg); memcpy(scanBuf + xMin, p, xMax - xMin + 1); state->clip->clipSpan(scanBuf, y, xMin, xMax, state->strokeAdjust); (this->*pipe.run)(&pipe, xMin, xMax, y, scanBuf + xMin, NULL); } } else { for (y = yMin; y <= yMax; ++y) { p = glyph->data + (y - yg) * ((glyph->w + 7) >> 3) + ((xMin - xg) >> 3); alpha = *p++; xx = (xMin - xg) & 7; alpha <<= xx; for (x = xMin; xx < 8 && x <= xMax; ++x, ++xx) { scanBuf[x] = (alpha & 0x80) ? 255 : 0; alpha <<= 1; } for (; x <= xMax; x += 8) { alpha = *p++; for (xx = 0; xx < 8 && x + xx <= xMax; ++xx) { scanBuf[x + xx] = (alpha & 0x80) ? 255 : 0; alpha <<= 1; } } state->clip->clipSpanBinary(scanBuf, y, xMin, xMax, state->strokeAdjust); (this->*pipe.run)(&pipe, xMin, xMax, y, scanBuf + xMin, NULL); } } } } } opClipRes = clipRes; return splashOk; } void Splash::getImageBounds(SplashCoord xyMin, SplashCoord xyMax, int *xyMinI, int *xyMaxI) { if (state->strokeAdjust == splashStrokeAdjustOff) { *xyMinI = splashFloor(xyMin); *xyMaxI = splashFloor(xyMax); if (*xyMaxI <= *xyMinI) { *xyMaxI = *xyMinI + 1; } } else { splashStrokeAdjust(xyMin, xyMax, xyMinI, xyMaxI, state->strokeAdjust); } } // The glyphMode flag is not currently used, but may be useful if the // stroke adjustment behavior is changed. SplashError Splash::fillImageMask(SplashImageMaskSource src, void *srcData, int w, int h, SplashCoord *mat, GBool glyphMode, GBool interpolate) { SplashBitmap *scaledMask; SplashClipResult clipRes; GBool minorAxisZero; SplashCoord wSize, hSize, t0, t1; int x0, y0, x1, y1, scaledWidth, scaledHeight; if (debugMode) { printf("fillImageMask: w=%d h=%d mat=[%.2f %.2f %.2f %.2f %.2f %.2f]\n", w, h, (double)mat[0], (double)mat[1], (double)mat[2], (double)mat[3], (double)mat[4], (double)mat[5]); } // check for singular matrix if (!splashCheckDet(mat[0], mat[1], mat[2], mat[3], 0.000001)) { return splashErrSingularMatrix; } minorAxisZero = splashAbs(mat[1]) <= 0.0001 && splashAbs(mat[2]) <= 0.0001; // rough estimate of size of scaled mask t0 = splashAbs(mat[0]); t1 = splashAbs(mat[1]); wSize = t0 > t1 ? t0 : t1; t0 = splashAbs(mat[2]); t1 = splashAbs(mat[3]); hSize = t0 > t1 ? t0 : t1; // stream-mode upscaling -- this is slower, so we only use it if the // upscaled mask is large (in which case clipping should remove many // pixels) #if USE_FIXEDPOINT if ((wSize > 2 * w && hSize > 2 * h && (int)wSize > 1000000 / (int)hSize) || (wSize > w && hSize > h && (int)wSize > 10000000 / (int)hSize)) { #else if ((wSize > 2 * w && hSize > 2 * h && wSize * hSize > 1000000) || (wSize > w && hSize > h && wSize * hSize > 10000000)) { upscaleMask(src, srcData, w, h, mat, glyphMode, interpolate); #endif // scaling only } else if (mat[0] > 0 && minorAxisZero && mat[3] > 0) { getImageBounds(mat[4], mat[0] + mat[4], &x0, &x1); getImageBounds(mat[5], mat[3] + mat[5], &y0, &y1); clipRes = state->clip->testRect(x0, y0, x1 - 1, y1 - 1, state->strokeAdjust); opClipRes = clipRes; if (clipRes != splashClipAllOutside) { scaledWidth = x1 - x0; scaledHeight = y1 - y0; scaledMask = scaleMask(src, srcData, w, h, scaledWidth, scaledHeight, interpolate); blitMask(scaledMask, x0, y0, clipRes); delete scaledMask; } // scaling plus vertical flip } else if (mat[0] > 0 && minorAxisZero && mat[3] < 0) { getImageBounds(mat[4], mat[0] + mat[4], &x0, &x1); getImageBounds(mat[3] + mat[5], mat[5], &y0, &y1); clipRes = state->clip->testRect(x0, y0, x1 - 1, y1 - 1, state->strokeAdjust); opClipRes = clipRes; if (clipRes != splashClipAllOutside) { scaledWidth = x1 - x0; scaledHeight = y1 - y0; scaledMask = scaleMask(src, srcData, w, h, scaledWidth, scaledHeight, interpolate); vertFlipImage(scaledMask, scaledWidth, scaledHeight, 1); blitMask(scaledMask, x0, y0, clipRes); delete scaledMask; } // scaling plus horizontal flip } else if (mat[0] < 0 && minorAxisZero && mat[3] > 0) { getImageBounds(mat[0] + mat[4], mat[4], &x0, &x1); getImageBounds(mat[5], mat[3] + mat[5], &y0, &y1); clipRes = state->clip->testRect(x0, y0, x1 - 1, y1 - 1, state->strokeAdjust); opClipRes = clipRes; if (clipRes != splashClipAllOutside) { scaledWidth = x1 - x0; scaledHeight = y1 - y0; scaledMask = scaleMask(src, srcData, w, h, scaledWidth, scaledHeight, interpolate); horizFlipImage(scaledMask, scaledWidth, scaledHeight, 1); blitMask(scaledMask, x0, y0, clipRes); delete scaledMask; } // scaling plus horizontal and vertical flips } else if (mat[0] < 0 && minorAxisZero && mat[3] < 0) { getImageBounds(mat[0] + mat[4], mat[4], &x0, &x1); getImageBounds(mat[3] + mat[5], mat[5], &y0, &y1); clipRes = state->clip->testRect(x0, y0, x1 - 1, y1 - 1, state->strokeAdjust); opClipRes = clipRes; if (clipRes != splashClipAllOutside) { scaledWidth = x1 - x0; scaledHeight = y1 - y0; scaledMask = scaleMask(src, srcData, w, h, scaledWidth, scaledHeight, interpolate); vertFlipImage(scaledMask, scaledWidth, scaledHeight, 1); horizFlipImage(scaledMask, scaledWidth, scaledHeight, 1); blitMask(scaledMask, x0, y0, clipRes); delete scaledMask; } // all other cases } else { arbitraryTransformMask(src, srcData, w, h, mat, glyphMode, interpolate); } return splashOk; } // The glyphMode flag is not currently used, but may be useful if the // stroke adjustment behavior is changed. void Splash::upscaleMask(SplashImageMaskSource src, void *srcData, int srcWidth, int srcHeight, SplashCoord *mat, GBool glyphMode, GBool interpolate) { SplashClipResult clipRes; SplashPipe pipe; Guchar *unscaledImage, *p; SplashCoord xMin, yMin, xMax, yMax, t; SplashCoord mi0, mi1, mi2, mi3, mi4, mi5, det; SplashCoord ix, iy, sx, sy, pix0, pix1; int xMinI, yMinI, xMaxI, yMaxI, x, y, x0, y0, x1, y1, tt; // compute the bbox of the target quadrilateral xMin = xMax = mat[4]; t = mat[2] + mat[4]; if (t < xMin) { xMin = t; } else if (t > xMax) { xMax = t; } t = mat[0] + mat[2] + mat[4]; if (t < xMin) { xMin = t; } else if (t > xMax) { xMax = t; } t = mat[0] + mat[4]; if (t < xMin) { xMin = t; } else if (t > xMax) { xMax = t; } getImageBounds(xMin, xMax, &xMinI, &xMaxI); yMin = yMax = mat[5]; t = mat[3] + mat[5]; if (t < yMin) { yMin = t; } else if (t > yMax) { yMax = t; } t = mat[1] + mat[3] + mat[5]; if (t < yMin) { yMin = t; } else if (t > yMax) { yMax = t; } t = mat[1] + mat[5]; if (t < yMin) { yMin = t; } else if (t > yMax) { yMax = t; } getImageBounds(yMin, yMax, &yMinI, &yMaxI); // clipping clipRes = state->clip->testRect(xMinI, yMinI, xMaxI - 1, yMaxI - 1, state->strokeAdjust); opClipRes = clipRes; if (clipRes == splashClipAllOutside) { return; } if (clipRes != splashClipAllInside) { if ((tt = state->clip->getXMinI(state->strokeAdjust)) > xMinI) { xMinI = tt; } if ((tt = state->clip->getXMaxI(state->strokeAdjust) + 1) < xMaxI) { xMaxI = tt; } if ((tt = state->clip->getYMinI(state->strokeAdjust)) > yMinI) { yMinI = tt; } if ((tt = state->clip->getYMaxI(state->strokeAdjust) + 1) < yMaxI) { yMaxI = tt; } } // invert the matrix det = mat[0] * mat[3] - mat[1] * mat[2]; if (splashAbs(det) < 1e-6) { // this should be caught by the singular matrix check in fillImageMask return; } det = (SplashCoord)1 / det; mi0 = det * mat[3] * srcWidth; mi1 = -det * mat[1] * srcHeight; mi2 = -det * mat[2] * srcWidth; mi3 = det * mat[0] * srcHeight; mi4 = det * (mat[2] * mat[5] - mat[3] * mat[4]) * srcWidth; mi5 = -det * (mat[0] * mat[5] - mat[1] * mat[4]) * srcHeight; // grab the image unscaledImage = (Guchar *)gmallocn(srcWidth, srcHeight); for (y = 0, p = unscaledImage; y < srcHeight; ++y, p += srcWidth) { (*src)(srcData, p); for (x = 0; x < srcWidth; ++x) { p[x] *= 255; } } // draw it pipeInit(&pipe, state->fillPattern, (Guchar)splashRound(state->fillAlpha * 255), gTrue, gFalse); for (y = yMinI; y < yMaxI; ++y) { for (x = xMinI; x < xMaxI; ++x) { ix = ((SplashCoord)x + 0.5) * mi0 + ((SplashCoord)y + 0.5) * mi2 + mi4; iy = ((SplashCoord)x + 0.5) * mi1 + ((SplashCoord)y + 0.5) * mi3 + mi5; if (interpolate) { if (ix >= 0 && ix < srcWidth && iy >= 0 && iy < srcHeight) { x0 = splashFloor(ix - 0.5); x1 = x0 + 1; sx = (ix - 0.5) - x0; y0 = splashFloor(iy - 0.5); y1 = y0 + 1; sy = (iy - 0.5) - y0; if (x0 < 0) { x0 = 0; } if (x1 >= srcWidth) { x1 = srcWidth - 1; } if (y0 < 0) { y0 = 0; } if (y1 >= srcHeight) { y1 = srcHeight - 1; } pix0 = ((SplashCoord)1 - sx) * (SplashCoord)unscaledImage[y0 * srcWidth + x0] + sx * (SplashCoord)unscaledImage[y0 * srcWidth + x1]; pix1 = ((SplashCoord)1 - sx) * (SplashCoord)unscaledImage[y1 * srcWidth + x0] + sx * (SplashCoord)unscaledImage[y1 * srcWidth + x1]; scanBuf[x] = (Guchar)splashRound(((SplashCoord)1 - sy) * pix0 + sy * pix1); } else { scanBuf[x] = 0; } } else { x0 = splashFloor(ix); y0 = splashFloor(iy); if (x0 >= 0 && x0 < srcWidth && y0 >= 0 && y0 < srcHeight) { scanBuf[x] = unscaledImage[y0 * srcWidth + x0]; } else { scanBuf[x] = 0; } } } if (clipRes != splashClipAllInside) { if (vectorAntialias) { state->clip->clipSpan(scanBuf, y, xMinI, xMaxI - 1, state->strokeAdjust); } else { state->clip->clipSpanBinary(scanBuf, y, xMinI, xMaxI - 1, state->strokeAdjust); } } (this->*pipe.run)(&pipe, xMinI, xMaxI - 1, y, scanBuf + xMinI, NULL); } gfree(unscaledImage); } // The glyphMode flag is not currently used, but may be useful if the // stroke adjustment behavior is changed. void Splash::arbitraryTransformMask(SplashImageMaskSource src, void *srcData, int srcWidth, int srcHeight, SplashCoord *mat, GBool glyphMode, GBool interpolate) { SplashBitmap *scaledMask; SplashClipResult clipRes; SplashPipe pipe; int scaledWidth, scaledHeight, t0, t1; SplashCoord r00, r01, r10, r11, det, ir00, ir01, ir10, ir11; SplashCoord vx[4], vy[4]; int xMin, yMin, xMax, yMax; ImageSection section[3]; int nSections; int y, xa, xb, x, i, xx, yy; // compute the four vertices of the target quadrilateral vx[0] = mat[4]; vy[0] = mat[5]; vx[1] = mat[2] + mat[4]; vy[1] = mat[3] + mat[5]; vx[2] = mat[0] + mat[2] + mat[4]; vy[2] = mat[1] + mat[3] + mat[5]; vx[3] = mat[0] + mat[4]; vy[3] = mat[1] + mat[5]; // clipping xMin = splashRound(vx[0]); xMax = splashRound(vx[0]); yMin = splashRound(vy[0]); yMax = splashRound(vy[0]); for (i = 1; i < 4; ++i) { t0 = splashRound(vx[i]); if (t0 < xMin) { xMin = t0; } else if (t0 > xMax) { xMax = t0; } t1 = splashRound(vy[i]); if (t1 < yMin) { yMin = t1; } else if (t1 > yMax) { yMax = t1; } } clipRes = state->clip->testRect(xMin, yMin, xMax - 1, yMax - 1, state->strokeAdjust); opClipRes = clipRes; if (clipRes == splashClipAllOutside) { return; } // compute the scale factors if (mat[0] >= 0) { t0 = splashRound(mat[0] + mat[4]) - splashRound(mat[4]); } else { t0 = splashRound(mat[4]) - splashRound(mat[0] + mat[4]); } if (mat[1] >= 0) { t1 = splashRound(mat[1] + mat[5]) - splashRound(mat[5]); } else { t1 = splashRound(mat[5]) - splashRound(mat[1] + mat[5]); } scaledWidth = t0 > t1 ? t0 : t1; if (mat[2] >= 0) { t0 = splashRound(mat[2] + mat[4]) - splashRound(mat[4]); } else { t0 = splashRound(mat[4]) - splashRound(mat[2] + mat[4]); } if (mat[3] >= 0) { t1 = splashRound(mat[3] + mat[5]) - splashRound(mat[5]); } else { t1 = splashRound(mat[5]) - splashRound(mat[3] + mat[5]); } scaledHeight = t0 > t1 ? t0 : t1; if (scaledWidth == 0) { scaledWidth = 1; } if (scaledHeight == 0) { scaledHeight = 1; } // compute the inverse transform (after scaling) matrix r00 = mat[0] / scaledWidth; r01 = mat[1] / scaledWidth; r10 = mat[2] / scaledHeight; r11 = mat[3] / scaledHeight; det = r00 * r11 - r01 * r10; if (splashAbs(det) < 1e-6) { // this should be caught by the singular matrix check in fillImageMask return; } ir00 = r11 / det; ir01 = -r01 / det; ir10 = -r10 / det; ir11 = r00 / det; // scale the input image scaledMask = scaleMask(src, srcData, srcWidth, srcHeight, scaledWidth, scaledHeight, interpolate); // construct the three sections i = 0; if (vy[1] < vy[i]) { i = 1; } if (vy[2] < vy[i]) { i = 2; } if (vy[3] < vy[i]) { i = 3; } // NB: if using fixed point, 0.000001 will be truncated to zero, // so these two comparisons must be <=, not < if (splashAbs(vy[i] - vy[(i-1) & 3]) <= 0.000001 && vy[(i-1) & 3] < vy[(i+1) & 3]) { i = (i-1) & 3; } if (splashAbs(vy[i] - vy[(i+1) & 3]) <= 0.000001) { section[0].y0 = splashRound(vy[i]); section[0].y1 = splashRound(vy[(i+2) & 3]) - 1; if (vx[i] < vx[(i+1) & 3]) { section[0].ia0 = i; section[0].ia1 = (i+3) & 3; section[0].ib0 = (i+1) & 3; section[0].ib1 = (i+2) & 3; } else { section[0].ia0 = (i+1) & 3; section[0].ia1 = (i+2) & 3; section[0].ib0 = i; section[0].ib1 = (i+3) & 3; } nSections = 1; } else { section[0].y0 = splashRound(vy[i]); section[2].y1 = splashRound(vy[(i+2) & 3]) - 1; section[0].ia0 = section[0].ib0 = i; section[2].ia1 = section[2].ib1 = (i+2) & 3; if (vx[(i+1) & 3] < vx[(i+3) & 3]) { section[0].ia1 = section[2].ia0 = (i+1) & 3; section[0].ib1 = section[2].ib0 = (i+3) & 3; } else { section[0].ia1 = section[2].ia0 = (i+3) & 3; section[0].ib1 = section[2].ib0 = (i+1) & 3; } if (vy[(i+1) & 3] < vy[(i+3) & 3]) { section[1].y0 = splashRound(vy[(i+1) & 3]); section[2].y0 = splashRound(vy[(i+3) & 3]); if (vx[(i+1) & 3] < vx[(i+3) & 3]) { section[1].ia0 = (i+1) & 3; section[1].ia1 = (i+2) & 3; section[1].ib0 = i; section[1].ib1 = (i+3) & 3; } else { section[1].ia0 = i; section[1].ia1 = (i+3) & 3; section[1].ib0 = (i+1) & 3; section[1].ib1 = (i+2) & 3; } } else { section[1].y0 = splashRound(vy[(i+3) & 3]); section[2].y0 = splashRound(vy[(i+1) & 3]); if (vx[(i+1) & 3] < vx[(i+3) & 3]) { section[1].ia0 = i; section[1].ia1 = (i+1) & 3; section[1].ib0 = (i+3) & 3; section[1].ib1 = (i+2) & 3; } else { section[1].ia0 = (i+3) & 3; section[1].ia1 = (i+2) & 3; section[1].ib0 = i; section[1].ib1 = (i+1) & 3; } } section[0].y1 = section[1].y0 - 1; section[1].y1 = section[2].y0 - 1; nSections = 3; } for (i = 0; i < nSections; ++i) { section[i].xa0 = vx[section[i].ia0]; section[i].ya0 = vy[section[i].ia0]; section[i].xa1 = vx[section[i].ia1]; section[i].ya1 = vy[section[i].ia1]; section[i].xb0 = vx[section[i].ib0]; section[i].yb0 = vy[section[i].ib0]; section[i].xb1 = vx[section[i].ib1]; section[i].yb1 = vy[section[i].ib1]; section[i].dxdya = (section[i].xa1 - section[i].xa0) / (section[i].ya1 - section[i].ya0); section[i].dxdyb = (section[i].xb1 - section[i].xb0) / (section[i].yb1 - section[i].yb0); } // initialize the pixel pipe pipeInit(&pipe, state->fillPattern, (Guchar)splashRound(state->fillAlpha * 255), gTrue, gFalse); // make sure narrow images cover at least one pixel if (nSections == 1) { if (section[0].y0 == section[0].y1) { ++section[0].y1; clipRes = opClipRes = splashClipPartial; } } else { if (section[0].y0 == section[2].y1) { ++section[1].y1; clipRes = opClipRes = splashClipPartial; } } // scan all pixels inside the target region for (i = 0; i < nSections; ++i) { for (y = section[i].y0; y <= section[i].y1; ++y) { xa = splashRound(section[i].xa0 + ((SplashCoord)y + 0.5 - section[i].ya0) * section[i].dxdya); xb = splashRound(section[i].xb0 + ((SplashCoord)y + 0.5 - section[i].yb0) * section[i].dxdyb); if (xa > xb) { continue; } // make sure narrow images cover at least one pixel if (xa == xb) { ++xb; } // check the scanBuf bounds if (xa >= bitmap->width || xb < 0) { continue; } if (xa < 0) { xa = 0; } if (xb > bitmap->width) { xb = bitmap->width; } // get the scan line for (x = xa; x < xb; ++x) { // map (x+0.5, y+0.5) back to the scaled image xx = splashFloor(((SplashCoord)x + 0.5 - mat[4]) * ir00 + ((SplashCoord)y + 0.5 - mat[5]) * ir10); yy = splashFloor(((SplashCoord)x + 0.5 - mat[4]) * ir01 + ((SplashCoord)y + 0.5 - mat[5]) * ir11); // xx should always be within bounds, but floating point // inaccuracy can cause problems if (xx < 0) { xx = 0; } else if (xx >= scaledWidth) { xx = scaledWidth - 1; } if (yy < 0) { yy = 0; } else if (yy >= scaledHeight) { yy = scaledHeight - 1; } scanBuf[x] = scaledMask->data[yy * scaledWidth + xx]; } // clip the scan line if (clipRes != splashClipAllInside) { if (vectorAntialias) { state->clip->clipSpan(scanBuf, y, xa, xb - 1, state->strokeAdjust); } else { state->clip->clipSpanBinary(scanBuf, y, xa, xb - 1, state->strokeAdjust); } } // draw the scan line (this->*pipe.run)(&pipe, xa, xb - 1, y, scanBuf + xa, NULL); } } delete scaledMask; } // Scale an image mask into a SplashBitmap. SplashBitmap *Splash::scaleMask(SplashImageMaskSource src, void *srcData, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, GBool interpolate) { SplashBitmap *dest; dest = new SplashBitmap(scaledWidth, scaledHeight, 1, splashModeMono8, gFalse); if (scaledHeight < srcHeight) { if (scaledWidth < srcWidth) { scaleMaskYdXd(src, srcData, srcWidth, srcHeight, scaledWidth, scaledHeight, dest); } else { scaleMaskYdXu(src, srcData, srcWidth, srcHeight, scaledWidth, scaledHeight, dest); } } else { if (scaledWidth < srcWidth) { scaleMaskYuXd(src, srcData, srcWidth, srcHeight, scaledWidth, scaledHeight, dest); } else { if (interpolate) { scaleMaskYuXuI(src, srcData, srcWidth, srcHeight, scaledWidth, scaledHeight, dest); } else { scaleMaskYuXu(src, srcData, srcWidth, srcHeight, scaledWidth, scaledHeight, dest); } } } return dest; } void Splash::scaleMaskYdXd(SplashImageMaskSource src, void *srcData, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, SplashBitmap *dest) { Guchar *lineBuf; Guint *pixBuf; Guint pix; Guchar *destPtr; int yp, yq, xp, xq, yt, y, yStep, xt, x, xStep, xx, d, d0, d1; int i, j; // Bresenham parameters for y scale yp = srcHeight / scaledHeight; yq = srcHeight % scaledHeight; // Bresenham parameters for x scale xp = srcWidth / scaledWidth; xq = srcWidth % scaledWidth; // allocate buffers lineBuf = (Guchar *)gmalloc(srcWidth); pixBuf = (Guint *)gmallocn(srcWidth, sizeof(int)); // init y scale Bresenham yt = 0; destPtr = dest->data; for (y = 0; y < scaledHeight; ++y) { // y scale Bresenham if ((yt += yq) >= scaledHeight) { yt -= scaledHeight; yStep = yp + 1; } else { yStep = yp; } // read rows from image memset(pixBuf, 0, srcWidth * sizeof(int)); for (i = 0; i < yStep; ++i) { (*src)(srcData, lineBuf); for (j = 0; j < srcWidth; ++j) { pixBuf[j] += lineBuf[j]; } } // init x scale Bresenham xt = 0; d0 = (255 << 23) / (yStep * xp); d1 = (255 << 23) / (yStep * (xp + 1)); xx = 0; for (x = 0; x < scaledWidth; ++x) { // x scale Bresenham if ((xt += xq) >= scaledWidth) { xt -= scaledWidth; xStep = xp + 1; d = d1; } else { xStep = xp; d = d0; } // compute the final pixel pix = 0; for (i = 0; i < xStep; ++i) { pix += pixBuf[xx++]; } // (255 * pix) / xStep * yStep pix = (pix * d) >> 23; // store the pixel *destPtr++ = (Guchar)pix; } } gfree(pixBuf); gfree(lineBuf); } void Splash::scaleMaskYdXu(SplashImageMaskSource src, void *srcData, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, SplashBitmap *dest) { Guchar *lineBuf; Guint *pixBuf; Guint pix; Guchar *destPtr; int yp, yq, xp, xq, yt, y, yStep, xt, x, xStep, d; int i, j; // Bresenham parameters for y scale yp = srcHeight / scaledHeight; yq = srcHeight % scaledHeight; // Bresenham parameters for x scale xp = scaledWidth / srcWidth; xq = scaledWidth % srcWidth; // allocate buffers lineBuf = (Guchar *)gmalloc(srcWidth); pixBuf = (Guint *)gmallocn(srcWidth, sizeof(int)); // init y scale Bresenham yt = 0; destPtr = dest->data; for (y = 0; y < scaledHeight; ++y) { // y scale Bresenham if ((yt += yq) >= scaledHeight) { yt -= scaledHeight; yStep = yp + 1; } else { yStep = yp; } // read rows from image memset(pixBuf, 0, srcWidth * sizeof(int)); for (i = 0; i < yStep; ++i) { (*src)(srcData, lineBuf); for (j = 0; j < srcWidth; ++j) { pixBuf[j] += lineBuf[j]; } } // init x scale Bresenham xt = 0; d = (255 << 23) / yStep; for (x = 0; x < srcWidth; ++x) { // x scale Bresenham if ((xt += xq) >= srcWidth) { xt -= srcWidth; xStep = xp + 1; } else { xStep = xp; } // compute the final pixel pix = pixBuf[x]; // (255 * pix) / yStep pix = (pix * d) >> 23; // store the pixel for (i = 0; i < xStep; ++i) { *destPtr++ = (Guchar)pix; } } } gfree(pixBuf); gfree(lineBuf); } void Splash::scaleMaskYuXd(SplashImageMaskSource src, void *srcData, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, SplashBitmap *dest) { Guchar *lineBuf; Guint pix; Guchar *destPtr0, *destPtr; int yp, yq, xp, xq, yt, y, yStep, xt, x, xStep, xx, d, d0, d1; int i; // Bresenham parameters for y scale yp = scaledHeight / srcHeight; yq = scaledHeight % srcHeight; // Bresenham parameters for x scale xp = srcWidth / scaledWidth; xq = srcWidth % scaledWidth; // allocate buffers lineBuf = (Guchar *)gmalloc(srcWidth); // init y scale Bresenham yt = 0; destPtr0 = dest->data; for (y = 0; y < srcHeight; ++y) { // y scale Bresenham if ((yt += yq) >= srcHeight) { yt -= srcHeight; yStep = yp + 1; } else { yStep = yp; } // read row from image (*src)(srcData, lineBuf); // init x scale Bresenham xt = 0; d0 = (255 << 23) / xp; d1 = (255 << 23) / (xp + 1); xx = 0; for (x = 0; x < scaledWidth; ++x) { // x scale Bresenham if ((xt += xq) >= scaledWidth) { xt -= scaledWidth; xStep = xp + 1; d = d1; } else { xStep = xp; d = d0; } // compute the final pixel pix = 0; for (i = 0; i < xStep; ++i) { pix += lineBuf[xx++]; } // (255 * pix) / xStep pix = (pix * d) >> 23; // store the pixel for (i = 0; i < yStep; ++i) { destPtr = destPtr0 + i * scaledWidth + x; *destPtr = (Guchar)pix; } } destPtr0 += yStep * scaledWidth; } gfree(lineBuf); } void Splash::scaleMaskYuXu(SplashImageMaskSource src, void *srcData, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, SplashBitmap *dest) { Guchar *lineBuf; Guchar pix; Guchar *srcPtr, *destPtr; int yp, yq, xp, xq, yt, y, yStep, xt, x, xStep; int i; // Bresenham parameters for y scale yp = scaledHeight / srcHeight; yq = scaledHeight % srcHeight; // Bresenham parameters for x scale xp = scaledWidth / srcWidth; xq = scaledWidth % srcWidth; // allocate buffers lineBuf = (Guchar *)gmalloc(srcWidth); // init y scale Bresenham yt = 0; destPtr = dest->data; for (y = 0; y < srcHeight; ++y) { // y scale Bresenham if ((yt += yq) >= srcHeight) { yt -= srcHeight; yStep = yp + 1; } else { yStep = yp; } // read row from image (*src)(srcData, lineBuf); // init x scale Bresenham xt = 0; // generate one row srcPtr = lineBuf; for (x = 0; x < srcWidth; ++x) { // x scale Bresenham if ((xt += xq) >= srcWidth) { xt -= srcWidth; xStep = xp + 1; } else { xStep = xp; } // compute the final pixel pix = *srcPtr ? 255 : 0; ++srcPtr; // duplicate the pixel horizontally for (i = 0; i < xStep; ++i) { *destPtr++ = pix; } } // duplicate the row vertically for (i = 1 ; i < yStep; ++i) { memcpy(destPtr, destPtr - scaledWidth, scaledWidth); destPtr += scaledWidth; } } gfree(lineBuf); } void Splash::scaleMaskYuXuI(SplashImageMaskSource src, void *srcData, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, SplashBitmap *dest) { Guchar *lineBuf0, *lineBuf1, *tBuf; Guchar pix; SplashCoord yr, xr, ys, xs, ySrc, xSrc; int ySrc0, ySrc1, yBuf, xSrc0, xSrc1, y, x; Guchar *destPtr; // ratios yr = (SplashCoord)srcHeight / (SplashCoord)scaledHeight; xr = (SplashCoord)srcWidth / (SplashCoord)scaledWidth; // allocate buffers lineBuf0 = (Guchar *)gmalloc(scaledWidth); lineBuf1 = (Guchar *)gmalloc(scaledWidth); // read first two rows (*src)(srcData, lineBuf0); if (srcHeight > 1) { (*src)(srcData, lineBuf1); yBuf = 1; } else { memcpy(lineBuf1, lineBuf0, srcWidth); yBuf = 0; } // interpolate first two rows for (x = scaledWidth - 1; x >= 0; --x) { xSrc = xr * x; xSrc0 = splashFloor(xSrc + xr * 0.5 - 0.5); xSrc1 = xSrc0 + 1; xs = ((SplashCoord)xSrc1 + 0.5) - (xSrc + xr * 0.5); if (xSrc0 < 0) { xSrc0 = 0; } if (xSrc1 >= srcWidth) { xSrc1 = srcWidth - 1; } lineBuf0[x] = (Guchar)(int) ((xs * (int)lineBuf0[xSrc0] + ((SplashCoord)1 - xs) * (int)lineBuf0[xSrc1]) * 255); lineBuf1[x] = (Guchar)(int) ((xs * (int)lineBuf1[xSrc0] + ((SplashCoord)1 - xs) * (int)lineBuf1[xSrc1]) * 255); } destPtr = dest->data; for (y = 0; y < scaledHeight; ++y) { // compute vertical interpolation parameters ySrc = yr * y; ySrc0 = splashFloor(ySrc + yr * 0.5 - 0.5); ySrc1 = ySrc0 + 1; ys = ((SplashCoord)ySrc1 + 0.5) - (ySrc + yr * 0.5); if (ySrc0 < 0) { ySrc0 = 0; ys = 1; } if (ySrc1 >= srcHeight) { ySrc1 = srcHeight - 1; ys = 0; } // read another row (if necessary) if (ySrc1 > yBuf) { tBuf = lineBuf0; lineBuf0 = lineBuf1; lineBuf1 = tBuf; (*src)(srcData, lineBuf1); // interpolate the row for (x = scaledWidth - 1; x >= 0; --x) { xSrc = xr * x; xSrc0 = splashFloor(xSrc + xr * 0.5 - 0.5); xSrc1 = xSrc0 + 1; xs = ((SplashCoord)xSrc1 + 0.5) - (xSrc + xr * 0.5); if (xSrc0 < 0) { xSrc0 = 0; } if (xSrc1 >= srcWidth) { xSrc1 = srcWidth - 1; } lineBuf1[x] = (Guchar)(int) ((xs * (int)lineBuf1[xSrc0] + ((SplashCoord)1 - xs) * (int)lineBuf1[xSrc1]) * 255); } ++yBuf; } // do the vertical interpolation for (x = 0; x < scaledWidth; ++x) { pix = (Guchar)(int)(ys * (int)lineBuf0[x] + ((SplashCoord)1 - ys) * (int)lineBuf1[x]); // store the pixel *destPtr++ = pix; } } gfree(lineBuf1); gfree(lineBuf0); } void Splash::blitMask(SplashBitmap *src, int xDest, int yDest, SplashClipResult clipRes) { SplashPipe pipe; int w, h, x0, x1, y0, y1, y, t; w = src->getWidth(); h = src->getHeight(); pipeInit(&pipe, state->fillPattern, (Guchar)splashRound(state->fillAlpha * 255), gTrue, gFalse); if (clipRes == splashClipAllInside) { for (y = 0; y < h; ++y) { (this->*pipe.run)(&pipe, xDest, xDest + w - 1, yDest + y, src->getDataPtr() + y * w, NULL); } } else { x0 = xDest; if ((t = state->clip->getXMinI(state->strokeAdjust)) > x0) { x0 = t; } x1 = xDest + w; if ((t = state->clip->getXMaxI(state->strokeAdjust) + 1) < x1) { x1 = t; } y0 = yDest; if ((t = state->clip->getYMinI(state->strokeAdjust)) > y0) { y0 = t; } y1 = yDest + h; if ((t = state->clip->getYMaxI(state->strokeAdjust) + 1) < y1) { y1 = t; } if (x0 < x1 && y0 < y1) { for (y = y0; y < y1; ++y) { memcpy(scanBuf + x0, src->getDataPtr() + (y - yDest) * w + (x0 - xDest), x1 - x0); if (vectorAntialias) { state->clip->clipSpan(scanBuf, y, x0, x1 - 1, state->strokeAdjust); } else { state->clip->clipSpanBinary(scanBuf, y, x0, x1 - 1, state->strokeAdjust); } (this->*pipe.run)(&pipe, x0, x1 - 1, y, scanBuf + x0, NULL); } } } } SplashError Splash::drawImage(SplashImageSource src, void *srcData, SplashColorMode srcMode, GBool srcAlpha, int w, int h, SplashCoord *mat, GBool interpolate) { GBool ok; SplashBitmap *scaledImg; SplashClipResult clipRes; GBool minorAxisZero; SplashCoord wSize, hSize, t0, t1; int x0, y0, x1, y1, scaledWidth, scaledHeight; int nComps; if (debugMode) { printf("drawImage: srcMode=%d srcAlpha=%d w=%d h=%d mat=[%.2f %.2f %.2f %.2f %.2f %.2f]\n", srcMode, srcAlpha, w, h, (double)mat[0], (double)mat[1], (double)mat[2], (double)mat[3], (double)mat[4], (double)mat[5]); } // check color modes ok = gFalse; // make gcc happy nComps = 0; // make gcc happy switch (bitmap->mode) { case splashModeMono1: case splashModeMono8: ok = srcMode == splashModeMono8; nComps = 1; break; case splashModeRGB8: case splashModeBGR8: ok = srcMode == splashModeRGB8; nComps = 3; break; #if SPLASH_CMYK case splashModeCMYK8: ok = srcMode == splashModeCMYK8; nComps = 4; break; #endif default: ok = gFalse; break; } if (!ok) { return splashErrModeMismatch; } // check for singular matrix if (!splashCheckDet(mat[0], mat[1], mat[2], mat[3], 0.000001)) { return splashErrSingularMatrix; } minorAxisZero = splashAbs(mat[1]) <= 0.0001 && splashAbs(mat[2]) <= 0.0001; // rough estimate of size of scaled image t0 = splashAbs(mat[0]); t1 = splashAbs(mat[1]); wSize = t0 > t1 ? t0 : t1; t0 = splashAbs(mat[2]); t1 = splashAbs(mat[3]); hSize = t0 > t1 ? t0 : t1; // stream-mode upscaling -- this is slower, so we only use it if the // upscaled image is large (in which case clipping should remove // many pixels) #if USE_FIXEDPOINT if ((wSize > 2 * w && hSize > 2 * h && (int)wSize > 1000000 / (int)hSize) || (wSize > w && hSize > h && (int)wSize > 10000000 / (int)hSize)) { #else if ((wSize > 2 * w && hSize > 2 * h && wSize * hSize > 1000000) || (wSize > w && hSize > h && wSize * hSize > 10000000)) { #endif upscaleImage(src, srcData, srcMode, nComps, srcAlpha, w, h, mat, interpolate); // scaling only } else if (mat[0] > 0 && minorAxisZero && mat[3] > 0) { getImageBounds(mat[4], mat[0] + mat[4], &x0, &x1); getImageBounds(mat[5], mat[3] + mat[5], &y0, &y1); clipRes = state->clip->testRect(x0, y0, x1 - 1, y1 - 1, state->strokeAdjust); opClipRes = clipRes; if (clipRes != splashClipAllOutside) { scaledWidth = x1 - x0; scaledHeight = y1 - y0; scaledImg = scaleImage(src, srcData, srcMode, nComps, srcAlpha, w, h, scaledWidth, scaledHeight, interpolate); blitImage(scaledImg, srcAlpha, x0, y0, clipRes); delete scaledImg; } // scaling plus vertical flip } else if (mat[0] > 0 && minorAxisZero && mat[3] < 0) { getImageBounds(mat[4], mat[0] + mat[4], &x0, &x1); getImageBounds(mat[3] + mat[5], mat[5], &y0, &y1); clipRes = state->clip->testRect(x0, y0, x1 - 1, y1 - 1, state->strokeAdjust); opClipRes = clipRes; if (clipRes != splashClipAllOutside) { scaledWidth = x1 - x0; scaledHeight = y1 - y0; scaledImg = scaleImage(src, srcData, srcMode, nComps, srcAlpha, w, h, scaledWidth, scaledHeight, interpolate); vertFlipImage(scaledImg, scaledWidth, scaledHeight, nComps); blitImage(scaledImg, srcAlpha, x0, y0, clipRes); delete scaledImg; } // scaling plus horizontal flip } else if (mat[0] < 0 && minorAxisZero && mat[3] > 0) { getImageBounds(mat[0] + mat[4], mat[4], &x0, &x1); getImageBounds(mat[5], mat[3] + mat[5], &y0, &y1); clipRes = state->clip->testRect(x0, y0, x1 - 1, y1 - 1, state->strokeAdjust); opClipRes = clipRes; if (clipRes != splashClipAllOutside) { scaledWidth = x1 - x0; scaledHeight = y1 - y0; scaledImg = scaleImage(src, srcData, srcMode, nComps, srcAlpha, w, h, scaledWidth, scaledHeight, interpolate); horizFlipImage(scaledImg, scaledWidth, scaledHeight, nComps); blitImage(scaledImg, srcAlpha, x0, y0, clipRes); delete scaledImg; } // scaling plus horizontal and vertical flips } else if (mat[0] < 0 && minorAxisZero && mat[3] < 0) { getImageBounds(mat[0] + mat[4], mat[4], &x0, &x1); getImageBounds(mat[3] + mat[5], mat[5], &y0, &y1); clipRes = state->clip->testRect(x0, y0, x1 - 1, y1 - 1, state->strokeAdjust); opClipRes = clipRes; if (clipRes != splashClipAllOutside) { scaledWidth = x1 - x0; scaledHeight = y1 - y0; scaledImg = scaleImage(src, srcData, srcMode, nComps, srcAlpha, w, h, scaledWidth, scaledHeight, interpolate); vertFlipImage(scaledImg, scaledWidth, scaledHeight, nComps); horizFlipImage(scaledImg, scaledWidth, scaledHeight, nComps); blitImage(scaledImg, srcAlpha, x0, y0, clipRes); delete scaledImg; } // all other cases } else { arbitraryTransformImage(src, srcData, srcMode, nComps, srcAlpha, w, h, mat, interpolate); } return splashOk; } void Splash::upscaleImage(SplashImageSource src, void *srcData, SplashColorMode srcMode, int nComps, GBool srcAlpha, int srcWidth, int srcHeight, SplashCoord *mat, GBool interpolate) { SplashClipResult clipRes; SplashPipe pipe; SplashColorPtr unscaledImage, pixelBuf, p, q, q00, q01, q10, q11; Guchar *unscaledAlpha, *alphaPtr; SplashCoord xMin, yMin, xMax, yMax, t; SplashCoord mi0, mi1, mi2, mi3, mi4, mi5, det; SplashCoord ix, iy, sx, sy, pix0, pix1; int rowSize, xMinI, yMinI, xMaxI, yMaxI, x, y, x0, y0, x1, y1, tt, i; // compute the bbox of the target quadrilateral xMin = xMax = mat[4]; t = mat[2] + mat[4]; if (t < xMin) { xMin = t; } else if (t > xMax) { xMax = t; } t = mat[0] + mat[2] + mat[4]; if (t < xMin) { xMin = t; } else if (t > xMax) { xMax = t; } t = mat[0] + mat[4]; if (t < xMin) { xMin = t; } else if (t > xMax) { xMax = t; } getImageBounds(xMin, xMax, &xMinI, &xMaxI); yMin = yMax = mat[5]; t = mat[3] + mat[5]; if (t < yMin) { yMin = t; } else if (t > yMax) { yMax = t; } t = mat[1] + mat[3] + mat[5]; if (t < yMin) { yMin = t; } else if (t > yMax) { yMax = t; } t = mat[1] + mat[5]; if (t < yMin) { yMin = t; } else if (t > yMax) { yMax = t; } getImageBounds(yMin, yMax, &yMinI, &yMaxI); // clipping clipRes = state->clip->testRect(xMinI, yMinI, xMaxI - 1, yMaxI - 1, state->strokeAdjust); opClipRes = clipRes; if (clipRes == splashClipAllOutside) { return; } if (clipRes != splashClipAllInside) { if ((tt = state->clip->getXMinI(state->strokeAdjust)) > xMinI) { xMinI = tt; } if ((tt = state->clip->getXMaxI(state->strokeAdjust) + 1) < xMaxI) { xMaxI = tt; } if ((tt = state->clip->getYMinI(state->strokeAdjust)) > yMinI) { yMinI = tt; } if ((tt = state->clip->getYMaxI(state->strokeAdjust) + 1) < yMaxI) { yMaxI = tt; } } // invert the matrix det = mat[0] * mat[3] - mat[1] * mat[2]; if (splashAbs(det) < 1e-6) { // this should be caught by the singular matrix check in fillImageMask return; } det = (SplashCoord)1 / det; mi0 = det * mat[3] * srcWidth; mi1 = -det * mat[1] * srcHeight; mi2 = -det * mat[2] * srcWidth; mi3 = det * mat[0] * srcHeight; mi4 = det * (mat[2] * mat[5] - mat[3] * mat[4]) * srcWidth; mi5 = -det * (mat[0] * mat[5] - mat[1] * mat[4]) * srcHeight; // grab the image if (srcWidth > INT_MAX / nComps) { rowSize = -1; } else { rowSize = srcWidth * nComps; } unscaledImage = (SplashColorPtr)gmallocn(srcHeight, rowSize); if (srcAlpha) { unscaledAlpha = (Guchar *)gmallocn(srcHeight, srcWidth); for (y = 0, p = unscaledImage, alphaPtr = unscaledAlpha; y < srcHeight; ++y, p += rowSize, alphaPtr += srcWidth) { (*src)(srcData, p, alphaPtr); } } else { unscaledAlpha = NULL; for (y = 0, p = unscaledImage; y < srcHeight; ++y, p += srcWidth * nComps) { (*src)(srcData, p, NULL); } } // draw it pixelBuf = (SplashColorPtr)gmallocn(xMaxI - xMinI, nComps); pipeInit(&pipe, NULL, (Guchar)splashRound(state->fillAlpha * 255), gTrue, gFalse); for (y = yMinI; y < yMaxI; ++y) { p = pixelBuf; for (x = xMinI; x < xMaxI; ++x) { ix = ((SplashCoord)x + 0.5) * mi0 + ((SplashCoord)y + 0.5) * mi2 + mi4; iy = ((SplashCoord)x + 0.5) * mi1 + ((SplashCoord)y + 0.5) * mi3 + mi5; if (interpolate) { if (ix >= 0 && ix < srcWidth && iy >= 0 && iy < srcHeight) { x0 = splashFloor(ix - 0.5); x1 = x0 + 1; sx = (ix - 0.5) - x0; y0 = splashFloor(iy - 0.5); y1 = y0 + 1; sy = (iy - 0.5) - y0; if (x0 < 0) { x0 = 0; } if (x1 >= srcWidth) { x1 = srcWidth - 1; } if (y0 < 0) { y0 = 0; } if (y1 >= srcHeight) { y1 = srcHeight - 1; } q00 = &unscaledImage[(y0 * srcWidth + x0) * nComps]; q01 = &unscaledImage[(y0 * srcWidth + x1) * nComps]; q10 = &unscaledImage[(y1 * srcWidth + x0) * nComps]; q11 = &unscaledImage[(y1 * srcWidth + x1) * nComps]; for (i = 0; i < nComps; ++i) { pix0 = ((SplashCoord)1 - sx) * (int)*q00++ + sx * (int)*q01++; pix1 = ((SplashCoord)1 - sx) * (int)*q10++ + sx * (int)*q11++; *p++ = (Guchar)splashRound(((SplashCoord)1 - sy) * pix0 + sy * pix1); } if (srcAlpha) { pix0 = ((SplashCoord)1 - sx) * (SplashCoord)unscaledAlpha[y0 * srcWidth + x0] + sx * (SplashCoord)unscaledAlpha[y0 * srcWidth + x1]; pix1 = ((SplashCoord)1 - sx) * (SplashCoord)unscaledAlpha[y1 * srcWidth + x0] + sx * (SplashCoord)unscaledAlpha[y1 * srcWidth + x1]; scanBuf[x] = (Guchar)splashRound(((SplashCoord)1 - sy) * pix0 + sy * pix1); } else { scanBuf[x] = 0xff; } } else { for (i = 0; i < nComps; ++i) { *p++ = 0; } scanBuf[x] = 0; } } else { x0 = splashFloor(ix); y0 = splashFloor(iy); if (x0 >= 0 && x0 < srcWidth && y0 >= 0 && y0 < srcHeight) { q = &unscaledImage[(y0 * srcWidth + x0) * nComps]; for (i = 0; i < nComps; ++i) { *p++ = *q++; } if (srcAlpha) { scanBuf[x] = unscaledAlpha[y0 * srcWidth + x0]; } else { scanBuf[x] = 0xff; } } else { for (i = 0; i < nComps; ++i) { *p++ = 0; } scanBuf[x] = 0; } } } if (clipRes != splashClipAllInside) { if (vectorAntialias) { state->clip->clipSpan(scanBuf, y, xMinI, xMaxI - 1, state->strokeAdjust); } else { state->clip->clipSpanBinary(scanBuf, y, xMinI, xMaxI - 1, state->strokeAdjust); } } (this->*pipe.run)(&pipe, xMinI, xMaxI - 1, y, scanBuf + xMinI, pixelBuf); } gfree(pixelBuf); gfree(unscaledImage); gfree(unscaledAlpha); } void Splash::arbitraryTransformImage(SplashImageSource src, void *srcData, SplashColorMode srcMode, int nComps, GBool srcAlpha, int srcWidth, int srcHeight, SplashCoord *mat, GBool interpolate) { SplashBitmap *scaledImg; SplashClipResult clipRes; SplashPipe pipe; SplashColorPtr pixelBuf; int scaledWidth, scaledHeight, t0, t1; SplashCoord r00, r01, r10, r11, det, ir00, ir01, ir10, ir11; SplashCoord vx[4], vy[4]; int xMin, yMin, xMax, yMax; ImageSection section[3]; int nSections; int y, xa, xb, x, i, xx, yy; // compute the four vertices of the target quadrilateral vx[0] = mat[4]; vy[0] = mat[5]; vx[1] = mat[2] + mat[4]; vy[1] = mat[3] + mat[5]; vx[2] = mat[0] + mat[2] + mat[4]; vy[2] = mat[1] + mat[3] + mat[5]; vx[3] = mat[0] + mat[4]; vy[3] = mat[1] + mat[5]; // clipping xMin = splashRound(vx[0]); xMax = splashRound(vx[0]); yMin = splashRound(vy[0]); yMax = splashRound(vy[0]); for (i = 1; i < 4; ++i) { t0 = splashRound(vx[i]); if (t0 < xMin) { xMin = t0; } else if (t0 > xMax) { xMax = t0; } t1 = splashRound(vy[i]); if (t1 < yMin) { yMin = t1; } else if (t1 > yMax) { yMax = t1; } } clipRes = state->clip->testRect(xMin, yMin, xMax - 1, yMax - 1, state->strokeAdjust); opClipRes = clipRes; if (clipRes == splashClipAllOutside) { return; } // compute the scale factors if (mat[0] >= 0) { t0 = splashRound(mat[0] + mat[4]) - splashRound(mat[4]); } else { t0 = splashRound(mat[4]) - splashRound(mat[0] + mat[4]); } if (mat[1] >= 0) { t1 = splashRound(mat[1] + mat[5]) - splashRound(mat[5]); } else { t1 = splashRound(mat[5]) - splashRound(mat[1] + mat[5]); } scaledWidth = t0 > t1 ? t0 : t1; if (mat[2] >= 0) { t0 = splashRound(mat[2] + mat[4]) - splashRound(mat[4]); } else { t0 = splashRound(mat[4]) - splashRound(mat[2] + mat[4]); } if (mat[3] >= 0) { t1 = splashRound(mat[3] + mat[5]) - splashRound(mat[5]); } else { t1 = splashRound(mat[5]) - splashRound(mat[3] + mat[5]); } scaledHeight = t0 > t1 ? t0 : t1; if (scaledWidth == 0) { scaledWidth = 1; } if (scaledHeight == 0) { scaledHeight = 1; } // compute the inverse transform (after scaling) matrix r00 = mat[0] / scaledWidth; r01 = mat[1] / scaledWidth; r10 = mat[2] / scaledHeight; r11 = mat[3] / scaledHeight; det = r00 * r11 - r01 * r10; if (splashAbs(det) < 1e-6) { // this should be caught by the singular matrix check in drawImage return; } ir00 = r11 / det; ir01 = -r01 / det; ir10 = -r10 / det; ir11 = r00 / det; // scale the input image scaledImg = scaleImage(src, srcData, srcMode, nComps, srcAlpha, srcWidth, srcHeight, scaledWidth, scaledHeight, interpolate); // construct the three sections i = 0; if (vy[1] < vy[i]) { i = 1; } if (vy[2] < vy[i]) { i = 2; } if (vy[3] < vy[i]) { i = 3; } // NB: if using fixed point, 0.000001 will be truncated to zero, // so these two comparisons must be <=, not < if (splashAbs(vy[i] - vy[(i-1) & 3]) <= 0.000001 && vy[(i-1) & 3] < vy[(i+1) & 3]) { i = (i-1) & 3; } if (splashAbs(vy[i] - vy[(i+1) & 3]) <= 0.000001) { section[0].y0 = splashRound(vy[i]); section[0].y1 = splashRound(vy[(i+2) & 3]) - 1; if (vx[i] < vx[(i+1) & 3]) { section[0].ia0 = i; section[0].ia1 = (i+3) & 3; section[0].ib0 = (i+1) & 3; section[0].ib1 = (i+2) & 3; } else { section[0].ia0 = (i+1) & 3; section[0].ia1 = (i+2) & 3; section[0].ib0 = i; section[0].ib1 = (i+3) & 3; } nSections = 1; } else { section[0].y0 = splashRound(vy[i]); section[2].y1 = splashRound(vy[(i+2) & 3]) - 1; section[0].ia0 = section[0].ib0 = i; section[2].ia1 = section[2].ib1 = (i+2) & 3; if (vx[(i+1) & 3] < vx[(i+3) & 3]) { section[0].ia1 = section[2].ia0 = (i+1) & 3; section[0].ib1 = section[2].ib0 = (i+3) & 3; } else { section[0].ia1 = section[2].ia0 = (i+3) & 3; section[0].ib1 = section[2].ib0 = (i+1) & 3; } if (vy[(i+1) & 3] < vy[(i+3) & 3]) { section[1].y0 = splashRound(vy[(i+1) & 3]); section[2].y0 = splashRound(vy[(i+3) & 3]); if (vx[(i+1) & 3] < vx[(i+3) & 3]) { section[1].ia0 = (i+1) & 3; section[1].ia1 = (i+2) & 3; section[1].ib0 = i; section[1].ib1 = (i+3) & 3; } else { section[1].ia0 = i; section[1].ia1 = (i+3) & 3; section[1].ib0 = (i+1) & 3; section[1].ib1 = (i+2) & 3; } } else { section[1].y0 = splashRound(vy[(i+3) & 3]); section[2].y0 = splashRound(vy[(i+1) & 3]); if (vx[(i+1) & 3] < vx[(i+3) & 3]) { section[1].ia0 = i; section[1].ia1 = (i+1) & 3; section[1].ib0 = (i+3) & 3; section[1].ib1 = (i+2) & 3; } else { section[1].ia0 = (i+3) & 3; section[1].ia1 = (i+2) & 3; section[1].ib0 = i; section[1].ib1 = (i+1) & 3; } } section[0].y1 = section[1].y0 - 1; section[1].y1 = section[2].y0 - 1; nSections = 3; } for (i = 0; i < nSections; ++i) { section[i].xa0 = vx[section[i].ia0]; section[i].ya0 = vy[section[i].ia0]; section[i].xa1 = vx[section[i].ia1]; section[i].ya1 = vy[section[i].ia1]; section[i].xb0 = vx[section[i].ib0]; section[i].yb0 = vy[section[i].ib0]; section[i].xb1 = vx[section[i].ib1]; section[i].yb1 = vy[section[i].ib1]; section[i].dxdya = (section[i].xa1 - section[i].xa0) / (section[i].ya1 - section[i].ya0); section[i].dxdyb = (section[i].xb1 - section[i].xb0) / (section[i].yb1 - section[i].yb0); } // initialize the pixel pipe pipeInit(&pipe, NULL, (Guchar)splashRound(state->fillAlpha * 255), gTrue, gFalse); // make sure narrow images cover at least one pixel if (nSections == 1) { if (section[0].y0 == section[0].y1) { ++section[0].y1; clipRes = opClipRes = splashClipPartial; } } else { if (section[0].y0 == section[2].y1) { ++section[1].y1; clipRes = opClipRes = splashClipPartial; } } pixelBuf = (SplashColorPtr)gmallocn(xMax - xMin + 1, bitmapComps); // scan all pixels inside the target region for (i = 0; i < nSections; ++i) { for (y = section[i].y0; y <= section[i].y1; ++y) { xa = splashRound(section[i].xa0 + ((SplashCoord)y + 0.5 - section[i].ya0) * section[i].dxdya); xb = splashRound(section[i].xb0 + ((SplashCoord)y + 0.5 - section[i].yb0) * section[i].dxdyb); if (xa > xb) { continue; } // make sure narrow images cover at least one pixel if (xa == xb) { ++xb; } // check the scanBuf bounds if (xa >= bitmap->width || xb < 0) { continue; } if (xa < 0) { xa = 0; } if (xb > bitmap->width) { xb = bitmap->width; } // clip the scan line memset(scanBuf + xa, 0xff, xb - xa); if (clipRes != splashClipAllInside) { if (vectorAntialias) { state->clip->clipSpan(scanBuf, y, xa, xb - 1, state->strokeAdjust); } else { state->clip->clipSpanBinary(scanBuf, y, xa, xb - 1, state->strokeAdjust); } } // draw the scan line for (x = xa; x < xb; ++x) { // map (x+0.5, y+0.5) back to the scaled image xx = splashFloor(((SplashCoord)x + 0.5 - mat[4]) * ir00 + ((SplashCoord)y + 0.5 - mat[5]) * ir10); yy = splashFloor(((SplashCoord)x + 0.5 - mat[4]) * ir01 + ((SplashCoord)y + 0.5 - mat[5]) * ir11); // xx should always be within bounds, but floating point // inaccuracy can cause problems if (xx < 0) { xx = 0; } else if (xx >= scaledWidth) { xx = scaledWidth - 1; } if (yy < 0) { yy = 0; } else if (yy >= scaledHeight) { yy = scaledHeight - 1; } // get the color scaledImg->getPixel(xx, yy, pixelBuf + (x - xa) * bitmapComps); // apply alpha if (srcAlpha) { scanBuf[x] = div255(scanBuf[x] * scaledImg->alpha[yy * scaledWidth + xx]); } } (this->*pipe.run)(&pipe, xa, xb - 1, y, scanBuf + xa, pixelBuf); } } gfree(pixelBuf); delete scaledImg; } // Scale an image into a SplashBitmap. SplashBitmap *Splash::scaleImage(SplashImageSource src, void *srcData, SplashColorMode srcMode, int nComps, GBool srcAlpha, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, GBool interpolate) { SplashBitmap *dest; dest = new SplashBitmap(scaledWidth, scaledHeight, 1, srcMode, srcAlpha); if (scaledHeight < srcHeight) { if (scaledWidth < srcWidth) { scaleImageYdXd(src, srcData, srcMode, nComps, srcAlpha, srcWidth, srcHeight, scaledWidth, scaledHeight, dest); } else { scaleImageYdXu(src, srcData, srcMode, nComps, srcAlpha, srcWidth, srcHeight, scaledWidth, scaledHeight, dest); } } else { if (scaledWidth < srcWidth) { scaleImageYuXd(src, srcData, srcMode, nComps, srcAlpha, srcWidth, srcHeight, scaledWidth, scaledHeight, dest); } else { if (interpolate) { scaleImageYuXuI(src, srcData, srcMode, nComps, srcAlpha, srcWidth, srcHeight, scaledWidth, scaledHeight, dest); } else { scaleImageYuXu(src, srcData, srcMode, nComps, srcAlpha, srcWidth, srcHeight, scaledWidth, scaledHeight, dest); } } } return dest; } void Splash::scaleImageYdXd(SplashImageSource src, void *srcData, SplashColorMode srcMode, int nComps, GBool srcAlpha, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, SplashBitmap *dest) { Guchar *lineBuf, *alphaLineBuf; Guint *pixBuf, *alphaPixBuf; Guint pix0, pix1, pix2; #if SPLASH_CMYK Guint pix3; #endif Guint alpha; Guchar *destPtr, *destAlphaPtr; int yp, yq, xp, xq, yt, y, yStep, xt, x, xStep, xx, xxa, d, d0, d1; int i, j; // Bresenham parameters for y scale yp = srcHeight / scaledHeight; yq = srcHeight % scaledHeight; // Bresenham parameters for x scale xp = srcWidth / scaledWidth; xq = srcWidth % scaledWidth; // allocate buffers lineBuf = (Guchar *)gmallocn(srcWidth, nComps); pixBuf = (Guint *)gmallocn(srcWidth, nComps * sizeof(int)); if (srcAlpha) { alphaLineBuf = (Guchar *)gmalloc(srcWidth); alphaPixBuf = (Guint *)gmallocn(srcWidth, sizeof(int)); } else { alphaLineBuf = NULL; alphaPixBuf = NULL; } // init y scale Bresenham yt = 0; destPtr = dest->data; destAlphaPtr = dest->alpha; for (y = 0; y < scaledHeight; ++y) { // y scale Bresenham if ((yt += yq) >= scaledHeight) { yt -= scaledHeight; yStep = yp + 1; } else { yStep = yp; } // read rows from image memset(pixBuf, 0, srcWidth * nComps * sizeof(int)); if (srcAlpha) { memset(alphaPixBuf, 0, srcWidth * sizeof(int)); } for (i = 0; i < yStep; ++i) { (*src)(srcData, lineBuf, alphaLineBuf); for (j = 0; j < srcWidth * nComps; ++j) { pixBuf[j] += lineBuf[j]; } if (srcAlpha) { for (j = 0; j < srcWidth; ++j) { alphaPixBuf[j] += alphaLineBuf[j]; } } } // init x scale Bresenham xt = 0; d0 = (1 << 23) / (yStep * xp); d1 = (1 << 23) / (yStep * (xp + 1)); xx = xxa = 0; for (x = 0; x < scaledWidth; ++x) { // x scale Bresenham if ((xt += xq) >= scaledWidth) { xt -= scaledWidth; xStep = xp + 1; d = d1; } else { xStep = xp; d = d0; } switch (srcMode) { case splashModeMono8: // compute the final pixel pix0 = 0; for (i = 0; i < xStep; ++i) { pix0 += pixBuf[xx++]; } // pix / xStep * yStep pix0 = (pix0 * d) >> 23; // store the pixel *destPtr++ = (Guchar)pix0; break; case splashModeRGB8: // compute the final pixel pix0 = pix1 = pix2 = 0; for (i = 0; i < xStep; ++i) { pix0 += pixBuf[xx]; pix1 += pixBuf[xx+1]; pix2 += pixBuf[xx+2]; xx += 3; } // pix / xStep * yStep pix0 = (pix0 * d) >> 23; pix1 = (pix1 * d) >> 23; pix2 = (pix2 * d) >> 23; // store the pixel *destPtr++ = (Guchar)pix0; *destPtr++ = (Guchar)pix1; *destPtr++ = (Guchar)pix2; break; #if SPLASH_CMYK case splashModeCMYK8: // compute the final pixel pix0 = pix1 = pix2 = pix3 = 0; for (i = 0; i < xStep; ++i) { pix0 += pixBuf[xx]; pix1 += pixBuf[xx+1]; pix2 += pixBuf[xx+2]; pix3 += pixBuf[xx+3]; xx += 4; } // pix / xStep * yStep pix0 = (pix0 * d) >> 23; pix1 = (pix1 * d) >> 23; pix2 = (pix2 * d) >> 23; pix3 = (pix3 * d) >> 23; // store the pixel *destPtr++ = (Guchar)pix0; *destPtr++ = (Guchar)pix1; *destPtr++ = (Guchar)pix2; *destPtr++ = (Guchar)pix3; break; #endif case splashModeMono1: // mono1 is not allowed case splashModeBGR8: // bgr8 is not allowed default: break; } // process alpha if (srcAlpha) { alpha = 0; for (i = 0; i < xStep; ++i, ++xxa) { alpha += alphaPixBuf[xxa]; } // alpha / xStep * yStep alpha = (alpha * d) >> 23; *destAlphaPtr++ = (Guchar)alpha; } } } gfree(alphaPixBuf); gfree(alphaLineBuf); gfree(pixBuf); gfree(lineBuf); } void Splash::scaleImageYdXu(SplashImageSource src, void *srcData, SplashColorMode srcMode, int nComps, GBool srcAlpha, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, SplashBitmap *dest) { Guchar *lineBuf, *alphaLineBuf; Guint *pixBuf, *alphaPixBuf; Guint pix[splashMaxColorComps]; Guint alpha; Guchar *destPtr, *destAlphaPtr; int yp, yq, xp, xq, yt, y, yStep, xt, x, xStep, d; int i, j; // Bresenham parameters for y scale yp = srcHeight / scaledHeight; yq = srcHeight % scaledHeight; // Bresenham parameters for x scale xp = scaledWidth / srcWidth; xq = scaledWidth % srcWidth; // allocate buffers lineBuf = (Guchar *)gmallocn(srcWidth, nComps); pixBuf = (Guint *)gmallocn(srcWidth, nComps * sizeof(int)); if (srcAlpha) { alphaLineBuf = (Guchar *)gmalloc(srcWidth); alphaPixBuf = (Guint *)gmallocn(srcWidth, sizeof(int)); } else { alphaLineBuf = NULL; alphaPixBuf = NULL; } // make gcc happy pix[0] = pix[1] = pix[2] = 0; #if SPLASH_CMYK pix[3] = 0; #endif // init y scale Bresenham yt = 0; destPtr = dest->data; destAlphaPtr = dest->alpha; for (y = 0; y < scaledHeight; ++y) { // y scale Bresenham if ((yt += yq) >= scaledHeight) { yt -= scaledHeight; yStep = yp + 1; } else { yStep = yp; } // read rows from image memset(pixBuf, 0, srcWidth * nComps * sizeof(int)); if (srcAlpha) { memset(alphaPixBuf, 0, srcWidth * sizeof(int)); } for (i = 0; i < yStep; ++i) { (*src)(srcData, lineBuf, alphaLineBuf); for (j = 0; j < srcWidth * nComps; ++j) { pixBuf[j] += lineBuf[j]; } if (srcAlpha) { for (j = 0; j < srcWidth; ++j) { alphaPixBuf[j] += alphaLineBuf[j]; } } } // init x scale Bresenham xt = 0; d = (1 << 23) / yStep; for (x = 0; x < srcWidth; ++x) { // x scale Bresenham if ((xt += xq) >= srcWidth) { xt -= srcWidth; xStep = xp + 1; } else { xStep = xp; } // compute the final pixel for (i = 0; i < nComps; ++i) { // pixBuf[] / yStep pix[i] = (pixBuf[x * nComps + i] * d) >> 23; } // store the pixel switch (srcMode) { case splashModeMono8: for (i = 0; i < xStep; ++i) { *destPtr++ = (Guchar)pix[0]; } break; case splashModeRGB8: for (i = 0; i < xStep; ++i) { *destPtr++ = (Guchar)pix[0]; *destPtr++ = (Guchar)pix[1]; *destPtr++ = (Guchar)pix[2]; } break; #if SPLASH_CMYK case splashModeCMYK8: for (i = 0; i < xStep; ++i) { *destPtr++ = (Guchar)pix[0]; *destPtr++ = (Guchar)pix[1]; *destPtr++ = (Guchar)pix[2]; *destPtr++ = (Guchar)pix[3]; } break; #endif case splashModeMono1: // mono1 is not allowed case splashModeBGR8: // BGR8 is not allowed default: break; } // process alpha if (srcAlpha) { // alphaPixBuf[] / yStep alpha = (alphaPixBuf[x] * d) >> 23; for (i = 0; i < xStep; ++i) { *destAlphaPtr++ = (Guchar)alpha; } } } } gfree(alphaPixBuf); gfree(alphaLineBuf); gfree(pixBuf); gfree(lineBuf); } void Splash::scaleImageYuXd(SplashImageSource src, void *srcData, SplashColorMode srcMode, int nComps, GBool srcAlpha, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, SplashBitmap *dest) { Guchar *lineBuf, *alphaLineBuf; Guint pix[splashMaxColorComps]; Guint alpha; Guchar *destPtr0, *destPtr, *destAlphaPtr0, *destAlphaPtr; int yp, yq, xp, xq, yt, y, yStep, xt, x, xStep, xx, xxa, d, d0, d1; int i, j; // Bresenham parameters for y scale yp = scaledHeight / srcHeight; yq = scaledHeight % srcHeight; // Bresenham parameters for x scale xp = srcWidth / scaledWidth; xq = srcWidth % scaledWidth; // allocate buffers lineBuf = (Guchar *)gmallocn(srcWidth, nComps); if (srcAlpha) { alphaLineBuf = (Guchar *)gmalloc(srcWidth); } else { alphaLineBuf = NULL; } // make gcc happy pix[0] = pix[1] = pix[2] = 0; #if SPLASH_CMYK pix[3] = 0; #endif // init y scale Bresenham yt = 0; destPtr0 = dest->data; destAlphaPtr0 = dest->alpha; for (y = 0; y < srcHeight; ++y) { // y scale Bresenham if ((yt += yq) >= srcHeight) { yt -= srcHeight; yStep = yp + 1; } else { yStep = yp; } // read row from image (*src)(srcData, lineBuf, alphaLineBuf); // init x scale Bresenham xt = 0; d0 = (1 << 23) / xp; d1 = (1 << 23) / (xp + 1); xx = xxa = 0; for (x = 0; x < scaledWidth; ++x) { // x scale Bresenham if ((xt += xq) >= scaledWidth) { xt -= scaledWidth; xStep = xp + 1; d = d1; } else { xStep = xp; d = d0; } // compute the final pixel for (i = 0; i < nComps; ++i) { pix[i] = 0; } for (i = 0; i < xStep; ++i) { for (j = 0; j < nComps; ++j, ++xx) { pix[j] += lineBuf[xx]; } } for (i = 0; i < nComps; ++i) { // pix[] / xStep pix[i] = (pix[i] * d) >> 23; } // store the pixel switch (srcMode) { case splashModeMono8: for (i = 0; i < yStep; ++i) { destPtr = destPtr0 + (i * scaledWidth + x) * nComps; *destPtr++ = (Guchar)pix[0]; } break; case splashModeRGB8: for (i = 0; i < yStep; ++i) { destPtr = destPtr0 + (i * scaledWidth + x) * nComps; *destPtr++ = (Guchar)pix[0]; *destPtr++ = (Guchar)pix[1]; *destPtr++ = (Guchar)pix[2]; } break; #if SPLASH_CMYK case splashModeCMYK8: for (i = 0; i < yStep; ++i) { destPtr = destPtr0 + (i * scaledWidth + x) * nComps; *destPtr++ = (Guchar)pix[0]; *destPtr++ = (Guchar)pix[1]; *destPtr++ = (Guchar)pix[2]; *destPtr++ = (Guchar)pix[3]; } break; #endif case splashModeMono1: // mono1 is not allowed case splashModeBGR8: // BGR8 is not allowed default: break; } // process alpha if (srcAlpha) { alpha = 0; for (i = 0; i < xStep; ++i, ++xxa) { alpha += alphaLineBuf[xxa]; } // alpha / xStep alpha = (alpha * d) >> 23; for (i = 0; i < yStep; ++i) { destAlphaPtr = destAlphaPtr0 + i * scaledWidth + x; *destAlphaPtr = (Guchar)alpha; } } } destPtr0 += yStep * scaledWidth * nComps; if (srcAlpha) { destAlphaPtr0 += yStep * scaledWidth; } } gfree(alphaLineBuf); gfree(lineBuf); } void Splash::scaleImageYuXu(SplashImageSource src, void *srcData, SplashColorMode srcMode, int nComps, GBool srcAlpha, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, SplashBitmap *dest) { Guchar *lineBuf, *alphaLineBuf; Guchar pix0, pix1, pix2; #if SPLASH_CMYK Guchar pix3; #endif Guint alpha; Guchar *srcPtr, *srcAlphaPtr; Guchar *destPtr, *destAlphaPtr; int yp, yq, xp, xq, yt, y, yStep, xt, x, xStep; int i; // Bresenham parameters for y scale yp = scaledHeight / srcHeight; yq = scaledHeight % srcHeight; // Bresenham parameters for x scale xp = scaledWidth / srcWidth; xq = scaledWidth % srcWidth; // allocate buffers lineBuf = (Guchar *)gmallocn(srcWidth, nComps); if (srcAlpha) { alphaLineBuf = (Guchar *)gmalloc(srcWidth); } else { alphaLineBuf = NULL; } // init y scale Bresenham yt = 0; destPtr = dest->data; destAlphaPtr = dest->alpha; for (y = 0; y < srcHeight; ++y) { // y scale Bresenham if ((yt += yq) >= srcHeight) { yt -= srcHeight; yStep = yp + 1; } else { yStep = yp; } // read row from image (*src)(srcData, lineBuf, alphaLineBuf); // init x scale Bresenham xt = 0; // generate one row srcPtr = lineBuf; srcAlphaPtr = alphaLineBuf; for (x = 0; x < srcWidth; ++x) { // x scale Bresenham if ((xt += xq) >= srcWidth) { xt -= srcWidth; xStep = xp + 1; } else { xStep = xp; } // duplicate the pixel horizontally switch (srcMode) { case splashModeMono8: pix0 = *srcPtr++; for (i = 0; i < xStep; ++i) { *destPtr++ = pix0; } break; case splashModeRGB8: pix0 = *srcPtr++; pix1 = *srcPtr++; pix2 = *srcPtr++; for (i = 0; i < xStep; ++i) { *destPtr++ = pix0; *destPtr++ = pix1; *destPtr++ = pix2; } break; #if SPLASH_CMYK case splashModeCMYK8: pix0 = *srcPtr++; pix1 = *srcPtr++; pix2 = *srcPtr++; pix3 = *srcPtr++; for (i = 0; i < xStep; ++i) { *destPtr++ = pix0; *destPtr++ = pix1; *destPtr++ = pix2; *destPtr++ = pix3; } break; #endif case splashModeMono1: // mono1 is not allowed case splashModeBGR8: // BGR8 is not allowed default: break; } // duplicate the alpha value horizontally if (srcAlpha) { alpha = *srcAlphaPtr++; for (i = 0; i < xStep; ++i) { *destAlphaPtr++ = alpha; } } } // duplicate the row vertically for (i = 1; i < yStep; ++i) { memcpy(destPtr, destPtr - scaledWidth * nComps, scaledWidth * nComps); destPtr += scaledWidth * nComps; } if (srcAlpha) { for (i = 1; i < yStep; ++i) { memcpy(destAlphaPtr, destAlphaPtr - scaledWidth, scaledWidth); destAlphaPtr += scaledWidth; } } } gfree(alphaLineBuf); gfree(lineBuf); } void Splash::scaleImageYuXuI(SplashImageSource src, void *srcData, SplashColorMode srcMode, int nComps, GBool srcAlpha, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, SplashBitmap *dest) { Guchar *lineBuf0, *lineBuf1, *alphaLineBuf0, *alphaLineBuf1, *tBuf; Guchar pix[splashMaxColorComps]; SplashCoord yr, xr, ys, xs, ySrc, xSrc; int ySrc0, ySrc1, yBuf, xSrc0, xSrc1, y, x, i; Guchar *destPtr, *destAlphaPtr; // ratios yr = (SplashCoord)srcHeight / (SplashCoord)scaledHeight; xr = (SplashCoord)srcWidth / (SplashCoord)scaledWidth; // allocate buffers lineBuf0 = (Guchar *)gmallocn(scaledWidth, nComps); lineBuf1 = (Guchar *)gmallocn(scaledWidth, nComps); if (srcAlpha) { alphaLineBuf0 = (Guchar *)gmalloc(scaledWidth); alphaLineBuf1 = (Guchar *)gmalloc(scaledWidth); } else { alphaLineBuf0 = NULL; alphaLineBuf1 = NULL; } // read first two rows (*src)(srcData, lineBuf0, alphaLineBuf0); if (srcHeight > 1) { (*src)(srcData, lineBuf1, alphaLineBuf1); yBuf = 1; } else { memcpy(lineBuf1, lineBuf0, srcWidth * nComps); if (srcAlpha) { memcpy(alphaLineBuf1, alphaLineBuf0, srcWidth); } yBuf = 0; } // interpolate first two rows for (x = scaledWidth - 1; x >= 0; --x) { xSrc = xr * x; xSrc0 = splashFloor(xSrc + xr * 0.5 - 0.5); xSrc1 = xSrc0 + 1; xs = ((SplashCoord)xSrc1 + 0.5) - (xSrc + xr * 0.5); if (xSrc0 < 0) { xSrc0 = 0; } if (xSrc1 >= srcWidth) { xSrc1 = srcWidth - 1; } for (i = 0; i < nComps; ++i) { lineBuf0[x*nComps+i] = (Guchar)(int) (xs * (int)lineBuf0[xSrc0*nComps+i] + ((SplashCoord)1 - xs) * (int)lineBuf0[xSrc1*nComps+i]); lineBuf1[x*nComps+i] = (Guchar)(int) (xs * (int)lineBuf1[xSrc0*nComps+i] + ((SplashCoord)1 - xs) * (int)lineBuf1[xSrc1*nComps+i]); } if (srcAlpha) { alphaLineBuf0[x] = (Guchar)(int) (xs * (int)alphaLineBuf0[xSrc0] + ((SplashCoord)1 - xs) * (int)alphaLineBuf0[xSrc1]); alphaLineBuf1[x] = (Guchar)(int) (xs * (int)alphaLineBuf1[xSrc0] + ((SplashCoord)1 - xs) * (int)alphaLineBuf1[xSrc1]); } } // make gcc happy pix[0] = pix[1] = pix[2] = 0; #if SPLASH_CMYK pix[3] = 0; #endif destPtr = dest->data; destAlphaPtr = dest->alpha; for (y = 0; y < scaledHeight; ++y) { // compute vertical interpolation parameters ySrc = yr * y; ySrc0 = splashFloor(ySrc + yr * 0.5 - 0.5); ySrc1 = ySrc0 + 1; ys = ((SplashCoord)ySrc1 + 0.5) - (ySrc + yr * 0.5); if (ySrc0 < 0) { ySrc0 = 0; ys = 1; } if (ySrc1 >= srcHeight) { ySrc1 = srcHeight - 1; ys = 0; } // read another row (if necessary) if (ySrc1 > yBuf) { tBuf = lineBuf0; lineBuf0 = lineBuf1; lineBuf1 = tBuf; tBuf = alphaLineBuf0; alphaLineBuf0 = alphaLineBuf1; alphaLineBuf1 = tBuf; (*src)(srcData, lineBuf1, alphaLineBuf1); // interpolate the row for (x = scaledWidth - 1; x >= 0; --x) { xSrc = xr * x; xSrc0 = splashFloor(xSrc + xr * 0.5 - 0.5); xSrc1 = xSrc0 + 1; xs = ((SplashCoord)xSrc1 + 0.5) - (xSrc + xr * 0.5); if (xSrc0 < 0) { xSrc0 = 0; } if (xSrc1 >= srcWidth) { xSrc1 = srcWidth - 1; } for (i = 0; i < nComps; ++i) { lineBuf1[x*nComps+i] = (Guchar)(int) (xs * (int)lineBuf1[xSrc0*nComps+i] + ((SplashCoord)1 - xs) * (int)lineBuf1[xSrc1*nComps+i]); } if (srcAlpha) { alphaLineBuf1[x] = (Guchar)(int) (xs * (int)alphaLineBuf1[xSrc0] + ((SplashCoord)1 - xs) * (int)alphaLineBuf1[xSrc1]); } } ++yBuf; } // do the vertical interpolation for (x = 0; x < scaledWidth; ++x) { for (i = 0; i < nComps; ++i) { pix[i] = (Guchar)(int) (ys * (int)lineBuf0[x*nComps+i] + ((SplashCoord)1 - ys) * (int)lineBuf1[x*nComps+i]); } // store the pixel switch (srcMode) { case splashModeMono8: *destPtr++ = pix[0]; break; case splashModeRGB8: *destPtr++ = pix[0]; *destPtr++ = pix[1]; *destPtr++ = pix[2]; break; #if SPLASH_CMYK case splashModeCMYK8: *destPtr++ = pix[0]; *destPtr++ = pix[1]; *destPtr++ = pix[2]; *destPtr++ = pix[3]; break; #endif case splashModeMono1: // mono1 is not allowed case splashModeBGR8: // BGR8 is not allowed default: break; } // process alpha if (srcAlpha) { *destAlphaPtr++ = (Guchar)(int) (ys * (int)alphaLineBuf0[x] + ((SplashCoord)1 - ys) * (int)alphaLineBuf1[x]); } } } gfree(alphaLineBuf1); gfree(alphaLineBuf0); gfree(lineBuf1); gfree(lineBuf0); } void Splash::vertFlipImage(SplashBitmap *img, int width, int height, int nComps) { Guchar *lineBuf; Guchar *p0, *p1; int w; w = width * nComps; lineBuf = (Guchar *)gmalloc(w); for (p0 = img->data, p1 = img->data + (height - 1) * w; p0 < p1; p0 += w, p1 -= w) { memcpy(lineBuf, p0, w); memcpy(p0, p1, w); memcpy(p1, lineBuf, w); } if (img->alpha) { for (p0 = img->alpha, p1 = img->alpha + (height - 1) * width; p0 < p1; p0 += width, p1 -= width) { memcpy(lineBuf, p0, width); memcpy(p0, p1, width); memcpy(p1, lineBuf, width); } } gfree(lineBuf); } void Splash::horizFlipImage(SplashBitmap *img, int width, int height, int nComps) { Guchar *lineBuf; SplashColorPtr p0, p1, p2; int w, x, y, i; w = width * nComps; lineBuf = (Guchar *)gmalloc(w); for (y = 0, p0 = img->data; y < height; ++y, p0 += img->rowSize) { memcpy(lineBuf, p0, w); p1 = p0; p2 = lineBuf + (w - nComps); for (x = 0; x < width; ++x) { for (i = 0; i < nComps; ++i) { p1[i] = p2[i]; } p1 += nComps; p2 -= nComps; } } if (img->alpha) { for (y = 0, p0 = img->alpha; y < height; ++y, p0 += width) { memcpy(lineBuf, p0, width); p1 = p0; p2 = lineBuf + (width - 1); for (x = 0; x < width; ++x) { *p1++ = *p2--; } } } gfree(lineBuf); } void Splash::blitImage(SplashBitmap *src, GBool srcAlpha, int xDest, int yDest, SplashClipResult clipRes) { SplashPipe pipe; int w, h, x0, y0, x1, y1, y; // split the image into clipped and unclipped regions w = src->getWidth(); h = src->getHeight(); if (clipRes == splashClipAllInside) { x0 = 0; y0 = 0; x1 = w; y1 = h; } else { if (state->clip->getNumPaths()) { x0 = x1 = w; y0 = y1 = h; } else { if ((x0 = splashCeil(state->clip->getXMin()) - xDest) < 0) { x0 = 0; } if ((y0 = splashCeil(state->clip->getYMin()) - yDest) < 0) { y0 = 0; } if ((x1 = splashFloor(state->clip->getXMax()) - xDest) > w) { x1 = w; } if (x1 < x0) { x1 = x0; } if ((y1 = splashFloor(state->clip->getYMax()) - yDest) > h) { y1 = h; } if (y1 < y0) { y1 = y0; } } } // draw the unclipped region if (x0 < w && y0 < h && x0 < x1 && y0 < y1) { pipeInit(&pipe, NULL, (Guchar)splashRound(state->fillAlpha * 255), srcAlpha, gFalse); if (srcAlpha) { for (y = y0; y < y1; ++y) { (this->*pipe.run)(&pipe, xDest + x0, xDest + x1 - 1, yDest + y, src->getAlphaPtr() + y * w + x0, src->getDataPtr() + y * src->getRowSize() + x0 * bitmapComps); } } else { for (y = y0; y < y1; ++y) { (this->*pipe.run)(&pipe, xDest + x0, xDest + x1 - 1, yDest + y, NULL, src->getDataPtr() + y * src->getRowSize() + x0 * bitmapComps); } } } // draw the clipped regions if (y0 > 0) { blitImageClipped(src, srcAlpha, 0, 0, xDest, yDest, w, y0); } if (y1 < h) { blitImageClipped(src, srcAlpha, 0, y1, xDest, yDest + y1, w, h - y1); } if (x0 > 0 && y0 < y1) { blitImageClipped(src, srcAlpha, 0, y0, xDest, yDest + y0, x0, y1 - y0); } if (x1 < w && y0 < y1) { blitImageClipped(src, srcAlpha, x1, y0, xDest + x1, yDest + y0, w - x1, y1 - y0); } } void Splash::blitImageClipped(SplashBitmap *src, GBool srcAlpha, int xSrc, int ySrc, int xDest, int yDest, int w, int h) { SplashPipe pipe; int y; if (xDest < 0) { xSrc -= xDest; w += xDest; xDest = 0; } if (xDest + w > bitmap->width) { w = bitmap->width - xDest; } if (yDest < 0) { ySrc -= yDest; h += yDest; yDest = 0; } if (yDest + h > bitmap->height) { h = bitmap->height - yDest; } if (w <= 0 || h <= 0) { return; } pipeInit(&pipe, NULL, (Guchar)splashRound(state->fillAlpha * 255), gTrue, gFalse); if (srcAlpha) { for (y = 0; y < h; ++y) { memcpy(scanBuf + xDest, src->getAlphaPtr() + (ySrc + y) * src->getWidth() + xSrc, w); if (vectorAntialias) { state->clip->clipSpan(scanBuf, yDest + y, xDest, xDest + w - 1, state->strokeAdjust); } else { state->clip->clipSpanBinary(scanBuf, yDest + y, xDest, xDest + w - 1, state->strokeAdjust); } (this->*pipe.run)(&pipe, xDest, xDest + w - 1, yDest + y, scanBuf + xDest, src->getDataPtr() + (ySrc + y) * src->getRowSize() + xSrc * bitmapComps); } } else { for (y = 0; y < h; ++y) { memset(scanBuf + xDest, 0xff, w); if (vectorAntialias) { state->clip->clipSpan(scanBuf, yDest + y, xDest, xDest + w - 1, state->strokeAdjust); } else { state->clip->clipSpanBinary(scanBuf, yDest + y, xDest, xDest + w - 1, state->strokeAdjust); } (this->*pipe.run)(&pipe, xDest, xDest + w - 1, yDest + y, scanBuf + xDest, src->getDataPtr() + (ySrc + y) * src->getRowSize() + xSrc * bitmapComps); } } } SplashError Splash::composite(SplashBitmap *src, int xSrc, int ySrc, int xDest, int yDest, int w, int h, GBool noClip, GBool nonIsolated) { SplashPipe pipe; Guchar *mono1Ptr, *lineBuf, *linePtr; Guchar mono1Mask, b; int x0, x1, x, y0, y1, y, t; if (!(src->mode == bitmap->mode || (src->mode == splashModeMono8 && bitmap->mode == splashModeMono1) || (src->mode == splashModeRGB8 && bitmap->mode == splashModeBGR8))) { return splashErrModeMismatch; } pipeInit(&pipe, NULL, (Guchar)splashRound(state->fillAlpha * 255), !noClip || src->alpha != NULL, nonIsolated); if (src->mode == splashModeMono1) { // in mono1 mode, pipeRun expects the source to be in mono8 // format, so we need to extract the source color values into // scanBuf, expanding them from mono1 to mono8 if (noClip) { if (src->alpha) { for (y = 0; y < h; ++y) { mono1Ptr = src->getDataPtr() + (ySrc + y) * src->rowSize + (xSrc >> 3); mono1Mask = 0x80 >> (xSrc & 7); for (x = 0; x < w; ++x) { scanBuf[x] = (*mono1Ptr & mono1Mask) ? 0xff : 0x00; mono1Ptr += mono1Mask & 1; mono1Mask = (mono1Mask << 7) | (mono1Mask >> 1); } // this uses shape instead of alpha, which isn't technically // correct, but works out the same (this->*pipe.run)(&pipe, xDest, xDest + w - 1, yDest + y, src->getAlphaPtr() + (ySrc + y) * src->getWidth() + xSrc, scanBuf); } } else { for (y = 0; y < h; ++y) { mono1Ptr = src->getDataPtr() + (ySrc + y) * src->rowSize + (xSrc >> 3); mono1Mask = 0x80 >> (xSrc & 7); for (x = 0; x < w; ++x) { scanBuf[x] = (*mono1Ptr & mono1Mask) ? 0xff : 0x00; mono1Ptr += mono1Mask & 1; mono1Mask = (mono1Mask << 7) | (mono1Mask >> 1); } (this->*pipe.run)(&pipe, xDest, xDest + w - 1, yDest + y, NULL, scanBuf); } } } else { x0 = xDest; if ((t = state->clip->getXMinI(state->strokeAdjust)) > x0) { x0 = t; } x1 = xDest + w; if ((t = state->clip->getXMaxI(state->strokeAdjust) + 1) < x1) { x1 = t; } y0 = yDest; if ((t = state->clip->getYMinI(state->strokeAdjust)) > y0) { y0 = t; } y1 = yDest + h; if ((t = state->clip->getYMaxI(state->strokeAdjust) + 1) < y1) { y1 = t; } if (x0 < x1 && y0 < y1) { if (src->alpha) { for (y = y0; y < y1; ++y) { mono1Ptr = src->getDataPtr() + (ySrc + y - yDest) * src->rowSize + ((xSrc + x0 - xDest) >> 3); mono1Mask = 0x80 >> ((xSrc + x0 - xDest) & 7); for (x = x0; x < x1; ++x) { scanBuf[x] = (*mono1Ptr & mono1Mask) ? 0xff : 0x00; mono1Ptr += mono1Mask & 1; mono1Mask = (mono1Mask << 7) | (mono1Mask >> 1); } memcpy(scanBuf2 + x0, src->getAlphaPtr() + (ySrc + y - yDest) * src->getWidth() + (xSrc + x0 - xDest), x1 - x0); if (!state->clip->clipSpanBinary(scanBuf2, y, x0, x1 - 1, state->strokeAdjust)) { continue; } // this uses shape instead of alpha, which isn't technically // correct, but works out the same (this->*pipe.run)(&pipe, x0, x1 - 1, y, scanBuf2 + x0, scanBuf + x0); } } else { for (y = y0; y < y1; ++y) { mono1Ptr = src->getDataPtr() + (ySrc + y - yDest) * src->rowSize + ((xSrc + x0 - xDest) >> 3); mono1Mask = 0x80 >> ((xSrc + x0 - xDest) & 7); for (x = x0; x < x1; ++x) { scanBuf[x] = (*mono1Ptr & mono1Mask) ? 0xff : 0x00; mono1Ptr += mono1Mask & 1; mono1Mask = (mono1Mask << 7) | (mono1Mask >> 1); } memset(scanBuf2 + x0, 0xff, x1 - x0); if (!state->clip->clipSpanBinary(scanBuf2, y, x0, x1 - 1, state->strokeAdjust)) { continue; } (this->*pipe.run)(&pipe, x0, x1 - 1, y, scanBuf2 + x0, scanBuf + x0); } } } } } else if (src->mode == splashModeBGR8) { // in BGR8 mode, pipeRun expects the source to be in RGB8 format, // so we need to swap bytes lineBuf = (Guchar *)gmallocn(w, 3); if (noClip) { if (src->alpha) { for (y = 0; y < h; ++y) { memcpy(lineBuf, src->getDataPtr() + (ySrc + y) * src->rowSize + xSrc * 3, w * 3); for (x = 0, linePtr = lineBuf; x < w; ++x, linePtr += 3) { b = linePtr[0]; linePtr[0] = linePtr[2]; linePtr[2] = b; } // this uses shape instead of alpha, which isn't technically // correct, but works out the same (this->*pipe.run)(&pipe, xDest, xDest + w - 1, yDest + y, src->getAlphaPtr() + (ySrc + y) * src->getWidth() + xSrc, lineBuf); } } else { for (y = 0; y < h; ++y) { memcpy(lineBuf, src->getDataPtr() + (ySrc + y) * src->rowSize + xSrc * 3, w * 3); for (x = 0, linePtr = lineBuf; x < w; ++x, linePtr += 3) { b = linePtr[0]; linePtr[0] = linePtr[2]; linePtr[2] = b; } (this->*pipe.run)(&pipe, xDest, xDest + w - 1, yDest + y, NULL, lineBuf); } } } else { x0 = xDest; if ((t = state->clip->getXMinI(state->strokeAdjust)) > x0) { x0 = t; } x1 = xDest + w; if ((t = state->clip->getXMaxI(state->strokeAdjust) + 1) < x1) { x1 = t; } y0 = yDest; if ((t = state->clip->getYMinI(state->strokeAdjust)) > y0) { y0 = t; } y1 = yDest + h; if ((t = state->clip->getYMaxI(state->strokeAdjust) + 1) < y1) { y1 = t; } if (x0 < x1 && y0 < y1) { if (src->alpha) { for (y = y0; y < y1; ++y) { memcpy(scanBuf + x0, src->getAlphaPtr() + (ySrc + y - yDest) * src->getWidth() + (xSrc + x0 - xDest), x1 - x0); state->clip->clipSpan(scanBuf, y, x0, x1 - 1, state->strokeAdjust); memcpy(lineBuf, src->getDataPtr() + (ySrc + y - yDest) * src->rowSize + (xSrc + x0 - xDest) * 3, (x1 - x0) * 3); for (x = 0, linePtr = lineBuf; x < x1 - x0; ++x, linePtr += 3) { b = linePtr[0]; linePtr[0] = linePtr[2]; linePtr[2] = b; } // this uses shape instead of alpha, which isn't technically // correct, but works out the same (this->*pipe.run)(&pipe, x0, x1 - 1, y, scanBuf + x0, lineBuf); } } else { for (y = y0; y < y1; ++y) { memset(scanBuf + x0, 0xff, x1 - x0); state->clip->clipSpan(scanBuf, y, x0, x1 - 1, state->strokeAdjust); memcpy(lineBuf, src->getDataPtr() + (ySrc + y - yDest) * src->rowSize + (xSrc + x0 - xDest) * 3, (x1 - x0) * 3); for (x = 0, linePtr = lineBuf; x < x1 - x0; ++x, linePtr += 3) { b = linePtr[0]; linePtr[0] = linePtr[2]; linePtr[2] = b; } (this->*pipe.run)(&pipe, x0, x1 - 1, yDest + y, scanBuf + x0, src->getDataPtr() + (ySrc + y - yDest) * src->rowSize + (xSrc + x0 - xDest) * bitmapComps); } } } } gfree(lineBuf); } else { // src->mode not mono1 or BGR8 if (noClip) { if (src->alpha) { for (y = 0; y < h; ++y) { // this uses shape instead of alpha, which isn't technically // correct, but works out the same (this->*pipe.run)(&pipe, xDest, xDest + w - 1, yDest + y, src->getAlphaPtr() + (ySrc + y) * src->getWidth() + xSrc, src->getDataPtr() + (ySrc + y) * src->rowSize + xSrc * bitmapComps); } } else { for (y = 0; y < h; ++y) { (this->*pipe.run)(&pipe, xDest, xDest + w - 1, yDest + y, NULL, src->getDataPtr() + (ySrc + y) * src->rowSize + xSrc * bitmapComps); } } } else { x0 = xDest; if ((t = state->clip->getXMinI(state->strokeAdjust)) > x0) { x0 = t; } x1 = xDest + w; if ((t = state->clip->getXMaxI(state->strokeAdjust) + 1) < x1) { x1 = t; } y0 = yDest; if ((t = state->clip->getYMinI(state->strokeAdjust)) > y0) { y0 = t; } y1 = yDest + h; if ((t = state->clip->getYMaxI(state->strokeAdjust) + 1) < y1) { y1 = t; } if (x0 < x1 && y0 < y1) { if (src->alpha) { for (y = y0; y < y1; ++y) { memcpy(scanBuf + x0, src->getAlphaPtr() + (ySrc + y - yDest) * src->getWidth() + (xSrc + x0 - xDest), x1 - x0); state->clip->clipSpan(scanBuf, y, x0, x1 - 1, state->strokeAdjust); // this uses shape instead of alpha, which isn't technically // correct, but works out the same (this->*pipe.run)(&pipe, x0, x1 - 1, y, scanBuf + x0, src->getDataPtr() + (ySrc + y - yDest) * src->rowSize + (xSrc + x0 - xDest) * bitmapComps); } } else { for (y = y0; y < y1; ++y) { memset(scanBuf + x0, 0xff, x1 - x0); state->clip->clipSpan(scanBuf, y, x0, x1 - 1, state->strokeAdjust); (this->*pipe.run)(&pipe, x0, x1 - 1, yDest + y, scanBuf + x0, src->getDataPtr() + (ySrc + y - yDest) * src->rowSize + (xSrc + x0 - xDest) * bitmapComps); } } } } } return splashOk; } void Splash::compositeBackground(SplashColorPtr color) { SplashColorPtr p; Guchar *q; Guchar alpha, alpha1, c, color0, color1, color2; #if SPLASH_CMYK Guchar color3; #endif int x, y, mask; switch (bitmap->mode) { case splashModeMono1: color0 = color[0]; for (y = 0; y < bitmap->height; ++y) { p = &bitmap->data[y * bitmap->rowSize]; q = &bitmap->alpha[y * bitmap->width]; mask = 0x80; for (x = 0; x < bitmap->width; ++x) { alpha = *q++; if (alpha == 0) { if (color0 & 0x80) { *p |= mask; } else { *p &= ~mask; } } else if (alpha != 255) { alpha1 = 255 - alpha; c = (*p & mask) ? 0xff : 0x00; c = div255(alpha1 * color0 + alpha * c); if (c & 0x80) { *p |= mask; } else { *p &= ~mask; } } if (!(mask >>= 1)) { mask = 0x80; ++p; } } } break; case splashModeMono8: color0 = color[0]; for (y = 0; y < bitmap->height; ++y) { p = &bitmap->data[y * bitmap->rowSize]; q = &bitmap->alpha[y * bitmap->width]; for (x = 0; x < bitmap->width; ++x) { alpha = *q++; if (alpha == 0) { p[0] = color0; } else if (alpha != 255) { alpha1 = 255 - alpha; p[0] = div255(alpha1 * color0 + alpha * p[0]); } ++p; } } break; case splashModeRGB8: case splashModeBGR8: color0 = color[0]; color1 = color[1]; color2 = color[2]; for (y = 0; y < bitmap->height; ++y) { p = &bitmap->data[y * bitmap->rowSize]; q = &bitmap->alpha[y * bitmap->width]; for (x = 0; x < bitmap->width; ++x) { alpha = *q++; if (alpha == 0) { p[0] = color0; p[1] = color1; p[2] = color2; } else if (alpha != 255) { alpha1 = 255 - alpha; p[0] = div255(alpha1 * color0 + alpha * p[0]); p[1] = div255(alpha1 * color1 + alpha * p[1]); p[2] = div255(alpha1 * color2 + alpha * p[2]); } p += 3; } } break; #if SPLASH_CMYK case splashModeCMYK8: color0 = color[0]; color1 = color[1]; color2 = color[2]; color3 = color[3]; for (y = 0; y < bitmap->height; ++y) { p = &bitmap->data[y * bitmap->rowSize]; q = &bitmap->alpha[y * bitmap->width]; for (x = 0; x < bitmap->width; ++x) { alpha = *q++; if (alpha == 0) { p[0] = color0; p[1] = color1; p[2] = color2; p[3] = color3; } else if (alpha != 255) { alpha1 = 255 - alpha; p[0] = div255(alpha1 * color0 + alpha * p[0]); p[1] = div255(alpha1 * color1 + alpha * p[1]); p[2] = div255(alpha1 * color2 + alpha * p[2]); p[3] = div255(alpha1 * color3 + alpha * p[3]); } p += 4; } } break; #endif } memset(bitmap->alpha, 255, bitmap->width * bitmap->height); } SplashError Splash::blitTransparent(SplashBitmap *src, int xSrc, int ySrc, int xDest, int yDest, int w, int h) { SplashColorPtr p, q; int x, y, mask, srcMask; if (src->mode != bitmap->mode) { return splashErrModeMismatch; } switch (bitmap->mode) { case splashModeMono1: for (y = 0; y < h; ++y) { p = &bitmap->data[(yDest + y) * bitmap->rowSize + (xDest >> 3)]; mask = 0x80 >> (xDest & 7); q = &src->data[(ySrc + y) * src->rowSize + (xSrc >> 3)]; srcMask = 0x80 >> (xSrc & 7); for (x = 0; x < w; ++x) { if (*q & srcMask) { *p |= mask; } else { *p &= ~mask; } if (!(mask >>= 1)) { mask = 0x80; ++p; } if (!(srcMask >>= 1)) { srcMask = 0x80; ++q; } } } break; case splashModeMono8: for (y = 0; y < h; ++y) { p = &bitmap->data[(yDest + y) * bitmap->rowSize + xDest]; q = &src->data[(ySrc + y) * src->rowSize + xSrc]; memcpy(p, q, w); } break; case splashModeRGB8: case splashModeBGR8: for (y = 0; y < h; ++y) { p = &bitmap->data[(yDest + y) * bitmap->rowSize + 3 * xDest]; q = &src->data[(ySrc + y) * src->rowSize + 3 * xSrc]; memcpy(p, q, 3 * w); } break; #if SPLASH_CMYK case splashModeCMYK8: for (y = 0; y < h; ++y) { p = &bitmap->data[(yDest + y) * bitmap->rowSize + 4 * xDest]; q = &src->data[(ySrc + y) * src->rowSize + 4 * xSrc]; memcpy(p, q, 4 * w); } break; #endif } if (bitmap->alpha) { for (y = 0; y < h; ++y) { q = &bitmap->alpha[(yDest + y) * bitmap->width + xDest]; memset(q, 0, w); } } return splashOk; } SplashError Splash::blitCorrectedAlpha(SplashBitmap *dest, int xSrc, int ySrc, int xDest, int yDest, int w, int h) { SplashColorPtr p, q; Guchar *alpha0Ptr; Guchar alpha0, aSrc; int x, y, mask, srcMask; if (bitmap->mode != dest->mode || !bitmap->alpha || !dest->alpha || !groupBackBitmap) { return splashErrModeMismatch; } switch (bitmap->mode) { case splashModeMono1: for (y = 0; y < h; ++y) { p = &dest->data[(yDest + y) * dest->rowSize + (xDest >> 3)]; mask = 0x80 >> (xDest & 7); q = &bitmap->data[(ySrc + y) * bitmap->rowSize + (xSrc >> 3)]; srcMask = 0x80 >> (xSrc & 7); for (x = 0; x < w; ++x) { if (*q & srcMask) { *p |= mask; } else { *p &= ~mask; } if (!(mask >>= 1)) { mask = 0x80; ++p; } if (!(srcMask >>= 1)) { srcMask = 0x80; ++q; } } } break; case splashModeMono8: for (y = 0; y < h; ++y) { p = &dest->data[(yDest + y) * dest->rowSize + xDest]; q = &bitmap->data[(ySrc + y) * bitmap->rowSize + xSrc]; memcpy(p, q, w); } break; case splashModeRGB8: case splashModeBGR8: for (y = 0; y < h; ++y) { p = &dest->data[(yDest + y) * dest->rowSize + 3 * xDest]; q = &bitmap->data[(ySrc + y) * bitmap->rowSize + 3 * xSrc]; memcpy(p, q, 3 * w); } break; #if SPLASH_CMYK case splashModeCMYK8: for (y = 0; y < h; ++y) { p = &dest->data[(yDest + y) * dest->rowSize + 4 * xDest]; q = &bitmap->data[(ySrc + y) * bitmap->rowSize + 4 * xSrc]; memcpy(p, q, 4 * w); } break; #endif } for (y = 0; y < h; ++y) { p = &dest->alpha[(yDest + y) * dest->width + xDest]; q = &bitmap->alpha[(ySrc + y) * bitmap->width + xSrc]; alpha0Ptr = &groupBackBitmap->alpha[(groupBackY + ySrc + y) * groupBackBitmap->width + (groupBackX + xSrc)]; for (x = 0; x < w; ++x) { alpha0 = *alpha0Ptr++; aSrc = *q++; *p++ = alpha0 + aSrc - div255(alpha0 * aSrc); } } return splashOk; } SplashPath *Splash::makeStrokePath(SplashPath *path, SplashCoord w, int lineCap, int lineJoin, GBool flatten) { SplashPath *pathIn, *dashPath, *pathOut; SplashCoord d, dx, dy, wdx, wdy, dxNext, dyNext, wdxNext, wdyNext; SplashCoord crossprod, dotprod, miter, m; SplashCoord angle, angleNext, dAngle, xc, yc; SplashCoord dxJoin, dyJoin, dJoin, kappa; SplashCoord cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4; GBool first, last, closed; int subpathStart0, subpathStart1, seg, i0, i1, j0, j1, k0, k1; int left0, left1, left2, right0, right1, right2, join0, join1, join2; int leftFirst, rightFirst, firstPt; pathOut = new SplashPath(); if (path->length == 0) { return pathOut; } if (flatten) { pathIn = flattenPath(path, state->matrix, state->flatness); if (state->lineDashLength > 0) { dashPath = makeDashedPath(pathIn); delete pathIn; pathIn = dashPath; if (pathIn->length == 0) { delete pathIn; return pathOut; } } } else { pathIn = path; } subpathStart0 = subpathStart1 = 0; // make gcc happy seg = 0; // make gcc happy closed = gFalse; // make gcc happy left0 = left1 = right0 = right1 = join0 = join1 = 0; // make gcc happy leftFirst = rightFirst = firstPt = 0; // make gcc happy i0 = 0; for (i1 = i0; !(pathIn->flags[i1] & splashPathLast) && i1 + 1 < pathIn->length && pathIn->pts[i1+1].x == pathIn->pts[i1].x && pathIn->pts[i1+1].y == pathIn->pts[i1].y; ++i1) ; while (i1 < pathIn->length) { if ((first = pathIn->flags[i0] & splashPathFirst)) { subpathStart0 = i0; subpathStart1 = i1; seg = 0; closed = pathIn->flags[i0] & splashPathClosed; } j0 = i1 + 1; if (j0 < pathIn->length) { for (j1 = j0; !(pathIn->flags[j1] & splashPathLast) && j1 + 1 < pathIn->length && pathIn->pts[j1+1].x == pathIn->pts[j1].x && pathIn->pts[j1+1].y == pathIn->pts[j1].y; ++j1) ; } else { j1 = j0; } if (pathIn->flags[i1] & splashPathLast) { if (first && lineCap == splashLineCapRound) { // special case: zero-length subpath with round line caps --> // draw a circle pathOut->moveTo(pathIn->pts[i0].x + (SplashCoord)0.5 * w, pathIn->pts[i0].y); pathOut->curveTo(pathIn->pts[i0].x + (SplashCoord)0.5 * w, pathIn->pts[i0].y + bezierCircle2 * w, pathIn->pts[i0].x + bezierCircle2 * w, pathIn->pts[i0].y + (SplashCoord)0.5 * w, pathIn->pts[i0].x, pathIn->pts[i0].y + (SplashCoord)0.5 * w); pathOut->curveTo(pathIn->pts[i0].x - bezierCircle2 * w, pathIn->pts[i0].y + (SplashCoord)0.5 * w, pathIn->pts[i0].x - (SplashCoord)0.5 * w, pathIn->pts[i0].y + bezierCircle2 * w, pathIn->pts[i0].x - (SplashCoord)0.5 * w, pathIn->pts[i0].y); pathOut->curveTo(pathIn->pts[i0].x - (SplashCoord)0.5 * w, pathIn->pts[i0].y - bezierCircle2 * w, pathIn->pts[i0].x - bezierCircle2 * w, pathIn->pts[i0].y - (SplashCoord)0.5 * w, pathIn->pts[i0].x, pathIn->pts[i0].y - (SplashCoord)0.5 * w); pathOut->curveTo(pathIn->pts[i0].x + bezierCircle2 * w, pathIn->pts[i0].y - (SplashCoord)0.5 * w, pathIn->pts[i0].x + (SplashCoord)0.5 * w, pathIn->pts[i0].y - bezierCircle2 * w, pathIn->pts[i0].x + (SplashCoord)0.5 * w, pathIn->pts[i0].y); pathOut->close(); } i0 = j0; i1 = j1; continue; } last = pathIn->flags[j1] & splashPathLast; if (last) { k0 = subpathStart1 + 1; } else { k0 = j1 + 1; } for (k1 = k0; !(pathIn->flags[k1] & splashPathLast) && k1 + 1 < pathIn->length && pathIn->pts[k1+1].x == pathIn->pts[k1].x && pathIn->pts[k1+1].y == pathIn->pts[k1].y; ++k1) ; // compute the deltas for segment (i1, j0) #if USE_FIXEDPOINT // the 1/d value can be small, which introduces significant // inaccuracies in fixed point mode d = splashDist(pathIn->pts[i1].x, pathIn->pts[i1].y, pathIn->pts[j0].x, pathIn->pts[j0].y); dx = (pathIn->pts[j0].x - pathIn->pts[i1].x) / d; dy = (pathIn->pts[j0].y - pathIn->pts[i1].y) / d; #else d = (SplashCoord)1 / splashDist(pathIn->pts[i1].x, pathIn->pts[i1].y, pathIn->pts[j0].x, pathIn->pts[j0].y); dx = d * (pathIn->pts[j0].x - pathIn->pts[i1].x); dy = d * (pathIn->pts[j0].y - pathIn->pts[i1].y); #endif wdx = (SplashCoord)0.5 * w * dx; wdy = (SplashCoord)0.5 * w * dy; // draw the start cap if (i0 == subpathStart0) { firstPt = pathOut->length; } if (first && !closed) { switch (lineCap) { case splashLineCapButt: pathOut->moveTo(pathIn->pts[i0].x - wdy, pathIn->pts[i0].y + wdx); pathOut->lineTo(pathIn->pts[i0].x + wdy, pathIn->pts[i0].y - wdx); break; case splashLineCapRound: pathOut->moveTo(pathIn->pts[i0].x - wdy, pathIn->pts[i0].y + wdx); pathOut->curveTo(pathIn->pts[i0].x - wdy - bezierCircle * wdx, pathIn->pts[i0].y + wdx - bezierCircle * wdy, pathIn->pts[i0].x - wdx - bezierCircle * wdy, pathIn->pts[i0].y - wdy + bezierCircle * wdx, pathIn->pts[i0].x - wdx, pathIn->pts[i0].y - wdy); pathOut->curveTo(pathIn->pts[i0].x - wdx + bezierCircle * wdy, pathIn->pts[i0].y - wdy - bezierCircle * wdx, pathIn->pts[i0].x + wdy - bezierCircle * wdx, pathIn->pts[i0].y - wdx - bezierCircle * wdy, pathIn->pts[i0].x + wdy, pathIn->pts[i0].y - wdx); break; case splashLineCapProjecting: pathOut->moveTo(pathIn->pts[i0].x - wdx - wdy, pathIn->pts[i0].y + wdx - wdy); pathOut->lineTo(pathIn->pts[i0].x - wdx + wdy, pathIn->pts[i0].y - wdx - wdy); break; } } else { pathOut->moveTo(pathIn->pts[i0].x - wdy, pathIn->pts[i0].y + wdx); pathOut->lineTo(pathIn->pts[i0].x + wdy, pathIn->pts[i0].y - wdx); } // draw the left side of the segment rectangle and the end cap left2 = pathOut->length - 1; if (last && !closed) { switch (lineCap) { case splashLineCapButt: pathOut->lineTo(pathIn->pts[j0].x + wdy, pathIn->pts[j0].y - wdx); pathOut->lineTo(pathIn->pts[j0].x - wdy, pathIn->pts[j0].y + wdx); break; case splashLineCapRound: pathOut->lineTo(pathIn->pts[j0].x + wdy, pathIn->pts[j0].y - wdx); pathOut->curveTo(pathIn->pts[j0].x + wdy + bezierCircle * wdx, pathIn->pts[j0].y - wdx + bezierCircle * wdy, pathIn->pts[j0].x + wdx + bezierCircle * wdy, pathIn->pts[j0].y + wdy - bezierCircle * wdx, pathIn->pts[j0].x + wdx, pathIn->pts[j0].y + wdy); pathOut->curveTo(pathIn->pts[j0].x + wdx - bezierCircle * wdy, pathIn->pts[j0].y + wdy + bezierCircle * wdx, pathIn->pts[j0].x - wdy + bezierCircle * wdx, pathIn->pts[j0].y + wdx + bezierCircle * wdy, pathIn->pts[j0].x - wdy, pathIn->pts[j0].y + wdx); break; case splashLineCapProjecting: pathOut->lineTo(pathIn->pts[j0].x + wdy + wdx, pathIn->pts[j0].y - wdx + wdy); pathOut->lineTo(pathIn->pts[j0].x - wdy + wdx, pathIn->pts[j0].y + wdx + wdy); break; } } else { pathOut->lineTo(pathIn->pts[j0].x + wdy, pathIn->pts[j0].y - wdx); pathOut->lineTo(pathIn->pts[j0].x - wdy, pathIn->pts[j0].y + wdx); } // draw the right side of the segment rectangle // (NB: if stroke adjustment is enabled, the closepath operation MUST // add a segment because this segment is used for a hint) right2 = pathOut->length - 1; pathOut->close(state->strokeAdjust != splashStrokeAdjustOff); // draw the join join2 = pathOut->length; if (!last || closed) { // compute the deltas for segment (j1, k0) #if USE_FIXEDPOINT // the 1/d value can be small, which introduces significant // inaccuracies in fixed point mode d = splashDist(pathIn->pts[j1].x, pathIn->pts[j1].y, pathIn->pts[k0].x, pathIn->pts[k0].y); dxNext = (pathIn->pts[k0].x - pathIn->pts[j1].x) / d; dyNext = (pathIn->pts[k0].y - pathIn->pts[j1].y) / d; #else d = (SplashCoord)1 / splashDist(pathIn->pts[j1].x, pathIn->pts[j1].y, pathIn->pts[k0].x, pathIn->pts[k0].y); dxNext = d * (pathIn->pts[k0].x - pathIn->pts[j1].x); dyNext = d * (pathIn->pts[k0].y - pathIn->pts[j1].y); #endif wdxNext = (SplashCoord)0.5 * w * dxNext; wdyNext = (SplashCoord)0.5 * w * dyNext; // compute the join parameters crossprod = dx * dyNext - dy * dxNext; dotprod = -(dx * dxNext + dy * dyNext); if (dotprod > 0.9999) { // avoid a divide-by-zero -- set miter to something arbitrary // such that sqrt(miter) will exceed miterLimit (and m is never // used in that situation) // (note: the comparison value (0.9999) has to be less than // 1-epsilon, where epsilon is the smallest value // representable in the fixed point format) miter = (state->miterLimit + 1) * (state->miterLimit + 1); m = 0; } else { miter = (SplashCoord)2 / ((SplashCoord)1 - dotprod); if (miter < 1) { // this can happen because of floating point inaccuracies miter = 1; } m = splashSqrt(miter - 1); } // round join if (lineJoin == splashLineJoinRound) { // join angle < 180 if (crossprod < 0) { angle = atan2((double)dx, (double)-dy); angleNext = atan2((double)dxNext, (double)-dyNext); if (angle < angleNext) { angle += 2 * M_PI; } dAngle = (angle - angleNext) / M_PI; if (dAngle < 0.501) { // span angle is <= 90 degrees -> draw a single arc kappa = dAngle * bezierCircle * w; cx1 = pathIn->pts[j0].x - wdy + kappa * dx; cy1 = pathIn->pts[j0].y + wdx + kappa * dy; cx2 = pathIn->pts[j0].x - wdyNext - kappa * dxNext; cy2 = pathIn->pts[j0].y + wdxNext - kappa * dyNext; pathOut->moveTo(pathIn->pts[j0].x, pathIn->pts[j0].y); pathOut->lineTo(pathIn->pts[j0].x - wdyNext, pathIn->pts[j0].y + wdxNext); pathOut->curveTo(cx2, cy2, cx1, cy1, pathIn->pts[j0].x - wdy, pathIn->pts[j0].y + wdx); } else { // span angle is > 90 degrees -> split into two arcs dJoin = splashDist(-wdy, wdx, -wdyNext, wdxNext); if (dJoin > 0) { dxJoin = (-wdyNext + wdy) / dJoin; dyJoin = (wdxNext - wdx) / dJoin; xc = pathIn->pts[j0].x + (SplashCoord)0.5 * w * cos((double)((SplashCoord)0.5 * (angle + angleNext))); yc = pathIn->pts[j0].y + (SplashCoord)0.5 * w * sin((double)((SplashCoord)0.5 * (angle + angleNext))); kappa = dAngle * bezierCircle2 * w; cx1 = pathIn->pts[j0].x - wdy + kappa * dx; cy1 = pathIn->pts[j0].y + wdx + kappa * dy; cx2 = xc - kappa * dxJoin; cy2 = yc - kappa * dyJoin; cx3 = xc + kappa * dxJoin; cy3 = yc + kappa * dyJoin; cx4 = pathIn->pts[j0].x - wdyNext - kappa * dxNext; cy4 = pathIn->pts[j0].y + wdxNext - kappa * dyNext; pathOut->moveTo(pathIn->pts[j0].x, pathIn->pts[j0].y); pathOut->lineTo(pathIn->pts[j0].x - wdyNext, pathIn->pts[j0].y + wdxNext); pathOut->curveTo(cx4, cy4, cx3, cy3, xc, yc); pathOut->curveTo(cx2, cy2, cx1, cy1, pathIn->pts[j0].x - wdy, pathIn->pts[j0].y + wdx); } } // join angle >= 180 } else { angle = atan2((double)-dx, (double)dy); angleNext = atan2((double)-dxNext, (double)dyNext); if (angleNext < angle) { angleNext += 2 * M_PI; } dAngle = (angleNext - angle) / M_PI; if (dAngle < 0.501) { // span angle is <= 90 degrees -> draw a single arc kappa = dAngle * bezierCircle * w; cx1 = pathIn->pts[j0].x + wdy + kappa * dx; cy1 = pathIn->pts[j0].y - wdx + kappa * dy; cx2 = pathIn->pts[j0].x + wdyNext - kappa * dxNext; cy2 = pathIn->pts[j0].y - wdxNext - kappa * dyNext; pathOut->moveTo(pathIn->pts[j0].x, pathIn->pts[j0].y); pathOut->lineTo(pathIn->pts[j0].x + wdy, pathIn->pts[j0].y - wdx); pathOut->curveTo(cx1, cy1, cx2, cy2, pathIn->pts[j0].x + wdyNext, pathIn->pts[j0].y - wdxNext); } else { // span angle is > 90 degrees -> split into two arcs dJoin = splashDist(wdy, -wdx, wdyNext, -wdxNext); if (dJoin > 0) { dxJoin = (wdyNext - wdy) / dJoin; dyJoin = (-wdxNext + wdx) / dJoin; xc = pathIn->pts[j0].x + (SplashCoord)0.5 * w * cos((double)((SplashCoord)0.5 * (angle + angleNext))); yc = pathIn->pts[j0].y + (SplashCoord)0.5 * w * sin((double)((SplashCoord)0.5 * (angle + angleNext))); kappa = dAngle * bezierCircle2 * w; cx1 = pathIn->pts[j0].x + wdy + kappa * dx; cy1 = pathIn->pts[j0].y - wdx + kappa * dy; cx2 = xc - kappa * dxJoin; cy2 = yc - kappa * dyJoin; cx3 = xc + kappa * dxJoin; cy3 = yc + kappa * dyJoin; cx4 = pathIn->pts[j0].x + wdyNext - kappa * dxNext; cy4 = pathIn->pts[j0].y - wdxNext - kappa * dyNext; pathOut->moveTo(pathIn->pts[j0].x, pathIn->pts[j0].y); pathOut->lineTo(pathIn->pts[j0].x + wdy, pathIn->pts[j0].y - wdx); pathOut->curveTo(cx1, cy1, cx2, cy2, xc, yc); pathOut->curveTo(cx3, cy3, cx4, cy4, pathIn->pts[j0].x + wdyNext, pathIn->pts[j0].y - wdxNext); } } } } else { pathOut->moveTo(pathIn->pts[j0].x, pathIn->pts[j0].y); // join angle < 180 if (crossprod < 0) { pathOut->lineTo(pathIn->pts[j0].x - wdyNext, pathIn->pts[j0].y + wdxNext); // miter join inside limit if (lineJoin == splashLineJoinMiter && splashSqrt(miter) <= state->miterLimit) { pathOut->lineTo(pathIn->pts[j0].x - wdy + wdx * m, pathIn->pts[j0].y + wdx + wdy * m); pathOut->lineTo(pathIn->pts[j0].x - wdy, pathIn->pts[j0].y + wdx); // bevel join or miter join outside limit } else { pathOut->lineTo(pathIn->pts[j0].x - wdy, pathIn->pts[j0].y + wdx); } // join angle >= 180 } else { pathOut->lineTo(pathIn->pts[j0].x + wdy, pathIn->pts[j0].y - wdx); // miter join inside limit if (lineJoin == splashLineJoinMiter && splashSqrt(miter) <= state->miterLimit) { pathOut->lineTo(pathIn->pts[j0].x + wdy + wdx * m, pathIn->pts[j0].y - wdx + wdy * m); pathOut->lineTo(pathIn->pts[j0].x + wdyNext, pathIn->pts[j0].y - wdxNext); // bevel join or miter join outside limit } else { pathOut->lineTo(pathIn->pts[j0].x + wdyNext, pathIn->pts[j0].y - wdxNext); } } } pathOut->close(); } // add stroke adjustment hints if (state->strokeAdjust != splashStrokeAdjustOff) { // subpath with one segment if (seg == 0 && last) { switch (lineCap) { case splashLineCapButt: pathOut->addStrokeAdjustHint(firstPt, left2 + 1, firstPt, pathOut->length - 1); break; case splashLineCapProjecting: pathOut->addStrokeAdjustHint(firstPt, left2 + 1, firstPt, pathOut->length - 1, gTrue); break; case splashLineCapRound: break; } pathOut->addStrokeAdjustHint(left2, right2, firstPt, pathOut->length - 1); } else { // start of subpath if (seg == 1) { // start cap if (!closed) { switch (lineCap) { case splashLineCapButt: pathOut->addStrokeAdjustHint(firstPt, left1 + 1, firstPt, firstPt + 1); pathOut->addStrokeAdjustHint(firstPt, left1 + 1, right1 + 1, right1 + 1); break; case splashLineCapProjecting: pathOut->addStrokeAdjustHint(firstPt, left1 + 1, firstPt, firstPt + 1, gTrue); pathOut->addStrokeAdjustHint(firstPt, left1 + 1, right1 + 1, right1 + 1, gTrue); break; case splashLineCapRound: break; } } // first segment pathOut->addStrokeAdjustHint(left1, right1, firstPt, left2); pathOut->addStrokeAdjustHint(left1, right1, right2 + 1, right2 + 1); } // middle of subpath if (seg > 1) { pathOut->addStrokeAdjustHint(left1, right1, left0 + 1, right0); pathOut->addStrokeAdjustHint(left1, right1, join0, left2); pathOut->addStrokeAdjustHint(left1, right1, right2 + 1, right2 + 1); } // end of subpath if (last) { if (closed) { // first segment pathOut->addStrokeAdjustHint(leftFirst, rightFirst, left2 + 1, right2); pathOut->addStrokeAdjustHint(leftFirst, rightFirst, join2, pathOut->length - 1); // last segment pathOut->addStrokeAdjustHint(left2, right2, left1 + 1, right1); pathOut->addStrokeAdjustHint(left2, right2, join1, pathOut->length - 1); pathOut->addStrokeAdjustHint(left2, right2, leftFirst - 1, leftFirst); pathOut->addStrokeAdjustHint(left2, right2, rightFirst + 1, rightFirst + 1); } else { // last segment pathOut->addStrokeAdjustHint(left2, right2, left1 + 1, right1); pathOut->addStrokeAdjustHint(left2, right2, join1, pathOut->length - 1); // end cap switch (lineCap) { case splashLineCapButt: pathOut->addStrokeAdjustHint(left2 - 1, left2 + 1, left2 + 1, left2 + 2); break; case splashLineCapProjecting: pathOut->addStrokeAdjustHint(left2 - 1, left2 + 1, left2 + 1, left2 + 2, gTrue); break; case splashLineCapRound: break; } } } } left0 = left1; left1 = left2; right0 = right1; right1 = right2; join0 = join1; join1 = join2; if (seg == 0) { leftFirst = left2; rightFirst = right2; } } i0 = j0; i1 = j1; ++seg; } if (pathIn != path) { delete pathIn; } return pathOut; } SplashClipResult Splash::limitRectToClipRect(int *xMin, int *yMin, int *xMax, int *yMax) { int t; if ((t = state->clip->getXMinI(state->strokeAdjust)) > *xMin) { *xMin = t; } if ((t = state->clip->getXMaxI(state->strokeAdjust) + 1) < *xMax) { *xMax = t; } if ((t = state->clip->getYMinI(state->strokeAdjust)) > *yMin) { *yMin = t; } if ((t = state->clip->getYMaxI(state->strokeAdjust) + 1) < *yMax) { *yMax = t; } if (*xMin >= *xMax || *yMin >= *yMax) { return splashClipAllOutside; } return state->clip->testRect(*xMin, *yMin, *xMax - 1, *yMax - 1, state->strokeAdjust); } void Splash::dumpPath(SplashPath *path) { int i; for (i = 0; i < path->length; ++i) { printf(" %3d: x=%8.2f y=%8.2f%s%s%s%s\n", i, (double)path->pts[i].x, (double)path->pts[i].y, (path->flags[i] & splashPathFirst) ? " first" : "", (path->flags[i] & splashPathLast) ? " last" : "", (path->flags[i] & splashPathClosed) ? " closed" : "", (path->flags[i] & splashPathCurve) ? " curve" : ""); } if (path->hintsLength == 0) { printf(" no hints\n"); } else { for (i = 0; i < path->hintsLength; ++i) { printf(" hint %3d: ctrl0=%d ctrl1=%d pts=%d..%d\n", i, path->hints[i].ctrl0, path->hints[i].ctrl1, path->hints[i].firstPt, path->hints[i].lastPt); } } } void Splash::dumpXPath(SplashXPath *path) { int i; for (i = 0; i < path->length; ++i) { printf(" %4d: x0=%8.2f y0=%8.2f x1=%8.2f y1=%8.2f count=%d\n", i, (double)path->segs[i].x0, (double)path->segs[i].y0, (double)path->segs[i].x1, (double)path->segs[i].y1, path->segs[i].count); } }
; A024655: n written in fractional base 9/7. ; Submitted by Jon Maiga ; 0,1,2,3,4,5,6,7,8,70,71,72,73,74,75,76,77,78,750,751,752,753,754,755,756,757,758,7530,7531,7532,7533,7534,7535,7536,7537,7538,75310,75311,75312,75313,75314,75315,75316,75317,75318,75380,75381,75382,75383,75384 mov $3,1 lpb $0 mov $2,$0 div $0,9 mul $0,7 mod $2,9 mul $2,$3 add $1,$2 mul $3,10 lpe mov $0,$1
; $Id: floorf.asm $ ;; @file ; IPRT - No-CRT floorf - AMD64 & X86. ; ; ; Copyright (C) 2006-2017 Oracle Corporation ; ; This file is part of VirtualBox Open Source Edition (OSE), as ; available from http://www.virtualbox.org. This file is free software; ; you can redistribute it and/or modify it under the terms of the GNU ; General Public License (GPL) as published by the Free Software ; Foundation, in version 2 as it comes in the "COPYING" file of the ; VirtualBox OSE distribution. VirtualBox OSE is distributed in the ; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. ; ; The contents of this file may alternatively be used under the terms ; of the Common Development and Distribution License Version 1.0 ; (CDDL) only, as it comes in the "COPYING.CDDL" file of the ; VirtualBox OSE distribution, in which case the provisions of the ; CDDL are applicable instead of those of the GPL. ; ; You may elect to license modified versions of this file under the ; terms and conditions of either the GPL or the CDDL or both. ; %include "iprt/asmdefs.mac" BEGINCODE ;; ; Compute the largest integral value not greater than rf. ; @returns st(0) ; @param rf 32-bit: [ebp + 8] 64-bit: xmm0 BEGINPROC RT_NOCRT(floorf) push xBP mov xBP, xSP sub xSP, 10h %ifdef RT_ARCH_AMD64 movss [xSP], xmm0 fld dword [xSP] %else fld dword [xBP + xCB*2] %endif ; Make it round down by modifying the fpu control word. fstcw [xBP - 10h] mov eax, [xBP - 10h] or eax, 00400h and eax, 0f7ffh mov [xBP - 08h], eax fldcw [xBP - 08h] ; Round ST(0) to integer. frndint ; Restore the fpu control word. fldcw [xBP - 10h] %ifdef RT_ARCH_AMD64 fstp dword [xSP] movss xmm0, [xSP] %endif leave ret ENDPROC RT_NOCRT(floorf)
; A014692: a(n) = prime(n) - (n-1). ; 2,2,3,4,7,8,11,12,15,20,21,26,29,30,33,38,43,44,49,52,53,58,61,66,73,76,77,80,81,84,97,100,105,106,115,116,121,126,129,134,139,140,149,150,153,154,165,176,179,180,183,188,189,198,203,208,213,214,219,222,223,232,245,248,249,252,265,270,279,280,283,288,295,300,305,308,313,320,323,330,339,340,349,350,355,358,363,370,373,374,377,388,395,398,405,408,413,424,425,442 mov $2,$0 seq $0,6005 ; The odd prime numbers together with 1. sub $0,$2 trn $0,2 add $0,2
; ; ZX Spectrum ZXMMC specific routines ; code by Alessandro Poppi ; ported to z88dk by Stefano Bodrato - Feb 2010 ; ; int mmc_command(struct MMC mmc_descriptor, unsigned char command, long parameter) ; ; $Id: mmc_command.asm,v 1.3 2016/06/10 21:28:03 dom Exp $ ; ;----------------------------------------------------------------------------------------- ; SEND COMMAND TO MMC ;----------------------------------------------------------------------------------------- ; SECTION code_clib PUBLIC mmc_command PUBLIC _mmc_command EXTERN mmc_send_command EXTERN __mmc_card_select INCLUDE "zxmmc.def" mmc_command: _mmc_command: ld ix,2 add ix,sp ld l,(ix+6) ld h,(ix+7) inc hl ; ptr to MMC mask to be used to select port ld a,(hl) ld (__mmc_card_select), a ; arg1 = addr_H.BYTE1 (H) ; arg2 = addr_H.BYTE0 (L) ; arg3 = addr_L.BYTE1 (D) ; arg4 = addr_L.BYTE0 (E) ld e,(ix+0) ; LSB ld d,(ix+1) ; . ld l,(ix+2) ; . ld h,(ix+3) ; MSB ld a,(ix+4) jp mmc_send_command
; A035487: Second column of Stolarsky array. ; 2,6,11,15,19,23,28,32,36,40,44,49,53,57,61,66,70,74,78,83,87,91,95,100,104,108,112,116,121,125,129,133,138,142,146,150,155,159,163,167,172,176,180,184,189,193,197,201 mov $4,$0 add $0,10 mov $1,19 mul $1,$0 mov $5,4 lpb $0 mov $0,6 mov $2,$1 div $2,$5 add $5,$2 sub $5,20 div $5,20 lpe mov $1,$5 add $1,1 mov $3,$4 mul $3,4 add $1,$3 mov $0,$1
.global s_prepare_buffers s_prepare_buffers: push %r8 push %rax push %rcx push %rdi push %rsi lea addresses_UC_ht+0x1a092, %rsi lea addresses_WT_ht+0x1a6fa, %rdi clflush (%rdi) nop nop and $1664, %rax mov $86, %rcx rep movsl nop nop nop nop nop and $79, %r8 pop %rsi pop %rdi pop %rcx pop %rax pop %r8 ret .global s_faulty_load s_faulty_load: push %r10 push %r13 push %r14 push %r8 push %rax push %rdi // Faulty Load mov $0x404fd10000000cfa, %r13 nop nop nop xor $48465, %rdi mov (%r13), %r14d lea oracles, %r10 and $0xff, %r14 shlq $12, %r14 mov (%r10,%r14,1), %r14 pop %rdi pop %rax pop %r8 pop %r14 pop %r13 pop %r10 ret /* <gen_faulty_load> [REF] {'src': {'type': 'addresses_NC', 'AVXalign': False, 'size': 8, 'NT': False, 'same': False, 'congruent': 0}, 'OP': 'LOAD'} [Faulty Load] {'src': {'type': 'addresses_NC', 'AVXalign': False, 'size': 4, 'NT': False, 'same': True, 'congruent': 0}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'type': 'addresses_UC_ht', 'congruent': 2, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_WT_ht', 'congruent': 7, 'same': False}} {'00': 21829} 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 */
// Copyright 2012-2021 Jan Niklas Hasse <jhasse@bixense.com> // For conditions of distribution and use, see copyright notice in LICENSE.txt /// Functions related to the global ModelView matrix /// @file #pragma once #include "Mat3.hpp" namespace jngl { /// Returns a copy of the global ModelView matrix jngl::Mat3 modelview(); /// Multiplies the global ModelView matrix with a rotation matrix void rotate(double degree); /// Multiplies the global ModelView matrix with a translation matrix void translate(double x, double y); /// Multiplies the global ModelView matrix with a translation matrix /// /// Equivalent to calling `jngl::translate(v.x, v.y);`. template <class Vect> void translate(Vect v) { translate(v.x, v.y); } /// Multiplies the global ModelView matrix by a scaling matrix /// /// Equivalent to calling `jngl::scale(factor, factor)`. void scale(double factor); /// Multiplies the global ModelView matrix by a scaling matrix void scale(double xfactor, double yfactor); /// Pushes the current ModelView matrix on a global stack void pushMatrix(); /// Replaces the current ModelView matrix with the top element of the global stack void popMatrix(); /// Resets the global ModelView matrix to the identity matrix void reset(); } // namespace jngl
#ifndef CPP_HPP_95E41B70_5DB2_4E5B_A468_95343C6438AD #define CPP_HPP_95E41B70_5DB2_4E5B_A468_95343C6438AD #pragma once /* cpp.hpp Some workarounds & emulations for C++ features, missed in currently used compilers & libraries. Here be dragons */ /* Copyright © 2013 Far Group All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the authors may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 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. */ // Internal: #include "common/compiler.hpp" // Platform: // Common: // External: //---------------------------------------------------------------------------- #if COMPILER == C_GCC // These inline implementations in gcc/cwchar are wrong and non-compilable if _CONST_RETURN is defined. namespace std { inline wchar_t* wcschr(wchar_t* p, wchar_t c) { return const_cast<wchar_t*>(wcschr(const_cast<const wchar_t*>(p), c)); } inline wchar_t* wcspbrk(wchar_t* s1, const wchar_t* s2) { return const_cast<wchar_t*>(wcspbrk(const_cast<const wchar_t*>(s1), s2)); } inline wchar_t* wcsrchr(wchar_t* p, wchar_t c) { return const_cast<wchar_t*>(wcsrchr(const_cast<const wchar_t*>(p), c)); } inline wchar_t* wcsstr(wchar_t* s1, const wchar_t* s2) { return const_cast<wchar_t*>(wcsstr(const_cast<const wchar_t*>(s1), s2)); } inline wchar_t* wmemchr(wchar_t* p, wchar_t c, size_t n) { return const_cast<wchar_t*>(wmemchr(const_cast<const wchar_t*>(p), c, n)); } } using std::wcschr; using std::wcspbrk; using std::wcsrchr; using std::wcsstr; using std::wmemchr; #endif #if COMPILER == C_GCC && !defined(_GLIBCXX_HAS_GTHREADS) namespace std::this_thread { inline void yield() noexcept { Sleep(0); } } #endif #if COMPILER == C_GCC #if _GCC_VER < GCC_VER_(7,2,0) // https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=fd847994d5093b888c5cc1ead8625c6c1c03501b namespace std { template<typename forward_iterator_type, typename searcher_type> forward_iterator_type search(forward_iterator_type First, forward_iterator_type Last, const searcher_type& Searcher) { return Searcher(First, Last).first; } } #endif #endif #endif // CPP_HPP_95E41B70_5DB2_4E5B_A468_95343C6438AD
dc.w word_21AC6-Map_CNZSOZBreakableWall dc.w word_21AE0-Map_CNZSOZBreakableWall dc.w word_21B12-Map_CNZSOZBreakableWall dc.w word_21B2C-Map_CNZSOZBreakableWall dc.w word_21B5E-Map_CNZSOZBreakableWall dc.w word_21B84-Map_CNZSOZBreakableWall word_21AC6: dc.w 4 ; DATA XREF: ROM:00021ABAo dc.b $E0, $D, 0, 0, $FF, $F0 dc.b $F0, $D, 0, 0, $FF, $F0 dc.b 0, $D, 0, 0, $FF, $F0 dc.b $10, $D, 0, 0, $FF, $F0 word_21AE0: dc.w 8 ; DATA XREF: ROM:00021ABAo dc.b $E0, 5, 0, 0, $FF, $F0 dc.b $E0, 5, 0, 4, 0, 0 dc.b $F0, 5, 0, 0, $FF, $F0 dc.b $F0, 5, 0, 4, 0, 0 dc.b 0, 5, 0, 0, $FF, $F0 dc.b 0, 5, 0, 4, 0, 0 dc.b $10, 5, 0, 0, $FF, $F0 dc.b $10, 5, 0, 4, 0, 0 word_21B12: dc.w 4 ; DATA XREF: ROM:00021ABAo dc.b $E0, $D, 0, 8, $FF, $F0 dc.b $F0, $D, 0, 8, $FF, $F0 dc.b 0, $D, 0, 8, $FF, $F0 dc.b $10, $D, 0, 8, $FF, $F0 word_21B2C: dc.w 8 ; DATA XREF: ROM:00021ABAo dc.b $E0, 5, 0, 8, $FF, $F0 dc.b $E0, 5, 0, $C, 0, 0 dc.b $F0, 5, 0, 8, $FF, $F0 dc.b $F0, 5, 0, $C, 0, 0 dc.b 0, 5, 0, 8, $FF, $F0 dc.b 0, 5, 0, $C, 0, 0 dc.b $10, 5, 0, 8, $FF, $F0 dc.b $10, 5, 0, $C, 0, 0 word_21B5E: dc.w 6 ; DATA XREF: ROM:00021ABAo dc.b $D0, $D, 0, 0, $FF, $F0 dc.b $E0, $D, 0, 0, $FF, $F0 dc.b $F0, $D, 0, 0, $FF, $F0 dc.b 0, $D, 0, 0, $FF, $F0 dc.b $10, $D, 0, 0, $FF, $F0 dc.b $20, $D, 0, 0, $FF, $F0 word_21B84: dc.w $C ; DATA XREF: ROM:00021ABAo dc.b $D0, 5, 0, 0, $FF, $F0 dc.b $D0, 5, 0, 4, 0, 0 dc.b $E0, 5, 0, 0, $FF, $F0 dc.b $E0, 5, 0, 4, 0, 0 dc.b $F0, 5, 0, 0, $FF, $F0 dc.b $F0, 5, 0, 4, 0, 0 dc.b 0, 5, 0, 0, $FF, $F0 dc.b 0, 5, 0, 4, 0, 0 dc.b $10, 5, 0, 0, $FF, $F0 dc.b $10, 5, 0, 4, 0, 0 dc.b $20, 5, 0, 0, $FF, $F0 dc.b $20, 5, 0, 4, 0, 0
;; ;; Copyright (c) 2020-2021, Intel Corporation ;; ;; Redistribution and use in source and binary forms, with or without ;; modification, are permitted provided that the following conditions are met: ;; ;; * Redistributions of source code must retain the above copyright notice, ;; this list of conditions and the following disclaimer. ;; * Redistributions in binary form must reproduce the above copyright ;; notice, this list of conditions and the following disclaimer in the ;; documentation and/or other materials provided with the distribution. ;; * Neither the name of Intel Corporation nor the names of its contributors ;; may be used to endorse or promote products derived from this software ;; without specific prior written permission. ;; ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" ;; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE ;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ;; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ;; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ;; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;; %include "include/os.asm" %include "include/reg_sizes.asm" %include "include/crc32_const.inc" %include "include/clear_regs.asm" %include "include/cet.inc" [bits 64] default rel %ifdef LINUX %define arg1 rdi %define arg2 rsi %define arg3 rdx %define arg4 rcx %else %define arg1 rcx %define arg2 rdx %define arg3 r8 %define arg4 r9 %endif struc STACK_FRAME _xmm_save: resq 8 * 2 _rsp_save: resq 1 endstruc section .text ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; arg1 - buffer pointer ;; arg2 - buffer size in bytes ;; Returns CRC value through RAX align 32 MKGLOBAL(crc24_lte_a_avx, function,) crc24_lte_a_avx: endbranch64 %ifdef SAFE_PARAM or arg1, arg1 jz .wrong_param %endif %ifndef LINUX mov rax, rsp sub rsp, STACK_FRAME_size and rsp, -16 mov [rsp + _rsp_save], rax vmovdqa [rsp + _xmm_save + 16*0], xmm6 vmovdqa [rsp + _xmm_save + 16*1], xmm7 vmovdqa [rsp + _xmm_save + 16*2], xmm8 vmovdqa [rsp + _xmm_save + 16*3], xmm9 vmovdqa [rsp + _xmm_save + 16*4], xmm10 vmovdqa [rsp + _xmm_save + 16*5], xmm11 vmovdqa [rsp + _xmm_save + 16*6], xmm12 vmovdqa [rsp + _xmm_save + 16*7], xmm13 %endif lea arg4, [rel crc32_lte24_a_const] mov arg3, arg2 mov arg2, arg1 xor DWORD(arg1), DWORD(arg1) call crc32_by8_avx shr eax, 8 ; adjust for 24-bit poly %ifdef SAFE_DATA clear_scratch_xmms_avx_asm %endif %ifndef LINUX vmovdqa xmm6, [rsp + _xmm_save + 16*0] vmovdqa xmm7, [rsp + _xmm_save + 16*1] vmovdqa xmm8, [rsp + _xmm_save + 16*2] vmovdqa xmm9, [rsp + _xmm_save + 16*3] vmovdqa xmm10, [rsp + _xmm_save + 16*4] vmovdqa xmm11, [rsp + _xmm_save + 16*5] vmovdqa xmm12, [rsp + _xmm_save + 16*6] vmovdqa xmm13, [rsp + _xmm_save + 16*7] mov rsp, [rsp + _rsp_save] %endif .wrong_param: ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; arg1 - buffer pointer ;; arg2 - buffer size in bytes ;; Returns CRC value through RAX align 32 MKGLOBAL(crc24_lte_b_avx, function,) crc24_lte_b_avx: endbranch64 %ifdef SAFE_PARAM or arg1, arg1 jz .wrong_param %endif %ifndef LINUX mov rax, rsp sub rsp, STACK_FRAME_size and rsp, -16 mov [rsp + _rsp_save], rax vmovdqa [rsp + _xmm_save + 16*0], xmm6 vmovdqa [rsp + _xmm_save + 16*1], xmm7 vmovdqa [rsp + _xmm_save + 16*2], xmm8 vmovdqa [rsp + _xmm_save + 16*3], xmm9 vmovdqa [rsp + _xmm_save + 16*4], xmm10 vmovdqa [rsp + _xmm_save + 16*5], xmm11 vmovdqa [rsp + _xmm_save + 16*6], xmm12 vmovdqa [rsp + _xmm_save + 16*7], xmm13 %endif lea arg4, [rel crc32_lte24_b_const] mov arg3, arg2 mov arg2, arg1 xor DWORD(arg1), DWORD(arg1) call crc32_by8_avx shr eax, 8 ; adjust for 24-bit poly %ifdef SAFE_DATA clear_scratch_xmms_avx_asm %endif %ifndef LINUX vmovdqa xmm6, [rsp + _xmm_save + 16*0] vmovdqa xmm7, [rsp + _xmm_save + 16*1] vmovdqa xmm8, [rsp + _xmm_save + 16*2] vmovdqa xmm9, [rsp + _xmm_save + 16*3] vmovdqa xmm10, [rsp + _xmm_save + 16*4] vmovdqa xmm11, [rsp + _xmm_save + 16*5] vmovdqa xmm12, [rsp + _xmm_save + 16*6] vmovdqa xmm13, [rsp + _xmm_save + 16*7] mov rsp, [rsp + _rsp_save] %endif .wrong_param: ret %ifdef LINUX section .note.GNU-stack noalloc noexec nowrite progbits %endif
; char *strupr(char *s) SECTION code_string PUBLIC strupr EXTERN asm_strupr defc strupr = asm_strupr
; error display routine ; blinks the (error #)+1 in all three leds pezro ldx #0 ; error #1 for zero page .byte skip2 ; skip next two bytes perr ldx temp ; get error # txs ; use stack as storage reg. pe20 tsx ; restore error # pe30 lda #led0+led1 ora ledprt jmp pea7a ; turn on led !!!!patch so ddrb led is output!!!! rea7d tya ; clear inner ctr !!!!patch return!!!! pd10 clc pd20 adc #1 ; count inner ctr bne pd20 dey ; done ? bne pd10 ; no lda ledprt and #$ff-led0-led1 sta ledprt ; turn off all leds pe40 ; wait tya ; clear inner ctr pd11 clc pd21 adc #1 ; count inner ctr bne pd21 dey ; done ? bne pd11 ; no dex ; blinked # ? bpl pe30 ; no - blink again cpx #$fc ; waited between counts ? bne pe40 ; no beq pe20 ; always - all again dskint sei cld ldx #$66 ; *,atnout,clk,*,*,side,fsdir,trk0 jmp patch5 ; *** rom ds 8/18/83 *** dkit10 inx ; fill ;********************************* ; ; power up diagnostic ; ;********************************* ldy #0 ldx #0 pu10 txa ; fill z-page accend pattern sta $0,x inx bne pu10 pu20 txa ; check pattern by inc... cmp $0,x ; ...back to orig # bne pezro ; bad bits pu30 inc $0,x ; bump contents iny bne pu30 ; not done cmp $0,x ; check for good count bne pezro ; something's wrong sty $0,x ; leave z-page zeroed lda $0,x ; check it bne pezro ; wrong inx ; next! bne pu20 ; not all done ; test 32k byte rom ; enter x=start page ; exit if ok rm10 inc temp ; next error # ldx #127 ; 128 pages stx ip+1 ; save page, start x=0 inx ; **** rom ds 04/22/86 *** lda #0 sta ip ; zero lo indirect ldy #2 ; skip signature bytes clc rt10 inc ip+1 ; do it backwards rt20 adc (ip),y ; total checksum in a iny bne rt20 dex bne rt10 adc #255 ; add in last carry sta ip+1 bne perr2 ; no - show error number ; **** rom ds 04/22/86 *** nop ; fill nop ; fill nop ; fill ;---------------------------------- ; test all common ram cr20 lda #$01 ; start of 1st block cr30 sta ip+1 ; save page # inc temp ; bump error # ; enter x=# of pages in block ; ip ptr to first page in block ; exit if ok ramtst ldx #7 ; save page count ra10 tya ; fill with adr sensitive pattern clc adc ip+1 sta (ip),y iny bne ra10 inc ip+1 dex bne ra10 ldx #7 ; restore page count ra30 dec ip+1 ; check pattern backwards ra40 dey tya ; gen pattern again clc adc ip+1 cmp (ip),y ; ok ? bne perr2 ; no - show error # eor #$ff ; yes - test inverse pattern sta (ip),y eor (ip),y ; ok ? sta (ip),y ; leave memory zero bne perr2 ; no - show error # tya bne ra40 dex bne ra30 beq diagok perr2 jmp perr diagok ;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> jmp ptch31 ; *** rom ds 05/01/85 *** ; ldx #topwrt ; txs ;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> rtch31 lda ledprt ; clear leds and #$ff-led0-led1 sta ledprt lda #3 ; neg edge of atn & edge on wp sta pcr1 lda #%10000010 ; set,_t1,_t2,_cb1,_cb2,_sr,ca1,_ca2(wps) sta ifr1 sta ier1 lda pb ; compute primary addr and #%01100000 ; pb5 and pb6 are unused lines asl a ; shift to lower rol a rol a rol a ora #$48 ; talk address sta tlkadr eor #$60 ; listen address sta lsnadr ; initialize buffer pntr table inttab ldx #0 ldy #0 intt1 lda #0 sta buftab,x inx lda bufind,y sta buftab,x inx iny cpy #bfcnt bne intt1 lda #<cmdbuf ; set pntr to cmdbuf sta buftab,x inx lda #>cmdbuf sta buftab,x inx lda #<errbuf ; set pntr to errbuf sta buftab,x inx lda #>errbuf sta buftab,x lda #$ff ldx #maxsa dskin1 sta lintab,x dex bpl dskin1 ldx #mxchns-1 dskin2 sta buf0,x ; set buffers as unused sta buf1,x sta ss,x dex bpl dskin2 lda #bfcnt ; set buffer pointers sta buf0+cmdchn lda #bfcnt+1 sta buf0+errchn lda #$ff sta buf0+blindx sta buf1+blindx lda #errchn sta lintab+errsa lda #cmdchn+$80 sta lintab+cmdsa lda #lxint ; lindx 0 to 5 free sta linuse lda #rdylst sta chnrdy+cmdchn lda #rdytlk sta chnrdy+errchn lda #$e0 sta bufuse lda #$ff sta bufuse+1 ;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> jsr ptch72 ; *** rom ds 05/20/86 *** nop ; lda #1 ; sta wpsw ;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> sta wpsw+1 jsr usrint ; init user jmp jsr lruint ;********************************** ; ; controller initialization ; ;********************************** jsr ptch10 ; *** rom ds 05/01/85 controller init *** ; jsr cntint ; set indirect vectors lda #<diagok sta vnmi lda #>diagok sta vnmi+1 lda #6 ; set up sector offset *** rom ds 01/22/85 *** sta secinc lda #5 sta revcnt ; set up recovery count ;* ;******************************* ;* ;* seterr ;* set up power on error msg ;* ;******************************* ;* ;* seterr lda #$73 jsr errts0 ;must be contiguous to .file idle ;******************************** ; init the serial bus ; ;******************************** ;-------rom -05 8/18/83----------------- lda #$00 ; data hi, clock hi,atna hi sta pb lda #%00011010 ; atna,clkout,datout sta ddrb1 ;--------------------------------------- jsr ptch29 ; *rom ds 02/01/85* ; jsr boot
#ifndef SRC_CONTEXT_FILTER_CONTEXT_H_ #define SRC_CONTEXT_FILTER_CONTEXT_H_ #include <memory> #include <unordered_map> #include <unordered_set> #include "core/crystal.hpp" #include "core/filter.hpp" #include "core/optics.hpp" #include "io/serialize.hpp" namespace icehalo { class RayPathFilterContext; using RayPathFilterContextPtrU = std::unique_ptr<RayPathFilterContext>; class RayPathFilterContext : public IJsonizable { public: ShortIdType GetId() const; AbstractRayPathFilter* GetFilter() const; void SaveToJson(rapidjson::Value& root, rapidjson::Value::AllocatorType& allocator) override; void LoadFromJson(const rapidjson::Value& root) override; static RayPathFilterContextPtrU CreateDefault(); private: RayPathFilterContext(); ShortIdType id_; RayPathFilterPtrU filter_; }; } // namespace icehalo #endif // SRC_CONTEXT_FILTER_CONTEXT_H_
; =============================================================== ; Jun 2007 ; =============================================================== ; ; uint zx_aaddr2py(void *attraddr) ; ; Attribute address to pixel y coordinate. ; ; =============================================================== SECTION code_arch PUBLIC asm_zx_aaddr2py asm_zx_aaddr2py: ; enter : hl = valid attribute address ; ; exit : hl = pixel y coordinate of topmost pixel in attr square ; ; uses : af, hl ld a,l and $e0 srl h rra srl h rra ld l,a ld h,0 ret
// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "content/child/npapi/np_channel_base.h" #include "base/auto_reset.h" #include "base/containers/hash_tables.h" #include "base/lazy_instance.h" #include "base/strings/string_number_conversions.h" #include "base/threading/thread_local.h" #include "ipc/ipc_sync_message.h" #if defined(OS_POSIX) #include "ipc/ipc_channel_posix.h" #endif namespace content { namespace { typedef base::hash_map<std::string, scoped_refptr<NPChannelBase> > ChannelMap; struct ChannelGlobals { ChannelMap channel_map; scoped_refptr<NPChannelBase> current_channel; }; #if defined(OS_ANDROID) // Workaround for http://crbug.com/298179 - NPChannelBase is only intended // for use on one thread per process. Using TLS to store the globals removes the // worst thread hostility in this class, especially needed for webview which // runs in single-process mode. TODO(joth): Make a complete fix, most likely // as part of addressing http://crbug.com/258510. base::LazyInstance<base::ThreadLocalPointer<ChannelGlobals> >::Leaky g_channels_tls_ptr = LAZY_INSTANCE_INITIALIZER; ChannelGlobals* GetChannelGlobals() { ChannelGlobals* globals = g_channels_tls_ptr.Get().Get(); if (!globals) { globals = new ChannelGlobals; g_channels_tls_ptr.Get().Set(globals); } return globals; } #else base::LazyInstance<ChannelGlobals>::Leaky g_channels_globals = LAZY_INSTANCE_INITIALIZER; ChannelGlobals* GetChannelGlobals() { return g_channels_globals.Pointer(); } #endif // OS_ANDROID ChannelMap* GetChannelMap() { return &GetChannelGlobals()->channel_map; } } // namespace NPChannelBase* NPChannelBase::GetChannel( const IPC::ChannelHandle& channel_handle, IPC::Channel::Mode mode, ChannelFactory factory, base::MessageLoopProxy* ipc_message_loop, bool create_pipe_now, base::WaitableEvent* shutdown_event) { scoped_refptr<NPChannelBase> channel; std::string channel_key = channel_handle.name; ChannelMap::const_iterator iter = GetChannelMap()->find(channel_key); if (iter == GetChannelMap()->end()) { channel = factory(); } else { channel = iter->second; } DCHECK(channel.get() != NULL); if (!channel->channel_valid()) { channel->channel_handle_ = channel_handle; if (mode & IPC::Channel::MODE_SERVER_FLAG) { channel->channel_handle_.name = IPC::Channel::GenerateVerifiedChannelID(channel_key); } channel->mode_ = mode; if (channel->Init(ipc_message_loop, create_pipe_now, shutdown_event)) { (*GetChannelMap())[channel_key] = channel; } else { channel = NULL; } } return channel.get(); } void NPChannelBase::Broadcast(IPC::Message* message) { for (ChannelMap::iterator iter = GetChannelMap()->begin(); iter != GetChannelMap()->end(); ++iter) { iter->second->Send(new IPC::Message(*message)); } delete message; } NPChannelBase::NPChannelBase() : mode_(IPC::Channel::MODE_NONE), non_npobject_count_(0), peer_pid_(0), in_remove_route_(false), default_owner_(NULL), channel_valid_(false), in_unblock_dispatch_(0), send_unblocking_only_during_unblock_dispatch_(false) { } NPChannelBase::~NPChannelBase() { // TODO(wez): Establish why these would ever be non-empty at teardown. //DCHECK(npobject_listeners_.empty()); //DCHECK(proxy_map_.empty()); //DCHECK(stub_map_.empty()); DCHECK(owner_to_route_.empty()); DCHECK(route_to_owner_.empty()); } NPChannelBase* NPChannelBase::GetCurrentChannel() { return GetChannelGlobals()->current_channel.get(); } void NPChannelBase::CleanupChannels() { // Make a copy of the references as we can't iterate the map since items will // be removed from it as we clean them up. std::vector<scoped_refptr<NPChannelBase> > channels; for (ChannelMap::const_iterator iter = GetChannelMap()->begin(); iter != GetChannelMap()->end(); ++iter) { channels.push_back(iter->second); } for (size_t i = 0; i < channels.size(); ++i) channels[i]->CleanUp(); // This will clean up channels added to the map for which subsequent // AddRoute wasn't called GetChannelMap()->clear(); } NPObjectBase* NPChannelBase::GetNPObjectListenerForRoute(int route_id) { ListenerMap::iterator iter = npobject_listeners_.find(route_id); if (iter == npobject_listeners_.end()) { DLOG(WARNING) << "Invalid route id passed in:" << route_id; return NULL; } return iter->second; } base::WaitableEvent* NPChannelBase::GetModalDialogEvent(int render_view_id) { return NULL; } bool NPChannelBase::Init(base::MessageLoopProxy* ipc_message_loop, bool create_pipe_now, base::WaitableEvent* shutdown_event) { #if defined(OS_POSIX) // Attempting to initialize with an invalid channel handle. // See http://crbug.com/97285 for details. if (mode_ == IPC::Channel::MODE_CLIENT && -1 == channel_handle_.socket.fd) return false; #endif channel_.reset(new IPC::SyncChannel( channel_handle_, mode_, this, ipc_message_loop, create_pipe_now, shutdown_event)); #if defined(OS_POSIX) // Check the validity of fd for bug investigation. Remove after fixed. // See crbug.com/97285 for details. if (mode_ == IPC::Channel::MODE_SERVER) CHECK_NE(-1, channel_->GetClientFileDescriptor()); #endif channel_valid_ = true; return true; } bool NPChannelBase::Send(IPC::Message* message) { if (!channel_) { VLOG(1) << "Channel is NULL; dropping message"; delete message; return false; } if (send_unblocking_only_during_unblock_dispatch_ && in_unblock_dispatch_ == 0 && message->is_sync()) { message->set_unblock(false); } return channel_->Send(message); } int NPChannelBase::Count() { return static_cast<int>(GetChannelMap()->size()); } bool NPChannelBase::OnMessageReceived(const IPC::Message& message) { // Push this channel as the current channel being processed. This also forms // a stack of scoped_refptr avoiding ourselves (or any instance higher // up the callstack) from being deleted while processing a message. base::AutoReset<scoped_refptr<NPChannelBase> > keep_alive( &GetChannelGlobals()->current_channel, this); bool handled; if (message.should_unblock()) in_unblock_dispatch_++; if (message.routing_id() == MSG_ROUTING_CONTROL) { handled = OnControlMessageReceived(message); } else { handled = router_.RouteMessage(message); if (!handled && message.is_sync()) { // The listener has gone away, so we must respond or else the caller will // hang waiting for a reply. IPC::Message* reply = IPC::SyncMessage::GenerateReply(&message); reply->set_reply_error(); Send(reply); } } if (message.should_unblock()) in_unblock_dispatch_--; return handled; } void NPChannelBase::OnChannelConnected(int32 peer_pid) { peer_pid_ = peer_pid; } void NPChannelBase::AddRoute(int route_id, IPC::Listener* listener, NPObjectBase* npobject) { if (npobject) { npobject_listeners_[route_id] = npobject; } else { non_npobject_count_++; } router_.AddRoute(route_id, listener); } void NPChannelBase::RemoveRoute(int route_id) { router_.RemoveRoute(route_id); ListenerMap::iterator iter = npobject_listeners_.find(route_id); if (iter != npobject_listeners_.end()) { // This was an NPObject proxy or stub, it's not involved in the refcounting. // If this RemoveRoute call from the NPObject is a result of us calling // OnChannelError below, don't call erase() here because that'll corrupt // the iterator below. if (in_remove_route_) { iter->second = NULL; } else { npobject_listeners_.erase(iter); } return; } non_npobject_count_--; DCHECK(non_npobject_count_ >= 0); if (!non_npobject_count_) { base::AutoReset<bool> auto_reset_in_remove_route(&in_remove_route_, true); for (ListenerMap::iterator npobj_iter = npobject_listeners_.begin(); npobj_iter != npobject_listeners_.end(); ++npobj_iter) { if (npobj_iter->second) { npobj_iter->second->GetChannelListener()->OnChannelError(); } } for (ChannelMap::iterator iter = GetChannelMap()->begin(); iter != GetChannelMap()->end(); ++iter) { if (iter->second.get() == this) { GetChannelMap()->erase(iter); return; } } NOTREACHED(); } } bool NPChannelBase::OnControlMessageReceived(const IPC::Message& msg) { NOTREACHED() << "should override in subclass if you care about control messages"; return false; } void NPChannelBase::OnChannelError() { channel_valid_ = false; // TODO(shess): http://crbug.com/97285 // Once an error is seen on a channel, remap the channel to prevent // it from being vended again. Keep the channel in the map so // RemoveRoute() can clean things up correctly. for (ChannelMap::iterator iter = GetChannelMap()->begin(); iter != GetChannelMap()->end(); ++iter) { if (iter->second.get() == this) { // Insert new element before invalidating |iter|. (*GetChannelMap())[iter->first + "-error"] = iter->second; GetChannelMap()->erase(iter); break; } } } void NPChannelBase::AddMappingForNPObjectProxy(int route_id, NPObject* object) { proxy_map_[route_id] = object; } void NPChannelBase::RemoveMappingForNPObjectProxy(int route_id) { proxy_map_.erase(route_id); } void NPChannelBase::AddMappingForNPObjectStub(int route_id, NPObject* object) { DCHECK(object != NULL); stub_map_[object] = route_id; } void NPChannelBase::RemoveMappingForNPObjectStub(int route_id, NPObject* object) { DCHECK(object != NULL); stub_map_.erase(object); } void NPChannelBase::AddMappingForNPObjectOwner(int route_id, struct _NPP* owner) { DCHECK(owner != NULL); route_to_owner_[route_id] = owner; owner_to_route_[owner] = route_id; } void NPChannelBase::SetDefaultNPObjectOwner(struct _NPP* owner) { DCHECK(owner != NULL); default_owner_ = owner; } void NPChannelBase::RemoveMappingForNPObjectOwner(int route_id) { DCHECK(route_to_owner_.find(route_id) != route_to_owner_.end()); owner_to_route_.erase(route_to_owner_[route_id]); route_to_owner_.erase(route_id); } NPObject* NPChannelBase::GetExistingNPObjectProxy(int route_id) { ProxyMap::iterator iter = proxy_map_.find(route_id); return iter != proxy_map_.end() ? iter->second : NULL; } int NPChannelBase::GetExistingRouteForNPObjectStub(NPObject* npobject) { StubMap::iterator iter = stub_map_.find(npobject); return iter != stub_map_.end() ? iter->second : MSG_ROUTING_NONE; } NPP NPChannelBase::GetExistingNPObjectOwner(int route_id) { RouteToOwnerMap::iterator iter = route_to_owner_.find(route_id); return iter != route_to_owner_.end() ? iter->second : default_owner_; } int NPChannelBase::GetExistingRouteForNPObjectOwner(NPP owner) { OwnerToRouteMap::iterator iter = owner_to_route_.find(owner); return iter != owner_to_route_.end() ? iter->second : MSG_ROUTING_NONE; } } // namespace content
[sonic2013_v48] moduleMatches = 0xC5691A40 .origin = codecave ; app::WorldAreaMapInfo::Load _linkSonicLoad: lwz r12, 0(r31) lwz r0, 0xC(r12) lis r4, LinksonicPacLoad@ha mtctr r0 addi r4, r4, LinksonicPacLoad@l li r5, 0x4001 mr r3, r31 bctrl ; return to original code lwz r12, 0(r31) b 0x02B0FD04 ; app::WorldAreaMapInfo::Initialize _linkSonicInit: ; app::ObjUtil::GetPackFile lis r4, LinksonicPacInit@ha addi r3, r1, 0x14 addi r4, r4, LinksonicPacInit@l bl GetPackFile ; app::ObjUtil::GetModelResource lis r31, chrLinkSonic@ha addi r3, r1, 0x40 addi r5, r1, 0x14 addi r4, r31, chrLinkSonic@l bl GetModelResource lwz r0, 0x40(r1) addi r4, r1, 0x14 addi r3, r1, 0x20 stw r0, 0x10(r30) bl 0x036924C8 ; hh::ut::Packfile::Packfile ; app::ObjUtil::GetSkeletonResource mr r5, r3 addi r3, r1, 0x44 addi r4, r31, chrLinkSonic@l bl GetSkeletonResource ; return to original code lmw r23, 0x134(r1) b 0x02B10D74 0x02B0FD00 = b _linkSonicLoad 0x02B10D70 = b _linkSonicInit
;字母反向排列 jmp start string: db 'changlon' start: ;将db中的内容入栈 mov ax,0x7c0 mov ds,ax mov si,string mov ax,cs mov ss,ax mov sp,0 mov cx, ( start - string ) xor ax,ax e: mov al , [si] push ax inc si loop e mov si,string mov cx, (start - string ) o: pop ax mov byte [si], al inc si loop o jmp $ times 510 - ($ -$$ ) db 0 db 0x55,0xaa ;检测点 ; aa55 and ; fff0 ; aa50 ; data 0x50 , 0xaa ; fff0 or ; aa50 ; ax = fff0
; BSD ; void bcopy_callee(const void *src, void *dst, size_t len) SECTION code_string PUBLIC _bcopy_callee EXTERN asm_bcopy _bcopy_callee: pop af pop hl pop de pop bc push af jp asm_bcopy
// written by bastiaan konings schuiling 2008 - 2014 // this work is public domain. the code is undocumented, scruffy, untested, and should generally not be used for anything important. // i do not offer support, so don't ask. to be used for inspiration :) #ifndef _HPP_GUI2_VIEW_FRAME #define _HPP_GUI2_VIEW_FRAME #include "../view.hpp" #include "image.hpp" namespace blunted { class Gui2Frame : public Gui2View { public: Gui2Frame(Gui2WindowManager *windowManager, const std::string &name, float x_percent, float y_percent, float width_percent, float height_percent, bool background = false); virtual ~Gui2Frame(); protected: }; } #endif
; A290917: p-INVERT of the positive integers, where p(S) = (1 - S)^2. ; 2,7,22,67,200,588,1708,4913,14018,39725,111922,313752,875702,2434747,6746350,18636343,51340988,141089508,386857888,1058572325,2891193242,7882921697,21458980582,58330331952,158339542250,429274563823,1162435429318,3144299295403,8496313890608,22935929106300,61859482184212,166695256984217,448836498626162,1207592128929557,3246663348410650,8722790407011528,23420161884503198,62842664791426723,168524287112683678,451674590870415775,1209916213847031332,3239379841392289812,8668723954146205192,23186988161773815437,61992328309541343050,165670063961221029833,442557977378868092878,1181744142395251471968,3154355158661744646098,8416623185934689212375,22449739247321584906102,59859967248223144505107,159558055725747823691672,425170506922027172818092,1132594492790954258424700,3016179747709690447194113,8030004051364061053709858,21372443533201469780854013,56869100627671335519055618,151281569461286521400004600,402333967011179195321830022,1069748698225749979864409227,2843638868371576523527297102,7557319762351998013186256647,20080049244367967004181897100,53341862592339533041341932868,141670913571729972757640971888,376187968618500777102989695733,998718888731644193527757183738,2650929296424396916538160347825,7035124900637570060283930268342,18666652506928418663847371190672,49520398024371978625662199095482,131349030677420289896817532737727,348334595937362916421421303251750,923623973811857762753660782777723,2448637073600304256641573358227968,6490617274618147358190881825585628,17202105085039320986188527406420708,45584038957226272754127243723672425,120776144382033685569193378466692562,319954450998330891678700872452697317,847491246445933124349653006518179562 mov $3,$0 add $3,1 mov $5,$0 lpb $3 mov $0,$5 sub $3,1 sub $0,$3 mov $2,$0 mul $0,2 mov $4,$0 add $0,8 lpb $2 sub $4,$2 add $4,2 add $4,$0 add $0,$4 sub $2,1 lpe mov $4,$0 div $4,5 add $4,1 add $1,$4 lpe mov $0,$1
// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "base/strings/stringprintf.h" #include "base/win/scoped_handle.h" #include "base/win/windows_version.h" #include "sandbox/win/src/nt_internals.h" #include "sandbox/win/src/process_mitigations.h" #include "sandbox/win/src/sandbox.h" #include "sandbox/win/src/sandbox_factory.h" #include "sandbox/win/src/target_services.h" #include "sandbox/win/src/win_utils.h" #include "sandbox/win/tests/common/controller.h" #include "testing/gtest/include/gtest/gtest.h" namespace { typedef BOOL (WINAPI *GetProcessDEPPolicyFunction)( HANDLE process, LPDWORD flags, PBOOL permanent); typedef BOOL (WINAPI *GetProcessMitigationPolicyFunction)( HANDLE process, PROCESS_MITIGATION_POLICY mitigation_policy, PVOID buffer, SIZE_T length); GetProcessMitigationPolicyFunction get_process_mitigation_policy; #if !defined(_WIN64) bool CheckWin8DepPolicy() { PROCESS_MITIGATION_DEP_POLICY policy = {}; if (!get_process_mitigation_policy(::GetCurrentProcess(), ProcessDEPPolicy, &policy, sizeof(policy))) { return false; } return policy.Enable && policy.Permanent; } #endif // !defined(_WIN64) #if defined(NDEBUG) bool CheckWin8AslrPolicy() { PROCESS_MITIGATION_ASLR_POLICY policy = {}; if (!get_process_mitigation_policy(::GetCurrentProcess(), ProcessASLRPolicy, &policy, sizeof(policy))) { return false; } return policy.EnableForceRelocateImages && policy.DisallowStrippedImages; } #endif // defined(NDEBUG) bool CheckWin8StrictHandlePolicy() { PROCESS_MITIGATION_STRICT_HANDLE_CHECK_POLICY policy = {}; if (!get_process_mitigation_policy(::GetCurrentProcess(), ProcessStrictHandleCheckPolicy, &policy, sizeof(policy))) { return false; } return policy.RaiseExceptionOnInvalidHandleReference && policy.HandleExceptionsPermanentlyEnabled; } bool CheckWin8Win32CallPolicy() { PROCESS_MITIGATION_SYSTEM_CALL_DISABLE_POLICY policy = {}; if (!get_process_mitigation_policy(::GetCurrentProcess(), ProcessSystemCallDisablePolicy, &policy, sizeof(policy))) { return false; } return policy.DisallowWin32kSystemCalls; } bool CheckWin8DllExtensionPolicy() { PROCESS_MITIGATION_EXTENSION_POINT_DISABLE_POLICY policy = {}; if (!get_process_mitigation_policy(::GetCurrentProcess(), ProcessExtensionPointDisablePolicy, &policy, sizeof(policy))) { return false; } return policy.DisableExtensionPoints; } } // namespace namespace sandbox { SBOX_TESTS_COMMAND int CheckWin8(int argc, wchar_t **argv) { get_process_mitigation_policy = reinterpret_cast<GetProcessMitigationPolicyFunction>( ::GetProcAddress(::GetModuleHandleW(L"kernel32.dll"), "GetProcessMitigationPolicy")); if (!get_process_mitigation_policy) return SBOX_TEST_NOT_FOUND; #if !defined(_WIN64) // DEP is always enabled on 64-bit. if (!CheckWin8DepPolicy()) return SBOX_TEST_FIRST_ERROR; #endif #if defined(NDEBUG) // ASLR cannot be forced in debug builds. if (!CheckWin8AslrPolicy()) return SBOX_TEST_SECOND_ERROR; #endif if (!CheckWin8StrictHandlePolicy()) return SBOX_TEST_THIRD_ERROR; if (!CheckWin8DllExtensionPolicy()) return SBOX_TEST_FIFTH_ERROR; return SBOX_TEST_SUCCEEDED; } TEST(ProcessMitigationsTest, CheckWin8) { if (base::win::GetVersion() < base::win::VERSION_WIN8) return; TestRunner runner; sandbox::TargetPolicy* policy = runner.GetPolicy(); sandbox::MitigationFlags mitigations = MITIGATION_DEP | MITIGATION_DEP_NO_ATL_THUNK | MITIGATION_EXTENSION_DLL_DISABLE; #if defined(NDEBUG) // ASLR cannot be forced in debug builds. mitigations |= MITIGATION_RELOCATE_IMAGE | MITIGATION_RELOCATE_IMAGE_REQUIRED; #endif EXPECT_EQ(policy->SetProcessMitigations(mitigations), SBOX_ALL_OK); mitigations |= MITIGATION_STRICT_HANDLE_CHECKS; EXPECT_EQ(policy->SetDelayedProcessMitigations(mitigations), SBOX_ALL_OK); EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckWin8")); } SBOX_TESTS_COMMAND int CheckDep(int argc, wchar_t **argv) { GetProcessDEPPolicyFunction get_process_dep_policy = reinterpret_cast<GetProcessDEPPolicyFunction>( ::GetProcAddress(::GetModuleHandleW(L"kernel32.dll"), "GetProcessDEPPolicy")); if (get_process_dep_policy) { BOOL is_permanent = FALSE; DWORD dep_flags = 0; if (!get_process_dep_policy(::GetCurrentProcess(), &dep_flags, &is_permanent)) { return SBOX_TEST_FIRST_ERROR; } if (!(dep_flags & PROCESS_DEP_ENABLE) || !is_permanent) return SBOX_TEST_SECOND_ERROR; } else { NtQueryInformationProcessFunction query_information_process = NULL; ResolveNTFunctionPtr("NtQueryInformationProcess", &query_information_process); if (!query_information_process) return SBOX_TEST_NOT_FOUND; ULONG size = 0; ULONG dep_flags = 0; if (!SUCCEEDED(query_information_process(::GetCurrentProcess(), ProcessExecuteFlags, &dep_flags, sizeof(dep_flags), &size))) { return SBOX_TEST_THIRD_ERROR; } static const int MEM_EXECUTE_OPTION_DISABLE = 2; static const int MEM_EXECUTE_OPTION_PERMANENT = 8; dep_flags &= 0xff; if (dep_flags != (MEM_EXECUTE_OPTION_DISABLE | MEM_EXECUTE_OPTION_PERMANENT)) { return SBOX_TEST_FOURTH_ERROR; } } return SBOX_TEST_SUCCEEDED; } #if !defined(_WIN64) // DEP is always enabled on 64-bit. TEST(ProcessMitigationsTest, CheckDep) { if (base::win::GetVersion() > base::win::VERSION_WIN7) return; TestRunner runner; sandbox::TargetPolicy* policy = runner.GetPolicy(); EXPECT_EQ(policy->SetProcessMitigations( MITIGATION_DEP | MITIGATION_DEP_NO_ATL_THUNK | MITIGATION_SEHOP), SBOX_ALL_OK); EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckDep")); } #endif SBOX_TESTS_COMMAND int CheckWin8Lockdown(int argc, wchar_t **argv) { get_process_mitigation_policy = reinterpret_cast<GetProcessMitigationPolicyFunction>( ::GetProcAddress(::GetModuleHandleW(L"kernel32.dll"), "GetProcessMitigationPolicy")); if (!get_process_mitigation_policy) return SBOX_TEST_NOT_FOUND; if (!CheckWin8Win32CallPolicy()) return SBOX_TEST_FIRST_ERROR; return SBOX_TEST_SUCCEEDED; } // This test validates that setting the MITIGATION_WIN32K_DISABLE mitigation on // the target process causes the launch to fail in process initialization. // The test process itself links against user32/gdi32. TEST(ProcessMitigationsTest, CheckWin8Win32KLockDownFailure) { if (base::win::GetVersion() < base::win::VERSION_WIN8) return; TestRunner runner; sandbox::TargetPolicy* policy = runner.GetPolicy(); EXPECT_EQ(policy->SetProcessMitigations(MITIGATION_WIN32K_DISABLE), SBOX_ALL_OK); EXPECT_NE(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckWin8Lockdown")); } // This test validates that setting the MITIGATION_WIN32K_DISABLE mitigation // along with the policy to fake user32 and gdi32 initialization successfully // launches the target process. // The test process itself links against user32/gdi32. TEST(ProcessMitigationsTest, CheckWin8Win32KLockDownSuccess) { if (base::win::GetVersion() < base::win::VERSION_WIN8) return; TestRunner runner; sandbox::TargetPolicy* policy = runner.GetPolicy(); EXPECT_EQ(policy->SetProcessMitigations(MITIGATION_WIN32K_DISABLE), SBOX_ALL_OK); EXPECT_EQ(policy->AddRule(sandbox::TargetPolicy::SUBSYS_WIN32K_LOCKDOWN, sandbox::TargetPolicy::FAKE_USER_GDI_INIT, NULL), sandbox::SBOX_ALL_OK); EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckWin8Lockdown")); } } // namespace sandbox
BITS 64 GLOBAL _start _start: ;stack frame push rbp mov rbp, rsp sub rsp, 0x200 ;lets print message: rdi and rdx already set! print: mov rdi, 1 mov rsi, msg1 mov rdx, 0x27 mov rax, 1 syscall ;now read input 1 byte at a time: mov rsi, rsp read: mov rax, 0 mov r10, rsp add r10, 0x200 mov rdi, 0 mov rdx, 1 syscall ;compare to \x00 or \x0a cmp byte [rsi], 0 jz decode cmp byte [rsi], 0xa jz decode cmp rsi, r10 jge exit1 inc rsi jmp read ;exit decode: mov rsi, rsp ;key mov rdi, msg2 ;data xor rcx, rcx xor rdx, rdx loop: mov bl, byte [rsi+rcx] xor byte [rdi], bl inc rdi cmp rcx,7 jz res inc rcx jmp loop res: xor ecx, ecx cmp rdx, 8 jz msg2 inc rdx jmp loop exit1: db 0xb0,0x3c,0x48,0x31,0xff,0x0f,0x05 txt1: db 0x48,0x31,0xc0 msg1: db 'Holographic demux codephrase required: ',0x27 msg2: incbin "dump.bin" ;db 0xd2, 0x6f, 0x65, 0x6d, 0x6f, 0x26, 0xd7, 0x8b, \ ; 0x6c, 0x2e, 0x65, 0x6d, 0x6f, 0x6e, 0x69, 0xd9, \ ; 0x4e, 0x6e, 0x65, 0x6d, 0xd7, 0x6f, 0x69, 0x63, \ ; 0x6d, 0x61, 0x60, 0x39, 0x07, 0x0b, 0x49, 0x02, \ ; 0x0e, 0x0d, 0x00, 0x1e, 0x1c, 0x4e, 0x02, 0x06, \ ; 0x14, 0x4e, 0x09, 0x04, 0x0a, 0x1d, 0x49, 0x14, \ ; 0x04, 0x1a, 0x0d, 0x04, 0x01, 0x4e, 0x10, 0x0c, \ ; 0x18, 0x1c, 0x16, 0x08, 0x03, 0x08, 0x4a, 0x63 ; ;mov rdi, 1 ;mov rsi, msg3 ;mov rdx, 0x23 ;mov rax, 1 ;syscall ;db 0xb0,0x3c,0x48,0x31,0xff,0x0f,0x05 ;msg3: ;db 'The access key lies within yourself',0x23
addi $t1, $t1, 1 # Counting - 1 bne $t1, 10, Continue nop li $t1, 0 Continue: sw $t1, 0x7f40($0) loop_0: lw $s0, 0x7f50($0) # Read Time Length beq $s0, 0, loop_0 nop li $t2, 55000000 beq $s0, 1, NextWait nop li $t2, 110000000 NextWait: sw $t2, 0x7f04($0) # Set Timer eret
; A094160: Column 4 of A048790. ; 0,4,76,344,936,1980,3604,5936,9104,13236,18460,24904,32696,41964,52836,65440,79904,96356,114924,135736,158920,184604,212916,243984,277936,314900,355004,398376,445144,495436,549380,607104,668736,734404,804236,878360,956904,1039996,1127764,1220336,1317840,1420404,1528156,1641224,1759736,1883820,2013604,2149216,2290784,2438436,2592300,2752504,2919176,3092444,3272436,3459280,3653104,3854036,4062204,4277736,4500760,4731404,4969796,5216064,5470336,5732740,6003404,6282456,6570024,6866236,7171220,7485104,7808016,8140084,8481436,8832200,9192504,9562476,9942244,10331936,10731680,11141604,11561836,11992504,12433736,12885660,13348404,13822096,14306864,14802836,15310140,15828904,16359256,16901324,17455236,18021120,18599104,19189316,19791884,20406936,21034600,21675004,22328276,22994544,23673936,24366580,25072604,25792136,26525304,27272236,28033060,28807904,29596896,30400164,31217836,32050040,32896904,33758556,34635124,35526736,36433520,37355604,38293116,39246184,40214936,41199500,42200004,43216576,44249344,45298436,46363980,47446104,48544936,49660604,50793236,51942960,53109904,54294196,55495964,56715336,57952440,59207404,60480356,61771424,63080736,64408420,65754604,67119416,68502984,69905436,71326900,72767504,74227376,75706644,77205436,78723880,80262104,81820236,83398404,84996736,86615360,88254404,89913996,91594264,93295336,95017340,96760404,98524656,100310224,102117236,103945820,105796104,107668216,109562284,111478436,113416800,115377504,117360676,119366444,121394936,123446280,125520604,127618036,129738704,131882736,134050260,136241404,138456296,140695064,142957836,145244740,147555904,149891456,152251524,154636236,157045720,159480104,161939516,164424084,166933936,169469200,172030004,174616476,177228744,179866936,182531180,185221604,187938336,190681504,193451236,196247660,199070904,201921096,204798364,207702836,210634640,213593904,216580756,219595324,222637736,225708120,228806604,231933316,235088384,238271936,241484100,244725004,247994776,251293544,254621436,257978580,261365104,264781136,268226804,271702236,275207560,278742904,282308396,285904164,289530336,293187040,296874404,300592556,304341624,308121736,311933020,315775604,319649616,323555184,327492436 mov $2,$0 mov $3,$0 lpb $3 mov $0,$2 sub $3,1 sub $0,$3 mov $4,$0 mul $4,4 mov $5,$0 sub $5,1 mul $5,8 pow $5,2 add $4,$5 add $1,$4 lpe
%ifidn __OUTPUT_FORMAT__,obj section code use32 class=code align=64 %elifidn __OUTPUT_FORMAT__,win32 $@feat.00 equ 1 section .text code align=64 %else section .text code %endif ;extern _OPENSSL_ia32cap_P global _bn_mul_mont align 16 _bn_mul_mont: L$_bn_mul_mont_begin: push ebp push ebx push esi push edi xor eax,eax mov edi,DWORD [40+esp] cmp edi,4 jl NEAR L$000just_leave lea esi,[20+esp] lea edx,[24+esp] mov ebp,esp add edi,2 neg edi lea esp,[edi*4+esp-32] neg edi mov eax,esp sub eax,edx and eax,2047 sub esp,eax xor edx,esp and edx,2048 xor edx,2048 sub esp,edx and esp,-64 mov eax,DWORD [esi] mov ebx,DWORD [4+esi] mov ecx,DWORD [8+esi] mov edx,DWORD [12+esi] mov esi,DWORD [16+esi] mov esi,DWORD [esi] mov DWORD [4+esp],eax mov DWORD [8+esp],ebx mov DWORD [12+esp],ecx mov DWORD [16+esp],edx mov DWORD [20+esp],esi lea ebx,[edi-3] mov DWORD [24+esp],ebp lea eax,[_OPENSSL_ia32cap_P] bt DWORD [eax],26 jnc NEAR L$001non_sse2 mov eax,-1 movd mm7,eax mov esi,DWORD [8+esp] mov edi,DWORD [12+esp] mov ebp,DWORD [16+esp] xor edx,edx xor ecx,ecx movd mm4,DWORD [edi] movd mm5,DWORD [esi] movd mm3,DWORD [ebp] pmuludq mm5,mm4 movq mm2,mm5 movq mm0,mm5 pand mm0,mm7 pmuludq mm5,[20+esp] pmuludq mm3,mm5 paddq mm3,mm0 movd mm1,DWORD [4+ebp] movd mm0,DWORD [4+esi] psrlq mm2,32 psrlq mm3,32 inc ecx align 16 L$0021st: pmuludq mm0,mm4 pmuludq mm1,mm5 paddq mm2,mm0 paddq mm3,mm1 movq mm0,mm2 pand mm0,mm7 movd mm1,DWORD [4+ecx*4+ebp] paddq mm3,mm0 movd mm0,DWORD [4+ecx*4+esi] psrlq mm2,32 movd DWORD [28+ecx*4+esp],mm3 psrlq mm3,32 lea ecx,[1+ecx] cmp ecx,ebx jl NEAR L$0021st pmuludq mm0,mm4 pmuludq mm1,mm5 paddq mm2,mm0 paddq mm3,mm1 movq mm0,mm2 pand mm0,mm7 paddq mm3,mm0 movd DWORD [28+ecx*4+esp],mm3 psrlq mm2,32 psrlq mm3,32 paddq mm3,mm2 movq [32+ebx*4+esp],mm3 inc edx L$003outer: xor ecx,ecx movd mm4,DWORD [edx*4+edi] movd mm5,DWORD [esi] movd mm6,DWORD [32+esp] movd mm3,DWORD [ebp] pmuludq mm5,mm4 paddq mm5,mm6 movq mm0,mm5 movq mm2,mm5 pand mm0,mm7 pmuludq mm5,[20+esp] pmuludq mm3,mm5 paddq mm3,mm0 movd mm6,DWORD [36+esp] movd mm1,DWORD [4+ebp] movd mm0,DWORD [4+esi] psrlq mm2,32 psrlq mm3,32 paddq mm2,mm6 inc ecx dec ebx L$004inner: pmuludq mm0,mm4 pmuludq mm1,mm5 paddq mm2,mm0 paddq mm3,mm1 movq mm0,mm2 movd mm6,DWORD [36+ecx*4+esp] pand mm0,mm7 movd mm1,DWORD [4+ecx*4+ebp] paddq mm3,mm0 movd mm0,DWORD [4+ecx*4+esi] psrlq mm2,32 movd DWORD [28+ecx*4+esp],mm3 psrlq mm3,32 paddq mm2,mm6 dec ebx lea ecx,[1+ecx] jnz NEAR L$004inner mov ebx,ecx pmuludq mm0,mm4 pmuludq mm1,mm5 paddq mm2,mm0 paddq mm3,mm1 movq mm0,mm2 pand mm0,mm7 paddq mm3,mm0 movd DWORD [28+ecx*4+esp],mm3 psrlq mm2,32 psrlq mm3,32 movd mm6,DWORD [36+ebx*4+esp] paddq mm3,mm2 paddq mm3,mm6 movq [32+ebx*4+esp],mm3 lea edx,[1+edx] cmp edx,ebx jle NEAR L$003outer emms jmp NEAR L$005common_tail align 16 L$001non_sse2: mov esi,DWORD [8+esp] lea ebp,[1+ebx] mov edi,DWORD [12+esp] xor ecx,ecx mov edx,esi and ebp,1 sub edx,edi lea eax,[4+ebx*4+edi] or ebp,edx mov edi,DWORD [edi] jz NEAR L$006bn_sqr_mont mov DWORD [28+esp],eax mov eax,DWORD [esi] xor edx,edx align 16 L$007mull: mov ebp,edx mul edi add ebp,eax lea ecx,[1+ecx] adc edx,0 mov eax,DWORD [ecx*4+esi] cmp ecx,ebx mov DWORD [28+ecx*4+esp],ebp jl NEAR L$007mull mov ebp,edx mul edi mov edi,DWORD [20+esp] add eax,ebp mov esi,DWORD [16+esp] adc edx,0 imul edi,DWORD [32+esp] mov DWORD [32+ebx*4+esp],eax xor ecx,ecx mov DWORD [36+ebx*4+esp],edx mov DWORD [40+ebx*4+esp],ecx mov eax,DWORD [esi] mul edi add eax,DWORD [32+esp] mov eax,DWORD [4+esi] adc edx,0 inc ecx jmp NEAR L$0082ndmadd align 16 L$0091stmadd: mov ebp,edx mul edi add ebp,DWORD [32+ecx*4+esp] lea ecx,[1+ecx] adc edx,0 add ebp,eax mov eax,DWORD [ecx*4+esi] adc edx,0 cmp ecx,ebx mov DWORD [28+ecx*4+esp],ebp jl NEAR L$0091stmadd mov ebp,edx mul edi add eax,DWORD [32+ebx*4+esp] mov edi,DWORD [20+esp] adc edx,0 mov esi,DWORD [16+esp] add ebp,eax adc edx,0 imul edi,DWORD [32+esp] xor ecx,ecx add edx,DWORD [36+ebx*4+esp] mov DWORD [32+ebx*4+esp],ebp adc ecx,0 mov eax,DWORD [esi] mov DWORD [36+ebx*4+esp],edx mov DWORD [40+ebx*4+esp],ecx mul edi add eax,DWORD [32+esp] mov eax,DWORD [4+esi] adc edx,0 mov ecx,1 align 16 L$0082ndmadd: mov ebp,edx mul edi add ebp,DWORD [32+ecx*4+esp] lea ecx,[1+ecx] adc edx,0 add ebp,eax mov eax,DWORD [ecx*4+esi] adc edx,0 cmp ecx,ebx mov DWORD [24+ecx*4+esp],ebp jl NEAR L$0082ndmadd mov ebp,edx mul edi add ebp,DWORD [32+ebx*4+esp] adc edx,0 add ebp,eax adc edx,0 mov DWORD [28+ebx*4+esp],ebp xor eax,eax mov ecx,DWORD [12+esp] add edx,DWORD [36+ebx*4+esp] adc eax,DWORD [40+ebx*4+esp] lea ecx,[4+ecx] mov DWORD [32+ebx*4+esp],edx cmp ecx,DWORD [28+esp] mov DWORD [36+ebx*4+esp],eax je NEAR L$005common_tail mov edi,DWORD [ecx] mov esi,DWORD [8+esp] mov DWORD [12+esp],ecx xor ecx,ecx xor edx,edx mov eax,DWORD [esi] jmp NEAR L$0091stmadd align 16 L$006bn_sqr_mont: mov DWORD [esp],ebx mov DWORD [12+esp],ecx mov eax,edi mul edi mov DWORD [32+esp],eax mov ebx,edx shr edx,1 and ebx,1 inc ecx align 16 L$010sqr: mov eax,DWORD [ecx*4+esi] mov ebp,edx mul edi add eax,ebp lea ecx,[1+ecx] adc edx,0 lea ebp,[eax*2+ebx] shr eax,31 cmp ecx,DWORD [esp] mov ebx,eax mov DWORD [28+ecx*4+esp],ebp jl NEAR L$010sqr mov eax,DWORD [ecx*4+esi] mov ebp,edx mul edi add eax,ebp mov edi,DWORD [20+esp] adc edx,0 mov esi,DWORD [16+esp] lea ebp,[eax*2+ebx] imul edi,DWORD [32+esp] shr eax,31 mov DWORD [32+ecx*4+esp],ebp lea ebp,[edx*2+eax] mov eax,DWORD [esi] shr edx,31 mov DWORD [36+ecx*4+esp],ebp mov DWORD [40+ecx*4+esp],edx mul edi add eax,DWORD [32+esp] mov ebx,ecx adc edx,0 mov eax,DWORD [4+esi] mov ecx,1 align 16 L$0113rdmadd: mov ebp,edx mul edi add ebp,DWORD [32+ecx*4+esp] adc edx,0 add ebp,eax mov eax,DWORD [4+ecx*4+esi] adc edx,0 mov DWORD [28+ecx*4+esp],ebp mov ebp,edx mul edi add ebp,DWORD [36+ecx*4+esp] lea ecx,[2+ecx] adc edx,0 add ebp,eax mov eax,DWORD [ecx*4+esi] adc edx,0 cmp ecx,ebx mov DWORD [24+ecx*4+esp],ebp jl NEAR L$0113rdmadd mov ebp,edx mul edi add ebp,DWORD [32+ebx*4+esp] adc edx,0 add ebp,eax adc edx,0 mov DWORD [28+ebx*4+esp],ebp mov ecx,DWORD [12+esp] xor eax,eax mov esi,DWORD [8+esp] add edx,DWORD [36+ebx*4+esp] adc eax,DWORD [40+ebx*4+esp] mov DWORD [32+ebx*4+esp],edx cmp ecx,ebx mov DWORD [36+ebx*4+esp],eax je NEAR L$005common_tail mov edi,DWORD [4+ecx*4+esi] lea ecx,[1+ecx] mov eax,edi mov DWORD [12+esp],ecx mul edi add eax,DWORD [32+ecx*4+esp] adc edx,0 mov DWORD [32+ecx*4+esp],eax xor ebp,ebp cmp ecx,ebx lea ecx,[1+ecx] je NEAR L$012sqrlast mov ebx,edx shr edx,1 and ebx,1 align 16 L$013sqradd: mov eax,DWORD [ecx*4+esi] mov ebp,edx mul edi add eax,ebp lea ebp,[eax*1+eax] adc edx,0 shr eax,31 add ebp,DWORD [32+ecx*4+esp] lea ecx,[1+ecx] adc eax,0 add ebp,ebx adc eax,0 cmp ecx,DWORD [esp] mov DWORD [28+ecx*4+esp],ebp mov ebx,eax jle NEAR L$013sqradd mov ebp,edx add edx,edx shr ebp,31 add edx,ebx adc ebp,0 L$012sqrlast: mov edi,DWORD [20+esp] mov esi,DWORD [16+esp] imul edi,DWORD [32+esp] add edx,DWORD [32+ecx*4+esp] mov eax,DWORD [esi] adc ebp,0 mov DWORD [32+ecx*4+esp],edx mov DWORD [36+ecx*4+esp],ebp mul edi add eax,DWORD [32+esp] lea ebx,[ecx-1] adc edx,0 mov ecx,1 mov eax,DWORD [4+esi] jmp NEAR L$0113rdmadd align 16 L$005common_tail: mov ebp,DWORD [16+esp] mov edi,DWORD [4+esp] lea esi,[32+esp] mov eax,DWORD [esi] mov ecx,ebx xor edx,edx align 16 L$014sub: sbb eax,DWORD [edx*4+ebp] mov DWORD [edx*4+edi],eax dec ecx mov eax,DWORD [4+edx*4+esi] lea edx,[1+edx] jge NEAR L$014sub sbb eax,0 and esi,eax not eax mov ebp,edi and ebp,eax or esi,ebp align 16 L$015copy: mov eax,DWORD [ebx*4+esi] mov DWORD [ebx*4+edi],eax mov DWORD [32+ebx*4+esp],ecx dec ebx jge NEAR L$015copy mov esp,DWORD [24+esp] mov eax,1 L$000just_leave: pop edi pop esi pop ebx pop ebp ret db 77,111,110,116,103,111,109,101,114,121,32,77,117,108,116,105 db 112,108,105,99,97,116,105,111,110,32,102,111,114,32,120,56 db 54,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121 db 32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46 db 111,114,103,62,0 segment .bss common _OPENSSL_ia32cap_P 16
// 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. /*============================================================ ** ** Source : test.c ** ** Purpose: InterlockedIncrement64() function ** ** The test case spawns MAX_THREADS Threads, and each thread call InterlockedDecrement Function to decrement a ** global counter REPEAT_COUNT Times. The Test case sets the global counter to Zero at the begining of the test. ** The test cases passes if at the end the test the value of the global counter is MAX_THREADS * REPEAT_COUNT. ** ** **=========================================================*/ #include <palsuite.h> #define MAX_THREADS 64 #define REPEAT_COUNT 10000 LONG GlobalCounter = 0; void IncrementCounter(void); int __cdecl main(int argc, char *argv[]) { LONG TotalOperations=0; int i=0; DWORD dwThreadID = 0; HANDLE hThread[MAX_THREADS]; TotalOperations = MAX_THREADS * REPEAT_COUNT; GlobalCounter = 0; /* * Initialize the PAL and return FAILURE if this fails */ if(0 != (PAL_Initialize(argc, argv))) { return FAIL; } /* ** Run only on 64 bit platforms */ #if defined(BIT64) //Create MAX_THREADS threads that will operate on the global counter for (i=0;i<MAX_THREADS;i++) { hThread[i] = CreateThread( NULL, // default security attributes 0, // use default stack size (LPTHREAD_START_ROUTINE) IncrementCounter, // thread function NULL, // argument to thread function 0, // use default creation flags &dwThreadID); // returns the thread identifier // Check the return value for success. if (hThread[i] == NULL) { Fail("ERROR: Was not able to create thread\n" "GetLastError returned %d\n", GetLastError()); } } //Wait for all threads to finish for (i=0;i<MAX_THREADS;i++) { if (WAIT_OBJECT_0 != WaitForSingleObject (hThread[i], INFINITE)) { Fail ("Main: Wait for Single Object failed. Failing test.\n" "GetLastError returned %d\n", GetLastError()); } } /* Compare the value of global counter with zero. */ if (TotalOperations!=GlobalCounter) { Fail("Test Case Failed: InterlockedDecrement \n"); } #endif //defined(BIT64) PAL_Terminate(); return PASS; } void IncrementCounter(void) { int i=0; for (i=0; i<REPEAT_COUNT;i++) { InterlockedIncrement(&GlobalCounter); } }
/*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*/ #ifndef OPENCV_OLD_CV_HPP #define OPENCV_OLD_CV_HPP //#if defined(__GNUC__) //#warning "This is a deprecated opencv_include.opencv header provided for compatibility. Please include a header from a corresponding opencv_include.opencv module" //#endif #include "cv.h" #include "opencv2/core.hpp" #include "opencv2/imgproc.hpp" #include "opencv2/photo.hpp" #include "opencv2/video.hpp" #include "opencv2/highgui.hpp" #include "opencv2/features2d.hpp" #include "opencv2/calib3d.hpp" #include "opencv2/objdetect.hpp" #endif
; A238340: Number of partitions of 4n into 4 parts. ; 1,5,15,34,64,108,169,249,351,478,632,816,1033,1285,1575,1906,2280,2700,3169,3689,4263,4894,5584,6336,7153,8037,8991,10018,11120,12300,13561,14905,16335,17854,19464,21168,22969,24869,26871,28978,31192,33516,35953,38505,41175,43966,46880,49920,53089,56389,59823,63394,67104,70956,74953,79097,83391,87838,92440,97200,102121,107205,112455,117874,123464,129228,135169,141289,147591,154078,160752,167616,174673,181925,189375,197026,204880,212940,221209,229689,238383,247294,256424,265776,275353,285157,295191,305458,315960,326700,337681,348905,360375,372094,384064,396288,408769,421509,434511,447778 mul $0,2 add $0,3 mov $1,$0 mul $0,2 sub $0,3 mul $0,$1 mul $0,$1 mul $0,8 div $0,288 add $0,1
<% from pwnlib.shellcraft import i386 %> <%page args="string, sock = '1'"/> <%docstring> Writes a string to a file descriptor Example: >>> run_assembly(shellcraft.echo('hello', 1)).recvall() 'hello' </%docstring> ${i386.pushstr(string, append_null = False)} ${i386.linux.syscall('SYS_write', sock, 'esp', len(string))}
; ######################################################################### .386 .model flat, stdcall option casemap :none ; case sensitive ; ######################################################################### include \masm32\include\windows.inc include \masm32\include\user32.inc include \masm32\include\kernel32.inc include \masm32\include\gdi32.inc include \masm32\include\masm32.inc includelib \masm32\lib\user32.lib includelib \masm32\lib\kernel32.lib includelib \masm32\lib\gdi32.lib includelib \masm32\lib\masm32.lib ; ######################################################################### ;============= ; Local macros ;============= szText MACRO Name, Text:VARARG LOCAL lbl jmp lbl Name db Text,0 lbl: ENDM m2m MACRO M1, M2 push M2 pop M1 ENDM return MACRO arg mov eax, arg ret ENDM ;================= ; Local prototypes ;================= WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD TopXY PROTO :DWORD,:DWORD Paint_Proc PROTO :DWORD,:DWORD Frame3D PROTO :DWORD, :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD FrameCtrl PROTO :DWORD,:DWORD,:DWORD,:DWORD FrameWindow PROTO :DWORD,:DWORD,:DWORD,:DWORD ; ---------------------------------- ; These are the two controls used on ; the client area of the window ; ---------------------------------- EditSl PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD Static PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD PushButton PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD .data szDisplayName db "Registration Skeleton",0 CommandLine dd 0 hWnd dd 0 hInstance dd 0 hEdit1 dd 0 hEdit2 dd 0 hEdit3 dd 0 hButn1 dd 0 hFont dd 0 .code start: invoke GetModuleHandle, NULL mov hInstance, eax invoke GetCommandLine mov CommandLine, eax invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT invoke ExitProcess,eax ; ######################################################################### WinMain proc hInst :DWORD, hPrevInst :DWORD, CmdLine :DWORD, CmdShow :DWORD ;==================== ; Put LOCALs on stack ;==================== LOCAL wc :WNDCLASSEX LOCAL msg :MSG LOCAL Wwd :DWORD LOCAL Wht :DWORD LOCAL Wtx :DWORD LOCAL Wty :DWORD ;================================================== ; Fill WNDCLASSEX structure with required variables ;================================================== mov wc.cbSize, sizeof WNDCLASSEX mov wc.style, CS_HREDRAW or CS_VREDRAW \ or CS_BYTEALIGNWINDOW mov wc.lpfnWndProc, offset WndProc mov wc.cbClsExtra, NULL mov wc.cbWndExtra, NULL m2m wc.hInstance, hInst ;<< NOTE: macro not mnemonic mov wc.hbrBackground, COLOR_BTNFACE+1 mov wc.lpszMenuName, NULL mov wc.lpszClassName, offset szClassName invoke LoadIcon,hInst,500 ; icon ID mov wc.hIcon, eax invoke LoadCursor,NULL,IDC_ARROW mov wc.hCursor, eax mov wc.hIconSm, 0 invoke RegisterClassEx, ADDR wc ;================================ ; Centre window at following size ;================================ mov Wwd, 355 mov Wht, 280 invoke GetSystemMetrics,SM_CXSCREEN invoke TopXY,Wwd,eax mov Wtx, eax invoke GetSystemMetrics,SM_CYSCREEN invoke TopXY,Wht,eax mov Wty, eax szText szClassName,"Template_Class" invoke CreateWindowEx,WS_EX_LEFT, ADDR szClassName, ADDR szDisplayName, WS_OVERLAPPED or WS_SYSMENU, Wtx,Wty,Wwd,Wht, NULL,NULL, hInst,NULL mov hWnd,eax invoke ShowWindow,hWnd,SW_SHOWNORMAL invoke UpdateWindow,hWnd ;=================================== ; Loop until PostQuitMessage is sent ;=================================== StartLoop: invoke GetMessage,ADDR msg,NULL,0,0 cmp eax, 0 je ExitLoop invoke TranslateMessage, ADDR msg invoke DispatchMessage, ADDR msg jmp StartLoop ExitLoop: return msg.wParam WinMain endp ; ######################################################################### WndProc proc hWin :DWORD, uMsg :DWORD, wParam :DWORD, lParam :DWORD LOCAL hDC :DWORD LOCAL Ps :PAINTSTRUCT .if uMsg == WM_COMMAND .if wParam == 500 ;<<<< The button invoke SendMessage,hWin,WM_SYSCOMMAND,SC_CLOSE,NULL .endif .elseif uMsg == WM_CREATE szText font1,"Times New Roman" invoke CreateFont,16,8,0,0,500,0,0,0, \ DEFAULT_CHARSET,0,0,0,\ DEFAULT_PITCH,ADDR font1 mov hFont, eax szText adrTxt,0 szText lbl1," Text Box 1" invoke Static,ADDR lbl1,hWin,50,30,200,17,0 szText lbl2," Text Box 2" invoke Static,ADDR lbl2,hWin,50,80,200,17,0 szText lbl3," Text Box 3" invoke Static,ADDR lbl3,hWin,50,130,200,17,0 invoke EditSl,ADDR adrTxt,50,50,250,23,hWin,700 mov hEdit1, eax invoke EditSl,ADDR adrTxt,50,100,250,23,hWin,701 mov hEdit2, eax invoke EditSl,ADDR adrTxt,50,150,250,23,hWin,702 mov hEdit3, eax szText ButnTxt,"Register" invoke PushButton,ADDR ButnTxt,hWin,125,215,100,25,500 mov hButn1, eax .elseif uMsg == WM_PAINT invoke BeginPaint,hWin,ADDR Ps mov hDC, eax invoke Paint_Proc,hWin,hDC invoke EndPaint,hWin,ADDR Ps return 0 .elseif uMsg == WM_CLOSE invoke DeleteObject,hFont .elseif uMsg == WM_DESTROY invoke PostQuitMessage,NULL return 0 .endif invoke DefWindowProc,hWin,uMsg,wParam,lParam ret WndProc endp ; ######################################################################## TopXY proc wDim:DWORD, sDim:DWORD shr sDim, 1 ; divide screen dimension by 2 shr wDim, 1 ; divide window dimension by 2 mov eax, wDim ; copy window dimension into eax sub sDim, eax ; sub half win dimension from half screen dimension return sDim TopXY endp ; ######################################################################## EditSl proc szMsg:DWORD,a:DWORD,b:DWORD, wd:DWORD,ht:DWORD,hParent:DWORD,ID:DWORD ; EditSl PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD ; invoke EditSl,ADDR adrTxt,200,10,150,25,hWnd,700 LOCAL hndle:DWORD szText slEdit,"EDIT" invoke CreateWindowEx,WS_EX_CLIENTEDGE,ADDR slEdit,szMsg, WS_VISIBLE or WS_CHILDWINDOW or \ ES_AUTOHSCROLL or ES_NOHIDESEL, a,b,wd,ht,hParent,ID,hInstance,NULL mov hndle, eax invoke SendMessage,hndle,WM_SETFONT,hFont,1 mov eax, hndle ret EditSl endp ; ######################################################################## Static proc lpText:DWORD,hParent:DWORD, a:DWORD,b:DWORD,wd:DWORD,ht:DWORD,ID:DWORD ; Static PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD ; invoke Static,ADDR szText,hWnd,20,20,100,15,500 LOCAL hndle:DWORD szText statClass,"STATIC" invoke CreateWindowEx,WS_EX_LEFT, ADDR statClass,lpText, WS_CHILD or WS_VISIBLE or SS_LEFT, a,b,wd,ht,hParent,ID, hInstance,NULL mov hndle, eax invoke SendMessage,hndle,WM_SETFONT,hFont, 0 mov eax, hndle ret Static endp ; ######################################################################## PushButton proc lpText:DWORD,hParent:DWORD, a:DWORD,b:DWORD,wd:DWORD,ht:DWORD,ID:DWORD ; PushButton PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD ; invoke PushButton,ADDR szText,hWnd,20,20,100,25,500 LOCAL hndle:DWORD szText btnClass,"BUTTON" invoke CreateWindowEx,0, ADDR btnClass,lpText, WS_CHILD or WS_VISIBLE, a,b,wd,ht,hParent,ID, hInstance,NULL mov hndle, eax invoke SendMessage,hndle,WM_SETFONT,hFont, 0 mov eax, hndle ret PushButton endp ; ######################################################################## Paint_Proc proc hWin:DWORD, hDC:DWORD invoke FrameCtrl,hEdit1,2,1,1 invoke FrameCtrl,hEdit2,2,1,1 invoke FrameCtrl,hEdit3,2,1,1 invoke FrameCtrl,hButn1,3,1,0 invoke FrameGrp,hEdit1,hEdit3,26,1,1 invoke FrameGrp,hEdit1,hEdit3,27,1,0 invoke FrameWindow,hWin,0,1,0 invoke FrameWindow,hWin,4,1,1 return 0 Paint_Proc endp ; ######################################################################### end start
/* * Copyright (c) 2002, 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. * */ #include "jni.h" extern "C" { JNIEXPORT jint JNICALL JVM_OnLoad(JavaVM *vm, char *options, void *reserved); }
; multitasking and dynamic thread registration ; delete the completed task [org 0x0100] jmp start ; PCB layout: ; ax,bx,cx,dx,si,di,bp,sp,ip,cs,ds,ss,es,flags,next,dummy ; 0, 2, 4, 6, 8, 10,12,14,16,18,20,22,24, 26 , 28 , 30 pcb: times 32*16 dw 0 ; space for 32 PCBs stack: times 32*256 dw 0 ; space for 32 512 byte stacks nextpcb: dw 1 ; index of next free pcb current: dw 0 ; index of current pcb lineno: dw 0 ; line number for next thread printnum: push bp mov bp, sp push es push ax push bx push cx push dx push di mov di, 80 ; load di with columns per row mov ax, [bp+8] ; load ax with row number mul di ; multiply with columns per row mov di, ax ; save result in di add di, [bp+6] ; add column number shl di, 1 ; turn into byte count add di, 8 ; to end of number location mov ax, 0xb800 mov es, ax ; point es to video base mov ax, [bp+4] ; load number in ax mov bx, 16 ; use base 16 for division mov cx, 4 ; initialize count of digits nextdigit: mov dx, 0 ; zero upper half of dividend div bx ; divide by 10 add dl, 0x30 ; convert digit into ascii value cmp dl, 0x39 ; is the digit an alphabet jbe skipalpha ; no, skip addition add dl, 7 ; yes, make in alphabet code skipalpha: mov dh, 0x07 ; attach normal attribute mov [es:di], dx ; print char on screen sub di, 2 ; to previous screen location loop nextdigit ; if no divide it again pop di pop dx pop cx pop bx pop ax pop es pop bp ret 6 ;;;;; COPY LINES 028-071 FROM EXAMPLE 10.1 (printnum) ;;;;; ; mytask subroutine to be run as a thread ; takes line number as parameter mytask: push bp mov bp, sp sub sp, 2 ; thread local variable push ax push bx mov ax, [bp+4] ; load line number parameter mov bx, 70 ; use column number 70 mov word [bp-2], 0 ; initialize local variable printagain: push ax ; line number push bx ; column number push word [bp-2] ; number to be printed call printnum ; print the number inc word [bp-2] ; increment the local variable cmp word [bp-2], 0xffff jne printagain ; print if param<ffff mov bx, 160 mul bl add ax, 142 push es push 0xb800 pop es mov bx, ax mov word [es:bx], 0x0720 mov word [es:bx+2], 0x0720 mov word [es:bx+4], 0x0720 mov word [es:bx+6], 0x0720 pop es cli pop bx pop ax mov sp, bp pop bp ret delete_me: mov bx, [cs:current] shl bx, 5 mov word [cs:pcb+bx+30], 0 call set_next mov word [cs:current], 0 mov ax, [cs:pcb+0] ; read ax of new process mov bx, [cs:pcb+2] ; read bx of new process mov cx, [cs:pcb+4] ; read cx of new process mov dx, [cs:pcb+6] ; read dx of new process mov si, [cs:pcb+8] ; read si of new process mov di, [cs:pcb+10] ; read diof new process mov bp, [cs:pcb+12] ; read bp of new process mov es, [cs:pcb+24] ; read es of new process mov ss, [cs:pcb+22] ; read ss of new process mov sp, [cs:pcb+14] ; read sp of new process push word [cs:pcb+26] ; push flags of new process push word [cs:pcb+18] ; push cs of new process push word [cs:pcb+16] ; push ip of new process push word [cs:pcb+20] ; push ds of new process pop ds ; read ds of new process iret ; return to new process set_next: pusha ;ax=next ;bx=next*32 ;si=current ;di=current*32 mov ax, 1 mov si, 0 set_next2: mov bx, ax shl bx, 5 mov di, si shl di, 5 cmp word [cs:pcb+bx+30], 0 je skip2 mov [cs:pcb+di+28], ax mov si, ax skip2: inc ax cmp ax, 32 jne set_next2 mov word [cs:pcb+di+28], 0 popa ret ; subroutine to register a new thread ; takes the segment, offset, of the thread routine and a parameter ; for the target thread subroutine initpcb: push bp mov bp, sp push ax push bx push cx push si ; push word [nextpcb] ; line number ; push word 0 ; column number ; push word 1 ; number to be printed ; call printnum ; print the number ; inc word [nextpcb] mov si, 1 init_loop: mov bx, si shl bx, 5 cmp word [pcb+bx+30], 0 je found inc si cmp si, 32 je exit jmp init_loop found: mov word [pcb+bx+30], 1 mov bx, si mov [nextpcb], bx or [pcb+30], cx mov cl, 5 shl bx, cl ; multiply by 32 for pcb start mov ax, [bp+8] ; read segment parameter mov [pcb+bx+18], ax ; save in pcb space for cs mov ax, [bp+6] ; read offset parameter mov [pcb+bx+16], ax ; save in pcb space for ip mov [pcb+bx+22], ds ; set stack to our segment mov si, [nextpcb] ; read this pcb index mov cl, 9 shl si, cl ; multiply by 512 add si, 256*2+stack ; end of stack for this thread shr bx, 5 mov ax, bx ; read parameter for subroutine dec ax shl bx, 5 sub si, 2 ; decrement thread stack pointer mov [si], ax ; pushing param on thread stack sub si, 2 ; space for return address mov word [si], delete_me; pushing return address on thread stack mov [pcb+bx+14], si ; save si in pcb space for sp mov word [pcb+bx+26], 0x0200 ; initialize thread flags mov ax, [pcb+28] ; read next of 0th thread in ax mov [pcb+bx+28], ax ; set as next of new thread mov ax, [nextpcb] ; read new thread index mov [pcb+28], ax ; set as next of 0th thread inc word [nextpcb] ; this pcb is now used call set_next exit: ; push word [lineno] ; line number ; push word 0 ; column number ; push word [pcb+30] ; number to be printed ; call printnum ; print the number pop si pop cx pop bx pop ax pop bp ret 6 ; timer interrupt service routine timer: push ds push bx push cs pop ds ; initialize ds to data segment mov bx, [current] ; read index of current in bx shl bx, 1 shl bx, 1 shl bx, 1 shl bx, 1 shl bx, 1 ; multiply by 32 for pcb start mov [pcb+bx+0], ax ; save ax in current pcb mov [pcb+bx+4], cx ; save cx in current pcb mov [pcb+bx+6], dx ; save dx in current pcb mov [pcb+bx+8], si ; save si in current pcb mov [pcb+bx+10], di ; save di in current pcb mov [pcb+bx+12], bp ; save bp in current pcb mov [pcb+bx+24], es ; save es in current pcb pop ax ; read original bx from stack mov [pcb+bx+2], ax ; save bx in current pcb pop ax ; read original ds from stack mov [pcb+bx+20], ax ; save ds in current pcb pop ax ; read original ip from stack mov [pcb+bx+16], ax ; save ip in current pcb pop ax ; read original cs from stack mov [pcb+bx+18], ax ; save cs in current pcb pop ax ; read original flags from stack mov [pcb+bx+26], ax ; save cs in current pcb mov [pcb+bx+22], ss ; save ss in current pcb mov [pcb+bx+14], sp ; save sp in current pcb mov bx, [pcb+bx+28] ; read next pcb of this pcb mov [current], bx ; update current to new pcb mov cl, 5 shl bx, cl ; multiply by 32 for pcb start mov cx, [pcb+bx+4] ; read cx of new process mov dx, [pcb+bx+6] ; read dx of new process mov si, [pcb+bx+8] ; read si of new process mov di, [pcb+bx+10] ; read diof new process mov bp, [pcb+bx+12] ; read bp of new process mov es, [pcb+bx+24] ; read es of new process mov ss, [pcb+bx+22] ; read ss of new process mov sp, [pcb+bx+14] ; read sp of new process push word [pcb+bx+26] ; push flags of new process push word [pcb+bx+18] ; push cs of new process push word [pcb+bx+16] ; push ip of new process push word [pcb+bx+20] ; push ds of new process mov al, 0x20 out 0x20, al ; send EOI to PIC mov ax, [pcb+bx+0] ; read ax of new process mov bx, [pcb+bx+2] ; read bx of new process pop ds ; read ds of new process iret ; return to new process start: xor ax, ax mov es, ax ; point es to IVT base cli mov word [es:8*4], timer mov [es:8*4+2], cs ; hook timer interrupt sti nextkey: xor ah, ah ; service 0 – get keystroke int 0x16 ; bios keyboard services push cs ; use current code segment mov ax, mytask push ax ; use mytask as offset push word [lineno] ; thread parameter call initpcb ; register the thread inc word [lineno] ; update line number jmp nextkey ; wait for next keypress
; A292350: Number of Lyndon words (aperiodic necklaces) with 6 beads of n colors. ; 0,9,116,670,2580,7735,19544,43596,88440,166485,295020,497354,804076,1254435,1897840,2795480,4022064,5667681,7839780,10665270,14292740,18894799,24670536,31848100,40687400,51482925,64566684,80311266,99133020,121495355,147912160,178951344,215238496,257460665,306370260,362789070,427612404,501813351,586447160,682655740,791672280,914825989,1053546956,1209371130,1383945420,1579032915,1796518224,2038412936,2306861200,2604145425,2932692100,3295077734,3694034916,4132458495,4613411880,5140133460,5716043144,6344749021,7030054140,7775963410,8586690620,9466665579,10420541376,11453201760,12569768640,13775609705,15076346164,16477860606,17986304980,19608108695,21349986840,23218948524,25222305336,27367679925,29663014700,32116580650,34736986284,37533186691,40514492720,43690580280,47071499760,50667685569,54489965796,58549571990,62858149060,67427765295,72270922504,77400566276,82830096360,88573377165,94644748380,101059035714,107831561756,114978156955,122515170720,130459482640,138828513824,147640238361,156913194900,166666498350 add $0,1 mov $1,$0 pow $1,2 mul $1,$0 bin $0,2 bin $1,2 sub $1,$0 mov $0,$1 div $0,3
// Document/View sample for Boost.Signals // Copyright Keith MacDonald 2005. Use, modification and // distribution is subject to 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) // For more information, see http://www.boost.org #include <iostream> #include <string> #include <boost/signal.hpp> #include <boost/bind.hpp> class Document { public: typedef boost::signal<void (bool)> signal_t; typedef boost::signals::connection connection_t; public: Document() {} connection_t connect(signal_t::slot_function_type subscriber) { return m_sig.connect(subscriber); } void disconnect(connection_t subscriber) { subscriber.disconnect(); } void append(const char* s) { m_text += s; m_sig(true); } const std::string& getText() const { return m_text; } private: signal_t m_sig; std::string m_text; }; class View { public: View(Document& m) : m_document(m) { m_connection = m_document.connect(boost::bind(&View::refresh, this, _1)); } virtual ~View() { m_document.disconnect(m_connection); } virtual void refresh(bool bExtended) const = 0; protected: Document& m_document; private: Document::connection_t m_connection; }; class TextView : public View { public: TextView(Document& doc) : View(doc) {} virtual void refresh(bool bExtended) const { std::cout << "TextView: " << m_document.getText() << std::endl; } }; class HexView : public View { public: HexView(Document& doc) : View(doc) {} virtual void refresh(bool bExtended) const { const std::string& s = m_document.getText(); std::cout << "HexView:"; for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) std::cout << ' ' << std::hex << static_cast<int>(*it); std::cout << std::endl; } }; int main(int argc, char* argv[]) { Document doc; TextView v1(doc); HexView v2(doc); doc.append(argc == 2 ? argv[1] : "Hello world!"); return 0; }
// Autogenerated from CppHeaderCreator // Created by Sc2ad // ========================================================================= #pragma once // Begin includes #include "beatsaber-hook/shared/utils/typedefs.h" #include "beatsaber-hook/shared/utils/byref.hpp" // Including type: Valve.VR.IVROverlay #include "Valve/VR/IVROverlay.hpp" // Including type: System.MulticastDelegate #include "System/MulticastDelegate.hpp" #include "beatsaber-hook/shared/utils/il2cpp-utils-methods.hpp" #include "beatsaber-hook/shared/utils/il2cpp-utils-properties.hpp" #include "beatsaber-hook/shared/utils/il2cpp-utils-fields.hpp" #include "beatsaber-hook/shared/utils/utils.h" // Completed includes // Begin forward declares // Forward declaring namespace: Valve::VR namespace Valve::VR { // Forward declaring type: EVROverlayError struct EVROverlayError; } // Forward declaring namespace: System::Text namespace System::Text { // Forward declaring type: StringBuilder class StringBuilder; } // Forward declaring namespace: System namespace System { // Forward declaring type: IAsyncResult class IAsyncResult; // Forward declaring type: AsyncCallback class AsyncCallback; } // Completed forward declares #include "beatsaber-hook/shared/utils/il2cpp-type-check.hpp" NEED_NO_BOX(::Valve::VR::IVROverlay::_GetOverlayTransformTrackedDeviceComponent); DEFINE_IL2CPP_ARG_TYPE(::Valve::VR::IVROverlay::_GetOverlayTransformTrackedDeviceComponent*, "Valve.VR", "IVROverlay/_GetOverlayTransformTrackedDeviceComponent"); // Type namespace: Valve.VR namespace Valve::VR { // Size: 0x70 #pragma pack(push, 1) // Autogenerated type: Valve.VR.IVROverlay/Valve.VR._GetOverlayTransformTrackedDeviceComponent // [TokenAttribute] Offset: FFFFFFFF // [UnmanagedFunctionPointerAttribute] Offset: 12082DC class IVROverlay::_GetOverlayTransformTrackedDeviceComponent : public ::System::MulticastDelegate { public: // public System.Void .ctor(System.Object object, System.IntPtr method) // Offset: 0x2640F54 template<::il2cpp_utils::CreationType creationType = ::il2cpp_utils::CreationType::Temporary> static IVROverlay::_GetOverlayTransformTrackedDeviceComponent* New_ctor(::Il2CppObject* object, ::System::IntPtr method) { static auto ___internal__logger = ::Logger::get().WithContext("::Valve::VR::IVROverlay::_GetOverlayTransformTrackedDeviceComponent::.ctor"); return THROW_UNLESS((::il2cpp_utils::New<IVROverlay::_GetOverlayTransformTrackedDeviceComponent*, creationType>(object, method))); } // public Valve.VR.EVROverlayError Invoke(System.UInt64 ulOverlayHandle, ref System.UInt32 punDeviceIndex, System.Text.StringBuilder pchComponentName, System.UInt32 unComponentNameSize) // Offset: 0x2640F64 ::Valve::VR::EVROverlayError Invoke(uint64_t ulOverlayHandle, ByRef<uint> punDeviceIndex, ::System::Text::StringBuilder* pchComponentName, uint unComponentNameSize); // public System.IAsyncResult BeginInvoke(System.UInt64 ulOverlayHandle, ref System.UInt32 punDeviceIndex, System.Text.StringBuilder pchComponentName, System.UInt32 unComponentNameSize, System.AsyncCallback callback, System.Object object) // Offset: 0x264121C ::System::IAsyncResult* BeginInvoke(uint64_t ulOverlayHandle, ByRef<uint> punDeviceIndex, ::System::Text::StringBuilder* pchComponentName, uint unComponentNameSize, ::System::AsyncCallback* callback, ::Il2CppObject* object); // public Valve.VR.EVROverlayError EndInvoke(ref System.UInt32 punDeviceIndex, System.IAsyncResult result) // Offset: 0x26412EC ::Valve::VR::EVROverlayError EndInvoke(ByRef<uint> punDeviceIndex, ::System::IAsyncResult* result); }; // Valve.VR.IVROverlay/Valve.VR._GetOverlayTransformTrackedDeviceComponent #pragma pack(pop) } #include "beatsaber-hook/shared/utils/il2cpp-utils-methods.hpp" // Writing MetadataGetter for method: Valve::VR::IVROverlay::_GetOverlayTransformTrackedDeviceComponent::New_ctor // Il2CppName: .ctor // Cannot get method pointer of value based method overload from template for constructor! // Try using FindMethod instead! // Writing MetadataGetter for method: Valve::VR::IVROverlay::_GetOverlayTransformTrackedDeviceComponent::Invoke // Il2CppName: Invoke template<> struct ::il2cpp_utils::il2cpp_type_check::MetadataGetter<static_cast<::Valve::VR::EVROverlayError (Valve::VR::IVROverlay::_GetOverlayTransformTrackedDeviceComponent::*)(uint64_t, ByRef<uint>, ::System::Text::StringBuilder*, uint)>(&Valve::VR::IVROverlay::_GetOverlayTransformTrackedDeviceComponent::Invoke)> { static const MethodInfo* get() { static auto* ulOverlayHandle = &::il2cpp_utils::GetClassFromName("System", "UInt64")->byval_arg; static auto* punDeviceIndex = &::il2cpp_utils::GetClassFromName("System", "UInt32")->this_arg; static auto* pchComponentName = &::il2cpp_utils::GetClassFromName("System.Text", "StringBuilder")->byval_arg; static auto* unComponentNameSize = &::il2cpp_utils::GetClassFromName("System", "UInt32")->byval_arg; return ::il2cpp_utils::FindMethod(classof(Valve::VR::IVROverlay::_GetOverlayTransformTrackedDeviceComponent*), "Invoke", std::vector<Il2CppClass*>(), ::std::vector<const Il2CppType*>{ulOverlayHandle, punDeviceIndex, pchComponentName, unComponentNameSize}); } }; // Writing MetadataGetter for method: Valve::VR::IVROverlay::_GetOverlayTransformTrackedDeviceComponent::BeginInvoke // Il2CppName: BeginInvoke template<> struct ::il2cpp_utils::il2cpp_type_check::MetadataGetter<static_cast<::System::IAsyncResult* (Valve::VR::IVROverlay::_GetOverlayTransformTrackedDeviceComponent::*)(uint64_t, ByRef<uint>, ::System::Text::StringBuilder*, uint, ::System::AsyncCallback*, ::Il2CppObject*)>(&Valve::VR::IVROverlay::_GetOverlayTransformTrackedDeviceComponent::BeginInvoke)> { static const MethodInfo* get() { static auto* ulOverlayHandle = &::il2cpp_utils::GetClassFromName("System", "UInt64")->byval_arg; static auto* punDeviceIndex = &::il2cpp_utils::GetClassFromName("System", "UInt32")->this_arg; static auto* pchComponentName = &::il2cpp_utils::GetClassFromName("System.Text", "StringBuilder")->byval_arg; static auto* unComponentNameSize = &::il2cpp_utils::GetClassFromName("System", "UInt32")->byval_arg; static auto* callback = &::il2cpp_utils::GetClassFromName("System", "AsyncCallback")->byval_arg; static auto* object = &::il2cpp_utils::GetClassFromName("System", "Object")->byval_arg; return ::il2cpp_utils::FindMethod(classof(Valve::VR::IVROverlay::_GetOverlayTransformTrackedDeviceComponent*), "BeginInvoke", std::vector<Il2CppClass*>(), ::std::vector<const Il2CppType*>{ulOverlayHandle, punDeviceIndex, pchComponentName, unComponentNameSize, callback, object}); } }; // Writing MetadataGetter for method: Valve::VR::IVROverlay::_GetOverlayTransformTrackedDeviceComponent::EndInvoke // Il2CppName: EndInvoke template<> struct ::il2cpp_utils::il2cpp_type_check::MetadataGetter<static_cast<::Valve::VR::EVROverlayError (Valve::VR::IVROverlay::_GetOverlayTransformTrackedDeviceComponent::*)(ByRef<uint>, ::System::IAsyncResult*)>(&Valve::VR::IVROverlay::_GetOverlayTransformTrackedDeviceComponent::EndInvoke)> { static const MethodInfo* get() { static auto* punDeviceIndex = &::il2cpp_utils::GetClassFromName("System", "UInt32")->this_arg; static auto* result = &::il2cpp_utils::GetClassFromName("System", "IAsyncResult")->byval_arg; return ::il2cpp_utils::FindMethod(classof(Valve::VR::IVROverlay::_GetOverlayTransformTrackedDeviceComponent*), "EndInvoke", std::vector<Il2CppClass*>(), ::std::vector<const Il2CppType*>{punDeviceIndex, result}); } };
; char *strcpy(char * restrict s1, const char * restrict s2) SECTION code_string PUBLIC strcpy EXTERN asm_strcpy strcpy: pop af pop hl pop de push de push hl push af jp asm_strcpy
// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // This file contains the implementation of the helper functions for resources. #include "gpu/command_buffer/common/resource.h" namespace gpu { namespace texture { // Gets the number of bytes per block for a given format. unsigned int GetBytesPerBlock(Format format) { switch (format) { case kXRGB8: case kARGB8: case kR32F: return 4; case kABGR16F: return 8; case kABGR32F: return 16; case kDXT1: return 8; case kUnknown: default: // TODO(petersont): Add DXT3/5 support. LOG(FATAL) << "Invalid format"; return 1; } } // Gets the width of a block for a given format. unsigned int GetBlockSizeX(Format format) { switch (format) { case kXRGB8: case kARGB8: case kABGR16F: case kR32F: case kABGR32F: return 1; case kDXT1: return 4; case kUnknown: default: // TODO(petersont): Add DXT3/5 support. LOG(FATAL) << "Invalid format"; return 1; } } // Gets the height of a block for a given format. unsigned int GetBlockSizeY(Format format) { // NOTE: currently only supported formats use square blocks. return GetBlockSizeX(format); } } // namespace texture namespace effect_param { // Gets the size of the data of a given parameter type. unsigned int GetDataSize(DataType type) { switch (type) { case kUnknown: return 0; case kFloat1: return sizeof(float); // NOLINT case kFloat2: return sizeof(float) * 2; // NOLINT case kFloat3: return sizeof(float) * 3; // NOLINT case kFloat4: return sizeof(float) * 4; // NOLINT case kMatrix4: return sizeof(float) * 16; // NOLINT case kInt: return sizeof(int); // NOLINT case kBool: return sizeof(bool); // NOLINT case kSampler: return sizeof(ResourceId); // NOLINT case kTexture: return sizeof(ResourceId); // NOLINT case kNumTypes: case kMake32Bit: default: LOG(FATAL) << "Invalid type."; return 0; } } } // namespace effect_param } // namespace gpu
; license:MIT License ; copyright-holders:Hiromasa Tanaka _music_game_over: DB 0 DW _music_game_over_trk1 DW _music_game_over_trk2 DW _music_game_over_trk3 _music_game_over_trk1: DB 201, %10, 200, 15 , 21 , 28 , 20 , 28 , 19 , 28 , 18 , 28 , 17 , 112 DB 255 _music_game_over_trk2: DB 201, %10, 200, 15 , 45 , 7 , 46 , 7 , 45 , 7 , 46 , 7 , 45 , 7 , 46 , 7 DB 45 , 7 , 46 , 7 , 45 , 7 , 46 , 7 , 45 , 7 , 46 , 7 , 45 , 7 , 46 , 7 DB 45 , 7 , 46 , 7 , 45 , 112 DB 255 _music_game_over_trk3: DB 201, %10, 200, 15 , 43 , 7 , 44 , 7 , 43 , 7 , 44 , 7 , 43 , 7 , 44 , 7 DB 43 , 7 , 44 , 7 , 43 , 7 , 44 , 7 , 43 , 7 , 44 , 7 , 43 , 7 , 44 , 7 DB 43 , 7 , 44 , 7 , 43 , 112 DB 255
SECTION code_clib SECTION code_fp_math48 PUBLIC _asin EXTERN cm48_sdcciy_asin defc _asin = cm48_sdcciy_asin
;; @file ; ; Copyright 2006 - 2010 Unified EFI, Inc.<BR> ; Copyright (c) 2010, 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: ; ; Port80.asm ; ;--*/ .code ; ; VOID ; Port80 ( ; UINT8 Number ; ) ; Abstract: Print a Hex Number to I/O 80h ; Port80 PROC mov al, cl out 80h, al ret Port80 ENDP END
; A070960: a(1) = 1; a(n) = n!*(3/2) for n>=2. ; 1,3,9,36,180,1080,7560,60480,544320,5443200,59875200,718502400,9340531200,130767436800,1961511552000,31384184832000,533531142144000,9603560558592000 mov $2,$0 mov $1,1 add $1,$2 fac $1 mul $1,3 div $1,2
SECTION code_fp_math48 PUBLIC ___fs2schar EXTERN cm48_sdccixp_ds2schar defc ___fs2schar = cm48_sdccixp_ds2schar
; A259060: Numbers that are representable in at least two ways as sums of four distinct nonvanishing cubes. ; 6426,7900,9614,11592,13858,16436,19350,22624,26282,30348,34846,39800,45234,51172,57638,64656,72250,80444,89262,98728,108866,119700,131254,143552,156618,170476,185150,200664,217042,234308,252486,271600,291674 mov $2,$0 add $0,4 mul $0,2 add $0,3 mov $3,$0 add $0,9 add $3,1 mov $1,$3 mov $4,16 mov $5,8 lpb $0,1 sub $0,1 add $1,3 add $5,$4 mov $4,$1 add $1,$3 lpe mov $1,3 add $1,$5 lpb $2,1 add $1,397 sub $2,1 lpe add $1,3549
; A032357: Convolution of Catalan numbers and powers of -1. ; Submitted by Christian Krause ; 1,0,2,3,11,31,101,328,1102,3760,13036,45750,162262,580638,2093802,7601043,27756627,101888163,375750537,1391512653,5172607767,19293659253,72188904387,270870709263,1019033438061,3842912963391,14524440108761,55009110807243,208738840943117,793503375708251,3021483126384053,11523152912842856,44010911964205342,168325218448037768,644618823701692996,2471666671205608266,9488131714654845226,36462672609966897138,140271190177039804262,540154181552935996128,2081972860723556112692,8031945730914342021328 mov $2,$0 add $2,1 mov $3,$0 lpb $2 mov $0,$3 sub $2,1 sub $0,$2 seq $0,108 ; Catalan numbers: C(n) = binomial(2n,n)/(n+1) = (2n)!/(n!(n+1)!). mul $1,-1 add $1,$0 lpe mov $0,$1
; Copyright (c) 2018 M D ; ; This software is released under the MIT License. ; https://opensource.org/licenses/MIT [extern isr_handler] [extern irq_handler] isr_common_stub: pusha mov ax, ds push eax mov ax, 0x10 mov ds, ax mov es, ax mov fs, ax mov gs, ax push esp cld call isr_handler pop eax pop eax mov ds, ax mov es, ax mov fs, ax mov gs, ax popa add esp, 8 iret irq_common_stub: pusha mov ax, ds push eax mov ax, 0x10 mov ds, ax mov es, ax mov fs, ax mov gs, ax push esp cld call irq_handler pop ebx pop ebx mov ds, bx mov es, bx mov fs, bx mov gs, bx popa add esp, 8 iret global isr0 global isr1 global isr2 global isr3 global isr4 global isr5 global isr6 global isr7 global isr8 global isr9 global isr10 global isr11 global isr12 global isr13 global isr14 global isr15 global isr16 global isr17 global isr18 global isr19 global isr20 global isr21 global isr22 global isr23 global isr24 global isr25 global isr26 global isr27 global isr28 global isr29 global isr30 global isr31 ; IRQs global irq0 global irq1 global irq2 global irq3 global irq4 global irq5 global irq6 global irq7 global irq8 global irq9 global irq10 global irq11 global irq12 global irq13 global irq14 global irq15 isr0: push byte 0 push byte 0 jmp isr_common_stub isr1: push byte 0 push byte 1 jmp isr_common_stub isr2: push byte 0 push byte 2 jmp isr_common_stub isr3: push byte 0 push byte 3 jmp isr_common_stub isr4: push byte 0 push byte 4 jmp isr_common_stub isr5: push byte 0 push byte 5 jmp isr_common_stub isr6: push byte 0 push byte 6 jmp isr_common_stub isr7: push byte 0 push byte 7 jmp isr_common_stub isr8: push byte 8 jmp isr_common_stub isr9: push byte 0 push byte 9 jmp isr_common_stub isr10: push byte 10 jmp isr_common_stub isr11: push byte 11 jmp isr_common_stub isr12: push byte 12 jmp isr_common_stub isr13: push byte 13 jmp isr_common_stub isr14: push byte 14 jmp isr_common_stub isr15: push byte 0 push byte 15 jmp isr_common_stub isr16: push byte 0 push byte 16 jmp isr_common_stub isr17: push byte 0 push byte 17 jmp isr_common_stub isr18: push byte 0 push byte 18 jmp isr_common_stub isr19: push byte 0 push byte 19 jmp isr_common_stub isr20: push byte 0 push byte 20 jmp isr_common_stub isr21: push byte 0 push byte 21 jmp isr_common_stub isr22: push byte 0 push byte 22 jmp isr_common_stub isr23: push byte 0 push byte 23 jmp isr_common_stub isr24: push byte 0 push byte 24 jmp isr_common_stub isr25: push byte 0 push byte 25 jmp isr_common_stub isr26: push byte 0 push byte 26 jmp isr_common_stub isr27: push byte 0 push byte 27 jmp isr_common_stub isr28: push byte 0 push byte 28 jmp isr_common_stub isr29: push byte 0 push byte 29 jmp isr_common_stub isr30: push byte 0 push byte 30 jmp isr_common_stub isr31: push byte 0 push byte 31 jmp isr_common_stub irq0: push byte 0 push byte 32 jmp irq_common_stub irq1: push byte 1 push byte 33 jmp irq_common_stub irq2: push byte 2 push byte 34 jmp irq_common_stub irq3: push byte 3 push byte 35 jmp irq_common_stub irq4: push byte 4 push byte 36 jmp irq_common_stub irq5: push byte 5 push byte 37 jmp irq_common_stub irq6: push byte 6 push byte 38 jmp irq_common_stub irq7: push byte 7 push byte 39 jmp irq_common_stub irq8: push byte 8 push byte 40 jmp irq_common_stub irq9: push byte 9 push byte 41 jmp irq_common_stub irq10: push byte 10 push byte 42 jmp irq_common_stub irq11: push byte 11 push byte 43 jmp irq_common_stub irq12: push byte 12 push byte 44 jmp irq_common_stub irq13: push byte 13 push byte 45 jmp irq_common_stub irq14: push byte 14 push byte 46 jmp irq_common_stub irq15: push byte 15 push byte 47 jmp irq_common_stub
; A209345: Number of 4-bead necklaces labeled with numbers -n..n allowing reversal, with sum zero with no three beads in a row equal ; 4,15,35,72,128,205,311,448,618,829,1083,1382,1734,2141,2605,3134,3730,4395,5137,5958,6860,7851,8933,10108,11384,12763,14247,15844,17556,19385,21339,23420,25630,27977,30463,33090,35866,38793,41873,45114,48518,52087,55829,59746,63840,68119,72585,77240,82092,87143,92395,97856,103528,109413,115519,121848,128402,135189,142211,149470,156974,164725,172725,180982,189498,198275,207321,216638,226228,236099,246253,256692,267424,278451,289775,301404,313340,325585,338147,351028,364230,377761,391623,405818,420354,435233,450457,466034,481966,498255,514909,531930,549320,567087,585233,603760,622676,641983,661683,681784 mov $2,$0 add $2,1 mov $6,$0 lpb $2 mov $0,$6 sub $2,1 sub $0,$2 mov $3,$0 add $3,1 mov $4,1 add $4,$0 gcd $5,$3 mul $3,$4 sub $3,1 mul $3,2 add $3,$4 sub $5,4 sub $3,$5 add $1,$3 lpe mov $0,$1
; Charging turning speed, credit goes to Colt Zero(Olivine Ellva) .org Update__16SpyroChargeStateFv+0x11C bl set_charge_speed .org end ; For crash testing ;.space 0x10000, 0xFF .global set_charge_speed set_charge_speed: stwu sp, -0x10 (sp) mflr r18 stw r18, 0x14 (sp) bl setspyrorotspeedtor18 lfs f1,0(r18) lwz r18, 0x14 (sp) mtlr r18 addi sp, sp, 0x10 blr .org end .include_cpp ./setr18value.cpp
; Tests for APU clock jitter. Also tests basic timing of frame irq flag ; since it's needed to determine jitter. .include "prefix_apu.a" jitter = 1 reset: jsr setup_apu lda #2;) Frame irq is set too soon sta result lda #$40 ; clear frame irq flag sta $4017 lda #$00 ; begin mode 0, frame irq enabled sta $4017 ldy #48 ; 29826 delay lda #123 jsr delay_ya1 lda $4015 ; read at 29830 and #$40 bne error lda #3;) Frame irq is set too late sta result lda #$40 ; clear frame irq flag sta $4017 lda #$00 ; begin mode 0, frame irq enabled sta $4017 ldy #48 ; 29828 delay lda #123 jsr delay_ya3 lda $4015 ; read at 29832 and #$40 beq error lda #4;) Even jitter not handled properly sta result jsr get_jitter sta <jitter sta <jitter ; keep on even clocks jsr get_jitter cmp <jitter bne error lda #5;) Odd jitter not handled properly sta result jsr get_jitter sta <jitter jsr get_jitter ; occurs on odd clock cmp <jitter beq error lda #1;) Passed tests sta result error: jmp report_final_result ; Return current jitter in A. Takes an even number of clocks. get_jitter: lda <0 ; make routine total an even number of clocks lda #$40 ; clear frame irq flag sta $4017 lda #$00 ; begin mode 0, frame irq enabled sta $4017 ldy #48 ; 29827 delay lda #123 jsr delay_ya2 lda $4015 ; read at 29831 and #$40 rts
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r11 push %r12 push %r13 push %r15 push %rcx push %rdi push %rsi lea addresses_normal_ht+0x152cb, %r13 dec %r12 movb $0x61, (%r13) nop sub %rsi, %rsi lea addresses_D_ht+0x9f0b, %rsi clflush (%rsi) nop nop nop add $39025, %r15 and $0xffffffffffffffc0, %rsi movntdqa (%rsi), %xmm4 vpextrq $0, %xmm4, %r11 nop nop nop nop add %r15, %r15 lea addresses_WC_ht+0x55cb, %rsi clflush (%rsi) nop nop nop add %r15, %r15 movb (%rsi), %r11b nop inc %r11 lea addresses_A_ht+0x41cb, %rsi lea addresses_A_ht+0x17b2b, %rdi and %r12, %r12 mov $17, %rcx rep movsl nop nop nop cmp $64190, %r15 lea addresses_A_ht+0xd88b, %rsi nop nop cmp $30808, %r12 mov (%rsi), %edi nop nop and %r13, %r13 lea addresses_WT_ht+0xb4b, %r11 nop nop nop nop nop dec %r15 movb $0x61, (%r11) nop nop nop nop nop dec %r11 lea addresses_A_ht+0xdbcb, %r13 nop nop nop add $44567, %rcx movw $0x6162, (%r13) cmp %r13, %r13 lea addresses_WT_ht+0x18ff, %r11 nop nop and $25780, %rcx mov $0x6162636465666768, %rsi movq %rsi, %xmm7 movups %xmm7, (%r11) nop nop nop inc %r15 lea addresses_A_ht+0xe54b, %rdi nop nop xor %r11, %r11 mov $0x6162636465666768, %rsi movq %rsi, %xmm1 movups %xmm1, (%rdi) add %rdi, %rdi lea addresses_normal_ht+0x110b, %r13 nop nop nop inc %r11 mov (%r13), %r15d xor $64566, %r10 lea addresses_A_ht+0x91cb, %rdi nop nop nop sub $63847, %r11 vmovups (%rdi), %ymm7 vextracti128 $0, %ymm7, %xmm7 vpextrq $0, %xmm7, %r13 nop nop nop cmp $32477, %r15 lea addresses_WC_ht+0xa5cb, %rsi lea addresses_A_ht+0x198fb, %rdi clflush (%rsi) nop nop cmp $53992, %r10 mov $32, %rcx rep movsw dec %rsi lea addresses_WT_ht+0xb44b, %rsi lea addresses_A_ht+0x1bb1b, %rdi nop sub $26029, %r15 mov $118, %rcx rep movsl nop nop nop nop and %r11, %r11 lea addresses_UC_ht+0x1405b, %r11 clflush (%r11) nop nop nop nop cmp %rdi, %rdi movups (%r11), %xmm6 vpextrq $1, %xmm6, %r15 nop nop and %r13, %r13 pop %rsi pop %rdi pop %rcx pop %r15 pop %r13 pop %r12 pop %r11 pop %r10 ret .global s_faulty_load s_faulty_load: push %r11 push %r8 push %rax push %rbx push %rcx push %rdi push %rsi // REPMOV lea addresses_D+0x80cb, %rsi lea addresses_normal+0x9dcb, %rdi nop nop nop nop xor %r8, %r8 mov $43, %rcx rep movsq nop nop nop nop xor %rax, %rax // Store lea addresses_A+0x139cb, %rax nop nop nop xor %rbx, %rbx mov $0x5152535455565758, %rcx movq %rcx, (%rax) nop nop nop nop xor $12804, %rcx // Store lea addresses_A+0x139cb, %r8 nop nop sub %rax, %rax movl $0x51525354, (%r8) nop and $57764, %rcx // Store lea addresses_A+0x139cb, %rcx nop nop xor $32970, %rdi movl $0x51525354, (%rcx) nop nop nop and %rbx, %rbx // Faulty Load lea addresses_A+0x139cb, %rax nop nop nop add %rdi, %rdi vmovntdqa (%rax), %ymm4 vextracti128 $0, %ymm4, %xmm4 vpextrq $1, %xmm4, %rsi lea oracles, %rdi and $0xff, %rsi shlq $12, %rsi mov (%rdi,%rsi,1), %rsi pop %rsi pop %rdi pop %rcx pop %rbx pop %rax pop %r8 pop %r11 ret /* <gen_faulty_load> [REF] {'src': {'type': 'addresses_A', 'AVXalign': False, 'size': 16, 'NT': False, 'same': False, 'congruent': 0}, 'OP': 'LOAD'} {'src': {'type': 'addresses_D', 'congruent': 8, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_normal', 'congruent': 7, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_A', 'AVXalign': False, 'size': 8, 'NT': False, 'same': True, 'congruent': 0}} {'OP': 'STOR', 'dst': {'type': 'addresses_A', 'AVXalign': False, 'size': 4, 'NT': False, 'same': True, 'congruent': 0}} {'OP': 'STOR', 'dst': {'type': 'addresses_A', 'AVXalign': False, 'size': 4, 'NT': False, 'same': True, 'congruent': 0}} [Faulty Load] {'src': {'type': 'addresses_A', 'AVXalign': False, 'size': 32, 'NT': True, 'same': True, 'congruent': 0}, 'OP': 'LOAD'} <gen_prepare_buffer> {'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'AVXalign': False, 'size': 1, 'NT': False, 'same': False, 'congruent': 6}} {'src': {'type': 'addresses_D_ht', 'AVXalign': False, 'size': 16, 'NT': True, 'same': False, 'congruent': 6}, 'OP': 'LOAD'} {'src': {'type': 'addresses_WC_ht', 'AVXalign': True, 'size': 1, 'NT': False, 'same': False, 'congruent': 9}, 'OP': 'LOAD'} {'src': {'type': 'addresses_A_ht', 'congruent': 9, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_A_ht', 'congruent': 5, 'same': False}} {'src': {'type': 'addresses_A_ht', 'AVXalign': True, 'size': 4, 'NT': True, 'same': False, 'congruent': 3}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'AVXalign': False, 'size': 1, 'NT': False, 'same': False, 'congruent': 7}} {'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'AVXalign': False, 'size': 2, 'NT': False, 'same': False, 'congruent': 9}} {'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'AVXalign': False, 'size': 16, 'NT': False, 'same': False, 'congruent': 2}} {'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'AVXalign': False, 'size': 16, 'NT': False, 'same': False, 'congruent': 6}} {'src': {'type': 'addresses_normal_ht', 'AVXalign': False, 'size': 4, 'NT': False, 'same': False, 'congruent': 6}, 'OP': 'LOAD'} {'src': {'type': 'addresses_A_ht', 'AVXalign': False, 'size': 32, 'NT': False, 'same': True, 'congruent': 10}, 'OP': 'LOAD'} {'src': {'type': 'addresses_WC_ht', 'congruent': 9, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_A_ht', 'congruent': 2, 'same': False}} {'src': {'type': 'addresses_WT_ht', 'congruent': 4, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_A_ht', 'congruent': 4, 'same': False}} {'src': {'type': 'addresses_UC_ht', 'AVXalign': False, 'size': 16, 'NT': False, 'same': False, 'congruent': 4}, 'OP': 'LOAD'} {'c3': 1, '81': 3, '2d': 1, '49': 1, '34': 1, 'a6': 1, '9c': 1, 'd7': 1, '14': 6, '02': 1, 'ff': 26, '40': 12, '75': 1, 'f5': 1, '1a': 1, '2a': 1, '92': 1, '42': 4, '46': 1, '51': 1, '82': 3, '6e': 5, '00': 21755} 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 42 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff 00 00 00 00 00 00 00 */
<% from pwnlib.shellcraft.thumb.linux import syscall %> <%page args="clock_id, res"/> <%docstring> Invokes the syscall clock_getres. See 'man 2 clock_getres' for more information. Arguments: clock_id(clockid_t): clock_id res(timespec): res </%docstring> ${syscall('SYS_clock_getres', clock_id, res)}
; A154681: Triangle read by rows where T(m,n) = 2*m*n + m + n +3. ; Submitted by Christian Krause ; 7,10,15,13,20,27,16,25,34,43,19,30,41,52,63,22,35,48,61,74,87,25,40,55,70,85,100,115,28,45,62,79,96,113,130,147,31,50,69,88,107,126,145,164,183,34,55,76,97,118,139,160,181,202,223,37,60,83,106,129,152,175,198,221,244,267,40,65,90,115,140,165,190,215,240,265,290,315,43,70,97,124,151,178,205,232,259,286,313,340,367,46,75,104,133,162,191,220,249,278 mul $0,2 add $0,1 lpb $0 mov $2,$0 sub $0,2 trn $0,$1 add $1,2 add $2,2 lpe add $1,1 mul $1,$2 mov $0,$1 div $0,2 add $0,3
%ifdef CONFIG { "RegData": { "XMM0": ["0xc0800000bf800000", "0xc2800000c1800000"] }, "MemoryRegions": { "0x100000000": "4096" } } %endif mov rdx, 0xe0000000 mov rax, 0x3f80000040000000 ; 1.0, 2.0 mov [rdx + 8 * 0], rax mov rax, 0x4080000041000000 ; 4.0, 8.0 mov [rdx + 8 * 1], rax mov rax, 0x4180000042000000 ; 16.0, 32.0 mov [rdx + 8 * 2], rax mov rax, 0x4280000043000000 ; 64.0, 128.0 mov [rdx + 8 * 3], rax movapd xmm0, [rdx] movapd xmm1, [rdx + 8 * 2] hsubps xmm0, xmm1 hlt
#include <EditorFrameworkPCH.h> #include <Core/Graphics/Camera.h> #include <EditorFramework/Assets/AssetDocument.h> #include <EditorFramework/DocumentWindow/EngineDocumentWindow.moc.h> #include <EditorFramework/DocumentWindow/EngineViewWidget.moc.h> #include <EditorFramework/Gizmos/SphereGizmo.h> #include <Foundation/Logging/Log.h> #include <Foundation/Utilities/GraphicsUtils.h> #include <QDesktopWidget> #include <QMouseEvent> EZ_BEGIN_DYNAMIC_REFLECTED_TYPE(ezSphereGizmo, 1, ezRTTINoAllocator) EZ_END_DYNAMIC_REFLECTED_TYPE; ezSphereGizmo::ezSphereGizmo() { m_bInnerEnabled = false; m_fRadiusInner = 1.0f; m_fRadiusOuter = 2.0f; m_ManipulateMode = ManipulateMode::None; m_InnerSphere.Configure(this, ezEngineGizmoHandleType::Sphere, ezColorLinearUB(200, 200, 0, 128), false, true); // this gizmo should be rendered very last so it is always on top m_OuterSphere.Configure(this, ezEngineGizmoHandleType::Sphere, ezColorLinearUB(200, 200, 200, 128), false); SetVisible(false); SetTransformation(ezTransform::IdentityTransform()); } void ezSphereGizmo::OnSetOwner(ezQtEngineDocumentWindow* pOwnerWindow, ezQtEngineViewWidget* pOwnerView) { pOwnerWindow->GetDocument()->AddSyncObject(&m_InnerSphere); pOwnerWindow->GetDocument()->AddSyncObject(&m_OuterSphere); } void ezSphereGizmo::OnVisibleChanged(bool bVisible) { m_InnerSphere.SetVisible(bVisible && m_bInnerEnabled); m_OuterSphere.SetVisible(bVisible); } void ezSphereGizmo::OnTransformationChanged(const ezTransform& transform) { ezTransform mScaleInner, mScaleOuter; mScaleInner.SetIdentity(); mScaleOuter.SetIdentity(); mScaleInner.m_vScale = ezVec3(m_fRadiusInner); mScaleOuter.m_vScale = ezVec3(m_fRadiusOuter); m_InnerSphere.SetTransformation(transform * mScaleInner); m_OuterSphere.SetTransformation(transform * mScaleOuter); } void ezSphereGizmo::DoFocusLost(bool bCancel) { ezGizmoEvent ev; ev.m_pGizmo = this; ev.m_Type = bCancel ? ezGizmoEvent::Type::CancelInteractions : ezGizmoEvent::Type::EndInteractions; m_GizmoEvents.Broadcast(ev); ezViewHighlightMsgToEngine msg; GetOwnerWindow()->GetEditorEngineConnection()->SendHighlightObjectMessage(&msg); m_InnerSphere.SetVisible(m_bInnerEnabled); m_OuterSphere.SetVisible(true); m_ManipulateMode = ManipulateMode::None; } ezEditorInput ezSphereGizmo::DoMousePressEvent(QMouseEvent* e) { if (IsActiveInputContext()) return ezEditorInput::WasExclusivelyHandled; if (e->button() != Qt::MouseButton::LeftButton) return ezEditorInput::MayBeHandledByOthers; if (e->modifiers() != 0) return ezEditorInput::MayBeHandledByOthers; if (m_pInteractionGizmoHandle == &m_InnerSphere) { m_ManipulateMode = ManipulateMode::InnerSphere; } else if (m_pInteractionGizmoHandle == &m_OuterSphere) { m_ManipulateMode = ManipulateMode::OuterSphere; } else return ezEditorInput::MayBeHandledByOthers; ezViewHighlightMsgToEngine msg; msg.m_HighlightObject = m_pInteractionGizmoHandle->GetGuid(); GetOwnerWindow()->GetEditorEngineConnection()->SendHighlightObjectMessage(&msg); // m_InnerSphere.SetVisible(false); // m_OuterSphere.SetVisible(false); // m_pInteractionGizmoHandle->SetVisible(true); m_LastInteraction = ezTime::Now(); m_LastMousePos = SetMouseMode(ezEditorInputContext::MouseMode::HideAndWrapAtScreenBorders); SetActiveInputContext(this); ezGizmoEvent ev; ev.m_pGizmo = this; ev.m_Type = ezGizmoEvent::Type::BeginInteractions; m_GizmoEvents.Broadcast(ev); return ezEditorInput::WasExclusivelyHandled; } ezEditorInput ezSphereGizmo::DoMouseReleaseEvent(QMouseEvent* e) { if (!IsActiveInputContext()) return ezEditorInput::MayBeHandledByOthers; if (e->button() != Qt::MouseButton::LeftButton) return ezEditorInput::WasExclusivelyHandled; FocusLost(false); SetActiveInputContext(nullptr); return ezEditorInput::WasExclusivelyHandled; } ezEditorInput ezSphereGizmo::DoMouseMoveEvent(QMouseEvent* e) { if (!IsActiveInputContext()) return ezEditorInput::MayBeHandledByOthers; const ezTime tNow = ezTime::Now(); if (tNow - m_LastInteraction < ezTime::Seconds(1.0 / 25.0)) return ezEditorInput::WasExclusivelyHandled; m_LastInteraction = tNow; const ezVec2I32 vNewMousePos = ezVec2I32(e->globalPos().x(), e->globalPos().y()); const ezVec2I32 vDiff = vNewMousePos - m_LastMousePos; m_LastMousePos = UpdateMouseMode(e); const float fSpeed = 0.02f; if (m_ManipulateMode == ManipulateMode::InnerSphere) { m_fRadiusInner += vDiff.x * fSpeed; m_fRadiusInner -= vDiff.y * fSpeed; m_fRadiusInner = ezMath::Max(0.0f, m_fRadiusInner); m_fRadiusOuter = ezMath::Max(m_fRadiusInner, m_fRadiusOuter); } else { m_fRadiusOuter += vDiff.x * fSpeed; m_fRadiusOuter -= vDiff.y * fSpeed; m_fRadiusOuter = ezMath::Max(0.0f, m_fRadiusOuter); m_fRadiusInner = ezMath::Min(m_fRadiusInner, m_fRadiusOuter); } // update the scale OnTransformationChanged(GetTransformation()); ezGizmoEvent ev; ev.m_pGizmo = this; ev.m_Type = ezGizmoEvent::Type::Interaction; m_GizmoEvents.Broadcast(ev); return ezEditorInput::WasExclusivelyHandled; } void ezSphereGizmo::SetInnerSphere(bool bEnabled, float fRadius) { m_fRadiusInner = fRadius; m_bInnerEnabled = bEnabled; // update the scale OnTransformationChanged(GetTransformation()); } void ezSphereGizmo::SetOuterSphere(float fRadius) { m_fRadiusOuter = fRadius; // update the scale OnTransformationChanged(GetTransformation()); }
include emu8086.inc ORG 100h MOV row, 0 GOTOXY 0, row PRINT 'Digite um numero inteiro entre 00 e 99: ' start: ADD row, 1 MOV AH, 01 INT 21h MOV BH, AL INT 21h MOV BL, AL CMP BH, 30h JB iffails JMP ifok iffails: GOTOXY 0, row PRINT 'O valor digitado eh invalido, digite novamente: ' JMP start ifok: CMP BH, 39H JA iffails CMP BL, 30h JB iffails CMP BL, 39H JA iffails GOTOXY 0, row PRINT 'O antecessor ao numero digitado eh: ' MOV AH, 02 MOV CX, BX CMP BL, 30h JNE diffx0 CMP BH, 30h JNE diff0x MOV CH, 2Dh MOV CL, 31h JMP prints diff0x: SUB CH, 1 MOV CL,39h JMP prints diffx0: SUB CL, 1 prints: ADD row, 1 MOV DL, CH INT 21h MOV DL, CL INT 21h GOTOXY 0, row PRINT 'O sucessor ao numero digitado eh: ' MOV CX, BX CMP BL, 39h JNE notx9 CMP BH, 39h JNE not9x MOV CH, 30h MOV CL, 30h MOV DL, 31h INT 21h JMP printnum not9x: ADD CH, 1 MOV CL,30h JMP printnum notx9: ADD CL, 1 printnum: ADD row, 1 MOV DL, CH INT 21h MOV DL, CL INT 21h GOTOXY 0, row PRINT 'O numero digitado foi: ' MOV DL, BH INT 21h MOV DL, BL INT 21h RET data: row DB 0
; ; ; Nim's Runtime Library ; (c) Copyright 2015 Rokas Kupstys ; ; See the file "copying.txt", included in this ; distribution, for details about the copyright. ; format MS64 COFF section ".text" executable align 16 public narch_getRegisters public narch_setjmp public narch_longjmp public narch_coroSwitchStack public narch_coroRestoreStack narch_getRegisters: mov [rcx], rax mov [rcx+8], rbx mov [rcx+10h], rcx mov [rcx+18h], rdx mov [rcx+20h], rsi mov [rcx+28h], rdi mov [rcx+30h], rbp mov [rcx+38h], rsp mov rax, [rsp] mov [rcx+40h], rax ; rip mov [rcx+48h], r8 mov [rcx+50h], r9 mov [rcx+58h], r10 mov [rcx+60h], r11 mov [rcx+68h], r12 mov [rcx+70h], r13 mov [rcx+78h], r14 mov [rcx+80h], r15 ret narch_setjmp: ; Based on code from musl libc Copyright © 2005-2014 Rich Felker, et al. mov [rcx], rbx ; rcx is jmp_buf, move registers onto it mov [rcx+8], rbp mov [rcx+10h], r12 mov [rcx+18h], r13 mov [rcx+20h], r14 mov [rcx+28h], r15 lea rdx, [rsp+8] ; this is our rsp WITHOUT current ret addr mov [rcx+30h], rdx mov rdx, [rsp] ; save return addr ptr for new rip mov [rcx+38h], rdx mov [rcx+40h], rsi mov [rcx+48h], rdi xor rax, rax ; always return 0 ret narch_longjmp: ; Based on code from musl libc Copyright © 2005-2014 Rich Felker, et al. mov rax, rdx ; val will be longjmp return test rax, rax jnz @F inc rax ; if val==0, val=1 per longjmp semantics @@: mov rbx, [rcx] ; rax is the jmp_buf, restore regs from it mov rbp, [rcx+8] mov r12, [rcx+10h] mov r13, [rcx+18h] mov r14, [rcx+20h] mov r15, [rcx+28h] mov rsp, [rcx+30h] ; this ends up being the stack pointer mov rdx, [rcx+38h] ; this is the instruction pointer jmp rdx ; goto saved address without altering rsp narch_coroSwitchStack: pop rax ; return address mov rdx, rsp ; old rsp for saving mov rsp, rcx ; swap stack with one passed to func push rdx ; store old stack pointer on newly switched stack sub rsp, 28h ; stack alignment + shadow space jmp rax ; return narch_coroRestoreStack: pop rax ; return address add rsp, 28h ; stack alignment + shadow space pop rsp ; resture old stack pointer jmp rax ; return
; A089607: a(n)=((-1)^(n+1)*A002425(n)) modulo 4. ; 1,3,1,3,3,1,1,3,3,3,1,1,3,1,1,3,3,3,1,3,3,1,1,1,3,3,1,1,3,1,1,3,3,3,1,3,3,1,1,3,3,3,1,1,3,1,1,1,3,3,1,3,3,1,1,1,3,3,1,1,3,1,1,3,3,3,1,3,3,1,1,3,3,3,1,1,3,1,1,3,3,3,1,3,3,1,1,1,3,3,1,1,3,1,1,1,3,3,1,3,3,1,1,3,3 lpb $0 add $0,1 mov $1,$0 add $1,1 div $1,2 gcd $0,$1 sub $0,1 lpe mod $1,2 mul $1,2 add $1,1
BITS 64 ;TEST_FILE_META_BEGIN ;TEST_TYPE=TEST_F ;TEST_IGNOREFLAGS= ;TEST_FILE_META_END ; DEC16r mov dx, 0x30 ;TEST_BEGIN_RECORDING dec dx ;TEST_END_RECORDING
; A266811: Total number of ON (black) cells after n iterations of the "Rule 62" elementary cellular automaton starting with a single ON (black) cell. ; Submitted by Christian Krause ; 1,4,7,13,18,26,35,45,55,69,82,97,113,131,149,170,190,213,237,262,287,316,344,374,405,438,471,507,542,580,619,659,699,743,786,831,877,925,973,1024,1074,1127,1181,1236,1291,1350,1408,1468,1529,1592,1655,1721,1786,1854,1923,1993,2063,2137,2210,2285,2361,2439,2517,2598,2678,2761,2845,2930,3015,3104,3192,3282,3373,3466,3559,3655,3750,3848,3947,4047,4147,4251,4354,4459,4565,4673,4781,4892,5002,5115,5229,5344,5459,5578,5696,5816,5937,6060,6183,6309 lpb $0 mov $2,$0 sub $0,1 seq $2,71047 ; Number of 1's in n-th row of triangle in A071031, cellular automaton "rule 62". add $1,$2 lpe mov $0,$1 add $0,1
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r12 push %r8 push %rax push %rcx push %rdi push %rdx push %rsi lea addresses_WT_ht+0x67ff, %rcx clflush (%rcx) nop nop sub %r12, %r12 movb (%rcx), %al nop nop xor %rax, %rax lea addresses_WT_ht+0x16867, %rsi lea addresses_A_ht+0xd027, %rdi nop nop nop nop add %rdx, %rdx mov $75, %rcx rep movsl nop nop nop nop nop cmp %rax, %rax lea addresses_WC_ht+0x827, %rsi nop xor $28897, %r8 movups (%rsi), %xmm7 vpextrq $1, %xmm7, %rcx nop nop nop nop nop cmp $60148, %r8 lea addresses_A_ht+0x16967, %rsi lea addresses_D_ht+0xe827, %rdi nop and $42409, %r10 mov $103, %rcx rep movsq nop nop nop cmp $5113, %rdx pop %rsi pop %rdx pop %rdi pop %rcx pop %rax pop %r8 pop %r12 pop %r10 ret .global s_faulty_load s_faulty_load: push %r12 push %r13 push %r15 push %r8 push %rax push %rcx push %rsi // Load lea addresses_normal+0x18c07, %r15 nop nop nop mfence vmovups (%r15), %ymm7 vextracti128 $0, %ymm7, %xmm7 vpextrq $0, %xmm7, %r12 and $16183, %rsi // Store lea addresses_WT+0x83e7, %r12 nop nop and $43252, %rax movl $0x51525354, (%r12) nop sub $4575, %r15 // Store mov $0xd02, %r15 nop nop nop nop and $6257, %r13 mov $0x5152535455565758, %rsi movq %rsi, %xmm1 vmovaps %ymm1, (%r15) add %r12, %r12 // Store lea addresses_PSE+0x1d027, %r8 dec %r15 mov $0x5152535455565758, %rax movq %rax, %xmm4 vmovups %ymm4, (%r8) xor %r15, %r15 // Store lea addresses_WC+0x6027, %rsi clflush (%rsi) nop nop nop and $25059, %r12 movl $0x51525354, (%rsi) nop inc %rcx // Store lea addresses_US+0x2c3, %r8 nop nop and $53178, %rsi mov $0x5152535455565758, %r12 movq %r12, (%r8) nop nop sub $37192, %rsi // Store lea addresses_US+0x1f847, %r13 nop nop nop nop cmp %r8, %r8 mov $0x5152535455565758, %rcx movq %rcx, %xmm4 vmovups %ymm4, (%r13) nop nop nop nop add $15626, %rcx // Faulty Load lea addresses_WC+0x6027, %r8 nop and %rsi, %rsi vmovntdqa (%r8), %ymm0 vextracti128 $1, %ymm0, %xmm0 vpextrq $0, %xmm0, %rcx lea oracles, %rax and $0xff, %rcx shlq $12, %rcx mov (%rax,%rcx,1), %rcx pop %rsi pop %rcx pop %rax pop %r8 pop %r15 pop %r13 pop %r12 ret /* <gen_faulty_load> [REF] {'src': {'same': False, 'congruent': 0, 'NT': False, 'type': 'addresses_WC', 'size': 16, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'same': False, 'congruent': 3, 'NT': False, 'type': 'addresses_normal', 'size': 32, 'AVXalign': False}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'same': False, 'congruent': 3, 'NT': False, 'type': 'addresses_WT', 'size': 4, 'AVXalign': False}} {'OP': 'STOR', 'dst': {'same': False, 'congruent': 0, 'NT': True, 'type': 'addresses_P', 'size': 32, 'AVXalign': True}} {'OP': 'STOR', 'dst': {'same': False, 'congruent': 10, 'NT': False, 'type': 'addresses_PSE', 'size': 32, 'AVXalign': False}} {'OP': 'STOR', 'dst': {'same': True, 'congruent': 0, 'NT': False, 'type': 'addresses_WC', 'size': 4, 'AVXalign': False}} {'OP': 'STOR', 'dst': {'same': False, 'congruent': 1, 'NT': False, 'type': 'addresses_US', 'size': 8, 'AVXalign': False}} {'OP': 'STOR', 'dst': {'same': False, 'congruent': 5, 'NT': False, 'type': 'addresses_US', 'size': 32, 'AVXalign': False}} [Faulty Load] {'src': {'same': True, 'congruent': 0, 'NT': True, 'type': 'addresses_WC', 'size': 32, 'AVXalign': False}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'same': False, 'congruent': 3, 'NT': False, 'type': 'addresses_WT_ht', 'size': 1, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_WT_ht', 'congruent': 5, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_A_ht', 'congruent': 11, 'same': False}} {'src': {'same': False, 'congruent': 8, 'NT': False, 'type': 'addresses_WC_ht', 'size': 16, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_A_ht', 'congruent': 6, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_D_ht', 'congruent': 8, 'same': False}} {'00': 517} 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 */
/* +----------------------------------------------------------------------+ | Swoole | +----------------------------------------------------------------------+ | This source file is subject to version 2.0 of the Apache license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.apache.org/licenses/LICENSE-2.0.html | | If you did not receive a copy of the Apache2.0 license and are unable| | to obtain it through the world-wide-web, please send a note to | | license@swoole.com so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Tianfeng Han <mikan.tenny@gmail.com> | +----------------------------------------------------------------------+ */ #include "php_swoole_cxx.h" #include "swoole_http.h" extern "C" { #include "ext/standard/url.h" #include "ext/standard/sha1.h" #include "ext/standard/php_var.h" #include "ext/standard/php_string.h" #include "ext/standard/php_math.h" #include "ext/standard/php_array.h" #include "ext/date/php_date.h" #include "ext/standard/md5.h" } #include "main/rfc1867.h" #include "main/php_variables.h" #include "websocket.h" #include "connection.h" #include "base64.h" #ifdef SW_HAVE_ZLIB #include <zlib.h> #endif #ifdef SW_HAVE_BROTLI #include <brotli/encode.h> #endif #ifdef SW_USE_HTTP2 #include "http2.h" #endif enum http_upload_errno { HTTP_UPLOAD_ERR_OK = 0, HTTP_UPLOAD_ERR_INI_SIZE, HTTP_UPLOAD_ERR_FORM_SIZE, HTTP_UPLOAD_ERR_PARTIAL, HTTP_UPLOAD_ERR_NO_FILE, HTTP_UPLOAD_ERR_NO_TMP_DIR = 6, HTTP_UPLOAD_ERR_CANT_WRITE, }; zend_class_entry *swoole_http_request_ce; static zend_object_handlers swoole_http_request_handlers; static PHP_METHOD(swoole_http_request, getData); static PHP_METHOD(swoole_http_request, rawContent); static PHP_METHOD(swoole_http_request, __destruct); static int http_request_on_path(swoole_http_parser *parser, const char *at, size_t length); static int http_request_on_query_string(swoole_http_parser *parser, const char *at, size_t length); static int http_request_on_body(swoole_http_parser *parser, const char *at, size_t length); static int http_request_on_header_field(swoole_http_parser *parser, const char *at, size_t length); static int http_request_on_header_value(swoole_http_parser *parser, const char *at, size_t length); static int http_request_on_headers_complete(swoole_http_parser *parser); static int http_request_message_complete(swoole_http_parser *parser); static int multipart_body_on_header_field(multipart_parser* p, const char *at, size_t length); static int multipart_body_on_header_value(multipart_parser* p, const char *at, size_t length); static int multipart_body_on_data(multipart_parser* p, const char *at, size_t length); static int multipart_body_on_header_complete(multipart_parser* p); static int multipart_body_on_data_end(multipart_parser* p); static int http_request_on_path(swoole_http_parser *parser, const char *at, size_t length) { http_context *ctx = (http_context *) parser->data; ctx->request.path = estrndup(at, length); ctx->request.path_len = length; return 0; } static inline char* http_trim_double_quote(char *ptr, int *len) { int i; char *tmp = ptr; //ltrim('"') for (i = 0; i < *len; i++) { if (tmp[0] == '"') { (*len)--; tmp++; continue; } else { break; } } //rtrim('"') for (i = (*len) - 1; i >= 0; i--) { if (tmp[i] == '"') { tmp[i] = 0; (*len)--; continue; } else { break; } } return tmp; } static sw_inline const char* http_get_method_name(int method) { switch (method) { case PHP_HTTP_GET: return "GET"; case PHP_HTTP_POST: return "POST"; case PHP_HTTP_HEAD: return "HEAD"; case PHP_HTTP_PUT: return "PUT"; case PHP_HTTP_DELETE: return "DELETE"; case PHP_HTTP_PATCH: return "PATCH"; case PHP_HTTP_CONNECT: return "CONNECT"; case PHP_HTTP_OPTIONS: return "OPTIONS"; case PHP_HTTP_TRACE: return "TRACE"; case PHP_HTTP_COPY: return "COPY"; case PHP_HTTP_LOCK: return "LOCK"; case PHP_HTTP_MKCOL: return "MKCOL"; case PHP_HTTP_MOVE: return "MOVE"; case PHP_HTTP_PROPFIND: return "PROPFIND"; case PHP_HTTP_PROPPATCH: return "PROPPATCH"; case PHP_HTTP_UNLOCK: return "UNLOCK"; /* subversion */ case PHP_HTTP_REPORT: return "REPORT"; case PHP_HTTP_MKACTIVITY: return "MKACTIVITY"; case PHP_HTTP_CHECKOUT: return "CHECKOUT"; case PHP_HTTP_MERGE: return "MERGE"; /* upnp */ case PHP_HTTP_MSEARCH: return "MSEARCH"; case PHP_HTTP_NOTIFY: return "NOTIFY"; case PHP_HTTP_SUBSCRIBE: return "SUBSCRIBE"; case PHP_HTTP_UNSUBSCRIBE: return "UNSUBSCRIBE"; case PHP_HTTP_NOT_IMPLEMENTED: return "IMPLEMENTED"; default: return NULL; } } ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_http_void, 0, 0, 0) ZEND_END_ARG_INFO() const zend_function_entry swoole_http_request_methods[] = { PHP_ME(swoole_http_request, rawContent, arginfo_swoole_http_void, ZEND_ACC_PUBLIC) PHP_ME(swoole_http_request, getData, arginfo_swoole_http_void, ZEND_ACC_PUBLIC) PHP_ME(swoole_http_request, __destruct, arginfo_swoole_http_void, ZEND_ACC_PUBLIC) PHP_FE_END }; static const swoole_http_parser_settings http_parser_settings = { NULL, http_request_on_path, http_request_on_query_string, NULL, NULL, http_request_on_header_field, http_request_on_header_value, http_request_on_headers_complete, http_request_on_body, http_request_message_complete }; static const multipart_parser_settings mt_parser_settings = { multipart_body_on_header_field, multipart_body_on_header_value, multipart_body_on_data, NULL, multipart_body_on_header_complete, multipart_body_on_data_end, NULL, }; size_t swoole_http_requset_parse(http_context *ctx, const char *data, size_t length) { return swoole_http_parser_execute(&ctx->parser, &http_parser_settings, data, length); } void swoole_http_request_init(int module_number) { SW_INIT_CLASS_ENTRY(swoole_http_request, "Swoole\\Http\\Request", "swoole_http_request", NULL, swoole_http_request_methods); SW_SET_CLASS_SERIALIZABLE(swoole_http_request, zend_class_serialize_deny, zend_class_unserialize_deny); SW_SET_CLASS_CLONEABLE(swoole_http_request, zend_class_clone_deny); SW_SET_CLASS_UNSET_PROPERTY_HANDLER(swoole_http_request, sw_zend_class_unset_property_deny); SW_SET_CLASS_CREATE_WITH_ITS_OWN_HANDLERS(swoole_http_request); zend_declare_property_long(swoole_http_request_ce, ZEND_STRL("fd"), 0, ZEND_ACC_PUBLIC); #ifdef SW_USE_HTTP2 zend_declare_property_long(swoole_http_request_ce, ZEND_STRL("streamId"), 0, ZEND_ACC_PUBLIC); #endif zend_declare_property_null(swoole_http_request_ce, ZEND_STRL("header"), ZEND_ACC_PUBLIC); zend_declare_property_null(swoole_http_request_ce, ZEND_STRL("server"), ZEND_ACC_PUBLIC); zend_declare_property_null(swoole_http_request_ce, ZEND_STRL("request"), ZEND_ACC_PUBLIC); zend_declare_property_null(swoole_http_request_ce, ZEND_STRL("cookie"), ZEND_ACC_PUBLIC); zend_declare_property_null(swoole_http_request_ce, ZEND_STRL("get"), ZEND_ACC_PUBLIC); zend_declare_property_null(swoole_http_request_ce, ZEND_STRL("files"), ZEND_ACC_PUBLIC); zend_declare_property_null(swoole_http_request_ce, ZEND_STRL("post"), ZEND_ACC_PUBLIC); zend_declare_property_null(swoole_http_request_ce, ZEND_STRL("tmpfiles"), ZEND_ACC_PUBLIC); } static int http_request_on_query_string(swoole_http_parser *parser, const char *at, size_t length) { http_context *ctx = (http_context *) parser->data; add_assoc_stringl_ex(ctx->request.zserver, ZEND_STRL("query_string"), (char *) at, length); //parse url params sapi_module.treat_data( PARSE_STRING, estrndup(at, length), // it will be freed by treat_data swoole_http_init_and_read_property(swoole_http_request_ce, ctx->request.zobject, &ctx->request.zget, ZEND_STRL("get")) ); return 0; } static int http_request_on_header_field(swoole_http_parser *parser, const char *at, size_t length) { http_context *ctx = (http_context *) parser->data; ctx->current_header_name = (char *) at; ctx->current_header_name_len = length; return 0; } int swoole_http_parse_form_data(http_context *ctx, const char *boundary_str, int boundary_len) { multipart_parser *mt_parser = multipart_parser_init(boundary_str, boundary_len, &mt_parser_settings); if (!mt_parser) { swoole_php_fatal_error(E_WARNING, "multipart_parser_init() failed"); return SW_ERR; } ctx->mt_parser = mt_parser; mt_parser->data = ctx; return SW_OK; } void swoole_http_parse_cookie(zval *zarray, const char *at, size_t length) { char keybuf[SW_HTTP_COOKIE_KEYLEN]; char valbuf[SW_HTTP_COOKIE_VALLEN]; char *_c = (char *) at; char *_value; int klen = 0; int vlen = 0; int state = -1; int i = 0, j = 0; while (_c < at + length) { if (state <= 0 && *_c == '=') { klen = i - j + 1; if (klen >= SW_HTTP_COOKIE_KEYLEN) { swWarn("cookie[%.*s...] name length %d is exceed the max name len %d", 8, (char *) at + j, klen, SW_HTTP_COOKIE_KEYLEN); return; } memcpy(keybuf, (char *) at + j, klen - 1); keybuf[klen - 1] = 0; j = i + 1; state = 1; } else if (state == 1 && *_c == ';') { vlen = i - j; if (vlen >= SW_HTTP_COOKIE_VALLEN) { swWarn("cookie[%s]'s value[v=%.*s...] length %d is exceed the max value len %d", keybuf, 8, (char *) at + j, vlen, SW_HTTP_COOKIE_VALLEN); return; } memcpy(valbuf, (char *) at + j, vlen); valbuf[vlen] = 0; _value = http_trim_double_quote(valbuf, &vlen); vlen = php_url_decode(_value, vlen); if (klen > 1) { add_assoc_stringl_ex(zarray, keybuf, klen - 1, _value, vlen); } j = i + 1; state = -1; } else if (state < 0) { if (isspace(*_c)) { //Remove leading spaces from cookie names j++; } else { state = 0; } } _c++; i++; } if (j < (off_t) length) { vlen = i - j; if (klen >= SW_HTTP_COOKIE_KEYLEN) { swWarn("cookie[%.*s...] name length %d is exceed the max name len %d", 8, keybuf, klen, SW_HTTP_COOKIE_KEYLEN); return; } keybuf[klen - 1] = 0; if (vlen >= SW_HTTP_COOKIE_VALLEN) { swWarn("cookie[%s]'s value[v=%.*s...] length %d is exceed the max value len %d", keybuf, 8, (char *) at + j, vlen, SW_HTTP_COOKIE_VALLEN); return; } memcpy(valbuf, (char *) at + j, vlen); valbuf[vlen] = 0; _value = http_trim_double_quote(valbuf, &vlen); vlen = php_url_decode(_value, vlen); if (klen > 1) { add_assoc_stringl_ex(zarray, keybuf, klen - 1, _value, vlen); } } } static int http_request_on_header_value(swoole_http_parser *parser, const char *at, size_t length) { size_t offset = 0; http_context *ctx = (http_context *) parser->data; zval *zheader = ctx->request.zheader; size_t header_len = ctx->current_header_name_len; char *header_name = zend_str_tolower_dup(ctx->current_header_name, header_len); if (ctx->parse_cookie && strncmp(header_name, "cookie", header_len) == 0) { zval *zcookie = swoole_http_init_and_read_property(swoole_http_request_ce, ctx->request.zobject, &ctx->request.zcookie, ZEND_STRL("cookie")); swoole_http_parse_cookie(zcookie, at, length); efree(header_name); return 0; } else if (strncmp(header_name, "upgrade", header_len) == 0 && strncasecmp(at, "websocket", length) == 0) { ctx->websocket = 1; if (ctx->co_socket) { return 0; } swServer *serv = (swServer *) ctx->private_data; swConnection *conn = swWorker_get_connection(serv, ctx->fd); if (!conn) { swWarn("connection[%d] is closed", ctx->fd); return SW_ERR; } swListenPort *port = (swListenPort *) serv->connection_list[conn->server_fd].object; if (port->open_websocket_protocol) { conn->websocket_status = WEBSOCKET_STATUS_CONNECTION; } } else if (parser->method == PHP_HTTP_POST || parser->method == PHP_HTTP_PUT || parser->method == PHP_HTTP_DELETE || parser->method == PHP_HTTP_PATCH) { if (strncmp(header_name, "content-type", header_len) == 0) { if (http_strncasecmp("application/x-www-form-urlencoded", at, length)) { ctx->request.post_form_urlencoded = 1; } else if (http_strncasecmp("multipart/form-data", at, length)) { // start offset offset = sizeof("multipart/form-data;") - 1; while (at[offset] == ' ') { offset++; } offset += sizeof("boundary=") - 1; int boundary_len = length - offset; char *boundary_str = (char *) at + offset; // find ';' char *tmp = (char*) memchr(boundary_str, ';', boundary_len); if (tmp) { boundary_len = tmp - boundary_str; } if (boundary_len <= 0) { swWarn("invalid multipart/form-data body fd:%d", ctx->fd); return 0; } // trim '"' if (boundary_len >= 2 && boundary_str[0] == '"' && *(boundary_str + boundary_len - 1) == '"') { boundary_str++; boundary_len -= 2; } swTraceLog(SW_TRACE_HTTP, "form_data, boundary_str=%s", boundary_str); swoole_http_parse_form_data(ctx, boundary_str, boundary_len); } } } #ifdef SW_HAVE_ZLIB else if (ctx->enable_compression && strncmp(header_name, "accept-encoding", header_len) == 0) { swoole_http_get_compression_method(ctx, at, length); } #endif add_assoc_stringl_ex(zheader, header_name, header_len, (char *) at, length); efree(header_name); return 0; } static int http_request_on_headers_complete(swoole_http_parser *parser) { http_context *ctx = (http_context *) parser->data; ctx->current_header_name = NULL; return 0; } static int multipart_body_on_header_field(multipart_parser* p, const char *at, size_t length) { http_context *ctx = (http_context *) p->data; return http_request_on_header_field(&ctx->parser, at, length); } static int multipart_body_on_header_value(multipart_parser* p, const char *at, size_t length) { char value_buf[SW_HTTP_COOKIE_KEYLEN]; int value_len; http_context *ctx = (http_context *) p->data; /** * Hash collision attack */ if (ctx->input_var_num > PG(max_input_vars)) { swoole_php_error(E_WARNING, "Input variables exceeded " ZEND_LONG_FMT ". " "To increase the limit change max_input_vars in php.ini", PG(max_input_vars)); return SW_OK; } else { ctx->input_var_num++; } size_t header_len = ctx->current_header_name_len; char *headername = zend_str_tolower_dup(ctx->current_header_name, header_len); if (strncasecmp(headername, "content-disposition", header_len) == 0) { //not form data if (swoole_strnpos((char *) at, length, (char *) ZEND_STRL("form-data;")) < 0) { return SW_OK; } zval tmp_array; array_init(&tmp_array); swoole_http_parse_cookie(&tmp_array, (char *) at + sizeof("form-data;") - 1, length - sizeof("form-data;") + 1); zval *zform_name; if (!(zform_name = zend_hash_str_find(Z_ARRVAL(tmp_array), ZEND_STRL("name")))) { return SW_OK; } if (Z_STRLEN_P(zform_name) >= SW_HTTP_COOKIE_KEYLEN) { swWarn("form_name[%s] is too large", Z_STRVAL_P(zform_name)); return SW_OK; } strncpy(value_buf, Z_STRVAL_P(zform_name), Z_STRLEN_P(zform_name)); value_len = Z_STRLEN_P(zform_name); char *tmp = http_trim_double_quote(value_buf, &value_len); zval *zfilename; //POST form data if (!(zfilename = zend_hash_str_find(Z_ARRVAL(tmp_array), ZEND_STRL("filename")))) { ctx->current_form_data_name = estrndup(tmp, value_len); ctx->current_form_data_name_len = value_len; } //upload file else { if (Z_STRLEN_P(zfilename) >= SW_HTTP_COOKIE_KEYLEN) { swWarn("filename[%s] is too large", Z_STRVAL_P(zfilename)); return SW_OK; } ctx->current_input_name = estrndup(tmp, value_len); zval *z_multipart_header = sw_malloc_zval(); array_init(z_multipart_header); add_assoc_string(z_multipart_header, "name", (char *) ""); add_assoc_string(z_multipart_header, "type", (char *) ""); add_assoc_string(z_multipart_header, "tmp_name", (char *) ""); add_assoc_long(z_multipart_header, "error", HTTP_UPLOAD_ERR_OK); add_assoc_long(z_multipart_header, "size", 0); strncpy(value_buf, Z_STRVAL_P(zfilename), Z_STRLEN_P(zfilename)); value_len = Z_STRLEN_P(zfilename); tmp = http_trim_double_quote(value_buf, &value_len); add_assoc_stringl(z_multipart_header, "name", tmp, value_len); ctx->current_multipart_header = z_multipart_header; } zval_ptr_dtor(&tmp_array); } if (strncasecmp(headername, "content-type", header_len) == 0 && ctx->current_multipart_header) { add_assoc_stringl(ctx->current_multipart_header, "type", (char * ) at, length); } efree(headername); return 0; } static int multipart_body_on_data(multipart_parser* p, const char *at, size_t length) { http_context *ctx = (http_context *) p->data; if (ctx->current_form_data_name) { swString_append_ptr(swoole_http_form_data_buffer, (char*) at, length); return 0; } if (p->fp == NULL) { return 0; } int n = fwrite(at, sizeof(char), length, (FILE *) p->fp); if (n != (off_t) length) { zval *z_multipart_header = ctx->current_multipart_header; add_assoc_long(z_multipart_header, "error", HTTP_UPLOAD_ERR_CANT_WRITE); fclose((FILE *) p->fp); p->fp = NULL; swSysWarn("write upload file failed"); } return 0; } #if 0 static void get_random_file_name(char *des, const char *src) { unsigned char digest[16] = {0}; char buf[19] = {0}; int n = sprintf(buf, "%s%d", src, swoole_system_random(0, 9999)); PHP_MD5_CTX ctx; PHP_MD5Init(&ctx); PHP_MD5Update(&ctx, buf, n); PHP_MD5Final(digest, &ctx); make_digest_ex(des, digest, 16); } #endif static int multipart_body_on_header_complete(multipart_parser* p) { http_context *ctx = (http_context *) p->data; if (!ctx->current_input_name) { return 0; } zval *z_multipart_header = ctx->current_multipart_header; zval *zerr = NULL; if (!(zerr = zend_hash_str_find(Z_ARRVAL_P(z_multipart_header), ZEND_STRL("error")))) { return 0; } if (Z_TYPE_P(zerr) == IS_LONG && Z_LVAL_P(zerr) != HTTP_UPLOAD_ERR_OK) { return 0; } char file_path[SW_HTTP_UPLOAD_TMPDIR_SIZE]; snprintf(file_path, SW_HTTP_UPLOAD_TMPDIR_SIZE, "%s/swoole.upfile.XXXXXX", ctx->upload_tmp_dir); int tmpfile = swoole_tmpfile(file_path); if (tmpfile < 0) { return 0; } FILE *fp = fdopen(tmpfile, "wb+"); if (fp == NULL) { add_assoc_long(z_multipart_header, "error", HTTP_UPLOAD_ERR_NO_TMP_DIR); swSysWarn("fopen(%s) failed", file_path); return 0; } p->fp = fp; add_assoc_string(z_multipart_header, "tmp_name", file_path); size_t file_path_len = strlen(file_path); add_next_index_stringl( swoole_http_init_and_read_property(swoole_http_request_ce, ctx->request.zobject, &ctx->request.ztmpfiles, ZEND_STRL("tmpfiles")), file_path, file_path_len ); // support is_upload_file zend_hash_str_add_ptr(SG(rfc1867_uploaded_files), file_path, file_path_len, (char *) file_path); return 0; } static int multipart_body_on_data_end(multipart_parser* p) { http_context *ctx = (http_context *) p->data; if (ctx->current_form_data_name) { php_register_variable_safe( ctx->current_form_data_name, swoole_http_form_data_buffer->str, swoole_http_form_data_buffer->length, swoole_http_init_and_read_property(swoole_http_request_ce, ctx->request.zobject, &ctx->request.zpost, ZEND_STRL("post")) ); efree(ctx->current_form_data_name); ctx->current_form_data_name = NULL; ctx->current_form_data_name_len = 0; swString_clear(swoole_http_form_data_buffer); return 0; } if (!ctx->current_input_name) { return 0; } zval *z_multipart_header = ctx->current_multipart_header; if (p->fp != NULL) { long size = swoole_file_get_size((FILE *) p->fp); add_assoc_long(z_multipart_header, "size", size); if (size == 0) { add_assoc_long(z_multipart_header, "error", HTTP_UPLOAD_ERR_NO_FILE); } fclose((FILE *) p->fp); p->fp = NULL; } php_register_variable_ex( ctx->current_input_name, z_multipart_header, swoole_http_init_and_read_property(swoole_http_request_ce, ctx->request.zobject, &ctx->request.zfiles, ZEND_STRL("files")) ); efree(ctx->current_input_name); ctx->current_input_name = NULL; efree(ctx->current_multipart_header); ctx->current_multipart_header = NULL; return 0; } static int http_request_on_body(swoole_http_parser *parser, const char *at, size_t length) { http_context *ctx = (http_context *) parser->data; ctx->request.post_length = length; swTraceLog(SW_TRACE_HTTP, "length=%ld", length); if (ctx->parse_body && ctx->request.post_form_urlencoded) { sapi_module.treat_data( PARSE_STRING, estrndup(at, length), // do not free, it will be freed by treat_data swoole_http_init_and_read_property(swoole_http_request_ce, ctx->request.zobject, &ctx->request.zpost, ZEND_STRL("post")) ); } else if (ctx->mt_parser != NULL) { multipart_parser *multipart_parser = ctx->mt_parser; char *c = (char *) at; while (*c == '\r' && *(c + 1) == '\n') { c += 2; length -= 2; } size_t n = multipart_parser_execute(multipart_parser, c, length); if (n != length) { swoole_error_log(SW_LOG_WARNING, SW_ERROR_SERVER_INVALID_REQUEST, "parse multipart body failed, n=%zu", n); } } return 0; } static int http_request_message_complete(swoole_http_parser *parser) { http_context *ctx = (http_context *) parser->data; ctx->request.version = parser->http_major * 100 + parser->http_minor; const char *vpath = ctx->request.path, *end = vpath + ctx->request.path_len, *p = end; ctx->request.ext = end; ctx->request.ext_len = 0; while (p > vpath) { --p; if (*p == '.') { ++p; ctx->request.ext = p; ctx->request.ext_len = end - p; break; } } if (ctx->mt_parser) { multipart_parser_free(ctx->mt_parser); ctx->mt_parser = NULL; } zval *zserver = ctx->request.zserver; add_assoc_string(zserver, "request_method", (char *) http_get_method_name(parser->method)); add_assoc_stringl_ex(zserver, ZEND_STRL("request_uri"), ctx->request.path, ctx->request.path_len); // path_info should be decoded zend_string * zstr_path = zend_string_init(ctx->request.path, ctx->request.path_len, 0); ZSTR_LEN(zstr_path) = php_url_decode(ZSTR_VAL(zstr_path), ZSTR_LEN(zstr_path)); add_assoc_str_ex(zserver, ZEND_STRL("path_info"), zstr_path); add_assoc_long_ex(zserver, ZEND_STRL("request_time"), time(NULL)); add_assoc_double_ex(zserver, ZEND_STRL("request_time_float"), swoole_microtime()); add_assoc_string(zserver, "server_protocol", (char *) (ctx->request.version == 101 ? "HTTP/1.1" : "HTTP/1.0")); ctx->keepalive = swoole_http_should_keep_alive(parser); ctx->completed = 1; return 0; } #ifdef SW_HAVE_ZLIB void swoole_http_get_compression_method(http_context *ctx, const char *accept_encoding, size_t length) { #ifdef SW_HAVE_BROTLI if (swoole_strnpos((char *) accept_encoding, length, (char *) ZEND_STRL("br")) >= 0) { ctx->accept_compression = 1; ctx->compression_method = HTTP_COMPRESS_BR; } else #endif if (swoole_strnpos((char *) accept_encoding, length, (char *) ZEND_STRL("gzip")) >= 0) { ctx->accept_compression = 1; ctx->compression_method = HTTP_COMPRESS_GZIP; } else if (swoole_strnpos((char *) accept_encoding, length, (char *) ZEND_STRL("deflate")) >= 0) { ctx->accept_compression = 1; ctx->compression_method = HTTP_COMPRESS_DEFLATE; } else { ctx->accept_compression = 0; } } const char* swoole_http_get_content_encoding(http_context *ctx) { if (ctx->compression_method == HTTP_COMPRESS_GZIP) { return "gzip"; } else if (ctx->compression_method == HTTP_COMPRESS_DEFLATE) { return "deflate"; } #ifdef SW_HAVE_BROTLI else if (ctx->compression_method == HTTP_COMPRESS_BR) { return "br"; } #endif else { return NULL; } } #endif static PHP_METHOD(swoole_http_request, rawContent) { http_context *ctx = swoole_http_context_get(getThis(), 0); if (UNEXPECTED(!ctx)) { RETURN_FALSE; } http_request *req = &ctx->request; if (req->post_length > 0) { zval *zdata = (zval *) swoole_get_property(getThis(), 0); RETVAL_STRINGL(Z_STRVAL_P(zdata) + Z_STRLEN_P(zdata) - req->post_length, req->post_length); } #ifdef SW_USE_HTTP2 else if (req->post_buffer) { RETVAL_STRINGL(req->post_buffer->str, req->post_buffer->length); } #endif else { RETURN_EMPTY_STRING(); } } static PHP_METHOD(swoole_http_request, getData) { zval *zdata = (zval *) swoole_get_property(getThis(), 0); if (zdata) { RETURN_STRINGL(Z_STRVAL_P(zdata), Z_STRLEN_P(zdata)); } else { RETURN_FALSE; } } static PHP_METHOD(swoole_http_request, __destruct) { SW_PREVENT_USER_DESTRUCT(); zval *ztmpfiles = sw_zend_read_property(swoole_http_request_ce, getThis(), ZEND_STRL("tmpfiles"), 0); //upload files if (ztmpfiles && ZVAL_IS_ARRAY(ztmpfiles)) { zval *z_file_path; SW_HASHTABLE_FOREACH_START(Z_ARRVAL_P(ztmpfiles), z_file_path) { if (Z_TYPE_P(z_file_path) != IS_STRING) { continue; } unlink(Z_STRVAL_P(z_file_path)); if (SG(rfc1867_uploaded_files)) { zend_hash_str_del(SG(rfc1867_uploaded_files), Z_STRVAL_P(z_file_path), Z_STRLEN_P(z_file_path)); } } SW_HASHTABLE_FOREACH_END(); } zval *zdata = (zval *) swoole_get_property(getThis(), 0); if (zdata) { sw_zval_free(zdata); swoole_set_property(getThis(), 0, NULL); } swoole_set_object(getThis(), NULL); }
ldl $1 xor r1,r1,r1 nop r0,r0,r0 add r7,r0,r0 nop r0,r0,r0 add r7,r0,r0 nop r0,r0,r0 add r7,r0,r0 nop r0,r0,r0 add r7,r0,r0 nop r0,r0,r0 ldl $100 lsr r1,r7,r0 push r0,r0,r0 hlt
/* * Copyright 2009-2017 Alibaba Cloud 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 <alibabacloud/emr/model/ListEmrAvailableResourceRequest.h> using AlibabaCloud::Emr::Model::ListEmrAvailableResourceRequest; ListEmrAvailableResourceRequest::ListEmrAvailableResourceRequest() : RpcServiceRequest("emr", "2016-04-08", "ListEmrAvailableResource") { setMethod(HttpRequest::Method::Post); } ListEmrAvailableResourceRequest::~ListEmrAvailableResourceRequest() {} long ListEmrAvailableResourceRequest::getResourceOwnerId()const { return resourceOwnerId_; } void ListEmrAvailableResourceRequest::setResourceOwnerId(long resourceOwnerId) { resourceOwnerId_ = resourceOwnerId; setParameter("ResourceOwnerId", std::to_string(resourceOwnerId)); } std::string ListEmrAvailableResourceRequest::getDepositType()const { return depositType_; } void ListEmrAvailableResourceRequest::setDepositType(const std::string& depositType) { depositType_ = depositType; setParameter("DepositType", depositType); } std::string ListEmrAvailableResourceRequest::getAccessKeyId()const { return accessKeyId_; } void ListEmrAvailableResourceRequest::setAccessKeyId(const std::string& accessKeyId) { accessKeyId_ = accessKeyId; setParameter("AccessKeyId", accessKeyId); } std::string ListEmrAvailableResourceRequest::getSystemDiskType()const { return systemDiskType_; } void ListEmrAvailableResourceRequest::setSystemDiskType(const std::string& systemDiskType) { systemDiskType_ = systemDiskType; setParameter("SystemDiskType", systemDiskType); } std::string ListEmrAvailableResourceRequest::getResourceGroupId()const { return resourceGroupId_; } void ListEmrAvailableResourceRequest::setResourceGroupId(const std::string& resourceGroupId) { resourceGroupId_ = resourceGroupId; setParameter("ResourceGroupId", resourceGroupId); } std::string ListEmrAvailableResourceRequest::getRegionId()const { return regionId_; } void ListEmrAvailableResourceRequest::setRegionId(const std::string& regionId) { regionId_ = regionId; setParameter("RegionId", regionId); } std::string ListEmrAvailableResourceRequest::getInstanceType()const { return instanceType_; } void ListEmrAvailableResourceRequest::setInstanceType(const std::string& instanceType) { instanceType_ = instanceType; setParameter("InstanceType", instanceType); } std::string ListEmrAvailableResourceRequest::getEmrVersion()const { return emrVersion_; } void ListEmrAvailableResourceRequest::setEmrVersion(const std::string& emrVersion) { emrVersion_ = emrVersion; setParameter("EmrVersion", emrVersion); } std::string ListEmrAvailableResourceRequest::getInstanceChargeType()const { return instanceChargeType_; } void ListEmrAvailableResourceRequest::setInstanceChargeType(const std::string& instanceChargeType) { instanceChargeType_ = instanceChargeType; setParameter("InstanceChargeType", instanceChargeType); } std::string ListEmrAvailableResourceRequest::getClusterId()const { return clusterId_; } void ListEmrAvailableResourceRequest::setClusterId(const std::string& clusterId) { clusterId_ = clusterId; setParameter("ClusterId", clusterId); } std::string ListEmrAvailableResourceRequest::getDestinationResource()const { return destinationResource_; } void ListEmrAvailableResourceRequest::setDestinationResource(const std::string& destinationResource) { destinationResource_ = destinationResource; setParameter("DestinationResource", destinationResource); } std::string ListEmrAvailableResourceRequest::getClusterType()const { return clusterType_; } void ListEmrAvailableResourceRequest::setClusterType(const std::string& clusterType) { clusterType_ = clusterType; setParameter("ClusterType", clusterType); } std::string ListEmrAvailableResourceRequest::getSpotStrategy()const { return spotStrategy_; } void ListEmrAvailableResourceRequest::setSpotStrategy(const std::string& spotStrategy) { spotStrategy_ = spotStrategy; setParameter("SpotStrategy", spotStrategy); } std::string ListEmrAvailableResourceRequest::getNetType()const { return netType_; } void ListEmrAvailableResourceRequest::setNetType(const std::string& netType) { netType_ = netType; setParameter("NetType", netType); } std::string ListEmrAvailableResourceRequest::getZoneId()const { return zoneId_; } void ListEmrAvailableResourceRequest::setZoneId(const std::string& zoneId) { zoneId_ = zoneId; setParameter("ZoneId", zoneId); } std::string ListEmrAvailableResourceRequest::getDataDiskType()const { return dataDiskType_; } void ListEmrAvailableResourceRequest::setDataDiskType(const std::string& dataDiskType) { dataDiskType_ = dataDiskType; setParameter("DataDiskType", dataDiskType); }
// Arquivo threadpl_unit.cpp // Criado em 02/12/2018 as 12:19 por Acrisio // Implementação da classe threadpl_unit #if defined(_WIN32) #pragma pack(1) #endif #if defined(_WIN32) #include <WinSock2.h> #elif defined(__linux__) #include "../UTIL/WinPort.h" #endif #include "threadpl_unit.hpp" #include "../UTIL/message_pool.h" #include "../SOCKET/socketserver.h" #include "../SOCKET/socket.h" #include "../UTIL/hex_util.h" #include "../UTIL/exception.h" #include "../TYPE/stda_error.h" using namespace stdA; threadpl_unit::threadpl_unit(size_t _num_thread_workers_io, size_t _num_thread_workers_logical, uint32_t _job_thread_num) : threadpool(_num_thread_workers_io, _num_thread_workers_logical, _job_thread_num) { }; threadpl_unit::~threadpl_unit() {}; void threadpl_unit::translate_packet(session *_session, Buffer *lpBuffer, DWORD dwIOsize, DWORD operation) { switch (operation) { case STDA_OT_SEND_RAW_COMPLETED: if (dwIOsize > 0 && lpBuffer != nullptr) { try { lpBuffer->consume(dwIOsize); _session->releaseSend(); }catch (exception& e) { CLEAR_PACKET_LOOP_SESSION(GET_FUNC_SEND, SET_FUNC_SEND); _session->releaseSend(); _smp::message_pool::getInstance().push(new message("[threadpl_unit::translate_packet][ErrorSystem] " + e.getFullMessageError(), CL_FILE_LOG_AND_CONSOLE)); }catch (std::exception& e) { CLEAR_PACKET_LOOP_SESSION(GET_FUNC_SEND, SET_FUNC_SEND); _session->releaseSend(); _smp::message_pool::getInstance().push(new message("[threadpl_unit::translate_packet][ErrorSystem] " + std::string(e.what()), CL_FILE_LOG_AND_CONSOLE)); } }else { _session->releaseSend(); try { // getConnectTime pode lançar exception if (_session->getConnectTime() <= 0 && _session->getState()) { _smp::message_pool::getInstance().push(new message("[threadpl_unit::translate_packet][Error] [STDA_OT_SEND_RAW_COMPLETED] _session[OID=" + std::to_string(_session->m_oid) + "] is not connected.", CL_FILE_LOG_AND_CONSOLE)); // Ainda não habilitar o disconnect session, vms aguardar as mensagens para ver se vai ter //DisconnectSession(_session); } }catch (exception& e) { _smp::message_pool::getInstance().push(new message("[threadpl_unit::translate_packet][ErrorSystem] " + e.getFullMessageError(), CL_FILE_LOG_AND_CONSOLE)); } } break; case STDA_OT_SEND_COMPLETED: if (dwIOsize > 0 && lpBuffer != nullptr) { packet_head ph; packet *_packet = nullptr; int32_t left = 0; //_session->releaseSend(); // Erro se colocar ele aqui do { try { LOOP_TRANSLATE_BUFFER_TO_PACKET_SERVER_UNIT(ph, sizeof(ph), STDA_OT_DISPACH_PACKET_SERVER); }catch (exception& e) { _smp::message_pool::getInstance().push(new message("SEND_COMPLETED MY class exception {SESSION[IP=" + std::string(_session->getIP()) + "]}: " + e.getFullMessageError(), CL_FILE_LOG_AND_CONSOLE)); if (STDA_SOURCE_ERROR_DECODE(e.getCodeError()) == STDA_ERROR_TYPE::CRYPT || STDA_SOURCE_ERROR_DECODE(e.getCodeError()) == STDA_ERROR_TYPE::COMPRESS) { CLEAR_PACKET_LOOP_SESSION(GET_FUNC_SEND, SET_FUNC_SEND); CLEAR_PACKET_LOOP_WITH_MSG; }else if (STDA_ERROR_CHECK_SOURCE_AND_ERROR(e.getCodeError(), STDA_ERROR_TYPE::PACKET, 15) || STDA_ERROR_CHECK_SOURCE_AND_ERROR(e.getCodeError(), STDA_ERROR_TYPE::PACKET, 1)) { CLEAR_PACKET_LOOP_SESSION(GET_FUNC_SEND, SET_FUNC_SEND); CLEAR_PACKET_LOOP_SIMPLE; CLEAR_BUFFER_LOOP_SERVER; // Libera o send _session->releaseSend(); //break; return; // Return por que o break só vai sair do while, e esse break é para sair do switch, mas como depois do switch não tem nada, então só terminar a função }else { CLEAR_PACKET_LOOP_SESSION(GET_FUNC_SEND, SET_FUNC_SEND); CLEAR_PACKET_LOOP_SIMPLE; CLEAR_BUFFER_LOOP_SERVER; // Libera o send _session->releaseSend(); //break; return; // Return por que o break só vai sair do while, e esse break é para sair do switch, mas como depois do switch não tem nada, então só terminar a função } }catch (std::exception& e) { _smp::message_pool::getInstance().push(new message("SEND_COMPLETED std::class exception {SESSION[IP=" + std::string(_session->getIP()) + "]}: " + std::string(e.what()), CL_FILE_LOG_AND_CONSOLE)); CLEAR_PACKET_LOOP_SESSION(GET_FUNC_SEND, SET_FUNC_SEND); CLEAR_PACKET_LOOP_SIMPLE; CLEAR_BUFFER_LOOP_SERVER; // Libera o send _session->releaseSend(); //break; return; // Return por que o break só vai sair do while, e esse break é para sair do switch, mas como depois do switch não tem nada, então só terminar a função }catch (...) { _smp::message_pool::getInstance().push(new message("SEND_COMPLETED Exception desconhecida. {SESSION[IP=" + std::string(_session->getIP()) + "]}", CL_FILE_LOG_AND_CONSOLE)); CLEAR_PACKET_LOOP_SESSION(GET_FUNC_SEND, SET_FUNC_SEND); CLEAR_PACKET_LOOP_SIMPLE; CLEAR_BUFFER_LOOP_SERVER; // Libera o send _session->releaseSend(); //break; return; // Return por que o break só vai sair do while, e esse break é para sair do switch, mas como depois do switch não tem nada, então só terminar a função } } while (dwIOsize > 0); // Libera o send _session->releaseSend(); }else { // Libera o send _session->releaseSend(); try { // getConnectTime pode lançar exception if (_session->getConnectTime() <= 0 && _session->getState()) { _smp::message_pool::getInstance().push(new message("[threadpl_unit::translate_packet][Error] [STDA_OT_SEND_COMPLETED] _session[OID=" + std::to_string(_session->m_oid) + "] is not connected.", CL_FILE_LOG_AND_CONSOLE)); // Ainda não habilitar o disconnect session, vms aguardar as mensagens para ver se vai ter //DisconnectSession(_session); } }catch (exception& e) { _smp::message_pool::getInstance().push(new message("[threadpl_unit::translate_packet][ErrorSystem] " + e.getFullMessageError(), CL_FILE_LOG_AND_CONSOLE)); } } break; case STDA_OT_RECV_COMPLETED: if (dwIOsize > 0 && lpBuffer != nullptr) { //_session->m_tick = std::clock(); // Tick time client para o TTL(time to live) packet_head ph; packet *_packet = nullptr; int32_t left = 0; lpBuffer->addSize(dwIOsize); // Add o size que recebeu no socket do { try { LOOP_TRANSLATE_BUFFER_TO_PACKET_CLIENT_UNIT(ph, sizeof(ph), STDA_OT_DISPACH_PACKET_CLIENT); }catch (exception& e) { _smp::message_pool::getInstance().push(new message("RECV_COMPLETED MY class exception {SESSION[IP=" + std::string(_session->getIP()) + "]}: " + e.getFullMessageError(), CL_FILE_LOG_AND_CONSOLE)); if (STDA_SOURCE_ERROR_DECODE(e.getCodeError()) == STDA_ERROR_TYPE::CRYPT || STDA_SOURCE_ERROR_DECODE(e.getCodeError()) == STDA_ERROR_TYPE::COMPRESS) { CLEAR_PACKET_LOOP_SESSION(GET_FUNC_RECV, SET_FUNC_RECV); CLEAR_PACKET_LOOP_WITH_MSG; CLEAR_BUFFER_LOOP_CLIENT; // Shutdown Socket Here #if defined(_WIN32) ::shutdown(_session->m_sock, SD_BOTH); #elif defined(__linux__) ::shutdown(_session->m_sock.fd, SD_BOTH); #endif break; }else if (STDA_ERROR_CHECK_SOURCE_AND_ERROR(e.getCodeError(), STDA_ERROR_TYPE::PACKET, 15) || STDA_ERROR_CHECK_SOURCE_AND_ERROR(e.getCodeError(), STDA_ERROR_TYPE::PACKET, 1)) { CLEAR_PACKET_LOOP_SESSION(GET_FUNC_RECV, SET_FUNC_RECV); CLEAR_PACKET_LOOP_SIMPLE; CLEAR_BUFFER_LOOP_CLIENT; // Shutdown Socket Here #if defined(_WIN32) ::shutdown(_session->m_sock, SD_BOTH); #elif defined(__linux__) ::shutdown(_session->m_sock.fd, SD_BOTH); #endif break; }else { CLEAR_PACKET_LOOP_SESSION(GET_FUNC_RECV, SET_FUNC_RECV); CLEAR_PACKET_LOOP_SIMPLE; CLEAR_BUFFER_LOOP_CLIENT; // Shutdown Socket Here #if defined(_WIN32) ::shutdown(_session->m_sock, SD_BOTH); #elif defined(__linux__) ::shutdown(_session->m_sock.fd, SD_BOTH); #endif break; } }catch (std::exception& e) { _smp::message_pool::getInstance().push(new message("RECV_COMPLETED std::class exception {SESSION[IP=" + std::string(_session->getIP()) + "]}: " + std::string(e.what()), CL_FILE_LOG_AND_CONSOLE)); CLEAR_PACKET_LOOP_SESSION(GET_FUNC_RECV, SET_FUNC_RECV); CLEAR_PACKET_LOOP_SIMPLE; CLEAR_BUFFER_LOOP_CLIENT; // Shutdown Socket Here #if defined(_WIN32) ::shutdown(_session->m_sock, SD_BOTH); #elif defined(__linux__) ::shutdown(_session->m_sock.fd, SD_BOTH); #endif break; }catch (...) { _smp::message_pool::getInstance().push(new message("RECV_COMPLETED Exception desconhecida {SESSION[IP=" + std::string(_session->getIP()) + "]}.", CL_FILE_LOG_AND_CONSOLE)); CLEAR_PACKET_LOOP_SESSION(GET_FUNC_RECV, SET_FUNC_RECV); CLEAR_PACKET_LOOP_SIMPLE; CLEAR_BUFFER_LOOP_CLIENT; // Shutdown Socket Here #if defined(_WIN32) ::shutdown(_session->m_sock, SD_BOTH); #elif defined(__linux__) ::shutdown(_session->m_sock.fd, SD_BOTH); #endif break; } } while (dwIOsize > 0); #if defined(_WIN32) // Post new IO Operation - RECV REQUEST memset(lpBuffer, 0, sizeof(OVERLAPPED)); // Zera o over pra receber mais #endif //_session->requestRecvBuffer(); // Manda de novo para receber qualquer resposta do cliente _session->releaseRecv(); //postIoOperation(_session, lpBuffer, operation - 1); }else { if (_session != nullptr /*&& _session->m_sock != INVALID_SOCKET*/) DisconnectSession(_session); } break; } };
SECTION code_fp_math48 PUBLIC _tan EXTERN cm48_sdccix_tan defc _tan = cm48_sdccix_tan
; A053477: Sum of iterates of divisor number function A000005. ; 1,2,5,9,7,15,9,17,14,19,13,27,15,23,24,23,19,33,21,35,30,31,25,41,30,35,36,43,31,47,33,47,42,43,44,50,39,47,48,57,43,59,45,59,60,55,49,67,54,65,60,67,55,71,64,73,66,67,61,87,63,71,78,73,74,83,69,83,78,87,73,99,75,83,90,91,86,95,81,99,88,91,85,111,94,95,96,105,91,117,100,107,102,103,104,123,99,113,114,114,103,119,105,121,122,115,109,135,111,127,120,131,115,131,124,131,132,127,128,143,126,131,132,139,134,153,129,145,138,147,133,159,142,143,152,153,139,155,141,167,150,151,152,168,154,155,162,163,151,177,153,169,168,171,164,183,159,167,168,187,170,181,165,179,182,175,169,191,174,187,186,187,175,191,190,195,186,187,181,213,183,199,192,201,194,203,196,203,206,207,193,215,195,203,212,210,199,225,201,227,210,211,212,231,214,215,222,227,218,233,213,227,222,223,224,239,226,227,228,247,230,239,225,251,239,235,229,255,231,247,248,249,235,261,244,251,246,255,241,275,243,257,258,259,260,263,256,265,258,267 trn $1,$0 mov $2,$0 lpb $0,1 cal $0,5 ; d(n) (also called tau(n) or sigma_0(n)), the number of divisors of n. add $1,$0 add $0,$1 sub $0,1 sub $0,$1 lpe add $1,1 add $1,$2
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright (c) GeoWorks 1994 -- All Rights Reserved PROJECT: Clavin MODULE: Outbox FILE: outboxUtils.asm AUTHOR: Adam de Boor, May 3, 1994 ROUTINES: Name Description ---- ----------- REVISION HISTORY: Name Date Description ---- ---- ----------- Adam 5/ 3/94 Initial revision DESCRIPTION: $Id: outboxUtils.asm,v 1.1 97/04/05 01:21:08 newdeal Exp $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ Outbox segment resource COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% OUCompareAddresses %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Compare two MailboxInternalTransAddrs for equality CALLED BY: (EXTERNAL) PASS: ds:si = address #1 es:di = address #2 bp = # significant bytes in an address for the medium / transport pair RETURN: flags set for je/jne to branch as expected DESTROYED: nothing SIDE EFFECTS: none PSEUDO CODE/STRATEGY: Two addresses are the same if their first <bp> bytes are the same, up to the length of the shortest address. In other words, if one address is 3 bytes, and bp is 6, the addresses are the same if the whole 3-byte address matches the first 3 bytes of the other address. This allows a transport to have an optional portion (e.g. a user name for infrared) of the significant bytes and still properly compare equal when two addresses, one with the optional part and one without, that match in their fixed portion are compared. REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 5/ 3/94 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ OUCompareAddresses proc far uses cx, si, di .enter EC < mov cx, ds:[si].MITA_medium > EC < cmp cx, es:[di].MITA_medium > EC < ERROR_NE ADDRESSES_USE_DIFFERENT_MEDIUM > ; ; First find the shorter of the two addresses. ; mov cx, ds:[si].MITA_opaqueLen cmp cx, es:[di].MITA_opaqueLen jb haveSize mov cx, es:[di].MITA_opaqueLen haveSize: ; ; If the shorter of the two is longer than the number of significant ; bytes, then compare only the significant bytes, thanks. ; cmp cx, bp jb doCompare mov cx, bp doCompare: add si, offset MITA_opaque add di, offset MITA_opaque jcxz noneSig repe cmpsb done: .leave ret noneSig: tst cx ; set ZF => addresses equal jmp done OUCompareAddresses endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% OUFindNextAddr %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Find the next address with a given talID CALLED BY: (EXTERNAL) OSCSetMessage, OTQGetTransport, OTrConnect, OTrSendMessage PASS: dxax = message cx = talID si = address index from which to search (inclusive) RETURN: carry set if no next marked address ds, ax, si, di = destroyed carry clear if found one: *ds:di = message ds:si = MailboxInternalTransAddr ax = index of found address DESTROYED: nothing SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 5/ 5/94 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ OUFindNextAddr proc far uses bx, dx .enter ; ; Lock down the message, s'il vous plais ; call MessageLock ; *ds:di <- message push di ; ; Arrange the registers for the enum. ; mov dx, cx ; dx <- talID mov ax, si ; ax <- starting elt mov cx, -1 ; cx <- enum all elements mov di, ds:[di] mov si, ds:[di].MMD_transAddrs test dx, mask TID_ADDR_INDEX jnz checkSent mov bx, cs mov di, offset OUFindNextAddrCallback call ChunkArrayEnumRange ; ax <- index of found, ; ds:cx <- found addr cmc ; return carry clear if found. ; ; Set up for return. ; popDone: pop di xchg cx, dx ; cx <- talID, ds:dx <- found addr jc unlockDone ; => not found, so release message block mov si, dx ; ds:si <- found addr done: .leave ret checkSent: ; ; TalID is an address #. Make sure the address hasn't been sent to, ; returning no-such-address if it has. ; mov ax, dx andnf ax, mask TID_NUMBER call ChunkArrayElementToPtr mov cx, di ; ds:cx <- address (for return) CheckHack <MAS_SENT eq 0> test ds:[di].MITA_flags, mask MTF_STATE jnz popDone stc jmp popDone unlockDone: call UtilVMUnlockDS jmp done OUFindNextAddr endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% OUFindNextAddrCallback %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Callback to find the next element with a particular talID CALLED BY: (INTERNAL) OUFindNextAddr via ChunkArrayEnumRange PASS: ds:di = MailboxInternalTransAddr *ds:si = address array dx = talID sought RETURN: carry set to stop enumerating (found one with talID): ax = index of found element ds:cx = found address carry clear if not found DESTROYED: nothing SIDE EFFECTS: none PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 5/ 5/94 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ OUFindNextAddrCallback proc far .enter cmp ds:[di].MITA_addrList, dx clc jne done call ChunkArrayPtrToElement mov cx, di stc done: .leave ret OUFindNextAddrCallback endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% OUUnmarkAddresses %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Unmakrs all the addresses in this message that are marked with this TalID. CALLED BY: (INTERNAL) OSCMsndSendMessageLater, OCDismiss PASS: dxax = MailboxMessage cx = TalID to unmark RETURN: nothing DESTROYED: bx, cx, di SIDE EFFECTS: PSEUDO CODE/STRATEGY: Why don't we simply use a callback to unmark those address whose MITA_addrList equal this TalID? REVISION HISTORY: Name Date Description ---- ---- ----------- AY 1/22/95 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ OUUnmarkAddresses proc far uses ax,dx,si,ds .enter ; ; Find the medium for this TalID. ; clr si ; start from first address call OUFindNextAddr ; ax = address index, *ds:di = MMD, ; ds:si = MailboxInternalTransAddr EC < ERROR_C NO_MESSAGE_ADDRESS_MARKED_WITH_GIVEN_ID > mov dx, ds:[si].MITA_medium ; ; Unmark add addresses using this medium. ; clr cx ; unmark TalID mov si, ds:[di] ; ds:si = MailboxMessageDesc mov si, ds:[si].MMD_transAddrs ; *ds:si = MITA array .assert segment ORMessageAddedMarkCallback eq segment @CurSeg mov bx, cs mov di, offset ORMessageAddedMarkCallback call ChunkArrayEnum call UtilVMUnlockDS .leave ret OUUnmarkAddresses endp Outbox ends Resident segment resource COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% OUChangeAddressMarkCallback %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: If the address has the indicated talID, change it to the other one. CALLED BY: (EXTERNAL) OTQAddOneMessage via ChunkArrayEnum, OTrPrepareBatch via ChunkArrayEnum PASS: ds:di = MailboxInternalTransAddr cx = talID for which to look dx = new talID to set, if match RETURN: carry set to stop enumerating (always clear) DESTROYED: nothing SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 5/ 2/94 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ if 0 ; no longer used OUChangeAddressMarkCallback proc far .enter cmp ds:[di].MITA_addrList, cx jne done mov ds:[di].MITA_addrList, dx done: clc .leave ret OUChangeAddressMarkCallback endp endif ; 0 Resident ends OutboxUICode segment resource COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% OUDeleteMessage %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Delete a message from the outbox and take down the interaction that was displaying it. CALLED BY: (INTERNAL) ODDeleteMessage, OSCMsndDeleteMessage PASS: dxax = MailboxMessage bx = talID with TID_ADDR_INDEX set, or 0 if deleting all addresses of the same medium. cx = address index *ds:si = GenInteraction object (to pass to UtilInteractionComplete) RETURN: ds fixed up DESTROYED: ax, bx, cx, dx, di SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- AY 1/17/95 Initial version (from ODDeleteMessage) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ OUDeleteMessage proc far curMsg local dword ; for OUDeleteMessageCallback .enter ; ; Run through all the addresses, marking them as sent. ; movdw ss:[curMsg], dxax mov di, offset OUDeleteMessageCallback call OUAddrEnum ; ; Remove the message from the outbox, thereby deleting it if no ; further references are outstanding. ; push ds:[LMBH_handle] call OUDeleteMessageIfNothingUnsent pop bx call MemDerefDS call UtilInteractionComplete .leave ret OUDeleteMessage endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% OUAddrEnum %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Enumerate the addresses currently being displayed CALLED BY: (INTERNAL) PASS: dxax = message bx = ODI_curID (i.e. either 0 to show all addresses, or a specific address #, with TID_ADDR_INDEX set) cx = selected address bp = value for callback routine cs:di = callback routine RETURN: nothing DESTROYED: di SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 5/27/94 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ OUAddrEnum proc near uses ds, si, dx, ax, bx, cx .enter ; ; Point to the selected address so we can get its medium or whatever. ; push di call MessageLock mov dx, di ; *ds:dx <- msg mov si, ds:[di] mov si, ds:[si].MMD_transAddrs mov_tr ax, cx call ChunkArrayElementToPtr pop cx ; cs:cx <- callback tst bx jz allForMedium ; => display all EC < test bx, mask TID_ADDR_INDEX > EC < ERROR_Z CUR_ID_DOESNT_MATCH_SELECTED_ADDRESS > EC < andnf bx, mask TID_NUMBER > EC < cmp bx, ax > EC < ERROR_NE CUR_ID_DOESNT_MATCH_SELECTED_ADDRESS > mov bx, dx ; pass *ds:bx = message dupLoop:: call cx if _DUPS_ALWAYS_TOGETHER ; ; Point to the next duplicate, if there is one. ; mov ax, ds:[di].MITA_next CheckHack <MITA_NIL eq -1> inc ax jz done dec ax push cx call ChunkArrayElementToPtr pop cx EC < ERROR_C INVALID_DUPLICATE_ADDR_LIST > EC < CheckHack <MAS_SENT eq 0> > EC < test ds:[di].MITA_flags, mask MTF_STATE > EC < ERROR_Z DUP_ADDRESS_SENT_BEFORE_ORIGINAL > jmp dupLoop endif ; _DUPS_ALWAYS_TOGETHER done: call UtilVMUnlockDS .leave ret allForMedium: ; ; Call back for all the addresses that are for the same medium. ; ; NOTE: We do not worry about whether an address is already being ; sent to, as that would seem to complicate things needlessly. ; We'll worry about it if the user actually tells us to send something. ; push cx ; pass the callback address push bp ; and the callback's bp mov bp, sp ; to our callback mov cx, ds:[di].MITA_medium mov bx, cs mov di, offset allForMediumCallback clr ax call ChunkArrayEnum pop bp pop cx jmp done ;-------------------- ; Callback to call the callback for an address if it's still unsent and ; it's for the same medium as that selected by the user. ; Pass: ds:di = MailboxInternalTransAddr ; cx = medium token ; ax = address # ; *ds:dx = message ; ss:bp -> callback's bp ; callback ; Return: carry set to stop enumerating (always clear) ; allForMediumCallback: CheckHack <MAS_SENT eq 0> test ds:[di].MITA_flags, mask MTF_STATE jz callbackDone cmp ds:[di].MITA_medium, cx jne callbackDone mov bx, dx push cx push bp mov cx, ss:[bp+2] ; cx <- callback routine mov bp, ss:[bp] ; bp <- callback's bp call cx mov_tr cx, bp ; remember the bp that came ; back, just in case pop bp mov ss:[bp], cx pop cx callbackDone: inc ax clc retf OUAddrEnum endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% OUDeleteMessageCallback %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Mark an address as sent to, thus effectively dequeueing it, if it's queued for transmission, removing it from any control panels, etc. CALLED BY: (INTERNAL) OUDeleteMessage via ODAddrEnum PASS: ds:di = MailboxInternalTransAddr *ds:bx = MailboxMessageDesc ax = address # ss:bp = frame inherited from OUDeleteMessage RETURN: nothing DESTROYED: nothing SIDE EFFECTS: block is dirtied. MA_OUTBOX_CHANGED is queued PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 5/27/94 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ OUDeleteMessageCallback proc near uses si, ax, cx, dx, di .enter inherit OUDeleteMessage Assert stackFrame, bp ; ; First mark the thing as sent ; CheckHack <MAS_SENT eq 0> BitClr ds:[di].MITA_flags, MTF_STATE ; MTF_STATE = MAS_SENT mov ds:[di].MITA_addrList, 0 ; ; Let everyone else know what's up. ; push bp movdw cxdx, ss:[curMsg] CheckHack <offset MABC_ADDRESS eq 0> Assert bitClear, ax, <not mask MABC_ADDRESS> ornf ax, (MACT_REMOVED shl offset MABC_TYPE) or \ mask MABC_OUTBOX mov_tr bp, ax mov ax, MSG_MA_BOX_CHANGED clr di call UtilForceQueueMailboxApp pop bp call UtilVMDirtyDS .leave ret OUDeleteMessageCallback endp OutboxUICode ends Transmit segment resource COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% OUDeleteMessageIfNothingUnsent %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Remove the passed message from the outbox if it has no more unsent addresses. CALLED BY: (EXTERNAL) OTrSendmessage, OUDeleteMessage PASS: dxax = message to check RETURN: carry set if message removed DESTROYED: nothing SIDE EFFECTS: Message may be removed from the outbox, causing notification to be generated via the MailboxApplication object PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 5/27/94 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ OUDeleteMessageIfNothingUnsent proc far msg local MailboxMessage push dx, ax uses bx, di, bp .enter ; ; See if there are any addresses for the message that remain unsent. ; If not, we wish to remove the message from the outbox (finally) ; mov bx, SEGMENT_CS mov di, offset OUFindUnsentAddrCallback call MessageAddrEnum jc done ; => at least one address still ; unsent, so leave the message ; in the outbox ; ; Fetch the outbox and remove the message. The message will continue ; to linger until it's removed from the batch and thread queues. ; call AdminGetOutbox call DBQRemove ;destroys dx, ax movdw dxax, msg jc done ; => not on outbox. Someone ; else already removed the msg. ; ; Remove the extra reference placed on the message when it was ; allocated. As others rebuild their queues, or what have you, the ; reference count will drop to 0 and the message will be freed. ; call DBQFree ;destroys dx, ax ; ; Flush the changes to disk. ; call UtilUpdateAdminFile ; ; Tell application about it. ; movdw cxdx, msg push bp mov bp, (MACT_REMOVED shl offset MABC_TYPE) or \ mask MABC_OUTBOX or \ (MABC_ALL shl offset MABC_ADDRESS) mov ax, MSG_MA_BOX_CHANGED call UtilSendToMailboxApp pop bp MovMsg dxax, cxdx clc done: cmc ; want carry *set* if removed .leave ret OUDeleteMessageIfNothingUnsent endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% OUFindUnsentAddrCallback %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Callback function to check the passed address to see if it remains unsent. If so, stop enumerating the addresses. CALLED BY: (INTERNAL) OUDeleteMessageIfNothingUnsent via MessageAddrEnum PASS: ds:di = MailboxInternalTransAddr RETURN: carry set if address still unsent DESTROYED: nothing SIDE EFFECTS: none PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 5/ 6/94 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ OUFindUnsentAddrCallback proc far .enter CheckHack <MAS_SENT eq 0> test ds:[di].MITA_flags, mask MTF_STATE jz done ; (carry cleared by "test") stc done: .leave ret OUFindUnsentAddrCallback endp Transmit ends
.constant_pool .const 0 string [start] .const 1 string [constructor] .const 2 int [-10] .const 3 int [1] .const 4 string [io.writeln] .const 5 int [-20] .end .entity start .valid_context_when (always) .method constructor ldconst 2 --> [-10] ldconst 3 --> [1] lcall 4 --> [io.writeln] ldconst 2 --> [-10] ldconst 5 --> [-20] add ldconst 3 --> [1] lcall 4 --> [io.writeln] exit .end .end
// Try and create two Data blocks that overlap each other define MEMORY_MAP = HIROM define ROM_SIZE = 1 include "../../../src/common/memory.inc" createDataBlock(rom0, 0xc00000, 0xc000ff) createDataBlock(rom1, 0xc00100, 0xc001ff) createDataBlock(rom2, 0xc00100, 0xc0017f) // ERROR createDataBlock(rom3, 0xc10000, 0xc1ffff)
#include "../GraphicsHost/GuiGraphicsHost.h" namespace vl { namespace presentation { namespace compositions { using namespace collections; using namespace controls; using namespace elements; /*********************************************************************** GuiWindowComposition ***********************************************************************/ GuiWindowComposition::GuiWindowComposition() { } GuiWindowComposition::~GuiWindowComposition() { } Rect GuiWindowComposition::GetBounds() { Rect bounds; if (relatedHostRecord) { if (auto window = relatedHostRecord->host->GetNativeWindow()) { bounds = Rect(Point(0, 0), window->Convert(window->GetClientSize())); } } UpdatePreviousBounds(bounds); return bounds; } void GuiWindowComposition::SetMargin(Margin value) { } /*********************************************************************** GuiBoundsComposition ***********************************************************************/ GuiBoundsComposition::GuiBoundsComposition() { } GuiBoundsComposition::~GuiBoundsComposition() { } bool GuiBoundsComposition::GetSizeAffectParent() { return sizeAffectParent; } void GuiBoundsComposition::SetSizeAffectParent(bool value) { sizeAffectParent = value; } bool GuiBoundsComposition::IsSizeAffectParent() { return sizeAffectParent; } Rect GuiBoundsComposition::GetPreferredBounds() { Rect result = GetBoundsInternal(compositionBounds); if (GetParent() && IsAlignedToParent()) { if (alignmentToParent.left >= 0) { vint offset = alignmentToParent.left - result.x1; result.x1 += offset; result.x2 += offset; } if (alignmentToParent.top >= 0) { vint offset = alignmentToParent.top - result.y1; result.y1 += offset; result.y2 += offset; } if (alignmentToParent.right >= 0) { result.x2 += alignmentToParent.right; } if (alignmentToParent.bottom >= 0) { result.y2 += alignmentToParent.bottom; } } return result; } Rect GuiBoundsComposition::GetBounds() { Rect result = GetPreferredBounds(); if (GetParent() && IsAlignedToParent()) { Size clientSize = GetParent()->GetClientArea().GetSize(); if (alignmentToParent.left >= 0 && alignmentToParent.right >= 0) { result.x1 = alignmentToParent.left; result.x2 = clientSize.x - alignmentToParent.right; } else if (alignmentToParent.left >= 0) { vint width = result.Width(); result.x1 = alignmentToParent.left; result.x2 = result.x1 + width; } else if (alignmentToParent.right >= 0) { vint width = result.Width(); result.x2 = clientSize.x - alignmentToParent.right; result.x1 = result.x2 - width; } if (alignmentToParent.top >= 0 && alignmentToParent.bottom >= 0) { result.y1 = alignmentToParent.top; result.y2 = clientSize.y - alignmentToParent.bottom; } else if (alignmentToParent.top >= 0) { vint height = result.Height(); result.y1 = alignmentToParent.top; result.y2 = result.y1 + height; } else if (alignmentToParent.bottom >= 0) { vint height = result.Height(); result.y2 = clientSize.y - alignmentToParent.bottom; result.y1 = result.y2 - height; } } UpdatePreviousBounds(result); return result; } void GuiBoundsComposition::SetBounds(Rect value) { compositionBounds = value; InvokeOnCompositionStateChanged(); } Margin GuiBoundsComposition::GetAlignmentToParent() { return alignmentToParent; } void GuiBoundsComposition::SetAlignmentToParent(Margin value) { alignmentToParent = value; InvokeOnCompositionStateChanged(); } bool GuiBoundsComposition::IsAlignedToParent() { return alignmentToParent != Margin(-1, -1, -1, -1); } } } }
; A314969: Coordination sequence Gal.4.78.2 where G.u.t.v denotes the coordination sequence for a vertex of type v in tiling number t in the Galebach list of u-uniform tilings. ; Submitted by Jamie Morken(s2) ; 1,5,9,14,20,26,31,35,40,45,49,54,60,66,71,75,80,85,89,94,100,106,111,115,120,125,129,134,140,146,151,155,160,165,169,174,180,186,191,195,200,205,209,214,220,226,231,235,240,245 mov $1,$0 seq $0,311625 ; Coordination sequence Gal.5.99.1 where G.u.t.v denotes the coordination sequence for a vertex of type v in tiling number t in the Galebach list of u-uniform tilings. mul $0,2 add $0,1 mul $0,2 div $0,6 mul $1,2 add $0,$1
noop # Test load pixel instruction # Write test values to register addi $1 $0 1 # $1 = 1 addi $2 $0 2 # $2 = 2; addi $3 $0 3 # $3 = 3; addi $5 $0 0 # i = 0 addi $6 $0 32 # lim = 32 printValues: lp $4 0($5) # pixel = pmem(i) noop noop noop beq $4 $0 3 # continue if $4 != 0 noop wli 48 j endPrintValues beq $4 $1 3 # continue if $4 != 1 noop wli 49 j endPrintValues beq $4 $2 3 # continue if $4 != 2 noop wli 50 j endPrintValues beq $4 $3 3 # continue if $4 != 3 noop wli 51 j endPrintValues endPrintValues: addi $5 $5 1 # i++ beq $5 $6 1 # if i == lim break j printValues # else continue end: j end
VictoryRoad2Object: db $7d ; border block db $7 ; warps db $8, $0, $2, VICTORY_ROAD_1 db $7, $1d, $3, $ff db $8, $1d, $3, $ff db $7, $17, $0, VICTORY_ROAD_3 db $e, $19, $2, VICTORY_ROAD_3 db $7, $1b, $1, VICTORY_ROAD_3 db $1, $1, $3, VICTORY_ROAD_3 db $0 ; signs db $d ; objects object SPRITE_HIKER, $c, $9, STAY, LEFT, $1, OPP_BLACKBELT, $9 object SPRITE_BLACK_HAIR_BOY_2, $15, $d, STAY, LEFT, $2, OPP_JUGGLER, $2 object SPRITE_BLACK_HAIR_BOY_1, $13, $8, STAY, DOWN, $3, OPP_TAMER, $5 object SPRITE_BLACK_HAIR_BOY_2, $4, $2, STAY, DOWN, $4, OPP_POKEMANIAC, $6 object SPRITE_BLACK_HAIR_BOY_2, $1a, $3, STAY, LEFT, $5, OPP_JUGGLER, $5 object SPRITE_BIRD, $b, $5, STAY, UP, $6, MOLTRES, 50 object SPRITE_BALL, $1b, $5, STAY, NONE, $7, TM_17 object SPRITE_BALL, $12, $9, STAY, NONE, $8, FULL_HEAL object SPRITE_BALL, $9, $b, STAY, NONE, $9, TM_05 object SPRITE_BALL, $b, $0, STAY, NONE, $a, GUARD_SPEC object SPRITE_BOULDER, $4, $e, STAY, BOULDER_MOVEMENT_BYTE_2, $b ; person object SPRITE_BOULDER, $5, $5, STAY, BOULDER_MOVEMENT_BYTE_2, $c ; person object SPRITE_BOULDER, $17, $10, STAY, BOULDER_MOVEMENT_BYTE_2, $d ; person ; warp-to EVENT_DISP VICTORY_ROAD_2_WIDTH, $8, $0 ; VICTORY_ROAD_1 EVENT_DISP VICTORY_ROAD_2_WIDTH, $7, $1d EVENT_DISP VICTORY_ROAD_2_WIDTH, $8, $1d EVENT_DISP VICTORY_ROAD_2_WIDTH, $7, $17 ; VICTORY_ROAD_3 EVENT_DISP VICTORY_ROAD_2_WIDTH, $e, $19 ; VICTORY_ROAD_3 EVENT_DISP VICTORY_ROAD_2_WIDTH, $7, $1b ; VICTORY_ROAD_3 EVENT_DISP VICTORY_ROAD_2_WIDTH, $1, $1 ; VICTORY_ROAD_3