text
stringlengths
1
1.05M
#include "Graphics.hh" #include "Surfaces.hh" int main(void) { bool quit; Graphics g; Surfaces s; SDL_Surface *currentSurface; SDL_Event event; quit = false; currentSurface = NULL; if (g.init() == false) return EXIT_FAILURE; if (s.loadMedia() == false) return EXIT_FAILURE; currentSurface = s.getSurface(KEY_PRESS_SURFACE_DEFAULT); while (quit != true) { while (SDL_PollEvent(&event) != 0) { if (event.type == SDL_QUIT) quit = true; else if (event.type == SDL_KEYDOWN) { switch (event.key.keysym.sym) { case SDLK_UP: currentSurface = s.getSurface(KEY_PRESS_SURFACE_UP); break ; case SDLK_DOWN: currentSurface = s.getSurface(KEY_PRESS_SURFACE_DOWN); break ; case SDLK_LEFT: currentSurface = s.getSurface(KEY_PRESS_SURFACE_LEFT); break ; case SDLK_RIGHT: currentSurface = s.getSurface(KEY_PRESS_SURFACE_RIGHT); break ; default: currentSurface = s.getSurface(KEY_PRESS_SURFACE_DEFAULT); break ; } } } SDL_BlitSurface(currentSurface, NULL, g.getScreenSurface(), NULL); SDL_UpdateWindowSurface(g.getWindow()); } currentSurface = NULL; return EXIT_SUCCESS; }
<% from pwnlib.shellcraft.mips.linux import syscall %> <%page args="fd, buf, n, offset"/> <%docstring> Invokes the syscall pwrite. See 'man 2 pwrite' for more information. Arguments: fd(int): fd buf(void): buf n(size_t): n offset(off_t): offset </%docstring> ${syscall('SYS_pwrite', fd, buf, n, offset)}
class Solution { public: void moveZeroes(vector<int>& nums) { int len = nums.size(), count = 0; for (int i = 0; i < len; i ++) { if (nums[i] == 0) { count ++; nums.push_back(0); } } auto it = nums.begin(); for (int j = 0; j < count;) { if (*it == 0) { it = nums.erase(it); j ++; } else it ++; } } };
; A170671: Number of reduced words of length n in Coxeter group on 38 generators S_i with relations (S_i)^2 = (S_i S_j)^49 = I. ; 1,38,1406,52022,1924814,71218118,2635070366,97497603542,3607411331054,133474219248998,4938546112212926,182726206151878262,6760869627619495694,250152176221921340678,9255630520211089605086 add $0,1 mov $3,1 lpb $0 sub $0,1 add $2,$3 div $3,$2 mul $2,37 lpe mov $0,$2 div $0,37
/* scheme/make_sob_integer.asm * Takes an integer, and place the corresponding Scheme object in R0 * * Programmer: Mayer Goldberg, 2010 */ MAKE_SOB_INTEGER: PUSH(FP); MOV(FP, SP); PUSH(IMM(2)); CALL(MALLOC); DROP(1); MOV(IND(R0), T_INTEGER); MOV(INDD(R0, 1), FPARG(0)); POP(FP); RETURN;
; A082392: Expansion of (1/x) * sum(k>=0, x^2^k/(1-2x^2^(k+1))). ; 1,1,2,1,4,2,8,1,16,4,32,2,64,8,128,1,256,16,512,4,1024,32,2048,2,4096,64,8192,8,16384,128,32768,1,65536,256,131072,16,262144,512,524288,4,1048576,1024,2097152,32,4194304,2048,8388608,2,16777216 lpb $0 mul $0,2 sub $0,2 dif $0,4 lpe div $0,2 mov $1,2 pow $1,$0 mov $0,$1
; A064201: 9 times octagonal numbers: a(n) = 9n(3n-2). ; 0,9,72,189,360,585,864,1197,1584,2025,2520,3069,3672,4329,5040,5805,6624,7497,8424,9405,10440,11529,12672,13869,15120,16425,17784,19197,20664,22185,23760,25389,27072,28809,30600,32445,34344,36297,38304,40365,42480,44649,46872,49149,51480,53865,56304,58797,61344,63945,66600,69309,72072,74889,77760,80685,83664,86697,89784,92925,96120,99369,102672,106029,109440,112905,116424,119997,123624,127305,131040,134829,138672,142569,146520,150525,154584,158697,162864,167085,171360,175689,180072,184509,189000,193545,198144,202797,207504,212265,217080,221949,226872,231849,236880,241965,247104,252297,257544,262845 mov $1,27 mul $1,$0 sub $1,18 mul $1,$0 mov $0,$1
noop # War program noop # Write cards to memory addi $3, $0, 0 # i = 0 addi $4, $0, 51 # limit = 51 WriteCards: noop # write each card sw $3, 0($s3) # *i = i sw $3, 52($3) # *(i+52) = i addi $3, $3, 1 # i++; beq $3, $4, 1 # if (limit == i) break j WriteCards # continue loop ShuffleCards: noop # Shuffle the cards in memory noop # TODO noop # Compare each card addi $3, $0, 0 # i = 0; addi $4, $0, 51 # limit = 51 addi $5, $0, 0 # p1Score = 0 addi $6, $0, 0 # p2Score = 0 CompareCards: noop # iterate over both decks lw $1, 0($3) # c1 = *i lw $2, 0($3) # c2 = *i addi $3, $3, 1 # i++ beq $1, $2, 4 # if (c1 == c2) noop noop noop wli T # disp('T') blt $1, $2, 4 # if (c1 < c2) addi $6, $0, 1 # p2Score++ noop noop wli A # disp('A') blt $2, $1, 4 # if (c2 < c1) addi $6, $0, 1 # p1Score++ noop noop wli B # disp('B') beq $3, $4, 1 # if (limit == i) break j CompareCards # continue loop wli 32 # disp(' ') blt $6, $5, 4 # if (p2Score < p1Score) noop noop noop wli 35 # disp('5') blt $5, $6, 4 # if (p1Score > p2Score) noop noop noop wli 36 # disp('6') beq $5, $6, 4 # if (p1Score == p2Score) noop noop noop wli T # disp("Tie") wli i wli e END: j END # End program
############################################################################### # 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 .globl h9_Encrypt_RIJ128_AES_NI .type h9_Encrypt_RIJ128_AES_NI, @function h9_Encrypt_RIJ128_AES_NI: push %ebp mov %esp, %ebp push %esi push %edi movl (8)(%ebp), %esi movl (20)(%ebp), %ecx movl (16)(%ebp), %eax movl (12)(%ebp), %edi movdqu (%esi), %xmm0 pxor (%ecx), %xmm0 lea (,%eax,4), %edx lea (-144)(%ecx,%edx,4), %ecx cmp $(12), %eax jl .Lkey_128gas_1 jz .Lkey_192gas_1 .Lkey_256gas_1: aesenc (-64)(%ecx), %xmm0 aesenc (-48)(%ecx), %xmm0 .Lkey_192gas_1: aesenc (-32)(%ecx), %xmm0 aesenc (-16)(%ecx), %xmm0 .Lkey_128gas_1: aesenc (%ecx), %xmm0 aesenc (16)(%ecx), %xmm0 aesenc (32)(%ecx), %xmm0 aesenc (48)(%ecx), %xmm0 aesenc (64)(%ecx), %xmm0 aesenc (80)(%ecx), %xmm0 aesenc (96)(%ecx), %xmm0 aesenc (112)(%ecx), %xmm0 aesenc (128)(%ecx), %xmm0 aesenclast (144)(%ecx), %xmm0 movdqu %xmm0, (%edi) pop %edi pop %esi pop %ebp ret .Lfe1: .size h9_Encrypt_RIJ128_AES_NI, .Lfe1-(h9_Encrypt_RIJ128_AES_NI)
TITLE Binary File Program (Binfile.asm) ; Create a binary file containing an array ; of doublewords. ; Last update: 11/12/01 INCLUDE Irvine16.inc .data myArray DWORD 50 DUP(?) fileName BYTE "binary array file.bin",0 fileHandle WORD ? commaStr BYTE ", ",0 ; Set CreateFile to zero if you just want to ; read and display the existing binary file. CreateFile = 1 .code main PROC mov ax,@data mov ds,ax .IF CreateFile EQ 1 call FillTheArray call DisplayTheArray call CreateTheFile call WaitMsg call Crlf .ENDIF call ReadTheFile call DisplayTheArray quit: call Crlf exit main ENDP ;------------------------------------------------------ ReadTheFile PROC ; ; Open and read the binary file. ; Receives: nothing. Returns: nothing ;------------------------------------------------------ mov ax,716Ch ; extended file open mov bx,0 ; mode: read-only mov cx,0 ; attribute: normal mov dx,1 ; open existing file mov si,OFFSET fileName ; filename int 21h ; call MS-DOS jc quit ; quit if error mov fileHandle,ax ; save handle ; Read the input file, then close the file. mov ah,3Fh ; read file mov bx,fileHandle ; file handle mov cx,SIZEOF myArray ; max bytes to read mov dx,OFFSET myArray ; buffer pointer int 21h jc quit ; quit if error mov ah,3Eh ; function: close file mov bx,fileHandle ; output file handle int 21h ; call MS-DOS quit: ret ReadTheFile ENDP ;------------------------------------------------------ DisplayTheArray PROC ; ; Display the array ; Receives: nothing. Returns: nothing ;------------------------------------------------------ mov CX,LENGTHOF myArray mov si,0 L1: mov eax,myArray[si] ; get a number call WriteHex ; display the number mov edx,OFFSET commaStr ; display a comma call WriteString add si,TYPE myArray ; next array position loop L1 ret DisplayTheArray ENDP ;------------------------------------------------------ FillTheArray PROC ; ; Fill the array with random integers. ; Receives: nothing. Returns: nothing ;------------------------------------------------------ mov CX,LENGTHOF myArray mov si,0 L1: mov eax,1000h ; generate random integers call RandomRange ; between 0 - 999 in EAX mov myArray[si],eax ; store in the array add si,TYPE myArray ; next array position loop L1 ret FillTheArray ENDP ;------------------------------------------------------ CreateTheFile PROC ; ; Create a file containing binary data ; Receives: nothing. Returns: nothing ;------------------------------------------------------ mov ax,716Ch ; create file mov bx,1 ; mode: write only mov cx,0 ; normal file mov dx,12h ; action: create/truncate mov si,OFFSET fileName ; filename int 21h ; call MS-DOS jc quit ; quit if error mov fileHandle,ax ; save handle ; Write integer array to the file. mov ah,40h ; write file or device mov bx,fileHandle ; output file handle mov cx,SIZEOF myArray ; number of bytes mov dx,OFFSET myArray ; buffer pointer int 21h jc quit ; quit if error ; Close the file. mov ah,3Eh ; function: close file mov bx,fileHandle ; output file handle int 21h ; call MS-DOS quit: ret CreateTheFile ENDP END main
.global s_prepare_buffers s_prepare_buffers: push %r11 push %r12 push %r15 push %r8 push %rbx push %rcx push %rdi push %rsi lea addresses_A_ht+0x16ae8, %rsi lea addresses_A_ht+0x3ca8, %rdi nop nop nop nop nop dec %rbx mov $53, %rcx rep movsw cmp $50, %rdi lea addresses_WC_ht+0x72e8, %rcx nop nop nop nop nop sub %r15, %r15 movw $0x6162, (%rcx) and %r15, %r15 lea addresses_D_ht+0x14ca0, %r15 nop nop nop nop nop xor %r8, %r8 movb $0x61, (%r15) add %rbx, %rbx lea addresses_WT_ht+0x1ae8, %r8 add %r11, %r11 mov (%r8), %r15w add %rbx, %rbx lea addresses_UC_ht+0x1a2f4, %rsi lea addresses_normal_ht+0x4a00, %rdi sub %r12, %r12 mov $27, %rcx rep movsw nop nop nop nop nop cmp %r11, %r11 lea addresses_UC_ht+0xc6e8, %rsi nop and $32759, %r8 movw $0x6162, (%rsi) nop nop nop xor $59066, %r15 lea addresses_A_ht+0xc9f8, %rsi lea addresses_A_ht+0x12460, %rdi nop nop nop nop nop sub $37723, %r11 mov $12, %rcx rep movsl nop nop and %r11, %r11 lea addresses_A_ht+0x1c328, %r15 nop nop nop add %rsi, %rsi movups (%r15), %xmm0 vpextrq $1, %xmm0, %r12 nop nop xor %r8, %r8 lea addresses_D_ht+0x10fe8, %rcx nop cmp $43205, %rbx mov (%rcx), %r12w nop nop nop xor %r12, %r12 lea addresses_UC_ht+0x14d90, %r11 nop nop nop nop nop add $43112, %r8 mov (%r11), %r12w nop nop nop nop nop add %r11, %r11 lea addresses_normal_ht+0xf484, %rdi nop nop nop nop nop sub %r8, %r8 mov (%rdi), %esi nop nop nop nop nop xor $16543, %r11 lea addresses_WT_ht+0x21bc, %rdi clflush (%rdi) nop add $12739, %rcx movb $0x61, (%rdi) nop nop sub $25888, %r12 lea addresses_A_ht+0x18dc8, %rsi lea addresses_D_ht+0x1bcd0, %rdi clflush (%rdi) nop nop nop and %r15, %r15 mov $111, %rcx rep movsb nop nop nop xor $59868, %r12 lea addresses_normal_ht+0x18e68, %rsi lea addresses_WC_ht+0x9ae8, %rdi clflush (%rsi) nop nop sub $30026, %r12 mov $10, %rcx rep movsl nop nop nop dec %rbx lea addresses_WT_ht+0x14de8, %rsi lea addresses_A_ht+0x146e8, %rdi clflush (%rsi) nop nop cmp %r12, %r12 mov $31, %rcx rep movsb nop xor $50723, %r11 pop %rsi pop %rdi pop %rcx pop %rbx pop %r8 pop %r15 pop %r12 pop %r11 ret .global s_faulty_load s_faulty_load: push %r11 push %r12 push %r14 push %r15 push %r9 push %rbp push %rcx // Store lea addresses_normal+0x155be, %rcx xor %r14, %r14 movw $0x5152, (%rcx) nop dec %r9 // Store lea addresses_RW+0x10848, %rbp nop nop nop nop nop inc %r15 mov $0x5152535455565758, %r9 movq %r9, (%rbp) xor %r11, %r11 // Store lea addresses_WC+0x1af78, %rcx sub %r15, %r15 movl $0x51525354, (%rcx) add $64654, %rbp // Load lea addresses_D+0x16ae8, %r14 nop add %rbp, %rbp movups (%r14), %xmm6 vpextrq $1, %xmm6, %rcx nop nop xor $61550, %r11 // Store lea addresses_UC+0xdae8, %r12 nop nop nop nop nop cmp %r11, %r11 mov $0x5152535455565758, %rcx movq %rcx, %xmm4 movups %xmm4, (%r12) nop nop nop cmp $17505, %r9 // Load lea addresses_RW+0x107e8, %rcx clflush (%rcx) nop sub %r9, %r9 mov (%rcx), %r12d nop nop nop nop nop cmp $59906, %rcx // Faulty Load lea addresses_UC+0xdae8, %r12 nop nop nop nop and $29341, %r11 mov (%r12), %r9 lea oracles, %r15 and $0xff, %r9 shlq $12, %r9 mov (%r15,%r9,1), %r9 pop %rcx pop %rbp pop %r9 pop %r15 pop %r14 pop %r12 pop %r11 ret /* <gen_faulty_load> [REF] {'src': {'congruent': 0, 'AVXalign': False, 'same': False, 'size': 8, 'NT': False, 'type': 'addresses_UC'}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'congruent': 1, 'AVXalign': False, 'same': False, 'size': 2, 'NT': False, 'type': 'addresses_normal'}} {'OP': 'STOR', 'dst': {'congruent': 5, 'AVXalign': False, 'same': False, 'size': 8, 'NT': False, 'type': 'addresses_RW'}} {'OP': 'STOR', 'dst': {'congruent': 1, 'AVXalign': False, 'same': False, 'size': 4, 'NT': False, 'type': 'addresses_WC'}} {'src': {'congruent': 10, 'AVXalign': False, 'same': False, 'size': 16, 'NT': False, 'type': 'addresses_D'}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'congruent': 0, 'AVXalign': False, 'same': True, 'size': 16, 'NT': False, 'type': 'addresses_UC'}} {'src': {'congruent': 7, 'AVXalign': False, 'same': False, 'size': 4, 'NT': True, 'type': 'addresses_RW'}, 'OP': 'LOAD'} [Faulty Load] {'src': {'congruent': 0, 'AVXalign': False, 'same': True, 'size': 8, 'NT': False, 'type': 'addresses_UC'}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'congruent': 10, 'same': False, 'type': 'addresses_A_ht'}, 'OP': 'REPM', 'dst': {'congruent': 4, 'same': False, 'type': 'addresses_A_ht'}} {'OP': 'STOR', 'dst': {'congruent': 11, 'AVXalign': False, 'same': False, 'size': 2, 'NT': False, 'type': 'addresses_WC_ht'}} {'OP': 'STOR', 'dst': {'congruent': 3, 'AVXalign': False, 'same': False, 'size': 1, 'NT': False, 'type': 'addresses_D_ht'}} {'src': {'congruent': 9, 'AVXalign': True, 'same': False, 'size': 2, 'NT': False, 'type': 'addresses_WT_ht'}, 'OP': 'LOAD'} {'src': {'congruent': 2, 'same': False, 'type': 'addresses_UC_ht'}, 'OP': 'REPM', 'dst': {'congruent': 3, 'same': True, 'type': 'addresses_normal_ht'}} {'OP': 'STOR', 'dst': {'congruent': 9, 'AVXalign': False, 'same': False, 'size': 2, 'NT': False, 'type': 'addresses_UC_ht'}} {'src': {'congruent': 2, 'same': False, 'type': 'addresses_A_ht'}, 'OP': 'REPM', 'dst': {'congruent': 1, 'same': False, 'type': 'addresses_A_ht'}} {'src': {'congruent': 6, 'AVXalign': False, 'same': False, 'size': 16, 'NT': False, 'type': 'addresses_A_ht'}, 'OP': 'LOAD'} {'src': {'congruent': 8, 'AVXalign': False, 'same': False, 'size': 2, 'NT': False, 'type': 'addresses_D_ht'}, 'OP': 'LOAD'} {'src': {'congruent': 3, 'AVXalign': False, 'same': False, 'size': 2, 'NT': False, 'type': 'addresses_UC_ht'}, 'OP': 'LOAD'} {'src': {'congruent': 2, 'AVXalign': False, 'same': False, 'size': 4, 'NT': False, 'type': 'addresses_normal_ht'}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'congruent': 2, 'AVXalign': False, 'same': False, 'size': 1, 'NT': False, 'type': 'addresses_WT_ht'}} {'src': {'congruent': 5, 'same': True, 'type': 'addresses_A_ht'}, 'OP': 'REPM', 'dst': {'congruent': 3, 'same': True, 'type': 'addresses_D_ht'}} {'src': {'congruent': 7, 'same': False, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'dst': {'congruent': 11, 'same': False, 'type': 'addresses_WC_ht'}} {'src': {'congruent': 8, 'same': False, 'type': 'addresses_WT_ht'}, 'OP': 'REPM', 'dst': {'congruent': 8, 'same': False, 'type': 'addresses_A_ht'}} {'8a': 1, '4a': 1, 'b2': 2, '56': 1, '80': 1, 'ba': 2, '68': 1, '74': 1, '58': 21815, 'bc': 1, '9a': 1, 'b6': 1, 'e0': 1} 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 */
title 'Preliminary Z80 tests' ; prelim.z80 - Preliminary Z80 tests ; Copyright (C) 1994 Frank D. Cringle ; ; This program is free software; you can redistribute it and/or ; modify it under the terms of the GNU General Public License ; as published by the Free Software Foundation; either version 2 ; of the License, or (at your option) any later version. ; ; 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 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., 675 Mass Ave, Cambridge, MA 02139, USA. ; ; ; These tests have two goals. To start with, we assume the worst and ; successively test the instructions needed to continue testing. ; Then we try to test all instructions which cannot be handled by ; zexlax - the crc-based instruction exerciser. ; ; Initially errors are 'reported' by jumping to 0. This should reboot ; cp/m, so if the program terminates without any output one of the ; early tests failed. Later errors are reported by outputting an ; address via the bdos conout routine. The address can be located in ; a listing of this program. ; ; If the program runs to completion it displays a suitable message. ; ;****************************************************************************** ; ; Modified by Ian Bartholomew to run a preliminary test on an 8080 CPU ; ; Assemble using M80 ; ;****************************************************************************** fault equ 8000h .8080 aseg org 0h start: lxi SP, stack mvi A, 1 ; test simple compares and z/nz jumps cpi 2 jz fault+$ cpi 1 jnz fault+$ jmp lab0 hlt ; emergency exit db 0FFh lab0: call lab2 ; does a simple call work? lab1: jmp fault+$ ; fail lab2: pop H ; check return address mov A, H cpi high lab1 jz lab3 jmp fault+$ lab3: mov A, L cpi low lab1 jz lab4 jmp fault+$ ; test presence and uniqueness of all machine registers ; (except ir) lab4: lxi SP, regs1 pop PSW pop B pop D pop H lxi SP, regs2+8 push H push D push B push PSW lda regs2+0 cpi 2 jnz fault+$ lda regs2+1 cpi 4 jnz fault+$ lda regs2+2 cpi 6 jnz fault+$ lda regs2+3 cpi 8 jnz fault+$ lda regs2+4 cpi 10 jnz fault+$ lda regs2+5 cpi 12 jnz fault+$ lda regs2+6 cpi 14 jnz fault+$ lda regs2+7 cpi 16 jnz fault+$ ; test access to memory via (HL) lxi H, hlval mov A, M cpi 0A5h jnz fault+$ lxi H, hlval+1 mov A, M cpi 03Ch jnz fault+$ ; test unconditional return lxi SP, stack lxi H, reta push H ret jmp fault+$ ; test instructions needed for hex output reta: mvi A, 0FFh ani 0Fh cpi 0Fh jnz fault+$ mvi A, 05Ah ani 0Fh cpi 0Ah jnz fault+$ rrc cpi 05h jnz fault+$ rrc cpi 82h jnz fault+$ rrc cpi 41h jnz fault+$ rrc cpi 0a0h jnz fault+$ lxi H, 01234h push H pop B mov A, B cpi 12h jnz fault+$ mov A, C cpi 34h jnz fault+$ ; test conditional call, ret, jp, jr tcond macro flag, pcond, ncond lxi H, flag push H pop psw c`pcond lab1`pcond jmp fault+$ lab1`pcond: pop H lxi H, 0D7h xor flag push H pop PSW c`ncond lab2`pcond jmp fault+$ lab2`pcond: pop H lxi H,lab3`pcond push H lxi H, flag push H pop PSW r`pcond jmp fault+$ lab3`pcond: lxi H,lab4`pcond push H lxi H, 0D7h xor flag push H pop PSW r`ncond jmp fault+$ lab4`pcond: lxi H, flag push H pop PSW j`pcond lab5`pcond jmp fault+$ lab5`pcond: lxi H, 0D7h xor flag push H pop PSW j`ncond lab6`pcond jmp fault+$ lab6`pcond: endm tcond 001h, c, nc tcond 004h, pe, po tcond 040h, z, nz tcond 080h, m, p ; test indirect jumps lxi H,lab7 pchl jmp fault+$ ; djnz (and (partially) inc a, inc hl) lab7: mvi A, 0A5h mvi B, 4 lab8: rrc dcr B jnz lab8 cpi 05Ah cnz fault+$ mvi B, 16 lab9: inr A dcr B jnz lab9 cpi 06Ah cnz fault+$ mvi B, 0 lxi H, 0 lab10: inx H dcr B jnz lab10 mov A, H cpi 1 cnz fault+$ mov a,l cpi 0 cnz fault+$ allok: lxi H, 0FFFFh; mov A, M jmp fault+$ regs1: db 2, 4, 6, 8, 10, 12, 14, 16 regs2: ds 8,0 hlval: db 0A5h,03Ch ds 120 stack equ $ end start
; A101605: a(n) = 1 if n is a product of exactly 3 (not necessarily distinct) primes, otherwise 0. ; 0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,1,0,1,0,0,0,0,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,1,0,0,1,0,0,1,0,0,0,0,1,0,0,0,1,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,1,0,1,1,0,0,0,0,0,0,1,0,0,0,1,0,1,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,1,0,0,0,0,1,0,1,0,0,0,1,0,1,1,1,0,0,0,0 cal $0,86436 ; Maximum number of parts possible in a factorization of n; a(1) = 1, and for n > 1, a(n) = A001222(n) = bigomega(n). mov $1,7 add $1,$0 add $1,$0 sub $1,4 gcd $1,729 div $1,8
// Copyright 2018 The Fuchsia Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "fidl.h" #include <utility> #include <fbl/algorithm.h> #include <fbl/unique_ptr.h> #include <lib/fidl/cpp/builder.h> #include <lib/fidl/cpp/message.h> #include <lib/fidl/cpp/message_part.h> namespace mock_device { namespace { template <typename MessageType> zx_status_t ParseActions(const fidl_type_t* type, fidl::Message* msg, fbl::Array<const fuchsia_device_mock_Action>* actions_out) { const char* err_out = nullptr; zx_status_t status = msg->Decode(type, &err_out); if (status != ZX_OK) { printf("mock-device: Failed to decode: %s\n", err_out); return status; } auto payload = msg->GetBytesAs<MessageType>(); auto array = std::make_unique<fuchsia_device_mock_Action[]>(payload->actions.count); memcpy(array.get(), payload->actions.data, payload->actions.count * sizeof(fuchsia_device_mock_Action)); actions_out->reset(array.release(), payload->actions.count); return ZX_OK; } } // namespace zx_status_t WaitForPerformActions(const zx::channel& c, fbl::Array<const fuchsia_device_mock_Action>* actions_out) { zx_signals_t signals; zx_status_t status = c.wait_one(ZX_CHANNEL_READABLE | ZX_CHANNEL_PEER_CLOSED, zx::time::infinite(), &signals); if (status != ZX_OK) { return status; } if (!(signals & ZX_CHANNEL_READABLE)) { return ZX_ERR_STOP; } FIDL_ALIGNDECL uint8_t request_buf[ZX_CHANNEL_MAX_MSG_BYTES]; zx_handle_t handles[ZX_CHANNEL_MAX_MSG_HANDLES]; fidl::Message request(fidl::BytePart(request_buf, sizeof(request_buf)), fidl::HandlePart(handles, fbl::count_of(handles))); status = request.Read(c.get(), 0); if (status != ZX_OK) { return status; } return ParseActions<fuchsia_device_mock_MockDeviceThreadPerformActionsRequest>( &fuchsia_device_mock_MockDeviceThreadPerformActionsRequestTable, &request, actions_out); } zx_status_t BindHook(const zx::channel& c, const fuchsia_device_mock_HookInvocation& record, fbl::Array<const fuchsia_device_mock_Action>* actions_out) { using RequestType = fuchsia_device_mock_MockDeviceBindRequest; using ResponseType = fuchsia_device_mock_MockDeviceBindResponse; const auto& kRequestOrdinal = fuchsia_device_mock_MockDeviceBindOrdinal; const fidl_type_t* kResponseTable = &fuchsia_device_mock_MockDeviceBindResponseTable; FIDL_ALIGNDECL char wr_bytes[sizeof(RequestType)]; fidl::Builder builder(wr_bytes, sizeof(wr_bytes)); auto req = builder.New<RequestType>(); ZX_ASSERT(req != nullptr); req->hdr.ordinal = kRequestOrdinal; req->hdr.txid = 0; req->record = record; fidl::Message msg(builder.Finalize(), fidl::HandlePart(nullptr, 0)); FIDL_ALIGNDECL uint8_t response_buf[ZX_CHANNEL_MAX_MSG_BYTES]; zx_handle_t handles[ZX_CHANNEL_MAX_MSG_HANDLES]; fidl::Message response(fidl::BytePart(response_buf, sizeof(response_buf)), fidl::HandlePart(handles, fbl::count_of(handles))); zx_status_t status = msg.Call(c.get(), 0, ZX_TIME_INFINITE, &response); if (status != ZX_OK) { return status; } return ParseActions<ResponseType>(kResponseTable, &response, actions_out); } zx_status_t ReleaseHook(const zx::channel& c, const fuchsia_device_mock_HookInvocation& record) { using RequestType = fuchsia_device_mock_MockDeviceReleaseRequest; const auto& kRequestOrdinal = fuchsia_device_mock_MockDeviceReleaseOrdinal; FIDL_ALIGNDECL char wr_bytes[sizeof(RequestType)]; fidl::Builder builder(wr_bytes, sizeof(wr_bytes)); auto req = builder.New<RequestType>(); ZX_ASSERT(req != nullptr); req->hdr.ordinal = kRequestOrdinal; req->hdr.txid = 0; req->record = record; fidl::Message msg(builder.Finalize(), fidl::HandlePart(nullptr, 0)); return msg.Write(c.get(), 0); } zx_status_t GetProtocolHook(const zx::channel& c, const fuchsia_device_mock_HookInvocation& record, uint32_t protocol_id, fbl::Array<const fuchsia_device_mock_Action>* actions_out) { using RequestType = fuchsia_device_mock_MockDeviceGetProtocolRequest; using ResponseType = fuchsia_device_mock_MockDeviceGetProtocolResponse; const auto& kRequestOrdinal = fuchsia_device_mock_MockDeviceGetProtocolOrdinal; const fidl_type_t* kResponseTable = &fuchsia_device_mock_MockDeviceGetProtocolResponseTable; FIDL_ALIGNDECL char wr_bytes[sizeof(RequestType)]; fidl::Builder builder(wr_bytes, sizeof(wr_bytes)); auto req = builder.New<RequestType>(); ZX_ASSERT(req != nullptr); req->hdr.ordinal = kRequestOrdinal; req->hdr.txid = 0; req->record = record; req->protocol_id = protocol_id; fidl::Message msg(builder.Finalize(), fidl::HandlePart(nullptr, 0)); FIDL_ALIGNDECL uint8_t response_buf[ZX_CHANNEL_MAX_MSG_BYTES]; zx_handle_t handles[ZX_CHANNEL_MAX_MSG_HANDLES]; fidl::Message response(fidl::BytePart(response_buf, sizeof(response_buf)), fidl::HandlePart(handles, fbl::count_of(handles))); zx_status_t status = msg.Call(c.get(), 0, ZX_TIME_INFINITE, &response); if (status != ZX_OK) { return status; } return ParseActions<ResponseType>(kResponseTable, &response, actions_out); } zx_status_t OpenHook(const zx::channel& c, const fuchsia_device_mock_HookInvocation& record, uint32_t flags, fbl::Array<const fuchsia_device_mock_Action>* actions_out) { using RequestType = fuchsia_device_mock_MockDeviceOpenRequest; using ResponseType = fuchsia_device_mock_MockDeviceOpenResponse; const auto& kRequestOrdinal = fuchsia_device_mock_MockDeviceOpenOrdinal; const fidl_type_t* kResponseTable = &fuchsia_device_mock_MockDeviceOpenResponseTable; FIDL_ALIGNDECL char wr_bytes[sizeof(RequestType)]; fidl::Builder builder(wr_bytes, sizeof(wr_bytes)); auto req = builder.New<RequestType>(); ZX_ASSERT(req != nullptr); req->hdr.ordinal = kRequestOrdinal; req->hdr.txid = 0; req->record = record; req->flags = flags; fidl::Message msg(builder.Finalize(), fidl::HandlePart(nullptr, 0)); FIDL_ALIGNDECL uint8_t response_buf[ZX_CHANNEL_MAX_MSG_BYTES]; zx_handle_t handles[ZX_CHANNEL_MAX_MSG_HANDLES]; fidl::Message response(fidl::BytePart(response_buf, sizeof(response_buf)), fidl::HandlePart(handles, fbl::count_of(handles))); zx_status_t status = msg.Call(c.get(), 0, ZX_TIME_INFINITE, &response); if (status != ZX_OK) { return status; } return ParseActions<ResponseType>(kResponseTable, &response, actions_out); } zx_status_t CloseHook(const zx::channel& c, const fuchsia_device_mock_HookInvocation& record, uint32_t flags, fbl::Array<const fuchsia_device_mock_Action>* actions_out) { using RequestType = fuchsia_device_mock_MockDeviceCloseRequest; using ResponseType = fuchsia_device_mock_MockDeviceCloseResponse; const auto& kRequestOrdinal = fuchsia_device_mock_MockDeviceCloseOrdinal; const fidl_type_t* kResponseTable = &fuchsia_device_mock_MockDeviceCloseResponseTable; FIDL_ALIGNDECL char wr_bytes[sizeof(RequestType)]; fidl::Builder builder(wr_bytes, sizeof(wr_bytes)); auto req = builder.New<RequestType>(); ZX_ASSERT(req != nullptr); req->hdr.ordinal = kRequestOrdinal; req->hdr.txid = 0; req->record = record; req->flags = flags; fidl::Message msg(builder.Finalize(), fidl::HandlePart(nullptr, 0)); FIDL_ALIGNDECL uint8_t response_buf[ZX_CHANNEL_MAX_MSG_BYTES]; zx_handle_t handles[ZX_CHANNEL_MAX_MSG_HANDLES]; fidl::Message response(fidl::BytePart(response_buf, sizeof(response_buf)), fidl::HandlePart(handles, fbl::count_of(handles))); zx_status_t status = msg.Call(c.get(), 0, ZX_TIME_INFINITE, &response); if (status != ZX_OK) { return status; } return ParseActions<ResponseType>(kResponseTable, &response, actions_out); } zx_status_t UnbindHook(const zx::channel& c, const fuchsia_device_mock_HookInvocation& record, fbl::Array<const fuchsia_device_mock_Action>* actions_out) { using RequestType = fuchsia_device_mock_MockDeviceUnbindRequest; using ResponseType = fuchsia_device_mock_MockDeviceUnbindResponse; const auto& kRequestOrdinal = fuchsia_device_mock_MockDeviceUnbindOrdinal; const fidl_type_t* kResponseTable = &fuchsia_device_mock_MockDeviceUnbindResponseTable; FIDL_ALIGNDECL char wr_bytes[sizeof(RequestType)]; fidl::Builder builder(wr_bytes, sizeof(wr_bytes)); auto req = builder.New<RequestType>(); ZX_ASSERT(req != nullptr); req->hdr.ordinal = kRequestOrdinal; req->hdr.txid = 0; req->record = record; fidl::Message msg(builder.Finalize(), fidl::HandlePart(nullptr, 0)); FIDL_ALIGNDECL uint8_t response_buf[ZX_CHANNEL_MAX_MSG_BYTES]; zx_handle_t handles[ZX_CHANNEL_MAX_MSG_HANDLES]; fidl::Message response(fidl::BytePart(response_buf, sizeof(response_buf)), fidl::HandlePart(handles, fbl::count_of(handles))); zx_status_t status = msg.Call(c.get(), 0, ZX_TIME_INFINITE, &response); if (status != ZX_OK) { return status; } return ParseActions<ResponseType>(kResponseTable, &response, actions_out); } zx_status_t ReadHook(const zx::channel& c, const fuchsia_device_mock_HookInvocation& record, uint64_t count, zx_off_t off, fbl::Array<const fuchsia_device_mock_Action>* actions_out) { using RequestType = fuchsia_device_mock_MockDeviceReadRequest; using ResponseType = fuchsia_device_mock_MockDeviceReadResponse; const auto& kRequestOrdinal = fuchsia_device_mock_MockDeviceReadOrdinal; const fidl_type_t* kResponseTable = &fuchsia_device_mock_MockDeviceReadResponseTable; FIDL_ALIGNDECL char wr_bytes[sizeof(RequestType)]; fidl::Builder builder(wr_bytes, sizeof(wr_bytes)); auto req = builder.New<RequestType>(); ZX_ASSERT(req != nullptr); req->hdr.ordinal = kRequestOrdinal; req->hdr.txid = 0; req->count = count; req->off = off; fidl::Message msg(builder.Finalize(), fidl::HandlePart(nullptr, 0)); FIDL_ALIGNDECL uint8_t response_buf[ZX_CHANNEL_MAX_MSG_BYTES]; zx_handle_t handles[ZX_CHANNEL_MAX_MSG_HANDLES]; fidl::Message response(fidl::BytePart(response_buf, sizeof(response_buf)), fidl::HandlePart(handles, fbl::count_of(handles))); zx_status_t status = msg.Call(c.get(), 0, ZX_TIME_INFINITE, &response); if (status != ZX_OK) { return status; } return ParseActions<ResponseType>(kResponseTable, &response, actions_out); } zx_status_t GetSizeHook(const zx::channel& c, const fuchsia_device_mock_HookInvocation& record, fbl::Array<const fuchsia_device_mock_Action>* actions_out) { using RequestType = fuchsia_device_mock_MockDeviceGetSizeRequest; using ResponseType = fuchsia_device_mock_MockDeviceGetSizeResponse; const auto& kRequestOrdinal = fuchsia_device_mock_MockDeviceGetSizeOrdinal; const fidl_type_t* kResponseTable = &fuchsia_device_mock_MockDeviceGetSizeResponseTable; FIDL_ALIGNDECL char wr_bytes[sizeof(RequestType)]; fidl::Builder builder(wr_bytes, sizeof(wr_bytes)); auto req = builder.New<RequestType>(); ZX_ASSERT(req != nullptr); req->hdr.ordinal = kRequestOrdinal; req->hdr.txid = 0; fidl::Message msg(builder.Finalize(), fidl::HandlePart(nullptr, 0)); FIDL_ALIGNDECL uint8_t response_buf[ZX_CHANNEL_MAX_MSG_BYTES]; zx_handle_t handles[ZX_CHANNEL_MAX_MSG_HANDLES]; fidl::Message response(fidl::BytePart(response_buf, sizeof(response_buf)), fidl::HandlePart(handles, fbl::count_of(handles))); zx_status_t status = msg.Call(c.get(), 0, ZX_TIME_INFINITE, &response); if (status != ZX_OK) { return status; } return ParseActions<ResponseType>(kResponseTable, &response, actions_out); } zx_status_t SuspendHook(const zx::channel& c, const fuchsia_device_mock_HookInvocation& record, uint32_t flags, fbl::Array<const fuchsia_device_mock_Action>* actions_out) { using RequestType = fuchsia_device_mock_MockDeviceSuspendRequest; using ResponseType = fuchsia_device_mock_MockDeviceSuspendResponse; const auto& kRequestOrdinal = fuchsia_device_mock_MockDeviceSuspendOrdinal; const fidl_type_t* kResponseTable = &fuchsia_device_mock_MockDeviceSuspendResponseTable; FIDL_ALIGNDECL char wr_bytes[sizeof(RequestType)]; fidl::Builder builder(wr_bytes, sizeof(wr_bytes)); auto req = builder.New<RequestType>(); ZX_ASSERT(req != nullptr); req->hdr.ordinal = kRequestOrdinal; req->hdr.txid = 0; req->record = record; req->flags = flags; fidl::Message msg(builder.Finalize(), fidl::HandlePart(nullptr, 0)); FIDL_ALIGNDECL uint8_t response_buf[ZX_CHANNEL_MAX_MSG_BYTES]; zx_handle_t handles[ZX_CHANNEL_MAX_MSG_HANDLES]; fidl::Message response(fidl::BytePart(response_buf, sizeof(response_buf)), fidl::HandlePart(handles, fbl::count_of(handles))); zx_status_t status = msg.Call(c.get(), 0, ZX_TIME_INFINITE, &response); if (status != ZX_OK) { return status; } return ParseActions<ResponseType>(kResponseTable, &response, actions_out); } zx_status_t ResumeHook(const zx::channel& c, const fuchsia_device_mock_HookInvocation& record, uint32_t flags, fbl::Array<const fuchsia_device_mock_Action>* actions_out) { using RequestType = fuchsia_device_mock_MockDeviceResumeRequest; using ResponseType = fuchsia_device_mock_MockDeviceResumeResponse; const auto& kRequestOrdinal = fuchsia_device_mock_MockDeviceResumeOrdinal; const fidl_type_t* kResponseTable = &fuchsia_device_mock_MockDeviceResumeResponseTable; FIDL_ALIGNDECL char wr_bytes[sizeof(RequestType)]; fidl::Builder builder(wr_bytes, sizeof(wr_bytes)); auto req = builder.New<RequestType>(); ZX_ASSERT(req != nullptr); req->hdr.ordinal = kRequestOrdinal; req->hdr.txid = 0; req->record = record; req->flags = flags; fidl::Message msg(builder.Finalize(), fidl::HandlePart(nullptr, 0)); FIDL_ALIGNDECL uint8_t response_buf[ZX_CHANNEL_MAX_MSG_BYTES]; zx_handle_t handles[ZX_CHANNEL_MAX_MSG_HANDLES]; fidl::Message response(fidl::BytePart(response_buf, sizeof(response_buf)), fidl::HandlePart(handles, fbl::count_of(handles))); zx_status_t status = msg.Call(c.get(), 0, ZX_TIME_INFINITE, &response); if (status != ZX_OK) { return status; } return ParseActions<ResponseType>(kResponseTable, &response, actions_out); } zx_status_t WriteHook(const zx::channel& c, const fuchsia_device_mock_HookInvocation& record, const uint8_t* buffer_data, size_t buffer_count, zx_off_t off, fbl::Array<const fuchsia_device_mock_Action>* actions_out) { using RequestType = fuchsia_device_mock_MockDeviceWriteRequest; using ResponseType = fuchsia_device_mock_MockDeviceWriteResponse; const auto& kRequestOrdinal = fuchsia_device_mock_MockDeviceWriteOrdinal; const fidl_type_t* kResponseTable = &fuchsia_device_mock_MockDeviceWriteResponseTable; FIDL_ALIGNDECL char wr_bytes[sizeof(RequestType)]; fidl::Builder builder(wr_bytes, sizeof(wr_bytes)); auto req = builder.New<RequestType>(); ZX_ASSERT(req != nullptr); req->hdr.ordinal = kRequestOrdinal; req->hdr.txid = 0; req->off = off; req->buffer.data = reinterpret_cast<char*>(FIDL_ALLOC_PRESENT); req->buffer.count = buffer_count; uint8_t* buffer_storage = builder.NewArray<uint8_t>(static_cast<uint32_t>(buffer_count)); memcpy(buffer_storage, buffer_data, buffer_count); fidl::Message msg(builder.Finalize(), fidl::HandlePart(nullptr, 0)); FIDL_ALIGNDECL uint8_t response_buf[ZX_CHANNEL_MAX_MSG_BYTES]; zx_handle_t handles[ZX_CHANNEL_MAX_MSG_HANDLES]; fidl::Message response(fidl::BytePart(response_buf, sizeof(response_buf)), fidl::HandlePart(handles, fbl::count_of(handles))); zx_status_t status = msg.Call(c.get(), 0, ZX_TIME_INFINITE, &response); if (status != ZX_OK) { return status; } return ParseActions<ResponseType>(kResponseTable, &response, actions_out); } zx_status_t MessageHook(const zx::channel& c, const fuchsia_device_mock_HookInvocation& record, fbl::Array<const fuchsia_device_mock_Action>* actions_out) { using RequestType = fuchsia_device_mock_MockDeviceMessageRequest; using ResponseType = fuchsia_device_mock_MockDeviceMessageResponse; const auto& kRequestOrdinal = fuchsia_device_mock_MockDeviceMessageOrdinal; const fidl_type_t* kResponseTable = &fuchsia_device_mock_MockDeviceMessageResponseTable; FIDL_ALIGNDECL char wr_bytes[sizeof(RequestType)]; fidl::Builder builder(wr_bytes, sizeof(wr_bytes)); auto req = builder.New<RequestType>(); ZX_ASSERT(req != nullptr); req->hdr.ordinal = kRequestOrdinal; req->hdr.txid = 0; req->record = record; fidl::Message msg(builder.Finalize(), fidl::HandlePart(nullptr, 0)); FIDL_ALIGNDECL uint8_t response_buf[ZX_CHANNEL_MAX_MSG_BYTES]; zx_handle_t handles[ZX_CHANNEL_MAX_MSG_HANDLES]; fidl::Message response(fidl::BytePart(response_buf, sizeof(response_buf)), fidl::HandlePart(handles, fbl::count_of(handles))); zx_status_t status = msg.Call(c.get(), 0, ZX_TIME_INFINITE, &response); if (status != ZX_OK) { return status; } return ParseActions<ResponseType>(kResponseTable, &response, actions_out); } zx_status_t RxrpcHook(const zx::channel& c, const fuchsia_device_mock_HookInvocation& record, fbl::Array<const fuchsia_device_mock_Action>* actions_out) { using RequestType = fuchsia_device_mock_MockDeviceRxrpcRequest; using ResponseType = fuchsia_device_mock_MockDeviceRxrpcResponse; const auto& kRequestOrdinal = fuchsia_device_mock_MockDeviceRxrpcOrdinal; const fidl_type_t* kResponseTable = &fuchsia_device_mock_MockDeviceRxrpcResponseTable; FIDL_ALIGNDECL char wr_bytes[sizeof(RequestType)]; fidl::Builder builder(wr_bytes, sizeof(wr_bytes)); auto req = builder.New<RequestType>(); ZX_ASSERT(req != nullptr); req->hdr.ordinal = kRequestOrdinal; req->hdr.txid = 0; req->record = record; fidl::Message msg(builder.Finalize(), fidl::HandlePart(nullptr, 0)); FIDL_ALIGNDECL uint8_t response_buf[ZX_CHANNEL_MAX_MSG_BYTES]; zx_handle_t handles[ZX_CHANNEL_MAX_MSG_HANDLES]; fidl::Message response(fidl::BytePart(response_buf, sizeof(response_buf)), fidl::HandlePart(handles, fbl::count_of(handles))); zx_status_t status = msg.Call(c.get(), 0, ZX_TIME_INFINITE, &response); if (status != ZX_OK) { return status; } return ParseActions<ResponseType>(kResponseTable, &response, actions_out); } zx_status_t SendAddDeviceDone(const zx::channel& c, uint64_t action_id) { using RequestType = fuchsia_device_mock_MockDeviceAddDeviceDoneRequest; const auto& kRequestOrdinal = fuchsia_device_mock_MockDeviceAddDeviceDoneOrdinal; FIDL_ALIGNDECL char wr_bytes[sizeof(RequestType)]; fidl::Builder builder(wr_bytes, sizeof(wr_bytes)); auto req = builder.New<RequestType>(); ZX_ASSERT(req != nullptr); req->hdr.ordinal = kRequestOrdinal; req->hdr.txid = 0; req->action_id = action_id; fidl::Message msg(builder.Finalize(), fidl::HandlePart(nullptr, 0)); return msg.Write(c.get(), 0); } zx_status_t SendRemoveDeviceDone(const zx::channel& c, uint64_t action_id) { using RequestType = fuchsia_device_mock_MockDeviceRemoveDeviceDoneRequest; const auto& kRequestOrdinal = fuchsia_device_mock_MockDeviceRemoveDeviceDoneOrdinal; FIDL_ALIGNDECL char wr_bytes[sizeof(RequestType)]; fidl::Builder builder(wr_bytes, sizeof(wr_bytes)); auto req = builder.New<RequestType>(); ZX_ASSERT(req != nullptr); req->hdr.ordinal = kRequestOrdinal; req->hdr.txid = 0; req->action_id = action_id; fidl::Message msg(builder.Finalize(), fidl::HandlePart(nullptr, 0)); return msg.Write(c.get(), 0); } zx_status_t SendAddDeviceDoneFromThread(const zx::channel& c, uint64_t action_id) { using EventType = fuchsia_device_mock_MockDeviceThreadAddDeviceDoneEvent; const auto& kEventOrdinal = fuchsia_device_mock_MockDeviceThreadAddDeviceDoneOrdinal; FIDL_ALIGNDECL char wr_bytes[sizeof(EventType)]; fidl::Builder builder(wr_bytes, sizeof(wr_bytes)); auto req = builder.New<EventType>(); ZX_ASSERT(req != nullptr); req->hdr.ordinal = kEventOrdinal; req->hdr.txid = 0; req->action_id = action_id; fidl::Message msg(builder.Finalize(), fidl::HandlePart(nullptr, 0)); return msg.Write(c.get(), 0); } zx_status_t SendRemoveDeviceDoneFromThread(const zx::channel& c, uint64_t action_id) { using EventType = fuchsia_device_mock_MockDeviceThreadRemoveDeviceDoneEvent; const auto& kEventOrdinal = fuchsia_device_mock_MockDeviceThreadRemoveDeviceDoneOrdinal; FIDL_ALIGNDECL char wr_bytes[sizeof(EventType)]; fidl::Builder builder(wr_bytes, sizeof(wr_bytes)); auto req = builder.New<EventType>(); ZX_ASSERT(req != nullptr); req->hdr.ordinal = kEventOrdinal; req->hdr.txid = 0; req->action_id = action_id; fidl::Message msg(builder.Finalize(), fidl::HandlePart(nullptr, 0)); return msg.Write(c.get(), 0); } } // namespace mock_device
; A102591: a(n) = Sum_{k=0..n} binomial(2n+1, 2k)*3^(n-k). ; Submitted by Jon Maiga ; 1,6,44,328,2448,18272,136384,1017984,7598336,56714752,423324672,3159738368,23584608256,176037912576,1313964867584,9807567290368,73204678852608,546407161659392,4078438577864704,30441879976280064 mul $0,2 mov $3,1 lpb $0 sub $0,1 add $2,$3 mov $3,$1 mov $1,$2 mul $3,2 add $3,$2 lpe add $2,$3 mov $0,$2
<% from pwnlib.shellcraft.aarch64.linux import syscall %> <%page args="fn, child_stack, flags, arg, vararg"/> <%docstring> Invokes the syscall clone. See 'man 2 clone' for more information. Arguments: fn(int): fn child_stack(void): child_stack flags(int): flags arg(void): arg vararg(int): vararg </%docstring> ${syscall('SYS_clone', fn, child_stack, flags, arg, vararg)}
; A100304: Expansion of (1-x-6x^2)/(1-x-8x^2). ; 1,0,2,2,18,34,178,450,1874,5474,20466,64258,227986,742050,2565938,8502338,29029842,97048546,329287282,1105675650,3739973906,12585379106,42505170354,143188203202,483229566034,1628735191650,5494571719922 mov $7,$0 mov $9,2 lpb $9 clr $0,7 mov $0,$7 sub $9,1 add $0,$9 sub $0,2 mov $1,2 mov $6,2 lpb $0 sub $0,1 mov $2,8 mul $2,$1 sub $6,2 mov $1,$6 add $6,$2 lpe add $3,2 sub $0,$3 mul $1,$0 sub $2,$1 mov $1,$2 div $1,12 mul $1,4 add $1,2 mov $10,$9 lpb $10 mov $8,$1 sub $10,1 lpe lpe lpb $7 mov $7,0 sub $8,$1 lpe mov $1,$8 div $1,2
; --COPYRIGHT--,BSD_EX ; Copyright (c) 2012, Texas Instruments Incorporated ; 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 Texas Instruments Incorporated nor the names of ; its contributors may be used to endorse or promote products derived ; from this software without specific prior written permission. ; ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" ; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, ; THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR ; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR ; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, ; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, ; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; ; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR ; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, ; EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ; ; ****************************************************************************** ; ; MSP430 CODE EXAMPLE DISCLAIMER ; ; MSP430 code examples are self-contained low-level programs that typically ; demonstrate a single peripheral function or device feature in a highly ; concise manner. For this the code may rely on the device's power-on default ; register values and settings such as the clock configuration and care must ; be taken when combining code from several examples to avoid potential side ; effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware ; for an API functional library-approach to peripheral configuration. ; ; --/COPYRIGHT-- ;******************************************************************************* ; MSP430F54xA Demo - USCI_B0 I2C Slave RX single bytes from MSP430 Master ; ; Description: This demo connects two MSP430's via the I2C bus. The master ; transmits to the slave. This is the SLAVE code. The interrupt driven ; data receiption is demonstrated using the USCI_B0 RX interrupt. ; ACLK = n/a, MCLK = SMCLK = default DCO = ~1.045MHz ; ; ***to be used with msp430x54xA_uscib0_i2c_06.asm*** ; ; /|\ /|\ ; MSP430F5438A 10k 10k MSP430F5438 ; slave | | master ; ----------------- | | ----------------- ; -|XIN P3.1/UCB0SDA|<-|----+->|P3.1/UCB0SDA XIN|- ; | | | | | ; -|XOUT | | | XOUT|- ; | P3.2/UCB0SCL|<-+------>|P3.2/UCB0SCL | ; | | | | ; ; D. Dang ; Texas Instruments Inc. ; December 2009 ; Built with CCS Version: 4.0.2 ;****************************************************************************** .cdecls C,LIST,"msp430.h" ;------------------------------------------------------------------------------- .def RESET ; Export program entry-point to ; make it known to linker. RXData .equ R5 ;------------------------------------------------------------------------------- .global _main .text ; Assemble to Flash memory ;------------------------------------------------------------------------------- _main RESET mov.w #0x5C00,SP ; Initialize stackpointer mov.w #WDTPW + WDTHOLD,&WDTCTL; Stop WDT bis.b #0x06,&P3SEL ; Assign I2C pins to USCI_B0 bis.b #UCSWRST,&UCB0CTL1 ; **Put state machine in reset** mov.b #UCMODE_3 + UCSYNC,UCB0CTL0; I2C Slave, synchronous mode mov.w #0x48,&UCB0I2COA ; Own Address is 048h bic.b #UCSWRST,&UCB0CTL1 ; **Initialize USCI state machine** bis.b #UCRXIE,&UCB0IE ; Enable RX interrupt Mainloop bis.b #LPM0 + GIE,SR ; Enter LPM0, enable interrupts nop ; Set breakpoint >>here<< and read jmp Mainloop ; RXData ; ;------------------------------------------------------------------------------- USCI_B0_ISR; USCI_B0 Interrupt Handler ISR ;------------------------------------------------------------------------------- add.w &UCB0IV,PC ; Add offset to PC reti ; Vector 0: No interrupt reti ; Vector 2: ALIFG reti ; Vector 4: NACKIFG reti ; Vector 6: STTIFG reti ; Vector 8: STPIFG jmp RXIFG_ISR ; Vector 10: RXIFG reti ; Vector 12: TXIFG ; RXIFG_ISR ; RXIFG Interrupt Handler mov.b &UCB0RXBUF,RXData ; Get RX data bic.b #LPM0,0(SP) ; Exit LPM0 reti ; ; ;------------------------------------------------------------------------------- ; Interrupt Vectors ;------------------------------------------------------------------------------- .sect ".int56" ; USCI_BO Interrupt Vector .short USCI_B0_ISR .sect ".reset" ; POR, ext. Reset .short RESET .end
//////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2013 Shuangyang Yang // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //////////////////////////////////////////////////////////////////////////////// #ifndef HPX_SMALL_BIG_OBJECT_HPP #define HPX_SMALL_BIG_OBJECT_HPP #include <hpx/runtime/serialization/serialize.hpp> #include <cstdint> #include <iostream> #define ENABLE_DEBUG false /////////////////////////////////////////////////////////////////////////////// struct small_object { private: std::uint64_t x_; friend class hpx::serialization::access; template <typename Archive> void serialize(Archive& ar, unsigned const) { ar & x_; if(ENABLE_DEBUG) { std::cout << "small_object: serialize(" << x_ << ")\n"; } } public: small_object() : x_(0) { if(ENABLE_DEBUG) { std::cout << "small_object: default ctor\n"; } } small_object(std::uint64_t x) : x_(x) { if(ENABLE_DEBUG) { std::cout << "small_object: ctor(" << x << ")\n"; } } small_object(small_object const& o) : x_(o.x_) { if(ENABLE_DEBUG) { std::cout << "small_object: copy(" << o.x_ << ")\n"; } } small_object& operator=(small_object const& o) { x_ = o.x_; if(ENABLE_DEBUG) { std::cout << "small_object: assign(" << o.x_ << ")\n"; } return *this; } bool operator==(small_object const& o) const { if(ENABLE_DEBUG) { std::cout << "small_object: equal(" << o.x_ << ")\n"; } return x_ == o.x_; } ~small_object() { if(ENABLE_DEBUG) { std::cout << "small_object: dtor(" << x_ << ")\n"; } } std::uint64_t operator()(std::uint64_t const& z_) { if(ENABLE_DEBUG) { std::cout << "small_object: call(" << x_ << ", " << z_ << ")\n"; } return x_ + z_; } friend inline std::istream& operator>> (std::istream& in, small_object& obj) { in >> obj.x_; if(ENABLE_DEBUG) { std::cout << "small_object: istream ("<< obj.x_ << ")\n"; } return in; } friend inline std::ostream& operator<< (std::ostream& out, small_object const& obj) { out << obj.x_; if(ENABLE_DEBUG) { std::cout << "small_object: ostream ("<< obj.x_ << ")\n"; } return out; } }; /////////////////////////////////////////////////////////////////////////////// struct big_object { private: std::uint64_t x_; std::uint64_t y_; friend class hpx::serialization::access; template <typename Archive> void serialize(Archive& ar, unsigned const) { ar & x_; ar & y_; if(ENABLE_DEBUG) { std::cout << "big_object: serialize(" << x_ << ", " << y_ << ")\n"; } } public: big_object() : x_(0), y_(0) { if(ENABLE_DEBUG) { std::cout << "big_object: default ctor\n"; } } big_object(std::uint64_t x, std::uint64_t y) : x_(x), y_(y) { if(ENABLE_DEBUG) { std::cout << "big_object: ctor(" << x << ", " << y << ")\n"; } } big_object(big_object const& o) : x_(o.x_), y_(o.y_) { if(ENABLE_DEBUG) { std::cout << "big_object: copy(" << o.x_ << ", " << o.y_ << ")\n"; } } big_object& operator=(big_object const& o) { x_ = o.x_; y_ = o.y_; if(ENABLE_DEBUG) { std::cout << "big_object: assign(" << o.x_ << ", " << o.y_ << ")\n"; } return *this; } bool operator==(big_object const& o) const { if(ENABLE_DEBUG) { std::cout << "big_object: equal(" << o.x_ << ", " << o.y_ << ")\n"; } return ((x_ == o.x_) && (y_ == o.y_)); } ~big_object() { if(ENABLE_DEBUG) { std::cout << "big_object: dtor(" << x_ << ", " << y_ << ")\n"; } } std::uint64_t operator()( std::uint64_t const& z_ , std::uint64_t const& w_ ) { if(ENABLE_DEBUG) { std::cout << "big_object: call(" << x_ << ", " << y_ << ", " << z_ << ", " << w_ << ")\n"; } return x_ + y_ + z_ + w_; } friend inline std::istream& operator>> (std::istream& in, big_object& obj) { in >> obj.x_; in >> obj.y_; if(ENABLE_DEBUG) { std::cout << "big_object: istream ("<< obj.x_ <<", "<< obj.y_ << ")\n"; } return in; } friend inline std::ostream& operator<< (std::ostream& out, big_object const& obj) { out << obj.x_; out << obj.y_; if(ENABLE_DEBUG) { std::cout << "big_object: ostream ("<< obj.x_ <<", "<< obj.y_ << ")\n"; } return out; } }; #undef ENABLE_DEBUG #endif
SECTION code_clib SECTION code_fp_math48 PUBLIC dread1, dread2 EXTERN cm48_sccz80p_dread1, cm48_sccz80p_dread2 defc dread1 = cm48_sccz80p_dread1 defc dread2 = cm48_sccz80p_dread2
; A052737: a(n) = ((2*n)!/n!)*2^(2*n+1). ; Submitted by Christian Krause ; 0,2,16,384,15360,860160,61931520,5449973760,566797271040,68015672524800,9250131463372800,1406019982432665600,236211357048687820800,43462889696958559027200,8692577939391711805440000,1877596834908609749975040000,435602465698797461994209280000 mov $1,2 pow $1,$0 seq $0,52714 ; a(n) = 2^(n-1) * n! * Catalan(n-1) for n > 0 with a(0) = 0. mul $1,2 mul $0,$1 div $0,2
; ; Copyright (c) 2016, Alliance for Open Media. All rights reserved ; ; This source code is subject to the terms of the BSD 2 Clause License and ; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License ; was not distributed with this source code in the LICENSE file, you can ; obtain it at www.aomedia.org/license/software. If the Alliance for Open ; Media Patent License 1.0 was not distributed with this source code in the ; PATENTS file, you can obtain it at www.aomedia.org/license/patent. ; ; %include "aom_ports/x86_abi_support.asm" %macro GET_PARAM_4 0 mov rdx, arg(5) ;filter ptr mov rsi, arg(0) ;src_ptr mov rdi, arg(2) ;output_ptr mov ecx, 0x01000100 movdqa xmm3, [rdx] ;load filters psrldq xmm3, 6 packsswb xmm3, xmm3 pshuflw xmm3, xmm3, 0b ;k3_k4 movd xmm2, ecx ;rounding_shift pshufd xmm2, xmm2, 0 movsxd rax, DWORD PTR arg(1) ;pixels_per_line movsxd rdx, DWORD PTR arg(3) ;out_pitch movsxd rcx, DWORD PTR arg(4) ;output_height %endm %macro APPLY_FILTER_4 1 punpcklbw xmm0, xmm1 pmaddubsw xmm0, xmm3 pmulhrsw xmm0, xmm2 ;rounding(+64)+shift(>>7) packuswb xmm0, xmm0 ;pack to byte %if %1 movd xmm1, [rdi] pavgb xmm0, xmm1 %endif movd [rdi], xmm0 lea rsi, [rsi + rax] lea rdi, [rdi + rdx] dec rcx %endm %macro GET_PARAM 0 mov rdx, arg(5) ;filter ptr mov rsi, arg(0) ;src_ptr mov rdi, arg(2) ;output_ptr mov ecx, 0x01000100 movdqa xmm7, [rdx] ;load filters psrldq xmm7, 6 packsswb xmm7, xmm7 pshuflw xmm7, xmm7, 0b ;k3_k4 punpcklwd xmm7, xmm7 movd xmm6, ecx ;rounding_shift pshufd xmm6, xmm6, 0 movsxd rax, DWORD PTR arg(1) ;pixels_per_line movsxd rdx, DWORD PTR arg(3) ;out_pitch movsxd rcx, DWORD PTR arg(4) ;output_height %endm %macro APPLY_FILTER_8 1 punpcklbw xmm0, xmm1 pmaddubsw xmm0, xmm7 pmulhrsw xmm0, xmm6 ;rounding(+64)+shift(>>7) packuswb xmm0, xmm0 ;pack back to byte %if %1 movq xmm1, [rdi] pavgb xmm0, xmm1 %endif movq [rdi], xmm0 ;store the result lea rsi, [rsi + rax] lea rdi, [rdi + rdx] dec rcx %endm %macro APPLY_FILTER_16 1 punpcklbw xmm0, xmm1 punpckhbw xmm2, xmm1 pmaddubsw xmm0, xmm7 pmaddubsw xmm2, xmm7 pmulhrsw xmm0, xmm6 ;rounding(+64)+shift(>>7) pmulhrsw xmm2, xmm6 packuswb xmm0, xmm2 ;pack back to byte %if %1 movdqu xmm1, [rdi] pavgb xmm0, xmm1 %endif movdqu [rdi], xmm0 ;store the result lea rsi, [rsi + rax] lea rdi, [rdi + rdx] dec rcx %endm global sym(aom_filter_block1d4_v2_ssse3) PRIVATE sym(aom_filter_block1d4_v2_ssse3): push rbp mov rbp, rsp SHADOW_ARGS_TO_STACK 6 push rsi push rdi ; end prolog GET_PARAM_4 .loop: movd xmm0, [rsi] ;load src movd xmm1, [rsi + rax] APPLY_FILTER_4 0 jnz .loop ; begin epilog pop rdi pop rsi UNSHADOW_ARGS pop rbp ret global sym(aom_filter_block1d8_v2_ssse3) PRIVATE sym(aom_filter_block1d8_v2_ssse3): push rbp mov rbp, rsp SHADOW_ARGS_TO_STACK 6 SAVE_XMM 7 push rsi push rdi ; end prolog GET_PARAM .loop: movq xmm0, [rsi] ;0 movq xmm1, [rsi + rax] ;1 APPLY_FILTER_8 0 jnz .loop ; begin epilog pop rdi pop rsi RESTORE_XMM UNSHADOW_ARGS pop rbp ret global sym(aom_filter_block1d16_v2_ssse3) PRIVATE sym(aom_filter_block1d16_v2_ssse3): push rbp mov rbp, rsp SHADOW_ARGS_TO_STACK 6 SAVE_XMM 7 push rsi push rdi ; end prolog GET_PARAM .loop: movdqu xmm0, [rsi] ;0 movdqu xmm1, [rsi + rax] ;1 movdqa xmm2, xmm0 APPLY_FILTER_16 0 jnz .loop ; begin epilog pop rdi pop rsi RESTORE_XMM UNSHADOW_ARGS pop rbp ret global sym(aom_filter_block1d4_v2_avg_ssse3) PRIVATE sym(aom_filter_block1d4_v2_avg_ssse3): push rbp mov rbp, rsp SHADOW_ARGS_TO_STACK 6 push rsi push rdi ; end prolog GET_PARAM_4 .loop: movd xmm0, [rsi] ;load src movd xmm1, [rsi + rax] APPLY_FILTER_4 1 jnz .loop ; begin epilog pop rdi pop rsi UNSHADOW_ARGS pop rbp ret global sym(aom_filter_block1d8_v2_avg_ssse3) PRIVATE sym(aom_filter_block1d8_v2_avg_ssse3): push rbp mov rbp, rsp SHADOW_ARGS_TO_STACK 6 SAVE_XMM 7 push rsi push rdi ; end prolog GET_PARAM .loop: movq xmm0, [rsi] ;0 movq xmm1, [rsi + rax] ;1 APPLY_FILTER_8 1 jnz .loop ; begin epilog pop rdi pop rsi RESTORE_XMM UNSHADOW_ARGS pop rbp ret global sym(aom_filter_block1d16_v2_avg_ssse3) PRIVATE sym(aom_filter_block1d16_v2_avg_ssse3): push rbp mov rbp, rsp SHADOW_ARGS_TO_STACK 6 SAVE_XMM 7 push rsi push rdi ; end prolog GET_PARAM .loop: movdqu xmm0, [rsi] ;0 movdqu xmm1, [rsi + rax] ;1 movdqa xmm2, xmm0 APPLY_FILTER_16 1 jnz .loop ; begin epilog pop rdi pop rsi RESTORE_XMM UNSHADOW_ARGS pop rbp ret global sym(aom_filter_block1d4_h2_ssse3) PRIVATE sym(aom_filter_block1d4_h2_ssse3): push rbp mov rbp, rsp SHADOW_ARGS_TO_STACK 6 push rsi push rdi ; end prolog GET_PARAM_4 .loop: movdqu xmm0, [rsi] ;load src movdqa xmm1, xmm0 psrldq xmm1, 1 APPLY_FILTER_4 0 jnz .loop ; begin epilog pop rdi pop rsi UNSHADOW_ARGS pop rbp ret global sym(aom_filter_block1d8_h2_ssse3) PRIVATE sym(aom_filter_block1d8_h2_ssse3): push rbp mov rbp, rsp SHADOW_ARGS_TO_STACK 6 SAVE_XMM 7 push rsi push rdi ; end prolog GET_PARAM .loop: movdqu xmm0, [rsi] ;load src movdqa xmm1, xmm0 psrldq xmm1, 1 APPLY_FILTER_8 0 jnz .loop ; begin epilog pop rdi pop rsi RESTORE_XMM UNSHADOW_ARGS pop rbp ret global sym(aom_filter_block1d16_h2_ssse3) PRIVATE sym(aom_filter_block1d16_h2_ssse3): push rbp mov rbp, rsp SHADOW_ARGS_TO_STACK 6 SAVE_XMM 7 push rsi push rdi ; end prolog GET_PARAM .loop: movdqu xmm0, [rsi] ;load src movdqu xmm1, [rsi + 1] movdqa xmm2, xmm0 APPLY_FILTER_16 0 jnz .loop ; begin epilog pop rdi pop rsi RESTORE_XMM UNSHADOW_ARGS pop rbp ret global sym(aom_filter_block1d4_h2_avg_ssse3) PRIVATE sym(aom_filter_block1d4_h2_avg_ssse3): push rbp mov rbp, rsp SHADOW_ARGS_TO_STACK 6 push rsi push rdi ; end prolog GET_PARAM_4 .loop: movdqu xmm0, [rsi] ;load src movdqa xmm1, xmm0 psrldq xmm1, 1 APPLY_FILTER_4 1 jnz .loop ; begin epilog pop rdi pop rsi UNSHADOW_ARGS pop rbp ret global sym(aom_filter_block1d8_h2_avg_ssse3) PRIVATE sym(aom_filter_block1d8_h2_avg_ssse3): push rbp mov rbp, rsp SHADOW_ARGS_TO_STACK 6 SAVE_XMM 7 push rsi push rdi ; end prolog GET_PARAM .loop: movdqu xmm0, [rsi] ;load src movdqa xmm1, xmm0 psrldq xmm1, 1 APPLY_FILTER_8 1 jnz .loop ; begin epilog pop rdi pop rsi RESTORE_XMM UNSHADOW_ARGS pop rbp ret global sym(aom_filter_block1d16_h2_avg_ssse3) PRIVATE sym(aom_filter_block1d16_h2_avg_ssse3): push rbp mov rbp, rsp SHADOW_ARGS_TO_STACK 6 SAVE_XMM 7 push rsi push rdi ; end prolog GET_PARAM .loop: movdqu xmm0, [rsi] ;load src movdqu xmm1, [rsi + 1] movdqa xmm2, xmm0 APPLY_FILTER_16 1 jnz .loop ; begin epilog pop rdi pop rsi RESTORE_XMM UNSHADOW_ARGS pop rbp ret
; A130664: a(1)=1. a(n) = a(n-1) + (number of terms from among a(1) through a(n-1) which are factorials). ; 1,2,4,6,9,12,15,18,21,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,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,500,505,510,515,520,525,530,535,540,545,550,555,560,565,570,575,580,585,590,595,600,605,610,615,620,625,630,635,640,645,650,655,660,665,670,675,680,685,690,695,700,705,710,715,720,726,732,738,744,750,756,762,768,774,780,786,792,798,804,810,816,822,828,834,840,846,852,858,864,870,876,882,888,894,900,906,912,918,924,930,936,942,948,954,960,966,972,978,984,990,996,1002,1008,1014,1020,1026,1032,1038,1044,1050,1056,1062,1068,1074,1080,1086,1092,1098,1104,1110,1116,1122,1128,1134,1140,1146,1152,1158,1164,1170,1176,1182,1188,1194,1200,1206,1212,1218,1224,1230,1236,1242,1248,1254,1260,1266,1272,1278,1284,1290,1296 mov $4,$0 add $4,1 mov $7,$0 lpb $4 mov $0,$7 sub $4,1 sub $0,$4 mov $2,$0 mov $3,1 lpb $2 add $5,$3 mov $6,$3 lpb $5 sub $2,1 sub $5,$5 add $6,$2 mov $8,$5 lpe lpb $6 add $8,1 mov $3,$8 sub $6,1 div $6,$8 lpe mov $2,1 lpe add $1,$3 lpe
############################################################################### # Copyright 2019 Intel Corporation # All Rights Reserved. # # If this software was obtained under the Intel Simplified Software License, # the following terms apply: # # The source code, information and material ("Material") contained herein is # owned by Intel Corporation or its suppliers or licensors, and title to such # Material remains with Intel Corporation or its suppliers or licensors. The # Material contains proprietary information of Intel or its suppliers and # licensors. The Material is protected by worldwide copyright laws and treaty # provisions. No part of the Material may be used, copied, reproduced, # modified, published, uploaded, posted, transmitted, distributed or disclosed # in any way without Intel's prior express written permission. No license under # any patent, copyright or other intellectual property rights in the Material # is granted to or conferred upon you, either expressly, by implication, # inducement, estoppel or otherwise. Any license under such intellectual # property rights must be express and approved by Intel in writing. # # Unless otherwise agreed by Intel in writing, you may not remove or alter this # notice or any other notice embedded in Materials by Intel or Intel's # suppliers or licensors in any way. # # # If this software was obtained under the Apache License, Version 2.0 (the # "License"), the following terms apply: # # You may not use this file except in compliance with the License. You may # obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 # # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # # See the License for the specific language governing permissions and # limitations under the License. ############################################################################### .text .p2align 4, 0x90 .globl _y8_Decrypt_RIJ128_AES_NI _y8_Decrypt_RIJ128_AES_NI: lea (,%rdx,4), %rax lea (,%rax,4), %rax movdqu (%rdi), %xmm0 pxor (%rcx,%rax), %xmm0 cmp $(12), %rdx jl .Lkey_128gas_1 jz .Lkey_192gas_1 .Lkey_256gas_1: aesdec (208)(%rcx), %xmm0 aesdec (192)(%rcx), %xmm0 .Lkey_192gas_1: aesdec (176)(%rcx), %xmm0 aesdec (160)(%rcx), %xmm0 .Lkey_128gas_1: aesdec (144)(%rcx), %xmm0 aesdec (128)(%rcx), %xmm0 aesdec (112)(%rcx), %xmm0 aesdec (96)(%rcx), %xmm0 aesdec (80)(%rcx), %xmm0 aesdec (64)(%rcx), %xmm0 aesdec (48)(%rcx), %xmm0 aesdec (32)(%rcx), %xmm0 aesdec (16)(%rcx), %xmm0 aesdeclast (%rcx), %xmm0 movdqu %xmm0, (%rsi) ret
/* * OctoMap - An Efficient Probabilistic 3D Mapping Framework Based on Octrees * http://octomap.github.com/ * * Copyright (c) 2009-2013, K.M. Wurm and A. Hornung, University of Freiburg * All rights reserved. * License: New BSD * * 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 University of Freiburg nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include <cassert> #include <octomap/CountingOcTree.h> namespace octomap { /// implementation of CountingOcTreeNode ---------------------------------- CountingOcTreeNode::CountingOcTreeNode() : OcTreeDataNode<unsigned int>(0) { } CountingOcTreeNode::~CountingOcTreeNode() { } /// implementation of CountingOcTree -------------------------------------- CountingOcTree::CountingOcTree(double resolution) : OcTreeBase<CountingOcTreeNode>(resolution) { countingOcTreeMemberInit.ensureLinking(); } CountingOcTreeNode* CountingOcTree::updateNode(const point3d& value) { OcTreeKey key; if (!coordToKeyChecked(value, key)) return NULL; return updateNode(key); } // Note: do not inline this method, will decrease speed (KMW) CountingOcTreeNode* CountingOcTree::updateNode(const OcTreeKey& k) { if (root == NULL) { root = new CountingOcTreeNode(); tree_size++; } CountingOcTreeNode* curNode (root); curNode->increaseCount(); // follow or construct nodes down to last level... for (int i=(tree_depth-1); i>=0; i--) { unsigned int pos = computeChildIdx(k, i); // requested node does not exist if (!nodeChildExists(curNode, pos)) { createNodeChild(curNode, pos); } // descent tree curNode = getNodeChild(curNode, pos); curNode->increaseCount(); // modify traversed nodes } return curNode; } void CountingOcTree::getCentersMinHits(point3d_list& node_centers, unsigned int min_hits) const { OcTreeKey root_key; root_key[0] = root_key[1] = root_key[2] = this->tree_max_val; getCentersMinHitsRecurs(node_centers, min_hits, this->tree_depth, this->root, 0, root_key); } void CountingOcTree::getCentersMinHitsRecurs( point3d_list& node_centers, unsigned int& min_hits, unsigned int max_depth, CountingOcTreeNode* node, unsigned int depth, const OcTreeKey& parent_key) const { if (depth < max_depth && nodeHasChildren(node)) { key_type center_offset_key = this->tree_max_val >> (depth + 1); OcTreeKey search_key; for (unsigned int i=0; i<8; ++i) { if (nodeChildExists(node,i)) { computeChildKey(i, center_offset_key, parent_key, search_key); getCentersMinHitsRecurs(node_centers, min_hits, max_depth, getNodeChild(node,i), depth+1, search_key); } } } else { // max level reached if (node->getCount() >= min_hits) { node_centers.push_back(this->keyToCoord(parent_key, depth)); } } } CountingOcTree::StaticMemberInitializer CountingOcTree::countingOcTreeMemberInit; } // namespace
/* * MIT License * * Copyright (c) 2016 Caetano Sauer * * 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 "options.h" #include <mutex> #include <fstream> namespace fineline { using std::string; void Options::init_description(popt::options_description& opt) { opt.add_options() /* General log manager options */ ("logpath,l", popt::value<string>()->default_value("log"), "Path in which log is stored (directory if file-based)") ("format", popt::value<bool>()->default_value(false)->implicit_value(true), "Whether to format the log, deleting all existing log files or blocks") ("log_recycle", popt::value<bool>()->default_value(false)->implicit_value(true), "Whether to clean-up log by deleting old files/partitions") /* File-based log (legacy::log_storage) options */ ("log_file_size", popt::value<unsigned>()->default_value(1024), "Maximum size of a log file (in MB)") ("log_max_files", popt::value<unsigned>()->default_value(0), "Maximum number of log files to maintain (0 = unlimited)") ("log_index_path", popt::value<string>()->default_value("index.db"), "Path to log index file") ("log_index_path_relative", popt::value<bool>()->default_value(true), "Whether log index path is relative to logpath or absolute") ; } popt::options_description& Options::get_description() { /* * This code makes sure that the descriptions are initialized only once. * After that, all callers will get the same descriptions, regardless of * multi-threaded schedules. */ static std::once_flag init_once_flag; static popt::options_description desc; std::call_once(init_once_flag, init_description, std::ref(desc)); return desc; } Options::Options() { // Initialize with default option values int argc = 0; char* ptr = nullptr; popt::store(popt::parse_command_line(argc, &ptr, get_description()), map_); } Options::Options(int argc, char** argv) { popt::store(popt::parse_command_line(argc, argv, get_description()), map_); } Options::Options(string config_file) { parse_from_file(config_file); } void Options::parse_from_file(string path) { std::ifstream is {path}; popt::store(popt::parse_config_file(is, get_description(), true), map_); } } // namespace fineline
#include "stdafx.h" #include "DevConsole.h" DevConsole DevConsole::m_instance; void DevConsole::init(int maxHistory) { // TODO(Ben): Add setCapacity new (&m_history) CommandRing(maxHistory); } void DevConsole::addListener(const nString& command, FuncNewCommand f, void* meta) { EventBinding eb = { f, meta }; m_commandListeners[command].emplace_back(eb); } // Adds listener for any command void DevConsole::addListener(FuncNewCommand f, void* meta) { EventBinding eb = { f, meta }; m_anyCommandListeners.emplace_back(eb); } bool DevConsole::removeListener(const nString& command, FuncNewCommand f) { auto& it = m_commandListeners.find(command); if (it == m_commandListeners.end()) return false; auto& listeners = it->second; auto foundListener = std::find(listeners.begin(), listeners.end(), f); if (foundListener != listeners.end()) { listeners.erase(foundListener, foundListener + 1); return true; } return false; } bool DevConsole::removeListener(FuncNewCommand f) { auto foundListener = std::find(m_anyCommandListeners.begin(), m_anyCommandListeners.end(), f); if (foundListener != m_anyCommandListeners.end()) { m_anyCommandListeners.erase(foundListener, foundListener + 1); return true; } return false; } void DevConsole::addCommand(const nString& s) { m_commandListeners.emplace(s, std::vector<EventBinding>()); } bool DevConsole::write(nString s) { // Remove leading ` while (s.size() && s.front() == '`') { s.erase(0, 1); } if (s.empty()) return false; // TODO(Ben): Concern about thread safety. // Ringbuffer push invalidates data... have to copy nString sCopy = s; m_history.push(sCopy); // Broadcast to listeners listening for any event for (auto& eb : m_anyCommandListeners) { eb.function(eb.metaData, s); } // Broadcast to specific listeners. nString command = getFirstToken(s); auto& it = m_commandListeners.find(command); if (it == m_commandListeners.end()) return false; for (auto& eb : it->second) { eb.function(eb.metaData, s); } return true; } void DevConsole::toggleFocus() { m_isFocused = !m_isFocused; if (m_isFocused) { // Enable input vui::InputDispatcher::key.onKeyDown += makeDelegate(*this, &DevConsole::onKeyDown); vui::InputDispatcher::key.onText += makeDelegate(*this, &DevConsole::onTextInput); } else { // Disable input vui::InputDispatcher::key.onKeyDown -= makeDelegate(*this, &DevConsole::onKeyDown); vui::InputDispatcher::key.onText -= makeDelegate(*this, &DevConsole::onTextInput); } } void DevConsole::setFocus(bool focus) { if (focus != m_isFocused) { toggleFocus(); } } const nString& DevConsole::getHistory(const i32& index) { return m_history.at(index); } nString DevConsole::getFirstToken(nString input) { size_t i = 0; while (i < input.size()) { while (input[i] == ' ') i++; size_t start = i; while (input[i] != ' ' && i < input.size()) i++; if (i - start > 0) { return input.substr(start, i - start); } } return ""; } void DevConsole::tokenize(nString& input, OUT std::vector<nString>& tokens) { // TODO(Ben): Pass in delimiters size_t i = 0; while (i < input.size()) { while (input[i] == ' ') i++; size_t start = i; while (input[i] != ' ' && i < input.size()) i++; if (i - start > 0) { tokens.emplace_back(input.substr(i, i - start)); } } } void DevConsole::onKeyDown(Sender s, const vui::KeyEvent& ev) { // TODO(Ben): Unicode is gonna be a nightmare if (ev.keyCode == VKEY_RETURN || ev.keyCode == VKEY_RETURN2) { write(m_currentLine); m_currentLine = ""; } else if (ev.keyCode == VKEY_BACKSPACE || ev.keyCode == VKEY_DELETE) { if (m_currentLine.size()) m_currentLine.pop_back(); } } void DevConsole::onTextInput(Sender s, const vui::TextEvent& ev) { const char* t = ev.text; while (*t != '\0') { m_currentLine += (*t); t++; } }
; Audio interfaces. MapSetup_Sound_Off:: push hl push de push bc push af ldh a, [hROMBank] push af ld a, BANK(_MapSetup_Sound_Off) ldh [hROMBank], a ld [MBC3RomBank], a call _MapSetup_Sound_Off pop af ldh [hROMBank], a ld [MBC3RomBank], a pop af pop bc pop de pop hl ret UpdateSound:: push hl push de push bc push af ldh a, [hROMBank] push af ld a, BANK(_UpdateSound) ldh [hROMBank], a ld [MBC3RomBank], a call _UpdateSound pop af ldh [hROMBank], a ld [MBC3RomBank], a pop af pop bc pop de pop hl ret _LoadMusicByte:: ; wCurMusicByte = [a:de] ldh [hROMBank], a ld [MBC3RomBank], a ld a, [de] ld [wCurMusicByte], a ld a, BANK(LoadMusicByte) ldh [hROMBank], a ld [MBC3RomBank], a ret PlayMusic:: ; Play music de. push hl push de push bc push af ldh a, [hROMBank] push af ld a, BANK(_PlayMusic) ; aka BANK(_MapSetup_Sound_Off) ldh [hROMBank], a ld [MBC3RomBank], a ld a, e and a jr z, .nomusic call _PlayMusic jr .end .nomusic call _MapSetup_Sound_Off .end pop af ldh [hROMBank], a ld [MBC3RomBank], a pop af pop bc pop de pop hl ret PlayMusic2:: ; Stop playing music, then play music de. push hl push de push bc push af ldh a, [hROMBank] push af ld a, BANK(_PlayMusic) ldh [hROMBank], a ld [MBC3RomBank], a push de ld de, MUSIC_NONE call _PlayMusic call DelayFrame pop de call _PlayMusic pop af ldh [hROMBank], a ld [MBC3RomBank], a pop af pop bc pop de pop hl ret PlayCry:: ; Play cry de. push hl push de push bc push af ldh a, [hROMBank] push af ; Cries are stuck in one bank. ld a, BANK(PokemonCries) ldh [hROMBank], a ld [MBC3RomBank], a ld hl, PokemonCries rept 6 ; sizeof(mon_cry) add hl, de endr ld e, [hl] inc hl ld d, [hl] inc hl ld a, [hli] ld [wCryPitch], a ld a, [hli] ld [wCryPitch + 1], a ld a, [hli] ld [wCryLength], a ld a, [hl] ld [wCryLength + 1], a ld a, BANK(_PlayCry) ldh [hROMBank], a ld [MBC3RomBank], a call _PlayCry pop af ldh [hROMBank], a ld [MBC3RomBank], a pop af pop bc pop de pop hl ret PlaySFX:: ; Play sound effect de. ; Sound effects are ordered by priority (highest to lowest) push hl push de push bc push af ; Is something already playing? call CheckSFX jr nc, .play ; Does it have priority? ld a, [wCurSFX] cp e jr c, .done .play ldh a, [hROMBank] push af ld a, BANK(_PlaySFX) ldh [hROMBank], a ld [MBC3RomBank], a ld a, e ld [wCurSFX], a call _PlaySFX pop af ldh [hROMBank], a ld [MBC3RomBank], a .done pop af pop bc pop de pop hl ret WaitPlaySFX:: call WaitSFX jp PlaySFX WaitSFX:: ; infinite loop until sfx is done playing push hl .wait ld hl, wChannel5Flags1 bit 0, [hl] jr nz, .wait ld hl, wChannel6Flags1 bit 0, [hl] jr nz, .wait ld hl, wChannel7Flags1 bit 0, [hl] jr nz, .wait ld hl, wChannel8Flags1 bit 0, [hl] jr nz, .wait pop hl ret IsSFXPlaying:: ; Return carry if no sound effect is playing. ; The inverse of CheckSFX. push hl ld hl, wChannel5Flags1 bit 0, [hl] jr nz, .playing ld hl, wChannel6Flags1 bit 0, [hl] jr nz, .playing ld hl, wChannel7Flags1 bit 0, [hl] jr nz, .playing ld hl, wChannel8Flags1 bit 0, [hl] jr nz, .playing pop hl scf ret .playing pop hl and a ret MaxVolume:: ld a, MAX_VOLUME ld [wVolume], a ret LowVolume:: ld a, $33 ; 40% ld [wVolume], a ret VolumeOff:: xor a ld [wVolume], a ret Unused_FadeOutMusic:: ld a, 4 ld [wMusicFade], a ret FadeInMusic:: ld a, 4 | (1 << MUSIC_FADE_IN_F) ld [wMusicFade], a ret SkipMusic:: ; Skip a frames of music. .loop and a ret z dec a call UpdateSound jr .loop FadeToMapMusic:: push hl push de push bc push af call GetMapMusic_MaybeSpecial ld a, [wMapMusic] cp e jr z, .done ld a, 8 ld [wMusicFade], a ld a, e ld [wMusicFadeID], a ld a, d ld [wMusicFadeID + 1], a ld a, e ld [wMapMusic], a .done pop af pop bc pop de pop hl ret PlayMapMusic:: push hl push de push bc push af call GetMapMusic_MaybeSpecial ld a, [wMapMusic] cp e jr z, .done push de ld de, MUSIC_NONE call PlayMusic call DelayFrame pop de ld a, e ld [wMapMusic], a call PlayMusic .done pop af pop bc pop de pop hl ret EnterMapMusic:: push hl push de push bc push af xor a ld [wDontPlayMapMusicOnReload], a ld de, MUSIC_BICYCLE ld a, [wPlayerState] cp PLAYER_BIKE jr z, .play call GetMapMusic_MaybeSpecial .play push de ld de, MUSIC_NONE call PlayMusic call DelayFrame pop de ld a, e ld [wMapMusic], a call PlayMusic pop af pop bc pop de pop hl ret TryRestartMapMusic:: ld a, [wDontPlayMapMusicOnReload] and a jr z, RestartMapMusic xor a ld [wMapMusic], a ld de, MUSIC_NONE call PlayMusic call DelayFrame xor a ld [wDontPlayMapMusicOnReload], a ret RestartMapMusic:: push hl push de push bc push af ld de, MUSIC_NONE call PlayMusic call DelayFrame ld a, [wMapMusic] ld e, a ld d, 0 call PlayMusic pop af pop bc pop de pop hl ret SpecialMapMusic:: ld a, [wPlayerState] cp PLAYER_SURF jr z, .surf cp PLAYER_SURF_PIKA jr z, .surf ld a, [wStatusFlags2] bit STATUSFLAGS2_BUG_CONTEST_TIMER_F, a jr nz, .contest .no and a ret .bike ld de, MUSIC_BICYCLE scf ret .surf ld de, MUSIC_SURF scf ret .contest ld a, [wMapGroup] cp GROUP_NONE jr nz, .no ld a, [wMapNumber] cp MAP_NONE jr z, .ranking cp MAP_NONE jr nz, .no .ranking ld de, MUSIC_BUG_CATCHING_CONTEST_RANKING scf ret GetMapMusic_MaybeSpecial:: call SpecialMapMusic ret c jp GetMapMusic CheckSFX:: ; Return carry if any SFX channels are active. ld a, [wChannel5Flags1] bit 0, a jr nz, .playing ld a, [wChannel6Flags1] bit 0, a jr nz, .playing ld a, [wChannel7Flags1] bit 0, a jr nz, .playing ld a, [wChannel8Flags1] bit 0, a jr nz, .playing and a ret .playing scf ret TerminateExpBarSound:: xor a ld [wChannel5Flags1], a ld [wSoundInput], a ldh [rNR10], a ldh [rNR11], a ldh [rNR12], a ldh [rNR13], a ldh [rNR14], a ret ChannelsOff:: ; Quickly turn off music channels xor a ld [wChannel1Flags1], a ld [wChannel2Flags1], a ld [wChannel3Flags1], a ld [wChannel4Flags1], a ld [wSoundInput], a ret SFXChannelsOff:: ; Quickly turn off sound effect channels xor a ld [wChannel5Flags1], a ld [wChannel6Flags1], a ld [wChannel7Flags1], a ld [wChannel8Flags1], a ld [wSoundInput], a ret
; ; This file is automatically generated ; ; Do not edit!!! ; ; djm 12/2/2000 ; ; ZSock Lib function: sock_listen SECTION code_clib PUBLIC sock_pair_listen PUBLIC _sock_pair_listen EXTERN no_zsock INCLUDE "packages.def" INCLUDE "zsock.def" .sock_pair_listen ._sock_pair_listen ld a,r_sock_pair_listen call_pkg(tcp_all) ret nc ; We failed..are we installed? cp rc_pnf scf ;signal error ret nz ;Internal error call_pkg(tcp_ayt) jr nc,sock_pair_listen jp no_zsock
// https://www.interviewbit.com/problems/palindrome-string/ int Solution::isPalindrome(string A) { int len = A.length(); for(int i=0;i<len;i++) { A[i] = tolower(A[i]); } int l = 0; int h = len; while(l<=h) { if(!(A[l]>='a' && A[l]<='z') && !(A[l]>='0' && A[l]<='9')) { l++; } else if(!(A[h]>='a' && A[h]<='z') && !(A[h]>='0' && A[h]<='9')) { h--; } else if(A[l] == A[h]) { l++; h--; } else { return 0; } } return 1; } /* int Solution::isPalindrome(string A) { // Do not write main() function. // Do not read input, instead use the arguments to the function. // Do not print the output, instead return values as specified // Still have a doubt. Checkout www.interviewbit.com/pages/sample_codes/ for more details int i = 0; int j = A.size()-1; LOOP:while(i < j){ char c = A[i]; char d = A[j]; if(! ( ( ( (int)c >= 97 ) && ( (int)c <= 122 ) ) || ( ( (int)c >= 65 ) && ( (int)c <= 90 ) ) || ( isdigit(c) ) ) ) { i++; goto LOOP; } if(! ( ( ( (int)d >= 97 ) && ( (int)d <= 122 ) ) || ( ( (int)d >= 65 ) && ( (int)d <= 90 ) ) || ( isdigit(d) ) ) ){ j--; goto LOOP; } c = tolower(c); d = tolower(d); if(c != d){ return 0; } i++; j--; } return 1; } */
; Copyright (c) 2004, Intel Corporation. All rights reserved.<BR> ; This program and the accompanying materials ; are licensed and made available under the terms and conditions of the BSD License ; which accompanies this distribution. The full text of the license may be found at ; http://opensource.org/licenses/bsd-license.php ; ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. ; ; Module Name: ; ; EnableDisableInterrupts.Asm ; ; Abstract: ; ; EnableDisableInterrupts function ; ; Notes: ; ;------------------------------------------------------------------------------ .code ;------------------------------------------------------------------------------ ; VOID ; EFIAPI ; EnableDisableInterrupts ( ; VOID ; ); ;------------------------------------------------------------------------------ EnableDisableInterrupts PROC sti cli ret EnableDisableInterrupts ENDP END
; A024488: a(n) = (1/(3n-1))*M(3n; n,n,n), where M(...) is a multinomial coefficient. ; Submitted by Christian Krause ; 3,18,210,3150,54054,1009008,19953648,411543990,8764362750,191413682460,4266468608220,96706621786320,2223107844022800,51721284534408000,1215794995122150720,28837137540553512390 mov $1,$0 add $1,$0 add $1,1 mov $2,$0 add $2,$1 bin $1,$0 mul $0,2 bin $2,$0 add $0,1 div $1,$0 mul $1,$2 mov $0,$1 mul $0,3
int aFxQA ,JAw/*nN8*/, MF, p ,Y5D ,kZ, Nsb , Z//nk ,/*pN*/ZYGs/*sl1R*/, y, //Gx GVw ,pmB , fiM , PR , PzIc//siEG , U6pU, Z3 ,jVy , hO2PU //acj , /*eWc*/ eTk5BM,L ,i59 , UG , AF , LnuO,hcGz , C9R, xoR1/*FU*/ , yXf , vZxuEv , Zg8GQ ,GUO ,hvIPx , Q,gN, ePCq ,OQN, U1D , L6,H , MejvO,Mw,g ;void f_f0 //F () {if /*98*/( true//n )//f for (int i=1;i< 1;++i) ; else{ if ( true/*z*/){ { ;//gn for (int //u i=1 ; i< 2 /*0W*/;++i ) /*ug*/ if ( true ) for //SYpF8 (int i=1 // ; i<3 ;++i) {{for (int i=1; i< 4 ;++i) { }/*lG*///Zr } } else { for(int i=1/*u*/ ; i<5;++i) { { } { }//FJ6l } {{ }if (true )/*oZ*//*n*/{ { }}/*V*/ else return ;/*0y*/ } { } } } if/*u5q*/( true ) {return ; } else { {//Qu }} return ;} else {{if( true ) { }else { } } ;return ; for/*w*/(int i=1 ;i< 6;++i ) //Qm {for (int i=1 ;i<7//4Q2 ;++i ){}{ return ;{ } /*H*/}} } for (int /*U1F*/ i=1 ; i< /**/8 ;++i)for(int i=1; i<9 ;++i/*Vnda*/ )return ; {{{ volatile int E , is8h ; //EC01 if ( true//z )if ( true )g=is8h +E ; else // { /*D*/ }else ; } };{ return ; ;}{return ; }} {int N , QAXO; volatile int xY , /*E*/ CS,p4ho ,Ii9 ,/*wP*/ fmDl,Ivr ; {volatile int u5Uc , x , u9F, FW0; { {} { } } aFxQA= FW0 + u5Uc+ x + u9F ; { /*4Y3*/}{ { /*o4PB*/} } }//e QAXO //w = Ivr+ xY +CS; N = p4ho+/*vi6*/Ii9+fmDl; }//8 {int CU5 ;volatile int Ln , jtW//ze ,neS,xvt ,YIXf , UBK, cmJ ;JAw =cmJ+ Ln +jtW ;for (int i=1 ; i< 10;++i//H ) CU5= neS+ xvt+/*ZIa*/YIXf+//cgV UBK;return ; {{/*mEmh*/{ {} }}} } } for(int i=1 ;i< 11 ;++i ){ int R;volatile int HdUX , D , T, e,Yixgt ,lUBt , //rL y920C,wE/**/,OcS, jT ; {{ { }}{ for(int i=1 ;/*Nlu*/i< 12 ;++i )return ; }}for (int i=1;/*ZQ*/i< 13 ;++i) R = jT/*mpc*/ //6 + HdUX +D+ T +e + Yixgt ; MF = lUBt +y920C+ /*HA*/wE + OcS ; } for//V (int i=1 ; i< 14 ;++i ) {{//ooi /*d*/int d2 ; volatile int K2, D0Mm , sh ;;d2 =sh + K2 +D0Mm ;{//nv {} } } if (true ) { for/*sQj*/(int i=1 ; i<15 ;++i ) {;{ {} } }; ;// } else { return ;{return ;} } /*v2*/{;/**/for (int i=1; i< 16 ;++i )/*Y*//*O*/{{ { }}for(int i=1/*x3P*/ ;i< 17;++i)for (int i=1 ; /*m*/i< 18;++i) if(true ) return ;else{{;/*j*/} }} { {//2 int QS; volatile int UHgTLV//N6p //y9 ,/*LOGo*/ ol ,LE ; QS= LE+ UHgTLV +ol; } ;}return ;}{{ int W6r ; volatile int eHFo ,/**/ dB ,uQ ; { volatile int Y ; p = Y; { } ; {} }W6r =/**/ uQ + eHFo + dB// ; {// ; }} for (int i=1; i< 19 ;++i //MdD5 )/*r*/ return ;{ return ;{ } } //Kiz { volatile int Ei, FBw//gT ; {}Y5D= FBw //E + Ei ; } } // } for//rE (int i=1//O ;i<20;++i )for (int i=1;i<21 ;++i )//Csun ; { volatile int iWJ,xKg, GLw ,/*4cX*/ WPlh,E8k, q4e2 ,//bz G ; {int Wkm ;volatile int ToJ , VEx ,P9qGG , Qz;for (int i=1; i< 22/*d3*/;++i ) { volatile int Me , Ty ,RwZ ; if ( true) { ; for (int i=1 ; i< 23 ;++i)//iC {return//a ; }}else{ } if( true )kZ// =RwZ+/*5wA*///oLz Me+ Ty;else/*5XZy*/ {}} {return ;/**/ for (int i=1 ; /*zn*/i< 24 ;++i )for(int i=1 ;// i<25 ;++i ){} } ; {for(int i=1 ;i< 26//Eay ;++i ) if ( true//q ) { { volatile int TNow0e;Nsb= //Gfr TNow0e; } { } }else for (int i=1 ;i< 27;++i ) { if (true) {} else ; //eM5 }for (int i=1 ; i<28;++i ) for(int i=1;i< 29 ;++i ) for(int i=1; i< 30 ;++i ) for (int /*2VR*/ i=1;i<31 ;++i ) {{} }} //5T1 for (int i=1;i< 32 ;++i) { {volatile int lzxIy ; {;} Z= lzxIy ; } }Wkm/*1Jt*/=/**/Qz+ ToJ + VEx+ P9qGG ; } {if (true)// /*3*/{int FdpJ; volatile int jH777 //KU , TJ ; FdpJ/*r*/=TJ+ jH777 ; {;}} else return ; { volatile int w , SxJy,KkY6; ;ZYGs= KkY6+ /**/w+SxJy ;;}}y= G+iWJ +xKg +/*BHrCUl*/ GLw+ WPlh +E8k + q4e2 ;; }{//l volatile int i, jtk , C18//IF ,O , iiXx//3Dl , zJ4 , Oa, SBxCql ,tvhju ,z70a//vE , /*Q*/b7fI , DT , cv9/*swx*/ ,DXH ,/*tm*/ h9 ;for//wBv (int i=1/*S*/; i<33 ;++i ) if ( true ){{ volatile int cLI9D, Bu0 /*M6*/ ;GVw /**/= /*wGMW*/Bu0 +cLI9D ; for (int i=1 ; i< 34 ;++i) { volatile int rYmp;pmB= /*6q*/rYmp ; /*VU*/}{} } ; return ;;}else { for (int i=1 ; i< 35;++i ); {for(int i=1;i<36 ;++i /*nm*/) return ; for (int i=1 ; i<37;++i) for /*cPuEV*/(int i=1 ;i<38 ;++i ) for (int i=1 ; i< 39;++i ) {//LF // { } {/*5*/ {} }}}{ {if(true) if( true/*1w*/ ) { }else ; else ;} } return ;}{return ;/*c*/{ { for(int i=1 ;i< 40;++i/**/) { } } ; {{ if (true) ;else{ } }} } {if ( true) return ;else {{}}{{ }return ;} } } if( true )//gFK fiM = h9 +i +jtk+ C18 + O; else PR =iiXx+/*eJ*/zJ4+ Oa + SBxCql; for (int i=1 ; i<41 ;++i )PzIc//r2 /*A4*/=tvhju /*G5r*/+ z70a +b7fI +DT +cv9+ DXH//A9 ; for(int i=1; i< 42 ;++i) return // ;{ /*pbLui*/volatile int HX , HG ,ctVg, /*tdSwl*/RWOBG /*D9B*/;if //yJ (//kBb true) if/*S*/ ( true )if (true ){ { ;/*0SiF*/{} if( true ) {}else{} }{ {return ; }{{}} } } else U6pU =//C RWOBG+HX + HG + ctVg; else ;else { volatile int X4lx , dX,n4oNK;Z3 =n4oNK+ X4lx+ dX;/*3*/ ; } if ( true ) { {} }else return ;if (true ) //1 {//bZ1 volatile int Axq0TMJ ,YwIE,MSzS, kll1 ;jVy =//Fk kll1 /*rL9*/+Axq0TMJ+YwIE +MSzS; /*7KV*/}else { { if ( true ) { }else/*eKh*/ {}//u }{ }} return ; }/*l*/ } return ; }void f_f1/*BA*/() { return ; {volatile int nW4 ,OCn , B , DYgSy, Uj //J ; hO2PU = Uj+ nW4+ OCn + B+ DYgSy ;return ; {{/*dra*/{//oXiu return ; } { return ; {{} { }}{//Do }// /*e*/} {{} }};} } {{ if/**/ ( true) for (int i=1;i< 43 ;++i ){; } else{ int Kxp; volatile int g42u, n4, FV ;{}Kxp = FV + g42u+n4 ;}for(int i=1 ; i< 44 ;++i)//bVa for(int i=1;i< 45 ;++i )return ;// { return ; } }{int /*3Z*/ Fq//uF ;volatile int i4F , xe,bLvv; for (int i=1;i<//ne 46 ;++i) { { return ;} } Fq= bLvv // +//t i4F + xe; } return ;} {for (int i=1; i< 47 ;++i ){int Kw ; volatile int xZo, yO, YI,EHP;return ; if ( true ) {{volatile int cmI7m; eTk5BM = cmI7m ; } for(int i=1; i<48 ;++i//X ){{} for (int i=1 ; i< 49 ;++i ){} for//weRH (int i=1 ; i<50 ;++i ) ;}{ int LG4Mi; volatile int /*MEK*/ QcYi, m7; /*d5P*/for/*bbV*/ (int i=1; i< 51;++i ) LG4Mi = m7+ QcYi; } }else Kw =EHP + xZo //LzHXE +yO +/*PqXTt*/YI ; }if ( /*sfv*/true ) {int F2xc ;/*AQ*/ volatile int I2ikv,bu, EZNKC ; {{} { }/*dTA*/ } { { {}}//R {/*P*/} }F2xc= EZNKC + I2ikv +//E bu ; }else/*G*/ return ; {volatile int //Y wh ,GN ,UP,me//vr ;/*g*/return ;; L =me+ wh + GN + UP; return ; ; }} for (int i=1 ; i< 52 /*v*/ ;++i ) {return ; {for (int i=1;i< 53 ;++i/*n*/ ) {;}{ if(true )if ( true) if ( true) { { {} } if//qp (true/*rDj*/){ }else{} ; }else{} else { } else ; // } ; };} return ; } void f_f2 () { volatile int EvVyM,/**/ Mxo //S , cHjl, Vk,Ijy; for (int i=1 //2YH ; i<54 ;++i){ volatile int oAr, ty2 ,VP , qH , r //tti ,pYO,jjzE ,W0,//VON Eozg ,r9 ;//Kx i59= r9 +oAr+ty2 +VP +qH ; {{ {{ } } /*Z*/return ; /**/} {return ; } { { {} if( true ){} else ;{//oy9 }} }}/*Zwb*//**/ for (int i=1 ;i<55;++i) UG = r + pYO +jjzE+ W0 + Eozg ;{ {for //9z (int i=1;i< 56;++i )return ;{ ;if ( true){/**/ }else{ {//Hof return ; {}/*2D*/} }/*WC*/ }} {return ; }{{ /*roek*/for/*O2*///Pv (int i=1 ;i< 57;++i ) return ; } }} }if (true ){ { int xYG1r; volatile int Qok , n,rn;if (true) { if ( true); else { } { } { }{} } else return ; return ;xYG1r= rn + Qok +n ;/*k*/} return ; if ( true){ for(int i=1;i<58;++i )//s return ;for (int /*rqGh*/i=1 ; i< 59 ;++i ) if ( true) ;else { volatile int bR , nOiX, I5MQv;//f ; if(true )return ; else { } if ( /*XxM*/true) { {} for (int i=1 ; i< 60;++i ){}}else //sb AF=I5MQv + bR +nOiX ;}{ { return ;return ;} {;/*Mv*/}{} }{{{ return ; }}{} } } else { { return ; } {//EV2 ; { }/*B*/ return/*cW*/ ; { for (int i=1 ; i<61 ;++i //10 ) { { { } } }{ }}//zD6 }//q { return ; for(int i=1;i<62 ;++i //rWL ) return ; } { /*ZB*///9 {int /*MG*/ Sh/*ho*/; // volatile int XacN ; for (int i=1 ;// i< 63 ;++i )return ;/*oxz*/Sh= XacN ;{ {} } }{ }; { } }/**/} { volatile int CfPSX , ue7 , n8XD ;{ for (int i=1; /*q*/i<64;++i)if (true )if (true)return/*lv*/ ;else ; else ; { }}LnuO/*T*/ = n8XD + CfPSX // + ue7;{volatile int z , U8w;;for(int i=1//H ; i< /*l*/ 65 ;++i )hcGz=//r /*tOL*/U8w/*BSG*/+ //a z; } { int vFZ; volatile int gI, fP ,//mV XLG;{ //9Mi volatile int XCuP , mO ,//2 //V nh;for (int i=1;//zrb i< 66;++i)C9R = nh//1hGw1 ; xoR1=XCuP +// mO ; } for(int i=1 ; i<67/*qw*/ ;++i )vFZ/*I*/ /*s*/= XLG +gI + fP/*gP*/;} for (int i=1/**/ ; i<68;++i ) { int App;volatile int XGhMx , OfP , xy,QN , Vg /**/ //mP ;for(int i=1 ; i<69 ;++i ) for (int i=1; i< 70;++i /*f*/ ) yXf= /*ih*/Vg + XGhMx + OfP ;/*F*/ App= xy+ QN ;} } { volatile int br,SQd0U, fTKY, eum; for (int i=1 ;i< 71//Dzo ;++i) return ;vZxuEv=eum+ br +SQd0U +fTKY;/*H*///qUo2N6 return ; } }else Zg8GQ =Ijy +EvVyM //Sn +Mxo+ cHjl/**/+ Vk ; { volatile int HrrO, Llhk , IbZ9 , oYOK;{int v1nf; volatile int gD , tMis8, SDv7 ; { {for (int i=1 ;i<72//GG ;++i)if ( true ) { }else{ //GP9J } } if( true) { { {// } /*ZMmr*/} //H }else if( true ) if ( true ) { for (int i=1;i< 73;++i// ) {}/*I*/}else return ; // else return ;} return ; {{ {{ } } } }v1nf= SDv7 +//K7c gD+ /*sZ*/ tMis8;/*0*/} /*Xxx*/{{ for (int i=1 ; i< 74;++i//5lsz ) ; return ; }{ volatile int v ,eGtcc,AG ,wRF; GUO= wRF +v + eGtcc + AG ; ;/*PI*/ }} ;hvIPx= oYOK/*7E*/+HrrO + Llhk + IbZ9 ; } for (int i=1 ; i< 75;++i ) ;/*q*/ { volatile int/*gIX*/ OR,i8scc,OpgK19 , PV , X73KH ; {return ; { volatile int LUS,ctf /*9*/,Tx , qTx; Q = qTx+LUS + ctf + Tx //Hv8 ; return ;{ }{{ return ; ;//AfV }} } {for (int //A i=1; i< 76 ;++i ) //o { }for (int i=1;i< 77// ;++i ) { {} } }{return//U ;//2 } }return ; { if ( true ) { {} if( true ) ; else { if (true ){{ } } else {} ;{{}}} { { } { }} } else{ for (int i=1 //5Of ; i< 78;++i ) { volatile int z02, KzD ,DKT ; { }/*9*/; if ( true ){ } else gN =DKT+ z02+ KzD; } { } }{volatile int NRt ,Wy , OXg;{ { } return ;return ;} {} if ( true/*8El*/) {{ }{ } { }}else ePCq =OXg+ NRt + Wy; } { int juu ;volatile int lLGs, ZQ , vc ;{ ;}if(true )/*T8*/{}else for(int i=1 ; i<79 ;++i ) return ;return ;juu = vc + lLGs+ ZQ ;} if( true )return ;/*M*/ else { for (int //JT i=1 ;/*gx*/i< 80 ;++i ) {} for (int i=1 ; i< 81 ;++i ) { }; }//sU { return ; {}}{{} }/*Gol3*/for (int i=1 ;i< 82;++i ){volatile int RsF4 , OZf7O ; for(int i=1 ; i<83;++i )for (int i=1 ; i< 84//qvNl ;++i ) {for(int i=1; i< 85//MA ;++i ) for (int i=1;i<86;++i ) { } } for (int i=1;//I i< 87;++i )OQN= OZf7O+ RsF4; for(int i=1 ; i<88 ;++i)/*h*/{ return//Bd ;for(int i=1; i< 89 ;++i){/*l0*/ } /*s*/}/*Z2b4*/} ; } if ( true//g ) U1D = X73KH+ OR+ i8scc +OpgK19 + /*s*/PV ; else ; return ;for (int i=1//y88O ;i< 90 ;++i ) if(true ) { if( true ){volatile int /*O*/ TY, DHg;{ ; }L6= DHg +TY ;} else {volatile int ebacF/*y*/, XCi, TF,Khc ,m , o7A ;H=o7A+ ebacF//E + XCi; MejvO =TF + Khc // + m ; if(true){ { } /*GV*/{ { {/*OLg*/} }} } else/*6*/{ { for(int i=1; i< 91 ;++i ){ }}} { for (int i=1 ; i< 92 ;++i) { { } }//NnP0 } }{ { {} {//D }{ }{ //lN } } { return ;}/*EBiycvb*/return ;}/*O*/}else { {{} return ; }{{ } } return ;}}return//s ;} int main() { return 175010021 ; for(int i=1 ;i<93 ;++i ) ;//ow { volatile int Lrc, XzE ,qdp , c, aHdJG,tC62 ; /*p6*/ Mw = tC62 + Lrc+ XzE + qdp +c+aHdJG ; ; {{{ }}{ { {{ } }}}{ { /*do*/} for (int i=1; i< 94 ;++i){ } } { ; }} {for(int i=1 ; i<95 ;++i ){ int Yq ;/*7*/volatile int LFGs ,//dM VA , mm/*gdA*/; Yq= mm+ LFGs+ VA ; } { { {}{ } }} {//KTSll {//4 { }//GDl } { } { }} } } {for (int i=1/*73g*/ ;i< 96;++i ) ; {{ {{}}}//Z {{ int //Ku ZHovNb ; volatile int Ft8l7,qTU ; for(int /*TN*/i=1 ;i< 97;++i )if ( true)ZHovNb = qTU+ Ft8l7 ;else { }} } /*7*/return 2142914676;/*9*/{{}; }} { { int Y8R6 /*Dy*/; volatile int ywEo, /*N4*/L7 ,vF//m , F ;Y8R6= F +//HR ywEo + L7+ vF ;}{ ; /*Oa*/ //Y {}//B } } } }
/*************************************************************************** * Copyright (C) 2008 by Gabriella Caniglia * * gabriella.caniglia@oact.inaf.it * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * 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 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->, * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include <cstdlib> #include <cstring> #include "luteditor.h" #include "color.h" #include <QString> #include <QStringList> #include "qdebug.h" #include "vtkLookupTable.h" //--------------------------------------------------------------------- void SelectLookTable( QString palette, vtkLookupTable *lut) //--------------------------------------------------------------------- { QStringList palettes; palettes << "Default" << "Default Step" << "EField" << "Glow" << "Gray" << "MinMax" << "PhysicsContour" << "PureRed" << "PureGreen" << "PureBlue" << "Run1" << "Run2" << "Sar" << "Temperature" << "TenStep" << "VolRenGlow" << "VolRenRGB" << "VolRenRGB" << "VolRenTwoLev" << "AllYellow" << "AllCyane" << "AllViolet" << "AllWhite" << "AllBlack" << "AllRed" << "AllGreen" << "AllBlu"; switch( palettes.indexOf(palette)) { case 0: lutDefault( lut); break; case 1: lutDefaultStep( lut); break; case 2: lutEField( lut); break; case 3: lutGlow( lut); break; case 4: lutGray( lut); break; case 5: lutMinMax( lut); break; case 6: lutPhysicsContour( lut); break; case 7: lutPureRed( lut); break; case 8: lutPureGreen( lut); break; case 9: lutPureBlue( lut); break; case 10: lutRun1( lut); break; case 11: lutRun2( lut); break; case 12: lutSar( lut); break; case 13: lutTemperature( lut); break; case 14: lutTenStep( lut); break; case 15: lutVolRenGlow( lut); break; case 16: lutVolRenGreen( lut); break; case 17: lutVolRenRGB( lut); break; case 18: lutVolRenTwoLev( lut); break; case 19: lutAllYellow( lut); break; case 20: lutAllCyane( lut); break; case 21: lutAllViolet( lut); break; case 22: lutAllWhite( lut); break; case 23: lutAllBlack( lut); break; case 24: lutAllRed( lut); break; case 25: lutAllGreen( lut); break; case 26: lutAllBlu( lut); break; default: lutDefault( lut); break; } } //--------------------------------------------------------------------- void lutVolRenGreen( vtkLookupTable *lut) //--------------------------------------------------------------------- { //VolRenGreen unsigned char v[256*4] = { 0, 0, 255, 0, 0, 1, 253, 0, 0, 3, 252, 1, 0, 5, 251, 1, 0, 7, 249, 2, 0, 9, 248, 3, 0, 11, 247, 3, 0, 13, 245, 4, 0, 14, 244, 5, 0, 16, 243, 5, 0, 18, 241, 6, 0, 20, 240, 6, 0, 22, 239, 7, 0, 24, 237, 8, 0, 26, 236, 8, 0, 28, 235, 9, 0, 29, 233, 10, 0, 31, 232, 10, 0, 33, 231, 11, 0, 35, 229, 11, 0, 37, 228, 12, 0, 39, 227, 13, 0, 41, 225, 13, 0, 43, 224, 14, 0, 44, 223, 15, 0, 46, 221, 15, 0, 48, 220, 16, 0, 50, 219, 16, 0, 52, 217, 17, 0, 54, 216, 18, 0, 56, 215, 18, 0, 58, 213, 19, 0, 59, 212, 20, 0, 61, 211, 20, 0, 63, 209, 21, 0, 65, 208, 21, 0, 67, 207, 22, 0, 69, 206, 23, 0, 71, 204, 23, 0, 73, 203, 24, 0, 75, 202, 25, 0, 76, 200, 25, 0, 78, 199, 26, 0, 80, 198, 26, 0, 82, 196, 27, 0, 84, 195, 28, 0, 86, 194, 28, 0, 88, 192, 29, 0, 89, 191, 30, 0, 91, 190, 30, 0, 93, 188, 31, 0, 95, 187, 31, 0, 97, 186, 32, 0, 99, 184, 33, 0, 101, 183, 33, 0, 103, 182, 34, 0, 105, 180, 35, 0, 106, 179, 35, 0, 108, 178, 36, 0, 110, 176, 36, 0, 112, 175, 37, 0, 114, 174, 38, 0, 116, 172, 38, 0, 118, 171, 39, 0, 119, 170, 40, 0, 121, 168, 40, 0, 123, 167, 41, 0, 125, 166, 41, 0, 127, 164, 42, 0, 129, 163, 43, 0, 131, 162, 43, 0, 133, 160, 44, 0, 135, 159, 45, 0, 136, 158, 45, 0, 138, 157, 46, 0, 140, 155, 46, 0, 142, 154, 47, 0, 144, 153, 48, 0, 146, 151, 48, 0, 148, 150, 49, 0, 149, 149, 50, 0, 151, 147, 50, 0, 153, 146, 51, 0, 155, 145, 51, 0, 157, 143, 52, 0, 159, 142, 53, 0, 161, 141, 53, 0, 163, 139, 54, 0, 165, 138, 55, 0, 166, 137, 55, 0, 168, 135, 56, 0, 170, 134, 56, 0, 172, 133, 57, 0, 174, 131, 58, 0, 176, 130, 58, 0, 178, 129, 59, 0, 179, 127, 60, 0, 181, 126, 60, 0, 183, 125, 61, 0, 185, 123, 61, 0, 187, 122, 62, 0, 189, 121, 63, 0, 191, 119, 63, 0, 193, 118, 64, 0, 195, 117, 65, 0, 196, 115, 65, 0, 198, 114, 66, 0, 200, 113, 66, 0, 202, 111, 67, 0, 204, 110, 68, 0, 206, 109, 68, 0, 208, 108, 69, 0, 210, 106, 70, 0, 211, 105, 70, 0, 213, 104, 71, 0, 215, 102, 71, 0, 217, 101, 72, 0, 219, 100, 73, 0, 221, 98, 73, 0, 223, 97, 74, 0, 225, 96, 75, 0, 226, 94, 75, 0, 228, 93, 76, 0, 230, 92, 76, 0, 232, 90, 77, 0, 234, 89, 78, 0, 236, 88, 78, 0, 238, 86, 79, 0, 239, 85, 80, 0, 241, 84, 80, 0, 243, 82, 81, 0, 245, 81, 81, 0, 247, 80, 82, 0, 249, 78, 83, 0, 251, 77, 83, 0, 253, 76, 84, 0, 255, 74, 85, 1, 254, 75, 85, 3, 255, 76, 86, 5, 254, 76, 86, 7, 255, 77, 87, 9, 255, 78, 88, 11, 255, 78, 88, 13, 255, 79, 89, 15, 255, 80, 90, 17, 255, 80, 90, 19, 255, 81, 91, 21, 255, 82, 91, 22, 255, 82, 92, 24, 255, 83, 93, 26, 255, 84, 93, 28, 255, 84, 94, 30, 255, 85, 95, 32, 255, 86, 95, 34, 255, 86, 96, 36, 255, 87, 96, 38, 255, 88, 97, 40, 255, 88, 98, 42, 255, 89, 98, 43, 255, 90, 99, 45, 255, 90, 100, 47, 255, 91, 100, 49, 255, 92, 101, 51, 255, 92, 101, 53, 255, 93, 102, 55, 255, 94, 103, 57, 254, 94, 103, 59, 255, 95, 104, 61, 254, 96, 105, 63, 255, 96, 105, 65, 255, 97, 106, 66, 255, 98, 106, 68, 255, 98, 107, 70, 255, 99, 108, 72, 255, 100, 108, 74, 255, 100, 109, 76, 255, 101, 110, 78, 255, 102, 110, 80, 255, 102, 111, 82, 255, 103, 111, 84, 255, 104, 112, 86, 255, 104, 113, 87, 255, 105, 113, 89, 255, 106, 114, 91, 255, 106, 115, 93, 255, 107, 115, 95, 255, 108, 116, 97, 255, 108, 117, 99, 254, 109, 117, 101, 255, 110, 118, 103, 254, 110, 118, 105, 255, 111, 119, 107, 255, 112, 120, 109, 255, 112, 120, 110, 255, 113, 121, 112, 255, 114, 122, 114, 255, 114, 122, 116, 255, 115, 123, 118, 255, 116, 123, 120, 255, 116, 124, 122, 255, 117, 125, 124, 255, 118, 125, 126, 255, 118, 126, 128, 255, 119, 127, 130, 255, 120, 127, 131, 255, 120, 128, 133, 255, 121, 128, 135, 254, 122, 129, 137, 255, 122, 130, 139, 254, 123, 130, 141, 255, 124, 131, 143, 255, 124, 132, 145, 255, 125, 132, 147, 255, 126, 133, 149, 255, 126, 133, 151, 255, 127, 134, 153, 255, 128, 135, 154, 255, 128, 135, 156, 255, 129, 136, 158, 255, 130, 137, 160, 255, 130, 137, 162, 255, 131, 138, 164, 255, 132, 138, 166, 255, 132, 139, 168, 255, 133, 140, 170, 255, 134, 140, 172, 254, 134, 141, 174, 255, 135, 142, 175, 255, 136, 142, 177, 255, 136, 143, 179, 254, 137, 143, 181, 255, 138, 144, 183, 255, 138, 145, 185, 255, 139, 145, 187, 255, 140, 146, 189, 255, 140, 147, 191, 255, 141, 147, 193, 255, 142, 148, 195, 255, 142, 148, 197, 254, 143, 149, 198, 255, 144, 150, 200, 254, 144, 150, 202, 255, 145, 151, 204, 255, 146, 152, 206, 255, 146, 152, 208, 255, 147, 153, 210, 255, 148, 153, 212, 255, 148, 154, 214, 255, 149, 155, 216, 254, 150, 155, 218, 255, 150, 156, 219, 255, 151, 157, 221, 255, 152, 157, 223, 255, 152, 158, 225, 255, 153, 158, 227, 255, 154, 159 }; lut->SetNumberOfTableValues(256); for(int i=0; i<256; i++) { int k = i*4; lut->SetTableValue(i, v[k]/255.0, v[k+1]/255.0, v[k+2]/255.0, v[k+3]/255.0); } }; //--------------------------------------------------------------------- void lutVolRenGlow( vtkLookupTable *lut) //--------------------------------------------------------------------- { //volrenGlow unsigned char v[256*4] = { 0, 0, 0, 0, 0, 0, 0, 1, 5, 0, 0, 2, 5, 0, 0, 3, 9, 0, 0, 4, 9, 0, 0, 5, 13, 0, 0, 6, 13, 0, 5, 7, 17, 0, 5, 8, 17, 0, 5, 9, 21, 0, 5, 10, 21, 0, 5, 11, 25, 0, 5, 12, 25, 0, 5, 13, 29, 0, 5, 14, 29, 0, 9, 15, 33, 0, 9, 16, 33, 0, 9, 17, 37, 0, 9, 18, 37, 0, 9, 19, 41, 0, 9, 20, 41, 0, 9, 21, 45, 0, 9, 22, 45, 0, 9, 23, 49, 0, 13, 24, 49, 0, 13, 25, 53, 0, 13, 26, 53, 0, 13, 27, 57, 0, 13, 28, 57, 0, 13, 29, 61, 0, 13, 30, 61, 5, 13, 31, 65, 5, 13, 32, 65, 5, 13, 33, 69, 5, 13, 34, 69, 5, 13, 35, 73, 5, 17, 36, 73, 5, 17, 37, 77, 5, 17, 38, 81, 5, 17, 39, 81, 5, 17, 40, 85, 5, 17, 41, 85, 5, 17, 42, 89, 5, 17, 43, 89, 9, 17, 44, 93, 9, 17, 45, 93, 9, 17, 46, 97, 9, 17, 47, 97, 9, 17, 48, 101, 9, 17, 49, 101, 9, 17, 50, 105, 9, 17, 51, 105, 9, 17, 52, 109, 13, 17, 53, 109, 13, 17, 54, 113, 13, 17, 55, 113, 13, 17, 56, 117, 13, 17, 57, 117, 13, 17, 58, 121, 13, 17, 59, 125, 13, 17, 60, 125, 13, 17, 61, 128, 17, 17, 62, 128, 17, 17, 63, 132, 17, 21, 64, 132, 17, 21, 65, 136, 17, 21, 66, 136, 17, 21, 67, 140, 17, 21, 68, 140, 21, 21, 69, 144, 21, 21, 70, 144, 21, 21, 71, 148, 21, 21, 72, 148, 21, 21, 73, 152, 25, 21, 74, 152, 25, 21, 75, 156, 25, 21, 76, 156, 25, 21, 77, 156, 25, 21, 78, 160, 29, 21, 79, 160, 29, 21, 80, 164, 29, 21, 81, 164, 29, 21, 82, 168, 33, 21, 83, 168, 33, 21, 84, 168, 33, 21, 85, 172, 33, 21, 86, 172, 37, 21, 87, 176, 37, 21, 88, 176, 37, 21, 89, 176, 37, 21, 90, 180, 41, 21, 91, 180, 41, 21, 92, 180, 41, 21, 93, 184, 45, 21, 94, 184, 45, 21, 95, 188, 45, 21, 96, 188, 49, 21, 97, 188, 49, 21, 98, 192, 49, 21, 99, 192, 53, 21, 100, 192, 53, 21, 101, 192, 53, 21, 102, 196, 57, 21, 103, 196, 57, 21, 104, 196, 61, 21, 105, 200, 61, 21, 106, 200, 61, 21, 107, 200, 65, 21, 108, 200, 65, 21, 109, 204, 69, 21, 110, 204, 69, 21, 111, 204, 69, 21, 112, 208, 73, 21, 113, 208, 73, 21, 114, 208, 77, 21, 115, 208, 77, 21, 116, 208, 81, 21, 117, 212, 81, 21, 118, 212, 85, 21, 119, 212, 85, 21, 120, 212, 89, 21, 121, 212, 89, 21, 122, 216, 93, 21, 123, 216, 93, 21, 124, 216, 97, 21, 125, 216, 97, 21, 126, 216, 101, 21, 127, 220, 101, 21, 128, 220, 105, 21, 129, 220, 105, 21, 130, 220, 109, 21, 131, 220, 109, 21, 132, 220, 113, 21, 133, 220, 113, 21, 134, 224, 117, 21, 135, 224, 117, 25, 136, 224, 121, 25, 137, 224, 121, 25, 138, 224, 125, 25, 139, 224, 125, 25, 140, 224, 128, 25, 141, 228, 128, 25, 142, 228, 132, 25, 143, 228, 132, 29, 144, 228, 136, 29, 145, 228, 136, 29, 146, 228, 140, 29, 147, 228, 140, 29, 148, 228, 144, 33, 149, 232, 144, 33, 150, 232, 144, 33, 151, 232, 148, 33, 152, 232, 148, 33, 153, 232, 152, 37, 154, 232, 152, 37, 155, 232, 156, 37, 156, 232, 156, 37, 157, 236, 160, 41, 158, 236, 160, 41, 159, 236, 160, 41, 160, 236, 164, 41, 161, 236, 164, 45, 162, 236, 168, 45, 163, 236, 168, 45, 164, 236, 172, 49, 165, 236, 172, 49, 166, 236, 172, 49, 167, 240, 176, 53, 168, 240, 176, 53, 169, 240, 180, 53, 170, 240, 180, 57, 171, 240, 180, 57, 172, 240, 184, 61, 173, 240, 184, 61, 174, 240, 188, 61, 175, 240, 188, 65, 176, 240, 188, 65, 177, 240, 192, 69, 178, 244, 192, 69, 179, 244, 192, 73, 180, 244, 192, 73, 181, 244, 192, 77, 182, 244, 200, 77, 183, 244, 200, 81, 184, 244, 200, 81, 185, 244, 204, 85, 186, 244, 204, 85, 187, 244, 204, 89, 188, 244, 208, 89, 189, 244, 208, 93, 190, 244, 208, 93, 191, 248, 212, 97, 192, 248, 212, 97, 193, 248, 212, 101, 194, 248, 216, 105, 195, 248, 216, 105, 196, 248, 216, 109, 197, 248, 220, 109, 198, 248, 220, 113, 199, 248, 220, 113, 200, 248, 224, 117, 201, 248, 224, 121, 202, 248, 224, 121, 203, 248, 224, 125, 204, 248, 228, 125, 205, 248, 228, 128, 206, 248, 228, 128, 207, 248, 228, 132, 208, 248, 232, 136, 209, 248, 232, 136, 210, 252, 232, 140, 211, 252, 232, 144, 212, 252, 236, 144, 213, 252, 236, 148, 214, 252, 236, 148, 215, 252, 236, 152, 216, 252, 240, 156, 217, 252, 240, 156, 218, 252, 240, 160, 219, 252, 240, 160, 220, 252, 240, 164, 221, 252, 240, 168, 222, 252, 244, 168, 223, 252, 244, 172, 224, 252, 244, 172, 225, 252, 244, 176, 226, 252, 244, 180, 227, 252, 244, 180, 228, 252, 248, 184, 229, 252, 248, 188, 230, 252, 248, 188, 231, 252, 248, 192, 232, 252, 248, 192, 233, 252, 248, 196, 234, 252, 248, 200, 235, 252, 248, 200, 236, 252, 252, 204, 237, 252, 252, 208, 238, 252, 252, 208, 239, 252, 252, 212, 240, 252, 252, 212, 241, 252, 252, 216, 242, 252, 252, 220, 243, 252, 252, 220, 244, 252, 252, 224, 245, 252, 252, 228, 246, 252, 252, 228, 247, 252, 252, 232, 248, 252, 252, 236, 249, 252, 252, 236, 250, 252, 252, 240, 251, 252, 252, 244, 252, 252, 252, 244, 253, 252, 252, 248, 254, 255, 255, 255, 255 }; lut->SetNumberOfTableValues(256); for(int i=0; i<256; i++) { int k = i*4; lut->SetTableValue(i, v[k]/255.0, v[k+1]/255.0, v[k+2]/255.0, v[k+3]/255.0); } }; //--------------------------------------------------------------------- void lutTenStep( vtkLookupTable *lut) //--------------------------------------------------------------------- { //tensteps unsigned char v[10*3] = { 29, 0, 134, 0, 18, 163, 0, 74, 188, 0, 159, 195, 0, 201, 150, 0, 209, 12, 141, 217, 0, 220, 221, 0, 226, 138, 0, 231, 48, 0, }; lut->SetNumberOfTableValues(10); for(int i=0; i<10; i++) { int k = i*3; lut->SetTableValue(i, v[k]/255.0, v[k+1]/255.0, v[k+2]/255.0, 1); } }; //--------------------------------------------------------------------- void lutTemperature( vtkLookupTable *lut) //--------------------------------------------------------------------- { //temperature unsigned char v[256*3] = { 255,255,255, 251,251,253, 249,247,255, 246,244,253, 242,242,255, 239,239,253, 237,235,255, 233,232,255, 230,230,253, 228,226,255, 225,223,253, 221,221,255, 219,218,253, 216,214,255, 212,212,255, 209,209,255, 207,205,255, 205,202,253, 202,200,255, 198,196,253, 195,193,255, 193,191,253, 189,188,255, 186,184,255, 184,181,255, 181,179,255, 177,175,253, 175,172,255, 172,170,253, 168,167,255, 165,163,255, 163,161,255, 160,158,255, 156,154,253, 154,151,255, 151,149,253, 149,144,255, 145,142,253, 142,138,255, 140,135,255, 137,133,255, 133,130,255, 130,126,253, 128,124,255, 124,121,253, 121,117,255, 119,114,255, 116,112,255, 112,109,255, 110,105,253, 107,103,255, 105,100,253, 102,96,255, 98,93,253, 96,91,255, 93,87,255, 89,84,253, 86,82,255, 84,79,253, 80,75,255, 77,73,253, 75,70,255, 72,66,255, 68,63,255, 66,61,255, 66,59,253, 68,59,251, 70,59,249, 70,58,249, 72,58,247, 73,56,246, 73,56,244, 75,56,244, 77,54,242, 77,54,240, 79,54,239, 79,52,237, 80,52,237, 82,52,235, 84,52,233, 84,51,232, 86,49,232, 86,49,230, 87,49,228, 89,49,228, 91,47,226, 91,47,225, 93,47,223, 93,45,221, 96,45,221, 96,45,219, 98,43,218, 98,43,216, 100,42,214, 100,42,214, 103,42,212, 103,40,211, 105,40,209, 105,40,209, 107,38,207, 107,38,205, 110,38,205, 110,38,202, 112,36,202, 112,35,200, 114,35,198, 114,35,198, 117,33,196, 117,33,195, 119,33,193, 119,33,193, 121,31,191, 121,31,189, 124,31,188, 124,29,186, 126,29,186, 126,28,184, 128,28,182, 128,28,181, 130,26,181, 131,26,179, 133,26,177, 133,24,175, 135,24,175, 135,24,174, 137,24,172, 138,22,170, 140,22,170, 140,22,168, 142,21,167, 142,19,165, 144,19,163, 145,19,163, 147,19,161, 147,17,160, 149,17,158, 149,17,158, 151,15,156, 153,15,154, 154,15,154, 154,14,151, 156,14,151, 156,12,149, 158,12,147, 160,12,147, 161,10,145, 161,10,144, 163,10,142, 165,10,142, 167,8,137, 168,8,135, 172,8,131, 174,8,128, 175,8,126, 179,8,121, 181,8,119, 182,7,116, 186,7,112, 188,7,110, 191,7,107, 193,5,103, 195,5,100, 198,5,96, 200,5,93, 202,5,91, 205,5,86, 207,5,84, 209,5,80, 212,3,77, 214,3,75, 216,3,72, 219,3,68, 221,3,65, 223,3,61, 226,3,59, 228,1,56, 230,1,52, 232,1,49, 235,1,45, 237,1,42, 239,1,40, 242,1,36, 244,1,33, 246,0,29, 249,0,26, 249,0,26, 249,0,26, 249,0,26, 251,0,26, 251,0,24, 251,0,24, 251,0,24, 251,0,24, 251,0,24, 251,0,24, 251,0,22, 253,0,22, 253,0,22, 253,0,22, 253,0,22, 253,0,22, 253,0,21, 253,0,21, 253,0,21, 255,0,21, 255,3,21, 255,8,21, 255,12,21, 255,17,21, 255,22,21, 255,26,22, 255,31,22, 255,35,22, 255,40,22, 255,45,22, 255,49,22, 255,54,22, 255,59,22, 255,63,22, 255,68,22, 255,73,22, 255,77,24, 255,82,24, 255,86,24, 255,91,24, 255,96,24, 255,100,24, 255,105,24, 255,110,24, 255,114,24, 255,119,24, 255,123,24, 255,128,26, 255,133,26, 255,137,24, 255,142,24, 255,147,24, 255,154,22, 255,158,22, 255,163,22, 255,168,21, 255,175,21, 255,179,19, 255,184,19, 255,191,19, 255,195,17, 255,200,17, 255,205,17, 255,212,17, 255,216,15, 255,221,15, 255,226,15, 255,232,14, 255,237,14, 255,242,12, 255,249,12, }; lut->SetNumberOfTableValues(256); for(int i=0; i<256; i++) { int k = i*3; lut->SetTableValue(i, v[k]/255.0, v[k+1]/255.0, v[k+2]/255.0, 1); } }; //--------------------------------------------------------------------- void lutSar( vtkLookupTable *lut) //--------------------------------------------------------------------- { //sar unsigned char v[256*3] = { 255,255,255, 251,251,253, 246,246,253, 244,246,253, 242,242,253, 239,239,251, 235,237,251, 232,232,251, 230,232,251, 226,228,249, 223,226,249, 221,223,249, 218,219,249, 214,219,246, 212,214,246, 209,214,246, 207,212,246, 204,209,246, 200,207,246, 198,205,246, 195,204,244, 191,202,244, 188,198,244, 186,198,244, 182,195,242, 179,195,242, 177,193,242, 174,189,242, 172,188,239, 168,186,239, 167,186,239, 163,186,239, 161,184,239, 158,181,239, 156,179,239, 153,181,237, 149,177,237, 147,177,237, 144,175,237, 142,174,235, 137,175,235, 137,174,235, 133,174,235, 130,172,232, 128,170,232, 126,170,232, 123,168,232, 121,170,232, 117,168,232, 116,167,232, 112,168,230, 110,167,230, 107,167,230, 105,167,230, 103,167,228, 100,165,228, 98,165,228, 93,163,228, 89,163,226, 87,163,226, 86,165,226, 84,165,226, 80,163,225, 79,165,225, 77,165,225, 75,163,223, 73,165,223, 68,163,223, 66,163,223, 65,167,221, 61,167,221, 59,165,221, 56,168,221, 54,168,219, 51,168,219, 51,168,219, 47,170,219, 45,168,218, 42,168,218, 40,172,216, 36,172,216, 35,172,216, 33,172,216, 33,174,216, 28,175,214, 28,174,214, 24,175,214, 24,175,214, 21,179,212, 17,179,212, 17,179,212, 14,181,212, 10,184,211, 10,182,211, 7,186,209, 5,186,209, 1,186,209, 1,188,209, 0,191,209, 0,193,209, 0,195,209, 0,200,209, 0,200,209, 0,204,209, 0,207,209, 0,211,209, 0,211,207, 0,211,205, 0,212,202, 0,212,198, 0,212,198, 0,212,193, 0,212,193, 0,212,189, 0,212,186, 0,214,184, 0,214,184, 0,214,181, 0,214,179, 0,214,177, 0,214,174, 0,214,172, 0,216,167, 0,216,165, 0,216,163, 0,216,161, 0,216,158, 0,216,156, 0,216,154, 0,218,151, 0,218,147, 0,218,145, 0,219,142, 0,219,140, 0,219,137, 0,219,137, 0,219,133, 0,219,130, 0,219,128, 0,221,124, 0,221,123, 0,221,121, 0,221,117, 0,221,114, 0,221,110, 0,221,110, 0,223,107, 0,223,103, 0,223,102, 0,223,100, 0,223,98, 0,223,93, 0,223,91, 0,225,87, 0,225,84, 0,225,84, 0,226,80, 0,226,77, 0,226,73, 0,226,72, 0,226,70, 0,226,68, 0,226,63, 0,228,59, 0,228,58, 0,228,56, 0,228,54, 0,228,51, 0,228,47, 0,228,43, 0,230,40, 0,230,38, 0,230,35, 0,230,35, 0,230,29, 0,230,28, 0,230,26, 0,232,22, 0,232,17, 0,232,15, 0,232,14, 0,232,12, 0,232,7, 0,232,3, 0,232,3, 0,232,0, 0,232,0, 5,235,0, 8,235,0, 8,235,0, 14,235,0, 14,235,0, 19,235,0, 24,235,0, 31,237,0, 38,237,0, 45,237,0, 51,237,0, 58,237,0, 66,237,0, 72,237,0, 79,239,0, 86,239,0, 93,239,0, 98,239,0, 107,239,0, 114,239,0, 121,239,0, 128,239,0, 133,239,0, 140,239,0, 149,242,0, 154,242,0, 161,242,0, 170,242,0, 177,242,0, 184,242,0, 191,242,0, 198,244,0, 205,244,0, 212,244,0, 219,244,0, 228,244,0, 233,244,0, 239,244,0, 246,242,0, 246,235,0, 246,226,0, 246,221,0, 246,214,0, 246,205,0, 246,198,0, 246,193,0, 246,186,0, 246,179,0, 249,174,0, 249,168,0, 249,160,0, 249,153,0, 249,144,0, 249,137,0, 249,131,0, 251,124,0, 251,119,0, 251,112,0, 251,103,0, 251,96,0, 251,89,0, 251,82,0, 253,77,0, 253,70,0, 253,61,0, 253,56,0, 253,47,0, 253,40,0, 255,33,0 }; lut->SetNumberOfTableValues(256); for(int i=0; i<256; i++) { int k = i*3; lut->SetTableValue(i, v[k]/255.0, v[k+1]/255.0, v[k+2]/255.0, 1); } }; //--------------------------------------------------------------------- void lutPhysicsContour( vtkLookupTable *lut) //--------------------------------------------------------------------- { //physicsContour unsigned char v[256*3] = { 101, 4, 255, 97, 4, 253, 92, 4, 250, 89, 4, 248, 83, 4, 245, 80, 4, 243, 76, 4, 241, 73, 4, 238, 68, 4, 236, 65, 2, 233, 62, 2, 231, 57, 2, 229, 54, 2, 226, 50, 2, 224, 48, 2, 221, 43, 2, 219, 41, 2, 217, 37, 2, 214, 35, 2, 212, 31, 1, 209, 28, 1, 207, 26, 1, 204, 22, 1, 202, 19, 1, 200, 16, 1, 197, 13, 1, 195, 12, 0, 192, 9, 0, 190, 6, 0, 188, 4, 0, 185, 1, 0, 183, 0, 1, 180, 0, 3, 178, 0, 6, 176, 0, 8, 173, 0, 10, 171, 0, 12, 168, 0, 13, 166, 0, 15, 164, 0, 18, 161, 1, 19, 159, 2, 22, 156, 3, 24, 154, 3, 25, 152, 4, 28, 149, 4, 29, 147, 5, 31, 144, 6, 33, 142, 7, 33, 140, 6, 35, 137, 7, 37, 135, 8, 37, 132, 8, 39, 130, 9, 40, 128, 19, 84, 255, 20, 85, 253, 21, 88, 250, 22, 91, 248, 22, 94, 245, 23, 95, 243, 24, 97, 241, 25, 100, 238, 25, 102, 236, 26, 103, 233, 27, 105, 231, 28, 107, 229, 29, 109, 226, 29, 111, 224, 30, 111, 221, 30, 113, 219, 29, 116, 217, 29, 118, 214, 29, 119, 212, 28, 121, 209, 28, 123, 207, 28, 124, 204, 27, 125, 202, 27, 126, 200, 27, 128, 197, 26, 129, 195, 26, 131, 192, 26, 132, 190, 25, 133, 188, 25, 134, 185, 25, 135, 183, 24, 136, 180, 24, 137, 178, 23, 137, 176, 23, 138, 173, 22, 138, 171, 22, 139, 168, 21, 140, 166, 21, 139, 164, 21, 140, 161, 20, 140, 159, 20, 140, 156, 20, 141, 154, 19, 140, 152, 19, 140, 149, 19, 140, 147, 18, 140, 144, 18, 140, 142, 18, 140, 140, 17, 137, 135, 17, 135, 131, 17, 132, 127, 16, 130, 123, 16, 128, 118, 32, 255, 232, 32, 253, 226, 31, 250, 221, 31, 248, 215, 31, 245, 209, 29, 243, 203, 29, 241, 198, 29, 238, 193, 28, 236, 187, 28, 233, 181, 28, 231, 176, 27, 229, 171, 27, 226, 167, 27, 224, 158, 26, 221, 151, 26, 219, 144, 26, 217, 138, 25, 214, 131, 25, 212, 124, 25, 209, 117, 24, 207, 111, 24, 204, 104, 23, 202, 98, 22, 200, 92, 22, 197, 86, 22, 195, 79, 21, 192, 74, 21, 190, 68, 21, 188, 63, 21, 185, 57, 20, 183, 52, 20, 180, 47, 20, 178, 42, 19, 176, 37, 19, 173, 32, 18, 171, 27, 18, 168, 23, 17, 166, 18, 21, 164, 17, 25, 161, 17, 28, 159, 17, 31, 156, 16, 35, 154, 16, 38, 152, 16, 41, 149, 15, 44, 147, 15, 47, 144, 15, 49, 142, 14, 52, 140, 14, 54, 137, 13, 57, 135, 13, 59, 132, 13, 61, 130, 13, 63, 128, 12, 133, 255, 25, 138, 253, 25, 142, 250, 24, 148, 248, 24, 152, 245, 24, 157, 243, 22, 161, 241, 22, 162, 238, 22, 164, 236, 22, 164, 233, 21, 165, 231, 21, 167, 229, 21, 167, 226, 21, 168, 224, 21, 169, 221, 20, 169, 219, 20, 170, 217, 20, 170, 214, 20, 171, 212, 19, 172, 209, 19, 172, 207, 19, 173, 204, 19, 173, 202, 18, 172, 200, 18, 173, 197, 18, 174, 195, 18, 173, 192, 17, 174, 190, 16, 173, 188, 16, 173, 185, 16, 174, 183, 16, 174, 180, 16, 174, 178, 15, 175, 176, 15, 173, 172, 15, 171, 167, 15, 168, 162, 14, 166, 159, 14, 164, 154, 14, 161, 149, 14, 159, 145, 14, 156, 140, 13, 154, 136, 13, 152, 132, 13, 149, 128, 13, 147, 123, 12, 144, 119, 12, 142, 115, 11, 140, 111, 11, 137, 107, 11, 135, 103, 11, 132, 99, 11, 130, 96, 10, 128, 92, 10, 255, 181, 20, 255, 178, 20, 255, 174, 20, 255, 170, 20, 255, 167, 20, 255, 164, 20, 255, 159, 20, 255, 155, 20, 255, 152, 20, 255, 148, 20, 255, 145, 19, 255, 142, 19, 255, 136, 19, 255, 133, 19, 255, 130, 19, 255, 126, 19, 255, 123, 19, 255, 119, 19, 255, 115, 19, 255, 111, 19, 255, 108, 19, 255, 105, 19, 255, 100, 19, 255, 96, 19, 255, 93, 19, 255, 89, 19, 255, 85, 19, 255, 82, 19, 255, 79, 18, 255, 74, 18, 255, 71, 18, 255, 67, 18, 255, 63, 18, 255, 60, 18, 255, 56, 18, 255, 52, 18, 255, 48, 18, 255, 45, 18, 255, 41, 18, 255, 37, 18, }; lut->SetNumberOfTableValues(256); for(int i=0; i<256; i++) { int k = i*3; lut->SetTableValue(i, v[k]/255.0, v[k+1]/255.0, v[k+2]/255.0, 1); } }; //--------------------------------------------------------------------- void lutGlow( vtkLookupTable *lut) //--------------------------------------------------------------------- { //glow unsigned char v[256*3] = { 0, 0, 0, 0, 0, 0, 5, 0, 0, 5, 0, 0, 9, 0, 0, 9, 0, 0, 13, 0, 0, 13, 0, 5, 17, 0, 5, 17, 0, 5, 21, 0, 5, 21, 0, 5, 25, 0, 5, 25, 0, 5, 29, 0, 5, 29, 0, 9, 33, 0, 9, 33, 0, 9, 37, 0, 9, 37, 0, 9, 41, 0, 9, 41, 0, 9, 45, 0, 9, 45, 0, 9, 49, 0, 13, 49, 0, 13, 53, 0, 13, 53, 0, 13, 57, 0, 13, 57, 0, 13, 61, 0, 13, 61, 5, 13, 65, 5, 13, 65, 5, 13, 69, 5, 13, 69, 5, 13, 73, 5, 17, 73, 5, 17, 77, 5, 17, 81, 5, 17, 81, 5, 17, 85, 5, 17, 85, 5, 17, 89, 5, 17, 89, 9, 17, 93, 9, 17, 93, 9, 17, 97, 9, 17, 97, 9, 17, 101, 9, 17, 101, 9, 17, 105, 9, 17, 105, 9, 17, 109, 13, 17, 109, 13, 17, 113, 13, 17, 113, 13, 17, 117, 13, 17, 117, 13, 17, 121, 13, 17, 125, 13, 17, 125, 13, 17, 128, 17, 17, 128, 17, 17, 132, 17, 21, 132, 17, 21, 136, 17, 21, 136, 17, 21, 140, 17, 21, 140, 21, 21, 144, 21, 21, 144, 21, 21, 148, 21, 21, 148, 21, 21, 152, 25, 21, 152, 25, 21, 156, 25, 21, 156, 25, 21, 156, 25, 21, 160, 29, 21, 160, 29, 21, 164, 29, 21, 164, 29, 21, 168, 33, 21, 168, 33, 21, 168, 33, 21, 172, 33, 21, 172, 37, 21, 176, 37, 21, 176, 37, 21, 176, 37, 21, 180, 41, 21, 180, 41, 21, 180, 41, 21, 184, 45, 21, 184, 45, 21, 188, 45, 21, 188, 49, 21, 188, 49, 21, 192, 49, 21, 192, 53, 21, 192, 53, 21, 192, 53, 21, 196, 57, 21, 196, 57, 21, 196, 61, 21, 200, 61, 21, 200, 61, 21, 200, 65, 21, 200, 65, 21, 204, 69, 21, 204, 69, 21, 204, 69, 21, 208, 73, 21, 208, 73, 21, 208, 77, 21, 208, 77, 21, 208, 81, 21, 212, 81, 21, 212, 85, 21, 212, 85, 21, 212, 89, 21, 212, 89, 21, 216, 93, 21, 216, 93, 21, 216, 97, 21, 216, 97, 21, 216, 101, 21, 220, 101, 21, 220, 105, 21, 220, 105, 21, 220, 109, 21, 220, 109, 21, 220, 113, 21, 220, 113, 21, 224, 117, 21, 224, 117, 25, 224, 121, 25, 224, 121, 25, 224, 125, 25, 224, 125, 25, 224, 128, 25, 228, 128, 25, 228, 132, 25, 228, 132, 29, 228, 136, 29, 228, 136, 29, 228, 140, 29, 228, 140, 29, 228, 144, 33, 232, 144, 33, 232, 144, 33, 232, 148, 33, 232, 148, 33, 232, 152, 37, 232, 152, 37, 232, 156, 37, 232, 156, 37, 236, 160, 41, 236, 160, 41, 236, 160, 41, 236, 164, 41, 236, 164, 45, 236, 168, 45, 236, 168, 45, 236, 172, 49, 236, 172, 49, 236, 172, 49, 240, 176, 53, 240, 176, 53, 240, 180, 53, 240, 180, 57, 240, 180, 57, 240, 184, 61, 240, 184, 61, 240, 188, 61, 240, 188, 65, 240, 188, 65, 240, 192, 69, 244, 192, 69, 244, 192, 73, 244, 192, 73, 244, 192, 77, 244, 200, 77, 244, 200, 81, 244, 200, 81, 244, 204, 85, 244, 204, 85, 244, 204, 89, 244, 208, 89, 244, 208, 93, 244, 208, 93, 248, 212, 97, 248, 212, 97, 248, 212, 101, 248, 216, 105, 248, 216, 105, 248, 216, 109, 248, 220, 109, 248, 220, 113, 248, 220, 113, 248, 224, 117, 248, 224, 121, 248, 224, 121, 248, 224, 125, 248, 228, 125, 248, 228, 129, 248, 228, 129, 248, 228, 133, 248, 232, 137, 248, 232, 137, 252, 232, 141, 252, 232, 145, 252, 236, 145, 252, 236, 148, 252, 236, 148, 252, 236, 152, 252, 240, 156, 252, 240, 156, 252, 240, 160, 252, 240, 160, 252, 240, 164, 252, 240, 168, 252, 244, 168, 252, 244, 172, 252, 244, 172, 252, 244, 176, 252, 244, 180, 252, 244, 180, 252, 248, 184, 252, 248, 188, 252, 248, 188, 252, 248, 192, 252, 248, 192, 252, 248, 196, 252, 248, 200, 252, 248, 200, 252, 252, 204, 252, 252, 208, 252, 252, 208, 252, 252, 212, 252, 252, 212, 252, 252, 216, 252, 252, 220, 252, 252, 220, 252, 252, 224, 252, 252, 228, 252, 252, 228, 252, 252, 232, 252, 252, 236, 252, 252, 236, 252, 252, 240, 252, 252, 244, 252, 252, 244, 252, 252, 248, 252, 252, 255, }; lut->SetNumberOfTableValues(256); for(int i=0; i<256; i++) { int k = i*3; lut->SetTableValue(i, v[k]/255.0, v[k+1]/255.0, v[k+2]/255.0, 1); } }; //--------------------------------------------------------------------- void lutEField( vtkLookupTable *lut) //--------------------------------------------------------------------- { //efield unsigned char v[256*3] = { 237,253,135, 233,251,137, 232,251,137, 230,249,140, 226,249,140, 225,247,142, 223,246,144, 221,246,145, 218,244,147, 216,244,149, 214,242,149, 211,242,151, 209,240,153, 207,239,154, 205,239,156, 202,239,158, 200,237,158, 198,237,161, 195,235,161, 193,235,163, 191,233,165, 188,232,167, 186,232,168, 184,230,170, 181,230,170, 179,228,172, 177,228,174, 175,226,175, 172,226,177, 170,226,179, 168,225,179, 165,223,181, 163,223,182, 161,221,184, 158,221,186, 156,219,188, 154,219,188, 151,218,191, 149,216,191, 147,216,193, 144,214,195, 142,214,195, 140,214,198, 137,212,198, 135,212,200, 133,211,202, 130,209,204, 128,209,205, 126,207,207, 124,207,207, 121,205,209, 119,205,211, 117,204,212, 114,202,214, 112,202,216, 110,202,216, 107,200,219, 105,200,219, 103,198,221, 100,198,223, 98,196,225, 96,195,226, 93,195,228, 91,193,228, 89,193,230, 86,191,232, 84,191,233, 82,189,235, 80,189,237, 77,188,237, 75,188,239, 73,186,240, 70,186,242, 68,184,244, 66,184,246, 65,182,246, 61,181,249, 59,181,249, 58,179,251, 54,179,253, 52,177,255, 54,175,255, 54,174,255, 54,172,255, 56,170,255, 56,168,255, 58,167,255, 58,165,255, 59,163,255, 59,161,255, 61,158,255, 61,156,255, 61,154,255, 63,154,255, 63,151,255, 63,149,255, 65,147,255, 66,145,255, 66,144,255, 66,142,255, 68,140,255, 68,140,255, 70,137,255, 70,135,255, 70,135,255, 72,133,255, 73,131,255, 73,130,255, 73,128,255, 75,126,255, 75,124,255, 75,124,255, 77,121,255, 77,121,255, 79,119,255, 79,117,255, 79,117,255, 80,114,255, 82,114,255, 82,112,255, 82,110,255, 84,110,255, 84,107,255, 84,107,255, 86,105,255, 86,105,255, 87,103,255, 87,102,255, 89,100,255, 89,100,255, 91,98,255, 91,96,255, 89,94,255, 89,91,255, 87,89,255, 89,86,255, 89,86,255, 89,84,255, 91,84,255, 91,82,255, 93,82,255, 93,80,255, 94,79,255, 96,79,255, 98,77,255, 98,77,255, 100,75,255, 100,75,255, 102,73,255, 103,73,255, 105,72,255, 105,70,255, 107,70,255, 107,68,255, 110,68,255, 110,66,255, 112,65,255, 114,63,255, 114,63,255, 117,61,255, 117,61,255, 119,59,255, 121,59,255, 123,58,255, 124,56,255, 126,56,255, 128,54,255, 128,54,255, 130,52,255, 131,52,253, 133,52,253, 135,51,253, 137,49,253, 137,49,253, 138,49,253, 140,47,253, 142,47,253, 144,47,251, 144,45,251, 147,45,251, 147,45,251, 149,45,251, 151,43,251, 153,42,251, 154,42,251, 156,42,251, 156,40,249, 158,40,249, 160,40,249, 161,38,249, 163,38,249, 165,38,249, 167,36,249, 168,36,249, 170,35,247, 170,35,247, 172,35,247, 175,33,247, 175,33,246, 177,33,246, 179,31,246, 181,31,246, 182,31,246, 184,29,246, 186,29,246, 188,28,246, 189,28,246, 191,28,244, 193,26,244, 195,26,244, 195,26,244, 198,26,244, 200,24,244, 202,24,244, 202,24,244, 205,22,242, 207,22,242, 209,22,242, 209,21,242, 212,21,242, 214,19,242, 216,19,242, 218,19,242, 219,17,242, 221,17,240, 223,17,240, 225,15,240, 226,15,240, 228,15,239, 230,15,239, 232,14,239, 233,12,239, 235,12,239, 237,12,239, 239,12,237, 239,10,235, 239,10,232, 237,10,230, 237,8,228, 237,8,226, 237,8,223, 237,8,221, 237,7,219, 237,5,216, 237,5,214, 235,5,212, 235,5,209, 235,3,207, 235,3,204, 235,3,202, 235,1,200, 235,1,196, 235,1,195, 235,1,191, 233,0,189, 233,0,186, }; lut->SetNumberOfTableValues(256); for(int i=0; i<256; i++) { int k = i*3; lut->SetTableValue(i, v[k]/255.0, v[k+1]/255.0, v[k+2]/255.0, 1); } }; //--------------------------------------------------------------------- void lutDefault( vtkLookupTable *lut) //--------------------------------------------------------------------- { Color *c = new Color(); lut->SetNumberOfTableValues(256); for(int i=0; i<256; i++) { int h = (i*240.0)/255.0; c->setHSV(h,255,255); lut->SetTableValue(i, c->m_red/255.0, c->m_green/255.0, c->m_blue/255.0, 1); } }; //--------------------------------------------------------------------- void lutMinMax( vtkLookupTable *lut) //--------------------------------------------------------------------- { Color *c = new Color(); int i; lut->SetNumberOfTableValues(256); for(i=0; i<128; i++) { int h = (i*240.0)/255.0; c->setHSV(h,255,255); lut->SetTableValue(i, c->m_red/255.0, c->m_green/255.0, c->m_blue/255.0, (128-i)/128.0); } for(i=128; i<256; i++) { int h = (i*240.0)/255.0; c->setHSV(h,255,255); lut->SetTableValue(i, c->m_red/255.0, c->m_green/255.0, c->m_blue/255.0, (i-128)/128.0); } }; //--------------------------------------------------------------------- void lutDefaultStep( vtkLookupTable *lut) //--------------------------------------------------------------------- { lutDefault( lut); Color *c = new Color(128,128,128); for(int i=0; i<256; i+=16) lut->SetTableValue(i, c->m_red/255.0, c->m_green/255.0, c->m_blue/255.0, 1); }; //--------------------------------------------------------------------- void lutGray( vtkLookupTable *lut) //--------------------------------------------------------------------- { lut->SetNumberOfTableValues(128); for(int i=0; i<128; i++) lut->SetTableValue(i, i/128.0, i/128.0, i/128.0, 1); }; //--------------------------------------------------------------------- void lutPureRed( vtkLookupTable *lut) //--------------------------------------------------------------------- { lut->SetNumberOfTableValues(128); for(int i=0; i<128; i++) { lut->SetTableValue(i, i/128.0, 0, 0, 1); } }; //--------------------------------------------------------------------- void lutPureGreen( vtkLookupTable *lut) //--------------------------------------------------------------------- { lut->SetNumberOfTableValues(128); for(int i=0; i<128; i++) lut->SetTableValue(i, 0, i/128.0, 0, 1); }; //--------------------------------------------------------------------- void lutPureBlue( vtkLookupTable *lut) //--------------------------------------------------------------------- { lut->SetNumberOfTableValues(128); for(int i=0; i<128; i++) lut->SetTableValue(i, 0, 0, i/128.0, 1); }; //--------------------------------------------------------------------- void lutAllYellow( vtkLookupTable *lut) //--------------------------------------------------------------------- { lut->SetNumberOfTableValues(1); for(int i=0; i<1; i++) lut->SetTableValue(i, 1, 1, 0, 1); }; //--------------------------------------------------------------------- void lutAllCyane( vtkLookupTable *lut) //--------------------------------------------------------------------- { lut->SetNumberOfTableValues(1); for(int i=0; i<1; i++) lut->SetTableValue(i, 0, 1, 1, 1); }; //--------------------------------------------------------------------- void lutAllViolet( vtkLookupTable *lut) //--------------------------------------------------------------------- { lut->SetNumberOfTableValues(1); for(int i=0; i<1; i++) lut->SetTableValue(i, 1, 0, 1, 1); }; //--------------------------------------------------------------------- void lutAllWhite( vtkLookupTable *lut) //--------------------------------------------------------------------- { lut->SetNumberOfTableValues(1); for(int i=0; i<1; i++) lut->SetTableValue(i, 1, 1, 1, 1); }; //--------------------------------------------------------------------- void lutAllBlack( vtkLookupTable *lut) //--------------------------------------------------------------------- { lut->SetNumberOfTableValues(1); for(int i=0; i<1; i++) lut->SetTableValue(i, 0, 0, 0, 1); }; //--------------------------------------------------------------------- void lutAllRed( vtkLookupTable *lut) //--------------------------------------------------------------------- { lut->SetNumberOfTableValues(1); for(int i=0; i<1; i++) lut->SetTableValue(i, 1, 0, 0, 1); }; //--------------------------------------------------------------------- void lutAllGreen( vtkLookupTable *lut) //--------------------------------------------------------------------- { lut->SetNumberOfTableValues(1); for(int i=0; i<1; i++) lut->SetTableValue(i, 0, 1, 0, 1); }; //--------------------------------------------------------------------- void lutAllBlu( vtkLookupTable *lut) //--------------------------------------------------------------------- { lut->SetNumberOfTableValues(1); for(int i=0; i<1; i++) lut->SetTableValue(i, 0, 0, 1, 1); }; //--------------------------------------------------------------------- void lutRun1( vtkLookupTable *lut) //--------------------------------------------------------------------- { //Run1 unsigned char v[256*4] = { 0,255,0,0, 64,198,255,0, 128,3,255,233, 192,78,47,255, 1,255,4,0, 65,193,255,0, 129,4,255,238, 193,80,45,255, 2,255,9,0, 66,189,255,0, 130,5,255,243, 194,82,43,255, 3,255,14,0, 67,182,255,0, 131,6,255,248, 195,85,41,255, 4,255,19,0, 68,175,255,0, 132,7,255,253, 196,87,39,255, 5,255,24,0, 69,168,255,0, 133,8,252,255, 197,90,37,255, 6,255,29,0, 70,161,255,0, 134,9,247,255, 198,93,35,255, 7,255,34,0, 71,154,255,0, 135,10,242,255, 199,96,33,255, 8,255,38,0, 72,147,255,0, 136,10,238,255, 200,98,31,255, 9,255,43,0, 73,140,255,0, 137,11,233,255, 201,101,29,255, 10,255,48,0, 74,133,255,0, 138,12,228,255, 202,104,27,255, 11,255,53,0, 75,126,255,0, 139,13,224,255, 203,108,25,255, 12,255,58,0, 76,119,255,0, 140,14,219,255, 204,111,23,255, 13,255,63,0, 77,112,255,0, 141,15,215,255, 205,114,21,255, 14,255,68,0, 78,105,255,0, 142,16,210,255, 206,117,19,255, 15,255,72,0, 79,98,255,0, 143,17,206,255, 207,121,17,255, 16,255,77,0, 80,91,255,0, 144,18,202,255, 208,124,15,255, 17,255,82,0, 81,84,255,0, 145,19,197,255, 209,128,13,255, 18,255,87,0, 82,77,255,0, 146,20,193,255, 210,131,11,255, 19,255,92,0, 83,70,255,0, 147,20,189,255, 211,135,9,255, 20,255,97,0, 84,64,255,0, 148,21,185,255, 212,139,7,255, 21,255,102,0, 85,57,255,0, 149,22,180,255, 213,143,5,255, 22,255,106,0, 86,50,255,0, 150,23,176,255, 214,147,3,255, 23,255,111,0, 87,43,255,0, 151,24,172,255, 215,151,1,255, 24,255,116,0, 88,36,255,0, 152,25,168,255, 216,155,0,255, 25,255,121,0, 89,29,255,0, 153,26,164,255, 217,159,0,255, 26,255,126,0, 90,22,255,0, 154,27,160,255, 218,163,0,255, 27,255,131,0, 91,15,255,0, 155,28,156,255, 219,167,0,255, 28,255,136,0, 92,8,255,0, 156,29,152,255, 220,172,0,255, 29,255,141,0, 93,1,255,0, 157,30,148,255, 221,176,0,255, 30,255,145,0, 94,0,255,5, 158,30,144,255, 222,180,0,255, 31,255,150,0, 95,0,255,12, 159,31,140,255, 223,184,0,255, 32,255,155,0, 96,0,255,19, 160,32,136,255, 224,188,0,255, 33,255,160,0, 97,0,255,26, 161,33,133,255, 225,192,0,255, 34,255,165,0, 98,0,255,33, 162,34,129,255, 226,197,0,255, 35,255,170,0, 99,0,255,40, 163,35,125,255, 227,201,0,255, 36,255,175,0, 100,0,255,47, 164,36,122,255, 228,205,0,255, 37,255,179,0, 101,0,255,54, 165,37,118,255, 229,209,0,255, 38,255,184,0, 102,0,255,60, 166,38,114,255, 230,213,0,255, 39,255,189,0, 103,0,255,67, 167,39,111,255, 231,217,0,255, 40,255,194,0, 104,0,255,74, 168,40,107,255, 232,222,0,255, 41,255,199,0, 105,0,255,81, 169,40,104,255, 233,226,0,255, 42,255,204,0, 106,0,255,88, 170,41,100,255, 234,230,0,255, 43,255,209,0, 107,0,255,95, 171,42,97,255, 235,234,0,255, 44,255,213,0, 108,0,255,102, 172,43,93,255, 236,238,0,255, 45,255,218,0, 109,0,255,109, 173,44,90,255, 237,242,0,255, 46,255,223,0, 110,0,255,116, 174,45,87,255, 238,247,0,255, 47,255,228,0, 111,0,255,123, 175,46,84,255, 239,251,0,255, 48,255,233,0, 112,0,255,130, 176,47,80,255, 240,255,0,254, 49,255,238,0, 113,0,255,137, 177,48,77,255, 241,255,0,250, 50,255,243,0, 114,0,255,144, 178,49,74,255, 242,255,0,246, 51,255,248,0, 115,0,255,151, 179,50,71,255, 243,255,0,242, 52,255,252,0, 116,0,255,158, 180,50,68,255, 244,255,0,237, 53,252,255,0, 117,0,255,165, 181,53,66,255, 245,255,0,233, 54,247,255,0, 118,0,255,172, 182,55,64,255, 246,255,0,229, 55,242,255,0, 119,0,255,178, 183,57,62,255, 247,255,0,225, 56,237,255,0, 120,0,255,185, 184,59,60,255, 248,255,0,221, 57,232,255,0, 121,0,255,192, 185,63,61,255, 249,255,0,217, 58,227,255,0, 122,0,255,199, 186,65,59,255, 250,255,0,212, 59,223,255,0, 123,0,255,206, 187,67,57,255, 251,255,0,208, 60,218,255,0, 124,0,255,213, 188,69,55,255, 252,255,0,204, 61,213,255,0, 125,0,255,218, 189,71,53,255, 253,255,0,200, 62,208,255,0, 126,1,255,223, 190,73,51,255, 254,255,0,196, 63,203,255,0, 127,2,255,228, 191,75,49,255, 255,255,0,191 }; lut->SetNumberOfTableValues(256); for(int i=0; i<256; i++) { int k = i*4; lut->SetTableValue(i, v[k]/255.0, v[k+1]/255.0, v[k+2]/255.0, v[k+3]/255.0); } }; //--------------------------------------------------------------------- void lutRun2( vtkLookupTable *lut) //--------------------------------------------------------------------- { //Run2 unsigned char v[256*4] = { 0,255,89,89, 64,255,151,151, 128,255,255,255, 192,130,142,255, 1,255,90,90, 65,255,153,153, 129,253,253,255, 193,128,141,255, 2,255,91,91, 66,255,154,154, 130,251,251,255, 194,127,140,255, 3,255,92,92, 67,255,156,156, 131,249,249,255, 195,126,139,255, 4,255,93,93, 68,255,157,157, 132,247,247,255, 196,125,138,255, 5,255,94,94, 69,255,159,159, 133,245,246,255, 197,124,137,255, 6,255,95,95, 70,255,161,161, 134,243,244,255, 198,123,136,255, 7,255,96,96, 71,255,162,162, 135,241,242,255, 199,121,135,255, 8,255,97,97, 72,255,164,164, 136,239,240,255, 200,120,134,255, 9,255,97,97, 73,255,165,165, 137,237,239,255, 201,119,133,255, 10,255,98,98, 74,255,167,167, 138,235,237,255, 202,118,132,255, 11,255,99,99, 75,255,169,169, 139,233,235,255, 203,117,130,255, 12,255,100,100, 76,255,170,170, 140,231,233,255, 204,116,129,255, 13,255,101,101, 77,255,172,172, 141,229,232,255, 205,114,128,255, 14,255,102,102, 78,255,174,174, 142,227,230,255, 206,113,127,255, 15,255,103,103, 79,255,175,175, 143,225,228,255, 207,112,126,255, 16,255,104,104, 80,255,177,177, 144,223,226,255, 208,111,125,255, 17,255,105,105, 81,255,178,178, 145,221,224,255, 209,110,124,255, 18,255,106,106, 82,255,180,180, 146,219,223,255, 210,108,123,255, 19,255,107,107, 83,255,182,182, 147,217,221,255, 211,107,122,255, 20,255,108,108, 84,255,183,183, 148,215,219,255, 212,106,121,255, 21,255,109,109, 85,255,185,185, 149,213,217,255, 213,105,120,255, 22,255,110,110, 86,255,187,187, 150,211,216,255, 214,104,119,255, 23,255,111,111, 87,255,188,188, 151,209,214,255, 215,103,118,255, 24,255,112,112, 88,255,190,190, 152,207,212,255, 216,101,117,255, 25,255,113,113, 89,255,191,191, 153,205,210,255, 217,100,116,255, 26,255,114,114, 90,255,193,193, 154,203,209,255, 218,99,115,255, 27,255,115,115, 91,255,195,195, 155,201,207,255, 219,98,114,255, 28,255,116,116, 92,255,196,196, 156,200,205,255, 220,97,112,255, 29,255,117,117, 93,255,198,198, 157,198,203,255, 221,96,111,255, 30,255,118,118, 94,255,199,199, 158,196,201,255, 222,94,110,255, 31,255,119,119, 95,255,201,201, 159,194,200,255, 223,93,109,255, 32,255,120,120, 96,255,203,203, 160,192,198,255, 224,92,108,255, 33,255,121,121, 97,255,204,204, 161,190,196,255, 225,91,107,255, 34,255,122,122, 98,255,206,206, 162,188,194,255, 226,90,106,255, 35,255,123,123, 99,255,208,208, 163,186,193,255, 227,88,105,255, 36,255,124,124, 100,255,209,209, 164,184,191,255, 228,87,104,255, 37,255,125,125, 101,255,211,211, 165,182,189,255, 229,86,103,255, 38,255,126,126, 102,255,212,212, 166,180,187,255, 230,85,102,255, 39,255,127,127, 103,255,214,214, 167,178,186,255, 231,84,101,255, 40,255,128,128, 104,255,216,216, 168,176,184,255, 232,83,100,255, 41,255,129,129, 105,255,217,217, 169,174,182,255, 233,81,99,255, 42,255,130,130, 106,255,219,219, 170,172,180,255, 234,80,98,255, 43,255,131,131, 107,255,221,221, 171,170,178,255, 235,79,97,255, 44,255,131,131, 108,255,222,222, 172,168,177,255, 236,78,96,255, 45,255,132,132, 109,255,224,224, 173,166,175,255, 237,77,95,255, 46,255,133,133, 110,255,225,225, 174,164,173,255, 238,76,93,255, 47,255,134,134, 111,255,227,227, 175,162,171,255, 239,74,92,255, 48,255,135,135, 112,255,229,229, 176,160,170,255, 240,73,91,255, 49,255,136,136, 113,255,230,230, 177,158,168,255, 241,72,90,255, 50,255,137,137, 114,255,232,232, 178,156,166,255, 242,71,89,255, 51,255,138,138, 115,255,233,233, 179,154,164,255, 243,70,88,255, 52,255,139,139, 116,255,235,235, 180,152,163,255, 244,69,87,255, 53,255,140,140, 117,255,237,237, 181,150,161,255, 245,67,86,255, 54,255,141,141, 118,255,238,238, 182,148,159,255, 246,66,85,255, 55,255,142,142, 119,255,240,240, 183,146,157,255, 247,65,84,255, 56,255,143,143, 120,255,242,242, 184,145,156,255, 248,64,83,255, 57,255,144,144, 121,255,243,243, 185,143,154,255, 249,63,82,255, 58,255,145,145, 122,255,245,245, 186,141,152,255, 250,61,81,255, 59,255,146,146, 123,255,246,246, 187,139,150,255, 251,60,80,255, 60,255,147,147, 124,255,248,248, 188,137,148,255, 252,59,79,255, 61,255,148,148, 125,255,250,250, 189,135,147,255, 253,58,78,255, 62,255,149,149, 126,255,251,251, 190,133,145,255, 254,57,77,255, 63,255,150,150, 127,255,253,253, 191,131,143,255, 255,56,75,255 }; lut->SetNumberOfTableValues(256); for(int i=0; i<256; i++) { int k = i*4; lut->SetTableValue(i, v[k]/255.0, v[k+1]/255.0, v[k+2]/255.0, v[k+3]/255.0); } }; //--------------------------------------------------------------------- void lutVolRenRGB( vtkLookupTable *lut) //--------------------------------------------------------------------- { //Run2 unsigned char v[4*4] = { 128,128,128,0, 255,0,0,50, 0,255,0,100, 0,0,255,150, }; lut->SetNumberOfTableValues(4); for(int i=0; i<4; i++) { int k = i*4; lut->SetTableValue(i, v[k]/255.0, v[k+1]/255.0, v[k+2]/255.0, v[k+3]/255.0); } }; //--------------------------------------------------------------------- void lutVolRenTwoLev( vtkLookupTable *lut) //--------------------------------------------------------------------- { //Run2 unsigned char v[8*4] = { 128,128,128,0, 128,128,128,0, 255,255,0,50, 128,128,128,0, 128,128,128,0, 255,50,0,100, 128,128,128,0, 128,128,128,0, }; lut->SetNumberOfTableValues(8); for(int i=0; i<8; i++) { int k = i*4; lut->SetTableValue(i, v[k]/255.0, v[k+1]/255.0, v[k+2]/255.0, v[k+3]/255.0); } }
 
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<iomanip> #include<algorithm> #include<queue> #include<stack> #include<vector> #define ri register int using namespace std; int ans,n,map[1005][1005],f[1005][1005]; inline int getint() { int num=0,bj=1; char c=getchar(); while(c<'0'||c>'9')bj=(c=='-'||bj==-1)?-1:1,c=getchar(); while(c>='0'&&c<='9')num=num*10+c-'0',c=getchar(); return num*bj; } int main() { char ch; n=getint(); for(ri i=1;i<=n;i++) for(ri j=1;j<=n;j++) { while(ch=getchar())if(ch=='0'||ch=='1')break; map[i][j]=ch-'0'; } for(ri i=1;i<=n;i++) for(ri j=1;j<=n;j++) { if(!map[i][j]){f[i][j]=0;continue;} int tmp=min(f[i-1][j-1],min(f[i-1][j],f[i][j-1])); f[i][j]=tmp+1; ans=max(f[i][j],ans); } printf("%d",ans*ans); return 0; }
; struct sp1_update __CALLEE__ *sp1_GetUpdateStruct_callee(uchar row, uchar col) ; 01.2008 aralbrec, Sprite Pack v3.0 ; ts2068 hi-res version INCLUDE "ts2068hr/customize.asm" PUBLIC sp1_GetUpdateStruct_callee PUBLIC ASMDISP_SP1_GETUPDATESTRUCT_CALLEE .sp1_GetUpdateStruct_callee pop hl pop de ex (sp),hl ld d,l .asmentry ; Return struct_sp1_update for row,col coordinate given ; 9 * (SP1V_DISPWIDTH * ROW + COL) + SP1V_UPDATEARRAY ; ; enter : d = row coord ; e = col coord ; exit : hl = struct update * ; uses : af, de, hl .SP1GetUpdateStruct ld l,d ld h,0 ld a,d ld d,h cp SP1V_DISPHEIGHT jp c, nohtadj dec h .nohtadj IF SP1V_DISPWIDTH=16 add hl,hl add hl,hl add hl,hl add hl,hl ld a,e cp SP1V_DISPWIDTH jp c, nowiadj dec d .nowiadj add hl,de ; hl = 16 * ROW + COL ENDIF IF SP1V_DISPWIDTH=24 add hl,hl add hl,hl add hl,hl push hl add hl,hl ld a,e cp SP1V_DISPWIDTH jp c, nowiadj dec d .nowiadj add hl,de pop de add hl,de ; hl = 24 * ROW + COL ENDIF IF SP1V_DISPWIDTH=32 add hl,hl add hl,hl add hl,hl add hl,hl add hl,hl ld a,e cp SP1V_DISPWIDTH jp c, nowiadj dec d .nowiadj add hl,de ; hl = 32 * ROW + COL ENDIF IF SP1V_DISPWIDTH=40 add hl,hl add hl,hl add hl,hl push hl add hl,hl add hl,hl ld a,e cp SP1V_DISPWIDTH jp c, nowiadj dec d .nowiadj add hl,de pop de add hl,de ; hl = 40 * ROW + COL ENDIF IF SP1V_DISPWIDTH=48 add hl,hl add hl,hl add hl,hl add hl,hl push hl add hl,hl ld a,e cp SP1V_DISPWIDTH jp c, nowiadj dec d .nowiadj add hl,de pop de add hl,de ; hl = 48 * ROW + COL ENDIF IF SP1V_DISPWIDTH=56 add hl,hl add hl,hl add hl,hl push hl add hl,hl push hl add hl,hl ld a,e cp SP1V_DISPWIDTH jp c, nowiadj dec d .nowiadj add hl,de pop de add hl,de pop de add hl,de ; hl = 56 * ROW + COL ENDIF IF SP1V_DISPWIDTH=64 add hl,hl add hl,hl add hl,hl add hl,hl add hl,hl add hl,hl ld a,e cp SP1V_DISPWIDTH jp c, nowiadj dec d .nowiadj add hl,de ; hl = 64 * ROW + COL ENDIF ld d,h ld e,l add hl,hl add hl,hl add hl,hl add hl,de ; hl = 9 * (SP1V_DISPWIDTH * ROW + COL) ld de,SP1V_UPDATEARRAY add hl,de ret DEFC ASMDISP_SP1_GETUPDATESTRUCT_CALLEE = asmentry - sp1_GetUpdateStruct_callee
/****************************************************************************** * Copyright 2017 The Apollo 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 "modules/canbus/vehicle/lincoln/protocol/gear_66.h" #include "modules/canbus/common/byte.h" namespace apollo { namespace canbus { namespace lincoln { // public const int32_t Gear66::ID = 0x66; uint32_t Gear66::GetPeriod() const { // on event, so value nonsense static const uint32_t PERIOD = 20 * 1000; return PERIOD; } void Gear66::UpdateData(uint8_t* data) { set_gear_p(data, gear_); set_clear_driver_override_flag_p(data); } void Gear66::Reset() { gear_ = 0; } Gear66* Gear66::set_gear_none() { gear_ = 0x00; return this; } Gear66* Gear66::set_gear_park() { gear_ = 0x01; return this; } Gear66* Gear66::set_gear_reverse() { gear_ = 0x02; return this; } Gear66* Gear66::set_gear_neutral() { gear_ = 0x03; return this; } Gear66* Gear66::set_gear_drive() { gear_ = 0x04; return this; } Gear66* Gear66::set_gear_low() { gear_ = 0x05; return this; } // private void Gear66::set_gear_p(uint8_t* data, int32_t gear) { gear = ProtocolData::BoundedValue(0, 5, gear); Byte frame(data); frame.set_value(gear, 0, 3); } void Gear66::set_clear_driver_override_flag_p(uint8_t* bytes) { Byte frame(bytes); frame.set_bit_0(7); } } // namespace lincoln } // namespace canbus } // namespace apollo
; ; Startup for V-Tech Laser 350/500/700 ; module laser500_crt0 ;-------- ; Include zcc_opt.def to find out some info ;-------- defc crt0 = 1 INCLUDE "zcc_opt.def" ;-------- ; Some scope definitions ;-------- EXTERN _main ;main() is always external to crt0 code PUBLIC cleanup ;jp'd to by exit() PUBLIC l_dcal ;jp(hl) ; 2 columns on left and 2 column on right are lost defc CONSOLE_COLUMNS = 40 defc CONSOLE_ROWS = 24 defc TAR__no_ansifont = 1 defc CRT_KEY_DEL = 12 defc __CPU_CLOCK = 3694700 IF startup = 2 INCLUDE "target/laser500/classic/rom.asm" ELSE INCLUDE "target/laser500/def/maths_mbf.def" INCLUDE "target/laser500/classic/ram.asm" ENDIF INCLUDE "crt/classic/crt_runtime_selection.asm" INCLUDE "crt/classic/crt_section.asm"
; ; Z88 Graphics Functions - Small C+ stubs ; Written around the Interlogic Standard Library ; Stubs Written by D Morris - 30/9/98 ; ; $Id: clga_callee.asm $ ; ;Usage: clga(struct *pixels) IF !__CPU_INTEL__ & !__CPU_GBZ80__ SECTION code_graphics PUBLIC clga_callee PUBLIC _clga_callee PUBLIC ASMDISP_CLGA_CALLEE EXTERN swapgfxbk EXTERN __graphics_end EXTERN cleararea .clga_callee ._clga_callee pop af ; ret addr pop bc ; y2 pop hl ld b,l ; x2 pop hl ; y pop de ld h,e ; x push af ; ret addr .asmentry push ix call swapgfxbk call cleararea jp __graphics_end DEFC ASMDISP_CLGA_CALLEE = asmentry - clga_callee ENDIF
; A211704: a(n) = n + [n/2] + [n/3] + [n/4] + [n/5], where []=floor. ; 1,3,5,8,10,13,14,17,19,22,23,27,28,30,33,36,37,40,41,45,47,49,50,54,56,58,60,63,64,68,69,72,74,76,78,82,83,85,87,91,92,95,96,99,102,104,105,109,110,113,115,118,119,122,124,127,129,131,132,137,138 add $0,1 mov $1,$0 lpb $1 mov $2,$1 mov $1,1 seq $2,187325 ; a(n) = floor(n/2) + floor(n/3) + floor(n/4) + floor(n/5). lpe add $0,$2
//===-- src/config.h - Application configuration header file ----*- C++ -*-===// // // Licensed under BSD0. See LICENSE for more information. // //===----------------------------------------------------------------------===// /// /// \file /// This file contains the configuration structure, as well as declaring /// the configuration functions. /// //===----------------------------------------------------------------------===// #pragma once #include <rgbmatrix/graphics.h> // for Font #include <rgbmatrix/led-matrix.h> // for RGBMatrix, RuntimeOptions (ptr only) namespace libconfig { class Config; } namespace RGBSign { struct Config { bool verbose; rgb_matrix::Font font; }; bool parseConfig(libconfig::Config &cfg, rgb_matrix::RGBMatrix::Options &options, rgb_matrix::RuntimeOptions &rt_options, Config &config); } // namespace RGBSign
0x0000 (0x000000) 0x2118- f:00020 d: 280 | A = OR[280] 0x0001 (0x000002) 0x1E00-0x0047 f:00017 d: 0 | A = A - 71 (0x0047) 0x0003 (0x000006) 0x8002- f:00100 d: 2 | P = P + 2 (0x0005), C = 0 0x0004 (0x000008) 0x704E- f:00070 d: 78 | P = P + 78 (0x0052) 0x0005 (0x00000A) 0x2118- f:00020 d: 280 | A = OR[280] 0x0006 (0x00000C) 0x2913- f:00024 d: 275 | OR[275] = A 0x0007 (0x00000E) 0x7480- f:00072 d: 128 | R = P + 128 (0x0087) 0x0008 (0x000010) 0x2119- f:00020 d: 281 | A = OR[281] 0x0009 (0x000012) 0x8602- f:00103 d: 2 | P = P + 2 (0x000B), A # 0 0x000A (0x000014) 0x7047- f:00070 d: 71 | P = P + 71 (0x0051) 0x000B (0x000016) 0x2120- f:00020 d: 288 | A = OR[288] 0x000C (0x000018) 0x1A00-0x0001 f:00015 d: 0 | A = A & 1 (0x0001) 0x000E (0x00001C) 0x2908- f:00024 d: 264 | OR[264] = A 0x000F (0x00001E) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x0010 (0x000020) 0x2708- f:00023 d: 264 | A = A - OR[264] 0x0011 (0x000022) 0x8602- f:00103 d: 2 | P = P + 2 (0x0013), A # 0 0x0012 (0x000024) 0x703F- f:00070 d: 63 | P = P + 63 (0x0051) 0x0013 (0x000026) 0x211B- f:00020 d: 283 | A = OR[283] 0x0014 (0x000028) 0x843D- f:00102 d: 61 | P = P + 61 (0x0051), A = 0 0x0015 (0x00002A) 0x211D- f:00020 d: 285 | A = OR[285] 0x0016 (0x00002C) 0x843B- f:00102 d: 59 | P = P + 59 (0x0051), A = 0 0x0017 (0x00002E) 0x211A- f:00020 d: 282 | A = OR[282] 0x0018 (0x000030) 0x0801- f:00004 d: 1 | A = A > 1 (0x0001) 0x0019 (0x000032) 0x2519- f:00022 d: 281 | A = A + OR[281] 0x001A (0x000034) 0x290D- f:00024 d: 269 | OR[269] = A 0x001B (0x000036) 0x310D- f:00030 d: 269 | A = (OR[269]) 0x001C (0x000038) 0x290D- f:00024 d: 269 | OR[269] = A 0x001D (0x00003A) 0x211A- f:00020 d: 282 | A = OR[282] 0x001E (0x00003C) 0x1201- f:00011 d: 1 | A = A & 1 (0x0001) 0x001F (0x00003E) 0x2908- f:00024 d: 264 | OR[264] = A 0x0020 (0x000040) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x0021 (0x000042) 0x2708- f:00023 d: 264 | A = A - OR[264] 0x0022 (0x000044) 0x8604- f:00103 d: 4 | P = P + 4 (0x0026), A # 0 0x0023 (0x000046) 0x210D- f:00020 d: 269 | A = OR[269] 0x0024 (0x000048) 0x0808- f:00004 d: 8 | A = A > 8 (0x0008) 0x0025 (0x00004A) 0x290D- f:00024 d: 269 | OR[269] = A 0x0026 (0x00004C) 0x210D- f:00020 d: 269 | A = OR[269] 0x0027 (0x00004E) 0x12FF- f:00011 d: 255 | A = A & 255 (0x00FF) 0x0028 (0x000050) 0x2913- f:00024 d: 275 | OR[275] = A 0x0029 (0x000052) 0x2D1A- f:00026 d: 282 | OR[282] = OR[282] + 1 0x002A (0x000054) 0x2113- f:00020 d: 275 | A = OR[275] 0x002B (0x000056) 0x1620- f:00013 d: 32 | A = A - 32 (0x0020) 0x002C (0x000058) 0x8203- f:00101 d: 3 | P = P + 3 (0x002F), C = 1 0x002D (0x00005A) 0x1020- f:00010 d: 32 | A = 32 (0x0020) 0x002E (0x00005C) 0x2913- f:00024 d: 275 | OR[275] = A 0x002F (0x00005E) 0x2113- f:00020 d: 275 | A = OR[275] 0x0030 (0x000060) 0x167F- f:00013 d: 127 | A = A - 127 (0x007F) 0x0031 (0x000062) 0x8004- f:00100 d: 4 | P = P + 4 (0x0035), C = 0 0x0032 (0x000064) 0x8403- f:00102 d: 3 | P = P + 3 (0x0035), A = 0 0x0033 (0x000066) 0x1020- f:00010 d: 32 | A = 32 (0x0020) 0x0034 (0x000068) 0x2913- f:00024 d: 275 | OR[275] = A 0x0035 (0x00006A) 0x2113- f:00020 d: 275 | A = OR[275] 0x0036 (0x00006C) 0x12FF- f:00011 d: 255 | A = A & 255 (0x00FF) 0x0037 (0x00006E) 0x290D- f:00024 d: 269 | OR[269] = A 0x0038 (0x000070) 0x211F- f:00020 d: 287 | A = OR[287] 0x0039 (0x000072) 0x0801- f:00004 d: 1 | A = A > 1 (0x0001) 0x003A (0x000074) 0x251C- f:00022 d: 284 | A = A + OR[284] 0x003B (0x000076) 0x290E- f:00024 d: 270 | OR[270] = A 0x003C (0x000078) 0x211F- f:00020 d: 287 | A = OR[287] 0x003D (0x00007A) 0x1201- f:00011 d: 1 | A = A & 1 (0x0001) 0x003E (0x00007C) 0x2908- f:00024 d: 264 | OR[264] = A 0x003F (0x00007E) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x0040 (0x000080) 0x2708- f:00023 d: 264 | A = A - OR[264] 0x0041 (0x000082) 0x8607- f:00103 d: 7 | P = P + 7 (0x0048), A # 0 0x0042 (0x000084) 0x310E- f:00030 d: 270 | A = (OR[270]) 0x0043 (0x000086) 0x0A09- f:00005 d: 9 | A = A < 9 (0x0009) 0x0044 (0x000088) 0x250D- f:00022 d: 269 | A = A + OR[269] 0x0045 (0x00008A) 0x0C09- f:00006 d: 9 | A = A >> 9 (0x0009) 0x0046 (0x00008C) 0x390E- f:00034 d: 270 | (OR[270]) = A 0x0047 (0x00008E) 0x7006- f:00070 d: 6 | P = P + 6 (0x004D) 0x0048 (0x000090) 0x310E- f:00030 d: 270 | A = (OR[270]) 0x0049 (0x000092) 0x1A00-0xFF00 f:00015 d: 0 | A = A & 65280 (0xFF00) 0x004B (0x000096) 0x250D- f:00022 d: 269 | A = A + OR[269] 0x004C (0x000098) 0x390E- f:00034 d: 270 | (OR[270]) = A 0x004D (0x00009A) 0x2D1F- f:00026 d: 287 | OR[287] = OR[287] + 1 0x004E (0x00009C) 0x2F1B- f:00027 d: 283 | OR[283] = OR[283] - 1 0x004F (0x00009E) 0x2F1D- f:00027 d: 285 | OR[285] = OR[285] - 1 0x0050 (0x0000A0) 0x723D- f:00071 d: 61 | P = P - 61 (0x0013) 0x0051 (0x0000A2) 0x702B- f:00070 d: 43 | P = P + 43 (0x007C) 0x0052 (0x0000A4) 0x1800-0x0048 f:00014 d: 0 | A = 72 (0x0048) 0x0054 (0x0000A8) 0x2913- f:00024 d: 275 | OR[275] = A 0x0055 (0x0000AA) 0x7432- f:00072 d: 50 | R = P + 50 (0x0087) 0x0056 (0x0000AC) 0x211D- f:00020 d: 285 | A = OR[285] 0x0057 (0x0000AE) 0x1605- f:00013 d: 5 | A = A - 5 (0x0005) 0x0058 (0x0000B0) 0x8003- f:00100 d: 3 | P = P + 3 (0x005B), C = 0 0x0059 (0x0000B2) 0x8402- f:00102 d: 2 | P = P + 2 (0x005B), A = 0 0x005A (0x0000B4) 0x7002- f:00070 d: 2 | P = P + 2 (0x005C) 0x005B (0x0000B6) 0x7021- f:00070 d: 33 | P = P + 33 (0x007C) 0x005C (0x0000B8) 0x311C- f:00030 d: 284 | A = (OR[284]) 0x005D (0x0000BA) 0x2920- f:00024 d: 288 | OR[288] = A 0x005E (0x0000BC) 0x2118- f:00020 d: 280 | A = OR[280] 0x005F (0x0000BE) 0x391C- f:00034 d: 284 | (OR[284]) = A 0x0060 (0x0000C0) 0x1028- f:00010 d: 40 | A = 40 (0x0028) 0x0061 (0x0000C2) 0x2922- f:00024 d: 290 | OR[290] = A 0x0062 (0x0000C4) 0x1800-0x0011 f:00014 d: 0 | A = 17 (0x0011) 0x0064 (0x0000C8) 0x2923- f:00024 d: 291 | OR[291] = A 0x0065 (0x0000CA) 0x211C- f:00020 d: 284 | A = OR[284] 0x0066 (0x0000CC) 0x2924- f:00024 d: 292 | OR[292] = A 0x0067 (0x0000CE) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x0068 (0x0000D0) 0x2925- f:00024 d: 293 | OR[293] = A 0x0069 (0x0000D2) 0x1010- f:00010 d: 16 | A = 16 (0x0010) 0x006A (0x0000D4) 0x2926- f:00024 d: 294 | OR[294] = A 0x006B (0x0000D6) 0x211C- f:00020 d: 284 | A = OR[284] 0x006C (0x0000D8) 0x2927- f:00024 d: 295 | OR[295] = A 0x006D (0x0000DA) 0x211F- f:00020 d: 287 | A = OR[287] 0x006E (0x0000DC) 0x2928- f:00024 d: 296 | OR[296] = A 0x006F (0x0000DE) 0x1002- f:00010 d: 2 | A = 2 (0x0002) 0x0070 (0x0000E0) 0x2929- f:00024 d: 297 | OR[297] = A 0x0071 (0x0000E2) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x0072 (0x0000E4) 0x292A- f:00024 d: 298 | OR[298] = A 0x0073 (0x0000E6) 0x1122- f:00010 d: 290 | A = 290 (0x0122) 0x0074 (0x0000E8) 0x5800- f:00054 d: 0 | B = A 0x0075 (0x0000EA) 0x1800-0x1518 f:00014 d: 0 | A = 5400 (0x1518) 0x0077 (0x0000EE) 0x7C09- f:00076 d: 9 | R = OR[9] 0x0078 (0x0000F0) 0x1006- f:00010 d: 6 | A = 6 (0x0006) 0x0079 (0x0000F2) 0x2B1F- f:00025 d: 287 | OR[287] = A + OR[287] 0x007A (0x0000F4) 0x2120- f:00020 d: 288 | A = OR[288] 0x007B (0x0000F6) 0x391C- f:00034 d: 284 | (OR[284]) = A 0x007C (0x0000F8) 0x2005- f:00020 d: 5 | A = OR[5] 0x007D (0x0000FA) 0x251E- f:00022 d: 286 | A = A + OR[286] 0x007E (0x0000FC) 0x290D- f:00024 d: 269 | OR[269] = A 0x007F (0x0000FE) 0x211F- f:00020 d: 287 | A = OR[287] 0x0080 (0x000100) 0x390D- f:00034 d: 269 | (OR[269]) = A 0x0081 (0x000102) 0x102A- f:00010 d: 42 | A = 42 (0x002A) 0x0082 (0x000104) 0x2922- f:00024 d: 290 | OR[290] = A 0x0083 (0x000106) 0x1122- f:00010 d: 290 | A = 290 (0x0122) 0x0084 (0x000108) 0x5800- f:00054 d: 0 | B = A 0x0085 (0x00010A) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x0086 (0x00010C) 0x7C09- f:00076 d: 9 | R = OR[9] 0x0087 (0x00010E) 0x1028- f:00010 d: 40 | A = 40 (0x0028) 0x0088 (0x000110) 0x2922- f:00024 d: 290 | OR[290] = A 0x0089 (0x000112) 0x1800-0x0023 f:00014 d: 0 | A = 35 (0x0023) 0x008B (0x000116) 0x2923- f:00024 d: 291 | OR[291] = A 0x008C (0x000118) 0x1800-0x003B f:00014 d: 0 | A = 59 (0x003B) 0x008E (0x00011C) 0x2924- f:00024 d: 292 | OR[292] = A 0x008F (0x00011E) 0x2113- f:00020 d: 275 | A = OR[275] 0x0090 (0x000120) 0x2925- f:00024 d: 293 | OR[293] = A 0x0091 (0x000122) 0x211C- f:00020 d: 284 | A = OR[284] 0x0092 (0x000124) 0x2926- f:00024 d: 294 | OR[294] = A 0x0093 (0x000126) 0x211D- f:00020 d: 285 | A = OR[285] 0x0094 (0x000128) 0x2927- f:00024 d: 295 | OR[295] = A 0x0095 (0x00012A) 0x1013- f:00010 d: 19 | A = 19 (0x0013) 0x0096 (0x00012C) 0x2928- f:00024 d: 296 | OR[296] = A 0x0097 (0x00012E) 0x1014- f:00010 d: 20 | A = 20 (0x0014) 0x0098 (0x000130) 0x2929- f:00024 d: 297 | OR[297] = A 0x0099 (0x000132) 0x1015- f:00010 d: 21 | A = 21 (0x0015) 0x009A (0x000134) 0x292A- f:00024 d: 298 | OR[298] = A 0x009B (0x000136) 0x1122- f:00010 d: 290 | A = 290 (0x0122) 0x009C (0x000138) 0x5800- f:00054 d: 0 | B = A 0x009D (0x00013A) 0x1800-0x1518 f:00014 d: 0 | A = 5400 (0x1518) 0x009F (0x00013E) 0x7C09- f:00076 d: 9 | R = OR[9] 0x00A0 (0x000140) 0x211D- f:00020 d: 285 | A = OR[285] 0x00A1 (0x000142) 0x271F- f:00023 d: 287 | A = A - OR[287] 0x00A2 (0x000144) 0x291D- f:00024 d: 285 | OR[285] = A 0x00A3 (0x000146) 0x0200- f:00001 d: 0 | EXIT 0x00A4 (0x000148) 0x0000- f:00000 d: 0 | PASS 0x00A5 (0x00014A) 0x0000- f:00000 d: 0 | PASS 0x00A6 (0x00014C) 0x0000- f:00000 d: 0 | PASS 0x00A7 (0x00014E) 0x0000- f:00000 d: 0 | PASS
; A304158: a(n) is the second Zagreb index of the linear phenylene G[n], defined pictorially in the Darafsheh reference (Fig. 3). ; 24,84,144,204,264,324,384,444,504,564,624,684,744,804,864,924,984,1044,1104,1164,1224,1284,1344,1404,1464,1524,1584,1644,1704,1764,1824,1884,1944,2004,2064,2124,2184,2244,2304,2364,2424,2484,2544,2604,2664,2724,2784,2844,2904,2964,3024,3084,3144,3204,3264,3324,3384,3444,3504,3564,3624,3684,3744,3804,3864,3924,3984,4044,4104,4164,4224,4284,4344,4404,4464,4524,4584,4644,4704,4764,4824,4884,4944,5004,5064,5124,5184,5244,5304,5364,5424,5484,5544,5604,5664,5724,5784,5844,5904,5964 mul $0,60 add $0,24
MXETMRXR TITLE 'MXE COMMON TIMER EXIT ROUTINE' *--------+---------+---------+---------+---------+---------+---------+- * Name : MXETMRXR * * Function : General purpose STIMERM exit routine * * Invoked by the MXETIMER macro * * * Register Usage : * r1 - parameter passed : +4 MXETIMER * r2 - * r3 - * r4 - * r5 - * r6 - * r7 - * r8 - * r9 - MXETIMER * r10 - * r11 - * r12 - Data * r13 - * *--------+---------+---------+---------+---------+---------+---------+- * Changes * 2019/01/09 RDS Code Written *--------+---------+---------+---------+---------+---------+---------+- MXETMRXR MXEMAIN DATAREG=(R12) LLGT R9,4(,R1) USING MXETIMER,R9 MXEMAC VER_ID,MXETIMER IF (LTR,R15,R15,NZ) MXEMAC ABEND,MXEEQU@RSN_TIMER ENDIF POST MXETIMER_ECB Post the timer ECB MXEMAIN RETURN MXEMAIN END * *--------+---------+---------+---------+---------+---------+---------+- * DSECTs *--------+---------+---------+---------+---------+---------+---------+- * MXEGBVT MXETIMER DSECT=YES MXEMAC REG_EQU * END
/* -*- c++ -*- */ /* * Copyright 2014 Free Software Foundation, Inc. * * This file is part of GNU Radio * * GNU Radio is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3, or (at your option) * any later version. * * GNU Radio 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 for more details. * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, * Boston, MA 02110-1301, USA. */ #include "atsc_fake_single_viterbi.h" namespace gr { namespace dtv { void atsc_fake_single_viterbi::reset() { post_coder_state = 0; } atsc_fake_single_viterbi::atsc_fake_single_viterbi() { reset(); } /* * implement simple slicer and post coder */ char atsc_fake_single_viterbi::decode(float input) { int y2, y1; if (input < -4){ y2 = 0; y1 = 0; } else if (input < 0){ y2 = 0; y1 = 1; } else if (input < 4){ y2 = 1; y1 = 0; } else { y2 = 1; y1 = 1; } int x1 = y1; int x2 = y2 ^ post_coder_state; post_coder_state = y2; return (x2 << 1) | x1; } } /* namespace dtv */ } /* namespace gr */
#include "Image.h" #include <Kore/Graphics4/Graphics.h> #include <Kore/IO/BufferReader.h> #include <Kore/IO/FileReader.h> #include <Kore/IO/Reader.h> #include <kinc/image.h> #include <kinc/log.h> #include <stdio.h> #include <stdlib.h> #include <string.h> using namespace Kore; namespace { static int read_callback(void *user_data, void *data, size_t size) { Kore::Reader *file = (Kore::Reader *)user_data; return file->read(data, (int)size); } static size_t size_callback(void *user_data) { Kore::Reader *file = (Kore::Reader *)user_data; return (size_t)file->size(); } static int pos_callback(void *user_data) { Kore::Reader *file = (Kore::Reader *)user_data; return file->pos(); } static void seek_callback(void *user_data, int pos) { Kore::Reader *file = (Kore::Reader *)user_data; file->seek(pos); } void loadImage(Kore::Reader &file, const char *filename, u8 *&output, int &outputSize, int &width, int &height, Graphics1::ImageCompression &compression, Graphics1::Image::Format &format, unsigned &internalFormat) { kinc_image_read_callbacks_t callbacks; callbacks.read = read_callback; callbacks.size = size_callback; callbacks.pos = pos_callback; callbacks.seek = seek_callback; size_t size = kinc_image_size_from_callbacks(callbacks, &file, filename); file.seek(0); output = new u8[size]; kinc_image_t image; kinc_image_init_from_callbacks(&image, output, callbacks, &file, filename); outputSize = (int)size; width = image.width; height = image.height; compression = (Graphics1::ImageCompression)image.compression; format = (Graphics1::Image::Format)image.format; internalFormat = image.internal_format; kinc_image_destroy(&image); } } int Graphics1::Image::sizeOf(Image::Format format) { switch (format) { case Image::RGBA128: return 16; case Image::RGBA32: case Image::BGRA32: return 4; case Image::RGBA64: return 8; case Image::A32: return 4; case Image::A16: return 2; case Image::Grey8: return 1; case Image::RGB24: return 3; } return -1; } Graphics1::Image::Image(int width, int height, Format format, bool readable) : width(width), height(height), depth(1), format(format), readable(readable) { compression = ImageCompressionNone; dataSize = width * height * sizeOf(format); data = new u8[dataSize]; } Graphics1::Image::Image(int width, int height, int depth, Format format, bool readable) : width(width), height(height), depth(depth), format(format), readable(readable) { compression = ImageCompressionNone; dataSize = width * height * depth * sizeOf(format); data = new u8[dataSize]; } Graphics1::Image::Image(const char *filename, bool readable) : depth(1), format(RGBA32), readable(readable) { FileReader reader(filename); init(reader, filename, readable); } Graphics1::Image::Image(Reader &reader, const char *format, bool readable) : depth(1), format(RGBA32), readable(readable) { init(reader, format, readable); } Graphics1::Image::Image(void *data, int width, int height, Format format, bool readable) : width(width), height(height), depth(1), format(format), readable(readable) { compression = ImageCompressionNone; this->data = data; } Graphics1::Image::Image(void *data, int width, int height, int depth, Format format, bool readable) : width(width), height(height), depth(depth), format(format), readable(readable) { compression = ImageCompressionNone; this->data = data; } Graphics1::Image::Image() : depth(1), format(RGBA32), readable(false) {} void Graphics1::Image::init(Kore::Reader &file, const char *filename, bool readable) { u8 *imageData; loadImage(file, filename, imageData, dataSize, width, height, compression, this->format, internalFormat); data = imageData; } Graphics1::Image::~Image() { if (data != nullptr) { free(data); data = nullptr; } } int Graphics1::Image::at(int x, int y) { if (data == nullptr) { kinc_log(KINC_LOG_LEVEL_WARNING, "Attempting to read a non-readable image."); return 0; } else { return *(int *)&((u8 *)data)[width * sizeOf(format) * y + x * sizeOf(format)]; } } u8 *Graphics1::Image::getPixels() { return (u8 *)data; }
<% import collections import pwnlib.abi import pwnlib.constants import pwnlib.shellcraft import six %> <%docstring>symlinkat(from_, tofd, to) -> str Invokes the syscall symlinkat. See 'man 2 symlinkat' for more information. Arguments: from(char*): from tofd(int): tofd to(char*): to Returns: int </%docstring> <%page args="from_=0, tofd=0, to=0"/> <% abi = pwnlib.abi.ABI.syscall() stack = abi.stack regs = abi.register_arguments[1:] allregs = pwnlib.shellcraft.registers.current() can_pushstr = ['from', 'to'] can_pushstr_array = [] argument_names = ['from_', 'tofd', 'to'] argument_values = [from_, tofd, to] # 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_symlinkat']: if hasattr(pwnlib.constants, syscall): break else: raise Exception("Could not locate any syscalls: %r" % syscalls) %> /* symlinkat(${', '.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)}
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r8 push %rax push %rbp push %rbx push %rcx push %rdi push %rsi lea addresses_D_ht+0x177fb, %rbp nop and $33440, %rax movw $0x6162, (%rbp) nop nop lfence lea addresses_UC_ht+0xf53d, %rsi lea addresses_WC_ht+0x3d3d, %rdi nop nop and $60546, %rbx mov $114, %rcx rep movsb nop nop nop nop nop sub $4005, %rcx lea addresses_WT_ht+0x313d, %rsi lea addresses_WT_ht+0x1aaad, %rdi sub $23511, %r8 mov $106, %rcx rep movsq nop nop nop nop sub %rax, %rax lea addresses_A_ht+0x14c33, %r10 nop nop sub $11533, %rbp mov $0x6162636465666768, %r8 movq %r8, %xmm1 movups %xmm1, (%r10) nop nop nop and %rsi, %rsi lea addresses_D_ht+0x393d, %rax nop and %rcx, %rcx movw $0x6162, (%rax) nop nop xor $40176, %rcx lea addresses_WT_ht+0x64bd, %rsi lea addresses_UC_ht+0x1a5bd, %rdi nop nop nop add %r8, %r8 mov $118, %rcx rep movsw nop nop and %rsi, %rsi lea addresses_D_ht+0x1404d, %rsi lea addresses_WT_ht+0x134bd, %rdi nop nop nop nop xor %r8, %r8 mov $13, %rcx rep movsb xor $37673, %r10 lea addresses_UC_ht+0x17e3d, %rsi lea addresses_WT_ht+0x1843d, %rdi nop nop dec %rax mov $67, %rcx rep movsw nop cmp %rax, %rax lea addresses_WT_ht+0xd191, %rcx nop nop nop nop nop and %rbx, %rbx mov (%rcx), %r10 xor %rsi, %rsi lea addresses_normal_ht+0x1a8bd, %rsi lea addresses_UC_ht+0x6071, %rdi nop nop nop nop nop cmp $50605, %rbx mov $97, %rcx rep movsb nop nop cmp %rcx, %rcx lea addresses_D_ht+0x1725d, %rsi lea addresses_A_ht+0xbc1, %rdi nop nop nop nop xor %rbx, %rbx mov $121, %rcx rep movsw nop nop nop sub %rbp, %rbp lea addresses_UC_ht+0x4ed3, %rsi lea addresses_WC_ht+0x11e9d, %rdi nop nop sub %r8, %r8 mov $34, %rcx rep movsl add $60172, %rcx lea addresses_normal_ht+0x10780, %rbx nop nop nop nop and %rdi, %rdi vmovups (%rbx), %ymm0 vextracti128 $0, %ymm0, %xmm0 vpextrq $1, %xmm0, %rax and $5745, %rcx lea addresses_UC_ht+0xfd3d, %rdi nop nop nop nop nop cmp $17934, %r10 mov (%rdi), %rbx nop xor $63608, %rbx pop %rsi pop %rdi pop %rcx pop %rbx pop %rbp pop %rax pop %r8 pop %r10 ret .global s_faulty_load s_faulty_load: push %r11 push %r12 push %r9 push %rax push %rcx push %rdi push %rsi // Store mov $0x13d, %rax nop nop nop and $1496, %rsi movb $0x51, (%rax) nop nop nop nop cmp %rcx, %rcx // Store lea addresses_D+0x413d, %rsi nop nop nop nop nop and $55146, %r11 mov $0x5152535455565758, %r12 movq %r12, %xmm0 movaps %xmm0, (%rsi) nop nop cmp %r11, %r11 // Load lea addresses_US+0x5c25, %rax nop nop nop nop cmp $42606, %rsi mov (%rax), %di nop nop nop nop xor %r11, %r11 // Faulty Load lea addresses_D+0x413d, %rcx nop nop nop xor %r11, %r11 movb (%rcx), %r12b lea oracles, %rax and $0xff, %r12 shlq $12, %r12 mov (%rax,%r12,1), %r12 pop %rsi pop %rdi pop %rcx pop %rax pop %r9 pop %r12 pop %r11 ret /* <gen_faulty_load> [REF] {'src': {'type': 'addresses_D', 'same': False, 'size': 8, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'dst': {'type': 'addresses_P', 'same': False, 'size': 1, 'congruent': 7, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'dst': {'type': 'addresses_D', 'same': True, 'size': 16, 'congruent': 0, 'NT': False, 'AVXalign': True}, 'OP': 'STOR'} {'src': {'type': 'addresses_US', 'same': False, 'size': 2, 'congruent': 3, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} [Faulty Load] {'src': {'type': 'addresses_D', 'same': True, 'size': 1, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} <gen_prepare_buffer> {'dst': {'type': 'addresses_D_ht', 'same': False, 'size': 2, 'congruent': 1, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'src': {'type': 'addresses_UC_ht', 'congruent': 8, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 9, 'same': False}, 'OP': 'REPM'} {'src': {'type': 'addresses_WT_ht', 'congruent': 11, 'same': True}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 4, 'same': False}, 'OP': 'REPM'} {'dst': {'type': 'addresses_A_ht', 'same': False, 'size': 16, 'congruent': 1, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'dst': {'type': 'addresses_D_ht', 'same': False, 'size': 2, 'congruent': 10, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'src': {'type': 'addresses_WT_ht', 'congruent': 0, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 7, 'same': False}, 'OP': 'REPM'} {'src': {'type': 'addresses_D_ht', 'congruent': 2, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 7, 'same': False}, 'OP': 'REPM'} {'src': {'type': 'addresses_UC_ht', 'congruent': 8, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 8, 'same': False}, 'OP': 'REPM'} {'src': {'type': 'addresses_WT_ht', 'same': False, 'size': 8, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_normal_ht', 'congruent': 7, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 2, 'same': False}, 'OP': 'REPM'} {'src': {'type': 'addresses_D_ht', 'congruent': 5, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 1, 'same': False}, 'OP': 'REPM'} {'src': {'type': 'addresses_UC_ht', 'congruent': 1, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 2, 'same': False}, 'OP': 'REPM'} {'src': {'type': 'addresses_normal_ht', 'same': False, 'size': 32, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_UC_ht', 'same': False, 'size': 8, 'congruent': 9, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'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 */
; A349355: Dirichlet convolution of A003958 with A063441 (Dirichlet inverse of A003959), where A003958 and A003959 are fully multiplicative with a(p) = p-1 and p+1 respectively. ; Submitted by Christian Krause ; 1,-2,-2,-2,-2,4,-2,-2,-4,4,-2,4,-2,4,4,-2,-2,8,-2,4,4,4,-2,4,-8,4,-8,4,-2,-8,-2,-2,4,4,4,8,-2,4,4,4,-2,-8,-2,4,8,4,-2,4,-12,16,4,4,-2,16,4,4,4,4,-2,-8,-2,4,8,-2,4,-8,-2,4,4,-8,-2,8,-2,4,16,4,4,-8,-2,4,-16,4,-2,-8,4,4,4,4,-2,-16,4,4,4,4,4,4,-2,24,8,16 add $0,1 mov $1,1 mov $2,1 lpb $0 mov $3,$0 lpb $3 mov $4,$0 mod $4,$2 cmp $4,0 cmp $4,0 mov $5,$2 add $2,1 cmp $5,1 max $4,$5 sub $3,$4 lpe mov $3,$2 sub $3,1 mov $5,2 lpb $0 dif $0,$2 mul $5,$3 lpe div $4,2 sub $4,1 dif $5,$3 div $5,$4 mul $1,$5 lpe mov $0,$1
; A239123: a(n) = 128*n - 107 for n >= 1. Third column of triangle A238475. ; 21,149,277,405,533,661,789,917,1045,1173,1301,1429,1557,1685,1813,1941,2069,2197,2325,2453,2581,2709,2837,2965,3093,3221,3349,3477,3605,3733,3861,3989,4117,4245,4373,4501,4629,4757,4885,5013,5141,5269,5397,5525,5653,5781,5909,6037,6165,6293,6421,6549,6677,6805,6933,7061,7189,7317,7445,7573,7701,7829,7957,8085,8213,8341,8469,8597,8725,8853,8981,9109,9237,9365,9493,9621,9749,9877,10005,10133,10261,10389,10517,10645,10773,10901,11029,11157,11285,11413,11541,11669,11797,11925,12053,12181,12309,12437,12565,12693 mul $0,128 add $0,21
;------------------------------------------------------------------------------- ; rtexit.nasm - must be linked last. ;------------------------------------------------------------------------------- module libc.rtexit global text_end, data_end, bss_end publicproc _fini section .text proc _fini ret endp ;--------------------------------------------------------------- text_end: section .data data_end: section .bss bss_end:
/* * * Copyright 2018 gRPC authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ #include "test/core/util/fuzzer_util.h" #include <algorithm> #include <grpc/support/alloc.h> #include "src/core/lib/gpr/useful.h" namespace grpc_core { namespace testing { uint8_t grpc_fuzzer_get_next_byte(input_stream* inp) { if (inp->cur == inp->end) { return 0; } return *inp->cur++; } char* grpc_fuzzer_get_next_string(input_stream* inp, bool* special) { char* str = nullptr; size_t cap = 0; size_t sz = 0; char c; do { if (cap == sz) { cap = std::max(3 * cap / 2, cap + 8); str = static_cast<char*>(gpr_realloc(str, cap)); } c = static_cast<char>(grpc_fuzzer_get_next_byte(inp)); str[sz++] = c; } while (c != 0 && c != 1); if (special != nullptr) { *special = (c == 1); } if (c == 1) { str[sz - 1] = 0; } return str; } uint32_t grpc_fuzzer_get_next_uint32(input_stream* inp) { uint8_t b = grpc_fuzzer_get_next_byte(inp); uint32_t x = b & 0x7f; if (b & 0x80) { x <<= 7; b = grpc_fuzzer_get_next_byte(inp); x |= b & 0x7f; if (b & 0x80) { x <<= 7; b = grpc_fuzzer_get_next_byte(inp); x |= b & 0x7f; if (b & 0x80) { x <<= 7; b = grpc_fuzzer_get_next_byte(inp); x |= b & 0x7f; if (b & 0x80) { x = (x << 4) | (grpc_fuzzer_get_next_byte(inp) & 0x0f); } } } } return x; } } // namespace testing } // namespace grpc_core
BITS 64 ;TEST_FILE_META_BEGIN ;TEST_TYPE=TEST_F ;TEST_IGNOREFLAGS= ;TEST_FILE_META_END ; Mov32RR mov eax, 0x8 mov ecx, 0x12 ;TEST_BEGIN_RECORDING mov ecx, eax ;TEST_END_RECORDING
; A258290: Arithmetic derivative of central binomial coefficients, cf. A000984. ; 0,1,5,24,59,456,1448,6868,19749,69364,236356,1526956,3717440,22858340,122553540,474051984,954720543,5726109024,19329586520,92051285020,319059863484,1271796704788,4829219746964,29791326914640,74372011398840,340296661452300,1491340256144172,4918156369293664,16629386836762668,90972433916145088,296754947668880656,1393204641965627376,3304047871855621443,15562098893945597308,60083941932537100508,296804762039836443156,660697835379526552568,3456870105995621862308,18337358859970411571540 mov $2,$0 mul $0,2 bin $0,$2 seq $0,3415 ; a(n) = n' = arithmetic derivative of n: a(0) = a(1) = 0, a(prime) = 1, a(mn) = m*a(n) + n*a(m).
#include "resources.h" #include "shader_loader.h" #include "texture_loader.h" #include "mesh_loader.h" #include "../scene/scene.h" #include "../scene/scene_node.h" #include <t1_utility/string_id.h> #include <t1_utility/logging/log.h> #include <stack> #include <vector> namespace T1 { std::map<unsigned int, Shader> Resources::m_Shaders = std::map<unsigned int, Shader>(); std::map<unsigned int, Texture> Resources::m_Textures = std::map<unsigned int, Texture>(); std::map<unsigned int, TextureCube> Resources::m_TexturesCube = std::map<unsigned int, TextureCube>(); std::map<unsigned int, SceneNode*> Resources::m_Meshes = std::map<unsigned int, SceneNode*>(); // -------------------------------------------------------------------------------------------- void Resources::Init() { // initialize default assets/resources that should always be available, regardless of // configuration. Texture placeholderTexture; } void Resources::Clean() { // traverse all stored mesh scene nodes and delete accordingly. // Note that this time we don't care about deleting dangling pointers as each scene node is // unique and shouldn't reference other scene nodes than their children. for(auto it = m_Meshes.begin(); it != m_Meshes.end(); it++) { delete it->second; } } // -------------------------------------------------------------------------------------------- Shader* Resources::LoadShader(std::string name, std::string vsPath, std::string fsPath, std::vector<std::string> defines) { unsigned int id = SID(name); // if shader already exists, return that handle if(Resources::m_Shaders.find(id) != Resources::m_Shaders.end()) return &Resources::m_Shaders[id]; Shader shader = ShaderLoader::Load(name, vsPath, fsPath, defines); Resources::m_Shaders[id] = shader; return &Resources::m_Shaders[id]; } // -------------------------------------------------------------------------------------------- Shader* Resources::GetShader(std::string name) { unsigned int id = SID(name); // if shader exists, return that handle if (Resources::m_Shaders.find(id) != Resources::m_Shaders.end()) { return &Resources::m_Shaders[id]; } else { Log::Message("Requested shader: " + name + " not found!", LOG_WARNING); return nullptr; } } // -------------------------------------------------------------------------------------------- Texture* Resources::LoadTexture(std::string name, std::string path, GLenum target, GLenum format, bool srgb) { unsigned int id = SID(name); // if texture already exists, return that handle if (Resources::m_Textures.find(id) != Resources::m_Textures.end()) return &Resources::m_Textures[id]; Log::Message("Loading texture file at: " + path + ".", LOG_INIT); Texture texture = TextureLoader::LoadTexture(path, target, format, srgb); Log::Message("Succesfully loaded: " + path + ".", LOG_INIT); // make sure texture got properly loaded if (texture.Width > 0) { Resources::m_Textures[id] = texture; return &Resources::m_Textures[id]; } else { return nullptr; } } // -------------------------------------------------------------------------------------------- Texture* Resources::LoadHDR(std::string name, std::string path) { unsigned int id = SID(name); // if texture already exists, return that handle if (Resources::m_Textures.find(id) != Resources::m_Textures.end()) return &Resources::m_Textures[id]; Texture texture = TextureLoader::LoadHDRTexture(path); // make sure texture got properly loaded if (texture.Width > 0) { Resources::m_Textures[id] = texture; return &Resources::m_Textures[id]; } else { return nullptr; } } // -------------------------------------------------------------------------------------------- Texture* Resources::GetTexture(std::string name) { unsigned int id = SID(name); // if shader exists, return that handle if (Resources::m_Textures.find(id) != Resources::m_Textures.end()) { return &Resources::m_Textures[id]; } else { Log::Message("Requested texture: " + name + " not found!", LOG_WARNING); return nullptr; } } // -------------------------------------------------------------------------------------------- TextureCube* Resources::LoadTextureCube(std::string name, std::string folder) { unsigned int id = SID(name); // if texture already exists, return that handle if (Resources::m_TexturesCube.find(id) != Resources::m_TexturesCube.end()) return &Resources::m_TexturesCube[id]; TextureCube texture = TextureLoader::LoadTextureCube(folder); Resources::m_TexturesCube[id] = texture; return &Resources::m_TexturesCube[id]; } // -------------------------------------------------------------------------------------------- TextureCube* Resources::GetTextureCube(std::string name) { unsigned int id = SID(name); // if shader exists, return that handle if (Resources::m_TexturesCube.find(id) != Resources::m_TexturesCube.end()) { return &Resources::m_TexturesCube[id]; } else { Log::Message("Requested texture cube: " + name + " not found!", LOG_WARNING); return nullptr; } } // -------------------------------------------------------------------------------------------- SceneNode* Resources::LoadMesh(Renderer* renderer, std::string name, std::string path) { unsigned int id = SID(name); // if mesh's scene node was already loaded before, copy the scene node's memory and return // the copied reference. We return a copy as the moment the global scene deletes the // returned node, all other and next requested scene nodes of this model will end up as // dangling pointers. if (Resources::m_Meshes.find(id) != Resources::m_Meshes.end()) { return Scene::MakeSceneNode(Resources::m_Meshes[id]); } // MeshLoader::LoadMesh initializes a scene node hierarchy on the heap. We are responsible // for managing the memory; keep a reference to the root node of the model scene. SceneNode* node = MeshLoader::LoadMesh(renderer, path); Resources::m_Meshes[id] = node; // return a copied reference through the scene to prevent dangling pointers. // See description above. return Scene::MakeSceneNode(node); } // -------------------------------------------------------------------------------------------- SceneNode* Resources::GetMesh(std::string name) { unsigned int id = SID(name); // if mesh's scene node was already loaded before, copy the scene node's memory and return // the copied reference. We return a copy as the moment the global scene deletes the // returned node, all other and next requested scene nodes of this model will end up as // dangling pointers. if (Resources::m_Meshes.find(id) != Resources::m_Meshes.end()) { return Scene::MakeSceneNode(Resources::m_Meshes[id]); } else { Log::Message("Requested mesh: " + name + " not found!", LOG_WARNING); return nullptr; } } }
.386 .model flat,C PUBLIC setdta ; Not supported in 0.93 yet, don't use until 0.94 is out! ; Use the default DTA at psp:[80h] instead. .code setdta proc near mov ah,1Ah mov edx,[esp+4] int 21h ret setdta endp end
VDC_0 .equ $0000 VDC_1 .equ $0001 VDC_2 .equ $0002 VDC_3 .equ $0003 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 x_y_sin_cosBank .equ $02 charBank .equ $12 shipBank .equ $13 course1Bank .equ $14 course1angleBank .equ $1C course2Bank .equ $20 course2angleBank .equ $28 ;---------------------------- add .macro ;\1 = \2 + \3 ;\1 = \1 + \2 .if (\# = 3) clc lda \2 adc \3 sta \1 .else clc lda \1 adc \2 sta \1 .endif .endm ;---------------------------- sub .macro ;\1 = \2 - \3 ;\1 = \1 - \2 .if (\# = 3) sec lda \2 sbc \3 sta \1 .else sec lda \1 sbc \2 sta \1 .endif .endm ;---------------------------- addw .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 .else clc lda \1 adc \2 sta \1 lda \1+1 adc \2+1 sta \1+1 .endif .endm ;---------------------------- subw .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 .else sec lda \1 sbc \2 sta \1 lda \1+1 sbc \2+1 sta \1+1 .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 ;---------------------------- mov .macro ;\1 = \2 lda \2 sta \1 .endm ;---------------------------- movw .macro ;\1 = \2 lda \2 sta \1 lda \2+1 sta \1+1 .endm ;---------------------------- movq .macro ;\1 = \2 lda \2 sta \1 lda \2+1 sta \1+1 lda \2+2 sta \1+2 lda \2+3 sta \1+3 .endm ;---------------------------- aslw .macro ;\1 = \1 << 1 asl \1 rol \1+1 .endm ;---------------------------- aslq .macro ;\1 = \1 << 1 asl \1 rol \1+1 rol \1+2 rol \1+3 .endm ;---------------------------- lsrw .macro ;\1 = \1 << 1 lsr \1+1 ror \1 .endm ;---------------------------- lsrq .macro ;\1 = \1 << 1 lsr \1+3 ror \1+2 ror \1+1 ror \1 .endm ;---------------------------- negq .macro ;\1 = ~\1 + 1 clc lda \1 eor #$FF adc #1 sta \1 lda \1+1 eor #$FF adc #0 sta \1+1 lda \1+2 eor #$FF adc #0 sta \1+2 lda \1+3 eor #$FF adc #0 sta \1+3 .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 .zp .org $2000 ;------- do not move for loopxfunc ------------- ;+++++++++++++++++++++++++++++++++++++++++++++++ x0a .ds 3 y0a .ds 3 x1a .ds 3 y1a .ds 3 ;+++++++++++++++++++++++++++++++++++++++++++++++ ;----------------------------------------------- hitwork .ds 2 ;--------------------- lapflag .ds 1 ;--------------------- calclineptr .ds 2 ;--------------------- stageflag .ds 1 ;--------------------- padlast .ds 1 padnow .ds 1 padstate .ds 1 ;--------------------- vdpstatus .ds 1 scrollxwork .ds 1 ;--------------------- mul16a .ds 2 mul16b .ds 2 mul16c .ds 2 mul16d .ds 2 ;--------------------- mul16an .ds 2 mul16bn .ds 2 mul16cn .ds 2 mul16dn .ds 2 ;--------------------- puthexaddr .ds 2 puthexdata .ds 1 ;--------------------- psgchno .ds 1 psgfreqwork .ds 2 psgdataaddrwork .ds 2 psg0dataaddr .ds 2 psg0addr .ds 2 psg0count .ds 1 psg1dataaddr .ds 2 psg1addr .ds 2 psg1count .ds 1 ;--------------------- spritexywork .ds 2 spritexwork .ds 2 spriteywork .ds 2 spritenowork .ds 2 spriteworkaddress .ds 2 ;/////////////////////////////////////////////// .org $2080 loopxfunc .ds 1 .bss ;/////////////////////////////////////////////// .org $2100 ;stack area ;/////////////////////////////////////////////// .org $2200 ;----------------------------------------------- centerangle .ds 1 centerx .ds 4 centery .ds 4 centerxwork .ds 4 centerywork .ds 4 centerangletmp .ds 1 centerxtmp .ds 4 centerytmp .ds 4 centerlastangle .ds 1 ;--------------------- shipspeed .ds 2 ;--------------------- hitangle .ds 1 hitspeed .ds 2 ;--------------------- hitnumber .ds 1 hitlastnumber .ds 1 hitdatanumber .ds 1 hitanglework .ds 1 hitspeedwork .ds 1 ;--------------------- lapcheck .ds 1 lapcount .ds 1 ;--------------------- stageno .ds 1 ;--------------------- enemyangle .ds 1 enemyx .ds 4 enemyy .ds 4 enemyangletmp .ds 1 enemyxtmp .ds 4 enemyytmp .ds 4 enemyxwork .ds 4 enemyywork .ds 4 enemycalcxwork .ds 4 enemycalcywork .ds 4 enemyyindex .ds 1 enemyflag .ds 1 enemylocatex .ds 2 enemyspeed .ds 2 ;--------------------- stageinittmp .ds 1 ;--------------------- laptime .ds 3 laplasttime .ds 9 ;--------------------- framecount .ds 1 drawcount .ds 1 drawcountwork .ds 1 ;/////////////////////////////////////////////// .org $3D00 ;sprite work spritework .ds 64 * 8 ;/////////////////////////////////////////////// ;------- do not move for loopxfunc ------------- ;+++++++++++++++++++++++++++++++++++++++++++++++ .org $3F00 mapconv .ds 256 ;+++++++++++++++++++++++++++++++++++++++++++++++ ;----------------------------------------------- ;/////////////////////////////////////////////// .code .bank 0 .org $E000 ;---------------------------- main: ;initialize jsr init stz stageno stz <stageflag jsr stageinit ;set raster count st0 #$06 st1 #$80 st2 #$00 ;screen on ;bg sp vsync raster ;+1 st0 #$05 st1 #$CC st2 #$00 ;vsyncinterrupt start cli .mainloop: tii centerangle, centerangletmp, 9 ;enemy tii enemyangle, enemyangletmp, 9 ;put line process jsr putline ;enemy rotation ;enemyxwork = enemyxtmp - centerxtmp subq enemyxwork, enemyxtmp, centerxtmp ;enemyywork = enemyytmp - centerytmp subq enemyywork, enemyytmp, centerytmp ;x scale lsrq enemyxwork lsrq enemyxwork ;y scale lsrq enemyywork lsrq enemyywork ;X=xcosA-ysinA process movw <mul16an, enemyxwork+1 lda centerangletmp eor #$FF inc a tax lda cosdatalow,x sta <mul16bn lda cosdatahigh,x sta <mul16bn+1 jsr smul16n movq enemycalcxwork, <mul16cn movw <mul16an, enemyywork+1 lda centerangletmp eor #$FF inc a tax lda sindatalow,x sta <mul16bn lda sindatahigh,x sta <mul16bn+1 jsr smul16n subq enemycalcxwork, <mul16cn aslq enemycalcxwork aslq enemycalcxwork ;Y=xsinA+ycosA process movw <mul16an, enemyxwork+1 lda centerangletmp eor #$FF inc a tax lda sindatalow,x sta <mul16bn lda sindatahigh,x sta <mul16bn+1 jsr smul16n movq enemycalcywork, <mul16cn movw <mul16an, enemyywork+1 lda centerangletmp eor #$FF inc a tax lda cosdatalow,x sta <mul16bn lda cosdatahigh,x sta <mul16bn+1 jsr smul16n addq enemycalcywork, <mul16cn aslq enemycalcywork aslq enemycalcywork ;move to enemy_work movq enemyxwork, enemycalcxwork movq enemyywork, enemycalcywork ;enemy screen locate stz enemyyindex ;negative enemyywork negq enemyywork ;enemyywork = enemyywork + 1 clc lda enemyywork+2 adc #1 sta enemyywork+2 lda enemyywork+3 adc #0 sta enemyywork+3 lda enemyywork+3 bne .enemyjump02 lda enemyywork+2 cmp #55 bcs .enemyjump02 ;enemyywork+2 >= 55 sta enemyyindex lda enemyywork+1 asl a rol enemyyindex asl a rol enemyyindex ;x scale movw <mul16an, enemyxwork+1 lda enemyxwork+3 lsr a ror <mul16an+1 ror <mul16an lsr a ror <mul16an+1 ror <mul16an ldx enemyyindex lda enemyxconvlow,x sta <mul16bn lda enemyxconvhigh,x sta <mul16bn+1 jsr smul16n lda <mul16cn+1 asl a rol <mul16dn rol <mul16dn+1 asl a rol <mul16dn rol <mul16dn+1 asl a rol <mul16dn rol <mul16dn+1 asl a rol <mul16dn rol <mul16dn+1 aslw <mul16dn lda <mul16dn sta enemylocatex lda <mul16dn+1 inc a sta enemylocatex+1 bra .enemyjump00 .enemyjump02: lda #$FF sta enemyyindex ;enemy screen locate end .enemyjump00: ;stage select ;select check bbr7 <stageflag, .selectcheckend rmb7 <stageflag lda stageno inc a and #$01 sta stageno sei jsr stageinit cli .selectcheckend: ;set sprite ;clear sprite work stz spritework tii spritework, spritework+1, 16 * 8 - 1 lda #LOW(spritework) sta <spriteworkaddress lda #HIGH(spritework) sta <spriteworkaddress+1 ;ship lda #$00 sta <spritexwork lda #$01 sta <spritexwork+1 lda #$A0 sta <spriteywork lda #$00 sta <spriteywork+1 lda #$00 sta <spritenowork lda #$00 sta <spritenowork+1 jsr setsprite3 ;enemy ldx enemyyindex lda enemyyconv, x sta <spriteywork lda #$00 sta <spriteywork+1 movw <spritexwork, enemylocatex lda enemynoconv, x sta <spritenowork lda #$00 sta <spritenowork+1 jsr setsprite3 ;set sprite sei st0 #$00 st1 #$00 st2 #$30 st0 #$02 tia spritework, VDC_2, 8 * 16 cli ;SATB DMA set sei st0 #$13 st1 #$00 st2 #$30 cli ;increment draw count inc drawcount ;put data ;put data line 24 ;put draw count ldx #0 ldy #24 lda drawcountwork jsr puthex ;put ship centerx ldx #4 lda centerx+3 jsr puthex lda centerx+2 jsr puthex2 ;put ship centery ldx #10 lda centery+3 jsr puthex lda centery+2 jsr puthex2 ;put hit number ldx #16 lda hitnumber jsr puthex ;put ship speed ldx #20 lda shipspeed jsr puthex ;put ship centerangle ldx #24 lda centerangle jsr puthex ;put hit speed ldx #28 lda hitspeed jsr puthex ;put hit angle ldx #32 lda hitangle jsr puthex ;put enemyx ldx #36 lda enemyx+3 jsr puthex lda enemyx+2 jsr puthex2 ;put enemyy ldx #42 lda enemyy+3 jsr puthex lda enemyy+2 jsr puthex2 cli ;put enemyspeed ldx #48 lda enemyspeed jsr puthex ;put enemyangle ldx #52 lda enemyangle jsr puthex ;put data line 25 ;put lap count ldx #0 ldy #25 lda lapcount jsr puthex ;put lap check ldx #4 lda lapcheck jsr puthex ;put lap flag ldx #8 lda <lapflag jsr puthex ;put lap time ldx #12 lda laptime+2 jsr puthex lda #$27 jsr putchar2 lda laptime+1 jsr puthex2 lda #$22 jsr putchar2 ldx laptime lda secconv, x jsr puthex2 ;put lap last time0 ldx #22 lda laplasttime+2 jsr puthex lda #$27 jsr putchar2 lda laplasttime+1 jsr puthex2 lda #$22 jsr putchar2 ldx laplasttime lda secconv, x jsr puthex2 ;put data line 26 ;put lap last time1 ldx #22 ldy #26 lda laplasttime+5 jsr puthex lda #$27 jsr putchar2 lda laplasttime+4 jsr puthex2 lda #$22 jsr putchar2 ldx laplasttime+3 lda secconv, x jsr puthex2 ;put stage no ldx #0 lda stageno jsr puthex ;put data line 27 ;put lap last time2 ldx #22 ldy #27 lda laplasttime+8 jsr puthex lda #$27 jsr putchar2 lda laplasttime+7 jsr puthex2 lda #$22 jsr putchar2 ldx laplasttime+6 lda secconv, x jsr puthex2 ;jump mainloop jmp .mainloop ;---------------------------- 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 ;---------------------------- checkpadmove: ;select button check bbr2 <padstate, .selectbuttonend smb7 <stageflag .selectbuttonend: ;centerangle lda centerangle sta centerlastangle ;centerangle(0-255) Addition bbs7 <padnow, .jumppadleft bbs5 <padnow, .jumppadright bra .jumppadend .jumppadleft: dec centerangle dec centerangle bra .jumppadend .jumppadright: inc centerangle inc centerangle .jumppadend: ;ship spped ;add ship spped bbs0 <padnow, .shipspeed00 lda shipspeed beq .shipspeed01 dec a sta shipspeed bra .shipspeed01 .shipspeed00: inc shipspeed bne .shipspeed01 lda #$FF sta shipspeed .shipspeed01: ;sub ship spped bbr1 <padnow, .shipspeed03 lda shipspeed sec sbc #4 bcs .shipspeed02 cla .shipspeed02: sta shipspeed .shipspeed03: ;;--------------------------------------- ; ;stz <hitspeed ; lda <centerlastangle ; cmp <centerangle ; beq .shipspeed04 ; bcc .shipspeed05 ; ; clc ; adc #64 ; sta <hitangle ; lda <shipspeed ; lsr a ; lsr a ; ;lsr a ; sta <hitspeed ; bra .shipspeed04 ;.shipspeed05: ; sec ; sbc #64 ; sta <hitangle ; lda <shipspeed ; lsr a ; lsr a ; ;lsr a ; sta <hitspeed ;.shipspeed04: ;add movement centerx centery ldy centerangle ;add movement centerx ;centerx + sin lda sindatalow, y sta <mul16a lda sindatahigh, y sta <mul16a+1 movw <mul16b, shipspeed jsr smul16 addq centerxwork, centerx, <mul16c ;add movement centery ;centery - cos lda cosdatalow, y sta <mul16a lda cosdatahigh, y sta <mul16a+1 movw <mul16b, shipspeed jsr smul16 subq centerywork, centery, <mul16c ;sub hit spped lda hitspeed sec sbc #4 bcs .hitspeed02 cla .hitspeed02: sta hitspeed .hitspeed03: ;add hit movement centerx centery ldy hitangle ;add hit movement centerx ;centerx + sin lda sindatalow, y sta <mul16a lda sindatahigh, y sta <mul16a+1 mov <mul16b, hitspeed jsr smul16 addq centerxwork, <mul16c ;add movement centery ;centery - cos lda cosdatalow, y sta <mul16a lda cosdatahigh, y sta <mul16a+1 mov <mul16b, hitspeed jsr smul16 subq centerywork, <mul16c ;map hit number lda hitnumber sta hitlastnumber jsr maphit2 sta hitnumber ;lapcheck cmp #$02 ;dark green beq .lapcheckjump00 cmp #$06 ;dark cyan beq .lapcheckjump01 ;on other color lda hitlastnumber cmp #$02 ;dark green beq .lapcheckjump02 cmp #$06 ;dark cyan beq .lapcheckjump02 bra .lapcheckend .lapcheckjump02: lda lapcheck asl a asl a ora #$01 and #$3F sta lapcheck bra .lapcheckend ;on dark green .lapcheckjump00: lda hitlastnumber cmp #$02 ;dark green beq .lapcheckend lda lapcheck asl a asl a ora #$02 and #$3F sta lapcheck cmp #$36 bne .lapcheckend smb7 <lapflag bra .lapcheckend ;;on dark cyan .lapcheckjump01: lda hitlastnumber cmp #$06 ;dark cyan beq .lapcheckend lda lapcheck asl a asl a ora #$03 and #$3F sta lapcheck bbr7 <lapflag, .lapcheckend inc lapcount stz <lapflag ldx #8 .laptimemove: lda laptime,x sta laptime+3,x dex bpl .laptimemove stz laptime stz laptime+1 stz laptime+2 .lapcheckend: ;map effect check lda hitnumber cmp #$05 ;dark magenta beq .mapeffectjump000 cmp #$09 ;red beq .mapeffectjump001 cmp #$0F ;white beq .mapeffectjump001 bra .mapeffectend .mapeffectjump000: ldy shipspeed lda lsr4data, y sta <hitwork sec lda shipspeed sbc <hitwork sta shipspeed bra .mapeffectend .mapeffectjump001: ;slow down ldy shipspeed lda lsr4data, y lsr a lsr a sta <hitwork sec lda shipspeed sbc <hitwork sta shipspeed bra .mapeffectend .mapeffectend: ;map hit check lda hitnumber cmp #$00 ;black beq .maphitjump000 cmp #$0C ;blue beq .maphitjump000 ;cmp #$05 ;dark magenta ;cmp #$06 ;dark cyan ;cmp #$02 ;dark green ;cmp #$09 ;red ;cmp #$0F ;white ;beq .maphitjump000 movq centerx, centerxwork movq centery, centerywork jmp .maphitjump006 .maphitjump000: lda shipspeed cmp hitspeed bcs .maphitjump007 lda hitangle sta hitanglework lda hitspeed sta hitspeedwork bra .maphitjump008 .maphitjump007: lda centerangle sta hitanglework lda shipspeed sta hitspeedwork .maphitjump008: lda centerxwork+2 asl a and #$02 sta <hitwork lda centerywork+2 and #$01 ora <hitwork eor #$FF and #$03 sta <hitwork lda centerx+2 asl a and #$02 sta <hitwork+1 lda centery+2 and #$01 ora <hitwork+1 eor <hitwork sta <hitwork+1 beq .maphitjump005 cmp #$02 beq .maphitjump003 stz hitdatanumber lda #$80 sta <hitwork bra .maphitjump004 .maphitjump005: clc lda hitanglework adc #$80 bra .maphitjump001 .maphitjump003: lda #$40 sta hitdatanumber lda #$C0 sta <hitwork .maphitjump004: lda hitanglework cmp hitdatanumber bcc .maphitjump002 ;hitanglework < hitdatanumber cmp <hitwork bcs .maphitjump002 ;hitanglework >= hitwork lda hitdatanumber asl a sec sbc hitanglework bra .maphitjump001 .maphitjump002: lda <hitwork asl a sec sbc hitanglework .maphitjump001: sta hitangle lda hitspeedwork sta hitspeed stz shipspeed .maphitjump006: rts ;---------------------------- enemymove: ;enemy speed lda enemyspeed cmp #$E0 bcs .enemyspeedend ;enemyspeed >= $E0 inc a sta enemyspeed .enemyspeedend: ;move enemy lda enemyy+2 lsr a tay clc lda mapconv, y adc #8 ;add $10000(64K) tam #$04 tya and #$1F ora #$80 stz <hitwork sta <hitwork+1 lda enemyx+3 lsr a lda enemyx+2 ror a tay lda [hitwork], y sta enemyangle ;add movement enemyx enemyy ldy enemyangle ;add movement enemyx ;enemyx + sin lda sindatalow, y sta <mul16a lda sindatahigh, y sta <mul16a+1 movw <mul16b, enemyspeed jsr smul16 addq enemyx, <mul16c lda enemyx+3 and #$01 sta enemyx+3 ;add movement enemyy ;enemyy - cos lda cosdatalow, y sta <mul16a lda cosdatahigh, y sta <mul16a+1 movw <mul16b, enemyspeed jsr smul16 subq enemyy, <mul16c stz enemyy+3 rts ;---------------------------- stageinit: lda stageno asl a asl a asl a tax phx ;set mapconv lda #8 sta stageinittmp lda stagedata, x clx .setmapconvloop1: ldy #32 .setmapconvloop0: sta mapconv, x inx dey bne .setmapconvloop0 inc a dec stageinittmp bne .setmapconvloop1 ;set stage BAT st0 #$00 st1 #$00 st2 #$00 st0 #$02 clx .setbatloop0: lda bgdata00, x sta VDC_2 st2 #$02 inc a sta VDC_2 st2 #$02 inx bne .setbatloop0 ;set ship center plx stz centerx stz centerx+1 lda stagedata+1, x sta centerx+2 lda stagedata+2, x sta centerx+3 stz centery stz centery+1 lda stagedata+3, x sta centery+2 stz centery+3 ;set enemy center stz enemyx stz enemyx+1 lda stagedata+4, x sta enemyx+2 lda stagedata+5, x sta enemyx+3 stz enemyy stz enemyy+1 lda stagedata+6, x sta enemyy+2 stz enemyy+3 ;set ship angle lda stagedata+7, x sta centerangle ;set enemy angle sta enemyangle ;set ship speed stz shipspeed stz shipspeed+1 ;set enemy speed lda #$00 sta enemyspeed stz enemyspeed+1 ;set hit angle stz hitangle ;set hit speed stz hitspeed stz hitspeed+1 ;set hit number stz hitnumber ;set hit last number stz hitlastnumber ;set lap check stz lapcheck ;set lap flag stz <lapflag ;set lap count stz lapcount ;set lap time .setlaptimeloop: stz laptime, x inx cpx #12 bne .setlaptimeloop rts ;---------------------------- maphit2: ;x centerxwork+3 centerxwork+2 ;y centerywork+2 ldy centerywork+2 lda mapconv, y tam #$04 tya and #$1F ora #$80 stz <hitwork sta <hitwork+1 lda centerxwork+3 lsr a lda centerxwork+2 ror a tay lda [hitwork], y bcs .maphit2jump00 tay lda lsr4data, y .maphit2jump00: and #$0F rts ;---------------------------- smul16: ;mul16d:mul16c = mul16a * mul16b ;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 and #$80 beq .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: rts ;---------------------------- umul16: ;mul16d:mul16c = mul16a * mul16b lda <mul16a+1 ora <mul16b+1 bne .umul16jp02 jsr umul8 ;clear d stz <mul16d stz <mul16d+1 rts .umul16jp02: ;push x y phx phy ;b to d lda <mul16b sta <mul16d lda <mul16b+1 sta <mul16d+1 ;set counter ldy #16 .umul16jp04: ;clear c stz <mul16c stz <mul16c+1 ;umul16 loop .umul16jp00: ;left shift c and d asl <mul16c rol <mul16c+1 rol <mul16d rol <mul16d+1 bcc .umul16jp01 ;add a to c ldx #LOW(mul16c) clc set adc <mul16a inx set adc <mul16a+1 bcc .umul16jp01 ;inc d inc <mul16d bne .umul16jp01 inc <mul16d+1 .umul16jp01: dey bne .umul16jp00 ;pull y x ply plx rts ;---------------------------- umul8: ;mul16c = mul16a * mul16b (8bit * 8bit) ;push x y phx phy ;b to c lda <mul16b sta <mul16c+1 ;clear a cla ;set counter ldy #8 ;umul8 loop .umul8jp00: ;left shift a asl a rol <mul16c+1 bcc .umul8jp01 ;add a to c clc adc <mul16a bcc .umul8jp01 ;inc c inc <mul16c+1 .umul8jp01: dey bne .umul8jp00 sta <mul16c ;pull y x ply plx rts ;---------------------------- smul16n: ;mul16dn:mul16cn = mul16an * mul16bn ;push x phx ;a eor b sign lda <mul16an+1 eor <mul16bn+1 pha ;a sign bbr7 <mul16an+1, .smul16njp00 ;a neg sec lda <mul16an eor #$FF adc #0 sta <mul16an lda <mul16an+1 eor #$FF adc #0 sta <mul16an+1 .smul16njp00: ;b sign bbr7 <mul16bn+1, .smul16njp01 ;b neg sec lda <mul16bn eor #$FF adc #0 sta <mul16bn lda <mul16bn+1 eor #$FF adc #0 sta <mul16bn+1 .smul16njp01: jsr umul16n ;anser sign pla and #$80 beq .smul16njp02 ;anser neg sec lda <mul16cn eor #$FF adc #0 sta <mul16cn lda <mul16cn+1 eor #$FF adc #0 sta <mul16cn+1 lda <mul16dn eor #$FF adc #0 sta <mul16dn lda <mul16dn+1 eor #$FF adc #0 sta <mul16dn+1 .smul16njp02: ;pull x plx rts ;---------------------------- umul16n: ;mul16dn:mul16cn = mul16an * mul16bn lda <mul16an+1 ora <mul16bn+1 bne .umul16njp02 jsr umul8n ;clear d stz <mul16dn stz <mul16dn+1 rts .umul16njp02: ;push x y phx phy ;b to d lda <mul16bn sta <mul16dn lda <mul16bn+1 sta <mul16dn+1 ;set counter ldy #16 .umul16njp04: ;clear c stz <mul16cn stz <mul16cn+1 ;umul16n loop .umul16njp00: ;left shift c and d asl <mul16cn rol <mul16cn+1 rol <mul16dn rol <mul16dn+1 bcc .umul16njp01 ;add a to c ldx #LOW(mul16cn) clc set adc <mul16an inx set adc <mul16an+1 bcc .umul16njp01 ;inc d inc <mul16dn bne .umul16njp01 inc <mul16dn+1 .umul16njp01: dey bne .umul16njp00 ;pull y x ply plx rts ;---------------------------- umul8n: ;mul16cn = mul16an * mul16bn (8bit * 8bit) ;push x y phx phy ;b to c lda <mul16bn sta <mul16cn+1 ;clear a cla ;set counter ldy #8 ;umul8 loop .umul8njp00: ;left shift a asl a rol <mul16cn+1 bcc .umul8njp01 ;add a to c clc adc <mul16an bcc .umul8njp01 ;inc c inc <mul16cn+1 .umul8njp01: dey bne .umul8njp00 sta <mul16cn ;pull y x ply plx 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 ;---------------------------- makechar: phx phy clx pha and #$01 beq .makecharjp01 ldx #$FF .makecharjp01: cly pla and #$02 beq .makecharjp02 ldy #$FF .makecharjp02: stx VDC_2 sty VDC_3 stx VDC_2 sty VDC_3 stx VDC_2 sty VDC_3 stx VDC_2 sty VDC_3 ply plx rts ;---------------------------- setvramaddress: stz <puthexaddr sty <puthexaddr+1 lsr <puthexaddr+1 ror <puthexaddr lsr <puthexaddr+1 ror <puthexaddr txa ora <puthexaddr sta <puthexaddr sei st0 #$00 lda <puthexaddr sta VDC_2 lda <puthexaddr+1 sta VDC_3 cli rts ;---------------------------- putchar2: sei st0 #$02 sta VDC_2 st2 #$02 cli rts ;---------------------------- putchar: pha phx phy sta <puthexdata stz <puthexaddr sty <puthexaddr+1 lsr <puthexaddr+1 ror <puthexaddr lsr <puthexaddr+1 ror <puthexaddr txa ora <puthexaddr sta <puthexaddr sei st0 #$00 ldy <puthexaddr sty VDC_2 ldy <puthexaddr+1 sty VDC_3 st0 #$02 lda <puthexdata sta VDC_2 st2 #$02 cli ply plx pla rts ;---------------------------- puthex2: pha phx phy sta <puthexdata ldx <puthexdata lda lsr4data, x jsr numtochar tax lda <puthexdata and #$0F jsr numtochar sei st0 #$02 stx VDC_2 st2 #$02 sta VDC_2 st2 #$02 cli ply plx pla rts ;---------------------------- puthex: pha phx phy sta <puthexdata stz <puthexaddr sty <puthexaddr+1 lsr <puthexaddr+1 ror <puthexaddr lsr <puthexaddr+1 ror <puthexaddr txa ora <puthexaddr sta <puthexaddr ldx <puthexdata lda lsr4data, x jsr numtochar tax lda <puthexdata and #$0F jsr numtochar sei st0 #$00 ldy <puthexaddr sty VDC_2 ldy <puthexaddr+1 sty VDC_3 st0 #$02 stx VDC_2 st2 #$02 sta VDC_2 st2 #$02 cli ply plx pla rts ;---------------------------- setsprite3: ldx <spritenowork lda shipdataindex, x sta <spritenowork lda shipdataindex+1, x sta <spritenowork+1 cly lda [spritenowork], y tax .spset3loop: ;sprite y iny clc lda [spritenowork], y adc <spriteywork sta <spritexywork iny lda [spritenowork], y adc <spriteywork+1 sta <spritexywork+1 cmp #$04 bcc .spset3jump00 ; < $04 stz <spritexywork stz <spritexywork+1 .spset3jump00: lda <spritexywork sta [spriteworkaddress] lda <spritexywork+1 inc <spriteworkaddress sta [spriteworkaddress] ;sprite x iny clc lda [spritenowork], y adc <spritexwork sta <spritexywork iny lda [spritenowork], y adc <spritexwork+1 sta <spritexywork+1 cmp #$04 bcc .spset3jump01 ; < $04 stz <spritexywork stz <spritexywork+1 .spset3jump01: lda <spritexywork inc <spriteworkaddress sta [spriteworkaddress] lda <spritexywork+1 inc <spriteworkaddress sta [spriteworkaddress] ;sprite no iny lda [spritenowork], y inc <spriteworkaddress sta [spriteworkaddress] iny lda [spritenowork], y inc <spriteworkaddress sta [spriteworkaddress] ;sprite attribute iny lda [spritenowork], y inc <spriteworkaddress sta [spriteworkaddress] iny lda [spritenowork], y inc <spriteworkaddress sta [spriteworkaddress] inc <spriteworkaddress bne .spset3jump02 inc <spriteworkaddress+1 .spset3jump02: dex bne .spset3loop rts ;---------------------------- init: ;reset wait cly .resetWaitloop0: clx .resetWaitloop1: dex bne .resetWaitloop1 dey bne .resetWaitloop0 cly vdpdataloop: lda vdpdata, y cmp #$FF beq vdpdataend sta VDC_0 iny lda vdpdata, y sta VDC_2 iny lda vdpdata, y sta VDC_3 iny bra vdpdataloop vdpdataend: ;disable interrupts TIQD IRQ2D lda #$05 sta INT_DIS_REG ;262Line VCE Clock 10MHz lda #$06 sta VCE_0 stz VCE_1 ;palette stz VCE_2 stz VCE_3 tia bgpalettedata, VCE_4, $60 stz VCE_2 lda #$01 sta VCE_3 tia sppalettedata, VCE_4, $20 ;clear BAT st0 #$00 st1 #$00 st2 #$00 st0 #$02 ldy #64 .clearbatloop0: ldx #64 .clearbatloop1: st1 #$00 st2 #$02 dex bne .clearbatloop1 dey bne .clearbatloop0 ;CHAR set to vram lda #charBank tam #$02 ;vram address $2000 st0 #$00 st1 #$00 st2 #$20 st0 #$02 tia $4000, VDC_2, $2000 ;Sprite CHAR set to vram lda #shipBank tam #$02 ;vram address $4000 st0 #$00 st1 #$00 st2 #$40 st0 #$02 tia $4000, VDC_2, $2000 ;make char ;vram address $1000 st0 #$00 st1 #$00 st2 #$10 st0 #$02 ldy #$00 .makecharloop00: ldx #$00 .makecharloop01: txa and #$03 jsr makechar tya and #$03 jsr makechar txa lsr a lsr a jsr makechar tya lsr a lsr a jsr makechar inx cpx #$10 bne .makecharloop01 iny cpy #$10 bne .makecharloop00 ;clear zeropage stz $2000 tii $2000, $2001, $00FF ;clear Sprite abt vram stz $2200 tii $2200, $2201, $01FF st0 #$00 st1 #$00 st2 #$30 st0 #$02 tia $2200, VDC_2, 512 ;clear sprite work stz spritework tii spritework, spritework+1, 64 * 8 - 1 ;loopxfunc set tii loopxfuncdata, loopxfunc, 122 ;set code bank6 lda #$01 tam #$06 ;initialize psg jsr psginit rts ;---------------------------- _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 ;---------------------------- _irq1: ;IRQ1 interrupt process pha phx phy ;ACK interrupt lda VDC_0 sta <vdpstatus bbs5 <vdpstatus, .vsyncproc ;raster st0 #$07 st1 #$00 st2 #$00 jmp .irq1end .vsyncproc: ;psg process jsr psgrun ;lap time sed clc lda laptime adc #1 sta laptime cmp #$60 bne .laptimeend stz laptime clc lda laptime+1 adc #1 sta laptime+1 cmp #$60 bne .laptimeend stz laptime+1 clc lda laptime+2 adc #1 sta laptime+2 .laptimeend: cld ;scrool x set 0 lda centerangletmp stz <scrollxwork asl a rol <scrollxwork asl a rol <scrollxwork asl a rol <scrollxwork st0 #$07 sta VDC_2 lda <scrollxwork and #$01 sta VDC_3 ;frame count lda framecount inc a sta framecount cmp #60 bne .framecountend lda drawcount sta drawcountwork ;count set 0 stz framecount stz drawcount .framecountend: jsr getpaddata jsr checkpadmove jsr enemymove .irq1end: st0 #$02 ply plx pla rti ;---------------------------- _irq2: _timer: _nmi: ;IRQ2 TIMER NMI interrupt process rti ;---------------------------- stagedata: .db $14, 176, 0, 38, 176, 0, 42, 64 ;BANKNo, ShipXLow, ShipXHigh, ShipY, EnemyXLow, EnemyXHigh, EnemyY, Angle .db $20, 180, 0, 16, 180, 0, 20, 64 ;---------------------------- secconv: .db $00, $02, $03, $05, $07, $08, $10, $12, $13, $15, $00, $00, $00, $00, $00, $00,\ $17, $18, $20, $22, $23, $25, $27, $28, $30, $32, $00, $00, $00, $00, $00, $00,\ $33, $35, $37, $38, $40, $42, $43, $45, $47, $48, $00, $00, $00, $00, $00, $00,\ $50, $52, $53, $55, $57, $58, $60, $62, $63, $65, $00, $00, $00, $00, $00, $00,\ $67, $68, $70, $72, $73, $75, $77, $78, $80, $82, $00, $00, $00, $00, $00, $00,\ $83, $85, $87, $88, $90, $92, $93, $95, $97, $98, $00, $00, $00, $00, $00, $00 ;---------------------------- bgdata00: .db $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02 .db $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02 .db $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02 .db $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02 .db $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02 .db $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02 .db $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04 .db $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04 .db $06, $06, $06, $06, $06, $06, $06, $06, $06, $06, $06, $06, $06, $06, $06, $06 .db $06, $06, $06, $06, $06, $06, $06, $06, $06, $06, $06, $06, $06, $06, $06, $06 .db $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08 .db $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08 .db $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $14, $18 .db $14, $18, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $0A .db $0C, $0C, $0E, $0C, $0E, $0E, $0C, $0E, $0C, $0E, $0C, $10, $10, $10, $12, $16 .db $12, $16, $10, $10, $0C, $0C, $0E, $0C, $0C, $0E, $0C, $0C, $0C, $0C, $0E, $0E ;---------------------------- enemynoconv .db $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\ $00, $00, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02,\ $02, $02, $02, $02, $02, $02, $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, $04, $04, $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, $06, $06, $06, $06, $06, $06, $06, $06,\ $06, $06, $06, $06, $06, $06, $06, $06, $06, $06, $06, $06, $06, $06, $06, $06,\ $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,\ $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,\ $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08,\ $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\ $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\ $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00 ;---------------------------- enemyxconvlow .db $C4, $89, $4D, $12, $D6, $9B, $5F, $24, $E8, $AD, $90, $72, $36, $19, $FB, $DD,\ $BF, $A2, $84, $66, $48, $2B, $0D, $F9, $E5, $D1, $BE, $AA, $96, $87, $78, $69,\ $5A, $4C, $3D, $2E, $1F, $16, $0C, $02, $F8, $EE, $DA, $D0, $C6, $BC, $B2, $A8,\ $9D, $95, $8D, $85, $7D, $75, $6D, $68, $60, $59, $51, $49, $41, $39, $31, $2C,\ $26, $20, $1A, $14, $0E, $08, $02, $FC, $F6, $F1, $EC, $E7, $E2, $DA, $D8, $D3,\ $CE, $C9, $C4, $BF, $BC, $BA, $B7, $B3, $AF, $AB, $A7, $A3, $9F, $9B, $97, $93,\ $8F, $8B, $87, $83, $7F, $7C, $79, $76, $74, $73, $70, $6D, $6B, $6A, $67, $64,\ $62, $61, $5E, $5B, $59, $58, $55, $52, $4F, $4D, $4C, $49, $46, $43, $42, $40,\ $3E, $3C, $3A, $38, $36, $35, $34, $32, $30, $2E, $2C, $2A, $28, $27, $26, $24,\ $24, $22, $20, $1E, $1C, $1A, $18, $16, $14, $12, $10, $0E, $0C, $0A, $08, $07,\ $06, $05, $04, $03, $02, $01, $00, $FF, $FE, $FD, $FC, $FB, $FA, $F9, $F8, $F7,\ $F6, $F5, $F4, $F3, $F2, $F1, $F0, $EF, $EE, $ED, $EC, $EB, $EA, $E9, $E8, $E7,\ $E6, $E5, $E4, $E3, $E2, $E1, $E0, $DF, $DE, $DD, $DC, $DB, $DA, $D9, $D8, $D7,\ $D6, $D5, $D4, $D3, $D2, $D1, $D0, $CF, $CE, $CD, $CC, $CC, $00, $00, $00, $00,\ $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\ $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00 ;---------------------------- enemyxconvhigh .db $07, $07, $07, $07, $06, $06, $06, $06, $05, $05, $05, $05, $05, $05, $04, $04,\ $04, $04, $04, $04, $04, $04, $04, $03, $03, $03, $03, $03, $03, $03, $03, $03,\ $03, $03, $03, $03, $03, $03, $03, $03, $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, $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, $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, $00, $00, $00, $00, $00, $00, $00, $00, $00,\ $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\ $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\ $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\ $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\ $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00 ;---------------------------- enemyyconv .db $B0, $AC, $A8, $A4, $A0, $9C, $98, $94, $92, $90, $8C, $8A, $88, $86, $84, $82, \ $80, $7E, $7C, $7A, $78, $76, $75, $74, $72, $71, $70, $6F, $6E, $6D, $6C, $6B, \ $6A, $69, $68, $67, $66, $65, $64, $64, $63, $62, $61, $61, $60, $60, $5F, $5E, \ $5E, $5D, $5D, $5C, $5C, $5B, $5B, $5A, $5A, $59, $59, $58, $58, $57, $57, $56, \ $56, $55, $55, $55, $54, $54, $54, $53, $53, $53, $52, $52, $52, $51, $51, $51, \ $50, $50, $50, $50, $4F, $4F, $4F, $4E, $4E, $4E, $4E, $4D, $4D, $4D, $4D, $4C, \ $4C, $4C, $4C, $4B, $4B, $4B, $4B, $4B, $4B, $4A, $4A, $4A, $4A, $4A, $4A, $49, \ $49, $49, $49, $49, $49, $48, $48, $48, $48, $48, $48, $48, $47, $47, $47, $47, \ $47, $47, $47, $46, $46, $46, $46, $46, $46, $46, $46, $46, $46, $45, $45, $45, \ $45, $45, $45, $45, $45, $44, $44, $44, $44, $44, $44, $44, $44, $43, $43, $43, \ $43, $43, $43, $43, $43, $43, $43, $42, $42, $42, $42, $42, $42, $42, $42, $42, \ $42, $41, $41, $41, $41, $41, $41, $41, $41, $41, $41, $40, $40, $40, $40, $40, \ $40, $40, $40, $40, $40, $40, $40, $40, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, \ $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, \ $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, \ $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF ;---------------------------- shipdataindex: .dw shipdata00 .dw shipdata01 .dw shipdata02 .dw shipdata03 .dw shipdata04 shipdata00: .db 8 .dw $0030 ;64 - 16 .dw $FFF0 ;32 - 64 + 16 .dw $0200 ;No 0 .dw $1080 ;Y 2CGY X 1CGX SP COLOR0 .dw $0030 ;64 - 16 .dw $0000 ;32 - 32 .dw $0208 ;No 4 .dw $1180 ;Y 2CGY X 2CGX SP COLOR0 .dw $0030 ;64 - 16 .dw $0020 ;32 .dw $0208 ;No 4 .dw $1980 ;Y 2CGY ~X 2CGX SP COLOR0 .dw $0030 ;64 - 16 .dw $0040 ;32 + 32 .dw $0200 ;No 0 .dw $1880 ;Y 2CGY ~X 1CGX SP COLOR0 .dw $0048 ;64 - 16 + 16 + 8 .dw $FFE0 ;32 - 64 .dw $0210 ;No 8 .dw $0180 ;Y 1CGY X 2CGX SP COLOR0 .dw $0048 ;64 - 16 + 16 + 8 .dw $0000 ;32 - 32 .dw $0214 ;No 10 .dw $0180 ;Y 1CGY X 2CGX SP COLOR0 .dw $0048 ;64 + 128 + 32 - 16 + 16 + 8 .dw $0020 ;32 .dw $0214 ;No 10 .dw $8980 ;~Y 1CGY ~X 2CGX SP COLOR0 .dw $0048 ;64 - 16 + 16 + 8 .dw $0040 ;32 + 32 .dw $0210 ;No 8 .dw $8980 ;~Y 1CGY ~X 2CGX SP COLOR0 shipdata01: .db 4 .dw $0040 ;64 - 16 + 16 .dw $FFF0 ;32 - 64 + 16 .dw $0202 ;No 1 .dw $0080 ;Y 1CGY X 1CGX SP COLOR0 .dw $0030 ;64 - 16 .dw $0000 ;32 - 32 .dw $0228 ;No 20 .dw $1180 ;Y 2CGY X 2CGX SP COLOR0 .dw $0030 ;64 - 16 .dw $0020 ;32 .dw $0228 ;No 20 .dw $1980 ;Y 2CGY ~X 2CGX SP COLOR0 .dw $0040 ;64 - 16 + 16 .dw $0040 ;32 + 32 .dw $0202 ;No 1 .dw $0880 ;Y 1CGY ~X 1CGX SP COLOR0 shipdata02: .db 2 .dw $0030 ;64 - 16 .dw $0000 ;32 - 32 .dw $0220 ;No 16 .dw $1180 ;Y 2CGY X 2CGX SP COLOR0 .dw $0030 ;64 - 16 .dw $0020 ;32 .dw $0220 ;No 16 .dw $1980 ;Y 2CGY ~X 2CGX SP COLOR0 shipdata03: .db 2 .dw $0038 ;64 - 8 .dw $0010 ;32 - 16 .dw $0206 ;No 3 .dw $0080 ;Y 1CGY X 1CGX SP COLOR0 .dw $0038 ;64 - 8 .dw $0020 ;32 .dw $0206 ;No 3 .dw $0880 ;Y 1CGY ~X 1CGX SP COLOR0 shipdata04: .db 1 .dw $0038 ;64 - 8 .dw $0018 ;32 - 8 .dw $0230 ;No 24 .dw $0080 ;Y 1CGY X 1CGX SP COLOR0 ;---------------------------- vdpdata: .db $05, $00, $00 ;screen off .db $0A, $02, $0B ;HSW $02 HDS $0B .db $0B, $3F, $04 ;HDW $3F HDE $04 .db $0C, $02, $0D ;VSW $02 VDS $0D .db $0D, $EF, $00 ;VDW $00EF .db $0E, $03, $00 ;VCR $03 .db $07, $00, $00 ;scrollx 0 .db $08, $00, $00 ;scrolly 0 .db $09, $50, $00 ;64x64 .db $FF ;end ;---------------------------- linebgpalettedata: .db $21, $00, $11, $00, $01, $00, $01, $00, $01, $00, $01, $00, $01, $00, $01, $00,\ $01, $00, $01, $00, $01, $00, $01, $00, $01, $00, $01, $00, $01, $00, $01, $00 ;---------------------------- bgpalettedata: .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF .dw $0049, $0061, $0109, $0121, $004C, $0064, $010C, $016D,\ $01B6, $00BA, $01D2, $01FA, $0097, $00BF, $01D7, $01FF .dw $00DB, $00E3, $011B, $0123, $00DC, $00E4, $011C, $01B6,\ $01FF, $013C, $01E4, $01FC, $0127, $013F, $01E7, $01FF ;---------------------------- sppalettedata: .dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\ $01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF ;---------------------------- sindatalow: .db $00, $06, $0D, $13, $19, $1F, $26, $2C, $32, $38, $3E, $44, $4A, $50, $56, $5C,\ $62, $68, $6D, $73, $79, $7E, $84, $89, $8E, $93, $98, $9D, $A2, $A7, $AC, $B1,\ $B5, $B9, $BE, $C2, $C6, $CA, $CE, $D1, $D5, $D8, $DC, $DF, $E2, $E5, $E7, $EA,\ $ED, $EF, $F1, $F3, $F5, $F7, $F8, $FA, $FB, $FC, $FD, $FE, $FF, $FF, $00, $00,\ $00, $00, $00, $FF, $FF, $FE, $FD, $FC, $FB, $FA, $F8, $F7, $F5, $F3, $F1, $EF,\ $ED, $EA, $E7, $E5, $E2, $DF, $DC, $D8, $D5, $D1, $CE, $CA, $C6, $C2, $BE, $B9,\ $B5, $B1, $AC, $A7, $A2, $9D, $98, $93, $8E, $89, $84, $7E, $79, $73, $6D, $68,\ $62, $5C, $56, $50, $4A, $44, $3E, $38, $32, $2C, $26, $1F, $19, $13, $0D, $06,\ $00, $FA, $F3, $ED, $E7, $E1, $DA, $D4, $CE, $C8, $C2, $BC, $B6, $B0, $AA, $A4,\ $9E, $98, $93, $8D, $87, $82, $7C, $77, $72, $6D, $68, $63, $5E, $59, $54, $4F,\ $4B, $47, $42, $3E, $3A, $36, $32, $2F, $2B, $28, $24, $21, $1E, $1B, $19, $16,\ $13, $11, $0F, $0D, $0B, $09, $08, $06, $05, $04, $03, $02, $01, $01, $00, $00,\ $00, $00, $00, $01, $01, $02, $03, $04, $05, $06, $08, $09, $0B, $0D, $0F, $11,\ $13, $16, $19, $1B, $1E, $21, $24, $28, $2B, $2F, $32, $36, $3A, $3E, $42, $47,\ $4B, $4F, $54, $59, $5E, $63, $68, $6D, $72, $77, $7C, $82, $87, $8D, $93, $98,\ $9E, $A4, $AA, $B0, $B6, $BC, $C2, $C8, $CE, $D4, $DA, $E1, $E7, $ED, $F3, $FA ;---------------------------- sindatahigh: .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, $01, $01,\ $01, $01, $01, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\ $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\ $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\ $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\ $00, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\ $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\ $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\ $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\ $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\ $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\ $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\ $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF ;---------------------------- cosdatalow: .db $00, $00, $00, $FF, $FF, $FE, $FD, $FC, $FB, $FA, $F8, $F7, $F5, $F3, $F1, $EF,\ $ED, $EA, $E7, $E5, $E2, $DF, $DC, $D8, $D5, $D1, $CE, $CA, $C6, $C2, $BE, $B9,\ $B5, $B1, $AC, $A7, $A2, $9D, $98, $93, $8E, $89, $84, $7E, $79, $73, $6D, $68,\ $62, $5C, $56, $50, $4A, $44, $3E, $38, $32, $2C, $26, $1F, $19, $13, $0D, $06,\ $00, $FA, $F3, $ED, $E7, $E1, $DA, $D4, $CE, $C8, $C2, $BC, $B6, $B0, $AA, $A4,\ $9E, $98, $93, $8D, $87, $82, $7C, $77, $72, $6D, $68, $63, $5E, $59, $54, $4F,\ $4B, $47, $42, $3E, $3A, $36, $32, $2F, $2B, $28, $24, $21, $1E, $1B, $19, $16,\ $13, $11, $0F, $0D, $0B, $09, $08, $06, $05, $04, $03, $02, $01, $01, $00, $00,\ $00, $00, $00, $01, $01, $02, $03, $04, $05, $06, $08, $09, $0B, $0D, $0F, $11,\ $13, $16, $19, $1B, $1E, $21, $24, $28, $2B, $2F, $32, $36, $3A, $3E, $42, $47,\ $4B, $4F, $54, $59, $5E, $63, $68, $6D, $72, $77, $7C, $82, $87, $8D, $93, $98,\ $9E, $A4, $AA, $B0, $B6, $BC, $C2, $C8, $CE, $D4, $DA, $E1, $E7, $ED, $F3, $FA,\ $00, $06, $0D, $13, $19, $1F, $26, $2C, $32, $38, $3E, $44, $4A, $50, $56, $5C,\ $62, $68, $6D, $73, $79, $7E, $84, $89, $8E, $93, $98, $9D, $A2, $A7, $AC, $B1,\ $B5, $B9, $BE, $C2, $C6, $CA, $CE, $D1, $D5, $D8, $DC, $DF, $E2, $E5, $E7, $EA,\ $ED, $EF, $F1, $F3, $F5, $F7, $F8, $FA, $FB, $FC, $FD, $FE, $FF, $FF, $00, $00 ;---------------------------- cosdatahigh: .db $01, $01, $01, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\ $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\ $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\ $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\ $00, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\ $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\ $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\ $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\ $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\ $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\ $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\ $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, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\ $00, $00, $00, $00, $00, $00, $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 ;------- do not move for loopxfunc ------------- ;+++++++++++++++++++++++++++++++++++++++++++++++ .org $FC00 asl4data: .db $00, $10, $20, $30, $40, $50, $60, $70, $80, $90, $A0, $B0, $C0, $D0, $E0, $F0,\ $00, $10, $20, $30, $40, $50, $60, $70, $80, $90, $A0, $B0, $C0, $D0, $E0, $F0,\ $00, $10, $20, $30, $40, $50, $60, $70, $80, $90, $A0, $B0, $C0, $D0, $E0, $F0,\ $00, $10, $20, $30, $40, $50, $60, $70, $80, $90, $A0, $B0, $C0, $D0, $E0, $F0,\ $00, $10, $20, $30, $40, $50, $60, $70, $80, $90, $A0, $B0, $C0, $D0, $E0, $F0,\ $00, $10, $20, $30, $40, $50, $60, $70, $80, $90, $A0, $B0, $C0, $D0, $E0, $F0,\ $00, $10, $20, $30, $40, $50, $60, $70, $80, $90, $A0, $B0, $C0, $D0, $E0, $F0,\ $00, $10, $20, $30, $40, $50, $60, $70, $80, $90, $A0, $B0, $C0, $D0, $E0, $F0,\ $00, $10, $20, $30, $40, $50, $60, $70, $80, $90, $A0, $B0, $C0, $D0, $E0, $F0,\ $00, $10, $20, $30, $40, $50, $60, $70, $80, $90, $A0, $B0, $C0, $D0, $E0, $F0,\ $00, $10, $20, $30, $40, $50, $60, $70, $80, $90, $A0, $B0, $C0, $D0, $E0, $F0,\ $00, $10, $20, $30, $40, $50, $60, $70, $80, $90, $A0, $B0, $C0, $D0, $E0, $F0,\ $00, $10, $20, $30, $40, $50, $60, $70, $80, $90, $A0, $B0, $C0, $D0, $E0, $F0,\ $00, $10, $20, $30, $40, $50, $60, $70, $80, $90, $A0, $B0, $C0, $D0, $E0, $F0,\ $00, $10, $20, $30, $40, $50, $60, $70, $80, $90, $A0, $B0, $C0, $D0, $E0, $F0,\ $00, $10, $20, $30, $40, $50, $60, $70, $80, $90, $A0, $B0, $C0, $D0, $E0, $F0 ;---------------------------- .org $FD00 lsr4data: .db $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,\ $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,\ $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,\ $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,\ $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,\ $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,\ $0C, $0C, $0C, $0C, $0C, $0C, $0C, $0C, $0C, $0C, $0C, $0C, $0C, $0C, $0C, $0C,\ $0D, $0D, $0D, $0D, $0D, $0D, $0D, $0D, $0D, $0D, $0D, $0D, $0D, $0D, $0D, $0D,\ $0E, $0E, $0E, $0E, $0E, $0E, $0E, $0E, $0E, $0E, $0E, $0E, $0E, $0E, $0E, $0E,\ $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F ;---------------------------- .org $FE00 mapconvaddr: .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 ;+++++++++++++++++++++++++++++++++++++++++++++++ ;----------------------------------------------- .org $FF00 ;---------------------------- loopxfuncdata: .db $A0, $40, $A6, $05, $BD, $00, $3F, $53, $04, $BD, $00, $FE, $85, $92, $A6, $02,\ $BD, $00, $00, $FF, $01, $04, $AA, $BD, $00, $FD, $29, $0F, $85, $B9, $A6, $0B,\ $BD, $00, $3F, $53, $04, $BD, $00, $FE, $85, $AE, $A6, $08, $BD, $00, $00, $7F,\ $07, $04, $AA, $BD, $00, $FC, $29, $F0, $09, $00, $78, $8D, $02, $00, $23, $01,\ $58, $A2, $00, $18, $F4, $69, $00, $E8, $F4, $69, $00, $E8, $F4, $69, $00, $E8,\ $18, $F4, $69, $00, $E8, $F4, $69, $00, $E8, $F4, $69, $00, $E8, $18, $F4, $69,\ $00, $E8, $F4, $69, $00, $E8, $F4, $69, $00, $E8, $18, $F4, $69, $00, $E8, $F4,\ $69, $00, $E8, $F4, $69, $00, $88, $D0, $89, $60 ;---------------------------- vramaddrconv: .dw $0200, $0240, $0280, $02C0, $0300, $0340, $0380, $03C0,\ $0400, $0440, $0480, $04C0, $0500, $0540, $0580, $05C0 ;---------------------------- ;interrupt vectors .org $FFF6 .dw _irq2 .dw _irq1 .dw _timer .dw _nmi .dw _reset ;/////////////////////////////////////////////// .code .bank 1 .org $C000 ;---------------------------- putline: ;put line process ;centerangletmp centerxtmp centerytmp ;initialize line counter clx ;set x y sin cos data ;set x y sin cos data address ;256angle * 32line * 16byte[x(4byte), y(4byte), sin(4byte), cos(4byte)] stz <calclineptr lda centerangletmp asl a and #$1F clc adc #$60 sta <calclineptr+1 ldy centerangletmp lda lsr4data, y inc a inc a tam #$03 ;put line loop .calcloop: ;set line bg palette lda linebgpalettedata, x sta <$BF ;loopfunc addr $BF ;set VRAM address sei st0 #$00 lda vramaddrconv, x sta VDC_2 lda vramaddrconv+1, x sta VDC_3 st0 #$02 cli ;calculate high line ;set x0a y0a ;X=xcosA-ysinA X+=centerx process clc cly lda [calclineptr], y adc centerxtmp sta <x0a iny lda [calclineptr], y adc centerxtmp+1 sta <x0a+1 iny lda [calclineptr], y adc centerxtmp+2 sta <x0a+2 iny lda [calclineptr], y adc centerxtmp+3 ;sta <??? lsr a ror <x0a+2 ror <x0a+1 ror <x0a ;Y=xsinA+ycosA Y+=centery process clc ldy #$04 lda [calclineptr], y adc centerytmp sta <y0a iny lda [calclineptr], y adc centerytmp+1 sta <y0a+1 iny lda [calclineptr], y adc centerytmp+2 sta <y0a+2 ;iny ;lda [calclineptr], y ;adc centerytmp+3 ;sta <??? ;set loopxfunc sin0 cos0 ;sin0 ldy #$08 lda [calclineptr], y sta <$D3 ;loopfunc addr $D3 iny lda [calclineptr], y sta <$D7 ;loopfunc addr $D7 iny lda [calclineptr], y sta <$DB ;loopfunc addr $DB ;cos0 ldy #$0C lda [calclineptr], y sta <$C6 ;loopfunc addr $C6 iny lda [calclineptr], y sta <$CA ;loopfunc addr $CA iny lda [calclineptr], y cmp #$80 ror a sta <$CE ;loopfunc addr $CE ror <$CA ror <$C6 ;increment calclinecounter inx ;calculate low line ;set x1a y1a ;X=xcosA-ysinA X+=centerx process clc ldy #$10 lda [calclineptr], y adc centerxtmp sta <x1a iny lda [calclineptr], y adc centerxtmp+1 sta <x1a+1 iny lda [calclineptr], y adc centerxtmp+2 sta <x1a+2 iny lda [calclineptr], y adc centerxtmp+3 ;sta <??? lsr a ror <x1a+2 ror <x1a+1 ror <x1a ;Y=xsinA+ycosA Y+=centery process clc ldy #$14 lda [calclineptr], y adc centerytmp sta <y1a iny lda [calclineptr], y adc centerytmp+1 sta <y1a+1 iny lda [calclineptr], y adc centerytmp+2 sta <y1a+2 ;iny ;lda [calclineptr], y ;adc centerytmp+3 ;sta <??? ;set loopxfunc sin1 cos1 ;sin1 ldy #$18 lda [calclineptr], y sta <$ED ;loopfunc addr $ED iny lda [calclineptr], y sta <$F1 ;loopfunc addr $F1 iny lda [calclineptr], y sta <$F5 ;loopfunc addr $F5 ;cos1 ldy #$1C lda [calclineptr], y sta <$E0 ;loopfunc addr $E0 iny lda [calclineptr], y sta <$E4 ;loopfunc addr $E4 iny lda [calclineptr], y cmp #$80 ror a sta <$E8 ;loopfunc addr $E8 ror <$E4 ror <$E0 ;jump loopxfunc phx jsr loopxfunc plx ;set x y sin cos data address(next 2lines) clc lda <calclineptr adc #$20 sta <calclineptr bcc .sincosaddrjump inc <calclineptr+1 .sincosaddrjump: ;increment calclinecounter inx cpx #32 jne .calcloop rts ;---------------------------- psgrun: stz <psgchno clx .psgrunloop: lda psg0count, x beq .psgrunjump00 dec a sta psg0count, x jmp .psgrunjump07 .psgrunjump00: lda [psg0addr, x] bmi .psgrunjump01 and #$0F cmp #$0C bcs .psgrunjump02 ;note asl a tay lda psgfreqdata, y sta <psgfreqwork lda psgfreqdata+1, y sta <psgfreqwork+1 lda [psg0addr, x] tay lda lsr4data, y ;scale(octave) shift .psgrunjump04: dec a bmi .psgrunjump03 lsr <psgfreqwork+1 ror <psgfreqwork bra .psgrunjump04 .psgrunjump03: lda <psgchno sta $0800 ;select ch lda <psgfreqwork sta $0802 ;r2 frequency lda <psgfreqwork+1 sta $0803 ;r3 frequency lda #$9F sta $0804 ;r4 keyon ddaoff volume31 bra .psgrunjump05 ;rest .psgrunjump02: lda <psgchno sta $0800 ;select ch lda #$00 sta $0804 ;r4 keyoff ddaoff volume0 ;set count .psgrunjump05: jsr psgdatanext lda [psg0addr, x] dec a sta psg0count, x jsr psgdatanext bra .psgrunjump07 .psgrunjump01: jsr psgdatanext lda [psg0addr, x] sta psgdataaddrwork jsr psgdatanext lda [psg0addr, x] sta psgdataaddrwork+1 clc lda psg0dataaddr, x adc psgdataaddrwork sta psg0addr, x lda psg0dataaddr+1, x adc psgdataaddrwork+1 sta psg0addr+1, x jmp .psgrunjump00 .psgrunjump07: inc <psgchno inx inx inx inx inx cpx #10 beq .psgrunend jmp .psgrunloop .psgrunend: rts ;---------------------------- psgdatanext: clc lda psg0addr, x adc #$01 sta psg0addr, x lda psg0addr+1, x adc #$00 sta psg0addr+1, x rts ;---------------------------- psginit: ;$0800~$080F cla sta $0800 ;select ch0 sta $0801 ;ch0 r1 mainvolumeleft0 mainvolumeright0 sta $0808 ;ch0 r8 lfofrequency0 sta $0809 ;ch0 r9 lfooff lfoctl0 .psginitloop0: sta $0800 ;ch select clx stx $0802 ;r2 frequency0 stx $0803 ;r3 frequency0 ldx #$40 ;r4 ddaon(wave buffer index reset) stx $0804 clx stx $0804 ;r4 keyoff ddaoff volume0 stx $0805 ;r5 leftvolume0 rightvolume0 sta $0807 ;r7 noiseoff noisefrequency0 inc a cmp #6 bne .psginitloop0 lda #$00 sta $0800 ;ch0 select clx .psginitloop1: lda psgwavedata0, x sta $0806 ;ch0 r6 wavebuffer inx cpx #$20 bne .psginitloop1 lda #$01 sta $0800 ;ch0 select clx .psginitloop2: lda psgwavedata1, x sta $0806 ;ch1 r6 wavebuffer inx cpx #$20 bne .psginitloop2 cla sta $0800 ;select ch0 lda #$FF sta $0801 ;ch0 r1 mainvolumeleft15 mainvolumeright15 lda #$88 sta $0805 ;ch0 r5 leftvolume15 rightvolume15 lda #1 sta $0800 ;select ch1 lda #$CC sta $0805 ;ch1 r5 leftvolume0 rightvolume15 ;;psg clock 3579545 ;;freq = 3579545 / (Hz * 32) ;;3579545 / (440 * 32) = 254.2290482954545 lda #LOW(psgmmldata0) sta psg0dataaddr sta <psg0addr lda #HIGH(psgmmldata0) sta psg0dataaddr+1 sta <psg0addr+1 stz psg0count lda #LOW(psgmmldata1) sta psg1dataaddr sta <psg1addr lda #HIGH(psgmmldata1) sta psg1dataaddr+1 sta <psg1addr+1 stz psg1count rts ;---------------------------- psgmmldata0: .db $27, $07, $0C, $02,\ ;1 $27, $07, $0C, $02,\ $27, $07, $0C, $02,\ $27, $07, $0C, $02,\ $27, $07, $0C, $02,\ $27, $07, $0C, $02,\ $27, $07, $0C, $02,\ $29, $07, $0C, $02 .db $29, $07, $0C, $02,\ ;2 $29, $07, $0C, $02,\ $29, $07, $0C, $02,\ $29, $07, $0C, $02,\ $29, $07, $0C, $02,\ $29, $07, $0C, $02,\ $29, $07, $0C, $02,\ $2A, $07, $0C, $02 .db $2A, $07, $0C, $02,\ ;3 $2A, $07, $0C, $02,\ $2A, $07, $0C, $02,\ $2A, $07, $0C, $02,\ $2A, $07, $0C, $02,\ $2A, $07, $0C, $02,\ $2A, $07, $0C, $02,\ $29, $07, $0C, $02 .db $29, $07, $0C, $02,\ ;4 $29, $07, $0C, $02,\ $29, $07, $0C, $02,\ $29, $07, $0C, $02,\ $29, $07, $0C, $02,\ $29, $07, $0C, $02,\ $29, $07, $0C, $02,\ $29, $07, $0C, $02 .db $2A, $07, $0C, $02,\ ;5 $2A, $07, $0C, $02,\ $2A, $07, $0C, $02,\ $2A, $07, $0C, $02,\ $2A, $07, $0C, $02,\ $2A, $07, $0C, $02,\ $2A, $07, $0C, $02,\ $29, $07, $0C, $02 .db $29, $07, $0C, $02,\ ;6 $29, $07, $0C, $02,\ $29, $07, $0C, $02,\ $29, $07, $0C, $02,\ $29, $07, $0C, $02,\ $29, $07, $0C, $02,\ $29, $07, $0C, $02,\ $2A, $07, $0C, $02 .db $2A, $07, $0C, $02,\ ;7 $2A, $07, $0C, $02,\ $2A, $07, $0C, $02,\ $2A, $07, $0C, $02,\ $2A, $07, $0C, $02,\ $2A, $07, $0C, $02,\ $2A, $07, $0C, $02,\ $29, $07, $0C, $02 .db $29, $07, $0C, $02,\ ;8 $29, $07, $0C, $02,\ $29, $07, $0C, $02,\ $29, $07, $0C, $02,\ $29, $07, $0C, $02,\ $29, $07, $0C, $02,\ $29, $07, $0C, $02,\ $29, $07, $0C, $02 .db $45, $19, $0C, $02,\ ;9 $43, $19, $0C, $02,\ $42, $10, $0C, $02 .db $40, $19, $0C, $02,\ ;10 $42, $19, $0C, $02,\ $43, $10, $0C, $02 .db $45, $19, $0C, $02,\ ;11 $43, $19, $0C, $02,\ $42, $10, $0C, $02 .db $40, $22, $0C, $02,\ ;12 $0C, $12,\ $40, $04,\ $42, $05,\ $43, $04,\ $45, $05 .db $47, $19, $0C, $02,\ ;13 $45, $19, $0C, $02,\ $4A, $10, $0C, $02 .db $48, $19, $0C, $02,\ ;14 $47, $19, $0C, $02,\ $45, $10, $0C, $02 .db $47, $19, $0C, $02,\ ;15 $48, $19, $0C, $02,\ $47, $10, $0C, $02 .db $45, $19, $0C, $02,\ ;16 $43, $19, $0C, $02,\ $42, $10, $0C, $02 .db $45, $19, $0C, $02,\ ;17 $43, $19, $0C, $02,\ $42, $10, $0C, $02 .db $40, $19, $0C, $02,\ ;18 $42, $19, $0C, $02,\ $43, $10, $0C, $02 .db $45, $19, $0C, $02,\ ;19 $43, $19, $0C, $02,\ $42, $10, $0C, $02 .db $40, $22, $0C, $02,\ ;20 $0C, $12,\ $40, $04,\ $42, $05,\ $43, $04,\ $45, $05 .db $47, $19, $0C, $02,\ ;21 $45, $19, $0C, $02,\ $4A, $10, $0C, $02 .db $48, $19, $0C, $02,\ ;22 $47, $19, $0C, $02,\ $45, $10, $0C, $02 .db $47, $19, $0C, $02,\ ;23 $48, $19, $0C, $02,\ $47, $10, $0C, $02 .db $45, $19, $0C, $02,\ ;24 $43, $19, $0C, $02,\ $42, $10, $0C, $02 .db $39, $22, $0C, $02,\ ;25 $0C, $09,\ $37, $07, $0C, $02,\ $39, $07, $0C, $02,\ $3A, $07, $0C, $02 .db $40, $22, $0C, $02,\ ;26 $0C, $09,\ $37, $07, $0C, $02,\ $39, $07, $0C, $02,\ $3A, $07, $0C, $02 .db $42, $22, $0C, $02,\ ;27 $0C, $09,\ $39, $07, $0C, $02,\ $3A, $07, $0C, $02,\ $42, $07, $0C, $02 .db $43, $22, $0C, $02,\ ;28 $0C, $09,\ $39, $07, $0C, $02,\ $3A, $07, $0C, $02,\ $43, $07, $0C, $02 .db $45, $22, $0C, $02,\ ;29 $0C, $09,\ $28, $07, $0C, $02,\ $31, $07, $0C, $02,\ $33, $07, $0C, $02 .db $35, $22, $0C, $02,\ ;30 $0C, $09,\ $31, $07, $0C, $02,\ $35, $07, $0C, $02,\ $38, $07, $0C, $02 .db $41, $22, $0C, $02,\ ;31 $0C, $09,\ $35, $07, $0C, $02,\ $41, $07, $0C, $02,\ $43, $07, $0C, $02 .db $45, $22, $0C, $02,\ ;32 $0C, $09,\ $38, $07, $0C, $02,\ $40, $07, $0C, $02,\ $43, $07, $0C, $02 .db $46, $0A, $0C, $02,\ ;33 $45, $0A, $0C, $02,\ $43, $0A, $0C, $02,\ $41, $0A, $0C, $02,\ $3B, $0A, $0C, $02,\ $41, $0A, $0C, $02 .db $3A, $0A, $0C, $02,\ ;34 $38, $0A, $0C, $02,\ $36, $0A, $0C, $02,\ $35, $0A, $0C, $02,\ $33, $0A, $0C, $02,\ $31, $0A, $0C, $02 .db $33, $0A, $0C, $02,\ ;35 $35, $0A, $0C, $02,\ $36, $0A, $0C, $02,\ $33, $0A, $0C, $02,\ $35, $0A, $0C, $02,\ $36, $0A, $0C, $02 .db $43, $46, $0C, $02 ;36 .db $0C, $24,\ ;37 $46, $04,\ $44, $05,\ $42, $04,\ $41, $05,\ $3B, $04,\ $39, $05,\ $38, $04,\ $36, $05 .db $80, $00, $00 ;---------------------------- psgmmldata1: ;.db $39, $FF, $0C, $FF, $80, $00, $00 ;.db $30, $10, $0C, $10, $30, $10, $32, $10, $34, $40,\ ; $37, $10, $0C, $10, $37, $10, $39, $10, $37, $40,\ ; $80, $00, $00 .db $20, $46, $0C, $02 ;1 .db $25, $46, $0C, $02 ;2 .db $23, $46, $0C, $02 ;3 .db $25, $2B, $0C, $02,\ ;4 $22, $10, $0C, $02,\ $21, $07, $0C, $02 .db $20, $46, $0C, $02 ;5 .db $25, $46, $0C, $02 ;6 .db $23, $46, $0C, $02 ;7 .db $25, $2B, $0C, $02,\ ;8 $22, $10, $0C, $02,\ $21, $07, $0C, $02 .db $20, $07, $0C, $02,\ ;9 $20, $07, $0C, $02,\ $20, $07, $0C, $02,\ $20, $07, $0C, $02,\ $20, $07, $0C, $02,\ $22, $07, $0C, $02,\ $1A, $07, $0C, $02,\ $17, $07, $0C, $02 .db $17, $07, $0C, $02,\ ;10 $17, $07, $0C, $02,\ $17, $07, $0C, $02,\ $17, $07, $0C, $02,\ $17, $07, $0C, $02,\ $17, $07, $0C, $02,\ $17, $07, $0C, $02,\ $17, $07, $0C, $02 .db $20, $07, $0C, $02,\ ;11 $20, $07, $0C, $02,\ $20, $07, $0C, $02,\ $20, $07, $0C, $02,\ $20, $07, $0C, $02,\ $22, $07, $0C, $02,\ $1A, $07, $0C, $02,\ $17, $07, $0C, $02 .db $17, $07, $0C, $02,\ ;12 $17, $07, $0C, $02,\ $17, $07, $0C, $02,\ $17, $07, $0C, $02,\ $17, $07, $0C, $02,\ $17, $07, $0C, $02,\ $17, $07, $0C, $02,\ $17, $07, $0C, $02 .db $21, $07, $0C, $02,\ ;13 $21, $07, $0C, $02,\ $21, $07, $0C, $02,\ $21, $07, $0C, $02,\ $21, $07, $0C, $02,\ $23, $07, $0C, $02,\ $10, $07, $0C, $02,\ $18, $07, $0C, $02 .db $18, $07, $0C, $02,\ ;14 $18, $07, $0C, $02,\ $18, $07, $0C, $02,\ $18, $07, $0C, $02,\ $18, $07, $0C, $02,\ $18, $07, $0C, $02,\ $18, $07, $0C, $02,\ $18, $07, $0C, $02 .db $21, $07, $0C, $02,\ ;15 $21, $07, $0C, $02,\ $21, $07, $0C, $02,\ $21, $07, $0C, $02,\ $21, $07, $0C, $02,\ $23, $07, $0C, $02,\ $10, $07, $0C, $02,\ $18, $07, $0C, $02 .db $18, $07, $0C, $02,\ ;16 $18, $07, $0C, $02,\ $18, $07, $0C, $02,\ $18, $07, $0C, $02,\ $18, $07, $0C, $02,\ $18, $07, $0C, $02,\ $18, $07, $0C, $02,\ $18, $07, $0C, $02 .db $20, $07, $0C, $02,\ ;17 $20, $07, $0C, $02,\ $20, $07, $0C, $02,\ $20, $07, $0C, $02,\ $20, $07, $0C, $02,\ $22, $07, $0C, $02,\ $1A, $07, $0C, $02,\ $17, $07, $0C, $02 .db $17, $07, $0C, $02,\ ;18 $17, $07, $0C, $02,\ $17, $07, $0C, $02,\ $17, $07, $0C, $02,\ $17, $07, $0C, $02,\ $17, $07, $0C, $02,\ $17, $07, $0C, $02,\ $17, $07, $0C, $02 .db $20, $07, $0C, $02,\ ;19 $20, $07, $0C, $02,\ $20, $07, $0C, $02,\ $20, $07, $0C, $02,\ $20, $07, $0C, $02,\ $22, $07, $0C, $02,\ $1A, $07, $0C, $02,\ $17, $07, $0C, $02 .db $17, $07, $0C, $02,\ ;20 $17, $07, $0C, $02,\ $17, $07, $0C, $02,\ $17, $07, $0C, $02,\ $17, $07, $0C, $02,\ $17, $07, $0C, $02,\ $17, $07, $0C, $02,\ $17, $07, $0C, $02 .db $21, $07, $0C, $02,\ ;21 $21, $07, $0C, $02,\ $21, $07, $0C, $02,\ $21, $07, $0C, $02,\ $21, $07, $0C, $02,\ $23, $07, $0C, $02,\ $10, $07, $0C, $02,\ $18, $07, $0C, $02 .db $18, $07, $0C, $02,\ ;22 $18, $07, $0C, $02,\ $18, $07, $0C, $02,\ $18, $07, $0C, $02,\ $18, $07, $0C, $02,\ $18, $07, $0C, $02,\ $18, $07, $0C, $02,\ $18, $07, $0C, $02 .db $21, $07, $0C, $02,\ ;23 $21, $07, $0C, $02,\ $21, $07, $0C, $02,\ $21, $07, $0C, $02,\ $21, $07, $0C, $02,\ $23, $07, $0C, $02,\ $10, $07, $0C, $02,\ $18, $07, $0C, $02 .db $18, $07, $0C, $02,\ ;24 $18, $07, $0C, $02,\ $18, $07, $0C, $02,\ $18, $07, $0C, $02,\ $18, $07, $0C, $02,\ $18, $07, $0C, $02,\ $18, $07, $0C, $02,\ $18, $07, $0C, $02 .db $0C, $10, $0C, $02,\ ;25 $27, $07, $0C, $02,\ $29, $10, $0C, $02,\ $0C, $07, $0C, $02,\ $0C, $10, $0C, $02 .db $0C, $10, $0C, $02,\ ;26 $2A, $07, $0C, $02,\ $30, $10, $0C, $02,\ $0C, $07, $0C, $02,\ $0C, $10, $0C, $02 .db $0C, $10, $0C, $02,\ ;27 $27, $07, $0C, $02,\ $29, $10, $0C, $02,\ $0C, $07, $0C, $02,\ $0C, $10, $0C, $02 .db $0C, $10, $0C, $02,\ ;28 $2A, $07, $0C, $02,\ $30, $10, $0C, $02,\ $0C, $07, $0C, $02,\ $0C, $10, $0C, $02 .db $0C, $10, $0C, $02,\ ;29 $27, $07, $0C, $02,\ $29, $10, $0C, $02,\ $0C, $07, $0C, $02,\ $0C, $10, $0C, $02 .db $0C, $10, $0C, $02,\ ;30 $2A, $07, $0C, $02,\ $30, $10, $0C, $02,\ $0C, $07, $0C, $02,\ $0C, $10, $0C, $02 .db $0C, $10, $0C, $02,\ ;31 $27, $07, $0C, $02,\ $29, $10, $0C, $02,\ $0C, $07, $0C, $02,\ $0C, $10, $0C, $02 .db $0C, $10, $0C, $02,\ ;32 $2A, $07, $0C, $02,\ $30, $10, $0C, $02,\ $0C, $07, $0C, $02,\ $0C, $10, $0C, $02 .db $13, $07, $0C, $02,\ ;33 $13, $07, $0C, $02,\ $13, $07, $0C, $02,\ $13, $07, $0C, $02,\ $13, $07, $0C, $02,\ $13, $07, $0C, $02,\ $13, $07, $0C, $02,\ $13, $07, $0C, $02 .db $0B, $07, $0C, $02,\ ;34 $0B, $07, $0C, $02,\ $0B, $07, $0C, $02,\ $0B, $07, $0C, $02,\ $0B, $07, $0C, $02,\ $0B, $07, $0C, $02,\ $0B, $07, $0C, $02,\ $0B, $07, $0C, $02 .db $06, $07, $0C, $02,\ ;35 $06, $07, $0C, $02,\ $06, $07, $0C, $02,\ $06, $07, $0C, $02,\ $18, $07, $0C, $02,\ $18, $07, $0C, $02,\ $18, $07, $0C, $02,\ $18, $07, $0C, $02 .db $0B, $07, $0C, $02,\ ;36 $0B, $07, $0C, $02,\ $0B, $07, $0C, $02,\ $0B, $07, $0C, $02,\ $0B, $07, $0C, $02,\ $0B, $07, $0C, $02,\ $0B, $07, $0C, $02,\ $0B, $07, $0C, $02 .db $0B, $07, $0C, $02,\ ;37 $0B, $07, $0C, $02,\ $0B, $07, $0C, $02,\ $0B, $07, $0C, $02,\ $0B, $07, $0C, $02,\ $0B, $07, $0C, $02,\ $0B, $07, $0C, $02,\ $0B, $07, $0C, $02 .db $80, $00, $00 ;---------------------------- psgwavedata0: .db $1F, $1F, $1F, $1F, $1F, $1F, $1F, $1F, $1F, $1F, $1F, $1F, $1F, $1F, $1F, $1F,\ $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00 ;---------------------------- psgwavedata1: .db $00, $02, $04, $06, $08, $0A, $0C, $0E, $10, $12, $14, $16, $18, $1A, $1C, $1E,\ $1E, $1C, $1A, $18, $16, $14, $12, $10, $0E, $0C, $0A, $08, $06, $04, $02, $00 ;---------------------------- psgfreqdata: .dw $0D5D, $0C9C, $0BE7, $0B3C, \ $0A9B, $0A02, $0973, $08EB, \ $086B, $07F2, $0780, $0714 ;//////////////////////////// .bank 2 INCBIN "x_y_sin_cos.dat" ;128K 2~17 $02~$11 left BGXY and additional value XY[left BGX:4byte, left BGY:4byte, additional value X:4byte, additional value Y:4byte] * 32line * 256angle INCBIN "char.dat" ;8K 18 $12 INCBIN "ship.dat" ;8K 19 $13 INCBIN "course1.dat" ;64K 20~27 $14~$1B dot(high nibble:low nibble) * 256column * 256row INCBIN "course1angle.dat" ;32K 28~31 $1C~$1F block angle * 256column * 128row INCBIN "course2.dat" ;64K 32~39 $20~$27 INCBIN "course2angle.dat" ;32K 40~43 $28~$2B
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r12 push %r8 push %rbx push %rcx push %rdi push %rdx push %rsi lea addresses_WT_ht+0xea6a, %rsi lea addresses_A_ht+0xe02a, %rdi nop nop nop add $6316, %r10 mov $19, %rcx rep movsl nop nop nop nop and $45760, %r8 lea addresses_WC_ht+0x11c2a, %r8 clflush (%r8) nop nop nop inc %rsi movw $0x6162, (%r8) nop dec %r8 lea addresses_A_ht+0x602a, %rsi lea addresses_D_ht+0x1f7a, %rdi nop nop nop inc %r12 mov $103, %rcx rep movsb dec %r8 lea addresses_D_ht+0x11e2a, %rsi nop nop nop nop sub %rdi, %rdi mov (%rsi), %r8w sub $33790, %r12 lea addresses_WC_ht+0x15dca, %rcx nop nop add $17556, %rsi movups (%rcx), %xmm4 vpextrq $0, %xmm4, %r12 nop nop nop nop nop xor $7733, %rcx lea addresses_normal_ht+0x1022a, %rdi nop dec %rdx movw $0x6162, (%rdi) nop xor $15335, %rcx lea addresses_WC_ht+0x1182a, %rsi dec %rdx movups (%rsi), %xmm4 vpextrq $1, %xmm4, %r12 nop nop nop nop dec %r12 lea addresses_D_ht+0x184d2, %rsi lea addresses_UC_ht+0x1a42a, %rdi and $34509, %rdx mov $15, %rcx rep movsl nop nop nop nop nop xor $41240, %rsi lea addresses_D_ht+0x2cc2, %rsi clflush (%rsi) nop and $61611, %rdx mov (%rsi), %r8d add %rdx, %rdx lea addresses_WC_ht+0xd42a, %rsi clflush (%rsi) inc %r8 mov $0x6162636465666768, %r10 movq %r10, (%rsi) xor $40655, %r12 lea addresses_UC_ht+0x16c2a, %rdx nop nop nop nop nop sub %rcx, %rcx movb (%rdx), %r10b nop nop nop nop nop xor $46341, %rdx lea addresses_WC_ht+0x18b84, %r10 nop nop nop sub %rdi, %rdi mov (%r10), %cx nop nop xor $27879, %r12 lea addresses_normal_ht+0x10597, %rdx nop nop nop nop dec %rcx mov $0x6162636465666768, %r10 movq %r10, (%rdx) nop nop nop nop cmp %r12, %r12 lea addresses_WC_ht+0x13c5a, %rsi lea addresses_WC_ht+0x1e02a, %rdi nop nop nop nop sub %rbx, %rbx mov $93, %rcx rep movsq nop add %rcx, %rcx pop %rsi pop %rdx pop %rdi pop %rcx pop %rbx pop %r8 pop %r12 pop %r10 ret .global s_faulty_load s_faulty_load: push %r12 push %r14 push %r9 push %rax push %rbp push %rbx push %rsi // Load lea addresses_WT+0x1ec8a, %rsi nop xor $652, %r9 mov (%rsi), %ebp nop nop add %rax, %rax // Load lea addresses_WT+0x1442a, %rbp nop nop nop nop sub %rbx, %rbx mov (%rbp), %esi nop nop nop cmp $58018, %rbx // Store lea addresses_D+0x1b82a, %r14 nop nop nop nop nop sub %rbx, %rbx mov $0x5152535455565758, %rbp movq %rbp, (%r14) nop nop cmp %rax, %rax // Store lea addresses_WC+0x9d2a, %rbx nop add $45420, %r9 movw $0x5152, (%rbx) nop add $36062, %r9 // Store lea addresses_A+0x1242a, %rbp nop nop nop nop xor %r12, %r12 movl $0x51525354, (%rbp) nop nop add %rsi, %rsi // Load lea addresses_UC+0x1262a, %rsi add $9573, %r12 mov (%rsi), %r14w nop nop nop nop cmp %rbx, %rbx // Store lea addresses_WT+0x1ae2a, %rbx nop nop cmp %r9, %r9 movw $0x5152, (%rbx) nop nop nop nop sub %r14, %r14 // Store mov $0x43caee000000090a, %rbx xor $53719, %r14 movl $0x51525354, (%rbx) nop nop nop and $47045, %rbx // Faulty Load lea addresses_RW+0xc02a, %rsi nop nop and %r12, %r12 movaps (%rsi), %xmm7 vpextrq $0, %xmm7, %r9 lea oracles, %rbx and $0xff, %r9 shlq $12, %r9 mov (%rbx,%r9,1), %r9 pop %rsi pop %rbx pop %rbp pop %rax pop %r9 pop %r14 pop %r12 ret /* <gen_faulty_load> [REF] {'src': {'type': 'addresses_RW', 'same': False, 'size': 4, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_WT', 'same': False, 'size': 4, 'congruent': 2, 'NT': True, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_WT', 'same': False, 'size': 4, 'congruent': 8, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'dst': {'type': 'addresses_D', 'same': False, 'size': 8, 'congruent': 11, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'dst': {'type': 'addresses_WC', 'same': False, 'size': 2, 'congruent': 5, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'dst': {'type': 'addresses_A', 'same': False, 'size': 4, 'congruent': 9, 'NT': True, 'AVXalign': False}, 'OP': 'STOR'} {'src': {'type': 'addresses_UC', 'same': False, 'size': 2, 'congruent': 9, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'dst': {'type': 'addresses_WT', 'same': False, 'size': 2, 'congruent': 7, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'dst': {'type': 'addresses_NC', 'same': False, 'size': 4, 'congruent': 5, 'NT': True, 'AVXalign': False}, 'OP': 'STOR'} [Faulty Load] {'src': {'type': 'addresses_RW', 'same': True, 'size': 16, 'congruent': 0, 'NT': False, 'AVXalign': True}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'type': 'addresses_WT_ht', 'congruent': 6, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 9, 'same': False}, 'OP': 'REPM'} {'dst': {'type': 'addresses_WC_ht', 'same': False, 'size': 2, 'congruent': 9, 'NT': True, 'AVXalign': False}, 'OP': 'STOR'} {'src': {'type': 'addresses_A_ht', 'congruent': 10, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 4, 'same': False}, 'OP': 'REPM'} {'src': {'type': 'addresses_D_ht', 'same': False, 'size': 2, 'congruent': 9, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_WC_ht', 'same': False, 'size': 16, 'congruent': 5, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'dst': {'type': 'addresses_normal_ht', 'same': False, 'size': 2, 'congruent': 8, 'NT': True, 'AVXalign': True}, 'OP': 'STOR'} {'src': {'type': 'addresses_WC_ht', 'same': False, 'size': 16, 'congruent': 11, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_D_ht', 'congruent': 0, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 10, 'same': False}, 'OP': 'REPM'} {'src': {'type': 'addresses_D_ht', 'same': False, 'size': 4, 'congruent': 3, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'dst': {'type': 'addresses_WC_ht', 'same': False, 'size': 8, 'congruent': 10, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'src': {'type': 'addresses_UC_ht', 'same': False, 'size': 1, 'congruent': 10, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_WC_ht', 'same': False, 'size': 2, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'dst': {'type': 'addresses_normal_ht', 'same': False, 'size': 8, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'src': {'type': 'addresses_WC_ht', 'congruent': 4, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 10, 'same': True}, 'OP': 'REPM'} {'00': 21829} 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 */
.global s_prepare_buffers s_prepare_buffers: push %r13 push %r8 push %rbp push %rbx push %rcx push %rdi push %rsi lea addresses_normal_ht+0x190ad, %rbx nop nop xor $29292, %rdi mov $0x6162636465666768, %rbp movq %rbp, %xmm5 movups %xmm5, (%rbx) add %rbp, %rbp lea addresses_WT_ht+0x11c86, %r13 nop nop and $22968, %rbp movl $0x61626364, (%r13) and $47996, %rcx lea addresses_normal_ht+0x1482d, %rsi lea addresses_D_ht+0x41ad, %rdi nop nop nop nop nop cmp %r8, %r8 mov $87, %rcx rep movsl nop nop nop xor %rbp, %rbp lea addresses_UC_ht+0x11c7b, %rbp nop cmp %r8, %r8 mov $0x6162636465666768, %rsi movq %rsi, (%rbp) nop nop nop nop nop dec %rcx lea addresses_UC_ht+0x14fcd, %rbx nop inc %r8 mov $0x6162636465666768, %rdi movq %rdi, %xmm4 movups %xmm4, (%rbx) nop nop nop nop nop xor %r8, %r8 lea addresses_UC_ht+0x1aaa3, %rdi nop nop nop and $6432, %r13 movb $0x61, (%rdi) nop nop nop nop add $1860, %rsi lea addresses_WC_ht+0x1cb45, %r13 nop nop nop nop xor $45844, %rbx and $0xffffffffffffffc0, %r13 vmovntdqa (%r13), %ymm1 vextracti128 $0, %ymm1, %xmm1 vpextrq $1, %xmm1, %rsi nop nop nop nop nop xor $33979, %rsi lea addresses_D_ht+0x12869, %r8 nop nop nop nop nop xor $56309, %rbx mov $0x6162636465666768, %rdi movq %rdi, %xmm3 vmovups %ymm3, (%r8) nop cmp $47149, %rdi lea addresses_WT_ht+0x1ccad, %rsi nop nop nop nop sub $57538, %rbx mov $0x6162636465666768, %rbp movq %rbp, %xmm5 movups %xmm5, (%rsi) nop cmp $16295, %rbx lea addresses_UC_ht+0x171f6, %rbx clflush (%rbx) nop xor %r8, %r8 movb $0x61, (%rbx) nop nop nop nop nop sub $41662, %r13 lea addresses_D_ht+0x440d, %rdi xor %rcx, %rcx mov $0x6162636465666768, %r13 movq %r13, %xmm5 vmovups %ymm5, (%rdi) nop nop nop add $37920, %rbx pop %rsi pop %rdi pop %rcx pop %rbx pop %rbp pop %r8 pop %r13 ret .global s_faulty_load s_faulty_load: push %r10 push %r15 push %rax push %rbp push %rbx push %rcx push %rdx // Store lea addresses_D+0xd58d, %rbp nop nop nop xor %r10, %r10 mov $0x5152535455565758, %rdx movq %rdx, %xmm6 movups %xmm6, (%rbp) nop nop nop inc %rdx // Store lea addresses_UC+0xdd51, %rcx clflush (%rcx) nop nop nop dec %r15 movl $0x51525354, (%rcx) nop sub %r10, %r10 // Store lea addresses_WC+0x17dad, %rax nop nop nop cmp %rbx, %rbx movw $0x5152, (%rax) nop nop dec %rbx // Store lea addresses_PSE+0xb4ad, %rbp cmp %rdx, %rdx mov $0x5152535455565758, %r15 movq %r15, %xmm4 vmovups %ymm4, (%rbp) and $5023, %rdx // Load lea addresses_WT+0x6a6d, %rbx nop nop and $35920, %r15 movb (%rbx), %cl nop inc %rcx // Load lea addresses_RW+0x1b7ad, %rax nop nop nop nop sub $11319, %r10 vmovups (%rax), %ymm2 vextracti128 $0, %ymm2, %xmm2 vpextrq $0, %xmm2, %rbx nop nop nop nop add $60892, %r10 // Faulty Load lea addresses_PSE+0xb4ad, %rbx nop cmp $26173, %r10 movb (%rbx), %dl lea oracles, %r15 and $0xff, %rdx shlq $12, %rdx mov (%r15,%rdx,1), %rdx pop %rdx pop %rcx pop %rbx pop %rbp pop %rax pop %r15 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_PSE', 'AVXalign': False, 'congruent': 0, 'size': 2, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_D', 'AVXalign': False, 'congruent': 1, 'size': 16, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_UC', 'AVXalign': False, 'congruent': 0, 'size': 4, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WC', 'AVXalign': False, 'congruent': 8, 'size': 2, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_PSE', 'AVXalign': False, 'congruent': 0, 'size': 32, 'same': True, 'NT': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WT', 'AVXalign': False, 'congruent': 3, 'size': 1, 'same': False, 'NT': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_RW', 'AVXalign': False, 'congruent': 5, 'size': 32, 'same': False, 'NT': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_PSE', 'AVXalign': True, 'congruent': 0, 'size': 1, 'same': True, 'NT': True}} <gen_prepare_buffer> {'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'AVXalign': False, 'congruent': 9, 'size': 16, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'AVXalign': False, 'congruent': 0, 'size': 4, 'same': False, 'NT': False}} {'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 6, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 4, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 1, 'size': 8, 'same': False, 'NT': True}} {'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 5, 'size': 16, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 1, 'size': 1, 'same': False, 'NT': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 3, 'size': 32, 'same': False, 'NT': True}} {'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'AVXalign': False, 'congruent': 0, 'size': 32, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'AVXalign': False, 'congruent': 9, 'size': 16, 'same': True, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 0, 'size': 1, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'AVXalign': False, 'congruent': 5, 'size': 32, 'same': False, 'NT': False}} {'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 */
section .rodata format: db 'Hello, %s', 10, 0 name: db 'Holberton', 0 section .text global main extern printf main: ;; printf(format, name) mov rdi, format mov rsi, name ;; no XMM registers mov rax, 0 call printf ;; return 0 mov rax, 0 ret
; A061419: a(n) = ceiling(a(n-1)*3/2) with a(1) = 1. ; 1,2,3,5,8,12,18,27,41,62,93,140,210,315,473,710,1065,1598,2397,3596,5394,8091,12137,18206,27309,40964,61446,92169,138254,207381,311072,466608,699912,1049868,1574802,2362203,3543305,5314958,7972437,11958656,17937984,26906976,40360464,60540696,90811044,136216566,204324849,306487274,459730911,689596367,1034394551,1551591827,2327387741,3491081612,5236622418,7854933627,11782400441,17673600662,26510400993,39765601490,59648402235,89472603353,134208905030,201313357545,301970036318,452955054477,679432581716,1019148872574,1528723308861,2293084963292,3439627444938,5159441167407,7739161751111,11608742626667,17413113940001,26119670910002,39179506365003,58769259547505,88153889321258,132230833981887,198346250972831,297519376459247,446279064688871,669418597033307,1004127895549961,1506191843324942,2259287764987413,3388931647481120,5083397471221680,7625096206832520,11437644310248780,17156466465373170,25734699698059755,38602049547089633,57903074320634450,86854611480951675,130281917221427513,195422875832141270,293134313748211905,439701470622317858 mul $0,2 mov $1,12 lpb $0 sub $0,2 div $1,4 mul $1,6 lpe div $1,6 sub $1,1 mov $0,$1
;------------------------------------------------------------------------------ ; ; Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR> ; This program and the accompanying materials ; are licensed and made available under the terms and conditions of the BSD License ; which accompanies this distribution. The full text of the license may be found at ; http://opensource.org/licenses/bsd-license.php. ; ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. ; ; Module Name: ; ; ScanMem8.Asm ; ; Abstract: ; ; ScanMem8 function ; ; Notes: ; ; The following BaseMemoryLib instances contain the same copy of this file: ; ; BaseMemoryLibRepStr ; BaseMemoryLibMmx ; BaseMemoryLibSse2 ; BaseMemoryLibOptDxe ; BaseMemoryLibOptPei ; ;------------------------------------------------------------------------------ .686 .model flat,C .code ;------------------------------------------------------------------------------ ; CONST VOID * ; EFIAPI ; InternalMemScanMem8 ( ; IN CONST VOID *Buffer, ; IN UINTN Length, ; IN UINT8 Value ; ); ;------------------------------------------------------------------------------ InternalMemScanMem8 PROC USES edi mov ecx, [esp + 12] mov edi, [esp + 8] mov al, [esp + 16] repne scasb lea eax, [edi - 1] jz @F mov eax, ecx @@: ret InternalMemScanMem8 ENDP END
; Listing generated by Microsoft (R) Optimizing Compiler Version 19.24.28117.0 include listing.inc INCLUDELIB LIBCMT INCLUDELIB OLDNAMES PUBLIC ?sum_result@@3HA ; sum_result PUBLIC ?multi_result@@3HA ; multi_result _BSS SEGMENT ?sum_result@@3HA DD 01H DUP (?) ; sum_result ?multi_result@@3HA DD 01H DUP (?) ; multi_result _BSS ENDS CONST SEGMENT $SG5099 DB 'Hello World!', 0aH, 00H ORG $+2 $SG5100 DB 'sum_result=%d,multi_result=%d', 0aH, 00H CONST ENDS PUBLIC __local_stdio_printf_options PUBLIC _vfprintf_l PUBLIC printf PUBLIC ?f@@YAXHHPEAH0@Z ; f PUBLIC main PUBLIC ?_OptionsStorage@?1??__local_stdio_printf_options@@9@4_KA ; `__local_stdio_printf_options'::`2'::_OptionsStorage EXTRN __acrt_iob_func:PROC EXTRN __stdio_common_vfprintf:PROC ; COMDAT ?_OptionsStorage@?1??__local_stdio_printf_options@@9@4_KA _BSS SEGMENT ?_OptionsStorage@?1??__local_stdio_printf_options@@9@4_KA DQ 01H DUP (?) ; `__local_stdio_printf_options'::`2'::_OptionsStorage _BSS ENDS ; COMDAT pdata pdata SEGMENT $pdata$_vfprintf_l DD imagerel $LN3 DD imagerel $LN3+67 DD imagerel $unwind$_vfprintf_l pdata ENDS ; COMDAT pdata pdata SEGMENT $pdata$printf DD imagerel $LN3 DD imagerel $LN3+87 DD imagerel $unwind$printf pdata ENDS pdata SEGMENT $pdata$main DD imagerel $LN3 DD imagerel $LN3+77 DD imagerel $unwind$main pdata ENDS xdata SEGMENT $unwind$main DD 010401H DD 04204H xdata ENDS ; COMDAT xdata xdata SEGMENT $unwind$printf DD 011801H DD 06218H xdata ENDS ; COMDAT xdata xdata SEGMENT $unwind$_vfprintf_l DD 011801H DD 06218H xdata ENDS ; Function compile flags: /Odtp _TEXT SEGMENT main PROC ; File C:\Users\libit\source\repos\L017\L017\L017.cpp ; Line 16 $LN3: sub rsp, 40 ; 00000028H ; Line 17 lea rcx, OFFSET FLAT:$SG5099 call printf ; Line 18 lea r9, OFFSET FLAT:?multi_result@@3HA ; multi_result lea r8, OFFSET FLAT:?sum_result@@3HA ; sum_result mov edx, 456 ; 000001c8H mov ecx, 123 ; 0000007bH call ?f@@YAXHHPEAH0@Z ; f ; Line 19 mov r8d, DWORD PTR ?multi_result@@3HA ; multi_result mov edx, DWORD PTR ?sum_result@@3HA ; sum_result lea rcx, OFFSET FLAT:$SG5100 call printf ; Line 20 xor eax, eax add rsp, 40 ; 00000028H ret 0 main ENDP _TEXT ENDS ; Function compile flags: /Odtp _TEXT SEGMENT x$ = 8 y$ = 16 sum$ = 24 multi$ = 32 ?f@@YAXHHPEAH0@Z PROC ; f ; File C:\Users\libit\source\repos\L017\L017\L017.cpp ; Line 7 mov QWORD PTR [rsp+32], r9 mov QWORD PTR [rsp+24], r8 mov DWORD PTR [rsp+16], edx mov DWORD PTR [rsp+8], ecx ; Line 8 mov eax, DWORD PTR y$[rsp] mov ecx, DWORD PTR x$[rsp] add ecx, eax mov eax, ecx mov rcx, QWORD PTR sum$[rsp] mov DWORD PTR [rcx], eax ; Line 9 mov eax, DWORD PTR x$[rsp] imul eax, DWORD PTR y$[rsp] mov rcx, QWORD PTR multi$[rsp] mov DWORD PTR [rcx], eax ; Line 10 ret 0 ?f@@YAXHHPEAH0@Z ENDP ; f _TEXT ENDS ; Function compile flags: /Odtp ; COMDAT printf _TEXT SEGMENT _Result$ = 32 _ArgList$ = 40 _Format$ = 64 printf PROC ; COMDAT ; File C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\stdio.h ; Line 954 $LN3: mov QWORD PTR [rsp+8], rcx mov QWORD PTR [rsp+16], rdx mov QWORD PTR [rsp+24], r8 mov QWORD PTR [rsp+32], r9 sub rsp, 56 ; 00000038H ; Line 957 lea rax, QWORD PTR _Format$[rsp+8] mov QWORD PTR _ArgList$[rsp], rax ; Line 958 mov ecx, 1 call __acrt_iob_func mov r9, QWORD PTR _ArgList$[rsp] xor r8d, r8d mov rdx, QWORD PTR _Format$[rsp] mov rcx, rax call _vfprintf_l mov DWORD PTR _Result$[rsp], eax ; Line 959 mov QWORD PTR _ArgList$[rsp], 0 ; Line 960 mov eax, DWORD PTR _Result$[rsp] ; Line 961 add rsp, 56 ; 00000038H ret 0 printf ENDP _TEXT ENDS ; Function compile flags: /Odtp ; COMDAT _vfprintf_l _TEXT SEGMENT _Stream$ = 64 _Format$ = 72 _Locale$ = 80 _ArgList$ = 88 _vfprintf_l PROC ; COMDAT ; File C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\stdio.h ; Line 642 $LN3: mov QWORD PTR [rsp+32], r9 mov QWORD PTR [rsp+24], r8 mov QWORD PTR [rsp+16], rdx mov QWORD PTR [rsp+8], rcx sub rsp, 56 ; 00000038H ; Line 643 call __local_stdio_printf_options mov rcx, QWORD PTR _ArgList$[rsp] mov QWORD PTR [rsp+32], rcx mov r9, QWORD PTR _Locale$[rsp] mov r8, QWORD PTR _Format$[rsp] mov rdx, QWORD PTR _Stream$[rsp] mov rcx, QWORD PTR [rax] call __stdio_common_vfprintf ; Line 644 add rsp, 56 ; 00000038H ret 0 _vfprintf_l ENDP _TEXT ENDS ; Function compile flags: /Odtp ; COMDAT __local_stdio_printf_options _TEXT SEGMENT __local_stdio_printf_options PROC ; COMDAT ; File C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\corecrt_stdio_config.h ; Line 88 lea rax, OFFSET FLAT:?_OptionsStorage@?1??__local_stdio_printf_options@@9@4_KA ; `__local_stdio_printf_options'::`2'::_OptionsStorage ; Line 89 ret 0 __local_stdio_printf_options ENDP _TEXT ENDS END
; A131865: Partial sums of powers of 16. ; 1,17,273,4369,69905,1118481,17895697,286331153,4581298449,73300775185,1172812402961,18764998447377,300239975158033,4803839602528529,76861433640456465,1229782938247303441,19676527011956855057,314824432191309680913,5037190915060954894609,80595054640975278313745,1289520874255604453019921,20632333988089671248318737,330117343809434739973099793,5281877500950955839569596689,84510040015215293433113547025,1352160640243444694929816752401,21634570243895115118877068038417,346153123902321841902033088614673,5538449982437149470432529417834769,88615199718994391526920470685356305 add $0,1 mov $1,16 pow $1,$0 div $1,15 mov $0,$1
; A169508: Number of reduced words of length n in Coxeter group on 15 generators S_i with relations (S_i)^2 = (S_i S_j)^34 = I. ; 1,15,210,2940,41160,576240,8067360,112943040,1581202560,22136835840,309915701760,4338819824640,60743477544960,850408685629440,11905721598812160,166680102383370240,2333521433367183360 add $0,1 mov $3,1 lpb $0 sub $0,1 add $2,$3 div $3,$2 mul $2,14 lpe mov $0,$2 div $0,14
;------------------------------------------------------------------------------ ; ; Copyright (c) 2006, Intel Corporation. All rights reserved.<BR> ; SPDX-License-Identifier: BSD-2-Clause-Patent ; ; Module Name: ; ; CpuId.Asm ; ; Abstract: ; ; AsmCpuid function ; ; Notes: ; ;------------------------------------------------------------------------------ SECTION .text ;------------------------------------------------------------------------------ ; VOID ; EFIAPI ; AsmCpuid ( ; IN UINT32 RegisterInEax, ; OUT UINT32 *RegisterOutEax OPTIONAL, ; OUT UINT32 *RegisterOutEbx OPTIONAL, ; OUT UINT32 *RegisterOutEcx OPTIONAL, ; OUT UINT32 *RegisterOutEdx OPTIONAL ; ); ;------------------------------------------------------------------------------ global ASM_PFX(AsmCpuid) ASM_PFX(AsmCpuid): push ebx push ebp mov ebp, esp mov eax, [ebp + 12] cpuid push ecx mov ecx, [ebp + 16] jecxz .0 mov [ecx], eax .0: mov ecx, [ebp + 20] jecxz .1 mov [ecx], ebx .1: mov ecx, [ebp + 24] jecxz .2 pop DWORD [ecx] .2: mov ecx, [ebp + 28] jecxz .3 mov [ecx], edx .3: mov eax, [ebp + 12] leave pop ebx ret
;************************************************************************ ;** An Assembly File Listing to generate a 16K ROM for the ZX Spectrum ** ;************************************************************************ ; ------------------------- ; Last updated: 13-DEC-2004 ; ------------------------- ; TASM cross-assembler directives. ; ( comment out, perhaps, for other assemblers - see Notes at end.) ;#define DEFB .BYTE ;#define DEFW .WORD ;#define DEFB .TEXT ;#define ORG .ORG ;#define EQU .EQU ;#define equ .EQU ; KR - porty dla Z80 SIOx sio_ad .equ 0F5h ; port B sio_ac .equ 0F7h ; It is always a good idea to anchor, using ORGs, important sections such as ; the character bitmaps so that they don't move as code is added and removed. ; Generally most approaches try to maintain main entry points as they are ; often used by third-party software. .ORG 0000 ;***************************************** ;** Part 1. RESTART ROUTINES AND TABLES ** ;***************************************** ; ----------- ; THE 'START' ; ----------- ; At switch on, the Z80 chip is in Interrupt Mode 0. ; The Spectrum uses Interrupt Mode 1. ; This location can also be 'called' to reset the machine. ; Typically with PRINT USR 0. ;; START L0000: DI ; Disable Interrupts. XOR A ; Signal coming from START. LD DE,0FFFFh ; Set pointer to top of possible physical RAM. JP L11CB ; Jump forward to common code at START-NEW. ; ------------------- ; THE 'ERROR' RESTART ; ------------------- ; The error pointer is made to point to the position of the error to enable ; the editor to highlight the error position if it occurred during syntax ; checking. It is used at 37 places in the program. An instruction fetch ; on address 008h may page in a peripheral ROM such as the Sinclair ; Interface 1 or Disciple Disk Interface. This was not an original design ; concept and not all errors pass through here. ;; ERROR-1 L0008: LD HL,(05C5Dh) ; Fetch the character address from CH_ADD. LD (05C5Fh),HL ; Copy it to the error pointer X_PTR. JR L0053 ; Forward to continue at ERROR-2. ; ----------------------------- ; THE 'PRINT CHARACTER' RESTART ; ----------------------------- ; The A register holds the code of the character that is to be sent to ; the output stream of the current channel. The alternate register set is ; used to output a character in the A register so there is no need to ; preserve any of the current main registers (HL, DE, BC). ; This restart is used 21 times. ;; PRINT-A L0010: JP L15F2 ; Jump forward to continue at PRINT-A-2. ; --- .DEFB 0FFh, 0FFh, 0FFh ; Five unused locations. .DEFB 0FFh, 0FFh ; ; ------------------------------- ; THE 'COLLECT CHARACTER' RESTART ; ------------------------------- ; The contents of the location currently addressed by CH_ADD are fetched. ; A return is made if the value represents a character that has ; relevance to the BASIC parser. Otherwise CH_ADD is incremented and the ; tests repeated. CH_ADD will be addressing somewhere - ; 1) in the BASIC program area during line execution. ; 2) in workspace if evaluating, for example, a string expression. ; 3) in the edit buffer if parsing a direct command or a new BASIC line. ; 4) in workspace if accepting input but not that from INPUT LINE. ;; GET-CHAR L0018: LD HL,(05C5Dh) ; fetch the address from CH_ADD. LD A,(HL) ; use it to pick up current character. ;; TEST-CHAR L001C: CALL L007D ; routine SKIP-OVER tests if the character is ; relevant. RET NC ; Return if it is significant. ; ------------------------------------ ; THE 'COLLECT NEXT CHARACTER' RESTART ; ------------------------------------ ; As the BASIC commands and expressions are interpreted, this routine is ; called repeatedly to step along the line. It is used 83 times. ;; NEXT-CHAR L0020: CALL L0074 ; routine CH-ADD+1 fetches the next immediate ; character. JR L001C ; jump back to TEST-CHAR until a valid ; character is found. ; --- .DEFB 0FFh, 0FFh, 0FFh ; unused ; ----------------------- ; THE 'CALCULATE' RESTART ; ----------------------- ; This restart enters the Spectrum's internal, floating-point, stack-based, ; FORTH-like language. ; It is further used recursively from within the calculator. ; It is used on 77 occasions. ;; FP-CALC L0028: JP L335B ; jump forward to the CALCULATE routine. ; --- .DEFB 0FFh, 0FFh, 0FFh ; spare - note that on the ZX81, space being a .DEFB 0FFh, 0FFh ; little cramped, these same locations were ; used for the five-byte end-calc literal. ; ------------------------------ ; THE 'CREATE BC SPACES' RESTART ; ------------------------------ ; This restart is used on only 12 occasions to create BC spaces ; between workspace and the calculator stack. ;; BC-SPACES L0030: PUSH BC ; Save number of spaces. LD HL,(05C61h) ; Fetch WORKSP. PUSH HL ; Save address of workspace. JP L169E ; Jump forward to continuation code RESERVE. ; -------------------------------- ; THE 'MASKABLE INTERRUPT' ROUTINE ; -------------------------------- ; This routine increments the Spectrum's three-byte FRAMES counter fifty ; times a second (sixty times a second in the USA ). ; Both this routine and the called KEYBOARD subroutine use the IY register ; to access system variables and flags so a user-written program must ; disable interrupts to make use of the IY register. ;; MASK-INT L0038: PUSH AF ; Save the registers that will be used but not PUSH HL ; the IY register unfortunately. LD HL,(05C78h) ; Fetch the first two bytes at FRAMES1. INC HL ; Increment lowest two bytes of counter. LD (05C78h),HL ; Place back in FRAMES1. LD A,H ; Test if the result was zero. OR L ; JR NZ,L0048 ; Forward, if not, to KEY-INT INC (IY+040h) ; otherwise increment FRAMES3 the third byte. ; Now save the rest of the main registers and read and decode the keyboard. ;; KEY-INT L0048: PUSH BC ; Save the other main registers. PUSH DE ; CALL L02BF ; Routine KEYBOARD executes a stage in the ; process of reading a key-press. POP DE ; POP BC ; Restore registers. POP HL ; POP AF ; EI ; Enable Interrupts. RET ; Return. ; --------------------- ; THE 'ERROR-2' ROUTINE ; --------------------- ; A continuation of the code at 0008. ; The error code is stored and after clearing down stacks, an indirect jump ; is made to MAIN-4, etc. to handle the error. ;; ERROR-2 L0053: POP HL ; drop the return address - the location ; after the RST 08H instruction. LD L,(HL) ; fetch the error code that follows. ; (nice to see this instruction used.) ; Note. this entry point is used when out of memory at REPORT-4. ; The L register has been loaded with the report code but X-PTR is not ; updated. ;; ERROR-3 L0055: LD (IY+00h),L ; Store it in the system variable ERR_NR. LD SP,(05C3Dh) ; ERR_SP points to an error handler on the ; machine stack. There may be a hierarchy ; of routines. ; To MAIN-4 initially at base. ; or REPORT-G on line entry. ; or ED-ERROR when editing. ; or ED-FULL during ed-enter. ; or IN-VAR-1 during runtime input etc. JP L16C5 ; Jump to SET-STK to clear the calculator stack ; and reset MEM to usual place in the systems ; variables area and then indirectly to MAIN-4, ; etc. ; --- .DEFB 0FFh, 0FFh, 0FFh ; Unused locations .DEFB 0FFh, 0FFh, 0FFh ; before the fixed-position .DEFB 0FFh ; NMI routine. ; ------------------------------------ ; THE 'NON-MASKABLE INTERRUPT' ROUTINE ; ------------------------------------ ; ; There is no NMI switch on the standard Spectrum or its peripherals. ; When the NMI line is held low, then no matter what the Z80 was doing at ; the time, it will now execute the code at 66 Hex. ; This Interrupt Service Routine will jump to location zero if the contents ; of the system variable NMIADD are zero or return if the location holds a ; non-zero address. So attaching a simple switch to the NMI as in the book ; "Spectrum Hardware Manual" causes a reset. The logic was obviously ; intended to work the other way. Sinclair Research said that, since they ; had never advertised the NMI, they had no plans to fix the error "until ; the opportunity arose". ; ; Note. The location NMIADD was, in fact, later used by Sinclair Research ; to enhance the text channel on the ZX Interface 1. ; On later Amstrad-made Spectrums, and the Brazilian Spectrum, the logic of ; this routine was indeed reversed but not as at first intended. ; ; It can be deduced by looking elsewhere in this ROM that the NMIADD system ; variable pointed to L121C and that this enabled a Warm Restart to be ; performed at any time, even while playing machine code games, or while ; another Spectrum has been allowed to gain control of this one. ; ; Software houses would have been able to protect their games from attack by ; placing two zeros in the NMIADD system variable. ;; RESET L0066: PUSH AF ; save the PUSH HL ; registers. LD HL,(05CB0h) ; fetch the system variable NMIADD. LD A,H ; test address OR L ; for zero. JR NZ,L0070 ; skip to NO-RESET if NOT ZERO JP (HL) ; jump to routine ( i.e. L0000 ) ;; NO-RESET L0070: POP HL ; restore the POP AF ; registers. RETN ; return to previous interrupt state. ; --------------------------- ; THE 'CH ADD + 1' SUBROUTINE ; --------------------------- ; This subroutine is called from RST 20, and three times from elsewhere ; to fetch the next immediate character following the current valid character ; address and update the associated system variable. ; The entry point TEMP-PTR1 is used from the SCANNING routine. ; Both TEMP-PTR1 and TEMP-PTR2 are used by the READ command routine. ;; CH-ADD+1 L0074: LD HL,(05C5Dh) ; fetch address from CH_ADD. ;; TEMP-PTR1 L0077: INC HL ; increase the character address by one. ;; TEMP-PTR2 L0078: LD (05C5Dh),HL ; update CH_ADD with character address. X007B: LD A,(HL) ; load character to A from HL. RET ; and return. ; -------------------------- ; THE 'SKIP OVER' SUBROUTINE ; -------------------------- ; This subroutine is called once from RST 18 to skip over white-space and ; other characters irrelevant to the parsing of a BASIC line etc. . ; Initially the A register holds the character to be considered ; and HL holds its address which will not be within quoted text ; when a BASIC line is parsed. ; Although the 'tab' and 'at' characters will not appear in a BASIC line, ; they could be present in a string expression, and in other situations. ; Note. although white-space is usually placed in a program to indent loops ; and make it more readable, it can also be used for the opposite effect and ; spaces may appear in variable names although the parser never sees them. ; It is this routine that helps make the variables 'Anum bEr5 3BUS' and ; 'a number 53 bus' appear the same to the parser. ;; SKIP-OVER L007D: CP 021h ; test if higher than space. RET NC ; return with carry clear if so. CP 00Dh ; carriage return ? RET Z ; return also with carry clear if so. ; all other characters have no relevance ; to the parser and must be returned with ; carry set. CP 010h ; test if 0-15d RET C ; return, if so, with carry set. CP 018h ; test if 24-32d CCF ; complement carry flag. RET C ; return with carry set if so. ; now leaves 16d-23d INC HL ; all above have at least one extra character ; to be stepped over. CP 016h ; controls 22d ('at') and 23d ('tab') have two. JR C,L0090 ; forward to SKIPS with ink, paper, flash, ; bright, inverse or over controls. ; Note. the high byte of tab is for RS232 only. ; it has no relevance on this machine. INC HL ; step over the second character of 'at'/'tab'. ;; SKIPS L0090: SCF ; set the carry flag LD (05C5Dh),HL ; update the CH_ADD system variable. RET ; return with carry set. ; ------------------ ; THE 'TOKEN' TABLES ; ------------------ ; The tokenized characters 134d (RND) to 255d (COPY) are expanded using ; this table. The last byte of a token is inverted to denote the end of ; the word. The first is an inverted step-over byte. ;; TKN-TABLE L0095: .DEFB '?'+080h .DEFB "RN" .DEFB 'D'+080h .DEFB "INKEY" .DEFB '$'+080h .DEFB 'P','I'+080h .DEFB 'F','N'+080h .DEFB "POIN" .DEFB 'T'+080h .DEFB "SCREEN" .DEFB '$'+080h .DEFB "ATT" .DEFB 'R'+080h .DEFB 'A','T'+080h .DEFB "TA" .DEFB 'B'+080h .DEFB "VAL" .DEFB '$'+080h .DEFB "COD" .DEFB 'E'+080h .DEFB "VA" .DEFB 'L'+080h .DEFB "LE" .DEFB 'N'+080h .DEFB "SI" .DEFB 'N'+080h .DEFB "CO" .DEFB 'S'+080h .DEFB "TA" .DEFB 'N'+080h .DEFB "AS" .DEFB 'N'+080h .DEFB "AC" .DEFB 'S'+080h .DEFB "AT" .DEFB 'N'+080h .DEFB 'L','N'+080h .DEFB "EX" .DEFB 'P'+080h .DEFB "IN" .DEFB 'T'+080h .DEFB "SQ" .DEFB 'R'+080h .DEFB "SG" .DEFB 'N'+080h .DEFB "AB" .DEFB 'S'+080h .DEFB "PEE" .DEFB 'K'+080h .DEFB 'I','N'+080h .DEFB "US" .DEFB 'R'+080h .DEFB "STR" .DEFB '$'+080h .DEFB "CHR" .DEFB '$'+080h .DEFB "NO" .DEFB 'T'+080h .DEFB "BI" .DEFB 'N'+080h ; The previous 32 function-type words are printed without a leading space ; The following have a leading space if they begin with a letter .DEFB 'O','R'+080h .DEFB "AN" .DEFB 'D'+080h .DEFB 03Ch,'='+080h ; <= .DEFB 03Eh,'='+080h ; >= .DEFB 03Ch,03Eh+080h ; <> .DEFB "LIN" .DEFB 'E'+080h .DEFB "THE" .DEFB 'N'+080h .DEFB 'T','O'+080h .DEFB "STE" .DEFB 'P'+080h .DEFB "DEF F" .DEFB 'N'+080h .DEFB "CA" .DEFB 'T'+080h .DEFB "FORMA" .DEFB 'T'+080h .DEFB "MOV" .DEFB 'E'+080h .DEFB "ERAS" .DEFB 'E'+080h .DEFB "OPEN " .DEFB '#'+080h .DEFB "CLOSE " .DEFB '#'+080h .DEFB "MERG" .DEFB 'E'+080h .DEFB "VERIF" .DEFB 'Y'+080h .DEFB "BEE" .DEFB 'P'+080h .DEFB "CIRCL" .DEFB 'E'+080h .DEFB "IN" .DEFB 'K'+080h .DEFB "PAPE" .DEFB 'R'+080h .DEFB "FLAS" .DEFB 'H'+080h .DEFB "BRIGH" .DEFB 'T'+080h .DEFB "INVERS" .DEFB 'E'+080h .DEFB "OVE" .DEFB 'R'+080h .DEFB "OU" .DEFB 'T'+080h .DEFB "LPRIN" .DEFB 'T'+080h .DEFB "LLIS" .DEFB 'T'+080h .DEFB "STO" .DEFB 'P'+080h .DEFB "REA" .DEFB 'D'+080h .DEFB "DAT" .DEFB 'A'+080h .DEFB "RESTOR" .DEFB 'E'+080h .DEFB "NE" .DEFB 'W'+080h .DEFB "BORDE" .DEFB 'R'+080h .DEFB "CONTINU" .DEFB 'E'+080h .DEFB "DI" .DEFB 'M'+080h .DEFB "RE" .DEFB 'M'+080h .DEFB "FO" .DEFB 'R'+080h .DEFB "GO T" .DEFB 'O'+080h .DEFB "GO SU" .DEFB 'B'+080h .DEFB "INPU" .DEFB 'T'+080h .DEFB "LOA" .DEFB 'D'+080h .DEFB "LIS" .DEFB 'T'+080h .DEFB "LE" .DEFB 'T'+080h .DEFB "PAUS" .DEFB 'E'+080h .DEFB "NEX" .DEFB 'T'+080h .DEFB "POK" .DEFB 'E'+080h .DEFB "PRIN" .DEFB 'T'+080h .DEFB "PLO" .DEFB 'T'+080h .DEFB "RU" .DEFB 'N'+080h .DEFB "SAV" .DEFB 'E'+080h .DEFB "RANDOMIZ" .DEFB 'E'+080h .DEFB 'I','F'+080h .DEFB "CL" .DEFB 'S'+080h .DEFB "DRA" .DEFB 'W'+080h .DEFB "CLEA" .DEFB 'R'+080h .DEFB "RETUR" .DEFB 'N'+080h .DEFB "COP" .DEFB 'Y'+080h ; ---------------- ; THE 'KEY' TABLES ; ---------------- ; These six look-up tables are used by the keyboard reading routine ; to decode the key values. ; ; The first table contains the maps for the 39 keys of the standard ; 40-key Spectrum keyboard. The remaining key [SHIFT 027h] is read directly. ; The keys consist of the 26 upper-case alphabetic characters, the 10 digit ; keys and the space, ENTER and symbol shift key. ; Unshifted alphabetic keys have 020h added to the value. ; The keywords for the main alphabetic keys are obtained by adding 0A5h to ; the values obtained from this table. ;; MAIN-KEYS L0205: .DEFB 042h ; B .DEFB 048h ; H .DEFB 059h ; Y .DEFB 036h ; 6 .DEFB 035h ; 5 .DEFB 054h ; T .DEFB 047h ; G .DEFB 056h ; V .DEFB 04Eh ; N .DEFB 04Ah ; J .DEFB 055h ; U .DEFB 037h ; 7 .DEFB 034h ; 4 .DEFB 052h ; R .DEFB 046h ; F .DEFB 043h ; C .DEFB 04Dh ; M .DEFB 04Bh ; K .DEFB 049h ; I .DEFB 038h ; 8 .DEFB 033h ; 3 .DEFB 045h ; E .DEFB 044h ; D .DEFB 058h ; X .DEFB 00Eh ; SYMBOL SHIFT .DEFB 04Ch ; L .DEFB 04Fh ; O .DEFB 039h ; 9 .DEFB 032h ; 2 .DEFB 057h ; W .DEFB 053h ; S .DEFB 05Ah ; Z .DEFB 020h ; SPACE .DEFB 00Dh ; ENTER .DEFB 050h ; P .DEFB 030h ; 0 .DEFB 031h ; 1 .DEFB 051h ; Q .DEFB 041h ; A ;; E-UNSHIFT ; The 26 unshifted extended mode keys for the alphabetic characters. ; The green keywords on the original keyboard. L022C: .DEFB 0E3h ; READ .DEFB 0C4h ; BIN .DEFB 0E0h ; LPRINT .DEFB 0E4h ; DATA .DEFB 0B4h ; TAN .DEFB 0BCh ; SGN .DEFB 0BDh ; ABS .DEFB 0BBh ; SQR .DEFB 0AFh ; CODE .DEFB 0B0h ; VAL .DEFB 0B1h ; LEN .DEFB 0C0h ; USR .DEFB 0A7h ; PI .DEFB 0A6h ; INKEY$ .DEFB 0BEh ; PEEK .DEFB 0ADh ; TAB .DEFB 0B2h ; SIN .DEFB 0BAh ; INT .DEFB 0E5h ; RESTORE .DEFB 0A5h ; RND .DEFB 0C2h ; CHR$ .DEFB 0E1h ; LLIST .DEFB 0B3h ; COS .DEFB 0B9h ; EXP .DEFB 0C1h ; STR$ .DEFB 0B8h ; LN ;; EXT-SHIFT ; The 26 shifted extended mode keys for the alphabetic characters. ; The red keywords below keys on the original keyboard. L0246: .DEFB 07Eh ; ~ .DEFB 0DCh ; BRIGHT .DEFB 0DAh ; PAPER .DEFB 05Ch ; \ .DEFB 0B7h ; ATN .DEFB 07Bh ; { .DEFB 07Dh ; } .DEFB 0D8h ; CIRCLE .DEFB 0BFh ; IN .DEFB 0AEh ; VAL$ .DEFB 0AAh ; SCREEN$ .DEFB 0ABh ; ATTR .DEFB 0DDh ; INVERSE .DEFB 0DEh ; OVER .DEFB 0DFh ; OUT .DEFB 07Fh ; (Copyright character) .DEFB 0B5h ; ASN .DEFB 0D6h ; VERIFY .DEFB 07Ch ; | .DEFB 0D5h ; MERGE .DEFB 05Dh ; ] .DEFB 0DBh ; FLASH .DEFB 0B6h ; ACS .DEFB 0D9h ; INK .DEFB 05Bh ; [ .DEFB 0D7h ; BEEP ;; CTL-CODES ; The ten control codes assigned to the top line of digits when the shift ; key is pressed. L0260: .DEFB 00Ch ; DELETE .DEFB 007h ; EDIT .DEFB 006h ; CAPS LOCK .DEFB 004h ; TRUE VIDEO .DEFB 005h ; INVERSE VIDEO .DEFB 008h ; CURSOR LEFT .DEFB 00Ah ; CURSOR DOWN .DEFB 00Bh ; CURSOR UP .DEFB 009h ; CURSOR RIGHT .DEFB 00Fh ; GRAPHICS ;; SYM-CODES ; The 26 red symbols assigned to the alphabetic characters of the keyboard. ; The ten single-character digit symbols are converted without the aid of ; a table using subtraction and minor manipulation. L026A: .DEFB 0E2h ; STOP .DEFB 02Ah ; * .DEFB 03Fh ; ? .DEFB 0CDh ; STEP .DEFB 0C8h ; >= .DEFB 0CCh ; TO .DEFB 0CBh ; THEN .DEFB 05Eh ; ^ .DEFB 0ACh ; AT .DEFB 02Dh ; - .DEFB 02Bh ; + .DEFB 03Dh ; = .DEFB 02Eh ; . .DEFB 02Ch ; , .DEFB 03Bh ; ; .DEFB 022h ; " .DEFB 0C7h ; <= .DEFB 03Ch ; < .DEFB 0C3h ; NOT .DEFB 03Eh ; > .DEFB 0C5h ; OR .DEFB 02Fh ; / .DEFB 0C9h ; <> .DEFB 060h ; pound .DEFB 0C6h ; AND .DEFB 03Ah ; : ;; E-DIGITS ; The ten keywords assigned to the digits in extended mode. ; The remaining red keywords below the keys. L0284: .DEFB 0D0h ; FORMAT .DEFB 0CEh ; DEF FN .DEFB 0A8h ; FN .DEFB 0CAh ; LINE .DEFB 0D3h ; OPEN # .DEFB 0D4h ; CLOSE # .DEFB 0D1h ; MOVE .DEFB 0D2h ; ERASE .DEFB 0A9h ; POINT .DEFB 0CFh ; CAT ;******************************* ;** Part 2. KEYBOARD ROUTINES ** ;******************************* ; Using shift keys and a combination of modes the Spectrum 40-key keyboard ; can be mapped to 256 input characters ; --------------------------------------------------------------------------- ; ; 0 1 2 3 4 -Bits- 4 3 2 1 0 ; PORT PORT ; ; F7FE [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] | [ 6 ] [ 7 ] [ 8 ] [ 9 ] [ 0 ] EFFE ; ^ | v ; FBFE [ Q ] [ W ] [ E ] [ R ] [ T ] | [ Y ] [ U ] [ I ] [ O ] [ P ] DFFE ; ^ | v ; FDFE [ A ] [ S ] [ D ] [ F ] [ G ] | [ H ] [ J ] [ K ] [ L ] [ ENT ] BFFE ; ^ | v ; FEFE [SHI] [ Z ] [ X ] [ C ] [ V ] | [ B ] [ N ] [ M ] [sym] [ SPC ] 7FFE ; ^ 027h 018h v ; Start End ; 00100111 00011000 ; ; --------------------------------------------------------------------------- ; The above map may help in reading. ; The neat arrangement of ports means that the B register need only be ; rotated left to work up the left hand side and then down the right ; hand side of the keyboard. When the reset bit drops into the carry ; then all 8 half-rows have been read. Shift is the first key to be ; read. The lower six bits of the shifts are unambiguous. ; ------------------------------- ; THE 'KEYBOARD SCANNING' ROUTINE ; ------------------------------- ; From keyboard and s-inkey$ ; Returns 1 or 2 keys in DE, most significant shift first if any ; key values 0-39 else 255 ;; KEY-SCAN L028E: LD L,02Fh ; initial key value ; valid values are obtained by subtracting ; eight five times. LD DE,0FFFFh ; a buffer to receive 2 keys. LD BC,0FEFEh ; the commencing port address ; B holds 11111110 initially and is also ; used to count the 8 half-rows ;; KEY-LINE L0296: IN A,(C) ; read the port to A - bits will be reset ; if a key is pressed else set. CPL ; complement - pressed key-bits are now set AND 01Fh ; apply 00011111 mask to pick up the ; relevant set bits. JR Z,L02AB ; forward to KEY-DONE if zero and therefore ; no keys pressed in row at all. LD H,A ; transfer row bits to H LD A,L ; load the initial key value to A ;; KEY-3KEYS L029F: INC D ; now test the key buffer RET NZ ; if we have collected 2 keys already ; then too many so quit. ;; KEY-BITS L02A1: SUB 008h ; subtract 8 from the key value ; cycling through key values (top = 027h) ; e.g. 2F> 27>1F>17>0F>07 ; 2E> 26>1E>16>0E>06 SRL H ; shift key bits right into carry. JR NC,L02A1 ; back to KEY-BITS if not pressed ; but if pressed we have a value (0-39d) LD D,E ; transfer a possible previous key to D LD E,A ; transfer the new key to E JR NZ,L029F ; back to KEY-3KEYS if there were more ; set bits - H was not yet zero. ;; KEY-DONE L02AB: DEC L ; cycles 2F>2E>2D>2C>2B>2A>29>28 for ; each half-row. RLC B ; form next port address e.g. FEFE > FDFE JR C,L0296 ; back to KEY-LINE if still more rows to do. LD A,D ; now test if D is still FF ? INC A ; if it is zero we have at most 1 key ; range now 001h-028h (1-40d) RET Z ; return if one key or no key. CP 028h ; is it capsshift (was 027h) ? RET Z ; return if so. CP 019h ; is it symbol shift (was 018h) ? RET Z ; return also LD A,E ; now test E LD E,D ; but first switch LD D,A ; the two keys. CP 018h ; is it symbol shift ? RET ; return (with zero set if it was). ; but with symbol shift now in D ; ---------------------- ; THE 'KEYBOARD' ROUTINE ; ---------------------- ; Called from the interrupt 50 times a second. ; .org 02BFh ;; KEYBOARD L02BF: CALL L028E ; routine KEY-SCAN RET NZ ; return if invalid combinations ; then decrease the counters within the two key-state maps ; as this could cause one to become free. ; if the keyboard has not been pressed during the last five interrupts ; then both sets will be free. LD HL,05C00h ; point to KSTATE-0 ;; K-ST-LOOP L02C6: BIT 7,(HL) ; is it free ? (i.e. 0FFh) JR NZ,L02D1 ; forward to K-CH-SET if so INC HL ; address the 5-counter DEC (HL) ; decrease the counter DEC HL ; step back JR NZ,L02D1 ; forward to K-CH-SET if not at end of count LD (HL),0FFh ; else mark this particular map free. ;; K-CH-SET L02D1: LD A,L ; make a copy of the low address byte. LD HL,05C04h ; point to KSTATE-4 ; (ld l,004h would do) CP L ; have both sets been considered ? JR NZ,L02C6 ; back to K-ST-LOOP to consider this 2nd set ; now the raw key (0-38d) is converted to a main key (uppercase). CALL L031E ; routine K-TEST to get main key in A RET NC ; return if just a single shift LD HL,05C00h ; point to KSTATE-0 CP (HL) ; does the main key code match ? JR Z,L0310 ; forward to K-REPEAT if so ; if not consider the second key map. EX DE,HL ; save kstate-0 in de LD HL,05C04h ; point to KSTATE-4 CP (HL) ; does the main key code match ? JR Z,L0310 ; forward to K-REPEAT if so ; having excluded a repeating key we can now consider a new key. ; the second set is always examined before the first. BIT 7,(HL) ; is the key map free ? JR NZ,L02F1 ; forward to K-NEW if so. EX DE,HL ; bring back KSTATE-0 BIT 7,(HL) ; is it free ? RET Z ; return if not. ; as we have a key but nowhere to put it yet. ; continue or jump to here if one of the buffers was free. ;; K-NEW L02F1: LD E,A ; store key in E LD (HL),A ; place in free location INC HL ; advance to the interrupt counter LD (HL),005h ; and initialize counter to 5 INC HL ; advance to the delay LD A,(05C09h) ; pick up the system variable REPDEL LD (HL),A ; and insert that for first repeat delay. INC HL ; advance to last location of state map. LD C,(IY+007h) ; pick up MODE (3 bytes) LD D,(IY+001h) ; pick up FLAGS (3 bytes) PUSH HL ; save state map location ; Note. could now have used, to avoid IY, ; ld l,041h; ld c,(hl); ld l,03Bh; ld d,(hl). ; six and two threes of course. CALL L0333 ; routine K-DECODE POP HL ; restore map pointer LD (HL),A ; put the decoded key in last location of map. ;; K-END L0308: LD (05C08h),A ; update LASTK system variable. SET 5,(IY+001h) ; update FLAGS - signal a new key. RET ; return to interrupt routine. ; ----------------------- ; THE 'REPEAT KEY' BRANCH ; ----------------------- ; A possible repeat has been identified. HL addresses the raw key. ; The last location of the key map holds the decoded key from the first ; context. This could be a keyword and, with the exception of NOT a repeat ; is syntactically incorrect and not really desirable. ;; K-REPEAT L0310: INC HL ; increment the map pointer to second location. LD (HL),005h ; maintain interrupt counter at 5. INC HL ; now point to third location. DEC (HL) ; decrease the REPDEL value which is used to ; time the delay of a repeat key. RET NZ ; return if not yet zero. LD A,(05C0Ah) ; fetch the system variable value REPPER. LD (HL),A ; for subsequent repeats REPPER will be used. INC HL ; advance ; LD A,(HL) ; pick up the key decoded possibly in another ; context. ; Note. should compare with 0A5h (RND) and make ; a simple return if this is a keyword. ; e.g. cp $a5; ret nc; (3 extra bytes) JR L0308 ; back to K-END ; ---------------------- ; THE 'KEY-TEST' ROUTINE ; ---------------------- ; also called from s-inkey$ ; begin by testing for a shift with no other. ;; K-TEST L031E: LD B,D ; load most significant key to B ; will be 0FFh if not shift. LD D,00h ; and reset D to index into main table LD A,E ; load least significant key from E CP 027h ; is it higher than 39d i.e. FF RET NC ; return with just a shift (in B now) CP 018h ; is it symbol shift ? JR NZ,L032C ; forward to K-MAIN if not ; but we could have just symbol shift and no other BIT 7,B ; is other key 0FFh (ie not shift) RET NZ ; return with solitary symbol shift ;; K-MAIN L032C: LD HL,L0205 ; address: MAIN-KEYS ADD HL,DE ; add offset 0-38 LD A,(HL) ; pick up main key value SCF ; set carry flag RET ; return (B has other key still) ; ---------------------------------- ; THE 'KEYBOARD DECODING' SUBROUTINE ; ---------------------------------- ; also called from s-inkey$ ;; K-DECODE L0333: LD A,E ; pick up the stored main key CP 03Ah ; an arbitrary point between digits and letters JR C,L0367 ; forward to K-DIGIT with digits, space, enter. DEC C ; decrease MODE ( 0='KLC', 1='E', 2='G') JP M,L034F ; to K-KLC-LET if was zero JR Z,L0341 ; to K-E-LET if was 1 for extended letters. ; proceed with graphic codes. ; Note. should selectively drop return address if code > 'U' (055h). ; i.e. abort the KEYBOARD call. ; e.g. cp 'V'; jr c,addit; pop af ;pop af ;;addit etc. (6 extra bytes). ; (s-inkey$ never gets into graphics mode.) ;; addit ADD A,04Fh ; add offset to augment 'A' to graphics A say. RET ; return. ; Note. ( but [GRAPH] V gives RND, etc ). ; --- ; the jump was to here with extended mode with uppercase A-Z. ;; K-E-LET L0341: LD HL,L022C-041h ; base address of E-UNSHIFT L022c. ; ( 001EBh in standard ROM ). INC B ; test B is it empty i.e. not a shift. JR Z,L034A ; forward to K-LOOK-UP if neither shift. LD HL,L0246-041h ; Address: 00205h L0246-041h EXT-SHIFT base ;; K-LOOK-UP L034A: LD D,00h ; prepare to index. ADD HL,DE ; add the main key value. LD A,(HL) ; pick up other mode value. RET ; return. ; --- ; the jump was here with mode = 0 ;; K-KLC-LET L034F: LD HL,L026A-041h ; prepare base of sym-codes BIT 0,B ; shift=027h sym-shift=018h JR Z,L034A ; back to K-LOOK-UP with symbol-shift BIT 3,D ; test FLAGS is it 'K' mode (from OUT-CURS) JR Z,L0364 ; skip to K-TOKENS if so BIT 3,(IY+030h) ; test FLAGS2 - consider CAPS LOCK ? RET NZ ; return if so with main code. INC B ; is shift being pressed ? ; result zero if not RET NZ ; return if shift pressed. ADD A,020h ; else convert the code to lower case. RET ; return. ; --- ; the jump was here for tokens ;; K-TOKENS L0364: ADD A,0A5h ; add offset to main code so that 'A' ; becomes 'NEW' etc. RET ; return. ; --- ; the jump was here with digits, space, enter and symbol shift (< $xx) ;; K-DIGIT L0367: CP 030h ; is it '0' or higher ? RET C ; return with space, enter and symbol-shift DEC C ; test MODE (was 0='KLC', 1='E', 2='G') JP M,L039D ; jump to K-KLC-DGT if was 0. JR NZ,L0389 ; forward to K-GRA-DGT if mode was 2. ; continue with extended digits 0-9. LD HL,L0284-030h ; 00254h - base of E-DIGITS BIT 5,B ; test - shift=027h sym-shift=018h JR Z,L034A ; to K-LOOK-UP if sym-shift CP 038h ; is character '8' ? JR NC,L0382 ; to K-8-&-9 if greater than '7' SUB 020h ; reduce to ink range 010h-017h INC B ; shift ? RET Z ; return if not. ADD A,008h ; add 8 to give paper range 018h - 01Fh RET ; return ; --- ; 89 ;; K-8-&-9 L0382: SUB 036h ; reduce to 02 and 03 bright codes INC B ; test if shift pressed. RET Z ; return if not. ADD A,0FEh ; subtract 2 setting carry RET ; to give 0 and 1 flash codes. ; --- ; graphics mode with digits ;; K-GRA-DGT L0389: LD HL,L0260-030h ; 00230h base address of CTL-CODES CP 039h ; is key '9' ? JR Z,L034A ; back to K-LOOK-UP - changed to 00Fh, GRAPHICS. CP 030h ; is key '0' ? JR Z,L034A ; back to K-LOOK-UP - changed to 00Ch, delete. ; for keys '0' - '7' we assign a mosaic character depending on shift. AND 007h ; convert character to number. 0 - 7. ADD A,080h ; add offset - they start at 080h INC B ; destructively test for shift RET Z ; and return if not pressed. XOR 00Fh ; toggle bits becomes range 088h-08Fh RET ; return. ; --- ; now digits in 'KLC' mode ;; K-KLC-DGT L039D: INC B ; return with digit codes if neither RET Z ; shift key pressed. BIT 5,B ; test for caps shift. LD HL,L0260-030h ; prepare base of table CTL-CODES. JR NZ,L034A ; back to K-LOOK-UP if shift pressed. ; must have been symbol shift SUB 010h ; for ASCII most will now be correct ; on a standard typewriter. CP 022h ; but '@' is not - see below. JR Z,L03B2 ; forward to K-@-CHAR if so CP 020h ; '_' is the other one that fails RET NZ ; return if not. LD A,05Fh ; substitute ASCII '_' RET ; return. ; --- ;; K-@-CHAR L03B2: LD A,040h ; substitute ASCII '@' RET ; return. ; ------------------------------------------------------------------------ ; The Spectrum Input character keys. One or two are abbreviated. ; From 00h Flash 0 to 0FFh COPY. The routine above has decoded all these. ; | 00 Fl0| 01 Fl1| 02 Br0| 03 Br1| 04 In0| 05 In1| 06 CAP| 07 EDT| ; | 08 LFT| 09 RIG| 0A DWN| 0B UP | 0C DEL| 0D ENT| 0E SYM| 0F GRA| ; | 10 Ik0| 11 Ik1| 12 Ik2| 13 Ik3| 14 Ik4| 15 Ik5| 16 Ik6| 17 Ik7| ; | 18 Pa0| 19 Pa1| 1A Pa2| 1B Pa3| 1C Pa4| 1D Pa5| 1E Pa6| 1F Pa7| ; | 20 SP | 21 ! | 22 " | 23 # | 24 $ | 25 % | 26 & | 27 ' | ; | 28 ( | 29 ) | 2A * | 2B + | 2C , | 2D - | 2E . | 2F / | ; | 30 0 | 31 1 | 32 2 | 33 3 | 34 4 | 35 5 | 36 6 | 37 7 | ; | 38 8 | 39 9 | 3A : | 3B ; | 3C < | 3D = | 3E > | 3F ? | ; | 40 @ | 41 A | 42 B | 43 C | 44 D | 45 E | 46 F | 47 G | ; | 48 H | 49 I | 4A J | 4B K | 4C L | 4D M | 4E N | 4F O | ; | 50 P | 51 Q | 52 R | 53 S | 54 T | 55 U | 56 V | 57 W | ; | 58 X | 59 Y | 5A Z | 5B [ | 5C \ | 5D ] | 5E ^ | 5F _ | ; | 60 £ | 61 a | 62 b | 63 c | 64 d | 65 e | 66 f | 67 g | ; | 68 h | 69 i | 6A j | 6B k | 6C l | 6D m | 6E n | 6F o | ; | 70 p | 71 q | 72 r | 73 s | 74 t | 75 u | 76 v | 77 w | ; | 78 x | 79 y | 7A z | 7B { | 7C | | 7D } | 7E ~ | 7F © | ; | 80 128| 81 129| 82 130| 83 131| 84 132| 85 133| 86 134| 87 135| ; | 88 136| 89 137| 8A 138| 8B 139| 8C 140| 8D 141| 8E 142| 8F 143| ; | 90 [A]| 91 [B]| 92 [C]| 93 [D]| 94 [E]| 95 [F]| 96 [G]| 97 [H]| ; | 98 [I]| 99 [J]| 9A [K]| 9B [L]| 9C [M]| 9D [N]| 9E [O]| 9F [P]| ; | A0 [Q]| A1 [R]| A2 [S]| A3 [T]| A4 [U]| A5 RND| A6 IK$| A7 PI | ; | A8 FN | A9 PNT| AA SC$| AB ATT| AC AT | AD TAB| AE VL$| AF COD| ; | B0 VAL| B1 LEN| B2 SIN| B3 COS| B4 TAN| B5 ASN| B6 ACS| B7 ATN| ; | B8 LN | B9 EXP| BA INT| BB SQR| BC SGN| BD ABS| BE PEK| BF IN | ; | C0 USR| C1 ST$| C2 CH$| C3 NOT| C4 BIN| C5 OR | C6 AND| C7 <= | ; | C8 >= | C9 <> | CA LIN| CB THN| CC TO | CD STP| CE DEF| CF CAT| ; | D0 FMT| D1 MOV| D2 ERS| D3 OPN| D4 CLO| D5 MRG| D6 VFY| D7 BEP| ; | D8 CIR| D9 INK| DA PAP| DB FLA| DC BRI| DD INV| DE OVR| DF OUT| ; | E0 LPR| E1 LLI| E2 STP| E3 REA| E4 DAT| E5 RES| E6 NEW| E7 BDR| ; | E8 CON| E9 DIM| EA REM| EB FOR| EC GTO| ED GSB| EE INP| EF LOA| ; | F0 LIS| F1 LET| F2 PAU| F3 NXT| F4 POK| F5 PRI| F6 PLO| F7 RUN| ; | F8 SAV| F9 RAN| FA IF | FB CLS| FC DRW| FD CLR| FE RET| FF CPY| ; Note that for simplicity, Sinclair have located all the control codes ; below the space character. ; ASCII DEL, 07Fh, has been made a copyright symbol. ; Also 060h, '`', not used in BASIC but used in other languages, has been ; allocated the local currency symbol for the relevant country - ; £ in most Spectrums. ; ------------------------------------------------------------------------ ;********************************** ;** Part 3. LOUDSPEAKER ROUTINES ** ;********************************** ; Documented by Alvin Albrecht. ; ------------------------------ ; Routine to control loudspeaker ; ------------------------------ ; Outputs a square wave of given duration and frequency ; to the loudspeaker. ; Enter with: DE = #cycles - 1 ; HL = tone period as described next ; ; The tone period is measured in T states and consists of ; three parts: a coarse part (H register), a medium part ; (bits 7..2 of L) and a fine part (bits 1..0 of L) which ; contribute to the waveform timing as follows: ; ; coarse medium fine ; duration of low = 118 + 1024*H + 16*(L>>2) + 4*(L&0x3) ; duration of hi = 118 + 1024*H + 16*(L>>2) + 4*(L&0x3) ; Tp = tone period = 236 + 2048*H + 32*(L>>2) + 8*(L&0x3) ; = 236 + 2048*H + 8*L = 236 + 8*HL ; ; As an example, to output five seconds of middle C (261.624 Hz): ; (a) Tone period = 1/261.624 = 3.822ms ; (b) Tone period in T-States = 3.822ms*fCPU = 13378 ; where fCPU = clock frequency of the CPU = 3.5MHz ; © Find H and L for desired tone period: ; HL = (Tp - 236) / 8 = (13378 - 236) / 8 = 1643 = 0x066B ; (d) Tone duration in cycles = 5s/3.822ms = 1308 cycles ; DE = 1308 - 1 = 0x051B ; ; The resulting waveform has a duty ratio of exactly 50%. ; ; ;; BEEPER L03B5: DI ; Disable Interrupts so they don't disturb timing LD A,L ; SRL L ; SRL L ; L = medium part of tone period CPL ; AND 003h ; A = 3 - fine part of tone period LD C,A ; LD B,00h ; LD IX,L03D1 ; Address: BE-IX+3 ADD IX,BC ; IX holds address of entry into the loop ; the loop will contain 0-3 NOPs, implementing ; the fine part of the tone period. LD A,(05C48h) ; BORDCR AND 038h ; bits 5..3 contain border colour RRCA ; border colour bits moved to 2..0 RRCA ; to match border bits on port #FE RRCA ; OR 008h ; bit 3 set (tape output bit on port #FE) ; for loud sound output ;; BE-IX+3 L03D1: NOP ;(4) ; optionally executed NOPs for small ; adjustments to tone period ;; BE-IX+2 L03D2: NOP ;(4) ; ;; BE-IX+1 L03D3: NOP ;(4) ; ;; BE-IX+0 L03D4: INC B ;(4) ; INC C ;(4) ; ;; BE-H&L-LP L03D6: DEC C ;(4) ; timing loop for duration of JR NZ,L03D6 ;(12/7); high or low pulse of waveform LD C,03Fh ;(7) ; DEC B ;(4) ; JP NZ,L03D6 ;(10) ; to BE-H&L-LP XOR 010h ;(7) ; toggle output beep bit OUT (0FEh),A ;(11) ; output pulse LD B,H ;(4) ; B = coarse part of tone period LD C,A ;(4) ; save port #FE output byte BIT 4,A ;(8) ; if new output bit is high, go JR NZ,L03F2 ;(12/7); to BE-AGAIN LD A,D ;(4) ; one cycle of waveform has completed OR E ;(4) ; (low->low). if cycle countdown = 0 JR Z,L03F6 ;(12/7); go to BE-END LD A,C ;(4) ; restore output byte for port #FE LD C,L ;(4) ; C = medium part of tone period DEC DE ;(6) ; decrement cycle count JP (IX) ;(8) ; do another cycle ;; BE-AGAIN ; halfway through cycle L03F2: LD C,L ;(4) ; C = medium part of tone period INC C ;(4) ; adds 16 cycles to make duration of high = duration of low JP (IX) ;(8) ; do high pulse of tone ;; BE-END L03F6: EI ; Enable Interrupts RET ; ; ------------------ ; THE 'BEEP' COMMAND ; ------------------ ; BASIC interface to BEEPER subroutine. ; Invoked in BASIC with: ; BEEP dur, pitch ; where dur = duration in seconds ; pitch = # of semitones above/below middle C ; ; Enter with: pitch on top of calculator stack ; duration next on calculator stack ; ;; beep L03F8: RST 28H ;; FP-CALC .DEFB 031h ;;duplicate ; duplicate pitch .DEFB 027h ;;int ; convert to integer .DEFB 0C0h ;;st-mem-0 ; store integer pitch to memory 0 .DEFB 003h ;;subtract ; calculate fractional part of pitch = fp_pitch - int_pitch .DEFB 034h ;;stk-data ; push constant .DEFB 0ECh ;;Exponent: 07Ch, Bytes: 4 ; constant = 0.05762265 .DEFB 06Ch,098h,01Fh,0F5h ;;(06Ch,098h,01Fh,0F5h) .DEFB 004h ;;multiply ; compute: .DEFB 0A1h ;;stk-one ; 1 + 0.05762265 * fraction_part(pitch) .DEFB 00Fh ;;addition .DEFB 038h ;;end-calc ; leave on calc stack LD HL,05C92h ; MEM-0: number stored here is in 16 bit integer format (pitch) ; 0, 0/FF (pos/neg), LSB, MSB, 0 ; LSB/MSB is stored in two's complement ; In the following, the pitch is checked if it is in the range -128<=p<=127 LD A,(HL) ; First byte must be zero, otherwise AND A ; error in integer conversion JR NZ,L046C ; to REPORT-B INC HL ; LD C,(HL) ; C = pos/neg flag = 0/FF INC HL ; LD B,(HL) ; B = LSB, two's complement LD A,B ; RLA ; SBC A,A ; A = 0/FF if B is pos/neg CP C ; must be the same as C if the pitch is -128<=p<=127 JR NZ,L046C ; if no, error REPORT-B INC HL ; if -128<=p<=127, MSB will be 0/FF if B is pos/neg CP (HL) ; verify this JR NZ,L046C ; if no, error REPORT-B ; now we know -128<=p<=127 LD A,B ; A = pitch + 60 ADD A,03Ch ; if -60<=pitch<=67, JP P,L0425 ; goto BE-i-OK JP PO,L046C ; if pitch <= 67 goto REPORT-B ; lower bound of pitch set at -60 ;; BE-I-OK ; here, -60<=pitch<=127 ; and A=pitch+60 -> 0<=A<=187 L0425: LD B,0FAh ; 6 octaves below middle C ;; BE-OCTAVE ; A=# semitones above 5 octaves below middle C L0427: INC B ; increment octave SUB 00Ch ; 12 semitones = one octave JR NC,L0427 ; to BE-OCTAVE ADD A,00Ch ; A = # semitones above C (0-11) PUSH BC ; B = octave displacement from middle C, 2's complement: -5<=B<=10 LD HL,L046E ; Address: semi-tone CALL L3406 ; routine LOC-MEM ; HL = 5*A + 0046Eh CALL L33B4 ; routine STACK-NUM ; read FP value (freq) from semitone table (HL) and push onto calc stack RST 28H ;; FP-CALC .DEFB 004h ;;multiply mult freq by 1 + 0.0576 * fraction_part(pitch) stacked earlier ;; thus taking into account fractional part of pitch. ;; the number 0.0576*frequency is the distance in Hz to the next ;; note (verify with the frequencies recorded in the semitone ;; table below) so that the fraction_part of the pitch does ;; indeed represent a fractional distance to the next note. .DEFB 038h ;;end-calc HL points to first byte of fp num on stack = middle frequency to generate POP AF ; A = octave displacement from middle C, 2's complement: -5<=A<=10 ADD A,(HL) ; increase exponent by A (equivalent to multiplying by 2^A) LD (HL),A ; RST 28H ;; FP-CALC .DEFB 0C0h ;;st-mem-0 ; store frequency in memory 0 .DEFB 002h ;;delete ; remove from calc stack .DEFB 031h ;;duplicate ; duplicate duration (seconds) .DEFB 038h ;;end-calc CALL L1E94 ; routine FIND-INT1 ; FP duration to A CP 00Bh ; if dur > 10 seconds, JR NC,L046C ; goto REPORT-B ;;; The following calculation finds the tone period for HL and the cycle count ;;; for DE expected in the BEEPER subroutine. From the example in the BEEPER comments, ;;; ;;; HL = ((fCPU / f) - 236) / 8 = fCPU/8/f - 236/8 = 437500/f -29.5 ;;; DE = duration * frequency - 1 ;;; ;;; Note the different constant (30.125) used in the calculation of HL ;;; below. This is probably an error. RST 28H ;; FP-CALC .DEFB 0E0h ;;get-mem-0 ; push frequency .DEFB 004h ;;multiply ; result1: #cycles = duration * frequency .DEFB 0E0h ;;get-mem-0 ; push frequency .DEFB 034h ;;stk-data ; push constant .DEFB 080h ;;Exponent 093h, Bytes: 3 ; constant = 437500 .DEFB 043h,055h,09Fh,080h ;;(055h,09Fh,080h,00h) .DEFB 001h ;;exchange ; frequency on top .DEFB 005h ;;division ; 437500 / frequency .DEFB 034h ;;stk-data ; push constant .DEFB 035h ;;Exponent: 085h, Bytes: 1 ; constant = 30.125 .DEFB 071h ;;(071h,00h,00h,00h) .DEFB 003h ;;subtract ; result2: tone_period(HL) = 437500 / freq - 30.125 .DEFB 038h ;;end-calc CALL L1E99 ; routine FIND-INT2 PUSH BC ; BC = tone_period(HL) CALL L1E99 ; routine FIND-INT2, BC = #cycles to generate POP HL ; HL = tone period LD D,B ; LD E,C ; DE = #cycles LD A,D ; OR E ; RET Z ; if duration = 0, skip BEEP and avoid 65536 cycle ; boondoggle that would occur next DEC DE ; DE = #cycles - 1 JP L03B5 ; to BEEPER ; --- ;; REPORT-B L046C: RST 08H ; ERROR-1 .DEFB 00Ah ; Error Report: Integer out of range ; --------------------- ; THE 'SEMI-TONE' TABLE ; --------------------- ; ; Holds frequencies corresponding to semitones in middle octave. ; To move n octaves higher or lower, frequencies are multiplied by 2^n. ;; semi-tone five byte fp decimal freq note (middle) L046E: .DEFB 089h, 002h, 0D0h, 012h, 086h; 261.625565290 C .DEFB 089h, 00Ah, 097h, 060h, 075h; 277.182631135 C# .DEFB 089h, 012h, 0D5h, 017h, 01Fh; 293.664768100 D .DEFB 089h, 01Bh, 090h, 041h, 002h; 311.126983881 D# .DEFB 089h, 024h, 0D0h, 053h, 0CAh; 329.627557039 E .DEFB 089h, 02Eh, 09Dh, 036h, 0B1h; 349.228231549 F .DEFB 089h, 038h, 0FFh, 049h, 03Eh; 369.994422674 F# .DEFB 089h, 043h, 0FFh, 06Ah, 073h; 391.995436072 G .DEFB 089h, 04Fh, 0A7h, 00h, 054h; 415.304697513 G# .DEFB 089h, 05Ch, 00h, 00h, 00h; 440.000000000 A .DEFB 089h, 069h, 014h, 0F6h, 024h; 466.163761616 A# .DEFB 089h, 076h, 0F1h, 010h, 005h; 493.883301378 B ; "Music is the hidden mathematical endeavour of a soul unconscious it ; is calculating" - Gottfried Wilhelm Liebnitz 1646 - 1716 ;**************************************** ;** Part 4. CASSETTE HANDLING ROUTINES ** ;**************************************** ; These routines begin with the service routines followed by a single ; command entry point. ; The first of these service routines is a curiosity. ; ----------------------- ; THE 'ZX81 NAME' ROUTINE ; ----------------------- ; This routine fetches a filename in ZX81 format and is not used by the ; cassette handling routines in this ROM. ;; zx81-name L04AA: CALL L24FB ; routine SCANNING to evaluate expression. LD A,(05C3Bh) ; fetch system variable FLAGS. ADD A,A ; test bit 7 - syntax, bit 6 - result type. JP M,L1C8A ; to REPORT-C if not string result ; 'Nonsense in BASIC'. POP HL ; drop return address. RET NC ; return early if checking syntax. PUSH HL ; re-save return address. CALL L2BF1 ; routine STK-FETCH fetches string parameters. LD H,D ; transfer start of filename LD L,E ; to the HL register. DEC C ; adjust to point to last character and RET M ; return if the null string. ; or multiple of 256! ADD HL,BC ; find last character of the filename. ; and also clear carry. SET 7,(HL) ; invert it. RET ; return. ; ========================================= ; ; PORT 254 (0FEh) ; ; spk mic { border } ; ___ ___ ___ ___ ___ ___ ___ ___ ; PORT | | | | | | | | | ; 254 | | | | | | | | | ; 0FEh |___|___|___|___|___|___|___|___| ; 7 6 5 4 3 2 1 0 ; ; ---------------------------------- ; Save header and program/data bytes ; ---------------------------------- ; This routine saves a section of data. It is called from SA-CTRL to save the ; seventeen bytes of header data. It is also the exit route from that routine ; when it is set up to save the actual data. ; On entry - ; HL points to start of data. ; IX points to descriptor. ; The accumulator is set to 00h for a header, 0FFh for data. .org 04C2h ;; SA-BYTES ;!!!!!!!!!!!!!!!!!! L04C2: LD HL,L053F ; address: SA/LD-RET PUSH HL ; is pushed as common exit route. ; however there is only one non-terminal exit ; point. ;LD HL,01F80h ; a timing constant H=01Fh, L=080h ; inner and outer loop counters ; a five second lead-in is used for a header. ;BIT 7,A ; test one bit of accumulator. ; (AND A ?) ;JR Z,L04D0 ; skip to SA-FLAG if a header is being saved. ; else is data bytes and a shorter lead-in is used. ;LD HL,00C98h ; another timing value H=00Ch, L=098h. ; a two second lead-in is used for the data. ;; SA-FLAG L04D0: ;EX AF,AF' ; save flag DI ; disable interrupts ;!!!! zapis długości (na taśmie tego nie ma, ale jest w plikach .TAP) push af ; trzeba przechować akumulator, żeby zwrócić wynik push hl ; przechowanie HL na wszelki wypadek inc de ; długość +2 - typ+suma kontrolna inc de ld l,e ; bajt do zapisania w L (nie w A, jak w innych przypadkach!) ;call print_sa_ld_byte call printCharL ld l,d ;call print_sa_ld_byte call printCharL ;ld a,e ; liczba bajtów w bloku LSB ;call printB ;ld hl,data_txt ;call printtxt ;ld a,d ; ; liczba bajtów w bloku MSB ;call printB ;ld hl,data_txt ;call printtxt dec de dec de pop hl pop af ;!!! zmieniona kolejność INC DE ; increase length by one. DEC IX ; decrease start. ;LD A,002h ; select red for border, microphone bit on. ;LD B,A ; also does as an initial slight counter value. ;; SA-LEADER ;!!!!!!!!!!!!!!!!!!!!!!!! L04D8: ;DJNZ L04D8 ; self loop to SA-LEADER for delay. ; after initial loop, count is 0A4h (or 0A3h) ;nop ;nop ;OUT (0FEh),A ; output byte 002h/00Dh to tape port. ;XOR 00Fh ; switch from RED (mic on) to CYAN (mic off). ;LD B,0A4h ; hold count. also timed instruction. ;DEC L ; originally 080h or 098h. ; but subsequently cycles 256 times. ;JR NZ,L04D8 ; back to SA-LEADER until L is zero. ; the outer loop is counted by H ;DEC B ; decrement count ;DEC H ; originally twelve or thirty-one. ;JP P,L04D8 ; back to SA-LEADER until H becomes 0FFh ; now send a sync pulse. At this stage mic is off and A holds value ; for mic on. ; A sync pulse is much shorter than the steady pulses of the lead-in. ;LD B,02Fh ; another short timed delay. ;; SA-SYNC-1 ;!!!!!!!!!!!!!!!!! L04EA: ;DJNZ L04EA ; self loop to SA-SYNC-1 ;nop ;nop ;OUT (0FEh),A ; switch to mic on and red. ;LD A,00Dh ; prepare mic off - cyan ;LD B,037h ; another short timed delay. ;; SA-SYNC-2 ;!!!!!!!!!!!!!!!!!!! L04F2: ;DJNZ L04F2 ; self loop to SA-SYNC-2 ;nop ;nop ;OUT (0FEh),A ; output mic off, cyan border. ;LD BC,03B0Eh ; B=03Bh time(*), C=00Eh, YELLOW, MIC OFF. ; ;!!!!!!!!!!!!!!!! moze niepotrzebne ;EX AF,AF' ; restore saved flag ; which is 1st byte to be saved. LD L,A ; and transfer to L. ; the initial parity is A, 0FFh or 00h. JP L0507 ; JUMP forward to SA-START -> ; the mid entry point of loop. ; ------------------------- ; During the save loop a parity byte is maintained in H. ; the save loop begins by testing if reduced length is zero and if so ; the final parity byte is saved reducing count to 0FFFFh. ;; SA-LOOP L04FE: LD A,D ; fetch high byte OR E ; test against low byte. JR Z,L050E ; forward to SA-PARITY if zero. LD L,(IX+00h) ; load currently addressed byte to L. ;; SA-LOOP-P L0505: LD A,H ; fetch parity byte. XOR L ; exclusive or with new byte. ; -> the mid entry point of loop. ;; SA-START L0507: LD H,A ; put parity byte in H. ;LD A,001h ; prepare blue, mic=on. ;SCF ; set carry flag ready to rotate in. JP L0525 ; JUMP forward to SA-8-BITS -8-> ; --- ;; SA-PARITY L050E: LD L,H ; transfer the running parity byte to L and JR L0505 ; back to SA-LOOP-P ; to output that byte before quitting normally. ; --- ; The entry point to save yellow part of bit. ; A bit consists of a period with mic on and blue border followed by ; a period of mic off with yellow border. ; Note. since the DJNZ instruction does not affect flags, the zero flag is ; used to indicate which of the two passes is in effect and the carry ; maintains the state of the bit to be saved. ;; SA-BIT-2 ;L0511: LD A,C ; fetch 'mic on and yellow' which is ; held permanently in C. ; BIT 7,B ; set the zero flag. B holds 03Eh. ; The entry point to save 1 entire bit. For first bit B holds 03Bh(*). ; Carry is set if saved bit is 1. zero is reset NZ on entry. ;; SA-BIT-1 ;!!!!!!!!!!!!!!!!! L0514: ;DJNZ L0514 ; self loop for delay to SA-BIT-1 ; nop ; nop ; JR NC,L051C ; forward to SA-OUT if bit is 0. ; but if bit is 1 then the mic state is held for longer. ; LD B,042h ; set timed delay. (66 decimal) ;; SA-SET ;!!!!!!!!!!!!!!!!! L051A: ;DJNZ L051A ; self loop to SA-SET ; (roughly an extra 66*13 clock cycles) ; nop ; nop ;; SA-OUT L051C: ;OUT (0FEh),A ; blue and mic on OR yellow and mic off. ;LD B,03Eh ; set up delay ;JR NZ,L0511 ; back to SA-BIT-2 if zero reset NZ (first pass) ; proceed when the blue and yellow bands have been output. ;DEC B ; change value 03Eh to 03Dh. ;XOR A ; clear carry flag (ready to rotate in). ;INC A ; reset zero flag i.e. NZ. ; -8-> ;; SA-8-BITS L0525: ;RL L ; rotate left through carry ; C<76543210<C ;JP NZ,L0514 ; JUMP back to SA-BIT-1 ; until all 8 bits done. ; !!!! KR ; zapis bajtu do SIO ;call print_sa_ld_byte call printCharL ; when the initial set carry is passed out again then a byte is complete. DEC DE ; decrease length INC IX ; increase byte pointer ;LD B,031h ; set up timing. ;!!!!!!!!! do rozważenia, czy to jest potrzebne ;LD A,07Fh ; test the space key and ;IN A,(0FEh) ; return to common exit (to restore border) ;RRA ; if a space is pressed ;RET NC ; return to SA/LD-RET. - - > ; now test if byte counter has reached 0FFFFh. LD A,D ; fetch high byte INC A ; increment. JP NZ,L04FE ; JUMP to SA-LOOP if more bytes. ;LD B,03Bh ; a final delay. ;; SA-DELAY ;!!!!!!!!!!!! L053C: ;DJNZ L053C ; self loop to SA-DELAY ;nop ;nop RET ; return - - > ; ------------------------------ ; THE 'SAVE/LOAD RETURN' ROUTINE ; ------------------------------ ; The address of this routine is pushed on the stack prior to any load/save ; operation and it handles normal completion with the restoration of the ; border and also abnormal termination when the break key, or to be more ; precise the space key is pressed during a tape operation. ; ; - - > .org 053Fh ;; SA/LD-RET L053F: PUSH AF ; preserve accumulator throughout. ;!!!!!!!!!!!!!!!!!! ;LD A,(05C48h) ; fetch border colour from BORDCR. ;AND 038h ; mask off paper bits. ;RRCA ; rotate ;RRCA ; to the ;RRCA ; range 0-7. ;OUT (0FEh),A ; change the border colour. ;LD A,07Fh ; read from port address 07FFEh the ;IN A,(0FEh) ; row with the space key at outside. ;RRA ; test for space key pressed. scf EI ; enable interrupts ;JR C,L0554 ; forward to SA/LD-END if not jr L0554 .org 0552h ; martwy kod po usunięciu odczytu spacji (powyżej) ;; REPORT-Da L0552: RST 08H ; ERROR-1 .DEFB 00Ch ; Error Report: BREAK - CONT repeats ; --- ;; SA/LD-END L0554: POP AF ; restore the accumulator. RET ; return. ; ------------------------------------ ; Load header or block of information ; ------------------------------------ ; This routine is used to load bytes and on entry A is set to 00h for a ; header or to 0FFh for data. IX points to the start of receiving location ; and DE holds the length of bytes to be loaded. If, on entry the carry flag ; is set then data is loaded, if reset then it is verified. ;!!!!!!!!!!!!!!!1 .org 0556h ;; LD-BYTES L0556: INC D ; reset the zero flag without disturbing carry. EX AF,AF' ; preserve entry flags. DEC D ; restore high byte of length. DI ; disable interrupts ;LD A,00Fh ; make the border white and mic off. ;OUT (0FEh),A ; output to port. LD HL,L053F ; Address: SA/LD-RET PUSH HL ; is saved on stack as terminating routine. call print_block_header ld_len_lsb: call get_char jr c, ld_len_lsb ; LSB długości bloku ld l,a ;call print_sa_ld_byte ld_len_msb: call get_char jr c, ld_len_msb ; MSB długości bloku ld l,a ;call print_sa_ld_byte ld_flag: call get_char jr c, ld_flag ; flaga ld l,a ;call print_sa_ld_byte ld_loop: call get_char jr c,ld_loop ld l,a ;call print_sa_ld_byte ; odtworzenie flagi carry - 0 oznacza weryfikację (na przyszłość) ex af,af' jr nc,ld_cont ; zapisanie flagi ex af,af' ld (ix+00h),L ld_cont: inc ix dec de ld a,d ; sposób na sprawdzenie obu rejestrów - muszą być =0, żeby Z=1 or e ; jr nz,ld_loop ld_checksum: call get_char jr c, ld_checksum ; suma kontrolna ld l,a call print_sa_ld_byte ; the reading of the EAR bit (D6) will always be preceded by a test of the ; space key (D0), so store the initial post-test state. ;IN A,(0FEh) ; read the ear state - bit 6. ;RRA ; rotate to bit 5. ;AND 020h ; isolate this bit. ;OR 002h ; combine with red border colour. ;LD C,A ; and store initial state long-term in C. ;CP A ; set the zero flag. ; ;!!! być może na przyszłość można przewidzieć sprawdzanie spacji ;; LD-BREAK L056B: ;RET NZ ; return if at any time space is pressed. ;; LD-START L056C: ;CALL L05E7 ; routine LD-EDGE-1 ;JR NC,L056B ; back to LD-BREAK with time out and no ; edge present on tape. ; but continue when a transition is found on tape. ;LD HL,00415h ; set up 16-bit outer loop counter for ; approx 1 second delay. ;; LD-WAIT L0574: ;DJNZ L0574 ; self loop to LD-WAIT (for 256 times) ;DEC HL ; decrease outer loop counter. ;LD A,H ; test for ;OR L ; zero. ;JR NZ,L0574 ; back to LD-WAIT, if not zero, with zero in B. ; continue after delay with H holding zero and B also. ; sample 256 edges to check that we are in the middle of a lead-in section. ;CALL L05E3 ; routine LD-EDGE-2 ;JR NC,L056B ; back to LD-BREAK ; if no edges at all. ;; LD-LEADER L0580: ;LD B,09Ch ; set timing value. ;CALL L05E3 ; routine LD-EDGE-2 ;JR NC,L056B ; back to LD-BREAK if time-out ;LD A,0C6h ; two edges must be spaced apart. ;CP B ; compare ;JR NC,L056C ; back to LD-START if too close together for a ; lead-in. ;INC H ; proceed to test 256 edged sample. ;JR NZ,L0580 ; back to LD-LEADER while more to do. ; sample indicates we are in the middle of a two or five second lead-in. ; Now test every edge looking for the terminal sync signal. ;; LD-SYNC L058F: ;LD B,0C9h ; initial timing value in B. ;CALL L05E7 ; routine LD-EDGE-1 ;JR NC,L056B ; back to LD-BREAK with time-out. ;LD A,B ; fetch augmented timing value from B. ;CP 0D4h ; compare ;JR NC,L058F ; back to LD-SYNC if gap too big, that is, ; a normal lead-in edge gap. ; but a short gap will be the sync pulse. ; in which case another edge should appear before B rises to 0FFh ;CALL L05E7 ; routine LD-EDGE-1 ;RET NC ; return with time-out. ; proceed when the sync at the end of the lead-in is found. ; We are about to load data so change the border colours. ;LD A,C ; fetch long-term mask from C ;XOR 003h ; and make blue/yellow. ;LD C,A ; store the new long-term byte. ;LD H,00h ; set up parity byte as zero. ;LD B,0B0h ; timing. ;JR L05C8 ; forward to LD-MARKER ; the loop mid entry point with the alternate ; zero flag reset to indicate first byte ; is discarded. ; -------------- ; the loading loop loads each byte and is entered at the mid point. ;; LD-LOOP L05A9: ;EX AF,AF' ; restore entry flags and type in A. ;JR NZ,L05B3 ; forward to LD-FLAG if awaiting initial flag ; which is to be discarded. ;JR NC,L05BD ; forward to LD-VERIFY if not to be loaded. ;LD (IX+00h),L ; place loaded byte at memory location. ;JR L05C2 ; forward to LD-NEXT ; --- ;; LD-FLAG L05B3: ;RL C ; preserve carry (verify) flag in long-term ; state byte. Bit 7 can be lost. ;XOR L ; compare type in A with first byte in L. ;RET NZ ; return if no match e.g. CODE vs. DATA. ; continue when data type matches. ;LD A,C ; fetch byte with stored carry ;RRA ; rotate it to carry flag again ;LD C,A ; restore long-term port state. ;INC DE ; increment length ?? ;JR L05C4 ; forward to LD-DEC. ; but why not to location after ? ; --- ; for verification the byte read from tape is compared with that in memory. ;; LD-VERIFY L05BD: ;LD A,(IX+00h) ; fetch byte from memory. ;XOR L ; compare with that on tape ;RET NZ ; return if not zero. ;; LD-NEXT L05C2: ;INC IX ; increment byte pointer. ;; LD-DEC L05C4: ;DEC DE ; decrement length. ;EX AF,AF' ; store the flags. ;;LD B,0B2h ; timing. ; when starting to read 8 bits the receiving byte is marked with bit at right. ; when this is rotated out again then 8 bits have been read. ;; LD-MARKER L05C8: ;LD L,001h ; initialize as %00000001 ;; LD-8-BITS L05CA: ;CALL L05E3 ; routine LD-EDGE-2 increments B relative to ; gap between 2 edges. ;RET NC ; return with time-out. ;LD A,0CBh ; the comparison byte. ;CP B ; compare to incremented value of B. ; if B is higher then bit on tape was set. ; if <= then bit on tape is reset. ;RL L ; rotate the carry bit into L. ;LD B,0B0h ; reset the B timer byte. ;JP NC,L05CA ; JUMP back to LD-8-BITS ; when carry set then marker bit has been passed out and byte is complete. ;LD A,H ; fetch the running parity byte. ;XOR L ; include the new byte. ;LD H,A ; and store back in parity register. ;LD A,D ; check length of ;OR E ; expected bytes. ;JR NZ,L05A9 ; back to LD-LOOP ; while there are more. ; when all bytes loaded then parity byte should be zero. ;LD A,H ; fetch parity byte. ;CP 001h ; set carry if zero. scf ; bez sprawdzania sumy kontrolnej RET ; return ; in no carry then error as checksum disagrees. ; ------------------------- ; Check signal being loaded ; ------------------------- ; An edge is a transition from one mic state to another. ; More specifically a change in bit 6 of value input from port 0FEh. ; Graphically it is a change of border colour, say, blue to yellow. ; The first entry point looks for two adjacent edges. The second entry point ; is used to find a single edge. ; The B register holds a count, up to 256, within which the edge (or edges) ; must be found. The gap between two edges will be more for a '1' than a '0' ; so the value of B denotes the state of the bit (two edges) read from tape. ; -> ;; LD-EDGE-2 L05E3: ;CALL L05E7 ; call routine LD-EDGE-1 below. ;RET NC ; return if space pressed or time-out. ; else continue and look for another adjacent ; edge which together represent a bit on the ; tape. ; -> ; this entry point is used to find a single edge from above but also ; when detecting a read-in signal on the tape. ;; LD-EDGE-1 L05E7: ;LD A,016h ; a delay value of twenty two. ;; LD-DELAY L05E9: ;DEC A ; decrement counter ;JR NZ,L05E9 ; loop back to LD-DELAY 22 times. ;AND A ; clear carry. ;; LD-SAMPLE L05ED: ;INC B ; increment the time-out counter. ;RET Z ; return with failure when 0FFh passed. ;LD A,07Fh ; prepare to read keyboard and EAR port ;IN A,(0FEh) ; row 07FFEh. bit 6 is EAR, bit 0 is SPACE key. ;RRA ; test outer key the space. (bit 6 moves to 5) ;RET NC ; return if space pressed. >>> ;XOR C ; compare with initial long-term state. ;AND 020h ; isolate bit 5 ;JR Z,L05ED ; back to LD-SAMPLE if no edge. ; but an edge, a transition of the EAR bit, has been found so switch the ; long-term comparison byte containing both border colour and EAR bit. ;LD A,C ; fetch comparison value. ;CPL ; switch the bits ;LD C,A ; and put back in C for long-term. ;AND 007h ; isolate new colour bits. ;OR 008h ; set bit 3 - MIC off. ;OUT (0FEh),A ; send to port to effect the change of colour. ;SCF ; set carry flag signaling edge found within ; time allowed. ;RET ; return. ; --------------------------------- ; Entry point for all tape commands ; --------------------------------- ; This is the single entry point for the four tape commands. ; The routine first determines in what context it has been called by examining ; the low byte of the Syntax table entry which was stored in T_ADDR. ; Subtracting $EO (the present arrangement) gives a value of ; 00h - SAVE ; 001h - LOAD ; 002h - VERIFY ; 003h - MERGE ; As with all commands the address STMT-RET is on the stack. .org 0605h ;; SAVE-ETC L0605: POP AF ; discard address STMT-RET. LD A,(05C74h) ; fetch T_ADDR ; Now reduce the low byte of the Syntax table entry to give command. ; Note. For ZASM use SUB 0E0h as next instruction. L0609: SUB 0E0h ;L1ADF + 1 % 256 ; subtract the known offset. ; ( is SUB 0E0h in standard ROM ) LD (05C74h),A ; and put back in T_ADDR as 0,1,2, or 3 ; for future reference. CALL L1C8C ; routine EXPT-EXP checks that a string ; expression follows and stacks the ; parameters in run-time. CALL L2530 ; routine SYNTAX-Z JR Z,L0652 ; forward to SA-DATA if checking syntax. LD BC,011h ; presume seventeen bytes for a header. LD A,(05C74h) ; fetch command from T_ADDR. AND A ; test for zero - SAVE. JR Z,L0621 ; forward to SA-SPACE if so. LD C,022h ; else double length to thirty four. ;; SA-SPACE L0621: RST 30H ; BC-SPACES creates 17/34 bytes in workspace. PUSH DE ; transfer the start of new space to POP IX ; the available index register. ; ten spaces are required for the default filename but it is simpler to ; overwrite the first file-type indicator byte as well. LD B,00Bh ; set counter to eleven. LD A,020h ; prepare a space. ;; SA-BLANK L0629: LD (DE),A ; set workspace location to space. INC DE ; next location. DJNZ L0629 ; loop back to SA-BLANK till all eleven done. LD (IX+001h),0FFh ; set first byte of ten character filename ; to 0FFh as a default to signal null string. CALL L2BF1 ; routine STK-FETCH fetches the filename ; parameters from the calculator stack. ; length of string in BC. ; start of string in DE. LD HL,0FFF6h ; prepare the value minus ten. DEC BC ; decrement length. ; ten becomes nine, zero becomes 0FFFFh. ADD HL,BC ; trial addition. INC BC ; restore true length. JR NC,L064B ; forward to SA-NAME if length is one to ten. ; the filename is more than ten characters in length or the null string. LD A,(05C74h) ; fetch command from T_ADDR. AND A ; test for zero - SAVE. JR NZ,L0644 ; forward to SA-NULL if not the SAVE command. ; but no more than ten characters are allowed for SAVE. ; The first ten characters of any other command parameter are acceptable. ; Weird, but necessary, if saving to sectors. ; Note. the golden rule that there are no restriction on anything is broken. ;; REPORT-Fa L0642: RST 08H ; ERROR-1 .DEFB 00Eh ; Error Report: Invalid file name ; continue with LOAD, MERGE, VERIFY and also SAVE within ten character limit. ;; SA-NULL L0644: LD A,B ; test length of filename OR C ; for zero. JR Z,L0652 ; forward to SA-DATA if so using the 255 ; indicator followed by spaces. LD BC,00Ah ; else trim length to ten. ; other paths rejoin here with BC holding length in range 1 - 10. ;; SA-NAME L064B: PUSH IX ; push start of file descriptor. POP HL ; and pop into HL. INC HL ; HL now addresses first byte of filename. EX DE,HL ; transfer destination address to DE, start ; of string in command to HL. LDIR ; copy up to ten bytes ; if less than ten then trailing spaces follow. ; the case for the null string rejoins here. ;; SA-DATA L0652: RST 18H ; GET-CHAR CP 0E4h ; is character after filename the token 'DATA' ? JR NZ,L06A0 ; forward to SA-SCR$ to consider SCREEN$ if ; not. ; continue to consider DATA. LD A,(05C74h) ; fetch command from T_ADDR CP 003h ; is it 'VERIFY' ? JP Z,L1C8A ; jump forward to REPORT-C if so. ; 'Nonsense in BASIC' ; VERIFY "d" DATA is not allowed. ; continue with SAVE, LOAD, MERGE of DATA. RST 20H ; NEXT-CHAR CALL L28B2 ; routine LOOK-VARS searches variables area ; returning with carry reset if found or ; checking syntax. SET 7,C ; this converts a simple string to a ; string array. The test for an array or string ; comes later. JR NC,L0672 ; forward to SA-V-OLD if variable found. LD HL,000h ; set destination to zero as not fixed. LD A,(05C74h) ; fetch command from T_ADDR DEC A ; test for 1 - LOAD JR Z,L0685 ; forward to SA-V-NEW with LOAD DATA. ; to load a new array. ; otherwise the variable was not found in run-time with SAVE/MERGE. ;; REPORT-2a L0670: RST 08H ; ERROR-1 .DEFB 001h ; Error Report: Variable not found ; continue with SAVE/LOAD DATA ;; SA-V-OLD L0672: JP NZ,L1C8A ; to REPORT-C if not an array variable. ; or erroneously a simple string. ; 'Nonsense in BASIC' CALL L2530 ; routine SYNTAX-Z JR Z,L0692 ; forward to SA-DATA-1 if checking syntax. INC HL ; step past single character variable name. LD A,(HL) ; fetch low byte of length. LD (IX+00Bh),A ; place in descriptor. INC HL ; point to high byte. LD A,(HL) ; and transfer that LD (IX+00Ch),A ; to descriptor. INC HL ; increase pointer within variable. ;; SA-V-NEW L0685: LD (IX+00Eh),C ; place character array name in header. LD A,001h ; default to type numeric. BIT 6,C ; test result from look-vars. JR Z,L068F ; forward to SA-V-TYPE if numeric. INC A ; set type to 2 - string array. ;; SA-V-TYPE L068F: LD (IX+00h),A ; place type 0, 1 or 2 in descriptor. ;; SA-DATA-1 L0692: EX DE,HL ; save var pointer in DE RST 20H ; NEXT-CHAR CP 029h ; is character ')' ? JR NZ,L0672 ; back if not to SA-V-OLD to report ; 'Nonsense in BASIC' RST 20H ; NEXT-CHAR advances character address. CALL L1BEE ; routine CHECK-END errors if not end of ; the statement. EX DE,HL ; bring back variables data pointer. JP L075A ; jump forward to SA-ALL ; --- ; the branch was here to consider a 'SCREEN$', the display file. ;; SA-SCR$ L06A0: CP 0AAh ; is character the token 'SCREEN$' ? JR NZ,L06C3 ; forward to SA-CODE if not. LD A,(05C74h) ; fetch command from T_ADDR CP 003h ; is it MERGE ? JP Z,L1C8A ; jump to REPORT-C if so. ; 'Nonsense in BASIC' ; continue with SAVE/LOAD/VERIFY SCREEN$. RST 20H ; NEXT-CHAR CALL L1BEE ; routine CHECK-END errors if not at end of ; statement. ; continue in runtime. LD (IX+00Bh),00h ; set descriptor length LD (IX+00Ch),01Bh ; to $1b00 to include bitmaps and attributes. LD HL,04000h ; set start to display file start. LD (IX+00Dh),L ; place start in LD (IX+00Eh),H ; the descriptor. JR L0710 ; forward to SA-TYPE-3 ; --- ; the branch was here to consider CODE. ;; SA-CODE L06C3: CP 0AFh ; is character the token 'CODE' ? JR NZ,L0716 ; forward if not to SA-LINE to consider an ; auto-started BASIC program. LD A,(05C74h) ; fetch command from T_ADDR CP 003h ; is it MERGE ? JP Z,L1C8A ; jump forward to REPORT-C if so. ; 'Nonsense in BASIC' RST 20H ; NEXT-CHAR advances character address. CALL L2048 ; routine PR-ST-END checks if a carriage ; return or ':' follows. JR NZ,L06E1 ; forward to SA-CODE-1 if there are parameters. LD A,(05C74h) ; else fetch the command from T_ADDR. AND A ; test for zero - SAVE without a specification. JP Z,L1C8A ; jump to REPORT-C if so. ; 'Nonsense in BASIC' ; for LOAD/VERIFY put zero on stack to signify handle at location saved from. CALL L1CE6 ; routine USE-ZERO JR L06F0 ; forward to SA-CODE-2 ; --- ; if there are more characters after CODE expect start and possibly length. ;; SA-CODE-1 L06E1: CALL L1C82 ; routine EXPT-1NUM checks for numeric ; expression and stacks it in run-time. RST 18H ; GET-CHAR CP 02Ch ; does a comma follow ? JR Z,L06F5 ; forward if so to SA-CODE-3 ; else allow saved code to be loaded to a specified address. LD A,(05C74h) ; fetch command from T_ADDR. AND A ; is the command SAVE which requires length ? JP Z,L1C8A ; jump to REPORT-C if so. ; 'Nonsense in BASIC' ; the command LOAD code may rejoin here with zero stacked as start. ;; SA-CODE-2 L06F0: CALL L1CE6 ; routine USE-ZERO stacks zero for length. JR L06F9 ; forward to SA-CODE-4 ; --- ; the branch was here with SAVE CODE start, ;; SA-CODE-3 L06F5: RST 20H ; NEXT-CHAR advances character address. CALL L1C82 ; routine EXPT-1NUM checks for expression ; and stacks in run-time. ; paths converge here and nothing must follow. ;; SA-CODE-4 L06F9: CALL L1BEE ; routine CHECK-END errors with extraneous ; characters and quits if checking syntax. ; in run-time there are two 16-bit parameters on the calculator stack. CALL L1E99 ; routine FIND-INT2 gets length. LD (IX+00Bh),C ; place length LD (IX+00Ch),B ; in descriptor. CALL L1E99 ; routine FIND-INT2 gets start. LD (IX+00Dh),C ; place start LD (IX+00Eh),B ; in descriptor. LD H,B ; transfer the LD L,C ; start to HL also. ;; SA-TYPE-3 L0710: LD (IX+00h),003h ; place type 3 - code in descriptor. JR L075A ; forward to SA-ALL. ; --- ; the branch was here with BASIC to consider an optional auto-start line ; number. ;; SA-LINE L0716: CP 0CAh ; is character the token 'LINE' ? JR Z,L0723 ; forward to SA-LINE-1 if so. ; else all possibilities have been considered and nothing must follow. CALL L1BEE ; routine CHECK-END ; continue in run-time to save BASIC without auto-start. LD (IX+00Eh),080h ; place high line number in descriptor to ; disable auto-start. JR L073A ; forward to SA-TYPE-0 to save program. ; --- ; the branch was here to consider auto-start. ;; SA-LINE-1 L0723: LD A,(05C74h) ; fetch command from T_ADDR AND A ; test for SAVE. JP NZ,L1C8A ; jump forward to REPORT-C with anything else. ; 'Nonsense in BASIC' ; RST 20H ; NEXT-CHAR CALL L1C82 ; routine EXPT-1NUM checks for numeric ; expression and stacks in run-time. CALL L1BEE ; routine CHECK-END quits if syntax path. CALL L1E99 ; routine FIND-INT2 fetches the numeric ; expression. LD (IX+00Dh),C ; place the auto-start LD (IX+00Eh),B ; line number in the descriptor. ; Note. this isn't checked, but is subsequently handled by the system. ; If the user typed 40000 instead of 4000 then it won't auto-start ; at line 4000, or indeed, at all. ; continue to save program and any variables. ;; SA-TYPE-0 L073A: LD (IX+00h),00h ; place type zero - program in descriptor. LD HL,(05C59h) ; fetch E_LINE to HL. LD DE,(05C53h) ; fetch PROG to DE. SCF ; set carry flag to calculate from end of ; variables E_LINE -1. SBC HL,DE ; subtract to give total length. LD (IX+00Bh),L ; place total length LD (IX+00Ch),H ; in descriptor. LD HL,(05C4Bh) ; load HL from system variable VARS SBC HL,DE ; subtract to give program length. LD (IX+00Fh),L ; place length of program LD (IX+010h),H ; in the descriptor. EX DE,HL ; start to HL, length to DE. ;; SA-ALL L075A: LD A,(05C74h) ; fetch command from T_ADDR AND A ; test for zero - SAVE. JP Z,L0970 ; jump forward to SA-CONTRL with SAVE -> ; --- ; continue with LOAD, MERGE and VERIFY. PUSH HL ; save start. LD BC,011h ; prepare to add seventeen ADD IX,BC ; to point IX at second descriptor. ;; LD-LOOK-H L0767: PUSH IX ; save IX LD DE,011h ; seventeen bytes XOR A ; reset zero flag SCF ; set carry flag CALL L0556 ; routine LD-BYTES loads a header from tape ; to second descriptor. POP IX ; restore IX. JR NC,L0767 ; loop back to LD-LOOK-H until header found. LD A,0FEh ; select system channel 'S' CALL L1601 ; routine CHAN-OPEN opens it. LD (IY+052h),003h ; set SCR_CT to 3 lines. LD C,080h ; C has bit 7 set to indicate type mismatch as ; a default startpoint. LD A,(IX+00h) ; fetch loaded header type to A CP (IX-011h) ; compare with expected type. JR NZ,L078A ; forward to LD-TYPE with mis-match. LD C,0F6h ; set C to minus ten - will count characters ; up to zero. ;; LD-TYPE L078A: CP 004h ; check if type in acceptable range 0 - 3. JR NC,L0767 ; back to LD-LOOK-H with 4 and over. ; else A indicates type 0-3. LD DE,L09C0 ; address base of last 4 tape messages PUSH BC ; save BC CALL L0C0A ; routine PO-MSG outputs relevant message. ; Note. all messages have a leading newline. POP BC ; restore BC PUSH IX ; transfer IX, POP DE ; the 2nd descriptor, to DE. LD HL,0FFF0h ; prepare minus seventeen. ADD HL,DE ; add to point HL to 1st descriptor. LD B,00Ah ; the count will be ten characters for the ; filename. LD A,(HL) ; fetch first character and test for INC A ; value 255. JR NZ,L07A6 ; forward to LD-NAME if not the wildcard. ; but if it is the wildcard, then add ten to C which is minus ten for a type ; match or -128 for a type mismatch. Although characters have to be counted ; bit 7 of C will not alter from state set here. LD A,C ; transfer 0F6h or 080h to A ADD A,B ; add 00Ah LD C,A ; place result, zero or -118, in C. ; At this point we have either a type mismatch, a wildcard match or ten ; characters to be counted. The characters must be shown on the screen. ;; LD-NAME L07A6: INC DE ; address next input character LD A,(DE) ; fetch character CP (HL) ; compare to expected INC HL ; address next expected character JR NZ,L07AD ; forward to LD-CH-PR with mismatch INC C ; increment matched character count ;; LD-CH-PR L07AD: RST 10H ; PRINT-A prints character DJNZ L07A6 ; loop back to LD-NAME for ten characters. ; if ten characters matched and the types previously matched then C will ; now hold zero. BIT 7,C ; test if all matched JR NZ,L0767 ; back to LD-LOOK-H if not ; else print a terminal carriage return. LD A,00Dh ; prepare carriage return. RST 10H ; PRINT-A outputs it. ; The various control routines for LOAD, VERIFY and MERGE are executed ; during the one-second gap following the header on tape. POP HL ; restore xx LD A,(IX+00h) ; fetch incoming type CP 003h ; compare with CODE JR Z,L07CB ; forward to VR-CONTRL if it is CODE. ; type is a program or an array. LD A,(05C74h) ; fetch command from T_ADDR DEC A ; was it LOAD ? JP Z,L0808 ; JUMP forward to LD-CONTRL if so to ; load BASIC or variables. CP 002h ; was command MERGE ? JP Z,L08B6 ; jump forward to ME-CONTRL if so. ; else continue into VERIFY control routine to verify. ; ---------------------------- ; THE 'VERIFY CONTROL' ROUTINE ; ---------------------------- ; There are two branches to this routine. ; 1) From above to verify a program or array ; 2) from earlier with no carry to load or verify code. ;; VR-CONTRL L07CB: PUSH HL ; save pointer to data. LD L,(IX-006h) ; fetch length of old data LD H,(IX-005h) ; to HL. LD E,(IX+00Bh) ; fetch length of new data LD D,(IX+00Ch) ; to DE. LD A,H ; check length of old OR L ; for zero. JR Z,L07E9 ; forward to VR-CONT-1 if length unspecified ; e.g. LOAD "x" CODE ; as opposed to, say, LOAD 'x' CODE 32768,300. SBC HL,DE ; subtract the two lengths. JR C,L0806 ; forward to REPORT-R if the length on tape is ; larger than that specified in command. ; 'Tape loading error' JR Z,L07E9 ; forward to VR-CONT-1 if lengths match. ; a length on tape shorter than expected is not allowed for CODE LD A,(IX+00h) ; else fetch type from tape. CP 003h ; is it CODE ? JR NZ,L0806 ; forward to REPORT-R if so ; 'Tape loading error' ;; VR-CONT-1 L07E9: POP HL ; pop pointer to data LD A,H ; test for zero OR L ; e.g. LOAD 'x' CODE JR NZ,L07F4 ; forward to VR-CONT-2 if destination specified. LD L,(IX+00Dh) ; else use the destination in the header LD H,(IX+00Eh) ; and load code at address saved from. ;; VR-CONT-2 L07F4: PUSH HL ; push pointer to start of data block. POP IX ; transfer to IX. LD A,(05C74h) ; fetch reduced command from T_ADDR CP 002h ; is it VERIFY ? SCF ; prepare a set carry flag JR NZ,L0800 ; skip to VR-CONT-3 if not AND A ; clear carry flag for VERIFY so that ; data is not loaded. ;; VR-CONT-3 L0800: LD A,0FFh ; signal data block to be loaded ; ----------------- ; Load a data block ; ----------------- ; This routine is called from 3 places other than above to load a data block. ; In all cases the accumulator is first set to 0FFh so the routine could be ; called at the previous instruction. ;; LD-BLOCK L0802: CALL L0556 ; routine LD-BYTES RET C ; return if successful. ;; REPORT-R L0806: RST 08H ; ERROR-1 .DEFB 01Ah ; Error Report: Tape loading error ; -------------------------- ; THE 'LOAD CONTROL' ROUTINE ; -------------------------- ; This branch is taken when the command is LOAD with type 0, 1 or 2. ;; LD-CONTRL L0808: LD E,(IX+00Bh) ; fetch length of found data block LD D,(IX+00Ch) ; from 2nd descriptor. PUSH HL ; save destination LD A,H ; test for zero OR L ; JR NZ,L0819 ; forward if not to LD-CONT-1 INC DE ; increase length INC DE ; for letter name INC DE ; and 16-bit length EX DE,HL ; length to HL, JR L0825 ; forward to LD-CONT-2 ; --- ;; LD-CONT-1 L0819: LD L,(IX-006h) ; fetch length from LD H,(IX-005h) ; the first header. EX DE,HL ; SCF ; set carry flag SBC HL,DE ; JR C,L082E ; to LD-DATA ;; LD-CONT-2 L0825: LD DE,005h ; allow overhead of five bytes. ADD HL,DE ; add in the difference in data lengths. LD B,H ; transfer to LD C,L ; the BC register pair CALL L1F05 ; routine TEST-ROOM fails if not enough room. ;; LD-DATA L082E: POP HL ; pop destination LD A,(IX+00h) ; fetch type 0, 1 or 2. AND A ; test for program and variables. JR Z,L0873 ; forward if so to LD-PROG ; the type is a numeric or string array. LD A,H ; test the destination for zero OR L ; indicating variable does not already exist. JR Z,L084C ; forward if so to LD-DATA-1 ; else the destination is the first dimension within the array structure DEC HL ; address high byte of total length LD B,(HL) ; transfer to B. DEC HL ; address low byte of total length. LD C,(HL) ; transfer to C. DEC HL ; point to letter of variable. INC BC ; adjust length to INC BC ; include these INC BC ; three bytes also. LD (05C5Fh),IX ; save header pointer in X_PTR. CALL L19E8 ; routine RECLAIM-2 reclaims the old variable ; sliding workspace including the two headers ; downwards. LD IX,(05C5Fh) ; reload IX from X_PTR which will have been ; adjusted down by POINTERS routine. ;; LD-DATA-1 L084C: LD HL,(05C59h) ; address E_LINE DEC HL ; now point to the 080h variables end-marker. LD C,(IX+00Bh) ; fetch new data length LD B,(IX+00Ch) ; from 2nd header. PUSH BC ; * save it. INC BC ; adjust the INC BC ; length to include INC BC ; letter name and total length. LD A,(IX-003h) ; fetch letter name from old header. PUSH AF ; preserve accumulator though not corrupted. CALL L1655 ; routine MAKE-ROOM creates space for variable ; sliding workspace up. IX no longer addresses ; anywhere meaningful. INC HL ; point to first new location. POP AF ; fetch back the letter name. LD (HL),A ; place in first new location. POP DE ; * pop the data length. INC HL ; address 2nd location LD (HL),E ; store low byte of length. INC HL ; address next. LD (HL),D ; store high byte. INC HL ; address start of data. PUSH HL ; transfer address POP IX ; to IX register pair. SCF ; set carry flag indicating load not verify. LD A,0FFh ; signal data not header. JP L0802 ; JUMP back to LD-BLOCK ; ----------------- ; the branch is here when a program as opposed to an array is to be loaded. ;; LD-PROG L0873: EX DE,HL ; transfer dest to DE. LD HL,(05C59h) ; address E_LINE DEC HL ; now variables end-marker. LD (05C5Fh),IX ; place the IX header pointer in X_PTR LD C,(IX+00Bh) ; get new length LD B,(IX+00Ch) ; from 2nd header PUSH BC ; and save it. CALL L19E5 ; routine RECLAIM-1 reclaims program and vars. ; adjusting X-PTR. POP BC ; restore new length. PUSH HL ; * save start PUSH BC ; ** and length. CALL L1655 ; routine MAKE-ROOM creates the space. LD IX,(05C5Fh) ; reload IX from adjusted X_PTR INC HL ; point to start of new area. LD C,(IX+00Fh) ; fetch length of BASIC on tape LD B,(IX+010h) ; from 2nd descriptor ADD HL,BC ; add to address the start of variables. LD (05C4Bh),HL ; set system variable VARS LD H,(IX+00Eh) ; fetch high byte of autostart line number. LD A,H ; transfer to A AND 0C0h ; test if greater than 03Fh. JR NZ,L08AD ; forward to LD-PROG-1 if so with no autostart. LD L,(IX+00Dh) ; else fetch the low byte. LD (05C42h),HL ; set system variable to line number NEWPPC LD (IY+00Ah),00h ; set statement NSPPC to zero. ;; LD-PROG-1 L08AD: POP DE ; ** pop the length POP IX ; * and start. SCF ; set carry flag LD A,0FFh ; signal data as opposed to a header. JP L0802 ; jump back to LD-BLOCK ; --------------------------- ; THE 'MERGE CONTROL' ROUTINE ; --------------------------- ; the branch was here to merge a program and its variables or an array. ; ;; ME-CONTRL L08B6: LD C,(IX+00Bh) ; fetch length LD B,(IX+00Ch) ; of data block on tape. PUSH BC ; save it. INC BC ; one for the pot. RST 30H ; BC-SPACES creates room in workspace. ; HL addresses last new location. LD (HL),080h ; place end-marker at end. EX DE,HL ; transfer first location to HL. POP DE ; restore length to DE. PUSH HL ; save start. PUSH HL ; and transfer it POP IX ; to IX register. SCF ; set carry flag to load data on tape. LD A,0FFh ; signal data not a header. CALL L0802 ; routine LD-BLOCK loads to workspace. POP HL ; restore first location in workspace to HL. X08CE LD DE,(05C53h) ; set DE from system variable PROG. ; now enter a loop to merge the data block in workspace with the program and ; variables. ;; ME-NEW-LP L08D2: LD A,(HL) ; fetch next byte from workspace. AND 0C0h ; compare with 03Fh. JR NZ,L08F0 ; forward to ME-VAR-LP if a variable or ; end-marker. ; continue when HL addresses a BASIC line number. ;; ME-OLD-LP L08D7: LD A,(DE) ; fetch high byte from program area. INC DE ; bump prog address. CP (HL) ; compare with that in workspace. INC HL ; bump workspace address. JR NZ,L08DF ; forward to ME-OLD-L1 if high bytes don't match LD A,(DE) ; fetch the low byte of program line number. CP (HL) ; compare with that in workspace. ;; ME-OLD-L1 L08DF: DEC DE ; point to start of DEC HL ; respective lines again. JR NC,L08EB ; forward to ME-NEW-L2 if line number in ; workspace is less than or equal to current ; program line as has to be added to program. PUSH HL ; else save workspace pointer. EX DE,HL ; transfer prog pointer to HL CALL L19B8 ; routine NEXT-ONE finds next line in DE. POP HL ; restore workspace pointer JR L08D7 ; back to ME-OLD-LP until destination position ; in program area found. ; --- ; the branch was here with an insertion or replacement point. ;; ME-NEW-L2 L08EB: CALL L092C ; routine ME-ENTER enters the line JR L08D2 ; loop back to ME-NEW-LP. ; --- ; the branch was here when the location in workspace held a variable. ;; ME-VAR-LP L08F0: LD A,(HL) ; fetch first byte of workspace variable. LD C,A ; copy to C also. CP 080h ; is it the end-marker ? RET Z ; return if so as complete. >>>>> PUSH HL ; save workspace area pointer. LD HL,(05C4Bh) ; load HL with VARS - start of variables area. ;; ME-OLD-VP L08F9: LD A,(HL) ; fetch first byte. CP 080h ; is it the end-marker ? JR Z,L0923 ; forward if so to ME-VAR-L2 to add ; variable at end of variables area. CP C ; compare with variable in workspace area. JR Z,L0909 ; forward to ME-OLD-V2 if a match to replace. ; else entire variables area has to be searched. ;; ME-OLD-V1 L0901: PUSH BC ; save character in C. CALL L19B8 ; routine NEXT-ONE gets following variable ; address in DE. POP BC ; restore character in C EX DE,HL ; transfer next address to HL. JR L08F9 ; loop back to ME-OLD-VP ; --- ; the branch was here when first characters of name matched. ;; ME-OLD-V2 L0909: AND 0E0h ; keep bits 11100000 CP 0A0h ; compare 10100000 - a long-named variable. JR NZ,L0921 ; forward to ME-VAR-L1 if just one-character. ; but long-named variables have to be matched character by character. POP DE ; fetch workspace 1st character pointer PUSH DE ; and save it on the stack again. PUSH HL ; save variables area pointer on stack. ;; ME-OLD-V3 L0912: INC HL ; address next character in vars area. INC DE ; address next character in workspace area. LD A,(DE) ; fetch workspace character. CP (HL) ; compare to variables character. JR NZ,L091E ; forward to ME-OLD-V4 with a mismatch. RLA ; test if the terminal inverted character. JR NC,L0912 ; loop back to ME-OLD-V3 if more to test. ; otherwise the long name matches in its entirety. POP HL ; restore pointer to first character of variable JR L0921 ; forward to ME-VAR-L1 ; --- ; the branch is here when two characters don't match ;; ME-OLD-V4 L091E: POP HL ; restore the prog/vars pointer. JR L0901 ; back to ME-OLD-V1 to resume search. ; --- ; branch here when variable is to replace an existing one ;; ME-VAR-L1 L0921: LD A,0FFh ; indicate a replacement. ; this entry point is when A holds 080h indicating a new variable. ;; ME-VAR-L2 L0923: POP DE ; pop workspace pointer. EX DE,HL ; now make HL workspace pointer, DE vars pointer INC A ; zero flag set if replacement. SCF ; set carry flag indicating a variable not a ; program line. CALL L092C ; routine ME-ENTER copies variable in. JR L08F0 ; loop back to ME-VAR-LP ; ------------------------ ; Merge a Line or Variable ; ------------------------ ; A BASIC line or variable is inserted at the current point. If the line ; number or variable names match (zero flag set) then a replacement takes ; place. ;; ME-ENTER L092C: JR NZ,L093E ; forward to ME-ENT-1 for insertion only. ; but the program line or variable matches so old one is reclaimed. EX AF,AF' ; save flag?? LD (05C5Fh),HL ; preserve workspace pointer in dynamic X_PTR EX DE,HL ; transfer program dest pointer to HL. CALL L19B8 ; routine NEXT-ONE finds following location ; in program or variables area. CALL L19E8 ; routine RECLAIM-2 reclaims the space between. EX DE,HL ; transfer program dest pointer back to DE. LD HL,(05C5Fh) ; fetch adjusted workspace pointer from X_PTR EX AF,AF' ; restore flags. ; now the new line or variable is entered. ;; ME-ENT-1 L093E: EX AF,AF' ; save or re-save flags. PUSH DE ; save dest pointer in prog/vars area. CALL L19B8 ; routine NEXT-ONE finds next in workspace. ; gets next in DE, difference in BC. ; prev addr in HL LD (05C5Fh),HL ; store pointer in X_PTR LD HL,(05C53h) ; load HL from system variable PROG EX (SP),HL ; swap with prog/vars pointer on stack. PUSH BC ; ** save length of new program line/variable. EX AF,AF' ; fetch flags back. JR C,L0955 ; skip to ME-ENT-2 if variable DEC HL ; address location before pointer CALL L1655 ; routine MAKE-ROOM creates room for BASIC line INC HL ; address next. JR L0958 ; forward to ME-ENT-3 ; --- ;; ME-ENT-2 L0955: CALL L1655 ; routine MAKE-ROOM creates room for variable. ;; ME-ENT-3 L0958: INC HL ; address next? POP BC ; ** pop length POP DE ; * pop value for PROG which may have been ; altered by POINTERS if first line. LD (05C53h),DE ; set PROG to original value. LD DE,(05C5Fh) ; fetch adjusted workspace pointer from X_PTR PUSH BC ; save length PUSH DE ; and workspace pointer EX DE,HL ; make workspace pointer source, prog/vars ; pointer the destination LDIR ; copy bytes of line or variable into new area. POP HL ; restore workspace pointer. POP BC ; restore length. PUSH DE ; save new prog/vars pointer. CALL L19E8 ; routine RECLAIM-2 reclaims the space used ; by the line or variable in workspace block ; as no longer required and space could be ; useful for adding more lines. POP DE ; restore the prog/vars pointer RET ; return. ; -------------------------- ; THE 'SAVE CONTROL' ROUTINE ; -------------------------- ; A branch from the main SAVE-ETC routine at SAVE-ALL. ; First the header data is saved. Then after a wait of 1 second ; the data itself is saved. ; HL points to start of data. ; IX points to start of descriptor. ;; SA-CONTRL L0970: PUSH HL ; save start of data LD A,0FDh ; select system channel 'S' CALL L1601 ; routine CHAN-OPEN XOR A ; clear to address table directly LD DE,L09A1 ; address: tape-msgs CALL L0C0A ; routine PO-MSG - ; 'Start tape then press any key.' SET 5,(IY+002h) ; TV_FLAG - Signal lower screen requires ; clearing CALL L15D4 ; routine WAIT-KEY PUSH IX ; save pointer to descriptor. LD DE,011h ; there are seventeen bytes. XOR A ; signal a header. CALL L04C2 ; routine SA-BYTES POP IX ; restore descriptor pointer. LD B,032h ; wait for a second - 50 interrupts. ;; SA-1-SEC L0991: HALT ; wait for interrupt DJNZ L0991 ; back to SA-1-SEC until pause complete. LD E,(IX+00Bh) ; fetch length of bytes from the LD D,(IX+00Ch) ; descriptor. LD A,0FFh ; signal data bytes. POP IX ; retrieve pointer to start JP L04C2 ; jump back to SA-BYTES ; Arrangement of two headers in workspace. ; Originally IX addresses first location and only one header is required ; when saving. ; ; OLD NEW PROG DATA DATA CODE ; HEADER HEADER num chr NOTES. ; ------ ------ ---- ---- ---- ---- ----------------------------- ; IX-011h IX+00h 0 1 2 3 Type. ; IX-010h IX+001h x x x x F (0FFh if filename is null). ; IX-00Fh IX+002h x x x x i ; IX-00Eh IX+003h x x x x l ; IX-00Dh IX+004h x x x x e ; IX-00Ch IX+005h x x x x n ; IX-00Bh IX+006h x x x x a ; IX-00Ah IX+007h x x x x m ; IX-009h IX+008h x x x x e ; IX-008h IX+009h x x x x . ; IX-007h IX+00Ah x x x x (terminal spaces). ; IX-006h IX+00Bh lo lo lo lo Total ; IX-005h IX+00Ch hi hi hi hi Length of datablock. ; IX-004h IX+00Dh Auto - - Start Various ; IX-003h IX+00Eh Start a-z a-z addr (080h if no autostart). ; IX-002h IX+00Fh lo - - - Length of Program ; IX-001h IX+010h hi - - - only i.e. without variables. ; ; ------------------------ ; Canned cassette messages ; ------------------------ ; The last-character-inverted Cassette messages. ; Starts with normal initial step-over byte. ;; tape-msgs L09A1: .DEFB 080h .DEFB "Start tape" .DEFB 02Ch ; znak "," .DEFB " then press " .DEFB "any key" L09C0: .DEFB '.'+080h .DEFB 00Dh .DEFB "Program:" .DEFB ' '+080h .DEFB 00Dh .DEFB "Number array:" .DEFB ' '+080h .DEFB 00Dh .DEFB "Character array:" .DEFB ' '+080h .DEFB 00Dh .DEFB "Bytes:" .DEFB ' '+080h ;************************************************** ;** Part 5. SCREEN AND PRINTER HANDLING ROUTINES ** ;************************************************** ; -------------------------- ; THE 'PRINT OUTPUT' ROUTINE ; -------------------------- ; This is the routine most often used by the RST 10 restart although the ; subroutine is on two occasions called directly when it is known that ; output will definitely be to the lower screen. ;; PRINT-OUT L09F4: CALL L0B03 ; routine PO-FETCH fetches print position ; to HL register pair. CP 020h ; is character a space or higher ? JP NC,L0AD9 ; jump forward to PO-ABLE if so. CP 006h ; is character in range 00-05 ? JR C,L0A69 ; to PO-QUEST to print '?' if so. CP 018h ; is character in range 24d - 31d ? JR NC,L0A69 ; to PO-QUEST to also print '?' if so. LD HL,L0A11 - 6 ; address 0A0B - the base address of control ; character table - where zero would be. LD E,A ; control character 06 - 23d LD D,00h ; is transferred to DE. ADD HL,DE ; index into table. LD E,(HL) ; fetch the offset to routine. ADD HL,DE ; add to make HL the address. PUSH HL ; push the address. JP L0B03 ; Jump forward to PO-FETCH, ; as the screen/printer position has been ; disturbed, and then indirectly to the PO-STORE ; routine on stack. ; ----------------------------- ; THE 'CONTROL CHARACTER' TABLE ; ----------------------------- ; For control characters in the range 6 - 23d the following table ; is indexed to provide an offset to the handling routine that ; follows the table. ;; ctlchrtab L0A11: .DEFB 04Eh ;L0A5F - $ ; 06d offset 04Eh to Address: PO-COMMA .DEFB 057h ;L0A69 - $ ; 07d offset 057h to Address: PO-QUEST .DEFB 010h ;L0A23 - $ ; 08d offset 010h to Address: PO-BACK-1 .DEFB 029h ;L0A3D - $ ; 09d offset 029h to Address: PO-RIGHT .DEFB 054h ;L0A69 - $ ; 10d offset 054h to Address: PO-QUEST .DEFB 053h ;L0A69 - $ ; 11d offset 053h to Address: PO-QUEST .DEFB 052h ;L0A69 - $ ; 12d offset 052h to Address: PO-QUEST .DEFB 037h ;L0A4F - $ ; 13d offset 037h to Address: PO-ENTER .DEFB 050h ;L0A69 - $ ; 14d offset 050h to Address: PO-QUEST .DEFB 04Fh ;L0A69 - $ ; 15d offset 04Fh to Address: PO-QUEST .DEFB 05Fh ;L0A7A - $ ; 16d offset 05Fh to Address: PO-1-OPER .DEFB 05Eh ;L0A7A - $ ; 17d offset 05Eh to Address: PO-1-OPER .DEFB 05Dh ;L0A7A - $ ; 18d offset 05Dh to Address: PO-1-OPER .DEFB 05Ch ;L0A7A - $ ; 19d offset 05Ch to Address: PO-1-OPER .DEFB 05Bh ;L0A7A - $ ; 20d offset 05Bh to Address: PO-1-OPER .DEFB 05Ah ;L0A7A - $ ; 21d offset 05Ah to Address: PO-1-OPER .DEFB 054h ;L0A75 - $ ; 22d offset 054h to Address: PO-2-OPER .DEFB 053h ;L0A75 - $ ; 23d offset 053h to Address: PO-2-OPER ; ------------------------- ; THE 'CURSOR LEFT' ROUTINE ; ------------------------- ; Backspace and up a line if that action is from the left of screen. ; For ZX printer backspace up to first column but not beyond. ;; PO-BACK-1 L0A23: INC C ; move left one column. LD A,022h ; value 021h is leftmost column. CP C ; have we passed ? JR NZ,L0A3A ; to PO-BACK-3 if not and store new position. BIT 1,(IY+001h) ; test FLAGS - is printer in use ? JR NZ,L0A38 ; to PO-BACK-2 if so, as we are unable to ; backspace from the leftmost position. INC B ; move up one screen line LD C,002h ; the rightmost column position. LD A,018h ; Note. This should be 019h ; credit. Dr. Frank O'Hara, 1982 CP B ; has position moved past top of screen ? JR NZ,L0A3A ; to PO-BACK-3 if not and store new position. DEC B ; else back to 018h. ;; PO-BACK-2 L0A38: LD C,021h ; the leftmost column position. ;; PO-BACK-3 L0A3A: JP L0DD9 ; to CL-SET and PO-STORE to save new ; position in system variables. ; -------------------------- ; THE 'CURSOR RIGHT' ROUTINE ; -------------------------- ; This moves the print position to the right leaving a trail in the ; current background colour. ; "However the programmer has failed to store the new print position ; so CHR$ 9 will only work if the next print position is at a newly ; defined place. ; e.g. PRINT PAPER 2; CHR$ 9; AT 4,0; ; does work but is not very helpful" ; - Dr. Ian Logan, Understanding Your Spectrum, 1982. ;; PO-RIGHT L0A3D: LD A,(05C91h) ; fetch P_FLAG value PUSH AF ; and save it on stack. LD (IY+057h),001h ; temporarily set P_FLAG 'OVER 1'. LD A,020h ; prepare a space. CALL L0B65 ; routine PO-CHAR to print it. ; Note. could be PO-ABLE which would update ; the column position. POP AF ; restore the permanent flag. LD (05C91h),A ; and restore system variable P_FLAG RET ; return without updating column position ; ----------------------- ; Perform carriage return ; ----------------------- ; A carriage return is 'printed' to screen or printer buffer. ;; PO-ENTER L0A4F: BIT 1,(IY+001h) ; test FLAGS - is printer in use ? JP NZ,L0ECD ; to COPY-BUFF if so, to flush buffer and reset ; the print position. LD C,021h ; the leftmost column position. CALL L0C55 ; routine PO-SCR handles any scrolling required. DEC B ; to next screen line. JP L0DD9 ; jump forward to CL-SET to store new position. ; ----------- ; Print comma ; ----------- ; The comma control character. The 32 column screen has two 16 character ; tabstops. The routine is only reached via the control character table. ;; PO-COMMA L0A5F: CALL L0B03 ; routine PO-FETCH - seems unnecessary. LD A,C ; the column position. 021h-001h DEC A ; move right. 020h-00h DEC A ; and again 01Fh-00h or 0FFh if trailing AND 010h ; will be 00h or 010h. JR L0AC3 ; forward to PO-FILL ; ------------------- ; Print question mark ; ------------------- ; This routine prints a question mark which is commonly ; used to print an unassigned control character in range 0-31d. ; there are a surprising number yet to be assigned. ;; PO-QUEST L0A69: LD A,03Fh ; prepare the character '?'. JR L0AD9 ; forward to PO-ABLE. ; -------------------------------- ; Control characters with operands ; -------------------------------- ; Certain control characters are followed by 1 or 2 operands. ; The entry points from control character table are PO-2-OPER and PO-1-OPER. ; The routines alter the output address of the current channel so that ; subsequent RST 010h instructions take the appropriate action ; before finally resetting the output address back to PRINT-OUT. ;; PO-TV-2 L0A6D: LD DE,L0A87 ; address: PO-CONT will be next output routine LD (05C0Fh),A ; store first operand in TVDATA-hi JR L0A80 ; forward to PO-CHANGE >> ; --- ; -> This initial entry point deals with two operands - AT or TAB. ;; PO-2-OPER L0A75: LD DE,L0A6D ; address: PO-TV-2 will be next output routine JR L0A7D ; forward to PO-TV-1 ; --- ; -> This initial entry point deals with one operand INK to OVER. ;; PO-1-OPER L0A7A: LD DE,L0A87 ; address: PO-CONT will be next output routine ;; PO-TV-1 L0A7D: LD (05C0Eh),A ; store control code in TVDATA-lo ;; PO-CHANGE L0A80: LD HL,(05C51h) ; use CURCHL to find current output channel. LD (HL),E ; make it INC HL ; the supplied LD (HL),D ; address from DE. RET ; return. ; --- ;; PO-CONT L0A87: LD DE,L09F4 ; Address: PRINT-OUT CALL L0A80 ; routine PO-CHANGE to restore normal channel. LD HL,(05C0Eh) ; TVDATA gives control code and possible ; subsequent character LD D,A ; save current character LD A,L ; the stored control code CP 016h ; was it INK to OVER (1 operand) ? JP C,L2211 ; to CO-TEMP-5 JR NZ,L0AC2 ; to PO-TAB if not 22d i.e. 23d TAB. ; else must have been 22d AT. LD B,H ; line to H (0-23d) LD C,D ; column to C (0-31d) LD A,01Fh ; the value 31d SUB C ; reverse the column number. JR C,L0AAC ; to PO-AT-ERR if C was greater than 31d. ADD A,002h ; transform to system range 002h-021h LD C,A ; and place in column register. BIT 1,(IY+001h) ; test FLAGS - is printer in use ? JR NZ,L0ABF ; to PO-AT-SET as line can be ignored. LD A,016h ; 22 decimal SUB B ; subtract line number to reverse ; 0 - 22 becomes 22 - 0. ;; PO-AT-ERR L0AAC: JP C,L1E9F ; to REPORT-B if higher than 22 decimal ; Integer out of range. INC A ; adjust for system range 001h-017h LD B,A ; place in line register INC B ; adjust to system range 002h-018h BIT 0,(IY+002h) ; TV_FLAG - Lower screen in use ? JP NZ,L0C55 ; exit to PO-SCR to test for scrolling CP (IY+031h) ; Compare against DF_SZ JP C,L0C86 ; to REPORT-5 if too low ; Out of screen. ;; PO-AT-SET L0ABF: JP L0DD9 ; print position is valid so exit via CL-SET ; --- ; Continue here when dealing with TAB. ; Note. In BASIC, TAB is followed by a 16-bit number and was initially ; designed to work with any output device. ;; PO-TAB L0AC2: LD A,H ; transfer parameter to A ; Losing current character - ; High byte of TAB parameter. ;; PO-FILL L0AC3: CALL L0B03 ; routine PO-FETCH, HL-addr, BC=line/column. ; column 1 (right), 021h (left) ADD A,C ; add operand to current column DEC A ; range 0 - 31+ AND 01Fh ; make range 0 - 31d RET Z ; return if result zero LD D,A ; Counter to D SET 0,(IY+001h) ; update FLAGS - signal suppress leading space. ;; PO-SPACE L0AD0: LD A,020h ; space character. CALL L0C3B ; routine PO-SAVE prints the character ; using alternate set (normal output routine) DEC D ; decrement counter. JR NZ,L0AD0 ; to PO-SPACE until done RET ; return ; ---------------------- ; Printable character(s) ; ---------------------- ; This routine prints printable characters and continues into ; the position store routine ;; PO-ABLE L0AD9: CALL L0B24 ; routine PO-ANY ; and continue into position store routine. ; ---------------------------- ; THE 'POSITION STORE' ROUTINE ; ---------------------------- ; This routine updates the system variables associated with the main screen, ; the lower screen/input buffer or the ZX printer. ;; PO-STORE L0ADC: BIT 1,(IY+001h) ; Test FLAGS - is printer in use ? JR NZ,L0AFC ; Forward, if so, to PO-ST-PR BIT 0,(IY+002h) ; Test TV_FLAG - is lower screen in use ? JR NZ,L0AF0 ; Forward, if so, to PO-ST-E ; This section deals with the upper screen. LD (05C88h),BC ; Update S_POSN - line/column upper screen LD (05C84h),HL ; Update DF_CC - upper display file address RET ; Return. ; --- ; This section deals with the lower screen. ;; PO-ST-E L0AF0: LD (05C8Ah),BC ; Update SPOSNL line/column lower screen LD (05C82h),BC ; Update ECHO_E line/column input buffer LD (05C86h),HL ; Update DFCCL lower screen memory address RET ; Return. ; --- ; This section deals with the ZX Printer. ;; PO-ST-PR L0AFC: LD (IY+045h),C ; Update P_POSN column position printer LD (05C80h),HL ; Update PR_CC - full printer buffer memory ; address RET ; Return. ; Note. that any values stored in location 23681 will be overwritten with ; the value 91 decimal. ; Credit April 1983, Dilwyn Jones. "Delving Deeper into your ZX Spectrum". ; ---------------------------- ; THE 'POSITION FETCH' ROUTINE ; ---------------------------- ; This routine fetches the line/column and display file address of the upper ; and lower screen or, if the printer is in use, the column position and ; absolute memory address. ; Note. that PR-CC-hi (23681) is used by this routine and if, in accordance ; with the manual (that says this is unused), the location has been used for ; other purposes, then subsequent output to the printer buffer could corrupt ; a 256-byte section of memory. ;; PO-FETCH L0B03: BIT 1,(IY+001h) ; Test FLAGS - is printer in use ? JR NZ,L0B1D ; Forward, if so, to PO-F-PR ; assume upper screen in use and thus optimize for path that requires speed. LD BC,(05C88h) ; Fetch line/column from S_POSN LD HL,(05C84h) ; Fetch DF_CC display file address BIT 0,(IY+002h) ; Test TV_FLAG - lower screen in use ? RET Z ; Return if upper screen in use. ; Overwrite registers with values for lower screen. LD BC,(05C8Ah) ; Fetch line/column from SPOSNL LD HL,(05C86h) ; Fetch display file address from DFCCL RET ; Return. ; --- ; This section deals with the ZX Printer. ;; PO-F-PR L0B1D: LD C,(IY+045h) ; Fetch column from P_POSN. LD HL,(05C80h) ; Fetch printer buffer address from PR_CC. RET ; Return. ; --------------------------------- ; THE 'PRINT ANY CHARACTER' ROUTINE ; --------------------------------- ; This routine is used to print any character in range 32d - 255d ; It is only called from PO-ABLE which continues into PO-STORE ;; PO-ANY L0B24: CP 080h ; ASCII ? JR C,L0B65 ; to PO-CHAR is so. CP 090h ; test if a block graphic character. JR NC,L0B52 ; to PO-T&UDG to print tokens and UDGs ; The 16 2*2 mosaic characters 128-143 decimal are formed from ; bits 0-3 of the character. LD B,A ; save character CALL L0B38 ; routine PO-GR-1 to construct top half ; then bottom half. CALL L0B03 ; routine PO-FETCH fetches print position. LD DE,05C92h ; MEM-0 is location of 8 bytes of character JR L0B7F ; to PR-ALL to print to screen or printer ; --- ;; PO-GR-1 L0B38: LD HL,05C92h ; address MEM-0 - a temporary buffer in ; systems variables which is normally used ; by the calculator. CALL L0B3E ; routine PO-GR-2 to construct top half ; and continue into routine to construct ; bottom half. ;; PO-GR-2 L0B3E: RR B ; rotate bit 0/2 to carry SBC A,A ; result 00h or 0FFh AND 00Fh ; mask off right hand side LD C,A ; store part in C RR B ; rotate bit 1/3 of original chr to carry SBC A,A ; result 00h or 0FFh AND 0F0h ; mask off left hand side OR C ; combine with stored pattern LD C,004h ; four bytes for top/bottom half ;; PO-GR-3 L0B4C: LD (HL),A ; store bit patterns in temporary buffer INC HL ; next address DEC C ; jump back to JR NZ,L0B4C ; to PO-GR-3 until byte is stored 4 times RET ; return ; --- ; Tokens and User defined graphics are now separated. ;; PO-T&UDG L0B52: SUB 0A5h ; the 'RND' character JR NC,L0B5F ; to PO-T to print tokens ADD A,015h ; add 21d to restore to 0 - 20 PUSH BC ; save current print position LD BC,(05C7Bh) ; fetch UDG to address bit patterns JR L0B6A ; to PO-CHAR-2 - common code to lay down ; a bit patterned character ; --- ;; PO-T L0B5F: CALL L0C10 ; routine PO-TOKENS prints tokens JP L0B03 ; exit via a JUMP to PO-FETCH as this routine ; must continue into PO-STORE. ; A JR instruction could be used. ; This point is used to print ASCII characters 32d - 127d. ;; PO-CHAR L0B65: PUSH BC ; save print position LD BC,(05C36h) ; address CHARS ; This common code is used to transfer the character bytes to memory. ;; PO-CHAR-2 L0B6A: EX DE,HL ; transfer destination address to DE LD HL,05C3Bh ; point to FLAGS RES 0,(HL) ; allow for leading space CP 020h ; is it a space ? JR NZ,L0B76 ; to PO-CHAR-3 if not SET 0,(HL) ; signal no leading space to FLAGS ;; PO-CHAR-3 L0B76: LD H,00h ; set high byte to 0 LD L,A ; character to A ; 0-21 UDG or 32-127 ASCII. ADD HL,HL ; multiply ADD HL,HL ; by ADD HL,HL ; eight ADD HL,BC ; HL now points to first byte of character POP BC ; the source address CHARS or UDG EX DE,HL ; character address to DE ; ---------------------------------- ; THE 'PRINT ALL CHARACTERS' ROUTINE ; ---------------------------------- ; This entry point entered from above to print ASCII and UDGs but also from ; earlier to print mosaic characters. ; HL=destination ; DE=character source ; BC=line/column ;; PR-ALL L0B7F: LD A,C ; column to A DEC A ; move right LD A,021h ; pre-load with leftmost position JR NZ,L0B93 ; but if not zero to PR-ALL-1 DEC B ; down one line LD C,A ; load C with 021h BIT 1,(IY+001h) ; test FLAGS - Is printer in use JR Z,L0B93 ; to PR-ALL-1 if not PUSH DE ; save source address CALL L0ECD ; routine COPY-BUFF outputs line to printer POP DE ; restore character source address LD A,C ; the new column number (021h) to C ;; PR-ALL-1 L0B93: CP C ; this test is really for screen - new line ? PUSH DE ; save source CALL Z,L0C55 ; routine PO-SCR considers scrolling POP DE ; restore source PUSH BC ; save line/column PUSH HL ; and destination LD A,(05C91h) ; fetch P_FLAG to accumulator LD B,0FFh ; prepare OVER mask in B. RRA ; bit 0 set if OVER 1 JR C,L0BA4 ; to PR-ALL-2 INC B ; set OVER mask to 0 ;; PR-ALL-2 L0BA4: RRA ; skip bit 1 of P_FLAG RRA ; bit 2 is INVERSE SBC A,A ; will be FF for INVERSE 1 else zero LD C,A ; transfer INVERSE mask to C LD A,008h ; prepare to count 8 bytes AND A ; clear carry to signal screen BIT 1,(IY+001h) ; test FLAGS - is printer in use ? JR Z,L0BB6 ; to PR-ALL-3 if screen SET 1,(IY+030h) ; update FLAGS2 - signal printer buffer has ; been used. SCF ; set carry flag to signal printer. ;; PR-ALL-3 L0BB6: EX DE,HL ; now HL=source, DE=destination ;; PR-ALL-4 L0BB7: EX AF,AF' ; save printer/screen flag LD A,(DE) ; fetch existing destination byte AND B ; consider OVER XOR (HL) ; now XOR with source XOR C ; now with INVERSE MASK LD (DE),A ; update screen/printer EX AF,AF' ; restore flag JR C,L0BD3 ; to PR-ALL-6 - printer address update INC D ; gives next pixel line down screen ;; PR-ALL-5 L0BC1: INC HL ; address next character byte DEC A ; the byte count is decremented JR NZ,L0BB7 ; back to PR-ALL-4 for all 8 bytes EX DE,HL ; destination to HL DEC H ; bring back to last updated screen position BIT 1,(IY+001h) ; test FLAGS - is printer in use ? CALL Z,L0BDB ; if not, call routine PO-ATTR to update ; corresponding colour attribute. POP HL ; restore original screen/printer position POP BC ; and line column DEC C ; move column to right INC HL ; increase screen/printer position RET ; return and continue into PO-STORE ; within PO-ABLE ; --- ; This branch is used to update the printer position by 32 places ; Note. The high byte of the address D remains constant (which it should). ;; PR-ALL-6 L0BD3: EX AF,AF' ; save the flag LD A,020h ; load A with 32 decimal ADD A,E ; add this to E LD E,A ; and store result in E EX AF,AF' ; fetch the flag JR L0BC1 ; back to PR-ALL-5 ; ----------------------------------- ; THE 'GET ATTRIBUTE ADDRESS' ROUTINE ; ----------------------------------- ; This routine is entered with the HL register holding the last screen ; address to be updated by PRINT or PLOT. ; The Spectrum screen arrangement leads to the L register holding the correct ; value for the attribute file and it is only necessary to manipulate H to ; form the correct colour attribute address. ;; PO-ATTR L0BDB: LD A,H ; fetch high byte 040h - 057h RRCA ; shift RRCA ; bits 3 and 4 RRCA ; to right. AND 003h ; range is now 0 - 2 OR 058h ; form correct high byte for third of screen LD H,A ; HL is now correct LD DE,(05C8Fh) ; make D hold ATTR_T, E hold MASK-T LD A,(HL) ; fetch existing attribute XOR E ; apply masks AND D ; XOR E ; BIT 6,(IY+057h) ; test P_FLAG - is this PAPER 9 ?? JR Z,L0BFA ; skip to PO-ATTR-1 if not. AND 0C7h ; set paper BIT 2,A ; to contrast with ink JR NZ,L0BFA ; skip to PO-ATTR-1 XOR 038h ; ;; PO-ATTR-1 L0BFA: BIT 4,(IY+057h) ; test P_FLAG - Is this INK 9 ?? JR Z,L0C08 ; skip to PO-ATTR-2 if not AND 0F8h ; make ink BIT 5,A ; contrast with paper. JR NZ,L0C08 ; to PO-ATTR-2 XOR 007h ; ;; PO-ATTR-2 L0C08: LD (HL),A ; save the new attribute. RET ; return. ; --------------------------------- ; THE 'MESSAGE PRINTING' SUBROUTINE ; --------------------------------- ; This entry point is used to print tape, boot-up, scroll? and error messages. ; On entry the DE register points to an initial step-over byte or the ; inverted end-marker of the previous entry in the table. ; Register A contains the message number, often zero to print first message. ; (HL has nothing important usually P_FLAG) ;; PO-MSG L0C0A: PUSH HL ; put hi-byte zero on stack to suppress LD H,00h ; trailing spaces EX (SP),HL ; ld h,0; push hl would have done ?. JR L0C14 ; forward to PO-TABLE. ; --- ; This entry point prints the BASIC keywords, '<>' etc. from alt set ;; PO-TOKENS L0C10: LD DE,L0095 ; address: TKN-TABLE PUSH AF ; save the token number to control ; trailing spaces - see later * ; -> ;; PO-TABLE L0C14: CALL L0C41 ; routine PO-SEARCH will set carry for ; all messages and function words. JR C,L0C22 ; forward to PO-EACH if not a command, '<>' etc. LD A,020h ; prepare leading space BIT 0,(IY+001h) ; test FLAGS - leading space if not set CALL Z,L0C3B ; routine PO-SAVE to print a space without ; disturbing registers. ;; PO-EACH L0C22: LD A,(DE) ; Fetch character from the table. AND 07Fh ; Cancel any inverted bit. CALL L0C3B ; Routine PO-SAVE to print using the alternate ; set of registers. LD A,(DE) ; Re-fetch character from table. INC DE ; Address next character in the table. ADD A,A ; Was character inverted ? ; (this also doubles character) JR NC,L0C22 ; back to PO-EACH if not. POP DE ; * re-fetch trailing space byte to D CP 048h ; was the last character '$' ? JR Z,L0C35 ; forward to PO-TR-SP to consider trailing ; space if so. CP 082h ; was it < 'A' i.e. '#','>','=' from tokens ; or ' ','.' (from tape) or '?' from scroll RET C ; Return if so as no trailing space required. ;; PO-TR-SP L0C35: LD A,D ; The trailing space flag (zero if an error msg) CP 003h ; Test against RND, INKEY$ and PI which have no ; parameters and therefore no trailing space. RET C ; Return if no trailing space. LD A,020h ; Prepare the space character and continue to ; print and make an indirect return. ; ----------------------------------- ; THE 'RECURSIVE PRINTING' SUBROUTINE ; ----------------------------------- ; This routine which is part of PRINT-OUT allows RST 010h to be used ; recursively to print tokens and the spaces associated with them. ; It is called on three occasions when the value of DE must be preserved. ;; PO-SAVE L0C3B: PUSH DE ; Save DE value. EXX ; Switch in main set RST 10H ; PRINT-A prints using this alternate set. EXX ; Switch back to this alternate set. POP DE ; Restore the initial DE value. RET ; Return. ; ------------ ; Table search ; ------------ ; This subroutine searches a message or the token table for the ; message number held in A. DE holds the address of the table. ;; PO-SEARCH L0C41: PUSH AF ; save the message/token number EX DE,HL ; transfer DE to HL INC A ; adjust for initial step-over byte ;; PO-STEP L0C44: BIT 7,(HL) ; is character inverted ? INC HL ; address next JR Z,L0C44 ; back to PO-STEP if not inverted. DEC A ; decrease counter JR NZ,L0C44 ; back to PO-STEP if not zero EX DE,HL ; transfer address to DE POP AF ; restore message/token number CP 020h ; return with carry set RET C ; for all messages and function tokens LD A,(DE) ; test first character of token SUB 041h ; and return with carry set RET ; if it is less that 'A' ; i.e. '<>', '<=', '>=' ; --------------- ; Test for scroll ; --------------- ; This test routine is called when printing carriage return, when considering ; PRINT AT and from the general PRINT ALL characters routine to test if ; scrolling is required, prompting the user if necessary. ; This is therefore using the alternate set. ; The B register holds the current line. ;; PO-SCR L0C55: BIT 1,(IY+001h) ; test FLAGS - is printer in use ? RET NZ ; return immediately if so. LD DE,L0DD9 ; set DE to address: CL-SET PUSH DE ; and push for return address. LD A,B ; transfer the line to A. BIT 0,(IY+002h) ; test TV_FLAG - lower screen in use ? JP NZ,L0D02 ; jump forward to PO-SCR-4 if so. CP (IY+031h) ; greater than DF_SZ display file size ? JR C,L0C86 ; forward to REPORT-5 if less. ; 'Out of screen' RET NZ ; return (via CL-SET) if greater BIT 4,(IY+002h) ; test TV_FLAG - Automatic listing ? JR Z,L0C88 ; forward to PO-SCR-2 if not. LD E,(IY+02Dh) ; fetch BREG - the count of scroll lines to E. DEC E ; decrease and jump JR Z,L0CD2 ; to PO-SCR-3 if zero and scrolling required. LD A,00h ; explicit - select channel zero. CALL L1601 ; routine CHAN-OPEN opens it. LD SP,(05C3Fh) ; set stack pointer to LIST_SP RES 4,(IY+002h) ; reset TV_FLAG - signal auto listing finished. RET ; return ignoring pushed value, CL-SET ; to MAIN or EDITOR without updating ; print position >> ; --- ;; REPORT-5 L0C86: RST 08H ; ERROR-1 .DEFB 004h ; Error Report: Out of screen ; continue here if not an automatic listing. ;; PO-SCR-2 L0C88: DEC (IY+052h) ; decrease SCR_CT JR NZ,L0CD2 ; forward to PO-SCR-3 to scroll display if ; result not zero. ; now produce prompt. LD A,018h ; reset SUB B ; the LD (05C8Ch),A ; SCR_CT scroll count LD HL,(05C8Fh) ; L=ATTR_T, H=MASK_T PUSH HL ; save on stack LD A,(05C91h) ; P_FLAG PUSH AF ; save on stack to prevent lower screen ; attributes (BORDCR etc.) being applied. LD A,0FDh ; select system channel 'K' CALL L1601 ; routine CHAN-OPEN opens it XOR A ; clear to address message directly LD DE,L0CF8 ; make DE address: scrl-mssg CALL L0C0A ; routine PO-MSG prints to lower screen SET 5,(IY+002h) ; set TV_FLAG - signal lower screen requires ; clearing LD HL,05C3Bh ; make HL address FLAGS SET 3,(HL) ; signal 'L' mode. RES 5,(HL) ; signal 'no new key'. EXX ; switch to main set. ; as calling chr input from alternative set. CALL L15D4 ; routine WAIT-KEY waits for new key ; Note. this is the right routine but the ; stream in use is unsatisfactory. From the ; choices available, it is however the best. EXX ; switch back to alternate set. CP 020h ; space is considered as BREAK JR Z,L0D00 ; forward to REPORT-D if so ; 'BREAK - CONT repeats' CP 0E2h ; is character 'STOP' ? JR Z,L0D00 ; forward to REPORT-D if so OR 020h ; convert to lower-case CP 06Eh ; is character 'n' ? JR Z,L0D00 ; forward to REPORT-D if so else scroll. LD A,0FEh ; select system channel 'S' CALL L1601 ; routine CHAN-OPEN POP AF ; restore original P_FLAG LD (05C91h),A ; and save in P_FLAG. POP HL ; restore original ATTR_T, MASK_T LD (05C8Fh),HL ; and reset ATTR_T, MASK-T as 'scroll?' has ; been printed. ;; PO-SCR-3 L0CD2: CALL L0DFE ; routine CL-SC-ALL to scroll whole display LD B,(IY+031h) ; fetch DF_SZ to B INC B ; increase to address last line of display LD C,021h ; set C to 021h (was 021h from above routine) PUSH BC ; save the line and column in BC. CALL L0E9B ; routine CL-ADDR finds display address. LD A,H ; now find the corresponding attribute byte RRCA ; (this code sequence is used twice RRCA ; elsewhere and is a candidate for RRCA ; a subroutine.) AND 003h ; OR 058h ; LD H,A ; LD DE,05AE0h ; start of last 'line' of attribute area LD A,(DE) ; get attribute for last line LD C,(HL) ; transfer to base line of upper part LD B,020h ; there are thirty two bytes EX DE,HL ; swap the pointers. ;; PO-SCR-3A L0CF0: LD (DE),A ; transfer LD (HL),C ; attributes. INC DE ; address next. INC HL ; address next. DJNZ L0CF0 ; loop back to PO-SCR-3A for all adjacent ; attribute lines. POP BC ; restore the line/column. RET ; return via CL-SET (was pushed on stack). ; --- ; The message 'scroll?' appears here with last byte inverted. ;; scrl-mssg L0CF8: .DEFB 080h ; initial step-over byte. .DEFB "scroll" .DEFB '?'+080h ;; REPORT-D L0D00: RST 08H ; ERROR-1 .DEFB 00Ch ; Error Report: BREAK - CONT repeats ; continue here if using lower display - A holds line number. ;; PO-SCR-4 L0D02: CP 002h ; is line number less than 2 ? JR C,L0C86 ; to REPORT-5 if so ; 'Out of Screen'. ADD A,(IY+031h) ; add DF_SZ SUB 019h ; RET NC ; return if scrolling unnecessary NEG ; Negate to give number of scrolls required. PUSH BC ; save line/column LD B,A ; count to B LD HL,(05C8Fh) ; fetch current ATTR_T, MASK_T to HL. PUSH HL ; and save LD HL,(05C91h) ; fetch P_FLAG PUSH HL ; and save. ; to prevent corruption by input AT CALL L0D4D ; routine TEMPS sets to BORDCR etc LD A,B ; transfer scroll number to A. ;; PO-SCR-4A L0D1C: PUSH AF ; save scroll number. LD HL,05C6Bh ; address DF_SZ LD B,(HL) ; fetch old value LD A,B ; transfer to A INC A ; and increment LD (HL),A ; then put back. LD HL,05C89h ; address S_POSN_hi - line CP (HL) ; compare JR C,L0D2D ; forward to PO-SCR-4B if scrolling required INC (HL) ; else increment S_POSN_hi LD B,018h ; set count to whole display ?? ; Note. should be 017h and the top line will be ; scrolled into the ROM which is harmless on ; the standard set up. ; credit P.Giblin 1984. ;; PO-SCR-4B L0D2D: CALL L0E00 ; routine CL-SCROLL scrolls B lines POP AF ; restore scroll counter. DEC A ; decrease JR NZ,L0D1C ; back to PO-SCR-4A until done POP HL ; restore original P_FLAG. LD (IY+057h),L ; and overwrite system variable P_FLAG. POP HL ; restore original ATTR_T/MASK_T. LD (05C8Fh),HL ; and update system variables. LD BC,(05C88h) ; fetch S_POSN to BC. RES 0,(IY+002h) ; signal to TV_FLAG - main screen in use. CALL L0DD9 ; call routine CL-SET for upper display. SET 0,(IY+002h) ; signal to TV_FLAG - lower screen in use. POP BC ; restore line/column RET ; return via CL-SET for lower display. ; ---------------------- ; Temporary colour items ; ---------------------- ; This subroutine is called 11 times to copy the permanent colour items ; to the temporary ones. ;; TEMPS L0D4D: XOR A ; clear the accumulator LD HL,(05C8Dh) ; fetch L=ATTR_P and H=MASK_P BIT 0,(IY+002h) ; test TV_FLAG - is lower screen in use ? JR Z,L0D5B ; skip to TEMPS-1 if not LD H,A ; set H, MASK P, to 00000000. LD L,(IY+00Eh) ; fetch BORDCR to L which is used for lower ; screen. ;; TEMPS-1 L0D5B: LD (05C8Fh),HL ; transfer values to ATTR_T and MASK_T ; for the print flag the permanent values are odd bits, temporary even bits. LD HL,05C91h ; address P_FLAG. JR NZ,L0D65 ; skip to TEMPS-2 if lower screen using A=0. LD A,(HL) ; else pick up flag bits. RRCA ; rotate permanent bits to temporary bits. ;; TEMPS-2 L0D65: XOR (HL) ; AND 055h ; BIN 01010101 XOR (HL) ; permanent now as original LD (HL),A ; apply permanent bits to temporary bits. RET ; and return. ; ----------------- ; THE 'CLS' COMMAND ; ----------------- ; This command clears the display. ; The routine is also called during initialization and by the CLEAR command. ; If it's difficult to write it should be difficult to read. ;; CLS L0D6B: CALL L0DAF ; Routine CL-ALL clears the entire display and ; sets the attributes to the permanent ones ; from ATTR-P. ; Having cleared all 24 lines of the display area, continue into the ; subroutine that clears the lower display area. Note that at the moment ; the attributes for the lower lines are the same as upper ones and have ; to be changed to match the BORDER colour. ; -------------------------- ; THE 'CLS-LOWER' SUBROUTINE ; -------------------------- ; This routine is called from INPUT, and from the MAIN execution loop. ; This is very much a housekeeping routine which clears between 2 and 23 ; lines of the display, setting attributes and correcting situations where ; errors have occurred while the normal input and output routines have been ; temporarily diverted to deal with, say colour control codes. ;; CLS-LOWER L0D6E: LD HL,05C3Ch ; address System Variable TV_FLAG. RES 5,(HL) ; TV_FLAG - signal do not clear lower screen. SET 0,(HL) ; TV_FLAG - signal lower screen in use. CALL L0D4D ; routine TEMPS applies permanent attributes, ; in this case BORDCR to ATTR_T. ; Note. this seems unnecessary and is repeated ; within CL-LINE. LD B,(IY+031h) ; fetch lower screen display file size DF_SZ CALL L0E44 ; routine CL-LINE clears lines to bottom of the ; display and sets attributes from BORDCR while ; preserving the B register. LD HL,05AC0h ; set initial attribute address to the leftmost ; cell of second line up. LD A,(05C8Dh) ; fetch permanent attribute from ATTR_P. DEC B ; decrement lower screen display file size. JR L0D8E ; forward to enter the backfill loop at CLS-3 ; where B is decremented again. ; --- ; The backfill loop is entered at midpoint and ensures, if more than 2 ; lines have been cleared, that any other lines take the permanent screen ; attributes. ;; CLS-1 L0D87: LD C,020h ; set counter to 32 character cells per line ;; CLS-2 L0D89: DEC HL ; decrease attribute address. LD (HL),A ; and place attributes in next line up. DEC C ; decrease the 32 counter. JR NZ,L0D89 ; loop back to CLS-2 until all 32 cells done. ;; CLS-3 L0D8E: DJNZ L0D87 ; decrease B counter and back to CLS-1 ; if not zero. LD (IY+031h),002h ; now set DF_SZ lower screen to 2 ; This entry point is also called from CL-ALL below to ; reset the system channel input and output addresses to normal. ;; CL-CHAN L0D94: LD A,0FDh ; select system channel 'K' CALL L1601 ; routine CHAN-OPEN opens it. LD HL,(05C51h) ; fetch CURCHL to HL to address current channel LD DE,L09F4 ; set address to PRINT-OUT for first pass. AND A ; clear carry for first pass. ;; CL-CHAN-A L0DA0: LD (HL),E ; Insert the output address on the first pass INC HL ; or the input address on the second pass. LD (HL),D ; INC HL ; LD DE,L10A8 ; fetch address KEY-INPUT for second pass CCF ; complement carry flag - will set on pass 1. JR C,L0DA0 ; back to CL-CHAN-A if first pass else done. LD BC,01721h ; line 23 for lower screen JR L0DD9 ; exit via CL-SET to set column ; for lower display ; --------------------------- ; Clearing whole display area ; --------------------------- ; This subroutine called from CLS, AUTO-LIST and MAIN-3 ; clears 24 lines of the display and resets the relevant system variables. ; This routine also recovers from an error situation where, for instance, an ; invalid colour or position control code has left the output routine addressing ; PO-TV-2 or PO-CONT. ;; CL-ALL L0DAF: LD HL,000h ; Initialize plot coordinates. LD (05C7Dh),HL ; Set system variable COORDS to 0,0. RES 0,(IY+030h) ; update FLAGS2 - signal main screen is clear. CALL L0D94 ; routine CL-CHAN makes channel 'K' 'normal'. LD A,0FEh ; select system channel 'S' CALL L1601 ; routine CHAN-OPEN opens it. CALL L0D4D ; routine TEMPS applies permanent attributes, ; in this case ATTR_P, to ATTR_T. ; Note. this seems unnecessary. LD B,018h ; There are 24 lines. CALL L0E44 ; routine CL-LINE clears 24 text lines and sets ; attributes from ATTR-P. ; This routine preserves B and sets C to 021h. LD HL,(05C51h) ; fetch CURCHL make HL address output routine. LD DE,L09F4 ; address: PRINT-OUT LD (HL),E ; is made INC HL ; the normal LD (HL),D ; output address. LD (IY+052h),001h ; set SCR_CT - scroll count - to default. ; Note. BC already contains 01821h. LD BC,01821h ; reset column and line to 0,0 ; and continue into CL-SET, below, exiting ; via PO-STORE (for the upper screen). ; -------------------- ; THE 'CL-SET' ROUTINE ; -------------------- ; This important subroutine is used to calculate the character output ; address for screens or printer based on the line/column for screens ; or the column for printer. ;; CL-SET L0DD9: LD HL,05B00h ; the base address of printer buffer BIT 1,(IY+001h) ; test FLAGS - is printer in use ? JR NZ,L0DF4 ; forward to CL-SET-2 if so. LD A,B ; transfer line to A. BIT 0,(IY+002h) ; test TV_FLAG - lower screen in use ? JR Z,L0DEE ; skip to CL-SET-1 if handling upper part ADD A,(IY+031h) ; add DF_SZ for lower screen SUB 018h ; and adjust. ;; CL-SET-1 L0DEE: PUSH BC ; save the line/column. LD B,A ; transfer line to B ; (adjusted if lower screen) CALL L0E9B ; routine CL-ADDR calculates address at left ; of screen. POP BC ; restore the line/column. ;; CL-SET-2 L0DF4: LD A,021h ; the column 001h-021h is reversed SUB C ; to range 00h - 020h LD E,A ; now transfer to DE LD D,00h ; prepare for addition ADD HL,DE ; and add to base address JP L0ADC ; exit via PO-STORE to update the relevant ; system variables. ; ---------------- ; Handle scrolling ; ---------------- ; The routine CL-SC-ALL is called once from PO to scroll all the display ; and from the routine CL-SCROLL, once, to scroll part of the display. ;; CL-SC-ALL L0DFE: LD B,017h ; scroll 23 lines, after 'scroll?'. ;; CL-SCROLL L0E00: CALL L0E9B ; routine CL-ADDR gets screen address in HL. LD C,008h ; there are 8 pixel lines to scroll. ;; CL-SCR-1 L0E05: PUSH BC ; save counters. PUSH HL ; and initial address. LD A,B ; get line count. AND 007h ; will set zero if all third to be scrolled. LD A,B ; re-fetch the line count. JR NZ,L0E19 ; forward to CL-SCR-3 if partial scroll. ; HL points to top line of third and must be copied to bottom of previous 3rd. ; ( so HL = 04800h or 05000h ) ( but also sometimes 04000h ) ;; CL-SCR-2 L0E0D: EX DE,HL ; copy HL to DE. LD HL,0F8E0h ; subtract 008h from H and add 0E0h to L - ADD HL,DE ; to make destination bottom line of previous ; third. EX DE,HL ; restore the source and destination. LD BC,020h ; thirty-two bytes are to be copied. DEC A ; decrement the line count. LDIR ; copy a pixel line to previous third. ;; CL-SCR-3 L0E19: EX DE,HL ; save source in DE. LD HL,0FFE0h ; load the value -32. ADD HL,DE ; add to form destination in HL. EX DE,HL ; switch source and destination LD B,A ; save the count in B. AND 007h ; mask to find count applicable to current RRCA ; third and RRCA ; multiply by RRCA ; thirty two (same as 5 RLCAs) LD C,A ; transfer byte count to C (0E0h at most) LD A,B ; store line count to A LD B,00h ; make B zero LDIR ; copy bytes (BC=0, H incremented, L=0) LD B,007h ; set B to 7, C is zero. ADD HL,BC ; add 7 to H to address next third. AND 0F8h ; has last third been done ? JR NZ,L0E0D ; back to CL-SCR-2 if not. POP HL ; restore topmost address. INC H ; next pixel line down. POP BC ; restore counts. DEC C ; reduce pixel line count. JR NZ,L0E05 ; back to CL-SCR-1 if all eight not done. CALL L0E88 ; routine CL-ATTR gets address in attributes ; from current 'ninth line', count in BC. LD HL,0FFE0h ; set HL to the 16-bit value -32. ADD HL,DE ; and add to form destination address. EX DE,HL ; swap source and destination addresses. LDIR ; copy bytes scrolling the linear attributes. LD B,001h ; continue to clear the bottom line. ; ------------------------------ ; THE 'CLEAR TEXT LINES' ROUTINE ; ------------------------------ ; This subroutine, called from CL-ALL, CLS-LOWER and AUTO-LIST and above, ; clears text lines at bottom of display. ; The B register holds on entry the number of lines to be cleared 1-24. ;; CL-LINE L0E44: PUSH BC ; save line count CALL L0E9B ; routine CL-ADDR gets top address LD C,008h ; there are eight screen lines to a text line. ;; CL-LINE-1 L0E4A: PUSH BC ; save pixel line count PUSH HL ; and save the address LD A,B ; transfer the line to A (1-24). ;; CL-LINE-2 L0E4D: AND 007h ; mask 0-7 to consider thirds at a time RRCA ; multiply RRCA ; by 32 (same as five RLCA instructions) RRCA ; now 32 - 256(0) LD C,A ; store result in C LD A,B ; save line in A (1-24) LD B,00h ; set high byte to 0, prepare for ldir. DEC C ; decrement count 31-255. LD D,H ; copy HL LD E,L ; to DE. LD (HL),00h ; blank the first byte. INC DE ; make DE point to next byte. LDIR ; ldir will clear lines. LD DE,00701h ; now address next third adjusting ADD HL,DE ; register E to address left hand side DEC A ; decrease the line count. AND 0F8h ; will be 16, 8 or 0 (AND 018h will do). LD B,A ; transfer count to B. JR NZ,L0E4D ; back to CL-LINE-2 if 16 or 8 to do ; the next third. POP HL ; restore start address. INC H ; address next line down. POP BC ; fetch counts. DEC C ; decrement pixel line count JR NZ,L0E4A ; back to CL-LINE-1 till all done. CALL L0E88 ; routine CL-ATTR gets attribute address ; in DE and B * 32 in BC. LD H,D ; transfer the address LD L,E ; to HL. INC DE ; make DE point to next location. LD A,(05C8Dh) ; fetch ATTR_P - permanent attributes BIT 0,(IY+002h) ; test TV_FLAG - lower screen in use ? JR Z,L0E80 ; skip to CL-LINE-3 if not. LD A,(05C48h) ; else lower screen uses BORDCR as attribute. ;; CL-LINE-3 L0E80: LD (HL),A ; put attribute in first byte. DEC BC ; decrement the counter. LDIR ; copy bytes to set all attributes. POP BC ; restore the line 001h-024h. LD C,021h ; make column 021h. (No use is made of this) RET ; return to the calling routine. ; ------------------ ; Attribute handling ; ------------------ ; This subroutine is called from CL-LINE or CL-SCROLL with the HL register ; pointing to the 'ninth' line and H needs to be decremented before or after ; the division. Had it been done first then either present code or that used ; at the start of PO-ATTR could have been used. ; The Spectrum screen arrangement leads to the L register already holding ; the correct value for the attribute file and it is only necessary ; to manipulate H to form the correct colour attribute address. ;; CL-ATTR L0E88: LD A,H ; fetch H to A - 048h, 050h, or 058h. RRCA ; divide by RRCA ; eight. RRCA ; 009h, 00Ah or 00Bh. DEC A ; 008h, 009h or 00Ah. OR 050h ; 058h, 059h or 05Ah. LD H,A ; save high byte of attributes. EX DE,HL ; transfer attribute address to DE LD H,C ; set H to zero - from last LDIR. LD L,B ; load L with the line from B. ADD HL,HL ; multiply ADD HL,HL ; by ADD HL,HL ; thirty two ADD HL,HL ; to give count of attribute ADD HL,HL ; cells to the end of display. LD B,H ; transfer the result LD C,L ; to register BC. RET ; return. ; ------------------------------- ; Handle display with line number ; ------------------------------- ; This subroutine is called from four places to calculate the address ; of the start of a screen character line which is supplied in B. ;; CL-ADDR L0E9B: LD A,018h ; reverse the line number SUB B ; to range 00h - 017h. LD D,A ; save line in D for later. RRCA ; multiply RRCA ; by RRCA ; thirty-two. AND 0E0h ; mask off low bits to make LD L,A ; L a multiple of 32. LD A,D ; bring back the line to A. AND 018h ; now 00h, 008h or 010h. OR 040h ; add the base address of screen. LD H,A ; HL now has the correct address. RET ; return. ; ------------------- ; Handle COPY command ; ------------------- ; This command copies the top 176 lines to the ZX Printer ; It is popular to call this from machine code at point ; L0EAF with B holding 192 (and interrupts disabled) for a full-screen ; copy. This particularly applies to 16K Spectrums as time-critical ; machine code routines cannot be written in the first 16K of RAM as ; it is shared with the ULA which has precedence over the Z80 chip. ;; COPY L0EAC: DI ; disable interrupts as this is time-critical. LD B,0B0h ; top 176 lines. L0EAF: LD HL,04000h ; address start of the display file. ; now enter a loop to handle each pixel line. ;; COPY-1 L0EB2: PUSH HL ; save the screen address. PUSH BC ; and the line counter. CALL L0EF4 ; routine COPY-LINE outputs one line. POP BC ; restore the line counter. POP HL ; and display address. INC H ; next line down screen within 'thirds'. LD A,H ; high byte to A. AND 007h ; result will be zero if we have left third. JR NZ,L0EC9 ; forward to COPY-2 if not to continue loop. LD A,L ; consider low byte first. ADD A,020h ; increase by 32 - sets carry if back to zero. LD L,A ; will be next group of 8. CCF ; complement - carry set if more lines in ; the previous third. SBC A,A ; will be FF, if more, else 00. AND 0F8h ; will be F8 (-8) or 00. ADD A,H ; that is subtract 8, if more to do in third. LD H,A ; and reset address. ;; COPY-2 L0EC9: DJNZ L0EB2 ; back to COPY-1 for all lines. JR L0EDA ; forward to COPY-END to switch off the printer ; motor and enable interrupts. ; Note. Nothing else is required. ; ------------------------------ ; Pass printer buffer to printer ; ------------------------------ ; This routine is used to copy 8 text lines from the printer buffer ; to the ZX Printer. These text lines are mapped linearly so HL does ; not need to be adjusted at the end of each line. ;; COPY-BUFF L0ECD: DI ; disable interrupts LD HL,05B00h ; the base address of the Printer Buffer. LD B,008h ; set count to 8 lines of 32 bytes. ;; COPY-3 L0ED3: PUSH BC ; save counter. CALL L0EF4 ; routine COPY-LINE outputs 32 bytes POP BC ; restore counter. DJNZ L0ED3 ; loop back to COPY-3 for all 8 lines. ; then stop motor and clear buffer. ; Note. the COPY command rejoins here, essentially to execute the next ; three instructions. ;; COPY-END L0EDA: LD A,004h ; output value 4 to port OUT (0FBh),A ; to stop the slowed printer motor. EI ; enable interrupts. ; -------------------- ; Clear Printer Buffer ; -------------------- ; This routine clears an arbitrary 256 bytes of memory. ; Note. The routine seems designed to clear a buffer that follows the ; system variables. ; The routine should check a flag or HL address and simply return if COPY ; is in use. ; As a consequence of this omission the buffer will needlessly ; be cleared when COPY is used and the screen/printer position may be set to ; the start of the buffer and the line number to 0 (B) ; giving an 'Out of Screen' error. ; There seems to have been an unsuccessful attempt to circumvent the use ; of PR_CC_hi. ;; CLEAR-PRB L0EDF: LD HL,05B00h ; the location of the buffer. LD (IY+046h),L ; update PR_CC_lo - set to zero - superfluous. XOR A ; clear the accumulator. LD B,A ; set count to 256 bytes. ;; PRB-BYTES L0EE7: LD (HL),A ; set addressed location to zero. INC HL ; address next byte - Note. not INC L. DJNZ L0EE7 ; back to PRB-BYTES. repeat for 256 bytes. RES 1,(IY+030h) ; set FLAGS2 - signal printer buffer is clear. LD C,021h ; set the column position . JP L0DD9 ; exit via CL-SET and then PO-STORE. ; ----------------- ; Copy line routine ; ----------------- ; This routine is called from COPY and COPY-BUFF to output a line of ; 32 bytes to the ZX Printer. ; Output to port 0FBh - ; bit 7 set - activate stylus. ; bit 7 low - deactivate stylus. ; bit 2 set - stops printer. ; bit 2 reset - starts printer ; bit 1 set - slows printer. ; bit 1 reset - normal speed. ;; COPY-LINE L0EF4: LD A,B ; fetch the counter 1-8 or 1-176 CP 003h ; is it 01 or 02 ?. SBC A,A ; result is 0FFh if so else 00h. AND 002h ; result is 02 now else 00. ; bit 1 set slows the printer. OUT (0FBh),A ; slow the printer for the ; last two lines. LD D,A ; save the mask to control the printer later. ;; COPY-L-1 L0EFD: CALL L1F54 ; call BREAK-KEY to read keyboard immediately. JR C,L0F0C ; forward to COPY-L-2 if 'break' not pressed. LD A,004h ; else stop the OUT (0FBh),A ; printer motor. EI ; enable interrupts. CALL L0EDF ; call routine CLEAR-PRB. ; Note. should not be cleared if COPY in use. ;; REPORT-Dc L0F0A: RST 08H ; ERROR-1 .DEFB 00Ch ; Error Report: BREAK - CONT repeats ;; COPY-L-2 L0F0C: IN A,(0FBh) ; test now to see if ADD A,A ; a printer is attached. RET M ; return if not - but continue with parent ; command. JR NC,L0EFD ; back to COPY-L-1 if stylus of printer not ; in position. LD C,020h ; set count to 32 bytes. ;; COPY-L-3 L0F14: LD E,(HL) ; fetch a byte from line. INC HL ; address next location. Note. not INC L. LD B,008h ; count the bits. ;; COPY-L-4 L0F18: RL D ; prepare mask to receive bit. RL E ; rotate leftmost print bit to carry RR D ; and back to bit 7 of D restoring bit 1 ;; COPY-L-5 L0F1E: IN A,(0FBh) ; read the port. RRA ; bit 0 to carry. JR NC,L0F1E ; back to COPY-L-5 if stylus not in position. LD A,D ; transfer command bits to A. OUT (0FBh),A ; and output to port. DJNZ L0F18 ; loop back to COPY-L-4 for all 8 bits. DEC C ; decrease the byte count. JR NZ,L0F14 ; back to COPY-L-3 until 256 bits done. RET ; return to calling routine COPY/COPY-BUFF. ; ---------------------------------- ; Editor routine for BASIC and INPUT ; ---------------------------------- ; The editor is called to prepare or edit a BASIC line. ; It is also called from INPUT to input a numeric or string expression. ; The behaviour and options are quite different in the various modes ; and distinguished by bit 5 of FLAGX. ; ; This is a compact and highly versatile routine. ;; EDITOR L0F2C: LD HL,(05C3Dh) ; fetch ERR_SP PUSH HL ; save on stack ;; ED-AGAIN L0F30: LD HL,L107F ; address: ED-ERROR PUSH HL ; save address on stack and LD (05C3Dh),SP ; make ERR_SP point to it. ; Note. While in editing/input mode should an error occur then RST 08 will ; update X_PTR to the location reached by CH_ADD and jump to ED-ERROR ; where the error will be cancelled and the loop begin again from ED-AGAIN ; above. The position of the error will be apparent when the lower screen is ; reprinted. If no error then the re-iteration is to ED-LOOP below when ; input is arriving from the keyboard. ;; ED-LOOP L0F38: CALL L15D4 ; routine WAIT-KEY gets key possibly ; changing the mode. PUSH AF ; save key. LD D,00h ; and give a short click based LD E,(IY-001h) ; on PIP value for duration. LD HL,0C8h ; and pitch. CALL L03B5 ; routine BEEPER gives click - effective ; with rubber keyboard. POP AF ; get saved key value. LD HL,L0F38 ; address: ED-LOOP is loaded to HL. PUSH HL ; and pushed onto stack. ; At this point there is a looping return address on the stack, an error ; handler and an input stream set up to supply characters. ; The character that has been received can now be processed. CP 018h ; range 24 to 255 ? JR NC,L0F81 ; forward to ADD-CHAR if so. CP 007h ; lower than 7 ? JR C,L0F81 ; forward to ADD-CHAR also. ; Note. This is a 'bug' and chr$ 6, the comma ; control character, should have had an ; entry in the ED-KEYS table. ; Steven Vickers, 1984, Pitman. CP 010h ; less than 16 ? JR C,L0F92 ; forward to ED-KEYS if editing control ; range 7 to 15 dealt with by a table LD BC,002h ; prepare for ink/paper etc. LD D,A ; save character in D CP 016h ; is it ink/paper/bright etc. ? JR C,L0F6C ; forward to ED-CONTR if so ; leaves 22d AT and 23d TAB ; which can't be entered via KEY-INPUT. ; so this code is never normally executed ; when the keyboard is used for input. INC BC ; if it was AT/TAB - 3 locations required BIT 7,(IY+037h) ; test FLAGX - Is this INPUT LINE ? JP Z,L101E ; jump to ED-IGNORE if not, else CALL L15D4 ; routine WAIT-KEY - input address is KEY-NEXT ; but is reset to KEY-INPUT LD E,A ; save first in E ;; ED-CONTR L0F6C: CALL L15D4 ; routine WAIT-KEY for control. ; input address will be key-next. PUSH DE ; saved code/parameters LD HL,(05C5Bh) ; fetch address of keyboard cursor from K_CUR RES 0,(IY+007h) ; set MODE to 'L' CALL L1655 ; routine MAKE-ROOM makes 2/3 spaces at cursor POP BC ; restore code/parameters INC HL ; address first location LD (HL),B ; place code (ink etc.) INC HL ; address next LD (HL),C ; place possible parameter. If only one ; then DE points to this location also. JR L0F8B ; forward to ADD-CH-1 ; ------------------------ ; Add code to current line ; ------------------------ ; this is the branch used to add normal non-control characters ; with ED-LOOP as the stacked return address. ; it is also the OUTPUT service routine for system channel 'R'. ;; ADD-CHAR L0F81: RES 0,(IY+007h) ; set MODE to 'L' X0F85: LD HL,(05C5Bh) ; fetch address of keyboard cursor from K_CUR CALL L1652 ; routine ONE-SPACE creates one space. ; either a continuation of above or from ED-CONTR with ED-LOOP on stack. ;; ADD-CH-1 L0F8B: LD (DE),A ; load current character to last new location. INC DE ; address next LD (05C5Bh),DE ; and update K_CUR system variable. RET ; return - either a simple return ; from ADD-CHAR or to ED-LOOP on stack. ; --- ; a branch of the editing loop to deal with control characters ; using a look-up table. ;; ED-KEYS L0F92: LD E,A ; character to E. LD D,00h ; prepare to add. LD HL,L0FA0 - 7 ; base address of editing keys table. 00F99h ADD HL,DE ; add E LD E,(HL) ; fetch offset to E ADD HL,DE ; add offset for address of handling routine. PUSH HL ; push the address on machine stack. LD HL,(05C5Bh) ; load address of cursor from K_CUR. RET ; Make an indirect jump forward to routine. ; ------------------ ; Editing keys table ; ------------------ ; For each code in the range 007h to 00Fh this table contains a ; single offset byte to the routine that services that code. ; Note. for what was intended there should also have been an ; entry for chr$ 6 with offset to ed-symbol. ;; ed-keys-t L0FA0: .DEFB 009h ;L0FA9 - $ ; 07d offset 009h to Address: ED-EDIT .DEFB 066h ;L1007 - $ ; 08d offset 066h to Address: ED-LEFT .DEFB 06Ah ;L100C - $ ; 09d offset 06Ah to Address: ED-RIGHT .DEFB 050h ;L0FF3 - $ ; 10d offset 050h to Address: ED-DOWN .DEFB 0B5h ;L1059 - $ ; 11d offset 0B5h to Address: ED-UP .DEFB 070h ;L1015 - $ ; 12d offset 070h to Address: ED-DELETE .DEFB 07Eh ;L1024 - $ ; 13d offset 07Eh to Address: ED-ENTER .DEFB 0CFh ;L1076 - $ ; 14d offset 0CFh to Address: ED-SYMBOL .DEFB 0D4h ;L107C - $ ; 15d offset 0D4h to Address: ED-GRAPH ; --------------- ; Handle EDIT key ; --------------- ; The user has pressed SHIFT 1 to bring edit line down to bottom of screen. ; Alternatively the user wishes to clear the input buffer and start again. ; Alternatively ... ;; ED-EDIT L0FA9: LD HL,(05C49h) ; fetch E_PPC the last line number entered. ; Note. may not exist and may follow program. BIT 5,(IY+037h) ; test FLAGX - input mode ? JP NZ,L1097 ; jump forward to CLEAR-SP if not in editor. CALL L196E ; routine LINE-ADDR to find address of line ; or following line if it doesn't exist. CALL L1695 ; routine LINE-NO will get line number from ; address or previous line if at end-marker. LD A,D ; if there is no program then DE will OR E ; contain zero so test for this. JP Z,L1097 ; jump to CLEAR-SP if so. ; Note. at this point we have a validated line number, not just an ; approximation and it would be best to update E_PPC with the true ; cursor line value which would enable the line cursor to be suppressed ; in all situations - see shortly. PUSH HL ; save address of line. INC HL ; address low byte of length. LD C,(HL) ; transfer to C INC HL ; next to high byte LD B,(HL) ; transfer to B. LD HL,00Ah ; an overhead of ten bytes ADD HL,BC ; is added to length. LD B,H ; transfer adjusted value LD C,L ; to BC register. CALL L1F05 ; routine TEST-ROOM checks free memory. CALL L1097 ; routine CLEAR-SP clears editing area. LD HL,(05C51h) ; address CURCHL EX (SP),HL ; swap with line address on stack PUSH HL ; save line address underneath LD A,0FFh ; select system channel 'R' CALL L1601 ; routine CHAN-OPEN opens it POP HL ; drop line address DEC HL ; make it point to first byte of line num. DEC (IY+00Fh) ; decrease E_PPC_lo to suppress line cursor. ; Note. ineffective when E_PPC is one ; greater than last line of program perhaps ; as a result of a delete. ; credit. Paul Harrison 1982. CALL L1855 ; routine OUT-LINE outputs the BASIC line ; to the editing area. INC (IY+00Fh) ; restore E_PPC_lo to the previous value. LD HL,(05C59h) ; address E_LINE in editing area. INC HL ; advance INC HL ; past space INC HL ; and digit characters INC HL ; of line number. LD (05C5Bh),HL ; update K_CUR to address start of BASIC. POP HL ; restore the address of CURCHL. CALL L1615 ; routine CHAN-FLAG sets flags for it. RET ; RETURN to ED-LOOP. ; ------------------- ; Cursor down editing ; ------------------- ; The BASIC lines are displayed at the top of the screen and the user ; wishes to move the cursor down one line in edit mode. ; With INPUT LINE, this key must be used instead of entering STOP. ;; ED-DOWN L0FF3: BIT 5,(IY+037h) ; test FLAGX - Input Mode ? JR NZ,L1001 ; skip to ED-STOP if so LD HL,05C49h ; address E_PPC - 'current line' CALL L190F ; routine LN-FETCH fetches number of next ; line or same if at end of program. JR L106E ; forward to ED-LIST to produce an ; automatic listing. ; --- ;; ED-STOP L1001: LD (IY+00h),010h ; set ERR_NR to 'STOP in INPUT' code JR L1024 ; forward to ED-ENTER to produce error. ; ------------------- ; Cursor left editing ; ------------------- ; This acts on the cursor in the lower section of the screen in both ; editing and input mode. ;; ED-LEFT L1007: CALL L1031 ; routine ED-EDGE moves left if possible JR L1011 ; forward to ED-CUR to update K-CUR ; and return to ED-LOOP. ; -------------------- ; Cursor right editing ; -------------------- ; This acts on the cursor in the lower screen in both editing and input ; mode and moves it to the right. ;; ED-RIGHT L100C: LD A,(HL) ; fetch addressed character. CP 00Dh ; is it carriage return ? RET Z ; return if so to ED-LOOP INC HL ; address next character ;; ED-CUR L1011: LD (05C5Bh),HL ; update K_CUR system variable RET ; return to ED-LOOP ; -------------- ; DELETE editing ; -------------- ; This acts on the lower screen and deletes the character to left of ; cursor. If control characters are present these are deleted first ; leaving the naked parameter (0-7) which appears as a '?' except in the ; case of chr$ 6 which is the comma control character. It is not mandatory ; to delete these second characters. ;; ED-DELETE L1015: CALL L1031 ; routine ED-EDGE moves cursor to left. LD BC,001h ; of character to be deleted. JP L19E8 ; to RECLAIM-2 reclaim the character. ; ------------------------------------------ ; Ignore next 2 codes from key-input routine ; ------------------------------------------ ; Since AT and TAB cannot be entered this point is never reached ; from the keyboard. If inputting from a tape device or network then ; the control and two following characters are ignored and processing ; continues as if a carriage return had been received. ; Here, perhaps, another Spectrum has said print #15; AT 0,0; "This is yellow" ; and this one is interpreting input #15; a$. ;; ED-IGNORE L101E: CALL L15D4 ; routine WAIT-KEY to ignore keystroke. CALL L15D4 ; routine WAIT-KEY to ignore next key. ; ------------- ; Enter/newline ; ------------- ; The enter key has been pressed to have BASIC line or input accepted. ;; ED-ENTER L1024: POP HL ; discard address ED-LOOP POP HL ; drop address ED-ERROR ;; ED-END L1026: POP HL ; the previous value of ERR_SP LD (05C3Dh),HL ; is restored to ERR_SP system variable BIT 7,(IY+00h) ; is ERR_NR 0FFh (= 'OK') ? RET NZ ; return if so LD SP,HL ; else put error routine on stack RET ; and make an indirect jump to it. ; ----------------------------- ; Move cursor left when editing ; ----------------------------- ; This routine moves the cursor left. The complication is that it must ; not position the cursor between control codes and their parameters. ; It is further complicated in that it deals with TAB and AT characters ; which are never present from the keyboard. ; The method is to advance from the beginning of the line each time, ; jumping one, two, or three characters as necessary saving the original ; position at each jump in DE. Once it arrives at the cursor then the next ; legitimate leftmost position is in DE. ;; ED-EDGE L1031: SCF ; carry flag must be set to call the nested CALL L1195 ; subroutine SET-DE. ; if input then DE=WORKSP ; if editing then DE=E_LINE SBC HL,DE ; subtract address from start of line ADD HL,DE ; and add back. INC HL ; adjust for carry. POP BC ; drop return address RET C ; return to ED-LOOP if already at left ; of line. PUSH BC ; resave return address - ED-LOOP. LD B,H ; transfer HL - cursor address LD C,L ; to BC register pair. ; at this point DE addresses start of line. ;; ED-EDGE-1 L103E: LD H,D ; transfer DE - leftmost pointer LD L,E ; to HL INC HL ; address next leftmost character to ; advance position each time. LD A,(DE) ; pick up previous in A AND 0F0h ; lose the low bits CP 010h ; is it INK to TAB 010h-01Fh ? ; that is, is it followed by a parameter ? JR NZ,L1051 ; to ED-EDGE-2 if not ; HL has been incremented once INC HL ; address next as at least one parameter. ; in fact since 'tab' and 'at' cannot be entered the next section seems ; superfluous. ; The test will always fail and the jump to ED-EDGE-2 will be taken. LD A,(DE) ; reload leftmost character SUB 017h ; decimal 23 ('tab') ADC A,00h ; will be 0 for 'tab' and 'at'. JR NZ,L1051 ; forward to ED-EDGE-2 if not ; HL has been incremented twice INC HL ; increment a third time for 'at'/'tab' ;; ED-EDGE-2 L1051: AND A ; prepare for true subtraction SBC HL,BC ; subtract cursor address from pointer ADD HL,BC ; and add back ; Note when HL matches the cursor position BC, ; there is no carry and the previous ; position is in DE. EX DE,HL ; transfer result to DE if looping again. ; transfer DE to HL to be used as K-CUR ; if exiting loop. JR C,L103E ; back to ED-EDGE-1 if cursor not matched. RET ; return. ; ----------------- ; Cursor up editing ; ----------------- ; The main screen displays part of the BASIC program and the user wishes ; to move up one line scrolling if necessary. ; This has no alternative use in input mode. ;; ED-UP L1059: BIT 5,(IY+037h) ; test FLAGX - input mode ? RET NZ ; return if not in editor - to ED-LOOP. LD HL,(05C49h) ; get current line from E_PPC CALL L196E ; routine LINE-ADDR gets address EX DE,HL ; and previous in DE CALL L1695 ; routine LINE-NO gets prev line number LD HL,05C4Ah ; set HL to E_PPC_hi as next routine stores ; top first. CALL L191C ; routine LN-STORE loads DE value to HL ; high byte first - E_PPC_lo takes E ; this branch is also taken from ed-down. ;; ED-LIST L106E: CALL L1795 ; routine AUTO-LIST lists to upper screen ; including adjusted current line. LD A,00h ; select lower screen again JP L1601 ; exit via CHAN-OPEN to ED-LOOP ; -------------------------------- ; Use of symbol and graphics codes ; -------------------------------- ; These will not be encountered with the keyboard but would be handled ; otherwise as follows. ; As noted earlier, Vickers says there should have been an entry in ; the KEYS table for chr$ 6 which also pointed here. ; If, for simplicity, two Spectrums were both using #15 as a bi-directional ; channel connected to each other:- ; then when the other Spectrum has said PRINT #15; x, y ; input #15; i ; j would treat the comma control as a newline and the ; control would skip to input j. ; You can get round the missing chr$ 6 handler by sending multiple print ; items separated by a newline '. ; chr014h would have the same functionality. ; This is chr$ 14. ;; ED-SYMBOL L1076: BIT 7,(IY+037h) ; test FLAGX - is this INPUT LINE ? JR Z,L1024 ; back to ED-ENTER if not to treat as if ; enter had been pressed. ; else continue and add code to buffer. ; Next is chr$ 15 ; Note that ADD-CHAR precedes the table so we can't offset to it directly. ;; ED-GRAPH L107C: JP L0F81 ; jump back to ADD-CHAR ; -------------------- ; Editor error routine ; -------------------- ; If an error occurs while editing, or inputting, then ERR_SP ; points to the stack location holding address ED_ERROR. ;; ED-ERROR L107F: BIT 4,(IY+030h) ; test FLAGS2 - is K channel in use ? JR Z,L1026 ; back to ED-END if not. ; but as long as we're editing lines or inputting from the keyboard, then ; we've run out of memory so give a short rasp. LD (IY+00h),0FFh ; reset ERR_NR to 'OK'. LD D,00h ; prepare for beeper. LD E,(IY-002h) ; use RASP value. LD HL,01A90h ; set the pitch - or tone period. CALL L03B5 ; routine BEEPER emits a warning rasp. JP L0F30 ; to ED-AGAIN to re-stack address of ; this routine and make ERR_SP point to it. ; --------------------- ; Clear edit/work space ; --------------------- ; The editing area or workspace is cleared depending on context. ; This is called from ED-EDIT to clear workspace if edit key is ; used during input, to clear editing area if no program exists ; and to clear editing area prior to copying the edit line to it. ; It is also used by the error routine to clear the respective ; area depending on FLAGX. ;; CLEAR-SP L1097: PUSH HL ; preserve HL CALL L1190 ; routine SET-HL ; if in edit HL = WORKSP-1, DE = E_LINE ; if in input HL = STKBOT, DE = WORKSP DEC HL ; adjust CALL L19E5 ; routine RECLAIM-1 reclaims space LD (05C5Bh),HL ; set K_CUR to start of empty area LD (IY+007h),00h ; set MODE to 'KLC' POP HL ; restore HL. RET ; return. ; ---------------------------- ; THE 'KEYBOARD INPUT' ROUTINE ; ---------------------------- ; This is the service routine for the input stream of the keyboard channel 'K'. ;; KEY-INPUT L10A8: BIT 3,(IY+002h) ; test TV_FLAG - has a key been pressed in ; editor ? CALL NZ,L111D ; routine ED-COPY, if so, to reprint the lower ; screen at every keystroke/mode change. AND A ; clear carry flag - required exit condition. BIT 5,(IY+001h) ; test FLAGS - has a new key been pressed ? RET Z ; return if not. >> LD A,(05C08h) ; system variable LASTK will hold last key - ; from the interrupt routine. RES 5,(IY+001h) ; update FLAGS - reset the new key flag. PUSH AF ; save the input character. BIT 5,(IY+002h) ; test TV_FLAG - clear lower screen ? CALL NZ,L0D6E ; routine CLS-LOWER if so. POP AF ; restore the character code. CP 020h ; if space or higher then JR NC,L111B ; forward to KEY-DONE2 and return with carry ; set to signal key-found. CP 010h ; with 16d INK and higher skip JR NC,L10FA ; forward to KEY-CONTR. CP 006h ; for 6 - 15d JR NC,L10DB ; skip forward to KEY-M-CL to handle Modes ; and CapsLock. ; that only leaves 0-5, the flash bright inverse switches. LD B,A ; save character in B AND 001h ; isolate the embedded parameter (0/1). LD C,A ; and store in C LD A,B ; re-fetch copy (0-5) RRA ; halve it 0, 1 or 2. ADD A,012h ; add 18d gives 'flash', 'bright' ; and 'inverse'. JR L1105 ; forward to KEY-DATA with the ; parameter (0/1) in C. ; --- ; Now separate capslock 06 from modes 7-15. ;; KEY-M-CL L10DB: JR NZ,L10E6 ; forward to KEY-MODE if not 06 (capslock) LD HL,05C6Ah ; point to FLAGS2 LD A,008h ; value 00001000 XOR (HL) ; toggle BIT 3 of FLAGS2 the capslock bit LD (HL),A ; and store result in FLAGS2 again. JR L10F4 ; forward to KEY-FLAG to signal no-key. ; --- ;; KEY-MODE L10E6: CP 00Eh ; compare with chr 14d RET C ; return with carry set "key found" for ; codes 7 - 13d leaving 14d and 15d ; which are converted to mode codes. SUB 00Dh ; subtract 13d leaving 1 and 2 ; 1 is 'E' mode, 2 is 'G' mode. LD HL,05C41h ; address the MODE system variable. CP (HL) ; compare with existing value before LD (HL),A ; inserting the new value. JR NZ,L10F4 ; forward to KEY-FLAG if it has changed. LD (HL),00h ; else make MODE zero - KLC mode ; Note. while in Extended/Graphics mode, ; the Extended Mode/Graphics key is pressed ; again to get out. ;; KEY-FLAG L10F4: SET 3,(IY+002h) ; update TV_FLAG - show key state has changed CP A ; clear carry and reset zero flags - ; no actual key returned. RET ; make the return. ; --- ; now deal with colour controls - 16-23 ink, 24-31 paper ;; KEY-CONTR L10FA: LD B,A ; make a copy of character. AND 007h ; mask to leave bits 0-7 LD C,A ; and store in C. LD A,010h ; initialize to 16d - INK. BIT 3,B ; was it paper ? JR NZ,L1105 ; forward to KEY-DATA with INK 16d and ; colour in C. INC A ; else change from INK to PAPER (17d) if so. ;; KEY-DATA L1105: LD (IY-02Dh),C ; put the colour (0-7)/state(0/1) in KDATA LD DE,L110D ; address: KEY-NEXT will be next input stream JR L1113 ; forward to KEY-CHAN to change it ... ; --- ; ... so that INPUT_AD directs control to here at next call to WAIT-KEY ;; KEY-NEXT L110D: LD A,(05C0Dh) ; pick up the parameter stored in KDATA. LD DE,L10A8 ; address: KEY-INPUT will be next input stream ; continue to restore default channel and ; make a return with the control code. ;; KEY-CHAN L1113: LD HL,(05C4Fh) ; address start of CHANNELS area using CHANS ; system variable. ; Note. One might have expected CURCHL to ; have been used. INC HL ; step over the INC HL ; output address LD (HL),E ; and update the input INC HL ; routine address for LD (HL),D ; the next call to WAIT-KEY. ;; KEY-DONE2 L111B: SCF ; set carry flag to show a key has been found RET ; and return. ; -------------------- ; Lower screen copying ; -------------------- ; This subroutine is called whenever the line in the editing area or ; input workspace is required to be printed to the lower screen. ; It is by calling this routine after any change that the cursor, for ; instance, appears to move to the left. ; Remember the edit line will contain characters and tokens ; e.g. "1000 LET a=1" is 8 characters. ;; ED-COPY L111D: CALL L0D4D ; routine TEMPS sets temporary attributes. RES 3,(IY+002h) ; update TV_FLAG - signal no change in mode RES 5,(IY+002h) ; update TV_FLAG - signal don't clear lower ; screen. LD HL,(05C8Ah) ; fetch SPOSNL PUSH HL ; and save on stack. LD HL,(05C3Dh) ; fetch ERR_SP PUSH HL ; and save also LD HL,L1167 ; address: ED-FULL PUSH HL ; is pushed as the error routine LD (05C3Dh),SP ; and ERR_SP made to point to it. LD HL,(05C82h) ; fetch ECHO_E PUSH HL ; and push also SCF ; set carry flag to control SET-DE CALL L1195 ; call routine SET-DE ; if in input DE = WORKSP ; if in edit DE = E_LINE EX DE,HL ; start address to HL CALL L187D ; routine OUT-LINE2 outputs entire line up to ; carriage return including initial ; characterized line number when present. EX DE,HL ; transfer new address to DE CALL L18E1 ; routine OUT-CURS considers a ; terminating cursor. LD HL,(05C8Ah) ; fetch updated SPOSNL EX (SP),HL ; exchange with ECHO_E on stack EX DE,HL ; transfer ECHO_E to DE CALL L0D4D ; routine TEMPS to re-set attributes ; if altered. ; the lower screen was not cleared, at the outset, so if deleting then old ; text from a previous print may follow this line and requires blanking. ;; ED-BLANK L1150: LD A,(05C8Bh) ; fetch SPOSNL_hi is current line SUB D ; compare with old JR C,L117C ; forward to ED-C-DONE if no blanking JR NZ,L115E ; forward to ED-SPACES if line has changed LD A,E ; old column to A SUB (IY+050h) ; subtract new in SPOSNL_lo JR NC,L117C ; forward to ED-C-DONE if no backfilling. ;; ED-SPACES L115E: LD A,020h ; prepare a space. PUSH DE ; save old line/column. CALL L09F4 ; routine PRINT-OUT prints a space over ; any text from previous print. ; Note. Since the blanking only occurs when ; using 009F4h to print to the lower screen, ; there is no need to vector via a RST 10 ; and we can use this alternate set. POP DE ; restore the old line column. JR L1150 ; back to ED-BLANK until all old text blanked. ; ------------------------------- ; THE 'EDITOR-FULL' ERROR ROUTINE ; ------------------------------- ; This is the error routine addressed by ERR_SP. This is not for the out of ; memory situation as we're just printing. The pitch and duration are exactly ; the same as used by ED-ERROR from which this has been augmented. The ; situation is that the lower screen is full and a rasp is given to suggest ; that this is perhaps not the best idea you've had that day. ;; ED-FULL L1167: LD D,00h ; prepare to moan. LD E,(IY-002h) ; fetch RASP value. LD HL,01A90h ; set pitch or tone period. CALL L03B5 ; routine BEEPER. LD (IY+00h),0FFh ; clear ERR_NR. LD DE,(05C8Ah) ; fetch SPOSNL. JR L117E ; forward to ED-C-END ; ------- ; the exit point from line printing continues here. ;; ED-C-DONE L117C: POP DE ; fetch new line/column. POP HL ; fetch the error address. ; the error path rejoins here. ;; ED-C-END L117E: POP HL ; restore the old value of ERR_SP. LD (05C3Dh),HL ; update the system variable ERR_SP POP BC ; old value of SPOSN_L PUSH DE ; save new value CALL L0DD9 ; routine CL-SET and PO-STORE ; update ECHO_E and SPOSN_L from BC POP HL ; restore new value LD (05C82h),HL ; and overwrite ECHO_E LD (IY+026h),00h ; make error pointer X_PTR_hi out of bounds RET ; return ; ----------------------------------------------- ; Point to first and last locations of work space ; ----------------------------------------------- ; These two nested routines ensure that the appropriate pointers are ; selected for the editing area or workspace. The routines that call ; these routines are designed to work on either area. ; this routine is called once ;; SET-HL L1190: LD HL,(05C61h) ; fetch WORKSP to HL. DEC HL ; point to last location of editing area. AND A ; clear carry to limit exit points to first ; or last. ; this routine is called with carry set and exits at a conditional return. ;; SET-DE L1195: LD DE,(05C59h) ; fetch E_LINE to DE BIT 5,(IY+037h) ; test FLAGX - Input Mode ? RET Z ; return now if in editing mode LD DE,(05C61h) ; fetch WORKSP to DE RET C ; return if carry set ( entry = set-de) LD HL,(05C63h) ; fetch STKBOT to HL as well RET ; and return (entry = set-hl (in input)) ; ----------------------------------- ; THE 'REMOVE FLOATING POINT' ROUTINE ; ----------------------------------- ; When a BASIC LINE or the INPUT BUFFER is parsed any numbers will have ; an invisible chr 14d inserted after them and the 5-byte integer or ; floating point form inserted after that. Similar invisible value holders ; are also created after the numeric and string variables in a DEF FN list. ; This routine removes these 'compiled' numbers from the edit line or ; input workspace. ;; REMOVE-FP L11A7: LD A,(HL) ; fetch character CP 00Eh ; is it the CHR$ 14 number marker ? LD BC,006h ; prepare to strip six bytes CALL Z,L19E8 ; routine RECLAIM-2 reclaims bytes if CHR$ 14. LD A,(HL) ; reload next (or same) character INC HL ; and advance address CP 00Dh ; end of line or input buffer ? JR NZ,L11A7 ; back to REMOVE-FP until entire line done. RET ; return. ; ********************************* ; ** Part 6. EXECUTIVE ROUTINES ** ; ********************************* ; The memory. ; ; +---------+-----------+------------+--------------+-------------+-- ; | BASIC | Display | Attributes | ZX Printer | System | ; | ROM | File | File | Buffer | Variables | ; +---------+-----------+------------+--------------+-------------+-- ; ^ ^ ^ ^ ^ ^ ; 000h 04000h 05800h 05B00h 05C00h 05CB6h = CHANS ; ; ; --+----------+---+---------+-----------+---+------------+--+---+-- ; | Channel |080h| BASIC | Variables |080h| Edit Line |NL|080h| ; | Info | | Program | Area | | or Command | | | ; --+----------+---+---------+-----------+---+------------+--+---+-- ; ^ ^ ^ ^ ^ ; CHANS PROG VARS E_LINE WORKSP ; ; ; ---5--> <---2--- <--3--- ; --+-------+--+------------+-------+-------+---------+-------+-+---+------+ ; | INPUT |NL| Temporary | Calc. | Spare | Machine | GOSUB |?|03Eh| UDGs | ; | data | | Work Space | Stack | | Stack | Stack | | | | ; --+-------+--+------------+-------+-------+---------+-------+-+---+------+ ; ^ ^ ^ ^ ^ ^ ^ ; WORKSP STKBOT STKEND sp RAMTOP UDG P_RAMT ; ; ----------------- ; THE 'NEW' COMMAND ; ----------------- ; The NEW command is about to set all RAM below RAMTOP to zero and then ; re-initialize the system. All RAM above RAMTOP should, and will be, ; preserved. ; There is nowhere to store values in RAM or on the stack which becomes ; inoperable. Similarly PUSH and CALL instructions cannot be used to store ; values or section common code. The alternate register set is the only place ; available to store 3 persistent 16-bit system variables. ;; NEW L11B7: DI ; Disable Interrupts - machine stack will be ; cleared. LD A,0FFh ; Flag coming from NEW. LD DE,(05CB2h) ; Fetch RAMTOP as top value. EXX ; Switch in alternate set. LD BC,(05CB4h) ; Fetch P-RAMT differs on 16K/48K machines. LD DE,(05C38h) ; Fetch RASP/PIP. LD HL,(05C7Bh) ; Fetch UDG differs on 16K/48K machines. EXX ; Switch back to main set and continue into... ; ---------------------- ; THE 'START-NEW' BRANCH ; ---------------------- ; This branch is taken from above and from RST 00h. ; The common code tests RAM and sets it to zero re-initializing all the ; non-zero system variables and channel information. The A register flags ; if coming from START or NEW. ;; START-NEW L11CB: LD B,A ; Save the flag to control later branching. LD A,007h ; Select a white border OUT (0FEh),A ; and set it now by writing to a port. LD A,03Fh ; Load the accumulator with last page in ROM. LD I,A ; Set the I register - this remains constant ; and can't be in the range 040h - 07Fh as 'snow' ; appears on the screen. call sio_init jp L11DA ; NOP ; These seem unnecessary. ; NOP ; ; NOP ; ; NOP ; ; NOP ; ; NOP ; ; ----------------------- ; THE 'RAM CHECK' SECTION ; ----------------------- ; Typically, a Spectrum will have 16K or 48K of RAM and this code will test ; it all till it finds an unpopulated location or, less likely, a faulty ; location. Usually it stops when it reaches the top 0FFFFh, or in the case ; of NEW the supplied top value. The entire screen turns black with ; sometimes red stripes on black paper just visible. .org 011DAh ;; ram-check L11DA: LD H,D ; Transfer the top value to the HL register LD L,E ; pair. ;; RAM-FILL L11DC: LD (HL),002h ; Load memory with 002h - red ink on black paper. DEC HL ; Decrement memory address. CP H ; Have we reached ROM - 03Fh ? JR NZ,L11DC ; Back to RAM-FILL if not. ;; RAM-READ L11E2: AND A ; Clear carry - prepare to subtract. SBC HL,DE ; subtract and add back setting ADD HL,DE ; carry when back at start. INC HL ; and increment for next iteration. JR NC,L11EF ; forward to RAM-DONE if we've got back to ; starting point with no errors. DEC (HL) ; decrement to 1. JR Z,L11EF ; forward to RAM-DONE if faulty. DEC (HL) ; decrement to zero. JR Z,L11E2 ; back to RAM-READ if zero flag was set. ;; RAM-DONE L11EF: DEC HL ; step back to last valid location. EXX ; regardless of state, set up possibly ; stored system variables in case from NEW. LD (05CB4h),BC ; insert P-RAMT. LD (05C38h),DE ; insert RASP/PIP. LD (05C7Bh),HL ; insert UDG. EXX ; switch in main set. INC B ; now test if we arrived here from NEW. JR Z,L1219 ; forward to RAM-SET if we did. ; This section applies to START only. LD (05CB4h),HL ; set P-RAMT to the highest working RAM ; address. LD DE,03EAFh ; address of last byte of 'U' bitmap in ROM. LD BC,0A8h ; there are 21 user defined graphics. EX DE,HL ; switch pointers and make the UDGs a LDDR ; copy of the standard characters A - U. EX DE,HL ; switch the pointer to HL. INC HL ; update to start of 'A' in RAM. LD (05C7Bh),HL ; make UDG system variable address the first ; bitmap. DEC HL ; point at RAMTOP again. LD BC,040h ; set the values of LD (05C38h),BC ; the PIP and RASP system variables. ; The NEW command path rejoins here. ;; RAM-SET L1219: LD (05CB2h),HL ; set system variable RAMTOP to HL. ; ; Note. this entry point is a disabled Warm Restart that was almost certainly ; once pointed to by the System Variable NMIADD. It would be essential that ; any NMI Handler would perform the tasks from here to the EI instruction ; below. ;; NMI_VECT L121C: LD HL,03C00h ; a strange place to set the pointer to the LD (05C36h),HL ; character set, CHARS - as no printing yet. LD HL,(05CB2h) ; fetch RAMTOP to HL again as we've lost it. LD (HL),03Eh ; top of user ram holds GOSUB end marker ; an impossible line number - see RETURN. ; no significance in the number 03Eh. It has ; been traditional since the ZX80. DEC HL ; followed by empty byte (not important). LD SP,HL ; set up the machine stack pointer. DEC HL ; DEC HL ; LD (05C3Dh),HL ; ERR_SP is where the error pointer is ; at moment empty - will take address MAIN-4 ; at the call preceding that address, ; although interrupts and calls will make use ; of this location in meantime. IM 1 ; select interrupt mode 1. LD IY,05C3Ah ; set IY to ERR_NR. IY can reach all standard ; system variables but shadow ROM system ; variables will be mostly out of range. EI ; enable interrupts now that we have a stack. ; If, as suggested above, the NMI service routine pointed to this section of ; code then a decision would have to be made at this point to jump forward, ; in a Warm Restart scenario, to produce a report code, leaving any program ; intact. LD HL,05CB6h ; The address of the channels - initially ; following system variables. LD (05C4Fh),HL ; Set the CHANS system variable. LD DE,L15AF ; Address: init-chan in ROM. LD BC,015h ; There are 21 bytes of initial data in ROM. EX DE,HL ; swap the pointers. LDIR ; Copy the bytes to RAM. EX DE,HL ; Swap pointers. HL points to program area. DEC HL ; Decrement address. LD (05C57h),HL ; Set DATADD to location before program area. INC HL ; Increment again. LD (05C53h),HL ; Set PROG the location where BASIC starts. LD (05C4Bh),HL ; Set VARS to same location with a LD (HL),080h ; variables end-marker. INC HL ; Advance address. LD (05C59h),HL ; Set E_LINE, where the edit line ; will be created. ; Note. it is not strictly necessary to ; execute the next fifteen bytes of code ; as this will be done by the call to SET-MIN. ; -- LD (HL),00Dh ; initially just has a carriage return INC HL ; followed by LD (HL),080h ; an end-marker. INC HL ; address the next location. LD (05C61h),HL ; set WORKSP - empty workspace. LD (05C63h),HL ; set STKBOT - bottom of the empty stack. LD (05C65h),HL ; set STKEND to the end of the empty stack. ; -- LD A,038h ; the colour system is set to white paper, ; black ink, no flash or bright. LD (05C8Dh),A ; set ATTR_P permanent colour attributes. LD (05C8Fh),A ; set ATTR_T temporary colour attributes. LD (05C48h),A ; set BORDCR the border colour/lower screen ; attributes. LD HL,00523h ; The keyboard repeat and delay values are LD (05C09h),HL ; loaded to REPDEL and REPPER. DEC (IY-03Ah) ; set KSTATE-0 to 0FFh - keyboard map available. DEC (IY-036h) ; set KSTATE-4 to 0FFh - keyboard map available. LD HL,L15C6 ; set source to ROM Address: init-strm LD DE,05C10h ; set destination to system variable STRMS-FD LD BC,00Eh ; copy the 14 bytes of initial 7 streams data LDIR ; from ROM to RAM. SET 1,(IY+001h) ; update FLAGS - signal printer in use. CALL L0EDF ; call routine CLEAR-PRB to initialize system ; variables associated with printer. ; The buffer is clear. LD (IY+031h),002h ; set DF_SZ the lower screen display size to ; two lines CALL L0D6B ; call routine CLS to set up system ; variables associated with screen and clear ; the screen and set attributes. XOR A ; clear accumulator so that we can address LD DE,L1539 - 1 ; the message table directly. CALL L0C0A ; routine PO-MSG puts ; ' © 1982 Sinclair Research Ltd' ; at bottom of display. SET 5,(IY+002h) ; update TV_FLAG - signal lower screen will ; require clearing. JR L12A9 ; forward to MAIN-1 ; ------------------------- ; THE 'MAIN EXECUTION LOOP' ; ------------------------- ; ; ;; MAIN-EXEC L12A2: LD (IY+031h),002h ; set DF_SZ lower screen display file size to ; two lines. CALL L1795 ; routine AUTO-LIST ;; MAIN-1 L12A9: CALL L16B0 ; routine SET-MIN clears work areas. ;; MAIN-2 L12AC: LD A,00h ; select channel 'K' the keyboard CALL L1601 ; routine CHAN-OPEN opens it CALL L0F2C ; routine EDITOR is called. ; Note the above routine is where the Spectrum ; waits for user-interaction. Perhaps the ; most common input at this stage ; is LOAD "". CALL L1B17 ; routine LINE-SCAN scans the input. BIT 7,(IY+00h) ; test ERR_NR - will be 0FFh if syntax is OK. JR NZ,L12CF ; forward, if correct, to MAIN-3. ; BIT 4,(IY+030h) ; test FLAGS2 - K channel in use ? JR Z,L1303 ; forward to MAIN-4 if not. ; LD HL,(05C59h) ; an editing error so address E_LINE. CALL L11A7 ; routine REMOVE-FP removes the hidden ; floating-point forms. LD (IY+00h),0FFh ; system variable ERR_NR is reset to 'OK'. JR L12AC ; back to MAIN-2 to allow user to correct. ; --- ; the branch was here if syntax has passed test. ;; MAIN-3 L12CF: LD HL,(05C59h) ; fetch the edit line address from E_LINE. LD (05C5Dh),HL ; system variable CH_ADD is set to first ; character of edit line. ; Note. the above two instructions are a little ; inadequate. ; They are repeated with a subtle difference ; at the start of the next subroutine and are ; therefore not required above. CALL L19FB ; routine E-LINE-NO will fetch any line ; number to BC if this is a program line. LD A,B ; test if the number of OR C ; the line is non-zero. JP NZ,L155D ; jump forward to MAIN-ADD if so to add the ; line to the BASIC program. ; Has the user just pressed the ENTER key ? RST 18H ; GET-CHAR gets character addressed by CH_ADD. CP 00Dh ; is it a carriage return ? JR Z,L12A2 ; back to MAIN-EXEC if so for an automatic ; listing. ; this must be a direct command. BIT 0,(IY+030h) ; test FLAGS2 - clear the main screen ? CALL NZ,L0DAF ; routine CL-ALL, if so, e.g. after listing. CALL L0D6E ; routine CLS-LOWER anyway. LD A,019h ; compute scroll count as 25 minus SUB (IY+04Fh) ; value of S_POSN_hi. LD (05C8Ch),A ; update SCR_CT system variable. SET 7,(IY+001h) ; update FLAGS - signal running program. LD (IY+00h),0FFh ; set ERR_NR to 'OK'. LD (IY+00Ah),001h ; set NSPPC to one for first statement. CALL L1B8A ; call routine LINE-RUN to run the line. ; sysvar ERR_SP therefore addresses MAIN-4 ; Examples of direct commands are RUN, CLS, LOAD "", PRINT USR 40000, ; LPRINT "A"; etc.. ; If a user written machine-code program disables interrupts then it ; must enable them to pass the next step. We also jumped to here if the ; keyboard was not being used. ;; MAIN-4 L1303: HALT ; wait for interrupt the only routine that can ; set bit 5 of FLAGS. RES 5,(IY+001h) ; update bit 5 of FLAGS - signal no new key. BIT 1,(IY+030h) ; test FLAGS2 - is printer buffer clear ? CALL NZ,L0ECD ; call routine COPY-BUFF if not. ; Note. the programmer has neglected ; to set bit 1 of FLAGS first. LD A,(05C3Ah) ; fetch ERR_NR INC A ; increment to give true code. ; Now deal with a runtime error as opposed to an editing error. ; However if the error code is now zero then the OK message will be printed. ;; MAIN-G L1313: PUSH AF ; save the error number. LD HL,000h ; prepare to clear some system variables. LD (IY+037h),H ; clear all the bits of FLAGX. LD (IY+026h),H ; blank X_PTR_hi to suppress error marker. LD (05C0Bh),HL ; blank DEFADD to signal that no defined ; function is currently being evaluated. LD HL,001h ; explicit - inc hl would do. LD (05C16h),HL ; ensure STRMS-00 is keyboard. CALL L16B0 ; routine SET-MIN clears workspace etc. RES 5,(IY+037h) ; update FLAGX - signal in EDIT not INPUT mode. ; Note. all the bits were reset earlier. CALL L0D6E ; call routine CLS-LOWER. SET 5,(IY+002h) ; update TV_FLAG - signal lower screen ; requires clearing. POP AF ; bring back the true error number LD B,A ; and make a copy in B. CP 00Ah ; is it a print-ready digit ? JR C,L133C ; forward to MAIN-5 if so. ADD A,007h ; add ASCII offset to letters. ;; MAIN-5 L133C: CALL L15EF ; call routine OUT-CODE to print the code. LD A,020h ; followed by a space. RST 10H ; PRINT-A LD A,B ; fetch stored report code. LD DE,L1391 ; address: rpt-mesgs. CALL L0C0A ; call routine PO-MSG to print the message. X1349: XOR A ; clear accumulator to directly LD DE,L1537 - 1 ; address the comma and space message. CALL L0C0A ; routine PO-MSG prints ', ' although it would ; be more succinct to use RST 010h. LD BC,(05C45h) ; fetch PPC the current line number. CALL L1A1B ; routine OUT-NUM-1 will print that LD A,03Ah ; then a ':' character. RST 10H ; PRINT-A LD C,(IY+00Dh) ; then SUBPPC for statement LD B,00h ; limited to 127 CALL L1A1B ; routine OUT-NUM-1 prints BC. CALL L1097 ; routine CLEAR-SP clears editing area which ; probably contained 'RUN'. LD A,(05C3Ah) ; fetch ERR_NR again INC A ; test for no error originally 0FFh. JR Z,L1386 ; forward to MAIN-9 if no error. CP 009h ; is code Report 9 STOP ? JR Z,L1373 ; forward to MAIN-6 if so CP 015h ; is code Report L Break ? JR NZ,L1376 ; forward to MAIN-7 if not ; Stop or Break was encountered so consider CONTINUE. ;; MAIN-6 L1373: INC (IY+00Dh) ; increment SUBPPC to next statement. ;; MAIN-7 L1376: LD BC,003h ; prepare to copy 3 system variables to LD DE,05C70h ; address OSPPC - statement for CONTINUE. ; also updating OLDPPC line number below. LD HL,05C44h ; set source top to NSPPC next statement. BIT 7,(HL) ; did BREAK occur before the jump ? ; e.g. between GO TO and next statement. JR Z,L1384 ; skip forward to MAIN-8, if not, as set-up ; is correct. ADD HL,BC ; set source to SUBPPC number of current ; statement/line which will be repeated. ;; MAIN-8 L1384: LDDR ; copy PPC to OLDPPC and SUBPPC to OSPCC ; or NSPPC to OLDPPC and NEWPPC to OSPCC ;; MAIN-9 L1386: LD (IY+00Ah),0FFh ; update NSPPC - signal 'no jump'. RES 3,(IY+001h) ; update FLAGS - signal use 'K' mode for ; the first character in the editor and JP L12AC ; jump back to MAIN-2. ; ---------------------- ; Canned report messages ; ---------------------- ; The Error reports with the last byte inverted. The first entry ; is a dummy entry. The last, which begins with 07Fh, the Spectrum ; character for copyright symbol, is placed here for convenience ; as is the preceding comma and space. ; The report line must accommodate a 4-digit line number and a 3-digit ; statement number which limits the length of the message text to twenty ; characters. ; e.g. "B Integer out of range, 1000:127" ;; rpt-mesgs L1391: .DEFB 080h .DEFB 'O','K'+080h ; 0 .DEFB "NEXT without FO" .DEFB 'R'+080h ; 1 .DEFB "Variable not" .DEFB " foun" .DEFB 'd'+080h ; 2 .DEFB "Subscript wron" .DEFB 'g'+080h ; 3 .DEFB "Out of memor" .DEFB 'y'+080h ; 4 .DEFB "Out of scree" .DEFB 'n'+080h ; 5 .DEFB "Number too bi" .DEFB 'g'+080h ; 6 .DEFB "RETURN without" .DEFB " GOSU" .DEFB 'B'+080h ; 7 .DEFB "End of fil" .DEFB 'e'+080h ; 8 .DEFB "STOP statemen" .DEFB 't'+080h ; 9 .DEFB "Invalid argumen" .DEFB 't'+080h ; A .DEFB "Integer out of " .DEFB "rang" .DEFB 'e'+080h ; B .DEFB "Nonsense in BASI" .DEFB 'C'+080h ; C .DEFB "BREAK - CONT " .DEFB "repeat" .DEFB 's'+080h ; D .DEFB "Out of DAT" .DEFB 'A'+080h ; E .DEFB "Invalid file nam" .DEFB 'e'+080h ; F .DEFB "No room for lin" .DEFB 'e'+080h ; G .DEFB "STOP in INPU" .DEFB 'T'+080h ; H .DEFB "FOR without NEX" .DEFB 'T'+080h ; I .DEFB "Invalid I/O " .DEFB "devic" .DEFB 'e'+080h ; J .DEFB "Invalid colou" .DEFB 'r'+080h ; K .DEFB "BREAK into " .DEFB "progra" .DEFB 'm'+080h ; L .DEFB "RAMTOP no goo" .DEFB 'd'+080h ; M .DEFB "Statement los" .DEFB 't'+080h ; N .DEFB "Invalid strea" .DEFB 'm'+080h ; O .DEFB "FN without DE" .DEFB 'F'+080h ; P .DEFB "Parameter erro" .DEFB 'r'+080h ; Q .DEFB "Tape loading " .DEFB "erro" .DEFB 'r'+080h ; R ;; comma-sp L1537: .DEFB 02Ch,' '+080h ; ", " used in report line. ;; copyright L1539: .DEFB 07Fh ; copyright .DEFB " 1982 Sinclair " .DEFB "Research Lt" .DEFB 'd'+080h ; ------------- ; REPORT-G ; ------------- ; Note ERR_SP points here during line entry which allows the ; normal 'Out of Memory' report to be augmented to the more ; precise 'No Room for line' report. ;; REPORT-G ; No Room for line L1555: LD A,010h ; i.e. 'G' -030h -007h LD BC,000h ; this seems unnecessary. JP L1313 ; jump back to MAIN-G ; ----------------------------- ; Handle addition of BASIC line ; ----------------------------- ; Note this is not a subroutine but a branch of the main execution loop. ; System variable ERR_SP still points to editing error handler. ; A new line is added to the BASIC program at the appropriate place. ; An existing line with same number is deleted first. ; Entering an existing line number deletes that line. ; Entering a non-existent line allows the subsequent line to be edited next. ;; MAIN-ADD L155D: LD (05C49h),BC ; set E_PPC to extracted line number. LD HL,(05C5Dh) ; fetch CH_ADD - points to location after the ; initial digits (set in E_LINE_NO). EX DE,HL ; save start of BASIC in DE. LD HL,L1555 ; Address: REPORT-G PUSH HL ; is pushed on stack and addressed by ERR_SP. ; the only error that can occur is ; 'Out of memory'. LD HL,(05C61h) ; fetch WORKSP - end of line. SCF ; prepare for true subtraction. SBC HL,DE ; find length of BASIC and PUSH HL ; save it on stack. LD H,B ; transfer line number LD L,C ; to HL register. CALL L196E ; routine LINE-ADDR will see if ; a line with the same number exists. JR NZ,L157D ; forward if no existing line to MAIN-ADD1. CALL L19B8 ; routine NEXT-ONE finds the existing line. CALL L19E8 ; routine RECLAIM-2 reclaims it. ;; MAIN-ADD1 L157D: POP BC ; retrieve the length of the new line. LD A,C ; and test if carriage return only DEC A ; i.e. one byte long. OR B ; result would be zero. JR Z,L15AB ; forward to MAIN-ADD2 is so. PUSH BC ; save the length again. INC BC ; adjust for inclusion INC BC ; of line number (two bytes) INC BC ; and line length INC BC ; (two bytes). DEC HL ; HL points to location before the destination LD DE,(05C53h) ; fetch the address of PROG PUSH DE ; and save it on the stack CALL L1655 ; routine MAKE-ROOM creates BC spaces in ; program area and updates pointers. POP HL ; restore old program pointer. LD (05C53h),HL ; and put back in PROG as it may have been ; altered by the POINTERS routine. POP BC ; retrieve BASIC length PUSH BC ; and save again. INC DE ; points to end of new area. LD HL,(05C61h) ; set HL to WORKSP - location after edit line. DEC HL ; decrement to address end marker. DEC HL ; decrement to address carriage return. LDDR ; copy the BASIC line back to initial command. LD HL,(05C49h) ; fetch E_PPC - line number. EX DE,HL ; swap it to DE, HL points to last of ; four locations. POP BC ; retrieve length of line. LD (HL),B ; high byte last. DEC HL ; LD (HL),C ; then low byte of length. DEC HL ; LD (HL),E ; then low byte of line number. DEC HL ; LD (HL),D ; then high byte range $0 - 027h (1-9999). ;; MAIN-ADD2 L15AB: POP AF ; drop the address of Report G JP L12A2 ; and back to MAIN-EXEC producing a listing ; and to reset ERR_SP in EDITOR. ; --------------------------------- ; THE 'INITIAL CHANNEL' INFORMATION ; --------------------------------- ; This initial channel information is copied from ROM to RAM, during ; initialization. It's new location is after the system variables and is ; addressed by the system variable CHANS which means that it can slide up and ; down in memory. The table is never searched, by this ROM, and the last ; character, which could be anything other than a comma, provides a ; convenient resting place for DATADD. ;; init-chan L15AF: .DEFW L09F4 ; PRINT-OUT .DEFW L10A8 ; KEY-INPUT .DEFB 04Bh ; 'K' .DEFW L09F4 ; PRINT-OUT .DEFW L15C4 ; REPORT-J .DEFB 053h ; 'S' .DEFW L0F81 ; ADD-CHAR .DEFW L15C4 ; REPORT-J .DEFB 052h ; 'R' ;.DEFW L09F4 ; PRINT-OUT .DEFW printerOut ; !!!! KR znak do SIO .DEFW L15C4 ; REPORT-J .DEFB 050h ; 'P' .DEFB 080h ; End Marker ;; REPORT-J L15C4: RST 08H ; ERROR-1 .DEFB 012h ; Error Report: Invalid I/O device ; ------------------------- ; THE 'INITIAL STREAM' DATA ; ------------------------- ; This is the initial stream data for the seven streams 0FDh - 003h that is ; copied from ROM to the STRMS system variables area during initialization. ; There are reserved locations there for another 12 streams. Each location ; contains an offset to the second byte of a channel. The first byte of a ; channel can't be used as that would result in an offset of zero for some ; and zero is used to denote that a stream is closed. ;; init-strm L15C6: .DEFB 001h, 00h ; stream 0FDh offset to channel 'K' .DEFB 006h, 00h ; stream 0FEh offset to channel 'S' .DEFB 00Bh, 00h ; stream 0FFh offset to channel 'R' .DEFB 001h, 00h ; stream 00h offset to channel 'K' .DEFB 001h, 00h ; stream 001h offset to channel 'K' .DEFB 006h, 00h ; stream 002h offset to channel 'S' .DEFB 010h, 00h ; stream 003h offset to channel 'P' ; ------------------------------ ; THE 'INPUT CONTROL' SUBROUTINE ; ------------------------------ ; ;; WAIT-KEY L15D4: BIT 5,(IY+002h) ; test TV_FLAG - clear lower screen ? JR NZ,L15DE ; forward to WAIT-KEY1 if so. SET 3,(IY+002h) ; update TV_FLAG - signal reprint the edit ; line to the lower screen. ;; WAIT-KEY1 L15DE: CALL L15E6 ; routine INPUT-AD is called. RET C ; return with acceptable keys. JR Z,L15DE ; back to WAIT-KEY1 if no key is pressed ; or it has been handled within INPUT-AD. ; Note. When inputting from the keyboard all characters are returned with ; above conditions so this path is never taken. ;; REPORT-8 L15E4: RST 08H ; ERROR-1 .DEFB 007h ; Error Report: End of file ; --------------------------- ; THE 'INPUT ADDRESS' ROUTINE ; --------------------------- ; This routine fetches the address of the input stream from the current ; channel area using the system variable CURCHL. ;; INPUT-AD L15E6: EXX ; switch in alternate set. PUSH HL ; save HL register LD HL,(05C51h) ; fetch address of CURCHL - current channel. INC HL ; step over output routine INC HL ; to point to low byte of input routine. JR L15F7 ; forward to CALL-SUB. ; ------------------------- ; THE 'CODE OUTPUT' ROUTINE ; ------------------------- ; This routine is called on five occasions to print the ASCII equivalent of ; a value 0-9. ;; OUT-CODE L15EF: LD E,030h ; add 48 decimal to give the ASCII character ADD A,E ; '0' to '9' and continue into the main output ; routine. ; ------------------------- ; THE 'MAIN OUTPUT' ROUTINE ; ------------------------- ; PRINT-A-2 is a continuation of the RST 10 restart that prints any character. ; The routine prints to the current channel and the printing of control codes ; may alter that channel to divert subsequent RST 10 instructions to temporary ; routines. The normal channel is 009F4h. ;; PRINT-A-2 L15F2: EXX ; switch in alternate set PUSH HL ; save HL register LD HL,(05C51h) ; fetch CURCHL the current channel. ; input-ad rejoins here also. ;; CALL-SUB L15F7: LD E,(HL) ; put the low byte in E. INC HL ; advance address. LD D,(HL) ; put the high byte to D. EX DE,HL ; transfer the stream to HL. CALL L162C ; use routine CALL-JUMP. ; in effect CALL (HL). POP HL ; restore saved HL register. EXX ; switch back to the main set and RET ; return. ; -------------------------- ; THE 'OPEN CHANNEL' ROUTINE ; -------------------------- ; This subroutine is used by the ROM to open a channel 'K', 'S', 'R' or 'P'. ; This is either for its own use or in response to a user's request, for ; example, when '#' is encountered with output - PRINT, LIST etc. ; or with input - INPUT, INKEY$ etc. ; It is entered with a system stream 0FDh - 0FFh, or a user stream 00h - 00Fh ; in the accumulator. ;; CHAN-OPEN L1601: ADD A,A ; double the stream (0FFh will become 0FEh etc.) ADD A,016h ; add the offset to stream 0 from 05C00h LD L,A ; result to L LD H,05Ch ; now form the address in STRMS area. LD E,(HL) ; fetch low byte of CHANS offset INC HL ; address next LD D,(HL) ; fetch high byte of offset LD A,D ; test that the stream is open. OR E ; zero if closed. JR NZ,L1610 ; forward to CHAN-OP-1 if open. ;; REPORT-Oa L160E: RST 08H ; ERROR-1 .DEFB 017h ; Error Report: Invalid stream ; continue here if stream was open. Note that the offset is from CHANS ; to the second byte of the channel. ;; CHAN-OP-1 L1610: DEC DE ; reduce offset so it points to the channel. LD HL,(05C4Fh) ; fetch CHANS the location of the base of ; the channel information area ADD HL,DE ; and add the offset to address the channel. ; and continue to set flags. ; ----------------- ; Set channel flags ; ----------------- ; This subroutine is used from ED-EDIT, str$ and read-in to reset the ; current channel when it has been temporarily altered. ;; CHAN-FLAG L1615: LD (05C51h),HL ; set CURCHL system variable to the ; address in HL RES 4,(IY+030h) ; update FLAGS2 - signal K channel not in use. ; Note. provide a default for channel 'R'. INC HL ; advance past INC HL ; output routine. INC HL ; advance past INC HL ; input routine. LD C,(HL) ; pick up the letter. LD HL,L162D ; address: chn-cd-lu CALL L16DC ; routine INDEXER finds offset to a ; flag-setting routine. RET NC ; but if the letter wasn't found in the ; table just return now. - channel 'R'. LD D,00h ; prepare to add LD E,(HL) ; offset to E ADD HL,DE ; add offset to location of offset to form ; address of routine ;; CALL-JUMP L162C: JP (HL) ; jump to the routine ; Footnote. calling any location that holds JP (HL) is the equivalent to ; a pseudo Z80 instruction CALL (HL). The ROM uses the instruction above. ; -------------------------- ; Channel code look-up table ; -------------------------- ; This table is used by the routine above to find one of the three ; flag setting routines below it. ; A zero end-marker is required as channel 'R' is not present. ;; chn-cd-lu L162D: .DEFB 'K',006h ; L1634-$-1 ; offset 006h to CHAN-K .DEFB 'S',012h ; L1642-$-1 ; offset 012h to CHAN-S .DEFB 'P',01Bh ; L164D-$-1 ; offset 01Bh to CHAN-P .DEFB 00h ; end marker. ; -------------- ; Channel K flag ; -------------- ; routine to set flags for lower screen/keyboard channel. ;; CHAN-K L1634: SET 0,(IY+002h) ; update TV_FLAG - signal lower screen in use RES 5,(IY+001h) ; update FLAGS - signal no new key SET 4,(IY+030h) ; update FLAGS2 - signal K channel in use JR L1646 ; forward to CHAN-S-1 for indirect exit ; -------------- ; Channel S flag ; -------------- ; routine to set flags for upper screen channel. ;; CHAN-S L1642: RES 0,(IY+002h) ; TV_FLAG - signal main screen in use ;; CHAN-S-1 L1646: RES 1,(IY+001h) ; update FLAGS - signal printer not in use JP L0D4D ; jump back to TEMPS and exit via that ; routine after setting temporary attributes. ; -------------- ; Channel P flag ; -------------- ; This routine sets a flag so that subsequent print related commands ; print to printer or update the relevant system variables. ; This status remains in force until reset by the routine above. ;; CHAN-P L164D: SET 1,(IY+001h) ; update FLAGS - signal printer in use RET ; return ; -------------------------- ; THE 'ONE SPACE' SUBROUTINE ; -------------------------- ; This routine is called once only to create a single space ; in workspace by ADD-CHAR. ;; ONE-SPACE L1652: LD BC,001h ; create space for a single character. ; --------- ; Make Room ; --------- ; This entry point is used to create BC spaces in various areas such as ; program area, variables area, workspace etc.. ; The entire free RAM is available to each BASIC statement. ; On entry, HL addresses where the first location is to be created. ; Afterwards, HL will point to the location before this. ;; MAKE-ROOM L1655: PUSH HL ; save the address pointer. CALL L1F05 ; routine TEST-ROOM checks if room ; exists and generates an error if not. POP HL ; restore the address pointer. CALL L1664 ; routine POINTERS updates the ; dynamic memory location pointers. ; DE now holds the old value of STKEND. LD HL,(05C65h) ; fetch new STKEND the top destination. EX DE,HL ; HL now addresses the top of the area to ; be moved up - old STKEND. LDDR ; the program, variables, etc are moved up. RET ; return with new area ready to be populated. ; HL points to location before new area, ; and DE to last of new locations. ; ----------------------------------------------- ; Adjust pointers before making or reclaiming room ; ----------------------------------------------- ; This routine is called by MAKE-ROOM to adjust upwards and by RECLAIM to ; adjust downwards the pointers within dynamic memory. ; The fourteen pointers to dynamic memory, starting with VARS and ending ; with STKEND, are updated adding BC if they are higher than the position ; in HL. ; The system variables are in no particular order except that STKEND, the first ; free location after dynamic memory must be the last encountered. ;; POINTERS L1664: PUSH AF ; preserve accumulator. PUSH HL ; put pos pointer on stack. LD HL,05C4Bh ; address VARS the first of the LD A,00Eh ; fourteen variables to consider. ;; PTR-NEXT L166B: LD E,(HL) ; fetch the low byte of the system variable. INC HL ; advance address. LD D,(HL) ; fetch high byte of the system variable. EX (SP),HL ; swap pointer on stack with the variable ; pointer. AND A ; prepare to subtract. SBC HL,DE ; subtract variable address ADD HL,DE ; and add back EX (SP),HL ; swap pos with system variable pointer JR NC,L167F ; forward to PTR-DONE if var before pos PUSH DE ; save system variable address. EX DE,HL ; transfer to HL ADD HL,BC ; add the offset EX DE,HL ; back to DE LD (HL),D ; load high byte DEC HL ; move back LD (HL),E ; load low byte INC HL ; advance to high byte POP DE ; restore old system variable address. ;; PTR-DONE L167F: INC HL ; address next system variable. DEC A ; decrease counter. JR NZ,L166B ; back to PTR-NEXT if more. EX DE,HL ; transfer old value of STKEND to HL. ; Note. this has always been updated. POP DE ; pop the address of the position. POP AF ; pop preserved accumulator. AND A ; clear carry flag preparing to subtract. SBC HL,DE ; subtract position from old stkend LD B,H ; to give number of data bytes LD C,L ; to be moved. INC BC ; increment as we also copy byte at old STKEND. ADD HL,DE ; recompute old stkend. EX DE,HL ; transfer to DE. RET ; return. ; ------------------- ; Collect line number ; ------------------- ; This routine extracts a line number, at an address that has previously ; been found using LINE-ADDR, and it is entered at LINE-NO. If it encounters ; the program 'end-marker' then the previous line is used and if that ; should also be unacceptable then zero is used as it must be a direct ; command. The program end-marker is the variables end-marker 080h, or ; if variables exist, then the first character of any variable name. ;; LINE-ZERO L168F: .DEFB 00h, 00h ; dummy line number used for direct commands ;; LINE-NO-A L1691: EX DE,HL ; fetch the previous line to HL and set LD DE,L168F ; DE to LINE-ZERO should HL also fail. ; -> The Entry Point. ;; LINE-NO L1695: LD A,(HL) ; fetch the high byte - max 02Fh AND 0C0h ; mask off the invalid bits. JR NZ,L1691 ; to LINE-NO-A if an end-marker. LD D,(HL) ; reload the high byte. INC HL ; advance address. LD E,(HL) ; pick up the low byte. RET ; return from here. ; ------------------- ; Handle reserve room ; ------------------- ; This is a continuation of the restart BC-SPACES ;; RESERVE L169E: LD HL,(05C63h) ; STKBOT first location of calculator stack DEC HL ; make one less than new location CALL L1655 ; routine MAKE-ROOM creates the room. INC HL ; address the first new location INC HL ; advance to second POP BC ; restore old WORKSP LD (05C61h),BC ; system variable WORKSP was perhaps ; changed by POINTERS routine. POP BC ; restore count for return value. EX DE,HL ; switch. DE = location after first new space INC HL ; HL now location after new space RET ; return. ; --------------------------- ; Clear various editing areas ; --------------------------- ; This routine sets the editing area, workspace and calculator stack ; to their minimum configurations as at initialization and indeed this ; routine could have been relied on to perform that task. ; This routine uses HL only and returns with that register holding ; WORKSP/STKBOT/STKEND though no use is made of this. The routines also ; reset MEM to its usual place in the systems variable area should it ; have been relocated to a FOR-NEXT variable. The main entry point ; SET-MIN is called at the start of the MAIN-EXEC loop and prior to ; displaying an error. ;; SET-MIN L16B0: LD HL,(05C59h) ; fetch E_LINE LD (HL),00Dh ; insert carriage return LD (05C5Bh),HL ; make K_CUR keyboard cursor point there. INC HL ; next location LD (HL),080h ; holds end-marker 080h INC HL ; next location becomes LD (05C61h),HL ; start of WORKSP ; This entry point is used prior to input and prior to the execution, ; or parsing, of each statement. ;; SET-WORK L16BF: LD HL,(05C61h) ; fetch WORKSP value LD (05C63h),HL ; and place in STKBOT ; This entry point is used to move the stack back to its normal place ; after temporary relocation during line entry and also from ERROR-3 ;; SET-STK L16C5: LD HL,(05C63h) ; fetch STKBOT value LD (05C65h),HL ; and place in STKEND. PUSH HL ; perhaps an obsolete entry point. LD HL,05C92h ; normal location of MEM-0 LD (05C68h),HL ; is restored to system variable MEM. POP HL ; saved value not required. RET ; return. ; ------------------ ; Reclaim edit-line? ; ------------------ ; This seems to be legacy code from the ZX80/ZX81 as it is ; not used in this ROM. ; That task, in fact, is performed here by the dual-area routine CLEAR-SP. ; This routine is designed to deal with something that is known to be in the ; edit buffer and not workspace. ; On entry, HL must point to the end of the something to be deleted. ;; REC-EDIT L16D4: LD DE,(05C59h) ; fetch start of edit line from E_LINE. JP L19E5 ; jump forward to RECLAIM-1. ; -------------------------- ; The Table INDEXING routine ; -------------------------- ; This routine is used to search two-byte hash tables for a character ; held in C, returning the address of the following offset byte. ; if it is known that the character is in the table e.g. for priorities, ; then the table requires no zero end-marker. If this is not known at the ; outset then a zero end-marker is required and carry is set to signal ; success. ;; INDEXER-1 L16DB: INC HL ; address the next pair of values. ; -> The Entry Point. ;; INDEXER L16DC: LD A,(HL) ; fetch the first byte of pair AND A ; is it the end-marker ? RET Z ; return with carry reset if so. CP C ; is it the required character ? INC HL ; address next location. JR NZ,L16DB ; back to INDEXER-1 if no match. SCF ; else set the carry flag. RET ; return with carry set ; -------------------------------- ; The Channel and Streams Routines ; -------------------------------- ; A channel is an input/output route to a hardware device ; and is identified to the system by a single letter e.g. 'K' for ; the keyboard. A channel can have an input and output route ; associated with it in which case it is bi-directional like ; the keyboard. Others like the upper screen 'S' are output ; only and the input routine usually points to a report message. ; Channels 'K' and 'S' are system channels and it would be inappropriate ; to close the associated streams so a mechanism is provided to ; re-attach them. When the re-attachment is no longer required, then ; closing these streams resets them as at initialization. ; Early adverts said that the network and RS232 were in this ROM. ; Channels 'N' and 'B' are user channels and have been removed successfully ; if, as seems possible, they existed. ; Ironically the tape streamer is not accessed through streams and ; channels. ; Early demonstrations of the Spectrum showed a single microdrive being ; controlled by the main ROM. ; --------------------- ; THE 'CLOSE #' COMMAND ; --------------------- ; This command allows streams to be closed after use. ; Any temporary memory areas used by the stream would be reclaimed and ; finally flags set or reset if necessary. ;; CLOSE L16E5: CALL L171E ; routine STR-DATA fetches parameter ; from calculator stack and gets the ; existing STRMS data pointer address in HL ; and stream offset from CHANS in BC. ; Note. this offset could be zero if the ; stream is already closed. A check for this ; should occur now and an error should be ; generated, for example, ; Report S 'Stream status closed'. CALL L1701 ; routine CLOSE-2 would perform any actions ; peculiar to that stream without disturbing ; data pointer to STRMS entry in HL. LD BC,000h ; the stream is to be blanked. LD DE,0A3E2h ; the number of bytes from stream 4, 05C1Eh, ; to 01000h0 EX DE,HL ; transfer offset to HL, STRMS data pointer ; to DE. ADD HL,DE ; add the offset to the data pointer. JR C,L16FC ; forward to CLOSE-1 if a non-system stream. ; i.e. higher than 3. ; proceed with a negative result. LD BC,L15C6 + 14 ; prepare the address of the byte after ; the initial stream data in ROM. (015D4h) ADD HL,BC ; index into the data table with negative value. LD C,(HL) ; low byte to C INC HL ; address next. LD B,(HL) ; high byte to B. ; and for streams 0 - 3 just enter the initial data back into the STRMS entry ; streams 0 - 2 can't be closed as they are shared by the operating system. ; -> for streams 4 - 15 then blank the entry. ;; CLOSE-1 L16FC: EX DE,HL ; address of stream to HL. LD (HL),C ; place zero (or low byte). INC HL ; next address. LD (HL),B ; place zero (or high byte). RET ; return. ; ------------------------ ; THE 'CLOSE-2' SUBROUTINE ; ------------------------ ; There is not much point in coming here. ; The purpose was once to find the offset to a special closing routine, ; in this ROM and within 256 bytes of the close stream look up table that ; would reclaim any buffers associated with a stream. At least one has been ; removed. ; Any attempt to CLOSE streams 00h to 004h, without first opening the stream, ; will lead to either a system restart or the production of a strange report. ; credit: Martin Wren-Hilton 1982. ;; CLOSE-2 L1701: PUSH HL ; * save address of stream data pointer ; in STRMS on the machine stack. LD HL,(05C4Fh) ; fetch CHANS address to HL ADD HL,BC ; add the offset to address the second ; byte of the output routine hopefully. INC HL ; step past INC HL ; the input routine. ; Note. When the Sinclair Interface1 is fitted then an instruction fetch ; on the next address pages this ROM out and the shadow ROM in. ;; ROM_TRAP L1708: INC HL ; to address channel's letter LD C,(HL) ; pick it up in C. ; Note. but if stream is already closed we ; get the value 010h (the byte preceding 'K'). EX DE,HL ; save the pointer to the letter in DE. ; Note. The string pointer is saved but not used!! LD HL,L1716 ; address: cl-str-lu in ROM. CALL L16DC ; routine INDEXER uses the code to get ; the 8-bit offset from the current point to ; the address of the closing routine in ROM. ; Note. it won't find 010h there! LD C,(HL) ; transfer the offset to C. LD B,00h ; prepare to add. ADD HL,BC ; add offset to point to the address of the ; routine that closes the stream. ; (and presumably removes any buffers that ; are associated with it.) JP (HL) ; jump to that routine. ; -------------------------------- ; THE 'CLOSE STREAM LOOK-UP' TABLE ; -------------------------------- ; This table contains an entry for a letter found in the CHANS area. ; followed by an 8-bit displacement, from that byte's address in the ; table to the routine that performs any ancillary actions associated ; with closing the stream of that channel. ; The table doesn't require a zero end-marker as the letter has been ; picked up from a channel that has an open stream. ;; cl-str-lu L1716: .DEFB 'K',005h ; L171C-$-1 ; offset 5 to CLOSE-STR .DEFB 'S',003h ; L171C-$-1 ; offset 3 to CLOSE-STR .DEFB 'P',001h ; L171C-$-1 ; offset 1 to CLOSE-STR ; ------------------------------ ; THE 'CLOSE STREAM' SUBROUTINES ; ------------------------------ ; The close stream routines in fact have no ancillary actions to perform ; which is not surprising with regard to 'K' and 'S'. ;; CLOSE-STR L171C: POP HL ; * now just restore the stream data pointer RET ; in STRMS and return. ; ----------- ; Stream data ; ----------- ; This routine finds the data entry in the STRMS area for the specified ; stream which is passed on the calculator stack. It returns with HL ; pointing to this system variable and BC holding a displacement from ; the CHANS area to the second byte of the stream's channel. If BC holds ; zero, then that signifies that the stream is closed. ;; STR-DATA L171E: CALL L1E94 ; routine FIND-INT1 fetches parameter to A CP 010h ; is it less than 16d ? JR C,L1727 ; skip forward to STR-DATA1 if so. ;; REPORT-Ob L1725: RST 08H ; ERROR-1 .DEFB 017h ; Error Report: Invalid stream ;; STR-DATA1 L1727: ADD A,003h ; add the offset for 3 system streams. ; range 00 - 15d becomes 3 - 18d. RLCA ; double as there are two bytes per ; stream - now 06 - 36d LD HL,05C10h ; address STRMS - the start of the streams ; data area in system variables. LD C,A ; transfer the low byte to A. LD B,00h ; prepare to add offset. ADD HL,BC ; add to address the data entry in STRMS. ; the data entry itself contains an offset from CHANS to the address of the ; stream LD C,(HL) ; low byte of displacement to C. INC HL ; address next. LD B,(HL) ; high byte of displacement to B. DEC HL ; step back to leave HL pointing to STRMS ; data entry. RET ; return with CHANS displacement in BC ; and address of stream data entry in HL. ; -------------------- ; Handle OPEN# command ; -------------------- ; Command syntax example: OPEN #5,"s" ; On entry the channel code entry is on the calculator stack with the next ; value containing the stream identifier. They have to swapped. ;; OPEN L1736: RST 28H ;; FP-CALC ;s,c. .DEFB 001h ;;exchange ;c,s. .DEFB 038h ;;end-calc CALL L171E ; routine STR-DATA fetches the stream off ; the stack and returns with the CHANS ; displacement in BC and HL addressing ; the STRMS data entry. LD A,B ; test for zero which OR C ; indicates the stream is closed. JR Z,L1756 ; skip forward to OPEN-1 if so. ; if it is a system channel then it can re-attached. EX DE,HL ; save STRMS address in DE. LD HL,(05C4Fh) ; fetch CHANS. ADD HL,BC ; add the offset to address the second ; byte of the channel. INC HL ; skip over the INC HL ; input routine. INC HL ; and address the letter. LD A,(HL) ; pick up the letter. EX DE,HL ; save letter pointer and bring back ; the STRMS pointer. CP 04Bh ; is it 'K' ? JR Z,L1756 ; forward to OPEN-1 if so CP 053h ; is it 'S' ? JR Z,L1756 ; forward to OPEN-1 if so CP 050h ; is it 'P' ? JR NZ,L1725 ; back to REPORT-Ob if not. ; to report 'Invalid stream'. ; continue if one of the upper-case letters was found. ; and rejoin here from above if stream was closed. ;; OPEN-1 L1756: CALL L175D ; routine OPEN-2 opens the stream. ; it now remains to update the STRMS variable. LD (HL),E ; insert or overwrite the low byte. INC HL ; address high byte in STRMS. LD (HL),D ; insert or overwrite the high byte. RET ; return. ; ----------------- ; OPEN-2 Subroutine ; ----------------- ; There is some point in coming here as, as well as once creating buffers, ; this routine also sets flags. ;; OPEN-2 L175D: PUSH HL ; * save the STRMS data entry pointer. CALL L2BF1 ; routine STK-FETCH now fetches the ; parameters of the channel string. ; start in DE, length in BC. LD A,B ; test that it is not OR C ; the null string. JR NZ,L1767 ; skip forward to OPEN-3 with 1 character ; or more! ;; REPORT-Fb L1765: RST 08H ; ERROR-1 .DEFB 00Eh ; Error Report: Invalid file name ;; OPEN-3 L1767: PUSH BC ; save the length of the string. LD A,(DE) ; pick up the first character. ; Note. There can be more than one character. AND 0DFh ; make it upper-case. LD C,A ; place it in C. LD HL,L177A ; address: op-str-lu is loaded. CALL L16DC ; routine INDEXER will search for letter. JR NC,L1765 ; back to REPORT-F if not found ; 'Invalid filename' LD C,(HL) ; fetch the displacement to opening routine. LD B,00h ; prepare to add. ADD HL,BC ; now form address of opening routine. POP BC ; restore the length of string. JP (HL) ; now jump forward to the relevant routine. ; ------------------------- ; OPEN stream look-up table ; ------------------------- ; The open stream look-up table consists of matched pairs. ; The channel letter is followed by an 8-bit displacement to the ; associated stream-opening routine in this ROM. ; The table requires a zero end-marker as the letter has been ; provided by the user and not the operating system. ;; op-str-lu L177A: .DEFB 'K',006h ; L1781-$-1 ; 006h offset to OPEN-K .DEFB 'S',008h ; L1785-$-1 ; 008h offset to OPEN-S .DEFB 'P',00Ah ; L1789-$-1 ; 00Ah offset to OPEN-P .DEFB 00h ; end-marker. ; ---------------------------- ; The Stream Opening Routines. ; ---------------------------- ; These routines would have opened any buffers associated with the stream ; before jumping forward to OPEN-END with the displacement value in E ; and perhaps a modified value in BC. The strange pathing does seem to ; provide for flexibility in this respect. ; ; There is no need to open the printer buffer as it is there already ; even if you are still saving up for a ZX Printer or have moved onto ; something bigger. In any case it would have to be created after ; the system variables but apart from that it is a simple task ; and all but one of the ROM routines can handle a buffer in that position. ; (PR-ALL-6 would require an extra 3 bytes of code). ; However it wouldn't be wise to have two streams attached to the ZX Printer ; as you can now, so one assumes that if PR_CC_hi was non-zero then ; the OPEN-P routine would have refused to attach a stream if another ; stream was attached. ; Something of significance is being passed to these ghost routines in the ; second character. Strings 'RB', 'RT' perhaps or a drive/station number. ; The routine would have to deal with that and exit to OPEN_END with BC ; containing 001h or more likely there would be an exit within the routine. ; Anyway doesn't matter, these routines are long gone. ; ----------------- ; OPEN-K Subroutine ; ----------------- ; Open Keyboard stream. ;; OPEN-K L1781: LD E,001h ; 01 is offset to second byte of channel 'K'. JR L178B ; forward to OPEN-END ; ----------------- ; OPEN-S Subroutine ; ----------------- ; Open Screen stream. ;; OPEN-S L1785: LD E,006h ; 06 is offset to 2nd byte of channel 'S' JR L178B ; to OPEN-END ; ----------------- ; OPEN-P Subroutine ; ----------------- ; Open Printer stream. ;; OPEN-P L1789: LD E,010h ; 16d is offset to 2nd byte of channel 'P' ;; OPEN-END L178B: DEC BC ; the stored length of 'K','S','P' or ; whatever is now tested. ?? LD A,B ; test now if initial or residual length OR C ; is one character. JR NZ,L1765 ; to REPORT-Fb 'Invalid file name' if not. LD D,A ; load D with zero to form the displacement ; in the DE register. POP HL ; * restore the saved STRMS pointer. RET ; return to update STRMS entry thereby ; signaling stream is open. ; ---------------------------------------- ; Handle CAT, ERASE, FORMAT, MOVE commands ; ---------------------------------------- ; These just generate an error report as the ROM is 'incomplete'. ; ; Luckily this provides a mechanism for extending these in a shadow ROM ; but without the powerful mechanisms set up in this ROM. ; An instruction fetch on 008h may page in a peripheral ROM, ; e.g. the Sinclair Interface 1 ROM, to handle these commands. ; However that wasn't the plan. ; Development of this ROM continued for another three months until the cost ; of replacing it and the manual became unfeasible. ; The ultimate power of channels and streams died at birth. ;; CAT-ETC L1793: JR L1725 ; to REPORT-Ob ; ----------------- ; Perform AUTO-LIST ; ----------------- ; This produces an automatic listing in the upper screen. ;; AUTO-LIST L1795: LD (05C3Fh),SP ; save stack pointer in LIST_SP LD (IY+002h),010h ; update TV_FLAG set bit 3 CALL L0DAF ; routine CL-ALL. SET 0,(IY+002h) ; update TV_FLAG - signal lower screen in use LD B,(IY+031h) ; fetch DF_SZ to B. CALL L0E44 ; routine CL-LINE clears lower display ; preserving B. RES 0,(IY+002h) ; update TV_FLAG - signal main screen in use SET 0,(IY+030h) ; update FLAGS2 - signal will be necessary to ; clear main screen. LD HL,(05C49h) ; fetch E_PPC current edit line to HL. LD DE,(05C6Ch) ; fetch S_TOP to DE, the current top line ; (initially zero) AND A ; prepare for true subtraction. SBC HL,DE ; subtract and ADD HL,DE ; add back. JR C,L17E1 ; to AUTO-L-2 if S_TOP higher than E_PPC ; to set S_TOP to E_PPC PUSH DE ; save the top line number. CALL L196E ; routine LINE-ADDR gets address of E_PPC. LD DE,002C0h ; prepare known number of characters in ; the default upper screen. EX DE,HL ; offset to HL, program address to DE. SBC HL,DE ; subtract high value from low to obtain ; negated result used in addition. EX (SP),HL ; swap result with top line number on stack. CALL L196E ; routine LINE-ADDR gets address of that ; top line in HL and next line in DE. POP BC ; restore the result to balance stack. ;; AUTO-L-1 L17CE: PUSH BC ; save the result. CALL L19B8 ; routine NEXT-ONE gets address in HL of ; line after auto-line (in DE). POP BC ; restore result. ADD HL,BC ; compute back. JR C,L17E4 ; to AUTO-L-3 if line 'should' appear EX DE,HL ; address of next line to HL. LD D,(HL) ; get line INC HL ; number LD E,(HL) ; in DE. DEC HL ; adjust back to start. LD (05C6Ch),DE ; update S_TOP. JR L17CE ; to AUTO-L-1 until estimate reached. ; --- ; the jump was to here if S_TOP was greater than E_PPC ;; AUTO-L-2 L17E1: LD (05C6Ch),HL ; make S_TOP the same as E_PPC. ; continue here with valid starting point from above or good estimate ; from computation ;; AUTO-L-3 L17E4: LD HL,(05C6Ch) ; fetch S_TOP line number to HL. CALL L196E ; routine LINE-ADDR gets address in HL. ; address of next in DE. JR Z,L17ED ; to AUTO-L-4 if line exists. EX DE,HL ; else use address of next line. ;; AUTO-L-4 L17ED: CALL L1833 ; routine LIST-ALL >>> ; The return will be to here if no scrolling occurred RES 4,(IY+002h) ; update TV_FLAG - signal no auto listing. RET ; return. ; ------------ ; Handle LLIST ; ------------ ; A short form of LIST #3. The listing goes to stream 3 - default printer. ;; LLIST L17F5: LD A,003h ; the usual stream for ZX Printer JR L17FB ; forward to LIST-1 ; ----------- ; Handle LIST ; ----------- ; List to any stream. ; Note. While a starting line can be specified it is ; not possible to specify an end line. ; Just listing a line makes it the current edit line. ;; LIST L17F9: LD A,002h ; default is stream 2 - the upper screen. ;; LIST-1 L17FB: LD (IY+002h),00h ; the TV_FLAG is initialized with bit 0 reset ; indicating upper screen in use. CALL L2530 ; routine SYNTAX-Z - checking syntax ? CALL NZ,L1601 ; routine CHAN-OPEN if in run-time. RST 18H ; GET-CHAR CALL L2070 ; routine STR-ALTER will alter if '#'. JR C,L181F ; forward to LIST-4 not a '#' . RST 18H ; GET-CHAR CP 03Bh ; is it ';' ? JR Z,L1814 ; skip to LIST-2 if so. CP 02Ch ; is it ',' ? JR NZ,L181A ; forward to LIST-3 if neither separator. ; we have, say, LIST #15, and a number must follow the separator. ;; LIST-2 L1814: RST 20H ; NEXT-CHAR CALL L1C82 ; routine EXPT-1NUM JR L1822 ; forward to LIST-5 ; --- ; the branch was here with just LIST #3 etc. ;; LIST-3 L181A: CALL L1CE6 ; routine USE-ZERO JR L1822 ; forward to LIST-5 ; --- ; the branch was here with LIST ;; LIST-4 L181F: CALL L1CDE ; routine FETCH-NUM checks if a number ; follows else uses zero. ;; LIST-5 L1822: CALL L1BEE ; routine CHECK-END quits if syntax OK >>> CALL L1E99 ; routine FIND-INT2 fetches the number ; from the calculator stack in run-time. LD A,B ; fetch high byte of line number and AND 03Fh ; make less than 040h so that NEXT-ONE ; (from LINE-ADDR) doesn't lose context. ; Note. this is not satisfactory and the typo ; LIST 20000 will list an entirely different ; section than LIST 2000. Such typos are not ; available for checking if they are direct ; commands. LD H,A ; transfer the modified LD L,C ; line number to HL. LD (05C49h),HL ; update E_PPC to new line number. CALL L196E ; routine LINE-ADDR gets the address of the ; line. ; This routine is called from AUTO-LIST ;; LIST-ALL L1833: LD E,001h ; signal current line not yet printed ;; LIST-ALL-2 L1835: CALL L1855 ; routine OUT-LINE outputs a BASIC line ; using PRINT-OUT and makes an early return ; when no more lines to print. >>> RST 10H ; PRINT-A prints the carriage return (in A) BIT 4,(IY+002h) ; test TV_FLAG - automatic listing ? JR Z,L1835 ; back to LIST-ALL-2 if not ; (loop exit is via OUT-LINE) ; continue here if an automatic listing required. LD A,(05C6Bh) ; fetch DF_SZ lower display file size. SUB (IY+04Fh) ; subtract S_POSN_hi ithe current line number. JR NZ,L1835 ; back to LIST-ALL-2 if upper screen not full. XOR E ; A contains zero, E contains one if the ; current edit line has not been printed ; or zero if it has (from OUT-LINE). RET Z ; return if the screen is full and the line ; has been printed. ; continue with automatic listings if the screen is full and the current ; edit line is missing. OUT-LINE will scroll automatically. PUSH HL ; save the pointer address. PUSH DE ; save the E flag. LD HL,05C6Ch ; fetch S_TOP the rough estimate. CALL L190F ; routine LN-FETCH updates S_TOP with ; the number of the next line. POP DE ; restore the E flag. POP HL ; restore the address of the next line. JR L1835 ; back to LIST-ALL-2. ; ------------------------ ; Print a whole BASIC line ; ------------------------ ; This routine prints a whole BASIC line and it is called ; from LIST-ALL to output the line to current channel ; and from ED-EDIT to 'sprint' the line to the edit buffer. ;; OUT-LINE L1855: LD BC,(05C49h) ; fetch E_PPC the current line which may be ; unchecked and not exist. CALL L1980 ; routine CP-LINES finds match or line after. LD D,03Eh ; prepare cursor '>' in D. JR Z,L1865 ; to OUT-LINE1 if matched or line after. LD DE,000h ; put zero in D, to suppress line cursor. RL E ; pick up carry in E if line before current ; leave E zero if same or after. ;; OUT-LINE1 L1865: LD (IY+02Dh),E ; save flag in BREG which is spare. LD A,(HL) ; get high byte of line number. CP 040h ; is it too high (02Fh is maximum possible) ? POP BC ; drop the return address and RET NC ; make an early return if so >>> PUSH BC ; save return address CALL L1A28 ; routine OUT-NUM-2 to print addressed number ; with leading space. INC HL ; skip low number byte. INC HL ; and the two INC HL ; length bytes. RES 0,(IY+001h) ; update FLAGS - signal leading space required. LD A,D ; fetch the cursor. AND A ; test for zero. JR Z,L1881 ; to OUT-LINE3 if zero. RST 10H ; PRINT-A prints '>' the current line cursor. ; this entry point is called from ED-COPY ;; OUT-LINE2 L187D: SET 0,(IY+001h) ; update FLAGS - suppress leading space. ;; OUT-LINE3 L1881: PUSH DE ; save flag E for a return value. EX DE,HL ; save HL address in DE. RES 2,(IY+030h) ; update FLAGS2 - signal NOT in QUOTES. LD HL,05C3Bh ; point to FLAGS. RES 2,(HL) ; signal 'K' mode. (starts before keyword) BIT 5,(IY+037h) ; test FLAGX - input mode ? JR Z,L1894 ; forward to OUT-LINE4 if not. SET 2,(HL) ; signal 'L' mode. (used for input) ;; OUT-LINE4 L1894: LD HL,(05C5Fh) ; fetch X_PTR - possibly the error pointer ; address. AND A ; clear the carry flag. SBC HL,DE ; test if an error address has been reached. JR NZ,L18A1 ; forward to OUT-LINE5 if not. LD A,03Fh ; load A with '?' the error marker. CALL L18C1 ; routine OUT-FLASH to print flashing marker. ;; OUT-LINE5 L18A1: CALL L18E1 ; routine OUT-CURS will print the cursor if ; this is the right position. EX DE,HL ; restore address pointer to HL. LD A,(HL) ; fetch the addressed character. CALL L18B6 ; routine NUMBER skips a hidden floating ; point number if present. INC HL ; now increment the pointer. CP 00Dh ; is character end-of-line ? JR Z,L18B4 ; to OUT-LINE6, if so, as line is finished. EX DE,HL ; save the pointer in DE. CALL L1937 ; routine OUT-CHAR to output character/token. JR L1894 ; back to OUT-LINE4 until entire line is done. ; --- ;; OUT-LINE6 L18B4: POP DE ; bring back the flag E, zero if current ; line printed else 1 if still to print. RET ; return with A holding 00Dh ; ------------------------- ; Check for a number marker ; ------------------------- ; this subroutine is called from two processes. while outputting BASIC lines ; and while searching statements within a BASIC line. ; during both, this routine will pass over an invisible number indicator ; and the five bytes floating-point number that follows it. ; Note that this causes floating point numbers to be stripped from ; the BASIC line when it is fetched to the edit buffer by OUT_LINE. ; the number marker also appears after the arguments of a DEF FN statement ; and may mask old 5-byte string parameters. ;; NUMBER L18B6: CP 00Eh ; character fourteen ? RET NZ ; return if not. INC HL ; skip the character INC HL ; and five bytes INC HL ; following. INC HL ; INC HL ; INC HL ; LD A,(HL) ; fetch the following character RET ; for return value. ; -------------------------- ; Print a flashing character ; -------------------------- ; This subroutine is called from OUT-LINE to print a flashing error ; marker '?' or from the next routine to print a flashing cursor e.g. 'L'. ; However, this only gets called from OUT-LINE when printing the edit line ; or the input buffer to the lower screen so a direct call to 009F4h can ; be used, even though out-line outputs to other streams. ; In fact the alternate set is used for the whole routine. ;; OUT-FLASH L18C1: EXX ; switch in alternate set LD HL,(05C8Fh) ; fetch L = ATTR_T, H = MASK-T PUSH HL ; save masks. RES 7,H ; reset flash mask bit so active. SET 7,L ; make attribute FLASH. LD (05C8Fh),HL ; resave ATTR_T and MASK-T LD HL,05C91h ; address P_FLAG LD D,(HL) ; fetch to D PUSH DE ; and save. LD (HL),00h ; clear inverse, over, ink/paper 9 CALL L09F4 ; routine PRINT-OUT outputs character ; without the need to vector via RST 10. POP HL ; pop P_FLAG to H. LD (IY+057h),H ; and restore system variable P_FLAG. POP HL ; restore temporary masks LD (05C8Fh),HL ; and restore system variables ATTR_T/MASK_T EXX ; switch back to main set RET ; return ; ---------------- ; Print the cursor ; ---------------- ; This routine is called before any character is output while outputting ; a BASIC line or the input buffer. This includes listing to a printer ; or screen, copying a BASIC line to the edit buffer and printing the ; input buffer or edit buffer to the lower screen. It is only in the ; latter two cases that it has any relevance and in the last case it ; performs another very important function also. ;; OUT-CURS L18E1: LD HL,(05C5Bh) ; fetch K_CUR the current cursor address AND A ; prepare for true subtraction. SBC HL,DE ; test against pointer address in DE and RET NZ ; return if not at exact position. ; the value of MODE, maintained by KEY-INPUT, is tested and if non-zero ; then this value 'E' or 'G' will take precedence. LD A,(05C41h) ; fetch MODE 0='KLC', 1='E', 2='G'. RLC A ; double the value and set flags. JR Z,L18F3 ; to OUT-C-1 if still zero ('KLC'). ADD A,043h ; add 'C' - will become 'E' if originally 1 ; or 'G' if originally 2. JR L1909 ; forward to OUT-C-2 to print. ; --- ; If mode was zero then, while printing a BASIC line, bit 2 of flags has been ; set if 'THEN' or ':' was encountered as a main character and reset otherwise. ; This is now used to determine if the 'K' cursor is to be printed but this ; transient state is also now transferred permanently to bit 3 of FLAGS ; to let the interrupt routine know how to decode the next key. ;; OUT-C-1 L18F3: LD HL,05C3Bh ; Address FLAGS RES 3,(HL) ; signal 'K' mode initially. LD A,04Bh ; prepare letter 'K'. BIT 2,(HL) ; test FLAGS - was the ; previous main character ':' or 'THEN' ? JR Z,L1909 ; forward to OUT-C-2 if so to print. SET 3,(HL) ; signal 'L' mode to interrupt routine. ; Note. transient bit has been made permanent. INC A ; augment from 'K' to 'L'. BIT 3,(IY+030h) ; test FLAGS2 - consider caps lock ? ; which is maintained by KEY-INPUT. JR Z,L1909 ; forward to OUT-C-2 if not set to print. LD A,043h ; alter 'L' to 'C'. ;; OUT-C-2 L1909: PUSH DE ; save address pointer but OK as OUT-FLASH ; uses alternate set without RST 10. CALL L18C1 ; routine OUT-FLASH to print. POP DE ; restore and RET ; return. ; ---------------------------- ; Get line number of next line ; ---------------------------- ; These two subroutines are called while editing. ; This entry point is from ED-DOWN with HL addressing E_PPC ; to fetch the next line number. ; Also from AUTO-LIST with HL addressing S_TOP just to update S_TOP ; with the value of the next line number. It gets fetched but is discarded. ; These routines never get called while the editor is being used for input. ;; LN-FETCH L190F: LD E,(HL) ; fetch low byte INC HL ; address next LD D,(HL) ; fetch high byte. PUSH HL ; save system variable hi pointer. EX DE,HL ; line number to HL, INC HL ; increment as a starting point. CALL L196E ; routine LINE-ADDR gets address in HL. CALL L1695 ; routine LINE-NO gets line number in DE. POP HL ; restore system variable hi pointer. ; This entry point is from the ED-UP with HL addressing E_PPC_hi ;; LN-STORE L191C: BIT 5,(IY+037h) ; test FLAGX - input mode ? RET NZ ; return if so. ; Note. above already checked by ED-UP/ED-DOWN. LD (HL),D ; save high byte of line number. DEC HL ; address lower LD (HL),E ; save low byte of line number. RET ; return. ; ----------------------------------------- ; Outputting numbers at start of BASIC line ; ----------------------------------------- ; This routine entered at OUT-SP-NO is used to compute then output the first ; three digits of a 4-digit BASIC line printing a space if necessary. ; The line number, or residual part, is held in HL and the BC register ; holds a subtraction value -1000, -100 or -10. ; Note. for example line number 200 - ; space(out_char), 2(out_code), 0(out_char) final number always out-code. ;; OUT-SP-2 L1925: LD A,E ; will be space if OUT-CODE not yet called. ; or 0FFh if spaces are suppressed. ; else 030h ('0'). ; (from the first instruction at OUT-CODE) ; this guy is just too clever. AND A ; test bit 7 of A. RET M ; return if 0FFh, as leading spaces not ; required. This is set when printing line ; number and statement in MAIN-5. JR L1937 ; forward to exit via OUT-CHAR. ; --- ; -> the single entry point. ;; OUT-SP-NO L192A: XOR A ; initialize digit to 0 ;; OUT-SP-1 L192B: ADD HL,BC ; add negative number to HL. INC A ; increment digit JR C,L192B ; back to OUT-SP-1 until no carry from ; the addition. SBC HL,BC ; cancel the last addition DEC A ; and decrement the digit. JR Z,L1925 ; back to OUT-SP-2 if it is zero. JP L15EF ; jump back to exit via OUT-CODE. -> ; ------------------------------------- ; Outputting characters in a BASIC line ; ------------------------------------- ; This subroutine ... ;; OUT-CHAR L1937: CALL L2D1B ; routine NUMERIC tests if it is a digit ? JR NC,L196C ; to OUT-CH-3 to print digit without ; changing mode. Will be 'K' mode if digits ; are at beginning of edit line. CP 021h ; less than quote character ? JR C,L196C ; to OUT-CH-3 to output controls and space. RES 2,(IY+001h) ; initialize FLAGS to 'K' mode and leave ; unchanged if this character would precede ; a keyword. CP 0CBh ; is character 'THEN' token ? JR Z,L196C ; to OUT-CH-3 to output if so. CP 03Ah ; is it ':' ? JR NZ,L195A ; to OUT-CH-1 if not statement separator ; to change mode back to 'L'. BIT 5,(IY+037h) ; FLAGX - Input Mode ?? JR NZ,L1968 ; to OUT-CH-2 if in input as no statements. ; Note. this check should seemingly be at ; the start. Commands seem inappropriate in ; INPUT mode and are rejected by the syntax ; checker anyway. ; unless INPUT LINE is being used. BIT 2,(IY+030h) ; test FLAGS2 - is the ':' within quotes ? JR Z,L196C ; to OUT-CH-3 if ':' is outside quoted text. JR L1968 ; to OUT-CH-2 as ':' is within quotes ; --- ;; OUT-CH-1 L195A: CP 022h ; is it quote character '"' ? JR NZ,L1968 ; to OUT-CH-2 with others to set 'L' mode. PUSH AF ; save character. LD A,(05C6Ah) ; fetch FLAGS2. XOR 004h ; toggle the quotes flag. LD (05C6Ah),A ; update FLAGS2 POP AF ; and restore character. ;; OUT-CH-2 L1968: SET 2,(IY+001h) ; update FLAGS - signal L mode if the cursor ; is next. ;; OUT-CH-3 L196C: RST 10H ; PRINT-A vectors the character to ; channel 'S', 'K', 'R' or 'P'. RET ; return. ; ------------------------------------------- ; Get starting address of line, or line after ; ------------------------------------------- ; This routine is used often to get the address, in HL, of a BASIC line ; number supplied in HL, or failing that the address of the following line ; and the address of the previous line in DE. ;; LINE-ADDR L196E: PUSH HL ; save line number in HL register LD HL,(05C53h) ; fetch start of program from PROG LD D,H ; transfer address to LD E,L ; the DE register pair. ;; LINE-AD-1 L1974: POP BC ; restore the line number to BC CALL L1980 ; routine CP-LINES compares with that ; addressed by HL RET NC ; return if line has been passed or matched. ; if NZ, address of previous is in DE PUSH BC ; save the current line number CALL L19B8 ; routine NEXT-ONE finds address of next ; line number in DE, previous in HL. EX DE,HL ; switch so next in HL JR L1974 ; back to LINE-AD-1 for another comparison ; -------------------- ; Compare line numbers ; -------------------- ; This routine compares a line number supplied in BC with an addressed ; line number pointed to by HL. ;; CP-LINES L1980: LD A,(HL) ; Load the high byte of line number and CP B ; compare with that of supplied line number. RET NZ ; return if yet to match (carry will be set). INC HL ; address low byte of LD A,(HL) ; number and pick up in A. DEC HL ; step back to first position. CP C ; now compare. RET ; zero set if exact match. ; carry set if yet to match. ; no carry indicates a match or ; next available BASIC line or ; program end marker. ; ------------------- ; Find each statement ; ------------------- ; The single entry point EACH-STMT is used to ; 1) To find the D'th statement in a line. ; 2) To find a token in held E. ;; not-used L1988: INC HL ; INC HL ; INC HL ; ; -> entry point. ;; EACH-STMT L198B: LD (05C5Dh),HL ; save HL in CH_ADD LD C,00h ; initialize quotes flag ;; EACH-S-1 L1990: DEC D ; decrease statement count RET Z ; return if zero RST 20H ; NEXT-CHAR CP E ; is it the search token ? JR NZ,L199A ; forward to EACH-S-3 if not AND A ; clear carry RET ; return signalling success. ; --- ;; EACH-S-2 L1998: INC HL ; next address LD A,(HL) ; next character ;; EACH-S-3 L199A: CALL L18B6 ; routine NUMBER skips if number marker LD (05C5Dh),HL ; save in CH_ADD CP 022h ; is it quotes '"' ? JR NZ,L19A5 ; to EACH-S-4 if not DEC C ; toggle bit 0 of C ;; EACH-S-4 L19A5: CP 03Ah ; is it ':' JR Z,L19AD ; to EACH-S-5 CP 0CBh ; 'THEN' JR NZ,L19B1 ; to EACH-S-6 ;; EACH-S-5 L19AD: BIT 0,C ; is it in quotes JR Z,L1990 ; to EACH-S-1 if not ;; EACH-S-6 L19B1: CP 00Dh ; end of line ? JR NZ,L1998 ; to EACH-S-2 DEC D ; decrease the statement counter ; which should be zero else ; 'Statement Lost'. SCF ; set carry flag - not found RET ; return ; ----------------------------------------------------------------------- ; Storage of variables. For full details - see chapter 24. ; ZX Spectrum BASIC Programming by Steven Vickers 1982. ; It is bits 7-5 of the first character of a variable that allow ; the six types to be distinguished. Bits 4-0 are the reduced letter. ; So any variable name is higher that 03Fh and can be distinguished ; also from the variables area end-marker 080h. ; ; 76543210 meaning brief outline of format. ; -------- ------------------------ ----------------------- ; 010 string variable. 2 byte length + contents. ; 110 string array. 2 byte length + contents. ; 100 array of numbers. 2 byte length + contents. ; 011 simple numeric variable. 5 bytes. ; 101 variable length named numeric. 5 bytes. ; 111 for-next loop variable. 18 bytes. ; 10000000 the variables area end-marker. ; ; Note. any of the above seven will serve as a program end-marker. ; ; ----------------------------------------------------------------------- ; ------------ ; Get next one ; ------------ ; This versatile routine is used to find the address of the next line ; in the program area or the next variable in the variables area. ; The reason one routine is made to handle two apparently unrelated tasks ; is that it can be called indiscriminately when merging a line or a ; variable. ;; NEXT-ONE L19B8: PUSH HL ; save the pointer address. LD A,(HL) ; get first byte. CP 040h ; compare with upper limit for line numbers. JR C,L19D5 ; forward to NEXT-O-3 if within BASIC area. ; the continuation here is for the next variable unless the supplied ; line number was erroneously over 16383. see RESTORE command. BIT 5,A ; is it a string or an array variable ? JR Z,L19D6 ; forward to NEXT-O-4 to compute length. ADD A,A ; test bit 6 for single-character variables. JP M,L19C7 ; forward to NEXT-O-1 if so CCF ; clear the carry for long-named variables. ; it remains set for for-next loop variables. ;; NEXT-O-1 L19C7: LD BC,005h ; set BC to 5 for floating point number JR NC,L19CE ; forward to NEXT-O-2 if not a for/next ; variable. LD C,012h ; set BC to eighteen locations. ; value, limit, step, line and statement. ; now deal with long-named variables ;; NEXT-O-2 L19CE: RLA ; test if character inverted. carry will also ; be set for single character variables INC HL ; address next location. LD A,(HL) ; and load character. JR NC,L19CE ; back to NEXT-O-2 if not inverted bit. ; forward immediately with single character ; variable names. JR L19DB ; forward to NEXT-O-5 to add length of ; floating point number(s etc.). ; --- ; this branch is for line numbers. ;; NEXT-O-3 L19D5: INC HL ; increment pointer to low byte of line no. ; strings and arrays rejoin here ;; NEXT-O-4 L19D6: INC HL ; increment to address the length low byte. LD C,(HL) ; transfer to C and INC HL ; point to high byte of length. LD B,(HL) ; transfer that to B INC HL ; point to start of BASIC/variable contents. ; the three types of numeric variables rejoin here ;; NEXT-O-5 L19DB: ADD HL,BC ; add the length to give address of next ; line/variable in HL. POP DE ; restore previous address to DE. ; ------------------ ; Difference routine ; ------------------ ; This routine terminates the above routine and is also called from the ; start of the next routine to calculate the length to reclaim. ;; DIFFER L19DD: AND A ; prepare for true subtraction. SBC HL,DE ; subtract the two pointers. LD B,H ; transfer result LD C,L ; to BC register pair. ADD HL,DE ; add back EX DE,HL ; and switch pointers RET ; return values are the length of area in BC, ; low pointer (previous) in HL, ; high pointer (next) in DE. ; ----------------------- ; Handle reclaiming space ; ----------------------- ; ;; RECLAIM-1 L19E5: CALL L19DD ; routine DIFFER immediately above ;; RECLAIM-2 L19E8: PUSH BC ; LD A,B ; CPL ; LD B,A ; LD A,C ; CPL ; LD C,A ; INC BC ; CALL L1664 ; routine POINTERS EX DE,HL ; POP HL ; ADD HL,DE ; PUSH DE ; LDIR ; copy bytes POP HL ; RET ; ; ---------------------------------------- ; Read line number of line in editing area ; ---------------------------------------- ; This routine reads a line number in the editing area returning the number ; in the BC register or zero if no digits exist before commands. ; It is called from LINE-SCAN to check the syntax of the digits. ; It is called from MAIN-3 to extract the line number in preparation for ; inclusion of the line in the BASIC program area. ; ; Interestingly the calculator stack is moved from its normal place at the ; end of dynamic memory to an adequate area within the system variables area. ; This ensures that in a low memory situation, that valid line numbers can ; be extracted without raising an error and that memory can be reclaimed ; by deleting lines. If the stack was in its normal place then a situation ; arises whereby the Spectrum becomes locked with no means of reclaiming space. ;; E-LINE-NO L19FB: LD HL,(05C59h) ; load HL from system variable E_LINE. DEC HL ; decrease so that NEXT_CHAR can be used ; without skipping the first digit. LD (05C5Dh),HL ; store in the system variable CH_ADD. RST 20H ; NEXT-CHAR skips any noise and white-space ; to point exactly at the first digit. LD HL,05C92h ; use MEM-0 as a temporary calculator stack ; an overhead of three locations are needed. LD (05C65h),HL ; set new STKEND. CALL L2D3B ; routine INT-TO-FP will read digits till ; a non-digit found. CALL L2DA2 ; routine FP-TO-BC will retrieve number ; from stack at membot. JR C,L1A15 ; forward to E-L-1 if overflow i.e. > 65535. ; 'Nonsense in BASIC' LD HL,0D8F0h ; load HL with value -9999 ADD HL,BC ; add to line number in BC ;; E-L-1 L1A15: JP C,L1C8A ; to REPORT-C 'Nonsense in BASIC' if over. ; Note. As ERR_SP points to ED_ERROR ; the report is never produced although ; the RST 008h will update X_PTR leading to ; the error marker being displayed when ; the ED_LOOP is reiterated. ; in fact, since it is immediately ; cancelled, any report will do. ; a line in the range 0 - 9999 has been entered. JP L16C5 ; jump back to SET-STK to set the calculator ; stack back to its normal place and exit ; from there. ; --------------------------------- ; Report and line number outputting ; --------------------------------- ; Entry point OUT-NUM-1 is used by the Error Reporting code to print ; the line number and later the statement number held in BC. ; If the statement was part of a direct command then -2 is used as a ; dummy line number so that zero will be printed in the report. ; This routine is also used to print the exponent of E-format numbers. ; ; Entry point OUT-NUM-2 is used from OUT-LINE to output the line number ; addressed by HL with leading spaces if necessary. ;; OUT-NUM-1 L1A1B: PUSH DE ; save the PUSH HL ; registers. XOR A ; set A to zero. BIT 7,B ; is the line number minus two ? JR NZ,L1A42 ; forward to OUT-NUM-4 if so to print zero ; for a direct command. LD H,B ; transfer the LD L,C ; number to HL. LD E,0FFh ; signal 'no leading zeros'. JR L1A30 ; forward to continue at OUT-NUM-3 ; --- ; from OUT-LINE - HL addresses line number. ;; OUT-NUM-2 L1A28: PUSH DE ; save flags LD D,(HL) ; high byte to D INC HL ; address next LD E,(HL) ; low byte to E PUSH HL ; save pointer EX DE,HL ; transfer number to HL LD E,020h ; signal 'output leading spaces' ;; OUT-NUM-3 L1A30: LD BC,0FC18h ; value -1000 CALL L192A ; routine OUT-SP-NO outputs space or number LD BC,0FF9Ch ; value -100 CALL L192A ; routine OUT-SP-NO LD C,0F6h ; value -10 ( B is still 0FFh ) CALL L192A ; routine OUT-SP-NO LD A,L ; remainder to A. ;; OUT-NUM-4 L1A42: CALL L15EF ; routine OUT-CODE for final digit. ; else report code zero wouldn't get ; printed. POP HL ; restore the POP DE ; registers and RET ; return. ;*************************************************** ;** Part 7. BASIC LINE AND COMMAND INTERPRETATION ** ;*************************************************** ; ---------------- ; The offset table ; ---------------- ; The BASIC interpreter has found a command code 0CEh - 0FFh ; which is then reduced to range 00h - 031h and added to the base address ; of this table to give the address of an offset which, when added to ; the offset therein, gives the location in the following parameter table ; where a list of class codes, separators and addresses relevant to the ; command exists. ;; offst-tbl L1A48: .DEFB 0B1h ;L1AF9 - $ ; B1 offset to Address: P-DEF-FN .DEFB 0CBh ;L1B14 - $ ; CB offset to Address: P-CAT .DEFB 0BCh ;L1B06 - $ ; BC offset to Address: P-FORMAT .DEFB 0BFh ;L1B0A - $ ; BF offset to Address: P-MOVE .DEFB 0C4h ;L1B10 - $ ; C4 offset to Address: P-ERASE .DEFB 0AFh ;L1AFC - $ ; AF offset to Address: P-OPEN .DEFB 0B4h ;L1B02 - $ ; B4 offset to Address: P-CLOSE .DEFB 093h ;L1AE2 - $ ; 93 offset to Address: P-MERGE .DEFB 091h ;L1AE1 - $ ; 91 offset to Address: P-VERIFY .DEFB 092h ;L1AE3 - $ ; 92 offset to Address: P-BEEP .DEFB 095h ;L1AE7 - $ ; 95 offset to Address: P-CIRCLE .DEFB 098h ;L1AEB - $ ; 98 offset to Address: P-INK .DEFB 098h ;L1AEC - $ ; 98 offset to Address: P-PAPER .DEFB 098h ;L1AED - $ ; 98 offset to Address: P-FLASH .DEFB 098h ;L1AEE - $ ; 98 offset to Address: P-BRIGHT .DEFB 098h ;L1AEF - $ ; 98 offset to Address: P-INVERSE .DEFB 098h ;L1AF0 - $ ; 98 offset to Address: P-OVER .DEFB 098h ;L1AF1 - $ ; 98 offset to Address: P-OUT .DEFB 07Fh ;L1AD9 - $ ; 7F offset to Address: P-LPRINT .DEFB 081h ;L1ADC - $ ; 81 offset to Address: P-LLIST .DEFB 02Eh ;L1A8A - $ ; 2E offset to Address: P-STOP .DEFB 06Ch ;L1AC9 - $ ; 6C offset to Address: P-READ .DEFB 06Eh ;L1ACC - $ ; 6E offset to Address: P-DATA .DEFB 070h ;L1ACF - $ ; 70 offset to Address: P-RESTORE .DEFB 048h ;L1AA8 - $ ; 48 offset to Address: P-NEW .DEFB 094h ;L1AF5 - $ ; 94 offset to Address: P-BORDER .DEFB 056h ;L1AB8 - $ ; 56 offset to Address: P-CONT .DEFB 03Fh ;L1AA2 - $ ; 3F offset to Address: P-DIM .DEFB 041h ;L1AA5 - $ ; 41 offset to Address: P-REM .DEFB 02Bh ;L1A90 - $ ; 2B offset to Address: P-FOR .DEFB 017h ;L1A7D - $ ; 17 offset to Address: P-GO-TO .DEFB 01Fh ;L1A86 - $ ; 1F offset to Address: P-GO-SUB .DEFB 037h ;L1A9F - $ ; 37 offset to Address: P-INPUT .DEFB 077h ;L1AE0 - $ ; 77 offset to Address: P-LOAD .DEFB 044h ;L1AAE - $ ; 44 offset to Address: P-LIST .DEFB 00Fh ;L1A7A - $ ; 0F offset to Address: P-LET .DEFB 059h ;L1AC5 - $ ; 59 offset to Address: P-PAUSE .DEFB 02Bh ;L1A98 - $ ; 2B offset to Address: P-NEXT .DEFB 043h ;L1AB1 - $ ; 43 offset to Address: P-POKE .DEFB 02Dh ;L1A9C - $ ; 2D offset to Address: P-PRINT .DEFB 051h ;L1AC1 - $ ; 51 offset to Address: P-PLOT .DEFB 03Ah ;L1AAB - $ ; 3A offset to Address: P-RUN .DEFB 06Dh ;L1ADF - $ ; 6D offset to Address: P-SAVE .DEFB 042h ;L1AB5 - $ ; 42 offset to Address: P-RANDOM .DEFB 00Dh ;L1A81 - $ ; 0D offset to Address: P-IF .DEFB 049h ;L1ABE - $ ; 49 offset to Address: P-CLS .DEFB 05Ch ;L1AD2 - $ ; 5C offset to Address: P-DRAW .DEFB 044h ;L1ABB - $ ; 44 offset to Address: P-CLEAR .DEFB 015h ;L1A8D - $ ; 15 offset to Address: P-RETURN .DEFB 05Dh ;L1AD6 - $ ; 5D offset to Address: P-COPY ; ------------------------------- ; The parameter or "Syntax" table ; ------------------------------- ; For each command there exists a variable list of parameters. ; If the character is greater than a space it is a required separator. ; If less, then it is a command class in the range 00 - 0B. ; Note that classes 00, 03 and 05 will fetch the addresses from this table. ; Some classes e.g. 07 and 0B have the same address in all invocations ; and the command is re-computed from the low-byte of the parameter address. ; Some e.g. 02 are only called once so a call to the command is made from ; within the class routine rather than holding the address within the table. ; Some class routines check syntax entirely and some leave this task for the ; command itself. ; Others for example CIRCLE (x,y,z) check the first part (x,y) using the ; class routine and the final part (,z) within the command. ; The last few commands appear to have been added in a rush but their syntax ; is rather simple e.g. MOVE "M1","M2" ;; P-LET L1A7A: .DEFB 001h ; Class-01 - A variable is required. .DEFB 03Dh ; Separator: '=' .DEFB 002h ; Class-02 - An expression, numeric or string, ; must follow. ;; P-GO-TO L1A7D: .DEFB 006h ; Class-06 - A numeric expression must follow. .DEFB 00h ; Class-00 - No further operands. .DEFW L1E67 ; Address: 01E67h; Address: GO-TO ;; P-IF L1A81: .DEFB 006h ; Class-06 - A numeric expression must follow. .DEFB 0CBh ; Separator: 'THEN' .DEFB 005h ; Class-05 - Variable syntax checked ; by routine. .DEFW L1CF0 ; Address: 01CF0h; Address: IF ;; P-GO-SUB L1A86: .DEFB 006h ; Class-06 - A numeric expression must follow. .DEFB 00h ; Class-00 - No further operands. .DEFW L1EED ; Address: 01EEDh; Address: GO-SUB ;; P-STOP L1A8A: .DEFB 00h ; Class-00 - No further operands. .DEFW L1CEE ; Address: 01CEEh; Address: STOP ;; P-RETURN L1A8D: .DEFB 00h ; Class-00 - No further operands. .DEFW L1F23 ; Address: 01F23h; Address: RETURN ;; P-FOR L1A90: .DEFB 004h ; Class-04 - A single character variable must ; follow. .DEFB 03Dh ; Separator: '=' .DEFB 006h ; Class-06 - A numeric expression must follow. .DEFB 0CCh ; Separator: 'TO' .DEFB 006h ; Class-06 - A numeric expression must follow. .DEFB 005h ; Class-05 - Variable syntax checked ; by routine. .DEFW L1D03 ; Address: 01D03h; Address: FOR ;; P-NEXT L1A98: .DEFB 004h ; Class-04 - A single character variable must ; follow. .DEFB 00h ; Class-00 - No further operands. .DEFW L1DAB ; Address: 01DABh; Address: NEXT ;; P-PRINT L1A9C: .DEFB 005h ; Class-05 - Variable syntax checked entirely ; by routine. .DEFW L1FCD ; Address: 01FCDh; Address: PRINT ;; P-INPUT L1A9F: .DEFB 005h ; Class-05 - Variable syntax checked entirely ; by routine. .DEFW L2089 ; Address: 02089h; Address: INPUT ;; P-DIM L1AA2: .DEFB 005h ; Class-05 - Variable syntax checked entirely ; by routine. .DEFW L2C02 ; Address: 02C02h; Address: DIM ;; P-REM L1AA5: .DEFB 005h ; Class-05 - Variable syntax checked entirely ; by routine. .DEFW L1BB2 ; Address: 01BB2h; Address: REM ;; P-NEW L1AA8: .DEFB 00h ; Class-00 - No further operands. .DEFW L11B7 ; Address: 011B7h; Address: NEW ;; P-RUN L1AAB: .DEFB 003h ; Class-03 - A numeric expression may follow ; else default to zero. .DEFW L1EA1 ; Address: 01EA1h; Address: RUN ;; P-LIST L1AAE: .DEFB 005h ; Class-05 - Variable syntax checked entirely ; by routine. .DEFW L17F9 ; Address: 017F9h; Address: LIST ;; P-POKE L1AB1: .DEFB 008h ; Class-08 - Two comma-separated numeric ; expressions required. .DEFB 00h ; Class-00 - No further operands. .DEFW L1E80 ; Address: 01E80h; Address: POKE ;; P-RANDOM L1AB5: .DEFB 003h ; Class-03 - A numeric expression may follow ; else default to zero. .DEFW L1E4F ; Address: 01E4Fh; Address: RANDOMIZE ;; P-CONT L1AB8: .DEFB 00h ; Class-00 - No further operands. .DEFW L1E5F ; Address: 01E5Fh; Address: CONTINUE ;; P-CLEAR L1ABB: .DEFB 003h ; Class-03 - A numeric expression may follow ; else default to zero. .DEFW L1EAC ; Address: 01EACh; Address: CLEAR ;; P-CLS L1ABE: .DEFB 00h ; Class-00 - No further operands. .DEFW L0D6B ; Address: 00D6Bh; Address: CLS ;; P-PLOT L1AC1: .DEFB 009h ; Class-09 - Two comma-separated numeric ; expressions required with optional colour ; items. .DEFB 00h ; Class-00 - No further operands. .DEFW L22DC ; Address: 022DCh; Address: PLOT ;; P-PAUSE L1AC5: .DEFB 006h ; Class-06 - A numeric expression must follow. .DEFB 00h ; Class-00 - No further operands. .DEFW L1F3A ; Address: 01F3Ah; Address: PAUSE ;; P-READ L1AC9: .DEFB 005h ; Class-05 - Variable syntax checked entirely ; by routine. .DEFW L1DED ; Address: 01DEDh; Address: READ ;; P-DATA L1ACC: .DEFB 005h ; Class-05 - Variable syntax checked entirely ; by routine. .DEFW L1E27 ; Address: 01E27h; Address: DATA ;; P-RESTORE L1ACF: .DEFB 003h ; Class-03 - A numeric expression may follow ; else default to zero. .DEFW L1E42 ; Address: 01E42h; Address: RESTORE ;; P-DRAW L1AD2: .DEFB 009h ; Class-09 - Two comma-separated numeric ; expressions required with optional colour ; items. .DEFB 005h ; Class-05 - Variable syntax checked ; by routine. .DEFW L2382 ; Address: 02382h; Address: DRAW ;; P-COPY L1AD6: .DEFB 00h ; Class-00 - No further operands. .DEFW L0EAC ; Address: 00EACh; Address: COPY ;; P-LPRINT L1AD9: .DEFB 005h ; Class-05 - Variable syntax checked entirely ; by routine. .DEFW L1FC9 ; Address: 01FC9h; Address: LPRINT ;; P-LLIST L1ADC: .DEFB 005h ; Class-05 - Variable syntax checked entirely ; by routine. .DEFW L17F5 ; Address: 017F5h; Address: LLIST ;; P-SAVE L1ADF: .DEFB 00Bh ; Class-0B - Offset address converted to tape ; command. ;; P-LOAD L1AE0: .DEFB 00Bh ; Class-0B - Offset address converted to tape ; command. ;; P-VERIFY L1AE1: .DEFB 00Bh ; Class-0B - Offset address converted to tape ; command. ;; P-MERGE L1AE2: .DEFB 00Bh ; Class-0B - Offset address converted to tape ; command. ;; P-BEEP L1AE3: .DEFB 008h ; Class-08 - Two comma-separated numeric ; expressions required. .DEFB 00h ; Class-00 - No further operands. .DEFW L03F8 ; Address: 003F8h; Address: BEEP ;; P-CIRCLE L1AE7: .DEFB 009h ; Class-09 - Two comma-separated numeric ; expressions required with optional colour ; items. .DEFB 005h ; Class-05 - Variable syntax checked ; by routine. .DEFW L2320 ; Address: 02320h; Address: CIRCLE ;; P-INK L1AEB: .DEFB 007h ; Class-07 - Offset address is converted to ; colour code. ;; P-PAPER L1AEC: .DEFB 007h ; Class-07 - Offset address is converted to ; colour code. ;; P-FLASH L1AED: .DEFB 007h ; Class-07 - Offset address is converted to ; colour code. ;; P-BRIGHT L1AEE: .DEFB 007h ; Class-07 - Offset address is converted to ; colour code. ;; P-INVERSE L1AEF: .DEFB 007h ; Class-07 - Offset address is converted to ; colour code. ;; P-OVER L1AF0: .DEFB 007h ; Class-07 - Offset address is converted to ; colour code. ;; P-OUT L1AF1: .DEFB 008h ; Class-08 - Two comma-separated numeric ; expressions required. .DEFB 00h ; Class-00 - No further operands. .DEFW L1E7A ; Address: 01E7Ah; Address: OUT ;; P-BORDER L1AF5: .DEFB 006h ; Class-06 - A numeric expression must follow. .DEFB 00h ; Class-00 - No further operands. .DEFW L2294 ; Address: 02294h; Address: BORDER ;; P-DEF-FN L1AF9: .DEFB 005h ; Class-05 - Variable syntax checked entirely ; by routine. .DEFW L1F60 ; Address: 01F60h; Address: DEF-FN ;; P-OPEN L1AFC: .DEFB 006h ; Class-06 - A numeric expression must follow. .DEFB 02Ch ; Separator: ',' see Footnote * .DEFB 00Ah ; Class-0A - A string expression must follow. .DEFB 00h ; Class-00 - No further operands. .DEFW L1736 ; Address: 01736h; Address: OPEN ;; P-CLOSE L1B02: .DEFB 006h ; Class-06 - A numeric expression must follow. .DEFB 00h ; Class-00 - No further operands. .DEFW L16E5 ; Address: 016E5h; Address: CLOSE ;; P-FORMAT L1B06: .DEFB 00Ah ; Class-0A - A string expression must follow. .DEFB 00h ; Class-00 - No further operands. .DEFW L1793 ; Address: 01793h; Address: CAT-ETC ;; P-MOVE L1B0A: .DEFB 00Ah ; Class-0A - A string expression must follow. .DEFB 02Ch ; Separator: ',' .DEFB 00Ah ; Class-0A - A string expression must follow. .DEFB 00h ; Class-00 - No further operands. .DEFW L1793 ; Address: 01793h; Address: CAT-ETC ;; P-ERASE L1B10: .DEFB 00Ah ; Class-0A - A string expression must follow. .DEFB 00h ; Class-00 - No further operands. .DEFW L1793 ; Address: 01793h; Address: CAT-ETC ;; P-CAT L1B14: .DEFB 00h ; Class-00 - No further operands. .DEFW L1793 ; Address: 01793h; Address: CAT-ETC ; * Note that a comma is required as a separator with the OPEN command ; but the Interface 1 programmers relaxed this allowing ';' as an ; alternative for their channels creating a confusing mixture of ; allowable syntax as it is this ROM which opens or re-opens the ; normal channels. ; ------------------------------- ; Main parser (BASIC interpreter) ; ------------------------------- ; This routine is called once from MAIN-2 when the BASIC line is to ; be entered or re-entered into the Program area and the syntax ; requires checking. ;; LINE-SCAN L1B17: RES 7,(IY+001h) ; update FLAGS - signal checking syntax CALL L19FB ; routine E-LINE-NO >> ; fetches the line number if in range. XOR A ; clear the accumulator. LD (05C47h),A ; set statement number SUBPPC to zero. DEC A ; set accumulator to 0FFh. LD (05C3Ah),A ; set ERR_NR to 'OK' - 1. JR L1B29 ; forward to continue at STMT-L-1. ; -------------- ; Statement loop ; -------------- ; ; ;; STMT-LOOP L1B28: RST 20H ; NEXT-CHAR ; -> the entry point from above or LINE-RUN ;; STMT-L-1 L1B29: CALL L16BF ; routine SET-WORK clears workspace etc. INC (IY+00Dh) ; increment statement number SUBPPC JP M,L1C8A ; to REPORT-C to raise ; 'Nonsense in BASIC' if over 127. RST 18H ; GET-CHAR LD B,00h ; set B to zero for later indexing. ; early so any other reason ??? CP 00Dh ; is character carriage return ? ; i.e. an empty statement. JR Z,L1BB3 ; forward to LINE-END if so. CP 03Ah ; is it statement end marker ':' ? ; i.e. another type of empty statement. JR Z,L1B28 ; back to STMT-LOOP if so. LD HL,L1B76 ; address: STMT-RET PUSH HL ; is now pushed as a return address LD C,A ; transfer the current character to C. ; advance CH_ADD to a position after command and test if it is a command. RST 20H ; NEXT-CHAR to advance pointer LD A,C ; restore current character SUB 0CEh ; subtract 'DEF FN' - first command JP C,L1C8A ; jump to REPORT-C if less than a command ; raising ; 'Nonsense in BASIC' LD C,A ; put the valid command code back in C. ; register B is zero. LD HL,L1A48 ; address: offst-tbl ADD HL,BC ; index into table with one of 50 commands. LD C,(HL) ; pick up displacement to syntax table entry. ADD HL,BC ; add to address the relevant entry. JR L1B55 ; forward to continue at GET-PARAM ; ---------------------- ; The main scanning loop ; ---------------------- ; not documented properly ; ;; SCAN-LOOP L1B52: LD HL,(05C74h) ; fetch temporary address from T_ADDR ; during subsequent loops. ; -> the initial entry point with HL addressing start of syntax table entry. ;; GET-PARAM L1B55: LD A,(HL) ; pick up the parameter. INC HL ; address next one. LD (05C74h),HL ; save pointer in system variable T_ADDR LD BC,L1B52 ; address: SCAN-LOOP PUSH BC ; is now pushed on stack as looping address. LD C,A ; store parameter in C. CP 020h ; is it greater than ' ' ? JR NC,L1B6F ; forward to SEPARATOR to check that correct ; separator appears in statement if so. LD HL,L1C01 ; address: class-tbl. LD B,00h ; prepare to index into the class table. ADD HL,BC ; index to find displacement to routine. LD C,(HL) ; displacement to BC ADD HL,BC ; add to address the CLASS routine. PUSH HL ; push the address on the stack. RST 18H ; GET-CHAR - HL points to place in statement. DEC B ; reset the zero flag - the initial state ; for all class routines. RET ; and make an indirect jump to routine ; and then SCAN-LOOP (also on stack). ; Note. one of the class routines will eventually drop the return address ; off the stack breaking out of the above seemingly endless loop. ; ----------------------- ; THE 'SEPARATOR' ROUTINE ; ----------------------- ; This routine is called once to verify that the mandatory separator ; present in the parameter table is also present in the correct ; location following the command. For example, the 'THEN' token after ; the 'IF' token and expression. ;; SEPARATOR L1B6F: RST 18H ; GET-CHAR CP C ; does it match the character in C ? JP NZ,L1C8A ; jump forward to REPORT-C if not ; 'Nonsense in BASIC'. RST 20H ; NEXT-CHAR advance to next character RET ; return. ; ------------------------------ ; Come here after interpretation ; ------------------------------ ; ; ;; STMT-RET L1B76: CALL L1F54 ; routine BREAK-KEY is tested after every ; statement. JR C,L1B7D ; step forward to STMT-R-1 if not pressed. ;; REPORT-L L1B7B: RST 08H ; ERROR-1 .DEFB 014h ; Error Report: BREAK into program ;; STMT-R-1 L1B7D: BIT 7,(IY+00Ah) ; test NSPPC - will be set if 0FFh - ; no jump to be made. JR NZ,L1BF4 ; forward to STMT-NEXT if a program line. LD HL,(05C42h) ; fetch line number from NEWPPC BIT 7,H ; will be set if minus two - direct command(s) JR Z,L1B9E ; forward to LINE-NEW if a jump is to be ; made to a new program line/statement. ; -------------------- ; Run a direct command ; -------------------- ; A direct command is to be run or, if continuing from above, ; the next statement of a direct command is to be considered. ;; LINE-RUN L1B8A: LD HL,0FFFEh ; The dummy value minus two LD (05C45h),HL ; is set/reset as line number in PPC. LD HL,(05C61h) ; point to end of line + 1 - WORKSP. DEC HL ; now point to 080h end-marker. LD DE,(05C59h) ; address the start of line E_LINE. DEC DE ; now location before - for GET-CHAR. LD A,(05C44h) ; load statement to A from NSPPC. JR L1BD1 ; forward to NEXT-LINE. ; ------------------------------ ; Find start address of new line ; ------------------------------ ; The branch was to here if a jump is to made to a new line number ; and statement. ; That is the previous statement was a GO TO, GO SUB, RUN, RETURN, NEXT etc.. ;; LINE-NEW L1B9E: CALL L196E ; routine LINE-ADDR gets address of line ; returning zero flag set if line found. LD A,(05C44h) ; fetch new statement from NSPPC JR Z,L1BBF ; forward to LINE-USE if line matched. ; continue as must be a direct command. AND A ; test statement which should be zero JR NZ,L1BEC ; forward to REPORT-N if not. ; 'Statement lost' ; LD B,A ; save statement in B.?? LD A,(HL) ; fetch high byte of line number. AND 0C0h ; test if using direct command ; a program line is less than 03Fh LD A,B ; retrieve statement. ; (we can assume it is zero). JR Z,L1BBF ; forward to LINE-USE if was a program line ; Alternatively a direct statement has finished correctly. ;; REPORT-0 L1BB0: RST 08H ; ERROR-1 .DEFB 0FFh ; Error Report: OK ; ----------------- ; THE 'REM' COMMAND ; ----------------- ; The REM command routine. ; The return address STMT-RET is dropped and the rest of line ignored. ;; REM L1BB2: POP BC ; drop return address STMT-RET and ; continue ignoring rest of line. ; ------------ ; End of line? ; ------------ ; ; ;; LINE-END L1BB3: CALL L2530 ; routine SYNTAX-Z (UNSTACK-Z?) RET Z ; return if checking syntax. LD HL,(05C55h) ; fetch NXTLIN to HL. LD A,0C0h ; test against the AND (HL) ; system limit 03Fh. RET NZ ; return if more as must be ; end of program. ; (or direct command) XOR A ; set statement to zero. ; and continue to set up the next following line and then consider this new one. ; --------------------- ; General line checking ; --------------------- ; The branch was here from LINE-NEW if BASIC is branching. ; or a continuation from above if dealing with a new sequential line. ; First make statement zero number one leaving others unaffected. ;; LINE-USE L1BBF: CP 001h ; will set carry if zero. ADC A,00h ; add in any carry. LD D,(HL) ; high byte of line number to D. INC HL ; advance pointer. LD E,(HL) ; low byte of line number to E. LD (05C45h),DE ; set system variable PPC. INC HL ; advance pointer. LD E,(HL) ; low byte of line length to E. INC HL ; advance pointer. LD D,(HL) ; high byte of line length to D. EX DE,HL ; swap pointer to DE before ADD HL,DE ; adding to address the end of line. INC HL ; advance to start of next line. ; ----------------------------- ; Update NEXT LINE but consider ; previous line or edit line. ; ----------------------------- ; The pointer will be the next line if continuing from above or to ; edit line end-marker (080h) if from LINE-RUN. ;; NEXT-LINE L1BD1: LD (05C55h),HL ; store pointer in system variable NXTLIN EX DE,HL ; bring back pointer to previous or edit line LD (05C5Dh),HL ; and update CH_ADD with character address. LD D,A ; store statement in D. LD E,00h ; set E to zero to suppress token searching ; if EACH-STMT is to be called. LD (IY+00Ah),0FFh ; set statement NSPPC to 0FFh signalling ; no jump to be made. DEC D ; decrement and test statement LD (IY+00Dh),D ; set SUBPPC to decremented statement number. JP Z,L1B28 ; to STMT-LOOP if result zero as statement is ; at start of line and address is known. INC D ; else restore statement. CALL L198B ; routine EACH-STMT finds the D'th statement ; address as E does not contain a token. JR Z,L1BF4 ; forward to STMT-NEXT if address found. ;; REPORT-N L1BEC: RST 08H ; ERROR-1 .DEFB 016h ; Error Report: Statement lost ; ----------------- ; End of statement? ; ----------------- ; This combination of routines is called from 20 places when ; the end of a statement should have been reached and all preceding ; syntax is in order. ;; CHECK-END L1BEE: CALL L2530 ; routine SYNTAX-Z RET NZ ; return immediately in runtime POP BC ; drop address of calling routine. POP BC ; drop address STMT-RET. ; and continue to find next statement. ; -------------------- ; Go to next statement ; -------------------- ; Acceptable characters at this point are carriage return and ':'. ; If so go to next statement which in the first case will be on next line. ;; STMT-NEXT L1BF4: RST 18H ; GET-CHAR - ignoring white space etc. CP 00Dh ; is it carriage return ? JR Z,L1BB3 ; back to LINE-END if so. CP 03Ah ; is it ':' ? JP Z,L1B28 ; jump back to STMT-LOOP to consider ; further statements JP L1C8A ; jump to REPORT-C with any other character ; 'Nonsense in BASIC'. ; Note. the two-byte sequence 'rst 08; defb $0b' could replace the above jp. ; ------------------- ; Command class table ; ------------------- ; ;; class-tbl L1C01: .DEFB 00Fh ;L1C10 - $ ; 0F offset to Address: CLASS-00 .DEFB 01Dh ;L1C1F - $ ; 1D offset to Address: CLASS-01 .DEFB 04Bh ;L1C4E - $ ; 4B offset to Address: CLASS-02 .DEFB 009h ;L1C0D - $ ; 09 offset to Address: CLASS-03 .DEFB 067h ;L1C6C - $ ; 67 offset to Address: CLASS-04 .DEFB 00Bh ;L1C11 - $ ; 0B offset to Address: CLASS-05 .DEFB 07Bh ;L1C82 - $ ; 7B offset to Address: CLASS-06 .DEFB 08Eh ;L1C96 - $ ; 8E offset to Address: CLASS-07 .DEFB 071h ;L1C7A - $ ; 71 offset to Address: CLASS-08 .DEFB 0B4h ;L1CBE - $ ; B4 offset to Address: CLASS-09 .DEFB 081h ;L1C8C - $ ; 81 offset to Address: CLASS-0A .DEFB 0CFh ;L1CDB - $ ; CF offset to Address: CLASS-0B ; -------------------------------- ; Command classes---00, 03, and 05 ; -------------------------------- ; class-03 e.g. RUN or RUN 200 ; optional operand ; class-00 e.g. CONTINUE ; no operand ; class-05 e.g. PRINT ; variable syntax checked by routine ;; CLASS-03 L1C0D: CALL L1CDE ; routine FETCH-NUM ;; CLASS-00 L1C10: CP A ; reset zero flag. ; if entering here then all class routines are entered with zero reset. ;; CLASS-05 L1C11: POP BC ; drop address SCAN-LOOP. CALL Z,L1BEE ; if zero set then call routine CHECK-END >>> ; as should be no further characters. EX DE,HL ; save HL to DE. LD HL,(05C74h) ; fetch T_ADDR LD C,(HL) ; fetch low byte of routine INC HL ; address next. LD B,(HL) ; fetch high byte of routine. EX DE,HL ; restore HL from DE PUSH BC ; push the address RET ; and make an indirect jump to the command. ; -------------------------------- ; Command classes---01, 02, and 04 ; -------------------------------- ; class-01 e.g. LET A = 2*3 ; a variable is reqd ; This class routine is also called from INPUT and READ to find the ; destination variable for an assignment. ;; CLASS-01 L1C1F: CALL L28B2 ; routine LOOK-VARS returns carry set if not ; found in runtime. ; ---------------------- ; Variable in assignment ; ---------------------- ; ; ;; VAR-A-1 L1C22: LD (IY+037h),00h ; set FLAGX to zero JR NC,L1C30 ; forward to VAR-A-2 if found or checking ; syntax. SET 1,(IY+037h) ; FLAGX - Signal a new variable JR NZ,L1C46 ; to VAR-A-3 if not assigning to an array ; e.g. LET a$(3,3) = "X" ;; REPORT-2 L1C2E: RST 08H ; ERROR-1 .DEFB 001h ; Error Report: Variable not found ;; VAR-A-2 L1C30: CALL Z,L2996 ; routine STK-VAR considers a subscript/slice BIT 6,(IY+001h) ; test FLAGS - Numeric or string result ? JR NZ,L1C46 ; to VAR-A-3 if numeric XOR A ; default to array/slice - to be retained. CALL L2530 ; routine SYNTAX-Z CALL NZ,L2BF1 ; routine STK-FETCH is called in runtime ; may overwrite A with 1. LD HL,05C71h ; address system variable FLAGX OR (HL) ; set bit 0 if simple variable to be reclaimed LD (HL),A ; update FLAGX EX DE,HL ; start of string/subscript to DE ;; VAR-A-3 L1C46: LD (05C72h),BC ; update STRLEN LD (05C4Dh),HL ; and DEST of assigned string. RET ; return. ; ------------------------------------------------- ; class-02 e.g. LET a = 1 + 1 ; an expression must follow ;; CLASS-02 L1C4E: POP BC ; drop return address SCAN-LOOP CALL L1C56 ; routine VAL-FET-1 is called to check ; expression and assign result in runtime CALL L1BEE ; routine CHECK-END checks nothing else ; is present in statement. RET ; Return ; ------------- ; Fetch a value ; ------------- ; ; ;; VAL-FET-1 L1C56: LD A,(05C3Bh) ; initial FLAGS to A ;; VAL-FET-2 L1C59: PUSH AF ; save A briefly CALL L24FB ; routine SCANNING evaluates expression. POP AF ; restore A LD D,(IY+001h) ; post-SCANNING FLAGS to D XOR D ; xor the two sets of flags AND 040h ; pick up bit 6 of xored FLAGS should be zero JR NZ,L1C8A ; forward to REPORT-C if not zero ; 'Nonsense in BASIC' - results don't agree. BIT 7,D ; test FLAGS - is syntax being checked ? JP NZ,L2AFF ; jump forward to LET to make the assignment ; in runtime. RET ; but return from here if checking syntax. ; ------------------ ; Command class---04 ; ------------------ ; class-04 e.g. FOR i ; a single character variable must follow ;; CLASS-04 L1C6C: CALL L28B2 ; routine LOOK-VARS PUSH AF ; preserve flags. LD A,C ; fetch type - should be 011xxxxx OR 09Fh ; combine with 10011111. INC A ; test if now 0FFh by incrementing. JR NZ,L1C8A ; forward to REPORT-C if result not zero. POP AF ; else restore flags. JR L1C22 ; back to VAR-A-1 ; -------------------------------- ; Expect numeric/string expression ; -------------------------------- ; This routine is used to get the two coordinates of STRING$, ATTR and POINT. ; It is also called from PRINT-ITEM to get the two numeric expressions that ; follow the AT ( in PRINT AT, INPUT AT). ;; NEXT-2NUM L1C79: RST 20H ; NEXT-CHAR advance past 'AT' or '('. ; -------- ; class-08 e.g. POKE 65535,2 ; two numeric expressions separated by comma ;; CLASS-08 ;; EXPT-2NUM L1C7A: CALL L1C82 ; routine EXPT-1NUM is called for first ; numeric expression CP 02Ch ; is character ',' ? JR NZ,L1C8A ; to REPORT-C if not required separator. ; 'Nonsense in BASIC'. RST 20H ; NEXT-CHAR ; -> ; class-06 e.g. GOTO a*1000 ; a numeric expression must follow ;; CLASS-06 ;; EXPT-1NUM L1C82: CALL L24FB ; routine SCANNING BIT 6,(IY+001h) ; test FLAGS - Numeric or string result ? RET NZ ; return if result is numeric. ;; REPORT-C L1C8A: RST 08H ; ERROR-1 .DEFB 00Bh ; Error Report: Nonsense in BASIC ; --------------------------------------------------------------- ; class-0A e.g. ERASE "????" ; a string expression must follow. ; ; these only occur in unimplemented commands ; ; although the routine expt-exp is called ; ; from SAVE-ETC ;; CLASS-0A ;; EXPT-EXP L1C8C: CALL L24FB ; routine SCANNING BIT 6,(IY+001h) ; test FLAGS - Numeric or string result ? RET Z ; return if string result. JR L1C8A ; back to REPORT-C if numeric. ; --------------------- ; Set permanent colours ; class 07 ; --------------------- ; class-07 e.g. PAPER 6 ; a single class for a collection of ; ; similar commands. Clever. ; ; Note. these commands should ensure that current channel is 'S' ;; CLASS-07 L1C96: BIT 7,(IY+001h) ; test FLAGS - checking syntax only ? ; Note. there is a subroutine to do this. RES 0,(IY+002h) ; update TV_FLAG - signal main screen in use CALL NZ,L0D4D ; routine TEMPS is called in runtime. POP AF ; drop return address SCAN-LOOP LD A,(05C74h) ; T_ADDR_lo to accumulator. ; points to '007h' entry + 1 ; e.g. for INK points to 0ECh now ; Note if you move alter the syntax table next line may have to be altered. ; Note. For ZASM assembler replace following expression with SUB 013h. L1CA5: SUB 013h ;L1AEB-0D8h % 256 ; convert 0EBh to 0D8h ('INK') etc. ; ( is SUB 013h in standard ROM ) CALL L21FC ; routine CO-TEMP-4 CALL L1BEE ; routine CHECK-END check that nothing else ; in statement. ; return here in runtime. LD HL,(05C8Fh) ; pick up ATTR_T and MASK_T LD (05C8Dh),HL ; and store in ATTR_P and MASK_P LD HL,05C91h ; point to P_FLAG. LD A,(HL) ; pick up in A RLCA ; rotate to left XOR (HL) ; combine with HL AND 0AAh ; 10101010 XOR (HL) ; only permanent bits affected LD (HL),A ; reload into P_FLAG. RET ; return. ; ------------------ ; Command class---09 ; ------------------ ; e.g. PLOT PAPER 0; 128,88 ; two coordinates preceded by optional ; ; embedded colour items. ; ; Note. this command should ensure that current channel is actually 'S'. ;; CLASS-09 L1CBE: CALL L2530 ; routine SYNTAX-Z JR Z,L1CD6 ; forward to CL-09-1 if checking syntax. RES 0,(IY+002h) ; update TV_FLAG - signal main screen in use CALL L0D4D ; routine TEMPS is called. LD HL,05C90h ; point to MASK_T LD A,(HL) ; fetch mask to accumulator. OR 0F8h ; or with 11111000 paper/bright/flash 8 LD (HL),A ; mask back to MASK_T system variable. RES 6,(IY+057h) ; reset P_FLAG - signal NOT PAPER 9 ? RST 18H ; GET-CHAR ;; CL-09-1 L1CD6: CALL L21E2 ; routine CO-TEMP-2 deals with any embedded ; colour items. JR L1C7A ; exit via EXPT-2NUM to check for x,y. ; Note. if either of the numeric expressions contain STR$ then the flag setting ; above will be undone when the channel flags are reset during STR$. ; e.g. ; 10 BORDER 3 : PLOT VAL STR$ 128, VAL STR$ 100 ; credit John Elliott. ; ------------------ ; Command class---0B ; ------------------ ; Again a single class for four commands. ; This command just jumps back to SAVE-ETC to handle the four tape commands. ; The routine itself works out which command has called it by examining the ; address in T_ADDR_lo. Note therefore that the syntax table has to be ; located where these and other sequential command addresses are not split ; over a page boundary. ;; CLASS-0B L1CDB: JP L0605 ; jump way back to SAVE-ETC ; -------------- ; Fetch a number ; -------------- ; This routine is called from CLASS-03 when a command may be followed by ; an optional numeric expression e.g. RUN. If the end of statement has ; been reached then zero is used as the default. ; Also called from LIST-4. ;; FETCH-NUM L1CDE: CP 00Dh ; is character a carriage return ? JR Z,L1CE6 ; forward to USE-ZERO if so CP 03Ah ; is it ':' ? JR NZ,L1C82 ; forward to EXPT-1NUM if not. ; else continue and use zero. ; ---------------- ; Use zero routine ; ---------------- ; This routine is called four times to place the value zero on the ; calculator stack as a default value in runtime. ;; USE-ZERO L1CE6: CALL L2530 ; routine SYNTAX-Z (UNSTACK-Z?) RET Z ; RST 28H ;; FP-CALC .DEFB 0A0h ;;stk-zero ;0. .DEFB 038h ;;end-calc RET ; return. ; ------------------- ; Handle STOP command ; ------------------- ; Command Syntax: STOP ; One of the shortest and least used commands. As with 'OK' not an error. ;; REPORT-9 ;; STOP L1CEE: RST 08H ; ERROR-1 .DEFB 008h ; Error Report: STOP statement ; ----------------- ; Handle IF command ; ----------------- ; e.g. IF score>100 THEN PRINT "You Win" ; The parser has already checked the expression the result of which is on ; the calculator stack. The presence of the 'THEN' separator has also been ; checked and CH-ADD points to the command after THEN. ; ;; IF L1CF0: POP BC ; drop return address - STMT-RET CALL L2530 ; routine SYNTAX-Z JR Z,L1D00 ; forward to IF-1 if checking syntax ; to check syntax of PRINT "You Win" RST 28H ;; FP-CALC score>100 (1=TRUE 0=FALSE) .DEFB 002h ;;delete . .DEFB 038h ;;end-calc EX DE,HL ; make HL point to deleted value CALL L34E9 ; routine TEST-ZERO JP C,L1BB3 ; jump to LINE-END if FALSE (0) ;; IF-1 L1D00: JP L1B29 ; to STMT-L-1, if true (1) to execute command ; after 'THEN' token. ; ------------------ ; Handle FOR command ; ------------------ ; e.g. FOR i = 0 TO 1 STEP 0.1 ; Using the syntax tables, the parser has already checked for a start and ; limit value and also for the intervening separator. ; the two values v,l are on the calculator stack. ; CLASS-04 has also checked the variable and the name is in STRLEN_lo. ; The routine begins by checking for an optional STEP. ;; FOR L1D03: CP 0CDh ; is there a 'STEP' ? JR NZ,L1D10 ; to F-USE-1 if not to use 1 as default. RST 20H ; NEXT-CHAR CALL L1C82 ; routine EXPT-1NUM CALL L1BEE ; routine CHECK-END JR L1D16 ; to F-REORDER ; --- ;; F-USE-1 L1D10: CALL L1BEE ; routine CHECK-END RST 28H ;; FP-CALC v,l. .DEFB 0A1h ;;stk-one v,l,1=s. .DEFB 038h ;;end-calc ;; F-REORDER L1D16: RST 28H ;; FP-CALC v,l,s. .DEFB 0C0h ;;st-mem-0 v,l,s. .DEFB 002h ;;delete v,l. .DEFB 001h ;;exchange l,v. .DEFB 0E0h ;;get-mem-0 l,v,s. .DEFB 001h ;;exchange l,s,v. .DEFB 038h ;;end-calc CALL L2AFF ; routine LET assigns the initial value v to ; the variable altering type if necessary. LD (05C68h),HL ; The system variable MEM is made to point to ; the variable instead of its normal ; location MEMBOT DEC HL ; point to single-character name LD A,(HL) ; fetch name SET 7,(HL) ; set bit 7 at location LD BC,006h ; add six to HL ADD HL,BC ; to address where limit should be. RLCA ; test bit 7 of original name. JR C,L1D34 ; forward to F-L-S if already a FOR/NEXT ; variable LD C,00Dh ; otherwise an additional 13 bytes are needed. ; 5 for each value, two for line number and ; 1 byte for looping statement. CALL L1655 ; routine MAKE-ROOM creates them. INC HL ; make HL address limit. ;; F-L-S L1D34: PUSH HL ; save position. RST 28H ;; FP-CALC l,s. .DEFB 002h ;;delete l. .DEFB 002h ;;delete . .DEFB 038h ;;end-calc ; DE points to STKEND, l. POP HL ; restore variable position EX DE,HL ; swap pointers LD C,00Ah ; ten bytes to move LDIR ; Copy 'deleted' values to variable. LD HL,(05C45h) ; Load with current line number from PPC EX DE,HL ; exchange pointers. LD (HL),E ; save the looping line INC HL ; in the next LD (HL),D ; two locations. LD D,(IY+00Dh) ; fetch statement from SUBPPC system variable. INC D ; increment statement. INC HL ; and pointer LD (HL),D ; and store the looping statement. ; CALL L1DDA ; routine NEXT-LOOP considers an initial RET NC ; iteration. Return to STMT-RET if a loop is ; possible to execute next statement. ; no loop is possible so execution continues after the matching 'NEXT' LD B,(IY+038h) ; get single-character name from STRLEN_lo LD HL,(05C45h) ; get the current line from PPC LD (05C42h),HL ; and store it in NEWPPC LD A,(05C47h) ; fetch current statement from SUBPPC NEG ; Negate as counter decrements from zero ; initially and we are in the middle of a ; line. LD D,A ; Store result in D. LD HL,(05C5Dh) ; get current address from CH_ADD LD E,0F3h ; search will be for token 'NEXT' ;; F-LOOP L1D64: PUSH BC ; save variable name. LD BC,(05C55h) ; fetch NXTLIN CALL L1D86 ; routine LOOK-PROG searches for 'NEXT' token. LD (05C55h),BC ; update NXTLIN POP BC ; and fetch the letter JR C,L1D84 ; forward to REPORT-I if the end of program ; was reached by LOOK-PROG. ; 'FOR without NEXT' RST 20H ; NEXT-CHAR fetches character after NEXT OR 020h ; ensure it is upper-case. CP B ; compare with FOR variable name JR Z,L1D7C ; forward to F-FOUND if it matches. ; but if no match i.e. nested FOR/NEXT loops then continue search. RST 20H ; NEXT-CHAR JR L1D64 ; back to F-LOOP ; --- ;; F-FOUND L1D7C: RST 20H ; NEXT-CHAR LD A,001h ; subtract the negated counter from 1 SUB D ; to give the statement after the NEXT LD (05C44h),A ; set system variable NSPPC RET ; return to STMT-RET to branch to new ; line and statement. -> ; --- ;; REPORT-I L1D84: RST 08H ; ERROR-1 .DEFB 011h ; Error Report: FOR without NEXT ; --------- ; LOOK-PROG ; --------- ; Find DATA, DEF FN or NEXT. ; This routine searches the program area for one of the above three keywords. ; On entry, HL points to start of search area. ; The token is in E, and D holds a statement count, decremented from zero. ;; LOOK-PROG L1D86: LD A,(HL) ; fetch current character CP 03Ah ; is it ':' a statement separator ? JR Z,L1DA3 ; forward to LOOK-P-2 if so. ; The starting point was PROG - 1 or the end of a line. ;; LOOK-P-1 L1D8B: INC HL ; increment pointer to address LD A,(HL) ; the high byte of line number AND 0C0h ; test for program end marker 080h or a ; variable SCF ; Set Carry Flag RET NZ ; return with carry set if at end ; of program. -> LD B,(HL) ; high byte of line number to B INC HL ; LD C,(HL) ; low byte to C. LD (05C42h),BC ; set system variable NEWPPC. INC HL ; LD C,(HL) ; low byte of line length to C. INC HL ; LD B,(HL) ; high byte to B. PUSH HL ; save address ADD HL,BC ; add length to position. LD B,H ; and save result LD C,L ; in BC. POP HL ; restore address. LD D,00h ; initialize statement counter to zero. ;; LOOK-P-2 L1DA3: PUSH BC ; save address of next line CALL L198B ; routine EACH-STMT searches current line. POP BC ; restore address. RET NC ; return if match was found. -> JR L1D8B ; back to LOOK-P-1 for next line. ; ------------------- ; Handle NEXT command ; ------------------- ; e.g. NEXT i ; The parameter tables have already evaluated the presence of a variable ;; NEXT L1DAB: BIT 1,(IY+037h) ; test FLAGX - handling a new variable ? JP NZ,L1C2E ; jump back to REPORT-2 if so ; 'Variable not found' ; now test if found variable is a simple variable uninitialized by a FOR. LD HL,(05C4Dh) ; load address of variable from DEST BIT 7,(HL) ; is it correct type ? JR Z,L1DD8 ; forward to REPORT-1 if not ; 'NEXT without FOR' INC HL ; step past variable name LD (05C68h),HL ; and set MEM to point to three 5-byte values ; value, limit, step. RST 28H ;; FP-CALC add step and re-store .DEFB 0E0h ;;get-mem-0 v. .DEFB 0E2h ;;get-mem-2 v,s. .DEFB 00Fh ;;addition v+s. .DEFB 0C0h ;;st-mem-0 v+s. .DEFB 002h ;;delete . .DEFB 038h ;;end-calc CALL L1DDA ; routine NEXT-LOOP tests against limit. RET C ; return if no more iterations possible. LD HL,(05C68h) ; find start of variable contents from MEM. LD DE,00Fh ; add 3*5 to ADD HL,DE ; address the looping line number LD E,(HL) ; low byte to E INC HL ; LD D,(HL) ; high byte to D INC HL ; address looping statement LD H,(HL) ; and store in H EX DE,HL ; swap registers JP L1E73 ; exit via GO-TO-2 to execute another loop. ; --- ;; REPORT-1 L1DD8: RST 08H ; ERROR-1 .DEFB 00h ; Error Report: NEXT without FOR ; ----------------- ; Perform NEXT loop ; ----------------- ; This routine is called from the FOR command to test for an initial ; iteration and from the NEXT command to test for all subsequent iterations. ; the system variable MEM addresses the variable's contents which, in the ; latter case, have had the step, possibly negative, added to the value. ;; NEXT-LOOP L1DDA: RST 28H ;; FP-CALC .DEFB 0E1h ;;get-mem-1 l. .DEFB 0E0h ;;get-mem-0 l,v. .DEFB 0E2h ;;get-mem-2 l,v,s. .DEFB 036h ;;less-0 l,v,(1/0) negative step ? .DEFB 00h ;;jump-true l,v.(1/0) .DEFB 002h ;;to L1DE2, NEXT-1 if step negative .DEFB 001h ;;exchange v,l. ;; NEXT-1 L1DE2: .DEFB 003h ;;subtract l-v OR v-l. .DEFB 037h ;;greater-0 (1/0) .DEFB 00h ;;jump-true . .DEFB 004h ;;to L1DE9, NEXT-2 if no more iterations. .DEFB 038h ;;end-calc . AND A ; clear carry flag signalling another loop. RET ; return ; --- ;; NEXT-2 L1DE9: .DEFB 038h ;;end-calc . SCF ; set carry flag signalling looping exhausted. RET ; return ; ------------------- ; Handle READ command ; ------------------- ; e.g. READ a, b$, c$(1000 TO 3000) ; A list of comma-separated variables is assigned from a list of ; comma-separated expressions. ; As it moves along the first list, the character address CH_ADD is stored ; in X_PTR while CH_ADD is used to read the second list. ;; READ-3 L1DEC: RST 20H ; NEXT-CHAR ; -> Entry point. ;; READ L1DED: CALL L1C1F ; routine CLASS-01 checks variable. CALL L2530 ; routine SYNTAX-Z JR Z,L1E1E ; forward to READ-2 if checking syntax RST 18H ; GET-CHAR LD (05C5Fh),HL ; save character position in X_PTR. LD HL,(05C57h) ; load HL with Data Address DATADD, which is ; the start of the program or the address ; after the last expression that was read or ; the address of the line number of the ; last RESTORE command. LD A,(HL) ; fetch character CP 02Ch ; is it a comma ? JR Z,L1E0A ; forward to READ-1 if so. ; else all data in this statement has been read so look for next DATA token LD E,0E4h ; token 'DATA' CALL L1D86 ; routine LOOK-PROG JR NC,L1E0A ; forward to READ-1 if DATA found ; else report the error. ;; REPORT-E L1E08: RST 08H ; ERROR-1 .DEFB 00Dh ; Error Report: Out of DATA ;; READ-1 L1E0A: CALL L0077 ; routine TEMP-PTR1 advances updating CH_ADD ; with new DATADD position. CALL L1C56 ; routine VAL-FET-1 assigns value to variable ; checking type match and adjusting CH_ADD. RST 18H ; GET-CHAR fetches adjusted character position LD (05C57h),HL ; store back in DATADD LD HL,(05C5Fh) ; fetch X_PTR the original READ CH_ADD LD (IY+026h),00h ; now nullify X_PTR_hi CALL L0078 ; routine TEMP-PTR2 restores READ CH_ADD ;; READ-2 L1E1E: RST 18H ; GET-CHAR CP 02Ch ; is it ',' indicating more variables to read ? JR Z,L1DEC ; back to READ-3 if so CALL L1BEE ; routine CHECK-END RET ; return from here in runtime to STMT-RET. ; ------------------- ; Handle DATA command ; ------------------- ; In runtime this 'command' is passed by but the syntax is checked when such ; a statement is found while parsing a line. ; e.g. DATA 1, 2, "text", score-1, a$(location, room, object), FN r(49), ; wages - tax, TRUE, The meaning of life ;; DATA L1E27: CALL L2530 ; routine SYNTAX-Z to check status JR NZ,L1E37 ; forward to DATA-2 if in runtime ;; DATA-1 L1E2C: CALL L24FB ; routine SCANNING to check syntax of ; expression CP 02Ch ; is it a comma ? CALL NZ,L1BEE ; routine CHECK-END checks that statement ; is complete. Will make an early exit if ; so. >>> RST 20H ; NEXT-CHAR JR L1E2C ; back to DATA-1 ; --- ;; DATA-2 L1E37: LD A,0E4h ; set token to 'DATA' and continue into ; the PASS-BY routine. ; ---------------------------------- ; Check statement for DATA or DEF FN ; ---------------------------------- ; This routine is used to backtrack to a command token and then ; forward to the next statement in runtime. ;; PASS-BY L1E39: LD B,A ; Give BC enough space to find token. CPDR ; Compare decrement and repeat. (Only use). ; Work backwards till keyword is found which ; is start of statement before any quotes. ; HL points to location before keyword. LD DE,00200h ; count 1+1 statements, dummy value in E to ; inhibit searching for a token. JP L198B ; to EACH-STMT to find next statement ; ----------------------------------------------------------------------- ; A General Note on Invalid Line Numbers. ; ======================================= ; One of the revolutionary concepts of Sinclair BASIC was that it supported ; virtual line numbers. That is the destination of a GO TO, RESTORE etc. need ; not exist. It could be a point before or after an actual line number. ; Zero suffices for a before but the after should logically be infinity. ; Since the maximum actual line limit is 9999 then the system limit, 16383 ; when variables kick in, would serve fine as a virtual end point. ; However, ironically, only the LOAD command gets it right. It will not ; autostart a program that has been saved with a line higher than 16383. ; All the other commands deal with the limit unsatisfactorily. ; LIST, RUN, GO TO, GO SUB and RESTORE have problems and the latter may ; crash the machine when supplied with an inappropriate virtual line number. ; This is puzzling as very careful consideration must have been given to ; this point when the new variable types were allocated their masks and also ; when the routine NEXT-ONE was successfully re-written to reflect this. ; An enigma. ; ------------------------------------------------------------------------- ; ---------------------- ; Handle RESTORE command ; ---------------------- ; The restore command sets the system variable for the data address to ; point to the location before the supplied line number or first line ; thereafter. ; This alters the position where subsequent READ commands look for data. ; Note. If supplied with inappropriate high numbers the system may crash ; in the LINE-ADDR routine as it will pass the program/variables end-marker ; and then lose control of what it is looking for - variable or line number. ; - observation, Steven Vickers, 1984, Pitman. ;; RESTORE L1E42: CALL L1E99 ; routine FIND-INT2 puts integer in BC. ; Note. B should be checked against limit 03Fh ; and an error generated if higher. ; this entry point is used from RUN command with BC holding zero ;; REST-RUN L1E45: LD H,B ; transfer the line LD L,C ; number to the HL register. CALL L196E ; routine LINE-ADDR to fetch the address. DEC HL ; point to the location before the line. LD (05C57h),HL ; update system variable DATADD. RET ; return to STMT-RET (or RUN) ; ------------------------ ; Handle RANDOMIZE command ; ------------------------ ; This command sets the SEED for the RND function to a fixed value. ; With the parameter zero, a random start point is used depending on ; how long the computer has been switched on. ;; RANDOMIZE L1E4F: CALL L1E99 ; routine FIND-INT2 puts parameter in BC. LD A,B ; test this OR C ; for zero. JR NZ,L1E5A ; forward to RAND-1 if not zero. LD BC,(05C78h) ; use the lower two bytes at FRAMES1. ;; RAND-1 L1E5A: LD (05C76h),BC ; place in SEED system variable. RET ; return to STMT-RET ; ----------------------- ; Handle CONTINUE command ; ----------------------- ; The CONTINUE command transfers the OLD (but incremented) values of ; line number and statement to the equivalent "NEW VALUE" system variables ; by using the last part of GO TO and exits indirectly to STMT-RET. ;; CONTINUE L1E5F: LD HL,(05C6Eh) ; fetch OLDPPC line number. LD D,(IY+036h) ; fetch OSPPC statement. JR L1E73 ; forward to GO-TO-2 ; -------------------- ; Handle GO TO command ; -------------------- ; The GO TO command routine is also called by GO SUB and RUN routines ; to evaluate the parameters of both commands. ; It updates the system variables used to fetch the next line/statement. ; It is at STMT-RET that the actual change in control takes place. ; Unlike some BASICs the line number need not exist. ; Note. the high byte of the line number is incorrectly compared with 0F0h ; instead of 03Fh. This leads to commands with operands greater than 32767 ; being considered as having been run from the editing area and the ; error report 'Statement Lost' is given instead of 'OK'. ; - Steven Vickers, 1984. ;; GO-TO L1E67: CALL L1E99 ; routine FIND-INT2 puts operand in BC LD H,B ; transfer line LD L,C ; number to HL. LD D,00h ; set statement to 0 - first. LD A,H ; compare high byte only CP 0F0h ; to 0F0h i.e. 61439 in full. JR NC,L1E9F ; forward to REPORT-B if above. ; This call entry point is used to update the system variables e.g. by RETURN. ;; GO-TO-2 L1E73: LD (05C42h),HL ; save line number in NEWPPC LD (IY+00Ah),D ; and statement in NSPPC RET ; to STMT-RET (or GO-SUB command) ; ------------------ ; Handle OUT command ; ------------------ ; Syntax has been checked and the two comma-separated values are on the ; calculator stack. ;; OUT L1E7A: CALL L1E85 ; routine TWO-PARAM fetches values ; to BC and A. OUT (C),A ; perform the operation. RET ; return to STMT-RET. ; ------------------- ; Handle POKE command ; ------------------- ; This routine alters a single byte in the 64K address space. ; Happily no check is made as to whether ROM or RAM is addressed. ; Sinclair BASIC requires no poking of system variables. ;; POKE L1E80: CALL L1E85 ; routine TWO-PARAM fetches values ; to BC and A. LD (BC),A ; load memory location with A. RET ; return to STMT-RET. ; ------------------------------------ ; Fetch two parameters from calculator stack ; ------------------------------------ ; This routine fetches a byte and word from the calculator stack ; producing an error if either is out of range. ;; TWO-PARAM L1E85: CALL L2DD5 ; routine FP-TO-A JR C,L1E9F ; forward to REPORT-B if overflow occurred JR Z,L1E8E ; forward to TWO-P-1 if positive NEG ; negative numbers are made positive ;; TWO-P-1 L1E8E: PUSH AF ; save the value CALL L1E99 ; routine FIND-INT2 gets integer to BC POP AF ; restore the value RET ; return ; ------------- ; Find integers ; ------------- ; The first of these routines fetches a 8-bit integer (range 0-255) from the ; calculator stack to the accumulator and is used for colours, streams, ; durations and coordinates. ; The second routine fetches 16-bit integers to the BC register pair ; and is used to fetch command and function arguments involving line numbers ; or memory addresses and also array subscripts and tab arguments. ; -> ;; FIND-INT1 L1E94: CALL L2DD5 ; routine FP-TO-A JR L1E9C ; forward to FIND-I-1 for common exit routine. ; --- ; -> ;; FIND-INT2 L1E99: CALL L2DA2 ; routine FP-TO-BC ;; FIND-I-1 L1E9C: JR C,L1E9F ; to REPORT-Bb with overflow. RET Z ; return if positive. ;; REPORT-Bb L1E9F: RST 08H ; ERROR-1 .DEFB 00Ah ; Error Report: Integer out of range ; ------------------ ; Handle RUN command ; ------------------ ; This command runs a program starting at an optional line. ; It performs a 'RESTORE 0' then CLEAR ;; RUN L1EA1: CALL L1E67 ; routine GO-TO puts line number in ; system variables. LD BC,000h ; prepare to set DATADD to first line. CALL L1E45 ; routine REST-RUN does the 'restore'. ; Note BC still holds zero. JR L1EAF ; forward to CLEAR-RUN to clear variables ; without disturbing RAMTOP and ; exit indirectly to STMT-RET ; -------------------- ; Handle CLEAR command ; -------------------- ; This command reclaims the space used by the variables. ; It also clears the screen and the GO SUB stack. ; With an integer expression, it sets the uppermost memory ; address within the BASIC system. ; "Contrary to the manual, CLEAR doesn't execute a RESTORE" - ; Steven Vickers, Pitman Pocket Guide to the Spectrum, 1984. ;; CLEAR L1EAC: CALL L1E99 ; routine FIND-INT2 fetches to BC. ;; CLEAR-RUN L1EAF: LD A,B ; test for OR C ; zero. JR NZ,L1EB7 ; skip to CLEAR-1 if not zero. LD BC,(05CB2h) ; use the existing value of RAMTOP if zero. ;; CLEAR-1 L1EB7: PUSH BC ; save ramtop value. LD DE,(05C4Bh) ; fetch VARS LD HL,(05C59h) ; fetch E_LINE DEC HL ; adjust to point at variables end-marker. CALL L19E5 ; routine RECLAIM-1 reclaims the space used by ; the variables. CALL L0D6B ; routine CLS to clear screen. LD HL,(05C65h) ; fetch STKEND the start of free memory. LD DE,032h ; allow for another 50 bytes. ADD HL,DE ; add the overhead to HL. POP DE ; restore the ramtop value. SBC HL,DE ; if HL is greater than the value then jump JR NC,L1EDA ; forward to REPORT-M ; 'RAMTOP no good' LD HL,(05CB4h) ; now P-RAMT (07FFFh on 16K RAM machine) AND A ; exact this time. SBC HL,DE ; new ramtop must be lower or the same. JR NC,L1EDC ; skip to CLEAR-2 if in actual RAM. ;; REPORT-M L1EDA: RST 08H ; ERROR-1 .DEFB 015h ; Error Report: RAMTOP no good ;; CLEAR-2 L1EDC: EX DE,HL ; transfer ramtop value to HL. LD (05CB2h),HL ; update system variable RAMTOP. POP DE ; pop the return address STMT-RET. POP BC ; pop the Error Address. LD (HL),03Eh ; now put the GO SUB end-marker at RAMTOP. DEC HL ; leave a location beneath it. LD SP,HL ; initialize the machine stack pointer. PUSH BC ; push the error address. LD (05C3Dh),SP ; make ERR_SP point to location. EX DE,HL ; put STMT-RET in HL. JP (HL) ; and go there directly. ; --------------------- ; Handle GO SUB command ; --------------------- ; The GO SUB command diverts BASIC control to a new line number ; in a very similar manner to GO TO but ; the current line number and current statement + 1 ; are placed on the GO SUB stack as a RETURN point. ;; GO-SUB L1EED: POP DE ; drop the address STMT-RET LD H,(IY+00Dh) ; fetch statement from SUBPPC and INC H ; increment it EX (SP),HL ; swap - error address to HL, ; H (statement) at top of stack, ; L (unimportant) beneath. INC SP ; adjust to overwrite unimportant byte LD BC,(05C45h) ; fetch the current line number from PPC PUSH BC ; and PUSH onto GO SUB stack. ; the empty machine-stack can be rebuilt PUSH HL ; push the error address. LD (05C3Dh),SP ; make system variable ERR_SP point to it. PUSH DE ; push the address STMT-RET. CALL L1E67 ; call routine GO-TO to update the system ; variables NEWPPC and NSPPC. ; then make an indirect exit to STMT-RET via LD BC,014h ; a 20-byte overhead memory check. ; ---------------------- ; Check available memory ; ---------------------- ; This routine is used on many occasions when extending a dynamic area ; upwards or the GO SUB stack downwards. ;; TEST-ROOM L1F05: LD HL,(05C65h) ; fetch STKEND ADD HL,BC ; add the supplied test value JR C,L1F15 ; forward to REPORT-4 if over 0FFFFh EX DE,HL ; was less so transfer to DE LD HL,050h ; test against another 80 bytes ADD HL,DE ; anyway JR C,L1F15 ; forward to REPORT-4 if this passes 0FFFFh SBC HL,SP ; if less than the machine stack pointer RET C ; then return - OK. ;; REPORT-4 L1F15: LD L,003h ; prepare 'Out of Memory' JP L0055 ; jump back to ERROR-3 at 055h ; Note. this error can't be trapped at 008h ; ------------------------------ ; THE 'FREE MEMORY' USER ROUTINE ; ------------------------------ ; This routine is not used by the ROM but allows users to evaluate ; approximate free memory with PRINT 65536 - USR 7962. ;; free-mem L1F1A: LD BC,000h ; allow no overhead. CALL L1F05 ; routine TEST-ROOM. LD B,H ; transfer the result LD C,L ; to the BC register. RET ; the USR function returns value of BC. ; -------------------- ; THE 'RETURN' COMMAND ; -------------------- ; As with any command, there are two values on the machine stack at the time ; it is invoked. The machine stack is below the GOSUB stack. Both grow ; downwards, the machine stack by two bytes, the GOSUB stack by 3 bytes. ; The highest location is a statement byte followed by a two-byte line number. ;; RETURN L1F23: POP BC ; drop the address STMT-RET. POP HL ; now the error address. POP DE ; now a possible BASIC return line. LD A,D ; the high byte 00h - 027h is CP 03Eh ; compared with the traditional end-marker 03Eh. JR Z,L1F36 ; forward to REPORT-7 with a match. ; 'RETURN without GOSUB' ; It was not the end-marker so a single statement byte remains at the base of ; the calculator stack. It can't be popped off. DEC SP ; adjust stack pointer to create room for two ; bytes. EX (SP),HL ; statement to H, error address to base of ; new machine stack. EX DE,HL ; statement to D, BASIC line number to HL. LD (05C3Dh),SP ; adjust ERR_SP to point to new stack pointer PUSH BC ; now re-stack the address STMT-RET JP L1E73 ; to GO-TO-2 to update statement and line ; system variables and exit indirectly to the ; address just pushed on stack. ; --- ;; REPORT-7 L1F36: PUSH DE ; replace the end-marker. PUSH HL ; now restore the error address ; as will be required in a few clock cycles. RST 08H ; ERROR-1 .DEFB 006h ; Error Report: RETURN without GOSUB ; -------------------- ; Handle PAUSE command ; -------------------- ; The pause command takes as its parameter the number of interrupts ; for which to wait. PAUSE 50 pauses for about a second. ; PAUSE 0 pauses indefinitely. ; Both forms can be finished by pressing a key. ;; PAUSE L1F3A: CALL L1E99 ; routine FIND-INT2 puts value in BC ;; PAUSE-1 L1F3D: HALT ; wait for interrupt. DEC BC ; decrease counter. LD A,B ; test if OR C ; result is zero. JR Z,L1F4F ; forward to PAUSE-END if so. LD A,B ; test if AND C ; now 0FFFFh INC A ; that is, initially zero. JR NZ,L1F49 ; skip forward to PAUSE-2 if not. INC BC ; restore counter to zero. ;; PAUSE-2 L1F49: BIT 5,(IY+001h) ; test FLAGS - has a new key been pressed ? JR Z,L1F3D ; back to PAUSE-1 if not. ;; PAUSE-END L1F4F: RES 5,(IY+001h) ; update FLAGS - signal no new key RET ; and return. ; ------------------- ; Check for BREAK key ; ------------------- ; This routine is called from COPY-LINE, when interrupts are disabled, ; to test if BREAK (SHIFT - SPACE) is being pressed. ; It is also called at STMT-RET after every statement. ;; BREAK-KEY L1F54: LD A,07Fh ; Input address: 07FFEh IN A,(0FEh) ; read lower right keys RRA ; rotate bit 0 - SPACE RET C ; return if not reset LD A,0FEh ; Input address: 0FEFEh IN A,(0FEh) ; read lower left keys RRA ; rotate bit 0 - SHIFT RET ; carry will be set if not pressed. ; return with no carry if both keys ; pressed. ; --------------------- ; Handle DEF FN command ; --------------------- ; e.g. DEF FN r$(a$,a) = a$(a TO ) ; this 'command' is ignored in runtime but has its syntax checked ; during line-entry. ;; DEF-FN L1F60: CALL L2530 ; routine SYNTAX-Z JR Z,L1F6A ; forward to DEF-FN-1 if parsing LD A,0CEh ; else load A with 'DEF FN' and JP L1E39 ; jump back to PASS-BY ; --- ; continue here if checking syntax. ;; DEF-FN-1 L1F6A: SET 6,(IY+001h) ; set FLAGS - Assume numeric result CALL L2C8D ; call routine ALPHA JR NC,L1F89 ; if not then to DEF-FN-4 to jump to ; 'Nonsense in BASIC' RST 20H ; NEXT-CHAR CP 024h ; is it '$' ? JR NZ,L1F7D ; to DEF-FN-2 if not as numeric. RES 6,(IY+001h) ; set FLAGS - Signal string result RST 20H ; get NEXT-CHAR ;; DEF-FN-2 L1F7D: CP 028h ; is it '(' ? JR NZ,L1FBD ; to DEF-FN-7 'Nonsense in BASIC' RST 20H ; NEXT-CHAR CP 029h ; is it ')' ? JR Z,L1FA6 ; to DEF-FN-6 if null argument ;; DEF-FN-3 L1F86: CALL L2C8D ; routine ALPHA checks that it is the expected ; alphabetic character. ;; DEF-FN-4 L1F89: JP NC,L1C8A ; to REPORT-C if not ; 'Nonsense in BASIC'. EX DE,HL ; save pointer in DE RST 20H ; NEXT-CHAR re-initializes HL from CH_ADD ; and advances. CP 024h ; '$' ? is it a string argument. JR NZ,L1F94 ; forward to DEF-FN-5 if not. EX DE,HL ; save pointer to '$' in DE RST 20H ; NEXT-CHAR re-initializes HL and advances ;; DEF-FN-5 L1F94: EX DE,HL ; bring back pointer. LD BC,006h ; the function requires six hidden bytes for ; each parameter passed. ; The first byte will be 00Eh ; then 5-byte numeric value ; or 5-byte string pointer. CALL L1655 ; routine MAKE-ROOM creates space in program ; area. INC HL ; adjust HL (set by LDDR) INC HL ; to point to first location. LD (HL),00Eh ; insert the 'hidden' marker. ; Note. these invisible storage locations hold nothing meaningful for the ; moment. They will be used every time the corresponding function is ; evaluated in runtime. ; Now consider the following character fetched earlier. CP 02Ch ; is it ',' ? (more than one parameter) JR NZ,L1FA6 ; to DEF-FN-6 if not RST 20H ; else NEXT-CHAR JR L1F86 ; and back to DEF-FN-3 ; --- ;; DEF-FN-6 L1FA6: CP 029h ; should close with a ')' JR NZ,L1FBD ; to DEF-FN-7 if not ; 'Nonsense in BASIC' RST 20H ; get NEXT-CHAR CP 03Dh ; is it '=' ? JR NZ,L1FBD ; to DEF-FN-7 if not 'Nonsense...' RST 20H ; address NEXT-CHAR LD A,(05C3Bh) ; get FLAGS which has been set above PUSH AF ; and preserve CALL L24FB ; routine SCANNING checks syntax of expression ; and also sets flags. POP AF ; restore previous flags XOR (IY+001h) ; xor with FLAGS - bit 6 should be same ; therefore will be reset. AND 040h ; isolate bit 6. ;; DEF-FN-7 L1FBD: JP NZ,L1C8A ; jump back to REPORT-C if the expected result ; is not the same type. ; 'Nonsense in BASIC' CALL L1BEE ; routine CHECK-END will return early if ; at end of statement and move onto next ; else produce error report. >>> ; There will be no return to here. ; ------------------------------- ; Returning early from subroutine ; ------------------------------- ; All routines are capable of being run in two modes - syntax checking mode ; and runtime mode. This routine is called often to allow a routine to return ; early if checking syntax. ;; UNSTACK-Z L1FC3: CALL L2530 ; routine SYNTAX-Z sets zero flag if syntax ; is being checked. POP HL ; drop the return address. RET Z ; return to previous call in chain if checking ; syntax. JP (HL) ; jump to return address as BASIC program is ; actually running. ; --------------------- ; Handle LPRINT command ; --------------------- ; A simple form of 'PRINT #3' although it can output to 16 streams. ; Probably for compatibility with other BASICs particularly ZX81 BASIC. ; An extra UDG might have been better. ;; LPRINT L1FC9: LD A,003h ; the printer channel JR L1FCF ; forward to PRINT-1 ; --------------------- ; Handle PRINT commands ; --------------------- ; The Spectrum's main stream output command. ; The default stream is stream 2 which is normally the upper screen ; of the computer. However the stream can be altered in range 0 - 15. ;; PRINT L1FCD: LD A,002h ; the stream for the upper screen. ; The LPRINT command joins here. ;; PRINT-1 L1FCF: CALL L2530 ; routine SYNTAX-Z checks if program running CALL NZ,L1601 ; routine CHAN-OPEN if so CALL L0D4D ; routine TEMPS sets temporary colours. CALL L1FDF ; routine PRINT-2 - the actual item CALL L1BEE ; routine CHECK-END gives error if not at end ; of statement RET ; and return >>> ; ------------------------------------ ; this subroutine is called from above ; and also from INPUT. ;; PRINT-2 L1FDF: RST 18H ; GET-CHAR gets printable character CALL L2045 ; routine PR-END-Z checks if more printing JR Z,L1FF2 ; to PRINT-4 if not e.g. just 'PRINT :' ; This tight loop deals with combinations of positional controls and ; print items. An early return can be made from within the loop ; if the end of a print sequence is reached. ;; PRINT-3 L1FE5: CALL L204E ; routine PR-POSN-1 returns zero if more ; but returns early at this point if ; at end of statement! ; JR Z,L1FE5 ; to PRINT-3 if consecutive positioners CALL L1FFC ; routine PR-ITEM-1 deals with strings etc. CALL L204E ; routine PR-POSN-1 for more position codes JR Z,L1FE5 ; loop back to PRINT-3 if so ;; PRINT-4 L1FF2: CP 029h ; return now if this is ')' from input-item. ; (see INPUT.) RET Z ; or continue and print carriage return in ; runtime ; --------------------- ; Print carriage return ; --------------------- ; This routine which continues from above prints a carriage return ; in run-time. It is also called once from PRINT-POSN. ;; PRINT-CR L1FF5: CALL L1FC3 ; routine UNSTACK-Z LD A,00Dh ; prepare a carriage return RST 10H ; PRINT-A RET ; return ; ----------- ; Print items ; ----------- ; This routine deals with print items as in ; PRINT AT 10,0;"The value of A is ";a ; It returns once a single item has been dealt with as it is part ; of a tight loop that considers sequences of positional and print items ;; PR-ITEM-1 L1FFC: RST 18H ; GET-CHAR CP 0ACh ; is character 'AT' ? JR NZ,L200E ; forward to PR-ITEM-2 if not. CALL L1C79 ; routine NEXT-2NUM check for two comma ; separated numbers placing them on the ; calculator stack in runtime. CALL L1FC3 ; routine UNSTACK-Z quits if checking syntax. CALL L2307 ; routine STK-TO-BC get the numbers in B and C. LD A,016h ; prepare the 'at' control. JR L201E ; forward to PR-AT-TAB to print the sequence. ; --- ;; PR-ITEM-2 L200E: CP 0ADh ; is character 'TAB' ? JR NZ,L2024 ; to PR-ITEM-3 if not RST 20H ; NEXT-CHAR to address next character CALL L1C82 ; routine EXPT-1NUM CALL L1FC3 ; routine UNSTACK-Z quits if checking syntax. CALL L1E99 ; routine FIND-INT2 puts integer in BC. LD A,017h ; prepare the 'tab' control. ;; PR-AT-TAB L201E: RST 10H ; PRINT-A outputs the control LD A,C ; first value to A RST 10H ; PRINT-A outputs it. LD A,B ; second value RST 10H ; PRINT-A RET ; return - item finished >>> ; --- ; Now consider paper 2; #2; a$ ;; PR-ITEM-3 L2024: CALL L21F2 ; routine CO-TEMP-3 will print any colour RET NC ; items - return if success. CALL L2070 ; routine STR-ALTER considers new stream RET NC ; return if altered. CALL L24FB ; routine SCANNING now to evaluate expression CALL L1FC3 ; routine UNSTACK-Z if not runtime. BIT 6,(IY+001h) ; test FLAGS - Numeric or string result ? CALL Z,L2BF1 ; routine STK-FETCH if string. ; note no flags affected. JP NZ,L2DE3 ; to PRINT-FP to print if numeric >>> ; It was a string expression - start in DE, length in BC ; Now enter a loop to print it ;; PR-STRING L203C: LD A,B ; this tests if the OR C ; length is zero and sets flag accordingly. DEC BC ; this doesn't but decrements counter. RET Z ; return if zero. LD A,(DE) ; fetch character. INC DE ; address next location. RST 10H ; PRINT-A. JR L203C ; loop back to PR-STRING. ; --------------- ; End of printing ; --------------- ; This subroutine returns zero if no further printing is required ; in the current statement. ; The first terminator is found in escaped input items only, ; the others in print_items. ;; PR-END-Z L2045: CP 029h ; is character a ')' ? RET Z ; return if so - e.g. INPUT (p$); a$ ;; PR-ST-END L2048: CP 00Dh ; is it a carriage return ? RET Z ; return also - e.g. PRINT a CP 03Ah ; is character a ':' ? RET ; return - zero flag will be set if so. ; e.g. PRINT a : ; -------------- ; Print position ; -------------- ; This routine considers a single positional character ';', ',', ''' ;; PR-POSN-1 L204E: RST 18H ; GET-CHAR CP 03Bh ; is it ';' ? ; i.e. print from last position. JR Z,L2067 ; forward to PR-POSN-3 if so. ; i.e. do nothing. CP 02Ch ; is it ',' ? ; i.e. print at next tabstop. JR NZ,L2061 ; forward to PR-POSN-2 if anything else. CALL L2530 ; routine SYNTAX-Z JR Z,L2067 ; forward to PR-POSN-3 if checking syntax. LD A,006h ; prepare the 'comma' control character. RST 10H ; PRINT-A outputs to current channel in ; run-time. JR L2067 ; skip to PR-POSN-3. ; --- ; check for newline. ;; PR-POSN-2 L2061: CP 027h ; is character a "'" ? (newline) RET NZ ; return if no match >>> CALL L1FF5 ; routine PRINT-CR outputs a carriage return ; in runtime only. ;; PR-POSN-3 L2067: RST 20H ; NEXT-CHAR to A. CALL L2045 ; routine PR-END-Z checks if at end. JR NZ,L206E ; to PR-POSN-4 if not. POP BC ; drop return address if at end. ;; PR-POSN-4 L206E: CP A ; reset the zero flag. RET ; and return to loop or quit. ; ------------ ; Alter stream ; ------------ ; This routine is called from PRINT ITEMS above, and also LIST as in ; LIST #15 ;; STR-ALTER L2070: CP 023h ; is character '#' ? SCF ; set carry flag. RET NZ ; return if no match. RST 20H ; NEXT-CHAR CALL L1C82 ; routine EXPT-1NUM gets stream number AND A ; prepare to exit early with carry reset CALL L1FC3 ; routine UNSTACK-Z exits early if parsing CALL L1E94 ; routine FIND-INT1 gets number off stack CP 010h ; must be range 0 - 15 decimal. JP NC,L160E ; jump back to REPORT-Oa if not ; 'Invalid stream'. CALL L1601 ; routine CHAN-OPEN AND A ; clear carry - signal item dealt with. RET ; return ; ------------------- ; THE 'INPUT' COMMAND ; ------------------- ; This command is mysterious. ; ;; INPUT L2089: CALL L2530 ; routine SYNTAX-Z to check if in runtime. JR Z,L2096 ; forward to INPUT-1 if checking syntax. LD A,001h ; select channel 'K' the keyboard for input. CALL L1601 ; routine CHAN-OPEN opens the channel and sets ; bit 0 of TV_FLAG. ; Note. As a consequence of clearing the lower screen channel 0 is made ; the current channel so the above two instructions are superfluous. CALL L0D6E ; routine CLS-LOWER clears the lower screen ; and sets DF_SZ to two and TV_FLAG to 001h. ;; INPUT-1 L2096: LD (IY+002h),001h ; update TV_FLAG - signal lower screen in use ; ensuring that the correct set of system ; variables are updated and that the border ; colour is used. ; Note. The Complete Spectrum ROM Disassembly incorrectly names DF-SZ as the ; system variable that is updated above and if, as some have done, you make ; this unnecessary alteration then there will be two blank lines between the ; lower screen and the upper screen areas which will also scroll wrongly. CALL L20C1 ; routine IN-ITEM-1 to handle the input. CALL L1BEE ; routine CHECK-END will make an early exit ; if checking syntax. >>> ; Keyboard input has been made and it remains to adjust the upper ; screen in case the lower two lines have been extended upwards. LD BC,(05C88h) ; fetch S_POSN current line/column of ; the upper screen. LD A,(05C6Bh) ; fetch DF_SZ the display file size of ; the lower screen. CP B ; test that lower screen does not overlap JR C,L20AD ; forward to INPUT-2 if not. ; the two screens overlap so adjust upper screen. LD C,021h ; set column of upper screen to leftmost. LD B,A ; and line to one above lower screen. ; continue forward to update upper screen ; print position. ;; INPUT-2 L20AD: LD (05C88h),BC ; set S_POSN update upper screen line/column. LD A,019h ; subtract from twenty five SUB B ; the new line number. LD (05C8Ch),A ; and place result in SCR_CT - scroll count. RES 0,(IY+002h) ; update TV_FLAG - signal main screen in use. CALL L0DD9 ; routine CL-SET sets the print position ; system variables for the upper screen. JP L0D6E ; jump back to CLS-LOWER and make ; an indirect exit >>. ; --------------------- ; INPUT ITEM subroutine ; --------------------- ; This subroutine deals with the input items and print items. ; from the current input channel. ; It is only called from the above INPUT routine but was obviously ; once called from somewhere else in another context. ;; IN-ITEM-1 L20C1: CALL L204E ; routine PR-POSN-1 deals with a single ; position item at each call. JR Z,L20C1 ; back to IN-ITEM-1 until no more in a ; sequence. CP 028h ; is character '(' ? JR NZ,L20D8 ; forward to IN-ITEM-2 if not. ; any variables within braces will be treated as part, or all, of the prompt ; instead of being used as destination variables. RST 20H ; NEXT-CHAR CALL L1FDF ; routine PRINT-2 to output the dynamic ; prompt. RST 18H ; GET-CHAR CP 029h ; is character a matching ')' ? JP NZ,L1C8A ; jump back to REPORT-C if not. ; 'Nonsense in BASIC'. RST 20H ; NEXT-CHAR JP L21B2 ; forward to IN-NEXT-2 ; --- ;; IN-ITEM-2 L20D8: CP 0CAh ; is the character the token 'LINE' ? JR NZ,L20ED ; forward to IN-ITEM-3 if not. RST 20H ; NEXT-CHAR - variable must come next. CALL L1C1F ; routine CLASS-01 returns destination ; address of variable to be assigned. ; or generates an error if no variable ; at this position. SET 7,(IY+037h) ; update FLAGX - signal handling INPUT LINE BIT 6,(IY+001h) ; test FLAGS - numeric or string result ? JP NZ,L1C8A ; jump back to REPORT-C if not string ; 'Nonsense in BASIC'. JR L20FA ; forward to IN-PROMPT to set up workspace. ; --- ; the jump was here for other variables. ;; IN-ITEM-3 L20ED: CALL L2C8D ; routine ALPHA checks if character is ; a suitable variable name. JP NC,L21AF ; forward to IN-NEXT-1 if not CALL L1C1F ; routine CLASS-01 returns destination ; address of variable to be assigned. RES 7,(IY+037h) ; update FLAGX - signal not INPUT LINE. ;; IN-PROMPT L20FA: CALL L2530 ; routine SYNTAX-Z JP Z,L21B2 ; forward to IN-NEXT-2 if checking syntax. CALL L16BF ; routine SET-WORK clears workspace. LD HL,05C71h ; point to system variable FLAGX RES 6,(HL) ; signal string result. SET 5,(HL) ; signal in Input Mode for editor. LD BC,001h ; initialize space required to one for ; the carriage return. BIT 7,(HL) ; test FLAGX - INPUT LINE in use ? JR NZ,L211C ; forward to IN-PR-2 if so as that is ; all the space that is required. LD A,(05C3Bh) ; load accumulator from FLAGS AND 040h ; mask to test BIT 6 of FLAGS and clear ; the other bits in A. ; numeric result expected ? JR NZ,L211A ; forward to IN-PR-1 if so LD C,003h ; increase space to three bytes for the ; pair of surrounding quotes. ;; IN-PR-1 L211A: OR (HL) ; if numeric result, set bit 6 of FLAGX. LD (HL),A ; and update system variable ;; IN-PR-2 L211C: RST 30H ; BC-SPACES opens 1 or 3 bytes in workspace LD (HL),00Dh ; insert carriage return at last new location. LD A,C ; fetch the length, one or three. RRCA ; lose bit 0. RRCA ; test if quotes required. JR NC,L2129 ; forward to IN-PR-3 if not. LD A,022h ; load the '"' character LD (DE),A ; place quote in first new location at DE. DEC HL ; decrease HL - from carriage return. LD (HL),A ; and place a quote in second location. ;; IN-PR-3 L2129: LD (05C5Bh),HL ; set keyboard cursor K_CUR to HL BIT 7,(IY+037h) ; test FLAGX - is this INPUT LINE ?? JR NZ,L215E ; forward to IN-VAR-3 if so as input will ; be accepted without checking its syntax. LD HL,(05C5Dh) ; fetch CH_ADD PUSH HL ; and save on stack. LD HL,(05C3Dh) ; fetch ERR_SP PUSH HL ; and save on stack ;; IN-VAR-1 L213A: LD HL,L213A ; address: IN-VAR-1 - this address PUSH HL ; is saved on stack to handle errors. BIT 4,(IY+030h) ; test FLAGS2 - is K channel in use ? JR Z,L2148 ; forward to IN-VAR-2 if not using the ; keyboard for input. (??) LD (05C3Dh),SP ; set ERR_SP to point to IN-VAR-1 on stack. ;; IN-VAR-2 L2148: LD HL,(05C61h) ; set HL to WORKSP - start of workspace. CALL L11A7 ; routine REMOVE-FP removes floating point ; forms when looping in error condition. LD (IY+00h),0FFh ; set ERR_NR to 'OK' cancelling the error. ; but X_PTR causes flashing error marker ; to be displayed at each call to the editor. CALL L0F2C ; routine EDITOR allows input to be entered ; or corrected if this is second time around. ; if we pass to next then there are no system errors RES 7,(IY+001h) ; update FLAGS - signal checking syntax CALL L21B9 ; routine IN-ASSIGN checks syntax using ; the VAL-FET-2 and powerful SCANNING routines. ; any syntax error and its back to IN-VAR-1. ; but with the flashing error marker showing ; where the error is. ; Note. the syntax of string input has to be ; checked as the user may have removed the ; bounding quotes or escaped them as with ; "hat" + "stand" for example. ; proceed if syntax passed. JR L2161 ; jump forward to IN-VAR-4 ; --- ; the jump was to here when using INPUT LINE. ;; IN-VAR-3 L215E: CALL L0F2C ; routine EDITOR is called for input ; when ENTER received rejoin other route but with no syntax check. ; INPUT and INPUT LINE converge here. ;; IN-VAR-4 L2161: LD (IY+022h),00h ; set K_CUR_hi to a low value so that the cursor ; no longer appears in the input line. CALL L21D6 ; routine IN-CHAN-K tests if the keyboard ; is being used for input. JR NZ,L2174 ; forward to IN-VAR-5 if using another input ; channel. ; continue here if using the keyboard. CALL L111D ; routine ED-COPY overprints the edit line ; to the lower screen. The only visible ; affect is that the cursor disappears. ; if you're inputting more than one item in ; a statement then that becomes apparent. LD BC,(05C82h) ; fetch line and column from ECHO_E CALL L0DD9 ; routine CL-SET sets S-POSNL to those ; values. ; if using another input channel rejoin here. ;; IN-VAR-5 L2174: LD HL,05C71h ; point HL to FLAGX RES 5,(HL) ; signal not in input mode BIT 7,(HL) ; is this INPUT LINE ? RES 7,(HL) ; cancel the bit anyway. JR NZ,L219B ; forward to IN-VAR-6 if INPUT LINE. POP HL ; drop the looping address POP HL ; drop the address of previous ; error handler. LD (05C3Dh),HL ; set ERR_SP to point to it. POP HL ; drop original CH_ADD which points to ; INPUT command in BASIC line. LD (05C5Fh),HL ; save in X_PTR while input is assigned. SET 7,(IY+001h) ; update FLAGS - Signal running program CALL L21B9 ; routine IN-ASSIGN is called again ; this time the variable will be assigned ; the input value without error. ; Note. the previous example now ; becomes "hatstand" LD HL,(05C5Fh) ; fetch stored CH_ADD value from X_PTR. LD (IY+026h),00h ; set X_PTR_hi so that iy is no longer relevant. LD (05C5Dh),HL ; put restored value back in CH_ADD JR L21B2 ; forward to IN-NEXT-2 to see if anything ; more in the INPUT list. ; --- ; the jump was to here with INPUT LINE only ;; IN-VAR-6 L219B: LD HL,(05C63h) ; STKBOT points to the end of the input. LD DE,(05C61h) ; WORKSP points to the beginning. SCF ; prepare for true subtraction. SBC HL,DE ; subtract to get length LD B,H ; transfer it to LD C,L ; the BC register pair. CALL L2AB2 ; routine STK-STO-$ stores parameters on ; the calculator stack. CALL L2AFF ; routine LET assigns it to destination. JR L21B2 ; forward to IN-NEXT-2 as print items ; not allowed with INPUT LINE. ; Note. that "hat" + "stand" will, for ; example, be unchanged as also would ; 'PRINT "Iris was here"'. ; --- ; the jump was to here when ALPHA found more items while looking for ; a variable name. ;; IN-NEXT-1 L21AF: CALL L1FFC ; routine PR-ITEM-1 considers further items. ;; IN-NEXT-2 L21B2: CALL L204E ; routine PR-POSN-1 handles a position item. JP Z,L20C1 ; jump back to IN-ITEM-1 if the zero flag ; indicates more items are present. RET ; return. ; --------------------------- ; INPUT ASSIGNMENT Subroutine ; --------------------------- ; This subroutine is called twice from the INPUT command when normal ; keyboard input is assigned. On the first occasion syntax is checked ; using SCANNING. The final call with the syntax flag reset is to make ; the assignment. ;; IN-ASSIGN L21B9: LD HL,(05C61h) ; fetch WORKSP start of input LD (05C5Dh),HL ; set CH_ADD to first character RST 18H ; GET-CHAR ignoring leading white-space. CP 0E2h ; is it 'STOP' JR Z,L21D0 ; forward to IN-STOP if so. LD A,(05C71h) ; load accumulator from FLAGX CALL L1C59 ; routine VAL-FET-2 makes assignment ; or goes through the motions if checking ; syntax. SCANNING is used. RST 18H ; GET-CHAR CP 00Dh ; is it carriage return ? RET Z ; return if so ; either syntax is OK ; or assignment has been made. ; if another character was found then raise an error. ; User doesn't see report but the flashing error marker ; appears in the lower screen. ;; REPORT-Cb L21CE: RST 08H ; ERROR-1 .DEFB 00Bh ; Error Report: Nonsense in BASIC ;; IN-STOP L21D0: CALL L2530 ; routine SYNTAX-Z (UNSTACK-Z?) RET Z ; return if checking syntax ; as user wouldn't see error report. ; but generate visible error report ; on second invocation. ;; REPORT-H L21D4: RST 08H ; ERROR-1 .DEFB 010h ; Error Report: STOP in INPUT ; ----------------------------------- ; THE 'TEST FOR CHANNEL K' SUBROUTINE ; ----------------------------------- ; This subroutine is called once from the keyboard INPUT command to check if ; the input routine in use is the one for the keyboard. ;; IN-CHAN-K L21D6: LD HL,(05C51h) ; fetch address of current channel CURCHL INC HL ; INC HL ; advance past INC HL ; input and INC HL ; output streams LD A,(HL) ; fetch the channel identifier. CP 04Bh ; test for 'K' RET ; return with zero set if keyboard is use. ; -------------------- ; Colour Item Routines ; -------------------- ; ; These routines have 3 entry points - ; 1) CO-TEMP-2 to handle a series of embedded Graphic colour items. ; 2) CO-TEMP-3 to handle a single embedded print colour item. ; 3) CO TEMP-4 to handle a colour command such as FLASH 1 ; ; "Due to a bug, if you bring in a peripheral channel and later use a colour ; statement, colour controls will be sent to it by mistake." - Steven Vickers ; Pitman Pocket Guide, 1984. ; ; To be fair, this only applies if the last channel was other than 'K', 'S' ; or 'P', which are all that are supported by this ROM, but if that last ; channel was a microdrive file, network channel etc. then ; PAPER 6; CLS will not turn the screen yellow and ; CIRCLE INK 2; 128,88,50 will not draw a red circle. ; ; This bug does not apply to embedded PRINT items as it is quite permissible ; to mix stream altering commands and colour items. ; The fix therefore would be to ensure that CLASS-07 and CLASS-09 make ; channel 'S' the current channel when not checking syntax. ; ----------------------------------------------------------------- ;; CO-TEMP-1 L21E1: RST 20H ; NEXT-CHAR ; -> Entry point from CLASS-09. Embedded Graphic colour items. ; e.g. PLOT INK 2; PAPER 8; 128,88 ; Loops till all colour items output, finally addressing the coordinates. ;; CO-TEMP-2 L21E2: CALL L21F2 ; routine CO-TEMP-3 to output colour control. RET C ; return if nothing more to output. -> RST 18H ; GET-CHAR CP 02Ch ; is it ',' separator ? JR Z,L21E1 ; back if so to CO-TEMP-1 CP 03Bh ; is it ';' separator ? JR Z,L21E1 ; back to CO-TEMP-1 for more. JP L1C8A ; to REPORT-C (REPORT-Cb is within range) ; 'Nonsense in BASIC' ; ------------------- ; CO-TEMP-3 ; ------------------- ; -> this routine evaluates and outputs a colour control and parameter. ; It is called from above and also from PR-ITEM-3 to handle a single embedded ; print item e.g. PRINT PAPER 6; "Hi". In the latter case, the looping for ; multiple items is within the PR-ITEM routine. ; It is quite permissible to send these to any stream. ;; CO-TEMP-3 L21F2: CP 0D9h ; is it 'INK' ? RET C ; return if less. CP 0DFh ; compare with 'OUT' CCF ; Complement Carry Flag RET C ; return if greater than 'OVER', 0DEh. PUSH AF ; save the colour token. RST 20H ; address NEXT-CHAR POP AF ; restore token and continue. ; -> this entry point used by CLASS-07. e.g. the command PAPER 6. ;; CO-TEMP-4 L21FC: SUB 0C9h ; reduce to control character 010h (INK) ; thru 015h (OVER). PUSH AF ; save control. CALL L1C82 ; routine EXPT-1NUM stacks addressed ; parameter on calculator stack. POP AF ; restore control. AND A ; clear carry CALL L1FC3 ; routine UNSTACK-Z returns if checking syntax. PUSH AF ; save again CALL L1E94 ; routine FIND-INT1 fetches parameter to A. LD D,A ; transfer now to D POP AF ; restore control. RST 10H ; PRINT-A outputs the control to current ; channel. LD A,D ; transfer parameter to A. RST 10H ; PRINT-A outputs parameter. RET ; return. -> ; ------------------------------------------------------------------------- ; ; {fl}{br}{ paper }{ ink } The temporary colour attributes ; ___ ___ ___ ___ ___ ___ ___ ___ system variable. ; ATTR_T | | | | | | | | | ; | | | | | | | | | ; 23695 |___|___|___|___|___|___|___|___| ; 7 6 5 4 3 2 1 0 ; ; ; {fl}{br}{ paper }{ ink } The temporary mask used for ; ___ ___ ___ ___ ___ ___ ___ ___ transparent colours. Any bit ; MASK_T | | | | | | | | | that is 1 shows that the ; | | | | | | | | | corresponding attribute is ; 23696 |___|___|___|___|___|___|___|___| taken not from ATTR-T but from ; 7 6 5 4 3 2 1 0 what is already on the screen. ; ; ; {paper9 }{ ink9 }{ inv1 }{ over1} The print flags. Even bits are ; ___ ___ ___ ___ ___ ___ ___ ___ temporary flags. The odd bits ; P_FLAG | | | | | | | | | are the permanent flags. ; | p | t | p | t | p | t | p | t | ; 23697 |___|___|___|___|___|___|___|___| ; 7 6 5 4 3 2 1 0 ; ; ----------------------------------------------------------------------- ; ------------------------------------ ; The colour system variable handler. ; ------------------------------------ ; This is an exit branch from PO-1-OPER, PO-2-OPER ; A holds control 010h (INK) to 015h (OVER) ; D holds parameter 0-9 for ink/paper 0,1 or 8 for bright/flash, ; 0 or 1 for over/inverse. ;; CO-TEMP-5 L2211: SUB 011h ; reduce range 0FFh-004h ADC A,00h ; add in carry if INK JR Z,L2234 ; forward to CO-TEMP-7 with INK and PAPER. SUB 002h ; reduce range 0FFh-002h ADC A,00h ; add carry if FLASH JR Z,L2273 ; forward to CO-TEMP-C with FLASH and BRIGHT. CP 001h ; is it 'INVERSE' ? LD A,D ; fetch parameter for INVERSE/OVER LD B,001h ; prepare OVER mask setting bit 0. JR NZ,L2228 ; forward to CO-TEMP-6 if OVER RLCA ; shift bit 0 RLCA ; to bit 2 LD B,004h ; set bit 2 of mask for inverse. ;; CO-TEMP-6 L2228: LD C,A ; save the A LD A,D ; re-fetch parameter CP 002h ; is it less than 2 JR NC,L2244 ; to REPORT-K if not 0 or 1. ; 'Invalid colour'. LD A,C ; restore A LD HL,05C91h ; address system variable P_FLAG JR L226C ; forward to exit via routine CO-CHANGE ; --- ; the branch was here with INK/PAPER and carry set for INK. ;; CO-TEMP-7 L2234: LD A,D ; fetch parameter LD B,007h ; set ink mask 00000111 JR C,L223E ; forward to CO-TEMP-8 with INK RLCA ; shift bits 0-2 RLCA ; to RLCA ; bits 3-5 LD B,038h ; set paper mask 00111000 ; both paper and ink rejoin here ;; CO-TEMP-8 L223E: LD C,A ; value to C LD A,D ; fetch parameter CP 00Ah ; is it less than 10d ? JR C,L2246 ; forward to CO-TEMP-9 if so. ; ink 10 etc. is not allowed. ;; REPORT-K L2244: RST 08H ; ERROR-1 .DEFB 013h ; Error Report: Invalid colour ;; CO-TEMP-9 L2246: LD HL,05C8Fh ; address system variable ATTR_T initially. CP 008h ; compare with 8 JR C,L2258 ; forward to CO-TEMP-B with 0-7. LD A,(HL) ; fetch temporary attribute as no change. JR Z,L2257 ; forward to CO-TEMP-A with INK/PAPER 8 ; it is either ink 9 or paper 9 (contrasting) OR B ; or with mask to make white CPL ; make black and change other to dark AND 024h ; 00100100 JR Z,L2257 ; forward to CO-TEMP-A if black and ; originally light. LD A,B ; else just use the mask (white) ;; CO-TEMP-A L2257: LD C,A ; save A in C ;; CO-TEMP-B L2258: LD A,C ; load colour to A CALL L226C ; routine CO-CHANGE addressing ATTR-T LD A,007h ; put 7 in accumulator CP D ; compare with parameter SBC A,A ; 00h if 0-7, 0FFh if 8 CALL L226C ; routine CO-CHANGE addressing MASK-T ; mask returned in A. ; now consider P-FLAG. RLCA ; 01110000 or 00001110 RLCA ; 11100000 or 00011100 AND 050h ; 01000000 or 00010000 (AND 01010000) LD B,A ; transfer to mask LD A,008h ; load A with 8 CP D ; compare with parameter SBC A,A ; 0FFh if was 9, 00h if 0-8 ; continue while addressing P-FLAG ; setting bit 4 if ink 9 ; setting bit 6 if paper 9 ; ----------------------- ; Handle change of colour ; ----------------------- ; This routine addresses a system variable ATTR_T, MASK_T or P-FLAG in HL. ; colour value in A, mask in B. ;; CO-CHANGE L226C: XOR (HL) ; impress bits specified AND B ; by mask XOR (HL) ; on system variable. LD (HL),A ; update system variable. INC HL ; address next location. LD A,B ; put current value of mask in A RET ; return. ; --- ; the branch was here with flash and bright ;; CO-TEMP-C L2273: SBC A,A ; set zero flag for bright. LD A,D ; fetch original parameter 0,1 or 8 RRCA ; rotate bit 0 to bit 7 LD B,080h ; mask for flash 10000000 JR NZ,L227D ; forward to CO-TEMP-D if flash RRCA ; rotate bit 7 to bit 6 LD B,040h ; mask for bright 01000000 ;; CO-TEMP-D L227D: LD C,A ; store value in C LD A,D ; fetch parameter CP 008h ; compare with 8 JR Z,L2287 ; forward to CO-TEMP-E if 8 CP 002h ; test if 0 or 1 JR NC,L2244 ; back to REPORT-K if not ; 'Invalid colour' ;; CO-TEMP-E L2287: LD A,C ; value to A LD HL,05C8Fh ; address ATTR_T CALL L226C ; routine CO-CHANGE addressing ATTR_T LD A,C ; fetch value RRCA ; for flash8/bright8 complete RRCA ; rotations to put set bit in RRCA ; bit 7 (flash) bit 6 (bright) JR L226C ; back to CO-CHANGE addressing MASK_T ; and indirect return. ; --------------------- ; Handle BORDER command ; --------------------- ; Command syntax example: BORDER 7 ; This command routine sets the border to one of the eight colours. ; The colours used for the lower screen are based on this. ;; BORDER L2294: CALL L1E94 ; routine FIND-INT1 CP 008h ; must be in range 0 (black) to 7 (white) JR NC,L2244 ; back to REPORT-K if not ; 'Invalid colour'. OUT (0FEh),A ; outputting to port effects an immediate ; change. RLCA ; shift the colour to RLCA ; the paper bits setting the RLCA ; ink colour black. BIT 5,A ; is the number light coloured ? ; i.e. in the range green to white. JR NZ,L22A6 ; skip to BORDER-1 if so XOR 007h ; make the ink white. ;; BORDER-1 L22A6: LD (05C48h),A ; update BORDCR with new paper/ink RET ; return. ; ----------------- ; Get pixel address ; ----------------- ; ; ;; PIXEL-ADD L22AA: LD A,0AFh ; load with 175 decimal. SUB B ; subtract the y value. JP C,L24F9 ; jump forward to REPORT-Bc if greater. ; 'Integer out of range' ; the high byte is derived from Y only. ; the first 3 bits are always 010 ; the next 2 bits denote in which third of the screen the byte is. ; the last 3 bits denote in which of the 8 scan lines within a third ; the byte is located. There are 24 discrete values. LD B,A ; the line number from top of screen to B. AND A ; clear carry (already clear) RRA ; 0xxxxxxx SCF ; set carry flag RRA ; 10xxxxxx AND A ; clear carry flag RRA ; 010xxxxx XOR B ; AND 0F8h ; keep the top 5 bits 11111000 XOR B ; 010xxbbb LD H,A ; transfer high byte to H. ; the low byte is derived from both X and Y. LD A,C ; the x value 0-255. RLCA ; RLCA ; RLCA ; XOR B ; the y value AND 0C7h ; apply mask 11000111 XOR B ; restore unmasked bits xxyyyxxx RLCA ; rotate to xyyyxxxx RLCA ; required position. yyyxxxxx LD L,A ; low byte to L. ; finally form the pixel position in A. LD A,C ; x value to A AND 007h ; mod 8 RET ; return ; ---------------- ; Point Subroutine ; ---------------- ; The point subroutine is called from s-point via the scanning functions ; table. ;; POINT-SUB L22CB: CALL L2307 ; routine STK-TO-BC CALL L22AA ; routine PIXEL-ADD finds address of pixel. LD B,A ; pixel position to B, 0-7. INC B ; increment to give rotation count 1-8. LD A,(HL) ; fetch byte from screen. ;; POINT-LP L22D4: RLCA ; rotate and loop back DJNZ L22D4 ; to POINT-LP until pixel at right. AND 001h ; test to give zero or one. JP L2D28 ; jump forward to STACK-A to save result. ; ------------------- ; Handle PLOT command ; ------------------- ; Command Syntax example: PLOT 128,88 ; ;; PLOT L22DC: CALL L2307 ; routine STK-TO-BC CALL L22E5 ; routine PLOT-SUB JP L0D4D ; to TEMPS ; ------------------- ; The Plot subroutine ; ------------------- ; A screen byte holds 8 pixels so it is necessary to rotate a mask ; into the correct position to leave the other 7 pixels unaffected. ; However all 64 pixels in the character cell take any embedded colour ; items. ; A pixel can be reset (inverse 1), toggled (over 1), or set ( with inverse ; and over switches off). With both switches on, the byte is simply put ; back on the screen though the colours may change. ;; PLOT-SUB L22E5: LD (05C7Dh),BC ; store new x/y values in COORDS CALL L22AA ; routine PIXEL-ADD gets address in HL, ; count from left 0-7 in B. LD B,A ; transfer count to B. INC B ; increase 1-8. LD A,0FEh ; 11111110 in A. ;; PLOT-LOOP L22F0: RRCA ; rotate mask. DJNZ L22F0 ; to PLOT-LOOP until B circular rotations. LD B,A ; load mask to B LD A,(HL) ; fetch screen byte to A LD C,(IY+057h) ; P_FLAG to C BIT 0,C ; is it to be OVER 1 ? JR NZ,L22FD ; forward to PL-TST-IN if so. ; was over 0 AND B ; combine with mask to blank pixel. ;; PL-TST-IN L22FD: BIT 2,C ; is it inverse 1 ? JR NZ,L2303 ; to PLOT-END if so. XOR B ; switch the pixel CPL ; restore other 7 bits ;; PLOT-END L2303: LD (HL),A ; load byte to the screen. JP L0BDB ; exit to PO-ATTR to set colours for cell. ; ------------------------------ ; Put two numbers in BC register ; ------------------------------ ; ; ;; STK-TO-BC L2307: CALL L2314 ; routine STK-TO-A LD B,A ; PUSH BC ; CALL L2314 ; routine STK-TO-A LD E,C ; POP BC ; LD D,C ; LD C,A ; RET ; ; ----------------------- ; Put stack in A register ; ----------------------- ; This routine puts the last value on the calculator stack into the accumulator ; deleting the last value. ;; STK-TO-A L2314: CALL L2DD5 ; routine FP-TO-A compresses last value into ; accumulator. e.g. PI would become 3. ; zero flag set if positive. JP C,L24F9 ; jump forward to REPORT-Bc if >= 255.5. LD C,001h ; prepare a positive sign byte. RET Z ; return if FP-TO-BC indicated positive. LD C,0FFh ; prepare negative sign byte and RET ; return. ; -------------------- ; THE 'CIRCLE' COMMAND ; -------------------- ; "Goe not Thou about to Square eyther circle" - ; - John Donne, Cambridge educated theologian, 1624 ; ; The CIRCLE command draws a circle as a series of straight lines. ; In some ways it can be regarded as a polygon, but the first line is drawn ; as a tangent, taking the radius as its distance from the centre. ; ; Both the CIRCLE algorithm and the ARC drawing algorithm make use of the ; 'ROTATION FORMULA' (see later). It is only necessary to work out where ; the first line will be drawn and how long it is and then the rotation ; formula takes over and calculates all other rotated points. ; ; All Spectrum circles consist of two vertical lines at each side and two ; horizontal lines at the top and bottom. The number of lines is calculated ; from the radius of the circle and is always divisible by 4. For complete ; circles it will range from 4 for a square circle to 32 for a circle of ; radius 87. The Spectrum can attempt larger circles e.g. CIRCLE 0,14,255 ; but these will error as they go off-screen after four lines are drawn. ; At the opposite end, CIRCLE 128,88,1.23 will draw a circle as a perfect 3x3 ; square using 4 straight lines although very small circles are just drawn as ; a dot on the screen. ; ; The first chord drawn is the vertical chord on the right of the circle. ; The starting point is at the base of this chord which is drawn upwards and ; the circle continues in an anti-clockwise direction. As noted earlier the ; x-coordinate of this point measured from the centre of the circle is the ; radius. ; ; The CIRCLE command makes extensive use of the calculator and as part of ; process of drawing a large circle, free memory is checked 1315 times. ; When drawing a large arc, free memory is checked 928 times. ; A single call to 'sin' involves 63 memory checks and so values of sine ; and cosine are pre-calculated and held in the mem locations. As a ; clever trick 'cos' is derived from 'sin' using simple arithmetic operations ; instead of the more expensive 'cos' function. ; ; Initially, the syntax has been partly checked using the class for the DRAW ; command which stacks the origin of the circle (X,Y). ;; CIRCLE L2320: RST 18H ; GET-CHAR x, y. CP 02Ch ; Is character the required comma ? JP NZ,L1C8A ; Jump, if not, to REPORT-C ; 'Nonsense in basic' RST 20H ; NEXT-CHAR advances the parsed character address. CALL L1C82 ; routine EXPT-1NUM stacks radius in runtime. CALL L1BEE ; routine CHECK-END will return here in runtime ; if nothing follows the command. ; Now make the radius positive and ensure that it is in floating point form ; so that the exponent byte can be accessed for quick testing. RST 28H ;; FP-CALC x, y, r. .DEFB 02Ah ;;abs x, y, r. .DEFB 03Dh ;;re-stack x, y, r. .DEFB 038h ;;end-calc x, y, r. LD A,(HL) ; Fetch first, floating-point, exponent byte. CP 081h ; Compare to one. JR NC,L233B ; Forward to C-R-GRE-1 ; if circle radius is greater than one. ; The circle is no larger than a single pixel so delete the radius from the ; calculator stack and plot a point at the centre. RST 28H ;; FP-CALC x, y, r. .DEFB 002h ;;delete x, y. .DEFB 038h ;;end-calc x, y. JR L22DC ; back to PLOT routine to just plot x,y. ; --- ; Continue when the circle's radius measures greater than one by forming ; the angle 2 * PI radians which is 360 degrees. ;; C-R-GRE-1 L233B: RST 28H ;; FP-CALC x, y, r .DEFB 0A3h ;;stk-pi/2 x, y, r, pi/2. .DEFB 038h ;;end-calc x, y, r, pi/2. ; Change the exponent of pi/2 from 081h to 083h giving 2*PI the central angle. ; This is quicker than multiplying by four. LD (HL),083h ; x, y, r, 2*PI. ; Now store this important constant in mem-5 and delete so that other ; parameters can be derived from it, by a routine shared with DRAW. RST 28H ;; FP-CALC x, y, r, 2*PI. .DEFB 0C5h ;;st-mem-5 store 2*PI in mem-5 .DEFB 002h ;;delete x, y, r. .DEFB 038h ;;end-calc x, y, r. ; The parameters derived from mem-5 (A) and from the radius are set up in ; four of the other mem locations by the CIRCLE DRAW PARAMETERS routine which ; also returns the number of straight lines in the B register. CALL L247D ; routine CD-PRMS1 ; mem-0 ; A/No of lines (=a) unused ; mem-1 ; sin(a/2) will be moving x var ; mem-2 ; - will be moving y var ; mem-3 ; cos(a) const ; mem-4 ; sin(a) const ; mem-5 ; Angle of rotation (A) (2*PI) const ; B ; Number of straight lines. PUSH BC ; Preserve the number of lines in B. ; Next calculate the length of half a chord by multiplying the sine of half ; the central angle by the radius of the circle. RST 28H ;; FP-CALC x, y, r. .DEFB 031h ;;duplicate x, y, r, r. .DEFB 0E1h ;;get-mem-1 x, y, r, r, sin(a/2). .DEFB 004h ;;multiply x, y, r, half-chord. .DEFB 038h ;;end-calc x, y, r, half-chord. LD A,(HL) ; fetch exponent of the half arc to A. CP 080h ; compare to a half pixel JR NC,L235A ; forward, if greater than .5, to C-ARC-GE1 ; If the first line is less than .5 then 4 'lines' would be drawn on the same ; spot so tidy the calculator stack and machine stack and plot the centre. RST 28H ;; FP-CALC x, y, r, hc. .DEFB 002h ;;delete x, y, r. .DEFB 002h ;;delete x, y. .DEFB 038h ;;end-calc x, y. POP BC ; Balance machine stack by taking chord-count. JP L22DC ; JUMP to PLOT ; --- ; The arc is greater than 0.5 so the circle can be drawn. ;; C-ARC-GE1 L235A: RST 28H ;; FP-CALC x, y, r, hc. .DEFB 0C2h ;;st-mem-2 x, y, r, half chord to mem-2. .DEFB 001h ;;exchange x, y, hc, r. .DEFB 0C0h ;;st-mem-0 x, y, hc, r. .DEFB 002h ;;delete x, y, hc. ; Subtract the length of the half-chord from the absolute y coordinate to ; give the starting y coordinate sy. ; Note that for a circle this is also the end coordinate. .DEFB 003h ;;subtract x, y-hc. (The start y-coord) .DEFB 001h ;;exchange sy, x. ; Next simply add the radius to the x coordinate to give a fuzzy x-coordinate. ; Strictly speaking, the radius should be multiplied by cos(a/2) first but ; doing it this way makes the circle slightly larger. .DEFB 0E0h ;;get-mem-0 sy, x, r. .DEFB 00Fh ;;addition sy, x+r. (The start x-coord) ; We now want three copies of this pair of values on the calculator stack. ; The first pair remain on the stack throughout the circle routine and are ; the end points. The next pair will be the moving absolute values of x and y ; that are updated after each line is drawn. The final pair will be loaded ; into the COORDS system variable so that the first vertical line starts at ; the right place. .DEFB 0C0h ;;st-mem-0 sy, sx. .DEFB 001h ;;exchange sx, sy. .DEFB 031h ;;duplicate sx, sy, sy. .DEFB 0E0h ;;get-mem-0 sx, sy, sy, sx. .DEFB 001h ;;exchange sx, sy, sx, sy. .DEFB 031h ;;duplicate sx, sy, sx, sy, sy. .DEFB 0E0h ;;get-mem-0 sx, sy, sx, sy, sy, sx. ; Locations mem-1 and mem-2 are the relative x and y values which are updated ; after each line is drawn. Since we are drawing a vertical line then the rx ; value in mem-1 is zero and the ry value in mem-2 is the full chord. .DEFB 0A0h ;;stk-zero sx, sy, sx, sy, sy, sx, 0. .DEFB 0C1h ;;st-mem-1 sx, sy, sx, sy, sy, sx, 0. .DEFB 002h ;;delete sx, sy, sx, sy, sy, sx. ; Although the three pairs of x/y values are the same for a circle, they ; will be labelled terminating, absolute and start coordinates. .DEFB 038h ;;end-calc tx, ty, ax, ay, sy, sx. ; Use the exponent manipulating trick again to double the value of mem-2. INC (IY+062h) ; Increment MEM-2-1st doubling half chord. ; Note. this first vertical chord is drawn at the radius so circles are ; slightly displaced to the right. ; It is only necessary to place the values (sx) and (sy) in the system ; variable COORDS to ensure that drawing commences at the correct pixel. ; Note. a couple of LD (COORDS),A instructions would have been quicker, and ; simpler, than using LD (COORDS),HL. CALL L1E94 ; routine FIND-INT1 fetches sx from stack to A. LD L,A ; place X value in L. PUSH HL ; save the holding register. CALL L1E94 ; routine FIND-INT1 fetches sy to A POP HL ; restore the holding register. LD H,A ; and place y value in high byte. LD (05C7Dh),HL ; Update the COORDS system variable. ; ; tx, ty, ax, ay. POP BC ; restore the chord count ; values 4,8,12,16,20,24,28 or 32. JP L2420 ; forward to DRW-STEPS ; tx, ty, ax, ay. ; Note. the jump to DRW-STEPS is just to decrement B and jump into the ; middle of the arc-drawing loop. The arc count which includes the first ; vertical arc draws one less than the perceived number of arcs. ; The final arc offsets are obtained by subtracting the final COORDS value ; from the initial sx and sy values which are kept at the base of the ; calculator stack throughout the arc loop. ; This ensures that the final line finishes exactly at the starting pixel ; removing the possibility of any inaccuracy. ; Since the initial sx and sy values are not required until the final arc ; is drawn, they are not shown until then. ; As the calculator stack is quite busy, only the active parts are shown in ; each section. ; ------------------ ; THE 'DRAW' COMMAND ; ------------------ ; The Spectrum's DRAW command is overloaded and can take two parameters sets. ; ; With two parameters, it simply draws an approximation to a straight line ; at offset x,y using the LINE-DRAW routine. ; ; With three parameters, an arc is drawn to the point at offset x,y turning ; through an angle, in radians, supplied by the third parameter. ; The arc will consist of 4 to 252 straight lines each one of which is drawn ; by calls to the DRAW-LINE routine. ;; DRAW L2382: RST 18H ; GET-CHAR CP 02Ch ; is it the comma character ? JR Z,L238D ; forward, if so, to DR-3-PRMS ; There are two parameters e.g. DRAW 255,175 CALL L1BEE ; routine CHECK-END JP L2477 ; jump forward to LINE-DRAW ; --- ; There are three parameters e.g. DRAW 255, 175, .5 ; The first two are relative coordinates and the third is the angle of ; rotation in radians (A). ;; DR-3-PRMS L238D: RST 20H ; NEXT-CHAR skips over the 'comma'. CALL L1C82 ; routine EXPT-1NUM stacks the rotation angle. CALL L1BEE ; routine CHECK-END ; Now enter the calculator and store the complete rotation angle in mem-5 RST 28H ;; FP-CALC x, y, A. .DEFB 0C5h ;;st-mem-5 x, y, A. ; Test the angle for the special case of 360 degrees. .DEFB 0A2h ;;stk-half x, y, A, 1/2. .DEFB 004h ;;multiply x, y, A/2. .DEFB 01Fh ;;sin x, y, sin(A/2). .DEFB 031h ;;duplicate x, y, sin(A/2),sin(A/2) .DEFB 030h ;;not x, y, sin(A/2), (0/1). .DEFB 030h ;;not x, y, sin(A/2), (1/0). .DEFB 00h ;;jump-true x, y, sin(A/2). .DEFB 006h ;;forward to L23A3, DR-SIN-NZ ; if sin(r/2) is not zero. ; The third parameter is 2*PI (or a multiple of 2*PI) so a 360 degrees turn ; would just be a straight line. Eliminating this case here prevents ; division by zero at later stage. .DEFB 002h ;;delete x, y. .DEFB 038h ;;end-calc x, y. JP L2477 ; forward to LINE-DRAW ; --- ; An arc can be drawn. ;; DR-SIN-NZ L23A3: .DEFB 0C0h ;;st-mem-0 x, y, sin(A/2). store mem-0 .DEFB 002h ;;delete x, y. ; The next step calculates (roughly) the diameter of the circle of which the ; arc will form part. This value does not have to be too accurate as it is ; only used to evaluate the number of straight lines and then discarded. ; After all for a circle, the radius is used. Consequently, a circle of ; radius 50 will have 24 straight lines but an arc of radius 50 will have 20 ; straight lines - when drawn in any direction. ; So that simple arithmetic can be used, the length of the chord can be ; calculated as X+Y rather than by Pythagoras Theorem and the sine of the ; nearest angle within reach is used. .DEFB 0C1h ;;st-mem-1 x, y. store mem-1 .DEFB 002h ;;delete x. .DEFB 031h ;;duplicate x, x. .DEFB 02Ah ;;abs x, x (+ve). .DEFB 0E1h ;;get-mem-1 x, X, y. .DEFB 001h ;;exchange x, y, X. .DEFB 0E1h ;;get-mem-1 x, y, X, y. .DEFB 02Ah ;;abs x, y, X, Y (+ve). .DEFB 00Fh ;;addition x, y, X+Y. .DEFB 0E0h ;;get-mem-0 x, y, X+Y, sin(A/2). .DEFB 005h ;;division x, y, X+Y/sin(A/2). .DEFB 02Ah ;;abs x, y, X+Y/sin(A/2) = D. ; Bring back sin(A/2) from mem-0 which will shortly get trashed. ; Then bring D to the top of the stack again. .DEFB 0E0h ;;get-mem-0 x, y, D, sin(A/2). .DEFB 001h ;;exchange x, y, sin(A/2), D. ; Note. that since the value at the top of the stack has arisen as a result ; of division then it can no longer be in integer form and the next re-stack ; is unnecessary. Only the Sinclair ZX80 had integer division. .DEFB 03Dh ;;re-stack (unnecessary) .DEFB 038h ;;end-calc x, y, sin(A/2), D. ; The next test avoids drawing 4 straight lines when the start and end pixels ; are adjacent (or the same) but is probably best dispensed with. LD A,(HL) ; fetch exponent byte of D. CP 081h ; compare to 1 JR NC,L23C1 ; forward, if > 1, to DR-PRMS ; else delete the top two stack values and draw a simple straight line. RST 28H ;; FP-CALC .DEFB 002h ;;delete .DEFB 002h ;;delete .DEFB 038h ;;end-calc x, y. JP L2477 ; to LINE-DRAW ; --- ; The ARC will consist of multiple straight lines so call the CIRCLE-DRAW ; PARAMETERS ROUTINE to pre-calculate sine values from the angle (in mem-5) ; and determine also the number of straight lines from that value and the ; 'diameter' which is at the top of the calculator stack. ;; DR-PRMS L23C1: CALL L247D ; routine CD-PRMS1 ; mem-0 ; (A)/No. of lines (=a) (step angle) ; mem-1 ; sin(a/2) ; mem-2 ; - ; mem-3 ; cos(a) const ; mem-4 ; sin(a) const ; mem-5 ; Angle of rotation (A) in ; B ; Count of straight lines - max 252. PUSH BC ; Save the line count on the machine stack. ; Remove the now redundant diameter value D. RST 28H ;; FP-CALC x, y, sin(A/2), D. .DEFB 002h ;;delete x, y, sin(A/2). ; Dividing the sine of the step angle by the sine of the total angle gives ; the length of the initial chord on a unary circle. This factor f is used ; to scale the coordinates of the first line which still points in the ; direction of the end point and may be larger. .DEFB 0E1h ;;get-mem-1 x, y, sin(A/2), sin(a/2) .DEFB 001h ;;exchange x, y, sin(a/2), sin(A/2) .DEFB 005h ;;division x, y, sin(a/2)/sin(A/2) .DEFB 0C1h ;;st-mem-1 x, y. f. .DEFB 002h ;;delete x, y. ; With the factor stored, scale the x coordinate first. .DEFB 001h ;;exchange y, x. .DEFB 031h ;;duplicate y, x, x. .DEFB 0E1h ;;get-mem-1 y, x, x, f. .DEFB 004h ;;multiply y, x, x*f (=xx) .DEFB 0C2h ;;st-mem-2 y, x, xx. .DEFB 002h ;;delete y. x. ; Now scale the y coordinate. .DEFB 001h ;;exchange x, y. .DEFB 031h ;;duplicate x, y, y. .DEFB 0E1h ;;get-mem-1 x, y, y, f .DEFB 004h ;;multiply x, y, y*f (=yy) ; Note. 'sin' and 'cos' trash locations mem-0 to mem-2 so fetch mem-2 to the ; calculator stack for safe keeping. .DEFB 0E2h ;;get-mem-2 x, y, yy, xx. ; Once we get the coordinates of the first straight line then the 'ROTATION ; FORMULA' used in the arc loop will take care of all other points, but we ; now use a variation of that formula to rotate the first arc through (A-a)/2 ; radians. ; ; xRotated = y * sin(angle) + x * cos(angle) ; yRotated = y * cos(angle) - x * sin(angle) ; .DEFB 0E5h ;;get-mem-5 x, y, yy, xx, A. .DEFB 0E0h ;;get-mem-0 x, y, yy, xx, A, a. .DEFB 003h ;;subtract x, y, yy, xx, A-a. .DEFB 0A2h ;;stk-half x, y, yy, xx, A-a, 1/2. .DEFB 004h ;;multiply x, y, yy, xx, (A-a)/2. (=angle) .DEFB 031h ;;duplicate x, y, yy, xx, angle, angle. .DEFB 01Fh ;;sin x, y, yy, xx, angle, sin(angle) .DEFB 0C5h ;;st-mem-5 x, y, yy, xx, angle, sin(angle) .DEFB 002h ;;delete x, y, yy, xx, angle .DEFB 020h ;;cos x, y, yy, xx, cos(angle). ; Note. mem-0, mem-1 and mem-2 can be used again now... .DEFB 0C0h ;;st-mem-0 x, y, yy, xx, cos(angle). .DEFB 002h ;;delete x, y, yy, xx. .DEFB 0C2h ;;st-mem-2 x, y, yy, xx. .DEFB 002h ;;delete x, y, yy. .DEFB 0C1h ;;st-mem-1 x, y, yy. .DEFB 0E5h ;;get-mem-5 x, y, yy, sin(angle) .DEFB 004h ;;multiply x, y, yy*sin(angle). .DEFB 0E0h ;;get-mem-0 x, y, yy*sin(angle), cos(angle) .DEFB 0E2h ;;get-mem-2 x, y, yy*sin(angle), cos(angle), xx. .DEFB 004h ;;multiply x, y, yy*sin(angle), xx*cos(angle). .DEFB 00Fh ;;addition x, y, xRotated. .DEFB 0E1h ;;get-mem-1 x, y, xRotated, yy. .DEFB 001h ;;exchange x, y, yy, xRotated. .DEFB 0C1h ;;st-mem-1 x, y, yy, xRotated. .DEFB 002h ;;delete x, y, yy. .DEFB 0E0h ;;get-mem-0 x, y, yy, cos(angle). .DEFB 004h ;;multiply x, y, yy*cos(angle). .DEFB 0E2h ;;get-mem-2 x, y, yy*cos(angle), xx. .DEFB 0E5h ;;get-mem-5 x, y, yy*cos(angle), xx, sin(angle). .DEFB 004h ;;multiply x, y, yy*cos(angle), xx*sin(angle). .DEFB 003h ;;subtract x, y, yRotated. .DEFB 0C2h ;;st-mem-2 x, y, yRotated. ; Now the initial x and y coordinates are made positive and summed to see ; if they measure up to anything significant. .DEFB 02Ah ;;abs x, y, yRotated'. .DEFB 0E1h ;;get-mem-1 x, y, yRotated', xRotated. .DEFB 02Ah ;;abs x, y, yRotated', xRotated'. .DEFB 00Fh ;;addition x, y, yRotated+xRotated. .DEFB 002h ;;delete x, y. .DEFB 038h ;;end-calc x, y. ; Although the test value has been deleted it is still above the calculator ; stack in memory and conveniently DE which points to the first free byte ; addresses the exponent of the test value. LD A,(DE) ; Fetch exponent of the length indicator. CP 081h ; Compare to that for 1 POP BC ; Balance the machine stack JP C,L2477 ; forward, if the coordinates of first line ; don't add up to more than 1, to LINE-DRAW ; Continue when the arc will have a discernable shape. PUSH BC ; Restore line counter to the machine stack. ; The parameters of the DRAW command were relative and they are now converted ; to absolute coordinates by adding to the coordinates of the last point ; plotted. The first two values on the stack are the terminal tx and ty ; coordinates. The x-coordinate is converted first but first the last point ; plotted is saved as it will initialize the moving ax, value. RST 28H ;; FP-CALC x, y. .DEFB 001h ;;exchange y, x. .DEFB 038h ;;end-calc y, x. LD A,(05C7Dh) ; Fetch System Variable COORDS-x CALL L2D28 ; routine STACK-A RST 28H ;; FP-CALC y, x, last-x. ; Store the last point plotted to initialize the moving ax value. .DEFB 0C0h ;;st-mem-0 y, x, last-x. .DEFB 00Fh ;;addition y, absolute x. .DEFB 001h ;;exchange tx, y. .DEFB 038h ;;end-calc tx, y. LD A,(05C7Eh) ; Fetch System Variable COORDS-y CALL L2D28 ; routine STACK-A RST 28H ;; FP-CALC tx, y, last-y. ; Store the last point plotted to initialize the moving ay value. .DEFB 0C5h ;;st-mem-5 tx, y, last-y. .DEFB 00Fh ;;addition tx, ty. ; Fetch the moving ax and ay to the calculator stack. .DEFB 0E0h ;;get-mem-0 tx, ty, ax. .DEFB 0E5h ;;get-mem-5 tx, ty, ax, ay. .DEFB 038h ;;end-calc tx, ty, ax, ay. POP BC ; Restore the straight line count. ; ----------------------------------- ; THE 'CIRCLE/DRAW CONVERGENCE POINT' ; ----------------------------------- ; The CIRCLE and ARC-DRAW commands converge here. ; ; Note. for both the CIRCLE and ARC commands the minimum initial line count ; is 4 (as set up by the CD_PARAMS routine) and so the zero flag will never ; be set and the loop is always entered. The first test is superfluous and ; the jump will always be made to ARC-START. ;; DRW-STEPS L2420: DEC B ; decrement the arc count (4,8,12,16...). JR Z,L245F ; forward, if zero (not possible), to ARC-END JR L2439 ; forward to ARC-START ; -------------- ; THE 'ARC LOOP' ; -------------- ; ; The arc drawing loop will draw up to 31 straight lines for a circle and up ; 251 straight lines for an arc between two points. In both cases the final ; closing straight line is drawn at ARC_END, but it otherwise loops back to ; here to calculate the next coordinate using the ROTATION FORMULA where (a) ; is the previously calculated, constant CENTRAL ANGLE of the arcs. ; ; Xrotated = x * cos(a) - y * sin(a) ; Yrotated = x * sin(a) + y * cos(a) ; ; The values cos(a) and sin(a) are pre-calculated and held in mem-3 and mem-4 ; for the duration of the routine. ; Memory location mem-1 holds the last relative x value (rx) and mem-2 holds ; the last relative y value (ry) used by DRAW. ; ; Note. that this is a very clever twist on what is after all a very clever, ; well-used formula. Normally the rotation formula is used with the x and y ; coordinates from the centre of the circle (or arc) and a supplied angle to ; produce two new x and y coordinates in an anticlockwise direction on the ; circumference of the circle. ; What is being used here, instead, is the relative X and Y parameters from ; the last point plotted that are required to get to the current point and ; the formula returns the next relative coordinates to use. ;; ARC-LOOP L2425: RST 28H ;; FP-CALC .DEFB 0E1h ;;get-mem-1 rx. .DEFB 031h ;;duplicate rx, rx. .DEFB 0E3h ;;get-mem-3 cos(a) .DEFB 004h ;;multiply rx, rx*cos(a). .DEFB 0E2h ;;get-mem-2 rx, rx*cos(a), ry. .DEFB 0E4h ;;get-mem-4 rx, rx*cos(a), ry, sin(a). .DEFB 004h ;;multiply rx, rx*cos(a), ry*sin(a). .DEFB 003h ;;subtract rx, rx*cos(a) - ry*sin(a) .DEFB 0C1h ;;st-mem-1 rx, new relative x rotated. .DEFB 002h ;;delete rx. .DEFB 0E4h ;;get-mem-4 rx, sin(a). .DEFB 004h ;;multiply rx*sin(a) .DEFB 0E2h ;;get-mem-2 rx*sin(a), ry. .DEFB 0E3h ;;get-mem-3 rx*sin(a), ry, cos(a). .DEFB 004h ;;multiply rx*sin(a), ry*cos(a). .DEFB 00Fh ;;addition rx*sin(a) + ry*cos(a). .DEFB 0C2h ;;st-mem-2 new relative y rotated. .DEFB 002h ;;delete . .DEFB 038h ;;end-calc . ; Note. the calculator stack actually holds tx, ty, ax, ay ; and the last absolute values of x and y ; are now brought into play. ; ; Magically, the two new rotated coordinates rx and ry are all that we would ; require to draw a circle or arc - on paper! ; The Spectrum DRAW routine draws to the rounded x and y coordinate and so ; repetitions of values like 3.49 would mean that the fractional parts ; would be lost until eventually the draw coordinates might differ from the ; floating point values used above by several pixels. ; For this reason the accurate offsets calculated above are added to the ; accurate, absolute coordinates maintained in ax and ay and these new ; coordinates have the integer coordinates of the last plot position ; ( from System Variable COORDS ) subtracted from them to give the relative ; coordinates required by the DRAW routine. ; The mid entry point. ;; ARC-START L2439: PUSH BC ; Preserve the arc counter on the machine stack. ; Store the absolute ay in temporary variable mem-0 for the moment. RST 28H ;; FP-CALC ax, ay. .DEFB 0C0h ;;st-mem-0 ax, ay. .DEFB 002h ;;delete ax. ; Now add the fractional relative x coordinate to the fractional absolute ; x coordinate to obtain a new fractional x-coordinate. .DEFB 0E1h ;;get-mem-1 ax, xr. .DEFB 00Fh ;;addition ax+xr (= new ax). .DEFB 031h ;;duplicate ax, ax. .DEFB 038h ;;end-calc ax, ax. LD A,(05C7Dh) ; COORDS-x last x (integer ix 0-255) CALL L2D28 ; routine STACK-A RST 28H ;; FP-CALC ax, ax, ix. .DEFB 003h ;;subtract ax, ax-ix = relative DRAW Dx. ; Having calculated the x value for DRAW do the same for the y value. .DEFB 0E0h ;;get-mem-0 ax, Dx, ay. .DEFB 0E2h ;;get-mem-2 ax, Dx, ay, ry. .DEFB 00Fh ;;addition ax, Dx, ay+ry (= new ay). .DEFB 0C0h ;;st-mem-0 ax, Dx, ay. .DEFB 001h ;;exchange ax, ay, Dx, .DEFB 0E0h ;;get-mem-0 ax, ay, Dx, ay. .DEFB 038h ;;end-calc ax, ay, Dx, ay. LD A,(05C7Eh) ; COORDS-y last y (integer iy 0-175) CALL L2D28 ; routine STACK-A RST 28H ;; FP-CALC ax, ay, Dx, ay, iy. .DEFB 003h ;;subtract ax, ay, Dx, ay-iy ( = Dy). .DEFB 038h ;;end-calc ax, ay, Dx, Dy. CALL L24B7 ; Routine DRAW-LINE draws (Dx,Dy) relative to ; the last pixel plotted leaving absolute x ; and y on the calculator stack. ; ax, ay. POP BC ; Restore the arc counter from the machine stack. DJNZ L2425 ; Decrement and loop while > 0 to ARC-LOOP ; ------------- ; THE 'ARC END' ; ------------- ; To recap the full calculator stack is tx, ty, ax, ay. ; Just as one would do if drawing the curve on paper, the final line would ; be drawn by joining the last point plotted to the initial start point ; in the case of a CIRCLE or to the calculated end point in the case of ; an ARC. ; The moving absolute values of x and y are no longer required and they ; can be deleted to expose the closing coordinates. ;; ARC-END L245F: RST 28H ;; FP-CALC tx, ty, ax, ay. .DEFB 002h ;;delete tx, ty, ax. .DEFB 002h ;;delete tx, ty. .DEFB 001h ;;exchange ty, tx. .DEFB 038h ;;end-calc ty, tx. ; First calculate the relative x coordinate to the end-point. LD A,(05C7Dh) ; COORDS-x CALL L2D28 ; routine STACK-A RST 28H ;; FP-CALC ty, tx, coords_x. .DEFB 003h ;;subtract ty, rx. ; Next calculate the relative y coordinate to the end-point. .DEFB 001h ;;exchange rx, ty. .DEFB 038h ;;end-calc rx, ty. LD A,(05C7Eh) ; COORDS-y CALL L2D28 ; routine STACK-A RST 28H ;; FP-CALC rx, ty, coords_y .DEFB 003h ;;subtract rx, ry. .DEFB 038h ;;end-calc rx, ry. ; Finally draw the last straight line. ;; LINE-DRAW L2477: CALL L24B7 ; routine DRAW-LINE draws to the relative ; coordinates (rx, ry). JP L0D4D ; jump back and exit via TEMPS >>> ; -------------------------------------------- ; THE 'INITIAL CIRCLE/DRAW PARAMETERS' ROUTINE ; -------------------------------------------- ; Begin by calculating the number of chords which will be returned in B. ; A rule of thumb is employed that uses a value z which for a circle is the ; radius and for an arc is the diameter with, as it happens, a pinch more if ; the arc is on a slope. ; ; NUMBER OF STRAIGHT LINES = ANGLE OF ROTATION * SQUARE ROOT ( Z ) / 2 ;; CD-PRMS1 L247D: RST 28H ;; FP-CALC z. .DEFB 031h ;;duplicate z, z. .DEFB 028h ;;sqr z, sqr(z). .DEFB 034h ;;stk-data z, sqr(z), 2. .DEFB 032h ;;Exponent: 082h, Bytes: 1 .DEFB 00h ;;(+00,+00,+00) .DEFB 001h ;;exchange z, 2, sqr(z). .DEFB 005h ;;division z, 2/sqr(z). .DEFB 0E5h ;;get-mem-5 z, 2/sqr(z), ANGLE. .DEFB 001h ;;exchange z, ANGLE, 2/sqr (z) .DEFB 005h ;;division z, ANGLE*sqr(z)/2 (= No. of lines) .DEFB 02Ah ;;abs (for arc only) .DEFB 038h ;;end-calc z, number of lines. ; As an example for a circle of radius 87 the number of lines will be 29. CALL L2DD5 ; routine FP-TO-A ; The value is compressed into A register, no carry with valid circle. JR C,L2495 ; forward, if over 256, to USE-252 ; now make a multiple of 4 e.g. 29 becomes 28 AND 0FCh ; AND 252 ; Adding 4 could set carry for arc, for the circle example, 28 becomes 32. ADD A,004h ; adding 4 could set carry if result is 256. JR NC,L2497 ; forward if less than 256 to DRAW-SAVE ; For an arc, a limit of 252 is imposed. ;; USE-252 L2495: LD A,0FCh ; Use a value of 252 (for arc). ; For both arcs and circles, constants derived from the central angle are ; stored in the 'mem' locations. Some are not relevant for the circle. ;; DRAW-SAVE L2497: PUSH AF ; Save the line count (A) on the machine stack. CALL L2D28 ; Routine STACK-A stacks the modified count(A). RST 28H ;; FP-CALC z, A. .DEFB 0E5h ;;get-mem-5 z, A, ANGLE. .DEFB 001h ;;exchange z, ANGLE, A. .DEFB 005h ;;division z, ANGLE/A. (Angle/count = a) .DEFB 031h ;;duplicate z, a, a. ; Note. that cos (a) could be formed here directly using 'cos' and stored in ; mem-3 but that would spoil a good story and be slightly slower, as also ; would using square roots to form cos (a) from sin (a). .DEFB 01Fh ;;sin z, a, sin(a) .DEFB 0C4h ;;st-mem-4 z, a, sin(a) .DEFB 002h ;;delete z, a. .DEFB 031h ;;duplicate z, a, a. .DEFB 0A2h ;;stk-half z, a, a, 1/2. .DEFB 004h ;;multiply z, a, a/2. .DEFB 01Fh ;;sin z, a, sin(a/2). ; Note. after second sin, mem-0 and mem-1 become free. .DEFB 0C1h ;;st-mem-1 z, a, sin(a/2). .DEFB 001h ;;exchange z, sin(a/2), a. .DEFB 0C0h ;;st-mem-0 z, sin(a/2), a. (for arc only) ; Now form cos(a) from sin(a/2) using the 'DOUBLE ANGLE FORMULA'. .DEFB 002h ;;delete z, sin(a/2). .DEFB 031h ;;duplicate z, sin(a/2), sin(a/2). .DEFB 004h ;;multiply z, sin(a/2)*sin(a/2). .DEFB 031h ;;duplicate z, sin(a/2)*sin(a/2), ;; sin(a/2)*sin(a/2). .DEFB 00Fh ;;addition z, 2*sin(a/2)*sin(a/2). .DEFB 0A1h ;;stk-one z, 2*sin(a/2)*sin(a/2), 1. .DEFB 003h ;;subtract z, 2*sin(a/2)*sin(a/2)-1. .DEFB 01Bh ;;negate z, 1-2*sin(a/2)*sin(a/2). .DEFB 0C3h ;;st-mem-3 z, cos(a). .DEFB 002h ;;delete z. .DEFB 038h ;;end-calc z. ; The radius/diameter is left on the calculator stack. POP BC ; Restore the line count to the B register. RET ; Return. ; -------------------------- ; THE 'DOUBLE ANGLE FORMULA' ; -------------------------- ; This formula forms cos(a) from sin(a/2) using simple arithmetic. ; ; THE GEOMETRIC PROOF OF FORMULA cos (a) = 1 - 2 * sin(a/2) * sin(a/2) ; ; ; A ; ; . /|\ ; . / | \ ; . / | \ ; . / |a/2\ ; . / | \ ; . 1 / | \ ; . / | \ ; . / | \ ; . / | \ ; . a/2 D / a E|-+ \ ; B ---------------------/----------+-+--------\ C ; <- 1 -><- 1 -> ; ; cos a = 1 - 2 * sin(a/2) * sin(a/2) ; ; The figure shows a right triangle that inscribes a circle of radius 1 with ; centre, or origin, D. Line BC is the diameter of length 2 and A is a point ; on the circle. The periphery angle BAC is therefore a right angle by the ; Rule of Thales. ; Line AC is a chord touching two points on the circle and the angle at the ; centre is (a). ; Since the vertex of the largest triangle B touches the circle, the ; inscribed angle (a/2) is half the central angle (a). ; The cosine of (a) is the length DE as the hypotenuse is of length 1. ; This can also be expressed as 1-length CE. Examining the triangle at the ; right, the top angle is also (a/2) as angle BAE and EBA add to give a right ; angle as do BAE and EAC. ; So cos (a) = 1 - AC * sin(a/2) ; Looking at the largest triangle, side AC can be expressed as ; AC = 2 * sin(a/2) and so combining these we get ; cos (a) = 1 - 2 * sin(a/2) * sin(a/2). ; ; "I will be sufficiently rewarded if when telling it to others, you will ; not claim the discovery as your own, but will say it is mine." ; - Thales, 640 - 546 B.C. ; ; -------------------------- ; THE 'LINE DRAWING' ROUTINE ; -------------------------- ; ; ;; DRAW-LINE L24B7: CALL L2307 ; routine STK-TO-BC LD A,C ; CP B ; JR NC,L24C4 ; to DL-X-GE-Y LD L,C ; PUSH DE ; XOR A ; LD E,A ; JR L24CB ; to DL-LARGER ; --- ;; DL-X-GE-Y L24C4: OR C ; RET Z ; LD L,B ; LD B,C ; PUSH DE ; LD D,00h ; ;; DL-LARGER L24CB: LD H,B ; LD A,B ; RRA ; ;; D-L-LOOP L24CE: ADD A,L ; JR C,L24D4 ; to D-L-DIAG CP H ; JR C,L24DB ; to D-L-HR-VT ;; D-L-DIAG L24D4: SUB H ; LD C,A ; EXX ; POP BC ; PUSH BC ; JR L24DF ; to D-L-STEP ; --- ;; D-L-HR-VT L24DB: LD C,A ; PUSH DE ; EXX ; POP BC ; ;; D-L-STEP L24DF: LD HL,(05C7Dh) ; COORDS LD A,B ; ADD A,H ; LD B,A ; LD A,C ; INC A ; ADD A,L ; JR C,L24F7 ; to D-L-RANGE JR Z,L24F9 ; to REPORT-Bc ;; D-L-PLOT L24EC: DEC A ; LD C,A ; CALL L22E5 ; routine PLOT-SUB EXX ; LD A,C ; DJNZ L24CE ; to D-L-LOOP POP DE ; RET ; ; --- ;; D-L-RANGE L24F7: JR Z,L24EC ; to D-L-PLOT ;; REPORT-Bc L24F9: RST 08H ; ERROR-1 .DEFB 00Ah ; Error Report: Integer out of range ;*********************************** ;** Part 8. EXPRESSION EVALUATION ** ;*********************************** ; ; It is a this stage of the ROM that the Spectrum ceases altogether to be ; just a colourful novelty. One remarkable feature is that in all previous ; commands when the Spectrum is expecting a number or a string then an ; expression of the same type can be substituted ad infinitum. ; This is the routine that evaluates that expression. ; This is what causes 2 + 2 to give the answer 4. ; That is quite easy to understand. However you don't have to make it much ; more complex to start a remarkable juggling act. ; e.g. PRINT 2 * (VAL "2+2" + TAN 3) ; In fact, provided there is enough free RAM, the Spectrum can evaluate ; an expression of unlimited complexity. ; Apart from a couple of minor glitches, which you can now correct, the ; system is remarkably robust. ; --------------------------------- ; Scan expression or sub-expression ; --------------------------------- ; ; ;; SCANNING L24FB: RST 18H ; GET-CHAR LD B,00h ; priority marker zero is pushed on stack ; to signify end of expression when it is ; popped off again. PUSH BC ; put in on stack. ; and proceed to consider the first character ; of the expression. ;; S-LOOP-1 L24FF: LD C,A ; store the character while a look up is done. LD HL,L2596 ; Address: scan-func CALL L16DC ; routine INDEXER is called to see if it is ; part of a limited range '+', '(', 'ATTR' etc. LD A,C ; fetch the character back JP NC,L2684 ; jump forward to S-ALPHNUM if not in primary ; operators and functions to consider in the ; first instance a digit or a variable and ; then anything else. >>> LD B,00h ; but here if it was found in table so LD C,(HL) ; fetch offset from table and make B zero. ADD HL,BC ; add the offset to position found JP (HL) ; and jump to the routine e.g. S-BIN ; making an indirect exit from there. ; ------------------------------------------------------------------------- ; The four service subroutines for routines in the scanning function table ; ------------------------------------------------------------------------- ; PRINT """Hooray!"" he cried." ;; S-QUOTE-S L250F: CALL L0074 ; routine CH-ADD+1 points to next character ; and fetches that character. INC BC ; increase length counter. CP 00Dh ; is it carriage return ? ; inside a quote. JP Z,L1C8A ; jump back to REPORT-C if so. ; 'Nonsense in BASIC'. CP 022h ; is it a quote '"' ? JR NZ,L250F ; back to S-QUOTE-S if not for more. CALL L0074 ; routine CH-ADD+1 CP 022h ; compare with possible adjacent quote RET ; return. with zero set if two together. ; --- ; This subroutine is used to get two coordinate expressions for the three ; functions SCREEN$, ATTR and POINT that have two fixed parameters and ; therefore require surrounding braces. ;; S-2-COORD L2522: RST 20H ; NEXT-CHAR CP 028h ; is it the opening '(' ? JR NZ,L252D ; forward to S-RPORT-C if not ; 'Nonsense in BASIC'. CALL L1C79 ; routine NEXT-2NUM gets two comma-separated ; numeric expressions. Note. this could cause ; many more recursive calls to SCANNING but ; the parent function will be evaluated fully ; before rejoining the main juggling act. RST 18H ; GET-CHAR CP 029h ; is it the closing ')' ? ;; S-RPORT-C L252D: JP NZ,L1C8A ; jump back to REPORT-C if not. ; 'Nonsense in BASIC'. ; ------------ ; Check syntax ; ------------ ; This routine is called on a number of occasions to check if syntax is being ; checked or if the program is being run. To test the flag inline would use ; four bytes of code, but a call instruction only uses 3 bytes of code. ;; SYNTAX-Z L2530: BIT 7,(IY+001h) ; test FLAGS - checking syntax only ? RET ; return. ; ---------------- ; Scanning SCREEN$ ; ---------------- ; This function returns the code of a bit-mapped character at screen ; position at line C, column B. It is unable to detect the mosaic characters ; which are not bit-mapped but detects the ASCII 32 - 127 range. ; The bit-mapped UDGs are ignored which is curious as it requires only a ; few extra bytes of code. As usual, anything to do with CHARS is weird. ; If no match is found a null string is returned. ; No actual check on ranges is performed - that's up to the BASIC programmer. ; No real harm can come from SCREEN$(255,255) although the BASIC manual ; says that invalid values will be trapped. ; Interestingly, in the Pitman pocket guide, 1984, Vickers says that the ; range checking will be performed. ;; S-SCRN$-S L2535: CALL L2307 ; routine STK-TO-BC. LD HL,(05C36h) ; fetch address of CHARS. LD DE,00100h ; fetch offset to chr$ 32 ADD HL,DE ; and find start of bitmaps. ; Note. not inc h. ?? LD A,C ; transfer line to A. RRCA ; multiply RRCA ; by RRCA ; thirty-two. AND 0E0h ; and with 11100000 XOR B ; combine with column 00h - 01Fh LD E,A ; to give the low byte of top line LD A,C ; column to A range 00000000 to 00011111 AND 018h ; and with 00011000 XOR 040h ; xor with 01000000 (high byte screen start) LD D,A ; register DE now holds start address of cell. LD B,060h ; there are 96 characters in ASCII set. ;; S-SCRN-LP L254F: PUSH BC ; save count PUSH DE ; save screen start address PUSH HL ; save bitmap start LD A,(DE) ; first byte of screen to A XOR (HL) ; xor with corresponding character byte JR Z,L255A ; forward to S-SC-MTCH if they match ; if inverse result would be 0FFh ; if any other then mismatch INC A ; set to 00h if inverse JR NZ,L2573 ; forward to S-SCR-NXT if a mismatch DEC A ; restore 0FFh ; a match has been found so seven more to test. ;; S-SC-MTCH L255A: LD C,A ; load C with inverse mask 00h or 0FFh LD B,007h ; count seven more bytes ;; S-SC-ROWS L255D: INC D ; increment screen address. INC HL ; increment bitmap address. LD A,(DE) ; byte to A XOR (HL) ; will give 00h or 0FFh (inverse) XOR C ; xor with inverse mask JR NZ,L2573 ; forward to S-SCR-NXT if no match. DJNZ L255D ; back to S-SC-ROWS until all eight matched. ; continue if a match of all eight bytes was found POP BC ; discard the POP BC ; saved POP BC ; pointers LD A,080h ; the endpoint of character set SUB B ; subtract the counter ; to give the code 32-127 LD BC,001h ; make one space in workspace. RST 30H ; BC-SPACES creates the space sliding ; the calculator stack upwards. LD (DE),A ; start is addressed by DE, so insert code JR L257D ; forward to S-SCR-STO ; --- ; the jump was here if no match and more bitmaps to test. ;; S-SCR-NXT L2573: POP HL ; restore the last bitmap start LD DE,008h ; and prepare to add 8. ADD HL,DE ; now addresses next character bitmap. POP DE ; restore screen address POP BC ; and character counter in B DJNZ L254F ; back to S-SCRN-LP if more characters. LD C,B ; B is now zero, so BC now zero. ;; S-SCR-STO L257D: JP L2AB2 ; to STK-STO-$ to store the string in ; workspace or a string with zero length. ; (value of DE doesn't matter in last case) ; Note. this exit seems correct but the general-purpose routine S-STRING ; that calls this one will also stack any of its string results so this ; leads to a double storing of the result in this case. ; The instruction at L257D should just be a RET. ; credit Stephen Kelly and others, 1982. ; ------------- ; Scanning ATTR ; ------------- ; This function subroutine returns the attributes of a screen location - ; a numeric result. ; Again it's up to the BASIC programmer to supply valid values of line/column. ;; S-ATTR-S L2580: CALL L2307 ; routine STK-TO-BC fetches line to C, ; and column to B. LD A,C ; line to A 00h - 017h (max 00010111) RRCA ; rotate RRCA ; bits RRCA ; left. LD C,A ; store in C as an intermediate value. AND 0E0h ; pick up bits 11100000 ( was 00011100 ) XOR B ; combine with column 00h - 01Fh LD L,A ; low byte now correct. LD A,C ; bring back intermediate result from C AND 003h ; mask to give correct third of ; screen 00h - 002h XOR 058h ; combine with base address. LD H,A ; high byte correct. LD A,(HL) ; pick up the colour attribute. JP L2D28 ; forward to STACK-A to store result ; and make an indirect exit. ; ----------------------- ; Scanning function table ; ----------------------- ; This table is used by INDEXER routine to find the offsets to ; four operators and eight functions. e.g. 0A8h is the token 'FN'. ; This table is used in the first instance for the first character of an ; expression or by a recursive call to SCANNING for the first character of ; any sub-expression. It eliminates functions that have no argument or ; functions that can have more than one argument and therefore require ; braces. By eliminating and dealing with these now it can later take a ; simplistic approach to all other functions and assume that they have ; one argument. ; Similarly by eliminating BIN and '.' now it is later able to assume that ; all numbers begin with a digit and that the presence of a number or ; variable can be detected by a call to ALPHANUM. ; By default all expressions are positive and the spurious '+' is eliminated ; now as in print +2. This should not be confused with the operator '+'. ; Note. this does allow a degree of nonsense to be accepted as in ; PRINT +"3 is the greatest.". ; An acquired programming skill is the ability to include brackets where ; they are not necessary. ; A bracket at the start of a sub-expression may be spurious or necessary ; to denote that the contained expression is to be evaluated as an entity. ; In either case this is dealt with by recursive calls to SCANNING. ; An expression that begins with a quote requires special treatment. ;; scan-func L2596: .DEFB 022h,01Ch ;L25B3-$-1 ; 01Ch offset to S-QUOTE .DEFB '(',04Fh ;L25E8-$-1 ; 04Fh offset to S-BRACKET .DEFB '.',0F2h ;L268D-$-1 ; 0F2h offset to S-DECIMAL .DEFB '+',012h ;L25AF-$-1 ; 012h offset to S-U-PLUS .DEFB 0A8h,056h ;L25F5-$-1 ; 056h offset to S-FN .DEFB 0A5h,057h ;L25F8-$-1 ; 057h offset to S-RND .DEFB 0A7h,084h ;L2627-$-1 ; 084h offset to S-PI .DEFB 0A6h,08Fh ;L2634-$-1 ; 08Fh offset to S-INKEY$ .DEFB 0C4h,0E6h ;L268D-$-1 ; 0E6h offset to S-BIN .DEFB 0AAh,0BFh ;L2668-$-1 ; 0BFh offset to S-SCREEN$ .DEFB 0ABh,0C7h ;L2672-$-1 ; 0C7h offset to S-ATTR .DEFB 0A9h,0CEh ;L267B-$-1 ; 0CEh offset to S-POINT .DEFB 00h ; zero end marker ; -------------------------- ; Scanning function routines ; -------------------------- ; These are the 11 subroutines accessed by the above table. ; S-BIN and S-DECIMAL are the same ; The 1-byte offset limits their location to within 255 bytes of their ; entry in the table. ; -> ;; S-U-PLUS L25AF: RST 20H ; NEXT-CHAR just ignore JP L24FF ; to S-LOOP-1 ; --- ; -> ;; S-QUOTE L25B3: RST 18H ; GET-CHAR INC HL ; address next character (first in quotes) PUSH HL ; save start of quoted text. LD BC,000h ; initialize length of string to zero. CALL L250F ; routine S-QUOTE-S JR NZ,L25D9 ; forward to S-Q-PRMS if ;; S-Q-AGAIN L25BE: CALL L250F ; routine S-QUOTE-S copies string until a ; quote is encountered JR Z,L25BE ; back to S-Q-AGAIN if two quotes WERE ; together. ; but if just an isolated quote then that terminates the string. CALL L2530 ; routine SYNTAX-Z JR Z,L25D9 ; forward to S-Q-PRMS if checking syntax. RST 30H ; BC-SPACES creates the space for true ; copy of string in workspace. POP HL ; re-fetch start of quoted text. PUSH DE ; save start in workspace. ;; S-Q-COPY L25CB: LD A,(HL) ; fetch a character from source. INC HL ; advance source address. LD (DE),A ; place in destination. INC DE ; advance destination address. CP 022h ; was it a '"' just copied ? JR NZ,L25CB ; back to S-Q-COPY to copy more if not LD A,(HL) ; fetch adjacent character from source. INC HL ; advance source address. CP 022h ; is this '"' ? - i.e. two quotes together ? JR Z,L25CB ; to S-Q-COPY if so including just one of the ; pair of quotes. ; proceed when terminating quote encountered. ;; S-Q-PRMS L25D9: DEC BC ; decrease count by 1. POP DE ; restore start of string in workspace. ;; S-STRING L25DB: LD HL,05C3Bh ; Address FLAGS system variable. RES 6,(HL) ; signal string result. BIT 7,(HL) ; is syntax being checked. CALL NZ,L2AB2 ; routine STK-STO-$ is called in runtime. JP L2712 ; jump forward to S-CONT-2 ===> ; --- ; -> ;; S-BRACKET L25E8: RST 20H ; NEXT-CHAR CALL L24FB ; routine SCANNING is called recursively. CP 029h ; is it the closing ')' ? JP NZ,L1C8A ; jump back to REPORT-C if not ; 'Nonsense in BASIC' RST 20H ; NEXT-CHAR JP L2712 ; jump forward to S-CONT-2 ===> ; --- ; -> ;; S-FN L25F5: JP L27BD ; jump forward to S-FN-SBRN. ; -------------------------------------------------------------------- ; ; RANDOM THEORY from the ZX81 manual by Steven Vickers ; ; (same algorithm as the ZX Spectrum). ; ; Chapter 5. Exercise 6. (For mathematicians only.) ; ; Let p be a [large] prime, & let a be a primitive root modulo p. ; Then if b_i is the residue of a^i modulo p (1<=b_i<p-1), the ; sequence ; ; (b_i-1)/(p-1) ; ; is a cyclical sequence of p-1 distinct numbers in the range 0 to 1 ; (excluding 1). By choosing a suitably, these can be made to look ; fairly random. ; ; 65537 is a Mersenne prime 2^16-1. Note. ; ; Use this, & Gauss' law of quadratic reciprocity, to show that 75 ; is a primitive root modulo 65537. ; ; The ZX81 uses p=65537 & a=75, & stores some b_i-1 in memory. ; The function RND involves replacing b_i-1 in memory by b_(i+1)-1, ; & yielding the result (b_(i+1)-1)/(p-1). RAND n (with 1<=n<=65535) ; makes b_i equal to n+1. ; ; -------------------------------------------------------------------- ; ; Steven Vickers writing in comp.sys.sinclair on 20-DEC-1993 ; ; Note. (Of course, 65537 is 2^16 + 1, not -1.) ; ; Consider arithmetic modulo a prime p. There are p residue classes, and the ; non-zero ones are all invertible. Hence under multiplication they form a ; group (Fp*, say) of order p-1; moreover (and not so obvious) Fp* is cyclic. ; Its generators are the "primitive roots". The "quadratic residues modulo p" ; are the squares in Fp*, and the "Legendre symbol" (d/p) is defined (when p ; does not divide d) as +1 or -1, according as d is or is not a quadratic ; residue mod p. ; ; In the case when p = 65537, we can show that d is a primitive root if and ; only if it's not a quadratic residue. For let w be a primitive root, d ; congruent to w^r (mod p). If d is not primitive, then its order is a proper ; factor of 65536: hence w^{32768*r} = 1 (mod p), so 65536 divides 32768*r, ; and hence r is even and d is a square (mod p). Conversely, the squares in ; Fp* form a subgroup of (Fp*)^2 of index 2, and so cannot be generators. ; ; Hence to check whether 75 is primitive mod 65537, we want to calculate that ; (75/65537) = -1. There is a multiplicative formula (ab/p) = (a/p)(b/p) (mod ; p), so (75/65537) = (5/65537)^2 * (3/65537) = (3/65537). Now the law of ; quadratic reciprocity says that if p and q are distinct odd primes, then ; ; (p/q)(q/p) = (-1)^{(p-1)(q-1)/4} ; ; Hence (3/65537) = (65537/3) * (-1)^{65536*2/4} = (65537/3) ; = (2/3) (because 65537 = 2 mod 3) ; = -1 ; ; (I referred to Pierre Samuel's "Algebraic Theory of Numbers".) ; ; -> ;; S-RND L25F8: CALL L2530 ; routine SYNTAX-Z JR Z,L2625 ; forward to S-RND-END if checking syntax. LD BC,(05C76h) ; fetch system variable SEED CALL L2D2B ; routine STACK-BC places on calculator stack RST 28H ;; FP-CALC ;s. .DEFB 0A1h ;;stk-one ;s,1. .DEFB 00Fh ;;addition ;s+1. .DEFB 034h ;;stk-data ; .DEFB 037h ;;Exponent: 087h, ;;Bytes: 1 .DEFB 016h ;;(+00,+00,+00) ;s+1,75. .DEFB 004h ;;multiply ;(s+1)*75 = v .DEFB 034h ;;stk-data ;v. .DEFB 080h ;;Bytes: 3 .DEFB 041h ;;Exponent 091h .DEFB 00h,00h,080h ;;(+00) ;v,65537. .DEFB 032h ;;n-mod-m ;remainder, result. .DEFB 002h ;;delete ;remainder. .DEFB 0A1h ;;stk-one ;remainder, 1. .DEFB 003h ;;subtract ;remainder - 1. = rnd .DEFB 031h ;;duplicate ;rnd,rnd. .DEFB 038h ;;end-calc CALL L2DA2 ; routine FP-TO-BC LD (05C76h),BC ; store in SEED for next starting point. LD A,(HL) ; fetch exponent AND A ; is it zero ? JR Z,L2625 ; forward if so to S-RND-END SUB 010h ; reduce exponent by 2^16 LD (HL),A ; place back ;; S-RND-END L2625: JR L2630 ; forward to S-PI-END ; --- ; the number PI 3.14159... ; -> ;; S-PI L2627: CALL L2530 ; routine SYNTAX-Z JR Z,L2630 ; to S-PI-END if checking syntax. RST 28H ;; FP-CALC .DEFB 0A3h ;;stk-pi/2 pi/2. .DEFB 038h ;;end-calc INC (HL) ; increment the exponent leaving pi ; on the calculator stack. ;; S-PI-END L2630: RST 20H ; NEXT-CHAR JP L26C3 ; jump forward to S-NUMERIC ; --- ; -> ;; S-INKEY$ L2634: LD BC,0105Ah ; priority 010h, operation code 01Ah ('read-in') ; +040h for string result, numeric operand. ; set this up now in case we need to use the ; calculator. RST 20H ; NEXT-CHAR CP 023h ; '#' ? JP Z,L270D ; to S-PUSH-PO if so to use the calculator ; single operation ; to read from network/RS232 etc. . ; else read a key from the keyboard. LD HL,05C3Bh ; fetch FLAGS RES 6,(HL) ; signal string result. BIT 7,(HL) ; checking syntax ? JR Z,L2665 ; forward to S-INK$-EN if so CALL L028E ; routine KEY-SCAN key in E, shift in D. LD C,00h ; the length of an empty string JR NZ,L2660 ; to S-IK$-STK to store empty string if ; no key returned. CALL L031E ; routine K-TEST get main code in A JR NC,L2660 ; to S-IK$-STK to stack null string if ; invalid DEC D ; D is expected to be FLAGS so set bit 3 0FFh ; 'L' Mode so no keywords. LD E,A ; main key to A ; C is MODE 0 'KLC' from above still. CALL L0333 ; routine K-DECODE PUSH AF ; save the code LD BC,001h ; make room for one character RST 30H ; BC-SPACES POP AF ; bring the code back LD (DE),A ; put the key in workspace LD C,001h ; set C length to one ;; S-IK$-STK L2660: LD B,00h ; set high byte of length to zero CALL L2AB2 ; routine STK-STO-$ ;; S-INK$-EN L2665: JP L2712 ; to S-CONT-2 ===> ; --- ; -> ;; S-SCREEN$ L2668: CALL L2522 ; routine S-2-COORD CALL NZ,L2535 ; routine S-SCRN$-S RST 20H ; NEXT-CHAR JP L25DB ; forward to S-STRING to stack result ; --- ; -> ;; S-ATTR L2672: CALL L2522 ; routine S-2-COORD CALL NZ,L2580 ; routine S-ATTR-S RST 20H ; NEXT-CHAR JR L26C3 ; forward to S-NUMERIC ; --- ; -> ;; S-POINT L267B: CALL L2522 ; routine S-2-COORD CALL NZ,L22CB ; routine POINT-SUB RST 20H ; NEXT-CHAR JR L26C3 ; forward to S-NUMERIC ; ----------------------------- ; ==> The branch was here if not in table. ;; S-ALPHNUM L2684: CALL L2C88 ; routine ALPHANUM checks if variable or ; a digit. JR NC,L26DF ; forward to S-NEGATE if not to consider ; a '-' character then functions. CP 041h ; compare 'A' JR NC,L26C9 ; forward to S-LETTER if alpha -> ; else must have been numeric so continue ; into that routine. ; This important routine is called during runtime and from LINE-SCAN ; when a BASIC line is checked for syntax. It is this routine that ; inserts, during syntax checking, the invisible floating point numbers ; after the numeric expression. During runtime it just picks these ; numbers up. It also handles BIN format numbers. ; -> ;; S-BIN ;; S-DECIMAL L268D: CALL L2530 ; routine SYNTAX-Z JR NZ,L26B5 ; to S-STK-DEC in runtime ; this route is taken when checking syntax. CALL L2C9B ; routine DEC-TO-FP to evaluate number RST 18H ; GET-CHAR to fetch HL LD BC,006h ; six locations required CALL L1655 ; routine MAKE-ROOM INC HL ; to first new location LD (HL),00Eh ; insert number marker INC HL ; address next EX DE,HL ; make DE destination. LD HL,(05C65h) ; STKEND points to end of stack. LD C,005h ; result is five locations lower AND A ; prepare for true subtraction SBC HL,BC ; point to start of value. LD (05C65h),HL ; update STKEND as we are taking number. LDIR ; Copy five bytes to program location EX DE,HL ; transfer pointer to HL DEC HL ; adjust CALL L0077 ; routine TEMP-PTR1 sets CH-ADD JR L26C3 ; to S-NUMERIC to record nature of result ; --- ; branch here in runtime. ;; S-STK-DEC L26B5: RST 18H ; GET-CHAR positions HL at digit. ;; S-SD-SKIP L26B6: INC HL ; advance pointer LD A,(HL) ; until we find CP 00Eh ; chr 14d - the number indicator JR NZ,L26B6 ; to S-SD-SKIP until a match ; it has to be here. INC HL ; point to first byte of number CALL L33B4 ; routine STACK-NUM stacks it LD (05C5Dh),HL ; update system variable CH_ADD ;; S-NUMERIC L26C3: SET 6,(IY+001h) ; update FLAGS - Signal numeric result JR L26DD ; forward to S-CONT-1 ===> ; actually S-CONT-2 is destination but why ; waste a byte on a jump when a JR will do. ; Actually a JR L2712 can be used. Rats. ; end of functions accessed from scanning functions table. ; -------------------------- ; Scanning variable routines ; -------------------------- ; ; ;; S-LETTER L26C9: CALL L28B2 ; routine LOOK-VARS JP C,L1C2E ; jump back to REPORT-2 if variable not found ; 'Variable not found' ; but a variable is always 'found' if syntax ; is being checked. CALL Z,L2996 ; routine STK-VAR considers a subscript/slice LD A,(05C3Bh) ; fetch FLAGS value CP 0C0h ; compare 11000000 JR C,L26DD ; step forward to S-CONT-1 if string ===> INC HL ; advance pointer CALL L33B4 ; routine STACK-NUM ;; S-CONT-1 L26DD: JR L2712 ; forward to S-CONT-2 ===> ; ---------------------------------------- ; -> the scanning branch was here if not alphanumeric. ; All the remaining functions will be evaluated by a single call to the ; calculator. The correct priority for the operation has to be placed in ; the B register and the operation code, calculator literal in the C register. ; the operation code has bit 7 set if result is numeric and bit 6 is ; set if operand is numeric. so ; 0C0h = numeric result, numeric operand. e.g. 'sin' ; 080h = numeric result, string operand. e.g. 'code' ; 040h = string result, numeric operand. e.g. 'str$' ; 00h = string result, string operand. e.g. 'val$' ;; S-NEGATE L26DF: LD BC,009DBh ; prepare priority 09, operation code 0C0h + ; 'negate' (01Bh) - bits 6 and 7 set for numeric ; result and numeric operand. CP 02Dh ; is it '-' ? JR Z,L270D ; forward if so to S-PUSH-PO LD BC,01018h ; prepare priority 010h, operation code 'val$' - ; bits 6 and 7 reset for string result and ; string operand. CP 0AEh ; is it 'VAL$' ? JR Z,L270D ; forward if so to S-PUSH-PO SUB 0AFh ; subtract token 'CODE' value to reduce ; functions 'CODE' to 'NOT' although the ; upper range is, as yet, unchecked. ; valid range would be 00h - 014h. JP C,L1C8A ; jump back to REPORT-C with anything else ; 'Nonsense in BASIC' LD BC,004F0h ; prepare priority 004h, operation 0C0h + ; 'not' (030h) CP 014h ; is it 'NOT' JR Z,L270D ; forward to S-PUSH-PO if so JP NC,L1C8A ; to REPORT-C if higher ; 'Nonsense in BASIC' LD B,010h ; priority 010h for all the rest ADD A,0DCh ; make range 0DCh - 0EFh ; 0C0h + 'code'(01Ch) thru 'chr$' (02Fh) LD C,A ; transfer 'function' to C CP 0DFh ; is it 'sin' ? JR NC,L2707 ; forward to S-NO-TO-$ with 'sin' through ; 'chr$' as operand is numeric. ; all the rest 'cos' through 'chr$' give a numeric result except 'str$' ; and 'chr$'. RES 6,C ; signal string operand for 'code', 'val' and ; 'len'. ;; S-NO-TO-$ L2707: CP 0EEh ; compare 'str$' JR C,L270D ; forward to S-PUSH-PO if lower as result ; is numeric. RES 7,C ; reset bit 7 of op code for 'str$', 'chr$' ; as result is string. ; >> This is where they were all headed for. ;; S-PUSH-PO L270D: PUSH BC ; push the priority and calculator operation ; code. RST 20H ; NEXT-CHAR JP L24FF ; jump back to S-LOOP-1 to go round the loop ; again with the next character. ; -------------------------------- ; ===> there were many branches forward to here ; An important step after the evaluation of an expression is to test for ; a string expression and allow it to be sliced. If a numeric expression is ; followed by a '(' then the numeric expression is complete. ; Since a string slice can itself be sliced then loop repeatedly ; e.g. (STR$ PI) (3 TO) (TO 2) or "nonsense" (4 TO ) ;; S-CONT-2 L2712: RST 18H ; GET-CHAR ;; S-CONT-3 L2713: CP 028h ; is it '(' ? JR NZ,L2723 ; forward, if not, to S-OPERTR BIT 6,(IY+001h) ; test FLAGS - numeric or string result ? JR NZ,L2734 ; forward, if numeric, to S-LOOP ; if a string expression preceded the '(' then slice it. CALL L2A52 ; routine SLICING RST 20H ; NEXT-CHAR JR L2713 ; loop back to S-CONT-3 ; --------------------------- ; the branch was here when possibility of a '(' has been excluded. ;; S-OPERTR L2723: LD B,00h ; prepare to add LD C,A ; possible operator to C LD HL,L2795 ; Address: 02795h - tbl-of-ops CALL L16DC ; routine INDEXER JR NC,L2734 ; forward to S-LOOP if not in table ; but if found in table the priority has to be looked up. LD C,(HL) ; operation code to C ( B is still zero ) LD HL,L27B0 - 0C3h ; 026EDh is base of table ADD HL,BC ; index into table. LD B,(HL) ; priority to B. ; ------------------ ; Scanning main loop ; ------------------ ; the juggling act ;; S-LOOP L2734: POP DE ; fetch last priority and operation LD A,D ; priority to A CP B ; compare with this one JR C,L2773 ; forward to S-TIGHTER to execute the ; last operation before this one as it has ; higher priority. ; the last priority was greater or equal this one. AND A ; if it is zero then so is this JP Z,L0018 ; jump to exit via get-char pointing at ; next character. ; This may be the character after the ; expression or, if exiting a recursive call, ; the next part of the expression to be ; evaluated. PUSH BC ; save current priority/operation ; as it has lower precedence than the one ; now in DE. ; the 'USR' function is special in that it is overloaded to give two types ; of result. LD HL,05C3Bh ; address FLAGS LD A,E ; new operation to A register CP 0EDh ; is it 0C0h + 'usr-no' (02Dh) ? JR NZ,L274C ; forward to S-STK-LST if not BIT 6,(HL) ; string result expected ? ; (from the lower priority operand we've ; just pushed on stack ) JR NZ,L274C ; forward to S-STK-LST if numeric ; as operand bits match. LD E,099h ; reset bit 6 and substitute 019h 'usr-$' ; for string operand. ;; S-STK-LST L274C: PUSH DE ; now stack this priority/operation CALL L2530 ; routine SYNTAX-Z JR Z,L275B ; forward to S-SYNTEST if checking syntax. LD A,E ; fetch the operation code AND 03Fh ; mask off the result/operand bits to leave ; a calculator literal. LD B,A ; transfer to B register ; now use the calculator to perform the single operation - operand is on ; the calculator stack. ; Note. although the calculator is performing a single operation most ; functions e.g. TAN are written using other functions and literals and ; these in turn are written using further strings of calculator literals so ; another level of magical recursion joins the juggling act for a while ; as the calculator too is calling itself. RST 28H ;; FP-CALC .DEFB 03Bh ;;fp-calc-2 L2758: .DEFB 038h ;;end-calc JR L2764 ; forward to S-RUNTEST ; --- ; the branch was here if checking syntax only. ;; S-SYNTEST L275B: LD A,E ; fetch the operation code to accumulator XOR (IY+001h) ; compare with bits of FLAGS AND 040h ; bit 6 will be zero now if operand ; matched expected result. ;; S-RPORT-C2 L2761: JP NZ,L1C8A ; to REPORT-C if mismatch ; 'Nonsense in BASIC' ; else continue to set flags for next ; the branch is to here in runtime after a successful operation. ;; S-RUNTEST L2764: POP DE ; fetch the last operation from stack LD HL,05C3Bh ; address FLAGS SET 6,(HL) ; set default to numeric result in FLAGS BIT 7,E ; test the operational result JR NZ,L2770 ; forward to S-LOOPEND if numeric RES 6,(HL) ; reset bit 6 of FLAGS to show string result. ;; S-LOOPEND L2770: POP BC ; fetch the previous priority/operation JR L2734 ; back to S-LOOP to perform these ; --- ; the branch was here when a stacked priority/operator had higher priority ; than the current one. ;; S-TIGHTER L2773: PUSH DE ; save high priority op on stack again LD A,C ; fetch lower priority operation code BIT 6,(IY+001h) ; test FLAGS - Numeric or string result ? JR NZ,L2790 ; forward to S-NEXT if numeric result ; if this is lower priority yet has string then must be a comparison. ; Since these can only be evaluated in context and were defaulted to ; numeric in operator look up they must be changed to string equivalents. AND 03Fh ; mask to give true calculator literal ADD A,008h ; augment numeric literals to string ; equivalents. ; 'no-&-no' => 'str-&-no' ; 'no-l-eql' => 'str-l-eql' ; 'no-gr-eq' => 'str-gr-eq' ; 'nos-neql' => 'strs-neql' ; 'no-grtr' => 'str-grtr' ; 'no-less' => 'str-less' ; 'nos-eql' => 'strs-eql' ; 'addition' => 'strs-add' LD C,A ; put modified comparison operator back CP 010h ; is it now 'str-&-no' ? JR NZ,L2788 ; forward to S-NOT-AND if not. SET 6,C ; set numeric operand bit JR L2790 ; forward to S-NEXT ; --- ;; S-NOT-AND L2788: JR C,L2761 ; back to S-RPORT-C2 if less ; 'Nonsense in BASIC'. ; e.g. a$ * b$ CP 017h ; is it 'strs-add' ? JR Z,L2790 ; forward to S-NEXT if so ; (bit 6 and 7 are reset) SET 7,C ; set numeric (Boolean) result for all others ;; S-NEXT L2790: PUSH BC ; now save this priority/operation on stack RST 20H ; NEXT-CHAR JP L24FF ; jump back to S-LOOP-1 ; ------------------ ; Table of operators ; ------------------ ; This table is used to look up the calculator literals associated with ; the operator character. The thirteen calculator operations 003h - 00Fh ; have bits 6 and 7 set to signify a numeric result. ; Some of these codes and bits may be altered later if the context suggests ; a string comparison or operation. ; that is '+', '=', '>', '<', '<=', '>=' or '<>'. ;; tbl-of-ops L2795: .DEFB '+', 0CFh ; 0C0h + 'addition' .DEFB '-', 0C3h ; 0C0h + 'subtract' .DEFB '*', 0C4h ; 0C0h + 'multiply' .DEFB '/', 0C5h ; 0C0h + 'division' .DEFB '^', 0C6h ; 0C0h + 'to-power' .DEFB '=', 0CEh ; 0C0h + 'nos-eql' .DEFB '>', 0CCh ; 0C0h + 'no-grtr' .DEFB '<', 0CDh ; 0C0h + 'no-less' .DEFB 0C7h, 0C9h ; '<=' 0C0h + 'no-l-eql' .DEFB 0C8h, 0CAh ; '>=' 0C0h + 'no-gr-eql' .DEFB 0C9h, 0CBh ; '<>' 0C0h + 'nos-neql' .DEFB 0C5h, 0C7h ; 'OR' 0C0h + 'or' .DEFB 0C6h, 0C8h ; 'AND' 0C0h + 'no-&-no' .DEFB 00h ; zero end-marker. ; ------------------- ; Table of priorities ; ------------------- ; This table is indexed with the operation code obtained from the above ; table 0C3h - 0CFh to obtain the priority for the respective operation. ;; tbl-priors L27B0: .DEFB 006h ; '-' opcode 0C3h .DEFB 008h ; '*' opcode 0C4h .DEFB 008h ; '/' opcode 0C5h .DEFB 00Ah ; '^' opcode 0C6h .DEFB 002h ; 'OR' opcode 0C7h .DEFB 003h ; 'AND' opcode 0C8h .DEFB 005h ; '<=' opcode 0C9h .DEFB 005h ; '>=' opcode 0CAh .DEFB 005h ; '<>' opcode 0CBh .DEFB 005h ; '>' opcode 0CCh .DEFB 005h ; '<' opcode 0CDh .DEFB 005h ; '=' opcode 0CEh .DEFB 006h ; '+' opcode 0CFh ; ---------------------- ; Scanning function (FN) ; ---------------------- ; This routine deals with user-defined functions. ; The definition can be anywhere in the program area but these are best ; placed near the start of the program as we shall see. ; The evaluation process is quite complex as the Spectrum has to parse two ; statements at the same time. Syntax of both has been checked previously ; and hidden locations have been created immediately after each argument ; of the DEF FN statement. Each of the arguments of the FN function is ; evaluated by SCANNING and placed in the hidden locations. Then the ; expression to the right of the DEF FN '=' is evaluated by SCANNING and for ; any variables encountered, a search is made in the DEF FN variable list ; in the program area before searching in the normal variables area. ; ; Recursion is not allowed: i.e. the definition of a function should not use ; the same function, either directly or indirectly ( through another function). ; You'll normally get error 4, ('Out of memory'), although sometimes the system ; will crash. - Vickers, Pitman 1984. ; ; As the definition is just an expression, there would seem to be no means ; of breaking out of such recursion. ; However, by the clever use of string expressions and VAL, such recursion is ; possible. ; e.g. DEF FN a(n) = VAL "n+FN a(n-1)+0" ((n<1) * 10 + 1 TO ) ; will evaluate the full 11-character expression for all values where n is ; greater than zero but just the 11th character, "0", when n drops to zero ; thereby ending the recursion producing the correct result. ; Recursive string functions are possible using VAL$ instead of VAL and the ; null string as the final addend. ; - from a turn of the century newsgroup discussion initiated by Mike Wynne. ;; S-FN-SBRN L27BD: CALL L2530 ; routine SYNTAX-Z JR NZ,L27F7 ; forward to SF-RUN in runtime RST 20H ; NEXT-CHAR CALL L2C8D ; routine ALPHA check for letters A-Z a-z JP NC,L1C8A ; jump back to REPORT-C if not ; 'Nonsense in BASIC' RST 20H ; NEXT-CHAR CP 024h ; is it '$' ? PUSH AF ; save character and flags JR NZ,L27D0 ; forward to SF-BRKT-1 with numeric function RST 20H ; NEXT-CHAR ;; SF-BRKT-1 L27D0: CP 028h ; is '(' ? JR NZ,L27E6 ; forward to SF-RPRT-C if not ; 'Nonsense in BASIC' RST 20H ; NEXT-CHAR CP 029h ; is it ')' ? JR Z,L27E9 ; forward to SF-FLAG-6 if no arguments. ;; SF-ARGMTS L27D9: CALL L24FB ; routine SCANNING checks each argument ; which may be an expression. RST 18H ; GET-CHAR CP 02Ch ; is it a ',' ? JR NZ,L27E4 ; forward if not to SF-BRKT-2 to test bracket RST 20H ; NEXT-CHAR if a comma was found JR L27D9 ; back to SF-ARGMTS to parse all arguments. ; --- ;; SF-BRKT-2 L27E4: CP 029h ; is character the closing ')' ? ;; SF-RPRT-C L27E6: JP NZ,L1C8A ; jump to REPORT-C ; 'Nonsense in BASIC' ; at this point any optional arguments have had their syntax checked. ;; SF-FLAG-6 L27E9: RST 20H ; NEXT-CHAR LD HL,05C3Bh ; address system variable FLAGS RES 6,(HL) ; signal string result POP AF ; restore test against '$'. JR Z,L27F4 ; forward to SF-SYN-EN if string function. SET 6,(HL) ; signal numeric result ;; SF-SYN-EN L27F4: JP L2712 ; jump back to S-CONT-2 to continue scanning. ; --- ; the branch was here in runtime. ;; SF-RUN L27F7: RST 20H ; NEXT-CHAR fetches name AND 0DFh ; AND 11101111 - reset bit 5 - upper-case. LD B,A ; save in B RST 20H ; NEXT-CHAR SUB 024h ; subtract '$' LD C,A ; save result in C JR NZ,L2802 ; forward if not '$' to SF-ARGMT1 RST 20H ; NEXT-CHAR advances to bracket ;; SF-ARGMT1 L2802: RST 20H ; NEXT-CHAR advances to start of argument PUSH HL ; save address LD HL,(05C53h) ; fetch start of program area from PROG DEC HL ; the search starting point is the previous ; location. ;; SF-FND-DF L2808: LD DE,0CEh ; search is for token 'DEF FN' in E, ; statement count in D. PUSH BC ; save C the string test, and B the letter. CALL L1D86 ; routine LOOK-PROG will search for token. POP BC ; restore BC. JR NC,L2814 ; forward to SF-CP-DEF if a match was found. ;; REPORT-P L2812: RST 08H ; ERROR-1 .DEFB 018h ; Error Report: FN without DEF ;; SF-CP-DEF L2814: PUSH HL ; save address of DEF FN CALL L28AB ; routine FN-SKPOVR skips over white-space etc. ; without disturbing CH-ADD. AND 0DFh ; make fetched character upper-case. CP B ; compare with FN name JR NZ,L2825 ; forward to SF-NOT-FD if no match. ; the letters match so test the type. CALL L28AB ; routine FN-SKPOVR skips white-space SUB 024h ; subtract '$' from fetched character CP C ; compare with saved result of same operation ; on FN name. JR Z,L2831 ; forward to SF-VALUES with a match. ; the letters matched but one was string and the other numeric. ;; SF-NOT-FD L2825: POP HL ; restore search point. DEC HL ; make location before LD DE,00200h ; the search is to be for the end of the ; current definition - 2 statements forward. PUSH BC ; save the letter/type CALL L198B ; routine EACH-STMT steps past rejected ; definition. POP BC ; restore letter/type JR L2808 ; back to SF-FND-DF to continue search ; --- ; Success! ; the branch was here with matching letter and numeric/string type. ;; SF-VALUES L2831: AND A ; test A ( will be zero if string '$' - '$' ) CALL Z,L28AB ; routine FN-SKPOVR advances HL past '$'. POP DE ; discard pointer to 'DEF FN'. POP DE ; restore pointer to first FN argument. LD (05C5Dh),DE ; save in CH_ADD CALL L28AB ; routine FN-SKPOVR advances HL past '(' PUSH HL ; save start address in DEF FN *** CP 029h ; is character a ')' ? JR Z,L2885 ; forward to SF-R-BR-2 if no arguments. ;; SF-ARG-LP L2843: INC HL ; point to next character. LD A,(HL) ; fetch it. CP 00Eh ; is it the number marker LD D,040h ; signal numeric in D. JR Z,L2852 ; forward to SF-ARG-VL if numeric. DEC HL ; back to letter CALL L28AB ; routine FN-SKPOVR skips any white-space INC HL ; advance past the expected '$' to ; the 'hidden' marker. LD D,00h ; signal string. ;; SF-ARG-VL L2852: INC HL ; now address first of 5-byte location. PUSH HL ; save address in DEF FN statement PUSH DE ; save D - result type CALL L24FB ; routine SCANNING evaluates expression in ; the FN statement setting FLAGS and leaving ; result as last value on calculator stack. POP AF ; restore saved result type to A XOR (IY+001h) ; xor with FLAGS AND 040h ; and with 01000000 to test bit 6 JR NZ,L288B ; forward to REPORT-Q if type mismatch. ; 'Parameter error' POP HL ; pop the start address in DEF FN statement EX DE,HL ; transfer to DE ?? pop straight into de ? LD HL,(05C65h) ; set HL to STKEND location after value LD BC,005h ; five bytes to move SBC HL,BC ; decrease HL by 5 to point to start. LD (05C65h),HL ; set STKEND 'removing' value from stack. LDIR ; copy value into DEF FN statement EX DE,HL ; set HL to location after value in DEF FN DEC HL ; step back one CALL L28AB ; routine FN-SKPOVR gets next valid character CP 029h ; is it ')' end of arguments ? JR Z,L2885 ; forward to SF-R-BR-2 if so. ; a comma separator has been encountered in the DEF FN argument list. PUSH HL ; save position in DEF FN statement RST 18H ; GET-CHAR from FN statement CP 02Ch ; is it ',' ? JR NZ,L288B ; forward to REPORT-Q if not ; 'Parameter error' RST 20H ; NEXT-CHAR in FN statement advances to next ; argument. POP HL ; restore DEF FN pointer CALL L28AB ; routine FN-SKPOVR advances to corresponding ; argument. JR L2843 ; back to SF-ARG-LP looping until all ; arguments are passed into the DEF FN ; hidden locations. ; --- ; the branch was here when all arguments passed. ;; SF-R-BR-2 L2885: PUSH HL ; save location of ')' in DEF FN RST 18H ; GET-CHAR gets next character in FN CP 029h ; is it a ')' also ? JR Z,L288D ; forward to SF-VALUE if so. ;; REPORT-Q L288B: RST 08H ; ERROR-1 .DEFB 019h ; Error Report: Parameter error ;; SF-VALUE L288D: POP DE ; location of ')' in DEF FN to DE. EX DE,HL ; now to HL, FN ')' pointer to DE. LD (05C5Dh),HL ; initialize CH_ADD to this value. ; At this point the start of the DEF FN argument list is on the machine stack. ; We also have to consider that this defined function may form part of the ; definition of another defined function (though not itself). ; As this defined function may be part of a hierarchy of defined functions ; currently being evaluated by recursive calls to SCANNING, then we have to ; preserve the original value of DEFADD and not assume that it is zero. LD HL,(05C0Bh) ; get original DEFADD address EX (SP),HL ; swap with DEF FN address on stack *** LD (05C0Bh),HL ; set DEFADD to point to this argument list ; during scanning. PUSH DE ; save FN ')' pointer. RST 20H ; NEXT-CHAR advances past ')' in define RST 20H ; NEXT-CHAR advances past '=' to expression CALL L24FB ; routine SCANNING evaluates but searches ; initially for variables at DEFADD POP HL ; pop the FN ')' pointer LD (05C5Dh),HL ; set CH_ADD to this POP HL ; pop the original DEFADD value LD (05C0Bh),HL ; and re-insert into DEFADD system variable. RST 20H ; NEXT-CHAR advances to character after ')' JP L2712 ; to S-CONT-2 - to continue current ; invocation of scanning ; -------------------- ; Used to parse DEF FN ; -------------------- ; e.g. DEF FN s $ ( x ) = b $ ( TO x ) : REM exaggerated ; ; This routine is used 10 times to advance along a DEF FN statement ; skipping spaces and colour control codes. It is similar to NEXT-CHAR ; which is, at the same time, used to skip along the corresponding FN function ; except the latter has to deal with AT and TAB characters in string ; expressions. These cannot occur in a program area so this routine is ; simpler as both colour controls and their parameters are less than space. ;; FN-SKPOVR L28AB: INC HL ; increase pointer LD A,(HL) ; fetch addressed character CP 021h ; compare with space + 1 JR C,L28AB ; back to FN-SKPOVR if less RET ; return pointing to a valid character. ; --------- ; LOOK-VARS ; --------- ; ; ;; LOOK-VARS L28B2: SET 6,(IY+001h) ; update FLAGS - presume numeric result RST 18H ; GET-CHAR CALL L2C8D ; routine ALPHA tests for A-Za-z JP NC,L1C8A ; jump to REPORT-C if not. ; 'Nonsense in BASIC' PUSH HL ; save pointer to first letter ^1 AND 01Fh ; mask lower bits, 1 - 26 decimal 000xxxxx LD C,A ; store in C. RST 20H ; NEXT-CHAR PUSH HL ; save pointer to second character ^2 CP 028h ; is it '(' - an array ? JR Z,L28EF ; forward to V-RUN/SYN if so. SET 6,C ; set 6 signaling string if solitary 010 CP 024h ; is character a '$' ? JR Z,L28DE ; forward to V-STR-VAR SET 5,C ; signal numeric 011 CALL L2C88 ; routine ALPHANUM sets carry if second ; character is alphanumeric. JR NC,L28E3 ; forward to V-TEST-FN if just one character ; It is more than one character but re-test current character so that 6 reset ; This loop renders the similar loop at V-PASS redundant. ;; V-CHAR L28D4: CALL L2C88 ; routine ALPHANUM JR NC,L28EF ; to V-RUN/SYN when no more RES 6,C ; make long named type 001 RST 20H ; NEXT-CHAR JR L28D4 ; loop back to V-CHAR ; --- ;; V-STR-VAR L28DE: RST 20H ; NEXT-CHAR advances past '$' RES 6,(IY+001h) ; update FLAGS - signal string result. ;; V-TEST-FN L28E3: LD A,(05C0Ch) ; load A with DEFADD_hi AND A ; and test for zero. JR Z,L28EF ; forward to V-RUN/SYN if a defined function ; is not being evaluated. ; Note. CALL L2530 ; routine SYNTAX-Z JP NZ,L2951 ; JUMP to STK-F-ARG in runtime and then ; back to this point if no variable found. ;; V-RUN/SYN L28EF: LD B,C ; save flags in B CALL L2530 ; routine SYNTAX-Z JR NZ,L28FD ; to V-RUN to look for the variable in runtime ; if checking syntax the letter is not returned LD A,C ; copy letter/flags to A AND 0E0h ; and with 11100000 to get rid of the letter SET 7,A ; use spare bit to signal checking syntax. LD C,A ; and transfer to C. JR L2934 ; forward to V-SYNTAX ; --- ; but in runtime search for the variable. ;; V-RUN L28FD: LD HL,(05C4Bh) ; set HL to start of variables from VARS ;; V-EACH L2900: LD A,(HL) ; get first character AND 07Fh ; and with 01111111 ; ignoring bit 7 which distinguishes ; arrays or for/next variables. JR Z,L2932 ; to V-80-BYTE if zero as must be 10000000 ; the variables end-marker. CP C ; compare with supplied value. JR NZ,L292A ; forward to V-NEXT if no match. RLA ; destructively test ADD A,A ; bits 5 and 6 of A ; jumping if bit 5 reset or 6 set JP P,L293F ; to V-FOUND-2 strings and arrays JR C,L293F ; to V-FOUND-2 simple and for next ; leaving long name variables. POP DE ; pop pointer to 2nd. char PUSH DE ; save it again PUSH HL ; save variable first character pointer ;; V-MATCHES L2912: INC HL ; address next character in vars area ;; V-SPACES L2913: LD A,(DE) ; pick up letter from prog area INC DE ; and advance address CP 020h ; is it a space JR Z,L2913 ; back to V-SPACES until non-space OR 020h ; convert to range 1 - 26. CP (HL) ; compare with addressed variables character JR Z,L2912 ; loop back to V-MATCHES if a match on an ; intermediate letter. OR 080h ; now set bit 7 as last character of long ; names are inverted. CP (HL) ; compare again JR NZ,L2929 ; forward to V-GET-PTR if no match ; but if they match check that this is also last letter in prog area LD A,(DE) ; fetch next character CALL L2C88 ; routine ALPHANUM sets carry if not alphanum JR NC,L293E ; forward to V-FOUND-1 with a full match. ;; V-GET-PTR L2929: POP HL ; pop saved pointer to char 1 ;; V-NEXT L292A: PUSH BC ; save flags CALL L19B8 ; routine NEXT-ONE gets next variable in DE EX DE,HL ; transfer to HL. POP BC ; restore the flags JR L2900 ; loop back to V-EACH ; to compare each variable ; --- ;; V-80-BYTE L2932: SET 7,B ; will signal not found ; the branch was here when checking syntax ;; V-SYNTAX L2934: POP DE ; discard the pointer to 2nd. character v2 ; in BASIC line/workspace. RST 18H ; GET-CHAR gets character after variable name. CP 028h ; is it '(' ? JR Z,L2943 ; forward to V-PASS ; Note. could go straight to V-END ? SET 5,B ; signal not an array JR L294B ; forward to V-END ; --------------------------- ; the jump was here when a long name matched and HL pointing to last character ; in variables area. ;; V-FOUND-1 L293E: POP DE ; discard pointer to first var letter ; the jump was here with all other matches HL points to first var char. ;; V-FOUND-2 L293F: POP DE ; discard pointer to 2nd prog char v2 POP DE ; drop pointer to 1st prog char v1 PUSH HL ; save pointer to last char in vars RST 18H ; GET-CHAR ;; V-PASS L2943: CALL L2C88 ; routine ALPHANUM JR NC,L294B ; forward to V-END if not ; but it never will be as we advanced past long-named variables earlier. RST 20H ; NEXT-CHAR JR L2943 ; back to V-PASS ; --- ;; V-END L294B: POP HL ; pop the pointer to first character in ; BASIC line/workspace. RL B ; rotate the B register left ; bit 7 to carry BIT 6,B ; test the array indicator bit. RET ; return ; ----------------------- ; Stack function argument ; ----------------------- ; This branch is taken from LOOK-VARS when a defined function is currently ; being evaluated. ; Scanning is evaluating the expression after the '=' and the variable ; found could be in the argument list to the left of the '=' or in the ; normal place after the program. Preference will be given to the former. ; The variable name to be matched is in C. ;; STK-F-ARG L2951: LD HL,(05C0Bh) ; set HL to DEFADD LD A,(HL) ; load the first character CP 029h ; is it ')' ? JP Z,L28EF ; JUMP back to V-RUN/SYN, if so, as there are ; no arguments. ; but proceed to search argument list of defined function first if not empty. ;; SFA-LOOP L295A: LD A,(HL) ; fetch character again. OR 060h ; or with 01100000 presume a simple variable. LD B,A ; save result in B. INC HL ; address next location. LD A,(HL) ; pick up byte. CP 00Eh ; is it the number marker ? JR Z,L296B ; forward to SFA-CP-VR if so. ; it was a string. White-space may be present but syntax has been checked. DEC HL ; point back to letter. CALL L28AB ; routine FN-SKPOVR skips to the '$' INC HL ; now address the hidden marker. RES 5,B ; signal a string variable. ;; SFA-CP-VR L296B: LD A,B ; transfer found variable letter to A. CP C ; compare with expected. JR Z,L2981 ; forward to SFA-MATCH with a match. INC HL ; step INC HL ; past INC HL ; the INC HL ; five INC HL ; bytes. CALL L28AB ; routine FN-SKPOVR skips to next character CP 029h ; is it ')' ? JP Z,L28EF ; jump back if so to V-RUN/SYN to look in ; normal variables area. CALL L28AB ; routine FN-SKPOVR skips past the ',' ; all syntax has been checked and these ; things can be taken as read. JR L295A ; back to SFA-LOOP while there are more ; arguments. ; --- ;; SFA-MATCH L2981: BIT 5,C ; test if numeric JR NZ,L2991 ; to SFA-END if so as will be stacked ; by scanning INC HL ; point to start of string descriptor LD DE,(05C65h) ; set DE to STKEND CALL L33C0 ; routine MOVE-FP puts parameters on stack. EX DE,HL ; new free location to HL. LD (05C65h),HL ; use it to set STKEND system variable. ;; SFA-END L2991: POP DE ; discard POP DE ; pointers. XOR A ; clear carry flag. INC A ; and zero flag. RET ; return. ; ------------------------ ; Stack variable component ; ------------------------ ; This is called to evaluate a complex structure that has been found, in ; runtime, by LOOK-VARS in the variables area. ; In this case HL points to the initial letter, bits 7-5 ; of which indicate the type of variable. ; 010 - simple string, 110 - string array, 100 - array of numbers. ; ; It is called from CLASS-01 when assigning to a string or array including ; a slice. ; It is called from SCANNING to isolate the required part of the structure. ; ; An important part of the runtime process is to check that the number of ; dimensions of the variable match the number of subscripts supplied in the ; BASIC line. ; ; If checking syntax, ; the B register, which counts dimensions is set to zero (256) to allow ; the loop to continue till all subscripts are checked. While doing this it ; is reading dimension sizes from some arbitrary area of memory. Although ; these are meaningless it is of no concern as the limit is never checked by ; int-exp during syntax checking. ; ; The routine is also called from the syntax path of DIM command to check the ; syntax of both string and numeric arrays definitions except that bit 6 of C ; is reset so both are checked as numeric arrays. This ruse avoids a terminal ; slice being accepted as part of the DIM command. ; All that is being checked is that there are a valid set of comma-separated ; expressions before a terminal ')', although, as above, it will still go ; through the motions of checking dummy dimension sizes. ;; STK-VAR L2996: XOR A ; clear A LD B,A ; and B, the syntax dimension counter (256) BIT 7,C ; checking syntax ? JR NZ,L29E7 ; forward to SV-COUNT if so. ; runtime evaluation. BIT 7,(HL) ; will be reset if a simple string. JR NZ,L29AE ; forward to SV-ARRAYS otherwise INC A ; set A to 1, simple string. ;; SV-SIMPLE$ L29A1: INC HL ; address length low LD C,(HL) ; place in C INC HL ; address length high LD B,(HL) ; place in B INC HL ; address start of string EX DE,HL ; DE = start now. CALL L2AB2 ; routine STK-STO-$ stacks string parameters ; DE start in variables area, ; BC length, A=1 simple string ; the only thing now is to consider if a slice is required. RST 18H ; GET-CHAR puts character at CH_ADD in A JP L2A49 ; jump forward to SV-SLICE? to test for '(' ; -------------------------------------------------------- ; the branch was here with string and numeric arrays in runtime. ;; SV-ARRAYS L29AE: INC HL ; step past INC HL ; the total length INC HL ; to address Number of dimensions. LD B,(HL) ; transfer to B overwriting zero. BIT 6,C ; a numeric array ? JR Z,L29C0 ; forward to SV-PTR with numeric arrays DEC B ; ignore the final element of a string array ; the fixed string size. JR Z,L29A1 ; back to SV-SIMPLE$ if result is zero as has ; been created with DIM a$(10) for instance ; and can be treated as a simple string. ; proceed with multi-dimensioned string arrays in runtime. EX DE,HL ; save pointer to dimensions in DE RST 18H ; GET-CHAR looks at the BASIC line CP 028h ; is character '(' ? JR NZ,L2A20 ; to REPORT-3 if not ; 'Subscript wrong' EX DE,HL ; dimensions pointer to HL to synchronize ; with next instruction. ; runtime numeric arrays path rejoins here. ;; SV-PTR L29C0: EX DE,HL ; save dimension pointer in DE JR L29E7 ; forward to SV-COUNT with true no of dims ; in B. As there is no initial comma the ; loop is entered at the midpoint. ; ---------------------------------------------------------- ; the dimension counting loop which is entered at mid-point. ;; SV-COMMA L29C3: PUSH HL ; save counter RST 18H ; GET-CHAR POP HL ; pop counter CP 02Ch ; is character ',' ? JR Z,L29EA ; forward to SV-LOOP if so ; in runtime the variable definition indicates a comma should appear here BIT 7,C ; checking syntax ? JR Z,L2A20 ; forward to REPORT-3 if not ; 'Subscript error' ; proceed if checking syntax of an array? BIT 6,C ; array of strings JR NZ,L29D8 ; forward to SV-CLOSE if so ; an array of numbers. CP 029h ; is character ')' ? JR NZ,L2A12 ; forward to SV-RPT-C if not ; 'Nonsense in BASIC' RST 20H ; NEXT-CHAR moves CH-ADD past the statement RET ; return -> ; --- ; the branch was here with an array of strings. ;; SV-CLOSE L29D8: CP 029h ; as above ')' could follow the expression JR Z,L2A48 ; forward to SV-DIM if so CP 0CCh ; is it 'TO' ? JR NZ,L2A12 ; to SV-RPT-C with anything else ; 'Nonsense in BASIC' ; now backtrack CH_ADD to set up for slicing routine. ; Note. in a BASIC line we can safely backtrack to a colour parameter. ;; SV-CH-ADD L29E0: RST 18H ; GET-CHAR DEC HL ; backtrack HL LD (05C5Dh),HL ; to set CH_ADD up for slicing routine JR L2A45 ; forward to SV-SLICE and make a return ; when all slicing complete. ; ---------------------------------------- ; -> the mid-point entry point of the loop ;; SV-COUNT L29E7: LD HL,000h ; initialize data pointer to zero. ;; SV-LOOP L29EA: PUSH HL ; save the data pointer. RST 20H ; NEXT-CHAR in BASIC area points to an ; expression. POP HL ; restore the data pointer. LD A,C ; transfer name/type to A. CP 0C0h ; is it 11000000 ? ; Note. the letter component is absent if ; syntax checking. JR NZ,L29FB ; forward to SV-MULT if not an array of ; strings. ; proceed to check string arrays during syntax. RST 18H ; GET-CHAR CP 029h ; ')' end of subscripts ? JR Z,L2A48 ; forward to SV-DIM to consider further slice CP 0CCh ; is it 'TO' ? JR Z,L29E0 ; back to SV-CH-ADD to consider a slice. ; (no need to repeat get-char at L29E0) ; if neither, then an expression is required so rejoin runtime loop ?? ; registers HL and DE only point to somewhere meaningful in runtime so ; comments apply to that situation. ;; SV-MULT L29FB: PUSH BC ; save dimension number. PUSH HL ; push data pointer/rubbish. ; DE points to current dimension. CALL L2AEE ; routine DE,(DE+1) gets next dimension in DE ; and HL points to it. EX (SP),HL ; dim pointer to stack, data pointer to HL (*) EX DE,HL ; data pointer to DE, dim size to HL. CALL L2ACC ; routine INT-EXP1 checks integer expression ; and gets result in BC in runtime. JR C,L2A20 ; to REPORT-3 if > HL ; 'Subscript out of range' DEC BC ; adjust returned result from 1-x to 0-x CALL L2AF4 ; routine GET-HL*DE multiplies data pointer by ; dimension size. ADD HL,BC ; add the integer returned by expression. POP DE ; pop the dimension pointer. *** POP BC ; pop dimension counter. DJNZ L29C3 ; back to SV-COMMA if more dimensions ; Note. during syntax checking, unless there ; are more than 256 subscripts, the branch ; back to SV-COMMA is always taken. BIT 7,C ; are we checking syntax ? ; then we've got a joker here. ;; SV-RPT-C L2A12: JR NZ,L2A7A ; forward to SL-RPT-C if so ; 'Nonsense in BASIC' ; more than 256 subscripts in BASIC line. ; but in runtime the number of subscripts are at least the same as dims PUSH HL ; save data pointer. BIT 6,C ; is it a string array ? JR NZ,L2A2C ; forward to SV-ELEM$ if so. ; a runtime numeric array subscript. LD B,D ; register DE has advanced past all dimensions LD C,E ; and points to start of data in variable. ; transfer it to BC. RST 18H ; GET-CHAR checks BASIC line CP 029h ; must be a ')' ? JR Z,L2A22 ; skip to SV-NUMBER if so ; else more subscripts in BASIC line than the variable definition. ;; REPORT-3 L2A20: RST 08H ; ERROR-1 .DEFB 002h ; Error Report: Subscript wrong ; continue if subscripts matched the numeric array. ;; SV-NUMBER L2A22: RST 20H ; NEXT-CHAR moves CH_ADD to next statement ; - finished parsing. POP HL ; pop the data pointer. LD DE,005h ; each numeric element is 5 bytes. CALL L2AF4 ; routine GET-HL*DE multiplies. ADD HL,BC ; now add to start of data in the variable. RET ; return with HL pointing at the numeric ; array subscript. -> ; --------------------------------------------------------------- ; the branch was here for string subscripts when the number of subscripts ; in the BASIC line was one less than in variable definition. ;; SV-ELEM$ L2A2C: CALL L2AEE ; routine DE,(DE+1) gets final dimension ; the length of strings in this array. EX (SP),HL ; start pointer to stack, data pointer to HL. CALL L2AF4 ; routine GET-HL*DE multiplies by element ; size. POP BC ; the start of data pointer is added ADD HL,BC ; in - now points to location before. INC HL ; point to start of required string. LD B,D ; transfer the length (final dimension size) LD C,E ; from DE to BC. EX DE,HL ; put start in DE. CALL L2AB1 ; routine STK-ST-0 stores the string parameters ; with A=0 - a slice or subscript. ; now check that there were no more subscripts in the BASIC line. RST 18H ; GET-CHAR CP 029h ; is it ')' ? JR Z,L2A48 ; forward to SV-DIM to consider a separate ; subscript or/and a slice. CP 02Ch ; a comma is allowed if the final subscript ; is to be sliced e.g. a$(2,3,4 TO 6). JR NZ,L2A20 ; to REPORT-3 with anything else ; 'Subscript error' ;; SV-SLICE L2A45: CALL L2A52 ; routine SLICING slices the string. ; but a slice of a simple string can itself be sliced. ;; SV-DIM L2A48: RST 20H ; NEXT-CHAR ;; SV-SLICE? L2A49: CP 028h ; is character '(' ? JR Z,L2A45 ; loop back if so to SV-SLICE RES 6,(IY+001h) ; update FLAGS - Signal string result RET ; and return. ; --- ; The above section deals with the flexible syntax allowed. ; DIM a$(3,3,10) can be considered as two dimensional array of ten-character ; strings or a 3-dimensional array of characters. ; a$(1,1) will return a 10-character string as will a$(1,1,1 TO 10) ; a$(1,1,1) will return a single character. ; a$(1,1) (1 TO 6) is the same as a$(1,1,1 TO 6) ; A slice can itself be sliced ad infinitum ; b$ () () () () () () (2 TO 10) (2 TO 9) (3) is the same as b$(5) ; ------------------------- ; Handle slicing of strings ; ------------------------- ; The syntax of string slicing is very natural and it is as well to reflect ; on the permutations possible. ; a$() and a$( TO ) indicate the entire string although just a$ would do ; and would avoid coming here. ; h$(16) indicates the single character at position 16. ; a$( TO 32) indicates the first 32 characters. ; a$(257 TO) indicates all except the first 256 characters. ; a$(19000 TO 19999) indicates the thousand characters at position 19000. ; Also a$(9 TO 5) returns a null string not an error. ; This enables a$(2 TO) to return a null string if the passed string is ; of length zero or 1. ; A string expression in brackets can be sliced. e.g. (STR$ PI) (3 TO ) ; We arrived here from SCANNING with CH-ADD pointing to the initial '(' ; or from above. ;; SLICING L2A52: CALL L2530 ; routine SYNTAX-Z CALL NZ,L2BF1 ; routine STK-FETCH fetches parameters of ; string at runtime, start in DE, length ; in BC. This could be an array subscript. RST 20H ; NEXT-CHAR CP 029h ; is it ')' ? e.g. a$() JR Z,L2AAD ; forward to SL-STORE to store entire string. PUSH DE ; else save start address of string XOR A ; clear accumulator to use as a running flag. PUSH AF ; and save on stack before any branching. PUSH BC ; save length of string to be sliced. LD DE,001h ; default the start point to position 1. RST 18H ; GET-CHAR POP HL ; pop length to HL as default end point ; and limit. CP 0CCh ; is it 'TO' ? e.g. a$( TO 10000) JR Z,L2A81 ; to SL-SECOND to evaluate second parameter. POP AF ; pop the running flag. CALL L2ACD ; routine INT-EXP2 fetches first parameter. PUSH AF ; save flag (will be 0FFh if parameter>limit) LD D,B ; transfer the start LD E,C ; to DE overwriting 0001. PUSH HL ; save original length. RST 18H ; GET-CHAR POP HL ; pop the limit length. CP 0CCh ; is it 'TO' after a start ? JR Z,L2A81 ; to SL-SECOND to evaluate second parameter CP 029h ; is it ')' ? e.g. a$(365) ;; SL-RPT-C L2A7A: JP NZ,L1C8A ; jump to REPORT-C with anything else ; 'Nonsense in BASIC' LD H,D ; copy start LD L,E ; to end - just a one character slice. JR L2A94 ; forward to SL-DEFINE. ; --------------------- ;; SL-SECOND L2A81: PUSH HL ; save limit length. RST 20H ; NEXT-CHAR POP HL ; pop the length. CP 029h ; is character ')' ? e.g. a$(7 TO ) JR Z,L2A94 ; to SL-DEFINE using length as end point. POP AF ; else restore flag. CALL L2ACD ; routine INT-EXP2 gets second expression. PUSH AF ; save the running flag. RST 18H ; GET-CHAR LD H,B ; transfer second parameter LD L,C ; to HL. e.g. a$(42 to 99) CP 029h ; is character a ')' ? JR NZ,L2A7A ; to SL-RPT-C if not ; 'Nonsense in BASIC' ; we now have start in DE and an end in HL. ;; SL-DEFINE L2A94: POP AF ; pop the running flag. EX (SP),HL ; put end point on stack, start address to HL ADD HL,DE ; add address of string to the start point. DEC HL ; point to first character of slice. EX (SP),HL ; start address to stack, end point to HL (*) AND A ; prepare to subtract. SBC HL,DE ; subtract start point from end point. LD BC,000h ; default the length result to zero. JR C,L2AA8 ; forward to SL-OVER if start > end. INC HL ; increment the length for inclusive byte. AND A ; now test the running flag. JP M,L2A20 ; jump back to REPORT-3 if 0FFh. ; 'Subscript out of range' LD B,H ; transfer the length LD C,L ; to BC. ;; SL-OVER L2AA8: POP DE ; restore start address from machine stack *** RES 6,(IY+001h) ; update FLAGS - signal string result for ; syntax. ;; SL-STORE L2AAD: CALL L2530 ; routine SYNTAX-Z (UNSTACK-Z?) RET Z ; return if checking syntax. ; but continue to store the string in runtime. ; ------------------------------------ ; other than from above, this routine is called from STK-VAR to stack ; a known string array element. ; ------------------------------------ ;; STK-ST-0 L2AB1: XOR A ; clear to signal a sliced string or element. ; ------------------------- ; this routine is called from chr$, scrn$ etc. to store a simple string result. ; -------------------------- ;; STK-STO-$ L2AB2: RES 6,(IY+001h) ; update FLAGS - signal string result. ; and continue to store parameters of string. ; --------------------------------------- ; Pass five registers to calculator stack ; --------------------------------------- ; This subroutine puts five registers on the calculator stack. ;; STK-STORE L2AB6: PUSH BC ; save two registers CALL L33A9 ; routine TEST-5-SP checks room and puts 5 ; in BC. POP BC ; fetch the saved registers. LD HL,(05C65h) ; make HL point to first empty location STKEND LD (HL),A ; place the 5 registers. INC HL ; LD (HL),E ; INC HL ; LD (HL),D ; INC HL ; LD (HL),C ; INC HL ; LD (HL),B ; INC HL ; LD (05C65h),HL ; update system variable STKEND. RET ; and return. ; ------------------------------------------- ; Return result of evaluating next expression ; ------------------------------------------- ; This clever routine is used to check and evaluate an integer expression ; which is returned in BC, setting A to 0FFh, if greater than a limit supplied ; in HL. It is used to check array subscripts, parameters of a string slice ; and the arguments of the DIM command. In the latter case, the limit check ; is not required and H is set to 0FFh. When checking optional string slice ; parameters, it is entered at the second entry point so as not to disturb ; the running flag A, which may be 00h or 0FFh from a previous invocation. ;; INT-EXP1 L2ACC: XOR A ; set result flag to zero. ; -> The entry point is here if A is used as a running flag. ;; INT-EXP2 L2ACD: PUSH DE ; preserve DE register throughout. PUSH HL ; save the supplied limit. PUSH AF ; save the flag. CALL L1C82 ; routine EXPT-1NUM evaluates expression ; at CH_ADD returning if numeric result, ; with value on calculator stack. POP AF ; pop the flag. CALL L2530 ; routine SYNTAX-Z JR Z,L2AEB ; forward to I-RESTORE if checking syntax so ; avoiding a comparison with supplied limit. PUSH AF ; save the flag. CALL L1E99 ; routine FIND-INT2 fetches value from ; calculator stack to BC producing an error ; if too high. POP DE ; pop the flag to D. LD A,B ; test value for zero and reject OR C ; as arrays and strings begin at 1. SCF ; set carry flag. JR Z,L2AE8 ; forward to I-CARRY if zero. POP HL ; restore the limit. PUSH HL ; and save. AND A ; prepare to subtract. SBC HL,BC ; subtract value from limit. ;; I-CARRY L2AE8: LD A,D ; move flag to accumulator 00h or 0FFh. SBC A,00h ; will set to 0FFh if carry set. ;; I-RESTORE L2AEB: POP HL ; restore the limit. POP DE ; and DE register. RET ; return. ; ----------------------- ; LD DE,(DE+1) Subroutine ; ----------------------- ; This routine just loads the DE register with the contents of the two ; locations following the location addressed by DE. ; It is used to step along the 16-bit dimension sizes in array definitions. ; Note. Such code is made into subroutines to make programs easier to ; write and it would use less space to include the five instructions in-line. ; However, there are so many exchanges going on at the places this is invoked ; that to implement it in-line would make the code hard to follow. ; It probably had a zippier label though as the intention is to simplify the ; program. ;; DE,(DE+1) L2AEE: EX DE,HL ; INC HL ; LD E,(HL) ; INC HL ; LD D,(HL) ; RET ; ; ------------------- ; HL=HL*DE Subroutine ; ------------------- ; This routine calls the mathematical routine to multiply HL by DE in runtime. ; It is called from STK-VAR and from DIM. In the latter case syntax is not ; being checked so the entry point could have been at the second CALL ; instruction to save a few clock-cycles. ;; GET-HL*DE L2AF4: CALL L2530 ; routine SYNTAX-Z. RET Z ; return if checking syntax. CALL L30A9 ; routine HL-HL*DE. JP C,L1F15 ; jump back to REPORT-4 if over 65535. RET ; else return with 16-bit result in HL. ; ----------------- ; THE 'LET' COMMAND ; ----------------- ; Sinclair BASIC adheres to the ANSI-78 standard and a LET is required in ; assignments e.g. LET a = 1 : LET h$ = "hat". ; ; Long names may contain spaces but not colour controls (when assigned). ; a substring can appear to the left of the equals sign. ; An earlier mathematician Lewis Carroll may have been pleased that ; 10 LET Babies cannot manage crocodiles = Babies are illogical AND ; Nobody is despised who can manage a crocodile AND Illogical persons ; are despised ; does not give the 'Nonsense..' error if the three variables exist. ; I digress. ;; LET L2AFF: LD HL,(05C4Dh) ; fetch system variable DEST to HL. BIT 1,(IY+037h) ; test FLAGX - handling a new variable ? JR Z,L2B66 ; forward to L-EXISTS if not. ; continue for a new variable. DEST points to start in BASIC line. ; from the CLASS routines. LD BC,005h ; assume numeric and assign an initial 5 bytes ;; L-EACH-CH L2B0B: INC BC ; increase byte count for each relevant ; character ;; L-NO-SP L2B0C: INC HL ; increase pointer. LD A,(HL) ; fetch character. CP 020h ; is it a space ? JR Z,L2B0C ; back to L-NO-SP is so. JR NC,L2B1F ; forward to L-TEST-CH if higher. CP 010h ; is it 00h - 00Fh ? JR C,L2B29 ; forward to L-SPACES if so. CP 016h ; is it 016h - 01Fh ? JR NC,L2B29 ; forward to L-SPACES if so. ; it was 010h - 015h so step over a colour code. INC HL ; increase pointer. JR L2B0C ; loop back to L-NO-SP. ; --- ; the branch was to here if higher than space. ;; L-TEST-CH L2B1F: CALL L2C88 ; routine ALPHANUM sets carry if alphanumeric JR C,L2B0B ; loop back to L-EACH-CH for more if so. CP 024h ; is it '$' ? JP Z,L2BC0 ; jump forward if so, to L-NEW$ ; with a new string. ;; L-SPACES L2B29: LD A,C ; save length lo in A. LD HL,(05C59h) ; fetch E_LINE to HL. DEC HL ; point to location before, the variables ; end-marker. CALL L1655 ; routine MAKE-ROOM creates BC spaces ; for name and numeric value. INC HL ; advance to first new location. INC HL ; then to second. EX DE,HL ; set DE to second location. PUSH DE ; save this pointer. LD HL,(05C4Dh) ; reload HL with DEST. DEC DE ; point to first. SUB 006h ; subtract six from length_lo. LD B,A ; save count in B. JR Z,L2B4F ; forward to L-SINGLE if it was just ; one character. ; HL points to start of variable name after 'LET' in BASIC line. ;; L-CHAR L2B3E: INC HL ; increase pointer. LD A,(HL) ; pick up character. CP 021h ; is it space or higher ? JR C,L2B3E ; back to L-CHAR with space and less. OR 020h ; make variable lower-case. INC DE ; increase destination pointer. LD (DE),A ; and load to edit line. DJNZ L2B3E ; loop back to L-CHAR until B is zero. OR 080h ; invert the last character. LD (DE),A ; and overwrite that in edit line. ; now consider first character which has bit 6 set LD A,0C0h ; set A 11000000 is xor mask for a long name. ; %101 is xor/or result ; single character numerics rejoin here with %00000000 in mask. ; %011 will be xor/or result ;; L-SINGLE L2B4F: LD HL,(05C4Dh) ; fetch DEST - HL addresses first character. XOR (HL) ; apply variable type indicator mask (above). OR 020h ; make lowercase - set bit 5. POP HL ; restore pointer to 2nd character. CALL L2BEA ; routine L-FIRST puts A in first character. ; and returns with HL holding ; new E_LINE-1 the 080h vars end-marker. ;; L-NUMERIC L2B59: PUSH HL ; save the pointer. ; the value of variable is deleted but remains after calculator stack. RST 28H ;; FP-CALC .DEFB 002h ;;delete ; delete variable value .DEFB 038h ;;end-calc ; DE (STKEND) points to start of value. POP HL ; restore the pointer. LD BC,005h ; start of number is five bytes before. AND A ; prepare for true subtraction. SBC HL,BC ; HL points to start of value. JR L2BA6 ; forward to L-ENTER ==> ; --- ; the jump was to here if the variable already existed. ;; L-EXISTS L2B66: BIT 6,(IY+001h) ; test FLAGS - numeric or string result ? JR Z,L2B72 ; skip forward to L-DELETE$ -*-> ; if string result. ; A numeric variable could be simple or an array element. ; They are treated the same and the old value is overwritten. LD DE,006h ; six bytes forward points to loc past value. ADD HL,DE ; add to start of number. JR L2B59 ; back to L-NUMERIC to overwrite value. ; --- ; -*-> the branch was here if a string existed. ;; L-DELETE$ L2B72: LD HL,(05C4Dh) ; fetch DEST to HL. ; (still set from first instruction) LD BC,(05C72h) ; fetch STRLEN to BC. BIT 0,(IY+037h) ; test FLAGX - handling a complete simple ; string ? JR NZ,L2BAF ; forward to L-ADD$ if so. ; must be a string array or a slice in workspace. ; Note. LET a$(3 TO 6) = h$ will assign "hat " if h$ = "hat" ; and "hats" if h$ = "hatstand". ; ; This is known as Procrustean lengthening and shortening after a ; character Procrustes in Greek legend who made travellers sleep in his bed, ; cutting off their feet or stretching them so they fitted the bed perfectly. ; The bloke was hatstand and slain by Theseus. LD A,B ; test if length OR C ; is zero and RET Z ; return if so. PUSH HL ; save pointer to start. RST 30H ; BC-SPACES creates room. PUSH DE ; save pointer to first new location. PUSH BC ; and length (*) LD D,H ; set DE to point to last location. LD E,L ; INC HL ; set HL to next location. LD (HL),020h ; place a space there. LDDR ; copy bytes filling with spaces. PUSH HL ; save pointer to start. CALL L2BF1 ; routine STK-FETCH start to DE, ; length to BC. POP HL ; restore the pointer. EX (SP),HL ; (*) length to HL, pointer to stack. AND A ; prepare for true subtraction. SBC HL,BC ; subtract old length from new. ADD HL,BC ; and add back. JR NC,L2B9B ; forward if it fits to L-LENGTH. LD B,H ; otherwise set LD C,L ; length to old length. ; "hatstand" becomes "hats" ;; L-LENGTH L2B9B: EX (SP),HL ; (*) length to stack, pointer to HL. EX DE,HL ; pointer to DE, start of string to HL. LD A,B ; is the length zero ? OR C ; JR Z,L2BA3 ; forward to L-IN-W/S if so ; leaving prepared spaces. LDIR ; else copy bytes overwriting some spaces. ;; L-IN-W/S L2BA3: POP BC ; pop the new length. (*) POP DE ; pop pointer to new area. POP HL ; pop pointer to variable in assignment. ; and continue copying from workspace ; to variables area. ; ==> branch here from L-NUMERIC ;; L-ENTER L2BA6: EX DE,HL ; exchange pointers HL=STKEND DE=end of vars. LD A,B ; test the length OR C ; and make a RET Z ; return if zero (strings only). PUSH DE ; save start of destination. LDIR ; copy bytes. POP HL ; address the start. RET ; and return. ; --- ; the branch was here from L-DELETE$ if an existing simple string. ; register HL addresses start of string in variables area. ;; L-ADD$ L2BAF: DEC HL ; point to high byte of length. DEC HL ; to low byte. DEC HL ; to letter. LD A,(HL) ; fetch masked letter to A. PUSH HL ; save the pointer on stack. PUSH BC ; save new length. CALL L2BC6 ; routine L-STRING adds new string at end ; of variables area. ; if no room we still have old one. POP BC ; restore length. POP HL ; restore start. INC BC ; increase INC BC ; length by three INC BC ; to include character and length bytes. JP L19E8 ; jump to indirect exit via RECLAIM-2 ; deleting old version and adjusting pointers. ; --- ; the jump was here with a new string variable. ;; L-NEW$ L2BC0: LD A,0DFh ; indicator mask %11011111 for ; %010xxxxx will be result LD HL,(05C4Dh) ; address DEST first character. AND (HL) ; combine mask with character. ;; L-STRING L2BC6: PUSH AF ; save first character and mask. CALL L2BF1 ; routine STK-FETCH fetches parameters of ; the string. EX DE,HL ; transfer start to HL. ADD HL,BC ; add to length. PUSH BC ; save the length. DEC HL ; point to end of string. LD (05C4Dh),HL ; save pointer in DEST. ; (updated by POINTERS if in workspace) INC BC ; extra byte for letter. INC BC ; two bytes INC BC ; for the length of string. LD HL,(05C59h) ; address E_LINE. DEC HL ; now end of VARS area. CALL L1655 ; routine MAKE-ROOM makes room for string. ; updating pointers including DEST. LD HL,(05C4Dh) ; pick up pointer to end of string from DEST. POP BC ; restore length from stack. PUSH BC ; and save again on stack. INC BC ; add a byte. LDDR ; copy bytes from end to start. EX DE,HL ; HL addresses length low INC HL ; increase to address high byte POP BC ; restore length to BC LD (HL),B ; insert high byte DEC HL ; address low byte location LD (HL),C ; insert that byte POP AF ; restore character and mask ;; L-FIRST L2BEA: DEC HL ; address variable name LD (HL),A ; and insert character. LD HL,(05C59h) ; load HL with E_LINE. DEC HL ; now end of VARS area. RET ; return ; ------------------------------------ ; Get last value from calculator stack ; ------------------------------------ ; ; ;; STK-FETCH L2BF1: LD HL,(05C65h) ; STKEND DEC HL ; LD B,(HL) ; DEC HL ; LD C,(HL) ; DEC HL ; LD D,(HL) ; DEC HL ; LD E,(HL) ; DEC HL ; LD A,(HL) ; LD (05C65h),HL ; STKEND RET ; ; ------------------ ; Handle DIM command ; ------------------ ; e.g. DIM a(2,3,4,7): DIM a$(32) : DIM b$(20,2,768) : DIM c$(20000) ; the only limit to dimensions is memory so, for example, ; DIM a(2,2,2,2,2,2,2,2,2,2,2,2,2) is possible and creates a multi- ; dimensional array of zeros. String arrays are initialized to spaces. ; It is not possible to erase an array, but it can be re-dimensioned to ; a minimal size of 1, after use, to free up memory. ;; DIM L2C02: CALL L28B2 ; routine LOOK-VARS ;; D-RPORT-C L2C05: JP NZ,L1C8A ; jump to REPORT-C if a long-name variable. ; DIM lottery numbers(49) doesn't work. CALL L2530 ; routine SYNTAX-Z JR NZ,L2C15 ; forward to D-RUN in runtime. RES 6,C ; signal 'numeric' array even if string as ; this simplifies the syntax checking. CALL L2996 ; routine STK-VAR checks syntax. CALL L1BEE ; routine CHECK-END performs early exit -> ; the branch was here in runtime. ;; D-RUN L2C15: JR C,L2C1F ; skip to D-LETTER if variable did not exist. ; else reclaim the old one. PUSH BC ; save type in C. CALL L19B8 ; routine NEXT-ONE find following variable ; or position of 080h end-marker. CALL L19E8 ; routine RECLAIM-2 reclaims the ; space between. POP BC ; pop the type. ;; D-LETTER L2C1F: SET 7,C ; signal array. LD B,00h ; initialize dimensions to zero and PUSH BC ; save with the type. LD HL,001h ; make elements one character presuming string BIT 6,C ; is it a string ? JR NZ,L2C2D ; forward to D-SIZE if so. LD L,005h ; make elements 5 bytes as is numeric. ;; D-SIZE L2C2D: EX DE,HL ; save the element size in DE. ; now enter a loop to parse each of the integers in the list. ;; D-NO-LOOP L2C2E: RST 20H ; NEXT-CHAR LD H,0FFh ; disable limit check by setting HL high CALL L2ACC ; routine INT-EXP1 JP C,L2A20 ; to REPORT-3 if > 65280 and then some ; 'Subscript out of range' POP HL ; pop dimension counter, array type PUSH BC ; save dimension size *** INC H ; increment the dimension counter PUSH HL ; save the dimension counter LD H,B ; transfer size LD L,C ; to HL CALL L2AF4 ; routine GET-HL*DE multiplies dimension by ; running total of size required initially ; 1 or 5. EX DE,HL ; save running total in DE RST 18H ; GET-CHAR CP 02Ch ; is it ',' ? JR Z,L2C2E ; loop back to D-NO-LOOP until all dimensions ; have been considered ; when loop complete continue. CP 029h ; is it ')' ? JR NZ,L2C05 ; to D-RPORT-C with anything else ; 'Nonsense in BASIC' RST 20H ; NEXT-CHAR advances to next statement/CR POP BC ; pop dimension counter/type LD A,C ; type to A ; now calculate space required for array variable LD L,B ; dimensions to L since these require 16 bits ; then this value will be doubled LD H,00h ; set high byte to zero ; another four bytes are required for letter(1), total length(2), number of ; dimensions(1) but since we have yet to double allow for two INC HL ; increment INC HL ; increment ADD HL,HL ; now double giving 4 + dimensions * 2 ADD HL,DE ; add to space required for array contents JP C,L1F15 ; to REPORT-4 if > 65535 ; 'Out of memory' PUSH DE ; save data space PUSH BC ; save dimensions/type PUSH HL ; save total space LD B,H ; total space LD C,L ; to BC LD HL,(05C59h) ; address E_LINE - first location after ; variables area DEC HL ; point to location before - the 080h end-marker CALL L1655 ; routine MAKE-ROOM creates the space if ; memory is available. INC HL ; point to first new location and LD (HL),A ; store letter/type POP BC ; pop total space DEC BC ; exclude name DEC BC ; exclude the 16-bit DEC BC ; counter itself INC HL ; point to next location the 16-bit counter LD (HL),C ; insert low byte INC HL ; address next LD (HL),B ; insert high byte POP BC ; pop the number of dimensions. LD A,B ; dimensions to A INC HL ; address next LD (HL),A ; and insert "No. of dims" LD H,D ; transfer DE space + 1 from make-room LD L,E ; to HL DEC DE ; set DE to next location down. LD (HL),00h ; presume numeric and insert a zero BIT 6,C ; test bit 6 of C. numeric or string ? JR Z,L2C7C ; skip to DIM-CLEAR if numeric LD (HL),020h ; place a space character in HL ;; DIM-CLEAR L2C7C: POP BC ; pop the data length LDDR ; LDDR sets to zeros or spaces ; The number of dimensions is still in A. ; A loop is now entered to insert the size of each dimension that was pushed ; during the D-NO-LOOP working downwards from position before start of data. ;; DIM-SIZES L2C7F: POP BC ; pop a dimension size *** LD (HL),B ; insert high byte at position DEC HL ; next location down LD (HL),C ; insert low byte DEC HL ; next location down DEC A ; decrement dimension counter JR NZ,L2C7F ; back to DIM-SIZES until all done. RET ; return. ; ----------------------------- ; Check whether digit or letter ; ----------------------------- ; This routine checks that the character in A is alphanumeric ; returning with carry set if so. ;; ALPHANUM L2C88: CALL L2D1B ; routine NUMERIC will reset carry if so. CCF ; Complement Carry Flag RET C ; Return if numeric else continue into ; next routine. ; This routine checks that the character in A is alphabetic ;; ALPHA L2C8D: CP 041h ; less than 'A' ? CCF ; Complement Carry Flag RET NC ; return if so CP 05Bh ; less than 'Z'+1 ? RET C ; is within first range CP 061h ; less than 'a' ? CCF ; Complement Carry Flag RET NC ; return if so. CP 07Bh ; less than 'z'+1 ? RET ; carry set if within a-z. ; ------------------------- ; Decimal to floating point ; ------------------------- ; This routine finds the floating point number represented by an expression ; beginning with BIN, '.' or a digit. ; Note that BIN need not have any '0's or '1's after it. ; BIN is really just a notational symbol and not a function. ;; DEC-TO-FP L2C9B: CP 0C4h ; 'BIN' token ? JR NZ,L2CB8 ; to NOT-BIN if not LD DE,000h ; initialize 16 bit buffer register. ;; BIN-DIGIT L2CA2: RST 20H ; NEXT-CHAR SUB 031h ; '1' ADC A,00h ; will be zero if '1' or '0' ; carry will be set if was '0' JR NZ,L2CB3 ; forward to BIN-END if result not zero EX DE,HL ; buffer to HL CCF ; Carry now set if originally '1' ADC HL,HL ; shift the carry into HL JP C,L31AD ; to REPORT-6 if overflow - too many digits ; after first '1'. There can be an unlimited ; number of leading zeros. ; 'Number too big' - raise an error EX DE,HL ; save the buffer JR L2CA2 ; back to BIN-DIGIT for more digits ; --- ;; BIN-END L2CB3: LD B,D ; transfer 16 bit buffer LD C,E ; to BC register pair. JP L2D2B ; JUMP to STACK-BC to put on calculator stack ; --- ; continue here with .1, 42, 3.14, 5., 2.3 E -4 ;; NOT-BIN L2CB8: CP 02Eh ; '.' - leading decimal point ? JR Z,L2CCB ; skip to DECIMAL if so. CALL L2D3B ; routine INT-TO-FP to evaluate all digits ; This number 'x' is placed on stack. CP 02Eh ; '.' - mid decimal point ? JR NZ,L2CEB ; to E-FORMAT if not to consider that format RST 20H ; NEXT-CHAR CALL L2D1B ; routine NUMERIC returns carry reset if 0-9 JR C,L2CEB ; to E-FORMAT if not a digit e.g. '1.' JR L2CD5 ; to DEC-STO-1 to add the decimal part to 'x' ; --- ; a leading decimal point has been found in a number. ;; DECIMAL L2CCB: RST 20H ; NEXT-CHAR CALL L2D1B ; routine NUMERIC will reset carry if digit ;; DEC-RPT-C L2CCF: JP C,L1C8A ; to REPORT-C if just a '.' ; raise 'Nonsense in BASIC' ; since there is no leading zero put one on the calculator stack. RST 28H ;; FP-CALC .DEFB 0A0h ;;stk-zero ; 0. .DEFB 038h ;;end-calc ; If rejoining from earlier there will be a value 'x' on stack. ; If continuing from above the value zero. ; Now store 1 in mem-0. ; Note. At each pass of the digit loop this will be divided by ten. ;; DEC-STO-1 L2CD5: RST 28H ;; FP-CALC .DEFB 0A1h ;;stk-one ;x or 0,1. .DEFB 0C0h ;;st-mem-0 ;x or 0,1. .DEFB 002h ;;delete ;x or 0. .DEFB 038h ;;end-calc ;; NXT-DGT-1 L2CDA: RST 18H ; GET-CHAR CALL L2D22 ; routine STK-DIGIT stacks single digit 'd' JR C,L2CEB ; exit to E-FORMAT when digits exhausted > RST 28H ;; FP-CALC ;x or 0,d. first pass. .DEFB 0E0h ;;get-mem-0 ;x or 0,d,1. .DEFB 0A4h ;;stk-ten ;x or 0,d,1,10. .DEFB 005h ;;division ;x or 0,d,1/10. .DEFB 0C0h ;;st-mem-0 ;x or 0,d,1/10. .DEFB 004h ;;multiply ;x or 0,d/10. .DEFB 00Fh ;;addition ;x or 0 + d/10. .DEFB 038h ;;end-calc last value. RST 20H ; NEXT-CHAR moves to next character JR L2CDA ; back to NXT-DGT-1 ; --- ; although only the first pass is shown it can be seen that at each pass ; the new less significant digit is multiplied by an increasingly smaller ; factor (1/100, 1/1000, 1/10000 ... ) before being added to the previous ; last value to form a new last value. ; Finally see if an exponent has been input. ;; E-FORMAT L2CEB: CP 045h ; is character 'E' ? JR Z,L2CF2 ; to SIGN-FLAG if so CP 065h ; 'e' is acceptable as well. RET NZ ; return as no exponent. ;; SIGN-FLAG L2CF2: LD B,0FFh ; initialize temporary sign byte to 0FFh RST 20H ; NEXT-CHAR CP 02Bh ; is character '+' ? JR Z,L2CFE ; to SIGN-DONE CP 02Dh ; is character '-' ? JR NZ,L2CFF ; to ST-E-PART as no sign INC B ; set sign to zero ; now consider digits of exponent. ; Note. incidentally this is the only occasion in Spectrum BASIC when an ; expression may not be used when a number is expected. ;; SIGN-DONE L2CFE: RST 20H ; NEXT-CHAR ;; ST-E-PART L2CFF: CALL L2D1B ; routine NUMERIC JR C,L2CCF ; to DEC-RPT-C if not ; raise 'Nonsense in BASIC'. PUSH BC ; save sign (in B) CALL L2D3B ; routine INT-TO-FP places exponent on stack CALL L2DD5 ; routine FP-TO-A transfers it to A POP BC ; restore sign JP C,L31AD ; to REPORT-6 if overflow (over 255) ; raise 'Number too big'. AND A ; set flags JP M,L31AD ; to REPORT-6 if over '127'. ; raise 'Number too big'. ; 127 is still way too high and it is ; impossible to enter an exponent greater ; than 39 from the keyboard. The error gets ; raised later in E-TO-FP so two different ; error messages depending how high A is. INC B ; 0FFh to 00h or 00h to 001h - expendable now. JR Z,L2D18 ; forward to E-FP-JUMP if exponent positive NEG ; Negate the exponent. ;; E-FP-JUMP L2D18: JP L2D4F ; JUMP forward to E-TO-FP to assign to ; last value x on stack x * 10 to power A ; a relative jump would have done. ; --------------------- ; Check for valid digit ; --------------------- ; This routine checks that the ASCII character in A is numeric ; returning with carry reset if so. ;; NUMERIC L2D1B: CP 030h ; '0' RET C ; return if less than zero character. CP 03Ah ; The upper test is '9' CCF ; Complement Carry Flag RET ; Return - carry clear if character '0' - '9' ; ----------- ; Stack Digit ; ----------- ; This subroutine is called from INT-TO-FP and DEC-TO-FP to stack a digit ; on the calculator stack. ;; STK-DIGIT L2D22: CALL L2D1B ; routine NUMERIC RET C ; return if not numeric character SUB 030h ; convert from ASCII to digit ; ----------------- ; Stack accumulator ; ----------------- ; ; ;; STACK-A L2D28: LD C,A ; transfer to C LD B,00h ; and make B zero ; ---------------------- ; Stack BC register pair ; ---------------------- ; ;; STACK-BC L2D2B: LD IY,05C3Ah ; re-initialize ERR_NR XOR A ; clear to signal small integer LD E,A ; place in E for sign LD D,C ; LSB to D LD C,B ; MSB to C LD B,A ; last byte not used CALL L2AB6 ; routine STK-STORE RST 28H ;; FP-CALC .DEFB 038h ;;end-calc make HL = STKEND-5 AND A ; clear carry RET ; before returning ; ------------------------- ; Integer to floating point ; ------------------------- ; This routine places one or more digits found in a BASIC line ; on the calculator stack multiplying the previous value by ten each time ; before adding in the new digit to form a last value on calculator stack. ;; INT-TO-FP L2D3B: PUSH AF ; save first character RST 28H ;; FP-CALC .DEFB 0A0h ;;stk-zero ; v=0. initial value .DEFB 038h ;;end-calc POP AF ; fetch first character back. ;; NXT-DGT-2 L2D40: CALL L2D22 ; routine STK-DIGIT puts 0-9 on stack RET C ; will return when character is not numeric > RST 28H ;; FP-CALC ; v, d. .DEFB 001h ;;exchange ; d, v. .DEFB 0A4h ;;stk-ten ; d, v, 10. .DEFB 004h ;;multiply ; d, v*10. .DEFB 00Fh ;;addition ; d + v*10 = newvalue .DEFB 038h ;;end-calc ; v. CALL L0074 ; routine CH-ADD+1 get next character JR L2D40 ; back to NXT-DGT-2 to process as a digit ;********************************* ;** Part 9. ARITHMETIC ROUTINES ** ;********************************* ; -------------------------- ; E-format to floating point ; -------------------------- ; This subroutine is used by the PRINT-FP routine and the decimal to FP ; routines to stack a number expressed in exponent format. ; Note. Though not used by the ROM as such, it has also been set up as ; a unary calculator literal but this will not work as the accumulator ; is not available from within the calculator. ; on entry there is a value x on the calculator stack and an exponent of ten ; in A. The required value is x + 10 ^ A ;; e-to-fp ;; E-TO-FP L2D4F: RLCA ; this will set the x. RRCA ; carry if bit 7 is set JR NC,L2D55 ; to E-SAVE if positive. CPL ; make negative positive INC A ; without altering carry. ;; E-SAVE L2D55: PUSH AF ; save positive exp and sign in carry LD HL,05C92h ; address MEM-0 CALL L350B ; routine FP-0/1 ; places an integer zero, if no carry, ; else a one in mem-0 as a sign flag RST 28H ;; FP-CALC .DEFB 0A4h ;;stk-ten x, 10. .DEFB 038h ;;end-calc POP AF ; pop the exponent. ; now enter a loop ;; E-LOOP L2D60: SRL A ; 0>76543210>C JR NC,L2D71 ; forward to E-TST-END if no bit PUSH AF ; save shifted exponent. RST 28H ;; FP-CALC .DEFB 0C1h ;;st-mem-1 x, 10. .DEFB 0E0h ;;get-mem-0 x, 10, (0/1). .DEFB 00h ;;jump-true .DEFB 004h ;;to L2D6D, E-DIVSN .DEFB 004h ;;multiply x*10. .DEFB 033h ;;jump .DEFB 002h ;;to L2D6E, E-FETCH ;; E-DIVSN L2D6D: .DEFB 005h ;;division x/10. ;; E-FETCH L2D6E: .DEFB 0E1h ;;get-mem-1 x/10 or x*10, 10. .DEFB 038h ;;end-calc new x, 10. POP AF ; restore shifted exponent ; the loop branched to here with no carry ;; E-TST-END L2D71: JR Z,L2D7B ; forward to E-END if A emptied of bits PUSH AF ; re-save shifted exponent RST 28H ;; FP-CALC .DEFB 031h ;;duplicate new x, 10, 10. .DEFB 004h ;;multiply new x, 100. .DEFB 038h ;;end-calc POP AF ; restore shifted exponent JR L2D60 ; back to E-LOOP until all bits done. ; --- ; although only the first pass is shown it can be seen that for each set bit ; representing a power of two, x is multiplied or divided by the ; corresponding power of ten. ;; E-END L2D7B: RST 28H ;; FP-CALC final x, factor. .DEFB 002h ;;delete final x. .DEFB 038h ;;end-calc x. RET ; return ; ------------- ; Fetch integer ; ------------- ; This routine is called by the mathematical routines - FP-TO-BC, PRINT-FP, ; mult, re-stack and negate to fetch an integer from address HL. ; HL points to the stack or a location in MEM and no deletion occurs. ; If the number is negative then a similar process to that used in INT-STORE ; is used to restore the twos complement number to normal in DE and a sign ; in C. ;; INT-FETCH L2D7F: INC HL ; skip zero indicator. LD C,(HL) ; fetch sign to C INC HL ; address low byte LD A,(HL) ; fetch to A XOR C ; two's complement SUB C ; LD E,A ; place in E INC HL ; address high byte LD A,(HL) ; fetch to A ADC A,C ; two's complement XOR C ; LD D,A ; place in D RET ; return ; ------------------------ ; Store a positive integer ; ------------------------ ; This entry point is not used in this ROM but would ; store any integer as positive. ;; p-int-sto L2D8C: LD C,00h ; make sign byte positive and continue ; ------------- ; Store integer ; ------------- ; this routine stores an integer in DE at address HL. ; It is called from mult, truncate, negate and sgn. ; The sign byte 00h +ve or 0FFh -ve is in C. ; If negative, the number is stored in 2's complement form so that it is ; ready to be added. ;; INT-STORE L2D8E: PUSH HL ; preserve HL LD (HL),00h ; first byte zero shows integer not exponent INC HL ; LD (HL),C ; then store the sign byte INC HL ; ; e.g. +1 -1 LD A,E ; fetch low byte 00000001 00000001 XOR C ; xor sign 00000000 or 11111111 ; gives 00000001 or 11111110 SUB C ; sub sign 00000000 or 11111111 ; gives 00000001>0 or 11111111>C LD (HL),A ; store 2's complement. INC HL ; LD A,D ; high byte 00000000 00000000 ADC A,C ; sign 00000000<0 11111111<C ; gives 00000000 or 00000000 XOR C ; xor sign 00000000 11111111 LD (HL),A ; store 2's complement. INC HL ; LD (HL),00h ; last byte always zero for integers. ; is not used and need not be looked at when ; testing for zero but comes into play should ; an integer be converted to fp. POP HL ; restore HL RET ; return. ; ----------------------------- ; Floating point to BC register ; ----------------------------- ; This routine gets a floating point number e.g. 127.4 from the calculator ; stack to the BC register. ;; FP-TO-BC L2DA2: RST 28H ;; FP-CALC set HL to .DEFB 038h ;;end-calc point to last value. LD A,(HL) ; get first of 5 bytes AND A ; and test JR Z,L2DAD ; forward to FP-DELETE if an integer ; The value is first rounded up and then converted to integer. RST 28H ;; FP-CALC x. .DEFB 0A2h ;;stk-half x. 1/2. .DEFB 00Fh ;;addition x + 1/2. .DEFB 027h ;;int int(x + .5) .DEFB 038h ;;end-calc ; now delete but leave HL pointing at integer ;; FP-DELETE L2DAD: RST 28H ;; FP-CALC .DEFB 002h ;;delete .DEFB 038h ;;end-calc PUSH HL ; save pointer. PUSH DE ; and STKEND. EX DE,HL ; make HL point to exponent/zero indicator LD B,(HL) ; indicator to B CALL L2D7F ; routine INT-FETCH ; gets int in DE sign byte to C ; but meaningless values if a large integer XOR A ; clear A SUB B ; subtract indicator byte setting carry ; if not a small integer. BIT 7,C ; test a bit of the sign byte setting zero ; if positive. LD B,D ; transfer int LD C,E ; to BC LD A,E ; low byte to A as a useful return value. POP DE ; pop STKEND POP HL ; and pointer to last value RET ; return ; if carry is set then the number was too big. ; ------------ ; LOG(2^A) ; ------------ ; This routine is used when printing floating point numbers to calculate ; the number of digits before the decimal point. ; first convert a one-byte signed integer to its five byte form. ;; LOG(2^A) L2DC1: LD D,A ; store a copy of A in D. RLA ; test sign bit of A. SBC A,A ; now 0FFh if negative or 00h LD E,A ; sign byte to E. LD C,A ; and to C XOR A ; clear A LD B,A ; and B. CALL L2AB6 ; routine STK-STORE stacks number AEDCB ; so 00 00 XX 00 00 (positive) or 00 FF XX FF 00 (negative). ; i.e. integer indicator, sign byte, low, high, unused. ; now multiply exponent by log to the base 10 of two. RST 28H ;; FP-CALC .DEFB 034h ;;stk-data .30103 (log 2) .DEFB 0EFh ;;Exponent: 07Fh, Bytes: 4 .DEFB 01Ah,020h,09Ah,085h ;; .DEFB 004h ;;multiply .DEFB 027h ;;int .DEFB 038h ;;end-calc ; ------------------- ; Floating point to A ; ------------------- ; this routine collects a floating point number from the stack into the ; accumulator returning carry set if not in range 0 - 255. ; Not all the calling routines raise an error with overflow so no attempt ; is made to produce an error report here. ;; FP-TO-A L2DD5: CALL L2DA2 ; routine FP-TO-BC returns with C in A also. RET C ; return with carry set if > 65535, overflow PUSH AF ; save the value and flags DEC B ; and test that INC B ; the high byte is zero. JR Z,L2DE1 ; forward FP-A-END if zero ; else there has been 8-bit overflow POP AF ; retrieve the value SCF ; set carry flag to show overflow RET ; and return. ; --- ;; FP-A-END L2DE1: POP AF ; restore value and success flag and RET ; return. ; ----------------------------- ; Print a floating point number ; ----------------------------- ; Not a trivial task. ; Begin by considering whether to print a leading sign for negative numbers. ;; PRINT-FP L2DE3: RST 28H ;; FP-CALC .DEFB 031h ;;duplicate .DEFB 036h ;;less-0 .DEFB 00h ;;jump-true .DEFB 00Bh ;;to L2DF2, PF-NEGTVE .DEFB 031h ;;duplicate .DEFB 037h ;;greater-0 .DEFB 00h ;;jump-true .DEFB 00Dh ;;to L2DF8, PF-POSTVE ; must be zero itself .DEFB 002h ;;delete .DEFB 038h ;;end-calc LD A,030h ; prepare the character '0' RST 10H ; PRINT-A RET ; return. -> ; --- ;; PF-NEGTVE L2DF2: .DEFB 02Ah ;;abs .DEFB 038h ;;end-calc LD A,02Dh ; the character '-' RST 10H ; PRINT-A ; and continue to print the now positive number. RST 28H ;; FP-CALC ;; PF-POSTVE L2DF8: .DEFB 0A0h ;;stk-zero x,0. begin by .DEFB 0C3h ;;st-mem-3 x,0. clearing a temporary .DEFB 0C4h ;;st-mem-4 x,0. output buffer to .DEFB 0C5h ;;st-mem-5 x,0. fifteen zeros. .DEFB 002h ;;delete x. .DEFB 038h ;;end-calc x. EXX ; in case called from 'str$' then save the PUSH HL ; pointer to whatever comes after EXX ; str$ as H'L' will be used. ; now enter a loop? ;; PF-LOOP L2E01: RST 28H ;; FP-CALC .DEFB 031h ;;duplicate x,x. .DEFB 027h ;;int x,int x. .DEFB 0C2h ;;st-mem-2 x,int x. .DEFB 003h ;;subtract x-int x. fractional part. .DEFB 0E2h ;;get-mem-2 x-int x, int x. .DEFB 001h ;;exchange int x, x-int x. .DEFB 0C2h ;;st-mem-2 int x, x-int x. .DEFB 002h ;;delete int x. .DEFB 038h ;;end-calc int x. ; ; mem-2 holds the fractional part. ; HL points to last value int x LD A,(HL) ; fetch exponent of int x. AND A ; test JR NZ,L2E56 ; forward to PF-LARGE if a large integer ; > 65535 ; continue with small positive integer components in range 0 - 65535 ; if original number was say .999 then this integer component is zero. CALL L2D7F ; routine INT-FETCH gets x in DE ; (but x is not deleted) LD B,010h ; set B, bit counter, to 16d LD A,D ; test if AND A ; high byte is zero JR NZ,L2E1E ; forward to PF-SAVE if 16-bit integer. ; and continue with integer in range 0 - 255. OR E ; test the low byte for zero ; i.e. originally just point something or other. JR Z,L2E24 ; forward if so to PF-SMALL ; LD D,E ; transfer E to D LD B,008h ; and reduce the bit counter to 8. ;; PF-SAVE L2E1E: PUSH DE ; save the part before decimal point. EXX ; POP DE ; and pop in into D'E' EXX ; JR L2E7B ; forward to PF-BITS ; --------------------- ; the branch was here when 'int x' was found to be zero as in say 0.5. ; The zero has been fetched from the calculator stack but not deleted and ; this should occur now. This omission leaves the stack unbalanced and while ; that causes no problems with a simple PRINT statement, it will if str$ is ; being used in an expression e.g. "2" + STR$ 0.5 gives the result "0.5" ; instead of the expected result "20.5". ; credit Tony Stratton, 1982. ; A .DEFB 02 delete is required immediately on using the calculator. ;; PF-SMALL L2E24: RST 28H ;; FP-CALC int x = 0. L2E25: .DEFB 0E2h ;;get-mem-2 int x = 0, x-int x. .DEFB 038h ;;end-calc LD A,(HL) ; fetch exponent of positive fractional number SUB 07Eh ; subtract CALL L2DC1 ; routine LOG(2^A) calculates leading digits. LD D,A ; transfer count to D LD A,(05CACh) ; fetch total MEM-5-1 SUB D ; LD (05CACh),A ; MEM-5-1 LD A,D ; CALL L2D4F ; routine E-TO-FP RST 28H ;; FP-CALC .DEFB 031h ;;duplicate .DEFB 027h ;;int .DEFB 0C1h ;;st-mem-1 .DEFB 003h ;;subtract .DEFB 0E1h ;;get-mem-1 .DEFB 038h ;;end-calc CALL L2DD5 ; routine FP-TO-A PUSH HL ; save HL LD (05CA1h),A ; MEM-3-1 DEC A ; RLA ; SBC A,A ; INC A ; LD HL,05CABh ; address MEM-5-1 leading digit counter LD (HL),A ; store counter INC HL ; address MEM-5-2 total digits ADD A,(HL) ; add counter to contents LD (HL),A ; and store updated value POP HL ; restore HL JP L2ECF ; JUMP forward to PF-FRACTN ; --- ; Note. while it would be pedantic to comment on every occasion a JP ; instruction could be replaced with a JR instruction, this applies to the ; above, which is useful if you wish to correct the unbalanced stack error ; by inserting a '..DEFB 02 delete' at L2E25, and maintain main addresses. ; the branch was here with a large positive integer > 65535 e.g. 123456789 ; the accumulator holds the exponent. ;; PF-LARGE L2E56: SUB 080h ; make exponent positive CP 01Ch ; compare to 28 JR C,L2E6F ; to PF-MEDIUM if integer <= 2^27 CALL L2DC1 ; routine LOG(2^A) SUB 007h ; LD B,A ; LD HL,05CACh ; address MEM-5-1 the leading digits counter. ADD A,(HL) ; add A to contents LD (HL),A ; store updated value. LD A,B ; NEG ; negate CALL L2D4F ; routine E-TO-FP JR L2E01 ; back to PF-LOOP ; ---------------------------- ;; PF-MEDIUM L2E6F: EX DE,HL ; CALL L2FBA ; routine FETCH-TWO EXX ; SET 7,D ; LD A,L ; EXX ; SUB 080h ; LD B,A ; ; the branch was here to handle bits in DE with 8 or 16 in B if small int ; and integer in D'E', 6 nibbles will accommodate 065535 but routine does ; 32-bit numbers as well from above ;; PF-BITS L2E7B: SLA E ; C<xxxxxxxx<0 RL D ; C<xxxxxxxx<C EXX ; RL E ; C<xxxxxxxx<C RL D ; C<xxxxxxxx<C EXX ; LD HL,05CAAh ; set HL to mem-4-5th last byte of buffer LD C,005h ; set byte count to 5 - 10 nibbles ;; PF-BYTES L2E8A: LD A,(HL) ; fetch 0 or prev value ADC A,A ; shift left add in carry C<xxxxxxxx<C DAA ; Decimal Adjust Accumulator. ; if greater than 9 then the left hand ; nibble is incremented. If greater than ; 99 then adjusted and carry set. ; so if we'd built up 7 and a carry came in ; 0000 0111 < C ; 0000 1111 ; daa 1 0101 which is 15 in BCD LD (HL),A ; put back DEC HL ; work down thru mem 4 DEC C ; decrease the 5 counter. JR NZ,L2E8A ; back to PF-BYTES until the ten nibbles rolled DJNZ L2E7B ; back to PF-BITS until 8 or 16 (or 32) done ; at most 9 digits for 32-bit number will have been loaded with digits ; each of the 9 nibbles in mem 4 is placed into ten bytes in mem-3 and mem 4 ; unless the nibble is zero as the buffer is already zero. ; ( or in the case of mem-5 will become zero as a result of RLD instruction ) XOR A ; clear to accept LD HL,05CA6h ; address MEM-4-0 byte destination. LD DE,05CA1h ; address MEM-3-0 nibble source. LD B,009h ; the count is 9 (not ten) as the first ; nibble is known to be blank. RLD ; shift RH nibble to left in (HL) ; A (HL) ; 0000 0000 < 0000 3210 ; 0000 0000 3210 0000 ; A picks up the blank nibble LD C,0FFh ; set a flag to indicate when a significant ; digit has been encountered. ;; PF-DIGITS L2EA1: RLD ; pick up leftmost nibble from (HL) ; A (HL) ; 0000 0000 < 7654 3210 ; 0000 7654 3210 0000 JR NZ,L2EA9 ; to PF-INSERT if non-zero value picked up. DEC C ; test INC C ; flag JR NZ,L2EB3 ; skip forward to PF-TEST-2 if flag still 0FFh ; indicating this is a leading zero. ; but if the zero is a significant digit e.g. 10 then include in digit totals. ; the path for non-zero digits rejoins here. ;; PF-INSERT L2EA9: LD (DE),A ; insert digit at destination INC DE ; increase the destination pointer INC (IY+071h) ; increment MEM-5-1st digit counter INC (IY+072h) ; increment MEM-5-2nd leading digit counter LD C,00h ; set flag to zero indicating that any ; subsequent zeros are significant and not ; leading. ;; PF-TEST-2 L2EB3: BIT 0,B ; test if the nibble count is even JR Z,L2EB8 ; skip to PF-ALL-9 if so to deal with the ; other nibble in the same byte INC HL ; point to next source byte if not ;; PF-ALL-9 L2EB8: DJNZ L2EA1 ; decrement the nibble count, back to PF-DIGITS ; if all nine not done. ; For 8-bit integers there will be at most 3 digits. ; For 16-bit integers there will be at most 5 digits. ; but for larger integers there could be nine leading digits. ; if nine digits complete then the last one is rounded up as the number will ; be printed using E-format notation LD A,(05CABh) ; fetch digit count from MEM-5-1st SUB 009h ; subtract 9 - max possible JR C,L2ECB ; forward if less to PF-MORE DEC (IY+071h) ; decrement digit counter MEM-5-1st to 8 LD A,004h ; load A with the value 4. CP (IY+06Fh) ; compare with MEM-4-4th - the ninth digit JR L2F0C ; forward to PF-ROUND ; to consider rounding. ; --------------------------------------- ; now delete int x from calculator stack and fetch fractional part. ;; PF-MORE L2ECB: RST 28H ;; FP-CALC int x. .DEFB 002h ;;delete . .DEFB 0E2h ;;get-mem-2 x - int x = f. .DEFB 038h ;;end-calc f. ;; PF-FRACTN L2ECF: EX DE,HL ; CALL L2FBA ; routine FETCH-TWO EXX ; LD A,080h ; SUB L ; LD L,00h ; SET 7,D ; EXX ; CALL L2FDD ; routine SHIFT-FP ;; PF-FRN-LP L2EDF: LD A,(IY+071h) ; MEM-5-1st CP 008h ; JR C,L2EEC ; to PF-FR-DGT EXX ; RL D ; EXX ; JR L2F0C ; to PF-ROUND ; --- ;; PF-FR-DGT L2EEC: LD BC,00200h ; ;; PF-FR-EXX L2EEF: LD A,E ; CALL L2F8B ; routine CA-10*A+C LD E,A ; LD A,D ; CALL L2F8B ; routine CA-10*A+C LD D,A ; PUSH BC ; EXX ; POP BC ; DJNZ L2EEF ; to PF-FR-EXX LD HL,05CA1h ; MEM-3 LD A,C ; LD C,(IY+071h) ; MEM-5-1st ADD HL,BC ; LD (HL),A ; INC (IY+071h) ; MEM-5-1st JR L2EDF ; to PF-FRN-LP ; ---------------- ; 1) with 9 digits but 8 in mem-5-1 and A holding 4, carry set if rounding up. ; e.g. ; 999999999 is printed as 1E+9 ; 100000001 is printed as 1E+8 ; 100000009 is printed as 1.0000001E+8 ;; PF-ROUND L2F0C: PUSH AF ; save A and flags LD HL,05CA1h ; address MEM-3 start of digits LD C,(IY+071h) ; MEM-5-1st No. of digits to C LD B,00h ; prepare to add ADD HL,BC ; address last digit + 1 LD B,C ; No. of digits to B counter POP AF ; restore A and carry flag from comparison. ;; PF-RND-LP L2F18: DEC HL ; address digit at rounding position. LD A,(HL) ; fetch it ADC A,00h ; add carry from the comparison LD (HL),A ; put back result even if 00Ah. AND A ; test A JR Z,L2F25 ; skip to PF-R-BACK if ZERO? CP 00Ah ; compare to 'ten' - overflow CCF ; complement carry flag so that set if ten. JR NC,L2F2D ; forward to PF-COUNT with 1 - 9. ;; PF-R-BACK L2F25: DJNZ L2F18 ; loop back to PF-RND-LP ; if B counts down to zero then we've rounded right back as in 999999995. ; and the first 8 locations all hold 00Ah. LD (HL),001h ; load first location with digit 1. INC B ; make B hold 1 also. ; could save an instruction byte here. INC (IY+072h) ; make MEM-5-2nd hold 1. ; and proceed to initialize total digits to 1. ;; PF-COUNT L2F2D: LD (IY+071h),B ; MEM-5-1st ; now balance the calculator stack by deleting it RST 28H ;; FP-CALC .DEFB 002h ;;delete .DEFB 038h ;;end-calc ; note if used from str$ then other values may be on the calculator stack. ; we can also restore the next literal pointer from its position on the ; machine stack. EXX ; POP HL ; restore next literal pointer. EXX ; LD BC,(05CABh) ; set C to MEM-5-1st digit counter. ; set B to MEM-5-2nd leading digit counter. LD HL,05CA1h ; set HL to start of digits at MEM-3-1 LD A,B ; CP 009h ; JR C,L2F46 ; to PF-NOT-E CP 0FCh ; JR C,L2F6C ; to PF-E-FRMT ;; PF-NOT-E L2F46: AND A ; test for zero leading digits as in .123 CALL Z,L15EF ; routine OUT-CODE prints a zero e.g. 0.123 ;; PF-E-SBRN L2F4A: XOR A ; SUB B ; JP M,L2F52 ; skip forward to PF-OUT-LP if originally +ve LD B,A ; else negative count now +ve JR L2F5E ; forward to PF-DC-OUT -> ; --- ;; PF-OUT-LP L2F52: LD A,C ; fetch total digit count AND A ; test for zero JR Z,L2F59 ; forward to PF-OUT-DT if so LD A,(HL) ; fetch digit INC HL ; address next digit DEC C ; decrease total digit counter ;; PF-OUT-DT L2F59: CALL L15EF ; routine OUT-CODE outputs it. DJNZ L2F52 ; loop back to PF-OUT-LP until B leading ; digits output. ;; PF-DC-OUT L2F5E: LD A,C ; fetch total digits and AND A ; test if also zero RET Z ; return if so --> ; INC B ; increment B LD A,02Eh ; prepare the character '.' ;; PF-DEC-0S L2F64: RST 10H ; PRINT-A outputs the character '.' or '0' LD A,030h ; prepare the character '0' ; (for cases like .000012345678) DJNZ L2F64 ; loop back to PF-DEC-0S for B times. LD B,C ; load B with now trailing digit counter. JR L2F52 ; back to PF-OUT-LP ; --------------------------------- ; the branch was here for E-format printing e.g. 123456789 => 1.2345679e+8 ;; PF-E-FRMT L2F6C: LD D,B ; counter to D DEC D ; decrement LD B,001h ; load B with 1. CALL L2F4A ; routine PF-E-SBRN above LD A,045h ; prepare character 'e' RST 10H ; PRINT-A LD C,D ; exponent to C LD A,C ; and to A AND A ; test exponent JP P,L2F83 ; to PF-E-POS if positive NEG ; negate LD C,A ; positive exponent to C LD A,02Dh ; prepare character '-' JR L2F85 ; skip to PF-E-SIGN ; --- ;; PF-E-POS L2F83: LD A,02Bh ; prepare character '+' ;; PF-E-SIGN L2F85: RST 10H ; PRINT-A outputs the sign LD B,00h ; make the high byte zero. JP L1A1B ; exit via OUT-NUM-1 to print exponent in BC ; ------------------------------ ; Handle printing floating point ; ------------------------------ ; This subroutine is called twice from above when printing floating-point ; numbers. It returns 10*A +C in registers C and A ;; CA-10*A+C L2F8B: PUSH DE ; preserve DE. LD L,A ; transfer A to L LD H,00h ; zero high byte. LD E,L ; copy HL LD D,H ; to DE. ADD HL,HL ; double (*2) ADD HL,HL ; double (*4) ADD HL,DE ; add DE (*5) ADD HL,HL ; double (*10) LD E,C ; copy C to E (D is 0) ADD HL,DE ; and add to give required result. LD C,H ; transfer to LD A,L ; destination registers. POP DE ; restore DE RET ; return with result. ; -------------- ; Prepare to add ; -------------- ; This routine is called twice by addition to prepare the two numbers. The ; exponent is picked up in A and the location made zero. Then the sign bit ; is tested before being set to the implied state. Negative numbers are twos ; complemented. ;; PREP-ADD L2F9B: LD A,(HL) ; pick up exponent LD (HL),00h ; make location zero AND A ; test if number is zero RET Z ; return if so INC HL ; address mantissa BIT 7,(HL) ; test the sign bit SET 7,(HL) ; set it to implied state DEC HL ; point to exponent RET Z ; return if positive number. PUSH BC ; preserve BC LD BC,005h ; length of number ADD HL,BC ; point HL past end LD B,C ; set B to 5 counter LD C,A ; store exponent in C SCF ; set carry flag ;; NEG-BYTE L2FAF: DEC HL ; work from LSB to MSB LD A,(HL) ; fetch byte CPL ; complement ADC A,00h ; add in initial carry or from prev operation LD (HL),A ; put back DJNZ L2FAF ; loop to NEG-BYTE till all 5 done LD A,C ; stored exponent to A POP BC ; restore original BC RET ; return ; ----------------- ; Fetch two numbers ; ----------------- ; This routine is called twice when printing floating point numbers and also ; to fetch two numbers by the addition, multiply and division routines. ; HL addresses the first number, DE addresses the second number. ; For arithmetic only, A holds the sign of the result which is stored in ; the second location. ;; FETCH-TWO L2FBA: PUSH HL ; save pointer to first number, result if math. PUSH AF ; save result sign. LD C,(HL) ; INC HL ; LD B,(HL) ; LD (HL),A ; store the sign at correct location in ; destination 5 bytes for arithmetic only. INC HL ; LD A,C ; LD C,(HL) ; PUSH BC ; INC HL ; LD C,(HL) ; INC HL ; LD B,(HL) ; EX DE,HL ; LD D,A ; LD E,(HL) ; PUSH DE ; INC HL ; LD D,(HL) ; INC HL ; LD E,(HL) ; PUSH DE ; EXX ; POP DE ; POP HL ; POP BC ; EXX ; INC HL ; LD D,(HL) ; INC HL ; LD E,(HL) ; POP AF ; restore possible result sign. POP HL ; and pointer to possible result. RET ; return. ; --------------------------------- ; Shift floating point number right ; --------------------------------- ; ; ;; SHIFT-FP L2FDD: AND A ; RET Z ; CP 021h ; JR NC,L2FF9 ; to ADDEND-0 PUSH BC ; LD B,A ; ;; ONE-SHIFT L2FE5: EXX ; SRA L ; RR D ; RR E ; EXX ; RR D ; RR E ; DJNZ L2FE5 ; to ONE-SHIFT POP BC ; RET NC ; CALL L3004 ; routine ADD-BACK RET NZ ; ;; ADDEND-0 L2FF9: EXX ; XOR A ; ;; ZEROS-4/5 L2FFB: LD L,00h ; LD D,A ; LD E,L ; EXX ; LD DE,000h ; RET ; ; ------------------ ; Add back any carry ; ------------------ ; ; ;; ADD-BACK L3004: INC E ; RET NZ ; INC D ; RET NZ ; EXX ; INC E ; JR NZ,L300D ; to ALL-ADDED INC D ; ;; ALL-ADDED L300D: EXX ; RET ; ; ----------------------- ; Handle subtraction (03) ; ----------------------- ; Subtraction is done by switching the sign byte/bit of the second number ; which may be integer of floating point and continuing into addition. ;; subtract L300F: EX DE,HL ; address second number with HL CALL L346E ; routine NEGATE switches sign EX DE,HL ; address first number again ; and continue. ; -------------------- ; Handle addition (0F) ; -------------------- ; HL points to first number, DE to second. ; If they are both integers, then go for the easy route. ;; addition L3014: LD A,(DE) ; fetch first byte of second OR (HL) ; combine with first byte of first JR NZ,L303E ; forward to FULL-ADDN if at least one was ; in floating point form. ; continue if both were small integers. PUSH DE ; save pointer to lowest number for result. INC HL ; address sign byte and PUSH HL ; push the pointer. INC HL ; address low byte LD E,(HL) ; to E INC HL ; address high byte LD D,(HL) ; to D INC HL ; address unused byte INC HL ; address known zero indicator of 1st number INC HL ; address sign byte LD A,(HL) ; sign to A, 00h or 0FFh INC HL ; address low byte LD C,(HL) ; to C INC HL ; address high byte LD B,(HL) ; to B POP HL ; pop result sign pointer EX DE,HL ; integer to HL ADD HL,BC ; add to the other one in BC ; setting carry if overflow. EX DE,HL ; save result in DE bringing back sign pointer ADC A,(HL) ; if pos/pos A=01 with overflow else 00 ; if neg/neg A=FF with overflow else FE ; if mixture A=00 with overflow else FF RRCA ; bit 0 to (C) ADC A,00h ; both acceptable signs now zero JR NZ,L303C ; forward to ADDN-OFLW if not SBC A,A ; restore a negative result sign LD (HL),A ; INC HL ; LD (HL),E ; INC HL ; LD (HL),D ; DEC HL ; DEC HL ; DEC HL ; POP DE ; STKEND RET ; ; --- ;; ADDN-OFLW L303C: DEC HL ; POP DE ; ;; FULL-ADDN L303E: CALL L3293 ; routine RE-ST-TWO EXX ; PUSH HL ; EXX ; PUSH DE ; PUSH HL ; CALL L2F9B ; routine PREP-ADD LD B,A ; EX DE,HL ; CALL L2F9B ; routine PREP-ADD LD C,A ; CP B ; JR NC,L3055 ; to SHIFT-LEN LD A,B ; LD B,C ; EX DE,HL ; ;; SHIFT-LEN L3055: PUSH AF ; SUB B ; CALL L2FBA ; routine FETCH-TWO CALL L2FDD ; routine SHIFT-FP POP AF ; POP HL ; LD (HL),A ; PUSH HL ; LD L,B ; LD H,C ; ADD HL,DE ; EXX ; EX DE,HL ; ADC HL,BC ; EX DE,HL ; LD A,H ; ADC A,L ; LD L,A ; RRA ; XOR L ; EXX ; EX DE,HL ; POP HL ; RRA ; JR NC,L307C ; to TEST-NEG LD A,001h ; CALL L2FDD ; routine SHIFT-FP INC (HL) ; JR Z,L309F ; to ADD-REP-6 ;; TEST-NEG L307C: EXX ; LD A,L ; AND 080h ; EXX ; INC HL ; LD (HL),A ; DEC HL ; JR Z,L30A5 ; to GO-NC-MLT LD A,E ; NEG ; Negate CCF ; Complement Carry Flag LD E,A ; LD A,D ; CPL ; ADC A,00h ; LD D,A ; EXX ; LD A,E ; CPL ; ADC A,00h ; LD E,A ; LD A,D ; CPL ; ADC A,00h ; JR NC,L30A3 ; to END-COMPL RRA ; EXX ; INC (HL) ; ;; ADD-REP-6 L309F: JP Z,L31AD ; to REPORT-6 EXX ; ;; END-COMPL L30A3: LD D,A ; EXX ; ;; GO-NC-MLT L30A5: XOR A ; JP L3155 ; to TEST-NORM ; ----------------------------- ; Used in 16 bit multiplication ; ----------------------------- ; This routine is used, in the first instance, by the multiply calculator ; literal to perform an integer multiplication in preference to ; 32-bit multiplication to which it will resort if this overflows. ; ; It is also used by STK-VAR to calculate array subscripts and by DIM to ; calculate the space required for multi-dimensional arrays. ;; HL-HL*DE L30A9: PUSH BC ; preserve BC throughout LD B,010h ; set B to 16 LD A,H ; save H in A high byte LD C,L ; save L in C low byte LD HL,000h ; initialize result to zero ; now enter a loop. ;; HL-LOOP L30B1: ADD HL,HL ; double result JR C,L30BE ; to HL-END if overflow RL C ; shift AC left into carry RLA ; JR NC,L30BC ; to HL-AGAIN to skip addition if no carry ADD HL,DE ; add in DE JR C,L30BE ; to HL-END if overflow ;; HL-AGAIN L30BC: DJNZ L30B1 ; back to HL-LOOP for all 16 bits ;; HL-END L30BE: POP BC ; restore preserved BC RET ; return with carry reset if successful ; and result in HL. ; ---------------------------------------------- ; THE 'PREPARE TO MULTIPLY OR DIVIDE' SUBROUTINE ; ---------------------------------------------- ; This routine is called in succession from multiply and divide to prepare ; two mantissas by setting the leftmost bit that is used for the sign. ; On the first call A holds zero and picks up the sign bit. On the second ; call the two bits are XORed to form the result sign - minus * minus giving ; plus etc. If either number is zero then this is flagged. ; HL addresses the exponent. ;; PREP-M/D L30C0: CALL L34E9 ; routine TEST-ZERO preserves accumulator. RET C ; return carry set if zero INC HL ; address first byte of mantissa XOR (HL) ; pick up the first or xor with first. SET 7,(HL) ; now set to give true 32-bit mantissa DEC HL ; point to exponent RET ; return with carry reset ; ---------------------- ; THE 'MULTIPLY' ROUTINE ; ---------------------- ; (offset: 004h 'multiply') ; ; ; "He said go forth and something about mathematics, I wasn't really ; listening" - overheard conversation between two unicorns. ; [ The Odd Streak ]. ;; multiply L30CA: LD A,(DE) ; OR (HL) ; JR NZ,L30F0 ; to MULT-LONG PUSH DE ; PUSH HL ; PUSH DE ; CALL L2D7F ; routine INT-FETCH EX DE,HL ; EX (SP),HL ; LD B,C ; CALL L2D7F ; routine INT-FETCH LD A,B ; XOR C ; LD C,A ; POP HL ; CALL L30A9 ; routine HL-HL*DE EX DE,HL ; POP HL ; JR C,L30EF ; to MULT-OFLW LD A,D ; OR E ; JR NZ,L30EA ; to MULT-RSLT LD C,A ; ;; MULT-RSLT L30EA: CALL L2D8E ; routine INT-STORE POP DE ; RET ; ; --- ;; MULT-OFLW L30EF: POP DE ; ;; MULT-LONG L30F0: CALL L3293 ; routine RE-ST-TWO XOR A ; CALL L30C0 ; routine PREP-M/D RET C ; EXX ; PUSH HL ; EXX ; PUSH DE ; EX DE,HL ; CALL L30C0 ; routine PREP-M/D EX DE,HL ; JR C,L315D ; to ZERO-RSLT PUSH HL ; CALL L2FBA ; routine FETCH-TWO LD A,B ; AND A ; SBC HL,HL ; EXX ; PUSH HL ; SBC HL,HL ; EXX ; LD B,021h ; JR L3125 ; to STRT-MLT ; --- ;; MLT-LOOP L3114: JR NC,L311B ; to NO-ADD ADD HL,DE ; EXX ; ADC HL,DE ; EXX ; ;; NO-ADD L311B: EXX ; RR H ; RR L ; EXX ; RR H ; RR L ; ;; STRT-MLT L3125: EXX ; RR B ; RR C ; EXX ; RR C ; RRA ; DJNZ L3114 ; to MLT-LOOP EX DE,HL ; EXX ; EX DE,HL ; EXX ; POP BC ; POP HL ; LD A,B ; ADD A,C ; JR NZ,L313B ; to MAKE-EXPT AND A ; ;; MAKE-EXPT L313B: DEC A ; CCF ; Complement Carry Flag ;; DIVN-EXPT L313D: RLA ; CCF ; Complement Carry Flag RRA ; JP P,L3146 ; to OFLW1-CLR JR NC,L31AD ; to REPORT-6 AND A ; ;; OFLW1-CLR L3146: INC A ; JR NZ,L3151 ; to OFLW2-CLR JR C,L3151 ; to OFLW2-CLR EXX ; BIT 7,D ; EXX ; JR NZ,L31AD ; to REPORT-6 ;; OFLW2-CLR L3151: LD (HL),A ; EXX ; LD A,B ; EXX ; ;; TEST-NORM L3155: JR NC,L316C ; to NORMALISE LD A,(HL) ; AND A ; ;; NEAR-ZERO L3159: LD A,080h ; JR Z,L315E ; to SKIP-ZERO ;; ZERO-RSLT L315D: XOR A ; ;; SKIP-ZERO L315E: EXX ; AND D ; CALL L2FFB ; routine ZEROS-4/5 RLCA ; LD (HL),A ; JR C,L3195 ; to OFLOW-CLR INC HL ; LD (HL),A ; DEC HL ; JR L3195 ; to OFLOW-CLR ; --- ;; NORMALISE L316C: LD B,020h ; ;; SHIFT-ONE L316E: EXX ; BIT 7,D ; EXX ; JR NZ,L3186 ; to NORML-NOW RLCA ; RL E ; RL D ; EXX ; RL E ; RL D ; EXX ; DEC (HL) ; JR Z,L3159 ; to NEAR-ZERO DJNZ L316E ; to SHIFT-ONE JR L315D ; to ZERO-RSLT ; --- ;; NORML-NOW L3186: RLA ; JR NC,L3195 ; to OFLOW-CLR CALL L3004 ; routine ADD-BACK JR NZ,L3195 ; to OFLOW-CLR EXX ; LD D,080h ; EXX ; INC (HL) ; JR Z,L31AD ; to REPORT-6 ;; OFLOW-CLR L3195: PUSH HL ; INC HL ; EXX ; PUSH DE ; EXX ; POP BC ; LD A,B ; RLA ; RL (HL) ; RRA ; LD (HL),A ; INC HL ; LD (HL),C ; INC HL ; LD (HL),D ; INC HL ; LD (HL),E ; POP HL ; POP DE ; EXX ; POP HL ; EXX ; RET ; ; --- ;; REPORT-6 L31AD: RST 08H ; ERROR-1 .DEFB 005h ; Error Report: Number too big ; ---------------------- ; THE 'DIVISION' ROUTINE ; ---------------------- ; (offset: 005h 'division') ; ; "He who can properly define and divide is to be considered a god" ; - Plato, 429 - 347 B.C. ;; division L31AF: CALL L3293 ; routine RE-ST-TWO EX DE,HL ; XOR A ; CALL L30C0 ; routine PREP-M/D JR C,L31AD ; to REPORT-6 EX DE,HL ; CALL L30C0 ; routine PREP-M/D RET C ; EXX ; PUSH HL ; EXX ; PUSH DE ; PUSH HL ; CALL L2FBA ; routine FETCH-TWO EXX ; PUSH HL ; LD H,B ; LD L,C ; EXX ; LD H,C ; LD L,B ; XOR A ; LD B,0DFh ; JR L31E2 ; to DIV-START ; --- ;; DIV-LOOP L31D2: RLA ; RL C ; EXX ; RL C ; RL B ; EXX ; ;; div-34th L31DB: ADD HL,HL ; EXX ; ADC HL,HL ; EXX ; JR C,L31F2 ; to SUBN-ONLY ;; DIV-START L31E2: SBC HL,DE ; EXX ; SBC HL,DE ; EXX ; JR NC,L31F9 ; to NO-RSTORE ADD HL,DE ; EXX ; ADC HL,DE ; EXX ; AND A ; JR L31FA ; to COUNT-ONE ; --- ;; SUBN-ONLY L31F2: AND A ; SBC HL,DE ; EXX ; SBC HL,DE ; EXX ; ;; NO-RSTORE L31F9: SCF ; Set Carry Flag ;; COUNT-ONE L31FA: INC B ; JP M,L31D2 ; to DIV-LOOP PUSH AF ; JR Z,L31E2 ; to DIV-START ; ; ; ; LD E,A ; LD D,C ; EXX ; LD E,C ; LD D,B ; POP AF ; RR B ; POP AF ; RR B ; EXX ; POP BC ; POP HL ; LD A,B ; SUB C ; JP L313D ; jump back to DIVN-EXPT ; ------------------------------------ ; Integer truncation towards zero (03Ah) ; ------------------------------------ ; ; ;; truncate L3214: LD A,(HL) ; AND A ; RET Z ; CP 081h ; JR NC,L3221 ; to T-GR-ZERO LD (HL),00h ; LD A,020h ; JR L3272 ; to NIL-BYTES ; --- ;; T-GR-ZERO L3221: CP 091h ; JR NZ,L323F ; to T-SMALL INC HL ; INC HL ; INC HL ; LD A,080h ; AND (HL) ; DEC HL ; OR (HL) ; DEC HL ; JR NZ,L3233 ; to T-FIRST LD A,080h ; XOR (HL) ; ;; T-FIRST L3233: DEC HL ; JR NZ,L326C ; to T-EXPNENT LD (HL),A ; INC HL ; LD (HL),0FFh ; DEC HL ; LD A,018h ; JR L3272 ; to NIL-BYTES ; --- ;; T-SMALL L323F: JR NC,L326D ; to X-LARGE PUSH DE ; CPL ; ADD A,091h ; INC HL ; LD D,(HL) ; INC HL ; LD E,(HL) ; DEC HL ; DEC HL ; LD C,00h ; BIT 7,D ; JR Z,L3252 ; to T-NUMERIC DEC C ; ;; T-NUMERIC L3252: SET 7,D ; LD B,008h ; SUB B ; ADD A,B ; JR C,L325E ; to T-TEST LD E,D ; LD D,00h ; SUB B ; ;; T-TEST L325E: JR Z,L3267 ; to T-STORE LD B,A ; ;; T-SHIFT L3261: SRL D ; RR E ; DJNZ L3261 ; to T-SHIFT ;; T-STORE L3267: CALL L2D8E ; routine INT-STORE POP DE ; RET ; ; --- ;; T-EXPNENT L326C: LD A,(HL) ; ;; X-LARGE L326D: SUB 0A0h ; RET P ; NEG ; Negate ;; NIL-BYTES L3272: PUSH DE ; EX DE,HL ; DEC HL ; LD B,A ; SRL B ; SRL B ; SRL B ; JR Z,L3283 ; to BITS-ZERO ;; BYTE-ZERO L327E: LD (HL),00h ; DEC HL ; DJNZ L327E ; to BYTE-ZERO ;; BITS-ZERO L3283: AND 007h ; JR Z,L3290 ; to IX-END LD B,A ; LD A,0FFh ; ;; LESS-MASK L328A: SLA A ; DJNZ L328A ; to LESS-MASK AND (HL) ; LD (HL),A ; ;; IX-END L3290: EX DE,HL ; POP DE ; RET ; ; ---------------------------------- ; Storage of numbers in 5 byte form. ; ================================== ; Both integers and floating-point numbers can be stored in five bytes. ; Zero is a special case stored as 5 zeros. ; For integers the form is ; Byte 1 - zero, ; Byte 2 - sign byte, 00h +ve, 0FFh -ve. ; Byte 3 - Low byte of integer. ; Byte 4 - High byte ; Byte 5 - unused but always zero. ; ; it seems unusual to store the low byte first but it is just as easy either ; way. Statistically it just increases the chances of trailing zeros which ; is an advantage elsewhere in saving ROM code. ; ; zero sign low high unused ; So +1 is 00000000 00000000 00000001 00000000 00000000 ; ; and -1 is 00000000 11111111 11111111 11111111 00000000 ; ; much of the arithmetic found in BASIC lines can be done using numbers ; in this form using the Z80's 16 bit register operation ADD. ; (multiplication is done by a sequence of additions). ; ; Storing -ve integers in two's complement form, means that they are ready for ; addition and you might like to add the numbers above to prove that the ; answer is zero. If, as in this case, the carry is set then that denotes that ; the result is positive. This only applies when the signs don't match. ; With positive numbers a carry denotes the result is out of integer range. ; With negative numbers a carry denotes the result is within range. ; The exception to the last rule is when the result is -65536 ; ; Floating point form is an alternative method of storing numbers which can ; be used for integers and larger (or fractional) numbers. ; ; In this form 1 is stored as ; 10000001 00000000 00000000 00000000 00000000 ; ; When a small integer is converted to a floating point number the last two ; bytes are always blank so they are omitted in the following steps ; ; first make exponent +1 +16d (bit 7 of the exponent is set if positive) ; 10010001 00000000 00000001 ; 10010000 00000000 00000010 <- now shift left and decrement exponent ; ... ; 10000010 01000000 00000000 <- until a 1 abuts the imaginary point ; 10000001 10000000 00000000 to the left of the mantissa. ; ; however since the leftmost bit of the mantissa is always set then it can ; be used to denote the sign of the mantissa and put back when needed by the ; PREP routines which gives ; ; 10000001 00000000 00000000 ; ---------------------------------------------- ; THE 'RE-STACK TWO "SMALL" INTEGERS' SUBROUTINE ; ---------------------------------------------- ; This routine is called to re-stack two numbers in full floating point form ; e.g. from mult when integer multiplication has overflowed. ;; RE-ST-TWO L3293: CALL L3296 ; routine RESTK-SUB below and continue ; into the routine to do the other one. ;; RESTK-SUB L3296: EX DE,HL ; swap pointers ; --------------------------------------------- ; THE 'RE-STACK ONE "SMALL" INTEGER' SUBROUTINE ; --------------------------------------------- ; (offset: 03Dh 're-stack') ; This routine re-stacks an integer, usually on the calculator stack, in full ; floating point form. HL points to first byte. ;; re-stack L3297: LD A,(HL) ; Fetch Exponent byte to A AND A ; test it RET NZ ; return if not zero as already in full ; floating-point form. PUSH DE ; preserve DE. CALL L2D7F ; routine INT-FETCH ; integer to DE, sign to C. ; HL points to 4th byte. XOR A ; clear accumulator. INC HL ; point to 5th. LD (HL),A ; and blank. DEC HL ; point to 4th. LD (HL),A ; and blank. LD B,091h ; set exponent byte +ve 081h ; and imaginary dec point 16 bits to right ; of first bit. ; we could skip to normalize now but it's quicker to avoid normalizing ; through an empty D. LD A,D ; fetch the high byte D AND A ; is it zero ? JR NZ,L32B1 ; skip to RS-NRMLSE if not. OR E ; low byte E to A and test for zero LD B,D ; set B exponent to 0 JR Z,L32BD ; forward to RS-STORE if value is zero. LD D,E ; transfer E to D LD E,B ; set E to 0 LD B,089h ; reduce the initial exponent by eight. ;; RS-NRMLSE L32B1: EX DE,HL ; integer to HL, addr of 4th byte to DE. ;; RSTK-LOOP L32B2: DEC B ; decrease exponent ADD HL,HL ; shift DE left JR NC,L32B2 ; loop back to RSTK-LOOP ; until a set bit pops into carry RRC C ; now rotate the sign byte 00h or 0FFh ; into carry to give a sign bit RR H ; rotate the sign bit to left of H RR L ; rotate any carry into L EX DE,HL ; address 4th byte, normalized int to DE ;; RS-STORE L32BD: DEC HL ; address 3rd byte LD (HL),E ; place E DEC HL ; address 2nd byte LD (HL),D ; place D DEC HL ; address 1st byte LD (HL),B ; store the exponent POP DE ; restore initial DE. RET ; return. ;**************************************** ;** Part 10. FLOATING-POINT CALCULATOR ** ;**************************************** ; As a general rule the calculator avoids using the IY register. ; exceptions are val, val$ and str$. ; So an assembly language programmer who has disabled interrupts to use ; IY for other purposes can still use the calculator for mathematical ; purposes. ; ------------------------ ; THE 'TABLE OF CONSTANTS' ; ------------------------ ; ; ; used 11 times ;; stk-zero 00 00 00 00 00 L32C5: .DEFB 00h ;;Bytes: 1 .DEFB 0B0h ;;Exponent 00h .DEFB 00h ;;(+00,+00,+00) ; used 19 times ;; stk-one 00 00 01 00 00 L32C8: .DEFB 040h ;;Bytes: 2 .DEFB 0B0h ;;Exponent 00h .DEFB 00h,001h ;;(+00,+00) ; used 9 times ;; stk-half 80 00 00 00 00 L32CC: .DEFB 030h ;;Exponent: 080h, Bytes: 1 .DEFB 00h ;;(+00,+00,+00) ; used 4 times. ;; stk-pi/2 81 49 0F DA A2 L32CE: .DEFB 0F1h ;;Exponent: 081h, Bytes: 4 .DEFB 049h,00Fh,0DAh,0A2h ;; ; used 3 times. ;; stk-ten 00 00 0A 00 00 L32D3: .DEFB 040h ;;Bytes: 2 .DEFB 0B0h ;;Exponent 00h .DEFB 00h,00Ah ;;(+00,+00) ; ------------------------ ; THE 'TABLE OF ADDRESSES' ; ------------------------ ; "Each problem that I solved became a rule which served afterwards to solve ; other problems" - Rene Descartes 1596 - 1650. ; ; Starts with binary operations which have two operands and one result. ; Three pseudo binary operations first. ;; tbl-addrs L32D7: .DEFW L368F ; 00h Address: 0368Fh - jump-true .DEFW L343C ; 001h Address: 0343Ch - exchange .DEFW L33A1 ; 002h Address: 033A1h - delete ; True binary operations. .DEFW L300F ; 003h Address: 0300Fh - subtract .DEFW L30CA ; 004h Address: 030CAh - multiply .DEFW L31AF ; 005h Address: 031AFh - division .DEFW L3851 ; 006h Address: 03851h - to-power .DEFW L351B ; 007h Address: 0351Bh - or .DEFW L3524 ; 008h Address: 03524h - no-&-no .DEFW L353B ; 009h Address: 0353Bh - no-l-eql .DEFW L353B ; 00Ah Address: 0353Bh - no-gr-eql .DEFW L353B ; 00Bh Address: 0353Bh - nos-neql .DEFW L353B ; 00Ch Address: 0353Bh - no-grtr .DEFW L353B ; 00Dh Address: 0353Bh - no-less .DEFW L353B ; 00Eh Address: 0353Bh - nos-eql .DEFW L3014 ; 00Fh Address: 03014h - addition .DEFW L352D ; 010h Address: 0352Dh - str-&-no .DEFW L353B ; 011h Address: 0353Bh - str-l-eql .DEFW L353B ; 012h Address: 0353Bh - str-gr-eql .DEFW L353B ; 013h Address: 0353Bh - strs-neql .DEFW L353B ; 014h Address: 0353Bh - str-grtr .DEFW L353B ; 015h Address: 0353Bh - str-less .DEFW L353B ; 016h Address: 0353Bh - strs-eql .DEFW L359C ; 017h Address: 0359Ch - strs-add ; Unary follow. .DEFW L35DE ; 018h Address: 035DEh - val$ .DEFW L34BC ; 019h Address: 034BCh - usr-$ .DEFW L3645 ; 01Ah Address: 03645h - read-in .DEFW L346E ; 01Bh Address: 0346Eh - negate .DEFW L3669 ; 01Ch Address: 03669h - code .DEFW L35DE ; 01Dh Address: 035DEh - val .DEFW L3674 ; 01Eh Address: 03674h - len .DEFW L37B5 ; 01Fh Address: 037B5h - sin .DEFW L37AA ; 020h Address: 037AAh - cos .DEFW L37DA ; 021h Address: 037DAh - tan .DEFW L3833 ; 022h Address: 03833h - asn .DEFW L3843 ; 023h Address: 03843h - acs .DEFW L37E2 ; 024h Address: 037E2h - atn .DEFW L3713 ; 025h Address: 03713h - ln .DEFW L36C4 ; 026h Address: 036C4h - exp .DEFW L36AF ; 027h Address: 036AFh - int .DEFW L384A ; 028h Address: 0384Ah - sqr .DEFW L3492 ; 029h Address: 03492h - sgn .DEFW L346A ; 02Ah Address: 0346Ah - abs .DEFW L34AC ; 02Bh Address: 034ACh - peek .DEFW L34A5 ; 02Ch Address: 034A5h - in .DEFW L34B3 ; 02Dh Address: 034B3h - usr-no .DEFW L361F ; 02Eh Address: 0361Fh - str$ .DEFW L35C9 ; 02Fh Address: 035C9h - chrs .DEFW L3501 ; 030h Address: 03501h - not ; End of true unary. .DEFW L33C0 ; 031h Address: 033C0h - duplicate .DEFW L36A0 ; 032h Address: 036A0h - n-mod-m .DEFW L3686 ; 033h Address: 03686h - jump .DEFW L33C6 ; 034h Address: 033C6h - stk-data .DEFW L367A ; 035h Address: 0367Ah - dec-jr-nz .DEFW L3506 ; 036h Address: 03506h - less-0 .DEFW L34F9 ; 037h Address: 034F9h - greater-0 .DEFW L369B ; 038h Address: 0369Bh - end-calc .DEFW L3783 ; 039h Address: 03783h - get-argt .DEFW L3214 ; 03Ah Address: 03214h - truncate .DEFW L33A2 ; 03Bh Address: 033A2h - fp-calc-2 .DEFW L2D4F ; 03Ch Address: 02D4Fh - e-to-fp .DEFW L3297 ; 03Dh Address: 03297h - re-stack ; The following are just the next available slots for the 128 compound ; literals which are in range 080h - 0FFh. .DEFW L3449 ; Address: 03449h - series-xx 080h - 09Fh. .DEFW L341B ; Address: 0341Bh - stk-const-xx 0A0h - 0BFh. .DEFW L342D ; Address: 0342Dh - st-mem-xx 0C0h - 0DFh. .DEFW L340F ; Address: 0340Fh - get-mem-xx 0E0h - 0FFh. ; Aside: 3E - 3F are therefore unused calculator literals. ; If the literal has to be also usable as a function then bits 6 and 7 are ; used to show type of arguments and result. ; -------------- ; The Calculator ; -------------- ; "A good calculator does not need artificial aids" ; Lao Tze 604 - 531 B.C. ;; CALCULATE L335B: CALL L35BF ; routine STK-PNTRS is called to set up the ; calculator stack pointers for a default ; unary operation. HL = last value on stack. ; DE = STKEND first location after stack. ; the calculate routine is called at this point by the series generator... ;; GEN-ENT-1 L335E: LD A,B ; fetch the Z80 B register to A LD (05C67h),A ; and store value in system variable BREG. ; this will be the counter for dec-jr-nz ; or if used from fp-calc2 the calculator ; instruction. ; ... and again later at this point ;; GEN-ENT-2 L3362: EXX ; switch sets EX (SP),HL ; and store the address of next instruction, ; the return address, in H'L'. ; If this is a recursive call the H'L' ; of the previous invocation goes on stack. ; c.f. end-calc. EXX ; switch back to main set ; this is the re-entry looping point when handling a string of literals. ;; RE-ENTRY L3365: LD (05C65h),DE ; save end of stack in system variable STKEND EXX ; switch to alt LD A,(HL) ; get next literal INC HL ; increase pointer' ; single operation jumps back to here ;; SCAN-ENT L336C: PUSH HL ; save pointer on stack AND A ; now test the literal JP P,L3380 ; forward to FIRST-3D if in range 00h - 03Dh ; anything with bit 7 set will be one of ; 128 compound literals. ; compound literals have the following format. ; bit 7 set indicates compound. ; bits 6-5 the subgroup 0-3. ; bits 4-0 the embedded parameter 00h - 01Fh. ; The subgroup 0-3 needs to be manipulated to form the next available four ; address places after the simple literals in the address table. LD D,A ; save literal in D AND 060h ; and with 01100000 to isolate subgroup RRCA ; rotate bits RRCA ; 4 places to right RRCA ; not five as we need offset * 2 RRCA ; 00000xx0 ADD A,07Ch ; add (03Eh * 2) to give correct offset. ; alter above if you add more literals. LD L,A ; store in L for later indexing. LD A,D ; bring back compound literal AND 01Fh ; use mask to isolate parameter bits JR L338E ; forward to ENT-TABLE ; --- ; the branch was here with simple literals. ;; FIRST-3D L3380: CP 018h ; compare with first unary operations. JR NC,L338C ; to DOUBLE-A with unary operations ; it is binary so adjust pointers. EXX ; LD BC,0FFFBh ; the value -5 LD D,H ; transfer HL, the last value, to DE. LD E,L ; ADD HL,BC ; subtract 5 making HL point to second ; value. EXX ; ;; DOUBLE-A L338C: RLCA ; double the literal LD L,A ; and store in L for indexing ;; ENT-TABLE L338E: LD DE,L32D7 ; Address: tbl-addrs LD H,00h ; prepare to index ADD HL,DE ; add to get address of routine LD E,(HL) ; low byte to E INC HL ; LD D,(HL) ; high byte to D LD HL,L3365 ; Address: RE-ENTRY EX (SP),HL ; goes to stack PUSH DE ; now address of routine EXX ; main set ; avoid using IY register. LD BC,(05C66h) ; STKEND_hi ; nothing much goes to C but BREG to B ; and continue into next ret instruction ; which has a dual identity ; ------------------ ; Handle delete (02) ; ------------------ ; A simple return but when used as a calculator literal this ; deletes the last value from the calculator stack. ; On entry, as always with binary operations, ; HL=first number, DE=second number ; On exit, HL=result, DE=stkend. ; So nothing to do ;; delete L33A1: RET ; return - indirect jump if from above. ; --------------------- ; Single operation (3B) ; --------------------- ; This single operation is used, in the first instance, to evaluate most ; of the mathematical and string functions found in BASIC expressions. ;; fp-calc-2 L33A2: POP AF ; drop return address. LD A,(05C67h) ; load accumulator from system variable BREG ; value will be literal e.g. 'tan' EXX ; switch to alt JR L336C ; back to SCAN-ENT ; next literal will be end-calc at L2758 ; --------------------------------- ; THE 'TEST FIVE SPACES' SUBROUTINE ; --------------------------------- ; This routine is called from MOVE-FP, STK-CONST and STK-STORE to test that ; there is enough space between the calculator stack and the machine stack ; for another five-byte value. It returns with BC holding the value 5 ready ; for any subsequent LDIR. ;; TEST-5-SP L33A9: PUSH DE ; save PUSH HL ; registers LD BC,005h ; an overhead of five bytes CALL L1F05 ; routine TEST-ROOM tests free RAM raising ; an error if not. POP HL ; else restore POP DE ; registers. RET ; return with BC set at 5. ; ----------------------------- ; THE 'STACK NUMBER' SUBROUTINE ; ----------------------------- ; This routine is called to stack a hidden floating point number found in ; a BASIC line. It is also called to stack a numeric variable value, and ; from BEEP, to stack an entry in the semi-tone table. It is not part of the ; calculator suite of routines. On entry, HL points to the number to be ; stacked. ;; STACK-NUM L33B4: LD DE,(05C65h) ; Load destination from STKEND system variable. CALL L33C0 ; Routine MOVE-FP puts on calculator stack ; with a memory check. LD (05C65h),DE ; Set STKEND to next free location. RET ; Return. ; --------------------------------- ; Move a floating point number (31) ; --------------------------------- ; This simple routine is a 5-byte LDIR instruction ; that incorporates a memory check. ; When used as a calculator literal it duplicates the last value on the ; calculator stack. ; Unary so on entry HL points to last value, DE to stkend ;; duplicate ;; MOVE-FP L33C0: CALL L33A9 ; routine TEST-5-SP test free memory ; and sets BC to 5. LDIR ; copy the five bytes. RET ; return with DE addressing new STKEND ; and HL addressing new last value. ; ------------------- ; Stack literals (034h) ; ------------------- ; When a calculator subroutine needs to put a value on the calculator ; stack that is not a regular constant this routine is called with a ; variable number of following data bytes that convey to the routine ; the integer or floating point form as succinctly as is possible. ;; stk-data L33C6: LD H,D ; transfer STKEND LD L,E ; to HL for result. ;; STK-CONST L33C8: CALL L33A9 ; routine TEST-5-SP tests that room exists ; and sets BC to 005h. EXX ; switch to alternate set PUSH HL ; save the pointer to next literal on stack EXX ; switch back to main set EX (SP),HL ; pointer to HL, destination to stack. PUSH BC ; save BC - value 5 from test room ??. LD A,(HL) ; fetch the byte following 'stk-data' AND 0C0h ; isolate bits 7 and 6 RLCA ; rotate RLCA ; to bits 1 and 0 range 00h - 003h. LD C,A ; transfer to C INC C ; and increment to give number of bytes ; to read. 001h - 004h LD A,(HL) ; reload the first byte AND 03Fh ; mask off to give possible exponent. JR NZ,L33DE ; forward to FORM-EXP if it was possible to ; include the exponent. ; else byte is just a byte count and exponent comes next. INC HL ; address next byte and LD A,(HL) ; pick up the exponent ( - 050h). ;; FORM-EXP L33DE: ADD A,050h ; now add 050h to form actual exponent LD (DE),A ; and load into first destination byte. LD A,005h ; load accumulator with 005h and SUB C ; subtract C to give count of trailing ; zeros plus one. INC HL ; increment source INC DE ; increment destination LD B,00h ; prepare to copy LDIR ; copy C bytes POP BC ; restore 5 counter to BC ??. EX (SP),HL ; put HL on stack as next literal pointer ; and the stack value - result pointer - ; to HL. EXX ; switch to alternate set. POP HL ; restore next literal pointer from stack ; to H'L'. EXX ; switch back to main set. LD B,A ; zero count to B XOR A ; clear accumulator ;; STK-ZEROS L33F1: DEC B ; decrement B counter RET Z ; return if zero. >> ; DE points to new STKEND ; HL to new number. LD (DE),A ; else load zero to destination INC DE ; increase destination JR L33F1 ; loop back to STK-ZEROS until done. ; ------------------------------- ; THE 'SKIP CONSTANTS' SUBROUTINE ; ------------------------------- ; This routine traverses variable-length entries in the table of constants, ; stacking intermediate, unwanted constants onto a dummy calculator stack, ; in the first five bytes of ROM. The destination DE normally points to the ; end of the calculator stack which might be in the normal place or in the ; system variables area during E-LINE-NO; INT-TO-FP; stk-ten. In any case, ; it would be simpler all round if the routine just shoved unwanted values ; where it is going to stick the wanted value. The instruction LD DE, 000h ; can be removed. ;; SKIP-CONS L33F7: AND A ; test if initially zero. ;; SKIP-NEXT L33F8: RET Z ; return if zero. >> PUSH AF ; save count. PUSH DE ; and normal STKEND LD DE,000h ; dummy value for STKEND at start of ROM ; Note. not a fault but this has to be ; moved elsewhere when running in RAM. ; e.g. with Expandor Systems 'Soft ROM'. ; Better still, write to the normal place. CALL L33C8 ; routine STK-CONST works through variable ; length records. POP DE ; restore real STKEND POP AF ; restore count DEC A ; decrease JR L33F8 ; loop back to SKIP-NEXT ; ------------------------------ ; THE 'LOCATE MEMORY' SUBROUTINE ; ------------------------------ ; This routine, when supplied with a base address in HL and an index in A, ; will calculate the address of the A'th entry, where each entry occupies ; five bytes. It is used for reading the semi-tone table and addressing ; floating-point numbers in the calculator's memory area. ; It is not possible to use this routine for the table of constants as these ; six values are held in compressed format. ;; LOC-MEM L3406: LD C,A ; store the original number 00h-01Fh. RLCA ; X2 - double. RLCA ; X4 - quadruple. ADD A,C ; X5 - now add original to multiply by five. LD C,A ; place the result in the low byte. LD B,00h ; set high byte to zero. ADD HL,BC ; add to form address of start of number in HL. RET ; return. ; ------------------------------ ; Get from memory area (0E0h etc.) ; ------------------------------ ; Literals 0E0h to 0FFh ; A holds 00h-01Fh offset. ; The calculator stack increases by 5 bytes. ;; get-mem-xx L340F: PUSH DE ; save STKEND LD HL,(05C68h) ; MEM is base address of the memory cells. CALL L3406 ; routine LOC-MEM so that HL = first byte CALL L33C0 ; routine MOVE-FP moves 5 bytes with memory ; check. ; DE now points to new STKEND. POP HL ; original STKEND is now RESULT pointer. RET ; return. ; -------------------------- ; Stack a constant (A0 etc.) ; -------------------------- ; This routine allows a one-byte instruction to stack up to 32 constants ; held in short form in a table of constants. In fact only 5 constants are ; required. On entry the A register holds the literal ANDed with 1F. ; It isn't very efficient and it would have been better to hold the ; numbers in full, five byte form and stack them in a similar manner ; to that used for semi-tone table values. ;; stk-const-xx L341B: LD H,D ; save STKEND - required for result LD L,E ; EXX ; swap PUSH HL ; save pointer to next literal LD HL,L32C5 ; Address: stk-zero - start of table of ; constants EXX ; CALL L33F7 ; routine SKIP-CONS CALL L33C8 ; routine STK-CONST EXX ; POP HL ; restore pointer to next literal. EXX ; RET ; return. ; -------------------------------- ; Store in a memory area (0C0h etc.) ; -------------------------------- ; Offsets 0C0h to 0DFh ; Although 32 memory storage locations can be addressed, only six ; 0C0h to 0C5h are required by the ROM and only the thirty bytes (6*5) ; required for these are allocated. Spectrum programmers who wish to ; use the floating point routines from assembly language may wish to ; alter the system variable MEM to point to 160 bytes of RAM to have ; use the full range available. ; A holds the derived offset 00h-01Fh. ; This is a unary operation, so on entry HL points to the last value and DE ; points to STKEND. ;; st-mem-xx L342D: PUSH HL ; save the result pointer. EX DE,HL ; transfer to DE. LD HL,(05C68h) ; fetch MEM the base of memory area. CALL L3406 ; routine LOC-MEM sets HL to the destination. EX DE,HL ; swap - HL is start, DE is destination. CALL L33C0 ; routine MOVE-FP. ; note. a short ld bc,5; ldir ; the embedded memory check is not required ; so these instructions would be faster. EX DE,HL ; DE = STKEND POP HL ; restore original result pointer RET ; return. ; ------------------------- ; THE 'EXCHANGE' SUBROUTINE ; ------------------------- ; (offset: 001h 'exchange') ; This routine swaps the last two values on the calculator stack. ; On entry, as always with binary operations, ; HL=first number, DE=second number ; On exit, HL=result, DE=stkend. ;; exchange L343C: LD B,005h ; there are five bytes to be swapped ; start of loop. ;; SWAP-BYTE L343E: LD A,(DE) ; each byte of second LD C,(HL) ; each byte of first EX DE,HL ; swap pointers LD (DE),A ; store each byte of first LD (HL),C ; store each byte of second INC HL ; advance both INC DE ; pointers. DJNZ L343E ; loop back to SWAP-BYTE until all 5 done. EX DE,HL ; even up the exchanges so that DE addresses ; STKEND. RET ; return. ; ------------------------------ ; THE 'SERIES GENERATOR' ROUTINE ; ------------------------------ ; (offset: 086h 'series-06') ; (offset: 088h 'series-08') ; (offset: 08Ch 'series-0C') ; The Spectrum uses Chebyshev polynomials to generate approximations for ; SIN, ATN, LN and EXP. These are named after the Russian mathematician ; Pafnuty Chebyshev, born in 1821, who did much pioneering work on numerical ; series. As far as calculators are concerned, Chebyshev polynomials have an ; advantage over other series, for example the Taylor series, as they can ; reach an approximation in just six iterations for SIN, eight for EXP and ; twelve for LN and ATN. The mechanics of the routine are interesting but ; for full treatment of how these are generated with demonstrations in ; Sinclair BASIC see "The Complete Spectrum ROM Disassembly" by Dr Ian Logan ; and Dr Frank O'Hara, published 1983 by Melbourne House. ;; series-xx L3449: LD B,A ; parameter 00h - 01Fh to B counter CALL L335E ; routine GEN-ENT-1 is called. ; A recursive call to a special entry point ; in the calculator that puts the B register ; in the system variable BREG. The return ; address is the next location and where ; the calculator will expect its first ; instruction - now pointed to by HL'. ; The previous pointer to the series of ; five-byte numbers goes on the machine stack. ; The initialization phase. .DEFB 031h ;;duplicate x,x .DEFB 00Fh ;;addition x+x .DEFB 0C0h ;;st-mem-0 x+x .DEFB 002h ;;delete . .DEFB 0A0h ;;stk-zero 0 .DEFB 0C2h ;;st-mem-2 0 ; a loop is now entered to perform the algebraic calculation for each of ; the numbers in the series ;; G-LOOP L3453: .DEFB 031h ;;duplicate v,v. .DEFB 0E0h ;;get-mem-0 v,v,x+2 .DEFB 004h ;;multiply v,v*x+2 .DEFB 0E2h ;;get-mem-2 v,v*x+2,v .DEFB 0C1h ;;st-mem-1 .DEFB 003h ;;subtract .DEFB 038h ;;end-calc ; the previous pointer is fetched from the machine stack to H'L' where it ; addresses one of the numbers of the series following the series literal. CALL L33C6 ; routine STK-DATA is called directly to ; push a value and advance H'L'. CALL L3362 ; routine GEN-ENT-2 recursively re-enters ; the calculator without disturbing ; system variable BREG ; H'L' value goes on the machine stack and is ; then loaded as usual with the next address. .DEFB 00Fh ;;addition .DEFB 001h ;;exchange .DEFB 0C2h ;;st-mem-2 .DEFB 002h ;;delete .DEFB 035h ;;dec-jr-nz .DEFB 0EEh ;;back to L3453, G-LOOP ; when the counted loop is complete the final subtraction yields the result ; for example SIN X. .DEFB 0E1h ;;get-mem-1 .DEFB 003h ;;subtract .DEFB 038h ;;end-calc RET ; return with H'L' pointing to location ; after last number in series. ; --------------------------------- ; THE 'ABSOLUTE MAGNITUDE' FUNCTION ; --------------------------------- ; (offset: 02Ah 'abs') ; This calculator literal finds the absolute value of the last value, ; integer or floating point, on calculator stack. ;; abs L346A: LD B,0FFh ; signal abs JR L3474 ; forward to NEG-TEST ; --------------------------- ; THE 'UNARY MINUS' OPERATION ; --------------------------- ; (offset: 01Bh 'negate') ; Unary so on entry HL points to last value, DE to STKEND. ;; NEGATE ;; negate L346E: CALL L34E9 ; call routine TEST-ZERO and RET C ; return if so leaving zero unchanged. LD B,00h ; signal negate required before joining ; common code. ;; NEG-TEST L3474: LD A,(HL) ; load first byte and AND A ; test for zero JR Z,L3483 ; forward to INT-CASE if a small integer ; for floating point numbers a single bit denotes the sign. INC HL ; address the first byte of mantissa. LD A,B ; action flag 0FFh=abs, 00h=neg. AND 080h ; now 080h 00h OR (HL) ; sets bit 7 for abs RLA ; sets carry for abs and if number negative CCF ; complement carry flag RRA ; and rotate back in altering sign LD (HL),A ; put the altered adjusted number back DEC HL ; HL points to result RET ; return with DE unchanged ; --- ; for integer numbers an entire byte denotes the sign. ;; INT-CASE L3483: PUSH DE ; save STKEND. PUSH HL ; save pointer to the last value/result. CALL L2D7F ; routine INT-FETCH puts integer in DE ; and the sign in C. POP HL ; restore the result pointer. LD A,B ; 0FFh=abs, 00h=neg OR C ; 0FFh for abs, no change neg CPL ; 00h for abs, switched for neg LD C,A ; transfer result to sign byte. CALL L2D8E ; routine INT-STORE to re-write the integer. POP DE ; restore STKEND. RET ; return. ; --------------------- ; THE 'SIGNUM' FUNCTION ; --------------------- ; (offset: 029h 'sgn') ; This routine replaces the last value on the calculator stack, ; which may be in floating point or integer form, with the integer values ; zero if zero, with one if positive and with -minus one if negative. ;; sgn L3492: CALL L34E9 ; call routine TEST-ZERO and RET C ; exit if so as no change is required. PUSH DE ; save pointer to STKEND. LD DE,001h ; the result will be 1. INC HL ; skip over the exponent. RL (HL) ; rotate the sign bit into the carry flag. DEC HL ; step back to point to the result. SBC A,A ; byte will be 0FFh if negative, 00h if positive. LD C,A ; store the sign byte in the C register. CALL L2D8E ; routine INT-STORE to overwrite the last ; value with 0001 and sign. POP DE ; restore STKEND. RET ; return. ; ----------------- ; THE 'IN' FUNCTION ; ----------------- ; (offset: 02Ch 'in') ; This function reads a byte from an input port. ;; in L34A5: CALL L1E99 ; Routine FIND-INT2 puts port address in BC. ; All 16 bits are put on the address line. IN A,(C) ; Read the port. JR L34B0 ; exit to STACK-A (via IN-PK-STK to save a byte ; of instruction code). ; ------------------- ; THE 'PEEK' FUNCTION ; ------------------- ; (offset: 02Bh 'peek') ; This function returns the contents of a memory address. ; The entire address space can be peeked including the ROM. ;; peek L34AC: CALL L1E99 ; routine FIND-INT2 puts address in BC. LD A,(BC) ; load contents into A register. ;; IN-PK-STK L34B0: JP L2D28 ; exit via STACK-A to put the value on the ; calculator stack. ; ------------------ ; THE 'USR' FUNCTION ; ------------------ ; (offset: $2d 'usr-no') ; The USR function followed by a number 0-65535 is the method by which ; the Spectrum invokes machine code programs. This function returns the ; contents of the BC register pair. ; Note. that STACK-BC re-initializes the IY register if a user-written ; program has altered it. ;; usr-no L34B3: CALL L1E99 ; routine FIND-INT2 to fetch the ; supplied address into BC. LD HL,L2D2B ; address: STACK-BC is PUSH HL ; pushed onto the machine stack. PUSH BC ; then the address of the machine code ; routine. RET ; make an indirect jump to the routine ; and, hopefully, to STACK-BC also. ; ------------------------- ; THE 'USR STRING' FUNCTION ; ------------------------- ; (offset: 019h 'usr-$') ; The user function with a one-character string argument, calculates the ; address of the User Defined Graphic character that is in the string. ; As an alternative, the ASCII equivalent, upper or lower case, ; may be supplied. This provides a user-friendly method of redefining ; the 21 User Definable Graphics e.g. ; POKE USR "a", BIN 10000000 will put a dot in the top left corner of the ; character 144. ; Note. the curious double check on the range. With 26 UDGs the first check ; only is necessary. With anything less the second check only is required. ; It is highly likely that the first check was written by Steven Vickers. ;; usr-$ L34BC: CALL L2BF1 ; routine STK-FETCH fetches the string ; parameters. DEC BC ; decrease BC by LD A,B ; one to test OR C ; the length. JR NZ,L34E7 ; to REPORT-A if not a single character. LD A,(DE) ; fetch the character CALL L2C8D ; routine ALPHA sets carry if 'A-Z' or 'a-z'. JR C,L34D3 ; forward to USR-RANGE if ASCII. SUB 090h ; make UDGs range 0-20d JR C,L34E7 ; to REPORT-A if too low. e.g. usr " ". CP 015h ; Note. this test is not necessary. JR NC,L34E7 ; to REPORT-A if higher than 20. INC A ; make range 1-21d to match LSBs of ASCII ;; USR-RANGE L34D3: DEC A ; make range of bits 0-4 start at zero ADD A,A ; multiply by eight ADD A,A ; and lose any set bits ADD A,A ; range now 0 - 25*8 CP 0A8h ; compare to 21*8 JR NC,L34E7 ; to REPORT-A if originally higher ; than 'U','u' or graphics U. LD BC,(05C7Bh) ; fetch the UDG system variable value. ADD A,C ; add the offset to character LD C,A ; and store back in register C. JR NC,L34E4 ; forward to USR-STACK if no overflow. INC B ; increment high byte. ;; USR-STACK L34E4: JP L2D2B ; jump back and exit via STACK-BC to store ; --- ;; REPORT-A L34E7: RST 08H ; ERROR-1 .DEFB 009h ; Error Report: Invalid argument ; ------------------------------ ; THE 'TEST FOR ZERO' SUBROUTINE ; ------------------------------ ; Test if top value on calculator stack is zero. The carry flag is set if ; the last value is zero but no registers are altered. ; All five bytes will be zero but first four only need be tested. ; On entry, HL points to the exponent the first byte of the value. ;; TEST-ZERO L34E9: PUSH HL ; preserve HL which is used to address. PUSH BC ; preserve BC which is used as a store. LD B,A ; preserve A in B. LD A,(HL) ; load first byte to accumulator INC HL ; advance. OR (HL) ; OR with second byte and clear carry. INC HL ; advance. OR (HL) ; OR with third byte. INC HL ; advance. OR (HL) ; OR with fourth byte. LD A,B ; restore A without affecting flags. POP BC ; restore the saved POP HL ; registers. RET NZ ; return if not zero and with carry reset. SCF ; set the carry flag. RET ; return with carry set if zero. ; -------------------------------- ; THE 'GREATER THAN ZERO' OPERATOR ; -------------------------------- ; (offset: 037h 'greater-0' ) ; Test if the last value on the calculator stack is greater than zero. ; This routine is also called directly from the end-tests of the comparison ; routine. ;; GREATER-0 ;; greater-0 L34F9: CALL L34E9 ; routine TEST-ZERO RET C ; return if was zero as this ; is also the Boolean 'false' value. LD A,0FFh ; prepare XOR mask for sign bit JR L3507 ; forward to SIGN-TO-C ; to put sign in carry ; (carry will become set if sign is positive) ; and then overwrite location with 1 or 0 ; as appropriate. ; ------------------ ; THE 'NOT' FUNCTION ; ------------------ ; (offset: 030h 'not') ; This overwrites the last value with 1 if it was zero else with zero ; if it was any other value. ; ; e.g. NOT 0 returns 1, NOT 1 returns 0, NOT -3 returns 0. ; ; The subroutine is also called directly from the end-tests of the comparison ; operator. ;; NOT ;; not L3501: CALL L34E9 ; routine TEST-ZERO sets carry if zero JR L350B ; to FP-0/1 to overwrite operand with ; 1 if carry is set else to overwrite with zero. ; ------------------------------ ; THE 'LESS THAN ZERO' OPERATION ; ------------------------------ ; (offset: 036h 'less-0' ) ; Destructively test if last value on calculator stack is less than zero. ; Bit 7 of second byte will be set if so. ;; less-0 L3506: XOR A ; set XOR mask to zero ; (carry will become set if sign is negative). ; transfer sign of mantissa to Carry Flag. ;; SIGN-TO-C L3507: INC HL ; address 2nd byte. XOR (HL) ; bit 7 of HL will be set if number is negative. DEC HL ; address 1st byte again. RLCA ; rotate bit 7 of A to carry. ; ---------------------------- ; THE 'ZERO OR ONE' SUBROUTINE ; ---------------------------- ; This routine places an integer value of zero or one at the addressed ; location of the calculator stack or MEM area. The value one is written if ; carry is set on entry else zero. ;; FP-0/1 L350B: PUSH HL ; save pointer to the first byte LD A,00h ; load accumulator with zero - without ; disturbing flags. LD (HL),A ; zero to first byte INC HL ; address next LD (HL),A ; zero to 2nd byte INC HL ; address low byte of integer RLA ; carry to bit 0 of A LD (HL),A ; load one or zero to low byte. RRA ; restore zero to accumulator. INC HL ; address high byte of integer. LD (HL),A ; put a zero there. INC HL ; address fifth byte. LD (HL),A ; put a zero there. POP HL ; restore pointer to the first byte. RET ; return. ; ----------------- ; THE 'OR' OPERATOR ; ----------------- ; (offset: 007h 'or' ) ; The Boolean OR operator. e.g. X OR Y ; The result is zero if both values are zero else a non-zero value. ; ; e.g. 0 OR 0 returns 0. ; -3 OR 0 returns -3. ; 0 OR -3 returns 1. ; -3 OR 2 returns 1. ; ; A binary operation. ; On entry HL points to first operand (X) and DE to second operand (Y). ;; or L351B: EX DE,HL ; make HL point to second number CALL L34E9 ; routine TEST-ZERO EX DE,HL ; restore pointers RET C ; return if result was zero - first operand, ; now the last value, is the result. SCF ; set carry flag JR L350B ; back to FP-0/1 to overwrite the first operand ; with the value 1. ; --------------------------------- ; THE 'NUMBER AND NUMBER' OPERATION ; --------------------------------- ; (offset: 008h 'no-&-no') ; The Boolean AND operator. ; ; e.g. -3 AND 2 returns -3. ; -3 AND 0 returns 0. ; 0 and -2 returns 0. ; 0 and 0 returns 0. ; ; Compare with OR routine above. ;; no-&-no L3524: EX DE,HL ; make HL address second operand. CALL L34E9 ; routine TEST-ZERO sets carry if zero. EX DE,HL ; restore pointers. RET NC ; return if second non-zero, first is result. ; AND A ; else clear carry. JR L350B ; back to FP-0/1 to overwrite first operand ; with zero for return value. ; --------------------------------- ; THE 'STRING AND NUMBER' OPERATION ; --------------------------------- ; (offset: 010h 'str-&-no') ; e.g. "You Win" AND score>99 will return the string if condition is true ; or the null string if false. ;; str-&-no L352D: EX DE,HL ; make HL point to the number. CALL L34E9 ; routine TEST-ZERO. EX DE,HL ; restore pointers. RET NC ; return if number was not zero - the string ; is the result. ; if the number was zero (false) then the null string must be returned by ; altering the length of the string on the calculator stack to zero. PUSH DE ; save pointer to the now obsolete number ; (which will become the new STKEND) DEC DE ; point to the 5th byte of string descriptor. XOR A ; clear the accumulator. LD (DE),A ; place zero in high byte of length. DEC DE ; address low byte of length. LD (DE),A ; place zero there - now the null string. POP DE ; restore pointer - new STKEND. RET ; return. ; --------------------------- ; THE 'COMPARISON' OPERATIONS ; --------------------------- ; (offset: 00Ah 'no-gr-eql') ; (offset: 00Bh 'nos-neql') ; (offset: 00Ch 'no-grtr') ; (offset: 00Dh 'no-less') ; (offset: 00Eh 'nos-eql') ; (offset: 011h 'str-l-eql') ; (offset: 012h 'str-gr-eql') ; (offset: 013h 'strs-neql') ; (offset: 014h 'str-grtr') ; (offset: 015h 'str-less') ; (offset: 016h 'strs-eql') ; True binary operations. ; A single entry point is used to evaluate six numeric and six string ; comparisons. On entry, the calculator literal is in the B register and ; the two numeric values, or the two string parameters, are on the ; calculator stack. ; The individual bits of the literal are manipulated to group similar ; operations although the SUB 8 instruction does nothing useful and merely ; alters the string test bit. ; Numbers are compared by subtracting one from the other, strings are ; compared by comparing every character until a mismatch, or the end of one ; or both, is reached. ; ; Numeric Comparisons. ; -------------------- ; The 'x>y' example is the easiest as it employs straight-thru logic. ; Number y is subtracted from x and the result tested for greater-0 yielding ; a final value 1 (true) or 0 (false). ; For 'x<y' the same logic is used but the two values are first swapped on the ; calculator stack. ; For 'x=y' NOT is applied to the subtraction result yielding true if the ; difference was zero and false with anything else. ; The first three numeric comparisons are just the opposite of the last three ; so the same processing steps are used and then a final NOT is applied. ; ; literal Test No sub 8 ExOrNot 1st RRCA exch sub ? End-Tests ; ========= ==== == ======== === ======== ======== ==== === = === === === ; no-l-eql x<=y 09 00000001 dec 00000000 00000000 ---- x-y ? --- >0? NOT ; no-gr-eql x>=y 0A 00000010 dec 00000001 10000000c swap y-x ? --- >0? NOT ; nos-neql x<>y 0B 00000011 dec 00000010 00000001 ---- x-y ? NOT --- NOT ; no-grtr x>y 0C 00000100 - 00000100 00000010 ---- x-y ? --- >0? --- ; no-less x<y 0D 00000101 - 00000101 10000010c swap y-x ? --- >0? --- ; nos-eql x=y 0E 00000110 - 00000110 00000011 ---- x-y ? NOT --- --- ; ; comp -> C/F ; ==== === ; str-l-eql x$<=y$ 11 00001001 dec 00001000 00000100 ---- x$y$ 0 !or >0? NOT ; str-gr-eql x$>=y$ 12 00001010 dec 00001001 10000100c swap y$x$ 0 !or >0? NOT ; strs-neql x$<>y$ 13 00001011 dec 00001010 00000101 ---- x$y$ 0 !or >0? NOT ; str-grtr x$>y$ 14 00001100 - 00001100 00000110 ---- x$y$ 0 !or >0? --- ; str-less x$<y$ 15 00001101 - 00001101 10000110c swap y$x$ 0 !or >0? --- ; strs-eql x$=y$ 16 00001110 - 00001110 00000111 ---- x$y$ 0 !or >0? --- ; ; String comparisons are a little different in that the eql/neql carry flag ; from the 2nd RRCA is, as before, fed into the first of the end tests but ; along the way it gets modified by the comparison process. The result on the ; stack always starts off as zero and the carry fed in determines if NOT is ; applied to it. So the only time the greater-0 test is applied is if the ; stack holds zero which is not very efficient as the test will always yield ; zero. The most likely explanation is that there were once separate end tests ; for numbers and strings. ;; no-l-eql,etc. L353B: LD A,B ; transfer literal to accumulator. SUB 008h ; subtract eight - which is not useful. BIT 2,A ; isolate '>', '<', '='. JR NZ,L3543 ; skip to EX-OR-NOT with these. DEC A ; else make 00h-002h, 008h-00Ah to match bits 0-2. ;; EX-OR-NOT L3543: RRCA ; the first RRCA sets carry for a swap. JR NC,L354E ; forward to NU-OR-STR with other 8 cases ; for the other 4 cases the two values on the calculator stack are exchanged. PUSH AF ; save A and carry. PUSH HL ; save HL - pointer to first operand. ; (DE points to second operand). CALL L343C ; routine exchange swaps the two values. ; (HL = second operand, DE = STKEND) POP DE ; DE = first operand EX DE,HL ; as we were. POP AF ; restore A and carry. ; Note. it would be better if the 2nd RRCA preceded the string test. ; It would save two duplicate bytes and if we also got rid of that sub 8 ; at the beginning we wouldn't have to alter which bit we test. ;; NU-OR-STR L354E: BIT 2,A ; test if a string comparison. JR NZ,L3559 ; forward to STRINGS if so. ; continue with numeric comparisons. RRCA ; 2nd RRCA causes eql/neql to set carry. PUSH AF ; save A and carry CALL L300F ; routine subtract leaves result on stack. JR L358C ; forward to END-TESTS ; --- ;; STRINGS L3559: RRCA ; 2nd RRCA causes eql/neql to set carry. PUSH AF ; save A and carry. CALL L2BF1 ; routine STK-FETCH gets 2nd string params PUSH DE ; save start2 *. PUSH BC ; and the length. CALL L2BF1 ; routine STK-FETCH gets 1st string ; parameters - start in DE, length in BC. POP HL ; restore length of second to HL. ; A loop is now entered to compare, by subtraction, each corresponding character ; of the strings. For each successful match, the pointers are incremented and ; the lengths decreased and the branch taken back to here. If both string ; remainders become null at the same time, then an exact match exists. ;; BYTE-COMP L3564: LD A,H ; test if the second string OR L ; is the null string and hold flags. EX (SP),HL ; put length2 on stack, bring start2 to HL *. LD A,B ; hi byte of length1 to A JR NZ,L3575 ; forward to SEC-PLUS if second not null. OR C ; test length of first string. ;; SECND-LOW L356B: POP BC ; pop the second length off stack. JR Z,L3572 ; forward to BOTH-NULL if first string is also ; of zero length. ; the true condition - first is longer than second (SECND-LESS) POP AF ; restore carry (set if eql/neql) CCF ; complement carry flag. ; Note. equality becomes false. ; Inequality is true. By swapping or applying ; a terminal 'not', all comparisons have been ; manipulated so that this is success path. JR L3588 ; forward to leave via STR-TEST ; --- ; the branch was here with a match ;; BOTH-NULL L3572: POP AF ; restore carry - set for eql/neql JR L3588 ; forward to STR-TEST ; --- ; the branch was here when 2nd string not null and low byte of first is yet ; to be tested. ;; SEC-PLUS L3575: OR C ; test the length of first string. JR Z,L3585 ; forward to FRST-LESS if length is zero. ; both strings have at least one character left. LD A,(DE) ; fetch character of first string. SUB (HL) ; subtract with that of 2nd string. JR C,L3585 ; forward to FRST-LESS if carry set JR NZ,L356B ; back to SECND-LOW and then STR-TEST ; if not exact match. DEC BC ; decrease length of 1st string. INC DE ; increment 1st string pointer. INC HL ; increment 2nd string pointer. EX (SP),HL ; swap with length on stack DEC HL ; decrement 2nd string length JR L3564 ; back to BYTE-COMP ; --- ; the false condition. ;; FRST-LESS L3585: POP BC ; discard length POP AF ; pop A AND A ; clear the carry for false result. ; --- ; exact match and x$>y$ rejoin here ;; STR-TEST L3588: PUSH AF ; save A and carry RST 28H ;; FP-CALC .DEFB 0A0h ;;stk-zero an initial false value. .DEFB 038h ;;end-calc ; both numeric and string paths converge here. ;; END-TESTS L358C: POP AF ; pop carry - will be set if eql/neql PUSH AF ; save it again. CALL C,L3501 ; routine NOT sets true(1) if equal(0) ; or, for strings, applies true result. POP AF ; pop carry and PUSH AF ; save A CALL NC,L34F9 ; routine GREATER-0 tests numeric subtraction ; result but also needlessly tests the string ; value for zero - it must be. POP AF ; pop A RRCA ; the third RRCA - test for '<=', '>=' or '<>'. CALL NC,L3501 ; apply a terminal NOT if so. RET ; return. ; ------------------------------------ ; THE 'STRING CONCATENATION' OPERATION ; ------------------------------------ ; (offset: 017h 'strs-add') ; This literal combines two strings into one e.g. LET a$ = b$ + c$ ; The two parameters of the two strings to be combined are on the stack. ;; strs-add L359C: CALL L2BF1 ; routine STK-FETCH fetches string parameters ; and deletes calculator stack entry. PUSH DE ; save start address. PUSH BC ; and length. CALL L2BF1 ; routine STK-FETCH for first string POP HL ; re-fetch first length PUSH HL ; and save again PUSH DE ; save start of second string PUSH BC ; and its length. ADD HL,BC ; add the two lengths. LD B,H ; transfer to BC LD C,L ; and create RST 30H ; BC-SPACES in workspace. ; DE points to start of space. CALL L2AB2 ; routine STK-STO-$ stores parameters ; of new string updating STKEND. POP BC ; length of first POP HL ; address of start LD A,B ; test for OR C ; zero length. JR Z,L35B7 ; to OTHER-STR if null string LDIR ; copy string to workspace. ;; OTHER-STR L35B7: POP BC ; now second length POP HL ; and start of string LD A,B ; test this one OR C ; for zero length JR Z,L35BF ; skip forward to STK-PNTRS if so as complete. LDIR ; else copy the bytes. ; and continue into next routine which ; sets the calculator stack pointers. ; ----------------------------------- ; THE 'SET STACK POINTERS' SUBROUTINE ; ----------------------------------- ; Register DE is set to STKEND and HL, the result pointer, is set to five ; locations below this. ; This routine is used when it is inconvenient to save these values at the ; time the calculator stack is manipulated due to other activity on the ; machine stack. ; This routine is also used to terminate the VAL and READ-IN routines for ; the same reason and to initialize the calculator stack at the start of ; the CALCULATE routine. ;; STK-PNTRS L35BF: LD HL,(05C65h) ; fetch STKEND value from system variable. LD DE,0FFFBh ; the value -5 PUSH HL ; push STKEND value. ADD HL,DE ; subtract 5 from HL. POP DE ; pop STKEND to DE. RET ; return. ; ------------------- ; THE 'CHR$' FUNCTION ; ------------------- ; (offset: $2f 'chr$') ; This function returns a single character string that is a result of ; converting a number in the range 0-255 to a string e.g. CHR$ 65 = "A". ;; chrs L35C9: CALL L2DD5 ; routine FP-TO-A puts the number in A. JR C,L35DC ; forward to REPORT-Bd if overflow JR NZ,L35DC ; forward to REPORT-Bd if negative PUSH AF ; save the argument. LD BC,001h ; one space required. RST 30H ; BC-SPACES makes DE point to start POP AF ; restore the number. LD (DE),A ; and store in workspace CALL L2AB2 ; routine STK-STO-$ stacks descriptor. EX DE,HL ; make HL point to result and DE to STKEND. RET ; return. ; --- ;; REPORT-Bd L35DC: RST 08H ; ERROR-1 .DEFB 00Ah ; Error Report: Integer out of range ; ---------------------------- ; THE 'VAL and VAL$' FUNCTIONS ; ---------------------------- ; (offset: $1d 'val') ; (offset: 018h 'val$') ; VAL treats the characters in a string as a numeric expression. ; e.g. VAL "2.3" = 2.3, VAL "2+4" = 6, VAL ("2" + "4") = 24. ; VAL$ treats the characters in a string as a string expression. ; e.g. VAL$ (z$+"(2)") = a$(2) if z$ happens to be "a$". ;; val ;; val$ L35DE: LD HL,(05C5Dh) ; fetch value of system variable CH_ADD PUSH HL ; and save on the machine stack. LD A,B ; fetch the literal (either 01Dh or 018h). ADD A,0E3h ; add 0E3h to form 00h (setting carry) or 0FBh. SBC A,A ; now form 0FFh bit 6 = numeric result ; or 00h bit 6 = string result. PUSH AF ; save this mask on the stack CALL L2BF1 ; routine STK-FETCH fetches the string operand ; from calculator stack. PUSH DE ; save the address of the start of the string. INC BC ; increment the length for a carriage return. RST 30H ; BC-SPACES creates the space in workspace. POP HL ; restore start of string to HL. LD (05C5Dh),DE ; load CH_ADD with start DE in workspace. PUSH DE ; save the start in workspace LDIR ; copy string from program or variables or ; workspace to the workspace area. EX DE,HL ; end of string + 1 to HL DEC HL ; decrement HL to point to end of new area. LD (HL),00Dh ; insert a carriage return at end. RES 7,(IY+001h) ; update FLAGS - signal checking syntax. CALL L24FB ; routine SCANNING evaluates string ; expression and result. RST 18H ; GET-CHAR fetches next character. CP 00Dh ; is it the expected carriage return ? JR NZ,L360C ; forward to V-RPORT-C if not ; 'Nonsense in BASIC'. POP HL ; restore start of string in workspace. POP AF ; restore expected result flag (bit 6). XOR (IY+001h) ; xor with FLAGS now updated by SCANNING. AND 040h ; test bit 6 - should be zero if result types ; match. ;; V-RPORT-C L360C: JP NZ,L1C8A ; jump back to REPORT-C with a result mismatch. LD (05C5Dh),HL ; set CH_ADD to the start of the string again. SET 7,(IY+001h) ; update FLAGS - signal running program. CALL L24FB ; routine SCANNING evaluates the string ; in full leaving result on calculator stack. POP HL ; restore saved character address in program. LD (05C5Dh),HL ; and reset the system variable CH_ADD. JR L35BF ; back to exit via STK-PNTRS. ; resetting the calculator stack pointers ; HL and DE from STKEND as it wasn't possible ; to preserve them during this routine. ; ------------------- ; THE 'STR$' FUNCTION ; ------------------- ; (offset: $2e 'str$') ; This function produces a string comprising the characters that would appear ; if the numeric argument were printed. ; e.g. STR$ (1/10) produces "0.1". ;; str$ L361F: LD BC,001h ; create an initial byte in workspace RST 30H ; using BC-SPACES restart. LD (05C5Bh),HL ; set system variable K_CUR to new location. PUSH HL ; and save start on machine stack also. LD HL,(05C51h) ; fetch value of system variable CURCHL PUSH HL ; and save that too. LD A,0FFh ; select system channel 'R'. CALL L1601 ; routine CHAN-OPEN opens it. CALL L2DE3 ; routine PRINT-FP outputs the number to ; workspace updating K-CUR. POP HL ; restore current channel. CALL L1615 ; routine CHAN-FLAG resets flags. POP DE ; fetch saved start of string to DE. LD HL,(05C5Bh) ; load HL with end of string from K_CUR. AND A ; prepare for true subtraction. SBC HL,DE ; subtract start from end to give length. LD B,H ; transfer the length to LD C,L ; the BC register pair. CALL L2AB2 ; routine STK-STO-$ stores string parameters ; on the calculator stack. EX DE,HL ; HL = last value, DE = STKEND. RET ; return. ; ------------------------ ; THE 'READ-IN' SUBROUTINE ; ------------------------ ; (offset: $1a 'read-in') ; This is the calculator literal used by the INKEY$ function when a '#' ; is encountered after the keyword. ; INKEY$ # does not interact correctly with the keyboard, #0 or #1, and ; its uses are for other channels. ;; read-in L3645: CALL L1E94 ; routine FIND-INT1 fetches stream to A CP 010h ; compare with 16 decimal. JP NC,L1E9F ; JUMP to REPORT-Bb if not in range 0 - 15. ; 'Integer out of range' ; (REPORT-Bd is within range) LD HL,(05C51h) ; fetch current channel CURCHL PUSH HL ; save it CALL L1601 ; routine CHAN-OPEN opens channel CALL L15E6 ; routine INPUT-AD - the channel must have an ; input stream or else error here from stream ; stub. LD BC,000h ; initialize length of string to zero JR NC,L365F ; forward to R-I-STORE if no key detected. INC C ; increase length to one. RST 30H ; BC-SPACES creates space for one character ; in workspace. LD (DE),A ; the character is inserted. ;; R-I-STORE L365F: CALL L2AB2 ; routine STK-STO-$ stacks the string ; parameters. POP HL ; restore current channel address CALL L1615 ; routine CHAN-FLAG resets current channel ; system variable and flags. JP L35BF ; jump back to STK-PNTRS ; ------------------- ; THE 'CODE' FUNCTION ; ------------------- ; (offset: $1c 'code') ; Returns the ASCII code of a character or first character of a string ; e.g. CODE "Aardvark" = 65, CODE "" = 0. ;; code L3669: CALL L2BF1 ; routine STK-FETCH to fetch and delete the ; string parameters. ; DE points to the start, BC holds the length. LD A,B ; test length OR C ; of the string. JR Z,L3671 ; skip to STK-CODE with zero if the null string. LD A,(DE) ; else fetch the first character. ;; STK-CODE L3671: JP L2D28 ; jump back to STACK-A (with memory check) ; ------------------ ; THE 'LEN' FUNCTION ; ------------------ ; (offset: $1e 'len') ; Returns the length of a string. ; In Sinclair BASIC strings can be more than twenty thousand characters long ; so a sixteen-bit register is required to store the length ;; len L3674: CALL L2BF1 ; Routine STK-FETCH to fetch and delete the ; string parameters from the calculator stack. ; Register BC now holds the length of string. JP L2D2B ; Jump back to STACK-BC to save result on the ; calculator stack (with memory check). ; ------------------------------------- ; THE 'DECREASE THE COUNTER' SUBROUTINE ; ------------------------------------- ; (offset: 035h 'dec-jr-nz') ; The calculator has an instruction that decrements a single-byte ; pseudo-register and makes consequential relative jumps just like ; the Z80's DJNZ instruction. ;; dec-jr-nz L367A: EXX ; switch in set that addresses code PUSH HL ; save pointer to offset byte LD HL,05C67h ; address BREG in system variables DEC (HL) ; decrement it POP HL ; restore pointer JR NZ,L3687 ; to JUMP-2 if not zero INC HL ; step past the jump length. EXX ; switch in the main set. RET ; return. ; Note. as a general rule the calculator avoids using the IY register ; otherwise the cumbersome 4 instructions in the middle could be replaced by ; dec (iy+$2d) - three bytes instead of six. ; --------------------- ; THE 'JUMP' SUBROUTINE ; --------------------- ; (offset: 033h 'jump') ; This enables the calculator to perform relative jumps just like the Z80 ; chip's JR instruction. ;; jump ;; JUMP L3686: EXX ; switch in pointer set ;; JUMP-2 L3687: LD E,(HL) ; the jump byte 0-127 forward, 128-255 back. LD A,E ; transfer to accumulator. RLA ; if backward jump, carry is set. SBC A,A ; will be 0FFh if backward or 00h if forward. LD D,A ; transfer to high byte. ADD HL,DE ; advance calculator pointer forward or back. EXX ; switch back. RET ; return. ; -------------------------- ; THE 'JUMP-TRUE' SUBROUTINE ; -------------------------- ; (offset: 00h 'jump-true') ; This enables the calculator to perform conditional relative jumps dependent ; on whether the last test gave a true result. ;; jump-true L368F: INC DE ; Collect the INC DE ; third byte LD A,(DE) ; of the test DEC DE ; result and DEC DE ; backtrack. AND A ; Is result 0 or 1 ? JR NZ,L3686 ; Back to JUMP if true (1). EXX ; Else switch in the pointer set. INC HL ; Step past the jump length. EXX ; Switch in the main set. RET ; Return. ; ------------------------- ; THE 'END-CALC' SUBROUTINE ; ------------------------- ; (offset: 038h 'end-calc') ; The end-calc literal terminates a mini-program written in the Spectrum's ; internal language. ;; end-calc L369B: POP AF ; Drop the calculator return address RE-ENTRY EXX ; Switch to the other set. EX (SP),HL ; Transfer H'L' to machine stack for the ; return address. ; When exiting recursion, then the previous ; pointer is transferred to H'L'. EXX ; Switch back to main set. RET ; Return. ; ------------------------ ; THE 'MODULUS' SUBROUTINE ; ------------------------ ; (offset: 032h 'n-mod-m') ; (n1,n2 -- r,q) ; Similar to FORTH's 'divide mod' /MOD ; On the Spectrum, this is only used internally by the RND function and could ; have been implemented inline. On the ZX81, this calculator routine was also ; used by PRINT-FP. ;; n-mod-m L36A0: RST 28H ;; FP-CALC 17, 3. .DEFB 0C0h ;;st-mem-0 17, 3. .DEFB 002h ;;delete 17. .DEFB 031h ;;duplicate 17, 17. .DEFB 0E0h ;;get-mem-0 17, 17, 3. .DEFB 005h ;;division 17, 17/3. .DEFB 027h ;;int 17, 5. .DEFB 0E0h ;;get-mem-0 17, 5, 3. .DEFB 001h ;;exchange 17, 3, 5. .DEFB 0C0h ;;st-mem-0 17, 3, 5. .DEFB 004h ;;multiply 17, 15. .DEFB 003h ;;subtract 2. .DEFB 0E0h ;;get-mem-0 2, 5. .DEFB 038h ;;end-calc 2, 5. RET ; return. ; ------------------ ; THE 'INT' FUNCTION ; ------------------ ; (offset 027h: 'int' ) ; This function returns the integer of x, which is just the same as truncate ; for positive numbers. The truncate literal truncates negative numbers ; upwards so that -3.4 gives -3 whereas the BASIC INT function has to ; truncate negative numbers down so that INT -3.4 is -4. ; It is best to work through using, say, +-3.4 as examples. ;; int L36AF: RST 28H ;; FP-CALC x. (= 3.4 or -3.4). .DEFB 031h ;;duplicate x, x. .DEFB 036h ;;less-0 x, (1/0) .DEFB 00h ;;jump-true x, (1/0) .DEFB 004h ;;to L36B7, X-NEG .DEFB 03Ah ;;truncate trunc 3.4 = 3. .DEFB 038h ;;end-calc 3. RET ; return with + int x on stack. ; --- ;; X-NEG L36B7: .DEFB 031h ;;duplicate -3.4, -3.4. .DEFB 03Ah ;;truncate -3.4, -3. .DEFB 0C0h ;;st-mem-0 -3.4, -3. .DEFB 003h ;;subtract -.4 .DEFB 0E0h ;;get-mem-0 -.4, -3. .DEFB 001h ;;exchange -3, -.4. .DEFB 030h ;;not -3, (0). .DEFB 00h ;;jump-true -3. .DEFB 003h ;;to L36C2, EXIT -3. .DEFB 0A1h ;;stk-one -3, 1. .DEFB 003h ;;subtract -4. ;; EXIT L36C2: .DEFB 038h ;;end-calc -4. RET ; return. ; ------------------ ; THE 'EXP' FUNCTION ; ------------------ ; (offset 026h: 'exp') ; The exponential function EXP x is equal to e^x, where e is the mathematical ; name for a number approximated to 2.718281828. ; ERROR 6 if argument is more than about 88. ;; EXP ;; exp L36C4: RST 28H ;; FP-CALC .DEFB 03Dh ;;re-stack (not required - mult will do) .DEFB 034h ;;stk-data .DEFB 0F1h ;;Exponent: 081h, Bytes: 4 .DEFB 038h,0AAh,03Bh,029h ;; .DEFB 004h ;;multiply .DEFB 031h ;;duplicate .DEFB 027h ;;int .DEFB 0C3h ;;st-mem-3 .DEFB 003h ;;subtract .DEFB 031h ;;duplicate .DEFB 00Fh ;;addition .DEFB 0A1h ;;stk-one .DEFB 003h ;;subtract .DEFB 088h ;;series-08 .DEFB 013h ;;Exponent: 063h, Bytes: 1 .DEFB 036h ;;(+00,+00,+00) .DEFB 058h ;;Exponent: 068h, Bytes: 2 .DEFB 065h,066h ;;(+00,+00) .DEFB 09Dh ;;Exponent: 06Dh, Bytes: 3 .DEFB 078h,065h,040h ;;(+00) .DEFB 0A2h ;;Exponent: 072h, Bytes: 3 .DEFB 060h,032h,0C9h ;;(+00) .DEFB 0E7h ;;Exponent: 077h, Bytes: 4 .DEFB 021h,0F7h,0AFh,024h ;; .DEFB 0EBh ;;Exponent: 07Bh, Bytes: 4 .DEFB 02Fh,0B0h,0B0h,014h ;; .DEFB 0EEh ;;Exponent: 07Eh, Bytes: 4 .DEFB 07Eh,0BBh,094h,058h ;; .DEFB 0F1h ;;Exponent: 081h, Bytes: 4 .DEFB 03Ah,07Eh,0F8h,0CFh ;; .DEFB 0E3h ;;get-mem-3 .DEFB 038h ;;end-calc CALL L2DD5 ; routine FP-TO-A JR NZ,L3705 ; to N-NEGTV JR C,L3703 ; to REPORT-6b ; 'Number too big' ADD A,(HL) ; JR NC,L370C ; to RESULT-OK ;; REPORT-6b L3703: RST 08H ; ERROR-1 .DEFB 005h ; Error Report: Number too big ; --- ;; N-NEGTV L3705: JR C,L370E ; to RSLT-ZERO SUB (HL) ; JR NC,L370E ; to RSLT-ZERO NEG ; Negate ;; RESULT-OK L370C: LD (HL),A ; RET ; return. ; --- ;; RSLT-ZERO L370E: RST 28H ;; FP-CALC .DEFB 002h ;;delete .DEFB 0A0h ;;stk-zero .DEFB 038h ;;end-calc RET ; return. ; -------------------------------- ; THE 'NATURAL LOGARITHM' FUNCTION ; -------------------------------- ; (offset 025h: 'ln') ; Function to calculate the natural logarithm (to the base e ). ; Natural logarithms were devised in 1614 by well-traveled Scotsman John ; Napier who noted ; "Nothing doth more molest and hinder calculators than the multiplications, ; divisions, square and cubical extractions of great numbers". ; ; Napier's logarithms enabled the above operations to be accomplished by ; simple addition and subtraction simplifying the navigational and ; astronomical calculations which beset his age. ; Napier's logarithms were quickly overtaken by logarithms to the base 10 ; devised, in conjunction with Napier, by Henry Briggs a Cambridge-educated ; professor of Geometry at Oxford University. These simplified the layout ; of the tables enabling humans to easily scale calculations. ; ; It is only recently with the introduction of pocket calculators and machines ; like the ZX Spectrum that natural logarithms are once more at the fore, ; although some computers retain logarithms to the base ten. ; ; 'Natural' logarithms are powers to the base 'e', which like 'pi' is a ; naturally occurring number in branches of mathematics. ; Like 'pi' also, 'e' is an irrational number and starts 2.718281828... ; ; The tabular use of logarithms was that to multiply two numbers one looked ; up their two logarithms in the tables, added them together and then looked ; for the result in a table of antilogarithms to give the desired product. ; ; The EXP function is the BASIC equivalent of a calculator's 'antiln' function ; and by picking any two numbers, 1.72 and 6.89 say, ; 10 PRINT EXP ( LN 1.72 + LN 6.89 ) ; will give just the same result as ; 20 PRINT 1.72 * 6.89. ; Division is accomplished by subtracting the two logs. ; ; Napier also mentioned "square and cubicle extractions". ; To raise a number to the power 3, find its 'ln', multiply by 3 and find the ; 'antiln'. e.g. PRINT EXP( LN 4 * 3 ) gives 64. ; Similarly to find the n'th root divide the logarithm by 'n'. ; The ZX81 ROM used PRINT EXP ( LN 9 / 2 ) to find the square root of the ; number 9. The Napieran square root function is just a special case of ; the 'to_power' function. A cube root or indeed any root/power would be just ; as simple. ; First test that the argument to LN is a positive, non-zero number. ; Error A if the argument is 0 or negative. ;; ln L3713: RST 28H ;; FP-CALC .DEFB 03Dh ;;re-stack .DEFB 031h ;;duplicate .DEFB 037h ;;greater-0 .DEFB 00h ;;jump-true .DEFB 004h ;;to L371C, VALID .DEFB 038h ;;end-calc ;; REPORT-Ab L371A: RST 08H ; ERROR-1 .DEFB 009h ; Error Report: Invalid argument ;; VALID L371C: .DEFB 0A0h ;;stk-zero Note. not .DEFB 002h ;;delete necessary. .DEFB 038h ;;end-calc LD A,(HL) ; LD (HL),080h ; CALL L2D28 ; routine STACK-A RST 28H ;; FP-CALC .DEFB 034h ;;stk-data .DEFB 038h ;;Exponent: 088h, Bytes: 1 .DEFB 00h ;;(+00,+00,+00) .DEFB 003h ;;subtract .DEFB 001h ;;exchange .DEFB 031h ;;duplicate .DEFB 034h ;;stk-data .DEFB 0F0h ;;Exponent: 080h, Bytes: 4 .DEFB 04Ch,0CCh,0CCh,0CDh ;; .DEFB 003h ;;subtract .DEFB 037h ;;greater-0 .DEFB 00h ;;jump-true .DEFB 008h ;;to L373D, GRE.8 .DEFB 001h ;;exchange .DEFB 0A1h ;;stk-one .DEFB 003h ;;subtract .DEFB 001h ;;exchange .DEFB 038h ;;end-calc INC (HL) ; RST 28H ;; FP-CALC ;; GRE.8 L373D: .DEFB 001h ;;exchange .DEFB 034h ;;stk-data .DEFB 0F0h ;;Exponent: 080h, Bytes: 4 .DEFB 031h,072h,017h,0F8h ;; .DEFB 004h ;;multiply .DEFB 001h ;;exchange .DEFB 0A2h ;;stk-half .DEFB 003h ;;subtract .DEFB 0A2h ;;stk-half .DEFB 003h ;;subtract .DEFB 031h ;;duplicate .DEFB 034h ;;stk-data .DEFB 032h ;;Exponent: 082h, Bytes: 1 .DEFB 020h ;;(+00,+00,+00) .DEFB 004h ;;multiply .DEFB 0A2h ;;stk-half .DEFB 003h ;;subtract .DEFB 08Ch ;;series-0C .DEFB 011h ;;Exponent: 061h, Bytes: 1 .DEFB 0ACh ;;(+00,+00,+00) .DEFB 014h ;;Exponent: 064h, Bytes: 1 .DEFB 009h ;;(+00,+00,+00) .DEFB 056h ;;Exponent: 066h, Bytes: 2 .DEFB 0DAh,0A5h ;;(+00,+00) .DEFB 059h ;;Exponent: 069h, Bytes: 2 .DEFB 030h,0C5h ;;(+00,+00) .DEFB 05Ch ;;Exponent: 06Ch, Bytes: 2 .DEFB 090h,0AAh ;;(+00,+00) .DEFB 09Eh ;;Exponent: 06Eh, Bytes: 3 .DEFB 070h,06Fh,061h ;;(+00) .DEFB 0A1h ;;Exponent: 071h, Bytes: 3 .DEFB 0CBh,0DAh,096h ;;(+00) .DEFB 0A4h ;;Exponent: 074h, Bytes: 3 .DEFB 031h,09Fh,0B4h ;;(+00) .DEFB 0E7h ;;Exponent: 077h, Bytes: 4 .DEFB 0A0h,0FEh,05Ch,0FCh ;; .DEFB 0EAh ;;Exponent: 07Ah, Bytes: 4 .DEFB 01Bh,043h,0CAh,036h ;; .DEFB 0EDh ;;Exponent: 07Dh, Bytes: 4 .DEFB 0A7h,09Ch,07Eh,05Eh ;; .DEFB 0F0h ;;Exponent: 080h, Bytes: 4 .DEFB 06Eh,023h,080h,093h ;; .DEFB 004h ;;multiply .DEFB 00Fh ;;addition .DEFB 038h ;;end-calc RET ; return. ; ----------------------------- ; THE 'TRIGONOMETRIC' FUNCTIONS ; ----------------------------- ; Trigonometry is rocket science. It is also used by carpenters and pyramid ; builders. ; Some uses can be quite abstract but the principles can be seen in simple ; right-angled triangles. Triangles have some special properties - ; ; 1) The sum of the three angles is always PI radians (180 degrees). ; Very helpful if you know two angles and wish to find the third. ; 2) In any right-angled triangle the sum of the squares of the two shorter ; sides is equal to the square of the longest side opposite the right-angle. ; Very useful if you know the length of two sides and wish to know the ; length of the third side. ; 3) Functions sine, cosine and tangent enable one to calculate the length ; of an unknown side when the length of one other side and an angle is ; known. ; 4) Functions arcsin, arccosine and arctan enable one to calculate an unknown ; angle when the length of two of the sides is known. ; -------------------------------- ; THE 'REDUCE ARGUMENT' SUBROUTINE ; -------------------------------- ; (offset 039h: 'get-argt') ; ; This routine performs two functions on the angle, in radians, that forms ; the argument to the sine and cosine functions. ; First it ensures that the angle 'wraps round'. That if a ship turns through ; an angle of, say, 3*PI radians (540 degrees) then the net effect is to turn ; through an angle of PI radians (180 degrees). ; Secondly it converts the angle in radians to a fraction of a right angle, ; depending within which quadrant the angle lies, with the periodicity ; resembling that of the desired sine value. ; The result lies in the range -1 to +1. ; ; 90 deg. ; ; (pi/2) ; II +1 I ; | ; sin+ |\ | /| sin+ ; cos- | \ | / | cos+ ; tan- | \ | / | tan+ ; | \|/) | ; 180 deg. (pi) 0 -|----+----|-- 0 (0) 0 degrees ; | /|\ | ; sin- | / | \ | sin- ; cos- | / | \ | cos+ ; tan+ |/ | \| tan- ; | ; III -1 IV ; (3pi/2) ; ; 270 deg. ; ;; get-argt L3783: RST 28H ;; FP-CALC X. .DEFB 03Dh ;;re-stack (not rquired done by mult) .DEFB 034h ;;stk-data .DEFB 0EEh ;;Exponent: 07Eh, ;;Bytes: 4 .DEFB 022h,0F9h,083h,06Eh ;; X, 1/(2*PI) .DEFB 004h ;;multiply X/(2*PI) = fraction .DEFB 031h ;;duplicate .DEFB 0A2h ;;stk-half .DEFB 00Fh ;;addition .DEFB 027h ;;int .DEFB 003h ;;subtract now range -.5 to .5 .DEFB 031h ;;duplicate .DEFB 00Fh ;;addition now range -1 to 1. .DEFB 031h ;;duplicate .DEFB 00Fh ;;addition now range -2 to +2. ; quadrant I (0 to +1) and quadrant IV (-1 to 0) are now correct. ; quadrant II ranges +1 to +2. ; quadrant III ranges -2 to -1. .DEFB 031h ;;duplicate Y, Y. .DEFB 02Ah ;;abs Y, abs(Y). range 1 to 2 .DEFB 0A1h ;;stk-one Y, abs(Y), 1. .DEFB 003h ;;subtract Y, abs(Y)-1. range 0 to 1 .DEFB 031h ;;duplicate Y, Z, Z. .DEFB 037h ;;greater-0 Y, Z, (1/0). .DEFB 0C0h ;;st-mem-0 store as possible sign ;; for cosine function. .DEFB 00h ;;jump-true .DEFB 004h ;;to L37A1, ZPLUS with quadrants II and III. ; else the angle lies in quadrant I or IV and value Y is already correct. .DEFB 002h ;;delete Y. delete the test value. .DEFB 038h ;;end-calc Y. RET ; return. with Q1 and Q4 >>> ; --- ; the branch was here with quadrants II (0 to 1) and III (1 to 0). ; Y will hold -2 to -1 if this is quadrant III. ;; ZPLUS L37A1: .DEFB 0A1h ;;stk-one Y, Z, 1. .DEFB 003h ;;subtract Y, Z-1. Q3 = 0 to -1 .DEFB 001h ;;exchange Z-1, Y. .DEFB 036h ;;less-0 Z-1, (1/0). .DEFB 00h ;;jump-true Z-1. .DEFB 002h ;;to L37A8, YNEG ;;if angle in quadrant III ; else angle is within quadrant II (-1 to 0) .DEFB 01Bh ;;negate range +1 to 0. ;; YNEG L37A8: .DEFB 038h ;;end-calc quadrants II and III correct. RET ; return. ; --------------------- ; THE 'COSINE' FUNCTION ; --------------------- ; (offset 020h: 'cos') ; Cosines are calculated as the sine of the opposite angle rectifying the ; sign depending on the quadrant rules. ; ; ; /| ; h /y| ; / |o ; /x | ; /----| ; a ; ; The cosine of angle x is the adjacent side (a) divided by the hypotenuse 1. ; However if we examine angle y then a/h is the sine of that angle. ; Since angle x plus angle y equals a right-angle, we can find angle y by ; subtracting angle x from pi/2. ; However it's just as easy to reduce the argument first and subtract the ; reduced argument from the value 1 (a reduced right-angle). ; It's even easier to subtract 1 from the angle and rectify the sign. ; In fact, after reducing the argument, the absolute value of the argument ; is used and rectified using the test result stored in mem-0 by 'get-argt' ; for that purpose. ; ;; cos L37AA: RST 28H ;; FP-CALC angle in radians. .DEFB 039h ;;get-argt X reduce -1 to +1 .DEFB 02Ah ;;abs ABS X. 0 to 1 .DEFB 0A1h ;;stk-one ABS X, 1. .DEFB 003h ;;subtract now opposite angle ;; although sign is -ve. .DEFB 0E0h ;;get-mem-0 fetch the sign indicator .DEFB 00h ;;jump-true .DEFB 006h ;;fwd to L37B7, C-ENT ;;forward to common code if in QII or QIII. .DEFB 01Bh ;;negate else make sign +ve. .DEFB 033h ;;jump .DEFB 003h ;;fwd to L37B7, C-ENT ;; with quadrants I and IV. ; ------------------- ; THE 'SINE' FUNCTION ; ------------------- ; (offset 01Fh: 'sin') ; This is a fundamental transcendental function from which others such as cos ; and tan are directly, or indirectly, derived. ; It uses the series generator to produce Chebyshev polynomials. ; ; ; /| ; 1 / | ; / |x ; /a | ; /----| ; y ; ; The 'get-argt' function is designed to modify the angle and its sign ; in line with the desired sine value and afterwards it can launch straight ; into common code. ;; sin L37B5: RST 28H ;; FP-CALC angle in radians .DEFB 039h ;;get-argt reduce - sign now correct. ;; C-ENT L37B7: .DEFB 031h ;;duplicate .DEFB 031h ;;duplicate .DEFB 004h ;;multiply .DEFB 031h ;;duplicate .DEFB 00Fh ;;addition .DEFB 0A1h ;;stk-one .DEFB 003h ;;subtract .DEFB 086h ;;series-06 .DEFB 014h ;;Exponent: 064h, Bytes: 1 .DEFB 0E6h ;;(+00,+00,+00) .DEFB 05Ch ;;Exponent: 06Ch, Bytes: 2 .DEFB 01Fh,00Bh ;;(+00,+00) .DEFB 0A3h ;;Exponent: 073h, Bytes: 3 .DEFB 08Fh,038h,0EEh ;;(+00) .DEFB 0E9h ;;Exponent: 079h, Bytes: 4 .DEFB 015h,063h,0BBh,023h ;; .DEFB 0EEh ;;Exponent: 07Eh, Bytes: 4 .DEFB 092h,00Dh,0CDh,0EDh ;; .DEFB 0F1h ;;Exponent: 081h, Bytes: 4 .DEFB 023h,05Dh,01Bh,0EAh ;; .DEFB 004h ;;multiply .DEFB 038h ;;end-calc RET ; return. ; ---------------------- ; THE 'TANGENT' FUNCTION ; ---------------------- ; (offset 021h: 'tan') ; ; Evaluates tangent x as sin(x) / cos(x). ; ; ; /| ; h / | ; / |o ; /x | ; /----| ; a ; ; the tangent of angle x is the ratio of the length of the opposite side ; divided by the length of the adjacent side. As the opposite length can ; be calculates using sin(x) and the adjacent length using cos(x) then ; the tangent can be defined in terms of the previous two functions. ; Error 6 if the argument, in radians, is too close to one like pi/2 ; which has an infinite tangent. e.g. PRINT TAN (PI/2) evaluates as 1/0. ; Similarly PRINT TAN (3*PI/2), TAN (5*PI/2) etc. ;; tan L37DA: RST 28H ;; FP-CALC x. .DEFB 031h ;;duplicate x, x. .DEFB 01Fh ;;sin x, sin x. .DEFB 001h ;;exchange sin x, x. .DEFB 020h ;;cos sin x, cos x. .DEFB 005h ;;division sin x/cos x (= tan x). .DEFB 038h ;;end-calc tan x. RET ; return. ; --------------------- ; THE 'ARCTAN' FUNCTION ; --------------------- ; (Offset 024h: 'atn') ; the inverse tangent function with the result in radians. ; This is a fundamental transcendental function from which others such as asn ; and acs are directly, or indirectly, derived. ; It uses the series generator to produce Chebyshev polynomials. ;; atn L37E2: CALL L3297 ; routine re-stack LD A,(HL) ; fetch exponent byte. CP 081h ; compare to that for 'one' JR C,L37F8 ; forward, if less, to SMALL RST 28H ;; FP-CALC .DEFB 0A1h ;;stk-one .DEFB 01Bh ;;negate .DEFB 001h ;;exchange .DEFB 005h ;;division .DEFB 031h ;;duplicate .DEFB 036h ;;less-0 .DEFB 0A3h ;;stk-pi/2 .DEFB 001h ;;exchange .DEFB 00h ;;jump-true .DEFB 006h ;;to L37FA, CASES .DEFB 01Bh ;;negate .DEFB 033h ;;jump .DEFB 003h ;;to L37FA, CASES ;; SMALL L37F8: RST 28H ;; FP-CALC .DEFB 0A0h ;;stk-zero ;; CASES L37FA: .DEFB 001h ;;exchange .DEFB 031h ;;duplicate .DEFB 031h ;;duplicate .DEFB 004h ;;multiply .DEFB 031h ;;duplicate .DEFB 00Fh ;;addition .DEFB 0A1h ;;stk-one .DEFB 003h ;;subtract .DEFB 08Ch ;;series-0C .DEFB 010h ;;Exponent: 060h, Bytes: 1 .DEFB 0B2h ;;(+00,+00,+00) .DEFB 013h ;;Exponent: 063h, Bytes: 1 .DEFB 00Eh ;;(+00,+00,+00) .DEFB 055h ;;Exponent: 065h, Bytes: 2 .DEFB 0E4h,08Dh ;;(+00,+00) .DEFB 058h ;;Exponent: 068h, Bytes: 2 .DEFB 039h,0BCh ;;(+00,+00) .DEFB 05Bh ;;Exponent: 06Bh, Bytes: 2 .DEFB 098h,0FDh ;;(+00,+00) .DEFB 09Eh ;;Exponent: 06Eh, Bytes: 3 .DEFB 00h,036h,075h ;;(+00) .DEFB 0A0h ;;Exponent: 070h, Bytes: 3 .DEFB 0DBh,0E8h,0B4h ;;(+00) .DEFB 063h ;;Exponent: 073h, Bytes: 2 .DEFB 042h,0C4h ;;(+00,+00) .DEFB 0E6h ;;Exponent: 076h, Bytes: 4 .DEFB 0B5h,009h,036h,0BEh ;; .DEFB 0E9h ;;Exponent: 079h, Bytes: 4 .DEFB 036h,073h,01Bh,05Dh ;; .DEFB 0ECh ;;Exponent: 07Ch, Bytes: 4 .DEFB 0D8h,0DEh,063h,0BEh ;; .DEFB 0F0h ;;Exponent: 080h, Bytes: 4 .DEFB 061h,0A1h,0B3h,00Ch ;; .DEFB 004h ;;multiply .DEFB 00Fh ;;addition .DEFB 038h ;;end-calc RET ; return. ; --------------------- ; THE 'ARCSIN' FUNCTION ; --------------------- ; (Offset 022h: 'asn') ; The inverse sine function with result in radians. ; Derived from arctan function above. ; Error A unless the argument is between -1 and +1 inclusive. ; Uses an adaptation of the formula asn(x) = atn(x/sqr(1-x*x)) ; ; ; /| ; / | ; 1/ |x ; /a | ; /----| ; y ; ; e.g. We know the opposite side (x) and hypotenuse (1) ; and we wish to find angle a in radians. ; We can derive length y by Pythagoras and then use ATN instead. ; Since y*y + x*x = 1*1 (Pythagoras Theorem) then ; y=sqr(1-x*x) - no need to multiply 1 by itself. ; So, asn(a) = atn(x/y) ; or more fully, ; asn(a) = atn(x/sqr(1-x*x)) ; Close but no cigar. ; While PRINT ATN (x/SQR (1-x*x)) gives the same results as PRINT ASN x, ; it leads to division by zero when x is 1 or -1. ; To overcome this, 1 is added to y giving half the required angle and the ; result is then doubled. ; That is, PRINT ATN (x/(SQR (1-x*x) +1)) *2 ; ; GEOMETRIC PROOF. ; ; ; . /| ; . c/ | ; . /1 |x ; . c b /a | ; ---------/----| ; 1 y ; ; By creating an isosceles triangle with two equal sides of 1, angles c and ; c are also equal. If b+c+c = 180 degrees and b+a = 180 degrees then c=a/2. ; ; A value higher than 1 gives the required error as attempting to find the ; square root of a negative number generates an error in Sinclair BASIC. ;; asn L3833: RST 28H ;; FP-CALC x. .DEFB 031h ;;duplicate x, x. .DEFB 031h ;;duplicate x, x, x. .DEFB 004h ;;multiply x, x*x. .DEFB 0A1h ;;stk-one x, x*x, 1. .DEFB 003h ;;subtract x, x*x-1. .DEFB 01Bh ;;negate x, 1-x*x. .DEFB 028h ;;sqr x, sqr(1-x*x) = y .DEFB 0A1h ;;stk-one x, y, 1. .DEFB 00Fh ;;addition x, y+1. .DEFB 005h ;;division x/y+1. .DEFB 024h ;;atn a/2 (half the angle) .DEFB 031h ;;duplicate a/2, a/2. .DEFB 00Fh ;;addition a. .DEFB 038h ;;end-calc a. RET ; return. ; --------------------- ; THE 'ARCCOS' FUNCTION ; --------------------- ; (Offset 023h: 'acs') ; the inverse cosine function with the result in radians. ; Error A unless the argument is between -1 and +1. ; Result in range 0 to pi. ; Derived from asn above which is in turn derived from the preceding atn. ; It could have been derived directly from atn using acs(x) = atn(sqr(1-x*x)/x). ; However, as sine and cosine are horizontal translations of each other, ; uses acs(x) = pi/2 - asn(x) ; e.g. the arccosine of a known x value will give the required angle b in ; radians. ; We know, from above, how to calculate the angle a using asn(x). ; Since the three angles of any triangle add up to 180 degrees, or pi radians, ; and the largest angle in this case is a right-angle (pi/2 radians), then ; we can calculate angle b as pi/2 (both angles) minus asn(x) (angle a). ; ; ; /| ; 1 /b| ; / |x ; /a | ; /----| ; y ; ;; acs L3843: RST 28H ;; FP-CALC x. .DEFB 022h ;;asn asn(x). .DEFB 0A3h ;;stk-pi/2 asn(x), pi/2. .DEFB 003h ;;subtract asn(x) - pi/2. .DEFB 01Bh ;;negate pi/2 -asn(x) = acs(x). .DEFB 038h ;;end-calc acs(x). RET ; return. ; -------------------------- ; THE 'SQUARE ROOT' FUNCTION ; -------------------------- ; (Offset 0280: h'sqr') ; This routine is remarkable for its brevity - 7 bytes. ; It wasn't written here but in the ZX81 where the programmers had to squeeze ; a bulky operating system into an 8K ROM. It simply calculates ; the square root by stacking the value .5 and continuing into the 'to-power' ; routine. With more space available the much faster Newton-Raphson method ; could have been used as on the Jupiter Ace. ;; sqr L384A: RST 28H ;; FP-CALC .DEFB 031h ;;duplicate .DEFB 030h ;;not .DEFB 00h ;;jump-true .DEFB 01Eh ;;to L386C, LAST .DEFB 0A2h ;;stk-half .DEFB 038h ;;end-calc ; ------------------------------ ; THE 'EXPONENTIATION' OPERATION ; ------------------------------ ; (Offset 006h: 'to-power') ; This raises the first number X to the power of the second number Y. ; As with the ZX80, ; 0 ^ 0 = 1. ; 0 ^ +n = 0. ; 0 ^ -n = arithmetic overflow. ; ;; to-power L3851: RST 28H ;; FP-CALC X, Y. .DEFB 001h ;;exchange Y, X. .DEFB 031h ;;duplicate Y, X, X. .DEFB 030h ;;not Y, X, (1/0). .DEFB 00h ;;jump-true .DEFB 007h ;;to L385D, XIS0 if X is zero. ; else X is non-zero. Function 'ln' will catch a negative value of X. .DEFB 025h ;;ln Y, LN X. .DEFB 004h ;;multiply Y * LN X. .DEFB 038h ;;end-calc JP L36C4 ; jump back to EXP routine -> ; --- ; these routines form the three simple results when the number is zero. ; begin by deleting the known zero to leave Y the power factor. ;; XIS0 L385D: .DEFB 002h ;;delete Y. .DEFB 031h ;;duplicate Y, Y. .DEFB 030h ;;not Y, (1/0). .DEFB 00h ;;jump-true .DEFB 009h ;;to L386A, ONE if Y is zero. .DEFB 0A0h ;;stk-zero Y, 0. .DEFB 001h ;;exchange 0, Y. .DEFB 037h ;;greater-0 0, (1/0). .DEFB 00h ;;jump-true 0. .DEFB 006h ;;to L386C, LAST if Y was any positive ;; number. ; else force division by zero thereby raising an Arithmetic overflow error. ; There are some one and two-byte alternatives but perhaps the most formal ; might have been to use end-calc; rst 08; defb 05. .DEFB 0A1h ;;stk-one 0, 1. .DEFB 001h ;;exchange 1, 0. .DEFB 005h ;;division 1/0 ouch! ; --- ;; ONE L386A: .DEFB 002h ;;delete . .DEFB 0A1h ;;stk-one 1. ;; LAST L386C: .DEFB 038h ;;end-calc last value is 1 or 0. RET ; return. ; "Everything should be made as simple as possible, but not simpler" ; - Albert Einstein, 1879-1955. ; --------------------- ; THE 'SPARE' LOCATIONS ; --------------------- .org 0386Eh ;; spare ;L386E: .DEFB 0FFh ; KR - Z80 SIO procedury ; czekaj aż znaki zostaną wysłane ;tx_emp: ld a,01h ; out (sio_ac),a ; ;;;;;;;;; ; in a,(sio_ac) ; ;ld a,1 ; tylko do symulacji ; ;;;;;;;;; ; bit 0,a ; bit 0 w RR1=1--> wszystkie znaki zostały wysłane ; jp z,tx_emp ; ret ; czekaj, na znak ;rx_av: ld a,00h ; out (sio_ac),a ; in a,(sio_ac) ; bit 0,a ; bit 0 w RR0=1-> jest znak do pobania ; jp z,rx_av ; ret ; odbierz znak get_char: ;push af ld a,00h out (sio_ac),a in a,(sio_ac) bit 0,a ; bit 0 w RR0=1-> jest znak do pobania jp z,no_char in a,(sio_ad) jr end_get_char no_char: xor a ; a=0 scf ; carry=1 - żaden klawisz nie został naciśnięty ret end_get_char: scf ; carry=1 ccf ; carry=0 - klawisz został naciśnięty ret print_key: push af ; trzeba przechować akumulator, żeby zwrócić wynik push hl ; przechowanie HL na wszelki wypadek call printB ld hl,key_txt call printtxt pop hl pop af ret ; SIO init sio_init: push af ld a,00h out (sio_ac),a ld a,00011000b ; channel reset out (sio_ac),a ld a,04h ; select WR4 out (sio_ac),a ld a,01000100b ; no parity, 1 stop bit, 16x clock out (sio_ac),a ld a,03h ;WR3 out (sio_ac),a ld a,11000001b ; 8 bits, no auto enable, Rx enable out (sio_ac),a ld a,05h ; select WR5 out (sio_ac),a ld a,11101000b ; enable DTR, enable transfer,8 bits out (sio_ac),a ld hl,startup_txt ; info o uruchomieniu call printtxt pop af ret printCharA: ; znak w A push af call tx_emp pop af OUT (sio_ad),A ret printCharL: ; znak w L push hl ld a,l ; przepisanie znaku do A, można teraz użyć standardowej procedury call printCharA ; standardowa procedura pop hl ret printB: ; bajt w A LD B,A call printH LD A,B call printL ret printH: ; bajt w A, maska 11110000 push af call tx_emp pop af AND 0F0h RRC A RRC A RRC A RRC A SUB 0Ah JR C,codeNH codeAH: ADD A,41h ; A-F JP outH codeNH: ADD A,0Ah ; 0-9 ADD A,30h outH: OUT (sio_ad),A ret printL: ; bajt w A, maska 00001111 push af call tx_emp pop af AND 0Fh SUB 0Ah JR C,codeNL codeAL: ADD A,41h JP outL codeNL: ADD A,0Ah ADD A,30h outL: OUT (sio_ad),A ret printCRLF: call tx_emp LD A,0Dh OUT (sio_ad),A call tx_emp LD A,0Ah OUT (sio_ad),A ret tx_emp: ld a,01h out (sio_ac),a ;;;;;;;;; in a,(sio_ac) ; rzeczywisty układ ;ld a,1 ; tylko do symulacji ;;;;;;;;; bit 0,a ; bit 0 w RR1=1--> wszystkie znaki zostały wysłane jp z,tx_emp ret printtxt: push af printtxtloop: call tx_emp ld a,(hl) cp 0h ; koniec tekstu jr z,printtxtend out (sio_ad),a inc hl jr printtxtloop printtxtend: pop af ret print_sa_ld_byte: ; znak w L push af ; trzeba przechować akumulator, żeby zwrócić wynik push hl ; przechowanie HL na wszelki wypadek ld a,l call printB ld hl,data_txt call printtxt pop hl pop af ret print_block_header: ; nagłówek bloku przy ładowaniu - długość push af push hl ld hl,block_txt call printtxt ld a,d call printB ld a,e call printB ld hl,length_txt call printtxt pop hl pop af ret ; obsługa drukarki przekierowanej do SIO printerOut: push af cp 0Dh ; sprawdzenie, czy koniec linii jr z,printerOutCRLF cp 0A5h ; pierwszy token RND (134) jr nc,printerOutToken call printCharA jr printerOutEND printerOutCRLF: call printCRLF jr printerOutEND printerOutToken: push hl push bc push de ld hl,L0095 ; tablica tokenów inc hl ; pierwzy token to "?" sub 0A5h ; A=0 dla pierwszego tokenu inc a ; A=1 dla pierwszego tokenu printerOutTokenSearchLoopStart: push hl pop de ; początek tekstu (hl będzie końcem tekstu) ld b,0 printerOutTokenSearchLoop: inc b ; zmienia flagi, dlatego musi być przed sprawdzeniem bitu bit 7,(hl) ; sprawdzenie, czy znak ma ustawiony bit 7 (+80h w tablicy) inc hl ; 16-bit inc nie zmienia flag, może być między bit a jr z jr z,printerOutTokenSearchLoop ; jeżeli nie, to powrót do pętli dec a jr z,printerOutTokenFound jr printerOutTokenSearchLoopStart printerOutTokenFound ; początek tokena w DE, koniec w HL-1, ale to nie ma znaczenia, liczba znaków w B call printSpace ; spacja przed tokenem (nie powinno być jej przez <> >= <= itd., ale to oznacza dodatkowe sprawdzenie) ld a,b cp 0 ; na wszelki wypadek sprawdenie, czy dugość nie jest zerowa jr z,printerOutTokenEND printerOutTokenCharLoop: ld a,(de) bit 7,a jr z,printerOutTokenChar sub 080h printerOutTokenChar: call printCharA inc de dec b jr nz,printerOutTokenCharLoop ; czy już wszystkie znaki call printSpace ; spacja za tokenem (nie powinno być jej przez <> >= <= itd., ale to oznacza dodatkowe sprawdzenie) printerOutTokenEND: pop de pop bc pop hl printerOutEND: pop af ret printSpace: ld a,020h call printCharA ret startup_txt: .defb "ZX2 Started" .defb 13 ; CRLF .defb 10 .defb 0 key_txt: .defb "(key)" .defb 13 ; CRLF .defb 10 .defb 0 data_txt: .defb "(data)" .defb 13 ; CRLF .defb 10 .defb 0 block_txt: .defb "BLOCK" .defb 13 ; CRLF .defb 10 .defb 0 length_txt: .defb "(length)" .defb 13 ; CRLF .defb 10 .defb 0 .ORG 03D00h ; ------------------------------- ; THE 'ZX SPECTRUM CHARACTER SET' ; ------------------------------- ;; char-set ; 020h - Character: ' ' CHR$(32) L3D00: .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b ; 021h - Character: '!' CHR$(33) .DEFB 00000000b .DEFB 00010000b .DEFB 00010000b .DEFB 00010000b .DEFB 00010000b .DEFB 00000000b .DEFB 00010000b .DEFB 00000000b ; 022h - Character: '"' CHR$(34) .DEFB 00000000b .DEFB 00100100b .DEFB 00100100b .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b ; 023h - Character: '#' CHR$(35) .DEFB 00000000b .DEFB 00100100b .DEFB 01111110b .DEFB 00100100b .DEFB 00100100b .DEFB 01111110b .DEFB 00100100b .DEFB 00000000b ; 024h - Character: '$' CHR$(36) .DEFB 00000000b .DEFB 00001000b .DEFB 00111110b .DEFB 00101000b .DEFB 00111110b .DEFB 00001010b .DEFB 00111110b .DEFB 00001000b ; 025h - Character: '%' CHR$(37) .DEFB 00000000b .DEFB 01100010b .DEFB 01100100b .DEFB 00001000b .DEFB 00010000b .DEFB 00100110b .DEFB 01000110b .DEFB 00000000b ; 026h - Character: '&' CHR$(38) .DEFB 00000000b .DEFB 00010000b .DEFB 00101000b .DEFB 00010000b .DEFB 00101010b .DEFB 01000100b .DEFB 00111010b .DEFB 00000000b ; 027h - Character: ''' CHR$(39) .DEFB 00000000b .DEFB 00001000b .DEFB 00010000b .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b ; 028h - Character: '(' CHR$(40) .DEFB 00000000b .DEFB 00000100b .DEFB 00001000b .DEFB 00001000b .DEFB 00001000b .DEFB 00001000b .DEFB 00000100b .DEFB 00000000b ; 029h - Character: ')' CHR$(41) .DEFB 00000000b .DEFB 00100000b .DEFB 00010000b .DEFB 00010000b .DEFB 00010000b .DEFB 00010000b .DEFB 00100000b .DEFB 00000000b ; 02Ah - Character: '*' CHR$(42) .DEFB 00000000b .DEFB 00000000b .DEFB 00010100b .DEFB 00001000b .DEFB 00111110b .DEFB 00001000b .DEFB 00010100b .DEFB 00000000b ; 02Bh - Character: '+' CHR$(43) .DEFB 00000000b .DEFB 00000000b .DEFB 00001000b .DEFB 00001000b .DEFB 00111110b .DEFB 00001000b .DEFB 00001000b .DEFB 00000000b ; 02Ch - Character: ',' CHR$(44) .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b .DEFB 00001000b .DEFB 00001000b .DEFB 00010000b ; 02Dh - Character: '-' CHR$(45) .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b .DEFB 00111110b .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b ; 02Eh - Character: '.' CHR$(46) .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b .DEFB 00011000b .DEFB 00011000b .DEFB 00000000b ; 02Fh - Character: '/' CHR$(47) .DEFB 00000000b .DEFB 00000000b .DEFB 00000010b .DEFB 00000100b .DEFB 00001000b .DEFB 00010000b .DEFB 00100000b .DEFB 00000000b ; 030h - Character: '0' CHR$(48) .DEFB 00000000b .DEFB 00111100b .DEFB 01000110b .DEFB 01001010b .DEFB 01010010b .DEFB 01100010b .DEFB 00111100b .DEFB 00000000b ; 031h - Character: '1' CHR$(49) .DEFB 00000000b .DEFB 00011000b .DEFB 00101000b .DEFB 00001000b .DEFB 00001000b .DEFB 00001000b .DEFB 00111110b .DEFB 00000000b ; 032h - Character: '2' CHR$(50) .DEFB 00000000b .DEFB 00111100b .DEFB 01000010b .DEFB 00000010b .DEFB 00111100b .DEFB 01000000b .DEFB 01111110b .DEFB 00000000b ; 033h - Character: '3' CHR$(51) .DEFB 00000000b .DEFB 00111100b .DEFB 01000010b .DEFB 00001100b .DEFB 00000010b .DEFB 01000010b .DEFB 00111100b .DEFB 00000000b ; 034h - Character: '4' CHR$(52) .DEFB 00000000b .DEFB 00001000b .DEFB 00011000b .DEFB 00101000b .DEFB 01001000b .DEFB 01111110b .DEFB 00001000b .DEFB 00000000b ; 035h - Character: '5' CHR$(53) .DEFB 00000000b .DEFB 01111110b .DEFB 01000000b .DEFB 01111100b .DEFB 00000010b .DEFB 01000010b .DEFB 00111100b .DEFB 00000000b ; 036h - Character: '6' CHR$(54) .DEFB 00000000b .DEFB 00111100b .DEFB 01000000b .DEFB 01111100b .DEFB 01000010b .DEFB 01000010b .DEFB 00111100b .DEFB 00000000b ; 037h - Character: '7' CHR$(55) .DEFB 00000000b .DEFB 01111110b .DEFB 00000010b .DEFB 00000100b .DEFB 00001000b .DEFB 00010000b .DEFB 00010000b .DEFB 00000000b ; 038h - Character: '8' CHR$(56) .DEFB 00000000b .DEFB 00111100b .DEFB 01000010b .DEFB 00111100b .DEFB 01000010b .DEFB 01000010b .DEFB 00111100b .DEFB 00000000b ; 039h - Character: '9' CHR$(57) .DEFB 00000000b .DEFB 00111100b .DEFB 01000010b .DEFB 01000010b .DEFB 00111110b .DEFB 00000010b .DEFB 00111100b .DEFB 00000000b ; 03Ah - Character: ':' CHR$(58) .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b .DEFB 00010000b .DEFB 00000000b .DEFB 00000000b .DEFB 00010000b .DEFB 00000000b ; 03Bh - Character: ';' CHR$(59) .DEFB 00000000b .DEFB 00000000b .DEFB 00010000b .DEFB 00000000b .DEFB 00000000b .DEFB 00010000b .DEFB 00010000b .DEFB 00100000b ; 03Ch - Character: '<' CHR$(60) .DEFB 00000000b .DEFB 00000000b .DEFB 00000100b .DEFB 00001000b .DEFB 00010000b .DEFB 00001000b .DEFB 00000100b .DEFB 00000000b ; 03Dh - Character: '=' CHR$(61) .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b .DEFB 00111110b .DEFB 00000000b .DEFB 00111110b .DEFB 00000000b .DEFB 00000000b ; 03Eh - Character: '>' CHR$(62) .DEFB 00000000b .DEFB 00000000b .DEFB 00010000b .DEFB 00001000b .DEFB 00000100b .DEFB 00001000b .DEFB 00010000b .DEFB 00000000b ; 03Fh - Character: '?' CHR$(63) .DEFB 00000000b .DEFB 00111100b .DEFB 01000010b .DEFB 00000100b .DEFB 00001000b .DEFB 00000000b .DEFB 00001000b .DEFB 00000000b ; 040h - Character: '@' CHR$(64) .DEFB 00000000b .DEFB 00111100b .DEFB 01001010b .DEFB 01010110b .DEFB 01011110b .DEFB 01000000b .DEFB 00111100b .DEFB 00000000b ; 041h - Character: 'A' CHR$(65) .DEFB 00000000b .DEFB 00111100b .DEFB 01000010b .DEFB 01000010b .DEFB 01111110b .DEFB 01000010b .DEFB 01000010b .DEFB 00000000b ; 042h - Character: 'B' CHR$(66) .DEFB 00000000b .DEFB 01111100b .DEFB 01000010b .DEFB 01111100b .DEFB 01000010b .DEFB 01000010b .DEFB 01111100b .DEFB 00000000b ; 043h - Character: 'C' CHR$(67) .DEFB 00000000b .DEFB 00111100b .DEFB 01000010b .DEFB 01000000b .DEFB 01000000b .DEFB 01000010b .DEFB 00111100b .DEFB 00000000b ; 044h - Character: 'D' CHR$(68) .DEFB 00000000b .DEFB 01111000b .DEFB 01000100b .DEFB 01000010b .DEFB 01000010b .DEFB 01000100b .DEFB 01111000b .DEFB 00000000b ; 045h - Character: 'E' CHR$(69) .DEFB 00000000b .DEFB 01111110b .DEFB 01000000b .DEFB 01111100b .DEFB 01000000b .DEFB 01000000b .DEFB 01111110b .DEFB 00000000b ; 046h - Character: 'F' CHR$(70) .DEFB 00000000b .DEFB 01111110b .DEFB 01000000b .DEFB 01111100b .DEFB 01000000b .DEFB 01000000b .DEFB 01000000b .DEFB 00000000b ; 047h - Character: 'G' CHR$(71) .DEFB 00000000b .DEFB 00111100b .DEFB 01000010b .DEFB 01000000b .DEFB 01001110b .DEFB 01000010b .DEFB 00111100b .DEFB 00000000b ; 048h - Character: 'H' CHR$(72) .DEFB 00000000b .DEFB 01000010b .DEFB 01000010b .DEFB 01111110b .DEFB 01000010b .DEFB 01000010b .DEFB 01000010b .DEFB 00000000b ; 049h - Character: 'I' CHR$(73) .DEFB 00000000b .DEFB 00111110b .DEFB 00001000b .DEFB 00001000b .DEFB 00001000b .DEFB 00001000b .DEFB 00111110b .DEFB 00000000b ; 04Ah - Character: 'J' CHR$(74) .DEFB 00000000b .DEFB 00000010b .DEFB 00000010b .DEFB 00000010b .DEFB 01000010b .DEFB 01000010b .DEFB 00111100b .DEFB 00000000b ; 04Bh - Character: 'K' CHR$(75) .DEFB 00000000b .DEFB 01000100b .DEFB 01001000b .DEFB 01110000b .DEFB 01001000b .DEFB 01000100b .DEFB 01000010b .DEFB 00000000b ; 04Ch - Character: 'L' CHR$(76) .DEFB 00000000b .DEFB 01000000b .DEFB 01000000b .DEFB 01000000b .DEFB 01000000b .DEFB 01000000b .DEFB 01111110b .DEFB 00000000b ; 04Dh - Character: 'M' CHR$(77) .DEFB 00000000b .DEFB 01000010b .DEFB 01100110b .DEFB 01011010b .DEFB 01000010b .DEFB 01000010b .DEFB 01000010b .DEFB 00000000b ; 04Eh - Character: 'N' CHR$(78) .DEFB 00000000b .DEFB 01000010b .DEFB 01100010b .DEFB 01010010b .DEFB 01001010b .DEFB 01000110b .DEFB 01000010b .DEFB 00000000b ; 04Fh - Character: 'O' CHR$(79) .DEFB 00000000b .DEFB 00111100b .DEFB 01000010b .DEFB 01000010b .DEFB 01000010b .DEFB 01000010b .DEFB 00111100b .DEFB 00000000b ; 050h - Character: 'P' CHR$(80) .DEFB 00000000b .DEFB 01111100b .DEFB 01000010b .DEFB 01000010b .DEFB 01111100b .DEFB 01000000b .DEFB 01000000b .DEFB 00000000b ; 051h - Character: 'Q' CHR$(81) .DEFB 00000000b .DEFB 00111100b .DEFB 01000010b .DEFB 01000010b .DEFB 01010010b .DEFB 01001010b .DEFB 00111100b .DEFB 00000000b ; 052h - Character: 'R' CHR$(82) .DEFB 00000000b .DEFB 01111100b .DEFB 01000010b .DEFB 01000010b .DEFB 01111100b .DEFB 01000100b .DEFB 01000010b .DEFB 00000000b ; 053h - Character: 'S' CHR$(83) .DEFB 00000000b .DEFB 00111100b .DEFB 01000000b .DEFB 00111100b .DEFB 00000010b .DEFB 01000010b .DEFB 00111100b .DEFB 00000000b ; 054h - Character: 'T' CHR$(84) .DEFB 00000000b .DEFB 11111110b .DEFB 00010000b .DEFB 00010000b .DEFB 00010000b .DEFB 00010000b .DEFB 00010000b .DEFB 00000000b ; 055h - Character: 'U' CHR$(85) .DEFB 00000000b .DEFB 01000010b .DEFB 01000010b .DEFB 01000010b .DEFB 01000010b .DEFB 01000010b .DEFB 00111100b .DEFB 00000000b ; 056h - Character: 'V' CHR$(86) .DEFB 00000000b .DEFB 01000010b .DEFB 01000010b .DEFB 01000010b .DEFB 01000010b .DEFB 00100100b .DEFB 00011000b .DEFB 00000000b ; 057h - Character: 'W' CHR$(87) .DEFB 00000000b .DEFB 01000010b .DEFB 01000010b .DEFB 01000010b .DEFB 01000010b .DEFB 01011010b .DEFB 00100100b .DEFB 00000000b ; 058h - Character: 'X' CHR$(88) .DEFB 00000000b .DEFB 01000010b .DEFB 00100100b .DEFB 00011000b .DEFB 00011000b .DEFB 00100100b .DEFB 01000010b .DEFB 00000000b ; 059h - Character: 'Y' CHR$(89) .DEFB 00000000b .DEFB 10000010b .DEFB 01000100b .DEFB 00101000b .DEFB 00010000b .DEFB 00010000b .DEFB 00010000b .DEFB 00000000b ; 05Ah - Character: 'Z' CHR$(90) .DEFB 00000000b .DEFB 01111110b .DEFB 00000100b .DEFB 00001000b .DEFB 00010000b .DEFB 00100000b .DEFB 01111110b .DEFB 00000000b ; 05Bh - Character: '[' CHR$(91) .DEFB 00000000b .DEFB 00001110b .DEFB 00001000b .DEFB 00001000b .DEFB 00001000b .DEFB 00001000b .DEFB 00001110b .DEFB 00000000b ; 05Ch - Character: '\' CHR$(92) .DEFB 00000000b .DEFB 00000000b .DEFB 01000000b .DEFB 00100000b .DEFB 00010000b .DEFB 00001000b .DEFB 00000100b .DEFB 00000000b ; 05Dh - Character: ']' CHR$(93) .DEFB 00000000b .DEFB 01110000b .DEFB 00010000b .DEFB 00010000b .DEFB 00010000b .DEFB 00010000b .DEFB 01110000b .DEFB 00000000b ; 05Eh - Character: '^' CHR$(94) .DEFB 00000000b .DEFB 00010000b .DEFB 00111000b .DEFB 01010100b .DEFB 00010000b .DEFB 00010000b .DEFB 00010000b .DEFB 00000000b ; 05Fh - Character: '_' CHR$(95) .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b .DEFB 11111111b ; 060h - Character: ' £ ' CHR$(96) .DEFB 00000000b .DEFB 00011100b .DEFB 00100010b .DEFB 01111000b .DEFB 00100000b .DEFB 00100000b .DEFB 01111110b .DEFB 00000000b ; 061h - Character: 'a' CHR$(97) .DEFB 00000000b .DEFB 00000000b .DEFB 00111000b .DEFB 00000100b .DEFB 00111100b .DEFB 01000100b .DEFB 00111100b .DEFB 00000000b ; 062h - Character: 'b' CHR$(98) .DEFB 00000000b .DEFB 00100000b .DEFB 00100000b .DEFB 00111100b .DEFB 00100010b .DEFB 00100010b .DEFB 00111100b .DEFB 00000000b ; 063h - Character: 'c' CHR$(99) .DEFB 00000000b .DEFB 00000000b .DEFB 00011100b .DEFB 00100000b .DEFB 00100000b .DEFB 00100000b .DEFB 00011100b .DEFB 00000000b ; 064h - Character: 'd' CHR$(100) .DEFB 00000000b .DEFB 00000100b .DEFB 00000100b .DEFB 00111100b .DEFB 01000100b .DEFB 01000100b .DEFB 00111100b .DEFB 00000000b ; 065h - Character: 'e' CHR$(101) .DEFB 00000000b .DEFB 00000000b .DEFB 00111000b .DEFB 01000100b .DEFB 01111000b .DEFB 01000000b .DEFB 00111100b .DEFB 00000000b ; 066h - Character: 'f' CHR$(102) .DEFB 00000000b .DEFB 00001100b .DEFB 00010000b .DEFB 00011000b .DEFB 00010000b .DEFB 00010000b .DEFB 00010000b .DEFB 00000000b ; 067h - Character: 'g' CHR$(103) .DEFB 00000000b .DEFB 00000000b .DEFB 00111100b .DEFB 01000100b .DEFB 01000100b .DEFB 00111100b .DEFB 00000100b .DEFB 00111000b ; 068h - Character: 'h' CHR$(104) .DEFB 00000000b .DEFB 01000000b .DEFB 01000000b .DEFB 01111000b .DEFB 01000100b .DEFB 01000100b .DEFB 01000100b .DEFB 00000000b ; 069h - Character: 'i' CHR$(105) .DEFB 00000000b .DEFB 00010000b .DEFB 00000000b .DEFB 00110000b .DEFB 00010000b .DEFB 00010000b .DEFB 00111000b .DEFB 00000000b ; 06Ah - Character: 'j' CHR$(106) .DEFB 00000000b .DEFB 00000100b .DEFB 00000000b .DEFB 00000100b .DEFB 00000100b .DEFB 00000100b .DEFB 00100100b .DEFB 00011000b ; 06Bh - Character: 'k' CHR$(107) .DEFB 00000000b .DEFB 00100000b .DEFB 00101000b .DEFB 00110000b .DEFB 00110000b .DEFB 00101000b .DEFB 00100100b .DEFB 00000000b ; 06Ch - Character: 'l' CHR$(108) .DEFB 00000000b .DEFB 00010000b .DEFB 00010000b .DEFB 00010000b .DEFB 00010000b .DEFB 00010000b .DEFB 00001100b .DEFB 00000000b ; 06Dh - Character: 'm' CHR$(109) .DEFB 00000000b .DEFB 00000000b .DEFB 01101000b .DEFB 01010100b .DEFB 01010100b .DEFB 01010100b .DEFB 01010100b .DEFB 00000000b ; 06Eh - Character: 'n' CHR$(110) .DEFB 00000000b .DEFB 00000000b .DEFB 01111000b .DEFB 01000100b .DEFB 01000100b .DEFB 01000100b .DEFB 01000100b .DEFB 00000000b ; 06Fh - Character: 'o' CHR$(111) .DEFB 00000000b .DEFB 00000000b .DEFB 00111000b .DEFB 01000100b .DEFB 01000100b .DEFB 01000100b .DEFB 00111000b .DEFB 00000000b ; 070h - Character: 'p' CHR$(112) .DEFB 00000000b .DEFB 00000000b .DEFB 01111000b .DEFB 01000100b .DEFB 01000100b .DEFB 01111000b .DEFB 01000000b .DEFB 01000000b ; 071h - Character: 'q' CHR$(113) .DEFB 00000000b .DEFB 00000000b .DEFB 00111100b .DEFB 01000100b .DEFB 01000100b .DEFB 00111100b .DEFB 00000100b .DEFB 00000110b ; 072h - Character: 'r' CHR$(114) .DEFB 00000000b .DEFB 00000000b .DEFB 00011100b .DEFB 00100000b .DEFB 00100000b .DEFB 00100000b .DEFB 00100000b .DEFB 00000000b ; 073h - Character: 's' CHR$(115) .DEFB 00000000b .DEFB 00000000b .DEFB 00111000b .DEFB 01000000b .DEFB 00111000b .DEFB 00000100b .DEFB 01111000b .DEFB 00000000b ; 074h - Character: 't' CHR$(116) .DEFB 00000000b .DEFB 00010000b .DEFB 00111000b .DEFB 00010000b .DEFB 00010000b .DEFB 00010000b .DEFB 00001100b .DEFB 00000000b ; 075h - Character: 'u' CHR$(117) .DEFB 00000000b .DEFB 00000000b .DEFB 01000100b .DEFB 01000100b .DEFB 01000100b .DEFB 01000100b .DEFB 00111000b .DEFB 00000000b ; 076h - Character: 'v' CHR$(118) .DEFB 00000000b .DEFB 00000000b .DEFB 01000100b .DEFB 01000100b .DEFB 00101000b .DEFB 00101000b .DEFB 00010000b .DEFB 00000000b ; 077h - Character: 'w' CHR$(119) .DEFB 00000000b .DEFB 00000000b .DEFB 01000100b .DEFB 01010100b .DEFB 01010100b .DEFB 01010100b .DEFB 00101000b .DEFB 00000000b ; 078h - Character: 'x' CHR$(120) .DEFB 00000000b .DEFB 00000000b .DEFB 01000100b .DEFB 00101000b .DEFB 00010000b .DEFB 00101000b .DEFB 01000100b .DEFB 00000000b ; 079h - Character: 'y' CHR$(121) .DEFB 00000000b .DEFB 00000000b .DEFB 01000100b .DEFB 01000100b .DEFB 01000100b .DEFB 00111100b .DEFB 00000100b .DEFB 00111000b ; 07Ah - Character: 'z' CHR$(122) .DEFB 00000000b .DEFB 00000000b .DEFB 01111100b .DEFB 00001000b .DEFB 00010000b .DEFB 00100000b .DEFB 01111100b .DEFB 00000000b ; 07Bh - Character: '{' CHR$(123) .DEFB 00000000b .DEFB 00001110b .DEFB 00001000b .DEFB 00110000b .DEFB 00001000b .DEFB 00001000b .DEFB 00001110b .DEFB 00000000b ; 07Ch - Character: '|' CHR$(124) .DEFB 00000000b .DEFB 00001000b .DEFB 00001000b .DEFB 00001000b .DEFB 00001000b .DEFB 00001000b .DEFB 00001000b .DEFB 00000000b ; 07Dh - Character: '}' CHR$(125) .DEFB 00000000b .DEFB 01110000b .DEFB 00010000b .DEFB 00001100b .DEFB 00010000b .DEFB 00010000b .DEFB 01110000b .DEFB 00000000b ; 07Eh - Character: '~' CHR$(126) .DEFB 00000000b .DEFB 00010100b .DEFB 00101000b .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b .DEFB 00000000b ; 07Fh - Character: ' © ' CHR$(127) .DEFB 00111100b .DEFB 01000010b .DEFB 10011001b .DEFB 10100001b .DEFB 10100001b .DEFB 10011001b .DEFB 01000010b .DEFB 00111100b ;#end ; generic cross-assembler directive ; Acknowledgements ; ----------------- ; Sean Irvine for default list of section headings ; Dr. Ian Logan for labels and functional disassembly. ; Dr. Frank O'Hara for labels and functional disassembly. ; ; Credits ; ------- ; Alex Pallero Gonzales for corrections. ; Mike Dailly for comments. ; Alvin Albrecht for comments. ; Andy Styles for full relocatability implementation and testing. testing. ; Andrew Owen for ZASM compatibility and format improvements. ; For other assemblers you may have to add directives like these near the ; beginning - see accompanying documentation. ; ZASM (MacOs) cross-assembler directives. (uncomment by removing ';' ) ; #target rom ; declare target file format as binary. ; #code 0,040000 h ; declare code segment. ; Also see notes at Address Labels 0609 and 1CA5 if your assembler has ; trouble with expressions. ; ; Note. The Sinclair Interface 1 ROM written by Dr. Ian Logan and Martin ; Brennan calls numerous routines in this ROM. ; Non-standard entry points have a label beginning with X.
; A343560: a(n) = (n-1)*(4*n+1). ; 0,9,26,51,84,125,174,231,296,369,450,539,636,741,854,975,1104,1241,1386,1539,1700,1869,2046,2231,2424,2625,2834,3051,3276,3509,3750,3999,4256,4521,4794,5075,5364,5661,5966,6279,6600,6929,7266,7611,7964,8325 sub $2,$0 mul $2,4 sub $2,2 bin $2,2 mov $0,$2 sub $0,3 div $0,2
/* file: split_layer_forward_fpt.cpp */ /******************************************************************************* * Copyright 2014-2017 Intel Corporation * * 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. *******************************************************************************/ /* //++ // Implementation of split calculation algorithm and types methods. //-- */ #include "split_layer_forward_types.h" #include "split_layer_types.h" #include "service_mkl_tensor.h" namespace daal { namespace algorithms { namespace neural_networks { namespace layers { namespace split { namespace forward { namespace interface1 { /** * Allocates memory to store the result of the forward split layer * \param[in] input Pointer to an object containing the input data * \param[in] parameter %Parameter of the algorithm * \param[in] method Computation method for the algorithm */ template <typename algorithmFPType> DAAL_EXPORT services::Status Result::allocate(const daal::algorithms::Input *input, const daal::algorithms::Parameter *parameter, const int method) { if (!get(layers::forward::resultForBackward)) { const layers::forward::Input *in = static_cast<const layers::forward::Input * >(input); const Parameter *par = static_cast<const Parameter *>(parameter); const size_t nOutputs = par->nOutputs; LayerDataPtr resultCollection = LayerDataPtr(new LayerData()); data_management::TensorPtr dataTensor = in->get(layers::forward::data); internal::MklTensor<algorithmFPType> *dataMkl = dynamic_cast<internal::MklTensor<algorithmFPType>*>( dataTensor.get() ); if (dataMkl != 0) { const services::Collection<size_t> &dataDims = dataTensor->getDimensions(); for(size_t i = 0; i < nOutputs; i++) { if (par->allowInplaceComputation) { (*resultCollection)[i] = dataTensor; } else { (*resultCollection)[i] = data_management::TensorPtr(new internal::MklTensor<algorithmFPType>( dataDims, data_management::Tensor::doAllocate)); } } } else { const services::Collection<size_t> &dataDims = dataTensor->getDimensions(); for(size_t i = 0; i < nOutputs; i++) { if (par->allowInplaceComputation) { (*resultCollection)[i] = dataTensor; } else { (*resultCollection)[i] = data_management::TensorPtr(new data_management::HomogenTensor<algorithmFPType>( dataDims, data_management::Tensor::doAllocate)); } } } set(layers::forward::resultForBackward, resultCollection); } return services::Status(); } template DAAL_EXPORT services::Status Result::allocate<DAAL_FPTYPE>(const daal::algorithms::Input *input, const daal::algorithms::Parameter *parameter, const int method); }// namespace interface1 }// namespace forward }// namespace split }// namespace layers }// namespace neural_networks }// namespace algorithms }// namespace daal
.filenamespace c64lib .label CHARSET_ADDR = $E000 .label SCREEN_ADDR = $C000 start: jsr configureC64 jsr unpackData jsr configureVic2 loop: jmp loop configureC64: { sei configureMemory(RAM_IO_RAM) disableNMI() disableCIAInterrupts() cli rts } unpackData: { // charset pushParamW(charset) pushParamW(CHARSET_ADDR) pushParamW(endCharset - charset) jsr copyLargeMemForward // color RAM pushParamW(charsetColours) pushParamW(COLOR_RAM) pushParamW(endCharsetColours - charsetColours) jsr copyLargeMemForward // screen colours pushParamW(charsetScreenColours) pushParamW(SCREEN_ADDR) pushParamW(endCharsetScreenColours - charsetScreenColours) jsr copyLargeMemForward rts } configureVic2: { lda #backgroundColour0 sta BORDER_COL sta BG_COL_0 setVideoMode(MULTICOLOR_BITMAP_MODE) setVICBank(0) configureBitmapMemory(0, 1) rts } #import "common/lib/sub/copy-large-mem-forward.asm"
UpdateSpriteFacingOffsetAndDelayMovement:: ld h, HIGH(wSpriteStateData2) ldh a, [hCurrentSpriteOffset] add $8 ld l, a ld a, $7f ; maximum movement delay ld [hl], a ; x#SPRITESTATEDATA2_MOVEMENTDELAY dec h ; HIGH(wSpriteStateData1) ldh a, [hCurrentSpriteOffset] add $9 ld l, a ld a, [hld] ; x#SPRITESTATEDATA1_FACINGDIRECTION ld b, a xor a ld [hld], a ld [hl], a ; x#SPRITESTATEDATA1_ANIMFRAMECOUNTER ldh a, [hCurrentSpriteOffset] add SPRITESTATEDATA1_IMAGEINDEX ld l, a ld a, [hl] ; x#SPRITESTATEDATA1_IMAGEINDEX or b ; or in the facing direction ld [hld], a ld a, $2 ; delayed movement status ld [hl], a ; x#SPRITESTATEDATA1_MOVEMENTSTATUS ret
use64 LoadGDT: lgdt [rdi] mov ax, 0x10 mov ds, ax mov es, ax mov fs, ax mov gs, ax mov ss, ax pop rdi mov rax, 0x08 push rax push rdi retfq
IslandMonsB4: db $0A IF DEF(_BLUE) db 31,KRABBY db 31,SHELLDER db 33,KRABBY db 33,JYNX db 29,SLOWPOKE db 31,SEEL db 31,SLOWPOKE db 29,SEEL db 39,SLOWBRO db 37,KINGLER ELSE db 31,KRABBY db 31,STARYU db 33,KRABBY db 33,STARYU db 29,PSYDUCK db 31,SEEL db 31,PSYDUCK db 29,SEEL db 39,GOLDUCK db 37,KINGLER ENDC db $05 db 15,TENTACOOL db 10,TENTACOOL db 15,TENTACOOL db 10,TENTACOOL db 15,TENTACOOL db 20,TENTACOOL db 25,TENTACOOL db 30,TENTACRUEL db 35,TENTACRUEL db 40,TENTACRUEL
; A188258: Positions of 0 in A188257; complement of A188259. ; 1,2,5,6,9,10,13,14,17,18,19,22,23,26,27,30,31,34,35,36,39,40,43,44,47,48,51,52,53,56,57,60,61,64,65,68,69,70,73,74,77,78,81,82,85,86,89,90,91,94,95,98,99,102,103,106,107,108,111,112,115,116,119,120,123,124,125,128,129,132,133,136,137,140,141,142,145,146,149,150,153 mov $2,$0 add $2,1 mov $3,$0 lpb $2 mov $0,$3 sub $2,1 sub $0,$2 mov $5,$0 mov $7,2 lpb $7 mov $0,$5 sub $7,1 add $0,$7 mul $0,25 add $0,1 div $0,56 mov $4,$0 mov $8,$7 lpb $8 mov $6,$4 sub $8,1 lpe lpe lpb $5 mov $5,0 sub $6,$4 lpe mov $4,$6 mul $4,2 add $4,1 add $1,$4 lpe
//+------------------------------------------------------------------------- // // Microsoft Windows // // Copyright (C) Microsoft Corporation, 2000 // // File: tasksymbol.cpp // // History: 17-Jan-2000 Vivekj added //-------------------------------------------------------------------------- #include "stdafx.h" #include "TaskSymbol.h" #include "tasks.h" //############################################################################ //############################################################################ // // Traces // //############################################################################ //############################################################################ #ifdef DBG CTraceTag tagTaskSymbol(TEXT("CTaskSymbol"), TEXT("CTaskSymbol")); #endif //DBG //############################################################################ //############################################################################ // // Implementation of class CTaskSymbol // //############################################################################ //############################################################################ extern CEOTSymbol s_rgEOTSymbol[]; CTaskSymbol::CTaskSymbol() : m_dwConsoleTaskID(0), m_bSmall(0) { } /*+-------------------------------------------------------------------------* * * CTaskSymbol::OnDraw * * PURPOSE: Draws out the symbol onto the DC specified in the ATL_DRAWINFO structure. * * PARAMETERS: * ATL_DRAWINFO& di : * * RETURNS: * HRESULT * *+-------------------------------------------------------------------------*/ HRESULT CTaskSymbol::OnDraw(ATL_DRAWINFO& di) { DECLARE_SC(sc, TEXT("CTaskSymbol::OnDraw")); RECT * pRect = (RECT *)di.prcBounds; sc = ScCheckPointers(pRect); if(sc) return sc.ToHr(); CConsoleTask *pConsoleTask = CConsoleTask::GetConsoleTask(m_dwConsoleTaskID); // get the console task from the unique ID COLORREF colorOld = SetTextColor (di.hdcDraw, ::GetSysColor (COLOR_WINDOWTEXT)); if(pConsoleTask) pConsoleTask->Draw(di.hdcDraw, pRect, m_bSmall); SetTextColor(di.hdcDraw, colorOld); return sc.ToHr(); } LRESULT CTaskSymbol::OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { Fire_Click(); return 0; } // from winuser.h, for Windows 2000 and above only. #define IDC_HAND MAKEINTRESOURCE(32649) LRESULT CTaskSymbol::OnSetCursor(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { static HCURSOR s_hCursorHand = ::LoadCursor(NULL, IDC_HAND); // if the hand cursor is available, use it. if(s_hCursorHand) ::SetCursor(s_hCursorHand); return 0; }
.global s_prepare_buffers s_prepare_buffers: push %r11 push %r15 push %r8 push %rbp push %rcx push %rdi push %rsi lea addresses_normal_ht+0x15303, %rsi lea addresses_D_ht+0xec69, %rdi nop and $30540, %r15 mov $97, %rcx rep movsl nop nop cmp $45047, %r8 lea addresses_normal_ht+0x8b37, %rbp nop cmp $29775, %r11 movw $0x6162, (%rbp) nop xor $48055, %rbp lea addresses_WC_ht+0x1a573, %r8 nop add $25939, %rdi mov (%r8), %r15d nop nop nop sub $48460, %rcx lea addresses_UC_ht+0x2e23, %rcx nop nop nop nop xor %r8, %r8 movb $0x61, (%rcx) nop nop nop nop cmp $25782, %rdi pop %rsi pop %rdi pop %rcx pop %rbp pop %r8 pop %r15 pop %r11 ret .global s_faulty_load s_faulty_load: push %r14 push %r15 push %r8 push %rax push %rcx push %rdx // Store lea addresses_RW+0x14777, %r14 nop nop nop nop add $48816, %rax mov $0x5152535455565758, %r8 movq %r8, %xmm2 movups %xmm2, (%r14) nop nop nop nop add $39328, %rax // Faulty Load lea addresses_D+0x7137, %r8 nop nop nop nop xor %r14, %r14 vmovups (%r8), %ymm5 vextracti128 $0, %ymm5, %xmm5 vpextrq $1, %xmm5, %r15 lea oracles, %rdx and $0xff, %r15 shlq $12, %r15 mov (%rdx,%r15,1), %r15 pop %rdx pop %rcx pop %rax pop %r8 pop %r15 pop %r14 ret /* <gen_faulty_load> [REF] {'src': {'NT': False, 'same': False, 'congruent': 0, 'type': 'addresses_D', 'AVXalign': True, 'size': 8}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 6, 'type': 'addresses_RW', 'AVXalign': False, 'size': 16}} [Faulty Load] {'src': {'NT': False, 'same': True, 'congruent': 0, 'type': 'addresses_D', 'AVXalign': False, 'size': 32}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'same': False, 'congruent': 1, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 1, 'type': 'addresses_D_ht'}} {'OP': 'STOR', 'dst': {'NT': False, 'same': True, 'congruent': 9, 'type': 'addresses_normal_ht', 'AVXalign': False, 'size': 2}} {'src': {'NT': False, 'same': False, 'congruent': 1, 'type': 'addresses_WC_ht', 'AVXalign': False, 'size': 4}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 0, 'type': 'addresses_UC_ht', 'AVXalign': False, 'size': 1}} {'36': 21829} 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 */
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright (c) GeoWorks 1992 -- All Rights Reserved PROJECT: MODULE: FILE: saverUtils.asm AUTHOR: Adam de Boor, Dec 9, 1992 ROUTINES: Name Description ---- ----------- REVISION HISTORY: Name Date Description ---- ---- ----------- Adam 12/ 9/92 Initial revision DESCRIPTION: Utility routines for internal and external use. $Id: saverUtils.asm,v 1.1 97/04/07 10:44:32 newdeal Exp $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ SaverUtilsCode segment resource COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SaverCreateLaunchBlock %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Create an AppLaunchBlock to use for a master saver. CALLED BY: (GLOBAL) PASS: bp = disk handle on which saver is located cx:dx = path to saver ds = some segment that can be fixed up RETURN: bx = AppLaunchBlock handle DESTROYED: ax SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 12/ 9/92 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ SaverCreateLaunchBlock proc far uses si, di, cx, dx, bp, es .enter ; ; Create a default launch block using the IACP function of the ; same name. ; push cx, dx mov dx, MSG_GEN_PROCESS_OPEN_APPLICATION call IACPCreateDefaultLaunchBlock ; ; Now copy the path into the AppInstanceReference stored therein. ; xchg bx, dx pop cx, si push ds mov ds, cx call MemLock mov es, ax ornf es:[ALB_launchFlags], mask ALF_NO_ACTIVATION_DIALOG mov es:[ALB_appRef].AIR_diskHandle, bp mov di, offset ALB_appRef.AIR_fileName copyName: if DBCS_PCGEOS lodsw stosw tst ax else lodsb stosb tst al endif jnz copyName pop ds ; ; Locate the system field to which the saver will want to attach, so ; it doesn't get biffed when one leaves the current field. ; push bx ; save ALB handle mov cx, SEGMENT_CS mov dx, offset SULocateSystemField mov bp, es ; bp <- ax for callback mov ax, MSG_GEN_SYSTEM_FOREACH_FIELD call UserCallSystem ; ; All set. ; pop bx call MemUnlock .leave ret SaverCreateLaunchBlock endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SULocateSystemField %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Record the passed field as the one to which we should attach, on the assumption it's the last, i.e. the system, field. CALLED BY: SaverCreateLaunchBlock via MSG_GEN_SYSTEM_FOREACH_FIELD PASS: ^lbx:si = field ax = segment of AppLaunchBlock RETURN: carry set to stop enumerating DESTROYED: es PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 5/25/92 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ SULocateSystemField proc far .enter mov es, ax mov es:[ALB_genParent].handle, bx mov es:[ALB_genParent].chunk, si clc .leave ret SULocateSystemField endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SaverDuplicateALB %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Make a copy of the given block of memory. CALLED BY: (GLOBAL) PASS: bx = handle of block to duplicate RETURN: dx = old handle bx = new handle DESTROYED: nothing SIDE EFFECTS: none PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 10/12/92 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ SaverDuplicateALB proc far uses ax, ds, si, di, es, cx .enter ; ; Figure the size of the block. ; mov ax, MGIT_SIZE call MemGetInfo push ax ; save for copy ; ; Allocate another the same size, locked. (XXX: pass NO_ERR flag. ; Ought to be able to handle an error more gracefully, but I have ; no time to code it -- ardeb 11/23/92) ; mov dx, bx mov cx, ALLOC_DYNAMIC_NO_ERR_LOCK or mask HF_SHARABLE call MemAlloc mov es, ax ; ; Lock down the source block. ; xchg bx, dx call MemLock mov ds, ax ; ; Copy the contents from the old to the new. ; clr si, di pop cx shr cx rep movsw ; ; Unlock the old. ; call MemUnlock ; ; Unlock the new. ; xchg bx, dx call MemUnlock .leave ret SaverDuplicateALB endp SaverUtilsCode ends
; Copyright (c) Piotr Durlej ; All rights reserved. ; ; Redistribution and use in source and binary forms, with or without ; modification, are permitted provided that the following conditions are met: ; ; 1. Redistributions of source code must retain the above copyright notice, ; this list of conditions and the following disclaimer. ; ; 2. Redistributions in binary form must reproduce the above copyright ; notice, this list of conditions and the following disclaimer in the ; documentation and/or other materials provided with the distribution. ; ; THIS SOFTWARE IS PROVIDED BY 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. ; d_fxdisk: dw -1, -1 dw 0x2000 dw strategy dw fxdisk_io fxcnt: db 1 db 0, 0, 0, 0, 0, 0, 0 ; ---- fxdisk ---------------------------------------------------------------- fxdisk_io: push si mov si, fxdisk_switch jmp d_switch fxdisk_readpart: mov ax, 0x0201 mov cx, 0x0001 mov dx, 0x0080 mov bx, IOBUF >> 4 mov ds, bx mov es, bx xor bx, bx int 0x13 ret fxdisk_getpart: call fxdisk_readpart jnc .ok call fxdisk_readpart jnc .ok call fxdisk_readpart jc .fini .ok: mov bx, 0x1be .loop: mov al, [bx + 0x4] cmp al, 0x01 je .found add bx, 0x10 cmp bx, 0x1fe jne .loop stc .fini: push cs pop es push cs pop ds ret .found: mov ax, [bx + 0x8] mov cx, [bx + 0xc] mov [cs:fxoff ], ax mov [cs:fxtots], cx jmp .fini fxdisk_init: call stk_enter mov byte [es:bx + 13], 1 ; number of units mov word [es:bx + 14], endresid mov word [es:bx + 16], cs mov word [es:bx + 18], fxdisk_bpba ; BPB list offset mov word [es:bx + 20], cs ; BPB list segment mov word [es:bx + 3], 0x0100 ; DONE mov ah, 0x08 mov dl, 0x80 int 0x13 jc .fail inc dh mov al, cl xor ah, ah shl ax, 1 shl ax, 1 mov al, ch inc ax mov [cs:fxdisk_geom ], ax mov [cs:fxdisk_geom + 2], dh and cl, 0x3f mov [cs:fxdisk_geom + 4], cl call fxdisk_getpart call stk_leave ret .fail: call stk_leave ret fxdisk_mcheck: mov byte [es:bx + 14], 0 ; Not sure if media changed ; mov byte [es:bx + 14], 1 ; Media has been changed mov word [es:bx + 3], 0x0100 ; DONE ret fxdisk_bbpb: mov word [es:bx + 3], 0x0100 ; DONE mov word [es:bx + 18], fxdisk_bpb mov word [es:bx + 20], cs ret fxdisk_lgeom: push ax mov ax, [cs:fxdisk_geom + 2] mov [cs:nhead], ax mov ax, [cs:fxdisk_geom + 4] mov [cs:nsect], ax pop ax ret fxdisk_ppkt: call floppy_ppkt add byte [cs:cunit], 0x80 ret fxdisk_nogeom: mov word [es:bx + 3], 0x800c mov word [es:bx + 18], 0 ret fxdisk_read: test word [cs:fxtots], -1 jz fxdisk_nogeom call stk_enter push ds push ax push bx push cx push dx push si push di call fxdisk_lgeom call fxdisk_ppkt add ax, [cs:fxoff] call seek .loop: call split call read3 jc .fail call next sub cx, [cs:ccnt] jnz .loop mov word [es:bx + 3], 0x0100 ; DONE .fini: pop di pop si pop dx pop cx pop bx pop ax pop ds call stk_leave ret .fail: mov word [es:bx + 3], 0x800c ; General Failure mov word [es:bx + 18], 0 jmp .fini fxdisk_write: test word [cs:fxtots], -1 jz fxdisk_nogeom call stk_enter push ds push ax push bx push cx push dx push si push di call fxdisk_lgeom call fxdisk_ppkt add ax, [cs:fxoff] call seek .loop: call split call write3 jc .fail call next sub cx, [cs:ccnt] jnz .loop mov word [es:bx + 3], 0x0100 ; DONE .fini: pop di pop si pop dx pop cx pop bx pop ax pop ds call stk_leave ret .fail: mov word [es:bx + 3], 0x800c ; General Failure mov word [es:bx + 18], 0 jmp .fini fxdisk_wrver: test word [cs:fxtots], -1 jz fxdisk_nogeom call stk_enter push ds push ax push bx push cx push dx push si push di call fxdisk_lgeom call fxdisk_ppkt add ax, [cs:fxoff] call seek .loop: call split call spldma call write3 jc .fail call verify3 jc .fail call next sub cx, [cs:ccnt] jnz .loop mov word [es:bx + 3], 0x0100 ; DONE .fini: pop di pop si pop dx pop cx pop bx pop ax pop ds call stk_leave ret .fail: mov word [es:bx + 3], 0x800c ; General Failure mov word [es:bx + 18], 0 jmp .fini fxdisk_bpba: dw fxdisk_bpb dw fxdisk_bpb fxdisk_geom: dw 0 ; Cylinders dw 0 ; Heads dw 0 ; Sectors fxoff: dw 0 ; Partition offset fxdisk_bpb: dw 0x0200 ; bytes per sector db 0x10 ; sectors per cluster dw 0x01 ; reserved sectors db 0x02 ; number of FATs dw 0x0200 ; number of dir entries fxtots: dw 0x0000 ; number of sectors db 0xf8 ; media descriptor dw 0x0008 ; sectors per FAT fxdisk_switch: dw fxdisk_init ; Init dw fxdisk_mcheck ; Media check (block only) dw fxdisk_bbpb ; Build BPB (block only) dw d_nofunc ; IOCTL input dw fxdisk_read ; Input dw d_nofunc ; Non-destructive input (no wait, char devs only) dw d_nofunc ; Input status dw d_nofunc ; Input flush dw fxdisk_write ; Output dw fxdisk_wrver ; Output with verify dw d_nofunc ; Output flush
DB 0 1
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r12 push %r8 push %rbx push %rcx push %rdi push %rsi lea addresses_WC_ht+0xc1ea, %rsi lea addresses_WT_ht+0xb7ea, %rdi nop nop nop nop nop cmp %rbx, %rbx mov $121, %rcx rep movsw dec %r10 lea addresses_UC_ht+0x5ca, %rsi lea addresses_normal_ht+0x153aa, %rdi nop nop nop dec %r8 mov $6, %rcx rep movsw nop nop add %rcx, %rcx lea addresses_UC_ht+0x1dea, %rsi lea addresses_A_ht+0x8fea, %rdi nop nop and %r12, %r12 mov $93, %rcx rep movsb nop nop nop nop sub $2436, %r10 lea addresses_D_ht+0x7daa, %r12 nop nop nop and %rcx, %rcx and $0xffffffffffffffc0, %r12 movaps (%r12), %xmm7 vpextrq $1, %xmm7, %rbx add $17067, %r12 lea addresses_normal_ht+0x1c92a, %r8 nop nop nop nop nop cmp %rdi, %rdi mov $0x6162636465666768, %r10 movq %r10, (%r8) nop nop add $17015, %r8 lea addresses_normal_ht+0x1492a, %rbx nop sub %rsi, %rsi vmovups (%rbx), %ymm7 vextracti128 $0, %ymm7, %xmm7 vpextrq $1, %xmm7, %rdi nop nop nop inc %r12 lea addresses_normal_ht+0x1ddc2, %rsi sub $30863, %r12 movw $0x6162, (%rsi) nop nop xor %r8, %r8 lea addresses_WT_ht+0xc1c0, %r12 nop and %r10, %r10 mov $0x6162636465666768, %rcx movq %rcx, %xmm3 vmovups %ymm3, (%r12) xor $9880, %rsi lea addresses_WT_ht+0xea8a, %r12 nop nop nop nop inc %r10 and $0xffffffffffffffc0, %r12 movntdqa (%r12), %xmm1 vpextrq $1, %xmm1, %rsi nop mfence lea addresses_WT_ht+0x1722a, %rcx nop nop nop inc %rdi and $0xffffffffffffffc0, %rcx vmovntdqa (%rcx), %ymm4 vextracti128 $1, %ymm4, %xmm4 vpextrq $1, %xmm4, %r8 inc %r8 lea addresses_WT_ht+0x12a6e, %rsi lea addresses_D_ht+0x610a, %rdi nop nop nop nop inc %r10 mov $32, %rcx rep movsw nop nop and $20594, %rbx lea addresses_normal_ht+0x4e3e, %r10 add $10942, %rcx mov (%r10), %di sub %rdi, %rdi lea addresses_normal_ht+0x88da, %rcx clflush (%rcx) nop nop nop nop nop and %r10, %r10 mov (%rcx), %ebx nop nop nop nop nop cmp $15668, %r8 pop %rsi pop %rdi pop %rcx pop %rbx pop %r8 pop %r12 pop %r10 ret .global s_faulty_load s_faulty_load: push %r11 push %r14 push %rax push %rcx push %rdi push %rdx push %rsi // Store lea addresses_D+0x16fea, %rcx nop nop nop nop nop cmp %rdx, %rdx movl $0x51525354, (%rcx) nop nop xor %rsi, %rsi // Store lea addresses_normal+0xf3ea, %rax nop nop nop nop nop lfence mov $0x5152535455565758, %r11 movq %r11, %xmm6 vmovups %ymm6, (%rax) nop nop xor $18983, %r14 // Faulty Load lea addresses_A+0x1fea, %rax nop xor %rcx, %rcx movb (%rax), %r11b lea oracles, %rdx and $0xff, %r11 shlq $12, %r11 mov (%rdx,%r11,1), %r11 pop %rsi pop %rdx pop %rdi pop %rcx pop %rax pop %r14 pop %r11 ret /* <gen_faulty_load> [REF] {'src': {'same': False, 'congruent': 0, 'NT': False, 'type': 'addresses_A', 'size': 32, 'AVXalign': True}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'same': False, 'congruent': 11, 'NT': False, 'type': 'addresses_D', 'size': 4, 'AVXalign': False}} {'OP': 'STOR', 'dst': {'same': True, 'congruent': 10, 'NT': False, 'type': 'addresses_normal', 'size': 32, 'AVXalign': False}} [Faulty Load] {'src': {'same': True, 'congruent': 0, 'NT': False, 'type': 'addresses_A', 'size': 1, 'AVXalign': False}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'type': 'addresses_WC_ht', 'congruent': 9, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_WT_ht', 'congruent': 11, 'same': False}} {'src': {'type': 'addresses_UC_ht', 'congruent': 5, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_normal_ht', 'congruent': 6, 'same': False}} {'src': {'type': 'addresses_UC_ht', 'congruent': 8, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_A_ht', 'congruent': 9, 'same': False}} {'src': {'same': False, 'congruent': 6, 'NT': False, 'type': 'addresses_D_ht', 'size': 16, 'AVXalign': True}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'same': False, 'congruent': 5, 'NT': False, 'type': 'addresses_normal_ht', 'size': 8, 'AVXalign': False}} {'src': {'same': False, 'congruent': 6, 'NT': False, 'type': 'addresses_normal_ht', 'size': 32, 'AVXalign': False}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'same': False, 'congruent': 3, 'NT': False, 'type': 'addresses_normal_ht', 'size': 2, 'AVXalign': False}} {'OP': 'STOR', 'dst': {'same': False, 'congruent': 1, 'NT': False, 'type': 'addresses_WT_ht', 'size': 32, 'AVXalign': False}} {'src': {'same': False, 'congruent': 5, 'NT': True, 'type': 'addresses_WT_ht', 'size': 16, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'same': False, 'congruent': 6, 'NT': True, 'type': 'addresses_WT_ht', 'size': 32, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_WT_ht', 'congruent': 2, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_D_ht', 'congruent': 5, 'same': False}} {'src': {'same': False, 'congruent': 2, 'NT': False, 'type': 'addresses_normal_ht', 'size': 2, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'same': False, 'congruent': 3, 'NT': False, 'type': 'addresses_normal_ht', 'size': 4, 'AVXalign': False}, 'OP': 'LOAD'} {'35': 21829} 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 */
.thumb .org 0x0 @r0=char data push {r14} ldrb r1,[r0,#0xB] mov r2,#0xC0 tst r1,r2 beq GetPortrait mov r1,#0x1 @blank mug b GoBack GetPortrait: ldr r1,PortraitGetter mov r14,r1 .short 0xF800 mov r1,r0 GoBack: sub r4,#0x4 mov r0,#0x3 pop {r2} str r0,[sp] bx r2 .align PortraitGetter: .long 0x080192B8
/** * @file * @copyright defined in eos/LICENSE */ #include <eosio/mongo_db_plugin/mongo_db_plugin.hpp> #include <eosio/chain/eosio_contract.hpp> #include <eosio/chain/config.hpp> #include <eosio/chain/exceptions.hpp> #include <eosio/chain/transaction.hpp> #include <eosio/chain/types.hpp> #include <fc/io/json.hpp> #include <fc/log/logger_config.hpp> #include <fc/utf8.hpp> #include <fc/variant.hpp> #include <boost/algorithm/string.hpp> #include <boost/chrono.hpp> #include <boost/signals2/connection.hpp> #include <queue> #include <thread> #include <mutex> #include <bsoncxx/builder/basic/kvp.hpp> #include <bsoncxx/builder/basic/document.hpp> #include <bsoncxx/exception/exception.hpp> #include <bsoncxx/json.hpp> #include <mongocxx/client.hpp> #include <mongocxx/instance.hpp> #include <mongocxx/pool.hpp> #include <mongocxx/exception/operation_exception.hpp> #include <mongocxx/exception/logic_error.hpp> namespace fc { class variant; } namespace eosio { using chain::account_name; using chain::action_name; using chain::block_id_type; using chain::permission_name; using chain::transaction; using chain::signed_transaction; using chain::signed_block; using chain::transaction_id_type; using chain::packed_transaction; static appbase::abstract_plugin& _mongo_db_plugin = app().register_plugin<mongo_db_plugin>(); struct filter_entry { name receiver; name action; name actor; friend bool operator<( const filter_entry& a, const filter_entry& b ) { return std::tie( a.receiver, a.action, a.actor ) < std::tie( b.receiver, b.action, b.actor ); } // receiver action actor bool match( const name& rr, const name& an, const name& ar ) const { return (receiver.value == 0 || receiver == rr) && (action.value == 0 || action == an) && (actor.value == 0 || actor == ar); } }; class mongo_db_plugin_impl { public: mongo_db_plugin_impl(); ~mongo_db_plugin_impl(); fc::optional<boost::signals2::scoped_connection> accepted_block_connection; fc::optional<boost::signals2::scoped_connection> irreversible_block_connection; fc::optional<boost::signals2::scoped_connection> accepted_transaction_connection; fc::optional<boost::signals2::scoped_connection> applied_transaction_connection; void consume_blocks(); void accepted_block( const chain::block_state_ptr& ); void applied_irreversible_block(const chain::block_state_ptr&); void accepted_transaction(const chain::transaction_metadata_ptr&); void applied_transaction(const chain::transaction_trace_ptr&); void process_accepted_transaction(const chain::transaction_metadata_ptr&); void _process_accepted_transaction(const chain::transaction_metadata_ptr&); void process_applied_transaction(const chain::transaction_trace_ptr&); void _process_applied_transaction(const chain::transaction_trace_ptr&); void process_accepted_block( const chain::block_state_ptr& ); void _process_accepted_block( const chain::block_state_ptr& ); void process_irreversible_block(const chain::block_state_ptr&); void _process_irreversible_block(const chain::block_state_ptr&); optional<abi_serializer> get_abi_serializer( account_name n ); template<typename T> fc::variant to_variant_with_abi( const T& obj ); void purge_abi_cache(); bool add_action_trace( mongocxx::bulk_write& bulk_action_traces, const chain::action_trace& atrace, const chain::transaction_trace_ptr& t, bool executed, const std::chrono::milliseconds& now, bool& write_ttrace ); void update_account(const chain::action& act); void add_pub_keys( const vector<chain::key_weight>& keys, const account_name& name, const permission_name& permission, const std::chrono::milliseconds& now ); void remove_pub_keys( const account_name& name, const permission_name& permission ); void add_account_control( const vector<chain::permission_level_weight>& controlling_accounts, const account_name& name, const permission_name& permission, const std::chrono::milliseconds& now ); void remove_account_control( const account_name& name, const permission_name& permission ); /// @return true if act should be added to mongodb, false to skip it bool filter_include( const account_name& receiver, const action_name& act_name, const vector<chain::permission_level>& authorization ) const; bool filter_include( const transaction& trx ) const; void init(); void wipe_database(); void create_expiration_index(mongocxx::collection& collection, uint32_t expire_after_seconds); template<typename Queue, typename Entry> void queue(Queue& queue, const Entry& e); bool configured{false}; bool wipe_database_on_startup{false}; uint32_t start_block_num = 0; std::atomic_bool start_block_reached{false}; bool is_producer = false; bool filter_on_star = true; std::set<filter_entry> filter_on; std::set<filter_entry> filter_out; bool update_blocks_via_block_num = false; bool store_blocks = true; bool store_block_states = true; bool store_transactions = true; bool store_transaction_traces = true; bool store_action_traces = true; uint32_t expire_after_seconds = 0; std::string db_name; mongocxx::instance mongo_inst; fc::optional<mongocxx::pool> mongo_pool; // consum thread mongocxx::collection _accounts; mongocxx::collection _trans; mongocxx::collection _trans_traces; mongocxx::collection _action_traces; mongocxx::collection _block_states; mongocxx::collection _blocks; mongocxx::collection _pub_keys; mongocxx::collection _account_controls; size_t max_queue_size = 0; int queue_sleep_time = 0; size_t abi_cache_size = 0; std::deque<chain::transaction_metadata_ptr> transaction_metadata_queue; std::deque<chain::transaction_metadata_ptr> transaction_metadata_process_queue; std::deque<chain::transaction_trace_ptr> transaction_trace_queue; std::deque<chain::transaction_trace_ptr> transaction_trace_process_queue; std::deque<chain::block_state_ptr> block_state_queue; std::deque<chain::block_state_ptr> block_state_process_queue; std::deque<chain::block_state_ptr> irreversible_block_state_queue; std::deque<chain::block_state_ptr> irreversible_block_state_process_queue; std::mutex mtx; std::condition_variable condition; std::thread consume_thread; std::atomic_bool done{false}; std::atomic_bool startup{true}; fc::optional<chain::chain_id_type> chain_id; fc::microseconds abi_serializer_max_time; struct by_account; struct by_last_access; struct abi_cache { account_name account; fc::time_point last_accessed; fc::optional<abi_serializer> serializer; }; typedef boost::multi_index_container<abi_cache, indexed_by< ordered_unique< tag<by_account>, member<abi_cache,account_name,&abi_cache::account> >, ordered_non_unique< tag<by_last_access>, member<abi_cache,fc::time_point,&abi_cache::last_accessed> > > > abi_cache_index_t; abi_cache_index_t abi_cache_index; static const action_name newaccount; static const action_name setabi; static const action_name updateauth; static const action_name deleteauth; static const permission_name owner; static const permission_name active; static const std::string block_states_col; static const std::string blocks_col; static const std::string trans_col; static const std::string trans_traces_col; static const std::string action_traces_col; static const std::string accounts_col; static const std::string pub_keys_col; static const std::string account_controls_col; }; const action_name mongo_db_plugin_impl::newaccount = chain::newaccount::get_name(); const action_name mongo_db_plugin_impl::setabi = chain::setabi::get_name(); const action_name mongo_db_plugin_impl::updateauth = chain::updateauth::get_name(); const action_name mongo_db_plugin_impl::deleteauth = chain::deleteauth::get_name(); const permission_name mongo_db_plugin_impl::owner = chain::config::owner_name; const permission_name mongo_db_plugin_impl::active = chain::config::active_name; const std::string mongo_db_plugin_impl::block_states_col = "block_states"; const std::string mongo_db_plugin_impl::blocks_col = "blocks"; const std::string mongo_db_plugin_impl::trans_col = "transactions"; const std::string mongo_db_plugin_impl::trans_traces_col = "transaction_traces"; const std::string mongo_db_plugin_impl::action_traces_col = "action_traces"; const std::string mongo_db_plugin_impl::accounts_col = "accounts"; const std::string mongo_db_plugin_impl::pub_keys_col = "pub_keys"; const std::string mongo_db_plugin_impl::account_controls_col = "account_controls"; bool mongo_db_plugin_impl::filter_include( const account_name& receiver, const action_name& act_name, const vector<chain::permission_level>& authorization ) const { bool include = false; if( filter_on_star ) { include = true; } else { auto itr = std::find_if( filter_on.cbegin(), filter_on.cend(), [&receiver, &act_name]( const auto& filter ) { return filter.match( receiver, act_name, 0 ); } ); if( itr != filter_on.cend() ) { include = true; } else { for( const auto& a : authorization ) { auto itr = std::find_if( filter_on.cbegin(), filter_on.cend(), [&receiver, &act_name, &a]( const auto& filter ) { return filter.match( receiver, act_name, a.actor ); } ); if( itr != filter_on.cend() ) { include = true; break; } } } } if( !include ) { return false; } if( filter_out.empty() ) { return true; } auto itr = std::find_if( filter_out.cbegin(), filter_out.cend(), [&receiver, &act_name]( const auto& filter ) { return filter.match( receiver, act_name, 0 ); } ); if( itr != filter_out.cend() ) { return false; } for( const auto& a : authorization ) { auto itr = std::find_if( filter_out.cbegin(), filter_out.cend(), [&receiver, &act_name, &a]( const auto& filter ) { return filter.match( receiver, act_name, a.actor ); } ); if( itr != filter_out.cend() ) { return false; } } return true; } bool mongo_db_plugin_impl::filter_include( const transaction& trx ) const { if( !filter_on_star || !filter_out.empty() ) { bool include = false; for( const auto& a : trx.actions ) { if( filter_include( a.account, a.name, a.authorization ) ) { include = true; break; } } if( !include ) { for( const auto& a : trx.context_free_actions ) { if( filter_include( a.account, a.name, a.authorization ) ) { include = true; break; } } } return include; } return true; } template<typename Queue, typename Entry> void mongo_db_plugin_impl::queue( Queue& queue, const Entry& e ) { std::unique_lock<std::mutex> lock( mtx ); auto queue_size = queue.size(); if( queue_size > max_queue_size ) { lock.unlock(); condition.notify_one(); queue_sleep_time += 10; if( queue_sleep_time > 1000 ) wlog("queue size: ${q}", ("q", queue_size)); std::this_thread::sleep_for( std::chrono::milliseconds( queue_sleep_time )); lock.lock(); } else { queue_sleep_time -= 10; if( queue_sleep_time < 0 ) queue_sleep_time = 0; } queue.emplace_back( e ); lock.unlock(); condition.notify_one(); } void mongo_db_plugin_impl::accepted_transaction( const chain::transaction_metadata_ptr& t ) { try { if( store_transactions ) { queue( transaction_metadata_queue, t ); } } catch (fc::exception& e) { elog("FC Exception while accepted_transaction ${e}", ("e", e.to_string())); } catch (std::exception& e) { elog("STD Exception while accepted_transaction ${e}", ("e", e.what())); } catch (...) { elog("Unknown exception while accepted_transaction"); } } void mongo_db_plugin_impl::applied_transaction( const chain::transaction_trace_ptr& t ) { try { // Traces emitted from an incomplete block leave the producer_block_id as empty. // // Avoid adding the action traces or transaction traces to the database if the producer_block_id is empty. // This way traces from speculatively executed transactions are not included in the Mongo database which can // avoid potential confusion for consumers of that database. // // Due to forks, it could be possible for multiple incompatible action traces with the same block_num and trx_id // to exist in the database. And if the producer double produces a block, even the block_time may not // disambiguate the two action traces. Without a producer_block_id to disambiguate and determine if the action // trace comes from an orphaned fork branching off of the blockchain, consumers of the Mongo DB database may be // reacting to a stale action trace that never actually executed in the current blockchain. // // It is better to avoid this potential confusion by not logging traces from speculative execution, i.e. emitted // from an incomplete block. This means that traces will not be recorded in speculative read-mode, but // users should not be using the mongo_db_plugin in that mode anyway. // // Allow logging traces if node is a producer for testing purposes, so a single nodeos can do both for testing. // // It is recommended to run mongo_db_plugin in read-mode = read-only. // if( !is_producer && !t->producer_block_id.valid() ) return; // always queue since account information always gathered queue( transaction_trace_queue, t ); } catch (fc::exception& e) { elog("FC Exception while applied_transaction ${e}", ("e", e.to_string())); } catch (std::exception& e) { elog("STD Exception while applied_transaction ${e}", ("e", e.what())); } catch (...) { elog("Unknown exception while applied_transaction"); } } void mongo_db_plugin_impl::applied_irreversible_block( const chain::block_state_ptr& bs ) { try { if( store_blocks || store_block_states || store_transactions ) { queue( irreversible_block_state_queue, bs ); } } catch (fc::exception& e) { elog("FC Exception while applied_irreversible_block ${e}", ("e", e.to_string())); } catch (std::exception& e) { elog("STD Exception while applied_irreversible_block ${e}", ("e", e.what())); } catch (...) { elog("Unknown exception while applied_irreversible_block"); } } void mongo_db_plugin_impl::accepted_block( const chain::block_state_ptr& bs ) { try { if( !start_block_reached ) { if( bs->block_num >= start_block_num ) { start_block_reached = true; } } if( store_blocks || store_block_states ) { queue( block_state_queue, bs ); } } catch (fc::exception& e) { elog("FC Exception while accepted_block ${e}", ("e", e.to_string())); } catch (std::exception& e) { elog("STD Exception while accepted_block ${e}", ("e", e.what())); } catch (...) { elog("Unknown exception while accepted_block"); } } void mongo_db_plugin_impl::consume_blocks() { try { auto mongo_client = mongo_pool->acquire(); auto& mongo_conn = *mongo_client; _accounts = mongo_conn[db_name][accounts_col]; _trans = mongo_conn[db_name][trans_col]; _trans_traces = mongo_conn[db_name][trans_traces_col]; _action_traces = mongo_conn[db_name][action_traces_col]; _blocks = mongo_conn[db_name][blocks_col]; _block_states = mongo_conn[db_name][block_states_col]; _pub_keys = mongo_conn[db_name][pub_keys_col]; _account_controls = mongo_conn[db_name][account_controls_col]; while (true) { std::unique_lock<std::mutex> lock(mtx); while ( transaction_metadata_queue.empty() && transaction_trace_queue.empty() && block_state_queue.empty() && irreversible_block_state_queue.empty() && !done ) { condition.wait(lock); } // capture for processing size_t transaction_metadata_size = transaction_metadata_queue.size(); if (transaction_metadata_size > 0) { transaction_metadata_process_queue = move(transaction_metadata_queue); transaction_metadata_queue.clear(); } size_t transaction_trace_size = transaction_trace_queue.size(); if (transaction_trace_size > 0) { transaction_trace_process_queue = move(transaction_trace_queue); transaction_trace_queue.clear(); } size_t block_state_size = block_state_queue.size(); if (block_state_size > 0) { block_state_process_queue = move(block_state_queue); block_state_queue.clear(); } size_t irreversible_block_size = irreversible_block_state_queue.size(); if (irreversible_block_size > 0) { irreversible_block_state_process_queue = move(irreversible_block_state_queue); irreversible_block_state_queue.clear(); } lock.unlock(); if (done) { ilog("draining queue, size: ${q}", ("q", transaction_metadata_size + transaction_trace_size + block_state_size + irreversible_block_size)); } // process transactions auto start_time = fc::time_point::now(); auto size = transaction_trace_process_queue.size(); while (!transaction_trace_process_queue.empty()) { const auto& t = transaction_trace_process_queue.front(); process_applied_transaction(t); transaction_trace_process_queue.pop_front(); } auto time = fc::time_point::now() - start_time; auto per = size > 0 ? time.count()/size : 0; if( time > fc::microseconds(500000) ) // reduce logging, .5 secs ilog( "process_applied_transaction, time per: ${p}, size: ${s}, time: ${t}", ("s", size)("t", time)("p", per) ); start_time = fc::time_point::now(); size = transaction_metadata_process_queue.size(); while (!transaction_metadata_process_queue.empty()) { const auto& t = transaction_metadata_process_queue.front(); process_accepted_transaction(t); transaction_metadata_process_queue.pop_front(); } time = fc::time_point::now() - start_time; per = size > 0 ? time.count()/size : 0; if( time > fc::microseconds(500000) ) // reduce logging, .5 secs ilog( "process_accepted_transaction, time per: ${p}, size: ${s}, time: ${t}", ("s", size)( "t", time )( "p", per )); // process blocks start_time = fc::time_point::now(); size = block_state_process_queue.size(); while (!block_state_process_queue.empty()) { const auto& bs = block_state_process_queue.front(); process_accepted_block( bs ); block_state_process_queue.pop_front(); } time = fc::time_point::now() - start_time; per = size > 0 ? time.count()/size : 0; if( time > fc::microseconds(500000) ) // reduce logging, .5 secs ilog( "process_accepted_block, time per: ${p}, size: ${s}, time: ${t}", ("s", size)("t", time)("p", per) ); // process irreversible blocks start_time = fc::time_point::now(); size = irreversible_block_state_process_queue.size(); while (!irreversible_block_state_process_queue.empty()) { const auto& bs = irreversible_block_state_process_queue.front(); process_irreversible_block(bs); irreversible_block_state_process_queue.pop_front(); } time = fc::time_point::now() - start_time; per = size > 0 ? time.count()/size : 0; if( time > fc::microseconds(500000) ) // reduce logging, .5 secs ilog( "process_irreversible_block, time per: ${p}, size: ${s}, time: ${t}", ("s", size)("t", time)("p", per) ); if( transaction_metadata_size == 0 && transaction_trace_size == 0 && block_state_size == 0 && irreversible_block_size == 0 && done ) { break; } } ilog("mongo_db_plugin consume thread shutdown gracefully"); } catch (fc::exception& e) { elog("FC Exception while consuming block ${e}", ("e", e.to_string())); } catch (std::exception& e) { elog("STD Exception while consuming block ${e}", ("e", e.what())); } catch (...) { elog("Unknown exception while consuming block"); } } namespace { auto find_account( mongocxx::collection& accounts, const account_name& name ) { using bsoncxx::builder::basic::make_document; using bsoncxx::builder::basic::kvp; return accounts.find_one( make_document( kvp( "name", name.to_string()))); } auto find_block( mongocxx::collection& blocks, const string& id ) { using bsoncxx::builder::basic::make_document; using bsoncxx::builder::basic::kvp; mongocxx::options::find options; options.projection( make_document( kvp( "_id", 1 )) ); // only return _id return blocks.find_one( make_document( kvp( "block_id", id )), options); } void handle_mongo_exception( const std::string& desc, int line_num ) { bool shutdown = true; try { try { throw; } catch( mongocxx::logic_error& e) { // logic_error on invalid key, do not shutdown wlog( "mongo logic error, ${desc}, line ${line}, code ${code}, ${what}", ("desc", desc)( "line", line_num )( "code", e.code().value() )( "what", e.what() )); shutdown = false; } catch( mongocxx::operation_exception& e) { elog( "mongo exception, ${desc}, line ${line}, code ${code}, ${details}", ("desc", desc)( "line", line_num )( "code", e.code().value() )( "details", e.code().message() )); if (e.raw_server_error()) { elog( " raw_server_error: ${e}", ( "e", bsoncxx::to_json(e.raw_server_error()->view()))); } } catch( mongocxx::exception& e) { elog( "mongo exception, ${desc}, line ${line}, code ${code}, ${what}", ("desc", desc)( "line", line_num )( "code", e.code().value() )( "what", e.what() )); } catch( bsoncxx::exception& e) { elog( "bsoncxx exception, ${desc}, line ${line}, code ${code}, ${what}", ("desc", desc)( "line", line_num )( "code", e.code().value() )( "what", e.what() )); } catch( fc::exception& er ) { elog( "mongo fc exception, ${desc}, line ${line}, ${details}", ("desc", desc)( "line", line_num )( "details", er.to_detail_string())); } catch( const std::exception& e ) { elog( "mongo std exception, ${desc}, line ${line}, ${what}", ("desc", desc)( "line", line_num )( "what", e.what())); } catch( ... ) { elog( "mongo unknown exception, ${desc}, line ${line_nun}", ("desc", desc)( "line_num", line_num )); } } catch (...) { std::cerr << "Exception attempting to handle exception for " << desc << " " << line_num << std::endl; } if( shutdown ) { // shutdown if mongo failed to provide opportunity to fix issue and restart app().quit(); } } // custom oid to avoid monotonic throttling // https://docs.mongodb.com/master/core/bulk-write-operations/#avoid-monotonic-throttling bsoncxx::oid make_custom_oid() { bsoncxx::oid x = bsoncxx::oid(); const char* p = x.bytes(); std::swap((short&)p[0], (short&)p[10]); return x; } } // anonymous namespace void mongo_db_plugin_impl::purge_abi_cache() { if( abi_cache_index.size() < abi_cache_size ) return; // remove the oldest (smallest) last accessed auto& idx = abi_cache_index.get<by_last_access>(); auto itr = idx.begin(); if( itr != idx.end() ) { idx.erase( itr ); } } optional<abi_serializer> mongo_db_plugin_impl::get_abi_serializer( account_name n ) { using bsoncxx::builder::basic::kvp; using bsoncxx::builder::basic::make_document; if( n.good()) { try { auto itr = abi_cache_index.find( n ); if( itr != abi_cache_index.end() ) { abi_cache_index.modify( itr, []( auto& entry ) { entry.last_accessed = fc::time_point::now(); }); return itr->serializer; } auto account = _accounts.find_one( make_document( kvp("name", n.to_string())) ); if(account) { auto view = account->view(); abi_def abi; if( view.find( "abi" ) != view.end()) { try { abi = fc::json::from_string( bsoncxx::to_json( view["abi"].get_document())).as<abi_def>(); } catch (...) { ilog( "Unable to convert account abi to abi_def for ${n}", ( "n", n )); return optional<abi_serializer>(); } purge_abi_cache(); // make room if necessary abi_cache entry; entry.account = n; entry.last_accessed = fc::time_point::now(); abi_serializer abis; if( n == chain::config::system_account_name ) { // redefine eosio setabi.abi from bytes to abi_def // Done so that abi is stored as abi_def in mongo instead of as bytes auto itr = std::find_if( abi.structs.begin(), abi.structs.end(), []( const auto& s ) { return s.name == "setabi"; } ); if( itr != abi.structs.end() ) { auto itr2 = std::find_if( itr->fields.begin(), itr->fields.end(), []( const auto& f ) { return f.name == "abi"; } ); if( itr2 != itr->fields.end() ) { if( itr2->type == "bytes" ) { itr2->type = "abi_def"; // unpack setabi.abi as abi_def instead of as bytes abis.add_specialized_unpack_pack( "abi_def", std::make_pair<abi_serializer::unpack_function, abi_serializer::pack_function>( []( fc::datastream<const char*>& stream, bool is_array, bool is_optional ) -> fc::variant { EOS_ASSERT( !is_array && !is_optional, chain::mongo_db_exception, "unexpected abi_def"); chain::bytes temp; fc::raw::unpack( stream, temp ); return fc::variant( fc::raw::unpack<abi_def>( temp ) ); }, []( const fc::variant& var, fc::datastream<char*>& ds, bool is_array, bool is_optional ) { EOS_ASSERT( false, chain::mongo_db_exception, "never called" ); } ) ); } } } } // mongo does not like empty json keys // make abi_serializer use empty_name instead of "" for the action data for( auto& s : abi.structs ) { if( s.name.empty() ) { s.name = "empty_struct_name"; } for( auto& f : s.fields ) { if( f.name.empty() ) { f.name = "empty_field_name"; } } } abis.set_abi( abi, abi_serializer_max_time ); entry.serializer.emplace( std::move( abis ) ); abi_cache_index.insert( entry ); return entry.serializer; } } } FC_CAPTURE_AND_LOG((n)) } return optional<abi_serializer>(); } template<typename T> fc::variant mongo_db_plugin_impl::to_variant_with_abi( const T& obj ) { fc::variant pretty_output; abi_serializer::to_variant( obj, pretty_output, [&]( account_name n ) { return get_abi_serializer( n ); }, abi_serializer_max_time ); return pretty_output; } void mongo_db_plugin_impl::process_accepted_transaction( const chain::transaction_metadata_ptr& t ) { try { if( start_block_reached ) { _process_accepted_transaction( t ); } } catch (fc::exception& e) { elog("FC Exception while processing accepted transaction metadata: ${e}", ("e", e.to_detail_string())); } catch (std::exception& e) { elog("STD Exception while processing accepted tranasction metadata: ${e}", ("e", e.what())); } catch (...) { elog("Unknown exception while processing accepted transaction metadata"); } } void mongo_db_plugin_impl::process_applied_transaction( const chain::transaction_trace_ptr& t ) { try { // always call since we need to capture setabi on accounts even if not storing transaction traces _process_applied_transaction( t ); } catch (fc::exception& e) { elog("FC Exception while processing applied transaction trace: ${e}", ("e", e.to_detail_string())); } catch (std::exception& e) { elog("STD Exception while processing applied transaction trace: ${e}", ("e", e.what())); } catch (...) { elog("Unknown exception while processing applied transaction trace"); } } void mongo_db_plugin_impl::process_irreversible_block(const chain::block_state_ptr& bs) { try { if( start_block_reached ) { _process_irreversible_block( bs ); } } catch (fc::exception& e) { elog("FC Exception while processing irreversible block: ${e}", ("e", e.to_detail_string())); } catch (std::exception& e) { elog("STD Exception while processing irreversible block: ${e}", ("e", e.what())); } catch (...) { elog("Unknown exception while processing irreversible block"); } } void mongo_db_plugin_impl::process_accepted_block( const chain::block_state_ptr& bs ) { try { if( start_block_reached ) { _process_accepted_block( bs ); } } catch (fc::exception& e) { elog("FC Exception while processing accepted block trace ${e}", ("e", e.to_string())); } catch (std::exception& e) { elog("STD Exception while processing accepted block trace ${e}", ("e", e.what())); } catch (...) { elog("Unknown exception while processing accepted block trace"); } } void mongo_db_plugin_impl::_process_accepted_transaction( const chain::transaction_metadata_ptr& t ) { using namespace bsoncxx::types; using bsoncxx::builder::basic::kvp; using bsoncxx::builder::basic::make_document; using bsoncxx::builder::basic::make_array; namespace bbb = bsoncxx::builder::basic; const signed_transaction& trx = t->packed_trx->get_signed_transaction(); if( !filter_include( trx ) ) return; auto trans_doc = bsoncxx::builder::basic::document{}; auto now = std::chrono::duration_cast<std::chrono::milliseconds>( std::chrono::microseconds{fc::time_point::now().time_since_epoch().count()} ); const auto& trx_id = t->id; const auto trx_id_str = trx_id.str(); trans_doc.append( kvp( "trx_id", trx_id_str ) ); auto v = to_variant_with_abi( trx ); string trx_json = fc::json::to_string( v, fc::time_point::maximum() ); try { const auto& trx_value = bsoncxx::from_json( trx_json ); trans_doc.append( bsoncxx::builder::concatenate_doc{trx_value.view()} ); } catch( bsoncxx::exception& ) { try { trx_json = fc::prune_invalid_utf8( trx_json ); const auto& trx_value = bsoncxx::from_json( trx_json ); trans_doc.append( bsoncxx::builder::concatenate_doc{trx_value.view()} ); trans_doc.append( kvp( "non-utf8-purged", b_bool{true} ) ); } catch( bsoncxx::exception& e ) { elog( "Unable to convert transaction JSON to MongoDB JSON: ${e}", ("e", e.what()) ); elog( " JSON: ${j}", ("j", trx_json) ); } } string signing_keys_json; if( t->signing_keys_future.valid() ) { signing_keys_json = fc::json::to_string( std::get<2>( t->signing_keys_future.get() ), fc::time_point::maximum() ); } else { flat_set<public_key_type> keys; trx.get_signature_keys( *chain_id, fc::time_point::maximum(), keys, false ); if( !keys.empty() ) { signing_keys_json = fc::json::to_string( keys, fc::time_point::maximum() ); } } if( !signing_keys_json.empty() ) { try { const auto& keys_value = bsoncxx::from_json( signing_keys_json ); trans_doc.append( kvp( "signing_keys", keys_value ) ); } catch( bsoncxx::exception& e ) { // should never fail, so don't attempt to remove invalid utf8 elog( "Unable to convert signing keys JSON to MongoDB JSON: ${e}", ("e", e.what()) ); elog( " JSON: ${j}", ("j", signing_keys_json) ); } } trans_doc.append( kvp( "accepted", b_bool{t->accepted} ) ); trans_doc.append( kvp( "implicit", b_bool{t->implicit} ) ); trans_doc.append( kvp( "scheduled", b_bool{t->scheduled} ) ); trans_doc.append( kvp( "createdAt", b_date{now} ) ); try { mongocxx::options::update update_opts{}; update_opts.upsert( true ); if( !_trans.update_one( make_document( kvp( "trx_id", trx_id_str ) ), make_document( kvp( "$set", trans_doc.view() ) ), update_opts ) ) { EOS_ASSERT( false, chain::mongo_db_insert_fail, "Failed to insert trans ${id}", ("id", trx_id) ); } } catch( ... ) { handle_mongo_exception( "trans insert", __LINE__ ); } } bool mongo_db_plugin_impl::add_action_trace( mongocxx::bulk_write& bulk_action_traces, const chain::action_trace& atrace, const chain::transaction_trace_ptr& t, bool executed, const std::chrono::milliseconds& now, bool& write_ttrace ) { using namespace bsoncxx::types; using bsoncxx::builder::basic::kvp; if( executed && atrace.receiver == chain::config::system_account_name ) { update_account( atrace.act ); } bool added = false; const bool in_filter = (store_action_traces || store_transaction_traces) && start_block_reached && filter_include( atrace.receiver, atrace.act.name, atrace.act.authorization ); write_ttrace |= in_filter; if( start_block_reached && store_action_traces && in_filter ) { auto action_traces_doc = bsoncxx::builder::basic::document{}; // improve data distributivity when using mongodb sharding action_traces_doc.append( kvp( "_id", make_custom_oid() ) ); auto v = to_variant_with_abi( atrace ); string json = fc::json::to_string( v, fc::time_point::maximum() ); try { const auto& value = bsoncxx::from_json( json ); action_traces_doc.append( bsoncxx::builder::concatenate_doc{value.view()} ); } catch( bsoncxx::exception& ) { try { json = fc::prune_invalid_utf8( json ); const auto& value = bsoncxx::from_json( json ); action_traces_doc.append( bsoncxx::builder::concatenate_doc{value.view()} ); action_traces_doc.append( kvp( "non-utf8-purged", b_bool{true} ) ); } catch( bsoncxx::exception& e ) { elog( "Unable to convert action trace JSON to MongoDB JSON: ${e}", ("e", e.what()) ); elog( " JSON: ${j}", ("j", json) ); } } if( t->receipt.valid() ) { action_traces_doc.append( kvp( "trx_status", std::string( t->receipt->status ) ) ); } action_traces_doc.append( kvp( "createdAt", b_date{now} ) ); mongocxx::model::insert_one insert_op{action_traces_doc.view()}; bulk_action_traces.append( insert_op ); added = true; } return added; } void mongo_db_plugin_impl::_process_applied_transaction( const chain::transaction_trace_ptr& t ) { using namespace bsoncxx::types; using bsoncxx::builder::basic::kvp; auto trans_traces_doc = bsoncxx::builder::basic::document{}; auto now = std::chrono::duration_cast<std::chrono::milliseconds>( std::chrono::microseconds{fc::time_point::now().time_since_epoch().count()}); mongocxx::options::bulk_write bulk_opts; bulk_opts.ordered(false); mongocxx::bulk_write bulk_action_traces = _action_traces.create_bulk_write(bulk_opts); bool write_atraces = false; bool write_ttrace = false; // filters apply to transaction_traces as well bool executed = t->receipt.valid() && t->receipt->status == chain::transaction_receipt_header::executed; for( const auto& atrace : t->action_traces ) { try { write_atraces |= add_action_trace( bulk_action_traces, atrace, t, executed, now, write_ttrace ); } catch(...) { handle_mongo_exception("add action traces", __LINE__); } } if( !start_block_reached ) return; //< add_action_trace calls update_account which must be called always // transaction trace insert if( store_transaction_traces && write_ttrace ) { try { auto v = to_variant_with_abi( *t ); string json = fc::json::to_string( v, fc::time_point::maximum() ); try { const auto& value = bsoncxx::from_json( json ); trans_traces_doc.append( bsoncxx::builder::concatenate_doc{value.view()} ); } catch( bsoncxx::exception& ) { try { json = fc::prune_invalid_utf8( json ); const auto& value = bsoncxx::from_json( json ); trans_traces_doc.append( bsoncxx::builder::concatenate_doc{value.view()} ); trans_traces_doc.append( kvp( "non-utf8-purged", b_bool{true} ) ); } catch( bsoncxx::exception& e ) { elog( "Unable to convert transaction JSON to MongoDB JSON: ${e}", ("e", e.what()) ); elog( " JSON: ${j}", ("j", json) ); } } trans_traces_doc.append( kvp( "createdAt", b_date{now} ) ); try { if( !_trans_traces.insert_one( trans_traces_doc.view() ) ) { EOS_ASSERT( false, chain::mongo_db_insert_fail, "Failed to insert trans ${id}", ("id", t->id) ); } } catch( ... ) { handle_mongo_exception( "trans_traces insert: " + json, __LINE__ ); } } catch( ... ) { handle_mongo_exception( "trans_traces serialization: " + t->id.str(), __LINE__ ); } } // insert action_traces if( write_atraces ) { try { if( !bulk_action_traces.execute() ) { EOS_ASSERT( false, chain::mongo_db_insert_fail, "Bulk action traces insert failed for transaction trace: ${id}", ("id", t->id) ); } } catch( ... ) { handle_mongo_exception( "action traces insert", __LINE__ ); } } } void mongo_db_plugin_impl::_process_accepted_block( const chain::block_state_ptr& bs ) { using namespace bsoncxx::types; using namespace bsoncxx::builder; using bsoncxx::builder::basic::kvp; using bsoncxx::builder::basic::make_document; mongocxx::options::update update_opts{}; update_opts.upsert( true ); auto block_num = bs->block_num; if( block_num % 1000 == 0 ) ilog( "block_num: ${b}", ("b", block_num) ); const auto& block_id = bs->id; const auto block_id_str = block_id.str(); auto now = std::chrono::duration_cast<std::chrono::milliseconds>( std::chrono::microseconds{fc::time_point::now().time_since_epoch().count()}); if( store_block_states ) { auto block_state_doc = bsoncxx::builder::basic::document{}; block_state_doc.append( kvp( "block_num", b_int32{static_cast<int32_t>(block_num)} ), kvp( "block_id", block_id_str ), kvp( "validated", b_bool{bs->validated} ) ); const chain::block_header_state& bhs = *bs; auto json = fc::json::to_string( bhs, fc::time_point::maximum() ); try { const auto& value = bsoncxx::from_json( json ); block_state_doc.append( kvp( "block_header_state", value ) ); } catch( bsoncxx::exception& ) { try { json = fc::prune_invalid_utf8( json ); const auto& value = bsoncxx::from_json( json ); block_state_doc.append( kvp( "block_header_state", value ) ); block_state_doc.append( kvp( "non-utf8-purged", b_bool{true} ) ); } catch( bsoncxx::exception& e ) { elog( "Unable to convert block_header_state JSON to MongoDB JSON: ${e}", ("e", e.what()) ); elog( " JSON: ${j}", ("j", json) ); } } block_state_doc.append( kvp( "createdAt", b_date{now} ) ); try { if( update_blocks_via_block_num ) { if( !_block_states.update_one( make_document( kvp( "block_num", b_int32{static_cast<int32_t>(block_num)} ) ), make_document( kvp( "$set", block_state_doc.view() ) ), update_opts ) ) { EOS_ASSERT( false, chain::mongo_db_insert_fail, "Failed to insert block_state ${num}", ("num", block_num) ); } } else { if( !_block_states.update_one( make_document( kvp( "block_id", block_id_str ) ), make_document( kvp( "$set", block_state_doc.view() ) ), update_opts ) ) { EOS_ASSERT( false, chain::mongo_db_insert_fail, "Failed to insert block_state ${bid}", ("bid", block_id) ); } } } catch( ... ) { handle_mongo_exception( "block_states insert: " + json, __LINE__ ); } } if( store_blocks ) { auto block_doc = bsoncxx::builder::basic::document{}; block_doc.append( kvp( "block_num", b_int32{static_cast<int32_t>(block_num)} ), kvp( "block_id", block_id_str ) ); auto v = to_variant_with_abi( *bs->block ); auto json = fc::json::to_string( v, fc::time_point::maximum() ); try { const auto& value = bsoncxx::from_json( json ); block_doc.append( kvp( "block", value ) ); } catch( bsoncxx::exception& ) { try { json = fc::prune_invalid_utf8( json ); const auto& value = bsoncxx::from_json( json ); block_doc.append( kvp( "block", value ) ); block_doc.append( kvp( "non-utf8-purged", b_bool{true} ) ); } catch( bsoncxx::exception& e ) { elog( "Unable to convert block JSON to MongoDB JSON: ${e}", ("e", e.what()) ); elog( " JSON: ${j}", ("j", json) ); } } block_doc.append( kvp( "createdAt", b_date{now} ) ); try { if( update_blocks_via_block_num ) { if( !_blocks.update_one( make_document( kvp( "block_num", b_int32{static_cast<int32_t>(block_num)} ) ), make_document( kvp( "$set", block_doc.view() ) ), update_opts ) ) { EOS_ASSERT( false, chain::mongo_db_insert_fail, "Failed to insert block ${num}", ("num", block_num) ); } } else { if( !_blocks.update_one( make_document( kvp( "block_id", block_id_str ) ), make_document( kvp( "$set", block_doc.view() ) ), update_opts ) ) { EOS_ASSERT( false, chain::mongo_db_insert_fail, "Failed to insert block ${bid}", ("bid", block_id) ); } } } catch( ... ) { handle_mongo_exception( "blocks insert: " + json, __LINE__ ); } } } void mongo_db_plugin_impl::_process_irreversible_block(const chain::block_state_ptr& bs) { using namespace bsoncxx::types; using namespace bsoncxx::builder; using bsoncxx::builder::basic::make_document; using bsoncxx::builder::basic::kvp; const auto block_id = bs->block->id(); const auto block_id_str = block_id.str(); auto now = std::chrono::duration_cast<std::chrono::milliseconds>( std::chrono::microseconds{fc::time_point::now().time_since_epoch().count()}); if( store_blocks ) { auto ir_block = find_block( _blocks, block_id_str ); if( !ir_block ) { _process_accepted_block( bs ); ir_block = find_block( _blocks, block_id_str ); if( !ir_block ) return; // should never happen } auto update_doc = make_document( kvp( "$set", make_document( kvp( "irreversible", b_bool{true} ), kvp( "validated", b_bool{bs->validated} ), kvp( "updatedAt", b_date{now} ) ) ) ); _blocks.update_one( make_document( kvp( "_id", ir_block->view()["_id"].get_oid() ) ), update_doc.view() ); } if( store_block_states ) { auto ir_block = find_block( _block_states, block_id_str ); if( !ir_block ) { _process_accepted_block( bs ); ir_block = find_block( _block_states, block_id_str ); if( !ir_block ) return; // should never happen } auto update_doc = make_document( kvp( "$set", make_document( kvp( "irreversible", b_bool{true} ), kvp( "validated", b_bool{bs->validated} ), kvp( "updatedAt", b_date{now} ) ) ) ); _block_states.update_one( make_document( kvp( "_id", ir_block->view()["_id"].get_oid() ) ), update_doc.view() ); } if( store_transactions ) { const auto block_num = bs->block->block_num(); bool transactions_in_block = false; mongocxx::options::bulk_write bulk_opts; bulk_opts.ordered( false ); auto bulk = _trans.create_bulk_write( bulk_opts ); for( const auto& receipt : bs->block->transactions ) { string trx_id_str; if( receipt.trx.contains<packed_transaction>() ) { const auto& pt = receipt.trx.get<packed_transaction>(); if( !filter_include( pt.get_signed_transaction() ) ) continue; const auto& id = pt.id(); trx_id_str = id.str(); } else { const auto& id = receipt.trx.get<transaction_id_type>(); trx_id_str = id.str(); } auto update_doc = make_document( kvp( "$set", make_document( kvp( "irreversible", b_bool{true} ), kvp( "block_id", block_id_str ), kvp( "block_num", b_int32{static_cast<int32_t>(block_num)} ), kvp( "updatedAt", b_date{now} ) ) ) ); mongocxx::model::update_one update_op{make_document( kvp( "trx_id", trx_id_str ) ), update_doc.view()}; update_op.upsert( false ); bulk.append( update_op ); transactions_in_block = true; } if( transactions_in_block ) { try { if( !bulk.execute() ) { EOS_ASSERT( false, chain::mongo_db_insert_fail, "Bulk transaction insert failed for block: ${bid}", ("bid", block_id) ); } } catch( ... ) { handle_mongo_exception( "bulk transaction insert", __LINE__ ); } } } } void mongo_db_plugin_impl::add_pub_keys( const vector<chain::key_weight>& keys, const account_name& name, const permission_name& permission, const std::chrono::milliseconds& now ) { using bsoncxx::builder::basic::kvp; using bsoncxx::builder::basic::make_document; using namespace bsoncxx::types; if( keys.empty()) return; mongocxx::bulk_write bulk = _pub_keys.create_bulk_write(); for( const auto& pub_key_weight : keys ) { auto find_doc = bsoncxx::builder::basic::document(); find_doc.append( kvp( "account", name.to_string()), kvp( "public_key", pub_key_weight.key.operator string()), kvp( "permission", permission.to_string()) ); auto update_doc = make_document( kvp( "$set", make_document( bsoncxx::builder::concatenate_doc{find_doc.view()}, kvp( "createdAt", b_date{now} )))); mongocxx::model::update_one insert_op{find_doc.view(), update_doc.view()}; insert_op.upsert(true); bulk.append( insert_op ); } try { if( !bulk.execute()) { EOS_ASSERT( false, chain::mongo_db_insert_fail, "Bulk pub_keys insert failed for account: ${a}, permission: ${p}", ("a", name)( "p", permission )); } } catch (...) { handle_mongo_exception( "pub_keys insert", __LINE__ ); } } void mongo_db_plugin_impl::remove_pub_keys( const account_name& name, const permission_name& permission ) { using bsoncxx::builder::basic::kvp; using bsoncxx::builder::basic::make_document; try { auto result = _pub_keys.delete_many( make_document( kvp( "account", name.to_string()), kvp( "permission", permission.to_string()))); if( !result ) { EOS_ASSERT( false, chain::mongo_db_update_fail, "pub_keys delete failed for account: ${a}, permission: ${p}", ("a", name)( "p", permission )); } } catch (...) { handle_mongo_exception( "pub_keys delete", __LINE__ ); } } void mongo_db_plugin_impl::add_account_control( const vector<chain::permission_level_weight>& controlling_accounts, const account_name& name, const permission_name& permission, const std::chrono::milliseconds& now ) { using bsoncxx::builder::basic::kvp; using bsoncxx::builder::basic::make_document; using namespace bsoncxx::types; if( controlling_accounts.empty()) return; mongocxx::bulk_write bulk = _account_controls.create_bulk_write(); for( const auto& controlling_account : controlling_accounts ) { auto find_doc = bsoncxx::builder::basic::document(); find_doc.append( kvp( "controlled_account", name.to_string()), kvp( "controlled_permission", permission.to_string()), kvp( "controlling_account", controlling_account.permission.actor.to_string()) ); auto update_doc = make_document( kvp( "$set", make_document( bsoncxx::builder::concatenate_doc{find_doc.view()}, kvp( "createdAt", b_date{now} )))); mongocxx::model::update_one insert_op{find_doc.view(), update_doc.view()}; insert_op.upsert(true); bulk.append( insert_op ); } try { if( !bulk.execute()) { EOS_ASSERT( false, chain::mongo_db_insert_fail, "Bulk account_controls insert failed for account: ${a}, permission: ${p}", ("a", name)( "p", permission )); } } catch (...) { handle_mongo_exception( "account_controls insert", __LINE__ ); } } void mongo_db_plugin_impl::remove_account_control( const account_name& name, const permission_name& permission ) { using bsoncxx::builder::basic::kvp; using bsoncxx::builder::basic::make_document; try { auto result = _account_controls.delete_many( make_document( kvp( "controlled_account", name.to_string()), kvp( "controlled_permission", permission.to_string()))); if( !result ) { EOS_ASSERT( false, chain::mongo_db_update_fail, "account_controls delete failed for account: ${a}, permission: ${p}", ("a", name)( "p", permission )); } } catch (...) { handle_mongo_exception( "account_controls delete", __LINE__ ); } } namespace { void create_account( mongocxx::collection& accounts, const name& name, std::chrono::milliseconds& now ) { using namespace bsoncxx::types; using bsoncxx::builder::basic::kvp; using bsoncxx::builder::basic::make_document; mongocxx::options::update update_opts{}; update_opts.upsert( true ); const string name_str = name.to_string(); auto update = make_document( kvp( "$set", make_document( kvp( "name", name_str), kvp( "createdAt", b_date{now} )))); try { if( !accounts.update_one( make_document( kvp( "name", name_str )), update.view(), update_opts )) { EOS_ASSERT( false, chain::mongo_db_update_fail, "Failed to insert account ${n}", ("n", name)); } } catch (...) { handle_mongo_exception( "create_account", __LINE__ ); } } } void mongo_db_plugin_impl::update_account(const chain::action& act) { using bsoncxx::builder::basic::kvp; using bsoncxx::builder::basic::make_document; using namespace bsoncxx::types; if (act.account != chain::config::system_account_name) return; try { if( act.name == newaccount ) { std::chrono::milliseconds now = std::chrono::duration_cast<std::chrono::milliseconds>( std::chrono::microseconds{fc::time_point::now().time_since_epoch().count()} ); auto newacc = act.data_as<chain::newaccount>(); create_account( _accounts, newacc.name, now ); add_pub_keys( newacc.owner.keys, newacc.name, owner, now ); add_account_control( newacc.owner.accounts, newacc.name, owner, now ); add_pub_keys( newacc.active.keys, newacc.name, active, now ); add_account_control( newacc.active.accounts, newacc.name, active, now ); } else if( act.name == updateauth ) { auto now = std::chrono::duration_cast<std::chrono::milliseconds>( std::chrono::microseconds{fc::time_point::now().time_since_epoch().count()} ); const auto update = act.data_as<chain::updateauth>(); remove_pub_keys(update.account, update.permission); remove_account_control(update.account, update.permission); add_pub_keys(update.auth.keys, update.account, update.permission, now); add_account_control(update.auth.accounts, update.account, update.permission, now); } else if( act.name == deleteauth ) { const auto del = act.data_as<chain::deleteauth>(); remove_pub_keys( del.account, del.permission ); remove_account_control(del.account, del.permission); } else if( act.name == setabi ) { auto now = std::chrono::duration_cast<std::chrono::milliseconds>( std::chrono::microseconds{fc::time_point::now().time_since_epoch().count()} ); auto setabi = act.data_as<chain::setabi>(); abi_cache_index.erase( setabi.account ); auto account = find_account( _accounts, setabi.account ); if( !account ) { create_account( _accounts, setabi.account, now ); account = find_account( _accounts, setabi.account ); } if( account ) { abi_def abi_def = fc::raw::unpack<chain::abi_def>( setabi.abi ); const string json_str = fc::json::to_string( abi_def, fc::time_point::maximum() ); try{ auto update_from = make_document( kvp( "$set", make_document( kvp( "abi", bsoncxx::from_json( json_str )), kvp( "updatedAt", b_date{now} )))); try { if( !_accounts.update_one( make_document( kvp( "_id", account->view()["_id"].get_oid())), update_from.view())) { EOS_ASSERT( false, chain::mongo_db_update_fail, "Failed to udpdate account ${n}", ("n", setabi.account)); } } catch( ... ) { handle_mongo_exception( "account update", __LINE__ ); } } catch( bsoncxx::exception& e ) { elog( "Unable to convert abi JSON to MongoDB JSON: ${e}", ("e", e.what())); elog( " JSON: ${j}", ("j", json_str)); } } } } catch( fc::exception& e ) { // if unable to unpack native type, skip account creation } } mongo_db_plugin_impl::mongo_db_plugin_impl() { } mongo_db_plugin_impl::~mongo_db_plugin_impl() { if (!startup) { try { ilog( "mongo_db_plugin shutdown in process please be patient this can take a few minutes" ); done = true; condition.notify_one(); consume_thread.join(); mongo_pool.reset(); } catch( std::exception& e ) { elog( "Exception on mongo_db_plugin shutdown of consume thread: ${e}", ("e", e.what())); } } } void mongo_db_plugin_impl::wipe_database() { ilog("mongo db wipe_database"); auto client = mongo_pool->acquire(); auto& mongo_conn = *client; auto block_states = mongo_conn[db_name][block_states_col]; auto blocks = mongo_conn[db_name][blocks_col]; auto trans = mongo_conn[db_name][trans_col]; auto trans_traces = mongo_conn[db_name][trans_traces_col]; auto action_traces = mongo_conn[db_name][action_traces_col]; auto accounts = mongo_conn[db_name][accounts_col]; auto pub_keys = mongo_conn[db_name][pub_keys_col]; auto account_controls = mongo_conn[db_name][account_controls_col]; block_states.drop(); blocks.drop(); trans.drop(); trans_traces.drop(); action_traces.drop(); accounts.drop(); pub_keys.drop(); account_controls.drop(); ilog("done wipe_database"); } void mongo_db_plugin_impl::create_expiration_index(mongocxx::collection& collection, uint32_t expire_after_seconds) { using bsoncxx::builder::basic::make_document; using bsoncxx::builder::basic::kvp; auto indexes = collection.indexes(); for( auto& index : indexes.list()) { auto key = index["key"]; if( !key ) { continue; } auto field = key["createdAt"]; if( !field ) { continue; } auto ttl = index["expireAfterSeconds"]; if( ttl && ttl.get_int32() == expire_after_seconds ) { return; } else { auto name = index["name"].get_utf8(); ilog( "mongo db drop ttl index for collection ${collection}", ( "collection", collection.name().to_string())); indexes.drop_one( name.value ); break; } } mongocxx::options::index index_options{}; index_options.expire_after( std::chrono::seconds( expire_after_seconds )); index_options.background( true ); ilog( "mongo db create ttl index for collection ${collection}", ( "collection", collection.name().to_string())); collection.create_index( make_document( kvp( "createdAt", 1 )), index_options ); } void mongo_db_plugin_impl::init() { using namespace bsoncxx::types; using bsoncxx::builder::basic::make_document; using bsoncxx::builder::basic::kvp; // Create the native contract accounts manually; sadly, we can't run their contracts to make them create themselves // See native_contract_chain_initializer::prepare_database() ilog("init mongo"); try { auto client = mongo_pool->acquire(); auto& mongo_conn = *client; auto accounts = mongo_conn[db_name][accounts_col]; if( accounts.count( make_document()) == 0 ) { auto now = std::chrono::duration_cast<std::chrono::milliseconds>( std::chrono::microseconds{fc::time_point::now().time_since_epoch().count()} ); auto doc = make_document( kvp( "name", name( chain::config::system_account_name ).to_string()), kvp( "createdAt", b_date{now} )); try { if( !accounts.insert_one( doc.view())) { EOS_ASSERT( false, chain::mongo_db_insert_fail, "Failed to insert account ${n}", ("n", name( chain::config::system_account_name ).to_string())); } } catch (...) { handle_mongo_exception( "account insert", __LINE__ ); } try { // MongoDB administrators (to enable sharding) : // 1. enableSharding database (default to EOS) // 2. shardCollection: blocks, action_traces, transaction_traces, especially action_traces // 3. Compound index with shard key (default to _id below), to improve query performance. // blocks indexes auto blocks = mongo_conn[db_name][blocks_col]; blocks.create_index( bsoncxx::from_json( R"xxx({ "block_num" : 1, "_id" : 1 })xxx" )); blocks.create_index( bsoncxx::from_json( R"xxx({ "block_id" : 1, "_id" : 1 })xxx" )); auto block_states = mongo_conn[db_name][block_states_col]; block_states.create_index( bsoncxx::from_json( R"xxx({ "block_num" : 1, "_id" : 1 })xxx" )); block_states.create_index( bsoncxx::from_json( R"xxx({ "block_id" : 1, "_id" : 1 })xxx" )); // accounts indexes accounts.create_index( bsoncxx::from_json( R"xxx({ "name" : 1, "_id" : 1 })xxx" )); // transactions indexes auto trans = mongo_conn[db_name][trans_col]; trans.create_index( bsoncxx::from_json( R"xxx({ "trx_id" : 1, "_id" : 1 })xxx" )); auto trans_trace = mongo_conn[db_name][trans_traces_col]; trans_trace.create_index( bsoncxx::from_json( R"xxx({ "id" : 1, "_id" : 1 })xxx" )); // action traces indexes auto action_traces = mongo_conn[db_name][action_traces_col]; action_traces.create_index( bsoncxx::from_json( R"xxx({ "block_num" : 1, "_id" : 1 })xxx" )); // pub_keys indexes auto pub_keys = mongo_conn[db_name][pub_keys_col]; pub_keys.create_index( bsoncxx::from_json( R"xxx({ "account" : 1, "permission" : 1, "_id" : 1 })xxx" )); pub_keys.create_index( bsoncxx::from_json( R"xxx({ "public_key" : 1, "_id" : 1 })xxx" )); // account_controls indexes auto account_controls = mongo_conn[db_name][account_controls_col]; account_controls.create_index( bsoncxx::from_json( R"xxx({ "controlled_account" : 1, "controlled_permission" : 1, "_id" : 1 })xxx" )); account_controls.create_index( bsoncxx::from_json( R"xxx({ "controlling_account" : 1, "_id" : 1 })xxx" )); } catch (...) { handle_mongo_exception( "create indexes", __LINE__ ); } } if( expire_after_seconds > 0 ) { try { mongocxx::collection block_states = mongo_conn[db_name][block_states_col]; create_expiration_index( block_states, expire_after_seconds ); mongocxx::collection blocks = mongo_conn[db_name][blocks_col]; create_expiration_index( blocks, expire_after_seconds ); mongocxx::collection trans = mongo_conn[db_name][trans_col]; create_expiration_index( trans, expire_after_seconds ); mongocxx::collection trans_traces = mongo_conn[db_name][trans_traces_col]; create_expiration_index( trans_traces, expire_after_seconds ); mongocxx::collection action_traces = mongo_conn[db_name][action_traces_col]; create_expiration_index( action_traces, expire_after_seconds ); } catch(...) { handle_mongo_exception( "create expiration indexes", __LINE__ ); } } } catch (...) { handle_mongo_exception( "mongo init", __LINE__ ); } ilog("starting db plugin thread"); consume_thread = std::thread( [this] { fc::set_os_thread_name( "mongodb" ); consume_blocks(); } ); startup = false; } //////////// // mongo_db_plugin //////////// mongo_db_plugin::mongo_db_plugin() :my(new mongo_db_plugin_impl) { } mongo_db_plugin::~mongo_db_plugin() { } void mongo_db_plugin::set_program_options(options_description& cli, options_description& cfg) { cfg.add_options() ("mongodb-queue-size,q", bpo::value<uint32_t>()->default_value(1024), "The target queue size between nodeos and MongoDB plugin thread.") ("mongodb-abi-cache-size", bpo::value<uint32_t>()->default_value(2048), "The maximum size of the abi cache for serializing data.") ("mongodb-wipe", bpo::bool_switch()->default_value(false), "Required with --replay-blockchain, --hard-replay-blockchain, or --delete-all-blocks to wipe mongo db." "This option required to prevent accidental wipe of mongo db.") ("mongodb-block-start", bpo::value<uint32_t>()->default_value(0), "If specified then only abi data pushed to mongodb until specified block is reached.") ("mongodb-uri,m", bpo::value<std::string>(), "MongoDB URI connection string, see: https://docs.mongodb.com/master/reference/connection-string/." " If not specified then plugin is disabled. Default database 'EOS' is used if not specified in URI." " Example: mongodb://127.0.0.1:27017/EOS") ("mongodb-update-via-block-num", bpo::value<bool>()->default_value(false), "Update blocks/block_state with latest via block number so that duplicates are overwritten.") ("mongodb-store-blocks", bpo::value<bool>()->default_value(true), "Enables storing blocks in mongodb.") ("mongodb-store-block-states", bpo::value<bool>()->default_value(true), "Enables storing block state in mongodb.") ("mongodb-store-transactions", bpo::value<bool>()->default_value(true), "Enables storing transactions in mongodb.") ("mongodb-store-transaction-traces", bpo::value<bool>()->default_value(true), "Enables storing transaction traces in mongodb.") ("mongodb-store-action-traces", bpo::value<bool>()->default_value(true), "Enables storing action traces in mongodb.") ("mongodb-expire-after-seconds", bpo::value<uint32_t>()->default_value(0), "Enables expiring data in mongodb after a specified number of seconds.") ("mongodb-filter-on", bpo::value<vector<string>>()->composing(), "Track actions which match receiver:action:actor. Receiver, Action, & Actor may be blank to include all. i.e. eosio:: or :transfer: Use * or leave unspecified to include all.") ("mongodb-filter-out", bpo::value<vector<string>>()->composing(), "Do not track actions which match receiver:action:actor. Receiver, Action, & Actor may be blank to exclude all.") ; } void mongo_db_plugin::plugin_initialize(const variables_map& options) { try { if( options.count( "mongodb-uri" )) { ilog( "initializing mongo_db_plugin" ); my->configured = true; if( options.at( "replay-blockchain" ).as<bool>() || options.at( "hard-replay-blockchain" ).as<bool>() || options.at( "delete-all-blocks" ).as<bool>() ) { if( options.at( "mongodb-wipe" ).as<bool>()) { ilog( "Wiping mongo database on startup" ); my->wipe_database_on_startup = true; } else if( options.count( "mongodb-block-start" ) == 0 ) { EOS_ASSERT( false, chain::plugin_config_exception, "--mongodb-wipe required with --replay-blockchain, --hard-replay-blockchain, or --delete-all-blocks" " --mongodb-wipe will remove all EOS collections from mongodb." ); } } if( options.count( "abi-serializer-max-time-ms") == 0 ) { EOS_ASSERT(false, chain::plugin_config_exception, "--abi-serializer-max-time-ms required as default value not appropriate for parsing full blocks"); } my->abi_serializer_max_time = app().get_plugin<chain_plugin>().get_abi_serializer_max_time(); if( options.count( "mongodb-queue-size" )) { my->max_queue_size = options.at( "mongodb-queue-size" ).as<uint32_t>(); } if( options.count( "mongodb-abi-cache-size" )) { my->abi_cache_size = options.at( "mongodb-abi-cache-size" ).as<uint32_t>(); EOS_ASSERT( my->abi_cache_size > 0, chain::plugin_config_exception, "mongodb-abi-cache-size > 0 required" ); } if( options.count( "mongodb-block-start" )) { my->start_block_num = options.at( "mongodb-block-start" ).as<uint32_t>(); } if( options.count( "mongodb-update-via-block-num" )) { my->update_blocks_via_block_num = options.at( "mongodb-update-via-block-num" ).as<bool>(); } if( options.count( "mongodb-store-blocks" )) { my->store_blocks = options.at( "mongodb-store-blocks" ).as<bool>(); } if( options.count( "mongodb-store-block-states" )) { my->store_block_states = options.at( "mongodb-store-block-states" ).as<bool>(); } if( options.count( "mongodb-store-transactions" )) { my->store_transactions = options.at( "mongodb-store-transactions" ).as<bool>(); } if( options.count( "mongodb-store-transaction-traces" )) { my->store_transaction_traces = options.at( "mongodb-store-transaction-traces" ).as<bool>(); } if( options.count( "mongodb-store-action-traces" )) { my->store_action_traces = options.at( "mongodb-store-action-traces" ).as<bool>(); } if( options.count( "mongodb-expire-after-seconds" )) { my->expire_after_seconds = options.at( "mongodb-expire-after-seconds" ).as<uint32_t>(); } if( options.count( "mongodb-filter-on" )) { auto fo = options.at( "mongodb-filter-on" ).as<vector<string>>(); my->filter_on_star = false; for( auto& s : fo ) { if( s == "*" ) { my->filter_on_star = true; break; } std::vector<std::string> v; boost::split( v, s, boost::is_any_of( ":" )); EOS_ASSERT( v.size() == 3, fc::invalid_arg_exception, "Invalid value ${s} for --mongodb-filter-on", ("s", s)); filter_entry fe{v[0], v[1], v[2]}; my->filter_on.insert( fe ); } } else { my->filter_on_star = true; } if( options.count( "mongodb-filter-out" )) { auto fo = options.at( "mongodb-filter-out" ).as<vector<string>>(); for( auto& s : fo ) { std::vector<std::string> v; boost::split( v, s, boost::is_any_of( ":" )); EOS_ASSERT( v.size() == 3, fc::invalid_arg_exception, "Invalid value ${s} for --mongodb-filter-out", ("s", s)); filter_entry fe{v[0], v[1], v[2]}; my->filter_out.insert( fe ); } } if( options.count( "producer-name") ) { wlog( "mongodb plugin not recommended on producer node" ); my->is_producer = true; } if( my->start_block_num == 0 ) { my->start_block_reached = true; } std::string uri_str = options.at( "mongodb-uri" ).as<std::string>(); ilog( "connecting to ${u}", ("u", uri_str)); mongocxx::uri uri = mongocxx::uri{uri_str}; my->db_name = uri.database(); if( my->db_name.empty()) my->db_name = "EOS"; my->mongo_pool.emplace(uri); // hook up to signals on controller chain_plugin* chain_plug = app().find_plugin<chain_plugin>(); EOS_ASSERT( chain_plug, chain::missing_chain_plugin_exception, "" ); auto& chain = chain_plug->chain(); my->chain_id.emplace( chain.get_chain_id()); my->accepted_block_connection.emplace( chain.accepted_block.connect( [&]( const chain::block_state_ptr& bs ) { my->accepted_block( bs ); } )); my->irreversible_block_connection.emplace( chain.irreversible_block.connect( [&]( const chain::block_state_ptr& bs ) { my->applied_irreversible_block( bs ); } )); my->accepted_transaction_connection.emplace( chain.accepted_transaction.connect( [&]( const chain::transaction_metadata_ptr& t ) { my->accepted_transaction( t ); } )); my->applied_transaction_connection.emplace( chain.applied_transaction.connect( [&]( std::tuple<const chain::transaction_trace_ptr&, const chain::signed_transaction&> t ) { my->applied_transaction( std::get<0>(t) ); } )); if( my->wipe_database_on_startup ) { my->wipe_database(); } my->init(); } else { wlog( "eosio::mongo_db_plugin configured, but no --mongodb-uri specified." ); wlog( "mongo_db_plugin disabled." ); } } FC_LOG_AND_RETHROW() } void mongo_db_plugin::plugin_startup() { } void mongo_db_plugin::plugin_shutdown() { my->accepted_block_connection.reset(); my->irreversible_block_connection.reset(); my->accepted_transaction_connection.reset(); my->applied_transaction_connection.reset(); my.reset(); } } // namespace eosio
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; The MIT License ; ; Copyright (c) 2014 Intel Corporation ; ; Permission is hereby granted, free of charge, to any person ; obtaining a copy of this software and associated documentation ; files (the "Software"), to deal in the Software without ; restriction, including without limitation the rights to use, ; copy, modify, merge, publish, distribute, sublicense, and/or ; sell copies of the Software, and to permit persons to whom the ; Software is furnished to do so, subject to the following ; conditions: ; ; The above copyright notice and this permission notice shall be ; included in all copies or substantial portions of the ; Software. ; ; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY ; KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE ; WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR ; PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR ; COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR ; OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE ; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; %include "options.asm" %if (MAJOR_VERSION == IGZIP1C) %include "lz0a_const.asm" %include "data_struct2.asm" %include "bitbuf2.asm" %include "huffman.asm" %include "utils.asm" %include "hash.asm" %include "reg_sizes.asm" ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; %if 1 %define tmp1 rax %define f_indices rbx %define f_end_i rcx %define tmp_len rcx %define tmp3 rcx %define tmp4 rdx %define code_len2 rdx %define tmp5 rsi %define hash rdi %define tmp_dist rdi %define code rdi %define len rbp %define m_out_buf r8 %define m_bits r9 %define dist r10 %define m_bit_count r11 %define tmp2 r12 %define code2 r12 %define file_start r13 %define f_i r14 %define stream r15 %define tmp6 r15 %endif %define f_end_i_mem_offset 0 %define stream_mem_offset 8 %define stack_size 16 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; void fast_lz2_finish ( LZ_Stream2 *stream ) ; arg 1: rcx: addr of stream global fast_lz2_finish fast_lz2_finish: push rbx push rsi push rdi push rbp push r12 push r13 push r14 push r15 %ifdef LINUX mov rcx, rdi %endif sub rsp, stack_size mov stream, rcx ; state->bitbuf.set_buf(stream->next_out, stream->avail_out); mov m_out_buf, [stream + _next_out] mov [stream + _internal_state_bitbuf_m_out_start], m_out_buf mov tmp1 %+ d, [stream + _avail_out] add tmp1, m_out_buf sub tmp1, SLOP mov [stream + _internal_state_bitbuf_m_out_end], tmp1 mov m_bits, [stream + _internal_state_bitbuf_m_bits] mov m_bit_count %+ d, [stream + _internal_state_bitbuf_m_bit_count] ; f_i = state->b_bytes_processed; ; f_end_i = state->b_bytes_valid; mov f_i %+ d, [stream + _internal_state_b_bytes_processed] mov f_end_i %+ d, [stream + _internal_state_b_bytes_valid] ; f_i += (UINT32)(state->buffer - state->file_start); ; f_end_i += (UINT32)(state->buffer - state->file_start); mov file_start, [stream + _internal_state_file_start] lea tmp1, [stream + _internal_state_buffer] sub tmp1, file_start add f_i, tmp1 add f_end_i, tmp1 ; for (f_i = f_start_i; f_i < f_end_i; f_i++) { mov [rsp + f_end_i_mem_offset], f_end_i cmp f_i, f_end_i jge .end_loop_2 mov tmp1 %+ d, [file_start + f_i] .loop2: mov tmp5, f_i and tmp5, 0x000000000000FFFF ; if (state->bitbuf.is_full()) { cmp m_out_buf, [stream + _internal_state_bitbuf_m_out_end] ja .end_loop_2 ; hash = compute_hash(state->file_start + f_i) & HASH_MASK; compute_hash hash, tmp1, tmp2 and hash %+ d, HASH_MASK ; f_indices = state->head[hash]; mov f_indices, [stream + _internal_state_head + 8 * hash] ; state->head[hash] = (f_indices << 16) | (f_i & 0xFFFF); mov tmp1, f_indices shl tmp1, 16 or tmp1, tmp5 mov [stream + _internal_state_head + 8 * hash], tmp1 xor len, len ; tmp5 = (f_i + 0x8000) << (64-16) mov tmp5, f_i ; add tmp5, 0x8000 add tmp5, 0x7FFF shl tmp5, (64-16) ; logical start of .index_loop ; tmp_dist = (UINT16)(f_i - f_indices); // mod 64k mov tmp_dist %+ d, f_i %+ d sub tmp_dist %+ d, f_indices %+ d and tmp_dist %+ d, 0xFFFF ; if ((tmp_dist-1) < (D-1)) { // should this <=??? @@@ mov tmp1 %+ d, tmp_dist %+ d sub tmp1 %+ d, 1 cmp tmp1 %+ d, (D-1) ja .end_index_loop mov [rsp + stream_mem_offset], stream .index_loop: ; f_indices >>= 16; ; f_indices |= ((UINT64)(f_i + 0x8000)) << (64-16); shr f_indices, 16 or f_indices, tmp5 ; tmp_len = f_end_i - f_i; mov tmp4, [rsp + f_end_i_mem_offset] sub tmp4, f_i ; if (tmp_len > 258) tmp_len = 258; cmp tmp4, 258 cmovg tmp4, [c258 wrt rip] ; tmp_len = compare(state->file_start + f_i, ; state->file_start + f_i - tmp_dist, tmp_len); lea tmp1, [file_start + f_i] mov tmp2, tmp1 sub tmp2, tmp_dist compare tmp4, tmp1, tmp2, tmp_len, tmp6 ; if (tmp_len > len) ; len = tmp_len; ; dist = tmp_dist; cmp tmp_len, len cmova len, tmp_len cmova dist, tmp_dist ;; duplicate start of loop above ; tmp_dist = (UINT16)(f_i - f_indices); // mod 64k mov tmp_dist %+ d, f_i %+ d sub tmp_dist %+ d, f_indices %+ d and tmp_dist %+ d, 0xFFFF ; if ((tmp_dist-1) < (D-1)) { // should this <=??? @@@ mov tmp1 %+ d, tmp_dist %+ d sub tmp1 %+ d, 1 cmp tmp1 %+ d, (D-1) jbe .index_loop mov stream, [rsp + stream_mem_offset] .end_index_loop: ; if (len >= SHORTEST_MATCH) { cmp len, SHORTEST_MATCH jb .encode_literal ;; encode as dist/len ; get_dist_code(dist, &code2, &code_len2); get_dist_code dist, code2, code_len2 ;; clobbers dist, rcx ; get_len_code(len, &code, &code_len); get_len_code len, code, rcx ;; rcx is code_len ; code2 <<= code_len ; code2 |= code ; code_len2 += code_len %ifdef USE_HSWNI shlx code2, code2, rcx %else shl code2, cl %endif or code2, code add code_len2, rcx ; for (k = f_i+1, f_i += len-1; k <= f_i; k++) { lea tmp3, [f_i + 1] ; tmp3 <= k add f_i, len .loop3: mov tmp5, tmp3 and tmp5, 0x000000000000FFFF ; hash = compute_hash(state->file_start + k) & HASH_MASK; mov tmp1 %+ d, [file_start + tmp3] compute_hash hash, tmp1, tmp2 and hash %+ d, HASH_MASK ; state->head[hash] = (f_indices << 16) | (k & 0xFFFF); mov tmp1, f_indices shl tmp1, 16 or tmp1 , tmp5 mov [stream + _internal_state_head + 8 * hash], tmp1 inc tmp3 cmp tmp3, f_i jl .loop3 mov tmp1 %+ d, [file_start + f_i] %ifdef USE_BITBUF8 write_bits_safe m_bits, m_bit_count, code2, code_len2, m_out_buf, tmp5 %elifdef USE_BITBUFB write_bits_always m_bits, m_bit_count, code2, code_len2, m_out_buf, tmp5 %else ; state->bitbuf.check_space(code_len2); check_space code_len2, m_bits, m_bit_count, m_out_buf, tmp5 ; state->bitbuf.write_bits(code2, code_len2); write_bits m_bits, m_bit_count, code2, code_len2 ; code2 is clobbered, rcx is clobbered %endif ; continue cmp f_i, [rsp + f_end_i_mem_offset] jl .loop2 jmp .end_loop_2 .encode_literal: mov tmp1 %+ d, [file_start + f_i + 1] ; get_lit_code(state->file_start[f_i], &code2, &code_len2); movzx tmp5, byte [file_start + f_i] get_lit_code tmp5, code2, code_len2 add f_i, 1 %ifdef USE_BITBUF8 write_bits_safe m_bits, m_bit_count, code2, code_len2, m_out_buf, tmp5 %elifdef USE_BITBUFB write_bits_always m_bits, m_bit_count, code2, code_len2, m_out_buf, tmp5 %else ; state->bitbuf.check_space(code_len2); check_space code_len2, m_bits, m_bit_count, m_out_buf, tmp5 ; state->bitbuf.write_bits(code2, code_len2); write_bits m_bits, m_bit_count, code2, code_len2 ; code2 is clobbered, rcx is clobbered %endif ; continue cmp f_i, [rsp + f_end_i_mem_offset] jl .loop2 .end_loop_2: ; if ((f_i >= f_end_i) && ! state->bitbuf.is_full()) { cmp f_i, [rsp + f_end_i_mem_offset] jl .not_end cmp m_out_buf, [stream + _internal_state_bitbuf_m_out_end] ja .not_end ; get_lit_code(256, &code2, &code_len2); get_lit_code_const 256, code2, code_len2 %ifdef USE_BITBUF8 write_bits_safe m_bits, m_bit_count, code2, code_len2, m_out_buf, tmp1 %elifdef USE_BITBUFB write_bits_always m_bits, m_bit_count, code2, code_len2, m_out_buf, tmp1 %else ; state->bitbuf.check_space(code_len2); check_space code_len2, m_bits, m_bit_count, m_out_buf, tmp1 ; state->bitbuf.write_bits(code2, code_len2); write_bits m_bits, m_bit_count, code2, code_len2 ; code2 is clobbered, rcx is clobbered %endif ; state->state = LZS2_TRL; mov dword [stream + _internal_state_state], LZS2_TRL ; } .not_end: ; state->b_bytes_processed = f_i - (state->buffer - state->file_start); add f_i, [stream + _internal_state_file_start] sub f_i, stream sub f_i, _internal_state_buffer mov [stream + _internal_state_b_bytes_processed], f_i %+ d ; // update output buffer ; stream->next_out = state->bitbuf.buffer_ptr(); mov [stream + _next_out], m_out_buf ; len = state->bitbuf.buffer_used(); sub m_out_buf, [stream + _internal_state_bitbuf_m_out_start] ; stream->avail_out -= len; sub [stream + _avail_out], m_out_buf %+ d ; stream->total_out += len; add [stream + _total_out], m_out_buf %+ d mov [stream + _internal_state_bitbuf_m_bits], m_bits mov [stream + _internal_state_bitbuf_m_bit_count], m_bit_count %+ d add rsp, stack_size pop r15 pop r14 pop r13 pop r12 pop rbp pop rdi pop rsi pop rbx ret section .data align 8 c258: dq 258 %endif ;; if (MAJOR_VERSION == IGZIP1C)
; ######################################################################### .386 .model flat, stdcall option casemap :none ; case sensitive ; ######################################################################### include \masm32\include\windows.inc include \masm32\include\user32.inc include \masm32\include\kernel32.inc include \masm32\include\gdi32.inc include \masm32\include\masm32.inc includelib \masm32\lib\user32.lib includelib \masm32\lib\kernel32.lib includelib \masm32\lib\gdi32.lib includelib \masm32\lib\masm32.lib ; ######################################################################### ;============= ; Local macros ;============= szText MACRO Name, Text:VARARG LOCAL lbl jmp lbl Name db Text,0 lbl: ENDM ;================= ; Local prototypes ;================= WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD .data hEdit1 dd 0 hEdit2 dd 0 hEdit3 dd 0 hEdit4 dd 0 hButn1 dd 0 hButn2 dd 0 hInstance dd 0 hIconImage dd 0 hIcon dd 0 dlgname db "TESTWIN",0 ; ######################################################################### .code start: invoke GetModuleHandle, NULL mov hInstance, eax ; ------------------------------------------- ; Call the dialog box stored in resource file ; ------------------------------------------- invoke DialogBoxParam,hInstance,ADDR dlgname,0,ADDR WndProc,0 invoke ExitProcess,eax ; ######################################################################### WndProc proc hWin :DWORD, uMsg :DWORD, wParam :DWORD, lParam :DWORD LOCAL Ps :PAINTSTRUCT .if uMsg == WM_INITDIALOG szText dlgTitle," Demo dialog box" invoke SendMessage,hWin,WM_SETTEXT,0,ADDR dlgTitle invoke LoadIcon,hInstance,200 mov hIcon, eax invoke SendMessage,hWin,WM_SETICON,1,hIcon invoke GetDlgItem,hWin,100 mov hEdit1, eax invoke GetDlgItem,hWin,101 mov hEdit2, eax invoke GetDlgItem,hWin,102 mov hEdit3, eax invoke GetDlgItem,hWin,103 mov hEdit4, eax invoke GetDlgItem,hWin,1000 mov hButn1, eax invoke GetDlgItem,hWin,1001 mov hButn2, eax xor eax, eax ret .elseif uMsg == WM_COMMAND .if wParam == 1000 szText calcMsg,"Calculate Button" invoke MessageBox,hWin,ADDR calcMsg, ADDR dlgTitle,MB_OK .elseif wParam == 1001 szText clearMsg,"Clear Button" invoke MessageBox,hWin,ADDR clearMsg, ADDR dlgTitle,MB_OK .endif .elseif uMsg == WM_CLOSE invoke EndDialog,hWin,0 .elseif uMsg == WM_PAINT invoke BeginPaint,hWin,ADDR Ps ; ---------------------------------------- ; The following function are in MASM32.LIB ; ---------------------------------------- invoke FrameGrp,hButn1,hButn2,6,1,0 invoke FrameGrp,hEdit1,hEdit3,4,1,0 invoke FrameCtrl,hEdit4,4,1,0 invoke FrameWindow,hWin,0,1,1 invoke FrameWindow,hWin,1,1,0 invoke EndPaint,hWin,ADDR Ps xor eax, eax ret .endif xor eax, eax ; this must be here in NT4 ret WndProc endp ; ######################################################################## end start
; A094951: a(n) = A081038(n) + A077616(n). ; 6,31,144,621,2538,9963,37908,140697,511758,1830519,6456024,22497669,77590386,265189059,899198172,3027619377,10130328342,33705582543,111577100832,367662044061,1206427402746,3943553157531,12845313733284,41705428220361,135001318437918,435788774790183,1403109937237608,4506728113627317 mov $2,$0 mov $3,1 add $3,$0 mov $0,$3 mov $1,$2 add $2,$3 lpb $0,1 sub $0,1 add $1,4 add $2,2 mul $1,$2 mov $2,1 lpe sub $1,12 div $1,3 add $1,6
; DRAW OR SPRITE 2 BYTE DEFINITION ROTATED ; 01.2006 aralbrec, Sprite Pack v3.0 ; sinclair spectrum version INCLUDE "clib_target_cfg.asm" SECTION code_clib SECTION code_temp_sp1 PUBLIC _SP1_DRAW_OR2 EXTERN _SP1_DRAW_OR2NR EXTERN SP1RETSPRDRAW ; following data segment copied into struct sp1_cs ld hl,0 ld ix,0 call _SP1_DRAW_OR2 ; following draw code called by way of SP1UpdateNow ; ; a = hor rot table ; bc = graphic disp ; hl = graphic def ptr (mask,graph) pairs ; ix = left graphic def ptr ; ; 51 + 178*4 - 6 + 10 = 767 cycles _SP1_DRAW_OR2: cp SP1V_ROTTBL/256 jp z, _SP1_DRAW_OR2NR add hl,bc add ix,bc ex de,hl ld h,a ; h = shift table ; de = sprite def (mask,graph) pairs ; ix = left sprite def _SP1Or2Rotate: ; 0 ld bc,(SP1V_PIXELBUFFER+0) inc de ld a,(de) inc de ld l,a ld a,(hl) inc h ld l,(ix+1) or (hl) or c ld (SP1V_PIXELBUFFER+0),a ld l,(ix+3) ld c,(hl) dec h inc de ld a,(de) inc de ld l,a ld a,c or b or (hl) ld (SP1V_PIXELBUFFER+1),a ; 1 ld bc,(SP1V_PIXELBUFFER+2) inc de ld a,(de) inc de ld l,a ld a,(hl) inc h ld l,(ix+5) or (hl) or c ld (SP1V_PIXELBUFFER+2),a ld l,(ix+7) ld c,(hl) dec h inc de ld a,(de) inc de ld l,a ld a,c or b or (hl) ld (SP1V_PIXELBUFFER+3),a ; 2 ld bc,(SP1V_PIXELBUFFER+4) inc de ld a,(de) inc de ld l,a ld a,(hl) inc h ld l,(ix+9) or (hl) or c ld (SP1V_PIXELBUFFER+4),a ld l,(ix+11) ld c,(hl) dec h inc de ld a,(de) inc de ld l,a ld a,c or b or (hl) ld (SP1V_PIXELBUFFER+5),a ; 3 ld bc,(SP1V_PIXELBUFFER+6) inc de ld a,(de) inc de ld l,a ld a,(hl) inc h ld l,(ix+13) or (hl) or c ld (SP1V_PIXELBUFFER+6),a ld l,(ix+15) ld c,(hl) dec h inc de ld a,(de) ld l,a ld a,c or b or (hl) ld (SP1V_PIXELBUFFER+7),a jp SP1RETSPRDRAW
; A156024: n(n+1)/2 - A156022(n) ; 0,1,2,4,6,9,12,15,19,23,27,32,37,42,48,54,60,66,73,80,87,94,101,109,117,125,133,142,151,160,169 mov $2,$0 mov $3,$0 lpb $2 mov $0,$3 sub $2,1 sub $0,$2 mov $4,$0 mul $0,4 add $0,$4 add $0,5 mul $0,2 div $4,2 add $4,18 div $0,$4 add $1,$0 lpe
; int __CALLEE__ strspn_callee(char *s1, char *s2) ; return length of prefix in s1 containing chars in s2 ; 01.2007 aralbrec PUBLIC strspn_callee PUBLIC ASMDISP_STRSPN_CALLEE EXTERN strchr_callee EXTERN ASMDISP_STRCHR_CALLEE .strspn_callee pop hl pop de ex (sp),hl ; enter : de = char *s2 ; hl = char *s1 ; exit : hl = prefix length ; uses : af, bc, hl .asmentry ld bc,0 .loop ld a,(hl) or a jr z, done push bc push hl ld c,a ld l,e ld h,d call strchr_callee + ASMDISP_STRCHR_CALLEE pop hl pop bc jr c, done inc bc inc hl jp loop .done ld l,c ld h,b ret DEFC ASMDISP_STRSPN_CALLEE = # asmentry - strspn_callee
/home/arnold/pulp-sdk/pkg/pulp_riscv_gcc/1.0.13/bin/riscv32-unknown-elf-objdump -Mmarch=rv32imfcxpulpv2 /home/arnold/PULP-DSP/test/mrWolf/mat_mul/test_fct/singlecore_riscy/build/wolfe/test/test -d /home/arnold/PULP-DSP/test/mrWolf/mat_mul/test_fct/singlecore_riscy/build/wolfe/test/test: file format elf32-littleriscv Disassembly of section .vectors: 1c008000 <__irq_vector_base>: 1c008000: 0940006f j 1c008094 <__rt_no_irq_handler> 1c008004: 0900006f j 1c008094 <__rt_no_irq_handler> 1c008008: 08c0006f j 1c008094 <__rt_no_irq_handler> 1c00800c: 0880006f j 1c008094 <__rt_no_irq_handler> 1c008010: 0840006f j 1c008094 <__rt_no_irq_handler> 1c008014: 0800006f j 1c008094 <__rt_no_irq_handler> 1c008018: 07c0006f j 1c008094 <__rt_no_irq_handler> 1c00801c: 0780006f j 1c008094 <__rt_no_irq_handler> 1c008020: 0740006f j 1c008094 <__rt_no_irq_handler> 1c008024: 0700006f j 1c008094 <__rt_no_irq_handler> 1c008028: 06c0006f j 1c008094 <__rt_no_irq_handler> 1c00802c: 0680006f j 1c008094 <__rt_no_irq_handler> 1c008030: 0640006f j 1c008094 <__rt_no_irq_handler> 1c008034: 0600006f j 1c008094 <__rt_no_irq_handler> 1c008038: 05c0006f j 1c008094 <__rt_no_irq_handler> 1c00803c: 0580006f j 1c008094 <__rt_no_irq_handler> 1c008040: 0540006f j 1c008094 <__rt_no_irq_handler> 1c008044: 0500006f j 1c008094 <__rt_no_irq_handler> 1c008048: 04c0006f j 1c008094 <__rt_no_irq_handler> 1c00804c: 0480006f j 1c008094 <__rt_no_irq_handler> 1c008050: 0440006f j 1c008094 <__rt_no_irq_handler> 1c008054: 0400006f j 1c008094 <__rt_no_irq_handler> 1c008058: 03c0006f j 1c008094 <__rt_no_irq_handler> 1c00805c: 0380006f j 1c008094 <__rt_no_irq_handler> 1c008060: 0340006f j 1c008094 <__rt_no_irq_handler> 1c008064: 0300006f j 1c008094 <__rt_no_irq_handler> 1c008068: 02c0006f j 1c008094 <__rt_no_irq_handler> 1c00806c: 0280006f j 1c008094 <__rt_no_irq_handler> 1c008070: 0240006f j 1c008094 <__rt_no_irq_handler> 1c008074: 0200006f j 1c008094 <__rt_no_irq_handler> 1c008078: 01c0006f j 1c008094 <__rt_no_irq_handler> 1c00807c: 0180006f j 1c008094 <__rt_no_irq_handler> 1c008080 <_start>: 1c008080: 0200006f j 1c0080a0 <_entry> 1c008084: 1ce0006f j 1c008252 <__rt_illegal_instr> ... 1c008090 <__rt_debug_struct_ptr>: 1c008090: 0fdc addi a5,sp,980 1c008092: 1c00 addi s0,sp,560 1c008094 <__rt_no_irq_handler>: 1c008094: 0000006f j 1c008094 <__rt_no_irq_handler> 1c008098 <__rt_semihosting_call>: 1c008098: 00100073 ebreak 1c00809c: 00008067 ret Disassembly of section .text: 1c0080a0 <_entry>: 1c0080a0: 7a101073 csrw pcmr,zero 1c0080a4: f1402573 csrr a0,mhartid 1c0080a8: 01f57593 andi a1,a0,31 1c0080ac: 8115 srli a0,a0,0x5 1c0080ae: 467d li a2,31 1c0080b0: 00c50463 beq a0,a2,1c0080b8 <_entry+0x18> 1c0080b4: 74d0706f j 1c010000 <__cluster_text_start> 1c0080b8: ffff9297 auipc t0,0xffff9 1c0080bc: ff028293 addi t0,t0,-16 # 1c0010a8 <_bss_start> 1c0080c0: ffff9317 auipc t1,0xffff9 1c0080c4: 14430313 addi t1,t1,324 # 1c001204 <__l2_priv0_end> 1c0080c8: 0002a023 sw zero,0(t0) 1c0080cc: 0291 addi t0,t0,4 1c0080ce: fe62ede3 bltu t0,t1,1c0080c8 <_entry+0x28> 1c0080d2: ffff9117 auipc sp,0xffff9 1c0080d6: dee10113 addi sp,sp,-530 # 1c000ec0 <stack> 1c0080da: 284010ef jal ra,1c00935e <__rt_init> 1c0080de: 00000513 li a0,0 1c0080e2: 00000593 li a1,0 1c0080e6: 00001397 auipc t2,0x1 1c0080ea: a6438393 addi t2,t2,-1436 # 1c008b4a <main> 1c0080ee: 000380e7 jalr t2 1c0080f2: 842a mv s0,a0 1c0080f4: 3de010ef jal ra,1c0094d2 <__rt_deinit> 1c0080f8: 8522 mv a0,s0 1c0080fa: 027020ef jal ra,1c00a920 <exit> 1c0080fe <_fini>: 1c0080fe: 8082 ret 1c008100 <__rt_event_enqueue>: 1c008100: 0035f513 andi a0,a1,3 1c008104: 02051c63 bnez a0,1c00813c <__rt_handle_special_event> 1c008108: e3ff8517 auipc a0,0xe3ff8 1c00810c: f2050513 addi a0,a0,-224 # 28 <__rt_sched> 1c008110: 0005ac23 sw zero,24(a1) 1c008114: 4110 lw a2,0(a0) 1c008116: c601 beqz a2,1c00811e <__rt_no_first> 1c008118: 4150 lw a2,4(a0) 1c00811a: ce0c sw a1,24(a2) 1c00811c: a011 j 1c008120 <__rt_common> 1c00811e <__rt_no_first>: 1c00811e: c10c sw a1,0(a0) 1c008120 <__rt_common>: 1c008120: c14c sw a1,4(a0) 1c008122: 4550 lw a2,12(a0) 1c008124: 00052623 sw zero,12(a0) 1c008128: ca01 beqz a2,1c008138 <enqueue_end> 1c00812a: e3ff8517 auipc a0,0xe3ff8 1c00812e: ef650513 addi a0,a0,-266 # 20 <__rt_thread_current> 1c008132: 4108 lw a0,0(a0) 1c008134: 00c51363 bne a0,a2,1c00813a <thread_enqueue> 1c008138 <enqueue_end>: 1c008138: 8482 jr s1 1c00813a <thread_enqueue>: 1c00813a: 8482 jr s1 1c00813c <__rt_handle_special_event>: 1c00813c: 5571 li a0,-4 1c00813e: 8de9 and a1,a1,a0 1c008140: 4190 lw a2,0(a1) 1c008142: 41c8 lw a0,4(a1) 1c008144: a0e1 j 1c00820c <__rt_call_external_c_function> 1c008146 <__rt_bridge_enqueue_event>: 1c008146: fe812e23 sw s0,-4(sp) 1c00814a: fe912c23 sw s1,-8(sp) 1c00814e: fea12a23 sw a0,-12(sp) 1c008152: feb12823 sw a1,-16(sp) 1c008156: fec12623 sw a2,-20(sp) 1c00815a: 00001617 auipc a2,0x1 1c00815e: 73460613 addi a2,a2,1844 # 1c00988e <__rt_bridge_handle_notif> 1c008162: 0aa004ef jal s1,1c00820c <__rt_call_external_c_function> 1c008166: ffc12403 lw s0,-4(sp) 1c00816a: ff812483 lw s1,-8(sp) 1c00816e: ff412503 lw a0,-12(sp) 1c008172: ff012583 lw a1,-16(sp) 1c008176: fec12603 lw a2,-20(sp) 1c00817a: 30200073 mret 1c00817e <__rt_remote_enqueue_event>: 1c00817e: fe812e23 sw s0,-4(sp) 1c008182: fe912c23 sw s1,-8(sp) 1c008186: fea12a23 sw a0,-12(sp) 1c00818a: feb12823 sw a1,-16(sp) 1c00818e: fec12623 sw a2,-20(sp) 1c008192: 4405 li s0,1 1c008194: ffff9497 auipc s1,0xffff9 1c008198: 03448493 addi s1,s1,52 # 1c0011c8 <__rt_fc_cluster_data> 1c00819c <__rt_remote_enqueue_event_loop_cluster>: 1c00819c: 40cc lw a1,4(s1) 1c00819e: 02058d63 beqz a1,1c0081d8 <__rt_remote_enqueue_event_loop_cluster_continue> 1c0081a2: 48cc lw a1,20(s1) 1c0081a4: 41c8 lw a0,4(a1) 1c0081a6: 00050e63 beqz a0,1c0081c2 <__rt_cluster_pool_update_end> 1c0081aa <__rt_cluster_pool_update_loop>: 1c0081aa: 5150 lw a2,36(a0) 1c0081ac: e219 bnez a2,1c0081b2 <__rt_cluster_pool_update_loop_end> 1c0081ae: 5108 lw a0,32(a0) 1c0081b0: fd6d bnez a0,1c0081aa <__rt_cluster_pool_update_loop> 1c0081b2 <__rt_cluster_pool_update_loop_end>: 1c0081b2: c501 beqz a0,1c0081ba <__rt_cluster_pool_update_no_current> 1c0081b4: 5108 lw a0,32(a0) 1c0081b6: c1c8 sw a0,4(a1) 1c0081b8: a029 j 1c0081c2 <__rt_cluster_pool_update_end> 1c0081ba <__rt_cluster_pool_update_no_current>: 1c0081ba: 0005a223 sw zero,4(a1) 1c0081be: 0005a423 sw zero,8(a1) 1c0081c2 <__rt_cluster_pool_update_end>: 1c0081c2: 40cc lw a1,4(s1) 1c0081c4: 4890 lw a2,16(s1) 1c0081c6: 0004a223 sw zero,4(s1) 1c0081ca: 00062023 sw zero,0(a2) 1c0081ce: 00000497 auipc s1,0x0 1c0081d2: 00a48493 addi s1,s1,10 # 1c0081d8 <__rt_remote_enqueue_event_loop_cluster_continue> 1c0081d6: b72d j 1c008100 <__rt_event_enqueue> 1c0081d8 <__rt_remote_enqueue_event_loop_cluster_continue>: 1c0081d8: 147d addi s0,s0,-1 1c0081da: 00804e63 bgtz s0,1c0081f6 <__rt_remote_enqueue_event_loop_next_cluster> 1c0081de: ffc12403 lw s0,-4(sp) 1c0081e2: ff812483 lw s1,-8(sp) 1c0081e6: ff412503 lw a0,-12(sp) 1c0081ea: ff012583 lw a1,-16(sp) 1c0081ee: fec12603 lw a2,-20(sp) 1c0081f2: 30200073 mret 1c0081f6 <__rt_remote_enqueue_event_loop_next_cluster>: 1c0081f6: ffff9497 auipc s1,0xffff9 1c0081fa: fd248493 addi s1,s1,-46 # 1c0011c8 <__rt_fc_cluster_data> 1c0081fe: 4084 lw s1,0(s1) 1c008200: 02800593 li a1,40 1c008204: 02b405b3 mul a1,s0,a1 1c008208: 94ae add s1,s1,a1 1c00820a: bf49 j 1c00819c <__rt_remote_enqueue_event_loop_cluster> 1c00820c <__rt_call_external_c_function>: 1c00820c: 7119 addi sp,sp,-128 1c00820e: c006 sw ra,0(sp) 1c008210: c20e sw gp,4(sp) 1c008212: c412 sw tp,8(sp) 1c008214: c616 sw t0,12(sp) 1c008216: c81a sw t1,16(sp) 1c008218: ca1e sw t2,20(sp) 1c00821a: d236 sw a3,36(sp) 1c00821c: d43a sw a4,40(sp) 1c00821e: d63e sw a5,44(sp) 1c008220: d842 sw a6,48(sp) 1c008222: da46 sw a7,52(sp) 1c008224: dc72 sw t3,56(sp) 1c008226: de76 sw t4,60(sp) 1c008228: c0fa sw t5,64(sp) 1c00822a: c6fe sw t6,76(sp) 1c00822c: 000600e7 jalr a2 1c008230: 4082 lw ra,0(sp) 1c008232: 4192 lw gp,4(sp) 1c008234: 4222 lw tp,8(sp) 1c008236: 42b2 lw t0,12(sp) 1c008238: 4342 lw t1,16(sp) 1c00823a: 43d2 lw t2,20(sp) 1c00823c: 5692 lw a3,36(sp) 1c00823e: 5722 lw a4,40(sp) 1c008240: 57b2 lw a5,44(sp) 1c008242: 5842 lw a6,48(sp) 1c008244: 58d2 lw a7,52(sp) 1c008246: 5e62 lw t3,56(sp) 1c008248: 5ef2 lw t4,60(sp) 1c00824a: 4f06 lw t5,64(sp) 1c00824c: 4fb6 lw t6,76(sp) 1c00824e: 6109 addi sp,sp,128 1c008250: 8482 jr s1 1c008252 <__rt_illegal_instr>: 1c008252: fe112e23 sw ra,-4(sp) 1c008256: fea12c23 sw a0,-8(sp) 1c00825a: 00001517 auipc a0,0x1 1c00825e: 30850513 addi a0,a0,776 # 1c009562 <__rt_handle_illegal_instr> 1c008262: 010000ef jal ra,1c008272 <__rt_call_c_function> 1c008266: ffc12083 lw ra,-4(sp) 1c00826a: ff812503 lw a0,-8(sp) 1c00826e: 30200073 mret 1c008272 <__rt_call_c_function>: 1c008272: 7119 addi sp,sp,-128 1c008274: c006 sw ra,0(sp) 1c008276: c20e sw gp,4(sp) 1c008278: c412 sw tp,8(sp) 1c00827a: c616 sw t0,12(sp) 1c00827c: c81a sw t1,16(sp) 1c00827e: ca1e sw t2,20(sp) 1c008280: ce2e sw a1,28(sp) 1c008282: d032 sw a2,32(sp) 1c008284: d236 sw a3,36(sp) 1c008286: d43a sw a4,40(sp) 1c008288: d63e sw a5,44(sp) 1c00828a: d842 sw a6,48(sp) 1c00828c: da46 sw a7,52(sp) 1c00828e: dc72 sw t3,56(sp) 1c008290: de76 sw t4,60(sp) 1c008292: c0fa sw t5,64(sp) 1c008294: c6fe sw t6,76(sp) 1c008296: 000500e7 jalr a0 1c00829a: 4082 lw ra,0(sp) 1c00829c: 4192 lw gp,4(sp) 1c00829e: 4222 lw tp,8(sp) 1c0082a0: 42b2 lw t0,12(sp) 1c0082a2: 4342 lw t1,16(sp) 1c0082a4: 43d2 lw t2,20(sp) 1c0082a6: 45f2 lw a1,28(sp) 1c0082a8: 5602 lw a2,32(sp) 1c0082aa: 5692 lw a3,36(sp) 1c0082ac: 5722 lw a4,40(sp) 1c0082ae: 57b2 lw a5,44(sp) 1c0082b0: 5842 lw a6,48(sp) 1c0082b2: 58d2 lw a7,52(sp) 1c0082b4: 5e62 lw t3,56(sp) 1c0082b6: 5ef2 lw t4,60(sp) 1c0082b8: 4f06 lw t5,64(sp) 1c0082ba: 4fb6 lw t6,76(sp) 1c0082bc: 6109 addi sp,sp,128 1c0082be: 8082 ret 1c0082c0 <__rt_thread_start>: 1c0082c0: 8526 mv a0,s1 1c0082c2: 80ca mv ra,s2 1c0082c4: 8402 jr s0 1c0082c6 <__rt_thread_switch>: 1c0082c6: 00152023 sw ra,0(a0) 1c0082ca: c140 sw s0,4(a0) 1c0082cc: c504 sw s1,8(a0) 1c0082ce: 01252623 sw s2,12(a0) 1c0082d2: 01352823 sw s3,16(a0) 1c0082d6: 01452a23 sw s4,20(a0) 1c0082da: 01552c23 sw s5,24(a0) 1c0082de: 01652e23 sw s6,28(a0) 1c0082e2: 03752023 sw s7,32(a0) 1c0082e6: 03852223 sw s8,36(a0) 1c0082ea: 03952423 sw s9,40(a0) 1c0082ee: 03a52623 sw s10,44(a0) 1c0082f2: 03b52823 sw s11,48(a0) 1c0082f6: 02252a23 sw sp,52(a0) 1c0082fa: 0005a083 lw ra,0(a1) 1c0082fe: 41c0 lw s0,4(a1) 1c008300: 4584 lw s1,8(a1) 1c008302: 00c5a903 lw s2,12(a1) 1c008306: 0105a983 lw s3,16(a1) 1c00830a: 0145aa03 lw s4,20(a1) 1c00830e: 0185aa83 lw s5,24(a1) 1c008312: 01c5ab03 lw s6,28(a1) 1c008316: 0205ab83 lw s7,32(a1) 1c00831a: 0245ac03 lw s8,36(a1) 1c00831e: 0285ac83 lw s9,40(a1) 1c008322: 02c5ad03 lw s10,44(a1) 1c008326: 0305ad83 lw s11,48(a1) 1c00832a: 0345a103 lw sp,52(a1) 1c00832e: 8082 ret 1c008330 <__rt_fc_socevents_handler>: 1c008330: 7119 addi sp,sp,-128 1c008332: c022 sw s0,0(sp) 1c008334: c226 sw s1,4(sp) 1c008336: c42a sw a0,8(sp) 1c008338: c62e sw a1,12(sp) 1c00833a: c832 sw a2,16(sp) 1c00833c: 1a10a437 lui s0,0x1a10a 1c008340: 80040413 addi s0,s0,-2048 # 1a109800 <__l1_end+0xa1061ec> 1c008344: 5048 lw a0,36(s0) 1c008346: 44bd li s1,15 1c008348: 00955c63 ble s1,a0,1c008360 <__rt_soc_evt_no_udma_channel> 1c00834c: e3ff8417 auipc s0,0xe3ff8 1c008350: cf440413 addi s0,s0,-780 # 40 <periph_channels> 1c008354: 00551493 slli s1,a0,0x5 1c008358: 94a2 add s1,s1,s0 1c00835a: 4ccc lw a1,28(s1) 1c00835c: 4080 lw s0,0(s1) 1c00835e: 8582 jr a1 1c008360 <__rt_soc_evt_no_udma_channel>: 1c008360: 44f9 li s1,30 1c008362: 00955863 ble s1,a0,1c008372 <__rt_soc_evt_no_udma> 1c008366: fea50593 addi a1,a0,-22 1c00836a: 058a slli a1,a1,0x2 1c00836c: 2485a583 lw a1,584(a1) 1c008370: 8582 jr a1 1c008372 <__rt_soc_evt_no_udma>: 1c008372: e3ff8497 auipc s1,0xe3ff8 1c008376: ece48493 addi s1,s1,-306 # 240 <__rt_socevents_status> 1c00837a: 02000593 li a1,32 1c00837e: 00b54463 blt a0,a1,1c008386 <socevents_set> 1c008382: 0491 addi s1,s1,4 1c008384: 1501 addi a0,a0,-32 1c008386 <socevents_set>: 1c008386: 408c lw a1,0(s1) 1c008388: 4405 li s0,1 1c00838a: 00a41533 sll a0,s0,a0 1c00838e: 00a5e633 or a2,a1,a0 1c008392: c090 sw a2,0(s1) 1c008394 <udma_event_handler_end>: 1c008394: 4402 lw s0,0(sp) 1c008396: 4492 lw s1,4(sp) 1c008398: 4522 lw a0,8(sp) 1c00839a: 45b2 lw a1,12(sp) 1c00839c: 4642 lw a2,16(sp) 1c00839e: 6109 addi sp,sp,128 1c0083a0: 30200073 mret 1c0083a4 <udma_event_handler>: 1c0083a4: 4080 lw s0,0(s1) 1c0083a6: 448c lw a1,8(s1) 1c0083a8: 0a040363 beqz s0,1c00844e <__rt_udma_no_copy> 1c0083ac: 4c50 lw a2,28(s0) 1c0083ae: 4848 lw a0,20(s0) 1c0083b0: 06061263 bnez a2,1c008414 <dmaCmd> 1c0083b4: c088 sw a0,0(s1) 1c0083b6: 4448 lw a0,12(s0) 1c0083b8: e55d bnez a0,1c008466 <handle_special_end> 1c0083ba <resume_after_special_end>: 1c0083ba: 04058263 beqz a1,1c0083fe <checkTask> 1c0083be: 4990 lw a2,16(a1) 1c0083c0: 49c8 lw a0,20(a1) 1c0083c2: c611 beqz a2,1c0083ce <__rt_udma_call_enqueue_callback_resume> 1c0083c4: 00000497 auipc s1,0x0 1c0083c8: 00a48493 addi s1,s1,10 # 1c0083ce <__rt_udma_call_enqueue_callback_resume> 1c0083cc: 8602 jr a2 1c0083ce <__rt_udma_call_enqueue_callback_resume>: 1c0083ce: 44d0 lw a2,12(s1) 1c0083d0: c488 sw a0,8(s1) 1c0083d2: 4188 lw a0,0(a1) 1c0083d4: 41c4 lw s1,4(a1) 1c0083d6: c208 sw a0,0(a2) 1c0083d8: c244 sw s1,4(a2) 1c0083da: 45c4 lw s1,12(a1) 1c0083dc: 88bd andi s1,s1,15 1c0083de: 4515 li a0,5 1c0083e0: 00a4cd63 blt s1,a0,1c0083fa <transfer_resume> 1c0083e4: 4519 li a0,6 1c0083e6: 00a48563 beq s1,a0,1c0083f0 <dual> 1c0083ea: 451d li a0,7 1c0083ec: 00a48263 beq s1,a0,1c0083f0 <dual> 1c0083f0 <dual>: 1c0083f0: 553d li a0,-17 1c0083f2: 00a674b3 and s1,a2,a0 1c0083f6: 51c8 lw a0,36(a1) 1c0083f8: d088 sw a0,32(s1) 1c0083fa <transfer_resume>: 1c0083fa: 4588 lw a0,8(a1) 1c0083fc: c608 sw a0,8(a2) 1c0083fe <checkTask>: 1c0083fe: 4c0c lw a1,24(s0) 1c008400: 00000497 auipc s1,0x0 1c008404: f9448493 addi s1,s1,-108 # 1c008394 <udma_event_handler_end> 1c008408: 00058463 beqz a1,1c008410 <checkTask+0x12> 1c00840c: cf5ff06f j 1c008100 <__rt_event_enqueue> 1c008410: f85ff06f j 1c008394 <udma_event_handler_end> 1c008414 <dmaCmd>: 1c008414: 44cc lw a1,12(s1) 1c008416: 553d li a0,-17 1c008418: 00a5f4b3 and s1,a1,a0 1c00841c: 5048 lw a0,36(s0) 1c00841e: 9532 add a0,a0,a2 1c008420: d088 sw a0,32(s1) 1c008422: d048 sw a0,36(s0) 1c008424: 4008 lw a0,0(s0) 1c008426: 5004 lw s1,32(s0) 1c008428: 9532 add a0,a0,a2 1c00842a: 8c91 sub s1,s1,a2 1c00842c: 00964963 blt a2,s1,1c00843e <not_last> 1c008430: 8626 mv a2,s1 1c008432: 00042e23 sw zero,28(s0) 1c008436: 00061463 bnez a2,1c00843e <not_last> 1c00843a: f5bff06f j 1c008394 <udma_event_handler_end> 1c00843e <not_last>: 1c00843e: c008 sw a0,0(s0) 1c008440: d004 sw s1,32(s0) 1c008442: c188 sw a0,0(a1) 1c008444: c1d0 sw a2,4(a1) 1c008446: 4541 li a0,16 1c008448: c588 sw a0,8(a1) 1c00844a: f4bff06f j 1c008394 <udma_event_handler_end> 1c00844e <__rt_udma_no_copy>: 1c00844e: e3ff8497 auipc s1,0xe3ff8 1c008452: df248493 addi s1,s1,-526 # 240 <__rt_socevents_status> 1c008456: 4080 lw s0,0(s1) 1c008458: 4585 li a1,1 1c00845a: 00a59533 sll a0,a1,a0 1c00845e: 8c49 or s0,s0,a0 1c008460: c080 sw s0,0(s1) 1c008462: f33ff06f j 1c008394 <udma_event_handler_end> 1c008466 <handle_special_end>: 1c008466: 460d li a2,3 1c008468: 04c50663 beq a0,a2,1c0084b4 <i2c_step1> 1c00846c: 4611 li a2,4 1c00846e: 06c50163 beq a0,a2,1c0084d0 <i2c_step2> 1c008472: b7a1 j 1c0083ba <resume_after_special_end> 1c008474 <spim_step3>: 1c008474: 5408 lw a0,40(s0) 1c008476: c448 sw a0,12(s0) 1c008478: 4088 lw a0,0(s1) 1c00847a: c848 sw a0,20(s0) 1c00847c: c080 sw s0,0(s1) 1c00847e: 44d0 lw a2,12(s1) 1c008480: 5448 lw a0,44(s0) 1c008482: c208 sw a0,0(a2) 1c008484: 5048 lw a0,36(s0) 1c008486: c248 sw a0,4(a2) 1c008488: 4408 lw a0,8(s0) 1c00848a: c608 sw a0,8(a2) 1c00848c: f09ff06f j 1c008394 <udma_event_handler_end> 1c008490 <spim_step2>: 1c008490: 00042623 sw zero,12(s0) 1c008494: 4088 lw a0,0(s1) 1c008496: c848 sw a0,20(s0) 1c008498: c080 sw s0,0(s1) 1c00849a: 90000637 lui a2,0x90000 1c00849e: c070 sw a2,68(s0) 1c0084a0: 44d0 lw a2,12(s1) 1c0084a2: 04440513 addi a0,s0,68 1c0084a6: c208 sw a0,0(a2) 1c0084a8: 4511 li a0,4 1c0084aa: c248 sw a0,4(a2) 1c0084ac: 4541 li a0,16 1c0084ae: c608 sw a0,8(a2) 1c0084b0: ee5ff06f j 1c008394 <udma_event_handler_end> 1c0084b4 <i2c_step1>: 1c0084b4: 5408 lw a0,40(s0) 1c0084b6: c448 sw a0,12(s0) 1c0084b8: 4088 lw a0,0(s1) 1c0084ba: c848 sw a0,20(s0) 1c0084bc: c080 sw s0,0(s1) 1c0084be: 44d0 lw a2,12(s1) 1c0084c0: 4008 lw a0,0(s0) 1c0084c2: c208 sw a0,0(a2) 1c0084c4: 5048 lw a0,36(s0) 1c0084c6: c248 sw a0,4(a2) 1c0084c8: 4408 lw a0,8(s0) 1c0084ca: c608 sw a0,8(a2) 1c0084cc: ec9ff06f j 1c008394 <udma_event_handler_end> 1c0084d0 <i2c_step2>: 1c0084d0: 00042623 sw zero,12(s0) 1c0084d4: 4088 lw a0,0(s1) 1c0084d6: c848 sw a0,20(s0) 1c0084d8: c080 sw s0,0(s1) 1c0084da: 02000613 li a2,32 1c0084de: c070 sw a2,68(s0) 1c0084e0: 44d0 lw a2,12(s1) 1c0084e2: 04440513 addi a0,s0,68 1c0084e6: c208 sw a0,0(a2) 1c0084e8: 4505 li a0,1 1c0084ea: c248 sw a0,4(a2) 1c0084ec: 4541 li a0,16 1c0084ee: c608 sw a0,8(a2) 1c0084f0: ea5ff06f j 1c008394 <udma_event_handler_end> 1c0084f4 <__clzsi2>: 1c0084f4: 67c1 lui a5,0x10 1c0084f6: 02f57663 bleu a5,a0,1c008522 <__clzsi2+0x2e> 1c0084fa: 0ff00793 li a5,255 1c0084fe: 00a7b7b3 sltu a5,a5,a0 1c008502: 078e slli a5,a5,0x3 1c008504: 02000713 li a4,32 1c008508: 8f1d sub a4,a4,a5 1c00850a: 00f557b3 srl a5,a0,a5 1c00850e: 1c000537 lui a0,0x1c000 1c008512: 2ec50513 addi a0,a0,748 # 1c0002ec <__DTOR_END__> 1c008516: 97aa add a5,a5,a0 1c008518: 0007c503 lbu a0,0(a5) # 10000 <__l1_heap_size+0x3614> 1c00851c: 40a70533 sub a0,a4,a0 1c008520: 8082 ret 1c008522: 01000737 lui a4,0x1000 1c008526: 47c1 li a5,16 1c008528: fce56ee3 bltu a0,a4,1c008504 <__clzsi2+0x10> 1c00852c: 47e1 li a5,24 1c00852e: bfd9 j 1c008504 <__clzsi2+0x10> 1c008530 <cluster_entry>: 1c008530: 7159 addi sp,sp,-112 1c008532: d4a2 sw s0,104(sp) 1c008534: f1402673 csrr a2,mhartid 1c008538: 40565413 srai s0,a2,0x5 1c00853c: f2643433 p.bclr s0,s0,25,6 1c008540: 1c000537 lui a0,0x1c000 1c008544: 85a2 mv a1,s0 1c008546: f4563633 p.bclr a2,a2,26,5 1c00854a: 3ec50513 addi a0,a0,1004 # 1c0003ec <__DTOR_END__+0x100> 1c00854e: d686 sw ra,108(sp) 1c008550: d2a6 sw s1,100(sp) 1c008552: d0ca sw s2,96(sp) 1c008554: cece sw s3,92(sp) 1c008556: ccd2 sw s4,88(sp) 1c008558: cad6 sw s5,84(sp) 1c00855a: 464020ef jal ra,1c00a9be <printf> 1c00855e: 0028 addi a0,sp,8 1c008560: 5c7000ef jal ra,1c009326 <rt_perf_init> 1c008564: 6589 lui a1,0x2 1c008566: 40058593 addi a1,a1,1024 # 2400 <__rt_hyper_pending_emu_stride+0x2158> 1c00856a: 450d li a0,3 1c00856c: 257d jal 1c008c1a <rt_alloc> 1c00856e: 1a050463 beqz a0,1c008716 <cluster_entry+0x1e6> 1c008572: 84aa mv s1,a0 1c008574: 1c000537 lui a0,0x1c000 1c008578: 42450513 addi a0,a0,1060 # 1c000424 <__DTOR_END__+0x138> 1c00857c: 342020ef jal ra,1c00a8be <puts> 1c008580: 65e1 lui a1,0x18 1c008582: 0599 addi a1,a1,6 1c008584: 0028 addi a0,sp,8 1c008586: 5b5000ef jal ra,1c00933a <rt_perf_conf> 1c00858a: 47fd li a5,31 1c00858c: 14f40163 beq s0,a5,1c0086ce <cluster_entry+0x19e> 1c008590: 102007b7 lui a5,0x10200 1c008594: 4705 li a4,1 1c008596: 40078793 addi a5,a5,1024 # 10200400 <__l1_end+0x1fcdec> 1c00859a: 02e7a023 sw a4,32(a5) 1c00859e: 4781 li a5,0 1c0085a0: 79f79073 csrw pccr31,a5 1c0085a4: f14027f3 csrr a5,mhartid 1c0085a8: 477d li a4,31 1c0085aa: ca5797b3 p.extractu a5,a5,5,5 1c0085ae: 12e78f63 beq a5,a4,1c0086ec <cluster_entry+0x1bc> 1c0085b2: 102007b7 lui a5,0x10200 1c0085b6: 4705 li a4,1 1c0085b8: 40078793 addi a5,a5,1024 # 10200400 <__l1_end+0x1fcdec> 1c0085bc: 00e7ac23 sw a4,24(a5) 1c0085c0: 478d li a5,3 1c0085c2: 7a179073 csrw pcmr,a5 1c0085c6: 100025b7 lui a1,0x10002 1c0085ca: 10003537 lui a0,0x10003 1c0085ce: 87a6 mv a5,s1 1c0085d0: 03000713 li a4,48 1c0085d4: 03000693 li a3,48 1c0085d8: 03000613 li a2,48 1c0085dc: 41458593 addi a1,a1,1044 # 10002414 <m_b> 1c0085e0: d1450513 addi a0,a0,-748 # 10002d14 <m_a> 1c0085e4: 2a81 jal 1c008734 <plp_mat_mult_i8s_xpulpv2> 1c0085e6: 477d li a4,31 1c0085e8: f14027f3 csrr a5,mhartid 1c0085ec: ca5797b3 p.extractu a5,a5,5,5 1c0085f0: 12e78a63 beq a5,a4,1c008724 <cluster_entry+0x1f4> 1c0085f4: 102007b7 lui a5,0x10200 1c0085f8: 40078793 addi a5,a5,1024 # 10200400 <__l1_end+0x1fcdec> 1c0085fc: 0007a023 sw zero,0(a5) 1c008600: 4781 li a5,0 1c008602: 7a179073 csrw pcmr,a5 1c008606: 10000937 lui s2,0x10000 1c00860a: 6985 lui s3,0x1 1c00860c: 01490913 addi s2,s2,20 # 10000014 <m_c> 1c008610: 4a81 li s5,0 1c008612: 4401 li s0,0 1c008614: 1c000a37 lui s4,0x1c000 1c008618: 90098993 addi s3,s3,-1792 # 900 <__rt_hyper_pending_emu_stride+0x658> 1c00861c: 0044a80b p.lw a6,4(s1!) 1c008620: 0049270b p.lw a4,4(s2!) 1c008624: 85a2 mv a1,s0 1c008626: 8642 mv a2,a6 1c008628: 0405 addi s0,s0,1 1c00862a: 86ba mv a3,a4 1c00862c: 43ca0513 addi a0,s4,1084 # 1c00043c <__DTOR_END__+0x150> 1c008630: 00e80563 beq a6,a4,1c00863a <cluster_entry+0x10a> 1c008634: 38a020ef jal ra,1c00a9be <printf> 1c008638: 0a85 addi s5,s5,1 1c00863a: ff3411e3 bne s0,s3,1c00861c <cluster_entry+0xec> 1c00863e: 0c0a8563 beqz s5,1c008708 <cluster_entry+0x1d8> 1c008642: 1c000537 lui a0,0x1c000 1c008646: 85d6 mv a1,s5 1c008648: 48850513 addi a0,a0,1160 # 1c000488 <__DTOR_END__+0x19c> 1c00864c: 372020ef jal ra,1c00a9be <printf> 1c008650: f14027f3 csrr a5,mhartid 1c008654: 477d li a4,31 1c008656: ca5797b3 p.extractu a5,a5,5,5 1c00865a: 0ae78263 beq a5,a4,1c0086fe <cluster_entry+0x1ce> 1c00865e: 102005b7 lui a1,0x10200 1c008662: 40058593 addi a1,a1,1024 # 10200400 <__l1_end+0x1fcdec> 1c008666: 0085a583 lw a1,8(a1) 1c00866a: 78102973 csrr s2,pccr1 1c00866e: 782024f3 csrr s1,pccr2 1c008672: 78f02473 csrr s0,pccr15 1c008676: 1c000537 lui a0,0x1c000 1c00867a: 49c50513 addi a0,a0,1180 # 1c00049c <__DTOR_END__+0x1b0> 1c00867e: 340020ef jal ra,1c00a9be <printf> 1c008682: 1c000537 lui a0,0x1c000 1c008686: 85ca mv a1,s2 1c008688: 4b050513 addi a0,a0,1200 # 1c0004b0 <__DTOR_END__+0x1c4> 1c00868c: 332020ef jal ra,1c00a9be <printf> 1c008690: 1c000537 lui a0,0x1c000 1c008694: 85a6 mv a1,s1 1c008696: 4c450513 addi a0,a0,1220 # 1c0004c4 <__DTOR_END__+0x1d8> 1c00869a: 324020ef jal ra,1c00a9be <printf> 1c00869e: 1c000537 lui a0,0x1c000 1c0086a2: 85a2 mv a1,s0 1c0086a4: 4d450513 addi a0,a0,1236 # 1c0004d4 <__DTOR_END__+0x1e8> 1c0086a8: 316020ef jal ra,1c00a9be <printf> 1c0086ac: 1c000537 lui a0,0x1c000 1c0086b0: 000365b7 lui a1,0x36 1c0086b4: 4e450513 addi a0,a0,1252 # 1c0004e4 <__DTOR_END__+0x1f8> 1c0086b8: 306020ef jal ra,1c00a9be <printf> 1c0086bc: 50b6 lw ra,108(sp) 1c0086be: 5426 lw s0,104(sp) 1c0086c0: 5496 lw s1,100(sp) 1c0086c2: 5906 lw s2,96(sp) 1c0086c4: 49f6 lw s3,92(sp) 1c0086c6: 4a66 lw s4,88(sp) 1c0086c8: 4ad6 lw s5,84(sp) 1c0086ca: 6165 addi sp,sp,112 1c0086cc: 8082 ret 1c0086ce: 4785 li a5,1 1c0086d0: 1a10b737 lui a4,0x1a10b 1c0086d4: 02f72023 sw a5,32(a4) # 1a10b020 <__l1_end+0xa107a0c> 1c0086d8: 4781 li a5,0 1c0086da: 79f79073 csrw pccr31,a5 1c0086de: f14027f3 csrr a5,mhartid 1c0086e2: 477d li a4,31 1c0086e4: ca5797b3 p.extractu a5,a5,5,5 1c0086e8: ece795e3 bne a5,a4,1c0085b2 <cluster_entry+0x82> 1c0086ec: 4785 li a5,1 1c0086ee: 1a10b737 lui a4,0x1a10b 1c0086f2: 00f72c23 sw a5,24(a4) # 1a10b018 <__l1_end+0xa107a04> 1c0086f6: 478d li a5,3 1c0086f8: 7a179073 csrw pcmr,a5 1c0086fc: b5e9 j 1c0085c6 <cluster_entry+0x96> 1c0086fe: 1a10b5b7 lui a1,0x1a10b 1c008702: 0085a583 lw a1,8(a1) # 1a10b008 <__l1_end+0xa1079f4> 1c008706: b795 j 1c00866a <cluster_entry+0x13a> 1c008708: 1c000537 lui a0,0x1c000 1c00870c: 47450513 addi a0,a0,1140 # 1c000474 <__DTOR_END__+0x188> 1c008710: 1ae020ef jal ra,1c00a8be <puts> 1c008714: bf35 j 1c008650 <cluster_entry+0x120> 1c008716: 1c000537 lui a0,0x1c000 1c00871a: 41050513 addi a0,a0,1040 # 1c000410 <__DTOR_END__+0x124> 1c00871e: 1a0020ef jal ra,1c00a8be <puts> 1c008722: b73d j 1c008650 <cluster_entry+0x120> 1c008724: 1a10b7b7 lui a5,0x1a10b 1c008728: 0007a023 sw zero,0(a5) # 1a10b000 <__l1_end+0xa1079ec> 1c00872c: 4781 li a5,0 1c00872e: 7a179073 csrw pcmr,a5 1c008732: bdd1 j 1c008606 <cluster_entry+0xd6> 1c008734 <plp_mat_mult_i8s_xpulpv2>: 1c008734: 7175 addi sp,sp,-144 1c008736: 00165293 srli t0,a2,0x1 1c00873a: c722 sw s0,140(sp) 1c00873c: c526 sw s1,136(sp) 1c00873e: c34a sw s2,132(sp) 1c008740: c14e sw s3,128(sp) 1c008742: ded2 sw s4,124(sp) 1c008744: dcd6 sw s5,120(sp) 1c008746: dada sw s6,116(sp) 1c008748: d8de sw s7,112(sp) 1c00874a: d6e2 sw s8,108(sp) 1c00874c: d4e6 sw s9,104(sp) 1c00874e: d2ea sw s10,100(sp) 1c008750: d0ee sw s11,96(sp) 1c008752: c8b2 sw a2,80(sp) 1c008754: dc16 sw t0,56(sp) 1c008756: de2a sw a0,60(sp) 1c008758: da2e sw a1,52(sp) 1c00875a: d036 sw a3,32(sp) 1c00875c: ca3a sw a4,20(sp) 1c00875e: ccbe sw a5,88(sp) 1c008760: 3c028b63 beqz t0,1c008b36 <plp_mat_mult_i8s_xpulpv2+0x402> 1c008764: 00275313 srli t1,a4,0x2 1c008768: 863e mv a2,a5 1c00876a: 00231793 slli a5,t1,0x2 1c00876e: 97ae add a5,a5,a1 1c008770: cebe sw a5,92(sp) 1c008772: 1c0007b7 lui a5,0x1c000 1c008776: 4f47ad03 lw s10,1268(a5) # 1c0004f4 <__DTOR_END__+0x208> 1c00877a: 1c0007b7 lui a5,0x1c000 1c00877e: 0026d393 srli t2,a3,0x2 1c008782: 4f87ac83 lw s9,1272(a5) # 1c0004f8 <__DTOR_END__+0x20c> 1c008786: 1c0007b7 lui a5,0x1c000 1c00878a: 84ba mv s1,a4 1c00878c: 89b6 mv s3,a3 1c00878e: 82ba mv t0,a4 1c008790: 4fc7ac03 lw s8,1276(a5) # 1c0004fc <__DTOR_END__+0x210> 1c008794: 00239713 slli a4,t2,0x2 1c008798: 048e slli s1,s1,0x3 1c00879a: 0686 slli a3,a3,0x1 1c00879c: 99aa add s3,s3,a0 1c00879e: 972a add a4,a4,a0 1c0087a0: c69a sw t1,76(sp) 1c0087a2: d41e sw t2,40(sp) 1c0087a4: caa6 sw s1,84(sp) 1c0087a6: c0b2 sw a2,64(sp) 1c0087a8: c2b6 sw a3,68(sp) 1c0087aa: d22a sw a0,36(sp) 1c0087ac: d84e sw s3,48(sp) 1c0087ae: d63a sw a4,44(sp) 1c0087b0: 00229d93 slli s11,t0,0x2 1c0087b4: c482 sw zero,72(sp) 1c0087b6: 42b6 lw t0,76(sp) 1c0087b8: 1e028963 beqz t0,1c0089aa <plp_mat_mult_i8s_xpulpv2+0x276> 1c0087bc: 53d2 lw t2,52(sp) 1c0087be: 4376 lw t1,92(sp) 1c0087c0: 4486 lw s1,64(sp) 1c0087c2: 4606 lw a2,64(sp) 1c0087c4: 407307b3 sub a5,t1,t2 1c0087c8: 17f1 addi a5,a5,-4 1c0087ca: 8389 srli a5,a5,0x2 1c0087cc: 94ee add s1,s1,s11 1c0087ce: 0785 addi a5,a5,1 1c0087d0: c626 sw s1,12(sp) 1c0087d2: cc1e sw t2,24(sp) 1c0087d4: c832 sw a2,16(sp) 1c0087d6: ce3e sw a5,28(sp) 1c0087d8: 59a2 lw s3,40(sp) 1c0087da: 1a098e63 beqz s3,1c008996 <plp_mat_mult_i8s_xpulpv2+0x262> 1c0087de: 5392 lw t2,36(sp) 1c0087e0: 5332 lw t1,44(sp) 1c0087e2: 44d2 lw s1,20(sp) 1c0087e4: 4662 lw a2,24(sp) 1c0087e6: 40730533 sub a0,t1,t2 1c0087ea: 1571 addi a0,a0,-4 1c0087ec: 00c489b3 add s3,s1,a2 1c0087f0: 5ac2 lw s5,48(sp) 1c0087f2: 01348933 add s2,s1,s3 1c0087f6: 8109 srli a0,a0,0x2 1c0087f8: 00990bb3 add s7,s2,s1 1c0087fc: 8a1e mv s4,t2 1c0087fe: 8b32 mv s6,a2 1c008800: 4481 li s1,0 1c008802: 4401 li s0,0 1c008804: 4381 li t2,0 1c008806: 4281 li t0,0 1c008808: 4f81 li t6,0 1c00880a: 4f01 li t5,0 1c00880c: 4e81 li t4,0 1c00880e: 4e01 li t3,0 1c008810: 0505 addi a0,a0,1 1c008812: 036540fb lp.setup x1,a0,1c00887e <plp_mat_mult_i8s_xpulpv2+0x14a> 1c008816: 21bb768b p.lw a3,s11(s6!) 1c00881a: 21b9f30b p.lw t1,s11(s3!) 1c00881e: 21b9758b p.lw a1,s11(s2!) 1c008822: 8636 mv a2,a3 1c008824: c9a31657 pv.shuffle2.b a2,t1,s10 1c008828: c99316d7 pv.shuffle2.b a3,t1,s9 1c00882c: 1c000337 lui t1,0x1c000 1c008830: 21bbf88b p.lw a7,s11(s7!) 1c008834: 50030313 addi t1,t1,1280 # 1c000500 <__DTOR_END__+0x214> 1c008838: 00032303 lw t1,0(t1) 1c00883c: 882e mv a6,a1 1c00883e: 004a270b p.lw a4,4(s4!) 1c008842: 004aa78b p.lw a5,4(s5!) 1c008846: c9a89857 pv.shuffle2.b a6,a7,s10 1c00884a: c99895d7 pv.shuffle2.b a1,a7,s9 1c00884e: 88b2 mv a7,a2 1c008850: c98818d7 pv.shuffle2.b a7,a6,s8 1c008854: c8681657 pv.shuffle2.b a2,a6,t1 1c008858: 8836 mv a6,a3 1c00885a: c9859857 pv.shuffle2.b a6,a1,s8 1c00885e: c86596d7 pv.shuffle2.b a3,a1,t1 1c008862: b9171e57 pv.sdotsp.b t3,a4,a7 1c008866: b8c71ed7 pv.sdotsp.b t4,a4,a2 1c00886a: b9071f57 pv.sdotsp.b t5,a4,a6 1c00886e: b8d71fd7 pv.sdotsp.b t6,a4,a3 1c008872: b91792d7 pv.sdotsp.b t0,a5,a7 1c008876: b8c793d7 pv.sdotsp.b t2,a5,a2 1c00887a: b9079457 pv.sdotsp.b s0,a5,a6 1c00887e: b8d794d7 pv.sdotsp.b s1,a5,a3 1c008882: 5822 lw a6,40(sp) 1c008884: 4642 lw a2,16(sp) 1c008886: 46b2 lw a3,12(sp) 1c008888: 4762 lw a4,24(sp) 1c00888a: 47f2 lw a5,28(sp) 1c00888c: 01c62023 sw t3,0(a2) # 90000000 <pulp__FC+0x90000001> 1c008890: 01d62223 sw t4,4(a2) 1c008894: 01e62423 sw t5,8(a2) 1c008898: 01f62623 sw t6,12(a2) 1c00889c: 0056a023 sw t0,0(a3) 1c0088a0: 0076a223 sw t2,4(a3) 1c0088a4: c680 sw s0,8(a3) 1c0088a6: c6c4 sw s1,12(a3) 1c0088a8: 0641 addi a2,a2,16 1c0088aa: 06c1 addi a3,a3,16 1c0088ac: 0711 addi a4,a4,4 1c0088ae: 17fd addi a5,a5,-1 1c0088b0: c832 sw a2,16(sp) 1c0088b2: c636 sw a3,12(sp) 1c0088b4: cc3a sw a4,24(sp) 1c0088b6: ce3e sw a5,28(sp) 1c0088b8: f385 bnez a5,1c0087d8 <plp_mat_mult_i8s_xpulpv2+0xa4> 1c0088ba: 4536 lw a0,76(sp) 1c0088bc: 4616 lw a2,68(sp) 1c0088be: 42a6 lw t0,72(sp) 1c0088c0: 4306 lw t1,64(sp) 1c0088c2: 5492 lw s1,36(sp) 1c0088c4: 56c2 lw a3,48(sp) 1c0088c6: 5732 lw a4,44(sp) 1c0088c8: 43d6 lw t2,84(sp) 1c0088ca: 59e2 lw s3,56(sp) 1c0088cc: 0285 addi t0,t0,1 1c0088ce: 931e add t1,t1,t2 1c0088d0: 94b2 add s1,s1,a2 1c0088d2: 96b2 add a3,a3,a2 1c0088d4: 9732 add a4,a4,a2 1c0088d6: c496 sw t0,72(sp) 1c0088d8: c09a sw t1,64(sp) 1c0088da: d226 sw s1,36(sp) 1c0088dc: d836 sw a3,48(sp) 1c0088de: d63a sw a4,44(sp) 1c0088e0: ec599be3 bne s3,t0,1c0087b6 <plp_mat_mult_i8s_xpulpv2+0x82> 1c0088e4: 42c6 lw t0,80(sp) 1c0088e6: 0986 slli s3,s3,0x1 1c0088e8: dc4e sw s3,56(sp) 1c0088ea: 080a slli a6,a6,0x2 1c0088ec: 050a slli a0,a0,0x2 1c0088ee: 0d328063 beq t0,s3,1c0089ae <plp_mat_mult_i8s_xpulpv2+0x27a> 1c0088f2: e961 bnez a0,1c0089c2 <plp_mat_mult_i8s_xpulpv2+0x28e> 1c0088f4: 5662 lw a2,56(sp) 1c0088f6: 49c6 lw s3,80(sp) 1c0088f8: 09367163 bleu s3,a2,1c00897a <plp_mat_mult_i8s_xpulpv2+0x246> 1c0088fc: 5302 lw t1,32(sp) 1c0088fe: 52f2 lw t0,60(sp) 1c008900: 43d2 lw t2,20(sp) 1c008902: 00628fb3 add t6,t0,t1 1c008906: 8e7e mv t3,t6 1c008908: 02760f33 mul t5,a2,t2 1c00890c: 42660e33 p.mac t3,a2,t1 1c008910: 42d2 lw t0,20(sp) 1c008912: 04557a63 bleu t0,a0,1c008966 <plp_mat_mult_i8s_xpulpv2+0x232> 1c008916: 43e6 lw t2,88(sp) 1c008918: 01e50333 add t1,a0,t5 1c00891c: 030a slli t1,t1,0x2 1c00891e: 41fe0eb3 sub t4,t3,t6 1c008922: 931e add t1,t1,t2 1c008924: 40a288b3 sub a7,t0,a0 1c008928: 01e8c07b lp.setup x0,a7,1c008964 <plp_mat_mult_i8s_xpulpv2+0x230> 1c00892c: 5382 lw t2,32(sp) 1c00892e: 4681 li a3,0 1c008930: 02787863 bleu t2,a6,1c008960 <plp_mat_mult_i8s_xpulpv2+0x22c> 1c008934: 44d2 lw s1,20(sp) 1c008936: 872a mv a4,a0 1c008938: 5672 lw a2,60(sp) 1c00893a: 43048733 p.mac a4,s1,a6 1c00893e: 59d2 lw s3,52(sp) 1c008940: 9876 add a6,a6,t4 1c008942: 9832 add a6,a6,a2 1c008944: 4681 li a3,0 1c008946: 410e07b3 sub a5,t3,a6 1c00894a: 82a6 mv t0,s1 1c00894c: 974e add a4,a4,s3 1c00894e: 0067c0fb lp.setup x1,a5,1c00895a <plp_mat_mult_i8s_xpulpv2+0x226> 1c008952: 0018060b p.lb a2,1(a6!) 1c008956: 0057758b p.lb a1,t0(a4!) 1c00895a: 42c586b3 p.mac a3,a1,a2 1c00895e: 5802 lw a6,32(sp) 1c008960: 00d3222b p.sw a3,4(t1!) 1c008964: 0505 addi a0,a0,1 1c008966: 54e2 lw s1,56(sp) 1c008968: 4652 lw a2,20(sp) 1c00896a: 5682 lw a3,32(sp) 1c00896c: 49c6 lw s3,80(sp) 1c00896e: 0485 addi s1,s1,1 1c008970: dc26 sw s1,56(sp) 1c008972: 9f32 add t5,t5,a2 1c008974: 9e36 add t3,t3,a3 1c008976: f8999de3 bne s3,s1,1c008910 <plp_mat_mult_i8s_xpulpv2+0x1dc> 1c00897a: 443a lw s0,140(sp) 1c00897c: 44aa lw s1,136(sp) 1c00897e: 491a lw s2,132(sp) 1c008980: 498a lw s3,128(sp) 1c008982: 5a76 lw s4,124(sp) 1c008984: 5ae6 lw s5,120(sp) 1c008986: 5b56 lw s6,116(sp) 1c008988: 5bc6 lw s7,112(sp) 1c00898a: 5c36 lw s8,108(sp) 1c00898c: 5ca6 lw s9,104(sp) 1c00898e: 5d16 lw s10,100(sp) 1c008990: 5d86 lw s11,96(sp) 1c008992: 6149 addi sp,sp,144 1c008994: 8082 ret 1c008996: 4801 li a6,0 1c008998: 4481 li s1,0 1c00899a: 4401 li s0,0 1c00899c: 4381 li t2,0 1c00899e: 4281 li t0,0 1c0089a0: 4f81 li t6,0 1c0089a2: 4f01 li t5,0 1c0089a4: 4e81 li t4,0 1c0089a6: 4e01 li t3,0 1c0089a8: bdf1 j 1c008884 <plp_mat_mult_i8s_xpulpv2+0x150> 1c0089aa: 4501 li a0,0 1c0089ac: bf01 j 1c0088bc <plp_mat_mult_i8s_xpulpv2+0x188> 1c0089ae: 5302 lw t1,32(sp) 1c0089b0: f46811e3 bne a6,t1,1c0088f2 <plp_mat_mult_i8s_xpulpv2+0x1be> 1c0089b4: 44d2 lw s1,20(sp) 1c0089b6: fca482e3 beq s1,a0,1c00897a <plp_mat_mult_i8s_xpulpv2+0x246> 1c0089ba: 5362 lw t1,56(sp) 1c0089bc: fa030fe3 beqz t1,1c00897a <plp_mat_mult_i8s_xpulpv2+0x246> 1c0089c0: bf0d j 1c0088f2 <plp_mat_mult_i8s_xpulpv2+0x1be> 1c0089c2: f20809e3 beqz a6,1c0088f4 <plp_mat_mult_i8s_xpulpv2+0x1c0> 1c0089c6: 5482 lw s1,32(sp) 1c0089c8: 08980263 beq a6,s1,1c008a4c <plp_mat_mult_i8s_xpulpv2+0x318> 1c0089cc: 59f2 lw s3,60(sp) 1c0089ce: 4652 lw a2,20(sp) 1c0089d0: 46e6 lw a3,88(sp) 1c0089d2: 00998fb3 add t6,s3,s1 1c0089d6: 54d2 lw s1,52(sp) 1c0089d8: 00251293 slli t0,a0,0x2 1c0089dc: 40a00433 neg s0,a0 1c0089e0: 42c804b3 p.mac s1,a6,a2 1c0089e4: 00261913 slli s2,a2,0x2 1c0089e8: 92b6 add t0,t0,a3 1c0089ea: 01098f33 add t5,s3,a6 1c0089ee: 040a slli s0,s0,0x2 1c0089f0: 4381 li t2,0 1c0089f2: 00540e33 add t3,s0,t0 1c0089f6: 41c28333 sub t1,t0,t3 1c0089fa: 1371 addi t1,t1,-4 1c0089fc: 00235313 srli t1,t1,0x2 1c008a00: 8ea6 mv t4,s1 1c008a02: 0305 addi t1,t1,1 1c008a04: 01a3407b lp.setup x0,t1,1c008a38 <plp_mat_mult_i8s_xpulpv2+0x304> 1c008a08: 5602 lw a2,32(sp) 1c008a0a: 4781 li a5,0 1c008a0c: 02c87263 bleu a2,a6,1c008a30 <plp_mat_mult_i8s_xpulpv2+0x2fc> 1c008a10: 8676 mv a2,t4 1c008a12: 86fa mv a3,t5 1c008a14: 4781 li a5,0 1c008a16: 41ef8733 sub a4,t6,t5 1c008a1a: 00a740fb lp.setup x1,a4,1c008a2e <plp_mat_mult_i8s_xpulpv2+0x2fa> 1c008a1e: 49d2 lw s3,20(sp) 1c008a20: 0016858b p.lb a1,1(a3!) 1c008a24: 0136788b p.lb a7,s3(a2!) 1c008a28: 89be mv s3,a5 1c008a2a: 42b889b3 p.mac s3,a7,a1 1c008a2e: 97ce add a5,a5,s3 1c008a30: 000e2703 lw a4,0(t3) 1c008a34: 0e85 addi t4,t4,1 1c008a36: 97ba add a5,a5,a4 1c008a38: 00fe222b p.sw a5,4(t3!) 1c008a3c: 5682 lw a3,32(sp) 1c008a3e: 59e2 lw s3,56(sp) 1c008a40: 0385 addi t2,t2,1 1c008a42: 92ca add t0,t0,s2 1c008a44: 9f36 add t5,t5,a3 1c008a46: 9fb6 add t6,t6,a3 1c008a48: fb33e5e3 bltu t2,s3,1c0089f2 <plp_mat_mult_i8s_xpulpv2+0x2be> 1c008a4c: 42d2 lw t0,20(sp) 1c008a4e: 06550663 beq a0,t0,1c008aba <plp_mat_mult_i8s_xpulpv2+0x386> 1c008a52: 06557463 bleu t0,a0,1c008aba <plp_mat_mult_i8s_xpulpv2+0x386> 1c008a56: 43e6 lw t2,88(sp) 1c008a58: 5652 lw a2,52(sp) 1c008a5a: 5482 lw s1,32(sp) 1c008a5c: 5e72 lw t3,60(sp) 1c008a5e: 8316 mv t1,t0 1c008a60: 00251293 slli t0,a0,0x2 1c008a64: 929e add t0,t0,t2 1c008a66: 00231413 slli s0,t1,0x2 1c008a6a: 01c48fb3 add t6,s1,t3 1c008a6e: 4381 li t2,0 1c008a70: 9532 add a0,a0,a2 1c008a72: 00660eb3 add t4,a2,t1 1c008a76: 832a mv t1,a0 1c008a78: 8f16 mv t5,t0 1c008a7a: 40ae88b3 sub a7,t4,a0 1c008a7e: 0158c07b lp.setup x0,a7,1c008aa8 <plp_mat_mult_i8s_xpulpv2+0x374> 1c008a82: 5602 lw a2,32(sp) 1c008a84: 4701 li a4,0 1c008a86: ce19 beqz a2,1c008aa4 <plp_mat_mult_i8s_xpulpv2+0x370> 1c008a88: 44d2 lw s1,20(sp) 1c008a8a: 861a mv a2,t1 1c008a8c: 86f2 mv a3,t3 1c008a8e: 4701 li a4,0 1c008a90: 41cf87b3 sub a5,t6,t3 1c008a94: 0067c0fb lp.setup x1,a5,1c008aa0 <plp_mat_mult_i8s_xpulpv2+0x36c> 1c008a98: 0016858b p.lb a1,1(a3!) 1c008a9c: 0096780b p.lb a6,s1(a2!) 1c008aa0: 42b80733 p.mac a4,a6,a1 1c008aa4: 00ef222b p.sw a4,4(t5!) 1c008aa8: 0305 addi t1,t1,1 1c008aaa: 5682 lw a3,32(sp) 1c008aac: 59e2 lw s3,56(sp) 1c008aae: 0385 addi t2,t2,1 1c008ab0: 92a2 add t0,t0,s0 1c008ab2: 9e36 add t3,t3,a3 1c008ab4: 9fb6 add t6,t6,a3 1c008ab6: fd33e0e3 bltu t2,s3,1c008a76 <plp_mat_mult_i8s_xpulpv2+0x342> 1c008aba: 42c6 lw t0,80(sp) 1c008abc: 5362 lw t1,56(sp) 1c008abe: ea537ee3 bleu t0,t1,1c00897a <plp_mat_mult_i8s_xpulpv2+0x246> 1c008ac2: 43d2 lw t2,20(sp) 1c008ac4: ea038be3 beqz t2,1c00897a <plp_mat_mult_i8s_xpulpv2+0x246> 1c008ac8: 5482 lw s1,32(sp) 1c008aca: 4fe6 lw t6,88(sp) 1c008acc: 00239293 slli t0,t2,0x2 1c008ad0: 026487b3 mul a5,s1,t1 1c008ad4: 5672 lw a2,60(sp) 1c008ad6: 59d2 lw s3,52(sp) 1c008ad8: 00960f33 add t5,a2,s1 1c008adc: 00798eb3 add t4,s3,t2 1c008ae0: 42530fb3 p.mac t6,t1,t0 1c008ae4: 00f60e33 add t3,a2,a5 1c008ae8: 9f3e add t5,t5,a5 1c008aea: 58d2 lw a7,52(sp) 1c008aec: 837e mv t1,t6 1c008aee: 411e8833 sub a6,t4,a7 1c008af2: 0168407b lp.setup x0,a6,1c008b1e <plp_mat_mult_i8s_xpulpv2+0x3ea> 1c008af6: 5382 lw t2,32(sp) 1c008af8: 4701 li a4,0 1c008afa: 02038063 beqz t2,1c008b1a <plp_mat_mult_i8s_xpulpv2+0x3e6> 1c008afe: 49d2 lw s3,20(sp) 1c008b00: 8646 mv a2,a7 1c008b02: 86f2 mv a3,t3 1c008b04: 4701 li a4,0 1c008b06: 41cf07b3 sub a5,t5,t3 1c008b0a: 0067c0fb lp.setup x1,a5,1c008b16 <plp_mat_mult_i8s_xpulpv2+0x3e2> 1c008b0e: 0016858b p.lb a1,1(a3!) 1c008b12: 0136750b p.lb a0,s3(a2!) 1c008b16: 42b50733 p.mac a4,a0,a1 1c008b1a: 00e3222b p.sw a4,4(t1!) 1c008b1e: 0885 addi a7,a7,1 1c008b20: 54e2 lw s1,56(sp) 1c008b22: 5602 lw a2,32(sp) 1c008b24: 49c6 lw s3,80(sp) 1c008b26: 0485 addi s1,s1,1 1c008b28: dc26 sw s1,56(sp) 1c008b2a: 9f96 add t6,t6,t0 1c008b2c: 9e32 add t3,t3,a2 1c008b2e: 9f32 add t5,t5,a2 1c008b30: fa999de3 bne s3,s1,1c008aea <plp_mat_mult_i8s_xpulpv2+0x3b6> 1c008b34: b599 j 1c00897a <plp_mat_mult_i8s_xpulpv2+0x246> 1c008b36: 82b2 mv t0,a2 1c008b38: 4801 li a6,0 1c008b3a: 4501 li a0,0 1c008b3c: da061ce3 bnez a2,1c0088f4 <plp_mat_mult_i8s_xpulpv2+0x1c0> 1c008b40: e3069de3 bne a3,a6,1c00897a <plp_mat_mult_i8s_xpulpv2+0x246> 1c008b44: dc16 sw t0,56(sp) 1c008b46: 84ba mv s1,a4 1c008b48: b5bd j 1c0089b6 <plp_mat_mult_i8s_xpulpv2+0x282> 1c008b4a <main>: 1c008b4a: 1101 addi sp,sp,-32 1c008b4c: 4681 li a3,0 1c008b4e: 4601 li a2,0 1c008b50: 4581 li a1,0 1c008b52: 4505 li a0,1 1c008b54: ce06 sw ra,28(sp) 1c008b56: 2559 jal 1c0091dc <rt_cluster_mount> 1c008b58: 1c008637 lui a2,0x1c008 1c008b5c: 4881 li a7,0 1c008b5e: 4801 li a6,0 1c008b60: 4781 li a5,0 1c008b62: 4701 li a4,0 1c008b64: 4681 li a3,0 1c008b66: 53060613 addi a2,a2,1328 # 1c008530 <cluster_entry> 1c008b6a: 4581 li a1,0 1c008b6c: c002 sw zero,0(sp) 1c008b6e: 4501 li a0,0 1c008b70: 2bc9 jal 1c009142 <rt_cluster_call> 1c008b72: 4501 li a0,0 1c008b74: 4681 li a3,0 1c008b76: 4601 li a2,0 1c008b78: 4581 li a1,0 1c008b7a: 258d jal 1c0091dc <rt_cluster_mount> 1c008b7c: 40f2 lw ra,28(sp) 1c008b7e: 4501 li a0,0 1c008b80: 6105 addi sp,sp,32 1c008b82: 8082 ret 1c008b84 <rt_user_alloc_init>: 1c008b84: 00758793 addi a5,a1,7 1c008b88: 9be1 andi a5,a5,-8 1c008b8a: 40b785b3 sub a1,a5,a1 1c008b8e: c11c sw a5,0(a0) 1c008b90: 8e0d sub a2,a2,a1 1c008b92: 00c05663 blez a2,1c008b9e <rt_user_alloc_init+0x1a> 1c008b96: 9a61 andi a2,a2,-8 1c008b98: c390 sw a2,0(a5) 1c008b9a: 0007a223 sw zero,4(a5) 1c008b9e: 8082 ret 1c008ba0 <rt_user_alloc>: 1c008ba0: 411c lw a5,0(a0) 1c008ba2: 059d addi a1,a1,7 1c008ba4: 99e1 andi a1,a1,-8 1c008ba6: 4681 li a3,0 1c008ba8: cb89 beqz a5,1c008bba <rt_user_alloc+0x1a> 1c008baa: 4398 lw a4,0(a5) 1c008bac: 00b74963 blt a4,a1,1c008bbe <rt_user_alloc+0x1e> 1c008bb0: 00b71c63 bne a4,a1,1c008bc8 <rt_user_alloc+0x28> 1c008bb4: 43d8 lw a4,4(a5) 1c008bb6: c699 beqz a3,1c008bc4 <rt_user_alloc+0x24> 1c008bb8: c2d8 sw a4,4(a3) 1c008bba: 853e mv a0,a5 1c008bbc: 8082 ret 1c008bbe: 86be mv a3,a5 1c008bc0: 43dc lw a5,4(a5) 1c008bc2: b7dd j 1c008ba8 <rt_user_alloc+0x8> 1c008bc4: c118 sw a4,0(a0) 1c008bc6: bfd5 j 1c008bba <rt_user_alloc+0x1a> 1c008bc8: 8f0d sub a4,a4,a1 1c008bca: c398 sw a4,0(a5) 1c008bcc: 97ba add a5,a5,a4 1c008bce: b7f5 j 1c008bba <rt_user_alloc+0x1a> 1c008bd0 <rt_user_free>: 1c008bd0: 411c lw a5,0(a0) 1c008bd2: 061d addi a2,a2,7 1c008bd4: 9a61 andi a2,a2,-8 1c008bd6: 4701 li a4,0 1c008bd8: c399 beqz a5,1c008bde <rt_user_free+0xe> 1c008bda: 02b7e763 bltu a5,a1,1c008c08 <rt_user_free+0x38> 1c008bde: 00c586b3 add a3,a1,a2 1c008be2: 02d79663 bne a5,a3,1c008c0e <rt_user_free+0x3e> 1c008be6: 4394 lw a3,0(a5) 1c008be8: 43dc lw a5,4(a5) 1c008bea: 9636 add a2,a2,a3 1c008bec: c190 sw a2,0(a1) 1c008bee: c1dc sw a5,4(a1) 1c008bf0: c31d beqz a4,1c008c16 <rt_user_free+0x46> 1c008bf2: 4314 lw a3,0(a4) 1c008bf4: 00d707b3 add a5,a4,a3 1c008bf8: 00f59d63 bne a1,a5,1c008c12 <rt_user_free+0x42> 1c008bfc: 419c lw a5,0(a1) 1c008bfe: 97b6 add a5,a5,a3 1c008c00: c31c sw a5,0(a4) 1c008c02: 41dc lw a5,4(a1) 1c008c04: c35c sw a5,4(a4) 1c008c06: 8082 ret 1c008c08: 873e mv a4,a5 1c008c0a: 43dc lw a5,4(a5) 1c008c0c: b7f1 j 1c008bd8 <rt_user_free+0x8> 1c008c0e: c190 sw a2,0(a1) 1c008c10: bff9 j 1c008bee <rt_user_free+0x1e> 1c008c12: c34c sw a1,4(a4) 1c008c14: 8082 ret 1c008c16: c10c sw a1,0(a0) 1c008c18: 8082 ret 1c008c1a <rt_alloc>: 1c008c1a: 1101 addi sp,sp,-32 1c008c1c: cc22 sw s0,24(sp) 1c008c1e: ce06 sw ra,28(sp) 1c008c20: ca26 sw s1,20(sp) 1c008c22: c84a sw s2,16(sp) 1c008c24: c64e sw s3,12(sp) 1c008c26: c452 sw s4,8(sp) 1c008c28: 4789 li a5,2 1c008c2a: 842a mv s0,a0 1c008c2c: 02a7ed63 bltu a5,a0,1c008c66 <rt_alloc+0x4c> 1c008c30: 1c001937 lui s2,0x1c001 1c008c34: 89ae mv s3,a1 1c008c36: 448d li s1,3 1c008c38: 1b890913 addi s2,s2,440 # 1c0011b8 <__rt_alloc_l2> 1c008c3c: 4a0d li s4,3 1c008c3e: 00241513 slli a0,s0,0x2 1c008c42: 85ce mv a1,s3 1c008c44: 954a add a0,a0,s2 1c008c46: 3fa9 jal 1c008ba0 <rt_user_alloc> 1c008c48: e519 bnez a0,1c008c56 <rt_alloc+0x3c> 1c008c4a: 0405 addi s0,s0,1 1c008c4c: 01441363 bne s0,s4,1c008c52 <rt_alloc+0x38> 1c008c50: 4401 li s0,0 1c008c52: 14fd addi s1,s1,-1 1c008c54: f4ed bnez s1,1c008c3e <rt_alloc+0x24> 1c008c56: 40f2 lw ra,28(sp) 1c008c58: 4462 lw s0,24(sp) 1c008c5a: 44d2 lw s1,20(sp) 1c008c5c: 4942 lw s2,16(sp) 1c008c5e: 49b2 lw s3,12(sp) 1c008c60: 4a22 lw s4,8(sp) 1c008c62: 6105 addi sp,sp,32 1c008c64: 8082 ret 1c008c66: 1c0017b7 lui a5,0x1c001 1c008c6a: ffd50413 addi s0,a0,-3 1c008c6e: 1b47a503 lw a0,436(a5) # 1c0011b4 <__rt_alloc_l1> 1c008c72: 040a slli s0,s0,0x2 1c008c74: 40f2 lw ra,28(sp) 1c008c76: 9522 add a0,a0,s0 1c008c78: 4462 lw s0,24(sp) 1c008c7a: 44d2 lw s1,20(sp) 1c008c7c: 4942 lw s2,16(sp) 1c008c7e: 49b2 lw s3,12(sp) 1c008c80: 4a22 lw s4,8(sp) 1c008c82: 6105 addi sp,sp,32 1c008c84: bf31 j 1c008ba0 <rt_user_alloc> 1c008c86 <__rt_alloc_init_l1>: 1c008c86: 1c0017b7 lui a5,0x1c001 1c008c8a: 1b47a703 lw a4,436(a5) # 1c0011b4 <__rt_alloc_l1> 1c008c8e: 100037b7 lui a5,0x10003 1c008c92: 01651593 slli a1,a0,0x16 1c008c96: 6635 lui a2,0xd 1c008c98: 050a slli a0,a0,0x2 1c008c9a: 61478793 addi a5,a5,1556 # 10003614 <__l1_end> 1c008c9e: 9ec60613 addi a2,a2,-1556 # c9ec <__l1_heap_size> 1c008ca2: 95be add a1,a1,a5 1c008ca4: 953a add a0,a0,a4 1c008ca6: bdf9 j 1c008b84 <rt_user_alloc_init> 1c008ca8 <__rt_alloc_init_l1_for_fc>: 1c008ca8: 100035b7 lui a1,0x10003 1c008cac: 01651793 slli a5,a0,0x16 1c008cb0: 61458593 addi a1,a1,1556 # 10003614 <__l1_end> 1c008cb4: 00b78733 add a4,a5,a1 1c008cb8: 050a slli a0,a0,0x2 1c008cba: 0791 addi a5,a5,4 1c008cbc: 6635 lui a2,0xd 1c008cbe: 1c0016b7 lui a3,0x1c001 1c008cc2: 9e860613 addi a2,a2,-1560 # c9e8 <_l1_preload_size+0x93d8> 1c008cc6: 95be add a1,a1,a5 1c008cc8: 953a add a0,a0,a4 1c008cca: 1ae6aa23 sw a4,436(a3) # 1c0011b4 <__rt_alloc_l1> 1c008cce: bd5d j 1c008b84 <rt_user_alloc_init> 1c008cd0 <__rt_allocs_init>: 1c008cd0: 1141 addi sp,sp,-16 1c008cd2: 1c0015b7 lui a1,0x1c001 1c008cd6: c606 sw ra,12(sp) 1c008cd8: 20458793 addi a5,a1,516 # 1c001204 <__l2_priv0_end> 1c008cdc: 1c008637 lui a2,0x1c008 1c008ce0: 06c7ca63 blt a5,a2,1c008d54 <__rt_allocs_init+0x84> 1c008ce4: 4581 li a1,0 1c008ce6: 4601 li a2,0 1c008ce8: 1c001537 lui a0,0x1c001 1c008cec: 1b850513 addi a0,a0,440 # 1c0011b8 <__rt_alloc_l2> 1c008cf0: 3d51 jal 1c008b84 <rt_user_alloc_init> 1c008cf2: 1c00b5b7 lui a1,0x1c00b 1c008cf6: 62858793 addi a5,a1,1576 # 1c00b628 <__l2_priv1_end> 1c008cfa: 1c010637 lui a2,0x1c010 1c008cfe: 04c7cf63 blt a5,a2,1c008d5c <__rt_allocs_init+0x8c> 1c008d02: 4581 li a1,0 1c008d04: 4601 li a2,0 1c008d06: 1c001537 lui a0,0x1c001 1c008d0a: 1bc50513 addi a0,a0,444 # 1c0011bc <__rt_alloc_l2+0x4> 1c008d0e: 3d9d jal 1c008b84 <rt_user_alloc_init> 1c008d10: 1c0135b7 lui a1,0x1c013 1c008d14: 79858793 addi a5,a1,1944 # 1c013798 <__l2_shared_end> 1c008d18: 1c080637 lui a2,0x1c080 1c008d1c: 1c001537 lui a0,0x1c001 1c008d20: 8e1d sub a2,a2,a5 1c008d22: 79858593 addi a1,a1,1944 1c008d26: 1c050513 addi a0,a0,448 # 1c0011c0 <__rt_alloc_l2+0x8> 1c008d2a: 3da9 jal 1c008b84 <rt_user_alloc_init> 1c008d2c: f14027f3 csrr a5,mhartid 1c008d30: 8795 srai a5,a5,0x5 1c008d32: 03f7f793 andi a5,a5,63 1c008d36: e789 bnez a5,1c008d40 <__rt_allocs_init+0x70> 1c008d38: 40b2 lw ra,12(sp) 1c008d3a: 4501 li a0,0 1c008d3c: 0141 addi sp,sp,16 1c008d3e: b7ad j 1c008ca8 <__rt_alloc_init_l1_for_fc> 1c008d40: 4591 li a1,4 1c008d42: 4501 li a0,0 1c008d44: 3dd9 jal 1c008c1a <rt_alloc> 1c008d46: 40b2 lw ra,12(sp) 1c008d48: 1c0017b7 lui a5,0x1c001 1c008d4c: 1aa7aa23 sw a0,436(a5) # 1c0011b4 <__rt_alloc_l1> 1c008d50: 0141 addi sp,sp,16 1c008d52: 8082 ret 1c008d54: 8e1d sub a2,a2,a5 1c008d56: 20458593 addi a1,a1,516 1c008d5a: b779 j 1c008ce8 <__rt_allocs_init+0x18> 1c008d5c: 8e1d sub a2,a2,a5 1c008d5e: 62858593 addi a1,a1,1576 1c008d62: b755 j 1c008d06 <__rt_allocs_init+0x36> 1c008d64 <__rt_init_cluster_data>: 1c008d64: 04050793 addi a5,a0,64 1c008d68: 01679693 slli a3,a5,0x16 1c008d6c: 6705 lui a4,0x1 1c008d6e: 177d addi a4,a4,-1 1c008d70: 00400793 li a5,4 1c008d74: 8ff9 and a5,a5,a4 1c008d76: 1c010737 lui a4,0x1c010 1c008d7a: 97b6 add a5,a5,a3 1c008d7c: 660d lui a2,0x3 1c008d7e: 18870713 addi a4,a4,392 # 1c010188 <_l1_preload_start_inL2> 1c008d82: 61060613 addi a2,a2,1552 # 3610 <_l1_preload_size> 1c008d86: 8f99 sub a5,a5,a4 1c008d88: 00f705b3 add a1,a4,a5 1c008d8c: 02c04b63 bgtz a2,1c008dc2 <__rt_init_cluster_data+0x5e> 1c008d90: 02800713 li a4,40 1c008d94: 02e50733 mul a4,a0,a4 1c008d98: 1c0017b7 lui a5,0x1c001 1c008d9c: 1c878513 addi a0,a5,456 # 1c0011c8 <__rt_fc_cluster_data> 1c008da0: 002017b7 lui a5,0x201 1c008da4: e0478793 addi a5,a5,-508 # 200e04 <__l1_heap_size+0x1f4418> 1c008da8: 97b6 add a5,a5,a3 1c008daa: 953a add a0,a0,a4 1c008dac: c91c sw a5,16(a0) 1c008dae: 6705 lui a4,0x1 1c008db0: 00400793 li a5,4 1c008db4: 177d addi a4,a4,-1 1c008db6: 8ff9 and a5,a5,a4 1c008db8: 97b6 add a5,a5,a3 1c008dba: 00052423 sw zero,8(a0) 1c008dbe: c95c sw a5,20(a0) 1c008dc0: 8082 ret 1c008dc2: 00072803 lw a6,0(a4) # 1000 <__rt_hyper_pending_emu_stride+0xd58> 1c008dc6: 1671 addi a2,a2,-4 1c008dc8: 0711 addi a4,a4,4 1c008dca: 0105a023 sw a6,0(a1) 1c008dce: bf6d j 1c008d88 <__rt_init_cluster_data+0x24> 1c008dd0 <__rt_cluster_mount_step>: 1c008dd0: 7179 addi sp,sp,-48 1c008dd2: d04a sw s2,32(sp) 1c008dd4: ce4e sw s3,28(sp) 1c008dd6: 6785 lui a5,0x1 1c008dd8: 1c0089b7 lui s3,0x1c008 1c008ddc: 00400913 li s2,4 1c008de0: 17fd addi a5,a5,-1 1c008de2: 08098993 addi s3,s3,128 # 1c008080 <_start> 1c008de6: d422 sw s0,40(sp) 1c008de8: d606 sw ra,44(sp) 1c008dea: d226 sw s1,36(sp) 1c008dec: cc52 sw s4,24(sp) 1c008dee: 842a mv s0,a0 1c008df0: 00f97933 and s2,s2,a5 1c008df4: f009f993 andi s3,s3,-256 1c008df8: 4c5c lw a5,28(s0) 1c008dfa: 4705 li a4,1 1c008dfc: 02e78d63 beq a5,a4,1c008e36 <__rt_cluster_mount_step+0x66> 1c008e00: 4709 li a4,2 1c008e02: 0ae78d63 beq a5,a4,1c008ebc <__rt_cluster_mount_step+0xec> 1c008e06: e7dd bnez a5,1c008eb4 <__rt_cluster_mount_step+0xe4> 1c008e08: 5018 lw a4,32(s0) 1c008e0a: 00042c23 sw zero,24(s0) 1c008e0e: eb01 bnez a4,1c008e1e <__rt_cluster_mount_step+0x4e> 1c008e10: 5048 lw a0,36(s0) 1c008e12: 006c addi a1,sp,12 1c008e14: c602 sw zero,12(sp) 1c008e16: 1e8010ef jal ra,1c009ffe <__rt_pmu_cluster_power_up> 1c008e1a: 47b2 lw a5,12(sp) 1c008e1c: cc08 sw a0,24(s0) 1c008e1e: 4c58 lw a4,28(s0) 1c008e20: 0705 addi a4,a4,1 1c008e22: cc58 sw a4,28(s0) 1c008e24: dbf1 beqz a5,1c008df8 <__rt_cluster_mount_step+0x28> 1c008e26: 50b2 lw ra,44(sp) 1c008e28: 5422 lw s0,40(sp) 1c008e2a: 5492 lw s1,36(sp) 1c008e2c: 5902 lw s2,32(sp) 1c008e2e: 49f2 lw s3,28(sp) 1c008e30: 4a62 lw s4,24(sp) 1c008e32: 6145 addi sp,sp,48 1c008e34: 8082 ret 1c008e36: 02042a03 lw s4,32(s0) 1c008e3a: 040a0493 addi s1,s4,64 1c008e3e: 04da slli s1,s1,0x16 1c008e40: 00990733 add a4,s2,s1 1c008e44: 00072223 sw zero,4(a4) 1c008e48: 00072423 sw zero,8(a4) 1c008e4c: 00072023 sw zero,0(a4) 1c008e50: 1c001737 lui a4,0x1c001 1c008e54: 09c72703 lw a4,156(a4) # 1c00109c <__rt_platform> 1c008e58: 00f70f63 beq a4,a5,1c008e76 <__rt_cluster_mount_step+0xa6> 1c008e5c: 4505 li a0,1 1c008e5e: 727000ef jal ra,1c009d84 <__rt_fll_init> 1c008e62: 1c0017b7 lui a5,0x1c001 1c008e66: 1f878793 addi a5,a5,504 # 1c0011f8 <__rt_freq_domains> 1c008e6a: 43cc lw a1,4(a5) 1c008e6c: c5b1 beqz a1,1c008eb8 <__rt_cluster_mount_step+0xe8> 1c008e6e: 4601 li a2,0 1c008e70: 4505 li a0,1 1c008e72: 0a8010ef jal ra,1c009f1a <rt_freq_set_and_get> 1c008e76: 8552 mv a0,s4 1c008e78: 35f5 jal 1c008d64 <__rt_init_cluster_data> 1c008e7a: 8552 mv a0,s4 1c008e7c: 3529 jal 1c008c86 <__rt_alloc_init_l1> 1c008e7e: 002017b7 lui a5,0x201 1c008e82: 40078793 addi a5,a5,1024 # 201400 <__l1_heap_size+0x1f4a14> 1c008e86: 97a6 add a5,a5,s1 1c008e88: 577d li a4,-1 1c008e8a: c398 sw a4,0(a5) 1c008e8c: 002007b7 lui a5,0x200 1c008e90: 04078713 addi a4,a5,64 # 200040 <__l1_heap_size+0x1f3654> 1c008e94: 06078793 addi a5,a5,96 1c008e98: 9726 add a4,a4,s1 1c008e9a: 97a6 add a5,a5,s1 1c008e9c: 01372023 sw s3,0(a4) 1c008ea0: 0711 addi a4,a4,4 1c008ea2: fef71de3 bne a4,a5,1c008e9c <__rt_cluster_mount_step+0xcc> 1c008ea6: 002007b7 lui a5,0x200 1c008eaa: 07a1 addi a5,a5,8 1c008eac: 94be add s1,s1,a5 1c008eae: 0ff00793 li a5,255 1c008eb2: c09c sw a5,0(s1) 1c008eb4: 4781 li a5,0 1c008eb6: b7a5 j 1c008e1e <__rt_cluster_mount_step+0x4e> 1c008eb8: c3c8 sw a0,4(a5) 1c008eba: bf75 j 1c008e76 <__rt_cluster_mount_step+0xa6> 1c008ebc: 505c lw a5,36(s0) 1c008ebe: 5b98 lw a4,48(a5) 1c008ec0: d398 sw a4,32(a5) 1c008ec2: 5798 lw a4,40(a5) 1c008ec4: c398 sw a4,0(a5) 1c008ec6: 57d8 lw a4,44(a5) 1c008ec8: c3d8 sw a4,4(a5) 1c008eca: 0207a823 sw zero,48(a5) # 200030 <__l1_heap_size+0x1f3644> 1c008ece: 505c lw a5,36(s0) 1c008ed0: 02802703 lw a4,40(zero) # 28 <__rt_sched> 1c008ed4: 0007ac23 sw zero,24(a5) 1c008ed8: cb01 beqz a4,1c008ee8 <__rt_cluster_mount_step+0x118> 1c008eda: 02c02703 lw a4,44(zero) # 2c <__rt_sched+0x4> 1c008ede: cf1c sw a5,24(a4) 1c008ee0: 02f02623 sw a5,44(zero) # 2c <__rt_sched+0x4> 1c008ee4: 4785 li a5,1 1c008ee6: bf25 j 1c008e1e <__rt_cluster_mount_step+0x4e> 1c008ee8: 02f02423 sw a5,40(zero) # 28 <__rt_sched> 1c008eec: bfd5 j 1c008ee0 <__rt_cluster_mount_step+0x110> 1c008eee <__rt_cluster_init>: 1c008eee: 1c001537 lui a0,0x1c001 1c008ef2: 1141 addi sp,sp,-16 1c008ef4: 02800613 li a2,40 1c008ef8: 4581 li a1,0 1c008efa: 1c850513 addi a0,a0,456 # 1c0011c8 <__rt_fc_cluster_data> 1c008efe: c606 sw ra,12(sp) 1c008f00: 073010ef jal ra,1c00a772 <memset> 1c008f04: 1c0085b7 lui a1,0x1c008 1c008f08: 17e58593 addi a1,a1,382 # 1c00817e <__rt_remote_enqueue_event> 1c008f0c: 4505 li a0,1 1c008f0e: 2bfd jal 1c00950c <rt_irq_set_handler> 1c008f10: f14027f3 csrr a5,mhartid 1c008f14: 8795 srai a5,a5,0x5 1c008f16: 03f7f793 andi a5,a5,63 1c008f1a: 477d li a4,31 1c008f1c: 02e79e63 bne a5,a4,1c008f58 <__rt_cluster_init+0x6a> 1c008f20: 1a10a7b7 lui a5,0x1a10a 1c008f24: 4709 li a4,2 1c008f26: 80e7a223 sw a4,-2044(a5) # 1a109804 <__l1_end+0xa1061f0> 1c008f2a: 1c0085b7 lui a1,0x1c008 1c008f2e: 14658593 addi a1,a1,326 # 1c008146 <__rt_bridge_enqueue_event> 1c008f32: 4511 li a0,4 1c008f34: 2be1 jal 1c00950c <rt_irq_set_handler> 1c008f36: f14027f3 csrr a5,mhartid 1c008f3a: 8795 srai a5,a5,0x5 1c008f3c: 03f7f793 andi a5,a5,63 1c008f40: 477d li a4,31 1c008f42: 02e79063 bne a5,a4,1c008f62 <__rt_cluster_init+0x74> 1c008f46: 1a10a7b7 lui a5,0x1a10a 1c008f4a: 4741 li a4,16 1c008f4c: 80e7a223 sw a4,-2044(a5) # 1a109804 <__l1_end+0xa1061f0> 1c008f50: 40b2 lw ra,12(sp) 1c008f52: 4501 li a0,0 1c008f54: 0141 addi sp,sp,16 1c008f56: 8082 ret 1c008f58: 002047b7 lui a5,0x204 1c008f5c: 4709 li a4,2 1c008f5e: cbd8 sw a4,20(a5) 1c008f60: b7e9 j 1c008f2a <__rt_cluster_init+0x3c> 1c008f62: 002047b7 lui a5,0x204 1c008f66: 4741 li a4,16 1c008f68: cbd8 sw a4,20(a5) 1c008f6a: b7dd j 1c008f50 <__rt_cluster_init+0x62> 1c008f6c <pi_cluster_conf_init>: 1c008f6c: 00052223 sw zero,4(a0) 1c008f70: 8082 ret 1c008f72 <pi_cluster_open>: 1c008f72: 1101 addi sp,sp,-32 1c008f74: ce06 sw ra,28(sp) 1c008f76: cc22 sw s0,24(sp) 1c008f78: ca26 sw s1,20(sp) 1c008f7a: c84a sw s2,16(sp) 1c008f7c: c64e sw s3,12(sp) 1c008f7e: 30047973 csrrci s2,mstatus,8 1c008f82: 00452983 lw s3,4(a0) 1c008f86: 02800793 li a5,40 1c008f8a: 0049a483 lw s1,4(s3) 1c008f8e: 02f484b3 mul s1,s1,a5 1c008f92: 1c0017b7 lui a5,0x1c001 1c008f96: 1c878793 addi a5,a5,456 # 1c0011c8 <__rt_fc_cluster_data> 1c008f9a: 94be add s1,s1,a5 1c008f9c: c504 sw s1,8(a0) 1c008f9e: 3b7000ef jal ra,1c009b54 <__rt_wait_event_prepare_blocking> 1c008fa2: f14027f3 csrr a5,mhartid 1c008fa6: 8795 srai a5,a5,0x5 1c008fa8: 03f7f793 andi a5,a5,63 1c008fac: 477d li a4,31 1c008fae: 842a mv s0,a0 1c008fb0: 04e79463 bne a5,a4,1c008ff8 <pi_cluster_open+0x86> 1c008fb4: 511c lw a5,32(a0) 1c008fb6: 0004ae23 sw zero,28(s1) 1c008fba: d0c8 sw a0,36(s1) 1c008fbc: d91c sw a5,48(a0) 1c008fbe: 411c lw a5,0(a0) 1c008fc0: 02052223 sw zero,36(a0) 1c008fc4: d51c sw a5,40(a0) 1c008fc6: 415c lw a5,4(a0) 1c008fc8: c144 sw s1,4(a0) 1c008fca: d55c sw a5,44(a0) 1c008fcc: 1c0097b7 lui a5,0x1c009 1c008fd0: dd078793 addi a5,a5,-560 # 1c008dd0 <__rt_cluster_mount_step> 1c008fd4: c11c sw a5,0(a0) 1c008fd6: 4785 li a5,1 1c008fd8: d11c sw a5,32(a0) 1c008fda: 8526 mv a0,s1 1c008fdc: 3bd5 jal 1c008dd0 <__rt_cluster_mount_step> 1c008fde: 8522 mv a0,s0 1c008fe0: 4c5000ef jal ra,1c009ca4 <__rt_wait_event> 1c008fe4: 30091073 csrw mstatus,s2 1c008fe8: 40f2 lw ra,28(sp) 1c008fea: 4462 lw s0,24(sp) 1c008fec: 44d2 lw s1,20(sp) 1c008fee: 4942 lw s2,16(sp) 1c008ff0: 49b2 lw s3,12(sp) 1c008ff2: 4501 li a0,0 1c008ff4: 6105 addi sp,sp,32 1c008ff6: 8082 ret 1c008ff8: 0049a483 lw s1,4(s3) 1c008ffc: 8526 mv a0,s1 1c008ffe: 339d jal 1c008d64 <__rt_init_cluster_data> 1c009000: 04048513 addi a0,s1,64 1c009004: 002017b7 lui a5,0x201 1c009008: 055a slli a0,a0,0x16 1c00900a: 40078793 addi a5,a5,1024 # 201400 <__l1_heap_size+0x1f4a14> 1c00900e: 97aa add a5,a5,a0 1c009010: 577d li a4,-1 1c009012: c398 sw a4,0(a5) 1c009014: 1c0086b7 lui a3,0x1c008 1c009018: 002007b7 lui a5,0x200 1c00901c: 04478713 addi a4,a5,68 # 200044 <__l1_heap_size+0x1f3658> 1c009020: 08068693 addi a3,a3,128 # 1c008080 <_start> 1c009024: 06078793 addi a5,a5,96 1c009028: 972a add a4,a4,a0 1c00902a: 97aa add a5,a5,a0 1c00902c: f006f693 andi a3,a3,-256 1c009030: c314 sw a3,0(a4) 1c009032: 0711 addi a4,a4,4 1c009034: fef71ee3 bne a4,a5,1c009030 <pi_cluster_open+0xbe> 1c009038: 002007b7 lui a5,0x200 1c00903c: 07a1 addi a5,a5,8 1c00903e: 953e add a0,a0,a5 1c009040: 57fd li a5,-1 1c009042: c11c sw a5,0(a0) 1c009044: 8522 mv a0,s0 1c009046: 3db000ef jal ra,1c009c20 <rt_event_push> 1c00904a: bf51 j 1c008fde <pi_cluster_open+0x6c> 1c00904c <pi_cluster_close>: 1c00904c: 451c lw a5,8(a0) 1c00904e: 1101 addi sp,sp,-32 1c009050: cc22 sw s0,24(sp) 1c009052: 5380 lw s0,32(a5) 1c009054: 1c0017b7 lui a5,0x1c001 1c009058: 09c7a703 lw a4,156(a5) # 1c00109c <__rt_platform> 1c00905c: ce06 sw ra,28(sp) 1c00905e: 4785 li a5,1 1c009060: 00f70563 beq a4,a5,1c00906a <pi_cluster_close+0x1e> 1c009064: 4505 li a0,1 1c009066: 5d5000ef jal ra,1c009e3a <__rt_fll_deinit> 1c00906a: c602 sw zero,12(sp) 1c00906c: e409 bnez s0,1c009076 <pi_cluster_close+0x2a> 1c00906e: 006c addi a1,sp,12 1c009070: 4501 li a0,0 1c009072: 749000ef jal ra,1c009fba <__rt_pmu_cluster_power_down> 1c009076: 40f2 lw ra,28(sp) 1c009078: 4462 lw s0,24(sp) 1c00907a: 4501 li a0,0 1c00907c: 6105 addi sp,sp,32 1c00907e: 8082 ret 1c009080 <__rt_cluster_push_fc_event>: 1c009080: 002047b7 lui a5,0x204 1c009084: 0c078793 addi a5,a5,192 # 2040c0 <__l1_heap_size+0x1f76d4> 1c009088: 0007e703 p.elw a4,0(a5) 1c00908c: f14027f3 csrr a5,mhartid 1c009090: 8795 srai a5,a5,0x5 1c009092: 02800693 li a3,40 1c009096: 03f7f793 andi a5,a5,63 1c00909a: 02d787b3 mul a5,a5,a3 1c00909e: 1c001737 lui a4,0x1c001 1c0090a2: 1c870713 addi a4,a4,456 # 1c0011c8 <__rt_fc_cluster_data> 1c0090a6: 4689 li a3,2 1c0090a8: 97ba add a5,a5,a4 1c0090aa: 00204737 lui a4,0x204 1c0090ae: 43d0 lw a2,4(a5) 1c0090b0: ee01 bnez a2,1c0090c8 <__rt_cluster_push_fc_event+0x48> 1c0090b2: c3c8 sw a0,4(a5) 1c0090b4: 4709 li a4,2 1c0090b6: 1a10a7b7 lui a5,0x1a10a 1c0090ba: 80e7a823 sw a4,-2032(a5) # 1a109810 <__l1_end+0xa1061fc> 1c0090be: 002047b7 lui a5,0x204 1c0090c2: 0c07a023 sw zero,192(a5) # 2040c0 <__l1_heap_size+0x1f76d4> 1c0090c6: 8082 ret 1c0090c8: c714 sw a3,8(a4) 1c0090ca: 03c76603 p.elw a2,60(a4) # 20403c <__l1_heap_size+0x1f7650> 1c0090ce: c354 sw a3,4(a4) 1c0090d0: bff9 j 1c0090ae <__rt_cluster_push_fc_event+0x2e> 1c0090d2 <__rt_cluster_new>: 1c0090d2: 1c0095b7 lui a1,0x1c009 1c0090d6: 1141 addi sp,sp,-16 1c0090d8: 4601 li a2,0 1c0090da: eee58593 addi a1,a1,-274 # 1c008eee <__rt_cluster_init> 1c0090de: 4501 li a0,0 1c0090e0: c606 sw ra,12(sp) 1c0090e2: 2b6d jal 1c00969c <__rt_cbsys_add> 1c0090e4: c105 beqz a0,1c009104 <__rt_cluster_new+0x32> 1c0090e6: f1402673 csrr a2,mhartid 1c0090ea: 1c000537 lui a0,0x1c000 1c0090ee: 40565593 srai a1,a2,0x5 1c0090f2: 03f5f593 andi a1,a1,63 1c0090f6: 8a7d andi a2,a2,31 1c0090f8: 51450513 addi a0,a0,1300 # 1c000514 <__DTOR_END__+0x228> 1c0090fc: 0c3010ef jal ra,1c00a9be <printf> 1c009100: 04b010ef jal ra,1c00a94a <abort> 1c009104: 40b2 lw ra,12(sp) 1c009106: 0141 addi sp,sp,16 1c009108: 8082 ret 1c00910a <__rt_cluster_pulpos_emu_init>: 1c00910a: 1141 addi sp,sp,-16 1c00910c: 45b1 li a1,12 1c00910e: 4501 li a0,0 1c009110: c606 sw ra,12(sp) 1c009112: 3621 jal 1c008c1a <rt_alloc> 1c009114: 1c0017b7 lui a5,0x1c001 1c009118: 18a7a423 sw a0,392(a5) # 1c001188 <__rt_fc_cluster_device> 1c00911c: e105 bnez a0,1c00913c <__rt_cluster_pulpos_emu_init+0x32> 1c00911e: f1402673 csrr a2,mhartid 1c009122: 1c000537 lui a0,0x1c000 1c009126: 40565593 srai a1,a2,0x5 1c00912a: 03f5f593 andi a1,a1,63 1c00912e: 8a7d andi a2,a2,31 1c009130: 55c50513 addi a0,a0,1372 # 1c00055c <__DTOR_END__+0x270> 1c009134: 08b010ef jal ra,1c00a9be <printf> 1c009138: 013010ef jal ra,1c00a94a <abort> 1c00913c: 40b2 lw ra,12(sp) 1c00913e: 0141 addi sp,sp,16 1c009140: 8082 ret 1c009142 <rt_cluster_call>: 1c009142: 7139 addi sp,sp,-64 1c009144: d84a sw s2,48(sp) 1c009146: 4906 lw s2,64(sp) 1c009148: dc22 sw s0,56(sp) 1c00914a: 842e mv s0,a1 1c00914c: de06 sw ra,60(sp) 1c00914e: da26 sw s1,52(sp) 1c009150: d64e sw s3,44(sp) 1c009152: 300479f3 csrrci s3,mstatus,8 1c009156: 84ca mv s1,s2 1c009158: 02091163 bnez s2,1c00917a <rt_cluster_call+0x38> 1c00915c: ce32 sw a2,28(sp) 1c00915e: cc36 sw a3,24(sp) 1c009160: ca3a sw a4,20(sp) 1c009162: c83e sw a5,16(sp) 1c009164: c642 sw a6,12(sp) 1c009166: c446 sw a7,8(sp) 1c009168: 1ed000ef jal ra,1c009b54 <__rt_wait_event_prepare_blocking> 1c00916c: 48a2 lw a7,8(sp) 1c00916e: 4832 lw a6,12(sp) 1c009170: 47c2 lw a5,16(sp) 1c009172: 4752 lw a4,20(sp) 1c009174: 46e2 lw a3,24(sp) 1c009176: 4672 lw a2,28(sp) 1c009178: 84aa mv s1,a0 1c00917a: 4531 li a0,12 1c00917c: 02a40433 mul s0,s0,a0 1c009180: 1c0015b7 lui a1,0x1c001 1c009184: 0c058313 addi t1,a1,192 # 1c0010c0 <__rt_pulpos_emu_global_cluster_task> 1c009188: 00f32623 sw a5,12(t1) 1c00918c: 1c0017b7 lui a5,0x1c001 1c009190: 1887a503 lw a0,392(a5) # 1c001188 <__rt_fc_cluster_device> 1c009194: 00c32023 sw a2,0(t1) 1c009198: 0c058593 addi a1,a1,192 1c00919c: 8626 mv a2,s1 1c00919e: 00d32223 sw a3,4(t1) 1c0091a2: 9522 add a0,a0,s0 1c0091a4: 00e32423 sw a4,8(t1) 1c0091a8: 01032823 sw a6,16(t1) 1c0091ac: 01132a23 sw a7,20(t1) 1c0091b0: 2041 jal 1c009230 <pi_cluster_send_task_to_cl_async> 1c0091b2: 842a mv s0,a0 1c0091b4: cd01 beqz a0,1c0091cc <rt_cluster_call+0x8a> 1c0091b6: 30099073 csrw mstatus,s3 1c0091ba: 547d li s0,-1 1c0091bc: 8522 mv a0,s0 1c0091be: 50f2 lw ra,60(sp) 1c0091c0: 5462 lw s0,56(sp) 1c0091c2: 54d2 lw s1,52(sp) 1c0091c4: 5942 lw s2,48(sp) 1c0091c6: 59b2 lw s3,44(sp) 1c0091c8: 6121 addi sp,sp,64 1c0091ca: 8082 ret 1c0091cc: 00091563 bnez s2,1c0091d6 <rt_cluster_call+0x94> 1c0091d0: 8526 mv a0,s1 1c0091d2: 2d3000ef jal ra,1c009ca4 <__rt_wait_event> 1c0091d6: 30099073 csrw mstatus,s3 1c0091da: b7cd j 1c0091bc <rt_cluster_call+0x7a> 1c0091dc <rt_cluster_mount>: 1c0091dc: 7139 addi sp,sp,-64 1c0091de: dc22 sw s0,56(sp) 1c0091e0: da26 sw s1,52(sp) 1c0091e2: d84a sw s2,48(sp) 1c0091e4: 4431 li s0,12 1c0091e6: 1c0014b7 lui s1,0x1c001 1c0091ea: de06 sw ra,60(sp) 1c0091ec: d64e sw s3,44(sp) 1c0091ee: 8936 mv s2,a3 1c0091f0: 02858433 mul s0,a1,s0 1c0091f4: 18848493 addi s1,s1,392 # 1c001188 <__rt_fc_cluster_device> 1c0091f8: c905 beqz a0,1c009228 <rt_cluster_mount+0x4c> 1c0091fa: 0068 addi a0,sp,12 1c0091fc: 89ae mv s3,a1 1c0091fe: 33bd jal 1c008f6c <pi_cluster_conf_init> 1c009200: 4088 lw a0,0(s1) 1c009202: 006c addi a1,sp,12 1c009204: 9522 add a0,a0,s0 1c009206: 2609 jal 1c009508 <pi_open_from_conf> 1c009208: 4088 lw a0,0(s1) 1c00920a: c84e sw s3,16(sp) 1c00920c: 9522 add a0,a0,s0 1c00920e: 3395 jal 1c008f72 <pi_cluster_open> 1c009210: 00090563 beqz s2,1c00921a <rt_cluster_mount+0x3e> 1c009214: 854a mv a0,s2 1c009216: 20b000ef jal ra,1c009c20 <rt_event_push> 1c00921a: 50f2 lw ra,60(sp) 1c00921c: 5462 lw s0,56(sp) 1c00921e: 54d2 lw s1,52(sp) 1c009220: 5942 lw s2,48(sp) 1c009222: 59b2 lw s3,44(sp) 1c009224: 6121 addi sp,sp,64 1c009226: 8082 ret 1c009228: 4088 lw a0,0(s1) 1c00922a: 9522 add a0,a0,s0 1c00922c: 3505 jal 1c00904c <pi_cluster_close> 1c00922e: b7cd j 1c009210 <rt_cluster_mount+0x34> 1c009230 <pi_cluster_send_task_to_cl_async>: 1c009230: 1101 addi sp,sp,-32 1c009232: ca26 sw s1,20(sp) 1c009234: 4504 lw s1,8(a0) 1c009236: cc22 sw s0,24(sp) 1c009238: c256 sw s5,4(sp) 1c00923a: 842e mv s0,a1 1c00923c: 8ab2 mv s5,a2 1c00923e: ce06 sw ra,28(sp) 1c009240: c84a sw s2,16(sp) 1c009242: c64e sw s3,12(sp) 1c009244: c452 sw s4,8(sp) 1c009246: 30047a73 csrrci s4,mstatus,8 1c00924a: 00060823 sb zero,16(a2) 1c00924e: 4785 li a5,1 1c009250: d1dc sw a5,36(a1) 1c009252: 49dc lw a5,20(a1) 1c009254: 0144a983 lw s3,20(s1) 1c009258: e399 bnez a5,1c00925e <pi_cluster_send_task_to_cl_async+0x2e> 1c00925a: 47a1 li a5,8 1c00925c: c9dc sw a5,20(a1) 1c00925e: 441c lw a5,8(s0) 1c009260: eb8d bnez a5,1c009292 <pi_cluster_send_task_to_cl_async+0x62> 1c009262: 445c lw a5,12(s0) 1c009264: e789 bnez a5,1c00926e <pi_cluster_send_task_to_cl_async+0x3e> 1c009266: 40000793 li a5,1024 1c00926a: c45c sw a5,12(s0) 1c00926c: c81c sw a5,16(s0) 1c00926e: 4818 lw a4,16(s0) 1c009270: 445c lw a5,12(s0) 1c009272: e311 bnez a4,1c009276 <pi_cluster_send_task_to_cl_async+0x46> 1c009274: c81c sw a5,16(s0) 1c009276: 01442903 lw s2,20(s0) 1c00927a: 4818 lw a4,16(s0) 1c00927c: 448c lw a1,8(s1) 1c00927e: 197d addi s2,s2,-1 1c009280: 02e90933 mul s2,s2,a4 1c009284: 993e add s2,s2,a5 1c009286: c9bd beqz a1,1c0092fc <pi_cluster_send_task_to_cl_async+0xcc> 1c009288: 44d0 lw a2,12(s1) 1c00928a: 07261063 bne a2,s2,1c0092ea <pi_cluster_send_task_to_cl_async+0xba> 1c00928e: 449c lw a5,8(s1) 1c009290: c41c sw a5,8(s0) 1c009292: 4858 lw a4,20(s0) 1c009294: 4785 li a5,1 1c009296: 01542c23 sw s5,24(s0) 1c00929a: 00e797b3 sll a5,a5,a4 1c00929e: 17fd addi a5,a5,-1 1c0092a0: d41c sw a5,40(s0) 1c0092a2: 02042023 sw zero,32(s0) 1c0092a6: 0089a783 lw a5,8(s3) 1c0092aa: cbbd beqz a5,1c009320 <pi_cluster_send_task_to_cl_async+0xf0> 1c0092ac: d380 sw s0,32(a5) 1c0092ae: 0089a423 sw s0,8(s3) 1c0092b2: 0009a783 lw a5,0(s3) 1c0092b6: e399 bnez a5,1c0092bc <pi_cluster_send_task_to_cl_async+0x8c> 1c0092b8: 0089a023 sw s0,0(s3) 1c0092bc: 509c lw a5,32(s1) 1c0092be: 00201737 lui a4,0x201 1c0092c2: e0470713 addi a4,a4,-508 # 200e04 <__l1_heap_size+0x1f4418> 1c0092c6: 04078793 addi a5,a5,64 1c0092ca: 07da slli a5,a5,0x16 1c0092cc: 97ba add a5,a5,a4 1c0092ce: 0007a023 sw zero,0(a5) 1c0092d2: 300a1073 csrw mstatus,s4 1c0092d6: 4501 li a0,0 1c0092d8: 40f2 lw ra,28(sp) 1c0092da: 4462 lw s0,24(sp) 1c0092dc: 44d2 lw s1,20(sp) 1c0092de: 4942 lw s2,16(sp) 1c0092e0: 49b2 lw s3,12(sp) 1c0092e2: 4a22 lw s4,8(sp) 1c0092e4: 4a92 lw s5,4(sp) 1c0092e6: 6105 addi sp,sp,32 1c0092e8: 8082 ret 1c0092ea: 509c lw a5,32(s1) 1c0092ec: 1c001737 lui a4,0x1c001 1c0092f0: 1b472503 lw a0,436(a4) # 1c0011b4 <__rt_alloc_l1> 1c0092f4: 078a slli a5,a5,0x2 1c0092f6: 953e add a0,a0,a5 1c0092f8: 8d9ff0ef jal ra,1c008bd0 <rt_user_free> 1c0092fc: 509c lw a5,32(s1) 1c0092fe: 1c001737 lui a4,0x1c001 1c009302: 1b472503 lw a0,436(a4) # 1c0011b4 <__rt_alloc_l1> 1c009306: 078a slli a5,a5,0x2 1c009308: 0124a623 sw s2,12(s1) 1c00930c: 85ca mv a1,s2 1c00930e: 953e add a0,a0,a5 1c009310: 891ff0ef jal ra,1c008ba0 <rt_user_alloc> 1c009314: c488 sw a0,8(s1) 1c009316: fd25 bnez a0,1c00928e <pi_cluster_send_task_to_cl_async+0x5e> 1c009318: 300a1073 csrw mstatus,s4 1c00931c: 557d li a0,-1 1c00931e: bf6d j 1c0092d8 <pi_cluster_send_task_to_cl_async+0xa8> 1c009320: 0089a223 sw s0,4(s3) 1c009324: b769 j 1c0092ae <pi_cluster_send_task_to_cl_async+0x7e> 1c009326 <rt_perf_init>: 1c009326: 00450793 addi a5,a0,4 1c00932a: 04850513 addi a0,a0,72 1c00932e: 0007a023 sw zero,0(a5) 1c009332: 0791 addi a5,a5,4 1c009334: fea79de3 bne a5,a0,1c00932e <rt_perf_init+0x8> 1c009338: 8082 ret 1c00933a <rt_perf_conf>: 1c00933a: c10c sw a1,0(a0) 1c00933c: 7a059073 csrw pcer,a1 1c009340: 8082 ret 1c009342 <cluster_start>: 1c009342: 002047b7 lui a5,0x204 1c009346: 00070737 lui a4,0x70 1c00934a: c798 sw a4,8(a5) 1c00934c: 0ff00713 li a4,255 1c009350: 08e7a223 sw a4,132(a5) # 204084 <__l1_heap_size+0x1f7698> 1c009354: 20e7a023 sw a4,512(a5) 1c009358: 20e7a623 sw a4,524(a5) 1c00935c: 8082 ret 1c00935e <__rt_init>: 1c00935e: 1101 addi sp,sp,-32 1c009360: ce06 sw ra,28(sp) 1c009362: cc22 sw s0,24(sp) 1c009364: 23d5 jal 1c009948 <__rt_bridge_set_available> 1c009366: 1c0017b7 lui a5,0x1c001 1c00936a: 09c7a703 lw a4,156(a5) # 1c00109c <__rt_platform> 1c00936e: 478d li a5,3 1c009370: 02f71263 bne a4,a5,1c009394 <__rt_init+0x36> 1c009374: 7d005073 csrwi 0x7d0,0 1c009378: 1c0007b7 lui a5,0x1c000 1c00937c: 6c078793 addi a5,a5,1728 # 1c0006c0 <stack_start> 1c009380: 7d179073 csrw 0x7d1,a5 1c009384: 1c0017b7 lui a5,0x1c001 1c009388: ec078793 addi a5,a5,-320 # 1c000ec0 <stack> 1c00938c: 7d279073 csrw 0x7d2,a5 1c009390: 7d00d073 csrwi 0x7d0,1 1c009394: 2c29 jal 1c0095ae <__rt_irq_init> 1c009396: 1a1067b7 lui a5,0x1a106 1c00939a: 577d li a4,-1 1c00939c: c3d8 sw a4,4(a5) 1c00939e: 1c0085b7 lui a1,0x1c008 1c0093a2: c798 sw a4,8(a5) 1c0093a4: 33058593 addi a1,a1,816 # 1c008330 <__rt_fc_socevents_handler> 1c0093a8: 4569 li a0,26 1c0093aa: 228d jal 1c00950c <rt_irq_set_handler> 1c0093ac: f14027f3 csrr a5,mhartid 1c0093b0: 8795 srai a5,a5,0x5 1c0093b2: 03f7f793 andi a5,a5,63 1c0093b6: 477d li a4,31 1c0093b8: 0ae79e63 bne a5,a4,1c009474 <__rt_init+0x116> 1c0093bc: 1a10a7b7 lui a5,0x1a10a 1c0093c0: 04000737 lui a4,0x4000 1c0093c4: 80e7a223 sw a4,-2044(a5) # 1a109804 <__l1_end+0xa1061f0> 1c0093c8: 46d000ef jal ra,1c00a034 <__rt_pmu_init> 1c0093cc: 373000ef jal ra,1c009f3e <__rt_freq_init> 1c0093d0: f14027f3 csrr a5,mhartid 1c0093d4: 8795 srai a5,a5,0x5 1c0093d6: 03f7f793 andi a5,a5,63 1c0093da: 477d li a4,31 1c0093dc: 00e78763 beq a5,a4,1c0093ea <__rt_init+0x8c> 1c0093e0: 002017b7 lui a5,0x201 1c0093e4: 577d li a4,-1 1c0093e6: 40e7a023 sw a4,1024(a5) # 201400 <__l1_heap_size+0x1f4a14> 1c0093ea: 1c000437 lui s0,0x1c000 1c0093ee: 2605 jal 1c00970e <__rt_utils_init> 1c0093f0: 2b440413 addi s0,s0,692 # 1c0002b4 <ctor_list+0x4> 1c0093f4: 8ddff0ef jal ra,1c008cd0 <__rt_allocs_init> 1c0093f8: 25cd jal 1c009ada <__rt_thread_sched_init> 1c0093fa: 0ed000ef jal ra,1c009ce6 <__rt_event_sched_init> 1c0093fe: 473000ef jal ra,1c00a070 <__rt_padframe_init> 1c009402: 401c lw a5,0(s0) 1c009404: efb5 bnez a5,1c009480 <__rt_init+0x122> 1c009406: 30045073 csrwi mstatus,8 1c00940a: 4501 li a0,0 1c00940c: 2cc1 jal 1c0096dc <__rt_cbsys_exec> 1c00940e: e521 bnez a0,1c009456 <__rt_init+0xf8> 1c009410: f14027f3 csrr a5,mhartid 1c009414: 8795 srai a5,a5,0x5 1c009416: 03f7f793 andi a5,a5,63 1c00941a: 477d li a4,31 1c00941c: 0ae78763 beq a5,a4,1c0094ca <__rt_init+0x16c> 1c009420: 4681 li a3,0 1c009422: 4601 li a2,0 1c009424: 4581 li a1,0 1c009426: 4505 li a0,1 1c009428: cfb9 beqz a5,1c009486 <__rt_init+0x128> 1c00942a: 3b4d jal 1c0091dc <rt_cluster_mount> 1c00942c: 6591 lui a1,0x4 1c00942e: 450d li a0,3 1c009430: feaff0ef jal ra,1c008c1a <rt_alloc> 1c009434: 872a mv a4,a0 1c009436: c105 beqz a0,1c009456 <__rt_init+0xf8> 1c009438: 6805 lui a6,0x1 1c00943a: 80080813 addi a6,a6,-2048 # 800 <__rt_hyper_pending_emu_stride+0x558> 1c00943e: 1c009637 lui a2,0x1c009 1c009442: c002 sw zero,0(sp) 1c009444: 48a1 li a7,8 1c009446: 87c2 mv a5,a6 1c009448: 4681 li a3,0 1c00944a: 34260613 addi a2,a2,834 # 1c009342 <cluster_start> 1c00944e: 4581 li a1,0 1c009450: 4501 li a0,0 1c009452: 39c5 jal 1c009142 <rt_cluster_call> 1c009454: c93d beqz a0,1c0094ca <__rt_init+0x16c> 1c009456: f1402673 csrr a2,mhartid 1c00945a: 1c000537 lui a0,0x1c000 1c00945e: 40565593 srai a1,a2,0x5 1c009462: 03f5f593 andi a1,a1,63 1c009466: 8a7d andi a2,a2,31 1c009468: 5b050513 addi a0,a0,1456 # 1c0005b0 <__DTOR_END__+0x2c4> 1c00946c: 552010ef jal ra,1c00a9be <printf> 1c009470: 4da010ef jal ra,1c00a94a <abort> 1c009474: 002047b7 lui a5,0x204 1c009478: 04000737 lui a4,0x4000 1c00947c: cbd8 sw a4,20(a5) 1c00947e: b7a9 j 1c0093c8 <__rt_init+0x6a> 1c009480: 9782 jalr a5 1c009482: 0411 addi s0,s0,4 1c009484: bfbd j 1c009402 <__rt_init+0xa4> 1c009486: 3b99 jal 1c0091dc <rt_cluster_mount> 1c009488: 6591 lui a1,0x4 1c00948a: 80058593 addi a1,a1,-2048 # 3800 <_l1_preload_size+0x1f0> 1c00948e: 450d li a0,3 1c009490: f8aff0ef jal ra,1c008c1a <rt_alloc> 1c009494: d169 beqz a0,1c009456 <__rt_init+0xf8> 1c009496: 00204737 lui a4,0x204 1c00949a: 0ff00793 li a5,255 1c00949e: 08f72223 sw a5,132(a4) # 204084 <__l1_heap_size+0x1f7698> 1c0094a2: 1c0107b7 lui a5,0x1c010 1c0094a6: 14478793 addi a5,a5,324 # 1c010144 <__rt_set_slave_stack> 1c0094aa: 0017e793 ori a5,a5,1 1c0094ae: 08f72023 sw a5,128(a4) 1c0094b2: 6785 lui a5,0x1 1c0094b4: 4462 lw s0,24(sp) 1c0094b6: 80078793 addi a5,a5,-2048 # 800 <__rt_hyper_pending_emu_stride+0x558> 1c0094ba: 08f72023 sw a5,128(a4) 1c0094be: 40f2 lw ra,28(sp) 1c0094c0: 08a72023 sw a0,128(a4) 1c0094c4: 4501 li a0,0 1c0094c6: 6105 addi sp,sp,32 1c0094c8: bdad j 1c009342 <cluster_start> 1c0094ca: 40f2 lw ra,28(sp) 1c0094cc: 4462 lw s0,24(sp) 1c0094ce: 6105 addi sp,sp,32 1c0094d0: 8082 ret 1c0094d2 <__rt_deinit>: 1c0094d2: 1c0017b7 lui a5,0x1c001 1c0094d6: 09c7a703 lw a4,156(a5) # 1c00109c <__rt_platform> 1c0094da: 1141 addi sp,sp,-16 1c0094dc: c606 sw ra,12(sp) 1c0094de: c422 sw s0,8(sp) 1c0094e0: 478d li a5,3 1c0094e2: 00f71463 bne a4,a5,1c0094ea <__rt_deinit+0x18> 1c0094e6: 7d005073 csrwi 0x7d0,0 1c0094ea: 4505 li a0,1 1c0094ec: 1c000437 lui s0,0x1c000 1c0094f0: 22f5 jal 1c0096dc <__rt_cbsys_exec> 1c0094f2: 2e840413 addi s0,s0,744 # 1c0002e8 <dtor_list+0x4> 1c0094f6: 401c lw a5,0(s0) 1c0094f8: e789 bnez a5,1c009502 <__rt_deinit+0x30> 1c0094fa: 40b2 lw ra,12(sp) 1c0094fc: 4422 lw s0,8(sp) 1c0094fe: 0141 addi sp,sp,16 1c009500: 8082 ret 1c009502: 9782 jalr a5 1c009504: 0411 addi s0,s0,4 1c009506: bfc5 j 1c0094f6 <__rt_deinit+0x24> 1c009508 <pi_open_from_conf>: 1c009508: c14c sw a1,4(a0) 1c00950a: 8082 ret 1c00950c <rt_irq_set_handler>: 1c00950c: f14027f3 csrr a5,mhartid 1c009510: 8795 srai a5,a5,0x5 1c009512: 03f7f793 andi a5,a5,63 1c009516: 477d li a4,31 1c009518: 04e79063 bne a5,a4,1c009558 <rt_irq_set_handler+0x4c> 1c00951c: 1a1047b7 lui a5,0x1a104 1c009520: 43dc lw a5,4(a5) 1c009522: 050a slli a0,a0,0x2 1c009524: 8d89 sub a1,a1,a0 1c009526: 8d9d sub a1,a1,a5 1c009528: 000ff737 lui a4,0xff 1c00952c: 00f506b3 add a3,a0,a5 1c009530: 8f6d and a4,a4,a1 1c009532: 0145d793 srli a5,a1,0x14 1c009536: 06f76713 ori a4,a4,111 1c00953a: 07fe slli a5,a5,0x1f 1c00953c: 8fd9 or a5,a5,a4 1c00953e: 7fe00637 lui a2,0x7fe00 1c009542: 01459713 slli a4,a1,0x14 1c009546: 8f71 and a4,a4,a2 1c009548: 8fd9 or a5,a5,a4 1c00954a: 05a6 slli a1,a1,0x9 1c00954c: 00100737 lui a4,0x100 1c009550: 8df9 and a1,a1,a4 1c009552: 8ddd or a1,a1,a5 1c009554: c28c sw a1,0(a3) 1c009556: 8082 ret 1c009558: 002007b7 lui a5,0x200 1c00955c: 43bc lw a5,64(a5) 1c00955e: b7d1 j 1c009522 <rt_irq_set_handler+0x16> 1c009560 <illegal_insn_handler_c>: 1c009560: 8082 ret 1c009562 <__rt_handle_illegal_instr>: 1c009562: 1c0017b7 lui a5,0x1c001 1c009566: ec47a703 lw a4,-316(a5) # 1c000ec4 <__rt_debug_config> 1c00956a: 1141 addi sp,sp,-16 1c00956c: c422 sw s0,8(sp) 1c00956e: c606 sw ra,12(sp) 1c009570: 8b05 andi a4,a4,1 1c009572: 843e mv s0,a5 1c009574: c30d beqz a4,1c009596 <__rt_handle_illegal_instr+0x34> 1c009576: 341026f3 csrr a3,mepc 1c00957a: f1402673 csrr a2,mhartid 1c00957e: 1c000537 lui a0,0x1c000 1c009582: 4298 lw a4,0(a3) 1c009584: 40565593 srai a1,a2,0x5 1c009588: 03f5f593 andi a1,a1,63 1c00958c: 8a7d andi a2,a2,31 1c00958e: 60850513 addi a0,a0,1544 # 1c000608 <__DTOR_END__+0x31c> 1c009592: 42c010ef jal ra,1c00a9be <printf> 1c009596: ec442783 lw a5,-316(s0) 1c00959a: 8385 srli a5,a5,0x1 1c00959c: 8b85 andi a5,a5,1 1c00959e: c399 beqz a5,1c0095a4 <__rt_handle_illegal_instr+0x42> 1c0095a0: 3aa010ef jal ra,1c00a94a <abort> 1c0095a4: 4422 lw s0,8(sp) 1c0095a6: 40b2 lw ra,12(sp) 1c0095a8: 0141 addi sp,sp,16 1c0095aa: fb7ff06f j 1c009560 <illegal_insn_handler_c> 1c0095ae <__rt_irq_init>: 1c0095ae: f14027f3 csrr a5,mhartid 1c0095b2: 8795 srai a5,a5,0x5 1c0095b4: 03f7f793 andi a5,a5,63 1c0095b8: 477d li a4,31 1c0095ba: 02e79763 bne a5,a4,1c0095e8 <__rt_irq_init+0x3a> 1c0095be: 1a10a7b7 lui a5,0x1a10a 1c0095c2: 577d li a4,-1 1c0095c4: 80e7a423 sw a4,-2040(a5) # 1a109808 <__l1_end+0xa1061f4> 1c0095c8: f14027f3 csrr a5,mhartid 1c0095cc: 8795 srai a5,a5,0x5 1c0095ce: 1c008737 lui a4,0x1c008 1c0095d2: 03f7f793 andi a5,a5,63 1c0095d6: 46fd li a3,31 1c0095d8: 00070713 mv a4,a4 1c0095dc: 00d79b63 bne a5,a3,1c0095f2 <__rt_irq_init+0x44> 1c0095e0: 1a1047b7 lui a5,0x1a104 1c0095e4: c3d8 sw a4,4(a5) 1c0095e6: 8082 ret 1c0095e8: 002047b7 lui a5,0x204 1c0095ec: 577d li a4,-1 1c0095ee: cb98 sw a4,16(a5) 1c0095f0: bfe1 j 1c0095c8 <__rt_irq_init+0x1a> 1c0095f2: 002007b7 lui a5,0x200 1c0095f6: c3b8 sw a4,64(a5) 1c0095f8: 8082 ret 1c0095fa <__rt_fc_cluster_lock_req>: 1c0095fa: 1141 addi sp,sp,-16 1c0095fc: c606 sw ra,12(sp) 1c0095fe: c422 sw s0,8(sp) 1c009600: c226 sw s1,4(sp) 1c009602: 300474f3 csrrci s1,mstatus,8 1c009606: 09654703 lbu a4,150(a0) 1c00960a: 411c lw a5,0(a0) 1c00960c: c729 beqz a4,1c009656 <__rt_fc_cluster_lock_req+0x5c> 1c00960e: 4398 lw a4,0(a5) 1c009610: c30d beqz a4,1c009632 <__rt_fc_cluster_lock_req+0x38> 1c009612: 43d8 lw a4,4(a5) 1c009614: cf09 beqz a4,1c00962e <__rt_fc_cluster_lock_req+0x34> 1c009616: 4798 lw a4,8(a5) 1c009618: c348 sw a0,4(a4) 1c00961a: c788 sw a0,8(a5) 1c00961c: 00052223 sw zero,4(a0) 1c009620: 30049073 csrw mstatus,s1 1c009624: 40b2 lw ra,12(sp) 1c009626: 4422 lw s0,8(sp) 1c009628: 4492 lw s1,4(sp) 1c00962a: 0141 addi sp,sp,16 1c00962c: 8082 ret 1c00962e: c3c8 sw a0,4(a5) 1c009630: b7ed j 1c00961a <__rt_fc_cluster_lock_req+0x20> 1c009632: 4705 li a4,1 1c009634: 08e50a23 sb a4,148(a0) 1c009638: 4705 li a4,1 1c00963a: c398 sw a4,0(a5) 1c00963c: 09554783 lbu a5,149(a0) 1c009640: 04078793 addi a5,a5,64 # 200040 <__l1_heap_size+0x1f3654> 1c009644: 00201737 lui a4,0x201 1c009648: 07da slli a5,a5,0x16 1c00964a: e0470713 addi a4,a4,-508 # 200e04 <__l1_heap_size+0x1f4418> 1c00964e: 97ba add a5,a5,a4 1c009650: 0007a023 sw zero,0(a5) 1c009654: b7f1 j 1c009620 <__rt_fc_cluster_lock_req+0x26> 1c009656: 842a mv s0,a0 1c009658: 47c8 lw a0,12(a5) 1c00965a: cd01 beqz a0,1c009672 <__rt_fc_cluster_lock_req+0x78> 1c00965c: 0007a023 sw zero,0(a5) 1c009660: 0007a623 sw zero,12(a5) 1c009664: 2185 jal 1c009ac4 <__rt_thread_wakeup> 1c009666: 4785 li a5,1 1c009668: 08f40a23 sb a5,148(s0) 1c00966c: 09544783 lbu a5,149(s0) 1c009670: bfc1 j 1c009640 <__rt_fc_cluster_lock_req+0x46> 1c009672: 43d8 lw a4,4(a5) 1c009674: e701 bnez a4,1c00967c <__rt_fc_cluster_lock_req+0x82> 1c009676: 0007a023 sw zero,0(a5) 1c00967a: b7f5 j 1c009666 <__rt_fc_cluster_lock_req+0x6c> 1c00967c: 4354 lw a3,4(a4) 1c00967e: c3d4 sw a3,4(a5) 1c009680: 4785 li a5,1 1c009682: 08f70a23 sb a5,148(a4) 1c009686: 09574783 lbu a5,149(a4) 1c00968a: 00201737 lui a4,0x201 1c00968e: e0470713 addi a4,a4,-508 # 200e04 <__l1_heap_size+0x1f4418> 1c009692: 04078793 addi a5,a5,64 1c009696: 07da slli a5,a5,0x16 1c009698: 97ba add a5,a5,a4 1c00969a: bff1 j 1c009676 <__rt_fc_cluster_lock_req+0x7c> 1c00969c <__rt_cbsys_add>: 1c00969c: 1101 addi sp,sp,-32 1c00969e: cc22 sw s0,24(sp) 1c0096a0: ca26 sw s1,20(sp) 1c0096a2: 842a mv s0,a0 1c0096a4: 84ae mv s1,a1 1c0096a6: 4501 li a0,0 1c0096a8: 45b1 li a1,12 1c0096aa: c632 sw a2,12(sp) 1c0096ac: ce06 sw ra,28(sp) 1c0096ae: d6cff0ef jal ra,1c008c1a <rt_alloc> 1c0096b2: 4632 lw a2,12(sp) 1c0096b4: c115 beqz a0,1c0096d8 <__rt_cbsys_add+0x3c> 1c0096b6: 1c0017b7 lui a5,0x1c001 1c0096ba: 040a slli s0,s0,0x2 1c0096bc: ec878793 addi a5,a5,-312 # 1c000ec8 <cbsys_first> 1c0096c0: 97a2 add a5,a5,s0 1c0096c2: 4398 lw a4,0(a5) 1c0096c4: c104 sw s1,0(a0) 1c0096c6: c150 sw a2,4(a0) 1c0096c8: c518 sw a4,8(a0) 1c0096ca: c388 sw a0,0(a5) 1c0096cc: 4501 li a0,0 1c0096ce: 40f2 lw ra,28(sp) 1c0096d0: 4462 lw s0,24(sp) 1c0096d2: 44d2 lw s1,20(sp) 1c0096d4: 6105 addi sp,sp,32 1c0096d6: 8082 ret 1c0096d8: 557d li a0,-1 1c0096da: bfd5 j 1c0096ce <__rt_cbsys_add+0x32> 1c0096dc <__rt_cbsys_exec>: 1c0096dc: 00251793 slli a5,a0,0x2 1c0096e0: 1c001537 lui a0,0x1c001 1c0096e4: ec850513 addi a0,a0,-312 # 1c000ec8 <cbsys_first> 1c0096e8: 1141 addi sp,sp,-16 1c0096ea: 953e add a0,a0,a5 1c0096ec: c422 sw s0,8(sp) 1c0096ee: 4100 lw s0,0(a0) 1c0096f0: c606 sw ra,12(sp) 1c0096f2: e411 bnez s0,1c0096fe <__rt_cbsys_exec+0x22> 1c0096f4: 4501 li a0,0 1c0096f6: 40b2 lw ra,12(sp) 1c0096f8: 4422 lw s0,8(sp) 1c0096fa: 0141 addi sp,sp,16 1c0096fc: 8082 ret 1c0096fe: 401c lw a5,0(s0) 1c009700: 4048 lw a0,4(s0) 1c009702: 9782 jalr a5 1c009704: e119 bnez a0,1c00970a <__rt_cbsys_exec+0x2e> 1c009706: 4400 lw s0,8(s0) 1c009708: b7ed j 1c0096f2 <__rt_cbsys_exec+0x16> 1c00970a: 557d li a0,-1 1c00970c: b7ed j 1c0096f6 <__rt_cbsys_exec+0x1a> 1c00970e <__rt_utils_init>: 1c00970e: 1c0017b7 lui a5,0x1c001 1c009712: ec878793 addi a5,a5,-312 # 1c000ec8 <cbsys_first> 1c009716: 0007a023 sw zero,0(a5) 1c00971a: 0007a223 sw zero,4(a5) 1c00971e: 0007a423 sw zero,8(a5) 1c009722: 0007a623 sw zero,12(a5) 1c009726: 0007a823 sw zero,16(a5) 1c00972a: 0007aa23 sw zero,20(a5) 1c00972e: 8082 ret 1c009730 <__rt_fc_lock>: 1c009730: 1141 addi sp,sp,-16 1c009732: c422 sw s0,8(sp) 1c009734: 842a mv s0,a0 1c009736: c606 sw ra,12(sp) 1c009738: c226 sw s1,4(sp) 1c00973a: c04a sw s2,0(sp) 1c00973c: 300474f3 csrrci s1,mstatus,8 1c009740: 401c lw a5,0(s0) 1c009742: eb99 bnez a5,1c009758 <__rt_fc_lock+0x28> 1c009744: 4785 li a5,1 1c009746: c01c sw a5,0(s0) 1c009748: 30049073 csrw mstatus,s1 1c00974c: 40b2 lw ra,12(sp) 1c00974e: 4422 lw s0,8(sp) 1c009750: 4492 lw s1,4(sp) 1c009752: 4902 lw s2,0(sp) 1c009754: 0141 addi sp,sp,16 1c009756: 8082 ret 1c009758: 02002783 lw a5,32(zero) # 20 <__rt_thread_current> 1c00975c: 4585 li a1,1 1c00975e: e3ff7517 auipc a0,0xe3ff7 1c009762: 8ca50513 addi a0,a0,-1846 # 28 <__rt_sched> 1c009766: c45c sw a5,12(s0) 1c009768: 29f1 jal 1c009c44 <__rt_event_execute> 1c00976a: bfd9 j 1c009740 <__rt_fc_lock+0x10> 1c00976c <__rt_fc_unlock>: 1c00976c: 300476f3 csrrci a3,mstatus,8 1c009770: 415c lw a5,4(a0) 1c009772: e791 bnez a5,1c00977e <__rt_fc_unlock+0x12> 1c009774: 00052023 sw zero,0(a0) 1c009778: 30069073 csrw mstatus,a3 1c00977c: 8082 ret 1c00977e: 43d8 lw a4,4(a5) 1c009780: c158 sw a4,4(a0) 1c009782: 4705 li a4,1 1c009784: 08e78a23 sb a4,148(a5) 1c009788: 0957c783 lbu a5,149(a5) 1c00978c: 00201737 lui a4,0x201 1c009790: e0470713 addi a4,a4,-508 # 200e04 <__l1_heap_size+0x1f4418> 1c009794: 04078793 addi a5,a5,64 1c009798: 07da slli a5,a5,0x16 1c00979a: 97ba add a5,a5,a4 1c00979c: 0007a023 sw zero,0(a5) 1c0097a0: bfe1 j 1c009778 <__rt_fc_unlock+0xc> 1c0097a2 <__rt_fc_cluster_lock>: 1c0097a2: f14027f3 csrr a5,mhartid 1c0097a6: 8795 srai a5,a5,0x5 1c0097a8: 03f7f793 andi a5,a5,63 1c0097ac: 08f58aa3 sb a5,149(a1) 1c0097b0: 4785 li a5,1 1c0097b2: 08f58b23 sb a5,150(a1) 1c0097b6: 1c0097b7 lui a5,0x1c009 1c0097ba: 5fa78793 addi a5,a5,1530 # 1c0095fa <__rt_fc_cluster_lock_req> 1c0097be: c188 sw a0,0(a1) 1c0097c0: 08058a23 sb zero,148(a1) 1c0097c4: 0205a423 sw zero,40(a1) 1c0097c8: 0205a623 sw zero,44(a1) 1c0097cc: c59c sw a5,8(a1) 1c0097ce: c5cc sw a1,12(a1) 1c0097d0: 05a1 addi a1,a1,8 1c0097d2: 0015e513 ori a0,a1,1 1c0097d6: 8abff06f j 1c009080 <__rt_cluster_push_fc_event> 1c0097da <__rt_fc_cluster_unlock>: 1c0097da: f14027f3 csrr a5,mhartid 1c0097de: 8795 srai a5,a5,0x5 1c0097e0: 03f7f793 andi a5,a5,63 1c0097e4: 08f58aa3 sb a5,149(a1) 1c0097e8: 1c0097b7 lui a5,0x1c009 1c0097ec: 5fa78793 addi a5,a5,1530 # 1c0095fa <__rt_fc_cluster_lock_req> 1c0097f0: c188 sw a0,0(a1) 1c0097f2: 08058a23 sb zero,148(a1) 1c0097f6: 08058b23 sb zero,150(a1) 1c0097fa: 0205a423 sw zero,40(a1) 1c0097fe: 0205a623 sw zero,44(a1) 1c009802: c59c sw a5,8(a1) 1c009804: c5cc sw a1,12(a1) 1c009806: 05a1 addi a1,a1,8 1c009808: 0015e513 ori a0,a1,1 1c00980c: 875ff06f j 1c009080 <__rt_cluster_push_fc_event> 1c009810 <__rt_event_enqueue>: 1c009810: 02802783 lw a5,40(zero) # 28 <__rt_sched> 1c009814: 00052c23 sw zero,24(a0) 1c009818: c799 beqz a5,1c009826 <__rt_event_enqueue+0x16> 1c00981a: 02c02783 lw a5,44(zero) # 2c <__rt_sched+0x4> 1c00981e: cf88 sw a0,24(a5) 1c009820: 02a02623 sw a0,44(zero) # 2c <__rt_sched+0x4> 1c009824: 8082 ret 1c009826: 02a02423 sw a0,40(zero) # 28 <__rt_sched> 1c00982a: bfdd j 1c009820 <__rt_event_enqueue+0x10> 1c00982c <__rt_bridge_check_bridge_req.part.5>: 1c00982c: 1c001737 lui a4,0x1c001 1c009830: fdc70793 addi a5,a4,-36 # 1c000fdc <__hal_debug_struct> 1c009834: 0a47a783 lw a5,164(a5) 1c009838: fdc70713 addi a4,a4,-36 1c00983c: c789 beqz a5,1c009846 <__rt_bridge_check_bridge_req.part.5+0x1a> 1c00983e: 4f94 lw a3,24(a5) 1c009840: e681 bnez a3,1c009848 <__rt_bridge_check_bridge_req.part.5+0x1c> 1c009842: 0af72623 sw a5,172(a4) 1c009846: 8082 ret 1c009848: 479c lw a5,8(a5) 1c00984a: bfcd j 1c00983c <__rt_bridge_check_bridge_req.part.5+0x10> 1c00984c <__rt_bridge_wait>: 1c00984c: f14027f3 csrr a5,mhartid 1c009850: 8795 srai a5,a5,0x5 1c009852: 03f7f793 andi a5,a5,63 1c009856: 477d li a4,31 1c009858: 02e79a63 bne a5,a4,1c00988c <__rt_bridge_wait+0x40> 1c00985c: 1a10a7b7 lui a5,0x1a10a 1c009860: 6711 lui a4,0x4 1c009862: 300476f3 csrrci a3,mstatus,8 1c009866: 80c7a603 lw a2,-2036(a5) # 1a10980c <__l1_end+0xa1061f8> 1c00986a: 01161593 slli a1,a2,0x11 1c00986e: 0005cb63 bltz a1,1c009884 <__rt_bridge_wait+0x38> 1c009872: 80e7a223 sw a4,-2044(a5) 1c009876: 10500073 wfi 1c00987a: 80e7a423 sw a4,-2040(a5) 1c00987e: 30069073 csrw mstatus,a3 1c009882: b7c5 j 1c009862 <__rt_bridge_wait+0x16> 1c009884: 80e7aa23 sw a4,-2028(a5) 1c009888: 30069073 csrw mstatus,a3 1c00988c: 8082 ret 1c00988e <__rt_bridge_handle_notif>: 1c00988e: 1141 addi sp,sp,-16 1c009890: c422 sw s0,8(sp) 1c009892: 1c001437 lui s0,0x1c001 1c009896: fdc40793 addi a5,s0,-36 # 1c000fdc <__hal_debug_struct> 1c00989a: 0a47a783 lw a5,164(a5) 1c00989e: c606 sw ra,12(sp) 1c0098a0: c226 sw s1,4(sp) 1c0098a2: c04a sw s2,0(sp) 1c0098a4: fdc40413 addi s0,s0,-36 1c0098a8: c399 beqz a5,1c0098ae <__rt_bridge_handle_notif+0x20> 1c0098aa: 4bd8 lw a4,20(a5) 1c0098ac: e30d bnez a4,1c0098ce <__rt_bridge_handle_notif+0x40> 1c0098ae: 0b442783 lw a5,180(s0) 1c0098b2: c789 beqz a5,1c0098bc <__rt_bridge_handle_notif+0x2e> 1c0098b4: 43a8 lw a0,64(a5) 1c0098b6: 0a042a23 sw zero,180(s0) 1c0098ba: 3f99 jal 1c009810 <__rt_event_enqueue> 1c0098bc: 0ac42783 lw a5,172(s0) 1c0098c0: eb95 bnez a5,1c0098f4 <__rt_bridge_handle_notif+0x66> 1c0098c2: 4422 lw s0,8(sp) 1c0098c4: 40b2 lw ra,12(sp) 1c0098c6: 4492 lw s1,4(sp) 1c0098c8: 4902 lw s2,0(sp) 1c0098ca: 0141 addi sp,sp,16 1c0098cc: b785 j 1c00982c <__rt_bridge_check_bridge_req.part.5> 1c0098ce: 4784 lw s1,8(a5) 1c0098d0: 4fd8 lw a4,28(a5) 1c0098d2: 0a942223 sw s1,164(s0) 1c0098d6: cb01 beqz a4,1c0098e6 <__rt_bridge_handle_notif+0x58> 1c0098d8: 0b042703 lw a4,176(s0) 1c0098dc: c798 sw a4,8(a5) 1c0098de: 0af42823 sw a5,176(s0) 1c0098e2: 87a6 mv a5,s1 1c0098e4: b7d1 j 1c0098a8 <__rt_bridge_handle_notif+0x1a> 1c0098e6: 43a8 lw a0,64(a5) 1c0098e8: 30047973 csrrci s2,mstatus,8 1c0098ec: 3715 jal 1c009810 <__rt_event_enqueue> 1c0098ee: 30091073 csrw mstatus,s2 1c0098f2: bfc5 j 1c0098e2 <__rt_bridge_handle_notif+0x54> 1c0098f4: 40b2 lw ra,12(sp) 1c0098f6: 4422 lw s0,8(sp) 1c0098f8: 4492 lw s1,4(sp) 1c0098fa: 4902 lw s2,0(sp) 1c0098fc: 0141 addi sp,sp,16 1c0098fe: 8082 ret 1c009900 <__rt_bridge_check_connection>: 1c009900: 1c001737 lui a4,0x1c001 1c009904: fdc70713 addi a4,a4,-36 # 1c000fdc <__hal_debug_struct> 1c009908: 471c lw a5,8(a4) 1c00990a: ef95 bnez a5,1c009946 <__rt_bridge_check_connection+0x46> 1c00990c: 1a1047b7 lui a5,0x1a104 1c009910: 5bfc lw a5,116(a5) 1c009912: 469d li a3,7 1c009914: 83a5 srli a5,a5,0x9 1c009916: 8b9d andi a5,a5,7 1c009918: 02d79763 bne a5,a3,1c009946 <__rt_bridge_check_connection+0x46> 1c00991c: 1141 addi sp,sp,-16 1c00991e: c422 sw s0,8(sp) 1c009920: c226 sw s1,4(sp) 1c009922: c606 sw ra,12(sp) 1c009924: 4785 li a5,1 1c009926: c71c sw a5,8(a4) 1c009928: 1a1044b7 lui s1,0x1a104 1c00992c: 441d li s0,7 1c00992e: 58fc lw a5,116(s1) 1c009930: 83a5 srli a5,a5,0x9 1c009932: 8b9d andi a5,a5,7 1c009934: 00878763 beq a5,s0,1c009942 <__rt_bridge_check_connection+0x42> 1c009938: 40b2 lw ra,12(sp) 1c00993a: 4422 lw s0,8(sp) 1c00993c: 4492 lw s1,4(sp) 1c00993e: 0141 addi sp,sp,16 1c009940: 8082 ret 1c009942: 3729 jal 1c00984c <__rt_bridge_wait> 1c009944: b7ed j 1c00992e <__rt_bridge_check_connection+0x2e> 1c009946: 8082 ret 1c009948 <__rt_bridge_set_available>: 1c009948: 1c0017b7 lui a5,0x1c001 1c00994c: fdc78793 addi a5,a5,-36 # 1c000fdc <__hal_debug_struct> 1c009950: 479c lw a5,8(a5) 1c009952: 8082 ret 1c009954 <__rt_bridge_send_notif>: 1c009954: 1141 addi sp,sp,-16 1c009956: c606 sw ra,12(sp) 1c009958: 3765 jal 1c009900 <__rt_bridge_check_connection> 1c00995a: 40b2 lw ra,12(sp) 1c00995c: 1c0017b7 lui a5,0x1c001 1c009960: fdc78793 addi a5,a5,-36 # 1c000fdc <__hal_debug_struct> 1c009964: 479c lw a5,8(a5) 1c009966: 0141 addi sp,sp,16 1c009968: 8082 ret 1c00996a <__rt_bridge_clear_notif>: 1c00996a: 1141 addi sp,sp,-16 1c00996c: c606 sw ra,12(sp) 1c00996e: 3f49 jal 1c009900 <__rt_bridge_check_connection> 1c009970: 1c0017b7 lui a5,0x1c001 1c009974: fdc78793 addi a5,a5,-36 # 1c000fdc <__hal_debug_struct> 1c009978: 4798 lw a4,8(a5) 1c00997a: c311 beqz a4,1c00997e <__rt_bridge_clear_notif+0x14> 1c00997c: 479c lw a5,8(a5) 1c00997e: 40b2 lw ra,12(sp) 1c009980: 0141 addi sp,sp,16 1c009982: 8082 ret 1c009984 <__rt_bridge_printf_flush>: 1c009984: 1141 addi sp,sp,-16 1c009986: c422 sw s0,8(sp) 1c009988: c606 sw ra,12(sp) 1c00998a: 1c001437 lui s0,0x1c001 1c00998e: 3f8d jal 1c009900 <__rt_bridge_check_connection> 1c009990: fdc40793 addi a5,s0,-36 # 1c000fdc <__hal_debug_struct> 1c009994: 479c lw a5,8(a5) 1c009996: c385 beqz a5,1c0099b6 <__rt_bridge_printf_flush+0x32> 1c009998: fdc40413 addi s0,s0,-36 1c00999c: 485c lw a5,20(s0) 1c00999e: e399 bnez a5,1c0099a4 <__rt_bridge_printf_flush+0x20> 1c0099a0: 4c1c lw a5,24(s0) 1c0099a2: cb91 beqz a5,1c0099b6 <__rt_bridge_printf_flush+0x32> 1c0099a4: 3f45 jal 1c009954 <__rt_bridge_send_notif> 1c0099a6: 485c lw a5,20(s0) 1c0099a8: e789 bnez a5,1c0099b2 <__rt_bridge_printf_flush+0x2e> 1c0099aa: 4422 lw s0,8(sp) 1c0099ac: 40b2 lw ra,12(sp) 1c0099ae: 0141 addi sp,sp,16 1c0099b0: bf6d j 1c00996a <__rt_bridge_clear_notif> 1c0099b2: 3d69 jal 1c00984c <__rt_bridge_wait> 1c0099b4: bfcd j 1c0099a6 <__rt_bridge_printf_flush+0x22> 1c0099b6: 40b2 lw ra,12(sp) 1c0099b8: 4422 lw s0,8(sp) 1c0099ba: 0141 addi sp,sp,16 1c0099bc: 8082 ret 1c0099be <__rt_bridge_req_shutdown>: 1c0099be: 1141 addi sp,sp,-16 1c0099c0: c606 sw ra,12(sp) 1c0099c2: c422 sw s0,8(sp) 1c0099c4: c226 sw s1,4(sp) 1c0099c6: 3f2d jal 1c009900 <__rt_bridge_check_connection> 1c0099c8: 1c0017b7 lui a5,0x1c001 1c0099cc: fdc78793 addi a5,a5,-36 # 1c000fdc <__hal_debug_struct> 1c0099d0: 479c lw a5,8(a5) 1c0099d2: cb95 beqz a5,1c009a06 <__rt_bridge_req_shutdown+0x48> 1c0099d4: 3f45 jal 1c009984 <__rt_bridge_printf_flush> 1c0099d6: 1a1044b7 lui s1,0x1a104 1c0099da: 441d li s0,7 1c0099dc: 58fc lw a5,116(s1) 1c0099de: 83a5 srli a5,a5,0x9 1c0099e0: 8b9d andi a5,a5,7 1c0099e2: 02878763 beq a5,s0,1c009a10 <__rt_bridge_req_shutdown+0x52> 1c0099e6: 1a1044b7 lui s1,0x1a104 1c0099ea: 441d li s0,7 1c0099ec: 58fc lw a5,116(s1) 1c0099ee: 83a5 srli a5,a5,0x9 1c0099f0: 8b9d andi a5,a5,7 1c0099f2: 02879163 bne a5,s0,1c009a14 <__rt_bridge_req_shutdown+0x56> 1c0099f6: 1a1044b7 lui s1,0x1a104 1c0099fa: 441d li s0,7 1c0099fc: 58fc lw a5,116(s1) 1c0099fe: 83a5 srli a5,a5,0x9 1c009a00: 8b9d andi a5,a5,7 1c009a02: 00878b63 beq a5,s0,1c009a18 <__rt_bridge_req_shutdown+0x5a> 1c009a06: 40b2 lw ra,12(sp) 1c009a08: 4422 lw s0,8(sp) 1c009a0a: 4492 lw s1,4(sp) 1c009a0c: 0141 addi sp,sp,16 1c009a0e: 8082 ret 1c009a10: 3d35 jal 1c00984c <__rt_bridge_wait> 1c009a12: b7e9 j 1c0099dc <__rt_bridge_req_shutdown+0x1e> 1c009a14: 3d25 jal 1c00984c <__rt_bridge_wait> 1c009a16: bfd9 j 1c0099ec <__rt_bridge_req_shutdown+0x2e> 1c009a18: 3d15 jal 1c00984c <__rt_bridge_wait> 1c009a1a: b7cd j 1c0099fc <__rt_bridge_req_shutdown+0x3e> 1c009a1c <__rt_bridge_init>: 1c009a1c: 1c0017b7 lui a5,0x1c001 1c009a20: 1a10a737 lui a4,0x1a10a 1c009a24: fdc78793 addi a5,a5,-36 # 1c000fdc <__hal_debug_struct> 1c009a28: 81070713 addi a4,a4,-2032 # 1a109810 <__l1_end+0xa1061fc> 1c009a2c: 0ae7ac23 sw a4,184(a5) 1c009a30: 4741 li a4,16 1c009a32: 0a07a223 sw zero,164(a5) 1c009a36: 0a07a623 sw zero,172(a5) 1c009a3a: 0a07aa23 sw zero,180(a5) 1c009a3e: 0ae7ae23 sw a4,188(a5) 1c009a42: 00400793 li a5,4 1c009a46: 0007a823 sw zero,16(a5) 1c009a4a: 0007a023 sw zero,0(a5) 1c009a4e: 8082 ret 1c009a50 <__rt_thread_enqueue_ready>: 1c009a50: 01802703 lw a4,24(zero) # 18 <__rt_ready_queue> 1c009a54: 02052c23 sw zero,56(a0) 1c009a58: 01800793 li a5,24 1c009a5c: e711 bnez a4,1c009a68 <__rt_thread_enqueue_ready+0x18> 1c009a5e: c388 sw a0,0(a5) 1c009a60: c3c8 sw a0,4(a5) 1c009a62: 0c052a23 sw zero,212(a0) 1c009a66: 8082 ret 1c009a68: 43d8 lw a4,4(a5) 1c009a6a: df08 sw a0,56(a4) 1c009a6c: bfd5 j 1c009a60 <__rt_thread_enqueue_ready+0x10> 1c009a6e <__rt_thread_sleep>: 1c009a6e: 01800713 li a4,24 1c009a72: 4708 lw a0,8(a4) 1c009a74: 01800793 li a5,24 1c009a78: 438c lw a1,0(a5) 1c009a7a: c999 beqz a1,1c009a90 <__rt_thread_sleep+0x22> 1c009a7c: 5d98 lw a4,56(a1) 1c009a7e: c398 sw a4,0(a5) 1c009a80: 4705 li a4,1 1c009a82: 0ce5aa23 sw a4,212(a1) 1c009a86: 00b50c63 beq a0,a1,1c009a9e <__rt_thread_sleep+0x30> 1c009a8a: c78c sw a1,8(a5) 1c009a8c: 83bfe06f j 1c0082c6 <__rt_thread_switch> 1c009a90: 10500073 wfi 1c009a94: 30045073 csrwi mstatus,8 1c009a98: 30047773 csrrci a4,mstatus,8 1c009a9c: bff1 j 1c009a78 <__rt_thread_sleep+0xa> 1c009a9e: 8082 ret 1c009aa0 <rt_thread_exit>: 1c009aa0: 300477f3 csrrci a5,mstatus,8 1c009aa4: 02002783 lw a5,32(zero) # 20 <__rt_thread_current> 1c009aa8: 4705 li a4,1 1c009aaa: c3e8 sw a0,68(a5) 1c009aac: 5fc8 lw a0,60(a5) 1c009aae: c3b8 sw a4,64(a5) 1c009ab0: c909 beqz a0,1c009ac2 <rt_thread_exit+0x22> 1c009ab2: 0d452783 lw a5,212(a0) 1c009ab6: c791 beqz a5,1c009ac2 <rt_thread_exit+0x22> 1c009ab8: 1141 addi sp,sp,-16 1c009aba: c606 sw ra,12(sp) 1c009abc: 3f51 jal 1c009a50 <__rt_thread_enqueue_ready> 1c009abe: 40b2 lw ra,12(sp) 1c009ac0: 0141 addi sp,sp,16 1c009ac2: b775 j 1c009a6e <__rt_thread_sleep> 1c009ac4 <__rt_thread_wakeup>: 1c009ac4: 5d18 lw a4,56(a0) 1c009ac6: eb09 bnez a4,1c009ad8 <__rt_thread_wakeup+0x14> 1c009ac8: 02002703 lw a4,32(zero) # 20 <__rt_thread_current> 1c009acc: 00a70663 beq a4,a0,1c009ad8 <__rt_thread_wakeup+0x14> 1c009ad0: 0d452783 lw a5,212(a0) 1c009ad4: c391 beqz a5,1c009ad8 <__rt_thread_wakeup+0x14> 1c009ad6: bfad j 1c009a50 <__rt_thread_enqueue_ready> 1c009ad8: 8082 ret 1c009ada <__rt_thread_sched_init>: 1c009ada: 1141 addi sp,sp,-16 1c009adc: c422 sw s0,8(sp) 1c009ade: 1c0087b7 lui a5,0x1c008 1c009ae2: 1c001437 lui s0,0x1c001 1c009ae6: c226 sw s1,4(sp) 1c009ae8: c04a sw s2,0(sp) 1c009aea: c606 sw ra,12(sp) 1c009aec: ee040413 addi s0,s0,-288 # 1c000ee0 <__rt_thread_main> 1c009af0: 2c078793 addi a5,a5,704 # 1c0082c0 <__rt_thread_start> 1c009af4: c01c sw a5,0(s0) 1c009af6: 1c00a7b7 lui a5,0x1c00a 1c009afa: 04840913 addi s2,s0,72 1c009afe: aa078793 addi a5,a5,-1376 # 1c009aa0 <rt_thread_exit> 1c009b02: 01800493 li s1,24 1c009b06: c45c sw a5,12(s0) 1c009b08: 854a mv a0,s2 1c009b0a: 4785 li a5,1 1c009b0c: e3ff6597 auipc a1,0xe3ff6 1c009b10: 51c58593 addi a1,a1,1308 # 28 <__rt_sched> 1c009b14: 0cf42a23 sw a5,212(s0) 1c009b18: 0004a023 sw zero,0(s1) # 1a104000 <__l1_end+0xa1009ec> 1c009b1c: 02042a23 sw zero,52(s0) 1c009b20: 00042223 sw zero,4(s0) 1c009b24: 00042423 sw zero,8(s0) 1c009b28: 2829 jal 1c009b42 <__rt_event_init> 1c009b2a: 02402783 lw a5,36(zero) # 24 <__rt_first_free> 1c009b2e: c480 sw s0,8(s1) 1c009b30: 40b2 lw ra,12(sp) 1c009b32: d03c sw a5,96(s0) 1c009b34: 4422 lw s0,8(sp) 1c009b36: 03202223 sw s2,36(zero) # 24 <__rt_first_free> 1c009b3a: 4492 lw s1,4(sp) 1c009b3c: 4902 lw s2,0(sp) 1c009b3e: 0141 addi sp,sp,16 1c009b40: 8082 ret 1c009b42 <__rt_event_init>: 1c009b42: 02052023 sw zero,32(a0) 1c009b46: 02052223 sw zero,36(a0) 1c009b4a: 02052823 sw zero,48(a0) 1c009b4e: 00052023 sw zero,0(a0) 1c009b52: 8082 ret 1c009b54 <__rt_wait_event_prepare_blocking>: 1c009b54: 02400793 li a5,36 1c009b58: 4388 lw a0,0(a5) 1c009b5a: 4d18 lw a4,24(a0) 1c009b5c: 02052223 sw zero,36(a0) 1c009b60: c398 sw a4,0(a5) 1c009b62: 4785 li a5,1 1c009b64: d11c sw a5,32(a0) 1c009b66: 00052023 sw zero,0(a0) 1c009b6a: 8082 ret 1c009b6c <rt_event_alloc>: 1c009b6c: 1141 addi sp,sp,-16 1c009b6e: c422 sw s0,8(sp) 1c009b70: 842e mv s0,a1 1c009b72: c606 sw ra,12(sp) 1c009b74: c226 sw s1,4(sp) 1c009b76: 300474f3 csrrci s1,mstatus,8 1c009b7a: f14027f3 csrr a5,mhartid 1c009b7e: 8795 srai a5,a5,0x5 1c009b80: 03f7f793 andi a5,a5,63 1c009b84: 477d li a4,31 1c009b86: 00378513 addi a0,a5,3 1c009b8a: 00e79363 bne a5,a4,1c009b90 <rt_event_alloc+0x24> 1c009b8e: 4501 li a0,0 1c009b90: 08c00593 li a1,140 1c009b94: 02b405b3 mul a1,s0,a1 1c009b98: 882ff0ef jal ra,1c008c1a <rt_alloc> 1c009b9c: 87aa mv a5,a0 1c009b9e: 557d li a0,-1 1c009ba0: cf91 beqz a5,1c009bbc <rt_event_alloc+0x50> 1c009ba2: 02402683 lw a3,36(zero) # 24 <__rt_first_free> 1c009ba6: 4581 li a1,0 1c009ba8: 4601 li a2,0 1c009baa: 02400713 li a4,36 1c009bae: 00864c63 blt a2,s0,1c009bc6 <rt_event_alloc+0x5a> 1c009bb2: c191 beqz a1,1c009bb6 <rt_event_alloc+0x4a> 1c009bb4: c314 sw a3,0(a4) 1c009bb6: 30049073 csrw mstatus,s1 1c009bba: 4501 li a0,0 1c009bbc: 40b2 lw ra,12(sp) 1c009bbe: 4422 lw s0,8(sp) 1c009bc0: 4492 lw s1,4(sp) 1c009bc2: 0141 addi sp,sp,16 1c009bc4: 8082 ret 1c009bc6: cf94 sw a3,24(a5) 1c009bc8: 0207a023 sw zero,32(a5) 1c009bcc: 0207a223 sw zero,36(a5) 1c009bd0: 0207a823 sw zero,48(a5) 1c009bd4: 0007a023 sw zero,0(a5) 1c009bd8: 86be mv a3,a5 1c009bda: 0605 addi a2,a2,1 1c009bdc: 4585 li a1,1 1c009bde: 08c78793 addi a5,a5,140 1c009be2: b7f1 j 1c009bae <rt_event_alloc+0x42> 1c009be4 <rt_event_get>: 1c009be4: 30047773 csrrci a4,mstatus,8 1c009be8: 02400793 li a5,36 1c009bec: 4388 lw a0,0(a5) 1c009bee: c509 beqz a0,1c009bf8 <rt_event_get+0x14> 1c009bf0: 4d14 lw a3,24(a0) 1c009bf2: c150 sw a2,4(a0) 1c009bf4: c394 sw a3,0(a5) 1c009bf6: c10c sw a1,0(a0) 1c009bf8: 30071073 csrw mstatus,a4 1c009bfc: 8082 ret 1c009bfe <rt_event_get_blocking>: 1c009bfe: 30047773 csrrci a4,mstatus,8 1c009c02: 02400793 li a5,36 1c009c06: 4388 lw a0,0(a5) 1c009c08: c909 beqz a0,1c009c1a <rt_event_get_blocking+0x1c> 1c009c0a: 4d14 lw a3,24(a0) 1c009c0c: 00052223 sw zero,4(a0) 1c009c10: c394 sw a3,0(a5) 1c009c12: 4785 li a5,1 1c009c14: 00052023 sw zero,0(a0) 1c009c18: d11c sw a5,32(a0) 1c009c1a: 30071073 csrw mstatus,a4 1c009c1e: 8082 ret 1c009c20 <rt_event_push>: 1c009c20: 30047773 csrrci a4,mstatus,8 1c009c24: 02400693 li a3,36 1c009c28: 42d4 lw a3,4(a3) 1c009c2a: 00052c23 sw zero,24(a0) 1c009c2e: 02400793 li a5,36 1c009c32: e691 bnez a3,1c009c3e <rt_event_push+0x1e> 1c009c34: c3c8 sw a0,4(a5) 1c009c36: c788 sw a0,8(a5) 1c009c38: 30071073 csrw mstatus,a4 1c009c3c: 8082 ret 1c009c3e: 4794 lw a3,8(a5) 1c009c40: ce88 sw a0,24(a3) 1c009c42: bfd5 j 1c009c36 <rt_event_push+0x16> 1c009c44 <__rt_event_execute>: 1c009c44: 1141 addi sp,sp,-16 1c009c46: c422 sw s0,8(sp) 1c009c48: 02400793 li a5,36 1c009c4c: 43dc lw a5,4(a5) 1c009c4e: c606 sw ra,12(sp) 1c009c50: c226 sw s1,4(sp) 1c009c52: 02400413 li s0,36 1c009c56: eb91 bnez a5,1c009c6a <__rt_event_execute+0x26> 1c009c58: c1a9 beqz a1,1c009c9a <__rt_event_execute+0x56> 1c009c5a: 10500073 wfi 1c009c5e: 30045073 csrwi mstatus,8 1c009c62: 300477f3 csrrci a5,mstatus,8 1c009c66: 405c lw a5,4(s0) 1c009c68: cb8d beqz a5,1c009c9a <__rt_event_execute+0x56> 1c009c6a: 4485 li s1,1 1c009c6c: 4f98 lw a4,24(a5) 1c009c6e: 53d4 lw a3,36(a5) 1c009c70: 00978823 sb s1,16(a5) 1c009c74: c058 sw a4,4(s0) 1c009c76: 43c8 lw a0,4(a5) 1c009c78: 4398 lw a4,0(a5) 1c009c7a: e691 bnez a3,1c009c86 <__rt_event_execute+0x42> 1c009c7c: 5394 lw a3,32(a5) 1c009c7e: e681 bnez a3,1c009c86 <__rt_event_execute+0x42> 1c009c80: 4014 lw a3,0(s0) 1c009c82: c01c sw a5,0(s0) 1c009c84: cf94 sw a3,24(a5) 1c009c86: 0207a023 sw zero,32(a5) 1c009c8a: c711 beqz a4,1c009c96 <__rt_event_execute+0x52> 1c009c8c: 30045073 csrwi mstatus,8 1c009c90: 9702 jalr a4 1c009c92: 300477f3 csrrci a5,mstatus,8 1c009c96: 405c lw a5,4(s0) 1c009c98: fbf1 bnez a5,1c009c6c <__rt_event_execute+0x28> 1c009c9a: 40b2 lw ra,12(sp) 1c009c9c: 4422 lw s0,8(sp) 1c009c9e: 4492 lw s1,4(sp) 1c009ca0: 0141 addi sp,sp,16 1c009ca2: 8082 ret 1c009ca4 <__rt_wait_event>: 1c009ca4: 1141 addi sp,sp,-16 1c009ca6: c422 sw s0,8(sp) 1c009ca8: c606 sw ra,12(sp) 1c009caa: 842a mv s0,a0 1c009cac: 501c lw a5,32(s0) 1c009cae: ef81 bnez a5,1c009cc6 <__rt_wait_event+0x22> 1c009cb0: 581c lw a5,48(s0) 1c009cb2: eb91 bnez a5,1c009cc6 <__rt_wait_event+0x22> 1c009cb4: 02400793 li a5,36 1c009cb8: 4398 lw a4,0(a5) 1c009cba: 40b2 lw ra,12(sp) 1c009cbc: c380 sw s0,0(a5) 1c009cbe: cc18 sw a4,24(s0) 1c009cc0: 4422 lw s0,8(sp) 1c009cc2: 0141 addi sp,sp,16 1c009cc4: 8082 ret 1c009cc6: 4585 li a1,1 1c009cc8: 4501 li a0,0 1c009cca: 3fad jal 1c009c44 <__rt_event_execute> 1c009ccc: b7c5 j 1c009cac <__rt_wait_event+0x8> 1c009cce <rt_event_wait>: 1c009cce: 1141 addi sp,sp,-16 1c009cd0: c606 sw ra,12(sp) 1c009cd2: c422 sw s0,8(sp) 1c009cd4: 30047473 csrrci s0,mstatus,8 1c009cd8: 37f1 jal 1c009ca4 <__rt_wait_event> 1c009cda: 30041073 csrw mstatus,s0 1c009cde: 40b2 lw ra,12(sp) 1c009ce0: 4422 lw s0,8(sp) 1c009ce2: 0141 addi sp,sp,16 1c009ce4: 8082 ret 1c009ce6 <__rt_event_sched_init>: 1c009ce6: 02400513 li a0,36 1c009cea: 00052023 sw zero,0(a0) 1c009cee: 00052223 sw zero,4(a0) 1c009cf2: 4585 li a1,1 1c009cf4: 0511 addi a0,a0,4 1c009cf6: bd9d j 1c009b6c <rt_event_alloc> 1c009cf8 <__rt_fll_set_freq>: 1c009cf8: 1141 addi sp,sp,-16 1c009cfa: c422 sw s0,8(sp) 1c009cfc: c226 sw s1,4(sp) 1c009cfe: c606 sw ra,12(sp) 1c009d00: 842a mv s0,a0 1c009d02: 84ae mv s1,a1 1c009d04: e111 bnez a0,1c009d08 <__rt_fll_set_freq+0x10> 1c009d06: 3965 jal 1c0099be <__rt_bridge_req_shutdown> 1c009d08: 8526 mv a0,s1 1c009d0a: feafe0ef jal ra,1c0084f4 <__clzsi2> 1c009d0e: 1579 addi a0,a0,-2 1c009d10: 00155793 srli a5,a0,0x1 1c009d14: e391 bnez a5,1c009d18 <__rt_fll_set_freq+0x20> 1c009d16: 4785 li a5,1 1c009d18: fff78713 addi a4,a5,-1 1c009d1c: 4505 li a0,1 1c009d1e: 00e51533 sll a0,a0,a4 1c009d22: 00f494b3 sll s1,s1,a5 1c009d26: 7761 lui a4,0xffff8 1c009d28: 8f65 and a4,a4,s1 1c009d2a: 1c0016b7 lui a3,0x1c001 1c009d2e: 953a add a0,a0,a4 1c009d30: 1f068693 addi a3,a3,496 # 1c0011f0 <__rt_fll_freq> 1c009d34: 00241713 slli a4,s0,0x2 1c009d38: 9736 add a4,a4,a3 1c009d3a: 00f55533 srl a0,a0,a5 1c009d3e: c308 sw a0,0(a4) 1c009d40: 1c001737 lui a4,0x1c001 1c009d44: 18c70713 addi a4,a4,396 # 1c00118c <__rt_fll_is_on> 1c009d48: 9722 add a4,a4,s0 1c009d4a: 00074703 lbu a4,0(a4) 1c009d4e: c715 beqz a4,1c009d7a <__rt_fll_set_freq+0x82> 1c009d50: 1a100737 lui a4,0x1a100 1c009d54: 0711 addi a4,a4,4 1c009d56: 0412 slli s0,s0,0x4 1c009d58: 943a add s0,s0,a4 1c009d5a: 4018 lw a4,0(s0) 1c009d5c: 80bd srli s1,s1,0xf 1c009d5e: 76c1 lui a3,0xffff0 1c009d60: 04c2 slli s1,s1,0x10 1c009d62: 8f75 and a4,a4,a3 1c009d64: 80c1 srli s1,s1,0x10 1c009d66: 0785 addi a5,a5,1 1c009d68: c40006b7 lui a3,0xc4000 1c009d6c: 8f45 or a4,a4,s1 1c009d6e: 8bbd andi a5,a5,15 1c009d70: 16fd addi a3,a3,-1 1c009d72: 07ea slli a5,a5,0x1a 1c009d74: 8f75 and a4,a4,a3 1c009d76: 8fd9 or a5,a5,a4 1c009d78: c01c sw a5,0(s0) 1c009d7a: 40b2 lw ra,12(sp) 1c009d7c: 4422 lw s0,8(sp) 1c009d7e: 4492 lw s1,4(sp) 1c009d80: 0141 addi sp,sp,16 1c009d82: 8082 ret 1c009d84 <__rt_fll_init>: 1c009d84: 1141 addi sp,sp,-16 1c009d86: 1a1005b7 lui a1,0x1a100 1c009d8a: 00451613 slli a2,a0,0x4 1c009d8e: c226 sw s1,4(sp) 1c009d90: 84aa mv s1,a0 1c009d92: 00458513 addi a0,a1,4 # 1a100004 <__l1_end+0xa0fc9f0> 1c009d96: 9532 add a0,a0,a2 1c009d98: 4114 lw a3,0(a0) 1c009d9a: c606 sw ra,12(sp) 1c009d9c: c422 sw s0,8(sp) 1c009d9e: 87b6 mv a5,a3 1c009da0: 0406c963 bltz a3,1c009df2 <__rt_fll_init+0x6e> 1c009da4: 00858793 addi a5,a1,8 1c009da8: 97b2 add a5,a5,a2 1c009daa: 4398 lw a4,0(a5) 1c009dac: 7841 lui a6,0xffff0 1c009dae: 3ff80813 addi a6,a6,1023 # ffff03ff <pulp__FC+0xffff0400> 1c009db2: 01077733 and a4,a4,a6 1c009db6: 6809 lui a6,0x2 1c009db8: 80080813 addi a6,a6,-2048 # 1800 <__rt_hyper_pending_emu_stride+0x1558> 1c009dbc: 01076733 or a4,a4,a6 1c009dc0: f0010837 lui a6,0xf0010 1c009dc4: 187d addi a6,a6,-1 1c009dc6: 01077733 and a4,a4,a6 1c009dca: 00500837 lui a6,0x500 1c009dce: 01076733 or a4,a4,a6 1c009dd2: 05b1 addi a1,a1,12 1c009dd4: c398 sw a4,0(a5) 1c009dd6: 962e add a2,a2,a1 1c009dd8: 421c lw a5,0(a2) 1c009dda: fc010737 lui a4,0xfc010 1c009dde: 177d addi a4,a4,-1 1c009de0: 8ff9 and a5,a5,a4 1c009de2: 014c0737 lui a4,0x14c0 1c009de6: 8fd9 or a5,a5,a4 1c009de8: c21c sw a5,0(a2) 1c009dea: c00007b7 lui a5,0xc0000 1c009dee: 8fd5 or a5,a5,a3 1c009df0: c11c sw a5,0(a0) 1c009df2: 1c001637 lui a2,0x1c001 1c009df6: 00249713 slli a4,s1,0x2 1c009dfa: 1f060613 addi a2,a2,496 # 1c0011f0 <__rt_fll_freq> 1c009dfe: 9732 add a4,a4,a2 1c009e00: 4300 lw s0,0(a4) 1c009e02: c015 beqz s0,1c009e26 <__rt_fll_init+0xa2> 1c009e04: 85a2 mv a1,s0 1c009e06: 8526 mv a0,s1 1c009e08: 3dc5 jal 1c009cf8 <__rt_fll_set_freq> 1c009e0a: 1c001537 lui a0,0x1c001 1c009e0e: 18c50513 addi a0,a0,396 # 1c00118c <__rt_fll_is_on> 1c009e12: 9526 add a0,a0,s1 1c009e14: 4785 li a5,1 1c009e16: 00f50023 sb a5,0(a0) 1c009e1a: 40b2 lw ra,12(sp) 1c009e1c: 8522 mv a0,s0 1c009e1e: 4422 lw s0,8(sp) 1c009e20: 4492 lw s1,4(sp) 1c009e22: 0141 addi sp,sp,16 1c009e24: 8082 ret 1c009e26: 06c2 slli a3,a3,0x10 1c009e28: 83e9 srli a5,a5,0x1a 1c009e2a: 82c1 srli a3,a3,0x10 1c009e2c: 8bbd andi a5,a5,15 1c009e2e: 06be slli a3,a3,0xf 1c009e30: 17fd addi a5,a5,-1 1c009e32: 00f6d433 srl s0,a3,a5 1c009e36: c300 sw s0,0(a4) 1c009e38: bfc9 j 1c009e0a <__rt_fll_init+0x86> 1c009e3a <__rt_fll_deinit>: 1c009e3a: 1c0017b7 lui a5,0x1c001 1c009e3e: 18c78793 addi a5,a5,396 # 1c00118c <__rt_fll_is_on> 1c009e42: 953e add a0,a0,a5 1c009e44: 00050023 sb zero,0(a0) 1c009e48: 8082 ret 1c009e4a <__rt_flls_constructor>: 1c009e4a: 1c0017b7 lui a5,0x1c001 1c009e4e: 1e07a823 sw zero,496(a5) # 1c0011f0 <__rt_fll_freq> 1c009e52: 1f078793 addi a5,a5,496 1c009e56: 0007a223 sw zero,4(a5) 1c009e5a: 1c0017b7 lui a5,0x1c001 1c009e5e: 18079623 sh zero,396(a5) # 1c00118c <__rt_fll_is_on> 1c009e62: 8082 ret 1c009e64 <gcd>: 1c009e64: cd19 beqz a0,1c009e82 <gcd+0x1e> 1c009e66: cd81 beqz a1,1c009e7e <gcd+0x1a> 1c009e68: 00054463 bltz a0,1c009e70 <gcd+0xc> 1c009e6c: 0005d563 bgez a1,1c009e76 <gcd+0x12> 1c009e70: 55fd li a1,-1 1c009e72: a031 j 1c009e7e <gcd+0x1a> 1c009e74: 85be mv a1,a5 1c009e76: 02b567b3 rem a5,a0,a1 1c009e7a: 852e mv a0,a1 1c009e7c: ffe5 bnez a5,1c009e74 <gcd+0x10> 1c009e7e: 852e mv a0,a1 1c009e80: 8082 ret 1c009e82: 4581 li a1,0 1c009e84: bfed j 1c009e7e <gcd+0x1a> 1c009e86 <__rt_freq_set_periph_freq.isra.3.constprop.4>: 1c009e86: 1101 addi sp,sp,-32 1c009e88: 1c0017b7 lui a5,0x1c001 1c009e8c: c84a sw s2,16(sp) 1c009e8e: 1907a903 lw s2,400(a5) # 1c001190 <__rt_periph_lcm> 1c009e92: c452 sw s4,8(sp) 1c009e94: 8a2e mv s4,a1 1c009e96: 85ca mv a1,s2 1c009e98: ce06 sw ra,28(sp) 1c009e9a: cc22 sw s0,24(sp) 1c009e9c: ca26 sw s1,20(sp) 1c009e9e: 842a mv s0,a0 1c009ea0: c64e sw s3,12(sp) 1c009ea2: 89aa mv s3,a0 1c009ea4: 37c1 jal 1c009e64 <gcd> 1c009ea6: 02a44533 div a0,s0,a0 1c009eaa: 03250933 mul s2,a0,s2 1c009eae: 4511 li a0,4 1c009eb0: 82dff0ef jal ra,1c0096dc <__rt_cbsys_exec> 1c009eb4: 1c0017b7 lui a5,0x1c001 1c009eb8: 1f07a783 lw a5,496(a5) # 1c0011f0 <__rt_fll_freq> 1c009ebc: 028954b3 divu s1,s2,s0 1c009ec0: 0527f263 bleu s2,a5,1c009f04 <__rt_freq_set_periph_freq.isra.3.constprop.4+0x7e> 1c009ec4: 1a1047b7 lui a5,0x1a104 1c009ec8: 0c97aa23 sw s1,212(a5) # 1a1040d4 <__l1_end+0xa100ac0> 1c009ecc: 4705 li a4,1 1c009ece: 0ce7ae23 sw a4,220(a5) 1c009ed2: 85a2 mv a1,s0 1c009ed4: 4501 li a0,0 1c009ed6: 350d jal 1c009cf8 <__rt_fll_set_freq> 1c009ed8: 57fd li a5,-1 1c009eda: 00fa0963 beq s4,a5,1c009eec <__rt_freq_set_periph_freq.isra.3.constprop.4+0x66> 1c009ede: c099 beqz s1,1c009ee4 <__rt_freq_set_periph_freq.isra.3.constprop.4+0x5e> 1c009ee0: 029459b3 divu s3,s0,s1 1c009ee4: 1c0017b7 lui a5,0x1c001 1c009ee8: 1f37ac23 sw s3,504(a5) # 1c0011f8 <__rt_freq_domains> 1c009eec: 4515 li a0,5 1c009eee: feeff0ef jal ra,1c0096dc <__rt_cbsys_exec> 1c009ef2: 40f2 lw ra,28(sp) 1c009ef4: 4462 lw s0,24(sp) 1c009ef6: 44d2 lw s1,20(sp) 1c009ef8: 4942 lw s2,16(sp) 1c009efa: 49b2 lw s3,12(sp) 1c009efc: 4a22 lw s4,8(sp) 1c009efe: 4501 li a0,0 1c009f00: 6105 addi sp,sp,32 1c009f02: 8082 ret 1c009f04: 85a2 mv a1,s0 1c009f06: 4501 li a0,0 1c009f08: 3bc5 jal 1c009cf8 <__rt_fll_set_freq> 1c009f0a: 1a1047b7 lui a5,0x1a104 1c009f0e: 0c97aa23 sw s1,212(a5) # 1a1040d4 <__l1_end+0xa100ac0> 1c009f12: 4705 li a4,1 1c009f14: 0ce7ae23 sw a4,220(a5) 1c009f18: b7c1 j 1c009ed8 <__rt_freq_set_periph_freq.isra.3.constprop.4+0x52> 1c009f1a <rt_freq_set_and_get>: 1c009f1a: 1141 addi sp,sp,-16 1c009f1c: 852e mv a0,a1 1c009f1e: c606 sw ra,12(sp) 1c009f20: c422 sw s0,8(sp) 1c009f22: 30047473 csrrci s0,mstatus,8 1c009f26: 4581 li a1,0 1c009f28: 3fb9 jal 1c009e86 <__rt_freq_set_periph_freq.isra.3.constprop.4> 1c009f2a: 30041073 csrw mstatus,s0 1c009f2e: 40b2 lw ra,12(sp) 1c009f30: 4422 lw s0,8(sp) 1c009f32: 00a03533 snez a0,a0 1c009f36: 40a00533 neg a0,a0 1c009f3a: 0141 addi sp,sp,16 1c009f3c: 8082 ret 1c009f3e <__rt_freq_init>: 1c009f3e: 1141 addi sp,sp,-16 1c009f40: c422 sw s0,8(sp) 1c009f42: c606 sw ra,12(sp) 1c009f44: 3719 jal 1c009e4a <__rt_flls_constructor> 1c009f46: 1c0017b7 lui a5,0x1c001 1c009f4a: 09c7a703 lw a4,156(a5) # 1c00109c <__rt_platform> 1c009f4e: 4785 li a5,1 1c009f50: 1c001437 lui s0,0x1c001 1c009f54: 02f70663 beq a4,a5,1c009f80 <__rt_freq_init+0x42> 1c009f58: 4501 li a0,0 1c009f5a: 352d jal 1c009d84 <__rt_fll_init> 1c009f5c: 1ea42c23 sw a0,504(s0) # 1c0011f8 <__rt_freq_domains> 1c009f60: 1a1047b7 lui a5,0x1a104 1c009f64: 4709 li a4,2 1c009f66: 0ce7a823 sw a4,208(a5) # 1a1040d0 <__l1_end+0xa100abc> 1c009f6a: 4705 li a4,1 1c009f6c: 0ce7ac23 sw a4,216(a5) 1c009f70: 40b2 lw ra,12(sp) 1c009f72: 4422 lw s0,8(sp) 1c009f74: 0ce7ae23 sw a4,220(a5) 1c009f78: 0ce7aa23 sw a4,212(a5) 1c009f7c: 0141 addi sp,sp,16 1c009f7e: 8082 ret 1c009f80: 026267b7 lui a5,0x2626 1c009f84: a0078793 addi a5,a5,-1536 # 2625a00 <__l1_heap_size+0x2619014> 1c009f88: 1ef42c23 sw a5,504(s0) 1c009f8c: bfd1 j 1c009f60 <__rt_freq_init+0x22> 1c009f8e <hal_itc_wait_for_event_noirq>: 1c009f8e: 1a10a7b7 lui a5,0x1a10a 1c009f92: 300476f3 csrrci a3,mstatus,8 1c009f96: 80c7a703 lw a4,-2036(a5) # 1a10980c <__l1_end+0xa1061f8> 1c009f9a: 8f69 and a4,a4,a0 1c009f9c: eb11 bnez a4,1c009fb0 <hal_itc_wait_for_event_noirq+0x22> 1c009f9e: 80a7a223 sw a0,-2044(a5) 1c009fa2: 10500073 wfi 1c009fa6: 80a7a423 sw a0,-2040(a5) 1c009faa: 30069073 csrw mstatus,a3 1c009fae: b7d5 j 1c009f92 <hal_itc_wait_for_event_noirq+0x4> 1c009fb0: 80a7aa23 sw a0,-2028(a5) 1c009fb4: 30069073 csrw mstatus,a3 1c009fb8: 8082 ret 1c009fba <__rt_pmu_cluster_power_down>: 1c009fba: 1a1047b7 lui a5,0x1a104 1c009fbe: 5bbc lw a5,112(a5) 1c009fc0: 01079713 slli a4,a5,0x10 1c009fc4: 02074c63 bltz a4,1c009ffc <__rt_pmu_cluster_power_down+0x42> 1c009fc8: 1141 addi sp,sp,-16 1c009fca: c422 sw s0,8(sp) 1c009fcc: c606 sw ra,12(sp) 1c009fce: c226 sw s1,4(sp) 1c009fd0: 1a104437 lui s0,0x1a104 1c009fd4: 547c lw a5,108(s0) 1c009fd6: e385 bnez a5,1c009ff6 <__rt_pmu_cluster_power_down+0x3c> 1c009fd8: 4485 li s1,1 1c009fda: c444 sw s1,12(s0) 1c009fdc: 478d li a5,3 1c009fde: d83c sw a5,112(s0) 1c009fe0: 00800537 lui a0,0x800 1c009fe4: 376d jal 1c009f8e <hal_itc_wait_for_event_noirq> 1c009fe6: d824 sw s1,112(s0) 1c009fe8: 4422 lw s0,8(sp) 1c009fea: 40b2 lw ra,12(sp) 1c009fec: 4492 lw s1,4(sp) 1c009fee: 00400537 lui a0,0x400 1c009ff2: 0141 addi sp,sp,16 1c009ff4: bf69 j 1c009f8e <hal_itc_wait_for_event_noirq> 1c009ff6: 4505 li a0,1 1c009ff8: 2a11 jal 1c00a10c <rt_time_wait_us> 1c009ffa: bfe9 j 1c009fd4 <__rt_pmu_cluster_power_down+0x1a> 1c009ffc: 8082 ret 1c009ffe <__rt_pmu_cluster_power_up>: 1c009ffe: 1141 addi sp,sp,-16 1c00a000: c606 sw ra,12(sp) 1c00a002: c422 sw s0,8(sp) 1c00a004: 478d li a5,3 1c00a006: 1a104437 lui s0,0x1a104 1c00a00a: d83c sw a5,112(s0) 1c00a00c: 00400537 lui a0,0x400 1c00a010: 3fbd jal 1c009f8e <hal_itc_wait_for_event_noirq> 1c00a012: 02700793 li a5,39 1c00a016: d83c sw a5,112(s0) 1c00a018: 00800537 lui a0,0x800 1c00a01c: 3f8d jal 1c009f8e <hal_itc_wait_for_event_noirq> 1c00a01e: 6791 lui a5,0x4 1c00a020: 00042623 sw zero,12(s0) # 1a10400c <__l1_end+0xa1009f8> 1c00a024: 02778793 addi a5,a5,39 # 4027 <_l1_preload_size+0xa17> 1c00a028: d83c sw a5,112(s0) 1c00a02a: 40b2 lw ra,12(sp) 1c00a02c: 4422 lw s0,8(sp) 1c00a02e: 4505 li a0,1 1c00a030: 0141 addi sp,sp,16 1c00a032: 8082 ret 1c00a034 <__rt_pmu_init>: 1c00a034: 1a1077b7 lui a5,0x1a107 1c00a038: 4741 li a4,16 1c00a03a: cb98 sw a4,16(a5) 1c00a03c: 1a10a7b7 lui a5,0x1a10a 1c00a040: 02000737 lui a4,0x2000 1c00a044: 80e7aa23 sw a4,-2028(a5) # 1a109814 <__l1_end+0xa106200> 1c00a048: 4709 li a4,2 1c00a04a: 02e02e23 sw a4,60(zero) # 3c <__rt_pmu_current_sequence> 1c00a04e: 8082 ret 1c00a050 <rt_padframe_set>: 1c00a050: 300476f3 csrrci a3,mstatus,8 1c00a054: 4158 lw a4,4(a0) 1c00a056: 1a1047b7 lui a5,0x1a104 1c00a05a: 4310 lw a2,0(a4) 1c00a05c: cb90 sw a2,16(a5) 1c00a05e: 4350 lw a2,4(a4) 1c00a060: cbd0 sw a2,20(a5) 1c00a062: 4710 lw a2,8(a4) 1c00a064: cf90 sw a2,24(a5) 1c00a066: 4758 lw a4,12(a4) 1c00a068: cfd8 sw a4,28(a5) 1c00a06a: 30069073 csrw mstatus,a3 1c00a06e: 8082 ret 1c00a070 <__rt_padframe_init>: 1c00a070: 1c001537 lui a0,0x1c001 1c00a074: fcc50513 addi a0,a0,-52 # 1c000fcc <__rt_padframe_profiles> 1c00a078: bfe1 j 1c00a050 <rt_padframe_set> 1c00a07a <__rt_time_poweroff>: 1c00a07a: 1a10b7b7 lui a5,0x1a10b 1c00a07e: 47d8 lw a4,12(a5) 1c00a080: 1c0017b7 lui a5,0x1c001 1c00a084: 4501 li a0,0 1c00a086: 18e7aa23 sw a4,404(a5) # 1c001194 <timer_count> 1c00a08a: 8082 ret 1c00a08c <__rt_time_poweron>: 1c00a08c: 1c0017b7 lui a5,0x1c001 1c00a090: 1947a703 lw a4,404(a5) # 1c001194 <timer_count> 1c00a094: 1a10b7b7 lui a5,0x1a10b 1c00a098: 4501 li a0,0 1c00a09a: c7d8 sw a4,12(a5) 1c00a09c: 8082 ret 1c00a09e <rt_event_push_delayed>: 1c00a09e: 30047373 csrrci t1,mstatus,8 1c00a0a2: 1a10b6b7 lui a3,0x1a10b 1c00a0a6: 46d0 lw a2,12(a3) 1c00a0a8: 1c001737 lui a4,0x1c001 1c00a0ac: 20072783 lw a5,512(a4) # 1c001200 <first_delayed> 1c00a0b0: 86ba mv a3,a4 1c00a0b2: 0005d363 bgez a1,1c00a0b8 <rt_event_push_delayed+0x1a> 1c00a0b6: 4581 li a1,0 1c00a0b8: 4779 li a4,30 1c00a0ba: 02e5c5b3 div a1,a1,a4 1c00a0be: 80000737 lui a4,0x80000 1c00a0c2: fff74713 not a4,a4 1c00a0c6: 00e67833 and a6,a2,a4 1c00a0ca: 0585 addi a1,a1,1 1c00a0cc: 962e add a2,a2,a1 1c00a0ce: d950 sw a2,52(a0) 1c00a0d0: 982e add a6,a6,a1 1c00a0d2: 4601 li a2,0 1c00a0d4: c799 beqz a5,1c00a0e2 <rt_event_push_delayed+0x44> 1c00a0d6: 0347a883 lw a7,52(a5) # 1a10b034 <__l1_end+0xa107a20> 1c00a0da: 00e8f8b3 and a7,a7,a4 1c00a0de: 0108e863 bltu a7,a6,1c00a0ee <rt_event_push_delayed+0x50> 1c00a0e2: ca09 beqz a2,1c00a0f4 <rt_event_push_delayed+0x56> 1c00a0e4: ce08 sw a0,24(a2) 1c00a0e6: cd1c sw a5,24(a0) 1c00a0e8: 30031073 csrw mstatus,t1 1c00a0ec: 8082 ret 1c00a0ee: 863e mv a2,a5 1c00a0f0: 4f9c lw a5,24(a5) 1c00a0f2: b7cd j 1c00a0d4 <rt_event_push_delayed+0x36> 1c00a0f4: cd1c sw a5,24(a0) 1c00a0f6: 1a10b7b7 lui a5,0x1a10b 1c00a0fa: 47d8 lw a4,12(a5) 1c00a0fc: 20a6a023 sw a0,512(a3) # 1a10b200 <__l1_end+0xa107bec> 1c00a100: 95ba add a1,a1,a4 1c00a102: cbcc sw a1,20(a5) 1c00a104: 08500713 li a4,133 1c00a108: c3d8 sw a4,4(a5) 1c00a10a: bff9 j 1c00a0e8 <rt_event_push_delayed+0x4a> 1c00a10c <rt_time_wait_us>: 1c00a10c: 1101 addi sp,sp,-32 1c00a10e: 85aa mv a1,a0 1c00a110: 4501 li a0,0 1c00a112: ce06 sw ra,28(sp) 1c00a114: cc22 sw s0,24(sp) 1c00a116: c62e sw a1,12(sp) 1c00a118: 34dd jal 1c009bfe <rt_event_get_blocking> 1c00a11a: 45b2 lw a1,12(sp) 1c00a11c: 842a mv s0,a0 1c00a11e: 3741 jal 1c00a09e <rt_event_push_delayed> 1c00a120: 8522 mv a0,s0 1c00a122: 4462 lw s0,24(sp) 1c00a124: 40f2 lw ra,28(sp) 1c00a126: 6105 addi sp,sp,32 1c00a128: b65d j 1c009cce <rt_event_wait> 1c00a12a <__rt_time_init>: 1c00a12a: 1141 addi sp,sp,-16 1c00a12c: 1c0017b7 lui a5,0x1c001 1c00a130: 2007a023 sw zero,512(a5) # 1c001200 <first_delayed> 1c00a134: 08300713 li a4,131 1c00a138: 1a10b7b7 lui a5,0x1a10b 1c00a13c: c606 sw ra,12(sp) 1c00a13e: c422 sw s0,8(sp) 1c00a140: 1c00a5b7 lui a1,0x1c00a 1c00a144: c3d8 sw a4,4(a5) 1c00a146: 1c258593 addi a1,a1,450 # 1c00a1c2 <__rt_timer_handler> 1c00a14a: 452d li a0,11 1c00a14c: bc0ff0ef jal ra,1c00950c <rt_irq_set_handler> 1c00a150: f14027f3 csrr a5,mhartid 1c00a154: 8795 srai a5,a5,0x5 1c00a156: 6705 lui a4,0x1 1c00a158: 03f7f793 andi a5,a5,63 1c00a15c: 46fd li a3,31 1c00a15e: 80070713 addi a4,a4,-2048 # 800 <__rt_hyper_pending_emu_stride+0x558> 1c00a162: 04d79863 bne a5,a3,1c00a1b2 <__rt_time_init+0x88> 1c00a166: 1a10a7b7 lui a5,0x1a10a 1c00a16a: 80e7a223 sw a4,-2044(a5) # 1a109804 <__l1_end+0xa1061f0> 1c00a16e: 1c00a5b7 lui a1,0x1c00a 1c00a172: 4601 li a2,0 1c00a174: 07a58593 addi a1,a1,122 # 1c00a07a <__rt_time_poweroff> 1c00a178: 4509 li a0,2 1c00a17a: d22ff0ef jal ra,1c00969c <__rt_cbsys_add> 1c00a17e: 1c00a5b7 lui a1,0x1c00a 1c00a182: 842a mv s0,a0 1c00a184: 4601 li a2,0 1c00a186: 08c58593 addi a1,a1,140 # 1c00a08c <__rt_time_poweron> 1c00a18a: 450d li a0,3 1c00a18c: d10ff0ef jal ra,1c00969c <__rt_cbsys_add> 1c00a190: 8d41 or a0,a0,s0 1c00a192: c505 beqz a0,1c00a1ba <__rt_time_init+0x90> 1c00a194: f1402673 csrr a2,mhartid 1c00a198: 1c000537 lui a0,0x1c000 1c00a19c: 40565593 srai a1,a2,0x5 1c00a1a0: 03f5f593 andi a1,a1,63 1c00a1a4: 8a7d andi a2,a2,31 1c00a1a6: 51450513 addi a0,a0,1300 # 1c000514 <__DTOR_END__+0x228> 1c00a1aa: 015000ef jal ra,1c00a9be <printf> 1c00a1ae: 79c000ef jal ra,1c00a94a <abort> 1c00a1b2: 002047b7 lui a5,0x204 1c00a1b6: cbd8 sw a4,20(a5) 1c00a1b8: bf5d j 1c00a16e <__rt_time_init+0x44> 1c00a1ba: 40b2 lw ra,12(sp) 1c00a1bc: 4422 lw s0,8(sp) 1c00a1be: 0141 addi sp,sp,16 1c00a1c0: 8082 ret 1c00a1c2 <__rt_timer_handler>: 1c00a1c2: 7179 addi sp,sp,-48 1c00a1c4: ce36 sw a3,28(sp) 1c00a1c6: cc3a sw a4,24(sp) 1c00a1c8: 1a10b6b7 lui a3,0x1a10b 1c00a1cc: 1c001737 lui a4,0x1c001 1c00a1d0: d61a sw t1,44(sp) 1c00a1d2: d032 sw a2,32(sp) 1c00a1d4: ca3e sw a5,20(sp) 1c00a1d6: 00c6a303 lw t1,12(a3) # 1a10b00c <__l1_end+0xa1079f8> 1c00a1da: 20072783 lw a5,512(a4) # 1c001200 <first_delayed> 1c00a1de: 02802603 lw a2,40(zero) # 28 <__rt_sched> 1c00a1e2: 02c02683 lw a3,44(zero) # 2c <__rt_sched+0x4> 1c00a1e6: c842 sw a6,16(sp) 1c00a1e8: 80000837 lui a6,0x80000 1c00a1ec: d42a sw a0,40(sp) 1c00a1ee: d22e sw a1,36(sp) 1c00a1f0: c646 sw a7,12(sp) 1c00a1f2: c472 sw t3,8(sp) 1c00a1f4: 4581 li a1,0 1c00a1f6: 4501 li a0,0 1c00a1f8: ffe84813 xori a6,a6,-2 1c00a1fc: efb9 bnez a5,1c00a25a <__rt_timer_handler+0x98> 1c00a1fe: c119 beqz a0,1c00a204 <__rt_timer_handler+0x42> 1c00a200: 02c02423 sw a2,40(zero) # 28 <__rt_sched> 1c00a204: c199 beqz a1,1c00a20a <__rt_timer_handler+0x48> 1c00a206: 02d02623 sw a3,44(zero) # 2c <__rt_sched+0x4> 1c00a20a: 20072023 sw zero,512(a4) 1c00a20e: 1a10b7b7 lui a5,0x1a10b 1c00a212: 08100713 li a4,129 1c00a216: c3d8 sw a4,4(a5) 1c00a218: 6785 lui a5,0x1 1c00a21a: 1a10a737 lui a4,0x1a10a 1c00a21e: 80078793 addi a5,a5,-2048 # 800 <__rt_hyper_pending_emu_stride+0x558> 1c00a222: 80f72a23 sw a5,-2028(a4) # 1a109814 <__l1_end+0xa106200> 1c00a226: 5332 lw t1,44(sp) 1c00a228: 5522 lw a0,40(sp) 1c00a22a: 5592 lw a1,36(sp) 1c00a22c: 5602 lw a2,32(sp) 1c00a22e: 46f2 lw a3,28(sp) 1c00a230: 4762 lw a4,24(sp) 1c00a232: 47d2 lw a5,20(sp) 1c00a234: 4842 lw a6,16(sp) 1c00a236: 48b2 lw a7,12(sp) 1c00a238: 4e22 lw t3,8(sp) 1c00a23a: 6145 addi sp,sp,48 1c00a23c: 30200073 mret 1c00a240: 0187a883 lw a7,24(a5) 1c00a244: 0007ac23 sw zero,24(a5) 1c00a248: c611 beqz a2,1c00a254 <__rt_timer_handler+0x92> 1c00a24a: ce9c sw a5,24(a3) 1c00a24c: 86be mv a3,a5 1c00a24e: 4585 li a1,1 1c00a250: 87c6 mv a5,a7 1c00a252: b76d j 1c00a1fc <__rt_timer_handler+0x3a> 1c00a254: 863e mv a2,a5 1c00a256: 4505 li a0,1 1c00a258: bfd5 j 1c00a24c <__rt_timer_handler+0x8a> 1c00a25a: 0347a883 lw a7,52(a5) 1c00a25e: 41130e33 sub t3,t1,a7 1c00a262: fdc87fe3 bleu t3,a6,1c00a240 <__rt_timer_handler+0x7e> 1c00a266: c119 beqz a0,1c00a26c <__rt_timer_handler+0xaa> 1c00a268: 02c02423 sw a2,40(zero) # 28 <__rt_sched> 1c00a26c: c199 beqz a1,1c00a272 <__rt_timer_handler+0xb0> 1c00a26e: 02d02623 sw a3,44(zero) # 2c <__rt_sched+0x4> 1c00a272: 20f72023 sw a5,512(a4) 1c00a276: 1a10b737 lui a4,0x1a10b 1c00a27a: 475c lw a5,12(a4) 1c00a27c: 406787b3 sub a5,a5,t1 1c00a280: 97c6 add a5,a5,a7 1c00a282: cb5c sw a5,20(a4) 1c00a284: 08500793 li a5,133 1c00a288: c35c sw a5,4(a4) 1c00a28a: bf71 j 1c00a226 <__rt_timer_handler+0x64> 1c00a28c <rt_periph_copy>: 1c00a28c: 7179 addi sp,sp,-48 1c00a28e: d422 sw s0,40(sp) 1c00a290: 842a mv s0,a0 1c00a292: d606 sw ra,44(sp) 1c00a294: d226 sw s1,36(sp) 1c00a296: d04a sw s2,32(sp) 1c00a298: 30047973 csrrci s2,mstatus,8 1c00a29c: 4015d493 srai s1,a1,0x1 1c00a2a0: 1a102537 lui a0,0x1a102 1c00a2a4: 049e slli s1,s1,0x7 1c00a2a6: 94aa add s1,s1,a0 1c00a2a8: 00459513 slli a0,a1,0x4 1c00a2ac: 8941 andi a0,a0,16 1c00a2ae: 94aa add s1,s1,a0 1c00a2b0: 853e mv a0,a5 1c00a2b2: ef89 bnez a5,1c00a2cc <rt_periph_copy+0x40> 1c00a2b4: ce2e sw a1,28(sp) 1c00a2b6: cc32 sw a2,24(sp) 1c00a2b8: ca36 sw a3,20(sp) 1c00a2ba: c83a sw a4,16(sp) 1c00a2bc: c63e sw a5,12(sp) 1c00a2be: 897ff0ef jal ra,1c009b54 <__rt_wait_event_prepare_blocking> 1c00a2c2: 47b2 lw a5,12(sp) 1c00a2c4: 4742 lw a4,16(sp) 1c00a2c6: 46d2 lw a3,20(sp) 1c00a2c8: 4662 lw a2,24(sp) 1c00a2ca: 45f2 lw a1,28(sp) 1c00a2cc: e419 bnez s0,1c00a2da <rt_periph_copy+0x4e> 1c00a2ce: 03450413 addi s0,a0,52 # 1a102034 <__l1_end+0xa0fea20> 1c00a2d2: 04052023 sw zero,64(a0) 1c00a2d6: 04052823 sw zero,80(a0) 1c00a2da: 00c42803 lw a6,12(s0) 1c00a2de: c054 sw a3,4(s0) 1c00a2e0: cc08 sw a0,24(s0) 1c00a2e2: 00f87813 andi a6,a6,15 1c00a2e6: 4891 li a7,4 1c00a2e8: 01076713 ori a4,a4,16 1c00a2ec: 0708ec63 bltu a7,a6,1c00a364 <rt_periph_copy+0xd8> 1c00a2f0: 04000893 li a7,64 1c00a2f4: 0596 slli a1,a1,0x5 1c00a2f6: 98ae add a7,a7,a1 1c00a2f8: 0008a303 lw t1,0(a7) 1c00a2fc: 00042a23 sw zero,20(s0) 1c00a300: 04000813 li a6,64 1c00a304: 02031663 bnez t1,1c00a330 <rt_periph_copy+0xa4> 1c00a308: 0088a023 sw s0,0(a7) 1c00a30c: 00b808b3 add a7,a6,a1 1c00a310: 0088a303 lw t1,8(a7) 1c00a314: 0088a223 sw s0,4(a7) 1c00a318: 02031163 bnez t1,1c00a33a <rt_periph_copy+0xae> 1c00a31c: 0084a883 lw a7,8(s1) 1c00a320: 0208f893 andi a7,a7,32 1c00a324: 00089b63 bnez a7,1c00a33a <rt_periph_copy+0xae> 1c00a328: c090 sw a2,0(s1) 1c00a32a: c0d4 sw a3,4(s1) 1c00a32c: c498 sw a4,8(s1) 1c00a32e: a005 j 1c00a34e <rt_periph_copy+0xc2> 1c00a330: 0048a883 lw a7,4(a7) 1c00a334: 0088aa23 sw s0,20(a7) 1c00a338: bfd1 j 1c00a30c <rt_periph_copy+0x80> 1c00a33a: 00042823 sw zero,16(s0) 1c00a33e: c010 sw a2,0(s0) 1c00a340: c054 sw a3,4(s0) 1c00a342: c418 sw a4,8(s0) 1c00a344: 00031563 bnez t1,1c00a34e <rt_periph_copy+0xc2> 1c00a348: 982e add a6,a6,a1 1c00a34a: 00882423 sw s0,8(a6) # 80000008 <pulp__FC+0x80000009> 1c00a34e: e399 bnez a5,1c00a354 <rt_periph_copy+0xc8> 1c00a350: 955ff0ef jal ra,1c009ca4 <__rt_wait_event> 1c00a354: 30091073 csrw mstatus,s2 1c00a358: 50b2 lw ra,44(sp) 1c00a35a: 5422 lw s0,40(sp) 1c00a35c: 5492 lw s1,36(sp) 1c00a35e: 5902 lw s2,32(sp) 1c00a360: 6145 addi sp,sp,48 1c00a362: 8082 ret 1c00a364: 4899 li a7,6 1c00a366: ff1814e3 bne a6,a7,1c00a34e <rt_periph_copy+0xc2> 1c00a36a: 04000893 li a7,64 1c00a36e: 0596 slli a1,a1,0x5 1c00a370: 98ae add a7,a7,a1 1c00a372: 0008a303 lw t1,0(a7) 1c00a376: 00042a23 sw zero,20(s0) 1c00a37a: 04000813 li a6,64 1c00a37e: 00031f63 bnez t1,1c00a39c <rt_periph_copy+0x110> 1c00a382: 0088a023 sw s0,0(a7) 1c00a386: 95c2 add a1,a1,a6 1c00a388: c1c0 sw s0,4(a1) 1c00a38a: 00031e63 bnez t1,1c00a3a6 <rt_periph_copy+0x11a> 1c00a38e: 02442803 lw a6,36(s0) 1c00a392: 1a1025b7 lui a1,0x1a102 1c00a396: 1305a023 sw a6,288(a1) # 1a102120 <__l1_end+0xa0feb0c> 1c00a39a: b779 j 1c00a328 <rt_periph_copy+0x9c> 1c00a39c: 0048a883 lw a7,4(a7) 1c00a3a0: 0088aa23 sw s0,20(a7) 1c00a3a4: b7cd j 1c00a386 <rt_periph_copy+0xfa> 1c00a3a6: c418 sw a4,8(s0) 1c00a3a8: 4598 lw a4,8(a1) 1c00a3aa: c010 sw a2,0(s0) 1c00a3ac: c054 sw a3,4(s0) 1c00a3ae: 00042823 sw zero,16(s0) 1c00a3b2: ff51 bnez a4,1c00a34e <rt_periph_copy+0xc2> 1c00a3b4: c580 sw s0,8(a1) 1c00a3b6: bf61 j 1c00a34e <rt_periph_copy+0xc2> 1c00a3b8 <__rt_periph_init>: 1c00a3b8: 1c0085b7 lui a1,0x1c008 1c00a3bc: 04000693 li a3,64 1c00a3c0: 4601 li a2,0 1c00a3c2: 04000793 li a5,64 1c00a3c6: 1a1028b7 lui a7,0x1a102 1c00a3ca: 3a458593 addi a1,a1,932 # 1c0083a4 <udma_event_handler> 1c00a3ce: 4841 li a6,16 1c00a3d0: 40165713 srai a4,a2,0x1 1c00a3d4: 00461513 slli a0,a2,0x4 1c00a3d8: 071e slli a4,a4,0x7 1c00a3da: 9746 add a4,a4,a7 1c00a3dc: 8941 andi a0,a0,16 1c00a3de: 972a add a4,a4,a0 1c00a3e0: 0006a023 sw zero,0(a3) 1c00a3e4: 0006a423 sw zero,8(a3) 1c00a3e8: c6d8 sw a4,12(a3) 1c00a3ea: cecc sw a1,28(a3) 1c00a3ec: 0605 addi a2,a2,1 1c00a3ee: 02068693 addi a3,a3,32 1c00a3f2: fd061fe3 bne a2,a6,1c00a3d0 <__rt_periph_init+0x18> 1c00a3f6: 1c008737 lui a4,0x1c008 1c00a3fa: 37270713 addi a4,a4,882 # 1c008372 <__rt_soc_evt_no_udma> 1c00a3fe: 2007a023 sw zero,512(a5) 1c00a402: 20e7a423 sw a4,520(a5) 1c00a406: 20e7a623 sw a4,524(a5) 1c00a40a: 20e7a823 sw a4,528(a5) 1c00a40e: 20e7aa23 sw a4,532(a5) 1c00a412: 20e7ac23 sw a4,536(a5) 1c00a416: 20e7ae23 sw a4,540(a5) 1c00a41a: 22e7a023 sw a4,544(a5) 1c00a41e: 22e7a223 sw a4,548(a5) 1c00a422: 2007a223 sw zero,516(a5) 1c00a426: 8082 ret 1c00a428 <__rt_i2c_init>: 1c00a428: 1c0107b7 lui a5,0x1c010 1c00a42c: 16878793 addi a5,a5,360 # 1c010168 <__cluster_text_end> 1c00a430: 00078223 sb zero,4(a5) 1c00a434: 00078a23 sb zero,20(a5) 1c00a438: 8082 ret 1c00a43a <__rt_hyper_init>: 1c00a43a: 1c001737 lui a4,0x1c001 1c00a43e: 26800793 li a5,616 1c00a442: 18072c23 sw zero,408(a4) # 1c001198 <__pi_hyper_cluster_reqs_first> 1c00a446: 577d li a4,-1 1c00a448: 0007aa23 sw zero,20(a5) 1c00a44c: 0207a823 sw zero,48(a5) 1c00a450: cf98 sw a4,24(a5) 1c00a452: 8082 ret 1c00a454 <__rt_spim_init>: 1c00a454: 1c0017b7 lui a5,0x1c001 1c00a458: 1807ae23 sw zero,412(a5) # 1c00119c <__rt_spim_open_count> 1c00a45c: 8082 ret 1c00a45e <rt_is_fc>: 1c00a45e: f1402573 csrr a0,mhartid 1c00a462: 8515 srai a0,a0,0x5 1c00a464: 03f57513 andi a0,a0,63 1c00a468: 1505 addi a0,a0,-31 1c00a46a: 00153513 seqz a0,a0 1c00a46e: 8082 ret 1c00a470 <__rt_io_end_of_flush>: 1c00a470: 1c0017b7 lui a5,0x1c001 1c00a474: 1a07a223 sw zero,420(a5) # 1c0011a4 <__rt_io_pending_flush> 1c00a478: 00052c23 sw zero,24(a0) 1c00a47c: 8082 ret 1c00a47e <__rt_io_uart_wait_req>: 1c00a47e: 1141 addi sp,sp,-16 1c00a480: c226 sw s1,4(sp) 1c00a482: 84aa mv s1,a0 1c00a484: c606 sw ra,12(sp) 1c00a486: c422 sw s0,8(sp) 1c00a488: c04a sw s2,0(sp) 1c00a48a: 30047973 csrrci s2,mstatus,8 1c00a48e: 1c001437 lui s0,0x1c001 1c00a492: 1a040413 addi s0,s0,416 # 1c0011a0 <__rt_io_event_current> 1c00a496: 4008 lw a0,0(s0) 1c00a498: c509 beqz a0,1c00a4a2 <__rt_io_uart_wait_req+0x24> 1c00a49a: 835ff0ef jal ra,1c009cce <rt_event_wait> 1c00a49e: 00042023 sw zero,0(s0) 1c00a4a2: 4785 li a5,1 1c00a4a4: 08f48623 sb a5,140(s1) 1c00a4a8: 08d4c783 lbu a5,141(s1) 1c00a4ac: 00201737 lui a4,0x201 1c00a4b0: e0470713 addi a4,a4,-508 # 200e04 <__l1_heap_size+0x1f4418> 1c00a4b4: 04078793 addi a5,a5,64 1c00a4b8: 07da slli a5,a5,0x16 1c00a4ba: 97ba add a5,a5,a4 1c00a4bc: 0007a023 sw zero,0(a5) 1c00a4c0: 30091073 csrw mstatus,s2 1c00a4c4: 40b2 lw ra,12(sp) 1c00a4c6: 4422 lw s0,8(sp) 1c00a4c8: 4492 lw s1,4(sp) 1c00a4ca: 4902 lw s2,0(sp) 1c00a4cc: 0141 addi sp,sp,16 1c00a4ce: 8082 ret 1c00a4d0 <__rt_io_start>: 1c00a4d0: 1101 addi sp,sp,-32 1c00a4d2: 0028 addi a0,sp,8 1c00a4d4: ce06 sw ra,28(sp) 1c00a4d6: cc22 sw s0,24(sp) 1c00a4d8: 7e1000ef jal ra,1c00b4b8 <rt_uart_conf_init> 1c00a4dc: 4585 li a1,1 1c00a4de: 4501 li a0,0 1c00a4e0: e8cff0ef jal ra,1c009b6c <rt_event_alloc> 1c00a4e4: 547d li s0,-1 1c00a4e6: ed1d bnez a0,1c00a524 <__rt_io_start+0x54> 1c00a4e8: 1c0017b7 lui a5,0x1c001 1c00a4ec: 0a07a783 lw a5,160(a5) # 1c0010a0 <__rt_iodev_uart_baudrate> 1c00a4f0: 842a mv s0,a0 1c00a4f2: 1c001537 lui a0,0x1c001 1c00a4f6: e3ff6597 auipc a1,0xe3ff6 1c00a4fa: b3258593 addi a1,a1,-1230 # 28 <__rt_sched> 1c00a4fe: 0ec50513 addi a0,a0,236 # 1c0010ec <__rt_io_event> 1c00a502: c43e sw a5,8(sp) 1c00a504: e3eff0ef jal ra,1c009b42 <__rt_event_init> 1c00a508: 1c0017b7 lui a5,0x1c001 1c00a50c: 1b07a503 lw a0,432(a5) # 1c0011b0 <__rt_iodev_uart_channel> 1c00a510: 4681 li a3,0 1c00a512: 4601 li a2,0 1c00a514: 002c addi a1,sp,8 1c00a516: 050d addi a0,a0,3 1c00a518: 7b1000ef jal ra,1c00b4c8 <__rt_uart_open> 1c00a51c: 1c0017b7 lui a5,0x1c001 1c00a520: 1aa7a423 sw a0,424(a5) # 1c0011a8 <_rt_io_uart> 1c00a524: 8522 mv a0,s0 1c00a526: 40f2 lw ra,28(sp) 1c00a528: 4462 lw s0,24(sp) 1c00a52a: 6105 addi sp,sp,32 1c00a52c: 8082 ret 1c00a52e <rt_event_execute.isra.2.constprop.11>: 1c00a52e: 1141 addi sp,sp,-16 1c00a530: c606 sw ra,12(sp) 1c00a532: c422 sw s0,8(sp) 1c00a534: 30047473 csrrci s0,mstatus,8 1c00a538: 4585 li a1,1 1c00a53a: e3ff6517 auipc a0,0xe3ff6 1c00a53e: aee50513 addi a0,a0,-1298 # 28 <__rt_sched> 1c00a542: f02ff0ef jal ra,1c009c44 <__rt_event_execute> 1c00a546: 30041073 csrw mstatus,s0 1c00a54a: 40b2 lw ra,12(sp) 1c00a54c: 4422 lw s0,8(sp) 1c00a54e: 0141 addi sp,sp,16 1c00a550: 8082 ret 1c00a552 <__rt_io_lock>: 1c00a552: 1c0017b7 lui a5,0x1c001 1c00a556: fec7a783 lw a5,-20(a5) # 1c000fec <__hal_debug_struct+0x10> 1c00a55a: c791 beqz a5,1c00a566 <__rt_io_lock+0x14> 1c00a55c: 1c0017b7 lui a5,0x1c001 1c00a560: 1a87a783 lw a5,424(a5) # 1c0011a8 <_rt_io_uart> 1c00a564: c3a1 beqz a5,1c00a5a4 <__rt_io_lock+0x52> 1c00a566: 7171 addi sp,sp,-176 1c00a568: d706 sw ra,172(sp) 1c00a56a: 3dd5 jal 1c00a45e <rt_is_fc> 1c00a56c: 1c0017b7 lui a5,0x1c001 1c00a570: c901 beqz a0,1c00a580 <__rt_io_lock+0x2e> 1c00a572: fbc78513 addi a0,a5,-68 # 1c000fbc <__rt_io_fc_lock> 1c00a576: 9baff0ef jal ra,1c009730 <__rt_fc_lock> 1c00a57a: 50ba lw ra,172(sp) 1c00a57c: 614d addi sp,sp,176 1c00a57e: 8082 ret 1c00a580: 002c addi a1,sp,8 1c00a582: fbc78513 addi a0,a5,-68 1c00a586: a1cff0ef jal ra,1c0097a2 <__rt_fc_cluster_lock> 1c00a58a: 4689 li a3,2 1c00a58c: 00204737 lui a4,0x204 1c00a590: 09c14783 lbu a5,156(sp) 1c00a594: 0ff7f793 andi a5,a5,255 1c00a598: f3ed bnez a5,1c00a57a <__rt_io_lock+0x28> 1c00a59a: c714 sw a3,8(a4) 1c00a59c: 03c76783 p.elw a5,60(a4) # 20403c <__l1_heap_size+0x1f7650> 1c00a5a0: c354 sw a3,4(a4) 1c00a5a2: b7fd j 1c00a590 <__rt_io_lock+0x3e> 1c00a5a4: 8082 ret 1c00a5a6 <__rt_io_unlock>: 1c00a5a6: 1c0017b7 lui a5,0x1c001 1c00a5aa: fec7a783 lw a5,-20(a5) # 1c000fec <__hal_debug_struct+0x10> 1c00a5ae: c791 beqz a5,1c00a5ba <__rt_io_unlock+0x14> 1c00a5b0: 1c0017b7 lui a5,0x1c001 1c00a5b4: 1a87a783 lw a5,424(a5) # 1c0011a8 <_rt_io_uart> 1c00a5b8: c3a1 beqz a5,1c00a5f8 <__rt_io_unlock+0x52> 1c00a5ba: 7171 addi sp,sp,-176 1c00a5bc: d706 sw ra,172(sp) 1c00a5be: 3545 jal 1c00a45e <rt_is_fc> 1c00a5c0: 1c0017b7 lui a5,0x1c001 1c00a5c4: c901 beqz a0,1c00a5d4 <__rt_io_unlock+0x2e> 1c00a5c6: fbc78513 addi a0,a5,-68 # 1c000fbc <__rt_io_fc_lock> 1c00a5ca: 9a2ff0ef jal ra,1c00976c <__rt_fc_unlock> 1c00a5ce: 50ba lw ra,172(sp) 1c00a5d0: 614d addi sp,sp,176 1c00a5d2: 8082 ret 1c00a5d4: 002c addi a1,sp,8 1c00a5d6: fbc78513 addi a0,a5,-68 1c00a5da: a00ff0ef jal ra,1c0097da <__rt_fc_cluster_unlock> 1c00a5de: 4689 li a3,2 1c00a5e0: 00204737 lui a4,0x204 1c00a5e4: 09c14783 lbu a5,156(sp) 1c00a5e8: 0ff7f793 andi a5,a5,255 1c00a5ec: f3ed bnez a5,1c00a5ce <__rt_io_unlock+0x28> 1c00a5ee: c714 sw a3,8(a4) 1c00a5f0: 03c76783 p.elw a5,60(a4) # 20403c <__l1_heap_size+0x1f7650> 1c00a5f4: c354 sw a3,4(a4) 1c00a5f6: b7fd j 1c00a5e4 <__rt_io_unlock+0x3e> 1c00a5f8: 8082 ret 1c00a5fa <__rt_io_uart_wait_pending>: 1c00a5fa: 7135 addi sp,sp,-160 1c00a5fc: cd22 sw s0,152(sp) 1c00a5fe: cf06 sw ra,156(sp) 1c00a600: cb26 sw s1,148(sp) 1c00a602: 1c001437 lui s0,0x1c001 1c00a606: 1a442783 lw a5,420(s0) # 1c0011a4 <__rt_io_pending_flush> 1c00a60a: e39d bnez a5,1c00a630 <__rt_io_uart_wait_pending+0x36> 1c00a60c: 1c001437 lui s0,0x1c001 1c00a610: 1a040413 addi s0,s0,416 # 1c0011a0 <__rt_io_event_current> 1c00a614: 4004 lw s1,0(s0) 1c00a616: c881 beqz s1,1c00a626 <__rt_io_uart_wait_pending+0x2c> 1c00a618: 3599 jal 1c00a45e <rt_is_fc> 1c00a61a: cd19 beqz a0,1c00a638 <__rt_io_uart_wait_pending+0x3e> 1c00a61c: 8526 mv a0,s1 1c00a61e: eb0ff0ef jal ra,1c009cce <rt_event_wait> 1c00a622: 00042023 sw zero,0(s0) 1c00a626: 40fa lw ra,156(sp) 1c00a628: 446a lw s0,152(sp) 1c00a62a: 44da lw s1,148(sp) 1c00a62c: 610d addi sp,sp,160 1c00a62e: 8082 ret 1c00a630: 3f9d jal 1c00a5a6 <__rt_io_unlock> 1c00a632: 3df5 jal 1c00a52e <rt_event_execute.isra.2.constprop.11> 1c00a634: 3f39 jal 1c00a552 <__rt_io_lock> 1c00a636: bfc1 j 1c00a606 <__rt_io_uart_wait_pending+0xc> 1c00a638: f14027f3 csrr a5,mhartid 1c00a63c: 8795 srai a5,a5,0x5 1c00a63e: 03f7f793 andi a5,a5,63 1c00a642: 08f106a3 sb a5,141(sp) 1c00a646: 1c00a7b7 lui a5,0x1c00a 1c00a64a: 47e78793 addi a5,a5,1150 # 1c00a47e <__rt_io_uart_wait_req> 1c00a64e: c03e sw a5,0(sp) 1c00a650: 00010793 mv a5,sp 1c00a654: 4705 li a4,1 1c00a656: c23e sw a5,4(sp) 1c00a658: 850a mv a0,sp 1c00a65a: 1c0017b7 lui a5,0x1c001 1c00a65e: 10e7a623 sw a4,268(a5) # 1c00110c <__rt_io_event+0x20> 1c00a662: 08010623 sb zero,140(sp) 1c00a666: d002 sw zero,32(sp) 1c00a668: d202 sw zero,36(sp) 1c00a66a: a17fe0ef jal ra,1c009080 <__rt_cluster_push_fc_event> 1c00a66e: 4689 li a3,2 1c00a670: 00204737 lui a4,0x204 1c00a674: 08c14783 lbu a5,140(sp) 1c00a678: 0ff7f793 andi a5,a5,255 1c00a67c: f7cd bnez a5,1c00a626 <__rt_io_uart_wait_pending+0x2c> 1c00a67e: c714 sw a3,8(a4) 1c00a680: 03c76783 p.elw a5,60(a4) # 20403c <__l1_heap_size+0x1f7650> 1c00a684: c354 sw a3,4(a4) 1c00a686: b7fd j 1c00a674 <__rt_io_uart_wait_pending+0x7a> 1c00a688 <__rt_io_stop>: 1c00a688: 1141 addi sp,sp,-16 1c00a68a: c422 sw s0,8(sp) 1c00a68c: 1c001437 lui s0,0x1c001 1c00a690: c606 sw ra,12(sp) 1c00a692: 1a840413 addi s0,s0,424 # 1c0011a8 <_rt_io_uart> 1c00a696: 3795 jal 1c00a5fa <__rt_io_uart_wait_pending> 1c00a698: 4008 lw a0,0(s0) 1c00a69a: 4581 li a1,0 1c00a69c: 6b5000ef jal ra,1c00b550 <rt_uart_close> 1c00a6a0: 40b2 lw ra,12(sp) 1c00a6a2: 00042023 sw zero,0(s0) 1c00a6a6: 4422 lw s0,8(sp) 1c00a6a8: 4501 li a0,0 1c00a6aa: 0141 addi sp,sp,16 1c00a6ac: 8082 ret 1c00a6ae <__rt_io_uart_flush.constprop.10>: 1c00a6ae: 7131 addi sp,sp,-192 1c00a6b0: dd22 sw s0,184(sp) 1c00a6b2: df06 sw ra,188(sp) 1c00a6b4: db26 sw s1,180(sp) 1c00a6b6: d94a sw s2,176(sp) 1c00a6b8: d74e sw s3,172(sp) 1c00a6ba: d552 sw s4,168(sp) 1c00a6bc: d356 sw s5,164(sp) 1c00a6be: 1c001437 lui s0,0x1c001 1c00a6c2: 1a442783 lw a5,420(s0) # 1c0011a4 <__rt_io_pending_flush> 1c00a6c6: 1a440a13 addi s4,s0,420 1c00a6ca: e7bd bnez a5,1c00a738 <__rt_io_uart_flush.constprop.10+0x8a> 1c00a6cc: 1c0014b7 lui s1,0x1c001 1c00a6d0: fdc48793 addi a5,s1,-36 # 1c000fdc <__hal_debug_struct> 1c00a6d4: 4f80 lw s0,24(a5) 1c00a6d6: fdc48a93 addi s5,s1,-36 1c00a6da: c431 beqz s0,1c00a726 <__rt_io_uart_flush.constprop.10+0x78> 1c00a6dc: 3349 jal 1c00a45e <rt_is_fc> 1c00a6de: 1c0017b7 lui a5,0x1c001 1c00a6e2: 1a87a903 lw s2,424(a5) # 1c0011a8 <_rt_io_uart> 1c00a6e6: 1c0019b7 lui s3,0x1c001 1c00a6ea: cd29 beqz a0,1c00a744 <__rt_io_uart_flush.constprop.10+0x96> 1c00a6ec: 1c00a5b7 lui a1,0x1c00a 1c00a6f0: 4785 li a5,1 1c00a6f2: fdc48613 addi a2,s1,-36 1c00a6f6: 47058593 addi a1,a1,1136 # 1c00a470 <__rt_io_end_of_flush> 1c00a6fa: 4501 li a0,0 1c00a6fc: 00fa2023 sw a5,0(s4) 1c00a700: ce4ff0ef jal ra,1c009be4 <rt_event_get> 1c00a704: 00492583 lw a1,4(s2) 1c00a708: 87aa mv a5,a0 1c00a70a: 4701 li a4,0 1c00a70c: 0586 slli a1,a1,0x1 1c00a70e: 86a2 mv a3,s0 1c00a710: ff898613 addi a2,s3,-8 # 1c000ff8 <__hal_debug_struct+0x1c> 1c00a714: 0585 addi a1,a1,1 1c00a716: 4501 li a0,0 1c00a718: b75ff0ef jal ra,1c00a28c <rt_periph_copy> 1c00a71c: 3569 jal 1c00a5a6 <__rt_io_unlock> 1c00a71e: 000a2783 lw a5,0(s4) 1c00a722: ef99 bnez a5,1c00a740 <__rt_io_uart_flush.constprop.10+0x92> 1c00a724: 353d jal 1c00a552 <__rt_io_lock> 1c00a726: 50fa lw ra,188(sp) 1c00a728: 546a lw s0,184(sp) 1c00a72a: 54da lw s1,180(sp) 1c00a72c: 594a lw s2,176(sp) 1c00a72e: 59ba lw s3,172(sp) 1c00a730: 5a2a lw s4,168(sp) 1c00a732: 5a9a lw s5,164(sp) 1c00a734: 6129 addi sp,sp,192 1c00a736: 8082 ret 1c00a738: 35bd jal 1c00a5a6 <__rt_io_unlock> 1c00a73a: 3bd5 jal 1c00a52e <rt_event_execute.isra.2.constprop.11> 1c00a73c: 3d19 jal 1c00a552 <__rt_io_lock> 1c00a73e: b751 j 1c00a6c2 <__rt_io_uart_flush.constprop.10+0x14> 1c00a740: 33fd jal 1c00a52e <rt_event_execute.isra.2.constprop.11> 1c00a742: bff1 j 1c00a71e <__rt_io_uart_flush.constprop.10+0x70> 1c00a744: 0054 addi a3,sp,4 1c00a746: 8622 mv a2,s0 1c00a748: ff898593 addi a1,s3,-8 1c00a74c: 854a mv a0,s2 1c00a74e: 64d000ef jal ra,1c00b59a <rt_uart_cluster_write> 1c00a752: 4689 li a3,2 1c00a754: 00204737 lui a4,0x204 1c00a758: 09c14783 lbu a5,156(sp) 1c00a75c: 0ff7f793 andi a5,a5,255 1c00a760: c781 beqz a5,1c00a768 <__rt_io_uart_flush.constprop.10+0xba> 1c00a762: 000aac23 sw zero,24(s5) 1c00a766: b7c1 j 1c00a726 <__rt_io_uart_flush.constprop.10+0x78> 1c00a768: c714 sw a3,8(a4) 1c00a76a: 03c76783 p.elw a5,60(a4) # 20403c <__l1_heap_size+0x1f7650> 1c00a76e: c354 sw a3,4(a4) 1c00a770: b7e5 j 1c00a758 <__rt_io_uart_flush.constprop.10+0xaa> 1c00a772 <memset>: 1c00a772: 962a add a2,a2,a0 1c00a774: 87aa mv a5,a0 1c00a776: 00c79363 bne a5,a2,1c00a77c <memset+0xa> 1c00a77a: 8082 ret 1c00a77c: 0785 addi a5,a5,1 1c00a77e: feb78fa3 sb a1,-1(a5) 1c00a782: bfd5 j 1c00a776 <memset+0x4> 1c00a784 <memcpy>: 1c00a784: 962a add a2,a2,a0 1c00a786: 87aa mv a5,a0 1c00a788: 00c79363 bne a5,a2,1c00a78e <memcpy+0xa> 1c00a78c: 8082 ret 1c00a78e: 0585 addi a1,a1,1 1c00a790: fff5c703 lbu a4,-1(a1) 1c00a794: 0785 addi a5,a5,1 1c00a796: fee78fa3 sb a4,-1(a5) 1c00a79a: b7fd j 1c00a788 <memcpy+0x4> 1c00a79c <memmove>: 1c00a79c: 40b507b3 sub a5,a0,a1 1c00a7a0: 00c7e763 bltu a5,a2,1c00a7ae <memmove+0x12> 1c00a7a4: 962e add a2,a2,a1 1c00a7a6: 87aa mv a5,a0 1c00a7a8: 00c59e63 bne a1,a2,1c00a7c4 <memmove+0x28> 1c00a7ac: 8082 ret 1c00a7ae: 167d addi a2,a2,-1 1c00a7b0: 00c587b3 add a5,a1,a2 1c00a7b4: 0007c703 lbu a4,0(a5) 1c00a7b8: 00c507b3 add a5,a0,a2 1c00a7bc: 00e78023 sb a4,0(a5) 1c00a7c0: f67d bnez a2,1c00a7ae <memmove+0x12> 1c00a7c2: 8082 ret 1c00a7c4: 0005c703 lbu a4,0(a1) 1c00a7c8: 0785 addi a5,a5,1 1c00a7ca: 0585 addi a1,a1,1 1c00a7cc: fee78fa3 sb a4,-1(a5) 1c00a7d0: bfe1 j 1c00a7a8 <memmove+0xc> 1c00a7d2 <strchr>: 1c00a7d2: 0ff5f593 andi a1,a1,255 1c00a7d6: 00054783 lbu a5,0(a0) 1c00a7da: 00b78563 beq a5,a1,1c00a7e4 <strchr+0x12> 1c00a7de: e781 bnez a5,1c00a7e6 <strchr+0x14> 1c00a7e0: c191 beqz a1,1c00a7e4 <strchr+0x12> 1c00a7e2: 4501 li a0,0 1c00a7e4: 8082 ret 1c00a7e6: 0505 addi a0,a0,1 1c00a7e8: b7fd j 1c00a7d6 <strchr+0x4> 1c00a7ea <__rt_putc_debug_bridge>: 1c00a7ea: 1141 addi sp,sp,-16 1c00a7ec: c422 sw s0,8(sp) 1c00a7ee: 1c001437 lui s0,0x1c001 1c00a7f2: c226 sw s1,4(sp) 1c00a7f4: c606 sw ra,12(sp) 1c00a7f6: 84aa mv s1,a0 1c00a7f8: fdc40413 addi s0,s0,-36 # 1c000fdc <__hal_debug_struct> 1c00a7fc: 485c lw a5,20(s0) 1c00a7fe: c791 beqz a5,1c00a80a <__rt_putc_debug_bridge+0x20> 1c00a800: 06400513 li a0,100 1c00a804: 909ff0ef jal ra,1c00a10c <rt_time_wait_us> 1c00a808: bfd5 j 1c00a7fc <__rt_putc_debug_bridge+0x12> 1c00a80a: 4c1c lw a5,24(s0) 1c00a80c: 00178713 addi a4,a5,1 1c00a810: 97a2 add a5,a5,s0 1c00a812: 00978e23 sb s1,28(a5) 1c00a816: cc18 sw a4,24(s0) 1c00a818: 4c14 lw a3,24(s0) 1c00a81a: 08000793 li a5,128 1c00a81e: 00f68563 beq a3,a5,1c00a828 <__rt_putc_debug_bridge+0x3e> 1c00a822: 47a9 li a5,10 1c00a824: 00f49663 bne s1,a5,1c00a830 <__rt_putc_debug_bridge+0x46> 1c00a828: c701 beqz a4,1c00a830 <__rt_putc_debug_bridge+0x46> 1c00a82a: c858 sw a4,20(s0) 1c00a82c: 00042c23 sw zero,24(s0) 1c00a830: 4c1c lw a5,24(s0) 1c00a832: e799 bnez a5,1c00a840 <__rt_putc_debug_bridge+0x56> 1c00a834: 4422 lw s0,8(sp) 1c00a836: 40b2 lw ra,12(sp) 1c00a838: 4492 lw s1,4(sp) 1c00a83a: 0141 addi sp,sp,16 1c00a83c: 948ff06f j 1c009984 <__rt_bridge_printf_flush> 1c00a840: 40b2 lw ra,12(sp) 1c00a842: 4422 lw s0,8(sp) 1c00a844: 4492 lw s1,4(sp) 1c00a846: 0141 addi sp,sp,16 1c00a848: 8082 ret 1c00a84a <__rt_putc_uart>: 1c00a84a: 1101 addi sp,sp,-32 1c00a84c: c62a sw a0,12(sp) 1c00a84e: ce06 sw ra,28(sp) 1c00a850: 336d jal 1c00a5fa <__rt_io_uart_wait_pending> 1c00a852: 1c0017b7 lui a5,0x1c001 1c00a856: fdc78793 addi a5,a5,-36 # 1c000fdc <__hal_debug_struct> 1c00a85a: 4f94 lw a3,24(a5) 1c00a85c: 4532 lw a0,12(sp) 1c00a85e: 00168713 addi a4,a3,1 1c00a862: cf98 sw a4,24(a5) 1c00a864: 97b6 add a5,a5,a3 1c00a866: 00a78e23 sb a0,28(a5) 1c00a86a: 08000793 li a5,128 1c00a86e: 00f70563 beq a4,a5,1c00a878 <__rt_putc_uart+0x2e> 1c00a872: 47a9 li a5,10 1c00a874: 00f51563 bne a0,a5,1c00a87e <__rt_putc_uart+0x34> 1c00a878: 40f2 lw ra,28(sp) 1c00a87a: 6105 addi sp,sp,32 1c00a87c: bd0d j 1c00a6ae <__rt_io_uart_flush.constprop.10> 1c00a87e: 40f2 lw ra,28(sp) 1c00a880: 6105 addi sp,sp,32 1c00a882: 8082 ret 1c00a884 <tfp_putc.isra.8>: 1c00a884: 1c0017b7 lui a5,0x1c001 1c00a888: 1a87a783 lw a5,424(a5) # 1c0011a8 <_rt_io_uart> 1c00a88c: c391 beqz a5,1c00a890 <tfp_putc.isra.8+0xc> 1c00a88e: bf75 j 1c00a84a <__rt_putc_uart> 1c00a890: 1c0017b7 lui a5,0x1c001 1c00a894: fec7a783 lw a5,-20(a5) # 1c000fec <__hal_debug_struct+0x10> 1c00a898: c395 beqz a5,1c00a8bc <tfp_putc.isra.8+0x38> 1c00a89a: 6689 lui a3,0x2 1c00a89c: f14027f3 csrr a5,mhartid 1c00a8a0: f8068693 addi a3,a3,-128 # 1f80 <__rt_hyper_pending_emu_stride+0x1cd8> 1c00a8a4: 00379713 slli a4,a5,0x3 1c00a8a8: 078a slli a5,a5,0x2 1c00a8aa: 0ff77713 andi a4,a4,255 1c00a8ae: 8ff5 and a5,a5,a3 1c00a8b0: 97ba add a5,a5,a4 1c00a8b2: 1a10f737 lui a4,0x1a10f 1c00a8b6: 97ba add a5,a5,a4 1c00a8b8: c388 sw a0,0(a5) 1c00a8ba: 8082 ret 1c00a8bc: b73d j 1c00a7ea <__rt_putc_debug_bridge> 1c00a8be <puts>: 1c00a8be: 1141 addi sp,sp,-16 1c00a8c0: c422 sw s0,8(sp) 1c00a8c2: c606 sw ra,12(sp) 1c00a8c4: 842a mv s0,a0 1c00a8c6: 3171 jal 1c00a552 <__rt_io_lock> 1c00a8c8: 00044503 lbu a0,0(s0) 1c00a8cc: c501 beqz a0,1c00a8d4 <puts+0x16> 1c00a8ce: 3f5d jal 1c00a884 <tfp_putc.isra.8> 1c00a8d0: 0405 addi s0,s0,1 1c00a8d2: bfdd j 1c00a8c8 <puts+0xa> 1c00a8d4: 4529 li a0,10 1c00a8d6: 377d jal 1c00a884 <tfp_putc.isra.8> 1c00a8d8: 31f9 jal 1c00a5a6 <__rt_io_unlock> 1c00a8da: 40b2 lw ra,12(sp) 1c00a8dc: 4422 lw s0,8(sp) 1c00a8de: 4501 li a0,0 1c00a8e0: 0141 addi sp,sp,16 1c00a8e2: 8082 ret 1c00a8e4 <fputc_locked>: 1c00a8e4: 1141 addi sp,sp,-16 1c00a8e6: c422 sw s0,8(sp) 1c00a8e8: 842a mv s0,a0 1c00a8ea: 0ff57513 andi a0,a0,255 1c00a8ee: c606 sw ra,12(sp) 1c00a8f0: 3f51 jal 1c00a884 <tfp_putc.isra.8> 1c00a8f2: 8522 mv a0,s0 1c00a8f4: 40b2 lw ra,12(sp) 1c00a8f6: 4422 lw s0,8(sp) 1c00a8f8: 0141 addi sp,sp,16 1c00a8fa: 8082 ret 1c00a8fc <_prf_locked>: 1c00a8fc: 1101 addi sp,sp,-32 1c00a8fe: ce06 sw ra,28(sp) 1c00a900: c02a sw a0,0(sp) 1c00a902: c62e sw a1,12(sp) 1c00a904: c432 sw a2,8(sp) 1c00a906: c236 sw a3,4(sp) 1c00a908: 31a9 jal 1c00a552 <__rt_io_lock> 1c00a90a: 4692 lw a3,4(sp) 1c00a90c: 4622 lw a2,8(sp) 1c00a90e: 45b2 lw a1,12(sp) 1c00a910: 4502 lw a0,0(sp) 1c00a912: 2ae9 jal 1c00aaec <_prf> 1c00a914: c02a sw a0,0(sp) 1c00a916: 3941 jal 1c00a5a6 <__rt_io_unlock> 1c00a918: 40f2 lw ra,28(sp) 1c00a91a: 4502 lw a0,0(sp) 1c00a91c: 6105 addi sp,sp,32 1c00a91e: 8082 ret 1c00a920 <exit>: 1c00a920: 1141 addi sp,sp,-16 1c00a922: c606 sw ra,12(sp) 1c00a924: c422 sw s0,8(sp) 1c00a926: 842a mv s0,a0 1c00a928: 85cff0ef jal ra,1c009984 <__rt_bridge_printf_flush> 1c00a92c: 80000537 lui a0,0x80000 1c00a930: 1c0017b7 lui a5,0x1c001 1c00a934: 8c49 or s0,s0,a0 1c00a936: fdc78793 addi a5,a5,-36 # 1c000fdc <__hal_debug_struct> 1c00a93a: c7c0 sw s0,12(a5) 1c00a93c: 818ff0ef jal ra,1c009954 <__rt_bridge_send_notif> 1c00a940: 1a1047b7 lui a5,0x1a104 1c00a944: 0a87a023 sw s0,160(a5) # 1a1040a0 <__l1_end+0xa100a8c> 1c00a948: a001 j 1c00a948 <exit+0x28> 1c00a94a <abort>: 1c00a94a: 1141 addi sp,sp,-16 1c00a94c: 557d li a0,-1 1c00a94e: c606 sw ra,12(sp) 1c00a950: 3fc1 jal 1c00a920 <exit> 1c00a952 <__rt_io_init>: 1c00a952: 1c0017b7 lui a5,0x1c001 1c00a956: fbc78793 addi a5,a5,-68 # 1c000fbc <__rt_io_fc_lock> 1c00a95a: 0007a223 sw zero,4(a5) 1c00a95e: 0007a023 sw zero,0(a5) 1c00a962: 0007a623 sw zero,12(a5) 1c00a966: 1c0017b7 lui a5,0x1c001 1c00a96a: 1a07a423 sw zero,424(a5) # 1c0011a8 <_rt_io_uart> 1c00a96e: 1c0017b7 lui a5,0x1c001 1c00a972: 1a07a023 sw zero,416(a5) # 1c0011a0 <__rt_io_event_current> 1c00a976: 1c0017b7 lui a5,0x1c001 1c00a97a: 1ac7a703 lw a4,428(a5) # 1c0011ac <__rt_iodev> 1c00a97e: 4785 li a5,1 1c00a980: 02f71e63 bne a4,a5,1c00a9bc <__rt_io_init+0x6a> 1c00a984: 1c00a5b7 lui a1,0x1c00a 1c00a988: 1141 addi sp,sp,-16 1c00a98a: 4601 li a2,0 1c00a98c: 4d058593 addi a1,a1,1232 # 1c00a4d0 <__rt_io_start> 1c00a990: 4501 li a0,0 1c00a992: c606 sw ra,12(sp) 1c00a994: d09fe0ef jal ra,1c00969c <__rt_cbsys_add> 1c00a998: 1c00a5b7 lui a1,0x1c00a 1c00a99c: 68858593 addi a1,a1,1672 # 1c00a688 <__rt_io_stop> 1c00a9a0: 4601 li a2,0 1c00a9a2: 4505 li a0,1 1c00a9a4: cf9fe0ef jal ra,1c00969c <__rt_cbsys_add> 1c00a9a8: 40b2 lw ra,12(sp) 1c00a9aa: 1c0017b7 lui a5,0x1c001 1c00a9ae: 1a07a223 sw zero,420(a5) # 1c0011a4 <__rt_io_pending_flush> 1c00a9b2: 4585 li a1,1 1c00a9b4: 4501 li a0,0 1c00a9b6: 0141 addi sp,sp,16 1c00a9b8: 9b4ff06f j 1c009b6c <rt_event_alloc> 1c00a9bc: 8082 ret 1c00a9be <printf>: 1c00a9be: 7139 addi sp,sp,-64 1c00a9c0: d432 sw a2,40(sp) 1c00a9c2: 862a mv a2,a0 1c00a9c4: 1c00b537 lui a0,0x1c00b 1c00a9c8: d22e sw a1,36(sp) 1c00a9ca: d636 sw a3,44(sp) 1c00a9cc: 4589 li a1,2 1c00a9ce: 1054 addi a3,sp,36 1c00a9d0: 8e450513 addi a0,a0,-1820 # 1c00a8e4 <fputc_locked> 1c00a9d4: ce06 sw ra,28(sp) 1c00a9d6: d83a sw a4,48(sp) 1c00a9d8: da3e sw a5,52(sp) 1c00a9da: dc42 sw a6,56(sp) 1c00a9dc: de46 sw a7,60(sp) 1c00a9de: c636 sw a3,12(sp) 1c00a9e0: 3f31 jal 1c00a8fc <_prf_locked> 1c00a9e2: 40f2 lw ra,28(sp) 1c00a9e4: 6121 addi sp,sp,64 1c00a9e6: 8082 ret 1c00a9e8 <_to_x>: 1c00a9e8: 872a mv a4,a0 1c00a9ea: 87aa mv a5,a0 1c00a9ec: 4325 li t1,9 1c00a9ee: 02c5f8b3 remu a7,a1,a2 1c00a9f2: 02700513 li a0,39 1c00a9f6: 02c5d5b3 divu a1,a1,a2 1c00a9fa: 0ff8f813 andi a6,a7,255 1c00a9fe: 01136363 bltu t1,a7,1c00aa04 <_to_x+0x1c> 1c00aa02: 4501 li a0,0 1c00aa04: 03080813 addi a6,a6,48 1c00aa08: 0785 addi a5,a5,1 1c00aa0a: 9542 add a0,a0,a6 1c00aa0c: fea78fa3 sb a0,-1(a5) 1c00aa10: fdf9 bnez a1,1c00a9ee <_to_x+0x6> 1c00aa12: 03000613 li a2,48 1c00aa16: 40e78533 sub a0,a5,a4 1c00aa1a: 00d54863 blt a0,a3,1c00aa2a <_to_x+0x42> 1c00aa1e: 00078023 sb zero,0(a5) 1c00aa22: 17fd addi a5,a5,-1 1c00aa24: 00f76763 bltu a4,a5,1c00aa32 <_to_x+0x4a> 1c00aa28: 8082 ret 1c00aa2a: 0785 addi a5,a5,1 1c00aa2c: fec78fa3 sb a2,-1(a5) 1c00aa30: b7dd j 1c00aa16 <_to_x+0x2e> 1c00aa32: 00074603 lbu a2,0(a4) # 1a10f000 <__l1_end+0xa10b9ec> 1c00aa36: 0007c683 lbu a3,0(a5) 1c00aa3a: 0705 addi a4,a4,1 1c00aa3c: 00c78023 sb a2,0(a5) 1c00aa40: fed70fa3 sb a3,-1(a4) 1c00aa44: 17fd addi a5,a5,-1 1c00aa46: bff9 j 1c00aa24 <_to_x+0x3c> 1c00aa48 <_rlrshift>: 1c00aa48: 411c lw a5,0(a0) 1c00aa4a: 4154 lw a3,4(a0) 1c00aa4c: 0017f713 andi a4,a5,1 1c00aa50: 01f69613 slli a2,a3,0x1f 1c00aa54: 8385 srli a5,a5,0x1 1c00aa56: 8fd1 or a5,a5,a2 1c00aa58: 97ba add a5,a5,a4 1c00aa5a: 8285 srli a3,a3,0x1 1c00aa5c: 00e7b733 sltu a4,a5,a4 1c00aa60: 9736 add a4,a4,a3 1c00aa62: c11c sw a5,0(a0) 1c00aa64: c158 sw a4,4(a0) 1c00aa66: 8082 ret 1c00aa68 <_ldiv5>: 1c00aa68: 4118 lw a4,0(a0) 1c00aa6a: 4154 lw a3,4(a0) 1c00aa6c: 4615 li a2,5 1c00aa6e: 00270793 addi a5,a4,2 1c00aa72: 00e7b733 sltu a4,a5,a4 1c00aa76: 9736 add a4,a4,a3 1c00aa78: 02c755b3 divu a1,a4,a2 1c00aa7c: 02b606b3 mul a3,a2,a1 1c00aa80: 8f15 sub a4,a4,a3 1c00aa82: 01d71693 slli a3,a4,0x1d 1c00aa86: 0037d713 srli a4,a5,0x3 1c00aa8a: 8f55 or a4,a4,a3 1c00aa8c: 02c75733 divu a4,a4,a2 1c00aa90: 01d75693 srli a3,a4,0x1d 1c00aa94: 070e slli a4,a4,0x3 1c00aa96: 95b6 add a1,a1,a3 1c00aa98: 02e606b3 mul a3,a2,a4 1c00aa9c: 8f95 sub a5,a5,a3 1c00aa9e: 02c7d7b3 divu a5,a5,a2 1c00aaa2: 973e add a4,a4,a5 1c00aaa4: 00f737b3 sltu a5,a4,a5 1c00aaa8: 97ae add a5,a5,a1 1c00aaaa: c118 sw a4,0(a0) 1c00aaac: c15c sw a5,4(a0) 1c00aaae: 8082 ret 1c00aab0 <_get_digit>: 1c00aab0: 419c lw a5,0(a1) 1c00aab2: 03000713 li a4,48 1c00aab6: 02f05863 blez a5,1c00aae6 <_get_digit+0x36> 1c00aaba: 17fd addi a5,a5,-1 1c00aabc: 4114 lw a3,0(a0) 1c00aabe: c19c sw a5,0(a1) 1c00aac0: 415c lw a5,4(a0) 1c00aac2: 4729 li a4,10 1c00aac4: 02d70633 mul a2,a4,a3 1c00aac8: 02f707b3 mul a5,a4,a5 1c00aacc: c110 sw a2,0(a0) 1c00aace: 02d73733 mulhu a4,a4,a3 1c00aad2: 100006b7 lui a3,0x10000 1c00aad6: 16fd addi a3,a3,-1 1c00aad8: 97ba add a5,a5,a4 1c00aada: 01c7d713 srli a4,a5,0x1c 1c00aade: 8ff5 and a5,a5,a3 1c00aae0: 03070713 addi a4,a4,48 1c00aae4: c15c sw a5,4(a0) 1c00aae6: 0ff77513 andi a0,a4,255 1c00aaea: 8082 ret 1c00aaec <_prf>: 1c00aaec: 714d addi sp,sp,-336 1c00aaee: 14912223 sw s1,324(sp) 1c00aaf2: 13312e23 sw s3,316(sp) 1c00aaf6: 13812423 sw s8,296(sp) 1c00aafa: 14112623 sw ra,332(sp) 1c00aafe: 14812423 sw s0,328(sp) 1c00ab02: 15212023 sw s2,320(sp) 1c00ab06: 13412c23 sw s4,312(sp) 1c00ab0a: 13512a23 sw s5,308(sp) 1c00ab0e: 13612823 sw s6,304(sp) 1c00ab12: 13712623 sw s7,300(sp) 1c00ab16: 13912223 sw s9,292(sp) 1c00ab1a: 13a12023 sw s10,288(sp) 1c00ab1e: 11b12e23 sw s11,284(sp) 1c00ab22: cc2a sw a0,24(sp) 1c00ab24: ce2e sw a1,28(sp) 1c00ab26: 84b2 mv s1,a2 1c00ab28: 8c36 mv s8,a3 1c00ab2a: 4981 li s3,0 1c00ab2c: 0004c503 lbu a0,0(s1) 1c00ab30: 00148b93 addi s7,s1,1 1c00ab34: cd01 beqz a0,1c00ab4c <_prf+0x60> 1c00ab36: 02500793 li a5,37 1c00ab3a: 14f50a63 beq a0,a5,1c00ac8e <_prf+0x1a2> 1c00ab3e: 45f2 lw a1,28(sp) 1c00ab40: 4762 lw a4,24(sp) 1c00ab42: 9702 jalr a4 1c00ab44: 57fd li a5,-1 1c00ab46: 04f51063 bne a0,a5,1c00ab86 <_prf+0x9a> 1c00ab4a: 59fd li s3,-1 1c00ab4c: 14c12083 lw ra,332(sp) 1c00ab50: 14812403 lw s0,328(sp) 1c00ab54: 854e mv a0,s3 1c00ab56: 14412483 lw s1,324(sp) 1c00ab5a: 14012903 lw s2,320(sp) 1c00ab5e: 13c12983 lw s3,316(sp) 1c00ab62: 13812a03 lw s4,312(sp) 1c00ab66: 13412a83 lw s5,308(sp) 1c00ab6a: 13012b03 lw s6,304(sp) 1c00ab6e: 12c12b83 lw s7,300(sp) 1c00ab72: 12812c03 lw s8,296(sp) 1c00ab76: 12412c83 lw s9,292(sp) 1c00ab7a: 12012d03 lw s10,288(sp) 1c00ab7e: 11c12d83 lw s11,284(sp) 1c00ab82: 6171 addi sp,sp,336 1c00ab84: 8082 ret 1c00ab86: 0985 addi s3,s3,1 1c00ab88: 8a62 mv s4,s8 1c00ab8a: 84de mv s1,s7 1c00ab8c: 8c52 mv s8,s4 1c00ab8e: bf79 j 1c00ab2c <_prf+0x40> 1c00ab90: 0f2a8663 beq s5,s2,1c00ac7c <_prf+0x190> 1c00ab94: 0d596963 bltu s2,s5,1c00ac66 <_prf+0x17a> 1c00ab98: fa0a8ae3 beqz s5,1c00ab4c <_prf+0x60> 1c00ab9c: 0dba8e63 beq s5,s11,1c00ac78 <_prf+0x18c> 1c00aba0: 8ba6 mv s7,s1 1c00aba2: 001b8493 addi s1,s7,1 1c00aba6: fff4ca83 lbu s5,-1(s1) 1c00abaa: 1c0007b7 lui a5,0x1c000 1c00abae: 66478513 addi a0,a5,1636 # 1c000664 <__DTOR_END__+0x378> 1c00abb2: 85d6 mv a1,s5 1c00abb4: c1fff0ef jal ra,1c00a7d2 <strchr> 1c00abb8: fd61 bnez a0,1c00ab90 <_prf+0xa4> 1c00abba: 02a00693 li a3,42 1c00abbe: 0eda9a63 bne s5,a3,1c00acb2 <_prf+0x1c6> 1c00abc2: 000c2903 lw s2,0(s8) 1c00abc6: 004c0693 addi a3,s8,4 1c00abca: 00095663 bgez s2,1c00abd6 <_prf+0xea> 1c00abce: 4705 li a4,1 1c00abd0: 41200933 neg s2,s2 1c00abd4: c63a sw a4,12(sp) 1c00abd6: 0004ca83 lbu s5,0(s1) 1c00abda: 8c36 mv s8,a3 1c00abdc: 002b8493 addi s1,s7,2 1c00abe0: 0c800713 li a4,200 1c00abe4: 01277463 bleu s2,a4,1c00abec <_prf+0x100> 1c00abe8: 0c800913 li s2,200 1c00abec: 02e00693 li a3,46 1c00abf0: 5d7d li s10,-1 1c00abf2: 02da9463 bne s5,a3,1c00ac1a <_prf+0x12e> 1c00abf6: 0004c703 lbu a4,0(s1) 1c00abfa: 02a00793 li a5,42 1c00abfe: 10f71063 bne a4,a5,1c00acfe <_prf+0x212> 1c00ac02: 000c2d03 lw s10,0(s8) 1c00ac06: 0485 addi s1,s1,1 1c00ac08: 0c11 addi s8,s8,4 1c00ac0a: 0c800793 li a5,200 1c00ac0e: 01a7d363 ble s10,a5,1c00ac14 <_prf+0x128> 1c00ac12: 5d7d li s10,-1 1c00ac14: 0004ca83 lbu s5,0(s1) 1c00ac18: 0485 addi s1,s1,1 1c00ac1a: 1c0007b7 lui a5,0x1c000 1c00ac1e: 85d6 mv a1,s5 1c00ac20: 66c78513 addi a0,a5,1644 # 1c00066c <__DTOR_END__+0x380> 1c00ac24: bafff0ef jal ra,1c00a7d2 <strchr> 1c00ac28: c501 beqz a0,1c00ac30 <_prf+0x144> 1c00ac2a: 0004ca83 lbu s5,0(s1) 1c00ac2e: 0485 addi s1,s1,1 1c00ac30: 06700693 li a3,103 1c00ac34: 1356c263 blt a3,s5,1c00ad58 <_prf+0x26c> 1c00ac38: 06500693 li a3,101 1c00ac3c: 1edadd63 ble a3,s5,1c00ae36 <_prf+0x34a> 1c00ac40: 04700693 li a3,71 1c00ac44: 0d56c163 blt a3,s5,1c00ad06 <_prf+0x21a> 1c00ac48: 04500693 li a3,69 1c00ac4c: 1edad563 ble a3,s5,1c00ae36 <_prf+0x34a> 1c00ac50: ee0a8ee3 beqz s5,1c00ab4c <_prf+0x60> 1c00ac54: 02500713 li a4,37 1c00ac58: 68ea8263 beq s5,a4,1c00b2dc <_prf+0x7f0> 1c00ac5c: 0c800713 li a4,200 1c00ac60: 69575763 ble s5,a4,1c00b2ee <_prf+0x802> 1c00ac64: b5dd j 1c00ab4a <_prf+0x5e> 1c00ac66: 034a8163 beq s5,s4,1c00ac88 <_prf+0x19c> 1c00ac6a: 016a8b63 beq s5,s6,1c00ac80 <_prf+0x194> 1c00ac6e: f3aa99e3 bne s5,s10,1c00aba0 <_prf+0xb4> 1c00ac72: 4785 li a5,1 1c00ac74: ca3e sw a5,20(sp) 1c00ac76: b72d j 1c00aba0 <_prf+0xb4> 1c00ac78: 4405 li s0,1 1c00ac7a: b71d j 1c00aba0 <_prf+0xb4> 1c00ac7c: 4c85 li s9,1 1c00ac7e: b70d j 1c00aba0 <_prf+0xb4> 1c00ac80: 03000713 li a4,48 1c00ac84: c83a sw a4,16(sp) 1c00ac86: bf29 j 1c00aba0 <_prf+0xb4> 1c00ac88: 4785 li a5,1 1c00ac8a: c63e sw a5,12(sp) 1c00ac8c: bf11 j 1c00aba0 <_prf+0xb4> 1c00ac8e: 02000713 li a4,32 1c00ac92: c83a sw a4,16(sp) 1c00ac94: 4401 li s0,0 1c00ac96: ca02 sw zero,20(sp) 1c00ac98: c602 sw zero,12(sp) 1c00ac9a: 4c81 li s9,0 1c00ac9c: 02300913 li s2,35 1c00aca0: 02d00a13 li s4,45 1c00aca4: 03000b13 li s6,48 1c00aca8: 02b00d13 li s10,43 1c00acac: 02000d93 li s11,32 1c00acb0: bdcd j 1c00aba2 <_prf+0xb6> 1c00acb2: fd0a8693 addi a3,s5,-48 1c00acb6: 4625 li a2,9 1c00acb8: 4901 li s2,0 1c00acba: 45a9 li a1,10 1c00acbc: f2d662e3 bltu a2,a3,1c00abe0 <_prf+0xf4> 1c00acc0: 000bc683 lbu a3,0(s7) 1c00acc4: 001b8493 addi s1,s7,1 1c00acc8: fd068713 addi a4,a3,-48 # fffffd0 <__l1_heap_size+0xfff35e4> 1c00accc: 8ab6 mv s5,a3 1c00acce: f0e669e3 bltu a2,a4,1c00abe0 <_prf+0xf4> 1c00acd2: 02b90933 mul s2,s2,a1 1c00acd6: 8ba6 mv s7,s1 1c00acd8: 9936 add s2,s2,a3 1c00acda: fd090913 addi s2,s2,-48 1c00acde: b7cd j 1c00acc0 <_prf+0x1d4> 1c00ace0: 02ad0733 mul a4,s10,a0 1c00ace4: 84ae mv s1,a1 1c00ace6: 973e add a4,a4,a5 1c00ace8: fd070d13 addi s10,a4,-48 1c00acec: 0004c783 lbu a5,0(s1) 1c00acf0: 00148593 addi a1,s1,1 1c00acf4: fd078613 addi a2,a5,-48 1c00acf8: fec6f4e3 bleu a2,a3,1c00ace0 <_prf+0x1f4> 1c00acfc: b739 j 1c00ac0a <_prf+0x11e> 1c00acfe: 4d01 li s10,0 1c00ad00: 46a5 li a3,9 1c00ad02: 4529 li a0,10 1c00ad04: b7e5 j 1c00acec <_prf+0x200> 1c00ad06: 06300693 li a3,99 1c00ad0a: 0cda8b63 beq s5,a3,1c00ade0 <_prf+0x2f4> 1c00ad0e: 0756c563 blt a3,s5,1c00ad78 <_prf+0x28c> 1c00ad12: 05800693 li a3,88 1c00ad16: f4da93e3 bne s5,a3,1c00ac5c <_prf+0x170> 1c00ad1a: 04410b93 addi s7,sp,68 1c00ad1e: 004c0a13 addi s4,s8,4 1c00ad22: 000c2583 lw a1,0(s8) 1c00ad26: 845e mv s0,s7 1c00ad28: 000c8963 beqz s9,1c00ad3a <_prf+0x24e> 1c00ad2c: 76e1 lui a3,0xffff8 1c00ad2e: 8306c693 xori a3,a3,-2000 1c00ad32: 04d11223 sh a3,68(sp) 1c00ad36: 04610413 addi s0,sp,70 1c00ad3a: 86ea mv a3,s10 1c00ad3c: 4641 li a2,16 1c00ad3e: 8522 mv a0,s0 1c00ad40: 3165 jal 1c00a9e8 <_to_x> 1c00ad42: 05800693 li a3,88 1c00ad46: 58da8863 beq s5,a3,1c00b2d6 <_prf+0x7ea> 1c00ad4a: 41740433 sub s0,s0,s7 1c00ad4e: 9522 add a0,a0,s0 1c00ad50: 01903433 snez s0,s9 1c00ad54: 0406 slli s0,s0,0x1 1c00ad56: a8c9 j 1c00ae28 <_prf+0x33c> 1c00ad58: 07000693 li a3,112 1c00ad5c: 50da8163 beq s5,a3,1c00b25e <_prf+0x772> 1c00ad60: 0556c163 blt a3,s5,1c00ada2 <_prf+0x2b6> 1c00ad64: 06e00693 li a3,110 1c00ad68: 46da8b63 beq s5,a3,1c00b1de <_prf+0x6f2> 1c00ad6c: 4956c063 blt a3,s5,1c00b1ec <_prf+0x700> 1c00ad70: 06900693 li a3,105 1c00ad74: eeda94e3 bne s5,a3,1c00ac5c <_prf+0x170> 1c00ad78: 000c2a83 lw s5,0(s8) 1c00ad7c: 004c0a13 addi s4,s8,4 1c00ad80: 04410b13 addi s6,sp,68 1c00ad84: 060ad963 bgez s5,1c00adf6 <_prf+0x30a> 1c00ad88: 02d00693 li a3,45 1c00ad8c: 04d10223 sb a3,68(sp) 1c00ad90: 800006b7 lui a3,0x80000 1c00ad94: 415005b3 neg a1,s5 1c00ad98: 06da9963 bne s5,a3,1c00ae0a <_prf+0x31e> 1c00ad9c: 800005b7 lui a1,0x80000 1c00ada0: a0ad j 1c00ae0a <_prf+0x31e> 1c00ada2: 07500693 li a3,117 1c00ada6: 50da8063 beq s5,a3,1c00b2a6 <_prf+0x7ba> 1c00adaa: 07800693 li a3,120 1c00adae: f6da86e3 beq s5,a3,1c00ad1a <_prf+0x22e> 1c00adb2: 07300693 li a3,115 1c00adb6: eada93e3 bne s5,a3,1c00ac5c <_prf+0x170> 1c00adba: 000c2583 lw a1,0(s8) 1c00adbe: 004c0a13 addi s4,s8,4 1c00adc2: 4c81 li s9,0 1c00adc4: 0c800793 li a5,200 1c00adc8: 019586b3 add a3,a1,s9 1c00adcc: 0006c683 lbu a3,0(a3) # 80000000 <pulp__FC+0x80000001> 1c00add0: 4a068f63 beqz a3,1c00b28e <_prf+0x7a2> 1c00add4: 0c85 addi s9,s9,1 1c00add6: fefc99e3 bne s9,a5,1c00adc8 <_prf+0x2dc> 1c00adda: 4a0d5c63 bgez s10,1c00b292 <_prf+0x7a6> 1c00adde: a97d j 1c00b29c <_prf+0x7b0> 1c00ade0: 000c2783 lw a5,0(s8) 1c00ade4: 004c0a13 addi s4,s8,4 1c00ade8: 040102a3 sb zero,69(sp) 1c00adec: 04f10223 sb a5,68(sp) 1c00adf0: 4c85 li s9,1 1c00adf2: 4401 li s0,0 1c00adf4: a105 j 1c00b214 <_prf+0x728> 1c00adf6: 4752 lw a4,20(sp) 1c00adf8: 02b00693 li a3,43 1c00adfc: e701 bnez a4,1c00ae04 <_prf+0x318> 1c00adfe: c41d beqz s0,1c00ae2c <_prf+0x340> 1c00ae00: 02000693 li a3,32 1c00ae04: 04d10223 sb a3,68(sp) 1c00ae08: 85d6 mv a1,s5 1c00ae0a: 04510c13 addi s8,sp,69 1c00ae0e: 86ea mv a3,s10 1c00ae10: 4629 li a2,10 1c00ae12: 8562 mv a0,s8 1c00ae14: bd5ff0ef jal ra,1c00a9e8 <_to_x> 1c00ae18: 47d2 lw a5,20(sp) 1c00ae1a: 9562 add a0,a0,s8 1c00ae1c: 41650533 sub a0,a0,s6 1c00ae20: eb89 bnez a5,1c00ae32 <_prf+0x346> 1c00ae22: e019 bnez s0,1c00ae28 <_prf+0x33c> 1c00ae24: 01fad413 srli s0,s5,0x1f 1c00ae28: 57fd li a5,-1 1c00ae2a: a9a1 j 1c00b282 <_prf+0x796> 1c00ae2c: 85d6 mv a1,s5 1c00ae2e: 8c5a mv s8,s6 1c00ae30: bff9 j 1c00ae0e <_prf+0x322> 1c00ae32: 4452 lw s0,20(sp) 1c00ae34: bfd5 j 1c00ae28 <_prf+0x33c> 1c00ae36: 0c1d addi s8,s8,7 1c00ae38: ff8c7c13 andi s8,s8,-8 1c00ae3c: 000c2883 lw a7,0(s8) 1c00ae40: 004c2303 lw t1,4(s8) 1c00ae44: 80000737 lui a4,0x80000 1c00ae48: 0158d593 srli a1,a7,0x15 1c00ae4c: 00b31693 slli a3,t1,0xb 1c00ae50: 8ecd or a3,a3,a1 1c00ae52: fff74713 not a4,a4 1c00ae56: 01435613 srli a2,t1,0x14 1c00ae5a: 08ae slli a7,a7,0xb 1c00ae5c: 8ef9 and a3,a3,a4 1c00ae5e: 7ff67613 andi a2,a2,2047 1c00ae62: d846 sw a7,48(sp) 1c00ae64: da36 sw a3,52(sp) 1c00ae66: 7ff00593 li a1,2047 1c00ae6a: 008c0a13 addi s4,s8,8 1c00ae6e: 08b61d63 bne a2,a1,1c00af08 <_prf+0x41c> 1c00ae72: 00d0 addi a2,sp,68 1c00ae74: 8732 mv a4,a2 1c00ae76: 00035863 bgez t1,1c00ae86 <_prf+0x39a> 1c00ae7a: 02d00713 li a4,45 1c00ae7e: 04e10223 sb a4,68(sp) 1c00ae82: 04510713 addi a4,sp,69 1c00ae86: 00d8e6b3 or a3,a7,a3 1c00ae8a: fbfa8793 addi a5,s5,-65 1c00ae8e: 00370513 addi a0,a4,3 # 80000003 <pulp__FC+0x80000004> 1c00ae92: eaa1 bnez a3,1c00aee2 <_prf+0x3f6> 1c00ae94: 46e5 li a3,25 1c00ae96: 02f6ee63 bltu a3,a5,1c00aed2 <_prf+0x3e6> 1c00ae9a: 6795 lui a5,0x5 1c00ae9c: e4978793 addi a5,a5,-439 # 4e49 <_l1_preload_size+0x1839> 1c00aea0: 00f71023 sh a5,0(a4) 1c00aea4: 04600793 li a5,70 1c00aea8: 00f70123 sb a5,2(a4) 1c00aeac: 000701a3 sb zero,3(a4) 1c00aeb0: 8d11 sub a0,a0,a2 1c00aeb2: 47d2 lw a5,20(sp) 1c00aeb4: 48079f63 bnez a5,1c00b352 <_prf+0x866> 1c00aeb8: e419 bnez s0,1c00aec6 <_prf+0x3da> 1c00aeba: 04414403 lbu s0,68(sp) 1c00aebe: fd340413 addi s0,s0,-45 1c00aec2: 00143413 seqz s0,s0 1c00aec6: 0c800793 li a5,200 1c00aeca: c8a7c0e3 blt a5,a0,1c00ab4a <_prf+0x5e> 1c00aece: 8caa mv s9,a0 1c00aed0: a691 j 1c00b214 <_prf+0x728> 1c00aed2: 679d lui a5,0x7 1c00aed4: e6978793 addi a5,a5,-407 # 6e69 <_l1_preload_size+0x3859> 1c00aed8: 00f71023 sh a5,0(a4) 1c00aedc: 06600793 li a5,102 1c00aee0: b7e1 j 1c00aea8 <_prf+0x3bc> 1c00aee2: 46e5 li a3,25 1c00aee4: 00f6ea63 bltu a3,a5,1c00aef8 <_prf+0x40c> 1c00aee8: 6791 lui a5,0x4 1c00aeea: 14e78793 addi a5,a5,334 # 414e <_l1_preload_size+0xb3e> 1c00aeee: 00f71023 sh a5,0(a4) 1c00aef2: 04e00793 li a5,78 1c00aef6: bf4d j 1c00aea8 <_prf+0x3bc> 1c00aef8: 6799 lui a5,0x6 1c00aefa: 16e78793 addi a5,a5,366 # 616e <_l1_preload_size+0x2b5e> 1c00aefe: 00f71023 sh a5,0(a4) 1c00af02: 06e00793 li a5,110 1c00af06: b74d j 1c00aea8 <_prf+0x3bc> 1c00af08: 04600593 li a1,70 1c00af0c: 00ba9463 bne s5,a1,1c00af14 <_prf+0x428> 1c00af10: 06600a93 li s5,102 1c00af14: 011665b3 or a1,a2,a7 1c00af18: 8dd5 or a1,a1,a3 1c00af1a: c9c9 beqz a1,1c00afac <_prf+0x4c0> 1c00af1c: 800007b7 lui a5,0x80000 1c00af20: 8edd or a3,a3,a5 1c00af22: da36 sw a3,52(sp) 1c00af24: d846 sw a7,48(sp) 1c00af26: c0260c13 addi s8,a2,-1022 1c00af2a: 02d00693 li a3,45 1c00af2e: 00034b63 bltz t1,1c00af44 <_prf+0x458> 1c00af32: 4752 lw a4,20(sp) 1c00af34: 02b00693 li a3,43 1c00af38: e711 bnez a4,1c00af44 <_prf+0x458> 1c00af3a: 04410b13 addi s6,sp,68 1c00af3e: c419 beqz s0,1c00af4c <_prf+0x460> 1c00af40: 02000693 li a3,32 1c00af44: 04d10223 sb a3,68(sp) 1c00af48: 04510b13 addi s6,sp,69 1c00af4c: 4b81 li s7,0 1c00af4e: 55f9 li a1,-2 1c00af50: 06bc4363 blt s8,a1,1c00afb6 <_prf+0x4ca> 1c00af54: 0b804a63 bgtz s8,1c00b008 <_prf+0x51c> 1c00af58: 4d91 li s11,4 1c00af5a: 1808 addi a0,sp,48 1c00af5c: 0c05 addi s8,s8,1 1c00af5e: aebff0ef jal ra,1c00aa48 <_rlrshift> 1c00af62: ffbc1ce3 bne s8,s11,1c00af5a <_prf+0x46e> 1c00af66: 000d5363 bgez s10,1c00af6c <_prf+0x480> 1c00af6a: 4d19 li s10,6 1c00af6c: fdfaf593 andi a1,s5,-33 1c00af70: 04700513 li a0,71 1c00af74: 0ca59663 bne a1,a0,1c00b040 <_prf+0x554> 1c00af78: 4c01 li s8,0 1c00af7a: 000c9463 bnez s9,1c00af82 <_prf+0x496> 1c00af7e: 01a03c33 snez s8,s10 1c00af82: 55f5 li a1,-3 1c00af84: 00bbc663 blt s7,a1,1c00af90 <_prf+0x4a4> 1c00af88: 001d0593 addi a1,s10,1 1c00af8c: 0b75df63 ble s7,a1,1c00b04a <_prf+0x55e> 1c00af90: 06700593 li a1,103 1c00af94: 14ba8c63 beq s5,a1,1c00b0ec <_prf+0x600> 1c00af98: 04500a93 li s5,69 1c00af9c: 001d0593 addi a1,s10,1 1c00afa0: 4541 li a0,16 1c00afa2: d62a sw a0,44(sp) 1c00afa4: 0ab55c63 ble a1,a0,1c00b05c <_prf+0x570> 1c00afa8: 45c1 li a1,16 1c00afaa: a84d j 1c00b05c <_prf+0x570> 1c00afac: 4c01 li s8,0 1c00afae: b751 j 1c00af32 <_prf+0x446> 1c00afb0: 1808 addi a0,sp,48 1c00afb2: a97ff0ef jal ra,1c00aa48 <_rlrshift> 1c00afb6: 55d2 lw a1,52(sp) 1c00afb8: 333337b7 lui a5,0x33333 1c00afbc: 33278793 addi a5,a5,818 # 33333332 <__l2_shared_end+0x1731fb9a> 1c00afc0: 5342 lw t1,48(sp) 1c00afc2: 0c05 addi s8,s8,1 1c00afc4: feb7e6e3 bltu a5,a1,1c00afb0 <_prf+0x4c4> 1c00afc8: 4895 li a7,5 1c00afca: 02b88533 mul a0,a7,a1 1c00afce: 1bfd addi s7,s7,-1 1c00afd0: 0268b5b3 mulhu a1,a7,t1 1c00afd4: 026888b3 mul a7,a7,t1 1c00afd8: 95aa add a1,a1,a0 1c00afda: da2e sw a1,52(sp) 1c00afdc: 4501 li a0,0 1c00afde: d846 sw a7,48(sp) 1c00afe0: 800006b7 lui a3,0x80000 1c00afe4: fff6c693 not a3,a3 1c00afe8: 00b6f663 bleu a1,a3,1c00aff4 <_prf+0x508> 1c00afec: d12d beqz a0,1c00af4e <_prf+0x462> 1c00afee: d846 sw a7,48(sp) 1c00aff0: da2e sw a1,52(sp) 1c00aff2: bfb1 j 1c00af4e <_prf+0x462> 1c00aff4: 01f8d313 srli t1,a7,0x1f 1c00aff8: 00159513 slli a0,a1,0x1 1c00affc: 00a365b3 or a1,t1,a0 1c00b000: 0886 slli a7,a7,0x1 1c00b002: 1c7d addi s8,s8,-1 1c00b004: 4505 li a0,1 1c00b006: bfe9 j 1c00afe0 <_prf+0x4f4> 1c00b008: 1808 addi a0,sp,48 1c00b00a: a5fff0ef jal ra,1c00aa68 <_ldiv5> 1c00b00e: 58c2 lw a7,48(sp) 1c00b010: 55d2 lw a1,52(sp) 1c00b012: 1c7d addi s8,s8,-1 1c00b014: 0b85 addi s7,s7,1 1c00b016: 4501 li a0,0 1c00b018: 80000737 lui a4,0x80000 1c00b01c: fff74713 not a4,a4 1c00b020: 00b77663 bleu a1,a4,1c00b02c <_prf+0x540> 1c00b024: d905 beqz a0,1c00af54 <_prf+0x468> 1c00b026: d846 sw a7,48(sp) 1c00b028: da2e sw a1,52(sp) 1c00b02a: b72d j 1c00af54 <_prf+0x468> 1c00b02c: 01f8d313 srli t1,a7,0x1f 1c00b030: 00159513 slli a0,a1,0x1 1c00b034: 00a365b3 or a1,t1,a0 1c00b038: 0886 slli a7,a7,0x1 1c00b03a: 1c7d addi s8,s8,-1 1c00b03c: 4505 li a0,1 1c00b03e: bfe9 j 1c00b018 <_prf+0x52c> 1c00b040: 06600593 li a1,102 1c00b044: 4c01 li s8,0 1c00b046: f4ba9be3 bne s5,a1,1c00af9c <_prf+0x4b0> 1c00b04a: 01ab85b3 add a1,s7,s10 1c00b04e: 06600a93 li s5,102 1c00b052: f405d7e3 bgez a1,1c00afa0 <_prf+0x4b4> 1c00b056: 45c1 li a1,16 1c00b058: d62e sw a1,44(sp) 1c00b05a: 4581 li a1,0 1c00b05c: 4301 li t1,0 1c00b05e: 080003b7 lui t2,0x8000 1c00b062: dc1a sw t1,56(sp) 1c00b064: de1e sw t2,60(sp) 1c00b066: 5dfd li s11,-1 1c00b068: 15fd addi a1,a1,-1 1c00b06a: 09b59463 bne a1,s11,1c00b0f2 <_prf+0x606> 1c00b06e: 55c2 lw a1,48(sp) 1c00b070: 5562 lw a0,56(sp) 1c00b072: 58d2 lw a7,52(sp) 1c00b074: 5372 lw t1,60(sp) 1c00b076: 952e add a0,a0,a1 1c00b078: 00b535b3 sltu a1,a0,a1 1c00b07c: 989a add a7,a7,t1 1c00b07e: 95c6 add a1,a1,a7 1c00b080: d82a sw a0,48(sp) 1c00b082: f0000537 lui a0,0xf0000 1c00b086: da2e sw a1,52(sp) 1c00b088: 8de9 and a1,a1,a0 1c00b08a: c981 beqz a1,1c00b09a <_prf+0x5ae> 1c00b08c: 1808 addi a0,sp,48 1c00b08e: 9dbff0ef jal ra,1c00aa68 <_ldiv5> 1c00b092: 1808 addi a0,sp,48 1c00b094: 9b5ff0ef jal ra,1c00aa48 <_rlrshift> 1c00b098: 0b85 addi s7,s7,1 1c00b09a: 06600593 li a1,102 1c00b09e: 001b0d93 addi s11,s6,1 1c00b0a2: 08ba9663 bne s5,a1,1c00b12e <_prf+0x642> 1c00b0a6: 05705f63 blez s7,1c00b104 <_prf+0x618> 1c00b0aa: 017b0db3 add s11,s6,s7 1c00b0ae: 106c addi a1,sp,44 1c00b0b0: 1808 addi a0,sp,48 1c00b0b2: 0b05 addi s6,s6,1 1c00b0b4: 9fdff0ef jal ra,1c00aab0 <_get_digit> 1c00b0b8: feab0fa3 sb a0,-1(s6) 1c00b0bc: ffbb19e3 bne s6,s11,1c00b0ae <_prf+0x5c2> 1c00b0c0: 4b81 li s7,0 1c00b0c2: 000c9463 bnez s9,1c00b0ca <_prf+0x5de> 1c00b0c6: 020d0063 beqz s10,1c00b0e6 <_prf+0x5fa> 1c00b0ca: 02e00613 li a2,46 1c00b0ce: 00cd8023 sb a2,0(s11) 1c00b0d2: 8b6e mv s6,s11 1c00b0d4: 01ad8cb3 add s9,s11,s10 1c00b0d8: 03000313 li t1,48 1c00b0dc: 036c9963 bne s9,s6,1c00b10e <_prf+0x622> 1c00b0e0: 001d0713 addi a4,s10,1 1c00b0e4: 9dba add s11,s11,a4 1c00b0e6: 060c1e63 bnez s8,1c00b162 <_prf+0x676> 1c00b0ea: a8d1 j 1c00b1be <_prf+0x6d2> 1c00b0ec: 06500a93 li s5,101 1c00b0f0: b575 j 1c00af9c <_prf+0x4b0> 1c00b0f2: 1828 addi a0,sp,56 1c00b0f4: c42e sw a1,8(sp) 1c00b0f6: 973ff0ef jal ra,1c00aa68 <_ldiv5> 1c00b0fa: 1828 addi a0,sp,56 1c00b0fc: 94dff0ef jal ra,1c00aa48 <_rlrshift> 1c00b100: 45a2 lw a1,8(sp) 1c00b102: b79d j 1c00b068 <_prf+0x57c> 1c00b104: 03000593 li a1,48 1c00b108: 00bb0023 sb a1,0(s6) 1c00b10c: bf5d j 1c00b0c2 <_prf+0x5d6> 1c00b10e: 000b8763 beqz s7,1c00b11c <_prf+0x630> 1c00b112: 006b00a3 sb t1,1(s6) 1c00b116: 0b85 addi s7,s7,1 1c00b118: 0b05 addi s6,s6,1 1c00b11a: b7c9 j 1c00b0dc <_prf+0x5f0> 1c00b11c: 106c addi a1,sp,44 1c00b11e: 1808 addi a0,sp,48 1c00b120: c41a sw t1,8(sp) 1c00b122: 98fff0ef jal ra,1c00aab0 <_get_digit> 1c00b126: 00ab00a3 sb a0,1(s6) 1c00b12a: 4322 lw t1,8(sp) 1c00b12c: b7f5 j 1c00b118 <_prf+0x62c> 1c00b12e: 106c addi a1,sp,44 1c00b130: 1808 addi a0,sp,48 1c00b132: 97fff0ef jal ra,1c00aab0 <_get_digit> 1c00b136: 00ab0023 sb a0,0(s6) 1c00b13a: 03000593 li a1,48 1c00b13e: 00b50363 beq a0,a1,1c00b144 <_prf+0x658> 1c00b142: 1bfd addi s7,s7,-1 1c00b144: 000c9463 bnez s9,1c00b14c <_prf+0x660> 1c00b148: 000d0b63 beqz s10,1c00b15e <_prf+0x672> 1c00b14c: 002b0d93 addi s11,s6,2 1c00b150: 02e00593 li a1,46 1c00b154: 00bb00a3 sb a1,1(s6) 1c00b158: 9d6e add s10,s10,s11 1c00b15a: 07bd1863 bne s10,s11,1c00b1ca <_prf+0x6de> 1c00b15e: 000c0f63 beqz s8,1c00b17c <_prf+0x690> 1c00b162: 03000593 li a1,48 1c00b166: fffdc603 lbu a2,-1(s11) 1c00b16a: fffd8713 addi a4,s11,-1 1c00b16e: 06b60663 beq a2,a1,1c00b1da <_prf+0x6ee> 1c00b172: 02e00593 li a1,46 1c00b176: 00b61363 bne a2,a1,1c00b17c <_prf+0x690> 1c00b17a: 8dba mv s11,a4 1c00b17c: fdfaf713 andi a4,s5,-33 1c00b180: 04500613 li a2,69 1c00b184: 02c71d63 bne a4,a2,1c00b1be <_prf+0x6d2> 1c00b188: 87d6 mv a5,s5 1c00b18a: 00fd8023 sb a5,0(s11) 1c00b18e: 02b00793 li a5,43 1c00b192: 000bd663 bgez s7,1c00b19e <_prf+0x6b2> 1c00b196: 41700bb3 neg s7,s7 1c00b19a: 02d00793 li a5,45 1c00b19e: 00fd80a3 sb a5,1(s11) 1c00b1a2: 47a9 li a5,10 1c00b1a4: 02fbc733 div a4,s7,a5 1c00b1a8: 0d91 addi s11,s11,4 1c00b1aa: 02fbe6b3 rem a3,s7,a5 1c00b1ae: 03070713 addi a4,a4,48 # 80000030 <pulp__FC+0x80000031> 1c00b1b2: feed8f23 sb a4,-2(s11) 1c00b1b6: 03068693 addi a3,a3,48 # 80000030 <pulp__FC+0x80000031> 1c00b1ba: fedd8fa3 sb a3,-1(s11) 1c00b1be: 00c8 addi a0,sp,68 1c00b1c0: 000d8023 sb zero,0(s11) 1c00b1c4: 40ad8533 sub a0,s11,a0 1c00b1c8: b1ed j 1c00aeb2 <_prf+0x3c6> 1c00b1ca: 106c addi a1,sp,44 1c00b1cc: 1808 addi a0,sp,48 1c00b1ce: 0d85 addi s11,s11,1 1c00b1d0: 8e1ff0ef jal ra,1c00aab0 <_get_digit> 1c00b1d4: fead8fa3 sb a0,-1(s11) 1c00b1d8: b749 j 1c00b15a <_prf+0x66e> 1c00b1da: 8dba mv s11,a4 1c00b1dc: b769 j 1c00b166 <_prf+0x67a> 1c00b1de: 000c2783 lw a5,0(s8) 1c00b1e2: 004c0a13 addi s4,s8,4 1c00b1e6: 0137a023 sw s3,0(a5) 1c00b1ea: b24d j 1c00ab8c <_prf+0xa0> 1c00b1ec: 004c0a13 addi s4,s8,4 1c00b1f0: 000c2583 lw a1,0(s8) 1c00b1f4: 00dc addi a5,sp,68 1c00b1f6: 040c8463 beqz s9,1c00b23e <_prf+0x752> 1c00b1fa: 03000693 li a3,48 1c00b1fe: 04d10223 sb a3,68(sp) 1c00b202: 04510513 addi a0,sp,69 1c00b206: ed8d bnez a1,1c00b240 <_prf+0x754> 1c00b208: 040102a3 sb zero,69(sp) 1c00b20c: 57fd li a5,-1 1c00b20e: 4401 li s0,0 1c00b210: 0efd1163 bne s10,a5,1c00b2f2 <_prf+0x806> 1c00b214: 0f2cc363 blt s9,s2,1c00b2fa <_prf+0x80e> 1c00b218: 8966 mv s2,s9 1c00b21a: 00c0 addi s0,sp,68 1c00b21c: 40898ab3 sub s5,s3,s0 1c00b220: 5b7d li s6,-1 1c00b222: 015409b3 add s3,s0,s5 1c00b226: 960903e3 beqz s2,1c00ab8c <_prf+0xa0> 1c00b22a: 45f2 lw a1,28(sp) 1c00b22c: 00044503 lbu a0,0(s0) 1c00b230: 47e2 lw a5,24(sp) 1c00b232: 9782 jalr a5 1c00b234: 91650be3 beq a0,s6,1c00ab4a <_prf+0x5e> 1c00b238: 197d addi s2,s2,-1 1c00b23a: 0405 addi s0,s0,1 1c00b23c: b7dd j 1c00b222 <_prf+0x736> 1c00b23e: 853e mv a0,a5 1c00b240: 86ea mv a3,s10 1c00b242: 4621 li a2,8 1c00b244: 40f50433 sub s0,a0,a5 1c00b248: fa0ff0ef jal ra,1c00a9e8 <_to_x> 1c00b24c: 9522 add a0,a0,s0 1c00b24e: 57fd li a5,-1 1c00b250: 4401 li s0,0 1c00b252: c6fd0ae3 beq s10,a5,1c00aec6 <_prf+0x3da> 1c00b256: 02000793 li a5,32 1c00b25a: c83e sw a5,16(sp) 1c00b25c: b1ad j 1c00aec6 <_prf+0x3da> 1c00b25e: 000c2583 lw a1,0(s8) 1c00b262: 77e1 lui a5,0xffff8 1c00b264: 8307c793 xori a5,a5,-2000 1c00b268: 46a1 li a3,8 1c00b26a: 4641 li a2,16 1c00b26c: 04610513 addi a0,sp,70 1c00b270: 04f11223 sh a5,68(sp) 1c00b274: f74ff0ef jal ra,1c00a9e8 <_to_x> 1c00b278: 004c0a13 addi s4,s8,4 1c00b27c: 0509 addi a0,a0,2 1c00b27e: 57fd li a5,-1 1c00b280: 4401 li s0,0 1c00b282: c4fd02e3 beq s10,a5,1c00aec6 <_prf+0x3da> 1c00b286: 02000713 li a4,32 1c00b28a: c83a sw a4,16(sp) 1c00b28c: b92d j 1c00aec6 <_prf+0x3da> 1c00b28e: 000d4563 bltz s10,1c00b298 <_prf+0x7ac> 1c00b292: 019d5363 ble s9,s10,1c00b298 <_prf+0x7ac> 1c00b296: 8cea mv s9,s10 1c00b298: 8e0c8ae3 beqz s9,1c00ab8c <_prf+0xa0> 1c00b29c: 8666 mv a2,s9 1c00b29e: 00c8 addi a0,sp,68 1c00b2a0: ce4ff0ef jal ra,1c00a784 <memcpy> 1c00b2a4: b6b9 j 1c00adf2 <_prf+0x306> 1c00b2a6: 000c2583 lw a1,0(s8) 1c00b2aa: 86ea mv a3,s10 1c00b2ac: 4629 li a2,10 1c00b2ae: 00c8 addi a0,sp,68 1c00b2b0: 004c0a13 addi s4,s8,4 1c00b2b4: f34ff0ef jal ra,1c00a9e8 <_to_x> 1c00b2b8: bf59 j 1c00b24e <_prf+0x762> 1c00b2ba: f9f78613 addi a2,a5,-97 # ffff7f9f <pulp__FC+0xffff7fa0> 1c00b2be: 0ff67613 andi a2,a2,255 1c00b2c2: 00c5e563 bltu a1,a2,1c00b2cc <_prf+0x7e0> 1c00b2c6: 1781 addi a5,a5,-32 1c00b2c8: 00f68023 sb a5,0(a3) 1c00b2cc: 0685 addi a3,a3,1 1c00b2ce: 0006c783 lbu a5,0(a3) 1c00b2d2: f7e5 bnez a5,1c00b2ba <_prf+0x7ce> 1c00b2d4: bc9d j 1c00ad4a <_prf+0x25e> 1c00b2d6: 86de mv a3,s7 1c00b2d8: 45e5 li a1,25 1c00b2da: bfd5 j 1c00b2ce <_prf+0x7e2> 1c00b2dc: 45f2 lw a1,28(sp) 1c00b2de: 4762 lw a4,24(sp) 1c00b2e0: 02500513 li a0,37 1c00b2e4: 9702 jalr a4 1c00b2e6: 57fd li a5,-1 1c00b2e8: 86f501e3 beq a0,a5,1c00ab4a <_prf+0x5e> 1c00b2ec: 0985 addi s3,s3,1 1c00b2ee: 8a62 mv s4,s8 1c00b2f0: b871 j 1c00ab8c <_prf+0xa0> 1c00b2f2: 02000793 li a5,32 1c00b2f6: c83e sw a5,16(sp) 1c00b2f8: bf31 j 1c00b214 <_prf+0x728> 1c00b2fa: 4732 lw a4,12(sp) 1c00b2fc: cf01 beqz a4,1c00b314 <_prf+0x828> 1c00b2fe: 02000713 li a4,32 1c00b302: 00d4 addi a3,sp,68 1c00b304: 019687b3 add a5,a3,s9 1c00b308: 00e78023 sb a4,0(a5) 1c00b30c: 0c85 addi s9,s9,1 1c00b30e: ff991ae3 bne s2,s9,1c00b302 <_prf+0x816> 1c00b312: b721 j 1c00b21a <_prf+0x72e> 1c00b314: 00cc addi a1,sp,68 1c00b316: 41990bb3 sub s7,s2,s9 1c00b31a: 001c8613 addi a2,s9,1 1c00b31e: 01758533 add a0,a1,s7 1c00b322: c7aff0ef jal ra,1c00a79c <memmove> 1c00b326: 4742 lw a4,16(sp) 1c00b328: 02000793 li a5,32 1c00b32c: 00f70363 beq a4,a5,1c00b332 <_prf+0x846> 1c00b330: c622 sw s0,12(sp) 1c00b332: 47b2 lw a5,12(sp) 1c00b334: 9bbe add s7,s7,a5 1c00b336: 4732 lw a4,12(sp) 1c00b338: ef7751e3 ble s7,a4,1c00b21a <_prf+0x72e> 1c00b33c: 4732 lw a4,12(sp) 1c00b33e: 00d4 addi a3,sp,68 1c00b340: 00e687b3 add a5,a3,a4 1c00b344: 4742 lw a4,16(sp) 1c00b346: 00e78023 sb a4,0(a5) 1c00b34a: 47b2 lw a5,12(sp) 1c00b34c: 0785 addi a5,a5,1 1c00b34e: c63e sw a5,12(sp) 1c00b350: b7dd j 1c00b336 <_prf+0x84a> 1c00b352: 4452 lw s0,20(sp) 1c00b354: be8d j 1c00aec6 <_prf+0x3da> 1c00b356 <__rt_uart_cluster_req_done>: 1c00b356: 300476f3 csrrci a3,mstatus,8 1c00b35a: 4785 li a5,1 1c00b35c: 08f50c23 sb a5,152(a0) # f0000098 <pulp__FC+0xf0000099> 1c00b360: 09954783 lbu a5,153(a0) 1c00b364: 00201737 lui a4,0x201 1c00b368: e0470713 addi a4,a4,-508 # 200e04 <__l1_heap_size+0x1f4418> 1c00b36c: 04078793 addi a5,a5,64 1c00b370: 07da slli a5,a5,0x16 1c00b372: 97ba add a5,a5,a4 1c00b374: 0007a023 sw zero,0(a5) 1c00b378: 30069073 csrw mstatus,a3 1c00b37c: 8082 ret 1c00b37e <__rt_uart_setup.isra.6>: 1c00b37e: 1c001737 lui a4,0x1c001 1c00b382: 1f872703 lw a4,504(a4) # 1c0011f8 <__rt_freq_domains> 1c00b386: 00155793 srli a5,a0,0x1 1c00b38a: 97ba add a5,a5,a4 1c00b38c: 02a7d7b3 divu a5,a5,a0 1c00b390: 1a102737 lui a4,0x1a102 1c00b394: 17fd addi a5,a5,-1 1c00b396: 07c2 slli a5,a5,0x10 1c00b398: 3067e793 ori a5,a5,774 1c00b39c: 1af72223 sw a5,420(a4) # 1a1021a4 <__l1_end+0xa0feb90> 1c00b3a0: 8082 ret 1c00b3a2 <__rt_uart_setfreq_after>: 1c00b3a2: 1c0017b7 lui a5,0x1c001 1c00b3a6: 17878793 addi a5,a5,376 # 1c001178 <__rt_uart> 1c00b3aa: 4398 lw a4,0(a5) 1c00b3ac: cb09 beqz a4,1c00b3be <__rt_uart_setfreq_after+0x1c> 1c00b3ae: 4788 lw a0,8(a5) 1c00b3b0: 1141 addi sp,sp,-16 1c00b3b2: c606 sw ra,12(sp) 1c00b3b4: 37e9 jal 1c00b37e <__rt_uart_setup.isra.6> 1c00b3b6: 40b2 lw ra,12(sp) 1c00b3b8: 4501 li a0,0 1c00b3ba: 0141 addi sp,sp,16 1c00b3bc: 8082 ret 1c00b3be: 4501 li a0,0 1c00b3c0: 8082 ret 1c00b3c2 <__rt_uart_cluster_req>: 1c00b3c2: 1141 addi sp,sp,-16 1c00b3c4: c606 sw ra,12(sp) 1c00b3c6: c422 sw s0,8(sp) 1c00b3c8: 30047473 csrrci s0,mstatus,8 1c00b3cc: 1c00b7b7 lui a5,0x1c00b 1c00b3d0: 35678793 addi a5,a5,854 # 1c00b356 <__rt_uart_cluster_req_done> 1c00b3d4: c55c sw a5,12(a0) 1c00b3d6: 4785 li a5,1 1c00b3d8: d55c sw a5,44(a0) 1c00b3da: 411c lw a5,0(a0) 1c00b3dc: 02052823 sw zero,48(a0) 1c00b3e0: c908 sw a0,16(a0) 1c00b3e2: 43cc lw a1,4(a5) 1c00b3e4: 4514 lw a3,8(a0) 1c00b3e6: 4150 lw a2,4(a0) 1c00b3e8: 0586 slli a1,a1,0x1 1c00b3ea: 00c50793 addi a5,a0,12 1c00b3ee: 4701 li a4,0 1c00b3f0: 0585 addi a1,a1,1 1c00b3f2: 4501 li a0,0 1c00b3f4: e99fe0ef jal ra,1c00a28c <rt_periph_copy> 1c00b3f8: 30041073 csrw mstatus,s0 1c00b3fc: 40b2 lw ra,12(sp) 1c00b3fe: 4422 lw s0,8(sp) 1c00b400: 0141 addi sp,sp,16 1c00b402: 8082 ret 1c00b404 <__rt_uart_wait_tx_done.isra.5>: 1c00b404: 1a102737 lui a4,0x1a102 1c00b408: 19872783 lw a5,408(a4) # 1a102198 <__l1_end+0xa0feb84> 1c00b40c: 8bc1 andi a5,a5,16 1c00b40e: e7b9 bnez a5,1c00b45c <__rt_uart_wait_tx_done.isra.5+0x58> 1c00b410: 1a102737 lui a4,0x1a102 1c00b414: 1a072783 lw a5,416(a4) # 1a1021a0 <__l1_end+0xa0feb8c> 1c00b418: 8b85 andi a5,a5,1 1c00b41a: ffed bnez a5,1c00b414 <__rt_uart_wait_tx_done.isra.5+0x10> 1c00b41c: f14027f3 csrr a5,mhartid 1c00b420: 8795 srai a5,a5,0x5 1c00b422: 1a10a637 lui a2,0x1a10a 1c00b426: 03f7f793 andi a5,a5,63 1c00b42a: 03200693 li a3,50 1c00b42e: 81460813 addi a6,a2,-2028 # 1a109814 <__l1_end+0xa106200> 1c00b432: 6711 lui a4,0x4 1c00b434: 6311 lui t1,0x4 1c00b436: 45fd li a1,31 1c00b438: 00204537 lui a0,0x204 1c00b43c: 88be mv a7,a5 1c00b43e: 00682023 sw t1,0(a6) 1c00b442: 02b79063 bne a5,a1,1c00b462 <__rt_uart_wait_tx_done.isra.5+0x5e> 1c00b446: 80e62223 sw a4,-2044(a2) 1c00b44a: 10500073 wfi 1c00b44e: 00b89c63 bne a7,a1,1c00b466 <__rt_uart_wait_tx_done.isra.5+0x62> 1c00b452: 80e62423 sw a4,-2040(a2) 1c00b456: 16fd addi a3,a3,-1 1c00b458: f2fd bnez a3,1c00b43e <__rt_uart_wait_tx_done.isra.5+0x3a> 1c00b45a: 8082 ret 1c00b45c: 10500073 wfi 1c00b460: b765 j 1c00b408 <__rt_uart_wait_tx_done.isra.5+0x4> 1c00b462: c958 sw a4,20(a0) 1c00b464: b7dd j 1c00b44a <__rt_uart_wait_tx_done.isra.5+0x46> 1c00b466: c918 sw a4,16(a0) 1c00b468: b7fd j 1c00b456 <__rt_uart_wait_tx_done.isra.5+0x52> 1c00b46a <__rt_uart_setfreq_before>: 1c00b46a: 1c0017b7 lui a5,0x1c001 1c00b46e: 1787a783 lw a5,376(a5) # 1c001178 <__rt_uart> 1c00b472: cf99 beqz a5,1c00b490 <__rt_uart_setfreq_before+0x26> 1c00b474: 1141 addi sp,sp,-16 1c00b476: c606 sw ra,12(sp) 1c00b478: 3771 jal 1c00b404 <__rt_uart_wait_tx_done.isra.5> 1c00b47a: 40b2 lw ra,12(sp) 1c00b47c: 005007b7 lui a5,0x500 1c00b480: 1a102737 lui a4,0x1a102 1c00b484: 0799 addi a5,a5,6 1c00b486: 1af72223 sw a5,420(a4) # 1a1021a4 <__l1_end+0xa0feb90> 1c00b48a: 4501 li a0,0 1c00b48c: 0141 addi sp,sp,16 1c00b48e: 8082 ret 1c00b490: 4501 li a0,0 1c00b492: 8082 ret 1c00b494 <soc_eu_fcEventMask_setEvent>: 1c00b494: 47fd li a5,31 1c00b496: 4721 li a4,8 1c00b498: 00a7d463 ble a0,a5,1c00b4a0 <soc_eu_fcEventMask_setEvent+0xc> 1c00b49c: 1501 addi a0,a0,-32 1c00b49e: 4711 li a4,4 1c00b4a0: 1a1067b7 lui a5,0x1a106 1c00b4a4: 973e add a4,a4,a5 1c00b4a6: 4314 lw a3,0(a4) 1c00b4a8: 4785 li a5,1 1c00b4aa: 00a79533 sll a0,a5,a0 1c00b4ae: fff54513 not a0,a0 1c00b4b2: 8d75 and a0,a0,a3 1c00b4b4: c308 sw a0,0(a4) 1c00b4b6: 8082 ret 1c00b4b8 <rt_uart_conf_init>: 1c00b4b8: 000997b7 lui a5,0x99 1c00b4bc: 96878793 addi a5,a5,-1688 # 98968 <__l1_heap_size+0x8bf7c> 1c00b4c0: c11c sw a5,0(a0) 1c00b4c2: 57fd li a5,-1 1c00b4c4: c15c sw a5,4(a0) 1c00b4c6: 8082 ret 1c00b4c8 <__rt_uart_open>: 1c00b4c8: 1141 addi sp,sp,-16 1c00b4ca: c606 sw ra,12(sp) 1c00b4cc: c422 sw s0,8(sp) 1c00b4ce: c226 sw s1,4(sp) 1c00b4d0: c04a sw s2,0(sp) 1c00b4d2: 30047973 csrrci s2,mstatus,8 1c00b4d6: cd8d beqz a1,1c00b510 <__rt_uart_open+0x48> 1c00b4d8: 4194 lw a3,0(a1) 1c00b4da: 1c0017b7 lui a5,0x1c001 1c00b4de: ffd50713 addi a4,a0,-3 # 203ffd <__l1_heap_size+0x1f7611> 1c00b4e2: 17878413 addi s0,a5,376 # 1c001178 <__rt_uart> 1c00b4e6: 0712 slli a4,a4,0x4 1c00b4e8: 943a add s0,s0,a4 1c00b4ea: 4010 lw a2,0(s0) 1c00b4ec: 17878793 addi a5,a5,376 1c00b4f0: c60d beqz a2,1c00b51a <__rt_uart_open+0x52> 1c00b4f2: c589 beqz a1,1c00b4fc <__rt_uart_open+0x34> 1c00b4f4: 418c lw a1,0(a1) 1c00b4f6: 4414 lw a3,8(s0) 1c00b4f8: 04d59a63 bne a1,a3,1c00b54c <__rt_uart_open+0x84> 1c00b4fc: 97ba add a5,a5,a4 1c00b4fe: 0605 addi a2,a2,1 1c00b500: c390 sw a2,0(a5) 1c00b502: 8522 mv a0,s0 1c00b504: 40b2 lw ra,12(sp) 1c00b506: 4422 lw s0,8(sp) 1c00b508: 4492 lw s1,4(sp) 1c00b50a: 4902 lw s2,0(sp) 1c00b50c: 0141 addi sp,sp,16 1c00b50e: 8082 ret 1c00b510: 000996b7 lui a3,0x99 1c00b514: 96868693 addi a3,a3,-1688 # 98968 <__l1_heap_size+0x8bf7c> 1c00b518: b7c9 j 1c00b4da <__rt_uart_open+0x12> 1c00b51a: 4785 li a5,1 1c00b51c: 1a102737 lui a4,0x1a102 1c00b520: c01c sw a5,0(s0) 1c00b522: c048 sw a0,4(s0) 1c00b524: c414 sw a3,8(s0) 1c00b526: 78072683 lw a3,1920(a4) # 1a102780 <__l1_end+0xa0ff16c> 1c00b52a: 00a797b3 sll a5,a5,a0 1c00b52e: 00151493 slli s1,a0,0x1 1c00b532: 8fd5 or a5,a5,a3 1c00b534: 78f72023 sw a5,1920(a4) 1c00b538: 8526 mv a0,s1 1c00b53a: 3fa9 jal 1c00b494 <soc_eu_fcEventMask_setEvent> 1c00b53c: 00148513 addi a0,s1,1 1c00b540: 3f91 jal 1c00b494 <soc_eu_fcEventMask_setEvent> 1c00b542: 4408 lw a0,8(s0) 1c00b544: 3d2d jal 1c00b37e <__rt_uart_setup.isra.6> 1c00b546: 30091073 csrw mstatus,s2 1c00b54a: bf65 j 1c00b502 <__rt_uart_open+0x3a> 1c00b54c: 4401 li s0,0 1c00b54e: bf55 j 1c00b502 <__rt_uart_open+0x3a> 1c00b550 <rt_uart_close>: 1c00b550: 1141 addi sp,sp,-16 1c00b552: c606 sw ra,12(sp) 1c00b554: c422 sw s0,8(sp) 1c00b556: c226 sw s1,4(sp) 1c00b558: 300474f3 csrrci s1,mstatus,8 1c00b55c: 411c lw a5,0(a0) 1c00b55e: 17fd addi a5,a5,-1 1c00b560: c11c sw a5,0(a0) 1c00b562: e78d bnez a5,1c00b58c <rt_uart_close+0x3c> 1c00b564: 842a mv s0,a0 1c00b566: 3d79 jal 1c00b404 <__rt_uart_wait_tx_done.isra.5> 1c00b568: 005007b7 lui a5,0x500 1c00b56c: 1a102737 lui a4,0x1a102 1c00b570: 0799 addi a5,a5,6 1c00b572: 1af72223 sw a5,420(a4) # 1a1021a4 <__l1_end+0xa0feb90> 1c00b576: 4050 lw a2,4(s0) 1c00b578: 78072683 lw a3,1920(a4) 1c00b57c: 4785 li a5,1 1c00b57e: 00c797b3 sll a5,a5,a2 1c00b582: fff7c793 not a5,a5 1c00b586: 8ff5 and a5,a5,a3 1c00b588: 78f72023 sw a5,1920(a4) 1c00b58c: 30049073 csrw mstatus,s1 1c00b590: 40b2 lw ra,12(sp) 1c00b592: 4422 lw s0,8(sp) 1c00b594: 4492 lw s1,4(sp) 1c00b596: 0141 addi sp,sp,16 1c00b598: 8082 ret 1c00b59a <rt_uart_cluster_write>: 1c00b59a: f14027f3 csrr a5,mhartid 1c00b59e: 8795 srai a5,a5,0x5 1c00b5a0: 03f7f793 andi a5,a5,63 1c00b5a4: 08f68ca3 sb a5,153(a3) 1c00b5a8: 1c00b7b7 lui a5,0x1c00b 1c00b5ac: 3c278793 addi a5,a5,962 # 1c00b3c2 <__rt_uart_cluster_req> 1c00b5b0: c6dc sw a5,12(a3) 1c00b5b2: 4785 li a5,1 1c00b5b4: c288 sw a0,0(a3) 1c00b5b6: c2cc sw a1,4(a3) 1c00b5b8: c690 sw a2,8(a3) 1c00b5ba: 08068c23 sb zero,152(a3) 1c00b5be: 0206a823 sw zero,48(a3) 1c00b5c2: ca94 sw a3,16(a3) 1c00b5c4: d6dc sw a5,44(a3) 1c00b5c6: 00c68513 addi a0,a3,12 1c00b5ca: ab7fd06f j 1c009080 <__rt_cluster_push_fc_event> 1c00b5ce <__rt_uart_init>: 1c00b5ce: 1c00b5b7 lui a1,0x1c00b 1c00b5d2: 1141 addi sp,sp,-16 1c00b5d4: 4601 li a2,0 1c00b5d6: 46a58593 addi a1,a1,1130 # 1c00b46a <__rt_uart_setfreq_before> 1c00b5da: 4511 li a0,4 1c00b5dc: c606 sw ra,12(sp) 1c00b5de: c422 sw s0,8(sp) 1c00b5e0: 8bcfe0ef jal ra,1c00969c <__rt_cbsys_add> 1c00b5e4: 1c00b5b7 lui a1,0x1c00b 1c00b5e8: 842a mv s0,a0 1c00b5ea: 4601 li a2,0 1c00b5ec: 3a258593 addi a1,a1,930 # 1c00b3a2 <__rt_uart_setfreq_after> 1c00b5f0: 4515 li a0,5 1c00b5f2: 8aafe0ef jal ra,1c00969c <__rt_cbsys_add> 1c00b5f6: 1c0017b7 lui a5,0x1c001 1c00b5fa: 1607ac23 sw zero,376(a5) # 1c001178 <__rt_uart> 1c00b5fe: 8d41 or a0,a0,s0 1c00b600: c105 beqz a0,1c00b620 <__rt_uart_init+0x52> 1c00b602: f1402673 csrr a2,mhartid 1c00b606: 1c000537 lui a0,0x1c000 1c00b60a: 40565593 srai a1,a2,0x5 1c00b60e: 03f5f593 andi a1,a1,63 1c00b612: 8a7d andi a2,a2,31 1c00b614: 67450513 addi a0,a0,1652 # 1c000674 <__DTOR_END__+0x388> 1c00b618: ba6ff0ef jal ra,1c00a9be <printf> 1c00b61c: b2eff0ef jal ra,1c00a94a <abort> 1c00b620: 40b2 lw ra,12(sp) 1c00b622: 4422 lw s0,8(sp) 1c00b624: 0141 addi sp,sp,16 1c00b626: 8082 ret Disassembly of section .text.cluster: 1c010000 <__cluster_text_start>: 1c010000: f1402573 csrr a0,mhartid 1c010004: 01f57593 andi a1,a0,31 1c010008: 8115 srli a0,a0,0x5 1c01000a: 000702b7 lui t0,0x70 1c01000e: 00204337 lui t1,0x204 1c010012: 00532023 sw t0,0(t1) # 204000 <__l1_heap_size+0x1f7614> 1c010016: 0e059863 bnez a1,1c010106 <__rt_slave_start> 1c01001a: e3ff0417 auipc s0,0xe3ff0 1c01001e: fea40413 addi s0,s0,-22 # 4 <__rt_bridge_flash_handle> 1c010022: 002049b7 lui s3,0x204 1c010026: 4a09 li s4,2 1c010028: 00000a97 auipc s5,0x0 1c01002c: 034a8a93 addi s5,s5,52 # 1c01005c <__rt_master_event> 1c010030: ffff1b97 auipc s7,0xffff1 1c010034: 198b8b93 addi s7,s7,408 # 1c0011c8 <__rt_fc_cluster_data> 1c010038: 02800393 li t2,40 1c01003c: 02a383b3 mul t2,t2,a0 1c010040: 9b9e add s7,s7,t2 1c010042: 0b91 addi s7,s7,4 1c010044: 1a10acb7 lui s9,0x1a10a 1c010048: 810c8c93 addi s9,s9,-2032 # 1a109810 <__l1_end+0xa1061fc> 1c01004c: 4c09 li s8,2 1c01004e: 00000d17 auipc s10,0x0 1c010052: 0f6d0d13 addi s10,s10,246 # 1c010144 <__rt_set_slave_stack> 1c010056: 001d6d13 ori s10,s10,1 1c01005a: a819 j 1c010070 <__rt_master_loop> 1c01005c <__rt_master_event>: 1c01005c: 000b0a63 beqz s6,1c010070 <__rt_master_loop> 1c010060 <__rt_push_event_to_fc_retry>: 1c010060: 000ba283 lw t0,0(s7) 1c010064: 08029a63 bnez t0,1c0100f8 <__rt_push_event_to_fc_wait> 1c010068: 016ba023 sw s6,0(s7) 1c01006c: 018ca023 sw s8,0(s9) 1c010070 <__rt_master_loop>: 1c010070: 00042e03 lw t3,0(s0) 1c010074: 060e0b63 beqz t3,1c0100ea <__rt_master_sleep> 1c010078 <__rt_master_loop_update_next>: 1c010078: 020e2e83 lw t4,32(t3) 1c01007c: 020e2223 sw zero,36(t3) 1c010080: 01d42023 sw t4,0(s0) 1c010084: 020e2f03 lw t5,32(t3) 1c010088: ffee98e3 bne t4,t5,1c010078 <__rt_master_loop_update_next> 1c01008c: 7d005073 csrwi 0x7d0,0 1c010090: 004e2503 lw a0,4(t3) 1c010094: 000e2283 lw t0,0(t3) 1c010098: 008e2103 lw sp,8(t3) 1c01009c: 00ce2303 lw t1,12(t3) 1c0100a0: 010e2383 lw t2,16(t3) 1c0100a4: 028e2f03 lw t5,40(t3) 1c0100a8: 018e2b03 lw s6,24(t3) 1c0100ac: 014e2f83 lw t6,20(t3) 1c0100b0: 80d6 mv ra,s5 1c0100b2: 911a add sp,sp,t1 1c0100b4: 01f02823 sw t6,16(zero) # 10 <__rt_bridge_flash_cs> 1c0100b8: 00030a63 beqz t1,1c0100cc <__rt_no_stack_check> 1c0100bc: 40610eb3 sub t4,sp,t1 1c0100c0: 7d1e9073 csrw 0x7d1,t4 1c0100c4: 7d211073 csrw 0x7d2,sp 1c0100c8: 7d00d073 csrwi 0x7d0,1 1c0100cc <__rt_no_stack_check>: 1c0100cc: 09e9a223 sw t5,132(s3) # 204084 <__l1_heap_size+0x1f7698> 1c0100d0: 21e9a023 sw t5,512(s3) 1c0100d4: 21e9a623 sw t5,524(s3) 1c0100d8 <__rt_master_no_slave_barrier>: 1c0100d8: 000f2863 p.beqimm t5,0,1c0100e8 <__rt_master_loop_no_slave> 1c0100dc: 09a9a023 sw s10,128(s3) 1c0100e0: 0879a023 sw t2,128(s3) 1c0100e4: 0829a023 sw sp,128(s3) 1c0100e8 <__rt_master_loop_no_slave>: 1c0100e8: 8282 jr t0 1c0100ea <__rt_master_sleep>: 1c0100ea: 0149a423 sw s4,8(s3) 1c0100ee: 03c9e003 p.elw zero,60(s3) 1c0100f2: 0149a223 sw s4,4(s3) 1c0100f6: bfad j 1c010070 <__rt_master_loop> 1c0100f8 <__rt_push_event_to_fc_wait>: 1c0100f8: 0149a423 sw s4,8(s3) 1c0100fc: 03c9e003 p.elw zero,60(s3) 1c010100: 0149a223 sw s4,4(s3) 1c010104: bfb1 j 1c010060 <__rt_push_event_to_fc_retry> 1c010106 <__rt_slave_start>: 1c010106: 00204937 lui s2,0x204 1c01010a: f14029f3 csrr s3,mhartid 1c01010e: 01f9f993 andi s3,s3,31 1c010112: 00000a17 auipc s4,0x0 1c010116: 012a0a13 addi s4,s4,18 # 1c010124 <__rt_fork_return> 1c01011a: 00000a97 auipc s5,0x0 1c01011e: 00ea8a93 addi s5,s5,14 # 1c010128 <__rt_wait_for_dispatch> 1c010122: a019 j 1c010128 <__rt_wait_for_dispatch> 1c010124 <__rt_fork_return>: 1c010124: 21c96283 p.elw t0,540(s2) # 20421c <__l1_heap_size+0x1f7830> 1c010128 <__rt_wait_for_dispatch>: 1c010128: 08096283 p.elw t0,128(s2) 1c01012c: 08096503 p.elw a0,128(s2) 1c010130: 0012f313 andi t1,t0,1 1c010134: 00031563 bnez t1,1c01013e <__rt_other_entry> 1c010138 <__rt_fork_entry>: 1c010138: 000a00b3 add ra,s4,zero 1c01013c: 8282 jr t0 1c01013e <__rt_other_entry>: 1c01013e: 000a80b3 add ra,s5,zero 1c010142: 8282 jr t0 1c010144 <__rt_set_slave_stack>: 1c010144: 7d005073 csrwi 0x7d0,0 1c010148: 08096283 p.elw t0,128(s2) 1c01014c: 02a98eb3 mul t4,s3,a0 1c010150: 005e8133 add sp,t4,t0 1c010154: c909 beqz a0,1c010166 <__rt_no_stack_check_end> 1c010156: 40a10eb3 sub t4,sp,a0 1c01015a: 7d1e9073 csrw 0x7d1,t4 1c01015e: 7d211073 csrw 0x7d2,sp 1c010162: 7d00d073 csrwi 0x7d0,1 1c010166 <__rt_no_stack_check_end>: 1c010166: 8082 ret
#include "license.hunspell" #include "license.myspell" #include <stdlib.h> #include <string.h> #include <stdio.h> #include "filemgr.hxx" #ifdef HUNSPELL_CHROME_CLIENT #include "google/bdict_reader.h" FileMgr::FileMgr(hunspell::LineIterator* iterator) : iterator_(iterator) { } FileMgr::~FileMgr() { } char * FileMgr::getline() { // Read one line from a BDICT file and store the line to our line buffer. // To emulate the original FileMgr::getline(), this function returns // the pointer to our line buffer if we can read a line without errors. // Otherwise, this function returns NULL. bool result = iterator_->AdvanceAndCopy(line_, BUFSIZE - 1); return result ? line_ : NULL; } int FileMgr::getlinenum() { // This function is used only for displaying a line number that causes a // parser error. For a BDICT file, providing a line number doesn't help // identifying the place where causes a parser error so much since it is a // binary file. So, we just return 0. return 0; } #else int FileMgr::fail(const char * err, const char * par) { fprintf(stderr, err, par); return -1; } FileMgr::FileMgr(const char * file, const char * key) { linenum = 0; hin = NULL; fin = fopen(file, "r"); if (!fin) { // check hzipped file char * st = (char *) malloc(strlen(file) + strlen(HZIP_EXTENSION) + 1); if (st) { strcpy(st, file); strcat(st, HZIP_EXTENSION); hin = new Hunzip(st, key); free(st); } } if (!fin && !hin) fail(MSG_OPEN, file); } FileMgr::~FileMgr() { if (fin) fclose(fin); if (hin) delete hin; } char * FileMgr::getline() { const char * l; linenum++; if (fin) return fgets(in, BUFSIZE - 1, fin); if (hin && ((l = hin->getline()) != NULL)) return strcpy(in, l); linenum--; return NULL; } int FileMgr::getlinenum() { return linenum; } #endif
// Copyright 2015 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "components/proximity_auth/device_to_device_secure_context.h" #include <memory> #include "base/bind.h" #include "base/memory/ptr_util.h" #include "components/proximity_auth/cryptauth/fake_secure_message_delegate.h" #include "components/proximity_auth/cryptauth/proto/cryptauth_api.pb.h" #include "components/proximity_auth/cryptauth/proto/securemessage.pb.h" #include "testing/gtest/include/gtest/gtest.h" namespace proximity_auth { namespace { const char kSymmetricKey[] = "symmetric key"; const char kResponderAuthMessage[] = "responder_auth_message"; const SecureContext::ProtocolVersion kProtocolVersion = SecureContext::PROTOCOL_VERSION_THREE_ONE; // Callback saving |result| to |result_out|. void SaveResult(std::string* result_out, const std::string& result) { *result_out = result; } } // namespace class ProximityAuthDeviceToDeviceSecureContextTest : public testing::Test { protected: ProximityAuthDeviceToDeviceSecureContextTest() : secure_context_(base::MakeUnique<FakeSecureMessageDelegate>(), kSymmetricKey, kResponderAuthMessage, kProtocolVersion) {} DeviceToDeviceSecureContext secure_context_; }; TEST_F(ProximityAuthDeviceToDeviceSecureContextTest, GetProperties) { EXPECT_EQ(kResponderAuthMessage, secure_context_.GetChannelBindingData()); EXPECT_EQ(kProtocolVersion, secure_context_.GetProtocolVersion()); } TEST_F(ProximityAuthDeviceToDeviceSecureContextTest, CheckEncodedHeader) { std::string message = "encrypt this message"; std::string encoded_message; secure_context_.Encode(message, base::Bind(&SaveResult, &encoded_message)); securemessage::SecureMessage secure_message; ASSERT_TRUE(secure_message.ParseFromString(encoded_message)); securemessage::HeaderAndBody header_and_body; ASSERT_TRUE( header_and_body.ParseFromString(secure_message.header_and_body())); cryptauth::GcmMetadata gcm_metadata; ASSERT_TRUE( gcm_metadata.ParseFromString(header_and_body.header().public_metadata())); EXPECT_EQ(1, gcm_metadata.version()); EXPECT_EQ(cryptauth::DEVICE_TO_DEVICE_MESSAGE, gcm_metadata.type()); } TEST_F(ProximityAuthDeviceToDeviceSecureContextTest, DecodeInvalidMessage) { std::string encoded_message = "invalidly encoded message"; std::string decoded_message = "not empty"; secure_context_.Decode(encoded_message, base::Bind(&SaveResult, &decoded_message)); EXPECT_TRUE(decoded_message.empty()); } TEST_F(ProximityAuthDeviceToDeviceSecureContextTest, EncodeAndDecode) { // Initialize second secure channel with the same parameters as the first. DeviceToDeviceSecureContext secure_context2( base::MakeUnique<FakeSecureMessageDelegate>(), kSymmetricKey, kResponderAuthMessage, kProtocolVersion); std::string message = "encrypt this message"; // Pass some messages between the two secure contexts. for (int i = 0; i < 3; ++i) { std::string encoded_message; secure_context_.Encode(message, base::Bind(&SaveResult, &encoded_message)); EXPECT_NE(message, encoded_message); std::string decoded_message; secure_context2.Decode(encoded_message, base::Bind(&SaveResult, &decoded_message)); EXPECT_EQ(message, decoded_message); } } TEST_F(ProximityAuthDeviceToDeviceSecureContextTest, DecodeInvalidSequenceNumber) { // Initialize second secure channel with the same parameters as the first. DeviceToDeviceSecureContext secure_context2( base::MakeUnique<FakeSecureMessageDelegate>(), kSymmetricKey, kResponderAuthMessage, kProtocolVersion); // Send a few messages over the first secure context. std::string message = "encrypt this message"; std::string encoded1; for (int i = 0; i < 3; ++i) { secure_context_.Encode(message, base::Bind(&SaveResult, &encoded1)); } // Second secure channel should not decode the message with an invalid // sequence number. std::string decoded_message = "not empty"; secure_context_.Decode(encoded1, base::Bind(&SaveResult, &decoded_message)); EXPECT_TRUE(decoded_message.empty()); } } // proximity_auth
/* ----------------------------------------------------------------------------- This source file is part of OGRE (Object-oriented Graphics Rendering Engine) For the latest info, see http://www.ogre3d.org/ Copyright (c) 2000-2009 Torus Knot Software Ltd 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. ----------------------------------------------------------------------------- OgreTerrainZonePageSource.cpp - based on OgreTerrainPageSource.cpp from Ogre3d ----------------------------------------------------------------------------- begin : Thu May 3 2007 author : Eric Cha email : ericcATxenopiDOTcom ----------------------------------------------------------------------------- */ #include "OgreTerrainZonePageSource.h" #include "OgreTerrainZonePage.h" #include "OgreTerrainZoneRenderable.h" #include "OgreSceneNode.h" #include "OgreTerrainZone.h" #include "OgrePCZSceneManager.h" namespace Ogre { //----------------------------------------------------------------------- template<> TerrainZonePageSourceListenerManager* Singleton<TerrainZonePageSourceListenerManager>::ms_Singleton = 0; TerrainZonePageSourceListenerManager* TerrainZonePageSourceListenerManager::getSingletonPtr(void) { return ms_Singleton; } TerrainZonePageSourceListenerManager& TerrainZonePageSourceListenerManager::getSingleton(void) { assert( ms_Singleton ); return ( *ms_Singleton ); } //------------------------------------------------------------------------- void TerrainZonePageSourceListenerManager::addListener(TerrainZonePageSourceListener* pl) { mPageSourceListeners.push_back(pl); } //------------------------------------------------------------------------- void TerrainZonePageSourceListenerManager::removeListener(TerrainZonePageSourceListener* pl) { PageSourceListenerList::iterator i, iend; iend = mPageSourceListeners.end(); for(i = mPageSourceListeners.begin(); i != iend; ++i) { if (*i == pl) { mPageSourceListeners.erase(i); break; } } } //------------------------------------------------------------------------- void TerrainZonePageSourceListenerManager::firePageConstructed( TerrainZone* sm, size_t pagex, size_t pagez, Real* heightData) { PageSourceListenerList::iterator i, iend; iend = mPageSourceListeners.end(); for(i = mPageSourceListeners.begin(); i != iend; ++i) { (*i)->pageConstructed(sm, pagex, pagez, heightData); } } //------------------------------------------------------------------------- TerrainZonePageSource::TerrainZonePageSource() : mTerrainZone(0), mAsyncLoading(false) { } //------------------------------------------------------------------------- TerrainZonePage* TerrainZonePageSource::buildPage(Real* heightData, const MaterialPtr& pMaterial) { String name; // Create a TerrainZone Page TerrainZonePage* page = OGRE_NEW TerrainZonePage((mPageSize-1) / (mTileSize-1)); // Create a node for all tiles to be attached to // Note we sequentially name since page can be attached at different points // so page x/z is not appropriate StringUtil::StrStreamType page_str; size_t pageIndex = mTerrainZone->_getPageCount(); page_str << pageIndex; name = mTerrainZone->getName() + "_page["; name += page_str.str() + "]_Node"; if (mTerrainZone->mPCZSM->hasSceneNode(name)) { page->pageSceneNode = mTerrainZone->mPCZSM->getSceneNode(name); // set the home zone of the scene node to the terrainzone ((PCZSceneNode*)(page->pageSceneNode))->anchorToHomeZone(mTerrainZone); // EXPERIMENTAL - prevent terrain zone pages from visiting other zones ((PCZSceneNode*)(page->pageSceneNode))->allowToVisit(false); } else { page->pageSceneNode = mTerrainZone->getTerrainRootNode()->createChildSceneNode(name); // set the home zone of the scene node to the terrainzone ((PCZSceneNode*)(page->pageSceneNode))->anchorToHomeZone(mTerrainZone); // EXPERIMENTAL - prevent terrain zone pages from visiting other zones ((PCZSceneNode*)(page->pageSceneNode))->allowToVisit(false); } size_t q = 0; for ( unsigned short j = 0; j < mPageSize - 1; j += ( mTileSize - 1 ) ) { size_t p = 0; for ( unsigned short i = 0; i < mPageSize - 1; i += ( mTileSize - 1 ) ) { StringUtil::StrStreamType new_name_str; // Create scene node for the tile and the TerrainZoneRenderable new_name_str << mTerrainZone->getName() << "_tile[" << pageIndex << "][" << (int)p << "," << (int)q << "]_Node"; name = new_name_str.str(); SceneNode *c; if (mTerrainZone->mPCZSM->hasSceneNode(name)) { c = mTerrainZone->mPCZSM->getSceneNode( name ); if (c->getParentSceneNode() != page->pageSceneNode) page->pageSceneNode->addChild(c); // set the home zone of the scene node to the terrainzone ((PCZSceneNode*)c)->anchorToHomeZone(mTerrainZone); // EXPERIMENTAL - prevent terrain zone pages from visiting other zones ((PCZSceneNode*)c)->allowToVisit(false); } else { c = page->pageSceneNode->createChildSceneNode( name ); // set the home zone of the scene node to the terrainzone ((PCZSceneNode*)c)->anchorToHomeZone(mTerrainZone); // EXPERIMENTAL - prevent terrain zone pages from visiting other zones ((PCZSceneNode*)c)->allowToVisit(false); } TerrainZoneRenderable *tile = OGRE_NEW TerrainZoneRenderable(name, mTerrainZone); // set queue tile->setRenderQueueGroup(mTerrainZone->mPCZSM->getWorldGeometryRenderQueue()); // Initialise the tile tile->setMaterial(pMaterial); tile->initialise(i, j, heightData); // Attach it to the page page->tiles[ p ][ q ] = tile; // Attach it to the node c ->attachObject( tile ); p++; } q++; } pageIndex++; // calculate neighbours for page page->linkNeighbours(); if(mTerrainZone->getOptions().lit) { q = 0; for ( unsigned short j = 0; j < mPageSize - 1; j += ( mTileSize - 1 ) ) { size_t p = 0; for ( unsigned short i = 0; i < mPageSize - 1; i += ( mTileSize - 1 ) ) { page->tiles[ p ][ q ]->_calculateNormals(); p++; } q++; } } return page; } //------------------------------------------------------------------------- void TerrainZonePageSource::firePageConstructed(size_t pagex, size_t pagez, Real* heightData) { TerrainZonePageSourceListenerManager::getSingleton().firePageConstructed( mTerrainZone, pagex, pagez, heightData); } //------------------------------------------------------------------------- void TerrainZonePageSource::addListener(TerrainZonePageSourceListener* pl) { TerrainZonePageSourceListenerManager::getSingleton().addListener(pl); } //------------------------------------------------------------------------- void TerrainZonePageSource::removeListener(TerrainZonePageSourceListener* pl) { TerrainZonePageSourceListenerManager::getSingleton().removeListener(pl); } //------------------------------------------------------------------------- }
// Copyright 2012 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "src/v8.h" #if V8_TARGET_ARCH_X87 #include "src/code-factory.h" #include "src/code-stubs.h" #include "src/codegen.h" #include "src/compiler.h" #include "src/debug.h" #include "src/full-codegen.h" #include "src/ic/ic.h" #include "src/parser.h" #include "src/scopes.h" namespace v8 { namespace internal { #define __ ACCESS_MASM(masm_) class JumpPatchSite BASE_EMBEDDED { public: explicit JumpPatchSite(MacroAssembler* masm) : masm_(masm) { #ifdef DEBUG info_emitted_ = false; #endif } ~JumpPatchSite() { DCHECK(patch_site_.is_bound() == info_emitted_); } void EmitJumpIfNotSmi(Register reg, Label* target, Label::Distance distance = Label::kFar) { __ test(reg, Immediate(kSmiTagMask)); EmitJump(not_carry, target, distance); // Always taken before patched. } void EmitJumpIfSmi(Register reg, Label* target, Label::Distance distance = Label::kFar) { __ test(reg, Immediate(kSmiTagMask)); EmitJump(carry, target, distance); // Never taken before patched. } void EmitPatchInfo() { if (patch_site_.is_bound()) { int delta_to_patch_site = masm_->SizeOfCodeGeneratedSince(&patch_site_); DCHECK(is_uint8(delta_to_patch_site)); __ test(eax, Immediate(delta_to_patch_site)); #ifdef DEBUG info_emitted_ = true; #endif } else { __ nop(); // Signals no inlined code. } } private: // jc will be patched with jz, jnc will become jnz. void EmitJump(Condition cc, Label* target, Label::Distance distance) { DCHECK(!patch_site_.is_bound() && !info_emitted_); DCHECK(cc == carry || cc == not_carry); __ bind(&patch_site_); __ j(cc, target, distance); } MacroAssembler* masm_; Label patch_site_; #ifdef DEBUG bool info_emitted_; #endif }; // Generate code for a JS function. On entry to the function the receiver // and arguments have been pushed on the stack left to right, with the // return address on top of them. The actual argument count matches the // formal parameter count expected by the function. // // The live registers are: // o edi: the JS function object being called (i.e. ourselves) // o esi: our context // o ebp: our caller's frame pointer // o esp: stack pointer (pointing to return address) // // The function builds a JS frame. Please see JavaScriptFrameConstants in // frames-x87.h for its layout. void FullCodeGenerator::Generate() { CompilationInfo* info = info_; handler_table_ = Handle<HandlerTable>::cast(isolate()->factory()->NewFixedArray( HandlerTable::LengthForRange(function()->handler_count()), TENURED)); profiling_counter_ = isolate()->factory()->NewCell( Handle<Smi>(Smi::FromInt(FLAG_interrupt_budget), isolate())); SetFunctionPosition(function()); Comment cmnt(masm_, "[ function compiled by full code generator"); ProfileEntryHookStub::MaybeCallEntryHook(masm_); #ifdef DEBUG if (strlen(FLAG_stop_at) > 0 && info->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) { __ int3(); } #endif // Sloppy mode functions and builtins need to replace the receiver with the // global proxy when called as functions (without an explicit receiver // object). if (is_sloppy(info->language_mode()) && !info->is_native() && info->MayUseThis()) { Label ok; // +1 for return address. int receiver_offset = (info->scope()->num_parameters() + 1) * kPointerSize; __ mov(ecx, Operand(esp, receiver_offset)); __ cmp(ecx, isolate()->factory()->undefined_value()); __ j(not_equal, &ok, Label::kNear); __ mov(ecx, GlobalObjectOperand()); __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalProxyOffset)); __ mov(Operand(esp, receiver_offset), ecx); __ bind(&ok); } // Open a frame scope to indicate that there is a frame on the stack. The // MANUAL indicates that the scope shouldn't actually generate code to set up // the frame (that is done below). FrameScope frame_scope(masm_, StackFrame::MANUAL); info->set_prologue_offset(masm_->pc_offset()); __ Prologue(info->IsCodePreAgingActive()); info->AddNoFrameRange(0, masm_->pc_offset()); { Comment cmnt(masm_, "[ Allocate locals"); int locals_count = info->scope()->num_stack_slots(); // Generators allocate locals, if any, in context slots. DCHECK(!IsGeneratorFunction(info->function()->kind()) || locals_count == 0); if (locals_count == 1) { __ push(Immediate(isolate()->factory()->undefined_value())); } else if (locals_count > 1) { if (locals_count >= 128) { Label ok; __ mov(ecx, esp); __ sub(ecx, Immediate(locals_count * kPointerSize)); ExternalReference stack_limit = ExternalReference::address_of_real_stack_limit(isolate()); __ cmp(ecx, Operand::StaticVariable(stack_limit)); __ j(above_equal, &ok, Label::kNear); __ InvokeBuiltin(Builtins::STACK_OVERFLOW, CALL_FUNCTION); __ bind(&ok); } __ mov(eax, Immediate(isolate()->factory()->undefined_value())); const int kMaxPushes = 32; if (locals_count >= kMaxPushes) { int loop_iterations = locals_count / kMaxPushes; __ mov(ecx, loop_iterations); Label loop_header; __ bind(&loop_header); // Do pushes. for (int i = 0; i < kMaxPushes; i++) { __ push(eax); } __ dec(ecx); __ j(not_zero, &loop_header, Label::kNear); } int remaining = locals_count % kMaxPushes; // Emit the remaining pushes. for (int i = 0; i < remaining; i++) { __ push(eax); } } } bool function_in_register = true; // Possibly allocate a local context. int heap_slots = info->scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; if (heap_slots > 0) { Comment cmnt(masm_, "[ Allocate context"); bool need_write_barrier = true; // Argument to NewContext is the function, which is still in edi. if (info->scope()->is_script_scope()) { __ push(edi); __ Push(info->scope()->GetScopeInfo(info->isolate())); __ CallRuntime(Runtime::kNewScriptContext, 2); } else if (heap_slots <= FastNewContextStub::kMaximumSlots) { FastNewContextStub stub(isolate(), heap_slots); __ CallStub(&stub); // Result of FastNewContextStub is always in new space. need_write_barrier = false; } else { __ push(edi); __ CallRuntime(Runtime::kNewFunctionContext, 1); } function_in_register = false; // Context is returned in eax. It replaces the context passed to us. // It's saved in the stack and kept live in esi. __ mov(esi, eax); __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), eax); // Copy parameters into context if necessary. int num_parameters = info->scope()->num_parameters(); int first_parameter = info->scope()->has_this_declaration() ? -1 : 0; for (int i = first_parameter; i < num_parameters; i++) { Variable* var = (i == -1) ? scope()->receiver() : scope()->parameter(i); if (var->IsContextSlot()) { int parameter_offset = StandardFrameConstants::kCallerSPOffset + (num_parameters - 1 - i) * kPointerSize; // Load parameter from stack. __ mov(eax, Operand(ebp, parameter_offset)); // Store it in the context. int context_offset = Context::SlotOffset(var->index()); __ mov(Operand(esi, context_offset), eax); // Update the write barrier. This clobbers eax and ebx. if (need_write_barrier) { __ RecordWriteContextSlot(esi, context_offset, eax, ebx, kDontSaveFPRegs); } else if (FLAG_debug_code) { Label done; __ JumpIfInNewSpace(esi, eax, &done, Label::kNear); __ Abort(kExpectedNewSpaceObject); __ bind(&done); } } } } ArgumentsAccessStub::HasNewTarget has_new_target = IsSubclassConstructor(info->function()->kind()) ? ArgumentsAccessStub::HAS_NEW_TARGET : ArgumentsAccessStub::NO_NEW_TARGET; // Possibly allocate RestParameters int rest_index; Variable* rest_param = scope()->rest_parameter(&rest_index); if (rest_param) { Comment cmnt(masm_, "[ Allocate rest parameter array"); int num_parameters = info->scope()->num_parameters(); int offset = num_parameters * kPointerSize; if (has_new_target == ArgumentsAccessStub::HAS_NEW_TARGET) { --num_parameters; ++rest_index; } __ lea(edx, Operand(ebp, StandardFrameConstants::kCallerSPOffset + offset)); __ push(edx); __ push(Immediate(Smi::FromInt(num_parameters))); __ push(Immediate(Smi::FromInt(rest_index))); RestParamAccessStub stub(isolate()); __ CallStub(&stub); SetVar(rest_param, eax, ebx, edx); } Variable* arguments = scope()->arguments(); if (arguments != NULL) { // Function uses arguments object. Comment cmnt(masm_, "[ Allocate arguments object"); if (function_in_register) { __ push(edi); } else { __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); } // Receiver is just before the parameters on the caller's stack. int num_parameters = info->scope()->num_parameters(); int offset = num_parameters * kPointerSize; __ lea(edx, Operand(ebp, StandardFrameConstants::kCallerSPOffset + offset)); __ push(edx); __ push(Immediate(Smi::FromInt(num_parameters))); // Arguments to ArgumentsAccessStub: // function, receiver address, parameter count. // The stub will rewrite receiver and parameter count if the previous // stack frame was an arguments adapter frame. ArgumentsAccessStub::Type type; if (is_strict(language_mode()) || !is_simple_parameter_list()) { type = ArgumentsAccessStub::NEW_STRICT; } else if (function()->has_duplicate_parameters()) { type = ArgumentsAccessStub::NEW_SLOPPY_SLOW; } else { type = ArgumentsAccessStub::NEW_SLOPPY_FAST; } ArgumentsAccessStub stub(isolate(), type, has_new_target); __ CallStub(&stub); SetVar(arguments, eax, ebx, edx); } if (FLAG_trace) { __ CallRuntime(Runtime::kTraceEnter, 0); } // Visit the declarations and body unless there is an illegal // redeclaration. if (scope()->HasIllegalRedeclaration()) { Comment cmnt(masm_, "[ Declarations"); scope()->VisitIllegalRedeclaration(this); } else { PrepareForBailoutForId(BailoutId::FunctionEntry(), NO_REGISTERS); { Comment cmnt(masm_, "[ Declarations"); // For named function expressions, declare the function name as a // constant. if (scope()->is_function_scope() && scope()->function() != NULL) { VariableDeclaration* function = scope()->function(); DCHECK(function->proxy()->var()->mode() == CONST || function->proxy()->var()->mode() == CONST_LEGACY); DCHECK(function->proxy()->var()->location() != Variable::UNALLOCATED); VisitVariableDeclaration(function); } VisitDeclarations(scope()->declarations()); } { Comment cmnt(masm_, "[ Stack check"); PrepareForBailoutForId(BailoutId::Declarations(), NO_REGISTERS); Label ok; ExternalReference stack_limit = ExternalReference::address_of_stack_limit(isolate()); __ cmp(esp, Operand::StaticVariable(stack_limit)); __ j(above_equal, &ok, Label::kNear); __ call(isolate()->builtins()->StackCheck(), RelocInfo::CODE_TARGET); __ bind(&ok); } { Comment cmnt(masm_, "[ Body"); DCHECK(loop_depth() == 0); VisitStatements(function()->body()); DCHECK(loop_depth() == 0); } } // Always emit a 'return undefined' in case control fell off the end of // the body. { Comment cmnt(masm_, "[ return <undefined>;"); __ mov(eax, isolate()->factory()->undefined_value()); EmitReturnSequence(); } } void FullCodeGenerator::ClearAccumulator() { __ Move(eax, Immediate(Smi::FromInt(0))); } void FullCodeGenerator::EmitProfilingCounterDecrement(int delta) { __ mov(ebx, Immediate(profiling_counter_)); __ sub(FieldOperand(ebx, Cell::kValueOffset), Immediate(Smi::FromInt(delta))); } void FullCodeGenerator::EmitProfilingCounterReset() { int reset_value = FLAG_interrupt_budget; __ mov(ebx, Immediate(profiling_counter_)); __ mov(FieldOperand(ebx, Cell::kValueOffset), Immediate(Smi::FromInt(reset_value))); } void FullCodeGenerator::EmitBackEdgeBookkeeping(IterationStatement* stmt, Label* back_edge_target) { Comment cmnt(masm_, "[ Back edge bookkeeping"); Label ok; DCHECK(back_edge_target->is_bound()); int distance = masm_->SizeOfCodeGeneratedSince(back_edge_target); int weight = Min(kMaxBackEdgeWeight, Max(1, distance / kCodeSizeMultiplier)); EmitProfilingCounterDecrement(weight); __ j(positive, &ok, Label::kNear); __ call(isolate()->builtins()->InterruptCheck(), RelocInfo::CODE_TARGET); // Record a mapping of this PC offset to the OSR id. This is used to find // the AST id from the unoptimized code in order to use it as a key into // the deoptimization input data found in the optimized code. RecordBackEdge(stmt->OsrEntryId()); EmitProfilingCounterReset(); __ bind(&ok); PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); // Record a mapping of the OSR id to this PC. This is used if the OSR // entry becomes the target of a bailout. We don't expect it to be, but // we want it to work if it is. PrepareForBailoutForId(stmt->OsrEntryId(), NO_REGISTERS); } void FullCodeGenerator::EmitReturnSequence() { Comment cmnt(masm_, "[ Return sequence"); if (return_label_.is_bound()) { __ jmp(&return_label_); } else { // Common return label __ bind(&return_label_); if (FLAG_trace) { __ push(eax); __ CallRuntime(Runtime::kTraceExit, 1); } // Pretend that the exit is a backwards jump to the entry. int weight = 1; if (info_->ShouldSelfOptimize()) { weight = FLAG_interrupt_budget / FLAG_self_opt_count; } else { int distance = masm_->pc_offset(); weight = Min(kMaxBackEdgeWeight, Max(1, distance / kCodeSizeMultiplier)); } EmitProfilingCounterDecrement(weight); Label ok; __ j(positive, &ok, Label::kNear); __ push(eax); __ call(isolate()->builtins()->InterruptCheck(), RelocInfo::CODE_TARGET); __ pop(eax); EmitProfilingCounterReset(); __ bind(&ok); #ifdef DEBUG // Add a label for checking the size of the code used for returning. Label check_exit_codesize; masm_->bind(&check_exit_codesize); #endif SetSourcePosition(function()->end_position() - 1); __ RecordJSReturn(); // Do not use the leave instruction here because it is too short to // patch with the code required by the debugger. __ mov(esp, ebp); int no_frame_start = masm_->pc_offset(); __ pop(ebp); int arg_count = info_->scope()->num_parameters() + 1; if (IsSubclassConstructor(info_->function()->kind())) { arg_count++; } int arguments_bytes = arg_count * kPointerSize; __ Ret(arguments_bytes, ecx); // Check that the size of the code used for returning is large enough // for the debugger's requirements. DCHECK(Assembler::kJSReturnSequenceLength <= masm_->SizeOfCodeGeneratedSince(&check_exit_codesize)); info_->AddNoFrameRange(no_frame_start, masm_->pc_offset()); } } void FullCodeGenerator::EffectContext::Plug(Variable* var) const { DCHECK(var->IsStackAllocated() || var->IsContextSlot()); } void FullCodeGenerator::AccumulatorValueContext::Plug(Variable* var) const { DCHECK(var->IsStackAllocated() || var->IsContextSlot()); codegen()->GetVar(result_register(), var); } void FullCodeGenerator::StackValueContext::Plug(Variable* var) const { DCHECK(var->IsStackAllocated() || var->IsContextSlot()); MemOperand operand = codegen()->VarOperand(var, result_register()); // Memory operands can be pushed directly. __ push(operand); } void FullCodeGenerator::TestContext::Plug(Variable* var) const { // For simplicity we always test the accumulator register. codegen()->GetVar(result_register(), var); codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL); codegen()->DoTest(this); } void FullCodeGenerator::EffectContext::Plug(Heap::RootListIndex index) const { UNREACHABLE(); // Not used on X87. } void FullCodeGenerator::AccumulatorValueContext::Plug( Heap::RootListIndex index) const { UNREACHABLE(); // Not used on X87. } void FullCodeGenerator::StackValueContext::Plug( Heap::RootListIndex index) const { UNREACHABLE(); // Not used on X87. } void FullCodeGenerator::TestContext::Plug(Heap::RootListIndex index) const { UNREACHABLE(); // Not used on X87. } void FullCodeGenerator::EffectContext::Plug(Handle<Object> lit) const { } void FullCodeGenerator::AccumulatorValueContext::Plug( Handle<Object> lit) const { if (lit->IsSmi()) { __ SafeMove(result_register(), Immediate(lit)); } else { __ Move(result_register(), Immediate(lit)); } } void FullCodeGenerator::StackValueContext::Plug(Handle<Object> lit) const { if (lit->IsSmi()) { __ SafePush(Immediate(lit)); } else { __ push(Immediate(lit)); } } void FullCodeGenerator::TestContext::Plug(Handle<Object> lit) const { codegen()->PrepareForBailoutBeforeSplit(condition(), true, true_label_, false_label_); DCHECK(!lit->IsUndetectableObject()); // There are no undetectable literals. if (lit->IsUndefined() || lit->IsNull() || lit->IsFalse()) { if (false_label_ != fall_through_) __ jmp(false_label_); } else if (lit->IsTrue() || lit->IsJSObject()) { if (true_label_ != fall_through_) __ jmp(true_label_); } else if (lit->IsString()) { if (String::cast(*lit)->length() == 0) { if (false_label_ != fall_through_) __ jmp(false_label_); } else { if (true_label_ != fall_through_) __ jmp(true_label_); } } else if (lit->IsSmi()) { if (Smi::cast(*lit)->value() == 0) { if (false_label_ != fall_through_) __ jmp(false_label_); } else { if (true_label_ != fall_through_) __ jmp(true_label_); } } else { // For simplicity we always test the accumulator register. __ mov(result_register(), lit); codegen()->DoTest(this); } } void FullCodeGenerator::EffectContext::DropAndPlug(int count, Register reg) const { DCHECK(count > 0); __ Drop(count); } void FullCodeGenerator::AccumulatorValueContext::DropAndPlug( int count, Register reg) const { DCHECK(count > 0); __ Drop(count); __ Move(result_register(), reg); } void FullCodeGenerator::StackValueContext::DropAndPlug(int count, Register reg) const { DCHECK(count > 0); if (count > 1) __ Drop(count - 1); __ mov(Operand(esp, 0), reg); } void FullCodeGenerator::TestContext::DropAndPlug(int count, Register reg) const { DCHECK(count > 0); // For simplicity we always test the accumulator register. __ Drop(count); __ Move(result_register(), reg); codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL); codegen()->DoTest(this); } void FullCodeGenerator::EffectContext::Plug(Label* materialize_true, Label* materialize_false) const { DCHECK(materialize_true == materialize_false); __ bind(materialize_true); } void FullCodeGenerator::AccumulatorValueContext::Plug( Label* materialize_true, Label* materialize_false) const { Label done; __ bind(materialize_true); __ mov(result_register(), isolate()->factory()->true_value()); __ jmp(&done, Label::kNear); __ bind(materialize_false); __ mov(result_register(), isolate()->factory()->false_value()); __ bind(&done); } void FullCodeGenerator::StackValueContext::Plug( Label* materialize_true, Label* materialize_false) const { Label done; __ bind(materialize_true); __ push(Immediate(isolate()->factory()->true_value())); __ jmp(&done, Label::kNear); __ bind(materialize_false); __ push(Immediate(isolate()->factory()->false_value())); __ bind(&done); } void FullCodeGenerator::TestContext::Plug(Label* materialize_true, Label* materialize_false) const { DCHECK(materialize_true == true_label_); DCHECK(materialize_false == false_label_); } void FullCodeGenerator::EffectContext::Plug(bool flag) const { } void FullCodeGenerator::AccumulatorValueContext::Plug(bool flag) const { Handle<Object> value = flag ? isolate()->factory()->true_value() : isolate()->factory()->false_value(); __ mov(result_register(), value); } void FullCodeGenerator::StackValueContext::Plug(bool flag) const { Handle<Object> value = flag ? isolate()->factory()->true_value() : isolate()->factory()->false_value(); __ push(Immediate(value)); } void FullCodeGenerator::TestContext::Plug(bool flag) const { codegen()->PrepareForBailoutBeforeSplit(condition(), true, true_label_, false_label_); if (flag) { if (true_label_ != fall_through_) __ jmp(true_label_); } else { if (false_label_ != fall_through_) __ jmp(false_label_); } } void FullCodeGenerator::DoTest(Expression* condition, Label* if_true, Label* if_false, Label* fall_through) { Handle<Code> ic = ToBooleanStub::GetUninitialized(isolate()); CallIC(ic, condition->test_id()); __ test(result_register(), result_register()); // The stub returns nonzero for true. Split(not_zero, if_true, if_false, fall_through); } void FullCodeGenerator::Split(Condition cc, Label* if_true, Label* if_false, Label* fall_through) { if (if_false == fall_through) { __ j(cc, if_true); } else if (if_true == fall_through) { __ j(NegateCondition(cc), if_false); } else { __ j(cc, if_true); __ jmp(if_false); } } MemOperand FullCodeGenerator::StackOperand(Variable* var) { DCHECK(var->IsStackAllocated()); // Offset is negative because higher indexes are at lower addresses. int offset = -var->index() * kPointerSize; // Adjust by a (parameter or local) base offset. if (var->IsParameter()) { offset += (info_->scope()->num_parameters() + 1) * kPointerSize; } else { offset += JavaScriptFrameConstants::kLocal0Offset; } return Operand(ebp, offset); } MemOperand FullCodeGenerator::VarOperand(Variable* var, Register scratch) { DCHECK(var->IsContextSlot() || var->IsStackAllocated()); if (var->IsContextSlot()) { int context_chain_length = scope()->ContextChainLength(var->scope()); __ LoadContext(scratch, context_chain_length); return ContextOperand(scratch, var->index()); } else { return StackOperand(var); } } void FullCodeGenerator::GetVar(Register dest, Variable* var) { DCHECK(var->IsContextSlot() || var->IsStackAllocated()); MemOperand location = VarOperand(var, dest); __ mov(dest, location); } void FullCodeGenerator::SetVar(Variable* var, Register src, Register scratch0, Register scratch1) { DCHECK(var->IsContextSlot() || var->IsStackAllocated()); DCHECK(!scratch0.is(src)); DCHECK(!scratch0.is(scratch1)); DCHECK(!scratch1.is(src)); MemOperand location = VarOperand(var, scratch0); __ mov(location, src); // Emit the write barrier code if the location is in the heap. if (var->IsContextSlot()) { int offset = Context::SlotOffset(var->index()); DCHECK(!scratch0.is(esi) && !src.is(esi) && !scratch1.is(esi)); __ RecordWriteContextSlot(scratch0, offset, src, scratch1, kDontSaveFPRegs); } } void FullCodeGenerator::PrepareForBailoutBeforeSplit(Expression* expr, bool should_normalize, Label* if_true, Label* if_false) { // Only prepare for bailouts before splits if we're in a test // context. Otherwise, we let the Visit function deal with the // preparation to avoid preparing with the same AST id twice. if (!context()->IsTest() || !info_->IsOptimizable()) return; Label skip; if (should_normalize) __ jmp(&skip, Label::kNear); PrepareForBailout(expr, TOS_REG); if (should_normalize) { __ cmp(eax, isolate()->factory()->true_value()); Split(equal, if_true, if_false, NULL); __ bind(&skip); } } void FullCodeGenerator::EmitDebugCheckDeclarationContext(Variable* variable) { // The variable in the declaration always resides in the current context. DCHECK_EQ(0, scope()->ContextChainLength(variable->scope())); if (generate_debug_code_) { // Check that we're not inside a with or catch context. __ mov(ebx, FieldOperand(esi, HeapObject::kMapOffset)); __ cmp(ebx, isolate()->factory()->with_context_map()); __ Check(not_equal, kDeclarationInWithContext); __ cmp(ebx, isolate()->factory()->catch_context_map()); __ Check(not_equal, kDeclarationInCatchContext); } } void FullCodeGenerator::VisitVariableDeclaration( VariableDeclaration* declaration) { // If it was not possible to allocate the variable at compile time, we // need to "declare" it at runtime to make sure it actually exists in the // local context. VariableProxy* proxy = declaration->proxy(); VariableMode mode = declaration->mode(); Variable* variable = proxy->var(); bool hole_init = mode == LET || mode == CONST || mode == CONST_LEGACY; switch (variable->location()) { case Variable::UNALLOCATED: globals_->Add(variable->name(), zone()); globals_->Add(variable->binding_needs_init() ? isolate()->factory()->the_hole_value() : isolate()->factory()->undefined_value(), zone()); break; case Variable::PARAMETER: case Variable::LOCAL: if (hole_init) { Comment cmnt(masm_, "[ VariableDeclaration"); __ mov(StackOperand(variable), Immediate(isolate()->factory()->the_hole_value())); } break; case Variable::CONTEXT: if (hole_init) { Comment cmnt(masm_, "[ VariableDeclaration"); EmitDebugCheckDeclarationContext(variable); __ mov(ContextOperand(esi, variable->index()), Immediate(isolate()->factory()->the_hole_value())); // No write barrier since the hole value is in old space. PrepareForBailoutForId(proxy->id(), NO_REGISTERS); } break; case Variable::LOOKUP: { Comment cmnt(masm_, "[ VariableDeclaration"); __ push(esi); __ push(Immediate(variable->name())); // VariableDeclaration nodes are always introduced in one of four modes. DCHECK(IsDeclaredVariableMode(mode)); PropertyAttributes attr = IsImmutableVariableMode(mode) ? READ_ONLY : NONE; __ push(Immediate(Smi::FromInt(attr))); // Push initial value, if any. // Note: For variables we must not push an initial value (such as // 'undefined') because we may have a (legal) redeclaration and we // must not destroy the current value. if (hole_init) { __ push(Immediate(isolate()->factory()->the_hole_value())); } else { __ push(Immediate(Smi::FromInt(0))); // Indicates no initial value. } __ CallRuntime(Runtime::kDeclareLookupSlot, 4); break; } } } void FullCodeGenerator::VisitFunctionDeclaration( FunctionDeclaration* declaration) { VariableProxy* proxy = declaration->proxy(); Variable* variable = proxy->var(); switch (variable->location()) { case Variable::UNALLOCATED: { globals_->Add(variable->name(), zone()); Handle<SharedFunctionInfo> function = Compiler::BuildFunctionInfo(declaration->fun(), script(), info_); // Check for stack-overflow exception. if (function.is_null()) return SetStackOverflow(); globals_->Add(function, zone()); break; } case Variable::PARAMETER: case Variable::LOCAL: { Comment cmnt(masm_, "[ FunctionDeclaration"); VisitForAccumulatorValue(declaration->fun()); __ mov(StackOperand(variable), result_register()); break; } case Variable::CONTEXT: { Comment cmnt(masm_, "[ FunctionDeclaration"); EmitDebugCheckDeclarationContext(variable); VisitForAccumulatorValue(declaration->fun()); __ mov(ContextOperand(esi, variable->index()), result_register()); // We know that we have written a function, which is not a smi. __ RecordWriteContextSlot(esi, Context::SlotOffset(variable->index()), result_register(), ecx, kDontSaveFPRegs, EMIT_REMEMBERED_SET, OMIT_SMI_CHECK); PrepareForBailoutForId(proxy->id(), NO_REGISTERS); break; } case Variable::LOOKUP: { Comment cmnt(masm_, "[ FunctionDeclaration"); __ push(esi); __ push(Immediate(variable->name())); __ push(Immediate(Smi::FromInt(NONE))); VisitForStackValue(declaration->fun()); __ CallRuntime(Runtime::kDeclareLookupSlot, 4); break; } } } void FullCodeGenerator::VisitImportDeclaration(ImportDeclaration* declaration) { VariableProxy* proxy = declaration->proxy(); Variable* variable = proxy->var(); switch (variable->location()) { case Variable::UNALLOCATED: // TODO(rossberg) break; case Variable::CONTEXT: { Comment cmnt(masm_, "[ ImportDeclaration"); EmitDebugCheckDeclarationContext(variable); // TODO(rossberg) break; } case Variable::PARAMETER: case Variable::LOCAL: case Variable::LOOKUP: UNREACHABLE(); } } void FullCodeGenerator::VisitExportDeclaration(ExportDeclaration* declaration) { // TODO(rossberg) } void FullCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) { // Call the runtime to declare the globals. __ push(esi); // The context is the first argument. __ Push(pairs); __ Push(Smi::FromInt(DeclareGlobalsFlags())); __ CallRuntime(Runtime::kDeclareGlobals, 3); // Return value is ignored. } void FullCodeGenerator::DeclareModules(Handle<FixedArray> descriptions) { // Call the runtime to declare the modules. __ Push(descriptions); __ CallRuntime(Runtime::kDeclareModules, 1); // Return value is ignored. } void FullCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) { Comment cmnt(masm_, "[ SwitchStatement"); Breakable nested_statement(this, stmt); SetStatementPosition(stmt); // Keep the switch value on the stack until a case matches. VisitForStackValue(stmt->tag()); PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); ZoneList<CaseClause*>* clauses = stmt->cases(); CaseClause* default_clause = NULL; // Can occur anywhere in the list. Label next_test; // Recycled for each test. // Compile all the tests with branches to their bodies. for (int i = 0; i < clauses->length(); i++) { CaseClause* clause = clauses->at(i); clause->body_target()->Unuse(); // The default is not a test, but remember it as final fall through. if (clause->is_default()) { default_clause = clause; continue; } Comment cmnt(masm_, "[ Case comparison"); __ bind(&next_test); next_test.Unuse(); // Compile the label expression. VisitForAccumulatorValue(clause->label()); // Perform the comparison as if via '==='. __ mov(edx, Operand(esp, 0)); // Switch value. bool inline_smi_code = ShouldInlineSmiCase(Token::EQ_STRICT); JumpPatchSite patch_site(masm_); if (inline_smi_code) { Label slow_case; __ mov(ecx, edx); __ or_(ecx, eax); patch_site.EmitJumpIfNotSmi(ecx, &slow_case, Label::kNear); __ cmp(edx, eax); __ j(not_equal, &next_test); __ Drop(1); // Switch value is no longer needed. __ jmp(clause->body_target()); __ bind(&slow_case); } // Record position before stub call for type feedback. SetSourcePosition(clause->position()); Handle<Code> ic = CodeFactory::CompareIC(isolate(), Token::EQ_STRICT, language_mode()).code(); CallIC(ic, clause->CompareId()); patch_site.EmitPatchInfo(); Label skip; __ jmp(&skip, Label::kNear); PrepareForBailout(clause, TOS_REG); __ cmp(eax, isolate()->factory()->true_value()); __ j(not_equal, &next_test); __ Drop(1); __ jmp(clause->body_target()); __ bind(&skip); __ test(eax, eax); __ j(not_equal, &next_test); __ Drop(1); // Switch value is no longer needed. __ jmp(clause->body_target()); } // Discard the test value and jump to the default if present, otherwise to // the end of the statement. __ bind(&next_test); __ Drop(1); // Switch value is no longer needed. if (default_clause == NULL) { __ jmp(nested_statement.break_label()); } else { __ jmp(default_clause->body_target()); } // Compile all the case bodies. for (int i = 0; i < clauses->length(); i++) { Comment cmnt(masm_, "[ Case body"); CaseClause* clause = clauses->at(i); __ bind(clause->body_target()); PrepareForBailoutForId(clause->EntryId(), NO_REGISTERS); VisitStatements(clause->statements()); } __ bind(nested_statement.break_label()); PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); } void FullCodeGenerator::VisitForInStatement(ForInStatement* stmt) { Comment cmnt(masm_, "[ ForInStatement"); FeedbackVectorSlot slot = stmt->ForInFeedbackSlot(); SetStatementPosition(stmt); Label loop, exit; ForIn loop_statement(this, stmt); increment_loop_depth(); // Get the object to enumerate over. If the object is null or undefined, skip // over the loop. See ECMA-262 version 5, section 12.6.4. SetExpressionPosition(stmt->enumerable()); VisitForAccumulatorValue(stmt->enumerable()); __ cmp(eax, isolate()->factory()->undefined_value()); __ j(equal, &exit); __ cmp(eax, isolate()->factory()->null_value()); __ j(equal, &exit); PrepareForBailoutForId(stmt->PrepareId(), TOS_REG); // Convert the object to a JS object. Label convert, done_convert; __ JumpIfSmi(eax, &convert, Label::kNear); __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); __ j(above_equal, &done_convert, Label::kNear); __ bind(&convert); __ push(eax); __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); __ bind(&done_convert); PrepareForBailoutForId(stmt->ToObjectId(), TOS_REG); __ push(eax); // Check for proxies. Label call_runtime, use_cache, fixed_array; STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); __ CmpObjectType(eax, LAST_JS_PROXY_TYPE, ecx); __ j(below_equal, &call_runtime); // Check cache validity in generated code. This is a fast case for // the JSObject::IsSimpleEnum cache validity checks. If we cannot // guarantee cache validity, call the runtime system to check cache // validity or get the property names in a fixed array. __ CheckEnumCache(&call_runtime); __ mov(eax, FieldOperand(eax, HeapObject::kMapOffset)); __ jmp(&use_cache, Label::kNear); // Get the set of properties to enumerate. __ bind(&call_runtime); __ push(eax); __ CallRuntime(Runtime::kGetPropertyNamesFast, 1); PrepareForBailoutForId(stmt->EnumId(), TOS_REG); __ cmp(FieldOperand(eax, HeapObject::kMapOffset), isolate()->factory()->meta_map()); __ j(not_equal, &fixed_array); // We got a map in register eax. Get the enumeration cache from it. Label no_descriptors; __ bind(&use_cache); __ EnumLength(edx, eax); __ cmp(edx, Immediate(Smi::FromInt(0))); __ j(equal, &no_descriptors); __ LoadInstanceDescriptors(eax, ecx); __ mov(ecx, FieldOperand(ecx, DescriptorArray::kEnumCacheOffset)); __ mov(ecx, FieldOperand(ecx, DescriptorArray::kEnumCacheBridgeCacheOffset)); // Set up the four remaining stack slots. __ push(eax); // Map. __ push(ecx); // Enumeration cache. __ push(edx); // Number of valid entries for the map in the enum cache. __ push(Immediate(Smi::FromInt(0))); // Initial index. __ jmp(&loop); __ bind(&no_descriptors); __ add(esp, Immediate(kPointerSize)); __ jmp(&exit); // We got a fixed array in register eax. Iterate through that. Label non_proxy; __ bind(&fixed_array); // No need for a write barrier, we are storing a Smi in the feedback vector. __ LoadHeapObject(ebx, FeedbackVector()); int vector_index = FeedbackVector()->GetIndex(slot); __ mov(FieldOperand(ebx, FixedArray::OffsetOfElementAt(vector_index)), Immediate(TypeFeedbackVector::MegamorphicSentinel(isolate()))); __ mov(ebx, Immediate(Smi::FromInt(1))); // Smi indicates slow check __ mov(ecx, Operand(esp, 0 * kPointerSize)); // Get enumerated object STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); __ CmpObjectType(ecx, LAST_JS_PROXY_TYPE, ecx); __ j(above, &non_proxy); __ Move(ebx, Immediate(Smi::FromInt(0))); // Zero indicates proxy __ bind(&non_proxy); __ push(ebx); // Smi __ push(eax); // Array __ mov(eax, FieldOperand(eax, FixedArray::kLengthOffset)); __ push(eax); // Fixed array length (as smi). __ push(Immediate(Smi::FromInt(0))); // Initial index. // Generate code for doing the condition check. PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS); __ bind(&loop); SetExpressionPosition(stmt->each()); __ mov(eax, Operand(esp, 0 * kPointerSize)); // Get the current index. __ cmp(eax, Operand(esp, 1 * kPointerSize)); // Compare to the array length. __ j(above_equal, loop_statement.break_label()); // Get the current entry of the array into register ebx. __ mov(ebx, Operand(esp, 2 * kPointerSize)); __ mov(ebx, FieldOperand(ebx, eax, times_2, FixedArray::kHeaderSize)); // Get the expected map from the stack or a smi in the // permanent slow case into register edx. __ mov(edx, Operand(esp, 3 * kPointerSize)); // Check if the expected map still matches that of the enumerable. // If not, we may have to filter the key. Label update_each; __ mov(ecx, Operand(esp, 4 * kPointerSize)); __ cmp(edx, FieldOperand(ecx, HeapObject::kMapOffset)); __ j(equal, &update_each, Label::kNear); // For proxies, no filtering is done. // TODO(rossberg): What if only a prototype is a proxy? Not specified yet. DCHECK(Smi::FromInt(0) == 0); __ test(edx, edx); __ j(zero, &update_each); // Convert the entry to a string or null if it isn't a property // anymore. If the property has been removed while iterating, we // just skip it. __ push(ecx); // Enumerable. __ push(ebx); // Current entry. __ InvokeBuiltin(Builtins::FILTER_KEY, CALL_FUNCTION); PrepareForBailoutForId(stmt->FilterId(), TOS_REG); __ test(eax, eax); __ j(equal, loop_statement.continue_label()); __ mov(ebx, eax); // Update the 'each' property or variable from the possibly filtered // entry in register ebx. __ bind(&update_each); __ mov(result_register(), ebx); // Perform the assignment as if via '='. { EffectContext context(this); EmitAssignment(stmt->each()); PrepareForBailoutForId(stmt->AssignmentId(), NO_REGISTERS); } // Generate code for the body of the loop. Visit(stmt->body()); // Generate code for going to the next element by incrementing the // index (smi) stored on top of the stack. __ bind(loop_statement.continue_label()); __ add(Operand(esp, 0 * kPointerSize), Immediate(Smi::FromInt(1))); EmitBackEdgeBookkeeping(stmt, &loop); __ jmp(&loop); // Remove the pointers stored on the stack. __ bind(loop_statement.break_label()); __ add(esp, Immediate(5 * kPointerSize)); // Exit and decrement the loop depth. PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); __ bind(&exit); decrement_loop_depth(); } void FullCodeGenerator::EmitNewClosure(Handle<SharedFunctionInfo> info, bool pretenure) { // Use the fast case closure allocation code that allocates in new // space for nested functions that don't need literals cloning. If // we're running with the --always-opt or the --prepare-always-opt // flag, we need to use the runtime function so that the new function // we are creating here gets a chance to have its code optimized and // doesn't just get a copy of the existing unoptimized code. if (!FLAG_always_opt && !FLAG_prepare_always_opt && !pretenure && scope()->is_function_scope() && info->num_literals() == 0) { FastNewClosureStub stub(isolate(), info->language_mode(), info->kind()); __ mov(ebx, Immediate(info)); __ CallStub(&stub); } else { __ push(esi); __ push(Immediate(info)); __ push(Immediate(pretenure ? isolate()->factory()->true_value() : isolate()->factory()->false_value())); __ CallRuntime(Runtime::kNewClosure, 3); } context()->Plug(eax); } void FullCodeGenerator::VisitVariableProxy(VariableProxy* expr) { Comment cmnt(masm_, "[ VariableProxy"); EmitVariableLoad(expr); } void FullCodeGenerator::EmitLoadHomeObject(SuperReference* expr) { Comment cnmt(masm_, "[ SuperReference "); __ mov(LoadDescriptor::ReceiverRegister(), Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); Handle<Symbol> home_object_symbol(isolate()->heap()->home_object_symbol()); __ mov(LoadDescriptor::NameRegister(), home_object_symbol); __ mov(LoadDescriptor::SlotRegister(), Immediate(SmiFromSlot(expr->HomeObjectFeedbackSlot()))); CallLoadIC(NOT_CONTEXTUAL); __ cmp(eax, isolate()->factory()->undefined_value()); Label done; __ j(not_equal, &done); __ CallRuntime(Runtime::kThrowNonMethodError, 0); __ bind(&done); } void FullCodeGenerator::EmitSetHomeObjectIfNeeded(Expression* initializer, int offset) { if (NeedsHomeObject(initializer)) { __ mov(StoreDescriptor::ReceiverRegister(), Operand(esp, 0)); __ mov(StoreDescriptor::NameRegister(), Immediate(isolate()->factory()->home_object_symbol())); __ mov(StoreDescriptor::ValueRegister(), Operand(esp, offset * kPointerSize)); CallStoreIC(); } } void FullCodeGenerator::EmitLoadGlobalCheckExtensions(VariableProxy* proxy, TypeofState typeof_state, Label* slow) { Register context = esi; Register temp = edx; Scope* s = scope(); while (s != NULL) { if (s->num_heap_slots() > 0) { if (s->calls_sloppy_eval()) { // Check that extension is NULL. __ cmp(ContextOperand(context, Context::EXTENSION_INDEX), Immediate(0)); __ j(not_equal, slow); } // Load next context in chain. __ mov(temp, ContextOperand(context, Context::PREVIOUS_INDEX)); // Walk the rest of the chain without clobbering esi. context = temp; } // If no outer scope calls eval, we do not need to check more // context extensions. If we have reached an eval scope, we check // all extensions from this point. if (!s->outer_scope_calls_sloppy_eval() || s->is_eval_scope()) break; s = s->outer_scope(); } if (s != NULL && s->is_eval_scope()) { // Loop up the context chain. There is no frame effect so it is // safe to use raw labels here. Label next, fast; if (!context.is(temp)) { __ mov(temp, context); } __ bind(&next); // Terminate at native context. __ cmp(FieldOperand(temp, HeapObject::kMapOffset), Immediate(isolate()->factory()->native_context_map())); __ j(equal, &fast, Label::kNear); // Check that extension is NULL. __ cmp(ContextOperand(temp, Context::EXTENSION_INDEX), Immediate(0)); __ j(not_equal, slow); // Load next context in chain. __ mov(temp, ContextOperand(temp, Context::PREVIOUS_INDEX)); __ jmp(&next); __ bind(&fast); } // All extension objects were empty and it is safe to use a global // load IC call. __ mov(LoadDescriptor::ReceiverRegister(), GlobalObjectOperand()); __ mov(LoadDescriptor::NameRegister(), proxy->var()->name()); __ mov(LoadDescriptor::SlotRegister(), Immediate(SmiFromSlot(proxy->VariableFeedbackSlot()))); ContextualMode mode = (typeof_state == INSIDE_TYPEOF) ? NOT_CONTEXTUAL : CONTEXTUAL; CallLoadIC(mode); } MemOperand FullCodeGenerator::ContextSlotOperandCheckExtensions(Variable* var, Label* slow) { DCHECK(var->IsContextSlot()); Register context = esi; Register temp = ebx; for (Scope* s = scope(); s != var->scope(); s = s->outer_scope()) { if (s->num_heap_slots() > 0) { if (s->calls_sloppy_eval()) { // Check that extension is NULL. __ cmp(ContextOperand(context, Context::EXTENSION_INDEX), Immediate(0)); __ j(not_equal, slow); } __ mov(temp, ContextOperand(context, Context::PREVIOUS_INDEX)); // Walk the rest of the chain without clobbering esi. context = temp; } } // Check that last extension is NULL. __ cmp(ContextOperand(context, Context::EXTENSION_INDEX), Immediate(0)); __ j(not_equal, slow); // This function is used only for loads, not stores, so it's safe to // return an esi-based operand (the write barrier cannot be allowed to // destroy the esi register). return ContextOperand(context, var->index()); } void FullCodeGenerator::EmitDynamicLookupFastCase(VariableProxy* proxy, TypeofState typeof_state, Label* slow, Label* done) { // Generate fast-case code for variables that might be shadowed by // eval-introduced variables. Eval is used a lot without // introducing variables. In those cases, we do not want to // perform a runtime call for all variables in the scope // containing the eval. Variable* var = proxy->var(); if (var->mode() == DYNAMIC_GLOBAL) { EmitLoadGlobalCheckExtensions(proxy, typeof_state, slow); __ jmp(done); } else if (var->mode() == DYNAMIC_LOCAL) { Variable* local = var->local_if_not_shadowed(); __ mov(eax, ContextSlotOperandCheckExtensions(local, slow)); if (local->mode() == LET || local->mode() == CONST || local->mode() == CONST_LEGACY) { __ cmp(eax, isolate()->factory()->the_hole_value()); __ j(not_equal, done); if (local->mode() == CONST_LEGACY) { __ mov(eax, isolate()->factory()->undefined_value()); } else { // LET || CONST __ push(Immediate(var->name())); __ CallRuntime(Runtime::kThrowReferenceError, 1); } } __ jmp(done); } } void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy) { // Record position before possible IC call. SetSourcePosition(proxy->position()); PrepareForBailoutForId(proxy->BeforeId(), NO_REGISTERS); Variable* var = proxy->var(); // Three cases: global variables, lookup variables, and all other types of // variables. switch (var->location()) { case Variable::UNALLOCATED: { Comment cmnt(masm_, "[ Global variable"); __ mov(LoadDescriptor::ReceiverRegister(), GlobalObjectOperand()); __ mov(LoadDescriptor::NameRegister(), var->name()); __ mov(LoadDescriptor::SlotRegister(), Immediate(SmiFromSlot(proxy->VariableFeedbackSlot()))); CallGlobalLoadIC(var->name()); context()->Plug(eax); break; } case Variable::PARAMETER: case Variable::LOCAL: case Variable::CONTEXT: { Comment cmnt(masm_, var->IsContextSlot() ? "[ Context variable" : "[ Stack variable"); if (var->binding_needs_init()) { // var->scope() may be NULL when the proxy is located in eval code and // refers to a potential outside binding. Currently those bindings are // always looked up dynamically, i.e. in that case // var->location() == LOOKUP. // always holds. DCHECK(var->scope() != NULL); // Check if the binding really needs an initialization check. The check // can be skipped in the following situation: we have a LET or CONST // binding in harmony mode, both the Variable and the VariableProxy have // the same declaration scope (i.e. they are both in global code, in the // same function or in the same eval code) and the VariableProxy is in // the source physically located after the initializer of the variable. // // We cannot skip any initialization checks for CONST in non-harmony // mode because const variables may be declared but never initialized: // if (false) { const x; }; var y = x; // // The condition on the declaration scopes is a conservative check for // nested functions that access a binding and are called before the // binding is initialized: // function() { f(); let x = 1; function f() { x = 2; } } // bool skip_init_check; if (var->scope()->DeclarationScope() != scope()->DeclarationScope()) { skip_init_check = false; } else if (var->is_this()) { CHECK(info_->function() != nullptr && (info_->function()->kind() & kSubclassConstructor) != 0); // TODO(dslomov): implement 'this' hole check elimination. skip_init_check = false; } else { // Check that we always have valid source position. DCHECK(var->initializer_position() != RelocInfo::kNoPosition); DCHECK(proxy->position() != RelocInfo::kNoPosition); skip_init_check = var->mode() != CONST_LEGACY && var->initializer_position() < proxy->position(); } if (!skip_init_check) { // Let and const need a read barrier. Label done; GetVar(eax, var); __ cmp(eax, isolate()->factory()->the_hole_value()); __ j(not_equal, &done, Label::kNear); if (var->mode() == LET || var->mode() == CONST) { // Throw a reference error when using an uninitialized let/const // binding in harmony mode. __ push(Immediate(var->name())); __ CallRuntime(Runtime::kThrowReferenceError, 1); } else { // Uninitalized const bindings outside of harmony mode are unholed. DCHECK(var->mode() == CONST_LEGACY); __ mov(eax, isolate()->factory()->undefined_value()); } __ bind(&done); context()->Plug(eax); break; } } context()->Plug(var); break; } case Variable::LOOKUP: { Comment cmnt(masm_, "[ Lookup variable"); Label done, slow; // Generate code for loading from variables potentially shadowed // by eval-introduced variables. EmitDynamicLookupFastCase(proxy, NOT_INSIDE_TYPEOF, &slow, &done); __ bind(&slow); __ push(esi); // Context. __ push(Immediate(var->name())); __ CallRuntime(Runtime::kLoadLookupSlot, 2); __ bind(&done); context()->Plug(eax); break; } } } void FullCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) { Comment cmnt(masm_, "[ RegExpLiteral"); Label materialized; // Registers will be used as follows: // edi = JS function. // ecx = literals array. // ebx = regexp literal. // eax = regexp literal clone. __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); __ mov(ecx, FieldOperand(edi, JSFunction::kLiteralsOffset)); int literal_offset = FixedArray::kHeaderSize + expr->literal_index() * kPointerSize; __ mov(ebx, FieldOperand(ecx, literal_offset)); __ cmp(ebx, isolate()->factory()->undefined_value()); __ j(not_equal, &materialized, Label::kNear); // Create regexp literal using runtime function // Result will be in eax. __ push(ecx); __ push(Immediate(Smi::FromInt(expr->literal_index()))); __ push(Immediate(expr->pattern())); __ push(Immediate(expr->flags())); __ CallRuntime(Runtime::kMaterializeRegExpLiteral, 4); __ mov(ebx, eax); __ bind(&materialized); int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; Label allocated, runtime_allocate; __ Allocate(size, eax, ecx, edx, &runtime_allocate, TAG_OBJECT); __ jmp(&allocated); __ bind(&runtime_allocate); __ push(ebx); __ push(Immediate(Smi::FromInt(size))); __ CallRuntime(Runtime::kAllocateInNewSpace, 1); __ pop(ebx); __ bind(&allocated); // Copy the content into the newly allocated memory. // (Unroll copy loop once for better throughput). for (int i = 0; i < size - kPointerSize; i += 2 * kPointerSize) { __ mov(edx, FieldOperand(ebx, i)); __ mov(ecx, FieldOperand(ebx, i + kPointerSize)); __ mov(FieldOperand(eax, i), edx); __ mov(FieldOperand(eax, i + kPointerSize), ecx); } if ((size % (2 * kPointerSize)) != 0) { __ mov(edx, FieldOperand(ebx, size - kPointerSize)); __ mov(FieldOperand(eax, size - kPointerSize), edx); } context()->Plug(eax); } void FullCodeGenerator::EmitAccessor(Expression* expression) { if (expression == NULL) { __ push(Immediate(isolate()->factory()->null_value())); } else { VisitForStackValue(expression); } } void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { Comment cmnt(masm_, "[ ObjectLiteral"); expr->BuildConstantProperties(isolate()); Handle<FixedArray> constant_properties = expr->constant_properties(); int flags = expr->ComputeFlags(); // If any of the keys would store to the elements array, then we shouldn't // allow it. if (MustCreateObjectLiteralWithRuntime(expr)) { __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); __ push(FieldOperand(edi, JSFunction::kLiteralsOffset)); __ push(Immediate(Smi::FromInt(expr->literal_index()))); __ push(Immediate(constant_properties)); __ push(Immediate(Smi::FromInt(flags))); __ CallRuntime(Runtime::kCreateObjectLiteral, 4); } else { __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); __ mov(eax, FieldOperand(edi, JSFunction::kLiteralsOffset)); __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index()))); __ mov(ecx, Immediate(constant_properties)); __ mov(edx, Immediate(Smi::FromInt(flags))); FastCloneShallowObjectStub stub(isolate(), expr->properties_count()); __ CallStub(&stub); } PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG); // If result_saved is true the result is on top of the stack. If // result_saved is false the result is in eax. bool result_saved = false; // Mark all computed expressions that are bound to a key that // is shadowed by a later occurrence of the same key. For the // marked expressions, no store code is emitted. expr->CalculateEmitStore(zone()); AccessorTable accessor_table(zone()); int property_index = 0; for (; property_index < expr->properties()->length(); property_index++) { ObjectLiteral::Property* property = expr->properties()->at(property_index); if (property->is_computed_name()) break; if (property->IsCompileTimeValue()) continue; Literal* key = property->key()->AsLiteral(); Expression* value = property->value(); if (!result_saved) { __ push(eax); // Save result on the stack result_saved = true; } switch (property->kind()) { case ObjectLiteral::Property::CONSTANT: UNREACHABLE(); case ObjectLiteral::Property::MATERIALIZED_LITERAL: DCHECK(!CompileTimeValue::IsCompileTimeValue(value)); // Fall through. case ObjectLiteral::Property::COMPUTED: // It is safe to use [[Put]] here because the boilerplate already // contains computed properties with an uninitialized value. if (key->value()->IsInternalizedString()) { if (property->emit_store()) { VisitForAccumulatorValue(value); DCHECK(StoreDescriptor::ValueRegister().is(eax)); __ mov(StoreDescriptor::NameRegister(), Immediate(key->value())); __ mov(StoreDescriptor::ReceiverRegister(), Operand(esp, 0)); CallStoreIC(key->LiteralFeedbackId()); PrepareForBailoutForId(key->id(), NO_REGISTERS); if (NeedsHomeObject(value)) { __ mov(StoreDescriptor::ReceiverRegister(), eax); __ mov(StoreDescriptor::NameRegister(), Immediate(isolate()->factory()->home_object_symbol())); __ mov(StoreDescriptor::ValueRegister(), Operand(esp, 0)); CallStoreIC(); } } else { VisitForEffect(value); } break; } __ push(Operand(esp, 0)); // Duplicate receiver. VisitForStackValue(key); VisitForStackValue(value); if (property->emit_store()) { EmitSetHomeObjectIfNeeded(value, 2); __ push(Immediate(Smi::FromInt(SLOPPY))); // Language mode __ CallRuntime(Runtime::kSetProperty, 4); } else { __ Drop(3); } break; case ObjectLiteral::Property::PROTOTYPE: __ push(Operand(esp, 0)); // Duplicate receiver. VisitForStackValue(value); DCHECK(property->emit_store()); __ CallRuntime(Runtime::kInternalSetPrototype, 2); break; case ObjectLiteral::Property::GETTER: if (property->emit_store()) { accessor_table.lookup(key)->second->getter = value; } break; case ObjectLiteral::Property::SETTER: if (property->emit_store()) { accessor_table.lookup(key)->second->setter = value; } break; } } // Emit code to define accessors, using only a single call to the runtime for // each pair of corresponding getters and setters. for (AccessorTable::Iterator it = accessor_table.begin(); it != accessor_table.end(); ++it) { __ push(Operand(esp, 0)); // Duplicate receiver. VisitForStackValue(it->first); EmitAccessor(it->second->getter); EmitSetHomeObjectIfNeeded(it->second->getter, 2); EmitAccessor(it->second->setter); EmitSetHomeObjectIfNeeded(it->second->setter, 3); __ push(Immediate(Smi::FromInt(NONE))); __ CallRuntime(Runtime::kDefineAccessorPropertyUnchecked, 5); } // Object literals have two parts. The "static" part on the left contains no // computed property names, and so we can compute its map ahead of time; see // runtime.cc::CreateObjectLiteralBoilerplate. The second "dynamic" part // starts with the first computed property name, and continues with all // properties to its right. All the code from above initializes the static // component of the object literal, and arranges for the map of the result to // reflect the static order in which the keys appear. For the dynamic // properties, we compile them into a series of "SetOwnProperty" runtime // calls. This will preserve insertion order. for (; property_index < expr->properties()->length(); property_index++) { ObjectLiteral::Property* property = expr->properties()->at(property_index); Expression* value = property->value(); if (!result_saved) { __ push(eax); // Save result on the stack result_saved = true; } __ push(Operand(esp, 0)); // Duplicate receiver. if (property->kind() == ObjectLiteral::Property::PROTOTYPE) { DCHECK(!property->is_computed_name()); VisitForStackValue(value); DCHECK(property->emit_store()); __ CallRuntime(Runtime::kInternalSetPrototype, 2); } else { EmitPropertyKey(property, expr->GetIdForProperty(property_index)); VisitForStackValue(value); EmitSetHomeObjectIfNeeded(value, 2); switch (property->kind()) { case ObjectLiteral::Property::CONSTANT: case ObjectLiteral::Property::MATERIALIZED_LITERAL: case ObjectLiteral::Property::COMPUTED: if (property->emit_store()) { __ push(Immediate(Smi::FromInt(NONE))); __ CallRuntime(Runtime::kDefineDataPropertyUnchecked, 4); } else { __ Drop(3); } break; case ObjectLiteral::Property::PROTOTYPE: UNREACHABLE(); break; case ObjectLiteral::Property::GETTER: __ push(Immediate(Smi::FromInt(NONE))); __ CallRuntime(Runtime::kDefineGetterPropertyUnchecked, 4); break; case ObjectLiteral::Property::SETTER: __ push(Immediate(Smi::FromInt(NONE))); __ CallRuntime(Runtime::kDefineSetterPropertyUnchecked, 4); break; } } } if (expr->has_function()) { DCHECK(result_saved); __ push(Operand(esp, 0)); __ CallRuntime(Runtime::kToFastProperties, 1); } if (result_saved) { context()->PlugTOS(); } else { context()->Plug(eax); } } void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { Comment cmnt(masm_, "[ ArrayLiteral"); expr->BuildConstantElements(isolate()); Handle<FixedArray> constant_elements = expr->constant_elements(); bool has_constant_fast_elements = IsFastObjectElementsKind(expr->constant_elements_kind()); AllocationSiteMode allocation_site_mode = TRACK_ALLOCATION_SITE; if (has_constant_fast_elements && !FLAG_allocation_site_pretenuring) { // If the only customer of allocation sites is transitioning, then // we can turn it off if we don't have anywhere else to transition to. allocation_site_mode = DONT_TRACK_ALLOCATION_SITE; } if (MustCreateArrayLiteralWithRuntime(expr)) { __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); __ push(Immediate(Smi::FromInt(expr->literal_index()))); __ push(Immediate(constant_elements)); __ push(Immediate(Smi::FromInt(expr->ComputeFlags()))); __ CallRuntime(Runtime::kCreateArrayLiteral, 4); } else { __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); __ mov(eax, FieldOperand(ebx, JSFunction::kLiteralsOffset)); __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index()))); __ mov(ecx, Immediate(constant_elements)); FastCloneShallowArrayStub stub(isolate(), allocation_site_mode); __ CallStub(&stub); } PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG); bool result_saved = false; // Is the result saved to the stack? ZoneList<Expression*>* subexprs = expr->values(); int length = subexprs->length(); // Emit code to evaluate all the non-constant subexpressions and to store // them into the newly cloned array. int array_index = 0; for (; array_index < length; array_index++) { Expression* subexpr = subexprs->at(array_index); if (subexpr->IsSpread()) break; // If the subexpression is a literal or a simple materialized literal it // is already set in the cloned array. if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue; if (!result_saved) { __ push(eax); // array literal. __ push(Immediate(Smi::FromInt(expr->literal_index()))); result_saved = true; } VisitForAccumulatorValue(subexpr); if (has_constant_fast_elements) { // Fast-case array literal with ElementsKind of FAST_*_ELEMENTS, they // cannot transition and don't need to call the runtime stub. int offset = FixedArray::kHeaderSize + (array_index * kPointerSize); __ mov(ebx, Operand(esp, kPointerSize)); // Copy of array literal. __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); // Store the subexpression value in the array's elements. __ mov(FieldOperand(ebx, offset), result_register()); // Update the write barrier for the array store. __ RecordWriteField(ebx, offset, result_register(), ecx, kDontSaveFPRegs, EMIT_REMEMBERED_SET, INLINE_SMI_CHECK); } else { // Store the subexpression value in the array's elements. __ mov(ecx, Immediate(Smi::FromInt(array_index))); StoreArrayLiteralElementStub stub(isolate()); __ CallStub(&stub); } PrepareForBailoutForId(expr->GetIdForElement(array_index), NO_REGISTERS); } // In case the array literal contains spread expressions it has two parts. The // first part is the "static" array which has a literal index is handled // above. The second part is the part after the first spread expression // (inclusive) and these elements gets appended to the array. Note that the // number elements an iterable produces is unknown ahead of time. if (array_index < length && result_saved) { __ Drop(1); // literal index __ Pop(eax); result_saved = false; } for (; array_index < length; array_index++) { Expression* subexpr = subexprs->at(array_index); __ Push(eax); if (subexpr->IsSpread()) { VisitForStackValue(subexpr->AsSpread()->expression()); __ InvokeBuiltin(Builtins::CONCAT_ITERABLE_TO_ARRAY, CALL_FUNCTION); } else { VisitForStackValue(subexpr); __ CallRuntime(Runtime::kAppendElement, 2); } PrepareForBailoutForId(expr->GetIdForElement(array_index), NO_REGISTERS); } if (result_saved) { __ Drop(1); // literal index context()->PlugTOS(); } else { context()->Plug(eax); } } void FullCodeGenerator::VisitAssignment(Assignment* expr) { DCHECK(expr->target()->IsValidReferenceExpression()); Comment cmnt(masm_, "[ Assignment"); Property* property = expr->target()->AsProperty(); LhsKind assign_type = GetAssignType(property); // Evaluate LHS expression. switch (assign_type) { case VARIABLE: // Nothing to do here. break; case NAMED_SUPER_PROPERTY: VisitForStackValue(property->obj()->AsSuperReference()->this_var()); EmitLoadHomeObject(property->obj()->AsSuperReference()); __ push(result_register()); if (expr->is_compound()) { __ push(MemOperand(esp, kPointerSize)); __ push(result_register()); } break; case NAMED_PROPERTY: if (expr->is_compound()) { // We need the receiver both on the stack and in the register. VisitForStackValue(property->obj()); __ mov(LoadDescriptor::ReceiverRegister(), Operand(esp, 0)); } else { VisitForStackValue(property->obj()); } break; case KEYED_SUPER_PROPERTY: VisitForStackValue(property->obj()->AsSuperReference()->this_var()); EmitLoadHomeObject(property->obj()->AsSuperReference()); __ Push(result_register()); VisitForAccumulatorValue(property->key()); __ Push(result_register()); if (expr->is_compound()) { __ push(MemOperand(esp, 2 * kPointerSize)); __ push(MemOperand(esp, 2 * kPointerSize)); __ push(result_register()); } break; case KEYED_PROPERTY: { if (expr->is_compound()) { VisitForStackValue(property->obj()); VisitForStackValue(property->key()); __ mov(LoadDescriptor::ReceiverRegister(), Operand(esp, kPointerSize)); __ mov(LoadDescriptor::NameRegister(), Operand(esp, 0)); } else { VisitForStackValue(property->obj()); VisitForStackValue(property->key()); } break; } } // For compound assignments we need another deoptimization point after the // variable/property load. if (expr->is_compound()) { AccumulatorValueContext result_context(this); { AccumulatorValueContext left_operand_context(this); switch (assign_type) { case VARIABLE: EmitVariableLoad(expr->target()->AsVariableProxy()); PrepareForBailout(expr->target(), TOS_REG); break; case NAMED_SUPER_PROPERTY: EmitNamedSuperPropertyLoad(property); PrepareForBailoutForId(property->LoadId(), TOS_REG); break; case NAMED_PROPERTY: EmitNamedPropertyLoad(property); PrepareForBailoutForId(property->LoadId(), TOS_REG); break; case KEYED_SUPER_PROPERTY: EmitKeyedSuperPropertyLoad(property); PrepareForBailoutForId(property->LoadId(), TOS_REG); break; case KEYED_PROPERTY: EmitKeyedPropertyLoad(property); PrepareForBailoutForId(property->LoadId(), TOS_REG); break; } } Token::Value op = expr->binary_op(); __ push(eax); // Left operand goes on the stack. VisitForAccumulatorValue(expr->value()); SetSourcePosition(expr->position() + 1); if (ShouldInlineSmiCase(op)) { EmitInlineSmiBinaryOp(expr->binary_operation(), op, expr->target(), expr->value()); } else { EmitBinaryOp(expr->binary_operation(), op); } // Deoptimization point in case the binary operation may have side effects. PrepareForBailout(expr->binary_operation(), TOS_REG); } else { VisitForAccumulatorValue(expr->value()); } // Record source position before possible IC call. SetSourcePosition(expr->position()); // Store the value. switch (assign_type) { case VARIABLE: EmitVariableAssignment(expr->target()->AsVariableProxy()->var(), expr->op()); PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); context()->Plug(eax); break; case NAMED_PROPERTY: EmitNamedPropertyAssignment(expr); break; case NAMED_SUPER_PROPERTY: EmitNamedSuperPropertyStore(property); context()->Plug(result_register()); break; case KEYED_SUPER_PROPERTY: EmitKeyedSuperPropertyStore(property); context()->Plug(result_register()); break; case KEYED_PROPERTY: EmitKeyedPropertyAssignment(expr); break; } } void FullCodeGenerator::VisitYield(Yield* expr) { Comment cmnt(masm_, "[ Yield"); // Evaluate yielded value first; the initial iterator definition depends on // this. It stays on the stack while we update the iterator. VisitForStackValue(expr->expression()); switch (expr->yield_kind()) { case Yield::kSuspend: // Pop value from top-of-stack slot; box result into result register. EmitCreateIteratorResult(false); __ push(result_register()); // Fall through. case Yield::kInitial: { Label suspend, continuation, post_runtime, resume; __ jmp(&suspend); __ bind(&continuation); __ jmp(&resume); __ bind(&suspend); VisitForAccumulatorValue(expr->generator_object()); DCHECK(continuation.pos() > 0 && Smi::IsValid(continuation.pos())); __ mov(FieldOperand(eax, JSGeneratorObject::kContinuationOffset), Immediate(Smi::FromInt(continuation.pos()))); __ mov(FieldOperand(eax, JSGeneratorObject::kContextOffset), esi); __ mov(ecx, esi); __ RecordWriteField(eax, JSGeneratorObject::kContextOffset, ecx, edx, kDontSaveFPRegs); __ lea(ebx, Operand(ebp, StandardFrameConstants::kExpressionsOffset)); __ cmp(esp, ebx); __ j(equal, &post_runtime); __ push(eax); // generator object __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); __ mov(context_register(), Operand(ebp, StandardFrameConstants::kContextOffset)); __ bind(&post_runtime); __ pop(result_register()); EmitReturnSequence(); __ bind(&resume); context()->Plug(result_register()); break; } case Yield::kFinal: { VisitForAccumulatorValue(expr->generator_object()); __ mov(FieldOperand(result_register(), JSGeneratorObject::kContinuationOffset), Immediate(Smi::FromInt(JSGeneratorObject::kGeneratorClosed))); // Pop value from top-of-stack slot, box result into result register. EmitCreateIteratorResult(true); EmitUnwindBeforeReturn(); EmitReturnSequence(); break; } case Yield::kDelegating: { VisitForStackValue(expr->generator_object()); // Initial stack layout is as follows: // [sp + 1 * kPointerSize] iter // [sp + 0 * kPointerSize] g Label l_catch, l_try, l_suspend, l_continuation, l_resume; Label l_next, l_call, l_loop; Register load_receiver = LoadDescriptor::ReceiverRegister(); Register load_name = LoadDescriptor::NameRegister(); // Initial send value is undefined. __ mov(eax, isolate()->factory()->undefined_value()); __ jmp(&l_next); // catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; } __ bind(&l_catch); __ mov(load_name, isolate()->factory()->throw_string()); // "throw" __ push(load_name); // "throw" __ push(Operand(esp, 2 * kPointerSize)); // iter __ push(eax); // exception __ jmp(&l_call); // try { received = %yield result } // Shuffle the received result above a try handler and yield it without // re-boxing. __ bind(&l_try); __ pop(eax); // result EnterTryBlock(expr->index(), &l_catch); const int try_block_size = TryCatch::kElementCount * kPointerSize; __ push(eax); // result __ jmp(&l_suspend); __ bind(&l_continuation); __ jmp(&l_resume); __ bind(&l_suspend); const int generator_object_depth = kPointerSize + try_block_size; __ mov(eax, Operand(esp, generator_object_depth)); __ push(eax); // g __ push(Immediate(Smi::FromInt(expr->index()))); // handler-index DCHECK(l_continuation.pos() > 0 && Smi::IsValid(l_continuation.pos())); __ mov(FieldOperand(eax, JSGeneratorObject::kContinuationOffset), Immediate(Smi::FromInt(l_continuation.pos()))); __ mov(FieldOperand(eax, JSGeneratorObject::kContextOffset), esi); __ mov(ecx, esi); __ RecordWriteField(eax, JSGeneratorObject::kContextOffset, ecx, edx, kDontSaveFPRegs); __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 2); __ mov(context_register(), Operand(ebp, StandardFrameConstants::kContextOffset)); __ pop(eax); // result EmitReturnSequence(); __ bind(&l_resume); // received in eax ExitTryBlock(expr->index()); // receiver = iter; f = iter.next; arg = received; __ bind(&l_next); __ mov(load_name, isolate()->factory()->next_string()); __ push(load_name); // "next" __ push(Operand(esp, 2 * kPointerSize)); // iter __ push(eax); // received // result = receiver[f](arg); __ bind(&l_call); __ mov(load_receiver, Operand(esp, kPointerSize)); __ mov(LoadDescriptor::SlotRegister(), Immediate(SmiFromSlot(expr->KeyedLoadFeedbackSlot()))); Handle<Code> ic = CodeFactory::KeyedLoadIC(isolate()).code(); CallIC(ic, TypeFeedbackId::None()); __ mov(edi, eax); __ mov(Operand(esp, 2 * kPointerSize), edi); CallFunctionStub stub(isolate(), 1, CALL_AS_METHOD); __ CallStub(&stub); __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); __ Drop(1); // The function is still on the stack; drop it. // if (!result.done) goto l_try; __ bind(&l_loop); __ push(eax); // save result __ Move(load_receiver, eax); // result __ mov(load_name, isolate()->factory()->done_string()); // "done" __ mov(LoadDescriptor::SlotRegister(), Immediate(SmiFromSlot(expr->DoneFeedbackSlot()))); CallLoadIC(NOT_CONTEXTUAL); // result.done in eax Handle<Code> bool_ic = ToBooleanStub::GetUninitialized(isolate()); CallIC(bool_ic); __ test(eax, eax); __ j(zero, &l_try); // result.value __ pop(load_receiver); // result __ mov(load_name, isolate()->factory()->value_string()); // "value" __ mov(LoadDescriptor::SlotRegister(), Immediate(SmiFromSlot(expr->ValueFeedbackSlot()))); CallLoadIC(NOT_CONTEXTUAL); // result.value in eax context()->DropAndPlug(2, eax); // drop iter and g break; } } } void FullCodeGenerator::EmitGeneratorResume(Expression *generator, Expression *value, JSGeneratorObject::ResumeMode resume_mode) { // The value stays in eax, and is ultimately read by the resumed generator, as // if CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it // is read to throw the value when the resumed generator is already closed. // ebx will hold the generator object until the activation has been resumed. VisitForStackValue(generator); VisitForAccumulatorValue(value); __ pop(ebx); // Load suspended function and context. __ mov(esi, FieldOperand(ebx, JSGeneratorObject::kContextOffset)); __ mov(edi, FieldOperand(ebx, JSGeneratorObject::kFunctionOffset)); // Push receiver. __ push(FieldOperand(ebx, JSGeneratorObject::kReceiverOffset)); // Push holes for arguments to generator function. __ mov(edx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); __ mov(edx, FieldOperand(edx, SharedFunctionInfo::kFormalParameterCountOffset)); __ mov(ecx, isolate()->factory()->the_hole_value()); Label push_argument_holes, push_frame; __ bind(&push_argument_holes); __ sub(edx, Immediate(Smi::FromInt(1))); __ j(carry, &push_frame); __ push(ecx); __ jmp(&push_argument_holes); // Enter a new JavaScript frame, and initialize its slots as they were when // the generator was suspended. Label resume_frame, done; __ bind(&push_frame); __ call(&resume_frame); __ jmp(&done); __ bind(&resume_frame); __ push(ebp); // Caller's frame pointer. __ mov(ebp, esp); __ push(esi); // Callee's context. __ push(edi); // Callee's JS Function. // Load the operand stack size. __ mov(edx, FieldOperand(ebx, JSGeneratorObject::kOperandStackOffset)); __ mov(edx, FieldOperand(edx, FixedArray::kLengthOffset)); __ SmiUntag(edx); // If we are sending a value and there is no operand stack, we can jump back // in directly. if (resume_mode == JSGeneratorObject::NEXT) { Label slow_resume; __ cmp(edx, Immediate(0)); __ j(not_zero, &slow_resume); __ mov(edx, FieldOperand(edi, JSFunction::kCodeEntryOffset)); __ mov(ecx, FieldOperand(ebx, JSGeneratorObject::kContinuationOffset)); __ SmiUntag(ecx); __ add(edx, ecx); __ mov(FieldOperand(ebx, JSGeneratorObject::kContinuationOffset), Immediate(Smi::FromInt(JSGeneratorObject::kGeneratorExecuting))); __ jmp(edx); __ bind(&slow_resume); } // Otherwise, we push holes for the operand stack and call the runtime to fix // up the stack and the handlers. Label push_operand_holes, call_resume; __ bind(&push_operand_holes); __ sub(edx, Immediate(1)); __ j(carry, &call_resume); __ push(ecx); __ jmp(&push_operand_holes); __ bind(&call_resume); __ push(ebx); __ push(result_register()); __ Push(Smi::FromInt(resume_mode)); __ CallRuntime(Runtime::kResumeJSGeneratorObject, 3); // Not reached: the runtime call returns elsewhere. __ Abort(kGeneratorFailedToResume); __ bind(&done); context()->Plug(result_register()); } void FullCodeGenerator::EmitCreateIteratorResult(bool done) { Label gc_required; Label allocated; const int instance_size = 5 * kPointerSize; DCHECK_EQ(isolate()->native_context()->iterator_result_map()->instance_size(), instance_size); __ Allocate(instance_size, eax, ecx, edx, &gc_required, TAG_OBJECT); __ jmp(&allocated); __ bind(&gc_required); __ Push(Smi::FromInt(instance_size)); __ CallRuntime(Runtime::kAllocateInNewSpace, 1); __ mov(context_register(), Operand(ebp, StandardFrameConstants::kContextOffset)); __ bind(&allocated); __ mov(ebx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); __ mov(ebx, FieldOperand(ebx, GlobalObject::kNativeContextOffset)); __ mov(ebx, ContextOperand(ebx, Context::ITERATOR_RESULT_MAP_INDEX)); __ pop(ecx); __ mov(edx, isolate()->factory()->ToBoolean(done)); __ mov(FieldOperand(eax, HeapObject::kMapOffset), ebx); __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), isolate()->factory()->empty_fixed_array()); __ mov(FieldOperand(eax, JSObject::kElementsOffset), isolate()->factory()->empty_fixed_array()); __ mov(FieldOperand(eax, JSGeneratorObject::kResultValuePropertyOffset), ecx); __ mov(FieldOperand(eax, JSGeneratorObject::kResultDonePropertyOffset), edx); // Only the value field needs a write barrier, as the other values are in the // root set. __ RecordWriteField(eax, JSGeneratorObject::kResultValuePropertyOffset, ecx, edx, kDontSaveFPRegs); } void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) { SetSourcePosition(prop->position()); Literal* key = prop->key()->AsLiteral(); DCHECK(!key->value()->IsSmi()); DCHECK(!prop->IsSuperAccess()); __ mov(LoadDescriptor::NameRegister(), Immediate(key->value())); __ mov(LoadDescriptor::SlotRegister(), Immediate(SmiFromSlot(prop->PropertyFeedbackSlot()))); CallLoadIC(NOT_CONTEXTUAL); } void FullCodeGenerator::EmitNamedSuperPropertyLoad(Property* prop) { // Stack: receiver, home_object. SetSourcePosition(prop->position()); Literal* key = prop->key()->AsLiteral(); DCHECK(!key->value()->IsSmi()); DCHECK(prop->IsSuperAccess()); __ push(Immediate(key->value())); __ CallRuntime(Runtime::kLoadFromSuper, 3); } void FullCodeGenerator::EmitKeyedPropertyLoad(Property* prop) { SetSourcePosition(prop->position()); Handle<Code> ic = CodeFactory::KeyedLoadIC(isolate()).code(); __ mov(LoadDescriptor::SlotRegister(), Immediate(SmiFromSlot(prop->PropertyFeedbackSlot()))); CallIC(ic); } void FullCodeGenerator::EmitKeyedSuperPropertyLoad(Property* prop) { // Stack: receiver, home_object, key. SetSourcePosition(prop->position()); __ CallRuntime(Runtime::kLoadKeyedFromSuper, 3); } void FullCodeGenerator::EmitInlineSmiBinaryOp(BinaryOperation* expr, Token::Value op, Expression* left, Expression* right) { // Do combined smi check of the operands. Left operand is on the // stack. Right operand is in eax. Label smi_case, done, stub_call; __ pop(edx); __ mov(ecx, eax); __ or_(eax, edx); JumpPatchSite patch_site(masm_); patch_site.EmitJumpIfSmi(eax, &smi_case, Label::kNear); __ bind(&stub_call); __ mov(eax, ecx); Handle<Code> code = CodeFactory::BinaryOpIC( isolate(), op, language_mode()).code(); CallIC(code, expr->BinaryOperationFeedbackId()); patch_site.EmitPatchInfo(); __ jmp(&done, Label::kNear); // Smi case. __ bind(&smi_case); __ mov(eax, edx); // Copy left operand in case of a stub call. switch (op) { case Token::SAR: __ SmiUntag(ecx); __ sar_cl(eax); // No checks of result necessary __ and_(eax, Immediate(~kSmiTagMask)); break; case Token::SHL: { Label result_ok; __ SmiUntag(eax); __ SmiUntag(ecx); __ shl_cl(eax); // Check that the *signed* result fits in a smi. __ cmp(eax, 0xc0000000); __ j(positive, &result_ok); __ SmiTag(ecx); __ jmp(&stub_call); __ bind(&result_ok); __ SmiTag(eax); break; } case Token::SHR: { Label result_ok; __ SmiUntag(eax); __ SmiUntag(ecx); __ shr_cl(eax); __ test(eax, Immediate(0xc0000000)); __ j(zero, &result_ok); __ SmiTag(ecx); __ jmp(&stub_call); __ bind(&result_ok); __ SmiTag(eax); break; } case Token::ADD: __ add(eax, ecx); __ j(overflow, &stub_call); break; case Token::SUB: __ sub(eax, ecx); __ j(overflow, &stub_call); break; case Token::MUL: { __ SmiUntag(eax); __ imul(eax, ecx); __ j(overflow, &stub_call); __ test(eax, eax); __ j(not_zero, &done, Label::kNear); __ mov(ebx, edx); __ or_(ebx, ecx); __ j(negative, &stub_call); break; } case Token::BIT_OR: __ or_(eax, ecx); break; case Token::BIT_AND: __ and_(eax, ecx); break; case Token::BIT_XOR: __ xor_(eax, ecx); break; default: UNREACHABLE(); } __ bind(&done); context()->Plug(eax); } void FullCodeGenerator::EmitClassDefineProperties(ClassLiteral* lit) { // Constructor is in eax. DCHECK(lit != NULL); __ push(eax); // No access check is needed here since the constructor is created by the // class literal. Register scratch = ebx; __ mov(scratch, FieldOperand(eax, JSFunction::kPrototypeOrInitialMapOffset)); __ Push(scratch); for (int i = 0; i < lit->properties()->length(); i++) { ObjectLiteral::Property* property = lit->properties()->at(i); Expression* value = property->value(); if (property->is_static()) { __ push(Operand(esp, kPointerSize)); // constructor } else { __ push(Operand(esp, 0)); // prototype } EmitPropertyKey(property, lit->GetIdForProperty(i)); // The static prototype property is read only. We handle the non computed // property name case in the parser. Since this is the only case where we // need to check for an own read only property we special case this so we do // not need to do this for every property. if (property->is_static() && property->is_computed_name()) { __ CallRuntime(Runtime::kThrowIfStaticPrototype, 1); __ push(eax); } VisitForStackValue(value); EmitSetHomeObjectIfNeeded(value, 2); switch (property->kind()) { case ObjectLiteral::Property::CONSTANT: case ObjectLiteral::Property::MATERIALIZED_LITERAL: case ObjectLiteral::Property::PROTOTYPE: UNREACHABLE(); case ObjectLiteral::Property::COMPUTED: __ CallRuntime(Runtime::kDefineClassMethod, 3); break; case ObjectLiteral::Property::GETTER: __ push(Immediate(Smi::FromInt(DONT_ENUM))); __ CallRuntime(Runtime::kDefineGetterPropertyUnchecked, 4); break; case ObjectLiteral::Property::SETTER: __ push(Immediate(Smi::FromInt(DONT_ENUM))); __ CallRuntime(Runtime::kDefineSetterPropertyUnchecked, 4); break; } } // prototype __ CallRuntime(Runtime::kToFastProperties, 1); // constructor __ CallRuntime(Runtime::kToFastProperties, 1); } void FullCodeGenerator::EmitBinaryOp(BinaryOperation* expr, Token::Value op) { __ pop(edx); Handle<Code> code = CodeFactory::BinaryOpIC( isolate(), op, language_mode()).code(); JumpPatchSite patch_site(masm_); // unbound, signals no inlined smi code. CallIC(code, expr->BinaryOperationFeedbackId()); patch_site.EmitPatchInfo(); context()->Plug(eax); } void FullCodeGenerator::EmitAssignment(Expression* expr) { DCHECK(expr->IsValidReferenceExpression()); Property* prop = expr->AsProperty(); LhsKind assign_type = GetAssignType(prop); switch (assign_type) { case VARIABLE: { Variable* var = expr->AsVariableProxy()->var(); EffectContext context(this); EmitVariableAssignment(var, Token::ASSIGN); break; } case NAMED_PROPERTY: { __ push(eax); // Preserve value. VisitForAccumulatorValue(prop->obj()); __ Move(StoreDescriptor::ReceiverRegister(), eax); __ pop(StoreDescriptor::ValueRegister()); // Restore value. __ mov(StoreDescriptor::NameRegister(), prop->key()->AsLiteral()->value()); CallStoreIC(); break; } case NAMED_SUPER_PROPERTY: { __ push(eax); VisitForStackValue(prop->obj()->AsSuperReference()->this_var()); EmitLoadHomeObject(prop->obj()->AsSuperReference()); // stack: value, this; eax: home_object Register scratch = ecx; Register scratch2 = edx; __ mov(scratch, result_register()); // home_object __ mov(eax, MemOperand(esp, kPointerSize)); // value __ mov(scratch2, MemOperand(esp, 0)); // this __ mov(MemOperand(esp, kPointerSize), scratch2); // this __ mov(MemOperand(esp, 0), scratch); // home_object // stack: this, home_object. eax: value EmitNamedSuperPropertyStore(prop); break; } case KEYED_SUPER_PROPERTY: { __ push(eax); VisitForStackValue(prop->obj()->AsSuperReference()->this_var()); EmitLoadHomeObject(prop->obj()->AsSuperReference()); __ push(result_register()); VisitForAccumulatorValue(prop->key()); Register scratch = ecx; Register scratch2 = edx; __ mov(scratch2, MemOperand(esp, 2 * kPointerSize)); // value // stack: value, this, home_object; eax: key, edx: value __ mov(scratch, MemOperand(esp, kPointerSize)); // this __ mov(MemOperand(esp, 2 * kPointerSize), scratch); __ mov(scratch, MemOperand(esp, 0)); // home_object __ mov(MemOperand(esp, kPointerSize), scratch); __ mov(MemOperand(esp, 0), eax); __ mov(eax, scratch2); // stack: this, home_object, key; eax: value. EmitKeyedSuperPropertyStore(prop); break; } case KEYED_PROPERTY: { __ push(eax); // Preserve value. VisitForStackValue(prop->obj()); VisitForAccumulatorValue(prop->key()); __ Move(StoreDescriptor::NameRegister(), eax); __ pop(StoreDescriptor::ReceiverRegister()); // Receiver. __ pop(StoreDescriptor::ValueRegister()); // Restore value. Handle<Code> ic = CodeFactory::KeyedStoreIC(isolate(), language_mode()).code(); CallIC(ic); break; } } context()->Plug(eax); } void FullCodeGenerator::EmitStoreToStackLocalOrContextSlot( Variable* var, MemOperand location) { __ mov(location, eax); if (var->IsContextSlot()) { __ mov(edx, eax); int offset = Context::SlotOffset(var->index()); __ RecordWriteContextSlot(ecx, offset, edx, ebx, kDontSaveFPRegs); } } void FullCodeGenerator::EmitVariableAssignment(Variable* var, Token::Value op) { if (var->IsUnallocated()) { // Global var, const, or let. __ mov(StoreDescriptor::NameRegister(), var->name()); __ mov(StoreDescriptor::ReceiverRegister(), GlobalObjectOperand()); CallStoreIC(); } else if (var->mode() == LET && op != Token::INIT_LET) { // Non-initializing assignment to let variable needs a write barrier. DCHECK(!var->IsLookupSlot()); DCHECK(var->IsStackAllocated() || var->IsContextSlot()); Label assign; MemOperand location = VarOperand(var, ecx); __ mov(edx, location); __ cmp(edx, isolate()->factory()->the_hole_value()); __ j(not_equal, &assign, Label::kNear); __ push(Immediate(var->name())); __ CallRuntime(Runtime::kThrowReferenceError, 1); __ bind(&assign); EmitStoreToStackLocalOrContextSlot(var, location); } else if (var->mode() == CONST && op != Token::INIT_CONST) { // Assignment to const variable needs a write barrier. DCHECK(!var->IsLookupSlot()); DCHECK(var->IsStackAllocated() || var->IsContextSlot()); Label const_error; MemOperand location = VarOperand(var, ecx); __ mov(edx, location); __ cmp(edx, isolate()->factory()->the_hole_value()); __ j(not_equal, &const_error, Label::kNear); __ push(Immediate(var->name())); __ CallRuntime(Runtime::kThrowReferenceError, 1); __ bind(&const_error); __ CallRuntime(Runtime::kThrowConstAssignError, 0); } else if (!var->is_const_mode() || op == Token::INIT_CONST) { if (var->IsLookupSlot()) { // Assignment to var. __ push(eax); // Value. __ push(esi); // Context. __ push(Immediate(var->name())); __ push(Immediate(Smi::FromInt(language_mode()))); __ CallRuntime(Runtime::kStoreLookupSlot, 4); } else { // Assignment to var or initializing assignment to let/const in harmony // mode. DCHECK(var->IsStackAllocated() || var->IsContextSlot()); MemOperand location = VarOperand(var, ecx); if (generate_debug_code_ && op == Token::INIT_LET) { // Check for an uninitialized let binding. __ mov(edx, location); __ cmp(edx, isolate()->factory()->the_hole_value()); __ Check(equal, kLetBindingReInitialization); } EmitStoreToStackLocalOrContextSlot(var, location); } } else if (op == Token::INIT_CONST_LEGACY) { // Const initializers need a write barrier. DCHECK(var->mode() == CONST_LEGACY); DCHECK(!var->IsParameter()); // No const parameters. if (var->IsLookupSlot()) { __ push(eax); __ push(esi); __ push(Immediate(var->name())); __ CallRuntime(Runtime::kInitializeLegacyConstLookupSlot, 3); } else { DCHECK(var->IsStackLocal() || var->IsContextSlot()); Label skip; MemOperand location = VarOperand(var, ecx); __ mov(edx, location); __ cmp(edx, isolate()->factory()->the_hole_value()); __ j(not_equal, &skip, Label::kNear); EmitStoreToStackLocalOrContextSlot(var, location); __ bind(&skip); } } else { DCHECK(var->mode() == CONST_LEGACY && op != Token::INIT_CONST_LEGACY); if (is_strict(language_mode())) { __ CallRuntime(Runtime::kThrowConstAssignError, 0); } // Silently ignore store in sloppy mode. } } void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) { // Assignment to a property, using a named store IC. // eax : value // esp[0] : receiver Property* prop = expr->target()->AsProperty(); DCHECK(prop != NULL); DCHECK(prop->key()->IsLiteral()); // Record source code position before IC call. SetSourcePosition(expr->position()); __ mov(StoreDescriptor::NameRegister(), prop->key()->AsLiteral()->value()); __ pop(StoreDescriptor::ReceiverRegister()); CallStoreIC(expr->AssignmentFeedbackId()); PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); context()->Plug(eax); } void FullCodeGenerator::EmitNamedSuperPropertyStore(Property* prop) { // Assignment to named property of super. // eax : value // stack : receiver ('this'), home_object DCHECK(prop != NULL); Literal* key = prop->key()->AsLiteral(); DCHECK(key != NULL); __ push(Immediate(key->value())); __ push(eax); __ CallRuntime((is_strict(language_mode()) ? Runtime::kStoreToSuper_Strict : Runtime::kStoreToSuper_Sloppy), 4); } void FullCodeGenerator::EmitKeyedSuperPropertyStore(Property* prop) { // Assignment to named property of super. // eax : value // stack : receiver ('this'), home_object, key __ push(eax); __ CallRuntime( (is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict : Runtime::kStoreKeyedToSuper_Sloppy), 4); } void FullCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) { // Assignment to a property, using a keyed store IC. // eax : value // esp[0] : key // esp[kPointerSize] : receiver __ pop(StoreDescriptor::NameRegister()); // Key. __ pop(StoreDescriptor::ReceiverRegister()); DCHECK(StoreDescriptor::ValueRegister().is(eax)); // Record source code position before IC call. SetSourcePosition(expr->position()); Handle<Code> ic = CodeFactory::KeyedStoreIC(isolate(), language_mode()).code(); CallIC(ic, expr->AssignmentFeedbackId()); PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); context()->Plug(eax); } void FullCodeGenerator::VisitProperty(Property* expr) { Comment cmnt(masm_, "[ Property"); Expression* key = expr->key(); if (key->IsPropertyName()) { if (!expr->IsSuperAccess()) { VisitForAccumulatorValue(expr->obj()); __ Move(LoadDescriptor::ReceiverRegister(), result_register()); EmitNamedPropertyLoad(expr); } else { VisitForStackValue(expr->obj()->AsSuperReference()->this_var()); EmitLoadHomeObject(expr->obj()->AsSuperReference()); __ push(result_register()); EmitNamedSuperPropertyLoad(expr); } } else { if (!expr->IsSuperAccess()) { VisitForStackValue(expr->obj()); VisitForAccumulatorValue(expr->key()); __ pop(LoadDescriptor::ReceiverRegister()); // Object. __ Move(LoadDescriptor::NameRegister(), result_register()); // Key. EmitKeyedPropertyLoad(expr); } else { VisitForStackValue(expr->obj()->AsSuperReference()->this_var()); EmitLoadHomeObject(expr->obj()->AsSuperReference()); __ push(result_register()); VisitForStackValue(expr->key()); EmitKeyedSuperPropertyLoad(expr); } } PrepareForBailoutForId(expr->LoadId(), TOS_REG); context()->Plug(eax); } void FullCodeGenerator::CallIC(Handle<Code> code, TypeFeedbackId ast_id) { ic_total_count_++; __ call(code, RelocInfo::CODE_TARGET, ast_id); } // Code common for calls using the IC. void FullCodeGenerator::EmitCallWithLoadIC(Call* expr) { Expression* callee = expr->expression(); CallICState::CallType call_type = callee->IsVariableProxy() ? CallICState::FUNCTION : CallICState::METHOD; // Get the target function. if (call_type == CallICState::FUNCTION) { { StackValueContext context(this); EmitVariableLoad(callee->AsVariableProxy()); PrepareForBailout(callee, NO_REGISTERS); } // Push undefined as receiver. This is patched in the method prologue if it // is a sloppy mode method. __ push(Immediate(isolate()->factory()->undefined_value())); } else { // Load the function from the receiver. DCHECK(callee->IsProperty()); DCHECK(!callee->AsProperty()->IsSuperAccess()); __ mov(LoadDescriptor::ReceiverRegister(), Operand(esp, 0)); EmitNamedPropertyLoad(callee->AsProperty()); PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG); // Push the target function under the receiver. __ push(Operand(esp, 0)); __ mov(Operand(esp, kPointerSize), eax); } EmitCall(expr, call_type); } void FullCodeGenerator::EmitSuperCallWithLoadIC(Call* expr) { Expression* callee = expr->expression(); DCHECK(callee->IsProperty()); Property* prop = callee->AsProperty(); DCHECK(prop->IsSuperAccess()); SetSourcePosition(prop->position()); Literal* key = prop->key()->AsLiteral(); DCHECK(!key->value()->IsSmi()); // Load the function from the receiver. SuperReference* super_ref = callee->AsProperty()->obj()->AsSuperReference(); EmitLoadHomeObject(super_ref); __ push(eax); VisitForAccumulatorValue(super_ref->this_var()); __ push(eax); __ push(eax); __ push(Operand(esp, kPointerSize * 2)); __ push(Immediate(key->value())); // Stack here: // - home_object // - this (receiver) // - this (receiver) <-- LoadFromSuper will pop here and below. // - home_object // - key __ CallRuntime(Runtime::kLoadFromSuper, 3); // Replace home_object with target function. __ mov(Operand(esp, kPointerSize), eax); // Stack here: // - target function // - this (receiver) EmitCall(expr, CallICState::METHOD); } // Code common for calls using the IC. void FullCodeGenerator::EmitKeyedCallWithLoadIC(Call* expr, Expression* key) { // Load the key. VisitForAccumulatorValue(key); Expression* callee = expr->expression(); // Load the function from the receiver. DCHECK(callee->IsProperty()); __ mov(LoadDescriptor::ReceiverRegister(), Operand(esp, 0)); __ mov(LoadDescriptor::NameRegister(), eax); EmitKeyedPropertyLoad(callee->AsProperty()); PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG); // Push the target function under the receiver. __ push(Operand(esp, 0)); __ mov(Operand(esp, kPointerSize), eax); EmitCall(expr, CallICState::METHOD); } void FullCodeGenerator::EmitKeyedSuperCallWithLoadIC(Call* expr) { Expression* callee = expr->expression(); DCHECK(callee->IsProperty()); Property* prop = callee->AsProperty(); DCHECK(prop->IsSuperAccess()); SetSourcePosition(prop->position()); // Load the function from the receiver. SuperReference* super_ref = callee->AsProperty()->obj()->AsSuperReference(); EmitLoadHomeObject(super_ref); __ push(eax); VisitForAccumulatorValue(super_ref->this_var()); __ push(eax); __ push(eax); __ push(Operand(esp, kPointerSize * 2)); VisitForStackValue(prop->key()); // Stack here: // - home_object // - this (receiver) // - this (receiver) <-- LoadKeyedFromSuper will pop here and below. // - home_object // - key __ CallRuntime(Runtime::kLoadKeyedFromSuper, 3); // Replace home_object with target function. __ mov(Operand(esp, kPointerSize), eax); // Stack here: // - target function // - this (receiver) EmitCall(expr, CallICState::METHOD); } void FullCodeGenerator::EmitCall(Call* expr, CallICState::CallType call_type) { // Load the arguments. ZoneList<Expression*>* args = expr->arguments(); int arg_count = args->length(); { PreservePositionScope scope(masm()->positions_recorder()); for (int i = 0; i < arg_count; i++) { VisitForStackValue(args->at(i)); } } // Record source position of the IC call. SetSourcePosition(expr->position()); Handle<Code> ic = CodeFactory::CallIC(isolate(), arg_count, call_type).code(); __ Move(edx, Immediate(SmiFromSlot(expr->CallFeedbackICSlot()))); __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); // Don't assign a type feedback id to the IC, since type feedback is provided // by the vector above. CallIC(ic); RecordJSReturnSite(expr); // Restore context register. __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); context()->DropAndPlug(1, eax); } void FullCodeGenerator::EmitResolvePossiblyDirectEval(int arg_count) { // Push copy of the first argument or undefined if it doesn't exist. if (arg_count > 0) { __ push(Operand(esp, arg_count * kPointerSize)); } else { __ push(Immediate(isolate()->factory()->undefined_value())); } // Push the enclosing function. __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); // Push the receiver of the enclosing function. Variable* this_var = scope()->LookupThis(); DCHECK_NOT_NULL(this_var); __ push(VarOperand(this_var, ecx)); // Push the language mode. __ push(Immediate(Smi::FromInt(language_mode()))); // Push the start position of the scope the calls resides in. __ push(Immediate(Smi::FromInt(scope()->start_position()))); // Do the runtime call. __ CallRuntime(Runtime::kResolvePossiblyDirectEval, 6); } void FullCodeGenerator::EmitLoadSuperConstructor() { __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); __ CallRuntime(Runtime::kGetPrototype, 1); } void FullCodeGenerator::EmitInitializeThisAfterSuper( SuperReference* super_ref) { Variable* this_var = super_ref->this_var()->var(); GetVar(ecx, this_var); __ cmp(ecx, isolate()->factory()->the_hole_value()); Label uninitialized_this; __ j(equal, &uninitialized_this); __ push(Immediate(this_var->name())); __ CallRuntime(Runtime::kThrowReferenceError, 1); __ bind(&uninitialized_this); EmitVariableAssignment(this_var, Token::INIT_CONST); } void FullCodeGenerator::VisitCall(Call* expr) { #ifdef DEBUG // We want to verify that RecordJSReturnSite gets called on all paths // through this function. Avoid early returns. expr->return_is_recorded_ = false; #endif Comment cmnt(masm_, "[ Call"); Expression* callee = expr->expression(); Call::CallType call_type = expr->GetCallType(isolate()); if (call_type == Call::POSSIBLY_EVAL_CALL) { // In a call to eval, we first call RuntimeHidden_ResolvePossiblyDirectEval // to resolve the function we need to call and the receiver of the call. // Then we call the resolved function using the given arguments. ZoneList<Expression*>* args = expr->arguments(); int arg_count = args->length(); { PreservePositionScope pos_scope(masm()->positions_recorder()); VisitForStackValue(callee); // Reserved receiver slot. __ push(Immediate(isolate()->factory()->undefined_value())); // Push the arguments. for (int i = 0; i < arg_count; i++) { VisitForStackValue(args->at(i)); } // Push a copy of the function (found below the arguments) and // resolve eval. __ push(Operand(esp, (arg_count + 1) * kPointerSize)); EmitResolvePossiblyDirectEval(arg_count); // The runtime call returns a pair of values in eax (function) and // edx (receiver). Touch up the stack with the right values. __ mov(Operand(esp, (arg_count + 0) * kPointerSize), edx); __ mov(Operand(esp, (arg_count + 1) * kPointerSize), eax); PrepareForBailoutForId(expr->EvalOrLookupId(), NO_REGISTERS); } // Record source position for debugger. SetSourcePosition(expr->position()); CallFunctionStub stub(isolate(), arg_count, NO_CALL_FUNCTION_FLAGS); __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); __ CallStub(&stub); RecordJSReturnSite(expr); // Restore context register. __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); context()->DropAndPlug(1, eax); } else if (call_type == Call::GLOBAL_CALL) { EmitCallWithLoadIC(expr); } else if (call_type == Call::LOOKUP_SLOT_CALL) { // Call to a lookup slot (dynamically introduced variable). VariableProxy* proxy = callee->AsVariableProxy(); Label slow, done; { PreservePositionScope scope(masm()->positions_recorder()); // Generate code for loading from variables potentially shadowed by // eval-introduced variables. EmitDynamicLookupFastCase(proxy, NOT_INSIDE_TYPEOF, &slow, &done); } __ bind(&slow); // Call the runtime to find the function to call (returned in eax) and // the object holding it (returned in edx). __ push(context_register()); __ push(Immediate(proxy->name())); __ CallRuntime(Runtime::kLoadLookupSlot, 2); __ push(eax); // Function. __ push(edx); // Receiver. PrepareForBailoutForId(expr->EvalOrLookupId(), NO_REGISTERS); // If fast case code has been generated, emit code to push the function // and receiver and have the slow path jump around this code. if (done.is_linked()) { Label call; __ jmp(&call, Label::kNear); __ bind(&done); // Push function. __ push(eax); // The receiver is implicitly the global receiver. Indicate this by // passing the hole to the call function stub. __ push(Immediate(isolate()->factory()->undefined_value())); __ bind(&call); } // The receiver is either the global receiver or an object found by // LoadContextSlot. EmitCall(expr); } else if (call_type == Call::PROPERTY_CALL) { Property* property = callee->AsProperty(); bool is_named_call = property->key()->IsPropertyName(); if (property->IsSuperAccess()) { if (is_named_call) { EmitSuperCallWithLoadIC(expr); } else { EmitKeyedSuperCallWithLoadIC(expr); } } else { { PreservePositionScope scope(masm()->positions_recorder()); VisitForStackValue(property->obj()); } if (is_named_call) { EmitCallWithLoadIC(expr); } else { EmitKeyedCallWithLoadIC(expr, property->key()); } } } else if (call_type == Call::SUPER_CALL) { EmitSuperConstructorCall(expr); } else { DCHECK(call_type == Call::OTHER_CALL); // Call to an arbitrary expression not handled specially above. { PreservePositionScope scope(masm()->positions_recorder()); VisitForStackValue(callee); } __ push(Immediate(isolate()->factory()->undefined_value())); // Emit function call. EmitCall(expr); } #ifdef DEBUG // RecordJSReturnSite should have been called. DCHECK(expr->return_is_recorded_); #endif } void FullCodeGenerator::VisitCallNew(CallNew* expr) { Comment cmnt(masm_, "[ CallNew"); // According to ECMA-262, section 11.2.2, page 44, the function // expression in new calls must be evaluated before the // arguments. // Push constructor on the stack. If it's not a function it's used as // receiver for CALL_NON_FUNCTION, otherwise the value on the stack is // ignored. DCHECK(!expr->expression()->IsSuperReference()); VisitForStackValue(expr->expression()); // Push the arguments ("left-to-right") on the stack. ZoneList<Expression*>* args = expr->arguments(); int arg_count = args->length(); for (int i = 0; i < arg_count; i++) { VisitForStackValue(args->at(i)); } // Call the construct call builtin that handles allocation and // constructor invocation. SetSourcePosition(expr->position()); // Load function and argument count into edi and eax. __ Move(eax, Immediate(arg_count)); __ mov(edi, Operand(esp, arg_count * kPointerSize)); // Record call targets in unoptimized code. if (FLAG_pretenuring_call_new) { EnsureSlotContainsAllocationSite(expr->AllocationSiteFeedbackSlot()); DCHECK(expr->AllocationSiteFeedbackSlot().ToInt() == expr->CallNewFeedbackSlot().ToInt() + 1); } __ LoadHeapObject(ebx, FeedbackVector()); __ mov(edx, Immediate(SmiFromSlot(expr->CallNewFeedbackSlot()))); CallConstructStub stub(isolate(), RECORD_CONSTRUCTOR_TARGET); __ call(stub.GetCode(), RelocInfo::CONSTRUCT_CALL); PrepareForBailoutForId(expr->ReturnId(), TOS_REG); context()->Plug(eax); } void FullCodeGenerator::EmitSuperConstructorCall(Call* expr) { Variable* new_target_var = scope()->DeclarationScope()->new_target_var(); GetVar(eax, new_target_var); __ push(eax); EmitLoadSuperConstructor(); __ push(result_register()); // Push the arguments ("left-to-right") on the stack. ZoneList<Expression*>* args = expr->arguments(); int arg_count = args->length(); for (int i = 0; i < arg_count; i++) { VisitForStackValue(args->at(i)); } // Call the construct call builtin that handles allocation and // constructor invocation. SetSourcePosition(expr->position()); // Load function and argument count into edi and eax. __ Move(eax, Immediate(arg_count)); __ mov(edi, Operand(esp, arg_count * kPointerSize)); // Record call targets in unoptimized code. if (FLAG_pretenuring_call_new) { UNREACHABLE(); /* TODO(dslomov): support pretenuring. EnsureSlotContainsAllocationSite(expr->AllocationSiteFeedbackSlot()); DCHECK(expr->AllocationSiteFeedbackSlot().ToInt() == expr->CallNewFeedbackSlot().ToInt() + 1); */ } __ LoadHeapObject(ebx, FeedbackVector()); __ mov(edx, Immediate(SmiFromSlot(expr->CallFeedbackSlot()))); CallConstructStub stub(isolate(), SUPER_CALL_RECORD_TARGET); __ call(stub.GetCode(), RelocInfo::CONSTRUCT_CALL); __ Drop(1); RecordJSReturnSite(expr); EmitInitializeThisAfterSuper(expr->expression()->AsSuperReference()); context()->Plug(eax); } void FullCodeGenerator::EmitIsSmi(CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); DCHECK(args->length() == 1); VisitForAccumulatorValue(args->at(0)); Label materialize_true, materialize_false; Label* if_true = NULL; Label* if_false = NULL; Label* fall_through = NULL; context()->PrepareTest(&materialize_true, &materialize_false, &if_true, &if_false, &fall_through); PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); __ test(eax, Immediate(kSmiTagMask)); Split(zero, if_true, if_false, fall_through); context()->Plug(if_true, if_false); } void FullCodeGenerator::EmitIsNonNegativeSmi(CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); DCHECK(args->length() == 1); VisitForAccumulatorValue(args->at(0)); Label materialize_true, materialize_false; Label* if_true = NULL; Label* if_false = NULL; Label* fall_through = NULL; context()->PrepareTest(&materialize_true, &materialize_false, &if_true, &if_false, &fall_through); PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); __ test(eax, Immediate(kSmiTagMask | 0x80000000)); Split(zero, if_true, if_false, fall_through); context()->Plug(if_true, if_false); } void FullCodeGenerator::EmitIsObject(CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); DCHECK(args->length() == 1); VisitForAccumulatorValue(args->at(0)); Label materialize_true, materialize_false; Label* if_true = NULL; Label* if_false = NULL; Label* fall_through = NULL; context()->PrepareTest(&materialize_true, &materialize_false, &if_true, &if_false, &fall_through); __ JumpIfSmi(eax, if_false); __ cmp(eax, isolate()->factory()->null_value()); __ j(equal, if_true); __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); // Undetectable objects behave like undefined when tested with typeof. __ movzx_b(ecx, FieldOperand(ebx, Map::kBitFieldOffset)); __ test(ecx, Immediate(1 << Map::kIsUndetectable)); __ j(not_zero, if_false); __ movzx_b(ecx, FieldOperand(ebx, Map::kInstanceTypeOffset)); __ cmp(ecx, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE); __ j(below, if_false); __ cmp(ecx, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); Split(below_equal, if_true, if_false, fall_through); context()->Plug(if_true, if_false); } void FullCodeGenerator::EmitIsSpecObject(CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); DCHECK(args->length() == 1); VisitForAccumulatorValue(args->at(0)); Label materialize_true, materialize_false; Label* if_true = NULL; Label* if_false = NULL; Label* fall_through = NULL; context()->PrepareTest(&materialize_true, &materialize_false, &if_true, &if_false, &fall_through); __ JumpIfSmi(eax, if_false); __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ebx); PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); Split(above_equal, if_true, if_false, fall_through); context()->Plug(if_true, if_false); } void FullCodeGenerator::EmitIsUndetectableObject(CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); DCHECK(args->length() == 1); VisitForAccumulatorValue(args->at(0)); Label materialize_true, materialize_false; Label* if_true = NULL; Label* if_false = NULL; Label* fall_through = NULL; context()->PrepareTest(&materialize_true, &materialize_false, &if_true, &if_false, &fall_through); __ JumpIfSmi(eax, if_false); __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); __ movzx_b(ebx, FieldOperand(ebx, Map::kBitFieldOffset)); __ test(ebx, Immediate(1 << Map::kIsUndetectable)); PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); Split(not_zero, if_true, if_false, fall_through); context()->Plug(if_true, if_false); } void FullCodeGenerator::EmitIsStringWrapperSafeForDefaultValueOf( CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); DCHECK(args->length() == 1); VisitForAccumulatorValue(args->at(0)); Label materialize_true, materialize_false, skip_lookup; Label* if_true = NULL; Label* if_false = NULL; Label* fall_through = NULL; context()->PrepareTest(&materialize_true, &materialize_false, &if_true, &if_false, &fall_through); __ AssertNotSmi(eax); // Check whether this map has already been checked to be safe for default // valueOf. __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); __ test_b(FieldOperand(ebx, Map::kBitField2Offset), 1 << Map::kStringWrapperSafeForDefaultValueOf); __ j(not_zero, &skip_lookup); // Check for fast case object. Return false for slow case objects. __ mov(ecx, FieldOperand(eax, JSObject::kPropertiesOffset)); __ mov(ecx, FieldOperand(ecx, HeapObject::kMapOffset)); __ cmp(ecx, isolate()->factory()->hash_table_map()); __ j(equal, if_false); // Look for valueOf string in the descriptor array, and indicate false if // found. Since we omit an enumeration index check, if it is added via a // transition that shares its descriptor array, this is a false positive. Label entry, loop, done; // Skip loop if no descriptors are valid. __ NumberOfOwnDescriptors(ecx, ebx); __ cmp(ecx, 0); __ j(equal, &done); __ LoadInstanceDescriptors(ebx, ebx); // ebx: descriptor array. // ecx: valid entries in the descriptor array. // Calculate the end of the descriptor array. STATIC_ASSERT(kSmiTag == 0); STATIC_ASSERT(kSmiTagSize == 1); STATIC_ASSERT(kPointerSize == 4); __ imul(ecx, ecx, DescriptorArray::kDescriptorSize); __ lea(ecx, Operand(ebx, ecx, times_4, DescriptorArray::kFirstOffset)); // Calculate location of the first key name. __ add(ebx, Immediate(DescriptorArray::kFirstOffset)); // Loop through all the keys in the descriptor array. If one of these is the // internalized string "valueOf" the result is false. __ jmp(&entry); __ bind(&loop); __ mov(edx, FieldOperand(ebx, 0)); __ cmp(edx, isolate()->factory()->value_of_string()); __ j(equal, if_false); __ add(ebx, Immediate(DescriptorArray::kDescriptorSize * kPointerSize)); __ bind(&entry); __ cmp(ebx, ecx); __ j(not_equal, &loop); __ bind(&done); // Reload map as register ebx was used as temporary above. __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); // Set the bit in the map to indicate that there is no local valueOf field. __ or_(FieldOperand(ebx, Map::kBitField2Offset), Immediate(1 << Map::kStringWrapperSafeForDefaultValueOf)); __ bind(&skip_lookup); // If a valueOf property is not found on the object check that its // prototype is the un-modified String prototype. If not result is false. __ mov(ecx, FieldOperand(ebx, Map::kPrototypeOffset)); __ JumpIfSmi(ecx, if_false); __ mov(ecx, FieldOperand(ecx, HeapObject::kMapOffset)); __ mov(edx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); __ mov(edx, FieldOperand(edx, GlobalObject::kNativeContextOffset)); __ cmp(ecx, ContextOperand(edx, Context::STRING_FUNCTION_PROTOTYPE_MAP_INDEX)); PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); Split(equal, if_true, if_false, fall_through); context()->Plug(if_true, if_false); } void FullCodeGenerator::EmitIsFunction(CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); DCHECK(args->length() == 1); VisitForAccumulatorValue(args->at(0)); Label materialize_true, materialize_false; Label* if_true = NULL; Label* if_false = NULL; Label* fall_through = NULL; context()->PrepareTest(&materialize_true, &materialize_false, &if_true, &if_false, &fall_through); __ JumpIfSmi(eax, if_false); __ CmpObjectType(eax, JS_FUNCTION_TYPE, ebx); PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); Split(equal, if_true, if_false, fall_through); context()->Plug(if_true, if_false); } void FullCodeGenerator::EmitIsMinusZero(CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); DCHECK(args->length() == 1); VisitForAccumulatorValue(args->at(0)); Label materialize_true, materialize_false; Label* if_true = NULL; Label* if_false = NULL; Label* fall_through = NULL; context()->PrepareTest(&materialize_true, &materialize_false, &if_true, &if_false, &fall_through); Handle<Map> map = masm()->isolate()->factory()->heap_number_map(); __ CheckMap(eax, map, if_false, DO_SMI_CHECK); // Check if the exponent half is 0x80000000. Comparing against 1 and // checking for overflow is the shortest possible encoding. __ cmp(FieldOperand(eax, HeapNumber::kExponentOffset), Immediate(0x1)); __ j(no_overflow, if_false); __ cmp(FieldOperand(eax, HeapNumber::kMantissaOffset), Immediate(0x0)); PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); Split(equal, if_true, if_false, fall_through); context()->Plug(if_true, if_false); } void FullCodeGenerator::EmitIsArray(CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); DCHECK(args->length() == 1); VisitForAccumulatorValue(args->at(0)); Label materialize_true, materialize_false; Label* if_true = NULL; Label* if_false = NULL; Label* fall_through = NULL; context()->PrepareTest(&materialize_true, &materialize_false, &if_true, &if_false, &fall_through); __ JumpIfSmi(eax, if_false); __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); Split(equal, if_true, if_false, fall_through); context()->Plug(if_true, if_false); } void FullCodeGenerator::EmitIsRegExp(CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); DCHECK(args->length() == 1); VisitForAccumulatorValue(args->at(0)); Label materialize_true, materialize_false; Label* if_true = NULL; Label* if_false = NULL; Label* fall_through = NULL; context()->PrepareTest(&materialize_true, &materialize_false, &if_true, &if_false, &fall_through); __ JumpIfSmi(eax, if_false); __ CmpObjectType(eax, JS_REGEXP_TYPE, ebx); PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); Split(equal, if_true, if_false, fall_through); context()->Plug(if_true, if_false); } void FullCodeGenerator::EmitIsJSProxy(CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); DCHECK(args->length() == 1); VisitForAccumulatorValue(args->at(0)); Label materialize_true, materialize_false; Label* if_true = NULL; Label* if_false = NULL; Label* fall_through = NULL; context()->PrepareTest(&materialize_true, &materialize_false, &if_true, &if_false, &fall_through); __ JumpIfSmi(eax, if_false); Register map = ebx; __ mov(map, FieldOperand(eax, HeapObject::kMapOffset)); __ CmpInstanceType(map, FIRST_JS_PROXY_TYPE); __ j(less, if_false); __ CmpInstanceType(map, LAST_JS_PROXY_TYPE); PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); Split(less_equal, if_true, if_false, fall_through); context()->Plug(if_true, if_false); } void FullCodeGenerator::EmitIsConstructCall(CallRuntime* expr) { DCHECK(expr->arguments()->length() == 0); Label materialize_true, materialize_false; Label* if_true = NULL; Label* if_false = NULL; Label* fall_through = NULL; context()->PrepareTest(&materialize_true, &materialize_false, &if_true, &if_false, &fall_through); // Get the frame pointer for the calling frame. __ mov(eax, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); // Skip the arguments adaptor frame if it exists. Label check_frame_marker; __ cmp(Operand(eax, StandardFrameConstants::kContextOffset), Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); __ j(not_equal, &check_frame_marker); __ mov(eax, Operand(eax, StandardFrameConstants::kCallerFPOffset)); // Check the marker in the calling frame. __ bind(&check_frame_marker); __ cmp(Operand(eax, StandardFrameConstants::kMarkerOffset), Immediate(Smi::FromInt(StackFrame::CONSTRUCT))); PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); Split(equal, if_true, if_false, fall_through); context()->Plug(if_true, if_false); } void FullCodeGenerator::EmitObjectEquals(CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); DCHECK(args->length() == 2); // Load the two objects into registers and perform the comparison. VisitForStackValue(args->at(0)); VisitForAccumulatorValue(args->at(1)); Label materialize_true, materialize_false; Label* if_true = NULL; Label* if_false = NULL; Label* fall_through = NULL; context()->PrepareTest(&materialize_true, &materialize_false, &if_true, &if_false, &fall_through); __ pop(ebx); __ cmp(eax, ebx); PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); Split(equal, if_true, if_false, fall_through); context()->Plug(if_true, if_false); } void FullCodeGenerator::EmitArguments(CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); DCHECK(args->length() == 1); // ArgumentsAccessStub expects the key in edx and the formal // parameter count in eax. VisitForAccumulatorValue(args->at(0)); __ mov(edx, eax); __ Move(eax, Immediate(Smi::FromInt(info_->scope()->num_parameters()))); ArgumentsAccessStub stub(isolate(), ArgumentsAccessStub::READ_ELEMENT); __ CallStub(&stub); context()->Plug(eax); } void FullCodeGenerator::EmitArgumentsLength(CallRuntime* expr) { DCHECK(expr->arguments()->length() == 0); Label exit; // Get the number of formal parameters. __ Move(eax, Immediate(Smi::FromInt(info_->scope()->num_parameters()))); // Check if the calling frame is an arguments adaptor frame. __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); __ cmp(Operand(ebx, StandardFrameConstants::kContextOffset), Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); __ j(not_equal, &exit); // Arguments adaptor case: Read the arguments length from the // adaptor frame. __ mov(eax, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); __ bind(&exit); __ AssertSmi(eax); context()->Plug(eax); } void FullCodeGenerator::EmitClassOf(CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); DCHECK(args->length() == 1); Label done, null, function, non_function_constructor; VisitForAccumulatorValue(args->at(0)); // If the object is a smi, we return null. __ JumpIfSmi(eax, &null); // Check that the object is a JS object but take special care of JS // functions to make sure they have 'Function' as their class. // Assume that there are only two callable types, and one of them is at // either end of the type range for JS object types. Saves extra comparisons. STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, eax); // Map is now in eax. __ j(below, &null); STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE == FIRST_SPEC_OBJECT_TYPE + 1); __ j(equal, &function); __ CmpInstanceType(eax, LAST_SPEC_OBJECT_TYPE); STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == LAST_SPEC_OBJECT_TYPE - 1); __ j(equal, &function); // Assume that there is no larger type. STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == LAST_TYPE - 1); // Check if the constructor in the map is a JS function. __ GetMapConstructor(eax, eax, ebx); __ CmpInstanceType(ebx, JS_FUNCTION_TYPE); __ j(not_equal, &non_function_constructor); // eax now contains the constructor function. Grab the // instance class name from there. __ mov(eax, FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset)); __ mov(eax, FieldOperand(eax, SharedFunctionInfo::kInstanceClassNameOffset)); __ jmp(&done); // Functions have class 'Function'. __ bind(&function); __ mov(eax, isolate()->factory()->Function_string()); __ jmp(&done); // Objects with a non-function constructor have class 'Object'. __ bind(&non_function_constructor); __ mov(eax, isolate()->factory()->Object_string()); __ jmp(&done); // Non-JS objects have class null. __ bind(&null); __ mov(eax, isolate()->factory()->null_value()); // All done. __ bind(&done); context()->Plug(eax); } void FullCodeGenerator::EmitSubString(CallRuntime* expr) { // Load the arguments on the stack and call the stub. SubStringStub stub(isolate()); ZoneList<Expression*>* args = expr->arguments(); DCHECK(args->length() == 3); VisitForStackValue(args->at(0)); VisitForStackValue(args->at(1)); VisitForStackValue(args->at(2)); __ CallStub(&stub); context()->Plug(eax); } void FullCodeGenerator::EmitRegExpExec(CallRuntime* expr) { // Load the arguments on the stack and call the stub. RegExpExecStub stub(isolate()); ZoneList<Expression*>* args = expr->arguments(); DCHECK(args->length() == 4); VisitForStackValue(args->at(0)); VisitForStackValue(args->at(1)); VisitForStackValue(args->at(2)); VisitForStackValue(args->at(3)); __ CallStub(&stub); context()->Plug(eax); } void FullCodeGenerator::EmitValueOf(CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); DCHECK(args->length() == 1); VisitForAccumulatorValue(args->at(0)); // Load the object. Label done; // If the object is a smi return the object. __ JumpIfSmi(eax, &done, Label::kNear); // If the object is not a value type, return the object. __ CmpObjectType(eax, JS_VALUE_TYPE, ebx); __ j(not_equal, &done, Label::kNear); __ mov(eax, FieldOperand(eax, JSValue::kValueOffset)); __ bind(&done); context()->Plug(eax); } void FullCodeGenerator::EmitDateField(CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); DCHECK(args->length() == 2); DCHECK_NOT_NULL(args->at(1)->AsLiteral()); Smi* index = Smi::cast(*(args->at(1)->AsLiteral()->value())); VisitForAccumulatorValue(args->at(0)); // Load the object. Label runtime, done, not_date_object; Register object = eax; Register result = eax; Register scratch = ecx; __ JumpIfSmi(object, &not_date_object); __ CmpObjectType(object, JS_DATE_TYPE, scratch); __ j(not_equal, &not_date_object); if (index->value() == 0) { __ mov(result, FieldOperand(object, JSDate::kValueOffset)); __ jmp(&done); } else { if (index->value() < JSDate::kFirstUncachedField) { ExternalReference stamp = ExternalReference::date_cache_stamp(isolate()); __ mov(scratch, Operand::StaticVariable(stamp)); __ cmp(scratch, FieldOperand(object, JSDate::kCacheStampOffset)); __ j(not_equal, &runtime, Label::kNear); __ mov(result, FieldOperand(object, JSDate::kValueOffset + kPointerSize * index->value())); __ jmp(&done); } __ bind(&runtime); __ PrepareCallCFunction(2, scratch); __ mov(Operand(esp, 0), object); __ mov(Operand(esp, 1 * kPointerSize), Immediate(index)); __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2); __ jmp(&done); } __ bind(&not_date_object); __ CallRuntime(Runtime::kThrowNotDateError, 0); __ bind(&done); context()->Plug(result); } void FullCodeGenerator::EmitOneByteSeqStringSetChar(CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); DCHECK_EQ(3, args->length()); Register string = eax; Register index = ebx; Register value = ecx; VisitForStackValue(args->at(0)); // index VisitForStackValue(args->at(1)); // value VisitForAccumulatorValue(args->at(2)); // string __ pop(value); __ pop(index); if (FLAG_debug_code) { __ test(value, Immediate(kSmiTagMask)); __ Check(zero, kNonSmiValue); __ test(index, Immediate(kSmiTagMask)); __ Check(zero, kNonSmiValue); } __ SmiUntag(value); __ SmiUntag(index); if (FLAG_debug_code) { static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; __ EmitSeqStringSetCharCheck(string, index, value, one_byte_seq_type); } __ mov_b(FieldOperand(string, index, times_1, SeqOneByteString::kHeaderSize), value); context()->Plug(string); } void FullCodeGenerator::EmitTwoByteSeqStringSetChar(CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); DCHECK_EQ(3, args->length()); Register string = eax; Register index = ebx; Register value = ecx; VisitForStackValue(args->at(0)); // index VisitForStackValue(args->at(1)); // value VisitForAccumulatorValue(args->at(2)); // string __ pop(value); __ pop(index); if (FLAG_debug_code) { __ test(value, Immediate(kSmiTagMask)); __ Check(zero, kNonSmiValue); __ test(index, Immediate(kSmiTagMask)); __ Check(zero, kNonSmiValue); __ SmiUntag(index); static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; __ EmitSeqStringSetCharCheck(string, index, value, two_byte_seq_type); __ SmiTag(index); } __ SmiUntag(value); // No need to untag a smi for two-byte addressing. __ mov_w(FieldOperand(string, index, times_1, SeqTwoByteString::kHeaderSize), value); context()->Plug(string); } void FullCodeGenerator::EmitMathPow(CallRuntime* expr) { // Load the arguments on the stack and call the runtime function. ZoneList<Expression*>* args = expr->arguments(); DCHECK(args->length() == 2); VisitForStackValue(args->at(0)); VisitForStackValue(args->at(1)); __ CallRuntime(Runtime::kMathPowSlow, 2); context()->Plug(eax); } void FullCodeGenerator::EmitSetValueOf(CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); DCHECK(args->length() == 2); VisitForStackValue(args->at(0)); // Load the object. VisitForAccumulatorValue(args->at(1)); // Load the value. __ pop(ebx); // eax = value. ebx = object. Label done; // If the object is a smi, return the value. __ JumpIfSmi(ebx, &done, Label::kNear); // If the object is not a value type, return the value. __ CmpObjectType(ebx, JS_VALUE_TYPE, ecx); __ j(not_equal, &done, Label::kNear); // Store the value. __ mov(FieldOperand(ebx, JSValue::kValueOffset), eax); // Update the write barrier. Save the value as it will be // overwritten by the write barrier code and is needed afterward. __ mov(edx, eax); __ RecordWriteField(ebx, JSValue::kValueOffset, edx, ecx, kDontSaveFPRegs); __ bind(&done); context()->Plug(eax); } void FullCodeGenerator::EmitNumberToString(CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); DCHECK_EQ(args->length(), 1); // Load the argument into eax and call the stub. VisitForAccumulatorValue(args->at(0)); NumberToStringStub stub(isolate()); __ CallStub(&stub); context()->Plug(eax); } void FullCodeGenerator::EmitStringCharFromCode(CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); DCHECK(args->length() == 1); VisitForAccumulatorValue(args->at(0)); Label done; StringCharFromCodeGenerator generator(eax, ebx); generator.GenerateFast(masm_); __ jmp(&done); NopRuntimeCallHelper call_helper; generator.GenerateSlow(masm_, call_helper); __ bind(&done); context()->Plug(ebx); } void FullCodeGenerator::EmitStringCharCodeAt(CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); DCHECK(args->length() == 2); VisitForStackValue(args->at(0)); VisitForAccumulatorValue(args->at(1)); Register object = ebx; Register index = eax; Register result = edx; __ pop(object); Label need_conversion; Label index_out_of_range; Label done; StringCharCodeAtGenerator generator(object, index, result, &need_conversion, &need_conversion, &index_out_of_range, STRING_INDEX_IS_NUMBER); generator.GenerateFast(masm_); __ jmp(&done); __ bind(&index_out_of_range); // When the index is out of range, the spec requires us to return // NaN. __ Move(result, Immediate(isolate()->factory()->nan_value())); __ jmp(&done); __ bind(&need_conversion); // Move the undefined value into the result register, which will // trigger conversion. __ Move(result, Immediate(isolate()->factory()->undefined_value())); __ jmp(&done); NopRuntimeCallHelper call_helper; generator.GenerateSlow(masm_, NOT_PART_OF_IC_HANDLER, call_helper); __ bind(&done); context()->Plug(result); } void FullCodeGenerator::EmitStringCharAt(CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); DCHECK(args->length() == 2); VisitForStackValue(args->at(0)); VisitForAccumulatorValue(args->at(1)); Register object = ebx; Register index = eax; Register scratch = edx; Register result = eax; __ pop(object); Label need_conversion; Label index_out_of_range; Label done; StringCharAtGenerator generator(object, index, scratch, result, &need_conversion, &need_conversion, &index_out_of_range, STRING_INDEX_IS_NUMBER); generator.GenerateFast(masm_); __ jmp(&done); __ bind(&index_out_of_range); // When the index is out of range, the spec requires us to return // the empty string. __ Move(result, Immediate(isolate()->factory()->empty_string())); __ jmp(&done); __ bind(&need_conversion); // Move smi zero into the result register, which will trigger // conversion. __ Move(result, Immediate(Smi::FromInt(0))); __ jmp(&done); NopRuntimeCallHelper call_helper; generator.GenerateSlow(masm_, NOT_PART_OF_IC_HANDLER, call_helper); __ bind(&done); context()->Plug(result); } void FullCodeGenerator::EmitStringAdd(CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); DCHECK_EQ(2, args->length()); VisitForStackValue(args->at(0)); VisitForAccumulatorValue(args->at(1)); __ pop(edx); StringAddStub stub(isolate(), STRING_ADD_CHECK_BOTH, NOT_TENURED); __ CallStub(&stub); context()->Plug(eax); } void FullCodeGenerator::EmitStringCompare(CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); DCHECK_EQ(2, args->length()); VisitForStackValue(args->at(0)); VisitForStackValue(args->at(1)); StringCompareStub stub(isolate()); __ CallStub(&stub); context()->Plug(eax); } void FullCodeGenerator::EmitCallFunction(CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); DCHECK(args->length() >= 2); int arg_count = args->length() - 2; // 2 ~ receiver and function. for (int i = 0; i < arg_count + 1; ++i) { VisitForStackValue(args->at(i)); } VisitForAccumulatorValue(args->last()); // Function. Label runtime, done; // Check for non-function argument (including proxy). __ JumpIfSmi(eax, &runtime); __ CmpObjectType(eax, JS_FUNCTION_TYPE, ebx); __ j(not_equal, &runtime); // InvokeFunction requires the function in edi. Move it in there. __ mov(edi, result_register()); ParameterCount count(arg_count); __ InvokeFunction(edi, count, CALL_FUNCTION, NullCallWrapper()); __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); __ jmp(&done); __ bind(&runtime); __ push(eax); __ CallRuntime(Runtime::kCall, args->length()); __ bind(&done); context()->Plug(eax); } void FullCodeGenerator::EmitDefaultConstructorCallSuper(CallRuntime* expr) { Variable* new_target_var = scope()->DeclarationScope()->new_target_var(); GetVar(eax, new_target_var); __ push(eax); EmitLoadSuperConstructor(); __ push(result_register()); // Check if the calling frame is an arguments adaptor frame. Label adaptor_frame, args_set_up, runtime; __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); __ j(equal, &adaptor_frame); // default constructor has no arguments, so no adaptor frame means no args. __ mov(eax, Immediate(0)); __ jmp(&args_set_up); // Copy arguments from adaptor frame. { __ bind(&adaptor_frame); __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); __ SmiUntag(ecx); // Subtract 1 from arguments count, for new.target. __ sub(ecx, Immediate(1)); __ mov(eax, ecx); __ lea(edx, Operand(edx, ecx, times_pointer_size, StandardFrameConstants::kCallerSPOffset)); Label loop; __ bind(&loop); __ push(Operand(edx, -1 * kPointerSize)); __ sub(edx, Immediate(kPointerSize)); __ dec(ecx); __ j(not_zero, &loop); } __ bind(&args_set_up); __ mov(edi, Operand(esp, eax, times_pointer_size, 0)); __ mov(ebx, Immediate(isolate()->factory()->undefined_value())); CallConstructStub stub(isolate(), SUPER_CONSTRUCTOR_CALL); __ call(stub.GetCode(), RelocInfo::CONSTRUCT_CALL); __ Drop(1); context()->Plug(eax); } void FullCodeGenerator::EmitRegExpConstructResult(CallRuntime* expr) { // Load the arguments on the stack and call the stub. RegExpConstructResultStub stub(isolate()); ZoneList<Expression*>* args = expr->arguments(); DCHECK(args->length() == 3); VisitForStackValue(args->at(0)); VisitForStackValue(args->at(1)); VisitForAccumulatorValue(args->at(2)); __ pop(ebx); __ pop(ecx); __ CallStub(&stub); context()->Plug(eax); } void FullCodeGenerator::EmitGetFromCache(CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); DCHECK_EQ(2, args->length()); DCHECK_NOT_NULL(args->at(0)->AsLiteral()); int cache_id = Smi::cast(*(args->at(0)->AsLiteral()->value()))->value(); Handle<FixedArray> jsfunction_result_caches( isolate()->native_context()->jsfunction_result_caches()); if (jsfunction_result_caches->length() <= cache_id) { __ Abort(kAttemptToUseUndefinedCache); __ mov(eax, isolate()->factory()->undefined_value()); context()->Plug(eax); return; } VisitForAccumulatorValue(args->at(1)); Register key = eax; Register cache = ebx; Register tmp = ecx; __ mov(cache, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); __ mov(cache, FieldOperand(cache, GlobalObject::kNativeContextOffset)); __ mov(cache, ContextOperand(cache, Context::JSFUNCTION_RESULT_CACHES_INDEX)); __ mov(cache, FieldOperand(cache, FixedArray::OffsetOfElementAt(cache_id))); Label done, not_found; STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); __ mov(tmp, FieldOperand(cache, JSFunctionResultCache::kFingerOffset)); // tmp now holds finger offset as a smi. __ cmp(key, FixedArrayElementOperand(cache, tmp)); __ j(not_equal, &not_found); __ mov(eax, FixedArrayElementOperand(cache, tmp, 1)); __ jmp(&done); __ bind(&not_found); // Call runtime to perform the lookup. __ push(cache); __ push(key); __ CallRuntime(Runtime::kGetFromCacheRT, 2); __ bind(&done); context()->Plug(eax); } void FullCodeGenerator::EmitHasCachedArrayIndex(CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); DCHECK(args->length() == 1); VisitForAccumulatorValue(args->at(0)); __ AssertString(eax); Label materialize_true, materialize_false; Label* if_true = NULL; Label* if_false = NULL; Label* fall_through = NULL; context()->PrepareTest(&materialize_true, &materialize_false, &if_true, &if_false, &fall_through); __ test(FieldOperand(eax, String::kHashFieldOffset), Immediate(String::kContainsCachedArrayIndexMask)); PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); Split(zero, if_true, if_false, fall_through); context()->Plug(if_true, if_false); } void FullCodeGenerator::EmitGetCachedArrayIndex(CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); DCHECK(args->length() == 1); VisitForAccumulatorValue(args->at(0)); __ AssertString(eax); __ mov(eax, FieldOperand(eax, String::kHashFieldOffset)); __ IndexFromHash(eax, eax); context()->Plug(eax); } void FullCodeGenerator::EmitFastOneByteArrayJoin(CallRuntime* expr) { Label bailout, done, one_char_separator, long_separator, non_trivial_array, not_size_one_array, loop, loop_1, loop_1_condition, loop_2, loop_2_entry, loop_3, loop_3_entry; ZoneList<Expression*>* args = expr->arguments(); DCHECK(args->length() == 2); // We will leave the separator on the stack until the end of the function. VisitForStackValue(args->at(1)); // Load this to eax (= array) VisitForAccumulatorValue(args->at(0)); // All aliases of the same register have disjoint lifetimes. Register array = eax; Register elements = no_reg; // Will be eax. Register index = edx; Register string_length = ecx; Register string = esi; Register scratch = ebx; Register array_length = edi; Register result_pos = no_reg; // Will be edi. // Separator operand is already pushed. Operand separator_operand = Operand(esp, 2 * kPointerSize); Operand result_operand = Operand(esp, 1 * kPointerSize); Operand array_length_operand = Operand(esp, 0); __ sub(esp, Immediate(2 * kPointerSize)); __ cld(); // Check that the array is a JSArray __ JumpIfSmi(array, &bailout); __ CmpObjectType(array, JS_ARRAY_TYPE, scratch); __ j(not_equal, &bailout); // Check that the array has fast elements. __ CheckFastElements(scratch, &bailout); // If the array has length zero, return the empty string. __ mov(array_length, FieldOperand(array, JSArray::kLengthOffset)); __ SmiUntag(array_length); __ j(not_zero, &non_trivial_array); __ mov(result_operand, isolate()->factory()->empty_string()); __ jmp(&done); // Save the array length. __ bind(&non_trivial_array); __ mov(array_length_operand, array_length); // Save the FixedArray containing array's elements. // End of array's live range. elements = array; __ mov(elements, FieldOperand(array, JSArray::kElementsOffset)); array = no_reg; // Check that all array elements are sequential one-byte strings, and // accumulate the sum of their lengths, as a smi-encoded value. __ Move(index, Immediate(0)); __ Move(string_length, Immediate(0)); // Loop condition: while (index < length). // Live loop registers: index, array_length, string, // scratch, string_length, elements. if (generate_debug_code_) { __ cmp(index, array_length); __ Assert(less, kNoEmptyArraysHereInEmitFastOneByteArrayJoin); } __ bind(&loop); __ mov(string, FieldOperand(elements, index, times_pointer_size, FixedArray::kHeaderSize)); __ JumpIfSmi(string, &bailout); __ mov(scratch, FieldOperand(string, HeapObject::kMapOffset)); __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); __ and_(scratch, Immediate( kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask)); __ cmp(scratch, kStringTag | kOneByteStringTag | kSeqStringTag); __ j(not_equal, &bailout); __ add(string_length, FieldOperand(string, SeqOneByteString::kLengthOffset)); __ j(overflow, &bailout); __ add(index, Immediate(1)); __ cmp(index, array_length); __ j(less, &loop); // If array_length is 1, return elements[0], a string. __ cmp(array_length, 1); __ j(not_equal, &not_size_one_array); __ mov(scratch, FieldOperand(elements, FixedArray::kHeaderSize)); __ mov(result_operand, scratch); __ jmp(&done); __ bind(&not_size_one_array); // End of array_length live range. result_pos = array_length; array_length = no_reg; // Live registers: // string_length: Sum of string lengths, as a smi. // elements: FixedArray of strings. // Check that the separator is a flat one-byte string. __ mov(string, separator_operand); __ JumpIfSmi(string, &bailout); __ mov(scratch, FieldOperand(string, HeapObject::kMapOffset)); __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); __ and_(scratch, Immediate( kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask)); __ cmp(scratch, kStringTag | kOneByteStringTag | kSeqStringTag); __ j(not_equal, &bailout); // Add (separator length times array_length) - separator length // to string_length. __ mov(scratch, separator_operand); __ mov(scratch, FieldOperand(scratch, SeqOneByteString::kLengthOffset)); __ sub(string_length, scratch); // May be negative, temporarily. __ imul(scratch, array_length_operand); __ j(overflow, &bailout); __ add(string_length, scratch); __ j(overflow, &bailout); __ shr(string_length, 1); // Live registers and stack values: // string_length // elements __ AllocateOneByteString(result_pos, string_length, scratch, index, string, &bailout); __ mov(result_operand, result_pos); __ lea(result_pos, FieldOperand(result_pos, SeqOneByteString::kHeaderSize)); __ mov(string, separator_operand); __ cmp(FieldOperand(string, SeqOneByteString::kLengthOffset), Immediate(Smi::FromInt(1))); __ j(equal, &one_char_separator); __ j(greater, &long_separator); // Empty separator case __ mov(index, Immediate(0)); __ jmp(&loop_1_condition); // Loop condition: while (index < length). __ bind(&loop_1); // Each iteration of the loop concatenates one string to the result. // Live values in registers: // index: which element of the elements array we are adding to the result. // result_pos: the position to which we are currently copying characters. // elements: the FixedArray of strings we are joining. // Get string = array[index]. __ mov(string, FieldOperand(elements, index, times_pointer_size, FixedArray::kHeaderSize)); __ mov(string_length, FieldOperand(string, String::kLengthOffset)); __ shr(string_length, 1); __ lea(string, FieldOperand(string, SeqOneByteString::kHeaderSize)); __ CopyBytes(string, result_pos, string_length, scratch); __ add(index, Immediate(1)); __ bind(&loop_1_condition); __ cmp(index, array_length_operand); __ j(less, &loop_1); // End while (index < length). __ jmp(&done); // One-character separator case __ bind(&one_char_separator); // Replace separator with its one-byte character value. __ mov_b(scratch, FieldOperand(string, SeqOneByteString::kHeaderSize)); __ mov_b(separator_operand, scratch); __ Move(index, Immediate(0)); // Jump into the loop after the code that copies the separator, so the first // element is not preceded by a separator __ jmp(&loop_2_entry); // Loop condition: while (index < length). __ bind(&loop_2); // Each iteration of the loop concatenates one string to the result. // Live values in registers: // index: which element of the elements array we are adding to the result. // result_pos: the position to which we are currently copying characters. // Copy the separator character to the result. __ mov_b(scratch, separator_operand); __ mov_b(Operand(result_pos, 0), scratch); __ inc(result_pos); __ bind(&loop_2_entry); // Get string = array[index]. __ mov(string, FieldOperand(elements, index, times_pointer_size, FixedArray::kHeaderSize)); __ mov(string_length, FieldOperand(string, String::kLengthOffset)); __ shr(string_length, 1); __ lea(string, FieldOperand(string, SeqOneByteString::kHeaderSize)); __ CopyBytes(string, result_pos, string_length, scratch); __ add(index, Immediate(1)); __ cmp(index, array_length_operand); __ j(less, &loop_2); // End while (index < length). __ jmp(&done); // Long separator case (separator is more than one character). __ bind(&long_separator); __ Move(index, Immediate(0)); // Jump into the loop after the code that copies the separator, so the first // element is not preceded by a separator __ jmp(&loop_3_entry); // Loop condition: while (index < length). __ bind(&loop_3); // Each iteration of the loop concatenates one string to the result. // Live values in registers: // index: which element of the elements array we are adding to the result. // result_pos: the position to which we are currently copying characters. // Copy the separator to the result. __ mov(string, separator_operand); __ mov(string_length, FieldOperand(string, String::kLengthOffset)); __ shr(string_length, 1); __ lea(string, FieldOperand(string, SeqOneByteString::kHeaderSize)); __ CopyBytes(string, result_pos, string_length, scratch); __ bind(&loop_3_entry); // Get string = array[index]. __ mov(string, FieldOperand(elements, index, times_pointer_size, FixedArray::kHeaderSize)); __ mov(string_length, FieldOperand(string, String::kLengthOffset)); __ shr(string_length, 1); __ lea(string, FieldOperand(string, SeqOneByteString::kHeaderSize)); __ CopyBytes(string, result_pos, string_length, scratch); __ add(index, Immediate(1)); __ cmp(index, array_length_operand); __ j(less, &loop_3); // End while (index < length). __ jmp(&done); __ bind(&bailout); __ mov(result_operand, isolate()->factory()->undefined_value()); __ bind(&done); __ mov(eax, result_operand); // Drop temp values from the stack, and restore context register. __ add(esp, Immediate(3 * kPointerSize)); __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); context()->Plug(eax); } void FullCodeGenerator::EmitDebugIsActive(CallRuntime* expr) { DCHECK(expr->arguments()->length() == 0); ExternalReference debug_is_active = ExternalReference::debug_is_active_address(isolate()); __ movzx_b(eax, Operand::StaticVariable(debug_is_active)); __ SmiTag(eax); context()->Plug(eax); } void FullCodeGenerator::EmitCallSuperWithSpread(CallRuntime* expr) { // Assert: expr == CallRuntime("ReflectConstruct") CallRuntime* call = expr->arguments()->at(0)->AsCallRuntime(); ZoneList<Expression*>* args = call->arguments(); DCHECK_EQ(3, args->length()); SuperReference* super_reference = args->at(0)->AsSuperReference(); // Load ReflectConstruct function EmitLoadJSRuntimeFunction(call); // Push the target function under the receiver __ push(Operand(esp, 0)); __ mov(Operand(esp, kPointerSize), eax); // Push super EmitLoadSuperConstructor(); __ Push(result_register()); // Push arguments array VisitForStackValue(args->at(1)); // Push NewTarget DCHECK(args->at(2)->IsVariableProxy()); VisitForStackValue(args->at(2)); EmitCallJSRuntimeFunction(call); // Restore context register. __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); context()->DropAndPlug(1, eax); EmitInitializeThisAfterSuper(super_reference); } void FullCodeGenerator::EmitLoadJSRuntimeFunction(CallRuntime* expr) { // Push the builtins object as receiver. __ mov(eax, GlobalObjectOperand()); __ push(FieldOperand(eax, GlobalObject::kBuiltinsOffset)); // Load the function from the receiver. __ mov(LoadDescriptor::ReceiverRegister(), Operand(esp, 0)); __ mov(LoadDescriptor::NameRegister(), Immediate(expr->name())); __ mov(LoadDescriptor::SlotRegister(), Immediate(SmiFromSlot(expr->CallRuntimeFeedbackSlot()))); CallLoadIC(NOT_CONTEXTUAL); } void FullCodeGenerator::EmitCallJSRuntimeFunction(CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); int arg_count = args->length(); // Record source position of the IC call. SetSourcePosition(expr->position()); CallFunctionStub stub(isolate(), arg_count, NO_CALL_FUNCTION_FLAGS); __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); __ CallStub(&stub); } void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) { ZoneList<Expression*>* args = expr->arguments(); int arg_count = args->length(); if (expr->is_jsruntime()) { Comment cmnt(masm_, "[ CallRuntime"); EmitLoadJSRuntimeFunction(expr); // Push the target function under the receiver. __ push(Operand(esp, 0)); __ mov(Operand(esp, kPointerSize), eax); // Push the arguments ("left-to-right"). for (int i = 0; i < arg_count; i++) { VisitForStackValue(args->at(i)); } EmitCallJSRuntimeFunction(expr); // Restore context register. __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); context()->DropAndPlug(1, eax); } else { const Runtime::Function* function = expr->function(); switch (function->function_id) { #define CALL_INTRINSIC_GENERATOR(Name) \ case Runtime::kInline##Name: { \ Comment cmnt(masm_, "[ Inline" #Name); \ return Emit##Name(expr); \ } FOR_EACH_FULL_CODE_INTRINSIC(CALL_INTRINSIC_GENERATOR) #undef CALL_INTRINSIC_GENERATOR default: { Comment cmnt(masm_, "[ CallRuntime for unhandled intrinsic"); // Push the arguments ("left-to-right"). for (int i = 0; i < arg_count; i++) { VisitForStackValue(args->at(i)); } // Call the C runtime function. __ CallRuntime(expr->function(), arg_count); context()->Plug(eax); } } } } void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) { switch (expr->op()) { case Token::DELETE: { Comment cmnt(masm_, "[ UnaryOperation (DELETE)"); Property* property = expr->expression()->AsProperty(); VariableProxy* proxy = expr->expression()->AsVariableProxy(); if (property != NULL) { VisitForStackValue(property->obj()); VisitForStackValue(property->key()); __ push(Immediate(Smi::FromInt(language_mode()))); __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION); context()->Plug(eax); } else if (proxy != NULL) { Variable* var = proxy->var(); // Delete of an unqualified identifier is disallowed in strict mode // but "delete this" is allowed. DCHECK(is_sloppy(language_mode()) || var->is_this()); if (var->IsUnallocated()) { __ push(GlobalObjectOperand()); __ push(Immediate(var->name())); __ push(Immediate(Smi::FromInt(SLOPPY))); __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION); context()->Plug(eax); } else if (var->IsStackAllocated() || var->IsContextSlot()) { // Result of deleting non-global variables is false. 'this' is // not really a variable, though we implement it as one. The // subexpression does not have side effects. context()->Plug(var->is_this()); } else { // Non-global variable. Call the runtime to try to delete from the // context where the variable was introduced. __ push(context_register()); __ push(Immediate(var->name())); __ CallRuntime(Runtime::kDeleteLookupSlot, 2); context()->Plug(eax); } } else { // Result of deleting non-property, non-variable reference is true. // The subexpression may have side effects. VisitForEffect(expr->expression()); context()->Plug(true); } break; } case Token::VOID: { Comment cmnt(masm_, "[ UnaryOperation (VOID)"); VisitForEffect(expr->expression()); context()->Plug(isolate()->factory()->undefined_value()); break; } case Token::NOT: { Comment cmnt(masm_, "[ UnaryOperation (NOT)"); if (context()->IsEffect()) { // Unary NOT has no side effects so it's only necessary to visit the // subexpression. Match the optimizing compiler by not branching. VisitForEffect(expr->expression()); } else if (context()->IsTest()) { const TestContext* test = TestContext::cast(context()); // The labels are swapped for the recursive call. VisitForControl(expr->expression(), test->false_label(), test->true_label(), test->fall_through()); context()->Plug(test->true_label(), test->false_label()); } else { // We handle value contexts explicitly rather than simply visiting // for control and plugging the control flow into the context, // because we need to prepare a pair of extra administrative AST ids // for the optimizing compiler. DCHECK(context()->IsAccumulatorValue() || context()->IsStackValue()); Label materialize_true, materialize_false, done; VisitForControl(expr->expression(), &materialize_false, &materialize_true, &materialize_true); __ bind(&materialize_true); PrepareForBailoutForId(expr->MaterializeTrueId(), NO_REGISTERS); if (context()->IsAccumulatorValue()) { __ mov(eax, isolate()->factory()->true_value()); } else { __ Push(isolate()->factory()->true_value()); } __ jmp(&done, Label::kNear); __ bind(&materialize_false); PrepareForBailoutForId(expr->MaterializeFalseId(), NO_REGISTERS); if (context()->IsAccumulatorValue()) { __ mov(eax, isolate()->factory()->false_value()); } else { __ Push(isolate()->factory()->false_value()); } __ bind(&done); } break; } case Token::TYPEOF: { Comment cmnt(masm_, "[ UnaryOperation (TYPEOF)"); { AccumulatorValueContext context(this); VisitForTypeofValue(expr->expression()); } __ mov(ebx, eax); TypeofStub typeof_stub(isolate()); __ CallStub(&typeof_stub); context()->Plug(eax); break; } default: UNREACHABLE(); } } void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { DCHECK(expr->expression()->IsValidReferenceExpression()); Comment cmnt(masm_, "[ CountOperation"); SetSourcePosition(expr->position()); Property* prop = expr->expression()->AsProperty(); LhsKind assign_type = GetAssignType(prop); // Evaluate expression and get value. if (assign_type == VARIABLE) { DCHECK(expr->expression()->AsVariableProxy()->var() != NULL); AccumulatorValueContext context(this); EmitVariableLoad(expr->expression()->AsVariableProxy()); } else { // Reserve space for result of postfix operation. if (expr->is_postfix() && !context()->IsEffect()) { __ push(Immediate(Smi::FromInt(0))); } switch (assign_type) { case NAMED_PROPERTY: { // Put the object both on the stack and in the register. VisitForStackValue(prop->obj()); __ mov(LoadDescriptor::ReceiverRegister(), Operand(esp, 0)); EmitNamedPropertyLoad(prop); break; } case NAMED_SUPER_PROPERTY: { VisitForStackValue(prop->obj()->AsSuperReference()->this_var()); EmitLoadHomeObject(prop->obj()->AsSuperReference()); __ push(result_register()); __ push(MemOperand(esp, kPointerSize)); __ push(result_register()); EmitNamedSuperPropertyLoad(prop); break; } case KEYED_SUPER_PROPERTY: { VisitForStackValue(prop->obj()->AsSuperReference()->this_var()); EmitLoadHomeObject(prop->obj()->AsSuperReference()); __ push(result_register()); VisitForAccumulatorValue(prop->key()); __ push(result_register()); __ push(MemOperand(esp, 2 * kPointerSize)); __ push(MemOperand(esp, 2 * kPointerSize)); __ push(result_register()); EmitKeyedSuperPropertyLoad(prop); break; } case KEYED_PROPERTY: { VisitForStackValue(prop->obj()); VisitForStackValue(prop->key()); __ mov(LoadDescriptor::ReceiverRegister(), Operand(esp, kPointerSize)); // Object. __ mov(LoadDescriptor::NameRegister(), Operand(esp, 0)); // Key. EmitKeyedPropertyLoad(prop); break; } case VARIABLE: UNREACHABLE(); } } // We need a second deoptimization point after loading the value // in case evaluating the property load my have a side effect. if (assign_type == VARIABLE) { PrepareForBailout(expr->expression(), TOS_REG); } else { PrepareForBailoutForId(prop->LoadId(), TOS_REG); } // Inline smi case if we are in a loop. Label done, stub_call; JumpPatchSite patch_site(masm_); if (ShouldInlineSmiCase(expr->op())) { Label slow; patch_site.EmitJumpIfNotSmi(eax, &slow, Label::kNear); // Save result for postfix expressions. if (expr->is_postfix()) { if (!context()->IsEffect()) { // Save the result on the stack. If we have a named or keyed property // we store the result under the receiver that is currently on top // of the stack. switch (assign_type) { case VARIABLE: __ push(eax); break; case NAMED_PROPERTY: __ mov(Operand(esp, kPointerSize), eax); break; case NAMED_SUPER_PROPERTY: __ mov(Operand(esp, 2 * kPointerSize), eax); break; case KEYED_PROPERTY: __ mov(Operand(esp, 2 * kPointerSize), eax); break; case KEYED_SUPER_PROPERTY: __ mov(Operand(esp, 3 * kPointerSize), eax); break; } } } if (expr->op() == Token::INC) { __ add(eax, Immediate(Smi::FromInt(1))); } else { __ sub(eax, Immediate(Smi::FromInt(1))); } __ j(no_overflow, &done, Label::kNear); // Call stub. Undo operation first. if (expr->op() == Token::INC) { __ sub(eax, Immediate(Smi::FromInt(1))); } else { __ add(eax, Immediate(Smi::FromInt(1))); } __ jmp(&stub_call, Label::kNear); __ bind(&slow); } ToNumberStub convert_stub(isolate()); __ CallStub(&convert_stub); PrepareForBailoutForId(expr->ToNumberId(), TOS_REG); // Save result for postfix expressions. if (expr->is_postfix()) { if (!context()->IsEffect()) { // Save the result on the stack. If we have a named or keyed property // we store the result under the receiver that is currently on top // of the stack. switch (assign_type) { case VARIABLE: __ push(eax); break; case NAMED_PROPERTY: __ mov(Operand(esp, kPointerSize), eax); break; case NAMED_SUPER_PROPERTY: __ mov(Operand(esp, 2 * kPointerSize), eax); break; case KEYED_PROPERTY: __ mov(Operand(esp, 2 * kPointerSize), eax); break; case KEYED_SUPER_PROPERTY: __ mov(Operand(esp, 3 * kPointerSize), eax); break; } } } // Record position before stub call. SetSourcePosition(expr->position()); // Call stub for +1/-1. __ bind(&stub_call); __ mov(edx, eax); __ mov(eax, Immediate(Smi::FromInt(1))); Handle<Code> code = CodeFactory::BinaryOpIC( isolate(), expr->binary_op(), language_mode()).code(); CallIC(code, expr->CountBinOpFeedbackId()); patch_site.EmitPatchInfo(); __ bind(&done); // Store the value returned in eax. switch (assign_type) { case VARIABLE: if (expr->is_postfix()) { // Perform the assignment as if via '='. { EffectContext context(this); EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), Token::ASSIGN); PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); context.Plug(eax); } // For all contexts except EffectContext We have the result on // top of the stack. if (!context()->IsEffect()) { context()->PlugTOS(); } } else { // Perform the assignment as if via '='. EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), Token::ASSIGN); PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); context()->Plug(eax); } break; case NAMED_PROPERTY: { __ mov(StoreDescriptor::NameRegister(), prop->key()->AsLiteral()->value()); __ pop(StoreDescriptor::ReceiverRegister()); CallStoreIC(expr->CountStoreFeedbackId()); PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); if (expr->is_postfix()) { if (!context()->IsEffect()) { context()->PlugTOS(); } } else { context()->Plug(eax); } break; } case NAMED_SUPER_PROPERTY: { EmitNamedSuperPropertyStore(prop); if (expr->is_postfix()) { if (!context()->IsEffect()) { context()->PlugTOS(); } } else { context()->Plug(eax); } break; } case KEYED_SUPER_PROPERTY: { EmitKeyedSuperPropertyStore(prop); if (expr->is_postfix()) { if (!context()->IsEffect()) { context()->PlugTOS(); } } else { context()->Plug(eax); } break; } case KEYED_PROPERTY: { __ pop(StoreDescriptor::NameRegister()); __ pop(StoreDescriptor::ReceiverRegister()); Handle<Code> ic = CodeFactory::KeyedStoreIC(isolate(), language_mode()).code(); CallIC(ic, expr->CountStoreFeedbackId()); PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); if (expr->is_postfix()) { // Result is on the stack if (!context()->IsEffect()) { context()->PlugTOS(); } } else { context()->Plug(eax); } break; } } } void FullCodeGenerator::VisitForTypeofValue(Expression* expr) { VariableProxy* proxy = expr->AsVariableProxy(); DCHECK(!context()->IsEffect()); DCHECK(!context()->IsTest()); if (proxy != NULL && proxy->var()->IsUnallocated()) { Comment cmnt(masm_, "[ Global variable"); __ mov(LoadDescriptor::ReceiverRegister(), GlobalObjectOperand()); __ mov(LoadDescriptor::NameRegister(), Immediate(proxy->name())); __ mov(LoadDescriptor::SlotRegister(), Immediate(SmiFromSlot(proxy->VariableFeedbackSlot()))); // Use a regular load, not a contextual load, to avoid a reference // error. CallLoadIC(NOT_CONTEXTUAL); PrepareForBailout(expr, TOS_REG); context()->Plug(eax); } else if (proxy != NULL && proxy->var()->IsLookupSlot()) { Comment cmnt(masm_, "[ Lookup slot"); Label done, slow; // Generate code for loading from variables potentially shadowed // by eval-introduced variables. EmitDynamicLookupFastCase(proxy, INSIDE_TYPEOF, &slow, &done); __ bind(&slow); __ push(esi); __ push(Immediate(proxy->name())); __ CallRuntime(Runtime::kLoadLookupSlotNoReferenceError, 2); PrepareForBailout(expr, TOS_REG); __ bind(&done); context()->Plug(eax); } else { // This expression cannot throw a reference error at the top level. VisitInDuplicateContext(expr); } } void FullCodeGenerator::EmitLiteralCompareTypeof(Expression* expr, Expression* sub_expr, Handle<String> check) { Label materialize_true, materialize_false; Label* if_true = NULL; Label* if_false = NULL; Label* fall_through = NULL; context()->PrepareTest(&materialize_true, &materialize_false, &if_true, &if_false, &fall_through); { AccumulatorValueContext context(this); VisitForTypeofValue(sub_expr); } PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); Factory* factory = isolate()->factory(); if (String::Equals(check, factory->number_string())) { __ JumpIfSmi(eax, if_true); __ cmp(FieldOperand(eax, HeapObject::kMapOffset), isolate()->factory()->heap_number_map()); Split(equal, if_true, if_false, fall_through); } else if (String::Equals(check, factory->string_string())) { __ JumpIfSmi(eax, if_false); __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, edx); __ j(above_equal, if_false); // Check for undetectable objects => false. __ test_b(FieldOperand(edx, Map::kBitFieldOffset), 1 << Map::kIsUndetectable); Split(zero, if_true, if_false, fall_through); } else if (String::Equals(check, factory->symbol_string())) { __ JumpIfSmi(eax, if_false); __ CmpObjectType(eax, SYMBOL_TYPE, edx); Split(equal, if_true, if_false, fall_through); } else if (String::Equals(check, factory->boolean_string())) { __ cmp(eax, isolate()->factory()->true_value()); __ j(equal, if_true); __ cmp(eax, isolate()->factory()->false_value()); Split(equal, if_true, if_false, fall_through); } else if (String::Equals(check, factory->undefined_string())) { __ cmp(eax, isolate()->factory()->undefined_value()); __ j(equal, if_true); __ JumpIfSmi(eax, if_false); // Check for undetectable objects => true. __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); __ movzx_b(ecx, FieldOperand(edx, Map::kBitFieldOffset)); __ test(ecx, Immediate(1 << Map::kIsUndetectable)); Split(not_zero, if_true, if_false, fall_through); } else if (String::Equals(check, factory->function_string())) { __ JumpIfSmi(eax, if_false); STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); __ CmpObjectType(eax, JS_FUNCTION_TYPE, edx); __ j(equal, if_true); __ CmpInstanceType(edx, JS_FUNCTION_PROXY_TYPE); Split(equal, if_true, if_false, fall_through); } else if (String::Equals(check, factory->object_string())) { __ JumpIfSmi(eax, if_false); __ cmp(eax, isolate()->factory()->null_value()); __ j(equal, if_true); __ CmpObjectType(eax, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE, edx); __ j(below, if_false); __ CmpInstanceType(edx, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); __ j(above, if_false); // Check for undetectable objects => false. __ test_b(FieldOperand(edx, Map::kBitFieldOffset), 1 << Map::kIsUndetectable); Split(zero, if_true, if_false, fall_through); } else { if (if_false != fall_through) __ jmp(if_false); } context()->Plug(if_true, if_false); } void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) { Comment cmnt(masm_, "[ CompareOperation"); SetSourcePosition(expr->position()); // First we try a fast inlined version of the compare when one of // the operands is a literal. if (TryLiteralCompare(expr)) return; // Always perform the comparison for its control flow. Pack the result // into the expression's context after the comparison is performed. Label materialize_true, materialize_false; Label* if_true = NULL; Label* if_false = NULL; Label* fall_through = NULL; context()->PrepareTest(&materialize_true, &materialize_false, &if_true, &if_false, &fall_through); Token::Value op = expr->op(); VisitForStackValue(expr->left()); switch (op) { case Token::IN: VisitForStackValue(expr->right()); __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION); PrepareForBailoutBeforeSplit(expr, false, NULL, NULL); __ cmp(eax, isolate()->factory()->true_value()); Split(equal, if_true, if_false, fall_through); break; case Token::INSTANCEOF: { VisitForStackValue(expr->right()); InstanceofStub stub(isolate(), InstanceofStub::kNoFlags); __ CallStub(&stub); PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); __ test(eax, eax); // The stub returns 0 for true. Split(zero, if_true, if_false, fall_through); break; } default: { VisitForAccumulatorValue(expr->right()); Condition cc = CompareIC::ComputeCondition(op); __ pop(edx); bool inline_smi_code = ShouldInlineSmiCase(op); JumpPatchSite patch_site(masm_); if (inline_smi_code) { Label slow_case; __ mov(ecx, edx); __ or_(ecx, eax); patch_site.EmitJumpIfNotSmi(ecx, &slow_case, Label::kNear); __ cmp(edx, eax); Split(cc, if_true, if_false, NULL); __ bind(&slow_case); } // Record position and call the compare IC. SetSourcePosition(expr->position()); Handle<Code> ic = CodeFactory::CompareIC(isolate(), op, language_mode()).code(); CallIC(ic, expr->CompareOperationFeedbackId()); patch_site.EmitPatchInfo(); PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); __ test(eax, eax); Split(cc, if_true, if_false, fall_through); } } // Convert the result of the comparison into one expected for this // expression's context. context()->Plug(if_true, if_false); } void FullCodeGenerator::EmitLiteralCompareNil(CompareOperation* expr, Expression* sub_expr, NilValue nil) { Label materialize_true, materialize_false; Label* if_true = NULL; Label* if_false = NULL; Label* fall_through = NULL; context()->PrepareTest(&materialize_true, &materialize_false, &if_true, &if_false, &fall_through); VisitForAccumulatorValue(sub_expr); PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); Handle<Object> nil_value = nil == kNullValue ? isolate()->factory()->null_value() : isolate()->factory()->undefined_value(); if (expr->op() == Token::EQ_STRICT) { __ cmp(eax, nil_value); Split(equal, if_true, if_false, fall_through); } else { Handle<Code> ic = CompareNilICStub::GetUninitialized(isolate(), nil); CallIC(ic, expr->CompareOperationFeedbackId()); __ test(eax, eax); Split(not_zero, if_true, if_false, fall_through); } context()->Plug(if_true, if_false); } void FullCodeGenerator::VisitThisFunction(ThisFunction* expr) { __ mov(eax, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); context()->Plug(eax); } Register FullCodeGenerator::result_register() { return eax; } Register FullCodeGenerator::context_register() { return esi; } void FullCodeGenerator::StoreToFrameField(int frame_offset, Register value) { DCHECK_EQ(POINTER_SIZE_ALIGN(frame_offset), frame_offset); __ mov(Operand(ebp, frame_offset), value); } void FullCodeGenerator::LoadContextField(Register dst, int context_index) { __ mov(dst, ContextOperand(esi, context_index)); } void FullCodeGenerator::PushFunctionArgumentForContextAllocation() { Scope* declaration_scope = scope()->DeclarationScope(); if (declaration_scope->is_script_scope() || declaration_scope->is_module_scope()) { // Contexts nested in the native context have a canonical empty function // as their closure, not the anonymous closure containing the global // code. Pass a smi sentinel and let the runtime look up the empty // function. __ push(Immediate(Smi::FromInt(0))); } else if (declaration_scope->is_eval_scope()) { // Contexts nested inside eval code have the same closure as the context // calling eval, not the anonymous closure containing the eval code. // Fetch it from the context. __ push(ContextOperand(esi, Context::CLOSURE_INDEX)); } else { DCHECK(declaration_scope->is_function_scope()); __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); } } // ---------------------------------------------------------------------------- // Non-local control flow support. void FullCodeGenerator::EnterFinallyBlock() { // Cook return address on top of stack (smi encoded Code* delta) DCHECK(!result_register().is(edx)); __ pop(edx); __ sub(edx, Immediate(masm_->CodeObject())); STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); STATIC_ASSERT(kSmiTag == 0); __ SmiTag(edx); __ push(edx); // Store result register while executing finally block. __ push(result_register()); // Store pending message while executing finally block. ExternalReference pending_message_obj = ExternalReference::address_of_pending_message_obj(isolate()); __ mov(edx, Operand::StaticVariable(pending_message_obj)); __ push(edx); ClearPendingMessage(); } void FullCodeGenerator::ExitFinallyBlock() { DCHECK(!result_register().is(edx)); // Restore pending message from stack. __ pop(edx); ExternalReference pending_message_obj = ExternalReference::address_of_pending_message_obj(isolate()); __ mov(Operand::StaticVariable(pending_message_obj), edx); // Restore result register from stack. __ pop(result_register()); // Uncook return address. __ pop(edx); __ SmiUntag(edx); __ add(edx, Immediate(masm_->CodeObject())); __ jmp(edx); } void FullCodeGenerator::ClearPendingMessage() { DCHECK(!result_register().is(edx)); ExternalReference pending_message_obj = ExternalReference::address_of_pending_message_obj(isolate()); __ mov(edx, Immediate(isolate()->factory()->the_hole_value())); __ mov(Operand::StaticVariable(pending_message_obj), edx); } #undef __ static const byte kJnsInstruction = 0x79; static const byte kJnsOffset = 0x11; static const byte kNopByteOne = 0x66; static const byte kNopByteTwo = 0x90; #ifdef DEBUG static const byte kCallInstruction = 0xe8; #endif void BackEdgeTable::PatchAt(Code* unoptimized_code, Address pc, BackEdgeState target_state, Code* replacement_code) { Address call_target_address = pc - kIntSize; Address jns_instr_address = call_target_address - 3; Address jns_offset_address = call_target_address - 2; switch (target_state) { case INTERRUPT: // sub <profiling_counter>, <delta> ;; Not changed // jns ok // call <interrupt stub> // ok: *jns_instr_address = kJnsInstruction; *jns_offset_address = kJnsOffset; break; case ON_STACK_REPLACEMENT: case OSR_AFTER_STACK_CHECK: // sub <profiling_counter>, <delta> ;; Not changed // nop // nop // call <on-stack replacment> // ok: *jns_instr_address = kNopByteOne; *jns_offset_address = kNopByteTwo; break; } Assembler::set_target_address_at(call_target_address, unoptimized_code, replacement_code->entry()); unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( unoptimized_code, call_target_address, replacement_code); } BackEdgeTable::BackEdgeState BackEdgeTable::GetBackEdgeState( Isolate* isolate, Code* unoptimized_code, Address pc) { Address call_target_address = pc - kIntSize; Address jns_instr_address = call_target_address - 3; DCHECK_EQ(kCallInstruction, *(call_target_address - 1)); if (*jns_instr_address == kJnsInstruction) { DCHECK_EQ(kJnsOffset, *(call_target_address - 2)); DCHECK_EQ(isolate->builtins()->InterruptCheck()->entry(), Assembler::target_address_at(call_target_address, unoptimized_code)); return INTERRUPT; } DCHECK_EQ(kNopByteOne, *jns_instr_address); DCHECK_EQ(kNopByteTwo, *(call_target_address - 2)); if (Assembler::target_address_at(call_target_address, unoptimized_code) == isolate->builtins()->OnStackReplacement()->entry()) { return ON_STACK_REPLACEMENT; } DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), Assembler::target_address_at(call_target_address, unoptimized_code)); return OSR_AFTER_STACK_CHECK; } } } // namespace v8::internal #endif // V8_TARGET_ARCH_X87
; A306535: Number of permutations p of [2n] having no index i with |p(i)-i| = n. ; 1,1,9,265,14833,1334961,176214841,32071101049,7697064251745,2355301661033953,895014631192902121,413496759611120779881,228250211305338670494289,148362637348470135821287825,112162153835443422680893595673,97581073836835777732377428235481,96800425246141091510518408809597121 mul $0,2 seq $0,166 ; Subfactorial or rencontres numbers, or derangements: number of permutations of n elements with no fixed points.
SECTION "Map_1A73", ROM0[$B800] Map_1A73_Header: hdr_tileset 18 hdr_dimensions 7, 5 hdr_pointers_a Map_1A73_Blocks, Map_1A73_TextPointers hdr_pointers_b Map_1A73_Script, Map_1A73_Objects hdr_pointers_c Map_1A73_InitScript, Map_1A73_RAMScript hdr_palette $06 hdr_music MUSIC_GAME_CORNER, AUDIO_3 hdr_connection NORTH, $0000, 0, 0 hdr_connection SOUTH, $0000, 0, 0 hdr_connection WEST, $0000, 0, 0 hdr_connection EAST, $0000, 0, 0 Map_1A73_Objects: hdr_border $0f hdr_warp_count 2 hdr_warp 2, 9, 3, 4, $1A3C hdr_warp 1, 9, 3, 4, $1A3C hdr_sign_count 7 hdr_signpost 7, 7, $05 hdr_signpost 7, 5, $05 hdr_signpost 7, 4, $05 hdr_signpost 6, 7, $05 hdr_signpost 6, 6, $05 hdr_signpost 6, 4, $05 hdr_signpost 11, 0, $06 hdr_object_count 4 hdr_object SPRITE_LASS, 12, 7, STAY, UP, $04 hdr_object SPRITE_FISHER2, 8, 6, STAY, LEFT, $03 hdr_object SPRITE_LAPRAS_GIVER, 5, 5, STAY, RIGHT, $02 hdr_object SPRITE_MR_FUJI, 1, 2, STAY, DOWN, $01 Map_1A73_RAMScript: rs_end Map_1A73_Blocks: db $0a,$0a,$0a,$1b,$1b,$34,$2a db $2f,$33,$20,$3a,$20,$20,$20 db $20,$20,$21,$39,$1f,$20,$2d db $20,$20,$21,$38,$1f,$20,$31 db $28,$29,$20,$20,$20,$20,$20 Map_1A73_TextPointers: dw Map_1A73_TX1 dw Map_1A73_TX2 dw Map_1A73_TX3 dw Map_1A73_TX4 dw Map_1A73_TX5 dw Map_1A73_TX6 Map_1A73_InitScript: ld hl, $d5a3 ld [hl], $05 inc hl ld [hl], $00 ret Map_1A73_Script: ret Map_1A73_TX1: TX_ASM ld hl, Map_1A73_LotteryIntro call PrintTextEnhanced ld de, YesNoBoxset ld bc, $0203 call PrintChoiceMenu and a jr z, .lottery ld hl, Map_1A73_LotteryNope call PrintTextEnhanced jp TextScriptEnd .lottery ld hl, Map_1A73_LotteryBegin call PrintTextEnhanced ld hl, SerialCheckLotteryStruct call CompleteEventSerial ld hl, Map_1A73_LotteryInfo call PrintTextEnhanced ld a, [StandardSerialBuffer+5] and a jr z, .noMatch ld hl, Map_1A73_LotteryWin call PrintTextEnhanced jp TextScriptEnd .noMatch ld hl, Map_1A73_LotteryLose call PrintTextEnhanced jp TextScriptEnd Map_1A73_LotteryIntro: text "Welcome to the Glitchland" next "Game Corner!" para "Here, you can play the" next "Glitchland Lottery." para "Every day, on 0, 3, 6, 9," next "12, 15, 18, 21 o'clock UTC," cont "we choose 5 random letters." para "The more of them happen" next "to appear in your username," cont "the bigger the reward!" para "Would you like to try?" done Map_1A73_LotteryNope: text "Understandable." next "Have a great day." done Map_1A73_LotteryBegin: text "OK, so let's see how many" next "you got." wait Map_1A73_LotteryInfo: text "So let's see. The lucky" next "letters right now are:" cont "" tx_buf StandardSerialBuffer+6 text "." wait Map_1A73_LotteryLose: text "We're sorry." next "You didn't get a match..." done Map_1A73_LotteryWin: text "Congradnafio! Your username," next "" tx_buf Map_1A73_CurrentUserBuffer text "," cont "got a " tx_buf StandardSerialBuffer+26 text " match!" tx_snd SFX_GET_KEY_ITEM para "We have already honored" next "your success with a unique" cont "achievement!" para "Thanks for participating." next "See you soon!" done Map_1A73_TX2: TX_ASM jp EnhancedTextOnly text "I lost again?" next "How is it possible!" para "I'm never lucky!" next "Kappa PJSalt!" done Map_1A73_TX3: TX_ASM jp EnhancedTextOnly text "We're so grateful that the" next "underage gambling" cont "restrictions didn't make" cont "their way through to" cont "Glitchland!" para "Otherwise, we'd be stuck" next "playing Voltorb Flip!" done Map_1A73_TX4: TX_ASM jp EnhancedTextOnly text "What? The path here was" next "blocked?" para "I sat here for two days" next "straight and I didn't even" cont "notice it!" para "When you have fun, you" next "lose track of time!" done Map_1A73_TX5: TX_ASM ld hl, PromptUserToPlaySlots ld b, b_PromptUserToPlaySlots call Bankswitch call OpenTextboxInOverworld ld a, [$d5a3] cp $10 jr c, .noThousand ld hl, Map_1A73_SlotThousand call PrintTextEnhanced ld bc, $8C25 ld de, $1640 call CompleteEvent jp TextScriptEnd .noThousand ld hl, Map_1A73_SlotFun call PrintTextEnhanced jp TextScriptEnd Map_1A73_SlotFun: text "Yeah!" next "That was a lot of fun!" done Map_1A73_SlotThousand: text "Wow! You won 1000 coins!" next "That's hugely impressive!" wait Map_1A73_TX6: TX_ASM jp EnhancedTextOnly text "Hey! There's switch behind" next "that poster..." para "No, just kidding." next "Nothing wrong here." done Map_1A73_CurrentUserBuffer: SUBST_CURRENT_USER
SECTION code_clib SECTION code_fp_math48 PUBLIC asm_tgamma EXTERN am48_tgamma defc asm_tgamma = am48_tgamma
; A106586: Digit next to last in squares ending in 6. ; 1,3,9,5,7,7,5,9,3,1,1,3,9,5,7,7,5,9,3,1,1,3,9,5,7,7,5,9,3,1,1,3,9,5,7,7,5,9,3,1,1,3,9,5,7,7,5,9,3,1,1,3,9,5,7,7,5,9,3,1,1,3,9,5,7,7,5,9,3,1,1,3,9,5,7,7,5,9,3,1,1,3,9,5,7,7,5,9,3,1,1,3,9,5,7,7,5,9,3,1,1,3,9,5,7 mov $1,$0 lpb $0,1 mul $1,4 add $0,$1 mod $0,2 sub $0,1 sub $1,1 lpe mul $1,2 mod $1,5 mul $1,2 add $1,1
; A076775: Greatest common divisor of n and the binary representation of n interpreted decimally. ; Submitted by Jon Maiga ; 1,2,1,4,1,2,1,8,1,10,1,4,1,2,1,16,1,2,1,20,21,2,1,8,1,2,1,4,1,10,1,32,11,2,1,4,1,2,1,40,1,42,1,4,1,2,1,16,1,10,1,4,1,2,1,8,1,2,1,20,1,2,21,64,1,22,1,4,3,10,1,8,1,2,1,4,1,2,1,80,3,2,1,84,1,2,1,8,1,10,1,4,1,2,1,32,1,2,11,100 add $0,1 mov $1,$0 seq $1,169965 ; Numbers whose decimal expansion contains only 0's and 2's. gcd $0,$1
BITS 32 section .text foo: fld1 fldl2t fldl2e fldpi fldlg2 fldln2 fldz fsin fcos fsincos fptan fpatan f2xm1 fyl2x fyl2xp1 fincstp fdecstp finit fninit fclex fnclex fwait wait fnop fcompp fucompp ftst fxam fprem fprem1 fabs fchs frndint fscale fsqrt fxtract