text
stringlengths
1
1.05M
; void __CALLEE__ in_MouseKempSetPos_callee(uint xcoord, uint ycoord) ; 09.2005 aralbrec PUBLIC in_MouseKempSetPos_callee PUBLIC ASMDISP_IN_MOUSEKEMPSETPOS_CALLEE PUBLIC CDISP_IN_MOUSEKEMPSETPOS_CALLEE EXTERN INMouseKemp EXTERN _in_KempcoordX, _in_KempcoordY .in_MouseKempSetPos_callee pop hl pop bc ex (sp),hl .centry ; bc = ycoord ; hl = xcoord ld a,b or a jr nz, correcty ld a,c cp 191 jp c, yok .correcty ld a,191 .yok ld b,a ld a,h or a jp z, xok ld l,255 .xok ld c,l .asmentry ; enter: C = x coord 0..255 ; B = y coord 0..191 push bc call INMouseKemp ; zero out any existing delta pop bc ld a,c ld (_in_KempcoordX),a ld a,b ld (_in_KempcoordY),a ret DEFC ASMDISP_IN_MOUSEKEMPSETPOS_CALLEE = # asmentry - in_MouseKempSetPos_callee DEFC CDISP_IN_MOUSEKEMPSETPOS_CALLEE = # centry - in_MouseKempSetPos_callee
BUFsiz equ 64 section .rodata $nl db 10, 0 $sp db 32, 0 section .data global _env $bufsiz dq BUFsiz $_env dq 0 section .bss $buffer resb BUFsiz section .text global _println, _printsp, _printi, _readln, _readi, _debug global _strlen, _atoi, _itoa, _argc, _argv, _envp extern _prints, _readb _argc: mov rax, [abs qword _env] mov rax, [rax] ret _argv: mov rax, [abs qword _env] add rax, 8 mov rbx, [rsp+8] lea rax, [rax+rbx*8] mov rax, [rax] ret _envp: mov rax, [abs qword _env] mov rbx, rax mov rdx, [rbx] lea rax, [rbx+rdx*8+16] mov rbx, [rsp+8] lea rax, [rax+rbx*8] mov rax, [rax] ret _strlen: mov rdx, [rsp+8] cmp byte [rdx], 0 mov rax, rdx je .Lend .Lrep: inc rax cmp byte [rax], 0 jne .Lrep .Lend: sub rax, rdx ret _println: mov rax, $nl push rax call _prints add rsp, 8 ret _printsp: mov rax, $nl push rax .Lmais: ;cmp qword [rsp+16], 0 mov rax, [rsp+16] cmp rax, 0 jle .Lfim call _prints dec qword [rsp+16] jmp .Lmais .Lfim: add rsp, 8 ret _debug: ret _itoa: mov rcx, [rsp+8] ; load arg mov rdi, $buffer+30 mov rsi, 0 test rcx, rcx jge .L8 inc rsi neg rcx .L8: mov [rdi], byte 0 ; put the NULL character and walk backwards dec rdi mov rbx, 10 .L9: mov rax, rcx xor rdx, rdx div rbx mov rcx, rax add rdx, byte '0' mov [rdi], dl dec rdi test rcx, rcx jg .L9 test rsi, rsi je .L10 mov [rdi], byte '-' dec rdi .L10: mov rax, rdi inc rax ret _printi: push qword [rsp+8] call _itoa add rsp, 8 push rax call _prints add rsp, 8 ret _atoi: mov rsi, [rsp+8] mov rcx, 1 xor rbx, rbx xor rax, rax cld lodsb cmp rax, '-' jne .L1 neg rcx lodsb .L1: cmp rax, '0' jb .L2 cmp rax, '9' ja .L2 sub rax, '0' xchg rbx, rax mov rdx, 10 mul rdx add rbx, rax xor rax, rax lodsb jmp .L1 .L2: mov rax, rbx mul rcx ret _readln: ; readln(buf, siz) mov rcx, [rsp+16] ; mov rdi, [rsp+8] ; cld _Lnext: call _readb cmp rax, 0 jle _Lerr cmp rax, 10 je _Lend cmp rcx, 1 jle _Lend stosb dec rcx jmp _Lnext _Lend: xor rax, rax stosb mov rax, [rsp+8] ret _Lerr: xor rax, rax ret _readi: mov rax, $bufsiz push rax mov rax, $buffer push rax call _readln add rsp, 16 cmp rax, 0 je .Lerr push rax call _atoi add rsp,8 ret .Lerr: mov rax, 0x8000000000000000 ret
; A244310: a(n) = L(n)^3 - L(n)^2, where L(n) is the n-th Lucas number (A000032). ; 4,0,18,48,294,1210,5508,23548,101614,433200,1845738,7840998,33282564,141149320,598366458,2535856048,10745092894,45524786370,192866785668,817050731748,3461224027254,14662350247600,62111682111618,263111844646798,1114566304573444,4721396023578960,20000200045073058,84722326168608048,358889844988851414,1520282596932819850,6440022564933017988,27280378962404436748,115561554399702638014,489526638410694627120,2073668217606150749658,8784199795676207799798,37210468151271044426244,157626074366798042207320,667714770765618742999818,2828485170904697704067248,11981655489663534963890254,50755107221920777976178450,215002084619153360685870468,910763446331592392675218548,3858055871602890780488081094,16342986937082200813844374960,69230003631291462207598287858,293263001491988308660903648798,1242282009677105706051977256964,5262391040404253900932625796000,22291846171827788605617468018738,94429775729112567441477521011248,400010949091935868432128072974214,1694473572106432312230139786958170,7177905237542736120478323626655108,30406094522343013532450829966923548,128802283327086629462093344683294094,545615227831139412277927402448681520 seq $0,32 ; Lucas numbers beginning at 2: L(n) = L(n-1) + L(n-2), L(0) = 2, L(1) = 1. mov $2,$0 mul $2,$0 sub $0,1 add $1,$0 mul $1,$2 mov $0,$1
/* * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ #include <AK/Singleton.h> #include <AK/Time.h> #include <Kernel/Scheduler.h> #include <Kernel/Sections.h> #include <Kernel/Time/TimeManagement.h> #include <Kernel/TimerQueue.h> namespace Kernel { static Singleton<TimerQueue> s_the; static SpinLock<u8> g_timerqueue_lock; Time Timer::remaining() const { return m_remaining; } Time Timer::now(bool is_firing) const { // NOTE: If is_firing is true then TimePrecision::Precise isn't really useful here. // We already have a quite precise time stamp because we just updated the time in the // interrupt handler. In those cases, just use coarse timestamps. auto clock_id = m_clock_id; if (is_firing) { switch (clock_id) { case CLOCK_MONOTONIC: clock_id = CLOCK_MONOTONIC_COARSE; break; case CLOCK_MONOTONIC_RAW: // TODO: use a special CLOCK_MONOTONIC_RAW_COARSE like mechanism here break; case CLOCK_REALTIME: clock_id = CLOCK_REALTIME_COARSE; break; default: break; } } return TimeManagement::the().current_time(clock_id); } TimerQueue& TimerQueue::the() { return *s_the; } UNMAP_AFTER_INIT TimerQueue::TimerQueue() { m_ticks_per_second = TimeManagement::the().ticks_per_second(); } bool TimerQueue::add_timer_without_id(NonnullRefPtr<Timer> timer, clockid_t clock_id, const Time& deadline, Function<void()>&& callback) { if (deadline <= TimeManagement::the().current_time(clock_id)) return false; // Because timer handlers can execute on any processor and there is // a race between executing a timer handler and cancel_timer() this // *must* be a RefPtr<Timer>. Otherwise calling cancel_timer() could // inadvertently cancel another timer that has been created between // returning from the timer handler and a call to cancel_timer(). timer->setup(clock_id, deadline, move(callback)); ScopedSpinLock lock(g_timerqueue_lock); timer->m_id = 0; // Don't generate a timer id add_timer_locked(move(timer)); return true; } TimerId TimerQueue::add_timer(NonnullRefPtr<Timer>&& timer) { ScopedSpinLock lock(g_timerqueue_lock); timer->m_id = ++m_timer_id_count; VERIFY(timer->m_id != 0); // wrapped auto id = timer->m_id; add_timer_locked(move(timer)); return id; } void TimerQueue::add_timer_locked(NonnullRefPtr<Timer> timer) { Time timer_expiration = timer->m_expires; timer->clear_cancelled(); timer->clear_callback_finished(); timer->set_in_use(); auto& queue = queue_for_timer(*timer); if (queue.list.is_empty()) { queue.list.append(timer.leak_ref()); queue.next_timer_due = timer_expiration; } else { Timer* following_timer = nullptr; for (auto& t : queue.list) { if (t.m_expires > timer_expiration) { following_timer = &t; break; } } if (following_timer) { bool next_timer_needs_update = queue.list.first() == following_timer; queue.list.insert_before(*following_timer, timer.leak_ref()); if (next_timer_needs_update) queue.next_timer_due = timer_expiration; } else { queue.list.append(timer.leak_ref()); } } } TimerId TimerQueue::add_timer(clockid_t clock_id, const Time& deadline, Function<void()>&& callback) { auto expires = TimeManagement::the().current_time(clock_id); expires = expires + deadline; auto timer = new Timer(); VERIFY(timer); timer->setup(clock_id, expires, move(callback)); return add_timer(adopt_ref(*timer)); } bool TimerQueue::cancel_timer(TimerId id) { Timer* found_timer = nullptr; Queue* timer_queue = nullptr; ScopedSpinLock lock(g_timerqueue_lock); for (auto& timer : m_timer_queue_monotonic.list) { if (timer.m_id == id) { found_timer = &timer; timer_queue = &m_timer_queue_monotonic; break; } } if (found_timer == nullptr) { for (auto& timer : m_timer_queue_realtime.list) { if (timer.m_id == id) { found_timer = &timer; timer_queue = &m_timer_queue_realtime; break; } }; } if (found_timer) { VERIFY(timer_queue); remove_timer_locked(*timer_queue, *found_timer); return true; } // The timer may be executing right now, if it is then it should // be in m_timers_executing. This is the case when the deferred // call has been queued but not yet executed. for (auto& timer : m_timers_executing) { if (timer.m_id == id) { found_timer = &timer; break; } } if (!found_timer) return false; // Keep a reference while we unlock NonnullRefPtr<Timer> executing_timer(*found_timer); lock.unlock(); if (!found_timer->set_cancelled()) { // We cancelled it even though the deferred call has been queued already. // We do not unref the timer here because the deferred call is still going // too need it! lock.lock(); VERIFY(m_timers_executing.contains(*found_timer)); m_timers_executing.remove(*found_timer); return true; } // At this point the deferred call is queued and is being executed // on another processor. We need to wait until it's complete! while (!found_timer->is_callback_finished()) Processor::wait_check(); return true; } bool TimerQueue::cancel_timer(Timer& timer, bool* was_in_use) { bool in_use = timer.is_in_use(); if (was_in_use) *was_in_use = in_use; // If the timer isn't in use, the cancellation is a no-op. if (!in_use) { VERIFY(!timer.m_list_node.is_in_list()); return false; } bool did_already_run = timer.set_cancelled(); auto& timer_queue = queue_for_timer(timer); if (!did_already_run) { timer.clear_in_use(); ScopedSpinLock lock(g_timerqueue_lock); if (timer_queue.list.contains(timer)) { // The timer has not fired, remove it VERIFY(timer.ref_count() > 1); remove_timer_locked(timer_queue, timer); return true; } // The timer was queued to execute but hasn't had a chance // to run. In this case, it should still be in m_timers_executing // and we don't need to spin. It still holds a reference // that will be dropped when it does get a chance to run, // but since we called set_cancelled it will only drop its reference VERIFY(m_timers_executing.contains(timer)); m_timers_executing.remove(timer); return true; } // At this point the deferred call is queued and is being executed // on another processor. We need to wait until it's complete! while (!timer.is_callback_finished()) Processor::wait_check(); return false; } void TimerQueue::remove_timer_locked(Queue& queue, Timer& timer) { bool was_next_timer = (queue.list.first() == &timer); queue.list.remove(timer); auto now = timer.now(false); if (timer.m_expires > now) timer.m_remaining = timer.m_expires - now; if (was_next_timer) update_next_timer_due(queue); // Whenever we remove a timer that was still queued (but hasn't been // fired) we added a reference to it. So, when removing it from the // queue we need to drop that reference. timer.unref(); } void TimerQueue::fire() { ScopedSpinLock lock(g_timerqueue_lock); auto fire_timers = [&](Queue& queue) { auto* timer = queue.list.first(); VERIFY(timer); VERIFY(queue.next_timer_due == timer->m_expires); while (timer && timer->now(true) > timer->m_expires) { queue.list.remove(*timer); m_timers_executing.append(*timer); update_next_timer_due(queue); lock.unlock(); // Defer executing the timer outside of the irq handler Processor::deferred_call_queue([this, timer]() { // Check if we were cancelled in between being triggered // by the timer irq handler and now. If so, just drop // our reference and don't execute the callback. if (!timer->set_cancelled()) { timer->m_callback(); ScopedSpinLock lock(g_timerqueue_lock); m_timers_executing.remove(*timer); } timer->clear_in_use(); timer->set_callback_finished(); // Drop the reference we added when queueing the timer timer->unref(); }); lock.lock(); timer = queue.list.first(); } }; if (!m_timer_queue_monotonic.list.is_empty()) fire_timers(m_timer_queue_monotonic); if (!m_timer_queue_realtime.list.is_empty()) fire_timers(m_timer_queue_realtime); } void TimerQueue::update_next_timer_due(Queue& queue) { VERIFY(g_timerqueue_lock.is_locked()); if (auto* next_timer = queue.list.first()) queue.next_timer_due = next_timer->m_expires; else queue.next_timer_due = {}; } }
org #4000 ld bc, 1 and b ld hl, var1 add hl, bc ld (hl), a loop: jr loop org #c000 var1: db 1
; A008706: Coordination sequence for 3.3.3.4.4 planar net. ; 1,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,105,110,115,120,125,130,135,140,145,150,155,160,165,170,175,180,185,190,195,200,205,210,215,220,225,230,235,240,245,250,255,260,265,270,275,280,285,290,295,300,305,310,315,320,325,330,335,340,345,350,355,360,365,370,375,380,385,390,395,400,405,410,415,420,425,430,435,440,445,450,455,460,465,470,475,480,485,490,495 pow $1,$0 mul $0,5 gcd $1,$0 mov $0,$1
dnl MIPS64 mpn_add_n -- Add two limb vectors of the same length > 0 and store dnl sum in a third limb vector. dnl Copyright 1995, 2000, 2001, 2002 Free Software Foundation, Inc. dnl This file is part of the GNU MP Library. dnl The GNU MP Library is free software; you can redistribute it and/or modify dnl it under the terms of the GNU Lesser General Public License as published dnl by the Free Software Foundation; either version 3 of the License, or (at dnl your option) any later version. dnl The GNU MP Library is distributed in the hope that it will be useful, but dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public dnl License for more details. dnl You should have received a copy of the GNU Lesser General Public License dnl along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. include(`../config.m4') C INPUT PARAMETERS C res_ptr $4 C s1_ptr $5 C s2_ptr $6 C size $7 ASM_START() PROLOGUE(mpn_add_n) ld $10,0($5) ld $11,0($6) daddiu $7,$7,-1 and $9,$7,4-1 C number of limbs in first loop beq $9,$0,.L0 C if multiple of 4 limbs, skip first loop move $2,$0 dsubu $7,$7,$9 .Loop0: daddiu $9,$9,-1 ld $12,8($5) daddu $11,$11,$2 ld $13,8($6) sltu $8,$11,$2 daddu $11,$10,$11 sltu $2,$11,$10 sd $11,0($4) or $2,$2,$8 daddiu $5,$5,8 daddiu $6,$6,8 move $10,$12 move $11,$13 bne $9,$0,.Loop0 daddiu $4,$4,8 .L0: beq $7,$0,.Lend nop .Loop: daddiu $7,$7,-4 ld $12,8($5) daddu $11,$11,$10 ld $13,8($6) sltu $8,$11,$10 daddu $11,$11,$2 sltu $2,$11,$2 sd $11,0($4) or $2,$2,$8 ld $10,16($5) daddu $13,$13,$12 ld $11,16($6) sltu $8,$13,$12 daddu $13,$13,$2 sltu $2,$13,$2 sd $13,8($4) or $2,$2,$8 ld $12,24($5) daddu $11,$11,$10 ld $13,24($6) sltu $8,$11,$10 daddu $11,$11,$2 sltu $2,$11,$2 sd $11,16($4) or $2,$2,$8 ld $10,32($5) daddu $13,$13,$12 ld $11,32($6) sltu $8,$13,$12 daddu $13,$13,$2 sltu $2,$13,$2 sd $13,24($4) or $2,$2,$8 daddiu $5,$5,32 daddiu $6,$6,32 bne $7,$0,.Loop daddiu $4,$4,32 .Lend: daddu $11,$11,$2 sltu $8,$11,$2 daddu $11,$10,$11 sltu $2,$11,$10 sd $11,0($4) j $31 or $2,$2,$8 EPILOGUE(mpn_add_n)
############################################################################### # Copyright 2019 Intel Corporation # All Rights Reserved. # # If this software was obtained under the Intel Simplified Software License, # the following terms apply: # # The source code, information and material ("Material") contained herein is # owned by Intel Corporation or its suppliers or licensors, and title to such # Material remains with Intel Corporation or its suppliers or licensors. The # Material contains proprietary information of Intel or its suppliers and # licensors. The Material is protected by worldwide copyright laws and treaty # provisions. No part of the Material may be used, copied, reproduced, # modified, published, uploaded, posted, transmitted, distributed or disclosed # in any way without Intel's prior express written permission. No license under # any patent, copyright or other intellectual property rights in the Material # is granted to or conferred upon you, either expressly, by implication, # inducement, estoppel or otherwise. Any license under such intellectual # property rights must be express and approved by Intel in writing. # # Unless otherwise agreed by Intel in writing, you may not remove or alter this # notice or any other notice embedded in Materials by Intel or Intel's # suppliers or licensors in any way. # # # If this software was obtained under the Apache License, Version 2.0 (the # "License"), the following terms apply: # # You may not use this file except in compliance with the License. You may # obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 # # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # # See the License for the specific language governing permissions and # limitations under the License. ############################################################################### .section .note.GNU-stack,"",%progbits .text .p2align 5, 0x90 Lpoly: .quad 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFF, 0x0, 0xFFFFFFFF00000001 LRR: .quad 0x3, 0xfffffffbffffffff, 0xfffffffffffffffe, 0x4fffffffd LOne: .long 1,1,1,1,1,1,1,1 LTwo: .long 2,2,2,2,2,2,2,2 LThree: .long 3,3,3,3,3,3,3,3 .p2align 5, 0x90 .globl p256r1_mul_by_2 .type p256r1_mul_by_2, @function p256r1_mul_by_2: push %r12 push %r13 xor %r13, %r13 movq (%rsi), %r8 movq (8)(%rsi), %r9 movq (16)(%rsi), %r10 movq (24)(%rsi), %r11 shld $(1), %r11, %r13 shld $(1), %r10, %r11 shld $(1), %r9, %r10 shld $(1), %r8, %r9 shl $(1), %r8 mov %r8, %rax mov %r9, %rdx mov %r10, %rcx mov %r11, %r12 subq Lpoly+0(%rip), %rax sbbq Lpoly+8(%rip), %rdx sbbq Lpoly+16(%rip), %rcx sbbq Lpoly+24(%rip), %r12 sbb $(0), %r13 cmove %rax, %r8 cmove %rdx, %r9 cmove %rcx, %r10 cmove %r12, %r11 movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) vzeroupper pop %r13 pop %r12 ret .Lfe1: .size p256r1_mul_by_2, .Lfe1-(p256r1_mul_by_2) .p2align 5, 0x90 .globl p256r1_div_by_2 .type p256r1_div_by_2, @function p256r1_div_by_2: push %r12 push %r13 push %r14 movq (%rsi), %r8 movq (8)(%rsi), %r9 movq (16)(%rsi), %r10 movq (24)(%rsi), %r11 xor %r13, %r13 xor %r14, %r14 mov %r8, %rax mov %r9, %rdx mov %r10, %rcx mov %r11, %r12 addq Lpoly+0(%rip), %rax adcq Lpoly+8(%rip), %rdx adcq Lpoly+16(%rip), %rcx adcq Lpoly+24(%rip), %r12 adc $(0), %r13 test $(1), %r8 cmovne %rax, %r8 cmovne %rdx, %r9 cmovne %rcx, %r10 cmovne %r12, %r11 cmovne %r13, %r14 shrd $(1), %r9, %r8 shrd $(1), %r10, %r9 shrd $(1), %r11, %r10 shrd $(1), %r14, %r11 movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) vzeroupper pop %r14 pop %r13 pop %r12 ret .Lfe2: .size p256r1_div_by_2, .Lfe2-(p256r1_div_by_2) .p2align 5, 0x90 .globl p256r1_mul_by_3 .type p256r1_mul_by_3, @function p256r1_mul_by_3: push %r12 push %r13 xor %r13, %r13 movq (%rsi), %r8 movq (8)(%rsi), %r9 movq (16)(%rsi), %r10 movq (24)(%rsi), %r11 shld $(1), %r11, %r13 shld $(1), %r10, %r11 shld $(1), %r9, %r10 shld $(1), %r8, %r9 shl $(1), %r8 mov %r8, %rax mov %r9, %rdx mov %r10, %rcx mov %r11, %r12 subq Lpoly+0(%rip), %rax sbbq Lpoly+8(%rip), %rdx sbbq Lpoly+16(%rip), %rcx sbbq Lpoly+24(%rip), %r12 sbb $(0), %r13 cmove %rax, %r8 cmove %rdx, %r9 cmove %rcx, %r10 cmove %r12, %r11 xor %r13, %r13 addq (%rsi), %r8 adcq (8)(%rsi), %r9 adcq (16)(%rsi), %r10 adcq (24)(%rsi), %r11 adc $(0), %r13 mov %r8, %rax mov %r9, %rdx mov %r10, %rcx mov %r11, %r12 subq Lpoly+0(%rip), %rax sbbq Lpoly+8(%rip), %rdx sbbq Lpoly+16(%rip), %rcx sbbq Lpoly+24(%rip), %r12 sbb $(0), %r13 cmove %rax, %r8 cmove %rdx, %r9 cmove %rcx, %r10 cmove %r12, %r11 movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) vzeroupper pop %r13 pop %r12 ret .Lfe3: .size p256r1_mul_by_3, .Lfe3-(p256r1_mul_by_3) .p2align 5, 0x90 .globl p256r1_add .type p256r1_add, @function p256r1_add: push %r12 push %r13 xor %r13, %r13 movq (%rsi), %r8 movq (8)(%rsi), %r9 movq (16)(%rsi), %r10 movq (24)(%rsi), %r11 addq (%rdx), %r8 adcq (8)(%rdx), %r9 adcq (16)(%rdx), %r10 adcq (24)(%rdx), %r11 adc $(0), %r13 mov %r8, %rax mov %r9, %rdx mov %r10, %rcx mov %r11, %r12 subq Lpoly+0(%rip), %rax sbbq Lpoly+8(%rip), %rdx sbbq Lpoly+16(%rip), %rcx sbbq Lpoly+24(%rip), %r12 sbb $(0), %r13 cmove %rax, %r8 cmove %rdx, %r9 cmove %rcx, %r10 cmove %r12, %r11 movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) vzeroupper pop %r13 pop %r12 ret .Lfe4: .size p256r1_add, .Lfe4-(p256r1_add) .p2align 5, 0x90 .globl p256r1_sub .type p256r1_sub, @function p256r1_sub: push %r12 push %r13 xor %r13, %r13 movq (%rsi), %r8 movq (8)(%rsi), %r9 movq (16)(%rsi), %r10 movq (24)(%rsi), %r11 subq (%rdx), %r8 sbbq (8)(%rdx), %r9 sbbq (16)(%rdx), %r10 sbbq (24)(%rdx), %r11 sbb $(0), %r13 mov %r8, %rax mov %r9, %rdx mov %r10, %rcx mov %r11, %r12 addq Lpoly+0(%rip), %rax adcq Lpoly+8(%rip), %rdx adcq Lpoly+16(%rip), %rcx adcq Lpoly+24(%rip), %r12 test %r13, %r13 cmovne %rax, %r8 cmovne %rdx, %r9 cmovne %rcx, %r10 cmovne %r12, %r11 movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) vzeroupper pop %r13 pop %r12 ret .Lfe5: .size p256r1_sub, .Lfe5-(p256r1_sub) .p2align 5, 0x90 .globl p256r1_neg .type p256r1_neg, @function p256r1_neg: push %r12 push %r13 xor %r13, %r13 xor %r8, %r8 xor %r9, %r9 xor %r10, %r10 xor %r11, %r11 subq (%rsi), %r8 sbbq (8)(%rsi), %r9 sbbq (16)(%rsi), %r10 sbbq (24)(%rsi), %r11 sbb $(0), %r13 mov %r8, %rax mov %r9, %rdx mov %r10, %rcx mov %r11, %r12 addq Lpoly+0(%rip), %rax adcq Lpoly+8(%rip), %rdx adcq Lpoly+16(%rip), %rcx adcq Lpoly+24(%rip), %r12 test %r13, %r13 cmovne %rax, %r8 cmovne %rdx, %r9 cmovne %rcx, %r10 cmovne %r12, %r11 movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) vzeroupper pop %r13 pop %r12 ret .Lfe6: .size p256r1_neg, .Lfe6-(p256r1_neg) .p2align 5, 0x90 p256r1_mmull: xor %r13, %r13 movq (%rbx), %rax mulq (%rsi) mov %rax, %r8 mov %rdx, %r9 movq (%rbx), %rax mulq (8)(%rsi) add %rax, %r9 adc $(0), %rdx mov %rdx, %r10 movq (%rbx), %rax mulq (16)(%rsi) add %rax, %r10 adc $(0), %rdx mov %rdx, %r11 movq (%rbx), %rax mulq (24)(%rsi) add %rax, %r11 adc $(0), %rdx mov %rdx, %r12 mov %r8, %rax shl $(32), %rax mov %r8, %rdx shr $(32), %rdx mov %r8, %rcx mov %r8, %rbp xor %r8, %r8 sub %rax, %rcx sbb %rdx, %rbp add %rax, %r9 adc %rdx, %r10 adc %rcx, %r11 adc %rbp, %r12 adc $(0), %r13 movq (8)(%rbx), %rax mulq (%rsi) add %rax, %r9 adc $(0), %rdx mov %rdx, %rcx movq (8)(%rbx), %rax mulq (8)(%rsi) add %rcx, %r10 adc $(0), %rdx add %rax, %r10 adc $(0), %rdx mov %rdx, %rcx movq (8)(%rbx), %rax mulq (16)(%rsi) add %rcx, %r11 adc $(0), %rdx add %rax, %r11 adc $(0), %rdx mov %rdx, %rcx movq (8)(%rbx), %rax mulq (24)(%rsi) add %rcx, %r12 adc $(0), %rdx add %rax, %r12 adc %rdx, %r13 adc $(0), %r8 mov %r9, %rax shl $(32), %rax mov %r9, %rdx shr $(32), %rdx mov %r9, %rcx mov %r9, %rbp xor %r9, %r9 sub %rax, %rcx sbb %rdx, %rbp add %rax, %r10 adc %rdx, %r11 adc %rcx, %r12 adc %rbp, %r13 adc $(0), %r8 movq (16)(%rbx), %rax mulq (%rsi) add %rax, %r10 adc $(0), %rdx mov %rdx, %rcx movq (16)(%rbx), %rax mulq (8)(%rsi) add %rcx, %r11 adc $(0), %rdx add %rax, %r11 adc $(0), %rdx mov %rdx, %rcx movq (16)(%rbx), %rax mulq (16)(%rsi) add %rcx, %r12 adc $(0), %rdx add %rax, %r12 adc $(0), %rdx mov %rdx, %rcx movq (16)(%rbx), %rax mulq (24)(%rsi) add %rcx, %r13 adc $(0), %rdx add %rax, %r13 adc %rdx, %r8 adc $(0), %r9 mov %r10, %rax shl $(32), %rax mov %r10, %rdx shr $(32), %rdx mov %r10, %rcx mov %r10, %rbp xor %r10, %r10 sub %rax, %rcx sbb %rdx, %rbp add %rax, %r11 adc %rdx, %r12 adc %rcx, %r13 adc %rbp, %r8 adc $(0), %r9 movq (24)(%rbx), %rax mulq (%rsi) add %rax, %r11 adc $(0), %rdx mov %rdx, %rcx movq (24)(%rbx), %rax mulq (8)(%rsi) add %rcx, %r12 adc $(0), %rdx add %rax, %r12 adc $(0), %rdx mov %rdx, %rcx movq (24)(%rbx), %rax mulq (16)(%rsi) add %rcx, %r13 adc $(0), %rdx add %rax, %r13 adc $(0), %rdx mov %rdx, %rcx movq (24)(%rbx), %rax mulq (24)(%rsi) add %rcx, %r8 adc $(0), %rdx add %rax, %r8 adc %rdx, %r9 adc $(0), %r10 mov %r11, %rax shl $(32), %rax mov %r11, %rdx shr $(32), %rdx mov %r11, %rcx mov %r11, %rbp xor %r11, %r11 sub %rax, %rcx sbb %rdx, %rbp add %rax, %r12 adc %rdx, %r13 adc %rcx, %r8 adc %rbp, %r9 adc $(0), %r10 movq Lpoly+0(%rip), %rax movq Lpoly+8(%rip), %rdx movq Lpoly+16(%rip), %rcx movq Lpoly+24(%rip), %rbp mov %r12, %rbx mov %r13, %r11 mov %r8, %r14 mov %r9, %r15 sub %rax, %rbx sbb %rdx, %r11 sbb %rcx, %r14 sbb %rbp, %r15 sbb $(0), %r10 cmovnc %rbx, %r12 cmovnc %r11, %r13 cmovnc %r14, %r8 cmovnc %r15, %r9 movq %r12, (%rdi) movq %r13, (8)(%rdi) movq %r8, (16)(%rdi) movq %r9, (24)(%rdi) ret .p2align 5, 0x90 .globl p256r1_mul_montl .type p256r1_mul_montl, @function p256r1_mul_montl: push %rbp push %rbx push %r12 push %r13 push %r14 push %r15 mov %rdx, %rbx call p256r1_mmull vzeroupper pop %r15 pop %r14 pop %r13 pop %r12 pop %rbx pop %rbp ret .Lfe7: .size p256r1_mul_montl, .Lfe7-(p256r1_mul_montl) .p2align 5, 0x90 .globl p256r1_to_mont .type p256r1_to_mont, @function p256r1_to_mont: push %rbp push %rbx push %r12 push %r13 push %r14 push %r15 lea LRR(%rip), %rbx call p256r1_mmull vzeroupper pop %r15 pop %r14 pop %r13 pop %r12 pop %rbx pop %rbp ret .Lfe8: .size p256r1_to_mont, .Lfe8-(p256r1_to_mont) .p2align 5, 0x90 p256r1_mmulx: xor %r13, %r13 xor %rdx, %rdx movq (%rbx), %rdx mulxq (%rsi), %r8, %r9 mulxq (8)(%rsi), %rcx, %r10 add %rcx, %r9 mulxq (16)(%rsi), %rcx, %r11 adc %rcx, %r10 mulxq (24)(%rsi), %rcx, %r12 adc %rcx, %r11 adc $(0), %r12 mov %r8, %rax shl $(32), %rax mov %r8, %rdx shr $(32), %rdx mov %r8, %rcx mov %r8, %rbp xor %r8, %r8 sub %rax, %rcx sbb %rdx, %rbp add %rax, %r9 adc %rdx, %r10 adc %rcx, %r11 adc %rbp, %r12 adc $(0), %r13 movq (8)(%rbx), %rdx mulxq (%rsi), %rcx, %rbp adcx %rcx, %r9 adox %rbp, %r10 mulxq (8)(%rsi), %rcx, %rbp adcx %rcx, %r10 adox %rbp, %r11 mulxq (16)(%rsi), %rcx, %rbp adcx %rcx, %r11 adox %rbp, %r12 mulxq (24)(%rsi), %rcx, %rbp adcx %rcx, %r12 adox %rbp, %r13 adcx %r8, %r13 adox %r8, %r8 adc $(0), %r8 mov %r9, %rax shl $(32), %rax mov %r9, %rdx shr $(32), %rdx mov %r9, %rcx mov %r9, %rbp xor %r9, %r9 sub %rax, %rcx sbb %rdx, %rbp add %rax, %r10 adc %rdx, %r11 adc %rcx, %r12 adc %rbp, %r13 adc $(0), %r8 movq (16)(%rbx), %rdx mulxq (%rsi), %rcx, %rbp adcx %rcx, %r10 adox %rbp, %r11 mulxq (8)(%rsi), %rcx, %rbp adcx %rcx, %r11 adox %rbp, %r12 mulxq (16)(%rsi), %rcx, %rbp adcx %rcx, %r12 adox %rbp, %r13 mulxq (24)(%rsi), %rcx, %rbp adcx %rcx, %r13 adox %rbp, %r8 adcx %r9, %r8 adox %r9, %r9 adc $(0), %r9 mov %r10, %rax shl $(32), %rax mov %r10, %rdx shr $(32), %rdx mov %r10, %rcx mov %r10, %rbp xor %r10, %r10 sub %rax, %rcx sbb %rdx, %rbp add %rax, %r11 adc %rdx, %r12 adc %rcx, %r13 adc %rbp, %r8 adc $(0), %r9 movq (24)(%rbx), %rdx mulxq (%rsi), %rcx, %rbp adcx %rcx, %r11 adox %rbp, %r12 mulxq (8)(%rsi), %rcx, %rbp adcx %rcx, %r12 adox %rbp, %r13 mulxq (16)(%rsi), %rcx, %rbp adcx %rcx, %r13 adox %rbp, %r8 mulxq (24)(%rsi), %rcx, %rbp adcx %rcx, %r8 adox %rbp, %r9 adcx %r10, %r9 adox %r10, %r10 adc $(0), %r10 mov %r11, %rax shl $(32), %rax mov %r11, %rdx shr $(32), %rdx mov %r11, %rcx mov %r11, %rbp xor %r11, %r11 sub %rax, %rcx sbb %rdx, %rbp add %rax, %r12 adc %rdx, %r13 adc %rcx, %r8 adc %rbp, %r9 adc $(0), %r10 movq Lpoly+0(%rip), %rax movq Lpoly+8(%rip), %rdx movq Lpoly+16(%rip), %rcx movq Lpoly+24(%rip), %rbp mov %r12, %rbx mov %r13, %r11 mov %r8, %r14 mov %r9, %r15 sub %rax, %rbx sbb %rdx, %r11 sbb %rcx, %r14 sbb %rbp, %r15 sbb $(0), %r10 cmovnc %rbx, %r12 cmovnc %r11, %r13 cmovnc %r14, %r8 cmovnc %r15, %r9 movq %r12, (%rdi) movq %r13, (8)(%rdi) movq %r8, (16)(%rdi) movq %r9, (24)(%rdi) ret .p2align 5, 0x90 .globl p256r1_mul_montx .type p256r1_mul_montx, @function p256r1_mul_montx: push %rbp push %rbx push %r12 push %r13 push %r14 push %r15 mov %rdx, %rbx call p256r1_mmulx vzeroupper pop %r15 pop %r14 pop %r13 pop %r12 pop %rbx pop %rbp ret .Lfe9: .size p256r1_mul_montx, .Lfe9-(p256r1_mul_montx) .p2align 5, 0x90 .globl p256r1_sqr_montl .type p256r1_sqr_montl, @function p256r1_sqr_montl: push %rbp push %rbx push %r12 push %r13 push %r14 push %r15 movq (%rsi), %rbx movq (8)(%rsi), %rax mul %rbx mov %rax, %r9 mov %rdx, %r10 movq (16)(%rsi), %rax mul %rbx add %rax, %r10 adc $(0), %rdx mov %rdx, %r11 movq (24)(%rsi), %rax mul %rbx add %rax, %r11 adc $(0), %rdx mov %rdx, %r12 movq (8)(%rsi), %rbx movq (16)(%rsi), %rax mul %rbx add %rax, %r11 adc $(0), %rdx mov %rdx, %rbp movq (24)(%rsi), %rax mul %rbx add %rax, %r12 adc $(0), %rdx add %rbp, %r12 adc $(0), %rdx mov %rdx, %r13 movq (16)(%rsi), %rbx movq (24)(%rsi), %rax mul %rbx add %rax, %r13 adc $(0), %rdx mov %rdx, %r14 xor %r15, %r15 shld $(1), %r14, %r15 shld $(1), %r13, %r14 shld $(1), %r12, %r13 shld $(1), %r11, %r12 shld $(1), %r10, %r11 shld $(1), %r9, %r10 shl $(1), %r9 movq (%rsi), %rax mul %rax mov %rax, %r8 add %rdx, %r9 adc $(0), %r10 movq (8)(%rsi), %rax mul %rax add %rax, %r10 adc %rdx, %r11 adc $(0), %r12 movq (16)(%rsi), %rax mul %rax add %rax, %r12 adc %rdx, %r13 adc $(0), %r14 movq (24)(%rsi), %rax mul %rax add %rax, %r14 adc %rdx, %r15 mov %r8, %rcx shl $(32), %rcx mov %r8, %rbp shr $(32), %rbp mov %r8, %rbx mov %r8, %rdx xor %r8, %r8 sub %rcx, %rbx sbb %rbp, %rdx add %rcx, %r9 adc %rbp, %r10 adc %rbx, %r11 adc %rdx, %r12 adc $(0), %r8 mov %r9, %rcx shl $(32), %rcx mov %r9, %rbp shr $(32), %rbp mov %r9, %rbx mov %r9, %rdx xor %r9, %r9 sub %rcx, %rbx sbb %rbp, %rdx add %rcx, %r10 adc %rbp, %r11 adc %rbx, %r12 adc %rdx, %r13 adc $(0), %r9 add %r8, %r13 adc $(0), %r9 mov %r10, %rcx shl $(32), %rcx mov %r10, %rbp shr $(32), %rbp mov %r10, %rbx mov %r10, %rdx xor %r10, %r10 sub %rcx, %rbx sbb %rbp, %rdx add %rcx, %r11 adc %rbp, %r12 adc %rbx, %r13 adc %rdx, %r14 adc $(0), %r10 add %r9, %r14 adc $(0), %r10 mov %r11, %rcx shl $(32), %rcx mov %r11, %rbp shr $(32), %rbp mov %r11, %rbx mov %r11, %rdx xor %r11, %r11 sub %rcx, %rbx sbb %rbp, %rdx add %rcx, %r12 adc %rbp, %r13 adc %rbx, %r14 adc %rdx, %r15 adc $(0), %r11 add %r10, %r15 adc $(0), %r11 movq Lpoly+0(%rip), %rcx movq Lpoly+8(%rip), %rbp movq Lpoly+16(%rip), %rbx movq Lpoly+24(%rip), %rdx mov %r12, %rax mov %r13, %r8 mov %r14, %r9 mov %r15, %r10 sub %rcx, %rax sbb %rbp, %r8 sbb %rbx, %r9 sbb %rdx, %r10 sbb $(0), %r11 cmovnc %rax, %r12 cmovnc %r8, %r13 cmovnc %r9, %r14 cmovnc %r10, %r15 movq %r12, (%rdi) movq %r13, (8)(%rdi) movq %r14, (16)(%rdi) movq %r15, (24)(%rdi) vzeroupper pop %r15 pop %r14 pop %r13 pop %r12 pop %rbx pop %rbp ret .Lfe10: .size p256r1_sqr_montl, .Lfe10-(p256r1_sqr_montl) .p2align 5, 0x90 .globl p256r1_sqr_montx .type p256r1_sqr_montx, @function p256r1_sqr_montx: push %rbp push %rbx push %r12 push %r13 push %r14 push %r15 movq (%rsi), %rdx mulxq (8)(%rsi), %r9, %r10 mulxq (16)(%rsi), %rcx, %r11 add %rcx, %r10 mulxq (24)(%rsi), %rcx, %r12 adc %rcx, %r11 adc $(0), %r12 movq (8)(%rsi), %rdx xor %r13, %r13 mulxq (16)(%rsi), %rcx, %rbp adcx %rcx, %r11 adox %rbp, %r12 mulxq (24)(%rsi), %rcx, %rbp adcx %rcx, %r12 adox %rbp, %r13 adc $(0), %r13 movq (16)(%rsi), %rdx mulxq (24)(%rsi), %rcx, %r14 add %rcx, %r13 adc $(0), %r14 xor %r15, %r15 shld $(1), %r14, %r15 shld $(1), %r13, %r14 shld $(1), %r12, %r13 shld $(1), %r11, %r12 shld $(1), %r10, %r11 shld $(1), %r9, %r10 shl $(1), %r9 xor %r8, %r8 movq (%rsi), %rdx mulx %rdx, %r8, %rbp adcx %rbp, %r9 movq (8)(%rsi), %rdx mulx %rdx, %rcx, %rbp adcx %rcx, %r10 adcx %rbp, %r11 movq (16)(%rsi), %rdx mulx %rdx, %rcx, %rbp adcx %rcx, %r12 adcx %rbp, %r13 movq (24)(%rsi), %rdx mulx %rdx, %rcx, %rbp adcx %rcx, %r14 adcx %rbp, %r15 mov %r8, %rcx shl $(32), %rcx mov %r8, %rbp shr $(32), %rbp mov %r8, %rbx mov %r8, %rdx xor %r8, %r8 sub %rcx, %rbx sbb %rbp, %rdx add %rcx, %r9 adc %rbp, %r10 adc %rbx, %r11 adc %rdx, %r12 adc $(0), %r8 mov %r9, %rcx shl $(32), %rcx mov %r9, %rbp shr $(32), %rbp mov %r9, %rbx mov %r9, %rdx xor %r9, %r9 sub %rcx, %rbx sbb %rbp, %rdx add %rcx, %r10 adc %rbp, %r11 adc %rbx, %r12 adc %rdx, %r13 adc $(0), %r9 add %r8, %r13 adc $(0), %r9 mov %r10, %rcx shl $(32), %rcx mov %r10, %rbp shr $(32), %rbp mov %r10, %rbx mov %r10, %rdx xor %r10, %r10 sub %rcx, %rbx sbb %rbp, %rdx add %rcx, %r11 adc %rbp, %r12 adc %rbx, %r13 adc %rdx, %r14 adc $(0), %r10 add %r9, %r14 adc $(0), %r10 mov %r11, %rcx shl $(32), %rcx mov %r11, %rbp shr $(32), %rbp mov %r11, %rbx mov %r11, %rdx xor %r11, %r11 sub %rcx, %rbx sbb %rbp, %rdx add %rcx, %r12 adc %rbp, %r13 adc %rbx, %r14 adc %rdx, %r15 adc $(0), %r11 add %r10, %r15 adc $(0), %r11 movq Lpoly+0(%rip), %rcx movq Lpoly+8(%rip), %rbp movq Lpoly+16(%rip), %rbx movq Lpoly+24(%rip), %rdx mov %r12, %rax mov %r13, %r8 mov %r14, %r9 mov %r15, %r10 sub %rcx, %rax sbb %rbp, %r8 sbb %rbx, %r9 sbb %rdx, %r10 sbb $(0), %r11 cmovnc %rax, %r12 cmovnc %r8, %r13 cmovnc %r9, %r14 cmovnc %r10, %r15 movq %r12, (%rdi) movq %r13, (8)(%rdi) movq %r14, (16)(%rdi) movq %r15, (24)(%rdi) vzeroupper pop %r15 pop %r14 pop %r13 pop %r12 pop %rbx pop %rbp ret .Lfe11: .size p256r1_sqr_montx, .Lfe11-(p256r1_sqr_montx) .p2align 5, 0x90 .globl p256r1_mont_back .type p256r1_mont_back, @function p256r1_mont_back: push %r12 push %r13 movq (%rsi), %r10 movq (8)(%rsi), %r11 movq (16)(%rsi), %r12 movq (24)(%rsi), %r13 xor %r8, %r8 xor %r9, %r9 mov %r10, %rax shl $(32), %rax mov %r10, %rdx shr $(32), %rdx mov %r10, %rcx mov %r10, %rsi xor %r10, %r10 sub %rax, %rcx sbb %rdx, %rsi add %rax, %r11 adc %rdx, %r12 adc %rcx, %r13 adc %rsi, %r8 adc $(0), %r9 mov %r11, %rax shl $(32), %rax mov %r11, %rdx shr $(32), %rdx mov %r11, %rcx mov %r11, %rsi xor %r11, %r11 sub %rax, %rcx sbb %rdx, %rsi add %rax, %r12 adc %rdx, %r13 adc %rcx, %r8 adc %rsi, %r9 adc $(0), %r10 mov %r12, %rax shl $(32), %rax mov %r12, %rdx shr $(32), %rdx mov %r12, %rcx mov %r12, %rsi xor %r12, %r12 sub %rax, %rcx sbb %rdx, %rsi add %rax, %r13 adc %rdx, %r8 adc %rcx, %r9 adc %rsi, %r10 adc $(0), %r11 mov %r13, %rax shl $(32), %rax mov %r13, %rdx shr $(32), %rdx mov %r13, %rcx mov %r13, %rsi xor %r13, %r13 sub %rax, %rcx sbb %rdx, %rsi add %rax, %r8 adc %rdx, %r9 adc %rcx, %r10 adc %rsi, %r11 adc $(0), %r12 mov %r8, %rax mov %r9, %rdx mov %r10, %rcx mov %r11, %rsi subq Lpoly+0(%rip), %rax sbbq Lpoly+8(%rip), %rdx sbbq Lpoly+16(%rip), %rcx sbbq Lpoly+24(%rip), %rsi sbb $(0), %r12 cmovnc %rax, %r8 cmovnc %rdx, %r9 cmovnc %rcx, %r10 cmovnc %rsi, %r11 movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) vzeroupper pop %r13 pop %r12 ret .Lfe12: .size p256r1_mont_back, .Lfe12-(p256r1_mont_back) .p2align 5, 0x90 .globl p256r1_select_pp_w5 .type p256r1_select_pp_w5, @function p256r1_select_pp_w5: push %r12 push %r13 movdqa LOne(%rip), %xmm0 movdqa %xmm0, %xmm8 movd %edx, %xmm1 pshufd $(0), %xmm1, %xmm1 pxor %xmm2, %xmm2 pxor %xmm3, %xmm3 pxor %xmm4, %xmm4 pxor %xmm5, %xmm5 pxor %xmm6, %xmm6 pxor %xmm7, %xmm7 mov $(16), %rcx .Lselect_loop_sse_w5gas_13: movdqa %xmm8, %xmm15 pcmpeqd %xmm1, %xmm15 paddd %xmm0, %xmm8 movdqa (%rsi), %xmm9 movdqa (16)(%rsi), %xmm10 movdqa (32)(%rsi), %xmm11 movdqa (48)(%rsi), %xmm12 movdqa (64)(%rsi), %xmm13 movdqa (80)(%rsi), %xmm14 add $(96), %rsi pand %xmm15, %xmm9 pand %xmm15, %xmm10 pand %xmm15, %xmm11 pand %xmm15, %xmm12 pand %xmm15, %xmm13 pand %xmm15, %xmm14 por %xmm9, %xmm2 por %xmm10, %xmm3 por %xmm11, %xmm4 por %xmm12, %xmm5 por %xmm13, %xmm6 por %xmm14, %xmm7 dec %rcx jnz .Lselect_loop_sse_w5gas_13 movdqu %xmm2, (%rdi) movdqu %xmm3, (16)(%rdi) movdqu %xmm4, (32)(%rdi) movdqu %xmm5, (48)(%rdi) movdqu %xmm6, (64)(%rdi) movdqu %xmm7, (80)(%rdi) vzeroupper pop %r13 pop %r12 ret .Lfe13: .size p256r1_select_pp_w5, .Lfe13-(p256r1_select_pp_w5) .p2align 5, 0x90 .globl p256r1_select_ap_w7 .type p256r1_select_ap_w7, @function p256r1_select_ap_w7: push %r12 push %r13 movdqa LOne(%rip), %xmm0 pxor %xmm2, %xmm2 pxor %xmm3, %xmm3 pxor %xmm4, %xmm4 pxor %xmm5, %xmm5 movdqa %xmm0, %xmm8 movd %edx, %xmm1 pshufd $(0), %xmm1, %xmm1 mov $(64), %rcx .Lselect_loop_sse_w7gas_14: movdqa %xmm8, %xmm15 pcmpeqd %xmm1, %xmm15 paddd %xmm0, %xmm8 movdqa (%rsi), %xmm9 movdqa (16)(%rsi), %xmm10 movdqa (32)(%rsi), %xmm11 movdqa (48)(%rsi), %xmm12 add $(64), %rsi pand %xmm15, %xmm9 pand %xmm15, %xmm10 pand %xmm15, %xmm11 pand %xmm15, %xmm12 por %xmm9, %xmm2 por %xmm10, %xmm3 por %xmm11, %xmm4 por %xmm12, %xmm5 dec %rcx jnz .Lselect_loop_sse_w7gas_14 movdqu %xmm2, (%rdi) movdqu %xmm3, (16)(%rdi) movdqu %xmm4, (32)(%rdi) movdqu %xmm5, (48)(%rdi) vzeroupper pop %r13 pop %r12 ret .Lfe14: .size p256r1_select_ap_w7, .Lfe14-(p256r1_select_ap_w7)
SECTION code_fp_math16 PUBLIC cm16_sccz80_exp EXTERN cm16_sccz80_read1, expf16 cm16_sccz80_exp: call cm16_sccz80_read1 jp expf16
; ; ; Z88 Maths Routines ; ; C Interface for Small C+ Compiler ; ; 7/12/98 djm ;Convert from integer to FP.. ;We could enter in here with a long in dehl, so, mod to compiler I think! SECTION code_fp IF FORz88 INCLUDE "target/z88/def/fpp.def" ELSE INCLUDE "fpp.def" ENDIF PUBLIC float EXTERN fa .float push de ;msb exx pop hl ld c,0 ;no exponent IF FORz88 fpp(FP_FLT) ELSE ld a,+(FP_FLT) call FPP ENDIF ld (fa+3),hl ld a,c ld (fa+5),a exx ld (fa+1),hl xor a ld (fa),a ret
/* Copyright (c) 2002, 2020, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2.0, as published by the Free Software Foundation. This program is also distributed with certain software (including but not limited to OpenSSL) that is licensed under separate terms, as designated in a particular file or component or in included license documentation. The authors of MySQL hereby grant you an additional permission to link the program and your derivative works with the separately licensed software that they have included with MySQL. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0, for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "sql/set_var.h" #include <string.h> #include <sys/types.h> #include <cstdlib> #include <utility> #include "m_ctype.h" #include "m_string.h" #include "map_helpers.h" #include "my_dbug.h" #include "my_io.h" #include "my_loglevel.h" #include "my_sys.h" #include "mysql/components/services/bits/psi_bits.h" #include "mysql/components/services/log_builtins.h" #include "mysql/components/services/log_shared.h" #include "mysql/plugin_audit.h" #include "mysql/psi/mysql_mutex.h" #include "mysql/psi/mysql_rwlock.h" #include "mysqld_error.h" #include "sql/auth/auth_acls.h" #include "sql/auth/auth_common.h" // SUPER_ACL, generate_password #include "sql/auth/sql_security_ctx.h" #include "sql/derror.h" // ER_THD #include "sql/enum_query_type.h" #include "sql/item.h" #include "sql/item_func.h" #include "sql/log.h" #include "sql/mysqld.h" // system_charset_info #include "sql/persisted_variable.h" #include "sql/protocol_classic.h" #include "sql/session_tracker.h" #include "sql/sql_audit.h" // mysql_audit #include "sql/sql_base.h" // lock_tables #include "sql/sql_class.h" // THD #include "sql/sql_error.h" #include "sql/sql_lex.h" #include "sql/sql_list.h" #include "sql/sql_parse.h" // is_supported_parser_charset #include "sql/sql_select.h" // free_underlaid_joins #include "sql/sql_show.h" // append_identifier #include "sql/sys_vars_shared.h" // PolyLock_mutex #include "sql/system_variables.h" // system_variables #include "sql/table.h" // table #include "sql/thd_raii.h" // Prepared_stmt_arena_holder #include "sql_string.h" using std::min; using std::string; static collation_unordered_map<string, sys_var *> *system_variable_hash; static PolyLock_mutex PLock_global_system_variables( &LOCK_global_system_variables); ulonglong system_variable_hash_version = 0; collation_unordered_map<string, sys_var *> *get_system_variable_hash(void) { return system_variable_hash; } /** list of variables that shouldn't be persisted in all cases */ static collation_unordered_set<string> *never_persistable_vars; /** Get source of a given system variable given its name and name length. */ bool get_sysvar_source(const char *name, uint length, enum enum_variable_source *source) { DBUG_TRACE; bool ret = false; sys_var *sysvar = nullptr; mysql_rwlock_wrlock(&LOCK_system_variables_hash); /* system_variable_hash should have been initialized. */ DBUG_ASSERT(get_system_variable_hash() != nullptr); std::string str(name, length); sysvar = find_or_nullptr(*get_system_variable_hash(), str); if (sysvar == nullptr) { ret = true; } else { *source = sysvar->get_source(); } mysql_rwlock_unlock(&LOCK_system_variables_hash); return ret; } sys_var_chain all_sys_vars = {nullptr, nullptr}; int sys_var_init() { DBUG_TRACE; /* Must be already initialized. */ DBUG_ASSERT(system_charset_info != nullptr); system_variable_hash = new collation_unordered_map<string, sys_var *>( system_charset_info, PSI_INSTRUMENT_ME); never_persistable_vars = new collation_unordered_set<string>( {PERSIST_ONLY_ADMIN_X509_SUBJECT, PERSISTED_GLOBALS_LOAD}, system_charset_info, PSI_INSTRUMENT_ME); if (mysql_add_sys_var_chain(all_sys_vars.first)) goto error; return 0; error: LogErr(ERROR_LEVEL, ER_FAILED_TO_INIT_SYS_VAR); return 1; } int sys_var_add_options(std::vector<my_option> *long_options, int parse_flags) { DBUG_TRACE; for (sys_var *var = all_sys_vars.first; var; var = var->next) { if (var->register_option(long_options, parse_flags)) goto error; } return 0; error: LogErr(ERROR_LEVEL, ER_FAILED_TO_INIT_SYS_VAR); return 1; } void sys_var_end() { DBUG_TRACE; delete system_variable_hash; delete never_persistable_vars; system_variable_hash = nullptr; for (sys_var *var = all_sys_vars.first; var; var = var->next) var->cleanup(); } /** This function will check for necessary privileges needed to perform RESET PERSIST or SET PERSIST[_ONLY] operation. @param [in] thd Pointer to connection handle. @param [in] static_variable describes if variable is static or dynamic @return 0 Success @return 1 Failure */ bool check_priv(THD *thd, bool static_variable) { Security_context *sctx = thd->security_context(); /* for dynamic variables user needs SUPER_ACL or SYSTEM_VARIABLES_ADMIN */ if (!static_variable) { if (!sctx->check_access(SUPER_ACL) && !(sctx->has_global_grant(STRING_WITH_LEN("SYSTEM_VARIABLES_ADMIN")) .first)) { my_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, MYF(0), "SUPER or SYSTEM_VARIABLES_ADMIN"); return true; } } else { /* for static variables user needs both SYSTEM_VARIABLES_ADMIN and PERSIST_RO_VARIABLES_ADMIN */ if (!(sctx->has_global_grant(STRING_WITH_LEN("SYSTEM_VARIABLES_ADMIN")) .first && sctx->has_global_grant(STRING_WITH_LEN("PERSIST_RO_VARIABLES_ADMIN")) .first)) { my_error(ER_PERSIST_ONLY_ACCESS_DENIED_ERROR, MYF(0), "SYSTEM_VARIABLES_ADMIN and PERSIST_RO_VARIABLES_ADMIN"); return true; } } return false; } /** sys_var constructor @param chain variables are linked into chain for mysql_add_sys_var_chain() @param name_arg the name of the variable. Must be 0-terminated and exist for the liftime of the sys_var object. @sa my_option::name @param comment shown in mysqld --help, @sa my_option::comment @param flags_arg or'ed flag_enum values @param off offset of the global variable value from the &global_system_variables. @param getopt_id -1 for no command-line option, otherwise @sa my_option::id @param getopt_arg_type no|optional|required value @sa my_option::arg_type @param show_val_type_arg what value_ptr() returns for sql_show.cc @param def_val default value, @sa my_option::def_value @param lock mutex or rw_lock that protects the global variable *in addition* to LOCK_global_system_variables. @param binlog_status_arg if the sysvar will be written to binlog or not @sa binlog_status_enum @param on_check_func a function to be called at the end of sys_var::check, put your additional checks here @param on_update_func a function to be called at the end of sys_var::update, any post-update activity should happen here @param substitute If non-NULL, this variable is deprecated and the string describes what one should use instead. If an empty string, the variable is deprecated but no replacement is offered. @param parse_flag either PARSE_EARLY or PARSE_NORMAL */ sys_var::sys_var(sys_var_chain *chain, const char *name_arg, const char *comment, int flags_arg, ptrdiff_t off, int getopt_id, enum get_opt_arg_type getopt_arg_type, SHOW_TYPE show_val_type_arg, longlong def_val, PolyLock *lock, enum binlog_status_enum binlog_status_arg, on_check_function on_check_func, on_update_function on_update_func, const char *substitute, int parse_flag) : next(nullptr), binlog_status(binlog_status_arg), flags(flags_arg), m_parse_flag(parse_flag), show_val_type(show_val_type_arg), guard(lock), offset(off), on_check(on_check_func), on_update(on_update_func), deprecation_substitute(substitute), is_os_charset(false) { /* There is a limitation in handle_options() related to short options: - either all short options should be declared when parsing in multiple stages, - or none should be declared. Because a lot of short options are used in the normal parsing phase for mysqld, we enforce here that no short option is present in the first (PARSE_EARLY) stage. See handle_options() for details. */ DBUG_ASSERT(parse_flag == PARSE_NORMAL || getopt_id <= 0 || getopt_id >= 255); name.str = name_arg; // ER_NO_DEFAULT relies on 0-termination of name_arg name.length = strlen(name_arg); // and so does this. DBUG_ASSERT(name.length <= NAME_CHAR_LEN); memset(&option, 0, sizeof(option)); option.name = name_arg; option.id = getopt_id; option.comment = comment; option.arg_type = getopt_arg_type; option.value = (uchar **)global_var_ptr(); option.def_value = def_val; /* set default values */ source.m_source = enum_variable_source::COMPILED; timestamp = 0; user[0] = '\0'; host[0] = '\0'; memset(source.m_path_name, 0, FN_REFLEN); option.arg_source = &source; if (chain->last) chain->last->next = this; else chain->first = this; chain->last = this; } bool sys_var::update(THD *thd, set_var *var) { enum_var_type type = var->type; if (type == OPT_GLOBAL || type == OPT_PERSIST || scope() == GLOBAL) { /* Yes, both locks need to be taken before an update, just as both are taken to get a value. If we'll take only 'guard' here, then value_ptr() for strings won't be safe in SHOW VARIABLES anymore, to make it safe we'll need value_ptr_unlock(). */ AutoWLock lock1(&PLock_global_system_variables); AutoWLock lock2(guard); return global_update(thd, var) || (on_update && on_update(this, thd, OPT_GLOBAL)); } else { /* Block reads from other threads. */ mysql_mutex_lock(&thd->LOCK_thd_sysvar); bool ret = session_update(thd, var) || (on_update && on_update(this, thd, OPT_SESSION)); mysql_mutex_unlock(&thd->LOCK_thd_sysvar); /* Make sure we don't session-track variables that are not actually part of the session. tx_isolation and and tx_read_only for example exist as GLOBAL, SESSION, and one-shot ("for next transaction only"). */ if ((var->type == OPT_SESSION) || !is_trilevel()) { if ((!ret) && thd->session_tracker.get_tracker(SESSION_SYSVARS_TRACKER) ->is_enabled()) thd->session_tracker.get_tracker(SESSION_SYSVARS_TRACKER) ->mark_as_changed(thd, &(var->var->name)); if ((!ret) && thd->session_tracker.get_tracker(SESSION_STATE_CHANGE_TRACKER) ->is_enabled()) thd->session_tracker.get_tracker(SESSION_STATE_CHANGE_TRACKER) ->mark_as_changed(thd, &var->var->name); } return ret; } } const uchar *sys_var::session_value_ptr(THD *, THD *target_thd, LEX_STRING *) { return session_var_ptr(target_thd); } const uchar *sys_var::global_value_ptr(THD *, LEX_STRING *) { return global_var_ptr(); } uchar *sys_var::session_var_ptr(THD *thd) { return ((uchar *)&(thd->variables)) + offset; } uchar *sys_var::global_var_ptr() { return ((uchar *)&global_system_variables) + offset; } bool sys_var::check(THD *thd, set_var *var) { if ((var->value && do_check(thd, var)) || (on_check && on_check(this, thd, var))) { if (!thd->is_error()) { char buff[STRING_BUFFER_USUAL_SIZE]; String str(buff, sizeof(buff), system_charset_info), *res; if (!var->value) { str.set(STRING_WITH_LEN("DEFAULT"), &my_charset_latin1); res = &str; } else if (!(res = var->value->val_str(&str))) { str.set(STRING_WITH_LEN("NULL"), &my_charset_latin1); res = &str; } ErrConvString err(res); my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.str, err.ptr()); } return true; } return false; } const uchar *sys_var::value_ptr(THD *running_thd, THD *target_thd, enum_var_type type, LEX_STRING *base) { if (type == OPT_GLOBAL || type == OPT_PERSIST || scope() == GLOBAL) { mysql_mutex_assert_owner(&LOCK_global_system_variables); AutoRLock lock(guard); return global_value_ptr(running_thd, base); } else return session_value_ptr(running_thd, target_thd, base); } const uchar *sys_var::value_ptr(THD *thd, enum_var_type type, LEX_STRING *base) { return value_ptr(thd, thd, type, base); } bool sys_var::set_default(THD *thd, set_var *var) { DBUG_TRACE; if (var->is_global_persist() || scope() == GLOBAL) global_save_default(thd, var); else session_save_default(thd, var); bool ret = check(thd, var) || update(thd, var); return ret; } void sys_var::set_user_host(THD *thd) { memset(user, 0, sizeof(user)); memset(host, 0, sizeof(host)); Security_context *sctx = thd->security_context(); bool truncated = false; if (sctx->user().length > 0) { truncated = set_and_truncate(user, thd->security_context()->user().str, sizeof(user)); if (truncated) { LogErr(WARNING_LEVEL, ER_USERNAME_TRUNKATED, sctx->user().str, USERNAME_CHAR_LENGTH); } } if (sctx->host().length > 0) { truncated = set_and_truncate(host, thd->security_context()->host().str, sizeof(host)); if (truncated) { LogErr(WARNING_LEVEL, ER_HOSTNAME_TRUNKATED, sctx->host().str, HOSTNAME_LENGTH); } } } void sys_var::do_deprecated_warning(THD *thd) { if (deprecation_substitute != nullptr) { char buf1[NAME_CHAR_LEN + 3]; strxnmov(buf1, sizeof(buf1) - 1, "@@", name.str, 0); /* if deprecation_substitute is an empty string, there is no replacement for the syntax */ uint errmsg = deprecation_substitute[0] == '\0' ? ER_DEPRECATE_MSG_NO_REPLACEMENT : ER_DEPRECATE_MSG_WITH_REPLACEMENT; if (thd) push_warning_printf( thd, Sql_condition::SL_WARNING, ER_WARN_DEPRECATED_SYNTAX, ER_THD_NONCONST(thd, errmsg), buf1, deprecation_substitute); else LogErr(WARNING_LEVEL, errmsg, buf1, deprecation_substitute); } } Item *sys_var::copy_value(THD *thd) { LEX_STRING str; const uchar *val_ptr = session_value_ptr(thd, thd, &str); switch (get_var_type()) { case GET_INT: return new Item_int(*pointer_cast<const int *>(val_ptr)); case GET_UINT: return new Item_int( static_cast<ulonglong>(*pointer_cast<const uint *>(val_ptr))); case GET_LONG: return new Item_int( static_cast<longlong>(*pointer_cast<const long *>(val_ptr))); case GET_ULONG: return new Item_int( static_cast<ulonglong>(*pointer_cast<const ulong *>(val_ptr))); case GET_LL: return new Item_int(*pointer_cast<const longlong *>(val_ptr)); case GET_ULL: return new Item_int(*pointer_cast<const ulonglong *>(val_ptr)); case GET_BOOL: return new Item_int(*pointer_cast<const bool *>(val_ptr)); case GET_ENUM: case GET_SET: case GET_FLAGSET: case GET_STR_ALLOC: case GET_STR: case GET_NO_ARG: case GET_PASSWORD: { const char *tmp_str_val = pointer_cast<const char *>(val_ptr); return new Item_string(tmp_str_val, strlen(tmp_str_val), system_charset_info); } case GET_DOUBLE: return new Item_float(*pointer_cast<const double *>(val_ptr), DECIMAL_NOT_SPECIFIED); default: DBUG_ASSERT(0); } return nullptr; } /** Throw warning (error in STRICT mode) if value for variable needed bounding. Plug-in interface also uses this. @param thd thread handle @param name variable's name @param fixed did we have to correct the value? (throw warn/err if so) @param is_unsigned is value's type unsigned? @param v variable's value @retval true on error, false otherwise (warning or ok) */ bool throw_bounds_warning(THD *thd, const char *name, bool fixed, bool is_unsigned, longlong v) { if (fixed) { char buf[22]; if (is_unsigned) ullstr((ulonglong)v, buf); else llstr(v, buf); if (thd->variables.sql_mode & MODE_STRICT_ALL_TABLES) { my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, buf); return true; } push_warning_printf(thd, Sql_condition::SL_WARNING, ER_TRUNCATED_WRONG_VALUE, ER_THD(thd, ER_TRUNCATED_WRONG_VALUE), name, buf); } return false; } bool throw_bounds_warning(THD *thd, const char *name, bool fixed, double v) { if (fixed) { char buf[64]; my_gcvt(v, MY_GCVT_ARG_DOUBLE, static_cast<int>(sizeof(buf)) - 1, buf, nullptr); if (thd->variables.sql_mode & MODE_STRICT_ALL_TABLES) { my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, buf); return true; } push_warning_printf(thd, Sql_condition::SL_WARNING, ER_TRUNCATED_WRONG_VALUE, ER_THD(thd, ER_TRUNCATED_WRONG_VALUE), name, buf); } return false; } const CHARSET_INFO *sys_var::charset(THD *thd) { return is_os_charset ? thd->variables.character_set_filesystem : system_charset_info; } struct my_old_conv { const char *old_name; const char *new_name; }; static my_old_conv old_conv[] = {{"cp1251_koi8", "cp1251"}, {"cp1250_latin2", "cp1250"}, {"kam_latin2", "keybcs2"}, {"mac_latin2", "MacRoman"}, {"macce_latin2", "MacCE"}, {"pc2_latin2", "pclatin2"}, {"vga_latin2", "pclatin1"}, {"koi8_cp1251", "koi8r"}, {"win1251ukr_koi8_ukr", "win1251ukr"}, {"koi8_ukr_win1251ukr", "koi8u"}, {nullptr, nullptr}}; const CHARSET_INFO *get_old_charset_by_name(const char *name) { my_old_conv *conv; for (conv = old_conv; conv->old_name; conv++) { if (!my_strcasecmp(&my_charset_latin1, name, conv->old_name)) return get_charset_by_csname(conv->new_name, MY_CS_PRIMARY, MYF(0)); } return nullptr; } /**************************************************************************** Main handling of variables: - Initialisation - Searching during parsing - Update loop ****************************************************************************/ /** Add variables to the dynamic hash of system variables @param first Pointer to first system variable to add @retval 0 SUCCESS @retval otherwise FAILURE */ int mysql_add_sys_var_chain(sys_var *first) { sys_var *var; /* A write lock should be held on LOCK_system_variables_hash */ for (var = first; var; var = var->next) { /* this fails if there is a conflicting variable name. */ if (!system_variable_hash->emplace(to_string(var->name), var).second) { LogErr(ERROR_LEVEL, ER_DUPLICATE_SYS_VAR, var->name.str); goto error; } } /* Update system_variable_hash version. */ system_variable_hash_version++; return 0; error: for (; first != var; first = first->next) system_variable_hash->erase(to_string(var->name)); return 1; } /* Remove variables to the dynamic hash of system variables SYNOPSIS mysql_del_sys_var_chain() first Pointer to first system variable to remove RETURN VALUES 0 SUCCESS otherwise FAILURE */ int mysql_del_sys_var_chain(sys_var *first) { int result = 0; /* A write lock should be held on LOCK_system_variables_hash */ for (sys_var *var = first; var; var = var->next) result |= !system_variable_hash->erase(to_string(var->name)); /* Update system_variable_hash version. */ system_variable_hash_version++; return result; } /* Comparison function for std::sort. @param a SHOW_VAR element @param b SHOW_VAR element @retval True if a < b. @retval False if a >= b. */ static int show_cmp(const void *a, const void *b) { return strcmp(static_cast<const SHOW_VAR *>(a)->name, static_cast<const SHOW_VAR *>(b)->name); } /* Number of records in the system_variable_hash. Requires lock on LOCK_system_variables_hash. */ ulong get_system_variable_hash_records(void) { return (system_variable_hash->size()); } /* Current version of the system_variable_hash. Requires lock on LOCK_system_variables_hash. */ ulonglong get_system_variable_hash_version(void) { return (system_variable_hash_version); } /** Constructs an array of system variables for display to the user. @param show_var_array Prealloced_array of SHOW_VAR elements for display @param sort If true, the system variables should be sorted @param query_scope OPT_GLOBAL or OPT_SESSION for SHOW GLOBAL|SESSION VARIABLES @param strict Use strict scope checking @retval True on error, false otherwise */ bool enumerate_sys_vars(Show_var_array *show_var_array, bool sort, enum enum_var_type query_scope, bool strict) { DBUG_ASSERT(show_var_array != nullptr); DBUG_ASSERT(query_scope == OPT_SESSION || query_scope == OPT_GLOBAL); int count = system_variable_hash->size(); /* Resize array if necessary. */ if (show_var_array->reserve(count + 1)) return true; if (show_var_array) { for (const auto &key_and_value : *system_variable_hash) { sys_var *sysvar = key_and_value.second; if (strict) { /* Strict scope match (5.7). Success if this is a: - global query and the variable scope is GLOBAL or SESSION, OR - session query and the variable scope is SESSION or ONLY_SESSION. */ if (!sysvar->check_scope(query_scope)) continue; } else { /* Non-strict scope match (5.6). Success if this is a: - global query and the variable scope is GLOBAL or SESSION, OR - session query and the variable scope is GLOBAL, SESSION or ONLY_SESSION. */ if (query_scope == OPT_GLOBAL && !sysvar->check_scope(query_scope)) continue; } /* Don't show non-visible variables. */ if (sysvar->not_visible()) continue; SHOW_VAR show_var; show_var.name = sysvar->name.str; show_var.value = (char *)sysvar; show_var.type = SHOW_SYS; show_var.scope = SHOW_SCOPE_UNDEF; /* not used for sys vars */ show_var_array->push_back(show_var); } if (sort) std::qsort(show_var_array->begin(), show_var_array->size(), show_var_array->element_size(), show_cmp); /* Make last element empty. */ show_var_array->push_back(SHOW_VAR()); } return false; } /** Find a user set-table variable. @param str Name of system variable to find @param length Length of variable. zero means that we should use strlen() on the variable @retval pointer pointer to variable definitions @retval 0 Unknown variable (error message is given) */ sys_var *intern_find_sys_var(const char *str, size_t length) { sys_var *var; /* This function is only called from the sql_plugin.cc. A lock on LOCK_system_variable_hash should be held */ var = find_or_nullptr(*system_variable_hash, string(str, length ? length : strlen(str))); /* Don't show non-visible variables. */ if (var && var->not_visible()) return nullptr; return var; } /** Execute update of all variables. First run a check of all variables that all updates will go ok. If yes, then execute all updates, returning an error if any one failed. This should ensure that in all normal cases none all or variables are updated. @param thd Thread id @param var_list List of variables to update @param opened True means tables are open and this function will lock them. @retval 0 ok @retval 1 ERROR, message sent (normally no variables was updated) @retval -1 ERROR, message not sent */ int sql_set_variables(THD *thd, List<set_var_base> *var_list, bool opened) { int error; List_iterator_fast<set_var_base> it(*var_list); DBUG_TRACE; LEX *lex = thd->lex; set_var_base *var; if (!thd->lex->unit->is_prepared()) { Prepared_stmt_arena_holder ps_arena_holder(thd); while ((var = it++)) { if ((error = var->resolve(thd))) goto err; } if ((error = thd->is_error())) goto err; thd->lex->unit->set_prepared(); if (!thd->stmt_arena->is_regular()) thd->lex->save_cmd_properties(thd); } if (opened && lock_tables(thd, lex->query_tables, lex->table_count, 0)) { error = 1; goto err; } thd->lex->set_exec_started(); it.rewind(); while ((var = it++)) { if ((error = var->check(thd))) goto err; } if ((error = thd->is_error())) goto err; it.rewind(); while ((var = it++)) { if ((error = var->update(thd))) // Returns 0, -1 or 1 goto err; } if (!error) { /* At this point SET statement is considered a success. */ Persisted_variables_cache *pv = nullptr; it.rewind(); while ((var = it++)) { set_var *setvar = dynamic_cast<set_var *>(var); if (setvar && (setvar->type == OPT_PERSIST || setvar->type == OPT_PERSIST_ONLY)) { pv = Persisted_variables_cache::get_instance(); /* update in-memory copy of persistent options */ if (pv->set_variable(thd, setvar)) return 1; } } /* flush all persistent options to a file */ if (pv && pv->flush_to_file()) { my_error(ER_VARIABLE_NOT_PERSISTED, MYF(0)); return 1; } } err: free_underlaid_joins(thd, thd->lex->select_lex); return error; } /** This function is used to check if key management UDFs like keying_key_generate/store/remove should proceed or not. If global variable @@keyring_operations is OFF then above said udfs will fail. @return Operation status @retval 0 OK @retval 1 ERROR, keyring operations are not allowed @sa Sys_keyring_operations */ bool keyring_access_test() { bool keyring_operations; mysql_mutex_lock(&LOCK_keyring_operations); keyring_operations = !opt_keyring_operations; mysql_mutex_unlock(&LOCK_keyring_operations); return keyring_operations; } /***************************************************************************** Functions to handle SET mysql_internal_variable=const_expr *****************************************************************************/ set_var::set_var(enum_var_type type_arg, sys_var *var_arg, LEX_CSTRING base_name_arg, Item *value_arg) : var(var_arg), type(type_arg), base(base_name_arg) { /* If the set value is a field, change it to a string to allow things like SET table_type=MYISAM; */ if (value_arg && value_arg->type() == Item::FIELD_ITEM) { Item_field *item = (Item_field *)value_arg; if (item->field_name) { if (!(value = new Item_string(item->field_name, strlen(item->field_name), system_charset_info))) // names are utf8 value = value_arg; /* Give error message later */ } else { /* Both Item_field and Item_insert_value will return the type as Item::FIELD_ITEM. If the item->field_name is NULL, we assume the object to be Item_insert_value. */ value = value_arg; } } else value = value_arg; } /** global X509 subject name to require from the client session to allow SET PERSIST[_ONLY] on sys_var::NOTPERSIST variables @sa set_var::resolve */ char *sys_var_persist_only_admin_x509_subject = nullptr; /** Checks if a THD can set non-persist variables Requires that: * the session uses SSL * the peer has presented a valid certificate * the certificate has a certain subject name The format checked is deliberately kept the same as the other SSL system and status variables representing names. Hence X509_NAME_oneline is used. @retval true the THD can set NON_PERSIST variables @retval false usual restrictions apply @param thd the THD handle @param var the variable to be set @param setvar_type the operation to check against. @sa sys_variables_admin_dn */ static bool can_persist_non_persistent_var(THD *thd, sys_var *var, enum_var_type setvar_type) { SSL *ssl = nullptr; X509 *cert = nullptr; char *ptr = nullptr; bool result = false; /* Bail off if no subject is set */ if (likely(!sys_var_persist_only_admin_x509_subject || !sys_var_persist_only_admin_x509_subject[0])) return false; /* Can't persist read only variables without command line support */ if (unlikely(setvar_type == OPT_PERSIST_ONLY && !var->is_settable_at_command_line() && (var->is_readonly() || var->is_persist_readonly()))) return false; /* do not allow setting the controlling variables */ if (never_persistable_vars->find(var->name.str) != never_persistable_vars->end()) return false; ssl = thd->get_ssl(); if (!ssl) return false; cert = SSL_get_peer_certificate(ssl); if (!cert) goto done; ptr = X509_NAME_oneline(X509_get_subject_name(cert), nullptr, 0); if (!ptr) goto done; result = !strcmp(sys_var_persist_only_admin_x509_subject, ptr); done: if (ptr) OPENSSL_free(ptr); if (cert) X509_free(cert); return result; } /** Resolve the variable assignment @param thd Thread handler @return status code @retval -1 Failure @retval 0 Success */ int set_var::resolve(THD *thd) { DBUG_TRACE; var->do_deprecated_warning(thd); if (var->is_readonly()) { if (type != OPT_PERSIST_ONLY) { my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0), var->name.str, "read only"); return -1; } if (type == OPT_PERSIST_ONLY && var->is_non_persistent() && !can_persist_non_persistent_var(thd, var, type)) { my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0), var->name.str, "non persistent read only"); return -1; } } if (!var->check_scope(type)) { int err = (is_global_persist()) ? ER_LOCAL_VARIABLE : ER_GLOBAL_VARIABLE; my_error(err, MYF(0), var->name.str); return -1; } if (type == OPT_GLOBAL || type == OPT_PERSIST) { /* Either the user has SUPER_ACL or she has SYSTEM_VARIABLES_ADMIN */ if (check_priv(thd, false)) return 1; } if (type == OPT_PERSIST_ONLY) { if (check_priv(thd, true)) return 1; } /* check if read/write non-persistent variables can be persisted */ if ((type == OPT_PERSIST || type == OPT_PERSIST_ONLY) && var->is_non_persistent() && !can_persist_non_persistent_var(thd, var, type)) { my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0), var->name.str, "non persistent"); return -1; } /* value is a NULL pointer if we are using SET ... = DEFAULT */ if (value == nullptr || value->fixed) return 0; if (value->fix_fields(thd, &value)) { return -1; } /* If expression has no data type (e.g because it contains a parameter), assign type character string. */ if (value->data_type() == MYSQL_TYPE_INVALID && value->propagate_type(thd, MYSQL_TYPE_VARCHAR)) { return -1; } if (value->check_cols(1)) { return -1; } return 0; } /** Verify that the supplied value is correct. @param thd Thread handler @return status code @retval -1 Failure @retval 0 Success */ int set_var::check(THD *thd) { DBUG_TRACE; /* value is a NULL pointer if we are using SET ... = DEFAULT */ if (!value) return 0; if (var->check_update_type(value->result_type())) { my_error(ER_WRONG_TYPE_FOR_VAR, MYF(0), var->name.str); return -1; } int ret = (type != OPT_PERSIST_ONLY && var->check(thd, this)) ? -1 : 0; if (!ret && (is_global_persist())) { ret = mysql_audit_notify(thd, AUDIT_EVENT(MYSQL_AUDIT_GLOBAL_VARIABLE_SET), var->name.str, value->item_name.ptr(), value->item_name.length()); } return ret; } /** Check variable, but without assigning value (used by PS). @param thd thread handler @retval 0 ok @retval 1 ERROR, message sent (normally no variables was updated) @retval -1 ERROR, message not sent */ int set_var::light_check(THD *thd) { if (!var->check_scope(type)) { int err = (is_global_persist()) ? ER_LOCAL_VARIABLE : ER_GLOBAL_VARIABLE; my_error(err, MYF(0), var->name.str); return -1; } Security_context *sctx = thd->security_context(); if ((type == OPT_GLOBAL || type == OPT_PERSIST) && !(sctx->check_access(SUPER_ACL) || sctx->has_global_grant(STRING_WITH_LEN("SYSTEM_VARIABLES_ADMIN")) .first)) return 1; if ((type == OPT_PERSIST_ONLY) && !(sctx->has_global_grant(STRING_WITH_LEN("PERSIST_RO_VARIABLES_ADMIN")) .first && sctx->has_global_grant(STRING_WITH_LEN("SYSTEM_VARIABLES_ADMIN")) .first)) return 1; if (value == nullptr || value->fixed) return 0; if (value->fix_fields(thd, &value)) { return -1; } /* If expression has no data type (e.g because it contains a parameter), assign type character string. */ if (value->data_type() == MYSQL_TYPE_INVALID && value->propagate_type(thd, MYSQL_TYPE_VARCHAR)) { return -1; } if (value->check_cols(1)) { return -1; } return 0; } /** Update variable source, user, host and timestamp values. */ void set_var::update_source_user_host_timestamp(THD *thd) { var->set_source(enum_variable_source::DYNAMIC); var->set_source_name(EMPTY_CSTR.str); var->set_user_host(thd); var->set_timestamp(); } /** Update variable @param thd thread handler @returns 0|1 ok or ERROR @note ERROR can be only due to abnormal operations involving the server's execution evironment such as out of memory, hard disk failure or the computer blows up. Consider set_var::check() method if there is a need to return an error due to logics. */ int set_var::update(THD *thd) { int ret = 0; /* for persist only syntax do not update the value */ if (type != OPT_PERSIST_ONLY) { if (value) ret = (int)var->update(thd, this); else ret = (int)var->set_default(thd, this); } /* For PERSIST_ONLY syntax we dont change the value of the variable for the current session, thus we should not change variables source/timestamp/user/host. */ if (ret == 0 && type != OPT_PERSIST_ONLY) { update_source_user_host_timestamp(thd); } return ret; } void set_var::print_short(const THD *thd, String *str) { str->append(var->name.str, var->name.length); str->append(STRING_WITH_LEN("=")); if (value) value->print(thd, str, QT_ORDINARY); else str->append(STRING_WITH_LEN("DEFAULT")); } /** Self-print assignment @param thd Thread handle @param str String buffer to append the partial assignment to. */ void set_var::print(const THD *thd, String *str) { switch (type) { case OPT_PERSIST: str->append("PERSIST "); break; case OPT_PERSIST_ONLY: str->append("PERSIST_ONLY "); break; case OPT_GLOBAL: str->append("GLOBAL "); break; default: str->append("SESSION "); } if (base.length) { str->append(base.str, base.length); str->append(STRING_WITH_LEN(".")); } print_short(thd, str); } /***************************************************************************** Functions to handle SET @user_variable=const_expr *****************************************************************************/ int set_var_user::resolve(THD *thd) { /* Item_func_set_user_var can't substitute something else on its place => NULL can be passed as last argument (reference on item) */ return !user_var_item->fixed && user_var_item->fix_fields(thd, nullptr) ? -1 : 0; } int set_var_user::check(THD *) { /* Item_func_set_user_var can't substitute something else on its place => 0 can be passed as last argument (reference on item) */ return user_var_item->check(false) ? -1 : 0; } /** Check variable, but without assigning value (used by PS). @param thd thread handler @retval 0 ok @retval 1 ERROR, message sent (normally no variables was updated) @retval -1 ERROR, message not sent */ int set_var_user::light_check(THD *thd) { /* Item_func_set_user_var can't substitute something else on its place => 0 can be passed as last argument (reference on item) */ return (user_var_item->fix_fields(thd, (Item **)nullptr)); } int set_var_user::update(THD *thd) { if (user_var_item->update()) { /* Give an error if it's not given already */ my_error(ER_SET_CONSTANTS_ONLY, MYF(0)); return -1; } if (thd->session_tracker.get_tracker(SESSION_STATE_CHANGE_TRACKER) ->is_enabled()) thd->session_tracker.get_tracker(SESSION_STATE_CHANGE_TRACKER) ->mark_as_changed(thd, nullptr); return 0; } void set_var_user::print(const THD *thd, String *str) { user_var_item->print_assignment(thd, str, QT_ORDINARY); } /***************************************************************************** Functions to handle SET PASSWORD *****************************************************************************/ set_var_password::set_var_password(LEX_USER *user_arg, char *password_arg, char *current_password_arg, bool retain_current, bool gen_pass) : user(user_arg), password(password_arg), current_password(current_password_arg), retain_current_password(retain_current), generate_password(gen_pass) { if (current_password != nullptr) { user_arg->uses_replace_clause = true; user_arg->current_auth.str = current_password_arg; user_arg->current_auth.length = strlen(current_password_arg); } user_arg->retain_current_password = retain_current_password; } set_var_password::~set_var_password() { // We copied the generated password buffer to circumvent // the password nullification code in change_password() if (generate_password) my_free(password); } /** Check the validity of the SET PASSWORD request @param thd The current thread @return status code @retval 0 failure @retval 1 success */ int set_var_password::check(THD *thd) { /* Returns 1 as the function sends error to client */ return check_change_password(thd, user->host.str, user->user.str, retain_current_password) ? 1 : 0; } int set_var_password::update(THD *thd) { if (generate_password) { thd->m_disable_password_validation = true; std::string generated_password; generate_random_password(&generated_password, thd->variables.generated_random_password_length); /* We need to copy the password buffer here because it will be set to \0 later by change_password() and since we're generated a random password we need to retain it until it can be sent to the client. Because set_var_password never will get its destructor called we also need to move the string allocated memory to the THD mem root. */ password = thd->mem_strdup(generated_password.c_str()); str_generated_password = thd->mem_strdup(generated_password.c_str()); } /* Returns 1 as the function sends error to client */ auto res = change_password(thd, user, password, current_password, retain_current_password) ? 1 : 0; return res; } void set_var_password::print(const THD *thd, String *str) { if (user->user.str != nullptr && user->user.length > 0) { str->append(STRING_WITH_LEN("PASSWORD FOR ")); append_identifier(thd, str, user->user.str, user->user.length); if (user->host.str != nullptr && user->host.length > 0) { str->append(STRING_WITH_LEN("@")); append_identifier(thd, str, user->host.str, user->host.length); } str->append(STRING_WITH_LEN("=")); } else str->append(STRING_WITH_LEN("PASSWORD FOR CURRENT_USER()=")); str->append(STRING_WITH_LEN("<secret>")); if (user->uses_replace_clause) { str->append(STRING_WITH_LEN(" REPLACE <secret>")); } if (user->retain_current_password) { str->append(STRING_WITH_LEN(" RETAIN CURRENT PASSWORD")); } } /***************************************************************************** Functions to handle SET NAMES and SET CHARACTER SET *****************************************************************************/ int set_var_collation_client::check(THD *) { /* Currently, UCS-2 cannot be used as a client character set */ if (!is_supported_parser_charset(character_set_client)) { my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), "character_set_client", character_set_client->csname); return 1; } return 0; } int set_var_collation_client::update(THD *thd) { thd->variables.character_set_client = character_set_client; thd->variables.character_set_results = character_set_results; thd->variables.collation_connection = collation_connection; thd->update_charset(); /* Mark client collation variables as changed */ if (thd->session_tracker.get_tracker(SESSION_SYSVARS_TRACKER)->is_enabled()) { LEX_CSTRING cs_client = {"character_set_client", sizeof("character_set_client") - 1}; thd->session_tracker.get_tracker(SESSION_SYSVARS_TRACKER) ->mark_as_changed(thd, &cs_client); LEX_CSTRING cs_results = {"character_set_results", sizeof("character_set_results") - 1}; thd->session_tracker.get_tracker(SESSION_SYSVARS_TRACKER) ->mark_as_changed(thd, &cs_results); LEX_CSTRING cs_connection = {"character_set_connection", sizeof("character_set_connection") - 1}; thd->session_tracker.get_tracker(SESSION_SYSVARS_TRACKER) ->mark_as_changed(thd, &cs_connection); } if (thd->session_tracker.get_tracker(SESSION_STATE_CHANGE_TRACKER) ->is_enabled()) thd->session_tracker.get_tracker(SESSION_STATE_CHANGE_TRACKER) ->mark_as_changed(thd, nullptr); thd->protocol_text->init(thd); thd->protocol_binary->init(thd); return 0; } void set_var_collation_client::print(const THD *, String *str) { str->append((set_cs_flags & SET_CS_NAMES) ? "NAMES " : "CHARACTER SET "); if (set_cs_flags & SET_CS_DEFAULT) str->append("DEFAULT"); else { str->append("'"); str->append(character_set_client->csname); str->append("'"); if (set_cs_flags & SET_CS_COLLATE) { str->append(" COLLATE '"); str->append(collation_connection->name); str->append("'"); } } }
.ORIG x200 ;GLOBAL INITIALIZE AND R0,R0,#0 ADD R0,R0,#1 LEA R1,TRAPFILE TRAP x0 ST R2,INIT_TRAP AND R0,R0,#0 ADD R0,R0,#1 LEA R1,INTFILE TRAP x0 ST R2,INIT_INT LD R0,INIT_TRAP JSRR R0 LD R0,INIT_INT JSRR R0 BRnzp OS_START TRAPFILE .STRINGZ "_trapvec.obj" INTFILE .STRINGZ "_intvec.obj" INIT_TRAP .BLKW 1 INIT_INT .BLKW 1 ; reading letters and print them SRUNPROG .STRINGZ "run" SCLSC .STRINGZ "cls" STOHALT .STRINGZ "halt" SUNKNOWN .STRINGZ "unknown command! input again!\n" .FILL 0 SHALTSTR .STRINGZ "Exit OS! Thank you~\n" OS_START JSR READ_STR LEA R1,SRUNPROG JSR STRCMP ADD R2,R2,#0 BRz RUN_PROG LEA R1,SCLSC JSR STRCMP ADD R2,R2,#0 BRz PCLS LEA R1,STOHALT JSR STRCMP ADD R2,R2,#0 BRz PHALT LEA R0,SUNKNOWN TRAP x22 BRnzp OS_START RUN_PROG AND R0,R0,#0 ADD R0,R0,#4 LD R1,PSR TRAP x0 LEA R1,OS_START TRAP x0 JSR READ_STR ADD R1,R0,#0 AND R0,R0,#0 ADD R0,R0,#1 TRAP x0 ; NOW R2 ADD R2,R2,#0 BRz OS_START AND R0,R0,#0 ADD R0,R0,#4 LD R1,USER_PSR TRAP x0 ADD R1,R2,#0 TRAP x0 RTI PCLS AND R0,R0,#0 ADD R0,R0,#3 TRAP x0 BRnzp OS_START PHALT LEA R0,SHALTSTR TRAP x22 LD R0,CLOCKVAL STI R0,CLOCK BRnzp PHALT CLOCKVAL .FILL x7FFF CLOCK .FILL xFFFE PSR .FILL x0002 USER_PSR .FILL x8002 ;;;;;;;;;;;;;;;;;;;;;;;;;;; STRCMP_R0 .BLKW 1 STRCMP_R1 .BLKW 1 STRCMP_R3 .BLKW 1 STRCMP ST R0,STRCMP_R0 ST R1,STRCMP_R1 ST R3,STRCMP_R3 CMP_NEXT LDR R2,R0,#0 LDR R3,R1,#0 NOT R3,R3 ADD R3,R3,#1 ADD R2,R2,R3 BRnp NOT_EQUAL LDR R2,R0,#0 ADD R2,R2,#0 BRz END_EQUAL ADD R0,R0,#1 ADD R1,R1,#1 BRnzp CMP_NEXT NOT_EQUAL LD R0,STRCMP_R0 LD R1,STRCMP_R1 LD R3,STRCMP_R3 AND R2,R2,#0 ADD R2,R2,#1 RET END_EQUAL LD R0,STRCMP_R0 LD R1,STRCMP_R1 LD R3,STRCMP_R3 AND R2,R2,#0 RET ;;;;;;;;;;;;;;;;;;;;;;;;;;; RSTR_R1 .BLKW 1 RSTR_R2 .BLKW 1 RSTR_R3 .BLKW 1 RSTR_R7 .BLKW 1 READ_STR ST R1,RSTR_R1 ST R2,RSTR_R2 ST R3,RSTR_R3 ST R7,RSTR_R7 AND R1,R1,#0 ST R1,BUFFID LEA R3,BUFFER RSTR_AGAIN GETC ADD R1,R0,#0 ADD R1,R1,#-10 BRz IS_ENTER ADD R1,R0,#0 ADD R1,R1,#-8 BRz IS_BACK PUTC LD R2,BUFFID ADD R2,R3,R2 STR R0,R2,#0 LD R2,BUFFID ADD R2,R2,#1 ST R2,BUFFID BRnzp RSTR_AGAIN IS_ENTER: PUTC LD R2,BUFFID ;ADD R2,R2,#1 ADD R2,R3,R2 AND R0,R0,#0 STR R0,R2,#0 LEA R0,BUFFER LD R1,RSTR_R1 LD R2,RSTR_R2 LD R3,RSTR_R3 LD R7,RSTR_R7 RET IS_BACK: LD R2,BUFFID ADD R2,R2,#0 BRnz CANTBACK PUTC ADD R2,R2,#-1 ST R2,BUFFID CANTBACK BRnzp RSTR_AGAIN BUFFID .FILL x0 BUFFER .BLKW #100 .END
/* * Copyright 2008-2009, Axel Dörfler, axeld@pinc-software.de. * Distributed under the terms of the MIT License. */ #include <kdevice_manager.h> #include <new> #include <set> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <KernelExport.h> #include <Locker.h> #include <module.h> #include <PCI.h> #include <boot_device.h> #include <device_manager_defs.h> #include <fs/devfs.h> #include <fs/KPath.h> #include <kernel.h> #include <generic_syscall.h> #include <util/AutoLock.h> #include <util/DoublyLinkedList.h> #include <util/Stack.h> #include "AbstractModuleDevice.h" #include "devfs_private.h" #include "id_generator.h" #include "IORequest.h" #include "io_resources.h" #include "IOSchedulerRoster.h" //#define TRACE_DEVICE_MANAGER #ifdef TRACE_DEVICE_MANAGER # define TRACE(a) dprintf a #else # define TRACE(a) ; #endif #define DEVICE_MANAGER_ROOT_NAME "system/devices_root/driver_v1" #define DEVICE_MANAGER_GENERIC_NAME "system/devices_generic/driver_v1" struct device_attr_private : device_attr, DoublyLinkedListLinkImpl<device_attr_private> { device_attr_private(); device_attr_private(const device_attr& attr); ~device_attr_private(); status_t InitCheck(); status_t CopyFrom(const device_attr& attr); static int Compare(const device_attr* attrA, const device_attr *attrB); private: void _Unset(); }; typedef DoublyLinkedList<device_attr_private> AttributeList; // I/O resource typedef struct io_resource_info { struct io_resource_info *prev, *next; device_node* owner; // associated node; NULL for temporary allocation io_resource resource; // info about actual resource } io_resource_info; namespace { class Device : public AbstractModuleDevice, public DoublyLinkedListLinkImpl<Device> { public: Device(device_node* node, const char* moduleName); virtual ~Device(); status_t InitCheck() const; const char* ModuleName() const { return fModuleName; } virtual status_t InitDevice(); virtual void UninitDevice(); virtual void Removed(); void SetRemovedFromParent(bool removed) { fRemovedFromParent = removed; } private: const char* fModuleName; bool fRemovedFromParent; }; } // unnamed namespace typedef DoublyLinkedList<Device> DeviceList; typedef DoublyLinkedList<device_node> NodeList; struct device_node : DoublyLinkedListLinkImpl<device_node> { device_node(const char* moduleName, const device_attr* attrs); ~device_node(); status_t InitCheck() const; status_t AcquireResources(const io_resource* resources); const char* ModuleName() const { return fModuleName; } device_node* Parent() const { return fParent; } AttributeList& Attributes() { return fAttributes; } const AttributeList& Attributes() const { return fAttributes; } status_t InitDriver(); bool UninitDriver(); void UninitUnusedDriver(); // The following two are only valid, if the node's driver is // initialized driver_module_info* DriverModule() const { return fDriver; } void* DriverData() const { return fDriverData; } void AddChild(device_node *node); void RemoveChild(device_node *node); const NodeList& Children() const { return fChildren; } void DeviceRemoved(); status_t Register(device_node* parent); status_t Probe(const char* devicePath, uint32 updateCycle); status_t Reprobe(); status_t Rescan(); bool IsRegistered() const { return fRegistered; } bool IsInitialized() const { return fInitialized > 0; } bool IsProbed() const { return fLastUpdateCycle != 0; } uint32 Flags() const { return fFlags; } void Acquire(); bool Release(); const DeviceList& Devices() const { return fDevices; } void AddDevice(Device* device); void RemoveDevice(Device* device); int CompareTo(const device_attr* attributes) const; device_node* FindChild(const device_attr* attributes) const; device_node* FindChild(const char* moduleName) const; int32 Priority(); void Dump(int32 level = 0); private: status_t _RegisterFixed(uint32& registered); bool _AlwaysRegisterDynamic(); status_t _AddPath(Stack<KPath*>& stack, const char* path, const char* subPath = NULL); status_t _GetNextDriverPath(void*& cookie, KPath& _path); status_t _GetNextDriver(void* list, driver_module_info*& driver); status_t _FindBestDriver(const char* path, driver_module_info*& bestDriver, float& bestSupport, device_node* previous = NULL); status_t _RegisterPath(const char* path); status_t _RegisterDynamic(device_node* previous = NULL); status_t _RemoveChildren(); device_node* _FindCurrentChild(); status_t _Probe(); void _ReleaseWaiting(); device_node* fParent; NodeList fChildren; int32 fRefCount; int32 fInitialized; bool fRegistered; uint32 fFlags; float fSupportsParent; uint32 fLastUpdateCycle; const char* fModuleName; driver_module_info* fDriver; void* fDriverData; DeviceList fDevices; AttributeList fAttributes; ResourceList fResources; }; // flags in addition to those specified by B_DEVICE_FLAGS enum node_flags { NODE_FLAG_REGISTER_INITIALIZED = 0x00010000, NODE_FLAG_DEVICE_REMOVED = 0x00020000, NODE_FLAG_OBSOLETE_DRIVER = 0x00040000, NODE_FLAG_WAITING_FOR_DRIVER = 0x00080000, NODE_FLAG_PUBLIC_MASK = 0x0000ffff }; static device_node *sRootNode; static recursive_lock sLock; static const char* sGenericContextPath; // #pragma mark - static device_attr_private* find_attr(const device_node* node, const char* name, bool recursive, type_code type) { do { AttributeList::ConstIterator iterator = node->Attributes().GetIterator(); while (iterator.HasNext()) { device_attr_private* attr = iterator.Next(); if (type != B_ANY_TYPE && attr->type != type) continue; if (!strcmp(attr->name, name)) return attr; } node = node->Parent(); } while (node != NULL && recursive); return NULL; } static void put_level(int32 level) { while (level-- > 0) kprintf(" "); } static void dump_attribute(device_attr* attr, int32 level) { if (attr == NULL) return; put_level(level + 2); kprintf("\"%s\" : ", attr->name); switch (attr->type) { case B_STRING_TYPE: kprintf("string : \"%s\"", attr->value.string); break; case B_INT8_TYPE: case B_UINT8_TYPE: kprintf("uint8 : %" B_PRIu8 " (%#" B_PRIx8 ")", attr->value.ui8, attr->value.ui8); break; case B_INT16_TYPE: case B_UINT16_TYPE: kprintf("uint16 : %" B_PRIu16 " (%#" B_PRIx16 ")", attr->value.ui16, attr->value.ui16); break; case B_INT32_TYPE: case B_UINT32_TYPE: kprintf("uint32 : %" B_PRIu32 " (%#" B_PRIx32 ")", attr->value.ui32, attr->value.ui32); break; case B_INT64_TYPE: case B_UINT64_TYPE: kprintf("uint64 : %" B_PRIu64 " (%#" B_PRIx64 ")", attr->value.ui64, attr->value.ui64); break; default: kprintf("raw data"); } kprintf("\n"); } static int dump_io_scheduler(int argc, char** argv) { if (argc != 2) { print_debugger_command_usage(argv[0]); return 0; } IOScheduler* scheduler = (IOScheduler*)parse_expression(argv[1]); scheduler->Dump(); return 0; } static int dump_io_request_owner(int argc, char** argv) { if (argc != 2) { print_debugger_command_usage(argv[0]); return 0; } IORequestOwner* owner = (IORequestOwner*)parse_expression(argv[1]); owner->Dump(); return 0; } static int dump_io_request(int argc, char** argv) { if (argc != 2 || !strcmp(argv[1], "--help")) { kprintf("usage: %s <ptr-to-io-request>\n", argv[0]); return 0; } IORequest* request = (IORequest*)parse_expression(argv[1]); request->Dump(); return 0; } static int dump_io_operation(int argc, char** argv) { if (argc != 2 || !strcmp(argv[1], "--help")) { kprintf("usage: %s <ptr-to-io-operation>\n", argv[0]); return 0; } IOOperation* operation = (IOOperation*)parse_expression(argv[1]); operation->Dump(); return 0; } static int dump_io_buffer(int argc, char** argv) { if (argc != 2 || !strcmp(argv[1], "--help")) { kprintf("usage: %s <ptr-to-io-buffer>\n", argv[0]); return 0; } IOBuffer* buffer = (IOBuffer*)parse_expression(argv[1]); buffer->Dump(); return 0; } static int dump_dma_buffer(int argc, char** argv) { if (argc != 2 || !strcmp(argv[1], "--help")) { kprintf("usage: %s <ptr-to-dma-buffer>\n", argv[0]); return 0; } DMABuffer* buffer = (DMABuffer*)parse_expression(argv[1]); buffer->Dump(); return 0; } static int dump_device_nodes(int argc, char** argv) { sRootNode->Dump(); return 0; } static void publish_directories(const char* subPath) { if (gBootDevice < 0) { if (subPath[0]) { // we only support the top-level directory for modules return; } // we can only iterate over the known modules to find all directories KPath path("drivers"); if (path.Append(subPath) != B_OK) return; size_t length = strlen(path.Path()) + 1; // account for the separating '/' void* list = open_module_list_etc(path.Path(), "driver_v1"); char name[B_FILE_NAME_LENGTH]; size_t nameLength = sizeof(name); while (read_next_module_name(list, name, &nameLength) == B_OK) { if (nameLength == length) continue; char* leaf = name + length; char* end = strchr(leaf, '/'); if (end != NULL) end[0] = '\0'; path.SetTo(subPath); path.Append(leaf); devfs_publish_directory(path.Path()); } close_module_list(list); } else { // TODO: implement module directory traversal! } } static status_t control_device_manager(const char* subsystem, uint32 function, void* buffer, size_t bufferSize) { // TODO: this function passes pointers to userland, and uses pointers // to device nodes that came from userland - this is completely unsafe // and should be changed. switch (function) { case DM_GET_ROOT: { device_node_cookie cookie; if (!IS_USER_ADDRESS(buffer)) return B_BAD_ADDRESS; if (bufferSize != sizeof(device_node_cookie)) return B_BAD_VALUE; cookie = (device_node_cookie)sRootNode; // copy back to user space return user_memcpy(buffer, &cookie, sizeof(device_node_cookie)); } case DM_GET_CHILD: { if (!IS_USER_ADDRESS(buffer)) return B_BAD_ADDRESS; if (bufferSize != sizeof(device_node_cookie)) return B_BAD_VALUE; device_node_cookie cookie; if (user_memcpy(&cookie, buffer, sizeof(device_node_cookie)) < B_OK) return B_BAD_ADDRESS; device_node* node = (device_node*)cookie; NodeList::ConstIterator iterator = node->Children().GetIterator(); if (!iterator.HasNext()) { return B_ENTRY_NOT_FOUND; } node = iterator.Next(); cookie = (device_node_cookie)node; // copy back to user space return user_memcpy(buffer, &cookie, sizeof(device_node_cookie)); } case DM_GET_NEXT_CHILD: { if (!IS_USER_ADDRESS(buffer)) return B_BAD_ADDRESS; if (bufferSize != sizeof(device_node_cookie)) return B_BAD_VALUE; device_node_cookie cookie; if (user_memcpy(&cookie, buffer, sizeof(device_node_cookie)) < B_OK) return B_BAD_ADDRESS; device_node* last = (device_node*)cookie; if (!last->Parent()) return B_ENTRY_NOT_FOUND; NodeList::ConstIterator iterator = last->Parent()->Children().GetIterator(); // skip those we already traversed while (iterator.HasNext()) { device_node* node = iterator.Next(); if (node == last) break; } if (!iterator.HasNext()) return B_ENTRY_NOT_FOUND; device_node* node = iterator.Next(); cookie = (device_node_cookie)node; // copy back to user space return user_memcpy(buffer, &cookie, sizeof(device_node_cookie)); } case DM_GET_NEXT_ATTRIBUTE: { struct device_attr_info attrInfo; if (!IS_USER_ADDRESS(buffer)) return B_BAD_ADDRESS; if (bufferSize != sizeof(device_attr_info)) return B_BAD_VALUE; if (user_memcpy(&attrInfo, buffer, sizeof(device_attr_info)) < B_OK) return B_BAD_ADDRESS; device_node* node = (device_node*)attrInfo.node_cookie; device_attr* last = (device_attr*)attrInfo.cookie; AttributeList::Iterator iterator = node->Attributes().GetIterator(); // skip those we already traversed while (iterator.HasNext() && last != NULL) { device_attr* attr = iterator.Next(); if (attr == last) break; } if (!iterator.HasNext()) { attrInfo.cookie = 0; return B_ENTRY_NOT_FOUND; } device_attr* attr = iterator.Next(); attrInfo.cookie = (device_node_cookie)attr; if (attr->name != NULL) strlcpy(attrInfo.name, attr->name, 254); else attrInfo.name[0] = '\0'; attrInfo.type = attr->type; switch (attrInfo.type) { case B_UINT8_TYPE: attrInfo.value.ui8 = attr->value.ui8; break; case B_UINT16_TYPE: attrInfo.value.ui16 = attr->value.ui16; break; case B_UINT32_TYPE: attrInfo.value.ui32 = attr->value.ui32; break; case B_UINT64_TYPE: attrInfo.value.ui64 = attr->value.ui64; break; case B_STRING_TYPE: if (attr->value.string != NULL) strlcpy(attrInfo.value.string, attr->value.string, 254); else attrInfo.value.string[0] = '\0'; break; /*case B_RAW_TYPE: if (attr.value.raw.length > attr_info->attr.value.raw.length) attr.value.raw.length = attr_info->attr.value.raw.length; user_memcpy(attr.value.raw.data, attr_info->attr.value.raw.data, attr.value.raw.length); break;*/ } // copy back to user space return user_memcpy(buffer, &attrInfo, sizeof(device_attr_info)); } } return B_BAD_HANDLER; } // #pragma mark - Device Manager module API static status_t rescan_node(device_node* node) { RecursiveLocker _(sLock); return node->Rescan(); } static status_t register_node(device_node* parent, const char* moduleName, const device_attr* attrs, const io_resource* ioResources, device_node** _node) { if ((parent == NULL && sRootNode != NULL) || moduleName == NULL) return B_BAD_VALUE; if (parent != NULL && parent->FindChild(attrs) != NULL) { // A node like this one already exists for this parent return B_NAME_IN_USE; } RecursiveLocker _(sLock); device_node* newNode = new(std::nothrow) device_node(moduleName, attrs); if (newNode == NULL) return B_NO_MEMORY; TRACE(("%p: register node \"%s\", parent %p\n", newNode, moduleName, parent)); status_t status = newNode->InitCheck(); if (status == B_OK) status = newNode->AcquireResources(ioResources); if (status == B_OK) status = newNode->Register(parent); if (status != B_OK) { newNode->Release(); return status; } if (_node) *_node = newNode; return B_OK; } /*! Unregisters the device \a node. If the node is currently in use, this function will return B_BUSY to indicate that the node hasn't been removed yet - it will still remove the node as soon as possible. */ static status_t unregister_node(device_node* node) { TRACE(("unregister_node(node %p)\n", node)); RecursiveLocker _(sLock); bool initialized = node->IsInitialized(); node->DeviceRemoved(); return initialized ? B_BUSY : B_OK; } static status_t get_driver(device_node* node, driver_module_info** _module, void** _data) { if (node->DriverModule() == NULL) return B_NO_INIT; if (_module != NULL) *_module = node->DriverModule(); if (_data != NULL) *_data = node->DriverData(); return B_OK; } static device_node* get_root_node(void) { if (sRootNode != NULL) sRootNode->Acquire(); return sRootNode; } static status_t get_next_child_node(device_node* parent, const device_attr* attributes, device_node** _node) { RecursiveLocker _(sLock); NodeList::ConstIterator iterator = parent->Children().GetIterator(); device_node* last = *_node; // skip those we already traversed while (iterator.HasNext() && last != NULL) { device_node* node = iterator.Next(); if (node != last) continue; } // find the next one that fits while (iterator.HasNext()) { device_node* node = iterator.Next(); if (!node->IsRegistered()) continue; if (!node->CompareTo(attributes)) { if (last != NULL) last->Release(); node->Acquire(); *_node = node; return B_OK; } } if (last != NULL) last->Release(); return B_ENTRY_NOT_FOUND; } static device_node* get_parent_node(device_node* node) { if (node == NULL) return NULL; RecursiveLocker _(sLock); device_node* parent = node->Parent(); parent->Acquire(); return parent; } static void put_node(device_node* node) { RecursiveLocker _(sLock); node->Release(); } static status_t publish_device(device_node *node, const char *path, const char *moduleName) { if (path == NULL || !path[0] || moduleName == NULL || !moduleName[0]) return B_BAD_VALUE; RecursiveLocker _(sLock); dprintf("publish device: node %p, path %s, module %s\n", node, path, moduleName); Device* device = new(std::nothrow) Device(node, moduleName); if (device == NULL) return B_NO_MEMORY; status_t status = device->InitCheck(); if (status == B_OK) status = devfs_publish_device(path, device); if (status != B_OK) { delete device; return status; } node->AddDevice(device); device_attr_private* attr; attr = new(std::nothrow) device_attr_private(); if (attr != NULL) { char buf[256]; sprintf(buf, "dev/%" B_PRIdINO "/path", device->ID()); attr->name = strdup(buf); attr->type = B_STRING_TYPE; attr->value.string = strdup(path); node->Attributes().Add(attr); } attr = new(std::nothrow) device_attr_private(); if (attr != NULL) { char buf[256]; sprintf(buf, "dev/%" B_PRIdINO "/driver", device->ID()); attr->name = strdup(buf); attr->type = B_STRING_TYPE; attr->value.string = strdup(moduleName); node->Attributes().Add(attr); } return B_OK; } static status_t unpublish_device(device_node *node, const char *path) { if (path == NULL) return B_BAD_VALUE; BaseDevice* baseDevice; status_t error = devfs_get_device(path, baseDevice); if (error != B_OK) return error; CObjectDeleter<BaseDevice, void, devfs_put_device> baseDevicePutter(baseDevice); Device* device = dynamic_cast<Device*>(baseDevice); if (device == NULL || device->Node() != node) return B_BAD_VALUE; return devfs_unpublish_device(device, true); } static status_t get_attr_uint8(const device_node* node, const char* name, uint8* _value, bool recursive) { if (node == NULL || name == NULL || _value == NULL) return B_BAD_VALUE; device_attr_private* attr = find_attr(node, name, recursive, B_UINT8_TYPE); if (attr == NULL) return B_NAME_NOT_FOUND; *_value = attr->value.ui8; return B_OK; } static status_t get_attr_uint16(const device_node* node, const char* name, uint16* _value, bool recursive) { if (node == NULL || name == NULL || _value == NULL) return B_BAD_VALUE; device_attr_private* attr = find_attr(node, name, recursive, B_UINT16_TYPE); if (attr == NULL) return B_NAME_NOT_FOUND; *_value = attr->value.ui16; return B_OK; } static status_t get_attr_uint32(const device_node* node, const char* name, uint32* _value, bool recursive) { if (node == NULL || name == NULL || _value == NULL) return B_BAD_VALUE; device_attr_private* attr = find_attr(node, name, recursive, B_UINT32_TYPE); if (attr == NULL) return B_NAME_NOT_FOUND; *_value = attr->value.ui32; return B_OK; } static status_t get_attr_uint64(const device_node* node, const char* name, uint64* _value, bool recursive) { if (node == NULL || name == NULL || _value == NULL) return B_BAD_VALUE; device_attr_private* attr = find_attr(node, name, recursive, B_UINT64_TYPE); if (attr == NULL) return B_NAME_NOT_FOUND; *_value = attr->value.ui64; return B_OK; } static status_t get_attr_string(const device_node* node, const char* name, const char** _value, bool recursive) { if (node == NULL || name == NULL || _value == NULL) return B_BAD_VALUE; device_attr_private* attr = find_attr(node, name, recursive, B_STRING_TYPE); if (attr == NULL) return B_NAME_NOT_FOUND; *_value = attr->value.string; return B_OK; } static status_t get_attr_raw(const device_node* node, const char* name, const void** _data, size_t* _length, bool recursive) { if (node == NULL || name == NULL || (_data == NULL && _length == NULL)) return B_BAD_VALUE; device_attr_private* attr = find_attr(node, name, recursive, B_RAW_TYPE); if (attr == NULL) return B_NAME_NOT_FOUND; if (_data != NULL) *_data = attr->value.raw.data; if (_length != NULL) *_length = attr->value.raw.length; return B_OK; } static status_t get_next_attr(device_node* node, device_attr** _attr) { if (node == NULL) return B_BAD_VALUE; device_attr_private* next; device_attr_private* attr = *(device_attr_private**)_attr; if (attr != NULL) { // next attribute next = attr->GetDoublyLinkedListLink()->next; } else { // first attribute next = node->Attributes().First(); } *_attr = next; return next ? B_OK : B_ENTRY_NOT_FOUND; } static status_t find_child_node(device_node* parent, const device_attr* attributes, device_node** _node, bool *_lastFound) { RecursiveLocker _(sLock); NodeList::ConstIterator iterator = parent->Children().GetIterator(); device_node* last = *_node; // find the next one that fits while (iterator.HasNext()) { device_node* node = iterator.Next(); if (!node->IsRegistered()) continue; if (node == last) *_lastFound = true; else if (!node->CompareTo(attributes) && *_lastFound) { if (last != NULL) last->Release(); node->Acquire(); *_node = node; return B_OK; } if (find_child_node(node, attributes, _node, _lastFound) == B_OK) return B_OK; } return B_ENTRY_NOT_FOUND; } static status_t find_child_node(device_node* parent, const device_attr* attributes, device_node** _node) { device_node* last = *_node; bool lastFound = last == NULL; status_t status = find_child_node(parent, attributes, _node, &lastFound); if (status == B_ENTRY_NOT_FOUND && last != NULL && lastFound) last->Release(); return status; } struct device_manager_info gDeviceManagerModule = { { B_DEVICE_MANAGER_MODULE_NAME, 0, NULL }, // device nodes rescan_node, register_node, unregister_node, get_driver, get_root_node, get_next_child_node, get_parent_node, put_node, // devices publish_device, unpublish_device, // I/O resources // ID generator dm_create_id, dm_free_id, // attributes get_attr_uint8, get_attr_uint16, get_attr_uint32, get_attr_uint64, get_attr_string, get_attr_raw, get_next_attr, find_child_node }; // #pragma mark - device_attr device_attr_private::device_attr_private() { name = NULL; type = 0; value.raw.data = NULL; value.raw.length = 0; } device_attr_private::device_attr_private(const device_attr& attr) { CopyFrom(attr); } device_attr_private::~device_attr_private() { _Unset(); } status_t device_attr_private::InitCheck() { return name != NULL ? B_OK : B_NO_INIT; } status_t device_attr_private::CopyFrom(const device_attr& attr) { name = strdup(attr.name); if (name == NULL) return B_NO_MEMORY; type = attr.type; switch (type) { case B_UINT8_TYPE: case B_UINT16_TYPE: case B_UINT32_TYPE: case B_UINT64_TYPE: value.ui64 = attr.value.ui64; break; case B_STRING_TYPE: if (attr.value.string != NULL) { value.string = strdup(attr.value.string); if (value.string == NULL) { _Unset(); return B_NO_MEMORY; } } else value.string = NULL; break; case B_RAW_TYPE: value.raw.data = malloc(attr.value.raw.length); if (value.raw.data == NULL) { _Unset(); return B_NO_MEMORY; } value.raw.length = attr.value.raw.length; memcpy((void*)value.raw.data, attr.value.raw.data, attr.value.raw.length); break; default: return B_BAD_VALUE; } return B_OK; } void device_attr_private::_Unset() { if (type == B_STRING_TYPE) free((char*)value.string); else if (type == B_RAW_TYPE) free((void*)value.raw.data); free((char*)name); name = NULL; value.raw.data = NULL; value.raw.length = 0; } /*static*/ int device_attr_private::Compare(const device_attr* attrA, const device_attr *attrB) { if (attrA->type != attrB->type) return -1; switch (attrA->type) { case B_UINT8_TYPE: return (int)attrA->value.ui8 - (int)attrB->value.ui8; case B_UINT16_TYPE: return (int)attrA->value.ui16 - (int)attrB->value.ui16; case B_UINT32_TYPE: if (attrA->value.ui32 > attrB->value.ui32) return 1; if (attrA->value.ui32 < attrB->value.ui32) return -1; return 0; case B_UINT64_TYPE: if (attrA->value.ui64 > attrB->value.ui64) return 1; if (attrA->value.ui64 < attrB->value.ui64) return -1; return 0; case B_STRING_TYPE: return strcmp(attrA->value.string, attrB->value.string); case B_RAW_TYPE: if (attrA->value.raw.length != attrB->value.raw.length) return -1; return memcmp(attrA->value.raw.data, attrB->value.raw.data, attrA->value.raw.length); } return -1; } // #pragma mark - Device Device::Device(device_node* node, const char* moduleName) : fModuleName(strdup(moduleName)), fRemovedFromParent(false) { fNode = node; } Device::~Device() { free((char*)fModuleName); } status_t Device::InitCheck() const { return fModuleName != NULL ? B_OK : B_NO_MEMORY; } status_t Device::InitDevice() { RecursiveLocker _(sLock); if ((fNode->Flags() & NODE_FLAG_DEVICE_REMOVED) != 0) { // TODO: maybe the device should be unlinked in devfs, too return ENODEV; } if ((fNode->Flags() & NODE_FLAG_WAITING_FOR_DRIVER) != 0) return B_BUSY; if (fInitialized++ > 0) { fNode->InitDriver(); // acquire another reference to our parent as well return B_OK; } status_t status = get_module(ModuleName(), (module_info**)&fDeviceModule); if (status == B_OK) { // our parent always has to be initialized status = fNode->InitDriver(); } if (status < B_OK) { fInitialized--; return status; } if (Module()->init_device != NULL) status = Module()->init_device(fNode->DriverData(), &fDeviceData); if (status < B_OK) { fNode->UninitDriver(); fInitialized--; put_module(ModuleName()); fDeviceModule = NULL; fDeviceData = NULL; } return status; } void Device::UninitDevice() { RecursiveLocker _(sLock); if (fInitialized-- > 1) { fNode->UninitDriver(); return; } TRACE(("uninit driver for node %p\n", this)); if (Module()->uninit_device != NULL) Module()->uninit_device(fDeviceData); fDeviceModule = NULL; fDeviceData = NULL; put_module(ModuleName()); fNode->UninitDriver(); } void Device::Removed() { RecursiveLocker _(sLock); if (!fRemovedFromParent) fNode->RemoveDevice(this); delete this; } // #pragma mark - device_node device_node::device_node(const char* moduleName, const device_attr* attrs) { fModuleName = strdup(moduleName); if (fModuleName == NULL) return; fParent = NULL; fRefCount = 1; fInitialized = 0; fRegistered = false; fFlags = 0; fSupportsParent = 0.0; fLastUpdateCycle = 0; fDriver = NULL; fDriverData = NULL; // copy attributes while (attrs != NULL && attrs->name != NULL) { device_attr_private* attr = new(std::nothrow) device_attr_private(*attrs); if (attr == NULL) break; fAttributes.Add(attr); attrs++; } device_attr_private* attr = new(std::nothrow) device_attr_private(); if (attr != NULL) { attr->name = strdup("device/driver"); attr->type = B_STRING_TYPE; attr->value.string = strdup(fModuleName); fAttributes.Add(attr); } get_attr_uint32(this, B_DEVICE_FLAGS, &fFlags, false); fFlags &= NODE_FLAG_PUBLIC_MASK; } device_node::~device_node() { TRACE(("delete node %p\n", this)); ASSERT(DriverModule() == NULL); if (Parent() != NULL) { if ((fFlags & NODE_FLAG_OBSOLETE_DRIVER) != 0) { // This driver has been obsoleted; another driver has been waiting // for us - make it available Parent()->_ReleaseWaiting(); } Parent()->RemoveChild(this); } // Delete children while (device_node* child = fChildren.RemoveHead()) { delete child; } // Delete devices while (Device* device = fDevices.RemoveHead()) { device->SetRemovedFromParent(true); devfs_unpublish_device(device, true); } // Delete attributes while (device_attr_private* attr = fAttributes.RemoveHead()) { delete attr; } // Delete resources while (io_resource_private* resource = fResources.RemoveHead()) { delete resource; } free((char*)fModuleName); } status_t device_node::InitCheck() const { return fModuleName != NULL ? B_OK : B_NO_MEMORY; } status_t device_node::AcquireResources(const io_resource* resources) { if (resources == NULL) return B_OK; for (uint32 i = 0; resources[i].type != 0; i++) { io_resource_private* resource = new(std::nothrow) io_resource_private; if (resource == NULL) return B_NO_MEMORY; status_t status = resource->Acquire(resources[i]); if (status != B_OK) { delete resource; return status; } fResources.Add(resource); } return B_OK; } status_t device_node::InitDriver() { if (fInitialized++ > 0) { if (Parent() != NULL) { Parent()->InitDriver(); // acquire another reference to our parent as well } Acquire(); return B_OK; } status_t status = get_module(ModuleName(), (module_info**)&fDriver); if (status == B_OK && Parent() != NULL) { // our parent always has to be initialized status = Parent()->InitDriver(); } if (status < B_OK) { fInitialized--; return status; } if (fDriver->init_driver != NULL) { status = fDriver->init_driver(this, &fDriverData); if (status != B_OK) { dprintf("driver %s init failed: %s\n", ModuleName(), strerror(status)); } } if (status < B_OK) { if (Parent() != NULL) Parent()->UninitDriver(); fInitialized--; put_module(ModuleName()); fDriver = NULL; fDriverData = NULL; return status; } Acquire(); return B_OK; } bool device_node::UninitDriver() { if (fInitialized-- > 1) { if (Parent() != NULL) Parent()->UninitDriver(); Release(); return false; } TRACE(("uninit driver for node %p\n", this)); if (fDriver->uninit_driver != NULL) fDriver->uninit_driver(fDriverData); fDriver = NULL; fDriverData = NULL; put_module(ModuleName()); if (Parent() != NULL) Parent()->UninitDriver(); Release(); return true; } void device_node::AddChild(device_node* node) { // we must not be destroyed as long as we have children Acquire(); node->fParent = this; int32 priority = node->Priority(); // Enforce an order in which the children are traversed - from most // specific to least specific child. NodeList::Iterator iterator = fChildren.GetIterator(); device_node* before = NULL; while (iterator.HasNext()) { device_node* child = iterator.Next(); if (child->Priority() <= priority) { before = child; break; } } fChildren.Insert(before, node); } void device_node::RemoveChild(device_node* node) { node->fParent = NULL; fChildren.Remove(node); Release(); } /*! Registers this node, and all of its children that have to be registered. Also initializes the driver and keeps it that way on return in case it returns successfully. */ status_t device_node::Register(device_node* parent) { // make it public if (parent != NULL) parent->AddChild(this); else sRootNode = this; status_t status = InitDriver(); if (status != B_OK) return status; if ((fFlags & B_KEEP_DRIVER_LOADED) != 0) { // We keep this driver loaded by having it always initialized InitDriver(); } fFlags |= NODE_FLAG_REGISTER_INITIALIZED; // We don't uninitialize the driver - this is done by the caller // in order to save reinitializing during driver loading. uint32 registeredFixedCount; status = _RegisterFixed(registeredFixedCount); if (status != B_OK) { UninitUnusedDriver(); return status; } // Register the children the driver wants if (DriverModule()->register_child_devices != NULL) { status = DriverModule()->register_child_devices(DriverData()); if (status != B_OK) { UninitUnusedDriver(); return status; } if (!fChildren.IsEmpty()) { fRegistered = true; return B_OK; } } if (registeredFixedCount > 0) { // Nodes with fixed children cannot have any dynamic children, so bail // out here fRegistered = true; return B_OK; } // Register all possible child device nodes status = _RegisterDynamic(); if (status == B_OK) fRegistered = true; else UninitUnusedDriver(); return status; } /*! Registers any children that are identified via the B_DEVICE_FIXED_CHILD attribute. If any of these children cannot be registered, this call will fail (we don't remove children we already registered up to this point in this case). */ status_t device_node::_RegisterFixed(uint32& registered) { AttributeList::Iterator iterator = fAttributes.GetIterator(); registered = 0; while (iterator.HasNext()) { device_attr_private* attr = iterator.Next(); if (strcmp(attr->name, B_DEVICE_FIXED_CHILD)) continue; driver_module_info* driver; status_t status = get_module(attr->value.string, (module_info**)&driver); if (status != B_OK) { TRACE(("register fixed child %s failed: %s\n", attr->value.string, strerror(status))); return status; } if (driver->register_device != NULL) { status = driver->register_device(this); if (status == B_OK) registered++; } put_module(attr->value.string); if (status != B_OK) return status; } return B_OK; } status_t device_node::_AddPath(Stack<KPath*>& stack, const char* basePath, const char* subPath) { KPath* path = new(std::nothrow) KPath; if (path == NULL) return B_NO_MEMORY; status_t status = path->SetTo(basePath); if (status == B_OK && subPath != NULL && subPath[0]) status = path->Append(subPath); if (status == B_OK) status = stack.Push(path); TRACE((" add path: \"%s\", %" B_PRId32 "\n", path->Path(), status)); if (status != B_OK) delete path; return status; } status_t device_node::_GetNextDriverPath(void*& cookie, KPath& _path) { Stack<KPath*>* stack = NULL; if (cookie == NULL) { // find all paths and add them stack = new(std::nothrow) Stack<KPath*>(); if (stack == NULL) return B_NO_MEMORY; StackDeleter<KPath*> stackDeleter(stack); bool generic = false; uint16 type = 0; uint16 subType = 0; uint16 interface = 0; if (get_attr_uint16(this, B_DEVICE_TYPE, &type, false) != B_OK || get_attr_uint16(this, B_DEVICE_SUB_TYPE, &subType, false) != B_OK) generic = true; get_attr_uint16(this, B_DEVICE_INTERFACE, &interface, false); // TODO: maybe make this extendible via settings file? switch (type) { case PCI_mass_storage: switch (subType) { case PCI_scsi: _AddPath(*stack, "busses", "scsi"); _AddPath(*stack, "busses", "virtio"); break; case PCI_ide: _AddPath(*stack, "busses", "ata"); _AddPath(*stack, "busses", "ide"); break; case PCI_sata: // TODO: check for ahci interface _AddPath(*stack, "busses", "scsi"); _AddPath(*stack, "busses", "ata"); _AddPath(*stack, "busses", "ide"); break; case PCI_nvm: _AddPath(*stack, "drivers", "disk"); break; default: _AddPath(*stack, "busses"); break; } break; case PCI_serial_bus: switch (subType) { case PCI_firewire: _AddPath(*stack, "busses", "firewire"); break; case PCI_usb: _AddPath(*stack, "busses", "usb"); break; default: _AddPath(*stack, "busses"); break; } break; case PCI_network: _AddPath(*stack, "drivers", "net"); _AddPath(*stack, "busses", "virtio"); break; case PCI_display: _AddPath(*stack, "drivers", "graphics"); break; case PCI_multimedia: switch (subType) { case PCI_audio: case PCI_hd_audio: _AddPath(*stack, "drivers", "audio"); break; case PCI_video: _AddPath(*stack, "drivers", "video"); break; default: _AddPath(*stack, "drivers"); break; } break; case PCI_base_peripheral: switch (subType) { case PCI_sd_host: _AddPath(*stack, "busses", "mmc"); break; case PCI_system_peripheral_other: _AddPath(*stack, "busses", "mmc"); _AddPath(*stack, "drivers"); break; default: _AddPath(*stack, "drivers"); break; } break; case PCI_data_acquisition: switch (subType) { case PCI_data_acquisition_other: _AddPath(*stack, "busses", "i2c"); break; default: _AddPath(*stack, "drivers"); break; } break; default: if (sRootNode == this) { _AddPath(*stack, "busses/pci"); _AddPath(*stack, "bus_managers"); } else if (!generic) { _AddPath(*stack, "busses", "virtio"); _AddPath(*stack, "drivers"); } else { // For generic drivers, we only allow busses when the // request is more specified if (sGenericContextPath != NULL && (!strcmp(sGenericContextPath, "disk") || !strcmp(sGenericContextPath, "ports") || !strcmp(sGenericContextPath, "bus"))) { _AddPath(*stack, "busses"); } _AddPath(*stack, "drivers", sGenericContextPath); _AddPath(*stack, "busses/i2c"); _AddPath(*stack, "busses/scsi"); _AddPath(*stack, "busses/random"); _AddPath(*stack, "bus_managers/pci"); } break; } stackDeleter.Detach(); cookie = (void*)stack; } else stack = static_cast<Stack<KPath*>*>(cookie); KPath* path; if (stack->Pop(&path)) { _path.Adopt(*path); delete path; return B_OK; } delete stack; return B_ENTRY_NOT_FOUND; } status_t device_node::_GetNextDriver(void* list, driver_module_info*& driver) { while (true) { char name[B_FILE_NAME_LENGTH]; size_t nameLength = sizeof(name); status_t status = read_next_module_name(list, name, &nameLength); if (status != B_OK) return status; if (!strcmp(fModuleName, name)) continue; if (get_module(name, (module_info**)&driver) != B_OK) continue; if (driver->supports_device == NULL || driver->register_device == NULL) { put_module(name); continue; } return B_OK; } } status_t device_node::_FindBestDriver(const char* path, driver_module_info*& bestDriver, float& bestSupport, device_node* previous) { if (bestDriver == NULL) bestSupport = previous != NULL ? previous->fSupportsParent : 0.0f; void* list = open_module_list_etc(path, "driver_v1"); driver_module_info* driver; while (_GetNextDriver(list, driver) == B_OK) { if (previous != NULL && driver == previous->DriverModule()) { put_module(driver->info.name); continue; } float support = driver->supports_device(this); if (support > bestSupport) { if (bestDriver != NULL) put_module(bestDriver->info.name); bestDriver = driver; bestSupport = support; continue; // keep reference to best module around } put_module(driver->info.name); } close_module_list(list); return bestDriver != NULL ? B_OK : B_ENTRY_NOT_FOUND; } status_t device_node::_RegisterPath(const char* path) { void* list = open_module_list_etc(path, "driver_v1"); driver_module_info* driver; uint32 count = 0; while (_GetNextDriver(list, driver) == B_OK) { float support = driver->supports_device(this); if (support > 0.0) { TRACE((" register module \"%s\", support %f\n", driver->info.name, support)); if (driver->register_device(this) == B_OK) count++; } put_module(driver->info.name); } close_module_list(list); return count > 0 ? B_OK : B_ENTRY_NOT_FOUND; } bool device_node::_AlwaysRegisterDynamic() { uint16 type = 0; uint16 subType = 0; get_attr_uint16(this, B_DEVICE_TYPE, &type, false); get_attr_uint16(this, B_DEVICE_SUB_TYPE, &subType, false); return type == PCI_serial_bus || type == PCI_bridge || type == 0; // TODO: we may want to be a bit more specific in the future } status_t device_node::_RegisterDynamic(device_node* previous) { // If this is not a bus, we don't have to scan it if (find_attr(this, B_DEVICE_BUS, false, B_STRING_TYPE) == NULL) return B_OK; // If we're not being probed, we honour the B_FIND_CHILD_ON_DEMAND // requirements if (!IsProbed() && (fFlags & B_FIND_CHILD_ON_DEMAND) != 0 && !_AlwaysRegisterDynamic()) return B_OK; KPath path; if ((fFlags & B_FIND_MULTIPLE_CHILDREN) == 0) { // find the one driver driver_module_info* bestDriver = NULL; float bestSupport = 0.0; void* cookie = NULL; while (_GetNextDriverPath(cookie, path) == B_OK) { _FindBestDriver(path.Path(), bestDriver, bestSupport, previous); } if (bestDriver != NULL) { TRACE((" register best module \"%s\", support %f\n", bestDriver->info.name, bestSupport)); if (bestDriver->register_device(this) == B_OK) { // There can only be one node of this driver // (usually only one at all, but there might be a new driver // "waiting" for its turn) device_node* child = FindChild(bestDriver->info.name); if (child != NULL) { child->fSupportsParent = bestSupport; if (previous != NULL) { previous->fFlags |= NODE_FLAG_OBSOLETE_DRIVER; previous->Release(); child->fFlags |= NODE_FLAG_WAITING_FOR_DRIVER; } } // TODO: if this fails, we could try the second best driver, // and so on... } put_module(bestDriver->info.name); } } else { // register all drivers that match void* cookie = NULL; while (_GetNextDriverPath(cookie, path) == B_OK) { _RegisterPath(path.Path()); } } return B_OK; } void device_node::_ReleaseWaiting() { NodeList::Iterator iterator = fChildren.GetIterator(); while (iterator.HasNext()) { device_node* child = iterator.Next(); child->fFlags &= ~NODE_FLAG_WAITING_FOR_DRIVER; } } status_t device_node::_RemoveChildren() { NodeList::Iterator iterator = fChildren.GetIterator(); while (iterator.HasNext()) { device_node* child = iterator.Next(); child->Release(); } return fChildren.IsEmpty() ? B_OK : B_BUSY; } device_node* device_node::_FindCurrentChild() { NodeList::Iterator iterator = fChildren.GetIterator(); while (iterator.HasNext()) { device_node* child = iterator.Next(); if ((child->Flags() & NODE_FLAG_WAITING_FOR_DRIVER) == 0) return child; } return NULL; } status_t device_node::_Probe() { device_node* previous = NULL; if (IsProbed() && !fChildren.IsEmpty() && (fFlags & (B_FIND_CHILD_ON_DEMAND | B_FIND_MULTIPLE_CHILDREN)) == B_FIND_CHILD_ON_DEMAND) { // We already have a driver that claims this node; remove all // (unused) nodes, and evaluate it again _RemoveChildren(); previous = _FindCurrentChild(); if (previous != NULL) { // This driver is still active - give it back the reference // that was stolen by _RemoveChildren() - _RegisterDynamic() // will release it, if it really isn't needed anymore previous->Acquire(); } } return _RegisterDynamic(previous); } status_t device_node::Probe(const char* devicePath, uint32 updateCycle) { if ((fFlags & NODE_FLAG_DEVICE_REMOVED) != 0 || updateCycle == fLastUpdateCycle) return B_OK; status_t status = InitDriver(); if (status < B_OK) return status; MethodDeleter<device_node, bool, &device_node::UninitDriver> uninit(this); if ((fFlags & B_FIND_CHILD_ON_DEMAND) != 0) { bool matches = false; uint16 type = 0; uint16 subType = 0; if (get_attr_uint16(this, B_DEVICE_SUB_TYPE, &subType, false) == B_OK && get_attr_uint16(this, B_DEVICE_TYPE, &type, false) == B_OK) { // Check if this node matches the device path // TODO: maybe make this extendible via settings file? if (!strcmp(devicePath, "disk")) { matches = type == PCI_mass_storage || (type == PCI_base_peripheral && (subType == PCI_sd_host || subType == PCI_system_peripheral_other)); } else if (!strcmp(devicePath, "audio")) { matches = type == PCI_multimedia && (subType == PCI_audio || subType == PCI_hd_audio); } else if (!strcmp(devicePath, "net")) { matches = type == PCI_network; } else if (!strcmp(devicePath, "graphics")) { matches = type == PCI_display; } else if (!strcmp(devicePath, "video")) { matches = type == PCI_multimedia && subType == PCI_video; } else if (!strcmp(devicePath, "power")) { matches = type == PCI_data_acquisition; } else if (!strcmp(devicePath, "input")) { matches = type == PCI_data_acquisition && subType == PCI_data_acquisition_other; } } else { // This driver does not support types, but still wants to its // children explored on demand only. matches = true; sGenericContextPath = devicePath; } if (matches) { fLastUpdateCycle = updateCycle; // This node will be probed in this update cycle status = _Probe(); sGenericContextPath = NULL; return status; } return B_OK; } NodeList::Iterator iterator = fChildren.GetIterator(); while (iterator.HasNext()) { device_node* child = iterator.Next(); status = child->Probe(devicePath, updateCycle); if (status != B_OK) return status; } return B_OK; } status_t device_node::Reprobe() { status_t status = InitDriver(); if (status < B_OK) return status; MethodDeleter<device_node, bool, &device_node::UninitDriver> uninit(this); // If this child has been probed already, probe it again status = _Probe(); if (status != B_OK) return status; NodeList::Iterator iterator = fChildren.GetIterator(); while (iterator.HasNext()) { device_node* child = iterator.Next(); status = child->Reprobe(); if (status != B_OK) return status; } return B_OK; } status_t device_node::Rescan() { status_t status = InitDriver(); if (status < B_OK) return status; MethodDeleter<device_node, bool, &device_node::UninitDriver> uninit(this); if (DriverModule()->rescan_child_devices != NULL) { status = DriverModule()->rescan_child_devices(DriverData()); if (status != B_OK) return status; } NodeList::Iterator iterator = fChildren.GetIterator(); while (iterator.HasNext()) { device_node* child = iterator.Next(); status = child->Rescan(); if (status != B_OK) return status; } return B_OK; } /*! Uninitializes all temporary references to the driver. The registration process keeps the driver initialized to optimize the startup procedure; this function gives this reference away again. */ void device_node::UninitUnusedDriver() { // First, we need to go to the leaf, and go back from there NodeList::Iterator iterator = fChildren.GetIterator(); while (iterator.HasNext()) { device_node* child = iterator.Next(); child->UninitUnusedDriver(); } if (!IsInitialized() || (fFlags & NODE_FLAG_REGISTER_INITIALIZED) == 0) return; fFlags &= ~NODE_FLAG_REGISTER_INITIALIZED; UninitDriver(); } /*! Calls device_removed() on this node and all of its children - starting with the deepest and last child. It will also remove the one reference that every node gets on its creation. */ void device_node::DeviceRemoved() { // notify children NodeList::ConstIterator iterator = Children().GetIterator(); while (iterator.HasNext()) { device_node* child = iterator.Next(); child->DeviceRemoved(); } // notify devices DeviceList::ConstIterator deviceIterator = Devices().GetIterator(); while (deviceIterator.HasNext()) { Device* device = deviceIterator.Next(); if (device->Module() != NULL && device->Module()->device_removed != NULL) device->Module()->device_removed(device->Data()); } fFlags |= NODE_FLAG_DEVICE_REMOVED; if (IsInitialized() && DriverModule()->device_removed != NULL) DriverModule()->device_removed(this); if ((fFlags & B_KEEP_DRIVER_LOADED) != 0) { // There is no point in keeping this driver loaded when its device // is gone UninitDriver(); } UninitUnusedDriver(); Release(); } void device_node::Acquire() { atomic_add(&fRefCount, 1); } bool device_node::Release() { if (atomic_add(&fRefCount, -1) > 1) return false; delete this; return true; } void device_node::AddDevice(Device* device) { fDevices.Add(device); } void device_node::RemoveDevice(Device* device) { char attrName[256]; device_attr_private* attr; sprintf(attrName, "dev/%" B_PRIdINO "/path", device->ID()); attr = find_attr(this, attrName, false, B_STRING_TYPE); if (attr != NULL) { fAttributes.Remove(attr); delete attr; } sprintf(attrName, "dev/%" B_PRIdINO "/driver", device->ID()); attr = find_attr(this, attrName, false, B_STRING_TYPE); if (attr != NULL) { fAttributes.Remove(attr); delete attr; } fDevices.Remove(device); } int device_node::CompareTo(const device_attr* attributes) const { if (attributes == NULL) return -1; for (; attributes->name != NULL; attributes++) { // find corresponding attribute AttributeList::ConstIterator iterator = Attributes().GetIterator(); device_attr_private* attr = NULL; bool found = false; while (iterator.HasNext()) { attr = iterator.Next(); if (!strcmp(attr->name, attributes->name)) { found = true; break; } } if (!found) return -1; int compare = device_attr_private::Compare(attr, attributes); if (compare != 0) return compare; } return 0; } device_node* device_node::FindChild(const device_attr* attributes) const { if (attributes == NULL) return NULL; NodeList::ConstIterator iterator = Children().GetIterator(); while (iterator.HasNext()) { device_node* child = iterator.Next(); // ignore nodes that are pending to be removed if ((child->Flags() & NODE_FLAG_DEVICE_REMOVED) == 0 && !child->CompareTo(attributes)) return child; } return NULL; } device_node* device_node::FindChild(const char* moduleName) const { if (moduleName == NULL) return NULL; NodeList::ConstIterator iterator = Children().GetIterator(); while (iterator.HasNext()) { device_node* child = iterator.Next(); if (!strcmp(child->ModuleName(), moduleName)) return child; } return NULL; } /*! This returns the priority or importance of this node. Nodes with higher priority are registered/probed first. Currently, only the B_FIND_MULTIPLE_CHILDREN flag alters the priority; it might make sense to be able to directly set the priority via an attribute. */ int32 device_node::Priority() { return (fFlags & B_FIND_MULTIPLE_CHILDREN) != 0 ? 0 : 100; } void device_node::Dump(int32 level) { put_level(level); kprintf("(%" B_PRId32 ") @%p \"%s\" (ref %" B_PRId32 ", init %" B_PRId32 ", module %p, data %p)\n", level, this, ModuleName(), fRefCount, fInitialized, DriverModule(), DriverData()); AttributeList::Iterator attribute = Attributes().GetIterator(); while (attribute.HasNext()) { dump_attribute(attribute.Next(), level); } DeviceList::Iterator deviceIterator = fDevices.GetIterator(); while (deviceIterator.HasNext()) { Device* device = deviceIterator.Next(); put_level(level); kprintf("device: %s, %p\n", device->ModuleName(), device->Data()); } NodeList::ConstIterator iterator = Children().GetIterator(); while (iterator.HasNext()) { iterator.Next()->Dump(level + 1); } } // #pragma mark - root node static void init_node_tree(void) { device_attr attrs[] = { {B_DEVICE_PRETTY_NAME, B_STRING_TYPE, {string: "Devices Root"}}, {B_DEVICE_BUS, B_STRING_TYPE, {string: "root"}}, {B_DEVICE_FLAGS, B_UINT32_TYPE, {ui32: B_FIND_MULTIPLE_CHILDREN | B_KEEP_DRIVER_LOADED }}, {NULL} }; device_node* node = NULL; if (register_node(NULL, DEVICE_MANAGER_ROOT_NAME, attrs, NULL, &node) != B_OK) { dprintf("Cannot register Devices Root Node\n"); } device_attr genericAttrs[] = { {B_DEVICE_PRETTY_NAME, B_STRING_TYPE, {string: "Generic"}}, {B_DEVICE_BUS, B_STRING_TYPE, {string: "generic"}}, {B_DEVICE_FLAGS, B_UINT32_TYPE, {ui32: B_FIND_MULTIPLE_CHILDREN | B_KEEP_DRIVER_LOADED | B_FIND_CHILD_ON_DEMAND}}, {NULL} }; if (register_node(node, DEVICE_MANAGER_GENERIC_NAME, genericAttrs, NULL, NULL) != B_OK) { dprintf("Cannot register Generic Devices Node\n"); } } driver_module_info gDeviceRootModule = { { DEVICE_MANAGER_ROOT_NAME, 0, NULL, }, }; driver_module_info gDeviceGenericModule = { { DEVICE_MANAGER_GENERIC_NAME, 0, NULL, }, NULL }; // #pragma mark - private kernel API status_t device_manager_probe(const char* path, uint32 updateCycle) { TRACE(("device_manager_probe(\"%s\")\n", path)); RecursiveLocker _(sLock); // first, publish directories in the driver directory publish_directories(path); return sRootNode->Probe(path, updateCycle); } status_t device_manager_init(struct kernel_args* args) { TRACE(("device manager init\n")); IOSchedulerRoster::Init(); dm_init_id_generator(); dm_init_io_resources(); recursive_lock_init(&sLock, "device manager"); register_generic_syscall(DEVICE_MANAGER_SYSCALLS, control_device_manager, 1, 0); add_debugger_command("dm_tree", &dump_device_nodes, "dump device node tree"); add_debugger_command_etc("io_scheduler", &dump_io_scheduler, "Dump an I/O scheduler", "<scheduler>\n" "Dumps I/O scheduler at address <scheduler>.\n", 0); add_debugger_command_etc("io_request_owner", &dump_io_request_owner, "Dump an I/O request owner", "<owner>\n" "Dumps I/O request owner at address <owner>.\n", 0); add_debugger_command("io_request", &dump_io_request, "dump an I/O request"); add_debugger_command("io_operation", &dump_io_operation, "dump an I/O operation"); add_debugger_command("io_buffer", &dump_io_buffer, "dump an I/O buffer"); add_debugger_command("dma_buffer", &dump_dma_buffer, "dump a DMA buffer"); init_node_tree(); return B_OK; } status_t device_manager_init_post_modules(struct kernel_args* args) { RecursiveLocker _(sLock); return sRootNode->Reprobe(); }
// // Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.16384 // // /// // Buffer Definitions: // // cbuffer cbPNTriangles // { // // float4x4 g_f4x4World; // Offset: 0 Size: 64 // float4x4 g_f4x4ViewProjection; // Offset: 64 Size: 64 [unused] // float4x4 g_f4x4WorldViewProjection;// Offset: 128 Size: 64 [unused] // float4 g_f4LightDir; // Offset: 192 Size: 16 [unused] // float4 g_f4Eye; // Offset: 208 Size: 16 [unused] // float4 g_f4ViewVector; // Offset: 224 Size: 16 [unused] // float4 g_f4TessFactors; // Offset: 240 Size: 16 [unused] // float4 g_f4ScreenParams; // Offset: 256 Size: 16 [unused] // float4 g_f4GUIParams1; // Offset: 272 Size: 16 [unused] // float4 g_f4GUIParams2; // Offset: 288 Size: 16 [unused] // float4 g_f4ViewFrustumPlanes[4]; // Offset: 304 Size: 64 [unused] // // } // // // Resource Bindings: // // Name Type Format Dim Slot Elements // ------------------------------ ---------- ------- ----------- ---- -------- // cbPNTriangles cbuffer NA NA 0 1 // // // // Input signature: // // Name Index Mask Register SysValue Format Used // -------------------- ----- ------ -------- -------- ------- ------ // POSITION 0 xyz 0 NONE float xyz // NORMAL 0 xyz 1 NONE float xyz // TEXCOORD 0 xy 2 NONE float xy // // // Output signature: // // Name Index Mask Register SysValue Format Used // -------------------- ----- ------ -------- -------- ------- ------ // POSITION 0 xyz 0 NONE float xyz // NORMAL 0 xyz 1 NONE float xyz // TEXCOORD 0 xy 2 NONE float xy // vs_5_0 dcl_globalFlags refactoringAllowed dcl_constantbuffer cb0[3], immediateIndexed dcl_input v0.xyz dcl_input v1.xyz dcl_input v2.xy dcl_output o0.xyz dcl_output o1.xyz dcl_output o2.xy dcl_temps 1 dp3 o0.x, v0.xyzx, cb0[0].xyzx dp3 o0.y, v0.xyzx, cb0[1].xyzx dp3 o0.z, v0.xyzx, cb0[2].xyzx dp3 r0.x, v1.xyzx, cb0[0].xyzx dp3 r0.y, v1.xyzx, cb0[1].xyzx dp3 r0.z, v1.xyzx, cb0[2].xyzx dp3 r0.w, r0.xyzx, r0.xyzx rsq r0.w, r0.w mul o1.xyz, r0.wwww, r0.xyzx mov o2.xy, v2.xyxx ret // Approximately 11 instruction slots used
;******************************************************************************* ; @INSTITUTION ; University of Sao Paulo | Sao Carlos School of Engineering | SEL ;------------------------------------------------------------------------------ ; @DISCIPLINE ; Name: SEL0433 | Applications of Microprocessors I ; Professor: Evandro Luis Linhari Rodrigues ; Semester: 2017\01 ;------------------------------------------------------------------------------ ; @DEVELOPMENT ; MCU: Intel 8052 ; IDE: MCU 8051 v1.5.7 ; Compiler: IDE native assembler ;------------------------------------------------------------------------------ ; @WARRANTY ; Copyright (c) 2017 Andre Marcos Perez ; The software is provided by "as is", without warranty of any kind, express or ; implied, including but not limited to the warranties of merchantability, ; fitness for a particular purpose and noninfringement. In no event shall the ; authors or copyright holders be liable for any claim, damages or other ; liability, whether in an action of contract, tort or otherwise, arising from, ; out of or in connection with the software or the use or other dealings in the ; software. ;------------------------------------------------------------------------------ ; @EXERCISE ; List: #2 ; Ex. : #5 ;------------------------------------------------------------------------------ ; @AUTHOR ; Name: Andre Marcos Perez ; Email: andre.marcos.perez@usp.br ; #USP: 8006891 ;******************************************************************************* ;******************************************************************************* ; @CONSTANT ; Code's constants ;------------------------------------------------------------------------------ EXTERNAL_RAM_ADDRESS_CURRENT_MSB EQU 1000H INTERNAL_RAM_ADDRESS_LITTLE_ENDIAN_MSB EQU 20H ;******************************************************************************* ;******************************************************************************* ; @CODE ; Main code ;------------------------------------------------------------------------------ ORG 0 MOV DPTR,#(EXTERNAL_RAM_ADDRESS_CURRENT_MSB+2D) MOV R1,#(INTERNAL_RAM_ADDRESS_LITTLE_ENDIAN_MSB+0D) MOV R0,#07H LOOP: MOV C,F0 MOVX A,@DPTR ADDC A,@R0 MOV F0,C MOV @R1,A DEC DPL INC R1 DEC R0 CJNE R1,#(INTERNAL_RAM_ADDRESS_LITTLE_ENDIAN_MSB+3D),LOOP SJMP $ ;******************************************************************************* END
.global s_prepare_buffers s_prepare_buffers: push %r12 push %r15 push %r8 push %rbx push %rcx push %rdi push %rdx push %rsi lea addresses_WT_ht+0x1c35a, %rdi nop nop nop add %r15, %r15 movb (%rdi), %r12b and %r15, %r15 lea addresses_A_ht+0xb0da, %r8 nop nop nop cmp %rdx, %rdx mov (%r8), %ebx nop nop nop nop nop and $20863, %r15 lea addresses_UC_ht+0x51ca, %rsi lea addresses_UC_ht+0x57c7, %rdi inc %r8 mov $114, %rcx rep movsq nop nop nop nop nop and $23839, %rsi pop %rsi pop %rdx pop %rdi pop %rcx pop %rbx pop %r8 pop %r15 pop %r12 ret .global s_faulty_load s_faulty_load: push %r12 push %r13 push %r9 push %rbp push %rsi // Faulty Load lea addresses_RW+0x1d55a, %r13 nop nop nop nop nop add %rbp, %rbp mov (%r13), %r12d lea oracles, %rsi and $0xff, %r12 shlq $12, %r12 mov (%rsi,%r12,1), %r12 pop %rsi pop %rbp pop %r9 pop %r13 pop %r12 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_RW', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_RW', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}} <gen_prepare_buffer> {'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 9, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_A_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 6, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 4, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 0, 'same': False}} {'32': 21829} 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 */
; Sets kdbg stack to a safe place, because we can do there context switching. ; Call the handler EXTERN kdbg_handler, kdbg_stack_hi GLOBAL kdbg_handler_enter kdbg_handler_enter: push ebp mov ebp, esp mov esp, [kdbg_stack_hi] call kdbg_handler mov esp, ebp pop ebp ret
; A155977: a(n) = n^5 + n^3. ; 0,2,40,270,1088,3250,7992,17150,33280,59778,101000,162382,250560,373490,540568,762750,1052672,1424770,1895400,2482958,3208000,4093362,5164280,6448510,7976448,9781250,11898952,14368590,17232320,20535538,24327000,28658942,33587200,39171330,45474728,52564750,60512832,69394610,79290040,90283518,102464000,115925122,130765320,147087950,165001408,184619250,206060312,229448830,254914560,282592898,312625000,345157902,380344640,418344370,459322488,503450750,550907392,601877250,656551880,715129678,777816000,844823282,916371160,992686590,1074003968,1160565250,1252620072,1350425870,1454248000,1564359858,1681043000,1804587262,1935290880,2073460610,2219411848,2373468750,2535964352,2707240690,2887648920,3077549438,3277312000,3487315842,3707949800,3939612430,4182712128,4437667250,4704906232,4984867710,5278000640,5584764418,5905629000,6241075022,6591593920,6957688050,7339870808,7738666750,8154611712,8588252930,9040149160,9510870798,10001000000,10511130802,11041869240,11593833470,12167653888,12763973250,13383446792,14026742350,14694540480,15387534578,16106431000,16851949182,17624821760,18425794690,19255627368,20115092750,21004977472,21926081970,22879220600,23865221758,24884928000,25939196162,27028897480,28154917710,29318157248,30519531250,31759969752,33040417790,34361835520,35725198338,37131497000,38581737742,40076942400,41618148530,43206409528,44842794750,46528389632,48264295810,50051631240,51891530318,53785144000,55733639922,57738202520,59800033150,61920350208,64100389250,66341403112,68644662030,71011453760,73443083698,75940875000,78506168702,81140323840,83844717570,86620745288,89469820750,92393376192,95392862450,98469749080,101625524478,104861696000,108179790082,111581352360,115067947790,118641160768,122302595250,126053874872,129896643070,133832563200,137863318658,141990613000,146216170062,150541734080,154969069810,159499962648,164136218750,168879665152,173732149890,178695542120,183771732238,188962632000,194270174642,199696315000,205243029630,210912316928,216706197250,222626713032,228675928910,234855931840,241168831218,247616759000,254201869822,260926341120,267792373250,274802189608,281958036750,289262184512,296716926130,304324578360,312087481598,320008000000,328088521602,336331458440,344739246670,353314346688,362059243250,370976445592,380068487550,389337927680,398787349378,408419361000,418236595982,428241712960,438437395890,448826354168,459411322750,470195062272,481180359170,492370025800,503766900558,515373848000,527193758962,539229550680,551484166910,563960578048,576661781250,589590800552,602750686990,616144518720,629775401138,643646467000,657760876542,672121817600,686732505730,701596184328,716716124750,732095626432,747738017010,763646652440,779824917118,796276224000,813004014722,830011759720,847302958350,864881139008,882749859250,900912705912,919373295230,938135272960,957202314498 mov $1,$0 pow $0,3 pow $1,5 add $1,$0
/* Copyright 2019 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 "constants.h" // This is a small number so that it's easy to read the logs const int kInferencesPerCycle = 1000;
; write a program that prints 123123 in STDOUT global _start section .data num: dd 12312311; use a label to refer to a specific location in memory newline: db 0xA section .test string_len: xor rax, rax; empty rax to be used as counter over the elements .loop: cmp byte[rdi + rax], 0 je .end inc rax jmp .loop .end: ret print_newline: xor rax, rax mov rax, 1; we want to WRITE mov rdi, 1; into the 1 file descriptor (STDOUT) mov rsi, newline; newline char mov rdx, 1; just one byte syscall ret print_string: push rdi; caller-saved argument call string_len pop rsi; take from the stack the old value of rdi that is now stored in rsi because this is the starting point for printing mov rdx, rax; how many bytes we need to read equals the length of the string we just computed through the previous call mov rax, 1 mov rdi, 1 syscall ret; print_uint: mov rax, rdi push 0; 0 is pushed to the stack. This will be the termination point for the string representing the number mov rdi, rsp; sub rsp, 16; we create a buffer on the stack that we are going to fill ; with the previous we take 16 bytes from the stack dec rdi; move below the 0 is pointing to mov r8, 10; .loop: xor rdx, rdx; div r8; quotient will be saved in rax while reminder in rdx or dl, 0x30; dl is the lowest byte of rdx. Here we get the relevant ascii code for the reminder (the bitwise or is going to increse the 0x30 moving over the ascii table) dec rdi; mov [rdi], dl test rax, rax jnz .loop call print_string add rsp, 24 ; why 24 here??? if less there will be a segmentation fault ; we give back space to the stack that we don't need anymore ; SOLUTION: is 24 because the architecture is 64 bits so the slot are of 8*8 ; this means that we need to go back and pass the block that contains the 0 (made of 8 slices of 8 bits) ; ______________________________________________________________________________________ ; if we add back to the stack 24 of buffer we get to the state before the 0 was pushed into the stack ; recall that the status of the world has to be resetted at the end of the function execution ; when we pop from the stack we need to get the same rip we pushed by calling the funcion ret _start: ;mov rdi, qword[num] ; this will create problems becuase the compiler will go to read in more memory area than desired mov edi, dword[num] ; num is used as a label for the memory area while we need to get the data in the memory cell ; how can we extend the 32 bit num so that the remaining bits are 0 instead of taking it from memory call print_uint call print_newline mov rax, 60; xor rdi,rdi; syscall; ; Troubles encountered/ mistakes I made ; 1) pushing into the registry data with lower bits than 64 ; if we print without the newline everythin works fine ; but if we add the newline, this is printed but the number showed is different ; we were accessing the memory like this: mov rdi, [num] ; but instead of 32bits the compiler was trying to put into rdi 64bits ; if there was nothing into the memory(undefined) we did not get the unexpected behaviour ; but if in the adjacent places in memory there was some data (like newline in this case) ; then we get a corruption due to this data ; so since [num] will go to
; ; jfdctflt.asm - floating-point FDCT (SSE) ; ; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB ; ; Based on the x86 SIMD extension for IJG JPEG library ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; ; This file should be assembled with NASM (Netwide Assembler), ; can *not* be assembled with Microsoft's MASM or any compatible ; assembler (including Borland's Turbo Assembler). ; NASM is available from http://nasm.sourceforge.net/ or ; http://sourceforge.net/project/showfiles.php?group_id=6208 ; ; This file contains a floating-point implementation of the forward DCT ; (Discrete Cosine Transform). The following code is based directly on ; the IJG's original jfdctflt.c; see the jfdctflt.c for more details. ; ; [TAB8] %include "jsimdext.inc" %include "jdct.inc" ; -------------------------------------------------------------------------- %macro unpcklps2 2 ; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(0 1 4 5) shufps %1,%2,0x44 %endmacro %macro unpckhps2 2 ; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(2 3 6 7) shufps %1,%2,0xEE %endmacro ; -------------------------------------------------------------------------- SECTION SEG_CONST alignz 16 global EXTN(jconst_fdct_float_sse) EXTN(jconst_fdct_float_sse): PD_0_382 times 4 dd 0.382683432365089771728460 PD_0_707 times 4 dd 0.707106781186547524400844 PD_0_541 times 4 dd 0.541196100146196984399723 PD_1_306 times 4 dd 1.306562964876376527856643 alignz 16 ; -------------------------------------------------------------------------- SECTION SEG_TEXT BITS 32 ; ; Perform the forward DCT on one block of samples. ; ; GLOBAL(void) ; jsimd_fdct_float_sse (FAST_FLOAT *data) ; %define data(b) (b)+8 ; FAST_FLOAT *data %define original_ebp ebp+0 %define wk(i) ebp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] %define WK_NUM 2 align 16 global EXTN(jsimd_fdct_float_sse) EXTN(jsimd_fdct_float_sse): push ebp mov eax,esp ; eax = original ebp sub esp, byte 4 and esp, byte (-SIZEOF_XMMWORD) ; align to 128 bits mov [esp],eax mov ebp,esp ; ebp = aligned ebp lea esp, [wk(0)] pushpic ebx ; push ecx ; need not be preserved ; push edx ; need not be preserved ; push esi ; unused ; push edi ; unused get_GOT ebx ; get GOT address ; ---- Pass 1: process rows. mov edx, POINTER [data(eax)] ; (FAST_FLOAT *) mov ecx, DCTSIZE/4 alignx 16,7 .rowloop: movaps xmm0, XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_FAST_FLOAT)] movaps xmm1, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_FAST_FLOAT)] movaps xmm2, XMMWORD [XMMBLOCK(2,1,edx,SIZEOF_FAST_FLOAT)] movaps xmm3, XMMWORD [XMMBLOCK(3,1,edx,SIZEOF_FAST_FLOAT)] ; xmm0=(20 21 22 23), xmm2=(24 25 26 27) ; xmm1=(30 31 32 33), xmm3=(34 35 36 37) movaps xmm4,xmm0 ; transpose coefficients(phase 1) unpcklps xmm0,xmm1 ; xmm0=(20 30 21 31) unpckhps xmm4,xmm1 ; xmm4=(22 32 23 33) movaps xmm5,xmm2 ; transpose coefficients(phase 1) unpcklps xmm2,xmm3 ; xmm2=(24 34 25 35) unpckhps xmm5,xmm3 ; xmm5=(26 36 27 37) movaps xmm6, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)] movaps xmm7, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)] movaps xmm1, XMMWORD [XMMBLOCK(0,1,edx,SIZEOF_FAST_FLOAT)] movaps xmm3, XMMWORD [XMMBLOCK(1,1,edx,SIZEOF_FAST_FLOAT)] ; xmm6=(00 01 02 03), xmm1=(04 05 06 07) ; xmm7=(10 11 12 13), xmm3=(14 15 16 17) movaps XMMWORD [wk(0)], xmm4 ; wk(0)=(22 32 23 33) movaps XMMWORD [wk(1)], xmm2 ; wk(1)=(24 34 25 35) movaps xmm4,xmm6 ; transpose coefficients(phase 1) unpcklps xmm6,xmm7 ; xmm6=(00 10 01 11) unpckhps xmm4,xmm7 ; xmm4=(02 12 03 13) movaps xmm2,xmm1 ; transpose coefficients(phase 1) unpcklps xmm1,xmm3 ; xmm1=(04 14 05 15) unpckhps xmm2,xmm3 ; xmm2=(06 16 07 17) movaps xmm7,xmm6 ; transpose coefficients(phase 2) unpcklps2 xmm6,xmm0 ; xmm6=(00 10 20 30)=data0 unpckhps2 xmm7,xmm0 ; xmm7=(01 11 21 31)=data1 movaps xmm3,xmm2 ; transpose coefficients(phase 2) unpcklps2 xmm2,xmm5 ; xmm2=(06 16 26 36)=data6 unpckhps2 xmm3,xmm5 ; xmm3=(07 17 27 37)=data7 movaps xmm0,xmm7 movaps xmm5,xmm6 subps xmm7,xmm2 ; xmm7=data1-data6=tmp6 subps xmm6,xmm3 ; xmm6=data0-data7=tmp7 addps xmm0,xmm2 ; xmm0=data1+data6=tmp1 addps xmm5,xmm3 ; xmm5=data0+data7=tmp0 movaps xmm2, XMMWORD [wk(0)] ; xmm2=(22 32 23 33) movaps xmm3, XMMWORD [wk(1)] ; xmm3=(24 34 25 35) movaps XMMWORD [wk(0)], xmm7 ; wk(0)=tmp6 movaps XMMWORD [wk(1)], xmm6 ; wk(1)=tmp7 movaps xmm7,xmm4 ; transpose coefficients(phase 2) unpcklps2 xmm4,xmm2 ; xmm4=(02 12 22 32)=data2 unpckhps2 xmm7,xmm2 ; xmm7=(03 13 23 33)=data3 movaps xmm6,xmm1 ; transpose coefficients(phase 2) unpcklps2 xmm1,xmm3 ; xmm1=(04 14 24 34)=data4 unpckhps2 xmm6,xmm3 ; xmm6=(05 15 25 35)=data5 movaps xmm2,xmm7 movaps xmm3,xmm4 addps xmm7,xmm1 ; xmm7=data3+data4=tmp3 addps xmm4,xmm6 ; xmm4=data2+data5=tmp2 subps xmm2,xmm1 ; xmm2=data3-data4=tmp4 subps xmm3,xmm6 ; xmm3=data2-data5=tmp5 ; -- Even part movaps xmm1,xmm5 movaps xmm6,xmm0 subps xmm5,xmm7 ; xmm5=tmp13 subps xmm0,xmm4 ; xmm0=tmp12 addps xmm1,xmm7 ; xmm1=tmp10 addps xmm6,xmm4 ; xmm6=tmp11 addps xmm0,xmm5 mulps xmm0,[GOTOFF(ebx,PD_0_707)] ; xmm0=z1 movaps xmm7,xmm1 movaps xmm4,xmm5 subps xmm1,xmm6 ; xmm1=data4 subps xmm5,xmm0 ; xmm5=data6 addps xmm7,xmm6 ; xmm7=data0 addps xmm4,xmm0 ; xmm4=data2 movaps XMMWORD [XMMBLOCK(0,1,edx,SIZEOF_FAST_FLOAT)], xmm1 movaps XMMWORD [XMMBLOCK(2,1,edx,SIZEOF_FAST_FLOAT)], xmm5 movaps XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)], xmm7 movaps XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_FAST_FLOAT)], xmm4 ; -- Odd part movaps xmm6, XMMWORD [wk(0)] ; xmm6=tmp6 movaps xmm0, XMMWORD [wk(1)] ; xmm0=tmp7 addps xmm2,xmm3 ; xmm2=tmp10 addps xmm3,xmm6 ; xmm3=tmp11 addps xmm6,xmm0 ; xmm6=tmp12, xmm0=tmp7 mulps xmm3,[GOTOFF(ebx,PD_0_707)] ; xmm3=z3 movaps xmm1,xmm2 ; xmm1=tmp10 subps xmm2,xmm6 mulps xmm2,[GOTOFF(ebx,PD_0_382)] ; xmm2=z5 mulps xmm1,[GOTOFF(ebx,PD_0_541)] ; xmm1=MULTIPLY(tmp10,FIX_0_541196) mulps xmm6,[GOTOFF(ebx,PD_1_306)] ; xmm6=MULTIPLY(tmp12,FIX_1_306562) addps xmm1,xmm2 ; xmm1=z2 addps xmm6,xmm2 ; xmm6=z4 movaps xmm5,xmm0 subps xmm0,xmm3 ; xmm0=z13 addps xmm5,xmm3 ; xmm5=z11 movaps xmm7,xmm0 movaps xmm4,xmm5 subps xmm0,xmm1 ; xmm0=data3 subps xmm5,xmm6 ; xmm5=data7 addps xmm7,xmm1 ; xmm7=data5 addps xmm4,xmm6 ; xmm4=data1 movaps XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_FAST_FLOAT)], xmm0 movaps XMMWORD [XMMBLOCK(3,1,edx,SIZEOF_FAST_FLOAT)], xmm5 movaps XMMWORD [XMMBLOCK(1,1,edx,SIZEOF_FAST_FLOAT)], xmm7 movaps XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)], xmm4 add edx, 4*DCTSIZE*SIZEOF_FAST_FLOAT dec ecx jnz near .rowloop ; ---- Pass 2: process columns. mov edx, POINTER [data(eax)] ; (FAST_FLOAT *) mov ecx, DCTSIZE/4 alignx 16,7 .columnloop: movaps xmm0, XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_FAST_FLOAT)] movaps xmm1, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_FAST_FLOAT)] movaps xmm2, XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_FAST_FLOAT)] movaps xmm3, XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_FAST_FLOAT)] ; xmm0=(02 12 22 32), xmm2=(42 52 62 72) ; xmm1=(03 13 23 33), xmm3=(43 53 63 73) movaps xmm4,xmm0 ; transpose coefficients(phase 1) unpcklps xmm0,xmm1 ; xmm0=(02 03 12 13) unpckhps xmm4,xmm1 ; xmm4=(22 23 32 33) movaps xmm5,xmm2 ; transpose coefficients(phase 1) unpcklps xmm2,xmm3 ; xmm2=(42 43 52 53) unpckhps xmm5,xmm3 ; xmm5=(62 63 72 73) movaps xmm6, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)] movaps xmm7, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)] movaps xmm1, XMMWORD [XMMBLOCK(4,0,edx,SIZEOF_FAST_FLOAT)] movaps xmm3, XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_FAST_FLOAT)] ; xmm6=(00 10 20 30), xmm1=(40 50 60 70) ; xmm7=(01 11 21 31), xmm3=(41 51 61 71) movaps XMMWORD [wk(0)], xmm4 ; wk(0)=(22 23 32 33) movaps XMMWORD [wk(1)], xmm2 ; wk(1)=(42 43 52 53) movaps xmm4,xmm6 ; transpose coefficients(phase 1) unpcklps xmm6,xmm7 ; xmm6=(00 01 10 11) unpckhps xmm4,xmm7 ; xmm4=(20 21 30 31) movaps xmm2,xmm1 ; transpose coefficients(phase 1) unpcklps xmm1,xmm3 ; xmm1=(40 41 50 51) unpckhps xmm2,xmm3 ; xmm2=(60 61 70 71) movaps xmm7,xmm6 ; transpose coefficients(phase 2) unpcklps2 xmm6,xmm0 ; xmm6=(00 01 02 03)=data0 unpckhps2 xmm7,xmm0 ; xmm7=(10 11 12 13)=data1 movaps xmm3,xmm2 ; transpose coefficients(phase 2) unpcklps2 xmm2,xmm5 ; xmm2=(60 61 62 63)=data6 unpckhps2 xmm3,xmm5 ; xmm3=(70 71 72 73)=data7 movaps xmm0,xmm7 movaps xmm5,xmm6 subps xmm7,xmm2 ; xmm7=data1-data6=tmp6 subps xmm6,xmm3 ; xmm6=data0-data7=tmp7 addps xmm0,xmm2 ; xmm0=data1+data6=tmp1 addps xmm5,xmm3 ; xmm5=data0+data7=tmp0 movaps xmm2, XMMWORD [wk(0)] ; xmm2=(22 23 32 33) movaps xmm3, XMMWORD [wk(1)] ; xmm3=(42 43 52 53) movaps XMMWORD [wk(0)], xmm7 ; wk(0)=tmp6 movaps XMMWORD [wk(1)], xmm6 ; wk(1)=tmp7 movaps xmm7,xmm4 ; transpose coefficients(phase 2) unpcklps2 xmm4,xmm2 ; xmm4=(20 21 22 23)=data2 unpckhps2 xmm7,xmm2 ; xmm7=(30 31 32 33)=data3 movaps xmm6,xmm1 ; transpose coefficients(phase 2) unpcklps2 xmm1,xmm3 ; xmm1=(40 41 42 43)=data4 unpckhps2 xmm6,xmm3 ; xmm6=(50 51 52 53)=data5 movaps xmm2,xmm7 movaps xmm3,xmm4 addps xmm7,xmm1 ; xmm7=data3+data4=tmp3 addps xmm4,xmm6 ; xmm4=data2+data5=tmp2 subps xmm2,xmm1 ; xmm2=data3-data4=tmp4 subps xmm3,xmm6 ; xmm3=data2-data5=tmp5 ; -- Even part movaps xmm1,xmm5 movaps xmm6,xmm0 subps xmm5,xmm7 ; xmm5=tmp13 subps xmm0,xmm4 ; xmm0=tmp12 addps xmm1,xmm7 ; xmm1=tmp10 addps xmm6,xmm4 ; xmm6=tmp11 addps xmm0,xmm5 mulps xmm0,[GOTOFF(ebx,PD_0_707)] ; xmm0=z1 movaps xmm7,xmm1 movaps xmm4,xmm5 subps xmm1,xmm6 ; xmm1=data4 subps xmm5,xmm0 ; xmm5=data6 addps xmm7,xmm6 ; xmm7=data0 addps xmm4,xmm0 ; xmm4=data2 movaps XMMWORD [XMMBLOCK(4,0,edx,SIZEOF_FAST_FLOAT)], xmm1 movaps XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_FAST_FLOAT)], xmm5 movaps XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)], xmm7 movaps XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_FAST_FLOAT)], xmm4 ; -- Odd part movaps xmm6, XMMWORD [wk(0)] ; xmm6=tmp6 movaps xmm0, XMMWORD [wk(1)] ; xmm0=tmp7 addps xmm2,xmm3 ; xmm2=tmp10 addps xmm3,xmm6 ; xmm3=tmp11 addps xmm6,xmm0 ; xmm6=tmp12, xmm0=tmp7 mulps xmm3,[GOTOFF(ebx,PD_0_707)] ; xmm3=z3 movaps xmm1,xmm2 ; xmm1=tmp10 subps xmm2,xmm6 mulps xmm2,[GOTOFF(ebx,PD_0_382)] ; xmm2=z5 mulps xmm1,[GOTOFF(ebx,PD_0_541)] ; xmm1=MULTIPLY(tmp10,FIX_0_541196) mulps xmm6,[GOTOFF(ebx,PD_1_306)] ; xmm6=MULTIPLY(tmp12,FIX_1_306562) addps xmm1,xmm2 ; xmm1=z2 addps xmm6,xmm2 ; xmm6=z4 movaps xmm5,xmm0 subps xmm0,xmm3 ; xmm0=z13 addps xmm5,xmm3 ; xmm5=z11 movaps xmm7,xmm0 movaps xmm4,xmm5 subps xmm0,xmm1 ; xmm0=data3 subps xmm5,xmm6 ; xmm5=data7 addps xmm7,xmm1 ; xmm7=data5 addps xmm4,xmm6 ; xmm4=data1 movaps XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_FAST_FLOAT)], xmm0 movaps XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_FAST_FLOAT)], xmm5 movaps XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_FAST_FLOAT)], xmm7 movaps XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)], xmm4 add edx, byte 4*SIZEOF_FAST_FLOAT dec ecx jnz near .columnloop ; pop edi ; unused ; pop esi ; unused ; pop edx ; need not be preserved ; pop ecx ; need not be preserved poppic ebx mov esp,ebp ; esp <- aligned ebp pop esp ; esp <- original ebp pop ebp ret ; For some reason, the OS X linker does not honor the request to align the ; segment unless we do this. align 16
; A057016: Consider recurrence b(0) = (2n+1)/2, b(n) = b(n-1)*floor(b(n-1)); sequence gives first integer reached. ; Submitted by Christian Krause ; 5,105,18,550935,39,2730,68,2789204756584545,105,15939,150,943242300,203,53940,264,3714817857497700192049140000201816119835,333,137085,410,41463649689,495,291870,588,27194270698105759097850,689,550935,798,535022394030,915 mul $0,2 add $0,2 mov $1,$0 add $0,3 lpb $1 bin $0,2 dif $1,2 lpe sub $0,7 div $0,2 add $0,4
// tsthash.cpp #include "direct.h" #include "bucket.h" #include "hash.h" #include <iostream.h> main () { int result; Directory Dir (4); result = Dir . Open ("tsthash"); if (result == 0) { cout<<"Please create tsthash.dir and tsthash.bkt"<<endl; return 0; } char * keys[]={"bill", "lee", "pauline", "alan", "julie", "mike", "elizabeth", "mark", "ashley", "peter", "joan", "john", "charles", "mary", "emily"}; const int numkeys = 15; for (int i = 0; i<numkeys; i++) { cout <<keys[i]<<" "<<(void*)Hash(keys[i]) <<" "<<(void*)MakeAddress(keys[i],16)<<endl; result = Dir . Remove (keys[i]); if (result == 0) cout << "remove for "<<keys[i]<<" failed"<<endl; Dir . Print (cout); } return 1; }
; A089611: Number of primes between n^2 and (n+1/3)^2. ; Submitted by Jon Maiga ; 0,1,1,1,0,1,1,1,1,2,1,2,1,2,3,2,1,1,2,2,2,2,1,2,2,3,3,2,3,3,3,3,5,2,3,5,2,4,3,6,3,4,5,2,4,5,4,3,3,3,4,6,4,3,4,4,5,4,4,6,4,6,4,5,7,5,6,7,6,7,5,5,3,8,8,7,2,7,7,4,7,4,4,5,5,4,8,5,6,5,7,4,8,8,6,6,11,8,9,5 add $0,1 mov $3,$0 mul $3,2 mov $5,$0 pow $5,2 lpb $3 mov $2,$5 seq $2,80339 ; Characteristic function of {1} union {primes}: 1 if n is 1 or a prime, else 0. sub $3,3 add $4,$2 add $5,1 lpe mov $0,$4
VDC_0 .equ $0000 VDC_1 .equ $0001 VDC_2 .equ $0002 VDC_3 .equ $0003 VDC1 .equ 1 VDC1_0 .equ VDC_0 VDC1_1 .equ VDC_1 VDC1_2 .equ VDC_2 VDC1_3 .equ VDC_3 VDC2 .equ 2 VDC2_0 .equ $0010 VDC2_1 .equ $0011 VDC2_2 .equ $0012 VDC2_3 .equ $0013 VPC_0 .equ $0008 VPC_1 .equ $0009 VPC_2 .equ $000A VPC_3 .equ $000B VPC_4 .equ $000C VPC_5 .equ $000D VPC_6 .equ $000E VPC_7 .equ $000F VCE_0 .equ $0400 VCE_1 .equ $0401 VCE_2 .equ $0402 VCE_3 .equ $0403 VCE_4 .equ $0404 VCE_5 .equ $0405 VCE_6 .equ $0406 VCE_7 .equ $0407 INT_DIS_REG .equ $1402 IO_PAD .equ $1000 chardatBank .equ 3 muldatBank .equ 4 divdatBank .equ 20 ;////////////////////////////////// ;---------------------------- putPolyLineV1m .macro sta VDC1_2 sty VDC1_3 .endm ;---------------------------- putPolyLineV2m .macro sta VDC2_2 sty VDC2_3 .endm ;---------------------------- putPolyLineV1lm .macro putPolyLineV1m ;30 putPolyLineV1m ;29 putPolyLineV1m ;28 putPolyLineV1m ;27 putPolyLineV1m ;26 putPolyLineV1m ;25 putPolyLineV1m ;24 putPolyLineV1m ;23 putPolyLineV1m ;22 putPolyLineV1m ;21 putPolyLineV1m ;20 putPolyLineV1m ;19 putPolyLineV1m ;18 putPolyLineV1m ;17 putPolyLineV1m ;16 putPolyLineV1m ;15 putPolyLineV1m ;14 putPolyLineV1m ;13 putPolyLineV1m ;12 putPolyLineV1m ;11 putPolyLineV1m ;10 putPolyLineV1m ;9 putPolyLineV1m ;8 putPolyLineV1m ;7 putPolyLineV1m ;6 putPolyLineV1m ;5 putPolyLineV1m ;4 putPolyLineV1m ;3 putPolyLineV1m ;2 putPolyLineV1m ;1 .endm ;---------------------------- putPolyLineV2lm .macro putPolyLineV2m ;30 putPolyLineV2m ;29 putPolyLineV2m ;28 putPolyLineV2m ;27 putPolyLineV2m ;26 putPolyLineV2m ;25 putPolyLineV2m ;24 putPolyLineV2m ;23 putPolyLineV2m ;22 putPolyLineV2m ;21 putPolyLineV2m ;20 putPolyLineV2m ;19 putPolyLineV2m ;18 putPolyLineV2m ;17 putPolyLineV2m ;16 putPolyLineV2m ;15 putPolyLineV2m ;14 putPolyLineV2m ;13 putPolyLineV2m ;12 putPolyLineV2m ;11 putPolyLineV2m ;10 putPolyLineV2m ;9 putPolyLineV2m ;8 putPolyLineV2m ;7 putPolyLineV2m ;6 putPolyLineV2m ;5 putPolyLineV2m ;4 putPolyLineV2m ;3 putPolyLineV2m ;2 putPolyLineV2m ;1 .endm ;---------------------------- setEdgeBufferm .macro ;set edge buffer lda edgeCount,x beq .jpCount1_\@ ;count 1 bpl .jpCount2_\@ ;count 2 ;count 0 .jpCount0_\@: tya sta edgeLeft,x inc edgeCount,x bra .jp2_\@ ;count 1 .jpCount1_\@: tya cmp edgeLeft,x bcs .jp4_\@ ;a >= edgeLeft,x lda edgeLeft,x sta edgeRight,x tya sta edgeLeft,x inc edgeCount,x bra .jp2_\@ .jp4_\@: sta edgeRight,x inc edgeCount,x bra .jp2_\@ ;count 2 .jpCount2_\@: tya cmp edgeLeft,x bcs .jp3_\@ ;a >= edgeLeft,x sta edgeLeft,x bra .jp2_\@ .jp3_\@: cmp edgeRight,x bcc .jp2_\@ ;a < edgeRight,x sta edgeRight,x .jp2_\@: .endm ;---------------------------- jcc .macro bcs .jp\@ jmp \1 .jp\@ .endm ;---------------------------- jcs .macro bcc .jp\@ jmp \1 .jp\@ .endm ;---------------------------- jeq .macro bne .jp\@ jmp \1 .jp\@ .endm ;---------------------------- jne .macro beq .jp\@ jmp \1 .jp\@ .endm ;---------------------------- jpl .macro bmi .jp\@ jmp \1 .jp\@ .endm ;---------------------------- jmi .macro bpl .jp\@ jmp \1 .jp\@ .endm ;---------------------------- add .macro ;\1 = \2 + \3 ;\1 = \1 + \2 .if (\# = 1) clc adc \1 .else .if (\# = 3) clc lda \2 adc \3 sta \1 .else clc lda \1 adc \2 sta \1 .endif .endif .endm ;---------------------------- sub .macro ;\1 = \2 - \3 ;\1 = \1 - \2 .if (\# = 1) sec sbc \1 .else .if (\# = 3) sec lda \2 sbc \3 sta \1 .else sec lda \1 sbc \2 sta \1 .endif .endif .endm ;---------------------------- addw .macro ;\1 = \2 + \3 ;\1 = \1 + \2 .if (\# = 3) .if (\?3 = 2);Immediate clc lda \2 adc #LOW(\3) sta \1 lda \2+1 adc #HIGH(\3) sta \1+1 .else clc lda \2 adc \3 sta \1 lda \2+1 adc \3+1 sta \1+1 .endif .else .if (\?2 = 2);Immediate clc lda \1 adc #LOW(\2) sta \1 lda \1+1 adc #HIGH(\2) sta \1+1 .else clc lda \1 adc \2 sta \1 lda \1+1 adc \2+1 sta \1+1 .endif .endif .endm ;---------------------------- addwb .macro ;\1(word) = \1(word) + \2(byte) clc lda \1 adc \2 sta \1 bcc .jp0\@ inc \1+1 .jp0\@ .endm ;---------------------------- subw .macro ;\1 = \2 - \3 ;\1 = \1 - \2 .if (\# = 3) .if (\?3 = 2);Immediate sec lda \2 sbc #LOW(\3) sta \1 lda \2+1 sbc #HIGH(\3) sta \1+1 .else .if (\?2 = 2);Immediate sec lda #LOW(\2) sbc \3 sta \1 lda #HIGH(\2) sbc \3+1 sta \1+1 .else sec lda \2 sbc \3 sta \1 lda \2+1 sbc \3+1 sta \1+1 .endif .endif .else .if (\?2 = 2);Immediate sec lda \1 sbc #LOW(\2) sta \1 lda \1+1 sbc #HIGH(\2) sta \1+1 .else sec lda \1 sbc \2 sta \1 lda \1+1 sbc \2+1 sta \1+1 .endif .endif .endm ;---------------------------- addq .macro ;\1 = \2 + \3 ;\1 = \1 + \2 .if (\# = 3) clc lda \2 adc \3 sta \1 lda \2+1 adc \3+1 sta \1+1 lda \2+2 adc \3+2 sta \1+2 lda \2+3 adc \3+3 sta \1+3 .else clc lda \1 adc \2 sta \1 lda \1+1 adc \2+1 sta \1+1 lda \1+2 adc \2+2 sta \1+2 lda \1+3 adc \2+3 sta \1+3 .endif .endm ;---------------------------- subq .macro ;\1 = \2 - \3 ;\1 = \1 - \2 .if (\# = 3) sec lda \2 sbc \3 sta \1 lda \2+1 sbc \3+1 sta \1+1 lda \2+2 sbc \3+2 sta \1+2 lda \2+3 sbc \3+3 sta \1+3 .else sec lda \1 sbc \2 sta \1 lda \1+1 sbc \2+1 sta \1+1 lda \1+2 sbc \2+2 sta \1+2 lda \1+3 sbc \2+3 sta \1+3 .endif .endm ;---------------------------- andm .macro ;\1 = \1 AND \2 lda \1 and \2 sta \1 .endm ;---------------------------- andmw .macro ;\1 = \1 AND \2 .if (\?2 = 2);Immediate lda \1 and #LOW(\2) sta \1 lda \1+1 and #HIGH(\2) sta \1+1 .else lda \1 and \2 sta \1 lda \1+1 and \2+1 sta \1+1 .endif .endm ;---------------------------- oram .macro ;\1 = \1 OR \2 lda \1 ora \2 sta \1 .endm ;---------------------------- oramw .macro ;\1 = \1 OR \2 .if (\?2 = 2);Immediate lda \1 ora #LOW(\2) sta \1 lda \1+1 ora #HIGH(\2) sta \1+1 .else lda \1 ora \2 sta \1 lda \1+1 ora \2+1 sta \1+1 .endif .endm ;---------------------------- eorm .macro ;\1 = \1 XOR \2 lda \1 eor \2 sta \1 .endm ;---------------------------- eormw .macro ;\1 = \1 XOR \2 .if (\?2 = 2);Immediate lda \1 eor #LOW(\2) sta \1 lda \1+1 eor #HIGH(\2) sta \1+1 .else lda \1 eor \2 sta \1 lda \1+1 eor \2+1 sta \1+1 .endif .endm ;---------------------------- mov .macro ;\1 = \2 lda \2 sta \1 .endm ;---------------------------- movw .macro ;\1 = \2 .if (\?2 = 2);Immediate lda #LOW(\2) sta \1 lda #HIGH(\2) sta \1+1 .else lda \2 sta \1 lda \2+1 sta \1+1 .endif .endm ;---------------------------- movq .macro ;\1 = \2 ;\1 = \2:\3 .if (\?2 = 2);Immediate lda #LOW(\3) sta \1 lda #HIGH(\3) sta \1+1 lda #LOW(\2) sta \1+2 lda #HIGH(\2) sta \1+3 .else lda \2 sta \1 lda \2+1 sta \1+1 lda \2+2 sta \1+2 lda \2+3 sta \1+3 .endif .endm ;---------------------------- stzw .macro ;\1 = 0 stz \1 stz \1+1 .endm ;---------------------------- stzq .macro ;\1 = 0 stz \1 stz \1+1 stz \1+2 stz \1+3 .endm ;---------------------------- cmpw .macro ;\1 - \2 .if (\?2 = 2);Immediate sec lda \1 sbc #LOW(\2) lda \1+1 sbc #HIGH(\2) .else sec lda \1 sbc \2 lda \1+1 sbc \2+1 .endif .endm ;---------------------------- cmpzw .macro ;\1 - \2 phx tsx pha .if (\?2 = 2);Immediate sec lda \1 sbc #LOW(\2) sta $2100, x lda \1+1 sbc #HIGH(\2) .else sec lda \1 sbc \2 sta $2100, x lda \1+1 sbc \2+1 .endif php ora $2100, x bne .jp0\@ pla ora #$02 bra .jp1\@ .jp0\@ pla and #$FD .jp1\@ txs plx pha plp .endm ;---------------------------- cmpq .macro ;\1 - \2 ;\1 - \2:\3 .if (\?2 = 2);Immediate sec lda \1 sbc #LOW(\3) lda \1+1 sbc #HIGH(\3) lda \1+2 sbc #LOW(\2) lda \1+3 sbc #HIGH(\2) .else sec lda \1 sbc \2 lda \1+1 sbc \2+1 lda \1+2 sbc \2+2 lda \1+3 sbc \2+3 .endif .endm ;---------------------------- cmpzq .macro ;\1 - \2 ;\1 - \2:\3 phx tsx pha .if (\?2 = 2);Immediate sec lda \1 sbc #LOW(\3) sta $2100, x lda \1+1 sbc #HIGH(\3) ora $2100, x sta $2100, x lda \1+2 sbc #LOW(\2) ora $2100, x sta $2100, x lda \1+3 sbc #HIGH(\2) .else sec lda \1 sbc \2 sta $2100, x lda \1+1 sbc \2+1 ora $2100, x sta $2100, x lda \1+2 sbc \2+2 ora $2100, x sta $2100, x lda \1+3 sbc \2+3 .endif php ora $2100, x bne .jp0\@ pla ora #$02 bra .jp1\@ .jp0\@ pla and #$FD .jp1\@ txs plx pha plp .endm ;////////////////////////////////// .zp ;********************************** .org $2000 ;--------------------- mul16a div16a .ds 2 mul16b div16b .ds 2 mul16c div16c .ds 2 mul16d div16d .ds 2 div16ans .ds 2 div16work .ds 2 muladdr .ds 2 sqrt64a .ds 8 sqrt64ans sqrt64b .ds 8 mulbank .ds 1 ;--------------------- ;LDRU RSBA padlast .ds 1 padnow .ds 1 padstate .ds 1 ;--------------------- puthexaddr .ds 2 puthexdata .ds 1 ;--------------------- udiv32_2Work .ds 2 ;--------------------- vsyncFlag .ds 1 vdp1Status .ds 1 vdp2Status .ds 1 selectVdc .ds 1 ;--------------------- vertexCount .ds 1 vertexCountWork .ds 1 vertex0Addr .ds 2 vertex1Addr .ds 2 vertexWork .ds 4 ;--------------------- clip2D0Count .ds 1 clip2D1Count .ds 1 clip2DFlag .ds 1 clip2D0LastIndex .ds 1 ;--------------------- edgeX0 .ds 1 edgeY0 .ds 1 edgeX1 .ds 1 edgeY1 .ds 1 edgeSlopeX .ds 1 edgeSlopeY .ds 1 edgeSigneX .ds 1 ;--------------------- minEdgeY .ds 1 ;--------------------- polyLineX0 .ds 1 polyLineX1 .ds 1 polyLineY .ds 1 polyLineLeftAddr .ds 2 polyLineRightAddr .ds 2 polyLineLeftData .ds 1 polyLineLeftMask .ds 1 polyLineRightData .ds 1 polyLineRightMask .ds 1 polyLineDataLow .ds 1 polyLineDataHigh .ds 1 polyLineColorNo .ds 1 polyLineColorDataWork .ds 1 polyLineColorDataWork0 .ds 1 polyLineColorDataWork1 .ds 1 polyLineColorDataWork2 .ds 1 polyLineColorDataWork3 .ds 1 polyLineYAddr .ds 2 polyLineCount .ds 1 ;--------------------- polyBufferAddr .ds 2 polyBufferZ0Work0 .ds 2 polyBufferZ0Work1 .ds 2 polyBufferNow .ds 2 polyBufferNext .ds 2 frontClipFlag .ds 1 frontClipCount .ds 1 frontClipData0 .ds 1 frontClipData1 .ds 1 frontClipDataWork .ds 1 clipFrontX .ds 2 clipFrontY .ds 2 polyBufferAddrWork0 .ds 1 polyBufferAddrWork1 .ds 1 polyBufferAddrWork2 .ds 1 ;--------------------- modelAddr .ds 2 modelAddrWork .ds 2 modelPolygonCount .ds 1 setModelCount .ds 1 setModelCountWork .ds 1 setModelFrontColor .ds 1 setModelBackColor .ds 1 setModelColorY .ds 1 setModelAttr .ds 1 model2DClipIndexWork .ds 1 ;--------------------- setBatWork .ds 2 ;--------------------- centerX .ds 2 centerY .ds 2 ;--------------------- translationX .ds 2 translationY .ds 2 translationZ .ds 2 ;--------------------- rotationX .ds 1 rotationY .ds 1 rotationZ .ds 1 rotationSelect .ds 1 vertexRotationSin .ds 2 vertexRotationCos .ds 2 ;--------------------- eyeTranslationX .ds 2 eyeTranslationY .ds 2 eyeTranslationZ .ds 2 eyeRotationX .ds 1 eyeRotationY .ds 1 eyeRotationZ .ds 1 eyeRotationSelect .ds 1 .bss ;********************************** .org $2100 ;********************************** .org $2200 ;--------------------- frameCount .ds 1 drawCount .ds 1 drawCountWork .ds 1 ;--------------------- shipX .ds 2 shipY .ds 2 shipZ .ds 2 shipRX .ds 1 shipRY .ds 1 shipRZ .ds 1 ;--------------------- ringX .ds 2 ringY .ds 2 ringZ .ds 2 ringRX .ds 1 ringRY .ds 1 ringRZ .ds 1 ;--------------------- building1X .ds 2 building1Y .ds 2 building1Z .ds 2 building1RX .ds 1 building1RY .ds 1 building1RZ .ds 1 ;--------------------- building2X .ds 2 building2Y .ds 2 building2Z .ds 2 building2RX .ds 1 building2RY .ds 1 building2RZ .ds 1 ;--------------------- matrix0 .ds 2*3*3 matrix1 .ds 2*3*3 matrix2 .ds 2*3*3 ;--------------------- eyeMatrix .ds 2*3*3 ;--------------------- transform2DWork0 .ds 256 transform2DWork1 .ds 256 ;--------------------- clip2D0 .ds (8+1)*4 clip2D1 .ds (8+1)*4 ;--------------------- edgeLeft .ds 192 edgeRight .ds 192 edgeCount .ds 192 .ds 1 ;--------------------- polyBufferStart .ds 6 polyBufferEnd .ds 6 polyBuffer .ds 2048 ;NEXT ADDR 2Byte ;SAMPLE Z 2Byte ;COLOR 1Byte ;COUNT 1Byte $00 DATA END ;X0 Y0 2Byte ;X1 Y1 2Byte ;X2 Y2 2Byte ;X3 Y3 2Byte ;X4 Y4 2Byte ;X5 Y5 2Byte ;X6 Y6 2Byte ;X7 Y7 2Byte ;X8 Y8 2Byte ;////////////////////////////////// .code .bank 0 ;********************************** .org $E000 main: ;initialize VDC jsr initializeVdc ;initialize pad jsr initializepad ;set poly proc bank lda #$01 tam #$05 lda #$02 tam #$06 jsr setBAT ;initialize datas lda #128 sta <centerX lda #96 sta <centerY ;-------- stz shipRX stz shipRY stz shipRZ lda #0 sta shipX lda #0 sta shipX+1 lda #0 sta shipY lda #0 sta shipY+1 lda #$C0 sta shipZ lda #$00 sta shipZ+1 ;-------- lda #0 sta ringX lda #0 sta ringX+1 lda #0 sta ringY lda #0 sta ringY+1 lda #$00 sta ringZ lda #$08 sta ringZ+1 lda #0 sta ringRX lda #0 sta ringRY lda #0 sta ringRZ ;-------- lda #$80 sta building1X lda #$00 sta building1X+1 lda #$80 sta building1Y lda #$00 sta building1Y+1 lda #$00 sta building1Z lda #$04 sta building1Z+1 lda #0 sta building1RX lda #0 sta building1RY lda #0 sta building1RZ ;-------- lda #$00 sta building2X lda #$FF sta building2X+1 lda #$80 sta building2Y lda #$00 sta building2Y+1 lda #$00 sta building2Z lda #$06 sta building2Z+1 lda #0 sta building2RX lda #0 sta building2RY lda #0 sta building2RZ ;-------- lda #60 sta frameCount stz drawCount stz drawCountWork ;VDC1 ;bg sp vsync ;+32 mov VDC1_0, #$05 movw VDC1_2, #$08C8 ;VDC2 ;bg sp ;+32 mov VDC2_0, #$05 movw VDC2_2, #$0800 mov <selectVdc, #VDC2 rmb7 <vsyncFlag ;vsync interrupt start cli ;main loop .mainLoop: ;wait vsync bbs7 <vsyncFlag, .mainLoop eorm <selectVdc, #$03 ;check pad ;pad up bbr4 <padnow, .checkPadDown sec lda shipY sbc #$04 sta shipY lda shipY+1 sbc #$00 sta shipY+1 .checkPadDown: ;pad down bbr6 <padnow, .checkPadLeft clc lda shipY adc #$04 sta shipY lda shipY+1 adc #$00 sta shipY+1 .checkPadLeft: ;pad left bbr7 <padnow, .checkPadRight sec lda shipX sbc #$04 sta shipX lda shipX+1 sbc #$00 sta shipX+1 .checkPadRight: ;pad right bbr5 <padnow, .checkPadEnd clc lda shipX adc #$04 sta shipX lda shipX+1 adc #$00 sta shipX+1 .checkPadEnd: ;set datas lda shipX sta <eyeTranslationX lda shipX+1 sta <eyeTranslationX+1 lda <eyeTranslationX+1 asl a ror <eyeTranslationX+1 ror <eyeTranslationX sec lda <eyeTranslationX sbc #$C1 lda <eyeTranslationX+1 sbc #$FF bpl .eyeJump0 ; >= -63 clc lda shipX adc #$3F sta <eyeTranslationX lda shipX+1 adc #$00 sta <eyeTranslationX+1 .eyeJump0: sec lda <eyeTranslationX sbc #$40 lda <eyeTranslationX+1 sbc #$00 bmi .eyeJump1 ; < 64 sec lda shipX sbc #$3F sta <eyeTranslationX lda shipX+1 sbc #$00 sta <eyeTranslationX+1 .eyeJump1: lda shipY sta <eyeTranslationY lda shipY+1 sta <eyeTranslationY+1 lda <eyeTranslationY+1 asl a ror <eyeTranslationY+1 ror <eyeTranslationY sec lda <eyeTranslationY sbc #$C1 lda <eyeTranslationY+1 sbc #$FF bpl .eyeJump2 ; >= -63 clc lda shipY adc #$3F sta <eyeTranslationY lda shipY+1 adc #$00 sta <eyeTranslationY+1 .eyeJump2: sec lda <eyeTranslationY sbc #$40 lda <eyeTranslationY+1 sbc #$00 bmi .eyeJump3 ; < 64 sec lda shipY sbc #$3F sta <eyeTranslationY lda shipY+1 sbc #$00 sta <eyeTranslationY+1 .eyeJump3: lda #0 sta <eyeRotationX lda #0 sta <eyeRotationY lda #0 sta <eyeRotationZ lda #$12 sta <eyeRotationSelect ;initialize buffer jsr initializePolyBuffer ;set ship model lda shipX sta <translationX lda shipX+1 sta <translationX+1 lda shipY sta <translationY lda shipY+1 sta <translationY+1 lda shipZ sta <translationZ lda shipZ+1 sta <translationZ+1 lda shipRX sta <rotationX lda shipRY sta <rotationY lda shipRZ sta <rotationZ lda #$12 sta <rotationSelect lda #LOW(modelData0) sta <modelAddr lda #HIGH(modelData0) sta <modelAddr+1 jsr setModel2 ;set ring model lda ringX sta <translationX lda ringX+1 sta <translationX+1 lda ringY sta <translationY lda ringY+1 sta <translationY+1 lda ringZ sta <translationZ lda ringZ+1 sta <translationZ+1 lda ringRX sta <rotationX lda ringRY sta <rotationY lda ringRZ sta <rotationZ lda #$12 sta <rotationSelect lda #LOW(modelData1) sta <modelAddr lda #HIGH(modelData1) sta <modelAddr+1 jsr setModel2 sec lda ringZ sbc #$10 sta ringZ lda ringZ+1 sbc #$00 sta ringZ+1 bpl .ringJump lda #$00 sta ringZ lda #$08 sta ringZ+1 .ringJump: inc ringRZ inc ringRZ ;set building1 model lda building1X sta <translationX lda building1X+1 sta <translationX+1 lda building1Y sta <translationY lda building1Y+1 sta <translationY+1 lda building1Z sta <translationZ lda building1Z+1 sta <translationZ+1 lda building1RX sta <rotationX lda building1RY sta <rotationY lda building1RZ sta <rotationZ lda #$12 sta <rotationSelect lda #LOW(modelData2) sta <modelAddr lda #HIGH(modelData2) sta <modelAddr+1 jsr setModel2 sec lda building1Z sbc #$10 sta building1Z lda building1Z+1 sbc #$00 sta building1Z+1 bpl .building1Jump lda #$00 sta building1Z lda #$08 sta building1Z+1 .building1Jump: ;set building2 model lda building2X sta <translationX lda building2X+1 sta <translationX+1 lda building2Y sta <translationY lda building2Y+1 sta <translationY+1 lda building2Z sta <translationZ lda building2Z+1 sta <translationZ+1 lda building2RX sta <rotationX lda building2RY sta <rotationY lda building2RZ sta <rotationZ lda #$12 sta <rotationSelect lda #LOW(modelData2) sta <modelAddr lda #HIGH(modelData2) sta <modelAddr+1 jsr setModel2 sec lda building2Z sbc #$10 sta building2Z lda building2Z+1 sbc #$00 sta building2Z+1 bpl .building2Jump lda #$00 sta building2Z lda #$08 sta building2Z+1 .building2Jump: ;put polygon jsr putPolyBuffer inc drawCountWork ldx #0 ldy #24 lda drawCount sei jsr puthex2 cli ;set vsync flag smb7 <vsyncFlag ;jump mainloop jmp .mainLoop ;---------------------------- initializeVdc: ; ;reset wait cly .resetWaitloop0: clx .resetWaitloop1: dex bne .resetWaitloop1 dey bne .resetWaitloop0 ;set vdc vdcdataloop: lda vdcdata, y cmp #$FF beq vdcdataend sta VDC1_0 sta VDC2_0 iny lda vdcdata, y sta VDC1_2 sta VDC2_2 iny lda vdcdata, y sta VDC1_3 sta VDC2_3 iny bra vdcdataloop vdcdataend: ;disable interrupts TIQD IRQ2D lda #$05 sta $1402 ;262Line VCE Clock 5MHz lda #$04 sta $0400 stz $0401 ;set palette stz $0402 stz $0403 tia palettedata, $0404, $20*32 ;CHAR set to vram lda #chardatBank tam #$06 ;vram address $1000 mov VDC1_0, #$00 movw VDC1_2, #$1000 mov VDC1_0, #$02 tia $C000, VDC1_2, $2000 mov VDC2_0, #$00 movw VDC2_2, #$1000 mov VDC2_0, #$02 tia $C000, VDC2_2, $2000 ;clear BAT st0 #$00 st1 #$00 st2 #$00 st0 #$02 ldy #32 .clearbatloop0: ldx #32 .clearbatloop1: st1 #$20 st2 #$01 dex bne .clearbatloop1 dey bne .clearbatloop0 ;clear zeropage stz $2000 tii $2000, $2001, $00FF ;screen on ;bg sp vsync ;+1 st0 #$05 st1 #$C8 st2 #$00 rts ;---------------------------- puthex2: ; pha phx phy sta <puthexdata stz <puthexaddr sty <puthexaddr+1 lsr <puthexaddr+1 ror <puthexaddr lsr <puthexaddr+1 ror <puthexaddr lsr <puthexaddr+1 ror <puthexaddr txa ora <puthexaddr sta <puthexaddr lda <puthexdata lsr a lsr a lsr a lsr a jsr numtochar tax lda <puthexdata and #$0F jsr numtochar tay lda <selectVdc cmp #VDC2 beq .vdc_2 mov VDC1_0, #$00 movw VDC1_2, <puthexaddr mov VDC1_0, #$02 stx VDC1_2 mov VDC1_3, #$01 addw <puthexaddr, #1 mov VDC1_0, #$00 movw VDC1_2, <puthexaddr mov VDC1_0, #$02 sty VDC1_2 mov VDC1_3, #$01 bra .puthexEnd .vdc_2: mov VDC2_0, #$00 movw VDC2_2, <puthexaddr mov VDC2_0, #$02 stx VDC2_2 mov VDC2_3, #$01 addw <puthexaddr, #1 mov VDC2_0, #$00 movw VDC2_2, <puthexaddr mov VDC2_0, #$02 sty VDC2_2 mov VDC2_3, #$01 .puthexEnd: ply plx pla rts ;---------------------------- sdiv32: ;div16d:div16c / div16a = div16a div16b ;push x phx ;d sign lda <div16d+1 pha ;d eor a sign eor <div16a+1 pha ;d sign bbr7 <div16d+1, .sdiv16jp00 ;d neg sec lda <mul16c eor #$FF adc #0 sta <mul16c lda <mul16c+1 eor #$FF adc #0 sta <mul16c+1 lda <mul16d eor #$FF adc #0 sta <mul16d lda <mul16d+1 eor #$FF adc #0 sta <mul16d+1 .sdiv16jp00: ;a sign bbr7 <div16a+1, .sdiv16jp01 ;a neg sec lda <mul16a eor #$FF adc #0 sta <mul16a lda <mul16a+1 eor #$FF adc #0 sta <mul16a+1 .sdiv16jp01: jsr udiv32 ;anser sign pla bpl .sdiv16jp02 ;anser neg sec lda <mul16a eor #$FF adc #0 sta <mul16a lda <mul16a+1 eor #$FF adc #0 sta <mul16a+1 .sdiv16jp02: ;remainder sign pla bpl .sdiv16jp03 ;remainder neg sec lda <mul16b eor #$FF adc #0 sta <mul16b lda <mul16b+1 eor #$FF adc #0 sta <mul16b+1 .sdiv16jp03: ;pull x plx rts ;---------------------------- udiv32: ;div16a div16b = div16d:div16c / div16a ;push x phx ;dec div16a lda <div16a bne .jp00 dec <div16a+1 .jp00: dec <div16a ldx #$10 asl <div16c rol <div16c+1 .jpPl00: ;div16d rol <div16d rol <div16d+1 lda <div16d sbc <div16a sta <div16d lda <div16d+1 sbc <div16a+1 sta <div16d+1 bcc .jpMi01 .jpPl01: rol <div16c rol <div16c+1 dex bne .jpPl00 lda <div16c sta <div16a lda <div16c+1 sta <div16a+1 lda <div16d sta <div16b lda <div16d+1 sta <div16b+1 ;pull x plx rts .jpMi00: ;div16d rol <div16d rol <div16d+1 lda <div16d adc <div16a sta <div16d lda <div16d+1 adc <div16a+1 sta <div16d+1 bcs .jpPl01 .jpMi01: rol <div16c rol <div16c+1 dex bne .jpMi00 sec lda <div16d adc <div16a sta <div16b lda <div16d+1 adc <div16a+1 sta <div16b+1 lda <div16c sta <div16a lda <div16c+1 sta <div16a+1 ;pull x plx rts ;---------------------------- smul16: ;mul16d:mul16c = mul16a * mul16b ;push x phx ;a eor b sign lda <mul16a+1 eor <mul16b+1 pha ;a sign bbr7 <mul16a+1, .smul16jp00 ;a neg sec lda <mul16a eor #$FF adc #0 sta <mul16a lda <mul16a+1 eor #$FF adc #0 sta <mul16a+1 .smul16jp00: ;b sign bbr7 <mul16b+1, .smul16jp01 ;b neg sec lda <mul16b eor #$FF adc #0 sta <mul16b lda <mul16b+1 eor #$FF adc #0 sta <mul16b+1 .smul16jp01: jsr umul16 ;anser sign pla bpl .smul16jp02 ;anser neg sec lda <mul16c eor #$FF adc #0 sta <mul16c lda <mul16c+1 eor #$FF adc #0 sta <mul16c+1 lda <mul16d eor #$FF adc #0 sta <mul16d lda <mul16d+1 eor #$FF adc #0 sta <mul16d+1 .smul16jp02: ;pull x plx rts ;---------------------------- umul16: ;mul16d:mul16c = mul16a * mul16b ;push x y phx phy ldx <mul16b lda mulbankdata, x pha tam #$02 lda muladdrdata, x stz <muladdr sta <muladdr+1 ldy <mul16a lda [muladdr], y sta <mul16c ldy <mul16a+1 lda [muladdr], y sta <mul16c+1 pla clc adc #8 tam #$02 clc ldy <mul16a lda [muladdr], y adc <mul16c+1 sta <mul16c+1 ldy <mul16a+1 lda [muladdr], y adc #0 sta <mul16d ldx <mul16b+1 lda mulbankdata, x pha tam #$02 lda muladdrdata, x stz <muladdr sta <muladdr+1 clc ldy <mul16a lda [muladdr], y adc <mul16c+1 sta <mul16c+1 ldy <mul16a+1 lda [muladdr], y adc <mul16d sta <mul16d cla adc #0 sta <mul16d+1 pla clc adc #8 tam #$02 clc ldy <mul16a lda [muladdr], y adc <mul16d sta <mul16d ldy <mul16a+1 lda [muladdr], y adc <mul16d+1 sta <mul16d+1 ;pull y x ply plx rts ;---------------------------- initializepad: ; stz <padlast stz <padnow stz <padstate rts ;---------------------------- getpaddata: ; lda <padnow sta <padlast lda #$01 sta IO_PAD lda #$03 sta IO_PAD lda #$01 sta IO_PAD lda IO_PAD asl a asl a asl a asl a sta <padnow lda #$00 sta IO_PAD lda IO_PAD and #$0F ora <padnow eor #$FF sta <padnow lda <padlast eor #$FF and <padnow sta <padstate ;get pad data end rts ;---------------------------- numtochar: ;in A Register $0 to $F ;out A Register '0'-'9'($30-$39) 'A'-'Z'($41-$5A) cmp #10 bcs .numtochar000 ora #$30 rts .numtochar000: adc #$41-10-1 rts ;---------------------------- puthex: ; pha phx phy sta <puthexdata stz <puthexaddr sty <puthexaddr+1 lsr <puthexaddr+1 ror <puthexaddr lsr <puthexaddr+1 ror <puthexaddr lsr <puthexaddr+1 ror <puthexaddr txa ora <puthexaddr sta <puthexaddr lda <puthexdata lsr a lsr a lsr a lsr a jsr numtochar tax lda <puthexdata and #$0F jsr numtochar stz VDC_0 ldy <puthexaddr sty VDC_2 ldy <puthexaddr+1 sty VDC_3 ldy #$02 sty VDC_0 stx VDC_2 ldy #$01 sty VDC_3 sta VDC_2 sty VDC_3 ply plx pla rts ;---------------------------- _irq1: ;IRQ1 interrupt process ;ACK interrupt pha phx phy lda VDC1_0 sta <vdp1Status lda VDC2_0 sta <vdp2Status bbs7 <vsyncFlag, .vsyncProc jmp .vsyncProcEnd .vsyncProc: lda <selectVdc cmp #VDC2 beq .vdc2Jp ;+32 bg sp vsync mov VDC1_0, #$05 movw VDC1_2, #$08C8 ;+32 mov VDC2_0, #$05 movw VDC2_2, #$0800 ;VRAM Clear clx cly .vramClearLoop2: mov VDC2_0, #$00 ;set VRAM addr sty VDC2_2 movw VDC2_3, #$40 iny mov VDC2_0, #$02 ;VRAM clear lda vramClearData, x sta VDC2_2 inx lda vramClearData, x sta VDC2_3 inx cpx #$20 bne .vramClearLoop2 mov VDC2_0, #$10 ;set DMA src movw VDC2_2, #$4000 mov VDC2_0, #$11 ;set DMA dist movw VDC2_2, #$4010 mov VDC2_0, #$12 ;set DMA count movw VDC2_2, #$4000-$10 bra .vdcEnd .vdc2Jp: ;+32 vsync mov VDC1_0, #$05 movw VDC1_2, #$0808 ;bg sp ;+32 bg sp mov VDC2_0, #$05 movw VDC2_2, #$08C0 ;VRAM Clear clx cly .vramClearLoop1: mov VDC1_0, #$00 ;set VRAM addr sty VDC1_2 movw VDC1_3, #$40 iny mov VDC1_0, #$02 ;VRAM clear lda vramClearData, x sta VDC1_2 inx lda vramClearData, x sta VDC1_3 inx cpx #$20 bne .vramClearLoop1 mov VDC1_0, #$10 ;set DMA src movw VDC1_2, #$4000 mov VDC1_0, #$11 ;set DMA dist movw VDC1_2, #$4010 mov VDC1_0, #$12 ;set DMA count movw VDC1_2, #$4000-$10 .vdcEnd: rmb7 <vsyncFlag .vsyncProcEnd: jsr getpaddata dec frameCount bne .irqEnd lda #60 sta frameCount lda drawCountWork sta drawCount stz drawCountWork .irqEnd: ply plx pla rti ;---------------------------- _reset: ;reset process ;disable interrupts sei ;select the 7.16 MHz clock csh ;clear the decimal flag cld ;initialize the stack pointer ldx #$FF txs ;I/O page0 lda #$FF tam #$00 ;RAM page1 lda #$F8 tam #$01 ;jump main jmp main ;---------------------------- _irq2: _timer: _nmi: ;IRQ2 TIMER NMI interrupt process rti ;---------------------------- vramClearData .db $00, $FF, $00, $FF, $00, $FF, $00, $FF, $00, $FF, $00, $FF, $00, $FF, $00, $FF,\ $FF, $00, $FF, $00, $FF, $00, $FF, $00, $FF, $00, $FF, $00, $FF, $00, $FF, $00 ;---------------------------- ;Star Fox Arwing modelData0 .dw modelData0Polygon .db 18 ;polygon count .dw modelData0Vertex .db 16 ;vertex count modelData0Polygon ; front color * 8 + vertex count(3 or 4), back color * 8 + back draw flag($01 = not draw : front side = clockwise) .db $19*8+3, $00*8+$01, 0*6, 2*6, 1*6, 0*0;0 Front Bottom .db $1C*8+3, $00*8+$01, 0*6, 1*6, 3*6, 0*0;1 Front Right .db $1E*8+3, $00*8+$01, 0*6, 3*6, 2*6, 0*0;2 Front Left .db $1A*8+3, $00*8+$01, 3*6, 1*6, 4*6, 0*0;3 Middle Outer Right .db $1C*8+3, $00*8+$01, 3*6, 4*6, 2*6, 0*0;4 Middle Outer Left .db $09*8+3, $00*8+$01, 5*6, 1*6, 2*6, 0*0;5 Middle Inner .db $1A*8+3, $00*8+$01, 1*6, 5*6, 4*6, 0*0;6 Middle Inner Right .db $1A*8+3, $00*8+$01, 4*6, 5*6, 2*6, 0*0;7 Middle Inner Left .db $09*8+3, $00*8+$01, 7*6, 6*6, 1*6, 0*0;8 Right Wing Front .db $1B*8+3, $00*8+$01, 6*6, 7*6, 8*6, 0*0;9 Right Wing Right .db $1D*8+3, $00*8+$01, 1*6, 8*6, 7*6, 0*0;10 Right Wing Left .db $1C*8+3, $00*8+$01, 1*6, 6*6, 8*6, 0*0;11 Right Wing Top .db $09*8+3, $00*8+$01, 2*6, 9*6,10*6, 0*0;12 Left Wing Front .db $1B*8+3, $00*8+$01, 2*6,10*6,11*6, 0*0;13 Left Wing Right .db $1D*8+3, $00*8+$01, 9*6,11*6,10*6, 0*0;14 Left Wing Left .db $1C*8+3, $00*8+$01, 9*6, 2*6,11*6, 0*0;15 Left Wing Top .db $04*8+3, $0C*8+$00, 1*6,13*6,12*6, 0*0;16 Right Wing .db $04*8+3, $0C*8+$00, 2*6,14*6,15*6, 0*0;17 Left Wing modelData0Vertex .dw 0, 10, 100;0 Front .dw 20, 10, 0;1 Front Bottom Right .dw -20, 10, 0;2 Front Bottom Left .dw 0, -10, 0;3 Front Middle Top .dw 0, 0, -20;4 Front Middle Back .dw 0, 0, 0;5 Front Middle Inner .dw 40, 10, 0;6 Right Wing Right .dw 30, 20, 0;7 Right Wing Bottom .dw 70, 30, -50;8 Right Wing Back .dw -40, 10, 0;9 Left Wing Left .dw -30, 20, 0;10 Left Wing Bottom .dw -70, 30, -50;11 Left Wing Back .dw 30, 20, 30;12 Right Wing Front .dw 40, -40, -30;13 Right Wing Top .dw -30, 20, 30;14 Left Wing Front .dw -40, -40, -30;15 Left Wing Top ;---------------------------- ;Ring modelData1 .dw modelData1Polygon .db 16 ;polygon count .dw modelData1Vertex .db 24 ;vertex count modelData1Polygon .db $1A*8+4, $00*8+$01, 0*6, 3*6, 4*6, 1*6; 0 .db $19*8+4, $00*8+$01, 1*6, 4*6, 5*6, 2*6; 1 .db $1B*8+4, $00*8+$01, 3*6, 6*6, 7*6, 4*6; 2 .db $1A*8+4, $00*8+$01, 4*6, 7*6, 8*6, 5*6; 3 .db $1C*8+4, $00*8+$01, 6*6, 9*6,10*6, 7*6; 4 .db $1B*8+4, $00*8+$01, 7*6,10*6,11*6, 8*6; 5 .db $1E*8+4, $00*8+$01, 9*6,12*6,13*6,10*6; 6 .db $1D*8+4, $00*8+$01,10*6,13*6,14*6,11*6; 7 .db $1E*8+4, $00*8+$01,12*6,15*6,16*6,13*6; 8 .db $1D*8+4, $00*8+$01,13*6,16*6,17*6,14*6; 9 .db $1C*8+4, $00*8+$01,15*6,18*6,19*6,16*6;10 .db $1B*8+4, $00*8+$01,16*6,19*6,20*6,17*6;11 .db $1B*8+4, $00*8+$01,18*6,21*6,22*6,19*6;12 .db $1A*8+4, $00*8+$01,19*6,22*6,23*6,20*6;13 .db $1A*8+4, $00*8+$01,21*6, 0*6, 1*6,22*6;14 .db $19*8+4, $00*8+$01,22*6, 1*6, 2*6,23*6;15 modelData1Vertex .dw 0,-159, 0; 0 .dw 0,-143, -15; 1 .dw 0,-127, 0; 2 .dw 112,-112, 0; 3 .dw 101,-101, -15; 4 .dw 90, -90, 0; 5 .dw 159, 0, 0; 6 .dw 143, 0, -15; 7 .dw 127, 0, 0; 8 .dw 112, 112, 0; 9 .dw 101, 101, -15;10 .dw 90, 90, 0;11 .dw 0, 159, 0;12 .dw 0, 143, -15;13 .dw 0, 127, 0;14 .dw -112, 112, 0;15 .dw -101, 101, -15;16 .dw -90, 90, 0;17 .dw -159, 0, 0;18 .dw -143, 0, -15;19 .dw -127, 0, 0;20 .dw -112,-112, 0;21 .dw -101,-101, -15;22 .dw -90, -90, 0;23 ;---------------------------- ;Building modelData2 .dw modelData2Polygon .db 4 ;polygon count .dw modelData2Vertex .db 8 ;vertex count modelData2Polygon .db $1D*8+4, $00*8+$01, 0*6, 1*6, 2*6, 3*6; 0 .db $1B*8+4, $00*8+$01, 3*6, 2*6, 6*6, 7*6; 1 .db $19*8+4, $00*8+$01, 2*6, 1*6, 5*6, 6*6; 2 .db $19*8+4, $00*8+$01, 0*6, 3*6, 7*6, 4*6; 3 modelData2Vertex .dw -50,-100, 50; 0 .dw 50,-100, 50; 1 .dw 50,-100, -50; 2 .dw -50,-100, -50; 3 .dw -50, 100, 50; 4 .dw 50, 100, 50; 5 .dw 50, 100, -50; 6 .dw -50, 100, -50; 7 ;---------------------------- vdcdata: .db $05, $00, $00 ;screen off +1 .db $0A, $02, $02 ;HSW $02 HDS $02 .db $0B, $1F, $04 ;HDW $1F HDE $04 .db $0C, $02, $0D ;VSW $02 VDS $0D .db $0D, $EF, $00 ;VDW $00EF .db $0E, $03, $00 ;VCR $03 .db $0F, $00, $00 ;DMA +1 +1 .db $07, $00, $00 ;scrollx 0 .db $08, $00, $00 ;scrolly 0 .db $09, $00, $00 ;32x32 .db $FF ;end ;---------------------------- palettedata: .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\;GRB $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF ;---------------------------- mulbankdata: .db $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04,\ $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04,\ $05, $05, $05, $05, $05, $05, $05, $05, $05, $05, $05, $05, $05, $05, $05, $05,\ $05, $05, $05, $05, $05, $05, $05, $05, $05, $05, $05, $05, $05, $05, $05, $05,\ $06, $06, $06, $06, $06, $06, $06, $06, $06, $06, $06, $06, $06, $06, $06, $06,\ $06, $06, $06, $06, $06, $06, $06, $06, $06, $06, $06, $06, $06, $06, $06, $06,\ $07, $07, $07, $07, $07, $07, $07, $07, $07, $07, $07, $07, $07, $07, $07, $07,\ $07, $07, $07, $07, $07, $07, $07, $07, $07, $07, $07, $07, $07, $07, $07, $07,\ $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08,\ $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08,\ $09, $09, $09, $09, $09, $09, $09, $09, $09, $09, $09, $09, $09, $09, $09, $09,\ $09, $09, $09, $09, $09, $09, $09, $09, $09, $09, $09, $09, $09, $09, $09, $09,\ $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A,\ $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A,\ $0B, $0B, $0B, $0B, $0B, $0B, $0B, $0B, $0B, $0B, $0B, $0B, $0B, $0B, $0B, $0B,\ $0B, $0B, $0B, $0B, $0B, $0B, $0B, $0B, $0B, $0B, $0B, $0B, $0B, $0B, $0B, $0B ;---------------------------- muladdrdata: .db $40, $41, $42, $43, $44, $45, $46, $47, $48, $49, $4A, $4B, $4C, $4D, $4E, $4F,\ $50, $51, $52, $53, $54, $55, $56, $57, $58, $59, $5A, $5B, $5C, $5D, $5E, $5F,\ $40, $41, $42, $43, $44, $45, $46, $47, $48, $49, $4A, $4B, $4C, $4D, $4E, $4F,\ $50, $51, $52, $53, $54, $55, $56, $57, $58, $59, $5A, $5B, $5C, $5D, $5E, $5F,\ $40, $41, $42, $43, $44, $45, $46, $47, $48, $49, $4A, $4B, $4C, $4D, $4E, $4F,\ $50, $51, $52, $53, $54, $55, $56, $57, $58, $59, $5A, $5B, $5C, $5D, $5E, $5F,\ $40, $41, $42, $43, $44, $45, $46, $47, $48, $49, $4A, $4B, $4C, $4D, $4E, $4F,\ $50, $51, $52, $53, $54, $55, $56, $57, $58, $59, $5A, $5B, $5C, $5D, $5E, $5F,\ $40, $41, $42, $43, $44, $45, $46, $47, $48, $49, $4A, $4B, $4C, $4D, $4E, $4F,\ $50, $51, $52, $53, $54, $55, $56, $57, $58, $59, $5A, $5B, $5C, $5D, $5E, $5F,\ $40, $41, $42, $43, $44, $45, $46, $47, $48, $49, $4A, $4B, $4C, $4D, $4E, $4F,\ $50, $51, $52, $53, $54, $55, $56, $57, $58, $59, $5A, $5B, $5C, $5D, $5E, $5F,\ $40, $41, $42, $43, $44, $45, $46, $47, $48, $49, $4A, $4B, $4C, $4D, $4E, $4F,\ $50, $51, $52, $53, $54, $55, $56, $57, $58, $59, $5A, $5B, $5C, $5D, $5E, $5F,\ $40, $41, $42, $43, $44, $45, $46, $47, $48, $49, $4A, $4B, $4C, $4D, $4E, $4F,\ $50, $51, $52, $53, $54, $55, $56, $57, $58, $59, $5A, $5B, $5C, $5D, $5E, $5F ;---------------------------- ;interrupt vectors .org $FFF6 .dw _irq2 .dw _irq1 .dw _timer .dw _nmi .dw _reset ;//////////////////////////// .bank 1 .org $A000 ;---------------------------- vertexRotationSelect: ; and #3 cmp #3 beq .rotationSelectJump2 cmp #1 beq .rotationSelectJump11 bcs .rotationSelectJump12 .rotationSelectJump10: ldx <rotationX jsr vertexRotationX rts .rotationSelectJump11: ldx <rotationY jsr vertexRotationY rts .rotationSelectJump12: ldx <rotationZ jsr vertexRotationZ .rotationSelectJump2: rts ;---------------------------- vertexRotationZ: ;x=xcosA-ysinA y=xsinA+ycosA z=z ;transform2DWork0 => transform2DWork0 ;vertexCount = count ;x = angle cpx #0 jeq .vertexRotationZEnd lda <vertexCount jeq .vertexRotationZEnd sta <vertexCountWork lda sinDataLow,x ;sin sta <vertexRotationSin lda sinDataHigh,x sta <vertexRotationSin+1 lda cosDataLow,x ;cos sta <vertexRotationCos lda cosDataHigh,x sta <vertexRotationCos+1 cly .vertexRotationZLoop: ;---------------- lda transform2DWork0,y ;X0 sta <mul16a lda transform2DWork0+1,y sta <mul16a+1 movw <mul16b, <vertexRotationCos ;cos jsr smul16 ;xcosA movq <div16ans, <mul16c lda transform2DWork0+2,y ;Y0 sta <mul16a lda transform2DWork0+3,y sta <mul16a+1 movw <mul16b, <vertexRotationSin ;sin jsr smul16 ;ysinA subq <mul16c, <div16ans, <mul16c ;xcosA-ysinA asl <mul16c+1 rol <mul16d rol <mul16d+1 asl <mul16c+1 rol <mul16d rol <mul16d+1 lda <mul16d+1 pha lda <mul16d pha ;---------------- lda transform2DWork0,y ;X0 sta <mul16a lda transform2DWork0+1,y sta <mul16a+1 movw <mul16b, <vertexRotationSin ;sin jsr smul16 ;xsinA movq <div16ans, <mul16c lda transform2DWork0+2,y ;Y0 sta <mul16a lda transform2DWork0+3,y sta <mul16a+1 movw <mul16b, <vertexRotationCos ;cos jsr smul16 ;ycosA addq <mul16c, <div16ans, <mul16c ;xsinA+ycosA asl <mul16c+1 rol <mul16d rol <mul16d+1 asl <mul16c+1 rol <mul16d rol <mul16d+1 lda <mul16d sta transform2DWork0+2,y lda <mul16d+1 sta transform2DWork0+3,y ;---------------- pla sta transform2DWork0,y pla sta transform2DWork0+1,y ;---------------- clc tya adc #6 tay dec <vertexCountWork jne .vertexRotationZLoop .vertexRotationZEnd: rts ;---------------------------- vertexRotationY: ;x=xcosA+zsinA y=y z=-xsinA+zcosA ;transform2DWork0 => transform2DWork0 ;vertexCount = count ;x = angle cpx #0 jeq .vertexRotationYEnd lda <vertexCount jeq .vertexRotationYEnd sta <vertexCountWork lda sinDataLow,x ;sin sta <vertexRotationSin lda sinDataHigh,x sta <vertexRotationSin+1 lda cosDataLow,x ;cos sta <vertexRotationCos lda cosDataHigh,x sta <vertexRotationCos+1 cly .vertexRotationYLoop: ;---------------- lda transform2DWork0+4,y ;Z0 sta <mul16a lda transform2DWork0+5,y sta <mul16a+1 movw <mul16b, <vertexRotationSin ;sin jsr smul16 ;zsinA movq <div16ans, <mul16c lda transform2DWork0,y ;X0 sta <mul16a lda transform2DWork0+1,y sta <mul16a+1 movw <mul16b, <vertexRotationCos ;cos jsr smul16 ;xcosA addq <mul16c, <div16ans, <mul16c ;zsinA+xcosA asl <mul16c+1 rol <mul16d rol <mul16d+1 asl <mul16c+1 rol <mul16d rol <mul16d+1 lda <mul16d+1 pha lda <mul16d pha ;---------------------------- lda transform2DWork0+4,y ;Z0 sta <mul16a lda transform2DWork0+5,y sta <mul16a+1 movw <mul16b, <vertexRotationCos ;cos jsr smul16 ;zcosA movq <div16ans, <mul16c lda transform2DWork0,y ;X0 sta <mul16a lda transform2DWork0+1,y sta <mul16a+1 movw <mul16b, <vertexRotationSin ;sin jsr smul16 ;xsinA subq <mul16c, <div16ans, <mul16c ;zcosA-xsinA asl <mul16c+1 rol <mul16d rol <mul16d+1 asl <mul16c+1 rol <mul16d rol <mul16d+1 lda <mul16d sta transform2DWork0+4,y lda <mul16d+1 sta transform2DWork0+5,y ;---------------- pla sta transform2DWork0,y pla sta transform2DWork0+1,y ;---------------- clc tya adc #6 tay dec <vertexCountWork jne .vertexRotationYLoop .vertexRotationYEnd: rts ;---------------------------- vertexRotationX: ;x=x y=ycosA-zsinA z= ysinA+zcosA ;transform2DWork0 => transform2DWork0 ;vertexCount = count ;x = angle cpx #0 jeq .vertexRotationXEnd lda <vertexCount jeq .vertexRotationXEnd sta <vertexCountWork lda sinDataLow,x ;sin sta <vertexRotationSin lda sinDataHigh,x sta <vertexRotationSin+1 lda cosDataLow,x ;cos sta <vertexRotationCos lda cosDataHigh,x sta <vertexRotationCos+1 cly .vertexRotationXLoop: ;---------------- lda transform2DWork0+2,y ;Y0 sta <mul16a lda transform2DWork0+3,y sta <mul16a+1 movw <mul16b, <vertexRotationCos ;cos jsr smul16 ;ycosA movq <div16ans, <mul16c lda transform2DWork0+4,y ;Z0 sta <mul16a lda transform2DWork0+5,y sta <mul16a+1 movw <mul16b, <vertexRotationSin ;sin jsr smul16 ;zsinA subq <mul16c, <div16ans, <mul16c ;ycosA-zsinA asl <mul16c+1 rol <mul16d rol <mul16d+1 asl <mul16c+1 rol <mul16d rol <mul16d+1 lda <mul16d+1 pha lda <mul16d pha ;---------------- lda transform2DWork0+2,y ;Y0 sta <mul16a lda transform2DWork0+3,y sta <mul16a+1 movw <mul16b, <vertexRotationSin ;sin jsr smul16 ;ysinA movq <div16ans, <mul16c lda transform2DWork0+4,y ;Z0 sta <mul16a lda transform2DWork0+5,y sta <mul16a+1 movw <mul16b, <vertexRotationCos ;cos jsr smul16 ;zcosA addq <mul16c, <div16ans, <mul16c ;ysinA+zcosA asl <mul16c+1 rol <mul16d rol <mul16d+1 asl <mul16c+1 rol <mul16d rol <mul16d+1 lda <mul16d sta transform2DWork0+4,y lda <mul16d+1 sta transform2DWork0+5,y ;---------------- pla sta transform2DWork0+2,y pla sta transform2DWork0+3,y ;---------------- clc tya adc #6 tay dec <vertexCountWork jne .vertexRotationXLoop .vertexRotationXEnd: rts ;---------------------------- vertexTranslation2: ; lda <vertexCount beq .vertexTranslation2End sta <vertexCountWork cly .vertexTranslation2Loop: clc lda transform2DWork0, y adc <translationX sta transform2DWork0, y lda transform2DWork0+1, y adc <translationX+1 sta transform2DWork0+1, y clc lda transform2DWork0+2, y adc <translationY sta transform2DWork0+2, y lda transform2DWork0+3, y adc <translationY+1 sta transform2DWork0+3, y clc lda transform2DWork0+4, y adc <translationZ sta transform2DWork0+4, y lda transform2DWork0+5, y adc <translationZ+1 sta transform2DWork0+5, y clc tya adc #6 tay dec <vertexCountWork bne .vertexTranslation2Loop .vertexTranslation2End: rts ;---------------------------- transform2D2: ; ldx <vertexCount cly .transform2D2Loop0: lda transform2DWork0, y sta transform2DWork1, y lda transform2DWork0+1, y sta transform2DWork1+1, y lda transform2DWork0+2, y sta transform2DWork1+2, y lda transform2DWork0+3, y sta transform2DWork1+3, y lda transform2DWork0+4, y sta transform2DWork1+4, y lda transform2DWork0+5, y sta transform2DWork1+5, y ;Z0 < 128 check sec lda transform2DWork0+4, y ;Z0 sbc #128 lda transform2DWork0+5, y sbc #00 bpl .transform2D2Jump05 jmp .transform2D2Jump00 .transform2D2Jump05: ;X0 to mul16c lda transform2DWork0, y sta <mul16c lda transform2DWork0+1, y sta <mul16c+1 ;Z0 to mul16a lda transform2DWork0+4, y sta <mul16a lda transform2DWork0+5, y sta <mul16a+1 ;X0*128/Z0 jsr transform2DProc ;X0*128/Z0+centerX ;mul16a+centerX to X0 clc lda <mul16a adc <centerX sta transform2DWork0, y ;X0 lda <mul16a+1 adc <centerX+1 sta transform2DWork0+1, y ;Y0 to mul16c lda transform2DWork0+2, y sta <mul16c lda transform2DWork0+3, y sta <mul16c+1 ;Z0 to mul16a lda transform2DWork0+4, y sta <mul16a lda transform2DWork0+5, y sta <mul16a+1 ;Y0*128/Z0 jsr transform2DProc ;Y0*128/Z0+centerY ;mul16a+centerY to Y0 clc lda <mul16a adc <centerY sta transform2DWork0+2, y ;Y0 lda <mul16a+1 adc <centerY+1 sta transform2DWork0+3, y jmp .transform2D2Jump01 .transform2D2Jump00: ;Z0<128 flag set lda #$00 sta transform2DWork0+4, y lda #$80 sta transform2DWork0+5, y .transform2D2Jump01: clc tya adc #6 tay dex jne .transform2D2Loop0 rts ;---------------------------- moveToTransform2DWork0: ;vertex0Addr to Transform2DWork0 lda <vertexCount beq .moveToTransform2DWork0End sta <vertexCountWork cly .moveToTransform2DWork0Loop: lda [vertex0Addr], y sta transform2DWork0, y iny lda [vertex0Addr],y sta transform2DWork0, y iny lda [vertex0Addr],y sta transform2DWork0, y iny lda [vertex0Addr],y sta transform2DWork0, y iny lda [vertex0Addr],y sta transform2DWork0, y iny lda [vertex0Addr],y sta transform2DWork0, y iny dec <vertexCountWork bne .moveToTransform2DWork0Loop .moveToTransform2DWork0End: rts ;---------------------------- putPolyBuffer: ; movw <polyBufferAddr, polyBufferStart .putPolyBufferLoop0: ldy #5 lda [polyBufferAddr], y ;COUNT beq .putPolyBufferEnd sta <clip2D0Count pha ldy #4 lda [polyBufferAddr], y ;COLOR sta <polyLineColorNo clx ldy #6 .putPolyBufferLoop1: lda [polyBufferAddr], y sta clip2D0,x inx inx iny lda [polyBufferAddr], y sta clip2D0,x inx inx iny dec <clip2D0Count bne .putPolyBufferLoop1 pla sta <clip2D0Count jsr calcEdge_putPoly ldy #0 lda [polyBufferAddr], y tax iny lda [polyBufferAddr], y sta <polyBufferAddr+1 txa sta <polyBufferAddr+0 bra .putPolyBufferLoop0 .putPolyBufferEnd: rts ;---------------------------- setModel2: ; ;rotation ldy #$05 lda [modelAddr], y ;vertex count sta <vertexCount ldy #$03 lda [modelAddr], y ;vertex data address sta <vertex0Addr ldy #$04 lda [modelAddr], y sta <vertex0Addr+1 jsr moveToTransform2DWork0 lda <rotationSelect and #3 jsr vertexRotationSelect lda <rotationSelect lsr a lsr a and #3 jsr vertexRotationSelect lda <rotationSelect lsr a lsr a lsr a lsr a and #3 jsr vertexRotationSelect ;translation subw <translationX, <eyeTranslationX subw <translationY, <eyeTranslationY subw <translationZ, <eyeTranslationZ jsr vertexTranslation2 ;eye rotation mov <rotationX, <eyeRotationX mov <rotationY, <eyeRotationY mov <rotationZ, <eyeRotationZ lda <eyeRotationSelect and #3 jsr vertexRotationSelect lda <eyeRotationSelect lsr a lsr a and #3 jsr vertexRotationSelect lda <eyeRotationSelect lsr a lsr a lsr a lsr a and #3 jsr vertexRotationSelect ;transform2D jsr transform2D2 jsr setModelProc2 rts ;---------------------------- setModel: ; ;Rotation ldy #$05 lda [modelAddr], y ;vertex count sta <vertexCount ldy #$03 lda [modelAddr], y ;vertex data address sta <vertex0Addr ldy #$04 lda [modelAddr], y sta <vertex0Addr+1 movw <vertex1Addr, #transform2DWork0 jsr vertexMultiply ;translation ldy #$05 lda [modelAddr], y ;vertex count sta <vertexCount movw <vertex0Addr, #transform2DWork0 movw <vertex1Addr, #transform2DWork1 jsr vertexTranslation ;transform2D ldy #$05 lda [modelAddr], y ;vertex count sta <vertexCount movw <vertex0Addr, #transform2DWork1 movw <vertex1Addr, #transform2DWork0 jsr transform2D jsr setModelProc rts ;---------------------------- setModelProc2: ; ldy #$00 lda [modelAddr], y sta <modelAddrWork ;ModelData Polygon Addr iny lda [modelAddr], y sta <modelAddrWork+1 ldy #$02 lda [modelAddr], y ;Polygon Count sta <modelPolygonCount cly .setModelLoop3: phy lda [modelAddrWork], y ;ModelData Vertex Count, Front Color and #$F8 lsr a lsr a sta <setModelFrontColor lda [modelAddrWork], y ;ModelData Vertex Count, Front Color and #$07 dec a sta <setModelCount iny lda [modelAddrWork], y ;ModelData Polygon Attr, Back Color sta <setModelAttr and #$F8 lsr a lsr a sta <setModelBackColor iny lda [modelAddrWork], y sta <frontClipDataWork stz <model2DClipIndexWork stz <frontClipCount stz <polyBufferZ0Work0 stz <polyBufferZ0Work0+1 .setModelLoop4: lda [modelAddrWork], y sta <frontClipData0 iny lda [modelAddrWork], y sta <frontClipData1 phy jsr clipFront ply dec <setModelCount bne .setModelLoop4 ;-------- lda [modelAddrWork], y sta <frontClipData0 lda <frontClipDataWork sta <frontClipData1 jsr clipFront lda <frontClipCount jeq .setModelJump0 sta <clip2D0Count jsr clip2D jeq .setModelJump0 ;back side check sec lda clip2D0+8 ;X2 sbc clip2D0+4 ;X1 sta <mul16a cla sbc #0 sta <mul16a+1 sec lda clip2D0+2 ;Y0 sbc clip2D0+6 ;Y1 sta <mul16b cla sbc #0 sta <mul16b+1 jsr smul16 movq <div16ans, <mul16c sec lda clip2D0+10 ;Y2 sbc clip2D0+6 ;Y1 sta <mul16a cla sbc #0 sta <mul16a+1 sec lda clip2D0 ;X0 sbc clip2D0+4 ;X1 sta <mul16b cla sbc #0 sta <mul16b+1 jsr smul16 cmpq <div16ans, <mul16c bpl .setModelJump2 ;Back Side bbr0 <setModelAttr, .setModelJump6 jmp .setModelJump0 .setModelJump6: lda <setModelBackColor bra .setModelJump5 .setModelJump2: ;Front Side lda <setModelFrontColor .setModelJump5: ldy #4 sta [polyBufferAddr], y ;COLOR lda <clip2D0Count ldy #5 sta [polyBufferAddr], y ;COUNT ;SAMPLE Z ldy #2 lda <polyBufferZ0Work0 ;SAMPLE Z sta [polyBufferAddr], y iny lda <polyBufferZ0Work0+1 sta [polyBufferAddr], y ;set buffer movw <polyBufferNow, #polyBufferStart .setBufferLoop: ldy #0 ;NEXT ADDR lda [polyBufferNow], y sta <polyBufferNext iny lda [polyBufferNow], y sta <polyBufferNext+1 ldy #2 ;NEXT SAMPLE Z lda [polyBufferNext], y sta <polyBufferZ0Work0 iny lda [polyBufferNext], y sta <polyBufferZ0Work0+1 ldy #2 ;SAMPLE Z sec lda [polyBufferAddr], y sbc <polyBufferZ0Work0 iny lda [polyBufferAddr], y sbc <polyBufferZ0Work0+1 bpl .setBufferJump ;SAMPLE Z >= NEXT SAMPLE Z movw <polyBufferNow, <polyBufferNext bra .setBufferLoop .setBufferJump: ldy #0 ;BUFFER -> NEXT lda <polyBufferNext sta [polyBufferAddr], y iny lda <polyBufferNext+1 sta [polyBufferAddr], y ldy #0 ;NOW -> BUFFER lda <polyBufferAddr sta [polyBufferNow], y iny lda <polyBufferAddr+1 sta [polyBufferNow], y ;set data clx ldy #6 .setModelLoop2: lda clip2D0,x sta [polyBufferAddr], y inx inx iny lda clip2D0,x sta [polyBufferAddr], y inx inx iny dec <clip2D0Count bne .setModelLoop2 ;next buffer addr clc tya adc <polyBufferAddr sta <polyBufferAddr bcc .setModelJump0 inc <polyBufferAddr+1 .setModelJump0: clc pla adc #6 tay dec <modelPolygonCount jne .setModelLoop3 rts ;---------------------------- clipFront: ldx <frontClipData0 ldy <frontClipData1 lda transform2DWork0+5, x ;Z0<128 flag and #$80 lsr a sta <frontClipFlag lda transform2DWork0+5, y ;Z0<128 flag and #$80 ora <frontClipFlag sta <frontClipFlag jeq .clipFrontJump8 cmp #$C0 jeq .clipFrontJump9 ;clip front ;(128-Z0) to mul16a sec lda #128 sbc transform2DWork1+4, x sta <mul16a lda #0 sbc transform2DWork1+5, x sta <mul16a+1 ;(X1-X0) to mul16b sec lda transform2DWork1+0, y sbc transform2DWork1+0, x sta <mul16b lda transform2DWork1+1, y sbc transform2DWork1+1, x sta <mul16b+1 ;(128-Z0)*(X1-X0) to mul16d:mul16c jsr smul16 ;(Z1-Z0) to mul16a sec lda transform2DWork1+4, y sbc transform2DWork1+4, x sta <mul16a lda transform2DWork1+5, y sbc transform2DWork1+5, x sta <mul16a+1 ;(128-Z0)*(X1-X0)/(Z1-Z0) jsr sdiv32 ;(128-Z0)*(X1-X0)/(Z1-Z0)+X0 clc lda <mul16a adc transform2DWork1+0, x sta <mul16a lda <mul16a+1 adc transform2DWork1+1, x sta <mul16a+1 ;mul16a+centerX addw <clipFrontX, <mul16a, <centerX ;(128-Z0) to mul16a sec lda #128 sbc transform2DWork1+4, x sta <mul16a lda #0 sbc transform2DWork1+5, x sta <mul16a+1 ;(Y1-Y0) to mul16b sec lda transform2DWork1+2, y sbc transform2DWork1+2, x sta <mul16b lda transform2DWork1+3, y sbc transform2DWork1+3, x sta <mul16b+1 ;(128-Z0)*(Y1-Y0) to mul16d:mul16c jsr smul16 ;(Z1-Z0) to mul16a sec lda transform2DWork1+4, y sbc transform2DWork1+4, x sta <mul16a lda transform2DWork1+5, y sbc transform2DWork1+5, x sta <mul16a+1 ;(128-Z0)*(Y1-Y0)/(Z1-Z0) jsr sdiv32 ;(128-Z0)*(Y1-Y0)/(Z1-Z0)+Y0 clc lda <mul16a adc transform2DWork1+2, x sta <mul16a lda <mul16a+1 adc transform2DWork1+3, x sta <mul16a+1 ;mul16a+centerY addw <clipFrontY, <mul16a, <centerY bbs7 <frontClipFlag, .clipFrontJump10 ldy <model2DClipIndexWork lda <clipFrontX sta clip2D0, y iny lda <clipFrontX+1 sta clip2D0, y iny lda <clipFrontY sta clip2D0, y iny lda <clipFrontY+1 sta clip2D0, y iny sty <model2DClipIndexWork lda #128 sta polyBufferZ0Work1 stz polyBufferZ0Work1+1 inc <frontClipCount bra .clipFrontJump11 .clipFrontJump10: ldy <model2DClipIndexWork lda transform2DWork0, x sta clip2D0, y iny lda transform2DWork0+1, x sta clip2D0, y iny lda transform2DWork0+2, x sta clip2D0, y iny lda transform2DWork0+3, x sta clip2D0, y iny lda <clipFrontX sta clip2D0, y iny lda <clipFrontX+1 sta clip2D0, y iny lda <clipFrontY sta clip2D0, y iny lda <clipFrontY+1 sta clip2D0, y iny sty <model2DClipIndexWork lda transform2DWork0+4, x sta polyBufferZ0Work1 lda transform2DWork0+5, x sta polyBufferZ0Work1+1 inc <frontClipCount inc <frontClipCount bra .clipFrontJump11 .clipFrontJump8: ldy <model2DClipIndexWork lda transform2DWork0, x sta clip2D0, y iny lda transform2DWork0+1, x sta clip2D0, y iny lda transform2DWork0+2, x sta clip2D0, y iny lda transform2DWork0+3, x sta clip2D0, y iny sty <model2DClipIndexWork lda transform2DWork0+4, x sta polyBufferZ0Work1 lda transform2DWork0+5, x sta polyBufferZ0Work1+1 inc <frontClipCount .clipFrontJump11: ;check Z sample cmpw <polyBufferZ0Work0, <polyBufferZ0Work1 bpl .clipFrontJump9 movw <polyBufferZ0Work0, <polyBufferZ0Work1 .clipFrontJump9: rts ;---------------------------- setModelProc: ; ldy #$00 lda [modelAddr], y sta <modelAddrWork ;ModelData Polygon Addr iny lda [modelAddr], y sta <modelAddrWork+1 ldy #$02 lda [modelAddr], y ;Polygon Count sta <modelPolygonCount stz <polyBufferAddrWork0 ;ModelData Polygon .setModelLoop0: ldy <polyBufferAddrWork0 lda [modelAddrWork], y ;ModelData Vertex Count, Front Color and #$F8 lsr a lsr a sta <setModelFrontColor lda [modelAddrWork], y ;ModelData Vertex Count, Front Color and #$07 sta <setModelCountWork sta <setModelCount iny lda [modelAddrWork], y ;ModelData Polygon Attr, Back Color sta <setModelAttr and #$F8 lsr a lsr a sta <setModelBackColor iny sty <polyBufferAddrWork0 stz <polyBufferAddrWork1 ;clip2D stz <polyBufferZ0Work0 stz <polyBufferZ0Work0+1 .setModelLoop1: ldy <polyBufferAddrWork0 ;ModelData Polygon lda [modelAddrWork], y tax ldy <polyBufferAddrWork1 ;move to clip2D0 lda transform2DWork0, x ;2D X0 sta clip2D0, y inx iny lda transform2DWork0, x sta clip2D0, y inx iny lda transform2DWork0, x ;2D Y0 sta clip2D0, y inx iny lda transform2DWork0, x sta clip2D0, y inx iny sty <polyBufferAddrWork1 sec lda transform2DWork0, x ;3D Z0 sbc <polyBufferZ0Work0 inx lda transform2DWork0, x bpl .setModelJump4 ;Z0<128 flag check ;next polygon data index add <polyBufferAddrWork0, <setModelCount jmp .setModelJump0 .setModelJump4: sbc <polyBufferZ0Work0+1 bmi .setModelJump1 ;3D Z0 < polyBufferZ0Work0 dex lda transform2DWork0,x ;3D Z0 sta <polyBufferZ0Work0 inx lda transform2DWork0,x ;3D Z0 sta <polyBufferZ0Work0+1 .setModelJump1: inc <polyBufferAddrWork0 dec <setModelCount bne .setModelLoop1 ;call clip2D mov <clip2D0Count, <setModelCountWork jsr clip2D ;.setModelJump3: jeq .setModelJump0 ;back side check sec lda clip2D0+8 ;X2 sbc clip2D0+4 ;X1 sta <mul16a cla sbc #0 sta <mul16a+1 sec lda clip2D0+2 ;Y0 sbc clip2D0+6 ;Y1 sta <mul16b cla sbc #0 sta <mul16b+1 jsr smul16 movq <div16ans, <mul16c sec lda clip2D0+10 ;Y2 sbc clip2D0+6 ;Y1 sta <mul16a cla sbc #0 sta <mul16a+1 sec lda clip2D0 ;X0 sbc clip2D0+4 ;X1 sta <mul16b cla sbc #0 sta <mul16b+1 jsr smul16 cmpq <div16ans, <mul16c bpl .setModelJump2 ;back side bbr0 <setModelAttr, .setModelJump6 jmp .setModelJump0 .setModelJump6: lda <setModelBackColor bra .setModelJump5 .setModelJump2: ;front side lda <setModelFrontColor .setModelJump5: ldy #4 sta [polyBufferAddr], y ;COLOR lda <clip2D0Count ldy #5 sta [polyBufferAddr], y ;COUNT clx ldy #6 .setModelLoop2: lda clip2D0, x sta [polyBufferAddr], y inx inx iny lda clip2D0, x sta [polyBufferAddr], y inx inx iny dec <clip2D0Count bne .setModelLoop2 sty <polyBufferAddrWork2 ;SAMPLE Z ldy #2 lda <polyBufferZ0Work0 ;SAMPLE Z sta [polyBufferAddr], y iny lda <polyBufferZ0Work0+1 sta [polyBufferAddr], y ;set buffer movw <polyBufferNow, #polyBufferStart .setBufferLoop: ldy #0 ;NEXT ADDR lda [polyBufferNow], y sta <polyBufferNext iny lda [polyBufferNow], y sta <polyBufferNext+1 ldy #2 ;NEXT SAMPLE Z lda [polyBufferNext], y sta <polyBufferZ0Work0 iny lda [polyBufferNext], y sta <polyBufferZ0Work0+1 ldy #2 ;SAMPLE Z sec lda [polyBufferAddr], y sbc <polyBufferZ0Work0 iny lda [polyBufferAddr], y sbc <polyBufferZ0Work0+1 bpl .setBufferJump ;SAMPLE Z >= NEXT SAMPLE Z movw <polyBufferNow, <polyBufferNext bra .setBufferLoop .setBufferJump: ldy #0 ;BUFFER -> NEXT lda <polyBufferNext sta [polyBufferAddr], y iny lda <polyBufferNext+1 sta [polyBufferAddr], y ldy #0 ;NOW -> BUFFER lda <polyBufferAddr sta [polyBufferNow], y iny lda <polyBufferAddr+1 sta [polyBufferNow], y ;next buffer addr clc lda <polyBufferAddr adc <polyBufferAddrWork2 sta <polyBufferAddr bcc .setModelJump0 inc <polyBufferAddr+1 ;unset polygon .setModelJump0: ;check triangle bbs2 <setModelCountWork, .setModelJump7 ;triangle inc <polyBufferAddrWork0 .setModelJump7: dec <modelPolygonCount jne .setModelLoop0 rts ;---------------------------- initializePolyBuffer: ; ;initialize polyBufferAddr = polyBuffer movw <polyBufferAddr, #polyBuffer ;polyBufferStart NEXT ADDR = polyBufferEnd movw polyBufferStart, #polyBufferEnd ;polyBufferStart SAMPLE Z = $7FFF movw polyBufferStart+2, #$7FFF ;polyBufferEnd SAMPLE Z = $0000 stzw polyBufferEnd+2 ;polyBufferEnd COLOR = $00 stz polyBufferEnd+4 ;polyBufferEnd COUNT = $00 stz polyBufferEnd+5 rts ;---------------------------- moveMatrix1ToMatrix0: ; tii matrix1, matrix0, 18 rts ;---------------------------- moveMatrix1ToMatrix2: ; tii matrix1, matrix2, 18 rts ;---------------------------- moveMatrix2ToMatrix0: ; tii matrix2, matrix0, 18 rts ;---------------------------- setMatrix1RotationX: ; stz matrix1+0+0 lda #$40 sta matrix1+0+1 stz matrix1+0+2 stz matrix1+0+3 stz matrix1+0+4 stz matrix1+0+5 stz matrix1+6+0 stz matrix1+6+1 lda cosDataLow, x sta matrix1+6+2 lda cosDataHigh, x sta matrix1+6+3 clc lda sinDataLow, x eor #$FF adc #$01 sta matrix1+6+4 lda sinDataHigh, x eor #$FF adc #$00 sta matrix1+6+5 stz matrix1+12+0 stz matrix1+12+1 lda sinDataLow,x sta matrix1+12+2 lda sinDataHigh, x sta matrix1+12+3 lda cosDataLow,x sta matrix1+12+4 lda cosDataHigh, x sta matrix1+12+5 rts ;---------------------------- setMatrix1RotationY: ; lda cosDataLow, x sta matrix1+0+0 lda cosDataHigh, x sta matrix1+0+1 stz matrix1+0+2 stz matrix1+0+3 lda sinDataLow, x sta matrix1+0+4 lda sinDataHigh, x sta matrix1+0+5 stz matrix1+6+0 stz matrix1+6+1 stz matrix1+6+2 lda #$40 sta matrix1+6+3 stz matrix1+6+4 stz matrix1+6+5 clc lda sinDataLow, x eor #$FF adc #$01 sta matrix1+12+0 lda sinDataHigh, x eor #$FF adc #$00 sta matrix1+12+1 stz matrix1+12+2 stz matrix1+12+3 lda cosDataLow, x sta matrix1+12+4 lda cosDataHigh, x sta matrix1+12+5 rts ;---------------------------- setMatrix1RotationZ: ; lda cosDataLow, x sta matrix1+0+0 lda cosDataHigh, x sta matrix1+0+1 clc lda sinDataLow, x eor #$FF adc #$01 sta matrix1+0+2 lda sinDataHigh, x eor #$FF adc #$00 sta matrix1+0+3 stz matrix1+0+4 stz matrix1+0+5 lda sinDataLow, x sta matrix1+6+0 lda sinDataHigh, x sta matrix1+6+1 lda cosDataLow, x sta matrix1+6+2 lda cosDataHigh, x sta matrix1+6+3 stz matrix1+6+4 stz matrix1+6+5 stz matrix1+12+0 stz matrix1+12+1 stz matrix1+12+2 stz matrix1+12+3 stz matrix1+12+4 lda #$40 sta matrix1+12+5 rts ;---------------------------- vertexTranslation: ; .vertexTranslationLoop: cly clc lda [vertex0Addr], y adc <translationX sta [vertex1Addr], y iny lda [vertex0Addr], y adc <translationX+1 sta [vertex1Addr], y iny clc lda [vertex0Addr], y adc <translationY sta [vertex1Addr], y iny lda [vertex0Addr], y adc <translationY+1 sta [vertex1Addr], y iny clc lda [vertex0Addr], y adc <translationZ sta [vertex1Addr], y iny lda [vertex0Addr], y adc <translationZ+1 sta [vertex1Addr], y iny clc lda <vertex0Addr adc #$06 sta <vertex0Addr bcc .vertexTranslationJump00 inc <vertex0Addr+1 .vertexTranslationJump00: clc lda <vertex1Addr adc #$06 sta <vertex1Addr bcc .vertexTranslationJump01 inc <vertex1Addr+1 .vertexTranslationJump01: dec <vertexCount bne .vertexTranslationLoop rts ;---------------------------- vertexMultiply: ; .vertexMultiplyLoop2: clx .vertexMultiplyLoop1: stz <vertexWork stz <vertexWork+1 stz <vertexWork+2 stz <vertexWork+3 cly .vertexMultiplyLoop0: lda [vertex0Addr], y sta <mul16a iny lda [vertex0Addr], y sta <mul16a+1 iny lda matrix2, x sta <mul16b inx lda matrix2, x sta <mul16b+1 inx jsr smul16 addq <vertexWork, <mul16c, <vertexWork cpy #6 bne .vertexMultiplyLoop0 lda <vertexWork+2 asl <vertexWork+1 rol a rol <vertexWork+3 asl <vertexWork+1 rol a rol <vertexWork+3 sta [vertex1Addr] inc <vertex1Addr bne .vertexMultiplyJump00 inc <vertex1Addr+1 .vertexMultiplyJump00: lda <vertexWork+3 sta [vertex1Addr] inc <vertex1Addr bne .vertexMultiplyJump01 inc <vertex1Addr+1 .vertexMultiplyJump01: cpx #18 bne .vertexMultiplyLoop1 clc lda <vertex0Addr adc #$06 sta <vertex0Addr bcc .vertexMultiplyJump02 inc <vertex0Addr+1 .vertexMultiplyJump02: dec <vertexCount bne .vertexMultiplyLoop2 rts ;---------------------------- matrixMultiply: ; stz vertex1Addr cly clx .matrixMultiplyLoop0: lda matrix0, x sta <mul16a lda matrix0+1, x sta <mul16a+1 lda matrix1, y sta <mul16b lda matrix1+1, y sta <mul16b+1 jsr smul16 movq <vertexWork, <mul16c ;---------------- lda matrix0+6, x sta <mul16a lda matrix0+7, x sta <mul16a+1 lda matrix1+2, y sta <mul16b lda matrix1+3, y sta <mul16b+1 jsr smul16 addq <vertexWork, <mul16c, <vertexWork ;---------------- lda matrix0+12, x sta <mul16a lda matrix0+13, x sta <mul16a+1 lda matrix1+4, y sta <mul16b lda matrix1+5, y sta <mul16b+1 jsr smul16 addq <vertexWork, <mul16c, <vertexWork ;---------------- lda <vertexWork+2 asl <vertexWork+1 rol a rol <vertexWork+3 asl <vertexWork+1 rol a rol <vertexWork+3 phx ldx <vertex1Addr sta matrix2, x inx lda <vertexWork+3 sta matrix2, x inx stx <vertex1Addr plx inx inx cpx #6 jne .matrixMultiplyLoop0 clx clc tya adc #6 tay cpy #18 jne .matrixMultiplyLoop0 rts ;---------------------------- transform2D: ; .transform2DLoop0: ;Z0 < 128 check ldy #$04 sec lda [vertex0Addr], y sbc #128 iny lda [vertex0Addr], y sbc #00 jmi .transform2DJump00 ;X0 to mul16c ldy #$00 lda [vertex0Addr], y sta <mul16c iny lda [vertex0Addr], y sta <mul16c+1 ;Z0 to mul16a ldy #$04 lda [vertex0Addr], y sta <mul16a iny lda [vertex0Addr], y sta <mul16a+1 ;X0*128/Z0 jsr transform2DProc ;X0*128/Z0+centerX ;mul16a+centerX to vertex1Addr X0 ldy #$00 clc lda <mul16a adc <centerX sta [vertex1Addr], y iny lda <mul16a+1 adc <centerX+1 sta [vertex1Addr], y ;Y0 to mul16c ldy #$02 lda [vertex0Addr], y sta <mul16c iny lda [vertex0Addr], y sta <mul16c+1 ;Z0 to mul16a ldy #$04 lda [vertex0Addr], y sta <mul16a iny lda [vertex0Addr], y sta <mul16a+1 ;Y0*128/Z0 jsr transform2DProc ;Y0*128/Z0+centerY ;mul16a+centerY to vertex1Addr Y0 ldy #$02 clc lda <mul16a adc <centerY sta [vertex1Addr], y iny lda <mul16a+1 adc <centerY+1 sta [vertex1Addr], y ;Z0>=128 flag set ;Z0 set iny lda [vertex0Addr], y sta [vertex1Addr], y iny lda [vertex0Addr], y sta [vertex1Addr], y jmp .transform2DJump01 .transform2DJump00: ;Z0<128 flag set ldy #$04 lda #$00 sta [vertex1Addr], y iny lda #$80 sta [vertex1Addr], y .transform2DJump01: addwb <vertex0Addr, #$06 addwb <vertex1Addr, #$06 dec <vertexCount jne .transform2DLoop0 rts ;---------------------------- transform2DProc: ;mul16a(rough value) = (mul16c(-32768_32767) * 128 / mul16a(1_32767)) ;push y phy ;c sign lda <mul16c+1 pha bpl .jp00 ;c neg sec cla sbc <mul16c sta <mul16c cla sbc <mul16c+1 sta <mul16c+1 .jp00: stz <muladdr ;get div data ldy <div16a+1 clc lda mulbankdata, y adc #divdatBank-muldatBank ;carry clear sta <mulbank tam #$02 lda muladdrdata, y sta <muladdr+1 ldy <div16a lda [muladdr], y sta <sqrt64a lda <mulbank adc #4 ;carry clear tam #$02 lda [muladdr], y sta <sqrt64a+1 lda <mulbank adc #8 ;carry clear tam #$02 lda [muladdr], y sta <sqrt64a+2 ;mul mul16c low byte ldy <mul16c lda mulbankdata, y sta <mulbank tam #$02 lda muladdrdata, y sta <muladdr+1 ldy <sqrt64a lda [muladdr], y sta <sqrt64b ldy <sqrt64a+1 lda [muladdr], y sta <sqrt64b+1 ldy <sqrt64a+2 lda [muladdr], y sta <sqrt64b+2 lda <mulbank adc #8 ;carry clear tam #$02 ldy <sqrt64a lda [muladdr], y adc <sqrt64b+1 sta <sqrt64b+1 ldy <sqrt64a+1 lda [muladdr], y adc <sqrt64b+2 sta <sqrt64b+2 ldy <sqrt64a+2 lda [muladdr], y adc #0 ;carry clear sta <sqrt64b+3 ;mul mul16c high byte ldy <mul16c+1 lda mulbankdata, y sta <mulbank tam #$02 lda muladdrdata, y sta <muladdr+1 ldy <sqrt64a lda [muladdr], y adc <sqrt64b+1 sta <sqrt64b+1 ldy <sqrt64a+1 lda [muladdr], y adc <sqrt64b+2 sta <sqrt64b+2 ldy <sqrt64a+2 lda [muladdr], y adc <sqrt64b+3 ;carry clear sta <sqrt64b+3 lda <mulbank adc #8 ;carry clear tam #$02 ldy <sqrt64a lda [muladdr], y adc <sqrt64b+2 sta <sqrt64b+2 ldy <sqrt64a+1 lda [muladdr], y adc <sqrt64b+3 sta <sqrt64b+3 movw <mul16a, <sqrt64b+2 pla bpl .jp01 ;ans neg sec cla sbc <mul16a sta <mul16a cla sbc <mul16a+1 sta <mul16a+1 .jp01: ;pull y ply rts ;---------------------------- clip2D: ; clx ldy <clip2D0Count .loop0: lda clip2D0+1, x bne .clipOut lda clip2D0+3, x bne .clipOut lda clip2D0+2, x cmp #192 bcs .clipOut inx inx inx inx dey bne .loop0 lda <clip2D0Count rts .clipOut: jsr clip2DY0 lda <clip2D1Count beq .clip2DEnd jsr clip2DY255 lda <clip2D0Count beq .clip2DEnd jsr clip2DX0 lda <clip2D1Count beq .clip2DEnd jsr clip2DX255 lda <clip2D0Count .clip2DEnd: rts ;---------------------------- clip2DX255: ; lda <clip2D1Count asl a asl a tax lda clip2D1 ;X0 sta clip2D1, x ;last X lda clip2D1+1 sta clip2D1+1, x lda clip2D1+2 ;Y0 sta clip2D1+2, x ;last Y lda clip2D1+3 sta clip2D1+3, x clx cly stz <clip2D0Count .clip2DX255Loop0: stz <clip2DFlag sec lda clip2D1, x ;X0 sbc #$00 lda clip2D1+1, x sbc #$01 bmi .clip2DX255Jump00 smb0 <clip2DFlag .clip2DX255Jump00: sec lda clip2D1+4, x ;X1 sbc #$00 lda clip2D1+5, x sbc #$01 bmi .clip2DX255Jump01 smb1 <clip2DFlag .clip2DX255Jump01: lda <clip2DFlag jeq .clip2DX255Jump02 cmp #$03 jeq .clip2DX255Jump03 ;(255-X0) to mul16a sec lda #255 sbc clip2D1, x ;X0 sta <mul16a lda #0 sbc clip2D1+1, x sta <mul16a+1 ;(Y1-Y0) to mul16b sec lda clip2D1+6, x ;Y1 sbc clip2D1+2, x ;Y0 sta <mul16b lda clip2D1+7, x sbc clip2D1+3, x sta <mul16b+1 ;(255-X0)*(Y1-Y0) to mul16d:mul16c jsr smul16 ;(X1-X0) to mul16a sec lda clip2D1+4, x ;X1 sbc clip2D1, x ;X0 sta <mul16a lda clip2D1+5, x sbc clip2D1+1, x sta <mul16a+1 ;(255-X0)*(Y1-Y0)/(X1-X0) jsr sdiv32 ;(255-X0)*(Y1-Y0)/(X1-X0)+Y0 clc lda <mul16a adc clip2D1+2, x ;Y0 sta <mul16a lda <mul16a+1 adc clip2D1+3, x sta <mul16a+1 bbs1 <clip2DFlag, .clip2DX255Jump04 ;X0>255 X1<=255 lda #$FF sta clip2D0, y ;X0 lda #$00 sta clip2D0+1, y lda <mul16a sta clip2D0+2, y ;Y0 lda <mul16a+1 sta clip2D0+3, y inc <clip2D0Count clc tya adc #$04 tay bra .clip2DX255Jump03 .clip2DX255Jump04: ;X0<=255 X1>255 lda clip2D1, x ;X0 sta clip2D0, y ;X0 lda clip2D1+1, x sta clip2D0+1, y lda clip2D1+2, x ;Y0 sta clip2D0+2, y ;Y0 lda clip2D1+3, x sta clip2D0+3, y lda #$FF sta clip2D0+4, y ;X1 lda #$00 sta clip2D0+5, y lda <mul16a sta clip2D0+6, y ;Y1 lda <mul16a+1 sta clip2D0+7, y add <clip2D0Count, #$02 clc tya adc #$08 tay bra .clip2DX255Jump03 .clip2DX255Jump02: ;X0<=255 X1<=255 lda clip2D1, x ;X0 sta clip2D0, y ;X0 lda clip2D1+1, x sta clip2D0+1, y lda clip2D1+2, x ;Y0 sta clip2D0+2, y ;Y0 lda clip2D1+3, x sta clip2D0+3, y inc <clip2D0Count clc tya adc #$04 tay .clip2DX255Jump03: ;X0>255 X1>255 clc txa adc #$04 tax dec <clip2D1Count jne .clip2DX255Loop0 rts ;---------------------------- clip2DX0: ; lda <clip2D0Count asl a asl a tax lda clip2D0 ;X0 sta clip2D0, x ;last X lda clip2D0+1 sta clip2D0+1, x lda clip2D0+2 ;Y0 sta clip2D0+2, x ;last Y lda clip2D0+3 sta clip2D0+3, x clx cly stz <clip2D1Count .clip2DX0Loop0: stz <clip2DFlag lda clip2D0+1,x ;X0 bpl .clip2DX0Jump00 smb0 <clip2DFlag .clip2DX0Jump00: lda clip2D0+5,x ;X1 bpl .clip2DX0Jump01 smb1 <clip2DFlag .clip2DX0Jump01: lda <clip2DFlag jeq .clip2DX0Jump02 cmp #$03 jeq .clip2DX0Jump03 ;(0-X0) to mul16a sec lda #0 sbc clip2D0, x ;X0 sta <mul16a lda #0 sbc clip2D0+1, x sta <mul16a+1 ;(Y1-Y0) to mul16b sec lda clip2D0+6, x ;Y1 sbc clip2D0+2, x ;Y0 sta <mul16b lda clip2D0+7, x sbc clip2D0+3, x sta <mul16b+1 ;(0-X0)*(Y1-Y0) to mul16d:mul16c jsr smul16 ;(X1-X0) to mul16a sec lda clip2D0+4, x ;X1 sbc clip2D0, x ;X0 sta <mul16a lda clip2D0+5, x sbc clip2D0+1, x sta <mul16a+1 ;(0-X0)*(Y1-Y0)/(X1-X0) jsr sdiv32 ;(0-X0)*(Y1-Y0)/(X1-X0)+Y0 clc lda <mul16a adc clip2D0+2, x ;Y0 sta <mul16a lda <mul16a+1 adc clip2D0+3, x sta <mul16a+1 bbs1 <clip2DFlag, .clip2DX0Jump04 ;X0<0 X1>=0 lda #$00 sta clip2D1, y ;X0 lda #$00 sta clip2D1+1, y lda <mul16a sta clip2D1+2, y ;Y0 lda <mul16a+1 sta clip2D1+3, y inc <clip2D1Count clc tya adc #$04 tay bra .clip2DX0Jump03 .clip2DX0Jump04: ;X0>=0 X1<0 lda clip2D0, x ;X0 sta clip2D1, y ;X0 lda clip2D0+1, x sta clip2D1+1, y lda clip2D0+2, x ;Y0 sta clip2D1+2, y ;Y0 lda clip2D0+3, x sta clip2D1+3, y lda #$00 sta clip2D1+4, y ;X1 lda #$00 sta clip2D1+5, y lda <mul16a sta clip2D1+6, y ;Y1 lda <mul16a+1 sta clip2D1+7, y add <clip2D1Count, #$02 clc tya adc #$08 tay bra .clip2DX0Jump03 .clip2DX0Jump02: ;X0>=0 X1>=0 lda clip2D0, x ;X0 sta clip2D1, y ;X0 lda clip2D0+1, x sta clip2D1+1, y lda clip2D0+2, x ;Y0 sta clip2D1+2, y ;Y0 lda clip2D0+3, x sta clip2D1+3, y inc <clip2D1Count clc tya adc #$04 tay .clip2DX0Jump03: ;X0<0 X1<0 clc txa adc #$04 tax dec <clip2D0Count jne .clip2DX0Loop0 rts ;---------------------------- clip2DY255: ; lda <clip2D1Count asl a asl a tax lda clip2D1 ;X0 sta clip2D1, x ;last X lda clip2D1+1 sta clip2D1+1, x lda clip2D1+2 ;Y0 sta clip2D1+2, x ;last Y lda clip2D1+3 sta clip2D1+3, x clx cly stz <clip2D0Count .clip2DY255Loop0: stz <clip2DFlag sec lda clip2D1+2, x ;Y0 sbc #192 lda clip2D1+3, x sbc #0 bmi .clip2DY255Jump00 smb0 <clip2DFlag .clip2DY255Jump00: sec lda clip2D1+6, x ;Y1 sbc #192 lda clip2D1+7, x sbc #0 bmi .clip2DY255Jump01 smb1 <clip2DFlag .clip2DY255Jump01: lda <clip2DFlag jeq .clip2DY255Jump02 cmp #$03 jeq .clip2DY255Jump03 . ;(191-Y0) to mul16a sec lda #191 sbc clip2D1+2, x ;Y0 sta <mul16a lda #0 sbc clip2D1+3, x sta <mul16a+1 ;(X1-X0) to mul16b sec lda clip2D1+4, x ;X1 sbc clip2D1, x ;X0 sta <mul16b lda clip2D1+5, x sbc clip2D1+1, x sta <mul16b+1 ;(191-Y0)*(X1-X0) to mul16d:mul16c jsr smul16 ;(Y1-Y0) to mul16a sec lda clip2D1+6, x ;Y1 sbc clip2D1+2, x ;Y0 sta <mul16a lda clip2D1+7, x sbc clip2D1+3, x sta <mul16a+1 ;(191-Y0)*(X1-X0)/(Y1-Y0) jsr sdiv32 ;(191-Y0)*(X1-X0)/(Y1-Y0)+X0 clc lda <mul16a adc clip2D1, x ;X0 sta <mul16a lda <mul16a+1 adc clip2D1+1, x sta <mul16a+1 bbs1 <clip2DFlag, .clip2DY255Jump04 ;Y0>191 Y1<=191 lda <mul16a sta clip2D0, y ;X0 lda <mul16a+1 sta clip2D0+1, y lda #191 sta clip2D0+2, y ;Y0 lda #0 sta clip2D0+3, y inc <clip2D0Count clc tya adc #$04 tay bra .clip2DY255Jump03 .clip2DY255Jump04: ;Y0<=191 Y1>191 lda clip2D1, x ;X0 sta clip2D0, y ;X0 lda clip2D1+1, x sta clip2D0+1, y lda clip2D1+2, x ;Y0 sta clip2D0+2, y ;Y0 lda clip2D1+3, x sta clip2D0+3, y lda <mul16a sta clip2D0+4, y ;X1 lda <mul16a+1 sta clip2D0+5, y lda #191 sta clip2D0+6, y ;Y1 lda #0 sta clip2D0+7, y add <clip2D0Count, #$02 clc tya adc #$08 tay bra .clip2DY255Jump03 .clip2DY255Jump02: ;Y0<=191 Y1<=191 lda clip2D1, x ;X0 sta clip2D0, y ;X0 lda clip2D1+1, x sta clip2D0+1, y lda clip2D1+2, x ;Y0 sta clip2D0+2, y ;Y0 lda clip2D1+3, x sta clip2D0+3, y inc <clip2D0Count clc tya adc #$04 tay .clip2DY255Jump03: ;Y0>191 Y1>191 clc txa adc #$04 tax dec <clip2D1Count jne .clip2DY255Loop0 rts ;---------------------------- clip2DY0: ; lda <clip2D0Count asl a asl a tax lda clip2D0 ;X0 sta clip2D0, x ;last X lda clip2D0+1 sta clip2D0+1, x lda clip2D0+2 ;Y0 sta clip2D0+2, x ;last Y lda clip2D0+3 sta clip2D0+3, x clx cly stz <clip2D1Count .clip2DY0Loop0: stz <clip2DFlag lda clip2D0+3, x ;Y0 bpl .clip2DY0Jump00 smb0 <clip2DFlag .clip2DY0Jump00: lda clip2D0+7, x ;Y1 bpl .clip2DY0Jump01 smb1 <clip2DFlag .clip2DY0Jump01: lda <clip2DFlag jeq .clip2DY0Jump02 cmp #$03 jeq .clip2DY0Jump03 . ;(0-Y0) to mul16a sec lda #0 sbc clip2D0+2, x ;Y0 sta <mul16a lda #0 sbc clip2D0+3, x sta <mul16a+1 ;(X1-X0) to mul16b sec lda clip2D0+4, x ;X1 sbc clip2D0, x ;X0 sta <mul16b lda clip2D0+5, x sbc clip2D0+1, x sta <mul16b+1 ;(0-Y0)*(X1-X0) to mul16d:mul16c jsr smul16 ;(Y1-Y0) to mul16a sec lda clip2D0+6, x ;Y1 sbc clip2D0+2, x ;Y0 sta <mul16a lda clip2D0+7, x sbc clip2D0+3, x sta <mul16a+1 ;(0-Y0)*(X1-X0)/(Y1-Y0) jsr sdiv32 ;(0-Y0)*(X1-X0)/(Y1-Y0)+X0 clc lda <mul16a adc clip2D0, x ;X0 sta <mul16a lda <mul16a+1 adc clip2D0+1, x sta <mul16a+1 bbs1 <clip2DFlag, .clip2DY0Jump04 ;Y0<0 Y1>=0 lda <mul16a sta clip2D1, y ;X0 lda <mul16a+1 sta clip2D1+1, y lda #$00 sta clip2D1+2, y ;Y0 lda #$00 sta clip2D1+3, y inc <clip2D1Count clc tya adc #$04 tay bra .clip2DY0Jump03 .clip2DY0Jump04: ;Y0>=0 Y1<0 lda clip2D0, x ;X0 sta clip2D1, y ;X0 lda clip2D0+1, x sta clip2D1+1, y lda clip2D0+2, x ;Y0 sta clip2D1+2, y ;Y0 lda clip2D0+3, x sta clip2D1+3, y lda <mul16a sta clip2D1+4, y ;X1 lda <mul16a+1 sta clip2D1+5, y lda #$00 sta clip2D1+6, y ;Y1 lda #$00 sta clip2D1+7, y add <clip2D1Count, #$02 clc tya adc #$08 tay bra .clip2DY0Jump03 .clip2DY0Jump02: ;Y0>=0 Y1>=0 lda clip2D0, x ;X0 sta clip2D1, y ;X0 lda clip2D0+1, x sta clip2D1+1, y lda clip2D0+2, x ;Y0 sta clip2D1+2, y ;Y0 lda clip2D0+3, x sta clip2D1+3, y inc <clip2D1Count clc tya adc #$04 tay .clip2DY0Jump03: ;Y0<0 Y1<0 clc txa adc #$04 tax dec <clip2D0Count jne .clip2DY0Loop0 rts ;---------------------------- calcEdge_putPoly: ; lda <clip2D0Count asl a asl a tax lda clip2D0 sta clip2D0, x lda clip2D0+2 sta clip2D0+2, x mov <minEdgeY, #$FF jsr initCalcEdge clx .calcEdge_putPolyLoop0: lda clip2D0, x sta <edgeX0 lda clip2D0+2, x sta <edgeY0 cmp <minEdgeY jcs .calcEdge_putPolyJump2 sta <minEdgeY .calcEdge_putPolyJump2: lda clip2D0+4, x sta <edgeX1 lda clip2D0+6, x sta <edgeY1 phx jsr calcEdge plx inx inx inx inx dec <clip2D0Count bne .calcEdge_putPolyLoop0 jsr putPolyLine rts ;---------------------------- calcEdge: ;calculation edge Y sec lda <edgeY1 sbc <edgeY0 beq .edgeJump6 sta <edgeSlopeY jcs .edgeJump7 eor #$FF inc a sta <edgeSlopeY ;edgeY0 > edgeY1 exchange X0<->X1 Y0<->Y1 lda <edgeX0 ldx <edgeX1 sta <edgeX1 stx <edgeX0 lda <edgeY0 ldx <edgeY1 sta <edgeY1 stx <edgeY0 jmp .edgeJump7 .edgeJump6: ;edgeY0 = edgeY1 ldy <edgeX0 ldx <edgeY0 setEdgeBufferm ldy <edgeX1 setEdgeBufferm rts .edgeJump7: ;calculation edge X sec lda <edgeX1 sbc <edgeX0 beq .edgeJump1 sta <edgeSlopeX stz <edgeSigneX bcs .edgeJump3 eor #$FF inc a sta <edgeSlopeX mov <edgeSigneX, #$FF bra .edgeJump3 .edgeJump1: ;edgeX0 = edgeX1 ldy <edgeX0 ldx <edgeY0 .edgeLoop0: setEdgeBufferm cpx <edgeY1 beq .edgeJump9 inx bra .edgeLoop0 .edgeJump9: rts .edgeJump3: ;edgeSlope compare lda <edgeSlopeY cmp <edgeSlopeX jcs .edgeJump4 ;edgeSlopeX > edgeSlopeY ;edgeSlope initialize lda <edgeSlopeX eor #$FF inc a ;check edgeSigneX bbs7 <edgeSigneX, .edgeJump10 ;edgeSigneX plus ldy <edgeX0 ldx <edgeY0 .edgeXLoop0: pha setEdgeBufferm pla .edgeXLoop1: cpy <edgeX1 beq .edgeXLoop3 iny adc <edgeSlopeY bcc .edgeXLoop1 sbc <edgeSlopeX inx bra .edgeXLoop0 .edgeXLoop3: rts ;edgeSigneX minus .edgeJump10: ldy <edgeX1 ldx <edgeY1 .edgeXLoop4: pha setEdgeBufferm pla .edgeXLoop5: cpy <edgeX0 beq .edgeXLoop7 iny adc <edgeSlopeY bcc .edgeXLoop5 sbc <edgeSlopeX dex bra .edgeXLoop4 .edgeXLoop7: rts .edgeJump4: ;edgeSlopeY >= edgeSlopeX ;edgeSlope initialize lda <edgeSlopeY eor #$FF inc a ldy <edgeX0 ldx <edgeY0 ;check edgeSigneX bbs7 <edgeSigneX, .edgeYLoop4 ;edgeSigneX plus .edgeYLoop0: pha setEdgeBufferm pla .edgeYLoop1: cpx <edgeY1 beq .edgeYLoop3 inx adc <edgeSlopeX bcc .edgeYLoop0 sbc <edgeSlopeY iny bra .edgeYLoop0 .edgeYLoop3: rts ;edgeSigneX minus .edgeYLoop4: pha setEdgeBufferm pla .edgeYLoop5: cpx <edgeY1 beq .edgeYLoop7 inx adc <edgeSlopeX bcc .edgeYLoop4 sbc <edgeSlopeY dey bra .edgeYLoop4 .edgeYLoop7: rts ;---------------------------- initCalcEdge: ;initialize calculation edge lda #$FF sta edgeCount tii edgeCount, edgeCount+1, 192 rts ;---------------------------- putPolyLine: ;put poly line ldy <minEdgeY bra .loopStart ;loop .loop0: cli iny .loopStart: lda edgeCount, y bpl .putPolyProc rts .putPolyProc: sei ;set poly color tya and #$01 ora <polyLineColorNo tax lda polyLineColorData0, x sta <polyLineColorDataWork0 lda polyLineColorData1, x sta <polyLineColorDataWork1 lda polyLineColorData2, x sta <polyLineColorDataWork2 lda polyLineColorData3, x sta <polyLineColorDataWork3 ;calation vram address ;left ;left address ldx edgeLeft,y lda polyLineAddrConvYLow0, y ora polyLineAddrConvXLow0, x sta <polyLineLeftAddr lda polyLineAddrConvYHigh0, y ora polyLineAddrConvXHigh0, x sta <polyLineLeftAddr+1 lda polyLineAddrConvX, x sta <polyLineCount lda polyLineLeftDatas, x sta <polyLineLeftData eor #$FF sta <polyLineLeftMask ;right ldx edgeRight,y ;calation counts sec lda polyLineAddrConvX, x sbc <polyLineCount ;count 0 jeq .polyLineJump03 sta <polyLineCount ;right address lda polyLineAddrConvYLow0, y ora polyLineAddrConvXLow0, x sta <polyLineRightAddr lda polyLineAddrConvYHigh0, y ora polyLineAddrConvXHigh0, x sta <polyLineRightAddr+1 lda polyLineRightDatas, x sta <polyLineRightData eor #$FF sta <polyLineRightMask ;put line lda <selectVdc cmp #VDC2 jeq .vdc2Jp ;VDC1 .vdc1Jp: stz VPC_6 ;select VDC#1 ;center jump index lda <polyLineCount asl a tax phy ;VDC1 left 0 1 lda <polyLineLeftAddr ldy <polyLineLeftAddr+1 st0 #$00 sta VDC1_2 sty VDC1_3 st0 #$01 sta VDC1_2 sty VDC1_3 st0 #$02 lda VDC1_2 and <polyLineLeftMask sta <polyLineDataLow lda VDC1_3 and <polyLineLeftMask sta <polyLineDataHigh lda <polyLineColorDataWork0 and <polyLineLeftData ora <polyLineDataLow sta VDC1_2 lda <polyLineColorDataWork1 and <polyLineLeftData ora <polyLineDataHigh sta VDC1_3 ;VDC1 center 0 1 lda <polyLineColorDataWork0 ldy <polyLineColorDataWork1 jmp [.centerVDC1_01Addr, x] .centerVDC1_01: putPolyLineV1lm ;VDC1 right 0 1 lda <polyLineRightAddr ldy <polyLineRightAddr+1 st0 #$00 sta VDC1_2 sty VDC1_3 st0 #$01 sta VDC1_2 sty VDC1_3 st0 #$02 lda VDC1_2 and <polyLineRightMask sta <polyLineDataLow lda VDC1_3 and <polyLineRightMask sta <polyLineDataHigh lda <polyLineColorDataWork0 and <polyLineRightData ora <polyLineDataLow sta VDC1_2 lda <polyLineColorDataWork1 and <polyLineRightData ora <polyLineDataHigh sta VDC1_3 ;VDC1 left 2 3 lda <polyLineLeftAddr ora #$08 ldy <polyLineLeftAddr+1 st0 #$00 sta VDC1_2 sty VDC1_3 st0 #$01 sta VDC1_2 sty VDC1_3 st0 #$02 lda VDC1_2 and <polyLineLeftMask sta <polyLineDataLow lda VDC1_3 and <polyLineLeftMask sta <polyLineDataHigh lda <polyLineColorDataWork2 and <polyLineLeftData ora <polyLineDataLow sta VDC1_2 lda <polyLineColorDataWork3 and <polyLineLeftData ora <polyLineDataHigh sta VDC1_3 ;VDC1 center 2 3 lda <polyLineColorDataWork2 ldy <polyLineColorDataWork3 jmp [.centerVDC1_02Addr, x] .centerVDC1_02: putPolyLineV1lm ;VDC1 right 2 3 lda <polyLineRightAddr ora #$08 ldy <polyLineRightAddr+1 st0 #$00 sta VDC1_2 sty VDC1_3 st0 #$01 sta VDC1_2 sty VDC1_3 st0 #$02 lda VDC1_2 and <polyLineRightMask sta <polyLineDataLow lda VDC1_3 and <polyLineRightMask sta <polyLineDataHigh lda <polyLineColorDataWork2 and <polyLineRightData ora <polyLineDataLow sta VDC1_2 lda <polyLineColorDataWork3 and <polyLineRightData ora <polyLineDataHigh sta VDC1_3 ply ;loop jump jmp .loop0 ;VDC2 .vdc2Jp: lda #$01 sta VPC_6 ;select VDC#2 lda <polyLineCount asl a tax phy ;VDC2 left 0 1 lda <polyLineLeftAddr ldy <polyLineLeftAddr+1 st0 #$00 sta VDC2_2 sty VDC2_3 st0 #$01 sta VDC2_2 sty VDC2_3 st0 #$02 lda VDC2_2 and <polyLineLeftMask sta <polyLineDataLow lda VDC2_3 and <polyLineLeftMask sta <polyLineDataHigh lda <polyLineColorDataWork0 and <polyLineLeftData ora <polyLineDataLow sta VDC2_2 lda <polyLineColorDataWork1 and <polyLineLeftData ora <polyLineDataHigh sta VDC2_3 ;VDC2 center 0 1 lda <polyLineColorDataWork0 ldy <polyLineColorDataWork1 jmp [.centerVDC2_01Addr, x] .centerVDC2_01: putPolyLineV2lm ;VDC2 right 0 1 lda <polyLineRightAddr ldy <polyLineRightAddr+1 st0 #$00 sta VDC2_2 sty VDC2_3 st0 #$01 sta VDC2_2 sty VDC2_3 st0 #$02 lda VDC2_2 and <polyLineRightMask sta <polyLineDataLow lda VDC2_3 and <polyLineRightMask sta <polyLineDataHigh lda <polyLineColorDataWork0 and <polyLineRightData ora <polyLineDataLow sta VDC2_2 lda <polyLineColorDataWork1 and <polyLineRightData ora <polyLineDataHigh sta VDC2_3 ;VDC2 left 2 3 lda <polyLineLeftAddr ora #$08 ldy <polyLineLeftAddr+1 st0 #$00 sta VDC2_2 sty VDC2_3 st0 #$01 sta VDC2_2 sty VDC2_3 st0 #$02 lda VDC2_2 and <polyLineLeftMask sta <polyLineDataLow lda VDC2_3 and <polyLineLeftMask sta <polyLineDataHigh lda <polyLineColorDataWork2 and <polyLineLeftData ora <polyLineDataLow sta VDC2_2 lda <polyLineColorDataWork3 and <polyLineLeftData ora <polyLineDataHigh sta VDC2_3 ;VDC2 center 2 3 lda <polyLineColorDataWork2 ldy <polyLineColorDataWork3 jmp [.centerVDC2_02Addr, x] .centerVDC2_02: putPolyLineV2lm ;VDC2 right 2 3 lda <polyLineRightAddr ora #$08 ldy <polyLineRightAddr+1 st0 #$00 sta VDC2_2 sty VDC2_3 st0 #$01 sta VDC2_2 sty VDC2_3 st0 #$02 lda VDC2_2 and <polyLineRightMask sta <polyLineDataLow lda VDC2_3 and <polyLineRightMask sta <polyLineDataHigh lda <polyLineColorDataWork2 and <polyLineRightData ora <polyLineDataLow sta VDC2_2 lda <polyLineColorDataWork3 and <polyLineRightData ora <polyLineDataHigh sta VDC2_3 ply ;loop jump jmp .loop0 ;put line same address .polyLineJump03: lda <polyLineLeftData and polyLineRightDatas,x sta <polyLineLeftData eor #$FF sta <polyLineLeftMask lda <selectVdc cmp #VDC2 beq .vdc2Jp2 ;VDC1 .vdc1Jp2: stz VPC_6 ;select VDC#1 ;VDC1 left 0 1 lda <polyLineLeftAddr ldx <polyLineLeftAddr+1 st0 #$00 sta VDC1_2 stx VDC1_3 st0 #$01 sta VDC1_2 stx VDC1_3 st0 #$02 lda VDC1_2 and <polyLineLeftMask sta <polyLineDataLow lda VDC1_3 and <polyLineLeftMask sta <polyLineDataHigh lda <polyLineColorDataWork0 and <polyLineLeftData ora <polyLineDataLow sta VDC1_2 lda <polyLineColorDataWork1 and <polyLineLeftData ora <polyLineDataHigh sta VDC1_3 ;VDC1 left 2 3 lda <polyLineLeftAddr ora #$08 ldx <polyLineLeftAddr+1 st0 #$00 sta VDC1_2 stx VDC1_3 st0 #$01 sta VDC1_2 stx VDC1_3 st0 #$02 lda VDC1_2 and <polyLineLeftMask sta <polyLineDataLow lda VDC1_3 and <polyLineLeftMask sta <polyLineDataHigh lda <polyLineColorDataWork2 and <polyLineLeftData ora <polyLineDataLow sta VDC1_2 lda <polyLineColorDataWork3 and <polyLineLeftData ora <polyLineDataHigh sta VDC1_3 ;loop jump jmp .loop0 ;VDC2 .vdc2Jp2: lda #$01 sta VPC_6 ;select VDC#2 ;VDC2 left 0 1 lda <polyLineLeftAddr ldx <polyLineLeftAddr+1 st0 #$00 sta VDC2_2 stx VDC2_3 st0 #$01 sta VDC2_2 stx VDC2_3 st0 #$02 lda VDC2_2 and <polyLineLeftMask sta <polyLineDataLow lda VDC2_3 and <polyLineLeftMask sta <polyLineDataHigh lda <polyLineColorDataWork0 and <polyLineLeftData ora <polyLineDataLow sta VDC2_2 lda <polyLineColorDataWork1 and <polyLineLeftData ora <polyLineDataHigh sta VDC2_3 ;VDC2 left 2 3 lda <polyLineLeftAddr ora #$08 ldx <polyLineLeftAddr+1 st0 #$00 sta VDC2_2 stx VDC2_3 st0 #$01 sta VDC2_2 stx VDC2_3 st0 #$02 lda VDC2_2 and <polyLineLeftMask sta <polyLineDataLow lda VDC2_3 and <polyLineLeftMask sta <polyLineDataHigh lda <polyLineColorDataWork2 and <polyLineLeftData ora <polyLineDataLow sta VDC2_2 lda <polyLineColorDataWork3 and <polyLineLeftData ora <polyLineDataHigh sta VDC2_3 ;loop jump jmp .loop0 ;-------- .centerVDC1_01Addr: dw .centerVDC1_01 +6*30 ;-1 dw .centerVDC1_01 +6*30 ;0 dw .centerVDC1_01 +6*29 ;1 dw .centerVDC1_01 +6*28 ;2 dw .centerVDC1_01 +6*27 ;3 dw .centerVDC1_01 +6*26 ;4 dw .centerVDC1_01 +6*25 ;5 dw .centerVDC1_01 +6*24 ;6 dw .centerVDC1_01 +6*23 ;7 dw .centerVDC1_01 +6*22 ;8 dw .centerVDC1_01 +6*21 ;9 dw .centerVDC1_01 +6*20 ;10 dw .centerVDC1_01 +6*19 ;11 dw .centerVDC1_01 +6*18 ;12 dw .centerVDC1_01 +6*17 ;13 dw .centerVDC1_01 +6*16 ;14 dw .centerVDC1_01 +6*15 ;15 dw .centerVDC1_01 +6*14 ;16 dw .centerVDC1_01 +6*13 ;17 dw .centerVDC1_01 +6*12 ;18 dw .centerVDC1_01 +6*11 ;19 dw .centerVDC1_01 +6*10 ;20 dw .centerVDC1_01 +6*9 ;21 dw .centerVDC1_01 +6*8 ;22 dw .centerVDC1_01 +6*7 ;23 dw .centerVDC1_01 +6*6 ;24 dw .centerVDC1_01 +6*5 ;25 dw .centerVDC1_01 +6*4 ;26 dw .centerVDC1_01 +6*3 ;27 dw .centerVDC1_01 +6*2 ;28 dw .centerVDC1_01 +6*1 ;29 dw .centerVDC1_01 +6*0 ;30 ;-------- .centerVDC1_02Addr: dw .centerVDC1_02 +6*30 ;-1 dw .centerVDC1_02 +6*30 ;0 dw .centerVDC1_02 +6*29 ;1 dw .centerVDC1_02 +6*28 ;2 dw .centerVDC1_02 +6*27 ;3 dw .centerVDC1_02 +6*26 ;4 dw .centerVDC1_02 +6*25 ;5 dw .centerVDC1_02 +6*24 ;6 dw .centerVDC1_02 +6*23 ;7 dw .centerVDC1_02 +6*22 ;8 dw .centerVDC1_02 +6*21 ;9 dw .centerVDC1_02 +6*20 ;10 dw .centerVDC1_02 +6*19 ;11 dw .centerVDC1_02 +6*18 ;12 dw .centerVDC1_02 +6*17 ;13 dw .centerVDC1_02 +6*16 ;14 dw .centerVDC1_02 +6*15 ;15 dw .centerVDC1_02 +6*14 ;16 dw .centerVDC1_02 +6*13 ;17 dw .centerVDC1_02 +6*12 ;18 dw .centerVDC1_02 +6*11 ;19 dw .centerVDC1_02 +6*10 ;20 dw .centerVDC1_02 +6*9 ;21 dw .centerVDC1_02 +6*8 ;22 dw .centerVDC1_02 +6*7 ;23 dw .centerVDC1_02 +6*6 ;24 dw .centerVDC1_02 +6*5 ;25 dw .centerVDC1_02 +6*4 ;26 dw .centerVDC1_02 +6*3 ;27 dw .centerVDC1_02 +6*2 ;28 dw .centerVDC1_02 +6*1 ;29 dw .centerVDC1_02 +6*0 ;30 ;-------- .centerVDC2_01Addr: dw .centerVDC2_01 +6*30 ;-1 dw .centerVDC2_01 +6*30 ;0 dw .centerVDC2_01 +6*29 ;1 dw .centerVDC2_01 +6*28 ;2 dw .centerVDC2_01 +6*27 ;3 dw .centerVDC2_01 +6*26 ;4 dw .centerVDC2_01 +6*25 ;5 dw .centerVDC2_01 +6*24 ;6 dw .centerVDC2_01 +6*23 ;7 dw .centerVDC2_01 +6*22 ;8 dw .centerVDC2_01 +6*21 ;9 dw .centerVDC2_01 +6*20 ;10 dw .centerVDC2_01 +6*19 ;11 dw .centerVDC2_01 +6*18 ;12 dw .centerVDC2_01 +6*17 ;13 dw .centerVDC2_01 +6*16 ;14 dw .centerVDC2_01 +6*15 ;15 dw .centerVDC2_01 +6*14 ;16 dw .centerVDC2_01 +6*13 ;17 dw .centerVDC2_01 +6*12 ;18 dw .centerVDC2_01 +6*11 ;19 dw .centerVDC2_01 +6*10 ;20 dw .centerVDC2_01 +6*9 ;21 dw .centerVDC2_01 +6*8 ;22 dw .centerVDC2_01 +6*7 ;23 dw .centerVDC2_01 +6*6 ;24 dw .centerVDC2_01 +6*5 ;25 dw .centerVDC2_01 +6*4 ;26 dw .centerVDC2_01 +6*3 ;27 dw .centerVDC2_01 +6*2 ;28 dw .centerVDC2_01 +6*1 ;29 dw .centerVDC2_01 +6*0 ;30 ;-------- .centerVDC2_02Addr: dw .centerVDC2_02 +6*30 ;-1 dw .centerVDC2_02 +6*30 ;0 dw .centerVDC2_02 +6*29 ;1 dw .centerVDC2_02 +6*28 ;2 dw .centerVDC2_02 +6*27 ;3 dw .centerVDC2_02 +6*26 ;4 dw .centerVDC2_02 +6*25 ;5 dw .centerVDC2_02 +6*24 ;6 dw .centerVDC2_02 +6*23 ;7 dw .centerVDC2_02 +6*22 ;8 dw .centerVDC2_02 +6*21 ;9 dw .centerVDC2_02 +6*20 ;10 dw .centerVDC2_02 +6*19 ;11 dw .centerVDC2_02 +6*18 ;12 dw .centerVDC2_02 +6*17 ;13 dw .centerVDC2_02 +6*16 ;14 dw .centerVDC2_02 +6*15 ;15 dw .centerVDC2_02 +6*14 ;16 dw .centerVDC2_02 +6*13 ;17 dw .centerVDC2_02 +6*12 ;18 dw .centerVDC2_02 +6*11 ;19 dw .centerVDC2_02 +6*10 ;20 dw .centerVDC2_02 +6*9 ;21 dw .centerVDC2_02 +6*8 ;22 dw .centerVDC2_02 +6*7 ;23 dw .centerVDC2_02 +6*6 ;24 dw .centerVDC2_02 +6*5 ;25 dw .centerVDC2_02 +6*4 ;26 dw .centerVDC2_02 +6*3 ;27 dw .centerVDC2_02 +6*2 ;28 dw .centerVDC2_02 +6*1 ;29 dw .centerVDC2_02 +6*0 ;30 ;---------------------------- setBAT: ;set BAT mov VDC1_0, #$00 movw VDC1_2, #$0000 mov VDC1_0, #$02 mov VDC2_0, #$00 movw VDC2_2, #$0000 mov VDC2_0, #$02 movw <setBatWork, #$0400 .clearbatloop0: movw VDC1_2, <setBatWork movw VDC2_2, <setBatWork addw <setBatWork, #$0002 cmpw <setBatWork, #$0800 bcc .clearbatloop0 movw <setBatWork, #$0401 .clearbatloop1: movw VDC1_2, <setBatWork movw VDC2_2, <setBatWork addw <setBatWork, #$0002 cmpw <setBatWork, #$0801 bcc .clearbatloop1 rts ;//////////////////////////// .bank 2 .org $C000 ;---------------------------- polyLineAddrConvYHigh0: .db $40, $40, $40, $40, $40, $40, $40, $40, $44, $44, $44, $44, $44, $44, $44, $44,\ $48, $48, $48, $48, $48, $48, $48, $48, $4C, $4C, $4C, $4C, $4C, $4C, $4C, $4C,\ $50, $50, $50, $50, $50, $50, $50, $50, $54, $54, $54, $54, $54, $54, $54, $54,\ $58, $58, $58, $58, $58, $58, $58, $58, $5C, $5C, $5C, $5C, $5C, $5C, $5C, $5C,\ $60, $60, $60, $60, $60, $60, $60, $60, $64, $64, $64, $64, $64, $64, $64, $64,\ $68, $68, $68, $68, $68, $68, $68, $68, $6C, $6C, $6C, $6C, $6C, $6C, $6C, $6C,\ $70, $70, $70, $70, $70, $70, $70, $70, $74, $74, $74, $74, $74, $74, $74, $74,\ $78, $78, $78, $78, $78, $78, $78, $78, $7C, $7C, $7C, $7C, $7C, $7C, $7C, $7C,\ $40, $40, $40, $40, $40, $40, $40, $40, $44, $44, $44, $44, $44, $44, $44, $44,\ $48, $48, $48, $48, $48, $48, $48, $48, $4C, $4C, $4C, $4C, $4C, $4C, $4C, $4C,\ $50, $50, $50, $50, $50, $50, $50, $50, $54, $54, $54, $54, $54, $54, $54, $54,\ $58, $58, $58, $58, $58, $58, $58, $58, $5C, $5C, $5C, $5C, $5C, $5C, $5C, $5C,\ $60, $60, $60, $60, $60, $60, $60, $60, $64, $64, $64, $64, $64, $64, $64, $64,\ $68, $68, $68, $68, $68, $68, $68, $68, $6C, $6C, $6C, $6C, $6C, $6C, $6C, $6C,\ $70, $70, $70, $70, $70, $70, $70, $70, $74, $74, $74, $74, $74, $74, $74, $74,\ $78, $78, $78, $78, $78, $78, $78, $78, $7C, $7C, $7C, $7C, $7C, $7C, $7C, $7C ;---------------------------- polyLineAddrConvYLow0: .db $00, $01, $02, $03, $04, $05, $06, $07, $00, $01, $02, $03, $04, $05, $06, $07,\ $00, $01, $02, $03, $04, $05, $06, $07, $00, $01, $02, $03, $04, $05, $06, $07,\ $00, $01, $02, $03, $04, $05, $06, $07, $00, $01, $02, $03, $04, $05, $06, $07,\ $00, $01, $02, $03, $04, $05, $06, $07, $00, $01, $02, $03, $04, $05, $06, $07,\ $00, $01, $02, $03, $04, $05, $06, $07, $00, $01, $02, $03, $04, $05, $06, $07,\ $00, $01, $02, $03, $04, $05, $06, $07, $00, $01, $02, $03, $04, $05, $06, $07,\ $00, $01, $02, $03, $04, $05, $06, $07, $00, $01, $02, $03, $04, $05, $06, $07,\ $00, $01, $02, $03, $04, $05, $06, $07, $00, $01, $02, $03, $04, $05, $06, $07,\ $10, $11, $12, $13, $14, $15, $16, $17, $10, $11, $12, $13, $14, $15, $16, $17,\ $10, $11, $12, $13, $14, $15, $16, $17, $10, $11, $12, $13, $14, $15, $16, $17,\ $10, $11, $12, $13, $14, $15, $16, $17, $10, $11, $12, $13, $14, $15, $16, $17,\ $10, $11, $12, $13, $14, $15, $16, $17, $10, $11, $12, $13, $14, $15, $16, $17,\ $10, $11, $12, $13, $14, $15, $16, $17, $10, $11, $12, $13, $14, $15, $16, $17,\ $10, $11, $12, $13, $14, $15, $16, $17, $10, $11, $12, $13, $14, $15, $16, $17,\ $10, $11, $12, $13, $14, $15, $16, $17, $10, $11, $12, $13, $14, $15, $16, $17,\ $10, $11, $12, $13, $14, $15, $16, $17, $10, $11, $12, $13, $14, $15, $16, $17 ;---------------------------- polyLineAddrConvXHigh0: .db $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\ $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\ $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\ $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\ $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01,\ $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01,\ $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01,\ $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01,\ $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02,\ $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02,\ $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02,\ $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02,\ $03, $03, $03, $03, $03, $03, $03, $03, $03, $03, $03, $03, $03, $03, $03, $03,\ $03, $03, $03, $03, $03, $03, $03, $03, $03, $03, $03, $03, $03, $03, $03, $03,\ $03, $03, $03, $03, $03, $03, $03, $03, $03, $03, $03, $03, $03, $03, $03, $03,\ $03, $03, $03, $03, $03, $03, $03, $03, $03, $03, $03, $03, $03, $03, $03, $03 ;---------------------------- polyLineAddrConvXLow0: .db $00, $00, $00, $00, $00, $00, $00, $00, $20, $20, $20, $20, $20, $20, $20, $20,\ $40, $40, $40, $40, $40, $40, $40, $40, $60, $60, $60, $60, $60, $60, $60, $60,\ $80, $80, $80, $80, $80, $80, $80, $80, $A0, $A0, $A0, $A0, $A0, $A0, $A0, $A0,\ $C0, $C0, $C0, $C0, $C0, $C0, $C0, $C0, $E0, $E0, $E0, $E0, $E0, $E0, $E0, $E0,\ $00, $00, $00, $00, $00, $00, $00, $00, $20, $20, $20, $20, $20, $20, $20, $20,\ $40, $40, $40, $40, $40, $40, $40, $40, $60, $60, $60, $60, $60, $60, $60, $60,\ $80, $80, $80, $80, $80, $80, $80, $80, $A0, $A0, $A0, $A0, $A0, $A0, $A0, $A0,\ $C0, $C0, $C0, $C0, $C0, $C0, $C0, $C0, $E0, $E0, $E0, $E0, $E0, $E0, $E0, $E0,\ $00, $00, $00, $00, $00, $00, $00, $00, $20, $20, $20, $20, $20, $20, $20, $20,\ $40, $40, $40, $40, $40, $40, $40, $40, $60, $60, $60, $60, $60, $60, $60, $60,\ $80, $80, $80, $80, $80, $80, $80, $80, $A0, $A0, $A0, $A0, $A0, $A0, $A0, $A0,\ $C0, $C0, $C0, $C0, $C0, $C0, $C0, $C0, $E0, $E0, $E0, $E0, $E0, $E0, $E0, $E0,\ $00, $00, $00, $00, $00, $00, $00, $00, $20, $20, $20, $20, $20, $20, $20, $20,\ $40, $40, $40, $40, $40, $40, $40, $40, $60, $60, $60, $60, $60, $60, $60, $60,\ $80, $80, $80, $80, $80, $80, $80, $80, $A0, $A0, $A0, $A0, $A0, $A0, $A0, $A0,\ $C0, $C0, $C0, $C0, $C0, $C0, $C0, $C0, $E0, $E0, $E0, $E0, $E0, $E0, $E0, $E0 ;---------------------------- polyLineAddrConvX: .db $00, $00, $00, $00, $00, $00, $00, $00, $01, $01, $01, $01, $01, $01, $01, $01,\ $02, $02, $02, $02, $02, $02, $02, $02, $03, $03, $03, $03, $03, $03, $03, $03,\ $04, $04, $04, $04, $04, $04, $04, $04, $05, $05, $05, $05, $05, $05, $05, $05,\ $06, $06, $06, $06, $06, $06, $06, $06, $07, $07, $07, $07, $07, $07, $07, $07,\ $08, $08, $08, $08, $08, $08, $08, $08, $09, $09, $09, $09, $09, $09, $09, $09,\ $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0B, $0B, $0B, $0B, $0B, $0B, $0B, $0B,\ $0C, $0C, $0C, $0C, $0C, $0C, $0C, $0C, $0D, $0D, $0D, $0D, $0D, $0D, $0D, $0D,\ $0E, $0E, $0E, $0E, $0E, $0E, $0E, $0E, $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F,\ $10, $10, $10, $10, $10, $10, $10, $10, $11, $11, $11, $11, $11, $11, $11, $11,\ $12, $12, $12, $12, $12, $12, $12, $12, $13, $13, $13, $13, $13, $13, $13, $13,\ $14, $14, $14, $14, $14, $14, $14, $14, $15, $15, $15, $15, $15, $15, $15, $15,\ $16, $16, $16, $16, $16, $16, $16, $16, $17, $17, $17, $17, $17, $17, $17, $17,\ $18, $18, $18, $18, $18, $18, $18, $18, $19, $19, $19, $19, $19, $19, $19, $19,\ $1A, $1A, $1A, $1A, $1A, $1A, $1A, $1A, $1B, $1B, $1B, $1B, $1B, $1B, $1B, $1B,\ $1C, $1C, $1C, $1C, $1C, $1C, $1C, $1C, $1D, $1D, $1D, $1D, $1D, $1D, $1D, $1D,\ $1E, $1E, $1E, $1E, $1E, $1E, $1E, $1E, $1F, $1F, $1F, $1F, $1F, $1F, $1F, $1F ;---------------------------- polyLineLeftDatas: .db $FF, $7F, $3F, $1F, $0F, $07, $03, $01, $FF, $7F, $3F, $1F, $0F, $07, $03, $01,\ $FF, $7F, $3F, $1F, $0F, $07, $03, $01, $FF, $7F, $3F, $1F, $0F, $07, $03, $01,\ $FF, $7F, $3F, $1F, $0F, $07, $03, $01, $FF, $7F, $3F, $1F, $0F, $07, $03, $01,\ $FF, $7F, $3F, $1F, $0F, $07, $03, $01, $FF, $7F, $3F, $1F, $0F, $07, $03, $01,\ $FF, $7F, $3F, $1F, $0F, $07, $03, $01, $FF, $7F, $3F, $1F, $0F, $07, $03, $01,\ $FF, $7F, $3F, $1F, $0F, $07, $03, $01, $FF, $7F, $3F, $1F, $0F, $07, $03, $01,\ $FF, $7F, $3F, $1F, $0F, $07, $03, $01, $FF, $7F, $3F, $1F, $0F, $07, $03, $01,\ $FF, $7F, $3F, $1F, $0F, $07, $03, $01, $FF, $7F, $3F, $1F, $0F, $07, $03, $01,\ $FF, $7F, $3F, $1F, $0F, $07, $03, $01, $FF, $7F, $3F, $1F, $0F, $07, $03, $01,\ $FF, $7F, $3F, $1F, $0F, $07, $03, $01, $FF, $7F, $3F, $1F, $0F, $07, $03, $01,\ $FF, $7F, $3F, $1F, $0F, $07, $03, $01, $FF, $7F, $3F, $1F, $0F, $07, $03, $01,\ $FF, $7F, $3F, $1F, $0F, $07, $03, $01, $FF, $7F, $3F, $1F, $0F, $07, $03, $01,\ $FF, $7F, $3F, $1F, $0F, $07, $03, $01, $FF, $7F, $3F, $1F, $0F, $07, $03, $01,\ $FF, $7F, $3F, $1F, $0F, $07, $03, $01, $FF, $7F, $3F, $1F, $0F, $07, $03, $01,\ $FF, $7F, $3F, $1F, $0F, $07, $03, $01, $FF, $7F, $3F, $1F, $0F, $07, $03, $01,\ $FF, $7F, $3F, $1F, $0F, $07, $03, $01, $FF, $7F, $3F, $1F, $0F, $07, $03, $01 ;---------------------------- polyLineRightDatas: .db $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF, $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF,\ $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF, $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF,\ $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF, $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF,\ $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF, $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF,\ $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF, $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF,\ $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF, $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF,\ $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF, $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF,\ $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF, $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF,\ $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF, $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF,\ $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF, $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF,\ $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF, $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF,\ $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF, $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF,\ $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF, $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF,\ $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF, $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF,\ $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF, $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF,\ $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF, $80, $C0, $E0, $F0, $F8, $FC, $FE, $FF ;---------------------------- polyLineColorData0: .db $00, $00, $FF, $FF, $00, $00, $FF, $FF, $00, $00, $FF, $FF, $00, $00, $FF, $FF,\ $00, $00, $FF, $FF, $00, $00, $FF, $FF, $00, $00, $FF, $FF, $00, $00, $FF, $FF,\ $00, $00, $FF, $FF, $00, $00, $FF, $FF, $00, $00, $FF, $FF, $00, $00, $FF, $FF,\ $00, $00, $55, $AA, $FF, $FF, $55, $AA, $00, $00, $AA, $55, $FF, $FF, $FF, $FF ;---------------------------- polyLineColorData1: .db $00, $00, $00, $00, $FF, $FF, $FF, $FF, $00, $00, $00, $00, $FF, $FF, $FF, $FF,\ $00, $00, $00, $00, $FF, $FF, $FF, $FF, $00, $00, $00, $00, $FF, $FF, $FF, $FF,\ $00, $00, $00, $00, $FF, $FF, $FF, $FF, $00, $00, $00, $00, $FF, $FF, $FF, $FF,\ $00, $00, $55, $AA, $FF, $FF, $55, $AA, $00, $00, $AA, $55, $FF, $FF, $FF, $FF ;---------------------------- polyLineColorData2: .db $00, $00, $00, $00, $00, $00, $00, $00, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\ $00, $00, $00, $00, $00, $00, $00, $00, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\ $00, $00, $00, $00, $00, $00, $00, $00, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\ $00, $00, $55, $AA, $FF, $FF, $55, $AA, $00, $00, $AA, $55, $FF, $FF, $FF, $FF ;---------------------------- polyLineColorData3: .db $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\ $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\ $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\ $00, $00, $00, $00, $00, $00, $AA, $55, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF ;---------------------------- sinDataHigh: .db $00, $01, $03, $04, $06, $07, $09, $0A, $0C, $0E, $0F, $11, $12, $14, $15, $17,\ $18, $19, $1B, $1C, $1E, $1F, $20, $22, $23, $24, $26, $27, $28, $29, $2A, $2C,\ $2D, $2E, $2F, $30, $31, $32, $33, $34, $35, $36, $36, $37, $38, $39, $39, $3A,\ $3B, $3B, $3C, $3C, $3D, $3D, $3E, $3E, $3E, $3F, $3F, $3F, $3F, $3F, $3F, $3F,\ $40, $3F, $3F, $3F, $3F, $3F, $3F, $3F, $3E, $3E, $3E, $3D, $3D, $3C, $3C, $3B,\ $3B, $3A, $39, $39, $38, $37, $36, $36, $35, $34, $33, $32, $31, $30, $2F, $2E,\ $2D, $2C, $2A, $29, $28, $27, $26, $24, $23, $22, $20, $1F, $1E, $1C, $1B, $19,\ $18, $17, $15, $14, $12, $11, $0F, $0E, $0C, $0A, $09, $07, $06, $04, $03, $01,\ $00, $FE, $FC, $FB, $F9, $F8, $F6, $F5, $F3, $F1, $F0, $EE, $ED, $EB, $EA, $E8,\ $E7, $E6, $E4, $E3, $E1, $E0, $DF, $DD, $DC, $DB, $D9, $D8, $D7, $D6, $D5, $D3,\ $D2, $D1, $D0, $CF, $CE, $CD, $CC, $CB, $CA, $C9, $C9, $C8, $C7, $C6, $C6, $C5,\ $C4, $C4, $C3, $C3, $C2, $C2, $C1, $C1, $C1, $C0, $C0, $C0, $C0, $C0, $C0, $C0,\ $C0, $C0, $C0, $C0, $C0, $C0, $C0, $C0, $C1, $C1, $C1, $C2, $C2, $C3, $C3, $C4,\ $C4, $C5, $C6, $C6, $C7, $C8, $C9, $C9, $CA, $CB, $CC, $CD, $CE, $CF, $D0, $D1,\ $D2, $D3, $D5, $D6, $D7, $D8, $D9, $DB, $DC, $DD, $DF, $E0, $E1, $E3, $E4, $E6,\ $E7, $E8, $EA, $EB, $ED, $EE, $F0, $F1, $F3, $F5, $F6, $F8, $F9, $FB, $FC, $FE ;---------------------------- sinDataLow: .db $00, $92, $24, $B5, $46, $D6, $64, $F1, $7C, $06, $8D, $12, $94, $13, $90, $09,\ $7E, $EF, $5D, $C6, $2B, $8C, $E7, $3D, $8E, $DA, $20, $60, $9A, $CE, $FB, $21,\ $41, $5A, $6C, $76, $79, $74, $68, $53, $37, $12, $E5, $B0, $71, $2B, $DB, $82,\ $21, $B6, $42, $C5, $3F, $AF, $15, $72, $C5, $0F, $4F, $85, $B1, $D4, $EC, $FB,\ $00, $FB, $EC, $D4, $B1, $85, $4F, $0F, $C5, $72, $15, $AF, $3F, $C5, $42, $B6,\ $21, $82, $DB, $2B, $71, $B0, $E5, $12, $37, $53, $68, $74, $79, $76, $6C, $5A,\ $41, $21, $FB, $CE, $9A, $60, $20, $DA, $8E, $3D, $E7, $8C, $2B, $C6, $5D, $EF,\ $7E, $09, $90, $13, $94, $12, $8D, $06, $7C, $F1, $64, $D6, $46, $B5, $24, $92,\ $00, $6E, $DC, $4B, $BA, $2A, $9C, $0F, $84, $FA, $73, $EE, $6C, $ED, $70, $F7,\ $82, $11, $A3, $3A, $D5, $74, $19, $C3, $72, $26, $E0, $A0, $66, $32, $05, $DF,\ $BF, $A6, $94, $8A, $87, $8C, $98, $AD, $C9, $EE, $1B, $50, $8F, $D5, $25, $7E,\ $DF, $4A, $BE, $3B, $C1, $51, $EB, $8E, $3B, $F1, $B1, $7B, $4F, $2C, $14, $05,\ $00, $05, $14, $2C, $4F, $7B, $B1, $F1, $3B, $8E, $EB, $51, $C1, $3B, $BE, $4A,\ $DF, $7E, $25, $D5, $8F, $50, $1B, $EE, $C9, $AD, $98, $8C, $87, $8A, $94, $A6,\ $BF, $DF, $05, $32, $66, $A0, $E0, $26, $72, $C3, $19, $74, $D5, $3A, $A3, $11,\ $82, $F7, $70, $ED, $6C, $EE, $73, $FA, $84, $0F, $9C, $2A, $BA, $4B, $DC, $6E ;---------------------------- cosDataHigh: .db $40, $3F, $3F, $3F, $3F, $3F, $3F, $3F, $3E, $3E, $3E, $3D, $3D, $3C, $3C, $3B,\ $3B, $3A, $39, $39, $38, $37, $36, $36, $35, $34, $33, $32, $31, $30, $2F, $2E,\ $2D, $2C, $2A, $29, $28, $27, $26, $24, $23, $22, $20, $1F, $1E, $1C, $1B, $19,\ $18, $17, $15, $14, $12, $11, $0F, $0E, $0C, $0A, $09, $07, $06, $04, $03, $01,\ $00, $FE, $FC, $FB, $F9, $F8, $F6, $F5, $F3, $F1, $F0, $EE, $ED, $EB, $EA, $E8,\ $E7, $E6, $E4, $E3, $E1, $E0, $DF, $DD, $DC, $DB, $D9, $D8, $D7, $D6, $D5, $D3,\ $D2, $D1, $D0, $CF, $CE, $CD, $CC, $CB, $CA, $C9, $C9, $C8, $C7, $C6, $C6, $C5,\ $C4, $C4, $C3, $C3, $C2, $C2, $C1, $C1, $C1, $C0, $C0, $C0, $C0, $C0, $C0, $C0,\ $C0, $C0, $C0, $C0, $C0, $C0, $C0, $C0, $C1, $C1, $C1, $C2, $C2, $C3, $C3, $C4,\ $C4, $C5, $C6, $C6, $C7, $C8, $C9, $C9, $CA, $CB, $CC, $CD, $CE, $CF, $D0, $D1,\ $D2, $D3, $D5, $D6, $D7, $D8, $D9, $DB, $DC, $DD, $DF, $E0, $E1, $E3, $E4, $E6,\ $E7, $E8, $EA, $EB, $ED, $EE, $F0, $F1, $F3, $F5, $F6, $F8, $F9, $FB, $FC, $FE,\ $00, $01, $03, $04, $06, $07, $09, $0A, $0C, $0E, $0F, $11, $12, $14, $15, $17,\ $18, $19, $1B, $1C, $1E, $1F, $20, $22, $23, $24, $26, $27, $28, $29, $2A, $2C,\ $2D, $2E, $2F, $30, $31, $32, $33, $34, $35, $36, $36, $37, $38, $39, $39, $3A,\ $3B, $3B, $3C, $3C, $3D, $3D, $3E, $3E, $3E, $3F, $3F, $3F, $3F, $3F, $3F, $3F ;---------------------------- cosDataLow: .db $00, $FB, $EC, $D4, $B1, $85, $4F, $0F, $C5, $72, $15, $AF, $3F, $C5, $42, $B6,\ $21, $82, $DB, $2B, $71, $B0, $E5, $12, $37, $53, $68, $74, $79, $76, $6C, $5A,\ $41, $21, $FB, $CE, $9A, $60, $20, $DA, $8E, $3D, $E7, $8C, $2B, $C6, $5D, $EF,\ $7E, $09, $90, $13, $94, $12, $8D, $06, $7C, $F1, $64, $D6, $46, $B5, $24, $92,\ $00, $6E, $DC, $4B, $BA, $2A, $9C, $0F, $84, $FA, $73, $EE, $6C, $ED, $70, $F7,\ $82, $11, $A3, $3A, $D5, $74, $19, $C3, $72, $26, $E0, $A0, $66, $32, $05, $DF,\ $BF, $A6, $94, $8A, $87, $8C, $98, $AD, $C9, $EE, $1B, $50, $8F, $D5, $25, $7E,\ $DF, $4A, $BE, $3B, $C1, $51, $EB, $8E, $3B, $F1, $B1, $7B, $4F, $2C, $14, $05,\ $00, $05, $14, $2C, $4F, $7B, $B1, $F1, $3B, $8E, $EB, $51, $C1, $3B, $BE, $4A,\ $DF, $7E, $25, $D5, $8F, $50, $1B, $EE, $C9, $AD, $98, $8C, $87, $8A, $94, $A6,\ $BF, $DF, $05, $32, $66, $A0, $E0, $26, $72, $C3, $19, $74, $D5, $3A, $A3, $11,\ $82, $F7, $70, $ED, $6C, $EE, $73, $FA, $84, $0F, $9C, $2A, $BA, $4B, $DC, $6E,\ $00, $92, $24, $B5, $46, $D6, $64, $F1, $7C, $06, $8D, $12, $94, $13, $90, $09,\ $7E, $EF, $5D, $C6, $2B, $8C, $E7, $3D, $8E, $DA, $20, $60, $9A, $CE, $FB, $21,\ $41, $5A, $6C, $76, $79, $74, $68, $53, $37, $12, $E5, $B0, $71, $2B, $DB, $82,\ $21, $B6, $42, $C5, $3F, $AF, $15, $72, $C5, $0F, $4F, $85, $B1, $D4, $EC, $FB ;//////////////////////////// .bank 3 INCBIN "char.dat" ; 8K 3 $03 INCBIN "mul.dat" ; 128K 4~19 $04~$13 INCBIN "div.dat" ; 96K 20~31 $14~$1F
; A216913: a(n) = Gauss_primorial(3*n, 3) / Gauss_primorial(3*n, 3*n). ; 1,2,1,2,5,2,7,2,1,10,11,2,13,14,5,2,17,2,19,10,7,22,23,2,5,26,1,14,29,10,31,2,11,34,35,2,37,38,13,10,41,14,43,22,5,46,47,2,7,10,17,26,53,2,55,14,19,58,59,10,61,62,7,2,65,22,67,34,23,70,71,2,73,74,5,38,77,26,79,10,1,82,83,14,85,86,29,22,89,10,91,46,31,94,95,2,97,14,11,10 seq $0,7947 ; Largest squarefree number dividing n: the squarefree kernel of n, rad(n), radical of n. dif $0,3
; A168547: a(n) = 1 - 2*n^2 + 4*n*(1 + 2*n^2)/3. ; 1,3,17,59,145,291,513,827,1249,1795,2481,3323,4337,5539,6945,8571,10433,12547,14929,17595,20561,23843,27457,31419,35745,40451,45553,51067,57009,63395,70241,77563,85377,93699,102545,111931,121873,132387,143489,155195,167521,180483,194097,208379,223345,239011,255393,272507,290369,308995,328401,348603,369617,391459,414145,437691,462113,487427,513649,540795,568881,597923,627937,658939,690945,723971,758033,793147,829329,866595,904961,944443,985057,1026819,1069745,1113851,1159153,1205667,1253409 mul $0,4 mov $1,$0 bin $0,3 add $0,$1 div $0,8 mul $0,2 add $0,1
.global s_prepare_buffers s_prepare_buffers: push %r13 push %r14 push %r15 push %rbx push %rcx push %rdi push %rsi lea addresses_normal_ht+0x250c, %rsi lea addresses_A_ht+0x8e8c, %rdi clflush (%rsi) and %r15, %r15 mov $8, %rcx rep movsw nop nop nop nop nop and %rcx, %rcx lea addresses_WT_ht+0x16d0c, %r14 sub $29435, %rbx movl $0x61626364, (%r14) add $61641, %rsi lea addresses_WT_ht+0xcfcc, %rcx nop nop nop nop cmp %rdi, %rdi mov (%rcx), %r14w nop and %rdi, %rdi pop %rsi pop %rdi pop %rcx pop %rbx pop %r15 pop %r14 pop %r13 ret .global s_faulty_load s_faulty_load: push %r14 push %rax push %rcx push %rdi push %rdx push %rsi // REPMOV lea addresses_WT+0x1018c, %rsi lea addresses_PSE+0x22cc, %rdi nop nop nop xor %rdx, %rdx mov $4, %rcx rep movsw nop nop sub $49057, %r14 // Store lea addresses_PSE+0x1d0c, %rdi nop nop nop nop nop inc %rdx mov $0x5152535455565758, %r14 movq %r14, %xmm2 movups %xmm2, (%rdi) nop nop dec %rax // Faulty Load lea addresses_PSE+0x1d0c, %rax nop nop nop nop nop cmp $3728, %r14 movups (%rax), %xmm2 vpextrq $0, %xmm2, %rdi lea oracles, %rdx and $0xff, %rdi shlq $12, %rdi mov (%rdx,%rdi,1), %rdi pop %rsi pop %rdx pop %rdi pop %rcx pop %rax pop %r14 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 1, 'type': 'addresses_PSE', 'congruent': 0}} {'dst': {'same': False, 'congruent': 4, 'type': 'addresses_PSE'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 3, 'type': 'addresses_WT'}} {'dst': {'same': True, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_PSE', 'congruent': 0}, 'OP': 'STOR'} [Faulty Load] {'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_PSE', 'congruent': 0}} <gen_prepare_buffer> {'dst': {'same': False, 'congruent': 4, 'type': 'addresses_A_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 11, 'type': 'addresses_normal_ht'}} {'dst': {'same': True, 'NT': False, 'AVXalign': False, 'size': 4, 'type': 'addresses_WT_ht', 'congruent': 9}, 'OP': 'STOR'} {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_WT_ht', 'congruent': 3}} {'58': 21829} 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 */
; ; ; Z88 Maths Routines ; ; C Interface for Small C+ Compiler ; ; 7/12/98 djm ;double cos(double) ;Number in FA.. INCLUDE "fpp.def" PUBLIC cos EXTERN fsetup EXTERN stkequ2 .cos call fsetup fpp(FP_COS) jp stkequ2
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r15 push %rax push %rbp push %rcx push %rdi push %rdx push %rsi lea addresses_normal_ht+0x2067, %rbp nop dec %rcx mov $0x6162636465666768, %r10 movq %r10, %xmm0 movups %xmm0, (%rbp) add %rax, %rax lea addresses_A_ht+0x1417f, %rdi cmp $38618, %r15 movb $0x61, (%rdi) nop nop nop nop and $38703, %rdx lea addresses_A_ht+0x10a67, %rdi nop nop nop nop sub %r15, %r15 vmovups (%rdi), %ymm7 vextracti128 $1, %ymm7, %xmm7 vpextrq $1, %xmm7, %rax nop xor $63616, %rdx lea addresses_UC_ht+0xf867, %rsi lea addresses_A_ht+0x7067, %rdi nop nop nop nop add $21941, %r15 mov $124, %rcx rep movsl nop nop nop nop nop dec %rcx lea addresses_WC_ht+0x19aa7, %r10 nop nop nop nop inc %rbp mov (%r10), %ecx nop cmp $37353, %rax lea addresses_D_ht+0x13867, %rsi nop xor $52021, %r15 movups (%rsi), %xmm6 vpextrq $1, %xmm6, %rdi nop add $24737, %rsi pop %rsi pop %rdx pop %rdi pop %rcx pop %rbp pop %rax pop %r15 pop %r10 ret .global s_faulty_load s_faulty_load: push %r10 push %r13 push %r14 push %rax push %rbx push %rcx // Faulty Load lea addresses_RW+0xa067, %rbx nop cmp $1699, %r10 mov (%rbx), %r13w lea oracles, %rbx and $0xff, %r13 shlq $12, %r13 mov (%rbx,%r13,1), %r13 pop %rcx pop %rbx pop %rax pop %r14 pop %r13 pop %r10 ret /* <gen_faulty_load> [REF] {'src': {'type': 'addresses_RW', 'same': False, 'size': 32, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} [Faulty Load] {'src': {'type': 'addresses_RW', 'same': True, 'size': 2, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} <gen_prepare_buffer> {'dst': {'type': 'addresses_normal_ht', 'same': False, 'size': 16, 'congruent': 11, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'dst': {'type': 'addresses_A_ht', 'same': False, 'size': 1, 'congruent': 3, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'src': {'type': 'addresses_A_ht', 'same': True, 'size': 32, 'congruent': 6, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_UC_ht', 'congruent': 9, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 11, 'same': False}, 'OP': 'REPM'} {'src': {'type': 'addresses_WC_ht', 'same': False, 'size': 4, 'congruent': 6, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_D_ht', 'same': False, 'size': 16, 'congruent': 10, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'32': 21829} 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 */
<% from pwnlib.shellcraft.mips.linux import syscall %> <%page args="fd, buf, n, flags, addr, addr_len"/> <%docstring> Invokes the syscall recvfrom. See 'man 2 recvfrom' for more information. Arguments: fd(int): fd buf(void): buf n(size_t): n flags(int): flags addr(SOCKADDR_ARG): addr addr_len(socklen_t): addr_len </%docstring> ${syscall('SYS_recvfrom', fd, buf, n, flags, addr, addr_len)}
; ; This file contains the splash screen code and bitmap ; [bits 32] global show_splash extern keys %define KEY_ENTER 0x1C section .text ; void show_splash() ; Show splash screen and wait for user to press ENTER show_splash: push ecx push esi push edi mov ecx, 64000 ; 320 x 200 pixels mov esi, splash_bitmap ; Source address mov edi, 0xa0000 ; Destination address (VGA buffer) write_pixel: sub byte [esi], 0x30 ; Subtract '0' from value movsb dec ecx cmp ecx, 0 jne write_pixel ; Ignore first ENTER press (leftover from GRUB menu) ignore_grub_enter: cmp byte [keys + KEY_ENTER], 0 je ignore_grub_enter mov byte [keys + KEY_ENTER], 0 ; Wait for user to press ENTER to continue wait_enter2: cmp byte [keys + KEY_ENTER], 0 je wait_enter2 pop edi pop esi pop ecx ret section .data ; This is the bitmap data of the splash screen (320x200 pixels, palette colored) ; Each pixel value is subtracted by '0' (0x30) to get the palette index splash_bitmap db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000010000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000100000100000000000000000100000000000000011100000000000000000000000000100000000000000000000000000000111000000000000100000000000000000000000000100000000000000000000000000000000000000000000000000" db "00000000000010001000100000010000000000000000000000000000000100000000000010000010000000000000000001000000000000000000000000000000100000100000000000001000100000000000000100000000000001000000100000100000000000000000000000000000000100100000000000100000000000000000000001000100000000000100000000000000000000000000000000000000" db "00000000000010001000100000010000000000000000000000000000000100000000000011000110000000000000000010100000000000000000000000000000100000100000000000001000100000000000000100000000000001000000110001100000000000000000000000000000000100100000000000100000000000000000000001000100000000000100000000000000000000000000000000000000" db "00000000000001010101001110010011100111001111011100011100001111001110000011000110010111100011100010100011110111100111001111011100111100100111000000011110111100011100001111101110111111110000110001100101111000111000111011100111001111111000001110100111001111000111000011110111100011101111000000000000000000000000000000000000" db "00000000000001010101010001010100001000101000100010100010000100010001000010101010010100010100010100010010000100001000101000100010100010101000100000001000100010100010000100101000100001000000101010100101000101000101000010000000100100100000010000101000101000101000100001000100010000010100000000000000000000000000000000000000" db "00000000000001010101011111010100001000101000100010111110000100010001000010101010010100010111110111110001110011101111101000100010100010101111100000001000100010111110000100101000011101000000101010100101000101111101000010000111100100100000010000101000101000101111100001000100010011110100000000000000000000000000000000000000" db "00000000000000100010010000010100001000101000100010100000000100010001000010010010010100010100000100010000010000101000001000100010100010101000000000001000100010100000000100101000000101000000100100100101000101000001000010001000100100100000010000101000101000101000000001000100010100010100000000000000000000000000000000000000" db "00000000000000100010001111010011100111001000100010011110000111001110000010000010010100010011111000001011110111100111101000100010111100100111101000001110100010011110000100101000111101110000100000100101000100111100111010001111100100111000001110100111001000100111100001110100010111110111000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000100000000000000000000000000000000000000000000000000000000100000000000000000000000100000000000000000010000000010000010000000000000000000000000000000000010000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000" db "00000000000000000100000000000000000000000010010000000000000000000000000000000000000000000000000000100000000000000000010000000010000000000000000000000100000000000000000010000000000000010000011110000000000000000000000000100000100000010000000000000000000000000000000001000000000000000000000000000000000000000000000000000000" db "00000000000000000100000000000000000000000010010000000000000000000000000000000000000000000000000000100000000000000000010000000010000000000000000000000100000000000000000010000000000000010000010001000000000000000000000000100000100000010000000000000000000000000000000001000000000000000000000000000000000000000000000000000000" db "00000000000000111100111000111001111011110010111100001110011100011110100010101110011100000011100000111100011100111011110000011110111010100010011100001111001110000011110010011100100010010000010001001110011100100010011110111101111000111100111000001000100111001000100001111001000100000000000000000000000000000000000000000000" db "00000000000001000101000101000101000010001000010000001000100010100010100010101000100010000000010000100010000010100100010000100010100010100010100010000100010001000010001010000010100010010000011110001000100010100010100010100010100000010001000100001000101000101000100001000101000100000000000000000000000000000000000000000000" db "00000000000001000101000101111100111010001000010000001000111110100010100010101000111110000011110000100010011110100100010000100010100010010100111110000100010001000010001010011110010100010000010001001000100010100010100010100010100000010001000100000101001000101000100001000100101000000000000000000000000000000000000000000000" db "00000000000001000101000101000000001010001000010000001000100000100010100010101000100000000100010000100010100010100100010000100010100010010100100000000100010001000010001010100010010100000000010001001000100010100010100010100010100000010001000100000101001000101000100001000100101000000000000000000000000000000000000000000000" db "00000000000000111100111000111101111010001000011100001000011110011110011110101000011110000111110000100010111110100011110000011110100010001000011110000111001110000011110010111110001000010000011110001000011100011110011110100010111000011100111000000010000111000111100001111000010000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000001000000000000000000000000000000000000010000000000000000000000000000010000000000000000000000000010000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000110000000000000000000000000000000000011100000000000000000000000000001100000000000000000000000001100000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000100000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000010000100000000000000000000000000000100000000000000011110000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000101000100000000000000000000000000000100000000000000110011000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000101000100111001000100111001111000111100111001110000100001001000100111001110100010011100011100111001111001110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000001000100101000100101000000101000101000101000101000000100001001000101000101000100010100010100010100010001010001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000001111100101111100010000111101000101000101111101000000100001000101001111101000010100100010100010100010001011111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000001000100101000000101001000101000101000101000001000000110011000101001000001000010100100010100010100010001010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000010000010100111101000101111101000100111100111101000000011110000010000111101000001000011100011100100001111001111010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000011100000000000000010000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000100010000000000000010000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000001000000001110011110111101110011100101111010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000001000000010001010001010001000100010101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000001000000010001010001010001000100010100111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000100010010001010001010001000100010100001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000011100001110010001011101000011100101111010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000010001000100100000111000111110000000000000100000100000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000010001000101010001000100100011000000000000110001100000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000001010101001010001000000100001000000000000110001100011100100010011100111101110001110011110111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000001010101010001000111000100001000000000000101010100100010100010100010100010001010001010001010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000001010101011111000000100100001000001110000101010100100010010100111110100010001011111010001010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000100010010001001000100100011000000000000100100100100010010100100000100010001010000010001010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000100010100000100111000111110000000000000100000100011100001000011110100010001001111010001011100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000001000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000010000000000000000000000000000010000000000000000000000000000001000000000000000001000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000101000000000000000000000000000010000000000000000000000000000001000000000000000001000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000101000111011100111001001001000010010111001000101111000000000001000000111000111001001000001110011100111001000101111000111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000001000100100010001000101010101000010101000101000101000000000000001000001000101000101010000000001010001000101000101000101000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000001111100100010001000101010101000011001111100101000111000011100001000001000101000101100000001111010001000101000101000101000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000001000100100010001000100100010000010101000000101000001000000000001000001000101000101010000010001010001000101000101000101000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000010000010100010000111000100010000010010111100010001111000000000001111100111000111001001000011111010000111000111101000100111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000001100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000111000000000000000000000000000000000000100000000000000000000000001010010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000001000100000000000000000000000000000000000100000000000000000000000001010010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000001000000111100011100011100111000000000000100100010111101110011110010111010010001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000111000100010000010100001000100000000000100100010100010001010001010010010010001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000100100010011110100001111100001110000100100010100010001010001010010010001010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000001000100100010100010100001000000000000000100100010100010001010001010010010001010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000111000111100111110011100111100000000000100011110100010001011110100010010000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000100000000000000000000000000000000100000000000000000010000100000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000100000000000000000000000000000011000000000000000000010000000000000011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000010000000000000000000000000000000000000100000000100000000000000000000000000000000000100000100000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000111100001011111000000000000111100010000000000000000000000000000000000000100000000100000000000010000000000000000000000100000100000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000001100110001010000000000000000100010010000000000000000000000000000000000000100000000100000000000010000000000000000000000100000100000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000001000010010010000000000000000100010010011100011100111000000111001111000111100000111100111001111111101110011100100010000111100100111000111010010111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000001000010010011111000000000000111100010000010100001000100000000101000101000100001000101000101000010001000100010100010000100010101000101000010100100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000001000010010010000000001110000100000010011110100001111100000111101000101000100001000101111100111010001000100010010100000100010101000101000011000011100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000001100100010010000000000000000100000010100010100001000000001000101000101000100001000101000000001010001000100010010100000100010101000101000010100000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000111000100011111000000000000100000010111110011100111100001111101000100111100000111100111101111011101000011100001000000111100100111000111010010111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000100100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000001111100011100000111000000000000011110000000000000000000010000000000000000000000001000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000001000000100010001000100000000000010001000000000000000000010000000000000000000000001000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000001000000100000010000000000000000010001000111001111001110111100001001001001110011101001111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000001111100011100010000000000000000011110001000101000010001010000001010101010001010001010001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000001000000000010010000000000111000010010001111100111011111010000001010101010001010001010001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000001000000100010001000100000000000010001001000000001010000010000000100010010001010001010001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000001111100011100000111000000000000010000100111101111001111011100000100010001110010001001111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111000000000000000000000000001111100100001011111011111001111000000100000000000000000100000000000001000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000100000000000000000000000001000000110001000100010000001000100000100000000000000000100000000000001000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000100111001110011110111100001000000101001000100010000001000100001111001110000011111111001110011111110000111100100111001000101011110001111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111000100010001010000100000001111100101001000100011111001111000000100010001000010000100000001010001000000100010100000101000101010001010001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000100011111001110011100001000000100101000100010000001001000000100010001000001110100001111010001000000100010100111100101001010001010001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000100010000000010000100001000000100011000100010000001000100000100010001000000010100010001010001000000100010101000100101001010001010001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000100001111011110111100001111100100001000100011111001000010000111001110000011110111011111010001110000111100101111100010001010001001111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000010000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000001100000000000001110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" db "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
; A111365: a(n) = 5*a(n-1) + 3*a(n-2) where a(0) = a(1) = 1. ; Submitted by Jamie Morken(s4) ; 1,1,8,43,239,1324,7337,40657,225296,1248451,6918143,38336068,212434769,1177182049,6523214552,36147618907,200307738191,1109981547676,6150830952953,34084099407793,188872989897824,1046617247712499 mov $1,3 mov $3,1 lpb $0 sub $0,1 mov $2,$3 mul $2,3 mul $3,5 add $3,$1 mov $1,$2 lpe mov $0,$1 div $0,3
; A254398: Final digits of A237424 in decimal representation. ; 1,4,7,4,7,7,4,7,7,7,4,7,7,7,7,4,7,7,7,7,7,4,7,7,7,7,7,7,4,7,7,7,7,7,7,7,4,7,7,7,7,7,7,7,7,4,7,7,7,7,7,7,7,7,7,4,7,7,7,7,7,7,7,7,7,7,4,7,7,7,7,7,7,7,7,7,7,7,4,7,7,7,7,7,7,7 sub $0,1 mov $1,2 mov $2,1 lpb $0 add $2,1 sub $0,$2 lpe lpb $2 mov $1,1 add $1,$0 mul $2,$1 div $2,2 lpe mul $1,3 add $1,1 mov $0,$1
COMMENT @===================================================================== Copyright (c) GeoWorks 1992 -- All Rights Reserved PROJECT: PC/GEOS MODULE: Iclas -- IconList FILE: iconlistMain.asm AUTHOR: Martin Turon, October 16, 1992 METHODS: Name Description ---- ----------- REVISION HISTORY: Name Date Description ---- ---- ----------- martin 10/16/92 Initial version DESCRIPTION: Externally callable routines for this module. No routines outside this file should be called from outside this module. $Id: iconlistMain.asm,v 1.1 97/04/07 10:45:25 newdeal Exp $ =============================================================================@ COMMENT @------------------------------------------------------------------- Work to be done: 1) make sure IconListClass frees the memory allocated by IconListBuildList whenever: * IconList object is destroyed * IconList object switchs lookup tables 2) add selectivity to IconListBuildList: * only add tokens of certain manufacturer id * only add 'ba**' tokens, etc. 3) fixup IconListClass, so that it can handle *any* video mode (not hardcoded for VGA). ----------------------------------------------------------------------------@ COMMENT @------------------------------------------------------------------- IconListSpecBuild ---------------------------------------------------------------------------- DESCRIPTION: Sets the IconList object to the correct size. CALLED BY: GLOBAL PASS: *ds:si = IconListClass object ds:di = IconListClass instance data bp = SpecBuildFlags RETURN: nothing DESTROYED: ax, cx, dx, bp PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- martin 10/16/92 Initial version ----------------------------------------------------------------------------@ IconListSpecBuild method dynamic IconListClass, MSG_SPEC_BUILD uses ax, bp .enter ; ; Get size from first moniker in list ; ; call VisGetSize ; ; Set size depending on DisplayType by append to object: ; HINT_FIXED_SIZE { ; SpecWidth <> ; SpecHeight <> ; word 5 ; } ; mov ax, HINT_FIXED_SIZE mov cx, size SpecWidth + size SpecHeight + size word call ObjVarAddData mov ds:[bx].SSA_width, SpecWidth <SST_PIXELS, (55*5)> mov ds:[bx].SSA_height, SpecHeight <SST_PIXELS, 32> mov ds:[bx].SSA_count, 5 mov di, ds:[si] add di, ds:[di].IconList_offset movdw dxcx, ds:[di].ILI_lookupTable mov ax, MSG_ICON_LIST_SET_TOKEN_LIST mov bx, ds:[LMBH_handle] mov di, mask MF_FORCE_QUEUE or \ mask MF_FIXUP_DS or mask MF_FIXUP_ES call ObjMessage .leave mov di, offset IconListClass GOTO ObjCallSuperNoLock IconListSpecBuild endm COMMENT @------------------------------------------------------------------- IconListQueryItemMoniker ---------------------------------------------------------------------------- SYNOPSIS: This is called when the dynamic GenList needs to show a moniker on the screen. It sends us the number of the list item whose moniker it needs. We get it by looking in our local table of tokens and grabbing the moniker from the token.db CALLED BY: GenDynamicListClass PASS: *ds:si = IconListClass object ds:di = IconListClass instance data ^lcx:dx = the dynamic list requesting the moniker bp = entry # it needs the moniker for RETURN: nothing DESTROYED: lots of stuff (but it doesn't matter) PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- martin 10/16/92 Initial version ----------------------------------------------------------------------------@ IconListQueryItemMoniker method dynamic IconListClass, MSG_GEN_DYNAMIC_LIST_QUERY_ITEM_MONIKER .enter call IconListLookupToken ; ax:cx:dx = GeodeToken call ShellLoadMoniker ; ^cx:dx = Moniker push cx jc error mov ax, MSG_GEN_DYNAMIC_LIST_REPLACE_ITEM_MONIKER_OPTR call ObjCallInstanceNoLock error: pop bx call MemFree ; free moniker .leave ret IconListQueryItemMoniker endm COMMENT @------------------------------------------------------------------- IconListGetSelected ---------------------------------------------------------------------------- DESCRIPTION: Returns the token currently selected in an IconListClass object. If nothing is selected, returns the first token in the list. CALLED BY: GLOBAL PASS: *ds:si = IconListClass object RETURN: ax:cx:dx = GeodeToken CF = set if no token selected clear otherwise DESTROYED: bp PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- martin 10/18/92 Initial version ----------------------------------------------------------------------------@ IconListGetSelected method dynamic IconListClass, MSG_ICON_LIST_GET_SELECTED .enter mov ax, MSG_GEN_ITEM_GROUP_GET_SELECTION call ObjCallInstanceNoLock pushf ; save carry flag jnc useSelected clr ax ; return first token in list useSelected: mov bp, ax mov di, ds:[si] add di, ds:[di].IconList_offset call IconListLookupToken popf ; restore carry flag .leave ret IconListGetSelected endm COMMENT @------------------------------------------------------------------- IconListSetTokenOfFile ---------------------------------------------------------------------------- DESCRIPTION: Sets the token of the given file to that of the current selection. WARNING: Be careful when sending this message across threads, as the current directorys may be different! (Use full path names) CALLED BY: GLOBAL PASS: *ds:si = IconListClass object cx:dx = file to set token of RETURN: IF ERROR: carry set ax = FileError ELSE: carry clear DESTROYED: cx, dx, bp PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- martin 10/18/92 Initial version ----------------------------------------------------------------------------@ IconListSetTokenOfFile method dynamic IconListClass, MSG_ICON_LIST_SET_TOKEN_OF_FILE .enter if ERROR_CHECK ; ; Validate that the filename is not in a movable code segment ; FXIP< push bx, si > FXIP< mov bx, cx > FXIP< mov si, dx > FXIP< call ECAssertValidFarPointerXIP > FXIP< pop bx, si > endif push cx, dx mov ax, MSG_ICON_LIST_GET_SELECTED call ObjCallInstanceNoLock mov di, dx pop ds, dx ; call IclasSetToken .leave ret IconListSetTokenOfFile endm COMMENT @------------------------------------------------------------------- IconListSetSelectionToToken ---------------------------------------------------------------------------- DESCRIPTION: CALLED BY: PASS: *ds:si = IconListClass object bp:cx:dx = GeodeToken RETURN: nothing DESTROYED: ax, cx, dx, bp PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- martin 11/30/92 Initial version ----------------------------------------------------------------------------@ IconListSetSelectionToToken method dynamic IconListClass, MSG_ICON_LIST_SET_SELECTION_TO_TOKEN .enter call IconListFindToken jc done mov cx, bp clr dx mov ax, MSG_GEN_ITEM_GROUP_SET_SINGLE_SELECTION call ObjCallInstanceNoLock done: .leave ret IconListSetSelectionToToken endm COMMENT @------------------------------------------------------------------- IconListSetTokenList ---------------------------------------------------------------------------- DESCRIPTION: Sets the token list, and forces a redraw if necessary. CALLED BY: GLOBAL PASS: *ds:si = IconListClass object ds:di = IconListClass instance data ^ldx:cx = new token list if dx=0, list will be built to contain all tokens in token db. RETURN: nothing DESTROYED: ax, cx, dx, bp PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- martin 10/18/92 Initial version ----------------------------------------------------------------------------@ IconListSetTokenList method dynamic IconListClass, MSG_ICON_LIST_SET_TOKEN_LIST ; ; Store token list in instance data. ; movdw ds:[di].ILI_lookupTable, dxcx FALL_THRU IconListInitialize IconListSetTokenList endm COMMENT @------------------------------------------------------------------- IconListInitialize ---------------------------------------------------------------------------- DESCRIPTION: Builds a table of all the tokens in the token DB if a table has not already been specified. The icon list is then notified to display a new list of items. If the list is already usable, invalidates all the current items and re-requests all the monikers. All items will be deselected. CALLED BY: GLOBAL PASS: *ds:si = IconListClass object ds:di = IconListClass instance data RETURN: nothing DESTROYED: ax, cx, dx, bp PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- martin 11/5/92 Initial version ----------------------------------------------------------------------------@ IconListInitialize method static IconListClass, MSG_ICON_LIST_INITIALIZE ; ; If no list is specified, build one with every entry of the ; token database. ; call IconListBuildListIfNeededAndGetSize ; ; Initialize list ; mov ax, MSG_GEN_DYNAMIC_LIST_INITIALIZE GOTO ObjCallInstanceNoLock IconListInitialize endm
if_eq macro bne L1\@! endm if_ne macro beq L1\@! endm if_le macro ble L1\@! endm endi macro L1\@@: endm do macro L1\@!: endm while macro bra L1\@@ endm while_eq macro bne L1\@@ endm while_ne macro beq L1\@@ endm
[org 0x0100] jmp start message: db 'hello_word' printstr: ;parameters order of pushing ;x pos, ypos, attribute, message, length push bp mov bp, sp ;saving registers push ax push cx push di push si push es mov ax, 0xb800 mov es, ax ;point es to video base mov al, 80 ;load al with coloumns per row mul byte [bp + 10] ;multiplying with ypos add ax, [bp + 12] ;adding x pos shl ax, 1 ;turn into byte offset by multiplying by 2 mov di, ax ;moving ax to di to point di to the required location mov si, [bp + 6] ;pointing si to the parameter string mov cx, [bp + 4] ;moving parameter length into cx mov ah, [bp + 8] ;moving parameter attribute into ah keepprintstr: mov al, [si] ;moving current char of string into al ;a char is the size of a byte mov [es:di], ax ;moving the char(al) with the attribute(ah) in video memory add di, 2 ;moving di to the next location in the video memory add si, 1 ;moving si to the next char loop keepprintstr ;repeat the loop cx times pop es pop si pop di pop cx pop ax pop bp ;there are 5 parameters so ret 10 ret 10 printnum: ;parameters order of pushing ;x pos, ypos, attribute, number, base push bp mov bp, sp push ax push bx push cx push dx push di push es mov ax, 0xb800 mov es, ax ;pointing es to video base mov ax, [bp + 6] ;loading number in ax mov bx, [bp + 4] ;moving base in bx for division mov cx, 0 ;intialize count of digits nextdigit: mov dx, 0 ;zero upper half of dividend div bx ;divide by bx add dl, 0x30 ;convert digit into ASCII value push dx ;save ASCII value on stack inc cx ;incrememnt count of values cmp ax, 0 ;is the quotient zero jnz nextdigit ;if no divide it again mov ax, 0xb800 mov es, ax ;pointing es to video base mov al, 80 ;load al with coloumns per row mul byte [bp+ 10] ;multiplying with ypos add ax, [bp + 12] ;adding xpos shl ax, 1 ;turn into byte offset by multiplying by 2 mov di, ax ;moving ax to di to point di to the required location keepprintnum: pop dx mov dh, [bp + 8] mov [es:di], dx add di, 2 loop keepprintnum pop es pop di pop dx pop cx pop bx pop ax pop bp ret 10 start: mov ax, 40 ;xpos push ax mov ax, 12 ;ypos push ax mov ax, 0x07 ;attribute push ax mov ax, message ;string/number push ax mov ax, 10 ;size/base push ax call printstr finish: mov ax, 0x04c00 int 21h
gdt_start: ; the GDT starts with a null 8-byte dd 0x0 dd 0x0 ; GDT for code segment base = 0x00000000, length = 0xfffff ; for flags, refer to os-dev.pdf, page 36 gdt_code: dw 0xffff ; segment length, bits 0-15 dw 0x0 ; segment base bits 0-15 db 0x0 ; segment base bits 16-23 db 10011010b ; flags (8 bits) db 11001111b ; flags (4 bits) + segment length, bits 16-19 db 0x0 ; segment base, bits 24-31 ; GDT for data segment, base and length identical to code segment ; some flags changed gdt_data: dw 0xffff dw 0x0 db 0x0 db 10010010b db 11001111b db 0x0 gdt_end: gdt_descriptor: dw gdt_end - gdt_start - 1 ; size (16 bit) always one less of its true size dd gdt_start ; address(32 bit) ; define some constants for later use CODE_SEG equ gdt_code - gdt_start DATA_SEG equ gdt_data - gdt_start
; Copyright 2012 Bubble Zap Games ; ; 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. ;==LoRom== ; We'll get to HiRom some other time. .MEMORYMAP ; Begin describing the system architecture. SLOTSIZE $8000 ; The slot is $8000 bytes in size. More details on slots later. DEFAULTSLOT 0 ; There's only 1 slot in SNES, there are more in other consoles. SLOT 0 $8000 ; Defines Slot 0's starting address. SLOT 1 $0 $2000 SLOT 2 $2000 $E000 SLOT 3 $0 $10000 .ENDME ; End MemoryMap definition .ROMBANKSIZE $8000 ; Every ROM bank is 32 KBytes in size .ROMBANKS 8 ; Tell WLA how many ROM banks we want .SNESHEADER ID "SNES" ; 1-4 letter string, just leave it as "SNES" NAME "Classic Kong Complete" ; Program Title - can't be over 21 bytes, ; "123456789012345678901" ; use spaces for unused bytes of the name. FASTROM;SLOWROM LOROM CARTRIDGETYPE $00 ; $00 = ROM only, see WLA documentation for others ROMSIZE $08 ; $10 = 4 Mbits, see WLA doc for more.. SRAMSIZE $00 ; No SRAM see WLA doc for more.. COUNTRY $01 ; $01 = U.S. $00 = Japan, that's all I know ; Values $00, $01, $0d use NTSC. ; Values in range $02..$0c use PAL. Other values are invalid. LICENSEECODE $00 ; Just use $00 VERSION $00 ; $00 = 1.00, $01 = 1.01, etc. .ENDSNES .SNESNATIVEVECTOR ; Define Native Mode interrupt vector table COP EmptyHandler BRK EmptyHandler ABORT EmptyHandler NMI VBlank IRQ EmptyHandler .ENDNATIVEVECTOR .SNESEMUVECTOR ; Define Emulation Mode interrupt vector table COP EmptyHandler ABORT EmptyHandler NMI EmptyHandler RESET tcc__start ; where execution starts IRQBRK EmptyHandler .ENDEMUVECTOR .include "data.asm"
.set k_p_in, 0 .set k_p_wei, 8 .set k_p_out, 16 .set k_hi, 24 .set k_wi, 28 .set k_n, 32 .set k_k, 36 .set k_c, 40 .set k_ho, 44 .set k_wo, 48 .set k_stride_h, 52 .set k_stride_w, 56 .set k_dilation_h, 60 .set k_dilation_w, 64 .set k_pad_h, 68 .set k_pad_w, 72 .set k_y, 76 .set k_x, 80 .set k_group, 84 .set k_batch_m, 88 .set k_stride_m, 92 .set k_alpha, 96 .set k_beta, 100 .set k_gamma, 104 .set k_magic_0, 108 .set k_magic_1, 112 .set k_magic_2, 116 .set k_shift_pack_0, 120 .set k_n_dword, 4 .set s_ka, 0 .set s_bx, 2 ; bx, ho*wo .set s_block_ig, 3 ; by, group .set s_block_in, 4 ; bz, batch .set s_p_in, 6 .set s_p_wei, 8 .set s_p_out, 10 .set s_hi, 16 .set s_wi, 17 .set s_n, 18 .set s_k, 19 .set s_c, 20 .set s_ho, 21 .set s_wo, 22 .set s_stride_h, 23 .set s_stride_w, 24 .set s_dilation_h, 25 .set s_dilation_w, 26 .set s_pad_h, 27 .set s_pad_w, 28 .set s_y, 29 .set s_x, 30 .set s_group, 31 .set s_batch_m, 32 .set s_stride_m, 33 .set s_alpha, 34 .set s_beta, 35 .set s_gamma, 36 .set s_magic_0, 37 .set s_magic_1, 38 .set s_magic_2, 39 .set s_shift_pack_0, 40 .set s__pack_0, 41 .set s_shift_m0, 42 .set s_shift_m1, s_shift_pack_0 .set s_shift_m2, 43 .set s_in_stride_wi, 12 .set s_in_stride_n, 13 .set s_wei_stride_k, 14 .set s_out_stride_wo, 15 .set s_out_stride_n, 44 .set s_in_diff_hi, 45 .set s_in_diff_wi, 46 .set s_dilation_w_x, 47 .set s_move_slice_k_ix, 48 .set s_kitr, 1 .set s_wei_offset, 49 .set s_out_stride, s_wei_offset .set s_sld_b_stride, 50 .set s_br, 51 .set s_ib_stride, 52 .set s_block_ik, 53 .set s_block_ib, 54 .set s_0xff, 55 .set s_tmp, 56 .set s_end, 62 ; magic_0: x ; magic_1: wo .set v_c, 0 .set v_c_buf, v_c .set v_sld_b_os, 8 .set v_ax, 9 .set v_ay, 25 .set v_ib, 41 .set v_b, 42 .set v_gld_b, v_b .set v_wei_iy_list, v_b+4 .set v_wei_ix_list, v_b+5 .set v_wei_flag, v_b+6 .set v_wei_os, v_b+7 .set v_tmp, v_b+8 .set v_wei_ik, v_ay .set v_wei_ic, v_ay+1 .set v_wei_ie, v_ay+2 .set v_wei_flag_ik, v_ay+3 .set v_sst_b_os, v_ay+4 .set v_in_os, 74 .set v_in_ihi, 76 .set v_in_iwi, 78 .set v_in_flag, 80 .set v_out_os, 82 .set v_out_flag, 84 .set v_tid, 86 .set v_end, 88 ; short wide igemv .text .globl igemm_fwd_btm_nhwc_fp16_256x4x16_r1 .p2align 8 .type igemm_fwd_btm_nhwc_fp16_256x4x16_r1,@function igemm_fwd_btm_nhwc_fp16_256x4x16_r1: s_load_dwordx2 s[s_p_in+0:s_p_in+1], s[s_ka+0:s_ka+1], 0+k_p_in s_load_dwordx4 s[s_p_wei+0:s_p_wei+3], s[s_ka+0:s_ka+1], 0+k_p_wei s_load_dwordx16 s[s_hi+0:s_hi+15], s[s_ka+0:s_ka+1], 0+k_hi s_load_dwordx8 s[s_batch_m:s_batch_m+7], s[s_ka+0:s_ka+1], 0+k_batch_m s_load_dword s[s_shift_pack_0], s[s_ka+0:s_ka+1], 0+k_shift_pack_0 v_mov_b32 v[v_tid], v0 s_mov_b32 s[s_ib_stride], 128 ; calculate wei offset, 4x32, 4 for k, 32 for yxc, 16 for yx, 2 for c v_lshrrev_b32 v[v_wei_ik], 5, v0 s_mov_b32 s[s_tmp], k_n_dword*4 * 4 ; 9 dword per row, 4 row v_and_b32 v[v_tmp+5], 31, v0 s_lshl_b32 s[s_block_ig], s[s_block_ig], 1 v_and_b32 v[v_wei_ic], 1, v0 s_lshl_b32 s[s_block_in], s[s_block_in], 1 v_lshrrev_b32 v[v_tmp+4], 1, v0 v_mov_b32 v[v_ib], v0 v_mul_u32_u24 v[v_tmp+5], s[s_tmp] ,v[v_tmp+5] v_lshlrev_b32 v[v_sst_b_os], 2, v[v_wei_ik] ; store, k*n*k_pack, ds_write2 if possible, n*k_pack->16dword, pad to x v_mov_b32 v[v_sld_b_os], 0 ; load v_lshlrev_b32 v[v_wei_ic], 3, v[v_wei_ic] ; 8xc, k_pack, 4x dword v_and_b32 v[v_wei_ie], 15, v[v_tmp+4] ; yx v_add_nc_u32 v[v_sst_b_os], v[v_sst_b_os], v[v_tmp+5] ; note, do not use or due to pad s_waitcnt lgkmcnt(0) s_bfe_u32 s[s_shift_m2], s[s_shift_pack_0], 0x00080010 ; offset:16, width:8 s_lshr_b32 s[s_tmp+3], s[s_k], 2 s_bfe_u32 s[s_shift_m0], s[s_shift_pack_0], 0x00080000 ; offset:0, width:8 .mdiv_u32_rem_ss s_tmp+4,s_tmp+5,s_bx,s_magic_2,s_shift_m2,s_tmp+3,s_tmp s_lshl_b32 s[s_block_ib], s[s_tmp+5], 8 ; 256 s_lshl_b32 s[s_block_ik], s[s_tmp+4], 2 v_add_nc_u32 v[v_ib], s[s_block_ib], v[v_ib] s_mul_i32 s[s_tmp], s[s_x], s[s_c] v_add_nc_u32 v[v_wei_ik], s[s_block_ik], v[v_wei_ik] v_mad_u32_u24 v[v_tmp+1], s[s_c], v[v_wei_ie], v[v_wei_ic] s_mul_i32 s[s_wei_stride_k], s[s_tmp], s[s_y] s_lshl_b32 s[s_wei_offset], s[s_c], 3+1 ; 8x s_c, half s_mul_i32 s[s_tmp+5], s[s_wei_stride_k], s[s_k] v_mad_u32_u24 v[v_wei_os], s[s_wei_stride_k], v[v_wei_ik], v[v_tmp+1] s_mul_i32 s[s_tmp+2], s[s_block_ig], s[s_tmp+5] v_cmp_gt_u32 s[s_k], v[v_wei_ik] s_add_u32 s[s_p_wei], s[s_p_wei], s[s_tmp+2] v_cndmask_b32 v[v_wei_flag_ik], 0, 1 s_addc_u32 s[s_p_wei+1], s[s_p_wei+1], 0 v_lshlrev_b32 v[v_wei_os], 1, v[v_wei_os] ; divide x .mdiv_u32_rem_vs v_wei_ix_list+0,v_wei_iy_list+0,v_wei_ie,s_magic_0,s_shift_m0,s_x,v_tmp ;v_add_nc_u32 v[v_wei_os+1], s[s_wei_offset], v[v_wei_os+0] ;v_add_nc_u32 v[v_wei_ie], 8, v[v_wei_ie] v_cmp_gt_u32 s[s_y], v[v_wei_iy_list+0] v_cndmask_b32 v[v_wei_flag+0], 0, v[v_wei_flag_ik] v_cmp_gt_u32 s[s_x], v[v_wei_ix_list+0] v_cndmask_b32 v[v_wei_flag+0], 0, v[v_wei_flag+0] v_cmpx_le_u32 1, v[v_wei_flag+0] global_load_dwordx4 v[v_gld_b+0:v_gld_b+3], v[v_wei_os+0], s[s_p_wei:s_p_wei+1] s_mov_b64 exec, -1 ; s_mov_b32 s[s_tmp+5], 128*k_n_dword*4 ; stride for wei sst offset. 32 thread for gemm_k, each thread store 4 c, hence 32*4=128 gemm_k ; calculate in offset s_mul_i32 s[s_in_stride_wi], s[s_c], s[s_group] s_bfe_u32 s[s_shift_m1], s[s_shift_pack_0], 0x00080008 ; offset:8, width:8 s_mul_i32 s[s_tmp+2], s[s_wi], s[s_in_stride_wi] s_mul_i32 s[s_tmp+0], s[s_block_ig], s[s_c] s_mul_i32 s[s_in_stride_n], s[s_hi], s[s_tmp+2] s_mul_i32 s[s_tmp+3], s[s_block_in], s[s_in_stride_n] s_lshl_b32 s[s_in_stride_wi], s[s_in_stride_wi], 1 s_add_u32 s[s_tmp+0], s[s_tmp+0], s[s_tmp+3] ;v_add_nc_u32 v[v_sst_b_os+1], s[s_tmp+5], v[v_sst_b_os+0] .mdiv_u32_rem_vs v_in_iwi,v_in_ihi,v_ib,s_magic_1,s_shift_m1,s_wo,v_tmp s_add_u32 s[s_p_in], s[s_p_in], s[s_tmp+0] v_add_nc_u32 v[v_tmp+5], s[s_ib_stride], v[v_ib] s_addc_u32 s[s_p_in+1], s[s_p_in+1], 0 v_mul_lo_u32 v[v_in_ihi], s[s_stride_h], v[v_in_ihi] .v_clear_nc v_ax, 4 v_sub_nc_i32 v[v_in_ihi], v[v_in_ihi], s[s_pad_h] v_mul_lo_u32 v[v_in_iwi], s[s_stride_w], v[v_in_iwi] .v_clear_nc v_ax+4, 4 v_sub_nc_i32 v[v_in_iwi], v[v_in_iwi], s[s_pad_w] .mdiv_u32_rem_vs v_in_iwi+1,v_in_ihi+1,v_tmp+5,s_magic_1,s_shift_m1,s_wo,v_tmp v_mul_lo_u32 v[v_tmp], s[s_wi], v[v_in_ihi] ; v_add_nc_u32 v[v_tmp+5], s[s_ib_stride], v[v_tmp+5] v_cmp_gt_u32 s[s_hi], v[v_in_ihi] v_cndmask_b32 v[v_in_flag], 0, 1 v_add_nc_u32 v[v_tmp], v[v_in_iwi], v[v_tmp] v_cmp_gt_u32 s[s_wi], v[v_in_iwi] v_cndmask_b32 v[v_in_flag], 0, v[v_in_flag] v_mul_lo_u32 v[v_in_os], s[s_in_stride_wi], v[v_tmp] v_mul_lo_u32 v[v_in_ihi+1], s[s_stride_h], v[v_in_ihi+1] .v_clear_nc v_ax+8, 4 v_sub_nc_i32 v[v_in_ihi+1], v[v_in_ihi+1], s[s_pad_h] v_mul_lo_u32 v[v_in_iwi+1], s[s_stride_w], v[v_in_iwi+1] .v_clear_nc v_ax+12, 4 v_sub_nc_i32 v[v_in_iwi+1], v[v_in_iwi+1], s[s_pad_w] v_cmpx_le_u32 1, v[v_in_flag] global_load_dwordx4 v[v_ax+0:v_ax+3], v[v_in_os], s[s_p_in:s_p_in+1] global_load_dwordx4 v[v_ax+4:v_ax+7], v[v_in_os], s[s_p_in:s_p_in+1] offset:16 s_mov_b64 exec, -1 v_mul_lo_u32 v[v_tmp], s[s_wi], v[v_in_ihi+1] v_cmp_gt_u32 s[s_hi], v[v_in_ihi+1] v_cndmask_b32 v[v_in_flag+1], 0, 1 v_add_nc_u32 v[v_tmp], v[v_in_iwi+1], v[v_tmp] v_cmp_gt_u32 s[s_wi], v[v_in_iwi+1] v_cndmask_b32 v[v_in_flag+1], 0, v[v_in_flag+1] v_mul_lo_u32 v[v_in_os+1], s[s_in_stride_wi], v[v_tmp] v_cmpx_le_u32 1, v[v_in_flag+1] global_load_dwordx4 v[v_ax+ 8:v_ax+11], v[v_in_os+1], s[s_p_in:s_p_in+1] global_load_dwordx4 v[v_ax+12:v_ax+15], v[v_in_os+1], s[s_p_in:s_p_in+1] offset:16 s_mov_b64 exec, -1 s_mul_i32 s[s_br], s[s_wo], s[s_ho] s_mul_i32 s[s_out_stride_wo], s[s_k], s[s_group] s_mul_i32 s[s_in_diff_wi], s[s_dilation_w], s[s_in_stride_wi] s_mov_b32 s[s_move_slice_k_ix], 0 s_mul_i32 s[s_out_stride_n], s[s_br], s[s_out_stride_wo] s_mul_i32 s[s_tmp+1], s[s_block_ig], s[s_k] s_mul_i32 s[s_tmp+4], s[s_block_in], s[s_out_stride_n] s_lshl_b32 s[s_tmp+5], s[s_block_ik], 1 s_add_u32 s[s_tmp+1], s[s_tmp+1], s[s_tmp+4] s_add_u32 s[s_tmp+1], s[s_tmp+1], s[s_tmp+5] s_add_u32 s[s_p_out], s[s_p_out], s[s_tmp+1] s_addc_u32 s[s_p_out+1], s[s_p_out+1], 0 ; calculate diffs, for y, x s_sub_i32 s[s_tmp+3], s[s_x], 1 s_mul_i32 s[s_tmp], s[s_in_diff_wi], s[s_tmp+3] s_mul_i32 s[s_tmp+1], s[s_in_stride_wi], s[s_wi] s_mul_i32 s[s_tmp+1], s[s_tmp+1], s[s_dilation_h] s_sub_i32 s[s_in_diff_hi], s[s_tmp+1], s[s_tmp] s_mul_i32 s[s_dilation_w_x], s[s_dilation_w], s[s_tmp+3] s_mul_i32 s[s_dilation_w_x], s[s_dilation_w_x], -1 v_add_nc_u32 v[v_tmp+5], s[s_ib_stride], v[v_ib] s_mul_i32 s[s_out_stride], s[s_stride_m], s[s_out_stride_wo] s_lshl_b32 s[s_out_stride], s[s_out_stride], 1 s_lshl_b32 s[s_out_stride_n], s[s_out_stride_n], 1 ; output offset v_mul_lo_u32 v[v_out_os], s[s_k], v[v_ib] v_lshlrev_b32 v[v_out_os], 1, v[v_out_os] v_cmp_gt_u32 s[s_out_stride_n], v[v_out_os] v_cndmask_b32 v[v_out_flag], 0, 1 v_add_nc_u32 v[v_tmp+4], s[s_ib_stride], v[v_tmp+5] v_mul_lo_u32 v[v_out_os+1], s[s_k], v[v_tmp+5] v_lshlrev_b32 v[v_out_os+1], 1, v[v_out_os+1] v_cmp_gt_u32 s[s_out_stride_n], v[v_out_os+1] v_cndmask_b32 v[v_out_flag+1], 0, 1 s_mov_b32 s[s_sld_b_stride], k_n_dword*8*4 s_waitcnt vmcnt(4) v_cmpx_le_u32 1, v[v_wei_flag+0] ds_write2_b32 v[v_sst_b_os+0], v[v_gld_b+0], v[v_gld_b+1], offset0:k_n_dword*0 offset1:k_n_dword*1 ds_write2_b32 v[v_sst_b_os+0], v[v_gld_b+2], v[v_gld_b+3], offset0:k_n_dword*2 offset1:k_n_dword*3 s_mov_b64 exec, -1 .v_clear_nc v_c, 8 s_waitcnt lgkmcnt(0) s_barrier ds_read_b128 v[v_b+ 0:v_b+ 3], v[v_sld_b_os], offset:k_n_dword*4*0 ds_read_b128 v[v_b+ 4:v_b+ 7], v[v_sld_b_os], offset:k_n_dword*4*1 ds_read_b128 v[v_b+ 8:v_b+11], v[v_sld_b_os], offset:k_n_dword*4*2 ds_read_b128 v[v_b+12:v_b+15], v[v_sld_b_os], offset:k_n_dword*4*3 ds_read_b128 v[v_b+16:v_b+19], v[v_sld_b_os], offset:k_n_dword*4*4 ds_read_b128 v[v_b+20:v_b+23], v[v_sld_b_os], offset:k_n_dword*4*5 ds_read_b128 v[v_b+24:v_b+27], v[v_sld_b_os], offset:k_n_dword*4*6 ds_read_b128 v[v_b+28:v_b+31], v[v_sld_b_os], offset:k_n_dword*4*7 s_sub_i32 s[s_kitr], s[s_wei_stride_k], 16 v_add_nc_u32 v[v_sld_b_os], s[s_sld_b_stride], v[v_sld_b_os] ; accumulate sld_b_os s_cmp_gt_i32 s[s_kitr], 0 s_cbranch_scc0 L_igemm_fwd_btm_nhwc_fp16_256x4x16_r1_fma_end L_igemm_fwd_btm_nhwc_fp16_256x4x16_r1_fma_body: ; accumulate im ; a buffer x ;--- start move slice window s_add_u32 s[s_move_slice_k_ix], 1, s[s_move_slice_k_ix] s_cmp_le_u32 s[s_x], s[s_move_slice_k_ix] s_cselect_b32 s[s_tmp], s[s_dilation_w_x], s[s_dilation_w] s_cselect_b32 s[s_tmp+1], s[s_in_diff_hi], s[s_in_diff_wi] v_add_nc_u32 v[v_in_iwi+0], s[s_tmp], v[v_in_iwi+0] v_add_nc_u32 v[v_in_iwi+1], s[s_tmp], v[v_in_iwi+1] v_add_nc_u32 v[v_in_os+0], s[s_tmp+1], v[v_in_os+0] v_add_nc_u32 v[v_in_os+1], s[s_tmp+1], v[v_in_os+1] s_cbranch_scc0 igemm_fwd_btm_nhwc_fp16_256x4x16_r1_fma_acc_yx_x_end_1 s_mov_b32 s[s_move_slice_k_ix], 0 v_add_nc_i32 v[v_in_ihi+0], s[s_dilation_h], v[v_in_ihi+0] v_add_nc_i32 v[v_in_ihi+1], s[s_dilation_h], v[v_in_ihi+1] igemm_fwd_btm_nhwc_fp16_256x4x16_r1_fma_acc_yx_x_end_1: v_cmp_gt_u32 s[s_wi], v[v_in_iwi+0] v_cndmask_b32 v[v_in_flag+0], 0, 1 v_cmp_gt_u32 s[s_wi], v[v_in_iwi+1] v_cndmask_b32 v[v_in_flag+1], 0, 1 v_cmp_gt_u32 s[s_hi], v[v_in_ihi+0] v_cndmask_b32 v[v_in_flag+0], 0, v[v_in_flag+0] v_cmp_gt_u32 s[s_hi], v[v_in_ihi+1] v_cndmask_b32 v[v_in_flag+1], 0, v[v_in_flag+1] ;--- end move slice window ;s_waitcnt vmcnt(0) .v_clear_nc v_ay, 16 v_cmpx_le_u32 1, v[v_in_flag+0] global_load_dwordx4 v[v_ay+0:v_ay+3], v[v_in_os], s[s_p_in:s_p_in+1] global_load_dwordx4 v[v_ay+4:v_ay+7], v[v_in_os], s[s_p_in:s_p_in+1] offset:16 s_mov_b64 exec, -1 v_cmpx_le_u32 1, v[v_in_flag+1] global_load_dwordx4 v[v_ay+ 8:v_ay+11], v[v_in_os+1], s[s_p_in:s_p_in+1] global_load_dwordx4 v[v_ay+12:v_ay+15], v[v_in_os+1], s[s_p_in:s_p_in+1] offset:16 s_mov_b64 exec, -1 s_waitcnt vmcnt(4) lgkmcnt(4) .fma_1x4_fp16 v_c+ 0, v_ax + 0, v_b + 0 .fma_1x4_fp16 v_c+ 4, v_ax + 8, v_b + 0 .fma_1x4_fp16 v_c+ 0, v_ax + 1, v_b + 4 .fma_1x4_fp16 v_c+ 4, v_ax + 9, v_b + 4 .fma_1x4_fp16 v_c+ 0, v_ax + 2, v_b + 8 .fma_1x4_fp16 v_c+ 4, v_ax +10, v_b + 8 .fma_1x4_fp16 v_c+ 0, v_ax + 3, v_b +12 .fma_1x4_fp16 v_c+ 4, v_ax +11, v_b +12 ds_read_b128 v[v_b+ 0:v_b+ 3], v[v_sld_b_os], offset:k_n_dword*4*0 ds_read_b128 v[v_b+ 4:v_b+ 7], v[v_sld_b_os], offset:k_n_dword*4*1 ds_read_b128 v[v_b+ 8:v_b+11], v[v_sld_b_os], offset:k_n_dword*4*2 ds_read_b128 v[v_b+12:v_b+15], v[v_sld_b_os], offset:k_n_dword*4*3 s_waitcnt lgkmcnt(4) .fma_1x4_fp16 v_c+ 0, v_ax + 4, v_b +16 .fma_1x4_fp16 v_c+ 4, v_ax +12, v_b +16 .fma_1x4_fp16 v_c+ 0, v_ax + 5, v_b +20 .fma_1x4_fp16 v_c+ 4, v_ax +13, v_b +20 .fma_1x4_fp16 v_c+ 0, v_ax + 6, v_b +24 .fma_1x4_fp16 v_c+ 4, v_ax +14, v_b +24 .fma_1x4_fp16 v_c+ 0, v_ax + 7, v_b +28 .fma_1x4_fp16 v_c+ 4, v_ax +15, v_b +28 ds_read_b128 v[v_b+16:v_b+19], v[v_sld_b_os], offset:k_n_dword*4*4 ds_read_b128 v[v_b+20:v_b+23], v[v_sld_b_os], offset:k_n_dword*4*5 ds_read_b128 v[v_b+24:v_b+27], v[v_sld_b_os], offset:k_n_dword*4*6 ds_read_b128 v[v_b+28:v_b+31], v[v_sld_b_os], offset:k_n_dword*4*7 s_sub_i32 s[s_kitr], s[s_kitr], 16 v_add_nc_u32 v[v_sld_b_os], s[s_sld_b_stride], v[v_sld_b_os] ; accumulate sld_b_os s_cmp_gt_i32 s[s_kitr], 0 s_cbranch_scc0 L_igemm_fwd_btm_nhwc_fp16_256x4x16_r1_fma_end_1 ; a buffer y ;--- start move slice window s_add_u32 s[s_move_slice_k_ix], 1, s[s_move_slice_k_ix] s_cmp_le_u32 s[s_x], s[s_move_slice_k_ix] s_cselect_b32 s[s_tmp], s[s_dilation_w_x], s[s_dilation_w] s_cselect_b32 s[s_tmp+1], s[s_in_diff_hi], s[s_in_diff_wi] v_add_nc_u32 v[v_in_iwi+0], s[s_tmp], v[v_in_iwi+0] v_add_nc_u32 v[v_in_iwi+1], s[s_tmp], v[v_in_iwi+1] v_add_nc_u32 v[v_in_os+0], s[s_tmp+1], v[v_in_os+0] v_add_nc_u32 v[v_in_os+1], s[s_tmp+1], v[v_in_os+1] s_cbranch_scc0 igemm_fwd_btm_nhwc_fp16_256x4x16_r1_fma_acc_yx_x_end_2 s_mov_b32 s[s_move_slice_k_ix], 0 v_add_nc_i32 v[v_in_ihi+0], s[s_dilation_h], v[v_in_ihi+0] v_add_nc_i32 v[v_in_ihi+1], s[s_dilation_h], v[v_in_ihi+1] igemm_fwd_btm_nhwc_fp16_256x4x16_r1_fma_acc_yx_x_end_2: v_cmp_gt_u32 s[s_wi], v[v_in_iwi+0] v_cndmask_b32 v[v_in_flag+0], 0, 1 v_cmp_gt_u32 s[s_wi], v[v_in_iwi+1] v_cndmask_b32 v[v_in_flag+1], 0, 1 v_cmp_gt_u32 s[s_hi], v[v_in_ihi+0] v_cndmask_b32 v[v_in_flag+0], 0, v[v_in_flag+0] v_cmp_gt_u32 s[s_hi], v[v_in_ihi+1] v_cndmask_b32 v[v_in_flag+1], 0, v[v_in_flag+1] ;--- end move slice window ; s_waitcnt vmcnt(0) .v_clear_nc v_ax, 16 v_cmpx_le_u32 1, v[v_in_flag+0] global_load_dwordx4 v[v_ax+0:v_ax+3], v[v_in_os], s[s_p_in:s_p_in+1] global_load_dwordx4 v[v_ax+4:v_ax+7], v[v_in_os], s[s_p_in:s_p_in+1] offset:16 s_mov_b64 exec, -1 v_cmpx_le_u32 1, v[v_in_flag+1] global_load_dwordx4 v[v_ax+ 8:v_ax+11], v[v_in_os+1], s[s_p_in:s_p_in+1] global_load_dwordx4 v[v_ax+12:v_ax+15], v[v_in_os+1], s[s_p_in:s_p_in+1] offset:16 s_mov_b64 exec, -1 s_waitcnt vmcnt(4) lgkmcnt(4) .fma_1x4_fp16 v_c+ 0, v_ay + 0, v_b + 0 .fma_1x4_fp16 v_c+ 4, v_ay + 8, v_b + 0 .fma_1x4_fp16 v_c+ 0, v_ay + 1, v_b + 4 .fma_1x4_fp16 v_c+ 4, v_ay + 9, v_b + 4 .fma_1x4_fp16 v_c+ 0, v_ay + 2, v_b + 8 .fma_1x4_fp16 v_c+ 4, v_ay +10, v_b + 8 .fma_1x4_fp16 v_c+ 0, v_ay + 3, v_b +12 .fma_1x4_fp16 v_c+ 4, v_ay +11, v_b +12 ds_read_b128 v[v_b+ 0:v_b+ 3], v[v_sld_b_os], offset:k_n_dword*4*0 ds_read_b128 v[v_b+ 4:v_b+ 7], v[v_sld_b_os], offset:k_n_dword*4*1 ds_read_b128 v[v_b+ 8:v_b+11], v[v_sld_b_os], offset:k_n_dword*4*2 ds_read_b128 v[v_b+12:v_b+15], v[v_sld_b_os], offset:k_n_dword*4*3 s_waitcnt lgkmcnt(4) .fma_1x4_fp16 v_c+ 0, v_ay + 4, v_b +16 .fma_1x4_fp16 v_c+ 4, v_ay +12, v_b +16 .fma_1x4_fp16 v_c+ 0, v_ay + 5, v_b +20 .fma_1x4_fp16 v_c+ 4, v_ay +13, v_b +20 .fma_1x4_fp16 v_c+ 0, v_ay + 6, v_b +24 .fma_1x4_fp16 v_c+ 4, v_ay +14, v_b +24 .fma_1x4_fp16 v_c+ 0, v_ay + 7, v_b +28 .fma_1x4_fp16 v_c+ 4, v_ay +15, v_b +28 ds_read_b128 v[v_b+16:v_b+19], v[v_sld_b_os], offset:k_n_dword*4*4 ds_read_b128 v[v_b+20:v_b+23], v[v_sld_b_os], offset:k_n_dword*4*5 ds_read_b128 v[v_b+24:v_b+27], v[v_sld_b_os], offset:k_n_dword*4*6 ds_read_b128 v[v_b+28:v_b+31], v[v_sld_b_os], offset:k_n_dword*4*7 s_sub_i32 s[s_kitr], s[s_kitr], 16 v_add_nc_u32 v[v_sld_b_os], s[s_sld_b_stride], v[v_sld_b_os] ; accumulate sld_b_os s_cmp_gt_i32 s[s_kitr], 0 s_cbranch_scc1 L_igemm_fwd_btm_nhwc_fp16_256x4x16_r1_fma_body L_igemm_fwd_btm_nhwc_fp16_256x4x16_r1_fma_end: s_waitcnt vmcnt(0) v_mov_b32 v[v_ay + 0], v[v_ax + 0] v_mov_b32 v[v_ay + 1], v[v_ax + 1] v_mov_b32 v[v_ay + 2], v[v_ax + 2] v_mov_b32 v[v_ay + 3], v[v_ax + 3] v_mov_b32 v[v_ay + 4], v[v_ax + 4] v_mov_b32 v[v_ay + 5], v[v_ax + 5] v_mov_b32 v[v_ay + 6], v[v_ax + 6] v_mov_b32 v[v_ay + 7], v[v_ax + 7] v_mov_b32 v[v_ay + 8], v[v_ax + 8] v_mov_b32 v[v_ay + 9], v[v_ax + 9] v_mov_b32 v[v_ay +10], v[v_ax +10] v_mov_b32 v[v_ay +11], v[v_ax +11] v_mov_b32 v[v_ay +12], v[v_ax +12] v_mov_b32 v[v_ay +13], v[v_ax +13] v_mov_b32 v[v_ay +14], v[v_ax +14] v_mov_b32 v[v_ay +15], v[v_ax +15] L_igemm_fwd_btm_nhwc_fp16_256x4x16_r1_fma_end_1: s_waitcnt vmcnt(0) s_sub_i32 s[s_batch_m], s[s_batch_m], 1 v_add_nc_u32 v[v_ib], s[s_stride_m], v[v_ib] s_cmp_gt_i32 s[s_batch_m], 0 s_cbranch_scc0 L_igemm_fwd_btm_nhwc_fp16_256x4x16_r1_fma_end_not_load_next ; --- start move slice for batch m ; ihi = iho * s_stride_h + iy * s_dilation_h - s_pad_h ; iwi = iwo * s_stride_w + ix * s_dilation_w - s_pad_w ; we will update v_in_os below, so use this as v_tmp .mdiv_u32_rem_vs v_in_iwi,v_in_ihi,v_ib,s_magic_1,s_shift_m1,s_wo,v_in_os v_mul_u32_u24 v[v_in_ihi], s[s_stride_h], v[v_in_ihi] .v_clear_nc v_ax, 4 v_add_nc_u32 v[v_in_flag+1], s[s_ib_stride], v[v_ib] v_sub_nc_i32 v[v_in_ihi], v[v_in_ihi], s[s_pad_h] v_mul_u32_u24 v[v_in_iwi], s[s_stride_w], v[v_in_iwi] .v_clear_nc v_ax+4, 4 v_sub_nc_i32 v[v_in_iwi], v[v_in_iwi], s[s_pad_w] .mdiv_u32_rem_vs v_in_iwi+1,v_in_ihi+1,v_in_flag+1,s_magic_1,s_shift_m1,s_wo,v_in_os+1 v_mul_u32_u24 v[v_in_os], s[s_wi], v[v_in_ihi] v_cmp_gt_u32 s[s_hi], v[v_in_ihi] v_cndmask_b32 v[v_in_flag], 0, 1 v_add_nc_u32 v[v_in_os], v[v_in_iwi], v[v_in_os] v_cmp_gt_u32 s[s_wi], v[v_in_iwi] v_cndmask_b32 v[v_in_flag], 0, v[v_in_flag] v_mul_lo_u32 v[v_in_os], s[s_in_stride_wi], v[v_in_os] v_mul_u32_u24 v[v_in_ihi+1], s[s_stride_h], v[v_in_ihi+1] .v_clear_nc v_ax+8, 4 v_sub_nc_i32 v[v_in_ihi+1], v[v_in_ihi+1], s[s_pad_h] v_mul_u32_u24 v[v_in_iwi+1], s[s_stride_w], v[v_in_iwi+1] .v_clear_nc v_ax+12, 4 v_sub_nc_i32 v[v_in_iwi+1], v[v_in_iwi+1], s[s_pad_w] ; v_add_nc_u32 v[v_in_flag+2], s[s_ib_stride], v[v_in_flag+1] v_cmpx_le_u32 1, v[v_in_flag] global_load_dwordx4 v[v_ax+0:v_ax+3], v[v_in_os], s[s_p_in:s_p_in+1] global_load_dwordx4 v[v_ax+4:v_ax+7], v[v_in_os], s[s_p_in:s_p_in+1] offset:16 s_mov_b64 exec, -1 v_mul_u32_u24 v[v_in_os+1], s[s_wi], v[v_in_ihi+1] v_cmp_gt_u32 s[s_hi], v[v_in_ihi+1] v_cndmask_b32 v[v_in_flag+1], 0, 1 v_add_nc_u32 v[v_in_os+1], v[v_in_iwi+1], v[v_in_os+1] v_cmp_gt_u32 s[s_wi], v[v_in_iwi+1] v_cndmask_b32 v[v_in_flag+1], 0, v[v_in_flag+1] v_mul_lo_u32 v[v_in_os+1], s[s_in_stride_wi], v[v_in_os+1] v_cmpx_le_u32 1, v[v_in_flag+1] global_load_dwordx4 v[v_ax+ 8:v_ax+11], v[v_in_os+1], s[s_p_in:s_p_in+1] global_load_dwordx4 v[v_ax+12:v_ax+15], v[v_in_os+1], s[s_p_in:s_p_in+1] offset:16 s_mov_b64 exec, -1 s_mov_b32 s[s_move_slice_k_ix], 0 L_igemm_fwd_btm_nhwc_fp16_256x4x16_r1_fma_end_not_load_next: ; --- end move slice for batch m s_waitcnt lgkmcnt(4) .fma_1x4_fp16 v_c+ 0, v_ay + 0, v_b + 0 .fma_1x4_fp16 v_c+ 4, v_ay + 8, v_b + 0 .fma_1x4_fp16 v_c+ 0, v_ay + 1, v_b + 4 .fma_1x4_fp16 v_c+ 4, v_ay + 9, v_b + 4 .fma_1x4_fp16 v_c+ 0, v_ay + 2, v_b + 8 .fma_1x4_fp16 v_c+ 4, v_ay +10, v_b + 8 .fma_1x4_fp16 v_c+ 0, v_ay + 3, v_b +12 .fma_1x4_fp16 v_c+ 4, v_ay +11, v_b +12 s_waitcnt lgkmcnt(0) .fma_1x4_fp16 v_c+ 0, v_ay + 4, v_b +16 .fma_1x4_fp16 v_c+ 4, v_ay +12, v_b +16 .fma_1x4_fp16 v_c+ 0, v_ay + 5, v_b +20 .fma_1x4_fp16 v_c+ 4, v_ay +13, v_b +20 .fma_1x4_fp16 v_c+ 0, v_ay + 6, v_b +24 .fma_1x4_fp16 v_c+ 4, v_ay +14, v_b +24 .fma_1x4_fp16 v_c+ 0, v_ay + 7, v_b +28 .fma_1x4_fp16 v_c+ 4, v_ay +15, v_b +28 v_mov_b32 v[v_sld_b_os], 0 ; reset to start .activ_f32 v_c + 0, activ_mode, s_alpha, s_beta, s_gamma, v_tmp+0, v_tmp+1 .activ_f32 v_c + 1, activ_mode, s_alpha, s_beta, s_gamma, v_tmp+0, v_tmp+1 .activ_f32 v_c + 2, activ_mode, s_alpha, s_beta, s_gamma, v_tmp+0, v_tmp+1 .activ_f32 v_c + 3, activ_mode, s_alpha, s_beta, s_gamma, v_tmp+0, v_tmp+1 .activ_f32 v_c + 4, activ_mode, s_alpha, s_beta, s_gamma, v_tmp+0, v_tmp+1 .activ_f32 v_c + 5, activ_mode, s_alpha, s_beta, s_gamma, v_tmp+0, v_tmp+1 .activ_f32 v_c + 6, activ_mode, s_alpha, s_beta, s_gamma, v_tmp+0, v_tmp+1 .activ_f32 v_c + 7, activ_mode, s_alpha, s_beta, s_gamma, v_tmp+0, v_tmp+1 v_cvt_f16_f32 v[v_c + 0], v[v_c + 0] v_cvt_f16_f32 v[v_c + 1], v[v_c + 1] v_cvt_f16_f32 v[v_c + 2], v[v_c + 2] v_cvt_f16_f32 v[v_c + 3], v[v_c + 3] v_cvt_f16_f32 v[v_c + 4], v[v_c + 4] v_cvt_f16_f32 v[v_c + 5], v[v_c + 5] v_cvt_f16_f32 v[v_c + 6], v[v_c + 6] v_cvt_f16_f32 v[v_c + 7], v[v_c + 7] v_pack_b32_f16 v[v_c_buf+0], v[v_c+ 0], v[v_c+ 1] v_pack_b32_f16 v[v_c_buf+1], v[v_c+ 2], v[v_c+ 3] v_pack_b32_f16 v[v_c_buf+2], v[v_c+ 4], v[v_c+ 5] v_pack_b32_f16 v[v_c_buf+3], v[v_c+ 6], v[v_c+ 7] v_cmpx_le_u32 1, v[v_out_flag] global_store_dwordx2 v[v_out_os], v[v_c_buf+0:v_c_buf+1], s[s_p_out:s_p_out+1] s_mov_b64 exec, -1 v_cmpx_le_u32 1, v[v_out_flag+1] global_store_dwordx2 v[v_out_os+1], v[v_c_buf+2:v_c_buf+3], s[s_p_out:s_p_out+1] s_mov_b64 exec, -1 s_cmp_le_i32 s[s_batch_m], 0 s_cbranch_scc1 L_igemm_fwd_btm_nhwc_fp16_256x4x16_r1_end ds_read_b128 v[v_b+ 0:v_b+ 3], v[v_sld_b_os], offset:k_n_dword*4*0 ds_read_b128 v[v_b+ 4:v_b+ 7], v[v_sld_b_os], offset:k_n_dword*4*1 ds_read_b128 v[v_b+ 8:v_b+11], v[v_sld_b_os], offset:k_n_dword*4*2 ds_read_b128 v[v_b+12:v_b+15], v[v_sld_b_os], offset:k_n_dword*4*3 ds_read_b128 v[v_b+16:v_b+19], v[v_sld_b_os], offset:k_n_dword*4*4 ds_read_b128 v[v_b+20:v_b+23], v[v_sld_b_os], offset:k_n_dword*4*5 ds_read_b128 v[v_b+24:v_b+27], v[v_sld_b_os], offset:k_n_dword*4*6 ds_read_b128 v[v_b+28:v_b+31], v[v_sld_b_os], offset:k_n_dword*4*7 .v_clear_nc v_c, 8 v_add_nc_u32 v[v_sld_b_os], s[s_sld_b_stride], v[v_sld_b_os] ; accumulate sld_b_os v_add_nc_u32 v[v_out_os], s[s_out_stride], v[v_out_os] s_sub_i32 s[s_kitr], s[s_wei_stride_k], 16 v_add_nc_u32 v[v_out_os+1], s[s_out_stride], v[v_out_os+1] v_cmp_gt_u32 s[s_out_stride_n], v[v_out_os] v_cndmask_b32 v[v_out_flag], 0, 1 s_cmp_gt_i32 s[s_kitr], 0 v_cmp_gt_u32 s[s_out_stride_n], v[v_out_os+1] v_cndmask_b32 v[v_out_flag+1], 0, 1 s_cbranch_scc0 L_igemm_fwd_btm_nhwc_fp16_256x4x16_r1_fma_end s_branch L_igemm_fwd_btm_nhwc_fp16_256x4x16_r1_fma_body L_igemm_fwd_btm_nhwc_fp16_256x4x16_r1_end: s_endpgm ; LDS: 1 * 4 * 4 * 128 ; r1 4dword 4 threads .rodata .p2align 6 .amdhsa_kernel igemm_fwd_btm_nhwc_fp16_256x4x16_r1 .amdhsa_group_segment_fixed_size 2048 .amdhsa_user_sgpr_kernarg_segment_ptr 1 .amdhsa_system_sgpr_workgroup_id_x 1 .amdhsa_system_sgpr_workgroup_id_y 1 .amdhsa_system_sgpr_workgroup_id_z 1 .amdhsa_system_vgpr_workitem_id 0 .amdhsa_next_free_vgpr 88 .amdhsa_next_free_sgpr 62 .amdhsa_ieee_mode 0 .amdhsa_dx10_clamp 0 .amdhsa_wavefront_size32 1 .amdhsa_workgroup_processor_mode 0 .end_amdhsa_kernel
; A075682: First differences of A075681. ; 0,2,19,39,61,86,114,145,179,216,256,299,345,394,446,501,559,620,684,751,821,894,970,1049,1131,1216,1304,1395,1489,1586,1686,1789,1895,2004,2116,2231,2349,2470,2594,2721,2851,2984,3120,3259,3401,3546 mov $4,$0 lpb $0 sub $0,1 trn $0,1 add $0,1 add $3,6 sub $4,1 add $4,$0 add $5,1 add $6,1 lpe add $3,$4 mov $0,$3 add $0,$6 mov $2,3 add $2,$6 add $2,$0 add $4,$6 add $4,$2 sub $5,1 trn $5,1 sub $0,$5 mul $6,2 sub $0,$6 mov $1,$0 mov $3,3 sub $4,4 add $3,$4 add $1,$3 trn $1,3
<% import collections import pwnlib.abi import pwnlib.constants import pwnlib.shellcraft import six %> <%docstring>flistxattr(fd, list, size) -> str Invokes the syscall flistxattr. See 'man 2 flistxattr' for more information. Arguments: fd(int): fd list(char*): list size(size_t): size Returns: ssize_t </%docstring> <%page args="fd=0, list=0, size=0"/> <% abi = pwnlib.abi.ABI.syscall() stack = abi.stack regs = abi.register_arguments[1:] allregs = pwnlib.shellcraft.registers.current() can_pushstr = ['list'] can_pushstr_array = [] argument_names = ['fd', 'list', 'size'] argument_values = [fd, list, size] # 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_flistxattr']: if hasattr(pwnlib.constants, syscall): break else: raise Exception("Could not locate any syscalls: %r" % syscalls) %> /* flistxattr(${', '.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)}
// Copyright (c) 2015-2018 The PIVX developers // Copyright (c) 2019 The Profitbase developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "zpbcchain.h" #include "invalid.h" #include "main.h" #include "txdb.h" #include "ui_interface.h" // 6 comes from OPCODE (1) + vch.size() (1) + BIGNUM size (4) #define SCRIPT_OFFSET 6 // For Script size (BIGNUM/Uint256 size) #define BIGNUM_SIZE 4 bool BlockToMintValueVector(const CBlock& block, const libzerocoin::CoinDenomination denom, vector<CBigNum>& vValues) { for (const CTransaction& tx : block.vtx) { if(!tx.IsZerocoinMint()) continue; for (const CTxOut& txOut : tx.vout) { if(!txOut.scriptPubKey.IsZerocoinMint()) continue; CValidationState state; libzerocoin::PublicCoin coin(Params().Zerocoin_Params(false)); if(!TxOutToPublicCoin(txOut, coin, state)) return false; if (coin.getDenomination() != denom) continue; vValues.push_back(coin.getValue()); } } return true; } bool BlockToPubcoinList(const CBlock& block, std::list<libzerocoin::PublicCoin>& listPubcoins, bool fFilterInvalid) { for (const CTransaction& tx : block.vtx) { if(!tx.IsZerocoinMint()) continue; // Filter out mints that have used invalid outpoints if (fFilterInvalid) { bool fValid = true; for (const CTxIn& in : tx.vin) { if (!ValidOutPoint(in.prevout, INT_MAX)) { fValid = false; break; } } if (!fValid) continue; } uint256 txHash = tx.GetHash(); for (unsigned int i = 0; i < tx.vout.size(); i++) { //Filter out mints that use invalid outpoints - edge case: invalid spend with minted change if (fFilterInvalid && !ValidOutPoint(COutPoint(txHash, i), INT_MAX)) break; const CTxOut txOut = tx.vout[i]; if(!txOut.scriptPubKey.IsZerocoinMint()) continue; CValidationState state; libzerocoin::PublicCoin pubCoin(Params().Zerocoin_Params(false)); if(!TxOutToPublicCoin(txOut, pubCoin, state)) return false; listPubcoins.emplace_back(pubCoin); } } return true; } //return a list of zerocoin mints contained in a specific block bool BlockToZerocoinMintList(const CBlock& block, std::list<CZerocoinMint>& vMints, bool fFilterInvalid) { for (const CTransaction& tx : block.vtx) { if(!tx.IsZerocoinMint()) continue; // Filter out mints that have used invalid outpoints if (fFilterInvalid) { bool fValid = true; for (const CTxIn& in : tx.vin) { if (!ValidOutPoint(in.prevout, INT_MAX)) { fValid = false; break; } } if (!fValid) continue; } uint256 txHash = tx.GetHash(); for (unsigned int i = 0; i < tx.vout.size(); i++) { //Filter out mints that use invalid outpoints - edge case: invalid spend with minted change if (fFilterInvalid && !ValidOutPoint(COutPoint(txHash, i), INT_MAX)) break; const CTxOut txOut = tx.vout[i]; if(!txOut.scriptPubKey.IsZerocoinMint()) continue; CValidationState state; libzerocoin::PublicCoin pubCoin(Params().Zerocoin_Params(false)); if(!TxOutToPublicCoin(txOut, pubCoin, state)) return false; //version should not actually matter here since it is just a reference to the pubcoin, not to the privcoin uint8_t version = 1; CZerocoinMint mint = CZerocoinMint(pubCoin.getDenomination(), pubCoin.getValue(), 0, 0, false, version, nullptr); mint.SetTxHash(tx.GetHash()); vMints.push_back(mint); } } return true; } void FindMints(std::vector<CMintMeta> vMintsToFind, std::vector<CMintMeta>& vMintsToUpdate, std::vector<CMintMeta>& vMissingMints) { // see which mints are in our public zerocoin database. The mint should be here if it exists, unless // something went wrong for (CMintMeta meta : vMintsToFind) { uint256 txHash; if (!zerocoinDB->ReadCoinMint(meta.hashPubcoin, txHash)) { vMissingMints.push_back(meta); continue; } // make sure the txhash and block height meta data are correct for this mint CTransaction tx; uint256 hashBlock; if (!GetTransaction(txHash, tx, hashBlock, true)) { LogPrintf("%s : cannot find tx %s\n", __func__, txHash.GetHex()); vMissingMints.push_back(meta); continue; } if (!mapBlockIndex.count(hashBlock)) { LogPrintf("%s : cannot find block %s\n", __func__, hashBlock.GetHex()); vMissingMints.push_back(meta); continue; } //see if this mint is spent uint256 hashTxSpend = 0; bool fSpent = zerocoinDB->ReadCoinSpend(meta.hashSerial, hashTxSpend); //if marked as spent, check that it actually made it into the chain CTransaction txSpend; uint256 hashBlockSpend; if (fSpent && !GetTransaction(hashTxSpend, txSpend, hashBlockSpend, true)) { LogPrintf("%s : cannot find spend tx %s\n", __func__, hashTxSpend.GetHex()); meta.isUsed = false; vMintsToUpdate.push_back(meta); continue; } //The mint has been incorrectly labelled as spent in zerocoinDB and needs to be undone int nHeightTx = 0; uint256 hashSerial = meta.hashSerial; uint256 txidSpend; if (fSpent && !IsSerialInBlockchain(hashSerial, nHeightTx, txidSpend)) { LogPrintf("%s : cannot find block %s. Erasing coinspend from zerocoinDB.\n", __func__, hashBlockSpend.GetHex()); meta.isUsed = false; vMintsToUpdate.push_back(meta); continue; } // is the denomination correct? for (auto& out : tx.vout) { if (!out.IsZerocoinMint()) continue; libzerocoin::PublicCoin pubcoin(Params().Zerocoin_Params(meta.nVersion < libzerocoin::PrivateCoin::PUBKEY_VERSION)); CValidationState state; TxOutToPublicCoin(out, pubcoin, state); if (GetPubCoinHash(pubcoin.getValue()) == meta.hashPubcoin && pubcoin.getDenomination() != meta.denom) { LogPrintf("%s: found mismatched denom pubcoinhash = %s\n", __func__, meta.hashPubcoin.GetHex()); meta.denom = pubcoin.getDenomination(); vMintsToUpdate.emplace_back(meta); } } // if meta data is correct, then no need to update if (meta.txid == txHash && meta.nHeight == mapBlockIndex[hashBlock]->nHeight && meta.isUsed == fSpent) continue; //mark this mint for update meta.txid = txHash; meta.nHeight = mapBlockIndex[hashBlock]->nHeight; meta.isUsed = fSpent; LogPrintf("%s: found updates for pubcoinhash = %s\n", __func__, meta.hashPubcoin.GetHex()); vMintsToUpdate.push_back(meta); } } int GetZerocoinStartHeight() { return Params().Zerocoin_StartHeight(); } bool GetZerocoinMint(const CBigNum& bnPubcoin, uint256& txHash) { txHash = 0; return zerocoinDB->ReadCoinMint(bnPubcoin, txHash); } bool IsPubcoinInBlockchain(const uint256& hashPubcoin, uint256& txid) { txid = 0; return zerocoinDB->ReadCoinMint(hashPubcoin, txid); } bool IsSerialKnown(const CBigNum& bnSerial) { uint256 txHash = 0; return zerocoinDB->ReadCoinSpend(bnSerial, txHash); } bool IsSerialInBlockchain(const CBigNum& bnSerial, int& nHeightTx) { uint256 txHash = 0; // if not in zerocoinDB then its not in the blockchain if (!zerocoinDB->ReadCoinSpend(bnSerial, txHash)) return false; return IsTransactionInChain(txHash, nHeightTx); } bool IsSerialInBlockchain(const uint256& hashSerial, int& nHeightTx, uint256& txidSpend) { CTransaction tx; return IsSerialInBlockchain(hashSerial, nHeightTx, txidSpend, tx); } bool IsSerialInBlockchain(const uint256& hashSerial, int& nHeightTx, uint256& txidSpend, CTransaction& tx) { txidSpend = 0; // if not in zerocoinDB then its not in the blockchain if (!zerocoinDB->ReadCoinSpend(hashSerial, txidSpend)) return false; return IsTransactionInChain(txidSpend, nHeightTx, tx); } std::string ReindexZerocoinDB() { if (!zerocoinDB->WipeCoins("spends") || !zerocoinDB->WipeCoins("mints")) { return _("Failed to wipe zerocoinDB"); } uiInterface.ShowProgress(_("Reindexing zerocoin database..."), 0); CBlockIndex* pindex = chainActive[Params().Zerocoin_StartHeight()]; std::vector<std::pair<libzerocoin::CoinSpend, uint256> > vSpendInfo; std::vector<std::pair<libzerocoin::PublicCoin, uint256> > vMintInfo; while (pindex) { uiInterface.ShowProgress(_("Reindexing zerocoin database..."), std::max(1, std::min(99, (int)((double)(pindex->nHeight - Params().Zerocoin_StartHeight()) / (double)(chainActive.Height() - Params().Zerocoin_StartHeight()) * 100)))); if (pindex->nHeight % 1000 == 0) LogPrintf("Reindexing zerocoin : block %d...\n", pindex->nHeight); CBlock block; if (!ReadBlockFromDisk(block, pindex)) { return _("Reindexing zerocoin failed"); } for (const CTransaction& tx : block.vtx) { for (unsigned int i = 0; i < tx.vin.size(); i++) { if (tx.IsCoinBase()) break; if (tx.ContainsZerocoins()) { uint256 txid = tx.GetHash(); //Record Serials if (tx.IsZerocoinSpend()) { for (auto& in : tx.vin) { if (!in.scriptSig.IsZerocoinSpend()) continue; libzerocoin::CoinSpend spend = TxInToZerocoinSpend(in); vSpendInfo.push_back(make_pair(spend, txid)); } } //Record mints if (tx.IsZerocoinMint()) { for (auto& out : tx.vout) { if (!out.IsZerocoinMint()) continue; CValidationState state; libzerocoin::PublicCoin coin(Params().Zerocoin_Params(pindex->nHeight < Params().Zerocoin_Block_V2_Start())); TxOutToPublicCoin(out, coin, state); vMintInfo.push_back(make_pair(coin, txid)); } } } } } // Flush the zerocoinDB to disk every 100 blocks if (pindex->nHeight % 100 == 0) { if ((!vSpendInfo.empty() && !zerocoinDB->WriteCoinSpendBatch(vSpendInfo)) || (!vMintInfo.empty() && !zerocoinDB->WriteCoinMintBatch(vMintInfo))) return _("Error writing zerocoinDB to disk"); vSpendInfo.clear(); vMintInfo.clear(); } pindex = chainActive.Next(pindex); } uiInterface.ShowProgress("", 100); // Final flush to disk in case any remaining information exists if ((!vSpendInfo.empty() && !zerocoinDB->WriteCoinSpendBatch(vSpendInfo)) || (!vMintInfo.empty() && !zerocoinDB->WriteCoinMintBatch(vMintInfo))) return _("Error writing zerocoinDB to disk"); uiInterface.ShowProgress("", 100); return ""; } bool RemoveSerialFromDB(const CBigNum& bnSerial) { return zerocoinDB->EraseCoinSpend(bnSerial); } libzerocoin::CoinSpend TxInToZerocoinSpend(const CTxIn& txin) { // extract the CoinSpend from the txin std::vector<char, zero_after_free_allocator<char> > dataTxIn; dataTxIn.insert(dataTxIn.end(), txin.scriptSig.begin() + BIGNUM_SIZE, txin.scriptSig.end()); CDataStream serializedCoinSpend(dataTxIn, SER_NETWORK, PROTOCOL_VERSION); libzerocoin::ZerocoinParams* paramsAccumulator = Params().Zerocoin_Params(chainActive.Height() < Params().Zerocoin_Block_V2_Start()); libzerocoin::CoinSpend spend(Params().Zerocoin_Params(true), paramsAccumulator, serializedCoinSpend); return spend; } bool TxOutToPublicCoin(const CTxOut& txout, libzerocoin::PublicCoin& pubCoin, CValidationState& state) { CBigNum publicZerocoin; vector<unsigned char> vchZeroMint; vchZeroMint.insert(vchZeroMint.end(), txout.scriptPubKey.begin() + SCRIPT_OFFSET, txout.scriptPubKey.begin() + txout.scriptPubKey.size()); publicZerocoin.setvch(vchZeroMint); libzerocoin::CoinDenomination denomination = libzerocoin::AmountToZerocoinDenomination(txout.nValue); LogPrint("zero", "%s ZCPRINT denomination %d pubcoin %s\n", __func__, denomination, publicZerocoin.GetHex()); if (denomination == libzerocoin::ZQ_ERROR) return state.DoS(100, error("TxOutToPublicCoin : txout.nValue is not correct")); libzerocoin::PublicCoin checkPubCoin(Params().Zerocoin_Params(false), publicZerocoin, denomination); pubCoin = checkPubCoin; return true; } //return a list of zerocoin spends contained in a specific block, list may have many denominations std::list<libzerocoin::CoinDenomination> ZerocoinSpendListFromBlock(const CBlock& block, bool fFilterInvalid) { std::list<libzerocoin::CoinDenomination> vSpends; for (const CTransaction& tx : block.vtx) { if (!tx.IsZerocoinSpend()) continue; for (const CTxIn& txin : tx.vin) { if (!txin.scriptSig.IsZerocoinSpend()) continue; if (fFilterInvalid) { libzerocoin::CoinSpend spend = TxInToZerocoinSpend(txin); if (invalid_out::ContainsSerial(spend.getCoinSerialNumber())) continue; } libzerocoin::CoinDenomination c = libzerocoin::IntToZerocoinDenomination(txin.nSequence); vSpends.push_back(c); } } return vSpends; }
_MeetLaprasGuyText:: text "Oh! Hi! You're" line "not a ROCKET! You" cont "came to save us?" cont "Why, thank you!" para "I want you to" line "have this #MON" cont "for saving us." prompt _HeresYourLaprasText:: text "It's LAPRAS. It's" line "very intelligent." para "We kept it in our" line "lab, but it will" cont "be much better" cont "off with you!" para "I think you will" line "be a good trainer" cont "for LAPRAS!" para "It's a good" line "swimmer. It'll" cont "give you a lift!" done _LaprasGuyText:: text "TEAM ROCKET's" line "BOSS went to the" cont "boardroom! Is our" cont "PRESIDENT OK?" done _LaprasGuySavedText:: text "Saved at last!" line "Thank you!" done _SilphCo7Text_51e00:: text "TEAM ROCKET was" line "after the MASTER" cont "BALL which will" cont "catch any #MON!" done _CanceledMasterBallText:: text "We canceled the" line "MASTER BALL" cont "project because" cont "of TEAM ROCKET." done _SilphCo7Text_51e23:: text "It would be bad" line "if TEAM ROCKET" cont "took over SILPH" cont "or our #MON!" done _SilphCo7Text_51e28:: text "Wow! You chased" line "off TEAM ROCKET" cont "all by yourself?" done _SilphCo7Text_51e46:: text "You! It's really" line "dangerous here!" cont "You came to save" cont "me? You can't!" done _SilphCo7Text_51e4b:: text "Safe at last!" line "Oh thank you!" done _SilphCo7BattleText1:: text "Aha! I smell a" line "little rat!" done _SilphCo7EndBattleText1:: text "Lights" line "out!" prompt _SilphCo7AfterBattleText1:: text "You won't find my" line "BOSS by just" cont "scurrying around!" done _SilphCo7BattleText2:: text "Heheh!" para "You mistook me for" line "a SILPH worker?" done _SilphCo7EndBattleText2:: text "I'm" line "done!" prompt _SilphCo7AfterBattleText2:: text "Despite your age," line "you are a skilled" cont "trainer!" done _SilphCo7BattleText3:: text "I am one of the 4" line "ROCKET BROTHERS!" done _SilphCo7EndBattleText3:: text "Aack!" line "Brothers, I lost!" prompt _SilphCo7AfterBattleText3:: text "Doesn't matter." line "My brothers will" cont "repay the favor!" done _SilphCo7BattleText4:: text "A child intruder?" line "That must be you!" done _SilphCo7EndBattleText4:: text "Fine!" line "I lost!" prompt _SilphCo7AfterBattleText4:: text "Go on home" line "before my BOSS" cont "gets ticked off!" done _SilphCo7Text_51ebe:: text $53, ": What" line "kept you ", $52, "?" done _SilphCo7Text_51ec3:: text $53, ": Hahaha!" line "I thought you'd" cont "turn up if I" cont "waited here!" para "I guess TEAM" line "ROCKET slowed you" cont "down! Not that I" cont "care!" para "I saw you in" line "SAFFRON, so I" cont "decided to see if" cont "you got better!" done _SilphCo7Text_51ec8:: text "Oh-oh!" line "So, you are ready" cont "for BOSS ROCKET!" prompt _SilphCo7Text_51ecd:: text $53, ": How can" line "I put this?" para "You're not good" line "enough to play" cont "with us big boys!" prompt _SilphCo7Text_51ed2:: text "Well, ", $52, "!" para "I'm moving on up" line "and ahead!" para "By checking my" line "#DEX, I'm" cont "starting to see" cont "what's strong and" cont "how they evolve!" para "I'm going to the" line "#MON LEAGUE" cont "to boot out the" cont "ELITE FOUR!" para "I'll become the" line "world's most" cont "powerful trainer!" para $52, ", well" line "good luck to you!" cont "Don't sweat it!" cont "Smell ya!" done
; double fdim(double x, double y) SECTION code_fp_math48 PUBLIC am48_fdim EXTERN am48_dcmp, am48_dsub, am48_derror_znc am48_fdim: ; return the positive difference between AC' and AC ; ; if AC' > AC return AC' - AC ; if AC' <= AC return 0 ; ; enter : AC = double y ; AC' = double x ; ; exit : success ; ; AC' = fdim(x,y) ; carry reset ; ; fail if overflow ; ; AC' = +-inf ; carry set, errno set ; ; uses : af, af', bc', de', hl' call am48_dcmp jp c, am48_dsub ; if x > y return x - y jp am48_derror_znc
/* * Copyright (C) 2013 The Android Open Source Project * * 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 "third_party/android_prediction/suggest/policyimpl/dictionary/structure/v4/content/bigram_dict_content.h" #include "third_party/android_prediction/suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer.h" namespace latinime { const int BigramDictContent::INVALID_LINKED_ENTRY_POS = Ver4DictConstants::NOT_A_TERMINAL_ID; const BigramEntry BigramDictContent::getBigramEntryAndAdvancePosition( int *const bigramEntryPos) const { const BufferWithExtendableBuffer *const bigramListBuffer = getContentBuffer(); const int bigramEntryTailPos = (*bigramEntryPos) + getBigramEntrySize(); if (*bigramEntryPos < 0 || bigramEntryTailPos > bigramListBuffer->getTailPosition()) { AKLOGE("Invalid bigram entry position. bigramEntryPos: %d, bigramEntryTailPos: %d, " "bufSize: %d", *bigramEntryPos, bigramEntryTailPos, bigramListBuffer->getTailPosition()); ASSERT(false); return BigramEntry(false /* hasNext */, NOT_A_PROBABILITY, Ver4DictConstants::NOT_A_TERMINAL_ID); } const int bigramFlags = bigramListBuffer->readUintAndAdvancePosition( Ver4DictConstants::BIGRAM_FLAGS_FIELD_SIZE, bigramEntryPos); const bool isLink = (bigramFlags & Ver4DictConstants::BIGRAM_IS_LINK_MASK) != 0; int probability = NOT_A_PROBABILITY; int timestamp = NOT_A_TIMESTAMP; int level = 0; int count = 0; if (mHasHistoricalInfo) { timestamp = bigramListBuffer->readUintAndAdvancePosition( Ver4DictConstants::TIME_STAMP_FIELD_SIZE, bigramEntryPos); level = bigramListBuffer->readUintAndAdvancePosition( Ver4DictConstants::WORD_LEVEL_FIELD_SIZE, bigramEntryPos); count = bigramListBuffer->readUintAndAdvancePosition( Ver4DictConstants::WORD_COUNT_FIELD_SIZE, bigramEntryPos); } else { probability = bigramListBuffer->readUintAndAdvancePosition( Ver4DictConstants::PROBABILITY_SIZE, bigramEntryPos); } const int encodedTargetTerminalId = bigramListBuffer->readUintAndAdvancePosition( Ver4DictConstants::BIGRAM_TARGET_TERMINAL_ID_FIELD_SIZE, bigramEntryPos); const int targetTerminalId = (encodedTargetTerminalId == Ver4DictConstants::INVALID_BIGRAM_TARGET_TERMINAL_ID) ? Ver4DictConstants::NOT_A_TERMINAL_ID : encodedTargetTerminalId; if (isLink) { const int linkedEntryPos = targetTerminalId; if (linkedEntryPos == INVALID_LINKED_ENTRY_POS) { // Bigram list terminator is found. return BigramEntry(false /* hasNext */, NOT_A_PROBABILITY, Ver4DictConstants::NOT_A_TERMINAL_ID); } *bigramEntryPos = linkedEntryPos; return getBigramEntryAndAdvancePosition(bigramEntryPos); } // hasNext is always true because we should continue to read the next entry until the terminator // is found. if (mHasHistoricalInfo) { const HistoricalInfo historicalInfo(timestamp, level, count); return BigramEntry(true /* hasNext */, probability, &historicalInfo, targetTerminalId); } else { return BigramEntry(true /* hasNext */, probability, targetTerminalId); } } bool BigramDictContent::writeBigramEntryAndAdvancePosition( const BigramEntry *const bigramEntryToWrite, int *const entryWritingPos) { return writeBigramEntryAttributesAndAdvancePosition(false /* isLink */, bigramEntryToWrite->getProbability(), bigramEntryToWrite->getTargetTerminalId(), bigramEntryToWrite->getHistoricalInfo()->getTimeStamp(), bigramEntryToWrite->getHistoricalInfo()->getLevel(), bigramEntryToWrite->getHistoricalInfo()->getCount(), entryWritingPos); } bool BigramDictContent::writeBigramEntryAttributesAndAdvancePosition( const bool isLink, const int probability, const int targetTerminalId, const int timestamp, const int level, const int count, int *const entryWritingPos) { BufferWithExtendableBuffer *const bigramListBuffer = getWritableContentBuffer(); const int bigramFlags = isLink ? Ver4DictConstants::BIGRAM_IS_LINK_MASK : 0; if (!bigramListBuffer->writeUintAndAdvancePosition(bigramFlags, Ver4DictConstants::BIGRAM_FLAGS_FIELD_SIZE, entryWritingPos)) { AKLOGE("Cannot write bigram flags. pos: %d, flags: %x", *entryWritingPos, bigramFlags); return false; } if (mHasHistoricalInfo) { if (!bigramListBuffer->writeUintAndAdvancePosition(timestamp, Ver4DictConstants::TIME_STAMP_FIELD_SIZE, entryWritingPos)) { AKLOGE("Cannot write bigram timestamps. pos: %d, timestamp: %d", *entryWritingPos, timestamp); return false; } if (!bigramListBuffer->writeUintAndAdvancePosition(level, Ver4DictConstants::WORD_LEVEL_FIELD_SIZE, entryWritingPos)) { AKLOGE("Cannot write bigram level. pos: %d, level: %d", *entryWritingPos, level); return false; } if (!bigramListBuffer->writeUintAndAdvancePosition(count, Ver4DictConstants::WORD_COUNT_FIELD_SIZE, entryWritingPos)) { AKLOGE("Cannot write bigram count. pos: %d, count: %d", *entryWritingPos, count); return false; } } else { if (!bigramListBuffer->writeUintAndAdvancePosition(probability, Ver4DictConstants::PROBABILITY_SIZE, entryWritingPos)) { AKLOGE("Cannot write bigram probability. pos: %d, probability: %d", *entryWritingPos, probability); return false; } } const int targetTerminalIdToWrite = (targetTerminalId == Ver4DictConstants::NOT_A_TERMINAL_ID) ? Ver4DictConstants::INVALID_BIGRAM_TARGET_TERMINAL_ID : targetTerminalId; if (!bigramListBuffer->writeUintAndAdvancePosition(targetTerminalIdToWrite, Ver4DictConstants::BIGRAM_TARGET_TERMINAL_ID_FIELD_SIZE, entryWritingPos)) { AKLOGE("Cannot write bigram target terminal id. pos: %d, target terminal id: %d", *entryWritingPos, targetTerminalId); return false; } return true; } bool BigramDictContent::writeLink(const int linkedEntryPos, const int writingPos) { const int targetTerminalId = linkedEntryPos; int pos = writingPos; return writeBigramEntryAttributesAndAdvancePosition(true /* isLink */, NOT_A_PROBABILITY /* probability */, targetTerminalId, NOT_A_TIMESTAMP, 0 /* level */, 0 /* count */, &pos); } bool BigramDictContent::runGC(const TerminalPositionLookupTable::TerminalIdMap *const terminalIdMap, const BigramDictContent *const originalBigramDictContent, int *const outBigramEntryCount) { for (TerminalPositionLookupTable::TerminalIdMap::const_iterator it = terminalIdMap->begin(); it != terminalIdMap->end(); ++it) { const int originalBigramListPos = originalBigramDictContent->getBigramListHeadPos(it->first); if (originalBigramListPos == NOT_A_DICT_POS) { // This terminal does not have a bigram list. continue; } const int bigramListPos = getContentBuffer()->getTailPosition(); int bigramEntryCount = 0; // Copy bigram list with GC from original content. if (!runGCBigramList(originalBigramListPos, originalBigramDictContent, bigramListPos, terminalIdMap, &bigramEntryCount)) { AKLOGE("Cannot complete GC for the bigram list. original pos: %d, pos: %d", originalBigramListPos, bigramListPos); return false; } if (bigramEntryCount == 0) { // All bigram entries are useless. This terminal does not have a bigram list. continue; } *outBigramEntryCount += bigramEntryCount; // Set bigram list position to the lookup table. if (!getUpdatableAddressLookupTable()->set(it->second, bigramListPos)) { AKLOGE("Cannot set bigram list position. terminal id: %d, pos: %d", it->second, bigramListPos); return false; } } return true; } // Returns whether GC for the bigram list was succeeded or not. bool BigramDictContent::runGCBigramList(const int bigramListPos, const BigramDictContent *const sourceBigramDictContent, const int toPos, const TerminalPositionLookupTable::TerminalIdMap *const terminalIdMap, int *const outEntryCount) { bool hasNext = true; int readingPos = bigramListPos; int writingPos = toPos; while (hasNext) { const BigramEntry originalBigramEntry = sourceBigramDictContent->getBigramEntryAndAdvancePosition(&readingPos); hasNext = originalBigramEntry.hasNext(); if (!originalBigramEntry.isValid()) { continue; } TerminalPositionLookupTable::TerminalIdMap::const_iterator it = terminalIdMap->find(originalBigramEntry.getTargetTerminalId()); if (it == terminalIdMap->end()) { // Target word has been removed. continue; } const BigramEntry updatedBigramEntry = originalBigramEntry.updateTargetTerminalIdAndGetEntry(it->second); if (!writeBigramEntryAndAdvancePosition(&updatedBigramEntry, &writingPos)) { AKLOGE("Cannot write bigram entry to run GC. pos: %d", writingPos); return false; } *outEntryCount += 1; } if (*outEntryCount > 0) { if (!writeTerminator(writingPos)) { AKLOGE("Cannot write terminator to run GC. pos: %d", writingPos); return false; } } return true; } } // namespace latinime
#pragma once // This file is generated from the Game's Reflection data #include <cstdint> #include <RED4ext/Common.hpp> #include <RED4ext/Scripting/Natives/Generated/game/ui/BaseItemDataSource.hpp> namespace RED4ext { namespace game::ui { struct ItemDataViewWrapper : game::ui::BaseItemDataSource { static constexpr const char* NAME = "gameuiItemDataViewWrapper"; static constexpr const char* ALIAS = NAME; }; RED4EXT_ASSERT_SIZE(ItemDataViewWrapper, 0x48); } // namespace game::ui } // namespace RED4ext
############################################################################### # Copyright 2018 Intel Corporation # All Rights Reserved. # # If this software was obtained under the Intel Simplified Software License, # the following terms apply: # # The source code, information and material ("Material") contained herein is # owned by Intel Corporation or its suppliers or licensors, and title to such # Material remains with Intel Corporation or its suppliers or licensors. The # Material contains proprietary information of Intel or its suppliers and # licensors. The Material is protected by worldwide copyright laws and treaty # provisions. No part of the Material may be used, copied, reproduced, # modified, published, uploaded, posted, transmitted, distributed or disclosed # in any way without Intel's prior express written permission. No license under # any patent, copyright or other intellectual property rights in the Material # is granted to or conferred upon you, either expressly, by implication, # inducement, estoppel or otherwise. Any license under such intellectual # property rights must be express and approved by Intel in writing. # # Unless otherwise agreed by Intel in writing, you may not remove or alter this # notice or any other notice embedded in Materials by Intel or Intel's # suppliers or licensors in any way. # # # If this software was obtained under the Apache License, Version 2.0 (the # "License"), the following terms apply: # # You may not use this file except in compliance with the License. You may # obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 # # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # # See the License for the specific language governing permissions and # limitations under the License. ############################################################################### .section .note.GNU-stack,"",%progbits .text .p2align 5, 0x90 .globl e9_Touch_SubsDword_8uT .type e9_Touch_SubsDword_8uT, @function e9_Touch_SubsDword_8uT: movslq %edx, %r8 xor %rcx, %rcx .Ltouch_tblgas_1: mov (%rsi,%rcx), %rax add $(64), %rcx cmp %r8, %rcx jl .Ltouch_tblgas_1 mov %rdi, %rax and $(255), %rax movzbq (%rsi,%rax), %rax shr $(8), %rdi mov %rdi, %r9 and $(255), %r9 movzbq (%r9,%rsi), %r9 shl $(8), %r9 shr $(8), %rdi mov %rdi, %rcx and $(255), %rcx movzbq (%rsi,%rcx), %rcx shl $(16), %rcx shr $(8), %rdi mov %rdi, %rdx and $(255), %rdx movzbq (%rsi,%rdx), %rdx shl $(24), %rdx or %r9, %rax or %rcx, %rax or %rdx, %rax vzeroupper ret .Lfe1: .size e9_Touch_SubsDword_8uT, .Lfe1-(e9_Touch_SubsDword_8uT)
; ; ZX Spectrum specific routines ; by Stefano Bodrato, 22/06/2006 ; Fixed by Antonio Schifano, Dec 2008 ; ; Copy a variable from basic ; ; int __CALLEE__ zx_getstr_callee(char variable, char *value); ; ; Debugged version by Antonio Schifano, 29/12/2008 ; ; $Id: zx_getstr_callee.asm,v 1.2 2008/12/31 13:58:11 stefano Exp $ ; XLIB zx_getstr_callee XDEF ASMDISP_ZX_GETSTR_CALLEE zx_getstr_callee: pop bc pop hl pop de push bc ; enter : hl = char *value ; e = char variable .asmentry ld a,e and 95 ld d,a push hl ; save destination ld hl,($5c4b) ; VARS loop: ld a,(hl) cp 128 jr z,notfound ; n.b. z => nc cp d jr z,found push de call $19b8 ;get next variable start ex de,hl pop de jr loop found: inc hl ld c,(hl) ld a,c inc hl ld b,(hl) or b inc hl pop de jr z,zerolen ldir zerolen: xor a ld (de),a ld h,a ld l,a ret notfound: pop hl ld hl,-1 ret DEFC ASMDISP_ZX_GETSTR_CALLEE = asmentry - zx_getstr_callee
; A231722: Partial sums of A001088 starting from its second term; a(1)=0, a(n) = A001088(2)+...+A001088(n). ; 0,1,3,7,23,55,247,1015,5623,24055,208375,945655,9793015,62877175,487550455,3884936695,58243116535,384392195575,6255075618295,53220543000055,616806151581175,6252662237392375,130241496125238775,1122152167228009975,20960365589283433975,259018926653948521975,4544073025817920105975,55964722215785579113975,1495742899534880031337975,13013968318087635649129975,358560730874670304182889975,5887308931779993000723049975,116462272949886446931526249975,1885661697239589709824377449975,44346447880192468019252806249975,553875882075627007732393951849975,18896935513111270437405475193449975,349072008871752852171520937542249975 lpb $0 mov $2,$0 sub $0,1 seq $2,1088 ; Product of totient function: a(n) = Product_{k=1..n} phi(k) (cf. A000010). add $1,$2 lpe mov $0,$1
* * Counter program 1 for COSMAC * SB-Assembler * .CR 1802 ;To load the 1802 cross overlay .OR $0000 * START LDI #IOR ;D <- #IOR PLO 3 ;R(3).0 <- D SEX 3 ;X <- 3 LOOP1 GLO 4 ;D <- R(4).0 STR 3 ;M(R(3)) <- D OUT 1 ;BUS <- M(R(3)); R(3)++ DEC 3 ;R(3)-- INC 4 ;R(4)++ BR LOOP1 ;Branch to LOOP1 * IOR .DB 0 ;IO Register .EN
#ifndef BOOST_METAPARSE_CHANGE_ERROR_MESSAGE_HPP #define BOOST_METAPARSE_CHANGE_ERROR_MESSAGE_HPP // Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. // 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/metaparse/v1/change_error_message.hpp> namespace boost { namespace metaparse { using v1::change_error_message; } } #endif
#include "rng.hpp" #include <random> #define ROL64(x, k) (((x) << (k)) | ((x) >> (64 - (k)))) static inline uint64_t splitmix64(uint64_t& state){ uint64_t result = (state += 0x9E3779B97f4A7C15); result = (result ^ (result >> 30)) * 0xBF58476D1CE4E5B9; return (result ^ (result >> 27)) * 0x94D049BB133111EB; } xoshiro256ss::xoshiro256ss(uint64_t seed){ _s[0] = splitmix64(seed); _s[1] = splitmix64(seed); _s[2] = splitmix64(seed); _s[3] = splitmix64(seed); } xoshiro256ss::xoshiro256ss(uint64_t initState[4]){ for(int i=0; i<4; ++i) _s[i] = initState[i]; } xoshiro256ss::xoshiro256ss(){ // default constructor uses std::random_device as a non-deterministic // source for the initial state // note that if no such source is available on the current platform, // a deterministic algorithm may be used instead std::random_device rd; std::uniform_int_distribution<uint64_t> dist; for(int i=0; i<4; ++i) _s[i] = dist(rd); } uint64_t xoshiro256ss::operator()(){ uint64_t r = ROL64(_s[1] * 5, 7) * 9; uint64_t const t = _s[1] << 17; _s[2] ^= _s[0]; _s[3] ^= _s[1]; _s[1] ^= _s[2]; _s[0] ^= _s[3]; _s[2] ^= t; _s[3] = ROL64(_s[3], 45); return r; } using iter_t = xoshiro256ss::iterator; bool iter_t::operator==(const iter_t& other) const{ return (_rng == other._rng) && (_c == other._c); } bool iter_t::operator!=(const iter_t& other) const{ return !(*this == other); } uint64_t iter_t::operator*() const { return (*_rng)(); } iter_t iter_t::operator++(int){ iter_t old = *this; _c++; return old; } iter_t& iter_t::operator++(){ _c++; return *this; } xoshiro256ss::generator xoshiro256ss::operator()(uintmax_t n){ return xoshiro256ss::generator {{this,0}, {this, n}}; }
; A340536: Digital root of 2*n^2. ; Submitted by Christian Krause ; 2,8,9,5,5,9,8,2,9,2,8,9,5,5,9,8,2,9,2,8,9,5,5,9,8,2,9,2,8,9,5,5,9,8,2,9,2,8,9,5,5,9,8,2,9,2,8,9,5,5,9,8,2,9,2,8,9,5,5,9,8,2,9,2,8,9,5,5,9,8,2,9,2,8,9,5,5,9,8,2,9,2,8,9,5,5,9,8,2,9 add $0,1 pow $0,2 mul $0,40 sub $0,1 mul $0,19 div $0,18 add $0,1 mod $0,10
/*========================================================================= * * Copyright Insight Software Consortium * * 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.txt * * 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 "itkFEMLinearSystemWrapperVNL.h" #include <vnl/vnl_sparse_matrix_linear_system.h> #include <vnl/algo/vnl_lsqr.h> namespace itk { namespace fem { void LinearSystemWrapperVNL::InitializeMatrix(unsigned int matrixIndex) { // allocate if necessary if( m_Matrices == nullptr ) { m_Matrices = new MatrixHolder(m_NumberOfMatrices); if( m_Matrices == nullptr ) { itkGenericExceptionMacro(<< "LinearSystemWrapperVNL::InitializeMatrix(): m_Matrices allocation failed."); } } // out with old, in with new delete ( *m_Matrices )[matrixIndex]; ( *m_Matrices )[matrixIndex] = new MatrixRepresentation( this->GetSystemOrder(), this->GetSystemOrder() ); if( ( *m_Matrices )[matrixIndex] == nullptr ) { itkGenericExceptionMacro( << "LinearSystemWrapperVNL::InitializeMatrix(): allocation of (*m_Matrices)[" << matrixIndex << "] failed."); } } bool LinearSystemWrapperVNL::IsMatrixInitialized(unsigned int matrixIndex) { if( !m_Matrices ) { return false; } if( !( ( *m_Matrices )[matrixIndex] ) ) { return false; } return true; } void LinearSystemWrapperVNL::DestroyMatrix(unsigned int matrixIndex) { if( m_Matrices ) { delete ( *m_Matrices )[matrixIndex]; ( *m_Matrices )[matrixIndex] = nullptr; } } void LinearSystemWrapperVNL::InitializeVector(unsigned int vectorIndex) { // allocate if necessary if( m_Vectors == nullptr ) { m_Vectors = new std::vector<vnl_vector<Float> *>(m_NumberOfVectors); if( m_Vectors == nullptr ) { itkGenericExceptionMacro(<< "InitializeVector(): m_Vectors memory allocation failed."); } } // out with old, in with new delete ( *m_Vectors )[vectorIndex]; ( *m_Vectors )[vectorIndex] = new vnl_vector<Float>( this->GetSystemOrder() ); if( ( *m_Vectors )[vectorIndex] == nullptr ) { itkGenericExceptionMacro(<< "InitializeVector(): allocation of (*m_Vectors)[" << vectorIndex << "] failed."); } ( *m_Vectors )[vectorIndex]->fill(0.0); } bool LinearSystemWrapperVNL::IsVectorInitialized(unsigned int vectorIndex) { if( !m_Vectors ) { return false; } if( !( *m_Vectors )[vectorIndex] ) { return false; } return true; } void LinearSystemWrapperVNL::DestroyVector(unsigned int vectorIndex) { if( m_Vectors ) { delete ( *m_Vectors )[vectorIndex]; ( *m_Vectors )[vectorIndex] = nullptr; } } void LinearSystemWrapperVNL::InitializeSolution(unsigned int solutionIndex) { // allocate if necessary if( m_Solutions == nullptr ) { m_Solutions = new std::vector<vnl_vector<Float> *>(m_NumberOfSolutions); if( m_Solutions == nullptr ) { itkGenericExceptionMacro(<< "InitializeSolution(): m_Solutions memory allocation failed."); } } // out with old, in with new delete ( *m_Solutions )[solutionIndex]; ( *m_Solutions )[solutionIndex] = new vnl_vector<Float>( this->GetSystemOrder() ); if( ( *m_Solutions )[solutionIndex] == nullptr ) { itkGenericExceptionMacro(<< "InitializeSolution(): allocation of (*m_olutions)[" << solutionIndex << "] failed."); } ( *m_Solutions )[solutionIndex]->fill(0.0); } bool LinearSystemWrapperVNL::IsSolutionInitialized(unsigned int solutionIndex) { if( !m_Solutions ) { return false; } if( !( *m_Solutions )[solutionIndex] ) { return false; } return true; } void LinearSystemWrapperVNL::DestroySolution(unsigned int solutionIndex) { if( m_Solutions ) { delete ( *m_Solutions )[solutionIndex]; ( *m_Solutions )[solutionIndex] = nullptr; } } LinearSystemWrapperVNL::Float LinearSystemWrapperVNL::GetSolutionValue(unsigned int i, unsigned int SolutionIndex) const { if( m_Solutions == nullptr ) { return 0.0; } if( ( ( *m_Solutions )[SolutionIndex] )->size() <= i ) { return 0.0; } else { return ( *( ( *m_Solutions )[SolutionIndex] ) )(i); } } void LinearSystemWrapperVNL::Solve() { if( ( m_Matrices->size() == 0 ) || ( m_Vectors->size() == 0 ) || ( m_Solutions->size() == 0 ) ) { itkGenericExceptionMacro( << "LinearSystemWrapperVNL::Solve(): m_Matrices, m_Vectors and m_Solutions size's are all zero."); } /* use functions to make sure that zero based matrix, vector, & index store final system to solve */ /* if (m_PrimaryMatrixSetupFunction != nullptr) (*m_PrimaryMatrixSetupFunction)(static_cast<Superclass*>(this)); if (m_PrimaryVectorSetupFunction != nullptr) (*m_PrimaryVectorSetupFunction)(static_cast<Superclass*>(this)); if (m_PrimarySolutionSetupFunction != nullptr) (*m_PrimarySolutionSetupFunction)(static_cast<Superclass*>(this)); */ /* * Solve the sparse system of linear equation and store the result in m_Solutions(0). * Here we use the iterative least squares solver. */ vnl_sparse_matrix_linear_system<Float> ls( ( *( ( *m_Matrices )[0] ) ), ( *( ( *m_Vectors )[0] ) ) ); vnl_lsqr lsq(ls); /* * Set max number of iterations to 3*size of the K matrix. * FIXME: There should be a better way to determine the number of iterations needed. */ lsq.set_max_iterations( 3 * this->GetSystemOrder() ); lsq.minimize( *( ( *m_Solutions )[0] ) ); } void LinearSystemWrapperVNL::SwapMatrices(unsigned int MatrixIndex1, unsigned int MatrixIndex2) { vnl_sparse_matrix<Float> *tmp; tmp = ( *m_Matrices )[MatrixIndex1]; ( *m_Matrices )[MatrixIndex1] = ( *m_Matrices )[MatrixIndex2]; ( *m_Matrices )[MatrixIndex2] = tmp; } void LinearSystemWrapperVNL::SwapVectors(unsigned int VectorIndex1, unsigned int VectorIndex2) { vnl_vector<Float> *tmp; tmp = ( *m_Vectors )[VectorIndex1]; ( *m_Vectors )[VectorIndex1] = ( *m_Vectors )[VectorIndex2]; ( *m_Vectors )[VectorIndex2] = tmp; } void LinearSystemWrapperVNL::SwapSolutions(unsigned int SolutionIndex1, unsigned int SolutionIndex2) { vnl_vector<Float> *tmp; tmp = ( *m_Solutions )[SolutionIndex1]; ( *m_Solutions )[SolutionIndex1] = ( *m_Solutions )[SolutionIndex2]; ( *m_Solutions )[SolutionIndex2] = tmp; } void LinearSystemWrapperVNL::CopySolution2Vector(unsigned int SolutionIndex, unsigned int VectorIndex) { delete ( *m_Vectors )[VectorIndex]; ( *m_Vectors )[VectorIndex] = new vnl_vector<Float>( *( ( *m_Solutions )[SolutionIndex] ) ); } void LinearSystemWrapperVNL::CopyVector2Solution(unsigned int VectorIndex, unsigned int SolutionIndex) { delete ( *m_Solutions )[SolutionIndex]; ( *m_Solutions )[SolutionIndex] = new vnl_vector<Float>( *( ( *m_Vectors )[VectorIndex] ) ); } void LinearSystemWrapperVNL::MultiplyMatrixMatrix(unsigned int ResultMatrixIndex, unsigned int LeftMatrixIndex, unsigned int RightMatrixIndex) { delete ( *m_Matrices )[ResultMatrixIndex]; ( *m_Matrices )[ResultMatrixIndex] = new vnl_sparse_matrix<Float>( this->GetSystemOrder(), this->GetSystemOrder() ); #if VXL_VERSION_DATE_FULL >= 20100109 *( ( *m_Matrices )[ResultMatrixIndex] ) = *( ( *m_Matrices )[LeftMatrixIndex] ) * ( *( ( *m_Matrices )[RightMatrixIndex] ) ); #else ( ( *m_Matrices )[LeftMatrixIndex] )->mult( *( ( *m_Matrices )[RightMatrixIndex] ), *( ( *m_Matrices )[ResultMatrixIndex] ) ); #endif } void LinearSystemWrapperVNL::MultiplyMatrixVector(unsigned int ResultVectorIndex, unsigned int MatrixIndex, unsigned int VectorIndex) { delete ( *m_Vectors )[ResultVectorIndex]; ( *m_Vectors )[ResultVectorIndex] = new vnl_vector<Float>( this->GetSystemOrder() ); ( ( *m_Matrices )[MatrixIndex] )->mult( *( ( *m_Vectors )[VectorIndex] ), *( ( *m_Vectors )[ResultVectorIndex] ) ); } void LinearSystemWrapperVNL::ScaleMatrix(Float scale, unsigned int matrixIndex) { for( ( ( *m_Matrices )[matrixIndex] )->reset(); ( ( *m_Matrices )[matrixIndex] )->next(); ) { ( *( ( *m_Matrices )[matrixIndex] ) )( ( ( *m_Matrices )[matrixIndex] )->getrow(), ( ( *m_Matrices )[matrixIndex] )->getcolumn() ) = scale * ( *( ( *m_Matrices )[matrixIndex] ) )( ( ( *m_Matrices )[matrixIndex] )->getrow(), ( ( *m_Matrices )[matrixIndex] )->getcolumn() ); } } LinearSystemWrapperVNL::~LinearSystemWrapperVNL() { unsigned int i; for( i = 0; i < m_NumberOfMatrices; i++ ) { this->DestroyMatrix(i); } for( i = 0; i < m_NumberOfVectors; i++ ) { this->DestroyVector(i); } for( i = 0; i < m_NumberOfSolutions; i++ ) { this->DestroySolution(i); } delete m_Matrices; delete m_Vectors; delete m_Solutions; } } // end namespace fem } // end namespace itk
#ifndef PLANNER_BASE_HPP #define PLANNER_BASE_HPP // The MIT License (MIT) // // Copyright (c) 2015, 2016, 2017 Howard Hinnant // Copyright (c) 2016 Adrian Colomitchi // Copyright (c) 2017 Florian Dang // Copyright (c) 2017 Paul Thompson // Copyright (c) 2018, 2019 Tomasz Kamiński // Copyright (c) 2019 Jiangang Zhuang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // // Our apologies. When the previous paragraph was written, lowercase had not // yet been invented (that would involve another several millennia of // evolution). We did not mean to shout. #include "date.h" #include "hpdf.h" #include "utils.hpp" #include <cstdint> #include <iostream> #include <memory> #include <typeinfo> #include <vector> #define FILL_BLACK 0.0 #define FILL_TITLE 0.8 #define FILL_LIGHT 0.9 #define FILL_DARK 0.5 /*! * @brief * Base class for the different Planner elements * */ class PlannerBase : public std::enable_shared_from_this<PlannerBase> { protected: std::uint64_t _id; /*! What section of the page is reserved for notes */ double _note_section_percentage; /*! representing the PDF Page that this object is controlling */ HPDF_Page _page; /*! The font used for the notes header */ HPDF_Font _notes_font; /*! The height of the page */ HPDF_REAL _page_height; /*! The width of the page */ HPDF_REAL _page_width; /*! The left margin of the page */ HPDF_REAL _margin_width; /*! The left margin of the page */ HPDF_REAL _margin_left; /*! Add time to margin */ bool _time_in_margin; /*! The gap between two time stamps in lines */ int _time_gap_lines; /*! The starting time */ int _time_start; /*! The left margin of the page */ HPDF_REAL _margin_right; /*! A string representing the title of the page */ std::string _page_title; /*! A string represeneting the title that appears when this object is * displayed in a grid of a parent page */ std::string _grid_string; /*! The font size of the page title */ HPDF_REAL _page_title_font_size; /*! The font size of the notes section title */ HPDF_REAL _note_title_font_size; /*! A pointer to the parent page object */ std::shared_ptr<PlannerBase> _parent; /*! A pointer to the left page object */ std::shared_ptr<PlannerBase> _left; /*! A pointer to the right page object */ std::shared_ptr<PlannerBase> _right; /*! Whether it shouold be left handed orientation */ bool _is_left_handed; /*! Whether it should be portrait / landscape orientation */ bool _is_portrait; public: PlannerBase() : _id(0), _note_section_percentage(0.5), _page_title("Base"), _page_title_font_size(45), _note_title_font_size(35), _grid_string("GridBase"), _margin_width(Remarkable_margin_width_px), _is_left_handed(false), _page_width(Remarkable_width_px), _page_height(Remarkable_height_px), _is_portrait(false), _time_in_margin(false) { _margin_left = _margin_width; _margin_right = _page_width - _margin_width; } PlannerBase(std::string grid_string, bool is_left_handed) : _id(0), _note_section_percentage(0.5), _page_title("Base"), _page_title_font_size(45), _note_title_font_size(35), _grid_string(grid_string), _margin_width((Remarkable_margin_width_px)), _is_left_handed(is_left_handed), _page_width(Remarkable_width_px), _page_height(Remarkable_height_px), _is_portrait(false) { _margin_left = _margin_width; _margin_right = _page_width - _margin_width; } void SetGridString(std::string grid_string) { _grid_string = grid_string; } void CreateThumbnail(HPDF_Doc& doc, HPDF_Page& page, HPDF_REAL x_start, HPDF_REAL y_start, HPDF_REAL x_stop, HPDF_REAL y_stop) {} void FillAreaWithDots(HPDF_Page& page, HPDF_REAL dot_spacing_x, HPDF_REAL dot_spacing_y, HPDF_REAL page_height, HPDF_REAL page_width, HPDF_REAL x_start, HPDF_REAL y_start, HPDF_REAL x_stop, HPDF_REAL y_stop) { HPDF_REAL x = x_start; const HPDF_UINT16 DASH_MODE1[] = {2, HPDF_UINT16(dot_spacing_x)}; for (HPDF_REAL y = y_start; y < y_stop; y = y + dot_spacing_y) { HPDF_Page_SetLineWidth(page, 2); HPDF_Page_SetDash(page, DASH_MODE1, 2, 0); HPDF_Page_MoveTo(page, x, page_height - y); HPDF_Page_LineTo(page, x_stop, page_height - y); HPDF_Page_Stroke(page); } HPDF_Page_SetDash(page, NULL, 0, 0); } void FillAreaWithLines(HPDF_Page& page, bool is_vertical_line, HPDF_REAL area_x_start, HPDF_REAL area_y_start, HPDF_REAL area_x_stop, HPDF_REAL area_y_stop, HPDF_REAL line_gap, HPDF_REAL page_height) { HPDF_REAL dim_start; HPDF_REAL dim_stop; if (is_vertical_line) { dim_start = area_x_start; dim_stop = area_x_stop; } else { dim_start = area_y_start; dim_stop = area_y_stop; } HPDF_Page_SetLineWidth(page, 0.5); HPDF_Page_SetGrayStroke(page, 0.5); for (HPDF_REAL dim = dim_start; dim < dim_stop; dim = dim + line_gap) { if (is_vertical_line) { HPDF_Page_MoveTo(page, dim, page_height - area_y_start); HPDF_Page_LineTo(page, dim, page_height - area_y_stop); } else { HPDF_Page_MoveTo(page, area_x_start, page_height - dim); HPDF_Page_LineTo(page, area_x_stop, page_height - dim); } HPDF_Page_Stroke(page); } } /*! * @brief * Create the page for this object with the given height and width */ void CreatePage(HPDF_Doc doc, std::uint64_t height, std::uint64_t width) { _page = HPDF_AddPage(doc); _notes_font = HPDF_GetFont(doc, "Helvetica", NULL); HPDF_Page_SetHeight(_page, height); _page_height = height; HPDF_Page_SetWidth(_page, width); _page_width = width; /* Draw the margin */ HPDF_REAL margin_x; if (_is_left_handed) { margin_x = _margin_right; } else { margin_x = _margin_left; } HPDF_Page_SetLineWidth(_page, 1); HPDF_Page_MoveTo(_page, margin_x, 0); HPDF_Page_LineTo(_page, margin_x, _page_height); HPDF_Page_Stroke(_page); } /*! * Set the navigation pointer for left sibling */ void SetLeft(std::shared_ptr<PlannerBase>& left) { _left = left; } /*! * Set the navigation pointer for the right sibling */ void SetRight(std::shared_ptr<PlannerBase>& right) { _right = right; } /*! * Base function for the build operation to create the page */ void Build() {} std::string GetGridString() { return _grid_string; } HPDF_Page& GetPage() { return _page; } void SetNotesSectionPercentage(double notes_section_percentage) { _note_section_percentage = notes_section_percentage; } /*! * Function to paint the background of a link/anchor. */ void PaintRect(HPDF_Page& page, HPDF_REAL page_height, HPDF_REAL rect_x_start, HPDF_REAL rect_y_start, HPDF_REAL rect_x_stop, HPDF_REAL rect_y_stop, HPDF_REAL padding_x, HPDF_REAL padding_y, HPDF_REAL gray) { HPDF_REAL grayfill = HPDF_Page_GetGrayFill(page); HPDF_Page_SetGrayFill(page, gray); HPDF_STATUS status = HPDF_Page_Rectangle(page, rect_x_start - padding_x, page_height - (rect_y_stop + padding_y), rect_x_stop - rect_x_start + (2 * padding_x), rect_y_stop - rect_y_start + (2 * padding_y)); HPDF_Page_Fill(page); HPDF_Page_SetGrayFill(page, grayfill); } /*! * Function to generate the title of a page. The title of the page when * clicked on will navigate to the parent page. */ void CreateTitle() { HPDF_Page_SetFontAndSize(_page, _notes_font, _page_title_font_size); HPDF_Page_SetLineWidth(_page, 1); HPDF_REAL page_title_text_x = GetCenteredTextXPosition(_page, _page_title, 0, _page_width); HPDF_REAL length = HPDF_Page_TextWidth(_page, _page_title.c_str()); HPDF_REAL x_padding = 20; HPDF_REAL y_padding = 0; PaintRect(_page, _page_height, page_title_text_x, 0, page_title_text_x + length, _page_title_font_size * 2, x_padding, y_padding, FILL_TITLE); HPDF_Page_BeginText(_page); HPDF_Page_MoveTextPos( _page, page_title_text_x, _page_height - _page_title_font_size - 10); if (NULL != _parent) { HPDF_Destination dest = HPDF_Page_CreateDestination(_parent->GetPage()); HPDF_Rect rect = {page_title_text_x - x_padding, _page_height - y_padding, page_title_text_x + length + x_padding, _page_height - ((_page_title_font_size * 2) + y_padding)}; HPDF_Annotation annotation = HPDF_Page_CreateLinkAnnot(_page, rect, dest); } HPDF_Page_ShowText(_page, _page_title.c_str()); HPDF_Page_EndText(_page); DrawTitleSeparator(); } void DrawTitleSeparator() { HPDF_Page_SetLineWidth(_page, 2); HPDF_Page_MoveTo(_page, 0, _page_height - (_page_title_font_size * 2)); HPDF_Page_LineTo( _page, _page_width, _page_height - (_page_title_font_size * 2)); HPDF_Page_Stroke(_page); } /*! * Function to setup the left and right navigation elements of the page. */ void AddNavigation() { HPDF_Page_SetFontAndSize(_page, _notes_font, _page_title_font_size); HPDF_Page_SetLineWidth(_page, 1); /* Add navigation to left and right */ std::string left_string = "<"; std::string right_string = ">"; HPDF_REAL page_title_text_x = GetCenteredTextXPosition(_page, _page_title, 0, _page_width); HPDF_REAL x_padding = 20; HPDF_REAL y_padding = 0; /* Add left navigation */ if (NULL != _left) { HPDF_REAL length = HPDF_Page_TextWidth(_page, left_string.c_str()); PaintRect(_page, _page_height, page_title_text_x - 100, 0, page_title_text_x - 100 + length, (_page_title_font_size * 2), x_padding, y_padding, FILL_TITLE); HPDF_Page_BeginText(_page); HPDF_Page_MoveTextPos(_page, page_title_text_x - 100, _page_height - _page_title_font_size - 10); HPDF_Destination dest = HPDF_Page_CreateDestination(_left->GetPage()); HPDF_Rect rect = {page_title_text_x - 100 - x_padding, _page_height - y_padding, page_title_text_x - 100 + length + x_padding, _page_height - ((_page_title_font_size * 2) + y_padding)}; HPDF_Annotation annotation = HPDF_Page_CreateLinkAnnot(_page, rect, dest); HPDF_Page_ShowText(_page, left_string.c_str()); HPDF_Page_EndText(_page); } /* Add right navigation */ if (NULL != _right) { HPDF_REAL title_length = HPDF_Page_TextWidth(_page, _page_title.c_str()); HPDF_REAL length = HPDF_Page_TextWidth(_page, right_string.c_str()); PaintRect(_page, _page_height, page_title_text_x + title_length + 100 - length, 0, page_title_text_x + title_length + 100, (_page_title_font_size * 2), x_padding, y_padding, FILL_TITLE); HPDF_Page_BeginText(_page); HPDF_Page_MoveTextPos(_page, page_title_text_x + title_length + 100 - length, _page_height - _page_title_font_size - 10); HPDF_Destination dest = HPDF_Page_CreateDestination(_right->GetPage()); HPDF_Rect rect = {page_title_text_x + title_length + 100 - length - x_padding, _page_height - y_padding, page_title_text_x + title_length + 100 + x_padding, _page_height - ((_page_title_font_size * 2) + y_padding)}; HPDF_Annotation annotation = HPDF_Page_CreateLinkAnnot(_page, rect, dest); HPDF_Page_ShowText(_page, right_string.c_str()); HPDF_Page_EndText(_page); } DrawTitleSeparator(); } /*! * Functin to generate the notes section */ void CreateNotesSection(bool time_in_margin) { HPDF_Page_SetFontAndSize(_page, _notes_font, _note_title_font_size); HPDF_Page_SetLineWidth(_page, 2); HPDF_REAL notes_divider_x_width; HPDF_REAL notes_section_text_x; HPDF_REAL notes_x_start; HPDF_REAL notes_y_start; HPDF_REAL notes_x_stop; HPDF_REAL notes_y_stop; HPDF_REAL margin_x; HPDF_REAL divider_location_x; std::string notes_string = "Notes"; notes_divider_x_width = _page_width * _note_section_percentage; if (_is_left_handed) { notes_x_start = _page_width - notes_divider_x_width; notes_y_start = 2 * _page_title_font_size; notes_x_stop = _page_width; notes_y_stop = _page_height; margin_x = _margin_right; divider_location_x = notes_x_start; notes_section_text_x = GetCenteredTextXPosition( _page, notes_string, notes_x_start, _margin_right); } else { notes_x_start = 0; notes_y_start = 2 * _page_title_font_size; notes_x_stop = notes_divider_x_width; notes_y_stop = _page_height; margin_x = _margin_left; divider_location_x = notes_x_stop; notes_section_text_x = GetCenteredTextXPosition( _page, notes_string, _margin_left, notes_divider_x_width); } /* Draw dividing line between notes section and the rest of the page */ HPDF_Page_MoveTo(_page, divider_location_x, 0); HPDF_Page_LineTo(_page, divider_location_x, _page_height - notes_y_start); HPDF_Page_Stroke(_page); /* Print Notes section title */ HPDF_Page_BeginText(_page); HPDF_Page_MoveTextPos(_page, notes_section_text_x, _page_height - notes_y_start - _note_title_font_size - 10); HPDF_Page_ShowText(_page, notes_string.c_str()); HPDF_Page_EndText(_page); HPDF_REAL dot_spacing = 40; FillAreaWithLines(_page, false, notes_x_start, notes_y_start + (2 * _note_title_font_size), notes_x_stop, notes_y_stop - 30, dot_spacing, _page_height); if(time_in_margin) { HPDF_REAL time_x = notes_x_start + margin_x - 10; HPDF_REAL time_y = notes_y_start + (2 * _note_title_font_size); if(_is_left_handed) { time_x = _margin_right + 50; } AddTimeToMargin(time_x , time_y , dot_spacing, _page_height); } } void AddTimeToMargin(HPDF_REAL x_start, HPDF_REAL y_start, HPDF_REAL gap, HPDF_REAL height ) { char time_str[5]; uint32_t i = 0; HPDF_Page_SetFontAndSize(_page, _notes_font, 20); for(HPDF_REAL y = y_start + 2 * _note_title_font_size; y <= height; y = y + _time_gap_lines * gap, i++ ) { std::uint32_t time_int = (_time_start + i * 100) % 2400; sprintf(time_str, "%04d",time_int); HPDF_Page_BeginText(_page); HPDF_Page_MoveTextPos(_page, x_start - HPDF_Page_TextWidth(_page, time_str), height - y); HPDF_Page_ShowText(_page, time_str); HPDF_Page_EndText(_page); } } /*! * Function to create a grid of child elements to be able to navigate to them */ void CreateGrid(HPDF_Doc& doc, HPDF_Page& page, HPDF_REAL x_start, HPDF_REAL y_start, HPDF_REAL x_stop, HPDF_REAL y_stop, HPDF_REAL num_rows, HPDF_REAL num_cols, std::vector<std::shared_ptr<PlannerBase>>& objects, bool create_annotations, size_t first_entry_offset, bool create_thumbnail, PlannerTypes page_type, PlannerTypes object_type, HPDF_REAL page_height, HPDF_REAL padding, bool grid_string_in_middle) { if ((first_entry_offset + objects.size()) > (num_rows * num_cols)) { std::cout << "[ERR] : Too many objects to fit in given grid : num_rows: " << num_rows << ", num_cols : " << num_cols << ", first_entry_offset : " << first_entry_offset << ", num objects : " << objects.size() << std::endl; return; } HPDF_REAL x_step_size = (x_stop - x_start) / num_cols; HPDF_REAL y_step_size = (y_stop - y_start) / num_rows; HPDF_Font font = HPDF_GetFont(doc, "Helvetica", NULL); HPDF_Page_SetFontAndSize(page, font, 25); size_t object_index = 0; size_t row_num = 0; for (HPDF_REAL y = y_start; y < y_stop && row_num < num_rows; y = y + y_step_size, row_num++) { size_t col_num = 0; for (HPDF_REAL x = x_start; x < x_stop && object_index < objects.size() && col_num < num_cols; x = x + x_step_size, col_num++) { HPDF_REAL x_pad_start = x + padding; HPDF_REAL y_pad_start = y + padding; HPDF_REAL x_pad_end = x + x_step_size - padding; HPDF_REAL y_pad_end = y + y_step_size - padding; if (first_entry_offset == 0) { if (true == create_annotations) { HPDF_REAL paint_rect_y_end = y_pad_end; if (true == create_thumbnail) { paint_rect_y_end = y_pad_start + 50; } PaintRect(page, page_height, x_pad_start, y_pad_start, x_pad_end, paint_rect_y_end, 0, 0, FILL_LIGHT); } HPDF_Page_BeginText(page); HPDF_REAL grid_x_start = GetCenteredTextXPosition(page, objects[object_index]->GetGridString(), x_pad_start, x_pad_end); HPDF_REAL grid_y_start = y_pad_start + 30; if (true == grid_string_in_middle) { grid_y_start = GetCenteredTextYPosition( page, GetGridString(), grid_y_start, y_pad_end); } HPDF_Page_MoveTextPos( page, grid_x_start, _page_height - grid_y_start); if (true == create_annotations) { HPDF_Destination dest = HPDF_Page_CreateDestination(objects[object_index]->GetPage()); HPDF_REAL rect_y_end = page_height - y_pad_end; if (true == create_thumbnail) { // To avoid the link covering the entire thumbnail, limit // annotation rect height to 50 pixels // TODO: Replace 50 with actual height of title of thumbnail rect_y_end = page_height - (y_pad_start + 50); } HPDF_Rect rect = { x_pad_start, rect_y_end, x_pad_end, page_height - y_pad_start}; HPDF_Annotation annotation = HPDF_Page_CreateLinkAnnot(page, rect, dest); } HPDF_Page_ShowText(page, objects[object_index]->GetGridString().c_str()); HPDF_Page_EndText(page); if (true == create_thumbnail) { CreateThumbnailCaller(doc, page, x_pad_start, y_pad_start, x_pad_end, y_pad_end, page_type, object_type, objects[object_index]); } object_index++; } else { first_entry_offset--; } } } /* Draw grid lines in the middle of the padding */ for (size_t row_num = 0; row_num < num_rows; row_num++) { HPDF_REAL x_line_start = x_start; HPDF_REAL x_line_stop = x_stop; HPDF_REAL y_line_start = y_start + row_num * y_step_size; HPDF_REAL y_line_stop = y_start + row_num * y_step_size; HPDF_Page_SetLineWidth(page, 2); HPDF_Page_MoveTo(page, x_line_start, page_height - y_line_start); HPDF_Page_LineTo(page, x_line_stop, page_height - y_line_stop); HPDF_Page_Stroke(page); } for (size_t col_num = 1; col_num < num_cols; col_num++) { HPDF_REAL x_line_start = x_start + x_step_size * col_num; HPDF_REAL x_line_stop = x_start + x_step_size * col_num; HPDF_REAL y_line_start = y_start; HPDF_REAL y_line_stop = y_stop; HPDF_Page_SetLineWidth(page, 1); HPDF_Page_MoveTo(page, x_line_start, page_height - y_line_start); HPDF_Page_LineTo(page, x_line_stop, page_height - y_line_stop); HPDF_Page_Stroke(page); } } }; #endif // PLANNER_BASE_HPP
; .:*~*:.__.:*~*:. ; | | ; |RiFT8 Firmware| ; |By Fell, 2012 | ; | | ; ':*~*:.__.:*~*:' ; MEMORY MAP LAYOUT: ; 0000-7FFF: 32kB ROM ; 8000-FFFE: 32kB Static RAM ; RAM MAP: ; 8000-83FF: ~1kB OS scratch space (buffers and stuff) ; 8400-FFFE: User space (stack grows down from FFEE) ; I/O MAP LAYOUT: ; 00-03: SCC2691 UART ; 80-87: IDE Hard Drive ; ; The ROM currently builds with zasm (Online version: http://k1.spdns.de/cgi-bin/zasm.cgi) ; but intention is to return to z80-asm package once I can build binaries for it. ; ; Simplest emulation for SCC2691 UART: ; - Respond to an in on IO 01 with bit 3 always set to show TX ready, and bit 0 set when a char is ready for the Rift8 ; - Respond to in on IO 03 with the character ; - Listen for data from out on IO 03 ; ; RFS (IDE driver/filesystem) is on standby pending a proper (but simple) IDE interface, but below is its TODO. ; Existing stuff needs refactored/testing -- there were possibly some bugs when it was working ; with the utter-optimisism IDE "interface" but the interface wasn't really reliable enough to ; know for sure! ; ; - These are easy cos they just use fileindex: ; Format - yay! ; VolRename - yay! ; ListAll - yay! ; ListTag - yay! ; FileExists - yay! NOTE: This should MAAAYBE??? return file record? NO WAIT -- SHOULD RETURN FIRST BLOCK NUM????? ; RenameFile } ; RetagFile } ; - ReadFile ; - DeleteFile (note this must use the freemap too) ; ; Approx sizes of stuff: ; Shell: 800 lines ; BASIC interpreter: 600 lines ; Dungeon Fungler: 3500 lines ; Game of life: 200 lines ; API + Drivers for UART, IDE: 2000 lines ; *** Hardware config constants *** uart_base equ $00 ; UART base address uart_mr equ uart_base ; UART mode registers MR1 and MR2 uart_sr_csr equ uart_base+1 ; R: Status register; W: Clock select register uart_cr equ uart_base+2 ; R: BRG Test; W: Command register uart_data equ uart_base+3 ; R: Rx holding register; W: Tx holding register ide_base equ $80 ; IDE base address ide_register0 equ ide_base ; IDE register addresses: Data (rw) ide_register1 equ ide_base+1 ; Error (r) ide_register2 equ ide_base+2 ; Sec count ide_register3 equ ide_base+3 ; LBA 0 (ATA-1 spoken here! LBA access for 64Gb of address capacity -- note 256 not 512 byte sectors) ide_register4 equ ide_base+4 ; LBA 1 ide_register5 equ ide_base+5 ; LBA 2 ide_register6 equ ide_base+6 ; LBA 3, Master/slave select, LBA select ide_register7 equ ide_base+7 ; Command (w), Status (r) ram_base equ $8000 ; RAM base (ROM 0-32kB, RAM 32kB-64kB) ram_size equ $8000 ; RAM size (32kB) ram_top equ ram_base+ram_size-1 ; Address of last byte of RAM int_vec equ $38 ; Z80 interupt handler vector nmi_vec equ $66 ; Z80 NMI handler vector ; *** Memory map: OS scratch space (Bottom of RAM) *** rand8_seed equ ram_base ; Location of Rand8's seed (1 byte) rand16_seed equ rand8_seed+1 ; Location of Rand16's seed (2 bytes) ide_lba0 equ rand16_seed+2 ; IDE: LBA of desired sector (LSB) ide_lba1 equ ide_lba0+1 ; IDE: LBA (cont) ide_lba2 equ ide_lba1+1 ; IDE: LBA (cont) ide_lba3 equ ide_lba2+1 ; IDE: LBA of desired sector (MSB) ide_status equ ide_lba3+1 ; IDE: Bit 0 selects master (0) or slave (1); other bits reserved (see IDE routines) freemap_size equ ide_status+1 ; RFS: Freemap size in blocks fileindex_size equ freemap_size+1 ; RFS: File index size in blocks int_buffer equ fileindex_size+1 ; Int->string buffer string_buffer equ int_buffer+10 ; Location of string buffer for GetString (256 bytes max including terminator) block_buffer equ string_buffer+256 ; RFS: Block buffer (4096 bytes) NOTE: SAFE TO USE AS TEMP VARS FROM USERSPACE PROGS scratch_base equ block_buffer+4096 ; General 1Kb scratch variable space. NOTE: SAFE TO USE AS TEMP VARS FROM USERSPACE PROGS prog_base equ scratch_base+1024 ; Location of the start of userspace ; *** Sys constants *** uart_disabletx equ 00001000b ; Command reg command to disable tx uart_resettx equ 00110000b ; CR command to reset tx uart_enabletx equ 00000100b ; CR command to enable tx uart_disablerx equ 00000010b ; Command reg command to disable rx uart_resetrx equ 00100000b ; CR command to reset rx uart_enablerx equ 00000001b ; CR command to enable rx uart_setmr1 equ 00010000b ; CR command to reset MR pointer to mr1 uart_txemptybit equ 3 ; SR bit that signifies tx empty uart_rxrdybit equ 0 ; SR bit that signifies rx ready ascii_tab equ 9 ; Tab ascii_spc equ 32 ; Space console_width equ 38 ; Console dimensions console_height equ 25 shellprompt equ '$' ; Shell prompt character ; *** Entrypoint: Set up interrupts, init UART, then jump over interrupt handlers to RAM test *** org $0000 ; im 1 ; Interrupt mode 1 di ; Disable interrupts ld a,uart_disablerx ; Disable UART rx + tx out (uart_cr),a ld a,uart_disabletx out (uart_cr),a ld a,uart_resettx ; Reset tx + rx out (uart_cr),a ld a,uart_resetrx out (uart_cr),a ld a,uart_setmr1 ; Reset MR pointer (causes the MR pointer to point to MR1) out (uart_cr),a ld a,00010011b ; Config UART mr1 (on this address after reset) for no RTS gubbins on rx, 8 bits per char, no parity out (uart_mr),a ; NB: When written to, the register addressed by uart_mr switches to mr2 ld a,00000111b ; Config UART mr2 for normal mode, no tx RTS, no tx CTS, stop bit length of 1 out (uart_mr),a ld a,11001100b ; Set UART for 38.4k both ways out (uart_sr_csr),a ld a,uart_enabletx ; Enable UART tx & rx out (uart_cr),a ld a,uart_enablerx out (uart_cr),a jp ram_test ; Jump over interrupt handlers to ramtest ; *** Interrupt handler *** org int_vec ; reti ; *** NMI handler *** org nmi_vec ; retn ; *** RAM test (fill every byte with FF and read it back) *** ; org nmi_vec+10 ; NOTE: This will have to change if NMI grows to more than 10 bytes ram_test: ld bc,ram_size ; bc is index counter ld hl,ram_base ; hl is actual address ram_loop: ld a,$FF ld (hl),a ; set byte ld a,(hl) ; try and read it back cp $FF jp nz,ram_error ; if not the same, error inc hl dec bc ld a,b ; check if BC==0 or c jp nz,ram_loop jp ram_ok ram_error: ;ld bc,msgRamError ; can't do this; no stack! ;call PrintString ;call PrintHex16 jp PrintHex16 ; try and at least print failing address (this will fault the CPU at the ret statement however) ;jp ram_error ; *** RAM's OK; Now we can set up the stack and set rand seeds *** ram_ok: ld sp,ram_top-1 ; init stack pointer -- now we can call subroutines :) ld a,42 call SeedRand8 ld hl,3473 call SeedRand16 ; *** Show the welcome and results of tests we've already done! *** call ClearScreen ld bc,msgWelcome call PrintString ld hl,ram_size call PrintUInt16 ld bc,msgRamOK call PrintLine ld bc,msgSerialOK call PrintLine ; *** Scan for an HD with an RFS filesystem *** ld bc,msgHDScan call PrintString ld a,0 ; Select master IDE drive ld (ide_status),a ld (freemap_size),a ld de,0 bootdelolp: ld b,50 ; Insert 4 sec delay bootdelilp: djnz bootdelilp inc de ld a,d or e jr nz,bootdelolp ld (ide_lba2),a ; Grab the superblock ld (ide_lba1),a ld (ide_lba0),a call RFSReadBlock jp nc,nodiskfound ld a,(block_buffer+8) ; Check magic number cp $42 jp nz,badfs ld bc,msgHDFSOK ; It's RiFT-FS! call PrintString ld a,(block_buffer+27) ; Grab fileindex_size ld (fileindex_size),a ld a,(block_buffer+26) ; Grab freemap_size to display FS size (TODO: Backup freemap_size and fileindex_size into RAM vars!!) ld (freemap_size),a ld b,a ld de,16 ld hl,0 sizedisplp: add hl,de djnz sizedisplp call PrintUInt16 ld bc,msgHDcap call PrintString ld bc,block_buffer+10 call PrintLine jp hddetectdone nodiskfound: ld bc,msgHDNotFound call PrintLine jp hddetectdone badfs: ld bc,msgHDBadFS call PrintLine hddetectdone: call NewLine ; *** Rock the shell! *** shell_ready: call ScanChar ; eat anything in UART buffer (from kb startup) call ScanChar call ScanChar call ScanChar ld bc,msgAnyKey ; force a pointless keypress (the first one out of the UART's usually dodgy) call PrintLine call GetCharSilent ;;;;;;;;;;;;;;;;;;;;;;;;; ;testloop: call GetString ; ld de,string_buffer ; call AToUInt16 ; call NewLine ; call PrintUInt16 ; call NewLine ; jr testloop ;;;;;;;;;;;;;;;;;;;;;;;;; shell: ld sp,ram_top-1 ; re-init stack pointer in case something's just jumped out of an app to this label ld bc,msgShellRdy call PrintLine shell_loop: ld a,shellprompt call PrintChar call GetString call NewLine ld hl,string_buffer ld de,cmdClear call StrCmp jp c,shell_cls ld de,cmdDFungler call StrCmp jp c,dungeonfungler ld de,cmdHelp call StrCmp jp c,shell_help ld de,cmdMemLoad call StrCmp jp c,shell_memload ld de,cmdMemDump call StrCmp jp c,shell_dump ld de,cmdGOL call StrCmp jp c,shell_gol ld de,cmdBASIC call StrCmp jp c,basic ; Note: Accepts direct jump, not a call ld de,cmdBlockLoad call StrCmp jp c,shell_blockload ld de,cmdBlockWrite call StrCmp jp c,shell_write_rawblock ld de,cmdRFSLibName call StrCmp jp c,shell_renamelib ld de,cmdRFSWrite call StrCmp jp c,shell_writefile ld de,cmdRFSFormat call StrCmp jp c,shell_format ld de,cmdRFSAll call StrCmp jp c,shell_rfsall ld de,cmdRFSRename call StrCmp jp c,shell_rename ld de,cmdRFSTagged call StrCmp jp c,shell_rfstagged ld de,cmdMemJump call StrCmp jp c,shell_jump ld bc,msgShellBadCom call PrintLine jp shell_loop cmdHelp: defm "help" defb 0 cmdClear: defm "cls" defb 0 cmdBASIC: defm "basic" defb 0 cmdDFungler: defm "fungle" defb 0 cmdGOL: defm "gol" defb 0 cmdMemLoad: defm "serload" defb 0 cmdMemDump: defm "dump" defb 0 cmdMemJump: defm "jump" defb 0 cmdBlockLoad: defm "blockload" defb 0 cmdBlockWrite: defm "blockwrite" defb 0 cmdRFSLibName: defm "renamelib" defb 0 cmdRFSRename: defm "rename" defb 0 cmdRFSWrite: defm "write" defb 0 cmdRFSFormat: defm "format" defb 0 cmdRFSAll: defm "list" defb 0 cmdRFSTagged: defm "listtag" defb 0 shell_help: ld bc,msgShellHelp call PrintString jp shell_loop msgShellHelp: defm "Welcome to the RiFT-OS Shell :)" defb 13,10,13,10 defm "General" defb 13,10 defm " help - help" defb 13,10 defm " basic - start BASIC" defb 13,10 defm " cls - clear screen" defb 13,10,13,10 defm "Fun Stuffs" defb 13,10 defm " fungle - Dungeon Fungler" defb 13,10 defm " gol - Game of Life" defb 13,10,13,10 defm "Memory Manipulation" defb 13,10 defm " dump - memory dump" defb 13,10 defm " jump - jump to a mem address" defb 13,10 defm " serload - serial memory load" defb 13,10,13,10 defm "Filesystem stuff" defb 13,10 defm " format - format RFS library" defb 13,10 defm " renamelib - rename RFS library" defb 13,10 defm " write - write RFS file" defb 13,10 defm " list - list all files" defb 13,10 defm " listtag - list files with tag" defb 13,10 defm " rename - rename/retag a file" defb 13,10 defm " blockload - DEBUG: Raw block load" defb 13,10 defm " blockwrite - DEBUG: Raw block write" defb 13,10 defb 0 shell_rfsall: call RFSListAll jp shell_loop shell_rfstagged: call RFSListTagged jp shell_loop shell_writefile: ld bc,msgShellMemHi call PrintLine ld a,shellprompt call PrintChar call GetString ld hl,string_buffer call AHexToUInt8 ld a,c ld (scratch_base),a ; Store start address high byte call NewLine ld bc,msgShellMemLo call PrintLine ld a,shellprompt call PrintChar call GetString ld hl,string_buffer call AHexToUInt8 ld a,c ld (scratch_base+1),a ; Store start address low byte call NewLine ld bc,msgShellNumBytesHi call PrintLine ld a,shellprompt call PrintChar call GetString ld hl,string_buffer call AHexToUInt8 ld a,c ld (scratch_base+2),a ; Store bytecount high byte call NewLine ld bc,msgShellNumBytesLo call PrintLine ld a,shellprompt call PrintChar call GetString ld hl,string_buffer call AHexToUInt8 ld a,c ld (scratch_base+3),a ; Store bytecount low byte call NewLine ld bc,msgShellFilename call PrintLine ld a,shellprompt call PrintChar call GetString call NewLine ld hl,string_buffer ; Store filename ld de,scratch_base+20 ; Note: Using a higher part of scratchspace as otherwise the filename will get overwritten before RFSWriteFile has a chance to use it! ld bc,15 ldir ld a,0 ld (scratch_base+35),a ; Ensure a terminated string ld bc,msgShellTag call PrintLine ld a,shellprompt call PrintChar call GetString call NewLine ld hl,string_buffer ; Store filename ld de,scratch_base+36 ld bc,15 ldir ld a,0 ld (scratch_base+51),a ; Ensure a terminated string ld a,(scratch_base) ; Set start address ld h,a ld a,(scratch_base+1) ld l,a ld a,(scratch_base+2) ; Set byte count ld d,a ld a,(scratch_base+3) ld e,a ld bc,scratch_base+20 ; Set address of filename and tag call RFSWriteFile ; Expects bc=filename+tag (32 bytes), hl=start address, de=bytecount jp shell_loop msgShellNumBytesHi: defm "Enter byte count high word (hex)" defb 0 msgShellNumBytesLo: defm "Enter byte count low word (hex)" defb 0 msgShellFilename: defm "Enter filename (max 15 chars)" defb 0 msgShellTag: defm "Enter file tag (max 15 chars)" defb 0 shell_write_rawblock: ld a,0 ; Set block number ld (ide_lba2),a ld (ide_lba1),a ld (ide_lba0),a call RFSWriteBlock jp shell_loop shell_format: call RFSFormat jp shell_loop shell_renamelib: call RFSRenameLib jp shell_loop shell_rename: call RFSRename jp shell_loop shell_blockload: ld bc,msgShellBNHi call PrintLine ld a,shellprompt call PrintChar call GetString ld hl,string_buffer call AHexToUInt8 ; Expects: hl - pointer to a zero-terminated string. a-f should be LOWERCASE! Returns: 8 bit unsigned integer in c; error code or 0 on success in b ld a,c ld (ide_lba2),a call NewLine ld bc,msgShellBNMid call PrintLine ld a,shellprompt call PrintChar call GetString ld hl,string_buffer call AHexToUInt8 ; Expects: hl - pointer to a zero-terminated string. a-f should be LOWERCASE! Returns: 8 bit unsigned integer in c; error code or 0 on success in b ld a,c ld (ide_lba1),a call NewLine ld bc,msgShellBNLo call PrintLine ld a,shellprompt call PrintChar call GetString ld hl,string_buffer call AHexToUInt8 ld a,c ld (ide_lba0),a call NewLine call RFSReadBlock jp nc,sblfailed ld bc,msgShellBNok call PrintLine sblfailed: jp shell_loop msgShellBNHi: defm "Enter block num high word (hex)" defb 0 msgShellBNMid: defm "Enter block num middle word (hex)" defb 0 msgShellBNLo: defm "Enter block num low word (hex)" defb 0 msgShellBNok: defm "Loaded block into buffer ($8114)." defb 0 shell_dump: ld bc,msgShellMemHi call PrintLine ld a,shellprompt call PrintChar call GetString ld hl,string_buffer call AHexToUInt8 ; Expects: hl - pointer to a zero-terminated string. a-f should be LOWERCASE! Returns: 8 bit unsigned integer in c; error code or 0 on success in b ld a,c ld (scratch_base),a call NewLine ld bc,msgShellMemLo call PrintLine ld a,shellprompt call PrintChar call GetString ld hl,string_buffer call AHexToUInt8 ; Expects: hl - pointer to a zero-terminated string. a-f should be LOWERCASE! Returns: 8 bit unsigned integer in c; error code or 0 on success in b ld a,c ld (scratch_base+1),a call NewLine ld bc,msgShellMemByt call PrintLine ld a,shellprompt call PrintChar call GetString ld hl,string_buffer call AToUInt8 ld (scratch_base+2),a call NewLine ld h,0 ld a,(scratch_base+2) ld l,a ld bc,(scratch_base) ld a,b ; Swap 'em! ld b,c ld c,a call MemDump ; Expects: hl - number of bytes; bc - start address jp shell_loop msgShellMemHi: defm "Enter start address high word (hex)" defb 0 msgShellMemLo: defm "Enter start address low word (hex)" defb 0 msgShellMemByt: defm "Enter bytecount (decimal) or 0 for" defb 13,10 defm "endless view (a keypress stops)" defb 0 shell_memload: ld bc,msgShellMemHi call PrintLine ld a,shellprompt call PrintChar call GetString ld hl,string_buffer call AHexToUInt8 ld a,c ld (scratch_base),a ; Store start address high word call NewLine ld bc,msgShellMemLo call PrintLine ld a,shellprompt call PrintChar call GetString ld hl,string_buffer call AHexToUInt8 ld a,c ld (scratch_base+1),a ; Store start address low word call NewLine ld bc,msgShellMemLd call PrintLine ld a,(scratch_base) ld d,a ld a,(scratch_base+1) ld e,a call MemLoad ; Expects: de - start address ld bc,msgShellOK call PrintLine jp shell_loop msgShellMemLd: defm "Feed me delicious hex bytes! Follow" defb 10,13 defm "each with Enter, and type a full" defb 10,13 defm "stop to end." defb 0 shell_cls: call ClearScreen jp shell_loop shell_gol: call game_of_life jp shell_loop shell_jump: ld bc,msgShellMemHi call PrintLine ld a,shellprompt call PrintChar call GetString ld hl,string_buffer call AHexToUInt8 ld a,c ld (scratch_base),a ; Store start address high word call NewLine ld bc,msgShellMemLo call PrintLine ld a,shellprompt call PrintChar call GetString ld hl,string_buffer call AHexToUInt8 ld a,c ld (scratch_base+1),a ; Store start address low word call ClearScreen ld hl,(scratch_base) ld a,h ; Swap 'em! ld h,l ld l,a jp (hl) msgShellBadCom: defm "Bad command; enter `help' for help!" defb 0 msgShellOK: defm "OK!" defb 0 msgShellRdy: defm "Ready (enter `help' for help)" defb 0 msgRamError: defm "RAM ERROR! Failed at address: " defb 0 msgRamOK: defm " bytes)" defb 0 msghaltingdisk: defb 13,10 defm "Sorrow in my heart;" defb 13,10 defm "The hard drive, it will not play." defb 13,10 defm "Dead leaves on the ground." defb 13,10,0 msgWelcome: defm " ______ __ _______ _______ ______ " defb 10,13 defm " | __ \__| ___|_ _| __ |" defb 10,13 defm " | < | ___| | | | __ |" defb 10,13 defm " |___|__|__|___| |___| |______|" defb 10,13,10,13 defm " RiFT-OS 1.0 by Fell^RiFT {Iain C}" defb 10,13 defm " ELITE SUPER PRO-SPEC EDITION 2012" defb 10,13,10,13 defm "Testing RAM: OK (" defb 0 msgSerialOK: defm "Serial port: OK (38400bps, 8-N-1)" defb 0 msgAnyKey: defm "Hit any key for shell..." defb 0 msgHDScan: defm "Checking HD: " defb 0 msgHDNotFound: defm "None found" defb 0 msgHDBadFS: defm "OK (Unformatted)" defb 0 msgHDFSOK: defm "OK (RFS, " defb 0 msgHDcap: defm "Mb)" defb 10,13 defm "HD lib name: " defb 0 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; *** BRAINDEAD BASIC INTERPRETER *** ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Limits: ; - Max 255 lines }- 16384 bytes for user prog ; - Max line length 64 chars } ; - Line numbers must be 1-255 ; - Max 52 x 1 char identified (A-Z, a-z), variables (all 16 bit unsigned int) ; - Max 52 x "$ and 1 char" identified ($A-$Z, $a-$z) string variables, max 32 bytes each (total 3328 bytes -- SO WASTEFUL) ; ; Legal statements (note -- they are case sensitive): ; (N and M are line numbers; Z is a direct 16 bit unsigned int; A, B and C are var identifiers) ; goto N ; input A ; print A ; print "Use a ~ for a newline!" ; A={expression | numeral} ; end ; if A>B then N [else M] ; if A<B then N [else M] ; if A<=B then N [else M] ; if A>=B then N [else M] ; if A==B then N [else M] ; if A<>B then N [else M] ; TODO: ; - use the expression evaluator to also do the RHS for comparisons! ; - input A$ ; - print A$ ; [Stop here and unify print functions into a nice linear parser.....] ; - GOSUB ; - FOR ; NICE TO HAVE: ; peek, poke, sys, random, seed ; OPTIMISATIONS: ; (memory) lose the 12 extra bytes in basprogvars ; (memory) should we really be reserving 1.5k+ string buffer? ;) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Constants ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; basicprompt equ '>' ; Command processor prompt character baslinelength equ 64 ; Line length / stride for stepping through baslines ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Memory layout ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; bascurrline equ prog_base ; Current line number (1 byte) basprogvars equ bascurrline+1 ; Program UInt16 variables (58*2 bytes not 51*2 bytes due to ASCII chars 91-96 - TODO - optimise away these 12 wasted bytes!) basprogstrvars equ basprogvars+58*2 ; Program string variables (58*32 bytes not 52*32 bytes due to ASCII chars 91-96 - TODO - optimise away these 192 wasted bytes!!!!!) baslines equ basprogstrvars+58*32; Here starts the prog lines (16384 bytes) basexprstckdpth equ baslines+16384 ; Expression operators stack depth tracking (1 byte) basforstart equ basexprstckdpth+1 ; FOR loop beginning line nums (64 bytes) basforiters equ basforstart+64 ; FOR loop max iters (64 bytes) basgosubstack equ basforiters+64 ; Stack of return line nums for GOSUB (64 bytes) basgosubstackp equ basgosubstack+64 ; Index into GOSUB returns stack (1 byte) bassystop equ basgosubstackp+1 ; (Just for debug) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Editor / command processor ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; basic: call ClearScreen ; Entrypoint - jump here to enter the interpreter :) jp basic_new basic_cmd_loop: ld a,basicprompt call PrintChar call GetString call NewLine ld hl,string_buffer ld de,basList call StrCmp jp c,basic_list ld de,basNew call StrCmp jp c,basic_new ld de,basQuit call StrCmp jp c,shell_loop ld de,basRun call StrCmp jp c,basic_run jp basic_addline ; Add/edit/delete a listing line basic_addline: ld hl,string_buffer call AToUInt8 cp 0 jp z,basic_cmd_loop ld e,a ; Backup line num ld a,(hl) ; Jump over any space cp 32 jp nz,basic_al_nosp inc hl ; Now a contains uint8 line number and hl=start of the actual line (after line number) basic_al_nosp: ld a,e ; Restore line num ld bc,hl ; Backup address of start of actual line ld h,0 ld l,a push hl ; Push line num add hl,hl ; Multiply by 64 (Shift left x 6) - NOTE: THIS NEEDS TO CHANGE IF BASLINELENGTH DOES!!! add hl,hl add hl,hl add hl,hl add hl,hl add hl,hl ld de,baslines add hl,de ; hl = target address to copy to; bc = start address to copy from ld de,hl ; de = dest ld hl,bc ; hl = source ld bc,baslinelength-1 ; bc = count ldir ld a,0 ld (de),a ; Ensure a terminated string ld bc,basMsgLineAdd1 call PrintString pop hl ; Pop line number call PrintUInt16 ld bc,basMsgLineAdd2 call PrintLine jp basic_cmd_loop ; LIST command basic_list: ld hl,0 ld bc,baslines basic_list_lp: ld a,(bc) cp 0 jp z,basic_list_dp ; Skip printing if line is empty call PrintUInt16 ld a,' ' call PrintChar call PrintString call NewLine basic_list_dp: push hl ld hl,bc ld bc,baslinelength add hl,bc ld bc,hl pop hl inc hl ld a,l cp 255 jp z,basic_cmd_loop jp basic_list_lp ; NEW command basic_new: ld hl,baslines ld de,baslines+1 ld bc,baslinelength*256 ld (hl),0 ldir jp basic_cmd_loop ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; RUN command (Main interpreter) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; basic_run: ld a,0 ; Reset PC ld (bascurrline),a ld hl,basStmtEnd ; Insert an END at last instruction ld de,baslines+baslinelength*255 ld bc,4 ldir basic_run_loop: call bas_next_line ; hl now points to start of current line ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;ld bc,basMsgCurLine ; Show debug info ;call PrintLine ;push hl ;ld a,(bascurrline) ;ld h,0 ;ld l,a ;call PrintUInt16 ;ld a,' ' ;call PrintChar ;pop hl ;ld bc,hl ;call PrintLine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ld de,basStmtGoto ; GOTO call StrStarts jp c,bas_stmt_goto ld de,basStmtRem ; REM call StrStarts jp c,bas_step_pc_and_cont ld de,basStmtCls ; CLS call StrStarts jp c,bas_stmt_cls ld de,basStmtPrintString ; PRINT "....." call StrStarts jp c,bas_stmt_print_string ld de,basStmtPrint ; PRINT a call StrStarts jp c,bas_stmt_print ld de,basStmtInput ; INPUT a call StrStarts jp c,bas_stmt_input ld de,basStmtEnd ; END call StrStarts jp c,basic_cmd_loop ld de,basStmtIf ; IF call StrStarts jp c,basic_stmt_if inc hl ; Assignment (A=3) ld a,'=' cp (hl) jp z,bas_stmt_ass dec hl bas_syn_err: ld bc,basMsgSynErr ; Syntax error! call PrintLine push hl ld a,(bascurrline) ld h,0 ld l,a call PrintUInt16 pop hl ld a,' ' call PrintChar ld bc,hl call PrintLine jp basic_cmd_loop ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Using bascurrline, set hl to that line or the next non-empty line bas_next_line: ld bc,baslinelength ld a,(bascurrline) ld h,0 ld l,a add hl,hl ; Multiply by 64 (Shift left x 6) - NOTE: THIS NEEDS TO CHANGE IF BASLINELENGTH DOES!!! add hl,hl add hl,hl add hl,hl add hl,hl add hl,hl ld de,baslines add hl,de ; hl = address of current statement bas_next_stmt_lp: ld a,(hl) cp 0 jp nz,bas_stmt_fnd add hl,bc ; Hmm let's step to next line ld a,(bascurrline) ; Also inc PC! inc a ld (bascurrline),a jp bas_next_stmt_lp bas_stmt_fnd: ret ; Step prog counter and run the next line bas_step_pc_and_cont: ld a,(bascurrline) inc a ld (bascurrline),a jp basic_run_loop ; Get a var. ; Expects: c - var name ; Returns: de - var value bas_get_var: push hl push bc ld hl,basprogvars ; hl=basprogvars ld b,0 add hl,bc ; add the var ident offset add hl,bc ; add the var ident offset ld bc,65 sbc hl,bc ld de,(hl) pop bc pop hl ret ; Set a var. ; Expects: c - var name; de - var value bas_set_var: ld hl,basprogvars ; hl=basprogvars ld b,0 ; (c = var name) add hl,bc ; add the var ident offset add hl,bc ; add the var ident offset (2 bytes) ld bc,65 ; make ASCII A the first one... sbc hl,bc ld (hl),de ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Handle statements ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; IF conditionals :) basic_stmt_if: ld bc,3 add hl,bc ld b,(hl) ; Pick up LHS op inc hl ld de,gr_or_eq ; Try 2-char conditions first... call StrStarts jp c,bas_if_gthan_or_eq ld de,ls_or_eq call StrStarts jp c,bas_if_lthan_or_eq ld de,equal call StrStarts jp c,bas_if_equal ld de,not_equal call StrStarts jp c,bas_if_not_equal ld a,(hl) ; OK, try single char conditions... cp '>' jp z,bas_if_gthan cp '<' jp z,bas_if_lthan jp bas_syn_err ; Didn't find a recognised one! bas_if_lthan: call bas_if_get_post_args ; de=LHS; bc=RHS -- ie, do if (de < bc) bas_if_lthan_actual_chk: and a push hl ld hl,de sbc hl,bc pop hl jp c,bas_if_pass jp bas_if_fail bas_if_gthan: call bas_if_get_post_args ; if (de > bc) ld a,e ; Like gthan_or_eq but with not-equal check first... cp c jp nz,bas_if_gthan_eq_actual_chk ; Different -- do next check ld a,d cp b jp nz,bas_if_gthan_eq_actual_chk ; Different -- do next check jp bas_if_fail ; Same! Continue bas_if_lthan_or_eq: ; if (de <= bc) inc hl call bas_if_get_post_args ld a,e ; Equality check first cp c jp nz,bas_if_lthan_actual_chk ; Different -- do next check ld a,d cp b jp nz,bas_if_lthan_actual_chk ; Different -- do next check jp bas_if_pass ; Same! Pass :) bas_if_gthan_or_eq: ; if (de >= bc) inc hl call bas_if_get_post_args bas_if_gthan_eq_actual_chk: and a push hl ld hl,de sbc hl,bc pop hl jp nc,bas_if_pass jp bas_if_fail bas_if_equal: inc hl ; if (de == bc) call bas_if_get_post_args ld a,e cp c jp nz,bas_if_fail ld a,d cp b jp nz,bas_if_fail jp bas_if_pass bas_if_not_equal: ; if (de != bc) inc hl call bas_if_get_post_args ld a,e cp c jp z,bas_if_fail ld a,d cp b jp z,bas_if_fail jp bas_if_pass bas_if_pass: ld bc,7 add hl,bc ; Skip past RHS var and " then " call AToUInt8 ld (bascurrline),a jp basic_run_loop bas_if_fail: ld bc,7 add hl,bc ; Skip past RHS var and " then " call AToUInt8 ; Eat the then-case line number inc hl ; Step over a potential space " " ld de,basStmtElse call StrStarts ; Check we have "else" jp nc,bas_step_pc_and_cont ; Nope -- just continue ld bc,5 ; Step over "else " add hl,bc call AToUInt8 ; Get else-case line number ld (bascurrline),a ; And set it jp basic_run_loop ; And go!! ; Put LHS value into de and RHS value into bc. ; NOTE!! Accepts: b = LHS var name; hl = address of RHS var name bas_if_get_post_args: ld c,b ; Get LHS name into c call bas_get_var ; Expects c, returns value in de (doesn't trash bc) push de ; de now contains LHS value inc hl ; step to RHS var name ld c,(hl) ; Get RHS var name into c call bas_get_var ; de now contains RHS value ld bc,de ; RHS value is in bc pop de ; LHS value is in de ret ; CLS bas_stmt_cls: call ClearScreen jp bas_step_pc_and_cont ; PRINT (a direct string) bas_stmt_print_string: ld bc,7 add hl,bc bas_stmt_ps_lp: ld a,(hl) cp '"' jp z,bas_step_pc_and_cont cp '~' jp nz,bas_stmt_ps_no_newline call NewLine jp bas_stmt_ps_no_char bas_stmt_ps_no_newline: call PrintChar bas_stmt_ps_no_char: inc hl jp bas_stmt_ps_lp ; PRINT (an int or string var) bas_stmt_print: ld bc,6 add hl,bc ld c,(hl) ; c=var name inc hl ; check for string var ($) ld a,(hl) cp '$' jp z,bas_stmt_print_strvar call bas_get_var ; ok, not a string var ld hl,de call PrintUInt16 jp bas_step_pc_and_cont bas_stmt_print_strvar: ; TODO: Print the string var inc hl ; now pointing at string var name jp bas_step_pc_and_cont ; INPUT (an int var) bas_stmt_input: ld bc,6 add hl,bc ld c,(hl) ; get var name in c inc hl ; check for string var ($) ld a,(hl) cp '$' jp z,bas_stmt_instr ; Input a UInt16 push bc ; to backup var name call GetString ld de,string_buffer call AToUInt16 ld de,hl pop bc ; to restore var name call bas_set_var jp bas_step_pc_and_cont bas_stmt_instr: ; Input a string push bc call GetString ; TODO: STORE THIS SHIT SOMEWHERE ; ASSIGNMENT bas_stmt_ass: dec hl ; Step back to var identifier ld c,(hl) ; Store var ident in c push bc ; Backup var identifier inc hl ; Step over var ident inc hl ; Step over = sign call Parse ; Invoke the cocking expression parser! Returns the result in de :)))) pop bc ; Restore c=var ident call bas_set_var jp bas_step_pc_and_cont ; GOTO bas_stmt_goto: ld bc,5 add hl,bc ; Skip past goto token and space call AToUInt8 ld (bascurrline),a jp basic_run_loop ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Holy 16-bit unsigned int recursive descent expression parser, batman!!!! ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Expects: hl=input pointer ; Returns: de=value; hl=updated input pointer Parse: call ParseFactors ; de=terminal value (num1) Parse_lp: ld a,(hl) ; Grab the oper cp '-' ; check for - jp z,Parse_sub_add ; found! cp '+' ; check for + jp z,Parse_sub_add ; found! ret ; Not found -- return leaving result in de Parse_sub_add: inc hl ; do a sub or add... start with step! ld bc,de ; bc = num1 push bc ; backup num1, we're about to trash it push af ; backup a (the oper), we're about to trash it call ParseFactors ; de = num2 pop af ; restore a=oper pop bc ; restore bc=num1 push hl ; backup input pointer, about to kill it ld hl,bc ; hl = num1 cp '-' ; check which oper again jp z,Parse_sub ; ok, let's sub add hl,de ; let's add!!! jp Parse_s_a_done ; done! Parse_sub: and a ; Clear carry flag to prevent sbc off-by-1! sbc hl,de ; hl = num1 - num2 \o/ Parse_s_a_done: ld de,hl ; update num1 pop hl ; restore input pointer jp Parse_lp ; loop da shizz ; Expects: hl=input pointer ; Returns: de=value; hl=updated input pointer ParseFactors: call ParseTerminal ; de=terminal value (num1 in c) ParseFact_lp: ld a,(hl) ; char a = *hl; cp '/' ; check for / jp z,ParseFact_d_m ; found! cp '*' ; check for * jp z,ParseFact_d_m ; found! ret ; Not found -- return (note we leave our retval in de) ParseFact_d_m: inc hl ; step to the RHS! ld bc,de ; bc = num1 push af ; backup a (the oper), we're about to trash it call ParseTerminal ; de = num2 pop af ; restore a=oper push hl ; backup input pointer, about to kill it cp '/' jp z,ParseFact_div call Mul16 ; hl = bc*de ld de,hl ; update num1 jp ParseFact_dn ParseFact_div: call Div16 ; bc = bc/de ld de,bc ; update num1 ParseFact_dn: pop hl ; restore input pointer jp ParseFact_lp ; sloop ; Expects: hl=input pointer ; Returns: de=value; hl=updated input pointer ParseTerminal: push bc ; Gonna trash bc whatever we do so back it up ld a,(hl) ; First let's peek at this badger to check for a numeral (in which case it's a direct value) or a letter (in which case it's a var) cp 58 jr nc,ParseTerm_var ; (Legit numeric chars are only 48-57!) ld de,hl call AToUInt16 ; convert value into a UInt16 and store it (incrementing hl) ld bc,de ; backup current address after the num... ld de,hl ; set output value in de ld hl,bc ; restore current address pop bc ; restore bc ret ParseTerm_var: ld c,a ; c=var name call bas_get_var ; returns the value in de pop bc ; restore bc inc hl ; manually inc hl to step over the var name ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Strings n things ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ls_or_eq: defm "<=" defb 0 gr_or_eq: defm ">=" defb 0 equal: defm "==" defb 0 not_equal: defm "<>" defb 0 basNew: defm "new" defb 0 basList: defm "list" defb 0 basRun: defm "run" defb 0 basQuit: defm "quit" defb 0 basStmtRem: defm "rem" defb 0 basStmtCls: defm "cls" defb 0 basStmtInput: defm "input " defb 0 basStmtEnd: defm "end" defb 0 basStmtGoto: defm "goto " defb 0 basStmtIf: defm "if " defb 0 basStmtElse: defm "else" defb 0 basStmtPrintString: defm 'print "' defb 0 basStmtPrint: defm "print " defb 0 basMsgLineAdd1: defm "Line " defb 0 basMsgLineAdd2: defm " added/edited" defb 0 basMsgLines: defm " lines." defb 0 basMsgCurLine: defm "DEBUG: Line about to execute:" defb 0 basMsgSynErr: defm "Syntax error near:" defb 0 ; *** DUNGEON FUNGLER *** ; ; Stats: ATT (range 0-15), DEF (range 0-20), HP (range 1-255) ; ; Normal unarmed human: Att=3, Def=2, HP=12 ; ; Character progression levels -- range 0-9 ; ; ATT = 3 + level + equipped-weapon bonus ; DEF = 2 + level + equipped-armour bonus (head) + equipped-armour bonus (body) + equipped-armour bonus (feet) + equipped-weapon or shield bonus ; ; #### COMBAT MODEL #### ; ; (All ATT and DEF below refers to ATTACKER'S ATT and DEFENDER'S DEF) ; Calculate hitcheck = (ATT*16) / (ATT+DEF) ; Roll a d16 numbered 0-15 and compare to hitcheck: ; 0 rolled --> critical hit: DMG = ATT * 2 ; 1 to (hitcheck - 1) rolled --> regular hit: DMG = ATT ; hitcheck rolled --> glancing blow: DMG = ATT / 2 (Possibility to expand this for defender to execute a stop-hit or time-hit if they have the higher att) ; higher than hitcheck rolled --> miss: DMG = 0 ; ; Corner case: ATT=15, DEF=20 -> Attacker must roll 0-6 on a d16 numbered 0-15 ; ; #### DATA STRUCTURES #### ; ; ITEM TABLE @ mfitemtbl (1-BASED INDEX) ; <name:11><map char:1><{if weapon: att/def bonuses}{if not weapon: RESERVED}:1><RESERVED:1><flags:1><activate function:2> ; Att/Def bonuses byte: ; Bits 0-3: Def bonus ; Bits 4-7: Att bonus ; ; Flags: ; Bit 7: Is slottable as head armour? ; Bit 6: Is slottable as body armour? ; Bit 5: Is slottable as feet armour? ; Bit 4: Is slottable as hand weapon? ; Bit 3: If weapon, requires two hands? ; Bit 2: RESERVED ; Bit 1: RESERVED ; Bit 0: RESERVED ; ; MONSTER TABLE @ mfmonstertbl (1-BASED INDEX) ; <name:11><map char:1><att:1><def:1><start hp:1><update function:2> ; ; MONSTER INSTANCE ARRAY @ mfmonsters (1-BASED INDEX) ; <type ID:1><x coord:1><y coord:1><hp:1><standing-on map char:1> ; ; RANKS TABLE @ mfranktbl (0-BASED INDEX) ; <name:11> ; Constants mfmapwidth equ 28 ; Map width mfmapheight equ console_height-1 ; Map height mfnumlevels equ 3 ; Number of dungeon levels before the key's found mfmaxinv equ 20 ; Max inventory slots mfmaxmonsters equ 60 ; Max live monsters :P mfmaxlos equ 5 ; Max line of sight distance ; Memory mfplayername equ prog_base ; Player name mfgold equ mfplayername+10 ; Gold mfhp equ mfgold+2 ; Current HP mfmaxhp equ mfhp+1 ; Max HP mfrank equ mfmaxhp+1 ; Rank mfplayerx equ mfrank+1 ; x (1-indexed) mfplayery equ mfplayerx+1 ; y (1-indexed) mfplayeratt equ mfplayery+1 ; Attack points mfplayerdef equ mfplayeratt+1 ; Defend points mfplayeroldx equ mfplayerdef+1 ; Previous x (1-indexed) mfplayeroldy equ mfplayeroldx+1 ; Previous y (1-indexed) mfdungeonlev equ mfplayeroldy+1 ; Dungeon level (1=right below surface, 2=next down) mfdungeondir equ mfdungeonlev+1 ; Direction of entry into level (0=down, 1=up) mfdoorindex equ mfdungeondir+1 ; Door array counter mfdoorarray equ mfdoorindex+1 ; Door array mfmap equ mfdoorarray+(12) ; The map! mfseenmap equ mfmap+(mfmapwidth*mfmapheight) ; Seen+fov map (0=not seen, 1=seen, 2=Going out of fov, 4=In fov) mfinventory equ mfseenmap+(mfmapwidth*mfmapheight) ; Inventory (0=empty slot, anything else=ID into item table) mfmonsters equ mfinventory+mfmaxinv ; Monster slots mfprintinfoudp equ mfmonsters+(mfmaxmonsters*5) ; Printinfo needed? (1=Yup) mfctlfirstcall equ mfprintinfoudp+1 ; Flag whether this will be first call to cleartopline this frame mfequipslothead equ mfctlfirstcall+1 ; Equip slot: Head armour mfequipslotbody equ mfequipslothead+1 ; Equip slot: Body armour mfequipslotfeet equ mfequipslotbody+1 ; Equip slot: Boots mfequipslothnd1 equ mfequipslotfeet+1 ; Equip slot: Main hand mfequipslothnd2 equ mfequipslothnd1+1 ; Equip slot: Off hand ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; THE HIGH LEVEL CONTROL ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Game entrypoint dungeonfungler: call ClearScreen ; Show welcome message ld bc,mfmsgbanner call PrintLine ld bc,mfmsgintro call PrintLine call GetCharSilent call ClearScreen ld bc,mfmsgbanner call PrintLine ld bc,mfmsgintro2 call PrintLine ld a,shellprompt call PrintChar call GetString call ClearScreen ld hl,string_buffer ; Store player name ld de,mfplayername ld bc,10 ldir ld a,0 ld (mfplayername+9),a ; Ensure a terminated string ld a,1 ; Starting dungeon level = 1 ld (mfdungeonlev),a ld a,0 ld (mfdungeondir),a ; Set direction -- going down ld hl,(mfplayername) ; Set the seed call SeedRand16 ld a,3 ; Set starting stats ld (mfplayeratt),a ld a,3 ld (mfplayerdef),a ld hl,30 ld (mfgold),hl ld a,250 ; DEBUG: WANTON CHEATING! ld (mfhp),a ld (mfmaxhp),a ld a,0 ld (mfrank),a ld hl,mfinventory ; Clear inventory ld a,0 ld b,mfmaxinv mfinvblnkloop: ld (hl),a inc hl dec b jp nz,mfinvblnkloop ld (mfequipslothead),a ; Clear equip slots ld (mfequipslotbody),a ld (mfequipslotfeet),a ld (mfequipslothnd1),a ld (mfequipslothnd2),a ; Level change setup mfdolevelchng: ld a,1 ; Inhibit the prompt/wait on below call to mfcleartopline ld (mfctlfirstcall),a call mfcleartopline ; Show stair ascend/descend message ld a,(mfdungeondir) cp 0 jp z,mfshowdnmess call Rand16 ; Pick a random up msg ld a,l and 3 cp 0 jp z,mfupmsg1 cp 1 jp z,mfupmsg2 ld bc,mfmsgasc3 jp mfshowmsg mfupmsg1: ld bc,mfmsgasc1 jp mfshowmsg mfupmsg2: ld bc,mfmsgasc2 jp mfshowmsg mfshowdnmess: call Rand16 ; Pick a random down msg ld a,l and 3 cp 0 jp z,mfdownmsg1 cp 1 jp z,mfdownmsg2 ld bc,mfmsgdec3 jp mfshowmsg mfdownmsg1: ld bc,mfmsgdec1 jp mfshowmsg mfdownmsg2: ld bc,mfmsgdec2 jp mfshowmsg mfshowmsg: call PrintString call mfbuildmap ; Build the new map call ClearScreen call mfprintinfo ; Print initial infos ld a,(mfdungeonlev) ; Bottom level? cp mfnumlevels jp nz,mfnotbottomlev ld a,1 call mfcheckinventory ; User doesn't already have the key? cp 1 jp z,mfskipstairsdn call mffindfloor ; Add the key!! ld a,'F' call mfsetcellat jp mfskipstairsdn mfnotbottomlev: call mffindfloor ; Not bottom level; place the stairs down ld a,'>' call mfsetcellat ld a,(mfdungeondir) cp 1 ; Player heading up (entered from below)? jp nz,mfskipstairsdn ld a,d ; Yep - so place player on stairs down ld (mfplayerx),a ld a,e ld (mfplayery),a mfskipstairsdn: call mffindfloor ; Place stairs up ld a,'<' call mfsetcellat ld a,(mfdungeondir) cp 0 ; Player heading down (entered from above)? jp nz,mftick ; No -- so they're already placed, let's play already! ld a,d ; Yep - so place player on stairs up ld (mfplayerx),a ld a,e ld (mfplayery),a ; Main game loop mftick: ld a,1 ; Tell next mfcleartopline calls that this is a new frame (ie don't show the Press Space message) ld (mfctlfirstcall),a call mfcalcfov ; Calculate visibility map call mfredrawmap ; Redraw dirty map areas call mfdrawplayer ; Draw the PC jp mfupdateplayer ; Let the PC take their turn mfplayermvret: ld a,(mfprintinfoudp) ; Side panel update needed? cp 1 call z,mfprintinfo ; OK, do it call mfupdatemonsters ; Update the monsters ;;;;;;;;;;;;;;;;;;;;;;;;;;;; ld a,1 ; DEBUG: Bottom-line debugger display ld d,a ld a,console_height ld e,a call CursorXY ld bc,mfmsgblinetest call PrintString ld hl,0 add hl,sp call PrintHex16 ld bc,mfmsgblinetest2 call PrintString ld a,(mfplayerx) call PrintHex8 ld a,',' call PrintChar ld a,(mfplayery) call PrintHex8 ;;;;;;;;;;;;;;;;;;;;;;;;;;;; jp mftick ; Loop ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SIDE PANEL / OTHER UI STUFF ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Prints the sidepanel and bottom line ; Expects: Nowt ; Returns: Nowt mfprintinfo: ld a,0 ; Reset our printinfo-redraw-needed flag ld (mfprintinfoudp),a ld a,29 ; Print info: Side panel ld d,a ld a,3 ld e,a call CursorXY ld bc,mfplayername ; Name call PrintString inc e call CursorXY call mfprintrank ; Rank inc e inc e call CursorXY push de call mfprintdepth ; Depth pop de ld bc,mfmsgdepth call PrintString inc e call CursorXY ld bc,mfmsggold ; Gold call PrintString ld hl,(mfgold) call PrintUInt16 inc e call CursorXY ld bc,mfmsghp ; HP call PrintString ld a,(mfhp) ld h,0 ld l,a call PrintUInt16 ld bc,mfmsgpad2 call PrintString inc e call CursorXY ld bc,msgofhp call PrintString ld a,(mfmaxhp) ld h,0 ld l,a call PrintUInt16 inc e inc e call CursorXY ld bc,mfmsgatt ; Att call PrintString ld a,(mfplayeratt) ld h,0 ld l,a call PrintUInt16 inc e call CursorXY ld bc,mfmsgdef ; Def call PrintString ld a,(mfplayerdef) ld h,0 ld l,a call PrintUInt16 ret ; Clears top line and positions cursor ready to print a line there. If this is not the first message received this frame, it'll ; give a "Press space to continue" prompt before blanking the line -- uses (mfctlfirstcall) ; Expects: Nowt ; Returns: Nowt mfcleartopline: ld a,(mfctlfirstcall) cp 1 ; First call this frame? Skip the wait! jp z,mfctlskipwait ld d,console_width-1 ld e,1 call CursorXY ld a,175 call PrintChar call GetCharSilent mfctlskipwait: ld a,0 ; Set not-first-time-called-this-frame ld (mfctlfirstcall),a call CursorHome ld bc,mfmsgpad38 call PrintString call CursorHome ret ; Prints current dungeon depth in feet ; Expects: Nowt ; Returns: Nowt mfprintdepth: ld a,(mfdungeonlev) ; Current dungeon level (displayed as depth) ld b,a ld hl,0 ld de,50 mflevloop: add hl,de dec b jp nz,mflevloop call PrintUInt16 ret ; Prints current PC rank ; Expects: Nowt ; Returns: Nowt mfprintrank: ld hl,mfranktbl ; Rank ld bc,mfranktblstride ld a,(mfrank) mfpinlp1: cp 0 jp z,mfpinlpdn add hl,bc dec a jp mfpinlp1 mfpinlpdn: ld b,h ld c,l call PrintString ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; MAP BUILDING / DRAWING / ACCESS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Checks the seen map for given cell; if not seen, it draws the cell and marks as seen. ; If revealing an unseen cell, has a chance to spawn a monster if the cell's carpet. ; Expects: d,e=x,y ; Returns: a=the map cell ; Trashes: hl mfsetfovspawnandretchar: push bc call mfmoveto ; Load mapcell address into hl ld b,(hl) ; Backup map char push de ; Backup xy ld de,mfmapwidth*mfmapheight add hl,de ld a,(hl) ; Check the seenmap cell cp 0 ; Never seen it? jp nz,mfmsdifdone ; Skip spawn if we actually have ld a,b ; Restore the map char cp '.' ; Carpet? Then chance to reveal a MONSTER! jp nz,mfmsdifdone push hl call Rand16 ld a,l pop hl and 15 ; Relate this to dungeon level maybe? (Actually, it's fine) cp 7 jp nz,mfmsdifdone pop de push de ld b,0 ; Ask for a random monster push hl call mfspawnmonster ; Spawn a monster! NB: It'll return the monster char in b... pop hl cp 1 ; Did we spawn ok? jp z,mfmsdifdone ; Yep -- go ahead and draw the char ld b,'.' ; No! Just make it carpet, then mfmsdifdone: ld a,4 ; Mark as seen THIS FRAME ld (hl),a ld a,b ; Load the char for ret val pop de ; Restore xy pop bc ret ; Expects: Nothing ; Trashes: Everything mfbuildmap: ;ld hl,(rand16_seed) ; DEBUG: View the seed ;call PrintHex16 ; DEBUG ;ld a,' ' ; DEBUG ;call PrintChar ; DEBUG ld d,0 ; Blank the door array ld (mfdoorindex),a ld d,1 ; Blank the map ld e,1 ld b,mfmapheight ld c,mfmapwidth ld a,' ' call mffillrect ; Expects: d=startx, e=starty, b=height, c=width ld a,0 ; Reset seen map ld de,mfseenmap ld h,mfmapheight mfbsmoloop: ld l,mfmapwidth mfbsmiloop: ld (de),a inc de dec l jp nz,mfbsmiloop dec h jp nz,mfbsmoloop ld hl,mfmonsters ; Clear monsters ld a,0 ld b,mfmaxmonsters mfmnstblnkloop: ld (hl),a inc hl ld (hl),a inc hl ld (hl),a inc hl ld (hl),a inc hl ld (hl),a inc hl dec b jp nz,mfmnstblnkloop ld d,$FF ; LOOP: Place rooms (FF max placement attempts)... mfbmaplp: push de call Rand16 ; Pick a width and height ld a,l and 7 add a,4 ld c,a ; W call Rand16 ld a,l and 7 add a,4 ld b,a ; H call Rand16 ld a,l and 15 add a,4 ld d,a ; X call Rand16 ld a,l and 15 add a,4 ld e,a ; Y ld a,c ; Check bounds, jp to next if no good add a,d cp mfmapwidth jp nc,mfbmaplpnext ld a,b add a,e cp mfmapheight jp nc,mfbmaplpnext dec d dec e inc b inc b inc c inc c call mftestfillrect ; Check the space (+ gap) is actually free, jp to next if not cp 0 jp nz,mfbmaplpnext inc d inc e dec b dec b dec c dec c call mfdig ; Looks good! Dig the room, dog mfdoorstart: call Rand16 ; Pick a wall for the door :) ld a,l and 3 cp 0 jp z,mfdoor2 cp 1 jp z,mfdoor3 cp 2 jp z,mfdoor4 mfdoor1: ld a,h ; Left-hand wall: Just inc e between 1 and height-1 (b) and 7 ld h,a ld l,b dec l dec l call Div8 inc a add a,e ld e,a jp mfdoordone mfdoor2: ld a,d ; Right-hand wall: Inc d by width-1 (c) then inc e between 1 and height-1 (b) add a,c dec a ld d,a and 7 ld h,a ld l,b dec l dec l call Div8 inc a add a,e ld e,a jp mfdoordone mfdoor3: ld a,h ; Top wall: Inc d between 1 and width-1 (c) and 7 ld h,a ld l,c dec l dec l call Div8 inc a add a,d ld d,a jp mfdoordone mfdoor4: ld a,e ; Bottom wall: Inc e by height-1 (b) then inc d between 1 and width-1 (c) add a,b dec a ld e,a and 7 ld h,a ld l,c dec l dec l call Div8 inc a add a,d ld d,a mfdoordone: ld hl,mfdoorarray ; Write the door pos into the door array ld a,(mfdoorindex) ld b,0 ld c,a add hl,bc ; Step to current blank pos add hl,bc ; (2 bytes per entry!) ld (hl),d ; Write the door x and y... inc hl ld (hl),e inc a ; Inc array counter and store it ld (mfdoorindex),a ld a,'.' ; Set the door as actual map carpet to make it a fungletarget call mfsetcellat call Rand16 ; 1-in-16 chance for another door!! ld a,l and 15 cp 0 jp z,mfdoorstart mfbmaplpnext: pop de dec d jp nz,mfbmaplp ld hl,mfdoorarray ; LOOP: Step through door array, digging paths ld a,(mfdoorindex) ld b,a mfdoorloop: ld d,(hl) inc hl ld e,(hl) inc hl call mffungle ; Start Horace from (d,e) cp 0 ; Check return value.... jp z,mfbuildmap ; Shit, we couldn't fungle! Go back to the start of the whole damn thing! push bc ; Set a door character where the door was... push de push hl ld a,'+' call mfsetcellat pop hl pop de pop bc dec b jp nz,mfdoorloop ld d,'=' ; Now replace all temp floor in rooms with actual floor :) ld e,'.' call mfmapreplace ld e,mfmapheight ; LOOP: Step through map, adding walls around corridors mfwallfoloop: ld d,mfmapwidth mfwallfiloop: call mfgetcellat cp ' ' jp nz,mfwallfnext inc d ; OK, this cell's a space! Check its neighbours for carpet/doors.... call mfgetcellat dec d cp '.' jp z,mfwallcarfnd dec d call mfgetcellat inc d cp '.' jp z,mfwallcarfnd inc e call mfgetcellat dec e cp '.' jp z,mfwallcarfnd dec e call mfgetcellat inc e cp '.' jp z,mfwallcarfnd inc d ; Skipping this block gives rounded corners.... inc e call mfgetcellat dec d dec e cp '.' jp z,mfwallcarfnd dec d dec e call mfgetcellat inc d inc e cp '.' jp z,mfwallcarfnd dec d inc e call mfgetcellat inc d dec e cp '.' jp z,mfwallcarfnd inc d dec e call mfgetcellat dec d inc e cp '.' jp z,mfwallcarfnd mfwallfnext: dec d ; Next cell jp nz,mfwallfiloop dec e jp nz,mfwallfoloop ld b,8 ; All walls and carpet now added; let's add some furniture.. mfpuddleloop: call mffindfloor ; Add some puddles! ld a,'~' call mfsetcellat call Rand16 ld a,l and 15 jp nz,mfskipsword call mffindfloor ; DEBUG: Add some longswords! ld a,'l' call mfsetcellat mfskipsword: call Rand16 ld a,l and 15 jp nz,mfskippotion call mffindfloor ; DEBUG: Add some potions! ld a,173 call mfsetcellat mfskippotion: call Rand16 ld a,l and 8 jp nz,mfskipgold call mffindfloor ; DEBUG: Add some delicious gold! ld a,'$' call mfsetcellat mfskipgold: dec b jp nz,mfpuddleloop ret mfwallcarfnd: ld a,178 ; Carpet found in neighbour! Set current cell to wall call mfsetcellat jp mfwallfnext ; A friendly mole called Horace fungles his way from (d,e) until he finds delicious carpet ; Expects: d=x, e=y ; Trashes: d, e mffungle: call NewLine ld a,$FF ld (scratch_base),a push hl push bc mffungletryagn: push de ld a,(scratch_base) dec a ld (scratch_base),a ld b,$FF ; Max steps mffungleloop: dec b ; Check max step counter jp z,mfdonebail ld a,d ; Check x bounds cp 26 jp nc,mfdonebail jp z,mfdonebail cp 1 jp z,mfdonebail ld a,e ; Check y bounds cp mfmapheight-1 jp nc,mfdonebail jp z,mfdonebail cp 1 jp z,mfdonebail ld a,'!' ; Set current cell to temp carpet (we'll replace later with actual carpet -- just don't want to collide with self and think done!) call mfsetcellat call Rand16 ; OK, let's have a look around for some space! Pick a direction to try first randomly (but only allow each dir to be tried once) ld a,l and 00000011b ld c,5 ; Only allow each of the 4 directions to be tried once (pre-decrement) cp 1 jp z,mftrydir2 cp 2 jp z,mftrydir3 cp 3 jp z,mftrydir4 mftrydir1: dec c ; Pre-decrement remaining tries jp z,mfdonebail ; and bail out if tried all 4 dec d ; Step in x call mfgetcellat cp ' ' ; Empty? Go that way! jp z,mffungleloop cp '.' ; Next to carpet? We're done! jp z,mfdoneok inc d ; Not empty OR door; step back to current cell mftrydir2: dec c jp z,mfdonebail dec e call mfgetcellat cp ' ' jp z,mffungleloop cp '.' jp z,mfdoneok inc e mftrydir3: dec c jp z,mfdonebail inc d call mfgetcellat cp ' ' jp z,mffungleloop cp '.' jp z,mfdoneok dec d mftrydir4: dec c jp z,mfdonebail inc e call mfgetcellat cp ' ' jp z,mffungleloop cp '.' jp z,mfdoneok dec e jp mftrydir1 ; Loop back to the start (we randomly jumped in somewhere remember, and c's not 0 so there are dirs left to try) mfdoneok: ld d,'!' ; Door reached; replace temp with actual carpet! ld e,'.' call mfmapreplace pop de pop bc pop hl ld a,1 ; Mark success ret mfdonebail: ld d,'!' ; Outta tries, or stuck; roll back! ld e,' ' call mfmapreplace pop de ld a,(scratch_base) cp 0 jp nz,mffungletryagn ld a,0 ; Mark failure :( pop bc pop hl ret ; Replaces all instances of a char with another char in the map ; Expects: d=char to replace, e=replacement ; Trashes: Stuff... mfmapreplace: ld bc,mfmap ld h,mfmapheight mfmaproloop: ld l,mfmapwidth mfmapriloop: ld a,(bc) cp d jp nz,mfmaprnext ld a,e ld (bc),a mfmaprnext: inc bc dec l jp nz,mfmapriloop dec h jp nz,mfmaproloop ret ; Expects: d=x, e=y, c=width, b=height mfdig: push de push bc ld a,219 call mffillrect inc d inc e dec c dec c dec b dec b ld a,'=' ; Note use of a temp char -- prevents Horace thinking it's actually carpet yet! call mffillrect pop bc pop de ret ; Expects: d=x, e=y ; Returns: Memory address of cell in hl mfmoveto: push bc push de ex af,af' ld bc,mfmapwidth ld hl,mfmap ld a,e mfmovetolp1: cp 1 jp z,mfmtlp1done add hl,bc dec a jp mfmovetolp1 mfmtlp1done: dec d ld e,d ld d,0 add hl,de ex af,af' pop de pop bc ret ; Expects: d=startx, e=starty, b=height, c=width ; Returns: a=0 if space clear, a=1 if not mftestfillrect: push bc push de push hl call mfmoveto ; hl is now address of TL cell ld a,mfmapwidth ; Calculate stride, store in e sub c ld e,a ld d,c ; Backup width, store in d mftestfoloop: ld c,d mftestfiloop: ld a,(hl) cp ' ' jp nz,mftestfillbad inc hl dec c jp nz,mftestfiloop dec b push de ld d,0 add hl,de pop de jp nz,mftestfoloop ld a,0 jp mftestfilldn mftestfillbad: ld a,1 mftestfilldn: pop hl pop de pop bc ret ; Expects: a=fill character, d=startx, e=starty, b=height, c=width ; Returns: Nothing ; Trashes: Nothing mffillrect: push bc push de push hl call mfmoveto ; hl is now address of TL cell ex af,af' ; Backup a (it's the fill char) ld a,mfmapwidth ; Calculate stride, store in e sub c ld e,a ld d,c ; Backup width, store in d ex af,af' ; Restore a mffillloloop: ld c,d mffillliloop: ld (hl),a inc hl dec c jp nz,mffillliloop dec b push de ld d,0 add hl,de pop de jp nz,mffillloloop pop hl pop de pop bc ret ; Calculates the fov map ; Expects: Nowt ; Returns: Nowt mfcalcfov: ld a,(mfplayerx) ld d,a ld a,(mfplayery) ld e,a dec d dec e call mfcalcfoviter inc d call mfcalcfoviter inc d call mfcalcfoviter dec d dec d inc e call mfcalcfoviter inc d call mfcalcfoviter inc d call mfcalcfoviter dec d dec d inc e call mfcalcfoviter inc d call mfcalcfoviter inc d call mfcalcfoviter ret ; Does one simple fov star ; Expects: de - x,y star center point mfcalcfoviter: call mfgetcellat cp 178 ret z cp 219 ret z cp ' ' ret z push de ld b,mfmaxlos mfdplp1: dec e ; Step up jp z,mfdplp1dn call mfsetfovspawnandretchar cp 178 jp z,mfdplp1dn cp 219 jp z,mfdplp1dn cp ' ' jp z,mfdplp1dn dec b jp z,mfdplp1dn jp mfdplp1 mfdplp1dn: pop de push de ld b,mfmaxlos mfdplp2: inc e ; Step down ld a,e cp mfmapheight jp z,mfdplp2dn call mfsetfovspawnandretchar cp 178 jp z,mfdplp2dn cp 219 jp z,mfdplp2dn cp ' ' jp z,mfdplp2dn dec b jp z,mfdplp2dn jp mfdplp2 mfdplp2dn: pop de push de ld b,mfmaxlos mfdplp3: dec d ; Step left jp z,mfdplp3dn call mfsetfovspawnandretchar cp 178 jp z,mfdplp3dn cp 219 jp z,mfdplp3dn cp ' ' jp z,mfdplp3dn dec b jp z,mfdplp3dn jp mfdplp3 mfdplp3dn: pop de push de ld b,mfmaxlos mfdplp4: inc d ; Step right ld a,d cp mfmapwidth jp z,mfdplp4dn call mfsetfovspawnandretchar cp 178 jp z,mfdplp4dn cp 219 jp z,mfdplp4dn cp ' ' jp z,mfdplp4dn dec b jp z,mfdplp4dn jp mfdplp4 mfdplp4dn: pop de push de ld b,mfmaxlos mfdplp5: dec d ; Step up-left jp z,mfdplp5dn dec e jp z,mfdplp5dn call mfsetfovspawnandretchar cp 178 jp z,mfdplp5dn cp 219 jp z,mfdplp5dn cp ' ' jp z,mfdplp5dn dec b jp z,mfdplp5dn jp mfdplp5 mfdplp5dn: pop de push de ld b,mfmaxlos mfdplp6: inc d ; Step up-right ld a,d cp mfmapwidth jp z,mfdplp6dn dec e jp z,mfdplp6dn call mfsetfovspawnandretchar cp 178 jp z,mfdplp6dn cp 219 jp z,mfdplp6dn cp ' ' jp z,mfdplp6dn dec b jp z,mfdplp6dn jp mfdplp6 mfdplp6dn: pop de push de ld b,mfmaxlos mfdplp7: inc e ; Step down-left ld a,e cp mfmapheight jp z,mfdplp7dn dec d jp z,mfdplp7dn call mfsetfovspawnandretchar cp 178 jp z,mfdplp7dn cp 219 jp z,mfdplp7dn cp ' ' jp z,mfdplp7dn dec b jp z,mfdplp7dn jp mfdplp7 mfdplp7dn: pop de push de ld b,mfmaxlos mfdplp8: inc e ; Step down-right ld a,e cp mfmapheight jp z,mfdplp8dn inc d ld a,d cp mfmapwidth jp z,mfdplp8dn call mfsetfovspawnandretchar cp 178 jp z,mfdplp8dn cp 219 jp z,mfdplp8dn cp ' ' jp z,mfdplp8dn dec b jp z,mfdplp8dn jp mfdplp8 mfdplp8dn: pop de ret ; Expects: d=x, e=y ; Returns: a=cell contents ; Trashes: hl, bc mfgetcellat: call mfmoveto ld a,(hl) ret ; Expects: d=x, e=y, a=cell contents ; Returns: Nowt ; Trashes: hl, bc mfsetcellat: call mfmoveto ld (hl),a ret ; Picks a blank bit of floor ; Returns: de=xy mffindfloor: push hl push bc ld b,$FF ; Max attempts mffindfloorlp: call Rand16 ; Pick random xy ld a,l and 31 inc a cp mfmapheight jp nc,mffindfloorlp ld e,a mffindfloorretryx: call Rand16 ld a,l and 31 inc a cp mfmapwidth jp nc,mffindfloorretryx ld d,a call mfgetcellat ; Check for floor cp '.' jp z,mffindfloordn dec b jp nz,mffindfloorlp mffindfloordn: pop bc pop hl ret ; Expects: Nowt mfredrawmapfull: call CursorHome ld bc,mfmap ld de,mfseenmap ld h,mfmapheight mfdrawfoloop: ld l,mfmapwidth mfdrawfiloop: ld a,(de) cp 1 ; Has this cell been seen (in memory)? jp z,mffmemcheck cp 2 ; In view RIGHT NOW?! jp z,mffdrawactual ld a,' ' jp mfdrawfdodraw mffmemcheck: ld a,(bc) cp 219 jp z,mfdrawfmem1 cp 178 jp z,mfdrawfmem2 ld a,' ' jp mfdrawfdodraw mfdrawfmem1: ld a,177 jp mfdrawfdodraw mfdrawfmem2: ld a,176 mfdrawfdodraw: call PrintChar ; MARK: DIRECT-RENDERING inc bc inc de dec l jp nz,mfdrawfiloop call NewLine dec h jp nz,mfdrawfoloop ret mffdrawactual: ld a,(bc) jp mfdrawfdodraw ; (just regions marked as seen) ; Expects: Nowt mfredrawmap: ld bc,mfmap ld de,mfseenmap ld h,mfmapheight mfdrawoloop: ld l,mfmapwidth mfdrawiloop: ld a,(de) cp 4 ; Is this cell currently in FOV? jp z,mfdrawfull cp 2 ; Has this cell GONE OUT OF FOV? jp z,mfdrawandmark1 jp mfshlooop mfdrawfull: ld a,2 ; Set to maybe-going-out-of-fov ld (de),a ld a,(bc) jp mfdrawdodraw mfdrawmem1: ld a,177 jp mfdrawdodraw mfdrawmem2: ld a,176 mfdrawdodraw: push af ; Set the goddam cursor push de ld a,mfmapwidth sub l inc a ld d,a ld a,mfmapheight sub h inc a ld e,a ld a,(mfplayerx) ; Is this really the player?! cp d jp nz,mfdrawreallydraw ld a,(mfplayery) cp e jp nz,mfdrawreallydraw pop de pop af jp mfshlooop mfdrawreallydraw: push hl call CursorXY pop hl pop de pop af call PrintChar ; MARK: DIRECT-RENDERING mfshlooop: inc bc inc de dec l jp nz,mfdrawiloop dec h jp nz,mfdrawoloop ret mfdrawandmark1: ld a,1 ; Set to seen-but-not-in-fov ld (de),a ld a,(bc) cp 219 jp z,mfdrawmem1 cp 178 jp z,mfdrawmem2 ld a,' ' jp mfdrawdodraw ; Expects: Nowt ; Returns: Nowt mfdrawplayer: ld a,(mfplayerx) ld d,a ld a,(mfplayery) ld e,a ;inc e ; Account for fact that screen coords are 1 pix down from map coords! call CursorXY ld a,'@' call PrintChar ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; PLAYER MOVEMENT / COMBAT / ACTIONS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Check player movement, with bounds + coldet checking ; Expects: Nothing ; Returns: a=0 if movement occured; a=1 if none occured; a=2 if stairs down encountered; a=3 if stairs up encountered ; NOTE: USES JP NOT CALL/RET -- To allow this routine to send player to new maps without breaking stack mfupdateplayer: ;call ScanChar ; Uncomment this for crazy realtime mode :P mfupdplykeylp: call GetCharSilent ; (and comment this, obviously!) cp 'w' jp z,mfplayerup cp ' ' jp z,mfplayeraction cp 's' jp z,mfplayerdown cp 'a' jp z,mfplayerleft cp 'd' jp z,mfplayerright cp 'r' jp z,mfplayermvret cp 'q' jp z,mfquit cp 'i' call z,mfshowinv jp mfupdplykeylp mfplayerup: ld a,(mfplayery) dec a cp 0 jp z,mfplayermvret ld e,a ld a,(mfplayerx) ld d,a call mfgetcellat cp 178 jp z,mfplayermvret cp 219 jp z,mfplayermvret jp mfmovementdone mfplayerdown: ld a,(mfplayery) inc a cp mfmapheight+1 jp z,mfplayermvret ld e,a ld a,(mfplayerx) ld d,a call mfgetcellat cp 178 jp z,mfplayermvret cp 219 jp z,mfplayermvret jp mfmovementdone mfplayerleft: ld a,(mfplayerx) dec a cp 0 jp z,mfplayermvret ld d,a ld a,(mfplayery) ld e,a call mfgetcellat cp 178 jp z,mfplayermvret cp 219 jp z,mfplayermvret jp mfmovementdone mfplayerright: ld a,(mfplayerx) inc a cp mfmapwidth+1 jp z,mfplayermvret ld d,a ld a,(mfplayery) ld e,a call mfgetcellat cp 178 jp z,mfplayermvret cp 219 jp z,mfplayermvret mfmovementdone: push af call mfgetmonsteridbychar ; Where are we going? Monster? cp 0 jp nz,mfmeleeattack pop af push de call mfgetitemidbychar ; No; item? cp 0 jp nz,mfshowiteminfo ; Yes!! ld bc,mfmsgpad10 ; No :/ ld d,29 ld e,20 call CursorXY call PrintString inc e call CursorXY call PrintString inc e call CursorXY call PrintString jp mfiteminfodone mfshowiteminfo: push af ld d,29 ; Yep, an item! ld e,20 call CursorXY call Rand16 ld a,l and 1 cp 0 jp z,mfshowiteminf1 ld bc,mfmsgthereis2 jp mfshowiteminf mfshowiteminf1: ld bc,mfmsgthereis1 mfshowiteminf: call PrintString ld d,29 ld e,21 call CursorXY pop af call mfgetitemrecordbyid call PrintString ld d,29 ld e,22 call CursorXY ld bc,mfmsghere call PrintString mfiteminfodone: pop de ld a,d ld (mfplayerx),a ld a,e ld (mfplayery),a jp mfplayermvret ; Note no ret! mfplayeraction: ld a,(mfplayerx) ; Player pressed space ld d,a ld a,(mfplayery) ld e,a call mfgetcellat ; Grab the current cell push de ; Push coords call mfgetitemidbychar ; Check t'see if it's an Item? pop de ; Pop coords cp 0 jp z,mfplayermvret ; Nothing we recognise... ; It IS an item! Fire its activate handler... ld (scratch_base),a ; Just put that there for a sec (item ID)! call mfgetitemrecordbyid push bc ld h,b ld l,c ld bc,15 add hl,bc ld b,(hl) ; Grab update jump address... inc hl ld c,(hl) ld h,c ; Prepare jump address in hl ld l,b pop bc ; Restore the master record ld a,(scratch_base) ; Restore the item ID (xy coords of activation square handily still in de) jp (hl) ; Jump to the event handler.... mfitemactretpoint: ; ... which'll jump back here jp mfplayermvret mfmeleeattack: ; Attacking monster in (d,e); a=monster type -- but we need to match it against the live monster table by coords pop af ; Housekeeping.. call mfgetlivemonsterbycoords push de push hl ld c,0 ld a,(hl) ; Get target's type and do a name lookup call mfgetmonsterecordbyid push hl ; Push array record ld d,29 ld e,16 call CursorXY ld bc,mfmsgtarget call PrintString ld d,29 ld e,17 call CursorXY pop hl ld b,h ld c,l push hl ; Push master record call PrintString call mfcleartopline call Rand16 ; Pick a random attack msg ld a,l and 3 cp 0 jp z,mfstrikemsg1 cp 1 jp z,mfstrikemsg2 cp 2 jp z,mfstrikemsg3 ld bc,mfmsgstrike4 jp mfshowstrikemsg mfstrikemsg1: ld bc,mfmsgstrike1 jp mfshowstrikemsg mfstrikemsg2: ld bc,mfmsgstrike2 jp mfshowstrikemsg mfstrikemsg3: ld bc,mfmsgstrike3 jp mfshowstrikemsg mfshowstrikemsg: call PrintString pop hl ; Pop master record ; Run the combat model calcs for PC attacking NPC and stick final damage inflicted in a (or 0 for a miss) ld de,13 ; Step to monster's DEF add hl,de ld a,(hl) ld d,a ; Store monster's DEF in d ld a,(mfplayeratt) add a,d ; a = att + def ld l,a ; l <-- att+def ld a,(mfplayeratt) rla rla rla rla ld h,a ; h <-- att * 16 call Div8 ; h = (att * 16) / (att+def) -> ie h = required roll, 0-15 ; ld a,h ; DEBUG: FOR CHANCE-TO-HIT DISPLAY ; ld (scratch_base+7),a ; DEBUG: FOR CHANCE-TO-HIT DISPLAY push hl ; Backup chance-to-hit ((att*16) / (att+def)) call Rand16 ; Roll a d16 ;) ld a,l and 15 ; ld (scratch_base+8),a ; DEBUG: FOR CHANCE-TO-HIT DISPLAY pop hl ; Restore chance-to-hit cp 0 jp z,mfmeleecrithit ; Crit hit! cp h jp c,mfmeleehit ; Regular hit! jp z,mfmeleeshithit ; Glancing blow! ld a,0 ; Ooooh, that's a bad miss! jp mfmeleecalcdn mfmeleecrithit: ld a,(mfplayeratt) ; Crit Hit! DMG = ATT * 2 add a,a jp mfmeleecalcdn mfmeleeshithit: ld a,(mfplayeratt) ; Shit Hit! DMG = ATT/2 ld h,a ld l,2 call Div8 ld a,h jp mfmeleecalcdn mfmeleehit: ld a,(mfplayeratt) ; Regular hit! DMG = ATT mfmeleecalcdn: ld (scratch_base),a pop hl ; Pop local array record -- for to update target's HP push hl inc hl inc hl inc hl ld a,(scratch_base) ld d,a ld a,(hl) ; Get target's hitpoints sub d jp z,mfkillmonster jp c,mfkillmonster ld (hl),a push af ld a,(scratch_base) cp 0 jp z,mfpickmissmsg ld d,a ld a,(mfplayeratt) ; Compare with player's ATT cp d jp z,mfreghit jp c,mfcrithit ld bc,mfmsgshithit jp mfshowhitmissmsg mfcrithit: ld bc,mfmsgcrithit jp mfshowhitmissmsg mfreghit: call Rand16 ; Pick a random hit msg ld a,l and 3 cp 0 jp z,mfhitmsg1 cp 1 jp z,mfhitmsg2 cp 2 jp z,mfhitmsg3 ld bc,mfmsghit4 jp mfshowhitmissmsg mfhitmsg1: ld bc,mfmsghit1 jp mfshowhitmissmsg mfhitmsg2: ld bc,mfmsghit2 jp mfshowhitmissmsg mfhitmsg3: ld bc,mfmsghit3 jp mfshowhitmissmsg mfpickmissmsg: call Rand16 ; Pick a random miss msg ld a,l and 3 cp 0 jp z,mfmissmsg1 cp 1 jp z,mfmissmsg2 cp 2 jp z,mfmissmsg3 ld bc,mfmsgmiss4 jp mfshowhitmissmsg mfmissmsg1: ld bc,mfmsgmiss1 jp mfshowhitmissmsg mfmissmsg2: ld bc,mfmsgmiss2 jp mfshowhitmissmsg mfmissmsg3: ld bc,mfmsgmiss3 jp mfshowhitmissmsg mfshowhitmissmsg: call PrintString ld a,(scratch_base) cp 0 jp z,mfskipdmgmsg ld h,0 ld l,a call PrintUInt16 ld bc, mfmsgdamage call PrintString mfskipdmgmsg: ;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;push hl ; DEBUG: Display max roll against our roll ;ld d,console_width-9 ;ld e,2 ;call CursorXY ;ld a,(scratch_base+7) ;ld l,a ;ld h,0 ;call PrintUInt16 ;ld a,':' ;call PrintChar ;ld a,(scratch_base+8) ;ld l,a ;ld h,0 ;call PrintUInt16 ;ld a,' ' ;call PrintChar ;call PrintChar ;pop hl ;;;;;;;;;;;;;;;;;;;;;;;;;;;; pop af ; Print sidepanel stuff push af ld d,29 ld e,18 call CursorXY ld bc,mfmsghp call PrintString pop af ld h,0 ld l,a call PrintUInt16 ld bc,mfmsgpad3 call PrintString pop hl pop de jp mfplayermvret mfkillmonster: pop hl pop de ld a,0 ld (hl),a ; Blank the monster's entry in live monster table: Type inc hl ld (hl),a ; x inc hl ld (hl),a ; y inc hl ld (hl),a ; hp inc hl ld a,(hl) push hl call mfsetcellat mfpickvanqmsg: call Rand16 ; Pick a random vanquished msg ld a,l and 3 cp 0 jp z,mfvanqmsg1 cp 1 jp z,mfvanqmsg2 cp 2 jp z,mfvanqmsg3 ld bc,mfmsgvanq4 jp mfshowhitvanqmsg mfvanqmsg1: ld bc,mfmsgvanq1 jp mfshowhitvanqmsg mfvanqmsg2: ld bc,mfmsgvanq2 jp mfshowhitvanqmsg mfvanqmsg3: ld bc,mfmsgvanq3 jp mfshowhitvanqmsg mfshowhitvanqmsg: call PrintString pop hl ld d,29 ld e,18 call CursorXY ld bc,mfmsgmnstrdead call PrintString ld a,1 ; Mark PrintInfo update needed ld (mfprintinfoudp),a jp mfplayermvret mfquit: call ClearScreen jp shell ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; INVENTORY / ITEMS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Shows the inventory screen ; Expects: Nothing ; Returns: Nothing mfshowinv: call ClearScreen ld bc,mfmsginv call PrintLine call NewLine ld b,mfmaxinv ld c,'a' ld d,0 ld hl,mfinventory mfshowinvlp: ld a,(hl) cp 0 jp nz,mfinvlistitem mfshowinvlpcnt: inc c inc hl dec b jp nz,mfshowinvlp jp mfinvprompt mfinvlistitem: push bc push hl ld d,a ld a,c call PrintChar ld a,':' call PrintChar ld a,ascii_tab call PrintChar ld a,d call mfgetitemrecordbyid call PrintString call NewLine pop hl pop bc inc d jp mfshowinvlpcnt mfinvprompt: call NewLine ld a,d cp 0 jp z,mflstnoitems ld bc,mfmsginvprompt call PrintLine call GetChar call NewLine cp 'e' jp z,mfinvequip cp 'd' jp z,mfinvdrop cp 'x' jp z,mfinvexit jp mfshowinv mflstnoitems: ld bc,msgnoitems call PrintString call GetCharSilent jp mfinvexit mfinvexit: call ClearScreen ; Full screen redraw process: Clear the screen... call mfredrawmapfull ; Draw the memory map ;call mfcalcfov ; Calc fov ;call mfredrawmap ; Draw active FoV regions call mfdrawplayer ; Draw the player call mfprintinfo ; Draw sidebar call mfcleartopline ld bc,mfmsginvclose call PrintString ret mfinvdrop: ld hl,mfinventory ld bc,mfmsgdropsel call PrintLine call GetChar call NewLine sub 97 cp mfmaxinv jp nc,mfinvbaditem mfdropsellp: cp 0 jp z,mfdropseldn dec a inc hl jp mfdropsellp mfdropseldn: ld a,(hl) ; a now contains table ID of chosen item, and hl is item's address in inv cp 0 jp z,mfinvbaditem push hl call mfgetitemcharbyid ; a=map char of item, hl=item's inv address pop hl ld b,a ; Backup A (it's the item char) ld a,(mfplayerx) ; de contains player's xy ld d,a ld a,(mfplayery) ld e,a push bc push hl call mfgetcellat ; Check for a gap at player's location pop hl pop bc cp '.' jp nz,mfinvdropnorm ld a,b ; OK -- Restore A push hl call mfsetcellat ; Place the item down pop hl ld a,0 ld (hl),a ; Remove item from inv jp mfinvexit mfinvdropnorm: ld bc,mfmsgnodrprm call PrintLine call GetCharSilent jp mfinvexit mfinvbaditem: ld bc,mfmsgbaditem call PrintLine call GetCharSilent jp mfinvexit mfinvequip: ; TODO: Implement me jp mfshowinv ; Checks for presence of an item by ID ; Expects: a=item ID ; Returns: a=1 if found, a=0 if not mfcheckinventory: ld b,mfmaxinv ld c,a dec b ld hl,mfinventory mfchkinvlp: ld a,(hl) cp c jp z,mfchkinvfnd inc hl dec b jp nz,mfchkinvlp ld a,0 ret mfchkinvfnd: ld a,1 ret ; Finds an empty slot and adds the item ; Expects: a=Item ID ; Returns: a=1 on success, a=0 on failure (inv full) mfaddinventory: ld c,mfmaxinv ld b,a ld hl,mfinventory mfaddinvloop: ld a,(hl) cp 0 jp z,mfaddinvdoit inc hl dec c jp z,mfinvfull jp mfaddinvloop mfaddinvdoit: ld (hl),b push bc call mfcleartopline call Rand16 ; Pick a random picked-up msg ld a,l and 3 cp 0 jp z,mfpupmsg1 cp 1 jp z,mfpupmsg2 cp 2 jp z,mfpupmsg3 ld bc,mfmsgpickup4 jp mfshowpupmsg mfpupmsg1: ld bc,mfmsgpickup1 jp mfshowpupmsg mfpupmsg2: ld bc,mfmsgpickup2 jp mfshowpupmsg mfpupmsg3: ld bc,mfmsgpickup3 jp mfshowpupmsg mfshowpupmsg: call PrintString pop bc ld a,b call mfgetitemrecordbyid call PrintString ld a,1 ret mfinvfull: call mfcleartopline ld bc, mfmsginvfull call PrintString ld a,0 ret ; Gets an item record by ID ; Expects: a=Item ID ; Returns: bc=0-terminated string with item name mfgetitemrecordbyid: dec a ; Account for 1-based indexing ld hl,mfitemtbl ld bc,mfitemtblstride mfginlp: cp 0 jp z,mfitemfound add hl,bc dec a jp mfginlp mfitemfound: ld b,h ld c,l ret ; Gets an item ID by map char ; Expects: a=Item char ; Returns: a=Item ID, or 0 for no match mfgetitemidbychar: ld d,a ld e,1 ld hl,mfitemtbl ld bc,11 add hl,bc ld bc,mfitemtblstride mfgiilp: ld a,(hl) cp d jp z,mfgiifound add hl,bc inc e ld a,e cp mfnumitems+1 jp nz,mfgiilp ld a,0 ret mfgiifound: ld a,e ret ; Gets an item map character by ID ; Expects: a=Item ID ; Returns: a=Item char mfgetitemcharbyid: dec a ; Account for 1-based indexing ld hl,mfitemtbl ld bc,mfitemtblstride mfgiclp: cp 0 jp z,mfitemcfound add hl,bc dec a jp mfgiclp mfitemcfound: ld b,0 ld c,11 add hl,bc ; Step to char entry in this table row ld a,(hl) ret ; *** Item Activation Behaviours *** ; Called when an item in a map cell is activated by the player ; Can expect the following: ; bc=Base of master record in item table ; de=XY coord we've been activated on ; a=Item ID ; And SHOULD jump back to mfitemactretpoint ; Null behaviour mfitemnothing: jp mfitemactretpoint ; Pickupable behaviour mfitempickup: call mfaddinventory ; It IS pick-up-able -- let's do that :) cp 0 ; Check for pickup failure (inventory could be full for example) jp z,mfitemactretpoint ; Failed -- don't update map char ld a,'.' ; OK, update map char call mfsetcellat jp mfitemactretpoint ; Stairs down behaviour mfitemstdwn: ld a,(mfdungeonlev) inc a ld (mfdungeonlev),a ld a,0 ld (mfdungeondir),a jp mfdolevelchng ; Fine to jp to this, won't kill stack :) ; Stairs up behaviour mfitemstup: ld a,(mfdungeonlev) cp 1 ; Trying to go up from first level? jp z,mfcheckforkey dec a ld (mfdungeonlev),a ld a,1 ld (mfdungeondir),a jp mfdolevelchng mfcheckforkey: ld a,1 call mfcheckinventory ; Got the key? cp 1 jp z,mkkeyfound call mfcleartopline ; No -- show message of stern protestation ld bc,mfmsgnoleave call PrintString jp mfplayermvret mkkeyfound: call ClearScreen ; Yes -- show win message!! ld bc,mfmsgbanner call PrintLine ld bc,mfmsgwin call PrintString ld bc,mfplayername call PrintString ld a,'!' call PrintChar ld bc,mfmsgwin2 call PrintString call mfprintrank ld bc,mfmsgwin3 call PrintString ld hl,(mfgold) call PrintUInt16 ld bc,mfmsgwin4 call PrintString call GetCharSilent call ClearScreen jp shell ; Jump out to the shell, it's all over! ; Gold pickup behaviour mfitemgoldpickup: push de ; We'll want those coords in a mo... call Rand16 ld a,(mfdungeonlev) ld b,a ld a,l and 15 ld c,a ld a,0 mflootloop: add a,c dec b jp nz,mflootloop inc a ; In case it's 0 ld d,0 ld e,a ld hl,(mfgold) add hl,de ld (mfgold),hl call mfcleartopline ld bc,mfmsggoldpup1 call PrintString ld hl,(mfgold) ld h,d ; hl <-- gold gained ld l,e call PrintUInt16 ld bc,mfmsggoldpup2 call PrintString ld a,1 ld (mfprintinfoudp),a ld a,'.' ; Remove the gold :) pop de ; Restore xy coords call mfsetcellat jp mfitemactretpoint ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; MONSTERS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Expects: de=Starting x,y; b=Monster ID to use or 0 for random choice ; Returns: b=Monster char; a=0 if failed and a=1 if succeeded mfspawnmonster: ld c,mfmaxmonsters ld hl,mfmonsters mfspawnloop: ld a,(hl) cp 0 jp z,mfspawndoit inc hl inc hl inc hl inc hl inc hl ld a,0 ; Prepare a=0 in case we're about to return with failure dec c ret z ; Outta slots :/ jp mfspawnloop mfspawndoit: push hl ; Slot found; push its address and choose a mob ld a,b ; Check for a specific ID.... cp 0 jp nz,mfspawnchosen call Rand16 ; Choose a random monster from the bestiary ld a,l and mfbestiarysize inc a mfspawnchosen: pop hl ld (hl),a ; Start to fill out the record... type inc hl ld (hl),d ; Start x inc hl ld (hl),e ; Start y inc hl push hl ld b,0 ld c,14 ; Select HP call mfgetmonsterecordbyid ld a,(hl) dec hl dec hl dec hl ld b,(hl) ; Grab its character pop hl ld (hl),a ; Start HP inc hl ld a,'.' ld (hl),a ; Char underneath us ld a,b ; Set the map cell call mfsetcellat ld a,1 ret ; Expects: Nothing ; Returns: Nothing mfupdatemonsters: ld c,mfmaxmonsters ld hl,mfmonsters mfumonsterloop: ld a,(hl) cp 0 call nz,mfumdoit ld de,5 add hl,de dec c ret z ; All done jp mfumonsterloop mfumdoit: ld d,h ; Store live monster array address for this monster for the update handler ld e,l push hl push bc push de ld b,0 ld c,0 call mfgetmonsterecordbyid ; Grab monster table record for this type... ld b,h ; Store master record address for the update handler ld c,l push bc ld de,15 add hl,de ; Step to update handler address ld b,(hl) ; Grab update jump address... inc hl ld c,(hl) ld h,c ; Prepare jump address in hl ld l,b pop bc ; Restore monster table record pop de ; Restore monster live array record jp (hl) ; Jump to the update handler mfupdretpoint: pop bc ; ... which'll jump back here pop hl ret ; *** Monster Behaviours *** ; These are called for each active monster each frame and can expect: ; de=address of current monster in live array ; bc=address of monster record in master table ; An infestation of spreading stuff!! ; OK for main behaviour: YES ; OK for external jumpin from another behaviour: NO mfmonspreader: call Rand16 ld a,l and 15 ; 1 chance to spread in 32 turns cp 0 jp nz,mfupdretpoint call mfmonupdstandardsave call Rand16 ld a,l and 3 cp 0 jp z,mfmonspreadup cp 1 jp z,mfmonspreaddown cp 2 jp z,mfmonspreadleft jp mfmonspreadright mfmonspreadup: ld a,(scratch_base+1) dec a cp 0 jp z,mfupdretpoint ld e,a ld a,(scratch_base) ld d,a call mfgetcellat cp '.' jp z,mfspreadok cp '+' jp z,mfspreadok jp mfupdretpoint mfmonspreaddown: ld a,(scratch_base+1) inc a cp mfmapheight+1 jp z,mfupdretpoint ld e,a ld a,(scratch_base) ld d,a call mfgetcellat cp '.' jp z,mfspreadok cp '+' jp z,mfspreadok jp mfupdretpoint mfmonspreadleft: ld a,(scratch_base) dec a cp 0 jp z,mfupdretpoint ld d,a ld a,(scratch_base+1) ld e,a call mfgetcellat cp '.' jp z,mfspreadok cp '+' jp z,mfspreadok jp mfupdretpoint mfmonspreadright: ld a,(scratch_base) inc a cp mfmapwidth+1 jp z,mfupdretpoint ld d,a ld a,(scratch_base+1) ld e,a call mfgetcellat cp '.' jp z,mfspreadok cp '+' jp z,mfspreadok jp mfupdretpoint mfspreadok: ld a,(mfplayerx) ; Is the player in the way?! cp d jp nz,mfspreadnotplayer ld a,(mfplayery) cp e jp nz,mfspreadnotplayer jp mfupdretpoint mfspreadnotplayer: ld a,(scratch_base+5) ld b,a push de call mfspawnmonster pop de ;cp 1 ;jp nz,mfupdretpoint ; Bail if spawn failed jp mfupdretpoint ; A monster that wanders unless attacked, in which case it pegs it! ; Checks its HP against the template's to determine if it's been attacked ; OK for main behaviour: YES ; OK for external jumpin from another behaviour: NO mfmoncoward: call mfmonupdstandardsave ld h,b ld l,c push de ld de,14 add hl,de pop de ld a,(hl) ld l,a ; l <-- Start HP ld a,(scratch_base+4) ; a <-- current HP cp l ; Compare jp z,mfmonwanderer_extentry ; Hasn't been attacked :) call Rand16 ; RUN AWAY AND COWER!!! Pick a direction ld a,l and 1 cp 0 jp nz,mfcowardotherway ld a,(mfplayerx) ld h,a ld a,(scratch_base) cp h jp c,mfmongoleft jp mfmongoright mfcowardotherway: ld a,(mfplayery) ld h,a ld a,(scratch_base+1) cp h jp c,mfmongoup jp mfmongodown ; A monster that wanders unless attacked, in which case it persues relentlessly ; Checks its HP against the template's to determine if it's been attacked ; OK for main behaviour: YES ; OK for external jumpin from another behaviour: NO mfmonhonourable: call mfmonupdstandardsave ld h,b ld l,c push de ld de,14 add hl,de pop de ld a,(hl) ld l,a ; l <-- Start HP ld a,(scratch_base+4) ; a <-- current HP cp l ; Compare jp z,mfmonwanderer_extentry ; Hasn't been attacked :) jp mfmonpsycho_extentry ; I DEMAND A DUEL OLD BOY ; A monster that just wanders randomly ; OK for main behaviour: YES ; OK for external jumpin from another behaviour: YES mfmonwanderer: call mfmonupdstandardsave mfmonwanderer_extentry: call Rand16 ld a,l and 3 cp 0 jp z,mfmongoup cp 1 jp z,mfmongodown cp 2 jp z,mfmongoleft jp mfmongoright ; A monster that CAN ONLY ATTACK. This mawfocker LIVES to attack. ATTACK! ; OK for main behaviour: YES ; OK for external jumpin from another behaviour: YES mfmonpsycho: call mfmonupdstandardsave mfmonpsycho_extentry: call Rand16 ld a,l and 1 cp 0 jp nz,mfpsychootherway mfpsychothisway: ld a,(mfplayerx) ld h,a ld a,(scratch_base) cp h jp z,mfpsychootherway ; We're locked in on x -- force y to lock in jp c,mfmongoright jp mfmongoleft mfpsychootherway: ld a,(mfplayery) ld h,a ld a,(scratch_base+1) cp h jp z,mfpsychothisway ; We're locked in on y -- force x to lock in jp c,mfmongodown jp mfmongoup ; Behaviours helper: Save useful stuff in scratch without wrecking de and bc: current xy, monster character, and such mfmonupdstandardsave: push de ; push live array address ld a,(de) ; grab current type ld (scratch_base+5),a ; store it inc de ld a,(de) ; grab current x ld (scratch_base),a ; and store it inc de ld a,(de) ; grab current y ld (scratch_base+1),a ; and store it inc de ld a,(de) ; grab current hp ld (scratch_base+4),a ; and store it inc de ld a,(de) ; grab current standing-on map char ld (scratch_base+3),a ; and store it ld de,11 ld h,b ld l,c add hl,de ld a,(hl) ; Grab monster's map char ld (scratch_base+2),a ; Store it inc hl ld a,(hl) ld (scratch_base+6),a ; Store monster's Att ;inc hl ;ld (scratch_base+7),a ; Store monster's Def pop de ; Restore live array address ret ; Behaviours helper: Perform chosen movement or attack player ; OK for main behaviour: NO ; OK for external jumpin from another behaviour: YES mfmongoup: push de ld a,(scratch_base+1) dec a cp 0 jp z,mfmonmovementnone ld e,a ld a,(scratch_base) ld d,a call mfgetcellat cp 178 jp z,mfmonmovementnone cp 219 jp z,mfmonmovementnone jp mfmonmovementdone mfmongodown: push de ld a,(scratch_base+1) inc a cp mfmapheight+1 jp z,mfmonmovementnone ld e,a ld a,(scratch_base) ld d,a call mfgetcellat cp 178 jp z,mfmonmovementnone cp 219 jp z,mfmonmovementnone jp mfmonmovementdone mfmongoleft: push de ld a,(scratch_base) dec a cp 0 jp z,mfmonmovementnone ld d,a ld a,(scratch_base+1) ld e,a call mfgetcellat cp 178 jp z,mfmonmovementnone cp 219 jp z,mfmonmovementnone jp mfmonmovementdone mfmongoright: push de ld a,(scratch_base) inc a cp mfmapwidth+1 jp z,mfmonmovementnone ld d,a ld a,(scratch_base+1) ld e,a call mfgetcellat cp 178 jp z,mfmonmovementnone cp 219 jp z,mfmonmovementnone mfmonmovementdone: push af ; Backup the char in the square for a mo, as mfmonnotplayer will want it ld a,(mfplayerx) cp d jp nz,mfmonnotplayer ld a,(mfplayery) cp e jp nz,mfmonnotplayer pop af ; It's the player -- attack!! call mfcleartopline call Rand16 ld a,l and 3 cp 0 jp z,mfmonstrmsg1 cp 1 jp z,mfmonstrmsg2 cp 2 jp z,mfmonstrmsg3 ld bc,mfmsgmnstrike4 jp mfshowmnstrikemsg mfmonstrmsg1: ld bc,mfmsgmnstrike1 jp mfshowmnstrikemsg mfmonstrmsg2: ld bc,mfmsgmnstrike2 jp mfshowmnstrikemsg mfmonstrmsg3: ld bc,mfmsgmnstrike3 mfshowmnstrikemsg: call PrintString ; Run NPC on PC combat calcs ld a,(mfplayerdef) ld d,a ; Store players's DEF in d ld a,(scratch_base+6) ; Load monster's ATT add a,d ; a = att + def ld l,a ; l <-- att+def ld a,(scratch_base+6) rla rla rla rla ld h,a ; h <-- att * 16 call Div8 ; h = (att * 16) / (att+def) -> ie h = required roll, 0-15 push hl ; Backup chance-to-hit ((att*16) / (att+def)) call Rand16 ; Roll a d16 ;) ld a,l and 15 pop hl ; Restore chance-to-hit cp 0 ; Compare roll to 0 jp z,mfmonstercrithit ; Crit hit! cp h ; Compare roll to chance-to-hit requirement jp c,mfmonsterhit ; Chance-to-hit greater than what we rolled? Then we hit! jp z,mfmonstershithit ; Glancing blow ld a,0 ; Missed! Set damage to 0 ld (scratch_base+8),a jp mfmonstercalcdn mfmonstercrithit: ld a,(scratch_base+6) ; Crit Hit! Set damage to monster's ATT * 2 add a,a ld (scratch_base+8),a jp mfmonstercalcdn mfmonstershithit: ld a,(scratch_base+6) ; Shit Hit! Set damage to monster's ATT / 2 ld h,a ld l,2 call Div8 ld a,h ld (scratch_base+8),a jp mfmonstercalcdn mfmonsterhit: ld a,(scratch_base+6) ; Hit! Set damage to monster's ATT ld (scratch_base+8),a mfmonstercalcdn: ld a,(scratch_base+8) ld d,a ld a,(mfhp) sub d jp z,mfplayerdead ; Have we just killed the player?! jp c,mfplayerdead ld (mfhp),a ld a,d cp 0 jp z,mfmpickmissmsg ld a,(scratch_base+6) ; Compare with monster's ATT cp d jp z,mfmreghit jp c,mfmcrithit ld bc,mfmmsgshithit jp mfmshowhitmissmsg mfmcrithit: ld bc,mfmmsgcrithit jp mfmshowhitmissmsg mfmreghit: call Rand16 ; Pick a random hit msg ld a,l and 3 cp 0 jp z,mfmhitmsg1 cp 1 jp z,mfmhitmsg2 cp 2 jp z,mfmhitmsg3 ld bc,mfmmsghit4 jp mfmshowhitmissmsg mfmhitmsg1: ld bc,mfmmsghit1 jp mfmshowhitmissmsg mfmhitmsg2: ld bc,mfmmsghit2 jp mfmshowhitmissmsg mfmhitmsg3: ld bc,mfmmsghit3 jp mfmshowhitmissmsg mfmpickmissmsg: call Rand16 ; Pick a random miss msg ld a,l and 3 cp 0 jp z,mfmmissmsg1 cp 1 jp z,mfmmissmsg2 cp 2 jp z,mfmmissmsg3 ld bc,mfmmsgmiss4 jp mfmshowhitmissmsg mfmmissmsg1: ld bc,mfmmsgmiss1 jp mfmshowhitmissmsg mfmmissmsg2: ld bc,mfmmsgmiss2 jp mfmshowhitmissmsg mfmmissmsg3: ld bc,mfmmsgmiss3 jp mfmshowhitmissmsg mfmshowhitmissmsg: call PrintString ld a,(scratch_base+8) cp 0 jp z,mfmskipdmgmsg ld h,0 ld l,a call PrintUInt16 ld bc, mfmmsgdamage call PrintString mfmskipdmgmsg: pop de ; Restore live array address ; Show our opponent info ld a,(scratch_base+5) ld c,0 call mfgetmonsterecordbyid push hl ld d,29 ld e,16 call CursorXY ld bc,mfmsgtarget call PrintString ld d,29 ld e,17 call CursorXY pop hl ld b,h ld c,l call PrintString ld d,29 ld e,18 call CursorXY ld bc,mfmsghp call PrintString ld a,(scratch_base+4) ld h,0 ld l,a call PrintUInt16 ld bc,mfmsgpad3 call PrintString ld a,33 ; Update player's HP display in side panel ld d,a ld a,8 ld e,a call CursorXY ld a,(mfhp) ld h,0 ld l,a call PrintUInt16 ld bc,mfmsgpad2 call PrintString jp mfupdretpoint ; Attack done, back to the ret point mfmonnotplayer: pop af call mfgetmonsteridbychar ; Trying to walk into another monster? cp 0 jp nz,mfmonmovementnone ; Disallow that! ld h,d ; OK, actual legal movement!! h <-- new x ld l,e ; l <-- new y pop de ; Update live array with new position push de ; push live array address inc de ld a,h ld (de),a inc de ld a,l ld (de),a pop de ; Restore live array address ; Remove old pos from map and undraw push de ; push live array address ld a,(scratch_base) ; grab OLD xy ld d,a ld a,(scratch_base+1) ld e,a ld a,(scratch_base+3) call mfsetcellat ; Set current cell back to whatever we're standing on pop de ; Restore live array address ; Set new pos in map and redraw ld h,d ; copy live array address into hl ld l,e push de ; push live array address inc hl ; Put NEW x and y coords into de ld d,(hl) inc hl ld e,(hl) push hl call mfgetcellat ; Get the char currently at the place we're stepping to... pop hl inc hl inc hl ; Step to right entry in live array cell ld (hl),a ; Update our standing-on character ld a,(scratch_base+2) ; Load the monster char call mfsetcellat ; Set current cell as monster pop de ; Restore live array address jp mfupdretpoint mfmonmovementnone: pop de ; Restore live array address jp mfupdretpoint mfplayerdead: pop de ld bc,mfmsgcollapse call PrintString ld a,33 ; Show HP as 0 in side panel ld d,a ld a,8 ld e,a call CursorXY ld a,'0' call PrintChar ld bc,mfmsgpad2 call PrintString ld a,(scratch_base+5) ; Show our opponent info ld c,0 call mfgetmonsterecordbyid push hl ld d,29 ld e,16 call CursorXY ld bc,mfmsgtarget call PrintString ld d,29 ld e,17 call CursorXY pop hl ld b,h ld c,l call PrintString ld d,29 ld e,18 call CursorXY ld bc,mfmsghp call PrintString ld a,(scratch_base+4) ld h,0 ld l,a call PrintUInt16 ld bc,mfmsgpad3 call PrintString mfdeadspacelp: call GetCharSilent cp ' ' jp nz,mfdeadspacelp call ClearScreen ld bc,mfmsgbanner call PrintLine ld bc,mfmsgdeath call PrintString ld bc,mfplayername call PrintString ld bc,mfmsgdeath2 call PrintString call mfprintrank ld bc,mfmsgdeath3 call PrintString call mfprintdepth ld bc,mfmsgdeath4 call PrintString ld hl,(mfgold) call PrintUInt16 ld bc,mfmsgdeath5 call PrintString ld a,(scratch_base+2) call mfgetmonsteridbychar ld c,0 call mfgetmonsterecordbyid ld b,h ld c,l call PrintString call NewLine call GetCharSilent call ClearScreen ld bc,mfmsgbanner call PrintLine call NewLine ld bc,mfmsgdeath6 call PrintString ld d,25 ld e,23 call CursorXY ld bc,mfplayername call StrLen ld h,a ld l,2 call Div8 ld a,5 sub h dec a ld h,a ld a,' ' mfdeathsplp: call PrintChar dec h jp nz,mfdeathsplp call PrintString call GetCharSilent call ClearScreen jp shell ; Gets a live monster entry by xy coords ; Expects: de=x,y on map ; Returns: hl=Base address of record in live monster array mfgetlivemonsterbycoords: ld hl,mfmonsters inc hl mfglmbclp: ld a,(hl) cp d jp z,mfglmbcdblchk inc hl inc hl inc hl inc hl inc hl jp mfglmbclp mfglmbcdblchk: inc hl ld a,(hl) cp e jp z,mfglmbcyup inc hl inc hl inc hl inc hl jp mfglmbclp mfglmbcyup: dec hl dec hl ret ; Gets a monster entry by ID; also uses an offset to choose the field you want. ; Expects: a=Monster ID; c=offset ; Returns: hl=Base address of record in master table mfgetmonsterecordbyid: push bc dec a ; Account for 1-based indexing ld hl,mfmonstertbl ld bc,mfmonstertblstride mfgmclp: cp 0 jp z,mfmonstrcfound add hl,bc dec a jp mfgmclp mfmonstrcfound: pop bc ld b,0 add hl,bc ; Step to wabted entry in this table row ret ; Gets an item ID by map char ; Expects: a=Monster char ; Returns: a=Monster ID, or 0 for no match mfgetmonsteridbychar: push de push bc ld d,a ld e,1 ld hl,mfmonstertbl ld bc,11 add hl,bc ld bc,mfmonstertblstride mfgmilp: ld a,(hl) cp d jp z,mfgmifound add hl,bc inc e ld a,e cp mfnummonsters+1 jp nz,mfgmilp ld a,0 pop bc pop de ret mfgmifound: ld a,e pop bc pop de ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; STRINGS AND TABLES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Strings: Banner screens mfmsgbanner: defm " __ _ _ __ _ __ ___ __ __ _" defb 13,10 defm " |*_\| || | \| |/ _] __/__\| \| |" defb 13,10 defm " | v | \/ | | ' | [/\ _| \/ | | ' |" defb 13,10 defm " |__/ \__/|_|\__|\__/___\__/|_|\__|" defb 13,10 defm " ___ _ _ __ _ __ _ ___ ___" defb 13,10 defm " |*__| || | \| |/ _] | | __| _ \" defb 13,10 defm " | _|| \/ | | ' | [/\ |_| _|| v /" defb 13,10 defm " |_| \__/|_|\__|\__/___|___|_|_\" defb 13,10 defb 0 mfmsgintro: defm " Foolishly, you've ventured through" defb 13,10 defm " the trapdoor in Robber's Cave... and" defb 13,10 defm " it's already slammed shut and locked" defb 13,10 defm " behind you. Your only choice now is" defb 13,10 defm " onwards, deep into the terrible Maen" defb 13,10 defm " Arthur dungeons, to find the key -" defb 13,10 defm " and with it, your freedom!" defb 13,10 defb 13,10 defm " ~ Prithee press a key to continue ~" defb 0 mfmsgintro2: defm " ~ Ye Controls ~" defb 13,10 defm " Climb, pick up, etc : Space" defb 13,10 defm " Move/melee attack : wsad" defb 13,10 defm " View inventory : i" defb 13,10 defm " Rest : r" defb 13,10 defb 13,10 defm " Whenever you see " defb 175 defm ", hit any key " defb 13,10 defm " to continue." defb 13,10 defb 13,10 defm "Enter your name to start:" defb 0 mfmsgdeath: defm " GAH! You totally died :(" defb 13,10 defb 13,10 defm " RIP " defb 0 mfmsgdeath2: defm ", brave adventurer," defb 13,10 defm " who held the rank of " defb 0 mfmsgdeath3: defb 13,10 defb 13,10 defm " Killed at a depth of " defb 0 mfmsgdeath4: defm " feet" defb 13,10 defm " while carrying " defb 0 mfmsgdeath5: defm " gold, " defb 13,10 defm " by a " defb 0 mfmsgdeath6: defm " _.---,._,' " defb 13,10 defm " /' _.--.< " defb 13,10 defm " /' `' " defb 13,10 defm " /' _.---._____ " defb 13,10 defm " \.' ___, .-'` " defb 13,10 defm " /' \\" defb 13,10 defm " /' `-." defb 13,10 defm " |" defb 13,10 defm " | .-'~~~`-." defb 13,10 defm " | .' `." defb 13,10 defm " | | R I P |" defb 13,10 defm " | | |" defb 13,10 defm " jgs | | |" defb 13,10 defm " \ \\| |//" defb 13,10 defm "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" defb 0 mfmsgwin: defm " ** YOU ARE FREE FROM THE DUNGEONS **" defb 13,10 defb 13,10 defm " As you emerge, blinking in the light," defb 13,10 defm " the citizens of Maen Arthur gather" defb 13,10 defm " round you in wonder -- for you are" defb 13,10 defm " the first adventurer to ever survive" defb 13,10 defm " the dreaded dungeons." defb 13,10 defb 13,10 defm " Congratulations, " defb 0 mfmsgwin2: defb 13,10 defb 13,10 defm " You attained the rank of " defb 0 mfmsgwin3: defb 13,10 defm " and escaped with " defb 0 mfmsgwin4: defm " gold." defb 0 ; Strings: Topline stuff mfmsginvclose: defm "You stop rummaging in your bag." defb 0 mfmsgmnstrike1: defm "The foe attacks" defb 0 mfmsgmnstrike2: defm "The foe assaults" defb 0 mfmsgmnstrike3: defm "The foe assails" defb 0 mfmsgmnstrike4: defm "The foe strikes" defb 0 mfmsgcollapse: defm "... YOU COLLAPSE! [SP]" defb 0 mfmmsgmiss1: defm " but you dodge!" defb 0 mfmmsgmiss2: defm " but you block!" defb 0 mfmmsgmiss3: defm " but misses!" defb 0 mfmmsgmiss4: defm " but you parry!" defb 0 mfmmsgcrithit: defm "; CRITICAL HIT! -" defb 0 mfmmsgshithit: defm "; glancing blow -" defb 0 mfmmsghit1: defm " and hits! -" defb 0 mfmmsghit2: defm " well; -" defb 0 mfmmsghit3: defm " for -" defb 0 mfmmsghit4: defm ", causing -" defb 0 mfmmsgdamage: defm " HP" defb 0 mfmsggoldpup1: defm "You acquire " defb 0 mfmsggoldpup2: defm " gold!" defb 0 mfmsgpickup1: defm "You pick up a " defb 0 mfmsgpickup2: defm "You grab a " defb 0 mfmsgpickup3: defm "You sieze a " defb 0 mfmsgpickup4: defm "You grasp a " defb 0 mfmsgstrike1: defm "You strike" defb 0 mfmsgstrike2: defm "You thrust" defb 0 mfmsgstrike3: defm "You attack" defb 0 mfmsgstrike4: defm "You swing" defb 0 mfmsgmiss1: defm " but are parried!" defb 0 mfmsgmiss2: defm " but your foe blocks!" defb 0 mfmsgmiss3: defm " but miss!" defb 0 mfmsgmiss4: defm " but the enemy dodges!" defb 0 mfmsghit1: defm " and hit: " defb 0 mfmsghit2: defm " and hit for " defb 0 mfmsghit3: defm " and cause " defb 0 mfmsghit4: defm ", inflicting " defb 0 mfmsgcrithit: defm "; a HUGE hit! " defb 0 mfmsgshithit: defm "; a POOR hit! " defb 0 mfmsgdamage: defm " HP damage" defb 0 mfmsgvanq1: defm "; your foe is vanquished!" defb 0 mfmsgvanq2: defm ", destroying your enemy" defb 0 mfmsgvanq3: defm " and kill your adversary" defb 0 mfmsgvanq4: defm ", dispatching the creature" defb 0 mfmsginvfull: defm "You're too encumbered to pick that up!" defb 0 mfmsgdec1: defm "You descend the stairs..." defb 0 mfmsgasc1: defm "You ascend the stairs..." defb 0 mfmsgdec2: defm "You clamber down the stairs..." defb 0 mfmsgasc2: defm "You clamber up the stairs..." defb 0 mfmsgdec3: defm "You stumble down the stairs..." defb 0 mfmsgasc3: defm "You drag yourself up the stairs..." defb 0 mfmsgnoleave: defm "You can't leave without the key!" defb 0 ; Strings: Sidepanel stuff mfmsgdepth: defm " feet " defb 0 mfmsggold: defm "Au: " defb 0 mfmsghp: defm "HP: " defb 0 msgofhp: defm " of " defb 0 mfmsgatt: defm "Att:" defb 0 mfmsgdef: defm "Def:" defb 0 mfmsgtarget: defm "Opponent:" defb 0 mfmsgthereis1: defm "There is a" defb 0 mfmsgthereis2: defm "You see a " defb 0 mfmsghere: defm "here." defb 0 mfmsgmnstrdead: defm "* DEAD * " defb 0 ; Strings: Misc mfmsginv: defm "INVENTORY" defb 0 mfmsginvprompt: defm "Commands: (e)quip, (d)rop, e(x)it" defb 0 msgnoitems: defm "You are bereft of carryments! " defb 175 defb 0 mfmsgdropsel: defm "Choose an item to drop..." defb 0 mfmsgbaditem: defm "No such item, adventurin' dude! " defb 175 defb 0 mfmsgnodrprm: defm "There's no room to put that down here! " defb 175 defb 0 mfmsgblinetest: defm "SP=" ; DEBUG defb 0 mfmsgblinetest2: defm ";Player=" ; DEBUG defb 0 mfmsgpad2: defm " " defb 0 mfmsgpad3: defm " " defb 0 mfmsgpad10: defm " " defb 0 mfmsgpad38: defm " " defb 0 ; Tables ; Rank table ; <name:11> mfranktblstride equ 11 mfranktbl: defm "Nubbins " ; 0 defb 0 defm "Blagger " ; 1 defb 0 defm "Novice " ; 2 defb 0 defm "Apprentice" ; 3 defb 0 defm "Journeyman" ; 4 defb 0 defm "Adventurer" ; 5 defb 0 defm "Total Pro " ; 6 defb 0 defm "Master " ; 7 defb 0 defm "Legendary " ; 8 defb 0 defm "Godlike " ; 9 defb 0 ; Item table ; <name:11><map char:1><{if weapon: att/def bonuses}{if not weapon: RESERVED}:1><RESERVED:1><flags:1><activate function:2> ; Att/Def bonuses byte: ; Bits 0-3: Def bonus ; Bits 4-7: Att bonus ; ; Flags: ; Bit 7: Is slottable as head armour ; Bit 6: Is slottable as body armour ; Bit 5: Is slottable as feet armour ; Bit 4: Is slottable as hand weapon ; Bit 3: If weapon, requires two hands ; Bit 2: RESERVED ; Bit 1: RESERVED ; Bit 0: RESERVED mfitemtblstride equ 17 mfnumitems equ 8 mfitemtbl: defm "GOLDEN KEY" ; Name defb 0 defb 'F' ; Map char defb 0 ; Att/def bonuses if weapon defb 0 ; RESERVED defb 00000000b ; Flags! defw mfitempickup ; OnActivate defm "longsword " ; Name defb 0 defb 'l' ; Map char defb 2 ; Att/def bonuses if weapon defb 1 ; RESERVED defb 00010000b ; Flags! defw mfitempickup ; OnActivate defm "Coin Purse" ; Name defb 0 defb '$' ; Map char defb 0 ; Att/def bonuses if weapon defb 0 ; RESERVED defb 00010000b ; Flags! defw mfitemgoldpickup ; OnActivate defm "HP Potion " ; Name defb 0 defb 173 ; Map char defb 0 ; Att/def bonuses if weapon defb 0 ; RESERVED defb 00000000b ; Flags defw mfitempickup ; OnActivate defm "puddle " ; Name defb 0 defb '~' ; Map char defb 0 ; Att/def bonuses if weapon defb 0 ; RESERVED defb 00000000b ; Flags defw mfitemnothing ; OnActivate defm "staircase " ; Name defb 0 defb '<' ; Map char defb 0 ; Att/def bonuses if weapon defb 0 ; RESERVED defb 00000000b ; Flags defw mfitemstup ; OnActivate defm "staircase " ; Name defb 0 defb '>' ; Map char defb 0 ; Att/def bonuses if weapon defb 0 ; RESERVED defb 00000000b ; Flags defw mfitemstdwn ; OnActivate defm "door " ; Name defb 0 defb '+' ; Map char defb 0 ; Att/def bonuses if weapon defb 0 ; RESERVED defb 00000000b ; Flags defw mfitemnothing ; OnActivate ; Monster table ; <name:11><map char:1><att:1><def:1><start hp:1><update function:2> ; TODO: XP for monsters innit; ; + Implement level-gaining ; Also, monster loot drops can be based on monster XP! mfmonstertblstride equ 17 mfbestiarysize equ 7 ; NB: USED AS AND FLAG WITH RESULT THEN INC'D BY 1 mfnummonsters equ 8 mfmonstertbl: ; MONSTER 1 defm "Slime mold" ; Name defb 0 defb '*' ; Map char defb 1 ; Att defb 1 ; Def defb 1 ; Start HP defw mfmonspreader ; OnUpdate ; MONSTER 2 defm "Baselisk " ; Name defb 0 defb 's' ; Map char defb 2 ; Att defb 2 ; Def defb 5 ; Start HP defw mfmonhonourable ; OnUpdate ; MONSTER 3 defm "Feral Mani" ; Name defb 0 defb 'm' ; Map char defb 3 ; Att defb 3 ; Def defb 6 ; Start HP defw mfmonhonourable ; OnUpdate ; MONSTER 4 defm "Balrog " defb 0 defb 'B' ; Map char defb 9 ; Att defb 9 ; Def defb 10 ; Start HP defw mfmonpsycho ; OnUpdate ; MONSTER 5 defm "Fungleater" ; Name defb 0 defb '#' ; Map char defb 5 ; Att defb 1 ; Def defb 3 ; Start HP defw mfmoncoward ; OnUpdate ; MONSTER 6 defm "Barrel-man" ; Name defb 0 defb 'U' ; Map char defb 4 ; Att defb 4 ; Def defb 4 ; Start HP defw mfmonhonourable ; OnUpdate ; MONSTER 7 defm "Drunk bat " defb 0 defb '"' ; Map char defb 2 ; Att defb 4 ; Def defb 4 ; Start HP defw mfmonwanderer ; OnUpdate ; MONSTER 8 defm "Farty hog " defb 0 defb '&' ; Map char defb 8 ; Att defb 8 ; Def defb 7 ; Start HP defw mfmonhonourable ; OnUpdate ; MONSTER 9 defm "Winged hob" ; Name defb 0 defb 'w' ; Map char defb 3 ; Att defb 7 ; Def defb 7 ; Start HP defw mfmonhonourable ; OnUpdate ; *** Subroutine: Play the game of life! *** game_of_life: golwidth equ console_width ; Game constants golheight equ console_height golboardaddress equ prog_base+golwidth golboardsize equ golwidth*golheight ;golcellnew equ 'o' ; Game of Life characters ;golcell2 equ 'O' ;golcell equ '@' golcellnew equ 176 golcell2 equ 177 golcell equ 178 golempty equ ' ' ld bc,golmsgintro ; Show welcome call PrintLine ld a,shellprompt call PrintChar call GetChar ; Get and set seed call SeedRand8 call ClearScreen ld bc,golboardaddress ; Setup initial board ld h,golheight golsetupoloop: ld l,golwidth golsetupiloop: call Rand8 cp 80 jp nc,golsetempcell ld a,golcell ld (bc),a jp golsetupcont golsetempcell: ld a,golempty ld (bc),a golsetupcont: inc bc dec l jp nz,golsetupiloop dec h jp nz,golsetupoloop ld bc,prog_base ; Setup blank top border (as update reads above board when neighbour checking) ld l,golwidth golborderloop: ld a,golempty ld (bc),a inc bc dec l jp nz,golborderloop goldrawloop: call CursorHome ; Update & draw board ld bc,golboardaddress ld h,golheight golupdoloop: ld l,golwidth golupdiloop: push hl push bc ld h,b ld l,c ld b,0 ; Counter for num of neighbours found ld de,golwidth+1 ; Set hl to first neighbour pos (above-left of us) sbc hl,de ld a,(hl) cp golempty jp z,golnextneigh1 inc b golnextneigh1: inc hl ; 2nd pos: above us ld a,(hl) cp golempty jp z,golnextneigh2 inc b golnextneigh2: inc hl ; 3rd pos: above-right of us ld a,(hl) cp golempty jp z,golnextneigh3 inc b golnextneigh3: ld de,golwidth-2 ; 4 pos: left of us add hl,de ld a,(hl) cp golempty jp z,golnextneigh4 inc b golnextneigh4: inc hl ; 5 pos: right of us inc hl ld a,(hl) cp golempty jp z,golnextneigh5 inc b golnextneigh5: ld de,golwidth-2 ; 6 pos: below-left of us add hl,de ld a,(hl) cp golempty jp z,golnextneigh6 inc b golnextneigh6: inc hl ; 7 pos: below us ld a,(hl) cp golempty jp z,golnextneigh7 inc b golnextneigh7: inc hl ; 8 pos: below-right of us ld a,(hl) cp golempty jp z,golneighdone inc b golneighdone: ld d,b pop bc pop hl ld a,(bc) ; d now contains (bc)'s number of neighbours cp golempty jp nz,golfullcell ld a,d ; Cell empty -- only create cell if 3 neighbours cp 3 jp nz,golwbbempty jp golwbbfullnew golfullcell: ld a,d ; Cell full -- cell only survives if 2 or 3 neighbours cp 2 jp z,golwbbfull2 cp 3 jp z,golwbbfull jp golwbbempty golwbbfullnew: ld a,golcellnew call golwritetobb jp golupdated golwbbfull: ld a,golcell call golwritetobb jp golupdated golwbbfull2: ld a,golcell2 call golwritetobb jp golupdated golwbbempty: ld a,golempty call golwritetobb golupdated: ld a,(bc) ; Draw from front buffer call PrintChar inc bc dec l jp nz,golupdiloop call NewLine dec h jp nz,golupdoloop ld hl,golboardaddress+golboardsize ; Blit backbuffer into front ld de,golboardaddress ld bc,golboardsize ldir call ScanChar cp 0 jp z,goldrawloop call ClearScreen ret golwritetobb: push hl ; Expects: bc - equiv frontbuffer address; a - byte to write push de ld h,b ld l,c ld de,golboardsize add hl,de ld (hl),a pop de pop hl ret golmsgintro: defm "Let's rock some cellular automata!" defb 13, 10 defm "(Once started press any key to quit)" defb 13, 10 defm "Hit a key to seed start pattern..." defb 0 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;; API FUNCTIONS ;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; *** API: ClearScreen *** ; Expects: nothing ClearScreen: ld a,12 call PrintChar ret ; *** API: CursorHome *** ; Expects: nothing CursorHome: ld a,$1B ; <esc> call PrintChar ld a,'[' call PrintChar ld a,'H' call PrintChar ret ; *** API: CursorXY *** ; Origin is 1,1 in top-left corner! ; Expects: d = x; e = y ; Trashes: h, l, a CursorXY: ld a,$1B ; <esc> call PrintChar ld a,'[' call PrintChar ld h,0 ; Row (y) ld l,e call PrintUInt16 ld a,';' call PrintChar ld h,0 ld l,d ; Col (x) call PrintUInt16 ld a,'H' call PrintChar ret ; *** API: NewLine *** ; Expects: nothing NewLine: ex af,af' push bc ld bc,ascii_newline call PrintString pop bc ex af,af' ret ascii_newline: defb 10, 13, 0 ; *** API: MemLoad *** ; Expects: de - start address ; Returns: A bunch of populated memory :P MemLoad: ld h,d ld l,e call PrintHex16 ld a,ascii_spc call PrintChar ld a, shellprompt call PrintChar call GetString call NewLine ld a,(string_buffer) cp '.' jp z,MemLoad_end ld hl,string_buffer call AHexToUInt8 ld a,c ld (de),a inc de jp MemLoad MemLoad_end: ret ; *** API: MemDump *** ; Expects: hl - number of bytes; bc - start address MemDump: push bc push hl ld d, 1 ; Trigger newline MemDump_loop: dec d jp z, MemDump_nline MemDump_next: ld a,(bc) call PrintHex8 ld a,ascii_spc call PrintChar inc bc dec hl ld a,1 cp d jp z,MemDump_ascii MemDump_cont: call ScanChar ; Check for keypress cp 0 jp nz,MemDump_quit ld a,h ; Check if HL==0 or l jp nz,MemDump_loop MemDump_quit: pop hl pop bc call NewLine ret MemDump_nline: call NewLine push hl ld h,b ld l,c call PrintHex16 ld a,':' call PrintChar ld a,ascii_spc call PrintChar pop hl ld d,8 jp MemDump_next MemDump_ascii: push hl push de ld de,8 ld h,b ld l,c sbc hl,de ld b,h ld c,l pop de pop hl ld e,8 MemDump_ascii_loop: ld a,(bc) cp 32 jp c,MemDump_skip cp 126 jp nc,MemDump_skip call PrintChar jp MemDump_cdone MemDump_skip: ld a,'.' call PrintChar MemDump_cdone: inc bc dec e jp nz, MemDump_ascii_loop jp MemDump_cont ; *** API: GetString *** ; Expects: Nothing ; Returns: Received string in the string buffer at string_buffer GetString: push bc push hl ld l,255 ld bc, string_buffer GetString_loop: in a,(uart_sr_csr) ; Wait for SR RxRdy bit uart_rxrdybit,a jr z,GetString_loop in a,(uart_data) ; Get char cp 10 ; Check for 10 (maybe a serial client sent 13,10 as a newline) jp z,GetString_loop ; Meh, we ignore them cp 13 ; Check for Enter pressed? jp z,GetString_done ; Done if so cp 127 ; Check for Backspace/Delete pressed... jp z,GetString_backspace ld (bc),a ; Otherwise, store char call PrintChar ; Echo it too inc bc ; Inc address dec l ; Check buffer space left jp z,GetString_done ; Buffer out? Accept jp GetString_loop GetString_done: ld a,0 ld (bc),a pop hl pop bc ret GetString_backspace: ld h,a ld a,l cp 255 jp z,GetString_loop ; Don't let them back up past 0! ld a,h call PrintChar ; Still print the backspace so display steps back dec bc ; But decrement the buffer address... inc l ; ...and inc avail buffer space jp GetString_loop ; Go about your business.. ; *** API: StrLen *** ; Expects: bc - base address of zero-terminated string ; Returns: a - length of the string StrLen: push bc push hl ld l,0 StrLen_lp: ld a,(bc) cp 0 jp z,StrLen_end inc l inc bc jp StrLen_lp StrLen_end: ld a,l pop hl pop bc ret ; *** API: StrCmp *** ; Expects: hl and de to point to the strings to compare ; Returns: carry set if they're the same, unset otherwise StrCmp: push hl push de StrCmp_lp: ld a,(de) ; fetch *s1 cp (hl) jp nz,StrCmp_diff ; quit if *s1 != *s2 or a ; check *s1 for zero inc de inc hl jp nz,StrCmp_lp ; loop if *s1 != 0 pop de pop hl scf ; we ran out of string and they ain't been different yet! set carry flag ret StrCmp_diff: pop de pop hl and a ; reset carry flag ret ; *** API: StrCmp *** ; Expects: hl and de to point to the strings to compare ; Returns: carry set if hl starts with de StrStarts: push hl push de StrStarts_lp: ld a,(de) ; fetch *s1 cp 0 ; if *s1 is 0 we got to end of s1 without a difference! jp z,StrStarts_same cp (hl) jp nz,StrStarts_diff ; quit if *s1 != *s2 or a ; check *s1 for zero inc de inc hl jp nz,StrStarts_lp ; loop if *s1 != 0 StrStarts_same: pop de pop hl scf ; we ran out of string and they ain't been different yet! set carry flag ret StrStarts_diff: pop de pop hl and a ; reset carry flag ret ; *** API: ScanChar *** ; Expects: Nothing ; Returns: Received character in a, or 0 if none waiting ScanChar: in a,(uart_sr_csr) bit uart_rxrdybit,a jr z,ScanChar_none in a,(uart_data) ret ScanChar_none: ld a,0 ret ; *** API: GetChar *** ; Expects: Nothing ; Returns: Received character in a GetChar: in a,(uart_sr_csr) ; Wait for SR RxRdy bit uart_rxrdybit,a jr z,GetChar in a,(uart_data) cp 10 ; Check for 10 (maybe a serial client sent 13,10 as a newline) jp z,GetChar ; Meh, we ignore them call PrintChar ret ; *** API: GetCharSilent *** ; (This variant doesn't echo the character) ; Expects: Nothing ; Returns: Received character in a GetCharSilent: in a,(uart_sr_csr) ; Wait for SR RxRdy bit uart_rxrdybit,a jr z,GetCharSilent in a,(uart_data) cp 10 ; Check for 10 (maybe a serial client sent 13,10 as a newline) jp z,GetCharSilent ; Meh, we ignore them ret ; *** API: PrintChar *** ; Expects: a - ASCII char to print PrintChar: ex af,af' ; Save a PrintChar_wait_txempty: in a,(uart_sr_csr) ; Wait for SR TxEmpty bit bit uart_txemptybit,a jr z,PrintChar_wait_txempty ex af,af' ; Load a out (uart_data),a ; Send it ret ; *** API: PrintLine *** ; Expects: bc - base address of zero-terminated string PrintLine: call PrintString call NewLine ret ; *** API: PrintString *** ; Expects: bc - base address of zero-terminated string PrintString: push bc PrintString_wait_txrdy: in a,(uart_sr_csr) ; Wait for SR TxEmpty bit bit uart_txemptybit,a jp z,PrintString_wait_txrdy ld a,(bc) ; Get current byte cp 0 ; Check for 0 jp z,PrintString_end out (uart_data),a ; Send it inc bc jp PrintString_wait_txrdy PrintString_end: pop bc ret ; *** API: PrintHex8 and PrintHex16 *** ; Expects: a - Number to print (1 byte) ; Expects: hl - Number to print (2 byte) PrintHex8: push bc push de ld b,a ; Back up a call PrintHex_Num21 ld a,b ; Restore a jp PrintHex_Num24 PrintHex16: push bc push de ld a,h call PrintHex_Num21 ld a,h call PrintHex_Num22 ld a,l call PrintHex_Num21 ld a,l jp PrintHex_Num24 PrintHex_Num21: rra rra rra rra PrintHex_Num22: or $F0 daa add a,$A0 adc a,$40 call PrintChar inc de ret PrintHex_Num24: or $F0 daa add a,$A0 adc a,$40 call PrintChar pop de pop bc ret ; *** API: PrintBinary8 *** ; Expects: a - Number to print PrintBinary8: push bc ld b,8 PrintBinary8_loop: rlca ld c,a and $1 add a,$30 call PrintChar ld a,c djnz PrintBinary8_loop pop bc ret ; *** API: SandRand8 *** ; Seeds the PRNG ; Expects: hl - seed SeedRand16: ld (rand16_seed),hl ret ; *** API: Rand16 *** ; Expects: Nothing ; Returns: Pseudorandom num in HL, period 65536 Rand16: push de ld de,(rand16_seed) ld a,d ld h,e ld l,253 or a sbc hl,de sbc a,0 sbc hl,de ld d,0 sbc a,d ld e,a sbc hl,de jr nc,Rand16_done inc hl Rand16_done ld (rand16_seed),hl pop de ret ; *** API: SandRand8 *** ; Seeds the PRNG ; Expects: a - seed SeedRand8: ld (rand8_seed),a ret ; *** API: Rand8 *** ; Expects: Nothing ; Returns: Pseudorandom num in a, period 256 ; Algo: x[i + 1] = (5 * x[i] + 1) mod 256 Rand8: ld a,(rand8_seed) push bc ld b,a add a,a add a,a add a,b inc a ; another possibility is ADD A,7 ld (rand8_seed),a pop bc ret ; *** API: PrintUInt16 *** ; Input: HL = number to print PrintUInt16: push bc push de push hl ld de,int_buffer call Num2Dec16 ld a,0 ; Add zero terminator ld (de),a ld bc,int_buffer PrintUInt16Step: ld a,(bc) cp '0' jp nz,PrintUInt16Done inc bc jp PrintUInt16Step PrintUInt16Done: call PrintString pop hl pop de pop bc ret Num2Dec16: ld bc,-10000 call Num2Dec16_Num1 ld bc,-1000 call Num2Dec16_Num1 ld bc,-100 call Num2Dec16_Num1 ld c,-10 call Num2Dec16_Num1 ld c,-1 Num2Dec16_Num1: ld a,'0'-1 Num2Dec16_Num2: inc a add hl,bc jr c,Num2Dec16_Num2 sbc hl,bc ld (de),a inc de ret ; *** API: AToUInt16 *** ; Expects: de - pointer to a zero-terminated string ; Returns: hl - UInt16 AToUInt16: ld hl,0 ; Clear hl AToUInt16_loop: ld a,(de) ; Get current char cp 48 ; Check for non-ASCII jr c,AToUInt16_end ; 48 is bigger than A cp 58 jr nc,AToUInt16_end ; 58 is bigger than A (legit chars are 48-57!) sub 48 ; Sub 48 to make ASCII char a decimal digit ld b,0 ld c,a ; bc = new_digit push de ld de,hl add hl,de add hl,de add hl,de add hl,de add hl,de add hl,de add hl,de add hl,de add hl,de pop de add hl,bc ; hl = 10*old_number+new_digit inc de jr AToUInt16_loop AToUInt16_end: ret ; *** API: AToUInt8 *** ; Expects: hl - pointer to a zero-terminated string ; Returns: 8 bit unsigned integer in a AToUInt8: push bc ld c,0 ; Clear c AToUInt8_loop: ld a,(hl) cp 0 ; End-of-string? jr z,AToUInt8_end cp ' ' ; MARK: Allow a space to terminate also! jr z,AToUInt8_end sub '0' ; (Sub 48) jr c,AToUInt8_end ; Less than 0 cp 10 jr nc,AToUInt8_end ; Greater than 9 ld b,a ; b = new_digit ld a,c ; a = old_number sla a sla a ; a = 4*old_number add a,c ; a = 5*old_number sla a ; a = 10*old_number add a,b ; a = 10*old_number+new_digit ld c,a inc hl jr AToUInt8_loop AToUInt8_end: ld a,c pop bc ret ; *** API: AHexToUInt8 *** ; Expects: hl - pointer to a zero-terminated string. a-f should be LOWERCASE! ; Returns: 8 bit unsigned integer in c; error code or 0 on success in b AHexToUInt8: push af ld c,0 ld b,2 ; counter for 2 nibbles AHexToUInt8_nextc: ld a,(hl) inc hl cp 0 jr z,AHexToUInt8_end ; End-of-string found cp ' ' ; Skip space jr z,AHexToUInt8_nextc cp 9 ; Skip tabs jr z,AHexToUInt8_nextc cp 'a' jr c,AHexToUInt8_test_hex_uc sub 'a'-10 cp 16 jr nc,AHexToUInt8_end ; Not in a-f, skip conversion jp AHexToUInt8_svr AHexToUInt8_test_hex_uc: cp 'a' jr c,AHexToUInt8_test_dec sub 'a'-10 cp 16 jr nc,AHexToUInt8_end ; Not in a-f, skip conversion jp AHexToUInt8_svr AHexToUInt8_test_dec: sub '0' cp 10 jr nc,AHexToUInt8_end ; Not in 0-9, skip conversion AHexToUInt8_svr: or c ld c,a dec b jr z,AHexToUInt8_end sla c sla c sla c sla c jp AHexToUInt8_nextc ; Next char AHexToUInt8_end: pop af ret ; *** API: Div8 *** ; Expects: h = dividend, l = divisor ; Returns: h = quotient, a = remainder Div8: ld a,0 sla h ; unroll 8 times: 1 rla ; ... cp l ; ... jr c,div8lu1 ; ... sub l ; ... inc h ; ... div8lu1: sla h ; unroll 8 times: 2 rla ; ... cp l ; ... jr c,div8lu2 ; ... sub l ; ... inc h ; ... div8lu2: sla h ; unroll 8 times: 3 rla ; ... cp l ; ... jr c,div8lu3 ; ... sub l ; ... inc h ; ... div8lu3: sla h ; unroll 8 times: 4 rla ; ... cp l ; ... jr c,div8lu4 ; ... sub l ; ... inc h ; ... div8lu4: sla h ; unroll 8 times: 5 rla ; ... cp l ; ... jr c,div8lu5 ; ... sub l ; ... inc h ; ... div8lu5: sla h ; unroll 8 times: 6 rla ; ... cp l ; ... jr c,div8lu6 ; ... sub l ; ... inc h ; ... div8lu6: sla h ; unroll 8 times: 7 rla ; ... cp l ; ... jr c,div8lu7 ; ... sub l ; ... inc h ; ... div8lu7: sla h ; unroll 8 times: 8 rla ; ... cp l ; ... jr c,div8lu8 ; ... sub l ; ... inc h ; ... div8lu8: ret ; *** API: Add32 *** ; Performs H'L'HL = H'L'HL + D'E'DE ; Expects: H, H', L, L', D, D', E, E' as above ; Returns: H, H', L, L' as above ; Changes: Flags Add32: add hl,de ; 16-bit add of hl and de exx adc hl,de ; 16-bit add of hl and de with carry exx ret ; result is in h'l'hl ; *** API: Mul32 *** ; Performs H'L'HL = B'C'BC * D'E'DE (32 bit result) ; Expects: B, B', C, C', D, D', E, E' as above ; Returns: H, H', L, L' as above ; Changes: A, Flags Mul32: and a ; reset carry flag sbc hl,hl ; lower result = 0 exx sbc hl,hl ; higher result = 0 ld a,b ; mpr is ac'bc ld b,32 ; initialize loop counter Mul32loop: sra a ; right shift mpr rr c exx rr b rr c ; lowest bit into carry jr nc,Mul32noadd add hl,de ; result += mpd exx adc hl,de exx Mul32noadd: sla e ; left shift mpd rl d exx rl e rl d djnz Mul32loop exx ret ; result in h'l'hl ; *** API: Mul16 *** ; Performs HL = BC * DE ; Expects: BC, DE ; Returns: HL Mul16: ld a,b ld b,16 Mul16_lp: add hl,hl sla c rla jr nc,Mul16_noadd add hl,de Mul16_noadd: djnz Mul16_lp ret ; *** API: Div16 *** ; Performs BC = BC / DE ; Expects: BC, DE ; Returns: BC = result, HL = remainder Div16: ld hl,0 ld a,b ld b,8 Div16_Loop1: rla adc hl,hl sbc hl,de jr nc,Div16_NoAdd1 add hl,de Div16_NoAdd1: djnz Div16_Loop1 ld b,a ld a,c ld c,b ld b,8 Div16_Loop2: rla adc hl,hl sbc hl,de jr nc,Div16_NoAdd2 add hl,de Div16_NoAdd2: djnz Div16_Loop2 rla cpl ld b,a ld a,c ld c,b rla cpl ld b,a ret ; *** API: RFSRename *** ; Interactive file rename ; Expects: Nothing ; Returns: Nothing RFSRename: call RFSCheckFSMounted ret nc ld bc,msgrnsource call PrintLine ld a,shellprompt call PrintChar call GetString call NewLine ld de,scratch_base ; de<--target address ldir ld hl,string_buffer ld bc,15 ; bc<--bytecount ldir ldir ld a,0 ld (de),a ; Ensure a terminated string ld bc,msgrnsourcetag call PrintLine ld a,shellprompt call PrintChar call GetString call NewLine ld de,scratch_base+16 ; de<--target address ldir ld hl,string_buffer ld bc,15 ; bc<--bytecount ldir ldir ld a,0 ld (de),a ; Ensure a terminated string ld a,(fileindex_size) ld b,a ; b <-- num blocks of fileindex left to traverse ld a,(freemap_size) ld h,0 ld l,a inc hl ; hl <-- current fileindex block num rnnextfiblock: push bc ; Backup num blocks of fileindex left push hl ; Backup current fileindex block ld a,0 ld (ide_lba2),a ; Grab the current fileindex block ld a,h ld (ide_lba1),a ld a,l ld (ide_lba0),a call RFSReadBlock ld hl,block_buffer ; hl <-- current address in block buffer ld b,64 ; b <-- 64 file records per block rnfiinnerblocklp: push bc ; backup records left this block push hl ; backup start of current record into block_buffer ld de,string_buffer call StrCmp ; compare filename jp nc,rntrynext ld de,16 add hl,de ld de,string_buffer+16 call StrCmp ; compare tag jp nc,rntrynext ld de,16 ; Sub 16 from hl to step back to filename, store it in de sbc hl,de ld d,h ld e,l jp rnfoundit rntrynext: pop hl ; pop curr rec addr ld de,64 add hl,de ; hl <-- start of next file record pop bc ; pop records left this block djnz rnfiinnerblocklp ; Keep going till block finished pop hl ; Restore current fileindex block pop bc ; Restore num blocks of fileindex left inc hl ; Inc fileindex block djnz rnnextfiblock ; Loop if more blocks to go through ld bc,msgrnnotok call PrintLine ret rnfoundit: pop hl pop bc pop hl pop bc push de ld bc,msgrndest call PrintLine ld a,shellprompt call PrintChar call GetString call NewLine pop de ; de<--target address ldir push de ld hl,string_buffer ld bc,15 ; bc<--bytecount ldir ldir ld a,0 ld (de),a ; Ensure a terminated string ld bc,msgrndest call PrintLine ld a,shellprompt call PrintChar call GetString call NewLine pop de ; de<--target address ldir ld h,d ld l,e ld de,16 add hl,de ld d,h ld e,l ld hl,string_buffer ld bc,15 ; bc<--bytecount ldir ldir ld a,0 ld (de),a ; Ensure a terminated string ; TODO: Check rename looks OK in block buffer (debug) ; TODO: rewrite the block and show success message ld bc,msgrnok call PrintLine ret msgrnsource defm "Enter source filename" defb 0 msgrnsourcetag defm "Enter source tag" defb 0 msgrndest defm "Enter destination filename" defb 0 msgrndesttag defm "Enter destination tag" defb 0 msgrnok defm "The shizzle is renamed!" defb 0 msgrnnotok defm "I am sorry ese, cause I no find file" defb 0 ; *** API: RFSFileExists *** ; Does a file exist? ; Expects: bc = filename/tag combo to check (32 bytes) ; Returns: carry set if exists, not set if doesn't ; Trashes: STRING BUFFER RFSFileExists: call RFSCheckFSMounted ret nc push bc ; backup filename ld de,string_buffer ; de<--target address ldir ld h,b ; hl<--source address ldir ld l,c ld bc,32 ; bc<--bytecount ldir ldir ld a,(fileindex_size) ld b,a ; b <-- num blocks of fileindex left to traverse ld a,(freemap_size) ld h,0 ld l,a inc hl ; hl <-- current fileindex block num fenextfiblock: push bc ; Backup num blocks of fileindex left push hl ; Backup current fileindex block ld a,0 ld (ide_lba2),a ; Grab the current fileindex block ld a,h ld (ide_lba1),a ld a,l ld (ide_lba0),a call RFSReadBlock ld hl,block_buffer ; hl <-- current address in block buffer ld b,64 ; b <-- 64 file records per block fefiinnerblocklp: push bc ; backup records left this block push hl ; backup start of current record into block_buffer ld de,string_buffer call StrCmp jp nc,fetrynext ld de,16 add hl,de ld de,string_buffer+16 call StrCmp jp nc,fetrynext jp fefoundit fetrynext: pop hl ; pop curr rec addr ld de,64 add hl,de ; hl <-- start of next file record pop bc ; pop records left this block djnz fefiinnerblocklp ; Keep going till block finished pop hl ; Restore current fileindex block pop bc ; Restore num blocks of fileindex left inc hl ; Inc fileindex block djnz fenextfiblock ; Loop if more blocks to go through pop bc ; Restore filename and a ; Clear carry flag to indicate it doesn't exist! ret fefoundit: pop hl pop bc pop hl pop bc pop bc ; Restore filename scf ret ; *** API: RFSListTagged *** ; List all files with given tag (it asks) ; Expects: Nothing ; Returns: Nothing RFSListTagged: call RFSCheckFSMounted ret nc ld a,0 ld (ide_lba2),a ; Grab the superblock ld (ide_lba1),a ld (ide_lba0),a call RFSReadBlock ld bc,msglistall ; Print current name call PrintString ld bc,block_buffer+10 call PrintLine ld bc,msgwithtag call PrintLine ld a,shellprompt call PrintChar call GetString call NewLine ld bc,msglistall2 call PrintLine ld a,(fileindex_size) ld b,a ; b <-- num blocks of fileindex left to traverse ld a,(freemap_size) ld h,0 ld l,a inc hl ; hl <-- current fileindex block num ltnextfiblock: push bc ; Backup num blocks of fileindex left push hl ; Backup current fileindex block ld a,0 ld (ide_lba2),a ; Grab the current fileindex block ld a,h ld (ide_lba1),a ld a,l ld (ide_lba0),a call RFSReadBlock ld hl,block_buffer ; hl <-- current address in block buffer ld b,64 ; b <-- 64 file records per block ltfiinnerblocklp: push bc ; backup records left this block push hl ; backup start of current record into block_buffer push hl ; backup start of current record into block_buffer ld de,16 add hl,de ; hl <-- current record tag ld d,h ; de <-- current tag ld e,l ld hl,string_buffer ; hl <-- string buffer call StrCmp pop hl ; restore start of current record in b_buff jp nc,ltskipit ; tag didn't match? skip it ld b,h ; Matched, print the record son!! ld c,l call PrintString ld bc,msgFileColSep1 call PrintString ld de,16 add hl,de ld b,h ; Print the tag! ld c,l call PrintString ld bc,msgFileColSep2 call PrintString ld de,19 add hl,de ld a,(hl) ; Grab num blocks ld b,a ld de,4 ld hl,0 ltsizedisplp: add hl,de ; Calc filesize from that djnz ltsizedisplp call PrintUInt16 ; Print that shizzle! ld bc,msgkb call PrintLine ltskipit: pop hl ld de,64 ; Step to next record add hl,de pop bc djnz ltfiinnerblocklp pop hl ; Restore current fileindex block pop bc ; Restore num blocks of fileindex left inc hl ; Inc fileindex block djnz ltnextfiblock ; Loop if more blocks to go through ret msgwithtag: defm "with tag?" defb 0 ; *** API: RFSListAll *** ; List all files ; Expects: Nothing ; Returns: Nothing RFSListAll: call RFSCheckFSMounted ret nc ld a,0 ld (ide_lba2),a ; Grab the superblock ld (ide_lba1),a ld (ide_lba0),a call RFSReadBlock ld bc,msglistall ; Print current name call PrintString ld bc,block_buffer+10 call PrintLine ld bc,msglistall2 call PrintLine ld a,(fileindex_size) ld b,a ; b <-- num blocks of fileindex left to traverse ld a,(freemap_size) ld h,0 ld l,a inc hl ; hl <-- current fileindex block num lanextfiblock: push bc ; Backup num blocks of fileindex left push hl ; Backup current fileindex block ld a,0 ld (ide_lba2),a ; Grab the current fileindex block ld a,h ld (ide_lba1),a ld a,l ld (ide_lba0),a call RFSReadBlock ld hl,block_buffer ; hl <-- current address in block buffer ld b,64 ; 64 file records per block lafiinnerblocklp: push bc push hl ld a,(hl) ; Grab this byte cp 0 ; Is it a 0? jp z,laskipit ; Yeah, skip it ld b,h ; No, print it son!! ld c,l call PrintString ld bc,msgFileColSep1 call PrintString ld de,16 add hl,de ld b,h ; Print the tag! ld c,l call PrintString ld bc,msgFileColSep2 call PrintString ld de,19 add hl,de ld a,(hl) ; Grab num blocks ld b,a ld de,4 ld hl,0 lasizedisplp: add hl,de ; Calc filesize from that djnz lasizedisplp call PrintUInt16 ; Print that shizzle! ld bc,msgkb call PrintLine laskipit: pop hl ld de,64 ; Step to next record add hl,de pop bc djnz lafiinnerblocklp pop hl ; Restore current fileindex block pop bc ; Restore num blocks of fileindex left inc hl ; Inc fileindex block djnz lanextfiblock ; Loop if more blocks to go through ret msglistall: defm "Listing all files on " defb 0 msglistall2: defm "Filename (Tag) Size" defb 0 msgFileColSep1: defm " (" defb 0 msgFileColSep2: defm ") " defb 0 msgkb: defm "KB" defb 0 ; *** API: RFSWriteFile *** ; Write a goddam file ; Expects: bc=filename, hl=start address, de=bytecount ; Returns: Nothing RFSWriteFile: call RFSCheckFSMounted ret nc call RFSFileExists jp c,RFSBailFileExistsAndReturn ; 1. Check bytecount and calculate how many blocks needed push hl push bc ld h,d ld l,e ld de,4093 ld b,0 blksneededlp: inc b jp z,filetoobig sbc hl,de jp nc,blksneededlp ld a,b ld (scratch_base),a ; Store num blocks needed pop bc pop hl ; 2. Loop through freemap blocks checking each byte until enough free blocks found; for every free one found, stick its block number in a FIFO, mark it as used. Re-write all touched freemap blocks. push hl ; Backup arguments - start address push bc ; Backup arguments - filename ld a,0 ; scratch_base 3-5 will keep track of found block number ld (scratch_base+3),a ld (scratch_base+4),a ld (scratch_base+5),a ld hl,scratch_base+10 ; scratch_base 6 and 7 will keep track of next FIFO address ld a,l ld (scratch_base+6),a ld a,h ld (scratch_base+7),a ld a,(freemap_size) ld b,a ; b <-- num blocks of freemap left ld a,(scratch_base) ld (scratch_base+1),a ; Backup num required blocks left to find ld hl,1 ; hl <-- current freemap block num nextfmblock: push bc ; Backup num blocks of freemap left push hl ; Backup current freemap block ld a,0 ld (ide_lba2),a ; Grab the current freemap block ld a,h ld (ide_lba1),a ld a,l ld (ide_lba0),a call RFSReadBlock ld a,0 ld (scratch_base+2),a ; Indicate that no block re-write needed ld hl,block_buffer ; hl <-- current address in block buffer ld bc,4096 ; Loop entire block innerblocklp: ld a,(hl) ; Grab this byte cp 0 ; Is it a 0? jp nz,skipthisone ; No -- block occupied ld a,1 ; Yes!! Mark the block as occupied... ld (hl),a ld (scratch_base+2),a ; Indicate that block re-write IS needed ; Found one! Store the block number in the FIFO :P push hl ld a,(scratch_base+6) ; Grab current FIFO address ld l,a ld a,(scratch_base+7) ld h,a ld a,(scratch_base+3) ; Write block num low byte... ld (hl),a inc hl ld a,(scratch_base+4) ; Write block num mid byte... ld (hl),a inc hl ld a,(scratch_base+5) ; Write block num high byte... ld (hl),a inc hl ld a,l ld (scratch_base+6),a ; Store current FIFO address ld a,h ld (scratch_base+7),a pop hl ld a,(scratch_base+1) ; Grab number of remaining needed blocks, decrement it, rewrite dec a ld (scratch_base+1),a cp 0 ; Is it zero now? jp z,writethisblockandcont ; Yes!! Bail out -- write the current freemap block cos it just changed, but don't check any more skipthisone: inc hl ; Increment address into block buffer push hl ; Now inc main 3-byte block num..... ld a,(scratch_base+3) ld l,a ld a,(scratch_base+4) ld h,a ld de,1 exx ld a,(scratch_base+5) ld l,a ld a,0 ld h,a ld de,0 exx call Add32 ; does H'L'HL = H'L'HL + D'E'DE exx ld a,l ld (scratch_base+5),a exx ld a,h ld (scratch_base+4),a ld a,l ld (scratch_base+3),a pop hl ; Block num inc'd! dec bc ; See if more bytes remaining this block ld a,b ; check if BC==0 or c jp nz,innerblocklp ld a,(scratch_base+2) ; No more bytes this block; rewrite the block if needed cp 0 ; Is it then? jp z,rewritedone ; not needed? skip it pop hl ; rewrite needed! restore the block num... push hl ; ...re-push block num ld a,0 ld (ide_lba2),a ; Re-write the current freemap block ld a,h ld (ide_lba1),a ld a,l ld (ide_lba0),a call RFSWriteBlock rewritedone: pop hl ; Restore current freemap block pop bc ; Restore num blocks of freemap left inc hl ; Inc freemap block ;djnz nextblock ; Loop if more blocks to go through dec b ; LOL -- too far away for djnz... jp nz,nextfmblock ; ...needs a long jump! pop bc ; Oh no! Ran out of freemap blocks without finding space -- save failed :( pop hl ; Restore arguments... ld bc,msgDiskFull call PrintLine and a ; Set carry to false... ret ; And ret :( writethisblockandcont: ; OK, all needed blocks found; re-write the current block and we're on our way. pop hl ; rewrite needed! restore the block num... push hl ; ...re-push block num ld a,0 ld (ide_lba2),a ; Re-write the current freemap block ld a,h ld (ide_lba1),a ld a,l ld (ide_lba0),a call RFSWriteBlock pop hl ; Restore current freemap block pop bc ; Restore num blocks of freemap left pop bc ; Restore arguments: Filename pop hl ; Restore arguments: Start address push hl ld a,(scratch_base+6) ; Grab current FIFO address ld l,a ld a,(scratch_base+7) ld h,a ld a,0 ; Write block num 0 (these will be picked up and used as continuation records by step 3) ld (hl),a inc hl ld (hl),a inc hl ld (hl),a pop hl ; 3. Dump the data ; ALRIGHT! (scratch_base) contains number of blocks to write, and block numbers to use are in memory at scratch_base+10 onwards (stride=3). ; They've already been marked as used in the freemap. ; hl = start address in RAM of data to dump ; de = bytecount to dump ; set fifo pointer in scratch_base6 and 7 back to scratch_base+10 ; for (num blocks to write) { ; - copy next 4093 bytes into block buffer ; - retrieve current block number and increment the pointer ; - peek at next block number and tack it into last 3 bytes of block buffer ; - write the block ; } push hl ld hl,scratch_base+10 ; scratch_base 6 and 7 will keep track of next FIFO address ld a,l ld (scratch_base+6),a ld a,h ld (scratch_base+7),a pop hl push bc ; Backup arguments: Filename ld a,(scratch_base) ld b,a ; b <-- num blocks to write dumpnextblock: push bc ; Backup block write counter ld de,block_buffer ; Target address ldir ld bc,4093 ; Bytecount for ldir ldir ; Copy next 4093 bytes into block buffer (source address for ldir is hl) push hl ; retrieve current block number from the FIFO and increment the pointer ld a,(scratch_base+6) ; Grab current FIFO address... ld l,a ld a,(scratch_base+7) ld h,a ld a,(hl) ; Grab destination block number: Low byte ld (ide_lba0),a inc hl ld a,(hl) ; Mid byte ld (ide_lba1),a inc hl ld a,(hl) ; High byte ld (ide_lba2),a inc hl ld a,l ld (scratch_base+6),a ; Store current FIFO address ld a,h ld (scratch_base+7),a ld a,(hl) ; Grab next destination block number: Low byte ld (block_buffer+4093),a ; Stick it at the tail end of block buffer (it's the block continuation record) inc hl ld a,(hl) ; Mid byte ld (block_buffer+4094),a inc hl ld a,(hl) ; High byte ld (block_buffer+4095),a call RFSWriteBlock ; write the block!! pop hl pop bc ; Restore block write counter djnz dumpnextblock pop bc ; Restore arguments: Filename ; 4. Create the file record ; foreach (file index block) { ; - read current block ; - search current block for a blank entry ; if (blank entry found) { ; - Create record ; - Break out of for loop ; } ; } ; scratch_base+10 contains start block (3 bytes), and ; bc is the filename. Go! push bc ; Backup arguments - filename ld a,(fileindex_size) ld b,a ; b <-- num blocks of fileindex left ld a,(freemap_size) ld h,0 ld l,a inc hl ; hl <-- current fileindex block num nextfiblock: push bc ; Backup num blocks of fileindex left push hl ; Backup current fileindex block ld a,0 ld (ide_lba2),a ; Grab the current fileindex block ld a,h ld (ide_lba1),a ld a,l ld (ide_lba0),a call RFSReadBlock ld hl,block_buffer ; hl <-- current address in block buffer ld b,64 ; 64 file records per block fiinnerblocklp: ld a,(hl) ; Grab this byte cp 0 ; Is it a 0? jp z,writefiblock ; Found a blank! ld de,64 ; File record stride add hl,de ; Increment address into block buffer djnz fiinnerblocklp pop hl ; Restore current freemap block pop bc ; Restore num blocks of freemap left inc hl ; Inc freemap block djnz nextfiblock ; Loop if more blocks to go through pop bc ; Oh no! Ran out of FI blocks without finding file record space -- save failed :( Restore args -- filename ld bc,msgFileIndexFull call PrintLine and a ; Set carry to false... ret ; And ret :( writefiblock: ld d,h ; Backup filerecord address in de ld e,l pop hl ; Restore the fileindex block num pop bc ; Restore num blocks of freemap left pop bc ; Restore arguments: Filename ; bc = filename address; de = filerecord address; hl = block number push hl ; Backup block number ld h,b ld l,c ld bc,31 ldir ld a,0 ld (de),a ; Ensure a terminated string pop hl ; Restore block number inc de ld a,(scratch_base+10) ; Grab first block in file (low byte) ld (de),a ; Dump it into file record inc de ld a,(scratch_base+11) ; Grab first block in file (mid byte) ld (de),a ; Dump it into file record inc de ld a,(scratch_base+12) ; Grab first block in file (high byte) ld (de),a ; Dump it into file record inc de ld a,(scratch_base) ; Grab number of blocks ld (de),a ; Dump that into file too ld a,0 ld (ide_lba2),a ; Re-write the current fileindex block ld a,h ld (ide_lba1),a ld a,l ld (ide_lba0),a call RFSWriteBlock scf ; Saved OK! \o/ Set carry flag ret filetoobig: pop bc ; File is too big to save!! pop hl ; Restore arguments... ld bc,msgFileTooBig call PrintLine and a ; Set carry to false... ret ; And ret :( msgDiskFull: defm "Eek; disk full! (No free blocks)" defb 0 msgFileIndexFull: defm "Eek; disk full! (Out of file records)" defb 0 msgFileTooBig: defm "A file that big?" defb 13,10 defm "It might be very useful." defb 13,10 defm "But now it is gone." defb 13,10 defb 13,10 defm "Only supporting up to 1Mb per file" defb 13,10 defm "for now (but not due to any RFS" defb 13,10 defm "limitation). You must have upped" defb 13,10 defm "your RAM in a BIG way!!" defb 0 ; *** API: RFSRenameLib *** ; Interactive library rename ; Expects: Nothing ; Returns: Nothing RFSRenameLib: call RFSCheckFSMounted ret nc ld a,0 ld (ide_lba2),a ; Grab the superblock ld (ide_lba1),a ld (ide_lba0),a call RFSReadBlock ld bc,msgrenamelibcn ; Print current name call PrintString ld bc,block_buffer+10 call PrintLine ld bc,msgrenamelibnn ; Prompt for new name call PrintLine ld a,shellprompt call PrintChar call GetString call NewLine ld hl,string_buffer ; Copy lib name into WIP superblock ld de,block_buffer+10 ld bc,16 ldir ld a,0 ld (block_buffer+25),a ; Ensure a terminated string ld a,0 ; Write the superblock! No turning back now... ld (ide_lba2),a ld (ide_lba1),a ld (ide_lba0),a call RFSWriteBlock ld bc,msgrenamelibok call PrintLine ret msgrenamelibcn: defm "Current library name: " defb 0 msgrenamelibnn: defm "Enter new name (15 chars max)..." defb 0 msgrenamelibok: defm "Renamed OK, dog!" defb 0 ; *** API: RFSFormat *** ; Interactive format routine ; Expects: Nothing ; Returns: Nothing RFSFormat: ld bc,msgformatwelcome ; Continue confirmation call PrintLine call GetChar cp 'y' call NewLine ret nz call RFSBlankBlockBuffer ; Blank to generate the superblock ld a,$42 ; Store RFS magic number in right place of WIP superblock ld (block_buffer+8),a ld bc,msgformatfmsize ; Prompt for freemap size call PrintLine ld a,shellprompt call PrintChar call GetString call NewLine ld hl,string_buffer call AToUInt8 ld (block_buffer+26),a ; Store size in WIP superblock ld (freemap_size),a ; Store size in sys constant ld bc,msgformatfisize ; Prompt for fileindex size call PrintLine ld a,shellprompt call PrintChar call GetString call NewLine ld hl,string_buffer call AToUInt8 ld (block_buffer+27),a ; Store size in WIP superblock ld (fileindex_size),a ; Store size in sys constant ld bc,msgformatlibnm call PrintLine ld a,shellprompt call PrintChar call GetString call NewLine ld hl,string_buffer ; Copy lib name into WIP superblock ld de,block_buffer+10 ld bc,16 ldir ld a,0 ld (block_buffer+25),a ; Ensure a terminated string ld bc,msgformatgo call PrintLine ld a,0 ; Write the superblock! No turning back now... ld (ide_lba2),a ld (ide_lba1),a ld (ide_lba0),a call RFSWriteBlock call RFSBlankBlockBuffer ; Blank to generate the first freemap block ld a,(fileindex_size) inc a ld d,a ld a,(freemap_size) add a,d ld b,a ; b <-- 1+freemapsize+fileindexsize push af ; backup 1+freemapsize+fileindexsize ld hl,block_buffer freemapcrtlp: ld (hl),1 ; Now set first hl bytes in freemap to 1! inc hl djnz freemapcrtlp ld a,0 ; Write the first freemap block ld (ide_lba2),a ld (ide_lba1),a ld a,1 ld (ide_lba0),a call RFSWriteBlock call RFSBlankBlockBuffer ; Blank to generate other freemap blocks + fileindex blocks pop af ; Restore 1+freemapsize+fileindexsize sub 2 ; We've done the superblock + first freemap block... ld b,a ; b <-- the number of blank blocks to now write! ld hl,2 ; First block num to write bnkblklp: push bc push hl ld a,0 ld (ide_lba2),a ld a,h ld (ide_lba1),a ld a,l ld (ide_lba0),a call RFSWriteBlock pop hl pop bc inc hl djnz bnkblklp ld bc,msgformatok call PrintLine ret msgformatwelcome: defm "RiFT-FS 1.0 HD format" defb 13,10,13,10 defm "WARNING: This will completely destroy" defb 13,10 defm "the disk contents! Press y to go on," defb 13,10 defm "or any other key to exit." defb 0 msgformatfmsize: defm "How many blocks for freemap? (RFS can" defb 13,10 defm "address 16Mb per freemap block)" defb 0 msgformatfisize: defm "How many blocks for file index? (RFS" defb 13,10 defm "can store 64 files per freemap block)" defb 0 msgformatlibnm: defm "Enter library name (up to 15 chars)" defb 0 msgformatgo: defm "Formatting... " defb 0 msgformatok: defm "Formatted OK!" defb 0 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;; RFS Internal routines ;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; *** RFS Support Routine: RFSBailFileExistsAndReturn *** ; ****** Note this gets JUMPED TO: it's just supposed to show message and return ****** RFSBailFileExistsAndReturn: ld bc,msgFileExists call PrintLine ret msgFileExists: defm "File already exists!" defb 0 ; *** RFS Support Routine: RFSCheckFSMounted *** ; Checks a drive exists and is mounted ; Expects: Nothing ; Returns: carry set if exists, unset if not ; Trashes: a RFSCheckFSMounted: ld a,(freemap_size) cp 0 jp z,rfscdenodrv scf ret rfscdenodrv: ld bc,msgNoDriveMounted call PrintLine and a ret msgNoDriveMounted: defm "No drive mounted!" defb 0 ; *** RFS Support Routine: RFSBlankBlockBuffer *** ; Fills the block buffer with zeroes ; Expects: Nothing ; Returns: Nothing RFSBlankBlockBuffer: ld hl,block_buffer ld a,0 ld c,16 ; 16 sectors rfsfsetolp: ld b,0 ; * 256 bytes per sector rfsfsetlp: ld (hl),a inc hl djnz rfsfsetlp dec c jp nz,rfsfsetolp ret ; *** RFS Support Routine: RFSReadBlock *** ; Expects: ide_lba0 - ide_lba2: block number; ide_status bit 0 set for master (0) or slave (1) ; Returns: The block, in the block buffer. Carry set if successful, not set if failed. RFSReadBlock: call RFSBlockToLBA ld hl,block_buffer ld b,16 readblklp: push bc call ide_read_sector ; NB: This self-advances hl, so we DON'T NEED TO ADD 256 HERE... pop bc jp nc,diskreaderror push hl ; Now inc sector num..... ld a,(ide_lba0) ld l,a ld a,(ide_lba1) ld h,a ld de,1 exx ld a,(ide_lba2) ld l,a ld a,(ide_lba3) ld h,a ld de,0 exx call Add32 ; does H'L'HL = H'L'HL + D'E'DE exx ; load H'L' into top 2 bytes of lba num ld a,h ld (ide_lba3),a ld a,l ld (ide_lba2),a exx ; load HL into bottom 2 bytes of lba num ld a,h ld (ide_lba1),a ld a,l ld (ide_lba0),a pop hl ; Sector num inc'd! djnz readblklp scf ret diskreaderror: push af ld a,(freemap_size) cp 0 jp z,disknotfound ld bc,msghaltingdisk call PrintLine ld bc,msgdiskrerror call PrintString pop af call PrintHex8 call NewLine halt disknotfound: pop af and a ; Clear carry flag to indicate failure ret msgdiskrerror: defm "Disk Read: " defb 0 ; *** RFS Support Routine: RFSWriteBlock *** ; Expects: ide_lba0 - ide_lba2: block number; ide_status bit 0 set for master (0) or slave (1) ; Returns: Nowt. RFSWriteBlock: call RFSBlockToLBA ld hl,block_buffer ld b,16 writeblklp: push bc call ide_write_sector pop bc jp nc,diskwriteerror push hl ; Now inc sector num..... ld a,(ide_lba0) ld l,a ld a,(ide_lba1) ld h,a ld de,1 exx ld a,(ide_lba2) ld l,a ld a,(ide_lba3) ld h,a ld de,0 exx call Add32 ; does H'L'HL = H'L'HL + D'E'DE exx ; load H'L' into top 2 bytes of lba num ld a,h ld (ide_lba3),a ld a,l ld (ide_lba2),a exx ; load HL into bottom 2 bytes of lba num ld a,h ld (ide_lba1),a ld a,l ld (ide_lba0),a pop hl ; Sector num inc'd! djnz writeblklp ret diskwriteerror: push af ld bc,msghaltingdisk call PrintLine ld bc,msgdiskwerror call PrintString pop af call PrintHex8 call NewLine halt msgdiskwerror: defm "Disk write: " defb 0 ; *** RFS Support Routine: RFSBlockToLBA *** ; Expects: ide_lba0 - ide_lba2 filled with block num ; Returns: ide_lba0 - ide_lba3 filled with lba num RFSBlockToLBA: ld a,(ide_lba1) ; d <- 2nd byte of block num ld d,a ld a,(ide_lba0) ; e <- Low byte of block num ld e,a ld bc,16 exx ld d,0 ld a,(ide_lba2) ; e' <- Top byte of block num ld e,a ld bc,0 exx call Mul32 ; does H'L'HL = B'C'BC * D'E'DE exx ld a,h ld (ide_lba3),a ; (ide_lba3) <- 4th (top) byte of lba num ld a,l ld (ide_lba2),a ; (ide_lba2) <- 3rd byte of lba num exx ld a,h ld (ide_lba1),a ; (ide_lba1) <- 2nd byte of lba num ld a,l ld (ide_lba0),a ; (ide_lba0) <- 1st (bottom) byte of lba num ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;; IDE INTERNAL ROUTINES ;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; *** IDE Routine: ide_read_sector *** ; Read an LBA-addressed 256 byte sector (I ignore the high databyte!!) into address in hl ; Expects: ide_lba0 - ide_lba3 set to desired LBA address, ide_status bit 0 set for master (0) or slave (1); hl=target address ; Returns: carry flag = 1 if operation sucessful else A = IDE error flags (or if $00, operation timed out) ide_read_sector: push hl call ide_setup_lba ;tell ide what drive/sector is required pop hl call ide_wait_busy_ready ;make sure drive is ready to proceed ret nc ld a,$20 out (ide_register7),a ;write $20 "read sector" command to reg 7 ide_srex: call ide_wait_busy_ready ;make sure drive is ready to proceed ret nc call ide_test_error ;ensure no error was reported ret nc call ide_wait_buffer ;wait for full buffer signal from drive ret nc ld b,0 ;read 256 words (512 bytes per sector) idebufrd: in a,(ide_register0) ;get low byte of ide data word first ld (hl),a inc hl djnz idebufrd scf ;carry set on return = operation ok ret ; *** IDE Routine: ide_write_sector *** ; Write from hl into an LBA-addressed 256 byte sector ; Expects: ide_lba0 - ide_lba3 set to desired LBA address, ide_status bit 0 set for master (0) or slave (1); hl=source address ; Returns: carry flag = 1 if operation sucessful else A = IDE error flags (or if $00, operation timed out) ide_write_sector: push hl call ide_setup_lba ;tell ide what drive/sector is required pop hl call ide_wait_busy_ready ;make sure drive is ready to proceed after lba req ret nc ld a,$30 out (ide_register7),a ;write $30 "write sector" command to reg 7 call ide_wait_busy_ready ret nc call ide_test_error ;ensure no error was reported ret nc call ide_wait_buffer ;wait for buffer ready signal from drive ret nc ld b,0 ;write 256 words (512 bytes per sector) idebufwt: ld a,(hl) out (ide_register0),a ;send low byte to output entire word inc hl djnz idebufwt call ide_wait_busy_ready ;make sure drive is ready to proceed ret nc call ide_test_error ;ensure no error was reported ret ;carry set on return = operation ok ; *** IDE Routine: Wait for drive to be ready *** ide_wait_busy_ready: ld a,(ide_status) ;choose bit 1 or bit 2 to test for previous and 1 ;access depending on master or slave drive inc a ;selection sla a ld c,a ld de,0 ide_wbsy: ld b,250 ;ide times out after ~10 seconds if disk(s) not ld a,(ide_status) ;spun up (first time access). ~1 second otherwise and c jr z,ide_dlp ld b,50 ;(~1 second) ide_dlp: djnz ide_dlp inc de ld a,d or e jr z,ide_timeout ; If de got to 0, we timed out :/ in a,(ide_register7) ; get status reg in A ; MARK/DBUG: SOMETIMES IT'S NOT ON THE GODDAM BUS AT THIS POINT; this is what causes the hard fail :/ and 11000000b ;mask off busy and rdy bits xor 01000000b ;we want busy(7) to be 0 and rdy(6) to be 1 jr nz,ide_wbsy ld a,(ide_status) ;from first time a disk is ready, timeout is reduced or c ;as spin-up is main reason for 10 second allowance ld (ide_status),a scf ;carry 1 = ok ret ide_timeout: xor a ;carry 0 = timed out ret ; *** IDE Routine: Wait for buffer *** ide_wait_buffer: ld de,0 ide_wdrq: ld b,250 ;wait 10 seconds approx ide_blp: djnz ide_blp inc de ld a,d or e jr z,ide_timeout2 in a,(ide_register7) bit 3,a ;to fill (or ready to fill) jr z,ide_wdrq scf ;carry 1 = ok ret ide_timeout2: xor a ;carry 0 = timed out ret ; *** IDE Routine: Test for error *** ide_test_error: scf ;carry set = all OK in a,(ide_register7) ;get status in A bit 0,a ;test error bit ret z bit 5,a jr nz,ide_err ;test write error bit in a,(ide_register1) ;read error report register ide_err: or a ;make carry flag zero = error! ret ;if a = 0, ide busy timed out ; *** IDE Routine: Setup for a 1-sector LBA transfer from the LBA address vars *** ide_setup_lba: ld a,1 out (ide_register2),a ;set sector count to 1 ld hl,ide_lba0 ld a,(hl) out (ide_register3),a ;set lba 0:7 inc hl ld a,(hl) out (ide_register4),a ;set lba 8:15 inc hl ld a,(hl) out (ide_register5),a ;set lba 16:23 inc hl ld a,(hl) and 00001111b ;lowest 4 bits used only or 11100000b ;to enable lba mode push hl ;set bit 4 for master or slave ld hl,(ide_status) bit 0,(hl) jr z,ide_mast or 16 ide_mast: pop hl out (ide_register6),a ;set lba 24:27 + bits 5:7=111 ret defm "Here lie the ROMTOP mountains ;)" defb 0
#ifndef FSLGRAPHICS_RENDER_TEXTURE2DFILTERHINT_HPP #define FSLGRAPHICS_RENDER_TEXTURE2DFILTERHINT_HPP /**************************************************************************************************************************************************** * Copyright (c) 2014 Freescale Semiconductor, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * * Neither the name of the Freescale Semiconductor, Inc. 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. * ****************************************************************************************************************************************************/ #include <FslBase/BasicTypes.hpp> namespace Fsl { enum class Texture2DFilterHint { Nearest = 0, Smooth = 1, }; } #endif
/******************************************************** Copyright (c) <2016> <Bloodknight Studios> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *********************************************************/ #include <iostream> #include <fstream> #include <string> #include <sstream> #include <stdlib.h> using namespace std; string setCase(const std::string & s, int Case){ string ret(s.size(), char()); for(unsigned int i = 0; i < s.size(); ++i){ if (Case == 0) ret[i] = (s[i] <= 'z' && s[i] >= 'a') ? s[i]-32 : s[i]; if (Case == 1) ret[i] = (s[i] <= 'Z' && s[i] >= 'A') ? s[i]+32 : s[i]; } return ret; } int main () { // Input file has 3 enries, name hex and vec3 rgb string colname, colhex, colrgb; string scolr, scolg, scolb; double colr, colg, colb; ifstream infile ("namedcolours.txt"); ofstream outfile ("colours.h"); outfile << "#ifndef COLOURS_H_INCLUDED\n"; outfile << "#define COLOURS_H_INCLUDED\n\n"; outfile << "\/\/ Named colours for use with opengl r, g, b system\n\n"; if (infile.is_open()) { while ( !infile.eof() ) { // read each line getline (infile, colname, '\t'); getline (infile, colhex, '\t'); getline (infile, scolr, ','); getline (infile, scolg, ','); getline (infile, scolb, '\n'); // convert string data to integer colr = atof(scolr.c_str()); colg = atof(scolg.c_str()); colb = atof(scolb.c_str()); string colnameupper, colnamelower; colnameupper = setCase(colname, 0); colnamelower = setCase(colname, 1); outfile.precision(2); outfile <<fixed << "GLfloat " << colnameupper<<"[] = {" << colr/256 << "f, " << colg/256 << "f, " << colb/256 <<"f };"<<endl; //printf("#define %s %f.2, %f.2, %f.2", toupper(), float() ) } infile.close(); outfile << "\n\n#endif // COLOURS_H_INCLUDED/n"; } else cout << "Unable to open file"; return 0; }
SECTION .text GLOBAL test test: movd xmm0, eax movd xmm0, ecx movd xmm0, edx movd xmm0, ebx movd xmm0, esp movd xmm0, ebp movd xmm0, esi movd xmm0, edi movd xmm0, r8d movd xmm0, r9d movd xmm0, r10d movd xmm0, r11d movd xmm0, r12d movd xmm0, r13d movd xmm0, r14d movd xmm0, r15d movd ebx, xmm0 movd r14d, xmm0 movd xmm1, eax movd xmm1, ecx movd xmm1, edx movd xmm1, ebx movd xmm1, esp movd xmm1, ebp movd xmm1, esi movd xmm1, edi movd xmm1, r8d movd xmm1, r9d movd xmm1, r10d movd xmm1, r11d movd xmm1, r12d movd xmm1, r13d movd xmm1, r14d movd xmm1, r15d movd ebx, xmm1 movd r14d, xmm1 movd xmm2, eax movd xmm2, ecx movd xmm2, edx movd xmm2, ebx movd xmm2, esp movd xmm2, ebp movd xmm2, esi movd xmm2, edi movd xmm2, r8d movd xmm2, r9d movd xmm2, r10d movd xmm2, r11d movd xmm2, r12d movd xmm2, r13d movd xmm2, r14d movd xmm2, r15d movd ebx, xmm2 movd r14d, xmm2 movd xmm3, eax movd xmm3, ecx movd xmm3, edx movd xmm3, ebx movd xmm3, esp movd xmm3, ebp movd xmm3, esi movd xmm3, edi movd xmm3, r8d movd xmm3, r9d movd xmm3, r10d movd xmm3, r11d movd xmm3, r12d movd xmm3, r13d movd xmm3, r14d movd xmm3, r15d movd ebx, xmm3 movd r14d, xmm3 movd xmm4, eax movd xmm4, ecx movd xmm4, edx movd xmm4, ebx movd xmm4, esp movd xmm4, ebp movd xmm4, esi movd xmm4, edi movd xmm4, r8d movd xmm4, r9d movd xmm4, r10d movd xmm4, r11d movd xmm4, r12d movd xmm4, r13d movd xmm4, r14d movd xmm4, r15d movd ebx, xmm4 movd r14d, xmm4 movd xmm5, eax movd xmm5, ecx movd xmm5, edx movd xmm5, ebx movd xmm5, esp movd xmm5, ebp movd xmm5, esi movd xmm5, edi movd xmm5, r8d movd xmm5, r9d movd xmm5, r10d movd xmm5, r11d movd xmm5, r12d movd xmm5, r13d movd xmm5, r14d movd xmm5, r15d movd ebx, xmm5 movd r14d, xmm5 movd xmm5, [rax] movd xmm5, [rcx] movd xmm5, [rdx] movd xmm5, [rbx] movd xmm5, [rsp] movd xmm5, [rbp] movd xmm5, [rsi] movd xmm5, [rdi] movd xmm5, [r8d] movd xmm5, [r9d] movd xmm5, [r10] movd xmm5, [r11] movd xmm5, [r12] movd xmm5, [r13] movd xmm5, [r14] movd xmm5, [r15] movd xmm5, [eax+0xee] movd xmm5, [ecx+0xdd] movd xmm5, [edx+0x8efde] movd xmm5, [ebx+0x4cd] movd xmm5, [esp+0xaa] movd xmm5, [ebp+0xff] movd xmm5, [esi+0xfddd] movd xmm5, [edi+0xabcd] movd xmm5, [r8d+0x9a9a9] movd xmm5, [r9d+0x456] movd xmm5, [r10d+0x123] movd xmm5, [r11d+0x89dd] movd xmm5, [r12d+0x9a34] movd xmm5, [r13d+0xffff] movd xmm5, [r14d+0x4edf] movd xmm5, [r15d+0xfe] movd ebx, xmm5 movd r14d, xmm5 movd xmm6, eax movd xmm6, ecx movd xmm6, edx movd xmm6, ebx movd xmm6, esp movd xmm6, ebp movd xmm6, esi movd xmm6, edi movd xmm6, r8d movd xmm6, r9d movd xmm6, r10d movd xmm6, r11d movd xmm6, r12d movd xmm6, r13d movd xmm6, r14d movd xmm6, r15d movd ebx, xmm6 movd r14d, xmm6 movd xmm7, eax movd xmm7, ecx movd xmm7, edx movd xmm7, ebx movd xmm7, esp movd xmm7, ebp movd xmm7, esi movd xmm7, edi movd xmm7, r8d movd xmm7, r9d movd xmm7, r10d movd xmm7, r11d movd xmm7, r12d movd xmm7, r13d movd xmm7, r14d movd xmm7, r15d movd ebx, xmm7 movd r14d, xmm7 movd xmm8, eax movd xmm8, ecx movd xmm8, edx movd xmm8, ebx movd xmm8, esp movd xmm8, ebp movd xmm8, esi movd xmm8, edi movd xmm8, r8d movd xmm8, r9d movd xmm8, r10d movd xmm8, r11d movd xmm8, r12d movd xmm8, r13d movd xmm8, r14d movd xmm8, r15d movd ebx, xmm8 movd r14d, xmm8 movd xmm9, eax movd xmm9, ecx movd xmm9, edx movd xmm9, ebx movd xmm9, esp movd xmm9, ebp movd xmm9, esi movd xmm9, edi movd xmm9, r8d movd xmm9, r9d movd xmm9, r10d movd xmm9, r11d movd xmm9, r12d movd xmm9, r13d movd xmm9, r14d movd xmm9, r15d movd ebx, xmm9 movd r14d, xmm9 movd xmm10, eax movd xmm10, ecx movd xmm10, edx movd xmm10, ebx movd xmm10, esp movd xmm10, ebp movd xmm10, esi movd xmm10, edi movd xmm10, r8d movd xmm10, r9d movd xmm10, r10d movd xmm10, r11d movd xmm10, r12d movd xmm10, r13d movd xmm10, r14d movd xmm10, r15d movd ebx, xmm10 movd r14d, xmm10 movd xmm11, eax movd xmm11, ecx movd xmm11, edx movd xmm11, ebx movd xmm11, esp movd xmm11, ebp movd xmm11, esi movd xmm11, edi movd xmm11, r8d movd xmm11, r9d movd xmm11, r10d movd xmm11, r11d movd xmm11, r12d movd xmm11, r13d movd xmm11, r14d movd xmm11, r15d movd ebx, xmm11 movd r14d, xmm11 movd xmm11, [eax] movd xmm11, [ecx] movd xmm11, [edx] movd xmm11, [ebx] movd xmm11, [esp] movd xmm11, [ebp] movd xmm11, [esi] movd xmm11, [edi] movd xmm11, [r8d] movd xmm11, [r9d] movd xmm11, [r10d] movd xmm11, [r11d] movd xmm11, [r12d] movd xmm11, [r13d] movd xmm11, [r14d] movd xmm11, [r15d] movd xmm11, [eax+0xee] movd xmm11, [ecx+0xdd] movd xmm11, [edx+0x8efde] movd xmm11, [ebx+0x4cd] movd xmm11, [esp+0xaa] movd xmm11, [ebp+0xff] movd xmm11, [esi+0xfddd] movd xmm11, [edi+0xabcd] movd xmm11, [r8d+0x9a9a9] movd xmm11, [r9d+0x456] movd xmm11, [r10d+0x123] movd xmm11, [r11d+0x89dd] movd xmm11, [r12d+0x9a34] movd xmm11, [r13d+0xffff] movd xmm11, [r14d+0x4edf] movd xmm11, [r15d+0xfe] movd [ebx+0x4cd], xmm11 movd [r14d+0x4edf], xmm11 movd xmm12, eax movd xmm12, ecx movd xmm12, edx movd xmm12, ebx movd xmm12, esp movd xmm12, ebp movd xmm12, esi movd xmm12, edi movd xmm12, r8d movd xmm12, r9d movd xmm12, r10d movd xmm12, r11d movd xmm12, r12d movd xmm12, r13d movd xmm12, r14d movd xmm12, r15d movd ebx, xmm12 movd r14d, xmm12 movd xmm13, eax movd xmm13, ecx movd xmm13, edx movd xmm13, ebx movd xmm13, esp movd xmm13, ebp movd xmm13, esi movd xmm13, edi movd xmm13, r8d movd xmm13, r9d movd xmm13, r10d movd xmm13, r11d movd xmm13, r12d movd xmm13, r13d movd xmm13, r14d movd xmm13, r15d movd ebx, xmm13 movd r14d, xmm13 movd xmm14, eax movd xmm14, ecx movd xmm14, edx movd xmm14, ebx movd xmm14, esp movd xmm14, ebp movd xmm14, esi movd xmm14, edi movd xmm14, r8d movd xmm14, r9d movd xmm14, r10d movd xmm14, r11d movd xmm14, r12d movd xmm14, r13d movd xmm14, r14d movd xmm14, r15d movd ebx, xmm14 movd r14d, xmm14 movd xmm15, eax movd xmm15, ecx movd xmm15, edx movd xmm15, ebx movd xmm15, esp movd xmm15, ebp movd xmm15, esi movd xmm15, edi movd xmm15, r8d movd xmm15, r9d movd xmm15, r10d movd xmm15, r11d movd xmm15, r12d movd xmm15, r13d movd xmm15, r14d movd xmm15, r15d movd ebx, xmm15 movd r14d, xmm15
// license:BSD-3-Clause // copyright-holders:Miodrag Milanovic /*************************************************************************** Digital Microsystems DMS-5000 2010-01-11 Skeleton driver. ****************************************************************************/ #include "emu.h" #include "cpu/i86/i86.h" #include "machine/74259.h" //#include "machine/z80sio.h" #include "emupal.h" #include "screen.h" class dms5000_state : public driver_device { public: dms5000_state(const machine_config &mconfig, device_type type, const char *tag) : driver_device(mconfig, type, tag) , m_maincpu(*this, "maincpu") , m_screen(*this, "screen") { } void dms5000(machine_config &config); private: uint8_t status_r(offs_t offset); void brightness_w(uint8_t data); uint32_t screen_update_dms5000(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); void io_map(address_map &map); void mem_map(address_map &map); required_device<cpu_device> m_maincpu; required_device<screen_device> m_screen; }; uint8_t dms5000_state::status_r(offs_t offset) { switch (offset) { case 0: return m_screen->vblank(); case 2: return m_screen->frame_number() & 1; default: return 0; } } void dms5000_state::brightness_w(uint8_t data) { } void dms5000_state::mem_map(address_map &map) { map.unmap_value_high(); map(0x00000, 0x1ffff).ram(); map(0x40000, 0x4ffff).ram(); map(0xfc000, 0xfffff).rom().region("maincpu", 0); } void dms5000_state::io_map(address_map &map) { map.unmap_value_high(); map(0x20, 0x2f).r(FUNC(dms5000_state::status_r)).umask16(0xff00); map(0x40, 0x4f).w("cntlatch", FUNC(ls259_device::write_d0)).umask16(0x00ff); map(0x50, 0x57).w(FUNC(dms5000_state::brightness_w)).umask16(0x00ff); } /* Input ports */ static INPUT_PORTS_START( dms5000 ) INPUT_PORTS_END uint32_t dms5000_state::screen_update_dms5000(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) { return 0; } void dms5000_state::dms5000(machine_config &config) { /* basic machine hardware */ I8086(config, m_maincpu, XTAL(9'830'400)); m_maincpu->set_addrmap(AS_PROGRAM, &dms5000_state::mem_map); m_maincpu->set_addrmap(AS_IO, &dms5000_state::io_map); LS259(config, "cntlatch", 0); // V34 /* video hardware */ SCREEN(config, m_screen, SCREEN_TYPE_RASTER); m_screen->set_refresh_hz(50); m_screen->set_vblank_time(ATTOSECONDS_IN_USEC(2500)); /* not accurate */ m_screen->set_size(640, 480); m_screen->set_visarea_full(); m_screen->set_screen_update(FUNC(dms5000_state::screen_update_dms5000)); m_screen->set_palette("palette"); PALETTE(config, "palette", palette_device::MONOCHROME); } /* ROM definition */ ROM_START( dms5000 ) ROM_REGION16_LE( 0x4000, "maincpu", 0 ) ROM_LOAD16_BYTE( "dms-5000_54-8673o.bin", 0x0001, 0x2000, CRC(dce9823e) SHA1(d36ab87d2e6f5e9f02d59a6a7724ad3ce2428a2f)) ROM_LOAD16_BYTE( "dms-5000_54-8672e.bin", 0x0000, 0x2000, CRC(94d64c06) SHA1(be5a53da7bb29a5fa9ac31efe550d5d6ff8b77cd)) ROM_END /* Driver */ /* YEAR NAME PARENT COMPAT MACHINE INPUT CLASS INIT COMPANY FULLNAME FLAGS */ COMP( 1982, dms5000, 0, 0, dms5000, dms5000, dms5000_state, empty_init, "Digital Microsystems", "DMS-5000", MACHINE_NOT_WORKING | MACHINE_NO_SOUND | MACHINE_SUPPORTS_SAVE )
;******************************************************************************* ;* ;* ASM_006: Control basico del ADC ;* ;******************************************************************************* ;* FileName: main.asm ;* Processor: PIC16F887 ;* Complier: MPASM v5.77 ;* Author: Pedro Sánchez (MrChunckuee) ;* Blog: http://mrchunckuee.blogspot.com/ ;* Email: mrchunckuee.psr@gmail.com ;* Description: Controlar los 8 LEDs en el puerto D, dependiendo del nivel ;* de voltaje en RA0. ;******************************************************************************* ;* Rev. Date Comment ;* v1.00 15/06/2015 Creación del firmware ;* v1.01 11/10/2019 Pruebas y revision del codigo, ademas se agrego ;* los comentario en las lineas. ;******************************************************************************* ;********** C A B E C E R A **************************************************** list p=16f887 ;Identifica el PIC a usar #include <P16F887.INC> ;Cabecera que define los registros del MCU ;********** F U S E S ********************************************************** ; Bits de configuración del MCU ; CONFIG1 __CONFIG _CONFIG1, _FOSC_INTRC_NOCLKOUT & _WDTE_OFF & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_ON & _IESO_ON & _FCMEN_ON & _LVP_OFF ; CONFIG2 __CONFIG _CONFIG2, _BOR4V_BOR40V & _WRT_OFF ;********** V A R I A B L E S ************************************************** ;Declaracion de constantes RContadorA EQU 0x0D ; Registro utilizado para el retardo RContadorB EQU 0x0E ; Registro utilizado para el retardo ;Declaracion de datos en memoria MisVariables UDATA Valor_ADC RES 1 ; Guarda el resultado de la conversion ;********** I N I C I O * D E * P R O G R A M A ******************************** ORG 0x00 ; Aqui comienza el micro despues del reset GOTO MCU_Init ; Configuramos el ADC ORG 0x04 ; Origen del codigo de programa RETURN ;********** C O N F I G U R A * M C U ****************************************** MCU_Init BANKSEL ANSEL MOVLW 0x01 MOVWF ANSEL ; use AN0 BANKSEL OSCCON movlw 0x71 ;Cargo valor a w movwf OSCCON ;Oscilador interno 8MHz --> IRCF<2:0> = 1, CCS = 1 BANKSEL TRISD MOVLW 0x00 MOVWF TRISD ;all PORTD outputs BANKSEL PORTD CLRF PORTD ;Clear PORTD ;********** C O N F I G U R A * A D C ****************************************** ADC_Init ;Se inicializa el registro ADCON1 del ADC BANKSEL ADCON1 movlw 0x0E ;Configura los canales para usar solo RA0/AN0 y movwf ADCON1 ;selecciona la justificacion a la izquierda BANKSEL TRISA movlw 0x01 movwf TRISA ;Se coloca RA0 como entrada (analoga). BANKSEL PORTA ;Selecciona el banco 0 nuevamente clrf PORTA ;Clear PORTA ;Se inicaliza ahora el registro ADCON0 del ADC. Notese que se usa ;el reloj interno del ADC debido a que la velocidad no es critica y ;la aplicacion no requiere exactitud en la velocidad de conversion. BANKSEL ADCON0 movlw 0xC1 ; Selecciona el reloj interno, selecciona tambien el movwf ADCON0 ; Canal cero del ADC (AN0) y activa el ADC. ;Nota: en caso de usar varios canales, puede modificarse este registro ;para intercambiarlos. clrf Valor_ADC ;Limpia la variable ;********** L E C T U R A * A D C ******************************************** ADC_Read bsf ADCON0, GO_DONE ; Inicia la conversion del ADC movlw d'1' ; Espera durante 1ms call Retardo_ms btfsc ADCON0, GO_DONE ; Espera a que la conversion termine por goto $-1 ; medio de verificar el mismo bit movf ADRESH, W ; Toma el resultado del ADC y lo guarda movwf Valor_ADC ;Nota: Dado que se utilizo la justificacion a la izquierda, se pueden ;tomar solo los 8 bits mas significativos y usarlos como resultado. ;Esto puede realizarse si solo se necesitan 8 bits de resolucion y no ;los 10 que provee el ADC. ;********** R U T I N A * L E D s ******************************************** ; Cargamos un valor a W. ; Le restamos al ADC el valor de W. ; Comparamos si es <= ejecutamos siguiente linea, si > saltamos una linea. ; Actualizamos PORTD. ; REalizamos nuevamente una lectura. Update_LED0 movlw d'28' SUBWF Valor_ADC,W BTFSC STATUS,C GOTO Update_LED1 MOVLW b'00000000' MOVWF PORTD GOTO ADC_Read ; Volvemos a leer RA0 Update_LED1 movlw d'56' SUBWF Valor_ADC,W BTFSC STATUS,C GOTO Update_LED2 MOVLW b'00000001' MOVWF PORTD GOTO ADC_Read ; Volvemos a leer RA0 Update_LED2 movlw d'84' SUBWF Valor_ADC,W BTFSC STATUS,C GOTO Update_LED3 MOVLW b'00000011' MOVWF PORTD GOTO ADC_Read ; Volvemos a leer RA0 Update_LED3 movlw d'112' SUBWF Valor_ADC,W BTFSC STATUS,C GOTO Update_LED4 MOVLW b'00000111' MOVWF PORTD GOTO ADC_Read ; Volvemos a leer RA0 Update_LED4 movlw d'140' SUBWF Valor_ADC,W BTFSC STATUS,C GOTO Update_LED5 MOVLW b'00001111' MOVWF PORTD GOTO ADC_Read ; Volvemos a leer RA0 Update_LED5 movlw d'168' SUBWF Valor_ADC,W BTFSC STATUS,C GOTO Update_LED6 MOVLW b'00011111' MOVWF PORTD GOTO ADC_Read ; Volvemos a leer RA0 Update_LED6 movlw d'196' SUBWF Valor_ADC,W BTFSC STATUS,C GOTO Update_LED7 MOVLW b'00111111' MOVWF PORTD GOTO ADC_Read ; Volvemos a leer RA0 Update_LED7 movlw d'224' SUBWF Valor_ADC,W BTFSC STATUS,C GOTO Update_LED8 MOVLW b'01111111' MOVWF PORTD GOTO ADC_Read ; Volvemos a leer RA0 Update_LED8 movlw d'250' SUBWF Valor_ADC,W BTFSC STATUS,C GOTO ADC_Read ; Volvemos a leer RA0 MOVLW b'11111111' MOVWF PORTD GOTO ADC_Read ; Volvemos a leer RA0 ;********** C O D I G O * R E T A R D O S ************************************** ; Las siguientes lineas duran ; Retardo = 1 + M + M + KM + (K-1)M + 2M + (K-1)2M + (M-1) + 2 + 2(M-1) + 2 ; Retardo = 2 + 4M + 4KM para K=249 y suponiendo M=1 tenemos ; Retardo = 1002 us = 1 ms Retardo_ms movwf RContadorB ; 1 ciclos máquina. Retardo_BucleExterno movlw d'249' ; Mx1 ciclos máquina. Este es el valor de "K". movwf RContadorA ; Mx1 ciclos máquina. Retardo_BucleInterno nop ; KxMx1 ciclos máquina. decfsz RContadorA,F ; (K-1)xMx1 cm (si no salta) + Mx2 cm (al saltar). goto Retardo_BucleInterno ; (K-1)xMx2 ciclos máquina. decfsz RContadorB,F ; (M-1)x1 cm (si no salta) + 2 cm (al saltar). goto Retardo_BucleExterno ; (M-1)x2 ciclos máquina. return ; 2 ciclos máquina. end ;Fin del programa
; A164392: Number of binary strings of length n with no substrings equal to 0001 or 0010. ; 1,2,4,8,14,25,44,78,137,241,423,743,1304,2289,4017,7050,12372,21712,38102,66865,117340,205918,361361,634145,1112847,1952911,3427120,6014177,10554145,18521234,32502500,57037912,100094558,175653705,308250764,540942382,949287705,1665883793,2923422263,5130248439,9002958408,15799090641,27725471313,48654810394,85383240116,149837141152,262945852582,461437804129,809766896828,1421041842110,2493754591521,4376234237761,7679755726111,13477031805983,23650542123616,41503808167361,72834106017089 mov $1,1 lpb $0 mov $2,$0 seq $2,259968 ; a(n) = a(n-1) + a(n-2) + a(n-4), with a(1)=1, a(2)=1, a(3)=3, a(4)=6. sub $2,$0 add $1,$2 add $1,$0 sub $0,2 lpe add $1,$0 mov $0,$1
; A266298: Triangle read by rows giving successive states of cellular automaton generated by "Rule 14" initiated with a single ON (black) cell. ; 1,1,1,0,1,1,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 mov $1,2 mov $2,1 lpb $0 add $1,2 sub $0,$1 add $0,3 lpe bin $2,$0 mov $0,$2
#include "te_service_impl.h" #include "info_manager.h" #include "task.h" te_rpc::Task toRpc( const tasks::task_ptr t ) { te_rpc::Task tmp; tmp.set_pid( t->pid() ); tmp.set_name( t->name() ); tmp.set_path_name( t->path_name() ); for( auto arg : t->argv() ) { tmp.add_args( arg ); } auto& envs = *tmp.mutable_envs(); for( auto env : t->envv() ) { envs[env.first] = env.second; } tmp.set_cpu_usage_user( t->cpu_usage_user() ); tmp.set_cpu_usage_kernel( t->cpu_usage_kernel() ); tmp.set_real_mem_size( t->real_mem_size() ); tmp.set_virtual_mem_size( t->virtual_mem_size() ); return tmp; } TEServiceImpl::~TEServiceImpl() { } TEServiceImpl::TEServiceImpl() : m_im( new info_manager() ) { } grpc::Status TEServiceImpl::ActiveTasks( grpc::ServerContext* context, const te_rpc::InfoType* request, grpc::ServerWriter<te_rpc::Task>* writer ) { auto tasks = m_im->active_tasks(); for( auto& tp : *tasks ) { writer->Write( toRpc( tp.second ) ); } return grpc::Status::OK; }
;-------------------------------------------------------- ; File Created by SDCC : free open source ANSI-C Compiler ; Version 4.0.0 #11528 (Linux) ;-------------------------------------------------------- ; Processed by Z88DK ;-------------------------------------------------------- EXTERN __divschar EXTERN __divschar_callee EXTERN __divsint EXTERN __divsint_callee EXTERN __divslong EXTERN __divslong_callee EXTERN __divslonglong EXTERN __divslonglong_callee EXTERN __divsuchar EXTERN __divsuchar_callee EXTERN __divuchar EXTERN __divuchar_callee EXTERN __divuint EXTERN __divuint_callee EXTERN __divulong EXTERN __divulong_callee EXTERN __divulonglong EXTERN __divulonglong_callee EXTERN __divuschar EXTERN __divuschar_callee EXTERN __modschar EXTERN __modschar_callee EXTERN __modsint EXTERN __modsint_callee EXTERN __modslong EXTERN __modslong_callee EXTERN __modslonglong EXTERN __modslonglong_callee EXTERN __modsuchar EXTERN __modsuchar_callee EXTERN __moduchar EXTERN __moduchar_callee EXTERN __moduint EXTERN __moduint_callee EXTERN __modulong EXTERN __modulong_callee EXTERN __modulonglong EXTERN __modulonglong_callee EXTERN __moduschar EXTERN __moduschar_callee EXTERN __mulint EXTERN __mulint_callee EXTERN __mullong EXTERN __mullong_callee EXTERN __mullonglong EXTERN __mullonglong_callee EXTERN __mulschar EXTERN __mulschar_callee EXTERN __mulsuchar EXTERN __mulsuchar_callee EXTERN __muluschar EXTERN __muluschar_callee EXTERN __rlslonglong EXTERN __rlslonglong_callee EXTERN __rlulonglong EXTERN __rlulonglong_callee EXTERN __rrslonglong EXTERN __rrslonglong_callee EXTERN __rrulonglong EXTERN __rrulonglong_callee EXTERN ___sdcc_call_hl EXTERN ___sdcc_call_iy EXTERN ___sdcc_enter_ix EXTERN _banked_call EXTERN _banked_ret EXTERN ___fs2schar EXTERN ___fs2schar_callee EXTERN ___fs2sint EXTERN ___fs2sint_callee EXTERN ___fs2slong EXTERN ___fs2slong_callee EXTERN ___fs2slonglong EXTERN ___fs2slonglong_callee EXTERN ___fs2uchar EXTERN ___fs2uchar_callee EXTERN ___fs2uint EXTERN ___fs2uint_callee EXTERN ___fs2ulong EXTERN ___fs2ulong_callee EXTERN ___fs2ulonglong EXTERN ___fs2ulonglong_callee EXTERN ___fsadd EXTERN ___fsadd_callee EXTERN ___fsdiv EXTERN ___fsdiv_callee EXTERN ___fseq EXTERN ___fseq_callee EXTERN ___fsgt EXTERN ___fsgt_callee EXTERN ___fslt EXTERN ___fslt_callee EXTERN ___fsmul EXTERN ___fsmul_callee EXTERN ___fsneq EXTERN ___fsneq_callee EXTERN ___fssub EXTERN ___fssub_callee EXTERN ___schar2fs EXTERN ___schar2fs_callee EXTERN ___sint2fs EXTERN ___sint2fs_callee EXTERN ___slong2fs EXTERN ___slong2fs_callee EXTERN ___slonglong2fs EXTERN ___slonglong2fs_callee EXTERN ___uchar2fs EXTERN ___uchar2fs_callee EXTERN ___uint2fs EXTERN ___uint2fs_callee EXTERN ___ulong2fs EXTERN ___ulong2fs_callee EXTERN ___ulonglong2fs EXTERN ___ulonglong2fs_callee EXTERN ____sdcc_2_copy_src_mhl_dst_deix EXTERN ____sdcc_2_copy_src_mhl_dst_bcix EXTERN ____sdcc_4_copy_src_mhl_dst_deix EXTERN ____sdcc_4_copy_src_mhl_dst_bcix EXTERN ____sdcc_4_copy_src_mhl_dst_mbc EXTERN ____sdcc_4_ldi_nosave_bc EXTERN ____sdcc_4_ldi_save_bc EXTERN ____sdcc_4_push_hlix EXTERN ____sdcc_4_push_mhl EXTERN ____sdcc_lib_setmem_hl EXTERN ____sdcc_ll_add_de_bc_hl EXTERN ____sdcc_ll_add_de_bc_hlix EXTERN ____sdcc_ll_add_de_hlix_bc EXTERN ____sdcc_ll_add_de_hlix_bcix EXTERN ____sdcc_ll_add_deix_bc_hl EXTERN ____sdcc_ll_add_deix_hlix EXTERN ____sdcc_ll_add_hlix_bc_deix EXTERN ____sdcc_ll_add_hlix_deix_bc EXTERN ____sdcc_ll_add_hlix_deix_bcix EXTERN ____sdcc_ll_asr_hlix_a EXTERN ____sdcc_ll_asr_mbc_a EXTERN ____sdcc_ll_copy_src_de_dst_hlix EXTERN ____sdcc_ll_copy_src_de_dst_hlsp EXTERN ____sdcc_ll_copy_src_deix_dst_hl EXTERN ____sdcc_ll_copy_src_deix_dst_hlix EXTERN ____sdcc_ll_copy_src_deixm_dst_hlsp EXTERN ____sdcc_ll_copy_src_desp_dst_hlsp EXTERN ____sdcc_ll_copy_src_hl_dst_de EXTERN ____sdcc_ll_copy_src_hlsp_dst_de EXTERN ____sdcc_ll_copy_src_hlsp_dst_deixm EXTERN ____sdcc_ll_lsl_hlix_a EXTERN ____sdcc_ll_lsl_mbc_a EXTERN ____sdcc_ll_lsr_hlix_a EXTERN ____sdcc_ll_lsr_mbc_a EXTERN ____sdcc_ll_push_hlix EXTERN ____sdcc_ll_push_mhl EXTERN ____sdcc_ll_sub_de_bc_hl EXTERN ____sdcc_ll_sub_de_bc_hlix EXTERN ____sdcc_ll_sub_de_hlix_bc EXTERN ____sdcc_ll_sub_de_hlix_bcix EXTERN ____sdcc_ll_sub_deix_bc_hl EXTERN ____sdcc_ll_sub_deix_hlix EXTERN ____sdcc_ll_sub_hlix_bc_deix EXTERN ____sdcc_ll_sub_hlix_deix_bc EXTERN ____sdcc_ll_sub_hlix_deix_bcix EXTERN ____sdcc_load_debc_deix EXTERN ____sdcc_load_dehl_deix EXTERN ____sdcc_load_debc_mhl EXTERN ____sdcc_load_hlde_mhl EXTERN ____sdcc_store_dehl_bcix EXTERN ____sdcc_store_debc_hlix EXTERN ____sdcc_store_debc_mhl EXTERN ____sdcc_cpu_pop_ei EXTERN ____sdcc_cpu_pop_ei_jp EXTERN ____sdcc_cpu_push_di EXTERN ____sdcc_outi EXTERN ____sdcc_outi_128 EXTERN ____sdcc_outi_256 EXTERN ____sdcc_ldi EXTERN ____sdcc_ldi_128 EXTERN ____sdcc_ldi_256 EXTERN ____sdcc_4_copy_srcd_hlix_dst_deix EXTERN ____sdcc_4_and_src_mbc_mhl_dst_deix EXTERN ____sdcc_4_or_src_mbc_mhl_dst_deix EXTERN ____sdcc_4_xor_src_mbc_mhl_dst_deix EXTERN ____sdcc_4_or_src_dehl_dst_bcix EXTERN ____sdcc_4_xor_src_dehl_dst_bcix EXTERN ____sdcc_4_and_src_dehl_dst_bcix EXTERN ____sdcc_4_xor_src_mbc_mhl_dst_debc EXTERN ____sdcc_4_or_src_mbc_mhl_dst_debc EXTERN ____sdcc_4_and_src_mbc_mhl_dst_debc EXTERN ____sdcc_4_cpl_src_mhl_dst_debc EXTERN ____sdcc_4_xor_src_debc_mhl_dst_debc EXTERN ____sdcc_4_or_src_debc_mhl_dst_debc EXTERN ____sdcc_4_and_src_debc_mhl_dst_debc EXTERN ____sdcc_4_and_src_debc_hlix_dst_debc EXTERN ____sdcc_4_or_src_debc_hlix_dst_debc EXTERN ____sdcc_4_xor_src_debc_hlix_dst_debc ;-------------------------------------------------------- ; Public variables in this module ;-------------------------------------------------------- GLOBAL _m32_tanf ;-------------------------------------------------------- ; Externals used ;-------------------------------------------------------- GLOBAL _m32_polyf GLOBAL _m32_hypotf GLOBAL _m32_ldexpf GLOBAL _m32_frexpf GLOBAL _m32_invsqrtf GLOBAL _m32_sqrtf GLOBAL _m32_invf GLOBAL _m32_sqrf GLOBAL _m32_div2f GLOBAL _m32_mul2f GLOBAL _m32_modff GLOBAL _m32_fmodf GLOBAL _m32_roundf GLOBAL _m32_floorf GLOBAL _m32_fabsf GLOBAL _m32_ceilf GLOBAL _m32_powf GLOBAL _m32_log10f GLOBAL _m32_log2f GLOBAL _m32_logf GLOBAL _m32_exp10f GLOBAL _m32_exp2f GLOBAL _m32_expf GLOBAL _m32_atanhf GLOBAL _m32_acoshf GLOBAL _m32_asinhf GLOBAL _m32_tanhf GLOBAL _m32_coshf GLOBAL _m32_sinhf GLOBAL _m32_atan2f GLOBAL _m32_atanf GLOBAL _m32_acosf GLOBAL _m32_asinf GLOBAL _m32_cosf GLOBAL _m32_sinf GLOBAL __MAX_OPEN ;-------------------------------------------------------- ; special function registers ;-------------------------------------------------------- ;-------------------------------------------------------- ; ram data ;-------------------------------------------------------- SECTION bss_compiler ;-------------------------------------------------------- ; ram data ;-------------------------------------------------------- IF 0 ; .area _INITIALIZED removed by z88dk ENDIF ;-------------------------------------------------------- ; absolute external ram data ;-------------------------------------------------------- SECTION IGNORE ;-------------------------------------------------------- ; global & static initialisations ;-------------------------------------------------------- SECTION code_crt_init ;-------------------------------------------------------- ; Home ;-------------------------------------------------------- SECTION IGNORE ;-------------------------------------------------------- ; code ;-------------------------------------------------------- SECTION code_compiler ; --------------------------------- ; Function m32_tanf ; --------------------------------- _m32_tanf: push ix ld ix,0 add ix,sp push af push af push hl ld c,l ld b,h push de ld l, c ld h, b call _m32_sinf ld (ix-4),l ld (ix-3),h ld (ix-2),e ld (ix-1),d pop de pop hl call _m32_cosf push de push hl ld l,(ix-2) ld h,(ix-1) push hl ld l,(ix-4) ld h,(ix-3) push hl call ___fsdiv ld sp,ix pop ix ret SECTION IGNORE
; A186294: (A007519(n)+1)/2. ; 9,21,37,45,49,57,69,97,117,121,129,141,157,169,177,201,205,217,225,229,261,285,289,297,301,309,321,337,381,385,405,429,441,465,469,477,489,505,517,525,549,565,577,597,601,609,625,645,649,661,681 seq $0,5123 ; Numbers n such that 8n + 1 is prime. mul $0,4 add $0,1
;-------------------------------------------------------- ; File Created by C51 ; Version 1.0.0 #1069 (Apr 23 2015) (MSVC) ; This file was generated Fri Feb 26 19:06:53 2016 ;-------------------------------------------------------- $name hellolcd $optc51 --model-small R_DSEG segment data R_CSEG segment code R_BSEG segment bit R_XSEG segment xdata R_PSEG segment xdata R_ISEG segment idata R_OSEG segment data overlay BIT_BANK segment data overlay R_HOME segment code R_GSINIT segment code R_IXSEG segment xdata R_CONST segment code R_XINIT segment code R_DINIT segment code ;-------------------------------------------------------- ; Public variables in this module ;-------------------------------------------------------- public _main public _LCDprint public _LCD_4BIT public _WriteCommand public _WriteData public _LCD_byte public _LCD_pulse public _waitms public _Timer3us public __c51_external_startup public _LCDprint_PARM_3 public _LCDprint_PARM_2 ;-------------------------------------------------------- ; Special Function Registers ;-------------------------------------------------------- _P0 DATA 0x80 _SP DATA 0x81 _DPL DATA 0x82 _DPH DATA 0x83 _EMI0TC DATA 0x84 _EMI0CF DATA 0x85 _OSCLCN DATA 0x86 _PCON DATA 0x87 _TCON DATA 0x88 _TMOD DATA 0x89 _TL0 DATA 0x8a _TL1 DATA 0x8b _TH0 DATA 0x8c _TH1 DATA 0x8d _CKCON DATA 0x8e _PSCTL DATA 0x8f _P1 DATA 0x90 _TMR3CN DATA 0x91 _TMR4CN DATA 0x91 _TMR3RLL DATA 0x92 _TMR4RLL DATA 0x92 _TMR3RLH DATA 0x93 _TMR4RLH DATA 0x93 _TMR3L DATA 0x94 _TMR4L DATA 0x94 _TMR3H DATA 0x95 _TMR4H DATA 0x95 _USB0ADR DATA 0x96 _USB0DAT DATA 0x97 _SCON DATA 0x98 _SCON0 DATA 0x98 _SBUF DATA 0x99 _SBUF0 DATA 0x99 _CPT1CN DATA 0x9a _CPT0CN DATA 0x9b _CPT1MD DATA 0x9c _CPT0MD DATA 0x9d _CPT1MX DATA 0x9e _CPT0MX DATA 0x9f _P2 DATA 0xa0 _SPI0CFG DATA 0xa1 _SPI0CKR DATA 0xa2 _SPI0DAT DATA 0xa3 _P0MDOUT DATA 0xa4 _P1MDOUT DATA 0xa5 _P2MDOUT DATA 0xa6 _P3MDOUT DATA 0xa7 _IE DATA 0xa8 _CLKSEL DATA 0xa9 _EMI0CN DATA 0xaa __XPAGE DATA 0xaa _SBCON1 DATA 0xac _P4MDOUT DATA 0xae _PFE0CN DATA 0xaf _P3 DATA 0xb0 _OSCXCN DATA 0xb1 _OSCICN DATA 0xb2 _OSCICL DATA 0xb3 _SBRLL1 DATA 0xb4 _SBRLH1 DATA 0xb5 _FLSCL DATA 0xb6 _FLKEY DATA 0xb7 _IP DATA 0xb8 _CLKMUL DATA 0xb9 _SMBTC DATA 0xb9 _AMX0N DATA 0xba _AMX0P DATA 0xbb _ADC0CF DATA 0xbc _ADC0L DATA 0xbd _ADC0H DATA 0xbe _SFRPAGE DATA 0xbf _SMB0CN DATA 0xc0 _SMB1CN DATA 0xc0 _SMB0CF DATA 0xc1 _SMB1CF DATA 0xc1 _SMB0DAT DATA 0xc2 _SMB1DAT DATA 0xc2 _ADC0GTL DATA 0xc3 _ADC0GTH DATA 0xc4 _ADC0LTL DATA 0xc5 _ADC0LTH DATA 0xc6 _P4 DATA 0xc7 _TMR2CN DATA 0xc8 _TMR5CN DATA 0xc8 _REG01CN DATA 0xc9 _TMR2RLL DATA 0xca _TMR5RLL DATA 0xca _TMR2RLH DATA 0xcb _TMR5RLH DATA 0xcb _TMR2L DATA 0xcc _TMR5L DATA 0xcc _TMR2H DATA 0xcd _TMR5H DATA 0xcd _SMB0ADM DATA 0xce _SMB1ADM DATA 0xce _SMB0ADR DATA 0xcf _SMB1ADR DATA 0xcf _PSW DATA 0xd0 _REF0CN DATA 0xd1 _SCON1 DATA 0xd2 _SBUF1 DATA 0xd3 _P0SKIP DATA 0xd4 _P1SKIP DATA 0xd5 _P2SKIP DATA 0xd6 _USB0XCN DATA 0xd7 _PCA0CN DATA 0xd8 _PCA0MD DATA 0xd9 _PCA0CPM0 DATA 0xda _PCA0CPM1 DATA 0xdb _PCA0CPM2 DATA 0xdc _PCA0CPM3 DATA 0xdd _PCA0CPM4 DATA 0xde _P3SKIP DATA 0xdf _ACC DATA 0xe0 _XBR0 DATA 0xe1 _XBR1 DATA 0xe2 _XBR2 DATA 0xe3 _IT01CF DATA 0xe4 _CKCON1 DATA 0xe4 _SMOD1 DATA 0xe5 _EIE1 DATA 0xe6 _EIE2 DATA 0xe7 _ADC0CN DATA 0xe8 _PCA0CPL1 DATA 0xe9 _PCA0CPH1 DATA 0xea _PCA0CPL2 DATA 0xeb _PCA0CPH2 DATA 0xec _PCA0CPL3 DATA 0xed _PCA0CPH3 DATA 0xee _RSTSRC DATA 0xef _B DATA 0xf0 _P0MDIN DATA 0xf1 _P1MDIN DATA 0xf2 _P2MDIN DATA 0xf3 _P3MDIN DATA 0xf4 _P4MDIN DATA 0xf5 _EIP1 DATA 0xf6 _EIP2 DATA 0xf7 _SPI0CN DATA 0xf8 _PCA0L DATA 0xf9 _PCA0H DATA 0xfa _PCA0CPL0 DATA 0xfb _PCA0CPH0 DATA 0xfc _PCA0CPL4 DATA 0xfd _PCA0CPH4 DATA 0xfe _VDM0CN DATA 0xff _DPTR DATA 0x8382 _TMR2RL DATA 0xcbca _TMR3RL DATA 0x9392 _TMR4RL DATA 0x9392 _TMR5RL DATA 0xcbca _TMR2 DATA 0xcdcc _TMR3 DATA 0x9594 _TMR4 DATA 0x9594 _TMR5 DATA 0xcdcc _SBRL1 DATA 0xb5b4 _ADC0 DATA 0xbebd _ADC0GT DATA 0xc4c3 _ADC0LT DATA 0xc6c5 _PCA0 DATA 0xfaf9 _PCA0CP1 DATA 0xeae9 _PCA0CP2 DATA 0xeceb _PCA0CP3 DATA 0xeeed _PCA0CP0 DATA 0xfcfb _PCA0CP4 DATA 0xfefd ;-------------------------------------------------------- ; special function bits ;-------------------------------------------------------- _P0_0 BIT 0x80 _P0_1 BIT 0x81 _P0_2 BIT 0x82 _P0_3 BIT 0x83 _P0_4 BIT 0x84 _P0_5 BIT 0x85 _P0_6 BIT 0x86 _P0_7 BIT 0x87 _TF1 BIT 0x8f _TR1 BIT 0x8e _TF0 BIT 0x8d _TR0 BIT 0x8c _IE1 BIT 0x8b _IT1 BIT 0x8a _IE0 BIT 0x89 _IT0 BIT 0x88 _P1_0 BIT 0x90 _P1_1 BIT 0x91 _P1_2 BIT 0x92 _P1_3 BIT 0x93 _P1_4 BIT 0x94 _P1_5 BIT 0x95 _P1_6 BIT 0x96 _P1_7 BIT 0x97 _S0MODE BIT 0x9f _SCON0_6 BIT 0x9e _MCE0 BIT 0x9d _REN0 BIT 0x9c _TB80 BIT 0x9b _RB80 BIT 0x9a _TI0 BIT 0x99 _RI0 BIT 0x98 _SCON_6 BIT 0x9e _MCE BIT 0x9d _REN BIT 0x9c _TB8 BIT 0x9b _RB8 BIT 0x9a _TI BIT 0x99 _RI BIT 0x98 _P2_0 BIT 0xa0 _P2_1 BIT 0xa1 _P2_2 BIT 0xa2 _P2_3 BIT 0xa3 _P2_4 BIT 0xa4 _P2_5 BIT 0xa5 _P2_6 BIT 0xa6 _P2_7 BIT 0xa7 _EA BIT 0xaf _ESPI0 BIT 0xae _ET2 BIT 0xad _ES0 BIT 0xac _ET1 BIT 0xab _EX1 BIT 0xaa _ET0 BIT 0xa9 _EX0 BIT 0xa8 _P3_0 BIT 0xb0 _P3_1 BIT 0xb1 _P3_2 BIT 0xb2 _P3_3 BIT 0xb3 _P3_4 BIT 0xb4 _P3_5 BIT 0xb5 _P3_6 BIT 0xb6 _P3_7 BIT 0xb7 _IP_7 BIT 0xbf _PSPI0 BIT 0xbe _PT2 BIT 0xbd _PS0 BIT 0xbc _PT1 BIT 0xbb _PX1 BIT 0xba _PT0 BIT 0xb9 _PX0 BIT 0xb8 _MASTER0 BIT 0xc7 _TXMODE0 BIT 0xc6 _STA0 BIT 0xc5 _STO0 BIT 0xc4 _ACKRQ0 BIT 0xc3 _ARBLOST0 BIT 0xc2 _ACK0 BIT 0xc1 _SI0 BIT 0xc0 _MASTER1 BIT 0xc7 _TXMODE1 BIT 0xc6 _STA1 BIT 0xc5 _STO1 BIT 0xc4 _ACKRQ1 BIT 0xc3 _ARBLOST1 BIT 0xc2 _ACK1 BIT 0xc1 _SI1 BIT 0xc0 _TF2 BIT 0xcf _TF2H BIT 0xcf _TF2L BIT 0xce _TF2LEN BIT 0xcd _TF2CEN BIT 0xcc _T2SPLIT BIT 0xcb _TR2 BIT 0xca _T2CSS BIT 0xc9 _T2XCLK BIT 0xc8 _TF5H BIT 0xcf _TF5L BIT 0xce _TF5LEN BIT 0xcd _TMR5CN_4 BIT 0xcc _T5SPLIT BIT 0xcb _TR5 BIT 0xca _TMR5CN_1 BIT 0xc9 _T5XCLK BIT 0xc8 _CY BIT 0xd7 _AC BIT 0xd6 _F0 BIT 0xd5 _RS1 BIT 0xd4 _RS0 BIT 0xd3 _OV BIT 0xd2 _F1 BIT 0xd1 _PARITY BIT 0xd0 _CF BIT 0xdf _CR BIT 0xde _PCA0CN_5 BIT 0xde _CCF4 BIT 0xdc _CCF3 BIT 0xdb _CCF2 BIT 0xda _CCF1 BIT 0xd9 _CCF0 BIT 0xd8 _ACC_7 BIT 0xe7 _ACC_6 BIT 0xe6 _ACC_5 BIT 0xe5 _ACC_4 BIT 0xe4 _ACC_3 BIT 0xe3 _ACC_2 BIT 0xe2 _ACC_1 BIT 0xe1 _ACC_0 BIT 0xe0 _AD0EN BIT 0xef _AD0TM BIT 0xee _AD0INT BIT 0xed _AD0BUSY BIT 0xec _AD0WINT BIT 0xeb _AD0CM2 BIT 0xea _AD0CM1 BIT 0xe9 _AD0CM0 BIT 0xe8 _B_7 BIT 0xf7 _B_6 BIT 0xf6 _B_5 BIT 0xf5 _B_4 BIT 0xf4 _B_3 BIT 0xf3 _B_2 BIT 0xf2 _B_1 BIT 0xf1 _B_0 BIT 0xf0 _SPIF BIT 0xff _WCOL BIT 0xfe _MODF BIT 0xfd _RXOVRN BIT 0xfc _NSSMD1 BIT 0xfb _NSSMD0 BIT 0xfa _TXBMT BIT 0xf9 _SPIEN BIT 0xf8 ;-------------------------------------------------------- ; overlayable register banks ;-------------------------------------------------------- rbank0 segment data overlay ;-------------------------------------------------------- ; internal ram data ;-------------------------------------------------------- rseg R_DSEG _LCDprint_PARM_2: ds 1 ;-------------------------------------------------------- ; overlayable items in internal ram ;-------------------------------------------------------- rseg R_OSEG ;-------------------------------------------------------- ; indirectly addressable internal ram data ;-------------------------------------------------------- rseg R_ISEG ;-------------------------------------------------------- ; absolute internal ram data ;-------------------------------------------------------- DSEG ;-------------------------------------------------------- ; bit data ;-------------------------------------------------------- rseg R_BSEG _LCDprint_PARM_3: DBIT 1 ;-------------------------------------------------------- ; paged external ram data ;-------------------------------------------------------- rseg R_PSEG ;-------------------------------------------------------- ; external ram data ;-------------------------------------------------------- rseg R_XSEG ;-------------------------------------------------------- ; absolute external ram data ;-------------------------------------------------------- XSEG ;-------------------------------------------------------- ; external initialized ram data ;-------------------------------------------------------- rseg R_IXSEG rseg R_HOME rseg R_GSINIT rseg R_CSEG ;-------------------------------------------------------- ; Reset entry point and interrupt vectors ;-------------------------------------------------------- CSEG at 0x0000 ljmp _crt0 ;-------------------------------------------------------- ; global & static initialisations ;-------------------------------------------------------- rseg R_HOME rseg R_GSINIT rseg R_GSINIT ;-------------------------------------------------------- ; data variables initialization ;-------------------------------------------------------- rseg R_DINIT ; The linker places a 'ret' at the end of segment R_DINIT. ;-------------------------------------------------------- ; code ;-------------------------------------------------------- rseg R_CSEG ;------------------------------------------------------------ ;Allocation info for local variables in function '_c51_external_startup' ;------------------------------------------------------------ ;------------------------------------------------------------ ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:19: char _c51_external_startup (void) ; ----------------------------------------- ; function _c51_external_startup ; ----------------------------------------- __c51_external_startup: using 0 ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:21: PCA0MD&=(~0x40) ; // DISABLE WDT: clear Watchdog Enable bit anl _PCA0MD,#0xBF ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:22: VDM0CN=0x80; // enable VDD monitor mov _VDM0CN,#0x80 ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:23: RSTSRC=0x02|0x04; // Enable reset on missing clock detector and VDD mov _RSTSRC,#0x06 ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:29: CLKSEL|=0b_0000_0010; // SYSCLK derived from the Internal High-Frequency Oscillator / 2. orl _CLKSEL,#0x02 ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:35: OSCICN |= 0x03; // Configure internal oscillator for its maximum frequency orl _OSCICN,#0x03 ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:37: P0MDOUT|=0x10; // Enable Uart TX as push-pull output orl _P0MDOUT,#0x10 ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:38: P1MDOUT|=0b_0000_1111; // LCD's D4 to D7 are connected to P1.3 to P1.0 orl _P1MDOUT,#0x0F ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:39: P2MDOUT|=0b_0000_0111; // P2.2 is LCD's RS, P2.1 is LCD's RW, P2.0 is LCD's E orl _P2MDOUT,#0x07 ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:40: XBR0=0x01; // Enable UART on P0.4(TX) and P0.5(RX) mov _XBR0,#0x01 ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:41: XBR1=0x40; // Enable crossbar and weak pull-ups mov _XBR1,#0x40 ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:44: TH1 = 0x10000-((SYSCLK/BAUDRATE)/2L); mov _TH1,#0x98 ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:45: CKCON &= ~0x0B; // T1M = 1; SCA1:0 = xx anl _CKCON,#0xF4 ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:46: CKCON |= 0x08; orl _CKCON,#0x08 ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:60: TL1 = TH1; // Init timer 1 mov _TL1,_TH1 ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:61: TMOD &= 0x0f; // TMOD: timer 1 in 8-bit autoreload anl _TMOD,#0x0F ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:62: TMOD |= 0x20; orl _TMOD,#0x20 ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:63: TR1 = 1; // Start timer1 setb _TR1 ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:64: SCON = 0x52; mov _SCON,#0x52 ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:66: return 0; mov dpl,#0x00 ret ;------------------------------------------------------------ ;Allocation info for local variables in function 'Timer3us' ;------------------------------------------------------------ ;us Allocated to registers r2 ;i Allocated to registers r3 ;------------------------------------------------------------ ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:70: void Timer3us(unsigned char us) ; ----------------------------------------- ; function Timer3us ; ----------------------------------------- _Timer3us: mov r2,dpl ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:75: CKCON|=0b_0100_0000; orl _CKCON,#0x40 ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:77: TMR3RL = (-(SYSCLK)/1000000L); // Set Timer3 to overflow in 1us. mov _TMR3RL,#0xE8 mov (_TMR3RL >> 8),#0xFF ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:78: TMR3 = TMR3RL; // Initialize Timer3 for first overflow mov _TMR3,_TMR3RL mov (_TMR3 >> 8),(_TMR3RL >> 8) ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:80: TMR3CN = 0x04; // Sart Timer3 and clear overflow flag mov _TMR3CN,#0x04 ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:81: for (i = 0; i < us; i++) // Count <us> overflows mov r3,#0x00 L003004?: clr c mov a,r3 subb a,r2 jnc L003007? ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:83: while (!(TMR3CN & 0x80)); // Wait for overflow L003001?: mov a,_TMR3CN jnb acc.7,L003001? ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:84: TMR3CN &= ~(0x80); // Clear overflow indicator anl _TMR3CN,#0x7F ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:81: for (i = 0; i < us; i++) // Count <us> overflows inc r3 sjmp L003004? L003007?: ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:86: TMR3CN = 0 ; // Stop Timer3 and clear overflow flag mov _TMR3CN,#0x00 ret ;------------------------------------------------------------ ;Allocation info for local variables in function 'waitms' ;------------------------------------------------------------ ;ms Allocated to registers r2 r3 ;j Allocated to registers r4 r5 ;k Allocated to registers r6 ;------------------------------------------------------------ ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:89: void waitms (unsigned int ms) ; ----------------------------------------- ; function waitms ; ----------------------------------------- _waitms: mov r2,dpl mov r3,dph ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:93: for(j=0; j<ms; j++) mov r4,#0x00 mov r5,#0x00 L004005?: clr c mov a,r4 subb a,r2 mov a,r5 subb a,r3 jnc L004009? ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:94: for (k=0; k<4; k++) Timer3us(250); mov r6,#0x00 L004001?: cjne r6,#0x04,L004018? L004018?: jnc L004007? mov dpl,#0xFA push ar2 push ar3 push ar4 push ar5 push ar6 lcall _Timer3us pop ar6 pop ar5 pop ar4 pop ar3 pop ar2 inc r6 sjmp L004001? L004007?: ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:93: for(j=0; j<ms; j++) inc r4 cjne r4,#0x00,L004005? inc r5 sjmp L004005? L004009?: ret ;------------------------------------------------------------ ;Allocation info for local variables in function 'LCD_pulse' ;------------------------------------------------------------ ;------------------------------------------------------------ ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:97: void LCD_pulse (void) ; ----------------------------------------- ; function LCD_pulse ; ----------------------------------------- _LCD_pulse: ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:99: LCD_E=1; setb _P1_7 ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:100: Timer3us(40); mov dpl,#0x28 lcall _Timer3us ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:101: LCD_E=0; clr _P1_7 ret ;------------------------------------------------------------ ;Allocation info for local variables in function 'LCD_byte' ;------------------------------------------------------------ ;x Allocated to registers r2 ;------------------------------------------------------------ ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:104: void LCD_byte (unsigned char x) ; ----------------------------------------- ; function LCD_byte ; ----------------------------------------- _LCD_byte: mov r2,dpl ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:107: ACC=x; //Send high nible mov _ACC,r2 ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:108: LCD_D7=ACC_7; mov c,_ACC_7 mov _P0_7,c ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:109: LCD_D6=ACC_6; mov c,_ACC_6 mov _P1_0,c ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:110: LCD_D5=ACC_5; mov c,_ACC_5 mov _P1_1,c ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:111: LCD_D4=ACC_4; mov c,_ACC_4 mov _P1_2,c ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:112: LCD_pulse(); push ar2 lcall _LCD_pulse ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:113: Timer3us(40); mov dpl,#0x28 lcall _Timer3us pop ar2 ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:114: ACC=x; //Send low nible mov _ACC,r2 ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:115: LCD_D7=ACC_3; mov c,_ACC_3 mov _P0_7,c ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:116: LCD_D6=ACC_2; mov c,_ACC_2 mov _P1_0,c ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:117: LCD_D5=ACC_1; mov c,_ACC_1 mov _P1_1,c ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:118: LCD_D4=ACC_0; mov c,_ACC_0 mov _P1_2,c ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:119: LCD_pulse(); ljmp _LCD_pulse ;------------------------------------------------------------ ;Allocation info for local variables in function 'WriteData' ;------------------------------------------------------------ ;x Allocated to registers r2 ;------------------------------------------------------------ ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:122: void WriteData (unsigned char x) ; ----------------------------------------- ; function WriteData ; ----------------------------------------- _WriteData: mov r2,dpl ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:124: LCD_RS=1; setb _P2_1 ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:125: LCD_byte(x); mov dpl,r2 lcall _LCD_byte ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:126: waitms(2); mov dptr,#0x0002 ljmp _waitms ;------------------------------------------------------------ ;Allocation info for local variables in function 'WriteCommand' ;------------------------------------------------------------ ;x Allocated to registers r2 ;------------------------------------------------------------ ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:129: void WriteCommand (unsigned char x) ; ----------------------------------------- ; function WriteCommand ; ----------------------------------------- _WriteCommand: mov r2,dpl ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:131: LCD_RS=0; clr _P2_1 ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:132: LCD_byte(x); mov dpl,r2 lcall _LCD_byte ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:133: waitms(5); mov dptr,#0x0005 ljmp _waitms ;------------------------------------------------------------ ;Allocation info for local variables in function 'LCD_4BIT' ;------------------------------------------------------------ ;------------------------------------------------------------ ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:136: void LCD_4BIT (void) ; ----------------------------------------- ; function LCD_4BIT ; ----------------------------------------- _LCD_4BIT: ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:138: LCD_E=0; // Resting state of LCD's enable is zero clr _P1_7 ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:139: LCD_RW=0; // We are only writing to the LCD in this program clr _P2_0 ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:140: waitms(20); mov dptr,#0x0014 lcall _waitms ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:142: WriteCommand(0x33); mov dpl,#0x33 lcall _WriteCommand ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:143: WriteCommand(0x33); mov dpl,#0x33 lcall _WriteCommand ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:144: WriteCommand(0x32); // Change to 4-bit mode mov dpl,#0x32 lcall _WriteCommand ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:147: WriteCommand(0x28); mov dpl,#0x28 lcall _WriteCommand ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:148: WriteCommand(0x0c); mov dpl,#0x0C lcall _WriteCommand ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:149: WriteCommand(0x01); // Clear screen command (takes some time) mov dpl,#0x01 lcall _WriteCommand ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:150: waitms(20); // Wait for clear screen command to finsih. mov dptr,#0x0014 ljmp _waitms ;------------------------------------------------------------ ;Allocation info for local variables in function 'LCDprint' ;------------------------------------------------------------ ;line Allocated with name '_LCDprint_PARM_2' ;string Allocated to registers r2 r3 r4 ;j Allocated to registers r5 r6 ;------------------------------------------------------------ ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:153: void LCDprint(char * string, unsigned char line, bit clear) ; ----------------------------------------- ; function LCDprint ; ----------------------------------------- _LCDprint: mov r2,dpl mov r3,dph mov r4,b ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:157: WriteCommand(line==2?0xc0:0x80); mov a,#0x02 cjne a,_LCDprint_PARM_2,L010013? mov r5,#0xC0 sjmp L010014? L010013?: mov r5,#0x80 L010014?: mov dpl,r5 push ar2 push ar3 push ar4 lcall _WriteCommand ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:158: waitms(5); mov dptr,#0x0005 lcall _waitms pop ar4 pop ar3 pop ar2 ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:159: for(j=0; string[j]!=0; j++) WriteData(string[j]);// Write the message mov r5,#0x00 mov r6,#0x00 L010003?: mov a,r5 add a,r2 mov r7,a mov a,r6 addc a,r3 mov r0,a mov ar1,r4 mov dpl,r7 mov dph,r0 mov b,r1 lcall __gptrget mov r7,a jz L010006? mov dpl,r7 push ar2 push ar3 push ar4 push ar5 push ar6 lcall _WriteData pop ar6 pop ar5 pop ar4 pop ar3 pop ar2 inc r5 cjne r5,#0x00,L010003? inc r6 sjmp L010003? L010006?: ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:160: if(clear) for(; j<CHARS_PER_LINE; j++) WriteData(' '); // Clear the rest of the line jnb _LCDprint_PARM_3,L010011? mov ar2,r5 mov ar3,r6 L010007?: clr c mov a,r2 subb a,#0x10 mov a,r3 xrl a,#0x80 subb a,#0x80 jnc L010011? mov dpl,#0x20 push ar2 push ar3 lcall _WriteData pop ar3 pop ar2 inc r2 cjne r2,#0x00,L010007? inc r3 sjmp L010007? L010011?: ret ;------------------------------------------------------------ ;Allocation info for local variables in function 'main' ;------------------------------------------------------------ ;------------------------------------------------------------ ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:164: void main (void) ; ----------------------------------------- ; function main ; ----------------------------------------- _main: ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:167: LCD_4BIT(); lcall _LCD_4BIT ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:170: LCDprint("LCD 4-bit test:", 1, 1); mov _LCDprint_PARM_2,#0x01 setb _LCDprint_PARM_3 mov dptr,#__str_0 mov b,#0x80 lcall _LCDprint ; C:\Users\jeffreyliou\Desktop\elec291\lab4\hellolcd.c:171: LCDprint("Hello, World!", 2, 1); mov _LCDprint_PARM_2,#0x02 setb _LCDprint_PARM_3 mov dptr,#__str_1 mov b,#0x80 ljmp _LCDprint rseg R_CSEG rseg R_XINIT rseg R_CONST __str_0: db 'LCD 4-bit test:' db 0x00 __str_1: db 'Hello, World!' db 0x00 CSEG end
#include "dfinstance.h" #include "memorylayout.h" #include "selectparentlayoutdialog.h" #include "ui_selectparentlayoutdialog.h" SelectParentLayoutDialog::SelectParentLayoutDialog(DFInstance *df, QWidget *parent) : QDialog(parent), ui(new Ui::SelectParentLayoutDialog), m_df(df), m_layout(NULL) { ui->setupUi(this); for (const auto &p: m_df->get_layouts()) { auto layout = p.second.get(); ui->cmb_select_layout->addItem(layout->game_version(), qVariantFromValue(layout)); } ui->cmb_select_layout->model()->sort(0); } SelectParentLayoutDialog::~SelectParentLayoutDialog() { delete ui; } MemoryLayout * SelectParentLayoutDialog::get_layout() { return m_layout; } QString SelectParentLayoutDialog::get_file_name() { return ui->le_file_name->text(); } QString SelectParentLayoutDialog::get_version_name() { return ui->le_version_name->text(); } void SelectParentLayoutDialog::selection_changed(int idx) { QVariant var = ui->cmb_select_layout->itemData(idx); m_layout = var.value<MemoryLayout *>(); ui->le_file_name->setText(m_layout->filename()); ui->le_version_name->setText(m_layout->game_version()); }
; sp1_UpdateNow SECTION code_clib SECTION code_temp_sp1 PUBLIC _sp1_UpdateNow EXTERN asm_sp1_UpdateNow _sp1_UpdateNow: push ix call asm_sp1_UpdateNow pop ix ret
; A025712: Index of 6^n within sequence of numbers of form 2^i*6^j. ; 1,4,10,18,29,42,58,77,98,122,148,177,209,243,280,319,361,405,452,502,554,609,666,726,789,854,922,992,1065,1140,1218,1299,1382,1468,1556,1647,1741,1837,1936,2037,2141,2247,2356,2468,2582,2699,2818,2940,3065,3192,3322,3454,3589,3727,3867,4010,4155,4303,4453,4606,4762,4920,5081,5244,5410,5579,5750,5924,6100,6279,6460,6644,6831,7020,7212,7406,7603,7803,8005,8210,8417,8627,8839,9054,9272,9492,9715,9940,10168,10399,10632,10868,11106,11347,11590,11836,12085,12336,12590,12846,13105,13367,13631,13898,14167,14439,14714,14991,15271,15553,15838,16125,16415,16708,17003,17301,17601,17904,18210,18518,18829,19142,19458,19776,20097,20421,20747,21076,21407,21741,22078,22417,22759,23103,23450,23799,24151,24506,24863,25223,25585,25950,26318,26688,27061,27436,27814,28194,28577,28963,29351,29742,30135,30531,30930,31331,31735,32141,32550,32962,33376,33793,34212,34634,35058,35485,35915,36347,36782,37219,37659,38102,38547,38995,39445,39898,40353,40811,41272,41735,42201,42669,43140,43614,44090,44569,45050,45534,46020,46509,47001,47495,47992,48491,48993,49498,50005,50515,51027,51542,52059,52579,53102,53627,54155,54685,55218,55754,56292,56833,57376,57922,58471,59022,59576,60132,60691,61252,61816,62383,62952,63524,64098,64675,65255,65837,66422,67009,67599,68191,68786,69384,69984,70587,71192,71800,72411,73024,73640,74258,74879,75502,76128,76757,77388,78022,78658,79297,79939,80583 mov $16,$0 mov $18,$0 add $18,1 lpb $18,1 clr $0,16 mov $0,$16 sub $18,1 sub $0,$18 mov $13,$0 mov $15,$0 add $15,1 lpb $15,1 mov $0,$13 sub $15,1 sub $0,$15 mov $9,$0 mov $11,2 lpb $11,1 clr $0,9 mov $0,$9 sub $11,1 add $0,$11 sub $0,1 mul $0,84 add $1,$0 div $1,53 mov $12,$11 lpb $12,1 mov $10,$1 sub $12,1 lpe lpe lpb $9,1 mov $9,0 sub $10,$1 lpe mov $1,$10 add $1,1 add $14,$1 lpe add $17,$14 lpe mov $1,$17
; A082999: a(n) = A046195(n) mod 5. ; 1,1,4,1,4,0,4,0,4,0,4,1,4,1,1,1,1,4,1,4,0,4,0,4,0,4,1,4,1,1,1,1,4,1,4,0,4,0,4,0,4,1,4,1,1,1,1,4,1,4,0,4,0,4,0,4,1,4,1,1,1,1,4,1,4,0,4,0,4,0,4,1,4,1,1,1,1,4,1,4,0,4,0,4,0,4,1,4,1,1,1,1,4,1,4,0,4,0,4,0,4,1,4,1,1 mul $0,7 div $0,3 sub $0,1 pow $0,2 lpb $0 mod $0,5 lpe mov $1,$0
%macro PUSH_CC 0 ; Don't bother being too picky, just take the time pusha %endmacro %macro PUSH_SEG 0 push ds push es push fs push gs mov ax, 0x10 mov ds, ax mov es, ax mov fs, ax mov gs, ax %endmacro %macro POP_CC 0 popa %endmacro %macro POP_SEG 0 pop gs pop fs pop es pop ds %endmacro
; ; ; Copyright (c) 2015 - 2021 by blindtiger ( blindtiger@foxmail.com ) ; ; The contents of this file are subject to the Mozilla Public 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.mozilla.org/MPL/ ; ; Software distributed under the License is distributed on an "AS IS" basis, ; WITHOUT WARRANTY OF ANY KIND, either express or implied. SEe the License ; for the specific language governing rights and limitations under the ; License. ; ; The Initial Developer of the Original Code is blindtiger. ; ; include ksamd64.inc include macamd64.inc end
;******************************************************************************* ;* Tutorial Twenty-One Input from a device using Kernel Jump Vectors * ;* * ;* Written By John C. Dale * ;* Tutorial #21 * ;* Date : 29th Sep, 2017 * ;* * ;******************************************************************************* ;* * ;******************************************************************************* ;******************************************************************************* ;* Kernel Vector Constants * ;******************************************************************************* CHROUT = $FFD2 CHRIN = $FFCF CHKIN = $FFC6 CHKOUT = $FFC9 OPEN = $FFC0 SETLFS = $FFBA SETNAM = $FFBD CLRCHN = $FFCC CLOSE = $FFC3 PRINTSTRING = $AB1E BUFFERTEXT = $0200 *=$9000 ;jmp INPUTFROMDEFAULT ;jmp INPUTFROMTAPE ;jmp INPUTFROMDISK TESTFILENAME TEXT "johntest" BRK TESTFILENAMEDISK TEXT "johntest,seq,read" BRK TESTTEXT TEXT " " BRK INPUTFROMDEFAULT jsr INPUTSTRING rts INPUTFROMTAPE lda #1 ; Logical File Number tax ; Device Number (Tape Device #1) ldy #0 ; Secondary Address (0 = Loading) jsr SETLFS lda #8 ldx #<TESTFILENAME ldy #>TESTFILENAME jsr SETNAM jsr OPEN ldx #1 ; Logical File Number jsr CHKIN jsr INPUTFROMDEFAULT jsr CLRCHN lda #1 ; Logical File Number jsr CLOSE RTS INPUTFROMDISK lda #8 ; Logical File Number tax ; Device Number (Disk Drive 8) ldy #2 ; Secondary Address jsr SETLFS lda #17 ldx #<TESTFILENAMEDISK ldy #>TESTFILENAMEDISK jsr SETNAM jsr OPEN ldx #8 ; Logical File Number jsr CHKIN NOCHKOUTERRORFOUND jsr INPUTFROMDEFAULT jsr CLRCHN lda #8 ; Logical File Number jsr CLOSE RTS INPUTSTRING ldx #0 @INPUTSTRINGLOOP jsr $e112 cmp #13 beq @INPUTEND sta TESTTEXT,x inx cpx #56 bcc @INPUTSTRINGLOOP @INPUTEND RTS
/*============================================================================= Copyright (c) 2001-2011 Joel de Guzman 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) This is an auto-generated file. Do not edit! ==============================================================================*/ namespace boost { namespace fusion { struct void_; struct fusion_sequence_tag; template <typename T0 , typename T1 , typename T2 , typename T3 , typename T4 , typename T5 , typename T6 , typename T7 , typename T8 , typename T9 , typename T10 , typename T11 , typename T12 , typename T13 , typename T14 , typename T15 , typename T16 , typename T17 , typename T18 , typename T19 , typename T20 , typename T21 , typename T22 , typename T23 , typename T24 , typename T25 , typename T26 , typename T27 , typename T28 , typename T29> struct set : sequence_base<set<T0 , T1 , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , T11 , T12 , T13 , T14 , T15 , T16 , T17 , T18 , T19 , T20 , T21 , T22 , T23 , T24 , T25 , T26 , T27 , T28 , T29> > { struct category : forward_traversal_tag, associative_tag {}; typedef set_tag fusion_tag; typedef fusion_sequence_tag tag; typedef mpl::false_ is_view; typedef vector< T0 , T1 , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , T11 , T12 , T13 , T14 , T15 , T16 , T17 , T18 , T19 , T20 , T21 , T22 , T23 , T24 , T25 , T26 , T27 , T28 , T29> storage_type; typedef typename storage_type::size size; BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set() : data() {} template <typename Sequence> BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set(Sequence const& rhs , typename boost::enable_if<traits::is_sequence<Sequence> >::type* = 0) : data(rhs) {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED explicit set(typename detail::call_param<T0 >::type arg0) : data(arg0) {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set(typename detail::call_param<T0 >::type arg0 , typename detail::call_param<T1 >::type arg1) : data(arg0 , arg1) {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set(typename detail::call_param<T0 >::type arg0 , typename detail::call_param<T1 >::type arg1 , typename detail::call_param<T2 >::type arg2) : data(arg0 , arg1 , arg2) {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set(typename detail::call_param<T0 >::type arg0 , typename detail::call_param<T1 >::type arg1 , typename detail::call_param<T2 >::type arg2 , typename detail::call_param<T3 >::type arg3) : data(arg0 , arg1 , arg2 , arg3) {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set(typename detail::call_param<T0 >::type arg0 , typename detail::call_param<T1 >::type arg1 , typename detail::call_param<T2 >::type arg2 , typename detail::call_param<T3 >::type arg3 , typename detail::call_param<T4 >::type arg4) : data(arg0 , arg1 , arg2 , arg3 , arg4) {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set(typename detail::call_param<T0 >::type arg0 , typename detail::call_param<T1 >::type arg1 , typename detail::call_param<T2 >::type arg2 , typename detail::call_param<T3 >::type arg3 , typename detail::call_param<T4 >::type arg4 , typename detail::call_param<T5 >::type arg5) : data(arg0 , arg1 , arg2 , arg3 , arg4 , arg5) {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set(typename detail::call_param<T0 >::type arg0 , typename detail::call_param<T1 >::type arg1 , typename detail::call_param<T2 >::type arg2 , typename detail::call_param<T3 >::type arg3 , typename detail::call_param<T4 >::type arg4 , typename detail::call_param<T5 >::type arg5 , typename detail::call_param<T6 >::type arg6) : data(arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6) {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set(typename detail::call_param<T0 >::type arg0 , typename detail::call_param<T1 >::type arg1 , typename detail::call_param<T2 >::type arg2 , typename detail::call_param<T3 >::type arg3 , typename detail::call_param<T4 >::type arg4 , typename detail::call_param<T5 >::type arg5 , typename detail::call_param<T6 >::type arg6 , typename detail::call_param<T7 >::type arg7) : data(arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 , arg7) {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set(typename detail::call_param<T0 >::type arg0 , typename detail::call_param<T1 >::type arg1 , typename detail::call_param<T2 >::type arg2 , typename detail::call_param<T3 >::type arg3 , typename detail::call_param<T4 >::type arg4 , typename detail::call_param<T5 >::type arg5 , typename detail::call_param<T6 >::type arg6 , typename detail::call_param<T7 >::type arg7 , typename detail::call_param<T8 >::type arg8) : data(arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 , arg7 , arg8) {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set(typename detail::call_param<T0 >::type arg0 , typename detail::call_param<T1 >::type arg1 , typename detail::call_param<T2 >::type arg2 , typename detail::call_param<T3 >::type arg3 , typename detail::call_param<T4 >::type arg4 , typename detail::call_param<T5 >::type arg5 , typename detail::call_param<T6 >::type arg6 , typename detail::call_param<T7 >::type arg7 , typename detail::call_param<T8 >::type arg8 , typename detail::call_param<T9 >::type arg9) : data(arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 , arg7 , arg8 , arg9) {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set(typename detail::call_param<T0 >::type arg0 , typename detail::call_param<T1 >::type arg1 , typename detail::call_param<T2 >::type arg2 , typename detail::call_param<T3 >::type arg3 , typename detail::call_param<T4 >::type arg4 , typename detail::call_param<T5 >::type arg5 , typename detail::call_param<T6 >::type arg6 , typename detail::call_param<T7 >::type arg7 , typename detail::call_param<T8 >::type arg8 , typename detail::call_param<T9 >::type arg9 , typename detail::call_param<T10 >::type arg10) : data(arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 , arg7 , arg8 , arg9 , arg10) {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set(typename detail::call_param<T0 >::type arg0 , typename detail::call_param<T1 >::type arg1 , typename detail::call_param<T2 >::type arg2 , typename detail::call_param<T3 >::type arg3 , typename detail::call_param<T4 >::type arg4 , typename detail::call_param<T5 >::type arg5 , typename detail::call_param<T6 >::type arg6 , typename detail::call_param<T7 >::type arg7 , typename detail::call_param<T8 >::type arg8 , typename detail::call_param<T9 >::type arg9 , typename detail::call_param<T10 >::type arg10 , typename detail::call_param<T11 >::type arg11) : data(arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 , arg7 , arg8 , arg9 , arg10 , arg11) {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set(typename detail::call_param<T0 >::type arg0 , typename detail::call_param<T1 >::type arg1 , typename detail::call_param<T2 >::type arg2 , typename detail::call_param<T3 >::type arg3 , typename detail::call_param<T4 >::type arg4 , typename detail::call_param<T5 >::type arg5 , typename detail::call_param<T6 >::type arg6 , typename detail::call_param<T7 >::type arg7 , typename detail::call_param<T8 >::type arg8 , typename detail::call_param<T9 >::type arg9 , typename detail::call_param<T10 >::type arg10 , typename detail::call_param<T11 >::type arg11 , typename detail::call_param<T12 >::type arg12) : data(arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 , arg7 , arg8 , arg9 , arg10 , arg11 , arg12) {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set(typename detail::call_param<T0 >::type arg0 , typename detail::call_param<T1 >::type arg1 , typename detail::call_param<T2 >::type arg2 , typename detail::call_param<T3 >::type arg3 , typename detail::call_param<T4 >::type arg4 , typename detail::call_param<T5 >::type arg5 , typename detail::call_param<T6 >::type arg6 , typename detail::call_param<T7 >::type arg7 , typename detail::call_param<T8 >::type arg8 , typename detail::call_param<T9 >::type arg9 , typename detail::call_param<T10 >::type arg10 , typename detail::call_param<T11 >::type arg11 , typename detail::call_param<T12 >::type arg12 , typename detail::call_param<T13 >::type arg13) : data(arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 , arg7 , arg8 , arg9 , arg10 , arg11 , arg12 , arg13) {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set(typename detail::call_param<T0 >::type arg0 , typename detail::call_param<T1 >::type arg1 , typename detail::call_param<T2 >::type arg2 , typename detail::call_param<T3 >::type arg3 , typename detail::call_param<T4 >::type arg4 , typename detail::call_param<T5 >::type arg5 , typename detail::call_param<T6 >::type arg6 , typename detail::call_param<T7 >::type arg7 , typename detail::call_param<T8 >::type arg8 , typename detail::call_param<T9 >::type arg9 , typename detail::call_param<T10 >::type arg10 , typename detail::call_param<T11 >::type arg11 , typename detail::call_param<T12 >::type arg12 , typename detail::call_param<T13 >::type arg13 , typename detail::call_param<T14 >::type arg14) : data(arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 , arg7 , arg8 , arg9 , arg10 , arg11 , arg12 , arg13 , arg14) {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set(typename detail::call_param<T0 >::type arg0 , typename detail::call_param<T1 >::type arg1 , typename detail::call_param<T2 >::type arg2 , typename detail::call_param<T3 >::type arg3 , typename detail::call_param<T4 >::type arg4 , typename detail::call_param<T5 >::type arg5 , typename detail::call_param<T6 >::type arg6 , typename detail::call_param<T7 >::type arg7 , typename detail::call_param<T8 >::type arg8 , typename detail::call_param<T9 >::type arg9 , typename detail::call_param<T10 >::type arg10 , typename detail::call_param<T11 >::type arg11 , typename detail::call_param<T12 >::type arg12 , typename detail::call_param<T13 >::type arg13 , typename detail::call_param<T14 >::type arg14 , typename detail::call_param<T15 >::type arg15) : data(arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 , arg7 , arg8 , arg9 , arg10 , arg11 , arg12 , arg13 , arg14 , arg15) {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set(typename detail::call_param<T0 >::type arg0 , typename detail::call_param<T1 >::type arg1 , typename detail::call_param<T2 >::type arg2 , typename detail::call_param<T3 >::type arg3 , typename detail::call_param<T4 >::type arg4 , typename detail::call_param<T5 >::type arg5 , typename detail::call_param<T6 >::type arg6 , typename detail::call_param<T7 >::type arg7 , typename detail::call_param<T8 >::type arg8 , typename detail::call_param<T9 >::type arg9 , typename detail::call_param<T10 >::type arg10 , typename detail::call_param<T11 >::type arg11 , typename detail::call_param<T12 >::type arg12 , typename detail::call_param<T13 >::type arg13 , typename detail::call_param<T14 >::type arg14 , typename detail::call_param<T15 >::type arg15 , typename detail::call_param<T16 >::type arg16) : data(arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 , arg7 , arg8 , arg9 , arg10 , arg11 , arg12 , arg13 , arg14 , arg15 , arg16) {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set(typename detail::call_param<T0 >::type arg0 , typename detail::call_param<T1 >::type arg1 , typename detail::call_param<T2 >::type arg2 , typename detail::call_param<T3 >::type arg3 , typename detail::call_param<T4 >::type arg4 , typename detail::call_param<T5 >::type arg5 , typename detail::call_param<T6 >::type arg6 , typename detail::call_param<T7 >::type arg7 , typename detail::call_param<T8 >::type arg8 , typename detail::call_param<T9 >::type arg9 , typename detail::call_param<T10 >::type arg10 , typename detail::call_param<T11 >::type arg11 , typename detail::call_param<T12 >::type arg12 , typename detail::call_param<T13 >::type arg13 , typename detail::call_param<T14 >::type arg14 , typename detail::call_param<T15 >::type arg15 , typename detail::call_param<T16 >::type arg16 , typename detail::call_param<T17 >::type arg17) : data(arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 , arg7 , arg8 , arg9 , arg10 , arg11 , arg12 , arg13 , arg14 , arg15 , arg16 , arg17) {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set(typename detail::call_param<T0 >::type arg0 , typename detail::call_param<T1 >::type arg1 , typename detail::call_param<T2 >::type arg2 , typename detail::call_param<T3 >::type arg3 , typename detail::call_param<T4 >::type arg4 , typename detail::call_param<T5 >::type arg5 , typename detail::call_param<T6 >::type arg6 , typename detail::call_param<T7 >::type arg7 , typename detail::call_param<T8 >::type arg8 , typename detail::call_param<T9 >::type arg9 , typename detail::call_param<T10 >::type arg10 , typename detail::call_param<T11 >::type arg11 , typename detail::call_param<T12 >::type arg12 , typename detail::call_param<T13 >::type arg13 , typename detail::call_param<T14 >::type arg14 , typename detail::call_param<T15 >::type arg15 , typename detail::call_param<T16 >::type arg16 , typename detail::call_param<T17 >::type arg17 , typename detail::call_param<T18 >::type arg18) : data(arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 , arg7 , arg8 , arg9 , arg10 , arg11 , arg12 , arg13 , arg14 , arg15 , arg16 , arg17 , arg18) {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set(typename detail::call_param<T0 >::type arg0 , typename detail::call_param<T1 >::type arg1 , typename detail::call_param<T2 >::type arg2 , typename detail::call_param<T3 >::type arg3 , typename detail::call_param<T4 >::type arg4 , typename detail::call_param<T5 >::type arg5 , typename detail::call_param<T6 >::type arg6 , typename detail::call_param<T7 >::type arg7 , typename detail::call_param<T8 >::type arg8 , typename detail::call_param<T9 >::type arg9 , typename detail::call_param<T10 >::type arg10 , typename detail::call_param<T11 >::type arg11 , typename detail::call_param<T12 >::type arg12 , typename detail::call_param<T13 >::type arg13 , typename detail::call_param<T14 >::type arg14 , typename detail::call_param<T15 >::type arg15 , typename detail::call_param<T16 >::type arg16 , typename detail::call_param<T17 >::type arg17 , typename detail::call_param<T18 >::type arg18 , typename detail::call_param<T19 >::type arg19) : data(arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 , arg7 , arg8 , arg9 , arg10 , arg11 , arg12 , arg13 , arg14 , arg15 , arg16 , arg17 , arg18 , arg19) {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set(typename detail::call_param<T0 >::type arg0 , typename detail::call_param<T1 >::type arg1 , typename detail::call_param<T2 >::type arg2 , typename detail::call_param<T3 >::type arg3 , typename detail::call_param<T4 >::type arg4 , typename detail::call_param<T5 >::type arg5 , typename detail::call_param<T6 >::type arg6 , typename detail::call_param<T7 >::type arg7 , typename detail::call_param<T8 >::type arg8 , typename detail::call_param<T9 >::type arg9 , typename detail::call_param<T10 >::type arg10 , typename detail::call_param<T11 >::type arg11 , typename detail::call_param<T12 >::type arg12 , typename detail::call_param<T13 >::type arg13 , typename detail::call_param<T14 >::type arg14 , typename detail::call_param<T15 >::type arg15 , typename detail::call_param<T16 >::type arg16 , typename detail::call_param<T17 >::type arg17 , typename detail::call_param<T18 >::type arg18 , typename detail::call_param<T19 >::type arg19 , typename detail::call_param<T20 >::type arg20) : data(arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 , arg7 , arg8 , arg9 , arg10 , arg11 , arg12 , arg13 , arg14 , arg15 , arg16 , arg17 , arg18 , arg19 , arg20) {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set(typename detail::call_param<T0 >::type arg0 , typename detail::call_param<T1 >::type arg1 , typename detail::call_param<T2 >::type arg2 , typename detail::call_param<T3 >::type arg3 , typename detail::call_param<T4 >::type arg4 , typename detail::call_param<T5 >::type arg5 , typename detail::call_param<T6 >::type arg6 , typename detail::call_param<T7 >::type arg7 , typename detail::call_param<T8 >::type arg8 , typename detail::call_param<T9 >::type arg9 , typename detail::call_param<T10 >::type arg10 , typename detail::call_param<T11 >::type arg11 , typename detail::call_param<T12 >::type arg12 , typename detail::call_param<T13 >::type arg13 , typename detail::call_param<T14 >::type arg14 , typename detail::call_param<T15 >::type arg15 , typename detail::call_param<T16 >::type arg16 , typename detail::call_param<T17 >::type arg17 , typename detail::call_param<T18 >::type arg18 , typename detail::call_param<T19 >::type arg19 , typename detail::call_param<T20 >::type arg20 , typename detail::call_param<T21 >::type arg21) : data(arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 , arg7 , arg8 , arg9 , arg10 , arg11 , arg12 , arg13 , arg14 , arg15 , arg16 , arg17 , arg18 , arg19 , arg20 , arg21) {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set(typename detail::call_param<T0 >::type arg0 , typename detail::call_param<T1 >::type arg1 , typename detail::call_param<T2 >::type arg2 , typename detail::call_param<T3 >::type arg3 , typename detail::call_param<T4 >::type arg4 , typename detail::call_param<T5 >::type arg5 , typename detail::call_param<T6 >::type arg6 , typename detail::call_param<T7 >::type arg7 , typename detail::call_param<T8 >::type arg8 , typename detail::call_param<T9 >::type arg9 , typename detail::call_param<T10 >::type arg10 , typename detail::call_param<T11 >::type arg11 , typename detail::call_param<T12 >::type arg12 , typename detail::call_param<T13 >::type arg13 , typename detail::call_param<T14 >::type arg14 , typename detail::call_param<T15 >::type arg15 , typename detail::call_param<T16 >::type arg16 , typename detail::call_param<T17 >::type arg17 , typename detail::call_param<T18 >::type arg18 , typename detail::call_param<T19 >::type arg19 , typename detail::call_param<T20 >::type arg20 , typename detail::call_param<T21 >::type arg21 , typename detail::call_param<T22 >::type arg22) : data(arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 , arg7 , arg8 , arg9 , arg10 , arg11 , arg12 , arg13 , arg14 , arg15 , arg16 , arg17 , arg18 , arg19 , arg20 , arg21 , arg22) {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set(typename detail::call_param<T0 >::type arg0 , typename detail::call_param<T1 >::type arg1 , typename detail::call_param<T2 >::type arg2 , typename detail::call_param<T3 >::type arg3 , typename detail::call_param<T4 >::type arg4 , typename detail::call_param<T5 >::type arg5 , typename detail::call_param<T6 >::type arg6 , typename detail::call_param<T7 >::type arg7 , typename detail::call_param<T8 >::type arg8 , typename detail::call_param<T9 >::type arg9 , typename detail::call_param<T10 >::type arg10 , typename detail::call_param<T11 >::type arg11 , typename detail::call_param<T12 >::type arg12 , typename detail::call_param<T13 >::type arg13 , typename detail::call_param<T14 >::type arg14 , typename detail::call_param<T15 >::type arg15 , typename detail::call_param<T16 >::type arg16 , typename detail::call_param<T17 >::type arg17 , typename detail::call_param<T18 >::type arg18 , typename detail::call_param<T19 >::type arg19 , typename detail::call_param<T20 >::type arg20 , typename detail::call_param<T21 >::type arg21 , typename detail::call_param<T22 >::type arg22 , typename detail::call_param<T23 >::type arg23) : data(arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 , arg7 , arg8 , arg9 , arg10 , arg11 , arg12 , arg13 , arg14 , arg15 , arg16 , arg17 , arg18 , arg19 , arg20 , arg21 , arg22 , arg23) {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set(typename detail::call_param<T0 >::type arg0 , typename detail::call_param<T1 >::type arg1 , typename detail::call_param<T2 >::type arg2 , typename detail::call_param<T3 >::type arg3 , typename detail::call_param<T4 >::type arg4 , typename detail::call_param<T5 >::type arg5 , typename detail::call_param<T6 >::type arg6 , typename detail::call_param<T7 >::type arg7 , typename detail::call_param<T8 >::type arg8 , typename detail::call_param<T9 >::type arg9 , typename detail::call_param<T10 >::type arg10 , typename detail::call_param<T11 >::type arg11 , typename detail::call_param<T12 >::type arg12 , typename detail::call_param<T13 >::type arg13 , typename detail::call_param<T14 >::type arg14 , typename detail::call_param<T15 >::type arg15 , typename detail::call_param<T16 >::type arg16 , typename detail::call_param<T17 >::type arg17 , typename detail::call_param<T18 >::type arg18 , typename detail::call_param<T19 >::type arg19 , typename detail::call_param<T20 >::type arg20 , typename detail::call_param<T21 >::type arg21 , typename detail::call_param<T22 >::type arg22 , typename detail::call_param<T23 >::type arg23 , typename detail::call_param<T24 >::type arg24) : data(arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 , arg7 , arg8 , arg9 , arg10 , arg11 , arg12 , arg13 , arg14 , arg15 , arg16 , arg17 , arg18 , arg19 , arg20 , arg21 , arg22 , arg23 , arg24) {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set(typename detail::call_param<T0 >::type arg0 , typename detail::call_param<T1 >::type arg1 , typename detail::call_param<T2 >::type arg2 , typename detail::call_param<T3 >::type arg3 , typename detail::call_param<T4 >::type arg4 , typename detail::call_param<T5 >::type arg5 , typename detail::call_param<T6 >::type arg6 , typename detail::call_param<T7 >::type arg7 , typename detail::call_param<T8 >::type arg8 , typename detail::call_param<T9 >::type arg9 , typename detail::call_param<T10 >::type arg10 , typename detail::call_param<T11 >::type arg11 , typename detail::call_param<T12 >::type arg12 , typename detail::call_param<T13 >::type arg13 , typename detail::call_param<T14 >::type arg14 , typename detail::call_param<T15 >::type arg15 , typename detail::call_param<T16 >::type arg16 , typename detail::call_param<T17 >::type arg17 , typename detail::call_param<T18 >::type arg18 , typename detail::call_param<T19 >::type arg19 , typename detail::call_param<T20 >::type arg20 , typename detail::call_param<T21 >::type arg21 , typename detail::call_param<T22 >::type arg22 , typename detail::call_param<T23 >::type arg23 , typename detail::call_param<T24 >::type arg24 , typename detail::call_param<T25 >::type arg25) : data(arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 , arg7 , arg8 , arg9 , arg10 , arg11 , arg12 , arg13 , arg14 , arg15 , arg16 , arg17 , arg18 , arg19 , arg20 , arg21 , arg22 , arg23 , arg24 , arg25) {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set(typename detail::call_param<T0 >::type arg0 , typename detail::call_param<T1 >::type arg1 , typename detail::call_param<T2 >::type arg2 , typename detail::call_param<T3 >::type arg3 , typename detail::call_param<T4 >::type arg4 , typename detail::call_param<T5 >::type arg5 , typename detail::call_param<T6 >::type arg6 , typename detail::call_param<T7 >::type arg7 , typename detail::call_param<T8 >::type arg8 , typename detail::call_param<T9 >::type arg9 , typename detail::call_param<T10 >::type arg10 , typename detail::call_param<T11 >::type arg11 , typename detail::call_param<T12 >::type arg12 , typename detail::call_param<T13 >::type arg13 , typename detail::call_param<T14 >::type arg14 , typename detail::call_param<T15 >::type arg15 , typename detail::call_param<T16 >::type arg16 , typename detail::call_param<T17 >::type arg17 , typename detail::call_param<T18 >::type arg18 , typename detail::call_param<T19 >::type arg19 , typename detail::call_param<T20 >::type arg20 , typename detail::call_param<T21 >::type arg21 , typename detail::call_param<T22 >::type arg22 , typename detail::call_param<T23 >::type arg23 , typename detail::call_param<T24 >::type arg24 , typename detail::call_param<T25 >::type arg25 , typename detail::call_param<T26 >::type arg26) : data(arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 , arg7 , arg8 , arg9 , arg10 , arg11 , arg12 , arg13 , arg14 , arg15 , arg16 , arg17 , arg18 , arg19 , arg20 , arg21 , arg22 , arg23 , arg24 , arg25 , arg26) {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set(typename detail::call_param<T0 >::type arg0 , typename detail::call_param<T1 >::type arg1 , typename detail::call_param<T2 >::type arg2 , typename detail::call_param<T3 >::type arg3 , typename detail::call_param<T4 >::type arg4 , typename detail::call_param<T5 >::type arg5 , typename detail::call_param<T6 >::type arg6 , typename detail::call_param<T7 >::type arg7 , typename detail::call_param<T8 >::type arg8 , typename detail::call_param<T9 >::type arg9 , typename detail::call_param<T10 >::type arg10 , typename detail::call_param<T11 >::type arg11 , typename detail::call_param<T12 >::type arg12 , typename detail::call_param<T13 >::type arg13 , typename detail::call_param<T14 >::type arg14 , typename detail::call_param<T15 >::type arg15 , typename detail::call_param<T16 >::type arg16 , typename detail::call_param<T17 >::type arg17 , typename detail::call_param<T18 >::type arg18 , typename detail::call_param<T19 >::type arg19 , typename detail::call_param<T20 >::type arg20 , typename detail::call_param<T21 >::type arg21 , typename detail::call_param<T22 >::type arg22 , typename detail::call_param<T23 >::type arg23 , typename detail::call_param<T24 >::type arg24 , typename detail::call_param<T25 >::type arg25 , typename detail::call_param<T26 >::type arg26 , typename detail::call_param<T27 >::type arg27) : data(arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 , arg7 , arg8 , arg9 , arg10 , arg11 , arg12 , arg13 , arg14 , arg15 , arg16 , arg17 , arg18 , arg19 , arg20 , arg21 , arg22 , arg23 , arg24 , arg25 , arg26 , arg27) {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set(typename detail::call_param<T0 >::type arg0 , typename detail::call_param<T1 >::type arg1 , typename detail::call_param<T2 >::type arg2 , typename detail::call_param<T3 >::type arg3 , typename detail::call_param<T4 >::type arg4 , typename detail::call_param<T5 >::type arg5 , typename detail::call_param<T6 >::type arg6 , typename detail::call_param<T7 >::type arg7 , typename detail::call_param<T8 >::type arg8 , typename detail::call_param<T9 >::type arg9 , typename detail::call_param<T10 >::type arg10 , typename detail::call_param<T11 >::type arg11 , typename detail::call_param<T12 >::type arg12 , typename detail::call_param<T13 >::type arg13 , typename detail::call_param<T14 >::type arg14 , typename detail::call_param<T15 >::type arg15 , typename detail::call_param<T16 >::type arg16 , typename detail::call_param<T17 >::type arg17 , typename detail::call_param<T18 >::type arg18 , typename detail::call_param<T19 >::type arg19 , typename detail::call_param<T20 >::type arg20 , typename detail::call_param<T21 >::type arg21 , typename detail::call_param<T22 >::type arg22 , typename detail::call_param<T23 >::type arg23 , typename detail::call_param<T24 >::type arg24 , typename detail::call_param<T25 >::type arg25 , typename detail::call_param<T26 >::type arg26 , typename detail::call_param<T27 >::type arg27 , typename detail::call_param<T28 >::type arg28) : data(arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 , arg7 , arg8 , arg9 , arg10 , arg11 , arg12 , arg13 , arg14 , arg15 , arg16 , arg17 , arg18 , arg19 , arg20 , arg21 , arg22 , arg23 , arg24 , arg25 , arg26 , arg27 , arg28) {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED set(typename detail::call_param<T0 >::type arg0 , typename detail::call_param<T1 >::type arg1 , typename detail::call_param<T2 >::type arg2 , typename detail::call_param<T3 >::type arg3 , typename detail::call_param<T4 >::type arg4 , typename detail::call_param<T5 >::type arg5 , typename detail::call_param<T6 >::type arg6 , typename detail::call_param<T7 >::type arg7 , typename detail::call_param<T8 >::type arg8 , typename detail::call_param<T9 >::type arg9 , typename detail::call_param<T10 >::type arg10 , typename detail::call_param<T11 >::type arg11 , typename detail::call_param<T12 >::type arg12 , typename detail::call_param<T13 >::type arg13 , typename detail::call_param<T14 >::type arg14 , typename detail::call_param<T15 >::type arg15 , typename detail::call_param<T16 >::type arg16 , typename detail::call_param<T17 >::type arg17 , typename detail::call_param<T18 >::type arg18 , typename detail::call_param<T19 >::type arg19 , typename detail::call_param<T20 >::type arg20 , typename detail::call_param<T21 >::type arg21 , typename detail::call_param<T22 >::type arg22 , typename detail::call_param<T23 >::type arg23 , typename detail::call_param<T24 >::type arg24 , typename detail::call_param<T25 >::type arg25 , typename detail::call_param<T26 >::type arg26 , typename detail::call_param<T27 >::type arg27 , typename detail::call_param<T28 >::type arg28 , typename detail::call_param<T29 >::type arg29) : data(arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 , arg7 , arg8 , arg9 , arg10 , arg11 , arg12 , arg13 , arg14 , arg15 , arg16 , arg17 , arg18 , arg19 , arg20 , arg21 , arg22 , arg23 , arg24 , arg25 , arg26 , arg27 , arg28 , arg29) {} template <typename T> BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED set& operator=(T const& rhs) { data = rhs; return *this; } BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED storage_type& get_data() { return data; } BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED storage_type const& get_data() const { return data; } private: storage_type data; }; }}
############################################################################### # Copyright 2018 Intel Corporation # All Rights Reserved. # # If this software was obtained under the Intel Simplified Software License, # the following terms apply: # # The source code, information and material ("Material") contained herein is # owned by Intel Corporation or its suppliers or licensors, and title to such # Material remains with Intel Corporation or its suppliers or licensors. The # Material contains proprietary information of Intel or its suppliers and # licensors. The Material is protected by worldwide copyright laws and treaty # provisions. No part of the Material may be used, copied, reproduced, # modified, published, uploaded, posted, transmitted, distributed or disclosed # in any way without Intel's prior express written permission. No license under # any patent, copyright or other intellectual property rights in the Material # is granted to or conferred upon you, either expressly, by implication, # inducement, estoppel or otherwise. Any license under such intellectual # property rights must be express and approved by Intel in writing. # # Unless otherwise agreed by Intel in writing, you may not remove or alter this # notice or any other notice embedded in Materials by Intel or Intel's # suppliers or licensors in any way. # # # If this software was obtained under the Apache License, Version 2.0 (the # "License"), the following terms apply: # # You may not use this file except in compliance with the License. You may # obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 # # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # # See the License for the specific language governing permissions and # limitations under the License. ############################################################################### .text .p2align 5, 0x90 Lpoly: .quad 0x1, 0xffffffff00000000, 0xffffffffffffffff, 0xffffffff LRR: .quad 0xffffffff00000001, 0xffffffff00000000, 0xfffffffe00000000, 0xffffffff LOne: .long 1,1,1,1,1,1,1,1 LTwo: .long 2,2,2,2,2,2,2,2 LThree: .long 3,3,3,3,3,3,3,3 .p2align 5, 0x90 .globl _l9_p224r1_mul_by_2 _l9_p224r1_mul_by_2: push %r12 push %r13 xor %r13, %r13 movq (%rsi), %r8 movq (8)(%rsi), %r9 movq (16)(%rsi), %r10 movq (24)(%rsi), %r11 shld $(1), %r11, %r13 shld $(1), %r10, %r11 shld $(1), %r9, %r10 shld $(1), %r8, %r9 shl $(1), %r8 mov %r8, %rax mov %r9, %rdx mov %r10, %rcx mov %r11, %r12 subq Lpoly+0(%rip), %rax sbbq Lpoly+8(%rip), %rdx sbbq Lpoly+16(%rip), %rcx sbbq Lpoly+24(%rip), %r12 sbb $(0), %r13 cmove %rax, %r8 cmove %rdx, %r9 cmove %rcx, %r10 cmove %r12, %r11 movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) vzeroupper pop %r13 pop %r12 ret .p2align 5, 0x90 .globl _l9_p224r1_div_by_2 _l9_p224r1_div_by_2: push %r12 push %r13 push %r14 movq (%rsi), %r8 movq (8)(%rsi), %r9 movq (16)(%rsi), %r10 movq (24)(%rsi), %r11 xor %r13, %r13 xor %r14, %r14 mov %r8, %rax mov %r9, %rdx mov %r10, %rcx mov %r11, %r12 addq Lpoly+0(%rip), %rax adcq Lpoly+8(%rip), %rdx adcq Lpoly+16(%rip), %rcx adcq Lpoly+24(%rip), %r12 adc $(0), %r13 test $(1), %r8 cmovne %rax, %r8 cmovne %rdx, %r9 cmovne %rcx, %r10 cmovne %r12, %r11 cmovne %r13, %r14 shrd $(1), %r9, %r8 shrd $(1), %r10, %r9 shrd $(1), %r11, %r10 shrd $(1), %r14, %r11 movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) vzeroupper pop %r14 pop %r13 pop %r12 ret .p2align 5, 0x90 .globl _l9_p224r1_mul_by_3 _l9_p224r1_mul_by_3: push %r12 push %r13 xor %r13, %r13 movq (%rsi), %r8 movq (8)(%rsi), %r9 movq (16)(%rsi), %r10 movq (24)(%rsi), %r11 shld $(1), %r11, %r13 shld $(1), %r10, %r11 shld $(1), %r9, %r10 shld $(1), %r8, %r9 shl $(1), %r8 mov %r8, %rax mov %r9, %rdx mov %r10, %rcx mov %r11, %r12 subq Lpoly+0(%rip), %rax sbbq Lpoly+8(%rip), %rdx sbbq Lpoly+16(%rip), %rcx sbbq Lpoly+24(%rip), %r12 sbb $(0), %r13 cmove %rax, %r8 cmove %rdx, %r9 cmove %rcx, %r10 cmove %r12, %r11 xor %r13, %r13 addq (%rsi), %r8 adcq (8)(%rsi), %r9 adcq (16)(%rsi), %r10 adcq (24)(%rsi), %r11 adc $(0), %r13 mov %r8, %rax mov %r9, %rdx mov %r10, %rcx mov %r11, %r12 subq Lpoly+0(%rip), %rax sbbq Lpoly+8(%rip), %rdx sbbq Lpoly+16(%rip), %rcx sbbq Lpoly+24(%rip), %r12 sbb $(0), %r13 cmove %rax, %r8 cmove %rdx, %r9 cmove %rcx, %r10 cmove %r12, %r11 movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) vzeroupper pop %r13 pop %r12 ret .p2align 5, 0x90 .globl _l9_p224r1_add _l9_p224r1_add: push %r12 push %r13 xor %r13, %r13 movq (%rsi), %r8 movq (8)(%rsi), %r9 movq (16)(%rsi), %r10 movq (24)(%rsi), %r11 addq (%rdx), %r8 adcq (8)(%rdx), %r9 adcq (16)(%rdx), %r10 adcq (24)(%rdx), %r11 adc $(0), %r13 mov %r8, %rax mov %r9, %rdx mov %r10, %rcx mov %r11, %r12 subq Lpoly+0(%rip), %rax sbbq Lpoly+8(%rip), %rdx sbbq Lpoly+16(%rip), %rcx sbbq Lpoly+24(%rip), %r12 sbb $(0), %r13 cmove %rax, %r8 cmove %rdx, %r9 cmove %rcx, %r10 cmove %r12, %r11 movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) vzeroupper pop %r13 pop %r12 ret .p2align 5, 0x90 .globl _l9_p224r1_sub _l9_p224r1_sub: push %r12 push %r13 xor %r13, %r13 movq (%rsi), %r8 movq (8)(%rsi), %r9 movq (16)(%rsi), %r10 movq (24)(%rsi), %r11 subq (%rdx), %r8 sbbq (8)(%rdx), %r9 sbbq (16)(%rdx), %r10 sbbq (24)(%rdx), %r11 sbb $(0), %r13 mov %r8, %rax mov %r9, %rdx mov %r10, %rcx mov %r11, %r12 addq Lpoly+0(%rip), %rax adcq Lpoly+8(%rip), %rdx adcq Lpoly+16(%rip), %rcx adcq Lpoly+24(%rip), %r12 test %r13, %r13 cmovne %rax, %r8 cmovne %rdx, %r9 cmovne %rcx, %r10 cmovne %r12, %r11 movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) vzeroupper pop %r13 pop %r12 ret .p2align 5, 0x90 .globl _l9_p224r1_neg _l9_p224r1_neg: push %r12 push %r13 xor %r13, %r13 xor %r8, %r8 xor %r9, %r9 xor %r10, %r10 xor %r11, %r11 subq (%rsi), %r8 sbbq (8)(%rsi), %r9 sbbq (16)(%rsi), %r10 sbbq (24)(%rsi), %r11 sbb $(0), %r13 mov %r8, %rax mov %r9, %rdx mov %r10, %rcx mov %r11, %r12 addq Lpoly+0(%rip), %rax adcq Lpoly+8(%rip), %rdx adcq Lpoly+16(%rip), %rcx adcq Lpoly+24(%rip), %r12 test %r13, %r13 cmovne %rax, %r8 cmovne %rdx, %r9 cmovne %rcx, %r10 cmovne %r12, %r11 movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) vzeroupper pop %r13 pop %r12 ret .p2align 5, 0x90 p224r1_mmull: xor %r13, %r13 movq (%rbx), %rax mulq (%rsi) mov %rax, %r8 mov %rdx, %r9 movq (%rbx), %rax mulq (8)(%rsi) add %rax, %r9 adc $(0), %rdx mov %rdx, %r10 movq (%rbx), %rax mulq (16)(%rsi) add %rax, %r10 adc $(0), %rdx mov %rdx, %r11 movq (%rbx), %rax mulq (24)(%rsi) add %rax, %r11 adc $(0), %rdx mov %rdx, %r12 neg %r8 mov %r8, %rcx mov %r8, %rbp xor %rax, %rax xor %rdx, %rdx shr $(32), %rbp shl $(32), %rcx sub %rcx, %rax sbb %rbp, %rdx sbb $(0), %rcx sbb $(0), %rbp neg %r8 adc %rax, %r9 adc %rdx, %r10 adc %rcx, %r11 adc %rbp, %r12 movq (8)(%rbx), %rax mulq (%rsi) add %rax, %r9 adc $(0), %rdx mov %rdx, %rcx movq (8)(%rbx), %rax mulq (8)(%rsi) add %rcx, %r10 adc $(0), %rdx add %rax, %r10 adc $(0), %rdx mov %rdx, %rcx movq (8)(%rbx), %rax mulq (16)(%rsi) add %rcx, %r11 adc $(0), %rdx add %rax, %r11 adc $(0), %rdx mov %rdx, %rcx movq (8)(%rbx), %rax mulq (24)(%rsi) add %rcx, %r12 adc $(0), %rdx add %rax, %r12 adc $(0), %rdx mov %rdx, %r13 neg %r9 mov %r9, %rcx mov %r9, %rbp xor %rax, %rax xor %rdx, %rdx shr $(32), %rbp shl $(32), %rcx sub %rcx, %rax sbb %rbp, %rdx sbb $(0), %rcx sbb $(0), %rbp neg %r9 adc %rax, %r10 adc %rdx, %r11 adc %rcx, %r12 adc %rbp, %r13 movq (16)(%rbx), %rax mulq (%rsi) add %rax, %r10 adc $(0), %rdx mov %rdx, %rcx movq (16)(%rbx), %rax mulq (8)(%rsi) add %rcx, %r11 adc $(0), %rdx add %rax, %r11 adc $(0), %rdx mov %rdx, %rcx movq (16)(%rbx), %rax mulq (16)(%rsi) add %rcx, %r12 adc $(0), %rdx add %rax, %r12 adc $(0), %rdx mov %rdx, %rcx movq (16)(%rbx), %rax mulq (24)(%rsi) add %rcx, %r13 adc $(0), %rdx add %rax, %r13 adc $(0), %rdx mov %rdx, %r14 neg %r10 mov %r10, %rcx mov %r10, %rbp xor %rax, %rax xor %rdx, %rdx shr $(32), %rbp shl $(32), %rcx sub %rcx, %rax sbb %rbp, %rdx sbb $(0), %rcx sbb $(0), %rbp neg %r10 adc %rax, %r11 adc %rdx, %r12 adc %rcx, %r13 adc %rbp, %r14 movq (24)(%rbx), %rax mulq (%rsi) add %rax, %r11 adc $(0), %rdx mov %rdx, %rcx movq (24)(%rbx), %rax mulq (8)(%rsi) add %rcx, %r12 adc $(0), %rdx add %rax, %r12 adc $(0), %rdx mov %rdx, %rcx movq (24)(%rbx), %rax mulq (16)(%rsi) add %rcx, %r13 adc $(0), %rdx add %rax, %r13 adc $(0), %rdx mov %rdx, %rcx movq (24)(%rbx), %rax mulq (24)(%rsi) add %rcx, %r14 adc $(0), %rdx add %rax, %r14 adc $(0), %rdx mov %rdx, %r15 neg %r11 mov %r11, %rcx mov %r11, %rbp xor %rax, %rax xor %rdx, %rdx shr $(32), %rbp shl $(32), %rcx sub %rcx, %rax sbb %rbp, %rdx sbb $(0), %rcx sbb $(0), %rbp neg %r11 adc %rax, %r12 adc %rdx, %r13 adc %rcx, %r14 adc %rbp, %r15 movq Lpoly+0(%rip), %rax movq Lpoly+8(%rip), %rdx movq Lpoly+16(%rip), %rcx movq Lpoly+24(%rip), %rbp mov %r12, %r8 mov %r13, %r9 mov %r14, %r10 mov %r15, %r11 sub %rax, %r12 sbb %rdx, %r13 sbb %rcx, %r14 sbb %rbp, %r15 cmovc %r8, %r12 cmovc %r9, %r13 cmovc %r10, %r14 cmovc %r11, %r15 movq %r12, (%rdi) movq %r13, (8)(%rdi) movq %r14, (16)(%rdi) movq %r15, (24)(%rdi) ret .p2align 5, 0x90 p224r1_mmulx: xor %r13, %r13 movq (%rbx), %rdx mulxq (%rsi), %r8, %r9 mulxq (8)(%rsi), %rcx, %r10 add %rcx, %r9 mulxq (16)(%rsi), %rcx, %r11 adc %rcx, %r10 mulxq (24)(%rsi), %rcx, %r12 adc %rcx, %r11 adc $(0), %r12 neg %r8 mov %r8, %rcx mov %r8, %rbp xor %rax, %rax xor %rdx, %rdx shr $(32), %rbp shl $(32), %rcx sub %rcx, %rax sbb %rbp, %rdx sbb $(0), %rcx sbb $(0), %rbp neg %r8 adc %rax, %r9 adc %rdx, %r10 adc %rcx, %r11 adc %rbp, %r12 movq (8)(%rbx), %rdx xor %rax, %rax mulxq (%rsi), %rcx, %rbp adcx %rcx, %r9 adox %rbp, %r10 mulxq (8)(%rsi), %rcx, %rbp adcx %rcx, %r10 adox %rbp, %r11 mulxq (16)(%rsi), %rcx, %rbp adcx %rcx, %r11 adox %rbp, %r12 mulxq (24)(%rsi), %rcx, %r13 adcx %rcx, %r12 adox %rax, %r13 adc $(0), %r13 neg %r9 mov %r9, %rcx mov %r9, %rbp xor %rax, %rax xor %rdx, %rdx shr $(32), %rbp shl $(32), %rcx sub %rcx, %rax sbb %rbp, %rdx sbb $(0), %rcx sbb $(0), %rbp neg %r9 adc %rax, %r10 adc %rdx, %r11 adc %rcx, %r12 adc %rbp, %r13 movq (16)(%rbx), %rdx xor %rax, %rax mulxq (%rsi), %rcx, %rbp adcx %rcx, %r10 adox %rbp, %r11 mulxq (8)(%rsi), %rcx, %rbp adcx %rcx, %r11 adox %rbp, %r12 mulxq (16)(%rsi), %rcx, %rbp adcx %rcx, %r12 adox %rbp, %r13 mulxq (24)(%rsi), %rcx, %r14 adcx %rcx, %r13 adox %rax, %r14 adc $(0), %r14 neg %r10 mov %r10, %rcx mov %r10, %rbp xor %rax, %rax xor %rdx, %rdx shr $(32), %rbp shl $(32), %rcx sub %rcx, %rax sbb %rbp, %rdx sbb $(0), %rcx sbb $(0), %rbp neg %r10 adc %rax, %r11 adc %rdx, %r12 adc %rcx, %r13 adc %rbp, %r14 movq (24)(%rbx), %rdx xor %rax, %rax mulxq (%rsi), %rcx, %rbp adcx %rcx, %r11 adox %rbp, %r12 mulxq (8)(%rsi), %rcx, %rbp adcx %rcx, %r12 adox %rbp, %r13 mulxq (16)(%rsi), %rcx, %rbp adcx %rcx, %r13 adox %rbp, %r14 mulxq (24)(%rsi), %rcx, %r15 adcx %rcx, %r14 adox %rax, %r15 adc $(0), %r15 neg %r11 mov %r11, %rcx mov %r11, %rbp xor %rax, %rax xor %rdx, %rdx shr $(32), %rbp shl $(32), %rcx sub %rcx, %rax sbb %rbp, %rdx sbb $(0), %rcx sbb $(0), %rbp neg %r11 adc %rax, %r12 adc %rdx, %r13 adc %rcx, %r14 adc %rbp, %r15 movq Lpoly+0(%rip), %rax movq Lpoly+8(%rip), %rdx movq Lpoly+16(%rip), %rcx movq Lpoly+24(%rip), %rbp mov %r12, %r8 mov %r13, %r9 mov %r14, %r10 mov %r15, %r11 sub %rax, %r12 sbb %rdx, %r13 sbb %rcx, %r14 sbb %rbp, %r15 cmovc %r8, %r12 cmovc %r9, %r13 cmovc %r10, %r14 cmovc %r11, %r15 movq %r12, (%rdi) movq %r13, (8)(%rdi) movq %r14, (16)(%rdi) movq %r15, (24)(%rdi) ret .globl _l9_p224r1_mul_montl _l9_p224r1_mul_montl: push %rbp push %rbx push %r12 push %r13 push %r14 push %r15 mov %rdx, %rbx call p224r1_mmull vzeroupper pop %r15 pop %r14 pop %r13 pop %r12 pop %rbx pop %rbp ret .p2align 5, 0x90 .globl _l9_p224r1_mul_montx _l9_p224r1_mul_montx: push %rbp push %rbx push %r12 push %r13 push %r14 push %r15 mov %rdx, %rbx call p224r1_mmulx vzeroupper pop %r15 pop %r14 pop %r13 pop %r12 pop %rbx pop %rbp ret .p2align 5, 0x90 .globl _l9_p224r1_to_mont _l9_p224r1_to_mont: push %rbp push %rbx push %r12 push %r13 push %r14 push %r15 lea LRR(%rip), %rbx call p224r1_mmull vzeroupper pop %r15 pop %r14 pop %r13 pop %r12 pop %rbx pop %rbp ret .p2align 5, 0x90 .globl _l9_p224r1_sqr_montl _l9_p224r1_sqr_montl: push %rbp push %rbx push %r12 push %r13 push %r14 push %r15 mov %rsi, %rbx call p224r1_mmull vzeroupper pop %r15 pop %r14 pop %r13 pop %r12 pop %rbx pop %rbp ret .p2align 5, 0x90 .globl _l9_p224r1_sqr_montx _l9_p224r1_sqr_montx: push %rbp push %rbx push %r12 push %r13 push %r14 push %r15 mov %rsi, %rbx call p224r1_mmulx vzeroupper pop %r15 pop %r14 pop %r13 pop %r12 pop %rbx pop %rbp ret .p2align 5, 0x90 .globl _l9_p224r1_mont_back _l9_p224r1_mont_back: push %r12 push %r13 push %r14 push %r15 movq (%rsi), %r8 movq (8)(%rsi), %r9 movq (16)(%rsi), %r10 movq (24)(%rsi), %r11 xor %r12, %r12 xor %r13, %r13 xor %r14, %r14 xor %r15, %r15 neg %r8 mov %r8, %rcx mov %r8, %rsi xor %rax, %rax xor %rdx, %rdx shr $(32), %rsi shl $(32), %rcx sub %rcx, %rax sbb %rsi, %rdx sbb $(0), %rcx sbb $(0), %rsi neg %r8 adc %rax, %r9 adc %rdx, %r10 adc %rcx, %r11 adc %rsi, %r12 neg %r9 mov %r9, %rcx mov %r9, %rsi xor %rax, %rax xor %rdx, %rdx shr $(32), %rsi shl $(32), %rcx sub %rcx, %rax sbb %rsi, %rdx sbb $(0), %rcx sbb $(0), %rsi neg %r9 adc %rax, %r10 adc %rdx, %r11 adc %rcx, %r12 adc %rsi, %r13 neg %r10 mov %r10, %rcx mov %r10, %rsi xor %rax, %rax xor %rdx, %rdx shr $(32), %rsi shl $(32), %rcx sub %rcx, %rax sbb %rsi, %rdx sbb $(0), %rcx sbb $(0), %rsi neg %r10 adc %rax, %r11 adc %rdx, %r12 adc %rcx, %r13 adc %rsi, %r14 neg %r11 mov %r11, %rcx mov %r11, %rsi xor %rax, %rax xor %rdx, %rdx shr $(32), %rsi shl $(32), %rcx sub %rcx, %rax sbb %rsi, %rdx sbb $(0), %rcx sbb $(0), %rsi neg %r11 adc %rax, %r12 adc %rdx, %r13 adc %rcx, %r14 adc %rsi, %r15 mov %r12, %r8 mov %r13, %r9 mov %r14, %r10 mov %r15, %r11 subq Lpoly+0(%rip), %r12 sbbq Lpoly+8(%rip), %r13 sbbq Lpoly+16(%rip), %r14 sbbq Lpoly+24(%rip), %r15 cmovc %r8, %r12 cmovc %r9, %r13 cmovc %r10, %r14 cmovc %r11, %r15 movq %r12, (%rdi) movq %r13, (8)(%rdi) movq %r14, (16)(%rdi) movq %r15, (24)(%rdi) vzeroupper pop %r15 pop %r14 pop %r13 pop %r12 ret .p2align 5, 0x90 .globl _l9_p224r1_select_pp_w5 _l9_p224r1_select_pp_w5: push %r12 push %r13 movdqa LOne(%rip), %xmm0 movdqa %xmm0, %xmm8 movd %edx, %xmm1 pshufd $(0), %xmm1, %xmm1 pxor %xmm2, %xmm2 pxor %xmm3, %xmm3 pxor %xmm4, %xmm4 pxor %xmm5, %xmm5 pxor %xmm6, %xmm6 pxor %xmm7, %xmm7 mov $(16), %rcx .Lselect_loop_sse_w5gas_13: movdqa %xmm8, %xmm15 pcmpeqd %xmm1, %xmm15 paddd %xmm0, %xmm8 movdqa (%rsi), %xmm9 movdqa (16)(%rsi), %xmm10 movdqa (32)(%rsi), %xmm11 movdqa (48)(%rsi), %xmm12 movdqa (64)(%rsi), %xmm13 movdqa (80)(%rsi), %xmm14 add $(96), %rsi pand %xmm15, %xmm9 pand %xmm15, %xmm10 pand %xmm15, %xmm11 pand %xmm15, %xmm12 pand %xmm15, %xmm13 pand %xmm15, %xmm14 por %xmm9, %xmm2 por %xmm10, %xmm3 por %xmm11, %xmm4 por %xmm12, %xmm5 por %xmm13, %xmm6 por %xmm14, %xmm7 dec %rcx jnz .Lselect_loop_sse_w5gas_13 movdqu %xmm2, (%rdi) movdqu %xmm3, (16)(%rdi) movdqu %xmm4, (32)(%rdi) movdqu %xmm5, (48)(%rdi) movdqu %xmm6, (64)(%rdi) movdqu %xmm7, (80)(%rdi) vzeroupper pop %r13 pop %r12 ret .p2align 5, 0x90 .globl _l9_p224r1_select_ap_w7 _l9_p224r1_select_ap_w7: push %r12 push %r13 movdqa LOne(%rip), %xmm0 pxor %xmm2, %xmm2 pxor %xmm3, %xmm3 pxor %xmm4, %xmm4 pxor %xmm5, %xmm5 movdqa %xmm0, %xmm8 movd %edx, %xmm1 pshufd $(0), %xmm1, %xmm1 mov $(64), %rcx .Lselect_loop_sse_w7gas_14: movdqa %xmm8, %xmm15 pcmpeqd %xmm1, %xmm15 paddd %xmm0, %xmm8 movdqa (%rsi), %xmm9 movdqa (16)(%rsi), %xmm10 movdqa (32)(%rsi), %xmm11 movdqa (48)(%rsi), %xmm12 add $(64), %rsi pand %xmm15, %xmm9 pand %xmm15, %xmm10 pand %xmm15, %xmm11 pand %xmm15, %xmm12 por %xmm9, %xmm2 por %xmm10, %xmm3 por %xmm11, %xmm4 por %xmm12, %xmm5 dec %rcx jnz .Lselect_loop_sse_w7gas_14 movdqu %xmm2, (%rdi) movdqu %xmm3, (16)(%rdi) movdqu %xmm4, (32)(%rdi) movdqu %xmm5, (48)(%rdi) vzeroupper pop %r13 pop %r12 ret
;====----------------------------------------------------------------------==== ; Microsoft Serial Compatible Mouse Driver (c)2001 Richard Fillion ; MSLogitech Driver Cell Distributed under BSD License ;====----------------------------------------------------------------------==== [bits 32] section .c_info version: db 0,0,1,'a' dd str_cellname dd str_author dd str_copyrights str_cellname: db "Microsoft Serial Mouse Driver",0 str_author: db "Richard Fillion (Raptor-32) - rick@rhix.dhs.org",0 str_copyrights: db "Distributed under BSD license.",0 section .c_init mov esi, incoming_data xor ebx, ebx mov bl, 0x60 ;baud rate divisor for 1200baud (serial mouse) mov bh, 0x00 xor eax, eax mov al, 1 ;com1 mov cl, 1 ;; externfunc com.enable_port TODO: BROKEN! Fix Me! DevFS enabled code!! section .text incoming_data: ;mouse data looks like this: ; 7 6 5 4 3 2 1 0 bits ; 0 1 LB RB Y7 Y6 X7 X6 ; 0 0 X5 X4 X3 X2 X1 X0 ; 0 0 Y5 Y4 Y3 Y2 Y1 Y0 ;byte is in AL, start by syncing driver with mouse movzx ebx, byte [sync] or ebx, 0 jnz .synced ;gotta sync it mov bl, al and bl, 01000000b jz near .not_first ;we have first byte, sync this puppy mov [byte_num], byte 1 mov [sync], byte 1 .synced: movzx ebx, byte [byte_num] cmp ebx, 2 jb .byte1 je near .byte2 .byte3: ;once 3rd byte is in, thats when you start doing major stuff ;al already = bits 0-5 of Y increment mov [byte_num], byte 1 cmp dword [client], -1 je .get_out mov bh, [byte_2] ;bh = bits 0-5 of X increment mov bl, [byte_1] ;we have buttons already, so all we need to worry about is: ;- bits 6,7 for bits 6 and 7 of Y increment ;- bits 4, 5 for bits 6 and 7 of X increment ;mouse data looks like this: ; 7 6 5 4 3 2 1 0 bits ; 0 1 LB RB Y7 Y6 X7 X6 bl ; 0 0 X5 X4 X3 X2 X1 X0 bh ; 0 0 Y5 Y4 Y3 Y2 Y1 Y0 al ;we will use ah for X and bl for Y mov ah, bl ;carbon copy of byte 1 and ah, 00000011b shl ah, 6 or ah, bh ; now AH is X and bl, 00001100b shl bl, 4 or bl, al ; now BL is Y movsx ecx, bl movsx ebx, al xor edx, edx movzx eax, byte [right_button] rol al, 1 and al, [left_button] call [client] .get_out: retn .byte1: mov [byte_1], al ;set the buttons so we can ignore that later mov bl, al ;check if it really is byte 1 and bl, 01000000b jz .not_synced mov bl, al mov cl, al and bl, 00100000b ;shr bl, 5 rol bl, 3 mov [left_button], byte bl and cl, 00010000b shr cl, 4 mov [right_button], cl inc byte [byte_num] retn .not_synced: mov [byte_num], byte 0 mov [sync], byte 0 retn .byte2: mov [byte_2], al mov [byte_num], byte 3 .not_first: retn ;===----[VARIABLES]-----=== right_button: db 0 left_button: db 0 byte_num: db 0 sync: db 0 byte_1: db 0 byte_2: db 0 byte_3: db 0 client: dd -1
; ; Z88 Graphics Functions ; ; Written around the Interlogic Standard Library ; ; $Id: getmaxy.asm,v 1.5 2017-01-02 21:51:24 aralbrec Exp $ ; INCLUDE "graphics/grafix.inc" SECTION code_clib PUBLIC getmaxy PUBLIC _getmaxy .getmaxy ._getmaxy ld hl,maxy-1 ret
XLIB pixeladdress INCLUDE "graphics/grafix.inc" XREF base_graphics ; ; $Id: pixladdr.asm,v 1.6 2002/04/17 21:30:25 dom Exp $ ; ; ****************************************************************** ; ; Get absolute pixel address in map of virtual (x,y) coordinate. ; ; TI Calculator version ; ; addr=base+12*y+int(x/8) ; .pixeladdress push bc ld a,h push af srl a srl a srl a ld c,a ; c=int(x/8) ;ld b,l ld h,0 ; TI 82, 83 and 83+ screens are 12 bytes wide IF FORti82 ld d,h ld e,l add hl,de add hl,de ENDIF IF FORti83 ld d,h ld e,l add hl,de add hl,de ENDIF IF FORti83p ld d,h ld e,l add hl,de add hl,de ENDIF ; TI 85 and TI86 screens are 16 bytes wide IF FORti85 add hl,hl add hl,hl ENDIF IF FORti86 add hl,hl add hl,hl ENDIF add hl,hl add hl,hl ld de,(base_graphics) add hl,de ld b,0 add hl,bc ld d,h ld e,l pop af pop bc and @00000111 ; a = x mod 8 xor @00000111 ; a = 7 - a ret
/* * Copyright (C) 2005-2020 Centre National d'Etudes Spatiales (CNES) * * This file is part of Orfeo Toolbox * * https://www.orfeo-toolbox.org/ * * 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. */ #ifndef otbBSplineDecompositionImageFilter_hxx #define otbBSplineDecompositionImageFilter_hxx #include "otbBSplineDecompositionImageFilter.h" #include "itkImageRegionConstIteratorWithIndex.h" #include "itkImageRegionIterator.h" #include "itkProgressReporter.h" #include "itkVector.h" namespace otb { /** * Constructor */ template <class TInputImage, class TOutputImage> BSplineDecompositionImageFilter<TInputImage, TOutputImage>::BSplineDecompositionImageFilter() { m_SplineOrder = 0; int SplineOrder = 3; m_Tolerance = 1e-10; // Need some guidance on this one...what is reasonable? m_IteratorDirection = 0; this->SetSplineOrder(SplineOrder); } /** * Standard "PrintSelf" method */ template <class TInputImage, class TOutputImage> void BSplineDecompositionImageFilter<TInputImage, TOutputImage>::PrintSelf(std::ostream& os, itk::Indent indent) const { Superclass::PrintSelf(os, indent); os << indent << "Spline Order: " << m_SplineOrder << std::endl; } template <class TInputImage, class TOutputImage> bool BSplineDecompositionImageFilter<TInputImage, TOutputImage>::DataToCoefficients1D() { // See Unser, 1993, Part II, Equation 2.5, // or Unser, 1999, Box 2. for an explanation. double c0 = 1.0; if (m_DataLength[m_IteratorDirection] == 1) // Required by mirror boundaries { return false; } // Compute overall gain for (int k = 0; k < m_NumberOfPoles; ++k) { // Note for cubic splines lambda = 6 c0 = c0 * (1.0 - m_SplinePoles[k]) * (1.0 - 1.0 / m_SplinePoles[k]); } // apply the gain for (unsigned int n = 0; n < m_DataLength[m_IteratorDirection]; ++n) { m_Scratch[n] *= c0; } // loop over all poles for (int k = 0; k < m_NumberOfPoles; ++k) { // causal initialization this->SetInitialCausalCoefficient(m_SplinePoles[k]); // causal recursion for (unsigned int n = 1; n < m_DataLength[m_IteratorDirection]; ++n) { m_Scratch[n] += m_SplinePoles[k] * m_Scratch[n - 1]; } // anticausal initialization this->SetInitialAntiCausalCoefficient(m_SplinePoles[k]); // anticausal recursion for (int n = m_DataLength[m_IteratorDirection] - 2; 0 <= n; n--) { m_Scratch[n] = m_SplinePoles[k] * (m_Scratch[n + 1] - m_Scratch[n]); } } return true; } template <class TInputImage, class TOutputImage> void BSplineDecompositionImageFilter<TInputImage, TOutputImage>::SetSplineOrder(unsigned int SplineOrder) { if (SplineOrder == m_SplineOrder) { return; } m_SplineOrder = SplineOrder; this->SetPoles(); this->Modified(); } template <class TInputImage, class TOutputImage> void BSplineDecompositionImageFilter<TInputImage, TOutputImage>::SetPoles() { /* See Unser, 1997. Part II, Table I for Pole values */ // See also, Handbook of Medical Imaging, Processing and Analysis, Ed. Isaac N. Bankman, // 2000, pg. 416. switch (m_SplineOrder) { case 3: m_NumberOfPoles = 1; m_SplinePoles[0] = std::sqrt(3.0) - 2.0; break; case 0: m_NumberOfPoles = 0; break; case 1: m_NumberOfPoles = 0; break; case 2: m_NumberOfPoles = 1; m_SplinePoles[0] = std::sqrt(8.0) - 3.0; break; case 4: m_NumberOfPoles = 2; m_SplinePoles[0] = std::sqrt(664.0 - std::sqrt(438976.0)) + std::sqrt(304.0) - 19.0; m_SplinePoles[1] = std::sqrt(664.0 + std::sqrt(438976.0)) - std::sqrt(304.0) - 19.0; break; case 5: m_NumberOfPoles = 2; m_SplinePoles[0] = std::sqrt(135.0 / 2.0 - std::sqrt(17745.0 / 4.0)) + std::sqrt(105.0 / 4.0) - 13.0 / 2.0; m_SplinePoles[1] = std::sqrt(135.0 / 2.0 + std::sqrt(17745.0 / 4.0)) - std::sqrt(105.0 / 4.0) - 13.0 / 2.0; break; default: // SplineOrder not implemented yet. itk::ExceptionObject err(__FILE__, __LINE__); err.SetLocation(ITK_LOCATION); err.SetDescription("SplineOrder must be between 0 and 5. Requested spline order has not been implemented yet."); throw err; break; } } template <class TInputImage, class TOutputImage> void BSplineDecompositionImageFilter<TInputImage, TOutputImage>::SetInitialCausalCoefficient(double z) { /* beginning InitialCausalCoefficient */ /* See Unser, 1999, Box 2 for explanation */ double sum, zn, z2n, iz; unsigned long horizon; /* this initialization corresponds to mirror boundaries */ horizon = m_DataLength[m_IteratorDirection]; zn = z; if (m_Tolerance > 0.0) { horizon = (long)std::ceil(log(m_Tolerance) / std::log(fabs(z))); } if (horizon < m_DataLength[m_IteratorDirection]) { /* accelerated loop */ sum = m_Scratch[0]; // verify this for (unsigned int n = 1; n < horizon; ++n) { sum += zn * m_Scratch[n]; zn *= z; } m_Scratch[0] = sum; } else { /* full loop */ iz = 1.0 / z; z2n = std::pow(z, (double)(m_DataLength[m_IteratorDirection] - 1L)); sum = m_Scratch[0] + z2n * m_Scratch[m_DataLength[m_IteratorDirection] - 1L]; z2n *= z2n * iz; for (unsigned int n = 1; n <= (m_DataLength[m_IteratorDirection] - 2); ++n) { sum += (zn + z2n) * m_Scratch[n]; zn *= z; z2n *= iz; } m_Scratch[0] = sum / (1.0 - zn * zn); } } template <class TInputImage, class TOutputImage> void BSplineDecompositionImageFilter<TInputImage, TOutputImage>::SetInitialAntiCausalCoefficient(double z) { // this initialization corresponds to mirror boundaries /* See Unser, 1999, Box 2 for explanation */ // Also see erratum at http://bigwww.epfl.ch/publications/unser9902.html m_Scratch[m_DataLength[m_IteratorDirection] - 1] = (z / (z * z - 1.0)) * (z * m_Scratch[m_DataLength[m_IteratorDirection] - 2] + m_Scratch[m_DataLength[m_IteratorDirection] - 1]); } template <class TInputImage, class TOutputImage> void BSplineDecompositionImageFilter<TInputImage, TOutputImage>::DataToCoefficientsND() { OutputImagePointer output = this->GetOutput(); itk::Size<ImageDimension> size = output->GetBufferedRegion().GetSize(); unsigned int count = output->GetBufferedRegion().GetNumberOfPixels() / size[0] * ImageDimension; itk::ProgressReporter progress(this, 0, count, 10); // Initialize coeffient array this->CopyImageToImage(); // Coefficients are initialized to the input data for (unsigned int n = 0; n < ImageDimension; ++n) { m_IteratorDirection = n; // Loop through each dimension // Initialize iterators OutputLinearIterator CIterator(output, output->GetBufferedRegion()); CIterator.SetDirection(m_IteratorDirection); // For each data vector while (!CIterator.IsAtEnd()) { // Copy coefficients to scratch this->CopyCoefficientsToScratch(CIterator); // Perform 1D BSpline calculations this->DataToCoefficients1D(); // Copy scratch back to coefficients. // Brings us back to the end of the line we were working on. CIterator.GoToBeginOfLine(); this->CopyScratchToCoefficients(CIterator); // m_Scratch = m_Image; CIterator.NextLine(); progress.CompletedPixel(); } } } /** * Copy the input image into the output image */ template <class TInputImage, class TOutputImage> void BSplineDecompositionImageFilter<TInputImage, TOutputImage>::CopyImageToImage() { typedef itk::ImageRegionConstIteratorWithIndex<TInputImage> InputIterator; typedef itk::ImageRegionIterator<TOutputImage> OutputIterator; typedef typename TOutputImage::PixelType OutputPixelType; InputIterator inIt(this->GetInput(), this->GetInput()->GetBufferedRegion()); OutputIterator outIt(this->GetOutput(), this->GetOutput()->GetBufferedRegion()); inIt.GoToBegin(); outIt.GoToBegin(); while (!outIt.IsAtEnd()) { outIt.Set(static_cast<OutputPixelType>(inIt.Get())); ++inIt; ++outIt; } } /** * Copy the scratch to one line of the output image */ template <class TInputImage, class TOutputImage> void BSplineDecompositionImageFilter<TInputImage, TOutputImage>::CopyScratchToCoefficients(OutputLinearIterator& Iter) { typedef typename TOutputImage::PixelType OutputPixelType; unsigned long j = 0; while (!Iter.IsAtEndOfLine()) { Iter.Set(static_cast<OutputPixelType>(m_Scratch[j])); ++Iter; ++j; } } /** * Copy one line of the output image to the scratch */ template <class TInputImage, class TOutputImage> void BSplineDecompositionImageFilter<TInputImage, TOutputImage>::CopyCoefficientsToScratch(OutputLinearIterator& Iter) { unsigned long j = 0; while (!Iter.IsAtEndOfLine()) { m_Scratch[j] = static_cast<double>(Iter.Get()); ++Iter; ++j; } } /** * Generate data */ template <class TInputImage, class TOutputImage> void BSplineDecompositionImageFilter<TInputImage, TOutputImage>::GenerateData() { // Allocate scratch memory InputImageConstPointer inputPtr = this->GetInput(); m_DataLength = inputPtr->GetBufferedRegion().GetSize(); unsigned long maxLength = 0; for (unsigned int n = 0; n < ImageDimension; ++n) { if (m_DataLength[n] > maxLength) { maxLength = m_DataLength[n]; } } m_Scratch.resize(maxLength); // Allocate memory for output image OutputImagePointer outputPtr = this->GetOutput(); outputPtr->SetBufferedRegion(outputPtr->GetRequestedRegion()); outputPtr->Allocate(); // Calculate actual output this->DataToCoefficientsND(); // Clean up m_Scratch.clear(); } } // namespace otb #endif
; A114240: a(n) = (n+1)(n+2)^2*(n+3)(7n^2 + 23n + 20)/240. ; Submitted by Christian Krause ; 1,15,94,380,1176,3038,6888,14148,26895,48037,81510,132496,207662,315420,466208,672792,950589,1318011,1796830,2412564,3194884,4178042,5401320,6909500,8753355,10990161,13684230,16907464,20739930,25270456 mov $3,2 mov $5,$0 lpb $3 mov $0,$5 sub $3,1 add $0,$3 trn $0,1 seq $0,107908 ; a(n) = (n+1)(n+2)^2*(n+3)^2*(n+4)(3n+5)/720. mov $2,$3 mul $2,$0 add $4,$2 lpe min $5,1 mul $5,$0 mov $0,$4 sub $0,$5
format PE console entry start include 'win32w.inc' include 'miscmacros.inc' include 'convert.inc' include 'parser.inc' include 'linkedlist.inc' include 'primitives.inc' MAXBUFFER = 512 section '.data' data readable writeable include 'variables.inc' theresult du '=> ',0 ;; WRONG ;str1 du '(progn (setq hello (lambda () (display "hello world")' ;du ' (hello)))' ;du ' (hello))',0 ;str1 du '(begin (setf factorial (lambda (x) (cond ((equal? x 1) 1)' ;du '(true (* x (factorial (- x 1))))))) (factorial 10))',0 ;; ERROR ;; OK ;str1 du '(begin (setf factorial (lambda (x y) (cond ((equal? x 1) y)' ;du '(true (factorial (- x 1) (* x y)))))) (factorial 5 1))',0 ;str1 du '(begin (setf factorial (lambda (x) (cond ((equal? x 1) 1)' ;du '(true (* (factorial (- x 1)) x))))) (factorial 5))',0 ;str1 du '(progn (setq 1+ (lambda (x) (+ x 1)) map (lambda (f x) (cond' ;du '((null? x) (quote ())) (true (cons (f (car x)) (map f' ;du ' (cdr x))))))) (map 1+ (quote (1 2 3))))',0 ;str1 du '(begin (setf factorial (lambda (x y) (cond ((equal? x 1) y)' ;du '(true (factorial (- x 1) (* x y)))))) (factorial 20 1))',0 ;str1 du '(/ 5 10 0 13)',0 ;; return overflow ;str1 du '(begin (setf factorial (lambda (x) (cond ((equal? x 1) 1)' ;du '(true (* (factorial (- x 1)) x))))) (factorial 40))',0 ;str1 du '(< 5 5.5 6 6.1 7)',0 ;str1 du '(< 5 5 6 6 7)',0 ;str1 du '(<= 5 5 6 6 7 )',0 ;str1 du '(< 5)',0 ; return argnum error ;str1 du '(string<? "helli" "hello")',0 ;str1 du '(string<=? "helli" "hello")',0 ;str1 du '(string>? "helli" "hello")',0 ;str1 du '(string>=? "helli" "hello")',0 ;str1 du '(string>=? "hello" "hello")',0 ;str1 du '(quasiquote hello)',0 ;str1 du '(quasiquote (quote hello))',0 ;str1 du '(quasiquote (unquote (+ 1 2)))',0 ;str1 du '(quasiquote (list (unquote (+ 1 2)) 4))',0 ;str1 du '((lambda (name) (quasiquote (list (unquote name) (quote ' ;du '(unquote name))))) (quote a))',0 str1 du "((lambda (name) `(list (unquote name) ',name)) 'a)",0 ;str1 du '(begin (setf map (lambda (f x) (cond ((null? x) (quote ())) (true ' ;du '(cons (f (car x)) (map f (cdr x))))))) (map abs (quote ' ;du '(4 -5 6))))',0 ;str1 du '(begin (setf map (lambda (f x) (cond ((null? x) (quote ())) (true ' ;du '(cons (f (car x)) (map f (cdr x))))))) (quasiquote (a (unquote ' ;du '(+ 1 2)) (unquote-splicing (map abs (quote (4 -5 6)))) b)))',0 ;str1 du '(quote (hello . world))',0 ;str1 du '(quasiquote ((foo (unquote (- 10 3))) (cons (unquote-splicing' ;du ' (cdr (quote (c)))) (unquote (car (quote (cons)))))))',0 ;str1 du '(quasiquote (cons (foo (unquote (- 10 3))) (cons (' ;du 'unquote-splicing (cdr (quote (c)))) (unquote (car (quote ' ;du ' (cons)))))))',0 ;str1 du '(cons (quote (foo 7)) (car (quote (cons))))',0 ;str1 du '(quasiquote ((foo (unquote (- 10 3))) (unquote-splicing (cdr ' ;du '(quote (c)))) . (unquote (car (quote (cons))))))',0 ;str1 du "`((foo ,(- 10 3) ,@(cdr '(c))) . (unquote (car '(cons))))",0 ;str1 du '(quasiquote (a (quasiquote (b (unquote (foo (unquote (+ 1 3)) d))' ;du ' e)) f))',0 ;str1 du '`(a `(b ,(foo ,(+ 1 3) d) e) f)',0 ;str1 du '(begin (setf map (lambda (f x) (cond ((null? x) (quote ()))' ;du ' (true (cons (f (car x)) (map f (cdr x))))))) ' ;du '(quasiquote (10 5 (unquote (sqrt 4)) (unquote-splicing (' ;du 'map sqrt (quote (16 9)))) 8)))',0 ;str1 du "(begin (setf map (lambda (f x) (cond ((null? x) '())" ;du " (true (cons (f (car x)) (map f (cdr x))))))) " ;du "`(10 5 ,(sqrt 4) ,@(map sqrt '(16 9)) 8))",0 ;str1 du '(quasiquote (quote hello-world))',0 ;str1 du "(quote (hello-world))",0 ;str1 du "'hello-world",0 ;str1 du "'(hello world)",0 ;str1 du "(quasiquote '(hello-world))",0 ;str1 du "'()",0 ;str1 du "(begin (set! greeting #t) (cond (greeting 'hello-world)" ;du " (true 'nice-day)))",0 ;str1 du "(begin (setf hello 'world) `(hello ,hello nice day))",0 ;str1 du "''hello",0 ;str1 du "''(hello)",0 ;str1 du "(begin (setf name 'andy) `'(,name))",0 ;str1 du "(quasiquote (quote (hello-world)))",0 ;str1 du "`'(hello-world)",0 ;str1 du "(quasiquote ((hello world)))",0 ;str1 du '`((hello world))',0 ;str1 du "(setq 'hello 'world)",0 ;str1 du "(+ '(hello) 4)",0 ;str1 du "(<= 5 'hello)",0 lenstr1 = $ - str1 section '.text' code readable executable start: initProgram .startloop: ; total 42 lines mov edi, [hBuffin] clearBuffer edi, MAXBUFFER writeIt prompt mov edx, 0 @@: mov esi, [hBuffin] lea esi, [esi+edx] invoke ReadConsoleW, [inhnd], esi, MAXBUFFER, numwrtn, 0 stdcall checkInput, esi invoke lstrlenW, edi lea eax, [eax*2] mov edx, eax cmp [numwrtn], 2 je @b cmp byte [aphostrophs], TRUE je @b cmp [parenthesis], 0 jl .invalid_expression jne @b stdcall normalizeInput, edi stdcall convertToQuote, edi invoke lstrlenW, edi lea eax, [eax*2] mov word [edi+eax-4], 0 ;cinvoke wsprintf, bufout, fmt, buffin ;writeLn [outhnd], bufout stdcall readExpression, edi mov ebx, eax stdcall eval, 0, eax, 0 checkNode eax ;stdcall removeNode, eax .to_finish: stdcall removeNode, ebx ;checkFUNSTACKTRACE ;cleanFUNSTACKTRACE jmp .startloop ;stdcall varlistLength, PRIMFUNTABLE ;checkItr eax ;checkItr lenstr1 ;stdcall checkInput, str1 ;cmp [parenthesis], 0 ;jne .invalid_expression ;stdcall normalizeInput, str1 ;stdcall convertToQuote, str1 ;writeLn str1 ;stdcall checkInput, str1 ;cmp [parenthesis], 0 ;jne .invalid_expression ;stdcall readExpression, str1 ;mov ebx, eax ;checkNode eax ;stdcall eval, 0, eax, 0 ;push eax ebx ;writeIt theresult ;pop ebx eax ;checkNode eax ;stdcall removeNode, eax ;.to_finish: ;stdcall removeNode, ebx ;checkFUNSTACKTRACE ; ;xor eax, eax ;jmp finish .invalid_expression: writeLn INVALID_EXPRESSION_ERRORtext mov eax, INVALID_EXPRESSION_ERROR jmp exit finish: push eax cleanupProgram pop eax exit: invoke ExitProcess, eax ret the_error\ no_binding_error, NO_BINDING_ERROR,\ argnum_error, ARGNUM_ERROR,\ type_error, TYPE_ERROR,\ stack_error, STACK_OVERFLOW_ERROR,\ zero_division_error, ZERO_DIVISION_ERROR,\ unimplemented_error, UNIMPLEMENTED_ERROR,\ overflow_error, OVERFLOW_ERROR proc initVarTable uses esi eax ebx ecx mov ebx, 0 mov ecx, VARTABLESIZE @@: lea esi, [VARTABLE+ebx] stdcall allocateVariable, NULL mov [esi], eax add ebx, 4 dec ecx jnz @b ret endp proc checkVARLIST uses esi edi eax ebx ecx edx, varlist locals colon du ':',0 endl mov esi, [varlist] cmp esi, 0 je .exit mov ebx, esi @@: mov eax, [esi+VARIABLESTRUCT.hVar] cmp eax, NULL je @f ; No variables list stdcall printNode, [outhnd], eax lea edi, [colon] writeIt edi ; Only protects protected-registers mov eax, [esi+VARIABLESTRUCT.hValue] cmp eax, 0 je .null_value stdcall printNode, [outhnd], eax .null_value: spacing [outhnd] .null_node: mov esi, [esi+VARIABLESTRUCT.next] ;pop esi cmp esi, NULL je @f cmp esi, ebx je @f jmp @b @@: newline .exit: ret endp proc checkVARTABLE uses esi edi eax ebx ecx mov ecx, VARTABLESIZE mov ebx, 0 .startloop: lea esi, [VARTABLE+ebx] mov esi, [esi] cmp esi, 0 je @f cmp [esi+VARIABLESTRUCT.hVar], NULL je @f stdcall checkVARLIST, esi @@: add ebx, 4 dec ecx jnz .startloop ;loop .startloop ret endp section '.idata' import data readable library kernel32, 'kernel32.dll',\ user32, 'user32.dll',\ msvcrt, 'msvcrt.dll' include 'api\kernel32.inc' include 'api\user32.inc' import msvcrt, wprintf, 'wprintf'
; A125119: Values of repunits with odd length L in base (L+3)/2 representation. ; Submitted by Christian Krause ; 1,13,341,19531,2015539,329554457,78536544841,25736391511831,11111111111111111,6115909044841454629,4182283628124518315101,3479492117784426363920483,3461445831219105624193478971 add $0,1 mov $2,1 mov $3,$0 sub $3,1 mul $3,4 lpb $3 mov $1,1 add $1,$2 mul $2,$0 add $2,$1 sub $3,2 lpe mov $0,$2
############################################################################### # Copyright 2018 Intel Corporation # All Rights Reserved. # # If this software was obtained under the Intel Simplified Software License, # the following terms apply: # # The source code, information and material ("Material") contained herein is # owned by Intel Corporation or its suppliers or licensors, and title to such # Material remains with Intel Corporation or its suppliers or licensors. The # Material contains proprietary information of Intel or its suppliers and # licensors. The Material is protected by worldwide copyright laws and treaty # provisions. No part of the Material may be used, copied, reproduced, # modified, published, uploaded, posted, transmitted, distributed or disclosed # in any way without Intel's prior express written permission. No license under # any patent, copyright or other intellectual property rights in the Material # is granted to or conferred upon you, either expressly, by implication, # inducement, estoppel or otherwise. Any license under such intellectual # property rights must be express and approved by Intel in writing. # # Unless otherwise agreed by Intel in writing, you may not remove or alter this # notice or any other notice embedded in Materials by Intel or Intel's # suppliers or licensors in any way. # # # If this software was obtained under the Apache License, Version 2.0 (the # "License"), the following terms apply: # # You may not use this file except in compliance with the License. You may # obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 # # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # # See the License for the specific language governing permissions and # limitations under the License. ############################################################################### .section .note.GNU-stack,"",%progbits .text .p2align 5, 0x90 ALPHA_MUL_CNT: .quad 0x87, 0x1 .p2align 5, 0x90 .globl cpAESEncryptXTS_AES_NI .type cpAESEncryptXTS_AES_NI, @function cpAESEncryptXTS_AES_NI: sub $(104), %rsp movslq %r8d, %r8 movdqu (%r9), %xmm15 shl $(4), %r8 movdqa (%rcx), %xmm0 movdqa ALPHA_MUL_CNT(%rip), %xmm8 pshufd $(95), %xmm15, %xmm9 movslq %edx, %rdx movdqa %xmm9, %xmm14 paddd %xmm9, %xmm9 movdqa %xmm15, %xmm10 psrad $(31), %xmm14 paddq %xmm15, %xmm15 pand %xmm8, %xmm14 pxor %xmm0, %xmm10 pxor %xmm14, %xmm15 movdqa %xmm9, %xmm14 paddd %xmm9, %xmm9 movdqa %xmm15, %xmm11 psrad $(31), %xmm14 paddq %xmm15, %xmm15 pand %xmm8, %xmm14 pxor %xmm0, %xmm11 pxor %xmm14, %xmm15 movdqa %xmm9, %xmm14 paddd %xmm9, %xmm9 movdqa %xmm15, %xmm12 psrad $(31), %xmm14 paddq %xmm15, %xmm15 pand %xmm8, %xmm14 pxor %xmm0, %xmm12 pxor %xmm14, %xmm15 movdqa %xmm9, %xmm14 paddd %xmm9, %xmm9 movdqa %xmm15, %xmm13 psrad $(31), %xmm14 paddq %xmm15, %xmm15 pand %xmm8, %xmm14 pxor %xmm0, %xmm13 pxor %xmm14, %xmm15 movdqa %xmm15, %xmm14 psrad $(31), %xmm9 paddq %xmm15, %xmm15 pand %xmm8, %xmm9 pxor %xmm0, %xmm14 pxor %xmm9, %xmm15 movdqa %xmm15, %xmm8 pxor %xmm0, %xmm15 sub $(6), %rdx jc .Lshort_inputgas_1 .p2align 5, 0x90 .Lblks_loopgas_1: pxor (%r8,%rcx), %xmm0 lea (-96)(%r8), %rax lea (16)(%rcx,%rax), %r10 neg %rax movdqu (%rsi), %xmm2 movdqu (16)(%rsi), %xmm3 movdqu (32)(%rsi), %xmm4 movdqu (48)(%rsi), %xmm5 movdqu (64)(%rsi), %xmm6 movdqu (80)(%rsi), %xmm7 movdqa (16)(%rcx), %xmm1 pxor %xmm10, %xmm2 pxor %xmm11, %xmm3 pxor %xmm12, %xmm4 pxor %xmm13, %xmm5 pxor %xmm14, %xmm6 pxor %xmm15, %xmm7 pxor %xmm0, %xmm10 pxor %xmm0, %xmm11 pxor %xmm0, %xmm12 pxor %xmm0, %xmm13 pxor %xmm0, %xmm14 pxor %xmm0, %xmm15 movdqa (32)(%rcx), %xmm0 movdqa %xmm10, (%rsp) movdqa %xmm11, (16)(%rsp) movdqa %xmm12, (32)(%rsp) movdqa %xmm13, (48)(%rsp) movdqa %xmm14, (64)(%rsp) movdqa %xmm15, (80)(%rsp) add $(96), %rsi .p2align 5, 0x90 .Lcipher_loopgas_1: add $(32), %rax aesenc %xmm1, %xmm2 aesenc %xmm1, %xmm3 aesenc %xmm1, %xmm4 aesenc %xmm1, %xmm5 aesenc %xmm1, %xmm6 aesenc %xmm1, %xmm7 movdqa (%r10,%rax), %xmm1 aesenc %xmm0, %xmm2 aesenc %xmm0, %xmm3 aesenc %xmm0, %xmm4 aesenc %xmm0, %xmm5 aesenc %xmm0, %xmm6 aesenc %xmm0, %xmm7 movdqa (16)(%r10,%rax), %xmm0 jnz .Lcipher_loopgas_1 movdqa (%rcx), %xmm10 movdqa %xmm8, %xmm15 pshufd $(95), %xmm8, %xmm9 movdqa ALPHA_MUL_CNT(%rip), %xmm8 aesenc %xmm1, %xmm2 aesenc %xmm1, %xmm3 aesenc %xmm1, %xmm4 aesenc %xmm1, %xmm5 aesenc %xmm1, %xmm6 aesenc %xmm1, %xmm7 movdqa (-48)(%r8,%rcx), %xmm1 movdqa %xmm9, %xmm14 paddd %xmm9, %xmm9 psrad $(31), %xmm14 paddq %xmm15, %xmm15 pand %xmm8, %xmm14 pxor %xmm14, %xmm15 movdqa %xmm10, %xmm11 pxor %xmm15, %xmm10 aesenc %xmm0, %xmm2 aesenc %xmm0, %xmm3 aesenc %xmm0, %xmm4 aesenc %xmm0, %xmm5 aesenc %xmm0, %xmm6 aesenc %xmm0, %xmm7 movdqa (-32)(%r8,%rcx), %xmm0 movdqa %xmm9, %xmm14 paddd %xmm9, %xmm9 psrad $(31), %xmm14 paddq %xmm15, %xmm15 pand %xmm8, %xmm14 pxor %xmm14, %xmm15 movdqa %xmm11, %xmm12 pxor %xmm15, %xmm11 aesenc %xmm1, %xmm2 aesenc %xmm1, %xmm3 aesenc %xmm1, %xmm4 aesenc %xmm1, %xmm5 aesenc %xmm1, %xmm6 aesenc %xmm1, %xmm7 movdqa (-16)(%r8,%rcx), %xmm1 movdqa %xmm9, %xmm14 paddd %xmm9, %xmm9 psrad $(31), %xmm14 paddq %xmm15, %xmm15 pand %xmm8, %xmm14 pxor %xmm14, %xmm15 movdqa %xmm12, %xmm13 pxor %xmm15, %xmm12 aesenc %xmm0, %xmm2 aesenc %xmm0, %xmm3 aesenc %xmm0, %xmm4 aesenc %xmm0, %xmm5 aesenc %xmm0, %xmm6 aesenc %xmm0, %xmm7 movdqa %xmm9, %xmm14 paddd %xmm9, %xmm9 psrad $(31), %xmm14 paddq %xmm15, %xmm15 pand %xmm8, %xmm14 pxor %xmm14, %xmm15 movdqa %xmm13, %xmm14 pxor %xmm15, %xmm13 aesenc %xmm1, %xmm2 aesenc %xmm1, %xmm3 aesenc %xmm1, %xmm4 aesenc %xmm1, %xmm5 aesenc %xmm1, %xmm6 aesenc %xmm1, %xmm7 movdqa %xmm9, %xmm0 paddd %xmm9, %xmm9 psrad $(31), %xmm0 paddq %xmm15, %xmm15 pand %xmm8, %xmm0 pxor %xmm0, %xmm15 movdqa %xmm14, %xmm0 pxor %xmm15, %xmm14 aesenclast (%rsp), %xmm2 aesenclast (16)(%rsp), %xmm3 aesenclast (32)(%rsp), %xmm4 aesenclast (48)(%rsp), %xmm5 aesenclast (64)(%rsp), %xmm6 aesenclast (80)(%rsp), %xmm7 psrad $(31), %xmm9 paddq %xmm15, %xmm15 pand %xmm8, %xmm9 pxor %xmm9, %xmm15 movdqa %xmm15, %xmm8 pxor %xmm0, %xmm15 movdqu %xmm2, (%rdi) movdqu %xmm3, (16)(%rdi) movdqu %xmm4, (32)(%rdi) movdqu %xmm5, (48)(%rdi) movdqu %xmm6, (64)(%rdi) movdqu %xmm7, (80)(%rdi) add $(96), %rdi sub $(6), %rdx jnc .Lblks_loopgas_1 .Lshort_inputgas_1: add $(6), %rdx jz .Lquitgas_1 movdqa %xmm10, (%rsp) movdqa %xmm11, (16)(%rsp) movdqa %xmm12, (32)(%rsp) movdqa %xmm13, (48)(%rsp) movdqa %xmm14, (64)(%rsp) movdqa %xmm15, (80)(%rsp) movdqa (%rcx), %xmm0 pxor (%r8,%rcx), %xmm0 lea (-144)(%r8,%rcx), %r10 xor %rax, %rax .Lsingle_blk_loopgas_1: movdqu (%rsi), %xmm2 movdqa (%rsp,%rax), %xmm1 add $(16), %rsi pxor %xmm1, %xmm2 pxor %xmm0, %xmm1 cmp $(192), %r8 jl .Lkey_128_sgas_1 .Lkey_256_sgas_1: aesenc (-64)(%r10), %xmm2 aesenc (-48)(%r10), %xmm2 aesenc (-32)(%r10), %xmm2 aesenc (-16)(%r10), %xmm2 .Lkey_128_sgas_1: aesenc (%r10), %xmm2 aesenc (16)(%r10), %xmm2 aesenc (32)(%r10), %xmm2 aesenc (48)(%r10), %xmm2 aesenc (64)(%r10), %xmm2 aesenc (80)(%r10), %xmm2 aesenc (96)(%r10), %xmm2 aesenc (112)(%r10), %xmm2 aesenc (128)(%r10), %xmm2 aesenclast %xmm1, %xmm2 movdqu %xmm2, (%rdi) add $(16), %rdi add $(16), %rax sub $(1), %rdx jnz .Lsingle_blk_loopgas_1 movdqa (%rsp,%rax), %xmm10 .Lquitgas_1: pxor (%rcx), %xmm10 movdqu %xmm10, (%r9) pxor %xmm1, %xmm1 add $(104), %rsp vzeroupper ret .Lfe1: .size cpAESEncryptXTS_AES_NI, .Lfe1-(cpAESEncryptXTS_AES_NI)
* Do dump V2.01  1987 Tony Tebby * section sdp * xdef sdp_do do screen dump xdef sdp_dosv do screen dump in supervisor mode * xref sdp_byte send byte xref sdp_sbuf send buffer xref sdp_ctrl send control sequence * include dev8_sys_sdp_data sdp_dosv move.l sp,dp_pstk(a5) ; save stack pointer sdp_do clr.w dp_bufpt(a5) ; clear buffer moveq #dp.pre,d0 ; set preamble bsr.l sdp_ctrl ; send control sequence bne.l dd_rts ; set start addresses move.l dp_stadd(a5),dp_raddr(a5) move.w dp_stpix(a5),dp_pxrrp(a5) ; and initial pointers and counters move.l dp_bainc(a5),a2 move.l dp_patt(a5),a4 move.w dp_mask(a5),d7 move.l dp_randi(a5),d4 move.w dp_nrows(a5),dp_rowc(a5) clr.w dp_ptrpt(a5) move.w dp_ptrnm(a5),dp_ptrct(a5) move.b dp_bitnw(a5),dp_bitwd(a5) move.b dp_bitlw(a5),dp_bitwe(a5) bra.s dd_rowlp page dd_nxrow ; Move to next row, skipping a bit at a time move.w dp_rbits(a5),dp_rbitc(a5); rbitc <- rbits dd_nxbit ; Move to next output bit, this could be a new row of ; the pattern or it could be a new pixel row. ; First we move to a new row of pattern, and if this ; exhausts the pattern, we reset the pointer and ; counter, then move to next pixel row move.w dp_ptrin(a5),d0 ; ptrpt <- ptrpt+ptrin add.w d0,dp_ptrpt(a5) subq.w #1,dp_ptrct(a5) ; ptrct <- ptrct-1 bgt.s dd_nxrlp ; more> nxrlp move.w dp_ptrnm(a5),dp_ptrct(a5); no more> ptrct <- ptrnm move.w dp_ptrsz(a5),d0 ; sub.w d0,dp_ptrpt(a5) ; ptrpt <- ptrpt-ptrsz ; pattern exhausted, move to next pixel move.w dp_pxrdc(a5),d0 ; pxrrp <- pxrrp-pxrdc sub.w d0,dp_pxrrp(a5) bge.s dd_nxrlp ; more> nxrlp ; pixels exhausted, move to next address move.l dp_rainc(a5),d0 ; no more> raddr <- raddr+rainc add.l d0,dp_raddr(a5) addq.w #8,dp_pxrrp(a5) ; pxrrp <- pxrrp+8 dd_nxrlp ; end of next row loop subq.w #1,dp_rbitc(a5) ; more bits? bgt.s dd_nxbit ; yes> nxbit dd_rowlp ; end of row loop subq.w #1,dp_rowc(a5) ; more rows? bgt.s dd_dorow ; yes> do row blt.s dd_done ; done> send epilogue dd_lstrw ; setup short? last row move.b dp_bitlr(a5),dp_bitwd(a5); bitwd <- bitlr move.b dp_bitlc(a5),dp_bitwe(a5); bitwe <- bitlc bra.s dd_dorow ; do row dd_done ; all done send epilogue moveq #dp.epi,d0 ; epilogue bsr.l sdp_ctrl ; send control sequence beq.l sdp_sbuf ; and buffer bra.s dd_rts dd_ok moveq #0,d0 ; set ok dd_rts rts ; return page dd_dorow ; Now we start the exciting business of doing one row ; this is one (or more) passes of the print head. ; For colour passes, the paper is not advanced ; for multipass, there may be a small increment moveq #dp.rpre,d0 ; row preamble bsr.l sdp_ctrl ; send control sequence bne.s dd_rts tst.w dp_ncolr(a5) ; colour? beq.s dr_strow ; no> strow clr.w dp_ptrpt(a5) ; yes> ptrpt <- 0 dr_clrrw ; do colour row moveq #dp.cpre,d0 ; colour preamble bsr.l sdp_ctrl ; send control sequence bne.s dd_rts dr_strow ; set the start of row pointers to the current values move.l dp_raddr(a5),dp_paddr(a5); paddr <- raddr set address move.w dp_pxrrp(a5),dp_pxprp(a5); pxprp <- pxrrp pixel move.w dp_ptrpt(a5),dp_ptppt(a5); ptppt <- ptrpt pattern move.w dp_ptrct(a5),dp_ptpct(a5); ptpct <- ptrct ... counter move.w dp_npass(a5),dp_passc(a5); passc <- npass number of passes dr_dopas ; do a pass moveq #dp.ppre,d0 ; pass preamble bsr.l sdp_ctrl ; send control sequence bne.s dd_rts move.b dp_bitwd(a5),dp_biten(a5); biten <- bitwd set bit move.l dp_paddr(a5),dp_waddr(a5); waddr <- paddr address move.l dp_waddr(a5),a1 ; baddr <- waddr move.w dp_pxprp(a5),dp_pxwrp(a5); pxwrp <- pxprp pixel move.w dp_pxwrp(a5),d3 ; pxbrp <- pxwrp move.w dp_ptppt(a5),dp_ptwpt(a5); ptwpt <- ptppt pattern move.w dp_ptwnm(a5),dp_ptwct(a5); ptwct <- ptwnm move.w dp_ptwpt(a5),d5 ; ptbpt <- ptwpt move.w dp_ptpct(a5),d6 ; ptbct <- ptpct unless tst.b dp_bitil(a5) ; inline? beq.s dp_dowrd ; no> do words move.w dp_ptbnm(a5),d6 ; yes> ptbct <- ptbnm dp_dowrd move.w dp_wrdrw(a5),dp_wrdct(a5); wrdct <- wrdrw word count bsr.s dd_dowrd ; do wrdct words bne.l dd_rts dr_endps ; end of pass moveq #dp.pepi,d0 ; pass epilogue bsr.l sdp_ctrl ; send control sequence bne.l dd_rts subq.w #1,dp_passc(a5) ; another pass? ble.s dr_endcl ; no> end of colour/row ; yes> nxtps dr_nxtps ; set up next pass move.w dp_ptpin(a5),d0 ; ptppt <- ptppt+ptpin add.w d0,dp_ptppt(a5) subq.w #1,dp_ptpct(a5) ; ptpct <- ptpct-1 bgt.s dr_dopas ; more> do another pass move.w dp_ptpnm(a5),dp_ptpct(a5); no more> ptpct <- ptpnm move.w dp_ptpsz(a5),d0 sub.w d0,dp_ptppt(a5) ; ptppt <- ptppt-ptpsz ; pattern exhausted, move to next pixel move.w dp_pxpdc(a5),d0 ; pxprp <- pxprp-pxpdc sub.w d0,dp_pxprp(a5) bge.l dr_dopas ; more> do another pass move.l dp_painc(a5),d0 ; no more> paddr <- paddr+painc add.l d0,dp_paddr(a5) addq.w #8,dp_pxprp(a5) ; pxprp <- pxprp+8 bra.l dr_dopas ; do another pass dr_endcl ; end of colour/row move.w dp_ncolr(a5),d2 ; colour? beq.s dr_endrw ; no> end of row moveq #dp.cepi,d0 ; yes> colour epilogue bsr.l sdp_ctrl ; send control sequence bne.l dd_rts addq.w #2,dp_ptrpt(a5) ; ptrpt <- ptrpt+2 next colour add.w d2,d2 cmp.w dp_ptrpt(a5),d2 ; last done? bgt.l dr_clrrw ; no> clrrw dr_endrw ; end of row moveq #dp.repi,d0 ; row epilog bsr.l sdp_ctrl ; send control sequence beq.l dd_nxrow ; done> next row bra.l dd_rts * page dd_dowrd ; Do wrdct words subq.w #1,dp_wrdct(a5) ; next word blt.l dd_ok ; done> return OK bgt.s dw_stwrd ; normal> setup move.b dp_bitwe(a5),dp_biten(a5); (short) final word dw_stwrd ; Set up to do word moveq #0,d1 ; outwd <- iniwd move.b dp_bitst(a5),d2 ; bitrp <- bitst dw_dopix ; Do one bit of a word move.w (a1),d0 ; pixel <- (baddr) lsr.w d3,d0 ; pixel <- pixel>>pxbrp......84......21 ror.w #2,d0 ; 21......84...... rol.b #2,d0 ; 21............84 rol.w #2,d0 ; ............8421 and.w d7,d0 ; 0000000000000401 or 0000000000008021 move.b dp_map(a5,d0.w),d0 ; pixel <- map(pixel) dw_dtbit ; add dot bit to word tst.l d4 ; random? bpl.s dw_dtpat ; ... no ; add random dot bit to word tst.b d0 ; zero? beq.s dw_nxbit ; yes> nxbit add.w #dp.randa,d4 ; no> randomise ror.w #dp.randr,d4 cmp.b d4,d0 ; value >= random? blo.s dw_nxbit ; no> nxbit bra.s dw_bchg ; outwd.bitrp <- ^outwd.bitrp dw_dtpat ; add pattern dot bit to word btst d0,(a4,d5.w) ; bit req? beq.s dw_nxbit ; no> nxbit dw_bchg ; change bit in word bchg d2,d1 ; outwd.bitrp <- ^outwd.bitrp dw_nxbit ; move to next bit in word cmp.b dp_biten(a5),d2 ; bitrp=biten? beq.s dw_wrwrd ; yes> write word add.b dp_bitin(a5),d2 ; bitrp <- bitrp+bitin dw_nxpat ; move to next bit of pattern add.w dp_ptbin(a5),d5 ; ptbpt <- ptbpt+ptbin subq.w #1,d6 ; ptbct <- ptbct-1 bgt.s dw_dtbit ; more> dtbit move.w dp_ptbnm(a5),d6 ; no more> ptbct <- ptbnm sub.w dp_ptbsz(a5),d5 ; ptbpt <- ptbpt-ptbsz ; Pattern exhausted, move to next pixel sub.w dp_pxbdc(a5),d3 ; pxbrp <- pxbrp-pxbdc bge.s dw_dopix ; more> do pixel add.w a2,a1 ; no more> baddr <- baddr+bainc addq.w #8,d3 ; pxbrp <- pxbrp+8 bra.s dw_dopix ; do pixel dw_wrwrd ; write word add.l dp_addwd(a5),d1 ; outwd <- outwd+addwd add odd bits move.w dp_nbwrd(a5),d2 ; bits <- nbwrd tst.b dp_msbyt(a5) ; byte order beq.s dw_wrlsb ; EQ ls byte first dw_wrmsb ; write bytes from msbyte rol.l #8,d1 ; rotate next byte in bsr.l sdp_byte ; send byte bne.l dd_rts subq.w #8,d2 ; bits <- bits-8 ble.s dw_nxwrd ; no more> next word bra.s dw_wrmsb ; write byte dw_wrlsb ; write bytes from lsbyte bsr.l sdp_byte ; send byte bne.l dd_rts subq.w #8,d2 ; bits <- bits-8 ble.s dw_nxwrd ; no more> next word ror.l #8,d1 ; rotate next byte in bra.s dw_wrlsb ; write byte dw_nxwrd ; move to next word tst.b dp_bitil(a5) ; in line? bne.s db_nxpat ; yes> move to next bit pattern ; move to pattern for next word move.w dp_ptwin(a5),d0 ; ptwpt <- ptwpt+ptwin add.w d0,dp_ptwpt(a5) subq.w #1,dp_ptwct(a5) ; ptwct <- ptwct-1 bgt.s dw_nxbad ; more> reset next bit address move.w dp_ptwnm(a5),dp_ptwct(a5); no more> ptwct <- ptwnm move.w dp_ptwsz(a5),d0 sub.w d0,dp_ptwpt(a5) ; ptwpt <- ptwpt-ptwsz dw_nxpix ; pattern exhausted, move to next pixel move.w dp_pxwdc(a5),d0 ; pxwrp <- pxwrp-pxwdc sub.w d0,dp_pxwrp(a5) bge.s dw_nxbpx ; more> set next bit pixel/address move.l dp_wainc(a5),d0 ; no more> waddr <- waddr+wainc add.l d0,dp_waddr(a5) addq.w #8,dp_pxwrp(a5) ; pxwrp <- pxwrp+8 dw_nxbpx ; set next bit pixel/address move.w dp_pxwrp(a5),d3 ; pxbrp <- pxwrp dw_nxbad move.l dp_waddr(a5),a1 ; baddr <- waddr dw_nxprp ; set next pattern running pointer move.w dp_ptwpt(a5),d5 ; ptbpt <- ptbpt move.w dp_ptpct(a5),d6 ; ptbct <- ptpct bra.l dd_dowrd ; do another word db_nxpat ; move to next bit of pattern add.w dp_ptbin(a5),d5 ; ptbpt <- ptbpt+ptbin subq.w #1,d6 ; ptbct <- ptbct-1 bgt.l dd_dowrd ; more> do next word move.w dp_ptbnm(a5),d6 ; no more> ptbct <- ptbnm sub.w dp_ptbsz(a5),d5 ; ptbpt <- ptbpt-ptbsz ; Pattern exhausted, move to next pixel sub.w dp_pxbdc(a5),d3 ; pxbrp <- pxbrp-pxbdc bge.l dd_dowrd ; more> do next word add.w a2,a1 ; no more> baddr <- baddr+bainc addq.w #8,d3 ; pxbrp <- pxbrp+8 bra.l dd_dowrd ; do next word end
;-------------------------------------------------------- ; File Created by SDCC : free open source ANSI-C Compiler ; Version 4.0.2 #11722 (Linux) ;-------------------------------------------------------- ; Processed by Z88DK ;-------------------------------------------------------- EXTERN __divschar EXTERN __divschar_callee EXTERN __divsint EXTERN __divsint_callee EXTERN __divslong EXTERN __divslong_callee EXTERN __divslonglong EXTERN __divslonglong_callee EXTERN __divsuchar EXTERN __divsuchar_callee EXTERN __divuchar EXTERN __divuchar_callee EXTERN __divuint EXTERN __divuint_callee EXTERN __divulong EXTERN __divulong_callee EXTERN __divulonglong EXTERN __divulonglong_callee EXTERN __divuschar EXTERN __divuschar_callee EXTERN __modschar EXTERN __modschar_callee EXTERN __modsint EXTERN __modsint_callee EXTERN __modslong EXTERN __modslong_callee EXTERN __modslonglong EXTERN __modslonglong_callee EXTERN __modsuchar EXTERN __modsuchar_callee EXTERN __moduchar EXTERN __moduchar_callee EXTERN __moduint EXTERN __moduint_callee EXTERN __modulong EXTERN __modulong_callee EXTERN __modulonglong EXTERN __modulonglong_callee EXTERN __moduschar EXTERN __moduschar_callee EXTERN __mulint EXTERN __mulint_callee EXTERN __mullong EXTERN __mullong_callee EXTERN __mullonglong EXTERN __mullonglong_callee EXTERN __mulschar EXTERN __mulschar_callee EXTERN __mulsuchar EXTERN __mulsuchar_callee EXTERN __muluschar EXTERN __muluschar_callee EXTERN __rlslonglong EXTERN __rlslonglong_callee EXTERN __rlulonglong EXTERN __rlulonglong_callee EXTERN __rrslonglong EXTERN __rrslonglong_callee EXTERN __rrulonglong EXTERN __rrulonglong_callee EXTERN ___sdcc_call_hl EXTERN ___sdcc_call_iy EXTERN ___sdcc_enter_ix EXTERN _banked_call EXTERN _banked_ret EXTERN ___fs2schar EXTERN ___fs2schar_callee EXTERN ___fs2sint EXTERN ___fs2sint_callee EXTERN ___fs2slong EXTERN ___fs2slong_callee EXTERN ___fs2slonglong EXTERN ___fs2slonglong_callee EXTERN ___fs2uchar EXTERN ___fs2uchar_callee EXTERN ___fs2uint EXTERN ___fs2uint_callee EXTERN ___fs2ulong EXTERN ___fs2ulong_callee EXTERN ___fs2ulonglong EXTERN ___fs2ulonglong_callee EXTERN ___fsadd EXTERN ___fsadd_callee EXTERN ___fsdiv EXTERN ___fsdiv_callee EXTERN ___fseq EXTERN ___fseq_callee EXTERN ___fsgt EXTERN ___fsgt_callee EXTERN ___fslt EXTERN ___fslt_callee EXTERN ___fsmul EXTERN ___fsmul_callee EXTERN ___fsneq EXTERN ___fsneq_callee EXTERN ___fssub EXTERN ___fssub_callee EXTERN ___schar2fs EXTERN ___schar2fs_callee EXTERN ___sint2fs EXTERN ___sint2fs_callee EXTERN ___slong2fs EXTERN ___slong2fs_callee EXTERN ___slonglong2fs EXTERN ___slonglong2fs_callee EXTERN ___uchar2fs EXTERN ___uchar2fs_callee EXTERN ___uint2fs EXTERN ___uint2fs_callee EXTERN ___ulong2fs EXTERN ___ulong2fs_callee EXTERN ___ulonglong2fs EXTERN ___ulonglong2fs_callee EXTERN ____sdcc_2_copy_src_mhl_dst_deix EXTERN ____sdcc_2_copy_src_mhl_dst_bcix EXTERN ____sdcc_4_copy_src_mhl_dst_deix EXTERN ____sdcc_4_copy_src_mhl_dst_bcix EXTERN ____sdcc_4_copy_src_mhl_dst_mbc EXTERN ____sdcc_4_ldi_nosave_bc EXTERN ____sdcc_4_ldi_save_bc EXTERN ____sdcc_4_push_hlix EXTERN ____sdcc_4_push_mhl EXTERN ____sdcc_lib_setmem_hl EXTERN ____sdcc_ll_add_de_bc_hl EXTERN ____sdcc_ll_add_de_bc_hlix EXTERN ____sdcc_ll_add_de_hlix_bc EXTERN ____sdcc_ll_add_de_hlix_bcix EXTERN ____sdcc_ll_add_deix_bc_hl EXTERN ____sdcc_ll_add_deix_hlix EXTERN ____sdcc_ll_add_hlix_bc_deix EXTERN ____sdcc_ll_add_hlix_deix_bc EXTERN ____sdcc_ll_add_hlix_deix_bcix EXTERN ____sdcc_ll_asr_hlix_a EXTERN ____sdcc_ll_asr_mbc_a EXTERN ____sdcc_ll_copy_src_de_dst_hlix EXTERN ____sdcc_ll_copy_src_de_dst_hlsp EXTERN ____sdcc_ll_copy_src_deix_dst_hl EXTERN ____sdcc_ll_copy_src_deix_dst_hlix EXTERN ____sdcc_ll_copy_src_deixm_dst_hlsp EXTERN ____sdcc_ll_copy_src_desp_dst_hlsp EXTERN ____sdcc_ll_copy_src_hl_dst_de EXTERN ____sdcc_ll_copy_src_hlsp_dst_de EXTERN ____sdcc_ll_copy_src_hlsp_dst_deixm EXTERN ____sdcc_ll_lsl_hlix_a EXTERN ____sdcc_ll_lsl_mbc_a EXTERN ____sdcc_ll_lsr_hlix_a EXTERN ____sdcc_ll_lsr_mbc_a EXTERN ____sdcc_ll_push_hlix EXTERN ____sdcc_ll_push_mhl EXTERN ____sdcc_ll_sub_de_bc_hl EXTERN ____sdcc_ll_sub_de_bc_hlix EXTERN ____sdcc_ll_sub_de_hlix_bc EXTERN ____sdcc_ll_sub_de_hlix_bcix EXTERN ____sdcc_ll_sub_deix_bc_hl EXTERN ____sdcc_ll_sub_deix_hlix EXTERN ____sdcc_ll_sub_hlix_bc_deix EXTERN ____sdcc_ll_sub_hlix_deix_bc EXTERN ____sdcc_ll_sub_hlix_deix_bcix EXTERN ____sdcc_load_debc_deix EXTERN ____sdcc_load_dehl_deix EXTERN ____sdcc_load_debc_mhl EXTERN ____sdcc_load_hlde_mhl EXTERN ____sdcc_store_dehl_bcix EXTERN ____sdcc_store_debc_hlix EXTERN ____sdcc_store_debc_mhl EXTERN ____sdcc_cpu_pop_ei EXTERN ____sdcc_cpu_pop_ei_jp EXTERN ____sdcc_cpu_push_di EXTERN ____sdcc_outi EXTERN ____sdcc_outi_128 EXTERN ____sdcc_outi_256 EXTERN ____sdcc_ldi EXTERN ____sdcc_ldi_128 EXTERN ____sdcc_ldi_256 EXTERN ____sdcc_4_copy_srcd_hlix_dst_deix EXTERN ____sdcc_4_and_src_mbc_mhl_dst_deix EXTERN ____sdcc_4_or_src_mbc_mhl_dst_deix EXTERN ____sdcc_4_xor_src_mbc_mhl_dst_deix EXTERN ____sdcc_4_or_src_dehl_dst_bcix EXTERN ____sdcc_4_xor_src_dehl_dst_bcix EXTERN ____sdcc_4_and_src_dehl_dst_bcix EXTERN ____sdcc_4_xor_src_mbc_mhl_dst_debc EXTERN ____sdcc_4_or_src_mbc_mhl_dst_debc EXTERN ____sdcc_4_and_src_mbc_mhl_dst_debc EXTERN ____sdcc_4_cpl_src_mhl_dst_debc EXTERN ____sdcc_4_xor_src_debc_mhl_dst_debc EXTERN ____sdcc_4_or_src_debc_mhl_dst_debc EXTERN ____sdcc_4_and_src_debc_mhl_dst_debc EXTERN ____sdcc_4_and_src_debc_hlix_dst_debc EXTERN ____sdcc_4_or_src_debc_hlix_dst_debc EXTERN ____sdcc_4_xor_src_debc_hlix_dst_debc ;-------------------------------------------------------- ; Public variables in this module ;-------------------------------------------------------- GLOBAL _am9511_cosh ;-------------------------------------------------------- ; Externals used ;-------------------------------------------------------- GLOBAL _hypot_callee GLOBAL _ldexp_callee GLOBAL _frexp_callee GLOBAL _sqrt_fastcall GLOBAL _sqr_fastcall GLOBAL _div2_fastcall GLOBAL _mul2_fastcall GLOBAL _am9511_modf GLOBAL _am9511_fmod GLOBAL _am9511_round GLOBAL _floor_fastcall GLOBAL _fabs_fastcall GLOBAL _ceil_fastcall GLOBAL _am9511_exp10 GLOBAL _am9511_exp2 GLOBAL _am9511_log2 GLOBAL _pow_callee GLOBAL _exp_fastcall GLOBAL _log10_fastcall GLOBAL _log_fastcall GLOBAL _am9511_atanh GLOBAL _am9511_acosh GLOBAL _am9511_asinh GLOBAL _am9511_tanh GLOBAL _am9511_sinh GLOBAL _am9511_atan2 GLOBAL _atan_fastcall GLOBAL _acos_fastcall GLOBAL _asin_fastcall GLOBAL _tan_fastcall GLOBAL _cos_fastcall GLOBAL _sin_fastcall GLOBAL _exp10_fastcall GLOBAL _exp10 GLOBAL _mul10u_fastcall GLOBAL _mul10u GLOBAL _mul2 GLOBAL _div2 GLOBAL _sqr GLOBAL _fam9511_f32_fastcall GLOBAL _fam9511_f32 GLOBAL _f32_fam9511_fastcall GLOBAL _f32_fam9511 GLOBAL _isunordered_callee GLOBAL _isunordered GLOBAL _islessgreater_callee GLOBAL _islessgreater GLOBAL _islessequal_callee GLOBAL _islessequal GLOBAL _isless_callee GLOBAL _isless GLOBAL _isgreaterequal_callee GLOBAL _isgreaterequal GLOBAL _isgreater_callee GLOBAL _isgreater GLOBAL _fma_callee GLOBAL _fma GLOBAL _fmin_callee GLOBAL _fmin GLOBAL _fmax_callee GLOBAL _fmax GLOBAL _fdim_callee GLOBAL _fdim GLOBAL _nexttoward_callee GLOBAL _nexttoward GLOBAL _nextafter_callee GLOBAL _nextafter GLOBAL _nan_fastcall GLOBAL _nan GLOBAL _copysign_callee GLOBAL _copysign GLOBAL _remquo_callee GLOBAL _remquo GLOBAL _remainder_callee GLOBAL _remainder GLOBAL _fmod_callee GLOBAL _fmod GLOBAL _modf_callee GLOBAL _modf GLOBAL _trunc_fastcall GLOBAL _trunc GLOBAL _lround_fastcall GLOBAL _lround GLOBAL _round_fastcall GLOBAL _round GLOBAL _lrint_fastcall GLOBAL _lrint GLOBAL _rint_fastcall GLOBAL _rint GLOBAL _nearbyint_fastcall GLOBAL _nearbyint GLOBAL _floor GLOBAL _ceil GLOBAL _tgamma_fastcall GLOBAL _tgamma GLOBAL _lgamma_fastcall GLOBAL _lgamma GLOBAL _erfc_fastcall GLOBAL _erfc GLOBAL _erf_fastcall GLOBAL _erf GLOBAL _cbrt_fastcall GLOBAL _cbrt GLOBAL _sqrt GLOBAL _pow GLOBAL _hypot GLOBAL _fabs GLOBAL _logb_fastcall GLOBAL _logb GLOBAL _log2_fastcall GLOBAL _log2 GLOBAL _log1p_fastcall GLOBAL _log1p GLOBAL _log10 GLOBAL _log GLOBAL _scalbln_callee GLOBAL _scalbln GLOBAL _scalbn_callee GLOBAL _scalbn GLOBAL _ldexp GLOBAL _ilogb_fastcall GLOBAL _ilogb GLOBAL _frexp GLOBAL _expm1_fastcall GLOBAL _expm1 GLOBAL _exp2_fastcall GLOBAL _exp2 GLOBAL _exp GLOBAL _tanh_fastcall GLOBAL _tanh GLOBAL _sinh_fastcall GLOBAL _sinh GLOBAL _cosh_fastcall GLOBAL _cosh GLOBAL _atanh_fastcall GLOBAL _atanh GLOBAL _asinh_fastcall GLOBAL _asinh GLOBAL _acosh_fastcall GLOBAL _acosh GLOBAL _tan GLOBAL _sin GLOBAL _cos GLOBAL _atan2_callee GLOBAL _atan2 GLOBAL _atan GLOBAL _asin GLOBAL _acos ;-------------------------------------------------------- ; special function registers ;-------------------------------------------------------- ;-------------------------------------------------------- ; ram data ;-------------------------------------------------------- SECTION bss_compiler ;-------------------------------------------------------- ; ram data ;-------------------------------------------------------- IF 0 ; .area _INITIALIZED removed by z88dk ENDIF ;-------------------------------------------------------- ; absolute external ram data ;-------------------------------------------------------- SECTION IGNORE ;-------------------------------------------------------- ; global & static initialisations ;-------------------------------------------------------- SECTION code_crt_init ;-------------------------------------------------------- ; Home ;-------------------------------------------------------- SECTION IGNORE ;-------------------------------------------------------- ; code ;-------------------------------------------------------- SECTION code_compiler ; --------------------------------- ; Function am9511_cosh ; --------------------------------- _am9511_cosh: push ix ld ix,0 add ix,sp push af push af call _exp_fastcall push hl ld c,l ld b,h push de push de push bc ld hl,0x3f80 push hl ld hl,0x0000 push hl call ___fsdiv_callee ld (ix-4),l ld (ix-3),h ld (ix-2),e ld (ix-1),d pop de pop bc ld l,(ix-2) ld h,(ix-1) push hl ld l,(ix-4) ld h,(ix-3) push hl push de push bc call ___fsadd_callee call _div2_fastcall ld sp, ix pop ix ret SECTION IGNORE
/* * FreeRTOS Kernel V10.1.0 * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of * the Software, and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * http://www.FreeRTOS.org * http://aws.amazon.com/freertos * * 1 tab == 4 spaces! */ #include "FreeRTOSConfig.h" #include "portasm.h" .CODE /* * The RTOS tick ISR. * * If the cooperative scheduler is in use this simply increments the tick * count. * * If the preemptive scheduler is in use a context switch can also occur. */ _vTickISR: portSAVE_CONTEXT call #_xTaskIncrementTick cmp.w #0x00, r15 jeq _SkipContextSwitch call #_vTaskSwitchContext _SkipContextSwitch: portRESTORE_CONTEXT /*-----------------------------------------------------------*/ /* * Manual context switch called by the portYIELD() macro. */ _vPortYield:: /* Mimic an interrupt by pushing the SR. */ push SR /* Now the SR is stacked we can disable interrupts. */ dint /* Save the context of the current task. */ portSAVE_CONTEXT /* Switch to the highest priority task that is ready to run. */ call #_vTaskSwitchContext /* Restore the context of the new task. */ portRESTORE_CONTEXT /*-----------------------------------------------------------*/ /* * Start off the scheduler by initialising the RTOS tick timer, then restoring * the context of the first task. */ _xPortStartScheduler:: /* Setup the hardware to generate the tick. Interrupts are disabled when this function is called. */ call #_prvSetupTimerInterrupt /* Restore the context of the first task that is going to run. */ portRESTORE_CONTEXT /*-----------------------------------------------------------*/ /* Place the tick ISR in the correct vector. */ .VECTORS .KEEP ORG TIMERA0_VECTOR DW _vTickISR END
object_const_def ; object_event constants const ROUTE43_SUPER_NERD1 const ROUTE43_SUPER_NERD2 const ROUTE43_SUPER_NERD3 const ROUTE43_FISHER const ROUTE43_LASS const ROUTE43_YOUNGSTER const ROUTE43_FRUIT_TREE const ROUTE43_POKE_BALL Route43_MapScripts: db 0 ; scene scripts db 1 ; callbacks callback MAPCALLBACK_NEWMAP, .CheckIfRockets .CheckIfRockets: checkevent EVENT_CLEARED_ROCKET_HIDEOUT iftrue .NoRockets setmapscene ROUTE_43_GATE, SCENE_DEFAULT return .NoRockets: setmapscene ROUTE_43_GATE, SCENE_FINISHED return TrainerCamperSpencer: trainer CAMPER, SPENCER, EVENT_BEAT_CAMPER_SPENCER, CamperSpencerSeenText, CamperSpencerBeatenText, 0, .Script .Script: endifjustbattled opentext writetext CamperSpencerAfterBattleText waitbutton closetext end TrainerPokemaniacBen: trainer POKEMANIAC, BEN, EVENT_BEAT_POKEMANIAC_BEN, PokemaniacBenSeenText, PokemaniacBenBeatenText, 0, .Script .Script: endifjustbattled opentext writetext PokemaniacBenAfterBattleText waitbutton closetext end TrainerPokemaniacBrent: trainer POKEMANIAC, BRENT1, EVENT_BEAT_POKEMANIAC_BRENT, PokemaniacBrentSeenText, PokemaniacBrentBeatenText, 0, .Script .Script: loadvar VAR_CALLERID, PHONE_POKEMANIAC_BRENT endifjustbattled opentext checkflag ENGINE_BRENT iftrue .WantsBattle checkcellnum PHONE_POKEMANIAC_BRENT iftrue .NumberAccepted checkevent EVENT_BRENT_ASKED_FOR_PHONE_NUMBER iftrue .AskedAlready writetext PokemaniacBrentAfterBattleText buttonsound setevent EVENT_BRENT_ASKED_FOR_PHONE_NUMBER scall .AskNumber1 sjump .AskForNumber .AskedAlready: scall .AskNumber2 .AskForNumber: askforphonenumber PHONE_POKEMANIAC_BRENT ifequal PHONE_CONTACTS_FULL, .PhoneFull ifequal PHONE_CONTACT_REFUSED, .NumberDeclined gettrainername STRING_BUFFER_3, POKEMANIAC, BRENT1 scall .RegisteredNumber sjump .NumberAccepted .WantsBattle: scall .Rematch winlosstext PokemaniacBrentBeatenText, 0 readmem wBrentFightCount ifequal 3, .Fight3 ifequal 2, .Fight2 ifequal 1, .Fight1 ifequal 0, .LoadFight0 .Fight3: checkevent EVENT_RESTORED_POWER_TO_KANTO iftrue .LoadFight3 .Fight2: checkevent EVENT_BEAT_ELITE_FOUR iftrue .LoadFight2 .Fight1: checkevent EVENT_CLEARED_ROCKET_HIDEOUT iftrue .LoadFight1 .LoadFight0: loadtrainer POKEMANIAC, BRENT1 startbattle reloadmapafterbattle loadmem wBrentFightCount, 1 clearflag ENGINE_BRENT end .LoadFight1: loadtrainer POKEMANIAC, BRENT2 startbattle reloadmapafterbattle loadmem wBrentFightCount, 2 clearflag ENGINE_BRENT end .LoadFight2: loadtrainer POKEMANIAC, BRENT3 startbattle reloadmapafterbattle loadmem wBrentFightCount, 3 clearflag ENGINE_BRENT end .LoadFight3: loadtrainer POKEMANIAC, BRENT4 startbattle reloadmapafterbattle clearflag ENGINE_BRENT end .AskNumber1: jumpstd asknumber1m end .AskNumber2: jumpstd asknumber2m end .RegisteredNumber: jumpstd registerednumberm end .NumberAccepted: jumpstd numberacceptedm end .NumberDeclined: jumpstd numberdeclinedm end .PhoneFull: jumpstd phonefullm end .Rematch: jumpstd rematchm end TrainerPokemaniacRon: trainer POKEMANIAC, RON, EVENT_BEAT_POKEMANIAC_RON, PokemaniacRonSeenText, PokemaniacRonBeatenText, 0, .Script .Script: endifjustbattled opentext writetext PokemaniacRonAfterBattleText waitbutton closetext end TrainerFisherMarvin: trainer FISHER, MARVIN, EVENT_BEAT_FISHER_MARVIN, FisherMarvinSeenText, FisherMarvinBeatenText, 0, .Script .Script: endifjustbattled opentext writetext FisherMarvinAfterBattleText waitbutton closetext end TrainerPicnickerTiffany: trainer PICNICKER, TIFFANY3, EVENT_BEAT_PICNICKER_TIFFANY, PicnickerTiffanySeenText, PicnickerTiffanyBeatenText, 0, .Script .Script: loadvar VAR_CALLERID, PHONE_PICNICKER_TIFFANY endifjustbattled opentext checkflag ENGINE_TIFFANY iftrue .WantsBattle checkflag ENGINE_TIFFANY_HAS_PINK_BOW iftrue .HasPinkBow checkcellnum PHONE_PICNICKER_TIFFANY iftrue .NumberAccepted checkpoke CLEFAIRY iffalse .NoClefairy checkevent EVENT_TIFFANY_ASKED_FOR_PHONE_NUMBER iftrue .AskedAlready writetext PicnickerTiffanyWantsPicnicText buttonsound setevent EVENT_TIFFANY_ASKED_FOR_PHONE_NUMBER scall .AskNumber1 sjump .AskForNumber .AskedAlready: scall .AskNumber2 .AskForNumber: askforphonenumber PHONE_PICNICKER_TIFFANY ifequal PHONE_CONTACTS_FULL, .PhoneFull ifequal PHONE_CONTACT_REFUSED, .NumberDeclined gettrainername STRING_BUFFER_3, PICNICKER, TIFFANY3 scall .RegisteredNumber sjump .NumberAccepted .WantsBattle: scall .Rematch winlosstext PicnickerTiffanyBeatenText, 0 readmem wTiffanyFightCount ifequal 3, .Fight3 ifequal 2, .Fight2 ifequal 1, .Fight1 ifequal 0, .LoadFight0 .Fight3: checkevent EVENT_RESTORED_POWER_TO_KANTO iftrue .LoadFight3 .Fight2: checkevent EVENT_BEAT_ELITE_FOUR iftrue .LoadFight2 .Fight1: ; checkevent EVENT_CLEARED_RADIO_TOWER ; iftrue .LoadFight1 .LoadFight0: loadtrainer PICNICKER, TIFFANY3 startbattle reloadmapafterbattle loadmem wTiffanyFightCount, 1 clearflag ENGINE_TIFFANY end .LoadFight1: loadtrainer PICNICKER, TIFFANY1 startbattle reloadmapafterbattle loadmem wTiffanyFightCount, 2 clearflag ENGINE_TIFFANY end .LoadFight2: loadtrainer PICNICKER, TIFFANY2 startbattle reloadmapafterbattle loadmem wTiffanyFightCount, 3 clearflag ENGINE_TIFFANY end .LoadFight3: loadtrainer PICNICKER, TIFFANY4 startbattle reloadmapafterbattle clearflag ENGINE_TIFFANY end .HasPinkBow: scall .Gift verbosegiveitem PINK_BOW iffalse .NoRoom clearflag ENGINE_TIFFANY_HAS_PINK_BOW setevent EVENT_TIFFANY_GAVE_PINK_BOW sjump .NumberAccepted .NoRoom: sjump .PackFull .NoClefairy: writetext PicnickerTiffanyClefairyText waitbutton closetext end .AskNumber1: jumpstd asknumber1f end .AskNumber2: jumpstd asknumber2f end .RegisteredNumber: jumpstd registerednumberf end .NumberAccepted: jumpstd numberacceptedf end .NumberDeclined: jumpstd numberdeclinedf end .PhoneFull: jumpstd phonefullf end .Rematch: jumpstd rematchf end .Gift: jumpstd giftf end .PackFull: jumpstd packfullf end Route43Sign1: jumptext Route43Sign1Text Route43Sign2: jumptext Route43Sign2Text Route43TrainerTips: jumptext Route43TrainerTipsText Route43FruitTree: fruittree FRUITTREE_ROUTE_43 Route43MaxEther: itemball MAX_ETHER PokemaniacBenSeenText: text "I love #MON!" para "That's why I" line "started--and why" para "I'll keep on col-" line "lecting #MON!" done PokemaniacBenBeatenText: text "How could you do" line "this to me?" done PokemaniacBenAfterBattleText: text "What else do I" line "like besides" cont "#MON?" para "MARY on the radio." line "I bet she's cute!" done PokemaniacBrentSeenText: text "Hey! Do you have" line "any rare #MON?" done PokemaniacBrentBeatenText: text "Oh, my poor #-" line "MON! Darlings!" done PokemaniacBrentAfterBattleText: text "I'd be happy just" line "to own a single" cont "rare #MON." done PokemaniacRonSeenText: text "Would you get" line "this?" para "Some <RIVAL> guy" line "made fun of my" cont "#MON!" para "Darn it! My #-" line "MON's great!" done PokemaniacRonBeatenText: text "My NIDOKING did" line "pretty right on!" done PokemaniacRonAfterBattleText: text "It's okay for" line "people to like" para "different types" line "of #MON." para "#MON isn't just" line "about having the" cont "most powerful one." done FisherMarvinSeenText: text "I'm in a slump." para "Maybe it's the" line "gear I'm using." para "Let's battle for a" line "change of pace!" done FisherMarvinBeatenText: text "I lost, but I feel" line "better anyway." done FisherMarvinAfterBattleText: text "KURT's LURE BALL" line "is the best for" para "catching hooked" line "#MON." para "It's much more" line "effective than a" cont "ULTRA BALL." done CamperSpencerSeenText: text "I can do so much" line "with my #MON--" cont "it's super-fun!" done CamperSpencerBeatenText: text "Losing isn't fun" line "at all…" done CamperSpencerAfterBattleText: text "What is going on" line "at LAKE OF RAGE?" para "We were planning" line "to camp there." done PicnickerTiffanySeenText: text "Are you going to" line "LAKE OF RAGE too?" para "Let's play for a " line "little while!" done PicnickerTiffanyBeatenText: text "I played too much!" done PicnickerTiffanyWantsPicnicText: text "I'm having a pic-" line "nic with #MON." para "Won't you join us?" done PicnickerTiffanyClefairyText: text "Isn't my CLEFAIRY" line "just the most" cont "adorable thing?" done Route43Sign1Text: text "ROUTE 43" para "LAKE OF RAGE -" line "MAHOGANY TOWN" done Route43Sign2Text: text "ROUTE 43" para "LAKE OF RAGE -" line "MAHOGANY TOWN" done Route43TrainerTipsText: text "TRAINER TIPS" para "All #MON have" line "pros and cons" para "depending on their" line "types." para "If their types" line "differ, a higher-" para "level #MON may" line "lose in battle." para "Learn which types" line "are strong and" para "weak against your" line "#MON's type." done Route43_MapEvents: db 0, 0 ; filler db 5 ; warp events warp_event 9, 51, ROUTE_43_MAHOGANY_GATE, 1 warp_event 10, 51, ROUTE_43_MAHOGANY_GATE, 2 warp_event 17, 35, ROUTE_43_GATE, 3 warp_event 17, 31, ROUTE_43_GATE, 1 warp_event 18, 31, ROUTE_43_GATE, 2 db 0 ; coord events db 3 ; bg events bg_event 13, 3, BGEVENT_READ, Route43Sign1 bg_event 11, 49, BGEVENT_READ, Route43Sign2 bg_event 16, 38, BGEVENT_READ, Route43TrainerTips db 8 ; object events object_event 13, 5, SPRITE_SUPER_NERD, SPRITEMOVEDATA_STANDING_LEFT, 0, 0, -1, -1, PAL_NPC_BLUE, OBJECTTYPE_TRAINER, 2, TrainerPokemaniacBen, -1 object_event 13, 20, SPRITE_SUPER_NERD, SPRITEMOVEDATA_SPINRANDOM_FAST, 0, 0, -1, -1, PAL_NPC_BLUE, OBJECTTYPE_TRAINER, 3, TrainerPokemaniacBrent, -1 object_event 14, 7, SPRITE_SUPER_NERD, SPRITEMOVEDATA_STANDING_DOWN, 0, 0, -1, -1, PAL_NPC_BLUE, OBJECTTYPE_TRAINER, 2, TrainerPokemaniacRon, -1 object_event 4, 16, SPRITE_FISHER, SPRITEMOVEDATA_STANDING_RIGHT, 0, 0, -1, -1, PAL_NPC_GREEN, OBJECTTYPE_TRAINER, 4, TrainerFisherMarvin, -1 object_event 9, 25, SPRITE_LASS, SPRITEMOVEDATA_STANDING_DOWN, 0, 0, -1, -1, PAL_NPC_GREEN, OBJECTTYPE_TRAINER, 2, TrainerPicnickerTiffany, -1 object_event 13, 40, SPRITE_YOUNGSTER, SPRITEMOVEDATA_SPINRANDOM_FAST, 0, 0, -1, -1, PAL_NPC_GREEN, OBJECTTYPE_TRAINER, 3, TrainerCamperSpencer, -1 object_event 1, 26, SPRITE_FRUIT_TREE, SPRITEMOVEDATA_STILL, 0, 0, -1, -1, 0, OBJECTTYPE_SCRIPT, 0, Route43FruitTree, -1 object_event 12, 32, SPRITE_POKE_BALL, SPRITEMOVEDATA_STILL, 0, 0, -1, -1, 0, OBJECTTYPE_ITEMBALL, 0, Route43MaxEther, EVENT_ROUTE_43_MAX_ETHER
/* This function takes last element as pivot, places the pivot element at its correct position in sorted array, and places all smaller (smaller than pivot) to left of pivot and all greater elements to right of pivot */ int partition (int arr[], int l, int h) { int x = arr[h]; int i = (l - 1); for (int j = l; j <= h- 1; j++) { if (arr[j] <= x) { i++; swap (&arr[i], &arr[j]); } } swap (&arr[i + 1], &arr[h]); return (i + 1); } /* A[] --> Array to be sorted, l --> Starting index, h --> Ending index */ void quickSort(int A[], int l, int h) { if (l < h) { int p = partition(A, l, h); /* Partitioning index */ quickSort(A, l, p - 1); quickSort(A, p + 1, h); } } http://www.geeksforgeeks.org/iterative-quick-sort/ On DLL http://www.geeksforgeeks.org/quicksort-for-linked-list/ ON SLL http://www.geeksforgeeks.org/quicksort-on-singly-linked-list/
varAxis1 DW 0 ; address of first axis in a rotation action varAxis2 DW 0 ; address of 2nd axis in a roation action ; Variables to simulate 6502 registers until code fixed ; These must be here in this order as reading Y and X can then be a 16 bit read regX DB 0 ; using 16 bit read into BC this would go into C regY DB 0 ; using 16 bit read into BC this would go into B regA DB 0 varGPLoopA DB 0 ; General Purpose innermost loop variable INF DW 0 ; page 0 &20 Used to get address from UNIV array INF28 DW 0 ; page 0 &20 Used to get address from UNIV array ;XX16 DS 16 ; 16 byte Matrix P0INWK ; page 0 & 46 p0INWK31 ; page 0 & 65 P0INWK36 ; PAGE 0 &6A XX4 DB 0 ; XX4 page 0 &96 last Normal Found to be visible LastNormalVisible equ XX4 varXX4 equ XX4 PATG DB 0 ; 6502 &03C9 SLSP DW 0 ; &03B0 \ SLSP \ ship lines pointer ;UNIV DS FreeListSize*2 ; Array of Universe Pointers ;HULLINDEX DS ShipTypeSize*2 ; hull index for table at XX21= &5600 XX21-1,Y ; Present System Variables RandomSeed DB 43 ; 00 DEBUG JUST SOME START VALUES RandomSeed1 DB 32 ; 01 RandomSeed2 DB 12 ; 02 RandomSeed3 DB 66 ; 03 RandomSeedSave DS 4 ; used in explosion routine to save randoms varT1 DB 0 ; 06 SClo DB 0 ; 07 SChi DB 0 ; 08 varP DB 0 ; 10 XX16+7 varPhi DB 0 ; 11 XX16+8 varPhi2 DB 0 ; 12 XX16+9 varPp1 equ varPhi varPp2 equ varPhi2 UnivPointerLo DB 0 ; 20 INF XX0+2 UnivPointerHi DB 0 ; 21 INF+1 XX0+3 UnivPointer equ UnivPointerLo varV DB 0 ; 22 XX0+4 varVHi DB 0 ; 23 XX0+5 varXXlo DB 0 ; 24 varXXHi DB 0 ; 25 varXX equ varXXlo YYlo DB 0 ; 26 YYHi DB 0 ; 27 varYY equ YYlo ; 28 ; 29 ;PlayerShipPositionData - Must be contiguous for setup BETA DB 0 ; 2A (pitch done) JSTY DB 0 ; Joystick analog BET1 DB 0 ; 2B lower7 magnitude BET2 DB 0 ; climb sign BET2FLIP DB 0 ; 7C BET 2 pitch Sign negated BET1MAXC DB 31 ; max climb BET1MAXD DB -31 ; max dive XC DB 0 ; 2C YC DB 0 ; 2D ;... ECM logic. If another ship adds ECM then we just set the loop A and B to starting values so they overlap ECMActive DB 0 ; 30 ECM Active flag ECMLoopA DB 0 ECMLoopB DB 0 JSTX DW 0 ; Joystick analog value ALPHA DB 0 ; 8D Alpha with bit 7 sign ALP1 DB 0 ; 31 ALP1 Roll magnitude Also Apha ALP2 DB 0 ; 32 ALP2 Roll Sign ALP2FLIP DB 0 ; 33 ALP2 negated roll sign ALP1MAXR DB 31 ; Maximum roll, added becuase we may allow different ship types ALP1MAXL DB -31 ; Maximum roll, added becuase we may allow different ship types MAXMESSAGES EQU 5 MESSAGETIMELIMIT EQU 20 MESSAGESIZE EQU 33 MESSAGELINE EQU $0001 MessageCount DB 0 ; used for enquing messages later MessageCurrent DB 0 MessageIndex DW MAXMESSAGES MessageQueue DS MAXMESSAGES * MESSAGESIZE MessageTimeout DB MAXMESSAGES IndexedWork DS 37 ; General purpose work space when doing temp arrays ; MOVED TO Universe XX19 DB 0 ; page 0 &67 ; MOVED TO Universe XX20 DB 0 ; page 0 &67 also used as XX19+1 for XX19 being a word ;DEFUNCT EQUATE NormalCountCopyBy4 equ XX20 ; Also used for normal * 4 holding variable XX21 DB 0 ; this may be part of XX20/xx21 accordign to spawn new shipXX21 DW 0 ; Ah XX21 is hull pointer hull pointer lo as it can;t hold HULLINDX as 16bit array ;XX21 is the pointer table to the pages for ship types. this will be repalaced by paging so just need an equate for first page SystemSeed DS 5 ; 6C QQ15 Current Galaxy Seed ; 6D QQ15+1 ; 6E QQ15+2 ; 6F QQ15+3 ; 70 QQ15+4 ; 71 QQ15+5 QQ17 DB 0 ; 72 XX18xlo DB 0 ; 72 XX18 xlo XX18xhi DB 0 ; 73 XX18+1 xhi XX18xsg DB 0 ; 74 XX18+2 xsgn XX18ylo DB 0 ; 75 XX18 ylo XX18yhi DB 0 ; 76 XX18+1 yhi XX18ysg DB 0 ; 77 XX18+2 ysgn XX18zlo DB 0 ; 78 XX18 zlo XX18zhi DB 0 ; 79 XX18+1 zhi XX18zsg DB 0 ; 7A XX18+2 zsgn SHIPMAXSPEED DB 40 ; variable to facilitate ship editing later DELTA DB 0 ; 7D DELTA \ bpl -2 inserted here to stall from title code if byte check fails DELT4Lo DB 0 ; 7E DELT4Hi DB 0 ; 7F DELTA4 equ DELT4Lo ; Not thise must be in this order else 16 bit fetches will fail varU DB 0 ; 80 varQ DB 0 ; 81 varR DB 0 ; 82 varS DB 0 ; 83 varRS equ varR varU16 DW 0 ; 16 bit variant on varU as I can't use above for this XSAV DB 0 ; 84 XSAV usef for nearby ship count outer YSAV DB 0 ; 85 XX17 DB 0 ; 86 RequiredScale equ XX17 ; use to hold calculated scale in drawing ship varXX17 equ XX17 ScreenChanged DB 0 ScreenIndex DB 0 InvertedYAxis DB 0 MenuIdMax DB 0 ; 87 MenuIdMax QQ11 ; Bit 7 Set ShortRangeChart $80 ; Bit 6 Set Galactic Chart $40 ; Bit 5 Set Market Place $20 ; Bit 4 Set Status Screen $10 ; Bit 3 Set Display Inventory $08 ; Bit 2 Set Planet Data $04 ; View bit combinations if the ones above not matched ; bits 1 0 ; 1 1 Front view , i.e. $03 ; 1 0 Aft View $02 ; 0 1 Left View $01 ; 0 0 Right view $00 ; Bit 0 Set Data On System ; 0 Space View (Not a menu) ZZDust DB 0 ; 88 ZZDust (Poss 16 bit need to check) XX13 DB 0 ; 89 TYPE DB 0 ; 8C used for ship type in drawing ;Docked flag = 00 = in free space ; FF = Docked ; FE = transition ; FD = Setup open space and transition to not docked ; FC = Hyperspace manimation ; FB = Hyperspace complete DockedFlag DB 0 ; 8E - GamePaused DB 0 varSWAP DB 0 ; 90 , general purpose swap variable varCNT DB 0 ; 93 varK DB 0 ; 40 varKp1 DB 0 ; 41 varKp2 DB 0 ; 42 varKp3 DB 0 ; 43 varK2 DB 0 ; 9B varK2p1 DB 0 ; 9C K2 plus 1 varK2p2 DB 0 ; 9D K2 plus 2 varK2p3 DB 0 ; 9E K2 plus 3 Point DB 0 ; 9F POINT varT DB 0 ; D1 varVector9ByteWork DS 9 varK3 DS 4 ; D2 varK3p2 DB 0 ; 42 varK3p3 DB 0 ; 43 varK3p1 equ varK3+1 ; D3 varK4 DS 4 ; E0 varK4p1 equ varK4+1 ; D3 ;Heap HeapStart DS 2 ; &0100 XX3 50 bytes for now HeapData DS 50 ; Contains X 16 bit, Y ;MissileArmedStatus DB 0 ; 0344 MSAR using MissileTarget, if missile is not armed tehn target is FF ; TODO will need an read for a list of missiles, who they are targeting an the target current vector for AI persuit ; i.e. a list of programmed missiles in universe slot list code DampingKeys DS 7 ; 0387 - 038D ; #&6 Does K toggle keyboard/joystick control - 03CD certainly makes keyboard not work anymore. ; #&5 Does J reverse both joystick channels ; #&4 Does Y reverse joystick Y channel 03CB ; #&2 Does X toggle startup message display ? PATG? 03C9 ; #&3 Does F toggle flashing information 03CA ; #&1 Does A toggle keyboard auto-recentering ? ; #&0 Caps-lock toggles keyboard flight damping NbrMissiles DB 0 ; 038B Does this clash with Dampingkeys? FugitiveInnocentStatus DB 0 ; 038C FIST StockAvaliabiliy DS 16 ; 038D - 039C Stock inventory in station AlienItemsAvaliability DB 0 ; 039D RandomMarketSeed DB 0 ; 039E \ QQ26 \ random byte for each system vist (for market) KillTally DW 0 ; 039F - 03A0 \ TALLY \ kills lo hi COMP DB 0 ; 03A1 2nd competion byte used for save integrity checks? ; MCH DB 0 ; 03A4 \ MCH \ old message to erase MarketPrice DB 0 ; 03AA QQ24 MaxStockAvaliable DB 0 ; 03AB \ QQ25 \ max available SystemEconomy DB 0 ; 03AC \ QQ28 \ the economy byte of present system (0 is Rich Ind.) CargoItem DB 0 ; 03AD (I think its item type just scooped) QQ29 ShipLineStackPointer DW 0 ; 03B0 & 03B1 ship Lines pointer reset to top LS% = &0CFF (make DW for z80 and direct hl pointer) ; this is ship lines stack pointer so may be redundant with paging ; LS = line stack so we will have one for now to remove later COK DB 0 ; 0366 Competition Byte what ? Does some file check and accelleration check DisplayEcononmy DB 0 ; 03B8 DisplayGovernment DB 0 ; 03B9 Is it target? 03B9 \ QQ4 \ Government, 0 is Anarchy. DisplayTekLevel DB 0 ; 03BA \ QQ5 \ Tech DisplayPopulation DW 0 ; 03BB \ QQ6 \ population*10 DisplayProductivity DW 0 ; 03BD \ QQ7 \ productivity*10 Distance DW 0 ; 03BE \ QQ8 distince in 0.1LY units DisplayRadius DW 0 ; --- Used in creation of sun and planet----; PlanetXPos DS 1 PlanetYPos DS 1 PlanetZPos DS 1 PlanetType DS 1 SunXPos DS 1 SunYPos DS 1 SunZPos DS 1 ; -- Current Missile Runbtime data CurrentMissileBank: DB 0 ; used by missile logic as local copy of missile bank number MissileXPos DW 0 MissileXSgn DB 0 MissileYPos DW 0 MissileYSgn DB 0 MissileZPos DW 0 MissileZSgn DB 0 CurrentTargetXpos DS 2 CurrentTargetXsgn DS 2 CurrentTargetYpos DS 2 CurrentTargetYsgn DS 2 CurrentTargetZpos DS 2 CurrentTargetZsgn DS 2 TargetVectorXpos DS 2 TargetVectorXsgn DS 2 TargetVectorYpos DS 2 TargetVectorYsgn DS 2 TargetVectorZpos DS 2 TargetVectorZsgn DS 2 CurrentMissileBlastRange: DB 0 ; TODO Initi for runtime copied in when setting up a missile CurrentMissileBlastDamage: DB 0 ; TODO Initi for runtime copied in when setting up a missile CurrentMissileDetonateRange: DB 0 ; TODO Initi for runtime copied in when setting up a missile, allows for proximity missiles CurrentMissileDetonateDamage: DB 0 ; TODO Initi for runtime copied in when setting up a missile ; --- Main Loop Data -----------------------; CurrentUniverseAI DB 0 ; current ship unviverse slot due an AI update SelectedUniverseSlot DB 0 SetStationAngryFlag DB 0 ; used to semaphore angry space station ShipBlastCheckCounter DB 0 InnerHyperCount DB 0 ; 2F QQ22+1 OuterHyperCount DB 0 ; 2E QQ22 EventCounter DB 0 HyperCircle DB 0 MissJumpFlag DB 0 PlayerMisJump DB 0 ; $0341 witchspace misjump HyperSpaceFX DB 0 ; 0348 HFX (probabyl BBC specific ExtraVessels DB 0 ; 0349 EV Use d by cops, extra vessels still to spawn? Delay DB 0 ; 034A Delay general purpose eg. spawing EV or when printign messages CurrentMissileCheck: DB 0 ; if > Universe Slot list then free for next missile MessageForDestroyed DB 0 ; 034B Message flag for item + destroyed UniverseSlotListSize equ 12 UniverseSlotList DS UniverseSlotListSize UniverseSlotType DS UniverseSlotListSize ; base type, e.g. missile, cargo etc, ; Probably not needed UniverseTypeCount DS UniverseSlotListSize ConsoleRefreshCounter DB ConsoleRefreshInterval ; Every 4 interations the console will update twice (once for primary and once for seconday buffer) ConsoleRedrawFlag DB 0 TextInputMode DB 0 CursorKeysPressed DB 0 ; mapping of the current key presses ; 7 6 5 4 3 2 1 0 ; Up Down Left Right Home Recentre FireLaserPressed DB 0 ; --- Current System Data ------------------; SpaceStationSafeZone DB 0 ; Flag to determine if we are in safe zone ExtraVesselsCounter DB 0 JunkCount DB 0 ; $033E AsteroidCount DB 0 ; Not used as yet TransporterCount DB 0 CopCount DB 0 PirateCount DB 0 ; --- Galaxy Data --------------------------; Galaxy DB 0 ; 0367 Galaxy (incremented with galactiv drive WorkingSeeds DS 6 PresentSystemSeeds DS 6 ; 03B2 - 03B7 GalaxySeeds DS 6 ; 035B - 0360 QQ21 PresentSystemX DB 0 ; System we are currently in PresentSystemY DB 0 ; System we are currently in TargetSystemX DB 0 ; System we are targeting for jump TargetSystemY DB 0 ; System we are targeting for jump GovPresentSystem DB 0 ; 03AE Govenment TekPresentSystem DB 0 ; 03AF Technology CompassColor DB 0 ; 03C5 SoundToggle DB 0 ; 03C6 KeyboardRecenterToggle DB 0 ; 03C8 PATGMask DB 0 ; &03C9 \ PATG \ Mask to scan keyboard X-key, for misjump FlashToggle DB 0 ; 03CA \ FLH \ flash toggle ReverseJoystick DB 0 ; 03CB \ JSTGY \ Y reverse joystick Y channel JoystickToggle DB 0 ; 03CD \ JSTK \ K toggle keyboard/joystick DigitalJoystick DB 0 ; 03CE \ JDB \ . = toggle between keyboard and bitpaddle DiskReadFailFlag DB 0 ; 03CF \ CATF \ Disk catalog fail flag ; Working Data ;UniverseTable DS 26 ; 1741 \ address pointers for 13 ships INF on pages &9. 37 bytes each. ; $0900 = EQUW page9+37* 0 \ copied to inner worskpace INWK on zero-page when needed ; $0925 = EQUW page9+37* 1 ; $094A = EQUW page9+37* 2 ; $096F = EQUW page9+37* 3 ; $0994 = EQUW page9+37* 4 ; $09B9 = EQUW page9+37* 5 ; $09DE = EQUW page9+37* 6 ; $0A03 = EQUW page9+37* 7 ; $0A28 = EQUW page9+37* 8 ; $0A4D = EQUW page9+37* 9 ; $0A72 = EQUW page9+37*10 ; $0A97 = EQUW page9+37*11 ; $0ABC = EQUW page9+37*12 \ allwk up to &0ABC while heap for edges working down from &CFF. ; 0b00 is start address of data to save ; Now MissionData VarTP DB 0 ; 0358 TP? The Plan \ mission uses lower 4 bits ; Bit mask XXXX10XX - Thargoid plan mission MissionData DB 0 ; &0B00 \ look at data, first byte is TP mission bits FileNameStringPointer DW 0 ;0C00 \ pointer to filename string CommanderLoadAddress DW 0 ;0C03 LengthOfFile DW 0 ;0C0B SaveDataEndAddress DW 0 ;&0C0F \ &0C00 is end address of data to save EdgesBuffer DS 50 EdgesBufferSP equ $ ; Was $0CFF ; Heap pointer for edges buffer ShipLinesBufferSP equ EdgesBufferSP ; was $0CFF ShipLineStack DS 70 ; For now but will be in the page later ShipLineStackTop equ $ - ShipLineStack LSO DS $C0 ;0E00 Line Buffer Solar of 192 lines (may be 191 in reality) ; LSX vector overlaps with LSO LSX2 DB 0 ; &0EC0 \ LSX2 bline buffer size? LSY2 DB 0 ; &0F0E \ LSY2 ; Star Positions are 16 bit 3d coordinates varDust DS MaxNumberOfStars * 6 varDustSceen DS MaxNumberOfStars * 2 ; To optimise star list to wipe from screen varStarX DB 0 varStarY DB 0 varDustX DS MaxNumberOfStars *2 varDustY DS MaxNumberOfStars *2 varDustZ DS MaxNumberOfStars *2 ; -- Player Runtime Data GunTemperature DB 0 CabinTemperature DB 0 PlayerForwardSheild0 DB 0 ; ????? PlayerForwardSheild1 DB 0 PlayerForwardSheild2 DB 0 ForeShield DB 0 ; These three must be contiguous AftShield DB 0 ; . PlayerEnergy DB 0 ; and in this order CompassX DB 0 ; 03A8 CompassY DB 0 ; 03A9 ; Simplification of missile targetting ; $FF no missile targettting enabled ; $FE missile targetting, no target selected ; bit 7 set then tagetting and lower nibble holds missile target and launching ; bit 7 clear launch at selected target in lower nibble MissileTargettingFlag DB 0 ;;MissileTarget DB 0 ; 45 ;;MissileLaunchFlag DB 0 CommanderName DS 15 CommanderName0 DB 0 ; Sneaky little 0 to allow use of print name directly BadnessStatus DB 0 ;note rapidly changing views could reset these so need to consider it in an array ; LaserType ; LaserPulseRate ; how many pulses can be fired before long pause ; LaserPulsePause ; time before next pulse - 0 = beam ; LaserPulseRest ; time before pulse count resets to 0 ; LaserDamageOutput ; amount of damage for a laser hit ; LaserEnergyDrain ; amount of energy drained by cycle ; LaserHeat ; amount of heat generated ; LaserDurability ; probabability out of 255 that a hit on unshielded will add random amount of damage ; LaserDurabilityAmount ; max amount of damagage can be sustained in one damage hit ; LaserInMarkets ; can this laser be purchased 0 = yes 1 = no ; LaserTechLevel ; minimum tech level system to buy from ; need to add copy table routines CurrLaserType DB 0 ; current view laser type, copied in from LaserType array CurrLaserDamage DB 0 ; copied in from LaserDamagedFlag array CurrLaserPulseRate DB 0 ; current view laser amount of pulses CurrLaserPulseOnTime DB 0 ; how many cycles the laser is on CurrLaserPulseOffTime DB 0 ; how many cycles the laser is on CurrLaserPulseRest DB 0 ; current view laser delay setup between pulses CurrLaserBurstRate DB 0 CurrLaserBurstCount DB 0 CurrLaserDamageOutput DB 0 CurrLaserEnergyDrain DB 0 CurrLaserHeat DB 0 CurrLaserDurability DB 0 CurrLaserDurabilityAmount DB 0 ; Count down timers must be aligned like this to work CurrLaserPulseOnCount DB 0 ; how many cycles the laser is on timer CurrLaserPulseOffCount DB 0 ; how many cycles the laser is on timer CurrLaserPulseRestCount DB 0 ; countdown after shooting for next shot CurrLaserPulseRateCount DB 0 ; current view laser current pulses fired ; -- Input variables JoystickX DB 0 ; 034C JSTX JoystickY DB 0 ; 034D JSTY XSAV2 DB 0 ; 034E used to temporary save 6502 X reg YSAV2 DB 0 ; 034F used to temporary save 6502 Y reg ; -- Console drawing data FShieldStart equ $8410 AShieldStart equ $8D10 FuelStart equ $9410 EnergyBar4Start equ $A5D5 EnergyBar3Start equ $ADD5 EnergyBar2Start equ $B5D5 EnergyBar1Start equ $BDD5 ; 70 /2 = 35 values ; 0 1 2 3 ; 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 FuelMapping DB 01,02,02,03,04,04,05,06,06,07,08,09,10,10,11,12,13,14,14,15,16,16,17,19,20,21,21,22,23,24,25,26,27,28,30,31,31 SpeedoStart equ $84D1 ; 0 1 2 3 4 ; 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 SpeedoMapping DB 01,02,02,03,04,04,05,06,06,07,08,09,10,10,11,12,13,14,14,15,16,16,17,18,19,20,20,21,22,23,24,24,25,26,26,27,28,28,29,30,31 DialMiddleXPos equ $E1 RollMiddle equ $8CE0 PitchMiddle equ $94E0
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r11 push %r12 push %rax push %rbp push %rbx push %rcx push %rdi push %rsi lea addresses_D_ht+0x181db, %r12 nop and $3858, %rbp vmovups (%r12), %ymm3 vextracti128 $0, %ymm3, %xmm3 vpextrq $0, %xmm3, %rsi nop nop xor $3903, %r11 lea addresses_WT_ht+0x18bdf, %rbp nop nop nop nop nop cmp %rsi, %rsi movb (%rbp), %r10b nop nop cmp %r12, %r12 lea addresses_WC_ht+0xfe9b, %rax sub $47157, %rbx mov $0x6162636465666768, %r11 movq %r11, %xmm4 movups %xmm4, (%rax) nop nop nop nop nop lfence lea addresses_UC_ht+0xa0db, %r10 nop and $41288, %r12 mov $0x6162636465666768, %rbp movq %rbp, (%r10) nop nop nop sub $21055, %rbp lea addresses_UC_ht+0x142db, %rsi lea addresses_normal_ht+0x15f7b, %rdi cmp $16371, %r12 mov $93, %rcx rep movsl nop nop nop sub $16673, %rcx lea addresses_normal_ht+0x1a49b, %rcx nop nop nop nop nop sub %r10, %r10 mov (%rcx), %rdi nop dec %rax lea addresses_A_ht+0xe2db, %rax clflush (%rax) nop nop nop inc %r11 mov (%rax), %r12 nop nop nop nop nop cmp %rdi, %rdi lea addresses_D_ht+0xb94b, %rsi lea addresses_D_ht+0x1a4f5, %rdi nop nop nop sub $3939, %r12 mov $68, %rcx rep movsw nop inc %rbx lea addresses_A_ht+0x13441, %r10 nop nop nop nop add %rcx, %rcx movb $0x61, (%r10) nop and %rdi, %rdi lea addresses_WT_ht+0x1413b, %rsi lea addresses_normal_ht+0x6c5b, %rdi nop nop nop add %r12, %r12 mov $39, %rcx rep movsl sub $20248, %rcx pop %rsi pop %rdi pop %rcx pop %rbx pop %rbp pop %rax pop %r12 pop %r11 pop %r10 ret .global s_faulty_load s_faulty_load: push %r10 push %r11 push %r15 push %r8 push %rbp push %rbx push %rdi // Load mov $0x77c0630000000929, %rdi nop nop nop sub %r10, %r10 movb (%rdi), %bl nop nop nop add $21810, %rbp // Store lea addresses_D+0x14adb, %r15 and %r8, %r8 movl $0x51525354, (%r15) nop nop nop nop sub %rbp, %rbp // Store lea addresses_WT+0x150db, %r8 clflush (%r8) nop xor %rbp, %rbp mov $0x5152535455565758, %rbx movq %rbx, %xmm7 movups %xmm7, (%r8) nop nop nop nop xor $46084, %r15 // Faulty Load lea addresses_US+0x1fadb, %rdi nop nop dec %r15 mov (%rdi), %r10w lea oracles, %r11 and $0xff, %r10 shlq $12, %r10 mov (%r11,%r10,1), %r10 pop %rdi pop %rbx pop %rbp pop %r8 pop %r15 pop %r11 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 1, 'type': 'addresses_US', 'congruent': 0}} {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 1, 'type': 'addresses_NC', 'congruent': 1}} {'dst': {'same': False, 'NT': False, 'AVXalign': True, 'size': 4, 'type': 'addresses_D', 'congruent': 10}, 'OP': 'STOR'} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_WT', 'congruent': 8}, 'OP': 'STOR'} [Faulty Load] {'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_US', 'congruent': 0}} <gen_prepare_buffer> {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_D_ht', 'congruent': 8}} {'OP': 'LOAD', 'src': {'same': False, 'NT': True, 'AVXalign': True, 'size': 1, 'type': 'addresses_WT_ht', 'congruent': 1}} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_WC_ht', 'congruent': 6}, 'OP': 'STOR'} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 8, 'type': 'addresses_UC_ht', 'congruent': 9}, 'OP': 'STOR'} {'dst': {'same': False, 'congruent': 4, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 11, 'type': 'addresses_UC_ht'}} {'OP': 'LOAD', 'src': {'same': False, 'NT': True, 'AVXalign': False, 'size': 8, 'type': 'addresses_normal_ht', 'congruent': 6}} {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 8, 'type': 'addresses_A_ht', 'congruent': 10}} {'dst': {'same': True, 'congruent': 1, 'type': 'addresses_D_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 4, 'type': 'addresses_D_ht'}} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 1, 'type': 'addresses_A_ht', 'congruent': 1}, 'OP': 'STOR'} {'dst': {'same': False, 'congruent': 6, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 5, 'type': 'addresses_WT_ht'}} {'54': 15} 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 */
// Copyright 2020-2022 The Defold Foundation // Copyright 2014-2020 King // Copyright 2009-2014 Ragnar Svensson, Christian Murray // Licensed under the Defold License version 1.0 (the "License"); you may not use // this file except in compliance with the License. // // You may obtain a copy of the License, together with FAQs at // https://www.defold.com/license // // 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 "comp_mesh.h" #include <string.h> #include <float.h> #include <stdint.h> #include <dlib/array.h> #include <dlib/hash.h> #include <dlib/log.h> #include <dlib/math.h> #include <dlib/message.h> #include <dlib/object_pool.h> #include <dlib/profile.h> #include <dlib/dstrings.h> #include <dlib/transform.h> #include <dmsdk/dlib/vmath.h> #include <gameobject/gameobject_ddf.h> #include <graphics/graphics.h> #include <render/render.h> #include "../gamesys.h" #include "../gamesys_private.h" #include "comp_private.h" #include <gamesys/gamesys_ddf.h> #include <gamesys/mesh_ddf.h> #include <dmsdk/gamesys/render_constants.h> #include "../resources/res_mesh.h" namespace dmGameSystem { using namespace dmVMath; using namespace dmGameSystemDDF; struct MeshComponent { dmGameObject::HInstance m_Instance; Matrix4 m_Local; Matrix4 m_World; uint32_t m_MixedHash; HComponentRenderConstants m_RenderConstants; MeshResource* m_Resource; dmGameSystem::BufferResource* m_BufferResource; dmGraphics::HTexture m_Textures[dmRender::RenderObject::MAX_TEXTURE_COUNT]; dmRender::HMaterial m_Material; // If the buffer resource property has changed (ie not same buffer resource as // used by the mesh resource), we need to create a specific vertex declaration // and vertbuffer for this buffer resource instead. dmGraphics::HVertexDeclaration m_VertexDeclaration; uint32_t m_BufferVersion; /// Component enablement uint8_t m_Enabled : 1; /// Added to update or not uint8_t m_AddedToUpdate : 1; uint8_t m_ReHash : 1; uint8_t :5; }; struct VertexBufferInfo { dmGraphics::HVertexBuffer m_VertexBuffer; uint32_t m_RefCount; uint32_t m_Version; }; struct MeshWorld { dmResource::HFactory m_ResourceFactory; dmObjectPool<MeshComponent*> m_Components; dmArray<dmRender::RenderObject> m_RenderObjects; dmHashTable64<VertexBufferInfo> m_ResourceToVertexBuffer; dmArray<dmGraphics::HVertexBuffer> m_VertexBufferPool; dmArray<dmGraphics::HVertexBuffer> m_VertexBufferWorld; // for meshes batched in world space dmGraphics::HContext m_GraphicsContext; void* m_WorldVertexData; size_t m_WorldVertexDataSize; /// Keep track of how much vertex data we have rendered so it can be /// reported to the profiler at end of the render dispatching. uint32_t m_RenderedVertexSize; }; static inline void DeallocVertexBuffer(MeshWorld* world, dmGraphics::HVertexBuffer vertex_buffer) { if (world->m_VertexBufferPool.Full()) world->m_VertexBufferPool.OffsetCapacity(4); world->m_VertexBufferPool.Push(vertex_buffer); } static inline dmGraphics::HVertexBuffer AllocVertexBuffer(MeshWorld* world, dmGraphics::HContext graphics_context) { if (!world->m_VertexBufferPool.Empty()) { dmGraphics::HVertexBuffer vertex_buffer = world->m_VertexBufferPool[world->m_VertexBufferPool.Size()-1]; world->m_VertexBufferPool.SetSize(world->m_VertexBufferPool.Size()-1); return vertex_buffer; } // TODO: perhaps control stream vs draw better? return dmGraphics::NewVertexBuffer(graphics_context, 0, 0x0, dmGraphics::BUFFER_USAGE_DYNAMIC_DRAW); } static dmGraphics::HVertexBuffer GetVertexBuffer(MeshWorld* world, dmhash_t path) { VertexBufferInfo* info = world->m_ResourceToVertexBuffer.Get(path); if (!info) return 0; return info->m_VertexBuffer; } static void AddVertexBufferInfo(MeshWorld* world, dmhash_t path, dmGraphics::HVertexBuffer vertex_buffer, uint32_t version) { VertexBufferInfo info; info.m_RefCount = 1; info.m_VertexBuffer = vertex_buffer; info.m_Version = version; if (world->m_ResourceToVertexBuffer.Full()) { uint32_t capacity = world->m_ResourceToVertexBuffer.Capacity() + 8; world->m_ResourceToVertexBuffer.SetCapacity(capacity/3, capacity); } world->m_ResourceToVertexBuffer.Put(path, info); } static void DecRefVertexBuffer(MeshWorld* world, dmhash_t path) { VertexBufferInfo* info = world->m_ResourceToVertexBuffer.Get(path); assert(info != 0); info->m_RefCount--; if (info->m_RefCount == 0) { world->m_ResourceToVertexBuffer.Erase(path); DeallocVertexBuffer(world, info->m_VertexBuffer); } } static void IncRefVertexBuffer(MeshWorld* world, dmhash_t path) { VertexBufferInfo* info = world->m_ResourceToVertexBuffer.Get(path); assert(info != 0); info->m_RefCount++; } static uint32_t CalcBufferVersion(const MeshComponent* component, BufferResource* br) { HashState32 state; dmHashInit32(&state, false); uint32_t version; dmBuffer::GetContentVersion(br->m_Buffer, &version); dmHashUpdateBuffer32(&state, &br->m_Buffer, sizeof(br->m_Buffer)); // The handle is not a pointer, but a version+index dmHashUpdateBuffer32(&state, &version, sizeof(version)); return dmHashFinal32(&state); } static void CopyBufferToVertexBuffer(dmBuffer::HBuffer buffer, dmGraphics::HVertexBuffer vertex_buffer, uint32_t vert_size, uint32_t elem_count, dmGraphics::BufferUsage buffer_usage) { uint8_t* bytes = 0x0; uint32_t size = 0; dmBuffer::Result r = dmBuffer::GetBytes(buffer, (void**)&bytes, &size); assert(r == dmBuffer::RESULT_OK); dmGraphics::SetVertexBufferData(vertex_buffer, vert_size * elem_count, bytes, buffer_usage); } static void CreateVertexBuffer(MeshWorld* world, dmGameSystem::BufferResource* br, uint32_t version) { dmGraphics::HVertexBuffer vertex_buffer = GetVertexBuffer(world, br->m_NameHash); if (!vertex_buffer) { vertex_buffer = AllocVertexBuffer(world, world->m_GraphicsContext); AddVertexBufferInfo(world, br->m_NameHash, vertex_buffer, version); // ref count == 1 CopyBufferToVertexBuffer(br->m_Buffer, vertex_buffer, br->m_Stride, br->m_ElementCount, dmGraphics::BUFFER_USAGE_STREAM_DRAW); } else { IncRefVertexBuffer(world, br->m_NameHash); } } static const uint32_t MAX_TEXTURE_COUNT = dmRender::RenderObject::MAX_TEXTURE_COUNT; static const dmhash_t PROP_VERTICES = dmHashString64("vertices"); static void ResourceReloadedCallback(const dmResource::ResourceReloadedParams& params); dmGameObject::CreateResult CompMeshNewWorld(const dmGameObject::ComponentNewWorldParams& params) { MeshContext* context = (MeshContext*)params.m_Context; MeshWorld* world = new MeshWorld(); uint32_t comp_count = dmMath::Min(params.m_MaxComponentInstances, context->m_MaxMeshCount); world->m_ResourceFactory = context->m_Factory; world->m_Components.SetCapacity(comp_count); world->m_RenderObjects.SetCapacity(comp_count); world->m_VertexBufferPool.SetCapacity(0); world->m_VertexBufferPool.SetSize(0); world->m_WorldVertexData = 0x0; world->m_WorldVertexDataSize = 0; world->m_RenderedVertexSize = 0; *params.m_World = world; dmResource::RegisterResourceReloadedCallback(context->m_Factory, ResourceReloadedCallback, world); return dmGameObject::CREATE_RESULT_OK; } dmGameObject::CreateResult CompMeshDeleteWorld(const dmGameObject::ComponentDeleteWorldParams& params) { MeshWorld* world = (MeshWorld*)params.m_World; if (world->m_VertexBufferPool.Capacity() < world->m_VertexBufferPool.Size()+world->m_VertexBufferWorld.Size()) world->m_VertexBufferPool.OffsetCapacity(world->m_VertexBufferWorld.Size()); world->m_VertexBufferPool.PushArray(world->m_VertexBufferWorld.Begin(), world->m_VertexBufferWorld.Size()); world->m_VertexBufferWorld.SetSize(0); for(uint32_t i = 0; i < world->m_VertexBufferPool.Size(); ++i) { dmGraphics::DeleteVertexBuffer(world->m_VertexBufferPool[i]); } if (world->m_WorldVertexData) { free(world->m_WorldVertexData); } dmResource::UnregisterResourceReloadedCallback(((MeshContext*)params.m_Context)->m_Factory, ResourceReloadedCallback, world); delete world; return dmGameObject::CREATE_RESULT_OK; } static inline dmGameSystem::BufferResource* GetVerticesBuffer(const MeshComponent* component, const MeshResource* resource) { return component->m_BufferResource ? component->m_BufferResource : resource->m_BufferResource; } static inline dmRender::HMaterial GetMaterial(const MeshComponent* component, const MeshResource* resource) { return component->m_Material ? component->m_Material : resource->m_Material; } static inline dmGraphics::HTexture GetTexture(const MeshComponent* component, const MeshResource* resource, uint32_t index) { assert(index < MAX_TEXTURE_COUNT); return component->m_Textures[index] ? component->m_Textures[index] : resource->m_Textures[index]; } static inline dmGraphics::HVertexDeclaration GetVertexDeclaration(const MeshComponent* component) { return component->m_VertexDeclaration ? component->m_VertexDeclaration : component->m_Resource->m_VertexDeclaration; } static void ReHash(MeshComponent* component) { // Hash resource-ptr, material-handle, textures and render constants HashState32 state; bool reverse = false; MeshResource* resource = component->m_Resource; dmHashInit32(&state, reverse); dmRender::HMaterial material = GetMaterial(component, resource); dmHashUpdateBuffer32(&state, &resource->m_PrimitiveType, sizeof(resource->m_PrimitiveType)); dmHashUpdateBuffer32(&state, &material, sizeof(material)); // We have to hash individually since we don't know which textures are set as properties for (uint32_t i = 0; i < MAX_TEXTURE_COUNT; ++i) { dmGraphics::HTexture texture = GetTexture(component, resource, i); dmHashUpdateBuffer32(&state, &texture, sizeof(texture)); } BufferResource* br = GetVerticesBuffer(component, resource); dmHashUpdateBuffer32(&state, &br->m_NameHash, sizeof(br->m_NameHash)); // Make sure there is a vertex declaration // If the mesh uses a buffer that has zero elements we couldn't // create a vert declaration, so just skip hashing it here. dmGraphics::HVertexDeclaration vert_decl = GetVertexDeclaration(component); if (vert_decl) { dmGraphics::HashVertexDeclaration(&state, vert_decl); } if (component->m_RenderConstants) dmGameSystem::HashRenderConstants(component->m_RenderConstants, &state); component->m_MixedHash = dmHashFinal32(&state); component->m_ReHash = 0; } dmGameObject::CreateResult CompMeshCreate(const dmGameObject::ComponentCreateParams& params) { MeshWorld* world = (MeshWorld*)params.m_World; if (world->m_Components.Full()) { dmLogError("Mesh could not be created since the buffer is full (%d).", world->m_Components.Capacity()); return dmGameObject::CREATE_RESULT_UNKNOWN_ERROR; } uint32_t index = world->m_Components.Alloc(); MeshComponent* component = new MeshComponent; memset(component, 0, sizeof(MeshComponent)); world->m_Components.Set(index, component); component->m_Instance = params.m_Instance; component->m_Local = Matrix4(params.m_Rotation, Vector3(params.m_Position)); component->m_Resource = (MeshResource*)params.m_Resource; component->m_Enabled = 1; component->m_World = Matrix4::identity(); component->m_BufferVersion = 0; const Matrix4& go_world = dmGameObject::GetWorldMatrix(component->m_Instance); if (dmGameObject::ScaleAlongZ(component->m_Instance)) { component->m_World = go_world * component->m_Local; } else { component->m_World = dmTransform::MulNoScaleZ(go_world, component->m_Local); } // Local space uses separate vertex buffers if (dmRender::GetMaterialVertexSpace(GetMaterial(component, component->m_Resource)) == dmRenderDDF::MaterialDesc::VERTEX_SPACE_LOCAL) { dmGameSystem::BufferResource* br = GetVerticesBuffer(component, component->m_Resource); component->m_BufferVersion = CalcBufferVersion(component, br); CreateVertexBuffer(world, br, component->m_BufferVersion); } ReHash(component); *params.m_UserData = (uintptr_t)index; return dmGameObject::CREATE_RESULT_OK; } dmGameObject::CreateResult CompMeshDestroy(const dmGameObject::ComponentDestroyParams& params) { MeshWorld* world = (MeshWorld*)params.m_World; uint32_t index = (uint32_t)*params.m_UserData; MeshComponent* component = world->m_Components.Get(index); dmResource::HFactory factory = dmGameObject::GetFactory(params.m_Instance); if (component->m_Material) { dmResource::Release(factory, component->m_Material); } for (uint32_t i = 0; i < MAX_TEXTURE_COUNT; ++i) { if (component->m_Textures[i]) { dmResource::Release(factory, component->m_Textures[i]); } } dmGameSystem::BufferResource* br = GetVerticesBuffer(component, component->m_Resource); if (dmRender::GetMaterialVertexSpace(GetMaterial(component, component->m_Resource)) == dmRenderDDF::MaterialDesc::VERTEX_SPACE_LOCAL) { DecRefVertexBuffer(world, br->m_NameHash); } if (component->m_BufferResource) { dmResource::Release(factory, component->m_BufferResource); } if (component->m_RenderConstants) dmGameSystem::DestroyRenderConstants(component->m_RenderConstants); delete component; world->m_Components.Free(index, true); return dmGameObject::CREATE_RESULT_OK; } static void UpdateTransforms(MeshWorld* world) { DM_PROFILE(Mesh, "UpdateTransforms"); dmArray<MeshComponent*>& components = world->m_Components.m_Objects; uint32_t n = components.Size(); for (uint32_t i = 0; i < n; ++i) { MeshComponent* c = components[i]; // NOTE: texture_set = c->m_Resource might be NULL so it's essential to "continue" here if (!c->m_Enabled || !c->m_AddedToUpdate) continue; const Matrix4& go_world = dmGameObject::GetWorldMatrix(c->m_Instance); if (dmGameObject::ScaleAlongZ(c->m_Instance)) { c->m_World = go_world * c->m_Local; } else { c->m_World = dmTransform::MulNoScaleZ(go_world, c->m_Local); } } } dmGameObject::CreateResult CompMeshAddToUpdate(const dmGameObject::ComponentAddToUpdateParams& params) { MeshWorld* world = (MeshWorld*)params.m_World; uint32_t index = (uint32_t)*params.m_UserData; MeshComponent* component = world->m_Components.Get(index); component->m_AddedToUpdate = true; return dmGameObject::CREATE_RESULT_OK; } dmGameObject::UpdateResult CompMeshUpdate(const dmGameObject::ComponentsUpdateParams& params, dmGameObject::ComponentsUpdateResult& update_result) { MeshWorld* world = (MeshWorld*)params.m_World; dmArray<MeshComponent*>& components = world->m_Components.m_Objects; const uint32_t count = components.Size(); for (uint32_t i = 0; i < count; ++i) { MeshComponent& component = *components[i]; if (!component.m_Enabled || !component.m_AddedToUpdate) continue; dmRender::HMaterial material = GetMaterial(&component, component.m_Resource); if (dmRender::GetMaterialVertexSpace(material) == dmRenderDDF::MaterialDesc::VERTEX_SPACE_LOCAL) { dmGameSystem::BufferResource* br = GetVerticesBuffer(&component, component.m_Resource); VertexBufferInfo* info = world->m_ResourceToVertexBuffer.Get(br->m_NameHash); assert(info != 0); if (info->m_Version != component.m_BufferVersion) { info->m_Version = component.m_BufferVersion; CopyBufferToVertexBuffer(br->m_Buffer, info->m_VertexBuffer, br->m_Stride, br->m_ElementCount, dmGraphics::BUFFER_USAGE_DYNAMIC_DRAW); } } if (component.m_RenderConstants && dmGameSystem::AreRenderConstantsUpdated(component.m_RenderConstants)) component.m_ReHash = 1; if (component.m_ReHash) { ReHash(&component); } } return dmGameObject::UPDATE_RESULT_OK; } static void FillRenderObject(dmRender::RenderObject& ro, const dmGraphics::PrimitiveType& primitive_type, const dmRender::HMaterial& material, const dmGraphics::HTexture* textures_resource, const dmGraphics::HTexture* textures_component, const dmGraphics::HVertexDeclaration& vert_decl, const dmGraphics::HVertexBuffer& vert_buffer, uint32_t vert_start, uint32_t vert_count, const Matrix4& world_transform, HComponentRenderConstants constants) { ro.Init(); ro.m_VertexDeclaration = vert_decl; ro.m_VertexBuffer = vert_buffer; ro.m_Material = material; ro.m_PrimitiveType = primitive_type; ro.m_VertexStart = vert_start; ro.m_VertexCount = vert_count; ro.m_WorldTransform = world_transform; // TODO(andsve): For future reference; we might want to have a separate buffer resource for indices. // if(mr->m_IndexBuffer) // { // ro.m_IndexBuffer = mr->m_IndexBuffer; // ro.m_IndexType = mr->m_IndexBufferElementType; // } for (uint32_t i = 0; i < dmRender::RenderObject::MAX_TEXTURE_COUNT; ++i) ro.m_Textures[i] = textures_component[i] ? textures_component[i] : textures_resource[i]; if (constants) dmGameSystem::EnableRenderObjectConstants(&ro, constants); } template<typename T> static void FillAndApply(const Matrix4& matrix, bool is_point, uint8_t component_count, uint32_t count, uint32_t stride, T* raw_data, T* src_stream_data, T* dst_data_ptr) { // Offset dst_data_ptr if stream isn't first! uint32_t ptr_offset = (uint8_t*)src_stream_data - (uint8_t*)raw_data; dst_data_ptr = (T*)((uint8_t*)dst_data_ptr + ptr_offset); Vector4 v(0.0f); float w = is_point ? 1.0f : 0.0f; if (component_count == 2) { for (int pi = 0; pi < count; ++pi) { v[0] = (float)src_stream_data[0]; v[1] = (float)src_stream_data[1]; v[2] = 0.0f; v[3] = w; v = matrix * v; dst_data_ptr[0] = (T)v[0]; dst_data_ptr[1] = (T)v[1]; dst_data_ptr[2] = (T)v[2]; // Update in/out-ptrs with stride (they will point to next entry in T "list"). src_stream_data += stride; dst_data_ptr += stride; } } else { for (int pi = 0; pi < count; ++pi) { v[0] = (float)src_stream_data[0]; v[1] = (float)src_stream_data[1]; v[2] = (float)src_stream_data[2]; v[3] = w; v = matrix * v; dst_data_ptr[0] = (T)v[0]; dst_data_ptr[1] = (T)v[1]; dst_data_ptr[2] = (T)v[2]; // Update in/out-ptrs with stride (they will point to next entry in T "list"). src_stream_data += stride; dst_data_ptr += stride; } } } static inline void FillAndApplyStream(const BufferResource* buffer_resource, bool is_point, const Matrix4& matrix, dmhash_t stream_id, dmBufferDDF::ValueType value_type, void* raw_data, void* dst_data_ptr) { // Get position stream to figure out offset and stride etc void* stream_data = 0x0; uint32_t count = 0; uint32_t components = 0; uint32_t stride = 0; dmBuffer::Result r = dmBuffer::GetStream(buffer_resource->m_Buffer, stream_id, &stream_data, &count, &components, &stride); if (r != dmBuffer::RESULT_OK) { dmLogError("Could not get stream %s from buffer when rendering mesh in world space (%d).", dmHashReverseSafe64(stream_id), r); return; } if (!(components == 3 || components == 2)) { dmLogError("Rendering mesh components in world space is only supported for streams with 3 or 2 components, %s has %d components.", dmHashReverseSafe64(stream_id), components); return; } switch (value_type) { case dmBufferDDF::VALUE_TYPE_UINT8: FillAndApply<uint8_t>(matrix, is_point, components, count, stride, (uint8_t*)raw_data, (uint8_t*)stream_data, (uint8_t*)dst_data_ptr); break; case dmBufferDDF::VALUE_TYPE_UINT16: FillAndApply<uint16_t>(matrix, is_point, components, count, stride, (uint16_t*)raw_data, (uint16_t*)stream_data, (uint16_t*)dst_data_ptr); break; case dmBufferDDF::VALUE_TYPE_UINT32: FillAndApply<uint32_t>(matrix, is_point, components, count, stride, (uint32_t*)raw_data, (uint32_t*)stream_data, (uint32_t*)dst_data_ptr); break; case dmBufferDDF::VALUE_TYPE_INT8: FillAndApply<int8_t>(matrix, is_point, components, count, stride, (int8_t*)raw_data, (int8_t*)stream_data, (int8_t*)dst_data_ptr); break; case dmBufferDDF::VALUE_TYPE_INT16: FillAndApply<int16_t>(matrix, is_point, components, count, stride, (int16_t*)raw_data, (int16_t*)stream_data, (int16_t*)dst_data_ptr); break; case dmBufferDDF::VALUE_TYPE_INT32: FillAndApply<int32_t>(matrix, is_point, components, count, stride, (int32_t*)raw_data, (int32_t*)stream_data, (int32_t*)dst_data_ptr); break; case dmBufferDDF::VALUE_TYPE_FLOAT32: FillAndApply<float>(matrix, is_point, components, count, stride, (float*)raw_data, (float*)stream_data, (float*)dst_data_ptr); break; default: dmLogError("Stream type (%d) for %s is not supported.", value_type, dmHashReverseSafe64(stream_id)); break; } } static inline void RenderBatchWorldVS(MeshWorld* world, dmRender::HMaterial material, dmRender::HRenderContext render_context, dmRender::RenderListEntry *buf, uint32_t* begin, uint32_t* end) { DM_PROFILE(Mesh, "RenderBatchWorld"); dmGraphics::HVertexBuffer vert_buffer = AllocVertexBuffer(world, world->m_GraphicsContext); assert(vert_buffer); if (world->m_VertexBufferWorld.Full()) world->m_VertexBufferWorld.OffsetCapacity(2); world->m_VertexBufferWorld.Push(vert_buffer); dmRender::RenderObject& ro = *world->m_RenderObjects.End(); world->m_RenderObjects.SetSize(world->m_RenderObjects.Size()+1); const MeshComponent* first = (MeshComponent*) buf[*begin].m_UserData; const MeshResource* mr = first->m_Resource; const BufferResource* br = GetVerticesBuffer(first, mr); // Setup vertex declaration, count and sizes etc. // These defaults to values in the mesh and buffer resources, // but will be overwritten if the component instance has a "custom" // vertices buffer set (ie set via resource properties). dmGraphics::HVertexDeclaration vert_decl = mr->m_VertexDeclaration; uint32_t vert_size = br->m_Stride; // Find out how many elements/vertices all instances in this batch has // TODO: We might want to calculate this only when a mesh/buffer changes. uint32_t element_count = 0; for (uint32_t *i=begin;i!=end;i++) { const MeshComponent* c = (MeshComponent*) buf[*i].m_UserData; const BufferResource* br = GetVerticesBuffer(c, c->m_Resource); element_count += br->m_ElementCount; } // Allocate a larger scratch buffer if vert count * vert size is larger than current buffer. if (world->m_WorldVertexDataSize < vert_size * element_count) { world->m_WorldVertexDataSize = vert_size * element_count; world->m_WorldVertexData = realloc(world->m_WorldVertexData, world->m_WorldVertexDataSize); } // Fill scratch buffer with data void* dst_data_ptr = world->m_WorldVertexData; for (uint32_t *i=begin;i!=end;i++) { const MeshComponent* component = (MeshComponent*) buf[*i].m_UserData; const MeshResource* mr = component->m_Resource; const BufferResource* br = GetVerticesBuffer(component, mr); // No idea of rendering with zero element count. if (br->m_ElementCount == 0) { continue; } void* raw_data = 0x0; uint32_t size = 0; dmBuffer::Result r = dmBuffer::GetBytes(br->m_Buffer, &raw_data, &size); if (r != dmBuffer::RESULT_OK) { dmLogError("Could not get bytes from buffer when rendering mesh in world space (%d).", r); continue; } // Copy all buffer data memcpy(dst_data_ptr, raw_data, size); // Modify position stream, if specified if (mr->m_PositionStreamId) { FillAndApplyStream(br, true, component->m_World, mr->m_PositionStreamId, mr->m_PositionStreamType, raw_data, dst_data_ptr); } // Modify normal stream, if specified if (mr->m_NormalStreamId) { Matrix4 normal_matrix = affineInverse(component->m_World); normal_matrix = transpose(normal_matrix); FillAndApplyStream(br, false, normal_matrix, mr->m_NormalStreamId, mr->m_NormalStreamType, raw_data, dst_data_ptr); } dst_data_ptr = (void*)((uint8_t*)dst_data_ptr + size); } world->m_RenderedVertexSize += vert_size * element_count; // since they are batched, they have the same settings as the first mesh const MeshComponent* component = (MeshComponent*) buf[*begin].m_UserData; FillRenderObject(ro, mr->m_PrimitiveType, material, mr->m_Textures, component->m_Textures, vert_decl, vert_buffer, 0, element_count, Matrix4::identity(), first->m_RenderConstants); dmGraphics::SetVertexBufferData(vert_buffer, vert_size * element_count, world->m_WorldVertexData, dmGraphics::BUFFER_USAGE_DYNAMIC_DRAW); dmRender::AddToRender(render_context, &ro); } static inline void RenderBatchLocalVS(MeshWorld* world, dmRender::HMaterial material, dmRender::HRenderContext render_context, dmRender::RenderListEntry *buf, uint32_t* begin, uint32_t* end) { DM_PROFILE(Mesh, "RenderBatchLocal"); for (uint32_t *i=begin;i!=end;i++) { dmRender::RenderObject& ro = *world->m_RenderObjects.End(); world->m_RenderObjects.SetSize(world->m_RenderObjects.Size()+1); const MeshComponent* component = (MeshComponent*) buf[*i].m_UserData; const MeshResource* mr = component->m_Resource; dmGameSystem::BufferResource* br = GetVerticesBuffer(component, mr); world->m_RenderedVertexSize += br->m_Stride * br->m_ElementCount; VertexBufferInfo* info = world->m_ResourceToVertexBuffer.Get(br->m_NameHash); assert(info != 0); dmGraphics::HVertexDeclaration vert_decl = GetVertexDeclaration(component); FillRenderObject(ro, mr->m_PrimitiveType, material, mr->m_Textures, component->m_Textures, vert_decl, info->m_VertexBuffer, 0, br->m_ElementCount, component->m_World, component->m_RenderConstants); dmRender::AddToRender(render_context, &ro); } } static void RenderBatch(MeshWorld* world, dmRender::HRenderContext render_context, dmRender::RenderListEntry *buf, uint32_t* begin, uint32_t* end) { DM_PROFILE(Mesh, "RenderBatch"); const MeshComponent* first = (MeshComponent*) buf[*begin].m_UserData; dmRender::HMaterial material = GetMaterial(first, first->m_Resource); switch(dmRender::GetMaterialVertexSpace(material)) { case dmRenderDDF::MaterialDesc::VERTEX_SPACE_WORLD: RenderBatchWorldVS(world, material, render_context, buf, begin, end); break; case dmRenderDDF::MaterialDesc::VERTEX_SPACE_LOCAL: RenderBatchLocalVS(world, material, render_context, buf, begin, end); break; default: assert(false); break; } } static void RenderListDispatch(dmRender::RenderListDispatchParams const &params) { MeshWorld *world = (MeshWorld *) params.m_UserData; switch (params.m_Operation) { case dmRender::RENDER_LIST_OPERATION_BEGIN: { world->m_RenderedVertexSize = 0; world->m_RenderObjects.SetSize(0); if (world->m_VertexBufferPool.Capacity() < world->m_VertexBufferPool.Size()+world->m_VertexBufferWorld.Size()) world->m_VertexBufferPool.OffsetCapacity(world->m_VertexBufferWorld.Size()); world->m_VertexBufferPool.PushArray(world->m_VertexBufferWorld.Begin(), world->m_VertexBufferWorld.Size()); world->m_VertexBufferWorld.SetSize(0); break; } case dmRender::RENDER_LIST_OPERATION_BATCH: { RenderBatch(world, params.m_Context, params.m_Buf, params.m_Begin, params.m_End); break; } case dmRender::RENDER_LIST_OPERATION_END: { DM_COUNTER("MeshVertexBuffer", world->m_RenderedVertexSize); break; } default: assert(false); break; } } dmGameObject::UpdateResult CompMeshRender(const dmGameObject::ComponentsRenderParams& params) { MeshContext* context = (MeshContext*)params.m_Context; dmRender::HRenderContext render_context = context->m_RenderContext; MeshWorld* world = (MeshWorld*)params.m_World; UpdateTransforms(world); dmArray<MeshComponent*>& components = world->m_Components.m_Objects; const uint32_t count = components.Size(); // Prepare list submit dmRender::RenderListEntry* render_list = dmRender::RenderListAlloc(render_context, count); dmRender::HRenderListDispatch dispatch = dmRender::RenderListMakeDispatch(render_context, &RenderListDispatch, world); dmRender::RenderListEntry* write_ptr = render_list; for (uint32_t i = 0; i < count; ++i) { MeshComponent& component = *components[i]; if (!component.m_Enabled) continue; const Vector4 trans = component.m_World.getCol(3); write_ptr->m_WorldPosition = Point3(trans.getX(), trans.getY(), trans.getZ()); write_ptr->m_UserData = (uintptr_t) &component; write_ptr->m_BatchKey = component.m_MixedHash; write_ptr->m_TagListKey = dmRender::GetMaterialTagListKey(component.m_Resource->m_Material); write_ptr->m_Dispatch = dispatch; write_ptr->m_MinorOrder = 0; write_ptr->m_MajorOrder = dmRender::RENDER_ORDER_WORLD; ++write_ptr; } dmRender::RenderListSubmit(render_context, render_list, write_ptr); return dmGameObject::UPDATE_RESULT_OK; } static bool CompMeshGetConstantCallback(void* user_data, dmhash_t name_hash, dmRender::Constant** out_constant) { MeshComponent* component = (MeshComponent*)user_data; return component->m_RenderConstants && dmGameSystem::GetRenderConstant(component->m_RenderConstants, name_hash, out_constant); } static void CompMeshSetConstantCallback(void* user_data, dmhash_t name_hash, int32_t value_index, uint32_t* element_index, const dmGameObject::PropertyVar& var) { MeshComponent* component = (MeshComponent*)user_data; if (!component->m_RenderConstants) component->m_RenderConstants = dmGameSystem::CreateRenderConstants(); dmGameSystem::SetRenderConstant(component->m_RenderConstants, GetMaterial(component, component->m_Resource), name_hash, value_index, element_index, var); component->m_ReHash = 1; } dmGameObject::UpdateResult CompMeshOnMessage(const dmGameObject::ComponentOnMessageParams& params) { MeshWorld* world = (MeshWorld*)params.m_World; MeshComponent* component = world->m_Components.Get(*params.m_UserData); if (params.m_Message->m_Id == dmGameObjectDDF::Enable::m_DDFDescriptor->m_NameHash) { component->m_Enabled = 1; } else if (params.m_Message->m_Id == dmGameObjectDDF::Disable::m_DDFDescriptor->m_NameHash) { component->m_Enabled = 0; } else if (params.m_Message->m_Descriptor != 0x0) { if (params.m_Message->m_Id == dmGameSystemDDF::SetConstant::m_DDFDescriptor->m_NameHash) { dmGameSystemDDF::SetConstant* ddf = (dmGameSystemDDF::SetConstant*)params.m_Message->m_Data; dmGameObject::PropertyResult result = dmGameSystem::SetMaterialConstant(component->m_Resource->m_Material, ddf->m_NameHash, dmGameObject::PropertyVar(ddf->m_Value), ddf->m_Index, CompMeshSetConstantCallback, component); if (result == dmGameObject::PROPERTY_RESULT_NOT_FOUND) { dmMessage::URL& receiver = params.m_Message->m_Receiver; dmLogError("'%s:%s#%s' has no constant named '%s'", dmMessage::GetSocketName(receiver.m_Socket), dmHashReverseSafe64(receiver.m_Path), dmHashReverseSafe64(receiver.m_Fragment), dmHashReverseSafe64(ddf->m_NameHash)); } } else if (params.m_Message->m_Id == dmGameSystemDDF::ResetConstant::m_DDFDescriptor->m_NameHash) { dmGameSystemDDF::ResetConstant* ddf = (dmGameSystemDDF::ResetConstant*)params.m_Message->m_Data; if (component->m_RenderConstants && dmGameSystem::ClearRenderConstant(component->m_RenderConstants, ddf->m_NameHash)) { component->m_ReHash = 1; } } } return dmGameObject::UPDATE_RESULT_OK; } void CompMeshOnReload(const dmGameObject::ComponentOnReloadParams& params) { MeshWorld* world = (MeshWorld*)params.m_World; int index = *params.m_UserData; MeshComponent* component = world->m_Components.Get(index); component->m_Resource = (MeshResource*)params.m_Resource; component->m_ReHash = 1; } dmGameObject::PropertyResult CompMeshGetProperty(const dmGameObject::ComponentGetPropertyParams& params, dmGameObject::PropertyDesc& out_value) { MeshWorld* world = (MeshWorld*)params.m_World; MeshComponent* component = world->m_Components.Get(*params.m_UserData); if (params.m_PropertyId == PROP_VERTICES) { return GetResourceProperty(dmGameObject::GetFactory(params.m_Instance), GetVerticesBuffer(component, component->m_Resource), out_value); } else if (params.m_PropertyId == PROP_MATERIAL) { return GetResourceProperty(dmGameObject::GetFactory(params.m_Instance), GetMaterial(component, component->m_Resource), out_value); } for (uint32_t i = 0; i < MAX_TEXTURE_COUNT; ++i) { if (params.m_PropertyId == PROP_TEXTURE[i]) { return GetResourceProperty(dmGameObject::GetFactory(params.m_Instance), GetTexture(component, component->m_Resource, i), out_value); } } return GetMaterialConstant(GetMaterial(component, component->m_Resource), params.m_PropertyId, params.m_Options.m_Index, out_value, true, CompMeshGetConstantCallback, component); } dmGameObject::PropertyResult CompMeshSetProperty(const dmGameObject::ComponentSetPropertyParams& params) { MeshWorld* world = (MeshWorld*)params.m_World; MeshComponent* component = world->m_Components.Get(*params.m_UserData); if (params.m_PropertyId == PROP_VERTICES) { BufferResource* prev_buffer_resource = GetVerticesBuffer(component, component->m_Resource); BufferResource* prev_custom_buffer_resource = component->m_BufferResource; dmGameObject::PropertyResult res = SetResourceProperty(dmGameObject::GetFactory(params.m_Instance), params.m_Value, BUFFER_EXT_HASH, (void**)&component->m_BufferResource); component->m_ReHash |= res == dmGameObject::PROPERTY_RESULT_OK; if (res == dmGameObject::PROPERTY_RESULT_OK) { BufferResource* br = GetVerticesBuffer(component, component->m_Resource); component->m_BufferVersion = CalcBufferVersion(component, br); // If the buffer resource was changed, we might need to recreate the vertex declaration. if (!prev_custom_buffer_resource || (component->m_BufferResource != prev_buffer_resource)) { // Perhaps figure our a way to avoid recreating the same vertex declarations all the time? (If if it's worth it?) dmGraphics::HVertexDeclaration new_vert_decl; bool r = dmGameSystem::BuildVertexDeclaration(component->m_BufferResource, &new_vert_decl); if (!r) { dmLogError("Error while building vertex declaration from new resource."); return dmGameObject::PROPERTY_RESULT_UNSUPPORTED_VALUE; } // Delete old vertex declaration if (component->m_VertexDeclaration) { dmGraphics::DeleteVertexDeclaration(component->m_VertexDeclaration); } component->m_VertexDeclaration = new_vert_decl; } if (dmRender::GetMaterialVertexSpace(GetMaterial(component, component->m_Resource)) == dmRenderDDF::MaterialDesc::VERTEX_SPACE_LOCAL) { CreateVertexBuffer(world, br, component->m_BufferVersion); // Will inc ref the buffer DecRefVertexBuffer(world, prev_buffer_resource->m_NameHash); } } return res; } else if (params.m_PropertyId == PROP_MATERIAL) { bool prev_material_local = dmRender::GetMaterialVertexSpace(GetMaterial(component, component->m_Resource)) == dmRenderDDF::MaterialDesc::VERTEX_SPACE_LOCAL; dmGameObject::PropertyResult res = SetResourceProperty(dmGameObject::GetFactory(params.m_Instance), params.m_Value, MATERIAL_EXT_HASH, (void**)&component->m_Material); component->m_ReHash |= res == dmGameObject::PROPERTY_RESULT_OK; bool new_material_local = dmRender::GetMaterialVertexSpace(GetMaterial(component, component->m_Resource)) == dmRenderDDF::MaterialDesc::VERTEX_SPACE_LOCAL; // If we're going from reference counted (local space) vertex buffers, to not reference counted (global space) if (res == dmGameObject::PROPERTY_RESULT_OK && new_material_local != prev_material_local) { if (prev_material_local) { BufferResource* br = GetVerticesBuffer(component, component->m_Resource); DecRefVertexBuffer(world, br->m_NameHash); } } return res; } for(uint32_t i = 0; i < MAX_TEXTURE_COUNT; ++i) { if(params.m_PropertyId == PROP_TEXTURE[i]) { dmGameObject::PropertyResult res = SetResourceProperty(dmGameObject::GetFactory(params.m_Instance), params.m_Value, TEXTURE_EXT_HASH, (void**)&component->m_Textures[i]); component->m_ReHash |= res == dmGameObject::PROPERTY_RESULT_OK; return res; } } dmGameObject::PropertyResult res = SetMaterialConstant(GetMaterial(component, component->m_Resource), params.m_PropertyId, params.m_Value, params.m_Options.m_Index, CompMeshSetConstantCallback, component); component->m_ReHash |= res == dmGameObject::PROPERTY_RESULT_OK; return res; } static void ResourceReloadedCallback(const dmResource::ResourceReloadedParams& params) { MeshWorld* world = (MeshWorld*) params.m_UserData; dmArray<MeshComponent*>& components = world->m_Components.m_Objects; uint32_t n = components.Size(); for (uint32_t i = 0; i < n; ++i) { MeshComponent* component = components[i]; if (component->m_Resource) { const dmRender::HMaterial material = GetMaterial(component, component->m_Resource); const dmGameSystem::BufferResource* buffer_resource = GetVerticesBuffer(component, component->m_Resource); if (component->m_Resource == params.m_Resource->m_Resource || material == params.m_Resource->m_Resource || buffer_resource == params.m_Resource->m_Resource) { component->m_ReHash = 1; continue; } for (uint32_t i = 0; i < MAX_TEXTURE_COUNT; ++i) { dmGraphics::HTexture texture = GetTexture(component, component->m_Resource, i); if (texture == params.m_Resource->m_Resource) { component->m_ReHash = 1; break; } } } } } static bool CompMeshIterPropertiesGetNext(dmGameObject::SceneNodePropertyIterator* pit) { MeshWorld* world = (MeshWorld*)pit->m_Node->m_ComponentWorld; MeshComponent* component = world->m_Components.Get(pit->m_Node->m_Component); uint64_t index = pit->m_Next++; uint32_t num_bool_properties = 1; if (index < num_bool_properties) { if (index == 0) { pit->m_Property.m_Type = dmGameObject::SCENE_NODE_PROPERTY_TYPE_BOOLEAN; pit->m_Property.m_Value.m_Bool = component->m_Enabled; pit->m_Property.m_NameHash = dmHashString64("enabled"); } return true; } index -= num_bool_properties; return false; } void CompMeshIterProperties(dmGameObject::SceneNodePropertyIterator* pit, dmGameObject::SceneNode* node) { assert(node->m_Type == dmGameObject::SCENE_NODE_TYPE_COMPONENT); assert(node->m_ComponentType != 0); pit->m_Node = node; pit->m_Next = 0; pit->m_FnIterateNext = CompMeshIterPropertiesGetNext; } }
; A063709: Remainder when n^n is divided by n!. ; Submitted by Jamie Morken(s1) ; 0,0,0,3,16,5,576,2023,4096,227529,2656000,26301011,443667456,5268921853,294332416,820814907375,19909425135616,225992064764177,5838869363687424,43054524724611979,296380418621440000,18832310886273284421,53576448734169923584,17015858359950947150567,288304656211160151883776,7288322605031817287265625,18824064201506736912203776,1746670812000472446477892803,63810182502208914012541812736,8753881281266583330457534483469,193154930349790397155246080000000,23810489862645382516681164734431 mov $2,$0 pow $2,$0 seq $0,142 ; Factorial numbers: n! = 1*2*3*4*...*n (order of symmetric group S_n, number of permutations of n letters). mod $2,$0 mov $0,$2
//---------------------------------------------------------------------------- // Anti-Grain Geometry - Version 2.4 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) // // Permission to copy, use, modify, sell and distribute this software // is granted provided this copyright notice appears in all copies. // This software is provided "as is" without express or implied // warranty, and with no claim as to its suitability for any purpose. // //---------------------------------------------------------------------------- // Contact: mcseem@antigrain.com // mcseemagg@yahoo.com // http://www.antigrain.com //---------------------------------------------------------------------------- // // class bspline // //---------------------------------------------------------------------------- #include "agg_bspline.h" namespace agg { //------------------------------------------------------------------------ bspline::bspline() : m_max(0), m_num(0), m_x(0), m_y(0), m_last_idx(-1) { } //------------------------------------------------------------------------ bspline::bspline(int num) : m_max(0), m_num(0), m_x(0), m_y(0), m_last_idx(-1) { init(num); } //------------------------------------------------------------------------ bspline::bspline(int num, const float64* x, const float64* y) : m_max(0), m_num(0), m_x(0), m_y(0), m_last_idx(-1) { init(num, x, y); } //------------------------------------------------------------------------ void bspline::init(int max) { if(max > 2 && max > m_max) { m_am.resize(max * 3); m_max = max; m_x = &m_am[m_max]; m_y = &m_am[m_max * 2]; } m_num = 0; m_last_idx = -1; } //------------------------------------------------------------------------ void bspline::add_point(float64 x, float64 y) { if(m_num < m_max) { m_x[m_num] = x; m_y[m_num] = y; ++m_num; } } //------------------------------------------------------------------------ void bspline::prepare() { if(m_num > 2) { int i, k, n1; float64* temp; float64* r; float64* s; float64 h, p, d, f, e; for(k = 0; k < m_num; k++) { m_am[k] = 0.0; } n1 = 3 * m_num; pod_array<float64> al(n1); temp = &al[0]; for(k = 0; k < n1; k++) { temp[k] = 0.0; } r = temp + m_num; s = temp + m_num * 2; n1 = m_num - 1; d = m_x[1] - m_x[0]; e = (m_y[1] - m_y[0]) / d; for(k = 1; k < n1; k++) { h = d; d = m_x[k + 1] - m_x[k]; f = e; e = (m_y[k + 1] - m_y[k]) / d; al[k] = d / (d + h); r[k] = 1.0 - al[k]; s[k] = 6.0 * (e - f) / (h + d); } for(k = 1; k < n1; k++) { p = 1.0 / (r[k] * al[k - 1] + 2.0); al[k] *= -p; s[k] = (s[k] - r[k] * s[k - 1]) * p; } m_am[n1] = 0.0; al[n1 - 1] = s[n1 - 1]; m_am[n1 - 1] = al[n1 - 1]; for(k = n1 - 2, i = 0; i < m_num - 2; i++, k--) { al[k] = al[k] * al[k + 1] + s[k]; m_am[k] = al[k]; } } m_last_idx = -1; } //------------------------------------------------------------------------ void bspline::init(int num, const float64* x, const float64* y) { if(num > 2) { init(num); int i; for(i = 0; i < num; i++) { add_point(*x++, *y++); } prepare(); } m_last_idx = -1; } //------------------------------------------------------------------------ void bspline::bsearch(int n, const float64 *x, float64 x0, int *i) { int j = n - 1; int k; for(*i = 0; (j - *i) > 1; ) { if(x0 < x[k = (*i + j) >> 1]) j = k; else *i = k; } } //------------------------------------------------------------------------ float64 bspline::interpolation(float64 x, int i) const { int j = i + 1; float64 d = m_x[i] - m_x[j]; float64 h = x - m_x[j]; float64 r = m_x[i] - x; float64 p = d * d / 6.0; return (m_am[j] * r * r * r + m_am[i] * h * h * h) / 6.0 / d + ((m_y[j] - m_am[j] * p) * r + (m_y[i] - m_am[i] * p) * h) / d; } //------------------------------------------------------------------------ float64 bspline::extrapolation_left(float64 x) const { float64 d = m_x[1] - m_x[0]; return (-d * m_am[1] / 6 + (m_y[1] - m_y[0]) / d) * (x - m_x[0]) + m_y[0]; } //------------------------------------------------------------------------ float64 bspline::extrapolation_right(float64 x) const { float64 d = m_x[m_num - 1] - m_x[m_num - 2]; return (d * m_am[m_num - 2] / 6 + (m_y[m_num - 1] - m_y[m_num - 2]) / d) * (x - m_x[m_num - 1]) + m_y[m_num - 1]; } //------------------------------------------------------------------------ float64 bspline::get(float64 x) const { if(m_num > 2) { int i; // Extrapolation on the left if(x < m_x[0]) return extrapolation_left(x); // Extrapolation on the right if(x >= m_x[m_num - 1]) return extrapolation_right(x); // Interpolation bsearch(m_num, m_x, x, &i); return interpolation(x, i); } return 0.0; } //------------------------------------------------------------------------ float64 bspline::get_stateful(float64 x) const { if(m_num > 2) { // Extrapolation on the left if(x < m_x[0]) return extrapolation_left(x); // Extrapolation on the right if(x >= m_x[m_num - 1]) return extrapolation_right(x); if(m_last_idx >= 0) { // Check if x is not in current range if(x < m_x[m_last_idx] || x > m_x[m_last_idx + 1]) { // Check if x between next points (most probably) if(m_last_idx < m_num - 2 && x >= m_x[m_last_idx + 1] && x <= m_x[m_last_idx + 2]) { ++m_last_idx; } else if(m_last_idx > 0 && x >= m_x[m_last_idx - 1] && x <= m_x[m_last_idx]) { // x is between pevious points --m_last_idx; } else { // Else perform full search bsearch(m_num, m_x, x, &m_last_idx); } } return interpolation(x, m_last_idx); } else { // Interpolation bsearch(m_num, m_x, x, &m_last_idx); return interpolation(x, m_last_idx); } } return 0.0; } }
TITLE CMDLINE - Copyright (c) SLR Systems 1994 INCLUDE MACROS INCLUDE IO_STRUC INCLUDE MODULES INCLUDE EXES PUBLIC PROCESS_POSIT_CMDLINE,SET_TINY,SET_BINARY,GETNST_SLASH,GET_NUMBER16,SET_STACK_1,GET_NUMBER ;basic command line functions EXTERNDEF TFLAGS:BYTE .DATA EXTERNDEF OUTBUF:BYTE,SYMBOL_TEXT:BYTE,RELOAD_BYTE:BYTE,MODEL_FAR_BYTE:BYTE,DEBUG_BYTE:BYTE,CACHE_BYTE:BYTE EXTERNDEF COMPRESS_BYTE:BYTE,CV_INFO_TYPE:BYTE,CODEVIEW_BYTE:BYTE,LAST_DELIM:BYTE,TD_INFO_TYPE:BYTE EXTERNDEF DEBUG_TYPES_SELECTED:BYTE,EXETYPE_FLAG:BYTE,EXETYPE_CMDLINE_FLAG:BYTE EXTERNDEF FILESTUFF_PTR:DWORD,OVERLAY_INTERRUPT_NUMBER:DWORD,RELOAD_DEPTH:DWORD,INPTR1:DWORD,CACHE_ORDER:DWORD EXTERNDEF PLINK_LEVEL:DWORD,DONT_PACK:DWORD,PACKCODE:DWORD,PACKDATA:DWORD,PADCODE:DWORD,PADDATA:DWORD EXTERNDEF SYMBOL_LENGTH:DWORD,FLAG_0C:DWORD,_OUTFILE_GINDEX:DWORD,MAPFILE_GINDEX:DWORD,TOKSTR:DWORD EXTERNDEF CURN_SECTION_GINDEX:DWORD,PACK_DEFAULT_SIZE:DWORD,TLINK_OUTTYPE:DWORD,IMPLIB_PAGESIZE:DWORD EXTERNDEF IMPLIB_FILE_GINDEX:DWORD,IMPLIB_COFF_FILE_GINDEX:DWORD,IMPDEF_FILE_GINDEX:DWORD EXTERNDEF CACHE_REG_TABLE:DWORD,CACHE_UMB_TABLE:DWORD EXTERNDEF CACHE_EMS_TABLE:DWORD,CACHE_XMS_TABLE:DWORD,CURN_OUTFILE:DWORD,SYS_BASE:DWORD,DEFFILE:DWORD EXTERNDEF STACK_SIZE:DWORD,PE_BASE:DWORD,HEAP_SIZE:DWORD,ALIGNMENT:DWORD,ENTRYPOINT_TXT:DWORD EXTERNDEF EXEHEADER:EXE,NEXEHEADER:NEXE,PEXEHEADER:PEXE,NULNAM:NFN_STRUCT,FILNAM:NFN_STRUCT,SRCNAM:NFN_STRUCT EXTERNDEF SYMBOL_TPTR:TPTR_STRUCT externdef PM_TYPES:DWORD externdef PM_STG:byte externdef VIO_STG:byte externdef NOVIO_STG:byte externdef NT_STG:byte externdef OS2_STG:byte externdef WINDOWS_STG:byte externdef DOS_STG:byte externdef DOS4_STG:byte externdef DOSX_STG:byte externdef UNKNOWN_STG:byte externdef FULL_TEXT:byte externdef ADDRESS_TEXT:byte externdef GROUP_TEXT:byte externdef NOGROUP_TEXT:byte externdef NOEXE_TXT:byte externdef I386_TXT:byte .CODE FILEPARSE_TEXT externdef printx:proc externdef _getcmd:proc externdef _set_prompt_mode:proc externdef _res_prompt_mode:proc EXTERNDEF _err_abort:proc,MOVE_FILNAM:PROC,SET_DEFAULTS:PROC,RES_LOGO_OUTPUT:PROC EXTERNDEF RES_ECHO_IND:PROC,NOIGNORECASE_PROC:PROC,HANDLE_RCS:PROC,MOVE_SOURCE_TO_FILNAM:PROC EXTERNDEF ERR_DSSI_SLASH_ABORT:PROC,SET_ECHO_IND:PROC,IGNORECASE_PROC:PROC,_abort:proc,_check_nul:proc EXTERNDEF NOCHECKSUM_PROC:PROC,RET_FALSE:PROC,LOUTALL_CON:PROC,_do_objs:proc EXTERNDEF YYLEX_FILENAME:PROC,PROCESS_FREE_CMDLINE:PROC,SCAN_HELPER:PROC,GETNST:PROC,GET_KEYWORD:PROC EXTERNDEF ERR_SYMBOL_TEXT_ABORT:PROC,VERBOSE_PROC:PROC,ERR_INBUF_ABORT:PROC,HELP_PROC_1:PROC EXTERNDEF SET_REORDER_ALLOWED:PROC,SILENT_PROC:PROC,RES_REORDER_ALLOWED:PROC,_filename_install:proc EXTERNDEF INSTALL_OUTFILE:PROC,_store_filnam:PROC,HANDLE_LIBS:PROC,_do_srcnam:proc,_do_search_library:proc EXTERNDEF DO_NEW_SECTION:PROC,VERIFY_SECTION:PROC,ENDAREA_PROC:PROC,REOPEN_AREA:PROC,LOWERCASE_PROC:PROC EXTERNDEF UPPERCASE_PROC:PROC,CHECKSUM_PROC:PROC,OVLCODEFIRST_PROC:PROC,OVLCODELAST_PROC:PROC EXTERNDEF ERR_SYMBOL_TEXT_RET:PROC,NONULLSDOSSEG_PROC:PROC,NOGROUPSTACK_PROC:PROC,GROUPSTACK_PROC:PROC EXTERNDEF ERRORDELETE_PROC:PROC,NOERRORDELETE_PROC:PROC,ERR_INBUF_RET:PROC,WARN_SYMBOL_TEXT_RET:PROC EXTERNDEF YYLEX_SYMBOL:PROC,FORCE_INSTALL_MODULE:PROC,DOSSEG_PROC:PROC,RC_PROTMODE:PROC,HANDLE_DEFS:PROC EXTERNDEF RES_PACKFUNCTIONS:PROC,SET_PACKFUNCTIONS:PROC,SEE_NEXT:PROC,MOVE_DEFAULT_FLAGS:PROC EXTERNDEF GET_NEXT:PROC,FORCE_SIGNON:PROC,HANDLE_STUB:PROC,GET_NUM_DOT_NUM:PROC EXTERNDEF GET_SYMBOL:PROC,SET_SUBSYSTEM:PROC,SET_SUBSYS_VERSION:PROC EXTERNDEF RCSTUFF:CMDLINE_STRUCT,IMPLIB_STUFF:CMDLINE_STRUCT,IMPDEF_STUFF:CMDLINE_STRUCT EXTERNDEF STUBSTUFF:CMDLINE_STRUCT,RESSTUFF:CMDLINE_STRUCT,OBJSTUFF:CMDLINE_STRUCT,LIBSTUFF:CMDLINE_STRUCT EXTERNDEF EXESTUFF:CMDLINE_STRUCT,MAPSTUFF:CMDLINE_STRUCT,DEFSTUFF:CMDLINE_STRUCT,OVLSTUFF:CMDLINE_STRUCT EXTERNDEF PATHSTUFF:CMDLINE_STRUCT EXTERNDEF CMDLIN_ERR:ABS,MISSING_COLON_ERR:ABS,ILL_NUMBER_ERR:ABS,DUP_CACHE_ERR:ABS,CACHE_VALUE_ERR:ABS EXTERNDEF SECTION_REQ_ERR:ABS,PAREN_NESTING_ERR:ABS,MULTIPLE_RC_ERR:ABS,TLINK_XTRA_ERR:ABS EXTERNDEF CANT_WINPACK_ERR:ABS,DUP_STUB_ERR:ABS PROCESS_POSIT_CMDLINE PROC ; ;PROCESS A POSITIONAL MS-STYLE CMDLINE ; ;NOW, START PARSING THE COMMAND INPUT... ; CALL PARSE_OBJS if fg_plink JC L99$ ;COMMAND WAS /FREEFORMAT endif CALL PARSE_OUTFILE CALL PARSE_MAPFILE CALL PARSE_LIBS if fg_segm OR fg_pe CALL PARSE_DEFFILE CALL PARSE_RCS endif RET if fg_plink L99$: JMP PROCESS_FREE_CMDLINE endif PROCESS_POSIT_CMDLINE ENDP PARSE_OBJS PROC NEAR ; ;HERE COME OBJS TO LINK ; MOV FILESTUFF_PTR,OFF OBJSTUFF CALL VERIFY_SECTION L1$: CALL GETNST_SLASH ;HANDLE ANY SLASH COMMANDS... JC L99$ ;COMMAND WAS /FREEFORMAT... CMP AL,',' JZ L65$ ;OK, GO READ .EXE FILE CMP AL,0DH JZ L4$ MOV LAST_DELIM,0 CMP AL,'+' JZ L3$ ;ALLOWS IGNORING A CR if fg_ov CMP AL,'(' JZ L5$ CMP AL,')' JZ L6$ endif CMP AL,';' JZ L7$ CMP AL,1AH JZ L7$ L2$: DEC INPTR1 RESS PLUS_FOUND MOV EAX,OFF OBJSTUFF CALL YYLEX_FILENAME MOV EAX,OFF FILNAM push EAX call _do_objs add ESP,4 JMP L1$ L99$: RESS PLUS_FOUND STC RET L65$: ; ;GOT A COMMA ;IF NEXT NON-BLANK IS A CR, DON'T COUNT IT... ; CMP LAST_DELIM,0DH ;IF LAST DELIMITER WAS A 0DH, SKIP THIS JMP L45$ L4$: ; ;FOUND CR ; CMP LAST_DELIM,',' L45$: MOV LAST_DELIM,0 JNZ L46$ if fg_td BITT TLINK_DEFAULT_MODE JNZ L46$ endif JMP L1$ L46$: MOV LAST_DELIM,AL CMP SRCNAM.NFN_PRIMLEN,0 ;IGNORE IF NO .OBJS YET JZ L1$ BITT PLUS_FOUND PUSHFD RESS PLUS_FOUND POPFD JZ L71$ if fg_td CMP AL,0DH ;PLUS OVERIDES A CR ALWAYS JZ L1$ BITT TLINK_DEFAULT_MODE ;IN TLINK MODE, THAT'S ALL IT OVERIDES JNZ L71$ endif JMP L1$ L3$: ; ;FOUND + ; SETT PLUS_FOUND JMP L1$ if fg_ov L5$: ; ;FOUND ( ; BITT PARSE_IN_OVERLAY ;IF ALREADY IN OVERLAY, ( IS FIRST CHAR OF FILENAME JNZ L2$ SETT PARSE_IN_OVERLAY CALL REOPEN_AREA CALL DO_NEW_SECTION ;SETUP NEW SECTION OR FNTBL+')',MASK FNTBL_ILLEGAL L59$: RESS PLUS_FOUND JMP L1$ L6$: ; ; ) IS END OF AN OVERLAY SECTION, UNLESS WE AREN'T IN ONE... ; BITT PARSE_IN_OVERLAY JZ L61$ RESS PARSE_IN_OVERLAY AND FNTBL+')',NOT MASK FNTBL_ILLEGAL CALL ENDAREA_PROC JMP L59$ endif L7$: DEC INPTR1 L71$: RESS PLUS_FOUND if fg_ov BITT PARSE_IN_OVERLAY JNZ L61$ endif RET if fg_ov L61$: MOV AL,PAREN_NESTING_ERR CALL ERR_INBUF_ABORT endif PARSE_OBJS ENDP GETNST_SLASH PROC ; ; ; L1$: CALL GETNST CMP AL,'/' JZ L5$ CMP AL,'-' JZ L5$ CLC RET if fg_td L3$: CALL PARSE_TLINK_SWITCH SETT SLASH_FOUND JMP L1$ endif L5$: ; ;PROCESS COMMANDS FROM COMMAND LINE... ;THIS IS JUMP TABLE HANDLER. ; ;COMMTBL LOOKS LIKE: ;COMMTBL DB 3 ;MAX LENGTH OF COMMAND ; DB 3 ;SIGNIFICANT CHARACTERS ; DW COPROC ;ROUTINE IF THIS COMMAND ; DB 'CO:' ;ASCII FOR COMMAND ; ; ETC ; ETC ;DS & ES ARE DGROUP ; RESS PLUS_FOUND MOV LAST_DELIM,0 CALL GET_KEYWORD ;PARSE IT OUT TO UPPER CASE XOR EAX,EAX MOV AL,SYMBOL_TEXT ;FIRST CHAR OF TOKEN if fg_td BITT TLINK_SYNTAX JNZ L3$ endif SUB AL,'A' ;DO TABLE LOOKUP ON START CMP AL,'Z'-'A' JA TRY_? if 1 mov EAX, OFF SYMBOL_TEXT push EAX call _getcmd add ESP,4 test EAX,EAX jz MS_BAD_CMD call EAX SETT SLASH_FOUND JMP L1$ else MOV ESI,MS_CMD_PTRS[EAX*4] ;START LOOKING HERE MS_CHECK_NEXT: MOV DL,[ESI] ;MAX LENGTH INC ESI AND EDX,03FH JZ MS_BAD_CMD ;END OF TABLE MOV BL,[ESI] INC ESI ;SIG_CHARS MOV ECX,EDX MOV EAX,ESI ADD ESI,4 MOV EDI,OFF SYMBOL_TEXT REPE CMPSB JZ MS_MATCHED ADD ESI,ECX ;ADJUST SI FOR NEXT TOKEN CMP BPTR [EDI-1],CH ;DID WE REACH END OF TOKEN? JNZ MS_CHECK_NEXT ;NO, TRY NEXT INC ECX SUB DL,CL CMP DL,BL ;IS IT AT LEAST MINMATCH LONG? JC MS_CHECK_NEXT MS_EXEC_THIS: push EAX call printx mov EAX,offset NOIGNORECASE_PROC push EAX call printx pop EAX pop EAX CALL DPTR [EAX] SETT SLASH_FOUND JMP L1$ MS_MATCHED: CMP [EDI],CL JNZ MS_CHECK_NEXT JMP MS_EXEC_THIS endif TRY_?: CMP AL,'?'-'A' JNZ MS_BAD_CMD JMP MS_HELP MS_BAD_CMD: ; ;SKIP TO END OF COMMAND... ; MOV AL,CMDLIN_ERR CALL WARN_SYMBOL_TEXT_RET JMP L1$ GETNST_SLASH ENDP PARSE_OUTFILE PROC NEAR ; ;GET NAME OF OUTPUT FILE (USE FIRST OBJ AS DEFAULT) ; MOV FILESTUFF_PTR,OFF EXESTUFF L1$: CALL GETNST_SLASH CMP AL,'+' JZ L1$ ;YEA, SKIP THOSE CMP AL,',' JZ L6$ ;GOT A COMMA CMP AL,0DH JZ L7$ L2$: DEC INPTR1 L3$: MOV EAX,OFF EXESTUFF CALL YYLEX_FILENAME MOV EAX,OFF FILNAM push ECX mov ECX,ESP push ECX push EAX call _filename_install add ESP,8 pop ECX ;CALL FILENAME_INSTALL ;EAX IS GINDEX, ECX IS FILE_LIST PHYS ASSUME ECX:PTR FILE_LIST_STRUCT OR [ECX].FILE_LIST_FLAGS,MASK FLF_RANDOM CALL INSTALL_OUTFILE ASSUME ECX:NOTHING MOV _OUTFILE_GINDEX,EAX MOV EAX,OFF FILNAM push EAX call _check_nul add ESP,4 MOV EAX,OFF FILNAM TEST [EAX].NFN_STRUCT.NFN_FLAGS,MASK NFN_NUL JNZ L5$ push EAX call _do_srcnam add ESP,4 L5$: ; ;(SE) Test for .DLL output (to avoid .def file) ; MOV EAX,OFF FILNAM ASSUME EAX:PTR NFN_STRUCT CMP [EAX].NFN_EXTLEN,4 JNE L51$ MOV ECX,[EAX].NFN_TOTAL_LENGTH LEA ECX,[EAX+ECX].NFN_TEXT MOV ECX,[ECX-4] OR ECX,20202000h CMP ECX,'lld.' JNE L51$ ASSUME EAX:NOTHING OR FLAG_0C,MASK APPTYPE ;OUTPUT A LIBRARY L51$: CALL GETNST_SLASH CMP AL,'+' JZ L5$ ;SKIP ANY TRAILING +'S CMP AL,0DH JZ L9$ CMP AL,',' JNZ L8$ ; ;MAKE SURE DEFAULT USED FOR MAP FILE ; SETT MAPFILE_SELECTED JMP L9$ L8$: DEC INPTR1 L9$: MOV LAST_DELIM,AL RET L6$: ; ;GOT A COMMA, SKIP IT IF WE JUST HAD A CR ; CMP LAST_DELIM,0DH JZ L3$ JMP L2$ L7$: ; ;GOT A CR, SKIP IT IF WE JUST HAD A COMMA ; CMP LAST_DELIM,',' JZ L3$ JMP L2$ PARSE_OUTFILE ENDP PARSE_MAPFILE PROC NEAR ; ;GET NAME OF MAP FILE (USE OUTFILE AS DEFAULT IF SELECTED) ; MOV FILESTUFF_PTR,OFF MAPSTUFF L1$: CALL GETNST_SLASH CMP AL,'+' JZ L1$ ;SKIP ANY LEADING +'S CMP AL,',' JZ L6$ CMP AL,0DH JZ L7$ L2$: DEC INPTR1 L3$: MOV EAX,OFF MAPSTUFF CALL YYLEX_FILENAME SETT SKIP_OUTFILE_LINK MOV EAX,OFF FILNAM push ECX mov ECX,ESP push ECX push EAX call _filename_install add ESP,8 pop ECX ;CALL FILENAME_INSTALL ;EAX IS GINDEX, ECX IS FILE_LIST PHYS CALL INSTALL_OUTFILE ;THIS IS AN OUTPUT FILE MOV MAPFILE_GINDEX,EAX XOR ECX,ECX MOV EAX,OFF FILNAM RESS SKIP_OUTFILE_LINK,CL RESS MAPFILE_SELECTED,CL CMP [EAX].NFN_STRUCT.NFN_PRIMLEN,ECX JZ L5$ push EAX call _check_nul add ESP,4 MOV EAX,OFF FILNAM TEST [EAX].NFN_STRUCT.NFN_FLAGS,MASK NFN_NUL JNZ L5$ SETT MAPFILE_SELECTED SETT SEGMENTS_MAP L5$: CALL GETNST_SLASH CMP AL,'+' JZ L5$ ;SKIP ANY TRAILING +'S CMP AL,0DH JZ L9$ CMP AL,',' JZ L9$ L8$: DEC INPTR1 L9$: MOV LAST_DELIM,AL RET L6$: ; ;GOT A COMMA, SKIP IT IF WE JUST HAD A CR ; CMP LAST_DELIM,0DH JZ L3$ JMP L2$ L7$: ; ;GOT A CR, SKIP IT IF WE JUST HAD A COMMA ; CMP LAST_DELIM,',' JZ L3$ JMP L2$ PARSE_MAPFILE ENDP PARSE_DEFFILE PROC NEAR ; ;GET NAME OF MAP FILE (USE OUTFILE AS DEFAULT IF SELECTED) ; MOV FILESTUFF_PTR,OFF DEFSTUFF L1$: CALL GETNST_SLASH CMP AL,'+' JZ L1$ ;SKIP ANY LEADING +'S if fg_def CMP AL,',' JZ L6$ CMP AL,0DH JZ L7$ L2$: DEC INPTR1 L3$: MOV EAX,OFF DEFSTUFF CALL YYLEX_FILENAME MOV EAX,OFF FILNAM push EAX call _store_filnam add ESP,4 XOR ECX,ECX MOV DEFFILE,EAX MOV EAX,OFF FILNAM RESS DEFFILE_SELECTED,CL CMP [EAX].NFN_STRUCT.NFN_PRIMLEN,ECX JZ L5$ push EAX call _check_nul add ESP,4 MOV EAX,OFF FILNAM TEST [EAX].NFN_STRUCT.NFN_FLAGS,MASK NFN_NUL JNZ L5$ SETT DEFFILE_SELECTED L5$: CALL GETNST_SLASH CMP AL,'+' JZ L5$ ;SKIP ANY TRAILING +'S CMP AL,',' JZ L9$ CMP AL,0DH JZ L9$ DEC INPTR1 L9$: endif MOV LAST_DELIM,AL RET if fg_def L6$: ; ;GOT A COMMA, SKIP IT IF WE JUST HAD A CR ; CMP LAST_DELIM,0DH JZ L3$ JMP L2$ L7$: ; ;GOT A CR, SKIP IT IF WE JUST HAD A COMMA ; CMP LAST_DELIM,',' JZ L3$ JMP L2$ endif PARSE_DEFFILE ENDP PARSE_LIBS PROC NEAR ; ;GET NAMES OF LIBRARIES TO SEARCH ; MOV FILESTUFF_PTR,OFF LIBSTUFF L1$: CALL GETNST_SLASH CMP AL,',' JZ L6$ ;SKIP COMMA CMP AL,0DH JZ L4$ ;TERMINATE IF PLUS NOT FOUND MOV LAST_DELIM,0 CMP AL,'+' JZ L3$ ;FLAG + FOUND DEC INPTR1 CMP AL,';' JZ L9$ CMP AL,1AH JZ L9$ RESS PLUS_FOUND MOV EAX,OFF LIBSTUFF CALL YYLEX_FILENAME MOV EAX,OFF FILNAM CALL HANDLE_LIBS JMP L1$ L3$: SETT PLUS_FOUND JMP L1$ L6$: ; ;COMMA FOUND ; CMP LAST_DELIM,0DH JMP L41$ L4$: ; ;CR FOUND ; CMP LAST_DELIM,',' L41$: MOV LAST_DELIM,0 JNZ L45$ if fg_td BITT TLINK_DEFAULT_MODE JNZ L45$ endif JMP L1$ L45$: MOV LAST_DELIM,AL BITT PLUS_FOUND PUSHFD RESS PLUS_FOUND POPFD JZ L71$ if fg_td CMP AL,0DH ;PLUS OVERIDES A CR ALWAYS JZ L1$ BITT TLINK_DEFAULT_MODE ;IN TLINK MODE, THAT'S ALL IT OVERIDES JNZ L71$ endif JMP L1$ L71$: RET L9$: RESS PLUS_FOUND RET PARSE_LIBS ENDP PARSE_RCS PROC NEAR ; ;GET NAMES OF .RES FILES TO BIND ; MOV FILESTUFF_PTR,OFF RESSTUFF L1$: CALL GETNST_SLASH CMP AL,',' JZ L6$ ;SKIP COMMA CMP AL,0DH JZ L4$ ;TERMINATE IF PLUS NOT FOUND MOV LAST_DELIM,0 CMP AL,'+' JZ L3$ ;FLAG + FOUND DEC INPTR1 CMP AL,';' JZ L9$ CMP AL,1AH JZ L9$ RESS PLUS_FOUND SETT RC_SUPPLIED MOV EAX,OFF RESSTUFF CALL YYLEX_FILENAME MOV EAX,OFF FILNAM CALL HANDLE_RCS JMP L1$ L3$: SETT PLUS_FOUND JMP L1$ L6$: ; ;COMMA FOUND ; CMP LAST_DELIM,0DH JMP L41$ L4$: ; ;CR FOUND ; CMP LAST_DELIM,',' L41$: MOV LAST_DELIM,0 JNZ L45$ if fg_td BITT TLINK_DEFAULT_MODE JNZ L45$ endif JMP L1$ L45$: MOV LAST_DELIM,AL BITT PLUS_FOUND PUSHFD RESS PLUS_FOUND POPFD JZ L71$ if fg_td CMP AL,0DH ;PLUS OVERIDES A CR ALWAYS JZ L1$ BITT TLINK_DEFAULT_MODE ;IN TLINK MODE, THAT'S ALL IT OVERIDES JNZ L71$ endif JMP L1$ L71$: RET L9$: RESS PLUS_FOUND RET PARSE_RCS ENDP MAKE_MAPOUT PROC ; PUSHM EDI,ESI SETT MAPFILE_SELECTED SETT SYMBOLS_OUT L1$: CALL FIX_GET_COLON JNZ L3$ CALL GET_KEYWORD MOV EAX,SYMBOL_LENGTH ;AT LEAST THIS MANY MUST MATCH MOV ESI,OFF FULL_TEXT MOV ECX,EAX MOV EDI,OFF SYMBOL_TEXT TEST ECX,ECX MOV EDX,EDI JZ L4$ REPE CMPSB JNZ L5$ SETT DETAILEDMAP_FLAG SETT ALPHA_ORDER_ALSO JMP L1$ L3$: POPM ESI,EDI RET L4$: POPM ESI,EDI MOV AL,CMDLIN_ERR CALL ERR_INBUF_RET RET L5$: MOV ECX,EAX ;AT LEAST THIS MANY MUST MATCH MOV EDI,EDX MOV ESI,OFF ADDRESS_TEXT REPE CMPSB JNZ L51$ RESS ALPHA_ORDER_ALSO JMP L1$ L51$: MOV ECX,EAX ;AT LEAST THIS MANY MUST MATCH MOV EDI,EDX MOV ESI,OFF GROUP_TEXT REPE CMPSB JNZ L52$ SETT PRINT_GROUP JMP L1$ L52$: MOV ECX,EAX ;AT LEAST THIS MANY MUST MATCH MOV EDI,EDX MOV ESI,OFF NOGROUP_TEXT REPE CMPSB JNZ L53$ RESS PRINT_GROUP JMP L1$ L53$: L59$: CALL GET_NUMBER1 TEST EAX,EAX JNZ L6$ RESS ALPHA_ORDER_ALSO L6$: JMP L1$ MAKE_MAPOUT ENDP GET_NUMBER PROC ; ;MS FORMAT NUMBER ; CALL GET_KEYWORD GET_NUMBER1 LABEL PROC PUSHM ESI,EBX MOV ESI,OFF SYMBOL_TEXT XOR EAX,EAX XOR EBX,EBX XOR ECX,ECX MOV BL,[ESI] MOV ECX,10 SUB BL,30H INC ESI CMP BL,CL JA GN_ERROR OR BL,BL JNZ GET_DECIMAL MOV BL,[ESI] INC ESI MOV CL,8 CMP BL,'X' JZ GET_HEX CMP BL,'x' JNZ GET_OCTAL GET_HEX: MOV CL,16 G_LOOP: MOV BL,[ESI] INC ESI GET_OCTAL: SUB BL,30H CMP BL,0AH JC GET_DECIMAL SUB BL,7 CMP BL,0AH JC NUMBER_DONE CMP BL,10H ;MUST BE 0A-0F JC GET_DECIMAL CMP BL,'a'-30H-7 JC NUMBER_DONE CMP BL,'f'-30H-7 JA NUMBER_DONE SUB BL,20H GET_DECIMAL: CMP BL,CL JNC NUMBER_DONE MUL ECX JC L9$ ADD EAX,EBX JNC G_LOOP L9$: GN_ERROR:: MOV AL,ILL_NUMBER_ERR CALL ERR_SYMBOL_TEXT_ABORT NUMBER_DONE: SUB ESI,OFF SYMBOL_TEXT+1 ;RESTORE CHARACTERS NOT PROCESSED POP EBX SUB ESI,SYMBOL_LENGTH ADD INPTR1,ESI POP ESI RET GET_NUMBER ENDP GET_COLON_NUMBER16 PROC CALL GET_COLON_NUMBER TEST EAX,0FFFF0000H JNZ GN_ERROR RET GET_COLON_NUMBER16 ENDP GET_NUMBER16 PROC CALL GET_NUMBER TEST EAX,0FFFF0000H JNZ GN_ERROR RET GET_NUMBER16 ENDP GET_COLON_NUMBER PROC ; ; ; CALL CHECK_COLON JMP GET_NUMBER GET_COLON_NUMBER ENDP MS_HELP PROC ; ;PRINT HELP MESSAGE ;PROCESS THROUGH OTHER TABLE... ; ;MOV EAX,OFF MS_CMD_PTRS JMP HELP_PROC_1 MS_HELP ENDP SET_DEBUGALL PROC ; ; ; MOV AL,-1 DBG_SET:: OR DEBUG_TYPES_SELECTED,AL RET SET_DEBUGALL ENDP SET_DEBUGBROWSERDEFS PROC ; ; ; MOV AL,MASK FL_DEBUG_BROWSERDEFS JMP DBG_SET SET_DEBUGBROWSERDEFS ENDP SET_DEBUGBROWSERREFS PROC ; ; ; MOV AL,MASK FL_DEBUG_BROWSERREFS JMP DBG_SET SET_DEBUGBROWSERREFS ENDP SET_DEBUGCOVERAGES PROC ; ; ; MOV AL,MASK FL_DEBUG_COVERAGES JMP DBG_SET SET_DEBUGCOVERAGES ENDP SET_DEBUGLOCALS PROC ; ; ; MOV AL,MASK FL_DEBUG_LOCALS JMP DBG_SET SET_DEBUGLOCALS ENDP SET_DEBUGLINNUMS PROC ; ; ; MOV AL,MASK FL_DEBUG_LINNUMS JMP DBG_SET SET_DEBUGLINNUMS ENDP SET_DEBUGPUBLICS PROC ; ; ; MOV AL,MASK FL_DEBUG_PUBLICS JMP DBG_SET SET_DEBUGPUBLICS ENDP SET_DEBUGTYPES PROC ; ; ; MOV AL,MASK FL_DEBUG_TYPES JMP DBG_SET SET_DEBUGTYPES ENDP RES_DEBUGALL PROC ; ; ; MOV AL,0 DBG_CLEAR:: AND DEBUG_TYPES_SELECTED,AL SETT FANCY_DEBUG RET RES_DEBUGALL ENDP RES_DEBUGBROWSERDEFS PROC ; ; ; MOV AL,NOT MASK FL_DEBUG_BROWSERDEFS JMP DBG_CLEAR RES_DEBUGBROWSERDEFS ENDP RES_DEBUGBROWSERREFS PROC ; ; ; MOV AL,NOT MASK FL_DEBUG_BROWSERREFS JMP DBG_CLEAR RES_DEBUGBROWSERREFS ENDP RES_DEBUGCOVERAGES PROC ; ; ; MOV AL,NOT MASK FL_DEBUG_COVERAGES JMP DBG_CLEAR RES_DEBUGCOVERAGES ENDP RES_DEBUGLOCALS PROC ; ; ; MOV AL,NOT MASK FL_DEBUG_LOCALS JMP DBG_CLEAR RES_DEBUGLOCALS ENDP RES_DEBUGLINNUMS PROC ; ; ; MOV AL,NOT MASK FL_DEBUG_LINNUMS JMP DBG_CLEAR RES_DEBUGLINNUMS ENDP RES_DEBUGPUBLICS PROC ; ; ; MOV AL,NOT MASK FL_DEBUG_PUBLICS JMP DBG_CLEAR RES_DEBUGPUBLICS ENDP RES_DEBUGTYPES PROC ; ; ; MOV AL,NOT MASK FL_DEBUG_TYPES JMP DBG_CLEAR RES_DEBUGTYPES ENDP HANDLE_DEBUGFILES PROC ; ; ; if any_overlays CALL FIX_GET_COLON JNZ L9$ else CALL CHECK_COLON endif SETT FANCY_DEBUG L1$: MOV EAX,OFF OBJSTUFF CALL YYLEX_FILENAME MOV EAX,OFF FILNAM push ECX mov ECX,ESP push ECX push EAX call _filename_install add ESP,8 pop ECX ;CALL FILENAME_INSTALL ;THAT FILE... OR [ECX].FILE_LIST_STRUCT.FILE_LIST_PLINK_FLAGS,MASK FL_DEBUG_COVERAGES+MASK FL_DEBUG_LINNUMS+MASK FL_DEBUG_LOCALS+ \ MASK FL_DEBUG_PUBLICS+MASK FL_DEBUG_TYPES+MASK FL_DEBUG_BROWSERDEFS+ \ MASK FL_DEBUG_BROWSERREFS CALL FIX_GET_COLON JZ L1$ RET if any_overlays L9$: SETT DEBUG_FLAG MOV DEBUG_BYTE,'Y' RET endif HANDLE_DEBUGFILES ENDP HANDLE_DEBUGMODULES PROC ; ; ; if any_overlays CALL FIX_GET_COLON JNZ L9$ else CALL CHECK_COLON endif SETT FANCY_DEBUG L1$: CALL YYLEX_SYMBOL ; MOV EAX,OFF SYMBOL_TPTR CALL FORCE_INSTALL_MODULE ;THAT FILE... ; ; ; OR [ECX].MODULE_STRUCT._M_FLAGS,MASK M_DEBUG_GLOBAL CALL FIX_GET_COLON JZ L1$ RET if any_overlays L9$: SETT DEBUG_FLAG MOV DEBUG_BYTE,'Y' RET endif HANDLE_DEBUGMODULES ENDP SET_ENTRYPOINT PROC ; ; ; CALL CHECK_COLON CALL GET_SYMBOL ;PARSE A SYMBOL (NO TRANSLATE) MOV EAX,SYMBOL_LENGTH PUSH EDI MOV ESI,OFF SYMBOL_TEXT MOV ECX,EAX ADD EAX,4 PUSH ESI P1ONLY_POOL_ALLOC MOV ENTRYPOINT_TXT,EAX MOV [EAX],ECX LEA EDI,[EAX+4] REP MOVSB POPM ESI,EDI RET SET_ENTRYPOINT ENDP CHECK_COLON PROC CALL FIX_GET_COLON JNZ COLON_EXP RET COLON_EXP LABEL PROC MOV AL,MISSING_COLON_ERR JMP ERR_SYMBOL_TEXT_ABORT CHECK_COLON ENDP ONERROR_PROC PROC ; ;ONERROR:NOEXE ; CALL CHECK_COLON ;MUST HAVE A COLON CALL GET_KEYWORD ;DOES UPPERCASE PUSHM EDI,ESI MOV EAX,SYMBOL_LENGTH MOV EDI,OFF NOEXE_TXT TEST EAX,EAX JZ L9$ MOV ECX,EAX MOV ESI,OFF SYMBOL_TEXT REPE CMPSB ;CX BYTES MUST MATCH JNZ L9$ CALL ERRORDELETE_PROC POPM ESI,EDI RET L9$: POPM ESI,EDI MOV AL,CMDLIN_ERR CALL ERR_INBUF_RET RET ONERROR_PROC ENDP if fg_segm PMTYPE_PROC PROC ; ;PMTYPE:[PM | VIO | NOVIO] ; CALL CHECK_COLON ;MUST HAVE A COLON CALL GET_KEYWORD PUSHM EDI,ESI,EBX MOV EBX,OFF PM_TYPES MOV EDX,3 ;3 TYPES TO CHECK L1$: MOV ESI,[EBX] MOV ECX,SYMBOL_LENGTH;AT LEAST THIS MANY MUST MATCH MOV EDI,OFF SYMBOL_TEXT TEST ECX,ECX JZ L4$ REPE CMPSB MOV EAX,[EBX+4] JZ L5$ ADD EBX,8 DEC EDX JNZ L1$ L4$: MOV AL,CMDLIN_ERR CALL ERR_INBUF_RET POPM EBX,ESI,EDI RET L5$: POPM EBX,ESI,EDI OR FLAG_0C,EAX RET PMTYPE_PROC ENDP endif EXETYPE_PROC PROC ; ;EXETYPE:[OS2 | WINDOWS | DOS4 | UNKNOWN | DOS | NT | DOSX] ; CALL CHECK_COLON ;MUST HAVE A COLON CALL GET_KEYWORD PUSHM EDI,ESI,EBX MOV EBX,OFF EXE_TYPES MOV EDX,N_EXE_TYPES ;6 TYPES TO CHECK L1$: MOV ESI,[EBX] MOV ECX,SYMBOL_LENGTH;AT LEAST THIS MANY MUST MATCH MOV EDI,OFF SYMBOL_TEXT TEST ECX,ECX JZ L4$ REPE CMPSB MOV EAX,[EBX+4] JZ L5$ ADD EBX,8 DEC EDX JNZ L1$ L4$: MOV AL,CMDLIN_ERR CALL ERR_INBUF_RET POPM EBX,ESI,EDI RET L5$: POPM EBX,ESI,EDI MOV EXETYPE_CMDLINE_FLAG,AL RET EXETYPE_PROC ENDP SUBSYSTEM_PROC PROC ; ;SUBSYSTEM:[OS2 | WINDOWS | DOS4 | UNKNOWN | DOS | NT | DOSX] ; CALL CHECK_COLON ;MUST HAVE A COLON CALL GET_KEYWORD PUSHM EDI,ESI,EBX MOV EBX,OFF SUBSYS_TYPES MOV EDX,N_SUBSYS_TYPES ;6 TYPES TO CHECK L1$: MOV ESI,[EBX] MOV ECX,SYMBOL_LENGTH ;AT LEAST THIS MANY MUST MATCH MOV EDI,OFF SYMBOL_TEXT TEST ECX,ECX JZ L4$ REPE CMPSB MOV EAX,[EBX+4] JZ L5$ ADD EBX,8 DEC EDX JNZ L1$ L4$: MOV AL,CMDLIN_ERR CALL ERR_INBUF_RET POPM EBX,ESI,EDI RET L5$: CALL SET_SUBSYSTEM JNZ L4$ CALL FIX_GET_COLON JNZ L9$ CALL GET_NUM_DOT_NUM MOV ECX,EDX CALL SET_SUBSYS_VERSION JNZ L4$ L9$: POPM EBX,ESI,EDI RET SUBSYSTEM_PROC ENDP FIX_GET_COLON PROC ; ; ; CALL GETNST CMP AL,':' JZ L9$ DEC INPTR1 L9$: RET FIX_GET_COLON ENDP SET_EMSMAXSIZE PROC ; CALL GET_COLON_NUMBER16 ; MOV EMS_MAX_1K_BLOCKS,AX RET SET_EMSMAXSIZE ENDP SET_XMSMAXSIZE PROC ; CALL GET_COLON_NUMBER16 ; MOV XMS_MAX_1K_BLOCKS,AX RET SET_XMSMAXSIZE ENDP SET_EXEPACK PROC ; ; ; SETT EXEPACK_SELECTED SET_EXEPACK_1 LABEL PROC CALL FIX_GET_COLON JZ L1$ RET L1$: CALL GET_NUMBER INC EAX ;FORCE TO # OF WORDS... AND AL,0FEH CMP DONT_PACK,EAX JA L2$ MOV DONT_PACK,EAX L2$: RET SET_EXEPACK ENDP SET_WINPACK PROC ; ; ; if fg_virt AND (NOT debug) MOV AL,CANT_WINPACK_ERR push EAX call _err_abort else SETT WINPACK_SELECTED endif SET_WINPACK ENDP RES_DEFAULTLIBRARYSEARCH PROC ; ; ; CALL FIX_GET_COLON JZ L1$ RESS DEFAULTLIBRARYSEARCH_FLAG RET L1$: ; ;NEED TO DISABLE A SINGLE LIBRARY NAME... ;OK, ; SETT DOING_NODEF MOV EAX,OFF LIBSTUFF CALL YYLEX_FILENAME ;NOW, WAS A PATH SUPPLIED? MOV EAX,OFF FILNAM push EAX call _do_search_library add ESP,4 RESS DOING_NODEF RET RES_DEFAULTLIBRARYSEARCH ENDP if fg_segm OR fg_pe RC_PROC PROC ; ;HANDLE SUPPLYING AN RC FILE FOR INCLUSION... ; BITT RC_SUPPLIED JNZ L0$ SETT RC_SUPPLIED SETT RC_REORDER OR FLAG_0C,MASK APPWINFLAGS L0$: CALL FIX_GET_COLON JZ L1$ CMP AL,'-' JZ L2$ RET L9$: MOV AL,MULTIPLE_RC_ERR push EAX call _err_abort L1$: MOV EAX,OFF RCSTUFF CALL YYLEX_FILENAME MOV EAX,OFF FILNAM CALL HANDLE_RCS JMP L0$ L2$: INC INPTR1 CALL GET_KEYWORD MOV ECX,SYMBOL_LENGTH MOV EAX,DPTR SYMBOL_TEXT DEC ECX JNZ L25$ CMP AL,'a' JC L11$ CMP AL,'z' JA L11$ SUB AL,20H L11$: CMP AL,'E' MOV EBX,MASK APP386 ;DRIVER USES EMS JZ L19$ CMP AL,'L' MOV EBX,MASK APP86 ;APP USES EMS JZ L19$ CMP AL,'M' MOV EBX,MASK APP286 ;MULTIPLE INSTANCE (MORE EMS JUNK) JZ L19$ CMP AL,'P' MOV EBX,MASK APP?? ;PRIVATE LIBRARY JZ L19$ CMP AL,'T' ;PROTMODE ONLY JZ L16$ CMP AL,'K' JNZ L95$ RESS RC_REORDER JMP L0$ L16$: CALL RC_PROTMODE JMP L0$ L19$: OR FLAG_0C,EBX JMP L0$ L95$: MOV AL,CMDLIN_ERR CALL ERR_INBUF_RET RET L25$: DEC ECX JNZ L95$ CMP AX,'04' MOV EBX,400H JZ L27$ CMP AX,'03' MOV BH,3 JZ L27$ CMP AX,'13' JNZ L95$ MOV BL,0AH L27$: BITT WINVER_SELECTED JNZ L28$ MOV NEXEHEADER._NEXE_WINVER_INT,BH SETT WINVER_SELECTED MOV NEXEHEADER._NEXE_WINVER_FRAC,BL L28$: JMP L0$ RC_PROC ENDP STUB_PROC PROC ; ;HANDLE SUPPLYING A STUB FILE FOR INCLUSION... ; CALL CHECK_COLON MOV EAX,OFF STUBSTUFF CALL YYLEX_FILENAME BITT STUB_SUPPLIED JNZ L9$ BITT STUB_NONE JNZ L9$ MOV EAX,OFF FILNAM.NFN_TEXT ADD EAX,FILNAM.NFN_PATHLEN MOV EAX,[EAX] CMP EAX,'ENON' JZ L5$ CMP EAX,'enon' JZ L5$ SETT STUB_SUPPLIED MOV EAX,OFF FILNAM JMP HANDLE_STUB L5$: SETT STUB_NONE RET L9$: MOV AL,DUP_STUB_ERR JMP ERR_INBUF_RET STUB_PROC ENDP if V5 PUBLIC PARSE_IMPDEF_FILENAME,PARSE_IMPLIB_FILENAME,PARSE_IMPLIB_COFF_FILENAME SET_IMPDEF PROC ; ;POSSIBLY :FILENAME, .DIN OUTPUT DESCRIBING THIS .DLL ; SETT IMPDEF_FLAG ;HE WANTS US TO BUILD .DIN CALL FIX_GET_COLON JZ L1$ RET L1$: CALL PARSE_IMPDEF_FILENAME RET SET_IMPDEF ENDP PARSE_IMPDEF_FILENAME PROC ; ; ; MOV EAX,OFF IMPDEF_STUFF ;LIKE DEF, BUT USE PRIMARY NAME AS DEFAULT CALL YYLEX_FILENAME SETT SKIP_OUTFILE_LINK MOV EAX,OFF FILNAM push ECX mov ECX,ESP push ECX push EAX call _filename_install add ESP,8 pop ECX ;CALL FILENAME_INSTALL ;AX IS GINDEX, DS:BX IS FILE_LIST PHYS CALL INSTALL_OUTFILE ;THIS IS AN OUTPUT FILE MOV IMPDEF_FILE_GINDEX,EAX RESS SKIP_OUTFILE_LINK RET PARSE_IMPDEF_FILENAME ENDP SET_IMPLIB PROC ; ;POSSIBLY :FILENAME, .LIB OUTPUT DESCRIBING THIS .DLL ; SETT IMPLIB_FLAG ;HE WANTS US TO BUILD .LIB CALL FIX_GET_COLON JZ L1$ RET L1$: CALL PARSE_IMPLIB_FILENAME RET SET_IMPLIB ENDP PARSE_IMPLIB_FILENAME PROC ; ; ; MOV EAX,OFF IMPLIB_STUFF ;LIKE LIB, BUT USE PRIMARY NAME AS DEFAULT CALL YYLEX_FILENAME SETT SKIP_OUTFILE_LINK MOV EAX,OFF FILNAM push ECX mov ECX,ESP push ECX push EAX call _filename_install add ESP,8 pop ECX ;CALL FILENAME_INSTALL ;AX IS GINDEX, DS:BX IS FILE_LIST PHYS CALL INSTALL_OUTFILE ;THIS IS AN OUTPUT FILE MOV IMPLIB_FILE_GINDEX,EAX RESS SKIP_OUTFILE_LINK RET PARSE_IMPLIB_FILENAME ENDP SET_IMPLIB_COFF PROC ; ;POSSIBLY :FILENAME, .LIB OUTPUT DESCRIBING THIS .DLL ; SETT IMPLIB_COFF_FLAG ;HE WANTS US TO BUILD .LIB CALL FIX_GET_COLON JZ L1$ RET L1$: CALL PARSE_IMPLIB_COFF_FILENAME RET SET_IMPLIB_COFF ENDP PARSE_IMPLIB_COFF_FILENAME PROC MOV EAX,OFF IMPLIB_STUFF ;LIKE LIB, BUT USE PRIMARY NAME AS DEFAULT CALL YYLEX_FILENAME SETT SKIP_OUTFILE_LINK MOV EAX,OFF FILNAM push ECX mov ECX,ESP push ECX push EAX call _filename_install add ESP,8 pop ECX ;CALL FILENAME_INSTALL ;AX IS GINDEX, DS:BX IS FILE_LIST PHYS CALL INSTALL_OUTFILE ;THIS IS AN OUTPUT FILE MOV IMPLIB_COFF_FILE_GINDEX,EAX RESS SKIP_OUTFILE_LINK RET PARSE_IMPLIB_COFF_FILENAME ENDP SET_PAGESIZE PROC ; ;:nnn, SETS PAGESIZE FOR OPTIMP .LIB FILE ; CALL GET_COLON_NUMBER16 MOV IMPLIB_PAGESIZE,EAX RET SET_PAGESIZE ENDP endif endif SET_CPARMAXALLOC PROC CALL GET_COLON_NUMBER16 MOV EXEHEADER._EXE_MAX_ABOVE,AX RET SET_CPARMAXALLOC ENDP if any_overlays SET_OVERLAYINTERRUPT PROC CALL GET_COLON_NUMBER16 MOV OVERLAY_INTERRUPT_NUMBER,EAX RET SET_OVERLAYINTERRUPT ENDP endif SET_CODEVIEW PROC if fg_cv SETT CODEVIEW_FLAG if any_overlays MOV CODEVIEW_BYTE,'Y' endif CALL FIX_GET_COLON JNZ L9$ CALL GET_NUMBER16 MOV CV_INFO_TYPE,AL L9$: endif if fg_td CALL RES_TD endif RET SET_CODEVIEW ENDP SET_CVVERSION PROC ; ; ; CALL FIX_GET_COLON JNZ L9$ CALL GET_NUMBER16 MOV CV_INFO_TYPE,AL L9$: RET SET_CVVERSION ENDP SET_CVWARNINGS PROC ; ; ; SETT CV_WARNINGS RET SET_CVWARNINGS ENDP RES_CODEVIEW PROC ; RESS CODEVIEW_FLAG if any_overlays MOV CODEVIEW_BYTE,'N' endif RET RES_CODEVIEW ENDP SET_BINARY PROC ; SETT OUTPUT_COM_SYS SETT OUTPUT_SYS XOR EAX,EAX PUSH EAX CALL FIX_GET_COLON POP EAX JNZ SB_DONE CALL GET_NUMBER SB_DONE LABEL PROC MOV SYS_BASE,EAX RET SET_TINY LABEL PROC SETT OUTPUT_COM_SYS SETT OUTPUT_COM MOV EAX,100H JMP SB_DONE SET_BINARY ENDP if any_overlays SET_RELOAD PROC ; SETT DOING_RELOAD MOV RELOAD_BYTE,'Y' CALL GET_COLON_NUMBER16 MOV RELOAD_DEPTH,EAX RET SET_RELOAD ENDP endif SET_PACKCODE PROC RESS NOPACKCODE_FLAG SETT PACKCODE_FLAG MOV EAX,OFF PACKCODE JMP PACK_PROC SET_PACKCODE ENDP SET_PACKDATA PROC RESS NOPACKDATA_FLAG SETT PACKDATA_FLAG MOV EAX,OFF PACKDATA PACK_PROC LABEL PROC PUSH EAX CALL FIX_GET_COLON JZ L1$ MOV EAX,PACK_DEFAULT_SIZE JMP L3$ L1$: CALL GET_NUMBER ;EAX CMP EAX,64K JA GN_ERROR TEST EAX,EAX JNZ L3$ MOV EAX,64K L3$: POP ECX MOV DPTR [ECX],EAX RET SET_PACKDATA ENDP PACKSIZE_PROC PROC ; ; ; CALL GET_COLON_NUMBER16 TEST EAX,EAX JNZ L1$ MOV EAX,64K L1$: MOV PACK_DEFAULT_SIZE,EAX RET PACKSIZE_PROC ENDP SET_NULLSDOSSEG PROC ; SETT NULLSDOSSEG_FLAG CALL DOSSEG_PROC RET SET_NULLSDOSSEG ENDP if fg_segm OR fg_pe SET_PADDATA PROC ; CALL GET_COLON_NUMBER16 MOV PADDATA,EAX RET SET_PADDATA ENDP SET_PADCODE PROC ; CALL GET_COLON_NUMBER16 MOV PADCODE,EAX RET SET_PADCODE ENDP endif SET_STACK PROC ; CALL GET_COLON_NUMBER CALL SET_STACK_1 ; if fg_pe CALL FIX_GET_COLON JNZ L9$ CALL GET_NUMBER MOV PEXEHEADER._PEXE_STACK_COMMIT,EAX endif L9$: RET SET_STACK ENDP SET_STACK_1 PROC ADD EAX,3 ;DWORD ALIGN IT... AND AL,0FCH SETT STACK_SIZE_FLAG MOV STACK_SIZE,EAX RET SET_STACK_1 ENDP if fg_segm OR fg_pe SET_HEAP PROC ; CALL GET_COLON_NUMBER CALL SET_HEAP_1 ; if fg_pe CALL FIX_GET_COLON JNZ L9$ CALL GET_NUMBER MOV PEXEHEADER._PEXE_HEAP_COMMIT,EAX endif L9$: RET SET_HEAP ENDP SET_HEAP_1 PROC ADD EAX,3 ;DWORD ALIGN IT... AND AL,0FCH SETT HEAP_SIZE_FLAG MOV HEAP_SIZE,EAX RET SET_HEAP_1 ENDP endif if fg_pe SET_PE_BASE PROC ; ; ; CALL GET_COLON_NUMBER MOV PE_BASE,EAX SETT PE_BASE_SPECIFIED RET SET_PE_BASE ENDP SET_PE_FIXED PROC ; ; ; SETT PE_BASE_FIXED RET SET_PE_FIXED ENDP SET_MACHINE PROC ; ;ONLY SUPPORTS i386, i486, PENTIUM ; CALL CHECK_COLON CALL GET_KEYWORD PUSHM EDI,ESI MOV ECX,SYMBOL_LENGTH ;AT LEAST THIS MANY MUST MATCH MOV ESI,OFF I386_TXT TEST ECX,ECX MOV EDI,OFF SYMBOL_TEXT JZ L4$ REPE CMPSB JNZ L4$ POPM ESI,EDI if fg_pe MOV PEXEHEADER._PEXE_CPU_REQUIRED,PEXE_80386 endif RET L4$: POPM ESI,EDI MOV AL,CMDLIN_ERR CALL ERR_INBUF_RET RET SET_MACHINE ENDP SET_VERSION PROC ; ; ; CALL CHECK_COLON CALL GET_NUM_DOT_NUM if fg_pe MOV PEXEHEADER._PEXE_USER_MAJOR,AX MOV PEXEHEADER._PEXE_USER_MINOR,DX endif RET SET_VERSION ENDP endif if fg_segm or fg_norm_exe OR fg_pe SET_ALIGNMENT PROC ; CALL GET_COLON_NUMBER MOV ALIGNMENT,EAX ;MUST BE A POWER OF 2... SETT ALIGNMENT_SPECIFIED RET SET_ALIGNMENT ENDP endif SET_SEGMENTS PROC ; CALL GET_COLON_NUMBER ;IGNORED... RET SET_SEGMENTS ENDP if fg_dospack SET_PACKDOTS PROC ; SETT DOTS_FLAG RET SET_PACKDOTS ENDP RES_PACKDOTS PROC ; RESS DOTS_FLAG RET RES_PACKDOTS ENDP public SET_QUIKPACK SET_QUIKPACK PROC ; SETT QUIKPACK_FLAG SET_SLRPACK LABEL PROC SETT SLRPACK_SELECTED if any_overlays MOV COMPRESS_BYTE,'Y' endif JMP SET_EXEPACK_1 SET_QUIKPACK ENDP endif .CONST ALIGN 4 EXE_TYPES LABEL DWORD if fg_pe DD NT_STG,PE_EXE_TYPE endif DD WINDOWS_STG,WIN_SEGM_TYPE DD OS2_STG,OS2_SEGM_TYPE DD DOS_STG,DOS_EXE_TYPE DD DOS4_STG,DOS4_SEGM_TYPE DD DOSX_STG,DOSX_EXE_TYPE DD UNKNOWN_STG,UNKNOWN_SEGM_TYPE N_EXE_TYPES EQU ($-EXE_TYPES)/8 SUBSYS_TYPES LABEL DWORD DD PSUB_UNKNOWN_STG,PSUB_UNKNOWN DD PSUB_NATIVE_STG,PSUB_NATIVE DD PSUB_WIN_GUI_STG,PSUB_WIN_GUI DD PSUB_WIN_CHAR_STG,PSUB_WIN_CHAR DD PSUB_OS2_STG,PSUB_OS2 DD PSUB_POSIX_STG,PSUB_POSIX N_SUBSYS_TYPES EQU ($-SUBSYS_TYPES)/8 PSUB_UNKNOWN_STG DB 'UNKNOWN',0 PSUB_NATIVE_STG DB 'NATIVE',0 PSUB_WIN_GUI_STG DB 'WINDOWS',0 PSUB_WIN_CHAR_STG DB 'CONSOLE',0 PSUB_OS2_STG DB 'OS2',0 PSUB_POSIX_STG DB 'POSIX',0 END
; A301672: Coordination sequence for node of type V2 in "krr" 2-D tiling (or net). ; 1,4,8,13,17,20,25,30,33,37,42,46,50,54,58,63,67,70,75,80,83,87,92,96,100,104,108,113,117,120,125,130,133,137,142,146,150,154,158,163,167,170,175,180,183,187,192,196,200,204,208,213,217,220,225,230,233,237,242,246,250,254,258,263,267,270,275,280,283,287,292,296,300,304,308,313,317,320,325,330,333,337,342,346,350,354,358,363,367,370,375,380,383,387,392,396,400,404,408,413,417,420,425,430,433,437,442,446,450,454,458,463,467,470,475,480,483,487,492,496,500,504,508,513,517,520,525,530,533,537,542,546,550,554,558,563,567,570,575,580,583,587,592,596,600,604,608,613,617,620,625,630,633,637,642,646,650,654,658,663,667,670,675,680,683,687,692,696,700,704,708,713,717,720,725,730,733,737,742,746,750,754,758,763,767,770,775,780,783,787,792,796,800,804,808,813,817,820,825,830,833,837,842,846,850,854,858,863,867,870,875,880,883,887,892,896,900,904,908,913,917,920,925,930,933,937,942,946,950,954,958,963,967,970,975,980,983,987,992,996,1000,1004,1008,1013,1017,1020,1025,1030,1033,1037 mov $3,2 mov $5,$0 lpb $3,1 mov $0,$5 sub $3,1 add $0,$3 sub $0,1 cal $0,301673 ; Partial sums of A301672. mov $2,$3 mov $4,$0 lpb $2,1 mov $1,$4 sub $2,1 lpe lpe lpb $5,1 sub $1,$4 mov $5,0 lpe
// ArduinoJson - arduinojson.org // Copyright Benoit Blanchon 2014-2021 // MIT License #pragma once #include <ArduinoJson/Polyfills/attributes.hpp> #include <ArduinoJson/Polyfills/type_traits.hpp> namespace ARDUINOJSON_NAMESPACE { // Forward declarations. class ArrayRef; class ObjectRef; template <typename> class ElementProxy; template <typename TArray> class ArrayShortcuts { public: // Returns the element at specified index if the variant is an array. FORCE_INLINE ElementProxy<TArray> operator[](size_t index) const; FORCE_INLINE ObjectRef createNestedObject() const; FORCE_INLINE ArrayRef createNestedArray() const; // Adds the specified value at the end of the array. // // bool add(TValue); // TValue = bool, long, int, short, float, double, serialized, VariantRef, // std::string, String, ObjectRef template <typename T> FORCE_INLINE bool add(const T &value) const { return impl()->addElement().set(value); } // // bool add(TValue); // TValue = char*, const char*, const __FlashStringHelper* template <typename T> FORCE_INLINE bool add(T *value) const { return impl()->addElement().set(value); } private: const TArray *impl() const { return static_cast<const TArray *>(this); } }; } // namespace ARDUINOJSON_NAMESPACE
; A182260: Number of ordered triples (w,x,y) with all terms in {1,...,n} and 2w<x+y. ; 0,3,11,28,56,99,159,240,344,475,635,828,1056,1323,1631,1984,2384,2835,3339,3900,4520,5203,5951,6768,7656,8619,9659,10780,11984,13275,14655,16128,17696,19363,21131,23004,24984,27075,29279,31600,34040 add $0,1 mov $1,2 mul $1,$0 bin $1,2 mul $1,$0 mul $1,6 div $1,24 mov $0,$1
; A190785: Numbers that are congruent to {0, 2, 3, 5, 7, 9, 11} mod 12. ; 0,2,3,5,7,9,11,12,14,15,17,19,21,23,24,26,27,29,31,33,35,36,38,39,41,43,45,47,48,50,51,53,55,57,59,60,62,63,65,67,69,71,72,74,75,77,79,81,83,84,86,87,89,91,93,95,96,98,99,101,103,105,107,108,110,111,113,115,117,119,120,122,123,125,127,129,131,132,134,135,137,139,141,143,144,146,147,149,151,153,155,156,158,159,161,163,165,167,168,170,171,173,175,177,179,180,182,183,185,187,189,191,192,194,195,197,199,201,203,204,206,207,209,211,213,215,216,218,219,221,223,225,227,228,230,231,233,235,237,239,240,242,243,245,247,249,251,252,254,255,257,259,261,263,264,266,267,269,271,273,275,276,278,279,281,283,285,287,288,290,291,293,295,297,299,300,302,303,305,307,309,311,312,314,315,317,319,321,323,324,326,327,329,331,333,335,336,338,339,341,343,345,347,348,350,351,353,355,357,359,360,362,363,365,367,369,371,372,374,375,377,379,381,383,384,386,387,389,391,393,395,396,398,399,401,403,405,407,408,410,411,413,415,417,419,420,422,423,425,427 lpb $0 add $1,$0 trn $0,2 mov $2,$0 trn $0,5 add $1,$2 add $1,1 trn $2,4 sub $1,$2 sub $1,$0 lpe