text stringlengths 1 1.05M |
|---|
; A056143: Concatenate ... floor[n/100], floor[n/10], n.
; 0,1,2,3,4,5,6,7,8,9,110,111,112,113,114,115,116,117,118,119,220,221,222,223,224,225,226,227,228,229,330,331,332,333,334,335,336,337,338,339,440,441,442,443,444,445,446,447,448,449,550,551,552,553,554,555
mov $2,$0
div $0,10
mov $1,100
mul $1,$0
add $1,$2
mov $0,$1
|
TILESET_MAGMA_BANK_NUMBER = CURRENT_BANK_NUMBER
tileset_magma:
; Tileset's size in tiles (zero means 256)
.byt $32
TILESET_MAGMA_0 = (*-(tileset_magma+1))/16
.byt %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000
.byt %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000
TILESET_MAGMA_1 = (*-(tileset_magma+1))/16
.byt %11010101, %11101011, %11010111, %11101111, %11110111, %11111111, %11111111, %11111111
.byt %11111111, %11111111, %11111111, %11111111, %11111111, %11111111, %11111111, %11111111
TILESET_MAGMA_2 = (*-(tileset_magma+1))/16
.byt %01111110, %00111100, %00111100, %00011000, %00011000, %10000000, %01000001, %10100010
.byt %11111111, %11111111, %11111111, %11111111, %11111111, %11111111, %11111111, %11111111
TILESET_MAGMA_3 = (*-(tileset_magma+1))/16
.byt %00000000, %00001000, %00011100, %01111110, %01111111, %11111111, %11111111, %11111111
.byt %00011000, %00010100, %01100010, %10000001, %10000000, %00000000, %01111110, %11111111
TILESET_MAGMA_4 = (*-(tileset_magma+1))/16
.byt %00000001, %00000111, %00011110, %00111011, %01111111, %11101111, %11110110, %01011010
.byt %00000001, %00000011, %00011101, %00111101, %01111011, %11110111, %11101111, %11100111
TILESET_MAGMA_5 = (*-(tileset_magma+1))/16
.byt %00110000, %01111000, %11111110, %10101100, %11111101, %01100101, %11111011, %11110111
.byt %11101000, %11110100, %00110000, %11011110, %10011110, %10011110, %00110100, %01111000
TILESET_MAGMA_6 = (*-(tileset_magma+1))/16
.byt %00000000, %00000000, %00000000, %00000000, %00000000, %00011010, %00110101, %01101111
.byt %00000000, %00000000, %00000000, %00000000, %00000000, %00011100, %00111010, %01111100
TILESET_MAGMA_7 = (*-(tileset_magma+1))/16
.byt %00000000, %00000000, %00110000, %01111000, %11111000, %10001101, %01011011, %11011011
.byt %00000000, %00000000, %00111000, %01111100, %11111110, %11110010, %11101100, %11111100
TILESET_MAGMA_8 = (*-(tileset_magma+1))/16
.byt %11111111, %01111111, %00011111, %00000000, %01111111, %00111111, %00011111, %00001111
.byt %11111111, %11111111, %11111111, %01111111, %00000000, %00000000, %00000000, %00000000
TILESET_MAGMA_9 = (*-(tileset_magma+1))/16
.byt %11111111, %11111111, %11111111, %00000000, %01000000, %11101111, %11111111, %11111110
.byt %11111111, %11111111, %11111111, %11111111, %10111111, %00010000, %00000000, %00000000
TILESET_MAGMA_10 = (*-(tileset_magma+1))/16
.byt %11111111, %11111111, %11111111, %11111100, %00000000, %11000001, %11111111, %11111111
.byt %11111111, %11111111, %11111111, %11111111, %11111111, %00111110, %00000000, %00000000
TILESET_MAGMA_11 = (*-(tileset_magma+1))/16
.byt %11111111, %11111110, %11111100, %00000000, %01100011, %11111110, %11111110, %00111110
.byt %11111111, %11111111, %11111111, %11111111, %10011100, %00000000, %00000000, %00000000
TILESET_MAGMA_12 = (*-(tileset_magma+1))/16
.byt %00000000, %00000000, %00100000, %00000000, %00000000, %00000110, %00000011, %00000011
.byt %00000000, %01000011, %00000111, %00000111, %00000110, %00111000, %01101000, %01000000
TILESET_MAGMA_13 = (*-(tileset_magma+1))/16
.byt %00000000, %00001000, %00000000, %00000010, %00000010, %00000011, %00000011, %00000111
.byt %11100000, %11110000, %11111000, %11110000, %10100000, %01000000, %00000000, %00000000
TILESET_MAGMA_14 = (*-(tileset_magma+1))/16
.byt %00001111, %10001111, %11111111, %11111100, %11111100, %11110000, %11100000, %00000000
.byt %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000
TILESET_MAGMA_15 = (*-(tileset_magma+1))/16
.byt %00000000, %00000000, %00000000, %00000000, %00000000, %01100000, %01110000, %11010000
.byt %00000000, %00000000, %00000000, %00000000, %00000000, %01010000, %01100000, %11101000
TILESET_MAGMA_16 = (*-(tileset_magma+1))/16
.byt %01011100, %00110011, %00100001, %01110000, %01111000, %00111111, %00001111, %00000000
.byt %00000000, %00001100, %00010100, %00001000, %00000000, %00000000, %00000000, %00000000
TILESET_MAGMA_17 = (*-(tileset_magma+1))/16
.byt %11101111, %01111100, %11111010, %11010100, %11101000, %00000000, %00000000, %00000000
.byt %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000
TILESET_MAGMA_18 = (*-(tileset_magma+1))/16
.byt %00000000, %00000000, %00000000, %00000000, %00101011, %01010011, %01111110, %00011100
.byt %00111100, %01101110, %01110110, %11100000, %10000000, %00000000, %00000000, %00000000
TILESET_MAGMA_19 = (*-(tileset_magma+1))/16
.byt %00010000, %00011000, %10010000, %11110000, %01100000, %11100000, %10100000, %00000000
.byt %01100011, %11000111, %00001110, %00001101, %00011010, %00010001, %01000000, %01000000
TILESET_MAGMA_20 = (*-(tileset_magma+1))/16
.byt %00000000, %00100000, %00110000, %01010000, %10110000, %11100000, %10000000, %00000000
.byt %10000000, %00000000, %00000000, %00000000, %00000000, %00011000, %01111110, %10001110
TILESET_MAGMA_21 = (*-(tileset_magma+1))/16
.byt %00110000, %01111000, %11111110, %10101101, %11111101, %01100101, %11111011, %11110111
.byt %11101000, %11110100, %00110000, %11011110, %10011110, %10011110, %00110100, %01111000
TILESET_MAGMA_22 = (*-(tileset_magma+1))/16
.byt %00011011, %00011111, %00000111, %00000011, %00001101, %00111100, %00011000, %00000000
.byt %00000000, %00000000, %00110000, %01100000, %00100000, %00000000, %00000000, %00000000
TILESET_MAGMA_23 = (*-(tileset_magma+1))/16
.byt %01111111, %01111111, %10011111, %11001111, %11100000, %11111001, %11111111, %11111111
.byt %11111111, %11111111, %01111111, %00111111, %00011111, %00000110, %00000000, %00000000
TILESET_MAGMA_24 = (*-(tileset_magma+1))/16
.byt %11111111, %11111111, %11111111, %11111111, %11111111, %00111110, %11000000, %11111111
.byt %11111111, %11111111, %11111111, %11111111, %11111111, %11111111, %00111111, %00000000
TILESET_MAGMA_25 = (*-(tileset_magma+1))/16
.byt %11111111, %11111111, %11111111, %11000011, %00000001, %00111100, %01111111, %11111111
.byt %11111111, %11111111, %11111111, %11111111, %11111111, %11000011, %10000000, %00000000
TILESET_MAGMA_26 = (*-(tileset_magma+1))/16
.byt %11111110, %11111110, %11111001, %11110011, %11000111, %00001111, %11111111, %11111111
.byt %11111111, %11111111, %11111110, %11111100, %11111000, %11110000, %00000000, %00000000
TILESET_MAGMA_27 = (*-(tileset_magma+1))/16
.byt %11100000, %11100110, %11110100, %11110000, %11100000, %11000000, %11011100, %11011000
.byt %00011111, %00011001, %00001011, %00001111, %00011111, %00111111, %00100011, %00100111
TILESET_MAGMA_28 = (*-(tileset_magma+1))/16
.byt %11111111, %01110111, %10101010, %00000101, %00000000, %00000000, %00000000, %00000000
.byt %00000000, %10001000, %01010101, %11111010, %11111111, %11111111, %11111111, %11111111
TILESET_MAGMA_29 = (*-(tileset_magma+1))/16
.byt %11101011, %11010101, %10101010, %01000001, %00000000, %00000000, %00000000, %00000000
.byt %00010100, %00101010, %01010101, %10111110, %11111111, %11111111, %11111111, %11111111
TILESET_MAGMA_30 = (*-(tileset_magma+1))/16
.byt %00111100, %01101110, %01110110, %11100000, %10101011, %01010011, %01111110, %00011100
.byt %11111111, %11111111, %11111111, %11111111, %11010100, %10101100, %10000001, %11100011
TILESET_MAGMA_31 = (*-(tileset_magma+1))/16
.byt %00000111, %01100111, %00101111, %00001111, %00000111, %00000011, %00111011, %00011011
.byt %11111000, %10011000, %11010000, %11110000, %11111000, %11111100, %11000100, %11100100
TILESET_MAGMA_32 = (*-(tileset_magma+1))/16
.byt %00000000, %00000000, %00000000, %00000000, %00101000, %01010101, %10101010, %11111111
.byt %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000
TILESET_MAGMA_33 = (*-(tileset_magma+1))/16
.byt %11000000, %11100000, %11110100, %11100110, %11110000, %11110000, %11101100, %11001000
.byt %00111111, %00011111, %00001011, %00011001, %00001111, %00001111, %00010011, %00110111
TILESET_MAGMA_34 = (*-(tileset_magma+1))/16
.byt %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000
.byt %11111111, %11111111, %11111111, %11111111, %11111111, %11111111, %11111111, %11111111
TILESET_MAGMA_35 = (*-(tileset_magma+1))/16
.byt %01110011, %11011111, %10011110, %11111101, %01111010, %11110001, %11100000, %01000000
.byt %11101111, %11100111, %01101111, %00001111, %10011111, %00011111, %01011111, %11111111
TILESET_MAGMA_36 = (*-(tileset_magma+1))/16
.byt %11100000, %11111000, %11111000, %11110010, %10100010, %01000011, %00000011, %00000111
.byt %11111111, %11110111, %11111111, %11111101, %11111101, %11111100, %11111100, %11111000
TILESET_MAGMA_37 = (*-(tileset_magma+1))/16
.byt %00000000, %01000011, %00100111, %00000111, %00000110, %00111110, %01101011, %01000011
.byt %11111111, %11111111, %11011111, %11111111, %11111111, %11111001, %11111100, %11111100
TILESET_MAGMA_38 = (*-(tileset_magma+1))/16
.byt %10000000, %00100000, %00110000, %01010000, %10110000, %11111000, %11111110, %10001110
.byt %11111111, %11011111, %11001111, %10101111, %01001111, %00011111, %01111111, %11111111
TILESET_MAGMA_39 = (*-(tileset_magma+1))/16
.byt %00000011, %00000111, %00101111, %01100111, %00001111, %00001111, %00110111, %00010011
.byt %11111100, %11111000, %11010000, %10011000, %11110000, %11110000, %11001000, %11101100
TILESET_MAGMA_40 = (*-(tileset_magma+1))/16
.byt %00000000, %10101010, %01010101, %10101110, %01011111, %11111011, %10110101, %11111111
.byt %11111111, %11111111, %11111111, %11111111, %11111111, %11111111, %11111111, %11111111
TILESET_MAGMA_41 = (*-(tileset_magma+1))/16
.byt %01011100, %00111111, %00110101, %01111000, %01111000, %00111111, %00001111, %00000000
.byt %10100011, %11001100, %11011110, %10001111, %10000111, %11000000, %11110000, %11111111
TILESET_MAGMA_42 = (*-(tileset_magma+1))/16
.byt %00001111, %10001111, %11111111, %11111100, %11111100, %11110000, %11100000, %00000000
.byt %11110000, %01110000, %00000000, %00000011, %00000011, %00001111, %00011111, %11111111
TILESET_MAGMA_43 = (*-(tileset_magma+1))/16
.byt %11101111, %01111100, %11111010, %11010100, %11101000, %00000000, %00000000, %00000000
.byt %00010000, %10000011, %00000101, %00101011, %00010111, %11111111, %11111111, %11111111
TILESET_MAGMA_44 = (*-(tileset_magma+1))/16
.byt %00011011, %00011111, %00110111, %01100011, %00101101, %00111100, %00011000, %00000000
.byt %11100100, %11100000, %11111000, %11111100, %11110010, %11000011, %11100111, %11111111
TILESET_MAGMA_45 = (*-(tileset_magma+1))/16
.byt %11111111, %11111111, %11111111, %11111111, %11111111, %11111111, %11111111, %11111111
.byt %11111111, %11111111, %11111111, %11111111, %11111111, %11111111, %11111111, %11111111
TILESET_MAGMA_46 = (*-(tileset_magma+1))/16
.byt %00000111, %00011110, %00110101, %01101011, %11010101, %10101001, %11011111, %10100111
.byt %11111111, %11111111, %11111111, %11111110, %11111110, %11111110, %11110001, %11111001
TILESET_MAGMA_47 = (*-(tileset_magma+1))/16
.byt %11111000, %10001100, %00100010, %10100010, %11110101, %11111001, %11111001, %01111111
.byt %11000111, %11110011, %11111101, %11011101, %00011010, %11100110, %10101110, %10010000
TILESET_MAGMA_48 = (*-(tileset_magma+1))/16
.byt %11010011, %10100001, %10000010, %10000101, %11000011, %01000011, %01001111, %00111000
.byt %11111100, %11111110, %11111101, %01111010, %00111100, %10111100, %10110000, %11000111
TILESET_MAGMA_49 = (*-(tileset_magma+1))/16
.byt %00100111, %10101011, %11010110, %11111100, %11111000, %11100000, %00000000, %00000000
.byt %11011000, %01010100, %00101001, %00000011, %00000111, %00011111, %11111111, %11111111
|
INCLUDE "config_private.inc"
SECTION code_driver
SECTION code_driver_character_input
PUBLIC _asci1_getc
EXTERN asci1RxBuffer, asci1RxCount, asci1RxOut
_asci1_getc:
; exit : l = char received
; carry reset if Rx buffer is empty
;
; modifies : af, hl
ld a,(asci1RxCount) ; get the number of bytes in the Rx buffer
ld l,a ; and put it in hl
or a ; see if there are zero bytes available
ret Z ; if the count is zero, then return
ld hl,asci1RxCount
di
dec (hl) ; atomically decrement Rx count
ld hl,(asci1RxOut) ; get the pointer to place where we pop the Rx byte
ei
ld a,(hl) ; get the Rx byte
inc l ; move the Rx pointer low byte along
IF __ASCI1_RX_SIZE != 0x100
push af
ld a,__ASCI1_RX_SIZE-1 ; load the buffer size, (n^2)-1
and l ; range check
or asci1RxBuffer&0xFF ; locate base
ld l,a ; return the low byte to l
pop af
ENDIF
ld (asci1RxOut),hl ; write where the next byte should be popped
ld l,a ; put the byte in hl
scf ; indicate char received
ret
EXTERN _asci1_need
defc NEED = _asci1_need
|
; A020499: Expansion of 1/((1-5x)(1-9x)(1-11x)).
; Submitted by Jon Maiga
; 1,25,426,6170,81851,1029315,12498676,148149460,1726010901,19855374605,226242178526,2559210312750,28786474721551,322368894171895,3597522989519976,40035969784960040,444564772324613801,4927735200720685185,54542795368974203026,603010141581622555330,6660466185471436647651,73511320169685258178475,810840253416218726467676,8939184383446462924762620,98510502640328249350343101,1085230799143388381332315765,11952076222965387060347113926,131603675351562872051966845910,1448817960994937025049591780151
add $0,2
lpb $0
sub $0,1
div $1,2
max $2,26
mul $2,5
mul $3,11
add $3,$1
mul $1,18
add $1,$2
lpe
mov $0,$3
div $0,65
|
////////////////////////////////////////////////////////////////////////////
// Module : script_game_object_script3.cpp
// Created : 25.09.2003
// Modified : 29.06.2004
// Author : Dmitriy Iassenev
// Description : XRay Script game object script export
////////////////////////////////////////////////////////////////////////////
#include "pch_script.h"
#include "script_game_object.h"
using namespace luabind;
class_<CScriptGameObject> &script_register_game_object_trader(class_<CScriptGameObject> &instance)
{
instance
.def("set_trader_global_anim", &CScriptGameObject::set_trader_global_anim)
.def("set_trader_head_anim", &CScriptGameObject::set_trader_head_anim)
.def("set_trader_sound", &CScriptGameObject::set_trader_sound)
.def("external_sound_start", &CScriptGameObject::external_sound_start)
.def("external_sound_stop", &CScriptGameObject::external_sound_stop)
;return (instance);
}
|
/*
** Copyright 2014-2016 The Earlham Institute
**
** 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 "services_tabs.h"
#include "filesystem_utils.h"
#include "string_utils.h"
ServicesTabs :: ServicesTabs (QWidget *parent_p)
: QTabWidget (parent_p)
{
}
void ServicesTabs :: SelectService (const char *service_name_s, const json_t *params_json_p)
{
}
void ServicesTabs :: AddService (const char * const service_name_s, ServicePrefsWidget *service_widget_p)
{
const char * const icon_path_s = service_widget_p -> GetServiceIconUri ();
QString service_name (service_name_s);
if (icon_path_s)
{
QIcon icon (icon_path_s);
addTab (service_widget_p, icon, service_name);
}
else
{
addTab (service_widget_p, service_name);
}
}
QWidget *ServicesTabs :: GetWidget ()
{
return this;
}
void ServicesTabs :: UpdateServicePrefs (const char *service_name_s, const json_t *params_json_p)
{
}
|
/*
* Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011 Apple Inc. All rights reserved.
* Copyright (C) 2008 Alp Toker <alp@atoker.com>
* Copyright (C) 2008 Xan Lopez <xan@gnome.org>
* Copyright (C) 2008, 2010 Collabora Ltd.
* Copyright (C) 2009 Holger Hans Peter Freyther
* Copyright (C) 2009, 2013 Gustavo Noronha Silva <gns@gnome.org>
* Copyright (C) 2009 Christian Dywan <christian@imendio.com>
* Copyright (C) 2009, 2010, 2011, 2012 Igalia S.L.
* Copyright (C) 2009 John Kjellberg <john.kjellberg@power.alstom.com>
* Copyright (C) 2012 Intel Corporation
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "ResourceHandle.h"
#if USE(SOUP)
#include "CredentialStorage.h"
#include "GUniquePtrSoup.h"
#include "HTTPParsers.h"
#include "LocalizedStrings.h"
#include "MIMETypeRegistry.h"
#include "NetworkStorageSession.h"
#include "NetworkingContext.h"
#include "ResourceError.h"
#include "ResourceHandleClient.h"
#include "ResourceHandleInternal.h"
#include "ResourceResponse.h"
#include "SharedBuffer.h"
#include "SoupNetworkSession.h"
#include "TextEncoding.h"
#include <errno.h>
#include <fcntl.h>
#include <gio/gio.h>
#include <glib.h>
#include <libsoup/soup.h>
#include <sys/stat.h>
#include <sys/types.h>
#if !COMPILER(MSVC)
#include <unistd.h>
#endif
#include <wtf/CompletionHandler.h>
#include <wtf/FileSystem.h>
#include <wtf/glib/GRefPtr.h>
#include <wtf/glib/RunLoopSourcePriority.h>
#include <wtf/text/CString.h>
namespace WebCore {
ResourceHandleInternal::~ResourceHandleInternal() = default;
ResourceHandle::~ResourceHandle()
{
ASSERT_NOT_REACHED();
}
void ResourceHandle::platformContinueSynchronousDidReceiveResponse()
{
ASSERT_NOT_REACHED();
}
bool ResourceHandle::start()
{
ASSERT_NOT_REACHED();
return false;
}
void ResourceHandle::cancel()
{
ASSERT_NOT_REACHED();
}
bool ResourceHandle::shouldUseCredentialStorage()
{
ASSERT_NOT_REACHED();
return false;
}
void ResourceHandle::didReceiveAuthenticationChallenge(const AuthenticationChallenge&)
{
ASSERT_NOT_REACHED();
}
void ResourceHandle::receivedRequestToContinueWithoutCredential(const AuthenticationChallenge&)
{
ASSERT_NOT_REACHED();
}
void ResourceHandle::receivedCredential(const AuthenticationChallenge&, const Credential&)
{
ASSERT_NOT_REACHED();
}
void ResourceHandle::receivedCancellation(const AuthenticationChallenge&)
{
ASSERT_NOT_REACHED();
}
void ResourceHandle::receivedRequestToPerformDefaultHandling(const AuthenticationChallenge&)
{
ASSERT_NOT_REACHED();
}
void ResourceHandle::receivedChallengeRejection(const AuthenticationChallenge&)
{
ASSERT_NOT_REACHED();
}
void ResourceHandle::platformSetDefersLoading(bool)
{
ASSERT_NOT_REACHED();
}
void ResourceHandle::platformLoadResourceSynchronously(NetworkingContext*, const ResourceRequest&, StoredCredentialsPolicy, ResourceError&, ResourceResponse&, Vector<char>&)
{
ASSERT_NOT_REACHED();
}
}
#endif
|
; A026324: Expansion of 1/((1-2x)(1-6x)(1-7x)(1-8x)).
; Submitted by Jon Maiga
; 1,23,341,4147,45045,455091,4373797,40541699,365712149,3230463379,28067769093,240654781731,2041291828213,17162300683187,143239714105829,1188212150789443,9805989936743637,80575358596047315
mov $1,1
mov $2,$0
mov $3,$0
lpb $2
mov $0,$3
sub $2,1
sub $0,$2
seq $0,16311 ; Expansion of 1/((1-2*x)*(1-7*x)*(1-8*x)).
mul $1,6
add $1,$0
lpe
mov $0,$1
|
; A137445: a(n) = 2a(n-1)-2a(n-2), with a(0)=3 and a(1)=2.
; 3,2,-2,-8,-12,-8,8,32,48,32,-32,-128,-192,-128,128,512,768,512,-512,-2048,-3072,-2048,2048,8192,12288,8192,-8192,-32768,-49152,-32768,32768,131072,196608,131072,-131072,-524288,-786432,-524288,524288
mov $2,$0
mov $0,6
mov $1,6
lpb $2
mul $1,2
sub $1,1
sub $1,$0
sub $1,1
add $0,$1
sub $2,1
lpe
sub $1,4
div $1,2
add $1,2
|
; Super Mario Bros. 3 Full Disassembly by Southbird 2012
; For more info, see http://www.sonicepoch.com/sm3mix/
;
; PLEASE INCLUDE A CREDIT TO THE SOUTHBIRD DISASSEMBLY
; AND THE ABOVE LINK SOMEWHERE IN YOUR WORKS :)
;
; Original disassembler source generated by DCC6502 version v1.4
; (With labels, comments, and some syntax corrections for nesasm by Southbird)
; For more info about DCC6502, e-mail veilleux@ameth.org
;
; This source file last updated: 2011-12-14 17:45:42.706614297 -0600
; Distribution package date: Fri Apr 6 23:46:16 UTC 2012
;---------------------------------------------------------------------------
; CAUTION!! ObjectGroup02 labels MUST appear at the
; address specified by the predefined constants! I can't
; verify this at the assembler level, so be careful!!
; I'm using a ".org" directive to help enforce it, but
; the assembler does not warn you if you overwrite and
; instead will simply "stomp" on your code if you passed
; that limit ... sorry, original coders assumed a constant
; position on banks 1 - 5 and didn't use a LUT this time...
; Object group $02 (i.e. objects starting at ID $48) State 1 jump table
.org ObjectGroup_InitJumpTable ; <-- help enforce this table *here*
ObjectGroup02_InitJumpTable:
.word ObjInit_TinyCheepCheep ; Object $48 - OBJ_TINYCHEEPCHEEP
.word ObjInit_FloatingBGCloud ; Object $49 - OBJ_FLOATINGBGCLOUD
.word ObjInit_BoomBoomQBall ; Object $4A - OBJ_BOOMBOOMQBALL
.word ObjInit_BoomBoom ; Object $4B - OBJ_BOOMBOOMJUMP
.word ObjInit_BoomBoom ; Object $4C - OBJ_BOOMBOOMFLY
.word ObjInit_DoNothing ; Object $4D
.word ObjInit_DoNothing ; Object $4E
.word ObjInit_DoNothing ; Object $4F - OBJ_CHAINCHOMPFREE
.word ObjInit_BobOmbExplode ; Object $50 - OBJ_BOBOMBEXPLODE
.word ObjInit_RotoDiscDualCCW ; Object $51 - OBJ_ROTODISCDUAL
.word ObjInit_TreasureBox ; Object $52 - OBJ_TREASUREBOX
.word ObjInit_PodobooCeiling ; Object $53 - OBJ_PODOBOOCEILING
.word ObjInit_DonutLift ; Object $54 - OBJ_DONUTLIFTSHAKEFALL
.word ObjInit_BobOmb ; Object $55 - OBJ_BOBOMB
.word ObjInit_PiranhaSidewaysL ; Object $56 - OBJ_PIRANHASIDEWAYSLEFT
.word ObjInit_PiranhaSidewaysR ; Object $57 - OBJ_PIRANHASIDEWAYSRIGHT
.word ObjInit_FireChomp ; Object $58 - OBJ_FIRECHOMP
.word ObjInit_FireSnake ; Object $59 - OBJ_FIRESNAKE
.word ObjInit_RotoDiscDualCW ; Object $5A - OBJ_ROTODISCCLOCKWISE
.word ObjInit_RotoDiscDualCCW ; Object $5B - OBJ_ROTODISCCCLOCKWISE
.word ObjInit_DoNothing ; Object $5C - OBJ_ICEBLOCK
.word ObjInit_Tornado ; Object $5D - OBJ_TORNADO
.word ObjInit_RotoDiscDualCW ; Object $5E - OBJ_ROTODISCDUALOPPOSE
.word ObjInit_RotoDiscDualCW ; Object $5F - OBJ_ROTODISCDUALOPPOSE2
.word ObjInit_RotoDiscDualCW ; Object $60 - OBJ_ROTODISCDUALCCLOCK
.word ObjInit_BlooperWithKids ; Object $61 - OBJ_BLOOPERWITHKIDS
.word ObjInit_Blooper ; Object $62 - OBJ_BLOOPER
.word ObjInit_BigBerthaBirther ; Object $63 - OBJ_BIGBERTHABIRTHER
.word ObjInit_CheepCheepHopper ; Object $64 - OBJ_CHEEPCHEEPHOPPER
.word ObjInit_WaterCurrent ; Object $65 - OBJ_WATERCURRENTUPWARD
.word ObjInit_WaterCurrent ; Object $66 - OBJ_WATERCURRENTDOWNARD
.word ObjInit_LavaLotus ; Object $67 - OBJ_LAVALOTUS
.word ObjInit_Twirling ; Object $68 - OBJ_TWIRLINGBUZZY
.word ObjInit_Twirling ; Object $69 - OBJ_TWIRLINGSPINY
.word ObjInit_BlooperWithKids ; Object $6A - OBJ_BLOOPERCHILDSHOOT
.word ObjInit_PileDriver ; Object $6B - OBJ_PILEDRIVER
; Object group $02 (i.e. objects starting at ID $48) State 2 jump table
.org ObjectGroup_NormalJumpTable ; <-- help enforce this table *here*
ObjectGroup02_NormalJumpTable:
.word ObjNorm_TinyCheepCheep ; Object $48 - OBJ_TINYCHEEPCHEEP
.word ObjNorm_FloatingBGCloud ; Object $49 - OBJ_FLOATINGBGCLOUD
.word ObjNorm_BoomBoomQBall ; Object $4A - OBJ_BOOMBOOMQBALL
.word ObjNorm_BoomBoom ; Object $4B - OBJ_BOOMBOOMJUMP
.word ObjNorm_BoomBoom ; Object $4C - OBJ_BOOMBOOMFLY
.word ObjNorm_DoNothing ; Object $4D
.word ObjNorm_DoNothing ; Object $4E
.word ObjNorm_ChainChompFree ; Object $4F - OBJ_CHAINCHOMPFREE
.word ObjNorm_BobOmb ; Object $50 - OBJ_BOBOMBEXPLODE
.word ObjNorm_RotoDiscDual ; Object $51 - OBJ_ROTODISCDUAL
.word ObjNorm_TreasureBox ; Object $52 - OBJ_TREASUREBOX
.word ObjNorm_PodobooCeiling ; Object $53 - OBJ_PODOBOOCEILING
.word ObjNorm_DonutLift ; Object $54 - OBJ_DONUTLIFTSHAKEFALL
.word ObjNorm_BobOmb ; Object $55 - OBJ_BOBOMB
.word ObjNorm_PiranhaSideways ; Object $56 - OBJ_PIRANHASIDEWAYSLEFT
.word ObjNorm_PiranhaSideways ; Object $57 - OBJ_PIRANHASIDEWAYSRIGHT
.word ObjNorm_FireChomp ; Object $58 - OBJ_FIRECHOMP
.word ObjNorm_FireSnake ; Object $59 - OBJ_FIRESNAKE
.word ObjNorm_RotoDisc ; Object $5A - OBJ_ROTODISCCLOCKWISE
.word ObjNorm_RotoDisc ; Object $5B - OBJ_ROTODISCCCLOCKWISE
.word ObjNorm_IceBlock ; Object $5C - OBJ_ICEBLOCK
.word ObjNorm_Tornado ; Object $5D - OBJ_TORNADO
.word ObjNorm_RotoDiscDualOpp ; Object $5E - OBJ_ROTODISCDUALOPPOSE
.word ObjNorm_RotoDiscDualOpp2 ; Object $5F - OBJ_ROTODISCDUALOPPOSE2
.word ObjNorm_RotoDiscDual ; Object $60 - OBJ_ROTODISCDUALCCLOCK
.word ObjNorm_Blooper ; Object $61 - OBJ_BLOOPERWITHKIDS
.word ObjNorm_Blooper ; Object $62 - OBJ_BLOOPER
.word ObjNorm_BigBerthaBirther ; Object $63 - OBJ_BIGBERTHABIRTHER
.word ObjNorm_CheepCheepHopper ; Object $64 - OBJ_CHEEPCHEEPHOPPER
.word ObjNorm_WaterCurrent ; Object $65 - OBJ_WATERCURRENTUPWARD
.word ObjNorm_WaterCurrent ; Object $66 - OBJ_WATERCURRENTDOWNARD
.word ObjNorm_LavaLotus ; Object $67 - OBJ_LAVALOTUS
.word ObjNorm_TwirlingShell ; Object $68 - OBJ_TWIRLINGBUZZY
.word ObjNorm_TwirlingShell ; Object $69 - OBJ_TWIRLINGSPINY
.word ObjNorm_Blooper ; Object $6A - OBJ_BLOOPERCHILDSHOOT
.word ObjNorm_PileDriver ; Object $6B - OBJ_PILEDRIVER
; Object group $02 (i.e. objects starting at ID $48) Collision routine jump table (if calling Object_HitTestRespond;
; Special values of OCSPECIAL_KILLCHANGETO or OCSPECIAL_HIGHSCORE can be used here instead otherwise.)
.org ObjectGroup_CollideJumpTable ; <-- help enforce this table *here*
ObjectGroup02_CollideJumpTable:
.word ObjHit_DoNothing ; Object $48 - OBJ_TINYCHEEPCHEEP
.word ObjHit_DoNothing ; Object $49 - OBJ_FLOATINGBGCLOUD
.word ObjHit_DoNothing ; Object $4A - OBJ_BOOMBOOMQBALL
.word ObjHit_DoNothing ; Object $4B - OBJ_BOOMBOOMJUMP
.word ObjHit_DoNothing ; Object $4C - OBJ_BOOMBOOMFLY
.word ObjHit_DoNothing ; Object $4D
.word ObjHit_DoNothing ; Object $4E
.word ObjHit_DoNothing ; Object $4F - OBJ_CHAINCHOMPFREE
.word ObjHit_DoNothing ; Object $50 - OBJ_BOBOMBEXPLODE
.word ObjHit_DoNothing ; Object $51 - OBJ_ROTODISCDUAL
.word ObjHit_DoNothing ; Object $52 - OBJ_TREASUREBOX
.word ObjHit_DoNothing ; Object $53 - OBJ_PODOBOOCEILING
.word ObjHit_DoNothing ; Object $54 - OBJ_DONUTLIFTSHAKEFALL
.word ObjHit_DoNothing ; Object $55 - OBJ_BOBOMB
.word ObjHit_DoNothing ; Object $56 - OBJ_PIRANHASIDEWAYSLEFT
.word ObjHit_DoNothing ; Object $57 - OBJ_PIRANHASIDEWAYSRIGHT
.word ObjHit_DoNothing ; Object $58 - OBJ_FIRECHOMP
.word ObjHit_DoNothing ; Object $59 - OBJ_FIRESNAKE
.word ObjHit_DoNothing ; Object $5A - OBJ_ROTODISCCLOCKWISE
.word ObjHit_DoNothing ; Object $5B - OBJ_ROTODISCCCLOCKWISE
.word ObjHit_DoNothing ; Object $5C - OBJ_ICEBLOCK
.word ObjHit_DoNothing ; Object $5D - OBJ_TORNADO
.word ObjHit_DoNothing ; Object $5E - OBJ_ROTODISCDUALOPPOSE
.word ObjHit_DoNothing ; Object $5F - OBJ_ROTODISCDUALOPPOSE2
.word ObjHit_DoNothing ; Object $60 - OBJ_ROTODISCDUALCCLOCK
.word ObjHit_DoNothing ; Object $61 - OBJ_BLOOPERWITHKIDS
.word ObjHit_DoNothing ; Object $62 - OBJ_BLOOPER
.word ObjHit_DoNothing ; Object $63 - OBJ_BIGBERTHABIRTHER
.word ObjHit_DoNothing ; Object $64 - OBJ_CHEEPCHEEPHOPPER
.word ObjHit_DoNothing ; Object $65 - OBJ_WATERCURRENTUPWARD
.word ObjHit_DoNothing ; Object $66 - OBJ_WATERCURRENTDOWNARD
.word ObjHit_DoNothing ; Object $67 - OBJ_LAVALOTUS
.word OCSPECIAL_KILLCHANGETO | OBJ_BUZZYBEATLE ; Object $68 - OBJ_TWIRLINGBUZZY
.word OCSPECIAL_KILLCHANGETO | OBJ_SPINY ; Object $69 - OBJ_TWIRLINGSPINY
.word ObjHit_DoNothing ; Object $6A - OBJ_BLOOPERCHILDSHOOT
.word ObjHit_DoNothing ; Object $6B - OBJ_PILEDRIVER
; Object group $02 (i.e. objects starting at ID $48) attribute bits set 1 (OA1_* flags valid here)
.org ObjectGroup_Attributes ; <-- help enforce this table *here*
ObjectGroup02_Attributes:
.byte OA1_PAL1 | OA1_HEIGHT16 | OA1_WIDTH16 ; Object $48 - OBJ_TINYCHEEPCHEEP
.byte OA1_PAL1 | OA1_HEIGHT16 | OA1_WIDTH48 ; Object $49 - OBJ_FLOATINGBGCLOUD
.byte OA1_PAL1 | OA1_HEIGHT16 | OA1_WIDTH16 ; Object $4A - OBJ_BOOMBOOMQBALL
.byte OA1_PAL3 | OA1_HEIGHT32 | OA1_WIDTH32 ; Object $4B - OBJ_BOOMBOOMJUMP
.byte OA1_PAL3 | OA1_HEIGHT32 | OA1_WIDTH32 ; Object $4C - OBJ_BOOMBOOMFLY
.byte OA1_PAL0 | OA1_HEIGHT16 | OA1_WIDTH8 ; Object $4D
.byte OA1_PAL0 | OA1_HEIGHT16 | OA1_WIDTH8 ; Object $4E
.byte OA1_PAL1 | OA1_HEIGHT16 | OA1_WIDTH16 ; Object $4F - OBJ_CHAINCHOMPFREE
.byte OA1_PAL3 | OA1_HEIGHT16 | OA1_WIDTH16 ; Object $50 - OBJ_BOBOMBEXPLODE
.byte OA1_PAL1 | OA1_HEIGHT16 | OA1_WIDTH16 ; Object $51 - OBJ_ROTODISCDUAL
.byte OA1_PAL3 | OA1_HEIGHT16 | OA1_WIDTH16 ; Object $52 - OBJ_TREASUREBOX
.byte OA1_PAL1 | OA1_HEIGHT16 | OA1_WIDTH16 ; Object $53 - OBJ_PODOBOOCEILING
.byte OA1_PAL3 | OA1_HEIGHT16 | OA1_WIDTH16 ; Object $54 - OBJ_DONUTLIFTSHAKEFALL
.byte OA1_PAL3 | OA1_HEIGHT16 | OA1_WIDTH16 ; Object $55 - OBJ_BOBOMB
.byte OA1_PAL1 | OA1_HEIGHT16 | OA1_WIDTH24 ; Object $56 - OBJ_PIRANHASIDEWAYSLEFT
.byte OA1_PAL1 | OA1_HEIGHT16 | OA1_WIDTH24 ; Object $57 - OBJ_PIRANHASIDEWAYSRIGHT
.byte OA1_PAL1 | OA1_HEIGHT16 | OA1_WIDTH16 ; Object $58 - OBJ_FIRECHOMP
.byte OA1_PAL1 | OA1_HEIGHT16 | OA1_WIDTH16 ; Object $59 - OBJ_FIRESNAKE
.byte OA1_PAL1 | OA1_HEIGHT16 | OA1_WIDTH16 ; Object $5A - OBJ_ROTODISCCLOCKWISE
.byte OA1_PAL1 | OA1_HEIGHT16 | OA1_WIDTH16 ; Object $5B - OBJ_ROTODISCCCLOCKWISE
.byte OA1_PAL2 | OA1_HEIGHT32 | OA1_WIDTH16 ; Object $5C - OBJ_ICEBLOCK
.byte OA1_PAL2 | OA1_HEIGHT16 | OA1_WIDTH8 ; Object $5D - OBJ_TORNADO
.byte OA1_PAL1 | OA1_HEIGHT16 | OA1_WIDTH16 ; Object $5E - OBJ_ROTODISCDUALOPPOSE
.byte OA1_PAL1 | OA1_HEIGHT16 | OA1_WIDTH16 ; Object $5F - OBJ_ROTODISCDUALOPPOSE2
.byte OA1_PAL1 | OA1_HEIGHT16 | OA1_WIDTH16 ; Object $60 - OBJ_ROTODISCDUALCCLOCK
.byte OA1_PAL3 | OA1_HEIGHT16 | OA1_WIDTH16 ; Object $61 - OBJ_BLOOPERWITHKIDS
.byte OA1_PAL3 | OA1_HEIGHT16 | OA1_WIDTH16 ; Object $62 - OBJ_BLOOPER
.byte OA1_PAL1 | OA1_HEIGHT32 | OA1_WIDTH24 ; Object $63 - OBJ_BIGBERTHABIRTHER
.byte OA1_PAL1 | OA1_HEIGHT16 | OA1_WIDTH16 ; Object $64 - OBJ_CHEEPCHEEPHOPPER
.byte OA1_PAL0 | OA1_HEIGHT16 | OA1_WIDTH32 ; Object $65 - OBJ_WATERCURRENTUPWARD
.byte OA1_PAL0 | OA1_HEIGHT16 | OA1_WIDTH32 ; Object $66 - OBJ_WATERCURRENTDOWNARD
.byte OA1_PAL2 | OA1_HEIGHT32 | OA1_WIDTH24 ; Object $67 - OBJ_LAVALOTUS
.byte OA1_PAL3 | OA1_HEIGHT16 | OA1_WIDTH16 ; Object $68 - OBJ_TWIRLINGBUZZY
.byte OA1_PAL1 | OA1_HEIGHT16 | OA1_WIDTH16 ; Object $69 - OBJ_TWIRLINGSPINY
.byte OA1_PAL2 | OA1_HEIGHT16 | OA1_WIDTH16 ; Object $6A - OBJ_BLOOPERCHILDSHOOT
.byte OA1_PAL3 | OA1_HEIGHT16 | OA1_WIDTH16 ; Object $6B - OBJ_PILEDRIVER
; Object group $02 (i.e. objects starting at ID $48) second set attribute bits
.org ObjectGroup_Attributes2 ; <-- help enforce this table *here*
ObjectGroup02_Attributes2:
.byte OA2_NOSHELLORSQUASH | OA2_TDOGRP1 ; Object $48 - OBJ_TINYCHEEPCHEEP
.byte OA2_TDOGRP0 ; Object $49 - OBJ_FLOATINGBGCLOUD
.byte OA2_NOSHELLORSQUASH | OA2_TDOGRP1 ; Object $4A - OBJ_BOOMBOOMQBALL
.byte OA2_STOMPDONTCARE | OA2_TDOGRP2 ; Object $4B - OBJ_BOOMBOOMJUMP
.byte OA2_STOMPDONTCARE | OA2_TDOGRP2 ; Object $4C - OBJ_BOOMBOOMFLY
.byte OA2_TDOGRP0 ; Object $4D
.byte OA2_TDOGRP0 ; Object $4E
.byte OA2_NOSHELLORSQUASH | OA2_TDOGRP1 ; Object $4F - OBJ_CHAINCHOMPFREE
.byte OA2_STOMPDONTCARE | OA2_TDOGRP1 ; Object $50 - OBJ_BOBOMBEXPLODE
.byte OA2_NOSHELLORSQUASH | OA2_TDOGRP1 ; Object $51 - OBJ_ROTODISCDUAL
.byte OA2_STOMPDONTCARE | OA2_TDOGRP1 ; Object $52 - OBJ_TREASUREBOX
.byte OA2_NOSHELLORSQUASH | OA2_TDOGRP1 ; Object $53 - OBJ_PODOBOOCEILING
.byte OA2_NOSHELLORSQUASH | OA2_TDOGRP1 ; Object $54 - OBJ_DONUTLIFTSHAKEFALL
.byte OA2_STOMPDONTCARE | OA2_TDOGRP1 ; Object $55 - OBJ_BOBOMB
.byte OA2_TDOGRP0 ; Object $56 - OBJ_PIRANHASIDEWAYSLEFT
.byte OA2_TDOGRP0 ; Object $57 - OBJ_PIRANHASIDEWAYSRIGHT
.byte OA2_NOSHELLORSQUASH | OA2_TDOGRP1 ; Object $58 - OBJ_FIRECHOMP
.byte OA2_NOSHELLORSQUASH | OA2_TDOGRP1 ; Object $59 - OBJ_FIRESNAKE
.byte OA2_NOSHELLORSQUASH | OA2_TDOGRP1 ; Object $5A - OBJ_ROTODISCCLOCKWISE
.byte OA2_NOSHELLORSQUASH | OA2_TDOGRP1 ; Object $5B - OBJ_ROTODISCCCLOCKWISE
.byte OA2_GNDPLAYERMOD | OA2_TDOGRP1 ; Object $5C - OBJ_ICEBLOCK
.byte OA2_NOSHELLORSQUASH | OA2_TDOGRP1 ; Object $5D - OBJ_TORNADO
.byte OA2_NOSHELLORSQUASH | OA2_TDOGRP1 ; Object $5E - OBJ_ROTODISCDUALOPPOSE
.byte OA2_NOSHELLORSQUASH | OA2_TDOGRP1 ; Object $5F - OBJ_ROTODISCDUALOPPOSE2
.byte OA2_NOSHELLORSQUASH | OA2_TDOGRP1 ; Object $60 - OBJ_ROTODISCDUALCCLOCK
.byte OA2_NOSHELLORSQUASH | OA2_TDOGRP1 ; Object $61 - OBJ_BLOOPERWITHKIDS
.byte OA2_NOSHELLORSQUASH | OA2_TDOGRP1 ; Object $62 - OBJ_BLOOPER
.byte OA2_NOSHELLORSQUASH | OA2_TDOGRP1 ; Object $63 - OBJ_BIGBERTHABIRTHER
.byte OA2_NOSHELLORSQUASH | OA2_TDOGRP1 ; Object $64 - OBJ_CHEEPCHEEPHOPPER
.byte OA2_TDOGRP0 ; Object $65 - OBJ_WATERCURRENTUPWARD
.byte OA2_TDOGRP0 ; Object $66 - OBJ_WATERCURRENTDOWNARD
.byte OA2_TDOGRP0 ; Object $67 - OBJ_LAVALOTUS
.byte OA2_TDOGRP1 ; Object $68 - OBJ_TWIRLINGBUZZY
.byte OA2_TDOGRP1 ; Object $69 - OBJ_TWIRLINGSPINY
.byte OA2_NOSHELLORSQUASH | OA2_TDOGRP1 ; Object $6A - OBJ_BLOOPERCHILDSHOOT
.byte OA2_NOSHELLORSQUASH | OA2_TDOGRP1 ; Object $6B - OBJ_PILEDRIVER
; Object group $02 (i.e. objects starting at ID $48) third set attribute bits
.org ObjectGroup_Attributes3 ; <-- help enforce this table *here*
ObjectGroup02_Attributes3:
.byte OA3_HALT_NORMALONLY | OA3_NOTSTOMPABLE ; Object $48 - OBJ_TINYCHEEPCHEEP
.byte OA3_HALT_NORMALONLY | OA3_TAILATKIMMUNE ; Object $49 - OBJ_FLOATINGBGCLOUD
.byte OA3_HALT_NORMALONLY | OA3_TAILATKIMMUNE ; Object $4A - OBJ_BOOMBOOMQBALL
.byte OA3_HALT_NORMALONLY | OA3_TAILATKIMMUNE ; Object $4B - OBJ_BOOMBOOMJUMP
.byte OA3_HALT_NORMALONLY | OA3_TAILATKIMMUNE ; Object $4C - OBJ_BOOMBOOMFLY
.byte OA3_HALT_HOTFOOTSPECIAL ; Object $4D
.byte OA3_HALT_HOTFOOTSPECIAL ; Object $4E
.byte OA3_HALT_NORMALONLY | OA3_NOTSTOMPABLE ; Object $4F - OBJ_CHAINCHOMPFREE
.byte OA3_HALT_NORMALONLY ; Object $50 - OBJ_BOBOMBEXPLODE
.byte OA3_HALT_NORMALONLY | OA3_NOTSTOMPABLE | OA3_TAILATKIMMUNE ; Object $51 - OBJ_ROTODISCDUAL
.byte OA3_HALT_NORMALONLY | OA3_NOTSTOMPABLE | OA3_TAILATKIMMUNE ; Object $52 - OBJ_TREASUREBOX
.byte OA3_HALT_NORMALONLY | OA3_NOTSTOMPABLE | OA3_TAILATKIMMUNE ; Object $53 - OBJ_PODOBOOCEILING
.byte OA3_HALT_NORMALONLY | OA3_TAILATKIMMUNE ; Object $54 - OBJ_DONUTLIFTSHAKEFALL
.byte OA3_HALT_NORMALONLY ; Object $55 - OBJ_BOBOMB
.byte OA3_HALT_NORMALONLY | OA3_NOTSTOMPABLE ; Object $56 - OBJ_PIRANHASIDEWAYSLEFT
.byte OA3_HALT_NORMALONLY | OA3_NOTSTOMPABLE ; Object $57 - OBJ_PIRANHASIDEWAYSRIGHT
.byte OA3_HALT_NORMALONLY ; Object $58 - OBJ_FIRECHOMP
.byte OA3_HALT_NORMALONLY | OA3_NOTSTOMPABLE ; Object $59 - OBJ_FIRESNAKE
.byte OA3_HALT_NORMALONLY | OA3_NOTSTOMPABLE | OA3_TAILATKIMMUNE ; Object $5A - OBJ_ROTODISCCLOCKWISE
.byte OA3_HALT_NORMALONLY | OA3_NOTSTOMPABLE | OA3_TAILATKIMMUNE ; Object $5B - OBJ_ROTODISCCCLOCKWISE
.byte OA3_HALT_NORMALONLY | OA3_NOTSTOMPABLE | OA3_TAILATKIMMUNE ; Object $5C - OBJ_ICEBLOCK
.byte OA3_HALT_NORMALONLY | OA3_TAILATKIMMUNE ; Object $5D - OBJ_TORNADO
.byte OA3_HALT_NORMALONLY | OA3_NOTSTOMPABLE | OA3_TAILATKIMMUNE ; Object $5E - OBJ_ROTODISCDUALOPPOSE
.byte OA3_HALT_NORMALONLY | OA3_NOTSTOMPABLE | OA3_TAILATKIMMUNE ; Object $5F - OBJ_ROTODISCDUALOPPOSE2
.byte OA3_HALT_NORMALONLY | OA3_NOTSTOMPABLE | OA3_TAILATKIMMUNE ; Object $60 - OBJ_ROTODISCDUALCCLOCK
.byte OA3_HALT_NORMALONLY | OA3_NOTSTOMPABLE ; Object $61 - OBJ_BLOOPERWITHKIDS
.byte OA3_HALT_NORMALONLY | OA3_NOTSTOMPABLE ; Object $62 - OBJ_BLOOPER
.byte OA3_HALT_NORMALONLY | OA3_NOTSTOMPABLE ; Object $63 - OBJ_BIGBERTHABIRTHER
.byte OA3_HALT_NORMALONLY ; Object $64 - OBJ_CHEEPCHEEPHOPPER
.byte OA3_HALT_NORMALONLY | OA3_TAILATKIMMUNE ; Object $65 - OBJ_WATERCURRENTUPWARD
.byte OA3_HALT_NORMALONLY | OA3_TAILATKIMMUNE ; Object $66 - OBJ_WATERCURRENTDOWNARD
.byte OA3_HALT_NORMALONLY | OA3_NOTSTOMPABLE | OA3_TAILATKIMMUNE ; Object $67 - OBJ_LAVALOTUS
.byte OA3_HALT_NORMALONLY ; Object $68 - OBJ_TWIRLINGBUZZY
.byte OA3_HALT_NORMALONLY | OA3_NOTSTOMPABLE ; Object $69 - OBJ_TWIRLINGSPINY
.byte OA3_HALT_NORMALONLY | OA3_NOTSTOMPABLE ; Object $6A - OBJ_BLOOPERCHILDSHOOT
.byte OA3_HALT_NORMALONLY ; Object $6B - OBJ_PILEDRIVER
; Object group $02 (i.e. objects starting at ID $48) Pattern Table Select
.org ObjectGroup_PatTableSel ; <-- help enforce this table *here*
ObjectGroup02_PatTableSel:
.byte OPTS_SETPT5 | $1A ; Object $48 - OBJ_TINYCHEEPCHEEP
.byte OPTS_SETPT5 | $36 ; Object $49 - OBJ_FLOATINGBGCLOUD
.byte OPTS_SETPT5 | $13 ; Object $4A - OBJ_BOOMBOOMQBALL
.byte OPTS_SETPT6 | $33 ; Object $4B - OBJ_BOOMBOOMJUMP
.byte OPTS_SETPT6 | $33 ; Object $4C - OBJ_BOOMBOOMFLY
.byte OPTS_NOCHANGE ; Object $4D
.byte OPTS_NOCHANGE ; Object $4E
.byte OPTS_SETPT5 | $0A ; Object $4F - OBJ_CHAINCHOMPFREE
.byte OPTS_SETPT5 | $36 ; Object $50 - OBJ_BOBOMBEXPLODE
.byte OPTS_SETPT5 | $12 ; Object $51 - OBJ_ROTODISCDUAL
.byte OPTS_SETPT5 | $05 ; Object $52 - OBJ_TREASUREBOX
.byte OPTS_SETPT5 | $12 ; Object $53 - OBJ_PODOBOOCEILING
.byte OPTS_SETPT5 | $0E ; Object $54 - OBJ_DONUTLIFTSHAKEFALL
.byte OPTS_SETPT5 | $0B ; Object $55 - OBJ_BOBOMB
.byte OPTS_SETPT5 | $5A ; Object $56 - OBJ_PIRANHASIDEWAYSLEFT
.byte OPTS_SETPT5 | $5A ; Object $57 - OBJ_PIRANHASIDEWAYSRIGHT
.byte OPTS_SETPT5 | $0E ; Object $58 - OBJ_FIRECHOMP
.byte OPTS_SETPT5 | $0E ; Object $59 - OBJ_FIRESNAKE
.byte OPTS_SETPT5 | $12 ; Object $5A - OBJ_ROTODISCCLOCKWISE
.byte OPTS_SETPT5 | $12 ; Object $5B - OBJ_ROTODISCCCLOCKWISE
.byte OPTS_SETPT6 | $4F ; Object $5C - OBJ_ICEBLOCK
.byte OPTS_NOCHANGE ; Object $5D - OBJ_TORNADO
.byte OPTS_SETPT5 | $12 ; Object $5E - OBJ_ROTODISCDUALOPPOSE
.byte OPTS_SETPT5 | $12 ; Object $5F - OBJ_ROTODISCDUALOPPOSE2
.byte OPTS_SETPT5 | $12 ; Object $60 - OBJ_ROTODISCDUALCCLOCK
.byte OPTS_SETPT5 | $1A ; Object $61 - OBJ_BLOOPERWITHKIDS
.byte OPTS_SETPT5 | $1A ; Object $62 - OBJ_BLOOPER
.byte OPTS_SETPT5 | $1A ; Object $63 - OBJ_BIGBERTHABIRTHER
.byte OPTS_SETPT6 | $4F ; Object $64 - OBJ_CHEEPCHEEPHOPPER
.byte OPTS_NOCHANGE ; Object $65 - OBJ_WATERCURRENTUPWARD
.byte OPTS_NOCHANGE ; Object $66 - OBJ_WATERCURRENTDOWNARD
.byte OPTS_SETPT6 | $1B ; Object $67 - OBJ_LAVALOTUS
.byte OPTS_SETPT5 | $0B ; Object $68 - OBJ_TWIRLINGBUZZY
.byte OPTS_SETPT5 | $0B ; Object $69 - OBJ_TWIRLINGSPINY
.byte OPTS_SETPT5 | $1A ; Object $6A - OBJ_BLOOPERCHILDSHOOT
.byte OPTS_SETPT6 | $4F ; Object $6B - OBJ_PILEDRIVER
; Object group $02 (i.e. objects starting at ID $48) "Kill Action"
; Determines what action is taken when object is in "Killed" state (6)
; See Object_DoKillAction for the jump table
; NOTE: Any action type other than zero always sets the frame to 2 (unless object is not general purpose, i.e. index >= 5)
.org ObjectGroup_KillAction ; <-- help enforce this table *here*
ObjectGroup02_KillAction:
.byte KILLACT_JUSTDRAW16X16 ; Object $48 - OBJ_TINYCHEEPCHEEP
.byte KILLACT_STANDARD ; Object $49 - OBJ_FLOATINGBGCLOUD
.byte KILLACT_STANDARD ; Object $4A - OBJ_BOOMBOOMQBALL
.byte KILLACT_NORMALANDKILLED ; Object $4B - OBJ_BOOMBOOMJUMP
.byte KILLACT_NORMALANDKILLED ; Object $4C - OBJ_BOOMBOOMFLY
.byte KILLACT_STANDARD ; Object $4D
.byte KILLACT_STANDARD ; Object $4E
.byte KILLACT_NORMALANDKILLED ; Object $4F - OBJ_CHAINCHOMPFREE
.byte KILLACT_JUSTDRAW16X16 ; Object $50 - OBJ_BOBOMBEXPLODE
.byte KILLACT_STANDARD ; Object $51 - OBJ_ROTODISCDUAL
.byte KILLACT_STANDARD ; Object $52 - OBJ_TREASUREBOX
.byte KILLACT_JUSTDRAWMIRROR ; Object $53 - OBJ_PODOBOOCEILING
.byte KILLACT_STANDARD ; Object $54 - OBJ_DONUTLIFTSHAKEFALL
.byte KILLACT_JUSTDRAW16X16 ; Object $55 - OBJ_BOBOMB
.byte KILLACT_POOFDEATH ; Object $56 - OBJ_PIRANHASIDEWAYSLEFT
.byte KILLACT_POOFDEATH ; Object $57 - OBJ_PIRANHASIDEWAYSRIGHT
.byte KILLACT_NORMALSTATE ; Object $58 - OBJ_FIRECHOMP
.byte KILLACT_NORMALSTATE ; Object $59 - OBJ_FIRESNAKE
.byte KILLACT_STANDARD ; Object $5A - OBJ_ROTODISCCLOCKWISE
.byte KILLACT_STANDARD ; Object $5B - OBJ_ROTODISCCCLOCKWISE
.byte KILLACT_NORMALSTATE ; Object $5C - OBJ_ICEBLOCK
.byte KILLACT_STANDARD ; Object $5D - OBJ_TORNADO
.byte KILLACT_STANDARD ; Object $5E - OBJ_ROTODISCDUALOPPOSE
.byte KILLACT_STANDARD ; Object $5F - OBJ_ROTODISCDUALOPPOSE2
.byte KILLACT_STANDARD ; Object $60 - OBJ_ROTODISCDUALCCLOCK
.byte KILLACT_NORMALSTATE ; Object $61 - OBJ_BLOOPERWITHKIDS
.byte KILLACT_JUSTDRAWMIRROR ; Object $62 - OBJ_BLOOPER
.byte KILLACT_NORMALANDKILLED ; Object $63 - OBJ_BIGBERTHABIRTHER
.byte KILLACT_JUSTDRAW16X16 ; Object $64 - OBJ_CHEEPCHEEPHOPPER
.byte KILLACT_STANDARD ; Object $65 - OBJ_WATERCURRENTUPWARD
.byte KILLACT_STANDARD ; Object $66 - OBJ_WATERCURRENTDOWNARD
.byte KILLACT_NORMALANDKILLED ; Object $67 - OBJ_LAVALOTUS
.byte KILLACT_JUSTDRAWMIRROR ; Object $68 - OBJ_TWIRLINGBUZZY
.byte KILLACT_JUSTDRAWMIRROR ; Object $69 - OBJ_TWIRLINGSPINY
.byte KILLACT_NORMALSTATE ; Object $6A - OBJ_BLOOPERCHILDSHOOT
.byte KILLACT_NORMALSTATE ; Object $6B - OBJ_PILEDRIVER
; Object group $02 (i.e. objects starting at ID $48) pattern index starts
; These are used for all states except "normal"
OG2_POff .func (\1 - ObjectGroup02_PatternSets)
.org ObjectGroup_PatternStarts ; <-- help enforce this table *here*
ObjectGroup02_PatternStarts:
; Index by object group relative index (ObjGroupRel_Idx)
.byte OG2_POff(ObjP48), OG2_POff(ObjP49), OG2_POff(ObjP4A), OG2_POff(ObjP4B)
.byte OG2_POff(ObjP4C), OG2_POff(ObjP4D), OG2_POff(ObjP4E), OG2_POff(ObjP4F)
.byte OG2_POff(ObjP50), OG2_POff(ObjP51), OG2_POff(ObjP52), OG2_POff(ObjP53)
.byte OG2_POff(ObjP54), OG2_POff(ObjP55), OG2_POff(ObjP56), OG2_POff(ObjP57)
.byte OG2_POff(ObjP58), OG2_POff(ObjP59), OG2_POff(ObjP5A), OG2_POff(ObjP5B)
.byte OG2_POff(ObjP5C), OG2_POff(ObjP5D), OG2_POff(ObjP5E), OG2_POff(ObjP5F)
.byte OG2_POff(ObjP60), OG2_POff(ObjP61), OG2_POff(ObjP62), OG2_POff(ObjP63)
.byte OG2_POff(ObjP64), OG2_POff(ObjP65), OG2_POff(ObjP66), OG2_POff(ObjP67)
.byte OG2_POff(ObjP68), OG2_POff(ObjP69), OG2_POff(ObjP6A), OG2_POff(ObjP6B)
; Object group $02 (i.e. objects starting at ID $48) pattern sets
; Note that each "frame" is made up of two tile starts, so there's
; always going to be an even amount of tiles per object. That is,
; for each "frame" value, it moves up two bytes to the next pair.
; NOTE: SPECIAL EXCEPTION: If an object has Objects_IsGiant set
; OR has its ID >= OBJ_BIGGREENTROOPA, there is an assumption
; that the initial bytes at ObjectGroup02_PatternSets form a
; valid JMP $xxxx instruction to go to an alternate giant shell
; drawing routine (since otherwise default code is used)
.org ObjectGroup_PatternSets ; <-- help enforce this table *here*
ObjectGroup02_PatternSets:
; (End restricted alignment space)
ObjP49:
ObjP4D:
ObjP4E:
ObjP4F:
ObjP5D:
ObjP65:
ObjP66:
.byte $91, $93, $9D, $9F, $9D, $9F
ObjP52:
.byte $AB, $AD, $85, $85, $87, $87, $9D, $9F, $81, $81, $83, $83, $8B, $8B, $B5, $B7, $91, $93, $A9, $A9, $95, $97, $99, $9B, $A1, $A3, $89, $8D
ObjP53:
.byte $8D, $8D
ObjP5C:
.byte $8F, $8F, $B5, $B5
ObjP6B:
.byte $75, $75
ObjP68:
.byte $95, $97, $91, $93, $A1, $A1
ObjP69:
.byte $81, $83, $85, $87, $89, $89
ObjP54:
.byte $91, $93, $91, $93
ObjP55:
.byte $B1, $B3, $B5, $B7, $A7, $B9, $A7, $B9
ObjP50:
.byte $9D, $BF, $BB, $BD, $BB, $BD, $BB, $BD
ObjP4A:
.byte $BD, $BF
ObjP48:
.byte $93, $95, $93, $97, $93, $97
ObjP4B:
ObjP4C:
.byte $C1, $C1, $CF, $CD, $C1, $C1, $C5, $C7, $C1, $C1, $CF, $CD, $C1, $C1, $C5, $C7, $C1, $C1, $CF, $CD, $C1, $C1, $C5, $C7, $D3, $D3, $ED, $ED, $D9, $D9, $DD, $DD, $71, $71, $E7, $E9, $71, $71, $E9, $E7, $C1, $C1, $C7, $C7, $C1, $C1, $C5, $C5, $81, $81, $85, $87, $81, $81, $8D, $8F, $89, $89, $91, $93, $81, $81, $87, $85, $81, $81, $8F, $8D, $89, $89, $93, $91, $71, $71, $AD, $99, $71, $71, $9D, $9F, $A1, $A1, $A5, $A5, $A7, $A7, $AB, $AB
ObjP56:
ObjP57:
.byte $81, $83, $87, $89
ObjP67:
.byte $C1, $C5, $C3, $C7, $C9, $CD, $CB, $CF, $D1, $D5, $D3, $E7
ObjP58:
.byte $AF, $AF, $99, $9B, $95, $97
ObjP59:
.byte $A1, $A3, $A5, $A7, $A5, $A7
ObjP51:
ObjP5A:
ObjP5B:
ObjP5E:
ObjP5F:
ObjP60:
.byte $99, $9B, $9D, $9F
ObjP61:
ObjP62:
ObjP6A:
.byte $B1, $B1, $B3, $B3, $B1, $B1
ObjP63:
.byte $81, $83, $8D, $A1, $81, $83, $87, $89, $81, $83, $87, $89
ObjP64:
.byte $E7, $E9, $E7, $EF, $E7, $EF
ObjNorm_IceBlock:
; This may seem confusing, but an Ice Block is in held state when grabbed,
; shelled state when kicked, and just comes here to get busted...
LDA #$03 ; A = 3
JMP PRG003_A4DD ; Jump to PRG003_A4DD
ObjInit_TreasureBox:
LDA Level_TreasureItem
STA <Objects_Var5,X ; Var5 = what item we're gonna get
TAY ; -> 'Y'
LDA ToadItem_PalPerItem,Y
STA Palette_Buffer+$1A
LDA #$30
STA Palette_Buffer+$19
LDA #$0f
STA Palette_Buffer+$1B
; Update the palette!
LDA #$06
STA Graphics_Queue
; Timer = $1F (ticks until appearance)
LDA #$1f
STA Objects_Timer,X
RTS ; Return
TBoxItem_MirrorFlags:
.byte $00, $81, $82, $03, $80, $81, $82, $03, $00, $81, $02, $03, $00, $01
ObjNorm_TreasureBox:
LDA Objects_Timer,X
BEQ PRG003_A2DB ; If timer has expired, jump to PRG003_A2DB
CMP #$18
BNE PRG003_A2DA ; If timer <> $18, jump to PRG003_A2DA (RTS)
; Treasure box appear sound
LDA Sound_QLevel1
ORA #SND_LEVELPOOF
STA Sound_QLevel1
JSR TreasureBox_Poof ; "Poof" and it appears!
PRG003_A2DA:
RTS ; Return
PRG003_A2DB:
LDA <Objects_Var4,X
BNE PRG003_A300 ; If Var4 is non-zero (box is now the rising power up), jump to PRG003_A300
JSR Object_DoMoveBounceConveyor ; Treasure box will bounce when it falls or even get carried by conveyors
JSR Object_HitTest ; Check if Player has touched the box yet
BCC PRG003_A2F8 ; If Player has not yet touched box, jump to PRG003_A2F8
; Powerup rising sound
LDA #SND_LEVELRISE
STA Sound_QLevel1
; Stop the clock
STA Level_TimerEn
; Var4++ (box is now a rising power up)
INC <Objects_Var4,X
; Item Y velocity
LDA #-$30
STA <Objects_YVel,X
JSR TreasureBox_Poof ; Do another poof on opening
PRG003_A2F8:
LDA #$00
STA Objects_Frame,X
JMP Object_ShakeAndDraw ; Just draw treasure box and don't come back
PRG003_A300:
LDA Objects_Timer2,X
BEQ PRG003_A30E ; If timer 2 is expired, jump to PRG003_A30E
CMP #$01
BEQ PRG003_A321 ; If timer 2 has one tick left, jump to PRG003_A321
; Otherwise...
AND #%00001100
BNE PRG003_A33A ; 12 ticks on, 12 ticks off; jump to PRG003_A33A
RTS ; Return
PRG003_A30E:
; Timer 2 expired
JSR Object_ApplyYVel_NoLimit ; Apply Y velocity
INC <Objects_YVel,X
BMI PRG003_A33A ; If Y velocity is still negative, jump to PRG003_A33A
; Item has slowed to apex...
; Set timer 2 to $70
LDA #$70
STA Objects_Timer2,X
; "You got it" sound
LDA #SND_MAPBONUSAPPEAR
STA Sound_QMap
BNE PRG003_A33A ; Jump (technically always) to PRG003_A33A
PRG003_A321:
; Timer 2 has one tick left
; Give Player the treasure item
LDA Level_TreasureItem
JSR Player_GetItem
LDX <SlotIndexBackup ; X = object slot index
; ?? This is the "full power" ringing noise, and really can't be heard this way
LDA Sound_QPlayer
ORA #SND_PLAYERPOWER
STA Sound_QPlayer
JSR Object_SetDeadEmpty ; Destroy the treasure box object
; Countdown until exit
LDA #$60
STA LevelEvent_Cnt
RTS ; Return
PRG003_A33A:
; Timer 2 has time yet... or Y velocity is still negative...
LDA Level_TreasureItem
TAY
STA Objects_Frame,X ; Item -> Frame
; Set sprite attribute
LDA #$02
STA Objects_SprAttr,X
LDA TBoxItem_MirrorFlags,Y
BPL PRG003_A34E ; If bit 7 not set, jump to PRG003_A34E
JMP Object_ShakeAndDrawMirrored ; Draw treasure box item mirrored
PRG003_A34E:
JMP Object_ShakeAndDraw ; Draw treasure box item without mirroring
TreasureBox_Poof:
JSR SpecialObj_FindEmptyAbort ; Find an empty special object slot or don't come back here!
; The "poof" from when it appears
LDA #SOBJ_POOF
STA SpecialObj_ID,Y
; Set the poof where the box will be
LDA <Objects_X,X
STA SpecialObj_XLo,Y
LDA <Objects_Y,X
STA SpecialObj_YLo,Y
LDA <Objects_YHi,X
STA SpecialObj_YHi,Y
; Set the "poof" counter
LDA #$1f
STA SpecialObj_Data,Y
RTS ; Return
ObjInit_PodobooCeiling:
; Store original Y/Hi into Var5/Var4
LDA <Objects_Y,X
STA <Objects_Var5,X
LDA <Objects_YHi,X
STA <Objects_Var4,X
RTS ; Return
ObjNorm_PodobooCeiling:
LDA Objects_Timer,X
BEQ PRG003_A387 ; If timer expired, jump to PRG003_A387
STA Objects_SprHVis,X ; Set horizontal off-scren bits (a stupid way of preventing drawing?)
LSR A
BNE PRG003_A386 ; If timer > 1, jump to PRG003_A386 (RTS)
; Propel downwards
LDA #$58
STA <Objects_YVel,X
PRG003_A386:
RTS ; Return
PRG003_A387:
LDA <Player_HaltGame
BNE PRG003_A3D5 ; If gameplay halted, jump to PRG003_A3D5
JSR Player_HitEnemy ; Handle Player collision with Podoboo
; Flip vertically based on velocity
LDA <Objects_YVel,X
EOR #SPR_VFLIP
AND #SPR_VFLIP
STA Objects_FlipBits,X
LDA <Counter_1
AND #$03
BNE PRG003_A3AA ; Proceed 1:4 ticks, otherwise jump to PRG003_A3AA
; Frame loop 0-2
INC Objects_Frame,X
LDY Objects_Frame,X
CPY #$03
BNE PRG003_A3AA
STA Objects_Frame,X ; Zero the frame
PRG003_A3AA:
LDA <Objects_YVel,X
BPL PRG003_A3C2 ; If Podoboo is moving downward, jump to PRG003_A3C2
LDA <Objects_Y,X
CMP <Objects_Var5,X
LDA <Objects_YHi,X
SBC <Objects_Var4,X
BCS PRG003_A3C2 ; If Podoboo has not returned to origin, jump to PRG003_A3C2
; Podoboo went back to where he came from; reload timer with random value $40-$7F
LDA RandomN,X
AND #$3f
ORA #$40
STA Objects_Timer,X
PRG003_A3C2:
JSR Object_ApplyYVel_NoLimit ; Apply Y velocity
LDA <Objects_YVel,X
BPL PRG003_A3CD ; If Podoboo is moving downward, jump to PRG003_A3CD
CMP #-$6F
BLT PRG003_A3D2 ; If Podoboo is not moving upward faster than -$6F, jump to PRG003_A3D2
PRG003_A3CD:
SUB #$02 ; Accelerate Podoboo
STA <Objects_YVel,X ; Update Y velocity
PRG003_A3D2:
JSR Object_DeleteOffScreen ; Delete object if it falls too far off-screen
PRG003_A3D5:
JMP Object_ShakeAndDrawMirrored ; Draw Podoboo and don't come back!
ObjInit_PileDriver:
RTS ; Return
PileDriver_TowardsPlayerXVel: .byte $10, -$10
; Runs compare against object's state to see if it's state 2 (Normal)
Object_CheckIfNormalState:
LDA Objects_State,X
CMP #OBJSTATE_NORMAL
RTS ; Return
ObjNorm_PileDriver
JSR Object_CheckIfNormalState
BEQ PRG003_A3E9 ; If in normal state, jump to PRG003_A3E9
JMP BrickBust_MicroGoomba ; Bust out the Micro Goomba
PRG003_A3E9:
JSR Object_DeleteOffScreen ; Delete object if it falls too far off-screen
LDA <Player_HaltGame
BEQ PRG003_A3F3 ; If gameplay halted, jump to PRG003_A3F3
JMP PRG003_A47A ; Jump to PRG003_A47A
PRG003_A3F3:
LDA <Objects_Var5,X
BEQ PRG003_A40F ; If Var5 = 0, jump to PRG003_A40F
DEC <Objects_Var5,X ; Var5--
BNE PRG003_A424 ; If Var5 <> 0, jump to PRG003_A424
; Piledriver jumps!
LDA #-$60
STA <Objects_YVel,X
; Timer set to $70
LDA #$70
STA Objects_Timer,X
JSR Level_ObjCalcXDiffs
; Jump towards Player
LDA PileDriver_TowardsPlayerXVel,Y
STA <Objects_XVel,X
JMP PRG003_A424 ; Jump to PRG003_A424
PRG003_A40F:
LDA Objects_Timer,X
BNE PRG003_A424 ; If timer not expired, jump to PRG003_A424
JSR Level_ObjCalcXDiffs
LDA <Temp_Var16
ADD #$30
CMP #$60
BGE PRG003_A424 ; If Player is not close enough, jump to PRG003_A424
; Var5 = $28
LDA #$28
STA <Objects_Var5,X
PRG003_A424:
JSR Object_ApplyXVel ; Apply X Velocity
JSR Object_ApplyYVel_NoLimit ; Apply Y velocity
LDA <Objects_YVel,X
BMI PRG003_A434 ; If Piledriver is moving upward, jump to PRG003_A434
CMP #$70
BGE PRG003_A446 ; If Piledriver is falling at or faster $70, jump to PRG003_A446
BLT PRG003_A437 ; Otherwise, jump to PRG003_A437
PRG003_A434:
JSR Negate ; Negate the velocity value (absolute value)
PRG003_A437:
LSR A
LSR A ; Divide current velocity by 4
; I'm not sure what this check is for? The Y velocity will never be
; negative because of the PRG003_A434 Negate, so maybe this is in error?
LDY <Objects_YVel,X
BPL PRG003_A43F ; If Piledriver is moving upward, jump to PRG003_A43F
; Probably unreachable?
LSR A
LSR A
PRG003_A43F:
ADD #$01 ; +1 to divided Y velocity
ADC <Objects_YVel,X
STA <Objects_YVel,X ; Update Y velocity
PRG003_A446:
JSR Object_WorldDetectN1 ; Detect world
JSR Object_HandleBumpUnderneath ; Handle getting bumped underneath
LDA <Objects_DetStat,X
AND #$08
BEQ PRG003_A456 ; If Piledriver hit ceiling, jump to PRG003_A456
; Bounce off ceiling
LDA #$01
STA <Objects_YVel,X
PRG003_A456:
LDA <Objects_DetStat,X
AND #$04
BEQ PRG003_A471 ; If Piledriver hits ground, jump to PRG003_A471
LDA <Objects_YVel,X
CMP #$20
BLT PRG003_A46A ; If Piledriver is not moving at least $20, jump to PRG003_A46A
; Wa-bam! Landing sound
LDA Sound_QLevel1
ORA #SND_LEVELBABOOM
STA Sound_QLevel1
PRG003_A46A:
JSR Object_HitGround ; Align Piledriver to ground
; Halt horizontal movement
LDA #$00
STA <Objects_XVel,X
PRG003_A471:
LDA <Objects_DetStat,X
AND #$03
BEQ PRG003_A47A ; If Piledriver has hit a wall, jump to PRG003_A47A
JSR Object_AboutFace ; Turn around
PRG003_A47A:
JSR Object_ShakeAndDrawMirrored ; Draw the Piledriver
; Add little Microgoomba sticking out the bottom
LDA Sprite_RAM+$00,Y
SUB #$01
STA Sprite_RAM+$00,Y
LDA Sprite_RAM+$04,Y
SBC #$01
STA Sprite_RAM+$04,Y
JSR Object_AnySprOffscreen
BNE PRG003_A4DA ; If any of Piledriver's sprites are off-screen, jump to PRG003_A4DA
LDA <Objects_YVel,X
ASL A ; Sets carry if negative
LDA #$02 ; A = 2
BCS PRG003_A4A1 ; If Piledriver is moving upward, jump to PRG003_A4A1
LDA <Objects_Var5,X
BEQ PRG003_A4DA ; If Var5 = 0, jump to PRG003_A4DA
LSR A
LSR A
LSR A ; A = Var5 / 8
PRG003_A4A1:
TAX ; -> 'X'
; Set Y offset
LDA Sprite_RAM+$00,Y
SUB Piledriver_YOff,X
STA Sprite_RAM+$00,Y
LDA Sprite_RAM+$04,Y
SUB Piledriver_YOff,X
STA Sprite_RAM+$04,Y
LDX <SlotIndexBackup ; X = object slot index
LDA <Objects_SpriteY,X
STA Sprite_RAM+$08,Y
; NOTE: This sprite is not visible... I suspect this may originally
; not have been the microgoomba, but a regular goomba, hence the
; timed toggled horizontal flip to do his "walking" animation...
;;;;;;;;;;;;;;;;;;
LDA <Objects_SpriteX,X
ADD #$04
STA Sprite_RAM+$0B,Y
LDA Level_NoStopCnt
LSR A
LSR A
LSR A
LSR A
LDA #SPR_PAL3 ; palette selected 3
BCC PRG003_A4D2 ; 16 ticks on, 16 ticks off; jump to PRG003_A4D2
LDA #(SPR_HFLIP | SPR_PAL3) ; horizontal flip, palette select 3
PRG003_A4D2:
STA Sprite_RAM+$0A,Y ; Set attribute
; Pattern $FF (not visible)
LDA #$ff
STA Sprite_RAM+$09,Y
;;;;;;;;;;;;;;;;;;
PRG003_A4DA:
RTS ; Return
BrickBust_MicroGoomba:
LDA #$04 ; A = 4 (the Microgoomba that falls out of a Piledriver)
PRG003_A4DD:
STA <Temp_Var16 ; Input value -> Temp_Var16
; Crumbling brick sound
LDA Sound_QLevel2
ORA #SND_LEVELCRUMBLE
STA Sound_QLevel2
JSR Object_SetDeadEmpty ; Destroy the Ice Block
; Break apart into the four brick bust pieces
PRG003_A4EA:
JSR BustBlock_Segment ; Generate Ice block segment
DEC <Temp_Var16 ; Temp_Var16--
BPL PRG003_A4EA ; While Temp_Var16 >= 0, loop!
RTS ; Return
Piledriver_YOff: .byte $01, $00, $02, $04, $05, $02
; "Bust block" is an ice block that smashed into wall or a Microgoomba brick getting busted
; First four are the brick bits, the last is the microgoomba
BustBlock_YOffByInput: .byte -$04, -$04, $04, $04, $00
BustBlock_YHiOffByInput: .byte $FF, $FF, $00, $00, $00
PRG003_A502: .byte $00, $08, $00, $08, $04
BustBlock_YVelByInput: .byte $C0, $C0, $D0, $D0, $D0
BustBlock_XVelByInput: .byte $F8, $08, $F8, $08, $00
; Generates a segment of the busted brick (or microgoomba in the case of the Piledriver)
BustBlock_Segment:
LDY #$07 ; Y = 7 (wider expanse of special object slots)
JSR SpecialObj_FindEmptyAbortY ; Find an empty special object slot or don't come back here...
; Temp_Var1 = Ice Block's Y
LDA <Objects_Y,X
STA <Temp_Var1
; Temp_Var3 = Ice Block's Y Hi
LDA <Objects_YHi,X
STA <Temp_Var3
; Temp_Var2 = Ice Block's X
LDA <Objects_X,X
STA <Temp_Var2
; X = Temp_Var16 (input value for Ice Block)
LDX <Temp_Var16
; Add Y offset by input
LDA <Temp_Var1
ADD BustBlock_YOffByInput,X
STA SpecialObj_YLo,Y
LDA <Temp_Var3
ADC BustBlock_YHiOffByInput,X
STA SpecialObj_YHi,Y
; X Lo = Temp_Var2
LDA <Temp_Var2
STA SpecialObj_XLo,Y
; Set Ice Block Y Velocity by input
LDA BustBlock_YVelByInput,X
STA SpecialObj_YVel,Y
; Set Ice Block X Velocity by input
LDA BustBlock_XVelByInput,X
STA SpecialObj_XVel,Y
LDA #SOBJ_BRICKDEBRIS ; Busting brick, input value 4 only
CPX #$04 ; X = 4
BNE PRG003_A54E ; If input value <> 4, jump to PRG003_A54E
LDA #SOBJ_MICROGOOMBA ; Otherwise, micro Goomba
PRG003_A54E:
STA SpecialObj_ID,Y ; Set appropriate ID
LDA #$ff
STA SpecialObj_Data,Y
STA SpecialObj_Timer,Y
LDX <SlotIndexBackup ; X = object slot index
LDA Level_ObjectID,X
CMP #OBJ_ICEBLOCK
BEQ PRG003_A567 ; If this is an Ice Block, jump to PRG003_A567
LDA #$00
STA SpecialObj_Timer,Y
PRG003_A567:
RTS ; Return
Twirler_InitXVel: .byte $08, -$08
ObjInit_Twirling:
JSR Level_ObjCalcXDiffs
; Set twirler X velocity towards Player
LDA Twirler_InitXVel,Y
STA <Objects_XVel,X
; Set vertically flipped
LDA #SPR_VFLIP
STA Objects_FlipBits,X
DEC <Objects_Y,X ; Start one pixel higher
LDY <Objects_Y,X
INY
BNE PRG003_A580
DEC <Objects_YHi,X ; Apply carry
PRG003_A580:
RTS ; Return
; FIXME: Anybody want to claim this?
; $A581
.byte $F8, $08
ObjNorm_TwirlingShell:
JSR Object_DeleteOffScreen ; Delete object if it falls too far off-screen
JSR TwirlShell_Draw ; Draw the twirling shell enemy
LDA <Player_HaltGame
BNE PRG003_A5EF ; If gameplay halted, jump to PRG003_A5EF
JSR Object_HandleBumpUnderneath ; Handle getting bumped from underneath
LDA Level_ObjectID,X
CMP #OBJ_BUZZYBEATLE
BNE PRG003_A59A ; If object has not become a Buzzle Beatle, jump to PRG003_A59A
JMP Object_SetShellState ; Set shell state and don't come back!
PRG003_A59A:
LDY #$00 ; Y = 0
LDA <Counter_1
AND #$08
BEQ PRG003_A5A3 ; 8 ticks on, 8 ticks off; jump to PRG003_A5A3
INY ; Y = 1
PRG003_A5A3:
TYA
STA Objects_Frame,X ; Toggle frame 0/1
JSR Object_ApplyXVel ; Apply X velocity
; Maintain Y Velocity = -$01 (sticks to ceiling)
LDA #-$01
STA <Objects_YVel,X
JSR Object_WorldDetectN1 ; Detect against world
LDA <Objects_DetStat,X
AND #$08
BNE PRG003_A5CA ; If still detecting ceiling, jump to PRG003_A5CA
; No more ceiling!
INC Objects_Var7,X ; Var7++
LDA Objects_Var7,X
CMP #$02
BGE PRG003_A5DB ; If Var7 >= 2, jump to PRG003_A5DB
JSR Object_AboutFace ; Turn around
JSR Object_ApplyXVel ; Apply X velocity
JMP PRG003_A5CF ; Jump to PRG003_A5CF
PRG003_A5CA:
; Var7 = 0
LDA #$00
STA Objects_Var7,X
PRG003_A5CF:
JSR Level_ObjCalcXDiffs
LDA <Temp_Var16
ADD #$30
CMP #$60
BGE PRG003_A5EF ; If Player is not close enough, jump to PRG003_A5EF
PRG003_A5DB:
; Go into "kicked" state!
LDA #OBJSTATE_KICKED
STA Objects_State,X
LDA ObjGroupRel_Idx
ASL A ; 2 byte index for ObjectGroup02_CollideJumpTable
TAY ; Y = offset into ObjectGroup_CollideJumpTable
LDA ObjectGroup02_CollideJumpTable,Y
STA Level_ObjectID,X ; Change into the appropriate target object
; Halt horizontal movement
LDA #$00
STA <Objects_XVel,X
PRG003_A5EF:
LDA <Objects_DetStat,X
AND #$03
BEQ PRG003_A5F8 ; If object has not hit a wall, jump to PRG003_A5F8
JSR Object_AboutFace ; Otherwise, turn around...
PRG003_A5F8:
RTS ; Return
; Unused data I think? Possibly was for the twirling shell
PRG003_A5F9:
.byte $00, $40, $00, $00, $40, $40, $00, $40
TwirlShell_Draw:
JSR Object_SetHFlipByXVel ; Set horizontal flip by travel direction
LDA Objects_Frame,X
CMP #$02
BLT PRG003_A613 ; If frame < 2, jump to PRG003_A613
; Clear horizontal flip on frame 2+
LDA Objects_FlipBits,X
AND #~SPR_HFLIP
STA Objects_FlipBits,X
PRG003_A613:
JMP Object_ShakeAndDraw ; Draw shelled enemy and don't come back!
ObjInit_DonutLift:
RTS ; Return
ObjNorm_DonutLift:
JSR Object_SetPaletteFromAttr ; Set palette
LDY #$5a ; Y = $5A (Patterns for donut lift, vertical only)
LDA Level_7Vertical
BNE PRG003_A62A ; If this level is vertical, jump to PRG003_A62A
LDA Level_TilesetIdx
CMP #$01
BNE PRG003_A62D ; If tileset is not Mini-Fortress style, jump to PRG003_A62D
LDY #$12 ; Y = $12 (Patterns for donut lift, Mini-Fortress only)
PRG003_A62A:
; Mini-Fortress or vertical orientation only...
STY PatTable_BankSel+4
PRG003_A62D:
JSR Object_AnySprOffscreen
BNE PRG003_A64E ; If object falls off-screen at all, jump to PRG003_A64E (destroys it)
JSR Object_ShakeAndDraw ; Draw donut lift
LDA <Player_HaltGame
BNE PRG003_A651 ; If gameplay is halted, jump to PRG003_A651 (RTS)
LDA Objects_Var7,X
BNE PRG003_A66A ; If Var7 is non-zero, jump to PRG003_A66A
JSR Object_HitTest ; Do Player to object collision test
LDA Objects_PlayerHitStat,X
BNE PRG003_A652 ; If Player is not touching object, jump to PRG003_A652
LDA Level_ChgTileEvent
BNE PRG003_A651 ; If a tile change event is active, jump to PRG003_A651
JSR DonutLift_ChangeBlock ; Do block change
PRG003_A64E:
JSR Object_SetDeadEmpty ; Mark as dead/empty
PRG003_A651:
RTS ; Return
PRG003_A652:
DEC <Objects_Var5,X ; Var5--
BNE PRG003_A65A ; If Var5 > 0, jump to PRG003_A65A
INC Objects_Var7,X ; Var7++
RTS ; Return
PRG003_A65A:
LDA <Counter_1
AND #$07
STA Objects_Timer4,X ; Timer4 = 0 to 7
LDA Objects_PlayerHitStat,X
BEQ PRG003_A669 ; If Player has not touched donut lift, jump to PRG003_A669 (RTS)
JSR PRG003_A67C
PRG003_A669:
RTS ; Return
PRG003_A66A:
JSR Object_ApplyYVel_NoLimit ; Apply Y limit
LDA <Objects_YVel,X
CMP #$40
BGS PRG003_A677 ; If donut lift is moving downward faster than $40, jump to PRG003_A677
; Gravity
INC <Objects_YVel,X
INC <Objects_YVel,X
PRG003_A677:
JSR Object_HitTest ; Do Player to object collision detection
BCC PRG003_A691 ; If no collision, jump to PRG003_A691 (RTS)
PRG003_A67C:
LDA <Player_YVel
BMI PRG003_A691 ; If Player is moving upward, jump to PRG003_A691 (RTS)
; Otherwise, lock Player at 31 pixels above donut lift
LDA <Objects_Y,X
SUB #31
STA <Player_Y
LDA <Objects_YHi,X
SBC #$00
STA <Player_YHi
; Player is not in air
LDA #$00
STA <Player_InAir
PRG003_A691:
RTS ; Return
DonutLift_ChangeBlock:
; Queue tile change event
LDA #CHNGTILE_DELETEDONUT
STA Level_ChgTileEvent
; Block change to occur at Y+1
LDA <Objects_Y,X
ADD #$01
STA Level_BlockChgYLo
LDA <Objects_YHi,X
ADC #$00
STA Level_BlockChgYHi
LDA <Objects_XHi,X
STA Level_BlockChgXHi
LDA <Objects_X,X
STA Level_BlockChgXLo
RTS ; Return
; Bob-omb's starting X velocity depending on where Player is
BobOmb_StartXVel: .byte $08, -$08
; Bob-omb's starting X velocity depending on where Player is
BobOmbExp_StartXVel: .byte $10, -$10
ObjInit_BobOmb:
JSR Level_ObjCalcXDiffs
; Start Bob-omb moving towards Player
LDA BobOmb_StartXVel,Y
STA <Objects_XVel,X
RTS ; Return
ObjInit_BobOmbExplode:
JSR Level_ObjCalcXDiffs
; Start Bob-omb moving towards Player
LDA BobOmbExp_StartXVel,Y
STA <Objects_XVel,X
INC Objects_Var7,X ; Var7 = 1 for exploding Bob-omb!
RTS ; Return
ObjNorm_BobOmb:
JSR Object_DeleteOffScreen ; Delete object if it falls too far off-screen
LDA <Objects_Var5,X
CMP #$02
BEQ PRG003_A6DD ; If Var5 = 2 (Exploding), jump to PRG003_A6DD
JSR Object_ShakeAndDraw ; Normally draw Bob-omb (Except when exploding)
LDA <Player_HaltGame
BNE PRG003_A6E8 ; If gameplay halted, jump to PRG003_A6E8 (RTS)
JSR Object_SetHFlipByXVel ; Set horizontal flip by travel direction
PRG003_A6DD:
LDA <Objects_Var5,X
JSR DynJump
; THESE MUST FOLLOW DynJump FOR THE DYNAMIC JUMP TO WORK!!
.word BobOmb_WalkAround ; 0: Unsquashed Bob-omb minding his own business
.word BobOmb_FlashToExplode ; 1: Squashed Bob-omb who then flashes and explodes
.word BobOmb_DoExplosion ; 2: Do the explosion, kill things, etc.
PRG003_A6E8:
RTS ; Return
BobOmb_WalkAround:
JSR Object_Move ; Do standard movements
LDA Objects_Var7,X
BEQ PRG003_A6FF ; If Var7 = 0 (Bob-omb not ready to explode), jump to PRG003_A6FF
; Bob-omb has been squashed and ready to blow!
LDA Objects_Timer3,X
ORA <Objects_Var5,X
BNE PRG003_A6FF ; If timer 3 not expired or Var5 <> 0 (initial internal state), jump to PRG003_A6FF
INC <Objects_Var5,X ; Var5++ (next internal state)
; Set timer to $60
LDA #$60
STA Objects_Timer,X
PRG003_A6FF:
LDA <Objects_DetStat,X
AND #$04
BEQ PRG003_A730 ; If Bob-omb's not on the ground, jump to PRG003_A730
LDA #-$20
STA <Objects_YVel,X
LDY #$00 ; Y = 0
LDA <Counter_1
AND #$08
BEQ PRG003_A712 ; 8 ticks on, 8 ticks off; jump to PRG003_A712
INY ; Y = 1
PRG003_A712:
; Little walking frame
TYA
STA Objects_Frame,X
JSR Object_HitGround ; Align to floor
LDA Objects_Var7,X
BEQ PRG003_A730 ; If Var7 = 0 (not ready to explode), jump to PRG003_A730
INC Objects_Var3,X ; Var3++
LDA Objects_Var3,X
AND #$3f
BNE PRG003_A730 ; Every 1:64 ticks proceed, otherwise jump to PRG003_A730
JSR Level_ObjCalcXDiffs
; March toward Player
LDA BobOmbExp_StartXVel,Y
STA <Objects_XVel,X
PRG003_A730:
LDA <Objects_DetStat,X
AND #$03
BEQ PRG003_A739 ; If Bob-omb has not hit wall, jump to PRG003_A739
JSR Object_AboutFace ; Otherwise, turn around
PRG003_A739:
JSR Object_HandleBumpUnderneath
BCC PRG003_A75E ; If Bob-omb wasn't hit from underneath, jump to PRG003_A75E
LDA Objects_PlayerHitStat,X
BEQ PRG003_A75E ; If Player didn't touch Bob-omb, jump to PRG003_A75E (RTS)
LDA Player_Kuribo
BEQ PRG003_A74B ; If Player is not in Kuribo's shoe, jump to PRG003_A74B
JMP BobOmb_Kill ; Jump to BobOmb_Kill
PRG003_A74B:
INC <Objects_Var5,X
LDA #$ff
STA Objects_Timer,X
LDA #$08
STA Objects_Timer2,X
; Little bounce for the Player
LDA #-$30
STA <Player_YVel
JMP PRG003_A7FE ; Just do Bob-omb death
PRG003_A75E:
RTS ; Return
PRG003_A75F:
.byte $10, $20, $30, $40, $FC, $F8, $F4, $F0
BobOmb_FlashToExplode:
; Toggles between frames 2 and 3, but these are indiscernable,
; both look like the "eyes closed, footless" Bob-omb...
; Maybe was supposed to animate crank or something?
LDY #$02 ; Y = 2
LDA <Counter_1
AND #$08
BEQ PRG003_A770 ; 8 ticks on, 8 ticks off; jump to PRG003_A770
INY ; Y = 3
PRG003_A770:
TYA
STA Objects_Frame,X
LDA Objects_Timer,X
BNE PRG003_A798 ; If timer not expired, jump to PRG003_A798
; Timer expired...
BobOmb_Explode:
; Var3 = 0
LDA #$00
STA Objects_Var3,X
; Set internal state to 2
LDA #$02
STA <Objects_Var5,X
; Reset timer to $28 (length of explosion)
LDA #$28
STA Objects_Timer,X
; Ba-boom
LDA Sound_QLevel1
ORA #SND_LEVELBABOOM
STA Sound_QLevel1
; Since Bob-omb is exploding, he no longer needs to enforce his pattern bank
INC Objects_DisPatChng,X
SetRotatingColor:
LDA #$10
STA RotatingColor_Cnt
RTS ; Return
PRG003_A798:
; Bob-omb's timer hasn't gone out yet...
CMP #$40
BGE PRG003_A79F ; If timer >= $40, jump to PRG003_A79F
STA Objects_ColorCycle,X ; Otherwise, start flashing
PRG003_A79F:
JSR Object_Move ; Do standard movements
LDA <Objects_DetStat,X
AND #$04
BEQ PRG003_A7CC ; If Bob-omb has not hit floor, jump to PRG003_A7CC
; This whole block works to get the X velocity arithmetically divided by 2
LDA <Objects_XVel,X
PHP ; Save CPU state
; Get absolute value of X velocity
BPL PRG003_A7B0
JSR Negate
PRG003_A7B0:
LSR A ; Divide by 2
PLP ; Restore CPU state
BPL PRG003_A7B7 ; If the X velocity was positive, jump to PRG003_A7B7
JSR Negate ; Otherwise, make this negative again
PRG003_A7B7:
STA <Objects_XVel,X ; X velocity now divided by 2
LDA <Objects_YVel,X
PHA ; Save Y velocity
JSR Object_HitGround ; Align to floor
PLA ; Restore Y velocity
BMI PRG003_A7CC ; If it's negative, jump to PRG003_A7CC
; Bob-omb was falling downward...
LSR A ; Divide by 2
JSR Negate ; Negate it (bounce back up)
CMP #$fc
BGE PRG003_A7CC ; If the velocity was small enough, then just stop
STA <Objects_YVel,X ; Otherwise, bounce away
PRG003_A7CC:
LDA <Objects_DetStat,X
AND #$03
BEQ PRG003_A7DC ; If Bob-omb did not hit a wall, jump to PRG003_A7DC
; Otherwise bounce off
LDA <Objects_XVel,X
JSR Negate
STA <Objects_XVel,X
; ... and sort of arithmetically divide by 2
ASL A
ROR <Objects_XVel,X
PRG003_A7DC:
JSR Object_HitTest
BCC PRG003_A7F0 ; If Player and Bob-omb didn't collide, jump to PRG003_A7F0 (RTS)
LDA Objects_Timer2,X
BNE PRG003_A7F0 ; If timer2 has not expired, jump to PRG003_A7F0 (RTS)
LDA Player_Kuribo
BNE BobOmb_Kill ; If Player is in Kuribo's shoe, kill Bob-omb, jump to BobOmb_Kill
; Otherwise, set Bob-omb's state to 4 (Held, doesn't really make sense)
LDA #OBJSTATE_HELD
STA Objects_State,X
PRG003_A7F0:
RTS ; Return
BobOmb_Kill:
; Player bounces
LDA #-$30
STA <Player_YVel
; Set Bob-omb state to Killed
LDA #OBJSTATE_KILLED
STA Objects_State,X
; A little bounce from the Bob-omb
LDA #-$10
STA <Objects_YVel,X
PRG003_A7FE:
LDA Kill_Tally
INC Kill_Tally
JSR Score_Get100PlusPts ; Get score according to Kill Tally
; "Kick" noise
LDA Sound_QPlayer
ORA #SND_PLAYERKICK
STA Sound_QPlayer
RTS ; Return
; X and Y offsets for the exploding Bob-omb stars
BombStars_XOff: .byte -$04, $04, $08, $04, -$04, -$08, $00, $08, $08, $00, -$08, -$08
BombStars_YOff: .byte -$08, -$08, $00, $08, $08, $00, $08, $04, -$04, -$08, -$04, $04
BobOmb_DoExplosion:
LDA <Player_HaltGame
BNE PRG003_A82E ; If gameplay is halted, jump to PRG003_A82E
INC <Objects_Var4,X ; Otherwise, Var4++
PRG003_A82E:
LDA Objects_Timer,X
BNE PRG003_A836 ; If timer has not expired, jump to PRG003_A836
JMP Object_SetDeadEmpty ; Otherwise, mark Bob-omb as Dead/Empty and don't come back!
PRG003_A836:
JSR Object_CalcSpriteXY_NoHi
; Temp_Var16 = 5
LDA #$05
STA <Temp_Var16
PRG003_A83D:
; Temp_Var1 = Bob-omb's sprite Y
LDA <Objects_SpriteY,X
STA <Temp_Var1
; Temp_Var2 = Bob-omb's sprite X + 4
LDA <Objects_SpriteX,X
ADD #$04
STA <Temp_Var2
LDA <Objects_Var4,X
LSR A ; Var4 / 2
PHA ; Save value
; Temp_Var3 = 0 to 3, depending on Var4 / 2
AND #$03
STA <Temp_Var3
LDX <Temp_Var16 ; X = Temp_Var16
PLA ; Restore Var4 / 2
AND #$04 ; Mask 0-3
BEQ PRG003_A85C ; If result is zero, jump to PRG003_A85C
; Otherwise, X += 6
TXA
ADD #$06
TAX
PRG003_A85C:
LDA <Temp_Var1
ADD BombStars_YOff,X
STA <Temp_Var1
LDA <Temp_Var2
ADD BombStars_XOff,X
STA <Temp_Var2
DEC <Temp_Var3 ; Temp_Var3--
BPL PRG003_A85C ; While Temp_Var3 >= 0, loop!
LDX <SlotIndexBackup ; X = object slot index
JSR Sprite_NoCarryIfVisible
BCS PRG003_A89D ; If this star is not visible, jump to PRG003_A89D
LDA <Temp_Var16
ASL A
ASL A ; A = Temp_Var16 * 4 (one sprite per star)
ADC Object_SprRAM,X ; Add the base Sprite_RAM offset
TAY ; -> 'Y'
; Star Y
LDA <Temp_Var1
STA Sprite_RAM+$00,Y
; Star X
LDA <Temp_Var2
STA Sprite_RAM+$03,Y
; Star pattern
LDA #$73
STA Sprite_RAM+$01,Y
LDA <Counter_1
LSR A
LSR A
ADD <SlotIndexBackup
AND #$03 ; Palette select 0 to 3
STA Sprite_RAM+$02,Y ; Set attributes
JSR PRG003_BD1E ; Uses part of the "Tail" hurt code, checks if Player has been hit by explosion
PRG003_A89D:
DEC <Temp_Var16 ; Temp_Var16--
BPL PRG003_A83D ; While Temp_Var16 >= 0, loop!
JSR Object_AnySprOffscreen
BNE PRG003_A8D2 ; If any part of the exploding Bob-omb has fallen off-screen, jump to PRG003_A8D2
JSR BobOmb_CalcULOffXY ; (large bounding box for explosion)
; Temp_Var13 = 0
LDA #$00
STA <Temp_Var13
JSR PRG000_DC09 ; Object-to-object collision test sans visibility check and bounding box calculation
BCC PRG003_A8D2 ; If there hasn't been a collision, jump to PRG003_A8D2 (RTS)
; "Kick" sound
LDA Sound_QPlayer
ORA #SND_PLAYERKICK
STA Sound_QPlayer
; Set object to state Killed
LDA #OBJSTATE_KILLED
STA Objects_State,Y
; Killed object bounces up a bit
LDA #-$30
STA Objects_YVel,Y
; Halt horizontal movement
LDA #$00
STA Objects_XVel,Y
; Var3 works as a kill counter for things killed by the explosion
LDA Objects_Var3,X
INC Objects_Var3,X
JSR Score_Get100PlusPtsY ; Get score for that
PRG003_A8D2:
RTS ; Return
; Calculates an upper left X/Y offset
BobOmb_CalcULOffXY:
; Temp_Var3 = Bob-omb's Sprite X - 24
LDA <Objects_SpriteX,X
SUB #24
STA <Temp_Var3
; Temp_Var7 = Bob-omb's Sprite Y - 24
LDA <Objects_SpriteY,X
SUB #24
STA <Temp_Var7
; Temp_Var4 and Temp_Var8 = $40
LDA #$40
STA <Temp_Var4
STA <Temp_Var8
RTS ; Return
ObjNorm_BoomBoomQBall:
LDY Objects_Timer,X ; Y = timer
BEQ PRG003_A8FF ; If timer expired, jump to PRG003_A8FF
; This timer is active after time has been converted to score,
; in that momentary pause after that before exiting
STY Player_VibeDisable ; Cause Player to be vibrationally disabled
DEY ; Y--
BNE PRG003_A8FE ; If timer > 1, jump to PRG003_A8FE (RTS)
; Y = 0 at this point...
STY Map_ReturnStatus ; Map_ReturnStatus = 0 (clear level)
; Set the lock busting / bridge building effect for this ball
LDA <Objects_Var4,X
STA Map_DoFortressFX
INC Level_ExitToMap ; Flag to exit to map
PRG003_A8FE:
RTS ; Return
PRG003_A8FF:
LDA <Objects_Var5,X
BEQ PRG003_A911 ; If Var5 = 0, jump to PRG003_A911
STA Player_VibeDisable ; Clear Player vibrationally disabled flag
JSR DoTimeBonus ; Convert remaining time into score
BNE PRG003_A910 ; If not done converting, jump to PRG003_A910 (RTS)
; Set timer to $40
LDA #$40
STA Objects_Timer,X
PRG003_A910:
RTS ; Return
PRG003_A911:
LDA <Player_HaltGame
BNE PRG003_A92D ; If gameplay is halted, jump to PRG003_A92D
LDA <Objects_YVel,X
BMI PRG003_A92D ; If ball moving upwards, jump to PRG003_A92D
JSR Object_HitTest
BCC PRG003_A92D ; If Player is not touching it, jump to PRG003_A92D
; A living Player has grabbed it!
INC <Objects_Var5,X ; Var5++
; Do the color cycle effect
LDA #$1e
STA RotatingColor_Cnt
; Victory fanfare
LDA Sound_QMusic1
ORA #MUS1_BOSSVICTORY
STA Sound_QMusic1
PRG003_A92D:
JSR Object_ShakeAndDraw ; Draw it
Object_DoMoveBounceConveyor:
JSR Object_Move ; Do standard movements
LDA <Objects_DetStat,X
AND #$04
BEQ ObjInit_BoomBoomQBall ; If ball hasn't hit ground, jump to ObjInit_BoomBoomQBall (RTS)
LDA Level_ObjectID,X
CMP #OBJ_BOOMBOOMQBALL
BNE PRG003_A946 ; If this isn't a Boom Boom ball, jump to PRG003_A946
LDA <Objects_Y,X
CMP #$70
BLT ObjInit_BoomBoomQBall ; If ball is higher than $70, jump to ObjInit_BoomBoomQBall
PRG003_A946:
JSR Object_HandleConveyorCarry ; Carry ball along conveyor
LDA <Objects_YVel,X
PHA ; Save Y velocity
JSR Object_HitGround ; Align to floor
PLA ; Restore Y velocity
LSR A
LSR A ; Current Y velocity / 4
JSR Negate ; Bounce at a quarter of impact
CMP #$fe
BCS ObjInit_BoomBoomQBall ; If the bounce is really small, jump to ObjInit_BoomBoomQBall (RTS)
STA <Objects_YVel,X ; Update Y velocity for a bounce
ObjInit_BoomBoomQBall:
RTS ; Return
ObjNorm_FloatingBGCloud:
LDA <Player_HaltGame
BNE PRG003_A98C ; If gameplay is halted, jump to PRG003_A98C
JSR Object_DeleteOffScreen ; Delete object if it falls too far off-screen
JSR PRG003_A98C
JSR Object_ApplyXVel ; Apply X velocity
JMP Fish_FixedY_ExceptHitFloor ; Jump to Fish_FixedY_ExceptHitFloor and don't come back
FloatingBGCloud_Patterns:
.byte $B7, $B9, $FF, $71, $71, $71, $01, $01
.byte $B7, $B9, $B9, $FF, $71, $71, $01, $01
.byte $B7, $B9, $B9, $B9, $FF, $71, $01, $01
.byte $B7, $B9, $B9, $B9, $B9, $FF, $01, $01
PRG003_A98C:
; Temp_Var16 = 0
LDA #$00
STA <Temp_Var16
JSR Object_CalcSpriteXY_NoHi
; Temp_Var1 = Sprite Y - 1
LDA <Objects_SpriteY,X
SUB #$01
STA <Temp_Var1
; Temp_Var2 = Sprite X
LDA <Objects_SpriteX,X
STA <Temp_Var2
PRG003_A99E:
LDA <Temp_Var2
JSR Sprite_NoCarryIfVisible
BCS PRG003_A9DA ; If carry set, not visible, jump to PRG003_A9DA
LDA <Temp_Var16
ASL A
ASL A ; Temp_Var16 * 4 (index by sprite)
ADC Object_SprRAM,X ; Add base offset into Sprite_RAM
TAY ; -> 'Y'
LDA <Objects_Var5,X
ASL A
ASL A
ASL A ; A = Var5 * 8 (base index)
ADC <Temp_Var16 ; Add loop index
TAX ; -> 'X'
LDA FloatingBGCloud_Patterns,X ; Get this pattern
LDX <SlotIndexBackup ; X = object slot index
CMP #$71
BEQ PRG003_A9DA ; If pattern is $71, jump to PRG003_A9DA
CMP #$ff
BLT PRG003_A9C4 ; If pattern < $FF, jump to PRG003_A9C4
LDA #$b7 ; Otherwise, use pattern $B7
PRG003_A9C4:
STA Sprite_RAM+$01,Y ; Store pattern
LDA #$22 ; A = $22 (last pattern < $FF)
BLT PRG003_A9CD ; If last pattern < $FF, jump to PRG003_A9CD
ORA #SPR_HFLIP ; Otherwise, apply horizontal flip
PRG003_A9CD:
STA Sprite_RAM+$02,Y ; Store attributes
; Store Y
LDA <Temp_Var1
STA Sprite_RAM+$00,Y
; Store X
LDA <Temp_Var2
STA Sprite_RAM+$03,Y
PRG003_A9DA:
; X += 8 (next sprite over)
LDA <Temp_Var2
ADD #$08
STA <Temp_Var2
INC <Temp_Var16 ; Temp_Var16++
LDA <Temp_Var16
CMP #$06
BNE PRG003_A99E ; If loop counter <> 6, loop!
RTS ; Return
ObjInit_BoomBoom:
; Set Var4 to Boom Boom's Y Hi -- this will select which value goes into Map_DoFortressFX
; So if Boom Boom's Y Hi is 1, then Map_DoFortressFX = 1, etc.
; The actual assignment to Map_DoFortressFX is done with the (?) ball after Boom Boom is defeated
LDA <Objects_YHi,X
STA <Objects_Var4,X
; Boom Boom will always appear at Y Hi = 1 (since this was used as a parameter)
LDA #$01
STA <Objects_YHi,X
STA Objects_IsGiant,X ; Boom Boom is considered a "giant" enemy
; Boom Boom requires 37 fire balls before going down
LDA #37
STA Objects_HitCount,X
; Boom Boom starts on frame 7
LDA #$07
STA Objects_Frame,X
ObjInit_FloatingBGCloud:
RTS ; Return
BoomBoom_TowardsPlayerXVel: .byte $10, -$10
BoomBoom_FinalAttackXVel:
.byte $20, -$20, $18, -$18 ; First two values are for any world besides World 1, last two are World 1 only
BoomBoom_GetupFrames:
.byte $0A, $06, $07, $07, $07, $07, $06, $0A, $10, $14
.byte $15, $15, $15, $15, $14, $10
ObjNorm_BoomBoom:
; Boom Boom's graphics
LDA #$4d
STA PatTable_BankSel+4
LDA Level_TilesetIdx
CMP #11
BNE PRG003_AA25 ; If Level_TilesetIdx <> 11 (ice level), jump to PRG003_AA25
STA Objects_Var2,X ; Var2 = 11
PRG003_AA25:
LDA Objects_HitCount,X
CMP #$20
BNE PRG003_AA3B ; If HitCount <> $20, jump to PRG003_AA3B
DEC Objects_HitCount,X ; HitCount--
; Var5 = 5
LDA #$05
STA <Objects_Var5,X
; Timer = $50
LDA #$50
STA Objects_Timer,X
JMP BoomBoom_Draw ; Draw Boom Boom and don't come back
PRG003_AA3B:
JSR BoomBoom_Draw ; Draw Boom Boom
JSR Object_DeleteOffScreen ; Delete object if it falls too far off-screen
JSR Object_CheckIfNormalState
BEQ PRG003_AA5D ; If Boom Boom is in normal state, jump to PRG003_AA5D
; Not normal state... any state not normal is considered Boom Boom has
; been killed, and as such will cause him to turn into the "(?)" ball.
LDA <Objects_Var5,X
BEQ PRG003_AA5D ; If Var5 = 0, jump to PRG003_AA5D
; Set state Normal (for the end ball)
LDA #OBJSTATE_NORMAL
STA Objects_State,X
LDA #$70
STA <Objects_Y,X
STA <Objects_X,X
LDA #$01
STA <Objects_YHi,X
LSR A ; A = 0
JMP PRG003_AE95 ; Jump to PRG003_AE95
PRG003_AA5D:
LDA <Player_HaltGame
BNE ObjInit_FloatingBGCloud ; If gameplay halted, jump to ObjInit_FloatingBGCloud (RTS)
LDA <Objects_Var5,X
CMP #$05
BEQ PRG003_AAD9 ; If Var5 (internal state) = 5, jump to PRG003_AAD9
; Var5 (Internal state) < 5...
LDY Objects_Timer2,X
BEQ PRG003_AA92 ; If timer 2 expired, jump to PRG003_AA92
DEY ; Y--
BNE PRG003_AA72 ; If Y > 0, jump to PRG003_AA72
JSR BoomBoom_ResetVar6 ; Sets Var6 to $2F
PRG003_AA72:
LDY #$08 ; Y = 8
; Boom Boom's squashed wiggle frames
LDA <Counter_1
AND #$04
BEQ PRG003_AA7B ; On for 4 ticks, off 4 ticks; jump to PRG003_AA7B every other
INY ; Y = 9
PRG003_AA7B:
LDA Level_ObjectID,X
CMP #OBJ_BOOMBOOMFLY
BNE PRG003_AA8D ; If this is not a flying Boom Boom, jump to PRG003_AA8D
LDA <Objects_Var5,X
CMP #$03
BNE PRG003_AA8D ; If Var5 (Internal State) <> 3, jump to PRG003_AA8D
; Add 10 to 'Y' (Boom Boom's wings appear)
TYA
ADD #$0a
TAY
PRG003_AA8D:
; Set frame
TYA
STA Objects_Frame,X
RTS ; Return
PRG003_AA92:
LDA Objects_Var6,X
BEQ PRG003_AAD3 ; If Var6 = 0, jump to PRG003_AAD3
DEC Objects_Var6,X
LSR A
LSR A
LSR A
TAY ; Y = Var6 / 8
; Set frames while Boom Boom is "getting up"
LDA BoomBoom_GetupFrames,Y
STA Objects_Frame,X
LDA Objects_Var6,X
CMP #$10
BNE PRG003_AABC ; If Var6 <> $10, jump to PRG003_AABC
; Boom Boom hops a bit when he gets up
LDA #-$2D
STA <Objects_YVel,X
LDA Objects_Var2,X
BNE PRG003_AABC ; If Var2 <> 0, jump to PRG003_AABC
JSR Level_ObjCalcXDiffs
; Set X Velocity towards Player
LDA BoomBoom_TowardsPlayerXVel,Y
STA <Objects_XVel,X
PRG003_AABC:
LDA <Counter_1
LSR A
BCC PRG003_AACD ; Every other tick, jump to PRG003_AACD
LDA <Objects_XVel,X
BEQ PRG003_AACD ; If Boom Boom is not moving horizontally, jump to PRG003_AACD
BPL PRG003_AACB ; If moving to the right, jump to PRG003_AACB
; Moving to the left...
; Double increment because it hits the decrement, basically a single increment
INC <Objects_XVel,X ; Moving left, slow down
INC <Objects_XVel,X
PRG003_AACB:
DEC <Objects_XVel,X ; Moving right, slow down
PRG003_AACD:
JSR BoomBoom_HitTest ; Test for collisions between Player and Boom Boom
JMP PRG003_AB8E ; Jump to PRG003_AB8E
PRG003_AAD3:
JSR BoomBoom_HitTest ; Test for collisions between Player and Boom Boom
INC Objects_Var3,X ; Var3++
PRG003_AAD9:
LDA <Objects_Var5,X ; Var5 is internal state for Boom Boom
JSR DynJump
; THESE MUST FOLLOW DynJump FOR THE DYNAMIC JUMP TO WORK!!
.word BoomBoom_Init ; 0: Initial state, wait for Player
.word BoomBoom_Unused ; 1: Lost state? Never used, just goes to state 2
.word BoomBoom_PrimaryAttack ; 2: Boom Boom's run around with fists flailing
.word BoomBoom_SeconaryAttack ; 3: Boom Boom jumps about or flies, depending
.word BoomBoom_FinalAttack ; 4: Second hit
.word BoomBoom_Death ; 5: Kaboom Death
BoomBoom_Init:
; Boom Boom awaits in his crouch frame
LDA #$07
STA Objects_Frame,X
STA Objects_SprHVis,X ; ??
LDA <Horz_Scroll
CMP #$07
BGE PRG003_AB1E ; If the horizontal scroll is any greater than 7, jump to PRG003_AB1E (RTS) (Waits for screen to come around to Boom Boom)
; Lock horizontal scroll to zero point
LDA #$00
STA <Horz_Scroll
; Halt Player horizontally
LDY #$00
STY <Player_XVel
LDA <Player_InAir
BNE PRG003_AB1E ; If Player is not on ground, jump to PRG003_AB1E (RTS)
STA Level_PSwitchCnt ; Cancel any active P-Switch
; Play boss music
LDA Sound_QMusic2
ORA #MUS2B_BOSS
STA Sound_QMusic2
; Lock horizontal scrolling
INC LevelJctBQ_Flag
; Lock vertical scrolling
LDA #$02
STA Level_FreeVertScroll
; Var5 = 2
STA <Objects_Var5,X
BoomBoom_ResetVar6:
; Var6 = $2F
LDA #$2f
STA Objects_Var6,X
PRG003_AB1E:
RTS ; Return
BoomBoom_Unused:
INC <Objects_Var5,X ; Just jumps to state 2
RTS ; Return
BoomBoom_XVelLimit: .byte $10, -$10 ; Boom Boom primary attack limits
BoomBoom_XVelFastLimit: .byte $30, -$30 ; Boom Boom final attack limits
BoomBoom_XVelAccel: .byte $01, -$01 ; Boom Boom primary attack acceleration
BoomBoom_XVelFastAccel: .byte $02, -$02 ; Boom Boom final attack acceleration
BoomBoom_PrimaryAttack:
LDA Objects_Var2,X
BEQ PRG003_AB52 ; If Var2 = 0, jump to PRG003_AB52
JSR Level_ObjCalcXDiffs
LDA <Objects_XVel,X
CMP BoomBoom_XVelLimit,Y
BEQ PRG003_AB42 ; If Boom Boom is at his X velocity limit, jump to PRG003_AB42
; Boom Boom X velocity not at his limit...
ADD BoomBoom_XVelAccel,Y ; Accelerate
STA <Objects_XVel,X ; Update X velocity
; While Boom Boom is accelerating...
INC Objects_Var3,X ; Var3++
PRG003_AB42:
INC Objects_Var1,X ; Var1++
LDA Objects_Var1,X
BNE PRG003_AB4F ; If Var1 has not overflowed, jump to PRG003_AB4F
; When Var1 overflows, Boom Boom goes back into his shell
; Var6 = $3F
LDA #$3f
STA Objects_Var6,X
PRG003_AB4F:
JMP PRG003_AB78 ; Jump to PRG003_AB78
PRG003_AB52:
INC Objects_Var1,X ; Var1++
LDA Objects_Var1,X
BNE PRG003_AB6C ; If Var1 has not overflowed, jump to PRG003_AB6C
; Var6 = $3F
LDA #$3f
STA Objects_Var6,X
JSR Level_ObjCalcXDiffs
; Boom Boom slides a bit when he jumps back in his shell
LDA BoomBoom_XVelSlide,Y
STA <Objects_XVel,X
JMP PRG003_AA92 ; Jump to PRG003_AA92
BoomBoom_XVelSlide: .byte $20, -$20
PRG003_AB6C:
AND #$3f
BNE PRG003_AB78 ; 1:64 counts on Var1 proceed, otherwise jump to PRG003_AB78
; Shift Boom Boom's horizontal direction towards Player
JSR Level_ObjCalcXDiffs
LDA BoomBoom_TowardsPlayerXVel,Y
STA <Objects_XVel,X
PRG003_AB78:
LDA Objects_Var3,X
AND #$03
BNE PRG003_AB8E ; Proceed 1:4 Var3 counts, otherwise jump to PRG003_AB8E
INC Objects_Frame,X ; Boom Boom's frame++
; Loop frames 0-6
LDA Objects_Frame,X
CMP #$06
BLT PRG003_AB8E ; If Boom Boom frame < 6, jump to PRG003_AB8E
LDA #$00
STA Objects_Frame,X
PRG003_AB8E:
JSR Object_Move ; Boom Boom does standard movements
LDA <Objects_DetStat,X
AND #$04
BEQ PRG003_AB9A ; If Boom Boom did not hit the ground, jump to PRG003_AB9A
JSR Object_HitGround ; Align to floor
PRG003_AB9A:
LDA <Objects_DetStat,X
AND #$08
BEQ PRG003_ABC3 ; If Boom Boom has not hit ceiling, jump to PRG003_ABC3
; Boom Boom Y Vel = 1, i.e. hit off ceiling
LDA #$01
STA <Objects_YVel,X
; Set tile detection coordinates
LDA <Objects_X,X
ADD #$08
STA ObjTile_DetXLo
LDA <Objects_XHi,X
STA ObjTile_DetXHi
LDA <Objects_Y,X
ADC #$0c
STA ObjTile_DetYLo
LDA #$01
STA ObjTile_DetYHi
LDA Object_TileFeet2
JSR Object_BumpBlocks ; Boom Boom can hit blocks! (???)
PRG003_ABC3:
LDA <Objects_DetStat,X
AND #$03
BNE PRG003_ABDB ; If Boom Boom has hit a wall, jump to PRG003_ABDB
; Boom Boom has not hit a wall...
PRG003_ABC9:
LDA <Objects_XVel,X
BPL PRG003_ABD5 ; If Boom Boom is not moving left, jump to PRG003_ABD5
; Boom Boom is moving leftward...
LDA <Objects_SpriteX,X
CMP #$08
BGE PRG003_ABDE ; If Boom Boom's Sprite X >= 8, jump to PRG003_ABDE (RTS)
BLT PRG003_ABDB ; Otherwise, jump to PRG003_ABDB
PRG003_ABD5:
; Boom Boom is moving rightward...
LDA <Objects_SpriteX,X
CMP #224
BLT PRG003_ABDE ; If Boom Boom's Sprite X < 224, jump to PRG003_ABDE (RTS)
PRG003_ABDB:
JSR Object_AboutFace ; Boom Boom turns around
PRG003_ABDE:
RTS ; Return
BoomBoom_SeconaryAttack:
LDA Level_ObjectID,X
CMP #OBJ_BOOMBOOMFLY
BNE PRG003_ABE9 ; If this is not the flying Boom Boom, jump to PRG003_ABE9
JMP PRG003_AC70 ; Jump to PRG003_AC70
PRG003_ABE9:
; Non-flying Boom Boom
LDA Objects_Var7,X
BEQ PRG003_AC1A ; If Var7 = 0, jump to PRG003_AC1A
LDA <Counter_1
AND #$03
BNE PRG003_AC00 ; Every 1:4 ticks, proceed, otherwise jump to PRG003_AC00
LDA <Objects_XVel,X
BEQ PRG003_AC00 ; If Boom Boom is not moving horizontally, jump to PRG003_AC00
BPL PRG003_ABFE ; If Boom Boom is moving to the right, jump to PRG003_ABFE
; Moving to the left...
; Double increment because it hits the decrement, basically a single increment
INC <Objects_XVel,X ; Moving left, slow down
INC <Objects_XVel,X
PRG003_ABFE:
DEC <Objects_XVel,X ; Moving right, slow down
PRG003_AC00:
; Jump tensing frame
LDA #$0B
STA Objects_Frame,X
DEC Objects_Var7,X ; Var7--
BNE PRG003_AC11 ; If Var7 <> 0, jump to PRG003_AC11
; Boom Boom's jump!
LDA #-$60
STA <Objects_YVel,X
JSR BoomBoom_SetXVelTowardsPlayer ; Jump towards Player
PRG003_AC11:
LDA Objects_Var2,X
BEQ PRG003_AC19 ; If Var2 = 0, jump to PRG003_AC19 (RTS)
JSR Object_ApplyXVel ; Apply X Velocity
PRG003_AC19:
RTS ; Return
PRG003_AC1A:
LDA <Objects_DetStat,X
AND #$04
BNE PRG003_AC23 ; If Boom Boom hit floor, jump to PRG003_AC23
JSR Object_ApplyXVel ; Otherwise, apply X velocity while jumping
PRG003_AC23:
JSR PRG003_AB78 ; Boom Boom flails arms while jumping
LDA <Objects_DetStat,X
AND #$04
BEQ PRG003_AC69 ; If Boom Boom has NOT hit floor, jump to PRG003_AC69 (RTS)
; Boom Boom hit floor...
LDA Objects_Var2,X
BEQ PRG003_AC47 ; If Var2 = 0, jump to PRG003_AC47
JSR Level_ObjCalcXDiffs
LDA <Objects_XVel,X
CMP BoomBoom_XVelLimit,Y
BEQ PRG003_AC44 ; If Boom Boom is at his X velocity limit, jump to PRG003_AC44
ADD BoomBoom_XVelAccel,Y ; Boom Boom accelerates towards Player
STA <Objects_XVel,X ; Update X Velocity
INC Objects_Var3,X ; Var3++
PRG003_AC44:
JMP PRG003_AC4D ; Jump to PRG003_AC4D
PRG003_AC47:
LDA <Counter_1
AND #$3f
BEQ BoomBoom_SetXVelTowardsPlayer ; Every 64 ticks, move towards Player
PRG003_AC4D:
LDA <Counter_1
ADD #$1f ; Offsets counter
ASL A
BNE PRG003_AC69 ; If offset counter has NOT overflowed, jump to PRG003_AC69 (RTS)
LDA #$18 ; A = $18
LDY World_Num
BNE PRG003_AC5D ; If any world besides 1, jump to PRG003_AC5D
ASL A ; Otherwise, A = $36 (World 1 only difficulty modifier)
PRG003_AC5D:
STA Objects_Var7,X ; Set Var7 (ticks tensed until jump)
RTS ; Return
BoomBoom_SetXVelTowardsPlayer:
JSR Level_ObjCalcXDiffs
LDA BoomBoom_TowardsPlayerXVel,Y
STA <Objects_XVel,X
PRG003_AC69:
RTS ; Return
BoomBoom_FlyXVelLimit: .byte $20, -$20
BoomBoom_FlyAccel: .byte $01, -$01
BoomBoom_FlyYVelAccel: .byte $10, -$10
PRG003_AC70:
; Flying Boom Boom
JSR Level_ObjCalcXDiffs
LDA <Objects_XVel,X
CMP BoomBoom_FlyXVelLimit,Y
BEQ PRG003_AC80 ; If flying Boom Boom is at his X velocity limit, jump to PRG003_AC80
; Flying Boom Boom accelerates
ADD BoomBoom_FlyAccel,Y
STA <Objects_XVel,X
PRG003_AC80:
JSR PRG003_ABC9 ; Handle Boom Boom hitting against walls
LDA Objects_Var13,X ; current flight state
JSR DynJump
; THESE MUST FOLLOW DynJump FOR THE DYNAMIC JUMP TO WORK!!
.word BoomBoom_FlightToPlan ; 0: Plan a flight towards the Player
.word BoomBoom_ExecuteFlight ; 1: Execute flight
BoomBoom_FlightToPlan:
JSR Object_ApplyXVel ; Apply X velocity
JSR Object_ApplyYVel_NoLimit ; Apply Y velocity
LDY #$00 ; Y = 0
LDA <Objects_Y,X
CMP #16
BLT PRG003_AC9C ; If Boom Boom's Y < 16, jump to PRG003_AC9C
INY ; Y = 1
PRG003_AC9C:
LDA <Objects_YVel,X
CMP BoomBoom_FlyYVelAccel,Y
BEQ PRG003_ACA9 ; If Boom Boom is flying at his vertical velocity limit, jump to PRG003_ACA9
; Otherwise, accelerate flight
ADD BoomBoom_FlyAccel,Y
STA <Objects_YVel,X
PRG003_ACA9:
LDA <Objects_Y,X
CMP #32
BGE PRG003_ACC2 ; If Boom Boom's Y >= 32, jump to PRG003_ACC2
INC Objects_Var14,X
LDA Objects_Var14,X
BNE PRG003_ACC2 ; If Objects_Var14 <> 0, jump to PRG003_ACC2
JSR BoomBoom_PlanFlight ; Plan a flight towards the Player
INC Objects_Var13,X ; Next flight state
; timer = $18
LDA #$18
STA Objects_Timer,X
PRG003_ACC2:
LDA #$03 ; A = 3
BNE PRG003_ACF0 ; Jump (technically always) to PRG003_ACF0
BoomBoom_ExecuteFlight:
LDA Objects_Timer,X
BEQ PRG003_ACD1 ; If timer expired, jump to PRG003_ACD1
; Set Boom Boom to frame $0C (first frame of flight animation)
LDA #$0c
STA Objects_Frame,X
RTS ; Return
PRG003_ACD1:
JSR Object_ApplyXVel ; Apply X velocity
JSR Object_ApplyYVel_NoLimit ; Apply Y velocity
LDA <Objects_Y,X
CMP #80
BLT PRG003_ACEE ; If Boom Boom's Y < 80, jump to PRG003_ACEE
; Return to initial flight state
LDA #$00
STA Objects_Var13,X
LDA RandomN,X
AND #$03
BNE PRG003_ACEE ; Only 1:4 chance we'll proceed, otherwise jump to PRG003_ACEE
; Set Var6 = $3F
LDA #$3f
STA Objects_Var6,X
PRG003_ACEE:
LDA #$01
PRG003_ACF0:
AND <Counter_1
BNE PRG003_AD03 ; Every other tick, jump to PRG003_AD03 (RTS)
INC Objects_Frame,X ; Frame++
; Boom Boom's flight animation, frames $0C to $12
LDA Objects_Frame,X
CMP #$12
BLT PRG003_AD03 ; If Boom Boom's frame < $12, jump to PRG003_AD03
; Set Boom Boom's frame to $0C
LDA #$0c
STA Objects_Frame,X
PRG003_AD03:
RTS ; Return
BoomBoom_FinalAttack:
INC Objects_Var3,X ; Var3++
JSR PRG003_AB78 ; Reuse some of Boom Boom's primary attack code
LDA <Objects_DetStat,X
AND #$04
BEQ PRG003_AD3E ; If Boom Boom hasn't hit the floor, jump to PRG003_AD3E
LDA Objects_Var2,X
BEQ PRG003_AD29 ; If Var2 = 0, jump to PRG003_AD29
JSR Level_ObjCalcXDiffs
LDA <Objects_XVel,X
CMP BoomBoom_XVelFastLimit,Y
BEQ PRG003_AD28 ; If Boom Boom is at his X velocity limit, jump to PRG003_AD28
ADD BoomBoom_XVelFastAccel,Y ; Boom Boom accelerates towards Player
STA <Objects_XVel,X ; Update X Velocity
INC Objects_Var3,X ; Var3++
PRG003_AD28:
RTS ; Return
PRG003_AD29:
LDA <Counter_1
AND #$1f
BNE PRG003_AD3E ; 1:32 ticks proceed, otherwise jump to PRG003_AD3E
JSR Level_ObjCalcXDiffs
LDA World_Num
BNE PRG003_AD39 ; If World_Num <> 0 (World 1, difficulty modifier), jump to PRG003_AD39
; Otherwise, Y += 2 (World 1 difficulty modifier)
INY
INY
PRG003_AD39:
; Set Boom Boom's X velocity towards Player as appropriate for direction and world
LDA BoomBoom_FinalAttackXVel,Y
STA <Objects_XVel,X
PRG003_AD3E:
RTS ; Return
BoomBoom_PlanFlight:
LDA #$20
JSR BoomBoom_CalcFlightPath ; Calculate a flight plan towards the Player
; Set velocities in accordance with flight plan
LDA <Temp_Var1
STA <Objects_YVel,X
LDA <Temp_Var2
STA <Objects_XVel,X
RTS ; Return
; Boom Boom's left arm patterns
BoomBoom_PatternLeft:
.byte $C9, $D1, $C3, $C3, $CB, $C9, $D5, $DB, $DF, $EB, $C3, $C3, $83, $8B, $71, $83
.byte $8B, $71, $95, $9B, $A3, $A9
; Boom Boom's right arm patterns
BoomBoom_PatternRight:
.byte $C3, $CB, $C9, $C9, $D1, $C3, $D5, $DB, $EB, $DF, $C3, $C3, $83, $8B, $71, $83
.byte $8B, $71, $95, $9B, $A3, $A9
; Boom Boom's left arm Y offset
BoomBoom_SprYOffArmLeft:
.byte $08, $10, $10, $10, $10, $08, $10, $10, $10, $10, $10, $10, $08, $10, $10, $08
.byte $10, $10, $10, $10, $10, $10
; Boom Boom's right arm Y offset
BoomBoom_SprYOffArmRight:
.byte $10, $10, $08, $08, $10, $10, $10, $10, $10, $10, $10, $10, $08, $10, $10, $08
.byte $10, $10, $10, $10, $10, $10
.byte $00, $02, $08, $0E, $10, $0E, $08, $02, $04, $03, $00, $03, $04, $07, $08, $07
PRG003_ADB5:
RTS
BoomBoom_Draw:
; Copy horizontal visibility -> Temp_VarNP0
LDA Objects_SprHVis,X
STA Temp_VarNP0
LDA <Objects_Y,X
PHA ; Save Boom Boom's Y
LDA Objects_Var7,X
BEQ PRG003_ADC8 ; If Var7 = 0, jump to PRG003_ADC8
; Draw +2 pixels down
INC <Objects_Y,X
INC <Objects_Y,X
PRG003_ADC8:
LDA <Objects_X,X
PHA ; Save Boom Boom's X
ADD #$08
STA <Objects_X,X ; Object's X += 8
LDA <Objects_XHi,X
PHA ; Save Boom Boom's X Hi
ADC #$00 ; Apply carry
STA <Objects_XHi,X ; Update X Hi
ASL Objects_SprHVis,X
JSR Object_DrawTallAndHFlip ; Draw large, mirrored sprite
; Restore X Hi
PLA
STA <Objects_XHi,X
; Restore X
PLA
STA <Objects_X,X
; Restore Y
PLA
STA <Objects_Y,X
; Beginning of arm drawing logic
JSR Object_CalcSpriteXY_NoHi
LDY Object_SprRAM,X ; Y = Sprite_RAM offset
LDA Objects_SprVVis,X
BNE PRG003_ADB5 ; If any sprite is vertically off-screen, jump to PRG003_ADB5 (RTS)
; Temp_Var1 = Sprite Y
LDA <Objects_SpriteY,X
STA <Temp_Var1
; X = frame
LDA Objects_Frame,X
TAX
LDA Temp_VarNP0
BMI PRG003_AE07 ; If this sprite is off-screen, jump to PRG003_AE07
; Add offset to sprite Y
LDA <Temp_Var1
ADD BoomBoom_SprYOffArmLeft,X
STA Sprite_RAM+$10,Y
PRG003_AE07:
LDA Temp_VarNP0
AND #$10
BNE PRG003_AE17 ; If the other side sprite is off-screen, jump to PRG003_AE17
; Add offset to sprite Y
LDA <Temp_Var1
ADD BoomBoom_SprYOffArmRight,X
STA Sprite_RAM+$14,Y
PRG003_AE17:
LDA BoomBoom_PatternLeft,X
STA Sprite_RAM+$11,Y
LDA BoomBoom_PatternRight,X
STA Sprite_RAM+$15,Y
; Copies attributes across
LDA Sprite_RAM+$02,Y
STA Sprite_RAM+$12,Y
; Horizontal flag
ORA #SPR_HFLIP
STA Sprite_RAM+$16,Y
LDX <SlotIndexBackup ; X = object slot index
; Temp_Var2 = Sprite X
LDA <Objects_SpriteX,X
STA <Temp_Var2
; Set Sprite Xs
STA Sprite_RAM+$13,Y
ADD #24
STA Sprite_RAM+$17,Y
RTS ; Return
BoomBoom_HitTest:
JSR Object_HandleBumpUnderneath ; Hm, Boom Boom handles getting bumped underneath?
LDA Objects_PlayerHitStat,X
BEQ PRG003_AE87 ; If Player is not hitting Boom Boom at all, jump to PRG003_AE87 (RTS)
LDA Objects_Frame,X
CMP #$07
BNE PRG003_AE50 ; If Boom Boom's frame <> 7 (Spiky Shell), jump to PRG003_AE50
JMP Player_HurtIfNotDieOffBehind ; Hurt Player and don't come back!
PRG003_AE50:
LDA <Player_YVel
BMI PRG003_AE87 ; If Player is moving upward, jump to PRG003_AE87 (RTS)
; Play squish sound
LDA Sound_QPlayer
ORA #SND_PLAYERSWIM
STA Sound_QPlayer
; Get 1000, 2000, or 4000 points
LDA <Objects_Var5,X
ADD #$07
JSR Score_PopUp
; Player Y Vel = -$30 (bounce off)
LDA #-$30
STA <Player_YVel
LDA <Objects_Var5,X
INC <Objects_Var5,X ; Var5++ (Next internal state)
CMP #$04
BEQ PRG003_AE82 ; If next up is internal state 4 (Death), jump to PRG003_AE82
; Halt Boom Boom's movement
LDA #$00
STA <Objects_YVel,X
STA <Objects_XVel,X
; Clear Var7 and Var3
STA Objects_Var7,X
STA Objects_Var3,X
; Timer2 = $30 (ticks till he gets back up)
LDA #$30
STA Objects_Timer2,X
RTS ; Return
PRG003_AE82:
; Object's timer = $80
LDA #$80
STA Objects_Timer,X
PRG003_AE87:
RTS ; Return
BoomBoom_Death:
LDA #$08
STA Objects_SprHVis,X ; ??
STA Objects_Frame,X ; Set Boom Boom's frame = 8
LDA Objects_Timer,X
BNE PRG003_AEE3 ; If timer not expired, jump to PRG003_AEE3
PRG003_AE95:
STA Objects_FlipBits,X ; Update flip bits
; Boom Boom becomes the "(?)" ball
LDA #OBJ_BOOMBOOMQBALL
STA Level_ObjectID,X
LDA #$01
STA BrickBust_En ; Enable brick bust slot 1
STA Level_TimerEn ; Halt the level timer
; Brick bust slot 1 "half" enable
LDA #$1f
STA BrickBust_HEn
; Relative Y -> BrickBust_YUpr
LDA <Objects_Y,X
SUB Level_VertScroll
STA BrickBust_YUpr
; +8 to center the ball
LDA <Objects_X,X
ADD #$08
STA <Objects_X,X
PHP ; Save CPU state (the carry bit)
; Relative X -> BrickBust_X
SUB <Horz_Scroll
STA BrickBust_X
PLP ; Restore CPU state (the carry bit)
; Apply carry
LDA <Objects_XHi,X
ADC #$00
STA <Objects_XHi,X
LDA #$00
STA <Objects_XVel,X ; Stop any movement
STA <Objects_Var5,X ; Var5 = 0
STA Objects_Frame,X ; Frame = 0
; Ball bounces up a bit
LDA #-$38
STA <Objects_YVel,X
; Play ba-boom sound
LDA Sound_QLevel1
ORA #SND_LEVELBABOOM
STA Sound_QLevel1
JSR SetRotatingColor ; Litle light show
JMP Explode_Stars ; Jump to Explode_Stars and don't come back
PRG003_AEE3:
STA Objects_ColorCycle,X ; Timer -> color cycle
RTS ; Return
Star_Vel:
.byte -$20, -$17, $00, $17, $20, $17, $00, -$17
Star_VelEnd
Explode_Stars:
LDY #(Star_VelEnd - Star_Vel - 1)
PRG003_AEF1:
; Explosion star
LDA #SOBJ_EXPLOSIONSTAR
STA SpecialObj_ID,Y
; Star X +4
LDA <Objects_X,X
ADD #$04
STA SpecialObj_XLo,Y
; Star Y +16
LDA <Objects_Y,X
ADD #16
STA SpecialObj_YLo,Y
LDA <Objects_YHi,X
ADC #$00
STA SpecialObj_YHi,Y
; Data = 0
LDA #$00
STA SpecialObj_Data,X
; Set Y velocity
LDA Star_Vel,Y
STA SpecialObj_YVel,Y
; X is rotated around by offset
TYA
ADD #$02
AND #$07
TAX
; Set X velocity
LDA Star_Vel,X
STA SpecialObj_XVel,Y
; SpecialObj_Timer = $3F
LDA #$3F
STA SpecialObj_Timer,Y
LDX <SlotIndexBackup ; X = object slot index
DEY ; Y--
BPL PRG003_AEF1 ; While Y >= 0, loop!
RTS ; Return
ObjInit_PiranhaSidewaysR:
; Right-way piranha +16 X (basically start outside of pipe instead of inside)
LDA #16
ADD <Objects_X,X
STA <Objects_X,X
ObjInit_PiranhaSidewaysL:
; Start X + 1 over
LDA <Objects_X,X
ADD #$01
STA <Objects_Var5,X
; Start Y + 7 over
LDA <Objects_Y,X
ADD #$07
STA <Objects_Y,X
RTS ; Return
ObjNorm_PiranhaSideways:
JSR Object_DeleteOffScreen ; Delete object if it falls too far off-screen
JSR SidePiranha_Draw ; Draw piranha
JSR Player_HitEnemy ; Player to piranha collision
LDA <Player_HaltGame
BNE PRG003_AF9C ; If gameplay halted, jump to PRG003_AF9C
; Var3 is the animation timer; toggles frame 0 and 1 every 8 ticks
INC Objects_Var3,X ; Var3++
LDA Objects_Var3,X
LDY #$00 ; Y = 0
AND #$08
BEQ PRG003_AF60 ; 8 ticks on, 8 ticks off; jump to PRG003_AF60
INY ; Y = 1
PRG003_AF60:
TYA
STA Objects_Frame,X ; Update frame
; Perform the state action of Var4 (0-3)
LDA <Objects_Var4,X
AND #$03
JSR DynJump
; THESE MUST FOLLOW DynJump FOR THE DYNAMIC JUMP TO WORK!!
.word SidePiranha_HideInPipe ; Piranha hides in pipe until timer expires
.word SidePiranha_Emerge ; Piranha emerges from pipe
.word SidePiranha_Chomp ; Piranha sits there and chomps for a bit
.word SidePiranha_Receed ; Piranha goes back into pipe
SidePiranha_Emerge:
LDA <Objects_Var5,X
SUB #25
CMP <Objects_X,X
BGE PRG003_AF95 ; If (Var5 - 25) >= Piranha's X, jump to PRG003_AF95
LDA #-$10 ; Leftward moving piranha
BNE PRG003_AF8B ; Jump (technically always) to PRG003_AF8B
SidePiranha_Receed:
LDA <Objects_X,X
ADD #$01
CMP <Objects_Var5,X
BGE PRG003_AF95 ; If piranha's X >= Var5, jump to PRG003_AF95
LDA #$10 ; Rightward moving piranha
PRG003_AF8B:
STA <Objects_XVel,X ; Update X velocity
JMP Object_ApplyXVel ; Apply X velocity and don't come back!
SidePiranha_Chomp:
LDA Objects_Timer,X
BNE PRG003_AFA4 ; If timer not expired, jump to PRG003_AFA4 (RTS)
PRG003_AF95:
INC <Objects_Var4,X ; Var4++ (next internal state)
; Reset timer to $38
LDA #$38
STA Objects_Timer,X
PRG003_AF9C:
RTS ; Return
SidePiranha_HideInPipe:
LDA Objects_Timer,X
BNE PRG003_AFA4 ; If timer not expired, jump to PRG003_AFA4 (RTS)
BEQ PRG003_AF95 ; Otherwise, jump to PRG003_AF95
PRG003_AFA4:
RTS ; Return
SidePiranha_EndSprXOff:
.byte 16, 0
SidePiranha_Draw:
LDA #$20 ; A = $20 (leftward piranha attributes)
LDY Level_ObjectID,X
CPY #OBJ_PIRANHASIDEWAYSLEFT
BEQ PRG003_AFB2 ; If this is a leftward piranha, jump to PRG003_AFB2
LDA #$60 ; A = $60 (rightward piranha attributes)
PRG003_AFB2:
STA Objects_FlipBits,X ; Set piranha attributes
LDA <Objects_X,X
PHA ; Save piranha's X
LDA Objects_FlipBits,X
AND #SPR_HFLIP
BEQ PRG003_AFC9 ; If piranha is not horizontally flipped, jump to PRG003_AFC9
ASL Objects_SprHVis,X
; Piranha's X += 8 (Piranha is 24 pixels wide, of which there's no routine for exactly)
LDA <Objects_X,X
ADD #$08
STA <Objects_X,X
PRG003_AFC9:
JSR Object_ShakeAndDraw ; Draw most of piranha
PLA ; Restore 'X'
STA <Objects_X,X ; -> 'X'
JSR Object_CalcSpriteXY_NoHi
LDY #$00 ; Y = 0
LDA Objects_FlipBits,X
AND #SPR_HFLIP
BEQ PRG003_AFDC ; If piranha is NOT horizontally flipped, jump to PRG003_AFDC
INY ; Y = 1
PRG003_AFDC:
LDA <Objects_SpriteX,X ; Get piranha's sprite X
ADD SidePiranha_EndSprXOff,Y
STA <Temp_Var2 ; Temp_Var2 = Sprite X for piranha's remaining bit
LDY Object_SprRAM,X ; Y = Sprite_RAM offset
; Set sprite X
LDA <Temp_Var2
STA Sprite_RAM+$13,Y
; Temp_Var1 = vertical visibility
LDA Objects_SprVVis,X
STA <Temp_Var1
LDA <Objects_SpriteY,X
LSR <Temp_Var1
BCS PRG003_AFFA ; If piranha's last bit isn't vertically visible, jump to PRG003_AFFA
STA Sprite_RAM+$10,Y ; Otherwise, set the Y
PRG003_AFFA:
LDA Sprite_RAM+$02,Y ; Get attribute value from earlier piranha segment
AND #~$03 ; Clear palette select
ORA #SPR_PAL2 ; Set palette select 2
STA Sprite_RAM+$12,Y ; -> Sprite's attribute
; Use pattern $85
LDA #$85
STA Sprite_RAM+$11,Y
RTS ; Return
LavaLotus_RightEdgePatTop: .byte $C1, $C9, $D1
LavaLotus_RightEdgePatBottom: .byte $C3, $CB, $D3
ObjNorm_LavaLotus:
JSR Object_CheckIfNormalState
BNE PRG003_B05F ; If not in normal state, jump to PRG003_B05F
JSR Object_DeleteOffScreen ; Delete object if it falls too far off-screen
LDA <Player_HaltGame
BNE PRG003_B05F ; If gameplay is halted, jump to PRG003_B05F
JSR Player_HitEnemy ; Player to Lava Lotus collision
LDA Objects_SprHVis,X
AND #%11100000
CMP #%11100000
BNE PRG003_B030 ; If the Lava Lotus does not have three horizontally off-screen sprites, jump to PRG003_B030
; Var5 = $FF
LDA #$ff
STA <Objects_Var5,X
; Var4 = $05
LDA #$05
STA <Objects_Var4,X
PRG003_B030:
DEC <Objects_Var5,X ; Var5--
LDA <Objects_Var5,X
CMP #$50
BLT PRG003_B056 ; If Var5 < $50, jump to PRG003_B056
LDY #$00 ; Y = 0
AND #%00001100
BEQ PRG003_B03F ; Periodically jump to PRG003_B03F
INY ; Y = 1
PRG003_B03F:
TYA
STA Objects_Frame,X ; Set frame 0/1
LDA Level_NoStopCnt
AND #$1f
BNE PRG003_B053 ; 1:32 ticks proceed, otherwise, jump to PRG003_B053
LDA <Objects_Var4,X
BEQ PRG003_B053 ; If Var4 = 0, jump to PRG003_B053
DEC <Objects_Var4,X ; Var4--
JSR LavaLotus_SpitFire ; Spit a fireball
PRG003_B053:
JMP PRG003_B05F ; Jump to PRG003_B05F
PRG003_B056:
; Var4 = 5
LDA #$05
STA <Objects_Var4,X
; Frame = 2 (open lotus)
LDA #$02
STA Objects_Frame,X
PRG003_B05F:
; Clear flip bits
LDA #$00
STA Objects_FlipBits,X
; Draw most of lotus
JSR Object_Draw16x32Sprite
LDA Objects_SprHVis,X
AND #%00100000
BNE PRG003_B0B1 ; If edge sprite of lotus is off-screen, jump to PRG003_B0B1 (RTS)
; Need to draw one more sprite for lotus...
LDY Object_SprRAM,X ; Y = Sprite_RAM offset
; Right edge sprite, so +16
LDA <Objects_SpriteX,X
ADD #16
STA Sprite_RAM+$13,Y
STA Sprite_RAM+$17,Y
; Vertical off-screen bits -> Temp_Var1
LDA Objects_SprVVis,X
STA <Temp_Var1
LDA <Objects_SpriteY,X
LSR <Temp_Var1
BCS PRG003_B08A ; If this sprite is vertically off-screen, jump to PRG003_B08A
STA Sprite_RAM+$10,Y ; Store this sprite's Y
PRG003_B08A:
LSR <Temp_Var1
BCS PRG003_B094 ; If this sprite is vertically off-screen, jump to PRG003_B08A
ADD #16
STA Sprite_RAM+$14,Y ; Store this sprite's Y
PRG003_B094:
LDA Sprite_RAM+$02,Y ; Get sprite attributes from left edge
ORA #SPR_HFLIP
STA Sprite_RAM+$12,Y ; Horizontally flipped compared to left edge
STA Sprite_RAM+$16,Y ; Horizontally flipped compared to left edge
LDA Objects_Frame,X
TAX
LDA LavaLotus_RightEdgePatTop,X
STA Sprite_RAM+$11,Y ; Set top pattern
LDA LavaLotus_RightEdgePatBottom,X
STA Sprite_RAM+$15,Y ; Set bottom pattern
LDX <SlotIndexBackup ; X = object slot index
PRG003_B0B1:
RTS ; Return
LavaLotusFire_XOff: .byte $03, $0D, $06, $0B, $08
LavaLotusFire_XVel: .byte $FB, $05, $FD, $03, $00
LavaLotusFire_YVel: .byte $F5, $F5, $F0, $F0, $EE
LavaLotus_SpitFire:
JSR Object_AnySprOffscreen
BNE PRG003_B0D0 ; If any part of Lava Lotus is off-screen, jump to PRG003_B0D0 (RTS)
LDY #$07 ; Y = 7
; This loop really could be replaced by
;JSR SpecialObj_FindEmptyAbortY
PRG003_B0C8:
LDA SpecialObj_ID,Y
BEQ PRG003_B0D1 ; If this special object slot is free, jump to PRG003_B0D1
DEY ; Y--
BPL PRG003_B0C8 ; If Y >= 0, loop!
PRG003_B0D0:
RTS ; Return
PRG003_B0D1:
; Lava Lotus fireball
LDA #SOBJ_LAVALOTUSFIRE
STA SpecialObj_ID,Y
LDA #$c0
STA SpecialObj_Var2,Y
; Fireball at Y + 7
LDA <Objects_Y,X
ADD #$07
STA SpecialObj_YLo,Y
LDA <Objects_YHi,X
ADC #$00
STA SpecialObj_YHi,Y
; Temp_Var1 = Var4 (which fireball we're on)
LDA <Objects_Var4,X
STA <Temp_Var1
; Fireball X
LDA <Objects_X,X
CLC
LDX <Temp_Var1 ; X = Temp_Var1 (Var4)
ADC LavaLotusFire_XOff,X
STA SpecialObj_XLo,Y
; Fireball Y velocity
LDA LavaLotusFire_YVel,X
STA SpecialObj_YVel,Y
; Fireball X velocity
LDA LavaLotusFire_XVel,X
STA SpecialObj_XVel,Y
; Fireball data = 1
LDA #$01
STA SpecialObj_Data,Y
LDX <SlotIndexBackup ; X = object slot index
; Store parent's object index into SpecialObj_Var1
TXA
STA SpecialObj_Var1,Y
RTS ; Return
ObjInit_LavaLotus:
; Var5 = $FF
LDA #$ff
STA <Objects_Var5,X
; Var4 = 5
LDA #$05
STA <Objects_Var4,X
; Mark object as in water
INC Objects_InWater,X
ObjInit_WaterCurrent:
RTS ; Return
CurrentUpward_YAccel: .byte -$03, -$03, -$02, -$01, $00, $00, $00, $00, $00
CurrentDownward_YAccel: .byte $03, $02, $01, $00, $00, $00, $00, $00, $00
ObjNorm_WaterCurrent:
JSR Object_DeleteOffScreen ; Delete object if it falls too far off-screen
JSR Object_AnySprOffscreen
ORA <Player_HaltGame
BNE PRG003_B197 ; If object falls off-screen or gameplay is halted, jump to PRG003_B197
JSR Level_ObjCalcXDiffs
LDA <Temp_Var16
ADD #$08
CMP #$20
BGE PRG003_B18C ; If Player is not close enough, jump to PRG003_B18C
JSR Level_ObjCalcYDiffs
LDA Level_ObjectID,X
CMP #OBJ_WATERCURRENTDOWNARD
BEQ PRG003_B157 ; If this is a downward current, jump to PRG003_B157
; For upward current...
; Negate Temp_Var16
LDA <Temp_Var16
JSR Negate
STA <Temp_Var16
DEY ; Y-- (change direction)
PRG003_B157:
CPY #$00
BNE PRG003_B18C ; If Player is on wrong side of current object, jump to PRG003_B18C
LDA <Temp_Var16
LSR A
LSR A
LSR A
LSR A
LSR A
TAY ; Y = index relative of Player's Y offset
LDA Level_ObjectID,X
CMP #OBJ_WATERCURRENTDOWNARD
BNE PRG003_B177 ; If this is not a downard current, jump to PRG003_B177
; Downward current...
LDA <Player_YVel
CMP #$3b
BGS PRG003_B18C ; If Player's Y velocity >= $3B, jump to PRG003_B18C
ADD CurrentDownward_YAccel,Y ; Push Player downward
JMP PRG003_B186 ; Jump to PRG003_B186
PRG003_B177:
LDA Player_HitCeiling
BNE PRG003_B18C ; If Player just hit off ceiling, jump to PRG003_B18C
LDA <Player_YVel
CMP #-$3C
BMI PRG003_B18C ; If Player's Y velocity is already moving faster than -$3C, jump to PRG003_B18C
ADD CurrentUpward_YAccel,Y ; Push Player upward
PRG003_B186:
STA <Player_YVel ; Update Player's Y velocity
; Flag Player as mid-air
LDA #$01
STA <Player_InAir
PRG003_B18C:
INC <Objects_Var5,X ; Var5++
LDA <Objects_Var5,X
AND #$0f
BNE PRG003_B197 ; 1:16 ticks proceed, otherwise jump to PRG003_B197
JSR Current_GenerateBubble ; Generate a bubble
PRG003_B197:
RTS ; Return
Current_GenerateBubble:
LDY #$01
JSR SpecialObj_FindEmptyAbortY ; Find a free special object in one of the first two slots or don't come back!
; SpecialObj_Timer = $28
LDA #$28
STA SpecialObj_Timer,Y
; A bubble
LDA #SOBJ_BUBBLE
STA SpecialObj_ID,Y
; Data = 0
LDA #$00
STA SpecialObj_Data,Y
STY <Temp_Var1 ; Special object index -> Temp_Var1
; Apply a bit of randomness to the bubble's X
TYA
ADC RandomN,Y
AND #$17
ADD <Objects_X,X
LDY <Temp_Var1 ; Y = special object index
STA SpecialObj_XLo,Y ; Store slightly random adjusted X -> Bubble X
LDA Level_ObjectID,X
CMP #OBJ_WATERCURRENTDOWNARD
BEQ PRG003_B1D7 ; If this is a downard current, jump to PRG003_B1D7
; Bubble appears at Y - 8
LDA <Objects_Y,X
SBC #$08
STA SpecialObj_YLo,Y
LDA <Objects_YHi,X
SBC #$00
STA SpecialObj_YHi,Y
; Bubble's Y velocity = -$80
LDA #-$80
STA SpecialObj_YVel,Y
RTS ; Return
PRG003_B1D7:
; Bubble appears at Y + 3
LDA <Objects_Y,X
ADC #$03
STA SpecialObj_YLo,Y
LDA <Objects_YHi,X ; Bug? They don't apply the carry (ADC) here!
STA SpecialObj_YHi,Y
; Bubble's Y velocity = $7F
LDA #$7f
STA SpecialObj_YVel,Y
RTS ; Return
ObjInit_BigBerthaBirther:
INC Objects_InWater,X ; Flag as in water
; Objects_Var10 = X
LDA <Objects_X,X
STA Objects_Var10,X
; Objects_Var11 = X Hi
LDA <Objects_XHi,X
STA Objects_Var11,X
PRG003_B1F6:
RTS ; Return
BigBerthaLCC_XVelAccel: .byte $01, -$01
BigBerthaLCC_XVelLimit: .byte $18, -$18
BigBerthaLCC_XVelLowLimit: .byte $08, -$08
ObjNorm_BigBerthaBirther:
JSR Object_CheckIfNormalState
BEQ PRG003_B205 ; If Big Bertha's in normal state, jump to PRG003_B205
JMP BigBerthaLCC_Draw ; Jump to BigBerthaLCC_Draw
PRG003_B205:
JSR Object_SetHFlipByXVel ; Set horizontal flip by travel direction
JSR BigBerthaLCC_Draw ; Draw Big Bertha
JSR Object_DeleteOffScreen_N2 ; If Big Bertha falls off-screen, delete it!
LDA <Player_HaltGame
BNE PRG003_B1F6 ; If gameplay is halted, jump to PRG003_B1F6 (RTS)
INC <Objects_Var5,X ; Var5++
JSR Player_HitEnemy ; Player to Bertha collision
JSR Object_ApplyXVel ; Apply X Velocity
JSR Object_ApplyYVel_NoLimit ; Apply Y Velocity
LDY #$02 ; Y = $02
LDA <Counter_1
AND #$40
BEQ PRG003_B227 ; 64 ticks on, 64 ticks off; jump to PRG003_B227
LDY #-$02 ; Y = -$02
PRG003_B227:
STY <Objects_YVel,X ; Y Velocity = $02 or -$02
LDA Objects_Timer,X
BEQ PRG003_B250 ; If timer expired, jump to PRG003_B250
CMP #$01
BNE PRG003_B23A ; If timer <> 1, jump to PRG003_B23A
JSR Object_AnySprOffscreen
BNE PRG003_B23F ; If any part of Big Bertha has fallen off-screen, jump to PRG003_B23F
JSR BigBertha_SpitOutCheepCheep ; Big Bertha spits out the little Cheep Cheep
PRG003_B23A:
; Big Bertha frame 1
LDA #$01
STA Objects_Frame,X
PRG003_B23F:
LDA <Objects_XVel,X
BEQ PRG003_B24B ; If Big Bertha is not moving, jump to PRG003_B24B
BPL PRG003_B249 ; If Big Bertha is moving to the right, jump to PRG003_B249
; Double increment because it hits the decrement, basically a single increment
INC <Objects_XVel,X ; Moving left, slow down
INC <Objects_XVel,X
PRG003_B249:
DEC <Objects_XVel,X ; Moving right, slow down
PRG003_B24B:
RTS ; Return
BigBertha_XMove: .byte -$10, $10
BigBertha_XHiMove: .byte $FF, $00
PRG003_B250:
LDA <Objects_Var5,X
LSR A
BCC PRG003_B2A4 ; If Var5 is even, jump to PRG003_B2A4
LDA Objects_Var7,X
AND #$01
TAY ; Y = 0 or 1
; Objects_Var10 is Big Bertha's original X
LDA Objects_Var10,X
ADD BigBertha_XMove,Y
STA <Temp_Var2
; Objects_Var11 is Big Bertha's original X Hi
LDA Objects_Var11,X
ADC BigBertha_XHiMove,Y
STA <Temp_Var1
LDY #$00 ; Y = 0
LDA <Objects_X,X
CMP <Temp_Var2
LDA <Objects_XHi,X
SBC <Temp_Var1
BLT PRG003_B279 ; If Big Bertha is to the left of origin, jump to PRG003_B279
INY ; Y = 1
PRG003_B279:
LDA <Objects_XVel,X
CMP BigBerthaLCC_XVelLimit,Y
BEQ PRG003_B28B ; If Big Bertha is at X velocity limit, jump to PRG003_B28B
ADD BigBerthaLCC_XVelAccel,Y
STA <Objects_XVel,X ; Update X velocity
BNE PRG003_B28B ; If X velocity is not at zero, jump to PRG003_B28B
INC Objects_Var7,X ; Otherwise, Var7++
PRG003_B28B:
CMP BigBerthaLCC_XVelLowLimit,Y
BNE PRG003_B2A4 ; If Big Bertha is at low limit, jump to PRG003_B2A4
LDA Objects_Timer3,X
BNE PRG003_B2A4 ; If timer 3 not expired, jump to PRG003_B2A4
LDA RandomN,X
BPL PRG003_B2A4 ; Random 50/50, jump to PRG003_B2A4
; Set timer to $26
LDA #$26
STA Objects_Timer,X
; Set timer to $80
LDA #$80
STA Objects_Timer3,X
PRG003_B2A4:
RTS ; Return
BigBertha_HVisByFlip: .byte $20, $80
BigBertha_SpriteXOff: .byte $10, $00
BigBerthaLCC_Draw:
; Save Big Bertha's X/Hi
LDA <Objects_X,X
PHA
LDA <Objects_XHi,X
PHA
LDA Objects_SprHVis,X
STA Temp_VarNP0 ; Store horizontal visibility bits -> Temp_VarNP0
LDA Objects_FlipBits,X
ASL A
BEQ PRG003_B2CB ; If Big Bertha is NOT horizontally flipped, jump to PRG003_B2CB
ASL Objects_SprHVis,X
; Move over 8 pixels
LDA <Objects_X,X
ADD #$08
STA <Objects_X,X
LDA <Objects_XHi,X
ADC #$00
STA <Objects_XHi,X
PRG003_B2CB:
JSR Object_Draw16x32Sprite ; Draw part of Big Bertha
; Restore Big Bertha's X/Hi
PLA
STA <Objects_XHi,X
PLA
STA <Objects_X,X
JSR Object_CalcSpriteXY_NoHi
LDY #$00 ; Y = 0
LDA Objects_FlipBits,X
ASL A
BEQ PRG003_B2E0 ; If Big Bertha is NOT horizontally flipped, jump to PRG003_B2E0
INY ; Y = 1
PRG003_B2E0:
LDA Temp_VarNP0
AND BigBertha_HVisByFlip,Y
BNE PRG003_B341 ; If check sprite for Big Bertha is off-screen, jump to PRG003_B341 (RTS)
; Calculate Sprite X with appropriate offset
LDA <Objects_SpriteX,X
ADD BigBertha_SpriteXOff,Y
STA <Temp_Var2
LDY Object_SprRAM,X ; Y = Sprite_RAM offset
; Store sprite Xs
LDA <Temp_Var2
STA Sprite_RAM+$13,Y
STA Sprite_RAM+$17,Y
; Temp_Var1 = Sprite vertical visibility bits
LDA Objects_SprVVis,X
STA <Temp_Var1
LDA <Objects_SpriteY,X
LSR <Temp_Var1
BCS PRG003_B309 ; If this sprite is vertically off-screen, jump to PRG003_B309
STA Sprite_RAM+$10,Y ; Otherwise, store Sprite Y
PRG003_B309:
LSR <Temp_Var1
BCS PRG003_B312 ; If this sprite is vertically off-screen, jump to PRG003_B312
ADC #16
STA Sprite_RAM+$14,Y ; Otherwise, store Sprite Y
PRG003_B312:
; Copy attributes across
LDA Sprite_RAM+$02,Y
STA Sprite_RAM+$12,Y
STA Sprite_RAM+$16,Y
; Store pattern
LDA #$85
STA Sprite_RAM+$11,Y
LDA <Objects_Var5,X
LSR A
LSR A
LSR A
; Select appropriate pattern by animation frame
LDA #$8b
BCS PRG003_B32B
LDA #$91
PRG003_B32B:
; Store pattern
STA Sprite_RAM+$15,Y
LDA Objects_FlipBits,X
BPL PRG003_B341 ; If Big Bertha is not vertically flipped, jump to PRG003_B341
; Otherwise swap Sprite Ys
LDA Sprite_RAM+$10,Y
PHA
LDA Sprite_RAM+$14,Y
STA Sprite_RAM+$10,Y
PLA
STA Sprite_RAM+$14,Y
PRG003_B341:
RTS ; Return
TinyCheep_XVel: .byte -$28, $28
TinyCheep_XOff: .byte $00, $08
TinyCheep_Flip: .byte $00, SPR_HFLIP
BigBertha_SpitOutCheepCheep:
LDY #$04 ; Y = 4
PRG003_B34A:
LDA Objects_State,Y
BEQ PRG003_B353 ; If this object slot is dead/empty, jump to PRG003_B353
DEY ; Y--
BPL PRG003_B34A ; While Y >= 0, loop!
RTS ; Return
PRG003_B353:
TYA
TAX ; X = open object slot index
JSR Level_PrepareNewObject
LDX <SlotIndexBackup ; X = object slot index
; Set to normal state
LDA #OBJSTATE_NORMAL
STA Objects_State,Y
; This is the tiny Cheep Cheep that comes out of Big Bertha
LDA #OBJ_TINYCHEEPCHEEP
STA Level_ObjectID,Y
; Cheep Cheep emerges at +14
LDA <Objects_Y,X
ADC #14
STA Objects_Y,Y
LDA <Objects_YHi,X
ADC #$00
STA Objects_YHi,Y
; Temp_Var1 = 0
LDA #$00
STA <Temp_Var1
LDA Objects_FlipBits,X
BEQ PRG003_B37D ; If Big Bertha is not flipped, jump to PRG003_B37D
INC <Temp_Var1 ; Otherwise, Temp_Var1 = 1
PRG003_B37D:
LDA <Objects_X,X
LDX <Temp_Var1 ; X = 0 or 1
ADC TinyCheep_XOff,X
STA Objects_X,Y ; Set Tiny Cheep Cheep's X
; Set tiny Cheep Cheep's X velocity
LDA TinyCheep_XVel,X
STA Objects_XVel,Y
; Set tiny Cheep Cheep's flip
LDA TinyCheep_Flip,X
STA Objects_FlipBits,Y
LDX <SlotIndexBackup ; X = object slot index
; Set tiny Cheep Cheep's X Hi
LDA <Objects_XHi,X
ADC #$00
STA Objects_XHi,Y
; Set tiny Cheep Cheep palette select 1 and flag as under water
LDA #SPR_PAL1
STA Objects_SprAttr,Y
STA Objects_InWater,Y
; Tiny Cheep Cheep's Var1 holds Big Bertha's object index
TXA
STA Objects_Var1,Y
; Timer set to $30
LDA #$30
STA Objects_Timer,Y
RTS ; Return
TinyCheepCheep_XVelLimit: .byte $08, -$08
PRG003_B3B0: .byte $FF, $01
ObjNorm_TinyCheepCheep:
JSR Object_DeleteOffScreen ; Delete object if it falls too far off-screen
; Toggle frame by counter
LDA Level_NoStopCnt
LSR A
LSR A
AND #$01
STA Objects_Frame,X
LDA <Player_HaltGame
BNE PRG003_B439 ; If gameplay is halted, jump to PRG003_B439
LDY #$02 ; Y = $02
LDA <Counter_1
AND #$10
BEQ PRG003_B3CD ; Every 1:16 ticks, jump to PRG003_B3CD
LDY #-$02 ; Y = -$02
PRG003_B3CD:
STY <Objects_YVel,X ; Set Y velocity
LDY #$00 ; Y = 0 (moving to the right)
LDA <Objects_XVel,X
BPL PRG003_B3D6 ; If moving to the right, jump to PRG003_B3D6
INY ; Y = 1 (moving to the left)
PRG003_B3D6:
CMP TinyCheepCheep_XVelLimit,Y
BEQ PRG003_B3E1 ; If hit the limit, jump to PRG003_B3E1
ADD PRG003_B3B0,Y ; Accelerate
STA <Objects_XVel,X ; Update X Vel
PRG003_B3E1:
JSR Object_ApplyXVel ; Apply X velocity
JSR Object_ApplyYVel_NoLimit ; Apply Y velocity
JSR Player_HitEnemy ; Player interaction with enemy
LDA Objects_Timer,X
BNE PRG003_B439 ; If timer not expired, jump to PRG003_B439
; Timer expired...
LDY Objects_Var1,X ; Y = Var1 (parent Big Birtha Birther)
LDA Objects_State,Y
CMP #OBJSTATE_NORMAL
BNE PRG003_B42E ; If Big Birtha Birther's state is not Normal, jump to PRG003_B42E
LDA Level_ObjectID,Y
CMP #OBJ_BIGBERTHABIRTHER
BNE PRG003_B42E ; If this is no longer a Big Bertha Birther, jump to PRG003_B42E
LDA <Objects_X,X
SBC Objects_X,Y
STA <Temp_Var1 ; Temp_Var1 = difference between the little Cheep's position and Big Bertha
ADC #$20
CMP #$48
BGE PRG003_B439 ; If too far right, jump to PRG003_B439
LDA <Temp_Var1
ADC #$08
CMP #$18
BGE PRG003_B41E ; If too far left, jump to PRG003_B41E
JSR Object_SetDeadEmpty ; Eradicate the Cheep Cheep
STA Objects_Frame,Y ; Clear the frame (?)
JMP PRG003_B439 ; Jump to PRG003_B439
PRG003_B41E:
LDA #$08 ; A = $08
LDY <Temp_Var1 ; Y = Temp_Var1
BMI PRG003_B426 ; If Temp_Var1 (difference) is negative, jump to PRG003_B426
LDA #-$08 ; A = -$08
PRG003_B426:
ADD <Objects_XVel,X ; Add to X velocity
STA <Objects_XVel,X ; Update X Velocity
JMP PRG003_B439 ; Jump to PRG003_B439
PRG003_B42E:
LDA #$08 ; A = $08
LDY Objects_FlipBits,X
BNE PRG003_B437 ; If not horizontally flipped, jump to PRG003_B437
LDA #-$08 ; A = -$08
PRG003_B437:
STA <Objects_XVel,X ; Update X Velocity
PRG003_B439:
JMP Object_ShakeAndDraw ; Draw object and don't come back!
CheepCheepHopper_InitXVel: .byte $0C, -$0C
ObjInit_CheepCheepHopper:
JSR Level_ObjCalcXDiffs
; Set hopper's initial X velocity
LDA CheepCheepHopper_InitXVel,Y
STA <Objects_XVel,X
ObjInit_TinyCheepCheep:
RTS ; Return
ObjNorm_CheepCheepHopper:
JSR Object_DeleteOffScreen ; Delete object if it falls too far off-screen
JSR Object_SetHFlipByXVel ; Set horizontal flip by travel direction
JSR Object_ShakeAndDraw ; Draw Cheep Chep
LDA <Player_HaltGame
BNE PRG003_B47A ; If gameplay is halted, jump to PRG003_B47A
JSR Object_Move ; Do standard movements
JSR Player_HitEnemy ; Player to Cheep Cheep collision
LDA Objects_InWater,X
BEQ PRG003_B471 ; If Cheep Cheep is NOT in water, jump to PRG003_B471
JSR Level_ObjCalcXDiffs
LDY #-$30 ; Y = -$30
LDA <Temp_Var16
ADD #$40
CMP #$80
BGE PRG003_B46F ; If Cheep Cheep is not close enough to Player, jump to PRG003_B46F
LDY #-$60 ; Otherwise, Y = -$60
PRG003_B46F:
STY <Objects_YVel,X ; Update Y velocity
PRG003_B471:
; Toggle frame 0/1
LDA <Counter_1
LSR A
LSR A
AND #$01
STA Objects_Frame,X
PRG003_B47A:
RTS ; Return
Tornado_InitXVel: .byte $08, -$08
ObjInit_Tornado:
JSR Level_ObjCalcXDiffs
; Set initial X velocity towards Player
LDA Tornado_InitXVel,Y
STA <Objects_XVel,X
; Var4 = $A5
LDA #$a5
STA <Objects_Var4,X
RTS ; Return
Tornado_ParticleOffsets:
.byte $18, $18, $17, $17, $16, $15, $14, $13, $11, $0F, $0D, $0B, $09, $07, $05, $02
.byte $12, $12, $11, $11, $10, $0F, $0F, $0E, $0C, $0B, $09, $08, $06, $05, $03, $01
.byte $0E, $0E, $0D, $0D, $0C, $0C, $0B, $0B, $09, $08, $07, $06, $05, $04, $02, $01
.byte $0A, $0A, $09, $09, $09, $08, $08, $07, $07, $06, $05, $04, $03, $02, $02, $00
.byte $07, $07, $06, $06, $06, $06, $05, $05, $04, $04, $03, $03, $02, $02, $01, $00
.byte $03, $03, $02, $02, $02, $02, $02, $02, $02, $01, $01, $01, $01, $00, $00, $00
.byte $02, $02, $01, $01, $01, $01, $01, $01, $01, $01, $01, $00, $00, $00, $00, $00
.byte $01, $01, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
Tornado_ScatterY:
.byte $00, $0C, $18, $24, $30, $3C, $48, $54
; Causes wider to narrow spreading based on position of tornado particle
Tornado_SpreadFreq:
.byte $38, $30, $28, $20, $18, $10, $08, $00
Tornado_ParticleDivCnt:
.byte $01, $02
PRG003_B51C:
.byte $01, $02, $01, $FF, $20, $E0
Tornado_MaskOffset:
.byte $09, $09, $09, $08, $07, $06, $07, $08
ObjNorm_Tornado:
JSR Object_DeleteOffScreen ; Delete object if it falls too far off-screen
LDA <Player_HaltGame
BNE PRG003_B534 ; If gameplay is halted, jump to PRG003_B534
JSR Object_ApplyXVel ; Apply X velocity
PRG003_B534:
LDY <Objects_Var4,X ; Y = Var4
BNE PRG003_B53B ; If Var4 <> 0, jump to PRG003_B53B
JMP Object_Delete ; Delete object and don't come back!
PRG003_B53B:
LDA <Counter_1
AND #$01
BNE PRG003_B543 ; Every other tick, jump to PRG003_B543
DEC <Objects_Var4,X ; Var4--
PRG003_B543:
CPY #$40
BGE PRG003_B551 ; If Var4 >= $40, jump to PRG003_B551
; They possibly intended this to divide Counter_1, but because of
; the previous AND instruction, this will shift it to nothing...
LSR A
LSR A
LSR A
LSR A
ADD #$03
JMP PRG003_B55D ; Jump to PRG003_B55D
PRG003_B551:
LDA <Counter_1
LSR A
LSR A
LSR A
LSR A
AND #$07
TAY ; Y = 0 to 7, by counter / 16
LDA Tornado_MaskOffset,Y
PRG003_B55D:
STA <Objects_Var5,X ; -> Var5
ADD <Objects_VarBSS,X
STA <Objects_VarBSS,X
STA <Temp_Var15 ; -> Temp_Var15
LDA <Counter_1
LSR A
LSR A
LSR A
AND #$01
TAY ; Y = 0 or 1
LDA Tornado_ParticleDivCnt,Y
STA <Temp_Var13 ; -> Temp_Var13
JSR Object_CalcSpriteXY_NoHi ; Calculate sprites
; Draw 7 scatter particles to represent the tornado
LDX #$07 ; X = 7
PRG003_B578:
STX <Temp_Var16 ; -> Temp_Var16
JSR Tornado_ScatterParticle ; Scatters tornado particle
JSR Tornado_DrawParticle ; Draw the tornado particle
DEX ; X--
BPL PRG003_B578 ; While X >= 0, loop
LDX <SlotIndexBackup ; X = object slot index
LDA Player_IsDying
ORA Player_OffScreen
BNE PRG003_B5C2 ; If Player is dead or off-screen, jump to PRG003_B5C2 (RTS)
LDA Objects_Var3,X
BEQ PRG003_B5C3 ; If Var3 = 0, jump to PRG003_B5C3
LDA <Counter_1
AND #$1f
ORA #$20
STA Player_TwisterSpin ; Set Player as twirling from Tornado
LDY #$00 ; Y = 0
LDA <Player_Y
CMP #48
BLT PRG003_B5A4 ; If Player Y < 48, jump to PRG003_B5A4
INY ; Y = 1
PRG003_B5A4:
; Var6 keeps a copy of how it has accelerate the Player
LDA Objects_Var6,X
CMP Tornado_PlayerYLimit,Y
BEQ PRG003_B5B3 ; If Var6 = Player Y limit, jump to PRG003_B5B3
ADD Tornado_PlayerYAccel,Y ; Accelerate!
STA Objects_Var6,X ; Update Var6
PRG003_B5B3:
STA <Player_YVel ; Set same to Player's Y velocity
; Halt Player's horizontal movement
LDA #$00
STA <Player_XVel
JSR Level_ObjCalcXDiffs
; Set a little plug-along value to the Player
LDA Tornado_PlayerXVelAdj,Y
STA Player_XVelAdj
PRG003_B5C2:
RTS ; Return
PRG003_B5C3:
JSR Level_ObjCalcXDiffs
; Palette select 0/1 depending on which side the particle is on
TYA
STA Objects_FlipBits,X
BEQ PRG003_B5D3 ; If on the zero side, jump to PRG003_B5D3
; Otherwise, negate Temp_Var16
LDA <Temp_Var16
JSR Negate
STA <Temp_Var16
PRG003_B5D3:
LDA <Temp_Var16
CMP #$10
BGE PRG003_B5EF ; If Temp_Var16 >= $10, jump to PRG003_B5EF
LDA <Player_Y
CMP #112
BLT PRG003_B5EF ; If Player Y < 112, jump to PRG003_B5EF
INC Objects_Var3,X ; Var3++
; Push Player upward
DEC <Player_Y
DEC <Player_Y
STA <Player_InAir ; Flag Player as mid-air
; Upward Player!
LDA #-$20
STA <Player_YVel
; Var6 = last set Player Y velocity
STA Objects_Var6,X
PRG003_B5EF:
LDA <Temp_Var16
LSR A
LSR A
LSR A
LSR A
LSR A
TAY ; Y = 0-7, based on upper 3 bits of Temp_Var16
STY <Temp_Var1 ; -> Temp_Var1
LDA Tornado_PlayerXVelAdj2,Y
LDY Objects_FlipBits,X
BNE PRG003_B604 ; If on the 1 side, jump to PRG003_B604
JSR Negate ; Otherwise, negate value from Tornado_PlayerXVelAdj2
PRG003_B604:
STA Player_XVelAdj ; -> Player_XVelAdj
LDA <Temp_Var16
CMP #$10
BGE PRG003_B61C ; If Temp_Var16 >= $10, jump to PRG003_B61C
LDA <Player_Y
LSR A
LSR A
LSR A
LSR A
TAY ; Y = upper 4 bits of Player's position (i.e. the tile grid row)
; Accelerate Player based on his vertical position
LDA <Player_YVel
ADD Tornado_PlayerYVelAccelByRow,Y
STA <Player_YVel
PRG003_B61C:
RTS ; Return
Tornado_PlayerYLimit: .byte $40, -$40
Tornado_PlayerYAccel: .byte $04, -$04
Tornado_PlayerXVelAdj: .byte -$08, $08
Tornado_PlayerXVelAdj2:
.byte $18, $10, $0A, $06, $00, $00, $00, $00
Tornado_PlayerYVelAccelByRow:
.byte $10, $04, -$08, -$08, -$08, -$08, -$08, -$08, -$02, -$02, -$02, -$02, $10, $10, $10, $10
Tornado_ScatterParticle:
TXA
ASL A
ASL A
ASL A
ASL A
STA <Temp_Var14 ; Temp_Var14 = 'X' << 4
; Temp_Var15 += Tornado_SpreadFreq[X]
LDA <Temp_Var15
ADD Tornado_SpreadFreq,X
STA <Temp_Var15
LDA <Temp_Var15
AND #%00001111
TAY ; Y = lower 4 bits of Temp_Var15
LDA <Temp_Var15
AND #%00010000
BEQ PRG003_B659 ; If Temp_Var15 bit 4 is NOT set, jump to PRG003_B659
; Sort of negates 'Y'
TYA
EOR #$ff
TAY
PRG003_B659:
LDA #$00
CPY #$10
BEQ PRG003_B668 ; If 'Y' = $10, jump to PRG003_B668
TYA
AND #%00001111
ORA <Temp_Var14 ; OR in Temp_Var14
TAY
LDA Tornado_ParticleOffsets,Y ; A = Tornado_ParticleOffsets[Y]
PRG003_B668:
STA <Temp_Var10 ; -> Temp_Var10 (particle offset X)
LDA <Temp_Var15
AND #%00001111
TAY ; Y = lower 4 bits of Temp_Var15
LDA <Temp_Var15
AND #%00010000
BNE PRG003_B679 ; If Temp_Var15 bit 4 is set, jump to PRG003_B679
; Sort of negates 'Y'
TYA
EOR #$ff
TAY
PRG003_B679:
LDA #$00
CPY #$10
BEQ PRG003_B693 ; If 'Y' = $10, jump to PRG003_B693
TYA
AND #%00001111
ORA <Temp_Var14 ; OR in Temp_Var14
TAY
LDA Tornado_ParticleOffsets,Y
LSR A
LSR A
LDY <Temp_Var13 ; Y = Temp_Var13
DEY ; Y--
BEQ PRG003_B693 ; If Y = 0, jump to PRG003_B693
LSR A
DEY ; Y--
BEQ PRG003_B693 ; If Y = 0, jump to PRG003_B693 (... next line)
PRG003_B693:
STA <Temp_Var9 ; -> Temp_Var9 (particle offset Y)
LDA <Temp_Var15
AND #%00110000
BEQ PRG003_B6B1 ; If neither bit 4 or 5 is set, jump to PRG003_B6B1
CMP #%00010000
BEQ PRG003_B6A6 ; If bit 4 is not set, jump to PRG003_B6A6
CMP #%00110000
BEQ PRG003_B6B2 ; If bit 4 and 5 are not set, jump to PRG003_B6B2
JSR PRG003_B6B2 ; Negate Temp_Var10
PRG003_B6A6:
LDY #$01 ; Y = 1
PRG003_B6A8:
; Negate Temp_Var9/10
LDA Temp_Var9,Y
JSR Negate
STA Temp_Var9,Y
PRG003_B6B1:
RTS ; Return
PRG003_B6B2:
LDY #$00 ; Y = 0
BEQ PRG003_B6A8 ; Jump (technically always) to PRG003_B6A8
PRG003_B6B6:
.byte $00, $02, $04, $06, $08, $06, $04, $02, $00, $02, $04, $06, $08, $06, $04, $50
Tornado_Masks:
.byte $0F, $03, $01, $00, $00, $00, $00, $00
Tornado_DrawParticle:
LDY <SlotIndexBackup ; Y = object's slot index
LDA Objects_Var5,Y
BEQ PRG003_B6B1 ; If Var5 = 0, jump to PRG003_B6B1 (RTS)
LSR A
AND #$07
TAY ; Y = 0 to 7
TXA ; object slot index -> 'A'
AND Tornado_Masks,Y
STA <Temp_Var1 ; -> Temp_Var1
LDA <Counter_1
AND Tornado_Masks,Y
CMP <Temp_Var1
BNE PRG003_B6B1 ; If masked counter value = Temp_Var1, jump to PRG003_B6B1 (RTS)
CPX #$06
BLT PRG003_B6F3 ; If object slot < 6, jump to PRG003_B6F3
JSR Object_GetRandNearUnusedSpr
LDX <SlotIndexBackup ; X = object slot index
BGS PRG003_B6FD ; Jump (technically always) to PRG003_B6FD
PRG003_B6F3:
TXA
ASL A
ASL A ; A *= 4 (next sprite over)
LDX <SlotIndexBackup ; X = object slot index
ADD Object_SprRAM,X ; Base Sprite_RAM offset
TAY ; Sprite_RAM offset -> 'Y'
PRG003_B6FD:
STY <Temp_Var14 ; -> Temp_Var14
LDA <Counter_1
AND #$0f ; 0-15 counter value
ADD Objects_SpriteY,X ; Add 0-15 to SpriteY
; Temp_Var1 (Sprite Y) = Temp_Var16 + Tornado_ScatterY[X] + Temp_Var9
LDX <Temp_Var16
ADD Tornado_ScatterY,X
ADD <Temp_Var9
STA <Temp_Var1
BCS PRG003_B753 ; If carry set, jump to PRG003_B753 (went too low, so skip it)
LDA <Counter_1
LSR A
LSR A
LSR A
AND #$07 ; A = 0-7
ADD <Temp_Var16 ; 'A' += Temp_Var16
TAX ; -> 'X'
; Temp_Var2 (Sprite X) = Tornado's Sprite X + Temp_Var10
LDA PRG003_B6B6,X ; A = PRG003_B6B6[X]
CLC ; Clear carry
LDX <SlotIndexBackup ; X = object slot index
ADC Objects_SpriteX,X
ADD <Temp_Var10
STA <Temp_Var2
JSR Sprite_NoCarryIfVisible
BCS PRG003_B753 ; If this particle is not visible, jump to PRG003_B753
LDY <Temp_Var14 ; Y = Temp_Var14
; Set particle sprite Y
LDA <Temp_Var1
STA Sprite_RAM+$00,Y
; Set particle sprite X
LDA <Temp_Var2
STA Sprite_RAM+$03,Y
; Pattern $17
LDA #$17
STA Sprite_RAM+$01,Y
LDX #$03 ; X = 3
LDA <Temp_Var15
AND #$3F
CMP #$20
BLT PRG003_B74F ; If lower 5 bits of Temp_Var15 < $20, jump to PRG003_B74F
LDX #$01 ; Otherwise, X = 1
PRG003_B74F:
; Set particle sprite attributes
TXA
STA Sprite_RAM+$02,Y
PRG003_B753:
LDX <Temp_Var16 ; X = Temp_Var16
ObjInit_Blooper:
RTS ; Return
ObjInit_BlooperWithKids:
; Var7 = 4 (kids left)
LDA #$04
STA Objects_Var7,X
JSR Object_InitTailBuffer ; Initialize tail buffer (if no buffer available, will be destroyed and won't come back)
RTS ; Return
Blooper_YVelAccel:
.byte $02, -$02
Blooper_YVelLimit:
.byte $24, -$24
PRG003_B763:
.byte $00, $10, $00, $01, $FF
Blooper_FlipTowardsPlayer:
.byte SPR_HFLIP, $00
ObjNorm_Blooper:
LDA Level_ObjectID,X
CMP #OBJ_BLOOPER
BNE PRG003_B781 ; If this is not a straight Blooper, jump to PRG003_B781
; Just a regular Blooper...
JSR Object_DeleteOffScreen ; Delete object if it falls too far off-screen
LDA <Player_HaltGame
BEQ PRG003_B77B ; If gameplay is not halted, jump to PRG003_B77B
JMP Object_ShakeAndDrawMirrored ; Otherwise, draw Blooper and don't come back!
PRG003_B77B:
JSR Player_HitEnemy ; Do Player to Blooper hit detection!
JMP PRG003_B78B ; Jump to PRG003_B78B
PRG003_B781:
JSR TailEnemy_DoStandard ; A Blooper with kids... gotta do Tail updates!
LDA <Player_HaltGame
BEQ PRG003_B78B ; If gameplay is not halted, jump to PRG003_B78B
JMP PRG003_BB17 ; Jump off to PRG003_BB17 (draws enemy) and don't come back!
PRG003_B78B:
LDA Objects_Timer,X
BEQ PRG003_B7A2 ; If timer = 0, jump to PRG003_B7A2
STA Objects_ColorCycle,X ; Cycle colors
CMP #$01
BNE PRG003_B79F ; If timer <> 1, jump to PRG003_B79F
; Var7 = 0
LDA #$00
STA Objects_Var7,X
JSR Blooper_LaunchKids ; Blooper launches off his four spawn
PRG003_B79F:
JMP PRG003_B85C ; Jump to PRG003_B85C
PRG003_B7A2:
LDA <Objects_Var5,X
AND #$01
TAY ; Y = 0 or 1
LDA <Objects_YVel,X
ADD Blooper_YVelAccel,Y
STA <Objects_YVel,X
CMP Blooper_YVelLimit,Y
BNE PRG003_B7B6 ; If Blooper is not at his velocity limit, jump to PRG003_B7B6
INC <Objects_Var5,X ; Otherwise, Var5++
PRG003_B7B6:
LDA <Objects_YVel,X
LDY Objects_FlipBits,X
BEQ PRG003_B7C0 ; If Blooper is not flipped, jump to PRG003_B7C0
JSR Negate ; Otherwise, negate Y velocity
PRG003_B7C0:
LDY <Objects_YVel,X
BMI PRG003_B7DD ; If Bloope is moving upward, jump to PRG003_B7DD
TXA
LSR A
BCC PRG003_B7D2 ; If Blooper is an "even" slot, jump to PRG003_B7D2
LDY #$00 ; Y = 0
LDA <Player_FlipBits
BNE PRG003_B7CF ; If Blooper is flipped, jump to PRG003_B7CF
INY ; Y = 1
PRG003_B7CF:
JMP PRG003_B7D5 ; Jump to PRG003_B7D5
PRG003_B7D2:
JSR Level_ObjCalcXDiffs
PRG003_B7D5
; Blooper faces Player
LDA Blooper_FlipTowardsPlayer,Y
STA Objects_FlipBits,X
LDA #$00 ; A = 0
PRG003_B7DD:
STA <Objects_XVel,X ; Update X Velocity
JSR Object_WorldDetectN1 ; Detect against world
LDA <Objects_DetStat,X
AND #$03
BNE PRG003_B7EB ; If Blooper hit a wall, jump to PRG003_B7EB
JSR Object_ApplyXVel ; Otherwise, apply X Velocity
PRG003_B7EB:
LDA <Objects_YVel,X
PHA ; Save Y velocity
CMP #$08
BLS PRG003_B814 ; If Y velocity < $08, jump to PRG003_B814
LDA <Player_Y
PHA ; Save Player's Y
SBC #23
STA <Player_Y ; Subtract 23 from Player's Y
LDA <Player_YHi
PHA ; Save Player Y Hi
SBC #$00 ; Apply carry
STA <Player_YHi
JSR Level_ObjCalcYDiffs
; Restore Player Y/Hi
PLA
STA <Player_YHi
PLA
STA <Player_Y
DEY ; Y--
BEQ PRG003_B810 ; If Y = 0, jump to PRG003_B810
PLA ; Restore Y velocity
LDA #$08
PHA ; Save 8 instead
PRG003_B810:
; Set velocity to $08
LDA #$08
STA <Objects_YVel,X
PRG003_B814:
LDA <Objects_DetStat,X
AND #$0c
BNE PRG003_B826 ; If Blooper hit floor or ceiling, jump to PRG003_B826
LDA <Objects_YVel,X
BPL PRG003_B823 ; If Blooper is not moving upward, jump to PRG003_B823
LDA Objects_InWater,X
BEQ PRG003_B826 ; If Blooper is not in water, jump to PRG003_B826
PRG003_B823:
JSR Object_ApplyYVel_NoLimit ; Apply Y Velocity
PRG003_B826:
PLA ; Restore Y Velocity
STA <Objects_YVel,X ; Update Y Veocity
JSR Object_DeleteOffScreen ; Delete object if it falls too far off-screen
LDA #$01 ; A = 1
LDY <Objects_YVel,X
BPL PRG003_B833 ; If Blooper is not moving upward, jump to PRG003_B833
LSR A ; A = 0
PRG003_B833:
STA Objects_Frame,X ; Set frame based on movement
LDA Level_ObjectID,X
CMP #OBJ_BLOOPER
BEQ PRG003_B85F ; If this is a normal Blooper, jump to PRG003_B85F
CMP #OBJ_BLOOPERCHILDSHOOT
BNE PRG003_B85C ; If this is NOT a Blooper that launches children, jump to PRG003_B85C
INC Objects_Var2,X ; Var2++
LDA Objects_Var2,X
AND #$3f
BNE PRG003_B85C ; If Var2 hasn't hit 64 ticks yet, jump to PRG003_B85C
LDA Objects_Var7,X
CMP #$04
BNE PRG003_B859 ; If Var7 <> 4, jump to PRG003_B859
; After all this, set timer to $40
LDA #$40
STA Objects_Timer,X
BNE PRG003_B85C ; Jump (technically always) to PRG003_B85C
PRG003_B859:
INC Objects_Var7,X ; Var7++
PRG003_B85C:
JMP Tail_DrawAndHurtPlayer ; Jump to Tail_DrawAndHurtPlayer
PRG003_B85F:
JMP Object_ShakeAndDrawMirrored ; Draw Blooper and don't come back!
BlooperKid_YVel: .byte $F8, $08, $08, $F8
BlooperKid_XVel: .byte $08, $08, $F8, $F8
BlooperKid_Data: .byte $00, $00, $01, $01
BlooperKid_UNKD: .byte $00, $01, $01, $00
Blooper_LaunchKids:
; Temp_Var1 = 3
LDA #$03
STA <Temp_Var1
PRG003_B876:
JSR SpecialObj_FindEmptyAbort
; Blooper child
LDA #SOBJ_BLOOPERKID
STA SpecialObj_ID,Y
; Blooper child X
LDA <Objects_X,X
ADD #$04
STA SpecialObj_XLo,Y
; Blooper child Y
LDA <Objects_Y,X
STA SpecialObj_YLo,Y
; Blooper child Y Hi
LDA <Objects_YHi,X
STA SpecialObj_YHi,Y
LDX <Temp_Var1 ; X = Temp_Var1
LDA BlooperKid_YVel,X
STA SpecialObj_YVel,Y
LDA BlooperKid_XVel,X
STA SpecialObj_XVel,Y
LDA BlooperKid_Data,X
STA SpecialObj_Data,Y
LDA BlooperKid_UNKD,X
STA SpecialObj_Var1,Y
LDA #$ff
STA SpecialObj_Timer,Y
LDX <SlotIndexBackup ; X = object slot index
DEC <Temp_Var1 ; Temp_Var1--
BPL PRG003_B876 ; While Temp_Var1 >= 0, loop
RTS ; Return
Object_SetHFlipByXVel:
; Clear horizontal flip
LDA Objects_FlipBits,X
AND #~SPR_HFLIP
LDY <Objects_XVel,X
BEQ PRG003_B8C6 ; If not moving horizontally, jump to PRG003_B8C6
BMI PRG003_B8C3 ; If moving leftward, jump to PRG003_B8C3
; Moving to the right
ORA #SPR_HFLIP ; Set horizontal flip
PRG003_B8C3:
STA Objects_FlipBits,X ; Update flip bits
PRG003_B8C6:
RTS ; Return
; Temp_Var2 is an X input
; I don't really understand this function, but it determines horizontal
; visibility by Sprite X somehow. Carry set if not visible.
Sprite_NoCarryIfVisible:
LDA Objects_SprVVis,X
BNE PRG003_B8E7 ; If any of the sprites are vertically off-screen, jump to PRG003_B8E7
LDA <Objects_SpriteY,X
CMP #208
BGE PRG003_B8E7 ; If sprite Y >= 208, jump to PRG003_B8E7
LDY #$40 ; Y = $40
LDA <Objects_SpriteX,X
BMI PRG003_B8DA ; If sprite X >= $80, jump to PRG003_B8DA
LDY #$C0 ; Y = $C0
PRG003_B8DA:
CPY <Temp_Var2 ; Compare $40 or $C0 to input X value
EOR Objects_SprHVis,X
BMI PRG003_B8E5 ; If there are inappropriate horizontally off-screen sprites (??) jump to PRG003_B8E5
BLT PRG003_B8E7 ; If input X value < 'Y', jump to PRG003_B8E7 (carry clear, but will set carry)
BGE PRG003_B8E9 ; If input X value >= 'Y', jump to PRG003_B8E9 (carry set, but will be clear)
PRG003_B8E5:
BLT PRG003_B8E9 ; If input X value < 'Y', jump to PRG003_B8E9 (carry clear)
PRG003_B8E7:
SEC ; Set carry
RTS ; Return
PRG003_B8E9:
CLC ; Clear carry
RTS ; Return
Chomp_JumpYVels: .byte -$40, -$60
Chomp_XVels: .byte $30, -$30
ObjNorm_ChainChompFree:
JSR Object_CheckIfNormalState
BEQ PRG003_B8F7 ; If in normal state, jump to PRG003_B8F7
JMP Tail_DrawAndHurtPlayer ; Otherwise, jump to Tail_DrawAndHurtPlayer
PRG003_B8F7:
LDA <Player_HaltGame
BEQ PRG003_B8FE ; If gameplay is not halted, jump to PRG003_B8FE
JMP PRG003_BB17 ; Jump to PRG003_BB17
PRG003_B8FE:
JSR Object_SetHFlipByXVel ; Set horizontal flip by travel direction
; Toggle frame
LDA <Counter_1
LSR A
LSR A
LSR A
AND #$01
STA Objects_Frame,X
JSR Object_WorldDetectN1 ; Detect world
JSR Object_HandleBumpUnderneath ; Get killed if hit from underneath
LDA <Player_HaltGame
BEQ PRG003_B918 ; If gameplay is not halted, jump to PRG003_B918
JMP PRG003_BB17 ; Jump to PRG003_BB17
PRG003_B918:
LDA Objects_Timer,X
BNE PRG003_B95A ; If timer is not expired, jump to PRG003_B95A
JSR Object_ApplyXVel ; Apply X Velocity
JSR Object_ApplyYVel_NoLimit ; Apply Y Velocity
LDA <Objects_YVel,X
BMI PRG003_B92B ; If freed chomp is moving upward, jump to PRG003_B92B
CMP #$70
BGE PRG003_B932 ; If Y velocity >= $70, jump to PRG003_B932
PRG003_B92B:
; Chomp's gravity
LDA <Objects_YVel,X
ADD #$06
STA <Objects_YVel,X
PRG003_B932:
LDA <Objects_DetStat,X
AND #$04
BEQ PRG003_B95A ; If chomp has not hit ground, jump to PRG003_B95A
; Timer = $0C
LDA #$0c
STA Objects_Timer,X
JSR Object_HitGround ; Align to floor
LDA RandomN,X
AND #$01
TAY ; Y = random 0 or 1
; Random jump velocity of two
LDA Chomp_JumpYVels,Y
STA <Objects_YVel,X
LDA <Objects_XVel,X
ASL A
ROL A
AND #$01
TAY ; Y = 0 or 1, depending if X Velocity is negative
; Set X velocity in facing direction
LDA Chomp_XVels,Y
STA <Objects_XVel,X
JMP PRG003_BDE6 ; Jump to PRG003_BDE6
PRG003_B95A:
JMP Enemy_DeleteIfOffAndDrawTail ; Jump to Enemy_DeleteIfOffAndDrawTail
ObjInit_FireSnake:
JSR Object_InitTailBuffer ; Initialize tail buffer (if no buffer available, will be destroyed and won't come back)
; Set X velocity = 0
LDA #$00
STA <Objects_XVel,X
BEQ PRG003_B96E ; Jump (technically always) to PRG003_B96E
ObjInit_FireChomp:
JSR Object_InitTailBuffer ; Initialize tail buffer (if no buffer available, will be destroyed and won't come back)
; Var5 = random value
LDA RandomN,X
STA <Objects_Var5,X
PRG003_B96E:
; Var7 = 4
LDA #$04
STA Objects_Var7,X
RTS ; Return
; Initializes the buffer which holds "tail" X and Y coordinates
Object_InitTailBuffer:
LDY #$01 ; Y = 1
PRG003_B976:
LDA Buffer_Occupied,Y
BEQ PRG003_B983 ; If this buffer slot is empty, jump to PRG003_B983
DEY ; Y--
BPL PRG003_B976 ; While Y >= 0, loop!
; Giving up...
; Do NOT return to caller
PLA
PLA
JMP Object_SetDeadAndNotSpawned ; Fire Chomp can't be created...
PRG003_B983:
; Mark buffer slot as occupied
LDA #$01
STA Buffer_Occupied,Y
JSR Object_CalcSpriteXY_NoHi
; Sprite Y -> Temp_Var1
LDA <Objects_SpriteY,X
STA <Temp_Var1
; Sprite X -> Temp_Var2
LDA <Objects_SpriteX,X
STA <Temp_Var2
TYA
STA Objects_Var6,X ; Store Buffer_Occupied slot index -> Var6
LSR A
ROR A
LSR A
LSR A ; A = $00 or $20
; Copy sprite X and Y into buffer space
TAX ; -> 'X'
LDY #$1f ; Y = $1F
PRG003_B99E:
LDA <Temp_Var1
STA Object_BufferY,X
LDA <Temp_Var2
STA Object_BufferX,X
INX ; X++
DEY ; Y--
BPL PRG003_B99E ; While Y >= 0, loop!
LDX <SlotIndexBackup ; X = object slot index
RTS ; Return
RotoDisc_VelAccels:
.byte $01, $FF, $01, $FF, $01, $FF, $01, $FF, $02, $FE, $02, $FE
PRG003_B9BB:
.byte $00, $03, $01
RotoDisc_VelLimits:
.byte $10, $F0, $10, $F0, $10, $F0, $10, $F0
PRG003_B9C6:
.byte $28, $D8, $28, $D8
ObjNorm_FireChomp:
JSR TailEnemy_DoStandard ; Do standard tailed enemy states
LDA <Player_HaltGame
BEQ PRG003_B9D4 ; If gameplay is not halted, jump to PRG003_B9D4
JMP PRG003_BD92 ; Jump (indirectly) to PRG003_BB17 (draws enemy) and don't come back!
PRG003_B9D4:
; Set frame 0
LDA #$00
STA Objects_Frame,X
LDA Objects_Timer,X
BEQ PRG003_BA08 ; If timer expired, jump to PRG003_BA08
CMP #$10
BNE PRG003_B9F2 ; If timer <> $10, jump to PRG003_B9F2
DEC Objects_Var7,X ; Var7--
BNE PRG003_B9EF ; If Var7 <> 0, jump to PRG003_B9EF
; Strips bit 0 off of X velocity?
LSR <Objects_XVel,X
ASL <Objects_XVel,X
; Var4 = $FF
LDA #$ff
STA <Objects_Var4,X
PRG003_B9EF:
JSR FireChomp_SpitFire ; Spit fire towards Player
PRG003_B9F2:
; Gaping mouth
INC Objects_Frame,X
LDA Objects_Timer,X
SUB #$08
CMP #$10
BGE PRG003_BA02 ; If timer >= $18, jump to PRG003_BA02
INC Objects_Frame,X ; Mouth open all the way
PRG003_BA02:
JSR TailEnemy_MoveTailWithScroll ; Update tail with scroll
JMP PRG003_BB17 ; Jump off to PRG003_BB17 (draws enemy) and don't come back!
PRG003_BA08:
JSR FireChomp_MoveAndExplodeDeath ; Move and explode when out of fire balls!
Enemy_DeleteIfOffAndDrawTail:
JSR Object_DeleteOffScreen ; Delete object if it falls too far off-screen
JMP Tail_DrawAndHurtPlayer ; Jump to Tail_DrawAndHurtPlayer
FireChomp_XVelLimit: .byte $0A, -$0A, $10, -$10
FireChomp_XVelAccel: .byte $01, -$01, $01, -$01
FireChomp_FlipTowardsPlayer: .byte SPR_HFLIP, $00
FireChomp_YVelLimit: .byte $12, -$12
FireChomp_YVelAccel: .byte $01, -$01
FireChomp_MoveAndExplodeDeath:
LDA <Objects_Var4,X
BEQ PRG003_BA38 ; If Var4 = 0, jump to PRG003_BA38
DEC <Objects_Var4,X ; Var4--
CMP #$40
BGE PRG003_BA4C ; If Var4 >= $40, jump to PRG003_BA4C
STA Objects_ColorCycle,X ; Cycle colors
CMP #$01
BNE PRG003_BA4C ; If Var4 <> 1, jump to PRG003_BA4C
; Turn into a Bob-omb (for the explosion!)
LDA #OBJ_BOBOMB
STA Level_ObjectID,X
JMP BobOmb_Explode ; Jump to BobOmb_Explode (do Bob-omb's explosion routine)
PRG003_BA38:
; Var4 = 0...
INC Objects_Var2,X ; Var2++
LDA Objects_Var2,X
AND #$7f
BNE PRG003_BA4C ; 128 ticks on, 128 ticks off; jump to PRG003_BA4C
LDA Objects_Var7,X
BEQ PRG003_BA4C ; If Var7 = 0, jump to PRG003_BA4C
; Timer = $20
LDA #$20
STA Objects_Timer,X
PRG003_BA4C:
JSR Level_ObjCalcXDiffs
; Face Player
LDA FireChomp_FlipTowardsPlayer,Y
STA Objects_FlipBits,X
LDA Objects_Var7,X
BNE PRG003_BA5C ; If Var7 <> 0, jump to PRG003_BA5C
; Y += 2
INY
INY
PRG003_BA5C:
INC Objects_Var3,X ; Var3++
LDA Objects_Var3,X
LSR A
BCC PRG003_BA72 ; Every other tick, jump to PRG003_BA72
LDA <Objects_XVel,X
CMP FireChomp_XVelLimit,Y
BEQ PRG003_BA72 ; If Fire Chomp's X velocity is at limit, jump to PRG003_BA72
; Otherwise, accelerate!
ADD FireChomp_XVelAccel,Y
STA <Objects_XVel,X
PRG003_BA72:
JSR Object_ApplyXVel ; Apply X velocity
LDA <Player_Y
PHA ; Save Player's Y
ADD #$00 ; Add ... zero?
STA <Player_Y ; Update Player's Y (pointless!)
LDA <Player_YHi
PHA ; Save Player's Y Hi
ADC #$00 ; Apply carry
STA <Player_YHi ; Update Player's Y Hi
JSR Level_ObjCalcYDiffs
PLA
STA <Player_YHi ; Restore Player's Y Hi
PLA
STA <Player_Y ; Restore Player's Y
LDA Objects_Var3,X
LSR A
BCC PRG003_BAA0 ; Every other count of Var3, jump to PRG003_BAA0
LDA <Objects_YVel,X
CMP FireChomp_YVelLimit,Y
BEQ PRG003_BAA0 ; If Fire Chomp's Y velocity is at limit, jump to PRG003_BAA0
; Otherwise, accelerate!
ADD FireChomp_YVelAccel,Y
STA <Objects_YVel,X
PRG003_BAA0:
JMP Object_ApplyYVel_NoLimit ; Apply Y velocity and don't come back!
; Moves all tail segments based on screen scroll change
TailEnemy_MoveTailWithScroll:
; Essentially shift Var6 left 5 places, so A = $00 or $20 (buffer offset)
LDA Objects_Var6,X
LSR A
ROR A
LSR A
LSR A
ADD #31 ; +31
TAY ; -> 'Y'
LDX #$1f ; X = $1F (all buffer entries)
PRG003_BAB0:
; Update X by scroll
LDA Object_BufferX,Y
SUB Level_ScrollDiffH
STA Object_BufferX,Y
; Update Y by scroll
LDA Object_BufferY,Y
SUB Level_ScrollDiffV
STA Object_BufferY,Y
DEY ; Y-- (previous buffer)
DEX ; X-- (decrement counter)
BPL PRG003_BAB0 ; While X >= 0, loop!
LDX <SlotIndexBackup ; X = object slot index
RTS ; Return
FireChompTail_Patterns:
.byte $65, $67, $65, $67
FireChompTail_Attributes:
.byte SPR_PAL1, SPR_PAL1, SPR_HFLIP | SPR_VFLIP | SPR_PAL1, SPR_HFLIP | SPR_VFLIP | SPR_PAL1
; For objects which have "tails", like the Fire Snake, Blooper w/ kids, etc.
Tail_DrawAndHurtPlayer:
JSR Object_DetermineHorzVis ; Determine is object is horizontally visible
; Essentially shift Var6 left 5 places, so A = $00 or $20 (buffer offset)
LDA Objects_Var6,X
LSR A
ROR A
LSR A
LSR A
PHA ; Save offset
TAY ; -> 'Y'
; Set buffer X
LDA <Objects_X,X
SUB <Horz_Scroll
ADD Level_ScrollDiffH
STA Object_BufferX,Y
; Set buffer Y
LDA <Objects_Y,X
SUB Level_VertScroll
ADD Level_ScrollDiffV
STA Object_BufferY,Y
PLA ; Restore offset
ADD #$1e ; Add $1E (other end of the buffer)
TAY ; -> 'Y'
LDX #$1e ; X = $1E (going to work backward)
PRG003_BAFF:
; Subtract and push down the line X
LDA Object_BufferX,Y
SUB Level_ScrollDiffH
STA Object_BufferX+1,Y
; Subtract and push down the line Y
LDA Object_BufferY,Y
SUB Level_ScrollDiffV
STA Object_BufferY+1,Y
DEY ; Y-- (previous buffer byte)
DEX ; X-- (previous buffer count)
BPL PRG003_BAFF ; While X >= 0, loop!
PRG003_BB17:
LDX <SlotIndexBackup ; X = object slot index
LDA Level_ObjectID,X
CMP #OBJ_BLOOPERCHILDSHOOT
BEQ PRG003_BB24 ; If this is a Blooper who launches off kids, jump to PRG003_BB24
CMP #OBJ_BLOOPERWITHKIDS
BNE PRG003_BB2A ; If this is not a Blooper w/ kids, jump to PRG003_BB2A
PRG003_BB24:
JSR Object_ShakeAndDrawMirrored ; Draw object
JMP PRG003_BB36 ; Jump to PRG003_BB36
PRG003_BB2A:
CMP #OBJ_FIRECHOMP
BNE PRG003_BB33 ; If this is not a Fire Chomp, jump to PRG003_BB33
; For a Fire Chomp....
LDA Objects_Frame,X
BEQ PRG003_BB24 ; If frame = 0, jump to PRG003_BB24
PRG003_BB33:
JSR Object_ShakeAndDraw ; Draw object, not mirrored
PRG003_BB36:
LDA Object_SprRAM,X
ADD #$08
STA <Temp_Var5 ; Temp_Var5 = Sprite_RAM offset two bytes over
; Essentially shift Var6 left 5 places, so A = $00 or $20 (buffer offset)
LDA Objects_Var6,X
LSR A
ROR A
LSR A
LSR A
ADD #$07
STA <Temp_Var4 ; Temp_Var4 = offset 7 bytes into the X/Y buffer
LDA Objects_Var7,X
BNE PRG003_BB52 ; If Var7 <> 0, jump to PRG003_BB52
JMP PRG003_BBF5 ; Jump to PRG003_BBF5
PRG003_BB52:
STA <Temp_Var16 ; Var7 -> Temp_Var16 (Tail length)
; TAIL DRAW / HURT LOGIC
; The following
PRG003_BB54:
LDY <Temp_Var4 ; Y = offset into X/Y Buffer
; Temp_Var1 = Buffer Y @ Temp_Var4
LDA Object_BufferY,Y
STA <Temp_Var1
; Temp_Var2 = Buffer X @ Temp_Var4 + 4
LDA Object_BufferX,Y
ADD #$04
STA <Temp_Var2
JSR Sprite_NoCarryIfVisible
BCS PRG003_BBE0 ; If carry set, sprite is not visible, jump to PRG003_BBE0
LDY <Temp_Var5 ; Y = Temp_Var5 (Sprite_RAM offset)
; Store Y and X into sprite RAM
LDA <Temp_Var1
STA Sprite_RAM+$00,Y
LDA <Temp_Var2
STA Sprite_RAM+$03,Y
LDA Level_ObjectID,X
CMP #OBJ_ROTODISCCLOCKWISE
BGE PRG003_BBBE ; Basically if a Blooper jump to PRG003_BBBE
; Fire Snake, Fire Chomp, or freed Chain Chomp
CMP #OBJ_FIRECHOMP
BNE PRG003_BB9B ; If not a Fire Chomp, jump to PRG003_BB9B
; Fire Chomp only
LDA <Temp_Var16
ASL A
ADC Level_NoStopCnt
LSR A
LSR A
AND #$03
TAX ; X = 0 to 3
LDA FireChompTail_Patterns,X
STA Sprite_RAM+$01,Y
LDA FireChompTail_Attributes,X
STA Sprite_RAM+$02,Y
LDX <SlotIndexBackup ; X = object slot index
JMP PRG003_BBDD ; Jump to PRG003_BBDD
PRG003_BB9B:
CMP #OBJ_CHAINCHOMPFREE
BEQ PRG003_BBB2 ; If a freed Chain Chomp, jump to PRG003_BBB2
; Fire snake
; Sets the carry
LDA Level_NoStopCnt
LSR A
LSR A
; Something removed here
NOP
NOP
LDA #$8b ; A = $8B
BCC PRG003_BBAC ; 4 ticks on, 4 ticks off; jump to PRG003_BBAC
LDA #$89 ; A = $89
PRG003_BBAC:
STA Sprite_RAM+$01,Y ; Store pattern $89 or $8B
JMP PRG003_BBD2 ; Jump to PRG003_BBD2
PRG003_BBB2:
; Freed Chain Chomp
; Chain link pattern
LDA #$9b
STA Sprite_RAM+$01,Y
; Palette select 3
LDA #SPR_PAL3
STA Sprite_RAM+$02,Y
BNE PRG003_BBE0 ; Jump (technically always) to PRG003_BBE0
PRG003_BBBE:
LDA <Temp_Var16
ASL A
ADC Level_NoStopCnt
LDX #$b5 ; X = $B5
AND #$08
BNE PRG003_BBCC ; 8 ticks on, 8 ticks off; jump to PRG003_BBCC
LDX #$b7 ; X = $B7
PRG003_BBCC:
TXA ; Pattern -> 'X'
STA Sprite_RAM+$01,Y ; Set pattern
LDX <SlotIndexBackup ; X = object slot index
PRG003_BBD2:
LDY Object_SprRAM,X ; Y = Sprite_RAM offset
; Copies attribute from one sprite to the other
LDA Sprite_RAM+$02,Y
LDY <Temp_Var5
STA Sprite_RAM+$02,Y
PRG003_BBDD:
JSR Tail_CheckHurtPlayer ; Have the tail hurt the Player by touching it
PRG003_BBE0:
LDA <Temp_Var4
ADD #$08
STA <Temp_Var4
LDA <Temp_Var5
ADD #$04
STA <Temp_Var5
DEC <Temp_Var16 ; Temp_Var16-- (one less tail segment)
BEQ PRG003_BBF5 ; If out of segments, jump to PRG003_BBF5
JMP PRG003_BB54 ; Otherwise, loop!
PRG003_BBF5:
LDX <SlotIndexBackup ; X = object slot index
RTS ; Return
RotoDiscSpin:
LDA <Objects_Var4,X
BEQ PRG003_BC6D ; If Var4 = 0, jump to PRG003_BC6D (RTS)
JSR Object_ApplyXVel ; Apply X velocity
JSR Object_ApplyYVel_NoLimit ; Apply Y velocity
LDA <Objects_Var4,X
CMP #$01
BEQ PRG003_BC6D ; If Var4 = 1, jump to PRG003_BC6D
; Var4 > 1...
LSR A
TAY ; Y = Var4 / 2
INC Objects_Var3,X ; Var3++
LDA Objects_Var3,X ; A = Var3
AND PRG003_B9BB-1,Y ; -1 because Y will always be at least 1
BNE PRG003_BC6D ; If masking of Var3 is non-zero, jump to PRG003_BC6D (RTS)
LDA <Objects_Var4,X
SUB #$02
ASL A ; A = (Var4 - 2) << 1
AND #%11111100 ; Keep all bits but the lower 2
PHA ; Save this value
ADD Objects_TargetingXVal,X
TAY ; -> 'Y'
LDA <Objects_Var4,X
AND #$01
BEQ PRG003_BC2A ; If Var4 bit 0 is not set, jump to PRG003_BC2A
INY ; Otherwise Y++
PRG003_BC2A:
LDA <Objects_XVel,X
CMP RotoDisc_VelLimits,Y
BNE PRG003_BC3F ; If X velocity is not at its limit, jump to PRG003_BC3F
PHA ; Save X Vel
LDA Objects_TargetingXVal,X
EOR #$01
STA Objects_TargetingXVal,X
TYA
EOR #$01
TAY
PLA ; Restore X Vel
PRG003_BC3F:
ADD RotoDisc_VelAccels,Y ; Accelerate
STA <Objects_XVel,X ; Update X Velocity
PLA ; Restore indexing value
ADD Objects_TargetingYVal,X
TAY ; -> 'Y'
LDA <Objects_Var4,X
AND #$01
BEQ PRG003_BC52 ; If Var4 bit 0 is not set, jump to PRG003_BC52
INY ; Otherwise, Y++
PRG003_BC52:
LDA <Objects_YVel,X
CMP RotoDisc_VelLimits,Y
BNE PRG003_BC67 ; If Y velocity is not at its limit, jump to PRG003_BC67
PHA ; Save Y velocity
LDA Objects_TargetingYVal,X
EOR #$01
STA Objects_TargetingYVal,X
TYA
EOR #$01
TAY
PLA ; Restore Y velocity
PRG003_BC67:
ADD RotoDisc_VelAccels,Y ; Accelerate
STA <Objects_YVel,X ; Update Y Velocity
PRG003_BC6D:
RTS ; Return
FireChomp_SpitFire:
JSR SpecialObj_FindEmptyAbort ; Find an empty special object slot or don't come back!
; Fire Chomp's fireball
LDA #SOBJ_FIRECHOMPFIRE
STA SpecialObj_ID,Y
; Calculate a flight path towards Player
LDA #$14
JSR BoomBoom_CalcFlightPath
; Send fireball along flight path
LDA <Temp_Var1
STA SpecialObj_YVel,Y
LDA <Temp_Var2
STA SpecialObj_XVel,Y
; Set coordinates as offset from Fire Chomp
LDA <Objects_X,X
ADD #$04
STA SpecialObj_XLo,Y
LDA <Objects_Y,X
STA SpecialObj_YLo,Y
LDA <Objects_YHi,X
STA SpecialObj_YHi,Y
RTS ; Return
; Calculates flying Boom Boom's path so he flies towards Player
BoomBoom_CalcFlightPath:
STA <Temp_Var2 ; Store input value -> Temp_Var2
; Backup 'X' and 'Y'
TXA
PHA
TYA
PHA
JSR Level_ObjCalcYDiffs
STY <Temp_Var3 ; Store Y difference indicator -> Temp_Var3
; Get absolute value of Y difference
LDA <Temp_Var16
BPL PRG003_BCAA
JSR Negate
PRG003_BCAA:
STA <Temp_Var13 ; -> Temp_Var13
JSR Level_ObjCalcXDiffs
STY <Temp_Var4 ; Store X difference indicator -> Temp_Var4
; Get absolute value of X difference
LDA <Temp_Var16
BPL PRG003_BCB8
JSR Negate
PRG003_BCB8:
STA <Temp_Var14 ; -> Temp_Var14
LDY #$00 ; Y = 0
LDA <Temp_Var14
CMP <Temp_Var13
BGE PRG003_BCCB ; If Y difference >= X difference, jump to PRG003_BCCB
INY ; Y = 1
; Swap differences (so greater difference will be in Temp_Var14)
PHA
LDA <Temp_Var13
STA <Temp_Var14
PLA
STA <Temp_Var13
PRG003_BCCB:
LDA #$00
STA <Temp_Var12 ; Clear Temp_Var12
STA <Temp_Var1 ; Clear Temp_Var1
LDX <Temp_Var2 ; X = Temp_Var2 (original input value)
PRG003_BCD3:
LDA <Temp_Var12
ADD <Temp_Var13 ; A = Temp_Var12 + Temp_Var13 (the lesser difference)
CMP <Temp_Var14
BLT PRG003_BCE0 ; If (Temp_Var12 + Temp_Var13) < Temp_Var14 (the greater difference), jump to PRG003_BCE0
; If (Temp_Var12 + Temp_Var13) >= Temp_Var14
SBC <Temp_Var14 ; Subtract total from Temp_Var14
INC <Temp_Var1 ; Temp_Var1++
PRG003_BCE0:
STA <Temp_Var12 ; Update Temp_Var12 with the previous total
DEX ; X--
BNE PRG003_BCD3 ; While X >= 0, loop!
TYA ; A = 0 or 1
BEQ PRG003_BCF2 ; If zero (don't need to swap), jump to PRG003_BCF2
; Swap Temp_Var1 and Temp_Var2
LDA <Temp_Var1
PHA
LDA <Temp_Var2
STA <Temp_Var1
PLA
STA <Temp_Var2
PRG003_BCF2:
LDA <Temp_Var1 ; A = Temp_Var1
LDY <Temp_Var3 ; Y = Temp_Var3 (Y difference indicator)
BEQ PRG003_BCFD ; If Player was lower than object, jump to PRG003_BCFD
; Otherwise, negate Temp_Var1
JSR Negate
STA <Temp_Var1
PRG003_BCFD:
LDA <Temp_Var2 ; A = Temp_Var2
LDY <Temp_Var4 ; Y = Temp_Var4 (X difference indicator)
BEQ PRG003_BD08 ; If Player was lower than object, jump to PRG003_BD08
; Otherwise, negate Temp_Var2
JSR Negate
STA <Temp_Var2
PRG003_BD08:
; Restore 'Y' and 'X'
PLA
TAY
PLA
TAX
RTS ; Return
Tail_PlayerYOff: .byte $12, $04 ; Offset to Player Sprite Y for small/ducking, or not
Tail_PlayerYLimit: .byte $0E, $18 ; Limit value
; For enemies with tails (e.g. Fire Snake, Fire Chomp, Blooper with Kids),
; checks if the Player has touched any part of their tail and should be hurt.
Tail_CheckHurtPlayer:
LDA <Temp_Var16
ADD <Counter_1
LSR A
BCC PRG003_BD60 ; Every other tick, jump to PRG003_BD60 (RTS)
LDA Objects_Var1,X
BNE PRG003_BD60 ; If Var1 <> 0, jump to PRG003_BD60 (RTS)
PRG003_BD1E:
LDY #$00 ; Y = 0
LDA <Player_Suit
BEQ PRG003_BD2A ; If Player is small, jump to PRG003_BD2A
LDA Player_IsDucking
BNE PRG003_BD2A ; If Player is ducking, jump to PRG003_BD2A
INY ; Y = 1
PRG003_BD2A:
LDA <Temp_Var1
CMP #$c3
BGE PRG003_BD60 ; If Temp_Var1 >= $C3, jump to PRG003_BD60 (RTS)
ADD #$08
SUB <Player_SpriteY
SUB Tail_PlayerYOff,Y
CMP Tail_PlayerYLimit,Y
BGE PRG003_BD60 ; If Player is not in good Y range, jump to PRG003_BD60 (RTS)
LDA <Temp_Var2
ADD #$04
SUB <Player_SpriteX
SBC #$00
CMP #$10
BGE PRG003_BD60 ; If Player is not in good X range, jump to PRG003_BD60 (RTS)
LDA Player_StarInv
BNE PRG003_BD60 ; If Player is invincible by Starman, jump to PRG003_BD60 (RTS)
Player_HurtIfNotDieOffBehind:
ORA Player_IsDying ; If Player is dying...
ORA Player_OffScreen ; ... off-screen ...
ORA Player_Behind_En ; ... or behind the scenes ...
BNE PRG003_BD60 ; ... jump to PRG003_BD60 (RTS)
JSR Player_GetHurt ; Otherwise, hurt Player!
PRG003_BD60:
RTS ; Return
FireSnake_XVelTowardsPlayer: .byte $08, -$08
FireSnake_FlipForTick: .byte $00, $00, SPR_HFLIP, SPR_HFLIP
FireSnake_FrameForTick: .byte $00, $01, $00, $01
FireSnake_JumpYVel: .byte -$18, -$24
FireSnake_RandomTimer3Vals: .byte $50, $70, $00, $70, $50, $00, $00, $00
ObjNorm_FireSnake:
LDA Level_NoStopCnt
LSR A
AND #$03
TAY ; Y = 0 to 3
; Set flip bit for this tick
LDA FireSnake_FlipForTick,Y
STA Objects_FlipBits,X
; Set frame for this tick
LDA FireSnake_FrameForTick,Y
STA Objects_Frame,X
JSR Object_WorldDetect4 ; Detect against the world
JSR TailEnemy_DoStandard ; Do standard tailed enemy states
LDA <Player_HaltGame
BEQ PRG003_BD95 ; If gameplay is NOT halted, jump to PRG003_BD95
PRG003_BD92:
JMP PRG003_BB17 ; Jump off to PRG003_BB17 (draws enemy) and don't come back!
PRG003_BD95:
LDA Objects_Timer,X
BNE PRG003_BDE6 ; If timer not expired, jump to PRG003_BDE6
JSR Object_ApplyXVel ; Apply X velocity
JSR Object_ApplyYVel_NoLimit ; Apply Y velocity
LDA <Objects_YVel,X
BMI PRG003_BDA8 ; If Fire Snake is moving upward, jump to PRG003_BDA8
CMP #$18
BGE PRG003_BDAA ; If Fire Snake is moving at $18 downward, jump to PRG003_BDAA
PRG003_BDA8:
INC <Objects_YVel,X ; Fire Snake's light gravity
PRG003_BDAA:
LDA <Objects_DetStat,X
AND #$04
BEQ PRG003_BDE6 ; If Fire Snake has not touched ground, jump to PRG003_BDE6
LDA Objects_Timer3,X
BNE PRG003_BDE6 ; If timer 3 is not expired, jump to PRG003_BDE6
; timer = $15
LDA #$15
STA Objects_Timer,X
JSR Object_HitGround ; Align Fire Snake to ground
LDA RandomN,X
AND #$01
TAY ; Y = 0 or 1, random
; Fire Snake's random hop
LDA FireSnake_JumpYVel,Y
STA <Objects_YVel,X
JSR Level_ObjCalcYDiffs
CPY #$00
BNE PRG003_BDDB ; If Player is lower than Fire Snake, jump to PRG003_BDDB
LDA RandomN,X
AND #$07
TAY ; Y = 0 to 7, random
; Random timer 3 reload value
LDA FireSnake_RandomTimer3Vals,Y
STA Objects_Timer3,X
PRG003_BDDB:
JSR Level_ObjCalcXDiffs
; Set X velocity towards Player
LDA FireSnake_XVelTowardsPlayer,Y
STA <Objects_XVel,X
JMP PRG003_BDE6 ; Jump to PRG003_BDE6 (... right down below)
PRG003_BDE6:
JMP Enemy_DeleteIfOffAndDrawTail ; Delete if off-screen, draw tail, and don't come back!
PRG003_BDE9:
JSR Object_SetHFlipByXVel ; Set horizontal flip by travel direction
TailEnemy_DoStandard:
LDA Objects_Var1,X
BEQ TailEnemy_InitOrHalt ; If Var1 = 0, jump to TailEnemy_InitOrHalt
LDY <Player_HaltGame
BEQ PRG003_BDFA ; If gameplay is not halted, jump to PRG003_BDFA
; Do not return to caller!
PLA
PLA
JMP PRG003_BB17 ; Jump off to PRG003_BB17 (draws enemy) and don't come back!
PRG003_BDFA:
; Jump based on Var1
JSR DynJump
; THESE MUST FOLLOW DynJump FOR THE DYNAMIC JUMP TO WORK!!
.word TailEnemy_InitOrHalt ; 0: Action to take initially or when gameplay is halted
.word TailEnemy_DrawAndWaitTimer2 ; 1: Draws object and waits for timer 2 to expire; WILL NOT RETURN TO CALLER!
.word TailEnemy_DoDeath ; 2: Does "wiggle death" and draws tail; WILL NOT RETURN TO CALLER!
TailEnemy_InitOrHalt:
JSR Object_CheckIfNormalState
BEQ PRG003_BE1D ; If in normal state, jump to PRG003_BE1D
; Not in normal state...
; Var1 = 1 (next internal state)
LDA #$01
STA Objects_Var1,X
LSR A
STA <Objects_XVel,X ; Stop horizontal velocity
STA <Objects_VarBSS+1,X
; Color cycle!
LDA #$10
STA Objects_ColorCycle,X
; Timer2 = 8
LDA #$08
STA Objects_Timer2,X
RTS ; Return
PRG003_BE1D:
LDA Level_ObjectID,X
CMP #OBJ_FIRESNAKE
BNE PRG003_BE27 ; If this is NOT a Fire Snake, jump to PRG003_BE27
JMP Object_HandleBumpUnderneath ; Otherwise just handle getting bumped underneath and don't come back!
PRG003_BE27:
JMP Player_HitEnemy ; Handle full enemy-to-Player collision and don't come back!
TailEnemy_DrawAndWaitTimer2:
LDA Objects_Timer2,X
BNE PRG003_BE37 ; If timer2 is not expired, jump to PRG003_BE37
INC Objects_Var1,X ; Var1++ (next internal state)
; Timer2 = $FF
LDA #$ff
STA Objects_Timer2,X
PRG003_BE37:
; Do NOT return to caller!
PLA
PLA
JMP Enemy_DeleteIfOffAndDrawTail ; Delete if off-screen, draw tail, and don't come back!
PRG003_BE3A:
RTS ; Return
TailEnemy_DoDeath:
LDA Objects_Timer2,X
BNE PRG003_BE52 ; If timer 2 is not expired, jump to PRG003_BE52
; Timer 2 expired...
STA Objects_Var1,X ; Var1 = 0 (Return to initial internal state)
; Removes bit 7 (vertical flip)
ASL Objects_FlipBits,X
LSR Objects_FlipBits,X
; Little hop upward
LDA #-$10
STA <Objects_YVel,X
JMP PRG003_BE37 ; Draw tail, Do NOT return to caller, and don't come back!
PRG003_BE52:
; Sets vertical flip bit 7
ASL Objects_FlipBits,X
SEC
ROR Objects_FlipBits,X
JSR Object_ApplyXVel ; Apply X velocity
JSR Object_ApplyYVel_NoLimit ; Apply Y velocity
LDA <Objects_YVel,X
BMI PRG003_BE67 ; If enemy moving upward, jump to PRG003_BE67
CMP #$18
BGE PRG003_BE6B ; If enemy moving downward >= $18, jump to PRG003_BE6B
PRG003_BE67:
; Apply gravity
INC <Objects_YVel,X
INC <Objects_YVel,X
PRG003_BE6B:
LDY #$08 ; Y = $08
LDA Level_NoStopCnt
AND #$08
BEQ PRG003_BE76 ; 8 ticks on, 8 ticks off; jump to PRG003_BE76
LDY #-$08 ; Y = -$08
PRG003_BE76:
STY <Objects_XVel,X ; Set X velocity as $08 or -$08
JMP PRG003_BE37 ; Draw tail, Do NOT return to caller, and don't come back!
ObjInit_RotoDiscDualCW:
LDY #$03 ; Y = 3
LDA PRG003_B9C6+1
BNE PRG003_BE87 ; Jump (technically always) to PRG003_BE87
ObjInit_RotoDiscDualCCW:
LDY #-$02 ; Y = -$02
; Set initial Y velocity
LDA PRG003_B9C6
PRG003_BE87:
STA <Objects_YVel,X
STY <Temp_Var1 ; Temp_Var1 = -$02
LDA #$00
STA <Objects_XVel,X
STA Objects_XVelFrac,X
STA Objects_YVelFrac,X
LDA <Objects_X,X
STA Objects_Var13,X
SUB #$30
STA <Objects_X,X
LDA <Objects_XHi,X
STA Objects_Var10,X
SBC #$00
STA <Objects_XHi,X
LDA <Objects_Y,X
STA Objects_Var14,X
ADD <Temp_Var1
STA <Objects_Y,X
LDA #$00
LDY <Temp_Var1
BPL PRG003_BEBA
LDA #$ff
PRG003_BEBA:
ADC <Objects_YHi,X
STA Objects_Var1,X
RTS ; Return
ObjNorm_RotoDiscDualOpp:
JSR ObjNorm_RotoDisc ; Partly a regular RotoDisc...
; Backup the Y coordinates
LDA <Objects_Y,X
PHA
LDA <Objects_YHi,X
PHA
; Calculate an opposite Y for the secondary RotoDisc
LDA Objects_Var14,X
SUB <Objects_Y,X
PHA
LDA Objects_Var1,X
SBC <Objects_YHi,X
TAY
PLA
ADD Objects_Var14,X
STA <Objects_Y,X
TYA
ADC Objects_Var1,X
STA <Objects_YHi,X
; Two sprites over
LDA Object_SprRAM,X
ADD #$08
STA Object_SprRAM,X
JSR Object_DetermineHorzVis ; Determine horizontal visibility of the RotoDisc
JSR Object_DetermineVertVis ; Determine vertical visibility of the RotoDisc
JSR RotoDisc_CollideAndCycle ; Test for collision and cycle the second RotoDisc
; Restore the Y coordinates
PLA
STA <Objects_YHi,X
PLA
STA <Objects_Y,X
RTS ; Return
ObjNorm_RotoDiscDualOpp2:
JSR ObjNorm_RotoDisc ; Partly a regular RotoDisc...
; Backup the X coordinates
LDA <Objects_X,X
PHA
LDA <Objects_XHi,X
PHA
; Calculate an opposite X for the secondary RotoDisc
LDA Objects_Var13,X
SUB <Objects_X,X
PHA
LDA Objects_Var10,X
SBC <Objects_XHi,X
TAY
PLA
ADD Objects_Var13,X
STA <Objects_X,X
TYA
ADC Objects_Var10,X
STA <Objects_XHi,X
; Two sprites over
LDA Object_SprRAM,X
ADD #$08
STA Object_SprRAM,X
JSR Object_DetermineHorzVis ; Determine horizontal visibility of the RotoDisc
JSR Object_DetermineVertVis ; Determine vertical visibility of the RotoDisc
JSR RotoDisc_CollideAndCycle ; Test for collision and cycle the second RotoDisc
; Restore the X coordinates
PLA
STA <Objects_XHi,X
PLA
STA <Objects_X,X
RTS ; Return
ObjNorm_RotoDiscDual:
JSR ObjNorm_RotoDisc ; Partly a regular RotoDisc...
; Backup all of the coordinates
LDA <Objects_X,X
PHA
LDA <Objects_XHi,X
PHA
LDA <Objects_Y,X
PHA
LDA <Objects_YHi,X
PHA
; Calculate an opposite X and opposite Y for the secondary RotoDisc
LDA Objects_Var13,X
SUB <Objects_X,X
PHA
LDA Objects_Var10,X
SBC <Objects_XHi,X
TAY
PLA
ADD Objects_Var13,X
STA <Objects_X,X
TYA
ADC Objects_Var10,X
STA <Objects_XHi,X
LDA Objects_Var14,X
SUB <Objects_Y,X
PHA
LDA Objects_Var1,X
SBC <Objects_YHi,X
TAY
PLA
ADD Objects_Var14,X
STA <Objects_Y,X
TYA
ADC Objects_Var1,X
STA <Objects_YHi,X
; Two sprites over
LDA Object_SprRAM,X
ADD #$08
STA Object_SprRAM,X
JSR Object_DetermineHorzVis ; Determine horizontal visibility of the RotoDisc
JSR Object_DetermineVertVis ; Determine vertical visibility of the RotoDisc
JSR RotoDisc_CollideAndCycle ; Test for collision and cycle the second RotoDisc
; Restore all of the coordinates
PLA
STA <Objects_YHi,X
PLA
STA <Objects_Y,X
PLA
STA <Objects_XHi,X
PLA
STA <Objects_X,X
RTS ; Return
ObjNorm_RotoDisc:
LDA <Player_HaltGame
BNE PRG003_BFAE ; If gameplay is halted, jump to PRG003_BFAE
; Var4 = 6
LDA #$06
STA <Objects_Var4,X
JSR RotoDiscSpin ; Do Rotodisc spin logic
JSR Object_DeleteOffScreen_N2 ; Delete if falls off-screen
RotoDisc_CollideAndCycle:
JSR Object_CalcSpriteXY_NoHi ; Calculate the sprite
JSR Player_HitEnemy ; Player to Rotodisc collision detection
PRG003_BFAE:
; Toggle between frame 0 and 1
LDA <Counter_1
AND #$01
STA Objects_Frame,X
; Cycle colors
LDA <Counter_1
LSR A
LSR A
STA Objects_ColorCycle,X
JMP Object_ShakeAndDraw ; Draw Rotodisc and don't come back!
; Rest of ROM bank was empty
|
; A293046: Number of even permutations on {1,2,...,n} with exactly 2 weak excedances.
; 0,0,1,1,7,11,31,57,127,247,511,1013,2047,4083,8191,16369,32767,65519,131071,262125,524287,1048555,2097151,4194281,8388607,16777191,33554431,67108837,134217727,268435427,536870911,1073741793,2147483647,4294967263,8589934591
mov $7,$0
mov $9,$0
lpb $9
mov $0,$7
sub $9,1
sub $0,$9
mov $3,$0
mov $5,2
lpb $5
sub $5,1
add $0,$5
sub $0,1
add $2,$0
mov $8,-2
pow $8,$0
add $8,$2
sub $8,1
bin $2,$8
mov $6,$5
gcd $8,$2
lpb $6
mov $4,$8
sub $6,1
lpe
lpe
lpb $3
mov $3,0
sub $4,$8
lpe
mov $8,$4
sub $8,1
div $8,2
add $1,$8
lpe
|
// Copyright 2020 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <cstring>
#include "src/tint/diagnostic/printer.h"
#define WIN32_LEAN_AND_MEAN 1
#include <Windows.h>
namespace tint::diag {
namespace {
struct ConsoleInfo {
HANDLE handle = INVALID_HANDLE_VALUE;
WORD default_attributes = 0;
operator bool() const { return handle != INVALID_HANDLE_VALUE; }
};
ConsoleInfo console_info(FILE* file) {
if (file == nullptr) {
return {};
}
ConsoleInfo console{};
if (file == stdout) {
console.handle = GetStdHandle(STD_OUTPUT_HANDLE);
} else if (file == stderr) {
console.handle = GetStdHandle(STD_ERROR_HANDLE);
} else {
return {};
}
CONSOLE_SCREEN_BUFFER_INFO info{};
if (GetConsoleScreenBufferInfo(console.handle, &info) == 0) {
return {};
}
console.default_attributes = info.wAttributes;
return console;
}
class PrinterWindows : public Printer {
public:
PrinterWindows(FILE* f, bool use_colors)
: file(f), console(console_info(use_colors ? f : nullptr)) {}
void write(const std::string& str, const Style& style) override {
write_color(style.color, style.bold);
fwrite(str.data(), 1, str.size(), file);
write_color(Color::kDefault, false);
}
private:
WORD attributes(Color color, bool bold) {
switch (color) {
case Color::kDefault:
return console.default_attributes;
case Color::kBlack:
return 0;
case Color::kRed:
return FOREGROUND_RED | (bold ? FOREGROUND_INTENSITY : 0);
case Color::kGreen:
return FOREGROUND_GREEN | (bold ? FOREGROUND_INTENSITY : 0);
case Color::kYellow:
return FOREGROUND_RED | FOREGROUND_GREEN | (bold ? FOREGROUND_INTENSITY : 0);
case Color::kBlue:
return FOREGROUND_BLUE | (bold ? FOREGROUND_INTENSITY : 0);
case Color::kMagenta:
return FOREGROUND_RED | FOREGROUND_BLUE | (bold ? FOREGROUND_INTENSITY : 0);
case Color::kCyan:
return FOREGROUND_GREEN | FOREGROUND_BLUE | (bold ? FOREGROUND_INTENSITY : 0);
case Color::kWhite:
return FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE |
(bold ? FOREGROUND_INTENSITY : 0);
}
return 0; // unreachable
}
void write_color(Color color, bool bold) {
if (console) {
SetConsoleTextAttribute(console.handle, attributes(color, bold));
fflush(file);
}
}
FILE* const file;
const ConsoleInfo console;
};
} // namespace
std::unique_ptr<Printer> Printer::create(FILE* out, bool use_colors) {
return std::make_unique<PrinterWindows>(out, use_colors);
}
} // namespace tint::diag
|
.global s_prepare_buffers
s_prepare_buffers:
push %r12
push %r8
push %r9
push %rax
push %rbp
push %rcx
push %rdi
push %rsi
lea addresses_D_ht+0x14fee, %rax
nop
nop
nop
nop
add $6520, %r9
movb $0x61, (%rax)
nop
nop
nop
nop
xor $20153, %rbp
lea addresses_normal_ht+0xfc6e, %rsi
lea addresses_WT_ht+0x63c, %rdi
nop
nop
and %r8, %r8
mov $116, %rcx
rep movsl
nop
nop
and %rax, %rax
lea addresses_A_ht+0x18c6e, %rsi
lea addresses_WC_ht+0x118b8, %rdi
dec %r12
mov $88, %rcx
rep movsl
nop
sub %r8, %r8
lea addresses_UC_ht+0x14072, %r12
nop
nop
nop
nop
add $14235, %r8
mov (%r12), %rsi
dec %rdi
lea addresses_WC_ht+0x137f7, %r12
nop
nop
nop
nop
nop
inc %rbp
movb (%r12), %r8b
sub %rax, %rax
lea addresses_D_ht+0xfcae, %rdi
nop
nop
nop
sub %rax, %rax
movb $0x61, (%rdi)
nop
nop
nop
nop
sub $30164, %rcx
lea addresses_WC_ht+0x906e, %rsi
sub %rax, %rax
mov (%rsi), %r8w
nop
nop
nop
add $53807, %r8
pop %rsi
pop %rdi
pop %rcx
pop %rbp
pop %rax
pop %r9
pop %r8
pop %r12
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r14
push %r15
push %rax
push %rcx
push %rdi
// Faulty Load
lea addresses_A+0x206e, %rax
nop
nop
cmp %rcx, %rcx
mov (%rax), %r15w
lea oracles, %rdi
and $0xff, %r15
shlq $12, %r15
mov (%rdi,%r15,1), %r15
pop %rdi
pop %rcx
pop %rax
pop %r15
pop %r14
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'src': {'congruent': 0, 'AVXalign': False, 'same': False, 'size': 2, 'NT': False, 'type': 'addresses_A'}, 'OP': 'LOAD'}
[Faulty Load]
{'src': {'congruent': 0, 'AVXalign': False, 'same': True, 'size': 2, 'NT': False, 'type': 'addresses_A'}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'congruent': 7, 'AVXalign': True, 'same': False, 'size': 1, 'NT': False, 'type': 'addresses_D_ht'}}
{'src': {'congruent': 8, 'same': False, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'dst': {'congruent': 1, 'same': False, 'type': 'addresses_WT_ht'}}
{'src': {'congruent': 10, 'same': False, 'type': 'addresses_A_ht'}, 'OP': 'REPM', 'dst': {'congruent': 1, 'same': False, 'type': 'addresses_WC_ht'}}
{'src': {'congruent': 2, 'AVXalign': False, 'same': False, 'size': 8, 'NT': False, 'type': 'addresses_UC_ht'}, 'OP': 'LOAD'}
{'src': {'congruent': 0, 'AVXalign': False, 'same': False, 'size': 1, 'NT': False, 'type': 'addresses_WC_ht'}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'congruent': 3, 'AVXalign': False, 'same': False, 'size': 1, 'NT': False, 'type': 'addresses_D_ht'}}
{'src': {'congruent': 11, 'AVXalign': False, 'same': False, 'size': 2, 'NT': False, 'type': 'addresses_WC_ht'}, 'OP': 'LOAD'}
{'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
*/
|
--- FUNCTION SOURCE (valueOf) id{0,0} ---
(){
return ToObject(this);
}
--- END ---
--- FUNCTION SOURCE (IsPrimitive) id{1,0} ---
(a){
return!(%_IsSpecObject(a));
}
--- END ---
--- FUNCTION SOURCE (toString) id{2,0} ---
(){
return FunctionSourceString(this);
}
--- END ---
--- FUNCTION SOURCE (y) id{3,0} ---
() { return this._y; },
--- END ---
--- Raw source ---
() { return this._y; },
--- Optimized code ---
optimization_id = 3
source_position = 114
kind = OPTIMIZED_FUNCTION
name = y
stack_slots = 1
Instructions (size = 204)
0x5a840ac0 0 8b4c2404 mov ecx,[esp+0x4]
0x5a840ac4 4 81f99180d03b cmp ecx,0x3bd08091 ;; object: 0x3bd08091 <undefined>
0x5a840aca 10 750a jnz 22 (0x5a840ad6)
0x5a840acc 12 8b4e13 mov ecx,[esi+0x13]
0x5a840acf 15 8b4917 mov ecx,[ecx+0x17]
0x5a840ad2 18 894c2404 mov [esp+0x4],ecx
0x5a840ad6 22 55 push ebp
0x5a840ad7 23 89e5 mov ebp,esp
0x5a840ad9 25 56 push esi
0x5a840ada 26 57 push edi
0x5a840adb 27 6a00 push 0x0
;;; <@0,#0> -------------------- B0 --------------------
;;; <@2,#1> context
0x5a840add 29 8b75fc mov esi,[ebp+0xfc] ;; debug: position 114
;;; <@8,#7> -------------------- B1 --------------------
;;; <@10,#9> stack-check
0x5a840ae0 32 3b2588282501 cmp esp,[0x1252888]
0x5a840ae6 38 7305 jnc 45 (0x5a840aed)
0x5a840ae8 40 e89385feff call StackCheck (0x5a829080) ;; code: BUILTIN
;;; <@11,#9> gap
0x5a840aed 45 8b4508 mov eax,[ebp+0x8]
;;; <@12,#11> check-non-smi
0x5a840af0 48 a801 test al,0x1 ;; debug: position 130
0x5a840af2 50 0f8466000000 jz 158 (0x5a840b5e)
;;; <@14,#12> check-maps
0x5a840af8 56 8178ff49ea505b cmp [eax+0xff],0x5b50ea49 ;; object: 0x5b50ea49 <Map(elements=3)>
0x5a840aff 63 0f855e000000 jnz 163 (0x5a840b63)
;;; <@16,#13> load-named-field
0x5a840b05 69 8b400f mov eax,[eax+0xf]
;;; <@18,#14> load-named-field
0x5a840b08 72 f20f104803 movsd xmm1,[eax+0x3]
;;; <@20,#18> number-tag-d
0x5a840b0d 77 8b0da40f2501 mov ecx,[0x1250fa4]
0x5a840b13 83 89c8 mov eax,ecx
0x5a840b15 85 83c00c add eax,0xc
0x5a840b18 88 0f8227000000 jc 133 (0x5a840b45)
0x5a840b1e 94 3b05a80f2501 cmp eax,[0x1250fa8]
0x5a840b24 100 0f871b000000 ja 133 (0x5a840b45)
0x5a840b2a 106 8905a40f2501 mov [0x1250fa4],eax
0x5a840b30 112 41 inc ecx
0x5a840b31 113 c741ff4981505b mov [ecx+0xff],0x5b508149 ;; object: 0x5b508149 <Map(elements=3)>
0x5a840b38 120 f20f114903 movsd [ecx+0x3],xmm1
;;; <@21,#18> gap
0x5a840b3d 125 89c8 mov eax,ecx
;;; <@22,#16> return
0x5a840b3f 127 89ec mov esp,ebp
0x5a840b41 129 5d pop ebp
0x5a840b42 130 c20400 ret 0x4
;;; <@20,#18> -------------------- Deferred number-tag-d --------------------
0x5a840b45 133 33c9 xor ecx,ecx
0x5a840b47 135 60 pushad
0x5a840b48 136 8b75fc mov esi,[ebp+0xfc]
0x5a840b4b 139 33c0 xor eax,eax
0x5a840b4d 141 bba0582600 mov ebx,0x2658a0
0x5a840b52 146 e8e995fcff call 0x5a80a140 ;; code: STUB, CEntryStub, minor: 1
0x5a840b57 151 89442418 mov [esp+0x18],eax
0x5a840b5b 155 61 popad
0x5a840b5c 156 ebda jmp 120 (0x5a840b38)
;;; -------------------- Jump table --------------------
;;; jump table entry 0: deoptimization bailout 1.
0x5a840b5e 158 e8a7942cd1 call 0x2bb0a00a ;; deoptimization bailout 1
;;; jump table entry 1: deoptimization bailout 2.
0x5a840b63 163 e8ac942cd1 call 0x2bb0a014 ;; deoptimization bailout 2
0x5a840b68 168 90 nop
0x5a840b69 169 90 nop
0x5a840b6a 170 90 nop
0x5a840b6b 171 90 nop
0x5a840b6c 172 90 nop
0x5a840b6d 173 0f1f00 nop
;;; Safepoint table.
Deoptimization Input Data (deopt points = 3)
index ast id argc pc
0 3 0 45
1 3 0 -1
2 3 0 -1
Safepoints (size = 28)
0x5a840aed 45 0 (sp -> fp) 0
0x5a840b57 151 0 | ecx (sp -> fp) <none>
RelocInfo (size = 137)
0x5a840ac6 embedded object (0x3bd08091 <undefined>)
0x5a840add position (114)
0x5a840add comment (;;; <@0,#0> -------------------- B0 --------------------)
0x5a840add comment (;;; <@2,#1> context)
0x5a840ae0 comment (;;; <@8,#7> -------------------- B1 --------------------)
0x5a840ae0 comment (;;; <@10,#9> stack-check)
0x5a840ae9 code target (BUILTIN) (0x5a829080)
0x5a840aed comment (;;; <@11,#9> gap)
0x5a840af0 comment (;;; <@12,#11> check-non-smi)
0x5a840af0 position (130)
0x5a840af8 comment (;;; <@14,#12> check-maps)
0x5a840afb embedded object (0x5b50ea49 <Map(elements=3)>)
0x5a840b05 comment (;;; <@16,#13> load-named-field)
0x5a840b08 comment (;;; <@18,#14> load-named-field)
0x5a840b0d comment (;;; <@20,#18> number-tag-d)
0x5a840b34 embedded object (0x5b508149 <Map(elements=3)>)
0x5a840b3d comment (;;; <@21,#18> gap)
0x5a840b3f comment (;;; <@22,#16> return)
0x5a840b45 comment (;;; <@20,#18> -------------------- Deferred number-tag-d --------------------)
0x5a840b53 code target (STUB) (0x5a80a140)
0x5a840b5e comment (;;; -------------------- Jump table --------------------)
0x5a840b5e comment (;;; jump table entry 0: deoptimization bailout 1.)
0x5a840b5f runtime entry (deoptimization bailout 1)
0x5a840b63 comment (;;; jump table entry 1: deoptimization bailout 2.)
0x5a840b64 runtime entry (deoptimization bailout 2)
0x5a840b70 comment (;;; Safepoint table.)
--- End code ---
--- FUNCTION SOURCE (Vec2.len) id{4,0} ---
() {
return Math.sqrt(this.len2());
}
--- END ---
--- FUNCTION SOURCE (Vec2.len2) id{4,1} ---
() {
return this.x * this.x + this.y * this.y;
},
--- END ---
INLINE (Vec2.len2) id{4,1} AS 1 AT <0:31>
--- FUNCTION SOURCE (x) id{4,2} ---
() { return this._x; },
--- END ---
INLINE (x) id{4,2} AS 2 AT <1:20>
INLINE (x) id{4,2} AS 3 AT <1:29>
--- FUNCTION SOURCE (y) id{4,3} ---
() { return this._y; },
--- END ---
INLINE (y) id{4,3} AS 4 AT <1:38>
INLINE (y) id{4,3} AS 5 AT <1:47>
--- Raw source ---
() {
return Math.sqrt(this.len2());
}
--- Optimized code ---
optimization_id = 4
source_position = 229
kind = OPTIMIZED_FUNCTION
name = Vec2.len
stack_slots = 1
Instructions (size = 232)
0x5a840e80 0 8b4c2404 mov ecx,[esp+0x4]
0x5a840e84 4 81f99180d03b cmp ecx,0x3bd08091 ;; object: 0x3bd08091 <undefined>
0x5a840e8a 10 750a jnz 22 (0x5a840e96)
0x5a840e8c 12 8b4e13 mov ecx,[esi+0x13]
0x5a840e8f 15 8b4917 mov ecx,[ecx+0x17]
0x5a840e92 18 894c2404 mov [esp+0x4],ecx
0x5a840e96 22 55 push ebp
0x5a840e97 23 89e5 mov ebp,esp
0x5a840e99 25 56 push esi
0x5a840e9a 26 57 push edi
0x5a840e9b 27 6a00 push 0x0
;;; <@0,#0> -------------------- B0 --------------------
;;; <@2,#1> context
0x5a840e9d 29 8b75fc mov esi,[ebp+0xfc] ;; debug: position 229
;;; <@8,#7> -------------------- B1 --------------------
;;; <@10,#9> stack-check
0x5a840ea0 32 3b2588282501 cmp esp,[0x1252888]
0x5a840ea6 38 7305 jnc 45 (0x5a840ead)
0x5a840ea8 40 e8d381feff call StackCheck (0x5a829080) ;; code: BUILTIN
;;; <@11,#9> gap
0x5a840ead 45 8b4508 mov eax,[ebp+0x8]
;;; <@12,#12> check-non-smi
0x5a840eb0 48 a801 test al,0x1 ;; debug: position 260
0x5a840eb2 50 0f8484000000 jz 188 (0x5a840f3c)
;;; <@14,#13> check-maps
0x5a840eb8 56 8178ff49ea505b cmp [eax+0xff],0x5b50ea49 ;; object: 0x5b50ea49 <Map(elements=3)>
0x5a840ebf 63 0f857c000000 jnz 193 (0x5a840f41)
;;; <@16,#26> load-named-field
0x5a840ec5 69 8b480b mov ecx,[eax+0xb] ;; debug: position 98
;;; <@18,#27> load-named-field
0x5a840ec8 72 f20f104903 movsd xmm1,[ecx+0x3]
;;; <@22,#31> -------------------- B2 (unreachable/replaced) --------------------
;;; <@26,#45> -------------------- B3 --------------------
;;; <@27,#45> gap
0x5a840ecd 77 0f28d1 movaps xmm2,xmm1 ;; debug: position 179
;;; <@28,#46> mul-d
0x5a840ed0 80 f20f59d1 mulsd xmm2,xmm1
;;; <@30,#56> load-named-field
0x5a840ed4 84 8b400f mov eax,[eax+0xf] ;; debug: position 17
;;; <@32,#57> load-named-field
0x5a840ed7 87 f20f104803 movsd xmm1,[eax+0x3]
;;; <@36,#61> -------------------- B4 (unreachable/replaced) --------------------
;;; <@40,#75> -------------------- B5 --------------------
;;; <@41,#75> gap
0x5a840edc 92 0f28d9 movaps xmm3,xmm1 ;; debug: position 197
;;; <@42,#76> mul-d
0x5a840edf 95 f20f59d9 mulsd xmm3,xmm1
;;; <@44,#78> add-d
0x5a840ee3 99 f20f58d3 addsd xmm2,xmm3 ;; debug: position 188
;;; <@48,#83> -------------------- B6 --------------------
;;; <@50,#84> check-maps
;;; <@52,#85> math-sqrt
0x5a840ee7 103 f20f51d2 sqrtsd xmm2,xmm2 ;; debug: position 250
;;; <@54,#89> number-tag-d
0x5a840eeb 107 8b0da40f2501 mov ecx,[0x1250fa4]
0x5a840ef1 113 89c8 mov eax,ecx
0x5a840ef3 115 83c00c add eax,0xc
0x5a840ef6 118 0f8227000000 jc 163 (0x5a840f23)
0x5a840efc 124 3b05a80f2501 cmp eax,[0x1250fa8]
0x5a840f02 130 0f871b000000 ja 163 (0x5a840f23)
0x5a840f08 136 8905a40f2501 mov [0x1250fa4],eax
0x5a840f0e 142 41 inc ecx
0x5a840f0f 143 c741ff4981505b mov [ecx+0xff],0x5b508149 ;; object: 0x5b508149 <Map(elements=3)>
0x5a840f16 150 f20f115103 movsd [ecx+0x3],xmm2
;;; <@55,#89> gap
0x5a840f1b 155 89c8 mov eax,ecx
;;; <@56,#87> return
0x5a840f1d 157 89ec mov esp,ebp
0x5a840f1f 159 5d pop ebp
0x5a840f20 160 c20400 ret 0x4
;;; <@54,#89> -------------------- Deferred number-tag-d --------------------
0x5a840f23 163 33c9 xor ecx,ecx
0x5a840f25 165 60 pushad
0x5a840f26 166 8b75fc mov esi,[ebp+0xfc]
0x5a840f29 169 33c0 xor eax,eax
0x5a840f2b 171 bba0582600 mov ebx,0x2658a0
0x5a840f30 176 e80b92fcff call 0x5a80a140 ;; code: STUB, CEntryStub, minor: 1
0x5a840f35 181 89442418 mov [esp+0x18],eax
0x5a840f39 185 61 popad
0x5a840f3a 186 ebda jmp 150 (0x5a840f16)
;;; -------------------- Jump table --------------------
;;; jump table entry 0: deoptimization bailout 1.
0x5a840f3c 188 e8c9902cd1 call 0x2bb0a00a ;; deoptimization bailout 1
;;; jump table entry 1: deoptimization bailout 2.
0x5a840f41 193 e8ce902cd1 call 0x2bb0a014 ;; deoptimization bailout 2
0x5a840f46 198 90 nop
0x5a840f47 199 90 nop
0x5a840f48 200 90 nop
0x5a840f49 201 90 nop
0x5a840f4a 202 90 nop
0x5a840f4b 203 90 nop
;;; Safepoint table.
Deoptimization Input Data (deopt points = 3)
index ast id argc pc
0 3 0 45
1 3 0 -1
2 3 0 -1
Safepoints (size = 28)
0x5a840ead 45 0 (sp -> fp) 0
0x5a840f35 181 0 | ecx (sp -> fp) <none>
RelocInfo (size = 272)
0x5a840e86 embedded object (0x3bd08091 <undefined>)
0x5a840e9d position (229)
0x5a840e9d comment (;;; <@0,#0> -------------------- B0 --------------------)
0x5a840e9d comment (;;; <@2,#1> context)
0x5a840ea0 comment (;;; <@8,#7> -------------------- B1 --------------------)
0x5a840ea0 comment (;;; <@10,#9> stack-check)
0x5a840ea9 code target (BUILTIN) (0x5a829080)
0x5a840ead comment (;;; <@11,#9> gap)
0x5a840eb0 comment (;;; <@12,#12> check-non-smi)
0x5a840eb0 position (260)
0x5a840eb8 comment (;;; <@14,#13> check-maps)
0x5a840ebb embedded object (0x5b50ea49 <Map(elements=3)>)
0x5a840ec5 comment (;;; <@16,#26> load-named-field)
0x5a840ec5 position (98)
0x5a840ec8 comment (;;; <@18,#27> load-named-field)
0x5a840ecd comment (;;; <@22,#31> -------------------- B2 (unreachable/replaced) --------------------)
0x5a840ecd position (179)
0x5a840ecd comment (;;; <@26,#45> -------------------- B3 --------------------)
0x5a840ecd comment (;;; <@27,#45> gap)
0x5a840ed0 comment (;;; <@28,#46> mul-d)
0x5a840ed4 comment (;;; <@30,#56> load-named-field)
0x5a840ed4 position (17)
0x5a840ed7 comment (;;; <@32,#57> load-named-field)
0x5a840edc comment (;;; <@36,#61> -------------------- B4 (unreachable/replaced) --------------------)
0x5a840edc position (197)
0x5a840edc comment (;;; <@40,#75> -------------------- B5 --------------------)
0x5a840edc comment (;;; <@41,#75> gap)
0x5a840edf comment (;;; <@42,#76> mul-d)
0x5a840ee3 comment (;;; <@44,#78> add-d)
0x5a840ee3 position (188)
0x5a840ee7 position (250)
0x5a840ee7 comment (;;; <@48,#83> -------------------- B6 --------------------)
0x5a840ee7 comment (;;; <@50,#84> check-maps)
0x5a840ee7 comment (;;; <@52,#85> math-sqrt)
0x5a840eeb comment (;;; <@54,#89> number-tag-d)
0x5a840f12 embedded object (0x5b508149 <Map(elements=3)>)
0x5a840f1b comment (;;; <@55,#89> gap)
0x5a840f1d comment (;;; <@56,#87> return)
0x5a840f23 comment (;;; <@54,#89> -------------------- Deferred number-tag-d --------------------)
0x5a840f31 code target (STUB) (0x5a80a140)
0x5a840f3c comment (;;; -------------------- Jump table --------------------)
0x5a840f3c comment (;;; jump table entry 0: deoptimization bailout 1.)
0x5a840f3d runtime entry (deoptimization bailout 1)
0x5a840f41 comment (;;; jump table entry 1: deoptimization bailout 2.)
0x5a840f42 runtime entry (deoptimization bailout 2)
0x5a840f4c comment (;;; Safepoint table.)
--- End code ---
--- FUNCTION SOURCE (loop) id{5,0} ---
(v) {
var sum = 0;
for (var i = 0; i < 1e5; i++) {
sum += v.len();
if (sum < 0) {
// Some random code that will never get executed.
for (var j = 0; j < 100; j++) {
sum -= v.len();
}
}
}
util.logger.log("loopish complete");
return sum;
}
--- END ---
--- FUNCTION SOURCE (Vec2.len) id{5,1} ---
() {
return Math.sqrt(this.len2());
}
--- END ---
INLINE (Vec2.len) id{5,1} AS 1 AT <0:68>
--- FUNCTION SOURCE (Vec2.len2) id{5,2} ---
() {
return this.x * this.x + this.y * this.y;
},
--- END ---
INLINE (Vec2.len2) id{5,2} AS 2 AT <1:31>
--- FUNCTION SOURCE (x) id{5,3} ---
() { return this._x; },
--- END ---
INLINE (x) id{5,3} AS 3 AT <2:20>
INLINE (x) id{5,3} AS 4 AT <2:29>
--- FUNCTION SOURCE (y) id{5,4} ---
() { return this._y; },
--- END ---
INLINE (y) id{5,4} AS 5 AT <2:38>
INLINE (y) id{5,4} AS 6 AT <2:47>
--- Raw source ---
(v) {
var sum = 0;
for (var i = 0; i < 1e5; i++) {
sum += v.len();
if (sum < 0) {
// Some random code that will never get executed.
for (var j = 0; j < 100; j++) {
sum -= v.len();
}
}
}
util.logger.log("loopish complete");
return sum;
}
--- Optimized code ---
optimization_id = 5
source_position = 379
kind = OPTIMIZED_FUNCTION
name = loop
stack_slots = 5
Instructions (size = 412)
0x5a841280 0 33d2 xor edx,edx
0x5a841282 2 f7c404000000 test esp,0x4
0x5a841288 8 751f jnz 41 (0x5a8412a9)
0x5a84128a 10 6a00 push 0x0
0x5a84128c 12 89e3 mov ebx,esp
0x5a84128e 14 ba02000000 mov edx,0x2
0x5a841293 19 b903000000 mov ecx,0x3
0x5a841298 24 8b4304 mov eax,[ebx+0x4]
0x5a84129b 27 8903 mov [ebx],eax
0x5a84129d 29 83c304 add ebx,0x4
0x5a8412a0 32 49 dec ecx
0x5a8412a1 33 75f5 jnz 24 (0x5a841298)
0x5a8412a3 35 c70378563412 mov [ebx],0x12345678
0x5a8412a9 41 55 push ebp
0x5a8412aa 42 89e5 mov ebp,esp
0x5a8412ac 44 56 push esi
0x5a8412ad 45 57 push edi
0x5a8412ae 46 83ec14 sub esp,0x14
;;; Store dynamic frame alignment tag for spilled doubles
0x5a8412b1 49 8955f4 mov [ebp+0xf4],edx
;;; <@0,#0> -------------------- B0 --------------------
;;; <@2,#1> context
0x5a8412b4 52 8b45fc mov eax,[ebp+0xfc] ;; debug: position 379
;;; <@3,#1> gap
0x5a8412b7 55 8945e4 mov [ebp+0xe4],eax
;;; <@10,#8> -------------------- B1 --------------------
;;; <@11,#8> gap
0x5a8412ba 58 89c6 mov esi,eax
;;; <@12,#10> stack-check
0x5a8412bc 60 3b2588282501 cmp esp,[0x1252888]
0x5a8412c2 66 7305 jnc 73 (0x5a8412c9)
0x5a8412c4 68 e8b77dfeff call StackCheck (0x5a829080) ;; code: BUILTIN
;;; <@15,#16> goto
0x5a8412c9 73 e97a000000 jmp 200 (0x5a841348) ;; debug: position 415
;;; <@16,#20> -------------------- B2 (OSR entry) --------------------
0x5a8412ce 78 33d2 xor edx,edx
0x5a8412d0 80 f7c504000000 test ebp,0x4
0x5a8412d6 86 7422 jz 122 (0x5a8412fa)
0x5a8412d8 88 6a00 push 0x0
0x5a8412da 90 89e3 mov ebx,esp
0x5a8412dc 92 ba02000000 mov edx,0x2
0x5a8412e1 97 b909000000 mov ecx,0x9
0x5a8412e6 102 8b4304 mov eax,[ebx+0x4]
0x5a8412e9 105 8903 mov [ebx],eax
0x5a8412eb 107 83c304 add ebx,0x4
0x5a8412ee 110 49 dec ecx
0x5a8412ef 111 75f5 jnz 102 (0x5a8412e6)
0x5a8412f1 113 c70378563412 mov [ebx],0x12345678
0x5a8412f7 119 83ed04 sub ebp,0x4
0x5a8412fa 122 ff75f4 push [ebp+0xf4]
0x5a8412fd 125 8955f4 mov [ebp+0xf4],edx
0x5a841300 128 83ec04 sub esp,0x4
;;; <@32,#29> context
0x5a841303 131 8b45fc mov eax,[ebp+0xfc]
;;; <@33,#29> gap
0x5a841306 134 8b4de8 mov ecx,[ebp+0xe8]
;;; <@34,#242> double-untag
0x5a841309 137 f6c101 test_b cl,0x1
0x5a84130c 140 7414 jz 162 (0x5a841322)
0x5a84130e 142 8179ff4981505b cmp [ecx+0xff],0x5b508149 ;; object: 0x5b508149 <Map(elements=3)>
0x5a841315 149 0f85c9000000 jnz 356 (0x5a8413e4)
0x5a84131b 155 f20f104903 movsd xmm1,[ecx+0x3]
0x5a841320 160 eb0b jmp 173 (0x5a84132d)
0x5a841322 162 89ca mov edx,ecx
0x5a841324 164 d1fa sar edx,1
0x5a841326 166 0f57c9 xorps xmm1,xmm1
0x5a841329 169 f20f2aca cvtsi2sd xmm1,edx
;;; <@35,#242> gap
0x5a84132d 173 8b55f0 mov edx,[ebp+0xf0]
;;; <@36,#243> check-smi
0x5a841330 176 f6c201 test_b dl,0x1
0x5a841333 179 0f85b0000000 jnz 361 (0x5a8413e9)
;;; <@38,#31> gap
0x5a841339 185 8b5d0c mov ebx,[ebp+0xc]
0x5a84133c 188 89c1 mov ecx,eax
0x5a84133e 190 89d0 mov eax,edx
0x5a841340 192 8b5508 mov edx,[ebp+0x8]
;;; <@39,#31> goto
0x5a841343 195 e90e000000 jmp 214 (0x5a841356)
;;; <@40,#17> -------------------- B3 --------------------
;;; <@42,#241> constant-d
0x5a841348 200 0f57c9 xorps xmm1,xmm1
;;; <@44,#19> gap
0x5a84134b 203 8b5d0c mov ebx,[ebp+0xc]
0x5a84134e 206 8b5508 mov edx,[ebp+0x8]
0x5a841351 209 8b4de4 mov ecx,[ebp+0xe4]
0x5a841354 212 33c0 xor eax,eax
;;; <@46,#44> -------------------- B4 --------------------
;;; <@48,#62> check-non-smi
0x5a841356 214 f6c201 test_b dl,0x1 ;; debug: position 447
0x5a841359 217 0f848f000000 jz 366 (0x5a8413ee)
;;; <@50,#63> check-maps
0x5a84135f 223 817aff49ea505b cmp [edx+0xff],0x5b50ea49 ;; object: 0x5b50ea49 <Map(elements=3)>
0x5a841366 230 0f8587000000 jnz 371 (0x5a8413f3)
;;; <@52,#83> load-named-field
0x5a84136c 236 8b720b mov esi,[edx+0xb] ;; debug: position 98
;;; <@54,#84> load-named-field
0x5a84136f 239 f20f105603 movsd xmm2,[esi+0x3]
;;; <@55,#84> gap
0x5a841374 244 0f28da movaps xmm3,xmm2
;;; <@56,#103> mul-d
0x5a841377 247 f20f59da mulsd xmm3,xmm2 ;; debug: position 179
;;; <@58,#113> load-named-field
0x5a84137b 251 8b720f mov esi,[edx+0xf] ;; debug: position 36035888
;;; <@60,#114> load-named-field
0x5a84137e 254 f20f105603 movsd xmm2,[esi+0x3]
;;; <@61,#114> gap
0x5a841383 259 0f28e2 movaps xmm4,xmm2
;;; <@62,#133> mul-d
0x5a841386 262 f20f59e2 mulsd xmm4,xmm2 ;; debug: position 197
;;; <@64,#135> add-d
0x5a84138a 266 f20f58dc addsd xmm3,xmm4 ;; debug: position 188
;;; <@66,#141> check-maps
;;; <@68,#142> math-sqrt
0x5a84138e 270 f20f51db sqrtsd xmm3,xmm3 ;; debug: position 250
;;; <@70,#245> constant-d
0x5a841392 274 0f57d2 xorps xmm2,xmm2 ;; debug: position 466
;;; <@74,#47> -------------------- B5 (loop header) --------------------
;;; <@77,#51> compare-numeric-and-branch
0x5a841395 277 3d400d0300 cmp eax,0x30d40 ;; debug: position 415
;; debug: position 418
;; debug: position 420
0x5a84139a 282 0f8d2c000000 jnl 332 (0x5a8413cc)
;;; <@78,#52> -------------------- B6 (unreachable/replaced) --------------------
;;; <@82,#58> -------------------- B7 --------------------
;;; <@84,#60> stack-check
0x5a8413a0 288 3b2588282501 cmp esp,[0x1252888]
0x5a8413a6 294 0f8225000000 jc 337 (0x5a8413d1)
;;; <@88,#88> -------------------- B8 (unreachable/replaced) --------------------
;;; <@92,#102> -------------------- B9 (unreachable/replaced) --------------------
;;; <@96,#118> -------------------- B10 (unreachable/replaced) --------------------
;;; <@100,#132> -------------------- B11 (unreachable/replaced) --------------------
;;; <@104,#140> -------------------- B12 (unreachable/replaced) --------------------
;;; <@108,#146> -------------------- B13 --------------------
;;; <@110,#147> add-d
0x5a8413ac 300 f20f58cb addsd xmm1,xmm3 ;; debug: position 98
;; debug: position 443
;;; <@113,#152> compare-numeric-and-branch
0x5a8413b0 304 660f2eca ucomisd xmm1,xmm2 ;; debug: position 466
0x5a8413b4 308 0f8a0d000000 jpe 327 (0x5a8413c7)
0x5a8413ba 314 0f8307000000 jnc 327 (0x5a8413c7)
;;; <@114,#156> -------------------- B14 (unreachable/replaced) --------------------
;;; <@118,#209> -------------------- B15 (unreachable/replaced) --------------------
;;; <@122,#153> -------------------- B16 (unreachable/replaced) --------------------
;;; <@126,#159> -------------------- B17 --------------------
;;; <@128,#169> gap
0x5a8413c0 320 33f6 xor esi,esi ;; debug: position 548
;;; <@130,#170> -------------------- B18 (loop header) --------------------
;;; <@132,#173> deoptimize
;;; deoptimize: Insufficient type feedback for combined type of binary operation
0x5a8413c2 322 e87f8cfc04 call 0x5f80a046 ;; debug: position 551
;; debug: position 553
;; soft deoptimization bailout 7
;;; <@134,#174> -------------------- B19 (unreachable/replaced) --------------------
;;; <@144,#178> -------------------- B20 (unreachable/replaced) --------------------
;;; <@148,#184> -------------------- B21 (unreachable/replaced) --------------------
;;; <@162,#194> -------------------- B22 (unreachable/replaced) --------------------
;;; <@166,#196> -------------------- B23 (unreachable/replaced) --------------------
;;; <@188,#181> -------------------- B24 (unreachable/replaced) --------------------
;;; <@192,#206> -------------------- B25 (unreachable/replaced) --------------------
;;; <@196,#218> -------------------- B26 --------------------
;;; <@198,#220> add-i
0x5a8413c7 327 83c002 add eax,0x2 ;; debug: position 427
;;; <@201,#223> goto
0x5a8413ca 330 ebc9 jmp 277 (0x5a841395)
;;; <@202,#55> -------------------- B27 (unreachable/replaced) --------------------
;;; <@206,#224> -------------------- B28 --------------------
;;; <@208,#226> deoptimize
;;; deoptimize: Insufficient type feedback for generic named load
0x5a8413cc 332 e87f8cfc04 call 0x5f80a050 ;; debug: position 611
;; soft deoptimization bailout 8
;;; <@210,#227> -------------------- B29 (unreachable/replaced) --------------------
;;; <@84,#60> -------------------- Deferred stack-check --------------------
0x5a8413d1 337 60 pushad ;; debug: position 420
0x5a8413d2 338 8b75fc mov esi,[ebp+0xfc]
0x5a8413d5 341 33c0 xor eax,eax
0x5a8413d7 343 bbb0db2600 mov ebx,0x26dbb0
0x5a8413dc 348 e85f8dfcff call 0x5a80a140 ;; code: STUB, CEntryStub, minor: 1
0x5a8413e1 353 61 popad
0x5a8413e2 354 ebc8 jmp 300 (0x5a8413ac)
;;; -------------------- Jump table --------------------
;;; jump table entry 0: deoptimization bailout 2.
0x5a8413e4 356 e82b8c2cd1 call 0x2bb0a014 ;; deoptimization bailout 2
;;; jump table entry 1: deoptimization bailout 3.
0x5a8413e9 361 e8308c2cd1 call 0x2bb0a01e ;; deoptimization bailout 3
;;; jump table entry 2: deoptimization bailout 4.
0x5a8413ee 366 e8358c2cd1 call 0x2bb0a028 ;; deoptimization bailout 4
;;; jump table entry 3: deoptimization bailout 5.
0x5a8413f3 371 e83a8c2cd1 call 0x2bb0a032 ;; deoptimization bailout 5
0x5a8413f8 376 90 nop
0x5a8413f9 377 90 nop
0x5a8413fa 378 90 nop
0x5a8413fb 379 90 nop
0x5a8413fc 380 90 nop
0x5a8413fd 381 0f1f00 nop
;;; Safepoint table.
Deoptimization Input Data (deopt points = 9)
index ast id argc pc
0 3 0 73
1 28 0 -1
2 26 0 -1
3 26 0 -1
4 26 0 -1
5 26 0 -1
6 30 0 300
7 82 0 -1
8 27 0 -1
Safepoints (size = 28)
0x5a8412c9 73 10000 (sp -> fp) 0
0x5a8413e1 353 00000 | ecx | edx | ebx (sp -> fp) 6
RelocInfo (size = 679)
0x5a8412b1 comment (;;; Store dynamic frame alignment tag for spilled doubles)
0x5a8412b4 position (379)
0x5a8412b4 comment (;;; <@0,#0> -------------------- B0 --------------------)
0x5a8412b4 comment (;;; <@2,#1> context)
0x5a8412b7 comment (;;; <@3,#1> gap)
0x5a8412ba comment (;;; <@10,#8> -------------------- B1 --------------------)
0x5a8412ba comment (;;; <@11,#8> gap)
0x5a8412bc comment (;;; <@12,#10> stack-check)
0x5a8412c5 code target (BUILTIN) (0x5a829080)
0x5a8412c9 position (415)
0x5a8412c9 comment (;;; <@15,#16> goto)
0x5a8412ce comment (;;; <@16,#20> -------------------- B2 (OSR entry) --------------------)
0x5a841303 comment (;;; <@32,#29> context)
0x5a841306 comment (;;; <@33,#29> gap)
0x5a841309 comment (;;; <@34,#242> double-untag)
0x5a841311 embedded object (0x5b508149 <Map(elements=3)>)
0x5a84132d comment (;;; <@35,#242> gap)
0x5a841330 comment (;;; <@36,#243> check-smi)
0x5a841339 comment (;;; <@38,#31> gap)
0x5a841343 comment (;;; <@39,#31> goto)
0x5a841348 comment (;;; <@40,#17> -------------------- B3 --------------------)
0x5a841348 comment (;;; <@42,#241> constant-d)
0x5a84134b comment (;;; <@44,#19> gap)
0x5a841356 comment (;;; <@46,#44> -------------------- B4 --------------------)
0x5a841356 comment (;;; <@48,#62> check-non-smi)
0x5a841356 position (447)
0x5a84135f comment (;;; <@50,#63> check-maps)
0x5a841362 embedded object (0x5b50ea49 <Map(elements=3)>)
0x5a84136c comment (;;; <@52,#83> load-named-field)
0x5a84136c position (98)
0x5a84136f comment (;;; <@54,#84> load-named-field)
0x5a841374 comment (;;; <@55,#84> gap)
0x5a841377 comment (;;; <@56,#103> mul-d)
0x5a841377 position (179)
0x5a84137b comment (;;; <@58,#113> load-named-field)
0x5a84137b position (36035888)
0x5a84137e comment (;;; <@60,#114> load-named-field)
0x5a841383 comment (;;; <@61,#114> gap)
0x5a841386 comment (;;; <@62,#133> mul-d)
0x5a841386 position (197)
0x5a84138a comment (;;; <@64,#135> add-d)
0x5a84138a position (188)
0x5a84138e comment (;;; <@66,#141> check-maps)
0x5a84138e position (250)
0x5a84138e comment (;;; <@68,#142> math-sqrt)
0x5a841392 comment (;;; <@70,#245> constant-d)
0x5a841392 position (466)
0x5a841395 position (415)
0x5a841395 position (418)
0x5a841395 comment (;;; <@74,#47> -------------------- B5 (loop header) --------------------)
0x5a841395 position (420)
0x5a841395 comment (;;; <@77,#51> compare-numeric-and-branch)
0x5a8413a0 comment (;;; <@78,#52> -------------------- B6 (unreachable/replaced) --------------------)
0x5a8413a0 comment (;;; <@82,#58> -------------------- B7 --------------------)
0x5a8413a0 comment (;;; <@84,#60> stack-check)
0x5a8413ac position (98)
0x5a8413ac comment (;;; <@88,#88> -------------------- B8 (unreachable/replaced) --------------------)
0x5a8413ac comment (;;; <@92,#102> -------------------- B9 (unreachable/replaced) --------------------)
0x5a8413ac comment (;;; <@96,#118> -------------------- B10 (unreachable/replaced) --------------------)
0x5a8413ac comment (;;; <@100,#132> -------------------- B11 (unreachable/replaced) --------------------)
0x5a8413ac comment (;;; <@104,#140> -------------------- B12 (unreachable/replaced) --------------------)
0x5a8413ac position (443)
0x5a8413ac comment (;;; <@108,#146> -------------------- B13 --------------------)
0x5a8413ac comment (;;; <@110,#147> add-d)
0x5a8413b0 position (466)
0x5a8413b0 comment (;;; <@113,#152> compare-numeric-and-branch)
0x5a8413c0 comment (;;; <@114,#156> -------------------- B14 (unreachable/replaced) --------------------)
0x5a8413c0 comment (;;; <@118,#209> -------------------- B15 (unreachable/replaced) --------------------)
0x5a8413c0 comment (;;; <@122,#153> -------------------- B16 (unreachable/replaced) --------------------)
0x5a8413c0 position (548)
0x5a8413c0 comment (;;; <@126,#159> -------------------- B17 --------------------)
0x5a8413c0 comment (;;; <@128,#169> gap)
0x5a8413c2 position (551)
0x5a8413c2 comment (;;; <@130,#170> -------------------- B18 (loop header) --------------------)
0x5a8413c2 comment (;;; <@132,#173> deoptimize)
0x5a8413c2 position (553)
0x5a8413c2 comment (;;; deoptimize: Insufficient type feedback for combined type of binary operation)
0x5a8413c3 runtime entry
0x5a8413c7 comment (;;; <@134,#174> -------------------- B19 (unreachable/replaced) --------------------)
0x5a8413c7 comment (;;; <@144,#178> -------------------- B20 (unreachable/replaced) --------------------)
0x5a8413c7 comment (;;; <@148,#184> -------------------- B21 (unreachable/replaced) --------------------)
0x5a8413c7 comment (;;; <@162,#194> -------------------- B22 (unreachable/replaced) --------------------)
0x5a8413c7 comment (;;; <@166,#196> -------------------- B23 (unreachable/replaced) --------------------)
0x5a8413c7 comment (;;; <@188,#181> -------------------- B24 (unreachable/replaced) --------------------)
0x5a8413c7 comment (;;; <@192,#206> -------------------- B25 (unreachable/replaced) --------------------)
0x5a8413c7 position (427)
0x5a8413c7 comment (;;; <@196,#218> -------------------- B26 --------------------)
0x5a8413c7 comment (;;; <@198,#220> add-i)
0x5a8413ca comment (;;; <@201,#223> goto)
0x5a8413cc comment (;;; <@202,#55> -------------------- B27 (unreachable/replaced) --------------------)
0x5a8413cc position (611)
0x5a8413cc comment (;;; <@206,#224> -------------------- B28 --------------------)
0x5a8413cc comment (;;; <@208,#226> deoptimize)
0x5a8413cc comment (;;; deoptimize: Insufficient type feedback for generic named load)
0x5a8413cd runtime entry
0x5a8413d1 comment (;;; <@210,#227> -------------------- B29 (unreachable/replaced) --------------------)
0x5a8413d1 position (420)
0x5a8413d1 comment (;;; <@84,#60> -------------------- Deferred stack-check --------------------)
0x5a8413dd code target (STUB) (0x5a80a140)
0x5a8413e4 comment (;;; -------------------- Jump table --------------------)
0x5a8413e4 comment (;;; jump table entry 0: deoptimization bailout 2.)
0x5a8413e5 runtime entry (deoptimization bailout 2)
0x5a8413e9 comment (;;; jump table entry 1: deoptimization bailout 3.)
0x5a8413ea runtime entry (deoptimization bailout 3)
0x5a8413ee comment (;;; jump table entry 2: deoptimization bailout 4.)
0x5a8413ef runtime entry (deoptimization bailout 4)
0x5a8413f3 comment (;;; jump table entry 3: deoptimization bailout 5.)
0x5a8413f4 runtime entry (deoptimization bailout 5)
0x5a841400 comment (;;; Safepoint table.)
--- End code ---
[deoptimizing (DEOPT soft): begin 0x4f818ccd loop (opt #5) @8, FP to SP delta: 28]
;;; deoptimize: Insufficient type feedback for generic named load
translating loop => node=27, height=12
0xbffff3a0: [top + 32] <- 0x4f81742d ; ebx 0x4f81742d <JS Global Object>
0xbffff39c: [top + 28] <- 0x55015305 ; edx 0x55015305 <a Vec2 with map 0x5b50ea49>
0xbffff398: [top + 24] <- 0x5a83f7c7 ; caller's pc
0xbffff394: [top + 20] <- 0xbffff3b0 ; caller's fp
0xbffff390: [top + 16] <- 0x4f808081; context
0xbffff38c: [top + 12] <- 0x4f818ccd; function
0xbffff388: [top + 8] <- 2.236068e+04 ; xmm1
0xbffff384: [top + 4] <- 0x3bd08091 <undefined> ; literal
0xbffff380: [top + 0] <- 0x3bd08091 <undefined> ; literal
[deoptimizing (soft): end 0x4f818ccd loop @8 => node=27, pc=0x5a83faf3, state=NO_REGISTERS, alignment=with padding, took 0.042 ms]
Materialized a new heap number 0x55047481 [2.236068e+04] in slot 0xbffff388
|
TITLE UNMANGLE -
INCLUDE MACROS
INCLUDE IO_STRUC
PUBLIC UNMANGLE
.DATA
EXTERNDEF TEMP_RECORD:BYTE,FNTBL:BYTE
EXTERNDEF UNMANGLE_STUFF:ALLOCS_STRUCT
.CODE MIDDLE_TEXT
EXTERNDEF UNMANGLE_POOL_GET:PROC,CBTA32:PROC,_release_minidata:proc
UM_STRUCT STRUC
ZNAMEI DD ?
ZNAMES DD 10 DUP(?)
ARGI DD ?
ARGS DD 10 DUP(?)
UM_STRUCT ENDS
UNMANGLE PROC
;
;
;
; JMP L9$
CMP BPTR [EAX],'?'
JNZ L9$
PUSHM EDI,ESI,EBX,EAX
PUSH EAX
MOV EAX,OFF UNMANGLE_STUFF ;RELEASE MEMORY USED LAST TIME...
push EAX
call _release_minidata
add ESP,4
POP EBX
CALL UM_NESTNAME
TEST EAX,EAX
JZ L69$
;
;APPEND THIS TO ORIGINAL STRING.
;
MOV ECX,")("
CALL STR_BRACKET
POP ECX
MOV EDX,[EAX]
PUSH EAX
MOV ESI,ECX
LEA EAX,[EBX+8+EDX]
SUB EAX,ECX
CALL UNMANGLE_POOL_GET
MOV ECX,EBX
MOV EDI,EAX
SUB ECX,ESI
MOV EDX,EAX
REP MOVSB
POP ECX
MOV BPTR [EDI],' '
INC EDI
PUSH EDX
LEA ESI,[ECX+4]
MOV ECX,[ECX]
REP MOVSB
MOV DPTR [EDI],0
L69$:
POPM EAX,EBX,ESI,EDI
L9$:
RET
UNMANGLE ENDP
UM_NESTNAME PROC
PUSHM EDI,ESI
XOR ECX,ECX
MOV EDI,-1 ;OPIDX
MOV UM.ZNAMEI,ECX
MOV UM.ARGI,ECX
MOV AL,[EBX]
INC EBX
CMP AL,'?'
JZ L1$
DEC EBX
CALL UM_ZNAME
POPM ESI,EDI
RET
L1$:
MOV AL,[EBX]
INC EBX
CMP AL,'?'
JNZ L2$
;
;?? IS OPERATOR
;
XOR EAX,EAX
MOV AL,[EBX]
INC EBX
SUB AL,30H
XOR EDI,EDI
CMP AL,10 ;0-9
JB L15$
CMP AL,'_'-30H ;_
JNZ L10$
ADD EDI,10+26
MOV AL,[EBX]
INC EBX
SUB AL,30H
CMP AL,10
JB L15$
L10$:
CMP AL,'A'-'0'
JB L8$
SUB AL,'A'-'9'-1
CMP AL,10+26
JA L8$
L15$:
ADD EDI,EAX
MOV EAX,UM_TABLE[EDI*4]
CALL STR_DUP
JMP L3$
L2$:
;
;
;
DEC EBX
CALL UM_ZNAME
L3$:
TEST EAX,EAX
JZ RETT
MOV ESI,EAX
;
;HANDLE SCOPING
;
L4$:
CMP BPTR [EBX],'@'
JZ L6$
CALL UM_ZNAME
TEST EAX,EAX
JZ RETT
TEST EDI,EDI
JNZ L42$
PUSH EAX
CALL STR_DUP
MOV ESI,EAX
POP EAX
DEC EDI
JMP L46$
L42$:
CMP EDI,1
JNZ L46$
MOV ECX,EAX
MOV EAX,OFF SQUIGGLE_M
PUSH ECX
CALL STR_CAT
MOV ESI,EAX
POP EAX
MOV EDI,-1
L46$:
PUSH EAX
MOV EAX,OFF COLONCOLON_M
MOV ECX,ESI
CALL STR_CAT
MOV ECX,EAX
POP EAX
CALL STR_CAT
MOV ESI,EAX
JMP L4$
L6$:
INC EBX
MOV EAX,ESI
CALL UM_TYPE_ENCODING
CMP EDI,11
JNZ L61$
MOV ECX,EAX
MOV EAX,OFF OPERATOR_M
CALL STR_CAT
L61$:
POPM ESI,EDI
RET
RETT:
L8$:
XOR EAX,EAX
JMP L61$
UM_NESTNAME ENDP
UM_ZNAME PROC
;
;RETURN POINTER TO STRING
;
TEST EBX,EBX
JZ L9$
XOR EAX,EAX
MOV ECX,UM.ZNAMEI
MOV AL,[EBX]
INC EBX
SUB AL,30H
CMP AL,10
JNC L2$
CMP CL,AL ;IS THIS A VALID INDEX INTO UM?
JBE L8$
MOV EAX,UM.ZNAMES[EAX*4]
JMP STR_DUP
L8$:
DEC EBX
L9$:
XOR EAX,EAX
RET
L81$:
MOV EBX,ECX
XOR EAX,EAX
RET
L2$:
CMP AL,'$' - 30H
JZ L21$
CMP AL,'?' - 30H
JNZ L3$
MOV AL,[EBX]
CMP AL,'$'
JNZ L3$
L21$:
;
;SET UP TO CALL UNMANGLE_PT
;
PUSHM EBP,EDI,ESI
MOV EBP,ESP
SUB ESP,SIZEOF UM_STRUCT
MOV ESI,OFF UM
MOV ECX,SIZEOF UM_STRUCT/4
MOV EDI,ESP
REP MOVSD
DEC EBX
CALL UNMANGLE_PT
MOV ESI,ESP
MOV EDI,OFF UM
MOV ECX,SIZEOF UM_STRUCT/4
REP MOVSD
MOV ESP,EBP
; DEC EBX
TEST EAX,EAX
POPM ESI,EDI,EBP
JNZ L5$
L3$:
;
;DEFINE A NEW ZNAME
;
LEA ECX,[EBX-1] ;START OF STRING
DEC EBX
L31$:
MOV AL,[EBX]
INC EBX
CMP AL,0
JZ L81$
CMP AL,'@'
JNZ L31$
DEC EBX
PUSH EDI
MOV EAX,EBX
PUSH ESI
MOV ESI,ECX
SUB EAX,ECX
PUSH EAX
ADD EAX,4
CALL UNMANGLE_POOL_GET
POP ECX
LEA EDI,[EAX+4]
MOV [EAX],ECX
ADD ECX,3
SHR ECX,2
REP MOVSD
POPM ESI,EDI
L5$:
MOV ECX,UM.ZNAMEI
INC EBX
CMP ECX,10
JAE L6$
MOV UM.ZNAMES[ECX*4],EAX
INC ECX
MOV UM.ZNAMEI,ECX
JMP STR_DUP
L6$:
RET
UM_ZNAME ENDP
PT_STRUCT STRUC
T_BP DD ?
BUF_BP DD 10 DUP(?)
FIRST_BP DB ?
NEW_MANGLE_BP DB ?
DB ?
DB ?
PT_STRUCT ENDS
FIX MACRO XX
XX EQU <[EBP - SIZEOF PT_STRUCT].(XX&_BP)>
ENDM
FIX T
FIX BUF
FIX FIRST
FIX NEW_MANGLE
UNMANGLE_PT PROC
;
;
;
PUSHM EBP,EDI
PUSH ESI
MOV EBP,ESP
ASSUME EBP:PTR PT_STRUCT
MOV ESI,EBX
XOR EAX,EAX
SUB ESP,SIZEOF PT_STRUCT
MOV NEW_MANGLE,AL
MOV AL,[EBX]
INC EBX
CMP AL,'?'
JNZ L05$
MOV NEW_MANGLE,1
MOV AL,[EBX]
INC EBX
L05$:
CMP AL,'$'
JZ L09$
L06$:
MOV ESP,EBP
XOR EAX,EAX
MOV EBX,ESI
POP ESI
POPM EDI,EBP
RET
L09$:
XOR EAX,EAX
MOV UM.ZNAMEI,EAX
MOV UM.ARGI,EAX
CALL UM_ZNAME
; TEST EAX,EAX
; JZ L9$
MOV CL,'<' ;ADD A < TO END
CALL STR_CATC
MOV T,EAX
MOV FIRST,1
L0$:
MOV AL,[EBX]
INC EBX
MOV CL,NEW_MANGLE
TEST CL,CL
JZ OLD_MANGLE
CMP AL,'$'
JZ OLD_MANGLE1
CMP AL,'@'
JZ SPEC
CMP AL,0
JNZ DO_ARG
SPEC:
DEC EBX
JMP DONE
DO_ARG:
DEC EBX
CALL UM_ARGUMENT
TEST EAX,EAX
JZ DONE
JMP L8$
OLD_MANGLE1:
MOV AL,[EBX]
INC EBX
OLD_MANGLE:
;
;@, D, F, I, L, R, S, T
;
CMP AL,'L'
JB BELOW_L
CMP AL,'S'
JB BELOW_S
JZ EQUAL_S
CMP AL,'T'
JZ EQUAL_T
JMP DONE
BELOW_S:
CMP AL,'L'
JZ EQUAL_L
CMP AL,'R'
JZ EQUAL_R
JMP DONE
BELOW_L:
CMP AL,'F'
JB BELOW_F
JZ EQUAL_F
CMP AL,'I'
JZ EQUAL_I
JMP DONE
BELOW_F:
CMP AL,'D'
JZ EQUAL_D
CMP AL,'0'
JZ EQUAL_I
CMP AL,'1'
JZ EQUAL_1
CMP AL,'@'
JNZ DONE
DEC EBX
JMP DONE
EQUAL_I:
LEA EDI,BUF+4
CALL UM_DIMENSION
MOV ECX,EDI
CALL CBTA32
SUB EAX,EDI ;LENGTH OF STRING
MOV BUF,EAX
LEA EAX,BUF
JMP L8$
EQUAL_@:
DEC EBX
JMP DONE
EQUAL_F:
MOV ECX,4
JMP L1
EQUAL_1:
MOV EAX,OFF UM_BAND
CALL STR_DUP
PUSH EAX
CALL UM_NESTNAME
MOV ECX,EAX
POP EAX
CALL STR_CAT
JMP L8$
EQUAL_D:
EQUAL_L:
MOV ECX,8
L1:
;
;WE WANT ECX HEX DIGITS, TO STORE INTO BUF
;
LEA EDX,BUF+4
MOV BUF,ECX
L12$:
MOV EAX,[EBX] ;I DON'T CONVERT FLOATS YET...
ADD EBX,4
MOV [EDX],EAX
ADD EDX,4
SUB ECX,4
JNZ L12$
LEA EAX,BUF
JMP L8$
EQUAL_R:
CALL UM_ZNAME
TEST EAX,EAX
JNZ L8$
JMP L91$
EQUAL_S:
CALL UM_STRING
MOV ECX,'""'
CALL STR_BRACKET
JMP L8$
EQUAL_T:
CALL UM_ARGUMENT
L8$:
;
;EAX IS A STRING
;
CMP FIRST,0
JNZ L81$
PUSH EAX
MOV EAX,T
MOV CL,','
CALL STR_CATC
MOV T,EAX
POP EAX
L81$:
MOV ECX,EAX
MOV EAX,T
CALL STR_CAT
MOV FIRST,0
MOV T,EAX
JMP L0$
DONE:
MOV EAX,T
MOV CL,'>'
CALL STR_CATC
L91$:
MOV ESP,EBP
L9$:
POPM ESI,EDI,EBP
RET
UNMANGLE_PT ENDP
UM_DIMENSION PROC
;
;
;
XOR ECX,ECX
XOR EAX,EAX
MOV AL,[EBX]
INC EBX
CMP AL,'0'
JB L5$
CMP AL,'9'
JA L5$
SUB AL,'0'-1
RET
L1$:
SHL ECX,4
SUB AL,'A'
CMP AL,16
JAE L8$
OR CL,AL
MOV AL,[EBX]
INC EBX
L5$:
CMP AL,'@'
JNZ L1$
L8$:
MOV EAX,ECX
RET
UM_DIMENSION ENDP
UM_STRING PROC
;
;
;
PUSHM EDI,ESI
SUB ESP,512 ;ROOM FOR A BIG STRING
MOV EDX,ESP
MOV ESI,ESP
L1$:
MOV AL,[EBX]
INC EBX
;
;CASES ARE: NUL, @, ?, ALPHANUMERIC
;
AND EAX,0FFH
JZ L8$
CMP AL,'@'
JZ L7$
CMP AL,'?'
JZ L5$
MOV CL,FNTBL[EAX]
AND CL,MASK IS_ALPHA + MASK IS_NUMERIC
JZ L8$
L4$:
MOV [EDX],AL
INC EDX
JMP L1$
L5$:
;
;AFTER ?
;
MOV AL,[EBX]
INC EBX
CMP AL,'$'
JZ L55$
MOV CL,FNTBL[EAX]
AND CL,MASK IS_NUMERIC + MASK IS_ALPHA
JZ L8$
AND CL,MASK IS_NUMERIC
JZ L57$
;
;IS_ALPHA
;
ADD AL,80H
JMP L4$
L57$:
;
;IS_DIGIT
;
MOV AL,SPECIAL_CHAR[EAX-30H]
JMP L4$
L55$:
;
;AFTER ?$
;
MOV AL,[EBX]
INC EBX
SUB AL,'A'
CMP AL,16
JAE L8$
SHL AL,4
MOV CL,[EBX]
SUB CL,'A'
INC EBX
CMP CL,16
JAE L8$
OR AL,CL
JMP L4$
L7$:
;
;WE ARE KEEPING THIS STRING, ALLOCATE SPACE AND COPY...
;
MOV EAX,EDX
SUB EAX,ESI
MOV ECX,EAX ;LENGTH OF STRING
ADD EAX,4 ;BYTES TO ALLOCATE
PUSH ECX
CALL UNMANGLE_POOL_GET
POP ECX
LEA EDI,[EAX+4]
MOV [EAX],ECX
ADD ECX,3
SHR ECX,2
REP MOVSD
L9$:
ADD ESP,512
POPM ESI,EDI
RET
L8$:
XOR EAX,EAX
JMP L9$
UM_STRING ENDP
UM_ARGUMENT PROC
;
;
;
XOR EAX,EAX
MOV EDX,EBX
MOV AL,[EBX] ;IF NUMERIC, JUST RETURN AN ALREADY-DEFINED
INC EBX
SUB AL,30H
MOV ECX,UM.ARGI
CMP AL,10
JAE L2$
CMP AL,CL
JAE L8$
MOV EAX,UM.ARGS[EAX*4]
JMP STR_DUP
L8$:
XOR EAX,EAX ;RETURN ERROR
RET
L2$:
;
;WE BE DEFINING AN ARGUMENT TO STORE AND RETURN
;
PUSH ESI
MOV ESI,EDX
PUSH EDI
DEC EBX
MOV EAX,OFF EMPTY_M ;NULL STRING
CALL STR_DUP
CALL UM_DATA_TYPE
TEST EAX,EAX
JZ L7$
MOV ECX,UM.ARGI
MOV EDX,EBX
CMP ECX,10
JAE L7$
SUB EDX,ESI
CMP EDX,1
JBE L7$
MOV UM.ARGS[ECX*4],EAX
INC ECX
POP EDI
MOV UM.ARGI,ECX
POP ESI
JMP STR_DUP
L7$:
POPM EDI,ESI
RET
UM_ARGUMENT ENDP
UM_DATA_TYPE PROC
;
;
;
PUSHM EDI,ESI
MOV EDI,EAX
XOR EAX,EAX
MOV AL,[EBX]
INC EBX
SUB AL,'A'
XOR ESI,ESI ;T=NULL
CMP AL,'Y'-'A'
JA L2$
JMP UDT_TABLE[EAX*4]
L2$:
CMP AL,'?'-'A'
JZ UDT_QMARK
CMP AL,'_'
JZ UDT__
L4$:
XOR EAX,EAX
POPM ESI,EDI
RET
UDT_QMARK:
POP ESI
CALL UM_INDIRECT_TYPE
MOV ECX,EDI
CALL STR_CAT
POP EDI
JMP UM_DATA_TYPE
UDT__:
MOV AL,[EBX]
INC EBX
SUB AL,'A'
CMP AL,'J'-'A'
JB L4$
CMP AL,'K'-'A'
JA L4$
MOV EAX,BASIC_TBL[EAX*4]
MOV ECX,BASIC_TBL[9*4]
CALL STR_CAT
JMP L1$
UDT_A:
UDT_B:
PUSH EAX
CALL UM_INDIRECT_TYPE
MOV ESI,EAX
MOV EAX,OFF EMPTY_M
CALL STR_DUP
CALL UM_DATA_TYPE
MOV ECX,ESI
CALL STR_CAT
MOV CL,'&'
CALL STR_CATC
POP ECX
CMP CL,'B'-'A'
JNZ UDT_B2
MOV ECX,OFF VOLATILE_M
CALL STR_CAT
UDT_B2:
L1$:
MOV ECX,EDI
POP ESI
POP EDI
JMP STR_CAT
UDT_C:
MOV EAX,BASIC_TBL[EAX*4]
CALL STR_DUP
JMP L1$
UDT_P:
MOV AH,[EBX]
MOV ESI,EAX
CALL UM_INDIRECT_TYPE
MOV ECX,ESI
CMP CH,'6'
JB UDT_P2
CMP CH,'9'
JBE UDT_P3
UDT_P2:
MOV CL,'*'
CALL STR_CATC
MOV ECX,ESI
UDT_P3:
CMP CL,'Q'-'A'
JZ UDT_P4
CMP CL,'S'-'A'
JNZ UDT_P5
UDT_P4:
MOV ECX,OFF CONST_M
CALL STR_CAT
MOV ECX,ESI
UDT_P5:
CMP CL,'R'-'A'
JB UDT_P6
MOV ECX,OFF VOLATILE_M
CALL STR_CAT
UDT_P6:
MOV ECX,EDI
CALL STR_CAT
MOV ECX,ESI
POPM ESI,EDI
CMP CH,'6'
JB UM_DATA_TYPE
CMP CH,'9'
JA UM_DATA_TYPE
RET
UDT_W:
INC EBX
UDT_T:
UDT_U:
UDT_V:
CALL UM_SCOPE
MOV CL,' '
CALL STR_CATC
JMP L1$
UDT_X:
MOV EAX,OFF VOID_M
CALL STR_DUP
JMP L1$
UDT_Y:
MOV EAX,EDI
POP ESI
POP EDI
JMP UM_ARRAY_TYPE
.CONST
UDT_TABLE DD UDT_A
DD UDT_B
DD UDT_C
DD UDT_C
DD UDT_C
DD UDT_C
DD UDT_C
DD UDT_C
DD UDT_C
DD UDT_C
DD UDT_C
DD UDT_C
DD UDT_C
DD UDT_C
DD UDT_C
DD UDT_P
DD UDT_P
DD UDT_P
DD UDT_P
DD UDT_T
DD UDT_U
DD UDT_V
DD UDT_W
DD UDT_X
DD UDT_Y
.CODE MIDDLE_TEXT
UM_DATA_TYPE ENDP
UM_SCOPE PROC
;
;
;
PUSH ESI
MOV AL,[EBX]
XOR ESI,ESI
JMP L8$
L1$:
TEST ESI,ESI
JZ L6$
MOV EAX,ESI
MOV CL,':'
CALL STR_CATC
MOV CL,':'
CALL STR_CATC
MOV ESI,EAX
CALL UM_ZNAME
TEST EAX,EAX
JZ L9$
MOV ECX,EAX
MOV EAX,ESI
CALL STR_CAT
MOV ESI,EAX
JMP L7$
L6$:
CALL UM_ZNAME
TEST EAX,EAX
JZ L9$
MOV ESI,EAX
L7$:
MOV AL,[EBX]
L8$:
CMP AL,0
JZ L9$
CMP AL,'@'
JNZ L1$
INC EBX
MOV EAX,ESI
POP ESI
RET
L9$:
POP ESI
XOR EAX,EAX
RET
UM_SCOPE ENDP
UM_ARRAY_TYPE PROC
;
;
;
PUSHM EBP,EDI,ESI,EAX
MOV EBP,ESP
SUB ESP,512
MOV EDI,ESP
CALL UM_DIMENSION
XOR ECX,ECX
MOV ESI,EAX
MOV [EDI],ECX
ADD EDI,4
TEST EAX,EAX
JZ L2$
L1$:
MOV BPTR [EDI],'['
CALL UM_DIMENSION
LEA ECX,[EDI+1]
CALL CBTA32
LEA EDI,[EAX+1]
MOV BPTR [EAX],']'
DEC ESI
JNZ L1$
L2$:
SUB EDI,ESP
MOV EAX,ESP
SUB EDI,4
MOV [ESP],EDI
CALL STR_DUP
MOV ESP,EBP
MOV ESI,EAX
POP EDX
MOV AL,' '
OR CL,1
LEA EDI,[EDX+4]
MOV ECX,[EDX]
REPNE SCASB
MOV EAX,EDX
JNZ L3$
MOV ECX,')('
CALL STR_BRACKET
L3$:
CALL UM_DATA_TYPE
MOV ECX,ESI
POPM ESI,EDI,EBP
JMP STR_CAT
UM_ARRAY_TYPE ENDP
UM_INDIRECT_TYPE PROC
;
;
;
XOR EAX,EAX
PUSH ESI
MOV AL,[EBX]
INC EBX
SUB AL,'0'
JC L9$
CMP AL,10
JB L1$
SUB AL,'A'-'0'
JB L9$
CMP AL,'Z'-'A'
JA L9$
MOV ESI,EAX
JMP L2$
L1$:
LEA ESI,[EAX+26]
L2$:
CMP ESI,'M'-'A'
JB L5$
CMP ESI,'P'-'A'
JBE L9$
CMP ESI,'6'-'0'+26
JB L5$
CMP ESI,'8'-'0'+26
JB L3$
CALL UM_SCOPE
MOV ECX,OFF CCA_M
CALL STR_CAT
JMP L4$
L3$:
CMP ESI,'6'-'0'+26
JNZ L31$
MOV EAX,OFF UM_TIMES
CALL STR_DUP
JMP L4$
L31$:
MOV EAX,OFF FARA_M
CALL STR_DUP
L4$:
MOV ECX,')('
CALL STR_BRACKET
XOR ECX,ECX
CALL UM_FUNCTION_TYPE
JMP L7$
L5$:
MOV EAX,OFF EMPTY_M
CALL STR_DUP
CMP ESI,'Q'-'A'
JB L55$
CALL UM_SCOPE
MOV ECX,OFF COLONCOLON_M
CALL STR_CAT
L55$:
MOV ECX,ESI
AND ECX,12
PUSH EAX
MOV EAX,PTR_TBL[ECX]
CALL STR_DUP
MOV ECX,EAX
POP EAX
CALL STR_CAT
TEST ESI,1
JZ L56$
MOV ECX,OFF CONST_M
CALL STR_CAT
L56$:
TEST ESI,2
JZ L57$
MOV ECX,OFF VOLATILE_M
CALL STR_CAT
L57$:
L7$:
POP ESI
RET
L9$:
POP ESI
XOR EAX,EAX
RET
UM_INDIRECT_TYPE ENDP
UM_FUNCTION_TYPE PROC
;
;
;
PUSHM EDI,ESI
PUSHM ECX,EAX
CALL UM_CALLING_CONVENTION
POP ECX
CALL STR_CAT
MOV ESI,EAX
MOV EDI,EBX
MOV AL,[EBX]
INC EBX
CMP AL,'@'
JZ L1$
DEC EBX
MOV EAX,OFF EMPTY_M
CALL STR_DUP
CALL UM_DATA_TYPE
L1$:
CALL UM_ARGUMENT_TYPES
MOV ECX,EAX
MOV EAX,ESI
POP ESI
CALL STR_CAT
TEST ESI,ESI
JZ L2$
MOV ECX,ESI
CALL STR_CAT
L2$:
MOV ESI,EAX
CALL UM_ARGUMENT_TYPES
MOV EAX,ESI
MOV CL,[EDI]
CMP CL,'@'
JZ L4$
PUSH EBX
MOV EBX,EDI
CALL UM_DATA_TYPE
POP EBX
L4$:
POPM ESI,EDI
RET
UM_FUNCTION_TYPE ENDP
UM_CALLING_CONVENTION PROC
;
;
;
XOR EAX,EAX
MOV AL,[EBX]
INC EBX
SUB AL,'A'
CMP AL,'K'-'A'
JA L9$
SHR EAX,1
MOV EAX,CC_TBL[EAX*4]
JNC STR_DUP
MOV ECX,OFF SAVEREGS_M
JMP STR_CAT
L9$:
XOR EAX,EAX
RET
UM_CALLING_CONVENTION ENDP
UM_TYPE_ENCODING PROC
;
;
;
PUSHM EDI,ESI
XOR EDI,EDI
XOR ESI,ESI
PUSH EAX
XOR EAX,EAX
L0$:
MOV AL,[EBX]
INC EBX
L1$:
CMP AL,'_'
JZ L0$
CMP AL,'$'
JZ L0$
SUB AL,30H
JB L8$
CMP AL,'Z'-'0'
JA L8$
JMP UTE_TBL[EAX*4]
CASE1:
;
;A,B,E,F,I,J,M,N,Q,R,U,V
;
CALL UM_INDIRECT_TYPE
MOV EDI,EAX
JMP L2$
CASE2:
;
;C,D,K,L,S,T,Y
;
JMP L2$
CASE3:
;
;Z
;
MOV EAX,OFF FAR_M
CALL STR_DUP
POP ECX
CALL STR_CAT
PUSH EAX
L2$:
POP EAX
MOV ECX,EDI
PUSH EAX
CALL UM_FUNCTION_TYPE
MOV ESI,EAX
JMP DEFAULT
CASE4:
POP EAX
PUSH EAX
CALL UM_DATA_TYPE
MOV ESI,EAX
CALL UM_INDIRECT_TYPE ;STORAGE CONVENTION
MOV ECX,ESI
CALL STR_CAT
MOV ESI,EAX
JMP DEFAULT
CASE5:
CALL UM_INDIRECT_TYPE
POP ECX
PUSH ECX
CALL STR_CAT
MOV ESI,EAX
CALL UM_SCOPE
; JMP DEFAULT
DEFAULT:
L8$:
MOV EAX,ESI
POP ECX
POPM ESI,EDI
RET
.CONST
UTE_TBL DD CASE4,CASE4,CASE4,CASE4 ;0-3
DD DEFAULT,DEFAULT ;4-5
DD CASE5,CASE5 ;6-7
DD DEFAULT,DEFAULT ;8-9
DD L8$,L8$,L8$,L8$,L8$,L8$,L8$
DD CASE1,CASE1,CASE2,CASE2 ;ABCD
DD CASE1,CASE1,DEFAULT,DEFAULT ;EFGH
DD CASE1,CASE1,CASE2,CASE2 ;IJKL
DD CASE1,CASE1,DEFAULT,DEFAULT ;MNOP
DD CASE1,CASE1,CASE2,CASE2 ;QRST
DD CASE1,CASE1,DEFAULT,DEFAULT ;UVWX
DD CASE2,CASE3 ;YZ
.CODE MIDDLE_TEXT
UM_TYPE_ENCODING ENDP
UM_ARGUMENT_TYPES PROC
;
;
;
MOV CL,[EBX]
MOV EAX,OFF VOID_M
CMP CL,'X'
JZ L8$
MOV EAX,OFF DOTDOTDOT_M
CMP CL,'Z'
JZ L8$
PUSH ESI
XOR ESI,ESI
L1$:
MOV AL,[EBX]
MOV ECX,OFF COMMADDD_M
CMP AL,'Z'
JZ L4$
CMP AL,0
JZ L5$
CMP AL,'@'
JZ L6$
TEST ESI,ESI
JZ L2$
MOV EAX,ESI
MOV CL,','
CALL STR_CATC
JMP L3$
L2$:
MOV EAX,OFF EMPTY_M
CALL STR_DUP
L3$:
MOV ESI,EAX
CALL UM_ARGUMENT
MOV ECX,EAX
MOV EAX,ESI
CALL STR_CAT
MOV ESI,EAX
JMP L1$
L4$:
MOV EAX,ESI
CALL STR_CAT
L41$:
POP ESI
INC EBX
L9$:
MOV ECX,')('
JMP STR_BRACKET
L6$:
MOV EAX,ESI
JMP L41$
L8$:
INC EBX
CALL STR_DUP
JMP L9$
L5$:
XOR EAX,EAX
POP ESI
RET
UM_ARGUMENT_TYPES ENDP
STR_DUP PROC
;
;
;
TEST EAX,EAX
JZ L9$
PUSHM EDI,ESI
MOV ESI,EAX
MOV EAX,[EAX] ;LENGTH
ADD EAX,4
CALL UNMANGLE_POOL_GET
MOV ECX,[ESI]
MOV EDI,EAX
ADD ECX,7
SHR ECX,2
REP MOVSD
POPM ESI,EDI
L9$:
RET
STR_DUP ENDP
STR_CATC PROC
;
;CL IS CHARACTER TO ADD ONTO EAX
;
TEST EAX,EAX
JZ L9$
MOV EDX,[EAX]
TEST DL,3
JZ L1$
MOV [EAX+EDX+4],CL
INC EDX
MOV [EAX],EDX
L9$:
RET
L1$:
PUSHM EDI,ESI
PUSH ECX
MOV ESI,EAX
LEA EAX,[EDX+5]
CALL UNMANGLE_POOL_GET
MOV ECX,[ESI]
MOV EDI,EAX
ADD ESI,4
INC ECX
MOV [EDI],ECX
ADD EDI,4
SHR ECX,2
POP EDX
REP MOVSD
POP ESI
MOV [EDI],DL
POP EDI
RET
STR_CATC ENDP
STR_BRACKET PROC
;
;INSERT CL ON LEFT, CH ON RIGHT
;
TEST EAX,EAX
JZ L9$
PUSH EDI
MOV EDX,[EAX]
PUSH ESI
INC EDX
AND DL,2
JZ L5$
;
;DON'T NEED ANY MEMORY
;
MOV EDX,ECX
MOV ECX,[EAX]
LEA ESI,[EAX+3+ECX]
LEA EDI,[EAX+4+ECX]
MOV BPTR [EAX+5+ECX],DH
STD
REP MOVSB
CLD
MOV [EDI],DL
POP ESI
POP EDI
ADD DPTR [EAX],2
L9$:
RET
L5$:
MOV ESI,EAX
MOV EAX,[EAX]
PUSH ECX
ADD EAX,4+2
CALL UNMANGLE_POOL_GET
LEA EDI,[EAX+5]
MOV ECX,[ESI]
ADD ECX,2
POP EDX
MOV [EDI-5],ECX
SUB ECX,2
MOV [EDI-1],DL
ADD ESI,4
REP MOVSB
MOV [EDI],DH
POP ESI
POP EDI
RET
STR_BRACKET ENDP
STR_CAT PROC
;
;EAX & ECX...
;
TEST EAX,EAX
JZ L9$
TEST ECX,ECX
JZ L91$
PUSH EDI
MOV EDX,[ECX] ;LENGTH OF SECOND STRING
TEST EDX,EDX
JZ L7$
PUSHM ESI,EBX
MOV ESI,EAX
MOV EAX,[EAX] ;LENGTH OF FIRST STRING
MOV EBX,ECX
ADD EAX,EDX
ADD EAX,4
CALL UNMANGLE_POOL_GET
LEA EDI,[EAX+4]
MOV ECX,[ESI]
ADD ESI,4
MOV EDX,ECX
ADD ECX,3
SHR ECX,2
REP MOVSD
LEA EDI,[EAX+4+EDX]
MOV ECX,[EBX]
LEA ESI,[EBX+4]
ADD EDX,ECX
REP MOVSB
MOV [EAX],EDX
POPM EBX,ESI
L7$:
POP EDI
RET
L91$:
XOR EAX,EAX
L9$:
RET
STR_CAT ENDP
.CONST
UM_TABLE DD UM_CTOR,UM_DTOR
DD UM_NEW,UM_DELETE
DD UM_SETEQUAL,UM_SHR
DD UM_SHL,UM_NOT
DD UM_EQUAL,UM_NOTEQUAL
DD UM_BRACKETS,UM_NOTHING
DD UM_RIGHT_ARROW,UM_TIMES
DD UM_INC,UM_DEC
DD UM_MINUS,UM_PLUS
DD UM_BAND,UM_HUH
DD UM_DIVIDE,UM_MOD
DD UM_LT,UM_LE
DD UM_GT,UM_GE
DD UM_COMMA,UM_PARENS
DD UM_SQUIGGLE,UM_UPARROW
DD UM_BOR,UM_LAND
DD UM_LOR,UM_TIMESEQ
DD UM_PLUSEQ,UM_MINUSEQ
DD UM_DIVEQ,UM_MODEQ
DD UM_SHLEQ,UM_SHREQ
DD UM_ANDEQ,UM_OREQ
DD UM_HATEQ,UM_VFTABLE
DD UM_VBTABLE,UM_VCALL_THUNK
DD UM_METACLASS,UM_GUARD
DD UM_LITSTRING,UM_ULTVBASEDTOR
DD UM_VECDELDTOR,UM_DEFCTORCLOS
DD UM_SCALDELDTOR,UM_VECCTOR
DD UM_VECDTOR,UM_VECVBASECTOR
DD 4 DUP(UM_NOTHING)
DD UM_NOTHING,UM_NEWB
DD UM_DELETEB,UM_QR
DD UM_SYMC1,UM_SYMC2
DD UM_SYMC3,UM_SYMC4
DD UM_SYMC5,UM_SYMC6
DD UM_SYMC7,UM_SYMC8
UM_CTOR DD 0
UM_DTOR DD 0
UM_NEW DD 3
DB 'new',0
UM_DELETE DD 6
DB 'delete',0,0
UM_SETEQUAL DD 1
DB '=',0,0,0
UM_SHR DD 2
DB '>>',0,0
UM_SHL DD 2
DB '<<',0,0
UM_NOT DD 1
DB '!',0,0,0
UM_EQUAL DD 2
DB '==',0,0
UM_NOTEQUAL DD 2
DB '!=',0,0
UM_BRACKETS DD 2
DB '[]',0,0
UM_NOTHING DD 0
UM_RIGHT_ARROW DD 2
DB '->',0,0
UM_TIMES DD 1
DB '*',0,0,0
UM_INC DD 2
DB '++',0,0
UM_DEC DD 2
DB '--',0,0
UM_MINUS DD 1
DB '-',0,0,0
UM_PLUS DD 1
DB '+',0,0,0
UM_BAND DD 1
DB '&',0,0,0
UM_HUH DD 3
DB '->*',0
UM_DIVIDE DD 1
DB '/',0,0,0
UM_MOD DD 1
DB '%',0,0,0
UM_LT DD 1
DB '<',0,0,0
UM_LE DD 2
DB '<=',0,0
UM_GT DD 1
DB '>',0,0,0
UM_GE DD 2
DB '>=',0,0
UM_COMMA DD 1
DB ',',0,0,0
UM_PARENS DD 2
DB '()',0,0
UM_SQUIGGLE DD 1
DB '~',0,0,0
UM_UPARROW DD 1
DB '^',0,0,0
UM_BOR DD 1
DB '|',0,0,0
UM_LAND DD 2
DB '&&',0,0
UM_LOR DD 2
DB '||',0,0
UM_TIMESEQ DD 2
DB '*=',0,0
UM_PLUSEQ DD 2
DB '+=',0,0
UM_MINUSEQ DD 2
DB '-=',0,0
UM_DIVEQ DD 2
DB '/=',0,0
UM_MODEQ DD 2
DB '%=',0,0
UM_SHLEQ DD 3
DB '<<=',0
UM_SHREQ DD 3
DB '>>=',0
UM_ANDEQ DD 2
DB '&=',0,0
UM_OREQ DD 2
DB '|=',0,0
UM_HATEQ DD 2
DB '^=',0,0
UM_VFTABLE DD 7
DB 'vftable',0
UM_VBTABLE DD 7
DB 'vbtable',0
UM_VCALL_THUNK DD 11
DB 'vcall_thunk',0
UM_METACLASS DD 9
DB 'metaclass',0,0,0
UM_GUARD DD 5
DB 'guard',0,0,0
UM_LITSTRING DD 10
DB 'lit_string',0,0
UM_ULTVBASEDTOR DD 14
DB 'ult_vbase_dtor',0,0
UM_VECDELDTOR DD 12
DB 'vec_del_dtor'
UM_DEFCTORCLOS DD 13
DB 'def_ctor_clos',0,0,0
UM_SCALDELDTOR DD 13
DB 'scal_del_dtor',0,0,0
UM_VECCTOR DD 8
DB 'vec_ctor'
UM_VECDTOR DD 8
DB 'vec_dtor'
UM_VECVBASECTOR DD 14
DB 'vec_vbase_ctor',0,0
UM_NEWB DD 5
DB 'new[]',0,0,0
UM_DELETEB DD 8
DB 'delete[]'
UM_QR DD 3
DB '?_R',0
UM_SYMC1 DD 4
DB '!<>='
UM_SYMC2 DD 2
DB '<>',0,0
UM_SYMC3 DD 3
DB '<>=',0
UM_SYMC4 DD 2
DB '!>',0,0
UM_SYMC5 DD 3
DB '!>=',0
UM_SYMC6 DD 2
DB '!<',0,0
UM_SYMC7 DD 3
DB '!<=',0
UM_SYMC8 DD 3
DB '!<>',0
BASIC_TBL DD EMPTY_M
DD EMPTY_M
DD SCHAR_M
DD CHAR_M
DD UCHAR_M
DD SHORT_M
DD USHORT_M
DD INT_M
DD U_M
DD LONG_M
DD ULONG_M
DD SEGM_M
DD FLOAT_M
DD DOUBLE_M
DD LDOUBLE_M
SCHAR_M DD 12
DB 'signed char '
CHAR_M DD 5
DB 'char ',0,0,0
UCHAR_M DD 14
DB 'unsigned char ',0,0
SHORT_M DD 6
DB 'short ',0,0
USHORT_M DD 15
DB 'unsigned short ',0
INT_M DD 4
DB 'int '
U_M DD 9
DB 'unsigned ',0,0,0
LONG_M DD 5
DB 'long ',0,0,0
ULONG_M DD 14
DB 'unsigned long ',0,0
SEGM_M DD 10
DB '__segment ',0,0
FLOAT_M DD 6
DB 'float ',0,0
DOUBLE_M DD 7
DB 'double ',0
LDOUBLE_M DD 12
DB 'long double '
VOLATILE_M DD 9
DB 'volatile ',0,0,0
CONST_M DD 6
DB 'const ',0,0
VOID_M DD 5
DB 'void ',0,0,0
COLONCOLON_M DD 2
DB '::',0,0
CCA_M DD 3
DB '::*',0
FARA_M DD 5
DB 'far *',0,0,0
SPECIAL_CHAR DB ",/\:. ",0AH,09H,"'-"
PTR_TBL DD EMPTY_M
DD FAR_M
DD HUGE_M
DD BASED_M
FAR_M DD 4
DB 'far '
HUGE_M DD 5
DB 'huge ',0,0,0
BASED_M DD 6
DB 'based ',0,0
CC_TBL DD CDECL_M
DD PASCAL_M
DD SYSCALL_M
DD STDCALL_M
DD FASTCALL_M
DD INTERRUPT_M
CDECL_M DD 6
DB 'cdecl ',0,0
PASCAL_M DD 7
DB 'pascal ',0
SYSCALL_M DD 8
DB 'syscall '
STDCALL_M DD 8
DB 'stdcall '
FASTCALL_M DD 9
DB 'fastcall ',0,0,0
INTERRUPT_M DD 10
DB 'interrupt ',0,0
SAVEREGS_M DD 9
DB 'saveregs ',0,0,0
COMMADDD_M DD 4
DB ',...'
DOTDOTDOT_M DD 3
DB '...',0
SQUIGGLE_M DD 1
DB '~',0,0,0
OPERATOR_M DD 9
DB 'operator ',0,0,0
.DATA?
UM UM_STRUCT<>
EMPTY_M DD ?,?
END
|
;================================================================================
;
; "Sixty/5o2"
; _________
;
; v1.0
;
; Sixty/5o2 - minimal bootloader and monitor (r/o) w/ serial connection support
;
; Written by Jan Roesner <jan@roesner.it> for Ben Eater's "Project 6502"
;
; Credits:
; - Ben Eater (Project 6502)
; - Steven Wozniak (bin2hex routine)
; - Anke L. (love, patience & support)
;
;================================================================================
PORTB = $6000 ; VIA port B
PORTA = $6001 ; VIA port A
DDRB = $6002 ; Data Direction Register B
DDRA = $6003 ; Data Direction Register A
IER = $600e ; VIA Interrupt Enable Register
E = %10000000
RW = %01000000
RS = %00100000
Z0 = $00 ; General purpose zero page locations
Z1 = $01
Z2 = $02
Z3 = $03
VIDEO_RAM = $3fde ; $3fde - $3ffd - Video RAM for 32 char LCD display
POSITION_MENU = $3fdc ; initialize positions for menu and cursor in RAM
POSITION_CURSOR = $3fdd
WAIT = $3fdb
WAIT_C = $18 ; global sleep multiplicator (adjust for slower clock)
PROGRAM_LOCATION = $0200 ; memory location for user programs
.org $8000
;================================================================================
;
; main - routine to initialize the bootloader
;
; Initializes the bootloader, LCD, VIA, Video Ram and prints a welcome message
; ————————————————————————————————————
; Preparatory Ops: none
;
; Returned Values: none
;
; Destroys: .A, .Y, .X
; ————————————————————————————————————
;
;================================================================================
main: ; boot routine, first thing loaded
ldx #$ff ; initialize the stackpointer with 0xff
txs
jsr LCD__initialize
jsr LCD__clear_video_ram
lda #<message ; render the boot screen
ldy #>message
jsr LCD__print
ldx #$20 ; delay further progress for a bit longer
lda #$ff
.wait:
jsr LIB__sleep
dex
bne .wait
jsr MENU_main ; start the menu routine
jmp main ; should the menu ever return ...
;================================================================================
;
; MENU_main - renders a scrollable menu w/ dynamic number of entries
;
; ————————————————————————————————————
; Preparatory Ops: none
;
; Returned Values: none
;
; Destroys: .A, .X, .Y
; ————————————————————————————————————
;
;================================================================================
MENU_main:
lda #0 ; since in RAM, positions need initialization
sta POSITION_MENU
sta POSITION_CURSOR
jmp .start
.MAX_SCREEN_POS: ; define some constants in ROM
.byte $05 ; its always number of items - 2, here its 6 windows ($00-$05) in 7 items
.OFFSETS:
.byte $00, $10, $20, $30, $40, $50 ; content offsets for all 6 screen windows
.start: ; and off we go
jsr LCD__clear_video_ram
ldx POSITION_MENU
ldy .OFFSETS,X
; load first offset into Y
ldx #0 ; set X to 0
.loop:
lda menu_items,Y ; load string char for Y
sta VIDEO_RAM,X ; store in video ram at X
iny
inx
cpx #$20 ; repeat 32 times
bne .loop
.render_cursor: ; render cursor position based on current state
lda #">"
ldy POSITION_CURSOR
bne .lower_cursor
sta VIDEO_RAM
jmp .render
.lower_cursor:
sta VIDEO_RAM+$10
.render: ; and update the screen
jsr LCD__render
.wait_for_input: ; handle keyboard input
ldx #4
lda #$ff ; debounce
.wait:
jsr LIB__sleep
dex
bne .wait
lda #0
jsr VIA__read_keyboard_input
beq .wait_for_input ; no
.handle_keyboard_input:
cmp #$01
beq .move_up ; UP key pressed
cmp #$02
beq .move_down ; DOWN key pressed
cmp #$08
beq .select_option ; RIGHT key pressed
lda #0 ; explicitly setting A is a MUST here
jmp .wait_for_input ; and go around
.move_up:
lda POSITION_CURSOR ; load cursor position
beq .dec_menu_offset ; is cursor in up position? yes?
lda #0 ; no?
sta POSITION_CURSOR ; set cursor in up position
jmp .start ; re-render the whole menu
.dec_menu_offset:
lda POSITION_MENU
beq .wait_for_input ; yes, just re-render
.decrease:
dec POSITION_MENU ; decrease menu position by one
jmp .start ; and re-render
.move_down:
lda POSITION_CURSOR ; load cursor position
cmp #1 ; is cursor in lower position?
beq .inc_menu_offset ; yes?
lda #1 ; no?
sta POSITION_CURSOR ; set cursor in lower position
jmp .start ; and re-render the whole menu
.inc_menu_offset:
lda POSITION_MENU ; load current menu positions
cmp .MAX_SCREEN_POS ; are we at the bottom yet?
bne .increase ; no?
jmp .wait_for_input ; yes
.increase:
adc #1 ; increase menu position
sta POSITION_MENU
jmp .start ; and re-render
.select_option:
clc
lda #0 ; clear A
adc POSITION_MENU
adc POSITION_CURSOR ; calculate index of selected option
cmp #0 ; branch trough all options
beq .load_and_run
cmp #1
beq .load
cmp #2
beq .run
cmp #3
beq .monitor
cmp #4
beq .clear_ram
cmp #5
beq .about
cmp #6
beq .credits
jmp .end ; should we have an invalid option, restart
.load_and_run: ; load and directly run
jsr .do_load ; load first
jsr .do_run ; run immediately after
jmp .start ; should a program ever return ...
.load: ; load program and go back into menu
jsr .do_load
jmp .start
.run: ; run a program already loaded
jsr .do_run
jmp .start
.monitor: ; start up the monitor
lda #<PROGRAM_LOCATION ; have it render the start location
ldy #>PROGRAM_LOCATION ; can also be set as params during debugging
jsr MONITOR__main
jmp .start
.clear_ram: ; start the clear ram routine
jsr BOOTLOADER__clear_ram
jmp .start
.about: ; start the about routine
lda #<about
ldy #>about
ldx #3
jsr LCD__print_text
jmp .start
.credits: ; start the credits routine
lda #<credits
ldy #>credits
ldx #3
jsr LCD__print_text
jmp .start
.do_load: ; orchestration of program loading
lda #$ff ; wait a bit
jsr LIB__sleep
jsr BOOTLOADER__program_ram ; call the bootloaders programming routine
rts
.do_run: ; orchestration of running a program
jmp BOOTLOADER__execute
.end
jmp .start ; should we ever reach this point ...
;================================================================================
;
; BOOTLOADER__program_ram - writes serial data to RAM
;
; Used in conjunction w/ the ISR, orchestrates user program reading
; ————————————————————————————————————
; Preparatory Ops: none
;
; Returned Values: none
; none
; Destroys: .A, .X, .Y
; ————————————————————————————————————
;
;================================================================================
BOOTLOADER__program_ram:
CURRENT_RAM_ADDRESS_L = Z0
CURRENT_RAM_ADDRESS_H = Z1
LOADING_STATE = Z2
lda #%01111111 ; we disable all 6522 interrupts!!!
sta IER
jsr LCD__clear_video_ram
lda #<message4 ; Rendering a message
ldy #>message4
jsr LCD__print
lda #$00 ; initializing loading state byte
sta LOADING_STATE
lda #>PROGRAM_LOCATION ; initializing RAM address counter
sta CURRENT_RAM_ADDRESS_H
lda #<PROGRAM_LOCATION
sta CURRENT_RAM_ADDRESS_L
cli ; enable interrupt handling
lda #%00000000 ; set all pins on port B to input
ldx #%11100001 ; set top 3 pins and bottom ones to on port A to output, 4 middle ones to input
jsr VIA__configure_ddrs
.wait_for_first_data:
lda LOADING_STATE ; checking loading state
cmp #$00 ; the ISR will set to $01 as soon as a byte is read
beq .wait_for_first_data
.loading_data
lda #$02 ; assuming we're done loading, we set loading state to $02
sta LOADING_STATE
ldx #$20 ; then we wait for * cycles !!!! Increase w/ instable loading
lda #$ff
.loop:
jsr LIB__sleep
dex
bne .loop
lda LOADING_STATE ; check back loading state, which was eventually updated by the ISR
cmp #$02
bne .loading_data
; when no data came in in last * cycles, we're done loading
.done_loading:
jsr LCD__clear_video_ram
lda #<message6
ldy #>message6
jsr LCD__print
lda #$ff ; wait a moment before we return to main menu
jsr LIB__sleep
rts
;================================================================================
;
; BOOTLOADER__execute - executes a user program in RAM
;
; Program needs to be loaded via serial loader or other mechanism beforehand
; ————————————————————————————————————
; Preparatory Ops: none
;
; Returned Values: none
;
; Destroys: .A, .Y
; ————————————————————————————————————
;
;================================================================================
BOOTLOADER__execute:
sei ; disable interrupt handling
jsr LCD__clear_video_ram ; print a message
lda #<message7
ldy #>message7
jsr LCD__print
jmp PROGRAM_LOCATION ; and jump to program location
;================================================================================
;
; BOOTLOADER__clear_ram - clears RAM from $0200 up to $3fff
;
; Useful during debugging or when using non-volatile RAM chips
; ————————————————————————————————————
; Preparatory Ops: none
;
; Returned Values: none
;
; Destroys: .A, .Y
; ————————————————————————————————————
;
;================================================================================
BOOTLOADER__clear_ram:
jsr LCD__clear_video_ram ; render message
lda #<message8
ldy #>message8
jsr LCD__print
ldy #<PROGRAM_LOCATION ; load start location into zero page
sty Z0
lda #>PROGRAM_LOCATION
sta Z1
lda #$00 ; load 0x00 cleaner byte
.loop:
sta (Z0),Y ; store it in current location
iny ; increase 16 bit address by 0x01
bne .loop
inc Z1
bit Z1 ; V is set on bit 6 (= $40)
bvs .loop
rts ; yes, return from subroutine
;================================================================================
;
; MONITOR__main - RAM/ROM Hexmonitor (r/o)
;
; Currently read only, traverses RAM and ROM locations, shows hex data contents
; ————————————————————————————————————
; Preparatory Ops: none
;
; Returned Values: none
;
; Destroys: .A, .X, .Y
; ————————————————————————————————————
;
;================================================================================
MONITOR__main:
sta Z0 ; store LSB
sty Z1 ; store MSB
.render_current_ram_location:
jsr LCD__clear_video_ram
lda #$00 ; select upper row of video ram
sta Z3 ; #TODO
jsr .transform_contents ; load and transform ram and address bytes
clc ; add offset to address
lda Z0
adc #$04
sta Z0
bcc .skip
inc Z1
.skip:
lda #$01 ; select lower row of video ram
sta Z3
jsr .transform_contents ; load and transform ram and address bytes there
jsr LCD__render
.wait_for_input: ; wait for key press
ldx #$04 ; debounce #TODO
.wait:
lda #$ff
jsr LIB__sleep
dex
bne .wait
lda #0
jsr VIA__read_keyboard_input
beq .wait_for_input ; a key was pressed? no
.handle_keyboard_input: ; determine action for key pressed
cmp #$01
beq .move_up ; UP key pressed
cmp #$02
beq .move_down ; DOWN key pressed
cmp #$04
beq .exit_monitor ; LEFT key pressed
cmp #$08
beq .fast_forward ; RIGHT key pressed
lda #0 ; explicitly setting A is a MUST here
jmp .wait_for_input
.exit_monitor:
lda #0 ; needed for whatever reason
rts
.move_down:
jmp .render_current_ram_location ; no math needed, the address is up to date already
.move_up:
sec ; decrease the 16bit RAM Pointer
lda Z0
sbc #$08
sta Z0
lda Z1
sbc #$00
sta Z1
jmp .render_current_ram_location ; and re-render
.fast_forward: ; add $0800 to current RAM location
sec
lda Z0
adc #$00
sta Z0
lda Z1
adc #$04
sta Z1
jmp .render_current_ram_location ; and re-render
.transform_contents: ; start reading address and ram contents into stack
ldy #3
.iterate_ram: ; transfer 4 ram bytes to stack
lda (Z0),Y
pha
dey
bne .iterate_ram
lda (Z0),Y
pha
lda Z0 ; transfer the matching address bytes to stack too
pha
lda Z1
pha
ldy #0
.iterate_stack: ; transform stack contents from bin to hex
cpy #6
beq .end
sty Z2 ; preserve Y #TODO
pla
jsr LIB__bin_to_hex
ldy Z2 ; restore Y
pha ; push least sign. nibble (LSN) onto stack
txa
pha ; push most sign. nibble (MSN) too
tya ; calculate nibble positions in video ram
adc MON__position_map,Y ; use the static map for that
tax
pla
jsr .store_nibble ; store MSN to video ram
inx
pla
jsr .store_nibble ; store LSN to video ram
iny
jmp .iterate_stack ; repeat for all 6 bytes on stack
.store_nibble: ; subroutine to store nibbles in two lcd rows
pha
lda Z3
beq .store_upper_line ; should we store in upper line? yes
pla ; no, store in lower line
sta VIDEO_RAM+$10,X
jmp .end_store
.store_upper_line ; upper line storage
pla
sta VIDEO_RAM,X
.end_store:
rts
.end:
lda #":" ; writing the two colons
sta VIDEO_RAM+$4
sta VIDEO_RAM+$14
rts
;================================================================================
;
; VIA__read_keyboard_input - returns 4-key keyboard inputs
;
; Input is read, normalized and returned to the caller
; ————————————————————————————————————
; Preparatory Ops: none
;
; Returned Values: .A: (UP: $1, DOWN: $2, LEFT: $4, RIGHT: $8)
;
; Destroys: .A
; ————————————————————————————————————
;
;================================================================================
VIA__read_keyboard_input:
lda PORTA ; load current key status from VIA
ror ; normalize the input to $1, $2, $4 and $8
and #$0f
rts
;================================================================================
;
; VIA__configure_ddrs - configures data direction registers of the VIA chip
;
; Expects one byte per register with bitwise setup input/output directions
; ————————————————————————————————————
; Preparatory Ops: .A: Byte for DDRB
; .X: Byte for DDRA
;
; Returned Values: none
;
; Destroys: none
; ————————————————————————————————————
;
;================================================================================
VIA__configure_ddrs:
sta DDRB ; configure data direction for port B from A reg.
stx DDRA ; configure data direction for port A from X reg.
rts
;================================================================================
;
; LCD__clear_video_ram - clears the Video Ram segment with 0x00 bytes
;
; Useful before rendering new contents by writing to the video ram
; ————————————————————————————————————
; Preparatory Ops: none
;
; Returned Values: none
;
; Destroys: none
; ————————————————————————————————————
;
;================================================================================
LCD__clear_video_ram:
pha ; preserve A via stack
tya ; same for Y
pha
ldy #$20 ; set index to 32
lda #$20 ; set character to 'space'
.loop:
sta VIDEO_RAM,Y ; clean video ram
dey ; decrease index
bne .loop ; are we done? no, repeat
sta VIDEO_RAM ; yes, write zero'th location manually
pla ; restore Y
tay
pla ; restore A
rts
;================================================================================
;
; LCD__print - prints a string to the LCD (highlevel)
;
; String must be given as address pointer, subroutines are called
; The given string is automatically broken into the second display line and
; the render routines are called automatically
;
; Important: String MUST NOT be zero terminated
; ————————————————————————————————————
; Preparatory Ops: .A: LSN String Address
; .Y: MSN String Address
; Returned Values: none
;
; Destroys: .A, .X, .Y
; ————————————————————————————————————
;
;================================================================================
LCD__print:
ldx #0 ; set offset to 0 as default
jsr LCD__print_with_offset ; call printing subroutine
rts
;================================================================================
;
; LCD__print_with_offset - prints string on LCD screen at given offset
;
; String must be given as address pointer, subroutines are called
; The given string is automatically broken into the second display line and
; the render routines are called automatically
;
; Important: String MUST NOT be zero terminated
; ————————————————————————————————————
; Preparatory Ops: .A: LSN String Address
; .Y: MSN String Address
; .X: Offset Byte
; Returned Values: none
;
; Destroys: .A, .X, .Y
; ————————————————————————————————————
;
;================================================================================
LCD__print_with_offset:
STRING_ADDRESS_PTR = Z0
sta STRING_ADDRESS_PTR ; load t_string lsb
sty STRING_ADDRESS_PTR+1 ; load t_string msb
stx Z2 ; X can not directly be added to A, therefore we store it #TODO
ldy #0
.loop:
clc
tya
adc Z2 ; compute offset based on given offset and current cursor position
tax
lda (STRING_ADDRESS_PTR),Y ; load char from given string at position Y
beq .return ; is string terminated via 0x00? yes
sta VIDEO_RAM,X ; no - store char to video ram
iny
jmp .loop ; loop until we find 0x00
.return:
jsr LCD__render ; render video ram contents to LCD screen aka scanline
rts
;================================================================================
;
; LCD__print_text - prints a scrollable / escapeable multiline text (highlevel)
;
; The text location must be given as memory pointer, the number of pages to
; be rendered needs to be given as well
;
; Important: The text MUST be zero terminated
; ————————————————————————————————————
; Preparatory Ops: .A: LSN Text Address
; .Y: MSN Text Address
; .X: Page Number Byte
; Returned Values: none
;
; Destroys: .A, .X, .Y
; ————————————————————————————————————
;
;================================================================================
LCD__print_text:
sta Z0 ; store text pointer in zero page
sty Z1
dex ; reduce X by one to get cardinality of pages
stx Z2 ; store given number of pages
.CURRENT_PAGE = Z3
lda #0
sta Z3
.render_page:
jsr LCD__clear_video_ram ; clear video ram
ldy #0 ; reset character index
.render_chars:
lda (Z0),Y ; load character from given text at current character index
cmp #$00
beq .do_render ; text ended? yes then render
sta VIDEO_RAM,Y ; no, store char in video ram at current character index
iny ; increase index
bne .render_chars ; repeat with next char
.do_render:
jsr LCD__render ; render current content to screen
.wait_for_input: ; handle keyboard input
ldx #4
.wait:
lda #$ff ; debounce
jsr LIB__sleep
dex
bne .wait
lda #0
jsr VIA__read_keyboard_input
bne .handle_keyboard_input ; do we have input? yes?
jmp .wait_for_input ; no
.handle_keyboard_input:
cmp #$01
beq .move_up ; UP key pressed
cmp #$02
beq .move_down ; DOWN key pressed
cmp #$04
beq .exit ; LEFT key pressed
lda #0 ; Explicitly setting A is a MUST here
jmp .wait_for_input
.exit:
rts
.move_up:
lda .CURRENT_PAGE ; are we on the first page?
beq .wait_for_input ; yes, just ignore the keypress and wait for next one
dec .CURRENT_PAGE ; no, decrease current page by 1
sec ; decrease reading pointer by 32 bytes
lda Z0
sbc #$20
sta Z0
bcs .skipdec
dec Z1
.skipdec:
jmp .render_page ; and re-render
.move_down:
lda .CURRENT_PAGE ; load current page
cmp Z2 ; are we on last page already
beq .wait_for_input ; yes, just ignore keypress and wait for next one
inc .CURRENT_PAGE ; no, increase current page by 1
clc ; add 32 to the text pointer
lda Z0
adc #$20
sta Z0
bcc .skipinc
inc Z1
.skipinc:
jmp .render_page ; and re-render
;================================================================================
;
; LCD__initialize - initializes the LCD display
;
; ————————————————————————————————————
; Preparatory Ops: none
;
; Returned Values: none
;
; Destroys: .A, .X
; ————————————————————————————————————
;
;================================================================================
LCD__initialize:
lda #%11111111 ; set all pins on port B to output
ldx #%11100000 ; set top 3 pins and bottom ones to on port A to output, 5 middle ones to input
jsr VIA__configure_ddrs
lda #%00111000 ; set 8-bit mode, 2-line display, 5x8 font
jsr LCD__send_instruction
lda #%00001110 ; display on, cursor on, blink off
jsr LCD__send_instruction
lda #%00000110 ; increment and shift cursor, don't shift display
jmp LCD__send_instruction
;================================================================================
;
; LCD__set_cursor - sets the cursor on hardware level into upper or lower row
;
; Always positions the cursor in the first column of the chosen row
; ————————————————————————————————————
; Preparatory Ops: .A: byte representing upper or lower row
;
; Returned Values: none
;
; Destroys: .A
; ————————————————————————————————————
;
;================================================================================
LCD__set_cursor:
jmp LCD__send_instruction
;================================================================================
;
; LCD__set_cursor_second_line - sets cursor to second row, first column
;
; Low level convenience function
; ————————————————————————————————————
; Preparatory Ops: none
;
; Returned Values: none
;
; Destroys: none
; ————————————————————————————————————
;
;================================================================================
LCD__set_cursor_second_line:
pha ; preserve A
lda #%11000000 ; set cursor to line 2 hardly
jsr LCD__send_instruction
pla ; restore A
rts
;================================================================================
;
; LCD__render - transfers Video Ram contents onto the LCD display
;
; Automatically breaks text into the second row if necessary but takes the
; additional LCD memory into account
; ————————————————————————————————————
; Preparatory Ops: Content in Video Ram needs to be available
;
; Returned Values: none
;
; Destroys: .A, .X, .Y
; ————————————————————————————————————
;
;================================================================================
LCD__render:
lda #%10000000 ; force cursor to first line
jsr LCD__set_cursor
ldx #0
.write_char: ; start writing chars from video ram
lda VIDEO_RAM,X ; read video ram char at X
cpx #$10 ; are we done with the first line?
beq .next_line ; yes - move on to second line
cpx #$20 ; are we done with 32 chars?
beq .return ; yes, return from routine
jsr LCD__send_data ; no, send data to lcd
inx
jmp .write_char ; repeat with next char
.next_line:
jsr LCD__set_cursor_second_line ; set cursort into line 2
jsr LCD__send_data ; send dataa to lcd
inx
jmp .write_char ; repear with next char
.return:
rts
;================================================================================
;
; LCD__check_busy_flag - returns the LCD's busy status flag
;
; Since the LCD needs clock cycles internally to process instructions, it can
; not handle instructions at all times. Therefore it provides a busy flag,
; which when 0 signals, that the LCD is ready to accept the next instruction
; ————————————————————————————————————
; Preparatory Ops: none
;
; Returned Values: .A: LCD's busy flag (busy: $01, ready: $00)
;
; Destroys: .A
; ————————————————————————————————————
;
;================================================================================
LCD__check_busy_flag:
lda #0 ; clear port A
sta PORTA ; clear RS/RW/E bits
lda #RW ; prepare read mode
sta PORTA
bit PORTB ; read data from LCD
bpl .ready ; bit 7 not set -> ready
lda #1 ; bit 7 set, LCD is still busy, need waiting
rts
.ready:
lda #0
.return:
rts
;================================================================================
;
; LCD__send_instruction - sends a control instruction to the LCD display
;
; In contrast to data, the LCD accepts a number of control instructions as well
; This routine can be used, to send arbitrary instructions following the LCD's
; specification
; ————————————————————————————————————
; Preparatory Ops: .A: control byte (see LCD manual)
;
; Returned Values: none
;
; Destroys: .A
; ————————————————————————————————————
;
;================================================================================
LCD__send_instruction:
pha ; preserve A
.loop ; wait until LCD becomes ready
jsr LCD__check_busy_flag
bne .loop
pla ; restore A
sta PORTB ; write accumulator content into PORTB
lda #E
sta PORTA ; set E bit to send instruction
lda #0
sta PORTA ; clear RS/RW/E bits
rts
;================================================================================
;
; LCD__send_data - sends content data to the LCD controller
;
; In contrast to instructions, there seems to be no constraint, and data can
; be sent at any rate to the display (see LCD__send_instruction)
; ————————————————————————————————————
; Preparatory Ops: .A: Content Byte
;
; Returned Values: none
;
; Destroys: .A
; ————————————————————————————————————
;
;================================================================================
LCD__send_data:
sta PORTB ; write accumulator content into PORTB
lda #(RS | E)
sta PORTA ; set E bit AND register select bit to send instruction
lda #0
sta PORTA ; clear RS/RW/E bits
rts
;================================================================================
;
; LIB__bin_to_hex: CONVERT BINARY BYTE TO HEX ASCII CHARS - THX Woz!
;
; Slighty modified version - original from Steven Wozniak for Apple I
; ————————————————————————————————————
; Preparatory Ops: .A: byte to convert
;
; Returned Values: .A: LSN ASCII char
; .X: MSN ASCII char
; ————————————————————————————————————
;
;================================================================================
LIB__bin_to_hex:
ldy #$ff ; state for output switching #TODO
pha ; save A for LSD
lsr
lsr
lsr
lsr ; MSD to LSD position
jsr .to_hex ; output hex digit, using internal recursion
pla ; restore A
.to_hex
and #%00001111 ; mask LSD for hex print
ora #"0" ; add "0"
cmp #"9"+1 ; is it a decimal digit?
bcc .output ; yes! output it
adc #6 ; add offset for letter A-F
.output
iny ; set switch for second nibble processing
bne .return ; did we process second nibble already? yes
tax ; no
.return
rts
;================================================================================
;
; LIB__sleep - sleeps for a given amount of cycles
;
; The routine does not actually sleep, but wait by burning cycles in TWO(!)
; nested loops. The user can configure the number of inner cycles via .A.
; In addition there is an outer loop, which nests the inner one, hence multiplies
; the number of burned cycles for ALL LIB__sleep calls by a globals multiplier.
;
; This way the whole codebase can easily be adjusted to other clock rates then
; 1MHz. The global number of outer cycles for 1MHz is $18 and stored in WAIT
;
; Unfortunately this calls for errors, where the global wait is not set back
; correctly. PR welcome
; ————————————————————————————————————
; Preparatory Ops: .A: byte representing the sleep duration
;
; Returned Values: none
;
; Destroys: .Y
; ————————————————————————————————————
;
;================================================================================
LIB__sleep:
ldy #WAIT_C
sty WAIT
.outerloop:
tay
.loop:
dey
bne .loop
dec WAIT
bne .outerloop
rts
message:
.asciiz "Sixty/5o2 Bootloader v0.1"
message2:
.asciiz "Enter Command..."
message3:
.asciiz "Programming RAM"
message4:
.asciiz "Awaiting data..."
message6:
.asciiz "Loading done!"
message7:
.asciiz "Running $0x200"
message8:
.asciiz "Cleaning RAM Patience please!"
MON__position_map:
.byte $00, $01, $03, $05, $07, $09
menu_items:
.text " Load & Run "
.text " Load "
.text " Run "
.text " Monitor "
.text " Clear RAM "
.text " About "
.text " Credits "
about:
.asciiz "Sixty/5o2 Bootloader and Monitor written by Jan Roesner <jan@roesner.it>git.io/JvTM1 "
credits:
.asciiz "Ben Eater 6502 Project Steven Wozniak bin2hex routine Anke L. love & patience"
;================================================================================
;
; ISR - Interrupt Service Routine
;
; This might be the most naive approach to serial RAM writing ever, but it is
; enormously stable and effective.
;
; Whenever the Arduino set up a data bit on the 8 data lines of VIA PortB, it
; pulls the 6502's interrupt line low for 3 microseconds. This triggers an
; interrupt, and causes the 6502 to lookup the ISR entry vector in memory
; location $fffe and $ffff. This is, where this routines address is put, so
; each time an interrupt is triggered, this routine is called.
;
; The routine reads the current byte from VIA PortB, writes it to the RAM and
; increases the RAM address by $01.
;
; In addition it REsets the LOADING_STATE byte, so the BOOTLOADER__program_ram
; routine knows, there is still data flowing in. Since there is no "Control Byte"
; that can be used to determine EOF, it is ust assumed, that EOF is reached, when
; no data came in for a defined number of cycles.
;
; Important: Due to the current hardware design (interrupt line) there is no
; way to have the ISR service different interrupt calls.
;
; Important: The routine is put as close to the end of the ROM as possible to
; not fragment the ROM for additional routines. In case of additional
; operations, the entry address needs recalculation!
;
; ————————————————————————————————————
; Preparatory Ops: none
;
; Returned Values: none
;
; Destroys: none
; ————————————————————————————————————
;
;================================================================================
.org $FFC9 ; as close as possible to the ROM's end
ISR:
CURRENT_RAM_ADDRESS = Z0 ; a RAM address handle for indirect writing
pha
tya
pha
.write_data:
lda #$01 ; progressing state of loading operation
sta LOADING_STATE ; so program_ram routine knows, data's still flowing
lda PORTB ; load serial data byte
ldy #0
sta (CURRENT_RAM_ADDRESS),Y ; store byte at current RAM location
; increase the 16bit RAM location
inc CURRENT_RAM_ADDRESS_L
bne .doneisr
inc CURRENT_RAM_ADDRESS_H
.doneisr
pla ; restore Y
tay
pla ; restore A
rti
.org $fffc
.word main ; entry vector main routine
.word ISR ; entry vector interrupt service routine |
; A166957: a(n) = 841*n^3 + 261*n^2 + 28*n + 1.
; Submitted by Simon Strandgaard
; 1,1131,7829,25141,58113,111791,191221,301449,447521,634483,867381,1151261,1491169,1892151,2359253,2897521,3512001,4207739,4989781,5863173,6832961,7904191,9081909,10371161,11776993,13304451,14958581,16744429,18667041,20731463,22942741,25305921,27826049,30508171,33357333,36378581,39576961,42957519,46525301,50285353,54242721,58402451,62769589,67349181,72146273,77165911,82413141,87893009,93610561,99570843,105778901,112239781,118958529,125940191,133189813,140712441,148513121,156596899,164968821
mul $0,29
mov $1,$0
add $1,3
pow $1,3
add $1,$0
mov $0,$1
div $0,29
add $0,1
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r13
push %r15
push %r9
push %rax
push %rcx
push %rdi
push %rsi
lea addresses_UC_ht+0x1d1c8, %r9
nop
dec %r11
mov (%r9), %r13d
nop
nop
nop
add %rcx, %rcx
lea addresses_WT_ht+0x61c8, %rsi
lea addresses_WC_ht+0x18148, %rdi
sub %r15, %r15
mov $33, %rcx
rep movsq
nop
nop
nop
nop
nop
cmp %r15, %r15
lea addresses_WC_ht+0x6858, %r11
nop
nop
inc %r13
movb (%r11), %cl
nop
nop
nop
add %rsi, %rsi
lea addresses_D_ht+0xa0c8, %r9
nop
cmp $3397, %rsi
movb (%r9), %cl
nop
nop
nop
xor $30145, %r15
lea addresses_UC_ht+0x54c8, %rsi
nop
nop
nop
nop
nop
cmp %rdi, %rdi
mov (%rsi), %r13
nop
nop
nop
nop
cmp $59095, %r11
lea addresses_D_ht+0xea68, %rsi
lea addresses_UC_ht+0x11dc8, %rdi
nop
nop
xor %rax, %rax
mov $105, %rcx
rep movsb
nop
nop
nop
nop
sub %r13, %r13
lea addresses_normal_ht+0x1bdc8, %r15
clflush (%r15)
nop
cmp %rdi, %rdi
mov $0x6162636465666768, %r11
movq %r11, %xmm7
vmovups %ymm7, (%r15)
nop
nop
nop
nop
and %rdi, %rdi
lea addresses_WC_ht+0x10168, %rsi
lea addresses_normal_ht+0x15dc8, %rdi
nop
nop
inc %r11
mov $67, %rcx
rep movsl
add %r13, %r13
lea addresses_UC_ht+0x5bc8, %r15
nop
nop
nop
cmp $23356, %rdi
mov $0x6162636465666768, %rsi
movq %rsi, (%r15)
cmp %rcx, %rcx
lea addresses_WT_ht+0x13398, %rsi
lea addresses_D_ht+0x159c8, %rdi
nop
nop
nop
nop
nop
and %r13, %r13
mov $88, %rcx
rep movsq
nop
nop
nop
and %r15, %r15
pop %rsi
pop %rdi
pop %rcx
pop %rax
pop %r9
pop %r15
pop %r13
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r13
push %r14
push %r15
push %rbp
push %rbx
push %rcx
push %rdi
// Store
lea addresses_UC+0x29c8, %r14
nop
nop
add $57547, %rbx
movw $0x5152, (%r14)
nop
nop
nop
add $12558, %r13
// Faulty Load
lea addresses_UC+0x139c8, %rdi
nop
nop
inc %r15
mov (%rdi), %rbx
lea oracles, %r15
and $0xff, %rbx
shlq $12, %rbx
mov (%r15,%rbx,1), %rbx
pop %rdi
pop %rcx
pop %rbx
pop %rbp
pop %r15
pop %r14
pop %r13
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_UC', 'AVXalign': False, 'congruent': 0, 'size': 8, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC', 'AVXalign': False, 'congruent': 10, 'size': 2, 'same': False, 'NT': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_UC', 'AVXalign': False, 'congruent': 0, 'size': 8, 'same': True, 'NT': False}}
<gen_prepare_buffer>
{'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 10, 'size': 4, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 8, 'same': True}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 7, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 2, 'size': 1, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'AVXalign': False, 'congruent': 6, 'size': 1, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 8, 'size': 8, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 5, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 10, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'AVXalign': False, 'congruent': 10, 'size': 32, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 4, 'same': True}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 4, 'same': True}}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 7, 'size': 8, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 2, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 9, 'same': False}}
{'52': 21827, 'ff': 2}
52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52
*/
|
//////////////////////////////////////////////////////////////////////////////
/// Copyright 2003 and onward LASMEA UMR 6602 CNRS/U.B.P Clermont-Ferrand
/// Copyright 2009 and onward LRI UMR 8623 CNRS/Univ Paris Sud XI
///
/// Distributed under the Boost Software License, Version 1.0
/// See accompanying file LICENSE.txt or copy at
/// http://www.boost.org/LICENSE_1_0.txt
//////////////////////////////////////////////////////////////////////////////
#ifndef NT2_TOOLBOX_CRLIBM_FUNCTION_SIMD_SSE_SSE4_2_LOG2_RU_HPP_INCLUDED
#define NT2_TOOLBOX_CRLIBM_FUNCTION_SIMD_SSE_SSE4_2_LOG2_RU_HPP_INCLUDED
#include <nt2/toolbox/crlibm/function/simd/sse/sse4_1/log2_ru.hpp>
#endif
|
global _start
section .data
%include "header.inc"
mov eax, foo
call eax
foo:
xor eax, eax
; clear stack (pushed eip is not the same between vm and gdb execution)
mov dword [esp], 0
%include "footer.inc"
|
; hardware.asm
*pragmapush list ; Save state of list pragma
pragma nolist ; Turn off assembly listing and exclude from symbol list
ifndef HARDWARE_MACROS ; Load defines only once
; make sure defines are included
ifndef SAM_DEFS
include ../defines/sam-defs.asm
endc
enable_normal_speed macro
sta NORMAL_SPEED_MODE
endm
enable_high_speed macro
sta HIGH_SPEED_MODE
endm
enable_rom_mode macro
sta ROM_MODE_ENABLE
endm
enable_ram_mode macro
sta RAM_MODE_ENABLE
endm
HARDWARE_MACROS equ 1 ; Set flag for defines being loaded
endc
*pragmapop list ; restore assembly listing to previous state
|
; int __CALLEE__ ioctl_callee(int fd, int request, int arg)
; 06.2008 aralbrec
XLIB ioctl_callee
XDEF ASMDISP_IOCTL_CALLEE
LIB stdio_error_mc, stdio_error_ebadf_mc
LIB l_jpix, stdio_fdcommon1
INCLUDE "../stdio.def"
.ioctl_callee
pop hl
pop bc
pop de
ex (sp),hl
.asmentry
; send a driver-specific control message
;
; enter : bc = int arg
; de = int request
; l = int fd
; exit : hl = return value, carry reset if success
; hl = -1, carry set if fail
call stdio_fdcommon1 ; ix = fdstruct *
jp c, stdio_error_ebadf_mc ; problem with fd
ld a,STDIO_MSG_ICTL
call l_jpix
ret nc
jp stdio_error_mc
defc ASMDISP_IOCTL_CALLEE = asmentry - ioctl_callee
|
;Anim.asm
;Animation for object metasprites
;X = Object Slot #
;Y = new Animation id #
;Call this to change the animation id without causing bugs.
ChangeAnimation:
LDA #0
STA OBJ_ANIMTIMER, x
STA OBJ_ANIMFRAME, x
TYA
STA OBJ_ANIMATION, x
RTS
;X = Object Slot #
;This loads the correct Metasprite id for the current animation state.
AnimateObject:
FrameQ = TEMP_BYTE
AnimPtr = TEMP_PTR
LDA OBJ_ANIMATION, x
CMP #$FF
BNE .start
STA OBJ_METASPRITE, x ;Invalid (255) animation #, metasprite = 255
RTS
.start
;Loads Animation pointer A from table into AnimPtr
TZP16 AnimPtr, Animation_Table
.loadFrameQ
LDY #0
;Load animation data from pointer
LDA [AnimPtr], y
STA <FrameQ ;# of metasprite frames
INC16 AnimPtr
;Decides if current frame is maintained or there's a transition to next one
;OBJ_ANIMFRAME *MUST* start at 0 and only this subroutine can manipulate it,
; because frame # wraparound ( > FrameQ) is only checked when transitioning!
LDY OBJ_ANIMFRAME, x
.getCurFrame
LDA [AnimPtr], y
CMP OBJ_ANIMTIMER, x ;Is Timer limit >= Timer?
BCC .transition ;Timer exceeds or is equal to limit, set next frame.
BEQ .transition
JMP .updateMetasprite ;Timer doesn't exceed limit, keep current frame #.
.transition:
INY
CPY <FrameQ
BCC .transition2 ;No overflow
LDY #0 ;Overflow = wraparound to zero
.transition2
TYA
STA OBJ_ANIMFRAME, x ;Store updated frame #.
LDA #0
STA OBJ_ANIMTIMER, x ;Clear timer.
.updateMetasprite:
TYA ;Y = frame #.
CLC
ADC <FrameQ
TAY
LDA [AnimPtr], y ;Metasprite id for the current anim. frame
STA OBJ_METASPRITE, x ;Error in timer or animation table entry
RTS
;X = Object Slot #
;Timer stops at 255 (no overflow)
AnimTimer_Tick:
INC OBJ_ANIMTIMER, x
BEQ .overflow
RTS
.overflow
DEC OBJ_ANIMTIMER, x
RTS
|
// Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <chainparams.h>
#include <chainparamsseeds.h>
#include <consensus/merkle.h>
#include <tinyformat.h>
#include <util/system.h>
#include <util/strencodings.h>
#include <versionbitsinfo.h>
#include <assert.h>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesisOutputScript, uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
{
CMutableTransaction txNew;
txNew.nVersion = 1;
txNew.vin.resize(1);
txNew.vout.resize(1);
txNew.vin[0].scriptSig = CScript() << 486604799 << CScriptNum(4) << std::vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));
txNew.vout[0].nValue = genesisReward;
txNew.vout[0].scriptPubKey = genesisOutputScript;
CBlock genesis;
genesis.nTime = nTime;
genesis.nBits = nBits;
genesis.nNonce = nNonce;
genesis.nVersion = nVersion;
genesis.vtx.push_back(MakeTransactionRef(std::move(txNew)));
genesis.hashPrevBlock.SetNull();
genesis.hashMerkleRoot = BlockMerkleRoot(genesis);
return genesis;
}
/**
* Build the genesis block. Note that the output of its generation
* transaction cannot be spent since it did not originally exist in the
* database.
*
* CBlock(hash=000000000019d6, ver=1, hashPrevBlock=00000000000000, hashMerkleRoot=4a5e1e, nTime=1231006505, nBits=1d00ffff, nNonce=2083236893, vtx=1)
* CTransaction(hash=4a5e1e, ver=1, vin.size=1, vout.size=1, nLockTime=0)
* CTxIn(COutPoint(000000, -1), coinbase 04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73)
* CTxOut(nValue=50.00000000, scriptPubKey=0x5F1DF16B2B704C8A578D0B)
* vMerkleTree: 4a5e1e
*/
static CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
{
const char* pszTimestamp = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks";
const CScript genesisOutputScript = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
return CreateGenesisBlock(pszTimestamp, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward);
}
/**
* Main network
*/
class CMainParams : public CChainParams {
public:
CMainParams() {
strNetworkID = "main";
consensus.nSubsidyHalvingInterval = 210000;
consensus.BIP16Exception = uint256S("0x00000000000002dc756eebf4f49723ed8d30cc28a5f108eb94b1ba88ac4f9c22");
consensus.BIP34Height = 227931;
consensus.BIP34AssumedBits = 0x1a02816d;
consensus.BIP34Hash = uint256S("0x000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8");
consensus.BIP65Height = 388381; // 000000000000000004c2b624ed5d7756c508d90fd0da2c7c679febfa6c4735f0
consensus.BIP66Height = 363725; // 00000000000000000379eaa19dce8c9b722d46ae6a57c2f1a988119488b50931
consensus.CSVHeight = 419328; // 000000000000000004a1b34462cb8aeebd5799177f7a29cf28f2d1961716b5b5
consensus.SegwitHeight = 481824; // 0000000000000000001c8018d9cb3b742ef25114f27563e3fc4a1902167f9893
consensus.MinBIP9WarningHeight = 483840; // segwit activation height + miner confirmation window
consensus.powLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
consensus.nPowTargetSpacing = 10 * 60;
consensus.fPowAllowMinDifficultyBlocks = false;
consensus.fPowNoRetargeting = false;
consensus.nRuleChangeActivationThreshold = 1916; // 95% of 2016
consensus.nMinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 1199145601; // January 1, 2008
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1230767999; // December 31, 2008
// The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x000000000000000000000000000000000000000008ea3cf107ae0dec57f03fe8");
// By default assume that the signatures in ancestors of this block are valid.
consensus.defaultAssumeValid = uint256S("0x00000000000000000005f8920febd3925f8272a6a71237563d78c2edfdd09ddf"); // 597379
/**
* The message start string is designed to be unlikely to occur in normal data.
* The characters are rarely used upper ASCII, not valid as UTF-8, and produce
* a large 32-bit integer with any alignment.
*/
pchMessageStart[0] = 0xf9;
pchMessageStart[1] = 0xbe;
pchMessageStart[2] = 0xb4;
pchMessageStart[3] = 0xd9;
nDefaultPort = 8333;
nPruneAfterHeight = 100000;
m_assumed_blockchain_size = 280;
m_assumed_chain_state_size = 4;
genesis = CreateGenesisBlock(1231006505, 2083236893, 0x1d00ffff, 1, 50 * COIN);
consensus.hashGenesisBlock = genesis.GetHash();
assert(consensus.hashGenesisBlock == uint256S("0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"));
assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
// Note that of those which support the service bits prefix, most only support a subset of
// possible options.
// This is fine at runtime as we'll fall back to using them as a oneshot if they don't support the
// service bits we want, but we should get them updated to support all service bits wanted by any
// release ASAP to avoid it where possible.
vSeeds.emplace_back("seed.bitcoin.sipa.be"); // Pieter Wuille, only supports x1, x5, x9, and xd
vSeeds.emplace_back("dnsseed.bluematt.me"); // Matt Corallo, only supports x9
vSeeds.emplace_back("dnsseed.bitcoin.dashjr.org"); // Luke Dashjr
vSeeds.emplace_back("seed.bitcoinstats.com"); // Christian Decker, supports x1 - xf
vSeeds.emplace_back("seed.bitcoin.jonasschnelli.ch"); // Jonas Schnelli, only supports x1, x5, x9, and xd
vSeeds.emplace_back("seed.btc.petertodd.org"); // Peter Todd, only supports x1, x5, x9, and xd
vSeeds.emplace_back("seed.bitcoin.sprovoost.nl"); // Sjors Provoost
vSeeds.emplace_back("dnsseed.emzy.de"); // Stephan Oeste
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,0);
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,5);
base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1,128);
base58Prefixes[EXT_PUBLIC_KEY] = {0x04, 0x88, 0xB2, 0x1E};
base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x88, 0xAD, 0xE4};
bech32_hrp = "bc";
vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_main, pnSeed6_main + ARRAYLEN(pnSeed6_main));
fDefaultConsistencyChecks = false;
fRequireStandard = true;
m_is_test_chain = false;
checkpointData = {
{
{ 11111, uint256S("0x0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d")},
{ 33333, uint256S("0x000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6")},
{ 74000, uint256S("0x0000000000573993a3c9e41ce34471c079dcf5f52a0e824a81e7f953b8661a20")},
{105000, uint256S("0x00000000000291ce28027faea320c8d2b054b2e0fe44a773f3eefb151d6bdc97")},
{134444, uint256S("0x00000000000005b12ffd4cd315cd34ffd4a594f430ac814c91184a0d42d2b0fe")},
{168000, uint256S("0x000000000000099e61ea72015e79632f216fe6cb33d7899acb35b75c8303b763")},
{193000, uint256S("0x000000000000059f452a5f7340de6682a977387c17010ff6e6c3bd83ca8b1317")},
{210000, uint256S("0x000000000000048b95347e83192f69cf0366076336c639f9b7228e9ba171342e")},
{216116, uint256S("0x00000000000001b4f4b433e81ee46494af945cf96014816a4e2370f11b23df4e")},
{225430, uint256S("0x00000000000001c108384350f74090433e7fcf79a606b8e797f065b130575932")},
{250000, uint256S("0x000000000000003887df1f29024b06fc2200b55f8af8f35453d7be294df2d214")},
{279000, uint256S("0x0000000000000001ae8c72a0b0c301f67e3afca10e819efa9041e458e9bd7e40")},
{295000, uint256S("0x00000000000000004d9b4ef50f0f9d686fd69db2e03af35a100370c64632a983")},
}
};
chainTxData = ChainTxData{
// Data from RPC: getchaintxstats 4096 00000000000000000005f8920febd3925f8272a6a71237563d78c2edfdd09ddf
/* nTime */ 1569926786,
/* nTxCount */ 460596047,
/* dTxRate */ 3.77848885073875,
};
}
};
/**
* Testnet (v3)
*/
class CTestNetParams : public CChainParams {
public:
CTestNetParams() {
strNetworkID = "test";
consensus.nSubsidyHalvingInterval = 210000;
consensus.BIP16Exception = uint256S("0x00000000dd30457c001f4095d208cc1296b0eed002427aa599874af7a432b105");
consensus.BIP34Height = 21111;
consensus.BIP34Hash = uint256S("0x0000000023b3a96d3484e5abb3755c413e7d41500f8e2a5c3f0dd01299cd8ef8");
consensus.BIP65Height = 581885; // 00000000007f6655f22f98e72ed80d8b06dc761d5da09df0fa1dc4be4f861eb6
consensus.BIP66Height = 330776; // 000000002104c8c45e99a8853285a3b592602a3ccde2b832481da85e9e4ba182
consensus.CSVHeight = 770112; // 00000000025e930139bac5c6c31a403776da130831ab85be56578f3fa75369bb
consensus.SegwitHeight = 834624; // 00000000002b980fcd729daaa248fd9316a5200e9b367f4ff2c42453e84201ca
consensus.MinBIP9WarningHeight = 836640; // segwit activation height + miner confirmation window
consensus.powLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
consensus.nPowTargetSpacing = 10 * 60;
consensus.fPowAllowMinDifficultyBlocks = true;
consensus.fPowNoRetargeting = false;
consensus.nRuleChangeActivationThreshold = 1512; // 75% for testchains
consensus.nMinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 1199145601; // January 1, 2008
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1230767999; // December 31, 2008
// The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x00000000000000000000000000000000000000000000012b2a3a62424f21c918");
// By default assume that the signatures in ancestors of this block are valid.
consensus.defaultAssumeValid = uint256S("0x00000000000000b7ab6ce61eb6d571003fbe5fe892da4c9b740c49a07542462d"); // 1580000
pchMessageStart[0] = 0x0b;
pchMessageStart[1] = 0x11;
pchMessageStart[2] = 0x09;
pchMessageStart[3] = 0x07;
nDefaultPort = 18333;
nPruneAfterHeight = 1000;
m_assumed_blockchain_size = 30;
m_assumed_chain_state_size = 2;
genesis = CreateGenesisBlock(1296688602, 414098458, 0x1d00ffff, 1, 50 * COIN);
consensus.hashGenesisBlock = genesis.GetHash();
assert(consensus.hashGenesisBlock == uint256S("0x000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943"));
assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
vFixedSeeds.clear();
vSeeds.clear();
// nodes with support for servicebits filtering should be at the top
vSeeds.emplace_back("testnet-seed.bitcoin.jonasschnelli.ch");
vSeeds.emplace_back("seed.tbtc.petertodd.org");
vSeeds.emplace_back("seed.testnet.bitcoin.sprovoost.nl");
vSeeds.emplace_back("testnet-seed.bluematt.me"); // Just a static list of stable node(s), only supports x9
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,111);
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);
base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1,239);
base58Prefixes[EXT_PUBLIC_KEY] = {0x04, 0x35, 0x87, 0xCF};
base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x35, 0x83, 0x94};
bech32_hrp = "tb";
vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_test, pnSeed6_test + ARRAYLEN(pnSeed6_test));
fDefaultConsistencyChecks = false;
fRequireStandard = false;
m_is_test_chain = true;
checkpointData = {
{
{546, uint256S("000000002a936ca763904c3c35fce2f3556c559c0214345d31b1bcebf76acb70")},
}
};
chainTxData = ChainTxData{
// Data from RPC: getchaintxstats 4096 00000000000000b7ab6ce61eb6d571003fbe5fe892da4c9b740c49a07542462d
/* nTime */ 1569741320,
/* nTxCount */ 52318009,
/* dTxRate */ 0.1517002392872353,
};
}
};
/**
* Regression test
*/
class CRegTestParams : public CChainParams {
public:
explicit CRegTestParams(const ArgsManager& args) {
strNetworkID = "regtest";
consensus.nSubsidyHalvingInterval = 150;
consensus.BIP16Exception = uint256();
consensus.BIP34Height = 500; // BIP34 activated on regtest (Used in functional tests)
consensus.BIP34Hash = uint256();
consensus.BIP65Height = 1351; // BIP65 activated on regtest (Used in functional tests)
consensus.BIP66Height = 1251; // BIP66 activated on regtest (Used in functional tests)
consensus.CSVHeight = 432; // CSV activated on regtest (Used in rpc activation tests)
consensus.SegwitHeight = 0; // SEGWIT is always activated on regtest unless overridden
consensus.MinBIP9WarningHeight = 0;
consensus.powLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
consensus.nPowTargetSpacing = 10 * 60;
consensus.fPowAllowMinDifficultyBlocks = true;
consensus.fPowNoRetargeting = true;
consensus.nRuleChangeActivationThreshold = 108; // 75% for testchains
consensus.nMinerConfirmationWindow = 144; // Faster than normal for regtest (144 instead of 2016)
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 0;
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;
// The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x00");
// By default assume that the signatures in ancestors of this block are valid.
consensus.defaultAssumeValid = uint256S("0x00");
pchMessageStart[0] = 0xfa;
pchMessageStart[1] = 0xbf;
pchMessageStart[2] = 0xb5;
pchMessageStart[3] = 0xda;
nDefaultPort = 18444;
nPruneAfterHeight = 1000;
m_assumed_blockchain_size = 0;
m_assumed_chain_state_size = 0;
UpdateActivationParametersFromArgs(args);
genesis = CreateGenesisBlock(1296688602, 2, 0x207fffff, 1, 50 * COIN);
consensus.hashGenesisBlock = genesis.GetHash();
assert(consensus.hashGenesisBlock == uint256S("0x0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206"));
assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
vFixedSeeds.clear(); //!< Regtest mode doesn't have any fixed seeds.
vSeeds.clear(); //!< Regtest mode doesn't have any DNS seeds.
fDefaultConsistencyChecks = true;
fRequireStandard = true;
m_is_test_chain = true;
checkpointData = {
{
{0, uint256S("0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206")},
}
};
chainTxData = ChainTxData{
0,
0,
0
};
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,111);
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);
base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1,239);
base58Prefixes[EXT_PUBLIC_KEY] = {0x04, 0x35, 0x87, 0xCF};
base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x35, 0x83, 0x94};
bech32_hrp = "bcrt";
}
/**
* Allows modifying the Version Bits regtest parameters.
*/
void UpdateVersionBitsParameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout)
{
consensus.vDeployments[d].nStartTime = nStartTime;
consensus.vDeployments[d].nTimeout = nTimeout;
}
void UpdateActivationParametersFromArgs(const ArgsManager& args);
};
void CRegTestParams::UpdateActivationParametersFromArgs(const ArgsManager& args)
{
if (gArgs.IsArgSet("-segwitheight")) {
int64_t height = gArgs.GetArg("-segwitheight", consensus.SegwitHeight);
if (height < -1 || height >= std::numeric_limits<int>::max()) {
throw std::runtime_error(strprintf("Activation height %ld for segwit is out of valid range. Use -1 to disable segwit.", height));
} else if (height == -1) {
LogPrintf("Segwit disabled for testing\n");
height = std::numeric_limits<int>::max();
}
consensus.SegwitHeight = static_cast<int>(height);
}
if (!args.IsArgSet("-vbparams")) return;
for (const std::string& strDeployment : args.GetArgs("-vbparams")) {
std::vector<std::string> vDeploymentParams;
boost::split(vDeploymentParams, strDeployment, boost::is_any_of(":"));
if (vDeploymentParams.size() != 3) {
throw std::runtime_error("Version bits parameters malformed, expecting deployment:start:end");
}
int64_t nStartTime, nTimeout;
if (!ParseInt64(vDeploymentParams[1], &nStartTime)) {
throw std::runtime_error(strprintf("Invalid nStartTime (%s)", vDeploymentParams[1]));
}
if (!ParseInt64(vDeploymentParams[2], &nTimeout)) {
throw std::runtime_error(strprintf("Invalid nTimeout (%s)", vDeploymentParams[2]));
}
bool found = false;
for (int j=0; j < (int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++j) {
if (vDeploymentParams[0] == VersionBitsDeploymentInfo[j].name) {
UpdateVersionBitsParameters(Consensus::DeploymentPos(j), nStartTime, nTimeout);
found = true;
LogPrintf("Setting version bits activation parameters for %s to start=%ld, timeout=%ld\n", vDeploymentParams[0], nStartTime, nTimeout);
break;
}
}
if (!found) {
throw std::runtime_error(strprintf("Invalid deployment (%s)", vDeploymentParams[0]));
}
}
}
static std::unique_ptr<const CChainParams> globalChainParams;
const CChainParams &Params() {
assert(globalChainParams);
return *globalChainParams;
}
std::unique_ptr<const CChainParams> CreateChainParams(const std::string& chain)
{
if (chain == CBaseChainParams::MAIN)
return std::unique_ptr<CChainParams>(new CMainParams());
else if (chain == CBaseChainParams::TESTNET)
return std::unique_ptr<CChainParams>(new CTestNetParams());
else if (chain == CBaseChainParams::REGTEST)
return std::unique_ptr<CChainParams>(new CRegTestParams(gArgs));
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
}
void SelectParams(const std::string& network)
{
SelectBaseParams(network);
globalChainParams = CreateChainParams(network);
}
|
//-*****************************************************************************
//
// Copyright (c) 2009-2012,
// Sony Pictures Imageworks Inc. and
// Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Sony Pictures Imageworks, nor
// Industrial Light & Magic, nor the names of their 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 <Alembic/AbcCoreAbstract/All.h>
#include <Alembic/AbcCoreHDF5/All.h>
#include <Alembic/Util/All.h>
#include <Alembic/AbcCoreAbstract/Tests/Assert.h>
//-*****************************************************************************
namespace A5 = Alembic::AbcCoreHDF5;
namespace AbcA = Alembic::AbcCoreAbstract;
using namespace AbcA;
//-*****************************************************************************
void testProps()
{
Alembic::Util::int32_t intVal = 15;
float32_t f0 = 67.3f;
size_t floatArraySize = 14;
chrono_t t0 = 0.25;
chrono_t dt = 1.0 / 24.0;
DataType floatDT( kFloat32POD, 1 );
Dimensions dims( floatArraySize );
std::string archiveName = "constantPropsTest.abc";
std::vector<float32_t> fvals;
for ( size_t i = 0 ; i < floatArraySize ; i++ )
{
fvals.push_back( f0 + i );
}
{
A5::WriteArchive w;
ArchiveWriterPtr a = w(archiveName, AbcA::MetaData());
std::vector < chrono_t > samps(1, t0);
AbcA::TimeSampling ts(TimeSamplingType(dt), samps);
a->addTimeSampling(ts);
ObjectWriterPtr top = a->getTop();
ObjectWriterPtr child = top->createChild(
ObjectHeader( "wow", MetaData() ) );
CompoundPropertyWriterPtr props = child->getProperties();
ScalarPropertyWriterPtr intProp = props->createScalarProperty("intProp",
MetaData(), DataType( kInt32POD, 1 ), 1);
ArrayPropertyWriterPtr floatArrayProp = props->createArrayProperty(
"floatArrayProp", MetaData(), DataType( kFloat32POD, 1 ), 1);
intProp->setSample( &intVal );
for ( size_t i = 0 ; i < 500 ; i++ )
{
floatArrayProp->setSample(ArraySample( &(fvals.front()), floatDT,
dims ) );
}
}
{
A5::ReadArchive r;
ArchiveReaderPtr a = r( archiveName );
ObjectReaderPtr top = a->getTop();
TESTING_ASSERT( top->getNumChildren() == 1 );
AbcA::ObjectReaderPtr child = top->getChild(0);
TESTING_ASSERT( child->getName() == "wow" );
CompoundPropertyReaderPtr props = child->getProperties();
TESTING_ASSERT( props->getNumProperties() == 2 );
ScalarPropertyReaderPtr intProp = props->getScalarProperty( "intProp" );
TESTING_ASSERT( intProp->isConstant() );
TESTING_ASSERT( intProp->getNumSamples() == 1 );
ArrayPropertyReaderPtr floatArrayProp = \
props->getArrayProperty( "floatArrayProp" );
TESTING_ASSERT( floatArrayProp->getNumSamples() == 500 );
TESTING_ASSERT( floatArrayProp->isConstant() );
}
}
int main ( int argc, char *argv[] )
{
testProps();
return 0;
}
|
; sprite ids
; OverworldSprites indexes (see data/sprites/sprites.asm)
const_def
const SPRITE_NONE ; 00
const SPRITE_CHRIS ; 01
const SPRITE_CHRIS_BIKE ; 02
const SPRITE_GAMEBOY_KID ; 03
const SPRITE_SILVER ; 04
const SPRITE_OAK ; 05
const SPRITE_RED ; 06
const SPRITE_BLUE ; 07
const SPRITE_BILL ; 08
const SPRITE_ELDER ; 09
const SPRITE_JANINE ; 0a
const SPRITE_KURT ; 0b
const SPRITE_MOM ; 0c
const SPRITE_BLAINE ; 0d
const SPRITE_REDS_MOM ; 0e
const SPRITE_DAISY ; 0f
const SPRITE_ELM ; 10
const SPRITE_WILL ; 11
const SPRITE_FALKNER ; 12
const SPRITE_WHITNEY ; 13
const SPRITE_BUGSY ; 14
const SPRITE_MORTY ; 15
const SPRITE_CHUCK ; 16
const SPRITE_JASMINE ; 17
const SPRITE_PRYCE ; 18
const SPRITE_CLAIR ; 19
const SPRITE_BROCK ; 1a
const SPRITE_KAREN ; 1b
const SPRITE_BRUNO ; 1c
const SPRITE_MISTY ; 1d
const SPRITE_LANCE ; 1e
const SPRITE_SURGE ; 1f
const SPRITE_ERIKA ; 20
const SPRITE_KOGA ; 21
const SPRITE_SABRINA ; 22
const SPRITE_COOLTRAINER_M ; 23
const SPRITE_COOLTRAINER_F ; 24
const SPRITE_BUG_CATCHER ; 25
const SPRITE_TWIN ; 26
const SPRITE_YOUNGSTER ; 27
const SPRITE_LASS ; 28
const SPRITE_TEACHER ; 29
const SPRITE_BUENA ; 2a
const SPRITE_SUPER_NERD ; 2b
const SPRITE_ROCKER ; 2c
const SPRITE_POKEFAN_M ; 2d
const SPRITE_POKEFAN_F ; 2e
const SPRITE_GRAMPS ; 2f
const SPRITE_GRANNY ; 30
const SPRITE_SWIMMER_GUY ; 31
const SPRITE_SWIMMER_GIRL ; 32
const SPRITE_BIG_SNORLAX ; 33
const SPRITE_SURFING_PIKACHU ; 34
const SPRITE_ROCKET ; 35
const SPRITE_ROCKET_GIRL ; 36
const SPRITE_NURSE ; 37
const SPRITE_LINK_RECEPTIONIST ; 38
const SPRITE_CLERK ; 39
const SPRITE_FISHER ; 3a
const SPRITE_FISHING_GURU ; 3b
const SPRITE_SCIENTIST ; 3c
const SPRITE_KIMONO_GIRL ; 3d
const SPRITE_SAGE ; 3e
const SPRITE_UNUSED_GUY ; 3f
const SPRITE_GENTLEMAN ; 40
const SPRITE_BLACK_BELT ; 41
const SPRITE_RECEPTIONIST ; 42
const SPRITE_OFFICER ; 43
const SPRITE_CAL ; 44
const SPRITE_SLOWPOKE ; 45
const SPRITE_CAPTAIN ; 46
const SPRITE_BIG_LAPRAS ; 47
const SPRITE_GYM_GUY ; 48
const SPRITE_SAILOR ; 49
const SPRITE_BIKER ; 4a
const SPRITE_PHARMACIST ; 4b
const SPRITE_MONSTER ; 4c
const SPRITE_FAIRY ; 4d
const SPRITE_BIRD ; 4e
const SPRITE_DRAGON ; 4f
const SPRITE_BIG_ONIX ; 50
const SPRITE_N64 ; 51
const SPRITE_SUDOWOODO ; 52
const SPRITE_SURF ; 53
const SPRITE_POKE_BALL ; 54
const SPRITE_POKEDEX ; 55
const SPRITE_PAPER ; 56
const SPRITE_VIRTUAL_BOY ; 57
const SPRITE_OLD_LINK_RECEPTIONIST ; 58
const SPRITE_ROCK ; 59
const SPRITE_BOULDER ; 5a
const SPRITE_SNES ; 5b
const SPRITE_FAMICOM ; 5c
const SPRITE_FRUIT_TREE ; 5d
const SPRITE_GOLD_TROPHY ; 5e
const SPRITE_SILVER_TROPHY ; 5f
const SPRITE_KRIS ; 60
const SPRITE_KRIS_BIKE ; 61
const SPRITE_KURT_OUTSIDE ; 62
const SPRITE_SUICUNE ; 63
const SPRITE_ENTEI ; 64
const SPRITE_RAIKOU ; 65
const SPRITE_STANDING_YOUNGSTER ; 66
; SpriteMons indexes (see data/sprites/sprite_mons.asm)
const_def $80
SPRITE_POKEMON EQU const_value
const SPRITE_UNOWN ; 80
const SPRITE_GEODUDE ; 81
const SPRITE_GROWLITHE ; 82
const SPRITE_WEEDLE ; 83
const SPRITE_SHELLDER ; 84
const SPRITE_ODDISH ; 85
const SPRITE_GENGAR ; 86
const SPRITE_ZUBAT ; 87
const SPRITE_MAGIKARP ; 88
const SPRITE_SQUIRTLE ; 89
const SPRITE_TOGEPI ; 8a
const SPRITE_BUTTERFREE ; 8b
const SPRITE_DIGLETT ; 8c
const SPRITE_POLIWAG ; 8d
const SPRITE_PIKACHU ; 8e
const SPRITE_CLEFAIRY ; 8f
const SPRITE_CHARMANDER ; 90
const SPRITE_JYNX ; 91
const SPRITE_STARMIE ; 92
const SPRITE_BULBASAUR ; 93
const SPRITE_JIGGLYPUFF ; 94
const SPRITE_GRIMER ; 95
const SPRITE_EKANS ; 96
const SPRITE_PARAS ; 97
const SPRITE_TENTACOOL ; 98
const SPRITE_TAUROS ; 99
const SPRITE_MACHOP ; 9a
const SPRITE_VOLTORB ; 9b
const SPRITE_LAPRAS ; 9c
const SPRITE_RHYDON ; 9d
const SPRITE_MOLTRES ; 9e
const SPRITE_SNORLAX ; 9f
const SPRITE_GYARADOS ; a0
const SPRITE_LUGIA ; a1
const SPRITE_HO_OH ; a2
; special GetMonSprite values (see engine/overworld/overworld.asm)
const_def $e0
const SPRITE_DAY_CARE_MON_1 ; e0
const SPRITE_DAY_CARE_MON_2 ; e1
; wVariableSprites indexes (see wram.asm)
const_def $f0
SPRITE_VARS EQU const_value
const SPRITE_CONSOLE ; f0
const SPRITE_DOLL_1 ; f1
const SPRITE_DOLL_2 ; f2
const SPRITE_BIG_DOLL ; f3
const SPRITE_WEIRD_TREE ; f4
const SPRITE_OLIVINE_RIVAL ; f5
const SPRITE_AZALEA_ROCKET ; f6
const SPRITE_FUCHSIA_GYM_1 ; f7
const SPRITE_FUCHSIA_GYM_2 ; f8
const SPRITE_FUCHSIA_GYM_3 ; f9
const SPRITE_FUCHSIA_GYM_4 ; fa
const SPRITE_COPYCAT ; fb
const SPRITE_JANINE_IMPERSONATOR ; fc
|
//------------------------------------------------------------------------------
// SystemTest_Propagate
//------------------------------------------------------------------------------
// GMAT: General Mission Analysis Tool
//
// Author: Wendy Shoan
// Created: 2016.05.31
//
/**
* System tester for propagation
*/
//------------------------------------------------------------------------------
#include <iostream>
#include <string>
#include <ctime>
#include <cmath>
#include "gmatdefs.hpp"
#include "GmatConstants.hpp"
#include "Rvector6.hpp"
#include "Rvector3.hpp"
#include "Rmatrix.hpp"
#include "RealUtilities.hpp"
#include "MessageInterface.hpp"
#include "ConsoleMessageReceiver.hpp"
#include "AbsoluteDate.hpp"
#include "Spacecraft.hpp"
#include "Earth.hpp"
#include "KeyValueStatistics.hpp"
#include "VisiblePOIReport.hpp"
#include "OrbitState.hpp"
#include "PointGroup.hpp"
#include "Propagator.hpp"
#include "ConicalSensor.hpp"
#include "CoverageChecker.hpp"
#include "TimeTypes.hpp"
using namespace std;
using namespace GmatMathUtil;
using namespace GmatMathConstants;
//------------------------------------------------------------------------------
// int main(int argc, char *argv[])
//------------------------------------------------------------------------------
int main(int argc, char *argv[])
{
std::string outFormat = "%16.9f ";
Real tolerance = 1e-15;
ConsoleMessageReceiver *consoleMsg = ConsoleMessageReceiver::Instance();
MessageInterface::SetMessageReceiver(consoleMsg);
std::string outPath = "./";
MessageInterface::SetLogFile(outPath + "GmatLog.txt");
MessageInterface::ShowMessage("%s\n",
GmatTimeUtil::FormatCurrentTime().c_str());
// Set global format setting
GmatGlobal *global = GmatGlobal::Instance();
global->SetActualFormat(false, false, 16, 1, false);
char *buffer = NULL;
buffer = getenv("OS");
if (buffer != NULL)
{
MessageInterface::ShowMessage("Current OS is %s\n", buffer);
}
else
{
MessageInterface::ShowMessage("Buffer is NULL\n");
}
MessageInterface::ShowMessage("*** START TEST ***\n");
AbsoluteDate *date = NULL;
OrbitState *state = NULL;
Spacecraft *sat1 = NULL;
Real initialJD = 2457473.00;
Real SMA = 6500;
Real ECC = 0.002;
Real INC = 45.0*RAD_PER_DEG;
Real RAAN = 75.0*RAD_PER_DEG;
Real AOP = 10.0*RAD_PER_DEG;
Real TA = 270.0*RAD_PER_DEG;
try
{
// Test the PointGroup
MessageInterface::ShowMessage("*** TEST*** Propagate!!!!\n");
clock_t t0 = clock();
for (Integer ii = 0; ii < 1; ii++)
{
// Create the epoch object and set the initial epoch
date = new AbsoluteDate();
date->SetJulianDate(initialJD);
MessageInterface::ShowMessage("--- date created\n");
// Create the spacecraft state object and set Keplerian elements
state = new OrbitState();
state->SetKeplerianState(SMA, ECC, INC, RAAN, AOP, TA);
MessageInterface::ShowMessage("--- state created\n");
// Create a spacecraft giving it a state and epoch
sat1 = new Spacecraft(date,state);
MessageInterface::ShowMessage("--- spacecraft created\n");
// Create the propagator
Propagator prop(sat1);
MessageInterface::ShowMessage("--- propagator created\n");
// Propagate for a duration and collect data
// Real startDate = date.GetJulianDate();
// MessageInterface::ShowMessage("Before propagation, julian date = %12.10f\n",
// startDate);
// Integer count = 0;
for (Integer stepIdx = 0; stepIdx < 86400/60; stepIdx++) // = 1:86400/60
{
// Propagate
date->Advance(60.0);
// MessageInterface::ShowMessage("In iteration %d, julian date = %12.10f\n",
// stepIdx, date.GetJulianDate());
prop.Propagate(*date);
}
}
Real timeSpent = ((Real) (clock() - t0)) / CLOCKS_PER_SEC;
MessageInterface::ShowMessage("TIME SPENT in 20 iterations is %12.10f seconds\n",
timeSpent);
// Comparison against truth below this line
OrbitState *orbState = sat1->GetOrbitState();
// AbsoluteDate orbEpoch = sat1.GetOrbitEpoch();
// Real jDate = orbEpoch.GetJulianDate();
// Rvector6 gregDate = orbEpoch.GetGregorianDate();
Rvector6 kepState = orbState->GetKeplerianState();
for (Integer ii = 2; ii < 6; ii++)
kepState(ii) *= DEG_PER_RAD;
//This is generated by this propagator but agrees very well with STK J2
// analytic propagator
Rvector6 truthData(6500.0,0.002, 45.0,
68.4059136572242, 16.9940847530552, 116.731954192478);
bool errorInProp = false;
for (Integer ii = 0; ii < 6; ii++)
{
// MessageInterface::ShowMessage(" kepState(%d) = %12.10f\n",
// ii, kepState(ii));
// MessageInterface::ShowMessage(" truthData(%d) = %12.10f\n",
// ii, truthData(ii));
if (Abs(kepState(ii) - truthData(ii)) > 1.0e-9)
{
errorInProp = true;
MessageInterface::ShowMessage("Error in J2 Analytic Propagation!\n");
MessageInterface::ShowMessage("Truth Component %16.12f\n", truthData[ii]);
MessageInterface::ShowMessage("Result Component %16.12f\n", kepState[ii]);
}
}
if (!errorInProp)
MessageInterface::ShowMessage("OK - J2 propagation is OK!!!\n");
MessageInterface::ShowMessage("Truth SMA %12.10f\n", truthData[0]);
MessageInterface::ShowMessage("Truth ECC %12.10f\n", truthData[1]);
MessageInterface::ShowMessage("Truth INC %12.10f\n", truthData[2] );
MessageInterface::ShowMessage("Truth RAAN %12.10f\n", truthData[3]);
MessageInterface::ShowMessage("Truth AOP %12.10f\n", truthData[4]);
MessageInterface::ShowMessage("Truth TA %12.10f\n", truthData[5]);
MessageInterface::ShowMessage("Result SMA %12.10f\n", kepState[0]);
MessageInterface::ShowMessage("Result ECC %12.10f\n", kepState[1]);
MessageInterface::ShowMessage("Result INC %12.10f\n", kepState[2]);
MessageInterface::ShowMessage("Result RAAN %12.10f\n", kepState[3]);
MessageInterface::ShowMessage("Result AOP %12.10f\n", kepState[4]);
MessageInterface::ShowMessage("Result TA %12.10f\n", kepState[5]);
/// ---------------------------------------------------------------------
/// Now test propgation with drag included
/// ---------------------------------------------------------------------
AbsoluteDate *date2 = NULL;
OrbitState *state2 = NULL;
Spacecraft *sat2 = NULL;
date2 = new AbsoluteDate();
date2->SetJulianDate(initialJD);
state2 = new OrbitState();
state2->SetKeplerianState(6700.0, ECC, 0.0, 0.0, 260.80535373076, 99.88774933207917);
// Create a spacecraft giving it a state and epoch
sat2 = new Spacecraft(date2, state2);
sat2->SetDragArea(2.55);
sat2->SetDragCoefficient(1.7);
sat2->SetTotalMass(124);
Propagator prop2(sat2);
prop2.SetApplyDrag(true);
//date->Advance(272881.85875455);
//prop2.Propagate(*date);
for (Integer stepIdx = 0; stepIdx < 2274; stepIdx++) // = 1:86400/60
{
date2->Advance(120.0);
prop2.Propagate(*date2);
}
orbState = sat2->GetOrbitState();
kepState = orbState->GetKeplerianState();
for (Integer ii = 2; ii < 6; ii++)
kepState(ii) *= DEG_PER_RAD;
MessageInterface::ShowMessage("Drag Propagation Results!\n");
MessageInterface::ShowMessage("Result SMA %12.10f\n", kepState[0]);
MessageInterface::ShowMessage("Result ECC %12.10f\n", kepState[1]);
MessageInterface::ShowMessage("Result INC %12.10f\n", kepState[2]);
MessageInterface::ShowMessage("Result RAAN %12.10f\n", kepState[3]);
MessageInterface::ShowMessage("Result AOP %12.10f\n", kepState[4]);
MessageInterface::ShowMessage("Result TA %12.10f\n", kepState[5]);
cout << endl;
cout << "Hit enter to end" << endl;
cin.get();
delete date, date2;
delete state, state2;
delete sat1, sat2;
MessageInterface::ShowMessage("*** END TEST ***\n");
}
catch (BaseException &be)
{
MessageInterface::ShowMessage("Exception caught: %s\n", be.GetFullMessage().c_str());
}
}
|
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (C) 2019-2021, LAAS-CNRS, University of Edinburgh
// Copyright note valid unless otherwise stated in individual files.
// All rights reserved.
///////////////////////////////////////////////////////////////////////////////
#ifndef CROCODDYL_CORE_SOLVER_BASE_HPP_
#define CROCODDYL_CORE_SOLVER_BASE_HPP_
#include <vector>
#include "crocoddyl/core/optctrl/shooting.hpp"
#include "crocoddyl/core/utils/stop-watch.hpp"
namespace crocoddyl {
class CallbackAbstract; // forward declaration
static std::vector<Eigen::VectorXd> DEFAULT_VECTOR;
/**
* @brief Abstract class for optimal control solvers
*
* A solver resolves an optimal control solver of the form
* \f{eqnarray*}{
* \begin{Bmatrix}
* \mathbf{x}^*_0,\cdots,\mathbf{x}^*_{T} \\
* \mathbf{u}^*_0,\cdots,\mathbf{u}^*_{T-1}
* \end{Bmatrix} =
* \arg\min_{\mathbf{x}_s,\mathbf{u}_s} && l_T (\mathbf{x}_T) + \sum_{k=0}^{T-1} l_k(\mathbf{x}_t,\mathbf{u}_t) \\
* \operatorname{subject}\,\operatorname{to} && \mathbf{x}_0 = \mathbf{\tilde{x}}_0\\
* && \mathbf{x}_{k+1} = \mathbf{f}_k(\mathbf{x}_k,\mathbf{u}_k)\\
* && \mathbf{x}_k\in\mathcal{X}, \mathbf{u}_k\in\mathcal{U}
* \f}
* where \f$l_T(\mathbf{x}_T)\f$, \f$l_k(\mathbf{x}_t,\mathbf{u}_t)\f$ are the terminal and running cost functions,
* respectively, \f$\mathbf{f}_k(\mathbf{x}_k,\mathbf{u}_k)\f$ describes evolution of the system, and state and
* control admissible sets are defined by \f$\mathbf{x}_k\in\mathcal{X}\f$, \f$\mathbf{u}_k\in\mathcal{U}\f$.
* An action model, defined in the shooting problem, describes each node \f$k\f$. Inside the action model, we
* specialize the cost functions, the system evolution and the admissible sets.
*
* The main routines are `computeDirection()` and `tryStep()`. The former finds a search direction and typically
* computes the derivatives of each action model. The latter rollout the dynamics and cost (i.e., the action)
* to try the search direction found by `computeDirection`. Both functions used the current guess defined by
* `setCandidate()`. Finally, `solve()` function is used to define when the search direction and length are
* computed in each iterate. It also describes the globalization strategy (i.e., regularization) of the
* numerical optimization.
*
* \sa `solve()`, `computeDirection()`, `tryStep()`, `stoppingCriteria()`
*/
class SolverAbstract {
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
/**
* @brief Initialize the solver
*
* @param[in] problem shooting problem
*/
explicit SolverAbstract(boost::shared_ptr<ShootingProblem> problem);
virtual ~SolverAbstract();
/**
* @brief Compute the optimal trajectory \f$\mathbf{x}^*_s,\mathbf{u}^*_s\f$ as lists of \f$T+1\f$ and \f$T\f$ terms
*
* From an initial guess \p init_xs, \p init_us (feasible or not), iterate over `computeDirection()` and `tryStep()`
* until `stoppingCriteria()` is below threshold. It also describes the globalization strategy used during the
* numerical optimization.
*
* @param[in] init_xs initial guess for state trajectory with \f$T+1\f$ elements (default [])
* @param[in] init_us initial guess for control trajectory with \f$T\f$ elements (default [])
* @param[in] maxiter maximum allowed number of iterations (default 100)
* @param[in] isFeasible true if the \p init_xs are obtained from integrating the \p init_us (rollout) (default
* false)
* @param[in] regInit initial guess for the regularization value. Very low values are typical used with very
* good guess points (init_xs, init_us)
* @return A boolean that describes if convergence was reached.
*/
virtual bool solve(const std::vector<Eigen::VectorXd>& init_xs = DEFAULT_VECTOR,
const std::vector<Eigen::VectorXd>& init_us = DEFAULT_VECTOR, const std::size_t maxiter = 100,
const bool is_feasible = false, const double reg_init = 1e-9) = 0;
/**
* @brief Compute the search direction \f$(\delta\mathbf{x}^k,\delta\mathbf{u}^k)\f$ for the current guess
* \f$(\mathbf{x}^k_s,\mathbf{u}^k_s)\f$.
*
* You must call `setCandidate()` first in order to define the current guess. A current guess defines a state
* and control trajectory \f$(\mathbf{x}^k_s,\mathbf{u}^k_s)\f$ of \f$T+1\f$ and \f$T\f$ elements, respectively.
*
* @param[in] recalc true for recalculating the derivatives at current state and control
* @return The search direction \f$(\delta\mathbf{x},\delta\mathbf{u})\f$ and the dual lambdas as lists of
* \f$T+1\f$, \f$T\f$ and \f$T+1\f$ lengths, respectively
*/
virtual void computeDirection(const bool recalc) = 0;
/**
* @brief Try a predefined step length \f$\alpha\f$ and compute its cost improvement \f$dV\f$.
*
* It uses the search direction found by `computeDirection()` to try a determined step length \f$\alpha\f$.
* Therefore, it assumes that we have run `computeDirection()` first. Additionally, it returns the cost improvement
* \f$dV\f$ along the predefined step length \f$\alpha\f$.
*
* @param[in] steplength applied step length (\f$0\leq\alpha\leq1\f$)
* @return the cost improvement
*/
virtual double tryStep(const double steplength = 1) = 0;
/**
* @brief Return a positive value that quantifies the algorithm termination
*
* These values typically represents the gradient norm which tell us that it's been reached the local minima.
* The stopping criteria strictly speaking depends on the search direction (calculated by `computeDirection()`) but
* it could also depend on the chosen step length, tested by `tryStep()`.
*/
virtual double stoppingCriteria() = 0;
/**
* @brief Return the expected improvement \f$dV_{exp}\f$ from a given current search direction
* \f$(\delta\mathbf{x}^k,\delta\mathbf{u}^k)\f$
*
* For computing the expected improvement, you need to compute the search direction first via `computeDirection()`.
*/
virtual const Eigen::Vector2d& expectedImprovement() = 0;
/**
* @brief Resizing the solver data
*
* If the shooting problem has changed after construction, then this function resizes all the data before starting
* resolve the problem.
*/
virtual void resizeData();
/**
* @brief Compute the dynamic feasibility \f$\|\mathbf{f}_{\mathbf{s}}\|_{\infty,1}\f$ for
* the current guess \f$(\mathbf{x}^k,\mathbf{u}^k)\f$
*
* The feasibility can be computed using the computed using the \f$\ell_\infty\f$ and \f$\ell_1\f$ norms.
* By default we use the \f$\ell_\infty\f$ norm; however, we can use the \f$\ell_1\f$ norm via `set_inffeas()`.
* Note that \f$\mathbf{f}_{\mathbf{s}}\f$ are the gaps on the dynamics, which are computed at each node as
* \f$\mathbf{x}^{'}-\mathbf{f}(\mathbf{x},\mathbf{u})\f$.
*/
double computeDynamicFeasibility();
/**
* @brief Set the solver candidate trajectories \f$(\mathbf{x}_s,\mathbf{u}_s)\f$
*
* The solver candidates are defined as a state and control trajectories \f$(\mathbf{x}_s,\mathbf{u}_s)\f$ of
* \f$T+1\f$ and \f$T\f$ elements, respectively. Additionally, we need to define the dynamic feasibility of the
* \f$(\mathbf{x}_s,\mathbf{u}_s)\f$ pair. Note that the trajectories are feasible if \f$\mathbf{x}_s\f$ is the
* resulting trajectory from the system rollout with \f$\mathbf{u}_s\f$ inputs.
*
* @param[in] xs state trajectory of \f$T+1\f$ elements (default [])
* @param[in] us control trajectory of \f$T\f$ elements (default [])
* @param[in] isFeasible true if the \p xs are obtained from integrating the \p us (rollout)
*/
void setCandidate(const std::vector<Eigen::VectorXd>& xs_warm = DEFAULT_VECTOR,
const std::vector<Eigen::VectorXd>& us_warm = DEFAULT_VECTOR, const bool is_feasible = false);
/**
* @brief Set a list of callback functions using for the solver diagnostic
*
* Each iteration, the solver calls these set of functions in order to allowed user the diagnostic of its
* performance.
*
* @param callbacks set of callback functions
*/
void setCallbacks(const std::vector<boost::shared_ptr<CallbackAbstract> >& callbacks);
/**
* @brief Return the list of callback functions using for diagnostic
*/
const std::vector<boost::shared_ptr<CallbackAbstract> >& getCallbacks() const;
/**
* @brief Return the shooting problem
*/
const boost::shared_ptr<ShootingProblem>& get_problem() const;
/**
* @brief Return the state trajectory \f$\mathbf{x}_s\f$
*/
const std::vector<Eigen::VectorXd>& get_xs() const;
/**
* @brief Return the control trajectory \f$\mathbf{u}_s\f$
*/
const std::vector<Eigen::VectorXd>& get_us() const;
/**
* @brief Return the gaps \f$\mathbf{f}_{s}\f$
*/
const std::vector<Eigen::VectorXd>& get_fs() const;
/**
* @brief Return the feasibility status of the \f$(\mathbf{x}_s,\mathbf{u}_s)\f$ trajectory
*/
bool get_is_feasible() const;
/**
* @brief Return the total cost
*/
double get_cost() const;
/**
* @brief Return the value computed by `stoppingCriteria()`
*/
double get_stop() const;
/**
* @brief Return the LQ approximation of the expected improvement
*/
const Eigen::Vector2d& get_d() const;
/**
* @brief Return the state regularization value
*/
double get_xreg() const;
/**
* @brief Return the control regularization value
*/
double get_ureg() const;
/**
* @brief Return the step length \f$\alpha\f$
*/
double get_steplength() const;
/**
* @brief Return the cost reduction \f$dV\f$
*/
double get_dV() const;
/**
* @brief Return the expected cost reduction \f$dV_{exp}\f$
*/
double get_dVexp() const;
/**
* @brief Return the threshold used for accepting a step
*/
double get_th_acceptstep() const;
/**
* @brief Return the tolerance for stopping the algorithm
*/
double get_th_stop() const;
/**
* @brief Return the number of iterations performed by the solver
*/
std::size_t get_iter() const;
/**
* @brief Return the threshold for accepting a gap as non-zero
*/
double get_th_gaptol() const;
/**
* @brief Return the feasibility of the dynamic constraints \f$\|\mathbf{f}_{\mathbf{s}}\|_{\infty,1}\f$ of the
* current guess
*/
double get_ffeas() const;
/**
* @brief Return the norm used for the computing the feasibility (true for \f$\ell_\infty\f$, false for \f$\ell_1\f$)
*/
bool get_inffeas() const;
/**
* @brief Modify the state trajectory \f$\mathbf{x}_s\f$
*/
void set_xs(const std::vector<Eigen::VectorXd>& xs);
/**
* @brief Modify the control trajectory \f$\mathbf{u}_s\f$
*/
void set_us(const std::vector<Eigen::VectorXd>& us);
/**
* @brief Modify the state regularization value
*/
void set_xreg(const double xreg);
/**
* @brief Modify the control regularization value
*/
void set_ureg(const double ureg);
/**
* @brief Modify the threshold used for accepting step
*/
void set_th_acceptstep(const double th_acceptstep);
/**
* @brief Modify the tolerance for stopping the algorithm
*/
void set_th_stop(const double th_stop);
/**
* @brief Modify the threshold for accepting a gap as non-zero
*/
void set_th_gaptol(const double th_gaptol);
/**
* @brief Modify the current norm used for computed the feasibility
*/
void set_inffeas(const bool inffeas);
protected:
boost::shared_ptr<ShootingProblem> problem_; //!< optimal control problem
std::vector<Eigen::VectorXd> xs_; //!< State trajectory
std::vector<Eigen::VectorXd> us_; //!< Control trajectory
std::vector<Eigen::VectorXd> fs_; //!< Gaps/defects between shooting nodes
std::vector<boost::shared_ptr<CallbackAbstract> > callbacks_; //!< Callback functions
bool is_feasible_; //!< Label that indicates is the iteration is feasible
bool was_feasible_; //!< Label that indicates in the previous iterate was feasible
double cost_; //!< Total cost
double stop_; //!< Value computed by `stoppingCriteria()`
Eigen::Vector2d d_; //!< LQ approximation of the expected improvement
double xreg_; //!< Current state regularization value
double ureg_; //!< Current control regularization values
double steplength_; //!< Current applied step-length
double dV_; //!< Cost reduction obtained by `tryStep()`
double dVexp_; //!< Expected cost reduction
double th_acceptstep_; //!< Threshold used for accepting step
double th_stop_; //!< Tolerance for stopping the algorithm
std::size_t iter_; //!< Number of iteration performed by the solver
double th_gaptol_; //!< Threshold limit to check non-zero gaps
double ffeas_; //!< Feasibility of the dynamic constraints
bool inffeas_; //!< True indicates if we use l-inf norm for computing the feasibility, otherwise false represents
//!< the l-1 norm
double tmp_feas_; //!< Temporal variables used for computed the feasibility
};
/**
* @brief Abstract class for solver callbacks
*
* A callback is used to diagnostic the behaviour of our solver in each iteration of it. For instance, it can be used
* to print values, record data or display motions.
*/
class CallbackAbstract {
public:
/**
* @brief Initialize the callback function
*/
CallbackAbstract() {}
virtual ~CallbackAbstract() {}
/**
* @brief Run the callback function given a solver
*
* @param[in] solver solver to be diagnostic
*/
virtual void operator()(SolverAbstract& solver) = 0;
};
bool raiseIfNaN(const double value);
} // namespace crocoddyl
#endif // CROCODDYL_CORE_SOLVER_BASE_HPP_
|
; A100088: Expansion of (1-x^2)/((1-2x)(1+x^2)).
; 1,2,2,4,10,20,38,76,154,308,614,1228,2458,4916,9830,19660,39322,78644,157286,314572,629146,1258292,2516582,5033164,10066330,20132660,40265318,80530636,161061274,322122548,644245094,1288490188,2576980378
mov $1,1
mov $2,1
mov $5,1
lpb $0,1
sub $0,1
mov $1,$2
sub $3,$4
mov $4,$2
mov $2,$3
mov $3,$5
mul $5,2
lpe
add $1,$3
|
//===- Parser.cpp - Main dispatch module for the Parser library -----------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This library implements the functionality defined in llvm/AsmParser/Parser.h
//
//===----------------------------------------------------------------------===//
#include "llvm/AsmParser/Parser.h"
#include "LLParser.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/raw_ostream.h"
#include <cstring>
#include <system_error>
using namespace llvm;
bool llvm::parseAssemblyInto(MemoryBufferRef F, Module &M, SMDiagnostic &Err) {
SourceMgr SM;
std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(F, false);
SM.AddNewSourceBuffer(std::move(Buf), SMLoc());
return LLParser(F.getBuffer(), SM, Err, &M).Run();
}
std::unique_ptr<Module> llvm::parseAssembly(MemoryBufferRef F,
SMDiagnostic &Err,
LLVMContext &Context) {
std::unique_ptr<Module> M =
make_unique<Module>(F.getBufferIdentifier(), Context);
if (parseAssemblyInto(F, *M, Err))
return nullptr;
return std::move(M);
}
std::unique_ptr<Module> llvm::parseAssemblyFile(StringRef Filename,
SMDiagnostic &Err,
LLVMContext &Context) {
ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
MemoryBuffer::getFileOrSTDIN(Filename);
if (std::error_code EC = FileOrErr.getError()) {
Err = SMDiagnostic(Filename, SourceMgr::DK_Error,
"Could not open input file: " + EC.message());
return nullptr;
}
return parseAssembly(FileOrErr.get()->getMemBufferRef(), Err, Context);
}
std::unique_ptr<Module> llvm::parseAssemblyString(StringRef AsmString,
SMDiagnostic &Err,
LLVMContext &Context) {
MemoryBufferRef F(AsmString, "<string>");
return parseAssembly(F, Err, Context);
}
|
#pragma once
/* This code is a stripped down version of 'google/spherical-harmonics' on
* github to focus on spherical harmonics rotations using Eigen. This part
* of the code is release using the Apache license V2.0 (see [here][license])
*
* Modifications:
* + I added a new Apply interface to the Rotation class that takes Eigen
* vectors as input and outputs to perform efficient Matrix products.
* See Rotation::Apply(const Eigen::VectorXf&, Eigen::VectorXf&) const.
* + I changed all Eigen type to be 32b float instead of 64b.
*
* [license]: https://github.com/google/spherical-harmonics/blob/master/LICENSE
*/
// Include Eigen
#include <Eigen/Core>
#include <Eigen/Geometry>
// Include STL
#include <vector>
#include <memory>
template <class T>
using VectorX = Eigen::Matrix<T, Eigen::Dynamic, 1>;
// Get the total number of coefficients for a function represented by
// all spherical harmonic basis of degree <= @order (it is a point of
// confusion that the order of an SH refers to its degree and not the order).
constexpr int GetCoefficientCount(int order) {
return (order + 1) * (order + 1);
}
// Get the one dimensional index associated with a particular degree @l
// and order @m. This is the index that can be used to access the Coeffs
// returned by SHSolver.
constexpr int GetIndex(int l, int m) {
return l * (l + 1) + m;
}
// Usage: CHECK(bool, string message);
// Note that it must end a semi-colon, making it look like a
// valid C++ statement (hence the awkward do() while(false)).
#ifndef NDEBUG
# define CHECK(condition, message) \
do { \
if (!(condition)) { \
std::cerr << "Check failed (" #condition ") in " << __FILE__ \
<< ":" << __LINE__ << ", message: " << message << std::endl; \
std::exit(EXIT_FAILURE); \
} \
} while(false)
#else
# define ASSERT(condition, message) do {} while(false)
#endif
// Return true if the first value is within epsilon of the second value.
bool NearByMargin(double actual, double expected) {
double diff = actual - expected;
if (diff < 0.0) {
diff = -diff;
}
// 5 bits of error in mantissa (source of '32 *')
return diff < 32 * std::numeric_limits<double>::epsilon();
}
// ---- The following functions are used to implement SH rotation computations
// based on the recursive approach described in [1, 4]. The names of the
// functions correspond with the notation used in [1, 4].
// See http://en.wikipedia.org/wiki/Kronecker_delta
double KroneckerDelta(int i, int j) {
if (i == j) {
return 1.0;
} else {
return 0.0;
}
}
// [4] uses an odd convention of referring to the rows and columns using
// centered indices, so the middle row and column are (0, 0) and the upper
// left would have negative coordinates.
//
// This is a convenience function to allow us to access an Eigen::MatrixXf
// in the same manner, assuming r is a (2l+1)x(2l+1) matrix.
double GetCenteredElement(const Eigen::MatrixXf& r, int i, int j) {
// The shift to go from [-l, l] to [0, 2l] is (rows - 1) / 2 = l,
// (since the matrix is assumed to be square, rows == cols).
int offset = (r.rows() - 1) / 2;
return r(i + offset, j + offset);
}
// P is a helper function defined in [4] that is used by the functions U, V, W.
// This should not be called on its own, as U, V, and W (and their coefficients)
// select the appropriate matrix elements to access (arguments @a and @b).
double P(int i, int a, int b, int l, const std::vector<Eigen::MatrixXf>& r) {
if (b == l) {
return GetCenteredElement(r[1], i, 1) *
GetCenteredElement(r[l - 1], a, l - 1) -
GetCenteredElement(r[1], i, -1) *
GetCenteredElement(r[l - 1], a, -l + 1);
} else if (b == -l) {
return GetCenteredElement(r[1], i, 1) *
GetCenteredElement(r[l - 1], a, -l + 1) +
GetCenteredElement(r[1], i, -1) *
GetCenteredElement(r[l - 1], a, l - 1);
} else {
return GetCenteredElement(r[1], i, 0) * GetCenteredElement(r[l - 1], a, b);
}
}
// The functions U, V, and W should only be called if the correspondingly
// named coefficient u, v, w from the function ComputeUVWCoeff() is non-zero.
// When the coefficient is 0, these would attempt to access matrix elements that
// are out of bounds. The list of rotations, @r, must have the @l - 1
// previously completed band rotations. These functions are valid for l >= 2.
double U(int m, int n, int l, const std::vector<Eigen::MatrixXf>& r) {
// Although [1, 4] split U into three cases for m == 0, m < 0, m > 0
// the actual values are the same for all three cases
return P(0, m, n, l, r);
}
double V(int m, int n, int l, const std::vector<Eigen::MatrixXf>& r) {
if (m == 0) {
return P(1, 1, n, l, r) + P(-1, -1, n, l, r);
} else if (m > 0) {
return P(1, m - 1, n, l, r) * sqrt(1 + KroneckerDelta(m, 1)) -
P(-1, -m + 1, n, l, r) * (1 - KroneckerDelta(m, 1));
} else {
// Note there is apparent errata in [1,4,4b] dealing with this particular
// case. [4b] writes it should be P*(1-d)+P*(1-d)^0.5
// [1] writes it as P*(1+d)+P*(1-d)^0.5, but going through the math by hand,
// you must have it as P*(1-d)+P*(1+d)^0.5 to form a 2^.5 term, which
// parallels the case where m > 0.
return P(1, m + 1, n, l, r) * (1 - KroneckerDelta(m, -1)) +
P(-1, -m - 1, n, l, r) * sqrt(1 + KroneckerDelta(m, -1));
}
}
double W(int m, int n, int l, const std::vector<Eigen::MatrixXf>& r) {
if (m == 0) {
// whenever this happens, w is also 0 so W can be anything
return 0.0;
} else if (m > 0) {
return P(1, m + 1, n, l, r) + P(-1, -m - 1, n, l, r);
} else {
return P(1, m - 1, n, l, r) - P(-1, -m + 1, n, l, r);
}
}
// Calculate the coefficients applied to the U, V, and W functions. Because
// their equations share many common terms they are computed simultaneously.
void ComputeUVWCoeff(int m, int n, int l, double* u, double* v, double* w) {
double d = KroneckerDelta(m, 0);
double denom = (abs(n) == l ? 2.0 * l * (2.0 * l - 1) : (l + n) * (l - n));
*u = sqrt((l + m) * (l - m) / denom);
*v = 0.5 * sqrt((1 + d) * (l + abs(m) - 1.0) * (l + abs(m)) / denom)
* (1 - 2 * d);
*w = -0.5 * sqrt((l - abs(m) - 1) * (l - abs(m)) / denom) * (1 - d);
}
// Calculate the (2l+1)x(2l+1) rotation matrix for the band @l.
// This uses the matrices computed for band 1 and band l-1 to compute the
// matrix for band l. @rotations must contain the previously computed l-1
// rotation matrices, and the new matrix for band l will be appended to it.
//
// This implementation comes from p. 5 (6346), Table 1 and 2 in [4] taking
// into account the corrections from [4b].
void ComputeBandRotation(int l, std::vector<Eigen::MatrixXf>* rotations) {
// The band's rotation matrix has rows and columns equal to the number of
// coefficients within that band (-l <= m <= l implies 2l + 1 coefficients).
Eigen::MatrixXf rotation(2 * l + 1, 2 * l + 1);
for (int m = -l; m <= l; m++) {
for (int n = -l; n <= l; n++) {
double u, v, w;
ComputeUVWCoeff(m, n, l, &u, &v, &w);
// The functions U, V, W are only safe to call if the coefficients
// u, v, w are not zero
if (!NearByMargin(u, 0.0))
u *= U(m, n, l, *rotations);
if (!NearByMargin(v, 0.0))
v *= V(m, n, l, *rotations);
if (!NearByMargin(w, 0.0))
w *= W(m, n, l, *rotations);
rotation(m + l, n + l) = (u + v + w);
}
}
rotations->push_back(rotation);
}
class Rotation {
public:
/*
// Create a new Rotation that can applies @rotation to sets of coefficients
// for the given @order. @order must be at least 0.
static std::unique_ptr<Rotation> Create(int order,
const Eigen::Quaternionf& rotation);
// Create a new Rotation that applies the same rotation as @rotation. This
// can be used to efficiently calculate the matrices for the same 3x3
// transform when a new order is necessary.
static std::unique_ptr<Rotation> Create(int order, const Rotation& rotation);
*/
// Transform the SH basis coefficients in @coeff by this rotation and store
// them into @result. These may be the same vector. The @result vector will
// be resized if necessary, but @coeffs must have its size equal to
// GetCoefficientCount(order()).
//
// This rotation transformation produces a set of coefficients that are equal
// to the coefficients found by projecting the original function rotated by
// the same rotation matrix.
//
// There are explicit instantiations for double, float, and Array3f.
template <typename T>
void Apply(const std::vector<T>& coeffs, std::vector<T>* result) const;
void Apply(const Eigen::MatrixXf& coeffs, Eigen::MatrixXf& result) const;
void Apply(const Eigen::VectorXf& coeffs, Eigen::VectorXf& result) const;
// The order (0-based) that the rotation was constructed with. It can only
// transform coefficient vectors that were fit using the same order.
int order() const;
// Return the rotation that is effectively applied to the inputs of the
// original function.
Eigen::Quaternionf rotation() const;
// Return the (2l+1)x(2l+1) matrix for transforming the coefficients within
// band @l by the rotation. @l must be at least 0 and less than or equal to
// the order this rotation was initially constructed with.
const Eigen::MatrixXf& band_rotation(int l) const;
Rotation(int order, const Eigen::Quaternionf& rotation);
private:
const int order_;
const Eigen::Quaternionf rotation_;
std::vector<Eigen::MatrixXf> band_rotations_;
};
Rotation::Rotation(int order, const Eigen::Quaternionf& rotation)
: order_(order), rotation_(rotation) {
band_rotations_.reserve(GetCoefficientCount(order));
// Order 0 (first band) is simply the 1x1 identity since the SH basis
// function is a simple sphere.
Eigen::MatrixXf r(1, 1);
r(0, 0) = 1.0;
band_rotations_.push_back(r);
r.resize(3, 3);
// The second band's transformation is simply a permutation of the
// rotation matrix's elements, provided in Appendix 1 of [1], updated to
// include the Condon-Shortely phase. The recursive method in
// ComputeBandRotation preserves the proper phases as high bands are computed.
Eigen::Matrix3f rotation_mat = rotation.toRotationMatrix();
r(0, 0) = rotation_mat(1, 1);
r(0, 1) = -rotation_mat(1, 2);
r(0, 2) = rotation_mat(1, 0);
r(1, 0) = -rotation_mat(2, 1);
r(1, 1) = rotation_mat(2, 2);
r(1, 2) = -rotation_mat(2, 0);
r(2, 0) = rotation_mat(0, 1);
r(2, 1) = -rotation_mat(0, 2);
r(2, 2) = rotation_mat(0, 0);
band_rotations_.push_back(r);
// Recursively build the remaining band rotations, using the equations
// provided in [4, 4b].
for (int l = 2; l <= order; l++) {
ComputeBandRotation(l, &band_rotations_);
}
}
/*
std::unique_ptr<Rotation> Rotation::Create(
int order, const Eigen::Quaternionf& rotation) {
#ifndef NDEBUG
CHECK(order >= 0, "Order must be at least 0.");
CHECK(NearByMargin(rotation.squaredNorm(), 1.0),
"Rotation must be normalized.");
#endif
std::unique_ptr<Rotation> sh_rot(new Rotation(order, rotation));
// Order 0 (first band) is simply the 1x1 identity since the SH basis
// function is a simple sphere.
Eigen::MatrixXf r(1, 1);
r(0, 0) = 1.0;
sh_rot->band_rotations_.push_back(r);
r.resize(3, 3);
// The second band's transformation is simply a permutation of the
// rotation matrix's elements, provided in Appendix 1 of [1], updated to
// include the Condon-Shortely phase. The recursive method in
// ComputeBandRotation preserves the proper phases as high bands are computed.
Eigen::Matrix3f rotation_mat = rotation.toRotationMatrix();
r(0, 0) = rotation_mat(1, 1);
r(0, 1) = -rotation_mat(1, 2);
r(0, 2) = rotation_mat(1, 0);
r(1, 0) = -rotation_mat(2, 1);
r(1, 1) = rotation_mat(2, 2);
r(1, 2) = -rotation_mat(2, 0);
r(2, 0) = rotation_mat(0, 1);
r(2, 1) = -rotation_mat(0, 2);
r(2, 2) = rotation_mat(0, 0);
sh_rot->band_rotations_.push_back(r);
// Recursively build the remaining band rotations, using the equations
// provided in [4, 4b].
for (int l = 2; l <= order; l++) {
ComputeBandRotation(l, &(sh_rot->band_rotations_));
}
return sh_rot;
}
std::unique_ptr<Rotation> Rotation::Create(int order,
const Rotation& rotation) {
#ifndef NDEBUG
CHECK(order >= 0, "Order must be at least 0.");
#endif
std::unique_ptr<Rotation> sh_rot(new Rotation(order, rotation.rotation_));
// Copy up to min(order, rotation.order_) band rotations into the new
// SHRotation. For shared orders, they are the same. If the new order is
// higher than already calculated then the remainder will be computed next.
for (int l = 0; l <= std::min(order, rotation.order_); l++) {
sh_rot->band_rotations_.push_back(rotation.band_rotations_[l]);
}
// Calculate remaining bands (automatically skipped if there are no more).
for (int l = rotation.order_ + 1; l <= order; l++) {
ComputeBandRotation(l, &(sh_rot->band_rotations_));
}
return sh_rot;
}
*/
int Rotation::order() const { return order_; }
Eigen::Quaternionf Rotation::rotation() const { return rotation_; }
const Eigen::MatrixXf& Rotation::band_rotation(int l) const {
return band_rotations_[l];
}
template <typename T>
void Rotation::Apply(const std::vector<T>& coeff,
std::vector<T>* result) const {
#ifndef NDEBUG
CHECK(coeff.size() == GetCoefficientCount(order_),
"Incorrect number of coefficients provided.");
#endif
// Resize to the required number of coefficients.
// If result is already the same size as coeff, there's no need to zero out
// its values since each index will be written explicitly later.
if (result->size() != coeff.size()) {
result->assign(coeff.size(), T());
}
// Because of orthogonality, the coefficients outside of each band do not
// interact with one another. By separating them into band-specific matrices,
// we take advantage of that sparsity.
for (int l = 0; l <= order_; l++) {
VectorX<T> band_coeff(2 * l + 1);
// Fill band_coeff from the subset of @coeff that's relevant.
for (int m = -l; m <= l; m++) {
// Offset by l to get the appropiate vector component (0-based instead
// of starting at -l).
band_coeff(m + l) = coeff[GetIndex(l, m)];
}
band_coeff = band_rotations_[l].cast<T>() * band_coeff;
// Copy rotated coefficients back into the appropriate subset into @result.
for (int m = -l; m <= l; m++) {
(*result)[GetIndex(l, m)] = band_coeff(m + l);
}
}
}
void Rotation::Apply(const Eigen::MatrixXf& coeffs,
Eigen::MatrixXf& result) const {
const int rows = coeffs.cols();
for(int l=0; l<=order_; ++l) {
const int i = l*l;
const int n = 2*l+1;
result.block(i, 0, n, rows) = band_rotations_[l] * coeffs.block(i, 0, n, rows);
}
}
void Rotation::Apply(const Eigen::VectorXf& coeffs,
Eigen::VectorXf& result) const {
for(int l=0; l<=order_; ++l) {
const int i = l*l;
const int n = 2*l+1;
result.segment(i, n) = band_rotations_[l] * coeffs.segment(i, n);
}
}
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/browser_list.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/message_loop.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_shutdown.h"
#include "chrome/browser/download/download_service.h"
#include "chrome/browser/metrics/thread_watcher.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tab_contents/tab_contents.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/browser_shutdown.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_details.h"
#include "content/public/browser/notification_service.h"
#if defined(OS_MACOSX)
#include "chrome/browser/chrome_browser_application_mac.h"
#endif
#if defined(OS_CHROMEOS)
#include "base/chromeos/chromeos_version.h"
#include "chrome/browser/chromeos/boot_times_loader.h"
#include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_metrics.h"
#include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h"
#include "chrome/browser/chromeos/login/user_manager.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/session_manager_client.h"
#include "chromeos/dbus/update_engine_client.h"
#endif
namespace browser {
namespace {
// Returns true if all browsers can be closed without user interaction.
// This currently checks if there is pending download, or if it needs to
// handle unload handler.
bool AreAllBrowsersCloseable() {
BrowserList::const_iterator browser_it = BrowserList::begin();
if (browser_it == BrowserList::end())
return true;
// If there are any downloads active, all browsers are not closeable.
if (DownloadService::DownloadCountAllProfiles() > 0)
return false;
// Check TabsNeedBeforeUnloadFired().
for (; browser_it != BrowserList::end(); ++browser_it) {
if ((*browser_it)->TabsNeedBeforeUnloadFired())
return false;
}
return true;
}
int g_keep_alive_count = 0;
#if defined(OS_CHROMEOS)
// Whether a session manager requested to shutdown.
bool g_session_manager_requested_shutdown = true;
#endif
} // namespace
void MarkAsCleanShutdown() {
// TODO(beng): Can this use ProfileManager::GetLoadedProfiles() instead?
for (BrowserList::const_iterator i = BrowserList::begin();
i != BrowserList::end(); ++i) {
(*i)->profile()->MarkAsCleanShutdown();
}
}
void AttemptExitInternal() {
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST,
content::NotificationService::AllSources(),
content::NotificationService::NoDetails());
#if !defined(OS_MACOSX)
// On most platforms, closing all windows causes the application to exit.
CloseAllBrowsers();
#else
// On the Mac, the application continues to run once all windows are closed.
// Terminate will result in a CloseAllBrowsers() call, and once (and if)
// that is done, will cause the application to exit cleanly.
chrome_browser_application_mac::Terminate();
#endif
}
void NotifyAppTerminating() {
static bool notified = false;
if (notified)
return;
notified = true;
content::NotificationService::current()->Notify(
content::NOTIFICATION_APP_TERMINATING,
content::NotificationService::AllSources(),
content::NotificationService::NoDetails());
}
void NotifyAndTerminate(bool fast_path) {
#if defined(OS_CHROMEOS)
static bool notified = false;
// Don't ask SessionManager to shutdown if
// a) a shutdown request has already been sent.
// b) shutdown request comes from session manager.
if (notified || g_session_manager_requested_shutdown)
return;
notified = true;
#endif
if (fast_path)
NotifyAppTerminating();
#if defined(OS_CHROMEOS)
if (base::chromeos::IsRunningOnChromeOS()) {
if (chromeos::KioskModeSettings::Get()->IsKioskModeEnabled())
chromeos::KioskModeMetrics::Get()->SessionEnded();
// If we're on a ChromeOS device, reboot if an update has been applied,
// or else signal the session manager to log out.
chromeos::UpdateEngineClient* update_engine_client
= chromeos::DBusThreadManager::Get()->GetUpdateEngineClient();
if (update_engine_client->GetLastStatus().status ==
chromeos::UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT) {
update_engine_client->RebootAfterUpdate();
} else {
chromeos::DBusThreadManager::Get()->GetSessionManagerClient()
->StopSession();
}
} else {
// If running the Chrome OS build, but we're not on the device, act
// as if we received signal from SessionManager.
content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
base::Bind(&browser::ExitCleanly));
}
#endif
}
void OnAppExiting() {
static bool notified = false;
if (notified)
return;
notified = true;
HandleAppExitingForPlatform();
}
void CloseAllBrowsers() {
bool session_ending =
browser_shutdown::GetShutdownType() == browser_shutdown::END_SESSION;
// Tell everyone that we are shutting down.
browser_shutdown::SetTryingToQuit(true);
#if defined(ENABLE_SESSION_SERVICE)
// Before we close the browsers shutdown all session services. That way an
// exit can restore all browsers open before exiting.
ProfileManager::ShutdownSessionServices();
#endif
// If there are no browsers, send the APP_TERMINATING action here. Otherwise,
// it will be sent by RemoveBrowser() when the last browser has closed.
if (browser_shutdown::ShuttingDownWithoutClosingBrowsers() ||
BrowserList::empty()) {
NotifyAndTerminate(true);
OnAppExiting();
return;
}
#if defined(OS_CHROMEOS)
chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker(
"StartedClosingWindows", false);
#endif
for (BrowserList::const_iterator i = BrowserList::begin();
i != BrowserList::end();) {
Browser* browser = *i;
browser->window()->Close();
if (!session_ending) {
++i;
} else {
// This path is hit during logoff/power-down. In this case we won't get
// a final message and so we force the browser to be deleted.
// Close doesn't immediately destroy the browser
// (Browser::TabStripEmpty() uses invoke later) but when we're ending the
// session we need to make sure the browser is destroyed now. So, invoke
// DestroyBrowser to make sure the browser is deleted and cleanup can
// happen.
while (browser->tab_count())
delete chrome::GetTabContentsAt(browser, 0);
browser->window()->DestroyBrowser();
i = BrowserList::begin();
if (i != BrowserList::end() && browser == *i) {
// Destroying the browser should have removed it from the browser list.
// We should never get here.
NOTREACHED();
return;
}
}
}
}
void AttemptUserExit() {
#if defined(OS_CHROMEOS)
chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("LogoutStarted", false);
// Write /tmp/uptime-logout-started as well.
const char kLogoutStarted[] = "logout-started";
chromeos::BootTimesLoader::Get()->RecordCurrentStats(kLogoutStarted);
// Login screen should show up in owner's locale.
PrefService* state = g_browser_process->local_state();
if (state) {
std::string owner_locale = state->GetString(prefs::kOwnerLocale);
if (!owner_locale.empty() &&
state->GetString(prefs::kApplicationLocale) != owner_locale &&
!state->IsManagedPreference(prefs::kApplicationLocale)) {
state->SetString(prefs::kApplicationLocale, owner_locale);
state->CommitPendingWrite();
}
}
g_session_manager_requested_shutdown = false;
// On ChromeOS, always terminate the browser, regardless of the result of
// AreAllBrowsersCloseable(). See crbug.com/123107.
NotifyAndTerminate(true);
#else
// Reset the restart bit that might have been set in cancelled restart
// request.
PrefService* pref_service = g_browser_process->local_state();
pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, false);
AttemptExitInternal();
#endif
}
void AttemptRestart() {
if (!CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableRestoreSessionState)) {
// TODO(beng): Can this use ProfileManager::GetLoadedProfiles instead?
BrowserList::const_iterator it;
for (it = BrowserList::begin(); it != BrowserList::end(); ++it)
content::BrowserContext::SaveSessionState((*it)->profile());
}
PrefService* pref_service = g_browser_process->local_state();
pref_service->SetBoolean(prefs::kWasRestarted, true);
#if defined(OS_CHROMEOS)
// For CrOS instead of browser restart (which is not supported) perform a full
// sign out. Session will be only restored if user has that setting set.
// Same session restore behavior happens in case of full restart after update.
AttemptUserExit();
#else
// Set the flag to restore state after the restart.
pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, true);
AttemptExit();
#endif
}
void AttemptExit() {
// If we know that all browsers can be closed without blocking,
// don't notify users of crashes beyond this point.
// Note that MarkAsCleanShutdown does not set UMA's exit cleanly bit
// so crashes during shutdown are still reported in UMA.
if (AreAllBrowsersCloseable())
MarkAsCleanShutdown();
AttemptExitInternal();
}
#if defined(OS_CHROMEOS)
// A function called when SIGTERM is received.
void ExitCleanly() {
// We always mark exit cleanly because SessionManager may kill
// chrome in 3 seconds after SIGTERM.
g_browser_process->EndSession();
// Don't block when SIGTERM is received. AreaAllBrowsersCloseable()
// can be false in following cases. a) power-off b) signout from
// screen locker.
if (!AreAllBrowsersCloseable())
browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION);
AttemptExitInternal();
}
#endif
void SessionEnding() {
// This is a time-limited shutdown where we need to write as much to
// disk as we can as soon as we can, and where we must kill the
// process within a hang timeout to avoid user prompts.
// Start watching for hang during shutdown, and crash it if takes too long.
// We disarm when |shutdown_watcher| object is destroyed, which is when we
// exit this function.
ShutdownWatcherHelper shutdown_watcher;
shutdown_watcher.Arm(base::TimeDelta::FromSeconds(90));
// EndSession is invoked once per frame. Only do something the first time.
static bool already_ended = false;
// We may get called in the middle of shutdown, e.g. http://crbug.com/70852
// In this case, do nothing.
if (already_ended || !content::NotificationService::current())
return;
already_ended = true;
browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION);
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST,
content::NotificationService::AllSources(),
content::NotificationService::NoDetails());
// Write important data first.
g_browser_process->EndSession();
CloseAllBrowsers();
// Send out notification. This is used during testing so that the test harness
// can properly shutdown before we exit.
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_SESSION_END,
content::NotificationService::AllSources(),
content::NotificationService::NoDetails());
// This will end by terminating the process.
content::ImmediateShutdownAndExitProcess();
}
void StartKeepAlive() {
// Increment the browser process refcount as long as we're keeping the
// application alive.
if (!WillKeepAlive())
g_browser_process->AddRefModule();
++g_keep_alive_count;
}
void EndKeepAlive() {
DCHECK_GT(g_keep_alive_count, 0);
--g_keep_alive_count;
DCHECK(g_browser_process);
// Although we should have a browser process, if there is none,
// there is nothing to do.
if (!g_browser_process) return;
// Allow the app to shutdown again.
if (!WillKeepAlive()) {
g_browser_process->ReleaseModule();
// If there are no browsers open and we aren't already shutting down,
// initiate a shutdown. Also skips shutdown if this is a unit test
// (MessageLoop::current() == null).
if (BrowserList::empty() && !browser_shutdown::IsTryingToQuit() &&
MessageLoop::current())
CloseAllBrowsers();
}
}
bool WillKeepAlive() {
return g_keep_alive_count > 0;
}
} // namespace browser
|
;;
;; Copyright (c) 2020, Intel Corporation
;;
;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions are met:
;;
;; * Redistributions of source code must retain the above copyright notice,
;; this list of conditions and the following disclaimer.
;; * Redistributions in binary form must reproduce the above copyright
;; notice, this list of conditions and the following disclaimer in the
;; documentation and/or other materials provided with the distribution.
;; * Neither the name of Intel Corporation nor the names of its contributors
;; may be used to endorse or promote products derived from this software
;; without specific prior written permission.
;;
;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
;; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
;; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
;; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
;; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;;
%include "include/os.asm"
%include "include/reg_sizes.asm"
%include "include/clear_regs.asm"
%include "include/crc32_refl_const.inc"
%include "include/crc32_refl.inc"
%ifndef LINUX
%xdefine arg1 rcx
%xdefine arg2 rdx
%xdefine arg3 r8
%xdefine arg4 r9
%else
%xdefine arg1 rdi
%xdefine arg2 rsi
%xdefine arg3 rdx
%xdefine arg4 rcx
%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(crc16_x25_avx512, function,)
crc16_x25_avx512:
%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 crc16_x25_ccitt_const]
mov arg3, arg2
mov arg2, arg1
mov DWORD(arg1), 0xffff0000
call crc32_refl_by16_vclmul_avx512
and eax, 0xffff
%ifdef SAFE_DATA
clear_scratch_zmms_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
|
; A038159: a(n) = n*a(n-1) + 1, a(0) = 2.
; 2,3,7,22,89,446,2677,18740,149921,1349290,13492901,148421912,1781062945,23153818286,324153456005,4862301840076,77796829441217,1322546100500690,23805829809012421,452310766371236000,9046215327424720001,189970521875919120022,4179351481270220640485,96125084069215074731156,2307002017661161793547745,57675050441529044838693626,1499551311479755165806034277,40487885409953389476762925480,1133660791478694905349361913441,32876162952882152255131495489790,986284888586464567653944864693701
mov $1,1
mov $2,1
lpb $0
sub $0,1
add $1,1
mul $1,$2
add $2,1
lpe
add $1,1
mov $0,$1
|
SECTION code_clib
SECTION code_fp_math48
PUBLIC fmin
EXTERN cm48_sccz80_fmin
defc fmin = cm48_sccz80_fmin
|
_stressfs: file format elf64-x86-64
Disassembly of section .text:
0000000000001000 <main>:
#include "fs.h"
#include "fcntl.h"
int
main(int argc, char *argv[])
{
1000: f3 0f 1e fa endbr64
1004: 55 push %rbp
1005: 48 89 e5 mov %rsp,%rbp
1008: 48 81 ec 30 02 00 00 sub $0x230,%rsp
100f: 89 bd dc fd ff ff mov %edi,-0x224(%rbp)
1015: 48 89 b5 d0 fd ff ff mov %rsi,-0x230(%rbp)
int fd, i;
char path[] = "stressfs0";
101c: 48 b8 73 74 72 65 73 movabs $0x7366737365727473,%rax
1023: 73 66 73
1026: 48 89 45 ee mov %rax,-0x12(%rbp)
102a: 66 c7 45 f6 30 00 movw $0x30,-0xa(%rbp)
char data[512];
printf(1, "stressfs starting\n");
1030: 48 be 10 1f 00 00 00 movabs $0x1f10,%rsi
1037: 00 00 00
103a: bf 01 00 00 00 mov $0x1,%edi
103f: b8 00 00 00 00 mov $0x0,%eax
1044: 48 ba f9 17 00 00 00 movabs $0x17f9,%rdx
104b: 00 00 00
104e: ff d2 callq *%rdx
memset(data, 'a', sizeof(data));
1050: 48 8d 85 e0 fd ff ff lea -0x220(%rbp),%rax
1057: ba 00 02 00 00 mov $0x200,%edx
105c: be 61 00 00 00 mov $0x61,%esi
1061: 48 89 c7 mov %rax,%rdi
1064: 48 b8 cd 12 00 00 00 movabs $0x12cd,%rax
106b: 00 00 00
106e: ff d0 callq *%rax
for(i = 0; i < 4; i++)
1070: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%rbp)
1077: eb 14 jmp 108d <main+0x8d>
if(fork() > 0)
1079: 48 b8 f5 14 00 00 00 movabs $0x14f5,%rax
1080: 00 00 00
1083: ff d0 callq *%rax
1085: 85 c0 test %eax,%eax
1087: 7f 0c jg 1095 <main+0x95>
for(i = 0; i < 4; i++)
1089: 83 45 fc 01 addl $0x1,-0x4(%rbp)
108d: 83 7d fc 03 cmpl $0x3,-0x4(%rbp)
1091: 7e e6 jle 1079 <main+0x79>
1093: eb 01 jmp 1096 <main+0x96>
break;
1095: 90 nop
printf(1, "write %d\n", i);
1096: 8b 45 fc mov -0x4(%rbp),%eax
1099: 89 c2 mov %eax,%edx
109b: 48 be 23 1f 00 00 00 movabs $0x1f23,%rsi
10a2: 00 00 00
10a5: bf 01 00 00 00 mov $0x1,%edi
10aa: b8 00 00 00 00 mov $0x0,%eax
10af: 48 b9 f9 17 00 00 00 movabs $0x17f9,%rcx
10b6: 00 00 00
10b9: ff d1 callq *%rcx
path[8] += i;
10bb: 0f b6 45 f6 movzbl -0xa(%rbp),%eax
10bf: 89 c2 mov %eax,%edx
10c1: 8b 45 fc mov -0x4(%rbp),%eax
10c4: 01 d0 add %edx,%eax
10c6: 88 45 f6 mov %al,-0xa(%rbp)
fd = open(path, O_CREATE | O_RDWR);
10c9: 48 8d 45 ee lea -0x12(%rbp),%rax
10cd: be 02 02 00 00 mov $0x202,%esi
10d2: 48 89 c7 mov %rax,%rdi
10d5: 48 b8 6a 15 00 00 00 movabs $0x156a,%rax
10dc: 00 00 00
10df: ff d0 callq *%rax
10e1: 89 45 f8 mov %eax,-0x8(%rbp)
for(i = 0; i < 20; i++)
10e4: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%rbp)
10eb: eb 24 jmp 1111 <main+0x111>
// printf(fd, "%d\n", i);
write(fd, data, sizeof(data));
10ed: 48 8d 8d e0 fd ff ff lea -0x220(%rbp),%rcx
10f4: 8b 45 f8 mov -0x8(%rbp),%eax
10f7: ba 00 02 00 00 mov $0x200,%edx
10fc: 48 89 ce mov %rcx,%rsi
10ff: 89 c7 mov %eax,%edi
1101: 48 b8 36 15 00 00 00 movabs $0x1536,%rax
1108: 00 00 00
110b: ff d0 callq *%rax
for(i = 0; i < 20; i++)
110d: 83 45 fc 01 addl $0x1,-0x4(%rbp)
1111: 83 7d fc 13 cmpl $0x13,-0x4(%rbp)
1115: 7e d6 jle 10ed <main+0xed>
close(fd);
1117: 8b 45 f8 mov -0x8(%rbp),%eax
111a: 89 c7 mov %eax,%edi
111c: 48 b8 43 15 00 00 00 movabs $0x1543,%rax
1123: 00 00 00
1126: ff d0 callq *%rax
printf(1, "read\n");
1128: 48 be 2d 1f 00 00 00 movabs $0x1f2d,%rsi
112f: 00 00 00
1132: bf 01 00 00 00 mov $0x1,%edi
1137: b8 00 00 00 00 mov $0x0,%eax
113c: 48 ba f9 17 00 00 00 movabs $0x17f9,%rdx
1143: 00 00 00
1146: ff d2 callq *%rdx
fd = open(path, O_RDONLY);
1148: 48 8d 45 ee lea -0x12(%rbp),%rax
114c: be 00 00 00 00 mov $0x0,%esi
1151: 48 89 c7 mov %rax,%rdi
1154: 48 b8 6a 15 00 00 00 movabs $0x156a,%rax
115b: 00 00 00
115e: ff d0 callq *%rax
1160: 89 45 f8 mov %eax,-0x8(%rbp)
for (i = 0; i < 20; i++)
1163: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%rbp)
116a: eb 24 jmp 1190 <main+0x190>
read(fd, data, sizeof(data));
116c: 48 8d 8d e0 fd ff ff lea -0x220(%rbp),%rcx
1173: 8b 45 f8 mov -0x8(%rbp),%eax
1176: ba 00 02 00 00 mov $0x200,%edx
117b: 48 89 ce mov %rcx,%rsi
117e: 89 c7 mov %eax,%edi
1180: 48 b8 29 15 00 00 00 movabs $0x1529,%rax
1187: 00 00 00
118a: ff d0 callq *%rax
for (i = 0; i < 20; i++)
118c: 83 45 fc 01 addl $0x1,-0x4(%rbp)
1190: 83 7d fc 13 cmpl $0x13,-0x4(%rbp)
1194: 7e d6 jle 116c <main+0x16c>
close(fd);
1196: 8b 45 f8 mov -0x8(%rbp),%eax
1199: 89 c7 mov %eax,%edi
119b: 48 b8 43 15 00 00 00 movabs $0x1543,%rax
11a2: 00 00 00
11a5: ff d0 callq *%rax
wait();
11a7: 48 b8 0f 15 00 00 00 movabs $0x150f,%rax
11ae: 00 00 00
11b1: ff d0 callq *%rax
exit();
11b3: 48 b8 02 15 00 00 00 movabs $0x1502,%rax
11ba: 00 00 00
11bd: ff d0 callq *%rax
00000000000011bf <stosb>:
"cc");
}
static inline void
stosb(void *addr, int data, int cnt)
{
11bf: f3 0f 1e fa endbr64
11c3: 55 push %rbp
11c4: 48 89 e5 mov %rsp,%rbp
11c7: 48 83 ec 10 sub $0x10,%rsp
11cb: 48 89 7d f8 mov %rdi,-0x8(%rbp)
11cf: 89 75 f4 mov %esi,-0xc(%rbp)
11d2: 89 55 f0 mov %edx,-0x10(%rbp)
asm volatile("cld; rep stosb" :
11d5: 48 8b 4d f8 mov -0x8(%rbp),%rcx
11d9: 8b 55 f0 mov -0x10(%rbp),%edx
11dc: 8b 45 f4 mov -0xc(%rbp),%eax
11df: 48 89 ce mov %rcx,%rsi
11e2: 48 89 f7 mov %rsi,%rdi
11e5: 89 d1 mov %edx,%ecx
11e7: fc cld
11e8: f3 aa rep stos %al,%es:(%rdi)
11ea: 89 ca mov %ecx,%edx
11ec: 48 89 fe mov %rdi,%rsi
11ef: 48 89 75 f8 mov %rsi,-0x8(%rbp)
11f3: 89 55 f0 mov %edx,-0x10(%rbp)
"=D" (addr), "=c" (cnt) :
"0" (addr), "1" (cnt), "a" (data) :
"memory", "cc");
}
11f6: 90 nop
11f7: c9 leaveq
11f8: c3 retq
00000000000011f9 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, char *t)
{
11f9: f3 0f 1e fa endbr64
11fd: 55 push %rbp
11fe: 48 89 e5 mov %rsp,%rbp
1201: 48 83 ec 20 sub $0x20,%rsp
1205: 48 89 7d e8 mov %rdi,-0x18(%rbp)
1209: 48 89 75 e0 mov %rsi,-0x20(%rbp)
char *os;
os = s;
120d: 48 8b 45 e8 mov -0x18(%rbp),%rax
1211: 48 89 45 f8 mov %rax,-0x8(%rbp)
while((*s++ = *t++) != 0)
1215: 90 nop
1216: 48 8b 55 e0 mov -0x20(%rbp),%rdx
121a: 48 8d 42 01 lea 0x1(%rdx),%rax
121e: 48 89 45 e0 mov %rax,-0x20(%rbp)
1222: 48 8b 45 e8 mov -0x18(%rbp),%rax
1226: 48 8d 48 01 lea 0x1(%rax),%rcx
122a: 48 89 4d e8 mov %rcx,-0x18(%rbp)
122e: 0f b6 12 movzbl (%rdx),%edx
1231: 88 10 mov %dl,(%rax)
1233: 0f b6 00 movzbl (%rax),%eax
1236: 84 c0 test %al,%al
1238: 75 dc jne 1216 <strcpy+0x1d>
;
return os;
123a: 48 8b 45 f8 mov -0x8(%rbp),%rax
}
123e: c9 leaveq
123f: c3 retq
0000000000001240 <strcmp>:
int
strcmp(const char *p, const char *q)
{
1240: f3 0f 1e fa endbr64
1244: 55 push %rbp
1245: 48 89 e5 mov %rsp,%rbp
1248: 48 83 ec 10 sub $0x10,%rsp
124c: 48 89 7d f8 mov %rdi,-0x8(%rbp)
1250: 48 89 75 f0 mov %rsi,-0x10(%rbp)
while(*p && *p == *q)
1254: eb 0a jmp 1260 <strcmp+0x20>
p++, q++;
1256: 48 83 45 f8 01 addq $0x1,-0x8(%rbp)
125b: 48 83 45 f0 01 addq $0x1,-0x10(%rbp)
while(*p && *p == *q)
1260: 48 8b 45 f8 mov -0x8(%rbp),%rax
1264: 0f b6 00 movzbl (%rax),%eax
1267: 84 c0 test %al,%al
1269: 74 12 je 127d <strcmp+0x3d>
126b: 48 8b 45 f8 mov -0x8(%rbp),%rax
126f: 0f b6 10 movzbl (%rax),%edx
1272: 48 8b 45 f0 mov -0x10(%rbp),%rax
1276: 0f b6 00 movzbl (%rax),%eax
1279: 38 c2 cmp %al,%dl
127b: 74 d9 je 1256 <strcmp+0x16>
return (uchar)*p - (uchar)*q;
127d: 48 8b 45 f8 mov -0x8(%rbp),%rax
1281: 0f b6 00 movzbl (%rax),%eax
1284: 0f b6 d0 movzbl %al,%edx
1287: 48 8b 45 f0 mov -0x10(%rbp),%rax
128b: 0f b6 00 movzbl (%rax),%eax
128e: 0f b6 c0 movzbl %al,%eax
1291: 29 c2 sub %eax,%edx
1293: 89 d0 mov %edx,%eax
}
1295: c9 leaveq
1296: c3 retq
0000000000001297 <strlen>:
uint
strlen(char *s)
{
1297: f3 0f 1e fa endbr64
129b: 55 push %rbp
129c: 48 89 e5 mov %rsp,%rbp
129f: 48 83 ec 18 sub $0x18,%rsp
12a3: 48 89 7d e8 mov %rdi,-0x18(%rbp)
int n;
for(n = 0; s[n]; n++)
12a7: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%rbp)
12ae: eb 04 jmp 12b4 <strlen+0x1d>
12b0: 83 45 fc 01 addl $0x1,-0x4(%rbp)
12b4: 8b 45 fc mov -0x4(%rbp),%eax
12b7: 48 63 d0 movslq %eax,%rdx
12ba: 48 8b 45 e8 mov -0x18(%rbp),%rax
12be: 48 01 d0 add %rdx,%rax
12c1: 0f b6 00 movzbl (%rax),%eax
12c4: 84 c0 test %al,%al
12c6: 75 e8 jne 12b0 <strlen+0x19>
;
return n;
12c8: 8b 45 fc mov -0x4(%rbp),%eax
}
12cb: c9 leaveq
12cc: c3 retq
00000000000012cd <memset>:
void*
memset(void *dst, int c, uint n)
{
12cd: f3 0f 1e fa endbr64
12d1: 55 push %rbp
12d2: 48 89 e5 mov %rsp,%rbp
12d5: 48 83 ec 10 sub $0x10,%rsp
12d9: 48 89 7d f8 mov %rdi,-0x8(%rbp)
12dd: 89 75 f4 mov %esi,-0xc(%rbp)
12e0: 89 55 f0 mov %edx,-0x10(%rbp)
stosb(dst, c, n);
12e3: 8b 55 f0 mov -0x10(%rbp),%edx
12e6: 8b 4d f4 mov -0xc(%rbp),%ecx
12e9: 48 8b 45 f8 mov -0x8(%rbp),%rax
12ed: 89 ce mov %ecx,%esi
12ef: 48 89 c7 mov %rax,%rdi
12f2: 48 b8 bf 11 00 00 00 movabs $0x11bf,%rax
12f9: 00 00 00
12fc: ff d0 callq *%rax
return dst;
12fe: 48 8b 45 f8 mov -0x8(%rbp),%rax
}
1302: c9 leaveq
1303: c3 retq
0000000000001304 <strchr>:
char*
strchr(const char *s, char c)
{
1304: f3 0f 1e fa endbr64
1308: 55 push %rbp
1309: 48 89 e5 mov %rsp,%rbp
130c: 48 83 ec 10 sub $0x10,%rsp
1310: 48 89 7d f8 mov %rdi,-0x8(%rbp)
1314: 89 f0 mov %esi,%eax
1316: 88 45 f4 mov %al,-0xc(%rbp)
for(; *s; s++)
1319: eb 17 jmp 1332 <strchr+0x2e>
if(*s == c)
131b: 48 8b 45 f8 mov -0x8(%rbp),%rax
131f: 0f b6 00 movzbl (%rax),%eax
1322: 38 45 f4 cmp %al,-0xc(%rbp)
1325: 75 06 jne 132d <strchr+0x29>
return (char*)s;
1327: 48 8b 45 f8 mov -0x8(%rbp),%rax
132b: eb 15 jmp 1342 <strchr+0x3e>
for(; *s; s++)
132d: 48 83 45 f8 01 addq $0x1,-0x8(%rbp)
1332: 48 8b 45 f8 mov -0x8(%rbp),%rax
1336: 0f b6 00 movzbl (%rax),%eax
1339: 84 c0 test %al,%al
133b: 75 de jne 131b <strchr+0x17>
return 0;
133d: b8 00 00 00 00 mov $0x0,%eax
}
1342: c9 leaveq
1343: c3 retq
0000000000001344 <gets>:
char*
gets(char *buf, int max)
{
1344: f3 0f 1e fa endbr64
1348: 55 push %rbp
1349: 48 89 e5 mov %rsp,%rbp
134c: 48 83 ec 20 sub $0x20,%rsp
1350: 48 89 7d e8 mov %rdi,-0x18(%rbp)
1354: 89 75 e4 mov %esi,-0x1c(%rbp)
int i, cc;
char c;
for(i=0; i+1 < max; ){
1357: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%rbp)
135e: eb 4f jmp 13af <gets+0x6b>
cc = read(0, &c, 1);
1360: 48 8d 45 f7 lea -0x9(%rbp),%rax
1364: ba 01 00 00 00 mov $0x1,%edx
1369: 48 89 c6 mov %rax,%rsi
136c: bf 00 00 00 00 mov $0x0,%edi
1371: 48 b8 29 15 00 00 00 movabs $0x1529,%rax
1378: 00 00 00
137b: ff d0 callq *%rax
137d: 89 45 f8 mov %eax,-0x8(%rbp)
if(cc < 1)
1380: 83 7d f8 00 cmpl $0x0,-0x8(%rbp)
1384: 7e 36 jle 13bc <gets+0x78>
break;
buf[i++] = c;
1386: 8b 45 fc mov -0x4(%rbp),%eax
1389: 8d 50 01 lea 0x1(%rax),%edx
138c: 89 55 fc mov %edx,-0x4(%rbp)
138f: 48 63 d0 movslq %eax,%rdx
1392: 48 8b 45 e8 mov -0x18(%rbp),%rax
1396: 48 01 c2 add %rax,%rdx
1399: 0f b6 45 f7 movzbl -0x9(%rbp),%eax
139d: 88 02 mov %al,(%rdx)
if(c == '\n' || c == '\r')
139f: 0f b6 45 f7 movzbl -0x9(%rbp),%eax
13a3: 3c 0a cmp $0xa,%al
13a5: 74 16 je 13bd <gets+0x79>
13a7: 0f b6 45 f7 movzbl -0x9(%rbp),%eax
13ab: 3c 0d cmp $0xd,%al
13ad: 74 0e je 13bd <gets+0x79>
for(i=0; i+1 < max; ){
13af: 8b 45 fc mov -0x4(%rbp),%eax
13b2: 83 c0 01 add $0x1,%eax
13b5: 39 45 e4 cmp %eax,-0x1c(%rbp)
13b8: 7f a6 jg 1360 <gets+0x1c>
13ba: eb 01 jmp 13bd <gets+0x79>
break;
13bc: 90 nop
break;
}
buf[i] = '\0';
13bd: 8b 45 fc mov -0x4(%rbp),%eax
13c0: 48 63 d0 movslq %eax,%rdx
13c3: 48 8b 45 e8 mov -0x18(%rbp),%rax
13c7: 48 01 d0 add %rdx,%rax
13ca: c6 00 00 movb $0x0,(%rax)
return buf;
13cd: 48 8b 45 e8 mov -0x18(%rbp),%rax
}
13d1: c9 leaveq
13d2: c3 retq
00000000000013d3 <stat>:
int
stat(char *n, struct stat *st)
{
13d3: f3 0f 1e fa endbr64
13d7: 55 push %rbp
13d8: 48 89 e5 mov %rsp,%rbp
13db: 48 83 ec 20 sub $0x20,%rsp
13df: 48 89 7d e8 mov %rdi,-0x18(%rbp)
13e3: 48 89 75 e0 mov %rsi,-0x20(%rbp)
int fd;
int r;
fd = open(n, O_RDONLY);
13e7: 48 8b 45 e8 mov -0x18(%rbp),%rax
13eb: be 00 00 00 00 mov $0x0,%esi
13f0: 48 89 c7 mov %rax,%rdi
13f3: 48 b8 6a 15 00 00 00 movabs $0x156a,%rax
13fa: 00 00 00
13fd: ff d0 callq *%rax
13ff: 89 45 fc mov %eax,-0x4(%rbp)
if(fd < 0)
1402: 83 7d fc 00 cmpl $0x0,-0x4(%rbp)
1406: 79 07 jns 140f <stat+0x3c>
return -1;
1408: b8 ff ff ff ff mov $0xffffffff,%eax
140d: eb 2f jmp 143e <stat+0x6b>
r = fstat(fd, st);
140f: 48 8b 55 e0 mov -0x20(%rbp),%rdx
1413: 8b 45 fc mov -0x4(%rbp),%eax
1416: 48 89 d6 mov %rdx,%rsi
1419: 89 c7 mov %eax,%edi
141b: 48 b8 91 15 00 00 00 movabs $0x1591,%rax
1422: 00 00 00
1425: ff d0 callq *%rax
1427: 89 45 f8 mov %eax,-0x8(%rbp)
close(fd);
142a: 8b 45 fc mov -0x4(%rbp),%eax
142d: 89 c7 mov %eax,%edi
142f: 48 b8 43 15 00 00 00 movabs $0x1543,%rax
1436: 00 00 00
1439: ff d0 callq *%rax
return r;
143b: 8b 45 f8 mov -0x8(%rbp),%eax
}
143e: c9 leaveq
143f: c3 retq
0000000000001440 <atoi>:
int
atoi(const char *s)
{
1440: f3 0f 1e fa endbr64
1444: 55 push %rbp
1445: 48 89 e5 mov %rsp,%rbp
1448: 48 83 ec 18 sub $0x18,%rsp
144c: 48 89 7d e8 mov %rdi,-0x18(%rbp)
int n;
n = 0;
1450: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%rbp)
while('0' <= *s && *s <= '9')
1457: eb 28 jmp 1481 <atoi+0x41>
n = n*10 + *s++ - '0';
1459: 8b 55 fc mov -0x4(%rbp),%edx
145c: 89 d0 mov %edx,%eax
145e: c1 e0 02 shl $0x2,%eax
1461: 01 d0 add %edx,%eax
1463: 01 c0 add %eax,%eax
1465: 89 c1 mov %eax,%ecx
1467: 48 8b 45 e8 mov -0x18(%rbp),%rax
146b: 48 8d 50 01 lea 0x1(%rax),%rdx
146f: 48 89 55 e8 mov %rdx,-0x18(%rbp)
1473: 0f b6 00 movzbl (%rax),%eax
1476: 0f be c0 movsbl %al,%eax
1479: 01 c8 add %ecx,%eax
147b: 83 e8 30 sub $0x30,%eax
147e: 89 45 fc mov %eax,-0x4(%rbp)
while('0' <= *s && *s <= '9')
1481: 48 8b 45 e8 mov -0x18(%rbp),%rax
1485: 0f b6 00 movzbl (%rax),%eax
1488: 3c 2f cmp $0x2f,%al
148a: 7e 0b jle 1497 <atoi+0x57>
148c: 48 8b 45 e8 mov -0x18(%rbp),%rax
1490: 0f b6 00 movzbl (%rax),%eax
1493: 3c 39 cmp $0x39,%al
1495: 7e c2 jle 1459 <atoi+0x19>
return n;
1497: 8b 45 fc mov -0x4(%rbp),%eax
}
149a: c9 leaveq
149b: c3 retq
000000000000149c <memmove>:
void*
memmove(void *vdst, void *vsrc, int n)
{
149c: f3 0f 1e fa endbr64
14a0: 55 push %rbp
14a1: 48 89 e5 mov %rsp,%rbp
14a4: 48 83 ec 28 sub $0x28,%rsp
14a8: 48 89 7d e8 mov %rdi,-0x18(%rbp)
14ac: 48 89 75 e0 mov %rsi,-0x20(%rbp)
14b0: 89 55 dc mov %edx,-0x24(%rbp)
char *dst, *src;
dst = vdst;
14b3: 48 8b 45 e8 mov -0x18(%rbp),%rax
14b7: 48 89 45 f8 mov %rax,-0x8(%rbp)
src = vsrc;
14bb: 48 8b 45 e0 mov -0x20(%rbp),%rax
14bf: 48 89 45 f0 mov %rax,-0x10(%rbp)
while(n-- > 0)
14c3: eb 1d jmp 14e2 <memmove+0x46>
*dst++ = *src++;
14c5: 48 8b 55 f0 mov -0x10(%rbp),%rdx
14c9: 48 8d 42 01 lea 0x1(%rdx),%rax
14cd: 48 89 45 f0 mov %rax,-0x10(%rbp)
14d1: 48 8b 45 f8 mov -0x8(%rbp),%rax
14d5: 48 8d 48 01 lea 0x1(%rax),%rcx
14d9: 48 89 4d f8 mov %rcx,-0x8(%rbp)
14dd: 0f b6 12 movzbl (%rdx),%edx
14e0: 88 10 mov %dl,(%rax)
while(n-- > 0)
14e2: 8b 45 dc mov -0x24(%rbp),%eax
14e5: 8d 50 ff lea -0x1(%rax),%edx
14e8: 89 55 dc mov %edx,-0x24(%rbp)
14eb: 85 c0 test %eax,%eax
14ed: 7f d6 jg 14c5 <memmove+0x29>
return vdst;
14ef: 48 8b 45 e8 mov -0x18(%rbp),%rax
}
14f3: c9 leaveq
14f4: c3 retq
00000000000014f5 <fork>:
mov $SYS_ ## name, %rax; \
mov %rcx, %r10 ;\
syscall ;\
ret
SYSCALL(fork)
14f5: 48 c7 c0 01 00 00 00 mov $0x1,%rax
14fc: 49 89 ca mov %rcx,%r10
14ff: 0f 05 syscall
1501: c3 retq
0000000000001502 <exit>:
SYSCALL(exit)
1502: 48 c7 c0 02 00 00 00 mov $0x2,%rax
1509: 49 89 ca mov %rcx,%r10
150c: 0f 05 syscall
150e: c3 retq
000000000000150f <wait>:
SYSCALL(wait)
150f: 48 c7 c0 03 00 00 00 mov $0x3,%rax
1516: 49 89 ca mov %rcx,%r10
1519: 0f 05 syscall
151b: c3 retq
000000000000151c <pipe>:
SYSCALL(pipe)
151c: 48 c7 c0 04 00 00 00 mov $0x4,%rax
1523: 49 89 ca mov %rcx,%r10
1526: 0f 05 syscall
1528: c3 retq
0000000000001529 <read>:
SYSCALL(read)
1529: 48 c7 c0 05 00 00 00 mov $0x5,%rax
1530: 49 89 ca mov %rcx,%r10
1533: 0f 05 syscall
1535: c3 retq
0000000000001536 <write>:
SYSCALL(write)
1536: 48 c7 c0 10 00 00 00 mov $0x10,%rax
153d: 49 89 ca mov %rcx,%r10
1540: 0f 05 syscall
1542: c3 retq
0000000000001543 <close>:
SYSCALL(close)
1543: 48 c7 c0 15 00 00 00 mov $0x15,%rax
154a: 49 89 ca mov %rcx,%r10
154d: 0f 05 syscall
154f: c3 retq
0000000000001550 <kill>:
SYSCALL(kill)
1550: 48 c7 c0 06 00 00 00 mov $0x6,%rax
1557: 49 89 ca mov %rcx,%r10
155a: 0f 05 syscall
155c: c3 retq
000000000000155d <exec>:
SYSCALL(exec)
155d: 48 c7 c0 07 00 00 00 mov $0x7,%rax
1564: 49 89 ca mov %rcx,%r10
1567: 0f 05 syscall
1569: c3 retq
000000000000156a <open>:
SYSCALL(open)
156a: 48 c7 c0 0f 00 00 00 mov $0xf,%rax
1571: 49 89 ca mov %rcx,%r10
1574: 0f 05 syscall
1576: c3 retq
0000000000001577 <mknod>:
SYSCALL(mknod)
1577: 48 c7 c0 11 00 00 00 mov $0x11,%rax
157e: 49 89 ca mov %rcx,%r10
1581: 0f 05 syscall
1583: c3 retq
0000000000001584 <unlink>:
SYSCALL(unlink)
1584: 48 c7 c0 12 00 00 00 mov $0x12,%rax
158b: 49 89 ca mov %rcx,%r10
158e: 0f 05 syscall
1590: c3 retq
0000000000001591 <fstat>:
SYSCALL(fstat)
1591: 48 c7 c0 08 00 00 00 mov $0x8,%rax
1598: 49 89 ca mov %rcx,%r10
159b: 0f 05 syscall
159d: c3 retq
000000000000159e <link>:
SYSCALL(link)
159e: 48 c7 c0 13 00 00 00 mov $0x13,%rax
15a5: 49 89 ca mov %rcx,%r10
15a8: 0f 05 syscall
15aa: c3 retq
00000000000015ab <mkdir>:
SYSCALL(mkdir)
15ab: 48 c7 c0 14 00 00 00 mov $0x14,%rax
15b2: 49 89 ca mov %rcx,%r10
15b5: 0f 05 syscall
15b7: c3 retq
00000000000015b8 <chdir>:
SYSCALL(chdir)
15b8: 48 c7 c0 09 00 00 00 mov $0x9,%rax
15bf: 49 89 ca mov %rcx,%r10
15c2: 0f 05 syscall
15c4: c3 retq
00000000000015c5 <dup>:
SYSCALL(dup)
15c5: 48 c7 c0 0a 00 00 00 mov $0xa,%rax
15cc: 49 89 ca mov %rcx,%r10
15cf: 0f 05 syscall
15d1: c3 retq
00000000000015d2 <getpid>:
SYSCALL(getpid)
15d2: 48 c7 c0 0b 00 00 00 mov $0xb,%rax
15d9: 49 89 ca mov %rcx,%r10
15dc: 0f 05 syscall
15de: c3 retq
00000000000015df <sbrk>:
SYSCALL(sbrk)
15df: 48 c7 c0 0c 00 00 00 mov $0xc,%rax
15e6: 49 89 ca mov %rcx,%r10
15e9: 0f 05 syscall
15eb: c3 retq
00000000000015ec <sleep>:
SYSCALL(sleep)
15ec: 48 c7 c0 0d 00 00 00 mov $0xd,%rax
15f3: 49 89 ca mov %rcx,%r10
15f6: 0f 05 syscall
15f8: c3 retq
00000000000015f9 <uptime>:
SYSCALL(uptime)
15f9: 48 c7 c0 0e 00 00 00 mov $0xe,%rax
1600: 49 89 ca mov %rcx,%r10
1603: 0f 05 syscall
1605: c3 retq
0000000000001606 <aread>:
SYSCALL(aread)
1606: 48 c7 c0 16 00 00 00 mov $0x16,%rax
160d: 49 89 ca mov %rcx,%r10
1610: 0f 05 syscall
1612: c3 retq
0000000000001613 <putc>:
#include <stdarg.h>
static void
putc(int fd, char c)
{
1613: f3 0f 1e fa endbr64
1617: 55 push %rbp
1618: 48 89 e5 mov %rsp,%rbp
161b: 48 83 ec 10 sub $0x10,%rsp
161f: 89 7d fc mov %edi,-0x4(%rbp)
1622: 89 f0 mov %esi,%eax
1624: 88 45 f8 mov %al,-0x8(%rbp)
write(fd, &c, 1);
1627: 48 8d 4d f8 lea -0x8(%rbp),%rcx
162b: 8b 45 fc mov -0x4(%rbp),%eax
162e: ba 01 00 00 00 mov $0x1,%edx
1633: 48 89 ce mov %rcx,%rsi
1636: 89 c7 mov %eax,%edi
1638: 48 b8 36 15 00 00 00 movabs $0x1536,%rax
163f: 00 00 00
1642: ff d0 callq *%rax
}
1644: 90 nop
1645: c9 leaveq
1646: c3 retq
0000000000001647 <print_x64>:
static char digits[] = "0123456789abcdef";
static void
print_x64(int fd, addr_t x)
{
1647: f3 0f 1e fa endbr64
164b: 55 push %rbp
164c: 48 89 e5 mov %rsp,%rbp
164f: 48 83 ec 20 sub $0x20,%rsp
1653: 89 7d ec mov %edi,-0x14(%rbp)
1656: 48 89 75 e0 mov %rsi,-0x20(%rbp)
int i;
for (i = 0; i < (sizeof(addr_t) * 2); i++, x <<= 4)
165a: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%rbp)
1661: eb 35 jmp 1698 <print_x64+0x51>
putc(fd, digits[x >> (sizeof(addr_t) * 8 - 4)]);
1663: 48 8b 45 e0 mov -0x20(%rbp),%rax
1667: 48 c1 e8 3c shr $0x3c,%rax
166b: 48 ba 70 22 00 00 00 movabs $0x2270,%rdx
1672: 00 00 00
1675: 0f b6 04 02 movzbl (%rdx,%rax,1),%eax
1679: 0f be d0 movsbl %al,%edx
167c: 8b 45 ec mov -0x14(%rbp),%eax
167f: 89 d6 mov %edx,%esi
1681: 89 c7 mov %eax,%edi
1683: 48 b8 13 16 00 00 00 movabs $0x1613,%rax
168a: 00 00 00
168d: ff d0 callq *%rax
for (i = 0; i < (sizeof(addr_t) * 2); i++, x <<= 4)
168f: 83 45 fc 01 addl $0x1,-0x4(%rbp)
1693: 48 c1 65 e0 04 shlq $0x4,-0x20(%rbp)
1698: 8b 45 fc mov -0x4(%rbp),%eax
169b: 83 f8 0f cmp $0xf,%eax
169e: 76 c3 jbe 1663 <print_x64+0x1c>
}
16a0: 90 nop
16a1: 90 nop
16a2: c9 leaveq
16a3: c3 retq
00000000000016a4 <print_x32>:
static void
print_x32(int fd, uint x)
{
16a4: f3 0f 1e fa endbr64
16a8: 55 push %rbp
16a9: 48 89 e5 mov %rsp,%rbp
16ac: 48 83 ec 20 sub $0x20,%rsp
16b0: 89 7d ec mov %edi,-0x14(%rbp)
16b3: 89 75 e8 mov %esi,-0x18(%rbp)
int i;
for (i = 0; i < (sizeof(uint) * 2); i++, x <<= 4)
16b6: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%rbp)
16bd: eb 36 jmp 16f5 <print_x32+0x51>
putc(fd, digits[x >> (sizeof(uint) * 8 - 4)]);
16bf: 8b 45 e8 mov -0x18(%rbp),%eax
16c2: c1 e8 1c shr $0x1c,%eax
16c5: 89 c2 mov %eax,%edx
16c7: 48 b8 70 22 00 00 00 movabs $0x2270,%rax
16ce: 00 00 00
16d1: 89 d2 mov %edx,%edx
16d3: 0f b6 04 10 movzbl (%rax,%rdx,1),%eax
16d7: 0f be d0 movsbl %al,%edx
16da: 8b 45 ec mov -0x14(%rbp),%eax
16dd: 89 d6 mov %edx,%esi
16df: 89 c7 mov %eax,%edi
16e1: 48 b8 13 16 00 00 00 movabs $0x1613,%rax
16e8: 00 00 00
16eb: ff d0 callq *%rax
for (i = 0; i < (sizeof(uint) * 2); i++, x <<= 4)
16ed: 83 45 fc 01 addl $0x1,-0x4(%rbp)
16f1: c1 65 e8 04 shll $0x4,-0x18(%rbp)
16f5: 8b 45 fc mov -0x4(%rbp),%eax
16f8: 83 f8 07 cmp $0x7,%eax
16fb: 76 c2 jbe 16bf <print_x32+0x1b>
}
16fd: 90 nop
16fe: 90 nop
16ff: c9 leaveq
1700: c3 retq
0000000000001701 <print_d>:
static void
print_d(int fd, int v)
{
1701: f3 0f 1e fa endbr64
1705: 55 push %rbp
1706: 48 89 e5 mov %rsp,%rbp
1709: 48 83 ec 30 sub $0x30,%rsp
170d: 89 7d dc mov %edi,-0x24(%rbp)
1710: 89 75 d8 mov %esi,-0x28(%rbp)
char buf[16];
int64 x = v;
1713: 8b 45 d8 mov -0x28(%rbp),%eax
1716: 48 98 cltq
1718: 48 89 45 f8 mov %rax,-0x8(%rbp)
if (v < 0)
171c: 83 7d d8 00 cmpl $0x0,-0x28(%rbp)
1720: 79 04 jns 1726 <print_d+0x25>
x = -x;
1722: 48 f7 5d f8 negq -0x8(%rbp)
int i = 0;
1726: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%rbp)
do {
buf[i++] = digits[x % 10];
172d: 48 8b 4d f8 mov -0x8(%rbp),%rcx
1731: 48 ba 67 66 66 66 66 movabs $0x6666666666666667,%rdx
1738: 66 66 66
173b: 48 89 c8 mov %rcx,%rax
173e: 48 f7 ea imul %rdx
1741: 48 c1 fa 02 sar $0x2,%rdx
1745: 48 89 c8 mov %rcx,%rax
1748: 48 c1 f8 3f sar $0x3f,%rax
174c: 48 29 c2 sub %rax,%rdx
174f: 48 89 d0 mov %rdx,%rax
1752: 48 c1 e0 02 shl $0x2,%rax
1756: 48 01 d0 add %rdx,%rax
1759: 48 01 c0 add %rax,%rax
175c: 48 29 c1 sub %rax,%rcx
175f: 48 89 ca mov %rcx,%rdx
1762: 8b 45 f4 mov -0xc(%rbp),%eax
1765: 8d 48 01 lea 0x1(%rax),%ecx
1768: 89 4d f4 mov %ecx,-0xc(%rbp)
176b: 48 b9 70 22 00 00 00 movabs $0x2270,%rcx
1772: 00 00 00
1775: 0f b6 14 11 movzbl (%rcx,%rdx,1),%edx
1779: 48 98 cltq
177b: 88 54 05 e0 mov %dl,-0x20(%rbp,%rax,1)
x /= 10;
177f: 48 8b 4d f8 mov -0x8(%rbp),%rcx
1783: 48 ba 67 66 66 66 66 movabs $0x6666666666666667,%rdx
178a: 66 66 66
178d: 48 89 c8 mov %rcx,%rax
1790: 48 f7 ea imul %rdx
1793: 48 c1 fa 02 sar $0x2,%rdx
1797: 48 89 c8 mov %rcx,%rax
179a: 48 c1 f8 3f sar $0x3f,%rax
179e: 48 29 c2 sub %rax,%rdx
17a1: 48 89 d0 mov %rdx,%rax
17a4: 48 89 45 f8 mov %rax,-0x8(%rbp)
} while(x != 0);
17a8: 48 83 7d f8 00 cmpq $0x0,-0x8(%rbp)
17ad: 0f 85 7a ff ff ff jne 172d <print_d+0x2c>
if (v < 0)
17b3: 83 7d d8 00 cmpl $0x0,-0x28(%rbp)
17b7: 79 32 jns 17eb <print_d+0xea>
buf[i++] = '-';
17b9: 8b 45 f4 mov -0xc(%rbp),%eax
17bc: 8d 50 01 lea 0x1(%rax),%edx
17bf: 89 55 f4 mov %edx,-0xc(%rbp)
17c2: 48 98 cltq
17c4: c6 44 05 e0 2d movb $0x2d,-0x20(%rbp,%rax,1)
while (--i >= 0)
17c9: eb 20 jmp 17eb <print_d+0xea>
putc(fd, buf[i]);
17cb: 8b 45 f4 mov -0xc(%rbp),%eax
17ce: 48 98 cltq
17d0: 0f b6 44 05 e0 movzbl -0x20(%rbp,%rax,1),%eax
17d5: 0f be d0 movsbl %al,%edx
17d8: 8b 45 dc mov -0x24(%rbp),%eax
17db: 89 d6 mov %edx,%esi
17dd: 89 c7 mov %eax,%edi
17df: 48 b8 13 16 00 00 00 movabs $0x1613,%rax
17e6: 00 00 00
17e9: ff d0 callq *%rax
while (--i >= 0)
17eb: 83 6d f4 01 subl $0x1,-0xc(%rbp)
17ef: 83 7d f4 00 cmpl $0x0,-0xc(%rbp)
17f3: 79 d6 jns 17cb <print_d+0xca>
}
17f5: 90 nop
17f6: 90 nop
17f7: c9 leaveq
17f8: c3 retq
00000000000017f9 <printf>:
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
17f9: f3 0f 1e fa endbr64
17fd: 55 push %rbp
17fe: 48 89 e5 mov %rsp,%rbp
1801: 48 81 ec f0 00 00 00 sub $0xf0,%rsp
1808: 89 bd 1c ff ff ff mov %edi,-0xe4(%rbp)
180e: 48 89 b5 10 ff ff ff mov %rsi,-0xf0(%rbp)
1815: 48 89 95 60 ff ff ff mov %rdx,-0xa0(%rbp)
181c: 48 89 8d 68 ff ff ff mov %rcx,-0x98(%rbp)
1823: 4c 89 85 70 ff ff ff mov %r8,-0x90(%rbp)
182a: 4c 89 8d 78 ff ff ff mov %r9,-0x88(%rbp)
1831: 84 c0 test %al,%al
1833: 74 20 je 1855 <printf+0x5c>
1835: 0f 29 45 80 movaps %xmm0,-0x80(%rbp)
1839: 0f 29 4d 90 movaps %xmm1,-0x70(%rbp)
183d: 0f 29 55 a0 movaps %xmm2,-0x60(%rbp)
1841: 0f 29 5d b0 movaps %xmm3,-0x50(%rbp)
1845: 0f 29 65 c0 movaps %xmm4,-0x40(%rbp)
1849: 0f 29 6d d0 movaps %xmm5,-0x30(%rbp)
184d: 0f 29 75 e0 movaps %xmm6,-0x20(%rbp)
1851: 0f 29 7d f0 movaps %xmm7,-0x10(%rbp)
va_list ap;
int i, c;
char *s;
va_start(ap, fmt);
1855: c7 85 20 ff ff ff 10 movl $0x10,-0xe0(%rbp)
185c: 00 00 00
185f: c7 85 24 ff ff ff 30 movl $0x30,-0xdc(%rbp)
1866: 00 00 00
1869: 48 8d 45 10 lea 0x10(%rbp),%rax
186d: 48 89 85 28 ff ff ff mov %rax,-0xd8(%rbp)
1874: 48 8d 85 50 ff ff ff lea -0xb0(%rbp),%rax
187b: 48 89 85 30 ff ff ff mov %rax,-0xd0(%rbp)
for (i = 0; (c = fmt[i] & 0xff) != 0; i++) {
1882: c7 85 4c ff ff ff 00 movl $0x0,-0xb4(%rbp)
1889: 00 00 00
188c: e9 41 03 00 00 jmpq 1bd2 <printf+0x3d9>
if (c != '%') {
1891: 83 bd 3c ff ff ff 25 cmpl $0x25,-0xc4(%rbp)
1898: 74 24 je 18be <printf+0xc5>
putc(fd, c);
189a: 8b 85 3c ff ff ff mov -0xc4(%rbp),%eax
18a0: 0f be d0 movsbl %al,%edx
18a3: 8b 85 1c ff ff ff mov -0xe4(%rbp),%eax
18a9: 89 d6 mov %edx,%esi
18ab: 89 c7 mov %eax,%edi
18ad: 48 b8 13 16 00 00 00 movabs $0x1613,%rax
18b4: 00 00 00
18b7: ff d0 callq *%rax
continue;
18b9: e9 0d 03 00 00 jmpq 1bcb <printf+0x3d2>
}
c = fmt[++i] & 0xff;
18be: 83 85 4c ff ff ff 01 addl $0x1,-0xb4(%rbp)
18c5: 8b 85 4c ff ff ff mov -0xb4(%rbp),%eax
18cb: 48 63 d0 movslq %eax,%rdx
18ce: 48 8b 85 10 ff ff ff mov -0xf0(%rbp),%rax
18d5: 48 01 d0 add %rdx,%rax
18d8: 0f b6 00 movzbl (%rax),%eax
18db: 0f be c0 movsbl %al,%eax
18de: 25 ff 00 00 00 and $0xff,%eax
18e3: 89 85 3c ff ff ff mov %eax,-0xc4(%rbp)
if (c == 0)
18e9: 83 bd 3c ff ff ff 00 cmpl $0x0,-0xc4(%rbp)
18f0: 0f 84 0f 03 00 00 je 1c05 <printf+0x40c>
break;
switch(c) {
18f6: 83 bd 3c ff ff ff 25 cmpl $0x25,-0xc4(%rbp)
18fd: 0f 84 74 02 00 00 je 1b77 <printf+0x37e>
1903: 83 bd 3c ff ff ff 25 cmpl $0x25,-0xc4(%rbp)
190a: 0f 8c 82 02 00 00 jl 1b92 <printf+0x399>
1910: 83 bd 3c ff ff ff 78 cmpl $0x78,-0xc4(%rbp)
1917: 0f 8f 75 02 00 00 jg 1b92 <printf+0x399>
191d: 83 bd 3c ff ff ff 63 cmpl $0x63,-0xc4(%rbp)
1924: 0f 8c 68 02 00 00 jl 1b92 <printf+0x399>
192a: 8b 85 3c ff ff ff mov -0xc4(%rbp),%eax
1930: 83 e8 63 sub $0x63,%eax
1933: 83 f8 15 cmp $0x15,%eax
1936: 0f 87 56 02 00 00 ja 1b92 <printf+0x399>
193c: 89 c0 mov %eax,%eax
193e: 48 8d 14 c5 00 00 00 lea 0x0(,%rax,8),%rdx
1945: 00
1946: 48 b8 40 1f 00 00 00 movabs $0x1f40,%rax
194d: 00 00 00
1950: 48 01 d0 add %rdx,%rax
1953: 48 8b 00 mov (%rax),%rax
1956: 3e ff e0 notrack jmpq *%rax
case 'c':
putc(fd, va_arg(ap, int));
1959: 8b 85 20 ff ff ff mov -0xe0(%rbp),%eax
195f: 83 f8 2f cmp $0x2f,%eax
1962: 77 23 ja 1987 <printf+0x18e>
1964: 48 8b 85 30 ff ff ff mov -0xd0(%rbp),%rax
196b: 8b 95 20 ff ff ff mov -0xe0(%rbp),%edx
1971: 89 d2 mov %edx,%edx
1973: 48 01 d0 add %rdx,%rax
1976: 8b 95 20 ff ff ff mov -0xe0(%rbp),%edx
197c: 83 c2 08 add $0x8,%edx
197f: 89 95 20 ff ff ff mov %edx,-0xe0(%rbp)
1985: eb 12 jmp 1999 <printf+0x1a0>
1987: 48 8b 85 28 ff ff ff mov -0xd8(%rbp),%rax
198e: 48 8d 50 08 lea 0x8(%rax),%rdx
1992: 48 89 95 28 ff ff ff mov %rdx,-0xd8(%rbp)
1999: 8b 00 mov (%rax),%eax
199b: 0f be d0 movsbl %al,%edx
199e: 8b 85 1c ff ff ff mov -0xe4(%rbp),%eax
19a4: 89 d6 mov %edx,%esi
19a6: 89 c7 mov %eax,%edi
19a8: 48 b8 13 16 00 00 00 movabs $0x1613,%rax
19af: 00 00 00
19b2: ff d0 callq *%rax
break;
19b4: e9 12 02 00 00 jmpq 1bcb <printf+0x3d2>
case 'd':
print_d(fd, va_arg(ap, int));
19b9: 8b 85 20 ff ff ff mov -0xe0(%rbp),%eax
19bf: 83 f8 2f cmp $0x2f,%eax
19c2: 77 23 ja 19e7 <printf+0x1ee>
19c4: 48 8b 85 30 ff ff ff mov -0xd0(%rbp),%rax
19cb: 8b 95 20 ff ff ff mov -0xe0(%rbp),%edx
19d1: 89 d2 mov %edx,%edx
19d3: 48 01 d0 add %rdx,%rax
19d6: 8b 95 20 ff ff ff mov -0xe0(%rbp),%edx
19dc: 83 c2 08 add $0x8,%edx
19df: 89 95 20 ff ff ff mov %edx,-0xe0(%rbp)
19e5: eb 12 jmp 19f9 <printf+0x200>
19e7: 48 8b 85 28 ff ff ff mov -0xd8(%rbp),%rax
19ee: 48 8d 50 08 lea 0x8(%rax),%rdx
19f2: 48 89 95 28 ff ff ff mov %rdx,-0xd8(%rbp)
19f9: 8b 10 mov (%rax),%edx
19fb: 8b 85 1c ff ff ff mov -0xe4(%rbp),%eax
1a01: 89 d6 mov %edx,%esi
1a03: 89 c7 mov %eax,%edi
1a05: 48 b8 01 17 00 00 00 movabs $0x1701,%rax
1a0c: 00 00 00
1a0f: ff d0 callq *%rax
break;
1a11: e9 b5 01 00 00 jmpq 1bcb <printf+0x3d2>
case 'x':
print_x32(fd, va_arg(ap, uint));
1a16: 8b 85 20 ff ff ff mov -0xe0(%rbp),%eax
1a1c: 83 f8 2f cmp $0x2f,%eax
1a1f: 77 23 ja 1a44 <printf+0x24b>
1a21: 48 8b 85 30 ff ff ff mov -0xd0(%rbp),%rax
1a28: 8b 95 20 ff ff ff mov -0xe0(%rbp),%edx
1a2e: 89 d2 mov %edx,%edx
1a30: 48 01 d0 add %rdx,%rax
1a33: 8b 95 20 ff ff ff mov -0xe0(%rbp),%edx
1a39: 83 c2 08 add $0x8,%edx
1a3c: 89 95 20 ff ff ff mov %edx,-0xe0(%rbp)
1a42: eb 12 jmp 1a56 <printf+0x25d>
1a44: 48 8b 85 28 ff ff ff mov -0xd8(%rbp),%rax
1a4b: 48 8d 50 08 lea 0x8(%rax),%rdx
1a4f: 48 89 95 28 ff ff ff mov %rdx,-0xd8(%rbp)
1a56: 8b 10 mov (%rax),%edx
1a58: 8b 85 1c ff ff ff mov -0xe4(%rbp),%eax
1a5e: 89 d6 mov %edx,%esi
1a60: 89 c7 mov %eax,%edi
1a62: 48 b8 a4 16 00 00 00 movabs $0x16a4,%rax
1a69: 00 00 00
1a6c: ff d0 callq *%rax
break;
1a6e: e9 58 01 00 00 jmpq 1bcb <printf+0x3d2>
case 'p':
print_x64(fd, va_arg(ap, addr_t));
1a73: 8b 85 20 ff ff ff mov -0xe0(%rbp),%eax
1a79: 83 f8 2f cmp $0x2f,%eax
1a7c: 77 23 ja 1aa1 <printf+0x2a8>
1a7e: 48 8b 85 30 ff ff ff mov -0xd0(%rbp),%rax
1a85: 8b 95 20 ff ff ff mov -0xe0(%rbp),%edx
1a8b: 89 d2 mov %edx,%edx
1a8d: 48 01 d0 add %rdx,%rax
1a90: 8b 95 20 ff ff ff mov -0xe0(%rbp),%edx
1a96: 83 c2 08 add $0x8,%edx
1a99: 89 95 20 ff ff ff mov %edx,-0xe0(%rbp)
1a9f: eb 12 jmp 1ab3 <printf+0x2ba>
1aa1: 48 8b 85 28 ff ff ff mov -0xd8(%rbp),%rax
1aa8: 48 8d 50 08 lea 0x8(%rax),%rdx
1aac: 48 89 95 28 ff ff ff mov %rdx,-0xd8(%rbp)
1ab3: 48 8b 10 mov (%rax),%rdx
1ab6: 8b 85 1c ff ff ff mov -0xe4(%rbp),%eax
1abc: 48 89 d6 mov %rdx,%rsi
1abf: 89 c7 mov %eax,%edi
1ac1: 48 b8 47 16 00 00 00 movabs $0x1647,%rax
1ac8: 00 00 00
1acb: ff d0 callq *%rax
break;
1acd: e9 f9 00 00 00 jmpq 1bcb <printf+0x3d2>
case 's':
if ((s = va_arg(ap, char*)) == 0)
1ad2: 8b 85 20 ff ff ff mov -0xe0(%rbp),%eax
1ad8: 83 f8 2f cmp $0x2f,%eax
1adb: 77 23 ja 1b00 <printf+0x307>
1add: 48 8b 85 30 ff ff ff mov -0xd0(%rbp),%rax
1ae4: 8b 95 20 ff ff ff mov -0xe0(%rbp),%edx
1aea: 89 d2 mov %edx,%edx
1aec: 48 01 d0 add %rdx,%rax
1aef: 8b 95 20 ff ff ff mov -0xe0(%rbp),%edx
1af5: 83 c2 08 add $0x8,%edx
1af8: 89 95 20 ff ff ff mov %edx,-0xe0(%rbp)
1afe: eb 12 jmp 1b12 <printf+0x319>
1b00: 48 8b 85 28 ff ff ff mov -0xd8(%rbp),%rax
1b07: 48 8d 50 08 lea 0x8(%rax),%rdx
1b0b: 48 89 95 28 ff ff ff mov %rdx,-0xd8(%rbp)
1b12: 48 8b 00 mov (%rax),%rax
1b15: 48 89 85 40 ff ff ff mov %rax,-0xc0(%rbp)
1b1c: 48 83 bd 40 ff ff ff cmpq $0x0,-0xc0(%rbp)
1b23: 00
1b24: 75 41 jne 1b67 <printf+0x36e>
s = "(null)";
1b26: 48 b8 38 1f 00 00 00 movabs $0x1f38,%rax
1b2d: 00 00 00
1b30: 48 89 85 40 ff ff ff mov %rax,-0xc0(%rbp)
while (*s)
1b37: eb 2e jmp 1b67 <printf+0x36e>
putc(fd, *(s++));
1b39: 48 8b 85 40 ff ff ff mov -0xc0(%rbp),%rax
1b40: 48 8d 50 01 lea 0x1(%rax),%rdx
1b44: 48 89 95 40 ff ff ff mov %rdx,-0xc0(%rbp)
1b4b: 0f b6 00 movzbl (%rax),%eax
1b4e: 0f be d0 movsbl %al,%edx
1b51: 8b 85 1c ff ff ff mov -0xe4(%rbp),%eax
1b57: 89 d6 mov %edx,%esi
1b59: 89 c7 mov %eax,%edi
1b5b: 48 b8 13 16 00 00 00 movabs $0x1613,%rax
1b62: 00 00 00
1b65: ff d0 callq *%rax
while (*s)
1b67: 48 8b 85 40 ff ff ff mov -0xc0(%rbp),%rax
1b6e: 0f b6 00 movzbl (%rax),%eax
1b71: 84 c0 test %al,%al
1b73: 75 c4 jne 1b39 <printf+0x340>
break;
1b75: eb 54 jmp 1bcb <printf+0x3d2>
case '%':
putc(fd, '%');
1b77: 8b 85 1c ff ff ff mov -0xe4(%rbp),%eax
1b7d: be 25 00 00 00 mov $0x25,%esi
1b82: 89 c7 mov %eax,%edi
1b84: 48 b8 13 16 00 00 00 movabs $0x1613,%rax
1b8b: 00 00 00
1b8e: ff d0 callq *%rax
break;
1b90: eb 39 jmp 1bcb <printf+0x3d2>
default:
// Print unknown % sequence to draw attention.
putc(fd, '%');
1b92: 8b 85 1c ff ff ff mov -0xe4(%rbp),%eax
1b98: be 25 00 00 00 mov $0x25,%esi
1b9d: 89 c7 mov %eax,%edi
1b9f: 48 b8 13 16 00 00 00 movabs $0x1613,%rax
1ba6: 00 00 00
1ba9: ff d0 callq *%rax
putc(fd, c);
1bab: 8b 85 3c ff ff ff mov -0xc4(%rbp),%eax
1bb1: 0f be d0 movsbl %al,%edx
1bb4: 8b 85 1c ff ff ff mov -0xe4(%rbp),%eax
1bba: 89 d6 mov %edx,%esi
1bbc: 89 c7 mov %eax,%edi
1bbe: 48 b8 13 16 00 00 00 movabs $0x1613,%rax
1bc5: 00 00 00
1bc8: ff d0 callq *%rax
break;
1bca: 90 nop
for (i = 0; (c = fmt[i] & 0xff) != 0; i++) {
1bcb: 83 85 4c ff ff ff 01 addl $0x1,-0xb4(%rbp)
1bd2: 8b 85 4c ff ff ff mov -0xb4(%rbp),%eax
1bd8: 48 63 d0 movslq %eax,%rdx
1bdb: 48 8b 85 10 ff ff ff mov -0xf0(%rbp),%rax
1be2: 48 01 d0 add %rdx,%rax
1be5: 0f b6 00 movzbl (%rax),%eax
1be8: 0f be c0 movsbl %al,%eax
1beb: 25 ff 00 00 00 and $0xff,%eax
1bf0: 89 85 3c ff ff ff mov %eax,-0xc4(%rbp)
1bf6: 83 bd 3c ff ff ff 00 cmpl $0x0,-0xc4(%rbp)
1bfd: 0f 85 8e fc ff ff jne 1891 <printf+0x98>
}
}
}
1c03: eb 01 jmp 1c06 <printf+0x40d>
break;
1c05: 90 nop
}
1c06: 90 nop
1c07: c9 leaveq
1c08: c3 retq
0000000000001c09 <free>:
static Header base;
static Header *freep;
void
free(void *ap)
{
1c09: f3 0f 1e fa endbr64
1c0d: 55 push %rbp
1c0e: 48 89 e5 mov %rsp,%rbp
1c11: 48 83 ec 18 sub $0x18,%rsp
1c15: 48 89 7d e8 mov %rdi,-0x18(%rbp)
Header *bp, *p;
bp = (Header*)ap - 1;
1c19: 48 8b 45 e8 mov -0x18(%rbp),%rax
1c1d: 48 83 e8 10 sub $0x10,%rax
1c21: 48 89 45 f0 mov %rax,-0x10(%rbp)
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
1c25: 48 b8 a0 22 00 00 00 movabs $0x22a0,%rax
1c2c: 00 00 00
1c2f: 48 8b 00 mov (%rax),%rax
1c32: 48 89 45 f8 mov %rax,-0x8(%rbp)
1c36: eb 2f jmp 1c67 <free+0x5e>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
1c38: 48 8b 45 f8 mov -0x8(%rbp),%rax
1c3c: 48 8b 00 mov (%rax),%rax
1c3f: 48 39 45 f8 cmp %rax,-0x8(%rbp)
1c43: 72 17 jb 1c5c <free+0x53>
1c45: 48 8b 45 f0 mov -0x10(%rbp),%rax
1c49: 48 3b 45 f8 cmp -0x8(%rbp),%rax
1c4d: 77 2f ja 1c7e <free+0x75>
1c4f: 48 8b 45 f8 mov -0x8(%rbp),%rax
1c53: 48 8b 00 mov (%rax),%rax
1c56: 48 39 45 f0 cmp %rax,-0x10(%rbp)
1c5a: 72 22 jb 1c7e <free+0x75>
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
1c5c: 48 8b 45 f8 mov -0x8(%rbp),%rax
1c60: 48 8b 00 mov (%rax),%rax
1c63: 48 89 45 f8 mov %rax,-0x8(%rbp)
1c67: 48 8b 45 f0 mov -0x10(%rbp),%rax
1c6b: 48 3b 45 f8 cmp -0x8(%rbp),%rax
1c6f: 76 c7 jbe 1c38 <free+0x2f>
1c71: 48 8b 45 f8 mov -0x8(%rbp),%rax
1c75: 48 8b 00 mov (%rax),%rax
1c78: 48 39 45 f0 cmp %rax,-0x10(%rbp)
1c7c: 73 ba jae 1c38 <free+0x2f>
break;
if(bp + bp->s.size == p->s.ptr){
1c7e: 48 8b 45 f0 mov -0x10(%rbp),%rax
1c82: 8b 40 08 mov 0x8(%rax),%eax
1c85: 89 c0 mov %eax,%eax
1c87: 48 c1 e0 04 shl $0x4,%rax
1c8b: 48 89 c2 mov %rax,%rdx
1c8e: 48 8b 45 f0 mov -0x10(%rbp),%rax
1c92: 48 01 c2 add %rax,%rdx
1c95: 48 8b 45 f8 mov -0x8(%rbp),%rax
1c99: 48 8b 00 mov (%rax),%rax
1c9c: 48 39 c2 cmp %rax,%rdx
1c9f: 75 2d jne 1cce <free+0xc5>
bp->s.size += p->s.ptr->s.size;
1ca1: 48 8b 45 f0 mov -0x10(%rbp),%rax
1ca5: 8b 50 08 mov 0x8(%rax),%edx
1ca8: 48 8b 45 f8 mov -0x8(%rbp),%rax
1cac: 48 8b 00 mov (%rax),%rax
1caf: 8b 40 08 mov 0x8(%rax),%eax
1cb2: 01 c2 add %eax,%edx
1cb4: 48 8b 45 f0 mov -0x10(%rbp),%rax
1cb8: 89 50 08 mov %edx,0x8(%rax)
bp->s.ptr = p->s.ptr->s.ptr;
1cbb: 48 8b 45 f8 mov -0x8(%rbp),%rax
1cbf: 48 8b 00 mov (%rax),%rax
1cc2: 48 8b 10 mov (%rax),%rdx
1cc5: 48 8b 45 f0 mov -0x10(%rbp),%rax
1cc9: 48 89 10 mov %rdx,(%rax)
1ccc: eb 0e jmp 1cdc <free+0xd3>
} else
bp->s.ptr = p->s.ptr;
1cce: 48 8b 45 f8 mov -0x8(%rbp),%rax
1cd2: 48 8b 10 mov (%rax),%rdx
1cd5: 48 8b 45 f0 mov -0x10(%rbp),%rax
1cd9: 48 89 10 mov %rdx,(%rax)
if(p + p->s.size == bp){
1cdc: 48 8b 45 f8 mov -0x8(%rbp),%rax
1ce0: 8b 40 08 mov 0x8(%rax),%eax
1ce3: 89 c0 mov %eax,%eax
1ce5: 48 c1 e0 04 shl $0x4,%rax
1ce9: 48 89 c2 mov %rax,%rdx
1cec: 48 8b 45 f8 mov -0x8(%rbp),%rax
1cf0: 48 01 d0 add %rdx,%rax
1cf3: 48 39 45 f0 cmp %rax,-0x10(%rbp)
1cf7: 75 27 jne 1d20 <free+0x117>
p->s.size += bp->s.size;
1cf9: 48 8b 45 f8 mov -0x8(%rbp),%rax
1cfd: 8b 50 08 mov 0x8(%rax),%edx
1d00: 48 8b 45 f0 mov -0x10(%rbp),%rax
1d04: 8b 40 08 mov 0x8(%rax),%eax
1d07: 01 c2 add %eax,%edx
1d09: 48 8b 45 f8 mov -0x8(%rbp),%rax
1d0d: 89 50 08 mov %edx,0x8(%rax)
p->s.ptr = bp->s.ptr;
1d10: 48 8b 45 f0 mov -0x10(%rbp),%rax
1d14: 48 8b 10 mov (%rax),%rdx
1d17: 48 8b 45 f8 mov -0x8(%rbp),%rax
1d1b: 48 89 10 mov %rdx,(%rax)
1d1e: eb 0b jmp 1d2b <free+0x122>
} else
p->s.ptr = bp;
1d20: 48 8b 45 f8 mov -0x8(%rbp),%rax
1d24: 48 8b 55 f0 mov -0x10(%rbp),%rdx
1d28: 48 89 10 mov %rdx,(%rax)
freep = p;
1d2b: 48 ba a0 22 00 00 00 movabs $0x22a0,%rdx
1d32: 00 00 00
1d35: 48 8b 45 f8 mov -0x8(%rbp),%rax
1d39: 48 89 02 mov %rax,(%rdx)
}
1d3c: 90 nop
1d3d: c9 leaveq
1d3e: c3 retq
0000000000001d3f <morecore>:
static Header*
morecore(uint nu)
{
1d3f: f3 0f 1e fa endbr64
1d43: 55 push %rbp
1d44: 48 89 e5 mov %rsp,%rbp
1d47: 48 83 ec 20 sub $0x20,%rsp
1d4b: 89 7d ec mov %edi,-0x14(%rbp)
char *p;
Header *hp;
if(nu < 4096)
1d4e: 81 7d ec ff 0f 00 00 cmpl $0xfff,-0x14(%rbp)
1d55: 77 07 ja 1d5e <morecore+0x1f>
nu = 4096;
1d57: c7 45 ec 00 10 00 00 movl $0x1000,-0x14(%rbp)
p = sbrk(nu * sizeof(Header));
1d5e: 8b 45 ec mov -0x14(%rbp),%eax
1d61: 48 c1 e0 04 shl $0x4,%rax
1d65: 48 89 c7 mov %rax,%rdi
1d68: 48 b8 df 15 00 00 00 movabs $0x15df,%rax
1d6f: 00 00 00
1d72: ff d0 callq *%rax
1d74: 48 89 45 f8 mov %rax,-0x8(%rbp)
if(p == (char*)-1)
1d78: 48 83 7d f8 ff cmpq $0xffffffffffffffff,-0x8(%rbp)
1d7d: 75 07 jne 1d86 <morecore+0x47>
return 0;
1d7f: b8 00 00 00 00 mov $0x0,%eax
1d84: eb 36 jmp 1dbc <morecore+0x7d>
hp = (Header*)p;
1d86: 48 8b 45 f8 mov -0x8(%rbp),%rax
1d8a: 48 89 45 f0 mov %rax,-0x10(%rbp)
hp->s.size = nu;
1d8e: 48 8b 45 f0 mov -0x10(%rbp),%rax
1d92: 8b 55 ec mov -0x14(%rbp),%edx
1d95: 89 50 08 mov %edx,0x8(%rax)
free((void*)(hp + 1));
1d98: 48 8b 45 f0 mov -0x10(%rbp),%rax
1d9c: 48 83 c0 10 add $0x10,%rax
1da0: 48 89 c7 mov %rax,%rdi
1da3: 48 b8 09 1c 00 00 00 movabs $0x1c09,%rax
1daa: 00 00 00
1dad: ff d0 callq *%rax
return freep;
1daf: 48 b8 a0 22 00 00 00 movabs $0x22a0,%rax
1db6: 00 00 00
1db9: 48 8b 00 mov (%rax),%rax
}
1dbc: c9 leaveq
1dbd: c3 retq
0000000000001dbe <malloc>:
void*
malloc(uint nbytes)
{
1dbe: f3 0f 1e fa endbr64
1dc2: 55 push %rbp
1dc3: 48 89 e5 mov %rsp,%rbp
1dc6: 48 83 ec 30 sub $0x30,%rsp
1dca: 89 7d dc mov %edi,-0x24(%rbp)
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
1dcd: 8b 45 dc mov -0x24(%rbp),%eax
1dd0: 48 83 c0 0f add $0xf,%rax
1dd4: 48 c1 e8 04 shr $0x4,%rax
1dd8: 83 c0 01 add $0x1,%eax
1ddb: 89 45 ec mov %eax,-0x14(%rbp)
if((prevp = freep) == 0){
1dde: 48 b8 a0 22 00 00 00 movabs $0x22a0,%rax
1de5: 00 00 00
1de8: 48 8b 00 mov (%rax),%rax
1deb: 48 89 45 f0 mov %rax,-0x10(%rbp)
1def: 48 83 7d f0 00 cmpq $0x0,-0x10(%rbp)
1df4: 75 4a jne 1e40 <malloc+0x82>
base.s.ptr = freep = prevp = &base;
1df6: 48 b8 90 22 00 00 00 movabs $0x2290,%rax
1dfd: 00 00 00
1e00: 48 89 45 f0 mov %rax,-0x10(%rbp)
1e04: 48 ba a0 22 00 00 00 movabs $0x22a0,%rdx
1e0b: 00 00 00
1e0e: 48 8b 45 f0 mov -0x10(%rbp),%rax
1e12: 48 89 02 mov %rax,(%rdx)
1e15: 48 b8 a0 22 00 00 00 movabs $0x22a0,%rax
1e1c: 00 00 00
1e1f: 48 8b 00 mov (%rax),%rax
1e22: 48 ba 90 22 00 00 00 movabs $0x2290,%rdx
1e29: 00 00 00
1e2c: 48 89 02 mov %rax,(%rdx)
base.s.size = 0;
1e2f: 48 b8 90 22 00 00 00 movabs $0x2290,%rax
1e36: 00 00 00
1e39: c7 40 08 00 00 00 00 movl $0x0,0x8(%rax)
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
1e40: 48 8b 45 f0 mov -0x10(%rbp),%rax
1e44: 48 8b 00 mov (%rax),%rax
1e47: 48 89 45 f8 mov %rax,-0x8(%rbp)
if(p->s.size >= nunits){
1e4b: 48 8b 45 f8 mov -0x8(%rbp),%rax
1e4f: 8b 40 08 mov 0x8(%rax),%eax
1e52: 39 45 ec cmp %eax,-0x14(%rbp)
1e55: 77 65 ja 1ebc <malloc+0xfe>
if(p->s.size == nunits)
1e57: 48 8b 45 f8 mov -0x8(%rbp),%rax
1e5b: 8b 40 08 mov 0x8(%rax),%eax
1e5e: 39 45 ec cmp %eax,-0x14(%rbp)
1e61: 75 10 jne 1e73 <malloc+0xb5>
prevp->s.ptr = p->s.ptr;
1e63: 48 8b 45 f8 mov -0x8(%rbp),%rax
1e67: 48 8b 10 mov (%rax),%rdx
1e6a: 48 8b 45 f0 mov -0x10(%rbp),%rax
1e6e: 48 89 10 mov %rdx,(%rax)
1e71: eb 2e jmp 1ea1 <malloc+0xe3>
else {
p->s.size -= nunits;
1e73: 48 8b 45 f8 mov -0x8(%rbp),%rax
1e77: 8b 40 08 mov 0x8(%rax),%eax
1e7a: 2b 45 ec sub -0x14(%rbp),%eax
1e7d: 89 c2 mov %eax,%edx
1e7f: 48 8b 45 f8 mov -0x8(%rbp),%rax
1e83: 89 50 08 mov %edx,0x8(%rax)
p += p->s.size;
1e86: 48 8b 45 f8 mov -0x8(%rbp),%rax
1e8a: 8b 40 08 mov 0x8(%rax),%eax
1e8d: 89 c0 mov %eax,%eax
1e8f: 48 c1 e0 04 shl $0x4,%rax
1e93: 48 01 45 f8 add %rax,-0x8(%rbp)
p->s.size = nunits;
1e97: 48 8b 45 f8 mov -0x8(%rbp),%rax
1e9b: 8b 55 ec mov -0x14(%rbp),%edx
1e9e: 89 50 08 mov %edx,0x8(%rax)
}
freep = prevp;
1ea1: 48 ba a0 22 00 00 00 movabs $0x22a0,%rdx
1ea8: 00 00 00
1eab: 48 8b 45 f0 mov -0x10(%rbp),%rax
1eaf: 48 89 02 mov %rax,(%rdx)
return (void*)(p + 1);
1eb2: 48 8b 45 f8 mov -0x8(%rbp),%rax
1eb6: 48 83 c0 10 add $0x10,%rax
1eba: eb 4e jmp 1f0a <malloc+0x14c>
}
if(p == freep)
1ebc: 48 b8 a0 22 00 00 00 movabs $0x22a0,%rax
1ec3: 00 00 00
1ec6: 48 8b 00 mov (%rax),%rax
1ec9: 48 39 45 f8 cmp %rax,-0x8(%rbp)
1ecd: 75 23 jne 1ef2 <malloc+0x134>
if((p = morecore(nunits)) == 0)
1ecf: 8b 45 ec mov -0x14(%rbp),%eax
1ed2: 89 c7 mov %eax,%edi
1ed4: 48 b8 3f 1d 00 00 00 movabs $0x1d3f,%rax
1edb: 00 00 00
1ede: ff d0 callq *%rax
1ee0: 48 89 45 f8 mov %rax,-0x8(%rbp)
1ee4: 48 83 7d f8 00 cmpq $0x0,-0x8(%rbp)
1ee9: 75 07 jne 1ef2 <malloc+0x134>
return 0;
1eeb: b8 00 00 00 00 mov $0x0,%eax
1ef0: eb 18 jmp 1f0a <malloc+0x14c>
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
1ef2: 48 8b 45 f8 mov -0x8(%rbp),%rax
1ef6: 48 89 45 f0 mov %rax,-0x10(%rbp)
1efa: 48 8b 45 f8 mov -0x8(%rbp),%rax
1efe: 48 8b 00 mov (%rax),%rax
1f01: 48 89 45 f8 mov %rax,-0x8(%rbp)
if(p->s.size >= nunits){
1f05: e9 41 ff ff ff jmpq 1e4b <malloc+0x8d>
}
}
1f0a: c9 leaveq
1f0b: c3 retq
|
DEVICE ZXSPECTRUM48
SLOT 0
PAGE 0 : ORG 0x0000 : DB "00"
PAGE 1 : ORG 0x0000 : DB "11"
PAGE 2 : ORG 0x0000 : DB "22"
PAGE 3 : ORG 0x0000 : DB "33"
PAGE 4 ; error - non-existing page (page 3 should be still visible in slot 0)
ASSERT {0} == "33"
SLOT 1 : PAGE 0 : ASSERT {0x4000} == "00" : PAGE 1 : ASSERT {0x4000} == "11"
SLOT 2 : PAGE 2 : ASSERT {0x8000} == "22" : PAGE 3 : ASSERT {0x8000} == "33"
SLOT 3 : PAGE 0 : ASSERT {0xC000} == "00" : PAGE 1 : ASSERT {0xC000} == "11"
SLOT 4 ; error
; pages: 3:1:3:1
ORG 0xC000-2
DB "AABB"
ASSERT {0x4000-2} == "AA" ; should be visible also at these addresses
ASSERT {0x4000} == "BB"
ORG 0xFFFE
DB "CCDD" ; "DD" goes beyond 0x10000 -> lost (error reported)
ASSERT {0} == "33" ; still page 3 there
; now try the 128 classic (should be not affected by the 48 device above)
DEVICE ZXSPECTRUM128
SLOT 0
PAGE 0 : ASSERT {0} == 0 : ORG 0x0000 : DB "00"
PAGE 1 : ASSERT {0} == 0 : ORG 0x0000 : DB "11"
PAGE 2 : ASSERT {0} == 0 : ORG 0x0000 : DB "22"
PAGE 3 : ASSERT {0} == 0 : ORG 0x0000 : DB "33"
PAGE 4 : ASSERT {0} == 0 : ORG 0x0000 : DB "44"
PAGE 5 : ASSERT {0} == 0 : ORG 0x0000 : DB "55"
PAGE 6 : ASSERT {0} == 0 : ORG 0x0000 : DB "66"
PAGE 7 : ASSERT {0} == 0 : ORG 0x0000 : DB "77"
PAGE 8 ; error - non-existing page (page 7 should be still visible in slot 0)
ASSERT {0} == "77"
SLOT 1 : PAGE 4 : ASSERT {0x4000} == "44" : PAGE 5 : ASSERT {0x4000} == "55"
SLOT 2 : PAGE 6 : ASSERT {0x8000} == "66" : PAGE 7 : ASSERT {0x8000} == "77"
SLOT 3 : PAGE 4 : ASSERT {0xC000} == "44" : PAGE 5 : ASSERT {0xC000} == "55"
SLOT 4 ; error
; pages: 7:5:7:5
ORG 0xC000-2
DB "AABB"
ASSERT {0x4000-2} == "AA" ; should be visible also at these addresses
ASSERT {0x4000} == "BB"
ORG 0xFFFE
DB "CCDD" ; "DD" goes beyond 0x10000 -> lost (error reported)
ASSERT {0} == "77" ; still page 7 there
; some more error states
ORG & : PAGE & : ORG 0x1234, & : DISP & : SLOT & ; syntax errors
ENT
DEVICE none
PAGE 1 : SLOT 1
|
/*!
@file
Defines `boost::hana::detail::has_duplicates`.
@copyright Louis Dionne 2013-2017
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_HANA_DETAIL_HAS_DUPLICATES_HPP
#define BOOST_HANA_DETAIL_HAS_DUPLICATES_HPP
#include <boost/hana/config.hpp>
#include <boost/hana/detail/fast_and.hpp>
#include <boost/hana/equal.hpp>
#include <cstddef>
#include <utility>
BOOST_HANA_NAMESPACE_BEGIN namespace detail {
template <typename T, typename ...U>
constexpr std::size_t pack_count() {
std::size_t c = 0;
std::size_t expand[] = {0, // avoid empty array
(decltype(hana::equal(std::declval<T>(), std::declval<U>()))::value
? ++c
: c)...
};
(void)expand;
return c;
}
//! @ingroup group-details
//! Returns whether any of the `T`s are duplicate w.r.t. `hana::equal`.
//!
//! In particular, this does not check whether all of the `T`s are unique
//! as _types_, but rather whether they are unique when compared as
//! `hana::equal(std::declval<T>(), std::declval<U>())`. This assumes
//! the comparison to return an `IntegralConstant` that can be explicitly
//! converted to `bool`.
//!
//! @note
//! Since this utility is mostly used in assertions to check that there
//! are no duplicates in a sequence, we expect it to return `false` most
//! of the time (otherwise we will assert). Hence, this implementation is
//! biased towards the fact that we __will__ have to compare every pair of
//! elements in most cases, and it does not try to be lazy.
//!
//! @todo
//! This implementation is O(n^2). We could do it in O(n), but that would
//! require a more elaborate setup including storage with O(1) lookup
//! (which could be based on a compile-time hash). If we implement such
//! storage for associative sequences, we could use it to optimize this.
template <typename ...T>
struct has_duplicates {
static constexpr bool value =
sizeof...(T) > 0 &&
!detail::fast_and<(detail::pack_count<T, T...>() == 1)...>::value
;
};
} BOOST_HANA_NAMESPACE_END
#endif // !BOOST_HANA_DETAIL_HAS_DUPLICATES_HPP
|
; hive 0.0.0.1
; type asm
section .text
global main
main:
mov edx,len
mov ecx,msg
mov ebx,1
mov eax,4
int 0x80
mov eax,1
int 0x80
section .data
msg db 'Hello world!', 0xa
len equ $ - msg |
a: NOP
b: NOP
c: NOP
INP
STA [a]
INP
STA [b]
INP
STA [c]
LDA [a]
LDB [b]
ADD
LDB [c]
MUL
OUT
HLT
|
/*
* MonochromeRectangleDetector.cpp
* zxing
*
* Created by Luiz Silva on 09/02/2010.
* Copyright 2010 ZXing authors All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <zxing/ReaderException.h>
#include <zxing/datamatrix/detector/MonochromeRectangleDetector.h>
#include <sstream>
namespace zxing {
namespace datamatrix {
std::vector<Ref<CornerPoint> > MonochromeRectangleDetector::detect() {
int height = image_->getHeight();
int width = image_->getWidth();
int halfHeight = height >> 1;
int halfWidth = width >> 1;
int deltaY = max(1, height / (MAX_MODULES << 3));
int deltaX = max(1, width / (MAX_MODULES << 3));
int top = 0;
int bottom = height;
int left = 0;
int right = width;
Ref<CornerPoint> pointA(findCornerFromCenter(halfWidth, 0, left, right,
halfHeight, -deltaY, top, bottom, halfWidth >> 1));
top = (int) pointA->getY() - 1;
Ref<CornerPoint> pointB(findCornerFromCenter(halfWidth, -deltaX, left, right,
halfHeight, 0, top, bottom, halfHeight >> 1));
left = (int) pointB->getX() - 1;
Ref<CornerPoint> pointC(findCornerFromCenter(halfWidth, deltaX, left, right,
halfHeight, 0, top, bottom, halfHeight >> 1));
right = (int) pointC->getX() + 1;
Ref<CornerPoint> pointD(findCornerFromCenter(halfWidth, 0, left, right,
halfHeight, deltaY, top, bottom, halfWidth >> 1));
bottom = (int) pointD->getY() + 1;
// Go try to find point A again with better information -- might have been off at first.
pointA.reset(findCornerFromCenter(halfWidth, 0, left, right,
halfHeight, -deltaY, top, bottom, halfWidth >> 2));
std::vector<Ref<CornerPoint> > corners(4);
corners[0].reset(pointA);
corners[1].reset(pointB);
corners[2].reset(pointC);
corners[3].reset(pointD);
return corners;
}
Ref<CornerPoint> MonochromeRectangleDetector::findCornerFromCenter(int centerX, int deltaX, int left, int right,
int centerY, int deltaY, int top, int bottom, int maxWhiteRun) {
Ref<TwoInts> lastRange(NULL);
for (int y = centerY, x = centerX;
y < bottom && y >= top && x < right && x >= left;
y += deltaY, x += deltaX) {
Ref<TwoInts> range(NULL);
if (deltaX == 0) {
// horizontal slices, up and down
range = blackWhiteRange(y, maxWhiteRun, left, right, true);
} else {
// vertical slices, left and right
range = blackWhiteRange(x, maxWhiteRun, top, bottom, false);
}
if (range == NULL) {
if (lastRange == NULL) {
throw ReaderException("Couldn't find corners (lastRange = NULL) ");
} else {
// lastRange was found
if (deltaX == 0) {
int lastY = y - deltaY;
if (lastRange->start < centerX) {
if (lastRange->end > centerX) {
// straddle, choose one or the other based on direction
Ref<CornerPoint> result(new CornerPoint(deltaY > 0 ? lastRange->start : lastRange->end, lastY));
return result;
}
Ref<CornerPoint> result(new CornerPoint(lastRange->start, lastY));
return result;
} else {
Ref<CornerPoint> result(new CornerPoint(lastRange->end, lastY));
return result;
}
} else {
int lastX = x - deltaX;
if (lastRange->start < centerY) {
if (lastRange->end > centerY) {
Ref<CornerPoint> result(new CornerPoint(lastX, deltaX < 0 ? lastRange->start : lastRange->end));
return result;
}
Ref<CornerPoint> result(new CornerPoint(lastX, lastRange->start));
return result;
} else {
Ref<CornerPoint> result(new CornerPoint(lastX, lastRange->end));
return result;
}
}
}
}
lastRange = range;
}
throw ReaderException("Couldn't find corners");
}
Ref<TwoInts> MonochromeRectangleDetector::blackWhiteRange(int fixedDimension, int maxWhiteRun, int minDim, int maxDim,
bool horizontal) {
int center = (minDim + maxDim) >> 1;
// Scan left/up first
int start = center;
while (start >= minDim) {
if (horizontal ? image_->get(start, fixedDimension) : image_->get(fixedDimension, start)) {
start--;
} else {
int whiteRunStart = start;
do {
start--;
} while (start >= minDim && !(horizontal ? image_->get(start, fixedDimension) :
image_->get(fixedDimension, start)));
int whiteRunSize = whiteRunStart - start;
if (start < minDim || whiteRunSize > maxWhiteRun) {
start = whiteRunStart;
break;
}
}
}
start++;
// Then try right/down
int end = center;
while (end < maxDim) {
if (horizontal ? image_->get(end, fixedDimension) : image_->get(fixedDimension, end)) {
end++;
} else {
int whiteRunStart = end;
do {
end++;
} while (end < maxDim && !(horizontal ? image_->get(end, fixedDimension) :
image_->get(fixedDimension, end)));
int whiteRunSize = end - whiteRunStart;
if (end >= maxDim || whiteRunSize > maxWhiteRun) {
end = whiteRunStart;
break;
}
}
}
end--;
Ref<TwoInts> result(NULL);
if (end > start) {
result = new TwoInts;
result->start = start;
result->end = end;
}
return result;
}
}
}
|
; A100525: Bisection of A048654.
; 4,22,128,746,4348,25342,147704,860882,5017588,29244646,170450288,993457082,5790292204,33748296142,196699484648,1146448611746,6681992185828,38945504503222,226991034833504,1323000704497802,7711013192153308,44943078448422046,261947457498378968,1526741666541851762,8898502541752731604,51864273583974537862,302287138962094495568,1761858560188592435546,10268864222169460117708,59851326772828168270702,348839096414799549506504,2033183251715969128768322,11850260413881015223103428,69068379231570122209852246
mov $1,4
mov $2,5
lpb $0
sub $0,1
add $2,$1
add $1,$2
add $1,$2
add $2,$1
lpe
mov $0,$1
|
; A127423: a(1) = 1; for n > 1, a(n) = n concatenated with n - 1.
; 1,21,32,43,54,65,76,87,98,109,1110,1211,1312,1413,1514,1615,1716,1817,1918,2019,2120,2221,2322,2423,2524,2625,2726,2827,2928,3029,3130,3231,3332,3433,3534,3635,3736,3837,3938,4039,4140,4241,4342,4443,4544,4645,4746,4847,4948,5049,5150,5251,5352,5453,5554,5655,5756,5857,5958,6059,6160,6261,6362,6463,6564,6665,6766,6867,6968,7069,7170,7271,7372,7473,7574,7675,7776,7877,7978,8079,8180,8281,8382,8483,8584,8685,8786,8887,8988,9089,9190,9291,9392,9493,9594,9695,9796,9897,9998,10099,101100,102101,103102,104103,105104,106105,107106,108107,109108,110109,111110,112111,113112,114113,115114,116115,117116,118117,119118,120119,121120,122121,123122,124123,125124,126125,127126,128127,129128,130129,131130,132131,133132,134133,135134,136135,137136,138137,139138,140139,141140,142141,143142,144143,145144,146145,147146,148147,149148,150149,151150,152151,153152,154153,155154,156155,157156,158157,159158,160159,161160,162161,163162,164163,165164,166165,167166,168167,169168,170169,171170,172171,173172,174173,175174,176175,177176,178177,179178,180179,181180,182181,183182,184183,185184,186185,187186,188187,189188,190189,191190,192191,193192,194193,195194,196195,197196,198197,199198,200199,201200,202201,203202,204203,205204,206205,207206,208207,209208,210209,211210,212211,213212,214213,215214,216215,217216,218217,219218,220219,221220,222221,223222,224223,225224,226225,227226,228227,229228,230229,231230,232231,233232,234233,235234,236235,237236,238237,239238,240239,241240,242241,243242,244243,245244,246245,247246,248247,249248,250249
mov $3,$0
add $0,1
mov $4,$0
sub $0,1
mov $1,$4
mov $2,$0
lpb $2,1
mul $1,10
div $2,10
lpe
add $1,$3
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include <vespamalloc/malloc/memblock.h>
namespace vespamalloc {
template <size_t MinSizeClassC, size_t MaxSizeClassMultiAllocC>
void
MemBlockT<MinSizeClassC, MaxSizeClassMultiAllocC>::logBigBlock(size_t exact, size_t adjusted, size_t gross) const
{
size_t sz(exact);
if (std::max(std::max(sz, adjusted), gross) > _bigBlockLimit) {
Stack st[32];
size_t count = Stack::fillStack(st, NELEMS(st));
fprintf(_logFile, "validating %p(%ld, %ld, %ld)",
ptr(), sz, adjusted, gross);
st[3].info(_logFile);
fprintf(_logFile, "\n");
for(size_t i=1; (i < count) && (i < NELEMS(st)); i++) {
const Stack & s = st[i];
if (s.valid()) {
s.info(_logFile);
fprintf(_logFile, " from ");
}
}
fprintf(_logFile, "\n");
}
}
template <size_t MinSizeClassC, size_t MaxSizeClassMultiAllocC>
void
MemBlockT<MinSizeClassC, MaxSizeClassMultiAllocC>::bigBlockLimit(size_t lim)
{
_bigBlockLimit = lim;
}
template <size_t MinSizeClassC, size_t MaxSizeClassMultiAllocC>
FILE * MemBlockT<MinSizeClassC, MaxSizeClassMultiAllocC>::_logFile = stderr;
template <size_t MinSizeClassC, size_t MaxSizeClassMultiAllocC>
size_t MemBlockT<MinSizeClassC, MaxSizeClassMultiAllocC>::_bigBlockLimit = 0x80000000;
}
|
<%
from pwnlib.shellcraft.powerpc.linux import syscall
%>
<%page args="pri, fmt, vararg"/>
<%docstring>
Invokes the syscall syslog. See 'man 2 syslog' for more information.
Arguments:
pri(int): pri
fmt(char): fmt
vararg(int): vararg
</%docstring>
${syscall('SYS_syslog', pri, fmt, vararg)}
|
; int vprintf(const char *format, void *arg)
INCLUDE "clib_cfg.asm"
SECTION code_clib
SECTION code_stdio
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
IF __CLIB_OPT_MULTITHREAD & $02
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PUBLIC vprintf_callee
EXTERN asm_vprintf
vprintf_callee:
pop af
pop bc
pop de
push af
jp asm_vprintf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ELSE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PUBLIC vprintf_callee
EXTERN vprintf_unlocked_callee
defc vprintf_callee = vprintf_unlocked_callee
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ENDIF
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;
; ZX 81 specific routines
; by Stefano Bodrato, Oct 2007
;
; convert ASCII character to ZX81 char code
;
; char ascii_zx(char character);
;
;
; $Id: ascii_zx.asm,v 1.4 2015/01/19 01:33:26 pauloscustodio Exp $
;
PUBLIC ascii_zx
EXTERN asctozx81
ascii_zx:
ld hl,asctozx81+1
ld a,(hl)
push af
push hl
ld a,229 ; push hl
ld (hl),a
ld hl,6
add hl,sp ; location of char
call asctozx81
pop bc
ld h,0
ld l,a
pop af
ld (bc),a
ret
|
; A164005: Zero together with row 5 of the array in A163280.
; 0,7,14,21,32,45,60,77,96,117,140,165,192,221,252,285,320,357,396,437,480,525,572,621,672,725,780,837,896,957,1020,1085,1152,1221,1292,1365,1440,1517,1596,1677,1760,1845,1932,2021,2112,2205,2300,2397,2496,2597,2700,2805,2912,3021,3132,3245,3360,3477,3596,3717,3840,3965,4092,4221,4352,4485,4620,4757,4896,5037,5180,5325,5472,5621,5772,5925,6080,6237,6396,6557,6720,6885,7052,7221,7392,7565,7740,7917,8096,8277,8460,8645,8832,9021,9212,9405,9600,9797,9996,10197,10400,10605,10812,11021,11232,11445,11660,11877,12096,12317,12540,12765,12992,13221,13452,13685,13920,14157,14396,14637,14880,15125,15372,15621,15872,16125,16380,16637,16896,17157,17420,17685,17952,18221,18492,18765,19040,19317,19596,19877,20160,20445,20732,21021,21312,21605,21900,22197,22496,22797,23100,23405,23712,24021,24332,24645,24960,25277,25596,25917,26240,26565,26892,27221,27552,27885,28220,28557,28896,29237,29580,29925,30272,30621,30972,31325,31680,32037,32396,32757,33120,33485,33852,34221,34592,34965,35340,35717,36096,36477,36860,37245,37632,38021,38412,38805,39200,39597,39996,40397,40800,41205,41612,42021,42432,42845,43260,43677,44096,44517,44940,45365,45792,46221,46652,47085,47520,47957,48396,48837,49280,49725,50172,50621,51072,51525,51980,52437,52896,53357,53820,54285,54752,55221,55692,56165,56640,57117,57596,58077,58560,59045,59532,60021,60512,61005,61500,61997,62496,62997
mov $1,$0
mov $2,3
trn $2,$0
add $1,$2
add $1,4
mul $1,$0
|
; 编写除法溢出(中断源号0)中断处理程序(存储于0000:0200)
assume cs:code
code segment
start: mov ax, 0
mov es, ax
mov di, 0200H
mov ax, cs
mov ds, ax
mov si, offset do0
mov cx, offset do0end - offset do0
cld ; set flag df to 0
rep movsb
;设置中断向量表
mov ax, 0
mov es, ax
mov word ptr es:[0*4], 0200H
mov word ptr es:[0*4+2], 0
mov ax, 1000H ; test the overflow
mov bl, 1
div bl
mov ax, 4c00H
int 21H
; display the string 'overflow' in the middle of dosbox screen
do0: jmp short do0start
db 'overflow!!!'
do0start:
mov ax, 0
mov ds, ax
mov si, 0202H
mov ax, 0b800H
mov es, ax
mov di, 160*12+30*2
mov cx, 11
s: mov al, [si]
mov es:[di], al
mov byte ptr es:[di+1], 01000001B
inc si
add di, 2
loop s
mov ax, 4c00H
int 21H
do0end: nop
code ends
end start
|
; A298016: Coordination sequence of snub-632 tiling with respect to a hexavalent node.
; 1,6,12,12,24,36,24,42,60,36,60,84,48,78,108,60,96,132,72,114,156,84,132,180,96,150,204,108,168,228,120,186,252,132,204,276,144,222,300,156,240,324,168,258,348,180,276,372,192,294,396,204,312,420,216,330,444,228,348,468,240,366,492,252,384,516,264,402,540,276,420,564,288,438,588,300,456,612,312,474,636,324,492,660,336,510,684,348,528,708,360,546,732,372,564,756,384,582,780,396,600,804,408,618,828,420,636,852,432,654,876,444,672,900,456,690,924,468,708,948,480,726,972,492,744,996,504,762,1020,516,780,1044,528,798,1068,540,816,1092,552,834,1116,564,852,1140,576,870,1164,588,888,1188,600,906,1212,612,924,1236,624,942,1260,636,960,1284,648,978,1308,660,996,1332,672,1014,1356,684,1032,1380,696,1050,1404,708,1068,1428,720,1086,1452,732,1104,1476,744,1122,1500,756,1140,1524,768,1158,1548,780,1176,1572,792,1194,1596,804,1212,1620,816,1230,1644,828,1248,1668,840,1266,1692,852,1284,1716,864,1302,1740,876,1320,1764,888,1338,1788,900,1356,1812,912,1374,1836,924,1392,1860,936,1410,1884,948,1428,1908,960,1446,1932,972,1464,1956,984,1482,1980,996
mov $2,$0
mov $4,2
lpb $4,1
mov $0,$2
sub $4,1
add $0,$4
sub $0,1
cal $0,298019 ; Partial sums of A298016.
mov $3,$0
mov $5,$4
lpb $5,1
mov $1,$3
sub $5,1
lpe
lpe
lpb $2,1
sub $1,$3
mov $2,0
lpe
|
; A147568: a(n) = 2*A000695(n)+3.
; 3,5,11,13,35,37,43,45,131,133,139,141,163,165,171,173,515,517,523,525,547,549,555,557,643,645,651,653,675,677,683,685,2051,2053,2059,2061,2083,2085,2091,2093,2179,2181,2187,2189,2211,2213,2219,2221,2563,2565,2571
mov $2,$0
mov $5,$0
lpb $2
mov $0,$5
sub $2,1
sub $0,$2
mov $3,$0
lpb $0
add $3,$0
mov $0,0
gcd $3,281474976710656
mov $4,3
mov $6,0
add $6,$3
mov $7,1
lpe
sub $4,$7
mul $6,$4
pow $6,2
add $6,$4
mov $3,$6
div $3,6
add $3,1
add $1,$3
lpe
div $1,4
mul $1,2
add $1,3
|
; A141892: Primes congruent to 10 mod 21.
; 31,73,157,199,241,283,367,409,577,619,661,787,829,997,1039,1123,1249,1291,1459,1543,1627,1669,1753,1879,2089,2131,2341,2383,2467,2551,2593,2677,2719,2803,2887,2971,3181,3307,3391,3433,3517,3559,3643,3727,3769,3853,4021,4231,4273,4357,4441,4483,4567,4651,4861,4903,4987,5113,5197,5281,5323,5407,5449,5659,5701,5743,5827,5869,5953,6037,6079,6121,6163,6247,6373,6709,6793,6961,7129,7213,7297,7507,7549,7591,7717,7759,7927,8011,8053,8179,8221,8263,8389,8431,8599,8641,8893,9103,9187,9397
mov $2,$0
add $2,2
pow $2,2
lpb $2
add $1,9
sub $2,1
mov $3,$1
seq $3,10051 ; Characteristic function of primes: 1 if n is prime, else 0.
sub $0,$3
add $1,12
mov $4,$0
max $4,0
cmp $4,$0
mul $2,$4
lpe
div $1,2
sub $1,22
mul $1,2
add $1,33
mov $0,$1
|
#ifndef BOOST_THREAD_TIME_HPP
#define BOOST_THREAD_TIME_HPP
// (C) Copyright 2007 Anthony Williams
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/date_time/time_clock.hpp>
#include <boost/date_time/microsec_time_clock.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/config/abi_prefix.hpp>
namespace boost
{
typedef boost::posix_time::ptime system_time;
inline system_time get_system_time()
{
#if defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK)
return boost::date_time::microsec_clock<system_time>::universal_time();
#else // defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK)
return boost::date_time::second_clock<system_time>::universal_time();
#endif // defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK)
}
namespace detail
{
inline system_time get_system_time_sentinel()
{
return system_time(boost::posix_time::pos_infin);
}
inline unsigned long get_milliseconds_until(system_time const& target_time)
{
if(target_time.is_pos_infinity())
{
return ~(unsigned long)0;
}
system_time const now=get_system_time();
if(target_time<=now)
{
return 0;
}
return static_cast<unsigned long>((target_time-now).total_milliseconds()+1);
}
}
}
#include <boost/config/abi_suffix.hpp>
#endif
|
;******************************************************************************
; MSP430x249 Demo - Write a byte to Port 1
;
; Description: Writes a byte(FFh) to Port 1 and stays in LPM4
; ACLK = 32.768kHz, MCLK = SMCLK = default DCO
;
; MSP430x249
; -----------------
; /|\| |
; | | |
; --|RST |
; | |
; | |
; | |
;
; JL Bile
; Texas Instruments Inc.
; May 2008
; Built Code Composer Essentials: v3 FET
;*******************************************************************************
.cdecls C,LIST, "msp430x24x.h"
;-------------------------------------------------------------------------------
.text ;Program Start
;-------------------------------------------------------------------------------
RESET mov.w #0500h,SP ; Initialize stackpointer
StopWDT mov.w #WDTPW+WDTHOLD,&WDTCTL ; Stop WDT
SetupP1 bis.b #0FFh,&P1DIR ; P1.x output
bis.b #0FFh,&P1OUT ; Set all P1 pins HI
;
Mainloop bis.w #LPM4,SR ; LPM4
nop ; Required only for debugger
;
;------------------------------------------------------------------------------
; Interrupt Vectors
;-------------------------------------------------------------------------------
.sect ".reset" ; POR, ext. Reset
.short RESET
.end
|
; A130863: Ratio of quadruple Sum of k^2-1 to quadruple sum of k made into an integer sequence: (1/6)*(-1 + n)(2 + n)(3 + n)(7 + n).
; 0,30,100,231,448,780,1260,1925,2816,3978,5460,7315,9600,12376,15708,19665,24320,29750,36036,43263,51520,60900,71500,83421,96768,111650,128180,146475,166656,188848
mov $2,$0
add $2,8
mul $0,$2
sub $2,4
bin $2,2
mul $0,$2
div $0,3
|
#include "sim/init.hh"
extern "C" {
void init_param_CreditLink_d();
}
EmbeddedSwig embed_swig_param_CreditLink_d(init_param_CreditLink_d);
|
sty {m1}
|
/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#include "tensorflow/compiler/xla/service/heap_simulator.h"
#include <algorithm>
#include <vector>
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "absl/memory/memory.h"
#include "tensorflow/compiler/xla/map_util.h"
#include "tensorflow/compiler/xla/util.h"
namespace xla {
using absl::flat_hash_map;
using absl::flat_hash_set;
namespace {
// FlattenSchedule walks through the instruction, and recurse into each called
// computations. As it walks it also tracks down the ordinal number of each
// instruction in the schedule and store it in the `instruction_schedule`. The
// end of each computation is tracked in `computation_schedule`.
int64 FlattenSchedule(
const HloComputation& computation,
const HloInstructionSequence& instruction_sequence,
const HloSchedule* schedule, int64 start_time,
absl::flat_hash_map<const HloInstruction*, int64>* instruction_schedule,
absl::flat_hash_map<const HloComputation*, int64>* computation_schedule) {
int64 time = start_time;
for (const HloInstruction* instruction :
instruction_sequence.instructions()) {
if (schedule != nullptr) {
// Recurse into sub computations if we have a module-scoped schedule.
if (instruction->opcode() == HloOpcode::kCall ||
instruction->opcode() == HloOpcode::kConditional) {
for (const HloComputation* called_computation :
instruction->called_computations()) {
const HloInstructionSequence& called_sequence =
schedule->sequence(called_computation);
time =
FlattenSchedule(*called_computation, called_sequence, schedule,
time, instruction_schedule, computation_schedule);
computation_schedule->insert({called_computation, time});
}
}
if (instruction->opcode() == HloOpcode::kWhile) {
const HloInstructionSequence& condition_sequence =
schedule->sequence(instruction->while_condition());
time = FlattenSchedule(*instruction->while_condition(),
condition_sequence, schedule, time,
instruction_schedule, computation_schedule);
computation_schedule->insert({instruction->while_condition(), time});
const HloInstructionSequence& body_sequence =
schedule->sequence(instruction->while_body());
time =
FlattenSchedule(*instruction->while_body(), body_sequence, schedule,
time, instruction_schedule, computation_schedule);
}
}
if (instruction_schedule->count(instruction) != 0) {
continue;
}
instruction_schedule->insert({instruction, time++});
}
computation_schedule->insert({&computation, time});
return time;
}
// The aliased buffers could have overlapping live ranges.
// NormalizeAliasedBuffers normalizes the buffer such that each alias buffer has
// disjoint live range while keeping the live range union the same. This avoid
// double counting aliased buffer sizes.
//
// Before(buffer1 and 2 are aliased):
//
// +----+ live range of buffer1
// +------------------+ live range of buffer2
//
// After:
//
// +----------+ live range of buffer1
// +------+ live range of buffer2
//
// Before(buffer1 and 2 are aliased):
//
// +----------+ live range of buffer1
// +------------+ live range of buffer2
//
// After:
//
// +----------+ live range of buffer1
// +------+ live range of buffer2
//
// Before(buffer1 and 2 are aliased):
//
// +----------+ live range of buffer1
// +---+ live range of buffer2
//
// After(unchanged):
//
// +----------+ live range of buffer1
// +---+ live range of buffer2
//
// As another example, imagine we have the following code sequence with live
// ranges of each while-aliased buffers:
//
// a p1 p2 e b
// a = ... +
// |
// { |
// p1 = param | +
// ROOT true | |
// } | +
// { // body |
// p2 = param + +
// c = p2 + 1 +
// d = c + 1
// ROOT e = d + 1 +
// } |
// |
// b = while (a) + +
// |
// f = b + 1 +
//
// After normalization it becomes:
//
// a p1 p2 e b
// a = ... +
// |
// { +
// p1 = param +
// ROOT true |
// } +
// { // body
// p2 = param +
// c = p2 + 1 +
// d = c + 1
// ROOT e = d + 1 +
// } |
// |
// b = while (a) +
// +
// f = b + 1 +
//
// Note there is no overlap of live ranges after normalization.
void NormalizeAliasedBuffers(
absl::flat_hash_map<const HloValue*, int64>* buffer_start_map,
absl::flat_hash_map<const HloValue*, int64>* buffer_end_map,
const std::vector<const HloValue*>& values_to_assign,
const HloAliasAnalysis& alias_analysis) {
absl::flat_hash_set<const HloValue*> values_to_assign_set(
values_to_assign.begin(), values_to_assign.end());
for (const HloBuffer& hlo_buffer : alias_analysis.buffers()) {
std::vector<const HloValue*> aliased_buffers;
for (const HloValue* hlo_value : hlo_buffer.values()) {
if (values_to_assign_set.count(hlo_value) != 0) {
aliased_buffers.push_back(hlo_value);
CHECK_NE(buffer_start_map->count(hlo_value), 0);
CHECK_NE(buffer_end_map->count(hlo_value), 0);
}
}
absl::c_sort(
aliased_buffers, [&](const HloValue* value1, const HloValue* value2) {
if ((*buffer_start_map)[value1] != (*buffer_start_map)[value2]) {
return (*buffer_start_map)[value1] < (*buffer_start_map)[value2];
}
return (*buffer_end_map)[value1] < (*buffer_end_map)[value2];
});
for (int64 i = 0; i < aliased_buffers.size(); ++i) {
// We can't use aliased_buffers.size() - 1 since aliased_buffers.size() is
// an unsigned integer and can be 0.
if (i + 1 == aliased_buffers.size()) {
break;
}
const HloValue* value1 = aliased_buffers[i];
const HloValue* value2 = aliased_buffers[i + 1];
if ((*buffer_start_map)[value1] == (*buffer_start_map)[value2]) {
// If value1 has the same start time as value2, make value1 disappear by
// setting the end time same as start time:
//
// Before:
// +----+ value1
// +----------+ value2
//
// After:
// + value1
// +----------+ value2
//
// Note that only when heap simulator runs before copy insertion can
// this happen where one instruction defines multiple aliased buffers --
// This is illegle to execute and can be fixed by copy insertion later.
(*buffer_end_map)[value1] = (*buffer_start_map)[value1];
continue;
}
if ((*buffer_end_map)[value1] < (*buffer_start_map)[value2]) {
continue;
}
if ((*buffer_end_map)[value1] > (*buffer_end_map)[value2]) {
(*buffer_end_map)[value2] = (*buffer_end_map)[value1];
}
(*buffer_end_map)[value1] = (*buffer_start_map)[value2] - 1;
}
}
}
} // namespace
/*static*/
StatusOr<int64> HeapSimulator::MinimumMemoryForModule(
const HloSchedule& schedule,
const LogicalBuffer::SizeFunction& size_function) {
if (schedule.empty()) {
return 0;
}
const HloModule* module = schedule.module();
TF_ASSIGN_OR_RETURN(std::unique_ptr<HloAliasAnalysis> alias_analysis,
HloAliasAnalysis::Run(module));
// The absolute minimum memory required for a given sequence of instructions
// is determined by the sequence of Alloc and Free calls on a simulated heap,
// ignoring fragmentation. We run the heap simulation on the whole module,
// rather than summing each computation, since it gives us a better lower
// bound, by minimizing the liveness of sub-computations.
TF_ASSIGN_OR_RETURN(
HeapSimulator::Result result,
HeapSimulator::Run(absl::make_unique<NoFragmentationStatsHeap>(), *module,
schedule, *alias_analysis, size_function));
return result.heap_size;
}
/*static*/
StatusOr<int64> HeapSimulator::MinimumMemoryForComputation(
const HloComputation& computation, const HloInstructionSequence& sequence,
const HloAliasAnalysis& alias_analysis,
const LogicalBuffer::SizeFunction& size_function,
const absl::flat_hash_map<const HloComputation*, int64>*
memory_by_computation) {
TF_ASSIGN_OR_RETURN(
HeapSimulator::Result result,
HeapSimulator::Run(absl::make_unique<NoFragmentationStatsHeap>(),
computation, sequence, alias_analysis, size_function,
HeapSimulator::Options(), memory_by_computation));
return result.heap_size;
}
StatusOr<int64> HeapSimulator::MinimumMemoryForComputation(
const HloComputation& computation, const HloInstructionSequence& sequence,
const HloAliasAnalysis& alias_analysis,
const LogicalBuffer::SizeFunction& size_function,
const HloSchedule* schedule) {
TF_ASSIGN_OR_RETURN(
HeapSimulator::Result result,
HeapSimulator::Run(absl::make_unique<NoFragmentationStatsHeap>(),
computation, sequence, alias_analysis, size_function,
schedule, HeapSimulator::Options()));
return result.heap_size;
}
/*static*/
StatusOr<HeapSimulator::Result> HeapSimulator::Run(
std::unique_ptr<HeapAlgorithm> algorithm, const HloModule& module,
const HloSchedule& schedule, const HloAliasAnalysis& alias_analysis,
const BufferValue::SizeFunction& size_fn, const Options& options) {
HeapSimulator heap(std::move(algorithm), size_fn, options, &schedule);
const HloComputation* entry_computation = module.entry_computation();
const HloInstructionSequence& instruction_sequence =
schedule.sequence(entry_computation);
TF_RETURN_IF_ERROR(heap.RunComputation(*entry_computation,
instruction_sequence, alias_analysis));
return heap.Finish();
}
/*static*/
StatusOr<HeapSimulator::Result> HeapSimulator::Run(
std::unique_ptr<HeapAlgorithm> algorithm, const HloComputation& computation,
const HloInstructionSequence& instruction_sequence,
const HloAliasAnalysis& alias_analysis,
const BufferValue::SizeFunction& size_fn, const Options& options,
const absl::flat_hash_map<const HloComputation*, int64>*
memory_by_computation) {
HeapSimulator heap(std::move(algorithm), size_fn, options,
/*schedule=*/nullptr, memory_by_computation);
TF_RETURN_IF_ERROR(
heap.RunComputation(computation, instruction_sequence, alias_analysis));
return heap.Finish();
}
/*static*/
StatusOr<HeapSimulator::Result> HeapSimulator::Run(
std::unique_ptr<HeapAlgorithm> algorithm, const HloComputation& computation,
const HloInstructionSequence& instruction_sequence,
const HloAliasAnalysis& alias_analysis,
const BufferValue::SizeFunction& size_fn, const HloSchedule* schedule,
const Options& options) {
HeapSimulator heap(std::move(algorithm), size_fn, options,
/*schedule=*/schedule, nullptr);
TF_RETURN_IF_ERROR(
heap.RunComputation(computation, instruction_sequence, alias_analysis));
return heap.Finish();
}
// Runs a heap simulation for the given 'computation', assuming the given
// 'instruction_sequence'.
Status HeapSimulator::RunComputation(
const HloComputation& computation,
const HloInstructionSequence& instruction_sequence,
const HloAliasAnalysis& alias_analysis) {
XLA_VLOG_LINES(1, computation.parent()->ToString());
XLA_VLOG_LINES(2, computation.ToString());
HloDataflowAnalysis& dataflow_analysis = alias_analysis.dataflow_analysis();
// instruction_schedule and computation_schedule are the maps that track each
// instruction/computation and their ordinal in the schedule.
absl::flat_hash_map<const HloInstruction*, int64> instruction_schedule;
absl::flat_hash_map<const HloComputation*, int64> computation_schedule;
// program_end_time is the time of the last instruction scheduled. It is equal
// to the number of instructions in a computation.
int64 program_end_time =
FlattenSchedule(computation, instruction_sequence, schedule_, 0,
&instruction_schedule, &computation_schedule);
VLOG(1) << "Program end time: " << program_end_time;
// We track the definition and free events for each buffer, then we go through
// each step and reply those events in program order.
absl::flat_hash_map<const HloValue*, int64> buffer_start_map;
absl::flat_hash_map<const HloValue*, int64> buffer_end_map;
// Record the buffer define/free event for each time step. We free all
// remaining buffers (entry parameter, etc) after the program has finished
// running, so we set the size of to program_end_time + 1.
std::vector<std::vector<const HloValue*>> buffers_defined(program_end_time +
1);
std::vector<std::vector<const HloValue*>> buffers_freed(program_end_time + 1);
// values_to_assign tracks the HloValues that we need to assign a buffer to.
// Note that we only need to assign a buffer to a value when both of the
// following conditions are met:
//
// - The user specifically asks us to assign a buffer to a set of HloValues,
// and the value is in the set. If the user don't provide such a set, by
// default we assign buffer to all HloValues.
//
// - If the instruction is in a nested call of the current computation, only
// assign a buffer if we are doing global heap simulation.
std::vector<const HloValue*> values_to_assign;
// Keeps track of buffer start time and buffer end time.
for (const HloValue* value : dataflow_analysis.values()) {
// Ignore buffers that are not defined.
if (instruction_schedule.count(value->defining_instruction()) == 0) {
continue;
}
if (IgnoreBuffer(value)) {
continue;
}
values_to_assign.push_back(value);
int64 buffer_start_time = instruction_schedule[value->instruction()];
int64 buffer_end_time = -1;
// A buffer's live range ends when the last user finishes executing.
for (const HloUse& use : value->uses()) {
const HloInstruction* used = use.instruction;
// As an optimization, we deem a while's init value's live range ends as
// soon as the loop body starts. This optimization is only applicable to
// the whole module simulation.
if (schedule_ != nullptr && used->opcode() == HloOpcode::kWhile) {
// The current live range is at the end of the while, move it to the
// beginning of the body.
used = used->while_body()->parameter_instruction(0);
VLOG(1) << "Moved value " << value->ToShortString()
<< " to while param: " << used->ToString();
}
if (instruction_schedule.count(used) == 0) {
// We didn't track the instruction `used`. This happens when we do
// computation scope (versus module scope) heap simulation and when the
// used instruction is outside of the computation being simulated.
continue;
}
buffer_end_time = std::max(buffer_end_time, instruction_schedule[used]);
}
if (buffer_end_time == -1) {
buffer_end_time = buffer_start_time;
}
for (const HloPosition& position : value->positions()) {
const HloComputation* position_comp = position.instruction->parent();
// If this instruction lives out, the live range of the instruction should
// be extended to the end of the computation.
if (position.instruction == position_comp->root_instruction()) {
if (schedule_ == nullptr && &computation != position_comp) {
continue;
}
if (computation_schedule.count(position_comp) == 0) {
continue;
}
buffer_end_time =
std::max(buffer_end_time, computation_schedule[position_comp]);
}
}
// Entry parameters live across whole computation.
if (value->instruction()->opcode() == HloOpcode::kParameter &&
value->instruction()->parent() ==
computation.parent()->entry_computation()) {
buffer_end_time = program_end_time;
}
CHECK(buffer_start_time <= buffer_end_time);
buffer_start_map[value] = buffer_start_time;
buffer_end_map[value] = buffer_end_time;
}
NormalizeAliasedBuffers(&buffer_start_map, &buffer_end_map, values_to_assign,
alias_analysis);
absl::c_sort(values_to_assign,
[&](const HloValue* value1, const HloValue* value2) {
if (buffer_start_map[value1] != buffer_start_map[value2]) {
return buffer_start_map[value1] < buffer_start_map[value2];
}
if (buffer_end_map[value1] != buffer_end_map[value2]) {
return buffer_end_map[value1] < buffer_end_map[value2];
}
return value1->id() < value2->id();
});
// For each value that we need to assign a buffer to, add the define and free
// events.
for (const HloValue* value : values_to_assign) {
buffers_defined[buffer_start_map[value]].push_back(value);
buffers_freed[buffer_end_map[value]].push_back(value);
}
// All HloValues in a hlo buffer should be allocated to the same address. This
// map tracks the first value that got allocated in a buffer.
absl::flat_hash_map<const HloBuffer*, const HloValue*> first_allocated_value;
VLOG(1) << "Program time" << program_end_time;
// Go through each step in the program and replay each buffer define and free
// events.
for (int64 i = 0; i < program_end_time + 1; ++i) {
VLOG(1) << "Time step: " << i;
for (const HloValue* value : buffers_defined[i]) {
bool shared = false;
VLOG(1) << "Start buffer: " << value->ToShortString();
const HloBuffer* hlo_buffer =
&alias_analysis.GetBufferContainingValue(*value);
if (first_allocated_value.count(hlo_buffer) != 0) {
// We've already assigned an address for another value in this HloBuffer
// (HloBuffer holds several aliased HloValues). All values in a buffer
// should be assigned the same address. Find the one that's already
// allocated and reuse its address.
ShareBuffer(value, first_allocated_value[hlo_buffer],
value->instruction());
VLOG(1) << " ShareWith"
<< first_allocated_value[hlo_buffer]->ToShortString();
continue;
}
if (options_.may_reuse_operand_buffers &&
hlo_buffer->values().size() == 1) {
// We don't support sharing an aliased buffer
// (hlo_buffer->values().size() > 1) with its operand.
for (const HloInstruction* operand : value->instruction()->operands()) {
const HloValueSet operand_value_set =
dataflow_analysis.GetValueSet(operand);
for (const HloValue* operand_value : operand_value_set.values()) {
const HloBuffer* operand_buffer =
&alias_analysis.GetBufferContainingValue(*operand_value);
if (operand_buffer->values().size() > 1) {
continue;
}
if (buffer_end_map.count(operand_value) == 0) {
continue;
}
// Can only share buffers that are about to be freed.
if (buffer_end_map[operand_value] != i) {
continue;
}
// The instruction that defines the operand value can be different
// from the actual operand, if directly passing the defining
// instruction into "CanShareOperandBufferWithUser" it creates a
// check failure. The first condition guards against that case.
if (value->instruction()->IsUserOf(operand_value->instruction()) &&
value->instruction()->opcode() != HloOpcode::kCopy &&
dataflow_analysis.CanShareOperandBufferWithUser(
operand_value->instruction(), operand_value->index(),
value->instruction(), value->index())) {
// Remove the operand buffer right before sharing (allocating) a
// new one.
Free(operand_value, operand_value->instruction());
buffers_freed[i].erase(
std::remove(buffers_freed[i].begin(), buffers_freed[i].end(),
operand_value),
buffers_freed[i].end());
ShareBuffer(value, operand_value, value->instruction());
// The live range of the operand buffer is now extended to the end
// of the current instruction.
buffer_end_map[operand_value] = buffer_end_map[value];
VLOG(1) << "Sharing " << value->ToShortString() << " with "
<< operand_value->ToShortString()
<< ", size:" << size_fn_(*value);
shared = true;
break;
}
}
if (shared) {
break;
}
}
}
if (!shared) {
Alloc(value, value->instruction());
first_allocated_value[hlo_buffer] = value;
}
}
if (!buffers_freed[i].empty()) {
VLOG(1) << "Free Buffer: ";
}
for (const HloValue* value : buffers_freed[i]) {
VLOG(1) << " " << value->ToShortString();
Free(value, value->instruction());
}
}
return Status::OK();
}
HeapSimulator::HeapSimulator(
std::unique_ptr<HeapAlgorithm> algorithm,
const BufferValue::SizeFunction& size_fn, const Options& options,
const HloSchedule* schedule,
const absl::flat_hash_map<const HloComputation*, int64>*
memory_by_computation)
: no_fragmentation_stats_(absl::make_unique<NoFragmentationStatsHeap>()),
algorithm_(std::move(algorithm)),
size_fn_(size_fn),
options_(options),
schedule_(schedule),
memory_by_computation_(memory_by_computation) {
for (const BufferValueFlatSet& value_set : options.must_alias_sets) {
auto group = std::make_shared<SharedGroup>();
group->refcount = 0;
VLOG(2) << "Shared buffers:";
for (const BufferValue* buffer_value : value_set) {
VLOG(2) << " " << buffer_value->ToString();
shared_buffers_.emplace(buffer_value, group);
// Refcounts are not incremented here as buffers are shared but not
// referenced yet.
}
}
debug_trace_.set_whole_module_simulation(schedule_ != nullptr);
}
HeapSimulator::~HeapSimulator() {}
bool HeapSimulator::IgnoreBuffer(const BufferValue* buffer) const {
// Buffers for constants are ignored unless the alloc_constants option is
// set. Also ignore buffers that we're not meant to assign.
//
// TODO(b/32248867): For consistency, constants should get allocations.
if (!options_.alloc_constants &&
buffer->instruction()->opcode() == HloOpcode::kConstant) {
return true;
}
return options_.buffers_to_assign != nullptr &&
!options_.buffers_to_assign->contains(buffer);
}
// Alloc always calls the underlying heap algorithm.
void HeapSimulator::Alloc(const BufferValue* buffer,
const HloInstruction* instruction) {
CHECK(!allocated_buffers_.contains(buffer))
<< "Alloc called on allocated buffer: " << *buffer;
CHECK(!freed_buffers_.contains(buffer))
<< "Alloc called on freed buffer: " << *buffer;
allocated_buffers_.insert(buffer);
const int64 size = size_fn_(*buffer);
algorithm_->Alloc(buffer, size);
no_fragmentation_stats_->Alloc(buffer, size);
FillDebugTrace(HeapSimulatorTrace::Event::ALLOC, buffer, instruction,
nullptr);
}
// Free calls the underlying algorithm for non-shared buffers, and for shared
// buffers whose group liveness has expired. Shared group liveness is tracked
// by maintaining a refcount; the Free call on the last buffer in the group
// causes Free to be called on the underlying algorithm.
void HeapSimulator::Free(const BufferValue* buffer,
const HloInstruction* instruction) {
const int64 size = size_fn_(*buffer);
algorithm_->Free(buffer, size);
no_fragmentation_stats_->Free(buffer, size);
FillDebugTrace(HeapSimulatorTrace::Event::FREE, buffer, instruction, nullptr);
}
// ShareBuffer associates buffers with their SharedGroup in shared_buffers_.
// The 'buffer' must be a non-allocated, non-freed buffer, just like in calls
// to Alloc. The 'shared' buffer must be a previously allocated or shared
// buffer. Both 'buffer' and 'shared' will be associated with the same
// SharedGroup.
void HeapSimulator::ShareBuffer(const BufferValue* buffer,
const BufferValue* shared,
const HloInstruction* instruction) {
algorithm_->ShareWith(buffer, shared, size_fn_(*shared));
no_fragmentation_stats_->ShareWith(buffer, shared, size_fn_(*shared));
FillDebugTrace(HeapSimulatorTrace::Event::SHARE_WITH, buffer, instruction,
shared);
}
HeapSimulator::Result HeapSimulator::Finish() {
Result result = algorithm_->Finish();
// Post-process the result to add chunks for shared buffers. An empty chunk
// map means that either no buffers were allocated, or the heap was only
// collecting statistics, e.g. NoFragmentationStatsHeap.
if (!result.chunk_map.empty()) {
// If we were told to assign specific buffers, make sure we've assigned
// exactly that many buffers.
if (options_.buffers_to_assign != nullptr) {
CHECK_EQ(options_.buffers_to_assign->size(), result.chunk_map.size());
}
}
// Fragmentation is the difference between the actual and ideal sizes.
const Result no_frag_result = no_fragmentation_stats_->Finish();
result.fragmentation_size = result.heap_size - no_frag_result.heap_size;
// Copy the debug trace we collected to the final result.
result.debug_trace.Swap(&debug_trace_);
return result;
}
void HeapSimulator::FillDebugTrace(HeapSimulatorTrace::Event::Kind kind,
const BufferValue* buffer,
const HloInstruction* instruction,
const BufferValue* share_with_canonical) {
HeapSimulatorTrace::Event* event = debug_trace_.add_events();
event->set_kind(kind);
event->set_buffer_id(buffer->id());
event->set_computation_name(instruction->parent()->name());
event->set_instruction_name(instruction->name());
if (kind == HeapSimulatorTrace::Event::SHARE_WITH) {
CHECK(share_with_canonical != nullptr);
event->set_share_with_canonical_id(share_with_canonical->id());
} else {
CHECK(share_with_canonical == nullptr);
}
}
void NoFragmentationStatsHeap::Alloc(const BufferValue* buffer, int64 size) {
current_heap_size_ += size;
if (current_heap_size_ > max_heap_size_) {
max_heap_size_ = current_heap_size_;
}
}
void NoFragmentationStatsHeap::AccountForSubcomputationMemory(
const HloInstruction* instruction, int64 alloc_size_by_instruction,
const absl::flat_hash_map<const HloComputation*, int64>&
memory_by_computation) {
// We only count the memory usage of the largest subcomputation, instead of
// adding them all, because subcomputations won't execute in parallel.
int64 max_subcomputation_bytes = 0;
for (const auto* c : instruction->called_computations()) {
auto it = memory_by_computation.find(c);
if (it != memory_by_computation.end()) {
int64 subcomputation_bytes = it->second;
if (subcomputation_bytes > max_subcomputation_bytes) {
max_subcomputation_bytes = subcomputation_bytes;
}
}
}
if (max_subcomputation_bytes > 0 &&
(instruction->opcode() == HloOpcode::kWhile ||
instruction->opcode() == HloOpcode::kCall ||
instruction->opcode() == HloOpcode::kConditional)) {
// The output buffer of while/call/conditional is always aliased with the
// output buffer of the root instruction in the body. Don't double count.
max_subcomputation_bytes -= alloc_size_by_instruction;
}
max_heap_size_ =
std::max(max_heap_size_, current_heap_size_ + max_subcomputation_bytes);
}
void NoFragmentationStatsHeap::Free(const BufferValue* buffer, int64 size) {
current_heap_size_ -= size;
}
HeapSimulator::Result NoFragmentationStatsHeap::Finish() {
// The result.chunk_map is empty, since we only collect stats, and don't
// actually compute chunk assignments.
Result result;
result.heap_size = max_heap_size_;
return result;
}
void GlobalDecreasingSizeBestFitHeap::Alloc(const BufferValue* buffer,
int64 size) {
// Degenerate case: 0-sized buffers are always allocated at offset 0.
if (size == 0) {
result_.chunk_map.emplace(buffer, Chunk{0, 0});
return;
}
auto emplace_result = buffer_intervals_.emplace(
buffer, BufferInterval{buffer, size, current_time_, -1, {}, true});
DCHECK(emplace_result.second);
++current_time_;
}
void GlobalDecreasingSizeBestFitHeap::ShareWith(const BufferValue* buffer,
const BufferValue* share_with,
int64 size) {
// Degenerate case: 0-sized buffers are always allocated at offset 0.
if (size == 0) {
result_.chunk_map.emplace(buffer, Chunk{0, 0});
return;
}
DCHECK_NE(buffer_intervals_.count(share_with), 0);
buffer_intervals_[share_with].colocations.push_back(buffer);
auto emplace_result = buffer_intervals_.emplace(
buffer, BufferInterval{buffer, size, current_time_, -1, {}, false});
DCHECK(emplace_result.second);
++current_time_;
}
absl::flat_hash_set<const BufferValue*>
GlobalDecreasingSizeBestFitHeap::GetTransitiveColocations(
const BufferInterval& interval) {
absl::flat_hash_set<const BufferValue*> result;
std::vector<const BufferInterval*> worklist = {&interval};
while (!worklist.empty()) {
const BufferInterval* item = worklist.back();
worklist.pop_back();
for (const BufferValue* buffer_colocated : item->colocations) {
result.insert(buffer_colocated);
worklist.push_back(&buffer_intervals_[buffer_colocated]);
}
}
return result;
}
void GlobalDecreasingSizeBestFitHeap::Free(const BufferValue* buffer,
int64 size) {
// Degenerate case: 0-sized buffers are always allocated at offset 0.
if (size == 0) {
return;
}
BufferInterval& buffer_interval = FindOrDie(buffer_intervals_, buffer);
DCHECK_EQ(buffer_interval.buffer, buffer);
DCHECK_EQ(buffer_interval.size, size);
DCHECK_EQ(buffer_interval.end, -1);
if (buffer_interval.end != -1) {
return;
}
buffer_interval.end = current_time_;
++current_time_;
}
namespace {
// Node in BufferIntervalTree that stores the alloc and free times of a
// buffer, and the chunk assigned to it.
struct BufferIntervalTreeNode {
// Alloc time.
int64 start;
// Free time.
int64 end;
// Maximum free time of all nodes in the subtree where this node is the
// root.
int64 subtree_end;
// Allocated chunk for the buffer.
HeapSimulator::Chunk chunk;
// Left child.
BufferIntervalTreeNode* left;
// Right child.
BufferIntervalTreeNode* right;
};
// An interval tree that can query buffers overlapping in time.
class BufferIntervalTree {
public:
explicit BufferIntervalTree(int capacity) : node_storage_(capacity) {}
using Chunk = HeapSimulator::Chunk;
// Adds a buffer to the interval tree, with the time interval and allocated
// chunk specified.
void Add(int64 start, int64 end, const Chunk& chunk) {
int index = node_count_;
DCHECK_LT(index, node_storage_.size());
++node_count_;
node_storage_[index] =
BufferIntervalTreeNode{start, end, end, chunk, nullptr, nullptr};
if (index == 0) {
// This is root.
return;
}
BufferIntervalTreeNode* parent = &node_storage_[0];
while (true) {
parent->subtree_end = std::max(parent->subtree_end, end);
if (parent->start > start) {
if (parent->left == nullptr) {
parent->left = &node_storage_[index];
return;
}
parent = parent->left;
} else {
if (parent->right == nullptr) {
parent->right = &node_storage_[index];
return;
}
parent = parent->right;
}
}
}
// Returns vector of allocated chunks that overlap with the given time
// interval.
std::vector<Chunk> ChunksOverlappingInTime(int64 start, int64 end) {
std::vector<Chunk> result;
if (node_count_ == 0) {
return result;
}
std::vector<BufferIntervalTreeNode*> visiting_stack;
visiting_stack.push_back(&node_storage_[0]);
while (!visiting_stack.empty()) {
BufferIntervalTreeNode* top = visiting_stack.back();
visiting_stack.pop_back();
if (start > top->subtree_end) {
continue;
}
if (top->left != nullptr) {
visiting_stack.push_back(top->left);
}
if (top->start <= end && top->end >= start) {
result.push_back(top->chunk);
}
if (end < top->start) {
continue;
}
if (top->right != nullptr) {
visiting_stack.push_back(top->right);
}
}
return result;
}
private:
int64 node_count_ = 0;
std::vector<BufferIntervalTreeNode> node_storage_;
};
} // namespace
HeapSimulator::Result GlobalDecreasingSizeBestFitHeap::Finish() {
std::vector<BufferInterval> sorted_buffer_intervals;
for (auto& entry : buffer_intervals_) {
sorted_buffer_intervals.push_back(entry.second);
}
if (type_ == kTemporal) {
// Sort by live-range. A live range is defined by the range between the
// start of the first buffer and the end of the last co-located
// buffer. There could be "holes" in the live ranges of each co-located
// buffers, but in this heuristics we think they are contiguous.
absl::c_sort(sorted_buffer_intervals,
[&](const BufferInterval& x, const BufferInterval& y) {
int64 x_end = x.end;
for (auto colocation : GetTransitiveColocations(x)) {
x_end = std::max(x_end, buffer_intervals_[colocation].end);
}
int64 y_end = y.end;
for (auto colocation : GetTransitiveColocations(y)) {
y_end = std::max(y_end, buffer_intervals_[colocation].end);
}
if (x_end - x.start != y_end - y.start) {
return x_end - x.start > y_end - y.start;
}
if (x.size != y.size) {
return x.size > y.size;
}
return x.buffer->id() < y.buffer->id();
});
} else {
// Sort by spatial size. We don't look at co-locates as they should have the
// same size.
CHECK(type_ == kSpatial);
absl::c_sort(sorted_buffer_intervals,
[&](const BufferInterval& x, const BufferInterval& y) {
if (x.size != y.size) {
return x.size > y.size;
}
if (x.end - x.start != y.end - y.start) {
return x.end - x.start > y.end - y.start;
}
return x.buffer->id() < y.buffer->id();
});
}
BufferIntervalTree interval_tree(sorted_buffer_intervals.size());
for (auto& buffer_interval : sorted_buffer_intervals) {
if (!buffer_interval.need_allocation) {
continue;
}
VLOG(1) << "Finding chunks for buffer: "
<< buffer_interval.buffer->ToString();
VLOG(1) << "Size " << buffer_interval.size << ", start "
<< buffer_interval.start << ", end " << buffer_interval.end;
auto chunks_overlapping_in_time = interval_tree.ChunksOverlappingInTime(
buffer_interval.start, buffer_interval.end);
// Get all colocated buffers and gather all interferenced chunks.
//
// Imagine that we've already allocated three chunks : a, b and c. And now
// we want to allocate d. Since e is colocated with d, we have to allocate
// chunks for them together at the same address. To do this, we first gather
// all chunks that overlap with d and e on the time dimension, in this case
// the overlapped chunks are a and b (c doesn't overlap with either of d and
// e), then find create a new chunk that doesn't overlap with a and b on the
// space dimension.
//
// space
// ^
// |+--d---+ +---e---+
// |
// |+---+ +---------------+ +-------+
// || | | | | |
// || | | | | |
// |+-a-+ +-------b-------+ +---c---+
// ----------------------------------------> time
for (auto colocation : GetTransitiveColocations(buffer_interval)) {
auto colocation_interval = buffer_intervals_[colocation];
auto colocation_overlapping = interval_tree.ChunksOverlappingInTime(
colocation_interval.start, colocation_interval.end);
VLOG(1) << " Alias size " << colocation_interval.size << ", start "
<< colocation_interval.start << ", end "
<< colocation_interval.end << " "
<< colocation_interval.buffer->ToString();
chunks_overlapping_in_time.insert(chunks_overlapping_in_time.end(),
colocation_overlapping.begin(),
colocation_overlapping.end());
}
absl::c_sort(
chunks_overlapping_in_time,
[](const Chunk& x, const Chunk& y) { return x.offset < y.offset; });
// Find the minimum free chunk that can hold this buffer.
Chunk min_fit_chunk{-1, INT64_MAX};
auto use_free_chunk_if_smaller = [&](int64 free_offset, int64 free_size) {
if (free_size < buffer_interval.size) {
return;
}
if (free_size < min_fit_chunk.size) {
min_fit_chunk = {free_offset, free_size};
}
};
int64 offset = 0;
for (auto& chunk : chunks_overlapping_in_time) {
if (offset < chunk.offset) {
use_free_chunk_if_smaller(offset, chunk.offset - offset);
}
offset =
std::max(offset, RoundUpToNearest(chunk.chunk_end(), alignment_));
}
use_free_chunk_if_smaller(offset, result_.heap_size - offset);
if (min_fit_chunk.offset == -1) {
// Increase the heap size to fit in the last free chunk.
result_.heap_size = offset + buffer_interval.size;
min_fit_chunk = {offset, buffer_interval.size};
}
min_fit_chunk.size = buffer_interval.size;
const auto emplace_result =
result_.chunk_map.emplace(buffer_interval.buffer, min_fit_chunk);
DCHECK(emplace_result.second);
interval_tree.Add(buffer_interval.start, buffer_interval.end,
min_fit_chunk);
for (auto colocation : GetTransitiveColocations(buffer_interval)) {
const auto emplace_result =
result_.chunk_map.emplace(colocation, min_fit_chunk);
DCHECK(emplace_result.second);
auto colocation_interval = buffer_intervals_[colocation];
interval_tree.Add(colocation_interval.start, colocation_interval.end,
min_fit_chunk);
}
}
VLOG(1) << "result heap_size: " << result_.heap_size;
return result_;
}
HeapSimulator::Result ChooseBestHeapAlgorithm::Finish() {
DCHECK(!algorithms_.empty());
std::vector<Result> results(algorithms_.size());
int64 min_size = INT64_MAX;
int min_size_index = -1;
for (int i = 0; i < algorithms_.size(); ++i) {
results[i] = algorithms_[i]->Finish();
if (results[i].heap_size < min_size) {
min_size = results[i].heap_size;
min_size_index = i;
}
}
DCHECK_GE(min_size_index, 0);
return results[min_size_index];
}
} // namespace xla
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %rax
push %rbp
push %rbx
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_normal_ht+0xd2f7, %rsi
inc %rdx
and $0xffffffffffffffc0, %rsi
vmovntdqa (%rsi), %ymm3
vextracti128 $1, %ymm3, %xmm3
vpextrq $0, %xmm3, %rcx
nop
nop
nop
nop
nop
dec %rbp
lea addresses_WT_ht+0x166f7, %rax
xor %rsi, %rsi
movb $0x61, (%rax)
nop
nop
nop
nop
xor %rdx, %rdx
lea addresses_D_ht+0x3cde, %rsi
lea addresses_WT_ht+0x1d047, %rdi
sub $43127, %rdx
mov $36, %rcx
rep movsw
nop
nop
nop
nop
nop
sub %rax, %rax
lea addresses_WC_ht+0x18ef7, %rcx
nop
nop
nop
nop
xor $40331, %r11
movb $0x61, (%rcx)
nop
add $26277, %rbp
lea addresses_WT_ht+0x1cef7, %rcx
nop
nop
sub %rax, %rax
mov (%rcx), %rbp
nop
nop
nop
nop
xor %rsi, %rsi
lea addresses_D_ht+0x11977, %rsi
lea addresses_UC_ht+0xcaf7, %rdi
nop
nop
xor %rbx, %rbx
mov $30, %rcx
rep movsw
nop
add %rdx, %rdx
lea addresses_UC_ht+0x11cef, %rbp
nop
nop
nop
nop
and $1588, %rdx
movw $0x6162, (%rbp)
nop
nop
nop
cmp $14841, %rdi
lea addresses_WC_ht+0x127f7, %rsi
lea addresses_WT_ht+0x1e2f7, %rdi
nop
nop
nop
nop
xor $12024, %rbp
mov $14, %rcx
rep movsl
nop
inc %rbp
lea addresses_D_ht+0xaf7, %rdi
nop
nop
nop
add %rcx, %rcx
mov $0x6162636465666768, %rsi
movq %rsi, %xmm6
movups %xmm6, (%rdi)
nop
nop
nop
cmp $45471, %rbp
lea addresses_normal_ht+0xf237, %rdx
nop
nop
nop
nop
nop
cmp $39884, %rcx
movw $0x6162, (%rdx)
nop
nop
nop
nop
dec %rdx
lea addresses_D_ht+0x90f7, %rsi
nop
nop
add %rbp, %rbp
mov $0x6162636465666768, %rbx
movq %rbx, (%rsi)
add $56739, %rdi
lea addresses_WC_ht+0xfaf7, %rdx
clflush (%rdx)
add %rax, %rax
mov $0x6162636465666768, %rsi
movq %rsi, %xmm7
vmovups %ymm7, (%rdx)
add %rsi, %rsi
lea addresses_A_ht+0x14af7, %rcx
cmp $1838, %rax
movb $0x61, (%rcx)
nop
nop
nop
nop
cmp $58574, %rdx
lea addresses_UC_ht+0x11977, %rdx
clflush (%rdx)
nop
nop
and %rbp, %rbp
movb (%rdx), %bl
sub $36982, %rax
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rbx
pop %rbp
pop %rax
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r12
push %r13
push %r15
push %r9
push %rbp
push %rdi
push %rdx
// Store
mov $0x641ec50000000ef7, %r12
nop
nop
sub %r15, %r15
mov $0x5152535455565758, %r13
movq %r13, %xmm7
vmovups %ymm7, (%r12)
add %rbp, %rbp
// Faulty Load
lea addresses_PSE+0x122f7, %rbp
nop
nop
nop
nop
xor $31720, %r9
mov (%rbp), %r15
lea oracles, %rdi
and $0xff, %r15
shlq $12, %r15
mov (%rdi,%r15,1), %r15
pop %rdx
pop %rdi
pop %rbp
pop %r9
pop %r15
pop %r13
pop %r12
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_PSE', 'AVXalign': False, 'congruent': 0, 'size': 4, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_NC', 'AVXalign': False, 'congruent': 10, 'size': 32, 'same': False, 'NT': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_PSE', 'AVXalign': False, 'congruent': 0, 'size': 8, 'same': True, 'NT': False}}
<gen_prepare_buffer>
{'OP': 'LOAD', 'src': {'type': 'addresses_normal_ht', 'AVXalign': False, 'congruent': 9, 'size': 32, 'same': False, 'NT': True}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'AVXalign': False, 'congruent': 10, 'size': 1, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 0, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 3, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 9, 'size': 1, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'AVXalign': False, 'congruent': 9, 'size': 8, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 7, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 10, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 3, 'size': 2, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 8, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 11, 'same': True}}
{'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'AVXalign': False, 'congruent': 9, 'size': 16, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'AVXalign': False, 'congruent': 6, 'size': 2, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'AVXalign': False, 'congruent': 8, 'size': 8, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 10, 'size': 32, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'AVXalign': False, 'congruent': 10, 'size': 1, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 6, 'size': 1, 'same': False, 'NT': False}}
{'33': 21829}
33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33
*/
|
//=================================================================================================
/*!
// \file src/mathtest/dvecsveckron/VDbVCb.cpp
// \brief Source file for the VDbVCb dense vector/sparse vector Kronecker product math test
//
// Copyright (C) 2012-2020 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <cstdlib>
#include <iostream>
#include <blaze/math/CompressedVector.h>
#include <blaze/math/DynamicVector.h>
#include <blazetest/mathtest/Creator.h>
#include <blazetest/mathtest/dvecsveckron/OperationTest.h>
#include <blazetest/system/MathTest.h>
#ifdef BLAZE_USE_HPX_THREADS
# include <hpx/hpx_main.hpp>
#endif
//=================================================================================================
//
// MAIN FUNCTION
//
//=================================================================================================
//*************************************************************************************************
int main()
{
std::cout << " Running 'VDbVCb'..." << std::endl;
using blazetest::mathtest::TypeB;
try
{
// Vector type definitions
using VDb = blaze::DynamicVector<TypeB>;
using VCb = blaze::CompressedVector<TypeB>;
// Creator type definitions
using CVDb = blazetest::Creator<VDb>;
using CVCb = blazetest::Creator<VCb>;
// Running tests with small vectors
for( size_t i=0UL; i<=6UL; ++i ) {
for( size_t j=0UL; j<=6UL; ++j ) {
for( size_t k=0UL; k<=j; ++k ) {
RUN_DVECSVECKRON_OPERATION_TEST( CVDb( i ), CVCb( j, k ) );
}
}
}
// Running tests with large vectors
RUN_DVECSVECKRON_OPERATION_TEST( CVDb( 16UL ), CVCb( 17UL, 7UL ) );
RUN_DVECSVECKRON_OPERATION_TEST( CVDb( 31UL ), CVCb( 32UL, 8UL ) );
}
catch( std::exception& ex ) {
std::cerr << "\n\n ERROR DETECTED during dense vector/sparse vector Kronecker product:\n"
<< ex.what() << "\n";
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
//*************************************************************************************************
|
; ----------------------------------------------------------------
; Z88DK INTERFACE LIBRARY FOR NIRVANA+ ENGINE - by Einar Saukas
;
; See "nirvana+.h" for further details
; ----------------------------------------------------------------
SECTION code_clib
SECTION code_nirvanap
PUBLIC asm_NIRVANAP_spriteT
asm_NIRVANAP_spriteT:
add hl,hl
add hl,hl
add hl,hl ; HL=sprite*8
ld bc,56472
add hl,bc ; HL=56472+sprite*8
ld (hl),a ; tile
dec l
dec l
ld (hl),d ; lin
dec hl
ld (hl),e ; col
ret
|
%define BPM 100
%include "../src/sointu.inc"
BEGIN_PATTERNS
PATTERN 64, 0, 68, 0, 32, 0, 0, 0, 75, 0, 78, 0, 0, 0, 0, 0,
END_PATTERNS
BEGIN_TRACKS
TRACK VOICES(1),0
END_TRACKS
BEGIN_PATCH
BEGIN_INSTRUMENT VOICES(1) ; Instrument0
SU_ENVELOPE MONO,ATTAC(80),DECAY(80),SUSTAIN(64),RELEASE(80),GAIN(128)
SU_OSCILLAT MONO,TRANSPOSE(64),DETUNE(64),PHASE(0),COLOR(128),SHAPE(64),GAIN(128),FLAGS(SINE)
SU_MULP MONO
SU_DELAY MONO,PREGAIN(40),DRY(128),FEEDBACK(125),DAMP(64),DELAY(0),COUNT(1)
SU_PAN MONO,PANNING(64)
SU_OUT STEREO,GAIN(128)
SU_OSCILLAT MONO,TRANSPOSE(70),DETUNE(64),PHASE(64),COLOR(128),SHAPE(64),GAIN(128),FLAGS(SINE+LFO)
SU_SEND MONO,AMOUNT(32),PORT(3,delay,damp) + SEND_POP
END_INSTRUMENT
END_PATCH
BEGIN_DELTIMES
DELTIME 11025
END_DELTIMES
%include "../src/sointu.asm"
|
prog 1 1
add 0 1
dec 0
dec 0 |
; A180415: (n^3 - 3n^2 + 14n - 6)/6.
; 1,3,6,11,19,31,48,71,101,139,186,243,311,391,484,591,713,851,1006,1179,1371,1583,1816,2071,2349,2651,2978,3331,3711,4119,4556,5023,5521,6051,6614,7211,7843,8511,9216,9959,10741,11563,12426,13331,14279,15271,16308,17391,18521,19699,20926,22203,23531,24911,26344,27831,29373,30971,32626,34339,36111,37943,39836,41791,43809,45891,48038,50251,52531,54879,57296,59783,62341,64971,67674,70451,73303,76231,79236,82319,85481,88723,92046,95451,98939,102511,106168,109911,113741,117659,121666,125763,129951,134231,138604,143071,147633,152291,157046,161899
mov $1,$0
pow $0,2
add $0,11
mul $0,$1
div $0,6
add $0,1
|
SECTION code_fp_math32
PUBLIC asinh_fastcall
EXTERN _m32_asinhf
defc asinh_fastcall = _m32_asinhf
; SDCC bridge for Classic
IF __CLASSIC
PUBLIC _asinh_fastcall
defc _asinh_fastcall = _m32_asinhf
ENDIF
|
.global s_prepare_buffers
s_prepare_buffers:
push %r12
push %r13
push %r14
push %r15
push %rbp
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_A_ht+0xcd7f, %r15
nop
sub $51470, %rbp
movups (%r15), %xmm3
vpextrq $0, %xmm3, %rdx
inc %r12
lea addresses_WC_ht+0x181cf, %r14
nop
nop
sub %r13, %r13
mov $0x6162636465666768, %rdi
movq %rdi, %xmm3
vmovups %ymm3, (%r14)
nop
and $59167, %rbp
lea addresses_D_ht+0x10f8f, %r14
nop
nop
dec %rdi
mov (%r14), %r12w
nop
add $38515, %rbp
lea addresses_WT_ht+0x1553d, %r15
nop
nop
nop
add $15143, %r12
mov (%r15), %rdi
nop
nop
nop
nop
nop
add %rdx, %rdx
lea addresses_WC_ht+0x1d0af, %rsi
lea addresses_UC_ht+0x1b4af, %rdi
clflush (%rsi)
nop
nop
nop
add $25065, %r13
mov $70, %rcx
rep movsl
add %rcx, %rcx
lea addresses_D_ht+0xf11f, %rsi
lea addresses_A_ht+0x19bef, %rdi
nop
nop
nop
nop
and %r15, %r15
mov $86, %rcx
rep movsq
nop
nop
add %rcx, %rcx
lea addresses_UC_ht+0x6a17, %rcx
nop
nop
sub $44798, %rdx
mov $0x6162636465666768, %rsi
movq %rsi, %xmm3
vmovups %ymm3, (%rcx)
nop
nop
nop
sub %rdx, %rdx
lea addresses_WC_ht+0x1ccc7, %rcx
nop
nop
nop
nop
nop
sub %rsi, %rsi
mov $0x6162636465666768, %r15
movq %r15, %xmm2
movups %xmm2, (%rcx)
and %r15, %r15
lea addresses_normal_ht+0x1224b, %rsi
lea addresses_WC_ht+0x1037d, %rdi
nop
nop
add $552, %r14
mov $4, %rcx
rep movsl
nop
sub %rdx, %rdx
lea addresses_WC_ht+0x50ef, %rbp
nop
nop
nop
add $47074, %r12
mov (%rbp), %r14w
nop
add %rsi, %rsi
lea addresses_WC_ht+0x80f, %rcx
inc %rdi
movups (%rcx), %xmm5
vpextrq $1, %xmm5, %r15
sub %r15, %r15
lea addresses_A_ht+0x67cf, %rbp
nop
nop
nop
nop
nop
xor $48911, %rdi
movl $0x61626364, (%rbp)
nop
nop
nop
nop
nop
sub %rdx, %rdx
lea addresses_A_ht+0x78bf, %rsi
sub $13221, %rdx
movl $0x61626364, (%rsi)
nop
nop
dec %r15
lea addresses_WC_ht+0x40ef, %rsi
lea addresses_WT_ht+0x17fef, %rdi
nop
xor $28065, %rdx
mov $110, %rcx
rep movsb
nop
nop
nop
and $37165, %rcx
lea addresses_UC_ht+0x8aef, %rsi
lea addresses_A_ht+0x1e5ef, %rdi
nop
nop
nop
nop
nop
add %rbp, %rbp
mov $76, %rcx
rep movsq
nop
sub %r13, %r13
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rbp
pop %r15
pop %r14
pop %r13
pop %r12
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r9
push %rbp
push %rbx
push %rcx
push %rdx
// Store
lea addresses_WT+0x1e41f, %r10
sub $55313, %r9
mov $0x5152535455565758, %rcx
movq %rcx, (%r10)
nop
nop
nop
sub %rbp, %rbp
// Faulty Load
lea addresses_A+0x85ef, %rbx
nop
nop
nop
nop
nop
cmp %r9, %r9
movups (%rbx), %xmm0
vpextrq $0, %xmm0, %rbp
lea oracles, %rcx
and $0xff, %rbp
shlq $12, %rbp
mov (%rcx,%rbp,1), %rbp
pop %rdx
pop %rcx
pop %rbx
pop %rbp
pop %r9
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_A', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 4, 'same': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_A', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}}
<gen_prepare_buffer>
{'OP': 'LOAD', 'src': {'type': 'addresses_A_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 4, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 5, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 5, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 8, 'AVXalign': False, 'NT': True, 'congruent': 1, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 4, 'same': True}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 6, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 4, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 9, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 3, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 3, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 2, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 0, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 8, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 4, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 3, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 4, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 6, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 5, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 8, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 11, 'same': False}}
{'00': 1, '35': 6654}
00 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35
*/
|
#include "SCN.h"
SCN::SCN(std::string name, Serial * serialport)
{
this->serialport = serialport;
#ifdef TARGET_MACOS
serviceId = CFStringCreateWithCString( NULL, "Hologram PPP Connection" , kCFStringEncodingUTF8 );
#endif
}
SCN::~SCN()
{
#ifdef TARGET_MACOS
if (m_connection)
{
SCNetworkConnectionUnscheduleFromRunLoop(m_connection, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
CFRelease(m_connection);
m_connection = NULL;
}
#endif
}
bool SCN::connect(){
#ifdef TARGET_MACOS
const void *pppKeys[3], *pppVals[3];
pppKeys[index] = (void*) kSCPropNetPPPAuthName;
pppVals[index] = (void*) cfUsername;
CFDictionaryRef pppDialOptions;
pppDialOptions = CFDictionaryCreate( NULL
, pppKeys
, pppVals
, index
, &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks );
CFStringRef keys[] = { kSCEntNetPPP };
CFDictionaryRef vals[] = { pppDialOptions };
CFDictionaryRef optionsForDial;
optionsForDial = CFDictionaryCreate( NULL
, (const void **) &keys
, (const void **) &vals
, 1
, &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks );
// create a connection reference
if (m_connection)
{
SCNetworkConnectionUnscheduleFromRunLoop(m_connection, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
CFRelease(m_connection);
m_connection = NULL;
}
for (int I = 0; I < 3; I++)
{
SCNetworkConnectionRef connection;
connection = SCNetworkConnectionCreateWithServiceID(NULL, serviceId, Connection::callback, NULL );
if (!connection) return NULL;
Boolean ok;
ok = SCNetworkConnectionScheduleWithRunLoop(connection, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode );
if (!ok) return NULL;
ok = SCNetworkConnectionStart(connection, optionsForDial, false);
if (ok) return connection;
sleep(3);
}
#endif
return false;
}
|
; A001750: Primes multiplied by 5.
; Submitted by Jamie Morken(s3)
; 10,15,25,35,55,65,85,95,115,145,155,185,205,215,235,265,295,305,335,355,365,395,415,445,485,505,515,535,545,565,635,655,685,695,745,755,785,815,835,865,895,905,955,965,985,995,1055,1115,1135,1145,1165,1195,1205,1255,1285,1315,1345,1355,1385,1405,1415,1465,1535,1555,1565,1585,1655,1685,1735,1745,1765,1795,1835,1865,1895,1915,1945,1985,2005,2045,2095,2105,2155,2165,2195,2215,2245,2285,2305,2315,2335,2395,2435,2455,2495,2515,2545,2605,2615,2705
mul $0,2
max $0,1
seq $0,173919 ; Numbers that are prime or one less than a prime.
mul $0,5
|
; Licensed to the .NET Foundation under one or more agreements.
; The .NET Foundation licenses this file to you under the MIT license.
; ==++==
;
;
; ==--==
ifdef FEATURE_COMINTEROP
include AsmMacros.inc
include asmconstants.inc
extern CallDescrWorkerUnwindFrameChainHandler:proc
extern ReverseComUnwindFrameChainHandler:proc
extern COMToCLRWorker:proc
extern JIT_FailFast:proc
extern s_gsCookie:qword
NESTED_ENTRY GenericComCallStub, _TEXT, ReverseComUnwindFrameChainHandler
;
; Set up a ComMethodFrame and call COMToCLRWorker.
;
; Stack frame layout:
;
; (stack parameters)
; ...
; r9
; r8
; rdx
; rcx
; UnmanagedToManagedFrame::m_ReturnAddress
; UnmanagedToManagedFrame::m_Datum
; Frame::m_Next
; __VFN_table <-- rsp + GenericComCallStub_ComMethodFrame_OFFSET
; GSCookie
; (optional padding to qword align xmm save area)
; xmm3
; xmm2
; xmm1
; xmm0 <-- rsp + GenericComCallStub_XMM_SAVE_OFFSET
; r12
; r13
; r14
; (optional padding to qword align rsp)
; callee's r9
; callee's r8
; callee's rdx
; callee's rcx
GenericComCallStub_STACK_FRAME_SIZE = 0
; ComMethodFrame MUST be the highest part of the stack frame, immediately
; below the return address and MethodDesc*, so that
; UnmanagedToManagedFrame::m_ReturnAddress and
; UnmanagedToManagedFrame::m_Datum are the right place.
GenericComCallStub_STACK_FRAME_SIZE = GenericComCallStub_STACK_FRAME_SIZE + (SIZEOF__ComMethodFrame - 8)
GenericComCallStub_ComMethodFrame_NEGOFFSET = GenericComCallStub_STACK_FRAME_SIZE
GenericComCallStub_STACK_FRAME_SIZE = GenericComCallStub_STACK_FRAME_SIZE + SIZEOF_GSCookie
; Ensure that the offset of the XMM save area will be 16-byte aligned.
if ((GenericComCallStub_STACK_FRAME_SIZE + 8) MOD 16) ne 0
GenericComCallStub_STACK_FRAME_SIZE = GenericComCallStub_STACK_FRAME_SIZE + 8
endif
; XMM save area MUST be immediately below GenericComCallStub
; (w/ alignment padding)
GenericComCallStub_STACK_FRAME_SIZE = GenericComCallStub_STACK_FRAME_SIZE + 4*16
GenericComCallStub_XMM_SAVE_NEGOFFSET = GenericComCallStub_STACK_FRAME_SIZE
; Add in the callee scratch area size.
GenericComCallStub_CALLEE_SCRATCH_SIZE = 4*8
GenericComCallStub_STACK_FRAME_SIZE = GenericComCallStub_STACK_FRAME_SIZE + GenericComCallStub_CALLEE_SCRATCH_SIZE
; Now we have the full size of the stack frame. The offsets have been computed relative to the
; top, so negate them to make them relative to the post-prologue rsp.
GenericComCallStub_ComMethodFrame_OFFSET = GenericComCallStub_STACK_FRAME_SIZE - GenericComCallStub_ComMethodFrame_NEGOFFSET
GenericComCallStub_XMM_SAVE_OFFSET = GenericComCallStub_STACK_FRAME_SIZE - GenericComCallStub_XMM_SAVE_NEGOFFSET
OFFSETOF_GSCookie = GenericComCallStub_ComMethodFrame_OFFSET - SIZEOF_GSCookie
.allocstack 8 ; UnmanagedToManagedFrame::m_Datum, pushed by prepad
;
; Allocate the remainder of the ComMethodFrame. The fields
; will be filled in by COMToCLRWorker
;
alloc_stack SIZEOF__ComMethodFrame - 10h
;
; Save ComMethodFrame* to pass to COMToCLRWorker
;
mov r10, rsp
alloc_stack GenericComCallStub_ComMethodFrame_OFFSET
;
; Save argument registers
;
SAVE_ARGUMENT_REGISTERS GenericComCallStub_STACK_FRAME_SIZE + 8h
;
; spill the fp args
;
SAVE_FLOAT_ARGUMENT_REGISTERS GenericComCallStub_XMM_SAVE_OFFSET
END_PROLOGUE
mov rcx, s_gsCookie
mov [rsp + OFFSETOF_GSCookie], rcx
;
; Call COMToCLRWorker. Note that the first parameter (pThread) is
; filled in by callee.
;
ifdef _DEBUG
mov rcx, 0cccccccccccccccch
endif
mov rdx, r10
call COMToCLRWorker
ifdef _DEBUG
mov rcx, s_gsCookie
cmp [rsp + OFFSETOF_GSCookie], rcx
je GoodGSCookie
call JIT_FailFast
GoodGSCookie:
endif ; _DEBUG
;
; epilogue
;
add rsp, GenericComCallStub_STACK_FRAME_SIZE
ret
NESTED_END GenericComCallStub, _TEXT
; ARG_SLOT COMToCLRDispatchHelperWithStack(DWORD dwStackSlots, // rcx
; ComMethodFrame *pFrame, // rdx
; PCODE pTarget, // r8
; PCODE pSecretArg, // r9
; INT_PTR pDangerousThis // rbp+40h
; );
NESTED_ENTRY COMToCLRDispatchHelperWithStack, _TEXT, CallDescrWorkerUnwindFrameChainHandler
ComMethodFrame_Arguments_OFFSET = SIZEOF__ComMethodFrame
ComMethodFrame_XMM_SAVE_OFFSET = GenericComCallStub_XMM_SAVE_OFFSET - GenericComCallStub_ComMethodFrame_OFFSET
push_nonvol_reg rdi ; save nonvolatile registers
push_nonvol_reg rsi ;
push_nonvol_reg rbp ;
set_frame rbp, 0 ; set frame pointer
END_PROLOGUE
;
; copy stack
;
lea rsi, [rdx + ComMethodFrame_Arguments_OFFSET]
add ecx, 4 ; outgoing argument homes
mov eax, ecx ; number of stack slots
shl eax, 3 ; compute number of argument bytes
add eax, 8h ; alignment padding
and rax, 0FFFFFFFFFFFFFFf0h ; for proper stack alignment, v-liti remove partial register stall
sub rsp, rax ; allocate argument list
mov rdi, rsp ; set destination argument list address
rep movsq ; copy arguments to the stack
; Stack layout:
;
; callee's rcx (to be loaded into rcx) <- rbp+40h
; r9 (to be loaded into r10)
; r8 (IL stub entry point)
; rdx (ComMethodFrame ptr)
; rcx (number of stack slots to repush)
; return address
; saved rdi
; saved rsi
; saved rbp <- rbp
; alignment
; (stack parameters)
; callee's r9
; callee's r8
; callee's rdx
; callee's rcx (not loaded into rcx) <- rsp
;
; load fp registers
;
movdqa xmm0, [rdx + ComMethodFrame_XMM_SAVE_OFFSET + 00h]
movdqa xmm1, [rdx + ComMethodFrame_XMM_SAVE_OFFSET + 10h]
movdqa xmm2, [rdx + ComMethodFrame_XMM_SAVE_OFFSET + 20h]
movdqa xmm3, [rdx + ComMethodFrame_XMM_SAVE_OFFSET + 30h]
;
; load secret arg and target
;
mov r10, r9
mov rax, r8
;
; load argument registers
;
mov rcx, [rbp + 40h] ; ignoring the COM IP at [rsp]
mov rdx, [rsp + 08h]
mov r8, [rsp + 10h]
mov r9, [rsp + 18h]
;
; call the target
;
call rax
; It is important to have an instruction between the previous call and the epilog.
; If the return address is in epilog, OS won't call personality routine because
; it thinks personality routine does not help in this case.
nop
;
; epilog
;
lea rsp, 0[rbp] ; deallocate argument list
pop rbp ; restore nonvolatile register
pop rsi ;
pop rdi ;
ret
NESTED_END COMToCLRDispatchHelperWithStack, _TEXT
; ARG_SLOT COMToCLRDispatchHelper(DWORD dwStackSlots, // rcx
; ComMethodFrame *pFrame, // rdx
; PCODE pTarget, // r8
; PCODE pSecretArg, // r9
; INT_PTR pDangerousThis // rsp + 28h on entry
; );
NESTED_ENTRY COMToCLRDispatchHelper, _TEXT, CallDescrWorkerUnwindFrameChainHandler
;
; Check to see if we have stack to copy and, if so, tail call to
; the routine that can handle that.
;
test ecx, ecx
jnz COMToCLRDispatchHelperWithStack
alloc_stack 28h ; alloc scratch space + alignment, pDangerousThis moves to [rsp+50]
END_PROLOGUE
; get pointer to arguments
lea r11, [rdx + ComMethodFrame_Arguments_OFFSET]
;
; load fp registers
;
movdqa xmm0, [rdx + ComMethodFrame_XMM_SAVE_OFFSET + 00h]
movdqa xmm1, [rdx + ComMethodFrame_XMM_SAVE_OFFSET + 10h]
movdqa xmm2, [rdx + ComMethodFrame_XMM_SAVE_OFFSET + 20h]
movdqa xmm3, [rdx + ComMethodFrame_XMM_SAVE_OFFSET + 30h]
;
; load secret arg and target
;
mov r10, r9
mov rax, r8
;
; load argument registers
;
mov rcx, [rsp + 50h] ; ignoring the COM IP at [r11 + 00h]
mov rdx, [r11 + 08h]
mov r8, [r11 + 10h]
mov r9, [r11 + 18h]
;
; call the target
;
call rax
; It is important to have an instruction between the previous call and the epilog.
; If the return address is in epilog, OS won't call personality routine because
; it thinks personality routine does not help in this case.
nop
;
; epilog
;
add rsp, 28h
ret
NESTED_END COMToCLRDispatchHelper, _TEXT
endif ; FEATURE_COMINTEROP
end
|
; A071187: Smallest prime factor of number of divisors of n.
; 1,2,2,3,2,2,2,2,3,2,2,2,2,2,2,5,2,2,2,2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,7,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,5,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3
seq $0,52409 ; a(n) = largest integer power m for which a representation of the form n = k^m exists (for some k).
seq $0,20639 ; Lpf(n): least prime dividing n (when n > 1); a(1) = 1. Or, smallest prime factor of n, or smallest prime divisor of n.
|
<%
import collections
import pwnlib.abi
import pwnlib.constants
import pwnlib.shellcraft
import six
%>
<%docstring>sigsuspend(set) -> str
Invokes the syscall sigsuspend.
See 'man 2 sigsuspend' for more information.
Arguments:
set(sigset_t*): set
Returns:
int
</%docstring>
<%page args="set=0"/>
<%
abi = pwnlib.abi.ABI.syscall()
stack = abi.stack
regs = abi.register_arguments[1:]
allregs = pwnlib.shellcraft.registers.current()
can_pushstr = []
can_pushstr_array = []
argument_names = ['set']
argument_values = [set]
# Load all of the arguments into their destination registers / stack slots.
register_arguments = dict()
stack_arguments = collections.OrderedDict()
string_arguments = dict()
dict_arguments = dict()
array_arguments = dict()
syscall_repr = []
for name, arg in zip(argument_names, argument_values):
if arg is not None:
syscall_repr.append('%s=%r' % (name, arg))
# If the argument itself (input) is a register...
if arg in allregs:
index = argument_names.index(name)
if index < len(regs):
target = regs[index]
register_arguments[target] = arg
elif arg is not None:
stack_arguments[index] = arg
# The argument is not a register. It is a string value, and we
# are expecting a string value
elif name in can_pushstr and isinstance(arg, (six.binary_type, six.text_type)):
if isinstance(arg, six.text_type):
arg = arg.encode('utf-8')
string_arguments[name] = arg
# The argument is not a register. It is a dictionary, and we are
# expecting K:V paris.
elif name in can_pushstr_array and isinstance(arg, dict):
array_arguments[name] = ['%s=%s' % (k,v) for (k,v) in arg.items()]
# The arguent is not a register. It is a list, and we are expecting
# a list of arguments.
elif name in can_pushstr_array and isinstance(arg, (list, tuple)):
array_arguments[name] = arg
# The argument is not a register, string, dict, or list.
# It could be a constant string ('O_RDONLY') for an integer argument,
# an actual integer value, or a constant.
else:
index = argument_names.index(name)
if index < len(regs):
target = regs[index]
register_arguments[target] = arg
elif arg is not None:
stack_arguments[target] = arg
# Some syscalls have different names on various architectures.
# Determine which syscall number to use for the current architecture.
for syscall in ['SYS_sigsuspend']:
if hasattr(pwnlib.constants, syscall):
break
else:
raise Exception("Could not locate any syscalls: %r" % syscalls)
%>
/* sigsuspend(${', '.join(syscall_repr)}) */
%for name, arg in string_arguments.items():
${pwnlib.shellcraft.pushstr(arg, append_null=(b'\x00' not in arg))}
${pwnlib.shellcraft.mov(regs[argument_names.index(name)], abi.stack)}
%endfor
%for name, arg in array_arguments.items():
${pwnlib.shellcraft.pushstr_array(regs[argument_names.index(name)], arg)}
%endfor
%for name, arg in stack_arguments.items():
${pwnlib.shellcraft.push(arg)}
%endfor
${pwnlib.shellcraft.setregs(register_arguments)}
${pwnlib.shellcraft.syscall(syscall)} |
%include "boot/x86_64/constants.asm"
[BITS 64]
global start
extern g8start
section .entry
start:
; update segments
xor ax, ax
mov ss, ax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
; set up stack
mov rsp, STACK_TOP
; jump to bootloader
jmp g8start
;hlt
; reserve space for stack
|
; A044702: Numbers n such that string 7,7 occurs in the base 9 representation of n but not of n+1.
; 70,151,232,313,394,475,556,638,718,799,880,961,1042,1123,1204,1285,1367,1447,1528,1609,1690,1771,1852,1933,2014,2096,2176,2257,2338,2419,2500,2581,2662,2743,2825,2905,2986,3067,3148
mov $1,$0
add $1,10
mod $1,9
div $1,8
add $1,70
mov $2,$0
mul $2,81
add $1,$2
|
; A273448: First differences of number of active (ON,black) cells in n-th stage of growth of two-dimensional cellular automaton defined by "Rule 721", based on the 5-celled von Neumann neighborhood.
; 3,17,20,39,40,48,56,64,72,80,88,96,104,112,120,128,136,144,152,160,168,176,184,192,200,208,216,224,232,240,248,256,264,272,280,288,296,304,312,320,328,336,344,352,360,368,376,384,392,400,408,416,424,432,440,448,456,464,472,480,488,496,504,512,520,528,536,544,552,560,568,576,584,592,600,608,616,624,632,640,648,656,664,672,680,688,696,704,712,720,728,736,744,752,760,768,776,784,792,800
mov $9,$0
add $0,4
mov $2,$0
mov $4,$0
mov $5,$0
add $5,6
mov $6,$0
mov $7,2
lpb $2
lpb $4
add $7,4
mov $4,$7
sub $5,4
add $5,$7
mov $1,$5
cmp $7,$5
lpe
lpb $5
add $1,$4
sub $1,1
add $1,$4
trn $5,$6
lpe
mov $2,1
mov $3,$4
add $3,$1
mov $4,8
add $4,$3
mov $3,$4
lpe
mov $1,$3
sub $1,30
mov $8,$9
mul $8,7
add $1,$8
mov $0,$1
|
; A096026: Numbers n such that (n+j) mod (2+j) = 1 for j from 0 to 8 and (n+9) mod 11 <> 1.
; 2523,5043,7563,10083,12603,15123,17643,20163,22683,25203,30243,32763,35283,37803,40323,42843,45363,47883,50403,52923,57963,60483,63003,65523,68043,70563,73083,75603,78123,80643,85683,88203,90723,93243,95763,98283,100803,103323,105843,108363,113403,115923,118443,120963,123483,126003,128523,131043,133563,136083,141123,143643,146163,148683,151203,153723,156243,158763,161283,163803,168843,171363,173883,176403,178923,181443,183963,186483,189003,191523,196563,199083,201603,204123,206643,209163,211683,214203,216723,219243,224283,226803,229323,231843,234363,236883,239403,241923,244443,246963,252003,254523,257043,259563,262083,264603,267123,269643,272163,274683,279723,282243,284763,287283,289803,292323,294843,297363,299883,302403,307443,309963,312483,315003,317523,320043,322563,325083,327603,330123,335163,337683,340203,342723,345243,347763,350283,352803,355323,357843,362883,365403,367923,370443,372963,375483,378003,380523,383043,385563,390603,393123,395643,398163,400683,403203,405723,408243,410763,413283,418323,420843,423363,425883,428403,430923,433443,435963,438483,441003,446043,448563,451083,453603,456123,458643,461163,463683,466203,468723,473763,476283,478803,481323,483843,486363,488883,491403,493923,496443,501483,504003,506523,509043,511563,514083,516603,519123,521643,524163,529203,531723,534243,536763,539283,541803,544323,546843,549363,551883,556923,559443,561963,564483,567003,569523,572043,574563,577083,579603,584643,587163,589683,592203,594723,597243,599763,602283,604803,607323,612363,614883,617403,619923,622443,624963,627483,630003,632523,635043,640083,642603,645123,647643,650163,652683,655203,657723,660243,662763,667803,670323,672843,675363,677883,680403,682923,685443,687963,690483
mov $1,$0
div $0,10
add $1,$0
mul $1,2520
add $1,2523
|
; A060453: Dot product of the squares and the quarter-squares: a(n) = sum(i=1..n, i^2 * floor(i^2/4)).
; 0,4,22,86,236,560,1148,2172,3792,6292,9922,15106,22204,31808,44408,60792,81600,107844,140334,180334,228844,287408,357236,440180,537680,651924,784602,938266,1114876,1317376,1548016,1810160,2106368,2440452
mov $23,$0
mov $25,$0
lpb $25
clr $0,23
mov $0,$23
sub $25,1
sub $0,$25
mov $20,$0
mov $22,$0
lpb $22
clr $0,20
mov $0,$20
sub $22,1
sub $0,$22
mov $17,$0
mov $19,$0
lpb $19
mov $0,$17
sub $19,1
sub $0,$19
mov $13,$0
mov $15,2
lpb $15
sub $15,1
add $0,$15
sub $0,1
mov $9,$0
mov $11,2
lpb $11
mov $0,$9
sub $11,1
add $0,$11
sub $0,1
mov $6,1
add $6,$0
mov $0,$6
pow $0,2
mov $1,$0
div $1,2
mul $1,$0
mov $0,$6
mov $12,$11
lpb $12
mov $10,$1
sub $12,1
lpe
lpe
lpb $9
mov $9,0
sub $10,$1
lpe
mov $1,$10
mov $16,$15
lpb $16
mov $14,$1
sub $16,1
lpe
lpe
lpb $13
mov $13,0
sub $14,$1
lpe
mov $1,$14
div $1,4
mul $1,2
add $18,$1
lpe
add $21,$18
lpe
add $24,$21
lpe
mov $1,$24
|
; A130606: a(n) = prime(n+1)^n - prime(n)^n where prime(n) is the n-th prime number.
; Submitted by Simon Strandgaard
; 1,16,218,12240,210242,19310760,483533066,61327422240,12705993314406,398921053680600,152509144883055582,15980538294526150800,793161021967277155922,182781628843528905568920,61073803538208251485772814
add $0,1
mov $3,$0
mov $5,$0
add $5,1
lpb $5
sub $5,1
sub $0,$5
seq $0,40 ; The prime numbers.
mov $2,$0
mov $0,$3
pow $2,$3
sub $2,$4
add $4,$2
lpe
mov $0,$2
|
//==--- kernel_program_cache.hpp - Cache for kernel and program -*- C++-*---==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#pragma once
#include <CL/sycl/detail/locked.hpp>
#include <CL/sycl/detail/os_util.hpp>
#include <CL/sycl/detail/pi.hpp>
#include <detail/platform_impl.hpp>
#include <atomic>
#include <condition_variable>
#include <map>
#include <mutex>
#include <type_traits>
__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {
namespace detail {
class context_impl;
class KernelProgramCache {
public:
/// Denotes build error data. The data is filled in from cl::sycl::exception
/// class instance.
struct BuildError {
std::string Msg;
pi_int32 Code;
bool isFilledIn() const {
return !Msg.empty();
}
};
/// Denotes pointer to some entity with its general state and build error.
/// The pointer is not null if and only if the entity is usable.
/// State of the entity is provided by the user of cache instance.
/// Currently there is only a single user - ProgramManager class.
template<typename T> struct BuildResult {
std::atomic<T *> Ptr;
std::atomic<int> State;
BuildError Error;
BuildResult(T* P, int S) : Ptr{P}, State{S}, Error{"", 0} {}
};
using PiProgramT = std::remove_pointer<RT::PiProgram>::type;
using PiProgramPtrT = std::atomic<PiProgramT *>;
using ProgramWithBuildStateT = BuildResult<PiProgramT>;
using ProgramCacheT = std::map<OSModuleHandle, ProgramWithBuildStateT>;
using ContextPtr = context_impl *;
using PiKernelT = std::remove_pointer<RT::PiKernel>::type;
using PiKernelPtrT = std::atomic<PiKernelT *>;
using KernelWithBuildStateT = BuildResult<PiKernelT>;
using KernelByNameT = std::map<string_class, KernelWithBuildStateT>;
using KernelCacheT = std::map<RT::PiProgram, KernelByNameT>;
~KernelProgramCache();
void setContextPtr(const ContextPtr &AContext) { MParentContext = AContext; }
Locked<ProgramCacheT> acquireCachedPrograms() {
return {MCachedPrograms, MProgramCacheMutex};
}
Locked<KernelCacheT> acquireKernelsPerProgramCache() {
return {MKernelsPerProgramCache, MKernelsPerProgramCacheMutex};
}
template <class Predicate> void waitUntilBuilt(Predicate Pred) const {
std::unique_lock<std::mutex> Lock(MBuildCVMutex);
MBuildCV.wait(Lock, Pred);
}
void notifyAllBuild() const { MBuildCV.notify_all(); }
private:
std::mutex MProgramCacheMutex;
std::mutex MKernelsPerProgramCacheMutex;
mutable std::condition_variable MBuildCV;
mutable std::mutex MBuildCVMutex;
ProgramCacheT MCachedPrograms;
KernelCacheT MKernelsPerProgramCache;
ContextPtr MParentContext;
};
} // namespace detail
} // namespace sycl
} // __SYCL_INLINE_NAMESPACE(cl)
|
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* 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 <optional>
#include "velox/functions/prestosql/tests/FunctionBaseTest.h"
using namespace facebook::velox;
using namespace facebook::velox::functions::test;
namespace {
class ArrayExceptTest : public FunctionBaseTest {
protected:
void testExpr(
const VectorPtr& expected,
const std::string& expression,
const std::vector<VectorPtr>& input) {
auto result = evaluate<ArrayVector>(expression, makeRowVector(input));
assertEqualVectors(expected, result);
// Also test using dictionary encodings.
if (input.size() == 2) {
// Wrap first column in a dictionary: repeat each row twice. Wrap second
// column in the same dictionary, then flatten to prevent peeling of
// encodings. Wrap the expected result in the same dictionary.
// The expression evaluation on both dictionary inputs should result in
// the dictionary of the expected result vector.
auto newSize = input[0]->size() * 2;
auto indices = makeIndices(newSize, [](auto row) { return row / 2; });
auto firstDict = wrapInDictionary(indices, newSize, input[0]);
auto secondFlat = flatten(wrapInDictionary(indices, newSize, input[1]));
auto dictResult = evaluate<ArrayVector>(
expression, makeRowVector({firstDict, secondFlat}));
auto dictExpected = wrapInDictionary(indices, newSize, expected);
assertEqualVectors(dictExpected, dictResult);
}
}
template <typename T>
void testInt() {
auto array1 = makeNullableArrayVector<T>({
{1, -2, 3, std::nullopt, 4, 5, 6, std::nullopt},
{1, 2, -2, 1},
{3, 8, std::nullopt},
{1, 1, -2, -2, -2, 4, 8},
});
auto array2 = makeNullableArrayVector<T>({
{1, -2, 4},
{1, -2, 4},
{1, -2, 4},
{1, -2, 4},
});
auto expected = makeNullableArrayVector<T>({
{3, std::nullopt, 5, 6},
{2},
{3, 8, std::nullopt},
{8},
});
testExpr(expected, "array_except(C0, C1)", {array1, array2});
expected = makeNullableArrayVector<T>({
{},
{4},
{1, -2, 4},
{},
});
testExpr(expected, "array_except(C1, C0)", {array1, array2});
// Change C1.
array2 = makeNullableArrayVector<T>({
{10, -24, 43},
{std::nullopt, -2, 2},
{std::nullopt, std::nullopt, std::nullopt},
{8, 1, 8, 1},
});
expected = makeNullableArrayVector<T>({
{1, -2, 3, std::nullopt, 4, 5, 6},
{1},
{3, 8},
{-2, 4},
});
testExpr(expected, "array_except(C0, C1)", {array1, array2});
}
template <typename T>
void testFloatingPoint() {
auto array1 = makeNullableArrayVector<T>({
{1.0001, -2.0, 3.03, std::nullopt, 4.00004},
{std::numeric_limits<T>::min(), 2.02, -2.001, 1},
{std::numeric_limits<T>::max(), 8.0001, std::nullopt},
{9.0009,
std::numeric_limits<T>::infinity(),
std::numeric_limits<T>::max()},
{std::numeric_limits<T>::quiet_NaN(), 9.0009},
});
auto array2 = makeNullableArrayVector<T>({
{1.0, -2.0, 4.0},
{std::numeric_limits<T>::min(), 2.0199, -2.001, 1.000001},
{1.0001, -2.02, std::numeric_limits<T>::max(), 8.00099},
{9.0009, std::numeric_limits<T>::infinity()},
{9.0009, std::numeric_limits<T>::quiet_NaN()},
});
auto expected = makeNullableArrayVector<T>({
{1.0001, 3.03, std::nullopt, 4.00004},
{2.02, 1},
{8.0001, std::nullopt},
{std::numeric_limits<T>::max()},
{std::numeric_limits<T>::quiet_NaN()},
});
testExpr(expected, "array_except(C0, C1)", {array1, array2});
expected = makeNullableArrayVector<T>({
{1.0, 4.0},
{2.0199, 1.000001},
{1.0001, -2.02, 8.00099},
{},
{std::numeric_limits<T>::quiet_NaN()},
});
testExpr(expected, "array_except(C1, C0)", {array1, array2});
}
};
} // namespace
TEST_F(ArrayExceptTest, intArrays) {
testInt<int8_t>();
testInt<int16_t>();
testInt<int32_t>();
testInt<int64_t>();
}
TEST_F(ArrayExceptTest, floatArrays) {
testFloatingPoint<float>();
testFloatingPoint<double>();
}
TEST_F(ArrayExceptTest, boolArrays) {
auto array1 = makeNullableArrayVector<bool>(
{{true, false},
{true, true},
{false, false},
{},
{true, false, true, std::nullopt},
{std::nullopt, true, false, true},
{false, true, false},
{true, false, true}});
auto array2 = makeNullableArrayVector<bool>(
{{true},
{true, true},
{false, false},
{},
{true, std::nullopt},
{std::nullopt, false},
{false, true, false},
{true, false, true}});
auto expected = makeNullableArrayVector<bool>(
{{false}, {}, {}, {}, {false}, {true}, {}, {}});
testExpr(expected, "array_except(C0, C1)", {array1, array2});
expected = makeNullableArrayVector<bool>({{}, {}, {}, {}, {}, {}, {}, {}});
testExpr(expected, "array_except(C1, C0)", {array1, array2});
}
// Test inline strings.
TEST_F(ArrayExceptTest, strArrays) {
using S = StringView;
auto array1 = makeNullableArrayVector<StringView>({
{S("a"), std::nullopt, S("b")},
{S("a"), S("b"), S("a"), S("a")},
{std::nullopt, S("b"), std::nullopt},
{S("abc")},
});
auto array2 = makeNullableArrayVector<StringView>({
{S("a")},
{S("a"), S("b"), S("b")},
{std::nullopt, std::nullopt, std::nullopt},
{S("abc"), S("a"), S("b")},
});
auto expected = makeNullableArrayVector<StringView>({
{std::nullopt, S("b")},
{},
{S("b")},
{},
});
testExpr(expected, "array_except(C0, C1)", {array1, array2});
expected = makeNullableArrayVector<StringView>({
{},
{},
{},
{S("a"), S("b")},
});
testExpr(expected, "array_except(C1, C0)", {array1, array2});
}
// Test non-inline (> 12 length) strings.
TEST_F(ArrayExceptTest, longStrArrays) {
using S = StringView;
auto array1 = makeNullableArrayVector<StringView>({
{S("red shiny car ahead"), S("blue clear sky above")},
{std::nullopt,
S("blue clear sky above"),
S("yellow rose flowers"),
S("orange beautiful sunset")},
{},
{S("red shiny car ahead"),
S("purple is an elegant color"),
S("green plants make us happy")},
});
auto array2 = makeNullableArrayVector<StringView>({
{S("red shiny car ahead")},
{std::nullopt},
{},
{S("red shiny car ahead"), S("green plants make us happy")},
});
auto expected = makeNullableArrayVector<StringView>({
{S("blue clear sky above")},
{S("blue clear sky above"),
S("yellow rose flowers"),
S("orange beautiful sunset")},
{},
{S("purple is an elegant color")},
});
testExpr(expected, "array_except(C0, C1)", {array1, array2});
expected = makeNullableArrayVector<StringView>({
{},
{},
{},
{},
});
testExpr(expected, "array_except(C1, C0)", {array1, array2});
}
// When one of the arrays is constant.
TEST_F(ArrayExceptTest, constant) {
auto array1 = makeNullableArrayVector<int32_t>({
{1, -2, 3, std::nullopt, 4, 5, 6, std::nullopt},
{1, 2, -2, 1},
{3, 8, std::nullopt},
{1, 1, -2, -2, -2, 4, 8},
});
auto expected = makeNullableArrayVector<int32_t>({
{3, std::nullopt, 5, 6},
{2},
{3, 8, std::nullopt},
{8},
});
testExpr(expected, "array_except(C0, ARRAY[1,-2,4])", {array1});
expected = makeNullableArrayVector<int32_t>({
{},
{4},
{1, -2, 4},
{},
});
testExpr(expected, "array_except(ARRAY[1,-2,4], C0)", {array1});
testExpr(expected, "array_except(ARRAY[1,1,-2,1,-2,4,1,4,4], C0)", {array1});
// Array containing NULLs.
expected = makeNullableArrayVector<int32_t>({
{-2, 3, 5, 6},
{2, -2},
{3, 8},
{-2, 8},
});
testExpr(expected, "array_except(C0, ARRAY[1,NULL,4])", {array1});
expected = makeNullableArrayVector<int32_t>({
{},
{std::nullopt, 4},
{1, 4},
{std::nullopt},
});
testExpr(expected, "array_except(ARRAY[1,NULL,4], C0)", {array1});
}
TEST_F(ArrayExceptTest, wrongTypes) {
auto expected = makeNullableArrayVector<int32_t>({{}});
auto array1 = makeNullableArrayVector<int32_t>({{1}});
EXPECT_THROW(
testExpr(expected, "array_except(1, 1)", {array1}),
std::invalid_argument);
EXPECT_THROW(
testExpr(expected, "array_except(C0, 1)", {array1}),
std::invalid_argument);
EXPECT_THROW(
testExpr(expected, "array_except(ARRAY[1], 1)", {array1}),
std::invalid_argument);
EXPECT_THROW(
testExpr(expected, "array_exvcept(C0)", {array1}), std::invalid_argument);
EXPECT_THROW(
testExpr(expected, "array_except(C0, C0, C0)", {array1}),
std::invalid_argument);
EXPECT_NO_THROW(testExpr(expected, "array_except(C0, C0)", {array1}));
}
|
; A152298: a(n) = (3^n-1)/2 if n odd, (3^n-1)/8 if n even.
; 0,1,1,13,10,121,91,1093,820,9841,7381,88573,66430,797161,597871,7174453,5380840,64570081,48427561,581130733,435848050,5230176601,3922632451,47071589413,35303692060,423644304721,317733228541,3812798742493,2859599056870,34315188682441,25736391511831,308836698141973,231627523606480,2779530283277761,2084647712458321
mov $1,2
mov $2,$0
mov $3,$0
sub $3,1
lpb $2
lpb $3
sub $3,$1
lpe
sub $1,$3
mul $1,3
sub $2,1
lpe
mul $1,4
div $1,16
|
; ===============================================================
; Sep 2005, improved Apr 2014
; ===============================================================
;
; int in_inkey(void)
;
; Read instantaneous state of the keyboard and return ascii code
; if only one key is pressed.
;
; ===============================================================
SECTION code_input
PUBLIC asm_in_inkey
EXTERN in_key_translation_table, error_znc, error_zc
asm_in_inkey:
; exit : if one key is pressed
;
; hl = ascii code
; carry reset
;
; if no keys are pressed
;
; hl = 0
; carry reset
;
; if more than one key is pressed
;
; hl = 0
; carry set
;
; uses : af, bc, de, hl
; locate a key row with key active
ld bc,$fefe ; key port, first row selected
ld de,$0500 ; e = offset into key translation table
ld hl,$ffe0 ; constant used in loop
; first row contains CAPS shift
in a,(c)
or $e1 ; ignore CAPS shift
cp h
jr nz, keyhit_0 ; if key is pressed in this row
ld e,d
ld b,$fd
row_loop:
in a,(c)
or l
cp h
jr nz, keyhit_0 ; if key is pressed in this row
ld a,e
add a,d
ld e,a ; increase index into key translation table
rlc b
jp m, row_loop ; if key row is not the last one
; last row contains SYM shift
in a,(c)
or $e2 ; ignore SYM shift
cp h
ld c,a
jr nz, keyhit_1 ; if key is pressed in this row
jp error_znc ; if no keys pressed
keyhit_0:
; at least one key row is active
; make sure no others are active
ld c,a
; c = key result
; b = key row containing keypress
; e = index into key translation table for row
; hl = $ffe0
; d = 5
ld a,b
cpl
or $81
in a,($fe) ; look at all other rows except CAPS/SYM rows
or l
cp h
jp nz, error_zc ; if more than one key pressed
ld a,$7f
in a,($fe) ; read SYM shift row
or $e2 ; ignore sym shift
cp h
jp nz, error_zc ; if key in sym shift row pressed
keyhit_1:
; only one key row is active
; determine ascii code from translation table
; c = key result
; e = index into key translation table for row
; d = 5
ld b,0
ld hl,rowtable - $e0
add hl,bc
ld a,(hl)
cp d
jp nc, error_zc ; if more than one key is pressed in row
add a,e
ld e,a ; e = index into key translation table for key
ld hl,in_key_translation_table
ld d,b
add hl,de
; check for shift modifiers
check_caps:
ld a,$fe
in a,($fe)
and $01
jr nz, check_sym
ld e,40
add hl,de
check_sym:
ld a,$7f
in a,($fe)
and $02
jr nz, ascii
ld e,80
add hl,de
ascii:
ld l,(hl)
ld h,b
ret
rowtable:
defb 255,255,255,255,255,255,255
defb 255,255,255,255,255,255,255,255
defb 4,255,255,255,255,255,255
defb 255,3,255,255,255,2,255,1
defb 0,255
|
#include "entities/Node.hpp"
#include "entities/Way.hpp"
#include "entities/Area.hpp"
#include "entities/Relation.hpp"
#include "formats/osm/BuildingProcessor.hpp"
#include "formats/osm/MultipolygonProcessor.hpp"
#include "formats/osm/RelationProcessor.hpp"
#include "formats/osm/OsmDataVisitor.hpp"
#include "utils/GeometryUtils.hpp"
#include <unordered_set>
using namespace utymap;
using namespace utymap::formats;
using namespace utymap::entities;
using namespace utymap::index;
void OsmDataVisitor::visitBounds(BoundingBox bbox) {
bbox_ = bbox;
}
void OsmDataVisitor::visitNode(std::uint64_t id, GeoCoordinate &coordinate, utymap::formats::Tags &tags) {
auto node = std::make_shared<Node>();
node->id = id;
node->coordinate = coordinate;
utymap::utils::setTags(stringTable_, *node, tags);
context_.nodeMap[id] = node;
}
void OsmDataVisitor::visitWay(std::uint64_t id, std::vector<std::uint64_t> &nodeIds, utymap::formats::Tags &tags) {
std::vector<GeoCoordinate> coordinates;
coordinates.reserve(nodeIds.size());
for (auto nodeId : nodeIds) {
coordinates.push_back(context_.nodeMap[nodeId]->coordinate);
}
auto size = coordinates.size();
if (size > 3 && coordinates[0]==coordinates[size - 1]) {
coordinates.pop_back();
auto area = std::make_shared<Area>();
area->id = id;
if (utymap::utils::isClockwise(coordinates)) {
std::reverse(coordinates.begin(), coordinates.end());
}
area->coordinates = std::move(coordinates);
utymap::utils::setTags(stringTable_, *area, tags);
context_.areaMap[id] = area;
} else {
auto way = std::make_shared<Way>();
way->id = id;
way->coordinates = std::move(coordinates);
utymap::utils::setTags(stringTable_, *way, tags);
context_.wayMap[id] = way;
}
}
void OsmDataVisitor::visitRelation(std::uint64_t id, RelationMembers &members, utymap::formats::Tags &tags) {
auto relation = std::make_shared<Relation>();
relation->id = id;
relation->tags = utymap::utils::convertTags(stringTable_, tags);
// NOTE Assume, relation may refer to another relations which are not yet processed.
// So, store all relation members to resolve them once all relations are visited.
relationMembers_[id] = members;
context_.relationMap[id] = relation;
}
void OsmDataVisitor::add(utymap::entities::Element &element) {
if (cancelToken_.isCancelled()) return;
add_(element);
}
bool OsmDataVisitor::hasTag(const std::string &key,
const std::string &value,
const std::vector<utymap::entities::Tag> &tags) const {
return utymap::utils::hasTag(stringTable_.getId(key), stringTable_.getId(value), tags);
}
void OsmDataVisitor::resolve(Relation &relation) {
if (cancelToken_.isCancelled()) return;
auto membersPair = relationMembers_.find(relation.id);
// already resolved
if (relation.elements.size()==membersPair->second.size())
return;
auto resolveFunc = std::bind(&OsmDataVisitor::resolve, this, std::placeholders::_1);
if (hasTag("type", "multipolygon", relation.tags))
MultipolygonProcessor(relation, membersPair->second, context_, resolveFunc).process();
else if (hasTag("type", "building", relation.tags))
BuildingProcessor(relation, membersPair->second, context_, resolveFunc).process();
else {
RelationProcessor(relation, membersPair->second, context_, relationMembers_, resolveFunc).process();
}
}
utymap::BoundingBox OsmDataVisitor::complete() {
// TODO return actual bounding box.
if (cancelToken_.isCancelled()) return utymap::BoundingBox();
// All relations are visited can start to resolve them
for (auto &membersPair : relationMembers_) {
auto relationPair = context_.relationMap.find(membersPair.first);
if (relationPair!=context_.relationMap.end())
resolve(*relationPair->second);
}
for (const auto &pair : context_.relationMap) {
add(*pair.second);
}
for (const auto &pair : context_.nodeMap) {
add(*pair.second);
}
for (const auto &pair : context_.wayMap) {
add(*pair.second);
}
for (const auto &pair : context_.areaMap) {
add(*pair.second);
}
return bbox_;
}
OsmDataVisitor::OsmDataVisitor(const StringTable &stringTable,
std::function<bool(Element &)> add,
const utymap::CancellationToken &cancelToken) :
stringTable_(stringTable), add_(add), cancelToken_(cancelToken), context_(), bbox_() {
}
|
// Copyright 2016 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 "remoting/base/telemetry_log_writer.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/containers/circular_deque.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/run_loop.h"
#include "base/test/task_environment.h"
#include "net/http/http_status_code.h"
#include "remoting/base/chromoting_event.h"
#include "remoting/base/fake_oauth_token_getter.h"
#include "remoting/base/url_request.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace remoting {
namespace {
constexpr char kFakeAccessToken[] = "access_token";
constexpr char kAuthorizationHeaderPrefix[] = "Authorization:Bearer ";
class FakeUrlRequest : public UrlRequest {
public:
FakeUrlRequest(const std::string& expected_post,
const UrlRequest::Result& returned_result)
: expected_post_(expected_post), returned_result_(returned_result) {}
void Respond() {
on_result_callback_.Run(returned_result_);
// Responding to current request will trigger sending pending events. Call
// RunUntilIdle() to allow the new request to be created. See LogFakeEvent()
// below.
base::RunLoop().RunUntilIdle();
}
// UrlRequest overrides.
void SetPostData(const std::string& content_type,
const std::string& post_data) override {
EXPECT_EQ(content_type, "application/json");
EXPECT_EQ(post_data, expected_post_);
}
void AddHeader(const std::string& value) override {
if (value.find(kAuthorizationHeaderPrefix) == 0) {
EXPECT_EQ(std::string(kAuthorizationHeaderPrefix) + kFakeAccessToken,
value);
}
}
void Start(const OnResultCallback& on_result_callback) override {
on_result_callback_ = on_result_callback;
}
private:
std::string expected_post_;
UrlRequest::Result returned_result_;
OnResultCallback on_result_callback_;
DISALLOW_COPY_AND_ASSIGN(FakeUrlRequest);
};
class FakeUrlRequestFactory : public UrlRequestFactory {
public:
~FakeUrlRequestFactory() override { EXPECT_TRUE(expected_requests_.empty()); }
// Returns a respond closure. Run this closure to respond to the URL request.
base::OnceClosure AddExpectedRequest(const std::string& exp_post,
const UrlRequest::Result& ret_result) {
FakeUrlRequest* fakeRequest = new FakeUrlRequest(exp_post, ret_result);
base::OnceClosure closure =
base::BindOnce(&FakeUrlRequest::Respond, base::Unretained(fakeRequest));
expected_requests_.push_back(std::unique_ptr<UrlRequest>(fakeRequest));
return closure;
}
// request_factory_ override.
std::unique_ptr<UrlRequest> CreateUrlRequest(
UrlRequest::Type type,
const std::string& url,
const net::NetworkTrafficAnnotationTag& traffic_annotation) override {
EXPECT_FALSE(expected_requests_.empty());
if (expected_requests_.empty()) {
return std::unique_ptr<UrlRequest>(nullptr);
}
EXPECT_EQ(type, UrlRequest::Type::POST);
std::unique_ptr<UrlRequest> request(std::move(expected_requests_.front()));
expected_requests_.pop_front();
return request;
}
private:
base::circular_deque<std::unique_ptr<UrlRequest>> expected_requests_;
};
} // namespace
class TelemetryLogWriterTest : public testing::Test {
public:
TelemetryLogWriterTest()
: log_writer_(
"",
std::make_unique<FakeOAuthTokenGetter>(OAuthTokenGetter::SUCCESS,
"email",
kFakeAccessToken)) {
auto request_factory = std::make_unique<FakeUrlRequestFactory>();
request_factory_ = request_factory.get();
log_writer_.Init(std::move(request_factory));
success_result_.success = true;
success_result_.status = 200;
success_result_.response_body = "{}";
unauth_result_.success = false;
unauth_result_.status = net::HTTP_UNAUTHORIZED;
unauth_result_.response_body = "{}";
}
protected:
void LogFakeEvent() {
ChromotingEvent entry;
entry.SetInteger("id", id_);
id_++;
log_writer_.Log(entry);
// It's an async process to create request to send all pending events.
base::RunLoop().RunUntilIdle();
}
UrlRequest::Result success_result_;
UrlRequest::Result unauth_result_;
FakeUrlRequestFactory* request_factory_; // No ownership.
TelemetryLogWriter log_writer_;
private:
int id_ = 0;
base::test::SingleThreadTaskEnvironment task_environment_;
};
// Test workflow: add request -> log event -> respond request.
// Test fails if req is incorrect or creates more/less reqs than expected
TEST_F(TelemetryLogWriterTest, PostOneLogImmediately) {
auto respond = request_factory_->AddExpectedRequest(
"{\"event\":[{\"id\":0}]}", success_result_);
LogFakeEvent();
std::move(respond).Run();
}
TEST_F(TelemetryLogWriterTest, PostOneLogAndHaveTwoPendingLogs) {
auto respond1 = request_factory_->AddExpectedRequest(
"{\"event\":[{\"id\":0}]}", success_result_);
LogFakeEvent();
auto respond2 = request_factory_->AddExpectedRequest(
"{\"event\":[{\"id\":1},{\"id\":2}]}", success_result_);
LogFakeEvent();
LogFakeEvent();
std::move(respond1).Run();
std::move(respond2).Run();
}
TEST_F(TelemetryLogWriterTest, PostLogFailedAndRetry) {
// kMaxTries = 5
auto respond1 = request_factory_->AddExpectedRequest(
"{\"event\":[{\"id\":0}]}", UrlRequest::Result::Failed());
auto respond2 = request_factory_->AddExpectedRequest(
"{\"event\":[{\"id\":0}]}", UrlRequest::Result::Failed());
auto respond3 = request_factory_->AddExpectedRequest(
"{\"event\":[{\"id\":0}]}", UrlRequest::Result::Failed());
auto respond4 = request_factory_->AddExpectedRequest(
"{\"event\":[{\"id\":0}]}", UrlRequest::Result::Failed());
auto respond5 = request_factory_->AddExpectedRequest(
"{\"event\":[{\"id\":0}]}", UrlRequest::Result::Failed());
LogFakeEvent();
std::move(respond1).Run();
std::move(respond2).Run();
std::move(respond3).Run();
std::move(respond4).Run();
std::move(respond5).Run();
}
TEST_F(TelemetryLogWriterTest, PostOneLogFailedResendWithTwoPendingLogs) {
auto respond1 = request_factory_->AddExpectedRequest(
"{\"event\":[{\"id\":0}]}", UrlRequest::Result::Failed());
LogFakeEvent();
auto respond2 = request_factory_->AddExpectedRequest(
"{\"event\":[{\"id\":0},{\"id\":1},{\"id\":2}]}", success_result_);
LogFakeEvent();
LogFakeEvent();
std::move(respond1).Run();
std::move(respond2).Run();
}
TEST_F(TelemetryLogWriterTest, PostThreeLogsFailedAndResendWithOnePending) {
// This tests the ordering of the resent log.
auto respond1 = request_factory_->AddExpectedRequest(
"{\"event\":[{\"id\":0}]}", UrlRequest::Result::Failed());
LogFakeEvent();
auto respond2 = request_factory_->AddExpectedRequest(
"{\"event\":[{\"id\":0},{\"id\":1},{\"id\":2}]}",
UrlRequest::Result::Failed());
LogFakeEvent();
LogFakeEvent();
std::move(respond1).Run();
auto respond3 = request_factory_->AddExpectedRequest(
"{\"event\":[{\"id\":0},{\"id\":1},{\"id\":2},{\"id\":3}]}",
success_result_);
LogFakeEvent();
std::move(respond2).Run();
std::move(respond3).Run();
}
TEST_F(TelemetryLogWriterTest, PostOneUnauthorizedCallClosureAndRetry) {
auto respond1 = request_factory_->AddExpectedRequest(
"{\"event\":[{\"id\":0}]}", unauth_result_);
LogFakeEvent();
auto respond2 = request_factory_->AddExpectedRequest(
"{\"event\":[{\"id\":0}]}", success_result_);
std::move(respond1).Run();
std::move(respond2).Run();
}
} // namespace remoting
|
.global s_prepare_buffers
s_prepare_buffers:
push %r12
push %r13
push %r8
push %r9
push %rbp
push %rcx
push %rdi
push %rsi
lea addresses_normal_ht+0x3098, %r8
nop
dec %r13
movw $0x6162, (%r8)
nop
nop
nop
nop
nop
cmp $18788, %rbp
lea addresses_A_ht+0x1d758, %r13
nop
add %r12, %r12
mov $0x6162636465666768, %r9
movq %r9, (%r13)
nop
nop
nop
nop
nop
add $57353, %r9
lea addresses_WC_ht+0xbcd8, %rsi
lea addresses_A_ht+0x132d8, %rdi
nop
nop
nop
nop
xor %r8, %r8
mov $51, %rcx
rep movsq
nop
nop
nop
sub $53773, %r12
lea addresses_UC_ht+0x9e0, %rbp
clflush (%rbp)
nop
nop
lfence
movb (%rbp), %r9b
nop
nop
nop
nop
nop
add %r8, %r8
lea addresses_UC_ht+0x126f2, %rbp
nop
nop
and $21070, %rcx
mov $0x6162636465666768, %rdi
movq %rdi, (%rbp)
nop
sub %r9, %r9
lea addresses_WC_ht+0x135d8, %r8
dec %rdi
mov (%r8), %bp
nop
sub %rdi, %rdi
lea addresses_A_ht+0x18d8, %rsi
lea addresses_D_ht+0x174d8, %rdi
nop
nop
nop
nop
xor $30200, %rbp
mov $12, %rcx
rep movsb
nop
nop
nop
nop
add %rdi, %rdi
lea addresses_WC_ht+0x67d8, %r9
nop
nop
nop
nop
nop
cmp %rdi, %rdi
mov (%r9), %r8
nop
nop
xor $30977, %r9
lea addresses_normal_ht+0x6c5b, %rsi
lea addresses_UC_ht+0xc198, %rdi
sub $3151, %r12
mov $41, %rcx
rep movsl
nop
nop
xor $54777, %rcx
lea addresses_UC_ht+0xb4d8, %rsi
nop
nop
nop
nop
and %r13, %r13
movl $0x61626364, (%rsi)
xor $24363, %r13
pop %rsi
pop %rdi
pop %rcx
pop %rbp
pop %r9
pop %r8
pop %r13
pop %r12
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r8
push %rbx
push %rdx
push %rsi
// Faulty Load
lea addresses_PSE+0x24d8, %rbx
nop
and $61766, %rdx
mov (%rbx), %r11d
lea oracles, %rsi
and $0xff, %r11
shlq $12, %r11
mov (%rsi,%r11,1), %r11
pop %rsi
pop %rdx
pop %rbx
pop %r8
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_PSE', 'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 0}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'same': True, 'type': 'addresses_PSE', 'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 0}}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_normal_ht', 'NT': True, 'AVXalign': False, 'size': 2, 'congruent': 5}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_A_ht', 'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 7}}
{'OP': 'REPM', 'src': {'same': False, 'congruent': 11, 'type': 'addresses_WC_ht'}, 'dst': {'same': False, 'congruent': 6, 'type': 'addresses_A_ht'}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_UC_ht', 'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 3}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_UC_ht', 'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 0}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_WC_ht', 'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 8}}
{'OP': 'REPM', 'src': {'same': False, 'congruent': 6, 'type': 'addresses_A_ht'}, 'dst': {'same': True, 'congruent': 9, 'type': 'addresses_D_ht'}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_WC_ht', 'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 5}}
{'OP': 'REPM', 'src': {'same': False, 'congruent': 0, 'type': 'addresses_normal_ht'}, 'dst': {'same': False, 'congruent': 6, 'type': 'addresses_UC_ht'}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_UC_ht', 'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 9}}
{'33': 21829}
33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33
*/
|
; A013720: a(n) = 15^(2*n + 1).
; 15,3375,759375,170859375,38443359375,8649755859375,1946195068359375,437893890380859375,98526125335693359375,22168378200531005859375,4987885095119476318359375,1122274146401882171630859375,252511682940423488616943359375,56815128661595284938812255859375,12783403948858939111232757568359375,2876265888493261300027370452880859375,647159824910983792506158351898193359375,145610960604971353313885629177093505859375,32762466136118554495624266564846038818359375,7371554880626674761515459977090358734130859375
mov $1,225
pow $1,$0
mul $1,15
mov $0,$1
|
; A234045: Period 7: repeat [0, 0, 1, -1, -1, 1, 0].
; 0,0,1,-1,-1,1,0,0,0,1,-1,-1,1,0,0,0,1,-1,-1,1,0,0,0,1,-1,-1,1,0,0,0,1,-1,-1,1,0,0,0,1,-1,-1,1,0,0,0,1,-1,-1,1,0,0,0,1,-1,-1,1,0,0,0,1,-1,-1,1,0,0,0,1,-1,-1,1,0,0,0,1,-1,-1,1,0,0,0,1,-1,-1,1,0,0,0,1,-1,-1,1,0
pow $0,2
add $0,3
mul $0,38
sub $0,1
mul $0,2
mod $0,14
sub $0,6
div $0,6
|
; A142698: Primes congruent to 53 mod 57.
; Submitted by Jon Maiga
; 53,167,281,509,1193,1307,1877,2333,2447,2789,2903,3359,3701,3929,4157,4271,5297,5639,5867,5981,6323,6551,6779,7121,7349,7577,7691,7919,8147,8831,9059,9173,9629,9743,9857,10313,10427,10883,11681,11909,12251,12479,12821,13049,13163,13619,14303,14759,15101,15329,15443,15671,16127,16811,17609,17837,18521,18749,19319,19433,19661,19889,20117,20231,21143,21599,21713,22283,22397,22511,22739,22853,23081,23537,23879,23993,24107,24677,25247,25589,25703,25931,26387,26501,26729,27299,27527,27983,28097,28211
mov $1,26
mov $2,$0
add $2,2
pow $2,2
lpb $2
sub $2,1
mov $3,$1
mul $3,2
seq $3,10051 ; Characteristic function of primes: 1 if n is prime, else 0.
sub $0,$3
add $1,57
mov $4,$0
max $4,0
cmp $4,$0
mul $2,$4
lpe
mov $0,$1
mul $0,2
sub $0,113
|
//
// kern_weg.cpp
// WhateverGreen
//
// Copyright © 2018 vit9696. All rights reserved.
//
#include <Headers/kern_api.hpp>
#include <Headers/kern_devinfo.hpp>
#include <Headers/kern_iokit.hpp>
#include <Headers/kern_cpu.hpp>
#include "kern_weg.hpp"
#include <IOKit/graphics/IOFramebuffer.h>
// This is a hack to let us access protected properties.
struct FramebufferViewer : public IOFramebuffer {
static IOMemoryMap *&getVramMap(IOFramebuffer *fb) {
return static_cast<FramebufferViewer *>(fb)->fVramMap;
}
};
static const char *pathIOGraphics[] { "/System/Library/Extensions/IOGraphicsFamily.kext/IOGraphicsFamily" };
static const char *pathAGDPolicy[] { "/System/Library/Extensions/AppleGraphicsControl.kext/Contents/PlugIns/AppleGraphicsDevicePolicy.kext/Contents/MacOS/AppleGraphicsDevicePolicy" };
static const char *pathBacklight[] { "/System/Library/Extensions/AppleBacklight.kext/Contents/MacOS/AppleBacklight" };
static KernelPatcher::KextInfo kextIOGraphics { "com.apple.iokit.IOGraphicsFamily", pathIOGraphics, arrsize(pathIOGraphics), {true}, {}, KernelPatcher::KextInfo::Unloaded };
static KernelPatcher::KextInfo kextAGDPolicy { "com.apple.driver.AppleGraphicsDevicePolicy", pathAGDPolicy, arrsize(pathAGDPolicy), {true}, {}, KernelPatcher::KextInfo::Unloaded };
// Note: initially marked as reloadable, but I doubt it needs to be.
static KernelPatcher::KextInfo kextBacklight { "com.apple.driver.AppleBacklight", pathBacklight, arrsize(pathBacklight), {true}, {}, KernelPatcher::KextInfo::Unloaded };
WEG::ApplePanelData WEG::appleBacklightData[] {
{
"F14Txxxx",
{
0x00, 0x11, 0x00, 0x00, 0x00, 0x34, 0x00, 0x52, 0x00, 0x73, 0x00, 0x94, 0x00, 0xBE, 0x00, 0xFA,
0x01, 0x36, 0x01, 0x72, 0x01, 0xC5, 0x02, 0x2F, 0x02, 0xB9, 0x03, 0x60, 0x04, 0x1A, 0x05, 0x0A,
0x06, 0x0E, 0x07, 0x10
}
},
{
"F15Txxxx",
{
0x00, 0x11, 0x00, 0x00, 0x00, 0x36, 0x00, 0x54, 0x00, 0x7D, 0x00, 0xB2, 0x00, 0xF5, 0x01, 0x49,
0x01, 0xB1, 0x02, 0x2B, 0x02, 0xB8, 0x03, 0x59, 0x04, 0x13, 0x04, 0xEC, 0x05, 0xF3, 0x07, 0x34,
0x08, 0xAF, 0x0A, 0xD9
}
},
{
"F16Txxxx",
{
0x00, 0x11, 0x00, 0x00, 0x00, 0x18, 0x00, 0x27, 0x00, 0x3A, 0x00, 0x52, 0x00, 0x71, 0x00, 0x96,
0x00, 0xC4, 0x00, 0xFC, 0x01, 0x40, 0x01, 0x93, 0x01, 0xF6, 0x02, 0x6E, 0x02, 0xFE, 0x03, 0xAA,
0x04, 0x78, 0x05, 0x6C
}
},
{
"F17Txxxx",
{
0x00, 0x11, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x34, 0x00, 0x4F, 0x00, 0x71, 0x00, 0x9B, 0x00, 0xCF,
0x01, 0x0E, 0x01, 0x5D, 0x01, 0xBB, 0x02, 0x2F, 0x02, 0xB9, 0x03, 0x60, 0x04, 0x29, 0x05, 0x1E,
0x06, 0x44, 0x07, 0xA1
}
},
{
"F18Txxxx",
{
0x00, 0x11, 0x00, 0x00, 0x00, 0x53, 0x00, 0x8C, 0x00, 0xD5, 0x01, 0x31, 0x01, 0xA2, 0x02, 0x2E,
0x02, 0xD8, 0x03, 0xAE, 0x04, 0xAC, 0x05, 0xE5, 0x07, 0x59, 0x09, 0x1C, 0x0B, 0x3B, 0x0D, 0xD0,
0x10, 0xEA, 0x14, 0x99
}
},
{
"F19Txxxx",
{
0x00, 0x11, 0x00, 0x00, 0x02, 0x8F, 0x03, 0x53, 0x04, 0x5A, 0x05, 0xA1, 0x07, 0xAE, 0x0A, 0x3D,
0x0E, 0x14, 0x13, 0x74, 0x1A, 0x5E, 0x24, 0x18, 0x31, 0xA9, 0x44, 0x59, 0x5E, 0x76, 0x83, 0x11,
0xB6, 0xC7, 0xFF, 0x7B
}
},
{
"F24Txxxx",
{
0x00, 0x11, 0x00, 0x01, 0x00, 0x34, 0x00, 0x52, 0x00, 0x73, 0x00, 0x94, 0x00, 0xBE, 0x00, 0xFA,
0x01, 0x36, 0x01, 0x72, 0x01, 0xC5, 0x02, 0x2F, 0x02, 0xB9, 0x03, 0x60, 0x04, 0x1A, 0x05, 0x0A,
0x06, 0x0E, 0x07, 0x10
}
}
};
WEG *WEG::callbackWEG;
void WEG::init() {
callbackWEG = this;
// Background init fix is only necessary on 10.10 and newer.
// Former boot-arg name is igfxrst.
if (getKernelVersion() >= KernelVersion::Yosemite) {
PE_parse_boot_argn("gfxrst", &resetFramebuffer, sizeof(resetFramebuffer));
if (resetFramebuffer >= FB_TOTAL) {
SYSLOG("weg", "invalid igfxrset value %d, falling back to autodetect", resetFramebuffer);
resetFramebuffer = FB_DETECT;
}
} else {
resetFramebuffer = FB_NONE;
}
// Black screen fix is needed everywhere, but the form depends on the boot-arg.
// Former boot-arg name is ngfxpatch.
char agdp[128];
if (PE_parse_boot_argn("agdpmod", agdp, sizeof(agdp)))
processGraphicsPolicyStr(agdp);
// Callback setup is only done here for compatibility.
lilu.onPatcherLoadForce([](void *user, KernelPatcher &patcher) {
static_cast<WEG *>(user)->processKernel(patcher);
}, this);
lilu.onKextLoadForce(nullptr, 0,
[](void *user, KernelPatcher &patcher, size_t index, mach_vm_address_t address, size_t size) {
static_cast<WEG *>(user)->processKext(patcher, index, address, size);
}, this);
// Perform a background fix.
if (resetFramebuffer != FB_NONE)
lilu.onKextLoadForce(&kextIOGraphics);
// Perform a black screen fix.
if (graphicsDisplayPolicyMod != AGDP_NONE_SET)
lilu.onKextLoad(&kextAGDPolicy);
// Disable backlight patches if asked specifically.
PE_parse_boot_argn("applbkl", &appleBacklightPatch, sizeof(appleBacklightPatch));
if (appleBacklightPatch != APPLBKL_OFF)
lilu.onKextLoad(&kextBacklight);
igfx.init();
ngfx.init();
rad.init();
if (getKernelVersion() >= KernelVersion::BigSur) {
unfair.init();
} else {
shiki.init();
cdf.init();
}
}
void WEG::deinit() {
igfx.deinit();
ngfx.deinit();
rad.deinit();
if (getKernelVersion() >= KernelVersion::BigSur) {
unfair.deinit();
} else {
shiki.deinit();
cdf.deinit();
}
}
void WEG::processKernel(KernelPatcher &patcher) {
// Correct GPU properties
auto devInfo = DeviceInfo::create();
if (devInfo) {
devInfo->processSwitchOff();
if (graphicsDisplayPolicyMod == AGDP_DETECT) { /* Default detect only */
auto getAgpdMod = [this](IORegistryEntry *device) {
auto prop = device->getProperty("agdpmod");
if (prop) {
DBGLOG("weg", "found agdpmod in external GPU %s", safeString(device->getName()));
const char *agdp = nullptr;
auto propStr = OSDynamicCast(OSString, prop);
auto propData = OSDynamicCast(OSData, prop);
if (propStr) {
agdp = propStr->getCStringNoCopy();
} else if (propData && propData->getLength() > 0) {
agdp = static_cast<const char *>(propData->getBytesNoCopy());
if (agdp && agdp[propData->getLength() - 1] != '\0') {
DBGLOG("weg", "agdpmod config is not null terminated");
agdp = nullptr;
}
}
if (agdp) {
processGraphicsPolicyStr(agdp);
return true;
}
}
return false;
};
size_t extNum = devInfo->videoExternal.size();
for (size_t i = 0; i < extNum; i++) {
if (getAgpdMod(devInfo->videoExternal[i].video))
break;
}
if (devInfo->videoBuiltin != nullptr && graphicsDisplayPolicyMod == AGDP_DETECT) /* Default detect only */
getAgpdMod(devInfo->videoBuiltin);
}
// Do not inject properties unless non-Apple
size_t extNum = devInfo->videoExternal.size();
if (devInfo->firmwareVendor != DeviceInfo::FirmwareVendor::Apple) {
DBGLOG("weg", "non-apple-fw proceeding with devprops %d", graphicsDisplayPolicyMod);
if (devInfo->videoBuiltin) {
processBuiltinProperties(devInfo->videoBuiltin, devInfo);
// Assume that enabled IGPU with connectors is the boot display.
if (resetFramebuffer == FB_DETECT && !devInfo->reportedFramebufferIsConnectorLess)
resetFramebuffer = FB_COPY;
}
if (appleBacklightPatch == APPLBKL_DETECT && devInfo->videoBuiltin != nullptr)
WIOKit::getOSDataValue(devInfo->videoBuiltin, "applbkl", appleBacklightPatch);
if (appleBacklightCustomName == nullptr && devInfo->videoBuiltin != nullptr) {
appleBacklightCustomName = OSDynamicCast(OSData, devInfo->videoBuiltin->getProperty("applbkl-name"));
appleBacklightCustomData = OSDynamicCast(OSData, devInfo->videoBuiltin->getProperty("applbkl-data"));
if (appleBacklightCustomName == nullptr || appleBacklightCustomData == nullptr)
appleBacklightCustomName = appleBacklightCustomData = nullptr;
}
for (size_t i = 0; i < extNum; i++) {
auto &v = devInfo->videoExternal[i];
processExternalProperties(v.video, devInfo, v.vendor);
// Assume that AMD GPU is the boot display.
if (v.vendor == WIOKit::VendorID::ATIAMD && resetFramebuffer == FB_DETECT)
resetFramebuffer = FB_ZEROFILL;
if (appleBacklightPatch == APPLBKL_DETECT)
WIOKit::getOSDataValue(v.video, "applbkl", appleBacklightPatch);
if (appleBacklightCustomName == nullptr) {
appleBacklightCustomName = OSDynamicCast(OSData, v.video->getProperty("applbkl-name"));
appleBacklightCustomData = OSDynamicCast(OSData, v.video->getProperty("applbkl-data"));
if (appleBacklightCustomName == nullptr || appleBacklightCustomData == nullptr)
appleBacklightCustomName = appleBacklightCustomData = nullptr;
}
}
// Note, disabled Optimus will make videoExternal 0, so this case checks for active IGPU only.
DBGLOG("weg", "resulting applbkl value is %d", appleBacklightPatch);
if (appleBacklightPatch == APPLBKL_OFF || (appleBacklightPatch == APPLBKL_DETECT && (devInfo->videoBuiltin == nullptr || extNum > 0))) {
// Either a builtin IGPU is not available, or some external GPU is available.
kextBacklight.switchOff();
}
if ((graphicsDisplayPolicyMod & AGDP_DETECT) && isGraphicsPolicyModRequired(devInfo))
graphicsDisplayPolicyMod = AGDP_VIT9696 | AGDP_PIKERA | AGDP_SET;
if (devInfo->managementEngine)
processManagementEngineProperties(devInfo->managementEngine);
} else {
if (appleBacklightPatch != APPLBKL_ON) {
// Do not patch AppleBacklight on Apple HW, unless forced.
kextBacklight.switchOff();
}
// Support legacy -wegtree argument.
bool rebuidTree = checkKernelArgument("-wegtree");
// Support device properties.
if (!rebuidTree && devInfo->videoBuiltin)
rebuidTree = devInfo->videoBuiltin->getProperty("rebuild-device-tree") != nullptr;
for (size_t i = 0; !rebuidTree && i < extNum; i++)
rebuidTree = devInfo->videoExternal[i].video->getProperty("rebuild-device-tree") != nullptr;
// Override with modern wegtree argument.
int tree;
if (PE_parse_boot_argn("wegtree", &tree, sizeof(tree)))
rebuidTree = tree != 0;
if (rebuidTree) {
DBGLOG("weg", "apple-fw proceeding with devprops by request");
if (devInfo->videoBuiltin)
processBuiltinProperties(devInfo->videoBuiltin, devInfo);
for (size_t i = 0; i < extNum; i++) {
auto &v = devInfo->videoExternal[i];
processExternalProperties(v.video, devInfo, v.vendor);
}
}
if (devInfo->managementEngine)
processManagementEngineProperties(devInfo->managementEngine);
}
igfx.processKernel(patcher, devInfo);
ngfx.processKernel(patcher, devInfo);
rad.processKernel(patcher, devInfo);
if (getKernelVersion() >= KernelVersion::BigSur) {
unfair.processKernel(patcher, devInfo);
} else {
shiki.processKernel(patcher, devInfo);
cdf.processKernel(patcher, devInfo);
}
DeviceInfo::deleter(devInfo);
}
// Disable mods that did not find a way to function.
if (resetFramebuffer == FB_DETECT) {
resetFramebuffer = FB_NONE;
kextIOGraphics.switchOff();
}
if ((graphicsDisplayPolicyMod & AGDP_DETECT) || graphicsDisplayPolicyMod == AGDP_NONE_SET) {
graphicsDisplayPolicyMod = AGDP_NONE_SET;
kextAGDPolicy.switchOff();
}
// We need to load vinfo for cleanup and copy.
if (resetFramebuffer == FB_COPY || resetFramebuffer == FB_ZEROFILL) {
auto info = reinterpret_cast<vc_info *>(patcher.solveSymbol(KernelPatcher::KernelID, "_vinfo"));
if (info) {
consoleVinfo = *info;
DBGLOG("weg", "vinfo 1: %u:%u %u:%u:%u",
consoleVinfo.v_height, consoleVinfo.v_width, consoleVinfo.v_depth, consoleVinfo.v_rowbytes, consoleVinfo.v_type);
DBGLOG("weg", "vinfo 2: %s %u:%u %u:%u:%u",
consoleVinfo.v_name, consoleVinfo.v_rows, consoleVinfo.v_columns, consoleVinfo.v_rowscanbytes, consoleVinfo.v_scale, consoleVinfo.v_rotate);
gotConsoleVinfo = true;
} else {
SYSLOG("weg", "failed to obtain vcinfo");
patcher.clearError();
}
}
}
void WEG::processKext(KernelPatcher &patcher, size_t index, mach_vm_address_t address, size_t size) {
if (kextIOGraphics.loadIndex == index) {
gIOFBVerboseBootPtr = patcher.solveSymbol<uint8_t *>(index, "__ZL16gIOFBVerboseBoot", address, size);
if (gIOFBVerboseBootPtr) {
KernelPatcher::RouteRequest request("__ZN13IOFramebuffer6initFBEv", wrapFramebufferInit, orgFramebufferInit);
patcher.routeMultiple(index, &request, 1, address, size);
} else {
SYSLOG("weg", "failed to resolve gIOFBVerboseBoot");
patcher.clearError();
}
return;
}
if (kextAGDPolicy.loadIndex == index) {
processGraphicsPolicyMods(patcher, address, size);
return;
}
if (kextBacklight.loadIndex == index) {
KernelPatcher::RouteRequest request("__ZN15AppleIntelPanel10setDisplayEP9IODisplay", wrapApplePanelSetDisplay, orgApplePanelSetDisplay);
if (patcher.routeMultiple(kextBacklight.loadIndex, &request, 1, address, size)) {
const uint8_t find[] = {"F%uT%04x"};
const uint8_t replace[] = {"F%uTxxxx"};
KernelPatcher::LookupPatch patch = {&kextBacklight, find, replace, sizeof(find), 1};
DBGLOG("weg", "applying backlight patch");
patcher.applyLookupPatch(&patch);
}
}
if (igfx.processKext(patcher, index, address, size))
return;
if (ngfx.processKext(patcher, index, address, size))
return;
if (rad.processKext(patcher, index, address, size))
return;
if (getKernelVersion() < KernelVersion::BigSur && cdf.processKext(patcher, index, address, size))
return;
}
void WEG::processBuiltinProperties(IORegistryEntry *device, DeviceInfo *info) {
auto name = device->getName();
// There could be only one IGPU, and it must be named IGPU for AppleGVA to function properly.
if (!name || strcmp(name, "IGPU") != 0)
WIOKit::renameDevice(device, "IGPU");
WIOKit::awaitPublishing(device);
// Obtain the real device info, should we cast to IOPCIDevice here?
auto obj = OSDynamicCast(IOService, device);
if (obj) {
uint32_t realDevice = WIOKit::readPCIConfigValue(obj, WIOKit::kIOPCIConfigDeviceID);
uint32_t acpiDevice = 0, fakeDevice = 0;
if (!WIOKit::getOSDataValue(obj, "device-id", acpiDevice))
DBGLOG("weg", "missing IGPU device-id");
// Set the right Intel model name here.
auto model = getIntelModel(realDevice, fakeDevice);
DBGLOG("weg", "IGPU has real %04X acpi %04X fake %04X and model %s",
realDevice, acpiDevice, fakeDevice, safeString(model));
if (model && !obj->getProperty("model")) {
DBGLOG("weg", "adding missing model %s from autotodetect", model);
obj->setProperty("model", const_cast<char *>(model), static_cast<unsigned>(strlen(model)+1));
}
// User may request to fake device-id even if it is supported.
if (realDevice != acpiDevice) {
DBGLOG("weg", "user requested to fake with normal device-id");
fakeDevice = acpiDevice;
}
// Update vtable I/O functions to ensure that a correct fake device ID is read.
if (fakeDevice && obj->getProperty("no-gfx-spoof") == nullptr) {
// Incorrect device-id means Intel drivers will most likely fail to do matching, error to log.
if (fakeDevice != acpiDevice) {
uint8_t bus = 0, dev = 0, fun = 0;
WIOKit::getDeviceAddress(obj, bus, dev, fun);
SYSLOG("weg", "IGPU device (%02X:%02X.%02X) has device-id 0x%04X, you should change it to 0x%04X",
bus, dev, fun, acpiDevice, fakeDevice);
}
if (fakeDevice != realDevice) {
hasIgpuSpoof = true;
KernelPatcher::routeVirtual(obj, WIOKit::PCIConfigOffset::ConfigRead16, wrapConfigRead16, &orgConfigRead16);
KernelPatcher::routeVirtual(obj, WIOKit::PCIConfigOffset::ConfigRead32, wrapConfigRead32, &orgConfigRead32);
DBGLOG("weg", "hooked configRead read methods!");
}
}
} else {
SYSLOG("weg", "invalid IGPU device type");
}
// Update the requested framebuffer identifier.
if (info->reportedFramebufferName && BaseDeviceInfo::get().cpuGeneration >= CPUInfo::CpuGeneration::SandyBridge)
device->setProperty(info->reportedFramebufferName, &info->reportedFramebufferId, sizeof(info->reportedFramebufferId));
// Set AAPL,os-info property if not present for first generation.
// Default value pulled from AppleIntelHDGraphicsFB. Property is required for non-MacBookPro6,1 platforms due to a bug in AppleIntelHDGraphicsFB.
if (BaseDeviceInfo::get().cpuGeneration == CPUInfo::CpuGeneration::Westmere) {
if (!device->getProperty("AAPL,os-info")) {
DBGLOG("weg", "fixing AAPL,os-info");
uint8_t osInfoBytes[] {
0x30, 0x49, 0x01, 0x01, 0x01, 0x00, 0x08, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF
};
device->setProperty("AAPL,os-info", osInfoBytes, sizeof(osInfoBytes));
} else {
DBGLOG("weg", "found existing AAPL,os-info");
}
}
// Ensure built-in.
if (!device->getProperty("built-in")) {
DBGLOG("weg", "fixing built-in");
uint8_t builtBytes[] { 0x00 };
device->setProperty("built-in", builtBytes, sizeof(builtBytes));
} else {
DBGLOG("weg", "found existing built-in");
}
}
void WEG::processExternalProperties(IORegistryEntry *device, DeviceInfo *info, uint32_t vendor) {
auto name = device->getName();
// It is unclear how to properly name the GPUs, and supposedly it does not really matter.
// However, we will try to at least name them in a unique manner (GFX0, GFX1, ...)
if (device->getProperty("preserve-names") == nullptr
&& currentExternalGfxIndex <= MaxExternalGfxIndex
&& (!name || strncmp(name, "GFX", strlen("GFX")) != 0)) {
char name[16];
snprintf(name, sizeof(name), "GFX%u", currentExternalGfxIndex++);
WIOKit::renameDevice(device, name);
}
// AAPL,slot-name is used to distinguish GPU slots in Mac Pro.
// NVIDIA Web Drivers have a preference panel, where they read this value and allow up to 4 GPUs.
// Each NVIDIA GPU is then displayed on the ECC tab. We permit more slots, since 4 is an artificial restriction.
// iMac on the other side has only one GPU and is not expected to have multiple slots.
// Here we pass AAPL,slot-name if the GPU is NVIDIA or we have more than one GPU.
bool wantSlot = info->videoExternal.size() > 1 || vendor == WIOKit::VendorID::NVIDIA;
if (wantSlot && currentExternalSlotIndex <= MaxExternalSlotIndex && !device->getProperty("AAPL,slot-name")) {
char name[16];
snprintf(name, sizeof(name), "Slot-%u", currentExternalSlotIndex++);
device->setProperty("AAPL,slot-name", name, sizeof("Slot-1"));
}
// Set the autodetected AMD GPU name here, it will later be handled by RAD to not get overridden.
// This is not necessary for NVIDIA, as their drivers properly detect the name.
if (vendor == WIOKit::VendorID::ATIAMD && !device->getProperty("model")) {
uint32_t dev, rev, subven, sub;
if (WIOKit::getOSDataValue(device, "device-id", dev) &&
WIOKit::getOSDataValue(device, "revision-id", rev) &&
WIOKit::getOSDataValue(device, "subsystem-vendor-id", subven) &&
WIOKit::getOSDataValue(device, "subsystem-id", sub)) {
auto model = getRadeonModel(dev, rev, subven, sub);
if (model) {
device->setProperty("model", const_cast<char *>(model), static_cast<unsigned>(strlen(model)+1));
}
}
}
if (vendor == WIOKit::VendorID::ATIAMD && device->getProperty("no-gfx-spoof") == nullptr) {
WIOKit::awaitPublishing(device);
uint32_t realDevice = WIOKit::readPCIConfigValue(device, WIOKit::kIOPCIConfigDeviceID);
uint32_t acpiDevice = 0;
if (WIOKit::getOSDataValue(device, "device-id", acpiDevice)) {
DBGLOG("weg", "found AMD GPU with device-id 0x%04X actual 0x%04X", acpiDevice, realDevice);
if (acpiDevice != realDevice) {
hasGfxSpoof = true;
KernelPatcher::routeVirtual(device, WIOKit::PCIConfigOffset::ConfigRead16, wrapConfigRead16, &orgConfigRead16);
KernelPatcher::routeVirtual(device, WIOKit::PCIConfigOffset::ConfigRead32, wrapConfigRead32, &orgConfigRead32);
}
} else {
DBGLOG("weg", "missing AMD GPU device-id");
}
DBGLOG("weg", "hooked configRead read methods!");
}
// Ensure built-in.
if (!device->getProperty("built-in")) {
DBGLOG("weg", "fixing built-in");
uint8_t builtBytes[] { 0x00 };
device->setProperty("built-in", builtBytes, sizeof(builtBytes));
} else {
DBGLOG("weg", "found existing built-in");
}
}
void WEG::processManagementEngineProperties(IORegistryEntry *imei) {
auto name = imei->getName();
// Rename mislabeled IMEI device
if (!name || strcmp(name, "IMEI") != 0)
WIOKit::renameDevice(imei, "IMEI");
uint32_t device = 0;
auto cpuGeneration = BaseDeviceInfo::get().cpuGeneration;
if ((cpuGeneration == CPUInfo::CpuGeneration::SandyBridge ||
cpuGeneration == CPUInfo::CpuGeneration::IvyBridge) &&
WIOKit::getOSDataValue(imei, "device-id", device)) {
// Exotic cases like SNB CPU on 7-series motherboards or IVB CPU on 6-series
// require device-id faking. Unfortunately it is too late to change it at this step,
// because device matching happens earlier, but we will spill a warning to make sure
// one fixes them at device property or ACPI level.
uint32_t suggest = 0;
if (cpuGeneration == CPUInfo::CpuGeneration::SandyBridge && device != 0x1C3A)
suggest = 0x1C3A;
else if (cpuGeneration == CPUInfo::CpuGeneration::IvyBridge && device != 0x1E3A)
suggest = 0x1E3A;
if (suggest != 0) {
uint8_t bus = 0, dev = 0, fun = 0;
WIOKit::getDeviceAddress(imei, bus, dev, fun);
SYSLOG("weg", "IMEI device (%02X:%02X.%02X) has device-id 0x%04X, you should change it to 0x%04X",
bus, dev, fun, device, suggest);
}
}
}
void WEG::processGraphicsPolicyStr(const char *agdp) {
DBGLOG("weg", "agdpmod using config %s", agdp);
if (strstr(agdp, "detect")) {
graphicsDisplayPolicyMod = AGDP_DETECT_SET;
} else if (strstr(agdp, "ignore")) {
graphicsDisplayPolicyMod = AGDP_NONE_SET;
} else {
graphicsDisplayPolicyMod = AGDP_NONE_SET;
if (strstr(agdp, "vit9696"))
graphicsDisplayPolicyMod |= AGDP_VIT9696;
if (strstr(agdp, "pikera"))
graphicsDisplayPolicyMod |= AGDP_PIKERA;
if (strstr(agdp, "cfgmap"))
graphicsDisplayPolicyMod |= AGDP_CFGMAP;
}
}
void WEG::processGraphicsPolicyMods(KernelPatcher &patcher, mach_vm_address_t address, size_t size) {
if (graphicsDisplayPolicyMod & AGDP_VIT9696) {
uint8_t find[] = {0xBA, 0x05, 0x00, 0x00, 0x00};
uint8_t replace[] = {0xBA, 0x00, 0x00, 0x00, 0x00};
KernelPatcher::LookupPatch patch {
&kextAGDPolicy, find, replace, sizeof(find), 1
};
patcher.applyLookupPatch(&patch);
if (patcher.getError() != KernelPatcher::Error::NoError) {
SYSLOG("weg", "failed to apply agdp vit9696's patch %d", patcher.getError());
patcher.clearError();
}
}
if (graphicsDisplayPolicyMod & AGDP_PIKERA) {
KernelPatcher::LookupPatch patch {
&kextAGDPolicy,
reinterpret_cast<const uint8_t *>("board-id"),
reinterpret_cast<const uint8_t *>("board-ix"),
sizeof("board-id"), 1
};
patcher.applyLookupPatch(&patch);
if (patcher.getError() != KernelPatcher::Error::NoError) {
SYSLOG("weg", "failed to apply agdp Piker-Alpha's patch %d", patcher.getError());
patcher.clearError();
}
}
if (graphicsDisplayPolicyMod & AGDP_CFGMAP) {
// Does not function in 10.13.x, as the symbols have been stripped. Abort on usage on 10.14 or newer.
if (getKernelVersion() >= KernelVersion::Mojave)
PANIC("weg", "adgpmod=cfgmap has no effect on 10.13.4, use agdpmod=ignore");
KernelPatcher::RouteRequest request("__ZN25AppleGraphicsDevicePolicy5startEP9IOService", wrapGraphicsPolicyStart, orgGraphicsPolicyStart);
patcher.routeMultiple(kextAGDPolicy.loadIndex, &request, 1, address, size);
}
}
bool WEG::isGraphicsPolicyModRequired(DeviceInfo *info) {
DBGLOG("weg", "detecting policy");
// Graphics policy patches are only applicable to discrete GPUs.
if (info->videoExternal.size() == 0) {
DBGLOG("weg", "no external gpus");
return false;
}
// Graphics policy patches do harm on Apple MacBooks, see:
// https://github.com/acidanthera/bugtracker/issues/260
if (info->firmwareVendor == DeviceInfo::FirmwareVendor::Apple) {
DBGLOG("weg", "apple firmware");
return false;
}
// We do not need AGDC patches on compatible devices.
auto boardId = BaseDeviceInfo::get().boardIdentifier;
DBGLOG("weg", "board is %s", boardId);
const char *compatibleBoards[] {
"Mac-00BE6ED71E35EB86", // iMac13,1
"Mac-27ADBB7B4CEE8E61", // iMac14,2
"Mac-4B7AC7E43945597E", // MacBookPro9,1
"Mac-77EB7D7DAF985301", // iMac14,3
"Mac-C3EC7CD22292981F", // MacBookPro10,1
"Mac-C9CF552659EA9913", // ???
"Mac-F221BEC8", // MacPro5,1 (and MacPro4,1)
"Mac-F221DCC8", // iMac10,1
"Mac-F42C88C8", // MacPro3,1
"Mac-FC02E91DDD3FA6A4", // iMac13,2
"Mac-2BD1B31983FE1663" // MacBookPro11,3
};
for (size_t i = 0; i < arrsize(compatibleBoards); i++) {
if (!strcmp(compatibleBoards[i], boardId)) {
DBGLOG("weg", "disabling nvidia patches on model %s", boardId);
return false;
}
}
return true;
}
void WEG::wrapFramebufferInit(IOFramebuffer *fb) {
bool backCopy = callbackWEG->gotConsoleVinfo && callbackWEG->resetFramebuffer == FB_COPY;
bool zeroFill = callbackWEG->gotConsoleVinfo && callbackWEG->resetFramebuffer == FB_ZEROFILL;
auto &info = callbackWEG->consoleVinfo;
// Copy back usually happens in a separate call to frameBufferInit
// Furthermore, v_baseaddr may not be available on subsequent calls, so we have to copy
if (backCopy && info.v_baseaddr) {
// Note, this buffer is left allocated and never freed, yet there actually is no way to free it.
callbackWEG->consoleBuffer = Buffer::create<uint8_t>(info.v_rowbytes * info.v_height);
if (callbackWEG->consoleBuffer)
lilu_os_memcpy(callbackWEG->consoleBuffer, reinterpret_cast<uint8_t *>(info.v_baseaddr), info.v_rowbytes * info.v_height);
else
SYSLOG("weg", "console buffer allocation failure");
// Even if we may succeed next time, it will be unreasonably dangerous
info.v_baseaddr = 0;
}
uint8_t verboseBoot = *callbackWEG->gIOFBVerboseBootPtr;
// For back copy we need a console buffer and no verbose
backCopy = backCopy && callbackWEG->consoleBuffer && !verboseBoot;
// Now check if the resolution and parameters match
if (backCopy || zeroFill) {
IODisplayModeID mode;
IOIndex depth;
IOPixelInformation pixelInfo;
if (fb->getCurrentDisplayMode(&mode, &depth) == kIOReturnSuccess &&
fb->getPixelInformation(mode, depth, kIOFBSystemAperture, &pixelInfo) == kIOReturnSuccess) {
DBGLOG("weg", "fb info 1: %d:%d %u:%u:%u",
mode, depth, pixelInfo.bytesPerRow, pixelInfo.bytesPerPlane, pixelInfo.bitsPerPixel);
DBGLOG("weg", "fb info 2: %u:%u %s %u:%u:%u",
pixelInfo.componentCount, pixelInfo.bitsPerComponent, pixelInfo.pixelFormat, pixelInfo.flags, pixelInfo.activeWidth, pixelInfo.activeHeight);
if (info.v_rowbytes != pixelInfo.bytesPerRow || info.v_width != pixelInfo.activeWidth ||
info.v_height != pixelInfo.activeHeight || info.v_depth != pixelInfo.bitsPerPixel) {
backCopy = zeroFill = false;
DBGLOG("weg", "this display has different mode");
}
} else {
DBGLOG("weg", "failed to obtain display mode");
backCopy = zeroFill = false;
}
}
// For whatever reason not resetting Intel framebuffer (back copy mode) twice works better.
if (!backCopy) *callbackWEG->gIOFBVerboseBootPtr = 1;
FunctionCast(wrapFramebufferInit, callbackWEG->orgFramebufferInit)(fb);
if (!backCopy) *callbackWEG->gIOFBVerboseBootPtr = verboseBoot;
// Finish the framebuffer initialisation by filling with black or copying the image back.
if (FramebufferViewer::getVramMap(fb)) {
auto src = reinterpret_cast<uint8_t *>(callbackWEG->consoleBuffer);
auto dst = reinterpret_cast<uint8_t *>(FramebufferViewer::getVramMap(fb)->getVirtualAddress());
if (backCopy) {
DBGLOG("weg", "attempting to copy...");
// Here you can actually draw at your will, but looks like only on Intel.
// On AMD you technically can draw too, but it happens for a very short while, and is not worth it.
lilu_os_memcpy(dst, src, info.v_rowbytes * info.v_height);
} else if (zeroFill) {
// On AMD we do a zero-fill to ensure no visual glitches.
DBGLOG("weg", "doing zero-fill...");
memset(dst, 0, info.v_rowbytes * info.v_height);
}
}
}
uint16_t WEG::wrapConfigRead16(IORegistryEntry *service, uint32_t space, uint8_t offset) {
auto result = callbackWEG->orgConfigRead16(service, space, offset);
if (offset == WIOKit::kIOPCIConfigDeviceID && service != nullptr) {
auto name = service->getName();
if (!name) return result;
bool doSpoof = (callbackWEG->hasIgpuSpoof && name[0] == 'I' && name[1] == 'G' && name[2] == 'P' && name[3] == 'U')
|| (callbackWEG->hasGfxSpoof && name[0] == 'G' && name[1] == 'F' && name[2] == 'X');
if (doSpoof) {
DBGLOG("weg", "configRead16 %s 0x%08X at off 0x%02X, result = 0x%04x", name, space, offset, result);
uint32_t device;
if (WIOKit::getOSDataValue(service, "device-id", device) && device != result) {
DBGLOG("weg", "configRead16 %s reported 0x%04x instead of 0x%04x", name, device, result);
return device;
}
}
}
return result;
}
uint32_t WEG::wrapConfigRead32(IORegistryEntry *service, uint32_t space, uint8_t offset) {
auto result = callbackWEG->orgConfigRead32(service, space, offset);
// According to lvs1974 unaligned reads may actually happen!
if ((offset == WIOKit::kIOPCIConfigDeviceID || offset == WIOKit::kIOPCIConfigVendorID) && service != nullptr) {
auto name = service->getName();
if (!name) return result;
bool doSpoof = (callbackWEG->hasIgpuSpoof && name[0] == 'I' && name[1] == 'G' && name[2] == 'P' && name[3] == 'U')
|| (callbackWEG->hasGfxSpoof && name[0] == 'G' && name[1] == 'F' && name[2] == 'X');
if (doSpoof) {
DBGLOG("weg", "configRead32 %s 0x%08X at off 0x%02X, result = 0x%08X", name, space, offset, result);
uint32_t device;
if (WIOKit::getOSDataValue(service, "device-id", device) && device != (result & 0xFFFF)) {
device = (result & 0xFFFF) | (device << 16);
DBGLOG("weg", "configRead32 %s reported 0x%08x instead of 0x%08x", name, device, result);
return device;
}
}
}
return result;
}
bool WEG::wrapGraphicsPolicyStart(IOService *that, IOService *provider) {
auto boardIdentifier = BaseDeviceInfo::get().boardIdentifier;
DBGLOG("weg", "agdp fix got board-id %s", boardIdentifier);
auto oldConfigMap = OSDynamicCast(OSDictionary, that->getProperty("ConfigMap"));
if (oldConfigMap) {
auto rawConfigMap = oldConfigMap->copyCollection();
if (rawConfigMap) {
auto newConfigMap = OSDynamicCast(OSDictionary, rawConfigMap);
if (newConfigMap) {
auto none = OSString::withCString("none");
if (none) {
newConfigMap->setObject(boardIdentifier, none);
none->release();
that->setProperty("ConfigMap", newConfigMap);
}
} else {
SYSLOG("weg", "agdp fix failed to clone ConfigMap");
}
rawConfigMap->release();
}
} else {
SYSLOG("weg", "agdp fix failed to obtain valid ConfigMap");
}
bool result = FunctionCast(wrapGraphicsPolicyStart, callbackWEG->orgGraphicsPolicyStart)(that, provider);
DBGLOG("weg", "agdp start returned %d", result);
return result;
}
bool WEG::wrapApplePanelSetDisplay(IOService *that, IODisplay *display) {
if (!callbackWEG->applePanelDisplaySet) {
callbackWEG->applePanelDisplaySet = true;
auto panels = OSDynamicCast(OSDictionary, that->getProperty("ApplePanels"));
if (panels) {
auto rawPanels = panels->copyCollection();
panels = OSDynamicCast(OSDictionary, rawPanels);
if (panels) {
const char *customName = nullptr;
if (callbackWEG->appleBacklightCustomName != nullptr) {
auto length = callbackWEG->appleBacklightCustomName->getLength();
const char *customNameBytes = static_cast<const char *>(callbackWEG->appleBacklightCustomName->getBytesNoCopy());
if (length > 0 && customNameBytes[length - 1] == '\0')
customName = customNameBytes;
}
for (auto &entry : appleBacklightData) {
if (customName != nullptr && strcmp(customName, entry.deviceName) == 0) {
panels->setObject(entry.deviceName, callbackWEG->appleBacklightCustomData);
DBGLOG("weg", "using custom panel data for %s device", entry.deviceName);
} else {
auto pd = OSData::withBytes(entry.deviceData, sizeof(entry.deviceData));
if (pd) {
panels->setObject(entry.deviceName, pd);
// No release required by current AppleBacklight implementation.
} else {
SYSLOG("weg", "panel start cannot allocate %s data", entry.deviceName);
}
}
}
that->setProperty("ApplePanels", panels);
}
if (rawPanels) {
rawPanels->release();
}
} else {
SYSLOG("weg", "panel start has no panels");
}
}
bool result = FunctionCast(wrapApplePanelSetDisplay, callbackWEG->orgApplePanelSetDisplay)(that, display);
DBGLOG("weg", "panel display set returned %d", result);
return result;
}
bool WEG::getVideoArgument(DeviceInfo *info, const char *name, void *bootarg, int size) {
if (PE_parse_boot_argn(name, bootarg, size))
return true;
for (size_t i = 0; i < info->videoExternal.size(); i++) {
auto prop = OSDynamicCast(OSData, info->videoExternal[i].video->getProperty(name));
auto propSize = prop ? prop->getLength() : 0;
if (propSize > 0 && propSize <= size) {
lilu_os_memcpy(bootarg, prop->getBytesNoCopy(), propSize);
memset(static_cast<uint8_t *>(bootarg) + propSize, 0, size - propSize);
return true;
}
}
if (info->videoBuiltin) {
auto prop = OSDynamicCast(OSData, info->videoBuiltin->getProperty(name));
auto propSize = prop ? prop->getLength() : 0;
if (propSize > 0 && propSize <= size) {
lilu_os_memcpy(bootarg, prop->getBytesNoCopy(), propSize);
memset(static_cast<uint8_t *>(bootarg) + propSize, 0, size - propSize);
return true;
}
}
return false;
}
|
global test_case
extern Array.beforeb
extern Array.eachb
extern std.outb
extern std.outln
extern sys.error
%include "Array.inc"
section .text
test_case:
mov rax, test_array ; Array to split
mov rbx, 3 ; delimit with value 3
call Array.beforeb ; split into two arrays
push qword[rbx+Array.length] ; preserve leftover length
mov rbx, std.outb ; fn to call
call Array.eachb ; print values from array
mov rax, empty_str ; empty message
call std.outln ; end line
pop rax ; restore length
call sys.error ; exit with array length
section .data
test_bytes: db 0x1, 0x2, 0x3, 0x4
empty_str: db 0x0
test_array:
istruc Array
at Array.pdata, dq test_bytes
at Array.length, dq 4
iend
|
_forktest: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
printf(1, "fork test OK\n");
}
int
main(void)
{
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 83 e4 f0 and $0xfffffff0,%esp
6: 83 ec 10 sub $0x10,%esp
forktest();
9: e8 42 00 00 00 call 50 <forktest>
exit(0);
e: c7 04 24 00 00 00 00 movl $0x0,(%esp)
15: e8 ae 03 00 00 call 3c8 <exit>
1a: 66 90 xchg %ax,%ax
1c: 66 90 xchg %ax,%ax
1e: 66 90 xchg %ax,%ax
00000020 <printf>:
{
20: 55 push %ebp
21: 89 e5 mov %esp,%ebp
23: 53 push %ebx
24: 83 ec 14 sub $0x14,%esp
27: 8b 5d 0c mov 0xc(%ebp),%ebx
write(fd, s, strlen(s));
2a: 89 1c 24 mov %ebx,(%esp)
2d: e8 ce 01 00 00 call 200 <strlen>
32: 89 5c 24 04 mov %ebx,0x4(%esp)
36: 89 44 24 08 mov %eax,0x8(%esp)
3a: 8b 45 08 mov 0x8(%ebp),%eax
3d: 89 04 24 mov %eax,(%esp)
40: e8 a3 03 00 00 call 3e8 <write>
}
45: 83 c4 14 add $0x14,%esp
48: 5b pop %ebx
49: 5d pop %ebp
4a: c3 ret
4b: 90 nop
4c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
00000050 <forktest>:
{
50: 55 push %ebp
51: 89 e5 mov %esp,%ebp
53: 53 push %ebx
write(fd, s, strlen(s));
54: bb 78 04 00 00 mov $0x478,%ebx
{
59: 83 ec 14 sub $0x14,%esp
write(fd, s, strlen(s));
5c: c7 04 24 78 04 00 00 movl $0x478,(%esp)
63: e8 98 01 00 00 call 200 <strlen>
68: 89 5c 24 04 mov %ebx,0x4(%esp)
for(n=0; n<N; n++){
6c: 31 db xor %ebx,%ebx
write(fd, s, strlen(s));
6e: c7 04 24 01 00 00 00 movl $0x1,(%esp)
75: 89 44 24 08 mov %eax,0x8(%esp)
79: e8 6a 03 00 00 call 3e8 <write>
7e: eb 12 jmp 92 <forktest+0x42>
if(pid == 0)
80: 0f 84 d8 00 00 00 je 15e <forktest+0x10e>
for(n=0; n<N; n++){
86: 43 inc %ebx
87: 81 fb e8 03 00 00 cmp $0x3e8,%ebx
8d: 8d 76 00 lea 0x0(%esi),%esi
90: 74 76 je 108 <forktest+0xb8>
pid = fork();
92: e8 29 03 00 00 call 3c0 <fork>
if(pid < 0)
97: 85 c0 test %eax,%eax
99: 79 e5 jns 80 <forktest+0x30>
for(; n > 0; n--){
9b: 85 db test %ebx,%ebx
9d: 8d 76 00 lea 0x0(%esi),%esi
a0: 74 21 je c3 <forktest+0x73>
a2: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
a9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
if(wait(0) < 0){
b0: c7 04 24 00 00 00 00 movl $0x0,(%esp)
b7: e8 14 03 00 00 call 3d0 <wait>
bc: 85 c0 test %eax,%eax
be: 78 79 js 139 <forktest+0xe9>
for(; n > 0; n--){
c0: 4b dec %ebx
c1: 75 ed jne b0 <forktest+0x60>
if(wait(0) != -1){
c3: c7 04 24 00 00 00 00 movl $0x0,(%esp)
ca: e8 01 03 00 00 call 3d0 <wait>
cf: 40 inc %eax
d0: 0f 85 94 00 00 00 jne 16a <forktest+0x11a>
write(fd, s, strlen(s));
d6: c7 04 24 aa 04 00 00 movl $0x4aa,(%esp)
dd: e8 1e 01 00 00 call 200 <strlen>
e2: ba aa 04 00 00 mov $0x4aa,%edx
e7: 89 54 24 04 mov %edx,0x4(%esp)
eb: c7 04 24 01 00 00 00 movl $0x1,(%esp)
f2: 89 44 24 08 mov %eax,0x8(%esp)
f6: e8 ed 02 00 00 call 3e8 <write>
}
fb: 83 c4 14 add $0x14,%esp
fe: 5b pop %ebx
ff: 5d pop %ebp
100: c3 ret
101: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
write(fd, s, strlen(s));
108: c7 04 24 b8 04 00 00 movl $0x4b8,(%esp)
10f: e8 ec 00 00 00 call 200 <strlen>
114: c7 04 24 01 00 00 00 movl $0x1,(%esp)
11b: 89 44 24 08 mov %eax,0x8(%esp)
11f: b8 b8 04 00 00 mov $0x4b8,%eax
124: 89 44 24 04 mov %eax,0x4(%esp)
128: e8 bb 02 00 00 call 3e8 <write>
exit(0);
12d: c7 04 24 00 00 00 00 movl $0x0,(%esp)
134: e8 8f 02 00 00 call 3c8 <exit>
write(fd, s, strlen(s));
139: c7 04 24 83 04 00 00 movl $0x483,(%esp)
140: e8 bb 00 00 00 call 200 <strlen>
145: b9 83 04 00 00 mov $0x483,%ecx
14a: 89 4c 24 04 mov %ecx,0x4(%esp)
14e: c7 04 24 01 00 00 00 movl $0x1,(%esp)
155: 89 44 24 08 mov %eax,0x8(%esp)
159: e8 8a 02 00 00 call 3e8 <write>
exit(0);
15e: c7 04 24 00 00 00 00 movl $0x0,(%esp)
165: e8 5e 02 00 00 call 3c8 <exit>
write(fd, s, strlen(s));
16a: c7 04 24 97 04 00 00 movl $0x497,(%esp)
171: e8 8a 00 00 00 call 200 <strlen>
176: c7 44 24 04 97 04 00 movl $0x497,0x4(%esp)
17d: 00
17e: c7 04 24 01 00 00 00 movl $0x1,(%esp)
185: 89 44 24 08 mov %eax,0x8(%esp)
189: e8 5a 02 00 00 call 3e8 <write>
exit(0);
18e: c7 04 24 00 00 00 00 movl $0x0,(%esp)
195: e8 2e 02 00 00 call 3c8 <exit>
19a: 66 90 xchg %ax,%ax
19c: 66 90 xchg %ax,%ax
19e: 66 90 xchg %ax,%ax
000001a0 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, const char *t)
{
1a0: 55 push %ebp
1a1: 89 e5 mov %esp,%ebp
1a3: 8b 45 08 mov 0x8(%ebp),%eax
1a6: 8b 4d 0c mov 0xc(%ebp),%ecx
1a9: 53 push %ebx
char *os;
os = s;
while((*s++ = *t++) != 0)
1aa: 89 c2 mov %eax,%edx
1ac: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
1b0: 41 inc %ecx
1b1: 0f b6 59 ff movzbl -0x1(%ecx),%ebx
1b5: 42 inc %edx
1b6: 84 db test %bl,%bl
1b8: 88 5a ff mov %bl,-0x1(%edx)
1bb: 75 f3 jne 1b0 <strcpy+0x10>
;
return os;
}
1bd: 5b pop %ebx
1be: 5d pop %ebp
1bf: c3 ret
000001c0 <strcmp>:
int
strcmp(const char *p, const char *q)
{
1c0: 55 push %ebp
1c1: 89 e5 mov %esp,%ebp
1c3: 8b 4d 08 mov 0x8(%ebp),%ecx
1c6: 53 push %ebx
1c7: 8b 5d 0c mov 0xc(%ebp),%ebx
while(*p && *p == *q)
1ca: 0f b6 01 movzbl (%ecx),%eax
1cd: 0f b6 13 movzbl (%ebx),%edx
1d0: 84 c0 test %al,%al
1d2: 75 18 jne 1ec <strcmp+0x2c>
1d4: eb 22 jmp 1f8 <strcmp+0x38>
1d6: 8d 76 00 lea 0x0(%esi),%esi
1d9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
p++, q++;
1e0: 41 inc %ecx
while(*p && *p == *q)
1e1: 0f b6 01 movzbl (%ecx),%eax
p++, q++;
1e4: 43 inc %ebx
1e5: 0f b6 13 movzbl (%ebx),%edx
while(*p && *p == *q)
1e8: 84 c0 test %al,%al
1ea: 74 0c je 1f8 <strcmp+0x38>
1ec: 38 d0 cmp %dl,%al
1ee: 74 f0 je 1e0 <strcmp+0x20>
return (uchar)*p - (uchar)*q;
}
1f0: 5b pop %ebx
return (uchar)*p - (uchar)*q;
1f1: 29 d0 sub %edx,%eax
}
1f3: 5d pop %ebp
1f4: c3 ret
1f5: 8d 76 00 lea 0x0(%esi),%esi
1f8: 5b pop %ebx
1f9: 31 c0 xor %eax,%eax
return (uchar)*p - (uchar)*q;
1fb: 29 d0 sub %edx,%eax
}
1fd: 5d pop %ebp
1fe: c3 ret
1ff: 90 nop
00000200 <strlen>:
uint
strlen(const char *s)
{
200: 55 push %ebp
201: 89 e5 mov %esp,%ebp
203: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
for(n = 0; s[n]; n++)
206: 80 39 00 cmpb $0x0,(%ecx)
209: 74 15 je 220 <strlen+0x20>
20b: 31 d2 xor %edx,%edx
20d: 8d 76 00 lea 0x0(%esi),%esi
210: 42 inc %edx
211: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1)
215: 89 d0 mov %edx,%eax
217: 75 f7 jne 210 <strlen+0x10>
;
return n;
}
219: 5d pop %ebp
21a: c3 ret
21b: 90 nop
21c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
for(n = 0; s[n]; n++)
220: 31 c0 xor %eax,%eax
}
222: 5d pop %ebp
223: c3 ret
224: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
22a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00000230 <memset>:
void*
memset(void *dst, int c, uint n)
{
230: 55 push %ebp
231: 89 e5 mov %esp,%ebp
233: 8b 55 08 mov 0x8(%ebp),%edx
236: 57 push %edi
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
237: 8b 4d 10 mov 0x10(%ebp),%ecx
23a: 8b 45 0c mov 0xc(%ebp),%eax
23d: 89 d7 mov %edx,%edi
23f: fc cld
240: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
242: 5f pop %edi
243: 89 d0 mov %edx,%eax
245: 5d pop %ebp
246: c3 ret
247: 89 f6 mov %esi,%esi
249: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000250 <strchr>:
char*
strchr(const char *s, char c)
{
250: 55 push %ebp
251: 89 e5 mov %esp,%ebp
253: 8b 45 08 mov 0x8(%ebp),%eax
256: 0f b6 4d 0c movzbl 0xc(%ebp),%ecx
for(; *s; s++)
25a: 0f b6 10 movzbl (%eax),%edx
25d: 84 d2 test %dl,%dl
25f: 74 1b je 27c <strchr+0x2c>
if(*s == c)
261: 38 d1 cmp %dl,%cl
263: 75 0f jne 274 <strchr+0x24>
265: eb 17 jmp 27e <strchr+0x2e>
267: 89 f6 mov %esi,%esi
269: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
270: 38 ca cmp %cl,%dl
272: 74 0a je 27e <strchr+0x2e>
for(; *s; s++)
274: 40 inc %eax
275: 0f b6 10 movzbl (%eax),%edx
278: 84 d2 test %dl,%dl
27a: 75 f4 jne 270 <strchr+0x20>
return (char*)s;
return 0;
27c: 31 c0 xor %eax,%eax
}
27e: 5d pop %ebp
27f: c3 ret
00000280 <gets>:
char*
gets(char *buf, int max)
{
280: 55 push %ebp
281: 89 e5 mov %esp,%ebp
283: 57 push %edi
284: 56 push %esi
int i, cc;
char c;
for(i=0; i+1 < max; ){
285: 31 f6 xor %esi,%esi
{
287: 53 push %ebx
288: 83 ec 3c sub $0x3c,%esp
28b: 8b 5d 08 mov 0x8(%ebp),%ebx
cc = read(0, &c, 1);
28e: 8d 7d e7 lea -0x19(%ebp),%edi
for(i=0; i+1 < max; ){
291: eb 32 jmp 2c5 <gets+0x45>
293: 90 nop
294: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
cc = read(0, &c, 1);
298: ba 01 00 00 00 mov $0x1,%edx
29d: 89 54 24 08 mov %edx,0x8(%esp)
2a1: 89 7c 24 04 mov %edi,0x4(%esp)
2a5: c7 04 24 00 00 00 00 movl $0x0,(%esp)
2ac: e8 2f 01 00 00 call 3e0 <read>
if(cc < 1)
2b1: 85 c0 test %eax,%eax
2b3: 7e 19 jle 2ce <gets+0x4e>
break;
buf[i++] = c;
2b5: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
2b9: 43 inc %ebx
2ba: 88 43 ff mov %al,-0x1(%ebx)
if(c == '\n' || c == '\r')
2bd: 3c 0a cmp $0xa,%al
2bf: 74 1f je 2e0 <gets+0x60>
2c1: 3c 0d cmp $0xd,%al
2c3: 74 1b je 2e0 <gets+0x60>
for(i=0; i+1 < max; ){
2c5: 46 inc %esi
2c6: 3b 75 0c cmp 0xc(%ebp),%esi
2c9: 89 5d d4 mov %ebx,-0x2c(%ebp)
2cc: 7c ca jl 298 <gets+0x18>
break;
}
buf[i] = '\0';
2ce: 8b 45 d4 mov -0x2c(%ebp),%eax
2d1: c6 00 00 movb $0x0,(%eax)
return buf;
}
2d4: 8b 45 08 mov 0x8(%ebp),%eax
2d7: 83 c4 3c add $0x3c,%esp
2da: 5b pop %ebx
2db: 5e pop %esi
2dc: 5f pop %edi
2dd: 5d pop %ebp
2de: c3 ret
2df: 90 nop
2e0: 8b 45 08 mov 0x8(%ebp),%eax
2e3: 01 c6 add %eax,%esi
2e5: 89 75 d4 mov %esi,-0x2c(%ebp)
2e8: eb e4 jmp 2ce <gets+0x4e>
2ea: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
000002f0 <stat>:
int
stat(const char *n, struct stat *st)
{
2f0: 55 push %ebp
int fd;
int r;
fd = open(n, O_RDONLY);
2f1: 31 c0 xor %eax,%eax
{
2f3: 89 e5 mov %esp,%ebp
2f5: 83 ec 18 sub $0x18,%esp
fd = open(n, O_RDONLY);
2f8: 89 44 24 04 mov %eax,0x4(%esp)
2fc: 8b 45 08 mov 0x8(%ebp),%eax
{
2ff: 89 5d f8 mov %ebx,-0x8(%ebp)
302: 89 75 fc mov %esi,-0x4(%ebp)
fd = open(n, O_RDONLY);
305: 89 04 24 mov %eax,(%esp)
308: e8 fb 00 00 00 call 408 <open>
if(fd < 0)
30d: 85 c0 test %eax,%eax
30f: 78 2f js 340 <stat+0x50>
311: 89 c3 mov %eax,%ebx
return -1;
r = fstat(fd, st);
313: 8b 45 0c mov 0xc(%ebp),%eax
316: 89 1c 24 mov %ebx,(%esp)
319: 89 44 24 04 mov %eax,0x4(%esp)
31d: e8 fe 00 00 00 call 420 <fstat>
close(fd);
322: 89 1c 24 mov %ebx,(%esp)
r = fstat(fd, st);
325: 89 c6 mov %eax,%esi
close(fd);
327: e8 c4 00 00 00 call 3f0 <close>
return r;
}
32c: 89 f0 mov %esi,%eax
32e: 8b 5d f8 mov -0x8(%ebp),%ebx
331: 8b 75 fc mov -0x4(%ebp),%esi
334: 89 ec mov %ebp,%esp
336: 5d pop %ebp
337: c3 ret
338: 90 nop
339: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
return -1;
340: be ff ff ff ff mov $0xffffffff,%esi
345: eb e5 jmp 32c <stat+0x3c>
347: 89 f6 mov %esi,%esi
349: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000350 <atoi>:
int
atoi(const char *s)
{
350: 55 push %ebp
351: 89 e5 mov %esp,%ebp
353: 8b 4d 08 mov 0x8(%ebp),%ecx
356: 53 push %ebx
int n;
n = 0;
while('0' <= *s && *s <= '9')
357: 0f be 11 movsbl (%ecx),%edx
35a: 88 d0 mov %dl,%al
35c: 2c 30 sub $0x30,%al
35e: 3c 09 cmp $0x9,%al
n = 0;
360: b8 00 00 00 00 mov $0x0,%eax
while('0' <= *s && *s <= '9')
365: 77 1e ja 385 <atoi+0x35>
367: 89 f6 mov %esi,%esi
369: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
n = n*10 + *s++ - '0';
370: 41 inc %ecx
371: 8d 04 80 lea (%eax,%eax,4),%eax
374: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax
while('0' <= *s && *s <= '9')
378: 0f be 11 movsbl (%ecx),%edx
37b: 88 d3 mov %dl,%bl
37d: 80 eb 30 sub $0x30,%bl
380: 80 fb 09 cmp $0x9,%bl
383: 76 eb jbe 370 <atoi+0x20>
return n;
}
385: 5b pop %ebx
386: 5d pop %ebp
387: c3 ret
388: 90 nop
389: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
00000390 <memmove>:
void*
memmove(void *vdst, const void *vsrc, int n)
{
390: 55 push %ebp
391: 89 e5 mov %esp,%ebp
393: 56 push %esi
394: 8b 45 08 mov 0x8(%ebp),%eax
397: 53 push %ebx
398: 8b 5d 10 mov 0x10(%ebp),%ebx
39b: 8b 75 0c mov 0xc(%ebp),%esi
char *dst;
const char *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
39e: 85 db test %ebx,%ebx
3a0: 7e 1a jle 3bc <memmove+0x2c>
3a2: 31 d2 xor %edx,%edx
3a4: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
3aa: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
*dst++ = *src++;
3b0: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx
3b4: 88 0c 10 mov %cl,(%eax,%edx,1)
3b7: 42 inc %edx
while(n-- > 0)
3b8: 39 d3 cmp %edx,%ebx
3ba: 75 f4 jne 3b0 <memmove+0x20>
return vdst;
}
3bc: 5b pop %ebx
3bd: 5e pop %esi
3be: 5d pop %ebp
3bf: c3 ret
000003c0 <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
3c0: b8 01 00 00 00 mov $0x1,%eax
3c5: cd 40 int $0x40
3c7: c3 ret
000003c8 <exit>:
SYSCALL(exit)
3c8: b8 02 00 00 00 mov $0x2,%eax
3cd: cd 40 int $0x40
3cf: c3 ret
000003d0 <wait>:
SYSCALL(wait)
3d0: b8 03 00 00 00 mov $0x3,%eax
3d5: cd 40 int $0x40
3d7: c3 ret
000003d8 <pipe>:
SYSCALL(pipe)
3d8: b8 04 00 00 00 mov $0x4,%eax
3dd: cd 40 int $0x40
3df: c3 ret
000003e0 <read>:
SYSCALL(read)
3e0: b8 05 00 00 00 mov $0x5,%eax
3e5: cd 40 int $0x40
3e7: c3 ret
000003e8 <write>:
SYSCALL(write)
3e8: b8 10 00 00 00 mov $0x10,%eax
3ed: cd 40 int $0x40
3ef: c3 ret
000003f0 <close>:
SYSCALL(close)
3f0: b8 15 00 00 00 mov $0x15,%eax
3f5: cd 40 int $0x40
3f7: c3 ret
000003f8 <kill>:
SYSCALL(kill)
3f8: b8 06 00 00 00 mov $0x6,%eax
3fd: cd 40 int $0x40
3ff: c3 ret
00000400 <exec>:
SYSCALL(exec)
400: b8 07 00 00 00 mov $0x7,%eax
405: cd 40 int $0x40
407: c3 ret
00000408 <open>:
SYSCALL(open)
408: b8 0f 00 00 00 mov $0xf,%eax
40d: cd 40 int $0x40
40f: c3 ret
00000410 <mknod>:
SYSCALL(mknod)
410: b8 11 00 00 00 mov $0x11,%eax
415: cd 40 int $0x40
417: c3 ret
00000418 <unlink>:
SYSCALL(unlink)
418: b8 12 00 00 00 mov $0x12,%eax
41d: cd 40 int $0x40
41f: c3 ret
00000420 <fstat>:
SYSCALL(fstat)
420: b8 08 00 00 00 mov $0x8,%eax
425: cd 40 int $0x40
427: c3 ret
00000428 <link>:
SYSCALL(link)
428: b8 13 00 00 00 mov $0x13,%eax
42d: cd 40 int $0x40
42f: c3 ret
00000430 <mkdir>:
SYSCALL(mkdir)
430: b8 14 00 00 00 mov $0x14,%eax
435: cd 40 int $0x40
437: c3 ret
00000438 <chdir>:
SYSCALL(chdir)
438: b8 09 00 00 00 mov $0x9,%eax
43d: cd 40 int $0x40
43f: c3 ret
00000440 <dup>:
SYSCALL(dup)
440: b8 0a 00 00 00 mov $0xa,%eax
445: cd 40 int $0x40
447: c3 ret
00000448 <getpid>:
SYSCALL(getpid)
448: b8 0b 00 00 00 mov $0xb,%eax
44d: cd 40 int $0x40
44f: c3 ret
00000450 <sbrk>:
SYSCALL(sbrk)
450: b8 0c 00 00 00 mov $0xc,%eax
455: cd 40 int $0x40
457: c3 ret
00000458 <sleep>:
SYSCALL(sleep)
458: b8 0d 00 00 00 mov $0xd,%eax
45d: cd 40 int $0x40
45f: c3 ret
00000460 <uptime>:
SYSCALL(uptime)
460: b8 0e 00 00 00 mov $0xe,%eax
465: cd 40 int $0x40
467: c3 ret
00000468 <detach>:
SYSCALL(detach)
468: b8 16 00 00 00 mov $0x16,%eax
46d: cd 40 int $0x40
46f: c3 ret
00000470 <priority>:
SYSCALL(priority)
470: b8 17 00 00 00 mov $0x17,%eax
475: cd 40 int $0x40
477: c3 ret
|
; A165793: a(0)=1, a(n)=n*(a(n-1)-2).
; 1,-1,-6,-24,-104,-530,-3192,-22358,-178880,-1609938,-16099400,-177093422,-2125121088,-27626574170,-386772038408,-5801580576150,-92825289218432,-1578029916713378,-28404538500840840,-539686231515975998,-10793724630319520000,-226668217236709920042,-4986700779207618240968,-114694117921775219542310,-2752658830122605269015488,-68816470753065131725387250,-1789228239579693424860068552,-48309162468651722471221850958,-1352656549122248229194211826880,-39227039924545198646632142979578,-1176811197736355959398964289387400,-36481147129827034741367892971009462
pow $0,2
mov $1,4
mov $2,$0
lpb $0
mov $0,$2
sub $1,8
add $3,1
div $0,$3
sub $0,$3
mul $1,$3
lpe
div $1,4
mov $0,$1
|
; A046161: a(n) = denominator of binomial(2n,n)/4^n.
; 1,2,8,16,128,256,1024,2048,32768,65536,262144,524288,4194304,8388608,33554432,67108864,2147483648,4294967296,17179869184,34359738368,274877906944,549755813888,2199023255552,4398046511104,70368744177664,140737488355328,562949953421312,1125899906842624,9007199254740992
mov $1,$0
mov $2,8
lpb $0
sub $0,1
add $2,$1
div $1,2
lpe
add $1,2
sub $2,1
pow $1,$2
mul $1,2
sub $1,244
div $1,256
add $1,1
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r12
push %r13
push %rbp
push %rbx
push %rcx
push %rdx
lea addresses_normal_ht+0x9361, %r12
nop
nop
nop
cmp $58578, %r11
mov (%r12), %bp
nop
nop
nop
nop
xor %rbp, %rbp
lea addresses_D_ht+0x1ee15, %rbx
nop
nop
nop
sub $24068, %r13
mov $0x6162636465666768, %rcx
movq %rcx, %xmm0
vmovups %ymm0, (%rbx)
inc %r12
lea addresses_normal_ht+0x1cde1, %r13
clflush (%r13)
nop
nop
nop
add $44391, %rdx
mov $0x6162636465666768, %r12
movq %r12, %xmm0
vmovups %ymm0, (%r13)
nop
nop
nop
nop
xor %rcx, %rcx
lea addresses_D_ht+0x1661, %r13
sub $14403, %r12
mov $0x6162636465666768, %rcx
movq %rcx, (%r13)
nop
nop
nop
nop
nop
sub $33827, %rbp
pop %rdx
pop %rcx
pop %rbx
pop %rbp
pop %r13
pop %r12
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r12
push %r13
push %r8
push %rax
push %rbx
// Load
mov $0x7513060000000fa1, %r12
nop
nop
nop
nop
inc %r11
vmovups (%r12), %ymm5
vextracti128 $0, %ymm5, %xmm5
vpextrq $0, %xmm5, %rbx
and %rbx, %rbx
// Faulty Load
lea addresses_normal+0xd361, %r8
nop
nop
nop
nop
nop
and %r11, %r11
vmovups (%r8), %ymm1
vextracti128 $0, %ymm1, %xmm1
vpextrq $0, %xmm1, %r13
lea oracles, %rax
and $0xff, %r13
shlq $12, %r13
mov (%rax,%r13,1), %r13
pop %rbx
pop %rax
pop %r8
pop %r13
pop %r12
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 8, 'type': 'addresses_normal', 'congruent': 0}}
{'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_NC', 'congruent': 6}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_normal', 'congruent': 0}}
<gen_prepare_buffer>
{'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_normal_ht', 'congruent': 10}}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_D_ht', 'congruent': 1}, 'OP': 'STOR'}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_normal_ht', 'congruent': 7}, 'OP': 'STOR'}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 8, 'type': 'addresses_D_ht', 'congruent': 7}, 'OP': 'STOR'}
{'34': 24}
34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34
*/
|
; A199264: Period 18: repeat (9,8,7,6,5,4,3,2,1,0,1,2,3,4,5,6,7,8).
; 9,8,7,6,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9,8,7,6,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9,8,7,6,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9,8,7,6,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9,8,7,6,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9,8,7,6,5,4,3,2,1,0
lpb $0
sub $0,5
mov $2,13
trn $2,$0
trn $0,13
add $0,$2
lpe
mov $1,9
sub $1,$0
mov $0,$1
|
; Licensed to the .NET Foundation under one or more agreements.
; The .NET Foundation licenses this file to you under the MIT license.
; See the LICENSE file in the project root for more information.
; ==++==
;
;
; ==--==
; ***********************************************************************
; File: JitHelpers_Fast.asm, see jithelp.asm for history
;
; Notes: routinues which we believe to be on the hot path for managed
; code in most scenarios.
; ***********************************************************************
include AsmMacros.inc
include asmconstants.inc
; Min amount of stack space that a nested function should allocate.
MIN_SIZE equ 28h
EXTERN g_ephemeral_low:QWORD
EXTERN g_ephemeral_high:QWORD
EXTERN g_lowest_address:QWORD
EXTERN g_highest_address:QWORD
EXTERN g_card_table:QWORD
ifdef FEATURE_USE_SOFTWARE_WRITE_WATCH_FOR_GC_HEAP
EXTERN g_sw_ww_table:QWORD
EXTERN g_sw_ww_enabled_for_gc_heap:BYTE
endif
ifdef WRITE_BARRIER_CHECK
; Those global variables are always defined, but should be 0 for Server GC
g_GCShadow TEXTEQU <?g_GCShadow@@3PEAEEA>
g_GCShadowEnd TEXTEQU <?g_GCShadowEnd@@3PEAEEA>
EXTERN g_GCShadow:QWORD
EXTERN g_GCShadowEnd:QWORD
endif
INVALIDGCVALUE equ 0CCCCCCCDh
ifdef _DEBUG
extern JIT_WriteBarrier_Debug:proc
endif
extern JIT_InternalThrow:proc
extern JITutil_ChkCastInterface:proc
extern JITutil_IsInstanceOfInterface:proc
extern JITutil_ChkCastAny:proc
extern JITutil_IsInstanceOfAny:proc
;EXTERN_C Object* JIT_IsInstanceOfClass(MethodTable* pMT, Object* pObject);
LEAF_ENTRY JIT_IsInstanceOfClass, _TEXT
; move rdx into rax in case of a match or null
mov rax, rdx
; check if the instance is null
test rdx, rdx
je IsNullInst
; check is the MethodTable for the instance matches pMT
cmp rcx, qword ptr [rdx]
jne JIT_IsInstanceOfClass2
IsNullInst:
REPRET
LEAF_END JIT_IsInstanceOfClass, _TEXT
LEAF_ENTRY JIT_IsInstanceOfClass2, _TEXT
; check if the parent class matches.
; start by putting the MethodTable for the instance in rdx
mov rdx, qword ptr [rdx]
align 16
CheckParent:
; NULL parent MethodTable* indicates that we're at the top of the hierarchy
; unroll 0
mov rdx, qword ptr [rdx + OFFSETOF__MethodTable__m_pParentMethodTable]
cmp rcx, rdx
je IsInst
test rdx, rdx
je DoneWithLoop
; unroll 1
mov rdx, qword ptr [rdx + OFFSETOF__MethodTable__m_pParentMethodTable]
cmp rcx, rdx
je IsInst
test rdx, rdx
je DoneWithLoop
; unroll 2
mov rdx, qword ptr [rdx + OFFSETOF__MethodTable__m_pParentMethodTable]
cmp rcx, rdx
je IsInst
test rdx, rdx
je DoneWithLoop
; unroll 3
mov rdx, qword ptr [rdx + OFFSETOF__MethodTable__m_pParentMethodTable]
cmp rcx, rdx
je IsInst
test rdx, rdx
jne CheckParent
align 16
DoneWithLoop:
if METHODTABLE_EQUIVALENCE_FLAGS gt 0
; check if the instance is a proxy or has type equivalence
; get the MethodTable of the original Object (stored earlier in rax)
mov rdx, [rax]
test dword ptr [rdx + OFFSETOF__MethodTable__m_dwFlags], METHODTABLE_EQUIVALENCE_FLAGS
jne SlowPath
endif ; METHODTABLE_EQUIVALENCE_FLAGS gt 0
; we didn't find a match in the ParentMethodTable hierarchy
; and it isn't a proxy and doesn't have type equivalence, return NULL
xor eax, eax
ret
if METHODTABLE_EQUIVALENCE_FLAGS gt 0
SlowPath:
; Set up the args to call JITutil_IsInstanceOfAny. Note that rcx already contains
; the MethodTable*
mov rdx, rax ; rdx = Object*
; Call out to JITutil_IsInstanceOfAny to handle the proxy/equivalence case.
jmp JITutil_IsInstanceOfAny
endif ; METHODTABLE_EQUIVALENCE_FLAGS gt 0
; if it is a null instance then rax is null
; if they match then rax contains the instance
align 16
IsInst:
REPRET
LEAF_END JIT_IsInstanceOfClass2, _TEXT
; TODO: this is not necessary... we will be calling JIT_ChkCastClass2 all of the time
; now that the JIT inlines the null check and the exact MT comparison... Or are
; they only doing it on the IBC hot path??? Look into that. If it will turn out
; to be cold then put it down at the bottom.
;EXTERN_C Object* JIT_ChkCastClass(MethodTable* pMT, Object* pObject);
LEAF_ENTRY JIT_ChkCastClass, _TEXT
; check if the instance is null
test rdx, rdx
je IsNullInst
; check if the MethodTable for the instance matches pMT
cmp rcx, qword ptr [rdx]
jne JIT_ChkCastClassSpecial
IsNullInst:
; setup the return value for a match or null
mov rax, rdx
ret
LEAF_END JIT_ChkCastClass, _TEXT
LEAF_ENTRY JIT_ChkCastClassSpecial, _TEXT
; save off the instance in case it is a proxy, and to setup
; our return value for a match
mov rax, rdx
; check if the parent class matches.
; start by putting the MethodTable for the instance in rdx
mov rdx, qword ptr [rdx]
align 16
CheckParent:
; NULL parent MethodTable* indicates that we're at the top of the hierarchy
; unroll 0
mov rdx, qword ptr [rdx + OFFSETOF__MethodTable__m_pParentMethodTable]
cmp rcx, rdx
je IsInst
test rdx, rdx
je DoneWithLoop
; unroll 1
mov rdx, qword ptr [rdx + OFFSETOF__MethodTable__m_pParentMethodTable]
cmp rcx, rdx
je IsInst
test rdx, rdx
je DoneWithLoop
; unroll 2
mov rdx, qword ptr [rdx + OFFSETOF__MethodTable__m_pParentMethodTable]
cmp rcx, rdx
je IsInst
test rdx, rdx
je DoneWithLoop
; unroll 3
mov rdx, qword ptr [rdx + OFFSETOF__MethodTable__m_pParentMethodTable]
cmp rcx, rdx
je IsInst
test rdx, rdx
jne CheckParent
align 16
DoneWithLoop:
; Set up the args to call JITutil_ChkCastAny. Note that rcx already contains the MethodTable*
mov rdx, rax ; rdx = Object*
; Call out to JITutil_ChkCastAny to handle the proxy case and throw a rich
; InvalidCastException in case of failure.
jmp JITutil_ChkCastAny
; if it is a null instance then rax is null
; if they match then rax contains the instance
align 16
IsInst:
REPRET
LEAF_END JIT_ChkCastClassSpecial, _TEXT
FIX_INDIRECTION macro Reg
ifdef FEATURE_PREJIT
test Reg, 1
jz @F
mov Reg, [Reg-1]
@@:
endif
endm
; PERF TODO: consider prefetching the entire interface map into the cache
; For all bizarre castes this quickly fails and falls back onto the JITutil_IsInstanceOfAny
; helper, this means that all failure cases take the slow path as well.
;
; This can trash r10/r11
LEAF_ENTRY JIT_IsInstanceOfInterface, _TEXT
test rdx, rdx
jz IsNullInst
; get methodtable
mov rax, [rdx]
mov r11w, word ptr [rax + OFFSETOF__MethodTable__m_wNumInterfaces]
test r11w, r11w
jz DoBizarre
; fetch interface map ptr
mov rax, [rax + OFFSETOF__MethodTable__m_pInterfaceMap]
; r11 holds number of interfaces
; rax is pointer to beginning of interface map list
align 16
Top:
; rax -> InterfaceInfo_t* into the interface map, aligned to 4 entries
; use offsets of SIZEOF__InterfaceInfo_t to get at entry 1, 2, 3 in this
; block. If we make it through the full 4 without a hit we'll move to
; the next block of 4 and try again.
; unroll 0
ifdef FEATURE_PREJIT
mov r10, [rax + OFFSETOF__InterfaceInfo_t__m_pMethodTable]
FIX_INDIRECTION r10
cmp rcx, r10
else
cmp rcx, [rax + OFFSETOF__InterfaceInfo_t__m_pMethodTable]
endif
je Found
; move to next entry in list
dec r11w
jz DoBizarre
; unroll 1
ifdef FEATURE_PREJIT
mov r10, [rax + SIZEOF__InterfaceInfo_t + OFFSETOF__InterfaceInfo_t__m_pMethodTable]
FIX_INDIRECTION r10
cmp rcx, r10
else
cmp rcx, [rax + SIZEOF__InterfaceInfo_t + OFFSETOF__InterfaceInfo_t__m_pMethodTable]
endif
je Found
; move to next entry in list
dec r11w
jz DoBizarre
; unroll 2
ifdef FEATURE_PREJIT
mov r10, [rax + 2 * SIZEOF__InterfaceInfo_t + OFFSETOF__InterfaceInfo_t__m_pMethodTable]
FIX_INDIRECTION r10
cmp rcx, r10
else
cmp rcx, [rax + 2 * SIZEOF__InterfaceInfo_t + OFFSETOF__InterfaceInfo_t__m_pMethodTable]
endif
je Found
; move to next entry in list
dec r11w
jz DoBizarre
; unroll 3
ifdef FEATURE_PREJIT
mov r10, [rax + 3 * SIZEOF__InterfaceInfo_t + OFFSETOF__InterfaceInfo_t__m_pMethodTable]
FIX_INDIRECTION r10
cmp rcx, r10
else
cmp rcx, [rax + 3 * SIZEOF__InterfaceInfo_t + OFFSETOF__InterfaceInfo_t__m_pMethodTable]
endif
je Found
; move to next entry in list
dec r11w
jz DoBizarre
; if we didn't find the entry in this loop jump to the next 4 entries in the map
add rax, 4 * SIZEOF__InterfaceInfo_t
jmp Top
DoBizarre:
mov rax, [rdx]
test dword ptr [rax + OFFSETOF__MethodTable__m_dwFlags], METHODTABLE_NONTRIVIALINTERFACECAST_FLAGS
jnz NonTrivialCast
xor rax,rax
ret
align 16
Found:
IsNullInst:
; return the successful instance
mov rax, rdx
ret
NonTrivialCast:
jmp JITutil_IsInstanceOfInterface
LEAF_END JIT_IsInstanceOfInterface, _TEXT
; For all bizarre castes this quickly fails and falls back onto the JITutil_ChkCastInterface
; helper, this means that all failure cases take the slow path as well.
;
; This can trash r10/r11
LEAF_ENTRY JIT_ChkCastInterface, _TEXT
test rdx, rdx
jz IsNullInst
; get methodtable
mov rax, [rdx]
mov r11w, word ptr [rax + OFFSETOF__MethodTable__m_wNumInterfaces]
; speculatively fetch interface map ptr
mov rax, [rax + OFFSETOF__MethodTable__m_pInterfaceMap]
test r11w, r11w
jz DoBizarre
; r11 holds number of interfaces
; rax is pointer to beginning of interface map list
align 16
Top:
; rax -> InterfaceInfo_t* into the interface map, aligned to 4 entries
; use offsets of SIZEOF__InterfaceInfo_t to get at entry 1, 2, 3 in this
; block. If we make it through the full 4 without a hit we'll move to
; the next block of 4 and try again.
; unroll 0
ifdef FEATURE_PREJIT
mov r10, [rax + OFFSETOF__InterfaceInfo_t__m_pMethodTable]
FIX_INDIRECTION r10
cmp rcx, r10
else
cmp rcx, [rax + OFFSETOF__InterfaceInfo_t__m_pMethodTable]
endif
je Found
; move to next entry in list
dec r11w
jz DoBizarre
; unroll 1
ifdef FEATURE_PREJIT
mov r10, [rax + SIZEOF__InterfaceInfo_t + OFFSETOF__InterfaceInfo_t__m_pMethodTable]
FIX_INDIRECTION r10
cmp rcx, r10
else
cmp rcx, [rax + SIZEOF__InterfaceInfo_t + OFFSETOF__InterfaceInfo_t__m_pMethodTable]
endif
je Found
; move to next entry in list
dec r11w
jz DoBizarre
; unroll 2
ifdef FEATURE_PREJIT
mov r10, [rax + 2 * SIZEOF__InterfaceInfo_t + OFFSETOF__InterfaceInfo_t__m_pMethodTable]
FIX_INDIRECTION r10
cmp rcx, r10
else
cmp rcx, [rax + 2 * SIZEOF__InterfaceInfo_t + OFFSETOF__InterfaceInfo_t__m_pMethodTable]
endif
je Found
; move to next entry in list
dec r11w
jz DoBizarre
; unroll 3
ifdef FEATURE_PREJIT
mov r10, [rax + 3 * SIZEOF__InterfaceInfo_t + OFFSETOF__InterfaceInfo_t__m_pMethodTable]
FIX_INDIRECTION r10
cmp rcx, r10
else
cmp rcx, [rax + 3 * SIZEOF__InterfaceInfo_t + OFFSETOF__InterfaceInfo_t__m_pMethodTable]
endif
je Found
; move to next entry in list
dec r11w
jz DoBizarre
; if we didn't find the entry in this loop jump to the next 4 entries in the map
add rax, 4 * SIZEOF__InterfaceInfo_t
jmp Top
DoBizarre:
jmp JITutil_ChkCastInterface
align 16
Found:
IsNullInst:
; return either NULL or the successful instance
mov rax, rdx
ret
LEAF_END JIT_ChkCastInterface, _TEXT
; There is an even more optimized version of these helpers possible which takes
; advantage of knowledge of which way the ephemeral heap is growing to only do 1/2
; that check (this is more significant in the JIT_WriteBarrier case).
;
; Additionally we can look into providing helpers which will take the src/dest from
; specific registers (like x86) which _could_ (??) make for easier register allocation
; for the JIT64, however it might lead to having to have some nasty code that treats
; these guys really special like... :(.
;
; Version that does the move, checks whether or not it's in the GC and whether or not
; it needs to have it's card updated
;
; void JIT_CheckedWriteBarrier(Object** dst, Object* src)
LEAF_ENTRY JIT_CheckedWriteBarrier, _TEXT
; When WRITE_BARRIER_CHECK is defined _NotInHeap will write the reference
; but if it isn't then it will just return.
;
; See if this is in GCHeap
cmp rcx, [g_lowest_address]
jb NotInHeap
cmp rcx, [g_highest_address]
jnb NotInHeap
jmp JIT_WriteBarrier
NotInHeap:
; See comment above about possible AV
mov [rcx], rdx
ret
LEAF_END_MARKED JIT_CheckedWriteBarrier, _TEXT
; Mark start of the code region that we patch at runtime
LEAF_ENTRY JIT_PatchedCodeStart, _TEXT
ret
LEAF_END JIT_PatchedCodeStart, _TEXT
; This is used by the mechanism to hold either the JIT_WriteBarrier_PreGrow
; or JIT_WriteBarrier_PostGrow code (depending on the state of the GC). It _WILL_
; change at runtime as the GC changes. Initially it should simply be a copy of the
; larger of the two functions (JIT_WriteBarrier_PostGrow) to ensure we have created
; enough space to copy that code in.
LEAF_ENTRY JIT_WriteBarrier, _TEXT
align 16
ifdef _DEBUG
; In debug builds, this just contains jump to the debug version of the write barrier by default
jmp JIT_WriteBarrier_Debug
endif
ifdef FEATURE_USE_SOFTWARE_WRITE_WATCH_FOR_GC_HEAP
; JIT_WriteBarrier_WriteWatch_PostGrow64
; Regarding patchable constants:
; - 64-bit constants have to be loaded into a register
; - The constants have to be aligned to 8 bytes so that they can be patched easily
; - The constant loads have been located to minimize NOP padding required to align the constants
; - Using different registers for successive constant loads helps pipeline better. Should we decide to use a special
; non-volatile calling convention, this should be changed to use just one register.
; Do the move into the GC . It is correct to take an AV here, the EH code
; figures out that this came from a WriteBarrier and correctly maps it back
; to the managed method which called the WriteBarrier (see setup in
; InitializeExceptionHandling, vm\exceptionhandling.cpp).
mov [rcx], rdx
; Update the write watch table if necessary
mov rax, rcx
mov r8, 0F0F0F0F0F0F0F0F0h
shr rax, 0Ch ; SoftwareWriteWatch::AddressToTableByteIndexShift
NOP_2_BYTE ; padding for alignment of constant
mov r9, 0F0F0F0F0F0F0F0F0h
add rax, r8
cmp byte ptr [rax], 0h
jne CheckCardTable
mov byte ptr [rax], 0FFh
NOP_3_BYTE ; padding for alignment of constant
; Check the lower and upper ephemeral region bounds
CheckCardTable:
cmp rdx, r9
jb Exit
NOP_3_BYTE ; padding for alignment of constant
mov r8, 0F0F0F0F0F0F0F0F0h
cmp rdx, r8
jae Exit
nop ; padding for alignment of constant
mov rax, 0F0F0F0F0F0F0F0F0h
; Touch the card table entry, if not already dirty.
shr rcx, 0Bh
cmp byte ptr [rcx + rax], 0FFh
jne UpdateCardTable
REPRET
UpdateCardTable:
mov byte ptr [rcx + rax], 0FFh
ret
align 16
Exit:
REPRET
else
; JIT_WriteBarrier_PostGrow64
; Do the move into the GC . It is correct to take an AV here, the EH code
; figures out that this came from a WriteBarrier and correctly maps it back
; to the managed method which called the WriteBarrier (see setup in
; InitializeExceptionHandling, vm\exceptionhandling.cpp).
mov [rcx], rdx
NOP_3_BYTE ; padding for alignment of constant
; Can't compare a 64 bit immediate, so we have to move them into a
; register. Values of these immediates will be patched at runtime.
; By using two registers we can pipeline better. Should we decide to use
; a special non-volatile calling convention, this should be changed to
; just one.
mov rax, 0F0F0F0F0F0F0F0F0h
; Check the lower and upper ephemeral region bounds
cmp rdx, rax
jb Exit
nop ; padding for alignment of constant
mov r8, 0F0F0F0F0F0F0F0F0h
cmp rdx, r8
jae Exit
nop ; padding for alignment of constant
mov rax, 0F0F0F0F0F0F0F0F0h
; Touch the card table entry, if not already dirty.
shr rcx, 0Bh
cmp byte ptr [rcx + rax], 0FFh
jne UpdateCardTable
REPRET
UpdateCardTable:
mov byte ptr [rcx + rax], 0FFh
ret
align 16
Exit:
REPRET
endif
; make sure this guy is bigger than any of the other guys
align 16
nop
LEAF_END_MARKED JIT_WriteBarrier, _TEXT
; Mark start of the code region that we patch at runtime
LEAF_ENTRY JIT_PatchedCodeLast, _TEXT
ret
LEAF_END JIT_PatchedCodeLast, _TEXT
; JIT_ByRefWriteBarrier has weird symantics, see usage in StubLinkerX86.cpp
;
; Entry:
; RDI - address of ref-field (assigned to)
; RSI - address of the data (source)
; RCX is trashed
; RAX is trashed when FEATURE_USE_SOFTWARE_WRITE_WATCH_FOR_GC_HEAP is defined
; Exit:
; RDI, RSI are incremented by SIZEOF(LPVOID)
LEAF_ENTRY JIT_ByRefWriteBarrier, _TEXT
mov rcx, [rsi]
; If !WRITE_BARRIER_CHECK do the write first, otherwise we might have to do some ShadowGC stuff
ifndef WRITE_BARRIER_CHECK
; rcx is [rsi]
mov [rdi], rcx
endif
; When WRITE_BARRIER_CHECK is defined _NotInHeap will write the reference
; but if it isn't then it will just return.
;
; See if this is in GCHeap
cmp rdi, [g_lowest_address]
jb NotInHeap
cmp rdi, [g_highest_address]
jnb NotInHeap
ifdef WRITE_BARRIER_CHECK
; we can only trash rcx in this function so in _DEBUG we need to save
; some scratch registers.
push r10
push r11
push rax
; **ALSO update the shadow GC heap if that is enabled**
; Do not perform the work if g_GCShadow is 0
cmp g_GCShadow, 0
je NoShadow
; If we end up outside of the heap don't corrupt random memory
mov r10, rdi
sub r10, [g_lowest_address]
jb NoShadow
; Check that our adjusted destination is somewhere in the shadow gc
add r10, [g_GCShadow]
cmp r10, [g_GCShadowEnd]
ja NoShadow
; Write ref into real GC
mov [rdi], rcx
; Write ref into shadow GC
mov [r10], rcx
; Ensure that the write to the shadow heap occurs before the read from
; the GC heap so that race conditions are caught by INVALIDGCVALUE
mfence
; Check that GC/ShadowGC values match
mov r11, [rdi]
mov rax, [r10]
cmp rax, r11
je DoneShadow
mov r11, INVALIDGCVALUE
mov [r10], r11
jmp DoneShadow
; If we don't have a shadow GC we won't have done the write yet
NoShadow:
mov [rdi], rcx
; If we had a shadow GC then we already wrote to the real GC at the same time
; as the shadow GC so we want to jump over the real write immediately above.
; Additionally we know for sure that we are inside the heap and therefore don't
; need to replicate the above checks.
DoneShadow:
pop rax
pop r11
pop r10
endif
ifdef FEATURE_USE_SOFTWARE_WRITE_WATCH_FOR_GC_HEAP
; Update the write watch table if necessary
cmp byte ptr [g_sw_ww_enabled_for_gc_heap], 0h
je CheckCardTable
mov rax, rdi
shr rax, 0Ch ; SoftwareWriteWatch::AddressToTableByteIndexShift
add rax, qword ptr [g_sw_ww_table]
cmp byte ptr [rax], 0h
jne CheckCardTable
mov byte ptr [rax], 0FFh
endif
; See if we can just quick out
CheckCardTable:
cmp rcx, [g_ephemeral_low]
jb Exit
cmp rcx, [g_ephemeral_high]
jnb Exit
; move current rdi value into rcx and then increment the pointers
mov rcx, rdi
add rsi, 8h
add rdi, 8h
; Check if we need to update the card table
; Calc pCardByte
shr rcx, 0Bh
add rcx, [g_card_table]
; Check if this card is dirty
cmp byte ptr [rcx], 0FFh
jne UpdateCardTable
REPRET
UpdateCardTable:
mov byte ptr [rcx], 0FFh
ret
align 16
NotInHeap:
; If WRITE_BARRIER_CHECK then we won't have already done the mov and should do it here
; If !WRITE_BARRIER_CHECK we want _NotInHeap and _Leave to be the same and have both
; 16 byte aligned.
ifdef WRITE_BARRIER_CHECK
; rcx is [rsi]
mov [rdi], rcx
endif
Exit:
; Increment the pointers before leaving
add rdi, 8h
add rsi, 8h
ret
LEAF_END_MARKED JIT_ByRefWriteBarrier, _TEXT
g_pObjectClass equ ?g_pObjectClass@@3PEAVMethodTable@@EA
EXTERN g_pObjectClass:qword
extern ArrayStoreCheck:proc
extern ObjIsInstanceOfNoGC:proc
; TODO: put definition for this in asmconstants.h
CanCast equ 1
;__declspec(naked) void F_CALL_CONV JIT_Stelem_Ref(PtrArray* array, unsigned idx, Object* val)
LEAF_ENTRY JIT_Stelem_Ref, _TEXT
; check for null PtrArray*
test rcx, rcx
je ThrowNullReferenceException
; we only want the lower 32-bits of edx, it might be dirty
or edx, edx
; check that index is in bounds
cmp edx, dword ptr [rcx + OFFSETOF__PtrArray__m_NumComponents] ; 8h -> array size offset
jae ThrowIndexOutOfRangeException
; r10 = Array MT
mov r10, [rcx]
; if we're assigning a null object* then we don't need a write barrier
test r8, r8
jz AssigningNull
mov r9, [r10 + OFFSETOF__MethodTable__m_ElementType] ; 10h -> typehandle offset
; check for exact match
cmp r9, [r8]
jne NotExactMatch
DoWrite:
lea rcx, [rcx + 8*rdx + OFFSETOF__PtrArray__m_Array]
mov rdx, r8
; JIT_WriteBarrier(Object** dst, Object* src)
jmp JIT_WriteBarrier
AssigningNull:
; write barrier is not needed for assignment of NULL references
mov [rcx + 8*rdx + OFFSETOF__PtrArray__m_Array], r8
ret
NotExactMatch:
cmp r9, [g_pObjectClass]
je DoWrite
jmp JIT_Stelem_Ref__ObjIsInstanceOfNoGC_Helper
ThrowNullReferenceException:
mov rcx, CORINFO_NullReferenceException_ASM
jmp JIT_InternalThrow
ThrowIndexOutOfRangeException:
mov rcx, CORINFO_IndexOutOfRangeException_ASM
jmp JIT_InternalThrow
LEAF_END JIT_Stelem_Ref, _TEXT
NESTED_ENTRY JIT_Stelem_Ref__ObjIsInstanceOfNoGC_Helper, _TEXT
alloc_stack MIN_SIZE
save_reg_postrsp rcx, MIN_SIZE + 8h
save_reg_postrsp rdx, MIN_SIZE + 10h
save_reg_postrsp r8, MIN_SIZE + 18h
END_PROLOGUE
; need to get TypeHandle before setting rcx to be the Obj* because that trashes the PtrArray*
mov rdx, r9
mov rcx, r8
; TypeHandle::CastResult ObjIsInstanceOfNoGC(Object *pElement, TypeHandle toTypeHnd)
call ObjIsInstanceOfNoGC
mov rcx, [rsp + MIN_SIZE + 8h]
mov rdx, [rsp + MIN_SIZE + 10h]
mov r8, [rsp + MIN_SIZE + 18h]
cmp eax, CanCast
jne NeedCheck
lea rcx, [rcx + 8*rdx + OFFSETOF__PtrArray__m_Array]
mov rdx, r8
add rsp, MIN_SIZE
; JIT_WriteBarrier(Object** dst, Object* src)
jmp JIT_WriteBarrier
NeedCheck:
add rsp, MIN_SIZE
jmp JIT_Stelem_Ref__ArrayStoreCheck_Helper
NESTED_END JIT_Stelem_Ref__ObjIsInstanceOfNoGC_Helper, _TEXT
; Need to save r8 to provide a stack address for the Object*
NESTED_ENTRY JIT_Stelem_Ref__ArrayStoreCheck_Helper, _TEXT
alloc_stack MIN_SIZE
save_reg_postrsp rcx, MIN_SIZE + 8h
save_reg_postrsp rdx, MIN_SIZE + 10h
save_reg_postrsp r8, MIN_SIZE + 18h
END_PROLOGUE
lea rcx, [rsp + MIN_SIZE + 18h]
lea rdx, [rsp + MIN_SIZE + 8h]
; HCIMPL2(FC_INNER_RET, ArrayStoreCheck, Object** pElement, PtrArray** pArray)
call ArrayStoreCheck
mov rcx, [rsp + MIN_SIZE + 8h]
mov rdx, [rsp + MIN_SIZE + 10h]
mov r8, [rsp + MIN_SIZE + 18h]
lea rcx, [rcx + 8*rdx + OFFSETOF__PtrArray__m_Array]
mov rdx, r8
add rsp, MIN_SIZE
; JIT_WriteBarrier(Object** dst, Object* src)
jmp JIT_WriteBarrier
NESTED_END JIT_Stelem_Ref__ArrayStoreCheck_Helper, _TEXT
extern JIT_FailFast:proc
extern s_gsCookie:qword
OFFSETOF_GSCOOKIE equ 0h
OFFSETOF_FRAME equ OFFSETOF_GSCOOKIE + \
8h
;
; incoming:
;
; rsp -> return address
; :
;
; Stack Layout:
;
; rsp-> callee scratch
; + 8h callee scratch
; +10h callee scratch
; +18h callee scratch
; :
; stack arguments
; :
; r13-> gsCookie
; + 8h __VFN_table
; +10h m_Next
; +18h m_pGCLayout
; +20h m_padding
; +28h m_rdi
; +30h m_rsi
; +38h m_rbx
; +40h m_rbp
; +48h m_r12
; +50h m_r13
; +58h m_r14
; +60h m_r15
; +68h m_ReturnAddress
; r12 -> // Caller's SP
;
; r14 = GetThread();
; r15 = GetThread()->GetFrame(); // For restoring/popping the frame
;
NESTED_ENTRY TailCallHelperStub, _TEXT
PUSH_CALLEE_SAVED_REGISTERS
alloc_stack 48h ; m_padding, m_pGCLayout, m_Next, __VFN_table, gsCookie, outgoing shadow area
set_frame r13, 20h
END_PROLOGUE
;
; This part is never executed, but we keep it here for reference
;
int 3
if 0 ne 0
; Save the caller's SP
mov r12, rsp + ...
;
; fully initialize the TailCallFrame
;
call TCF_GETMETHODFRAMEVPTR
mov [r13 + OFFSETOF_FRAME], rax
mov rax, s_gsCookie
mov [r13 + OFFSETOF_GSCOOKIE], rax
;
; link the TailCallFrame
;
INLINE_GETTHREAD r14
mov r15, [r14 + OFFSETOF__Thread__m_pFrame]
mov [r13 + OFFSETOF_FRAME + OFFSETOF__Frame__m_Next], r15
lea r10, [r13 + OFFSETOF_FRAME]
mov [r14 + OFFSETOF__Thread__m_pFrame], r10
endif
; the pretend call would be here
; with the return address pointing this this real epilog
PATCH_LABEL JIT_TailCallHelperStub_ReturnAddress
; our epilog (which also unlinks the TailCallFrame)
ifdef _DEBUG
mov rcx, s_gsCookie
cmp [r13 + OFFSETOF_GSCookie], rcx
je GoodGSCookie
call JIT_FailFast
GoodGSCookie:
endif ; _DEBUG
;
; unlink the TailCallFrame
;
mov [r14 + OFFSETOF__Thread__m_pFrame], r15
;
; epilog
;
lea rsp, [r13 + 28h]
POP_CALLEE_SAVED_REGISTERS
ret
NESTED_END TailCallHelperStub, _TEXT
; The following helper will access ("probe") a word on each page of the stack
; starting with the page right beneath rsp down to the one pointed to by r11.
; The procedure is needed to make sure that the "guard" page is pushed down below the allocated stack frame.
; The call to the helper will be emitted by JIT in the function/funclet prolog when large (larger than 0x3000 bytes) stack frame is required.
;
; NOTE: this helper will NOT modify a value of rsp and can be defined as a leaf function.
PAGE_SIZE equ 1000h
LEAF_ENTRY JIT_StackProbe, _TEXT
; On entry:
; r11 - points to the lowest address on the stack frame being allocated (i.e. [InitialSp - FrameSize])
; rsp - points to some byte on the last probed page
; On exit:
; rax - is not preserved
; r11 - is preserved
;
; NOTE: this helper will probe at least one page below the one pointed by rsp.
lea rax, [rsp - PAGE_SIZE] ; rax points to some byte on the first unprobed page
or rax, (PAGE_SIZE - 1) ; rax points to the **highest address** on the first unprobed page
; This is done to make the following loop end condition simpler.
ProbeLoop:
test dword ptr [rax], eax
sub rax, PAGE_SIZE ; rax points to the highest address of the **next page** to probe
cmp rax, r11
jge ProbeLoop ; if (rax >= r11), then we need to probe the page pointed to by rax.
ret
LEAF_END JIT_StackProbe, _TEXT
end
|
#include "base.hpp"
namespace {
struct lk_node {
int data;
lk_node* next;
lk_node* child;
lk_node(int val) : data(val), next(nullptr), child(nullptr) {}
lk_node(int val, lk_node* chd) : data(val), next(nullptr), child(chd) {}
~lk_node() {
delete next;
delete child;
}
};
lk_node* populate(const std::vector<int>& samples) {
lk_node* root = nullptr;
return root;
}
lk_node* tail(lk_node* head) {
lk_node* current = head;
while (current && current->next) {
current = current->next;
}
return current;
}
lk_node* flatten(lk_node* head) {
lk_node* current = head;
while (current) {
if (current->child) {
lk_node* flat_child_list = flatten(current->child);
lk_node* flat_child_list_tail = tail(flat_child_list);
flat_child_list_tail->next = current->next;
current->next = flat_child_list;
current = flat_child_list_tail->next;
} else {
current = current->next;
}
}
return head;
}
} // namespace
/**
* @brief A link list node could store the normal data and a pointer may/maynot point to another linked_list.
* The goal is flattern the given link list into a link list that only contains normal data.
* Note: the nested/child linked list could also has nested multiple levels. We should recursively flatten
the child node using divide and conquer.
*/
TEST_CASE("flatten_nested_link_list", "[link_list]") {}
/**
* @brief A link list node could store the normal data and a pointer may/maynot point to another linked_list.
* The goal is flattern the given link list into a link list level by level. Level 0 first and then
* second level, ..., etc.
* Note: the nested/child linked list could also has nested multiple levels. We should recursively flatten
the child node using divide and conquer.
*/
TEST_CASE("flatten_nested_link_list_level_by_level", "[link_list]") {}
|
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "LmbrCentral_precompiled.h"
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Component/ComponentApplicationBus.h>
#include <AzCore/Math/Transform.h>
#include <AzCore/Component/Entity.h>
#include <AzCore/RTTI/BehaviorContext.h>
#include <AzCore/Component/TickBus.h>
#include <MathConversion.h>
#include <AzFramework/Entity/GameEntityContextBus.h>
#include <AzFramework/Network/NetBindingSystemBus.h>
#include <AzFramework/Network/NetworkContext.h>
#include <GridMate/Replica/ReplicaChunk.h>
#include <GridMate/Replica/ReplicaFunctions.h>
#include <GridMate/Replica/RemoteProcedureCall.h>
#include <GridMate/Serialize/MarshalerTypes.h>
#include <GridMate/Serialize/MathMarshal.h>
#include <GridMate/Serialize/DataMarshal.h>
#include <GridMate/Serialize/ContainerMarshal.h>
#include "TriggerAreaComponent.h"
#include <LmbrCentral/Shape/ShapeComponentBus.h>
#include <IRenderAuxGeom.h>
#include <IActorSystem.h>
namespace LmbrCentral
{
// BehaviorContext TriggerAreaNotificationBus forwarder
class BehaviorTriggerAreaNotificationBusHandler : public TriggerAreaNotificationBus::Handler, public AZ::BehaviorEBusHandler
{
public:
AZ_EBUS_BEHAVIOR_BINDER(BehaviorTriggerAreaNotificationBusHandler, "{D3C88952-AA9A-48AA-8C2C-9011020A6AEA}", AZ::SystemAllocator,
OnTriggerAreaEntered, OnTriggerAreaExited);
void OnTriggerAreaEntered(AZ::EntityId id)
{
Call(FN_OnTriggerAreaEntered, id);
}
void OnTriggerAreaExited(AZ::EntityId id)
{
Call(FN_OnTriggerAreaExited, id);
}
};
// BehaviorContext TriggerAreaEntityNotificationBus forwarder
class BehaviorTriggerAreaEntityNotificationBusHandler : public TriggerAreaEntityNotificationBus::Handler, public AZ::BehaviorEBusHandler
{
public:
AZ_EBUS_BEHAVIOR_BINDER(BehaviorTriggerAreaEntityNotificationBusHandler,"{4CCF51B5-DF0A-436F-97BD-9EF208D17CC8}", AZ::SystemAllocator,
OnEntityEnteredTriggerArea, OnEntityExitedTriggerArea);
void OnEntityEnteredTriggerArea(AZ::EntityId id)
{
Call(FN_OnEntityEnteredTriggerArea, id);
}
void OnEntityExitedTriggerArea(AZ::EntityId id)
{
Call(FN_OnEntityExitedTriggerArea, id);
}
};
//=========================================================================
// ReplicaChunk
//=========================================================================
class TriggerAreaReplicaChunk : public GridMate::ReplicaChunkBase
{
public:
AZ_CLASS_ALLOCATOR(TriggerAreaReplicaChunk, AZ::SystemAllocator, 0);
static const char* GetChunkName() { return "TriggerAreaChunk"; }
TriggerAreaReplicaChunk()
: OnAreaEnter("OnAreaEnter")
, OnAreaExit("OnAreaExit")
{
}
bool IsReplicaMigratable() override
{
return true;
}
void OnReplicaChangeOwnership(const GridMate::ReplicaContext& /*rc*/) override
{
TriggerAreaComponent* triggerAreaComponent = static_cast<TriggerAreaComponent*>(GetHandler());
if (triggerAreaComponent)
{
triggerAreaComponent->EnforceProximityTriggerState();
}
}
GridMate::Rpc< GridMate::RpcArg<AZ::u64> >::BindInterface<TriggerAreaComponent,&TriggerAreaComponent::OnEntityEnterAreaRPC> OnAreaEnter;
GridMate::Rpc< GridMate::RpcArg<AZ::u64> >::BindInterface<TriggerAreaComponent,&TriggerAreaComponent::OnEntityExitAreaRPC> OnAreaExit;
// Only used to pass along the initial set, after that all of the enter/exits will take care of updating the list.
AZStd::vector< AZ::u64 > m_initialEntitiesInArea;
};
class TriggerAreaReplicaChunkDesc : public AzFramework::ExternalChunkDescriptor<TriggerAreaReplicaChunk>
{
public:
GridMate::ReplicaChunkBase* CreateFromStream(GridMate::UnmarshalContext& context) override
{
TriggerAreaReplicaChunk* triggerAreaChunk = aznew TriggerAreaReplicaChunk;
AZStd::vector<AZ::u64> initialEntitiesInArea;
context.m_iBuf->Read(initialEntitiesInArea);
triggerAreaChunk->m_initialEntitiesInArea.reserve(initialEntitiesInArea.size());
for (AZ::u64 entityId : initialEntitiesInArea)
{
triggerAreaChunk->m_initialEntitiesInArea.push_back(entityId);
}
return triggerAreaChunk;
}
void DiscardCtorStream(GridMate::UnmarshalContext& context) override
{
AZStd::vector< AZ::u64 > discard;
context.m_iBuf->Read(discard);
}
void MarshalCtorData(GridMate::ReplicaChunkBase* chunk, GridMate::WriteBuffer& wb) override
{
TriggerAreaReplicaChunk* triggerAreaChunk = static_cast<TriggerAreaReplicaChunk*>(chunk);
TriggerAreaComponent* triggerAreaComponent = static_cast<TriggerAreaComponent*>(chunk->GetHandler());
if (triggerAreaComponent)
{
AZStd::vector< AZ::u64 > entitiesInside;
entitiesInside.reserve(triggerAreaComponent->m_entitiesInside.size());
for (AZ::EntityId entityId : triggerAreaComponent->m_entitiesInside)
{
AZ::u64 writableId = static_cast<AZ::u64>(entityId);
entitiesInside.push_back(writableId);
}
wb.Write(entitiesInside);
}
else
{
wb.Write(triggerAreaChunk->m_initialEntitiesInArea);
}
}
void DeleteReplicaChunk(GridMate::ReplicaChunkBase* replica)
{
delete replica;
}
};
//=========================================================================
// Reflect
//=========================================================================
void TriggerAreaComponent::Reflect(AZ::ReflectContext* context)
{
AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context);
if (serialize)
{
serialize->Class<TriggerAreaComponent, AZ::Component, AzFramework::NetBindable>()
->Version(2)
->Field("TriggerOnce", &TriggerAreaComponent::m_triggerOnce)
->Field("ActivatedBy", &TriggerAreaComponent::m_activationEntityType)
->Field("SpecificInteractEntities", &TriggerAreaComponent::m_specificInteractEntities)
->Field("RequiredTags", &TriggerAreaComponent::m_requiredTags)
->Field("ExcludedTags", &TriggerAreaComponent::m_excludedTags);
}
AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context);
if (behaviorContext)
{
behaviorContext->EBus<TriggerAreaRequestsBus>("TriggerAreaRequestsBus")
->Event("AddRequiredTag", &TriggerAreaRequestsBus::Events::AddRequiredTag)
->Event("RemoveRequiredTag", &TriggerAreaRequestsBus::Events::RemoveRequiredTag)
->Event("AddExcludedTag", &TriggerAreaRequestsBus::Events::AddExcludedTag)
->Event("RemoveExcludedTag", &TriggerAreaRequestsBus::Events::RemoveExcludedTag)
->Event("GetEntitiesInside", &TriggerAreaRequestsBus::Events::GetEntitiesInside)
;
behaviorContext->EBus<TriggerAreaNotificationBus>("TriggerAreaNotificationBus")
->Handler<BehaviorTriggerAreaNotificationBusHandler>();
behaviorContext->EBus<TriggerAreaEntityNotificationBus>("TriggerAreaEntityNotificationBus")
->Handler<BehaviorTriggerAreaEntityNotificationBusHandler>();
}
AzFramework::NetworkContext* netContext = azrtti_cast<AzFramework::NetworkContext*>(context);
if (netContext)
{
netContext->Class<TriggerAreaComponent>()
->Chunk<TriggerAreaReplicaChunk,TriggerAreaReplicaChunkDesc>()
->RPC<TriggerAreaReplicaChunk, TriggerAreaComponent>("OnAreaEnter",&TriggerAreaReplicaChunk::OnAreaEnter)
->RPC<TriggerAreaReplicaChunk, TriggerAreaComponent>("OnAreaExit",&TriggerAreaReplicaChunk::OnAreaExit);
}
}
//=========================================================================
// Constructor
//=========================================================================
TriggerAreaComponent::TriggerAreaComponent()
: m_activationEntityType(ActivationEntityType::AllEntities)
, m_triggerOnce(false)
, m_proximityTrigger(nullptr)
, m_replicaChunk(nullptr)
{
}
//=========================================================================
// Activate
//=========================================================================
void TriggerAreaComponent::Activate()
{
if (!IsNetworkControlled())
{
EnforceProximityTriggerState();
TriggerAreaRequestsBus::Handler::BusConnect(GetEntityId());
}
}
void TriggerAreaComponent::CreateProximityTrigger()
{
AZ_Error("TriggerAreaComponent", m_proximityTrigger == nullptr, "Creating two proximity triggers to TriggerAreaComponent on Entity(%s)", GetEntity()->GetName().c_str());
if (m_proximityTrigger == nullptr)
{
AZ::Transform entityTransform = AZ::Transform::CreateIdentity();
EBUS_EVENT_ID_RESULT(entityTransform, GetEntityId(), AZ::TransformBus, GetWorldTM);
// Create an entry in the proximity trigger system.
EBUS_EVENT_RESULT(m_proximityTrigger, ProximityTriggerSystemRequestBus, CreateTrigger, AZStd::bind(&TriggerAreaComponent::NarrowPassCheck, this, AZStd::placeholders::_1));
AZ_Assert(m_proximityTrigger, "Failed to create proximity trigger.");
m_proximityTrigger->id = GetEntityId();
UpdateTriggerArea();
ProximityTriggerEventBus::Handler::BusConnect(GetEntityId());
ShapeComponentNotificationsBus::Handler::BusConnect(GetEntityId());
}
}
//=========================================================================
// UpdateTriggerArea
//=========================================================================
void TriggerAreaComponent::UpdateTriggerArea()
{
AZ::Aabb encompassingAABB;
EBUS_EVENT_ID_RESULT(encompassingAABB, GetEntityId(), ShapeComponentRequestsBus, GetEncompassingAabb);
m_cachedAABB = AZAabbToLyAABB(encompassingAABB);
EBUS_EVENT(ProximityTriggerSystemRequestBus, MoveTrigger, m_proximityTrigger, m_cachedAABB, false);
}
//=========================================================================
// Deactivate
//=========================================================================
void TriggerAreaComponent::Deactivate()
{
TriggerAreaRequestsBus::Handler::BusDisconnect();
AZ::TickBus::Handler::BusDisconnect();
RemoveProximityTrigger();
}
bool TriggerAreaComponent::AddRequiredTagInternal(const Tag& requiredTag)
{
bool isTagExcluded = (m_excludedTags.end() != AZStd::find(m_excludedTags.begin(), m_excludedTags.end(), requiredTag));
AZ_Warning("TriggerAreaComponent", !isTagExcluded, "Required tag is already Excluded");
if (!isTagExcluded)
{
m_requiredTags.push_back(requiredTag);
}
return !isTagExcluded;
}
void TriggerAreaComponent::AddRequiredTag(const Tag& requiredTag)
{
if (AddRequiredTagInternal(requiredTag))
{
ReevaluateTagsAllEntities();
}
}
void TriggerAreaComponent::RemoveRequiredTag(const Tag& requiredTag)
{
const auto& requiredTagIter = AZStd::find(m_requiredTags.begin(), m_requiredTags.end(), requiredTag);
bool isTagRequired = (m_requiredTags.end() != requiredTagIter);
AZ_Warning("TriggerAreaComponent", isTagRequired, "No such tag is required %i", requiredTag);
if (isTagRequired)
{
m_requiredTags.erase(requiredTagIter);
ReevaluateTagsAllEntities();
}
}
bool TriggerAreaComponent::AddExcludedTagInternal(const Tag& excludedTag)
{
bool isTagRequired = (m_requiredTags.end() != AZStd::find(m_requiredTags.begin(), m_requiredTags.end(), excludedTag));
AZ_Warning("TriggerAreaComponent", !isTagRequired, "Excluded tag is already Required");
if (!isTagRequired)
{
m_excludedTags.push_back(excludedTag);
}
return !isTagRequired;
}
void TriggerAreaComponent::AddExcludedTag(const Tag& excludedTag)
{
if (AddExcludedTagInternal(excludedTag))
{
ReevaluateTagsAllEntities();
}
}
void TriggerAreaComponent::RemoveExcludedTag(const Tag& excludedTag)
{
const auto& excludedTagIter = AZStd::find(m_excludedTags.begin(), m_excludedTags.end(), excludedTag);
bool isTagExcluded = (m_excludedTags.end() != excludedTagIter);
AZ_Warning("TriggerAreaComponent", isTagExcluded, "No such tag is excluded %i", excludedTag);
if (isTagExcluded)
{
m_excludedTags.erase(excludedTagIter);
ReevaluateTagsAllEntities();
}
}
void TriggerAreaComponent::OnTick(float deltaTime, AZ::ScriptTimePoint)
{
TriggerAreaReplicaChunk* triggerAreaReplicaChunk = static_cast<TriggerAreaReplicaChunk*>(m_replicaChunk.get());
for (AZ::u64 entityId : triggerAreaReplicaChunk->m_initialEntitiesInArea)
{
OnTriggerEnterImpl(AZ::EntityId(entityId));
}
triggerAreaReplicaChunk->m_initialEntitiesInArea.clear();
AZ::TickBus::Handler::BusDisconnect();
}
void TriggerAreaComponent::OnTransformChanged(const AZ::Transform& /*parentLocalTM*/, const AZ::Transform& /*parentWorldTM*/)
{
UpdateTriggerArea();
}
void TriggerAreaComponent::RemoveProximityTrigger()
{
if (m_proximityTrigger)
{
ProximityTriggerEventBus::Handler::BusDisconnect();
ShapeComponentNotificationsBus::Handler::BusDisconnect();
EBUS_EVENT(ProximityTriggerSystemRequestBus, RemoveTrigger, m_proximityTrigger);
m_proximityTrigger = nullptr;
m_entitiesInside.clear();
}
}
//=========================================================================
// OnTriggerEnter
//=========================================================================
void TriggerAreaComponent::OnTriggerEnter(AZ::EntityId entityId)
{
AZ_Error("TriggerAreaComponent", !IsNetworkControlled(), "OnTriggerEnter being called on a proxy TriggerAreaComponent for Entity(%s).", GetEntity()->GetName().c_str());
if (!IsNetworkControlled())
{
bool result = OnTriggerEnterImpl(entityId);
if (result && m_replicaChunk && m_replicaChunk->IsMaster())
{
static_cast<TriggerAreaReplicaChunk*>(m_replicaChunk.get())->OnAreaEnter(static_cast<AZ::u64>(entityId));
}
}
}
bool TriggerAreaComponent::OnTriggerEnterImpl(AZ::EntityId entityId)
{
bool retVal = false;
FilteringResult result = EntityPassesFilters(entityId);
if (result == FilteringResult::Pass)
{
retVal = true;
if (m_entitiesInside.end() == AZStd::find(m_entitiesInside.begin(), m_entitiesInside.end(), entityId))
{
EBUS_EVENT_ID(GetEntityId(), TriggerAreaNotificationBus, OnTriggerAreaEntered, entityId);
EBUS_EVENT_ID(entityId, TriggerAreaEntityNotificationBus, OnEntityEnteredTriggerArea, GetEntityId());
HandleEnter();
m_entitiesInside.push_back(entityId);
}
}
if (result == FilteringResult::FailWithPossibilityOfChange || result == FilteringResult::Pass)
{
TagComponentNotificationsBus::MultiHandler::BusConnect(entityId);
}
return retVal;
}
//=========================================================================
// OnTriggerExit
//=========================================================================
void TriggerAreaComponent::OnTriggerExit(AZ::EntityId entityId)
{
AZ_Error("TriggerAreaComponent", !IsNetworkControlled(), "OnTriggerExit being called on a proxy TriggerAreaComponent for Entity(%s).", GetEntity()->GetName().c_str());
if (!IsNetworkControlled())
{
bool result = OnTriggerExitImpl(entityId);
if (result && m_replicaChunk && m_replicaChunk->IsMaster())
{
static_cast<TriggerAreaReplicaChunk*>(m_replicaChunk.get())->OnAreaExit(static_cast<AZ::u64>(entityId));
}
}
}
bool TriggerAreaComponent::OnTriggerExitImpl(AZ::EntityId entityId)
{
bool retVal = false;
auto foundIter = AZStd::find(m_entitiesInside.begin(), m_entitiesInside.end(), entityId);
if (foundIter != m_entitiesInside.end())
{
m_entitiesInside.erase(foundIter);
retVal = true;
EBUS_EVENT_ID(GetEntityId(), TriggerAreaNotificationBus, OnTriggerAreaExited, entityId);
EBUS_EVENT_ID(entityId, TriggerAreaEntityNotificationBus, OnEntityExitedTriggerArea, GetEntityId());
}
auto excludedEntityIter = AZStd::find(m_entitiesInsideExcludedByTags.begin(), m_entitiesInsideExcludedByTags.end(), entityId);
if (excludedEntityIter != m_entitiesInsideExcludedByTags.end())
{
m_entitiesInsideExcludedByTags.erase(excludedEntityIter);
}
TagComponentNotificationsBus::MultiHandler::BusDisconnect(entityId);
return retVal;
}
//=========================================================================
// DebugDraw
//=========================================================================
void TriggerAreaComponent::DebugDraw() const
{
gEnv->pRenderer->GetIRenderAuxGeom()->DrawAABB(m_cachedAABB ,false ,m_entitiesInside.empty() ? Col_LightGray : Col_Green, eBBD_Faceted);
}
//=========================================================================
// HandleEnter
//=========================================================================
void TriggerAreaComponent::HandleEnter()
{
if (m_entitiesInside.size() == 0) // First one in
{
if (m_triggerOnce)
{
Deactivate();
}
}
}
//=========================================================================
// EntityPassesFilters
//=========================================================================
TriggerAreaComponent::FilteringResult TriggerAreaComponent::EntityPassesFilters(AZ::EntityId id) const
{
bool result = false;
switch (m_activationEntityType)
{
case ActivationEntityType::AllEntities:
{
result = true;
break;
}
case ActivationEntityType::SpecificEntities:
{
auto foundIter = AZStd::find(m_specificInteractEntities.begin(), m_specificInteractEntities.end(), id);
result = foundIter != m_specificInteractEntities.end();
break;
}
}
if (!result)
{
return FilteringResult::FailWithoutPossibilityOfChange;
}
if (result)
{
for (const Tag& requiredTag : m_requiredTags)
{
result = false;
EBUS_EVENT_ID_RESULT(result, id, TagComponentRequestBus, HasTag, requiredTag);
if (!result)
{
break;
}
}
}
if (result && LmbrCentral::TagComponentRequestBus::FindFirstHandler(id))
{
for (const Tag& requiredTag : m_excludedTags)
{
result = true;
EBUS_EVENT_ID_RESULT(result, id, TagComponentRequestBus, HasTag, requiredTag);
result = !result;
if (!result)
{
break;
}
}
}
if (!result)
{
return FilteringResult::FailWithPossibilityOfChange;
}
else
{
return FilteringResult::Pass;
}
}
//=========================================================================
// IsPlayer
//=========================================================================
bool TriggerAreaComponent::IsPlayer(AZ::EntityId entityId)
{
// We don't yet have a way to create player actors in AZ::Entity/Components,
// so check legacy code paths.
if (IsLegacyEntityId(entityId))
{
const /*Cry*/ EntityId id = GetLegacyEntityId(entityId);
IActor* actor = gEnv->pGame && gEnv->pGame->GetIGameFramework() ? gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(id) : nullptr;
if (actor && actor->GetChannelId() != kInvalidChannelId)
{
return true;
}
}
return false;
}
//=========================================================================
// IsLocalPlayer
//=========================================================================
bool TriggerAreaComponent::IsLocalPlayer(AZ::EntityId entityId)
{
// We don't yet have a way to create player actors in AZ::Entity/Components,
// so check legacy code paths.
if (IsLegacyEntityId(entityId) && gEnv->pGame)
{
const /*Cry*/ EntityId id = GetLegacyEntityId(entityId);
return (id == gEnv->pGame->GetClientActorId());
}
return false;
}
bool TriggerAreaComponent::IsNetworkControlled() const
{
return m_replicaChunk != nullptr && m_replicaChunk->IsActive() && m_replicaChunk->IsProxy();
}
GridMate::ReplicaChunkPtr TriggerAreaComponent::GetNetworkBinding()
{
TriggerAreaReplicaChunk* replicaChunk = GridMate::CreateReplicaChunk<TriggerAreaReplicaChunk>();
replicaChunk->SetHandler(this);
m_replicaChunk = replicaChunk;
return m_replicaChunk;
}
void TriggerAreaComponent::SetNetworkBinding(GridMate::ReplicaChunkPtr chunk)
{
chunk->SetHandler(this);
m_replicaChunk = chunk;
EnforceProximityTriggerState();
AZ::TickBus::Handler::BusConnect();
}
void TriggerAreaComponent::UnbindFromNetwork()
{
m_replicaChunk->SetHandler(nullptr);
m_replicaChunk = nullptr;
EnforceProximityTriggerState();
}
bool TriggerAreaComponent::OnEntityEnterAreaRPC(AZ::u64 entityId, const GridMate::RpcContext& rpcContext)
{
bool allowTrigger = false;
if (IsNetworkControlled())
{
OnTriggerEnterImpl(AZ::EntityId(entityId));
}
else if (!m_entitiesInside.empty())
{
allowTrigger = (m_entitiesInside.back() == AZ::EntityId(entityId));
}
return allowTrigger;
}
bool TriggerAreaComponent::OnEntityExitAreaRPC(AZ::u64 entityId, const GridMate::RpcContext& rpcContext)
{
if (IsNetworkControlled())
{
OnTriggerExitImpl(AZ::EntityId(entityId));
}
return true;
}
void TriggerAreaComponent::EnforceProximityTriggerState()
{
if (IsNetworkControlled())
{
if (m_proximityTrigger)
{
RemoveProximityTrigger();
}
}
else if (m_proximityTrigger == nullptr)
{
CreateProximityTrigger();
}
}
bool TriggerAreaComponent::NarrowPassCheck(const AZ::Vector3& position) const
{
bool isPointInside = false;
EBUS_EVENT_ID_RESULT(isPointInside, GetEntityId(), ShapeComponentRequestsBus, IsPointInside, position);
return isPointInside;
}
void TriggerAreaComponent::OnShapeChanged(ShapeComponentNotifications::ShapeChangeReasons changeReason)
{
(void)changeReason;
UpdateTriggerArea();
}
void TriggerAreaComponent::ReevaluateTagsAllEntities()
{
for (const AZ::EntityId& entityInside : m_entitiesInside)
{
HandleTagChange(entityInside);
}
for (const AZ::EntityId& entityInside : m_entitiesInsideExcludedByTags)
{
HandleTagChange(entityInside);
}
}
void TriggerAreaComponent::HandleTagChange(const AZ::EntityId& entityId)
{
FilteringResult result = EntityPassesFilters(entityId);
if (result != FilteringResult::Pass)
{
OnTriggerExit(entityId);
if (result == FilteringResult::FailWithPossibilityOfChange)
{
TagComponentNotificationsBus::MultiHandler::BusConnect(entityId);
m_entitiesInsideExcludedByTags.push_back(entityId);
}
}
else
{
OnTriggerEnter(entityId);
auto foundIter = AZStd::find(m_entitiesInsideExcludedByTags.begin(), m_entitiesInsideExcludedByTags.end(), entityId);
if (foundIter != m_entitiesInsideExcludedByTags.end())
{
m_entitiesInsideExcludedByTags.erase(foundIter);
}
}
}
void TriggerAreaComponent::OnTagAdded(const Tag& tagAdded)
{
AZ::EntityId tagAddedToEntity = *(TagComponentNotificationsBus::GetCurrentBusId());
HandleTagChange(tagAddedToEntity);
}
void TriggerAreaComponent::OnTagRemoved(const Tag& tagRemoved)
{
AZ::EntityId tagRemovedFromEntity = *(TagComponentNotificationsBus::GetCurrentBusId());
HandleTagChange(tagRemovedFromEntity);
}
} // namespace LmbrCentral
|
#pragma once
#include <iostream>
#include <spdlog/fmt/fmt.h>
#include <ghc/filesystem.hpp>
#include <simdjson/error.h>
#include "platform.hpp"
#include "rpgmakerVersion.hpp"
template <>
struct fmt::formatter<ghc::filesystem::path> {
static constexpr auto parse(format_parse_context& ctx) {
return ctx.end();
}
template <typename FormatContext>
auto format(const ghc::filesystem::path& p, FormatContext& ctx) {
return format_to(ctx.out(), "{}", p.u8string());
}
};
template <>
struct fmt::formatter<std::error_code> {
static constexpr auto parse(format_parse_context& ctx) {
return ctx.end();
}
template <typename FormatContext>
auto format(const std::error_code& ec, FormatContext& ctx) {
return format_to(ctx.out(), "\n[{}]({}): {}", ec.category().name(), ec.value(), ec.message());
}
};
template <>
struct fmt::formatter<Platform> {
static constexpr auto parse(format_parse_context& ctx) {
return ctx.end();
}
template <typename FormatContext>
auto format(const Platform& p, FormatContext& ctx) {
return format_to(ctx.out(), "{}", PlatformNames[(int)p]);
}
};
template <>
struct fmt::formatter<RPGMakerVersion> {
static constexpr auto parse(format_parse_context& ctx) {
return ctx.end();
}
template <typename FormatContext>
auto format(const RPGMakerVersion& version, FormatContext& ctx) {
return format_to(ctx.out(), "{}", RPGMakerVersionNames[(int)version]);
}
};
template <>
struct fmt::formatter<simdjson::error_code> {
static constexpr auto parse(format_parse_context& ctx) {
return ctx.end();
}
template <typename FormatContext>
auto format(const simdjson::error_code& error, FormatContext& ctx) {
return format_to(ctx.out(), "{}", simdjson::error_message(error));
}
};
|
namespace menu {
seek(codeCursor)
namespace largeText {
enqueue pc
seek($ee53fc); jsl description; jmp $5409 //descriptions
seek($ee5532); jsl chapterName; jmp $553f //chapter names
seek($ee51f2); jsl main; nop #15 //text renderer for both description types
seek($ee540b); jsl test; nop #2 //test if OAM text should be cleared during list navigation
seek($ee9317); jml cancelStatus; nop #2 //clear OAM text when cancelling list navigation
seek($eeba32); jml acceptEquipment; nop #2 //clear OAM text when accepting list navigation
seek($eeba40); jml cancelEquipment; nop #2 //clear OAM text when cancelling list navigation
seek($eee218); jml cancelShop; nop #2 //clear OAM text when cancelling list navigation
seek($eeeca5); jml cancelInventory; nop #2 //clear OAM text when cancelling list navigation
seek($ee5478); nop #2 //disable post-main text increment (descriptions)
seek($ee55af); nop #2 //disable post-main text increment (name entry)
seek($ee5175); nop #3 //disable OAM setup (now handled inside main)
seek($ee511c); nop #4 //disable OAM clearing (left-half)
seek($ee5140); nop #4 //disable OAM clearing (right-half)
dequeue pc
//the tiledata output is segmented into four quadrants for sprite 16x16 alignment:
//$7e7800 = ( 0-127),(0- 7)
//$7e7a00 = ( 0-127),(8-15)
//$7e7c00 = (128-255),(0- 7)
//$7e7e00 = (128-255),(8-15)
constant index = $12 //current Y index into text string
constant buffer = $14 //text string is located at [$14],y
constant output = $7e7804 //where to write tiledata to ($7e:7800+)
constant naming = $7e9e00 //name select screen text is always located here
variable(2, pixel) //current X position position to render to
variable(2, pixels) //maximum number of pixels that can be rendered for this line
variable(2, ramAddressL) //position of tile N
variable(2, ramAddressR) //position of tile N+1
variable(2, character) //current character being rendered
variable(2, style) //current font style being used (#$00 = normal, #$60 = italic)
variable(2, color) //current font color being used (#$00 = normal, #$01 = yellow, #$02 = shadow)
//keeps track of the type of text being rendered.
//item descriptions will be transferred to VRAM via main.
//chapter descriptions will be transferred to VRAM via the original game engine.
variable(2, type)
namespace type {
constant nameEntry = 0
constant chapterName = 1
constant description = 2
}
function description {
enter
asl; tax; lda lists.descriptions.text,x
add.w #lists.descriptions.text >> 0; sta.b buffer+0; sep #$20; lda #$00
adc.b #lists.descriptions.text >> 16; sta.b buffer+2; rep #$20
lda.w #type.description; sta type
leave; rtl
}
function chapterName {
enter
asl; tax; lda lists.descriptions.text,x
add.w #lists.descriptions.text >> 0; sta.b buffer+0; sep #$20; lda #$00
adc.b #lists.descriptions.text >> 16; sta.b buffer+2; rep #$20
lda.w #type.chapterName; sta type
leave; rtl
}
//------
//ee51f2 lda $12
//ee51f4 and #$0001
//ee51f7 beq $51fb
//ee51f9 bra $5200
//ee51fb jsr $5207
//ee51fe bra $5205
//ee5200 jsr $5283
//ee5203 bra $5205
//------
function main {
enter; ldb #$7e
lda.b buffer+0; cmp.w #naming >> 0; bne +
lda.b buffer+1; cmp.w #naming >> 8; bne +
lda.w #type.nameEntry; sta type; +
initialize:
lda #$0000; sta character; sta pixel; sta style; sta color
lda.w #216; sta pixels
renderCharacter:
ldy.b index; lda [buffer],y; and #$00ff
cmp.w #command.terminal; bne +; jml finished; +; inc.b index
cmp.w #command.base; bcc decode
cmp.w #command.styleNormal; bne +; lda.w #$00; sta style; bra renderCharacter; +
cmp.w #command.styleItalic; bne +; lda.w #$60; sta style; bra renderCharacter; +
cmp.w #command.colorNormal; bne +; lda.w #$00; sta color; bra renderCharacter; +
cmp.w #command.colorYellow; bne +; lda.w #$01; sta color; bra renderCharacter; +
cmp.w #command.alignLeft; bne +; jsl align.left; bra renderCharacter; +
cmp.w #command.alignCenter; bne +; jsl align.center; bra renderCharacter; +
cmp.w #command.alignRight; bne +; jsl align.right; bra renderCharacter; +
cmp.w #command.alignSkip; bne +; jsl align.skip; bra renderCharacter; +
bra renderCharacter
decode:
character.decode(); add style; pha
//perform font kerning
lda character; mul(180); add $01,s; tax
lda largeFont.kernings,x; and #$00ff; pha
lda pixel; sub $01,s; sta pixel; pla; pla
sta character
//calculate first RAM tile write position
lda pixel; and #$00f8; asl #2; cmp #$0200; bcc +
add #$0200; +; sta ramAddressL
//calculate second RAM tile write position
lda pixel; add #$0008; and #$00f8; asl #2; cmp #$0200; bcc +
add #$0200; +; sta ramAddressR
//select one of eight pre-shifted copies of the proportional font
lda pixel; and #$0007; mul(8192); pha
//select the tile for the given character
lda character; mul(44); add $01,s; tax; pla
//add character width to pixel position for next character render
phx; lda character; tax
lda largeFont.widths,x; and #$00ff
plx; add pixel; cmp pixels; bcc +; beq +
lda pixels; sta pixel; jmp renderCharacter
+;sta pixel
//draw all 11 lines of the current character
lda type; cmp.w #type.description; jne shadow
lda color; jne yellow //only descriptions support font color selection
macro tile(variable font) {
macro lineL(variable n) {
variable t = n + 1
variable r = t / 6 * $200 + t % 6 * 2 - t / 6 * 4
lda.l font+$00+n*2,x; ora.w output+r,y; sta.w output+r,y
}
lda ramAddressL; tay
lineL(0); lineL(1); lineL(2); lineL(3); lineL(4)
lineL(5); lineL(6); lineL(7); lineL(8); lineL(9); lineL(10)
macro lineR(variable n) {
variable t = n + 1
variable r = t / 6 * $200 + t % 6 * 2 - t / 6 * 4
lda.l font+$16+n*2,x; ora.w output+r,y; sta.w output+r,y
}
lda ramAddressR; tay
lineR(0); lineR(1); lineR(2); lineR(3); lineR(4)
lineR(5); lineR(6); lineR(7); lineR(8); lineR(9); lineR(10)
jmp renderCharacter //keep rendering until all characters have been rendered
}
normal:; tile(largeFont.normal)
yellow:; tile(largeFont.yellow)
shadow:; tile(largeFont.shadow)
finished:
lda type; cmp.w #type.description; bne +; jsl write; +
leave; rtl
}
namespace align {
function left {
lda.w #0; sta pixel; rtl
}
function center {
lda.b index; add.b buffer+0; sta render.large.width.address+0
lda.w #$0000; adc.b buffer+2; sta render.large.width.address+2
lda style; sta render.large.width.style; jsl render.large.width
cmp pixels; bcc +; beq +; lda.w #0; sta pixel; rtl; +
pha; lda pixels; inc; sub $01,s; lsr; sta pixel; pla; rtl
}
function right {
lda.b index; add.b buffer+0; sta render.large.width.address+0
lda.w #$0000; adc.b buffer+2; sta render.large.width.address+2
lda style; sta render.large.width.style; jsl render.large.width
cmp pixels; bcc +; beq +; lda.w #0; sta pixel; rtl; +
pha; lda pixels; sub $01,s; sta pixel; pla; rtl
}
function skip {
ldy.b index; lda [buffer],y; and #$00ff; inc.b index
add pixel; sta pixel; rtl
}
}
function write {
//write 15 OAM entries (240 pixels)
lda #$c818; ldx #$0000; ldy #$000f
-;sta $7e6e20,x; add #$0010
inx #4; dey; bne -
//descriptions were originally rendered one character at a time, and only the
//next 24x16 pixels would be transferred after each function call, whereas this
//routine renders the entire string all at once, so it needs to all be copied here.
vwait() //vsync() cannot be used here due to the large size of the transfer
ldb #$00; sep #$20
lda #$01; sta $4300
lda #$18; sta $4301
ldx #$7800; stx $4302
lda #$7e; sta $4304
ldx #$0800; stx $4305
lda #$80; sta $2115
ldx #$7c00; stx $2116
lda #$01; sta $420b
lda #$ff; sta [buffer]
rtl
}
function clearSprites {
enter; ldb #$7e
lda #$e000; ldx #$0000; ldy #$000f
-;sta $6e20,x; add #$0010
inx #4; dey; bne -
leave; rtl
}
//------
//ee9312 bit #$8000 ;test if B is pressed
//ee9315 beq $92dd ;branch if not set
//ee9317 lda #$000c
//ee931a jsr $fb7c
//------
function cancelStatus {
jsl clearSprites
lda #$000c
pea $931c
jml $eefb7c
}
//------
//eeba2d bit #$0080 ;test if A is pressed
//eeba30 beq $ba3b ;branch if not set
//eeba32 lda #$000e
//eeba35 jsr $fb7c
//------
function acceptEquipment {
jsl clearSprites
lda #$000e
pea $ba37
jml $eefb7c
}
//------
//eeba3b bit #$8000 ;test if B is pressed
//eeba3e beq $ba49 ;branch if not set
//eeba40 lda #$000c
//eeba43 jsr $fb7c
//------
function cancelEquipment {
jsl clearSprites
lda #$000c
pea $ba45
jml $eefb7c
}
//------
//eee213 bit #$8000 ;test if B is pressed
//eee216 beq $e221 ;branch if not set
//eee218 lda #$000c
//eee21b jsr $fb7c
//------
function cancelShop {
jsl clearSprites
lda #$000c
pea $e21d
jml $eefb7c
}
//------
//eeeca0 bit #$8000 ;test if B is pressed
//eeeca3 beq $ecae ;branch if not set
//eeeca5 lda #$000c
//eeeca8 jsr $fb7c
//------
function cancelInventory {
jsl clearSprites
lda #$000c
pea $ecaa
jml $eefb7c
}
//------
//ee540b lda [$14],y
//ee540d and #$00ff
//------
function test {
lda [$14],y; and #$00ff
cmp #$00ff; beq +; rtl; +
cpy #$0000; beq +; rtl; +
jsl clearSprites; rtl
}
}
namespace disableTileQueuing {
//original renderer would queue up two 24x8 DMA transfers at a time.
//this resulted in choppy partial-character text rendering.
//------
//trying to extend it to transfer the entire #$0800 bytes of tiledata failed:
//the DMA list processing would occasionally run beyond vblank for the NMI routine,
//which resorted in severe graphical distortion. so instead of using this routine,
//tiledata is uploaded to VRAM manually inside renderCharacter.
//------
//a second issue is that this list can only hold 96 entries, and each character adds
//two (or when striding the left/right quadrants, four) transfer requests. however,
//some strings render immediately and queue all characters before sending any.
//this would cause the DMA transfer buffer to overflow on particularly long strings.
enqueue pc
seek($ee5178); plp; rts
dequeue pc
}
namespace disableTileAlignment {
//original renderer drew 12x12 tiles onto 16x16 sprites.
//after rendering 10 tiles, 120 of 128 pixels were used.
//the game would then skip the remaining 8 pixels, too short for another character,
//and place all subsequent sprites 8 pixels further to the left to account for this.
//the proportional font renderer writes to all 128 pixels, so this is not desirable.
//------
//ee5352 cpx #$001c ;is this the first tile of the second line?
//ee5355 bne $535b ;no, continue as normal
//ee5357 sec ;yes, subtract 8 for sprite X position,
//ee5358 sbc #$0008 ;which will affect all remaining tiles
//------
enqueue pc
seek($ee5355); db $80 //bne $535b -> bra $535b
dequeue pc
}
namespace disableCharacterLengthLimits {
//original game limited the maximum length of text strings.
//this doesn't work well for the thinner proportional font, so disable these checks.
//------
//ee547a lda $12 ;load how many characters have been rendered
//ee547c cmp #$0014 ;20 characters * 12x12 = 240 pixels
//ee547f bcs $5484 ;if length exceeded, skip rendering character
//------
//ee55b1 lda $12 ;load how many characters have been rendered
//ee55b3 cmp #$000a ;10 characters * 12x12 = 120 pixels
//ee55b6 bcs $55bb ;if length exceeded, skip rendering character
//------
enqueue pc
seek($ee547c); nop #5
seek($ee55b3); nop #5
dequeue pc
}
codeCursor = pc()
}
|
//===--- UnqualifiedLookup.cpp - Swift Name Lookup Routines ---------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
///
/// This file implements unqualified lookup, which searches for an identifier
/// from a given context.
///
//===----------------------------------------------------------------------===//
#include "swift/AST/ASTContext.h"
#include "swift/AST/ASTVisitor.h"
#include "swift/AST/DebuggerClient.h"
#include "swift/AST/ImportCache.h"
#include "swift/AST/ModuleNameLookup.h"
#include "swift/AST/NameLookup.h"
#include "swift/AST/NameLookupRequests.h"
#include "swift/AST/PropertyWrappers.h"
#include "swift/AST/SourceFile.h"
#include "swift/Basic/Debug.h"
#include "swift/Basic/STLExtras.h"
#include "swift/Basic/SourceManager.h"
#include "swift/Basic/Statistic.h"
#include "swift/Parse/Lexer.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/TinyPtrVector.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#define DEBUG_TYPE "namelookup"
using namespace swift;
using namespace swift::namelookup;
namespace {
class UnqualifiedLookupFactory {
friend class ASTScopeDeclConsumerForUnqualifiedLookup;
public:
using Flags = UnqualifiedLookupFlags;
using Options = UnqualifiedLookupOptions;
using ResultsVector = SmallVector<LookupResultEntry, 4>;
private:
/// Finds lookup results based on the types that self conforms to.
/// For instance, self always conforms to a struct, enum or class.
/// But in addition, self could conform to any number of protocols.
/// For example, when there's a protocol extension, e.g. extension P where
/// self: P2, self also conforms to P2 so P2 must be searched.
class ResultFinderForTypeContext {
UnqualifiedLookupFactory *const factory;
/// Nontypes are formally members of the base type, i.e. the dynamic type
/// of the activation record.
const DeclContext *const dynamicContext;
/// Types are formally members of the metatype, i.e. the static type of the
/// activation record.
const DeclContext *const staticContext;
using SelfBounds = SmallVector<NominalTypeDecl *, 2>;
SelfBounds selfBounds;
public:
/// \p staticContext is also the context from which to derive the self types
ResultFinderForTypeContext(UnqualifiedLookupFactory *factory,
const DeclContext *dynamicContext,
const DeclContext *staticContext);
SWIFT_DEBUG_DUMP;
private:
SelfBounds findSelfBounds(const DeclContext *dc);
// Classify this declaration.
// Types are formally members of the metatype.
const DeclContext *
whereValueIsMember(const ValueDecl *const member) const {
return isa<TypeDecl>(member) ? staticContext : dynamicContext;
}
public:
/// Do the lookups and add matches to results.
void findResults(const DeclNameRef &Name, NLOptions baseNLOptions,
const DeclContext *contextForLookup,
SmallVectorImpl<LookupResultEntry> &results) const;
};
// Inputs
const DeclNameRef Name;
DeclContext *const DC;
ModuleDecl &M;
const ASTContext &Ctx;
const SourceLoc Loc;
const SourceManager &SM;
/// Used to find the file-local names.
DebuggerClient *const DebugClient;
const Options options;
const bool isOriginallyTypeLookup;
const NLOptions baseNLOptions;
// Outputs
SmallVectorImpl<LookupResultEntry> &Results;
size_t &IndexOfFirstOuterResult;
ResultsVector UnavailableInnerResults;
#ifndef NDEBUG
static unsigned lookupCounter;
static const unsigned targetLookup;
#endif
public:
// clang-format off
UnqualifiedLookupFactory(DeclNameRef Name,
DeclContext *const DC,
SourceLoc Loc,
Options options,
SmallVectorImpl<LookupResultEntry> &Results,
size_t &IndexOfFirstOuterResult);
// clang-format on
void performUnqualifiedLookup();
private:
void lookUpTopLevelNamesInModuleScopeContext(const DeclContext *);
void lookInASTScopes();
/// Can lookup stop searching for results, assuming hasn't looked for outer
/// results yet?
bool isFirstResultEnough() const;
/// Do we want precise scoping of VarDecls? If IncludeOuterResults is on,
/// this is true, which allows us to resolve forward references to
/// local VarDecls from inside local function and closure bodies.
bool hasPreciseScopingOfVarDecls() const;
/// Every time lookup finishes searching a scope, call me
/// to record the dividing line between results from first fruitful scope and
/// the result.
void recordCompletionOfAScope();
#pragma mark context-based lookup declarations
bool isInsideBodyOfFunction(const AbstractFunctionDecl *const AFD) const;
/// For diagnostic purposes, move aside the unavailables, and put
/// them back as a last-ditch effort.
/// Could be cleaner someday with a richer interface to UnqualifiedLookup.
void setAsideUnavailableResults(size_t firstPossiblyUnavailableResult);
void addImportedResults(const DeclContext *const dc);
void addNamesKnownToDebugClient(const DeclContext *dc);
void addUnavailableInnerResults();
void lookForAModuleWithTheGivenName(const DeclContext *dc);
#pragma mark common helper declarations
static NLOptions
computeBaseNLOptions(const UnqualifiedLookupOptions options,
const bool isOriginallyTypeLookup);
void findResultsAndSaveUnavailables(
const DeclContext *lookupContextForThisContext,
ResultFinderForTypeContext &&resultFinderForTypeContext,
NLOptions baseNLOptions);
public:
SWIFT_DEBUG_DUMP;
SWIFT_DEBUG_DUMPER(dumpResults());
SWIFT_DEBUG_DUMPER(dumpScopes());
void printScopes(raw_ostream &OS) const;
void print(raw_ostream &OS) const;
void printResults(raw_ostream &OS) const;
#ifndef NDEBUG
bool isTargetLookup() const;
void stopForDebuggingIfStartingTargetLookup(bool isASTScopeLookup) const;
void stopForDebuggingIfDuringTargetLookup(bool isASTScopeLookup) const;
void
stopForDebuggingIfAddingTargetLookupResult(const LookupResultEntry &) const;
void addedResult(const LookupResultEntry &) const;
#endif
};
} // namespace
namespace {
/// Used to gather lookup results
class ASTScopeDeclConsumerForUnqualifiedLookup
: public AbstractASTScopeDeclConsumer {
UnqualifiedLookupFactory &factory;
/// The 'self' parameter from the innermost scope containing the lookup
/// location to be used when an instance member of a type is accessed,
/// or nullptr if instance members should not be 'self' qualified.
DeclContext *candidateSelfDC;
public:
ASTScopeDeclConsumerForUnqualifiedLookup(UnqualifiedLookupFactory &factory)
: factory(factory), candidateSelfDC(nullptr) {}
virtual ~ASTScopeDeclConsumerForUnqualifiedLookup() = default;
void maybeUpdateSelfDC(VarDecl *var);
bool consume(ArrayRef<ValueDecl *> values,
NullablePtr<DeclContext> baseDC = nullptr) override;
bool consumePossiblyNotInScope(ArrayRef<VarDecl *> vars) override;
/// returns true if finished
bool lookInMembers(DeclContext *const scopeDC,
NominalTypeDecl *const nominal) override;
#ifndef NDEBUG
void startingNextLookupStep() override {
factory.stopForDebuggingIfDuringTargetLookup(true);
}
bool isTargetLookup() const override { return factory.isTargetLookup(); }
void finishingLookup(std::string msg) const override {
if (isTargetLookup())
llvm::errs() << "Finishing lookup: " << msg << "\n";
}
#endif
};
} // namespace
#pragma mark UnqualifiedLookupFactory functions
// clang-format off
UnqualifiedLookupFactory::UnqualifiedLookupFactory(
DeclNameRef Name,
DeclContext *const DC,
SourceLoc Loc,
Options options,
SmallVectorImpl<LookupResultEntry> &Results,
size_t &IndexOfFirstOuterResult)
:
Name(Name),
DC(DC),
M(*DC->getParentModule()),
Ctx(M.getASTContext()),
Loc(Loc),
SM(Ctx.SourceMgr),
DebugClient(M.getDebugClient()),
options(options),
isOriginallyTypeLookup(options.contains(Flags::TypeLookup)),
baseNLOptions(computeBaseNLOptions(options, isOriginallyTypeLookup)),
Results(Results),
IndexOfFirstOuterResult(IndexOfFirstOuterResult)
{}
// clang-format on
void UnqualifiedLookupFactory::performUnqualifiedLookup() {
#ifndef NDEBUG
++lookupCounter;
auto localCounter = lookupCounter;
(void)localCounter; // for debugging
#endif
FrontendStatsTracer StatsTracer(Ctx.Stats,
"performUnqualifedLookup",
DC->getParentSourceFile());
if (Loc.isValid() && DC->getParentSourceFile()) {
// Operator lookup is always global, for the time being.
if (!Name.isOperator())
lookInASTScopes();
} else {
assert((DC->isModuleScopeContext() || !DC->getParentSourceFile()) &&
"Unqualified lookup without a source location must start from "
"a module-scope context");
#ifndef NDEBUG
stopForDebuggingIfStartingTargetLookup(false);
#endif
}
recordCompletionOfAScope();
if (!isFirstResultEnough()) {
// If no result has been found yet, the dependency must be on a top-level
// name, since up to now, the search has been for non-top-level names.
auto *moduleScopeContext = DC->getModuleScopeContext();
lookUpTopLevelNamesInModuleScopeContext(moduleScopeContext);
}
}
void UnqualifiedLookupFactory::lookUpTopLevelNamesInModuleScopeContext(
const DeclContext *DC) {
// TODO: Does the debugger client care about compound names?
if (Name.isSimpleName() && !Name.isSpecial() && DebugClient &&
DebugClient->lookupOverrides(Name.getBaseName(),
const_cast<DeclContext *>(DC), Loc,
isOriginallyTypeLookup, Results)) {
return;
}
addImportedResults(DC);
addNamesKnownToDebugClient(DC);
if (Results.empty()) {
// If we still haven't found anything, but we do have some
// declarations that are "unavailable in the current Swift", drop
// those in.
addUnavailableInnerResults();
if (Results.empty())
lookForAModuleWithTheGivenName(DC);
}
recordCompletionOfAScope();
}
#pragma mark context-based lookup definitions
bool UnqualifiedLookupFactory::isInsideBodyOfFunction(
const AbstractFunctionDecl *const AFD) const {
auto range = Lexer::getCharSourceRangeFromSourceRange(
SM, AFD->getBodySourceRange());
return range.contains(Loc);
}
void UnqualifiedLookupFactory::ResultFinderForTypeContext::findResults(
const DeclNameRef &Name, NLOptions baseNLOptions,
const DeclContext *contextForLookup,
SmallVectorImpl<LookupResultEntry> &results) const {
// An optimization:
if (selfBounds.empty())
return;
SmallVector<ValueDecl *, 4> Lookup;
contextForLookup->lookupQualified(selfBounds, Name, baseNLOptions, Lookup);
for (auto Result : Lookup) {
results.emplace_back(const_cast<DeclContext *>(whereValueIsMember(Result)),
Result);
#ifndef NDEBUG
factory->addedResult(results.back());
#endif
}
}
// TODO (someday): Instead of adding unavailable entries to Results,
// then later shunting them aside, just put them in the right place
// to begin with.
void UnqualifiedLookupFactory::setAsideUnavailableResults(
const size_t firstPossiblyUnavailableResult) {
// An optimization:
assert(Results.size() >= firstPossiblyUnavailableResult);
if (Results.size() == firstPossiblyUnavailableResult)
return;
// Predicate that determines whether a lookup result should
// be unavailable except as a last-ditch effort.
auto unavailableLookupResult = [&](const LookupResultEntry &result) {
auto &effectiveVersion = Ctx.LangOpts.EffectiveLanguageVersion;
return result.getValueDecl()->getAttrs().isUnavailableInSwiftVersion(
effectiveVersion);
};
// If all of the results we found are unavailable, keep looking.
auto begin = Results.begin() + firstPossiblyUnavailableResult;
if (std::all_of(begin, Results.end(), unavailableLookupResult)) {
// better to have more structure in results
UnavailableInnerResults.append(begin, Results.end());
Results.erase(begin, Results.end());
return;
}
// The debugger may have a different private discriminator
// in order to support lookup relative to the place where
// execution is suspended.
filterForDiscriminator(Results, DebugClient);
}
void UnqualifiedLookupFactory::addImportedResults(const DeclContext *const dc) {
using namespace namelookup;
SmallVector<ValueDecl *, 8> CurModuleResults;
auto resolutionKind = isOriginallyTypeLookup ? ResolutionKind::TypesOnly
: ResolutionKind::Overloadable;
auto nlOptions = NL_UnqualifiedDefault;
if (options.contains(Flags::IncludeUsableFromInline))
nlOptions |= NL_IncludeUsableFromInline;
lookupInModule(dc, Name.getFullName(), CurModuleResults,
NLKind::UnqualifiedLookup, resolutionKind, dc, nlOptions);
// Always perform name shadowing for type lookup.
if (options.contains(Flags::TypeLookup)) {
removeShadowedDecls(CurModuleResults, dc);
}
for (auto VD : CurModuleResults) {
Results.push_back(LookupResultEntry(VD));
#ifndef NDEBUG
addedResult(Results.back());
#endif
}
filterForDiscriminator(Results, DebugClient);
}
void UnqualifiedLookupFactory::addNamesKnownToDebugClient(
const DeclContext *dc) {
if (Name.isSimpleName() && DebugClient)
DebugClient->lookupAdditions(Name.getBaseName(),
const_cast<DeclContext *>(dc), Loc,
isOriginallyTypeLookup, Results);
}
void UnqualifiedLookupFactory::addUnavailableInnerResults() {
Results = std::move(UnavailableInnerResults);
}
void UnqualifiedLookupFactory::lookForAModuleWithTheGivenName(
const DeclContext *const dc) {
using namespace namelookup;
if (!Name.isSimpleName() || Name.isSpecial())
return;
// Look for a module with the given name.
if (Name.isSimpleName(M.getName())) {
Results.push_back(LookupResultEntry(&M));
#ifndef NDEBUG
addedResult(Results.back());
#endif
return;
}
ModuleDecl *desiredModule = Ctx.getLoadedModule(Name.getBaseIdentifier());
if (!desiredModule && Name.getFullName() == Ctx.TheBuiltinModule->getName())
desiredModule = Ctx.TheBuiltinModule;
if (desiredModule) {
// Make sure the desired module is actually visible from the current
// context.
if (Ctx.getImportCache().isImportedBy(desiredModule, dc)) {
Results.push_back(LookupResultEntry(desiredModule));
#ifndef NDEBUG
addedResult(Results.back());
#endif
}
}
}
#pragma mark common helper definitions
void UnqualifiedLookupFactory::findResultsAndSaveUnavailables(
const DeclContext *lookupContextForThisContext,
ResultFinderForTypeContext &&resultFinderForTypeContext,
NLOptions baseNLOptions) {
auto firstPossiblyUnavailableResult = Results.size();
resultFinderForTypeContext.findResults(Name, baseNLOptions,
lookupContextForThisContext, Results);
setAsideUnavailableResults(firstPossiblyUnavailableResult);
}
NLOptions UnqualifiedLookupFactory::computeBaseNLOptions(
const UnqualifiedLookupOptions options,
const bool isOriginallyTypeLookup) {
NLOptions baseNLOptions = NL_UnqualifiedDefault;
if (options.contains(Flags::AllowProtocolMembers))
baseNLOptions |= NL_ProtocolMembers;
if (isOriginallyTypeLookup)
baseNLOptions |= NL_OnlyTypes;
if (options.contains(Flags::IgnoreAccessControl))
baseNLOptions |= NL_IgnoreAccessControl;
return baseNLOptions;
}
bool UnqualifiedLookupFactory::isFirstResultEnough() const {
return !Results.empty() && !options.contains(Flags::IncludeOuterResults);
}
bool UnqualifiedLookupFactory::hasPreciseScopingOfVarDecls() const {
return !options.contains(Flags::IncludeOuterResults);
}
void UnqualifiedLookupFactory::recordCompletionOfAScope() {
// OK to call (NOOP) if there are more inner results and Results is empty
if (IndexOfFirstOuterResult == 0)
IndexOfFirstOuterResult = Results.size();
}
UnqualifiedLookupFactory::ResultFinderForTypeContext::
ResultFinderForTypeContext(UnqualifiedLookupFactory *factory,
const DeclContext *dynamicContext,
const DeclContext *staticContext)
: factory(factory), dynamicContext(dynamicContext),
staticContext(staticContext), selfBounds(findSelfBounds(staticContext)) {}
UnqualifiedLookupFactory::ResultFinderForTypeContext::SelfBounds
UnqualifiedLookupFactory::ResultFinderForTypeContext::findSelfBounds(
const DeclContext *dc) {
auto nominal = dc->getSelfNominalTypeDecl();
if (!nominal)
return {};
SelfBounds selfBounds;
selfBounds.push_back(nominal);
// For a protocol extension, check whether there are additional "Self"
// constraints that can affect name lookup.
if (dc->getExtendedProtocolDecl()) {
auto ext = cast<ExtensionDecl>(dc);
auto bounds = getSelfBoundsFromWhereClause(ext);
for (auto bound : bounds.decls)
selfBounds.push_back(bound);
}
return selfBounds;
}
#pragma mark ASTScopeImpl support
void UnqualifiedLookupFactory::lookInASTScopes() {
ASTScopeDeclConsumerForUnqualifiedLookup consumer(*this);
#ifndef NDEBUG
stopForDebuggingIfStartingTargetLookup(true);
#endif
ASTScope::unqualifiedLookup(DC->getParentSourceFile(), Loc, consumer);
}
void ASTScopeDeclConsumerForUnqualifiedLookup::maybeUpdateSelfDC(
VarDecl *var) {
// We have a binding named 'self'.
//
// There are three possibilities:
//
// 1) This binding is the 'self' parameter of a method,
// 2) This binding is a bona-fide 'self' capture, meaning a capture
// list entry named 'self' with initial value expression 'self',
// 3) None of the above.
//
// How we handle these cases depends on whether we've already seen
// another 'self' binding.
if (candidateSelfDC == nullptr) {
// We haven't seen one yet, so record it.
if (var->isSelfParameter())
candidateSelfDC = var->getDeclContext();
else if (var->isSelfParamCapture())
candidateSelfDC = var->getParentCaptureList()->getClosureBody();
} else {
// If we see a binding named 'self' that is not a bona-fide
// 'self', we have to forget about the previous 'self' capture
// because it's not going to be the right one for accessing
// instance members of the innermost nominal type. Eg,
//
// class C {
// func bar() {}
// func foo() {
// _ { [self=12] { [self] bar() } }
// }
// }
//
// Instead, we're going to move on and look for the next-innermost
// 'self' binding.
if (!var->isSelfParameter() &&
!var->isSelfParamCapture())
candidateSelfDC = nullptr;
}
}
bool ASTScopeDeclConsumerForUnqualifiedLookup::consume(
ArrayRef<ValueDecl *> values, NullablePtr<DeclContext> baseDC) {
for (auto *value: values) {
if (factory.isOriginallyTypeLookup && !isa<TypeDecl>(value))
continue;
if (auto *var = dyn_cast<VarDecl>(value)) {
// Try to resolve the base for unqualified instance member
// references. This is used by lookInMembers().
if (var->getName() == factory.Ctx.Id_self) {
maybeUpdateSelfDC(var);
}
// Local VarDecls with a pattern binding are visited as part of their
// BraceStmt when hasPreciseScopingOfVarDecls() is off.
if (var->getParentPatternBinding() &&
!factory.hasPreciseScopingOfVarDecls())
continue;
}
auto fullName = factory.Name.getFullName();
if (!value->getName().matchesRef(fullName)) {
bool foundMatch = false;
if (auto *varDecl = dyn_cast<VarDecl>(value)) {
// Check if the name matches any auxiliary decls not in the AST
varDecl->visitAuxiliaryDecls([&](VarDecl *auxiliaryVar) {
if (auxiliaryVar->ValueDecl::getName().matchesRef(fullName)) {
value = auxiliaryVar;
foundMatch = true;
}
});
}
if (!foundMatch)
continue;
}
factory.Results.push_back(LookupResultEntry(value));
#ifndef NDEBUG
factory.stopForDebuggingIfAddingTargetLookupResult(factory.Results.back());
#endif
}
factory.recordCompletionOfAScope();
return factory.isFirstResultEnough();
}
bool ASTScopeDeclConsumerForUnqualifiedLookup::consumePossiblyNotInScope(
ArrayRef<VarDecl *> vars) {
if (factory.hasPreciseScopingOfVarDecls())
return false;
for (auto *var : vars) {
if (!factory.Name.getFullName().isSimpleName(var->getName()))
continue;
factory.Results.push_back(LookupResultEntry(var));
}
return false;
}
bool ASTScopeDeclGatherer::consume(ArrayRef<ValueDecl *> valuesArg,
NullablePtr<DeclContext>) {
for (auto *v: valuesArg)
values.push_back(v);
return false;
}
// TODO: in future, migrate this functionality into ASTScopes
bool ASTScopeDeclConsumerForUnqualifiedLookup::lookInMembers(
DeclContext *const scopeDC,
NominalTypeDecl *const nominal) {
if (candidateSelfDC) {
if (auto *afd = dyn_cast<AbstractFunctionDecl>(candidateSelfDC)) {
assert(factory.isInsideBodyOfFunction(afd) && "Should be inside");
}
}
// We're looking for members of a type.
//
// If we started the looking from inside a scope where a 'self' parameter
// is visible, instance members are returned with the 'self' parameter's
// DeclContext as the base, which is how the expression checker knows to
// convert the unqualified reference into a self member access.
auto resultFinder = UnqualifiedLookupFactory::ResultFinderForTypeContext(
&factory, candidateSelfDC ? candidateSelfDC : scopeDC, scopeDC);
factory.findResultsAndSaveUnavailables(scopeDC, std::move(resultFinder),
factory.baseNLOptions);
factory.recordCompletionOfAScope();
// We're done looking inside a nominal type declaration. It is possible
// that this nominal type is nested inside of another type, in which case
// we will visit the outer type next. Make sure to clear out the known
// 'self' parameeter context, since any members of the outer type are
// not accessed via the innermost 'self' parameter.
candidateSelfDC = nullptr;
return factory.isFirstResultEnough();
}
LookupResult
UnqualifiedLookupRequest::evaluate(Evaluator &evaluator,
UnqualifiedLookupDescriptor desc) const {
SmallVector<LookupResultEntry, 4> results;
size_t indexOfFirstOuterResult = 0;
UnqualifiedLookupFactory factory(desc.Name, desc.DC, desc.Loc, desc.Options,
results, indexOfFirstOuterResult);
factory.performUnqualifiedLookup();
return LookupResult(results, indexOfFirstOuterResult);
}
#pragma mark debugging
void UnqualifiedLookupFactory::ResultFinderForTypeContext::dump() const {
(void)factory;
llvm::errs() << "dynamicContext: ";
dynamicContext->dumpContext();
llvm::errs() << "staticContext: ";
staticContext->dumpContext();
llvm::errs() << "selfBounds: ";
for (const auto *D : selfBounds)
D->dump(llvm::errs(), 1);
llvm::errs() << "\n";
}
void UnqualifiedLookupFactory::dump() const { print(llvm::errs()); }
void UnqualifiedLookupFactory::dumpScopes() const { printScopes(llvm::errs()); }
void UnqualifiedLookupFactory::dumpResults() const {
printResults(llvm::errs());
}
void UnqualifiedLookupFactory::printScopes(raw_ostream &out) const {
out << "\n\nScopes:\n";
DC->getParentSourceFile()->getScope().print(out);
out << "\n";
}
void UnqualifiedLookupFactory::printResults(raw_ostream &out) const {
for (auto i : indices(Results)) {
out << i << ": ";
Results[i].print(out);
out << "\n";
}
}
void UnqualifiedLookupFactory::print(raw_ostream &OS) const {
OS << "Look up";
#ifndef NDEBUG
OS << " (" << lookupCounter << ")";
#endif
OS << " '" << Name << "' at: ";
Loc.print(OS, DC->getASTContext().SourceMgr);
OS << "\nStarting in: ";
DC->printContext(OS);
OS << "\n";
}
#pragma mark breakpointing
#ifndef NDEBUG
bool UnqualifiedLookupFactory::isTargetLookup() const {
return lookupCounter == targetLookup;
}
void UnqualifiedLookupFactory::stopForDebuggingIfStartingTargetLookup(
const bool isASTScopeLookup) const {
if (!isTargetLookup())
return;
if (isASTScopeLookup)
llvm::errs() << "starting target ASTScopeImpl lookup\n";
else
llvm::errs() << "starting target context-based lookup\n";
}
void UnqualifiedLookupFactory::stopForDebuggingIfDuringTargetLookup(
const bool isASTScopeLookup) const {
if (!isTargetLookup())
return;
if (isASTScopeLookup)
llvm::errs() << "during target ASTScopeImpl lookup\n";
else
llvm::errs() << "during target context-based lookup\n";
}
void UnqualifiedLookupFactory::stopForDebuggingIfAddingTargetLookupResult(
const LookupResultEntry &e) const {
if (!isTargetLookup())
return;
auto &out = llvm::errs();
out << "\nresult for Target lookup:\n";
e.print(out);
out << "\n";
}
void UnqualifiedLookupFactory::addedResult(const LookupResultEntry &e) const {
stopForDebuggingIfAddingTargetLookupResult(e);
}
unsigned UnqualifiedLookupFactory::lookupCounter = 0;
// set to ~0 when not debugging
const unsigned UnqualifiedLookupFactory::targetLookup = ~0;
#endif // NDEBUG
namespace {
class ASTScopeDeclConsumerForLocalLookup
: public AbstractASTScopeDeclConsumer {
DeclName name;
bool stopAfterInnermostBraceStmt;
SmallVectorImpl<ValueDecl *> &results;
public:
ASTScopeDeclConsumerForLocalLookup(
DeclName name, bool stopAfterInnermostBraceStmt,
SmallVectorImpl<ValueDecl *> &results)
: name(name), stopAfterInnermostBraceStmt(stopAfterInnermostBraceStmt),
results(results) {}
bool consume(ArrayRef<ValueDecl *> values,
NullablePtr<DeclContext> baseDC) override {
for (auto *value: values) {
bool foundMatch = false;
if (auto *varDecl = dyn_cast<VarDecl>(value)) {
// Check if the name matches any auxiliary decls not in the AST
varDecl->visitAuxiliaryDecls([&](VarDecl *auxiliaryVar) {
if (name.isSimpleName(auxiliaryVar->getName())) {
results.push_back(auxiliaryVar);
foundMatch = true;
}
});
}
if (!foundMatch && value->getName().matchesRef(name))
results.push_back(value);
}
return (!stopAfterInnermostBraceStmt && !results.empty());
}
bool lookInMembers(DeclContext *const,
NominalTypeDecl *const) override {
return true;
}
bool finishLookupInBraceStmt(BraceStmt *stmt) override {
return stopAfterInnermostBraceStmt;
}
#ifndef NDEBUG
void startingNextLookupStep() override {}
void finishingLookup(std::string) const override {}
bool isTargetLookup() const override { return false; }
#endif
};
}
/// Lookup that only finds local declarations and does not trigger
/// interface type computation.
void ASTScope::lookupLocalDecls(SourceFile *sf, DeclName name, SourceLoc loc,
bool stopAfterInnermostBraceStmt,
SmallVectorImpl<ValueDecl *> &results) {
ASTScopeDeclConsumerForLocalLookup consumer(name, stopAfterInnermostBraceStmt,
results);
ASTScope::unqualifiedLookup(sf, loc, consumer);
}
ValueDecl *ASTScope::lookupSingleLocalDecl(SourceFile *sf, DeclName name,
SourceLoc loc) {
SmallVector<ValueDecl *, 1> result;
ASTScope::lookupLocalDecls(sf, name, loc,
/*finishLookupInBraceStmt=*/false,
result);
if (result.size() != 1)
return nullptr;
return result[0];
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.