hexsha stringlengths 40 40 | size int64 6 1.05M | ext stringclasses 3 values | lang stringclasses 1 value | max_stars_repo_path stringlengths 4 232 | max_stars_repo_name stringlengths 7 106 | max_stars_repo_head_hexsha stringlengths 40 40 | max_stars_repo_licenses listlengths 1 7 | max_stars_count int64 1 33.5k ⌀ | max_stars_repo_stars_event_min_datetime stringlengths 24 24 ⌀ | max_stars_repo_stars_event_max_datetime stringlengths 24 24 ⌀ | max_issues_repo_path stringlengths 4 232 | max_issues_repo_name stringlengths 7 106 | max_issues_repo_head_hexsha stringlengths 40 40 | max_issues_repo_licenses listlengths 1 7 | max_issues_count int64 1 37.5k ⌀ | max_issues_repo_issues_event_min_datetime stringlengths 24 24 ⌀ | max_issues_repo_issues_event_max_datetime stringlengths 24 24 ⌀ | max_forks_repo_path stringlengths 4 232 | max_forks_repo_name stringlengths 7 106 | max_forks_repo_head_hexsha stringlengths 40 40 | max_forks_repo_licenses listlengths 1 7 | max_forks_count int64 1 12.6k ⌀ | max_forks_repo_forks_event_min_datetime stringlengths 24 24 ⌀ | max_forks_repo_forks_event_max_datetime stringlengths 24 24 ⌀ | content stringlengths 6 1.05M | avg_line_length float64 1.16 19.7k | max_line_length int64 2 938k | alphanum_fraction float64 0 1 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
8e47d2a9be360c0d9e0c5198afa65103b5fb5ed5 | 6,429 | asm | Assembly | Transynther/x86/_processed/NONE/_xt_/i7-7700_9_0xca.log_21829_101.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 9 | 2020-08-13T19:41:58.000Z | 2022-03-30T12:22:51.000Z | Transynther/x86/_processed/NONE/_xt_/i7-7700_9_0xca.log_21829_101.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 1 | 2021-04-29T06:29:35.000Z | 2021-05-13T21:02:30.000Z | Transynther/x86/_processed/NONE/_xt_/i7-7700_9_0xca.log_21829_101.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 3 | 2020-07-14T17:07:07.000Z | 2022-03-21T01:12:22.000Z | .global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r13
push %r14
push %r8
push %r9
push %rax
push %rcx
push %rdi
push %rsi
lea addresses_UC_ht+0x8b1a, %rsi
nop
nop
add $53835, %r11
movb $0x61, (%rsi)
nop
nop
cmp $18844, %rax
lea addresses_UC_ht+0xb1da, %r13
nop
nop
inc %r8
mov $0x6162636465666768, %r9
movq %r9, (%r13)
nop
nop
add %r8, %r8
lea addresses_normal_ht+0x42b4, %rsi
lea addresses_UC_ht+0x159ba, %rdi
nop
nop
mfence
mov $18, %rcx
rep movsb
nop
nop
xor %r14, %r14
lea addresses_WT_ht+0x8bfa, %rsi
lea addresses_UC_ht+0xfdee, %rdi
xor %r13, %r13
mov $114, %rcx
rep movsq
nop
nop
inc %r14
lea addresses_D_ht+0xe032, %r13
sub %rsi, %rsi
movb $0x61, (%r13)
sub %rcx, %rcx
lea addresses_normal_ht+0x15eba, %rsi
inc %rcx
movb (%rsi), %r8b
add $13801, %rax
lea addresses_D_ht+0x141ba, %r11
nop
nop
nop
nop
nop
cmp %r14, %r14
mov $0x6162636465666768, %rcx
movq %rcx, (%r11)
nop
nop
nop
nop
and $62964, %r14
lea addresses_WT_ht+0x5e2, %rsi
lea addresses_normal_ht+0xe4a, %rdi
nop
dec %r9
mov $2, %rcx
rep movsq
sub %r14, %r14
lea addresses_WC_ht+0x16c12, %rsi
lea addresses_A_ht+0x1d8c6, %rdi
nop
sub %r13, %r13
mov $99, %rcx
rep movsq
add %rsi, %rsi
pop %rsi
pop %rdi
pop %rcx
pop %rax
pop %r9
pop %r8
pop %r14
pop %r13
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r12
push %r13
push %r8
push %rbp
push %rbx
push %rdi
push %rsi
// Store
lea addresses_A+0x6472, %rbx
nop
nop
nop
nop
nop
inc %rdi
mov $0x5152535455565758, %r13
movq %r13, %xmm1
movups %xmm1, (%rbx)
nop
nop
nop
nop
nop
xor $20637, %rbx
// Faulty Load
lea addresses_D+0x29ba, %rsi
nop
nop
add $31262, %r12
mov (%rsi), %ebp
lea oracles, %rsi
and $0xff, %rbp
shlq $12, %rbp
mov (%rsi,%rbp,1), %rbp
pop %rsi
pop %rdi
pop %rbx
pop %rbp
pop %r8
pop %r13
pop %r12
ret
/*
<gen_faulty_load>
[REF]
{'src': {'congruent': 0, 'AVXalign': False, 'same': True, 'size': 16, 'NT': False, 'type': 'addresses_D'}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'congruent': 0, 'AVXalign': False, 'same': False, 'size': 16, 'NT': False, 'type': 'addresses_A'}}
[Faulty Load]
{'src': {'congruent': 0, 'AVXalign': False, 'same': True, 'size': 4, 'NT': False, 'type': 'addresses_D'}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'congruent': 4, 'AVXalign': False, 'same': False, 'size': 1, 'NT': True, 'type': 'addresses_UC_ht'}}
{'OP': 'STOR', 'dst': {'congruent': 5, 'AVXalign': False, 'same': False, 'size': 8, 'NT': False, 'type': 'addresses_UC_ht'}}
{'src': {'congruent': 1, 'same': False, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'dst': {'congruent': 11, 'same': False, 'type': 'addresses_UC_ht'}}
{'src': {'congruent': 6, 'same': False, 'type': 'addresses_WT_ht'}, 'OP': 'REPM', 'dst': {'congruent': 2, 'same': False, 'type': 'addresses_UC_ht'}}
{'OP': 'STOR', 'dst': {'congruent': 2, 'AVXalign': False, 'same': False, 'size': 1, 'NT': False, 'type': 'addresses_D_ht'}}
{'src': {'congruent': 8, 'AVXalign': False, 'same': False, 'size': 1, 'NT': False, 'type': 'addresses_normal_ht'}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'congruent': 10, 'AVXalign': False, 'same': False, 'size': 8, 'NT': False, 'type': 'addresses_D_ht'}}
{'src': {'congruent': 3, 'same': False, 'type': 'addresses_WT_ht'}, 'OP': 'REPM', 'dst': {'congruent': 4, 'same': False, 'type': 'addresses_normal_ht'}}
{'src': {'congruent': 3, 'same': False, 'type': 'addresses_WC_ht'}, 'OP': 'REPM', 'dst': {'congruent': 2, 'same': False, 'type': 'addresses_A_ht'}}
{'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
*/
| 39.931677 | 2,999 | 0.659045 |
d07d1d01b76ee3fcddd32278fce2ca17a9c74245 | 288 | asm | Assembly | programs/oeis/098/A098721.asm | neoneye/loda | afe9559fb53ee12e3040da54bd6aa47283e0d9ec | [
"Apache-2.0"
] | 22 | 2018-02-06T19:19:31.000Z | 2022-01-17T21:53:31.000Z | programs/oeis/098/A098721.asm | neoneye/loda | afe9559fb53ee12e3040da54bd6aa47283e0d9ec | [
"Apache-2.0"
] | 41 | 2021-02-22T19:00:34.000Z | 2021-08-28T10:47:47.000Z | programs/oeis/098/A098721.asm | neoneye/loda | afe9559fb53ee12e3040da54bd6aa47283e0d9ec | [
"Apache-2.0"
] | 5 | 2021-02-24T21:14:16.000Z | 2021-08-09T19:48:05.000Z | ; A098721: a(n) = C(n, 2)^(n-3) = (n(n-1)/2)^(n-3).
; 1,1,6,100,3375,194481,17210368,2176782336,373669453125,83733937890625,23762680013799936,8335775831236199424,3543686674874777831491,1795856326022129150390625,1069932053790720000000000000
mov $2,$0
add $0,2
bin $0,2
sub $2,1
pow $0,$2
| 32 | 187 | 0.75 |
85e6ed0830d674fafe646dc5cc9e85abb5d73754 | 238 | asm | Assembly | libsrc/strings/strstrip.asm | meesokim/z88dk | 5763c7778f19a71d936b3200374059d267066bb2 | [
"ClArtistic"
] | null | null | null | libsrc/strings/strstrip.asm | meesokim/z88dk | 5763c7778f19a71d936b3200374059d267066bb2 | [
"ClArtistic"
] | null | null | null | libsrc/strings/strstrip.asm | meesokim/z88dk | 5763c7778f19a71d936b3200374059d267066bb2 | [
"ClArtistic"
] | null | null | null | ; CALLER linkage for function pointers
PUBLIC strstrip
EXTERN strstrip_callee
EXTERN ASMDISP_STRSTRIP_CALLEE
.strstrip
pop bc
pop de
pop hl
push hl
push de
push bc
jp strstrip_callee + ASMDISP_STRSTRIP_CALLEE
| 13.222222 | 47 | 0.743697 |
935d0cb097743755da5a427aef6db9efb16888f4 | 5,730 | asm | Assembly | videocodec/libvpx_internal/libvpx/vp8/encoder/ppc/fdct_altivec.asm | Omegaphora/hardware_intel_common_omx-components | 2dc257bd12d2604f5bac67d039e2b7e53c255ac9 | [
"Apache-2.0"
] | 49 | 2015-01-07T04:37:04.000Z | 2022-03-25T08:37:14.000Z | videocodec/libvpx_internal/libvpx/vp8/encoder/ppc/fdct_altivec.asm | Omegaphora/hardware_intel_common_omx-components | 2dc257bd12d2604f5bac67d039e2b7e53c255ac9 | [
"Apache-2.0"
] | 15 | 2015-02-17T09:28:19.000Z | 2017-09-23T16:51:25.000Z | videocodec/libvpx_internal/libvpx/vp8/encoder/ppc/fdct_altivec.asm | Omegaphora/hardware_intel_common_omx-components | 2dc257bd12d2604f5bac67d039e2b7e53c255ac9 | [
"Apache-2.0"
] | 16 | 2015-01-08T01:47:24.000Z | 2022-02-25T06:06:06.000Z | ;
; Copyright (c) 2010 The WebM 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 in the root of the source
; tree. An additional intellectual property rights grant can be found
; in the file PATENTS. All contributing project authors may
; be found in the AUTHORS file in the root of the source tree.
;
.globl vp8_short_fdct4x4_ppc
.globl vp8_short_fdct8x4_ppc
.macro load_c V, LABEL, OFF, R0, R1
lis \R0, \LABEL@ha
la \R1, \LABEL@l(\R0)
lvx \V, \OFF, \R1
.endm
;# Forward and inverse DCTs are nearly identical; only differences are
;# in normalization (fwd is twice unitary, inv is half unitary)
;# and that they are of course transposes of each other.
;#
;# The following three accomplish most of implementation and
;# are used only by ppc_idct.c and ppc_fdct.c.
.macro prologue
mfspr r11, 256 ;# get old VRSAVE
oris r12, r11, 0xfffc
mtspr 256, r12 ;# set VRSAVE
stwu r1,-32(r1) ;# create space on the stack
li r6, 16
load_c v0, dct_tab, 0, r9, r10
lvx v1, r6, r10
addi r10, r10, 32
lvx v2, 0, r10
lvx v3, r6, r10
load_c v4, ppc_dctperm_tab, 0, r9, r10
load_c v5, ppc_dctperm_tab, r6, r9, r10
load_c v6, round_tab, 0, r10, r9
.endm
.macro epilogue
addi r1, r1, 32 ;# recover stack
mtspr 256, r11 ;# reset old VRSAVE
.endm
;# Do horiz xf on two rows of coeffs v8 = a0 a1 a2 a3 b0 b1 b2 b3.
;# a/A are the even rows 0,2 b/B are the odd rows 1,3
;# For fwd transform, indices are horizontal positions, then frequencies.
;# For inverse transform, frequencies then positions.
;# The two resulting A0..A3 B0..B3 are later combined
;# and vertically transformed.
.macro two_rows_horiz Dst
vperm v9, v8, v8, v4 ;# v9 = a2 a3 a0 a1 b2 b3 b0 b1
vmsumshm v10, v0, v8, v6
vmsumshm v10, v1, v9, v10
vsraw v10, v10, v7 ;# v10 = A0 A1 B0 B1
vmsumshm v11, v2, v8, v6
vmsumshm v11, v3, v9, v11
vsraw v11, v11, v7 ;# v11 = A2 A3 B2 B3
vpkuwum v10, v10, v11 ;# v10 = A0 A1 B0 B1 A2 A3 B2 B3
vperm \Dst, v10, v10, v5 ;# Dest = A0 B0 A1 B1 A2 B2 A3 B3
.endm
;# Vertical xf on two rows. DCT values in comments are for inverse transform;
;# forward transform uses transpose.
.macro two_rows_vert Ceven, Codd
vspltw v8, \Ceven, 0 ;# v8 = c00 c10 or c02 c12 four times
vspltw v9, \Codd, 0 ;# v9 = c20 c30 or c22 c32 ""
vmsumshm v8, v8, v12, v6
vmsumshm v8, v9, v13, v8
vsraw v10, v8, v7
vspltw v8, \Codd, 1 ;# v8 = c01 c11 or c03 c13
vspltw v9, \Ceven, 1 ;# v9 = c21 c31 or c23 c33
vmsumshm v8, v8, v12, v6
vmsumshm v8, v9, v13, v8
vsraw v8, v8, v7
vpkuwum v8, v10, v8 ;# v8 = rows 0,1 or 2,3
.endm
.macro two_rows_h Dest
stw r0, 0(r8)
lwz r0, 4(r3)
stw r0, 4(r8)
lwzux r0, r3,r5
stw r0, 8(r8)
lwz r0, 4(r3)
stw r0, 12(r8)
lvx v8, 0,r8
two_rows_horiz \Dest
.endm
.align 2
;# r3 short *input
;# r4 short *output
;# r5 int pitch
vp8_short_fdct4x4_ppc:
prologue
vspltisw v7, 14 ;# == 14, fits in 5 signed bits
addi r8, r1, 0
lwz r0, 0(r3)
two_rows_h v12 ;# v12 = H00 H10 H01 H11 H02 H12 H03 H13
lwzux r0, r3, r5
two_rows_h v13 ;# v13 = H20 H30 H21 H31 H22 H32 H23 H33
lvx v6, r6, r9 ;# v6 = Vround
vspltisw v7, -16 ;# == 16 == -16, only low 5 bits matter
two_rows_vert v0, v1
stvx v8, 0, r4
two_rows_vert v2, v3
stvx v8, r6, r4
epilogue
blr
.align 2
;# r3 short *input
;# r4 short *output
;# r5 int pitch
vp8_short_fdct8x4_ppc:
prologue
vspltisw v7, 14 ;# == 14, fits in 5 signed bits
addi r8, r1, 0
addi r10, r3, 0
lwz r0, 0(r3)
two_rows_h v12 ;# v12 = H00 H10 H01 H11 H02 H12 H03 H13
lwzux r0, r3, r5
two_rows_h v13 ;# v13 = H20 H30 H21 H31 H22 H32 H23 H33
lvx v6, r6, r9 ;# v6 = Vround
vspltisw v7, -16 ;# == 16 == -16, only low 5 bits matter
two_rows_vert v0, v1
stvx v8, 0, r4
two_rows_vert v2, v3
stvx v8, r6, r4
;# Next block
addi r3, r10, 8
addi r4, r4, 32
lvx v6, 0, r9 ;# v6 = Hround
vspltisw v7, 14 ;# == 14, fits in 5 signed bits
addi r8, r1, 0
lwz r0, 0(r3)
two_rows_h v12 ;# v12 = H00 H10 H01 H11 H02 H12 H03 H13
lwzux r0, r3, r5
two_rows_h v13 ;# v13 = H20 H30 H21 H31 H22 H32 H23 H33
lvx v6, r6, r9 ;# v6 = Vround
vspltisw v7, -16 ;# == 16 == -16, only low 5 bits matter
two_rows_vert v0, v1
stvx v8, 0, r4
two_rows_vert v2, v3
stvx v8, r6, r4
epilogue
blr
.data
.align 4
ppc_dctperm_tab:
.byte 4,5,6,7, 0,1,2,3, 12,13,14,15, 8,9,10,11
.byte 0,1,4,5, 2,3,6,7, 8,9,12,13, 10,11,14,15
.align 4
dct_tab:
.short 23170, 23170,-12540,-30274, 23170, 23170,-12540,-30274
.short 23170, 23170, 30274, 12540, 23170, 23170, 30274, 12540
.short 23170,-23170, 30274,-12540, 23170,-23170, 30274,-12540
.short -23170, 23170, 12540,-30274,-23170, 23170, 12540,-30274
.align 4
round_tab:
.long (1 << (14-1)), (1 << (14-1)), (1 << (14-1)), (1 << (14-1))
.long (1 << (16-1)), (1 << (16-1)), (1 << (16-1)), (1 << (16-1))
| 27.815534 | 77 | 0.558639 |
1755d7f63dd8acafabf6ccd58ce38ecbcf771e0a | 270 | asm | Assembly | examples/interrupt.asm | nicolasbauw/Intel8080 | a9f3408574879f5b84d5be9773f6a77076209b03 | [
"MIT"
] | 1 | 2022-03-21T16:35:08.000Z | 2022-03-21T16:35:08.000Z | examples/interrupt.asm | nicolasbauw/Intel8080 | a9f3408574879f5b84d5be9773f6a77076209b03 | [
"MIT"
] | null | null | null | examples/interrupt.asm | nicolasbauw/Intel8080 | a9f3408574879f5b84d5be9773f6a77076209b03 | [
"MIT"
] | null | null | null | .target "8080"
.format "bin"
.org 0
lxi sp,$ff00
mvi a,$0f
jmp start
int .org $8
mov b,a
ret
start .org $9700
ei
@loop cmp b
jnz @loop
ret
.end
| 14.210526 | 24 | 0.355556 |
2f4cb3b869ee5c40ff5f47fcea48aae6e8a500ae | 6,431 | asm | Assembly | Transynther/x86/_processed/NONE/_xt_/i3-7100_9_0x84_notsx.log_21829_966.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 9 | 2020-08-13T19:41:58.000Z | 2022-03-30T12:22:51.000Z | Transynther/x86/_processed/NONE/_xt_/i3-7100_9_0x84_notsx.log_21829_966.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 1 | 2021-04-29T06:29:35.000Z | 2021-05-13T21:02:30.000Z | Transynther/x86/_processed/NONE/_xt_/i3-7100_9_0x84_notsx.log_21829_966.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 3 | 2020-07-14T17:07:07.000Z | 2022-03-21T01:12:22.000Z | .global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r13
push %r14
push %r8
push %r9
push %rcx
push %rdi
push %rsi
lea addresses_WC_ht+0x47db, %r9
nop
xor $15638, %r14
movl $0x61626364, (%r9)
nop
nop
nop
nop
nop
add $54531, %r13
lea addresses_A_ht+0x205b, %rsi
lea addresses_A_ht+0xbd1b, %rdi
nop
nop
and %r8, %r8
mov $127, %rcx
rep movsq
nop
nop
nop
cmp $45236, %rcx
lea addresses_normal_ht+0xe8db, %rsi
lea addresses_WC_ht+0x1b8e3, %rdi
nop
nop
xor %r13, %r13
mov $18, %rcx
rep movsl
nop
cmp %r9, %r9
lea addresses_UC_ht+0x1cd23, %r13
nop
nop
nop
nop
nop
and %r9, %r9
mov $0x6162636465666768, %r11
movq %r11, (%r13)
and $37236, %rcx
lea addresses_WC_ht+0x10c53, %rsi
lea addresses_A_ht+0x345b, %rdi
inc %r8
mov $49, %rcx
rep movsl
inc %r9
pop %rsi
pop %rdi
pop %rcx
pop %r9
pop %r8
pop %r14
pop %r13
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r13
push %r8
push %r9
push %rax
push %rbp
push %rcx
// Store
lea addresses_RW+0x1e1bf, %r13
nop
nop
dec %rcx
movb $0x51, (%r13)
nop
nop
nop
cmp $12691, %r11
// Load
lea addresses_US+0x1045b, %r13
nop
nop
nop
nop
nop
and %rax, %rax
mov (%r13), %ebp
// Exception!!!
mov (0), %r11
nop
and %r9, %r9
// Load
lea addresses_UC+0x1b5db, %rcx
nop
nop
nop
nop
cmp $27662, %rax
vmovaps (%rcx), %ymm6
vextracti128 $0, %ymm6, %xmm6
vpextrq $0, %xmm6, %r8
cmp %r9, %r9
// Load
lea addresses_WT+0x1641b, %rcx
nop
nop
sub %r13, %r13
mov (%rcx), %bp
nop
nop
nop
nop
nop
add $21339, %r9
// Store
lea addresses_UC+0x1223, %rbp
nop
nop
nop
and %rax, %rax
movl $0x51525354, (%rbp)
nop
nop
sub $38120, %r13
// Faulty Load
lea addresses_normal+0x1085b, %rcx
xor $32541, %r8
mov (%rcx), %r9w
lea oracles, %rbp
and $0xff, %r9
shlq $12, %r9
mov (%rbp,%r9,1), %r9
pop %rcx
pop %rbp
pop %rax
pop %r9
pop %r8
pop %r13
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'src': {'type': 'addresses_normal', 'same': False, 'size': 8, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'dst': {'type': 'addresses_RW', 'same': False, 'size': 1, 'congruent': 1, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'src': {'type': 'addresses_US', 'same': False, 'size': 4, 'congruent': 10, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_UC', 'same': False, 'size': 32, 'congruent': 2, 'NT': False, 'AVXalign': True}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_WT', 'same': False, 'size': 2, 'congruent': 5, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'dst': {'type': 'addresses_UC', 'same': False, 'size': 4, 'congruent': 1, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
[Faulty Load]
{'src': {'type': 'addresses_normal', 'same': True, 'size': 2, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'dst': {'type': 'addresses_WC_ht', 'same': False, 'size': 4, 'congruent': 7, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'src': {'type': 'addresses_A_ht', 'congruent': 11, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 6, 'same': False}, 'OP': 'REPM'}
{'src': {'type': 'addresses_normal_ht', 'congruent': 5, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 3, 'same': False}, 'OP': 'REPM'}
{'dst': {'type': 'addresses_UC_ht', 'same': True, 'size': 8, 'congruent': 3, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'src': {'type': 'addresses_WC_ht', 'congruent': 3, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 10, 'same': False}, 'OP': 'REPM'}
{'34': 21829}
34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34
*/
| 36.539773 | 2,999 | 0.653709 |
4d0c26fb1f026f2262cb164d6e07c9914c694c8b | 9,115 | asm | Assembly | Transynther/x86/_processed/NONE/_xt_/i7-7700_9_0x48_notsx.log_21829_168.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 9 | 2020-08-13T19:41:58.000Z | 2022-03-30T12:22:51.000Z | Transynther/x86/_processed/NONE/_xt_/i7-7700_9_0x48_notsx.log_21829_168.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 1 | 2021-04-29T06:29:35.000Z | 2021-05-13T21:02:30.000Z | Transynther/x86/_processed/NONE/_xt_/i7-7700_9_0x48_notsx.log_21829_168.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 3 | 2020-07-14T17:07:07.000Z | 2022-03-21T01:12:22.000Z | .global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r15
push %r8
push %r9
push %rbp
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_D_ht+0x11056, %r9
nop
nop
nop
nop
cmp $57474, %rbp
mov $0x6162636465666768, %r10
movq %r10, %xmm1
movups %xmm1, (%r9)
nop
nop
nop
nop
inc %rbx
lea addresses_UC_ht+0x699a, %r15
nop
sub $63743, %r8
mov $0x6162636465666768, %r10
movq %r10, %xmm4
vmovups %ymm4, (%r15)
nop
nop
nop
nop
nop
dec %r10
lea addresses_UC_ht+0xaf6, %r15
nop
nop
nop
nop
nop
and $14615, %rbp
movl $0x61626364, (%r15)
nop
nop
nop
nop
nop
cmp %rbp, %rbp
lea addresses_A_ht+0x11055, %rsi
lea addresses_UC_ht+0x19e9e, %rdi
nop
sub %r15, %r15
mov $43, %rcx
rep movsl
nop
nop
nop
nop
nop
cmp $24141, %r10
lea addresses_normal_ht+0x6c0c, %rcx
nop
nop
and %r15, %r15
mov $0x6162636465666768, %rsi
movq %rsi, %xmm1
vmovups %ymm1, (%rcx)
nop
nop
xor %rbp, %rbp
lea addresses_D_ht+0x15d42, %r8
nop
nop
nop
xor %rbp, %rbp
movups (%r8), %xmm0
vpextrq $0, %xmm0, %r9
xor %r9, %r9
lea addresses_WC_ht+0x15306, %rsi
lea addresses_A_ht+0x8756, %rdi
clflush (%rsi)
nop
nop
nop
nop
nop
xor %r8, %r8
mov $83, %rcx
rep movsw
nop
nop
nop
add %r10, %r10
lea addresses_WC_ht+0x19222, %r9
nop
nop
and $43112, %rbp
mov $0x6162636465666768, %rsi
movq %rsi, (%r9)
nop
nop
dec %rbx
lea addresses_A_ht+0xf616, %rcx
clflush (%rcx)
nop
nop
nop
nop
dec %rbx
mov $0x6162636465666768, %rdi
movq %rdi, (%rcx)
nop
nop
add $17921, %rbp
lea addresses_normal_ht+0x8bf6, %rcx
nop
nop
nop
sub $41577, %rbx
mov $0x6162636465666768, %rsi
movq %rsi, %xmm7
vmovups %ymm7, (%rcx)
nop
nop
nop
nop
sub $28477, %rsi
lea addresses_A_ht+0xb056, %r9
nop
nop
nop
nop
add %rsi, %rsi
and $0xffffffffffffffc0, %r9
movaps (%r9), %xmm4
vpextrq $0, %xmm4, %rbp
nop
nop
nop
nop
and %rdi, %rdi
lea addresses_WT_ht+0x1e756, %rdi
nop
mfence
movl $0x61626364, (%rdi)
inc %r15
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rbp
pop %r9
pop %r8
pop %r15
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r12
push %r13
push %rbp
push %rbx
push %rcx
push %rdi
push %rsi
// Store
lea addresses_UC+0x1c556, %rdi
nop
inc %rbp
mov $0x5152535455565758, %rsi
movq %rsi, %xmm1
movups %xmm1, (%rdi)
nop
nop
nop
nop
cmp %r12, %r12
// Store
lea addresses_D+0x16056, %r12
nop
nop
nop
nop
sub %rbx, %rbx
mov $0x5152535455565758, %rsi
movq %rsi, %xmm4
movups %xmm4, (%r12)
nop
nop
nop
nop
inc %r13
// REPMOV
lea addresses_D+0x8e96, %rsi
lea addresses_WC+0x125ce, %rdi
nop
nop
nop
add $27477, %r13
mov $34, %rcx
rep movsw
nop
dec %rcx
// Store
lea addresses_UC+0x18456, %r11
nop
nop
nop
nop
inc %rdi
mov $0x5152535455565758, %rbp
movq %rbp, %xmm2
movups %xmm2, (%r11)
nop
and $41101, %rdi
// Store
lea addresses_WT+0xb256, %rbx
nop
nop
sub $35852, %rsi
mov $0x5152535455565758, %rdi
movq %rdi, %xmm1
movups %xmm1, (%rbx)
nop
nop
nop
nop
nop
inc %r12
// Store
lea addresses_UC+0x14b56, %rdi
nop
nop
nop
nop
nop
add %r13, %r13
mov $0x5152535455565758, %rbx
movq %rbx, (%rdi)
nop
nop
nop
nop
sub %rbx, %rbx
// Store
lea addresses_A+0x121d6, %rbp
clflush (%rbp)
and %rdi, %rdi
mov $0x5152535455565758, %rsi
movq %rsi, %xmm4
movups %xmm4, (%rbp)
nop
nop
nop
nop
nop
add $42867, %r12
// Faulty Load
lea addresses_RW+0x1c456, %rbp
add %rsi, %rsi
mov (%rbp), %r11w
lea oracles, %rcx
and $0xff, %r11
shlq $12, %r11
mov (%rcx,%r11,1), %r11
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rbp
pop %r13
pop %r12
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 1, 'type': 'addresses_RW', 'congruent': 0}}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_UC', 'congruent': 7}, 'OP': 'STOR'}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_D', 'congruent': 9}, 'OP': 'STOR'}
{'dst': {'same': False, 'congruent': 3, 'type': 'addresses_WC'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 5, 'type': 'addresses_D'}}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_UC', 'congruent': 9}, 'OP': 'STOR'}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_WT', 'congruent': 8}, 'OP': 'STOR'}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 8, 'type': 'addresses_UC', 'congruent': 5}, 'OP': 'STOR'}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_A', 'congruent': 6}, 'OP': 'STOR'}
[Faulty Load]
{'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_RW', 'congruent': 0}}
<gen_prepare_buffer>
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_D_ht', 'congruent': 6}, 'OP': 'STOR'}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_UC_ht', 'congruent': 2}, 'OP': 'STOR'}
{'dst': {'same': False, 'NT': True, 'AVXalign': False, 'size': 4, 'type': 'addresses_UC_ht', 'congruent': 5}, 'OP': 'STOR'}
{'dst': {'same': False, 'congruent': 3, 'type': 'addresses_UC_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 0, 'type': 'addresses_A_ht'}}
{'dst': {'same': True, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_normal_ht', 'congruent': 0}, 'OP': 'STOR'}
{'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_D_ht', 'congruent': 2}}
{'dst': {'same': False, 'congruent': 7, 'type': 'addresses_A_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 4, 'type': 'addresses_WC_ht'}}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 8, 'type': 'addresses_WC_ht', 'congruent': 2}, 'OP': 'STOR'}
{'dst': {'same': False, 'NT': True, 'AVXalign': True, 'size': 8, 'type': 'addresses_A_ht', 'congruent': 5}, 'OP': 'STOR'}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_normal_ht', 'congruent': 1}, 'OP': 'STOR'}
{'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': True, 'size': 16, 'type': 'addresses_A_ht', 'congruent': 2}}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 4, 'type': 'addresses_WT_ht', 'congruent': 5}, 'OP': 'STOR'}
{'32': 21829}
32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32
*/
| 28.663522 | 2,999 | 0.656829 |
7a4612011b8caff4b167794ff54c4e0f6a5090b9 | 5,578 | asm | Assembly | Transynther/x86/_processed/NONE/_zr_/i7-7700_9_0x48.log_21829_2472.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 9 | 2020-08-13T19:41:58.000Z | 2022-03-30T12:22:51.000Z | Transynther/x86/_processed/NONE/_zr_/i7-7700_9_0x48.log_21829_2472.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 1 | 2021-04-29T06:29:35.000Z | 2021-05-13T21:02:30.000Z | Transynther/x86/_processed/NONE/_zr_/i7-7700_9_0x48.log_21829_2472.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 3 | 2020-07-14T17:07:07.000Z | 2022-03-21T01:12:22.000Z | .global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r11
push %r12
push %r9
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_normal_ht+0x30c0, %rdx
nop
nop
nop
nop
nop
inc %rsi
vmovups (%rdx), %ymm1
vextracti128 $0, %ymm1, %xmm1
vpextrq $1, %xmm1, %r10
nop
xor %r12, %r12
lea addresses_WC_ht+0x18a98, %rcx
nop
nop
nop
nop
add $20105, %r11
movl $0x61626364, (%rcx)
nop
nop
nop
xor %r11, %r11
lea addresses_D_ht+0xee98, %r11
nop
nop
sub %rsi, %rsi
movb $0x61, (%r11)
nop
nop
cmp $23682, %r11
lea addresses_UC_ht+0x13a98, %rsi
lea addresses_WT_ht+0xac98, %rdi
clflush (%rsi)
add $21534, %r9
mov $76, %rcx
rep movsb
add $35166, %rcx
lea addresses_UC_ht+0x16a38, %rsi
and $18254, %r12
mov $0x6162636465666768, %r10
movq %r10, %xmm6
movups %xmm6, (%rsi)
nop
nop
nop
nop
nop
inc %r11
lea addresses_normal_ht+0x9a88, %r10
nop
nop
cmp %rcx, %rcx
movb (%r10), %r9b
nop
xor $33303, %r10
lea addresses_WT_ht+0x1cd50, %r12
nop
nop
nop
dec %rcx
mov (%r12), %r9
nop
dec %rcx
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %r9
pop %r12
pop %r11
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r13
push %r14
push %rax
push %rbx
push %rsi
// Faulty Load
lea addresses_A+0xca98, %r13
inc %rbx
mov (%r13), %eax
lea oracles, %rsi
and $0xff, %rax
shlq $12, %rax
mov (%rsi,%rax,1), %rax
pop %rsi
pop %rbx
pop %rax
pop %r14
pop %r13
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_A', 'AVXalign': False, 'congruent': 0, 'size': 2, 'same': True, 'NT': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_A', 'AVXalign': False, 'congruent': 0, 'size': 4, 'same': True, 'NT': False}}
<gen_prepare_buffer>
{'OP': 'LOAD', 'src': {'type': 'addresses_normal_ht', 'AVXalign': False, 'congruent': 3, 'size': 32, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 9, 'size': 4, 'same': False, 'NT': True}}
{'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'AVXalign': False, 'congruent': 10, 'size': 1, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 11, 'same': True}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 9, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 5, 'size': 16, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_normal_ht', 'AVXalign': False, 'congruent': 1, 'size': 1, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'AVXalign': True, 'congruent': 0, 'size': 8, 'same': False, 'NT': True}}
{'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
*/
| 43.92126 | 2,999 | 0.658659 |
71b450d95abe0b1880d89c1fd154a70f6394f642 | 263 | asm | Assembly | programs/oeis/226/A226233.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | 1 | 2021-03-15T11:38:20.000Z | 2021-03-15T11:38:20.000Z | programs/oeis/226/A226233.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | null | null | null | programs/oeis/226/A226233.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | null | null | null | ; A226233: Ten copies of each positive integer.
; 1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9,10
mov $1,$0
div $1,10
add $1,1
| 37.571429 | 184 | 0.551331 |
87e1ceb89bad7213b4913965f0dcceb66f5747c6 | 6,493 | asm | Assembly | Transynther/x86/_processed/NONE/_xt_sm_/i7-7700_9_0x48.log_21829_1971.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 9 | 2020-08-13T19:41:58.000Z | 2022-03-30T12:22:51.000Z | Transynther/x86/_processed/NONE/_xt_sm_/i7-7700_9_0x48.log_21829_1971.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 1 | 2021-04-29T06:29:35.000Z | 2021-05-13T21:02:30.000Z | Transynther/x86/_processed/NONE/_xt_sm_/i7-7700_9_0x48.log_21829_1971.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 3 | 2020-07-14T17:07:07.000Z | 2022-03-21T01:12:22.000Z | .global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r12
push %r13
push %r8
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_WC_ht+0x4a4e, %rbx
nop
nop
nop
nop
nop
and $28372, %r13
mov $0x6162636465666768, %r10
movq %r10, (%rbx)
nop
nop
nop
nop
add $33406, %rbx
lea addresses_WC_ht+0xff4e, %rsi
lea addresses_WT_ht+0x1554e, %rdi
nop
add %r8, %r8
mov $60, %rcx
rep movsb
nop
nop
nop
inc %r8
lea addresses_A_ht+0x3546, %rsi
lea addresses_normal_ht+0x904e, %rdi
add %r12, %r12
mov $127, %rcx
rep movsw
nop
dec %rbx
lea addresses_UC_ht+0x123ce, %rsi
lea addresses_UC_ht+0xea4e, %rdi
nop
nop
cmp %r10, %r10
mov $77, %rcx
rep movsl
nop
nop
and %rdi, %rdi
lea addresses_D_ht+0xd96e, %r12
inc %rbx
mov (%r12), %r10d
nop
inc %rbx
lea addresses_WT_ht+0x344e, %rsi
nop
nop
xor %rcx, %rcx
mov $0x6162636465666768, %rbx
movq %rbx, %xmm5
movups %xmm5, (%rsi)
nop
nop
and $58596, %r10
lea addresses_normal_ht+0x244e, %rsi
lea addresses_UC_ht+0x1564e, %rdi
nop
nop
nop
nop
nop
xor %rbx, %rbx
mov $45, %rcx
rep movsq
nop
nop
nop
nop
cmp $63870, %r10
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %r8
pop %r13
pop %r12
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r14
push %r8
push %r9
push %rax
push %rbx
push %rdx
push %rsi
// Store
lea addresses_PSE+0x1724e, %rdx
clflush (%rdx)
nop
add %r14, %r14
movl $0x51525354, (%rdx)
// Exception!!!
nop
nop
mov (0), %rax
sub %r14, %r14
// Load
lea addresses_US+0x624e, %r14
nop
nop
nop
nop
sub $16494, %rsi
mov (%r14), %r8d
nop
nop
xor $65359, %r14
// Store
lea addresses_UC+0x1c64e, %rsi
nop
cmp %r8, %r8
movb $0x51, (%rsi)
xor %rbx, %rbx
// Faulty Load
lea addresses_PSE+0x1724e, %rax
nop
nop
nop
nop
and %r8, %r8
mov (%rax), %bx
lea oracles, %rsi
and $0xff, %rbx
shlq $12, %rbx
mov (%rsi,%rbx,1), %rbx
pop %rsi
pop %rdx
pop %rbx
pop %rax
pop %r9
pop %r8
pop %r14
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_PSE', 'AVXalign': False, 'congruent': 0, 'size': 4, 'same': True, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_US', 'AVXalign': False, 'congruent': 10, 'size': 4, 'same': False, 'NT': True}}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC', 'AVXalign': False, 'congruent': 10, 'size': 1, 'same': False, 'NT': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_PSE', 'AVXalign': False, 'congruent': 0, 'size': 2, 'same': True, 'NT': False}}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 10, 'size': 8, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 5, 'same': True}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 7, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 3, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 6, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 7, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 9, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'AVXalign': True, 'congruent': 4, 'size': 4, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'AVXalign': False, 'congruent': 9, 'size': 16, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 8, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 10, 'same': False}}
{'54': 21829}
54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54
*/
| 37.102857 | 2,999 | 0.657015 |
72064452eda1ace95084e78cd94d8278cd774749 | 9,822 | asm | Assembly | lab5/loadknl.asm | wkcn/OSLabs | 9f88f02dbeee8930e3dadac8b51e54dcaad5175f | [
"MIT"
] | 73 | 2017-10-02T01:24:19.000Z | 2021-12-17T08:50:03.000Z | lab4/loadknl.asm | wkcn/OSLabs | 9f88f02dbeee8930e3dadac8b51e54dcaad5175f | [
"MIT"
] | 4 | 2018-03-21T02:24:19.000Z | 2020-02-15T04:19:34.000Z | lab5/loadknl.asm | wkcn/OSLabs | 9f88f02dbeee8930e3dadac8b51e54dcaad5175f | [
"MIT"
] | 14 | 2016-12-22T23:24:48.000Z | 2021-10-13T08:27:42.000Z | ;汇编程序源代码(bootOS.asm)
;%define _BOOT_DEBUG_ ;用于生成.COM文件易于调试
%ifdef _BOOT_DEBUG_
org 100h ; 调试状态,做成 .COM 文件, 可调试
%else
org 7c00h ; BIOS将把引导扇区加载到0:7C00处,并开始执行
%endif
;==============================================================
%ifdef _BOOT_DEBUG_
BaseOfStack equ 100h ; 堆栈基地址(栈底, 从这个位置向低地址生长)
%else
BaseOfStack equ 7c00h ; 堆栈基地址(栈底, 从这个位置向低地址生长)
%endif
BaseOfkernal equ 0000h ; kernal.BIN 被加载到的位置 ---- 段地址
OffsetOfkernal equ 7e00h ; kernal.BIN 被加载到的位置 ---- 偏移地址
FATSegment equ 8000h ; 存放FAT的临时位置 -- 段
RootDirSectors equ 14 ; 根目录占用的扇区数
SectorNoOfRootDirectory equ 19 ; 根目录区的首扇区号
SectorNoOfFAT1 equ 1 ; FAT#1的首扇区号 = BPB_RsvdSecCnt
DeltaSectorNo equ 17 ; DeltaSectorNo = BPB_RsvdSecCnt +
; (BPB_NumFATs * FATSz) - 2 = 1 + (2*9) -2 = 17
; 文件的开始扇区号 = 目录条目中的开始扇区号
; + 根目录占用扇区数目 + DeltaSectorNo
; 用户数据空间的第一个簇编号为002
;==============================================================
jmp short LABEL_START ; 引导开始,跳转指令
nop ; 这个 nop 不可少,无操作,占字节位
; 下面是 FAT12 磁盘引导扇区的BPB和EBPB结构区51字节
BS_OEMName DB 'MiraiOS ' ; OEM串,必须8个字节,不足补空格
BPB_BytsPerSec DW 512 ; 每扇区字节数
BPB_SecPerClus DB 1 ; 每簇扇区数
BPB_RsvdSecCnt DW 1 ; Boot记录占用扇区数
BPB_NumFATs DB 2 ; FAT表数
BPB_RootEntCnt DW 224 ; 根目录文件数最大值
BPB_TotSec16 DW 2880 ; 逻辑扇区总数
BPB_Media DB 0F0h ; 介质描述符
BPB_FATSz16 DW 9 ; 每FAT扇区数
BPB_SecPerTrk DW 18 ; 每磁道扇区数
BPB_NumHeads DW 2 ; 磁头数(面数)
BPB_HiddSec DD 0 ; 隐藏扇区数
BPB_TotSec32 DD 0 ; BPB_TotSec16为0时由此值记录扇区总数
BS_DrvNum DB 0 ; 中断 13 的驱动器号(软盘)
BS_Reserved1 DB 0 ; 未使用
BS_BootSig DB 29h ; 扩展引导标记 (29h)
BS_VolID DD 0 ; 卷序列号
BS_VolLab DB 'MiraiOS '; 卷标,必须11个字节,不足补空格
BS_FileSysType DB 'FAT12 ' ; 文件系统类型,必须8个字节,不足补空格
LABEL_START:
mov ax, cs ; 置其他段寄存器值与CS相同
mov ds, ax ; 数据段
mov es, ax ; 附加段
mov ss, ax ; 堆栈段
mov sp, BaseOfStack ; 堆栈基址
; 清屏
mov ax, 3h
int 10h ; 显示服务BIOS调用
mov dh, 0 ; "Booting "
call DispStr ; 显示字符串
; 软驱复位
xor ah, ah ; 功能号ah=0(复位磁盘驱动器)
xor dl, dl ; dl=0(软驱,硬盘和U盘为80h)
int 13h ; 磁盘服务BIOS调用
; 下面在A盘根目录中寻找 kernal.BIN
mov word [wSectorNo], SectorNoOfRootDirectory ; 给表示当前扇区号的
; 变量wSectorNo赋初值为根目录区的首扇区号(=19)
LABEL_SEARCH_IN_ROOT_DIR_BEGIN:
cmp word [wRootDirSizeForLoop], 0 ; 判断根目录区是否已读完
jz LABEL_NO_kernalBIN ;若读完则表示未找到kernal.BIN
dec word [wRootDirSizeForLoop] ; 递减变量wRootDirSizeForLoop的值
; 调用读扇区函数读入一个根目录扇区到装载区
mov ax, BaseOfkernal
mov es, ax ; ES <- BaseOf kernal(9000h)
mov bx, OffsetOfkernal; BX <- OffsetOf kernal(100h)
mov ax, [wSectorNo] ; AX <- 根目录中的当前扇区号
mov cl, 1 ; 只读一个扇区
call ReadSector ; 调用读扇区函数
mov si, kernalFileName ; DS:SI -> " kernal BIN"
mov di, OffsetOfkernal ; ES:DI -> BaseOfkernal :0100
cld ; 清除DF标志位
; 置比较字符串时的方向为左/上[索引增加]
mov dx, 10h ; 循环次数=16(每个扇区有16个文件条目:512/32=16)
LABEL_SEARCH_FOR_kernalBIN:
cmp dx, 0 ; 循环次数控制
jz LABEL_GOTO_NEXT_SECTOR_IN_ROOT_DIR ; 若已读完一扇区
dec dx ; 递减循环次数值 就跳到下一扇区
mov cx, 11 ; 初始循环次数为11
LABEL_CMP_FILENAME:
cmp cx, 0
jz LABEL_FILENAME_FOUND ; 如果比较了11个字符都相等,表示找到
dec cx ; 递减循环次数值
lodsb ; DS:SI -> AL(装入字符串字节)
cmp al, byte [es:di] ; 比较字符串的当前字符
jz LABEL_GO_ON
jmp LABEL_DIFFERENT ; 只要发现不一样的字符就表明本DirectoryEntry
; 不是我们要找的kernal.BIN
LABEL_GO_ON:
inc di ; 递增DI
jmp LABEL_CMP_FILENAME ; 继续循环
LABEL_DIFFERENT:
and di, 0FFE0h ; DI &= E0为了让它指向本条目开头(低5位清零)
; FFE0h = 1111111111100000(低5位=32=目录条目大小)
add di, 20h ; DI += 20h 下一个目录条目
mov si, kernalFileName ; SI指向装载文件名串的起始地址
jmp LABEL_SEARCH_FOR_kernalBIN; 转到循环开始处
LABEL_GOTO_NEXT_SECTOR_IN_ROOT_DIR:
add word [wSectorNo], 1 ; 递增当前扇区号
jmp LABEL_SEARCH_IN_ROOT_DIR_BEGIN
LABEL_NO_kernalBIN:
mov dh, 2 ; "No kernal "
call DispStr ; 显示字符串
%ifdef _BOOT_DEBUG_ ; 没有找到kernal.BIN就回到 DOS
mov ax, 4c00h ; AH=4Ch(功能号,终止进程)、AL=0(返回代码)
int 21h ; DOS软中断
%else
jmp $ ; 没有找到 kernal.BIN,在这里进入死循环
%endif
LABEL_FILENAME_FOUND: ; 找到 kernal.BIN 后便来到这里继续
; 计算文件的起始扇区号
mov ax, RootDirSectors ; AX=根目录占用的扇区数
and di, 0FFE0h ; DI -> 当前条目的开始地址
add di, 1Ah ; DI -> 文件的首扇区号在条目中的偏移地址
mov cx, word [es:di] ; CX=文件的首扇区号
push cx ; 保存此扇区在FAT中的序号
add cx, ax ; CX=文件的相对起始扇区号+根目录占用的扇区数
add cx, DeltaSectorNo ; CL <- LOADER.BIN的起始扇区号(0-based)
mov ax, BaseOfkernal
mov es, ax ; ES <- BaseOf kernal(装载程序基址=9000h)
mov bx, OffsetOfkernal; BX <- OffsetOf kernal(装载程序偏移地址=100h)
mov ax, cx ; AX <- 起始扇区号
LABEL_GOON_LOADING_FILE:
push bx ; 保存装载程序偏移地址
mov cl, 1 ; 1个扇区
call ReadSector ; 读扇区
; 每读一个扇区就在 "Booting " 后面打一个点, 形成这样的效果:Booting ......
mov ah, 0Eh ; 功能号(以电传方式显示单个字符)
mov al, '.' ; 要显示的字符
mov bl, 0Fh ; 黑底白字
int 10h ; 显示服务BIOS调用
; 计算文件的下一扇区号
pop bx ; 取出装载程序偏移地址
pop ax ; 取出此扇区在FAT中的序号
call GetFATEntry ; 获取FAT项中的下一簇号
cmp ax, 0FF8h ; 是否是文件最后簇
jae LABEL_FILE_LOADED ; ≥FF8h时跳转,否则读下一个簇
push ax ; 保存扇区在FAT中的序号
mov dx, RootDirSectors ; DX = 根目录扇区数 = 14
add ax, dx ; 扇区序号 + 根目录扇区数
add ax, DeltaSectorNo ; AX = 要读的数据扇区地址
add bx, [BPB_BytsPerSec] ; BX+512指向装载程序区的下一个扇区地址
jmp LABEL_GOON_LOADING_FILE
LABEL_FILE_LOADED:
mov dh, 1 ; "Ready."
call DispStr ; 显示字符串
; **********************************************************************
jmp BaseOfkernal:OffsetOfkernal ; 这一句正式跳转到已加载到内
; 存中的 kernal.BIN 的开始处,
; 开始执行 kernal.BIN 的代码。
; Boot Sector 的使命到此结束
; **********************************************************************
;==============================================================
;变量
wRootDirSizeForLoop dw RootDirSectors ; 根目录区剩余扇区数
; 初始化为14,在循环中会递减至零
wSectorNo dw 0 ; 当前扇区号,初始化为0,在循环中会递增
bOdd db 0 ; 奇数还是偶数FAT项
;字符串
kernalFileName db "KERNEL BIN", 0 ; kernal.BIN之文件名
; 为简化代码,下面每个字符串的长度均为MessageLength(=9),似串数组
MessageLength equ 9
BootMessage: db "Booting " ; 9字节,不够则用空格补齐。序号0
Message1 db "Ready. " ; 9字节,不够则用空格补齐。序号1
Message2 db "No kernal" ; 9字节,不够则用空格补齐。序号2
;==============================================================
;----------------------------------------------------------------------------
; 函数名:DispStr
;----------------------------------------------------------------------------
; 作用:显示一个字符串,函数开始时DH中须为串序号(0-based)
DispStr:
mov ax, MessageLength ; 串长->AX(即AL=9)
mul dh ; AL*DH(串序号)->AX(=当前串的相对地址)
add ax, BootMessage ; AX+串数组的起始地址
mov bp, ax ; BP=当前串的偏移地址
mov ax, ds ; ES:BP = 串地址
mov es, ax ; 置ES=DS
mov cx, MessageLength ; CX = 串长(=9)
mov ax, 1301h ; AH = 13h(功能号)、AL = 01h(光标置于串尾)
mov bx, 0007h ; 页号为0(BH = 0) 黑底白字(BL = 07h)
mov dl, 0 ; 列号=0
int 10h ; 显示服务BIOS调用
ret ; 函数返回
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; 函数名:ReadSector
;----------------------------------------------------------------------------
; 作用:从第 AX个扇区开始,将CL个扇区读入ES:BX中
ReadSector:
; -----------------------------------------------------------------------
; 怎样由扇区号求扇区在磁盘中的位置 (扇区号->柱面号、起始扇区、磁头号)
; -----------------------------------------------------------------------
; 设扇区号为 x
; ┌ 柱面号 = y >> 1
; x ┌ 商 y ┤
; -------------- => ┤ └ 磁头号 = y & 1
; 每磁道扇区数 │
; └ 余 z => 起始扇区号 = z + 1
push bp ; 保存BP
mov bp, sp ; 让BP=SP
sub sp, 2 ; 辟出两个字节的堆栈区域保存要读的扇区数: byte [bp-2]
mov byte [bp-2], cl ; 压CL入栈(保存表示读入扇区数的传递参数)
push bx ; 保存BX
mov bl, [BPB_SecPerTrk] ; BL=18(磁道扇区数)为除数
div bl ; AX/BL,商y在AL中、余数z在AH中
inc ah ; z ++(因磁盘的起始扇区号为1)
mov cl, ah ; CL <- 起始扇区号
mov dh, al ; DH <- y
shr al, 1 ; y >> 1 (等价于y/BPB_NumHeads,软盘有2个磁头)
mov ch, al ; CH <- 柱面号
and dh, 1 ; DH & 1 = 磁头号
pop bx ; 恢复BX
; 至此,"柱面号、起始扇区、磁头号"已全部得到
mov dl, [BS_DrvNum] ; 驱动器号(0表示软盘A)
.GoOnReading: ; 使用磁盘中断读入扇区
mov ah, 2 ; 功能号(读扇区)
mov al, byte [bp-2] ; 读AL个扇区
int 13h ; 磁盘服务BIOS调用
jc .GoOnReading ; 如果读取错误,CF会被置为1,
; 这时就不停地读,直到正确为止
add sp, 2 ; 栈指针+2
pop bp ; 恢复BP
ret
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; 函数名:GetFATEntry
;----------------------------------------------------------------------------
; 作用:找到序号为AX的扇区在FAT中的条目,结果放在AX中。需要注意的
; 是,中间需要读FAT的扇区到ES:BX处,所以函数一开始保存了ES和BX
GetFATEntry:
push es ; 保存ES、BX和AX(入栈)
push bx
push ax
; 设置读入的FAT扇区写入的基地址
;mov ax,BaseOfkernal ;BaseOfKernal=9000h
;sub ax, 1000h ; 在BaseOfKernal后面留出4K空间用于存放FAT
mov ax, FATSegment
mov es, ax ; ES=8000h
; 判断FAT项的奇偶
pop ax ; 取出FAT项序号(出栈)
mov byte [bOdd], 0; 初始化奇偶变量值为0(偶)
mov bx, 3 ; AX*1.5 = (AX*3)/2
mul bx ; DX:AX = AX * 3(AX*BX 的结果值放入DX:AX中)
mov bx, 2 ; BX = 2(除数)
xor dx, dx ; DX=0
div bx ; DX:AX / 2 => AX <- 商、DX <- 余数
cmp dx, 0 ; 余数 = 0(偶数)?
jz LABEL_EVEN ; 偶数跳转
mov byte [bOdd], 1 ; 奇数
LABEL_EVEN: ; 偶数
; 现在AX中是FAT项在FAT中的偏移量,下面来
; 计算FAT项在哪个扇区中(FAT占用不止一个扇区)
xor dx, dx ; DX=0
mov bx, [BPB_BytsPerSec] ; BX=512
div bx ; DX:AX / 512
; AX <- 商 (FAT项所在的扇区相对于FAT的扇区号)
; DX <- 余数 (FAT项在扇区内的偏移)
push dx ; 保存余数(入栈)
mov bx, 0 ; BX <- 0 于是,ES:BX = 8000h:0
add ax, SectorNoOfFAT1 ; 此句之后的AX就是FAT项所在的扇区号
mov cl, 2 ; 读取FAT项所在的扇区,一次读两个,避免在边界
call ReadSector ; 发生错误, 因为一个 FAT项可能跨越两个扇区
pop dx ; DX= FAT项在扇区内的偏移(出栈)
add bx, dx ; BX= FAT项在扇区内的偏移
mov ax, [es:bx] ; AX= FAT项值
cmp byte [bOdd], 1 ; 是否为奇数项?
jnz LABEL_EVEN_2 ; 偶数跳转
shr ax, 4 ; 奇数:右移4位(取高12位)
LABEL_EVEN_2: ; 偶数
and ax, 0FFFh ; 取低12位
LABEL_GET_FAT_ENRY_OK:
pop bx ; 恢复ES、BX(出栈)
pop es
ret
;----------------------------------------------------------------------------
times 510-($-$$) db 0 ; 用0填充引导扇区剩下的空间
db 55h, 0aah ; 引导扇区结束标志
| 31.082278 | 78 | 0.564244 |
656fbd87b9769700578d1d81e96907176cdce4e6 | 31 | asm | Assembly | tests/stack_and_math/div.asm | UPB-FILS-ALF/devoir-1-tests | 75ad3698f506329c609cdfe66e9fbeffe2ae03ad | [
"Apache-2.0"
] | null | null | null | tests/stack_and_math/div.asm | UPB-FILS-ALF/devoir-1-tests | 75ad3698f506329c609cdfe66e9fbeffe2ae03ad | [
"Apache-2.0"
] | null | null | null | tests/stack_and_math/div.asm | UPB-FILS-ALF/devoir-1-tests | 75ad3698f506329c609cdfe66e9fbeffe2ae03ad | [
"Apache-2.0"
] | 1 | 2021-03-25T10:58:49.000Z | 2021-03-25T10:58:49.000Z | push 55
push 3
div
stack
print
| 5.166667 | 7 | 0.774194 |
b9da81e86071799cad969453b3356b79c452a224 | 671 | asm | Assembly | AVR Studio/template/template.asm | ataniazov/AVR | 01e22a151d4c0affb7e73577c63373023260dfcb | [
"Apache-2.0"
] | null | null | null | AVR Studio/template/template.asm | ataniazov/AVR | 01e22a151d4c0affb7e73577c63373023260dfcb | [
"Apache-2.0"
] | null | null | null | AVR Studio/template/template.asm | ataniazov/AVR | 01e22a151d4c0affb7e73577c63373023260dfcb | [
"Apache-2.0"
] | null | null | null | ;============================================================
.include "m16def.inc" ; ATMega16
;= Start macro.inc ==========================================
;= End macro.inc ============================================
; RAM =======================================================
.DSEG ; RAM segment
; FLASH =====================================================
.CSEG ; Code segment
NOP
NOP
NOP
RJMP PC+2
NOP
NOP
RJMP PC-6
NOP
JMP PC
; EEPROM ====================================================
.ESEG ; EEPROM segment
;============================================================
| 27.958333 | 63 | 0.216095 |
a7eed8f88ee3822236bc42bd5ef637d8e4d4f61a | 2,135 | asm | Assembly | programs/oeis/256/A256716.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | null | null | null | programs/oeis/256/A256716.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | null | null | null | programs/oeis/256/A256716.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | null | null | null | ; A256716: a(n) = n*(n+1)*(22*n-19)/6.
; 0,1,25,94,230,455,791,1260,1884,2685,3685,4906,6370,8099,10115,12440,15096,18105,21489,25270,29470,34111,39215,44804,50900,57525,64701,72450,80794,89755,99355,109616,120560,132209,144585,157710,171606,186295,201799,218140,235340,253421,272405,292314,313170,334995,357811,381640,406504,432425,459425,487526,516750,547119,578655,611380,645316,680485,716909,754610,793610,833931,875595,918624,963040,1008865,1056121,1104830,1155014,1206695,1259895,1314636,1370940,1428829,1488325,1549450,1612226,1676675,1742819,1810680,1880280,1951641,2024785,2099734,2176510,2255135,2335631,2418020,2502324,2588565,2676765,2766946,2859130,2953339,3049595,3147920,3248336,3350865,3455529,3562350,3671350,3782551,3895975,4011644,4129580,4249805,4372341,4497210,4624434,4754035,4886035,5020456,5157320,5296649,5438465,5582790,5729646,5879055,6031039,6185620,6342820,6502661,6665165,6830354,6998250,7168875,7342251,7518400,7697344,7879105,8063705,8251166,8441510,8634759,8830935,9030060,9232156,9437245,9645349,9856490,10070690,10287971,10508355,10731864,10958520,11188345,11421361,11657590,11897054,12139775,12385775,12635076,12887700,13143669,13403005,13665730,13931866,14201435,14474459,14750960,15030960,15314481,15601545,15892174,16186390,16484215,16785671,17090780,17399564,17712045,18028245,18348186,18671890,18999379,19330675,19665800,20004776,20347625,20694369,21045030,21399630,21758191,22120735,22487284,22857860,23232485,23611181,23993970,24380874,24771915,25167115,25566496,25970080,26377889,26789945,27206270,27626886,28051815,28481079,28914700,29352700,29795101,30241925,30693194,31148930,31609155,32073891,32543160,33016984,33495385,33978385,34466006,34958270,35455199,35956815,36463140,36974196,37490005,38010589,38535970,39066170,39601211,40141115,40685904,41235600,41790225,42349801,42914350,43483894,44058455,44638055,45222716,45812460,46407309,47007285,47612410,48222706,48838195,49458899,50084840,50716040,51352521,51994305,52641414,53293870,53951695,54614911,55283540,55957604,56637125
lpb $0,1
add $2,4
add $3,$0
add $1,$3
add $2,5
add $3,$0
sub $0,1
add $3,$2
add $3,$2
lpe
| 152.5 | 1,988 | 0.844496 |
3a4ee9db3c6788a0487c70a394186827f036b85a | 131 | asm | Assembly | libsrc/target/nc100/padsetalarm.asm | jpoikela/z88dk | 7108b2d7e3a98a77de99b30c9a7c9199da9c75cb | [
"ClArtistic"
] | 640 | 2017-01-14T23:33:45.000Z | 2022-03-30T11:28:42.000Z | libsrc/target/nc100/padsetalarm.asm | jpoikela/z88dk | 7108b2d7e3a98a77de99b30c9a7c9199da9c75cb | [
"ClArtistic"
] | 1,600 | 2017-01-15T16:12:02.000Z | 2022-03-31T12:11:12.000Z | libsrc/target/nc100/padsetalarm.asm | jpoikela/z88dk | 7108b2d7e3a98a77de99b30c9a7c9199da9c75cb | [
"ClArtistic"
] | 215 | 2017-01-17T10:43:03.000Z | 2022-03-23T17:25:02.000Z |
SECTION code_clib
PUBLIC padsetalarm
PUBLIC _padsetalarm
; fastcall
.padsetalarm
._padsetalarm
jp 0xb878
| 13.1 | 33 | 0.687023 |
c97c82a8e6a776a100405e7413caec767490321a | 7,030 | asm | Assembly | ffmpeg-2.3.6/ffmpeg-2.3.6/libavcodec/x86/hevc_idct.asm | d2262272d/ffmpeg | 24614260b55822e61c4fd2da65ef3d82977f1124 | [
"MIT"
] | 16 | 2018-12-30T07:34:43.000Z | 2021-04-13T06:37:22.000Z | ffmpeg-2.3.6/ffmpeg-2.3.6/libavcodec/x86/hevc_idct.asm | d2262272d/ffmpeg | 24614260b55822e61c4fd2da65ef3d82977f1124 | [
"MIT"
] | 5 | 2018-06-22T05:52:48.000Z | 2020-10-15T22:15:25.000Z | ffmpeg-2.3.6/ffmpeg-2.3.6/libavcodec/x86/hevc_idct.asm | d2262272d/ffmpeg | 24614260b55822e61c4fd2da65ef3d82977f1124 | [
"MIT"
] | 10 | 2018-05-24T06:35:54.000Z | 2021-06-24T00:59:59.000Z | ; /*
; * Provide SSE & MMX idct functions for HEVC decoding
; * Copyright (c) 2014 Pierre-Edouard LEPERE
; *
; * This file is part of FFmpeg.
; *
; * FFmpeg is free software; you can redistribute it and/or
; * modify it under the terms of the GNU Lesser General Public
; * License as published by the Free Software Foundation; either
; * version 2.1 of the License, or (at your option) any later version.
; *
; * FFmpeg is distributed in the hope that it will be useful,
; * but WITHOUT ANY WARRANTY; without even the implied warranty of
; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
; * Lesser General Public License for more details.
; *
; * You should have received a copy of the GNU Lesser General Public
; * License along with FFmpeg; if not, write to the Free Software
; * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
; */
%include "libavutil/x86/x86util.asm"
SECTION_RODATA 32
max_pixels_10: times 16 dw ((1 << 10)-1)
dc_add_10: times 4 dd ((1 << 14-10) + 1)
SECTION_TEXT 32
;the idct_dc_add macros and functions were largely inspired by x264 project's code in the h264_idct.asm file
%macro DC_ADD_INIT 2
add %1w, ((1 << 14-8) + 1)
sar %1w, (15-8)
movd m0, %1d
lea %1, [%2*3]
SPLATW m0, m0, 0
pxor m1, m1
psubw m1, m0
packuswb m0, m0
packuswb m1, m1
%endmacro
%macro DC_ADD_INIT_AVX2 2
add %1w, ((1 << 14-8) + 1)
sar %1w, (15-8)
movd xm0, %1d
vpbroadcastw m0, xm0 ;SPLATW
lea %1, [%2*3]
pxor m1, m1
psubw m1, m0
packuswb m0, m0
packuswb m1, m1
%endmacro
%macro DC_ADD_OP 4
%1 m2, [%2 ]
%1 m3, [%2+%3 ]
%1 m4, [%2+%3*2]
%1 m5, [%2+%4 ]
paddusb m2, m0
paddusb m3, m0
paddusb m4, m0
paddusb m5, m0
psubusb m2, m1
psubusb m3, m1
psubusb m4, m1
psubusb m5, m1
%1 [%2 ], m2
%1 [%2+%3 ], m3
%1 [%2+%3*2], m4
%1 [%2+%4 ], m5
%endmacro
INIT_MMX mmxext
; void ff_hevc_idct_dc_add_8_mmxext(uint8_t *dst, int16_t *coeffs, ptrdiff_t stride)
%if ARCH_X86_64
cglobal hevc_idct4_dc_add_8, 3, 4, 0
movsx r3, word [r1]
DC_ADD_INIT r3, r2
DC_ADD_OP movh, r0, r2, r3
RET
; void ff_hevc_idct8_dc_add_8_mmxext(uint8_t *dst, int16_t *coeffs, ptrdiff_t stride)
cglobal hevc_idct8_dc_add_8, 3, 4, 0
movsx r3, word [r1]
DC_ADD_INIT r3, r2
DC_ADD_OP mova, r0, r2, r3
lea r0, [r0+r2*4]
DC_ADD_OP mova, r0, r2, r3
RET
%else
; void ff_hevc_idct_dc_add_8_mmxext(uint8_t *dst, int16_t *coeffs, ptrdiff_t stride)
cglobal hevc_idct4_dc_add_8, 2, 3, 0
movsx r2, word [r1]
mov r1, r2m
DC_ADD_INIT r2, r1
DC_ADD_OP movh, r0, r1, r2
RET
; void ff_hevc_idct8_dc_add_8_mmxext(uint8_t *dst, int16_t *coeffs, ptrdiff_t stride)
cglobal hevc_idct8_dc_add_8, 2, 3, 0
movsx r2, word [r1]
mov r1, r2m
DC_ADD_INIT r2, r1
DC_ADD_OP mova, r0, r1, r2
lea r0, [r0+r1*4]
DC_ADD_OP mova, r0, r1, r2
RET
%endif
INIT_XMM sse2
; void ff_hevc_idct16_dc_add_8_sse2(uint8_t *dst, int16_t *coeffs, ptrdiff_t stride)
cglobal hevc_idct16_dc_add_8, 3, 4, 6
movsx r3, word [r1]
DC_ADD_INIT r3, r2
DC_ADD_OP mova, r0, r2, r3
lea r0, [r0+r2*4]
DC_ADD_OP mova, r0, r2, r3
lea r0, [r0+r2*4]
DC_ADD_OP mova, r0, r2, r3
lea r0, [r0+r2*4]
DC_ADD_OP mova, r0, r2, r3
RET
%if HAVE_AVX2_EXTERNAL
INIT_YMM avx2
; void ff_hevc_idct32_dc_add_8_avx2(uint8_t *dst, int16_t *coeffs, ptrdiff_t stride)
cglobal hevc_idct32_dc_add_8, 3, 4, 6
movsx r3, word [r1]
DC_ADD_INIT_AVX2 r3, r2
DC_ADD_OP mova, r0, r2, r3,
%rep 7
lea r0, [r0+r2*4]
DC_ADD_OP mova, r0, r2, r3
%endrep
RET
%endif ;HAVE_AVX2_EXTERNAL
;-----------------------------------------------------------------------------
; void ff_hevc_idct_dc_add_10(pixel *dst, int16_t *block, int stride)
;-----------------------------------------------------------------------------
%macro IDCT_DC_ADD_OP_10 3
pxor m5, m5
%if avx_enabled
paddw m1, m0, [%1+0 ]
paddw m2, m0, [%1+%2 ]
paddw m3, m0, [%1+%2*2]
paddw m4, m0, [%1+%3 ]
%else
mova m1, [%1+0 ]
mova m2, [%1+%2 ]
mova m3, [%1+%2*2]
mova m4, [%1+%3 ]
paddw m1, m0
paddw m2, m0
paddw m3, m0
paddw m4, m0
%endif
CLIPW m1, m5, m6
CLIPW m2, m5, m6
CLIPW m3, m5, m6
CLIPW m4, m5, m6
mova [%1+0 ], m1
mova [%1+%2 ], m2
mova [%1+%2*2], m3
mova [%1+%3 ], m4
%endmacro
INIT_MMX mmxext
cglobal hevc_idct4_dc_add_10,3,3
mov r1w, [r1]
add r1w, ((1 << 4) + 1)
sar r1w, 5
movd m0, r1d
lea r1, [r2*3]
SPLATW m0, m0, 0
mova m6, [max_pixels_10]
IDCT_DC_ADD_OP_10 r0, r2, r1
RET
;-----------------------------------------------------------------------------
; void ff_hevc_idct8_dc_add_10(pixel *dst, int16_t *block, int stride)
;-----------------------------------------------------------------------------
%macro IDCT8_DC_ADD 0
cglobal hevc_idct8_dc_add_10,3,4,7
mov r1w, [r1]
add r1w, ((1 << 4) + 1)
sar r1w, 5
movd m0, r1d
lea r1, [r2*3]
SPLATW m0, m0, 0
mova m6, [max_pixels_10]
IDCT_DC_ADD_OP_10 r0, r2, r1
lea r0, [r0+r2*4]
IDCT_DC_ADD_OP_10 r0, r2, r1
RET
%endmacro
INIT_XMM sse2
IDCT8_DC_ADD
%if HAVE_AVX_EXTERNAL
INIT_XMM avx
IDCT8_DC_ADD
%endif
%if HAVE_AVX2_EXTERNAL
INIT_YMM avx2
cglobal hevc_idct16_dc_add_10,3,4,7
mov r1w, [r1]
add r1w, ((1 << 4) + 1)
sar r1w, 5
movd xm0, r1d
lea r1, [r2*3]
vpbroadcastw m0, xm0 ;SPLATW
mova m6, [max_pixels_10]
IDCT_DC_ADD_OP_10 r0, r2, r1
lea r0, [r0+r2*4]
IDCT_DC_ADD_OP_10 r0, r2, r1
lea r0, [r0+r2*4]
IDCT_DC_ADD_OP_10 r0, r2, r1
lea r0, [r0+r2*4]
IDCT_DC_ADD_OP_10 r0, r2, r1
RET
%endif ;HAVE_AVX_EXTERNAL
| 31.106195 | 108 | 0.496159 |
1a763d4333271190329747e1100368b847beb045 | 1,212 | asm | Assembly | pwnlib/shellcraft/templates/i386/cgc/syscall.asm | IMULMUL/python3-pwntools | 61210a68cd88e9084c72292d3119c38c44f07966 | [
"MIT"
] | 325 | 2016-01-25T08:38:06.000Z | 2022-03-30T14:31:50.000Z | pwnlib/shellcraft/templates/i386/cgc/syscall.asm | IMULMUL/python3-pwntools | 61210a68cd88e9084c72292d3119c38c44f07966 | [
"MIT"
] | 8 | 2016-08-23T10:15:27.000Z | 2019-01-16T02:49:34.000Z | pwnlib/shellcraft/templates/i386/cgc/syscall.asm | IMULMUL/python3-pwntools | 61210a68cd88e9084c72292d3119c38c44f07966 | [
"MIT"
] | 71 | 2016-07-13T10:03:52.000Z | 2022-01-10T11:57:34.000Z | <%
from pwnlib.shellcraft import i386
from pwnlib.constants import Constant
from pwnlib.abi import linux_i386_syscall as abi
%>
<%page args="syscall=None, arg0=None, arg1=None, arg2=None, arg3=None, arg4=None, arg5=None"/>
<%docstring>
Args: [syscall_number, \*args]
Does a syscall
Any of the arguments can be expressions to be evaluated by :func:`pwnlib.constants.eval`.
</%docstring>
<%
append_cdq = False
if isinstance(syscall, (str, Constant)) and str(syscall).startswith('SYS_'):
syscall_repr = str(syscall)[4:] + "(%s)"
args = []
else:
syscall_repr = 'syscall(%s)'
if syscall is None:
args = ['?']
else:
args = [repr(syscall)]
for arg in (arg0, arg1, arg2, arg3, arg4, arg5):
if arg is None:
args.append('?')
else:
args.append(repr(arg))
while args and args[-1] == '?':
args.pop()
syscall_repr = syscall_repr % ', '.join(args)
registers = abi.register_arguments
arguments = [syscall, arg0, arg1, arg2, arg3, arg4, arg5]
regctx = dict(zip(registers, arguments))
%>\
/* call ${syscall_repr} */
%if any(a is not None for a in arguments):
${i386.setregs(regctx)}
%endif
int 0x80
| 28.186047 | 94 | 0.629538 |
1de5d30f801afe18affb50478c40ebccf87f5dcc | 1,575 | asm | Assembly | src/assembly/fatorial.asm | DiasIuri/gold-compiler | e1b8386287f4a82188214d0ce7d409a074f7a769 | [
"MIT"
] | 2 | 2020-06-25T23:50:27.000Z | 2020-07-24T19:06:39.000Z | src/assembly/fatorial.asm | DiasIuri/gold-compiler | e1b8386287f4a82188214d0ce7d409a074f7a769 | [
"MIT"
] | null | null | null | src/assembly/fatorial.asm | DiasIuri/gold-compiler | e1b8386287f4a82188214d0ce7d409a074f7a769 | [
"MIT"
] | null | null | null | .data
bl: .asciiz "\n"
number: .word 0
fatorial: .word 0
text0: .asciiz "Digite o numero para calcular o fatorial: "
text1: .asciiz "Serio?"
text2: .asciiz "O fatorial e: 1"
text3: .asciiz "O fatorial e: "
.text
main:
# Line 4 - Output
la $a0, text0
jal printText
jal breakLine
# Line 5 - Input
jal userInput
sw $v0, number
jal breakLine
# Line 6 - If
lw $s7, number
addi $s6, $zero, 0
bge $s7, $s6, else0
if0:
# Line 7 - Output
la $a0, text1
jal printText
jal breakLine
# Line 8 - End if
j endElse0
else0:
# Line 9 - Elif
# Line 10 - If
lw $s7, number
addi $s6, $zero, 0
bne $s7, $s6, else1
if1:
# Line 11 - Output
la $a0, text2
jal printText
jal breakLine
# Line 12 - End if
j endElse1
else1:
# Line 13 - Else
# Line 14 - Assignment
lw $s7, number
sw $s7, fatorial
# Line 15 - While
lw $s7, number
addi $s6, $zero, 2
bgt $s7, $s6, while0
j endWhile0
while0:
# Line 16 - Assignment
lw $s7, number
sub $t0, $s7, 1
# Line 17 - Assignment
lw $s7, fatorial
mul $s7, $s7, $t0
sw $s7, fatorial
# Line 18 - Assignment
lw $s7, number
sub $s7, $s7, 1
sw $s7, number
# Line 19 - End while
lw $s7, number
addi $s6, $zero, 2
bgt $s7, $s6, while0
endWhile0:
# Line 20 - Output
la $a0, text3
jal printText
jal breakLine
# Line 21 - Output
lw $a0, fatorial
jal printValue
jal breakLine
# Line 22 - End if
endElse1:
endElse0:
j finishProgram
printValue:
li $v0, 1
syscall
jr $ra
printText:
li $v0, 4
syscall
jr $ra
userInput:
li $v0, 5
syscall
jr $ra
breakLine:
li $v0, 4
la $a0, bl
syscall
jr $ra
finishProgram:
li $v0, 10
syscall
| 12.401575 | 61 | 0.655238 |
cc055e79df538551ec6470713851bc4f7d1b63e0 | 55,889 | asm | Assembly | deps/openssl/asm/x64-win32-masm/aes/bsaes-x86_64.asm | gokulkrishh/node-1 | 8a79cca80cd3d4a577c680cfcb72877bcaab8df2 | [
"Artistic-2.0"
] | 1 | 2015-05-22T14:55:21.000Z | 2015-05-22T14:55:21.000Z | deps/openssl/asm/x64-win32-masm/aes/bsaes-x86_64.asm | jeffmo/node | d9fc6af32a50684930b04f0f2b701eb2fd62192b | [
"Artistic-2.0"
] | null | null | null | deps/openssl/asm/x64-win32-masm/aes/bsaes-x86_64.asm | jeffmo/node | d9fc6af32a50684930b04f0f2b701eb2fd62192b | [
"Artistic-2.0"
] | null | null | null | OPTION DOTNAME
.text$ SEGMENT ALIGN(64) 'CODE'
EXTERN asm_AES_encrypt:NEAR
EXTERN asm_AES_decrypt:NEAR
ALIGN 64
_bsaes_encrypt8 PROC PRIVATE
lea r11,QWORD PTR[$L$BS0]
movdqa xmm8,XMMWORD PTR[rax]
lea rax,QWORD PTR[16+rax]
movdqa xmm7,XMMWORD PTR[80+r11]
pxor xmm15,xmm8
pxor xmm0,xmm8
DB 102,68,15,56,0,255
pxor xmm1,xmm8
DB 102,15,56,0,199
pxor xmm2,xmm8
DB 102,15,56,0,207
pxor xmm3,xmm8
DB 102,15,56,0,215
pxor xmm4,xmm8
DB 102,15,56,0,223
pxor xmm5,xmm8
DB 102,15,56,0,231
pxor xmm6,xmm8
DB 102,15,56,0,239
DB 102,15,56,0,247
_bsaes_encrypt8_bitslice::
movdqa xmm7,XMMWORD PTR[r11]
movdqa xmm8,XMMWORD PTR[16+r11]
movdqa xmm9,xmm5
psrlq xmm5,1
movdqa xmm10,xmm3
psrlq xmm3,1
pxor xmm5,xmm6
pxor xmm3,xmm4
pand xmm5,xmm7
pand xmm3,xmm7
pxor xmm6,xmm5
psllq xmm5,1
pxor xmm4,xmm3
psllq xmm3,1
pxor xmm5,xmm9
pxor xmm3,xmm10
movdqa xmm9,xmm1
psrlq xmm1,1
movdqa xmm10,xmm15
psrlq xmm15,1
pxor xmm1,xmm2
pxor xmm15,xmm0
pand xmm1,xmm7
pand xmm15,xmm7
pxor xmm2,xmm1
psllq xmm1,1
pxor xmm0,xmm15
psllq xmm15,1
pxor xmm1,xmm9
pxor xmm15,xmm10
movdqa xmm7,XMMWORD PTR[32+r11]
movdqa xmm9,xmm4
psrlq xmm4,2
movdqa xmm10,xmm3
psrlq xmm3,2
pxor xmm4,xmm6
pxor xmm3,xmm5
pand xmm4,xmm8
pand xmm3,xmm8
pxor xmm6,xmm4
psllq xmm4,2
pxor xmm5,xmm3
psllq xmm3,2
pxor xmm4,xmm9
pxor xmm3,xmm10
movdqa xmm9,xmm0
psrlq xmm0,2
movdqa xmm10,xmm15
psrlq xmm15,2
pxor xmm0,xmm2
pxor xmm15,xmm1
pand xmm0,xmm8
pand xmm15,xmm8
pxor xmm2,xmm0
psllq xmm0,2
pxor xmm1,xmm15
psllq xmm15,2
pxor xmm0,xmm9
pxor xmm15,xmm10
movdqa xmm9,xmm2
psrlq xmm2,4
movdqa xmm10,xmm1
psrlq xmm1,4
pxor xmm2,xmm6
pxor xmm1,xmm5
pand xmm2,xmm7
pand xmm1,xmm7
pxor xmm6,xmm2
psllq xmm2,4
pxor xmm5,xmm1
psllq xmm1,4
pxor xmm2,xmm9
pxor xmm1,xmm10
movdqa xmm9,xmm0
psrlq xmm0,4
movdqa xmm10,xmm15
psrlq xmm15,4
pxor xmm0,xmm4
pxor xmm15,xmm3
pand xmm0,xmm7
pand xmm15,xmm7
pxor xmm4,xmm0
psllq xmm0,4
pxor xmm3,xmm15
psllq xmm15,4
pxor xmm0,xmm9
pxor xmm15,xmm10
dec r10d
jmp $L$enc_sbox
ALIGN 16
$L$enc_loop::
pxor xmm15,XMMWORD PTR[rax]
pxor xmm0,XMMWORD PTR[16+rax]
DB 102,68,15,56,0,255
pxor xmm1,XMMWORD PTR[32+rax]
DB 102,15,56,0,199
pxor xmm2,XMMWORD PTR[48+rax]
DB 102,15,56,0,207
pxor xmm3,XMMWORD PTR[64+rax]
DB 102,15,56,0,215
pxor xmm4,XMMWORD PTR[80+rax]
DB 102,15,56,0,223
pxor xmm5,XMMWORD PTR[96+rax]
DB 102,15,56,0,231
pxor xmm6,XMMWORD PTR[112+rax]
DB 102,15,56,0,239
lea rax,QWORD PTR[128+rax]
DB 102,15,56,0,247
$L$enc_sbox::
pxor xmm4,xmm5
pxor xmm1,xmm0
pxor xmm2,xmm15
pxor xmm5,xmm1
pxor xmm4,xmm15
pxor xmm5,xmm2
pxor xmm2,xmm6
pxor xmm6,xmm4
pxor xmm2,xmm3
pxor xmm3,xmm4
pxor xmm2,xmm0
pxor xmm1,xmm6
pxor xmm0,xmm4
movdqa xmm10,xmm6
movdqa xmm9,xmm0
movdqa xmm8,xmm4
movdqa xmm12,xmm1
movdqa xmm11,xmm5
pxor xmm10,xmm3
pxor xmm9,xmm1
pxor xmm8,xmm2
movdqa xmm13,xmm10
pxor xmm12,xmm3
movdqa xmm7,xmm9
pxor xmm11,xmm15
movdqa xmm14,xmm10
por xmm9,xmm8
por xmm10,xmm11
pxor xmm14,xmm7
pand xmm13,xmm11
pxor xmm11,xmm8
pand xmm7,xmm8
pand xmm14,xmm11
movdqa xmm11,xmm2
pxor xmm11,xmm15
pand xmm12,xmm11
pxor xmm10,xmm12
pxor xmm9,xmm12
movdqa xmm12,xmm6
movdqa xmm11,xmm4
pxor xmm12,xmm0
pxor xmm11,xmm5
movdqa xmm8,xmm12
pand xmm12,xmm11
por xmm8,xmm11
pxor xmm7,xmm12
pxor xmm10,xmm14
pxor xmm9,xmm13
pxor xmm8,xmm14
movdqa xmm11,xmm1
pxor xmm7,xmm13
movdqa xmm12,xmm3
pxor xmm8,xmm13
movdqa xmm13,xmm0
pand xmm11,xmm2
movdqa xmm14,xmm6
pand xmm12,xmm15
pand xmm13,xmm4
por xmm14,xmm5
pxor xmm10,xmm11
pxor xmm9,xmm12
pxor xmm8,xmm13
pxor xmm7,xmm14
movdqa xmm11,xmm10
pand xmm10,xmm8
pxor xmm11,xmm9
movdqa xmm13,xmm7
movdqa xmm14,xmm11
pxor xmm13,xmm10
pand xmm14,xmm13
movdqa xmm12,xmm8
pxor xmm14,xmm9
pxor xmm12,xmm7
pxor xmm10,xmm9
pand xmm12,xmm10
movdqa xmm9,xmm13
pxor xmm12,xmm7
pxor xmm9,xmm12
pxor xmm8,xmm12
pand xmm9,xmm7
pxor xmm13,xmm9
pxor xmm8,xmm9
pand xmm13,xmm14
pxor xmm13,xmm11
movdqa xmm11,xmm5
movdqa xmm7,xmm4
movdqa xmm9,xmm14
pxor xmm9,xmm13
pand xmm9,xmm5
pxor xmm5,xmm4
pand xmm4,xmm14
pand xmm5,xmm13
pxor xmm5,xmm4
pxor xmm4,xmm9
pxor xmm11,xmm15
pxor xmm7,xmm2
pxor xmm14,xmm12
pxor xmm13,xmm8
movdqa xmm10,xmm14
movdqa xmm9,xmm12
pxor xmm10,xmm13
pxor xmm9,xmm8
pand xmm10,xmm11
pand xmm9,xmm15
pxor xmm11,xmm7
pxor xmm15,xmm2
pand xmm7,xmm14
pand xmm2,xmm12
pand xmm11,xmm13
pand xmm15,xmm8
pxor xmm7,xmm11
pxor xmm15,xmm2
pxor xmm11,xmm10
pxor xmm2,xmm9
pxor xmm5,xmm11
pxor xmm15,xmm11
pxor xmm4,xmm7
pxor xmm2,xmm7
movdqa xmm11,xmm6
movdqa xmm7,xmm0
pxor xmm11,xmm3
pxor xmm7,xmm1
movdqa xmm10,xmm14
movdqa xmm9,xmm12
pxor xmm10,xmm13
pxor xmm9,xmm8
pand xmm10,xmm11
pand xmm9,xmm3
pxor xmm11,xmm7
pxor xmm3,xmm1
pand xmm7,xmm14
pand xmm1,xmm12
pand xmm11,xmm13
pand xmm3,xmm8
pxor xmm7,xmm11
pxor xmm3,xmm1
pxor xmm11,xmm10
pxor xmm1,xmm9
pxor xmm14,xmm12
pxor xmm13,xmm8
movdqa xmm10,xmm14
pxor xmm10,xmm13
pand xmm10,xmm6
pxor xmm6,xmm0
pand xmm0,xmm14
pand xmm6,xmm13
pxor xmm6,xmm0
pxor xmm0,xmm10
pxor xmm6,xmm11
pxor xmm3,xmm11
pxor xmm0,xmm7
pxor xmm1,xmm7
pxor xmm6,xmm15
pxor xmm0,xmm5
pxor xmm3,xmm6
pxor xmm5,xmm15
pxor xmm15,xmm0
pxor xmm0,xmm4
pxor xmm4,xmm1
pxor xmm1,xmm2
pxor xmm2,xmm4
pxor xmm3,xmm4
pxor xmm5,xmm2
dec r10d
jl $L$enc_done
pshufd xmm7,xmm15,093h
pshufd xmm8,xmm0,093h
pxor xmm15,xmm7
pshufd xmm9,xmm3,093h
pxor xmm0,xmm8
pshufd xmm10,xmm5,093h
pxor xmm3,xmm9
pshufd xmm11,xmm2,093h
pxor xmm5,xmm10
pshufd xmm12,xmm6,093h
pxor xmm2,xmm11
pshufd xmm13,xmm1,093h
pxor xmm6,xmm12
pshufd xmm14,xmm4,093h
pxor xmm1,xmm13
pxor xmm4,xmm14
pxor xmm8,xmm15
pxor xmm7,xmm4
pxor xmm8,xmm4
pshufd xmm15,xmm15,04Eh
pxor xmm9,xmm0
pshufd xmm0,xmm0,04Eh
pxor xmm12,xmm2
pxor xmm15,xmm7
pxor xmm13,xmm6
pxor xmm0,xmm8
pxor xmm11,xmm5
pshufd xmm7,xmm2,04Eh
pxor xmm14,xmm1
pshufd xmm8,xmm6,04Eh
pxor xmm10,xmm3
pshufd xmm2,xmm5,04Eh
pxor xmm10,xmm4
pshufd xmm6,xmm4,04Eh
pxor xmm11,xmm4
pshufd xmm5,xmm1,04Eh
pxor xmm7,xmm11
pshufd xmm1,xmm3,04Eh
pxor xmm8,xmm12
pxor xmm2,xmm10
pxor xmm6,xmm14
pxor xmm5,xmm13
movdqa xmm3,xmm7
pxor xmm1,xmm9
movdqa xmm4,xmm8
movdqa xmm7,XMMWORD PTR[48+r11]
jnz $L$enc_loop
movdqa xmm7,XMMWORD PTR[64+r11]
jmp $L$enc_loop
ALIGN 16
$L$enc_done::
movdqa xmm7,XMMWORD PTR[r11]
movdqa xmm8,XMMWORD PTR[16+r11]
movdqa xmm9,xmm1
psrlq xmm1,1
movdqa xmm10,xmm2
psrlq xmm2,1
pxor xmm1,xmm4
pxor xmm2,xmm6
pand xmm1,xmm7
pand xmm2,xmm7
pxor xmm4,xmm1
psllq xmm1,1
pxor xmm6,xmm2
psllq xmm2,1
pxor xmm1,xmm9
pxor xmm2,xmm10
movdqa xmm9,xmm3
psrlq xmm3,1
movdqa xmm10,xmm15
psrlq xmm15,1
pxor xmm3,xmm5
pxor xmm15,xmm0
pand xmm3,xmm7
pand xmm15,xmm7
pxor xmm5,xmm3
psllq xmm3,1
pxor xmm0,xmm15
psllq xmm15,1
pxor xmm3,xmm9
pxor xmm15,xmm10
movdqa xmm7,XMMWORD PTR[32+r11]
movdqa xmm9,xmm6
psrlq xmm6,2
movdqa xmm10,xmm2
psrlq xmm2,2
pxor xmm6,xmm4
pxor xmm2,xmm1
pand xmm6,xmm8
pand xmm2,xmm8
pxor xmm4,xmm6
psllq xmm6,2
pxor xmm1,xmm2
psllq xmm2,2
pxor xmm6,xmm9
pxor xmm2,xmm10
movdqa xmm9,xmm0
psrlq xmm0,2
movdqa xmm10,xmm15
psrlq xmm15,2
pxor xmm0,xmm5
pxor xmm15,xmm3
pand xmm0,xmm8
pand xmm15,xmm8
pxor xmm5,xmm0
psllq xmm0,2
pxor xmm3,xmm15
psllq xmm15,2
pxor xmm0,xmm9
pxor xmm15,xmm10
movdqa xmm9,xmm5
psrlq xmm5,4
movdqa xmm10,xmm3
psrlq xmm3,4
pxor xmm5,xmm4
pxor xmm3,xmm1
pand xmm5,xmm7
pand xmm3,xmm7
pxor xmm4,xmm5
psllq xmm5,4
pxor xmm1,xmm3
psllq xmm3,4
pxor xmm5,xmm9
pxor xmm3,xmm10
movdqa xmm9,xmm0
psrlq xmm0,4
movdqa xmm10,xmm15
psrlq xmm15,4
pxor xmm0,xmm6
pxor xmm15,xmm2
pand xmm0,xmm7
pand xmm15,xmm7
pxor xmm6,xmm0
psllq xmm0,4
pxor xmm2,xmm15
psllq xmm15,4
pxor xmm0,xmm9
pxor xmm15,xmm10
movdqa xmm7,XMMWORD PTR[rax]
pxor xmm3,xmm7
pxor xmm5,xmm7
pxor xmm2,xmm7
pxor xmm6,xmm7
pxor xmm1,xmm7
pxor xmm4,xmm7
pxor xmm15,xmm7
pxor xmm0,xmm7
DB 0F3h,0C3h ;repret
_bsaes_encrypt8 ENDP
ALIGN 64
_bsaes_decrypt8 PROC PRIVATE
lea r11,QWORD PTR[$L$BS0]
movdqa xmm8,XMMWORD PTR[rax]
lea rax,QWORD PTR[16+rax]
movdqa xmm7,XMMWORD PTR[((-48))+r11]
pxor xmm15,xmm8
pxor xmm0,xmm8
DB 102,68,15,56,0,255
pxor xmm1,xmm8
DB 102,15,56,0,199
pxor xmm2,xmm8
DB 102,15,56,0,207
pxor xmm3,xmm8
DB 102,15,56,0,215
pxor xmm4,xmm8
DB 102,15,56,0,223
pxor xmm5,xmm8
DB 102,15,56,0,231
pxor xmm6,xmm8
DB 102,15,56,0,239
DB 102,15,56,0,247
movdqa xmm7,XMMWORD PTR[r11]
movdqa xmm8,XMMWORD PTR[16+r11]
movdqa xmm9,xmm5
psrlq xmm5,1
movdqa xmm10,xmm3
psrlq xmm3,1
pxor xmm5,xmm6
pxor xmm3,xmm4
pand xmm5,xmm7
pand xmm3,xmm7
pxor xmm6,xmm5
psllq xmm5,1
pxor xmm4,xmm3
psllq xmm3,1
pxor xmm5,xmm9
pxor xmm3,xmm10
movdqa xmm9,xmm1
psrlq xmm1,1
movdqa xmm10,xmm15
psrlq xmm15,1
pxor xmm1,xmm2
pxor xmm15,xmm0
pand xmm1,xmm7
pand xmm15,xmm7
pxor xmm2,xmm1
psllq xmm1,1
pxor xmm0,xmm15
psllq xmm15,1
pxor xmm1,xmm9
pxor xmm15,xmm10
movdqa xmm7,XMMWORD PTR[32+r11]
movdqa xmm9,xmm4
psrlq xmm4,2
movdqa xmm10,xmm3
psrlq xmm3,2
pxor xmm4,xmm6
pxor xmm3,xmm5
pand xmm4,xmm8
pand xmm3,xmm8
pxor xmm6,xmm4
psllq xmm4,2
pxor xmm5,xmm3
psllq xmm3,2
pxor xmm4,xmm9
pxor xmm3,xmm10
movdqa xmm9,xmm0
psrlq xmm0,2
movdqa xmm10,xmm15
psrlq xmm15,2
pxor xmm0,xmm2
pxor xmm15,xmm1
pand xmm0,xmm8
pand xmm15,xmm8
pxor xmm2,xmm0
psllq xmm0,2
pxor xmm1,xmm15
psllq xmm15,2
pxor xmm0,xmm9
pxor xmm15,xmm10
movdqa xmm9,xmm2
psrlq xmm2,4
movdqa xmm10,xmm1
psrlq xmm1,4
pxor xmm2,xmm6
pxor xmm1,xmm5
pand xmm2,xmm7
pand xmm1,xmm7
pxor xmm6,xmm2
psllq xmm2,4
pxor xmm5,xmm1
psllq xmm1,4
pxor xmm2,xmm9
pxor xmm1,xmm10
movdqa xmm9,xmm0
psrlq xmm0,4
movdqa xmm10,xmm15
psrlq xmm15,4
pxor xmm0,xmm4
pxor xmm15,xmm3
pand xmm0,xmm7
pand xmm15,xmm7
pxor xmm4,xmm0
psllq xmm0,4
pxor xmm3,xmm15
psllq xmm15,4
pxor xmm0,xmm9
pxor xmm15,xmm10
dec r10d
jmp $L$dec_sbox
ALIGN 16
$L$dec_loop::
pxor xmm15,XMMWORD PTR[rax]
pxor xmm0,XMMWORD PTR[16+rax]
DB 102,68,15,56,0,255
pxor xmm1,XMMWORD PTR[32+rax]
DB 102,15,56,0,199
pxor xmm2,XMMWORD PTR[48+rax]
DB 102,15,56,0,207
pxor xmm3,XMMWORD PTR[64+rax]
DB 102,15,56,0,215
pxor xmm4,XMMWORD PTR[80+rax]
DB 102,15,56,0,223
pxor xmm5,XMMWORD PTR[96+rax]
DB 102,15,56,0,231
pxor xmm6,XMMWORD PTR[112+rax]
DB 102,15,56,0,239
lea rax,QWORD PTR[128+rax]
DB 102,15,56,0,247
$L$dec_sbox::
pxor xmm2,xmm3
pxor xmm3,xmm6
pxor xmm1,xmm6
pxor xmm5,xmm3
pxor xmm6,xmm5
pxor xmm0,xmm6
pxor xmm15,xmm0
pxor xmm1,xmm4
pxor xmm2,xmm15
pxor xmm4,xmm15
pxor xmm0,xmm2
movdqa xmm10,xmm2
movdqa xmm9,xmm6
movdqa xmm8,xmm0
movdqa xmm12,xmm3
movdqa xmm11,xmm4
pxor xmm10,xmm15
pxor xmm9,xmm3
pxor xmm8,xmm5
movdqa xmm13,xmm10
pxor xmm12,xmm15
movdqa xmm7,xmm9
pxor xmm11,xmm1
movdqa xmm14,xmm10
por xmm9,xmm8
por xmm10,xmm11
pxor xmm14,xmm7
pand xmm13,xmm11
pxor xmm11,xmm8
pand xmm7,xmm8
pand xmm14,xmm11
movdqa xmm11,xmm5
pxor xmm11,xmm1
pand xmm12,xmm11
pxor xmm10,xmm12
pxor xmm9,xmm12
movdqa xmm12,xmm2
movdqa xmm11,xmm0
pxor xmm12,xmm6
pxor xmm11,xmm4
movdqa xmm8,xmm12
pand xmm12,xmm11
por xmm8,xmm11
pxor xmm7,xmm12
pxor xmm10,xmm14
pxor xmm9,xmm13
pxor xmm8,xmm14
movdqa xmm11,xmm3
pxor xmm7,xmm13
movdqa xmm12,xmm15
pxor xmm8,xmm13
movdqa xmm13,xmm6
pand xmm11,xmm5
movdqa xmm14,xmm2
pand xmm12,xmm1
pand xmm13,xmm0
por xmm14,xmm4
pxor xmm10,xmm11
pxor xmm9,xmm12
pxor xmm8,xmm13
pxor xmm7,xmm14
movdqa xmm11,xmm10
pand xmm10,xmm8
pxor xmm11,xmm9
movdqa xmm13,xmm7
movdqa xmm14,xmm11
pxor xmm13,xmm10
pand xmm14,xmm13
movdqa xmm12,xmm8
pxor xmm14,xmm9
pxor xmm12,xmm7
pxor xmm10,xmm9
pand xmm12,xmm10
movdqa xmm9,xmm13
pxor xmm12,xmm7
pxor xmm9,xmm12
pxor xmm8,xmm12
pand xmm9,xmm7
pxor xmm13,xmm9
pxor xmm8,xmm9
pand xmm13,xmm14
pxor xmm13,xmm11
movdqa xmm11,xmm4
movdqa xmm7,xmm0
movdqa xmm9,xmm14
pxor xmm9,xmm13
pand xmm9,xmm4
pxor xmm4,xmm0
pand xmm0,xmm14
pand xmm4,xmm13
pxor xmm4,xmm0
pxor xmm0,xmm9
pxor xmm11,xmm1
pxor xmm7,xmm5
pxor xmm14,xmm12
pxor xmm13,xmm8
movdqa xmm10,xmm14
movdqa xmm9,xmm12
pxor xmm10,xmm13
pxor xmm9,xmm8
pand xmm10,xmm11
pand xmm9,xmm1
pxor xmm11,xmm7
pxor xmm1,xmm5
pand xmm7,xmm14
pand xmm5,xmm12
pand xmm11,xmm13
pand xmm1,xmm8
pxor xmm7,xmm11
pxor xmm1,xmm5
pxor xmm11,xmm10
pxor xmm5,xmm9
pxor xmm4,xmm11
pxor xmm1,xmm11
pxor xmm0,xmm7
pxor xmm5,xmm7
movdqa xmm11,xmm2
movdqa xmm7,xmm6
pxor xmm11,xmm15
pxor xmm7,xmm3
movdqa xmm10,xmm14
movdqa xmm9,xmm12
pxor xmm10,xmm13
pxor xmm9,xmm8
pand xmm10,xmm11
pand xmm9,xmm15
pxor xmm11,xmm7
pxor xmm15,xmm3
pand xmm7,xmm14
pand xmm3,xmm12
pand xmm11,xmm13
pand xmm15,xmm8
pxor xmm7,xmm11
pxor xmm15,xmm3
pxor xmm11,xmm10
pxor xmm3,xmm9
pxor xmm14,xmm12
pxor xmm13,xmm8
movdqa xmm10,xmm14
pxor xmm10,xmm13
pand xmm10,xmm2
pxor xmm2,xmm6
pand xmm6,xmm14
pand xmm2,xmm13
pxor xmm2,xmm6
pxor xmm6,xmm10
pxor xmm2,xmm11
pxor xmm15,xmm11
pxor xmm6,xmm7
pxor xmm3,xmm7
pxor xmm0,xmm6
pxor xmm5,xmm4
pxor xmm3,xmm0
pxor xmm1,xmm6
pxor xmm4,xmm6
pxor xmm3,xmm1
pxor xmm6,xmm15
pxor xmm3,xmm4
pxor xmm2,xmm5
pxor xmm5,xmm0
pxor xmm2,xmm3
pxor xmm3,xmm15
pxor xmm6,xmm2
dec r10d
jl $L$dec_done
pshufd xmm14,xmm4,093h
movdqa xmm9,xmm5
pxor xmm4,xmm6
pxor xmm5,xmm6
pshufd xmm7,xmm15,093h
movdqa xmm12,xmm6
pxor xmm6,xmm15
pxor xmm15,xmm0
pshufd xmm8,xmm0,093h
pxor xmm0,xmm5
pxor xmm15,xmm2
pxor xmm0,xmm3
pshufd xmm10,xmm3,093h
pxor xmm5,xmm15
pxor xmm3,xmm4
pxor xmm4,xmm2
pshufd xmm13,xmm2,093h
movdqa xmm11,xmm1
pxor xmm2,xmm1
pxor xmm1,xmm3
pxor xmm3,xmm4
pxor xmm2,xmm12
pxor xmm3,xmm9
pxor xmm3,xmm11
pshufd xmm12,xmm12,093h
pxor xmm6,xmm4
pxor xmm4,xmm7
pxor xmm6,xmm8
pshufd xmm9,xmm9,093h
pxor xmm4,xmm12
pxor xmm6,xmm13
pxor xmm4,xmm14
pshufd xmm11,xmm11,093h
pxor xmm14,xmm13
pxor xmm6,xmm4
pxor xmm5,xmm7
pshufd xmm7,xmm7,093h
pxor xmm15,xmm8
pxor xmm0,xmm8
pxor xmm15,xmm9
pshufd xmm8,xmm8,093h
pxor xmm5,xmm9
pxor xmm3,xmm9
pxor xmm15,xmm14
pshufd xmm9,xmm9,093h
pxor xmm5,xmm10
pxor xmm1,xmm10
pxor xmm0,xmm10
pshufd xmm10,xmm10,093h
pxor xmm2,xmm11
pxor xmm3,xmm11
pxor xmm2,xmm14
pxor xmm5,xmm12
pxor xmm0,xmm11
pxor xmm14,xmm12
pxor xmm3,xmm14
pshufd xmm11,xmm11,093h
pxor xmm1,xmm14
pxor xmm0,xmm14
pxor xmm14,xmm12
pshufd xmm12,xmm12,093h
pxor xmm14,xmm13
pxor xmm0,xmm2
pxor xmm2,xmm11
pshufd xmm13,xmm13,093h
pxor xmm15,xmm7
pxor xmm2,xmm12
pxor xmm15,xmm9
pshufd xmm14,xmm14,093h
pxor xmm5,xmm6
pxor xmm6,xmm8
pxor xmm4,xmm7
pxor xmm5,xmm7
pxor xmm6,xmm12
pxor xmm4,xmm12
pxor xmm6,xmm14
pshufd xmm7,xmm7,093h
pxor xmm4,xmm13
pxor xmm5,xmm6
pxor xmm0,xmm8
pshufd xmm8,xmm8,093h
pxor xmm2,xmm14
pxor xmm0,xmm9
pxor xmm3,xmm9
pshufd xmm9,xmm9,093h
pxor xmm15,xmm13
pxor xmm13,xmm10
pxor xmm0,xmm2
pxor xmm5,xmm13
pxor xmm1,xmm13
pxor xmm3,xmm12
pxor xmm1,xmm11
pshufd xmm11,xmm11,093h
pxor xmm3,xmm13
pxor xmm1,xmm14
pxor xmm13,xmm10
pshufd xmm12,xmm12,093h
pshufd xmm13,xmm13,093h
pshufd xmm14,xmm14,093h
pshufd xmm10,xmm10,093h
pxor xmm0,xmm6
pxor xmm8,xmm6
pxor xmm7,xmm12
pxor xmm8,xmm12
pxor xmm5,xmm7
pxor xmm7,xmm4
pxor xmm8,xmm13
pxor xmm13,xmm14
pxor xmm0,xmm8
pxor xmm2,xmm11
pxor xmm11,xmm0
pxor xmm1,xmm10
pxor xmm10,xmm5
pxor xmm3,xmm9
pxor xmm9,xmm15
pxor xmm10,xmm14
pxor xmm12,xmm3
pxor xmm9,xmm13
pxor xmm12,xmm13
pxor xmm13,xmm1
pxor xmm14,xmm2
movdqa xmm15,xmm7
movdqa xmm0,xmm8
movdqa xmm1,xmm9
movdqa xmm2,xmm10
movdqa xmm3,xmm11
movdqa xmm4,xmm12
movdqa xmm5,xmm13
movdqa xmm6,xmm14
movdqa xmm7,XMMWORD PTR[((-16))+r11]
jnz $L$dec_loop
movdqa xmm7,XMMWORD PTR[((-32))+r11]
jmp $L$dec_loop
ALIGN 16
$L$dec_done::
movdqa xmm7,XMMWORD PTR[r11]
movdqa xmm8,XMMWORD PTR[16+r11]
movdqa xmm9,xmm2
psrlq xmm2,1
movdqa xmm10,xmm1
psrlq xmm1,1
pxor xmm2,xmm4
pxor xmm1,xmm6
pand xmm2,xmm7
pand xmm1,xmm7
pxor xmm4,xmm2
psllq xmm2,1
pxor xmm6,xmm1
psllq xmm1,1
pxor xmm2,xmm9
pxor xmm1,xmm10
movdqa xmm9,xmm5
psrlq xmm5,1
movdqa xmm10,xmm15
psrlq xmm15,1
pxor xmm5,xmm3
pxor xmm15,xmm0
pand xmm5,xmm7
pand xmm15,xmm7
pxor xmm3,xmm5
psllq xmm5,1
pxor xmm0,xmm15
psllq xmm15,1
pxor xmm5,xmm9
pxor xmm15,xmm10
movdqa xmm7,XMMWORD PTR[32+r11]
movdqa xmm9,xmm6
psrlq xmm6,2
movdqa xmm10,xmm1
psrlq xmm1,2
pxor xmm6,xmm4
pxor xmm1,xmm2
pand xmm6,xmm8
pand xmm1,xmm8
pxor xmm4,xmm6
psllq xmm6,2
pxor xmm2,xmm1
psllq xmm1,2
pxor xmm6,xmm9
pxor xmm1,xmm10
movdqa xmm9,xmm0
psrlq xmm0,2
movdqa xmm10,xmm15
psrlq xmm15,2
pxor xmm0,xmm3
pxor xmm15,xmm5
pand xmm0,xmm8
pand xmm15,xmm8
pxor xmm3,xmm0
psllq xmm0,2
pxor xmm5,xmm15
psllq xmm15,2
pxor xmm0,xmm9
pxor xmm15,xmm10
movdqa xmm9,xmm3
psrlq xmm3,4
movdqa xmm10,xmm5
psrlq xmm5,4
pxor xmm3,xmm4
pxor xmm5,xmm2
pand xmm3,xmm7
pand xmm5,xmm7
pxor xmm4,xmm3
psllq xmm3,4
pxor xmm2,xmm5
psllq xmm5,4
pxor xmm3,xmm9
pxor xmm5,xmm10
movdqa xmm9,xmm0
psrlq xmm0,4
movdqa xmm10,xmm15
psrlq xmm15,4
pxor xmm0,xmm6
pxor xmm15,xmm1
pand xmm0,xmm7
pand xmm15,xmm7
pxor xmm6,xmm0
psllq xmm0,4
pxor xmm1,xmm15
psllq xmm15,4
pxor xmm0,xmm9
pxor xmm15,xmm10
movdqa xmm7,XMMWORD PTR[rax]
pxor xmm5,xmm7
pxor xmm3,xmm7
pxor xmm1,xmm7
pxor xmm6,xmm7
pxor xmm2,xmm7
pxor xmm4,xmm7
pxor xmm15,xmm7
pxor xmm0,xmm7
DB 0F3h,0C3h ;repret
_bsaes_decrypt8 ENDP
ALIGN 16
_bsaes_key_convert PROC PRIVATE
lea r11,QWORD PTR[$L$masks]
movdqu xmm7,XMMWORD PTR[rcx]
lea rcx,QWORD PTR[16+rcx]
movdqa xmm0,XMMWORD PTR[r11]
movdqa xmm1,XMMWORD PTR[16+r11]
movdqa xmm2,XMMWORD PTR[32+r11]
movdqa xmm3,XMMWORD PTR[48+r11]
movdqa xmm4,XMMWORD PTR[64+r11]
pcmpeqd xmm5,xmm5
movdqu xmm6,XMMWORD PTR[rcx]
movdqa XMMWORD PTR[rax],xmm7
lea rax,QWORD PTR[16+rax]
dec r10d
jmp $L$key_loop
ALIGN 16
$L$key_loop::
DB 102,15,56,0,244
movdqa xmm8,xmm0
movdqa xmm9,xmm1
pand xmm8,xmm6
pand xmm9,xmm6
movdqa xmm10,xmm2
pcmpeqb xmm8,xmm0
psllq xmm0,4
movdqa xmm11,xmm3
pcmpeqb xmm9,xmm1
psllq xmm1,4
pand xmm10,xmm6
pand xmm11,xmm6
movdqa xmm12,xmm0
pcmpeqb xmm10,xmm2
psllq xmm2,4
movdqa xmm13,xmm1
pcmpeqb xmm11,xmm3
psllq xmm3,4
movdqa xmm14,xmm2
movdqa xmm15,xmm3
pxor xmm8,xmm5
pxor xmm9,xmm5
pand xmm12,xmm6
pand xmm13,xmm6
movdqa XMMWORD PTR[rax],xmm8
pcmpeqb xmm12,xmm0
psrlq xmm0,4
movdqa XMMWORD PTR[16+rax],xmm9
pcmpeqb xmm13,xmm1
psrlq xmm1,4
lea rcx,QWORD PTR[16+rcx]
pand xmm14,xmm6
pand xmm15,xmm6
movdqa XMMWORD PTR[32+rax],xmm10
pcmpeqb xmm14,xmm2
psrlq xmm2,4
movdqa XMMWORD PTR[48+rax],xmm11
pcmpeqb xmm15,xmm3
psrlq xmm3,4
movdqu xmm6,XMMWORD PTR[rcx]
pxor xmm13,xmm5
pxor xmm14,xmm5
movdqa XMMWORD PTR[64+rax],xmm12
movdqa XMMWORD PTR[80+rax],xmm13
movdqa XMMWORD PTR[96+rax],xmm14
movdqa XMMWORD PTR[112+rax],xmm15
lea rax,QWORD PTR[128+rax]
dec r10d
jnz $L$key_loop
movdqa xmm7,XMMWORD PTR[80+r11]
DB 0F3h,0C3h ;repret
_bsaes_key_convert ENDP
EXTERN asm_AES_cbc_encrypt:NEAR
PUBLIC bsaes_cbc_encrypt
ALIGN 16
bsaes_cbc_encrypt PROC PUBLIC
mov r11d,DWORD PTR[48+rsp]
cmp r11d,0
jne asm_AES_cbc_encrypt
cmp r8,128
jb asm_AES_cbc_encrypt
mov rax,rsp
$L$cbc_dec_prologue::
push rbp
push rbx
push r12
push r13
push r14
push r15
lea rsp,QWORD PTR[((-72))+rsp]
mov r10,QWORD PTR[160+rsp]
lea rsp,QWORD PTR[((-160))+rsp]
movaps XMMWORD PTR[64+rsp],xmm6
movaps XMMWORD PTR[80+rsp],xmm7
movaps XMMWORD PTR[96+rsp],xmm8
movaps XMMWORD PTR[112+rsp],xmm9
movaps XMMWORD PTR[128+rsp],xmm10
movaps XMMWORD PTR[144+rsp],xmm11
movaps XMMWORD PTR[160+rsp],xmm12
movaps XMMWORD PTR[176+rsp],xmm13
movaps XMMWORD PTR[192+rsp],xmm14
movaps XMMWORD PTR[208+rsp],xmm15
$L$cbc_dec_body::
mov rbp,rsp
mov eax,DWORD PTR[240+r9]
mov r12,rcx
mov r13,rdx
mov r14,r8
mov r15,r9
mov rbx,r10
shr r14,4
mov edx,eax
shl rax,7
sub rax,96
sub rsp,rax
mov rax,rsp
mov rcx,r15
mov r10d,edx
call _bsaes_key_convert
pxor xmm7,XMMWORD PTR[rsp]
movdqa XMMWORD PTR[rax],xmm6
movdqa XMMWORD PTR[rsp],xmm7
movdqu xmm14,XMMWORD PTR[rbx]
sub r14,8
$L$cbc_dec_loop::
movdqu xmm15,XMMWORD PTR[r12]
movdqu xmm0,XMMWORD PTR[16+r12]
movdqu xmm1,XMMWORD PTR[32+r12]
movdqu xmm2,XMMWORD PTR[48+r12]
movdqu xmm3,XMMWORD PTR[64+r12]
movdqu xmm4,XMMWORD PTR[80+r12]
mov rax,rsp
movdqu xmm5,XMMWORD PTR[96+r12]
mov r10d,edx
movdqu xmm6,XMMWORD PTR[112+r12]
movdqa XMMWORD PTR[32+rbp],xmm14
call _bsaes_decrypt8
pxor xmm15,XMMWORD PTR[32+rbp]
movdqu xmm7,XMMWORD PTR[r12]
movdqu xmm8,XMMWORD PTR[16+r12]
pxor xmm0,xmm7
movdqu xmm9,XMMWORD PTR[32+r12]
pxor xmm5,xmm8
movdqu xmm10,XMMWORD PTR[48+r12]
pxor xmm3,xmm9
movdqu xmm11,XMMWORD PTR[64+r12]
pxor xmm1,xmm10
movdqu xmm12,XMMWORD PTR[80+r12]
pxor xmm6,xmm11
movdqu xmm13,XMMWORD PTR[96+r12]
pxor xmm2,xmm12
movdqu xmm14,XMMWORD PTR[112+r12]
pxor xmm4,xmm13
movdqu XMMWORD PTR[r13],xmm15
lea r12,QWORD PTR[128+r12]
movdqu XMMWORD PTR[16+r13],xmm0
movdqu XMMWORD PTR[32+r13],xmm5
movdqu XMMWORD PTR[48+r13],xmm3
movdqu XMMWORD PTR[64+r13],xmm1
movdqu XMMWORD PTR[80+r13],xmm6
movdqu XMMWORD PTR[96+r13],xmm2
movdqu XMMWORD PTR[112+r13],xmm4
lea r13,QWORD PTR[128+r13]
sub r14,8
jnc $L$cbc_dec_loop
add r14,8
jz $L$cbc_dec_done
movdqu xmm15,XMMWORD PTR[r12]
mov rax,rsp
mov r10d,edx
cmp r14,2
jb $L$cbc_dec_one
movdqu xmm0,XMMWORD PTR[16+r12]
je $L$cbc_dec_two
movdqu xmm1,XMMWORD PTR[32+r12]
cmp r14,4
jb $L$cbc_dec_three
movdqu xmm2,XMMWORD PTR[48+r12]
je $L$cbc_dec_four
movdqu xmm3,XMMWORD PTR[64+r12]
cmp r14,6
jb $L$cbc_dec_five
movdqu xmm4,XMMWORD PTR[80+r12]
je $L$cbc_dec_six
movdqu xmm5,XMMWORD PTR[96+r12]
movdqa XMMWORD PTR[32+rbp],xmm14
call _bsaes_decrypt8
pxor xmm15,XMMWORD PTR[32+rbp]
movdqu xmm7,XMMWORD PTR[r12]
movdqu xmm8,XMMWORD PTR[16+r12]
pxor xmm0,xmm7
movdqu xmm9,XMMWORD PTR[32+r12]
pxor xmm5,xmm8
movdqu xmm10,XMMWORD PTR[48+r12]
pxor xmm3,xmm9
movdqu xmm11,XMMWORD PTR[64+r12]
pxor xmm1,xmm10
movdqu xmm12,XMMWORD PTR[80+r12]
pxor xmm6,xmm11
movdqu xmm14,XMMWORD PTR[96+r12]
pxor xmm2,xmm12
movdqu XMMWORD PTR[r13],xmm15
movdqu XMMWORD PTR[16+r13],xmm0
movdqu XMMWORD PTR[32+r13],xmm5
movdqu XMMWORD PTR[48+r13],xmm3
movdqu XMMWORD PTR[64+r13],xmm1
movdqu XMMWORD PTR[80+r13],xmm6
movdqu XMMWORD PTR[96+r13],xmm2
jmp $L$cbc_dec_done
ALIGN 16
$L$cbc_dec_six::
movdqa XMMWORD PTR[32+rbp],xmm14
call _bsaes_decrypt8
pxor xmm15,XMMWORD PTR[32+rbp]
movdqu xmm7,XMMWORD PTR[r12]
movdqu xmm8,XMMWORD PTR[16+r12]
pxor xmm0,xmm7
movdqu xmm9,XMMWORD PTR[32+r12]
pxor xmm5,xmm8
movdqu xmm10,XMMWORD PTR[48+r12]
pxor xmm3,xmm9
movdqu xmm11,XMMWORD PTR[64+r12]
pxor xmm1,xmm10
movdqu xmm14,XMMWORD PTR[80+r12]
pxor xmm6,xmm11
movdqu XMMWORD PTR[r13],xmm15
movdqu XMMWORD PTR[16+r13],xmm0
movdqu XMMWORD PTR[32+r13],xmm5
movdqu XMMWORD PTR[48+r13],xmm3
movdqu XMMWORD PTR[64+r13],xmm1
movdqu XMMWORD PTR[80+r13],xmm6
jmp $L$cbc_dec_done
ALIGN 16
$L$cbc_dec_five::
movdqa XMMWORD PTR[32+rbp],xmm14
call _bsaes_decrypt8
pxor xmm15,XMMWORD PTR[32+rbp]
movdqu xmm7,XMMWORD PTR[r12]
movdqu xmm8,XMMWORD PTR[16+r12]
pxor xmm0,xmm7
movdqu xmm9,XMMWORD PTR[32+r12]
pxor xmm5,xmm8
movdqu xmm10,XMMWORD PTR[48+r12]
pxor xmm3,xmm9
movdqu xmm14,XMMWORD PTR[64+r12]
pxor xmm1,xmm10
movdqu XMMWORD PTR[r13],xmm15
movdqu XMMWORD PTR[16+r13],xmm0
movdqu XMMWORD PTR[32+r13],xmm5
movdqu XMMWORD PTR[48+r13],xmm3
movdqu XMMWORD PTR[64+r13],xmm1
jmp $L$cbc_dec_done
ALIGN 16
$L$cbc_dec_four::
movdqa XMMWORD PTR[32+rbp],xmm14
call _bsaes_decrypt8
pxor xmm15,XMMWORD PTR[32+rbp]
movdqu xmm7,XMMWORD PTR[r12]
movdqu xmm8,XMMWORD PTR[16+r12]
pxor xmm0,xmm7
movdqu xmm9,XMMWORD PTR[32+r12]
pxor xmm5,xmm8
movdqu xmm14,XMMWORD PTR[48+r12]
pxor xmm3,xmm9
movdqu XMMWORD PTR[r13],xmm15
movdqu XMMWORD PTR[16+r13],xmm0
movdqu XMMWORD PTR[32+r13],xmm5
movdqu XMMWORD PTR[48+r13],xmm3
jmp $L$cbc_dec_done
ALIGN 16
$L$cbc_dec_three::
movdqa XMMWORD PTR[32+rbp],xmm14
call _bsaes_decrypt8
pxor xmm15,XMMWORD PTR[32+rbp]
movdqu xmm7,XMMWORD PTR[r12]
movdqu xmm8,XMMWORD PTR[16+r12]
pxor xmm0,xmm7
movdqu xmm14,XMMWORD PTR[32+r12]
pxor xmm5,xmm8
movdqu XMMWORD PTR[r13],xmm15
movdqu XMMWORD PTR[16+r13],xmm0
movdqu XMMWORD PTR[32+r13],xmm5
jmp $L$cbc_dec_done
ALIGN 16
$L$cbc_dec_two::
movdqa XMMWORD PTR[32+rbp],xmm14
call _bsaes_decrypt8
pxor xmm15,XMMWORD PTR[32+rbp]
movdqu xmm7,XMMWORD PTR[r12]
movdqu xmm14,XMMWORD PTR[16+r12]
pxor xmm0,xmm7
movdqu XMMWORD PTR[r13],xmm15
movdqu XMMWORD PTR[16+r13],xmm0
jmp $L$cbc_dec_done
ALIGN 16
$L$cbc_dec_one::
lea rcx,QWORD PTR[r12]
lea rdx,QWORD PTR[32+rbp]
lea r8,QWORD PTR[r15]
call asm_AES_decrypt
pxor xmm14,XMMWORD PTR[32+rbp]
movdqu XMMWORD PTR[r13],xmm14
movdqa xmm14,xmm15
$L$cbc_dec_done::
movdqu XMMWORD PTR[rbx],xmm14
lea rax,QWORD PTR[rsp]
pxor xmm0,xmm0
$L$cbc_dec_bzero::
movdqa XMMWORD PTR[rax],xmm0
movdqa XMMWORD PTR[16+rax],xmm0
lea rax,QWORD PTR[32+rax]
cmp rbp,rax
ja $L$cbc_dec_bzero
lea rsp,QWORD PTR[rbp]
movaps xmm6,XMMWORD PTR[64+rbp]
movaps xmm7,XMMWORD PTR[80+rbp]
movaps xmm8,XMMWORD PTR[96+rbp]
movaps xmm9,XMMWORD PTR[112+rbp]
movaps xmm10,XMMWORD PTR[128+rbp]
movaps xmm11,XMMWORD PTR[144+rbp]
movaps xmm12,XMMWORD PTR[160+rbp]
movaps xmm13,XMMWORD PTR[176+rbp]
movaps xmm14,XMMWORD PTR[192+rbp]
movaps xmm15,XMMWORD PTR[208+rbp]
lea rsp,QWORD PTR[160+rbp]
mov r15,QWORD PTR[72+rsp]
mov r14,QWORD PTR[80+rsp]
mov r13,QWORD PTR[88+rsp]
mov r12,QWORD PTR[96+rsp]
mov rbx,QWORD PTR[104+rsp]
mov rax,QWORD PTR[112+rsp]
lea rsp,QWORD PTR[120+rsp]
mov rbp,rax
$L$cbc_dec_epilogue::
DB 0F3h,0C3h ;repret
bsaes_cbc_encrypt ENDP
PUBLIC bsaes_ctr32_encrypt_blocks
ALIGN 16
bsaes_ctr32_encrypt_blocks PROC PUBLIC
mov rax,rsp
$L$ctr_enc_prologue::
push rbp
push rbx
push r12
push r13
push r14
push r15
lea rsp,QWORD PTR[((-72))+rsp]
mov r10,QWORD PTR[160+rsp]
lea rsp,QWORD PTR[((-160))+rsp]
movaps XMMWORD PTR[64+rsp],xmm6
movaps XMMWORD PTR[80+rsp],xmm7
movaps XMMWORD PTR[96+rsp],xmm8
movaps XMMWORD PTR[112+rsp],xmm9
movaps XMMWORD PTR[128+rsp],xmm10
movaps XMMWORD PTR[144+rsp],xmm11
movaps XMMWORD PTR[160+rsp],xmm12
movaps XMMWORD PTR[176+rsp],xmm13
movaps XMMWORD PTR[192+rsp],xmm14
movaps XMMWORD PTR[208+rsp],xmm15
$L$ctr_enc_body::
mov rbp,rsp
movdqu xmm0,XMMWORD PTR[r10]
mov eax,DWORD PTR[240+r9]
mov r12,rcx
mov r13,rdx
mov r14,r8
mov r15,r9
movdqa XMMWORD PTR[32+rbp],xmm0
cmp r8,8
jb $L$ctr_enc_short
mov ebx,eax
shl rax,7
sub rax,96
sub rsp,rax
mov rax,rsp
mov rcx,r15
mov r10d,ebx
call _bsaes_key_convert
pxor xmm7,xmm6
movdqa XMMWORD PTR[rax],xmm7
movdqa xmm8,XMMWORD PTR[rsp]
lea r11,QWORD PTR[$L$ADD1]
movdqa xmm15,XMMWORD PTR[32+rbp]
movdqa xmm7,XMMWORD PTR[((-32))+r11]
DB 102,68,15,56,0,199
DB 102,68,15,56,0,255
movdqa XMMWORD PTR[rsp],xmm8
jmp $L$ctr_enc_loop
ALIGN 16
$L$ctr_enc_loop::
movdqa XMMWORD PTR[32+rbp],xmm15
movdqa xmm0,xmm15
movdqa xmm1,xmm15
paddd xmm0,XMMWORD PTR[r11]
movdqa xmm2,xmm15
paddd xmm1,XMMWORD PTR[16+r11]
movdqa xmm3,xmm15
paddd xmm2,XMMWORD PTR[32+r11]
movdqa xmm4,xmm15
paddd xmm3,XMMWORD PTR[48+r11]
movdqa xmm5,xmm15
paddd xmm4,XMMWORD PTR[64+r11]
movdqa xmm6,xmm15
paddd xmm5,XMMWORD PTR[80+r11]
paddd xmm6,XMMWORD PTR[96+r11]
movdqa xmm8,XMMWORD PTR[rsp]
lea rax,QWORD PTR[16+rsp]
movdqa xmm7,XMMWORD PTR[((-16))+r11]
pxor xmm15,xmm8
pxor xmm0,xmm8
DB 102,68,15,56,0,255
pxor xmm1,xmm8
DB 102,15,56,0,199
pxor xmm2,xmm8
DB 102,15,56,0,207
pxor xmm3,xmm8
DB 102,15,56,0,215
pxor xmm4,xmm8
DB 102,15,56,0,223
pxor xmm5,xmm8
DB 102,15,56,0,231
pxor xmm6,xmm8
DB 102,15,56,0,239
lea r11,QWORD PTR[$L$BS0]
DB 102,15,56,0,247
mov r10d,ebx
call _bsaes_encrypt8_bitslice
sub r14,8
jc $L$ctr_enc_loop_done
movdqu xmm7,XMMWORD PTR[r12]
movdqu xmm8,XMMWORD PTR[16+r12]
movdqu xmm9,XMMWORD PTR[32+r12]
movdqu xmm10,XMMWORD PTR[48+r12]
movdqu xmm11,XMMWORD PTR[64+r12]
movdqu xmm12,XMMWORD PTR[80+r12]
movdqu xmm13,XMMWORD PTR[96+r12]
movdqu xmm14,XMMWORD PTR[112+r12]
lea r12,QWORD PTR[128+r12]
pxor xmm7,xmm15
movdqa xmm15,XMMWORD PTR[32+rbp]
pxor xmm0,xmm8
movdqu XMMWORD PTR[r13],xmm7
pxor xmm3,xmm9
movdqu XMMWORD PTR[16+r13],xmm0
pxor xmm5,xmm10
movdqu XMMWORD PTR[32+r13],xmm3
pxor xmm2,xmm11
movdqu XMMWORD PTR[48+r13],xmm5
pxor xmm6,xmm12
movdqu XMMWORD PTR[64+r13],xmm2
pxor xmm1,xmm13
movdqu XMMWORD PTR[80+r13],xmm6
pxor xmm4,xmm14
movdqu XMMWORD PTR[96+r13],xmm1
lea r11,QWORD PTR[$L$ADD1]
movdqu XMMWORD PTR[112+r13],xmm4
lea r13,QWORD PTR[128+r13]
paddd xmm15,XMMWORD PTR[112+r11]
jnz $L$ctr_enc_loop
jmp $L$ctr_enc_done
ALIGN 16
$L$ctr_enc_loop_done::
add r14,8
movdqu xmm7,XMMWORD PTR[r12]
pxor xmm15,xmm7
movdqu XMMWORD PTR[r13],xmm15
cmp r14,2
jb $L$ctr_enc_done
movdqu xmm8,XMMWORD PTR[16+r12]
pxor xmm0,xmm8
movdqu XMMWORD PTR[16+r13],xmm0
je $L$ctr_enc_done
movdqu xmm9,XMMWORD PTR[32+r12]
pxor xmm3,xmm9
movdqu XMMWORD PTR[32+r13],xmm3
cmp r14,4
jb $L$ctr_enc_done
movdqu xmm10,XMMWORD PTR[48+r12]
pxor xmm5,xmm10
movdqu XMMWORD PTR[48+r13],xmm5
je $L$ctr_enc_done
movdqu xmm11,XMMWORD PTR[64+r12]
pxor xmm2,xmm11
movdqu XMMWORD PTR[64+r13],xmm2
cmp r14,6
jb $L$ctr_enc_done
movdqu xmm12,XMMWORD PTR[80+r12]
pxor xmm6,xmm12
movdqu XMMWORD PTR[80+r13],xmm6
je $L$ctr_enc_done
movdqu xmm13,XMMWORD PTR[96+r12]
pxor xmm1,xmm13
movdqu XMMWORD PTR[96+r13],xmm1
jmp $L$ctr_enc_done
ALIGN 16
$L$ctr_enc_short::
lea rcx,QWORD PTR[32+rbp]
lea rdx,QWORD PTR[48+rbp]
lea r8,QWORD PTR[r15]
call asm_AES_encrypt
movdqu xmm0,XMMWORD PTR[r12]
lea r12,QWORD PTR[16+r12]
mov eax,DWORD PTR[44+rbp]
bswap eax
pxor xmm0,XMMWORD PTR[48+rbp]
inc eax
movdqu XMMWORD PTR[r13],xmm0
bswap eax
lea r13,QWORD PTR[16+r13]
mov DWORD PTR[44+rsp],eax
dec r14
jnz $L$ctr_enc_short
$L$ctr_enc_done::
lea rax,QWORD PTR[rsp]
pxor xmm0,xmm0
$L$ctr_enc_bzero::
movdqa XMMWORD PTR[rax],xmm0
movdqa XMMWORD PTR[16+rax],xmm0
lea rax,QWORD PTR[32+rax]
cmp rbp,rax
ja $L$ctr_enc_bzero
lea rsp,QWORD PTR[rbp]
movaps xmm6,XMMWORD PTR[64+rbp]
movaps xmm7,XMMWORD PTR[80+rbp]
movaps xmm8,XMMWORD PTR[96+rbp]
movaps xmm9,XMMWORD PTR[112+rbp]
movaps xmm10,XMMWORD PTR[128+rbp]
movaps xmm11,XMMWORD PTR[144+rbp]
movaps xmm12,XMMWORD PTR[160+rbp]
movaps xmm13,XMMWORD PTR[176+rbp]
movaps xmm14,XMMWORD PTR[192+rbp]
movaps xmm15,XMMWORD PTR[208+rbp]
lea rsp,QWORD PTR[160+rbp]
mov r15,QWORD PTR[72+rsp]
mov r14,QWORD PTR[80+rsp]
mov r13,QWORD PTR[88+rsp]
mov r12,QWORD PTR[96+rsp]
mov rbx,QWORD PTR[104+rsp]
mov rax,QWORD PTR[112+rsp]
lea rsp,QWORD PTR[120+rsp]
mov rbp,rax
$L$ctr_enc_epilogue::
DB 0F3h,0C3h ;repret
bsaes_ctr32_encrypt_blocks ENDP
PUBLIC bsaes_xts_encrypt
ALIGN 16
bsaes_xts_encrypt PROC PUBLIC
mov rax,rsp
$L$xts_enc_prologue::
push rbp
push rbx
push r12
push r13
push r14
push r15
lea rsp,QWORD PTR[((-72))+rsp]
mov r10,QWORD PTR[160+rsp]
mov r11d,DWORD PTR[168+rsp]
lea rsp,QWORD PTR[((-160))+rsp]
movaps XMMWORD PTR[64+rsp],xmm6
movaps XMMWORD PTR[80+rsp],xmm7
movaps XMMWORD PTR[96+rsp],xmm8
movaps XMMWORD PTR[112+rsp],xmm9
movaps XMMWORD PTR[128+rsp],xmm10
movaps XMMWORD PTR[144+rsp],xmm11
movaps XMMWORD PTR[160+rsp],xmm12
movaps XMMWORD PTR[176+rsp],xmm13
movaps XMMWORD PTR[192+rsp],xmm14
movaps XMMWORD PTR[208+rsp],xmm15
$L$xts_enc_body::
mov rbp,rsp
mov r12,rcx
mov r13,rdx
mov r14,r8
mov r15,r9
lea rcx,QWORD PTR[r11]
lea rdx,QWORD PTR[32+rbp]
lea r8,QWORD PTR[r10]
call asm_AES_encrypt
mov eax,DWORD PTR[240+r15]
mov rbx,r14
mov edx,eax
shl rax,7
sub rax,96
sub rsp,rax
mov rax,rsp
mov rcx,r15
mov r10d,edx
call _bsaes_key_convert
pxor xmm7,xmm6
movdqa XMMWORD PTR[rax],xmm7
and r14,-16
sub rsp,080h
movdqa xmm6,XMMWORD PTR[32+rbp]
pxor xmm14,xmm14
movdqa xmm12,XMMWORD PTR[$L$xts_magic]
pcmpgtd xmm14,xmm6
sub r14,080h
jc $L$xts_enc_short
jmp $L$xts_enc_loop
ALIGN 16
$L$xts_enc_loop::
pshufd xmm13,xmm14,013h
pxor xmm14,xmm14
movdqa xmm15,xmm6
movdqa XMMWORD PTR[rsp],xmm6
paddq xmm6,xmm6
pand xmm13,xmm12
pcmpgtd xmm14,xmm6
pxor xmm6,xmm13
pshufd xmm13,xmm14,013h
pxor xmm14,xmm14
movdqa xmm0,xmm6
movdqa XMMWORD PTR[16+rsp],xmm6
paddq xmm6,xmm6
pand xmm13,xmm12
pcmpgtd xmm14,xmm6
pxor xmm6,xmm13
movdqu xmm7,XMMWORD PTR[r12]
pshufd xmm13,xmm14,013h
pxor xmm14,xmm14
movdqa xmm1,xmm6
movdqa XMMWORD PTR[32+rsp],xmm6
paddq xmm6,xmm6
pand xmm13,xmm12
pcmpgtd xmm14,xmm6
pxor xmm6,xmm13
movdqu xmm8,XMMWORD PTR[16+r12]
pxor xmm15,xmm7
pshufd xmm13,xmm14,013h
pxor xmm14,xmm14
movdqa xmm2,xmm6
movdqa XMMWORD PTR[48+rsp],xmm6
paddq xmm6,xmm6
pand xmm13,xmm12
pcmpgtd xmm14,xmm6
pxor xmm6,xmm13
movdqu xmm9,XMMWORD PTR[32+r12]
pxor xmm0,xmm8
pshufd xmm13,xmm14,013h
pxor xmm14,xmm14
movdqa xmm3,xmm6
movdqa XMMWORD PTR[64+rsp],xmm6
paddq xmm6,xmm6
pand xmm13,xmm12
pcmpgtd xmm14,xmm6
pxor xmm6,xmm13
movdqu xmm10,XMMWORD PTR[48+r12]
pxor xmm1,xmm9
pshufd xmm13,xmm14,013h
pxor xmm14,xmm14
movdqa xmm4,xmm6
movdqa XMMWORD PTR[80+rsp],xmm6
paddq xmm6,xmm6
pand xmm13,xmm12
pcmpgtd xmm14,xmm6
pxor xmm6,xmm13
movdqu xmm11,XMMWORD PTR[64+r12]
pxor xmm2,xmm10
pshufd xmm13,xmm14,013h
pxor xmm14,xmm14
movdqa xmm5,xmm6
movdqa XMMWORD PTR[96+rsp],xmm6
paddq xmm6,xmm6
pand xmm13,xmm12
pcmpgtd xmm14,xmm6
pxor xmm6,xmm13
movdqu xmm12,XMMWORD PTR[80+r12]
pxor xmm3,xmm11
movdqu xmm13,XMMWORD PTR[96+r12]
pxor xmm4,xmm12
movdqu xmm14,XMMWORD PTR[112+r12]
lea r12,QWORD PTR[128+r12]
movdqa XMMWORD PTR[112+rsp],xmm6
pxor xmm5,xmm13
lea rax,QWORD PTR[128+rsp]
pxor xmm6,xmm14
mov r10d,edx
call _bsaes_encrypt8
pxor xmm15,XMMWORD PTR[rsp]
pxor xmm0,XMMWORD PTR[16+rsp]
movdqu XMMWORD PTR[r13],xmm15
pxor xmm3,XMMWORD PTR[32+rsp]
movdqu XMMWORD PTR[16+r13],xmm0
pxor xmm5,XMMWORD PTR[48+rsp]
movdqu XMMWORD PTR[32+r13],xmm3
pxor xmm2,XMMWORD PTR[64+rsp]
movdqu XMMWORD PTR[48+r13],xmm5
pxor xmm6,XMMWORD PTR[80+rsp]
movdqu XMMWORD PTR[64+r13],xmm2
pxor xmm1,XMMWORD PTR[96+rsp]
movdqu XMMWORD PTR[80+r13],xmm6
pxor xmm4,XMMWORD PTR[112+rsp]
movdqu XMMWORD PTR[96+r13],xmm1
movdqu XMMWORD PTR[112+r13],xmm4
lea r13,QWORD PTR[128+r13]
movdqa xmm6,XMMWORD PTR[112+rsp]
pxor xmm14,xmm14
movdqa xmm12,XMMWORD PTR[$L$xts_magic]
pcmpgtd xmm14,xmm6
pshufd xmm13,xmm14,013h
pxor xmm14,xmm14
paddq xmm6,xmm6
pand xmm13,xmm12
pcmpgtd xmm14,xmm6
pxor xmm6,xmm13
sub r14,080h
jnc $L$xts_enc_loop
$L$xts_enc_short::
add r14,080h
jz $L$xts_enc_done
pshufd xmm13,xmm14,013h
pxor xmm14,xmm14
movdqa xmm15,xmm6
movdqa XMMWORD PTR[rsp],xmm6
paddq xmm6,xmm6
pand xmm13,xmm12
pcmpgtd xmm14,xmm6
pxor xmm6,xmm13
pshufd xmm13,xmm14,013h
pxor xmm14,xmm14
movdqa xmm0,xmm6
movdqa XMMWORD PTR[16+rsp],xmm6
paddq xmm6,xmm6
pand xmm13,xmm12
pcmpgtd xmm14,xmm6
pxor xmm6,xmm13
movdqu xmm7,XMMWORD PTR[r12]
cmp r14,16
je $L$xts_enc_1
pshufd xmm13,xmm14,013h
pxor xmm14,xmm14
movdqa xmm1,xmm6
movdqa XMMWORD PTR[32+rsp],xmm6
paddq xmm6,xmm6
pand xmm13,xmm12
pcmpgtd xmm14,xmm6
pxor xmm6,xmm13
movdqu xmm8,XMMWORD PTR[16+r12]
cmp r14,32
je $L$xts_enc_2
pxor xmm15,xmm7
pshufd xmm13,xmm14,013h
pxor xmm14,xmm14
movdqa xmm2,xmm6
movdqa XMMWORD PTR[48+rsp],xmm6
paddq xmm6,xmm6
pand xmm13,xmm12
pcmpgtd xmm14,xmm6
pxor xmm6,xmm13
movdqu xmm9,XMMWORD PTR[32+r12]
cmp r14,48
je $L$xts_enc_3
pxor xmm0,xmm8
pshufd xmm13,xmm14,013h
pxor xmm14,xmm14
movdqa xmm3,xmm6
movdqa XMMWORD PTR[64+rsp],xmm6
paddq xmm6,xmm6
pand xmm13,xmm12
pcmpgtd xmm14,xmm6
pxor xmm6,xmm13
movdqu xmm10,XMMWORD PTR[48+r12]
cmp r14,64
je $L$xts_enc_4
pxor xmm1,xmm9
pshufd xmm13,xmm14,013h
pxor xmm14,xmm14
movdqa xmm4,xmm6
movdqa XMMWORD PTR[80+rsp],xmm6
paddq xmm6,xmm6
pand xmm13,xmm12
pcmpgtd xmm14,xmm6
pxor xmm6,xmm13
movdqu xmm11,XMMWORD PTR[64+r12]
cmp r14,80
je $L$xts_enc_5
pxor xmm2,xmm10
pshufd xmm13,xmm14,013h
pxor xmm14,xmm14
movdqa xmm5,xmm6
movdqa XMMWORD PTR[96+rsp],xmm6
paddq xmm6,xmm6
pand xmm13,xmm12
pcmpgtd xmm14,xmm6
pxor xmm6,xmm13
movdqu xmm12,XMMWORD PTR[80+r12]
cmp r14,96
je $L$xts_enc_6
pxor xmm3,xmm11
movdqu xmm13,XMMWORD PTR[96+r12]
pxor xmm4,xmm12
movdqa XMMWORD PTR[112+rsp],xmm6
lea r12,QWORD PTR[112+r12]
pxor xmm5,xmm13
lea rax,QWORD PTR[128+rsp]
mov r10d,edx
call _bsaes_encrypt8
pxor xmm15,XMMWORD PTR[rsp]
pxor xmm0,XMMWORD PTR[16+rsp]
movdqu XMMWORD PTR[r13],xmm15
pxor xmm3,XMMWORD PTR[32+rsp]
movdqu XMMWORD PTR[16+r13],xmm0
pxor xmm5,XMMWORD PTR[48+rsp]
movdqu XMMWORD PTR[32+r13],xmm3
pxor xmm2,XMMWORD PTR[64+rsp]
movdqu XMMWORD PTR[48+r13],xmm5
pxor xmm6,XMMWORD PTR[80+rsp]
movdqu XMMWORD PTR[64+r13],xmm2
pxor xmm1,XMMWORD PTR[96+rsp]
movdqu XMMWORD PTR[80+r13],xmm6
movdqu XMMWORD PTR[96+r13],xmm1
lea r13,QWORD PTR[112+r13]
movdqa xmm6,XMMWORD PTR[112+rsp]
jmp $L$xts_enc_done
ALIGN 16
$L$xts_enc_6::
pxor xmm3,xmm11
lea r12,QWORD PTR[96+r12]
pxor xmm4,xmm12
lea rax,QWORD PTR[128+rsp]
mov r10d,edx
call _bsaes_encrypt8
pxor xmm15,XMMWORD PTR[rsp]
pxor xmm0,XMMWORD PTR[16+rsp]
movdqu XMMWORD PTR[r13],xmm15
pxor xmm3,XMMWORD PTR[32+rsp]
movdqu XMMWORD PTR[16+r13],xmm0
pxor xmm5,XMMWORD PTR[48+rsp]
movdqu XMMWORD PTR[32+r13],xmm3
pxor xmm2,XMMWORD PTR[64+rsp]
movdqu XMMWORD PTR[48+r13],xmm5
pxor xmm6,XMMWORD PTR[80+rsp]
movdqu XMMWORD PTR[64+r13],xmm2
movdqu XMMWORD PTR[80+r13],xmm6
lea r13,QWORD PTR[96+r13]
movdqa xmm6,XMMWORD PTR[96+rsp]
jmp $L$xts_enc_done
ALIGN 16
$L$xts_enc_5::
pxor xmm2,xmm10
lea r12,QWORD PTR[80+r12]
pxor xmm3,xmm11
lea rax,QWORD PTR[128+rsp]
mov r10d,edx
call _bsaes_encrypt8
pxor xmm15,XMMWORD PTR[rsp]
pxor xmm0,XMMWORD PTR[16+rsp]
movdqu XMMWORD PTR[r13],xmm15
pxor xmm3,XMMWORD PTR[32+rsp]
movdqu XMMWORD PTR[16+r13],xmm0
pxor xmm5,XMMWORD PTR[48+rsp]
movdqu XMMWORD PTR[32+r13],xmm3
pxor xmm2,XMMWORD PTR[64+rsp]
movdqu XMMWORD PTR[48+r13],xmm5
movdqu XMMWORD PTR[64+r13],xmm2
lea r13,QWORD PTR[80+r13]
movdqa xmm6,XMMWORD PTR[80+rsp]
jmp $L$xts_enc_done
ALIGN 16
$L$xts_enc_4::
pxor xmm1,xmm9
lea r12,QWORD PTR[64+r12]
pxor xmm2,xmm10
lea rax,QWORD PTR[128+rsp]
mov r10d,edx
call _bsaes_encrypt8
pxor xmm15,XMMWORD PTR[rsp]
pxor xmm0,XMMWORD PTR[16+rsp]
movdqu XMMWORD PTR[r13],xmm15
pxor xmm3,XMMWORD PTR[32+rsp]
movdqu XMMWORD PTR[16+r13],xmm0
pxor xmm5,XMMWORD PTR[48+rsp]
movdqu XMMWORD PTR[32+r13],xmm3
movdqu XMMWORD PTR[48+r13],xmm5
lea r13,QWORD PTR[64+r13]
movdqa xmm6,XMMWORD PTR[64+rsp]
jmp $L$xts_enc_done
ALIGN 16
$L$xts_enc_3::
pxor xmm0,xmm8
lea r12,QWORD PTR[48+r12]
pxor xmm1,xmm9
lea rax,QWORD PTR[128+rsp]
mov r10d,edx
call _bsaes_encrypt8
pxor xmm15,XMMWORD PTR[rsp]
pxor xmm0,XMMWORD PTR[16+rsp]
movdqu XMMWORD PTR[r13],xmm15
pxor xmm3,XMMWORD PTR[32+rsp]
movdqu XMMWORD PTR[16+r13],xmm0
movdqu XMMWORD PTR[32+r13],xmm3
lea r13,QWORD PTR[48+r13]
movdqa xmm6,XMMWORD PTR[48+rsp]
jmp $L$xts_enc_done
ALIGN 16
$L$xts_enc_2::
pxor xmm15,xmm7
lea r12,QWORD PTR[32+r12]
pxor xmm0,xmm8
lea rax,QWORD PTR[128+rsp]
mov r10d,edx
call _bsaes_encrypt8
pxor xmm15,XMMWORD PTR[rsp]
pxor xmm0,XMMWORD PTR[16+rsp]
movdqu XMMWORD PTR[r13],xmm15
movdqu XMMWORD PTR[16+r13],xmm0
lea r13,QWORD PTR[32+r13]
movdqa xmm6,XMMWORD PTR[32+rsp]
jmp $L$xts_enc_done
ALIGN 16
$L$xts_enc_1::
pxor xmm7,xmm15
lea r12,QWORD PTR[16+r12]
movdqa XMMWORD PTR[32+rbp],xmm7
lea rcx,QWORD PTR[32+rbp]
lea rdx,QWORD PTR[32+rbp]
lea r8,QWORD PTR[r15]
call asm_AES_encrypt
pxor xmm15,XMMWORD PTR[32+rbp]
movdqu XMMWORD PTR[r13],xmm15
lea r13,QWORD PTR[16+r13]
movdqa xmm6,XMMWORD PTR[16+rsp]
$L$xts_enc_done::
and ebx,15
jz $L$xts_enc_ret
mov rdx,r13
$L$xts_enc_steal::
movzx eax,BYTE PTR[r12]
movzx ecx,BYTE PTR[((-16))+rdx]
lea r12,QWORD PTR[1+r12]
mov BYTE PTR[((-16))+rdx],al
mov BYTE PTR[rdx],cl
lea rdx,QWORD PTR[1+rdx]
sub ebx,1
jnz $L$xts_enc_steal
movdqu xmm15,XMMWORD PTR[((-16))+r13]
lea rcx,QWORD PTR[32+rbp]
pxor xmm15,xmm6
lea rdx,QWORD PTR[32+rbp]
movdqa XMMWORD PTR[32+rbp],xmm15
lea r8,QWORD PTR[r15]
call asm_AES_encrypt
pxor xmm6,XMMWORD PTR[32+rbp]
movdqu XMMWORD PTR[(-16)+r13],xmm6
$L$xts_enc_ret::
lea rax,QWORD PTR[rsp]
pxor xmm0,xmm0
$L$xts_enc_bzero::
movdqa XMMWORD PTR[rax],xmm0
movdqa XMMWORD PTR[16+rax],xmm0
lea rax,QWORD PTR[32+rax]
cmp rbp,rax
ja $L$xts_enc_bzero
lea rsp,QWORD PTR[rbp]
movaps xmm6,XMMWORD PTR[64+rbp]
movaps xmm7,XMMWORD PTR[80+rbp]
movaps xmm8,XMMWORD PTR[96+rbp]
movaps xmm9,XMMWORD PTR[112+rbp]
movaps xmm10,XMMWORD PTR[128+rbp]
movaps xmm11,XMMWORD PTR[144+rbp]
movaps xmm12,XMMWORD PTR[160+rbp]
movaps xmm13,XMMWORD PTR[176+rbp]
movaps xmm14,XMMWORD PTR[192+rbp]
movaps xmm15,XMMWORD PTR[208+rbp]
lea rsp,QWORD PTR[160+rbp]
mov r15,QWORD PTR[72+rsp]
mov r14,QWORD PTR[80+rsp]
mov r13,QWORD PTR[88+rsp]
mov r12,QWORD PTR[96+rsp]
mov rbx,QWORD PTR[104+rsp]
mov rax,QWORD PTR[112+rsp]
lea rsp,QWORD PTR[120+rsp]
mov rbp,rax
$L$xts_enc_epilogue::
DB 0F3h,0C3h ;repret
bsaes_xts_encrypt ENDP
PUBLIC bsaes_xts_decrypt
ALIGN 16
bsaes_xts_decrypt PROC PUBLIC
mov rax,rsp
$L$xts_dec_prologue::
push rbp
push rbx
push r12
push r13
push r14
push r15
lea rsp,QWORD PTR[((-72))+rsp]
mov r10,QWORD PTR[160+rsp]
mov r11d,DWORD PTR[168+rsp]
lea rsp,QWORD PTR[((-160))+rsp]
movaps XMMWORD PTR[64+rsp],xmm6
movaps XMMWORD PTR[80+rsp],xmm7
movaps XMMWORD PTR[96+rsp],xmm8
movaps XMMWORD PTR[112+rsp],xmm9
movaps XMMWORD PTR[128+rsp],xmm10
movaps XMMWORD PTR[144+rsp],xmm11
movaps XMMWORD PTR[160+rsp],xmm12
movaps XMMWORD PTR[176+rsp],xmm13
movaps XMMWORD PTR[192+rsp],xmm14
movaps XMMWORD PTR[208+rsp],xmm15
$L$xts_dec_body::
mov rbp,rsp
mov r12,rcx
mov r13,rdx
mov r14,r8
mov r15,r9
lea rcx,QWORD PTR[r11]
lea rdx,QWORD PTR[32+rbp]
lea r8,QWORD PTR[r10]
call asm_AES_encrypt
mov eax,DWORD PTR[240+r15]
mov rbx,r14
mov edx,eax
shl rax,7
sub rax,96
sub rsp,rax
mov rax,rsp
mov rcx,r15
mov r10d,edx
call _bsaes_key_convert
pxor xmm7,XMMWORD PTR[rsp]
movdqa XMMWORD PTR[rax],xmm6
movdqa XMMWORD PTR[rsp],xmm7
xor eax,eax
and r14,-16
test ebx,15
setnz al
shl rax,4
sub r14,rax
sub rsp,080h
movdqa xmm6,XMMWORD PTR[32+rbp]
pxor xmm14,xmm14
movdqa xmm12,XMMWORD PTR[$L$xts_magic]
pcmpgtd xmm14,xmm6
sub r14,080h
jc $L$xts_dec_short
jmp $L$xts_dec_loop
ALIGN 16
$L$xts_dec_loop::
pshufd xmm13,xmm14,013h
pxor xmm14,xmm14
movdqa xmm15,xmm6
movdqa XMMWORD PTR[rsp],xmm6
paddq xmm6,xmm6
pand xmm13,xmm12
pcmpgtd xmm14,xmm6
pxor xmm6,xmm13
pshufd xmm13,xmm14,013h
pxor xmm14,xmm14
movdqa xmm0,xmm6
movdqa XMMWORD PTR[16+rsp],xmm6
paddq xmm6,xmm6
pand xmm13,xmm12
pcmpgtd xmm14,xmm6
pxor xmm6,xmm13
movdqu xmm7,XMMWORD PTR[r12]
pshufd xmm13,xmm14,013h
pxor xmm14,xmm14
movdqa xmm1,xmm6
movdqa XMMWORD PTR[32+rsp],xmm6
paddq xmm6,xmm6
pand xmm13,xmm12
pcmpgtd xmm14,xmm6
pxor xmm6,xmm13
movdqu xmm8,XMMWORD PTR[16+r12]
pxor xmm15,xmm7
pshufd xmm13,xmm14,013h
pxor xmm14,xmm14
movdqa xmm2,xmm6
movdqa XMMWORD PTR[48+rsp],xmm6
paddq xmm6,xmm6
pand xmm13,xmm12
pcmpgtd xmm14,xmm6
pxor xmm6,xmm13
movdqu xmm9,XMMWORD PTR[32+r12]
pxor xmm0,xmm8
pshufd xmm13,xmm14,013h
pxor xmm14,xmm14
movdqa xmm3,xmm6
movdqa XMMWORD PTR[64+rsp],xmm6
paddq xmm6,xmm6
pand xmm13,xmm12
pcmpgtd xmm14,xmm6
pxor xmm6,xmm13
movdqu xmm10,XMMWORD PTR[48+r12]
pxor xmm1,xmm9
pshufd xmm13,xmm14,013h
pxor xmm14,xmm14
movdqa xmm4,xmm6
movdqa XMMWORD PTR[80+rsp],xmm6
paddq xmm6,xmm6
pand xmm13,xmm12
pcmpgtd xmm14,xmm6
pxor xmm6,xmm13
movdqu xmm11,XMMWORD PTR[64+r12]
pxor xmm2,xmm10
pshufd xmm13,xmm14,013h
pxor xmm14,xmm14
movdqa xmm5,xmm6
movdqa XMMWORD PTR[96+rsp],xmm6
paddq xmm6,xmm6
pand xmm13,xmm12
pcmpgtd xmm14,xmm6
pxor xmm6,xmm13
movdqu xmm12,XMMWORD PTR[80+r12]
pxor xmm3,xmm11
movdqu xmm13,XMMWORD PTR[96+r12]
pxor xmm4,xmm12
movdqu xmm14,XMMWORD PTR[112+r12]
lea r12,QWORD PTR[128+r12]
movdqa XMMWORD PTR[112+rsp],xmm6
pxor xmm5,xmm13
lea rax,QWORD PTR[128+rsp]
pxor xmm6,xmm14
mov r10d,edx
call _bsaes_decrypt8
pxor xmm15,XMMWORD PTR[rsp]
pxor xmm0,XMMWORD PTR[16+rsp]
movdqu XMMWORD PTR[r13],xmm15
pxor xmm5,XMMWORD PTR[32+rsp]
movdqu XMMWORD PTR[16+r13],xmm0
pxor xmm3,XMMWORD PTR[48+rsp]
movdqu XMMWORD PTR[32+r13],xmm5
pxor xmm1,XMMWORD PTR[64+rsp]
movdqu XMMWORD PTR[48+r13],xmm3
pxor xmm6,XMMWORD PTR[80+rsp]
movdqu XMMWORD PTR[64+r13],xmm1
pxor xmm2,XMMWORD PTR[96+rsp]
movdqu XMMWORD PTR[80+r13],xmm6
pxor xmm4,XMMWORD PTR[112+rsp]
movdqu XMMWORD PTR[96+r13],xmm2
movdqu XMMWORD PTR[112+r13],xmm4
lea r13,QWORD PTR[128+r13]
movdqa xmm6,XMMWORD PTR[112+rsp]
pxor xmm14,xmm14
movdqa xmm12,XMMWORD PTR[$L$xts_magic]
pcmpgtd xmm14,xmm6
pshufd xmm13,xmm14,013h
pxor xmm14,xmm14
paddq xmm6,xmm6
pand xmm13,xmm12
pcmpgtd xmm14,xmm6
pxor xmm6,xmm13
sub r14,080h
jnc $L$xts_dec_loop
$L$xts_dec_short::
add r14,080h
jz $L$xts_dec_done
pshufd xmm13,xmm14,013h
pxor xmm14,xmm14
movdqa xmm15,xmm6
movdqa XMMWORD PTR[rsp],xmm6
paddq xmm6,xmm6
pand xmm13,xmm12
pcmpgtd xmm14,xmm6
pxor xmm6,xmm13
pshufd xmm13,xmm14,013h
pxor xmm14,xmm14
movdqa xmm0,xmm6
movdqa XMMWORD PTR[16+rsp],xmm6
paddq xmm6,xmm6
pand xmm13,xmm12
pcmpgtd xmm14,xmm6
pxor xmm6,xmm13
movdqu xmm7,XMMWORD PTR[r12]
cmp r14,16
je $L$xts_dec_1
pshufd xmm13,xmm14,013h
pxor xmm14,xmm14
movdqa xmm1,xmm6
movdqa XMMWORD PTR[32+rsp],xmm6
paddq xmm6,xmm6
pand xmm13,xmm12
pcmpgtd xmm14,xmm6
pxor xmm6,xmm13
movdqu xmm8,XMMWORD PTR[16+r12]
cmp r14,32
je $L$xts_dec_2
pxor xmm15,xmm7
pshufd xmm13,xmm14,013h
pxor xmm14,xmm14
movdqa xmm2,xmm6
movdqa XMMWORD PTR[48+rsp],xmm6
paddq xmm6,xmm6
pand xmm13,xmm12
pcmpgtd xmm14,xmm6
pxor xmm6,xmm13
movdqu xmm9,XMMWORD PTR[32+r12]
cmp r14,48
je $L$xts_dec_3
pxor xmm0,xmm8
pshufd xmm13,xmm14,013h
pxor xmm14,xmm14
movdqa xmm3,xmm6
movdqa XMMWORD PTR[64+rsp],xmm6
paddq xmm6,xmm6
pand xmm13,xmm12
pcmpgtd xmm14,xmm6
pxor xmm6,xmm13
movdqu xmm10,XMMWORD PTR[48+r12]
cmp r14,64
je $L$xts_dec_4
pxor xmm1,xmm9
pshufd xmm13,xmm14,013h
pxor xmm14,xmm14
movdqa xmm4,xmm6
movdqa XMMWORD PTR[80+rsp],xmm6
paddq xmm6,xmm6
pand xmm13,xmm12
pcmpgtd xmm14,xmm6
pxor xmm6,xmm13
movdqu xmm11,XMMWORD PTR[64+r12]
cmp r14,80
je $L$xts_dec_5
pxor xmm2,xmm10
pshufd xmm13,xmm14,013h
pxor xmm14,xmm14
movdqa xmm5,xmm6
movdqa XMMWORD PTR[96+rsp],xmm6
paddq xmm6,xmm6
pand xmm13,xmm12
pcmpgtd xmm14,xmm6
pxor xmm6,xmm13
movdqu xmm12,XMMWORD PTR[80+r12]
cmp r14,96
je $L$xts_dec_6
pxor xmm3,xmm11
movdqu xmm13,XMMWORD PTR[96+r12]
pxor xmm4,xmm12
movdqa XMMWORD PTR[112+rsp],xmm6
lea r12,QWORD PTR[112+r12]
pxor xmm5,xmm13
lea rax,QWORD PTR[128+rsp]
mov r10d,edx
call _bsaes_decrypt8
pxor xmm15,XMMWORD PTR[rsp]
pxor xmm0,XMMWORD PTR[16+rsp]
movdqu XMMWORD PTR[r13],xmm15
pxor xmm5,XMMWORD PTR[32+rsp]
movdqu XMMWORD PTR[16+r13],xmm0
pxor xmm3,XMMWORD PTR[48+rsp]
movdqu XMMWORD PTR[32+r13],xmm5
pxor xmm1,XMMWORD PTR[64+rsp]
movdqu XMMWORD PTR[48+r13],xmm3
pxor xmm6,XMMWORD PTR[80+rsp]
movdqu XMMWORD PTR[64+r13],xmm1
pxor xmm2,XMMWORD PTR[96+rsp]
movdqu XMMWORD PTR[80+r13],xmm6
movdqu XMMWORD PTR[96+r13],xmm2
lea r13,QWORD PTR[112+r13]
movdqa xmm6,XMMWORD PTR[112+rsp]
jmp $L$xts_dec_done
ALIGN 16
$L$xts_dec_6::
pxor xmm3,xmm11
lea r12,QWORD PTR[96+r12]
pxor xmm4,xmm12
lea rax,QWORD PTR[128+rsp]
mov r10d,edx
call _bsaes_decrypt8
pxor xmm15,XMMWORD PTR[rsp]
pxor xmm0,XMMWORD PTR[16+rsp]
movdqu XMMWORD PTR[r13],xmm15
pxor xmm5,XMMWORD PTR[32+rsp]
movdqu XMMWORD PTR[16+r13],xmm0
pxor xmm3,XMMWORD PTR[48+rsp]
movdqu XMMWORD PTR[32+r13],xmm5
pxor xmm1,XMMWORD PTR[64+rsp]
movdqu XMMWORD PTR[48+r13],xmm3
pxor xmm6,XMMWORD PTR[80+rsp]
movdqu XMMWORD PTR[64+r13],xmm1
movdqu XMMWORD PTR[80+r13],xmm6
lea r13,QWORD PTR[96+r13]
movdqa xmm6,XMMWORD PTR[96+rsp]
jmp $L$xts_dec_done
ALIGN 16
$L$xts_dec_5::
pxor xmm2,xmm10
lea r12,QWORD PTR[80+r12]
pxor xmm3,xmm11
lea rax,QWORD PTR[128+rsp]
mov r10d,edx
call _bsaes_decrypt8
pxor xmm15,XMMWORD PTR[rsp]
pxor xmm0,XMMWORD PTR[16+rsp]
movdqu XMMWORD PTR[r13],xmm15
pxor xmm5,XMMWORD PTR[32+rsp]
movdqu XMMWORD PTR[16+r13],xmm0
pxor xmm3,XMMWORD PTR[48+rsp]
movdqu XMMWORD PTR[32+r13],xmm5
pxor xmm1,XMMWORD PTR[64+rsp]
movdqu XMMWORD PTR[48+r13],xmm3
movdqu XMMWORD PTR[64+r13],xmm1
lea r13,QWORD PTR[80+r13]
movdqa xmm6,XMMWORD PTR[80+rsp]
jmp $L$xts_dec_done
ALIGN 16
$L$xts_dec_4::
pxor xmm1,xmm9
lea r12,QWORD PTR[64+r12]
pxor xmm2,xmm10
lea rax,QWORD PTR[128+rsp]
mov r10d,edx
call _bsaes_decrypt8
pxor xmm15,XMMWORD PTR[rsp]
pxor xmm0,XMMWORD PTR[16+rsp]
movdqu XMMWORD PTR[r13],xmm15
pxor xmm5,XMMWORD PTR[32+rsp]
movdqu XMMWORD PTR[16+r13],xmm0
pxor xmm3,XMMWORD PTR[48+rsp]
movdqu XMMWORD PTR[32+r13],xmm5
movdqu XMMWORD PTR[48+r13],xmm3
lea r13,QWORD PTR[64+r13]
movdqa xmm6,XMMWORD PTR[64+rsp]
jmp $L$xts_dec_done
ALIGN 16
$L$xts_dec_3::
pxor xmm0,xmm8
lea r12,QWORD PTR[48+r12]
pxor xmm1,xmm9
lea rax,QWORD PTR[128+rsp]
mov r10d,edx
call _bsaes_decrypt8
pxor xmm15,XMMWORD PTR[rsp]
pxor xmm0,XMMWORD PTR[16+rsp]
movdqu XMMWORD PTR[r13],xmm15
pxor xmm5,XMMWORD PTR[32+rsp]
movdqu XMMWORD PTR[16+r13],xmm0
movdqu XMMWORD PTR[32+r13],xmm5
lea r13,QWORD PTR[48+r13]
movdqa xmm6,XMMWORD PTR[48+rsp]
jmp $L$xts_dec_done
ALIGN 16
$L$xts_dec_2::
pxor xmm15,xmm7
lea r12,QWORD PTR[32+r12]
pxor xmm0,xmm8
lea rax,QWORD PTR[128+rsp]
mov r10d,edx
call _bsaes_decrypt8
pxor xmm15,XMMWORD PTR[rsp]
pxor xmm0,XMMWORD PTR[16+rsp]
movdqu XMMWORD PTR[r13],xmm15
movdqu XMMWORD PTR[16+r13],xmm0
lea r13,QWORD PTR[32+r13]
movdqa xmm6,XMMWORD PTR[32+rsp]
jmp $L$xts_dec_done
ALIGN 16
$L$xts_dec_1::
pxor xmm7,xmm15
lea r12,QWORD PTR[16+r12]
movdqa XMMWORD PTR[32+rbp],xmm7
lea rcx,QWORD PTR[32+rbp]
lea rdx,QWORD PTR[32+rbp]
lea r8,QWORD PTR[r15]
call asm_AES_decrypt
pxor xmm15,XMMWORD PTR[32+rbp]
movdqu XMMWORD PTR[r13],xmm15
lea r13,QWORD PTR[16+r13]
movdqa xmm6,XMMWORD PTR[16+rsp]
$L$xts_dec_done::
and ebx,15
jz $L$xts_dec_ret
pxor xmm14,xmm14
movdqa xmm12,XMMWORD PTR[$L$xts_magic]
pcmpgtd xmm14,xmm6
pshufd xmm13,xmm14,013h
movdqa xmm5,xmm6
paddq xmm6,xmm6
pand xmm13,xmm12
movdqu xmm15,XMMWORD PTR[r12]
pxor xmm6,xmm13
lea rcx,QWORD PTR[32+rbp]
pxor xmm15,xmm6
lea rdx,QWORD PTR[32+rbp]
movdqa XMMWORD PTR[32+rbp],xmm15
lea r8,QWORD PTR[r15]
call asm_AES_decrypt
pxor xmm6,XMMWORD PTR[32+rbp]
mov rdx,r13
movdqu XMMWORD PTR[r13],xmm6
$L$xts_dec_steal::
movzx eax,BYTE PTR[16+r12]
movzx ecx,BYTE PTR[rdx]
lea r12,QWORD PTR[1+r12]
mov BYTE PTR[rdx],al
mov BYTE PTR[16+rdx],cl
lea rdx,QWORD PTR[1+rdx]
sub ebx,1
jnz $L$xts_dec_steal
movdqu xmm15,XMMWORD PTR[r13]
lea rcx,QWORD PTR[32+rbp]
pxor xmm15,xmm5
lea rdx,QWORD PTR[32+rbp]
movdqa XMMWORD PTR[32+rbp],xmm15
lea r8,QWORD PTR[r15]
call asm_AES_decrypt
pxor xmm5,XMMWORD PTR[32+rbp]
movdqu XMMWORD PTR[r13],xmm5
$L$xts_dec_ret::
lea rax,QWORD PTR[rsp]
pxor xmm0,xmm0
$L$xts_dec_bzero::
movdqa XMMWORD PTR[rax],xmm0
movdqa XMMWORD PTR[16+rax],xmm0
lea rax,QWORD PTR[32+rax]
cmp rbp,rax
ja $L$xts_dec_bzero
lea rsp,QWORD PTR[rbp]
movaps xmm6,XMMWORD PTR[64+rbp]
movaps xmm7,XMMWORD PTR[80+rbp]
movaps xmm8,XMMWORD PTR[96+rbp]
movaps xmm9,XMMWORD PTR[112+rbp]
movaps xmm10,XMMWORD PTR[128+rbp]
movaps xmm11,XMMWORD PTR[144+rbp]
movaps xmm12,XMMWORD PTR[160+rbp]
movaps xmm13,XMMWORD PTR[176+rbp]
movaps xmm14,XMMWORD PTR[192+rbp]
movaps xmm15,XMMWORD PTR[208+rbp]
lea rsp,QWORD PTR[160+rbp]
mov r15,QWORD PTR[72+rsp]
mov r14,QWORD PTR[80+rsp]
mov r13,QWORD PTR[88+rsp]
mov r12,QWORD PTR[96+rsp]
mov rbx,QWORD PTR[104+rsp]
mov rax,QWORD PTR[112+rsp]
lea rsp,QWORD PTR[120+rsp]
mov rbp,rax
$L$xts_dec_epilogue::
DB 0F3h,0C3h ;repret
bsaes_xts_decrypt ENDP
ALIGN 64
_bsaes_const::
$L$M0ISR::
DQ 00a0e0206070b0f03h,00004080c0d010509h
$L$ISRM0::
DQ 001040b0e0205080fh,00306090c00070a0dh
$L$ISR::
DQ 00504070602010003h,00f0e0d0c080b0a09h
$L$BS0::
DQ 05555555555555555h,05555555555555555h
$L$BS1::
DQ 03333333333333333h,03333333333333333h
$L$BS2::
DQ 00f0f0f0f0f0f0f0fh,00f0f0f0f0f0f0f0fh
$L$SR::
DQ 00504070600030201h,00f0e0d0c0a09080bh
$L$SRM0::
DQ 00304090e00050a0fh,001060b0c0207080dh
$L$M0SR::
DQ 00a0e02060f03070bh,00004080c05090d01h
$L$SWPUP::
DQ 00706050403020100h,00c0d0e0f0b0a0908h
$L$SWPUPM0SR::
DQ 00a0d02060c03070bh,00004080f05090e01h
$L$ADD1::
DQ 00000000000000000h,00000000100000000h
$L$ADD2::
DQ 00000000000000000h,00000000200000000h
$L$ADD3::
DQ 00000000000000000h,00000000300000000h
$L$ADD4::
DQ 00000000000000000h,00000000400000000h
$L$ADD5::
DQ 00000000000000000h,00000000500000000h
$L$ADD6::
DQ 00000000000000000h,00000000600000000h
$L$ADD7::
DQ 00000000000000000h,00000000700000000h
$L$ADD8::
DQ 00000000000000000h,00000000800000000h
$L$xts_magic::
DD 087h,0,1,0
$L$masks::
DQ 00101010101010101h,00101010101010101h
DQ 00202020202020202h,00202020202020202h
DQ 00404040404040404h,00404040404040404h
DQ 00808080808080808h,00808080808080808h
$L$M0::
DQ 002060a0e03070b0fh,00004080c0105090dh
$L$63::
DQ 06363636363636363h,06363636363636363h
DB 66,105,116,45,115,108,105,99,101,100,32,65,69,83,32,102
DB 111,114,32,120,56,54,95,54,52,47,83,83,83,69,51,44
DB 32,69,109,105,108,105,97,32,75,195,164,115,112,101,114,44
DB 32,80,101,116,101,114,32,83,99,104,119,97,98,101,44,32
DB 65,110,100,121,32,80,111,108,121,97,107,111,118,0
ALIGN 64
EXTERN __imp_RtlVirtualUnwind:NEAR
ALIGN 16
se_handler PROC PRIVATE
push rsi
push rdi
push rbx
push rbp
push r12
push r13
push r14
push r15
pushfq
sub rsp,64
mov rax,QWORD PTR[120+r8]
mov rbx,QWORD PTR[248+r8]
mov rsi,QWORD PTR[8+r9]
mov r11,QWORD PTR[56+r9]
mov r10d,DWORD PTR[r11]
lea r10,QWORD PTR[r10*1+rsi]
cmp rbx,r10
jb $L$in_prologue
mov rax,QWORD PTR[152+r8]
mov r10d,DWORD PTR[4+r11]
lea r10,QWORD PTR[r10*1+rsi]
cmp rbx,r10
jae $L$in_prologue
mov rax,QWORD PTR[160+r8]
lea rsi,QWORD PTR[64+rax]
lea rdi,QWORD PTR[512+r8]
mov ecx,20
DD 0a548f3fch
lea rax,QWORD PTR[160+rax]
mov rbp,QWORD PTR[112+rax]
mov rbx,QWORD PTR[104+rax]
mov r12,QWORD PTR[96+rax]
mov r13,QWORD PTR[88+rax]
mov r14,QWORD PTR[80+rax]
mov r15,QWORD PTR[72+rax]
lea rax,QWORD PTR[120+rax]
mov QWORD PTR[144+r8],rbx
mov QWORD PTR[160+r8],rbp
mov QWORD PTR[216+r8],r12
mov QWORD PTR[224+r8],r13
mov QWORD PTR[232+r8],r14
mov QWORD PTR[240+r8],r15
$L$in_prologue::
mov QWORD PTR[152+r8],rax
mov rdi,QWORD PTR[40+r9]
mov rsi,r8
mov ecx,154
DD 0a548f3fch
mov rsi,r9
xor rcx,rcx
mov rdx,QWORD PTR[8+rsi]
mov r8,QWORD PTR[rsi]
mov r9,QWORD PTR[16+rsi]
mov r10,QWORD PTR[40+rsi]
lea r11,QWORD PTR[56+rsi]
lea r12,QWORD PTR[24+rsi]
mov QWORD PTR[32+rsp],r10
mov QWORD PTR[40+rsp],r11
mov QWORD PTR[48+rsp],r12
mov QWORD PTR[56+rsp],rcx
call QWORD PTR[__imp_RtlVirtualUnwind]
mov eax,1
add rsp,64
popfq
pop r15
pop r14
pop r13
pop r12
pop rbp
pop rbx
pop rdi
pop rsi
DB 0F3h,0C3h ;repret
se_handler ENDP
.text$ ENDS
.pdata SEGMENT READONLY ALIGN(4)
ALIGN 4
DD imagerel $L$cbc_dec_prologue
DD imagerel $L$cbc_dec_epilogue
DD imagerel $L$cbc_dec_info
DD imagerel $L$ctr_enc_prologue
DD imagerel $L$ctr_enc_epilogue
DD imagerel $L$ctr_enc_info
DD imagerel $L$xts_enc_prologue
DD imagerel $L$xts_enc_epilogue
DD imagerel $L$xts_enc_info
DD imagerel $L$xts_dec_prologue
DD imagerel $L$xts_dec_epilogue
DD imagerel $L$xts_dec_info
.pdata ENDS
.xdata SEGMENT READONLY ALIGN(8)
ALIGN 8
$L$cbc_dec_info::
DB 9,0,0,0
DD imagerel se_handler
DD imagerel $L$cbc_dec_body,imagerel $L$cbc_dec_epilogue
$L$ctr_enc_info::
DB 9,0,0,0
DD imagerel se_handler
DD imagerel $L$ctr_enc_body,imagerel $L$ctr_enc_epilogue
$L$xts_enc_info::
DB 9,0,0,0
DD imagerel se_handler
DD imagerel $L$xts_enc_body,imagerel $L$xts_enc_epilogue
$L$xts_dec_info::
DB 9,0,0,0
DD imagerel se_handler
DD imagerel $L$xts_dec_body,imagerel $L$xts_dec_epilogue
.xdata ENDS
END
| 19.875178 | 60 | 0.752635 |
9aa24aa25391bffd908c04d4d8258afe17c66722 | 960 | asm | Assembly | programs/oeis/008/A008592.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | null | null | null | programs/oeis/008/A008592.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | null | null | null | programs/oeis/008/A008592.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | null | null | null | ; A008592: Multiples of 10: a(n) = 10 * n.
; 0,10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,190,200,210,220,230,240,250,260,270,280,290,300,310,320,330,340,350,360,370,380,390,400,410,420,430,440,450,460,470,480,490,500,510,520,530,540,550,560,570,580,590,600,610,620,630,640,650,660,670,680,690,700,710,720,730,740,750,760,770,780,790,800,810,820,830,840,850,860,870,880,890,900,910,920,930,940,950,960,970,980,990,1000,1010,1020,1030,1040,1050,1060,1070,1080,1090,1100,1110,1120,1130,1140,1150,1160,1170,1180,1190,1200,1210,1220,1230,1240,1250,1260,1270,1280,1290,1300,1310,1320,1330,1340,1350,1360,1370,1380,1390,1400,1410,1420,1430,1440,1450,1460,1470,1480,1490,1500,1510,1520,1530,1540,1550,1560,1570,1580,1590,1600,1610,1620,1630,1640,1650,1660,1670,1680,1690,1700,1710,1720,1730,1740,1750,1760,1770,1780,1790,1800,1810,1820,1830,1840,1850,1860,1870,1880,1890,1900,1910,1920,1930,1940,1950,1960,1970,1980,1990,2000
mov $1,$0
mul $1,10
| 160 | 895 | 0.759375 |
15a933f4767b8a8d926db3d01a6c076004125281 | 1,276 | asm | Assembly | main.asm | mkiesinski/the-way-nes | 59df7a4b09f76eedcac50bd0121899f01387e9dc | [
"MIT"
] | 2 | 2018-02-10T19:47:03.000Z | 2018-09-05T18:07:25.000Z | main.asm | mkiesinski/no-mans-byte-nes | 59df7a4b09f76eedcac50bd0121899f01387e9dc | [
"MIT"
] | null | null | null | main.asm | mkiesinski/no-mans-byte-nes | 59df7a4b09f76eedcac50bd0121899f01387e9dc | [
"MIT"
] | null | null | null | .inesprg 4 ; 4x 16KB PRG = 128KB PRG
.ineschr 0 ; 0x 8KB CHR
.inesmap 1 ; MMC1 mapper
.inesmir %10
.include "nes_constants.asm"
.include "constants.asm"
.rsset $0000
.include "variables.asm"
.bank 0
.org $8000
.include "maps/map00.asm"
.bank 1
.org $A000
.bank 2
.org $8000
.bank 3
.org $A000
.bank 4
.org $8000
.bank 5
.org $A000
.bank 6
.org $C000
Graphics:
.incbin "graphics/bank.chr"
.bank 7
.org $E000
;; subroutines
.include "init_helper.asm"
.include "engine/readController.asm"
.include "engine/drawsprite.asm"
.include "engine/renderMap.asm"
.include "engine/renderPlayer.asm"
.include "engine/renderEnemies.asm"
;; START
.include "init.asm"
.include "engine/init.asm"
NMI
.include "engine/engine.asm"
RTI
.include "engine/overworld.asm"
palette:
.db $30,$37,$16,$27, $22,$16,$17,$0F, $22,$30,$21,$0F, $22,$27,$17,$0F ;;background palette
.db $30,$1E,$16,$27, $30,$0F,$16,$30, $22,$1C,$15,$14, $22,$02,$38,$3C ;;sprite palette
.include "maps/tileset.asm"
.include "sprites/sprites.asm"
.org $FFFA
.dw NMI
.dw RESET
.dw 0 | 18.764706 | 100 | 0.561129 |
8a534ec025d2f316294e3ae3600209ac277dedb6 | 34,616 | asm | Assembly | AMPS/code/68k Debug.asm | NatsumiFox/AMPS-Sonic-3-Knuckles | af951b39f0ca103a905d7492448ac5245a2e8104 | [
"Apache-2.0"
] | 5 | 2021-07-09T08:17:56.000Z | 2022-02-27T19:57:47.000Z | AMPS/code/68k Debug.asm | NatsumiFox/AMPS-Sonic-3-Knuckles | af951b39f0ca103a905d7492448ac5245a2e8104 | [
"Apache-2.0"
] | null | null | null | AMPS/code/68k Debug.asm | NatsumiFox/AMPS-Sonic-3-Knuckles | af951b39f0ca103a905d7492448ac5245a2e8104 | [
"Apache-2.0"
] | null | null | null | ; ===========================================================================
; ---------------------------------------------------------------------------
;
; ---------------------------------------------------------------------------
if safe=1 ; all of this code is only required in safe mode!
ifndef isAMPS
warning "Not using custom debugger macro definition! All features may not work."
endif
; ===========================================================================
; ---------------------------------------------------------------------------
; write channel string to console
; ---------------------------------------------------------------------------
if isAMPS ; check if Vladik's debugger is active
AMPS_Debug_GetChannel macro
cmp.w #mPSG1,a1
bne.s .cpsg2
Console.Write "PSG1"
bra.w .end
.cpsg2
cmp.w #mPSG2,a1
bne.s .cpsg3
Console.Write "PSG2"
bra.w .end
.cpsg3
cmp.w #mPSG3,a1
bne.s .cpsgs1
Console.Write "PSG3"
bra.w .end
.cpsgs1
cmp.w #mSFXPSG1,a1
bne.s .cpsgs2
Console.Write "SFX PSG1"
bra.w .end
.cpsgs2
cmp.w #mSFXPSG2,a1
bne.s .cpsgs3
Console.Write "SFX PSG2"
bra.w .end
.cpsgs3
cmp.w #mSFXPSG3,a1
bne.s .cdacs1
Console.Write "SFX PSG3"
bra.w .end
.cdacs1
cmp.w #mSFXDAC1,a1
bne.s .cdac1
Console.Write "SFX DAC1"
bra.w .end
.cdac1
cmp.w #mDAC1,a1
bne.s .cdac2
Console.Write "DAC1"
bra.w .end
.cdac2
cmp.w #mDAC2,a1
bne.s .cfm1
Console.Write "DAC2"
bra.w .end
.cfm1
cmp.w #mFM1,a1
bne.s .cfm2
Console.Write "FM1"
bra.w .end
.cfm2
cmp.w #mFM2,a1
bne.s .cfm3
Console.Write "FM2"
bra.w .end
.cfm3
cmp.w #mFM3,a1
bne.s .cfm4
Console.Write "FM3"
bra.w .end
.cfm4
cmp.w #mFM4,a1
bne.s .cfm5
Console.Write "FM4"
bra.w .end
.cfm5
cmp.w #mFM5,a1
bne.s .cfms3
Console.Write "FM5"
bra.w .end
.cfms3
cmp.w #mSFXFM3,a1
bne.s .cfms4
Console.Write "SFX FM3"
rts
.cfms4
cmp.w #mSFXFM4,a1
bne.s .cfms5
Console.Write "SFX FM4"
bra.s .end
.cfms5
cmp.w #mSFXFM5,a1
beq.s .cfms5_
.addr
Console.Write "%<pal2>%<.l a1>"
rts
.cfms5_
Console.Write "SFX FM5"
.end
endm
endif
; ===========================================================================
; ---------------------------------------------------------------------------
; Channel console code
; ---------------------------------------------------------------------------
if isAMPS ; check if Vladik's debugger is active
AMPS_Debug_Console_Channel:
Console.WriteLine " %<pal0>d0: %<pal2>%<.l d0> %<pal0>a0: %<pal2>%<.l a0>"
Console.WriteLine " %<pal0>d1: %<pal2>%<.l d1> %<pal0>a1: %<pal2>%<.l a1>"
Console.WriteLine " %<pal0>d2: %<pal2>%<.l d2> %<pal0>a2: %<pal2>%<.l a2>"
Console.WriteLine " %<pal0>d3: %<pal2>%<.l d3> %<pal0>a3: %<pal2>%<.l a3>"
Console.WriteLine " %<pal0>d4: %<pal2>%<.l d4> %<pal0>a4: %<pal2>%<.l a4>"
Console.WriteLine " %<pal0>d5: %<pal2>%<.l d5> %<pal0>a5: %<pal2>%<.l a5>"
Console.WriteLine " %<pal0>d6: %<pal2>%<.l d6> %<pal0>a6: %<pal2>%<.l a6>"
Console.WriteLine " %<pal0>d7: %<pal2>%<.l d7> %<pal0>sp: %<pal2>%<.l a7>"
Console.BreakLine
Console.Write "%<pal1>Channel: %<pal0>"
AMPS_Debug_GetChannel
Console.BreakLine
Console.WriteLine "%<pal1>Addr: %<pal0>%<.l a4 sym|split>%<pal2>%<symdisp>"
; ---------------------------------------------------------------------------
; fmt: flag, type, pan, det, pitch, vol, tick, sample/voice, dur, lastdur, freq
; some AS is ASS code here!
move.b cType(a1),d0
move.b cPanning(a1),d1
Console.Write "%<pal1>CH: %<pal2>%<.b (a1)> %<.b d0> %<.b d1> "
move.b cDetune(a1),d0
move.b cPitch(a1),d1
move.b cVolume(a1),d2
move.b cTick(a1),d3
Console.Write "%<.b d0> %<.b d1> %<.b d2> %<.b d3> "
move.b cSample(a1),d0
move.b cDuration(a1),d1
move.b cLastDur(a1),d2
move.w cFreq(a1),d3
Console.Write "%<.b d0> %<.b d1> %<.b d2> %<.w d3> "
Console.BreakLine
; ---------------------------------------------------------------------------
if FEATURE_MODULATION
move.l cMod(a1),d0
Console.WriteLine "%<pal1>Mod: %<pal0>%<.l d0 sym|split>%<pal2>%<symdisp>"
move.b cModDelay(a1),d0
move.w cModFreq(a1),d1
move.b cModSpeed(a1),d2
move.b cModStep(a1),d3
move.b cModCount(a1),d4
Console.Write "%<pal1>Mod Data: %<pal2>%<.b d0> %<.w d1> %<.b d2> %<.b d3> %<.b d4>"
Console.BreakLine
endif
; ---------------------------------------------------------------------------
if FEATURE_PORTAMENTO
move.b cPortaSpeed(a1),d0
move.w cPortaFreq(a1),d1
move.w cPortaDisp(a1),d2
Console.WriteLine "%<pal1>Porta: %<pal2>%<.b d0> %<.w d1> %<.w d2>"
Console.BreakLine
endif
; ---------------------------------------------------------------------------
move.b cVolEnv(a1),d0
move.b cEnvPos(a1),d1
Console.WriteLine "%<pal1>VolEnv: %<pal2>%<.b d0> %<pal2>%<.b d1>"
Console.BreakLine
if FEATURE_MODENV=0
Console.BreakLine
endif
; ---------------------------------------------------------------------------
if FEATURE_MODENV
move.b cModEnv(a1),d0
move.b cModEnvPos(a1),d1
move.b cModEnvSens(a1),d2
Console.WriteLine "%<pal1>ModEnv: %<pal2>%<.b d0> %<.b d1>%<.b d2>"
Console.BreakLine
endif
; ---------------------------------------------------------------------------
move.b cLoop(a1),d0
move.b cLoop+1(a1),d1
move.b cLoop+2(a1),d2
Console.Write "%<pal1>Loop: %<pal2>%<.b d0> %<.b d1> %<.b d2> "
cmp.w #mSFXDAC1,a1
bhs.w .rts
moveq #0,d0
move.b cStack(a1),d0
move.b cGateCur(a1),d2
move.b cGateMain(a1),d1
Console.WriteLine "%<.b d2> %<.b d1>"
Console.WriteLine "%<pal1>Stack: %<pal2>%<.b d0>"
; ---------------------------------------------------------------------------
move.w a1,d1
add.w #cSize,d1
add.w d0,a1
.loop
cmp.w a1,d1
bls.s .rts
Console.WriteLine "%<pal0>%<.l (a1) sym|split>%<pal2>%<symdisp>"
tst.l (a1)+
bra.s .loop
.rts
rts
endif
; ===========================================================================
; ---------------------------------------------------------------------------
; Generic console code
; ---------------------------------------------------------------------------
if isAMPS ; check if Vladik's debugger is active
AMPS_Debug_Console_Main:
Console.WriteLine " %<pal0>d0: %<pal2>%<.l d0> %<pal0>a0: %<pal2>%<.l a0>"
Console.WriteLine " %<pal0>d1: %<pal2>%<.l d1> %<pal0>a1: %<pal2>%<.l a1>"
Console.WriteLine " %<pal0>d2: %<pal2>%<.l d2> %<pal0>a2: %<pal2>%<.l a2>"
Console.WriteLine " %<pal0>d3: %<pal2>%<.l d3> %<pal0>a3: %<pal2>%<.l a3>"
Console.WriteLine " %<pal0>d4: %<pal2>%<.l d4> %<pal0>a4: %<pal2>%<.l a4>"
Console.WriteLine " %<pal0>d5: %<pal2>%<.l d5> %<pal0>a5: %<pal2>%<.l a5>"
Console.WriteLine " %<pal0>d6: %<pal2>%<.l d6> %<pal0>a6: %<pal2>%<.l a6>"
Console.WriteLine " %<pal0>d7: %<pal2>%<.l d7> %<pal0>sp: %<pal2>%<.l a7>"
Console.BreakLine
; ---------------------------------------------------------------------------
move.l mVctMus.w,d0
Console.WriteLine "%<pal1>PatMus: %<pal0>%<.l d0 sym|split>%<pal2>%<symdisp>"
move.b mFlags.w,d0
move.b mCtrPal.w,d1
Console.Write "%<pal1>Misc: %<pal2>%<.b d0> %<.b d1> "
move.b mSpindash.w,d0
move.b mContCtr.w,d1
move.b mContLast.w,d2
Console.WriteLine "%<.b d0> %<.b d1> %<.b d2>"
move.b mTempo.w,d0
move.b mTempoAcc.w,d1
move.b mSpeed.w,d2
move.b mSpeedAcc.w,d3
Console.WriteLine "%<pal1>Tempo: %<pal2>%<.b d0> %<.b d1> %<.b d2> %<.b d3>"
move.b mMasterVolFM.w,d0
move.b mMasterVolDAC.w,d1
move.b mMasterVolPSG.w,d2
Console.WriteLine "%<pal1>Volume: %<pal2>%<.b d0> %<.b d1> %<.b d2>"
move.l mVctMus.w,d0
Console.WriteLine "%<pal1>Fade: %<pal0>%<.l d0 sym|split>%<pal2>%<symdisp>"
move.b mQueue.w,d0
move.b mQueue+1.w,d1
move.b mQueue+2.w,d2
Console.WriteLine "%<pal1>Queue: %<pal2>%<.b d0> %<.b d1> %<.b d2>"
move.b mComm.w,d0
move.b mComm+1.w,d1
move.b mComm+2.w,d2
Console.Write "%<pal1>Comm: %<pal2>%<.b d0> %<.b d1> %<.b d2> "
move.b mComm+3.w,d0
move.b mComm+4.w,d1
move.b mComm+5.w,d2
Console.Write "%<.b d0> %<.b d1> %<.b d2> "
move.b mComm+6.w,d0
move.b mComm+7.w,d1
Console.WriteLine "%<.b d0> %<.b d1>"
.rts
rts
endif
; ===========================================================================
; ---------------------------------------------------------------------------
; Invalid fade address handler
; ---------------------------------------------------------------------------
AMPS_Debug_FadeAddr macro
cmp.l #$10000,a4 ; check if the address is in 16-bit range
bhs.s .ok2 ; if not, continue to work
if isAMPS ; check if Vladik's debugger is active
jsr AMPS_DebugR_FadeAddr
else
bra.w *
endif
.ok2
endm
; ---------------------------------------------------------------------------
if isAMPS ; check if Vladik's debugger is active
AMPS_DebugR_FadeAddr:
RaiseError2 "Fade data must be after address $10000but was at: %<pal0>%<.l a4 sym|split>%<pal2>%<symdisp>", AMPS_Debug_Console_Channel
endif
; ===========================================================================
; ---------------------------------------------------------------------------
; Invalid fade command handler
; ---------------------------------------------------------------------------
AMPS_Debug_FadeCmd macro
cmp.b #fLast,d2 ; check against max
bhs.s .fail ; if in range, branch
cmp.b #$80,d2 ; check against min
blo.s .fail ; if too little, bra
btst #1,d2 ; check if bit1 set
bne.s .fail ; if is, branch
btst #0,d2 ; check if even
beq.s .ok ; if is, branch
.fail
if isAMPS ; check if Vladik's debugger is active
jsr AMPS_DebugR_FadeCmd
else
bra.w *
endif
.ok
endm
; ---------------------------------------------------------------------------
if isAMPS ; check if Vladik's debugger is active
AMPS_DebugR_FadeCmd:
RaiseError2 "Invalid Fade command: %<.b d2>", AMPS_Debug_Console_Main
endif
; ===========================================================================
; ---------------------------------------------------------------------------
; Invalid volume envelope handler
; ---------------------------------------------------------------------------
AMPS_Debug_VolEnvID macro
cmp.b #(VolEnvs_End-VolEnvs)/4,d4 ; check against max
bls.s .ok ; if in range, branch
if isAMPS ; check if Vladik's debugger is active
jsr AMPS_DebugR_VolEnvID
else
bra.w *
endif
.ok
endm
; ---------------------------------------------------------------------------
if isAMPS ; check if Vladik's debugger is active
AMPS_DebugR_VolEnvID:
RaiseError2 "Volume envelope ID out of range: %<.b d4>", AMPS_Debug_Console_Channel
endif
; ===========================================================================
; ---------------------------------------------------------------------------
; Invalid volume envelope command handler
; ---------------------------------------------------------------------------
AMPS_Debug_VolEnvCmd macro
btst #0,d4 ; check if even
beq.s .ok ; if is, branch
if isAMPS ; check if Vladik's debugger is active
RaiseError2 "Invalid volume envelope command: %<.b d4>", AMPS_Debug_Console_Channel
else
bra.w *
endif
.ok
endm
; ===========================================================================
; ---------------------------------------------------------------------------
; Invalid modulation envelope handler
; ---------------------------------------------------------------------------
AMPS_Debug_ModEnvID macro
cmp.b #(ModEnvs_End-ModEnvs)/4,d4 ; check against max
bls.s .ok ; if in range, branch
if isAMPS ; check if Vladik's debugger is active
jsr AMPS_DebugR_ModEnvID
else
bra.w *
endif
.ok
endm
; ---------------------------------------------------------------------------
if isAMPS ; check if Vladik's debugger is active
AMPS_DebugR_ModEnvID:
RaiseError2 "Modulation envelope ID out of range: %<.b d4>", AMPS_Debug_Console_Channel
endif
; ===========================================================================
; ---------------------------------------------------------------------------
; PSG note check
; ---------------------------------------------------------------------------
AMPS_Debug_NotePSG macro
cmp.b #dFreqPSG_-dFreqPSG,d1; check against max
blo.s .ok ; if too little, bra
.fail
if isAMPS ; check if Vladik's debugger is active
jsr AMPS_DebugR_NotePSG
else
bra.w *
endif
.ok
endm
; ---------------------------------------------------------------------------
if isAMPS ; check if Vladik's debugger is active
AMPS_DebugR_NotePSG:
lsr.w #1,d1 ; get real note
RaiseError2 "Invalid PSG note: %<.b d1>", AMPS_Debug_Console_Channel
endif
; ===========================================================================
; ---------------------------------------------------------------------------
; FM note check
; ---------------------------------------------------------------------------
AMPS_Debug_NoteFM macro
cmp.b #dFreqFM_-dFreqFM,d1; check against max
blo.s .ok ; if too little, bra
.fail
if isAMPS ; check if Vladik's debugger is active
jsr AMPS_DebugR_NoteFM
else
bra.w *
endif
.ok
endm
; ---------------------------------------------------------------------------
if isAMPS ; check if Vladik's debugger is active
AMPS_DebugR_NoteFM:
lsr.w #1,d1 ; get real note
RaiseError2 "Invalid FM note: %<.b d1>", AMPS_Debug_Console_Channel
endif
; ===========================================================================
; ---------------------------------------------------------------------------
; DAC frequency check
; ---------------------------------------------------------------------------
AMPS_Debug_FreqDAC macro
cmp.w #MaxPitch,d2 ; check if frequency is too large
bgt.s .fail ; if so, branch
cmp.w #-MaxPitch,d2 ; check if frequency is too small
bge.s .ok ; if not, branch
.fail
if isAMPS ; check if Vladik's debugger is active
jsr AMPS_DebugR_FreqDAC
else
bra.w *
endif
.ok
endm
; ---------------------------------------------------------------------------
if isAMPS ; check if Vladik's debugger is active
AMPS_DebugR_FreqDAC:
RaiseError "Out of range DAC frequency: %<.w d2>", AMPS_Debug_Console_Channel
endif
; ===========================================================================
; ---------------------------------------------------------------------------
; Invalid tracker command handlers
; ---------------------------------------------------------------------------
AMPS_Debug_dcInvalid macro
if isAMPS ; check if Vladik's debugger is active
RaiseError "Invalid command detected!", AMPS_Debug_Console_Channel
else
bra.w *
endif
endm
; ===========================================================================
; ---------------------------------------------------------------------------
; Handler for disabled features - portamento
; ---------------------------------------------------------------------------
AMPS_Debug_dcPortamento macro
if isAMPS ; check if Vladik's debugger is active
RaiseError "Portamento feature is disabled. Set FEATURE_PORTAMENTO to 1 to enable.", AMPS_Debug_Console_Channel
else
bra.w *
endif
endm
; ===========================================================================
; ---------------------------------------------------------------------------
; Handler for disabled features - modulation
; ---------------------------------------------------------------------------
AMPS_Debug_dcModulate macro
if isAMPS ; check if Vladik's debugger is active
jsr AMPS_DebugR_dcModulate
else
bra.w *
endif
endm
; ---------------------------------------------------------------------------
if FEATURE_MODULATION=0
if isAMPS ; check if Vladik's debugger is active
AMPS_DebugR_dcModulate:
RaiseError "Modulation feature is disabled. Set FEATURE_MODULATION to 1 to enable.", AMPS_Debug_Console_Channel
endif
endif
; ===========================================================================
; ---------------------------------------------------------------------------
; Handler for PSG channel using dcVoice
; ---------------------------------------------------------------------------
AMPS_Debug_dcVoiceEnv macro
tst.b cType(a1) ; check if this is a PSG channel
bpl.s .ok ; if not, skip
if isAMPS ; check if Vladik's debugger is active
jsr AMPS_DebugR_dcVoiceEnv
else
bra.w *
endif
.ok
endm
; ---------------------------------------------------------------------------
if isAMPS ; check if Vladik's debugger is active
AMPS_DebugR_dcVoiceEnv:
RaiseError "You can not use sVoice for PSG channel. Please use sVolEnv instead.", AMPS_Debug_Console_Channel
endif
; ===========================================================================
; ---------------------------------------------------------------------------
; Handler for disabled features - modulation envelopes
; ---------------------------------------------------------------------------
AMPS_Debug_dcModEnv macro
if isAMPS ; check if Vladik's debugger is active
RaiseError "Modulation envelopes are disabled. Set FEATURE_MODENV to 1 to enable.", AMPS_Debug_Console_Channel
else
bra.w *
endif
endm
; ===========================================================================
; ---------------------------------------------------------------------------
; Handler for disabled features - modulation
; ---------------------------------------------------------------------------
AMPS_Debug_dcBackup macro
if isAMPS ; check if Vladik's debugger is active
jsr AMPS_DebugR_dcBackup
else
bra.w *
endif
endm
if FEATURE_BACKUP=0
if isAMPS ; check if Vladik's debugger is active
AMPS_DebugR_dcBackup:
RaiseError "Backup feature is disabled. Set FEATURE_BACKUP to 1 to enable.", AMPS_Debug_Console_Channel
endif
endif
; ===========================================================================
; ---------------------------------------------------------------------------
; PSG on sPan handler
; ---------------------------------------------------------------------------
AMPS_Debug_dcPan macro
if FEATURE_FM6
cmp.w #mFM6,a1; check if this is FM6
beq.s .fail ; if so, branch
endif
tst.b cType(a1) ; check for PSG channel
bpl.s .ok ; if no, branch
if isAMPS ; check if Vladik's debugger is active
RaiseError "sPan on a PSG channel!", AMPS_Debug_Console_Channel
else
bra.w *
endif
.fail
if isAMPS ; check if Vladik's debugger is active
RaiseError "sPan on FM6 channel!", AMPS_Debug_Console_Channel
else
bra.w *
endif
.ok
endm
; ===========================================================================
; ---------------------------------------------------------------------------
; NoisePSG command on an invalid channel handler
; ---------------------------------------------------------------------------
AMPS_Debug_dcNoisePSG macro
beq.s .ckch ; branch if value is 0
cmp.b #snPeri10,d3 ; check if the value is below valid range
blo.s .fail ; branch if yes
cmp.b #snWhitePSG3,d3 ; check if the value is above valid range
bls.s .ckch ; branch if not
.fail
if isAMPS ; check if Vladik's debugger is active
RaiseError "sNoisePSG with an invalid value: %<.b d3>", AMPS_Debug_Console_Channel
else
bra.w *
endif
.ckch
cmp.b #ctPSG3,cType(a1); check if this is PSG3 or PSG4 channel
bhs.s .ok ; if is, branch
if isAMPS ; check if Vladik's debugger is active
RaiseError "sNoisePSG on an invalid channel!", AMPS_Debug_Console_Channel
else
bra.w *
endif
.ok
endm
; ===========================================================================
; ---------------------------------------------------------------------------
; Gate command on SFX channel handler
; ---------------------------------------------------------------------------
AMPS_Debug_dcGate macro
cmp.w #mSFXDAC1,a1 ; check for SFX channel
blo.s .ok ; if not, branch
if isAMPS ; check if Vladik's debugger is active
RaiseError "sGate on a SFX channel!", AMPS_Debug_Console_Channel
else
bra.w *
endif
.ok
endm
; ===========================================================================
; ---------------------------------------------------------------------------
; Call command handlers
; ---------------------------------------------------------------------------
AMPS_Debug_dcCall1 macro
cmp.w #mSFXDAC1,a1 ; check for SFX channel
blo.s .ok1 ; if no, branch
if isAMPS ; check if Vladik's debugger is active
RaiseError "sCall on a SFX channel!", AMPS_Debug_Console_Channel
else
bra.w *
endif
.ok1
endm
; ---------------------------------------------------------------------------
AMPS_Debug_dcCall2 macro
cmp.b #cGateCur,d4 ; check for invalid stack address
bhi.s .ok2 ; if no, branch
if isAMPS ; check if Vladik's debugger is active
RaiseError "sCall stack too deep!", AMPS_Debug_Console_Channel
else
bra.w *
endif
.ok2
endm
; ===========================================================================
; ---------------------------------------------------------------------------
; Loop command handler
; ---------------------------------------------------------------------------
AMPS_Debug_dcLoop macro
cmp.b #cSizeSFX-cLoop,d4 ; check for invalid call number
bhi.s .fail ; if is, branch
cmp.w #mSFXDAC1,a1 ; check for SFX channel
blo.s .ok ; if no, branch
cmp.b #cPrio-cLoop,d4 ; check if cPrio
bne.s .ok ; if not, branch
.fail
if isAMPS ; check if Vladik's debugger is active
RaiseError "sLoop ID %<.b d4> is invalid!", AMPS_Debug_Console_Channel
else
bra.w *
endif
.ok
endm
; ===========================================================================
; ---------------------------------------------------------------------------
; Return command handlers
; ---------------------------------------------------------------------------
AMPS_Debug_dcReturn1 macro
cmp.w #mSFXDAC1,a1 ; check for SFX channel
blo.s .ok1 ; if no, branch
if isAMPS ; check if Vladik's debugger is active
RaiseError "sRet on a SFX channel!", AMPS_Debug_Console_Channel
else
bra.w *
endif
.ok1
endm
; ---------------------------------------------------------------------------
AMPS_Debug_dcReturn2 macro
cmp.b #cSize,d3 ; check for invalid stack address
bls.s .ok2 ; if no, branch
if isAMPS ; check if Vladik's debugger is active
RaiseError "sRet stack too shallow!", AMPS_Debug_Console_Channel
else
bra.w *
endif
.ok2
endm
; ===========================================================================
; ---------------------------------------------------------------------------
; Update FM voice handler
; ---------------------------------------------------------------------------
AMPS_Debug_UpdVoiceFM macro
cmp.b #'N',(a4)+ ; check if this is valid voice
bne.s .fail ; if not, branch
cmp.w #'AT',(a4)+ ; check if this is valid voice
beq.s .ok ; if is, branch
.fail
if isAMPS ; check if Vladik's debugger is active
move.b cVoice(a1),d4
RaiseError "FM voice Update invalid voice: %<.b d4>", AMPS_Debug_Console_Channel
else
bra.w *
endif
.ok
endm
; ===========================================================================
; ---------------------------------------------------------------------------
; Update FM Volume handler
; ---------------------------------------------------------------------------
AMPS_Debug_UpdVolFM macro
cmp.b #'N',(a4)+ ; check if this is valid voice
bne.s .fail ; if not, branch
cmp.w #'AT',(a4)+ ; check if this is valid voice
beq.s .ok ; if is, branch
.fail
if isAMPS ; check if Vladik's debugger is active
jsr AMPS_DebugR_UpdVolFM
else
bra.w *
endif
.ok
endm
; ---------------------------------------------------------------------------
if isAMPS ; check if Vladik's debugger is active
AMPS_DebugR_UpdVolFM:
move.b cVoice(a1),d4
RaiseError2 "FM Volume Update invalid voice: %<.b d4>", AMPS_Debug_Console_Channel
endif
; ===========================================================================
; ---------------------------------------------------------------------------
; Invalid cue handler
; ---------------------------------------------------------------------------
AMPS_Debug_CuePtr macro id
cmp.l #$A00000+YM_Buffer1,a0 ; check against min
blo.s .fail ; if not in range, branch
cmp.l #$A00000+YM_BufferEnd,a0; check against max
blo.s .ok ; if in range, branch
.fail
if isAMPS ; check if Vladik's debugger is active
jsr AMPS_DebugR_CuePtr{"id"}
else
bra.w *
endif
.ok
endm
; ---------------------------------------------------------------------------
if isAMPS ; check if Vladik's debugger is active
AMPS_DebugR_CuePtrGen:
RaiseError2 "CUE invalid at macro: %<.l a0>", AMPS_Debug_Console_Channel
AMPS_DebugR_CuePtr0:
RaiseError2 "CUE invalid at dUpdateVoiceFM: %<.l a0>", AMPS_Debug_Console_Channel
AMPS_DebugR_CuePtr3:
RaiseError2 "CUE invalid at UpdateAMPS: %<.l a0>", AMPS_Debug_Console_Channel
endif
; ===========================================================================
; ---------------------------------------------------------------------------
; Play Command handler
; ---------------------------------------------------------------------------
AMPS_Debug_PlayCmd macro
cmp.b #(dSoundCommands_End-dSoundCommands)/4,d1; check if this is valid command
bls.s .ok ; if is, branch
if isAMPS ; check if Vladik's debugger is active
RaiseError "Invalid command in queue: %<.b d1>", AMPS_Debug_Console_Channel
else
bra.w *
endif
.ok
endm
; ===========================================================================
; ---------------------------------------------------------------------------
; Sound ID check
; ---------------------------------------------------------------------------
AMPS_Debug_SoundID macro
cmp.b #SFXlast,d1 ; check if this is a valid sound id
blo.s .ok ; if yes, branch
if isAMPS ; check if Vladik's debugger is active
RaiseError "Sound ID %<.b d1> is not a valid sound!", AMPS_Debug_Console_Main
else
bra.w *
endif
.ok
endm
; ===========================================================================
; ---------------------------------------------------------------------------
; Tracker address handlers
; ---------------------------------------------------------------------------
AMPS_Debug_PlayTrackMus macro
cmp.l #musaddr,d2 ; check if this is valid tracker
blo.s .fail ; if no, branch
cmp.l #musend,d2 ; check if this is valid tracker
blo.s .ok ; if is, branch
.fail
if isAMPS ; check if Vladik's debugger is active
lsr.w #2,d1 ; get actual ID
RaiseError "Invalid tracker at Music %<.b d1>: %<.l d2>%<endl>%<.l d2 sym>", AMPS_Debug_Console_Main
else
bra.w *
endif
.ok
endm
; ---------------------------------------------------------------------------
AMPS_Debug_PlayTrackMus2 macro ch
swap d2 ; make some space to store stuff
move.w d1,d2 ; store this thing away
move.l a3,d1 ; load the target address
and.l #$FFFFFF,d1 ; remove high byte
cmp.l #musaddr,d1 ; check if this is valid tracker
blo.s .fail ; if no, branch
cmp.l #dacaddr,d1 ; check if this is valid tracker
blo.s .ok ; if is, branch
.fail
if isAMPS ; check if Vladik's debugger is active
RaiseError "Invalid tracker at Music ch: %<.l d1>%<endl>%<.l d1 sym>", AMPS_Debug_Console_Main
else
bra.w *
endif
.ok
move.w d2,d1 ; get the value back
swap d2 ; also this one as well
endm
; ---------------------------------------------------------------------------
AMPS_Debug_PlayTrackSFX macro
cmp.l #sfxaddr,d2 ; check if this is valid tracker
blo.s .fail ; if no, branch
cmp.l #musaddr,d2 ; check if this is valid tracker
blo.s .ok ; if is, branch
.fail
if isAMPS ; check if Vladik's debugger is active
lsr.w #2,d1 ; get actual ID
RaiseError "Invalid tracker at SFX %<.b d1>: %<.l d2>%<endl>%<.l d2 sym>", AMPS_Debug_Console_Main
else
bra.w *
endif
.ok
endm
; ---------------------------------------------------------------------------
AMPS_Debug_PlayTrackSFX2 macro
move.l a3,d4
and.l #$FFFFFF,d4 ; remove high byte
cmp.l #sfxaddr,d4 ; check if this is valid tracker
blo.s .fail ; if no, branch
cmp.l #musaddr,d4 ; check if this is valid tracker
blo.s .ok ; if is, branch
.fail
if isAMPS ; check if Vladik's debugger is active
RaiseError "Invalid tracker at SFX ch: %<.l d2>%<endl>%<.l d2 sym>", AMPS_Debug_Console_Main
else
bra.w *
endif
.ok
endm
; ---------------------------------------------------------------------------
AMPS_Debug_TrackUpd macro
move.l a2,d1 ; copy to d1
and.l #$FFFFFF,d1 ; remove high byte
cmp.l #sfxaddr,d1 ; check if this is valid tracker
blo.s .fail2 ; if no, branch
cmp.l #dacaddr,d1 ; check if this is valid tracker
blo.s .data ; if is, branch
.fail2
if isAMPS ; check if Vladik's debugger is active
RaiseError "Invalid tracker address: %<.l a2>%<endl>%<.l a2 sym>", AMPS_Debug_Console_Channel
else
bra.w *
endif
endm
; ===========================================================================
; ---------------------------------------------------------------------------
; Tracker debugger handler and console code
; ---------------------------------------------------------------------------
AMPS_Debug_ChkTracker macro
.fail
if isAMPS ; check if Vladik's debugger is active
jsr AMPS_DebugR_ChkTracker
else
bra.w *
endif
endm
; ---------------------------------------------------------------------------
AMPS_DebugR_ChkTracker:
ifndef isAMPS ; if not custom version
moveq #0,d7
Console.Run AMPS_DebugR_ChkTracker2
else
jsr AMPS_Debug_CalcMax(pc)
swap d7 ; swap d7 words
.loop
move.l d7,$FF0000 ; save stuff in RAM
Console.Run AMPS_DebugR_ChkTracker2, NAT
move.l $FF0000,d7 ; get stuff back
.nodraw
moveq #-1,d6
dbf d6,* ; delay a lot
; ---------------------------------------------------------------------------
; implement reading control data
lea $A10003,a1
move.b #0,(a1) ; set TH low
or.l d0,d0 ; delay
move.b #$40,(a1) ; set TH high
or.l d0,d0 ; delay
move.b (a1),d0 ; get dpad stat
move.w d7,d5 ; copy to d5
btst #0,d0 ; check if up held
bne.s .ckd ; if not ,branch
subq.w #1,d7 ; move up
bpl.s .ckd ; if positive, branch
clr.w d7 ; else force to 0
.ckd
btst #1,d0 ; check if down held
bne.s .ckdraw ; if not ,branch
swap d7
move.w d7,d6 ; copy high word to d6
swap d7
cmp.w d6,d7 ; check if we can move up
bge.s .ckdraw ; if not, branch
addq.w #1,d7 ; move down
.ckdraw
cmp.w d7,d5 ; check if we need to redraw
beq.s .nodraw ; if not, branch
bra.w .loop
endif
; ---------------------------------------------------------------------------
AMPS_Debug_CalcMax:
moveq #28,d6 ; max lines count
moveq #10-1,d7 ; run for 10 chs
moveq #cSize,d5 ; prepare size
lea mPSG3.w,a5 ; start at PSG3
.chkloop
tst.w d6 ; check if we have no lines left
; ble.s .rts ; if so, we found it
subq.w #3,d6 ; we need at least 3 lines
bmi.s .add ; if not enough lines, branch
move.w a5,d1 ; copy ch to d1
add.w #cSize,d1 ; go to end of it
moveq #0,d0
move.b cStack(a5),d0 ; get stack to d0
lea (a5,d0.w),a6 ; and get first element to a6
.stack
cmp.w a6,d1 ; check if stack is dry now
bhi.s .inc ; if not, branch
sub.w d5,a5 ; sub ch size
dbf d7,.chkloop ; loop for all chans
bra.s .add
.inc
addq.w #4,a6 ; go to next long
subq.w #1,d6 ; sub 1 line
bpl.s .stack ; if lines left, branch
.add
addq.w #1,d7 ; increase ch by 1
.rts
rts
; ---------------------------------------------------------------------------
AMPS_DebugR_ChkTracker_Ch:
subq.w #1,d7 ; sub 1 from offset
bpl.w .n ; branch if positive
tst.w d6 ; check if we need to render anymore
bmi.w .n ; if not, branch
; fmt: <addr> lstdur, dur, freq, sample, loop0, loop1, loop2
jsr (a0)
move.b cLastDur(a5),d0
move.b cDuration(a5),d1
move.w cFreq(a5),d2
Console.Write ": %<pal2>%<.w a5> %<.b d0> %<.b d1> %<.w d2>"
move.b cSample(a5),d0
move.b cLoop(a5),d1
move.b cLoop+1(a5),d2
move.b cLoop+2(a5),d3
Console.WriteLine " %<.b d0> %<.b d1> %<.b d2> %<.b d3>"
move.l cData(a5),d0
Console.WriteLine " %<pal1>Addr: %<pal0>%<.l d0 sym|split>%<pal2>%<symdisp>"
; ---------------------------------------------------------------------------
subq.w #2,d6 ; sub those 2 lines from stuff
bmi.w .n ; if drawn all, branch
move.w a5,d1 ; copy ch to d1
add.w d5,d1 ; go to end of it
moveq #0,d0
move.b cStack(a5),d0 ; get stack to d0
lea (a5,d0.w),a6 ; and get first element to a6
cmp.w a6,d1 ; check if stack is dry
bls.s .c ; if is, branch
Console.WriteLine " %<pal1>Stack:%<pal0>%<.l (a6) sym|split>%<pal2>%<symdisp>"
tst.l (a6)+ ; AS HACK
subq.w #1,d6 ; sub a line
bmi.s .n ; if drawn all, branch
.loop
cmp.w a6,d1 ; check if we printed full stack
bls.s .c ; if not though, branch
Console.WriteLine " %<pal0>%<.l (a6) sym|split>%<pal2>%<symdisp>"
tst.l (a6)+ ; AS HACK
subq.w #1,d6 ; sub a line
bpl.s .loop ; if we havent drawn all, branch
.c
Console.BreakLine
subq.w #1,d6 ; sub a line
.n
add.w d5,a5 ; go to next ch
rts
; ---------------------------------------------------------------------------
AMPS_DebugR_ChkTracker2:
moveq #40-1,d6
moveq #cSize,d5
lea mDAC1.w,a5
lea AMPS_DebugR_ChDAC1(pc),a0
jsr AMPS_DebugR_ChkTracker_Ch(pc)
lea AMPS_DebugR_ChDAC2(pc),a0
jsr AMPS_DebugR_ChkTracker_Ch(pc)
lea AMPS_DebugR_ChFM1(pc),a0
jsr AMPS_DebugR_ChkTracker_Ch(pc)
lea AMPS_DebugR_ChFM2(pc),a0
jsr AMPS_DebugR_ChkTracker_Ch(pc)
lea AMPS_DebugR_ChFM3(pc),a0
jsr AMPS_DebugR_ChkTracker_Ch(pc)
lea AMPS_DebugR_ChFM4(pc),a0
jsr AMPS_DebugR_ChkTracker_Ch(pc)
lea AMPS_DebugR_ChFM5(pc),a0
jsr AMPS_DebugR_ChkTracker_Ch(pc)
lea AMPS_DebugR_ChPSG1(pc),a0
jsr AMPS_DebugR_ChkTracker_Ch(pc)
lea AMPS_DebugR_ChPSG2(pc),a0
jsr AMPS_DebugR_ChkTracker_Ch(pc)
lea AMPS_DebugR_ChPSG3(pc),a0
jmp AMPS_DebugR_ChkTracker_Ch(pc)
; ---------------------------------------------------------------------------
AMPS_DebugR_ChDAC1:
Console.Write " %<pal0>DAC1"
rts
AMPS_DebugR_ChDAC2:
Console.Write " %<pal0>DAC2"
rts
AMPS_DebugR_ChFM1:
Console.Write " %<pal0> FM1"
rts
AMPS_DebugR_ChFM2:
Console.Write " %<pal0> FM2"
rts
AMPS_DebugR_ChFM3:
Console.Write " %<pal0> FM3"
rts
AMPS_DebugR_ChFM4:
Console.Write " %<pal0> FM4"
rts
AMPS_DebugR_ChFM5:
Console.Write " %<pal0> FM5"
rts
AMPS_DebugR_ChPSG1:
Console.Write " %<pal0>PSG1"
rts
AMPS_DebugR_ChPSG2:
Console.Write " %<pal0>PSG2"
rts
AMPS_DebugR_ChPSG3:
Console.Write " %<pal0>PSG3"
rts
endif
; ---------------------------------------------------------------------------
| 28.894825 | 136 | 0.492605 |
5d538576f9b32ec0855ed6ab2fa87a1b982ba5bd | 259 | asm | Assembly | test/tools/llvm-ml/rip-relative-addressing.asm | DrItanium/llvm12_960 | ca6cd650b78a57a16165ced69b62d4a287e710c4 | [
"Apache-2.0"
] | 250 | 2019-05-07T12:56:44.000Z | 2022-03-10T15:52:06.000Z | test/tools/llvm-ml/rip-relative-addressing.asm | DrItanium/llvm12_960 | ca6cd650b78a57a16165ced69b62d4a287e710c4 | [
"Apache-2.0"
] | 410 | 2019-06-06T20:52:32.000Z | 2022-01-18T14:21:48.000Z | test/tools/llvm-ml/rip-relative-addressing.asm | DrItanium/llvm12_960 | ca6cd650b78a57a16165ced69b62d4a287e710c4 | [
"Apache-2.0"
] | 50 | 2019-05-10T21:12:24.000Z | 2022-01-21T06:39:47.000Z | # RUN: llvm-ml -m32 -filetype=s %s /Fo - | FileCheck %s --check-prefix=CHECK-32
# RUN: llvm-ml -m64 -filetype=s %s /Fo - | FileCheck %s --check-prefix=CHECK-64
.code
mov eax, [4]
; CHECK-32: mov eax, dword ptr [4]
; CHECK-64: mov eax, dword ptr [rip + 4]
END | 32.375 | 79 | 0.637066 |
f24bfd9b60926b9b923bfe6570043118ae28310b | 3,084 | asm | Assembly | Demo3/Stage2/Stage2.asm | mooseman/plan_42 | 0b726f06088c6940aa7050b5cef9f93a3cdcc788 | [
"Unlicense"
] | 7 | 2015-02-18T13:45:06.000Z | 2019-01-24T21:49:18.000Z | SysBoot/Stage2/Pre-Source Control/stage2_4.asm | ClaytonHunt/TonOS | f4f799458958f02f2c505d42d49dd666f08431ff | [
"MIT"
] | null | null | null | SysBoot/Stage2/Pre-Source Control/stage2_4.asm | ClaytonHunt/TonOS | f4f799458958f02f2c505d42d49dd666f08431ff | [
"MIT"
] | 2 | 2017-04-21T09:38:50.000Z | 2020-05-26T22:13:58.000Z |
;*******************************************************
;
; Stage2.asm
; Stage2 Bootloader
;
; OS Development Series
;*******************************************************
bits 16
; Remember the memory map-- 0x500 through 0x7bff is unused above the BIOS data area.
; We are loaded at 0x500 (0x50:0)
org 0x500
jmp main ; go to start
;*******************************************************
; Preprocessor directives
;*******************************************************
%include "stdio.inc" ; basic i/o routines
%include "Gdt.inc" ; Gdt routines
%include "A20.inc" ; A20 enabling
;*******************************************************
; Data Section
;*******************************************************
LoadingMsg db 0x0D, 0x0A, "Searching for Operating System...", 0x00
;*******************************************************
; STAGE 2 ENTRY POINT
;
; -Store BIOS information
; -Load Kernel
; -Install GDT; go into protected mode (pmode)
; -Jump to Stage 3
;*******************************************************
main:
;-------------------------------;
; Setup segments and stack ;
;-------------------------------;
cli ; clear interrupts
xor ax, ax ; null segments
mov ds, ax
mov es, ax
mov ax, 0x9000 ; stack begins at 0x9000-0xffff
mov ss, ax
mov sp, 0xFFFF
sti ; enable interrupts
;-------------------------------;
; Install our GDT ;
;-------------------------------;
call InstallGDT ; install our GDT
;-------------------------------;
; Enable A20 ;
;-------------------------------;
call EnableA20_KKbrd_Out
;-------------------------------;
; Print loading message ;
;-------------------------------;
mov si, LoadingMsg
call Puts16
;-------------------------------;
; Go into pmode ;
;-------------------------------;
EnterStage3:
cli ; clear interrupts
mov eax, cr0 ; set bit 0 in cr0--enter pmode
or eax, 1
mov cr0, eax
jmp CODE_DESC:Stage3 ; far jump to fix CS
; Note: Do NOT re-enable interrupts! Doing so will triple fault!
; We will fix this in Stage 3.
;******************************************************
; ENTRY POINT FOR STAGE 3
;******************************************************
bits 32
Stage3:
;-------------------------------;
; Set registers ;
;-------------------------------;
mov ax, DATA_DESC ; set data segments to data selector (0x10)
mov ds, ax
mov ss, ax
mov es, ax
mov esp, 90000h ; stack begins from 90000h
;---------------------------------------;
; Clear screen and print success ;
;---------------------------------------;
call ClrScr32
mov ebx, msg
call Puts32
;---------------------------------------;
; Stop execution ;
;---------------------------------------;
cli
hlt
msg db 0x0A, 0x0A, 0x0A, " <[ OS Development Series Tutorial 10 ]>"
db 0x0A, 0x0A, " Basic 32 bit graphics demo in Assembly Language", 0
| 24.09375 | 96 | 0.38489 |
e6f989c61b90142701d7ddd8f50a0beb9ad11fec | 277 | asm | Assembly | libsrc/stdio/m5/fgetc_cons.asm | meesokim/z88dk | 5763c7778f19a71d936b3200374059d267066bb2 | [
"ClArtistic"
] | null | null | null | libsrc/stdio/m5/fgetc_cons.asm | meesokim/z88dk | 5763c7778f19a71d936b3200374059d267066bb2 | [
"ClArtistic"
] | null | null | null | libsrc/stdio/m5/fgetc_cons.asm | meesokim/z88dk | 5763c7778f19a71d936b3200374059d267066bb2 | [
"ClArtistic"
] | null | null | null | ;
; SORD M5 Stdio
;
; getkey() Wait for keypress
;
; Stefano Bodrato - Apr. 2000
;
;
; $Id: fgetc_cons.asm,v 1.5 2015/01/19 01:33:20 pauloscustodio Exp $
;
PUBLIC fgetc_cons
EXTERN msxbios
INCLUDE "m5bios.def"
.fgetc_cons
ld ix,ACECHI
call msxbios
ld h,0
ld l,a
ret
| 12.043478 | 68 | 0.68231 |
d5ceed634d4a58dddc927a25e379b80e629abb7e | 275 | asm | Assembly | libsrc/zxvgs/loadany.asm | meesokim/z88dk | 5763c7778f19a71d936b3200374059d267066bb2 | [
"ClArtistic"
] | null | null | null | libsrc/zxvgs/loadany.asm | meesokim/z88dk | 5763c7778f19a71d936b3200374059d267066bb2 | [
"ClArtistic"
] | null | null | null | libsrc/zxvgs/loadany.asm | meesokim/z88dk | 5763c7778f19a71d936b3200374059d267066bb2 | [
"ClArtistic"
] | null | null | null | ;ZXVGS specific functions
;020121 (C) created by Yarek
PUBLIC loadany
;int loadany(char *name, int adr, int len)
;returns 0 if OK
.loadany
POP AF ;return address
POP BC
POP HL
POP DE
PUSH DE
PUSH HL
PUSH BC
PUSH AF
RST 8
DEFB $EC
AND $7F
LD L,A
LD H,0
RET
| 11 | 42 | 0.683636 |
21751f2db7b1fe5be53ad7e4aee0f3b07b71fd4b | 598 | asm | Assembly | programs/oeis/090/A090889.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | null | null | null | programs/oeis/090/A090889.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | null | null | null | programs/oeis/090/A090889.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | null | null | null | ; A090889: Double partial sums of (n * its dyadic valuation).
; 0,0,2,4,14,24,40,56,96,136,186,236,310,384,472,560,712,864,1034,1204,1414,1624,1856,2088,2392,2696,3026,3356,3742,4128,4544,4960,5536,6112,6722,7332,8014,8696,9416,10136,10976,11816,12698,13580
mov $10,$0
mov $12,$0
lpb $12,1
clr $0,10
mov $0,$10
sub $12,1
sub $0,$12
mov $7,$0
mov $9,$0
lpb $9,1
clr $0,7
mov $0,$7
sub $9,1
sub $0,$9
mov $1,$0
gcd $0,281474976710656
sub $0,1
mov $6,$1
lpb $0,1
div $0,2
add $5,$6
lpe
add $8,$5
lpe
add $11,$8
lpe
mov $1,$11
| 19.290323 | 195 | 0.580268 |
3e15a22ca3191df05d41578f50bf27cd01e58ed4 | 10,851 | asm | Assembly | src/any/ppu_timing/statcount.asm | Hacktix/TixTest-GB | 5aba36df2dd8355e88b6a99bd7956041ff5f24ba | [
"MIT"
] | 5 | 2021-04-23T11:23:08.000Z | 2021-12-27T12:36:26.000Z | src/any/ppu_timing/statcount.asm | Hacktix/TixTest-GB | 5aba36df2dd8355e88b6a99bd7956041ff5f24ba | [
"MIT"
] | null | null | null | src/any/ppu_timing/statcount.asm | Hacktix/TixTest-GB | 5aba36df2dd8355e88b6a99bd7956041ff5f24ba | [
"MIT"
] | null | null | null | ; ===== Makefile Headers =====
; MBC 0x00
; RAM 0x00
INCLUDE "hardware.inc"
INCLUDE "font.inc"
INCLUDE "common.inc"
SCROLL_INIT_COOLDOWN EQU 20
SCROLL_ITER_COOLDOWN EQU 3
SECTION "Header", ROM0[0]
ds $40 - @
VBlank:
jp HandleVBlank
ds $100 - @
SECTION "Test", ROM0[$100]
EntryPoint::
jr Main
ds $150 - @
;----------------------------------------------------------------------------
; This Test ROM ROM is intended as an emulator debugging tool to assist with
; PPU timings. It allows for running a variable amount of machine cycles
; (referred to as NOPs) before storing the status of the STAT register.
;----------------------------------------------------------------------------
Main::
;====================================================
; Wait for VBlank & Stop PPU
ld a, [rLY]
cp SCRN_Y
jr c, Main
xor a
ldh [rLCDC], a
;====================================================
; Initialize Palettes
; DMG Palettes
ld a, %11100100
ldh [rBGP], a
; CGB Palettes
ld a, BCPSF_AUTOINC
ldh [rBCPS], a
ld c, LOW(rBCPD)
ld hl, defaultPalette
call LoadPalette
ld hl, errorPalette
call LoadPalette
ld hl, passPalette
call LoadPalette
;====================================================
; Initialize important Variables
ld sp, $DFFF
xor a
ld [wReadSTAT], a
ld [wJoypadScrollCooldown], a
ld [wJoypadCooldown], a
inc a
ld [wCountNOP], a
; Set LYC to FF so that the coincidence bit isn't set
ld a, $FF
ldh [rLYC], a
;====================================================
; Clear VRAM before anything
ld hl, $8000
ld de, $2000
.vramClearLoop
xor a
ld [hli], a
dec de
ld a, d
or e
jr nz, .vramClearLoop
;====================================================
; Load Font Data & Tilemap into VRAM
; Font Tiles
call LoadFont
; "NOPs" String
ld hl, $9821
ld de, strNOPs
call Strcpy
; "NOPs" String
ld hl, $9861
ld de, strRead
call Strcpy
; "Exp." String
ld hl, $98A1
ld de, strExpected
call Strcpy
; "Press Start" String
ld hl, $9A01
ld de, strPressStart
call Strcpy
;====================================================
; Re-enable LCD & Interrupts
xor a
ldh [rIF], a
ld a, IEF_VBLANK
ldh [rIE], a
ei
ld a, LCDCF_ON | LCDCF_BG8800 | LCDCF_BGON
ldh [rLCDC], a
.mainLoop
;====================================================
; Main Loop - Fetch input state and HALT
; Fetch D-Pad bits
ld c, LOW(rP1)
ld a, $20
ldh [c], a
ldh a, [c]
or $F0
ld b, a
swap b
; Fetch Button bits
ld a, $10
ldh [c], a
ldh a, [c]
or $F0
xor b
ld b, a
; Release joypad
ld a, $30
ldh [c], a
; Update HRAM Variables
ldh a, [hHeldKeys]
cpl
and b
ldh [hPressedKeys], a
ld a, b
ldh [hHeldKeys], a
; Wait for VBlank
halt
jr .mainLoop
;----------------------------------------------------------------------------
; Called when the START Button is pressed. Starts a test run and prints
; the results to screen, then returns to the main loop.
;----------------------------------------------------------------------------
RunTest::
;====================================================
; Turn off LCD & Interrupts
xor a
ldh [rLCDC], a
ldh [rIE], a
di
;====================================================
; Prepare C for STAT Read, check if 1 NOP selected
ld c, LOW(rSTAT)
ld a, [wCountNOP]
dec a
jr z, .singleNopTest
;====================================================
; Calculate jump address
ld hl, ClockslideBase
ld a, [wCountNOP]
ld b, a
ld a, $FF
sub b
add l
ld l, a
adc h
sub l
ld h, a
;====================================================
; Enable LCD and start test
ld a, LCDCF_ON
ldh [rLCDC], a
jp hl
.singleNopTest
;====================================================
; Enable LCD and immediately read from STAT
ld a, LCDCF_ON
ldh [rLCDC], a
ld a, [$ff00+c]
;====================================================
; Store variables in memory and end test run
ld [wReadSTAT], a
jp ClockslideBase.postTestCleanup
;----------------------------------------------------------------------------
; 253 NOPs followed by code to store STAT in RAM
; - 1 Cycle timeout by JP HL
; - n Cycles timeout by NOPs
; - 1 Cycle timeout by LD A, [$FF00+C]
; => 253 NOP instructions for 255 NOPs
;----------------------------------------------------------------------------
ClockslideBase::
REPT $FD
nop
ENDR
;====================================================
; Store variables in memory and end test run
ld a, [$ff00+c]
ld [wReadSTAT], a
.postTestCleanup
;====================================================
; Wait for VBlank & Stop PPU
ld a, [rLY]
cp SCRN_Y
jr c, .postTestCleanup
xor a
ldh [rLCDC], a
;====================================================
; Print read STAT value to screen
ld a, [wReadSTAT]
call ConvertToASCII
ld hl, $9867
ld a, d
ld [hli], a
ld a, e
ld [hl], a
;====================================================
; Fetch & Print expected value
; Fetch Expected Value from Result Table
ld a, [wCountNOP]
ld hl, Expected
add l
ld l, a
adc h
sub l
ld h, a
ld a, [hl]
push af ; Preserve expected value for comparison
; Print value
call ConvertToASCII
ld hl, $98A7
ld a, d
ld [hli], a
ld a, e
ld [hl], a
;====================================================
; Compare values and print PASS/FAIL
; Pre-emptively load PASS String & initialize VRAM Bank 1 with pass palette
ld a, 1
ldh [rVBK], a
inc a
ld hl, $98E7
ld [hli], a
ld [hli], a
ld [hli], a
ld [hli], a
ld [hli], a
ld de, strPass
; Fetch expected value from stack & compare to RAM value
pop bc
ld a, [wReadSTAT]
cp b
jr z, .noFail
; If values don't match, load FAIL string & fail palette
ld de, strFail
ld a, 1
ld hl, $98E7
ld [hli], a
ld [hli], a
ld [hli], a
ld [hli], a
ld [hli], a
.noFail
; Reset to VRAM Bank 0
xor a
ldh [rVBK], a
; Print to screen
ld hl, $98E7
call Strcpy
;====================================================
; Turn on LCD & interrupts and return to main loop
xor a
ldh [rIF], a
ld a, IEF_VBLANK
ldh [rIE], a
ei
ld a, LCDCF_ON | LCDCF_BG8800 | LCDCF_BGON
ldh [rLCDC], a
jp Main.mainLoop
;----------------------------------------------------------------------------
; Called whenever a VBlank interrupt occurs. Handles all variable-updating
; and is in charge of starting tests if the START button is pressed.
;----------------------------------------------------------------------------
HandleVBlank::
;====================================================
; Check if test should be started
ldh a, [hPressedKeys]
and $08
jp nz, RunTest
;====================================================
; Handle fresh D-Pad up/down inputs
; Check if D-Pad Up was just pressed
ldh a, [hPressedKeys]
and $40
jr z, .noUpPressed
; Increment wCountNOP by 1, set to 1 if result is 0
ld hl, wCountNOP
inc [hl]
jr nz, .noZeroIncNOP
inc [hl]
.noZeroIncNOP
; Update Scroll Cooldown & Continue
ld a, SCROLL_INIT_COOLDOWN
ld [wJoypadScrollCooldown], a
xor a
ld [wJoypadCooldown], a
jr .noDownHeld
.noUpPressed
; Check if D-Pad Down was just pressed
ldh a, [hPressedKeys]
and $80
jr z, .noDownPressed
; Decrement wCountNOP by 1, set to $FF if result is 0
ld hl, wCountNOP
dec [hl]
jr nz, .noZeroDecNOP
dec [hl]
.noZeroDecNOP
; Update Scroll Cooldown & Continue
ld a, SCROLL_INIT_COOLDOWN
ld [wJoypadScrollCooldown], a
xor a
ld [wJoypadCooldown], a
jr .noDownHeld
.noDownPressed
;====================================================
; Handle held D-Pad up/down inputs
; Check if D-Pad Up is held
ldh a, [hHeldKeys]
and $40
jr z, .noUpHeld
; Check if scroll cooldown is over
ld hl, wJoypadScrollCooldown
dec [hl]
jr nz, .noDownHeld
; Increment scroll cooldown & check value change cooldown
inc [hl]
ld a, [wJoypadCooldown]
inc a
ld [wJoypadCooldown], a
cp SCROLL_ITER_COOLDOWN
jr nz, .noDownHeld
; Reset value change cooldown & handle NOP count increment logic
xor a
ld [wJoypadCooldown], a
ld hl, wCountNOP
inc [hl]
jr nz, .noUpHeld
inc [hl]
.noUpHeld
; Check if D-Pad Down is held
ldh a, [hHeldKeys]
and $80
jr z, .noDownHeld
; Check if scroll cooldown is over
ld hl, wJoypadScrollCooldown
dec [hl]
jr nz, .noDownHeld
; Increment scroll cooldown & check value change cooldown
inc [hl]
ld a, [wJoypadCooldown]
inc a
ld [wJoypadCooldown], a
cp SCROLL_ITER_COOLDOWN
jr nz, .noDownHeld
; Reset value change cooldown & handle NOP count decrement logic
xor a
ld [wJoypadCooldown], a
ld hl, wCountNOP
dec [hl]
jr nz, .noDownHeld
dec [hl]
.noDownHeld
;====================================================
; Print new NOP Count to screen
ld a, [wCountNOP]
call ConvertToASCII
ld hl, $9827
ld a, d
ld [hli], a
ld a, e
ld [hl], a
reti
SECTION "Expected Results", ROM0
Expected::
; Scanline 0
db $FF ; NOP 0 cannot be read => unknown
REPT 18 ; 18 M-cycles of mode 0 (First-scanline-after-LCD-on-quirk)
db $80
ENDR
REPT 43 ; 43 M-cycles of drawing
db $83
ENDR
REPT 51 ; 51 M-cycles of HBlank
db $80
ENDR
; Scanline 1
REPT 20 ; 20 M-cycles of OAM-scan
db $82
ENDR
REPT 43 ; 43 M-cycles of drawing
db $83
ENDR
REPT 51 ; 51 M-cycles of HBlank
db $80
ENDR
; Scanline 2
REPT 20 ; 20 M-cycles of OAM-scan
db $82
ENDR
REPT 9 ; 43 M-cycles of drawing, but cannot test further than 9 M-cycles into scanline 2
db $83
ENDR
SECTION "Strings", ROM0
strNOPs: db "NOPs: 01h", 0
strRead: db "Read: --h", 0
strExpected: db "Exp.: --h", 0
strPressStart: db "Press START to run", 0
strPass: db "PASS!", 0
strFail: db "FAIL!", 0
SECTION "CGB Palettes", ROM0
defaultPalette: dw $FFFF, $0000, $0000, $0000
errorPalette: dw $FFFF, $001F, $001F, $001F
passPalette: dw $FFFF, $03E0, $03E0, $03E0
SECTION "WRAM", WRAM0
wCountNOP: db
wReadSTAT: db
wJoypadScrollCooldown: db
wJoypadCooldown: db
SECTION "HRAM", HRAM
hHeldKeys:: db
hPressedKeys:: db | 21.529762 | 94 | 0.50023 |
f7f7e7c555819e93664a6d07738a8ec88845388b | 328 | asm | Assembly | project-two/test/sim1.asm | aryan-gupta/ECGR3183 | fcfc8700f2309d3932a64568be645e20a475d7a2 | [
"RSA-MD"
] | null | null | null | project-two/test/sim1.asm | aryan-gupta/ECGR3183 | fcfc8700f2309d3932a64568be645e20a475d7a2 | [
"RSA-MD"
] | null | null | null | project-two/test/sim1.asm | aryan-gupta/ECGR3183 | fcfc8700f2309d3932a64568be645e20a475d7a2 | [
"RSA-MD"
] | null | null | null | Set R1, #30.0 --angle of inclined plane
--convert to radians
Set R2, #3.14159265 --pi
Fmul R1, R1, R2
Set R2, #180.0
Fdiv R1, R1, R2
--compute equation
Cos R2, R1
Set R3, #0.4
FMul R2, R2, R3
Sin R1, R1
Fadd R1, R1, R2
Set R2, #100.0 --mass of crate
Fmul R1, R1, R2
Set R2, #9.81 --acceleration of gravity
Fmul R1, R1, R2
Get R1 | 19.294118 | 39 | 0.667683 |
7537e051e6c8587159d08ff1542c1ede205ff376 | 52,715 | asm | Assembly | Library/Spreadsheet/Spreadsheet/spreadsheetScroll.asm | steakknife/pcgeos | 95edd7fad36df400aba9bab1d56e154fc126044a | [
"Apache-2.0"
] | 504 | 2018-11-18T03:35:53.000Z | 2022-03-29T01:02:51.000Z | Library/Spreadsheet/Spreadsheet/spreadsheetScroll.asm | steakknife/pcgeos | 95edd7fad36df400aba9bab1d56e154fc126044a | [
"Apache-2.0"
] | 96 | 2018-11-19T21:06:50.000Z | 2022-03-06T10:26:48.000Z | Library/Spreadsheet/Spreadsheet/spreadsheetScroll.asm | steakknife/pcgeos | 95edd7fad36df400aba9bab1d56e154fc126044a | [
"Apache-2.0"
] | 73 | 2018-11-19T20:46:53.000Z | 2022-03-29T00:59:26.000Z | COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Copyright (c) GeoWorks 1991 -- All Rights Reserved
PROJECT: PC GEOS
MODULE: GeoCalc
FILE: spreadsheetScroll.asm
AUTHOR: Gene Anderson, May 15, 1991
ROUTINES:
Name Description
---- -----------
MSG_META_CONTENT_TRACK_SCROLLING Make scrolls on cell boundaries
MSG_SPREADSHEET_SCALE Scale the spreadsheet view
EXT RecalcViewDocSize Recalculate document size for view
INT ReturnXScroll16 Finish word-sized x scroll
INT ReturnXScroll32 Finish dword-sized x scroll
INT ReturnYScroll16 Finish word-sized y scroll
INT ReturnYScroll32 Finish dword-sized y scroll
INT NScrollNoChange Do nothing scroll handler
INT NScrollNoScroll Do not scroll handler
INT NScrollLeftPage Normalized scroll left one page
INT NScrollRightPage Normalized scroll right one page
INT NScrollUpPage Normalized scroll up one page
INT NScrollDownPage Normalized scroll down one page
INT NScrollLeftColumn Normalized scroll left one column
INT NScrollRightColumn Normalized scroll right one column
INT NScrollUpRow Normalized scroll up one row
INT NScrollDownRow Normalized scroll down one row
INT NScrollGeneral Handle general normalized scroll
REVISION HISTORY:
Name Date Description
---- ---- -----------
Gene 5/15/91 Initial revision
DESCRIPTION:
$Id: spreadsheetScroll.asm,v 1.1 97/04/07 11:14:00 newdeal Exp $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
DrawCode segment resource
scrollRoutines nptr \
NScrollNoChange, ;SA_NOTHING (x)
NScrollNoChange, ;SA_NOTHING (y)
NScrollNoChange, ;SA_TO_BEGINNING (x)
NScrollNoChange, ;SA_TO_BEGINNING (y)
NScrollLeftPage, ;SA_PAGE_BACK (x)
NScrollUpPage, ;SA_PAGE_BACK (y)
NScrollLeftColumn, ;SA_INC_BACK (x)
NScrollUpRow, ;SA_INC_BACK (y)
NScrollRightColumn, ;SA_INC_FWD (x)
NScrollDownRow, ;SA_INC_FWD (y)
NScrollGeneral, ;SA_DRAGGING (x)
NScrollGeneral, ;SA_DRAGGING (y)
NScrollRightPage, ;SA_PAGE_FWD (x)
NScrollDownPage, ;SA_PAGE_FWD (y)
NScrollGeneral, ;SA_TO_END (x)
NScrollGeneral, ;SA_TO_END (y)
NScrollGeneral, ;SA_SCROLL (x)
NScrollGeneral, ;SA_SCROLL (y)
NScrollInto, ;SA_SCROLL_INTO (x)
NScrollInto, ;SA_SCROLL_INTO (y)
NScrollNoChange, ;SA_INITIAL_POS (x)
NScrollNoChange, ;SA_INITIAL_POS (y)
NScrollKeepVisCell, ;SA_SCALE (x)
NScrollKeepVisCell, ;SA_SCALE (y)
NScrollGeneral, ;SA_PAN (x)
NScrollGeneral, ;SA_PAN (y)
NScrollSelect, ;SA_DRAG_SCROLL (x)
NScrollSelect, ;SA_DRAG_SCROLL (y)
NScrollKeepVisCell, ;SA_SCROLL_FOR_SIZE_CHANGE (x)
NScrollKeepVisCell ;SA_SCROLL_FOR_SIZE_CHANGE (y)
CheckHack <ScrollAction eq (length scrollRoutines)/2>
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SpreadsheetNormalizePosition
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Handle normalized scrolling, to keep a cell in the upper left
CALLED BY: MSG_META_CONTENT_TRACK_SCROLLING
PASS: *ds:si - instance data
ds:di - *ds:si
es - seg addr of SpreadsheetClass
ax - the method
cx:dx - TrackScrollingParams
RETURN: ss:bp.TSP_change - (x,y) change in position
DESTROYED: bx, si, di, ds, es (method handler)
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 5/15/91 Initial version
cbh 6/15/94 Changed to always move the selection on a
page up/down.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
SpreadsheetNormalizePosition method dynamic SpreadsheetClass,
MSG_META_CONTENT_TRACK_SCROLLING
push si
mov si, di ;ds:si <- ptr to instance data
;
; Common setup for a scroll
;
call GenSetupTrackingArgs
push cx ;must save cx
;
; Call the appropriate scrolling routine based on
; the ScrollAction and whether it is horizontal
; or vertical.
;
clr bh
mov bl, ss:[bp].TSP_action ;bx <- ScrollAction
shl bx, 1 ;*2 for each (x,y) pair
shl bx, 1 ;*2 for each (size nptr) = 2
test ss:[bp].TSP_flags, mask SF_VERTICAL
jz horizontal
add bx, (size nptr)
horizontal:
call cs:scrollRoutines[bx] ;call appropriate routine
EC < call ECCheckTrackingArgs ;>
;
; Return adjusted scroll amount
;
pop cx
call GenReturnTrackingArgs ;sends NORMALIZE_COMPLETE
pop si
;
; Try to keep the current selection onscreen. 8/10/93 cbh
; (Not if we have the target. 8/31/93 cbh) (And only on page up/down.
; -cbh 1/25/94). (And now only on a keyboard-induced scroll. 6/15/94)
;
mov di, ds:[si]
add di, ds:[di].Spreadsheet_offset
test ds:[di].SSI_flags, mask SF_IS_APP_TARGET
jz exit
test ss:[bp].TSP_flags, mask SF_KBD_RELATED_SCROLL
jz exit
mov al, ss:[bp].TSP_action
cmp al, SA_PAGE_FWD
je adjustSelection
cmp al, SA_PAGE_BACK
jne exit
adjustSelection:
mov bl, ss:[bp].TSP_flags
sub sp, size SpreadsheetRangeParams
mov bp, sp
mov ax, SPREADSHEET_ADDRESS_USE_SELECTION
mov ss:[bp].SRP_selection.CR_start.CR_row,ax
mov ss:[bp].SRP_selection.CR_start.CR_column,ax
mov ss:[bp].SRP_selection.CR_end.CR_row, ax
mov ss:[bp].SRP_selection.CR_end.CR_column, ax
mov ax, ds:[di].SSI_active.CR_row
mov dx, ds:[di].SSI_active.CR_column
test bl, mask SF_VERTICAL
mov bx, SPREADSHEET_ADDRESS_ON_SCREEN
jz 10$
mov ax, bx ;vertical, keep row onscreen
jmp short 20$
10$:
mov dx, bx ;horiz, keep col onscreen
20$:
mov ss:[bp].SRP_active.CR_row, ax
mov ss:[bp].SRP_active.CR_column, dx
mov dx, size SpreadsheetRangeParams
mov bx, ds:[LMBH_handle]
mov ax, MSG_SPREADSHEET_SET_SELECTION
mov di, mask MF_CALL or mask MF_STACK
call ObjMessage
add sp, size SpreadsheetRangeParams
exit:
ret
SpreadsheetNormalizePosition endm
if ERROR_CHECK
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ECCheckTrackingArgs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Verify the tracking args are valid before we return them
CALLED BY: SpreadsheetNormalizePosition()
PASS: ss:bp - TrackScrollingParams
ds:si - ptr to Spreadsheet instance
RETURN: none
DESTROYED: none (flags preserved)
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
gene 2/ 5/93 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
ECCheckTrackingArgs proc near
uses ax, bx, cx, dx, bp
class SpreadsheetClass
.enter
pushf
mov bx, bp ;ss:bx <- TrackScrollingParams
;
; Check x offset
;
clr cx ;cx <- column origin
pushdw ds:[si].SSI_offset.PD_x
mov bp, sp
incdw ss:[bp] ;account for initial -1 offset
call Pos32ToColRel ;ax <- column #
cmp cx, 0 ;not at edge?
je xOffsetOK
cmp dx, 0 ;not at edge?
je xOffsetOK
WARNING SPREADSHEET_SCROLL_RETURNING_BAD_OFFSET
xOffsetOK:
movdw dxax, ss:[bx].TSP_oldOrigin.PD_x
adddw dxax, ss:[bx].TSP_change.PD_x
cmpdw dxax, ss:[bp].PD_x ;at an integral position?
WARNING_NE SPREADSHEET_SCROLL_RETURNING_BAD_OFFSET
add sp, (size SSI_offset.PD_x)
;
; Check y offset
;
clr cx ;cx <- row origin
pushdw ds:[si].SSI_offset.PD_y
mov bp, sp
incdw ss:[bp] ;account for initial -1 offset
call Pos32ToRowRel ;ax <- row #
cmp cx, 0 ;not at edge?
je yOffsetOK
cmp dx, 0 ;not at edge?
je yOffsetOK
WARNING SPREADSHEET_SCROLL_RETURNING_BAD_OFFSET
yOffsetOK:
movdw dxax, ss:[bx].TSP_oldOrigin.PD_y
adddw dxax, ss:[bx].TSP_change.PD_y
cmpdw dxax, ss:[bp].PD_x ;at an integral position?
WARNING_NE SPREADSHEET_SCROLL_RETURNING_BAD_OFFSET
add sp, (size SSI_offset.PD_y)
popf
.leave
ret
ECCheckTrackingArgs endp
endif
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ReturnYDelta32
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Calculate and return the delta required to get to a row
CALLED BY: NScrollKeepVisCell()
PASS: ss:bp - ptr to TrackScrollingParams
ds:si - ptr to Spreadsheet instance
ax - row to return delta for
RETURN: none
DESTROYED: ax, dx
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
gene 2/ 7/93 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
ReturnYDelta32 proc near
EC < call ECCheckInstancePtr ;>
clr dx ;dx <- start row
call RowGetRelPos32 ;ax:dx <- position of row
subdw axdx, ss:[bp].TSP_oldOrigin.PD_y
GOTO ReturnYScroll32
ReturnYDelta32 endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ReturnXDelta32
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Calculate and return the delta required to get to a column
CALLED BY: NScrollKeepVisCell()
PASS: ss:bp - ptr to TrackScrollingParams
ds:si - ptr to Spreadsheet instance
cx - column to return delta for
RETURN: none
DESTROYED: ax, dx
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
gene 2/ 7/93 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
ReturnXDelta32 proc near
EC < call ECCheckInstancePtr ;>
clr dx ;dx <- start column
call ColumnGetRelPos32 ;ax:dx <- position of column
subdw axdx, ss:[bp].TSP_oldOrigin.PD_x
GOTO ReturnXScroll32
ReturnXDelta32 endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ReturnXScroll16, ReturnXScroll32
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Return x scroll value
CALLED BY: INTERNAL: ScrollLeftColumn(), ScrollRightColumn()
PASS: ss:bp - ptr to TrackScrollingParams
ds:si - ptr to Spreadsheet instance
ax:dx - x scroll amount (ReturnXScroll32)
dx - x scroll amount (ReturnXScroll16)
RETURN: none
DESTROYED: ax
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 5/21/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
ReturnXScroll16 proc near
mov ax, dx
cwd ;sign extend to dword
xchg ax, dx ;ax:dx <- dword value
FALL_THRU ReturnXScroll32
ReturnXScroll16 endp
ReturnXScroll32 proc near
class SpreadsheetClass
uses bx, cx, dx
.enter
EC < call ECCheckInstancePtr ;>
;
; Added 4/10/95, -cassie
; Since the current offset is used to calculate the scroll amount, we
; want to make sure the offset is valid. It may not be if the spreadsheet
; size has changed, as when there are large point size changes. See bug
; 33261 for more info. (Though I never saw the problem in the X dimension,
; this code is added as a safeguard, and to keep this routine like its
; Y counterpart.) Set X offset to MIN(X offset, right bound - 1).
;
movdw cxbx, ds:[si].SSI_bounds.RD_right
decdw cxbx ; account for strangeness
jgedw cxbx, ds:[si].SSI_offset.PD_x, $10
movdw ds:[si].SSI_offset.PD_x, cxbx
$10:
;vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
; Added 3/28/93, -jw
; This code is designed to ensure that we never mistakenly return an offset
; that is less than zero. This just ain't allowed.
;
;
; Now we grovel... We simply can not return an offset that is
; less than zero. To make sure this doesn't happen we force
; oldOrigin+change >= -1.
;
adddw axdx, ds:[si].SSI_offset.PD_x
jgedw axdx, -1, changeInBounds
;
; axdx needs to hold the final value we want if we scroll too far back.
;
movdw axdx, -1
changeInBounds:
;
; So now ax.dx = The new origin. We refigure the change by subtracting
; off the old origin.
;
subdw axdx, ds:[si].SSI_offset.PD_x
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
;vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
; Added 3/30/93 -jw
; This code handles the fact that the origin of the view will not always
; be what we tell it to be. This messes up our idea of a cached position.
;
; To handle this we make a few assumptions:
; SSI_offset is where the view *should* have been
; TSP_oldOrigin is where the view is
;
; The idea here is that we want the origin to end up at a row/column boundary.
; SSI_offset will always hold a value that falls on a column boundary. Since
; all of the scrolling code uses this as the basis for computing the scroll
; amount, adding the suggested change (axdx) to SSI_offset will always get
; us to a cell boundary.
;
; The problem here is that we need to return a scroll amount to the view
; to allow it to scroll to the proper location.
;
; Here's how we make that work:
; (SSI_offset + 1) - TSP_oldOrigin
; This is how far off the last scroll was from where we
; told it to go.
;
; Poof, we take this amount and add it to the distance that we would suggest
; the view scrolled if TSP_oldOrigin had been where we told it to go last time.
;
; In essence we are saying "I know you screwed up last time, so here's a little
; extra to put you in the right place this time".
;
;
; Get the old "correct" origin for later computation.
;
movdw cxbx, ds:[si].SSI_offset.PD_x ; cx.bx <- old value
;
; The value passed to us should always put us on a column boundary.
;
adddw ds:[si].SSI_offset.PD_x, axdx ; Set new value
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Added 4/19/95, -cassie
; This code is designed to ensure that we never mistakenly return an offset
; that is outside the spreadsheet bottom. This can happen when scaling
; (see bug 35189), by adding the change amount to the old (unscaled) origin.
;
cmp ss:[bp].TSP_action, SA_SCALE
jne haveOffset
;
; Calculate the offset of the last row.
;
pushdw cxbx ;save old offset
pushdw axdx ;save the change amount
mov cx, ds:[si].SSI_maxCol
clr dx ;dx <- start column
call ColumnGetRelPos32 ;ax.dx <- offset of last row
decdw axdx ;account for strangeness
movdw cxbx, axdx ;cx.bx <- offset of last row
popdw axdx ;ax.dx <- change
;
; If the new offset falls before the last column, we can use it.
; Else use the last column as the new offset. Calculate what the
; old offset would have been if adding the change amount to
; it landed on the last column.
;
jledw ds:[si].SSI_offset.PD_x, cxbx, noScale
movdw ds:[si].SSI_offset.PD_x, cxbx ;save it as new offset
subdw cxbx, axdx ;calculate old origin
add sp, size dword ;remove cx, bx from stack
jmp haveOffset
noScale:
popdw cxbx ;restore old offset
haveOffset:
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
; Figure the amount that the view origin should change in order to get
; it to where our offset is:
; change + ((SSI_offset + 1) - TSP_oldOrigin)
;
; axdx = change amount
;
adddw axdx, cxbx ; Add in the old SSI_offset
incdw axdx ; Account for the strangeness
subdw axdx, ss:[bp].TSP_oldOrigin.PD_x
;
; Save this as the final change amount
;
movdw ss:[bp].TSP_change.PD_x, axdx
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
EC < jgedw ds:[si].SSI_offset.PD_x, -1, offsetOK >
EC < ERROR SPREADSHEET_SCROLL_OFFSET_OFF_DOCUMENT >
EC <offsetOK: >
andnf ds:[si].SSI_gsRefCount, not (mask SSRCAF_TRANSFORM_VALID)
.leave
ret
ReturnXScroll32 endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ReturnYScroll16, ReturnYScroll32
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Return y scroll value
CALLED BY: INTERNAL: ScrollUpRow(), ScrollDownRow()
PASS: ss:bp - ptr to TrackScrollingParams
ds:si - ptr to Spreadsheet instance
ax:dx - y scroll amount (ReturnYScroll32)
dx - y scroll amount (ReturnYScroll16)
RETURN: none
DESTROYED: ax
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 5/21/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
ReturnYScroll16 proc near
mov ax, dx
cwd ;sign extend to dword
xchg ax, dx ;ax:dx <- dword
FALL_THRU ReturnYScroll32
ReturnYScroll16 endp
ReturnYScroll32 proc near
class SpreadsheetClass
uses bx, cx, dx
.enter
EC < call ECCheckInstancePtr ;>
;
; Added 4/10/95, -cassie
; Since the current offset is used to calculate the scroll amount, we
; want to make sure the offset is valid. It may not be if the spreadsheet
; size has changed, as when there are large point size changes. See bug
; 33261 for more info. Set Y offset to MIN(Y offset, bottom bound - 1).
;
movdw cxbx, ds:[si].SSI_bounds.RD_bottom
decdw cxbx ; account for strangeness
jgedw cxbx, ds:[si].SSI_offset.PD_y, $10
movdw ds:[si].SSI_offset.PD_y, cxbx
$10:
;vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
; Added 3/28/93, -jw
; This code is designed to ensure that we never mistakenly return an offset
; that is less than zero. This just ain't allowed.
;
;
; Now we grovel... We simply can not return an offset that is
; less than zero. To make sure this doesn't happen we force
; oldOrigin+change >= -1.
;
adddw axdx, ds:[si].SSI_offset.PD_y
jgedw axdx, -1, changeInBounds
;
; axdx needs to hold the final value we want if we scroll too far back.
;
movdw axdx, -1
changeInBounds:
;
; So now ax.dx = The new origin. We refigure the change by subtracting
; off the old origin.
;
subdw axdx, ds:[si].SSI_offset.PD_y
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
;vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
; Added 3/30/93 -jw
; This code handles the fact that the origin of the view will not always
; be what we tell it to be. This messes up our idea of a cached position.
;
; To handle this we make a few assumptions:
; SSI_offset is where the view *should* have been
; TSP_oldOrigin is where the view is
;
; The idea here is that we want the origin to end up at a row/column boundary.
; SSI_offset will always hold a value that falls on a column boundary. Since
; all of the scrolling code uses this as the basis for computing the scroll
; amount, adding the suggested change (axdx) to SSI_offset will always get
; us to a cell boundary.
;
; The problem here is that we need to return a scroll amount to the view
; to allow it to scroll to the proper location.
;
; Here's how we make that work:
; (SSI_offset + 1) - TSP_oldOrigin
; This is how far off the last scroll was from where we
; told it to go.
;
; Poof, we take this amount and add it to the distance that we would suggest
; the view scrolled if TSP_oldOrigin had been where we told it to go last time.
;
; In essence we are saying "I know you screwed up last time, so here's a little
; extra to put you in the right place this time".
;
;
; Get the old "correct" origin for later computation.
;
movdw cxbx, ds:[si].SSI_offset.PD_y ; cx.bx <- old value
;
; The value passed to us should always put us on a row boundary.
;
adddw ds:[si].SSI_offset.PD_y, axdx ; Set new value
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Added 4/19/95, -cassie
; This code is designed to ensure that we never mistakenly return an offset
; that is outside the spreadsheet bottom. This can happen when scaling
; (see bug 35189), by adding the change amount to the old (unscaled) origin.
;
cmp ss:[bp].TSP_action, SA_SCALE
jne haveOffset
;
; Calculate the offset of the last row.
;
pushdw cxbx ;save old offset
pushdw axdx ;save the change amount
mov ax, ds:[si].SSI_maxRow
clr dx ;dx <- start row
call RowGetRelPos32 ;ax.dx <- offset of last row
decdw axdx ;account for strangeness
movdw cxbx, axdx ;cx.bx <- offset of last row
popdw axdx ;ax.dx <- change
;
; If the new offset falls before the last row, we can use it.
; Else use the last row as the new offset. Calculate what the
; old offset would have been if adding the change amount to
; it landed on the last row.
;
jledw ds:[si].SSI_offset.PD_y, cxbx, noScale
movdw ds:[si].SSI_offset.PD_y, cxbx ;save it as new offset
subdw cxbx, axdx ;calculate old origin
add sp, size dword ;remove cx, bx from stack
jmp haveOffset
noScale:
popdw cxbx ;restore old offset
haveOffset:
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
; Figure the amount that the view origin should change in order to get
; it to where our offset is:
; change + ((SSI_offset + 1) - TSP_oldOrigin)
;
; axdx = change amount
; cxbx = old SSI_offset
;
adddw axdx, cxbx ; Add in the old SSI_offset
incdw axdx ; Account for the strangeness
subdw axdx, ss:[bp].TSP_oldOrigin.PD_y
;
; Save this as the final change amount
;
movdw ss:[bp].TSP_change.PD_y, axdx
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
EC < jgedw ds:[si].SSI_offset.PD_y, -1, offsetOK >
EC < ERROR SPREADSHEET_SCROLL_OFFSET_OFF_DOCUMENT >
EC <offsetOK: >
andnf ds:[si].SSI_gsRefCount, not (mask SSRCAF_TRANSFORM_VALID)
.leave
ret
ReturnYScroll32 endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NScrollNoChange
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Do-nothing routine for no change in passed scrolling offsets
CALLED BY: SpreadsheetNormalizePosition()
PASS: none
RETURN: none
DESTROYED: none
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 5/19/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
NScrollNoChange proc near
ret
NScrollNoChange endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NScrollUpPage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Adjust offset for scrolling up a page.
CALLED BY: SpreadsheetNormalizePosition()
PASS: ss:bp - ptr to TrackScrollingParams
ds:si - ptr to Spreadsheet instance
RETURN: none
DESTROYED: ax, bx, cx, dx, di
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
This (and NScrollLeftPage) would be much more efficient
if there were a PositionToCell() routine that dealt with
negative offsets.
Another (perhaps easier) optimization would be adding a routine
to round (actually truncate) to the nearest cell row boundary.
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 5/19/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
NScrollUpPage proc near
class SpreadsheetClass
locals local CellLocals
.enter
EC < call ECCheckInstancePtr ;>
call CreateGState ;di <- handle of GState
call GetWinBounds32 ;(cx,dx) <- window size
call DestroyGState
;
; Figure out where the top of the window, minus the height of
; the window is. In other words, we want to move up the height
; of the window.
;
dec dx ;so we don't go too far
sub ss:locals.CL_docBounds.RD_top.low, dx
sbb ss:locals.CL_docBounds.RD_top.high, 0
;
; This is just wrong. We want to compute the distance
; relative to <zero> and then we want to limit ourselves
; to scrolling only as far as the minimum row.
;
;;; push bp
;;; lea bp, ss:locals.CL_docBounds.RD_top
;;; call SSGetMinRow
;;; mov cx, dx ; minimum row
;;; call Pos32ToRowRel ;ax <- nearest row
;;; pop bp
push bp
lea bp, ss:locals.CL_docBounds.RD_top
clr cx ;relative to top
call Pos32ToRowRel ;ax <- nearest row
pop bp
;
; Now check that we haven't gone too far.
;
call SSGetMinRow ;dx <- min row
cmp ax, dx
jae rowOK
mov ax, dx ;use min row
rowOK:
mov ds:[si].SSI_visible.CR_start.CR_row, ax
.leave
GOTO ReturnYDelta32
NScrollUpPage endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NScrollDownPage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Adjust offset for scrolling down a page.
CALLED BY: SpreadsheetNormalizePosition()
PASS: ss:bp - ptr to TrackScrollingParams
ds:si - ptr to Spreadsheet instance
RETURN: none
DESTROYED: ax, bx, cx, dx, di
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 5/19/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
NScrollDownPage proc near
class SpreadsheetClass
EC < call ECCheckInstancePtr ;>
mov ax, ds:[si].SSI_visible.CR_end.CR_row
mov dx, ds:[si].SSI_visible.CR_start.CR_row
cmp ax, dx ;single row?
ja scrollOK ;branch if more than one row
cmp ax, ds:[si].SSI_maxRow ;already at max, don't bump!
jae scrollOK ; (cbh 3/15/94)
inc ax ;ax <- row below
scrollOK:
call RowGetRelPos16 ;dx <- position of bottom row
mov ds:[si].SSI_visible.CR_start.CR_row, ax
GOTO ReturnYScroll16
NScrollDownPage endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NScrollLeftPage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Adjust offset for scrolling left a page
CALLED BY: SpreadsheetNormalizePosition()
PASS: ss:bp - ptr to TrackScrollingParams
ds:si - ptr to Spreadsheet instance
RETURN: none
DESTROYED: ax, bx, cx, dx, di
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 5/19/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
NScrollLeftPage proc near
class SpreadsheetClass
locals local CellLocals
.enter
EC < call ECCheckInstancePtr ;>
call CreateGState ;di <- handle of GState
call GetWinBounds32 ;(cx,dx) <- size
call DestroyGState
;
; Figure out where the left of the window, minus the width of
; the window is. In other words, we want to move left the
; width of the window.
;
dec cx ;so we don't go too far
sub ss:locals.CL_docBounds.RD_left.low, cx
sbb ss:locals.CL_docBounds.RD_left.high, 0
;
; This is just wrong. We want to compute the distance
; relative to <zero> and then we want to limit ourselves
; to scrolling only as far as the minimum column.
;
;;; push bp
;;; lea bp, ss:locals.CL_docBounds.RD_left
;;; call SSGetMinColumn
;;; mov cx, dx ; minimum column
;;; call Pos32ToColRel ;ax <- nearest column
;;; pop bp
push bp
lea bp, ss:locals.CL_docBounds.RD_left
clr cx ;relative to left
call Pos32ToColRel ;ax <- nearest column
pop bp
;
; Now check that we haven't gone too far.
;
call SSGetMinColumn ;dx <- min column
cmp ax, dx
jae colOK
mov ax, dx ;use min column
colOK:
mov ds:[si].SSI_visible.CR_start.CR_column, ax
mov cx, ax ;cx <- column
.leave
GOTO ReturnXDelta32
NScrollLeftPage endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NScrollRightPage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Adjust offset for scrolling right a page
CALLED BY: SpreadsheetNormalizePosition()
PASS: ss:bp - ptr to TrackScrollingParams
ds:si - ptr to Spreadsheet instance
RETURN: none
DESTROYED: ax, bx, cx, dx, di
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 5/19/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
NScrollRightPage proc near
class SpreadsheetClass
EC < call ECCheckInstancePtr ;>
mov cx, ds:[si].SSI_visible.CR_end.CR_column
mov dx, ds:[si].SSI_visible.CR_start.CR_column
cmp cx, dx ;single column?
ja scrollOK ;branch if more than one column
cmp cx, ds:[si].SSI_maxCol ;already at max, don't bump!
jae scrollOK ; (3/15/94 cbh)
inc cx ;cx <- column to right
scrollOK:
call ColumnGetRelPos16
mov ds:[si].SSI_visible.CR_start.CR_column, cx
GOTO ReturnXScroll16
NScrollRightPage endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NScrollUpRow
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Adjust offset for scrolling up a row.
CALLED BY: SpreadsheetNormalizePosition()
PASS: ss:bp - ptr to TrackScrollingParams
ds:si - ptr to Spreadsheet instance
RETURN: none
DESTROYED: ax, bx, cx, dx, di
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 5/19/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
NScrollUpRow proc near
class SpreadsheetClass
EC < call ECCheckInstancePtr ;>
mov ax, ds:[si].SSI_visible.CR_start.CR_row ;ax <- top row
call GetPreviousRow ;ax <- row above top
jc noScroll
mov ds:[si].SSI_visible.CR_start.CR_row, ax ;store new top
call RowGetHeight ;dx <- height of row above first
neg dx ;dx <- scroll up
GOTO ReturnYScroll16
noScroll:
clr dx ;dx <- no scroll
GOTO ReturnYScroll16
NScrollUpRow endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NScrollDownRow
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Adjust offset for scrolling down one row.
CALLED BY: SpreadsheetNormalizePosition()
PASS: ss:bp - ptr to TrackScrollingParams
ds:si - ptr to Spreadsheet instance
RETURN: none
DESTROYED: ax, bx, cx, dx, di
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 5/19/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
NScrollDownRow proc near
class SpreadsheetClass
EC < call ECCheckInstancePtr ;>
mov ax, ds:[si].SSI_visible.CR_start.CR_row
call RowGetHeight ;dx <- height of first row
call GetNextRow ;ax <- top row + 1
jc noScroll ;branch if at bottom
mov ds:[si].SSI_visible.CR_start.CR_row, ax ;store new top
GOTO ReturnYScroll16
noScroll:
clr dx ;dx <- no scroll
GOTO ReturnYScroll16
NScrollDownRow endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NScrollLeftColumn
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Adjust offset for scrolling left one column
CALLED BY: SpreadsheetNormalizePosition()
PASS: ss:bp - ptr to TrackScrollingParams
ds:si - ptr to Spreadsheet instance
RETURN: none
DESTROYED: ax, bx, cx, dx, di
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 5/19/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
NScrollLeftColumn proc near
class SpreadsheetClass
EC < call ECCheckInstancePtr ;>
mov cx, ds:[si].SSI_visible.CR_start.CR_column ;cx <- left column
call GetPreviousColumn ;cx <- column to left
jc noScroll ;branch if at left
mov ds:[si].SSI_visible.CR_start.CR_column, cx ;store new left
call ColumnGetWidth ;dx <- width
neg dx ;dx <- scroll left
GOTO ReturnXScroll16
noScroll:
clr dx ;dx <- no scroll
GOTO ReturnXScroll16
NScrollLeftColumn endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NScrollRightColumn
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Adjust offset for scrolling right one column
CALLED BY: SpreadsheetNormalizePosition()
PASS: ss:bp - ptr to TrackScrollingParams
ds:si - ptr to Spreadsheet instance
RETURN: dx:cx - x scroll amount
bx:ax - y scroll amount
DESTROYED: ax, bx, cx, di
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 5/19/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
NScrollRightColumn proc near
class SpreadsheetClass
EC < call ECCheckInstancePtr ;>
mov cx, ds:[si].SSI_visible.CR_start.CR_column
call ColumnGetWidth ;dx <- width of first column
call GetNextColumn ;cx <- left column + 1
jc noScroll
mov ds:[si].SSI_visible.CR_start.CR_column, cx ;store new left
GOTO ReturnXScroll16
noScroll:
clr dx ;dx <- no scroll
GOTO ReturnXScroll16
NScrollRightColumn endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NScrollGeneral
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Adjust offset for scrolling to generalized position.
CALLED BY: SpreadsheetNormalizePosition()
PASS: ss:bp - ptr to TrackScrollingParams
ds:si - ptr to Spreadsheet instance
RETURN: none
DESTROYED: ax, bx, cx, dx, di
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
optimization: As with page left and page up, this would be quicker
if there were a PosRoundToCell() routine...except it would be
difficult to deal with the negative positions correctly.
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 5/19/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
NScrollGeneral proc near
class SpreadsheetClass
EC < call ECCheckInstancePtr ;>
;
; Figure out cell we should scroll to
;
push ss:[bp].TSP_newOrigin.PD_y.high
push ss:[bp].TSP_newOrigin.PD_y.low
push ss:[bp].TSP_newOrigin.PD_x.high
push ss:[bp].TSP_newOrigin.PD_x.low
mov bx, sp ;ss:bx <- ptr to PointDWord
clr ax, cx ;(ax,cx) <- cell origin
call Pos32ToCellRel ;(ax,cx) <- cell at position
add sp, (size PointDWord)
mov ds:[si].SSI_visible.CR_start.CR_row, ax
mov ds:[si].SSI_visible.CR_start.CR_column, cx
;
; Round position to cell boundaries
;
call ReturnYDelta32
GOTO ReturnXDelta32
NScrollGeneral endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NScrollKeepVisCell
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Adjust offset to keep current cell in upper left,
after a document size change.
CALLED BY: SpreadsheetNormalizePosition()
PASS: ss:bp - ptr to TrackScrollingParams
TSP_oldOrigin PointDWord
ds:si - ptr to Spreadsheet instance
RETURN: none
DESTROYED: ax, bx, cx, dx, di
PSEUDO CODE/STRATEGY:
NOTE: unlike NScrollKeepCell(), this may require scrolling
to occur, in particular if the change in document size
occurred above or to the left of the current visible area.
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 9/18/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
NScrollKeepVisCell proc near
class SpreadsheetClass
EC < call ECCheckInstancePtr ;>
;
; Figure out where the upper-left is, and how far it has moved.
;
mov ax, ds:[si].SSI_visible.CR_start.CR_row
call ReturnYDelta32
mov cx, ds:[si].SSI_visible.CR_start.CR_column
GOTO ReturnXDelta32
NScrollKeepVisCell endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NScrollInto
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Adjust offset for scrolling to keep cell visible
CALLED BY: SpreadsheetNormalizePosition()
PASS: ss:bp - ptr to TrackScrollingParams
ds:si - ptr to Spreadsheet instance
RETURN: none
DESTROYED: ax, bx, cx, dx, di
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 10/ 8/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
NScrollInto proc near
class SpreadsheetClass
.enter
EC < call ECCheckInstancePtr ;>
;
; First we try generalized scrolling, and see if that did anything
;
pushdw ss:[bp].TSP_change.PD_x
pushdw ss:[bp].TSP_change.PD_y
call NScrollGeneral ;try generalized scrolling
mov ax, ss:[bp].TSP_change.PD_x.low
or ax, ss:[bp].TSP_change.PD_x.high
or ax, ss:[bp].TSP_change.PD_y.low
or ax, ss:[bp].TSP_change.PD_y.high
jnz donePop ;branch if scroll occurred
;
; If no scroll occurred, but was supposed to, it was a very
; small scroll (ie. less than a row or column). Calling the
; handler for SA_DRAG_SCROLL handles this case exactly, so
; we restore the original suggested change and pass it on.
;
popdw ss:[bp].TSP_change.PD_y ;restore suggested y scroll
popdw ss:[bp].TSP_change.PD_x ;restore suggested x scroll
call NScrollSelect
jmp done
donePop:
add sp, (size PointDWord) ;ignore saved values
done:
.leave
ret
NScrollInto endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NScrollSelect
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Adjust offset for scrolling while selecting
CALLED BY: SpreadsheetNormalizePosition()
PASS: ss:bp - ptr to TrackScrollingParams
ds:si - ptr to Spreadsheet instance
RETURN: none
DESTROYED: ax, bx, cx, dx, di
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 6/11/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
NScrollSelect proc near
class SpreadsheetClass
.enter
EC < call ECCheckInstancePtr ;>
;
; Deal with left or right scrolling
;
EC < cmp ss:[bp].TSP_change.PD_x.high, 0 >
EC < je xOK ;>
EC < cmp ss:[bp].TSP_change.PD_x.high, -1 >
EC < je xOK ;>
EC < ERROR SCROLL_AMOUNT_TOO_LARGE ;>
EC <xOK: ;>
tst ss:[bp].TSP_change.PD_x.low ;selecting left or right?
jz afterXScroll ;branch if no scroll
js scrollLeft ;branch if negative (ie. left)
call NScrollRightColumn
jmp afterXScroll
scrollLeft:
call NScrollLeftColumn
afterXScroll:
;
; Deal with up or down scrolling
;
EC < cmp ss:[bp].TSP_change.PD_y.high, 0 >
EC < je yOK ;>
EC < cmp ss:[bp].TSP_change.PD_y.high, -1 >
EC < je yOK ;>
EC < ERROR SCROLL_AMOUNT_TOO_LARGE ;>
EC <yOK: ;>
tst ss:[bp].TSP_change.PD_y.low ;selecting up or down?
jz afterYScroll ;branch if no scroll
js scrollUp ;branch if negative (ie. up)
call NScrollDownRow
jmp afterYScroll
scrollUp:
call NScrollUpRow
afterYScroll:
.leave
ret
NScrollSelect endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
RecalcViewDocSize
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Recalculate document view size
CALLED BY: UpdateDocUIRedrawAll, SpreadsheetSetDocOrigin
PASS: ds:si - ptr to Spreadsheet instance
RETURN: none
DESTROYED: none
PSEUDO CODE/STRATEGY:
Functionality of adding on "mystery gray area" has been
removed. This is to make the spreadsheet more well-behaved in
the context of a compound document. CalcSetDocSize has been
merged into this procedure.
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 5/22/91 Initial version
chrisb 11/18/91 merged CalcSetDocSize into this procedure
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
RecalcViewDocSize proc far
uses ax, bx, cx, dx
bounds local RectDWord
class SpreadsheetClass
.enter
EC < call ECCheckInstancePtr >
movdw ss:[bounds].RD_left, ds:[si].SSI_bounds.RD_left, ax
movdw ss:[bounds].RD_top, ds:[si].SSI_bounds.RD_top, ax
clr dx ;dx <- minimum column
mov cx, ds:[si].SSI_maxCol
inc cx
call ColumnGetRelPos32Far ;ax:dx <- x size - last col
movdw ss:bounds.RD_right, axdx
movdw ds:[si].SSI_bounds.RD_right, axdx
clr dx ;dx <- minimum row
mov ax, ds:[si].SSI_maxRow
inc ax
call RowGetRelPos32Far ;ax:dx <- y size - last row
movdw ss:bounds.RD_bottom, axdx
movdw ds:[si].SSI_bounds.RD_bottom, axdx
;
; Tell our parent about the change...
;
push bp, si
lea bp, ss:bounds ;ss:bp <- ptr to RectDWord
mov dx, (size RectDWord) ;dx <- size of args
mov ax, MSG_VIS_CONTENT_SET_DOC_BOUNDS ;ax <- method to send
mov si, ds:[si].SSI_chunk
call VisCallParent
pop bp, si
.leave
ret
RecalcViewDocSize endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SendToViewStack
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Send a message to the view with data on the stack
CALLED BY: KeepCellOnScreen
PASS: ds:si - ptr to Spreadsheet instance
ax - method to send to view
ss: bp - stack data
dx - size of stack data
RETURN: cx, dx, bp - return from method
DESTROYED: cx, dx, bp (if not returned)
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 5/22/91 Initial version
cbh 8/ 8/91 Changed for new MSG_VIS_VUP_CALL_OBJECT_OF_CLASS
CDB 12/16/91 Changed name to protect the innocent
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
SendToViewStack proc far
class SpreadsheetClass
push di
mov di, mask MF_STACK
FALL_THRU SendToViewCommon, di
SendToViewStack endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SendToViewCommon
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Send a message to the view.
CALLED BY: SendToView, SendToViewStack
PASS: ax, cx, dx, bp - message data
RETURN: ax, cx, dx, bp - returned from method called
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
CDB 12/17/91 Initial version.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
SendToViewCommon proc far
uses bx,si
class SpreadsheetClass
.enter
EC < call ECCheckInstancePtr ;>
push si
ornf di, mask MF_RECORD
mov bx, segment GenViewClass
mov si, offset GenViewClass
call ObjMessage
mov cx, di ;cx <- event to send to view
pop si
mov si, ds:[si].SSI_chunk
mov ax, MSG_VIS_VUP_CALL_OBJECT_OF_CLASS
call ObjCallInstanceNoLock
.leave
FALL_THRU_POP di
ret
SendToViewCommon endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
KeepSelectCellOnScreen
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Keep non-anchor cell of keyboard selection on screen
CALLED BY: {Extend,Contract}Selection{Left,Right,Up,Down}
PASS: ds:si - ptr to instance data
RETURN: none
DESTROYED: none
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 10/ 8/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
KeepSelectCellOnScreen proc near
class SpreadsheetClass
uses ax, cx
.enter
EC < call ECCheckInstancePtr ;>
mov ax, ds:[si].SSI_selected.CR_start.CR_row
cmp ax, ds:[si].SSI_active.CR_row ;anchored at top?
mov ax, ds:[si].SSI_selected.CR_end.CR_row
jne notBottom ;branch if not anchored at top
afterRow:
mov cx, ds:[si].SSI_selected.CR_start.CR_column
cmp cx, ds:[si].SSI_active.CR_column ;anchored at left?
mov cx, ds:[si].SSI_selected.CR_end.CR_column
jne notRight ;branch if not anchored at top
afterCol:
call KeepCellOnScreen
done:
.leave
ret
notBottom:
cmp ax, ds:[si].SSI_active.CR_row ;anchored at bottom?
jne done ;branch if not anchored at bttm
mov ax, ds:[si].SSI_selected.CR_start.CR_row
jmp afterRow
notRight:
cmp cx, ds:[si].SSI_active.CR_column ;anchored at right?
jne done ;branch if not anchored at right
mov cx, ds:[si].SSI_selected.CR_start.CR_column
jmp afterCol
KeepSelectCellOnScreen endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
KeepCellOnScreen, KeepActiveCellOnScreen
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Keep a cell in visible area
CALLED BY: MoveActiveCellFar())
PASS: ds:si - ptr to instance data
(ax,cx) - cell to keep on screen (r,c)
RETURN: none
DESTROYED: none (ax,cx)
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 10/ 2/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
KeepActiveCellOnScreen proc far
class SpreadsheetClass
EC < call ECCheckInstancePtr ;>
mov ax, ds:[si].SSI_active.CR_row
mov cx, ds:[si].SSI_active.CR_column
FALL_THRU KeepCellOnScreen
KeepActiveCellOnScreen endp
KeepCellOnScreen proc far
uses ax, bx, cx, dx, bp
class SpreadsheetClass
.enter
EC < call ECCheckInstancePtr ;>
;
; Set up args for GenView method
;
sub sp, (size MakeRectVisibleParams)
mov bp, sp ;ss:bp <- ptr to args
;
; We may want to put the active cell in the center of the screen.
;
push ds, bx
mov bx, handle dgroup
call MemDerefDS ; ds = dgroup
tst ds:[centerFlag]
pop ds, bx ; restore ds, bx
jz dontCenter
mov ss:[bp].MRVP_xMargin, MRVM_50_PERCENT
mov ss:[bp].MRVP_xFlags, mask MRVF_ALWAYS_SCROLL
mov ss:[bp].MRVP_yMargin, MRVM_50_PERCENT
mov ss:[bp].MRVP_yFlags, mask MRVF_ALWAYS_SCROLL
jmp partialVisible
dontCenter:
mov ss:[bp].MRVP_xMargin, MRVM_0_PERCENT
mov ss:[bp].MRVP_xFlags, 0
mov ss:[bp].MRVP_yMargin, MRVM_0_PERCENT
mov ss:[bp].MRVP_yFlags, 0
partialVisible:
;
; Special case the right column and bottom row. They are generally
; only partially visible, so we treat them as being off screen.
;
if _SCROLL_PARTLY_VISIBLE_CELL_ON_SCREEN_ONLY_WITH_KBD
;
; We only do this special case if the user got here via the
; keyboard. We do this with a hack, which is to see if we
; have got the grab, which is taken when doing selection.
;
test ds:[si].SSI_flags, mask SF_HAVE_GRAB
jnz checkScroll
endif
cmp ax, ds:[si].SSI_visible.CR_end.CR_row
je doScrollRow
cmp cx, ds:[si].SSI_visible.CR_end.CR_column
je doScrollColumn
;
; See if the cell is already visible -- if so, we're done
;
checkScroll:
;
; If we want to put the cell in the center of the screen, then
; we don't care if it is already visible or not.
;
push ds, bx
mov bx, handle dgroup
call MemDerefDS ; ds = dgroup
tst ds:[centerFlag]
pop ds, bx ;restore ds
jne getBounds
call CellVisible? ;cell visible?
jc done ;branch if already on screen
;
; Get y bounds
;
getBounds::
clr dx ;dx <- origin row
call RowGetRelPos32 ;ax:dx <- position of row
push bx
pushdw axdx
;
; Get x bounds
;
clr dx ;dx <- origin column
call ColumnGetRelPos32 ;ax:dx <- position of column
setBounds:
movdw ss:[bp].MRVP_bounds.RD_left, axdx
add dx, bx ;add in column width
adc ax, 0
movdw ss:[bp].MRVP_bounds.RD_right, axdx
popdw axdx ;ax:dx <- position of row
pop bx ;bx <- row height
movdw ss:[bp].MRVP_bounds.RD_top, axdx
add dx, bx ;add in row height
adc ax, 0
movdw ss:[bp].MRVP_bounds.RD_bottom, axdx
;
; Tell her about it...
;
mov dx, (size MakeRectVisibleParams) ;dx <- size of args
mov ax, MSG_GEN_VIEW_MAKE_RECT_VISIBLE
call SendToViewStack
done:
add sp, (size MakeRectVisibleParams) ;done with args
.leave
ret
;
; The cell is already partially visible, so we can scroll to it
; more easily than if it were at an arbitrary position.
;
; See if there is only a partial row or column visible.
;
;
; if there is only one row or one column visible, we still need to ensure
; that the new cell is visible - brianc 5/5/94
;
doScrollRow:
cmp ax, ds:[si].SSI_visible.CR_start.CR_row
; je done
je checkScroll
jmp doScroll
doScrollColumn:
cmp cx, ds:[si].SSI_visible.CR_start.CR_column
; je done
je checkScroll
doScroll:
;
; Get the bounds relative to the visible range, and make convert
; them into absolute offsets before passing them to the view.
;
mov dx, ds:[si].SSI_visible.CR_start.CR_row
call RowGetRelPos32
adddw axdx, ds:[si].SSI_offset.PD_y
push bx
pushdw axdx
mov dx, ds:[si].SSI_visible.CR_start.CR_column
call ColumnGetRelPos32
adddw axdx, ds:[si].SSI_offset.PD_x
jmp setBounds
KeepCellOnScreen endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SpreadsheetSetDocOrigin
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DESCRIPTION: Update our SSI_offset field. Also, add vardata to
specify the upper left-hand corner of the spreadsheet
PASS: *ds:si - SpreadsheetClass object
ds:di - SpreadsheetClass instance data
es - segment of SpreadsheetClass
ss:bp - PointDWord
RETURN: nothing
DESTROYED: ax, cx, dx, bp
REGISTER/STACK USAGE:
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
chrisb 9/ 1/94 Initial version.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
SpreadsheetSetDocOrigin method dynamic SpreadsheetClass,
MSG_SPREADSHEET_SET_DOC_ORIGIN
mov ax, ss:[bp].PD_x.low
or ax, ss:[bp].PD_x.high
or ax, ss:[bp].PD_y.low
or ax, ss:[bp].PD_y.high
jz deleteVarData
mov ax, TEMP_SPREADSHEET_DOC_ORIGIN or \
mask VDF_SAVE_TO_STATE
mov cx, size SpreadsheetDocOrigin
call ObjVarAddData ; ds:bx - vardata
;
; Now, re-dereference the spreadsheet. Store the origin in
; the vardata, and update the "offset" field
;
mov si, ds:[si]
add si, ds:[si].Spreadsheet_offset
ornf ds:[si].SSI_flags, mask SF_NONZERO_DOC_ORIGIN
movdw dxcx, ss:[bp].PD_x
movdw ds:[si].SSI_bounds.RD_left, dxcx
decdw dxcx
movdw ds:[si].SSI_offset.PD_x, dxcx
movdw dxcx, ss:[bp].PD_y
movdw ds:[si].SSI_bounds.RD_top, dxcx
decdw dxcx
movdw ds:[si].SSI_offset.PD_y, dxcx
;
; Also, compute the upper left-hand row & column information
;
push bx ; ds:bx - vardata ptr
clr ax, cx
mov bx, bp
call Pos32ToCellRelFar
pop bx ; ds:bx - vardata ptr
mov ds:[bx].SDO_rowCol.CR_row, ax
mov ds:[bx].SDO_rowCol.CR_column, cx
mov ds:[si].SSI_visible.CR_start.CR_row, ax
mov ds:[si].SSI_visible.CR_start.CR_column, cx
call setSelection
; We'll let the "draw" handler figure out the lower-right hand
; corner.
; lea bx, ss:[bounds].RD_right
; call Pos32ToVisCellFar
; mov ds:[si].SSI_visible.CR_end.CR_row, ax
; mov ds:[si].SSI_visible.CR_end.CR_column, cx
done:
;
; Tell the view (and the content) about the new document bounds
;
call RecalcViewDocSize
ret
;------------------------
deleteVarData:
mov ax, TEMP_SPREADSHEET_DOC_ORIGIN
call ObjVarDeleteData
mov si, ds:[si]
add si, ds:[si].Spreadsheet_offset
clr ax
movdw ds:[si].SSI_bounds.RD_left, axax
movdw ds:[si].SSI_bounds.RD_top, axax
andnf ds:[si].SSI_flags, not mask SF_NONZERO_DOC_ORIGIN
jmp done
setSelection:
;----------------------
mov bp, ax
mov ax, MSG_SPREADSHEET_MOVE_ACTIVE_CELL
mov si, ds:[si].SSI_chunk
call ObjCallInstanceNoLock
mov si, ds:[si]
add si, ds:[si].Spreadsheet_offset
retn
SpreadsheetSetDocOrigin endm
DrawCode ends
| 28.743184 | 80 | 0.614417 |
4dae207764e2afcec057ecde28f6b98217fef4d9 | 1,320 | asm | Assembly | 2020 Fall E C E 252/EX11/strlen.asm | jsswd888/2020_FALL_UW_MADISON | 8bfb4616ec8d9c609ef0e15111ac98cfb1af9a65 | [
"MIT"
] | null | null | null | 2020 Fall E C E 252/EX11/strlen.asm | jsswd888/2020_FALL_UW_MADISON | 8bfb4616ec8d9c609ef0e15111ac98cfb1af9a65 | [
"MIT"
] | null | null | null | 2020 Fall E C E 252/EX11/strlen.asm | jsswd888/2020_FALL_UW_MADISON | 8bfb4616ec8d9c609ef0e15111ac98cfb1af9a65 | [
"MIT"
] | null | null | null | ; Filename: strlen.asm
; Subroutine: STRLEN
; Description: Finds length of an ASCIIZ string
; Assumes: R1 - string address
; Returns: R2 - length of the string
;return length of the string
.orig x0200
START
LEA R1, S1
JSR STRLEN
LEA R1, S6
JSR STRLEN
LEA R1, S2
JSR STRLEN
LEA R1, S5
JSR STRLEN
LEA R1, S3
JSR STRLEN
LEA R1, S4
JSR STRLEN
LEA R1, S7
JSR STRLEN
BR START ; loop forever
S1 .STRINGZ "Ciao!"
S2 .STRINGZ "Hi!"
S3 .STRINGZ "Salve!"
S4 .STRINGZ "Hello!"
S5 .STRINGZ "Gelato!"
S6 .STRINGZ ""
S7 .STRINGZ "Italiano"
; Subroutine: STRLEN
; Description: Finds length of ASCIIZ string
; Assumes: R1 = string address
; Returns: R2 = length of the string
STRLEN
ST R0, STRLEN_R0 ; context save
ST R1, STRLEN_R1 ; context save ADDED
AND R2, R2, #0 ; ADDED initialize String len to 0
STRLEN_LOOP
LDR R0, R1, #0 ; get current character
BRz STRLEN_EXIT ; at null terminator?
ADD R2, R2, #1 ; ADDED increment the string count//count how many
; numbers of the character is not null
ADD R1, R1, #1 ; increment string pointer (address)
BR STRLEN_LOOP
STRLEN_EXIT
LD R0, STRLEN_R0 ; context restore
LD R1, STRLEN_R1 ; ADDED
;NOT R3, R3
;ADD R3, R3, #1
;ADD R2, R3, #1
RET
STRLEN_R0 .BLKW 1
STRLEN_R1 .BLKW 1 ; ADDED
.end | 18.857143 | 66 | 0.67197 |
d3435d917611f17a84dfaea9e868495ced821826 | 1,561 | asm | Assembly | src/core/asm/x86/inst_0x0fb0.asm | Hiroshi123/bin_tools | 95929eb218a82e30c43ee5bd209301a24abebffa | [
"MIT"
] | null | null | null | src/core/asm/x86/inst_0x0fb0.asm | Hiroshi123/bin_tools | 95929eb218a82e30c43ee5bd209301a24abebffa | [
"MIT"
] | 4 | 2019-02-27T05:41:26.000Z | 2020-07-16T00:24:24.000Z | src/core/asm/x86/inst_0x0fb0.asm | Hiroshi123/bin_tools | 95929eb218a82e30c43ee5bd209301a24abebffa | [
"MIT"
] | null | null | null |
default rel
section .text
global _0x0fb0_cmpxchg
global _0x0fb1_cmpxchg
global _0x0fb2_lss
global _0x0fb3_btr
global _0x0fb4_lfs
global _0x0fb5_lgs
global _0x0fb6_movzbS
global _0x0fb7_movzwS
global _0x0fb8_popcnt
;; global _0x0fb9
global _0x0fba_bitop
global _0x0fbb_btc
global _0x0fbc_bsf
global _0x0fbd_bsr
global _0x0fbe_movsbS
global _0x0fbf_movswS
%include "extern_for_inst.asm"
_0x0fb0_cmpxchg:
call _do01
;; db 0xeb,0xfe
ret
_0x0fb1_cmpxchg:
call _do01
;; db 0xeb,0xfe
ret
_0x0fb2_lss:
db 0xeb,0xfe
_0x0fb3_btr:
db 0xeb,0xfe
_0x0fb4_lfs:
db 0xeb,0xfe
_0x0fb5_lgs:
db 0xeb,0xfe
;;; casting from 1byte to larger bytes
;;; the bits which was not given from another register will be fed as value0.
_0x0fb6_movzbS:
add dword [_rip],1
call _get_mod_reg_rm
;; it loads just 1byte which means dflag must be 0
mov byte [_context._dflag],0x00
call _set_scale_index_base
call _fetch_displacement_by_mod
ret
call _load_rm_by_mod
call _mov_res_to_arg2
call _mov_reg_to_arg1
call _assign
pop rbp
ret
_0x0fb7_movzwS:
add dword [_rip],1
call _get_mod_reg_rm
call _set_scale_index_base
call _fetch_displacement_by_mod
ret
db 0xeb,0xfe
;;; [TODO] needs to be sign extended..
_0x0fbe_movsbS:
add dword [_rip],1
call _get_mod_reg_rm
;; it loads just 1byte which means dflag must be 0
mov byte [_context._dflag],0x00
call _set_scale_index_base
call _fetch_displacement_by_mod
ret
call _load_rm_by_mod
call _mov_res_to_arg2
call _mov_reg_to_arg1
call _assign
pop rbp
ret
| 16.092784 | 77 | 0.778988 |
644b3121434b675aee327a78407111de09bd9a86 | 470 | asm | Assembly | oeis/303/A303872.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 11 | 2021-08-22T19:44:55.000Z | 2022-03-20T16:47:57.000Z | oeis/303/A303872.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 9 | 2021-08-29T13:15:54.000Z | 2022-03-09T19:52:31.000Z | oeis/303/A303872.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 3 | 2021-08-22T20:56:47.000Z | 2021-09-29T06:26:12.000Z | ; A303872: Triangle read by rows: T(0,0) = 1; T(n,k) = -T(n-1,k) + 2 T(n-1,k-1) for k = 0,1,...,n; T(n,k)=0 for n or k < 0.
; Submitted by Jon Maiga
; 1,-1,2,1,-4,4,-1,6,-12,8,1,-8,24,-32,16,-1,10,-40,80,-80,32,1,-12,60,-160,240,-192,64,-1,14,-84,280,-560,672,-448,128,1,-16,112,-448,1120,-1792,1792,-1024,256,-1,18,-144,672,-2016,4032,-5376,4608,-2304,512
lpb $0
add $1,1
sub $0,$1
lpe
sub $1,$0
sub $2,1
sub $2,$0
bin $2,$1
mov $1,2
pow $1,$0
mul $2,$1
mov $0,$2
| 27.647059 | 207 | 0.559574 |
b593aaa39aa8643113d73fc4715f85801b0459a8 | 1,580 | asm | Assembly | programs/oeis/088/A088581.asm | neoneye/loda | afe9559fb53ee12e3040da54bd6aa47283e0d9ec | [
"Apache-2.0"
] | 22 | 2018-02-06T19:19:31.000Z | 2022-01-17T21:53:31.000Z | programs/oeis/088/A088581.asm | neoneye/loda | afe9559fb53ee12e3040da54bd6aa47283e0d9ec | [
"Apache-2.0"
] | 41 | 2021-02-22T19:00:34.000Z | 2021-08-28T10:47:47.000Z | programs/oeis/088/A088581.asm | neoneye/loda | afe9559fb53ee12e3040da54bd6aa47283e0d9ec | [
"Apache-2.0"
] | 5 | 2021-02-24T21:14:16.000Z | 2021-08-09T19:48:05.000Z | ; A088581: a(n) = n*x^n + (n-1)*x^(n-1) + . . . + x + 1 for x=3.
; 1,4,22,103,427,1642,6016,21325,73813,250960,841450,2790067,9167359,29893558,96855124,312088729,1000836265,3196219036,10169787838,32252755711,101988443731,321655860994,1012039172392,3177332285413,9955641160957,31137856397032,97226367933586,303117500028235,943667688767143,2933948632348750,9110682595188220,28258557879990577,87555203923249489,271004202619581748,838028380408245094,2589132458873234839,7992539329565203195,24653043847532105626,75985409119105805008,234035060086845879421,720341678449123031461,2215734529913125273984,6811332073436644360762,20926381671401738698723,64256301367480632945487,197200373162268149384422,604895526666283199797156,1854569801537285854323145,5683359069227166327764473,17409026201527425277678540,53303925586120054716190990,163142317702973500798039087,499118575942760512342515619,1526430596329801566872741938,4666516394493964790153811064,14261222999995574639068188949,43568690449527764723024834125,133061135697206416586535304216,406248600137488617011988318178,1239941379550073952793112171131,3783410876063046163650778163191,11540992840427611406766659438974,35195259157998252967742953165132,107302619384141015145557784040033,327058383882861814163660125754017,996626728839901748671940698163812,3036234918093654164558703057196726,9247768949002809249304752059706055,28160499431173968014800184843465803,85733076046018524845058340523440330,260953961395545436937148379549449760,794126083959105898017365212585735597
lpb $0
mul $1,3
add $1,$0
sub $0,1
lpe
mul $1,3
add $1,1
mov $0,$1
| 131.666667 | 1,440 | 0.903797 |
288aaa06df43b22a646a68089a6fc1e9367eddaf | 7,802 | asm | Assembly | src/tocompress/textures-C.asm | santiontanon/talesofpopolon-ext | a7c7fd1164d506d6b0c6245fdf3ad0b634facd84 | [
"Apache-2.0"
] | 4 | 2019-10-20T08:14:01.000Z | 2021-09-24T19:41:47.000Z | src/tocompress/textures-C.asm | santiontanon/talesofpopolon-ext | a7c7fd1164d506d6b0c6245fdf3ad0b634facd84 | [
"Apache-2.0"
] | 1 | 2019-10-20T12:21:06.000Z | 2019-10-21T21:52:35.000Z | src/tocompress/textures-C.asm | santiontanon/talesofpopolon-ext | a7c7fd1164d506d6b0c6245fdf3ad0b634facd84 | [
"Apache-2.0"
] | null | null | null | org #0000
textures:
walltexture1:
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
db #80,#80,#80,#80, 0, 0,#90,#90,#80,#80,#80,#80, 0, 0,#90,#90
db #80,#80,#80,#80, 0, 0,#80,#80,#80,#80,#80,#80, 0, 0,#80,#80
db #80,#80,#80,#80, 0, 0,#80,#80,#80,#80,#80,#80, 0, 0,#80,#80
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
db 0, 0,#90,#90,#80,#80,#80,#80, 0, 0,#90,#90,#80,#80,#80,#80
db 0, 0,#80,#80,#80,#80,#80,#80, 0, 0,#80,#80,#80,#80,#80,#80
db 0, 0,#80,#80,#80,#80,#80,#80, 0, 0,#80,#80,#80,#80,#80,#80
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
db #80,#80,#80,#80, 0, 0,#90,#90,#80,#80,#80,#80, 0, 0,#90,#90
db #80,#80,#80,#80, 0, 0,#80,#80,#80,#80,#80,#80, 0, 0,#80,#80
db #80,#80,#80,#80, 0, 0,#80,#80,#80,#80,#80,#80, 0, 0,#80,#80
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
db 0, 0,#90,#90,#80,#80,#80,#80, 0, 0,#90,#90,#80,#80,#80,#80
db 0, 0,#80,#80,#80,#80,#80,#80, 0, 0,#80,#80,#80,#80,#80,#80
db 0, 0,#80,#80,#80,#80,#80,#80, 0, 0,#80,#80,#80,#80,#80,#80
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
db #80,#80,#80,#80, 0, 0,#90,#90,#80,#80,#80,#80, 0, 0,#90,#90
db #80,#80,#80,#80, 0, 0,#80,#80,#80,#80,#80,#80, 0, 0,#80,#80
db #80,#80,#80,#80, 0, 0,#80,#80,#80,#80,#80,#80, 0, 0,#80,#80
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
db 0, 0,#90,#90,#80,#80,#80,#80, 0, 0,#90,#90,#80,#80,#80,#80
db 0, 0,#80,#80,#80,#80,#80,#80, 0, 0,#80,#80,#80,#80,#80,#80
db 0, 0,#80,#80,#80,#80,#80,#80, 0, 0,#80,#80,#80,#80,#80,#80
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
prisoner1:
db 0, 0, 0, 0, 0, #e0, 0, 0, 0, 0, 0, #e0, 0, 0, 0, #00
db 0, 0, 0, 0, 0, #e0, 0, 0, 0, 0, 0, #e0, 0, 0, 0, #00
db #80, 0, 0, 0, #e0, 0, 0, 0, 0, 0, 0, 0, #e0, 0, 0, #00
db #80, 0, 0, 0, #e0, 0, 0, 0, 0, 0, 0, 0, #e0, 0, 0, #00
db #80, 0, 0, #e0, 0, 0, 0, 0, 0, #b0, #b0, 0, 0, #e0, 0, #00
db 0, 0, 0, #e0, 0, 0, 0, 0, #b0, #b0, #b0, #b0, 0, #e0, 0, #00
db 0, 0, #e0, 0, 0, 0, 0, 0, #b0, #b0, #b0, #b0, 0, 0, #e0, #00
db 0, 0, #e0, 0, 0, 0, 0, 0, #b0, 0, #b0, 0, 0, 0, #e0, #00
db 0, #b0, #b0, 0, 0, 0, 0, 0, #b0, #b0, #b0, #b0, 0, 0, #e0, #00
db 0, #b0, #b0, 0, 0, 0, 0, 0, #b0, #b0, 0, #b0, 0, #b0, #b0, #00
db 0, 0, #90, 0, 0, 0, 0, 0, #b0, #b0, #b0, #b0, 0, #b0, #b0, #00
db 0, 0, #b0, 0, 0, 0, 0, 0, #90, #90, 0, 0, 0, 0, #90, #00
db #80, 0, #b0, 0, 0, #b0, #b0, #b0, #b0, #b0, #b0, #b0, 0, 0, #b0, #00
db #80, 0, #b0, 0, #b0, #b0, #b0, #b0, #b0, #b0, #b0, #b0, #b0, 0, #b0, #00
db #80, 0, 0, #b0, #b0, 0, 0, #b0, #b0, #b0, #b0, 0, #b0, #b0, 0, #00
db 0, 0, 0, 0, 0, 0, 0, #b0, #b0, #b0, #b0, 0, 0, 0, 0, #00
db 0, 0, 0, 0, 0, 0, 0, #b0, #b0, #b0, #b0, 0, 0, 0, 0, #00
db 0, 0, 0, 0, 0, 0, 0, #90, #b0, #b0, 0, 0, 0, 0, 0, #00
db 0, 0, 0, 0, 0, 0, 0, #90, #b0, #b0, 0, 0, 0, 0, 0, #00
db 0, 0, 0, 0, 0, 0, 0, #90, #90, #90, 0, 0, 0, 0, 0, #00
db 0, 0, 0, 0, 0, 0, 0, #f0, #f0, #f0, 0, 0, 0, 0, 0, #00
db 0, 0, 0, 0, 0, 0, #f0, #f0, #f0, #f0, #f0, 0, 0, 0, 0, #00
db #80, 0, 0, 0, 0, 0, #f0, #f0, #f0, 0, #f0, 0, 0, 0, 0, #00
db #80, 0, 0, 0, 0, #f0, #f0, #f0, 0, #f0, #f0, #f0, 0, 0, 0, #00
db #80, 0, 0, 0, 0, #f0, #f0, #f0, 0, #f0, #f0, #f0, 0, 0, 0, #00
db 0, 0, 0, 0, 0, #90, #90, 0, 0, 0, #90, #90, 0, 0, 0, #00
db 0, 0, 0, 0, 0, #b0, #b0, 0, 0, 0, #b0, #b0, 0, 0, 0, #00
db 0, 0, 0, 0, 0, #b0, #b0, 0, 0, 0, #b0, #b0, 0, 0, 0, #00
db 0, 0, 0, 0, #b0, #b0, 0, 0, 0, 0, 0, #b0, #b0, 0, 0, #00
db 0, 0, 0, 0, #b0, #b0, 0, 0, 0, 0, 0, #b0, #b0, 0, 0, #00
db 0, 0, 0, #b0, #b0, 0, 0, 0, 0, 0, 0, 0, #b0, 0, 0, #00
db 0, 0, 0, #b0, #b0, #b0, #b0, 0, 0, 0, 0, 0, #b0, #b0, #b0, #00
prisoner2:
db 0, 0, 0, 0, #e0, 0, 0, 0, 0, 0, 0, 0, #e0, 0, 0, #00
db 0, 0, 0, 0, #e0, 0, 0, 0, 0, 0, 0, 0, #e0, 0, 0, #00
db #80, 0, 0, 0, #e0, 0, 0, 0, 0, 0, 0, 0, 0, #e0, 0, #00
db #80, 0, 0, 0, #e0, 0, 0, 0, 0, 0, 0, 0, 0, #e0, 0, #00
db #80, 0, 0, #e0, 0, 0, 0, 0, #b0, #b0, 0, 0, 0, #e0, 0, #00
db 0, 0, 0, #e0, 0, 0, 0, #b0, #b0, #b0, #b0, 0, 0, #e0, 0, #00
db 0, 0, 0, #e0, 0, 0, 0, #b0, #b0, #b0, #b0, 0, 0, 0, #e0, #00
db 0, 0, 0, #e0, 0, 0, 0, #b0, 0, #b0, 0, 0, 0, 0, #e0, #00
db 0, 0, #e0, 0, 0, 0, 0, #b0, #b0, #b0, #b0, 0, 0, 0, #e0, #00
db 0, #b0, #b0, 0, 0, 0, 0, #b0, #b0, 0, #b0, 0, 0, 0, #e0, #00
db 0, #b0, #b0, 0, 0, 0, 0, #b0, #b0, #b0, #b0, 0, 0, 0, #b0, #b0
db 0, 0, #90, 0, 0, 0, 0, #90, #90, 0, 0, 0, 0, 0, #b0, #b0
db #80, 0, #b0, 0, 0, #b0, #b0, #b0, #b0, #b0, #b0, #b0, 0, 0, 0, #90
db #80, 0, #b0, 0, #b0, #b0, #b0, #b0, #b0, #b0, #b0, #b0, #b0, 0, #b0, #00
db #80, 0, #b0, #b0, #b0, 0, #b0, #b0, #b0, #b0, #b0, 0, #b0, #b0, 0, #00
db 0, 0, 0, 0, 0, 0, #b0, #b0, #b0, #b0, #b0, 0, 0, 0, 0, #00
db 0, 0, 0, 0, 0, 0, 0, #b0, #b0, #b0, #b0, 0, 0, 0, 0, #00
db 0, 0, 0, 0, 0, 0, 0, #90, #b0, #b0, 0, 0, 0, 0, 0, #00
db 0, 0, 0, 0, 0, 0, 0, #90, #b0, #b0, 0, 0, 0, 0, 0, #00
db 0, 0, 0, 0, 0, 0, 0, #90, #90, #90, 0, 0, 0, 0, 0, #00
db 0, 0, 0, 0, 0, 0, 0, #f0, #f0, #f0, 0, 0, 0, 0, 0, #00
db 0, 0, 0, 0, 0, 0, #f0, #f0, #f0, #f0, #f0, 0, 0, 0, 0, #00
db #80, 0, 0, 0, 0, 0, #f0, #f0, #f0, 0, #f0, 0, 0, 0, 0, #00
db #80, 0, 0, 0, 0, #f0, #f0, #f0, 0, #f0, #f0, #f0, 0, 0, 0, #00
db #80, 0, 0, 0, 0, #f0, #f0, #f0, 0, #f0, #f0, #f0, 0, 0, 0, #00
db 0, 0, 0, 0, 0, #90, #90, 0, 0, 0, #90, #90, 0, 0, 0, #00
db 0, 0, 0, 0, 0, #b0, #b0, 0, 0, 0, #b0, #b0, 0, 0, 0, #00
db 0, 0, 0, 0, 0, #b0, #b0, 0, 0, 0, #b0, #b0, 0, 0, 0, #00
db 0, 0, 0, 0, #b0, #b0, 0, 0, 0, 0, 0, #b0, #b0, 0, 0, #00
db 0, 0, 0, 0, #b0, #b0, 0, 0, 0, 0, 0, #b0, #b0, 0, 0, #00
db 0, 0, 0, #b0, #b0, 0, 0, 0, 0, 0, 0, 0, #b0, 0, 0, #00
db 0, 0, 0, #b0, #b0, #b0, #b0, 0, 0, 0, 0, 0, #b0, #b0, #b0, #00
| 73.603774 | 85 | 0.304409 |
9575d6865bf536b8fd9742e76862a2c10dad7de2 | 3,990 | asm | Assembly | libsrc/graphics/w_dcircle.asm | Toysoft/z88dk | f930bef9ac4feeec91a07303b79ddd9071131a24 | [
"ClArtistic"
] | 8 | 2017-01-18T12:02:17.000Z | 2021-06-12T09:40:28.000Z | libsrc/graphics/w_dcircle.asm | Toysoft/z88dk | f930bef9ac4feeec91a07303b79ddd9071131a24 | [
"ClArtistic"
] | 1 | 2017-03-06T07:41:56.000Z | 2017-03-06T07:41:56.000Z | libsrc/graphics/w_dcircle.asm | Toysoft/z88dk | f930bef9ac4feeec91a07303b79ddd9071131a24 | [
"ClArtistic"
] | 3 | 2017-03-07T03:19:40.000Z | 2021-09-15T17:59:19.000Z | ; Z88 Small C+ Graphics Functions
; Draw a circle on the Z88 map
; Adapted from my Spectrum Routine
; (C) 1995-1998 D.J.Morris
;
; $Id: w_dcircle.asm,v 1.4 2016-04-13 21:09:09 dom Exp $
;
SECTION code_clib
PUBLIC w_draw_circle
EXTERN l_cmp
DEFVARS 0
{
x0l ds.b 1
x0h ds.b 1
y0l ds.b 1
y0h ds.b 1
rlv ds.b 1
rh ds.b 1
cxl ds.b 1
cxh ds.b 1
dal ds.b 1
dahi ds.b 1
scale ds.b 1
}
;iy points to table on stack (above)
;Entry:
; de = x0, hl = y0, bc = radius, a = scale factor
; b=x0 c=y0, d=radius, e=scale factor
; ix=plot routine
.w_draw_circle
ld iy,-11 ;create buffer on stack
add iy,sp
ld sp,iy
ld (iy+x0l),e
ld (iy+x0h),d
ld (iy+y0l),l
ld (iy+y0h),h
ld (iy+rlv),c
ld (iy+rh),b
ld (iy+scale),a ;step factor - usually 1
call l9900
ld hl,11
add hl,sp
ld sp,hl
ret
;Line 9900
.l9900
ld (iy+cxl),0
ld (iy+cxh),0
srl b
rr c
ld (iy+dal),c
ld (iy+dahi),b
;Line 9905
.l9905
ld b,(iy+rh)
ld c,(iy+rlv)
ld d,(iy+cxh)
ld e,(iy+cxl)
ld h,b
ld l,c
call l_cmp
ret nc
;Line 9910
bit 7,(iy+dahi)
jr z,l9915
ld c,(iy+dal)
ld b,(iy+dahi)
ld e,(iy+rlv)
ld h,(iy+rh)
add hl,bc
ld b,h
ld c,l
ld (iy+dal),c
ld (iy+dahi),b
ld d,(iy+rh)
ld e,(iy+rlv)
ld c,(iy+scale)
ld b,0
ld h,d
ld l,e
or a; CY = 0
sbc hl,bc
ld b,h
ld c,l
ld (iy+rlv),c
ld (iy+rh),b
;Line 9915
.l9915
ld b,(iy+dahi)
ld c,(iy+dal)
dec bc
ld h,b
ld l,c
ld d,(iy+cxh)
ld e,(iy+cxl)
or a
sbc hl,de
ld b,h
ld c,l
ld (iy+dal),c
ld (iy+dahi),b
.l9920
ld b,(iy+y0h)
ld c,(iy+y0l)
ld d,(iy+rh)
ld e,(iy+rlv)
srl d
rr e
ld h,b
ld l,c
add hl,de
push hl
ld b,(iy+x0h)
ld c,(iy+x0l)
ld d,(iy+cxh)
ld e,(iy+cxl)
ld h,b
ld l,c
add hl,de
pop de
call do_w_plot; (cx,r)
ld b,(iy+y0h)
ld c,(iy+y0l)
ld d,(iy+rh)
ld e,(iy+rlv)
srl d
rr e
ld h,b
ld l,c
add hl,de
push hl
ld b,(iy+x0h)
ld c,(iy+x0l)
ld d,(iy+cxh)
ld e,(iy+cxl)
ld h,b
ld l,c
or a
sbc hl,de
pop de
call do_w_plot; (-cx,r)
ld b,(iy+y0h)
ld c,(iy+y0l)
ld d,(iy+rh)
ld e,(iy+rlv)
srl d
rr e
ld h,b
ld l,c
or a
sbc hl,de
push hl
ld b,(iy+x0h)
ld c,(iy+x0l)
ld d,(iy+cxh)
ld e,(iy+cxl)
ld h,b
ld l,c
add hl,de
pop de
call do_w_plot; (cx,-r)
ld b,(iy+y0h)
ld c,(iy+y0l)
ld d,(iy+rh)
ld e,(iy+rlv)
srl d
rr e
ld h,b
ld l,c
or a
sbc hl,de
push hl
ld b,(iy+x0h)
ld c,(iy+x0l)
ld d,(iy+cxh)
ld e,(iy+cxl)
ld h,b
ld l,c
or a
sbc hl,de
pop de
call do_w_plot; (-cx,-r)
ld b,(iy+y0h)
ld c,(iy+y0l)
ld d,(iy+cxh)
ld e,(iy+cxl)
srl d
rr e
ld h,b
ld l,c
add hl,de
push hl
ld b,(iy+x0h)
ld c,(iy+x0l)
ld d,(iy+rh)
ld e,(iy+rlv)
ld h,b
ld l,c
add hl,de
pop de
call do_w_plot; (r,cx)
ld b,(iy+y0h)
ld c,(iy+y0l)
ld d,(iy+cxh)
ld e,(iy+cxl)
srl d
rr e
ld h,b
ld l,c
add hl,de
push hl
ld b,(iy+x0h)
ld c,(iy+x0l)
ld d,(iy+rh)
ld e,(iy+rlv)
ld h,b
ld l,c
or a
sbc hl,de
pop de
call do_w_plot; (-r,cx)
ld b,(iy+y0h)
ld c,(iy+y0l)
ld d,(iy+cxh)
ld e,(iy+cxl)
srl d
rr e
ld h,b
ld l,c
or a
sbc hl,de
push hl
ld b,(iy+x0h)
ld c,(iy+x0l)
ld d,(iy+rh)
ld e,(iy+rlv)
ld h,b
ld l,c
add hl,de
pop de
call do_w_plot; (r,-cx)
ld b,(iy+y0h)
ld c,(iy+y0l)
ld d,(iy+cxh)
ld e,(iy+cxl)
srl d
rr e
ld h,b
ld l,c
or a
sbc hl,de
push hl
ld b,(iy+x0h)
ld c,(iy+x0l)
ld d,(iy+rh)
ld e,(iy+rlv)
ld h,b
ld l,c
or a
sbc hl,de
pop de
call do_w_plot ; (-r,-cx)
ld b,(iy+cxh)
ld c,(iy+cxl)
ld e,(iy+scale)
ld d,0
ld h,b
ld l,c
add hl,de
ld b,h
ld c,l
ld (iy+cxh),b
ld (iy+cxl),c
jp l9905
.do_w_plot
jp (ix)
| 12.507837 | 56 | 0.508271 |
64546b5d3b01016f2544b5fe4cf96d908dafcb06 | 7,898 | asm | Assembly | Transynther/x86/_processed/NONE/_xt_sm_/i7-7700_9_0xca.log_21829_1887.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 9 | 2020-08-13T19:41:58.000Z | 2022-03-30T12:22:51.000Z | Transynther/x86/_processed/NONE/_xt_sm_/i7-7700_9_0xca.log_21829_1887.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 1 | 2021-04-29T06:29:35.000Z | 2021-05-13T21:02:30.000Z | Transynther/x86/_processed/NONE/_xt_sm_/i7-7700_9_0xca.log_21829_1887.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 3 | 2020-07-14T17:07:07.000Z | 2022-03-21T01:12:22.000Z | .global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r8
push %r9
push %rax
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_UC_ht+0x11400, %r8
nop
nop
and %r9, %r9
mov (%r8), %si
nop
nop
nop
nop
nop
xor $36983, %rdx
lea addresses_normal_ht+0x2200, %rsi
lea addresses_UC_ht+0x13ab0, %rdi
clflush (%rdi)
nop
nop
nop
sub $40193, %rdx
mov $25, %rcx
rep movsq
nop
nop
dec %rcx
lea addresses_WC_ht+0x15798, %rsi
lea addresses_WT_ht+0x6430, %rdi
nop
nop
and $6143, %r9
mov $20, %rcx
rep movsb
nop
nop
xor %rdi, %rdi
lea addresses_A_ht+0x7ee8, %rdi
nop
nop
nop
nop
nop
inc %r11
movb $0x61, (%rdi)
nop
nop
nop
sub %rdx, %rdx
lea addresses_D_ht+0x70d0, %rcx
nop
nop
nop
sub %rdi, %rdi
movw $0x6162, (%rcx)
nop
xor $18842, %rcx
lea addresses_UC_ht+0x18400, %rdi
nop
sub %r11, %r11
mov $0x6162636465666768, %r8
movq %r8, %xmm7
and $0xffffffffffffffc0, %rdi
vmovaps %ymm7, (%rdi)
nop
nop
nop
nop
nop
cmp %rsi, %rsi
lea addresses_normal_ht+0x1c430, %r9
nop
nop
nop
and %rdx, %rdx
mov (%r9), %r8w
nop
nop
nop
nop
cmp %r9, %r9
lea addresses_normal_ht+0x104f0, %rsi
nop
nop
sub $14262, %rdi
and $0xffffffffffffffc0, %rsi
vmovaps (%rsi), %ymm7
vextracti128 $1, %ymm7, %xmm7
vpextrq $0, %xmm7, %r11
nop
nop
inc %rdx
lea addresses_WC_ht+0x6385, %r9
nop
nop
xor $20546, %rdi
mov $0x6162636465666768, %rcx
movq %rcx, (%r9)
nop
add %rdi, %rdi
lea addresses_D_ht+0x1a8ed, %rcx
nop
nop
nop
xor %rdx, %rdx
movl $0x61626364, (%rcx)
nop
nop
nop
and %rdi, %rdi
lea addresses_UC_ht+0xe230, %rdx
clflush (%rdx)
nop
nop
nop
nop
nop
inc %rcx
movb $0x61, (%rdx)
nop
mfence
lea addresses_WT_ht+0x18000, %rsi
lea addresses_normal_ht+0x16630, %rdi
clflush (%rsi)
nop
inc %rax
mov $20, %rcx
rep movsw
nop
add %rdx, %rdx
lea addresses_UC_ht+0xfd60, %rsi
lea addresses_UC_ht+0x19630, %rdi
and %r8, %r8
mov $73, %rcx
rep movsb
nop
nop
nop
nop
sub $37061, %rdi
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rax
pop %r9
pop %r8
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r12
push %r13
push %r14
push %r15
push %r8
push %rdx
// Store
lea addresses_normal+0x4630, %r14
nop
nop
nop
sub %rdx, %rdx
mov $0x5152535455565758, %r12
movq %r12, %xmm0
vmovups %ymm0, (%r14)
nop
nop
and $64877, %r13
// Store
mov $0xaf2, %r15
clflush (%r15)
nop
nop
nop
nop
nop
sub $58980, %r11
mov $0x5152535455565758, %r8
movq %r8, %xmm0
vmovups %ymm0, (%r15)
nop
nop
nop
cmp %r15, %r15
// Faulty Load
lea addresses_normal+0x4630, %rdx
nop
nop
sub %r15, %r15
movb (%rdx), %r13b
lea oracles, %r15
and $0xff, %r13
shlq $12, %r13
mov (%r15,%r13,1), %r13
pop %rdx
pop %r8
pop %r15
pop %r14
pop %r13
pop %r12
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'src': {'congruent': 0, 'AVXalign': False, 'same': False, 'size': 16, 'NT': False, 'type': 'addresses_normal'}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'congruent': 0, 'AVXalign': False, 'same': True, 'size': 32, 'NT': False, 'type': 'addresses_normal'}}
{'OP': 'STOR', 'dst': {'congruent': 0, 'AVXalign': False, 'same': False, 'size': 32, 'NT': False, 'type': 'addresses_P'}}
[Faulty Load]
{'src': {'congruent': 0, 'AVXalign': False, 'same': True, 'size': 1, 'NT': False, 'type': 'addresses_normal'}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'congruent': 3, 'AVXalign': False, 'same': False, 'size': 2, 'NT': False, 'type': 'addresses_UC_ht'}, 'OP': 'LOAD'}
{'src': {'congruent': 3, 'same': False, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'dst': {'congruent': 6, 'same': False, 'type': 'addresses_UC_ht'}}
{'src': {'congruent': 0, 'same': True, 'type': 'addresses_WC_ht'}, 'OP': 'REPM', 'dst': {'congruent': 9, 'same': False, 'type': 'addresses_WT_ht'}}
{'OP': 'STOR', 'dst': {'congruent': 3, 'AVXalign': False, 'same': False, 'size': 1, 'NT': False, 'type': 'addresses_A_ht'}}
{'OP': 'STOR', 'dst': {'congruent': 3, 'AVXalign': False, 'same': False, 'size': 2, 'NT': False, 'type': 'addresses_D_ht'}}
{'OP': 'STOR', 'dst': {'congruent': 3, 'AVXalign': True, 'same': False, 'size': 32, 'NT': False, 'type': 'addresses_UC_ht'}}
{'src': {'congruent': 8, 'AVXalign': False, 'same': False, 'size': 2, 'NT': False, 'type': 'addresses_normal_ht'}, 'OP': 'LOAD'}
{'src': {'congruent': 4, 'AVXalign': True, 'same': True, 'size': 32, 'NT': False, 'type': 'addresses_normal_ht'}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'congruent': 0, 'AVXalign': False, 'same': True, 'size': 8, 'NT': False, 'type': 'addresses_WC_ht'}}
{'OP': 'STOR', 'dst': {'congruent': 0, 'AVXalign': False, 'same': False, 'size': 4, 'NT': False, 'type': 'addresses_D_ht'}}
{'OP': 'STOR', 'dst': {'congruent': 10, 'AVXalign': False, 'same': False, 'size': 1, 'NT': True, 'type': 'addresses_UC_ht'}}
{'src': {'congruent': 1, 'same': False, 'type': 'addresses_WT_ht'}, 'OP': 'REPM', 'dst': {'congruent': 10, 'same': False, 'type': 'addresses_normal_ht'}}
{'src': {'congruent': 4, 'same': True, 'type': 'addresses_UC_ht'}, 'OP': 'REPM', 'dst': {'congruent': 11, 'same': False, 'type': 'addresses_UC_ht'}}
{'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
*/
| 32.771784 | 2,999 | 0.658395 |
b22c58f7ec9a8d8e8266b88facbd234167fc1b52 | 315 | asm | Assembly | oeis/131/A131919.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 11 | 2021-08-22T19:44:55.000Z | 2022-03-20T16:47:57.000Z | oeis/131/A131919.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 9 | 2021-08-29T13:15:54.000Z | 2022-03-09T19:52:31.000Z | oeis/131/A131919.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 3 | 2021-08-22T20:56:47.000Z | 2021-09-29T06:26:12.000Z | ; A131919: A002024 + A131821 - A000012.
; Submitted by Jamie Morken(s4.)
; 1,3,3,5,3,5,7,4,4,7,9,5,5,5,9,11,6,6,6,6,11,13,7,7,7,7,7,13,15,8,8,8,8,8,8,15,17,9,9,9,9,9,9,9,17,19,10,10,10,10,10,10,10,10,19
lpb $0
mov $1,$0
add $2,1
sub $0,$2
mod $1,$2
cmp $1,0
add $1,1
mul $1,$2
lpe
add $1,1
mov $0,$1
| 19.6875 | 129 | 0.561905 |
8e878002847b7a9c652223ed2e694c622adcce5e | 116 | asm | Assembly | libsrc/_DEVELOPMENT/math/float/math48/lm/z80/asm_dequate.asm | jpoikela/z88dk | 7108b2d7e3a98a77de99b30c9a7c9199da9c75cb | [
"ClArtistic"
] | 640 | 2017-01-14T23:33:45.000Z | 2022-03-30T11:28:42.000Z | libsrc/_DEVELOPMENT/math/float/math48/lm/z80/asm_dequate.asm | jpoikela/z88dk | 7108b2d7e3a98a77de99b30c9a7c9199da9c75cb | [
"ClArtistic"
] | 1,600 | 2017-01-15T16:12:02.000Z | 2022-03-31T12:11:12.000Z | libsrc/_DEVELOPMENT/math/float/math48/lm/z80/asm_dequate.asm | jpoikela/z88dk | 7108b2d7e3a98a77de99b30c9a7c9199da9c75cb | [
"ClArtistic"
] | 215 | 2017-01-17T10:43:03.000Z | 2022-03-23T17:25:02.000Z |
SECTION code_clib
SECTION code_fp_math48
PUBLIC asm_dequate
EXTERN am48_dequate
defc asm_dequate = am48_dequate
| 11.6 | 31 | 0.853448 |
465cb479f4e60aeb807a0fa299a0c24e62a992c5 | 1,220 | asm | Assembly | mvs/asm/fss/svc.asm | mvslovers/mvsclib | b6efbcefb46ee7fcb5c4d741c3ed93bd02353b44 | [
"MIT"
] | null | null | null | mvs/asm/fss/svc.asm | mvslovers/mvsclib | b6efbcefb46ee7fcb5c4d741c3ed93bd02353b44 | [
"MIT"
] | null | null | null | mvs/asm/fss/svc.asm | mvslovers/mvsclib | b6efbcefb46ee7fcb5c4d741c3ed93bd02353b44 | [
"MIT"
] | null | null | null | ********************************************
* struct REGS
* {
* unsigned int R0;
* unsigned int R1;
* unsigned int R15;
* };
* void EXSVC(int svc, struct REGS *regs);
********************************************
COPY PDPTOP
CSECT
* Program text area
DS 0F
* X-func EXSVC prologue
EXSVC PDPPRLG CINDEX=0,FRAME=88,BASER=12,ENTRY=YES
B @@FEN0
LTORG
@@FEN0 EQU *
DROP 12
BALR 12,0
USING *,12
@@PG0 EQU *
LR 11,1
L 10,=A(@@PGT0)
* Function EXSVC code
* Initialize registers
L 2,0(11) * svc
L 3,4(11) * regs
L 0,0(3) * regs->R0
L 1,4(3) * regs->R1
L 15,8(3) * regs->R15
* Execute service
EX 2,DOSVC
* Return registers
ST 0,0(3) * regs->R0
ST 1,4(3) * regs->R1
ST 15,8(3) * regs->R15
L 15,0
* Function EXSVC epilogue
PDPEPIL
* Function EXSVC literal pool
DS 0F
LTORG
DS 0F
DOSVC SVC 0 * Executed Instruction
* Function EXSVC page table
DS 0F
@@PGT0 EQU *
DC A(@@PG0)
END
| 23.921569 | 53 | 0.429508 |
9587977f5bb3c4bb14f47623692be2596a9a46dd | 60 | asm | Assembly | audio/sfx/cymbal1_3.asm | adhi-thirumala/EvoYellow | 6fb1b1d6a1fa84b02e2d982f270887f6c63cdf4c | [
"Unlicense"
] | 16 | 2018-08-28T21:47:01.000Z | 2022-02-20T20:29:59.000Z | audio/sfx/cymbal1_3.asm | adhi-thirumala/EvoYellow | 6fb1b1d6a1fa84b02e2d982f270887f6c63cdf4c | [
"Unlicense"
] | 5 | 2019-04-03T19:53:11.000Z | 2022-03-11T22:49:34.000Z | audio/sfx/cymbal1_3.asm | adhi-thirumala/EvoYellow | 6fb1b1d6a1fa84b02e2d982f270887f6c63cdf4c | [
"Unlicense"
] | 2 | 2019-12-09T19:46:02.000Z | 2020-12-05T21:36:30.000Z | SFX_Cymbal1_3_Ch1:
unknownnoise0x20 0, 161, 16
endchannel
| 15 | 28 | 0.816667 |
671090beb14b3f7a0be9421f4f77d6dfed43a412 | 52 | asm | Assembly | 01-bootsector-barebones/boot_sect_simple.asm | shambhu047/sample-os | f8112002c2911bad206e5d512599a84ff275ee02 | [
"MIT"
] | 17 | 2015-05-29T08:59:30.000Z | 2020-09-22T11:19:15.000Z | 01-bootsector-barebones/boot_sect_simple.asm | shambhu047/sample-os | f8112002c2911bad206e5d512599a84ff275ee02 | [
"MIT"
] | null | null | null | 01-bootsector-barebones/boot_sect_simple.asm | shambhu047/sample-os | f8112002c2911bad206e5d512599a84ff275ee02 | [
"MIT"
] | 5 | 2016-05-29T19:17:20.000Z | 2019-11-13T09:58:19.000Z | loop:
jmp loop
times 510-($-$$) db 0
dw 0xaa55
| 8.666667 | 21 | 0.576923 |
6a482fad6f0ba334541a350ab9040099fb33cdb1 | 969 | asm | Assembly | data/pokemon/base_stats/sentret.asm | AtmaBuster/pokeplat-gen2 | fa83b2e75575949b8f72cb2c48f7a1042e97f70f | [
"blessing"
] | 6 | 2021-06-19T06:41:19.000Z | 2022-02-15T17:12:33.000Z | data/pokemon/base_stats/sentret.asm | AtmaBuster/pokeplat-gen2-old | 01e42c55db5408d72d89133dc84a46c699d849ad | [
"blessing"
] | null | null | null | data/pokemon/base_stats/sentret.asm | AtmaBuster/pokeplat-gen2-old | 01e42c55db5408d72d89133dc84a46c699d849ad | [
"blessing"
] | 2 | 2021-08-11T19:47:07.000Z | 2022-01-01T07:07:56.000Z | db 0 ; species ID placeholder
db 35, 46, 34, 20, 35, 45
; hp atk def spd sat sdf
db NORMAL, NORMAL ; type
db 255 ; catch rate
db 57 ; base exp
db NO_ITEM, BERRY ; items
db GENDER_F50 ; gender ratio
db 15 ; step cycles to hatch
INCBIN "gfx/pokemon/sentret/front.dimensions"
db GROWTH_MEDIUM_FAST ; growth rate
dn EGG_GROUND, EGG_GROUND ; egg groups
db 70 ; happiness
; tm/hm learnset
tmhm FOCUS_PUNCH, WATER_PULSE, TOXIC, HIDDEN_POWER, SUNNY_DAY, ICE_BEAM, PROTECT, RAIN_DANCE, FRUSTRATION, SOLARBEAM, IRON_TAIL, THUNDERBOLT, RETURN, DIG, SHADOW_BALL, BRICK_BREAK, DOUBLE_TEAM, SHOCK_WAVE, FLAMETHROWER, FACADE, SECRET_POWER, REST, ATTRACT, THIEF, FLING, CHARGE_BEAM, ENDURE, SHADOW_CLAW, CAPTIVATE, SLEEP_TALK, NATURAL_GIFT, GRASS_KNOT, SWAGGER, U_TURN, SUBSTITUTE, CUT, SURF, AQUA_TAIL, FIRE_PUNCH, FURY_CUTTER, HELPING_HAND, ICE_PUNCH, KNOCK_OFF, LAST_RESORT, MUD_SLAP, ROLLOUT, SNORE, SUCKER_PUNCH, SWIFT, THUNDERPUNCH, UPROAR
; end
| 48.45 | 548 | 0.755418 |
8f5ffde9fffea9a850d3b6d4244910f1e8d2514b | 578 | asm | Assembly | tools/gdcc_acc/lib/src/libc/ZDACS/defs.asm | SpencerBelleau/EZDoomJukebox | 6514bec88d8c0433a28e6d724bf27f4dd4527ebb | [
"MIT"
] | null | null | null | tools/gdcc_acc/lib/src/libc/ZDACS/defs.asm | SpencerBelleau/EZDoomJukebox | 6514bec88d8c0433a28e6d724bf27f4dd4527ebb | [
"MIT"
] | null | null | null | tools/gdcc_acc/lib/src/libc/ZDACS/defs.asm | SpencerBelleau/EZDoomJukebox | 6514bec88d8c0433a28e6d724bf27f4dd4527ebb | [
"MIT"
] | null | null | null | ;;-----------------------------------------------------------------------------
;;
;; Copyright(C) 2017 David Hill
;;
;; See COPYLIB for license information.
;;
;;-----------------------------------------------------------------------------
;;
;; ZDACS definitions
;;
;;-----------------------------------------------------------------------------
;;----------------------------------------------------------------------------|
;; Glyphs |
;;
Glyph "___MathRegSize" type=Fixed(32, 0, 0, 0) value=1
;; EOF
| 26.272727 | 79 | 0.204152 |
a7c35d5439f290f05ce7dbdc2f40483057a3f975 | 203 | asm | Assembly | mc-sema/validator/x86/tests/FDIVR_ST0Fr.asm | randolphwong/mcsema | eb5b376736e7f57ff0a61f7e4e5a436bbb874720 | [
"BSD-3-Clause"
] | 2 | 2021-08-07T16:21:29.000Z | 2021-11-17T10:58:37.000Z | mc-sema/validator/x86/tests/FDIVR_ST0Fr.asm | randolphwong/mcsema | eb5b376736e7f57ff0a61f7e4e5a436bbb874720 | [
"BSD-3-Clause"
] | null | null | null | mc-sema/validator/x86/tests/FDIVR_ST0Fr.asm | randolphwong/mcsema | eb5b376736e7f57ff0a61f7e4e5a436bbb874720 | [
"BSD-3-Clause"
] | null | null | null | BITS 32
;TEST_FILE_META_BEGIN
;TEST_TYPE=TEST_F
;TEST_IGNOREFLAGS=
;TEST_FILE_META_END
; set up st0 to be 3.141593
FLDPI
FLD1
FLD1
;TEST_BEGIN_RECORDING
FDIVR st0, st2
mov edi, 0
;TEST_END_RECORDING
| 11.277778 | 27 | 0.802956 |
c589738e431de399c83d6bdd7b567da6b6f4d09e | 360 | asm | Assembly | programs/oeis/063/A063247.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | 1 | 2021-03-15T11:38:20.000Z | 2021-03-15T11:38:20.000Z | programs/oeis/063/A063247.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | null | null | null | programs/oeis/063/A063247.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | null | null | null | ; A063247: Dimension of the space of weight 2n cuspidal newforms for Gamma_0( 100 ).
; 1,5,8,11,14,18,20,24,27,30,33,37,39,43,46,49,52,56,58,62,65,68,71,75,77,81,84,87,90,94,96,100,103,106,109,113,115,119,122,125,128,132,134,138,141,144,147,151,153,157
mov $1,$0
mov $3,$0
div $3,3
mov $4,$0
div $0,2
add $3,$0
sub $1,$3
add $1,1
mov $2,$4
mul $2,3
add $1,$2
| 24 | 167 | 0.655556 |
a2e25c1ed7fcb8671e47cbf3d80025887316c732 | 754 | asm | Assembly | oeis/125/A125131.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 11 | 2021-08-22T19:44:55.000Z | 2022-03-20T16:47:57.000Z | oeis/125/A125131.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 9 | 2021-08-29T13:15:54.000Z | 2022-03-09T19:52:31.000Z | oeis/125/A125131.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 3 | 2021-08-22T20:56:47.000Z | 2021-09-29T06:26:12.000Z | ; A125131: Product 1-p, where p ranges over the prime factors of n with multiplicity.
; Submitted by Jon Maiga
; 1,-1,-2,1,-4,2,-6,-1,4,4,-10,-2,-12,6,8,1,-16,-4,-18,-4,12,10,-22,2,16,12,-8,-6,-28,-8,-30,-1,20,16,24,4,-36,18,24,4,-40,-12,-42,-10,-16,22,-46,-2,36,-16,32,-12,-52,8,40,6,36,28,-58,8,-60,30,-24,1,48,-20,-66,-16,44,-24,-70,-4,-72,36,-32,-18,60,-24,-78,-4,16,40,-82,12,64,42,56,10,-88,16,72,-22,60,46,72,2,-96,-36,-40,16
add $0,1
mov $1,1
lpb $0
mov $3,$0
lpb $3
mov $4,$0
mov $6,$2
cmp $6,0
add $2,$6
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 $5,-1
lpb $0
dif $0,$2
mul $5,$2
div $2,2
lpe
add $5,1
mul $1,$5
lpe
mov $0,$1
| 22.848485 | 321 | 0.51061 |
bd44cd507ff66edb8ea1b7739d4db9ec94c83425 | 371 | asm | Assembly | programs/oeis/117/A117573.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | null | null | null | programs/oeis/117/A117573.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | null | null | null | programs/oeis/117/A117573.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | null | null | null | ; A117573: Expansion of (1+2x^2)/((1-x)(1-x^2)(1-x^3)).
; 1,1,4,5,8,11,15,18,24,28,34,40,47,53,62,69,78,87,97,106,118,128,140,152,165,177,192,205,220,235,251,266,284,300,318,336,355,373,394,413,434,455,477,498,522,544,568,592,617,641,668
mov $2,$0
add $2,1
lpb $2,1
add $1,1
trn $2,2
mov $3,2
mov $4,$2
lpb $4,1
add $1,3
trn $4,$3
lpe
trn $2,1
lpe
| 21.823529 | 181 | 0.592992 |
9c7a777ebeb0b7259322ca694429954f4340dbf6 | 1,600 | asm | Assembly | unittests/ASM/H0F38/66_40.asm | cobalt2727/FEX | 13087f8425aeaad28dc81bed46a83e1d72ff0db8 | [
"MIT"
] | 628 | 2020-03-06T14:01:32.000Z | 2022-03-31T06:35:14.000Z | unittests/ASM/H0F38/66_40.asm | cobalt2727/FEX | 13087f8425aeaad28dc81bed46a83e1d72ff0db8 | [
"MIT"
] | 576 | 2020-03-06T08:25:12.000Z | 2022-03-30T04:05:29.000Z | unittests/ASM/H0F38/66_40.asm | cobalt2727/FEX | 13087f8425aeaad28dc81bed46a83e1d72ff0db8 | [
"MIT"
] | 38 | 2020-03-07T06:10:00.000Z | 2022-03-29T09:27:36.000Z | %ifdef CONFIG
{
"RegData": {
"XMM1": ["0x7a84d3fa541ef1be", "0x5f0d7667e4d8e24a"],
"XMM2": ["0x44683c4ce9ac9780", "0x9da95e9a6f25ef94"],
"XMM3": ["0x4bc94ea0ccb0a64c", "0x3cf36ee04f371510"],
"XMM4": ["0x1ac415407b8ba3db", "0x92cdc300dab0773c"],
"XMM5": ["0x6796b1563f8d578c", "0x4c64f16199291fe4"],
"XMM6": ["0x01a14ef664207dc6", "0x1d3220da400e1027"],
"XMM7": ["0x75ddba582c3dd348", "0xa5141c506d8c60d7"],
"XMM8": ["0x7873ff38fb240e0d", "0x6c154f1adb67cd17"]
}
}
%endif
lea rdx, [rel .data]
movaps xmm1, [rdx + 16 * 0]
movaps xmm2, [rdx + 16 * 1]
movaps xmm3, [rdx + 16 * 2]
movaps xmm4, [rdx + 16 * 3]
movaps xmm5, [rdx + 16 * 4]
movaps xmm6, [rdx + 16 * 5]
movaps xmm7, [rdx + 16 * 6]
movaps xmm8, [rdx + 16 * 7]
pmulld xmm1, [rdx + 16 * 8]
pmulld xmm2, [rdx + 16 * 9]
pmulld xmm3, [rdx + 16 * 10]
pmulld xmm4, [rdx + 16 * 11]
pmulld xmm5, [rdx + 16 * 12]
pmulld xmm6, [rdx + 16 * 13]
pmulld xmm7, [rdx + 16 * 14]
pmulld xmm8, [rdx + 16 * 15]
hlt
align 16
; 256bytes of random data
.data:
dd 655.9708,532.2244,108.0451,512.4019,754.227,586.0859,127.7574,114.8167,764.4266,226.6145,337.864,320.3296,296.5247,480.0057,28.4267,565.9418,265.8255,536.4473,754.3489,460.681,818.7269,43.7204,464.592,847.9381,306.0592,702.7584,887.6473,551.5908,620.9001,520.9829,232.9532,510.3388,204.8474,225.626,564.973,790.5175,836.1953,844.5266,633.5626,501.7409,393.2616,674.4415,244.3265,971.1598,770.8029,746.1836,255.9902,567.7578,187.7175,924.181,466.4362,169.8267,651.7481,462.4206,396.6924,355.8538,6.148,523.1443,989.7004,713.6646,497.5427,657.6965,651.0534,778.5236
| 38.095238 | 566 | 0.68125 |
0817cbf642ce77a8870fb40798420217c2a8cf30 | 562 | asm | Assembly | oeis/019/A019683.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 11 | 2021-08-22T19:44:55.000Z | 2022-03-20T16:47:57.000Z | oeis/019/A019683.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 9 | 2021-08-29T13:15:54.000Z | 2022-03-09T19:52:31.000Z | oeis/019/A019683.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 3 | 2021-08-22T20:56:47.000Z | 2021-09-29T06:26:12.000Z | ; A019683: Decimal expansion of Pi/16.
; Submitted by Jon Maiga
; 1,9,6,3,4,9,5,4,0,8,4,9,3,6,2,0,7,7,4,0,3,9,1,5,2,1,1,4,5,4,9,6,8,9,3,0,2,6,2,3,2,3,0,8,7,4,6,0,9,4,4,1,1,3,8,1,0,9,3,4,0,3,7,0,1,9,2,3,8,5,2,5,3,9,2,8,8,8,0,6,2,4,1,4,2,5,2,1,7,6,5,8,3,8,8,2,3,1,6,7
mov $2,1
mov $3,$0
mul $3,5
lpb $3
mul $1,$3
mov $5,$3
mul $5,2
add $5,1
mul $2,$5
add $1,$2
cmp $4,0
mov $5,$0
add $5,$4
div $1,$5
div $2,$5
sub $3,1
lpe
mul $1,2
div $1,8
div $2,5
mov $6,10
pow $6,$0
div $2,$6
cmp $4,0
add $2,$4
div $1,$2
add $1,$6
mov $0,$1
mod $0,10
| 16.529412 | 201 | 0.519573 |
e5aaae0f71bedffc77f05a3af405a4fdef8f0c09 | 767 | asm | Assembly | oeis/010/A010923.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 11 | 2021-08-22T19:44:55.000Z | 2022-03-20T16:47:57.000Z | oeis/010/A010923.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 9 | 2021-08-29T13:15:54.000Z | 2022-03-09T19:52:31.000Z | oeis/010/A010923.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 3 | 2021-08-22T20:56:47.000Z | 2021-09-29T06:26:12.000Z | ; A010923: Shallit sequence S(14,23), a(n)=[ a(n-1)^2/a(n-2)+1 ].
; Submitted by Christian Krause
; 14,23,38,63,105,176,296,498,838,1411,2376,4001,6738,11348,19113,32192,54221,91325,153820,259082,436377,734999,1237975,2085149,3512064,5915450,9963529,16781802,28265977,47609039,80189006,135064199,227491757,383169633,645381484,1087030976,1830911441,3083846532,5194194116,8748701414,14735640356,24819580236,41804193657,70411771299,118596176694,199754286350,336450769557,566691821257,954492155576,1607673237697,2707841257897,4560879727322,7681995326142,12938962594727,21793394283647,36707118590486
mov $2,1
mov $4,2
lpb $4
mov $1,14
mov $3,8
mov $4,1
lpb $0
sub $0,1
div $3,$2
mov $2,$1
add $3,$4
add $1,$3
mul $3,$1
lpe
lpe
mov $0,$1
| 36.52381 | 496 | 0.752282 |
e4e757e14b778a6d2caa04eec5ada5326666975d | 354 | asm | Assembly | oeis/098/A098497.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 11 | 2021-08-22T19:44:55.000Z | 2022-03-20T16:47:57.000Z | oeis/098/A098497.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 9 | 2021-08-29T13:15:54.000Z | 2022-03-09T19:52:31.000Z | oeis/098/A098497.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 3 | 2021-08-22T20:56:47.000Z | 2021-09-29T06:26:12.000Z | ; A098497: Main diagonal of triangle A098495.
; Submitted by Jon Maiga
; 1,-1,1,-7,76,-989,15289,-275807,5702887,-133121449,3464398070,-99482086439,3125039826481,-106610733533317,3925411300203301,-155161278879431551,6553471162481684656
add $0,1
mov $1,1
mov $2,$0
mov $4,1
lpb $0
sub $0,1
sub $1,$4
mov $3,$2
mul $3,$1
add $4,$3
lpe
mov $0,$4
| 20.823529 | 164 | 0.706215 |
b0d88ec6197880f7869f3c4c0bc7b91611056ce5 | 237 | asm | Assembly | programs/oeis/182/A182258.asm | neoneye/loda | afe9559fb53ee12e3040da54bd6aa47283e0d9ec | [
"Apache-2.0"
] | 22 | 2018-02-06T19:19:31.000Z | 2022-01-17T21:53:31.000Z | programs/oeis/182/A182258.asm | neoneye/loda | afe9559fb53ee12e3040da54bd6aa47283e0d9ec | [
"Apache-2.0"
] | 41 | 2021-02-22T19:00:34.000Z | 2021-08-28T10:47:47.000Z | programs/oeis/182/A182258.asm | neoneye/loda | afe9559fb53ee12e3040da54bd6aa47283e0d9ec | [
"Apache-2.0"
] | 5 | 2021-02-24T21:14:16.000Z | 2021-08-09T19:48:05.000Z | ; A182258: Least number k such that there exist a simple graph on k vertices having precisely n spanning trees.
; 3,4,5,6,7,4,5,10,5,5,13
mov $2,$0
lpb $2
lpb $0
sub $2,4
mov $0,$2
sub $2,1
mul $2,2
lpe
lpe
add $0,3
| 16.928571 | 111 | 0.616034 |
c0dc04e5b36472f343e65ffd2a78cd99f760bae5 | 8,727 | asm | Assembly | Appl/Test/KernelErrorTest/kerr.asm | steakknife/pcgeos | 95edd7fad36df400aba9bab1d56e154fc126044a | [
"Apache-2.0"
] | 504 | 2018-11-18T03:35:53.000Z | 2022-03-29T01:02:51.000Z | Appl/Test/KernelErrorTest/kerr.asm | steakknife/pcgeos | 95edd7fad36df400aba9bab1d56e154fc126044a | [
"Apache-2.0"
] | 96 | 2018-11-19T21:06:50.000Z | 2022-03-06T10:26:48.000Z | Appl/Test/KernelErrorTest/kerr.asm | steakknife/pcgeos | 95edd7fad36df400aba9bab1d56e154fc126044a | [
"Apache-2.0"
] | 73 | 2018-11-19T20:46:53.000Z | 2022-03-29T00:59:26.000Z | COMMENT @----------------------------------------------------------------------
Copyright (c) Berkeley Softworks 1988 -- All Rights Reserved
PROJECT: PC GEOS
MODULE: kerr
FILE: app.asm
REVISION HISTORY:
Name Date Description
---- ---- -----------
Tony 2/89 Initial version
DESCRIPTION:
This file contains a kerr application
$Id: kerr.asm,v 1.1 97/04/04 16:58:23 newdeal Exp $
------------------------------------------------------------------------------@
;
; Standard include files
;
include geos.def
include heap.def
include geode.def
include resource.def
include ec.def
include system.def
include object.def
include graphics.def
include win.def
include lmem.def
include timer.def
include Objects/processC.def ; need for ui.def
include localize.def ; for Resources file
;------------------------------------------------------------------------------
; Libraries used
;------------------------------------------------------------------------------
UseLib ui.def
;------------------------------------------------------------------------------
; Resource Definitions
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Macros
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Constants
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Definitions
;------------------------------------------------------------------------------
kerr_ProcessClass class GenProcessClass
MSG_KERR_HANDLE_TABLE_FULL message
MSG_KERR_LOW_ON_HANDLES message
MSG_KERR_ILLEGAL_HANDLE message
MSG_KERR_FATAL_ERROR message
MSG_KERR_UNRECOVERABLE_ERROR message
MSG_KERR_MEMORY_FULL message
MSG_KERR_DIVIDE_0 message
MSG_KERR_OVERFLOW message
MSG_KERR_BOUND message
MSG_KERR_FPU message
MSG_KERR_SINGLE_STEP message
MSG_KERR_ILLEGAL_INSTRUNCTION message
MSG_KERR_PROTECTION_FAULT message
MSG_KERR_STACK_EXCEPTION message
MSG_KERR_DIVIDE_0_REAL message
MSG_KERR_OVERFLOW_REAL message
MSG_KERR_BOUND_REAL message
MSG_KERR_SINGLE_STEP_REAL message
MSG_KERR_BREAKPOINT_REAL message
MSG_KERR_ILLEGAL_INSTRUCTION_REAL message
MSG_KERR_PROTECTION_FAULT_REAL message
MSG_KERR_STACK_EXCEPTION_REAL message
MSG_KERR_SET_NOTIFY_FLAGS message
; cx = new SysNotifyFlags
MSG_KERR_SYS_NOTIFY_1 message
MSG_KERR_SYS_NOTIFY_2 message
kerr_ProcessClass endc
;------------------------------------------------------------------------------
; Resources
;------------------------------------------------------------------------------
include kerr.rdef
;------------------------------------------------------------------------------
; Variables
;------------------------------------------------------------------------------
idata segment
kerr_ProcessClass mask CLASSF_NEVER_SAVED
idata ends
;------------------------------------------------------------------------------
; Code
;------------------------------------------------------------------------------
CommonCode segment resource
;---
KerrHandleTableFull method dynamic kerr_ProcessClass,
MSG_KERR_HANDLE_TABLE_FULL
mov bx, handle 0
mov ax, MSG_META_DUMMY
deathLoop:
mov di, mask MF_FORCE_QUEUE
call ObjMessage
jmp deathLoop
KerrHandleTableFull endm
;---
KerrLowOnHandles method dynamic kerr_ProcessClass,
MSG_KERR_LOW_ON_HANDLES
mov bx, handle 0
mov ax, MSG_META_DUMMY
lowLoop:
mov di, mask MF_CAN_DISCARD_IF_DESPERATE or mask MF_FORCE_QUEUE
call ObjMessage
jnc lowLoop
ret
KerrLowOnHandles endm
;---
KerrIllegalHandle method dynamic kerr_ProcessClass,
MSG_KERR_ILLEGAL_HANDLE
mov bx, 0x1234
call MemLock
ret
KerrIllegalHandle endm
;---
KerrFatalError method dynamic kerr_ProcessClass, MSG_KERR_FATAL_ERROR
ERROR 0x1234
KerrFatalError endm
;---
KerrUnrecoverableError method dynamic kerr_ProcessClass,
MSG_KERR_UNRECOVERABLE_ERROR
mov dx, offset fooFile
mov al, FileAccessFlags <FE_EXCLUSIVE,FA_READ_WRITE>
mov ah, FILE_CREATE_TRUNCATE
clr cx
call FileCreate ;ax = handle
mov bx, ax
mov al, FILE_NO_ERRORS
mov cx, 1000
call FileRead
ret
KerrUnrecoverableError endm
idata segment
fooFile char "foo",0
idata ends
;---
KerrMemoryFull method dynamic kerr_ProcessClass, MSG_KERR_MEMORY_FULL
deathLoop:
mov ax, 20000
mov cx, ALLOC_FIXED or (mask HAF_NO_ERR shl 8)
call MemAlloc
jmp deathLoop
KerrMemoryFull endm
;---
KerrDivide0 method dynamic kerr_ProcessClass, MSG_KERR_DIVIDE_0
int 0
ret
KerrDivide0 endm
;---
KerrOverflow method dynamic kerr_ProcessClass, MSG_KERR_OVERFLOW
int 4
ret
KerrOverflow endm
;---
KerrBound method dynamic kerr_ProcessClass, MSG_KERR_BOUND
int 5
ret
KerrBound endm
;---
KerrFPU method dynamic kerr_ProcessClass, MSG_KERR_FPU
int 2
ret
KerrFPU endm
;---
KerrSingleStep method dynamic kerr_ProcessClass, MSG_KERR_SINGLE_STEP
int 1
ret
KerrSingleStep endm
;---
KerrIllegalInstrunction method dynamic kerr_ProcessClass,
MSG_KERR_ILLEGAL_INSTRUNCTION
int 6
ret
KerrIllegalInstrunction endm
;---
KerrProtectionFault method dynamic kerr_ProcessClass,
MSG_KERR_PROTECTION_FAULT
int 13
ret
KerrProtectionFault endm
;---
KerrStackException method dynamic kerr_ProcessClass,
MSG_KERR_STACK_EXCEPTION
int 12
ret
KerrStackException endm
;---
KerrDivide0Real method dynamic kerr_ProcessClass, MSG_KERR_DIVIDE_0_REAL
clr cl
div cl
ret
KerrDivide0Real endm
;---
KerrOverflowReal method dynamic kerr_ProcessClass,
MSG_KERR_OVERFLOW_REAL
mov al, 40h
shl al ; OF set
into
ret
KerrOverflowReal endm
;---
bounds sword 1, 2
KerrBoundReal method dynamic kerr_ProcessClass, MSG_KERR_BOUND_REAL
clr ax
bound ax, cs:[bounds]
ret
KerrBoundReal endm
;---
KerrSingleStepReal method dynamic kerr_ProcessClass,
MSG_KERR_SINGLE_STEP_REAL
pushf
pop ax
BitSet ax, CPU_TRAP
push ax
popf
nop
ret
KerrSingleStepReal endm
;---
KerrBreakpointReal method dynamic kerr_ProcessClass,
MSG_KERR_BREAKPOINT_REAL
nop
int 3
ret
KerrBreakpointReal endm
;---
KerrIllegalInstructionReal method dynamic kerr_ProcessClass,
MSG_KERR_ILLEGAL_INSTRUCTION_REAL
; "LOCK CMP AX, AX", illegal prefix use for this instruction. This
; raises an exception only on 386 processors or above.
.inst db 0xf0 | cmp ax, ax
ret
KerrIllegalInstructionReal endm
;---
KerrProtectionFaultReal method dynamic kerr_ProcessClass,
MSG_KERR_PROTECTION_FAULT_REAL
; Operand crossing offset 65536, using general segment reg. (This
; might not cause a fault to us if HIMEM.SYS is loaded but EMM386.EXE
; is not. I don't know why.)
segmov ds, 0x8000 ; just somewhere such that ds:0xffff
; is valid as far as the processor
; is concerned.
mov ax, {word} ds:[0xffff]
; Instruction longer than 15 bytes. Here we use 12 LOCK prefixes,
; plus a 4-byte instruction which by itself is a valid instruction
; to be used with LOCK and accesses valid memory. (This causes a
; fault to us even when HIMEM.SYS is loaded.)
mov bp, sp
.inst db 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
0xf0, 0xf0, 0xf0, 0xf0
or {byte} ss:[bp], 0 ; 4 bytes
ret
KerrProtectionFaultReal endm
;---
KerrStackExceptionReal method dynamic kerr_ProcessClass,
MSG_KERR_STACK_EXCEPTION_REAL
; Operand crossing offset 65536, using stack segment reg. (This
; might not cause a fault to us if HIMEM.SYS is loaded.)
mov ax, {word} ss:[0xffff]
ret
KerrStackExceptionReal endm
;---
udata segment
notifyFlags SysNotifyFlags <>
udata ends
idata segment
string1 char "String # 1", 0
string2 char "String # 2", 0
idata ends
KerrSetNotifyFlags method dynamic kerr_ProcessClass,
MSG_KERR_SET_NOTIFY_FLAGS
mov ds:[notifyFlags], cx
ret
KerrSetNotifyFlags endm
KerrSysNotify1 method dynamic kerr_ProcessClass,
MSG_KERR_SYS_NOTIFY_1
mov ax, ds:[notifyFlags]
mov si, offset string1
clr di
call SysNotify
ret
KerrSysNotify1 endm
KerrSysNotify2 method dynamic kerr_ProcessClass,
MSG_KERR_SYS_NOTIFY_2
mov ax, ds:[notifyFlags]
mov si, offset string1
mov di, offset string2
call SysNotify
ret
KerrSysNotify2 endm
CommonCode ends
end
| 21.87218 | 80 | 0.621061 |
9435cf2be16f5966a21dce63a1adbf01e016d524 | 353 | asm | Assembly | libsrc/math/mbf32/c/sccz80/sqrt.asm | ahjelm/z88dk | c4de367f39a76b41f6390ceeab77737e148178fa | [
"ClArtistic"
] | 640 | 2017-01-14T23:33:45.000Z | 2022-03-30T11:28:42.000Z | libsrc/math/mbf32/c/sccz80/sqrt.asm | C-Chads/z88dk | a4141a8e51205c6414b4ae3263b633c4265778e6 | [
"ClArtistic"
] | 1,600 | 2017-01-15T16:12:02.000Z | 2022-03-31T12:11:12.000Z | libsrc/math/mbf32/c/sccz80/sqrt.asm | C-Chads/z88dk | a4141a8e51205c6414b4ae3263b633c4265778e6 | [
"ClArtistic"
] | 215 | 2017-01-17T10:43:03.000Z | 2022-03-23T17:25:02.000Z |
SECTION code_fp_mbf32
PUBLIC sqrt
EXTERN ___mbf32_setup_single
EXTERN ___mbf32_SQR
EXTERN ___mbf32_return
EXTERN msbios
sqrt:
call ___mbf32_setup_single
IF __CPU_INTEL__ || __CPU_GBZ80__
call ___mbf32_SQR
ELSE
ld ix,___mbf32_SQR
call msbios
ENDIF
jp ___mbf32_return
| 18.578947 | 37 | 0.660057 |
306d60479fbb6748026079f76cb943db3c83bc5e | 372 | asm | Assembly | dv3/qlsd/respr.asm | olifink/smsqe | c546d882b26566a46d71820d1539bed9ea8af108 | [
"BSD-2-Clause"
] | null | null | null | dv3/qlsd/respr.asm | olifink/smsqe | c546d882b26566a46d71820d1539bed9ea8af108 | [
"BSD-2-Clause"
] | null | null | null | dv3/qlsd/respr.asm | olifink/smsqe | c546d882b26566a46d71820d1539bed9ea8af108 | [
"BSD-2-Clause"
] | null | null | null | ; QL-SD RESPR version initialisation 2018 M. Kilgus
section header
xdef nd_init
xref banner
xref init
include 'dev8_keys_qlv'
base
suba.l a0,a0
lea banner(pc),a1 ; Output version string
move.w ut.wtext,a2
jsr (a2)
moveq #1,d7 ; start by RESPR
bra.s init
; Doesn't make sense for RESPR version to have network code, provide stub
nd_init
rts
end
| 14.88 | 73 | 0.715054 |
1dafab3f172a777711caf6d497b3c74e4d2fd617 | 144 | asm | Assembly | other.7z/SFC.7z/SFC/ソースデータ/ヨッシーアイランド/日本_Ver2/sfc/ys_w42.asm | prismotizm/gigaleak | d082854866186a05fec4e2fdf1def0199e7f3098 | [
"MIT"
] | null | null | null | other.7z/SFC.7z/SFC/ソースデータ/ヨッシーアイランド/日本_Ver2/sfc/ys_w42.asm | prismotizm/gigaleak | d082854866186a05fec4e2fdf1def0199e7f3098 | [
"MIT"
] | null | null | null | other.7z/SFC.7z/SFC/ソースデータ/ヨッシーアイランド/日本_Ver2/sfc/ys_w42.asm | prismotizm/gigaleak | d082854866186a05fec4e2fdf1def0199e7f3098 | [
"MIT"
] | null | null | null | Name: ys_w42.asm
Type: file
Size: 18446
Last-Modified: '2016-05-13T04:51:43Z'
SHA-1: C9377154D0852F144CBB272C26653261242527F0
Description: null
| 20.571429 | 47 | 0.8125 |
4d2fb6a373c6023ca62cf6f443761a10090e8e73 | 31,717 | asm | Assembly | src/libav/libavcodec/x86/dsputil_yasm.asm | fillest/rtmp_load | 12845c868d144195688f7158eb4126c582cfdce3 | [
"MIT"
] | 10 | 2015-05-19T08:08:02.000Z | 2020-09-26T00:58:57.000Z | src/libav/libavcodec/x86/dsputil_yasm.asm | fillest/rtmp_load | 12845c868d144195688f7158eb4126c582cfdce3 | [
"MIT"
] | null | null | null | src/libav/libavcodec/x86/dsputil_yasm.asm | fillest/rtmp_load | 12845c868d144195688f7158eb4126c582cfdce3 | [
"MIT"
] | 3 | 2016-07-05T12:35:52.000Z | 2022-03-31T09:13:02.000Z | ;******************************************************************************
;* MMX optimized DSP utils
;* Copyright (c) 2008 Loren Merritt
;*
;* This file is part of Libav.
;*
;* Libav is free software; you can redistribute it and/or
;* modify it under the terms of the GNU Lesser General Public
;* License as published by the Free Software Foundation; either
;* version 2.1 of the License, or (at your option) any later version.
;*
;* Libav is distributed in the hope that it will be useful,
;* but WITHOUT ANY WARRANTY; without even the implied warranty of
;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;* Lesser General Public License for more details.
;*
;* You should have received a copy of the GNU Lesser General Public
;* License along with Libav; if not, write to the Free Software
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;******************************************************************************
%include "x86inc.asm"
%include "x86util.asm"
SECTION_RODATA
pb_f: times 16 db 15
pb_zzzzzzzz77777777: times 8 db -1
pb_7: times 8 db 7
pb_zzzz3333zzzzbbbb: db -1,-1,-1,-1,3,3,3,3,-1,-1,-1,-1,11,11,11,11
pb_zz11zz55zz99zzdd: db -1,-1,1,1,-1,-1,5,5,-1,-1,9,9,-1,-1,13,13
pb_revwords: db 14, 15, 12, 13, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3, 0, 1
pd_16384: times 4 dd 16384
SECTION_TEXT
%macro SCALARPRODUCT 1
; int scalarproduct_int16(int16_t *v1, int16_t *v2, int order, int shift)
cglobal scalarproduct_int16_%1, 3,3,4, v1, v2, order, shift
shl orderq, 1
add v1q, orderq
add v2q, orderq
neg orderq
movd m3, shiftm
pxor m2, m2
.loop:
movu m0, [v1q + orderq]
movu m1, [v1q + orderq + mmsize]
pmaddwd m0, [v2q + orderq]
pmaddwd m1, [v2q + orderq + mmsize]
paddd m2, m0
paddd m2, m1
add orderq, mmsize*2
jl .loop
%if mmsize == 16
movhlps m0, m2
paddd m2, m0
psrad m2, m3
pshuflw m0, m2, 0x4e
%else
psrad m2, m3
pshufw m0, m2, 0x4e
%endif
paddd m2, m0
movd eax, m2
RET
; int scalarproduct_and_madd_int16(int16_t *v1, int16_t *v2, int16_t *v3, int order, int mul)
cglobal scalarproduct_and_madd_int16_%1, 4,4,8, v1, v2, v3, order, mul
shl orderq, 1
movd m7, mulm
%if mmsize == 16
pshuflw m7, m7, 0
punpcklqdq m7, m7
%else
pshufw m7, m7, 0
%endif
pxor m6, m6
add v1q, orderq
add v2q, orderq
add v3q, orderq
neg orderq
.loop:
movu m0, [v2q + orderq]
movu m1, [v2q + orderq + mmsize]
mova m4, [v1q + orderq]
mova m5, [v1q + orderq + mmsize]
movu m2, [v3q + orderq]
movu m3, [v3q + orderq + mmsize]
pmaddwd m0, m4
pmaddwd m1, m5
pmullw m2, m7
pmullw m3, m7
paddd m6, m0
paddd m6, m1
paddw m2, m4
paddw m3, m5
mova [v1q + orderq], m2
mova [v1q + orderq + mmsize], m3
add orderq, mmsize*2
jl .loop
%if mmsize == 16
movhlps m0, m6
paddd m6, m0
pshuflw m0, m6, 0x4e
%else
pshufw m0, m6, 0x4e
%endif
paddd m6, m0
movd eax, m6
RET
%endmacro
INIT_MMX
SCALARPRODUCT mmx2
INIT_XMM
SCALARPRODUCT sse2
%macro SCALARPRODUCT_LOOP 1
align 16
.loop%1:
sub orderq, mmsize*2
%if %1
mova m1, m4
mova m4, [v2q + orderq]
mova m0, [v2q + orderq + mmsize]
palignr m1, m0, %1
palignr m0, m4, %1
mova m3, m5
mova m5, [v3q + orderq]
mova m2, [v3q + orderq + mmsize]
palignr m3, m2, %1
palignr m2, m5, %1
%else
mova m0, [v2q + orderq]
mova m1, [v2q + orderq + mmsize]
mova m2, [v3q + orderq]
mova m3, [v3q + orderq + mmsize]
%endif
%define t0 [v1q + orderq]
%define t1 [v1q + orderq + mmsize]
%ifdef ARCH_X86_64
mova m8, t0
mova m9, t1
%define t0 m8
%define t1 m9
%endif
pmaddwd m0, t0
pmaddwd m1, t1
pmullw m2, m7
pmullw m3, m7
paddw m2, t0
paddw m3, t1
paddd m6, m0
paddd m6, m1
mova [v1q + orderq], m2
mova [v1q + orderq + mmsize], m3
jg .loop%1
%if %1
jmp .end
%endif
%endmacro
; int scalarproduct_and_madd_int16(int16_t *v1, int16_t *v2, int16_t *v3, int order, int mul)
cglobal scalarproduct_and_madd_int16_ssse3, 4,5,10, v1, v2, v3, order, mul
shl orderq, 1
movd m7, mulm
pshuflw m7, m7, 0
punpcklqdq m7, m7
pxor m6, m6
mov r4d, v2d
and r4d, 15
and v2q, ~15
and v3q, ~15
mova m4, [v2q + orderq]
mova m5, [v3q + orderq]
; linear is faster than branch tree or jump table, because the branches taken are cyclic (i.e. predictable)
cmp r4d, 0
je .loop0
cmp r4d, 2
je .loop2
cmp r4d, 4
je .loop4
cmp r4d, 6
je .loop6
cmp r4d, 8
je .loop8
cmp r4d, 10
je .loop10
cmp r4d, 12
je .loop12
SCALARPRODUCT_LOOP 14
SCALARPRODUCT_LOOP 12
SCALARPRODUCT_LOOP 10
SCALARPRODUCT_LOOP 8
SCALARPRODUCT_LOOP 6
SCALARPRODUCT_LOOP 4
SCALARPRODUCT_LOOP 2
SCALARPRODUCT_LOOP 0
.end:
movhlps m0, m6
paddd m6, m0
pshuflw m0, m6, 0x4e
paddd m6, m0
movd eax, m6
RET
;-----------------------------------------------------------------------------
; void ff_apply_window_int16(int16_t *output, const int16_t *input,
; const int16_t *window, unsigned int len)
;-----------------------------------------------------------------------------
%macro REVERSE_WORDS_MMXEXT 1-2
pshufw %1, %1, 0x1B
%endmacro
%macro REVERSE_WORDS_SSE2 1-2
pshuflw %1, %1, 0x1B
pshufhw %1, %1, 0x1B
pshufd %1, %1, 0x4E
%endmacro
%macro REVERSE_WORDS_SSSE3 2
pshufb %1, %2
%endmacro
; dst = (dst * src) >> 15
; pmulhw cuts off the bottom bit, so we have to lshift by 1 and add it back
; in from the pmullw result.
%macro MUL16FIXED_MMXEXT 3 ; dst, src, temp
mova %3, %1
pmulhw %1, %2
pmullw %3, %2
psrlw %3, 15
psllw %1, 1
por %1, %3
%endmacro
; dst = ((dst * src) + (1<<14)) >> 15
%macro MUL16FIXED_SSSE3 3 ; dst, src, unused
pmulhrsw %1, %2
%endmacro
%macro APPLY_WINDOW_INT16 3 ; %1=instruction set, %2=mmxext/sse2 bit exact version, %3=has_ssse3
cglobal apply_window_int16_%1, 4,5,6, output, input, window, offset, offset2
lea offset2q, [offsetq-mmsize]
%if %2
mova m5, [pd_16384]
%elifidn %1, ssse3
mova m5, [pb_revwords]
ALIGN 16
%endif
.loop:
%if %2
; This version expands 16-bit to 32-bit, multiplies by the window,
; adds 16384 for rounding, right shifts 15, then repacks back to words to
; save to the output. The window is reversed for the second half.
mova m3, [windowq+offset2q]
mova m4, [ inputq+offset2q]
pxor m0, m0
punpcklwd m0, m3
punpcklwd m1, m4
pmaddwd m0, m1
paddd m0, m5
psrad m0, 15
pxor m2, m2
punpckhwd m2, m3
punpckhwd m1, m4
pmaddwd m2, m1
paddd m2, m5
psrad m2, 15
packssdw m0, m2
mova [outputq+offset2q], m0
REVERSE_WORDS m3
mova m4, [ inputq+offsetq]
pxor m0, m0
punpcklwd m0, m3
punpcklwd m1, m4
pmaddwd m0, m1
paddd m0, m5
psrad m0, 15
pxor m2, m2
punpckhwd m2, m3
punpckhwd m1, m4
pmaddwd m2, m1
paddd m2, m5
psrad m2, 15
packssdw m0, m2
mova [outputq+offsetq], m0
%elif %3
; This version does the 16x16->16 multiplication in-place without expanding
; to 32-bit. The ssse3 version is bit-identical.
mova m0, [windowq+offset2q]
mova m1, [ inputq+offset2q]
pmulhrsw m1, m0
REVERSE_WORDS m0, m5
pmulhrsw m0, [ inputq+offsetq ]
mova [outputq+offset2q], m1
mova [outputq+offsetq ], m0
%else
; This version does the 16x16->16 multiplication in-place without expanding
; to 32-bit. The mmxext and sse2 versions do not use rounding, and
; therefore are not bit-identical to the C version.
mova m0, [windowq+offset2q]
mova m1, [ inputq+offset2q]
mova m2, [ inputq+offsetq ]
MUL16FIXED m1, m0, m3
REVERSE_WORDS m0
MUL16FIXED m2, m0, m3
mova [outputq+offset2q], m1
mova [outputq+offsetq ], m2
%endif
add offsetd, mmsize
sub offset2d, mmsize
jae .loop
REP_RET
%endmacro
INIT_MMX
%define REVERSE_WORDS REVERSE_WORDS_MMXEXT
%define MUL16FIXED MUL16FIXED_MMXEXT
APPLY_WINDOW_INT16 mmxext, 0, 0
APPLY_WINDOW_INT16 mmxext_ba, 1, 0
INIT_XMM
%define REVERSE_WORDS REVERSE_WORDS_SSE2
APPLY_WINDOW_INT16 sse2, 0, 0
APPLY_WINDOW_INT16 sse2_ba, 1, 0
APPLY_WINDOW_INT16 ssse3_atom, 0, 1
%define REVERSE_WORDS REVERSE_WORDS_SSSE3
APPLY_WINDOW_INT16 ssse3, 0, 1
; void add_hfyu_median_prediction_mmx2(uint8_t *dst, const uint8_t *top, const uint8_t *diff, int w, int *left, int *left_top)
cglobal add_hfyu_median_prediction_mmx2, 6,6,0, dst, top, diff, w, left, left_top
movq mm0, [topq]
movq mm2, mm0
movd mm4, [left_topq]
psllq mm2, 8
movq mm1, mm0
por mm4, mm2
movd mm3, [leftq]
psubb mm0, mm4 ; t-tl
add dstq, wq
add topq, wq
add diffq, wq
neg wq
jmp .skip
.loop:
movq mm4, [topq+wq]
movq mm0, mm4
psllq mm4, 8
por mm4, mm1
movq mm1, mm0 ; t
psubb mm0, mm4 ; t-tl
.skip:
movq mm2, [diffq+wq]
%assign i 0
%rep 8
movq mm4, mm0
paddb mm4, mm3 ; t-tl+l
movq mm5, mm3
pmaxub mm3, mm1
pminub mm5, mm1
pminub mm3, mm4
pmaxub mm3, mm5 ; median
paddb mm3, mm2 ; +residual
%if i==0
movq mm7, mm3
psllq mm7, 56
%else
movq mm6, mm3
psrlq mm7, 8
psllq mm6, 56
por mm7, mm6
%endif
%if i<7
psrlq mm0, 8
psrlq mm1, 8
psrlq mm2, 8
%endif
%assign i i+1
%endrep
movq [dstq+wq], mm7
add wq, 8
jl .loop
movzx r2d, byte [dstq-1]
mov [leftq], r2d
movzx r2d, byte [topq-1]
mov [left_topq], r2d
RET
%macro ADD_HFYU_LEFT_LOOP 1 ; %1 = is_aligned
add srcq, wq
add dstq, wq
neg wq
%%.loop:
mova m1, [srcq+wq]
mova m2, m1
psllw m1, 8
paddb m1, m2
mova m2, m1
pshufb m1, m3
paddb m1, m2
pshufb m0, m5
mova m2, m1
pshufb m1, m4
paddb m1, m2
%if mmsize == 16
mova m2, m1
pshufb m1, m6
paddb m1, m2
%endif
paddb m0, m1
%if %1
mova [dstq+wq], m0
%else
movq [dstq+wq], m0
movhps [dstq+wq+8], m0
%endif
add wq, mmsize
jl %%.loop
mov eax, mmsize-1
sub eax, wd
movd m1, eax
pshufb m0, m1
movd eax, m0
RET
%endmacro
; int add_hfyu_left_prediction(uint8_t *dst, const uint8_t *src, int w, int left)
INIT_MMX
cglobal add_hfyu_left_prediction_ssse3, 3,3,7, dst, src, w, left
.skip_prologue:
mova m5, [pb_7]
mova m4, [pb_zzzz3333zzzzbbbb]
mova m3, [pb_zz11zz55zz99zzdd]
movd m0, leftm
psllq m0, 56
ADD_HFYU_LEFT_LOOP 1
INIT_XMM
cglobal add_hfyu_left_prediction_sse4, 3,3,7, dst, src, w, left
mova m5, [pb_f]
mova m6, [pb_zzzzzzzz77777777]
mova m4, [pb_zzzz3333zzzzbbbb]
mova m3, [pb_zz11zz55zz99zzdd]
movd m0, leftm
pslldq m0, 15
test srcq, 15
jnz add_hfyu_left_prediction_ssse3.skip_prologue
test dstq, 15
jnz .unaligned
ADD_HFYU_LEFT_LOOP 1
.unaligned:
ADD_HFYU_LEFT_LOOP 0
; float scalarproduct_float_sse(const float *v1, const float *v2, int len)
cglobal scalarproduct_float_sse, 3,3,2, v1, v2, offset
neg offsetq
shl offsetq, 2
sub v1q, offsetq
sub v2q, offsetq
xorps xmm0, xmm0
.loop:
movaps xmm1, [v1q+offsetq]
mulps xmm1, [v2q+offsetq]
addps xmm0, xmm1
add offsetq, 16
js .loop
movhlps xmm1, xmm0
addps xmm0, xmm1
movss xmm1, xmm0
shufps xmm0, xmm0, 1
addss xmm0, xmm1
%ifndef ARCH_X86_64
movd r0m, xmm0
fld dword r0m
%endif
RET
; extern void ff_emu_edge_core(uint8_t *buf, const uint8_t *src, x86_reg linesize,
; x86_reg start_y, x86_reg end_y, x86_reg block_h,
; x86_reg start_x, x86_reg end_x, x86_reg block_w);
;
; The actual function itself is below. It basically wraps a very simple
; w = end_x - start_x
; if (w) {
; if (w > 22) {
; jump to the slow loop functions
; } else {
; jump to the fast loop functions
; }
; }
;
; ... and then the same for left/right extend also. See below for loop
; function implementations. Fast are fixed-width, slow is variable-width
%macro EMU_EDGE_FUNC 0
%ifdef ARCH_X86_64
%define w_reg r10
cglobal emu_edge_core, 6, 7, 1
mov r11, r5 ; save block_h
%else
%define w_reg r6
cglobal emu_edge_core, 2, 7, 0
mov r4, r4m ; end_y
mov r5, r5m ; block_h
%endif
; start with vertical extend (top/bottom) and body pixel copy
mov w_reg, r7m
sub w_reg, r6m ; w = start_x - end_x
sub r5, r4
%ifdef ARCH_X86_64
sub r4, r3
%else
sub r4, dword r3m
%endif
cmp w_reg, 22
jg .slow_v_extend_loop
%ifdef ARCH_X86_32
mov r2, r2m ; linesize
%endif
sal w_reg, 7 ; w * 128
%ifdef PIC
lea rax, [.emuedge_v_extend_1 - (.emuedge_v_extend_2 - .emuedge_v_extend_1)]
add w_reg, rax
%else
lea w_reg, [.emuedge_v_extend_1 - (.emuedge_v_extend_2 - .emuedge_v_extend_1)+w_reg]
%endif
call w_reg ; fast top extend, body copy and bottom extend
.v_extend_end:
; horizontal extend (left/right)
mov w_reg, r6m ; start_x
sub r0, w_reg
%ifdef ARCH_X86_64
mov r3, r0 ; backup of buf+block_h*linesize
mov r5, r11
%else
mov r0m, r0 ; backup of buf+block_h*linesize
mov r5, r5m
%endif
test w_reg, w_reg
jz .right_extend
cmp w_reg, 22
jg .slow_left_extend_loop
mov r1, w_reg
dec w_reg
; FIXME we can do a if size == 1 here if that makes any speed difference, test me
sar w_reg, 1
sal w_reg, 6
; r0=buf+block_h*linesize,r10(64)/r6(32)=start_x offset for funcs
; r6(rax)/r3(ebx)=val,r2=linesize,r1=start_x,r5=block_h
%ifdef PIC
lea rax, [.emuedge_extend_left_2]
add w_reg, rax
%else
lea w_reg, [.emuedge_extend_left_2+w_reg]
%endif
call w_reg
; now r3(64)/r0(32)=buf,r2=linesize,r11/r5=block_h,r6/r3=val, r10/r6=end_x, r1=block_w
.right_extend:
%ifdef ARCH_X86_32
mov r0, r0m
mov r5, r5m
%endif
mov w_reg, r7m ; end_x
mov r1, r8m ; block_w
mov r4, r1
sub r1, w_reg
jz .h_extend_end ; if (end_x == block_w) goto h_extend_end
cmp r1, 22
jg .slow_right_extend_loop
dec r1
; FIXME we can do a if size == 1 here if that makes any speed difference, test me
sar r1, 1
sal r1, 6
%ifdef PIC
lea rax, [.emuedge_extend_right_2]
add r1, rax
%else
lea r1, [.emuedge_extend_right_2+r1]
%endif
call r1
.h_extend_end:
RET
%ifdef ARCH_X86_64
%define vall al
%define valh ah
%define valw ax
%define valw2 r10w
%define valw3 r3w
%ifdef WIN64
%define valw4 r4w
%else ; unix64
%define valw4 r3w
%endif
%define vald eax
%else
%define vall bl
%define valh bh
%define valw bx
%define valw2 r6w
%define valw3 valw2
%define valw4 valw3
%define vald ebx
%define stack_offset 0x14
%endif
%endmacro
; macro to read/write a horizontal number of pixels (%2) to/from registers
; on x86-64, - fills xmm0-15 for consecutive sets of 16 pixels
; - if (%2 & 15 == 8) fills the last 8 bytes into rax
; - else if (%2 & 8) fills 8 bytes into mm0
; - if (%2 & 7 == 4) fills the last 4 bytes into rax
; - else if (%2 & 4) fills 4 bytes into mm0-1
; - if (%2 & 3 == 3) fills 2 bytes into r10/r3, and 1 into eax
; (note that we're using r3 for body/bottom because it's a shorter
; opcode, and then the loop fits in 128 bytes)
; - else fills remaining bytes into rax
; on x86-32, - fills mm0-7 for consecutive sets of 8 pixels
; - if (%2 & 7 == 4) fills 4 bytes into ebx
; - else if (%2 & 4) fills 4 bytes into mm0-7
; - if (%2 & 3 == 3) fills 2 bytes into r6, and 1 into ebx
; - else fills remaining bytes into ebx
; writing data out is in the same way
%macro READ_NUM_BYTES 2
%assign %%src_off 0 ; offset in source buffer
%assign %%smidx 0 ; mmx register idx
%assign %%sxidx 0 ; xmm register idx
%if cpuflag(sse)
%rep %2/16
movups xmm %+ %%sxidx, [r1+%%src_off]
%assign %%src_off %%src_off+16
%assign %%sxidx %%sxidx+1
%endrep ; %2/16
%endif
%ifdef ARCH_X86_64
%if (%2-%%src_off) == 8
mov rax, [r1+%%src_off]
%assign %%src_off %%src_off+8
%endif ; (%2-%%src_off) == 8
%endif ; x86-64
%rep (%2-%%src_off)/8
movq mm %+ %%smidx, [r1+%%src_off]
%assign %%src_off %%src_off+8
%assign %%smidx %%smidx+1
%endrep ; (%2-%%dst_off)/8
%if (%2-%%src_off) == 4
mov vald, [r1+%%src_off]
%elif (%2-%%src_off) & 4
movd mm %+ %%smidx, [r1+%%src_off]
%assign %%src_off %%src_off+4
%endif ; (%2-%%src_off) ==/& 4
%if (%2-%%src_off) == 1
mov vall, [r1+%%src_off]
%elif (%2-%%src_off) == 2
mov valw, [r1+%%src_off]
%elif (%2-%%src_off) == 3
%ifidn %1, top
mov valw2, [r1+%%src_off]
%elifidn %1, body
mov valw3, [r1+%%src_off]
%elifidn %1, bottom
mov valw4, [r1+%%src_off]
%endif ; %1 ==/!= top
mov vall, [r1+%%src_off+2]
%endif ; (%2-%%src_off) == 1/2/3
%endmacro ; READ_NUM_BYTES
%macro WRITE_NUM_BYTES 2
%assign %%dst_off 0 ; offset in destination buffer
%assign %%dmidx 0 ; mmx register idx
%assign %%dxidx 0 ; xmm register idx
%if cpuflag(sse)
%rep %2/16
movups [r0+%%dst_off], xmm %+ %%dxidx
%assign %%dst_off %%dst_off+16
%assign %%dxidx %%dxidx+1
%endrep ; %2/16
%endif
%ifdef ARCH_X86_64
%if (%2-%%dst_off) == 8
mov [r0+%%dst_off], rax
%assign %%dst_off %%dst_off+8
%endif ; (%2-%%dst_off) == 8
%endif ; x86-64
%rep (%2-%%dst_off)/8
movq [r0+%%dst_off], mm %+ %%dmidx
%assign %%dst_off %%dst_off+8
%assign %%dmidx %%dmidx+1
%endrep ; (%2-%%dst_off)/8
%if (%2-%%dst_off) == 4
mov [r0+%%dst_off], vald
%elif (%2-%%dst_off) & 4
movd [r0+%%dst_off], mm %+ %%dmidx
%assign %%dst_off %%dst_off+4
%endif ; (%2-%%dst_off) ==/& 4
%if (%2-%%dst_off) == 1
mov [r0+%%dst_off], vall
%elif (%2-%%dst_off) == 2
mov [r0+%%dst_off], valw
%elif (%2-%%dst_off) == 3
%ifidn %1, top
mov [r0+%%dst_off], valw2
%elifidn %1, body
mov [r0+%%dst_off], valw3
%elifidn %1, bottom
mov [r0+%%dst_off], valw4
%endif ; %1 ==/!= top
mov [r0+%%dst_off+2], vall
%endif ; (%2-%%dst_off) == 1/2/3
%endmacro ; WRITE_NUM_BYTES
; vertical top/bottom extend and body copy fast loops
; these are function pointers to set-width line copy functions, i.e.
; they read a fixed number of pixels into set registers, and write
; those out into the destination buffer
; r0=buf,r1=src,r2=linesize,r3(64)/r3m(32)=start_x,r4=end_y,r5=block_h
; r6(eax/64)/r3(ebx/32)=val_reg
%macro VERTICAL_EXTEND 0
%assign %%n 1
%rep 22
ALIGN 128
.emuedge_v_extend_ %+ %%n:
; extend pixels above body
%ifdef ARCH_X86_64
test r3 , r3 ; if (!start_y)
jz .emuedge_copy_body_ %+ %%n %+ _loop ; goto body
%else ; ARCH_X86_32
cmp dword r3m, 0
je .emuedge_copy_body_ %+ %%n %+ _loop
%endif ; ARCH_X86_64/32
READ_NUM_BYTES top, %%n ; read bytes
.emuedge_extend_top_ %+ %%n %+ _loop: ; do {
WRITE_NUM_BYTES top, %%n ; write bytes
add r0 , r2 ; dst += linesize
%ifdef ARCH_X86_64
dec r3d
%else ; ARCH_X86_32
dec dword r3m
%endif ; ARCH_X86_64/32
jnz .emuedge_extend_top_ %+ %%n %+ _loop ; } while (--start_y)
; copy body pixels
.emuedge_copy_body_ %+ %%n %+ _loop: ; do {
READ_NUM_BYTES body, %%n ; read bytes
WRITE_NUM_BYTES body, %%n ; write bytes
add r0 , r2 ; dst += linesize
add r1 , r2 ; src += linesize
dec r4d
jnz .emuedge_copy_body_ %+ %%n %+ _loop ; } while (--end_y)
; copy bottom pixels
test r5 , r5 ; if (!block_h)
jz .emuedge_v_extend_end_ %+ %%n ; goto end
sub r1 , r2 ; src -= linesize
READ_NUM_BYTES bottom, %%n ; read bytes
.emuedge_extend_bottom_ %+ %%n %+ _loop: ; do {
WRITE_NUM_BYTES bottom, %%n ; write bytes
add r0 , r2 ; dst += linesize
dec r5d
jnz .emuedge_extend_bottom_ %+ %%n %+ _loop ; } while (--block_h)
.emuedge_v_extend_end_ %+ %%n:
%ifdef ARCH_X86_64
ret
%else ; ARCH_X86_32
rep ret
%endif ; ARCH_X86_64/32
%assign %%n %%n+1
%endrep
%endmacro VERTICAL_EXTEND
; left/right (horizontal) fast extend functions
; these are essentially identical to the vertical extend ones above,
; just left/right separated because number of pixels to extend is
; obviously not the same on both sides.
; for reading, pixels are placed in eax (x86-64) or ebx (x86-64) in the
; lowest two bytes of the register (so val*0x0101), and are splatted
; into each byte of mm0 as well if n_pixels >= 8
%macro READ_V_PIXEL 2
mov vall, %2
mov valh, vall
%if %1 >= 8
movd mm0, vald
%if cpuflag(mmx2)
pshufw mm0, mm0, 0
%else ; mmx
punpcklwd mm0, mm0
punpckldq mm0, mm0
%endif ; sse
%endif ; %1 >= 8
%endmacro
%macro WRITE_V_PIXEL 2
%assign %%dst_off 0
%rep %1/8
movq [%2+%%dst_off], mm0
%assign %%dst_off %%dst_off+8
%endrep
%if %1 & 4
%if %1 >= 8
movd [%2+%%dst_off], mm0
%else ; %1 < 8
mov [%2+%%dst_off] , valw
mov [%2+%%dst_off+2], valw
%endif ; %1 >=/< 8
%assign %%dst_off %%dst_off+4
%endif ; %1 & 4
%if %1&2
mov [%2+%%dst_off], valw
%endif ; %1 & 2
%endmacro
; r0=buf+block_h*linesize, r1=start_x, r2=linesize, r5=block_h, r6/r3=val
%macro LEFT_EXTEND 0
%assign %%n 2
%rep 11
ALIGN 64
.emuedge_extend_left_ %+ %%n: ; do {
sub r0, r2 ; dst -= linesize
READ_V_PIXEL %%n, [r0+r1] ; read pixels
WRITE_V_PIXEL %%n, r0 ; write pixels
dec r5
jnz .emuedge_extend_left_ %+ %%n ; } while (--block_h)
%ifdef ARCH_X86_64
ret
%else ; ARCH_X86_32
rep ret
%endif ; ARCH_X86_64/32
%assign %%n %%n+2
%endrep
%endmacro ; LEFT_EXTEND
; r3/r0=buf+block_h*linesize, r2=linesize, r11/r5=block_h, r0/r6=end_x, r6/r3=val
%macro RIGHT_EXTEND 0
%assign %%n 2
%rep 11
ALIGN 64
.emuedge_extend_right_ %+ %%n: ; do {
%ifdef ARCH_X86_64
sub r3, r2 ; dst -= linesize
READ_V_PIXEL %%n, [r3+w_reg-1] ; read pixels
WRITE_V_PIXEL %%n, r3+r4-%%n ; write pixels
dec r11
%else ; ARCH_X86_32
sub r0, r2 ; dst -= linesize
READ_V_PIXEL %%n, [r0+w_reg-1] ; read pixels
WRITE_V_PIXEL %%n, r0+r4-%%n ; write pixels
dec r5
%endif ; ARCH_X86_64/32
jnz .emuedge_extend_right_ %+ %%n ; } while (--block_h)
%ifdef ARCH_X86_64
ret
%else ; ARCH_X86_32
rep ret
%endif ; ARCH_X86_64/32
%assign %%n %%n+2
%endrep
%ifdef ARCH_X86_32
%define stack_offset 0x10
%endif
%endmacro ; RIGHT_EXTEND
; below follow the "slow" copy/extend functions, these act on a non-fixed
; width specified in a register, and run a loop to copy the full amount
; of bytes. They are optimized for copying of large amounts of pixels per
; line, so they unconditionally splat data into mm registers to copy 8
; bytes per loop iteration. It could be considered to use xmm for x86-64
; also, but I haven't optimized this as much (i.e. FIXME)
%macro V_COPY_NPX 4-5
%if %0 == 4
test w_reg, %4
jz .%1_skip_%4_px
%else ; %0 == 5
.%1_%4_px_loop:
%endif
%3 %2, [r1+cnt_reg]
%3 [r0+cnt_reg], %2
add cnt_reg, %4
%if %0 == 5
sub w_reg, %4
test w_reg, %5
jnz .%1_%4_px_loop
%endif
.%1_skip_%4_px:
%endmacro
%macro V_COPY_ROW 2
%ifidn %1, bottom
sub r1, linesize
%endif
.%1_copy_loop:
xor cnt_reg, cnt_reg
%if notcpuflag(sse)
%define linesize r2m
V_COPY_NPX %1, mm0, movq, 8, 0xFFFFFFF8
%else ; sse
V_COPY_NPX %1, xmm0, movups, 16, 0xFFFFFFF0
%ifdef ARCH_X86_64
%define linesize r2
V_COPY_NPX %1, rax , mov, 8
%else ; ARCH_X86_32
%define linesize r2m
V_COPY_NPX %1, mm0, movq, 8
%endif ; ARCH_X86_64/32
%endif ; sse
V_COPY_NPX %1, vald, mov, 4
V_COPY_NPX %1, valw, mov, 2
V_COPY_NPX %1, vall, mov, 1
mov w_reg, cnt_reg
%ifidn %1, body
add r1, linesize
%endif
add r0, linesize
dec %2
jnz .%1_copy_loop
%endmacro
%macro SLOW_V_EXTEND 0
.slow_v_extend_loop:
; r0=buf,r1=src,r2(64)/r2m(32)=linesize,r3(64)/r3m(32)=start_x,r4=end_y,r5=block_h
; r11(64)/r3(later-64)/r2(32)=cnt_reg,r6(64)/r3(32)=val_reg,r10(64)/r6(32)=w=end_x-start_x
%ifdef ARCH_X86_64
push r11 ; save old value of block_h
test r3, r3
%define cnt_reg r11
jz .do_body_copy ; if (!start_y) goto do_body_copy
V_COPY_ROW top, r3
%else
cmp dword r3m, 0
%define cnt_reg r2
je .do_body_copy ; if (!start_y) goto do_body_copy
V_COPY_ROW top, dword r3m
%endif
.do_body_copy:
V_COPY_ROW body, r4
%ifdef ARCH_X86_64
pop r11 ; restore old value of block_h
%define cnt_reg r3
%endif
test r5, r5
%ifdef ARCH_X86_64
jz .v_extend_end
%else
jz .skip_bottom_extend
%endif
V_COPY_ROW bottom, r5
%ifdef ARCH_X86_32
.skip_bottom_extend:
mov r2, r2m
%endif
jmp .v_extend_end
%endmacro
%macro SLOW_LEFT_EXTEND 0
.slow_left_extend_loop:
; r0=buf+block_h*linesize,r2=linesize,r6(64)/r3(32)=val,r5=block_h,r4=cntr,r10/r6=start_x
mov r4, 8
sub r0, linesize
READ_V_PIXEL 8, [r0+w_reg]
.left_extend_8px_loop:
movq [r0+r4-8], mm0
add r4, 8
cmp r4, w_reg
jle .left_extend_8px_loop
sub r4, 8
cmp r4, w_reg
jge .left_extend_loop_end
.left_extend_2px_loop:
mov [r0+r4], valw
add r4, 2
cmp r4, w_reg
jl .left_extend_2px_loop
.left_extend_loop_end:
dec r5
jnz .slow_left_extend_loop
%ifdef ARCH_X86_32
mov r2, r2m
%endif
jmp .right_extend
%endmacro
%macro SLOW_RIGHT_EXTEND 0
.slow_right_extend_loop:
; r3(64)/r0(32)=buf+block_h*linesize,r2=linesize,r4=block_w,r11(64)/r5(32)=block_h,
; r10(64)/r6(32)=end_x,r6/r3=val,r1=cntr
%ifdef ARCH_X86_64
%define buf_reg r3
%define bh_reg r11
%else
%define buf_reg r0
%define bh_reg r5
%endif
lea r1, [r4-8]
sub buf_reg, linesize
READ_V_PIXEL 8, [buf_reg+w_reg-1]
.right_extend_8px_loop:
movq [buf_reg+r1], mm0
sub r1, 8
cmp r1, w_reg
jge .right_extend_8px_loop
add r1, 8
cmp r1, w_reg
je .right_extend_loop_end
.right_extend_2px_loop:
sub r1, 2
mov [buf_reg+r1], valw
cmp r1, w_reg
jg .right_extend_2px_loop
.right_extend_loop_end:
dec bh_reg
jnz .slow_right_extend_loop
jmp .h_extend_end
%endmacro
%macro emu_edge 1
INIT_XMM %1
EMU_EDGE_FUNC
VERTICAL_EXTEND
LEFT_EXTEND
RIGHT_EXTEND
SLOW_V_EXTEND
SLOW_LEFT_EXTEND
SLOW_RIGHT_EXTEND
%endmacro
emu_edge sse
%ifdef ARCH_X86_32
emu_edge mmx
%endif
;-----------------------------------------------------------------------------
; void ff_vector_clip_int32(int32_t *dst, const int32_t *src, int32_t min,
; int32_t max, unsigned int len)
;-----------------------------------------------------------------------------
; %1 = number of xmm registers used
; %2 = number of inline load/process/store loops per asm loop
; %3 = process 4*mmsize (%3=0) or 8*mmsize (%3=1) bytes per loop
; %4 = CLIPD function takes min/max as float instead of int (CLIPD_SSE2)
; %5 = suffix
%macro VECTOR_CLIP_INT32 4-5
cglobal vector_clip_int32%5, 5,5,%2, dst, src, min, max, len
%if %4
cvtsi2ss m4, minm
cvtsi2ss m5, maxm
%else
movd m4, minm
movd m5, maxm
%endif
SPLATD m4
SPLATD m5
.loop:
%assign %%i 1
%rep %2
mova m0, [srcq+mmsize*0*%%i]
mova m1, [srcq+mmsize*1*%%i]
mova m2, [srcq+mmsize*2*%%i]
mova m3, [srcq+mmsize*3*%%i]
%if %3
mova m7, [srcq+mmsize*4*%%i]
mova m8, [srcq+mmsize*5*%%i]
mova m9, [srcq+mmsize*6*%%i]
mova m10, [srcq+mmsize*7*%%i]
%endif
CLIPD m0, m4, m5, m6
CLIPD m1, m4, m5, m6
CLIPD m2, m4, m5, m6
CLIPD m3, m4, m5, m6
%if %3
CLIPD m7, m4, m5, m6
CLIPD m8, m4, m5, m6
CLIPD m9, m4, m5, m6
CLIPD m10, m4, m5, m6
%endif
mova [dstq+mmsize*0*%%i], m0
mova [dstq+mmsize*1*%%i], m1
mova [dstq+mmsize*2*%%i], m2
mova [dstq+mmsize*3*%%i], m3
%if %3
mova [dstq+mmsize*4*%%i], m7
mova [dstq+mmsize*5*%%i], m8
mova [dstq+mmsize*6*%%i], m9
mova [dstq+mmsize*7*%%i], m10
%endif
%assign %%i %%i+1
%endrep
add srcq, mmsize*4*(%2+%3)
add dstq, mmsize*4*(%2+%3)
sub lend, mmsize*(%2+%3)
jg .loop
REP_RET
%endmacro
INIT_MMX mmx
%define SPLATD SPLATD_MMX
%define CLIPD CLIPD_MMX
VECTOR_CLIP_INT32 0, 1, 0, 0
INIT_XMM sse2
%define SPLATD SPLATD_SSE2
VECTOR_CLIP_INT32 6, 1, 0, 0, _int
%define CLIPD CLIPD_SSE2
VECTOR_CLIP_INT32 6, 2, 0, 1
INIT_XMM sse4
%define CLIPD CLIPD_SSE41
%ifdef m8
VECTOR_CLIP_INT32 11, 1, 1, 0
%else
VECTOR_CLIP_INT32 6, 1, 0, 0
%endif
;-----------------------------------------------------------------------------
; void ff_butterflies_float_interleave(float *dst, const float *src0,
; const float *src1, int len);
;-----------------------------------------------------------------------------
%macro BUTTERFLIES_FLOAT_INTERLEAVE 0
cglobal butterflies_float_interleave, 4,4,3, dst, src0, src1, len
%ifdef ARCH_X86_64
movsxd lenq, lend
%endif
test lenq, lenq
jz .end
shl lenq, 2
lea src0q, [src0q + lenq]
lea src1q, [src1q + lenq]
lea dstq, [ dstq + 2*lenq]
neg lenq
.loop:
mova m0, [src0q + lenq]
mova m1, [src1q + lenq]
subps m2, m0, m1
addps m0, m0, m1
unpcklps m1, m0, m2
unpckhps m0, m0, m2
%if cpuflag(avx)
vextractf128 [dstq + 2*lenq ], m1, 0
vextractf128 [dstq + 2*lenq + 16], m0, 0
vextractf128 [dstq + 2*lenq + 32], m1, 1
vextractf128 [dstq + 2*lenq + 48], m0, 1
%else
mova [dstq + 2*lenq ], m1
mova [dstq + 2*lenq + mmsize], m0
%endif
add lenq, mmsize
jl .loop
%if mmsize == 32
vzeroupper
RET
%endif
.end:
REP_RET
%endmacro
INIT_XMM sse
BUTTERFLIES_FLOAT_INTERLEAVE
INIT_YMM avx
BUTTERFLIES_FLOAT_INTERLEAVE
| 26.856054 | 126 | 0.584891 |
f9c8ca789dd3e750797f9912a4fd2e1593e0be8d | 6,081 | asm | Assembly | Transynther/x86/_processed/NONE/_xt_/i7-7700_9_0x48_notsx.log_21829_1534.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 9 | 2020-08-13T19:41:58.000Z | 2022-03-30T12:22:51.000Z | Transynther/x86/_processed/NONE/_xt_/i7-7700_9_0x48_notsx.log_21829_1534.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 1 | 2021-04-29T06:29:35.000Z | 2021-05-13T21:02:30.000Z | Transynther/x86/_processed/NONE/_xt_/i7-7700_9_0x48_notsx.log_21829_1534.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 3 | 2020-07-14T17:07:07.000Z | 2022-03-21T01:12:22.000Z | .global s_prepare_buffers
s_prepare_buffers:
push %r12
push %r13
push %r8
push %rax
push %rcx
push %rdi
push %rsi
lea addresses_D_ht+0x18d5b, %rsi
lea addresses_WC_ht+0x60b1, %rdi
clflush (%rdi)
nop
nop
and $25829, %r12
mov $66, %rcx
rep movsb
nop
nop
nop
and %rax, %rax
lea addresses_WC_ht+0x19831, %r13
nop
nop
add $41340, %rdi
mov $0x6162636465666768, %rax
movq %rax, (%r13)
nop
cmp $563, %rsi
lea addresses_normal_ht+0x17821, %rsi
lea addresses_A_ht+0xb7b1, %rdi
nop
nop
nop
nop
and $56042, %r8
mov $85, %rcx
rep movsq
nop
nop
dec %r8
pop %rsi
pop %rdi
pop %rcx
pop %rax
pop %r8
pop %r13
pop %r12
ret
.global s_faulty_load
s_faulty_load:
push %r13
push %r15
push %r9
push %rax
push %rcx
push %rdi
push %rsi
// REPMOV
lea addresses_RW+0x18671, %rsi
lea addresses_WC+0x14331, %rdi
nop
nop
nop
nop
cmp $10748, %r9
mov $71, %rcx
rep movsb
nop
nop
nop
sub %rax, %rax
// Store
lea addresses_UC+0x10e49, %rax
nop
xor $24790, %rdi
movb $0x51, (%rax)
nop
cmp %r9, %r9
// Load
lea addresses_PSE+0x190c9, %rsi
nop
nop
nop
nop
nop
xor %r15, %r15
vmovups (%rsi), %ymm7
vextracti128 $1, %ymm7, %xmm7
vpextrq $1, %xmm7, %rdi
nop
nop
xor $8901, %rcx
// Load
lea addresses_normal+0x95f1, %rax
nop
nop
nop
nop
nop
xor %r13, %r13
mov (%rax), %si
nop
nop
nop
nop
nop
xor $43344, %rax
// Store
lea addresses_WT+0x151a1, %rax
add %r15, %r15
movb $0x51, (%rax)
nop
nop
nop
nop
nop
sub $15939, %rsi
// Faulty Load
lea addresses_normal+0x1ccb1, %r15
clflush (%r15)
and $55131, %r13
vmovups (%r15), %ymm3
vextracti128 $1, %ymm3, %xmm3
vpextrq $1, %xmm3, %rdi
lea oracles, %r13
and $0xff, %rdi
shlq $12, %rdi
mov (%r13,%rdi,1), %rdi
pop %rsi
pop %rdi
pop %rcx
pop %rax
pop %r9
pop %r15
pop %r13
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 1, 'type': 'addresses_normal', 'congruent': 0}}
{'dst': {'same': False, 'congruent': 5, 'type': 'addresses_WC'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 6, 'type': 'addresses_RW'}}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 1, 'type': 'addresses_UC', 'congruent': 3}, 'OP': 'STOR'}
{'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_PSE', 'congruent': 1}}
{'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_normal', 'congruent': 5}}
{'dst': {'same': False, 'NT': True, 'AVXalign': False, 'size': 1, 'type': 'addresses_WT', 'congruent': 4}, 'OP': 'STOR'}
[Faulty Load]
{'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_normal', 'congruent': 0}}
<gen_prepare_buffer>
{'dst': {'same': False, 'congruent': 10, 'type': 'addresses_WC_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 0, 'type': 'addresses_D_ht'}}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 8, 'type': 'addresses_WC_ht', 'congruent': 7}, 'OP': 'STOR'}
{'dst': {'same': False, 'congruent': 8, 'type': 'addresses_A_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 2, 'type': 'addresses_normal_ht'}}
{'34': 21829}
34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34
*/
| 37.079268 | 2,999 | 0.657787 |
291f56fbc37087361a60c2588655ff8c19673509 | 131 | asm | Assembly | libsrc/_DEVELOPMENT/error/z80/error_bc_zc.asm | meesokim/z88dk | 5763c7778f19a71d936b3200374059d267066bb2 | [
"ClArtistic"
] | null | null | null | libsrc/_DEVELOPMENT/error/z80/error_bc_zc.asm | meesokim/z88dk | 5763c7778f19a71d936b3200374059d267066bb2 | [
"ClArtistic"
] | null | null | null | libsrc/_DEVELOPMENT/error/z80/error_bc_zc.asm | meesokim/z88dk | 5763c7778f19a71d936b3200374059d267066bb2 | [
"ClArtistic"
] | null | null | null |
SECTION code_error
PUBLIC error_bc_zc
pop bc
error_bc_zc:
; set bc = 0
; set carry flag
ld bc,0
scf
ret
| 8.1875 | 19 | 0.603053 |
31b68d60b7a4f6faba79d1580a48e1ca2b4d2c3d | 1,522 | asm | Assembly | programs/oeis/211/A211533.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | null | null | null | programs/oeis/211/A211533.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | null | null | null | programs/oeis/211/A211533.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | null | null | null | ; A211533: Number of ordered triples (w,x,y) with all terms in {1,...,n} and w=3x-5y.
; 0,0,1,1,3,4,5,8,10,13,16,19,23,27,32,36,41,47,52,59,65,71,79,86,94,102,110,119,128,138,147,157,168,178,190,201,212,225,237,250,263,276,290,304,319,333,348,364,379,396,412,428,446,463,481,499,517,536,555,575,594,614,635,655,677,698,719,742,764,787,810,833,857,881,906,930,955,981,1006,1033,1059,1085,1113,1140,1168,1196,1224,1253,1282,1312,1341,1371,1402,1432,1464,1495,1526,1559,1591,1624,1657,1690,1724,1758,1793,1827,1862,1898,1933,1970,2006,2042,2080,2117,2155,2193,2231,2270,2309,2349,2388,2428,2469,2509,2551,2592,2633,2676,2718,2761,2804,2847,2891,2935,2980,3024,3069,3115,3160,3207,3253,3299,3347,3394,3442,3490,3538,3587,3636,3686,3735,3785,3836,3886,3938,3989,4040,4093,4145,4198,4251,4304,4358,4412,4467,4521,4576,4632,4687,4744,4800,4856,4914,4971,5029,5087,5145,5204,5263,5323,5382,5442,5503,5563,5625,5686,5747,5810,5872,5935,5998,6061,6125,6189,6254,6318,6383,6449,6514,6581,6647,6713,6781,6848,6916,6984,7052,7121,7190,7260,7329,7399,7470,7540,7612,7683,7754,7827,7899,7972,8045,8118,8192,8266,8341,8415,8490,8566,8641,8718,8794,8870,8948,9025,9103,9181,9259,9338,9417,9497,9576,9656,9737,9817,9899,9980,10061,10144,10226,10309
mov $9,$0
mov $11,$0
lpb $11,1
clr $0,9
mov $0,$9
sub $11,1
sub $0,$11
sub $0,1
add $5,$0
div $5,3
add $8,2
mul $0,$8
add $0,2
mul $0,2
div $0,5
mov $4,3
add $4,$5
add $5,$4
mul $5,$0
mod $5,2
add $5,$4
mov $1,$5
sub $1,3
add $10,$1
lpe
mov $1,$10
| 50.733333 | 1,144 | 0.711564 |
516fc56da4133577dcaaef6d80beec1c26d77b64 | 794 | asm | Assembly | programs/oeis/212/A212031.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | null | null | null | programs/oeis/212/A212031.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | null | null | null | programs/oeis/212/A212031.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | null | null | null | ; A212031: Number of lower triangular n X n arrays colored with integers 0 upwards introduced in row major order, with no element equal to any element at a city block distance of two, and containing the value n(n+1)/2-2.
; 0,3,10,31,78,166,313,540,871,1333,1956,2773,3820,5136,6763,8746,11133,13975,17326,21243,25786,31018,37005,43816,51523,60201,69928,80785,92856,106228,120991,137238,155065,174571,195858,219031,244198,271470,300961,332788,367071,403933,443500,485901,531268,579736,631443,686530,745141,807423,873526,943603,1017810,1096306,1179253,1266816,1359163,1456465,1558896,1666633,1779856,1898748,2023495,2154286,2291313,2434771,2584858,2741775,2905726,3076918
mov $2,2
lpb $0,1
add $3,$0
sub $0,1
add $3,4
add $4,$3
add $1,$4
add $1,$2
sub $1,$0
lpe
trn $4,1
sub $1,$4
| 49.625 | 448 | 0.764484 |
d3e43c6bb607e074018300d116ef18a10866df6d | 432 | asm | Assembly | programs/oeis/033/A033504.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | 1 | 2021-03-15T11:38:20.000Z | 2021-03-15T11:38:20.000Z | programs/oeis/033/A033504.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | null | null | null | programs/oeis/033/A033504.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | null | null | null | ; A033504: a(n)/4^n is the expected number of tosses of a coin required to obtain n+1 heads or n+1 tails.
; 1,10,66,372,1930,9516,45332,210664,960858,4319100,19188796,84438360,368603716,1598231992,6889682280,29551095248,126193235194,536799072924,2275560109868,9616650989560,40527780684972,170368957887656,714556104675736,2990728476330672
mov $2,$0
add $2,1
cal $0,346 ; a(n) = 2^(2*n+1) - binomial(2*n+1, n+1).
mul $0,$2
mov $1,$0
| 48 | 231 | 0.761574 |
64d3a56e94fdd99d80c4dd284967a96c25db2528 | 692 | asm | Assembly | oeis/008/A008936.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 11 | 2021-08-22T19:44:55.000Z | 2022-03-20T16:47:57.000Z | oeis/008/A008936.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 9 | 2021-08-29T13:15:54.000Z | 2022-03-09T19:52:31.000Z | oeis/008/A008936.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 3 | 2021-08-22T20:56:47.000Z | 2021-09-29T06:26:12.000Z | ; A008936: Expansion of (1 - 2*x -x^4)/(1 - 2*x)^2 in powers of x.
; 1,2,4,8,15,28,52,96,176,320,576,1024,1792,3072,5120,8192,12288,16384,16384,0,-65536,-262144,-786432,-2097152,-5242880,-12582912,-29360128,-67108864,-150994944,-335544320,-738197504,-1610612736,-3489660928,-7516192768,-16106127360,-34359738368,-73014444032,-154618822656,-326417514496,-687194767360,-1443109011456,-3023656976384,-6322191859712,-13194139533312,-27487790694400,-57174604644352,-118747255799808,-246290604621824,-510173395288064,-1055531162664960,-2181431069507584,-4503599627370496
add $0,1
mov $2,$0
lpb $0
sub $0,1
sub $2,10
mul $2,2
cmp $3,0
sub $3,$2
lpe
mov $0,$3
sub $0,12
div $0,32
add $0,1
| 40.705882 | 497 | 0.74422 |
292537130ec7731c7d399a156ae92f32ac3f6665 | 7,078 | asm | Assembly | Transynther/x86/_processed/NONE/_xt_/i9-9900K_12_0xa0.log_21829_1000.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 9 | 2020-08-13T19:41:58.000Z | 2022-03-30T12:22:51.000Z | Transynther/x86/_processed/NONE/_xt_/i9-9900K_12_0xa0.log_21829_1000.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 1 | 2021-04-29T06:29:35.000Z | 2021-05-13T21:02:30.000Z | Transynther/x86/_processed/NONE/_xt_/i9-9900K_12_0xa0.log_21829_1000.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 3 | 2020-07-14T17:07:07.000Z | 2022-03-21T01:12:22.000Z | .global s_prepare_buffers
s_prepare_buffers:
push %r13
push %r14
push %r15
push %r9
push %rbp
push %rcx
push %rdi
push %rsi
lea addresses_UC_ht+0x1c118, %rbp
nop
sub %r9, %r9
movw $0x6162, (%rbp)
nop
nop
nop
nop
nop
dec %r13
lea addresses_A_ht+0x8f18, %rsi
lea addresses_D_ht+0x2f18, %rdi
clflush (%rsi)
nop
nop
dec %r15
mov $86, %rcx
rep movsq
nop
cmp %rsi, %rsi
lea addresses_normal_ht+0x9118, %r13
nop
nop
nop
nop
add %r15, %r15
mov (%r13), %ecx
sub %r14, %r14
lea addresses_normal_ht+0x4f94, %rsi
lea addresses_WC_ht+0x1d6a8, %rdi
nop
nop
xor %r15, %r15
mov $23, %rcx
rep movsb
cmp $22874, %r13
lea addresses_WT_ht+0x1a318, %rcx
nop
dec %r9
mov $0x6162636465666768, %rbp
movq %rbp, %xmm2
vmovups %ymm2, (%rcx)
nop
nop
nop
sub $19630, %r14
lea addresses_A_ht+0x1d5e8, %r13
nop
sub %rdi, %rdi
mov $0x6162636465666768, %r15
movq %r15, %xmm3
vmovups %ymm3, (%r13)
nop
nop
nop
nop
nop
inc %r13
lea addresses_A_ht+0xff18, %rcx
nop
nop
nop
nop
nop
and $48780, %rdi
mov (%rcx), %r15w
nop
nop
and $31768, %r14
lea addresses_WT_ht+0xc051, %rbp
nop
nop
nop
nop
nop
add $34986, %r15
movups (%rbp), %xmm0
vpextrq $0, %xmm0, %r14
xor $56669, %rcx
lea addresses_D_ht+0xf815, %r14
nop
nop
add $4849, %r15
mov $0x6162636465666768, %r13
movq %r13, %xmm4
vmovups %ymm4, (%r14)
sub $3773, %rdi
lea addresses_WC_ht+0x1e6b0, %rsi
lea addresses_normal_ht+0x2518, %rdi
nop
nop
nop
nop
xor %r13, %r13
mov $88, %rcx
rep movsb
nop
nop
nop
nop
nop
inc %r14
lea addresses_A_ht+0xbd18, %r9
nop
nop
nop
nop
nop
dec %rbp
mov $0x6162636465666768, %rcx
movq %rcx, %xmm0
and $0xffffffffffffffc0, %r9
vmovntdq %ymm0, (%r9)
nop
nop
nop
nop
sub $31023, %r9
lea addresses_normal_ht+0x13718, %rcx
nop
add $26834, %r15
movups (%rcx), %xmm2
vpextrq $0, %xmm2, %r14
nop
nop
nop
dec %r15
pop %rsi
pop %rdi
pop %rcx
pop %rbp
pop %r9
pop %r15
pop %r14
pop %r13
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r15
push %r9
push %rax
push %rcx
push %rdi
// Faulty Load
lea addresses_normal+0x10f18, %r10
nop
nop
nop
nop
nop
xor $63722, %r15
movb (%r10), %al
lea oracles, %r10
and $0xff, %rax
shlq $12, %rax
mov (%r10,%rax,1), %rax
pop %rdi
pop %rcx
pop %rax
pop %r9
pop %r15
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'src': {'NT': False, 'same': False, 'congruent': 0, 'type': 'addresses_normal', 'AVXalign': False, 'size': 32}, 'OP': 'LOAD'}
[Faulty Load]
{'src': {'NT': False, 'same': True, 'congruent': 0, 'type': 'addresses_normal', 'AVXalign': False, 'size': 1}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 8, 'type': 'addresses_UC_ht', 'AVXalign': False, 'size': 2}}
{'src': {'same': False, 'congruent': 9, 'type': 'addresses_A_ht'}, 'OP': 'REPM', 'dst': {'same': True, 'congruent': 11, 'type': 'addresses_D_ht'}}
{'src': {'NT': False, 'same': False, 'congruent': 6, 'type': 'addresses_normal_ht', 'AVXalign': False, 'size': 4}, 'OP': 'LOAD'}
{'src': {'same': False, 'congruent': 2, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 3, 'type': 'addresses_WC_ht'}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 10, 'type': 'addresses_WT_ht', 'AVXalign': False, 'size': 32}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': True, 'congruent': 2, 'type': 'addresses_A_ht', 'AVXalign': False, 'size': 32}}
{'src': {'NT': True, 'same': False, 'congruent': 11, 'type': 'addresses_A_ht', 'AVXalign': False, 'size': 2}, 'OP': 'LOAD'}
{'src': {'NT': False, 'same': False, 'congruent': 0, 'type': 'addresses_WT_ht', 'AVXalign': False, 'size': 16}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 0, 'type': 'addresses_D_ht', 'AVXalign': False, 'size': 32}}
{'src': {'same': False, 'congruent': 3, 'type': 'addresses_WC_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 6, 'type': 'addresses_normal_ht'}}
{'OP': 'STOR', 'dst': {'NT': True, 'same': False, 'congruent': 2, 'type': 'addresses_A_ht', 'AVXalign': False, 'size': 32}}
{'src': {'NT': False, 'same': True, 'congruent': 11, 'type': 'addresses_normal_ht', 'AVXalign': False, 'size': 16}, 'OP': 'LOAD'}
{'34': 21829}
34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34
*/
| 35.39 | 2,999 | 0.660921 |
f16d9673f05ba8568a3628031f9f6a5f21b82c72 | 16,116 | asm | Assembly | source/jni/u2/techno/koea.asm | Falken42/SecondReality | b998d193a066523cb4ca2b86c8041bea1bddfcb4 | [
"Unlicense"
] | 9 | 2015-05-13T21:02:00.000Z | 2018-04-15T16:32:27.000Z | source/jni/u2/techno/koea.asm | falken42/SecondReality | b998d193a066523cb4ca2b86c8041bea1bddfcb4 | [
"Unlicense"
] | null | null | null | source/jni/u2/techno/koea.asm | falken42/SecondReality | b998d193a066523cb4ca2b86c8041bea1bddfcb4 | [
"Unlicense"
] | null | null | null | extrn _circle:byte
extrn _circle2:byte
code SEGMENT para public 'CODE'
ASSUME cs:code
.386
LOCALS
ALIGN 16
_rows dw 200 dup(0)
_blit16t dw 256 dup(0)
_vbufseg dw 0
clipleft dw 0
polyisides dw 0
polyixy dw 16 dup(0,0)
polysides dw 0
polyxy dw 16 dup(0,0)
include polyclip.asm
ALIGN 2
PUBLIC _sin1024
include sin1024.inc
REPOUTSB MACRO
local l1
l1: mov al,ds:[si]
inc si
out dx,al
dec cx
jnz l1
ENDM
PUBLIC _asminit
_asminit PROC FAR
push bp
mov bp,sp
push si
push di
push ds
mov ax,[bp+8]
mov cs:_vbufseg,ax
call blitinit
pop ds
pop di
pop si
pop bp
ret
_asminit ENDP
PUBLIC _asmdoit
_asmdoit PROC FAR
push bp
mov bp,sp
push si
push di
push ds
lds si,[bp+6]
les di,[bp+10]
call blit16
pop ds
pop di
pop si
pop bp
ret
_asmdoit ENDP
PUBLIC _asmdoit2
_asmdoit2 PROC FAR
push bp
mov bp,sp
push si
push di
push ds
lds si,[bp+6]
les di,[bp+10]
call blit16b
pop ds
pop di
pop si
pop bp
ret
_asmdoit2 ENDP
blitinit PROC NEAR
mov bx,OFFSET _rows
mov cx,200
mov dx,40
xor ax,ax
@@l1: mov cs:[bx],ax
add ax,dx
add bx,2
loop @@l1
xor al,al
mov bx,OFFSET _blit16t
mov cx,256
@@1: mov dh,255
mov dl,al
xor ah,ah
REPT 8
local l2
rcl dl,1
jnc l2
xor ah,dh
l2: shr dh,1
ENDM
mov cs:[bx],ah
ror ah,1
and ah,80h
mov cs:[bx+1],ah
add bx,2
inc al
loop @@1
ret
blitinit ENDP
blit16 PROC NEAR
xor ebx,ebx
mov cx,200
jmp @@1
ALIGN 16
@@1: zzz=0
xor dh,dh ;line starts black
REPT 40/2
mov bl,ds:[si+zzz]
xor bl,dh
mov ax,cs:_blit16t[ebx*2]
mov bl,ds:[si+1+zzz]
xor bl,ah
mov dx,cs:_blit16t[ebx*2]
mov ah,dl
mov es:[di+zzz],ax
zzz=zzz+2
ENDM
add si,40
add di,40
dec cx
jz @@2
jmp @@1
@@2:
ret
blit16 ENDP
blit16b PROC NEAR
xor ebx,ebx
mov cx,200
jmp @@1
ALIGN 16
@@1: zzz=0
xor dh,dh ;line starts black
REPT 40/2
mov bl,ds:[si+zzz]
xor bl,dh
mov ax,cs:_blit16t[ebx*2]
mov bl,ds:[si+1+zzz]
xor bl,ah
mov dx,cs:_blit16t[ebx*2]
mov ah,dl
mov es:[di+zzz],ax
zzz=zzz+2
ENDM
add si,40
add di,80
dec cx
jz @@2
jmp @@1
@@2:
ret
blit16b ENDP
drawline PROC NEAR
push si
push di
push bp
@@vis: movzx ebx,bx
cmp bx,cx
je @@0
jle @@1
xchg bx,cx
xchg ax,dx
@@1: sub cx,bx
mov di,cx
mov si,cs:_rows[ebx*2]
mov bp,cs:clipleft
or bp,bp
jz @@nl
push si
;left overflow fill
jge @@ndn
@@nup: add si,40
xor byte ptr ds:[si],080h
inc bp
jnz @@nup
jmp @@nl2
@@ndn: sub si,40
xor byte ptr ds:[si],080h
dec bp
jnz @@ndn
@@nl2: pop si
@@nl: ;
jcxz @@0
movzx ebp,ax
shr bp,3
add si,bp
mov bp,ax
and bp,7
;go on
cmp ax,dx
jl @@r
@@l: ;=============== left
neg dx
add dx,ax
mov bx,di
shr bx,1
neg bx
jmp cs:_loffs[ebp*2]
ALIGN 16
_loffs LABEL WORD
dw OFFSET @@l7
dw OFFSET @@l6
dw OFFSET @@l5
dw OFFSET @@l4
dw OFFSET @@l3
dw OFFSET @@l2
dw OFFSET @@l1
dw OFFSET @@l0
llinemacro MACRO mask,lbl1,lbl2,lbl3,lbl4,lbl5,lbl6,lbl7,lbl0
local l1,l2
;ds:si=startpoint
;di=ycnt
;dx=xcnt
;bx=counter
l1: xor byte ptr ds:[si],mask
add si,40
dec cx
jz @@0
add bx,dx
jl l1
l2: IF lbl1 EQ @@l0
dec si
ENDIF
sub bx,di
jl lbl1
IF lbl2 EQ @@l0
dec si
ENDIF
sub bx,di
jl lbl2
IF lbl3 EQ @@l0
dec si
ENDIF
sub bx,di
jl lbl3
IF lbl4 EQ @@l0
dec si
ENDIF
sub bx,di
jl lbl4
IF lbl5 EQ @@l0
dec si
ENDIF
sub bx,di
jl lbl5
IF lbl6 EQ @@l0
dec si
ENDIF
sub bx,di
jl lbl6
IF lbl7 EQ @@l0
dec si
ENDIF
sub bx,di
jl lbl7
IF lbl0 EQ @@l0
dec si
ENDIF
sub bx,di
jl l1
jmp l2
ENDM
@@l7: llinemacro 10000000b,@@l0,@@l1,@@l2,@@l3,@@l4,@@l5,@@l6,@@l7
@@l6: llinemacro 01000000b,@@l7,@@l0,@@l1,@@l2,@@l3,@@l4,@@l5,@@l6
@@l5: llinemacro 00100000b,@@l6,@@l7,@@l0,@@l1,@@l2,@@l3,@@l4,@@l5
@@l4: llinemacro 00010000b,@@l5,@@l6,@@l7,@@l0,@@l1,@@l2,@@l3,@@l4
@@l3: llinemacro 00001000b,@@l4,@@l5,@@l6,@@l7,@@l0,@@l1,@@l2,@@l3
@@l2: llinemacro 00000100b,@@l3,@@l4,@@l5,@@l6,@@l7,@@l0,@@l1,@@l2
@@l1: llinemacro 00000010b,@@l2,@@l3,@@l4,@@l5,@@l6,@@l7,@@l0,@@l1
@@l0: llinemacro 00000001b,@@l1,@@l2,@@l3,@@l4,@@l5,@@l6,@@l7,@@l0
@@r: ;=============== right
sub dx,ax
mov bx,di
shr bx,1
neg bx
jmp cs:_roffs[ebp*2]
ALIGN 16
_roffs LABEL WORD
dw OFFSET @@r7
dw OFFSET @@r6
dw OFFSET @@r5
dw OFFSET @@r4
dw OFFSET @@r3
dw OFFSET @@r2
dw OFFSET @@r1
dw OFFSET @@r0
rlinemacro MACRO mask,lbl1,lbl2,lbl3,lbl4,lbl5,lbl6,lbl7,lbl0
local l1,l2
;ds:si=startpoint
;di=ycnt
;dx=xcnt
;bx=counter
l1: xor byte ptr ds:[si],mask
add si,40
dec cx
jz @@0
add bx,dx
jl l1
l2: IF lbl1 EQ @@r7
inc si
ENDIF
sub bx,di
jl lbl1
IF lbl2 EQ @@r7
inc si
ENDIF
sub bx,di
jl lbl2
IF lbl3 EQ @@r7
inc si
ENDIF
sub bx,di
jl lbl3
IF lbl4 EQ @@r7
inc si
ENDIF
sub bx,di
jl lbl4
IF lbl5 EQ @@r7
inc si
ENDIF
sub bx,di
jl lbl5
IF lbl6 EQ @@r7
inc si
ENDIF
sub bx,di
jl lbl6
IF lbl7 EQ @@r7
inc si
ENDIF
sub bx,di
jl lbl7
IF lbl0 EQ @@r7
inc si
ENDIF
sub bx,di
jl l1
jmp l2
ENDM
@@r7: rlinemacro 10000000b,@@r6,@@r5,@@r4,@@r3,@@r2,@@r1,@@r0,@@r7
@@r6: rlinemacro 01000000b,@@r5,@@r4,@@r3,@@r2,@@r1,@@r0,@@r7,@@r6
@@r5: rlinemacro 00100000b,@@r4,@@r3,@@r2,@@r1,@@r0,@@r7,@@r6,@@r5
@@r4: rlinemacro 00010000b,@@r3,@@r2,@@r1,@@r0,@@r7,@@r6,@@r5,@@r4
@@r3: rlinemacro 00001000b,@@r2,@@r1,@@r0,@@r7,@@r6,@@r5,@@r4,@@r3
@@r2: rlinemacro 00000100b,@@r1,@@r0,@@r7,@@r6,@@r5,@@r4,@@r3,@@r2
@@r1: rlinemacro 00000010b,@@r0,@@r7,@@r6,@@r5,@@r4,@@r3,@@r2,@@r1
@@r0: rlinemacro 00000001b,@@r7,@@r6,@@r5,@@r4,@@r3,@@r2,@@r1,@@r0
@@0: pop bp
pop di
pop si
ret
drawline ENDP
PUBLIC _asmbox
_asmbox PROC FAR
push bp
mov bp,sp
push si
push di
push ds
mov eax,[bp+6]
mov dword ptr cs:polyixy[0],eax
mov eax,[bp+10]
mov dword ptr cs:polyixy[4],eax
mov eax,[bp+14]
mov dword ptr cs:polyixy[8],eax
mov eax,[bp+18]
mov dword ptr cs:polyixy[12],eax
mov cs:polyisides,4
call clipanypoly
mov ds,cs:_vbufseg
mov si,OFFSET polyxy
mov di,cs:polysides
or di,di
jz @@0
dec di
jz @@2
@@1: mov ax,cs:[si+0]
mov bx,cs:[si+2]
mov dx,cs:[si+4]
mov cx,cs:[si+6]
call drawline
add si,4
dec di
jnz @@1
@@2: mov ax,cs:[si+0]
mov bx,cs:[si+2]
mov dx,cs:polyxy[0]
mov cx,cs:polyxy[2]
call drawline
@@0: pop ds
pop di
pop si
pop bp
ret
_asmbox ENDP
;################################################################
ALIGN 16
flip8 LABEL BYTE
db 0,128,64,192,32,160,96,224,16,144,80,208,48,176,112,240,8,136,72,200
db 40,168,104,232,24,152,88,216,56,184,120,248,4,132,68,196,36,164,100
db 228,20,148,84,212,52,180,116,244,12,140,76,204,44,172,108,236,28,156
db 92,220,60,188,124,252,2,130,66,194,34,162,98,226,18,146,82,210,50,178
db 114,242,10,138,74,202,42,170,106,234,26,154,90,218,58,186,122,250,6
db 134,70,198,38,166,102,230,22,150,86,214,54,182,118,246,14,142,78,206
db 46,174,110,238,30,158,94,222,62,190,126,254,1,129,65,193,33,161,97,225
db 17,145,81,209,49,177,113,241,9,137,73,201,41,169,105,233,25,153,89,217
db 57,185,121,249,5,133,69,197,37,165,101,229,21,149,85,213,53,181,117,245
db 13,141,77,205,45,173,109,237,29,157,93,221,61,189,125,253,3,131,67,195
db 35,163,99,227,19,147,83,211,51,179,115,243,11,139,75,203,43,171,107,235
db 27,155,91,219,59,187,123,251,7,135,71,199,39,167,103,231,23,151,87,215
db 55,183,119,247,15,143,79,207,47,175,111,239,31,159,95,223,63,191,127,255
circles dw 8 dup(0)
pal2 LABEL WORD
db 0, 0*7/9, 0
db 10,10*7/9,10
db 20,20*7/9,20
db 30,30*7/9,30
db 40,40*7/9,40
db 50,50*7/9,50
db 60,60*7/9,60
db 30,30*7/9,30
db 0, 0*7/9, 0
db 10,10*7/9,10
db 20,20*7/9,20
db 30,30*7/9,30
db 40,40*7/9,40
db 50,50*7/9,50
db 60,60*7/9,60
db 30,30*7/9,30
pal1 LABEL WORD
db 30,30*8/9,30
db 60,60*8/9,60
db 50,50*8/9,50
db 40,40*8/9,40
db 30,30*8/9,30
db 20,20*8/9,20
db 10,10*8/9,10
db 0, 0*8/9, 0
db 30,30*8/9,30
db 60,60*8/9,60
db 50,50*8/9,50
db 40,40*8/9,40
db 30,30*8/9,30
db 20,20*8/9,20
db 10,10*8/9,10
db 0, 0*8/9, 0
sinuspower db 0
powercnt db 0
PUBLIC _power0
_power0 LABEL WORD
power0 db 256 dup(0)
db 256 dup(0)
db 256 dup(0)
db 256 dup(0)
db 256 dup(0)
db 256 dup(0)
db 256 dup(0)
db 256 dup(0)
db 256 dup(0)
db 256 dup(0)
db 256 dup(0)
db 256 dup(0)
db 256 dup(0)
db 256 dup(0)
db 256 dup(0)
db 256 dup(0)
PLANE MACRO pl
mov dx,3c4h
mov ax,0002h+pl*100h
out dx,ax
ENDM
bltline PROC NEAR
push si
mov dx,3c4h
mov al,2
out dx,al
inc dx
@@1: mov al,ch
out dx,al
zzz=0
REPT 10
mov eax,ds:[si+zzz]
mov es:[di+zzz],eax
zzz=zzz+4
ENDM
add si,40
shl ch,1
dec cl
jnz @@1
pop si
ret
bltline ENDP
bltlinerev PROC NEAR
push si
mov dx,3c4h
mov al,2
out dx,al
inc dx
xor bx,bx
@@1: mov al,ch
out dx,al
zzz=0
REPT 10
mov bl,ds:[si+36-zzz]
mov al,cs:flip8[bx]
rol eax,8
mov bl,ds:[si+37-zzz]
mov al,cs:flip8[bx]
rol eax,8
mov bl,ds:[si+38-zzz]
mov al,cs:flip8[bx]
rol eax,8
mov bl,ds:[si+39-zzz]
mov al,cs:flip8[bx]
mov es:[di+zzz],eax
zzz=zzz+4
ENDM
add si,40
shl ch,1
dec cl
jnz @@1
pop si
ret
bltlinerev ENDP
resetmode13 PROC NEAR
mov ax,13
int 10h
mov dx,3dah
in al,dx
mov dx,3c0h
xor al,al
REPT 16
out dx,al
out dx,al
inc al
ENDM
mov al,11h
out dx,al
mov al,255
out dx,al
mov al,32
out dx,al
;clear pal
mov dx,3c8h
xor al,al
out dx,al
inc dx
mov cx,768
@@clp: out dx,al
loop @@clp
ret
resetmode13 ENDP
outpal PROC NEAR
mov dx,3c8h
out dx,al
mov ax,cs
mov ds,ax
inc dx
REPOUTSB
ret
outpal ENDP
waitb PROC NEAR
mov bx,1
int 0fch
ret
waitb ENDP
rotate1 PROC NEAR
xor si,si
mov cx,32000/32-2
cld
jmp @@2
;edx.eax
@@1: popf
zzz=0
REPT 16
mov ax,ds:[si+zzz]
rcr al,1
rcr ah,1
mov es:[si+zzz],ax
zzz=zzz+2
ENDM
@@2: pushf
add si,zzz
dec cx
jz @@0
jmp @@1
@@0: popf
ret
rotate1 ENDP
ALIGN 2
framecount dw 0
palanimc dw 0
palanimc2 dw 0
scrnpos dw 0
scrnposl dw 0
scrnx dw 0
scrny dw 0
scrnrot dw 0
sinurot dw 0
overrot dw 211
overx dw 0
overya dw 0
patdir dw 0
memseg dw 0
init_interference PROC NEAR
mov dx,3d4h
mov ax,2813h
out dx,ax
mov bx,20+100*80
;get mem for circles
mov ah,48h
mov bx,16384
int 21h
mov cs:memseg,ax
zzz=0
REPT 8
mov cs:circles[zzz],ax
add ax,2048
zzz=zzz+2
ENDM
mov ax,SEG _circle2
mov ds,ax
xor si,si
mov ax,0a000h
mov es,ax
mov cx,200
xor di,di
mov bp,80*399
@@1: push cx
push di
mov cx,0401h
call bltline
add di,40
mov cx,0401h
call bltlinerev
add di,40
mov di,bp
mov cx,0401h
call bltline
add di,40
mov cx,0401h
call bltlinerev
add di,40
pop di
add di,80
sub bp,80
add si,40
pop cx
loop @@1
mov dx,3ceh
mov ax,0204h
out dx,ax
mov cx,400
mov es,cs:circles[0]
mov ax,0a000h
mov ds,ax
mov cx,32000/4
xor si,si
xor di,di
rep movsd
zzz=0
REPT 7
mov ds,cs:circles[zzz]
mov es,cs:circles[zzz+2]
call rotate1
zzz=zzz+2
ENDM
mov ax,SEG _circle
mov ds,ax
xor si,si
mov ax,0a000h
mov es,ax
mov cx,200
xor di,di
mov bp,80*399
@@10: push cx
push di
mov cx,0103h ;start at plane 1, copy 3 planes
call bltline
add di,40
mov cx,0103h ;start at plane 1, copy 3 planes
call bltlinerev
add di,40
mov di,bp
mov cx,0103h ;start at plane 1, copy 3 planes
call bltline
add di,40
mov cx,0103h ;start at plane 1, copy 3 planes
call bltlinerev
add di,40
pop di
add di,80
sub bp,80
add si,40*3
pop cx
loop @@10
mov cs:framecount,0
ret
init_interference ENDP
do_interference PROC NEAR
@@aga: call waitb
mov dx,3c0h
mov al,13h
out dx,al
mov al,byte ptr cs:scrnposl
out dx,al
mov al,32
out dx,al
mov si,cs:palanimc
add si,cs:patdir
cmp si,0
jge @@a11
mov si,8*3-3
@@a11: cmp si,8*3
jb @@a1
xor si,si
@@a1: mov cs:palanimc,si
mov cs:palanimc2,si
mov si,cs:palanimc
add si,OFFSET pal1
xor al,al
mov cx,8*3
call outpal
mov si,cs:palanimc
add si,OFFSET pal2
mov al,8
mov cx,8*3
call outpal
PLANE 8
mov ax,0a000h
mov es,ax
xor si,si
mov di,cs:scrnpos
mov bp,cs:sinurot
add bp,7*2
and bp,2047
mov cs:sinurot,bp
mov cx,200
@@cp1: zzz=0
push si
add bp,9*2
and bp,2047
mov bx,cs:_sin1024[bp]
sar bx,3
mov bh,cs:sinuspower
movsx ax,byte ptr cs:power0[bx]
sub ax,cs:scrnposl
add ax,cs:overx
mov bx,ax
and bx,7
shl bx,1
neg bx
mov ds,cs:circles[bx+7*2]
sar ax,3
add si,ax
add si,cs:overya
REPT 40/4+1
mov eax,ds:[si+zzz]
mov es:[di+zzz],eax
zzz=zzz+4
ENDM
pop si
add di,80
add si,80
dec cx
jz @@cp0
jmp @@cp1
@@cp0:
;MOVE
mov bx,6
int 0fch
;bx=row
and bx,7
cmp bx,0
jne @@m1
mov cs:patdir,-3
@@m1: cmp bx,4
jne @@m2
mov cs:patdir,-3 ;-3
@@m2:
mov bx,cs:scrnrot
add bx,5
and bx,1023
mov cs:scrnrot,bx
shl bx,1
mov ax,cs:_sin1024[bx]
sar ax,2
add ax,160
mov cs:scrnx,ax
add bx,256*2
and bx,1024*2-1
mov ax,cs:_sin1024[bx]
sar ax,2
add ax,100
mov cs:scrny,ax
mov bx,cs:overrot
add bx,7
and bx,1023
mov cs:overrot,bx
shl bx,1
mov ax,cs:_sin1024[bx]
sar ax,2
add ax,160
mov cs:overx,ax
add bx,256*2
and bx,1024*2-1
mov ax,cs:_sin1024[bx]
sar ax,2
add ax,100
mov bx,80
mul bx
mov cs:overya,ax
mov ax,cs:scrnx
mov bx,ax
and ax,7
mov cs:scrnposl,ax
mov ax,80
mul cs:scrny
sar bx,3
add ax,bx
mov cs:scrnpos,ax
mov bx,cs:scrnpos
mov dx,3d4h
mov al,0ch
mov ah,bh
out dx,ax
inc al
mov ah,bl
out dx,ax
cmp cs:framecount,70*5
jb @@p1
inc cs:powercnt
cmp cs:powercnt,16
jb @@p1
mov cs:powercnt,0
cmp cs:sinuspower,15
jae @@p1
inc cs:sinuspower
@@p1:
inc cs:framecount
;cmp cs:framecount,70*13
;je @@xx
mov ax,0
mov bx,9
int 0fch
cmp ax,925
jae @@xx
mov bx,2
int 0fch
or ax,ax
jz @@aga
@@xx: ret
do_interference ENDP
PUBLIC _initinterference
_initinterference PROC FAR
push bp
mov bp,sp
push si
push di
push ds
; call resetmode13
;@@wm1: mov bx,2
; int 0fch
; or ax,ax
; jnz @@xit
; mov bx,6
; mov ax,0f1h
; int 0fch
; cmp ax,0f1h
; jne @@wm1
call init_interference
pop ds
pop di
pop si
pop bp
ret
_initinterference ENDP
PUBLIC _dointerference
_dointerference PROC FAR
push bp
mov bp,sp
push si
push di
push ds
call do_interference
mov es,cs:memseg
mov ah,49h
int 21h
pop ds
pop di
pop si
pop bp
ret
_dointerference ENDP
PUBLIC _inittwk
_inittwk PROC FAR
push bp
mov bp,sp
push si
push di
push ds
;clear palette
mov dx,3c8h
xor al,al
out dx,al
inc dx
mov cx,768
@@1: out dx,al
loop @@1
;400 rows
mov dx,3d4h
mov ax,00009h
out dx,ax
;tweak
mov dx,3d4h
mov ax,00014h
out dx,ax
mov ax,0e317h
out dx,ax
mov dx,3c4h
mov ax,0604h
out dx,ax
;
mov dx,3c4h
mov ax,0f02h
out dx,ax
mov ax,0a000h
mov es,ax
xor di,di
mov cx,32768
xor ax,ax
rep stosw
;
pop ds
pop di
pop si
pop bp
ret
_inittwk ENDP
PUBLIC _lineblit
_lineblit PROC FAR
push bp
mov bp,sp
push si
push di
push ds
mov di,[bp+6]
mov es,[bp+8]
mov si,[bp+10]
mov ds,[bp+12]
zpl=0
REPT 4
mov dx,3c4h
mov ax,02h+(100h shl zpl)
out dx,ax
zzz=0
REPT 80/2
mov al,ds:[si+(zzz+0)*4+zpl]
mov ah,ds:[si+(zzz+1)*4+zpl]
mov es:[di+zzz],ax
zzz=zzz+2
ENDM
zpl=zpl+1
ENDM
pop ds
pop di
pop si
pop bp
ret
_lineblit ENDP
PUBLIC _setpalarea
_setpalarea PROC FAR
push bp
mov bp,sp
push si
push di
push ds
mov si,[bp+6]
mov ds,[bp+8]
mov ax,[bp+10]
mov dx,3c8h
out dx,al
inc dx
mov cx,[bp+12]
shl cx,1
add cx,ax
REPOUTSB
pop ds
pop di
pop si
pop bp
ret
_setpalarea ENDP
code ENDS
END
| 15.118199 | 76 | 0.610822 |
cc8786cae7cb99849212d6ab80185a898d086dec | 514 | asm | Assembly | oeis/113/A113605.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 11 | 2021-08-22T19:44:55.000Z | 2022-03-20T16:47:57.000Z | oeis/113/A113605.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 9 | 2021-08-29T13:15:54.000Z | 2022-03-09T19:52:31.000Z | oeis/113/A113605.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 3 | 2021-08-22T20:56:47.000Z | 2021-09-29T06:26:12.000Z | ; A113605: a(1) = a(2) = a(3) = 1; a(n) = a(n-3) + gcd(a(n-1), a(n-2)).
; Submitted by Christian Krause
; 1,1,1,2,2,3,3,5,4,4,9,5,5,14,6,7,15,7,8,16,15,9,19,16,10,21,17,11,22,28,13,23,29,14,24,31,15,25,36,16,29,37,17,30,38,19,49,39,20,50,49,21,57,52,22,59,53,23,60,54,29,61,55,30,66,61,31,67,62,32,69,63,35,76,64,39,77,65,40,82,67,41,83,68,42,85,69,43,86,112,45,87,115,46,110,117,47,111,118,48
mov $2,3
mov $3,3
lpb $0
sub $0,1
gcd $2,$1
add $2,$4
mov $4,$1
mov $1,$3
mov $3,$2
lpe
mov $0,$2
div $0,3
| 30.235294 | 289 | 0.581712 |
a03e8dc0f6ab3a001393d4e34a29451aa8313e12 | 1,440 | asm | Assembly | Lab Exam/First problem (another).asm | Deboraj-roy/COMPUTER-ORGANIZATION-AND-ARCHITECTURE-C- | 7ad0268edada61a648499557948d174ae1faea8b | [
"MIT"
] | null | null | null | Lab Exam/First problem (another).asm | Deboraj-roy/COMPUTER-ORGANIZATION-AND-ARCHITECTURE-C- | 7ad0268edada61a648499557948d174ae1faea8b | [
"MIT"
] | 1 | 2022-03-16T14:31:47.000Z | 2022-03-16T14:31:47.000Z | Lab Exam/First problem (another).asm | Deboraj-roy/COMPUTER-ORGANIZATION-AND-ARCHITECTURE-C- | 7ad0268edada61a648499557948d174ae1faea8b | [
"MIT"
] | null | null | null | .MODEL SMALL
.STACK 100H
.DATA
CR EQU 0DH
LF EQU 0AH
MSG1 DB CR,LF, 'ENTER FIRST NUMBER: $'
MSG2 DB CR,LF, 'ENTER SECOND NUMBER: $'
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
MOV AH,2
MOV DL,'?'
INT 21H
LEA DX,MSG1
MOV AH,9H
INT 21H
MOV AH,1H
INT 21H
MOV BL,AL
LEA DX,MSG2
MOV AH,9H
INT 21H
MOV AH,1H
INT 21H
MOV CL,AL
MOV AH,2H
CMP CL,BL
JGE GENAREL
JNG OPOSITE
GENAREL:
MOV DL,0DH
INT 21H
MOV DL,0AH
INT 21H
MOV DL,CL
INT 21H
MOV DL,0DH
INT 21H
MOV DL,0AH
INT 21H
MOV DL,BL
INT 21H
JMP EXIT
OPOSITE:
MOV DL,0DH
INT 21H
MOV DL,0AH
INT 21H
MOV DL,BL
INT 21H
MOV DL,0DH
INT 21H
MOV DL,0AH
INT 21H
MOV DL,CL
INT 21H
JMP EXIT
EXIT:
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
| 13.980583 | 43 | 0.333333 |
94688a62ce5dd04c87d03de4a63f86d9f2d7a6bd | 673 | asm | Assembly | oeis/138/A138523.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 11 | 2021-08-22T19:44:55.000Z | 2022-03-20T16:47:57.000Z | oeis/138/A138523.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 9 | 2021-08-29T13:15:54.000Z | 2022-03-09T19:52:31.000Z | oeis/138/A138523.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 3 | 2021-08-22T20:56:47.000Z | 2021-09-29T06:26:12.000Z | ; A138523: a(n) = Sum_{k=1..n} (2k-1)!.
; Submitted by Jamie Morken(w3)
; 1,7,127,5167,368047,40284847,6267305647,1313941673647,357001369769647,122002101778601647,51212944273488041647,25903229683158464681647,15537113273014144448681647,10904406563691366305216681647,8852666400303393320848832681647,8231691320578226211046411712681647,8691549310132464721729240812992681647,10341839515696277394388380578336192681647,13774094930742041323710367962159238592681647,20411656176128185399963992107865056595392681647,33472938269339935293570026045548616721747392681647
mov $1,1
mov $2,$0
add $2,1
add $2,$0
lpb $2
mul $1,$2
sub $2,1
mul $1,$2
add $1,1
sub $2,1
lpe
mov $0,$1
| 39.588235 | 483 | 0.833581 |
16f98d6f144aa350fdbc23138b04f257eb66db53 | 68,300 | asm | Assembly | ass3Tests.asm | chendoy/xv6-paging | 26618772394cf6a23aa0a357e862296f92096892 | [
"MIT-0"
] | null | null | null | ass3Tests.asm | chendoy/xv6-paging | 26618772394cf6a23aa0a357e862296f92096892 | [
"MIT-0"
] | null | null | null | ass3Tests.asm | chendoy/xv6-paging | 26618772394cf6a23aa0a357e862296f92096892 | [
"MIT-0"
] | null | null | null |
_ass3Tests: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
}
int
main(void)
{
0: 8d 4c 24 04 lea 0x4(%esp),%ecx
4: 83 e4 f0 and $0xfffffff0,%esp
7: ff 71 fc pushl -0x4(%ecx)
a: 55 push %ebp
b: 89 e5 mov %esp,%ebp
d: 51 push %ecx
e: 83 ec 04 sub $0x4,%esp
// simple_fork_test();
// pagefault_test();
// free_pages_test();
free_pages_with_swap_test(); // not relevant to selection=None
11: e8 ea 05 00 00 call 600 <free_pages_with_swap_test>
// num_pages_test();
// pagefault_cow_test();
// cow_refs_test();
// allocate_more_than_MaxPages_test(); // should pass only with selection=None
exit();
16: e8 f7 08 00 00 call 912 <exit>
1b: 66 90 xchg %ax,%ax
1d: 66 90 xchg %ax,%ax
1f: 90 nop
00000020 <simple_fork_test>:
{
20: 55 push %ebp
21: 89 e5 mov %esp,%ebp
23: 83 ec 10 sub $0x10,%esp
printf(1, "\n-------- simple_fork_test --------\n");
26: 68 c8 0d 00 00 push $0xdc8
2b: 6a 01 push $0x1
2d: e8 3e 0a 00 00 call a70 <printf>
pid = fork();
32: e8 d3 08 00 00 call 90a <fork>
if(pid == 0) // child
37: 83 c4 10 add $0x10,%esp
3a: 85 c0 test %eax,%eax
3c: 74 21 je 5f <simple_fork_test+0x3f>
sleep(20);
3e: 83 ec 0c sub $0xc,%esp
41: 6a 14 push $0x14
43: e8 5a 09 00 00 call 9a2 <sleep>
printf(1, "I'm parent!\n");
48: 58 pop %eax
49: 5a pop %edx
4a: 68 28 11 00 00 push $0x1128
4f: 6a 01 push $0x1
51: e8 1a 0a 00 00 call a70 <printf>
wait();
56: 83 c4 10 add $0x10,%esp
}
59: c9 leave
wait();
5a: e9 bb 08 00 00 jmp 91a <wait>
printf(1, "I'm child!\n");
5f: 51 push %ecx
60: 51 push %ecx
61: 68 1c 11 00 00 push $0x111c
66: 6a 01 push $0x1
68: e8 03 0a 00 00 call a70 <printf>
exit();
6d: e8 a0 08 00 00 call 912 <exit>
72: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
79: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000080 <free_pages_with_swap_test1>:
{
80: 55 push %ebp
81: 89 e5 mov %esp,%ebp
83: 53 push %ebx
84: 83 ec 04 sub $0x4,%esp
int init_free = getNumberOfFreePages();
87: e8 26 09 00 00 call 9b2 <getNumberOfFreePages>
printf(1, "init free pages: %d\n", init_free);
8c: 83 ec 04 sub $0x4,%esp
int init_free = getNumberOfFreePages();
8f: 89 c3 mov %eax,%ebx
printf(1, "init free pages: %d\n", init_free);
91: 50 push %eax
92: 68 35 11 00 00 push $0x1135
97: 6a 01 push $0x1
99: e8 d2 09 00 00 call a70 <printf>
printf(1, "sbrk res: %d\n", (sbrk(3 * PGSIZE)));
9e: c7 04 24 00 30 00 00 movl $0x3000,(%esp)
a5: e8 f0 08 00 00 call 99a <sbrk>
aa: 83 c4 0c add $0xc,%esp
ad: 50 push %eax
ae: 68 4a 11 00 00 push $0x114a
b3: 6a 01 push $0x1
b5: e8 b6 09 00 00 call a70 <printf>
printf(1, "sbrk res: %d\n", (sbrk(3 * PGSIZE)));
ba: c7 04 24 00 30 00 00 movl $0x3000,(%esp)
c1: e8 d4 08 00 00 call 99a <sbrk>
c6: 83 c4 0c add $0xc,%esp
c9: 50 push %eax
ca: 68 4a 11 00 00 push $0x114a
cf: 6a 01 push $0x1
d1: e8 9a 09 00 00 call a70 <printf>
printf(1, "sbrk res: %d\n", (sbrk(3 * PGSIZE)));
d6: c7 04 24 00 30 00 00 movl $0x3000,(%esp)
dd: e8 b8 08 00 00 call 99a <sbrk>
e2: 83 c4 0c add $0xc,%esp
e5: 50 push %eax
e6: 68 4a 11 00 00 push $0x114a
eb: 6a 01 push $0x1
ed: e8 7e 09 00 00 call a70 <printf>
printf(1, "allocated 9 pages. <should be: %d> <actually: %d>\n",init_free-9, getNumberOfFreePages());
f2: e8 bb 08 00 00 call 9b2 <getNumberOfFreePages>
f7: 50 push %eax
f8: 8d 43 f7 lea -0x9(%ebx),%eax
printf(1, "allocated 3 more pages. <should be: %d> <actually: %d>\n",init_free-12, getNumberOfFreePages());
fb: 83 eb 0c sub $0xc,%ebx
printf(1, "allocated 9 pages. <should be: %d> <actually: %d>\n",init_free-9, getNumberOfFreePages());
fe: 50 push %eax
ff: 68 f0 0d 00 00 push $0xdf0
104: 6a 01 push $0x1
106: e8 65 09 00 00 call a70 <printf>
printf(1, "a %d\n", (sbrk(3 * PGSIZE)));
10b: 83 c4 14 add $0x14,%esp
10e: 68 00 30 00 00 push $0x3000
113: e8 82 08 00 00 call 99a <sbrk>
118: 83 c4 0c add $0xc,%esp
11b: 50 push %eax
11c: 68 58 11 00 00 push $0x1158
121: 6a 01 push $0x1
123: e8 48 09 00 00 call a70 <printf>
printf(1, "allocated 3 more pages. <should be: %d> <actually: %d>\n",init_free-12, getNumberOfFreePages());
128: e8 85 08 00 00 call 9b2 <getNumberOfFreePages>
12d: 50 push %eax
12e: 53 push %ebx
12f: 68 24 0e 00 00 push $0xe24
134: 6a 01 push $0x1
136: e8 35 09 00 00 call a70 <printf>
printf(1, "sbrk res: %d\n", (sbrk(1 * PGSIZE)));
13b: 83 c4 14 add $0x14,%esp
13e: 68 00 10 00 00 push $0x1000
143: e8 52 08 00 00 call 99a <sbrk>
148: 83 c4 0c add $0xc,%esp
14b: 50 push %eax
14c: 68 4a 11 00 00 push $0x114a
151: 6a 01 push $0x1
153: e8 18 09 00 00 call a70 <printf>
printf(1, "allocated 1 more file, will swap page to disk. <should be: %d> <actually: %d> \n", init_free-12, getNumberOfFreePages());
158: e8 55 08 00 00 call 9b2 <getNumberOfFreePages>
15d: 50 push %eax
15e: 53 push %ebx
15f: 68 5c 0e 00 00 push $0xe5c
164: 6a 01 push $0x1
166: e8 05 09 00 00 call a70 <printf>
}
16b: 83 c4 20 add $0x20,%esp
16e: 8b 5d fc mov -0x4(%ebp),%ebx
171: c9 leave
172: c3 ret
173: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
179: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000180 <pagefault_test>:
{
180: 55 push %ebp
181: 89 e5 mov %esp,%ebp
183: 53 push %ebx
184: 83 ec 10 sub $0x10,%esp
char *arr = (char*)malloc(len);
187: 68 00 f0 00 00 push $0xf000
18c: e8 3f 0b 00 00 call cd0 <malloc>
memset((void*)arr, '0', len);
191: 83 c4 0c add $0xc,%esp
char *arr = (char*)malloc(len);
194: 89 c3 mov %eax,%ebx
memset((void*)arr, '0', len);
196: 68 00 f0 00 00 push $0xf000
19b: 6a 30 push $0x30
19d: 50 push %eax
19e: e8 cd 05 00 00 call 770 <memset>
printf(1,"arr[0]: %c\n", arr[0]);
1a3: 0f be 03 movsbl (%ebx),%eax
1a6: 83 c4 0c add $0xc,%esp
1a9: 50 push %eax
1aa: 68 5e 11 00 00 push $0x115e
1af: 6a 01 push $0x1
1b1: e8 ba 08 00 00 call a70 <printf>
printf(1,"arr[0]: %c\n", arr[len/2]);
1b6: 0f be 83 00 78 00 00 movsbl 0x7800(%ebx),%eax
1bd: 83 c4 0c add $0xc,%esp
1c0: 50 push %eax
1c1: 68 5e 11 00 00 push $0x115e
1c6: 6a 01 push $0x1
1c8: e8 a3 08 00 00 call a70 <printf>
printf(1,"arr[0]: %c\n", arr[len-1]);
1cd: 0f be 83 ff ef 00 00 movsbl 0xefff(%ebx),%eax
1d4: 83 c4 0c add $0xc,%esp
1d7: 50 push %eax
1d8: 68 5e 11 00 00 push $0x115e
1dd: 6a 01 push $0x1
1df: e8 8c 08 00 00 call a70 <printf>
return;
1e4: 83 c4 10 add $0x10,%esp
}
1e7: 8b 5d fc mov -0x4(%ebp),%ebx
1ea: c9 leave
1eb: c3 ret
1ec: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
000001f0 <pagefault_cow_test>:
{
1f0: 55 push %ebp
1f1: 89 e5 mov %esp,%ebp
1f3: 53 push %ebx
1f4: 83 ec 10 sub $0x10,%esp
char *arr = (char*)malloc(len);
1f7: 68 00 d0 00 00 push $0xd000
1fc: e8 cf 0a 00 00 call cd0 <malloc>
memset((void*)arr, '0', len); // will cause some pagefaults
201: 83 c4 0c add $0xc,%esp
char *arr = (char*)malloc(len);
204: 89 c3 mov %eax,%ebx
memset((void*)arr, '0', len); // will cause some pagefaults
206: 68 00 d0 00 00 push $0xd000
20b: 6a 30 push $0x30
20d: 50 push %eax
20e: e8 5d 05 00 00 call 770 <memset>
if((pid = fork()) == 0) // child
213: e8 f2 06 00 00 call 90a <fork>
218: 83 c4 10 add $0x10,%esp
21b: 85 c0 test %eax,%eax
21d: 74 37 je 256 <pagefault_cow_test+0x66>
wait();
21f: e8 f6 06 00 00 call 91a <wait>
printf(1, "parent: arr[0]: %c (should be \'0\')\n" ,arr[0]);
224: 0f be 03 movsbl (%ebx),%eax
227: 83 ec 04 sub $0x4,%esp
22a: 50 push %eax
22b: 68 b0 0e 00 00 push $0xeb0
230: 6a 01 push $0x1
232: e8 39 08 00 00 call a70 <printf>
printf(1, "parent: arr[1000]: %c (should be \'0\')\n",arr[1000]);
237: 0f be 83 e8 03 00 00 movsbl 0x3e8(%ebx),%eax
23e: 83 c4 0c add $0xc,%esp
241: 50 push %eax
242: 68 d4 0e 00 00 push $0xed4
247: 6a 01 push $0x1
249: e8 22 08 00 00 call a70 <printf>
return;
24e: 83 c4 10 add $0x10,%esp
}
251: 8b 5d fc mov -0x4(%ebp),%ebx
254: c9 leave
255: c3 ret
printf(1, "child: writing \'1\'s arr\n");
256: 50 push %eax
257: 50 push %eax
258: 68 6a 11 00 00 push $0x116a
25d: 6a 01 push $0x1
25f: e8 0c 08 00 00 call a70 <printf>
memset((void*)arr, '1', len);
264: 83 c4 0c add $0xc,%esp
267: 68 00 d0 00 00 push $0xd000
26c: 6a 31 push $0x31
26e: 53 push %ebx
26f: e8 fc 04 00 00 call 770 <memset>
exit();
274: e8 99 06 00 00 call 912 <exit>
279: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
00000280 <cow_refs_test>:
{
280: 55 push %ebp
281: 89 e5 mov %esp,%ebp
283: 53 push %ebx
284: 83 ec 10 sub $0x10,%esp
char *arr = (char*)malloc(len);
287: 68 00 80 00 00 push $0x8000
28c: e8 3f 0a 00 00 call cd0 <malloc>
memset((void*)arr, '0', len); // will cause some pagefaults
291: 83 c4 0c add $0xc,%esp
char *arr = (char*)malloc(len);
294: 89 c3 mov %eax,%ebx
memset((void*)arr, '0', len); // will cause some pagefaults
296: 68 00 80 00 00 push $0x8000
29b: 6a 30 push $0x30
29d: 50 push %eax
29e: e8 cd 04 00 00 call 770 <memset>
if((pid = fork()) == 0) // child
2a3: e8 62 06 00 00 call 90a <fork>
2a8: 83 c4 10 add $0x10,%esp
2ab: 85 c0 test %eax,%eax
2ad: 74 09 je 2b8 <cow_refs_test+0x38>
}
2af: 8b 5d fc mov -0x4(%ebp),%ebx
2b2: c9 leave
wait();
2b3: e9 62 06 00 00 jmp 91a <wait>
printf(1, "before child write on arr num ref of rampage[%d] is : %d\n",6 , getNumRefs(6));
2b8: 83 ec 0c sub $0xc,%esp
2bb: 6a 06 push $0x6
2bd: e8 f8 06 00 00 call 9ba <getNumRefs>
2c2: 50 push %eax
2c3: 6a 06 push $0x6
2c5: 68 fc 0e 00 00 push $0xefc
2ca: 6a 01 push $0x1
2cc: e8 9f 07 00 00 call a70 <printf>
memset((void*)arr, '1', len);
2d1: 83 c4 1c add $0x1c,%esp
2d4: 68 00 80 00 00 push $0x8000
2d9: 6a 31 push $0x31
2db: 53 push %ebx
2dc: e8 8f 04 00 00 call 770 <memset>
printf(1, "after child write on arr num ref of rampage[%d] is : %d\n",6, getNumRefs(6));
2e1: c7 04 24 06 00 00 00 movl $0x6,(%esp)
2e8: e8 cd 06 00 00 call 9ba <getNumRefs>
2ed: 50 push %eax
2ee: 6a 06 push $0x6
2f0: 68 38 0f 00 00 push $0xf38
2f5: 6a 01 push $0x1
2f7: e8 74 07 00 00 call a70 <printf>
exit();
2fc: 83 c4 20 add $0x20,%esp
2ff: e8 0e 06 00 00 call 912 <exit>
304: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
30a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00000310 <num_pages_test>:
{
310: 55 push %ebp
311: 89 e5 mov %esp,%ebp
313: 57 push %edi
314: 56 push %esi
315: 53 push %ebx
316: 83 ec 28 sub $0x28,%esp
char* oldbrk = sbrk(0);
319: 6a 00 push $0x0
31b: e8 7a 06 00 00 call 99a <sbrk>
320: 89 45 e4 mov %eax,-0x1c(%ebp)
printf(1, "sbrk test\n");
323: 58 pop %eax
324: 5a pop %edx
325: 68 83 11 00 00 push $0x1183
32a: 6a 01 push $0x1
32c: e8 3f 07 00 00 call a70 <printf>
printf(1, "allocating 10 pages, should not write to swap\n");
331: 59 pop %ecx
332: 5b pop %ebx
333: 68 74 0f 00 00 push $0xf74
338: 6a 01 push $0x1
33a: e8 31 07 00 00 call a70 <printf>
a = sbrk(0);
33f: c7 04 24 00 00 00 00 movl $0x0,(%esp)
346: e8 4f 06 00 00 call 99a <sbrk>
34b: 8d b0 00 c0 00 00 lea 0xc000(%eax),%esi
351: 89 c3 mov %eax,%ebx
353: 83 c4 10 add $0x10,%esp
356: 8d 76 00 lea 0x0(%esi),%esi
359: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
b = sbrk(PGSIZE);
360: 83 ec 0c sub $0xc,%esp
363: 68 00 10 00 00 push $0x1000
368: e8 2d 06 00 00 call 99a <sbrk>
printf(1, "%x -> ", b);
36d: 83 c4 0c add $0xc,%esp
b = sbrk(PGSIZE);
370: 89 c7 mov %eax,%edi
printf(1, "%x -> ", b);
372: 50 push %eax
373: 68 8e 11 00 00 push $0x118e
378: 6a 01 push $0x1
37a: e8 f1 06 00 00 call a70 <printf>
if(b != a){
37f: 83 c4 10 add $0x10,%esp
382: 39 df cmp %ebx,%edi
384: 75 2e jne 3b4 <num_pages_test+0xa4>
*b = 1;
386: c6 03 01 movb $0x1,(%ebx)
a = b + PGSIZE;
389: 81 c3 00 10 00 00 add $0x1000,%ebx
for(i = 0; i < 12; i++){
38f: 39 de cmp %ebx,%esi
391: 75 cd jne 360 <num_pages_test+0x50>
printf(1, "\ncreating child process\n");
393: 83 ec 08 sub $0x8,%esp
396: 68 95 11 00 00 push $0x1195
39b: 6a 01 push $0x1
39d: e8 ce 06 00 00 call a70 <printf>
pid = fork();
3a2: e8 63 05 00 00 call 90a <fork>
if(pid < 0){
3a7: 83 c4 10 add $0x10,%esp
3aa: 85 c0 test %eax,%eax
3ac: 0f 88 b5 01 00 00 js 567 <num_pages_test+0x257>
if(pid > 0) // parent will writeToSwapFile
3b2: 75 0c jne 3c0 <num_pages_test+0xb0>
exit();
3b4: e8 59 05 00 00 call 912 <exit>
3b9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
int ramPagesBefore = getNumberOfFreePages();
3c0: e8 ed 05 00 00 call 9b2 <getNumberOfFreePages>
c = sbrk(PGSIZE);
3c5: 83 ec 0c sub $0xc,%esp
int ramPagesBefore = getNumberOfFreePages();
3c8: 89 c3 mov %eax,%ebx
c = sbrk(PGSIZE);
3ca: 68 00 10 00 00 push $0x1000
3cf: e8 c6 05 00 00 call 99a <sbrk>
if(c != a){
3d4: 83 c4 10 add $0x10,%esp
3d7: 39 f0 cmp %esi,%eax
3d9: 0f 85 9b 01 00 00 jne 57a <num_pages_test+0x26a>
int ramPagesAfter = getNumberOfFreePages();
3df: e8 ce 05 00 00 call 9b2 <getNumberOfFreePages>
printf(1, "parent: %d should be equal to %d\n", ramPagesBefore, ramPagesAfter);
3e4: 50 push %eax
3e5: 53 push %ebx
3e6: 68 a4 0f 00 00 push $0xfa4
3eb: 6a 01 push $0x1
3ed: e8 7e 06 00 00 call a70 <printf>
wait();
3f2: e8 23 05 00 00 call 91a <wait>
printf(1, "*********************************\n");
3f7: 5f pop %edi
3f8: 58 pop %eax
3f9: 68 c8 0f 00 00 push $0xfc8
3fe: 6a 01 push $0x1
400: e8 6b 06 00 00 call a70 <printf>
a = sbrk(0);
405: c7 04 24 00 00 00 00 movl $0x0,(%esp)
40c: e8 89 05 00 00 call 99a <sbrk>
c = sbrk(-4096);
411: c7 04 24 00 f0 ff ff movl $0xfffff000,(%esp)
a = sbrk(0);
418: 89 c3 mov %eax,%ebx
c = sbrk(-4096);
41a: e8 7b 05 00 00 call 99a <sbrk>
if(c == (char*)0xffffffff){
41f: 83 c4 10 add $0x10,%esp
422: 83 f8 ff cmp $0xffffffff,%eax
425: 0f 84 62 01 00 00 je 58d <num_pages_test+0x27d>
printf(1, "*********************************\n");
42b: 83 ec 08 sub $0x8,%esp
42e: 68 c8 0f 00 00 push $0xfc8
433: 6a 01 push $0x1
435: e8 36 06 00 00 call a70 <printf>
c = sbrk(0);
43a: c7 04 24 00 00 00 00 movl $0x0,(%esp)
441: e8 54 05 00 00 call 99a <sbrk>
if(c != a - 4096){
446: 8d 93 00 f0 ff ff lea -0x1000(%ebx),%edx
44c: 83 c4 10 add $0x10,%esp
44f: 39 d0 cmp %edx,%eax
451: 0f 85 49 01 00 00 jne 5a0 <num_pages_test+0x290>
a = sbrk(0);
457: 83 ec 0c sub $0xc,%esp
45a: 6a 00 push $0x0
45c: e8 39 05 00 00 call 99a <sbrk>
461: 89 c3 mov %eax,%ebx
c = sbrk(4096);
463: c7 04 24 00 10 00 00 movl $0x1000,(%esp)
46a: e8 2b 05 00 00 call 99a <sbrk>
if(c != a || sbrk(0) != a + 4096){
46f: 83 c4 10 add $0x10,%esp
472: 39 c3 cmp %eax,%ebx
c = sbrk(4096);
474: 89 c6 mov %eax,%esi
if(c != a || sbrk(0) != a + 4096){
476: 0f 85 d8 00 00 00 jne 554 <num_pages_test+0x244>
47c: 83 ec 0c sub $0xc,%esp
47f: 6a 00 push $0x0
481: e8 14 05 00 00 call 99a <sbrk>
486: 8d 93 00 10 00 00 lea 0x1000(%ebx),%edx
48c: 83 c4 10 add $0x10,%esp
48f: 39 d0 cmp %edx,%eax
491: 0f 85 bd 00 00 00 jne 554 <num_pages_test+0x244>
char *curbrk = sbrk(0);
497: 83 ec 0c sub $0xc,%esp
49a: 6a 00 push $0x0
49c: e8 f9 04 00 00 call 99a <sbrk>
int size = curbrk - oldbrk;
4a1: 8b 75 e4 mov -0x1c(%ebp),%esi
4a4: 29 f0 sub %esi,%eax
4a6: 89 c3 mov %eax,%ebx
printf(1, "proc size in bytes: %d, in pages: %d\n", size, size / PGSIZE);
4a8: 8d 80 ff 0f 00 00 lea 0xfff(%eax),%eax
4ae: 85 db test %ebx,%ebx
4b0: 0f 49 c3 cmovns %ebx,%eax
4b3: c1 f8 0c sar $0xc,%eax
4b6: 50 push %eax
4b7: 53 push %ebx
4b8: 68 4c 10 00 00 push $0x104c
4bd: 6a 01 push $0x1
4bf: e8 ac 05 00 00 call a70 <printf>
printf(1, "filling mem with junk (should not cause pagefaults)\n");
4c4: 83 c4 18 add $0x18,%esp
4c7: 68 74 10 00 00 push $0x1074
4cc: 6a 01 push $0x1
4ce: e8 9d 05 00 00 call a70 <printf>
memset((void*)oldbrk, '1', size);
4d3: 83 c4 0c add $0xc,%esp
4d6: 53 push %ebx
4d7: 6a 31 push $0x31
4d9: 56 push %esi
4da: e8 91 02 00 00 call 770 <memset>
memset((void*)oldbrk, '$', size);
4df: 83 c4 0c add $0xc,%esp
4e2: 53 push %ebx
4e3: 6a 24 push $0x24
4e5: 56 push %esi
4e6: e8 85 02 00 00 call 770 <memset>
memset((void*)oldbrk, 3, size);
4eb: 83 c4 0c add $0xc,%esp
4ee: 53 push %ebx
4ef: 6a 03 push $0x3
4f1: 56 push %esi
4f2: e8 79 02 00 00 call 770 <memset>
printf(1, "*********************************\n");
4f7: 58 pop %eax
4f8: 5a pop %edx
4f9: 68 c8 0f 00 00 push $0xfc8
4fe: 6a 01 push $0x1
500: e8 6b 05 00 00 call a70 <printf>
printf(1, "alocating 3 more pages up to limit (16) - should cause 3 swaps\n");
505: 59 pop %ecx
506: 5b pop %ebx
507: 68 ac 10 00 00 push $0x10ac
50c: 6a 01 push $0x1
50e: e8 5d 05 00 00 call a70 <printf>
sbrk(3 * PGSIZE);
513: c7 04 24 00 30 00 00 movl $0x3000,(%esp)
51a: e8 7b 04 00 00 call 99a <sbrk>
curbrk = sbrk(0);
51f: c7 04 24 00 00 00 00 movl $0x0,(%esp)
526: e8 6f 04 00 00 call 99a <sbrk>
size = curbrk - oldbrk;
52b: 29 f0 sub %esi,%eax
printf(1, "proc size in bytes: %d, in pages: %d\n", size, size / PGSIZE);
52d: 8d 90 ff 0f 00 00 lea 0xfff(%eax),%edx
533: 85 c0 test %eax,%eax
535: 0f 49 d0 cmovns %eax,%edx
538: c1 fa 0c sar $0xc,%edx
53b: 52 push %edx
53c: 50 push %eax
53d: 68 4c 10 00 00 push $0x104c
542: 6a 01 push $0x1
544: e8 27 05 00 00 call a70 <printf>
return;
549: 83 c4 20 add $0x20,%esp
}
54c: 8d 65 f4 lea -0xc(%ebp),%esp
54f: 5b pop %ebx
550: 5e pop %esi
551: 5f pop %edi
552: 5d pop %ebp
553: c3 ret
printf(1, "sbrk re-allocation failed, a %x c %x\n", a, c);
554: 56 push %esi
555: 53 push %ebx
556: 68 24 10 00 00 push $0x1024
55b: 6a 01 push $0x1
55d: e8 0e 05 00 00 call a70 <printf>
exit();
562: e8 ab 03 00 00 call 912 <exit>
printf(1, "sbrk test fork failed\n");
567: 50 push %eax
568: 50 push %eax
569: 68 ae 11 00 00 push $0x11ae
56e: 6a 01 push $0x1
570: e8 fb 04 00 00 call a70 <printf>
exit();
575: e8 98 03 00 00 call 912 <exit>
printf(1, "sbrk test failed post-fork\n");
57a: 50 push %eax
57b: 50 push %eax
57c: 68 c5 11 00 00 push $0x11c5
581: 6a 01 push $0x1
583: e8 e8 04 00 00 call a70 <printf>
exit();
588: e8 85 03 00 00 call 912 <exit>
printf(1, "sbrk could not deallocate\n");
58d: 56 push %esi
58e: 56 push %esi
58f: 68 e1 11 00 00 push $0x11e1
594: 6a 01 push $0x1
596: e8 d5 04 00 00 call a70 <printf>
exit();
59b: e8 72 03 00 00 call 912 <exit>
printf(1, "sbrk deallocation produced wrong address, a %x c %x\n", a, c);
5a0: 50 push %eax
5a1: 53 push %ebx
5a2: 68 ec 0f 00 00 push $0xfec
5a7: 6a 01 push $0x1
5a9: e8 c2 04 00 00 call a70 <printf>
exit();
5ae: e8 5f 03 00 00 call 912 <exit>
5b3: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
5b9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000005c0 <free_pages_test>:
{
5c0: 55 push %ebp
5c1: 89 e5 mov %esp,%ebp
5c3: 53 push %ebx
5c4: 83 ec 04 sub $0x4,%esp
int init = getNumberOfFreePages();
5c7: e8 e6 03 00 00 call 9b2 <getNumberOfFreePages>
char *arr = sbrk(len);
5cc: 83 ec 0c sub $0xc,%esp
int init = getNumberOfFreePages();
5cf: 89 c3 mov %eax,%ebx
char *arr = sbrk(len);
5d1: 68 00 a0 00 00 push $0xa000
printf(1, "allocated %d files <expected: %d> <actual: %d>\n",len/PGSIZE, init - (len/PGSIZE), getNumberOfFreePages());
5d6: 83 eb 0a sub $0xa,%ebx
char *arr = sbrk(len);
5d9: e8 bc 03 00 00 call 99a <sbrk>
printf(1, "allocated %d files <expected: %d> <actual: %d>\n",len/PGSIZE, init - (len/PGSIZE), getNumberOfFreePages());
5de: e8 cf 03 00 00 call 9b2 <getNumberOfFreePages>
5e3: 89 04 24 mov %eax,(%esp)
5e6: 53 push %ebx
5e7: 6a 0a push $0xa
5e9: 68 ec 10 00 00 push $0x10ec
5ee: 6a 01 push $0x1
5f0: e8 7b 04 00 00 call a70 <printf>
}
5f5: 83 c4 20 add $0x20,%esp
5f8: 8b 5d fc mov -0x4(%ebp),%ebx
5fb: c9 leave
5fc: c3 ret
5fd: 8d 76 00 lea 0x0(%esi),%esi
00000600 <free_pages_with_swap_test>:
{
600: 55 push %ebp
601: 89 e5 mov %esp,%ebp
603: 53 push %ebx
604: 83 ec 04 sub $0x4,%esp
int init_free = getNumberOfFreePages();
607: e8 a6 03 00 00 call 9b2 <getNumberOfFreePages>
printf(1, "init free pages: %d\n", init_free);
60c: 83 ec 04 sub $0x4,%esp
int init_free = getNumberOfFreePages();
60f: 89 c3 mov %eax,%ebx
printf(1, "init free pages: %d\n", init_free);
611: 50 push %eax
612: 68 35 11 00 00 push $0x1135
617: 6a 01 push $0x1
619: e8 52 04 00 00 call a70 <printf>
sbrk(9 * PGSIZE);
61e: c7 04 24 00 90 00 00 movl $0x9000,(%esp)
625: e8 70 03 00 00 call 99a <sbrk>
printf(1, "allocated 9 pages. <should be: %d> <actually: %d>\n",init_free-9, getNumberOfFreePages());
62a: e8 83 03 00 00 call 9b2 <getNumberOfFreePages>
62f: 50 push %eax
630: 8d 43 f7 lea -0x9(%ebx),%eax
printf(1, "allocated 3 more pages. <should be: %d> <actually: %d>\n",init_free-12, getNumberOfFreePages());
633: 83 eb 0c sub $0xc,%ebx
printf(1, "allocated 9 pages. <should be: %d> <actually: %d>\n",init_free-9, getNumberOfFreePages());
636: 50 push %eax
637: 68 f0 0d 00 00 push $0xdf0
63c: 6a 01 push $0x1
63e: e8 2d 04 00 00 call a70 <printf>
sbrk(3 * PGSIZE);
643: 83 c4 14 add $0x14,%esp
646: 68 00 30 00 00 push $0x3000
64b: e8 4a 03 00 00 call 99a <sbrk>
printf(1, "allocated 3 more pages. <should be: %d> <actually: %d>\n",init_free-12, getNumberOfFreePages());
650: e8 5d 03 00 00 call 9b2 <getNumberOfFreePages>
655: 50 push %eax
656: 53 push %ebx
657: 68 24 0e 00 00 push $0xe24
65c: 6a 01 push $0x1
65e: e8 0d 04 00 00 call a70 <printf>
sbrk(1 * PGSIZE);
663: 83 c4 14 add $0x14,%esp
666: 68 00 10 00 00 push $0x1000
66b: e8 2a 03 00 00 call 99a <sbrk>
printf(1, "allocated 1 more file, will swap page to disk. <should be: %d> <actually: %d> \n", init_free-12, getNumberOfFreePages());
670: e8 3d 03 00 00 call 9b2 <getNumberOfFreePages>
675: 50 push %eax
676: 53 push %ebx
677: 68 5c 0e 00 00 push $0xe5c
67c: 6a 01 push $0x1
67e: e8 ed 03 00 00 call a70 <printf>
}
683: 83 c4 20 add $0x20,%esp
686: 8b 5d fc mov -0x4(%ebp),%ebx
689: c9 leave
68a: c3 ret
68b: 90 nop
68c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
00000690 <allocate_more_than_MaxPages_test>:
{
690: 55 push %ebp
691: 89 e5 mov %esp,%ebp
693: 83 ec 14 sub $0x14,%esp
printf(1, "sbrk res: %d\n", (sbrk(29 * PGSIZE)));
696: 68 00 d0 01 00 push $0x1d000
69b: e8 fa 02 00 00 call 99a <sbrk>
6a0: 83 c4 0c add $0xc,%esp
6a3: 50 push %eax
6a4: 68 4a 11 00 00 push $0x114a
6a9: 6a 01 push $0x1
6ab: e8 c0 03 00 00 call a70 <printf>
}
6b0: 83 c4 10 add $0x10,%esp
6b3: c9 leave
6b4: c3 ret
6b5: 66 90 xchg %ax,%ax
6b7: 66 90 xchg %ax,%ax
6b9: 66 90 xchg %ax,%ax
6bb: 66 90 xchg %ax,%ax
6bd: 66 90 xchg %ax,%ax
6bf: 90 nop
000006c0 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, const char *t)
{
6c0: 55 push %ebp
6c1: 89 e5 mov %esp,%ebp
6c3: 53 push %ebx
6c4: 8b 45 08 mov 0x8(%ebp),%eax
6c7: 8b 4d 0c mov 0xc(%ebp),%ecx
char *os;
os = s;
while((*s++ = *t++) != 0)
6ca: 89 c2 mov %eax,%edx
6cc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
6d0: 83 c1 01 add $0x1,%ecx
6d3: 0f b6 59 ff movzbl -0x1(%ecx),%ebx
6d7: 83 c2 01 add $0x1,%edx
6da: 84 db test %bl,%bl
6dc: 88 5a ff mov %bl,-0x1(%edx)
6df: 75 ef jne 6d0 <strcpy+0x10>
;
return os;
}
6e1: 5b pop %ebx
6e2: 5d pop %ebp
6e3: c3 ret
6e4: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
6ea: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
000006f0 <strcmp>:
int
strcmp(const char *p, const char *q)
{
6f0: 55 push %ebp
6f1: 89 e5 mov %esp,%ebp
6f3: 53 push %ebx
6f4: 8b 55 08 mov 0x8(%ebp),%edx
6f7: 8b 4d 0c mov 0xc(%ebp),%ecx
while(*p && *p == *q)
6fa: 0f b6 02 movzbl (%edx),%eax
6fd: 0f b6 19 movzbl (%ecx),%ebx
700: 84 c0 test %al,%al
702: 75 1c jne 720 <strcmp+0x30>
704: eb 2a jmp 730 <strcmp+0x40>
706: 8d 76 00 lea 0x0(%esi),%esi
709: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
p++, q++;
710: 83 c2 01 add $0x1,%edx
while(*p && *p == *q)
713: 0f b6 02 movzbl (%edx),%eax
p++, q++;
716: 83 c1 01 add $0x1,%ecx
719: 0f b6 19 movzbl (%ecx),%ebx
while(*p && *p == *q)
71c: 84 c0 test %al,%al
71e: 74 10 je 730 <strcmp+0x40>
720: 38 d8 cmp %bl,%al
722: 74 ec je 710 <strcmp+0x20>
return (uchar)*p - (uchar)*q;
724: 29 d8 sub %ebx,%eax
}
726: 5b pop %ebx
727: 5d pop %ebp
728: c3 ret
729: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
730: 31 c0 xor %eax,%eax
return (uchar)*p - (uchar)*q;
732: 29 d8 sub %ebx,%eax
}
734: 5b pop %ebx
735: 5d pop %ebp
736: c3 ret
737: 89 f6 mov %esi,%esi
739: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000740 <strlen>:
uint
strlen(const char *s)
{
740: 55 push %ebp
741: 89 e5 mov %esp,%ebp
743: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
for(n = 0; s[n]; n++)
746: 80 39 00 cmpb $0x0,(%ecx)
749: 74 15 je 760 <strlen+0x20>
74b: 31 d2 xor %edx,%edx
74d: 8d 76 00 lea 0x0(%esi),%esi
750: 83 c2 01 add $0x1,%edx
753: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1)
757: 89 d0 mov %edx,%eax
759: 75 f5 jne 750 <strlen+0x10>
;
return n;
}
75b: 5d pop %ebp
75c: c3 ret
75d: 8d 76 00 lea 0x0(%esi),%esi
for(n = 0; s[n]; n++)
760: 31 c0 xor %eax,%eax
}
762: 5d pop %ebp
763: c3 ret
764: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
76a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00000770 <memset>:
void*
memset(void *dst, int c, uint n)
{
770: 55 push %ebp
771: 89 e5 mov %esp,%ebp
773: 57 push %edi
774: 8b 55 08 mov 0x8(%ebp),%edx
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
777: 8b 4d 10 mov 0x10(%ebp),%ecx
77a: 8b 45 0c mov 0xc(%ebp),%eax
77d: 89 d7 mov %edx,%edi
77f: fc cld
780: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
782: 89 d0 mov %edx,%eax
784: 5f pop %edi
785: 5d pop %ebp
786: c3 ret
787: 89 f6 mov %esi,%esi
789: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000790 <strchr>:
char*
strchr(const char *s, char c)
{
790: 55 push %ebp
791: 89 e5 mov %esp,%ebp
793: 53 push %ebx
794: 8b 45 08 mov 0x8(%ebp),%eax
797: 8b 5d 0c mov 0xc(%ebp),%ebx
for(; *s; s++)
79a: 0f b6 10 movzbl (%eax),%edx
79d: 84 d2 test %dl,%dl
79f: 74 1d je 7be <strchr+0x2e>
if(*s == c)
7a1: 38 d3 cmp %dl,%bl
7a3: 89 d9 mov %ebx,%ecx
7a5: 75 0d jne 7b4 <strchr+0x24>
7a7: eb 17 jmp 7c0 <strchr+0x30>
7a9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
7b0: 38 ca cmp %cl,%dl
7b2: 74 0c je 7c0 <strchr+0x30>
for(; *s; s++)
7b4: 83 c0 01 add $0x1,%eax
7b7: 0f b6 10 movzbl (%eax),%edx
7ba: 84 d2 test %dl,%dl
7bc: 75 f2 jne 7b0 <strchr+0x20>
return (char*)s;
return 0;
7be: 31 c0 xor %eax,%eax
}
7c0: 5b pop %ebx
7c1: 5d pop %ebp
7c2: c3 ret
7c3: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
7c9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000007d0 <gets>:
char*
gets(char *buf, int max)
{
7d0: 55 push %ebp
7d1: 89 e5 mov %esp,%ebp
7d3: 57 push %edi
7d4: 56 push %esi
7d5: 53 push %ebx
int i, cc;
char c;
for(i=0; i+1 < max; ){
7d6: 31 f6 xor %esi,%esi
7d8: 89 f3 mov %esi,%ebx
{
7da: 83 ec 1c sub $0x1c,%esp
7dd: 8b 7d 08 mov 0x8(%ebp),%edi
for(i=0; i+1 < max; ){
7e0: eb 2f jmp 811 <gets+0x41>
7e2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
cc = read(0, &c, 1);
7e8: 8d 45 e7 lea -0x19(%ebp),%eax
7eb: 83 ec 04 sub $0x4,%esp
7ee: 6a 01 push $0x1
7f0: 50 push %eax
7f1: 6a 00 push $0x0
7f3: e8 32 01 00 00 call 92a <read>
if(cc < 1)
7f8: 83 c4 10 add $0x10,%esp
7fb: 85 c0 test %eax,%eax
7fd: 7e 1c jle 81b <gets+0x4b>
break;
buf[i++] = c;
7ff: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
803: 83 c7 01 add $0x1,%edi
806: 88 47 ff mov %al,-0x1(%edi)
if(c == '\n' || c == '\r')
809: 3c 0a cmp $0xa,%al
80b: 74 23 je 830 <gets+0x60>
80d: 3c 0d cmp $0xd,%al
80f: 74 1f je 830 <gets+0x60>
for(i=0; i+1 < max; ){
811: 83 c3 01 add $0x1,%ebx
814: 3b 5d 0c cmp 0xc(%ebp),%ebx
817: 89 fe mov %edi,%esi
819: 7c cd jl 7e8 <gets+0x18>
81b: 89 f3 mov %esi,%ebx
break;
}
buf[i] = '\0';
return buf;
}
81d: 8b 45 08 mov 0x8(%ebp),%eax
buf[i] = '\0';
820: c6 03 00 movb $0x0,(%ebx)
}
823: 8d 65 f4 lea -0xc(%ebp),%esp
826: 5b pop %ebx
827: 5e pop %esi
828: 5f pop %edi
829: 5d pop %ebp
82a: c3 ret
82b: 90 nop
82c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
830: 8b 75 08 mov 0x8(%ebp),%esi
833: 8b 45 08 mov 0x8(%ebp),%eax
836: 01 de add %ebx,%esi
838: 89 f3 mov %esi,%ebx
buf[i] = '\0';
83a: c6 03 00 movb $0x0,(%ebx)
}
83d: 8d 65 f4 lea -0xc(%ebp),%esp
840: 5b pop %ebx
841: 5e pop %esi
842: 5f pop %edi
843: 5d pop %ebp
844: c3 ret
845: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
849: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000850 <stat>:
int
stat(const char *n, struct stat *st)
{
850: 55 push %ebp
851: 89 e5 mov %esp,%ebp
853: 56 push %esi
854: 53 push %ebx
int fd;
int r;
fd = open(n, O_RDONLY);
855: 83 ec 08 sub $0x8,%esp
858: 6a 00 push $0x0
85a: ff 75 08 pushl 0x8(%ebp)
85d: e8 f0 00 00 00 call 952 <open>
if(fd < 0)
862: 83 c4 10 add $0x10,%esp
865: 85 c0 test %eax,%eax
867: 78 27 js 890 <stat+0x40>
return -1;
r = fstat(fd, st);
869: 83 ec 08 sub $0x8,%esp
86c: ff 75 0c pushl 0xc(%ebp)
86f: 89 c3 mov %eax,%ebx
871: 50 push %eax
872: e8 f3 00 00 00 call 96a <fstat>
close(fd);
877: 89 1c 24 mov %ebx,(%esp)
r = fstat(fd, st);
87a: 89 c6 mov %eax,%esi
close(fd);
87c: e8 b9 00 00 00 call 93a <close>
return r;
881: 83 c4 10 add $0x10,%esp
}
884: 8d 65 f8 lea -0x8(%ebp),%esp
887: 89 f0 mov %esi,%eax
889: 5b pop %ebx
88a: 5e pop %esi
88b: 5d pop %ebp
88c: c3 ret
88d: 8d 76 00 lea 0x0(%esi),%esi
return -1;
890: be ff ff ff ff mov $0xffffffff,%esi
895: eb ed jmp 884 <stat+0x34>
897: 89 f6 mov %esi,%esi
899: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000008a0 <atoi>:
int
atoi(const char *s)
{
8a0: 55 push %ebp
8a1: 89 e5 mov %esp,%ebp
8a3: 53 push %ebx
8a4: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
n = 0;
while('0' <= *s && *s <= '9')
8a7: 0f be 11 movsbl (%ecx),%edx
8aa: 8d 42 d0 lea -0x30(%edx),%eax
8ad: 3c 09 cmp $0x9,%al
n = 0;
8af: b8 00 00 00 00 mov $0x0,%eax
while('0' <= *s && *s <= '9')
8b4: 77 1f ja 8d5 <atoi+0x35>
8b6: 8d 76 00 lea 0x0(%esi),%esi
8b9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
n = n*10 + *s++ - '0';
8c0: 8d 04 80 lea (%eax,%eax,4),%eax
8c3: 83 c1 01 add $0x1,%ecx
8c6: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax
while('0' <= *s && *s <= '9')
8ca: 0f be 11 movsbl (%ecx),%edx
8cd: 8d 5a d0 lea -0x30(%edx),%ebx
8d0: 80 fb 09 cmp $0x9,%bl
8d3: 76 eb jbe 8c0 <atoi+0x20>
return n;
}
8d5: 5b pop %ebx
8d6: 5d pop %ebp
8d7: c3 ret
8d8: 90 nop
8d9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
000008e0 <memmove>:
void*
memmove(void *vdst, const void *vsrc, int n)
{
8e0: 55 push %ebp
8e1: 89 e5 mov %esp,%ebp
8e3: 56 push %esi
8e4: 53 push %ebx
8e5: 8b 5d 10 mov 0x10(%ebp),%ebx
8e8: 8b 45 08 mov 0x8(%ebp),%eax
8eb: 8b 75 0c mov 0xc(%ebp),%esi
char *dst;
const char *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
8ee: 85 db test %ebx,%ebx
8f0: 7e 14 jle 906 <memmove+0x26>
8f2: 31 d2 xor %edx,%edx
8f4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
*dst++ = *src++;
8f8: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx
8fc: 88 0c 10 mov %cl,(%eax,%edx,1)
8ff: 83 c2 01 add $0x1,%edx
while(n-- > 0)
902: 39 d3 cmp %edx,%ebx
904: 75 f2 jne 8f8 <memmove+0x18>
return vdst;
}
906: 5b pop %ebx
907: 5e pop %esi
908: 5d pop %ebp
909: c3 ret
0000090a <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
90a: b8 01 00 00 00 mov $0x1,%eax
90f: cd 40 int $0x40
911: c3 ret
00000912 <exit>:
SYSCALL(exit)
912: b8 02 00 00 00 mov $0x2,%eax
917: cd 40 int $0x40
919: c3 ret
0000091a <wait>:
SYSCALL(wait)
91a: b8 03 00 00 00 mov $0x3,%eax
91f: cd 40 int $0x40
921: c3 ret
00000922 <pipe>:
SYSCALL(pipe)
922: b8 04 00 00 00 mov $0x4,%eax
927: cd 40 int $0x40
929: c3 ret
0000092a <read>:
SYSCALL(read)
92a: b8 05 00 00 00 mov $0x5,%eax
92f: cd 40 int $0x40
931: c3 ret
00000932 <write>:
SYSCALL(write)
932: b8 10 00 00 00 mov $0x10,%eax
937: cd 40 int $0x40
939: c3 ret
0000093a <close>:
SYSCALL(close)
93a: b8 15 00 00 00 mov $0x15,%eax
93f: cd 40 int $0x40
941: c3 ret
00000942 <kill>:
SYSCALL(kill)
942: b8 06 00 00 00 mov $0x6,%eax
947: cd 40 int $0x40
949: c3 ret
0000094a <exec>:
SYSCALL(exec)
94a: b8 07 00 00 00 mov $0x7,%eax
94f: cd 40 int $0x40
951: c3 ret
00000952 <open>:
SYSCALL(open)
952: b8 0f 00 00 00 mov $0xf,%eax
957: cd 40 int $0x40
959: c3 ret
0000095a <mknod>:
SYSCALL(mknod)
95a: b8 11 00 00 00 mov $0x11,%eax
95f: cd 40 int $0x40
961: c3 ret
00000962 <unlink>:
SYSCALL(unlink)
962: b8 12 00 00 00 mov $0x12,%eax
967: cd 40 int $0x40
969: c3 ret
0000096a <fstat>:
SYSCALL(fstat)
96a: b8 08 00 00 00 mov $0x8,%eax
96f: cd 40 int $0x40
971: c3 ret
00000972 <link>:
SYSCALL(link)
972: b8 13 00 00 00 mov $0x13,%eax
977: cd 40 int $0x40
979: c3 ret
0000097a <mkdir>:
SYSCALL(mkdir)
97a: b8 14 00 00 00 mov $0x14,%eax
97f: cd 40 int $0x40
981: c3 ret
00000982 <chdir>:
SYSCALL(chdir)
982: b8 09 00 00 00 mov $0x9,%eax
987: cd 40 int $0x40
989: c3 ret
0000098a <dup>:
SYSCALL(dup)
98a: b8 0a 00 00 00 mov $0xa,%eax
98f: cd 40 int $0x40
991: c3 ret
00000992 <getpid>:
SYSCALL(getpid)
992: b8 0b 00 00 00 mov $0xb,%eax
997: cd 40 int $0x40
999: c3 ret
0000099a <sbrk>:
SYSCALL(sbrk)
99a: b8 0c 00 00 00 mov $0xc,%eax
99f: cd 40 int $0x40
9a1: c3 ret
000009a2 <sleep>:
SYSCALL(sleep)
9a2: b8 0d 00 00 00 mov $0xd,%eax
9a7: cd 40 int $0x40
9a9: c3 ret
000009aa <uptime>:
SYSCALL(uptime)
9aa: b8 0e 00 00 00 mov $0xe,%eax
9af: cd 40 int $0x40
9b1: c3 ret
000009b2 <getNumberOfFreePages>:
SYSCALL(getNumberOfFreePages)
9b2: b8 17 00 00 00 mov $0x17,%eax
9b7: cd 40 int $0x40
9b9: c3 ret
000009ba <getNumRefs>:
9ba: b8 18 00 00 00 mov $0x18,%eax
9bf: cd 40 int $0x40
9c1: c3 ret
9c2: 66 90 xchg %ax,%ax
9c4: 66 90 xchg %ax,%ax
9c6: 66 90 xchg %ax,%ax
9c8: 66 90 xchg %ax,%ax
9ca: 66 90 xchg %ax,%ax
9cc: 66 90 xchg %ax,%ax
9ce: 66 90 xchg %ax,%ax
000009d0 <printint>:
write(fd, &c, 1);
}
static void
printint(int fd, int xx, int base, int sgn)
{
9d0: 55 push %ebp
9d1: 89 e5 mov %esp,%ebp
9d3: 57 push %edi
9d4: 56 push %esi
9d5: 53 push %ebx
9d6: 83 ec 3c sub $0x3c,%esp
char buf[16];
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
9d9: 85 d2 test %edx,%edx
{
9db: 89 45 c0 mov %eax,-0x40(%ebp)
neg = 1;
x = -xx;
9de: 89 d0 mov %edx,%eax
if(sgn && xx < 0){
9e0: 79 76 jns a58 <printint+0x88>
9e2: f6 45 08 01 testb $0x1,0x8(%ebp)
9e6: 74 70 je a58 <printint+0x88>
x = -xx;
9e8: f7 d8 neg %eax
neg = 1;
9ea: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp)
} else {
x = xx;
}
i = 0;
9f1: 31 f6 xor %esi,%esi
9f3: 8d 5d d7 lea -0x29(%ebp),%ebx
9f6: eb 0a jmp a02 <printint+0x32>
9f8: 90 nop
9f9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
do{
buf[i++] = digits[x % base];
a00: 89 fe mov %edi,%esi
a02: 31 d2 xor %edx,%edx
a04: 8d 7e 01 lea 0x1(%esi),%edi
a07: f7 f1 div %ecx
a09: 0f b6 92 04 12 00 00 movzbl 0x1204(%edx),%edx
}while((x /= base) != 0);
a10: 85 c0 test %eax,%eax
buf[i++] = digits[x % base];
a12: 88 14 3b mov %dl,(%ebx,%edi,1)
}while((x /= base) != 0);
a15: 75 e9 jne a00 <printint+0x30>
if(neg)
a17: 8b 45 c4 mov -0x3c(%ebp),%eax
a1a: 85 c0 test %eax,%eax
a1c: 74 08 je a26 <printint+0x56>
buf[i++] = '-';
a1e: c6 44 3d d8 2d movb $0x2d,-0x28(%ebp,%edi,1)
a23: 8d 7e 02 lea 0x2(%esi),%edi
a26: 8d 74 3d d7 lea -0x29(%ebp,%edi,1),%esi
a2a: 8b 7d c0 mov -0x40(%ebp),%edi
a2d: 8d 76 00 lea 0x0(%esi),%esi
a30: 0f b6 06 movzbl (%esi),%eax
write(fd, &c, 1);
a33: 83 ec 04 sub $0x4,%esp
a36: 83 ee 01 sub $0x1,%esi
a39: 6a 01 push $0x1
a3b: 53 push %ebx
a3c: 57 push %edi
a3d: 88 45 d7 mov %al,-0x29(%ebp)
a40: e8 ed fe ff ff call 932 <write>
while(--i >= 0)
a45: 83 c4 10 add $0x10,%esp
a48: 39 de cmp %ebx,%esi
a4a: 75 e4 jne a30 <printint+0x60>
putc(fd, buf[i]);
}
a4c: 8d 65 f4 lea -0xc(%ebp),%esp
a4f: 5b pop %ebx
a50: 5e pop %esi
a51: 5f pop %edi
a52: 5d pop %ebp
a53: c3 ret
a54: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
neg = 0;
a58: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp)
a5f: eb 90 jmp 9f1 <printint+0x21>
a61: eb 0d jmp a70 <printf>
a63: 90 nop
a64: 90 nop
a65: 90 nop
a66: 90 nop
a67: 90 nop
a68: 90 nop
a69: 90 nop
a6a: 90 nop
a6b: 90 nop
a6c: 90 nop
a6d: 90 nop
a6e: 90 nop
a6f: 90 nop
00000a70 <printf>:
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, const char *fmt, ...)
{
a70: 55 push %ebp
a71: 89 e5 mov %esp,%ebp
a73: 57 push %edi
a74: 56 push %esi
a75: 53 push %ebx
a76: 83 ec 2c sub $0x2c,%esp
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
a79: 8b 75 0c mov 0xc(%ebp),%esi
a7c: 0f b6 1e movzbl (%esi),%ebx
a7f: 84 db test %bl,%bl
a81: 0f 84 b3 00 00 00 je b3a <printf+0xca>
ap = (uint*)(void*)&fmt + 1;
a87: 8d 45 10 lea 0x10(%ebp),%eax
a8a: 83 c6 01 add $0x1,%esi
state = 0;
a8d: 31 ff xor %edi,%edi
ap = (uint*)(void*)&fmt + 1;
a8f: 89 45 d4 mov %eax,-0x2c(%ebp)
a92: eb 2f jmp ac3 <printf+0x53>
a94: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
a98: 83 f8 25 cmp $0x25,%eax
a9b: 0f 84 a7 00 00 00 je b48 <printf+0xd8>
write(fd, &c, 1);
aa1: 8d 45 e2 lea -0x1e(%ebp),%eax
aa4: 83 ec 04 sub $0x4,%esp
aa7: 88 5d e2 mov %bl,-0x1e(%ebp)
aaa: 6a 01 push $0x1
aac: 50 push %eax
aad: ff 75 08 pushl 0x8(%ebp)
ab0: e8 7d fe ff ff call 932 <write>
ab5: 83 c4 10 add $0x10,%esp
ab8: 83 c6 01 add $0x1,%esi
for(i = 0; fmt[i]; i++){
abb: 0f b6 5e ff movzbl -0x1(%esi),%ebx
abf: 84 db test %bl,%bl
ac1: 74 77 je b3a <printf+0xca>
if(state == 0){
ac3: 85 ff test %edi,%edi
c = fmt[i] & 0xff;
ac5: 0f be cb movsbl %bl,%ecx
ac8: 0f b6 c3 movzbl %bl,%eax
if(state == 0){
acb: 74 cb je a98 <printf+0x28>
state = '%';
} else {
putc(fd, c);
}
} else if(state == '%'){
acd: 83 ff 25 cmp $0x25,%edi
ad0: 75 e6 jne ab8 <printf+0x48>
if(c == 'd'){
ad2: 83 f8 64 cmp $0x64,%eax
ad5: 0f 84 05 01 00 00 je be0 <printf+0x170>
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
adb: 81 e1 f7 00 00 00 and $0xf7,%ecx
ae1: 83 f9 70 cmp $0x70,%ecx
ae4: 74 72 je b58 <printf+0xe8>
printint(fd, *ap, 16, 0);
ap++;
} else if(c == 's'){
ae6: 83 f8 73 cmp $0x73,%eax
ae9: 0f 84 99 00 00 00 je b88 <printf+0x118>
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
aef: 83 f8 63 cmp $0x63,%eax
af2: 0f 84 08 01 00 00 je c00 <printf+0x190>
putc(fd, *ap);
ap++;
} else if(c == '%'){
af8: 83 f8 25 cmp $0x25,%eax
afb: 0f 84 ef 00 00 00 je bf0 <printf+0x180>
write(fd, &c, 1);
b01: 8d 45 e7 lea -0x19(%ebp),%eax
b04: 83 ec 04 sub $0x4,%esp
b07: c6 45 e7 25 movb $0x25,-0x19(%ebp)
b0b: 6a 01 push $0x1
b0d: 50 push %eax
b0e: ff 75 08 pushl 0x8(%ebp)
b11: e8 1c fe ff ff call 932 <write>
b16: 83 c4 0c add $0xc,%esp
b19: 8d 45 e6 lea -0x1a(%ebp),%eax
b1c: 88 5d e6 mov %bl,-0x1a(%ebp)
b1f: 6a 01 push $0x1
b21: 50 push %eax
b22: ff 75 08 pushl 0x8(%ebp)
b25: 83 c6 01 add $0x1,%esi
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
b28: 31 ff xor %edi,%edi
write(fd, &c, 1);
b2a: e8 03 fe ff ff call 932 <write>
for(i = 0; fmt[i]; i++){
b2f: 0f b6 5e ff movzbl -0x1(%esi),%ebx
write(fd, &c, 1);
b33: 83 c4 10 add $0x10,%esp
for(i = 0; fmt[i]; i++){
b36: 84 db test %bl,%bl
b38: 75 89 jne ac3 <printf+0x53>
}
}
}
b3a: 8d 65 f4 lea -0xc(%ebp),%esp
b3d: 5b pop %ebx
b3e: 5e pop %esi
b3f: 5f pop %edi
b40: 5d pop %ebp
b41: c3 ret
b42: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
state = '%';
b48: bf 25 00 00 00 mov $0x25,%edi
b4d: e9 66 ff ff ff jmp ab8 <printf+0x48>
b52: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
printint(fd, *ap, 16, 0);
b58: 83 ec 0c sub $0xc,%esp
b5b: b9 10 00 00 00 mov $0x10,%ecx
b60: 6a 00 push $0x0
b62: 8b 7d d4 mov -0x2c(%ebp),%edi
b65: 8b 45 08 mov 0x8(%ebp),%eax
b68: 8b 17 mov (%edi),%edx
b6a: e8 61 fe ff ff call 9d0 <printint>
ap++;
b6f: 89 f8 mov %edi,%eax
b71: 83 c4 10 add $0x10,%esp
state = 0;
b74: 31 ff xor %edi,%edi
ap++;
b76: 83 c0 04 add $0x4,%eax
b79: 89 45 d4 mov %eax,-0x2c(%ebp)
b7c: e9 37 ff ff ff jmp ab8 <printf+0x48>
b81: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
s = (char*)*ap;
b88: 8b 45 d4 mov -0x2c(%ebp),%eax
b8b: 8b 08 mov (%eax),%ecx
ap++;
b8d: 83 c0 04 add $0x4,%eax
b90: 89 45 d4 mov %eax,-0x2c(%ebp)
if(s == 0)
b93: 85 c9 test %ecx,%ecx
b95: 0f 84 8e 00 00 00 je c29 <printf+0x1b9>
while(*s != 0){
b9b: 0f b6 01 movzbl (%ecx),%eax
state = 0;
b9e: 31 ff xor %edi,%edi
s = (char*)*ap;
ba0: 89 cb mov %ecx,%ebx
while(*s != 0){
ba2: 84 c0 test %al,%al
ba4: 0f 84 0e ff ff ff je ab8 <printf+0x48>
baa: 89 75 d0 mov %esi,-0x30(%ebp)
bad: 89 de mov %ebx,%esi
baf: 8b 5d 08 mov 0x8(%ebp),%ebx
bb2: 8d 7d e3 lea -0x1d(%ebp),%edi
bb5: 8d 76 00 lea 0x0(%esi),%esi
write(fd, &c, 1);
bb8: 83 ec 04 sub $0x4,%esp
s++;
bbb: 83 c6 01 add $0x1,%esi
bbe: 88 45 e3 mov %al,-0x1d(%ebp)
write(fd, &c, 1);
bc1: 6a 01 push $0x1
bc3: 57 push %edi
bc4: 53 push %ebx
bc5: e8 68 fd ff ff call 932 <write>
while(*s != 0){
bca: 0f b6 06 movzbl (%esi),%eax
bcd: 83 c4 10 add $0x10,%esp
bd0: 84 c0 test %al,%al
bd2: 75 e4 jne bb8 <printf+0x148>
bd4: 8b 75 d0 mov -0x30(%ebp),%esi
state = 0;
bd7: 31 ff xor %edi,%edi
bd9: e9 da fe ff ff jmp ab8 <printf+0x48>
bde: 66 90 xchg %ax,%ax
printint(fd, *ap, 10, 1);
be0: 83 ec 0c sub $0xc,%esp
be3: b9 0a 00 00 00 mov $0xa,%ecx
be8: 6a 01 push $0x1
bea: e9 73 ff ff ff jmp b62 <printf+0xf2>
bef: 90 nop
write(fd, &c, 1);
bf0: 83 ec 04 sub $0x4,%esp
bf3: 88 5d e5 mov %bl,-0x1b(%ebp)
bf6: 8d 45 e5 lea -0x1b(%ebp),%eax
bf9: 6a 01 push $0x1
bfb: e9 21 ff ff ff jmp b21 <printf+0xb1>
putc(fd, *ap);
c00: 8b 7d d4 mov -0x2c(%ebp),%edi
write(fd, &c, 1);
c03: 83 ec 04 sub $0x4,%esp
putc(fd, *ap);
c06: 8b 07 mov (%edi),%eax
write(fd, &c, 1);
c08: 6a 01 push $0x1
ap++;
c0a: 83 c7 04 add $0x4,%edi
putc(fd, *ap);
c0d: 88 45 e4 mov %al,-0x1c(%ebp)
write(fd, &c, 1);
c10: 8d 45 e4 lea -0x1c(%ebp),%eax
c13: 50 push %eax
c14: ff 75 08 pushl 0x8(%ebp)
c17: e8 16 fd ff ff call 932 <write>
ap++;
c1c: 89 7d d4 mov %edi,-0x2c(%ebp)
c1f: 83 c4 10 add $0x10,%esp
state = 0;
c22: 31 ff xor %edi,%edi
c24: e9 8f fe ff ff jmp ab8 <printf+0x48>
s = "(null)";
c29: bb fc 11 00 00 mov $0x11fc,%ebx
while(*s != 0){
c2e: b8 28 00 00 00 mov $0x28,%eax
c33: e9 72 ff ff ff jmp baa <printf+0x13a>
c38: 66 90 xchg %ax,%ax
c3a: 66 90 xchg %ax,%ax
c3c: 66 90 xchg %ax,%ax
c3e: 66 90 xchg %ax,%ax
00000c40 <free>:
static Header base;
static Header *freep;
void
free(void *ap)
{
c40: 55 push %ebp
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
c41: a1 fc 15 00 00 mov 0x15fc,%eax
{
c46: 89 e5 mov %esp,%ebp
c48: 57 push %edi
c49: 56 push %esi
c4a: 53 push %ebx
c4b: 8b 5d 08 mov 0x8(%ebp),%ebx
bp = (Header*)ap - 1;
c4e: 8d 4b f8 lea -0x8(%ebx),%ecx
c51: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
c58: 39 c8 cmp %ecx,%eax
c5a: 8b 10 mov (%eax),%edx
c5c: 73 32 jae c90 <free+0x50>
c5e: 39 d1 cmp %edx,%ecx
c60: 72 04 jb c66 <free+0x26>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
c62: 39 d0 cmp %edx,%eax
c64: 72 32 jb c98 <free+0x58>
break;
if(bp + bp->s.size == p->s.ptr){
c66: 8b 73 fc mov -0x4(%ebx),%esi
c69: 8d 3c f1 lea (%ecx,%esi,8),%edi
c6c: 39 fa cmp %edi,%edx
c6e: 74 30 je ca0 <free+0x60>
bp->s.size += p->s.ptr->s.size;
bp->s.ptr = p->s.ptr->s.ptr;
} else
bp->s.ptr = p->s.ptr;
c70: 89 53 f8 mov %edx,-0x8(%ebx)
if(p + p->s.size == bp){
c73: 8b 50 04 mov 0x4(%eax),%edx
c76: 8d 34 d0 lea (%eax,%edx,8),%esi
c79: 39 f1 cmp %esi,%ecx
c7b: 74 3a je cb7 <free+0x77>
p->s.size += bp->s.size;
p->s.ptr = bp->s.ptr;
} else
p->s.ptr = bp;
c7d: 89 08 mov %ecx,(%eax)
freep = p;
c7f: a3 fc 15 00 00 mov %eax,0x15fc
}
c84: 5b pop %ebx
c85: 5e pop %esi
c86: 5f pop %edi
c87: 5d pop %ebp
c88: c3 ret
c89: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
c90: 39 d0 cmp %edx,%eax
c92: 72 04 jb c98 <free+0x58>
c94: 39 d1 cmp %edx,%ecx
c96: 72 ce jb c66 <free+0x26>
{
c98: 89 d0 mov %edx,%eax
c9a: eb bc jmp c58 <free+0x18>
c9c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
bp->s.size += p->s.ptr->s.size;
ca0: 03 72 04 add 0x4(%edx),%esi
ca3: 89 73 fc mov %esi,-0x4(%ebx)
bp->s.ptr = p->s.ptr->s.ptr;
ca6: 8b 10 mov (%eax),%edx
ca8: 8b 12 mov (%edx),%edx
caa: 89 53 f8 mov %edx,-0x8(%ebx)
if(p + p->s.size == bp){
cad: 8b 50 04 mov 0x4(%eax),%edx
cb0: 8d 34 d0 lea (%eax,%edx,8),%esi
cb3: 39 f1 cmp %esi,%ecx
cb5: 75 c6 jne c7d <free+0x3d>
p->s.size += bp->s.size;
cb7: 03 53 fc add -0x4(%ebx),%edx
freep = p;
cba: a3 fc 15 00 00 mov %eax,0x15fc
p->s.size += bp->s.size;
cbf: 89 50 04 mov %edx,0x4(%eax)
p->s.ptr = bp->s.ptr;
cc2: 8b 53 f8 mov -0x8(%ebx),%edx
cc5: 89 10 mov %edx,(%eax)
}
cc7: 5b pop %ebx
cc8: 5e pop %esi
cc9: 5f pop %edi
cca: 5d pop %ebp
ccb: c3 ret
ccc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
00000cd0 <malloc>:
return freep;
}
void*
malloc(uint nbytes)
{
cd0: 55 push %ebp
cd1: 89 e5 mov %esp,%ebp
cd3: 57 push %edi
cd4: 56 push %esi
cd5: 53 push %ebx
cd6: 83 ec 0c sub $0xc,%esp
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
cd9: 8b 45 08 mov 0x8(%ebp),%eax
if((prevp = freep) == 0){
cdc: 8b 15 fc 15 00 00 mov 0x15fc,%edx
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
ce2: 8d 78 07 lea 0x7(%eax),%edi
ce5: c1 ef 03 shr $0x3,%edi
ce8: 83 c7 01 add $0x1,%edi
if((prevp = freep) == 0){
ceb: 85 d2 test %edx,%edx
ced: 0f 84 9d 00 00 00 je d90 <malloc+0xc0>
cf3: 8b 02 mov (%edx),%eax
cf5: 8b 48 04 mov 0x4(%eax),%ecx
base.s.ptr = freep = prevp = &base;
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
if(p->s.size >= nunits){
cf8: 39 cf cmp %ecx,%edi
cfa: 76 6c jbe d68 <malloc+0x98>
cfc: 81 ff 00 10 00 00 cmp $0x1000,%edi
d02: bb 00 10 00 00 mov $0x1000,%ebx
d07: 0f 43 df cmovae %edi,%ebx
p = sbrk(nu * sizeof(Header));
d0a: 8d 34 dd 00 00 00 00 lea 0x0(,%ebx,8),%esi
d11: eb 0e jmp d21 <malloc+0x51>
d13: 90 nop
d14: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
d18: 8b 02 mov (%edx),%eax
if(p->s.size >= nunits){
d1a: 8b 48 04 mov 0x4(%eax),%ecx
d1d: 39 f9 cmp %edi,%ecx
d1f: 73 47 jae d68 <malloc+0x98>
p->s.size = nunits;
}
freep = prevp;
return (void*)(p + 1);
}
if(p == freep)
d21: 39 05 fc 15 00 00 cmp %eax,0x15fc
d27: 89 c2 mov %eax,%edx
d29: 75 ed jne d18 <malloc+0x48>
p = sbrk(nu * sizeof(Header));
d2b: 83 ec 0c sub $0xc,%esp
d2e: 56 push %esi
d2f: e8 66 fc ff ff call 99a <sbrk>
if(p == (char*)-1)
d34: 83 c4 10 add $0x10,%esp
d37: 83 f8 ff cmp $0xffffffff,%eax
d3a: 74 1c je d58 <malloc+0x88>
hp->s.size = nu;
d3c: 89 58 04 mov %ebx,0x4(%eax)
free((void*)(hp + 1));
d3f: 83 ec 0c sub $0xc,%esp
d42: 83 c0 08 add $0x8,%eax
d45: 50 push %eax
d46: e8 f5 fe ff ff call c40 <free>
return freep;
d4b: 8b 15 fc 15 00 00 mov 0x15fc,%edx
if((p = morecore(nunits)) == 0)
d51: 83 c4 10 add $0x10,%esp
d54: 85 d2 test %edx,%edx
d56: 75 c0 jne d18 <malloc+0x48>
return 0;
}
}
d58: 8d 65 f4 lea -0xc(%ebp),%esp
return 0;
d5b: 31 c0 xor %eax,%eax
}
d5d: 5b pop %ebx
d5e: 5e pop %esi
d5f: 5f pop %edi
d60: 5d pop %ebp
d61: c3 ret
d62: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
if(p->s.size == nunits)
d68: 39 cf cmp %ecx,%edi
d6a: 74 54 je dc0 <malloc+0xf0>
p->s.size -= nunits;
d6c: 29 f9 sub %edi,%ecx
d6e: 89 48 04 mov %ecx,0x4(%eax)
p += p->s.size;
d71: 8d 04 c8 lea (%eax,%ecx,8),%eax
p->s.size = nunits;
d74: 89 78 04 mov %edi,0x4(%eax)
freep = prevp;
d77: 89 15 fc 15 00 00 mov %edx,0x15fc
}
d7d: 8d 65 f4 lea -0xc(%ebp),%esp
return (void*)(p + 1);
d80: 83 c0 08 add $0x8,%eax
}
d83: 5b pop %ebx
d84: 5e pop %esi
d85: 5f pop %edi
d86: 5d pop %ebp
d87: c3 ret
d88: 90 nop
d89: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
base.s.ptr = freep = prevp = &base;
d90: c7 05 fc 15 00 00 00 movl $0x1600,0x15fc
d97: 16 00 00
d9a: c7 05 00 16 00 00 00 movl $0x1600,0x1600
da1: 16 00 00
base.s.size = 0;
da4: b8 00 16 00 00 mov $0x1600,%eax
da9: c7 05 04 16 00 00 00 movl $0x0,0x1604
db0: 00 00 00
db3: e9 44 ff ff ff jmp cfc <malloc+0x2c>
db8: 90 nop
db9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
prevp->s.ptr = p->s.ptr;
dc0: 8b 08 mov (%eax),%ecx
dc2: 89 0a mov %ecx,(%edx)
dc4: eb b1 jmp d77 <malloc+0xa7>
| 37.079262 | 140 | 0.436223 |
8a8c46502600738f84ec56fa6bede88a523913a7 | 6,478 | asm | Assembly | Transynther/x86/_processed/NONE/_zr_/i9-9900K_12_0xca.log_21829_201.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 9 | 2020-08-13T19:41:58.000Z | 2022-03-30T12:22:51.000Z | Transynther/x86/_processed/NONE/_zr_/i9-9900K_12_0xca.log_21829_201.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 1 | 2021-04-29T06:29:35.000Z | 2021-05-13T21:02:30.000Z | Transynther/x86/_processed/NONE/_zr_/i9-9900K_12_0xca.log_21829_201.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 3 | 2020-07-14T17:07:07.000Z | 2022-03-21T01:12:22.000Z | .global s_prepare_buffers
s_prepare_buffers:
push %r12
push %r14
push %rax
push %rbp
push %rcx
push %rdi
push %rsi
lea addresses_A_ht+0x7990, %rsi
lea addresses_UC_ht+0x1bd94, %rdi
nop
nop
nop
nop
sub %r14, %r14
mov $97, %rcx
rep movsl
and %rbp, %rbp
lea addresses_normal_ht+0x120f0, %rsi
lea addresses_normal_ht+0x12390, %rdi
nop
nop
nop
dec %r12
mov $94, %rcx
rep movsw
nop
nop
nop
nop
nop
and $26311, %rsi
lea addresses_UC_ht+0xf90, %rdi
nop
nop
add %rax, %rax
movb $0x61, (%rdi)
nop
xor %rcx, %rcx
lea addresses_WT_ht+0xa4d0, %rbp
nop
inc %r12
movups (%rbp), %xmm1
vpextrq $1, %xmm1, %rdi
nop
nop
nop
dec %rcx
lea addresses_D_ht+0x7f90, %rsi
lea addresses_UC_ht+0x12258, %rdi
dec %r14
mov $121, %rcx
rep movsw
nop
nop
nop
nop
nop
sub %rdi, %rdi
lea addresses_WT_ht+0x11f90, %r12
nop
nop
nop
and %rbp, %rbp
mov $0x6162636465666768, %r14
movq %r14, %xmm6
and $0xffffffffffffffc0, %r12
vmovntdq %ymm6, (%r12)
nop
cmp %rcx, %rcx
lea addresses_normal_ht+0x18826, %r12
sub %rdi, %rdi
movb $0x61, (%r12)
nop
nop
nop
nop
cmp %rcx, %rcx
lea addresses_WT_ht+0x1e390, %r14
nop
nop
nop
nop
nop
sub %rax, %rax
mov $0x6162636465666768, %rcx
movq %rcx, (%r14)
nop
nop
nop
add $2836, %rcx
lea addresses_normal_ht+0xf90, %r14
nop
xor $28868, %rbp
mov (%r14), %r12w
nop
nop
nop
and %rsi, %rsi
lea addresses_D_ht+0xc890, %rax
and %rbp, %rbp
movups (%rax), %xmm2
vpextrq $1, %xmm2, %r14
nop
nop
nop
nop
nop
sub %rsi, %rsi
pop %rsi
pop %rdi
pop %rcx
pop %rbp
pop %rax
pop %r14
pop %r12
ret
.global s_faulty_load
s_faulty_load:
push %r12
push %r14
push %r8
push %r9
push %rbp
push %rdi
push %rsi
// Faulty Load
lea addresses_WC+0xaf90, %rsi
nop
nop
nop
nop
nop
cmp $239, %rbp
mov (%rsi), %r8d
lea oracles, %rdi
and $0xff, %r8
shlq $12, %r8
mov (%rdi,%r8,1), %r8
pop %rsi
pop %rdi
pop %rbp
pop %r9
pop %r8
pop %r14
pop %r12
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'size': 1, 'NT': False, 'type': 'addresses_WC', 'same': False, 'AVXalign': False, 'congruent': 0}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'size': 4, 'NT': False, 'type': 'addresses_WC', 'same': True, 'AVXalign': False, 'congruent': 0}}
<gen_prepare_buffer>
{'OP': 'REPM', 'src': {'same': True, 'type': 'addresses_A_ht', 'congruent': 8}, 'dst': {'same': False, 'type': 'addresses_UC_ht', 'congruent': 2}}
{'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_normal_ht', 'congruent': 5}, 'dst': {'same': False, 'type': 'addresses_normal_ht', 'congruent': 10}}
{'OP': 'STOR', 'dst': {'size': 1, 'NT': False, 'type': 'addresses_UC_ht', 'same': False, 'AVXalign': False, 'congruent': 11}}
{'OP': 'LOAD', 'src': {'size': 16, 'NT': False, 'type': 'addresses_WT_ht', 'same': True, 'AVXalign': False, 'congruent': 6}}
{'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_D_ht', 'congruent': 11}, 'dst': {'same': False, 'type': 'addresses_UC_ht', 'congruent': 2}}
{'OP': 'STOR', 'dst': {'size': 32, 'NT': True, 'type': 'addresses_WT_ht', 'same': False, 'AVXalign': False, 'congruent': 11}}
{'OP': 'STOR', 'dst': {'size': 1, 'NT': False, 'type': 'addresses_normal_ht', 'same': False, 'AVXalign': False, 'congruent': 0}}
{'OP': 'STOR', 'dst': {'size': 8, 'NT': False, 'type': 'addresses_WT_ht', 'same': False, 'AVXalign': False, 'congruent': 8}}
{'OP': 'LOAD', 'src': {'size': 2, 'NT': False, 'type': 'addresses_normal_ht', 'same': False, 'AVXalign': False, 'congruent': 11}}
{'OP': 'LOAD', 'src': {'size': 16, 'NT': False, 'type': 'addresses_D_ht', 'same': False, 'AVXalign': False, 'congruent': 7}}
{'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
*/
| 37.662791 | 2,999 | 0.659772 |
cdc447da1bd968754ac89dfc8fff04a3054070db | 8,666 | asm | Assembly | Transynther/x86/_processed/US/_st_sm_/i9-9900K_12_0xca.log_21829_491.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 9 | 2020-08-13T19:41:58.000Z | 2022-03-30T12:22:51.000Z | Transynther/x86/_processed/US/_st_sm_/i9-9900K_12_0xca.log_21829_491.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 1 | 2021-04-29T06:29:35.000Z | 2021-05-13T21:02:30.000Z | Transynther/x86/_processed/US/_st_sm_/i9-9900K_12_0xca.log_21829_491.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 3 | 2020-07-14T17:07:07.000Z | 2022-03-21T01:12:22.000Z | .global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r15
push %r9
push %rax
push %rbp
push %rcx
push %rdi
push %rsi
lea addresses_WT_ht+0x1e132, %rsi
lea addresses_UC_ht+0x1e30a, %rdi
cmp $28333, %rax
mov $52, %rcx
rep movsl
nop
add $50442, %rbp
lea addresses_WT_ht+0x124a, %r9
nop
nop
nop
add $6201, %r15
mov $0x6162636465666768, %rcx
movq %rcx, %xmm2
vmovups %ymm2, (%r9)
nop
nop
nop
inc %rcx
lea addresses_UC_ht+0x12d62, %rsi
lea addresses_A_ht+0x7c32, %rdi
nop
add $22279, %r10
mov $64, %rcx
rep movsl
nop
nop
nop
nop
nop
add %r9, %r9
lea addresses_UC_ht+0x12f32, %rdi
xor $48890, %rbp
mov $0x6162636465666768, %r15
movq %r15, %xmm1
vmovups %ymm1, (%rdi)
nop
nop
nop
nop
nop
add $65073, %rax
lea addresses_WC_ht+0x11dbb, %rsi
and $4768, %r15
mov $0x6162636465666768, %rbp
movq %rbp, %xmm3
movups %xmm3, (%rsi)
nop
and %r10, %r10
lea addresses_UC_ht+0x1c732, %rsi
lea addresses_A_ht+0xb932, %rdi
nop
add %rax, %rax
mov $10, %rcx
rep movsw
add $46752, %r10
lea addresses_WC_ht+0x7d32, %rcx
nop
nop
nop
and $25330, %r10
mov $0x6162636465666768, %r15
movq %r15, (%rcx)
nop
nop
nop
nop
nop
xor $3875, %r10
lea addresses_D_ht+0x14d32, %rdi
nop
nop
and %r15, %r15
vmovups (%rdi), %ymm1
vextracti128 $0, %ymm1, %xmm1
vpextrq $0, %xmm1, %rax
nop
cmp $11920, %r10
lea addresses_A_ht+0x1b0d2, %rcx
clflush (%rcx)
nop
nop
nop
nop
and $26008, %rbp
mov (%rcx), %esi
nop
nop
cmp %r15, %r15
lea addresses_UC_ht+0x16f32, %rsi
lea addresses_UC_ht+0xc432, %rdi
clflush (%rsi)
nop
nop
nop
nop
dec %r9
mov $90, %rcx
rep movsl
inc %rax
lea addresses_D_ht+0x1d4f4, %r15
nop
nop
xor %rcx, %rcx
mov $0x6162636465666768, %r9
movq %r9, %xmm0
movups %xmm0, (%r15)
nop
nop
nop
nop
xor $21751, %rdi
lea addresses_WT_ht+0x11132, %rcx
add $8610, %r10
mov (%rcx), %rax
nop
nop
nop
nop
sub %rbp, %rbp
lea addresses_normal_ht+0xc302, %rsi
nop
nop
xor $37408, %rdi
movups (%rsi), %xmm7
vpextrq $0, %xmm7, %rcx
nop
nop
add $6627, %r10
pop %rsi
pop %rdi
pop %rcx
pop %rbp
pop %rax
pop %r9
pop %r15
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r11
push %r13
push %rax
push %rbp
push %rbx
push %rdx
// Store
lea addresses_UC+0xb932, %rdx
nop
nop
nop
nop
cmp %r10, %r10
movw $0x5152, (%rdx)
nop
nop
nop
nop
add $49155, %r13
// Store
lea addresses_WC+0x1d532, %r10
nop
nop
and $58077, %rax
movw $0x5152, (%r10)
nop
dec %rbx
// Store
lea addresses_WT+0x12932, %rbp
add %r11, %r11
mov $0x5152535455565758, %rax
movq %rax, (%rbp)
nop
nop
nop
nop
nop
xor %rbx, %rbx
// Store
lea addresses_WC+0x1b2ee, %r11
nop
nop
nop
nop
nop
inc %rax
mov $0x5152535455565758, %r13
movq %r13, %xmm5
movups %xmm5, (%r11)
nop
xor $19075, %rbx
// Store
lea addresses_US+0xb532, %rbp
nop
nop
cmp %rdx, %rdx
mov $0x5152535455565758, %rax
movq %rax, %xmm0
vmovups %ymm0, (%rbp)
nop
nop
nop
nop
and $38314, %rbp
// Faulty Load
lea addresses_US+0xb532, %r13
cmp %rbp, %rbp
mov (%r13), %r11d
lea oracles, %r13
and $0xff, %r11
shlq $12, %r11
mov (%r13,%r11,1), %r11
pop %rdx
pop %rbx
pop %rbp
pop %rax
pop %r13
pop %r11
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'size': 8, 'NT': False, 'type': 'addresses_US', 'same': False, 'AVXalign': False, 'congruent': 0}}
{'OP': 'STOR', 'dst': {'size': 2, 'NT': False, 'type': 'addresses_UC', 'same': False, 'AVXalign': False, 'congruent': 9}}
{'OP': 'STOR', 'dst': {'size': 2, 'NT': False, 'type': 'addresses_WC', 'same': False, 'AVXalign': False, 'congruent': 9}}
{'OP': 'STOR', 'dst': {'size': 8, 'NT': False, 'type': 'addresses_WT', 'same': False, 'AVXalign': False, 'congruent': 10}}
{'OP': 'STOR', 'dst': {'size': 16, 'NT': False, 'type': 'addresses_WC', 'same': False, 'AVXalign': False, 'congruent': 2}}
{'OP': 'STOR', 'dst': {'size': 32, 'NT': False, 'type': 'addresses_US', 'same': True, 'AVXalign': False, 'congruent': 0}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'size': 4, 'NT': False, 'type': 'addresses_US', 'same': True, 'AVXalign': False, 'congruent': 0}}
<gen_prepare_buffer>
{'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_WT_ht', 'congruent': 5}, 'dst': {'same': False, 'type': 'addresses_UC_ht', 'congruent': 3}}
{'OP': 'STOR', 'dst': {'size': 32, 'NT': False, 'type': 'addresses_WT_ht', 'same': False, 'AVXalign': False, 'congruent': 2}}
{'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_UC_ht', 'congruent': 3}, 'dst': {'same': False, 'type': 'addresses_A_ht', 'congruent': 6}}
{'OP': 'STOR', 'dst': {'size': 32, 'NT': False, 'type': 'addresses_UC_ht', 'same': False, 'AVXalign': False, 'congruent': 9}}
{'OP': 'STOR', 'dst': {'size': 16, 'NT': False, 'type': 'addresses_WC_ht', 'same': True, 'AVXalign': False, 'congruent': 0}}
{'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_UC_ht', 'congruent': 7}, 'dst': {'same': False, 'type': 'addresses_A_ht', 'congruent': 10}}
{'OP': 'STOR', 'dst': {'size': 8, 'NT': False, 'type': 'addresses_WC_ht', 'same': False, 'AVXalign': False, 'congruent': 10}}
{'OP': 'LOAD', 'src': {'size': 32, 'NT': False, 'type': 'addresses_D_ht', 'same': False, 'AVXalign': False, 'congruent': 9}}
{'OP': 'LOAD', 'src': {'size': 4, 'NT': False, 'type': 'addresses_A_ht', 'same': False, 'AVXalign': False, 'congruent': 5}}
{'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_UC_ht', 'congruent': 9}, 'dst': {'same': False, 'type': 'addresses_UC_ht', 'congruent': 8}}
{'OP': 'STOR', 'dst': {'size': 16, 'NT': False, 'type': 'addresses_D_ht', 'same': False, 'AVXalign': False, 'congruent': 0}}
{'OP': 'LOAD', 'src': {'size': 8, 'NT': False, 'type': 'addresses_WT_ht', 'same': False, 'AVXalign': False, 'congruent': 9}}
{'OP': 'LOAD', 'src': {'size': 16, 'NT': False, 'type': 'addresses_normal_ht', 'same': False, 'AVXalign': False, 'congruent': 3}}
{'58': 21829}
58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58
*/
| 32.335821 | 2,999 | 0.655435 |
0dc02335cb058a80502854b335fedd00049d2cf7 | 1,421 | asm | Assembly | programs/oeis/068/A068397.asm | neoneye/loda | afe9559fb53ee12e3040da54bd6aa47283e0d9ec | [
"Apache-2.0"
] | 22 | 2018-02-06T19:19:31.000Z | 2022-01-17T21:53:31.000Z | programs/oeis/068/A068397.asm | neoneye/loda | afe9559fb53ee12e3040da54bd6aa47283e0d9ec | [
"Apache-2.0"
] | 41 | 2021-02-22T19:00:34.000Z | 2021-08-28T10:47:47.000Z | programs/oeis/068/A068397.asm | neoneye/loda | afe9559fb53ee12e3040da54bd6aa47283e0d9ec | [
"Apache-2.0"
] | 5 | 2021-02-24T21:14:16.000Z | 2021-08-09T19:48:05.000Z | ; A068397: a(n) = Lucas(n) + (-1)^n + 1.
; 1,5,4,9,11,20,29,49,76,125,199,324,521,845,1364,2209,3571,5780,9349,15129,24476,39605,64079,103684,167761,271445,439204,710649,1149851,1860500,3010349,4870849,7881196,12752045,20633239,33385284,54018521,87403805,141422324,228826129,370248451,599074580,969323029,1568397609,2537720636,4106118245,6643838879,10749957124,17393796001,28143753125,45537549124,73681302249,119218851371,192900153620,312119004989,505019158609,817138163596,1322157322205,2139295485799,3461452808004,5600748293801,9062201101805,14662949395604,23725150497409,38388099893011,62113250390420,100501350283429,162614600673849,263115950957276,425730551631125,688846502588399,1114577054219524,1803423556807921,2918000611027445,4721424167835364,7639424778862809,12360848946698171,20000273725560980,32361122672259149,52361396397820129,84722519070079276,137083915467899405,221806434537978679,358890350005878084,580696784543856761,939587134549734845,1520283919093591604,2459871053643326449,3980154972736918051,6440026026380244500,10420180999117162549,16860207025497407049,27280388024614569596,44140595050111976645,71420983074726546239,115561578124838522884,186982561199565069121,302544139324403592005,489526700523968661124,792070839848372253129
add $0,1
mov $1,$0
gcd $1,2
mov $2,$0
seq $0,32 ; Lucas numbers beginning at 2: L(n) = L(n-1) + L(n-2), L(0) = 2, L(1) = 1.
mod $2,2
sub $2,8
sub $2,$1
sub $0,$2
sub $0,8
| 101.5 | 1,207 | 0.853624 |
36993346a52216e69bda418bc2255b6a622496cb | 413 | asm | Assembly | oeis/133/A133274.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 11 | 2021-08-22T19:44:55.000Z | 2022-03-20T16:47:57.000Z | oeis/133/A133274.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 9 | 2021-08-29T13:15:54.000Z | 2022-03-09T19:52:31.000Z | oeis/133/A133274.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 3 | 2021-08-22T20:56:47.000Z | 2021-09-29T06:26:12.000Z | ; A133274: Numbers which are both 12-gonal and centered 12-gonal numbers.
; Submitted by Christian Krause
; 1,793,382537,184382353,88871911921,42836077163881,20646900321079033,9951763118682930337,4796729176304851343713,2312013511215819664739641,1114385715676848773553163561,537131602942729893032960097073
mov $3,3
lpb $0
sub $0,1
mov $1,$3
mul $1,20
add $2,$1
add $3,$2
lpe
pow $3,2
mov $0,$3
div $0,5
| 25.8125 | 198 | 0.779661 |
3ecb42b160ea76716732b4c62d2c401377ca1854 | 888 | asm | Assembly | oeis/126/A126718.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 11 | 2021-08-22T19:44:55.000Z | 2022-03-20T16:47:57.000Z | oeis/126/A126718.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 9 | 2021-08-29T13:15:54.000Z | 2022-03-09T19:52:31.000Z | oeis/126/A126718.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 3 | 2021-08-22T20:56:47.000Z | 2021-09-29T06:26:12.000Z | ; A126718: a(n) is the number of nonnegative integers k less than 10^n such that the decimal representation of k lacks the digits 1,2,3, at least one of digits 4,5, at least one of digits 6,7 and at least one of digits 8,9.
; Submitted by Jamie Morken(s2)
; 7,43,235,1171,5467,24403,105595,447091,1864027,7686163,31440955,127865011,517788187,2090186323,8417944315,33843570931,135890057947,545108340883,2185079263675,8754257900851,35058860433307,140360940805843,561820285607035,2248410759910771,8997031992754267,35998295031677203,144023681711342395,576186232404576691,2305019447906540827,9220901349712090963,36886076079548597755,147551716373179994611,590229101683446592987,2360983115357505823123,9444132587404260861115,37777130727745914580531
mov $1,1
mov $2,1
mov $3,2
lpb $0
sub $0,1
mul $1,4
mul $3,3
add $1,$3
mul $2,2
add $2,1
sub $1,$2
lpe
mov $0,$1
mul $0,6
add $0,1
| 44.4 | 485 | 0.801802 |
0806b85509977891f200e52ffe7a0e8eefe3407b | 3,370 | asm | Assembly | bbuf.asm | jorgicor/altair | a83f4a5b177c366000f69cb261befb499602aa69 | [
"MIT"
] | null | null | null | bbuf.asm | jorgicor/altair | a83f4a5b177c366000f69cb261befb499602aa69 | [
"MIT"
] | null | null | null | bbuf.asm | jorgicor/altair | a83f4a5b177c366000f69cb261befb499602aa69 | [
"MIT"
] | null | null | null | ; ----------------------------------------------------------------------------
; Altair, CIDLESA's 1981 arcade game remade for the ZX Spectrum and
; Amstrad CPC.
; ----------------------------------------------------------------------------
; Common to all hardware.
; --------------------
; 'inirecs' Init Rects
; --------------------
; Sets Current Rect Pointer to the start of the Rect List and sets
; the Number of Rects to 0.
;
; Saves DE, BC.
inirecs ld hl,bbuf_reclst
ld (bbuf_rectp),hl
xor a
ld (bbuf_nrects),a
ret
; -------------------------------
; 'savrec' Save Rect in Rect List
; -------------------------------
; Saves a rect in the rect list if there is space enough (MAXRECS) and
; points Current Rect Pointer to the next rect and increments Number of
; Rects.
;
; In B,C height,width. DE address of first byte of rect. A restore value.
; Saves BC, DE.
savrec push af
ld a,(bbuf_nrects)
cp MAXRECS
jr nz,savrec1
pop af
ret
savrec1 inc a
ld (bbuf_nrects),a
pop af
ld hl,(bbuf_rectp)
ld (hl),c
inc hl
ld (hl),b
inc hl
ld (hl),e
inc hl
ld (hl),d
inc hl
ld (hl),a
inc hl
ld (bbuf_rectp),hl
ret
; ---------------------
; 'blkrecs' Blank Rects
; ---------------------
; Goes through the Rect List and calls 'erase' for each.
blkrecs ld hl,bbuf_reclst
ld a,(bbuf_nrects)
blkrec1 or a
ret z
push af
ld c,(hl)
inc hl
ld b,(hl)
inc hl
ld e,(hl)
inc hl
ld d,(hl)
inc hl
ld a,(hl)
inc hl
push hl
call erase
pop hl
pop af
dec a
jr blkrec1
; ------------------
; 'erase' Erase Rect
; ------------------
; Fills a rect with a value. The rect is assummed in a buffer with a
; with of BBUFWB bytes.
;
; In: B,C height,width in bytes. DE address of first byte.
; A value to erase to.
erase
; Set DE as the offset we have to add to go to the next line at destiny.
ex af,af'
ld a,BBUFWB
sub c
ld l,a
ex af,af'
ld h,0
ex de,hl
; Fill rect.
erase2 push bc
erase1 ld (hl),a
inc hl
dec c
jr nz,erase1
pop bc
add hl,de
djnz erase2
ret
; -----------------
; 'drim' Draw Image
; -----------------
; Draws an image in the Back Buffer, draws its color, and saves the
; rects where we have painted to be restored later.
; An image starts with two bytes. The first is the width in bytes; the
; second is the height in pixels. Then comes the actual image data.
;
; In HL start of image. D,E x,y position in bytes.
drim
; Calc Back Buffer paint address.
ex de,hl
ld bc,bbuf
call cbpos
ex de,hl
; Set C width and B height.
ld c,(hl)
inc hl
ld b,(hl)
inc hl
; Now, HL start of image data. DE address in Back Buffer. B,C height, width.
; Save rect to restore later, and paint.
push hl
xor a
call savrec
pop hl
call cpim
ret
; -----------------
; 'cpim' Copy Image
; -----------------
; Copies a set of bytes into a buffer, arranged as rows and columns.
; The buffer where to paint is assumed to be have a width of BBUFWB
; bytes.
;
; In B,C is height in bytes, width in bytes. HL start of image data.
; DE address where to paint.
cpim
; Calc offset between buffer lines.
ld a,BBUFWB
sub c
; Copy all lines.
cpim1 push bc
; Copy a line.
ld b,0
ldir
#if 0
push af
ld b,c
cpim2 ld a,(de)
or (hl)
ld (de),a
inc hl
inc de
djnz cpim2
pop af
#endif
; Here B is 0. Go to next line at destiny.
ex de,hl
ld c,a
add hl,bc
ex de,hl
; For height lines.
pop bc
djnz cpim1
ret
| 16.766169 | 78 | 0.593769 |
0c9588721394b390db39e798b958c61f2c48a046 | 596 | asm | Assembly | oeis/003/A003954.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 11 | 2021-08-22T19:44:55.000Z | 2022-03-20T16:47:57.000Z | oeis/003/A003954.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 9 | 2021-08-29T13:15:54.000Z | 2022-03-09T19:52:31.000Z | oeis/003/A003954.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 3 | 2021-08-22T20:56:47.000Z | 2021-09-29T06:26:12.000Z | ; A003954: Expansion of g.f.: (1+x)/(1-11*x).
; 1,12,132,1452,15972,175692,1932612,21258732,233846052,2572306572,28295372292,311249095212,3423740047332,37661140520652,414272545727172,4556998002998892,50126978032987812,551396758362865932,6065364341991525252,66719007761906777772,733909085380974555492,8072999939190720110412,88802999331097921214532,976832992642077133359852,10745162919062848466958372,118196792109691333136542092,1300164713206604664501963012,14301811845272651309521593132,157319930297999164404737524452
mov $1,11
pow $1,$0
sub $1,1
mul $1,12
add $1,10
div $1,11
add $1,1
mov $0,$1
| 49.666667 | 470 | 0.855705 |
95bbe69ff36224e08765ad179292d8d4f06dd99e | 283 | asm | Assembly | programs/oeis/004/A004343.asm | neoneye/loda | afe9559fb53ee12e3040da54bd6aa47283e0d9ec | [
"Apache-2.0"
] | 22 | 2018-02-06T19:19:31.000Z | 2022-01-17T21:53:31.000Z | programs/oeis/004/A004343.asm | neoneye/loda | afe9559fb53ee12e3040da54bd6aa47283e0d9ec | [
"Apache-2.0"
] | 41 | 2021-02-22T19:00:34.000Z | 2021-08-28T10:47:47.000Z | programs/oeis/004/A004343.asm | neoneye/loda | afe9559fb53ee12e3040da54bd6aa47283e0d9ec | [
"Apache-2.0"
] | 5 | 2021-02-24T21:14:16.000Z | 2021-08-09T19:48:05.000Z | ; A004343: Binomial coefficient C(5n,n-1).
; 1,10,105,1140,12650,142506,1623160,18643560,215553195,2505433700,29248649430,342700125300,4027810484880,47465835030320,560658857389200,6635869816740560,78682166288559225,934433788613079150
mov $1,5
mul $1,$0
add $1,5
bin $1,$0
mov $0,$1
| 31.444444 | 190 | 0.80212 |
f6cdf2e626708e43642f3b801f67524e4e68f93d | 495 | asm | Assembly | programs/oeis/060/A060582.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | null | null | null | programs/oeis/060/A060582.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | null | null | null | programs/oeis/060/A060582.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | null | null | null | ; A060582: If the final digit of n in base 3 is the same as a([n/3]) then this digit, otherwise a(n)= mod 3-sum of these two digits, with a(0)=0.
; 0,2,1,1,0,2,2,1,0,2,1,0,0,2,1,1,0,2,1,0,2,2,1,0,0,2,1,1,0,2,2,1,0,0,2,1,0,2,1,1,0,2,2,1,0,2,1,0,0,2,1,1,0,2,2,1,0,0,2,1,1,0,2,1,0,2,2,1,0,0,2,1,0,2,1,1,0,2,2,1,0,2,1,0,0,2,1,1,0,2,1,0,2,2,1,0,0,2,1,0,2,1,1,0,2
mov $2,$0
mul $0,2
add $0,$2
cal $0,287451 ; Start with 0 and repeatedly substitute 0->012, 1->201, 2->120.
mul $0,4
mov $1,$0
div $1,4
| 45 | 211 | 0.585859 |
566c46b7eca5a70446c7a98e55e28716ca97df96 | 5,167 | asm | Assembly | kernel/tmr.asm | iocoder/upcr | 3de4cb76177b4fee5403c8630acf8c7ffac515d1 | [
"MIT"
] | null | null | null | kernel/tmr.asm | iocoder/upcr | 3de4cb76177b4fee5403c8630acf8c7ffac515d1 | [
"MIT"
] | null | null | null | kernel/tmr.asm | iocoder/upcr | 3de4cb76177b4fee5403c8630acf8c7ffac515d1 | [
"MIT"
] | null | null | null | ;###############################################################################
;# File name: KERNEL/TMR.ASM
;# DESCRIPTION: KERNEL TIMER MANAGEMENT
;# AUTHOR: RAMSES A.
;###############################################################################
;#
;# UPCR OPERATING SYSTEM FOR X86_64 ARCHITECTURE
;# COPYRIGHT (C) 2021 RAMSES A.
;#
;# PERMISSION IS HEREBY GRANTED, FREE OF CHARGE, TO ANY PERSON OBTAINING A COPY
;# OF THIS SOFTWARE AND ASSOCIATED DOCUMENTATION FILES (THE "SOFTWARE"), TO DEAL
;# IN THE SOFTWARE WITHOUT RESTRICTION, INCLUDING WITHOUT LIMITATION THE RIGHTS
;# TO USE, COPY, MODIFY, MERGE, PUBLISH, DISTRIBUTE, SUBLICENSE, AND/OR SELL
;# COPIES OF THE SOFTWARE, AND TO PERMIT PERSONS TO WHOM THE SOFTWARE IS
;# FURNISHED TO DO SO, SUBJECT TO THE FOLLOWING CONDITIONS:
;#
;# THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN ALL
;# COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE.
;#
;###############################################################################
;#
;# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
;# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
;# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
;# SOFTWARE.
;#
;###############################################################################
;###############################################################################
;# INCLUDES #
;###############################################################################
;# COMMON DEFINITIONS USED BY KERNEL
INCLUDE "kernel/macro.inc"
;###############################################################################
;# GLOBALS #
;###############################################################################
;# GLOBAL SYMBOLS
PUBLIC KTMRINIT
PUBLIC KTMRSETUP
PUBLIC KTMRINTR
;###############################################################################
;# TEXT SECTION #
;###############################################################################
;# TEXT SECTION
SEGMENT ".text"
;#-----------------------------------------------------------------------------#
;# KTMRINIT() #
;#-----------------------------------------------------------------------------#
KTMRINIT: ;# PRINT INIT MSG
LEA RDI, [RIP+KTMRNAME]
CALL KCONMOD
LEA RDI, [RIP+KTMRMSG]
CALL KCONSTR
MOV RDI, '\n'
CALL KCONCHR
;# DONE
XOR RAX, RAX
RET
;#-----------------------------------------------------------------------------#
;# KTMRSETUP() #
;#-----------------------------------------------------------------------------#
KTMRSETUP: ;# SCHEDULE TSC INTERRUPT
;#CALL KTSCUS
;# SCHEDULE LAPIC INTERRUPT
;#CALL KLATUS
;# SCHEDULE RTC INTERRUPT
;#CALL KRTCUS
;# SCHEDULE HPET INTERRUPT
;#CALL KHPTUS
;# SCHEDULE PIT INTERRUPT
;#MOV RDI, 0xFFFF
;#CALL KPITUS
;# DONE
XOR RAX, RAX
RET
;#-----------------------------------------------------------------------------#
;# KTMRSYNC() #
;#-----------------------------------------------------------------------------#
KTMRINTR: ;# TSC INTERRUPT
;#CALL KTSCUS
;# LAPIC INTERRUPT
;#CALL KLATUS
;# RTC INTERRUPT
;#CALL KRTCUS
;# HPET INTERRUPT
;#CALL KHPTUS
;# PIT INTERRUPT
;#MOV RDI, 0xFFFF
;#CALL KPITUS
;# DONE
XOR RAX, RAX
RET
;###############################################################################
;# DATA SECTION #
;###############################################################################
;# DATA SECTION
SEGMENT ".data"
;#-----------------------------------------------------------------------------#
;# LOGGING STRINGS #
;#-----------------------------------------------------------------------------#
;# TMR HEADING AND ASCII STRINGS
KTMRNAME: DB "KERNEL TMR\0"
KTMRMSG: DB "TSC IS SELECTED TO BE THE MAIN TIMER.\0"
| 38.559701 | 81 | 0.330946 |
9c3d375bc33817798f3613560060e346cfcdf0c8 | 4,832 | asm | Assembly | packages/boot/x86_64/boot.asm | Gaelan/os-experiment | b475b2f489fc79e38f00409704b48efb9ce66b46 | [
"MIT"
] | 2 | 2018-01-02T22:11:07.000Z | 2018-03-20T20:41:26.000Z | packages/boot/x86_64/boot.asm | Gaelan/os-experiment | b475b2f489fc79e38f00409704b48efb9ce66b46 | [
"MIT"
] | null | null | null | packages/boot/x86_64/boot.asm | Gaelan/os-experiment | b475b2f489fc79e38f00409704b48efb9ce66b46 | [
"MIT"
] | null | null | null | %macro print 1-*
push ecx
push edi
push esi
mov edi, 0xB8000 ; message destination (vga text buffer)
%rep %0
cmp edi, 0xB8FA0 ; end of vga text buffer (exclusive)
jge %%end ; stop writing bytes
mov esi, %1 ; message start
mov ecx, %1_end - %1 ; message length
rep movsb
add edi, 2 ; skip a character before next text
%rotate 1
%endrep
%%end:
pop esi
pop edi
pop ecx
%endmacro
%macro error 1+
print error_msg,%1
%endmacro
global start
extern long_start
section .text
bits 32
start:
mov esp, stack_top ; Initalize stack
mov edi, ebx ; Copy multiboot info pointer to edi
call check_multiboot
call check_cpuid
call check_long_mode
call build_page_tables
call enable_paging
; load 64-bit GDT
lgdt [gdt64.pointer]
; jump to 64 bit code
jmp gdt64.code:long_start
hlt
check_multiboot:
cmp eax, 0x36d76289
jne .no_multiboot
ret
.no_multiboot:
error no_multiboot_error
hlt
check_cpuid:
; Check if CPUID is supported by attempting to flip the ID bit (bit 21)
; in the FLAGS register. If we can flip it, CPUID is available.
; Copy FLAGS in to EAX via stack
pushfd
pop eax
; Copy to ECX as well for comparing later on
mov ecx, eax
; Flip the ID bit
xor eax, 1 << 21
; Copy EAX to FLAGS via the stack
push eax
popfd
; Copy FLAGS back to EAX (with the flipped bit if CPUID is supported)
pushfd
pop eax
; Restore FLAGS from the old version stored in ECX (i.e. flipping the
; ID bit back if it was ever flipped).
push ecx
popfd
; Compare EAX and ECX. If they are equal then that means the bit
; wasn't flipped, and CPUID isn't supported.
cmp eax, ecx
je .no_cpuid
ret
.no_cpuid:
error no_cpuid_error
hlt
check_long_mode:
; test if extended processor info in available
mov eax, 0x80000000 ; implicit argument for cpuid
cpuid ; get highest supported argument
cmp eax, 0x80000001 ; it needs to be at least 0x80000001
jb .no_long_mode ; if it's less, the CPU is too old for long mode
; use extended info to test if long mode is available
mov eax, 0x80000001 ; argument for extended processor info
cpuid ; returns various feature bits in ecx and edx
test edx, 1 << 29 ; test if the LM-bit is set in the D-register
jz .no_long_mode ; If it's not set, there is no long mode
ret
.no_long_mode:
error no_long_mode_error
hlt
build_page_tables:
; map first P4 entry to P3 table
mov eax, p3_table
or eax, 0b11 ; present + writable
mov [p4_table], eax
; map P4 table recursively by mapping the last entry to itself
mov eax, p4_table
or eax, 0b11 ; present + writable
mov [p4_table + 511 * 8], eax
; map first P3 entry to P2 table
mov eax, p2_table
or eax, 0b11 ; present + writable
mov [p3_table], eax
; map each P2 entry to a huge 2MiB page
mov ecx, 0 ; counter variable
.map_p2_table:
; map ecx-th P2 entry to a huge page that starts at address 2MiB*ecx
mov eax, 0x200000 ; 2MiB
mul ecx ; start address of ecx-th page
or eax, 0b10000011 ; present + writable + huge
mov [p2_table + ecx * 8], eax ; map ecx-th entry
inc ecx ; increase counter
cmp ecx, 512 ; if counter == 512, the whole P2 table is mapped
jne .map_p2_table ; else map the next entry
ret ; .map_p2_table
ret ; build_page_tables
enable_paging:
; load P4 to cr3 register (cpu uses this to access the P4 table)
mov eax, p4_table
mov cr3, eax
; enable PAE-flag in cr4 (Physical Address Extension)
mov eax, cr4
or eax, 1 << 5
mov cr4, eax
; set the long mode bit in the EFER MSR (model specific register)
mov ecx, 0xC0000080
rdmsr
or eax, 1 << 8
wrmsr
; enable paging in the cr0 register
mov eax, cr0
or eax, 1 << 31
mov cr0, eax
ret
section .bss
align 4096
p4_table:
resb 4096
p3_table:
resb 4096
p2_table:
resb 4096
stack_bottom:
resb 4096 * 4
stack_top:
section .rodata
gdt64:
dq 0 ; zero entry
.code: equ $ - gdt64
dq (1<<43) | (1<<44) | (1<<47) | (1<<53) ; code segment
.pointer:
dw $ - gdt64 - 1
dq gdt64
error_msg:
db 'E',4,'R',4,'R',4,'O',4,'R',4,':',4
error_msg_end:
no_multiboot_error:
db 'N',7,'o',7,'t',7,' ',7,'l',7,'o',7,'a',7,'d',7,'e',7,'d',7,' ',7,'b',7,'y',7,' ',7,'m',7,'u',7,'l',7,'t',7,'i',7,'b',7,'o',7,'o',7,'t',7
no_multiboot_error_end:
no_cpuid_error:
db 'C',7,'P',7,'U',7,'I',7,'D',7,' ',7,'u',7,'n',7,'s',7,'u',7,'p',7,'p',7,'o',7,'r',7,'t',7,'e',7,'d',7
no_cpuid_error_end:
no_long_mode_error:
db 'C',7,'P',7,'U',7,' ',7,'i',7,'s',7,' ',7,'n',7,'o',7,'t',7,' ',7,'6',7,'4',7,'b',7,'i',7,'t',7
no_long_mode_error_end: | 24.653061 | 141 | 0.631623 |
80452eed1cee3f40230eb19e30b4aec5563747af | 1,059 | asm | Assembly | test/cases/string-constant.asm | JohanEngelen/gcc-explorer | 31e658c0257f3a8615115857b03466862fa7e654 | [
"BSD-2-Clause"
] | null | null | null | test/cases/string-constant.asm | JohanEngelen/gcc-explorer | 31e658c0257f3a8615115857b03466862fa7e654 | [
"BSD-2-Clause"
] | null | null | null | test/cases/string-constant.asm | JohanEngelen/gcc-explorer | 31e658c0257f3a8615115857b03466862fa7e654 | [
"BSD-2-Clause"
] | null | null | null | .file "example.cpp"
.intel_syntax noprefix
.text
.Ltext0:
.globl s_sA
.section .rodata
.LC0:
.string "hello world!"
.data
.align 8
.type s_sA, @object
.size s_sA, 8
s_sA:
.quad .LC0
.section .rodata
.align 8
.type s_sB, @object
.size s_sB, 10
s_sB:
.string "hey there"
.text
.globl main
.type main, @function
main:
.LFB0:
.file 1 "/tmp/gcc-explorer-compiler116820-58-ewfj5u/example.cpp"
.loc 1 6 0
.cfi_startproc
push rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
mov rbp, rsp
.cfi_def_cfa_register 6
.loc 1 7 0
mov rax, QWORD PTR s_sA[rip]
mov rdi, rax
call puts
.loc 1 8 0
mov edi, OFFSET FLAT:s_sB
call puts
.loc 1 9 0
mov eax, 0
pop rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
| 22.531915 | 72 | 0.463645 |
b1293a07bd05fed02e6915335fc3a536768711ed | 20,032 | asm | Assembly | s3d/music-original/VVZ1.asm | Cancer52/flamedriver | 9ee6cf02c137dcd63e85a559907284283421e7ba | [
"0BSD"
] | 9 | 2017-10-09T20:28:45.000Z | 2021-06-29T21:19:20.000Z | s3d/music-original/VVZ1.asm | Cancer52/flamedriver | 9ee6cf02c137dcd63e85a559907284283421e7ba | [
"0BSD"
] | 12 | 2018-08-01T13:52:20.000Z | 2022-02-21T02:19:37.000Z | s3d/music-original/VVZ1.asm | Cancer52/flamedriver | 9ee6cf02c137dcd63e85a559907284283421e7ba | [
"0BSD"
] | 2 | 2018-02-17T19:50:36.000Z | 2019-10-30T19:28:06.000Z | Snd_VVZ1_Header:
smpsHeaderStartSong 3
smpsHeaderVoice Snd_VVZ1_Voices
smpsHeaderChan $06, $03
smpsHeaderTempo $01, $1D
smpsHeaderDAC Snd_VVZ1_DAC
smpsHeaderFM Snd_VVZ1_FM1, $00, $18
smpsHeaderFM Snd_VVZ1_FM2, $0C, $0F
smpsHeaderFM Snd_VVZ1_FM3, $F4, $10
smpsHeaderFM Snd_VVZ1_FM4, $F4, $10
smpsHeaderFM Snd_VVZ1_FM5, $00, $1C
smpsHeaderPSG Snd_VVZ1_PSG1, $E8, $02, $00, $00
smpsHeaderPSG Snd_VVZ1_PSG2, $E8, $04, $00, $00
smpsHeaderPSG Snd_VVZ1_PSG3, $23, $02, $00, $00
; FM1 Data
Snd_VVZ1_FM1:
smpsModSet $0C, $01, $09, $07
Snd_VVZ1_Jump00:
smpsPan panCenter, $00
smpsSetvoice $01
dc.b nRst, $30
Snd_VVZ1_Jump03:
dc.b nRst, $60, nRst, nRst, nRst
Snd_VVZ1_Loop06:
smpsCall Snd_VVZ1_Call0A
dc.b nG3, $24, nF3, nEb3, $18, smpsNoAttack, $0C, nF3, $18, nEb3, nBb2, nB2
dc.b $0C
smpsCall Snd_VVZ1_Call0A
dc.b nG3, $24, nC4, $3C, smpsNoAttack, $60
smpsLoop $00, $02, Snd_VVZ1_Loop06
Snd_VVZ1_Loop07:
dc.b nAb4, $24, nF4, $18, nBb4, $0C, nAb4, nG4
smpsLoop $00, $05, Snd_VVZ1_Loop07
dc.b nAb4, $24, nG4, $18, nAb4, $0C, nG4, $18, nAb4, $60, smpsNoAttack, nF4
Snd_VVZ1_Loop08:
dc.b nAb4, $24, nF4, $18, nBb4, $0C, nAb4, nG4
smpsLoop $00, $05, Snd_VVZ1_Loop08
dc.b nAb4, $24, nG4, nEb4, $18, nF4, $60, smpsNoAttack, nF4
smpsJump Snd_VVZ1_Jump03
Snd_VVZ1_Call0A:
dc.b nC3, $24, nF3, nC4, $18, smpsNoAttack, $0C, nBb3, $18, nAb3, nG3, $0C
dc.b nF3, nAb3
smpsReturn
; FM2 Data
Snd_VVZ1_FM2:
smpsPan panCenter, $00
smpsModSet $01, $01, $01, $02
smpsSetvoice $00
smpsPan panCenter, $00
smpsModSet $07, $01, $03, $05
dc.b nRst, $30
Snd_VVZ1_Loop04:
smpsCall Snd_VVZ1_Call07
smpsLoop $00, $05, Snd_VVZ1_Loop04
smpsCall Snd_VVZ1_Call08
smpsCall Snd_VVZ1_Call09
smpsCall Snd_VVZ1_Call08
dc.b nAb2, nAb3, nG2, $0C, nAb2, nG2, $06, nG3, nFs2, $0C, nG2, nAb2
dc.b $06, nG2, nD2, nEb2, nF2, nF3, nE2, $0C, nF2, nF2, $06, nF3
dc.b nEb2, $0C, nEb3, nD2, $06, nEb2, nEb2, nEb3
smpsCall Snd_VVZ1_Call08
smpsCall Snd_VVZ1_Call09
smpsCall Snd_VVZ1_Call08
Snd_VVZ1_Loop05:
dc.b nF1, nF2, nF1, $0C, nF1, nF1, $06, nF2, nF1, $0C, nF1, nF1
dc.b $06, nF2, nF1, nF2
smpsLoop $00, $02, Snd_VVZ1_Loop05
smpsJump Snd_VVZ1_Loop04
Snd_VVZ1_Call07:
dc.b nF2, $0C, nC2, nEb2, nC2, $06, nF2, $0C, $06, nC2, $0C, nEb2
dc.b nC2, nF2, nC2, nEb2, $06, nE2, $0C, nF2, nF2, $06, nC2, $0C
dc.b nF2, nE2, nEb2, nBb1, nCs2, nD2, $06, nEb2, $0C, $06, nBb1, $0C
dc.b nCs2, nD2, nEb2, nBb1, nCs2, $06, nD2, $0C, nEb2, nEb2, $06, nBb1
dc.b $0C, nEb2, nE2
smpsReturn
Snd_VVZ1_Call08:
dc.b nCs2, $06, nCs3, nC2, $0C, nCs2, nCs2, $06, nCs3, nC2, $0C, nCs2
dc.b nCs2, $06, nCs3, nCs2, nD2, nEb2, nEb3, nD2, $0C, nEb2, nEb2, $06
dc.b nEb3, nD2, $0C, nEb2, nEb2, $06, nEb3, nEb2, nCs2
smpsReturn
Snd_VVZ1_Call09:
dc.b nC2, nC3, nB1, $0C, nC2, nC2, $06, nC3, nB1, $0C, nC2, nC2
dc.b $06, nB1, nC2, nEb2, nCs2, nCs3, nC2, $0C, nCs2, nCs2, $06, nCs3
dc.b nC2, $0C, nCs2, nCs2, $06, nAb1, nB1, nC2
smpsReturn
; FM3 Data
Snd_VVZ1_FM3:
smpsPan panRight, $00
smpsSetvoice $02
smpsAlterPitch $FB
smpsModSet $01, $01, $0A, $B7
dc.b nC3, $30
smpsAlterPitch $05
Snd_VVZ1_Jump02:
smpsSetvoice $02
smpsModSet $01, $01, $02, $06
dc.b nF3, $60, smpsNoAttack, $30
smpsModSet $01, $01, $0A, $B7
smpsAlterPitch $FB
dc.b nC3
smpsAlterPitch $05
smpsModSet $01, $01, $02, $06
dc.b nEb3, $60, smpsNoAttack, $30
smpsAlterPitch $FB
smpsModSet $01, $01, $0C, $BF
dc.b nC3, $30
smpsAlterPitch $05
Snd_VVZ1_Loop03:
smpsModSet $01, $01, $02, $06
dc.b nF3, $60, smpsNoAttack, $30
smpsAlterPitch $FB
smpsModSet $01, $01, $0C, $BF
dc.b nC3
smpsAlterPitch $05
smpsModSet $01, $01, $02, $06
dc.b nEb3, $60, smpsNoAttack, $30
smpsAlterPitch $FB
smpsModSet $01, $01, $0C, $BF
dc.b nC3
smpsAlterPitch $05
smpsLoop $00, $04, Snd_VVZ1_Loop03
smpsAlterPitch $F4
smpsFMAlterVol $03
smpsSetvoice $03
smpsModSet $01, $01, $02, $06
dc.b nAb5, $0C, nAb5, nAb5, nAb5, nAb5, nAb5, nAb5, nAb5, nBb5, nBb5, nBb5
dc.b nBb5, nBb5, nBb5, nBb5, nBb5, nG5, nG5, nG5, nG5, nG5, nG5, nG5
dc.b nG5, nAb5, nAb5, nAb5, nAb5, nAb5, nAb5, nAb5, nAb5, nAb5, nAb5, nAb5
dc.b nAb5, nAb5, nAb5, nAb5, nAb5, nBb5, nBb5, nBb5, nBb5, nBb5, nBb5, nBb5
dc.b nBb5, nC6, nC6, nC6, nBb5, nBb5, nBb5, nBb5, nBb5, nAb5, nAb5, nAb5
dc.b nAb5, nAb5, nAb5, nAb5, nAb5, nAb5, nAb5, nAb5, nAb5, nAb5, nAb5, nAb5
dc.b nAb5, nBb5, nBb5, nBb5, nBb5, nBb5, nBb5, nBb5, nBb5, nG5, nG5, nG5
dc.b nG5, nG5, nG5, nG5, nG5, nAb5, nAb5, nAb5, nAb5, nAb5, nAb5, nAb5
dc.b nAb5, nAb5, nAb5, nAb5, nAb5, nAb5, nAb5, nAb5, nAb5, nBb5, nBb5, nBb5
dc.b nBb5, nBb5, nBb5, nBb5, nBb5, nAb5, nAb5, nAb5, nAb5, nAb5, nAb5, nAb5
dc.b nAb5, nAb5, nAb5, nAb5, nAb5, nAb5, nAb5, nAb5, nAb5
smpsFMAlterVol $FD
smpsAlterPitch $0C
smpsJump Snd_VVZ1_Jump02
; FM4 Data
Snd_VVZ1_FM4:
smpsPan panLeft, $00
smpsModSet $01, $01, $01, $05
smpsSetvoice $02
smpsAlterPitch $FB
smpsModSet $01, $01, $08, $B7
dc.b nG2, $30
smpsAlterPitch $05
Snd_VVZ1_Jump01:
smpsSetvoice $02
smpsModSet $01, $01, $02, $06
dc.b nC3, $60, smpsNoAttack, $30
smpsModSet $01, $01, $08, $B7
smpsAlterPitch $FB
dc.b nG2
smpsAlterPitch $05
smpsModSet $01, $01, $02, $06
dc.b nBb2, $60, smpsNoAttack, $30
smpsAlterPitch $FB
smpsModSet $01, $01, $08, $BF
dc.b nG2, $30
smpsAlterPitch $05
Snd_VVZ1_Loop02:
smpsModSet $01, $01, $02, $06
dc.b nC3, $60, smpsNoAttack, $30
smpsAlterPitch $FB
smpsModSet $01, $01, $08, $BF
dc.b nG2
smpsModSet $01, $01, $02, $06
smpsAlterPitch $05
dc.b nBb2, $60, smpsNoAttack, $30
smpsAlterPitch $FB
smpsModSet $01, $01, $08, $BF
dc.b nBb2
smpsAlterPitch $05
smpsModSet $01, $01, $02, $06
smpsLoop $00, $04, Snd_VVZ1_Loop02
smpsAlterPitch $F4
smpsFMAlterVol $03
smpsSetvoice $03
smpsModSet $01, $01, $02, $06
dc.b nCs5, $0C, nCs5, nCs5, nCs5, nCs5, nCs5, nCs5, nCs5, nEb5, nEb5, nEb5
dc.b nEb5, nEb5, nEb5, nEb5, nEb5, nC5, nC5, nC5, nEb5, nEb5, nEb5, nEb5
dc.b nEb5, nF5, nF5, nF5, nCs5, nCs5, nCs5, nCs5, nCs5, nCs5, nCs5, nCs5
dc.b nCs5, nCs5, nCs5, nCs5, nCs5, nEb5, nEb5, nEb5, nEb5, nEb5, nEb5, nEb5
dc.b nEb5, nAb5, nAb5, nAb5, nG5, nG5, nG5, nG5, nG5, nF5, nF5, nF5
dc.b nC5, nC5, nC5, nC5, nC5, nCs5, nCs5, nCs5, nCs5, nCs5, nCs5, nCs5
dc.b nCs5, nEb5, nEb5, nEb5, nEb5, nEb5, nEb5, nEb5, nEb5, nC5, nC5, nC5
dc.b nEb5, nEb5, nEb5, nEb5, nEb5, nF5, nF5, nF5, nCs5, nCs5, nCs5, nCs5
dc.b nCs5, nCs5, nCs5, nCs5, nCs5, nCs5, nCs5, nCs5, nCs5, nEb5, nEb5, nBb5
dc.b nBb5, nBb5, nBb5, nBb5, nBb5, nF5, nF5, nF5, nC5, nC5, nC5, nC5
dc.b nC5, nF5, nF5, nF5, nC5, nC5, nC5, nC5, nC5
smpsFMAlterVol $FD
smpsAlterPitch $0C
smpsJump Snd_VVZ1_Jump01
; FM5 Data
Snd_VVZ1_FM5:
smpsModSet $01, $01, $01, $08
dc.b nRst, $0B
smpsAlterNote $01
smpsJump Snd_VVZ1_Jump00
; Unreachable
smpsStop
; PSG1 Data
Snd_VVZ1_PSG1:
smpsModSet $01, $01, $01, $04
smpsPSGvoice sTone_11
smpsAlterPitch $FB
smpsModSet $01, $01, $F9, $A7
dc.b nC3, $30
smpsAlterPitch $05
Snd_VVZ1_Jump04:
smpsPSGvoice sTone_11
smpsModSet $0F, $01, $01, $06
dc.b nF3, $60, smpsNoAttack, $30
smpsModSet $01, $01, $FB, $A7
smpsAlterPitch $F7
dc.b nC3
smpsAlterPitch $09
smpsModSet $0F, $01, $01, $06
dc.b nEb3, $60, smpsNoAttack, $30
smpsAlterPitch $FB
smpsModSet $01, $01, $F9, $A7
dc.b nC3, $30
smpsAlterPitch $05
Snd_VVZ1_Loop0B:
smpsPSGvoice sTone_11
smpsModSet $0F, $01, $01, $06
dc.b nF3, $60, smpsNoAttack, $30
smpsAlterPitch $F7
smpsModSet $01, $01, $FB, $A7
dc.b nC3
smpsAlterPitch $09
smpsModSet $0F, $01, $01, $06
dc.b nEb3, $60, smpsNoAttack, $30
smpsAlterPitch $FB
smpsModSet $01, $01, $F9, $A7
dc.b nC3
smpsAlterPitch $05
smpsModSet $0F, $01, $01, $06
dc.b nF3, $60, smpsNoAttack, $30
smpsAlterPitch $F7
smpsModSet $01, $01, $FB, $A7
dc.b nC3
smpsAlterPitch $09
smpsModSet $0F, $01, $01, $06
dc.b nEb3, $6C
smpsAlterPitch $0C
smpsPSGvoice sTone_26
dc.b nG4, $18, nC5, $3C
smpsAlterPitch $F4
smpsLoop $00, $02, Snd_VVZ1_Loop0B
smpsAlterPitch $0C
smpsPSGvoice sTone_26
smpsModSet $0F, $01, $01, $06
dc.b nAb3, $0C, nC4, nF4, nC4, nF4, nAb4, nC5, nAb4, nBb4, nG4, nEb4
dc.b nG4, nEb4, nBb3, nG3, nBb3, nG3, nEb4, nG4, nBb3, nEb4, nG4, nAb4
dc.b nBb4, nAb4, nF4, nCs4, nF4, nCs4, nAb3, nC4, nCs4, nAb3, nCs4, nF4
dc.b nCs4, nF4, nAb4, nCs5, nAb4, nBb4, nG4, nEb4, nG4, nEb4, nBb3, nEb4
dc.b nE4, nF4, nEb4, nG4, nBb3, nEb4, nG4, nAb4, nBb4, nAb4, nF4, nCs4
dc.b nF4, nCs4, nAb3, nC4, nCs4, nAb3, nCs4, nF4, nCs4, nF4, nAb4, nCs5
dc.b nAb4, nBb4, nG4, nEb4, nG4, nEb4, nBb3, nG3, nBb3, nG3, nBb3, nEb4
dc.b nBb3, nEb4, nG4, nAb4, nBb4, nAb4, nF4, nCs4, nF4, nCs4, nAb3, nC4
dc.b nCs4, nAb3, nCs4, nF4, nCs4, nF4, nAb4, nCs5, nAb4, nBb4, nG4, nEb4
dc.b nG4, nEb4, nBb3, nEb4, nE4, nF4, nEb4, nC4, nAb4, nF4, nEb4, nG4
dc.b nEb4, nF4, nEb4, nC4, nAb4, nF4, nEb4, nG4, nEb4
smpsAlterPitch $F4
smpsJump Snd_VVZ1_Jump04
; PSG2 Data
Snd_VVZ1_PSG2:
smpsAlterNote $FE
dc.b nRst, $0D, nRst, $30
smpsJump Snd_VVZ1_Jump04
; PSG3 Data
Snd_VVZ1_PSG3:
smpsPSGform $E7
dc.b nRst, $30
Snd_VVZ1_Loop09:
smpsCall Snd_VVZ1_Call0B
smpsLoop $00, $14, Snd_VVZ1_Loop09
Snd_VVZ1_Loop0A:
smpsCall Snd_VVZ1_Call0C
smpsLoop $00, $10, Snd_VVZ1_Loop0A
smpsJump Snd_VVZ1_Loop09
Snd_VVZ1_Call0B:
smpsPSGvoice sTone_0F
dc.b (nMaxPSG2-$23)&$FF, $06, $06, $06, $06
smpsPSGvoice sTone_12
dc.b $0C
smpsPSGvoice sTone_0F
dc.b (nMaxPSG2-$23)&$FF, $06, $06, $06, $06
smpsPSGvoice sTone_12
dc.b $0C
smpsPSGvoice sTone_0F
dc.b (nMaxPSG2-$23)&$FF, $06, $06
smpsPSGvoice sTone_12
dc.b $0C
smpsReturn
Snd_VVZ1_Call0C:
smpsPSGvoice sTone_0F
dc.b (nMaxPSG2-$23)&$FF, $06, $06
smpsPSGvoice sTone_12
dc.b $0C
smpsPSGvoice sTone_0F
dc.b (nMaxPSG2-$23)&$FF, $06, $06, $06, $06
smpsPSGvoice sTone_12
dc.b $0C
smpsPSGvoice sTone_0F
dc.b (nMaxPSG2-$23)&$FF, $06, $06, $06, $06
smpsPSGvoice sTone_12
dc.b $0C
smpsReturn
; DAC Data
Snd_VVZ1_DAC:
dc.b nRst, $30
Snd_VVZ1_Loop00:
smpsCall Snd_VVZ1_Call00
smpsCall Snd_VVZ1_Call01
smpsCall Snd_VVZ1_Call00
smpsCall Snd_VVZ1_Call02
smpsLoop $00, $05, Snd_VVZ1_Loop00
Snd_VVZ1_Loop01:
smpsCall Snd_VVZ1_Call03
smpsCall Snd_VVZ1_Call04
smpsCall Snd_VVZ1_Call03
smpsCall Snd_VVZ1_Call05
smpsCall Snd_VVZ1_Call03
smpsCall Snd_VVZ1_Call04
smpsCall Snd_VVZ1_Call06
smpsLoop $00, $02, Snd_VVZ1_Loop01
smpsJump Snd_VVZ1_Loop00
Snd_VVZ1_Call00:
dc.b dElectricHighTom, $06, dElectricMidTom, dElectricLowTom, $0C, dElectricLowTom, dElectricMidTom, $06, dElectricLowTom, dElectricFloorTom, $0C, dElectricFloorTom
dc.b dKickS3, $06, dKickS3, dKickS3, dSnareS3
smpsReturn
Snd_VVZ1_Call01:
dc.b dElectricHighTom, dElectricMidTom, dElectricLowTom, $0C, dElectricLowTom, dElectricMidTom, $06, dElectricLowTom, dElectricFloorTom, $0C, dElectricFloorTom, dSnareS3
dc.b $06, dSnareS3, $0C, $06
smpsReturn
Snd_VVZ1_Call02:
dc.b dElectricHighTom, dElectricMidTom, dElectricLowTom, $0C, dElectricLowTom, dElectricMidTom, $06, dElectricLowTom, dElectricFloorTom, $0C, dElectricFloorTom, dSnareS3
dc.b $06, dSnareS3, dSnareS3, dSnareS3
smpsReturn
Snd_VVZ1_Call03:
dc.b dKickS3, $06, dKickS3, dKickS3, dKickS3, dKickS3, $0C, dSnareS3, $06, $0C, dSnareS3, dSnareS3
dc.b $06
smpsReturn
Snd_VVZ1_Call04:
dc.b dElectricHighTom, $06, dElectricMidTom, dElectricLowTom, $0C
smpsReturn
Snd_VVZ1_Call05:
dc.b dElectricMidTom, $06, dElectricLowTom, dElectricFloorTom, $0C
smpsReturn
Snd_VVZ1_Call06:
dc.b dKickS3, $06, dKickS3, dKickS3, dKickS3, dKickS3, $0C, dElectricHighTom, $06, dElectricMidTom, $0C, dElectricLowTom
dc.b dElectricFloorTom, $06, dSnareS3, dSnareS3, dSnareS3, dSnareS3, dKickS3, dKickS3, dSnareS3, $0C, dKickS3, dKickS3
dc.b $06, dSnareS3, $0C, dSnareS3, dSnareS3, $06, dElectricHighTom, $04, dElectricHighTom, dElectricHighTom, dElectricMidTom, $06
dc.b dElectricLowTom, dKickS3, dKickS3, dSnareS3, $0C, dKickS3, dSnareS3, $06, $0C, dSnareS3, dSnareS3, $06
dc.b dElectricMidTom, $04, dElectricMidTom, dElectricMidTom, dElectricLowTom, $06, dElectricFloorTom, dKickS3, dKickS3, dKickS3, dKickS3, dKickS3
dc.b $0C, dSnareS3, $06, $0C, dSnareS3, dSnareS3, $06, dElectricHighTom, $04, dElectricMidTom, dElectricLowTom, dElectricFloorTom
dc.b $06, dElectricFloorTom, dSnareS3, $04, dSnareS3, dSnareS3, dElectricHighTom, $06, dElectricHighTom, dElectricMidTom, dElectricLowTom, dSnareS3
dc.b $04, dSnareS3, dSnareS3, dElectricMidTom, $06, dElectricMidTom, dElectricLowTom, dElectricFloorTom, dSnareS3, $0C, $06, dSnareS3
smpsReturn
Snd_VVZ1_Voices:
; Voice $00
; $08
; $0A, $70, $30, $00, $1F, $1F, $5F, $5F, $12, $0E, $0A, $0A
; $00, $04, $04, $03, $2F, $2F, $2F, $2F, $24, $2D, $13, $80
smpsVcAlgorithm $00
smpsVcFeedback $01
smpsVcUnusedBits $00
smpsVcDetune $00, $03, $07, $00
smpsVcCoarseFreq $00, $00, $00, $0A
smpsVcRateScale $01, $01, $00, $00
smpsVcAttackRate $1F, $1F, $1F, $1F
smpsVcAmpMod $00, $00, $00, $00
smpsVcDecayRate1 $0A, $0A, $0E, $12
smpsVcDecayRate2 $03, $04, $04, $00
smpsVcDecayLevel $02, $02, $02, $02
smpsVcReleaseRate $0F, $0F, $0F, $0F
smpsVcTotalLevel $00, $13, $2D, $24
; Voice $01
; $3D
; $06, $21, $51, $06, $12, $14, $14, $0F, $0A, $06, $06, $06
; $00, $00, $00, $00, $2B, $2B, $2B, $1B, $19, $80, $80, $80
smpsVcAlgorithm $05
smpsVcFeedback $07
smpsVcUnusedBits $00
smpsVcDetune $00, $05, $02, $00
smpsVcCoarseFreq $06, $01, $01, $06
smpsVcRateScale $00, $00, $00, $00
smpsVcAttackRate $0F, $14, $14, $12
smpsVcAmpMod $00, $00, $00, $00
smpsVcDecayRate1 $06, $06, $06, $0A
smpsVcDecayRate2 $00, $00, $00, $00
smpsVcDecayLevel $01, $02, $02, $02
smpsVcReleaseRate $0B, $0B, $0B, $0B
smpsVcTotalLevel $00, $00, $00, $19
; Voice $02
; $3E
; $07, $01, $02, $0A, $1F, $1F, $1F, $1F, $03, $06, $00, $00
; $08, $06, $07, $0C, $15, $0A, $0A, $0A, $20, $85, $86, $88
smpsVcAlgorithm $06
smpsVcFeedback $07
smpsVcUnusedBits $00
smpsVcDetune $00, $00, $00, $00
smpsVcCoarseFreq $0A, $02, $01, $07
smpsVcRateScale $00, $00, $00, $00
smpsVcAttackRate $1F, $1F, $1F, $1F
smpsVcAmpMod $00, $00, $00, $00
smpsVcDecayRate1 $00, $00, $06, $03
smpsVcDecayRate2 $0C, $07, $06, $08
smpsVcDecayLevel $00, $00, $00, $01
smpsVcReleaseRate $0A, $0A, $0A, $05
smpsVcTotalLevel $08, $06, $05, $20
; Voice $03
; $16
; $7A, $74, $3C, $31, $1F, $1F, $1F, $1F, $0A, $08, $0C, $0A
; $07, $0A, $07, $05, $2F, $AF, $AF, $5F, $14, $85, $8A, $80
smpsVcAlgorithm $06
smpsVcFeedback $02
smpsVcUnusedBits $00
smpsVcDetune $03, $03, $07, $07
smpsVcCoarseFreq $01, $0C, $04, $0A
smpsVcRateScale $00, $00, $00, $00
smpsVcAttackRate $1F, $1F, $1F, $1F
smpsVcAmpMod $00, $00, $00, $00
smpsVcDecayRate1 $0A, $0C, $08, $0A
smpsVcDecayRate2 $05, $07, $0A, $07
smpsVcDecayLevel $05, $0A, $0A, $02
smpsVcReleaseRate $0F, $0F, $0F, $0F
smpsVcTotalLevel $00, $0A, $05, $14
; Unused voice
; Voice $04
; $3C
; $71, $71, $11, $11, $17, $1E, $19, $1E, $04, $01, $07, $01
; $00, $00, $00, $00, $F7, $F8, $F7, $F8, $1E, $80, $14, $80
smpsVcAlgorithm $04
smpsVcFeedback $07
smpsVcUnusedBits $00
smpsVcDetune $01, $01, $07, $07
smpsVcCoarseFreq $01, $01, $01, $01
smpsVcRateScale $00, $00, $00, $00
smpsVcAttackRate $1E, $19, $1E, $17
smpsVcAmpMod $00, $00, $00, $00
smpsVcDecayRate1 $01, $07, $01, $04
smpsVcDecayRate2 $00, $00, $00, $00
smpsVcDecayLevel $0F, $0F, $0F, $0F
smpsVcReleaseRate $08, $07, $08, $07
smpsVcTotalLevel $00, $14, $00, $1E
; Unused voice
; Voice $05
; $3A
; $01, $07, $01, $01, $8E, $8E, $8D, $53, $0E, $0E, $0E, $03
; $00, $00, $00, $07, $1F, $FF, $1F, $0F, $18, $28, $27, $80
smpsVcAlgorithm $02
smpsVcFeedback $07
smpsVcUnusedBits $00
smpsVcDetune $00, $00, $00, $00
smpsVcCoarseFreq $01, $01, $07, $01
smpsVcRateScale $01, $02, $02, $02
smpsVcAttackRate $13, $0D, $0E, $0E
smpsVcAmpMod $00, $00, $00, $00
smpsVcDecayRate1 $03, $0E, $0E, $0E
smpsVcDecayRate2 $07, $00, $00, $00
smpsVcDecayLevel $00, $01, $0F, $01
smpsVcReleaseRate $0F, $0F, $0F, $0F
smpsVcTotalLevel $00, $27, $28, $18
; Unused voice
; Voice $06
; $3A
; $06, $06, $06, $06, $8E, $8E, $8D, $53, $0E, $0E, $0E, $03
; $00, $00, $00, $06, $1F, $FF, $1F, $0F, $17, $28, $27, $80
smpsVcAlgorithm $02
smpsVcFeedback $07
smpsVcUnusedBits $00
smpsVcDetune $00, $00, $00, $00
smpsVcCoarseFreq $06, $06, $06, $06
smpsVcRateScale $01, $02, $02, $02
smpsVcAttackRate $13, $0D, $0E, $0E
smpsVcAmpMod $00, $00, $00, $00
smpsVcDecayRate1 $03, $0E, $0E, $0E
smpsVcDecayRate2 $06, $00, $00, $00
smpsVcDecayLevel $00, $01, $0F, $01
smpsVcReleaseRate $0F, $0F, $0F, $0F
smpsVcTotalLevel $00, $27, $28, $17
; Unused voice
; Voice $07
; $35
; $06, $06, $13, $00, $1F, $1D, $18, $19, $00, $09, $06, $0D
; $00, $00, $02, $03, $00, $06, $15, $16, $1E, $80, $83, $80
smpsVcAlgorithm $05
smpsVcFeedback $06
smpsVcUnusedBits $00
smpsVcDetune $00, $01, $00, $00
smpsVcCoarseFreq $00, $03, $06, $06
smpsVcRateScale $00, $00, $00, $00
smpsVcAttackRate $19, $18, $1D, $1F
smpsVcAmpMod $00, $00, $00, $00
smpsVcDecayRate1 $0D, $06, $09, $00
smpsVcDecayRate2 $03, $02, $00, $00
smpsVcDecayLevel $01, $01, $00, $00
smpsVcReleaseRate $06, $05, $06, $00
smpsVcTotalLevel $00, $03, $00, $1E
; Unused voice
; Voice $08
; $3D
; $01, $21, $50, $01, $12, $14, $14, $0F, $0A, $05, $05, $05
; $00, $00, $00, $00, $26, $28, $28, $18, $19, $80, $80, $80
smpsVcAlgorithm $05
smpsVcFeedback $07
smpsVcUnusedBits $00
smpsVcDetune $00, $05, $02, $00
smpsVcCoarseFreq $01, $00, $01, $01
smpsVcRateScale $00, $00, $00, $00
smpsVcAttackRate $0F, $14, $14, $12
smpsVcAmpMod $00, $00, $00, $00
smpsVcDecayRate1 $05, $05, $05, $0A
smpsVcDecayRate2 $00, $00, $00, $00
smpsVcDecayLevel $01, $02, $02, $02
smpsVcReleaseRate $08, $08, $08, $06
smpsVcTotalLevel $00, $00, $00, $19
; Unused voice
; Voice $09
; $04
; $57, $02, $70, $50, $1F, $1F, $1F, $1F, $00, $00, $00, $00
; $06, $0A, $00, $0A, $00, $0F, $00, $0F, $1A, $80, $10, $80
smpsVcAlgorithm $04
smpsVcFeedback $00
smpsVcUnusedBits $00
smpsVcDetune $05, $07, $00, $05
smpsVcCoarseFreq $00, $00, $02, $07
smpsVcRateScale $00, $00, $00, $00
smpsVcAttackRate $1F, $1F, $1F, $1F
smpsVcAmpMod $00, $00, $00, $00
smpsVcDecayRate1 $00, $00, $00, $00
smpsVcDecayRate2 $0A, $00, $0A, $06
smpsVcDecayLevel $00, $00, $00, $00
smpsVcReleaseRate $0F, $00, $0F, $00
smpsVcTotalLevel $00, $10, $00, $1A
| 33.780776 | 170 | 0.607827 |
9c17abe1c9fc0dd03e54617a75cf5057f16d409e | 4,324 | asm | Assembly | Transynther/x86/_processed/NC/_st_zr_un_/i7-8650U_0xd2.log_1134_66.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 9 | 2020-08-13T19:41:58.000Z | 2022-03-30T12:22:51.000Z | Transynther/x86/_processed/NC/_st_zr_un_/i7-8650U_0xd2.log_1134_66.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 1 | 2021-04-29T06:29:35.000Z | 2021-05-13T21:02:30.000Z | Transynther/x86/_processed/NC/_st_zr_un_/i7-8650U_0xd2.log_1134_66.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 3 | 2020-07-14T17:07:07.000Z | 2022-03-21T01:12:22.000Z | .global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r15
push %rdi
push %rdx
lea addresses_WT_ht+0x14799, %rdi
nop
nop
sub %r10, %r10
movups (%rdi), %xmm4
vpextrq $0, %xmm4, %rdx
xor $52467, %r15
pop %rdx
pop %rdi
pop %r15
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r11
push %rax
push %rbp
push %rbx
push %rcx
push %rsi
// Store
lea addresses_A+0x15009, %rcx
nop
nop
nop
nop
xor $16954, %rbp
mov $0x5152535455565758, %r10
movq %r10, (%rcx)
nop
nop
nop
cmp %r11, %r11
// Faulty Load
mov $0x31723d0000000009, %r11
nop
nop
nop
cmp $27281, %rax
mov (%r11), %bx
lea oracles, %rsi
and $0xff, %rbx
shlq $12, %rbx
mov (%rsi,%rbx,1), %rbx
pop %rsi
pop %rcx
pop %rbx
pop %rbp
pop %rax
pop %r11
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_NC', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_A', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 7, 'same': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_NC', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}}
<gen_prepare_buffer>
{'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 2, 'same': False}}
{'58': 752, '00': 321, '16': 61}
58 00 58 58 58 58 58 58 58 58 00 00 58 58 00 00 00 58 58 58 58 58 00 16 00 58 00 58 58 58 58 00 58 58 58 00 58 58 58 58 58 16 00 58 58 58 00 00 58 58 58 58 00 58 58 58 58 00 58 58 00 00 00 58 58 58 58 58 58 58 58 58 00 58 58 58 00 58 58 58 16 58 00 58 58 58 58 58 58 58 58 58 58 58 00 58 16 16 58 58 00 00 58 58 58 00 00 58 58 00 58 58 58 58 58 58 00 00 58 58 58 58 58 00 58 58 58 00 58 58 00 58 16 58 58 58 58 58 00 16 00 00 58 58 00 58 16 58 58 58 58 00 58 58 58 58 00 58 00 58 58 58 00 58 00 58 16 16 00 58 58 58 58 58 58 00 58 58 58 58 58 58 16 58 58 58 58 58 58 58 58 00 58 58 00 00 58 58 58 00 58 58 58 58 00 00 58 00 58 00 58 58 00 00 58 58 58 00 00 00 58 58 58 58 58 58 58 58 58 00 58 58 58 58 16 58 58 58 58 00 00 58 58 58 00 00 00 00 00 00 58 58 00 58 58 58 58 58 58 58 58 00 58 58 00 00 58 58 58 58 00 58 58 58 00 58 58 58 58 58 58 00 00 00 58 00 00 58 16 58 00 58 16 58 58 58 00 58 58 58 00 00 58 00 00 58 00 00 58 58 58 58 58 00 58 00 58 00 58 00 58 58 58 58 00 00 58 58 58 58 58 00 00 00 58 58 16 00 58 58 00 58 58 00 58 00 58 58 58 58 16 58 00 00 58 00 58 58 58 58 58 00 58 00 58 58 58 58 00 00 58 00 00 58 58 58 58 58 58 16 58 58 16 16 58 58 58 58 58 16 58 58 58 58 58 58 00 16 58 00 58 58 00 58 58 58 00 58 58 00 00 58 00 58 58 58 58 00 58 00 00 58 58 58 00 58 00 58 58 58 00 58 58 00 58 16 58 58 58 00 58 16 00 58 58 00 58 58 58 58 00 58 58 00 00 00 58 58 16 58 58 58 58 58 58 00 58 58 58 58 58 00 00 00 00 58 00 58 00 00 00 00 16 58 58 58 58 58 58 58 58 58 58 00 00 58 00 58 16 58 58 16 00 58 58 58 58 00 16 58 58 58 58 58 00 00 00 00 16 00 58 00 58 58 58 00 58 58 00 00 58 00 58 58 58 58 00 00 58 00 58 00 58 58 58 58 58 58 00 58 58 00 58 00 58 00 00 00 58 00 58 58 00 58 58 58 00 58 00 00 58 58 16 58 58 00 00 58 00 58 58 00 58 58 58 58 16 58 00 58 58 00 58 58 58 58 16 58 00 58 58 58 58 00 00 58 58 00 58 00 58 58 58 58 58 58 58 58 58 00 58 58 58 58 58 58 00 00 58 58 58 58 58 58 58 16 58 58 58 58 00 58 00 58 58 00 58 58 00 00 00 58 58 58 58 16 58 58 58 58 00 58 58 58 58 16 58 00 58 16 16 58 58 16 00 00 58 00 00 58 58 58 58 00 58 58 58 58 58 00 58 58 58 00 58 58 58 58 58 58 58 58 58 00 16 58 00 58 00 58 58 58 58 58 58 00 00 58 58 00 58 00 58 58 58 16 58 58 58 58 58 58 58 00 00 58 00 58 58 00 58 00 58 58 58 58 00 16 58 58 58 58 58 16 00 00 58 58 58 58 00 00 58 00 58 00 00 00 58 58 00 58 58 00 58 58 58 00 58 00 58 58 58 00 58 58 00 58 58 58 00 58 58 58 58 00 00 58 00 58 00 16 58 58 16 58 58 00 00 58 16 58 58 58 00 00 58 00 58 00 00 58 58 00 58 58 00 58 58 16 58 58 58 58 58 58 58 58 58 00 00 00 58 58 58 58 00 00 58 58 16 58 58 00 00 58 00 58 58 58 00 58 00 58 58 00 00 58 58 58 16 58 58 58 58 58 16 58 00 58 00 00 00 00 58 58 58 58 58 58 58 58 00 58 58 00 16 58 58 00 00 00 58 58 00 58 58 58 00 58 58 58 00 58 58 58 00 58 58 00 00 00 58 58 58 58 58 58 58 00 58 58 58 00 58 58 58 58 58 00 58 58 00 00 00 16 58 58 58 00 58 58 58 58 58 58 58 58 00 58 58 00 00 00 00 00 58 00 58 58 00 58 58 58 00 58 58 00 16 58 16 00 00 00 00 58 58 00 58 00 00 58 58 58 58 00 58 00 58 58
*/
| 56.894737 | 2,999 | 0.659574 |
ba1d57a66fb681218efbd03cd374cc32b0a2ed2e | 263 | asm | Assembly | third_party/libvpx/source/config/win/x64/asm_dec_offsets.asm | kpek8883/web | 20bff89ae8df14aed15ec471f465338bd3668b3a | [
"BSD-3-Clause"
] | 117 | 2015-01-01T12:49:08.000Z | 2021-12-16T10:57:43.000Z | third_party/libvpx/source/config/win/x64/asm_dec_offsets.asm | kpek8883/web | 20bff89ae8df14aed15ec471f465338bd3668b3a | [
"BSD-3-Clause"
] | 4 | 2015-04-10T15:56:09.000Z | 2018-05-09T08:03:10.000Z | third_party/libvpx/source/config/win/x64/asm_dec_offsets.asm | kpek8883/web | 20bff89ae8df14aed15ec471f465338bd3668b3a | [
"BSD-3-Clause"
] | 48 | 2015-01-01T12:49:09.000Z | 2020-12-21T09:23:00.000Z | bool_decoder_user_buffer_end EQU 0
bool_decoder_user_buffer EQU 8
bool_decoder_value EQU 16
bool_decoder_count EQU 24
bool_decoder_range EQU 28
END
| 37.571429 | 50 | 0.501901 |
cb249d3c819d2c9515d89edf924636c3671aae7e | 594 | asm | Assembly | oeis/020/A020658.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 11 | 2021-08-22T19:44:55.000Z | 2022-03-20T16:47:57.000Z | oeis/020/A020658.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 9 | 2021-08-29T13:15:54.000Z | 2022-03-09T19:52:31.000Z | oeis/020/A020658.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 3 | 2021-08-22T20:56:47.000Z | 2021-09-29T06:26:12.000Z | ; A020658: Lexicographically earliest increasing sequence of positive numbers that contains no arithmetic progression of length 7.
; Submitted by Simon Strandgaard
; 1,2,3,4,5,6,8,9,10,11,12,13,15,16,17,18,19,20,22,23,24,25,26,27,29,30,31,32,33,34,36,37,38,39,40,41,50,51,52,53,54,55,57,58,59,60,61,62,64,65,66,67,68,69,71,72,73,74,75,76,78,79,80,81,82,83,85,86,87,88,89,90,99,100,101,102,103,104,106,107,108,109,110,111,113,114,115,116,117,118,120,121,122,123,124,125,127,128,129,130
mov $3,1
lpb $0
mov $2,$0
div $0,6
mod $2,6
mul $2,$3
add $1,$2
mul $3,7
lpe
mov $0,$1
add $0,1
| 37.125 | 320 | 0.688552 |
7e2d13a63cc8561716af40a9ec749af21bb008d7 | 838,667 | asm | Assembly | Z80EmulatorConsoleApp/DataFiles/code.asm | PendleCodeMonkey/Z80Emulator | 6ef3e6a637d21361bdf7958c99d5c1e4b76a2765 | [
"MIT"
] | null | null | null | Z80EmulatorConsoleApp/DataFiles/code.asm | PendleCodeMonkey/Z80Emulator | 6ef3e6a637d21361bdf7958c99d5c1e4b76a2765 | [
"MIT"
] | null | null | null | Z80EmulatorConsoleApp/DataFiles/code.asm | PendleCodeMonkey/Z80Emulator | 6ef3e6a637d21361bdf7958c99d5c1e4b76a2765 | [
"MIT"
] | null | null | null |
;************************************************************************
;** 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 DEFM .TEXT
;#define ORG .ORG
;#define EQU .EQU
;#define equ .EQU
; 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,$FFFF ; 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 $0008 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,($5C5D) ; Fetch the character address from CH_ADD.
LD ($5C5F),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 $FF, $FF, $FF ; Five unused locations.
DEFB $FF, $FF ;
; -------------------------------
; 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,($5C5D) ; 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 $FF, $FF, $FF ; 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 $FF, $FF, $FF ; spare - note that on the ZX81, space being a
DEFB $FF, $FF ; 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,($5C61) ; 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,($5C78) ; Fetch the first two bytes at FRAMES1.
INC HL ; Increment lowest two bytes of counter.
LD ($5C78),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+$40) ; 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+$00),L ; Store it in the system variable ERR_NR.
LD SP,($5C3D) ; 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 $FF, $FF, $FF ; Unused locations
DEFB $FF, $FF, $FF ; before the fixed-position
DEFB $FF ; 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,($5CB0) ; 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,($5C5D) ; fetch address from CH_ADD.
;; TEMP-PTR1
L0077: INC HL ; increase the character address by one.
;; TEMP-PTR2
L0078: LD ($5C5D),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 $21 ; test if higher than space.
RET NC ; return with carry clear if so.
CP $0D ; 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 $10 ; test if 0-15d
RET C ; return, if so, with carry set.
CP $18 ; 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 $16 ; 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 ($5C5D),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 '?'+$80
DEFM "RN"
DEFB 'D'+$80
DEFM "INKEY"
DEFB '$'+$80
DEFB 'P','I'+$80
DEFB 'F','N'+$80
DEFM "POIN"
DEFB 'T'+$80
DEFM "SCREEN"
DEFB '$'+$80
DEFM "ATT"
DEFB 'R'+$80
DEFB 'A','T'+$80
DEFM "TA"
DEFB 'B'+$80
DEFM "VAL"
DEFB '$'+$80
DEFM "COD"
DEFB 'E'+$80
DEFM "VA"
DEFB 'L'+$80
DEFM "LE"
DEFB 'N'+$80
DEFM "SI"
DEFB 'N'+$80
DEFM "CO"
DEFB 'S'+$80
DEFM "TA"
DEFB 'N'+$80
DEFM "AS"
DEFB 'N'+$80
DEFM "AC"
DEFB 'S'+$80
DEFM "AT"
DEFB 'N'+$80
DEFB 'L','N'+$80
DEFM "EX"
DEFB 'P'+$80
DEFM "IN"
DEFB 'T'+$80
DEFM "SQ"
DEFB 'R'+$80
DEFM "SG"
DEFB 'N'+$80
DEFM "AB"
DEFB 'S'+$80
DEFM "PEE"
DEFB 'K'+$80
DEFB 'I','N'+$80
DEFM "US"
DEFB 'R'+$80
DEFM "STR"
DEFB '$'+$80
DEFM "CHR"
DEFB '$'+$80
DEFM "NO"
DEFB 'T'+$80
DEFM "BI"
DEFB 'N'+$80
; 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'+$80
DEFM "AN"
DEFB 'D'+$80
DEFB $3C,'='+$80 ; <=
DEFB $3E,'='+$80 ; >=
DEFB $3C,$3E+$80 ; <>
DEFM "LIN"
DEFB 'E'+$80
DEFM "THE"
DEFB 'N'+$80
DEFB 'T','O'+$80
DEFM "STE"
DEFB 'P'+$80
DEFM "DEF F"
DEFB 'N'+$80
DEFM "CA"
DEFB 'T'+$80
DEFM "FORMA"
DEFB 'T'+$80
DEFM "MOV"
DEFB 'E'+$80
DEFM "ERAS"
DEFB 'E'+$80
DEFM "OPEN "
DEFB '#'+$80
DEFM "CLOSE "
DEFB '#'+$80
DEFM "MERG"
DEFB 'E'+$80
DEFM "VERIF"
DEFB 'Y'+$80
DEFM "BEE"
DEFB 'P'+$80
DEFM "CIRCL"
DEFB 'E'+$80
DEFM "IN"
DEFB 'K'+$80
DEFM "PAPE"
DEFB 'R'+$80
DEFM "FLAS"
DEFB 'H'+$80
DEFM "BRIGH"
DEFB 'T'+$80
DEFM "INVERS"
DEFB 'E'+$80
DEFM "OVE"
DEFB 'R'+$80
DEFM "OU"
DEFB 'T'+$80
DEFM "LPRIN"
DEFB 'T'+$80
DEFM "LLIS"
DEFB 'T'+$80
DEFM "STO"
DEFB 'P'+$80
DEFM "REA"
DEFB 'D'+$80
DEFM "DAT"
DEFB 'A'+$80
DEFM "RESTOR"
DEFB 'E'+$80
DEFM "NE"
DEFB 'W'+$80
DEFM "BORDE"
DEFB 'R'+$80
DEFM "CONTINU"
DEFB 'E'+$80
DEFM "DI"
DEFB 'M'+$80
DEFM "RE"
DEFB 'M'+$80
DEFM "FO"
DEFB 'R'+$80
DEFM "GO T"
DEFB 'O'+$80
DEFM "GO SU"
DEFB 'B'+$80
DEFM "INPU"
DEFB 'T'+$80
DEFM "LOA"
DEFB 'D'+$80
DEFM "LIS"
DEFB 'T'+$80
DEFM "LE"
DEFB 'T'+$80
DEFM "PAUS"
DEFB 'E'+$80
DEFM "NEX"
DEFB 'T'+$80
DEFM "POK"
DEFB 'E'+$80
DEFM "PRIN"
DEFB 'T'+$80
DEFM "PLO"
DEFB 'T'+$80
DEFM "RU"
DEFB 'N'+$80
DEFM "SAV"
DEFB 'E'+$80
DEFM "RANDOMIZ"
DEFB 'E'+$80
DEFB 'I','F'+$80
DEFM "CL"
DEFB 'S'+$80
DEFM "DRA"
DEFB 'W'+$80
DEFM "CLEA"
DEFB 'R'+$80
DEFM "RETUR"
DEFB 'N'+$80
DEFM "COP"
DEFB 'Y'+$80
; ----------------
; 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 $27] 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 $20 added to the value.
; The keywords for the main alphabetic keys are obtained by adding $A5 to
; the values obtained from this table.
;; MAIN-KEYS
L0205: DEFB $42 ; B
DEFB $48 ; H
DEFB $59 ; Y
DEFB $36 ; 6
DEFB $35 ; 5
DEFB $54 ; T
DEFB $47 ; G
DEFB $56 ; V
DEFB $4E ; N
DEFB $4A ; J
DEFB $55 ; U
DEFB $37 ; 7
DEFB $34 ; 4
DEFB $52 ; R
DEFB $46 ; F
DEFB $43 ; C
DEFB $4D ; M
DEFB $4B ; K
DEFB $49 ; I
DEFB $38 ; 8
DEFB $33 ; 3
DEFB $45 ; E
DEFB $44 ; D
DEFB $58 ; X
DEFB $0E ; SYMBOL SHIFT
DEFB $4C ; L
DEFB $4F ; O
DEFB $39 ; 9
DEFB $32 ; 2
DEFB $57 ; W
DEFB $53 ; S
DEFB $5A ; Z
DEFB $20 ; SPACE
DEFB $0D ; ENTER
DEFB $50 ; P
DEFB $30 ; 0
DEFB $31 ; 1
DEFB $51 ; Q
DEFB $41 ; A
;; E-UNSHIFT
; The 26 unshifted extended mode keys for the alphabetic characters.
; The green keywords on the original keyboard.
L022C: DEFB $E3 ; READ
DEFB $C4 ; BIN
DEFB $E0 ; LPRINT
DEFB $E4 ; DATA
DEFB $B4 ; TAN
DEFB $BC ; SGN
DEFB $BD ; ABS
DEFB $BB ; SQR
DEFB $AF ; CODE
DEFB $B0 ; VAL
DEFB $B1 ; LEN
DEFB $C0 ; USR
DEFB $A7 ; PI
DEFB $A6 ; INKEY$
DEFB $BE ; PEEK
DEFB $AD ; TAB
DEFB $B2 ; SIN
DEFB $BA ; INT
DEFB $E5 ; RESTORE
DEFB $A5 ; RND
DEFB $C2 ; CHR$
DEFB $E1 ; LLIST
DEFB $B3 ; COS
DEFB $B9 ; EXP
DEFB $C1 ; STR$
DEFB $B8 ; LN
;; EXT-SHIFT
; The 26 shifted extended mode keys for the alphabetic characters.
; The red keywords below keys on the original keyboard.
L0246: DEFB $7E ; ~
DEFB $DC ; BRIGHT
DEFB $DA ; PAPER
DEFB $5C ; \
DEFB $B7 ; ATN
DEFB $7B ; {
DEFB $7D ; }
DEFB $D8 ; CIRCLE
DEFB $BF ; IN
DEFB $AE ; VAL$
DEFB $AA ; SCREEN$
DEFB $AB ; ATTR
DEFB $DD ; INVERSE
DEFB $DE ; OVER
DEFB $DF ; OUT
DEFB $7F ; (Copyright character)
DEFB $B5 ; ASN
DEFB $D6 ; VERIFY
DEFB $7C ; |
DEFB $D5 ; MERGE
DEFB $5D ; ]
DEFB $DB ; FLASH
DEFB $B6 ; ACS
DEFB $D9 ; INK
DEFB $5B ; [
DEFB $D7 ; BEEP
;; CTL-CODES
; The ten control codes assigned to the top line of digits when the shift
; key is pressed.
L0260: DEFB $0C ; DELETE
DEFB $07 ; EDIT
DEFB $06 ; CAPS LOCK
DEFB $04 ; TRUE VIDEO
DEFB $05 ; INVERSE VIDEO
DEFB $08 ; CURSOR LEFT
DEFB $0A ; CURSOR DOWN
DEFB $0B ; CURSOR UP
DEFB $09 ; CURSOR RIGHT
DEFB $0F ; 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 $E2 ; STOP
DEFB $2A ; *
DEFB $3F ; ?
DEFB $CD ; STEP
DEFB $C8 ; >=
DEFB $CC ; TO
DEFB $CB ; THEN
DEFB $5E ; ^
DEFB $AC ; AT
DEFB $2D ; -
DEFB $2B ; +
DEFB $3D ; =
DEFB $2E ; .
DEFB $2C ; ,
DEFB $3B ; ;
DEFB $22 ; "
DEFB $C7 ; <=
DEFB $3C ; <
DEFB $C3 ; NOT
DEFB $3E ; >
DEFB $C5 ; OR
DEFB $2F ; /
DEFB $C9 ; <>
DEFB $60 ; pound
DEFB $C6 ; AND
DEFB $3A ; :
;; E-DIGITS
; The ten keywords assigned to the digits in extended mode.
; The remaining red keywords below the keys.
L0284: DEFB $D0 ; FORMAT
DEFB $CE ; DEF FN
DEFB $A8 ; FN
DEFB $CA ; LINE
DEFB $D3 ; OPEN #
DEFB $D4 ; CLOSE #
DEFB $D1 ; MOVE
DEFB $D2 ; ERASE
DEFB $A9 ; POINT
DEFB $CF ; 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
; ^ $27 $18 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,$2F ; initial key value
; valid values are obtained by subtracting
; eight five times.
LD DE,$FFFF ; a buffer to receive 2 keys.
LD BC,$FEFE ; 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 $1F ; 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 $08 ; subtract 8 from the key value
; cycling through key values (top = $27)
; 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 $01-$28 (1-40d)
RET Z ; return if one key or no key.
CP $28 ; is it capsshift (was $27) ?
RET Z ; return if so.
CP $19 ; is it symbol shift (was $18) ?
RET Z ; return also
LD A,E ; now test E
LD E,D ; but first switch
LD D,A ; the two keys.
CP $18 ; 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.
;
;; 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,$5C00 ; point to KSTATE-0
;; K-ST-LOOP
L02C6: BIT 7,(HL) ; is it free ? (i.e. $FF)
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),$FF ; else mark this particular map free.
;; K-CH-SET
L02D1: LD A,L ; make a copy of the low address byte.
LD HL,$5C04 ; point to KSTATE-4
; (ld l,$04 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,$5C00 ; 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,$5C04 ; 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),$05 ; and initialize counter to 5
INC HL ; advance to the delay
LD A,($5C09) ; 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+$07) ; pick up MODE (3 bytes)
LD D,(IY+$01) ; pick up FLAGS (3 bytes)
PUSH HL ; save state map location
; Note. could now have used, to avoid IY,
; ld l,$41; ld c,(hl); ld l,$3B; 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 ($5C08),A ; update LASTK system variable.
SET 5,(IY+$01) ; 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),$05 ; 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,($5C0A) ; 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 $A5 (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 $FF if not shift.
LD D,$00 ; and reset D to index into main table
LD A,E ; load least significant key from E
CP $27 ; is it higher than 39d i.e. FF
RET NC ; return with just a shift (in B now)
CP $18 ; 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 $FF (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 $3A ; 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' ($55).
; 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,$4F ; 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-$41 ; base address of E-UNSHIFT L022c.
; ( $01EB 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-$41 ; Address: $0205 L0246-$41 EXT-SHIFT base
;; K-LOOK-UP
L034A: LD D,$00 ; 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-$41 ; prepare base of sym-codes
BIT 0,B ; shift=$27 sym-shift=$18
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+$30) ; 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,$20 ; else convert the code to lower case.
RET ; return.
; ---
; the jump was here for tokens
;; K-TOKENS
L0364: ADD A,$A5 ; 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 $30 ; 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-$30 ; $0254 - base of E-DIGITS
BIT 5,B ; test - shift=$27 sym-shift=$18
JR Z,L034A ; to K-LOOK-UP if sym-shift
CP $38 ; is character '8' ?
JR NC,L0382 ; to K-8-&-9 if greater than '7'
SUB $20 ; reduce to ink range $10-$17
INC B ; shift ?
RET Z ; return if not.
ADD A,$08 ; add 8 to give paper range $18 - $1F
RET ; return
; ---
; 89
;; K-8-&-9
L0382: SUB $36 ; reduce to 02 and 03 bright codes
INC B ; test if shift pressed.
RET Z ; return if not.
ADD A,$FE ; subtract 2 setting carry
RET ; to give 0 and 1 flash codes.
; ---
; graphics mode with digits
;; K-GRA-DGT
L0389: LD HL,L0260-$30 ; $0230 base address of CTL-CODES
CP $39 ; is key '9' ?
JR Z,L034A ; back to K-LOOK-UP - changed to $0F, GRAPHICS.
CP $30 ; is key '0' ?
JR Z,L034A ; back to K-LOOK-UP - changed to $0C, delete.
; for keys '0' - '7' we assign a mosaic character depending on shift.
AND $07 ; convert character to number. 0 - 7.
ADD A,$80 ; add offset - they start at $80
INC B ; destructively test for shift
RET Z ; and return if not pressed.
XOR $0F ; toggle bits becomes range $88-$8F
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-$30 ; prepare base of table CTL-CODES.
JR NZ,L034A ; back to K-LOOK-UP if shift pressed.
; must have been symbol shift
SUB $10 ; for ASCII most will now be correct
; on a standard typewriter.
CP $22 ; but '@' is not - see below.
JR Z,L03B2 ; forward to K-@-CHAR if so
CP $20 ; '_' is the other one that fails
RET NZ ; return if not.
LD A,$5F ; substitute ASCII '_'
RET ; return.
; ---
;; K-@-CHAR
L03B2: LD A,$40 ; substitute ASCII '@'
RET ; return.
; ------------------------------------------------------------------------
; The Spectrum Input character keys. One or two are abbreviated.
; From $00 Flash 0 to $FF 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, $7F, has been made a copyright symbol.
; Also $60, '`', 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 $03 ; A = 3 - fine part of tone period
LD C,A ;
LD B,$00 ;
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,($5C48) ; BORDCR
AND $38 ; bits 5..3 contain border colour
RRCA ; border colour bits moved to 2..0
RRCA ; to match border bits on port #FE
RRCA ;
OR $08 ; 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,$3F ;(7) ;
DEC B ;(4) ;
JP NZ,L03D6 ;(10) ; to BE-H&L-LP
XOR $10 ;(7) ; toggle output beep bit
OUT ($FE),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 $31 ;;duplicate ; duplicate pitch
DEFB $27 ;;int ; convert to integer
DEFB $C0 ;;st-mem-0 ; store integer pitch to memory 0
DEFB $03 ;;subtract ; calculate fractional part of pitch = fp_pitch - int_pitch
DEFB $34 ;;stk-data ; push constant
DEFB $EC ;;Exponent: $7C, Bytes: 4 ; constant = 0.05762265
DEFB $6C,$98,$1F,$F5 ;;($6C,$98,$1F,$F5)
DEFB $04 ;;multiply ; compute:
DEFB $A1 ;;stk-one ; 1 + 0.05762265 * fraction_part(pitch)
DEFB $0F ;;addition
DEFB $38 ;;end-calc ; leave on calc stack
LD HL,$5C92 ; 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,$3C ; 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,$FA ; 6 octaves below middle C
;; BE-OCTAVE ; A=# semitones above 5 octaves below middle C
L0427: INC B ; increment octave
SUB $0C ; 12 semitones = one octave
JR NC,L0427 ; to BE-OCTAVE
ADD A,$0C ; 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 + $046E
CALL L33B4 ; routine STACK-NUM
; read FP value (freq) from semitone table (HL) and push onto calc stack
RST 28H ;; FP-CALC
DEFB $04 ;;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 $38 ;;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 $C0 ;;st-mem-0 ; store frequency in memory 0
DEFB $02 ;;delete ; remove from calc stack
DEFB $31 ;;duplicate ; duplicate duration (seconds)
DEFB $38 ;;end-calc
CALL L1E94 ; routine FIND-INT1 ; FP duration to A
CP $0B ; 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 $E0 ;;get-mem-0 ; push frequency
DEFB $04 ;;multiply ; result1: #cycles = duration * frequency
DEFB $E0 ;;get-mem-0 ; push frequency
DEFB $34 ;;stk-data ; push constant
DEFB $80 ;;Exponent $93, Bytes: 3 ; constant = 437500
DEFB $43,$55,$9F,$80 ;;($55,$9F,$80,$00)
DEFB $01 ;;exchange ; frequency on top
DEFB $05 ;;division ; 437500 / frequency
DEFB $34 ;;stk-data ; push constant
DEFB $35 ;;Exponent: $85, Bytes: 1 ; constant = 30.125
DEFB $71 ;;($71,$00,$00,$00)
DEFB $03 ;;subtract ; result2: tone_period(HL) = 437500 / freq - 30.125
DEFB $38 ;;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 $0A ; 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 $89, $02, $D0, $12, $86; 261.625565290 C
DEFB $89, $0A, $97, $60, $75; 277.182631135 C#
DEFB $89, $12, $D5, $17, $1F; 293.664768100 D
DEFB $89, $1B, $90, $41, $02; 311.126983881 D#
DEFB $89, $24, $D0, $53, $CA; 329.627557039 E
DEFB $89, $2E, $9D, $36, $B1; 349.228231549 F
DEFB $89, $38, $FF, $49, $3E; 369.994422674 F#
DEFB $89, $43, $FF, $6A, $73; 391.995436072 G
DEFB $89, $4F, $A7, $00, $54; 415.304697513 G#
DEFB $89, $5C, $00, $00, $00; 440.000000000 A
DEFB $89, $69, $14, $F6, $24; 466.163761616 A#
DEFB $89, $76, $F1, $10, $05; 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,($5C3B) ; 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 ($FE)
;
; spk mic { border }
; ___ ___ ___ ___ ___ ___ ___ ___
; PORT | | | | | | | | |
; 254 | | | | | | | | |
; $FE |___|___|___|___|___|___|___|___|
; 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 $00 for a header, $FF for data.
;; 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,$1F80 ; a timing constant H=$1F, L=$80
; 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,$0C98 ; another timing value H=$0C, L=$98.
; a two second lead-in is used for the data.
;; SA-FLAG
L04D0: EX AF,AF' ; save flag
INC DE ; increase length by one.
DEC IX ; decrease start.
DI ; disable interrupts
LD A,$02 ; 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 $A4 (or $A3)
OUT ($FE),A ; output byte $02/$0D to tape port.
XOR $0F ; switch from RED (mic on) to CYAN (mic off).
LD B,$A4 ; hold count. also timed instruction.
DEC L ; originally $80 or $98.
; 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 $FF
; 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,$2F ; another short timed delay.
;; SA-SYNC-1
L04EA: DJNZ L04EA ; self loop to SA-SYNC-1
OUT ($FE),A ; switch to mic on and red.
LD A,$0D ; prepare mic off - cyan
LD B,$37 ; another short timed delay.
;; SA-SYNC-2
L04F2: DJNZ L04F2 ; self loop to SA-SYNC-2
OUT ($FE),A ; output mic off, cyan border.
LD BC,$3B0E ; B=$3B time(*), C=$0E, YELLOW, MIC OFF.
;
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, $FF or $00.
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 $FFFF.
;; 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+$00) ; 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,$01 ; 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 $3E.
; The entry point to save 1 entire bit. For first bit B holds $3B(*).
; 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
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,$42 ; set timed delay. (66 decimal)
;; SA-SET
L051A: DJNZ L051A ; self loop to SA-SET
; (roughly an extra 66*13 clock cycles)
;; SA-OUT
L051C: OUT ($FE),A ; blue and mic on OR yellow and mic off.
LD B,$3E ; 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 $3E to $3D.
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.
; 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,$31 ; set up timing.
LD A,$7F ; test the space key and
IN A,($FE) ; 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 $FFFF.
LD A,D ; fetch high byte
INC A ; increment.
JP NZ,L04FE ; JUMP to SA-LOOP if more bytes.
LD B,$3B ; a final delay.
;; SA-DELAY
L053C: DJNZ L053C ; self loop to SA-DELAY
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.
;
; - - >
;; SA/LD-RET
L053F: PUSH AF ; preserve accumulator throughout.
LD A,($5C48) ; fetch border colour from BORDCR.
AND $38 ; mask off paper bits.
RRCA ; rotate
RRCA ; to the
RRCA ; range 0-7.
OUT ($FE),A ; change the border colour.
LD A,$7F ; read from port address $7FFE the
IN A,($FE) ; row with the space key at outside.
RRA ; test for space key pressed.
EI ; enable interrupts
JR C,L0554 ; forward to SA/LD-END if not
;; REPORT-Da
L0552: RST 08H ; ERROR-1
DEFB $0C ; 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 $00 for a
; header or to $FF 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.
;; 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,$0F ; make the border white and mic off.
OUT ($FE),A ; output to port.
LD HL,L053F ; Address: SA/LD-RET
PUSH HL ; is saved on stack as terminating routine.
; 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,($FE) ; read the ear state - bit 6.
RRA ; rotate to bit 5.
AND $20 ; isolate this bit.
OR $02 ; combine with red border colour.
LD C,A ; and store initial state long-term in C.
CP A ; set the zero flag.
;
;; 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,$0415 ; 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,$9C ; set timing value.
CALL L05E3 ; routine LD-EDGE-2
JR NC,L056B ; back to LD-BREAK if time-out
LD A,$C6 ; 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,$C9 ; 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 $D4 ; 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 $FF
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 $03 ; and make blue/yellow.
LD C,A ; store the new long-term byte.
LD H,$00 ; set up parity byte as zero.
LD B,$B0 ; 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+$00),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+$00) ; 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,$B2 ; 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,$01 ; 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,$CB ; 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,$B0 ; 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 $01 ; set carry if zero.
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 $FE.
; 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,$16 ; 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 $FF passed.
LD A,$7F ; prepare to read keyboard and EAR port
IN A,($FE) ; row $7FFE. 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 $20 ; 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 $07 ; isolate new colour bits.
OR $08 ; set bit 3 - MIC off.
OUT ($FE),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
; $00 - SAVE
; $01 - LOAD
; $02 - VERIFY
; $03 - MERGE
; As with all commands the address STMT-RET is on the stack.
;; SAVE-ETC
L0605: POP AF ; discard address STMT-RET.
LD A,($5C74) ; fetch T_ADDR
; Now reduce the low byte of the Syntax table entry to give command.
; Note. For ZASM use SUB $E0 as next instruction.
L0609: SUB L1ADF + 1 % 256 ; subtract the known offset.
; ( is SUB $E0 in standard ROM )
LD ($5C74),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,$0011 ; presume seventeen bytes for a header.
LD A,($5C74) ; fetch command from T_ADDR.
AND A ; test for zero - SAVE.
JR Z,L0621 ; forward to SA-SPACE if so.
LD C,$22 ; 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,$0B ; set counter to eleven.
LD A,$20 ; 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+$01),$FF ; set first byte of ten character filename
; to $FF 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,$FFF6 ; prepare the value minus ten.
DEC BC ; decrement length.
; ten becomes nine, zero becomes $FFFF.
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,($5C74) ; 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 $0E ; 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,$000A ; 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 $E4 ; 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,($5C74) ; fetch command from T_ADDR
CP $03 ; 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,$0000 ; set destination to zero as not fixed.
LD A,($5C74) ; 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 $01 ; 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+$0B),A ; place in descriptor.
INC HL ; point to high byte.
LD A,(HL) ; and transfer that
LD (IX+$0C),A ; to descriptor.
INC HL ; increase pointer within variable.
;; SA-V-NEW
L0685: LD (IX+$0E),C ; place character array name in header.
LD A,$01 ; 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+$00),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 $29 ; 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 $AA ; is character the token 'SCREEN$' ?
JR NZ,L06C3 ; forward to SA-CODE if not.
LD A,($5C74) ; fetch command from T_ADDR
CP $03 ; 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+$0B),$00 ; set descriptor length
LD (IX+$0C),$1B ; to $1b00 to include bitmaps and attributes.
LD HL,$4000 ; set start to display file start.
LD (IX+$0D),L ; place start in
LD (IX+$0E),H ; the descriptor.
JR L0710 ; forward to SA-TYPE-3
; ---
; the branch was here to consider CODE.
;; SA-CODE
L06C3: CP $AF ; is character the token 'CODE' ?
JR NZ,L0716 ; forward if not to SA-LINE to consider an
; auto-started BASIC program.
LD A,($5C74) ; fetch command from T_ADDR
CP $03 ; 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,($5C74) ; 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 $2C ; 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,($5C74) ; 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+$0B),C ; place length
LD (IX+$0C),B ; in descriptor.
CALL L1E99 ; routine FIND-INT2 gets start.
LD (IX+$0D),C ; place start
LD (IX+$0E),B ; in descriptor.
LD H,B ; transfer the
LD L,C ; start to HL also.
;; SA-TYPE-3
L0710: LD (IX+$00),$03 ; 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 $CA ; 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+$0E),$80 ; 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,($5C74) ; 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+$0D),C ; place the auto-start
LD (IX+$0E),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+$00),$00 ; place type zero - program in descriptor.
LD HL,($5C59) ; fetch E_LINE to HL.
LD DE,($5C53) ; 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+$0B),L ; place total length
LD (IX+$0C),H ; in descriptor.
LD HL,($5C4B) ; load HL from system variable VARS
SBC HL,DE ; subtract to give program length.
LD (IX+$0F),L ; place length of program
LD (IX+$10),H ; in the descriptor.
EX DE,HL ; start to HL, length to DE.
;; SA-ALL
L075A: LD A,($5C74) ; 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,$0011 ; prepare to add seventeen
ADD IX,BC ; to point IX at second descriptor.
;; LD-LOOK-H
L0767: PUSH IX ; save IX
LD DE,$0011 ; 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,$FE ; select system channel 'S'
CALL L1601 ; routine CHAN-OPEN opens it.
LD (IY+$52),$03 ; set SCR_CT to 3 lines.
LD C,$80 ; C has bit 7 set to indicate type mismatch as
; a default startpoint.
LD A,(IX+$00) ; fetch loaded header type to A
CP (IX-$11) ; compare with expected type.
JR NZ,L078A ; forward to LD-TYPE with mis-match.
LD C,$F6 ; set C to minus ten - will count characters
; up to zero.
;; LD-TYPE
L078A: CP $04 ; 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,$FFF0 ; prepare minus seventeen.
ADD HL,DE ; add to point HL to 1st descriptor.
LD B,$0A ; 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 $F6 or $80 to A
ADD A,B ; add $0A
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,$0D ; 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+$00) ; fetch incoming type
CP $03 ; compare with CODE
JR Z,L07CB ; forward to VR-CONTRL if it is CODE.
; type is a program or an array.
LD A,($5C74) ; 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 $02 ; 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-$06) ; fetch length of old data
LD H,(IX-$05) ; to HL.
LD E,(IX+$0B) ; fetch length of new data
LD D,(IX+$0C) ; 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+$00) ; else fetch type from tape.
CP $03 ; 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+$0D) ; else use the destination in the header
LD H,(IX+$0E) ; 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,($5C74) ; fetch reduced command from T_ADDR
CP $02 ; 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,$FF ; 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 $FF 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 $1A ; 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+$0B) ; fetch length of found data block
LD D,(IX+$0C) ; 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-$06) ; fetch length from
LD H,(IX-$05) ; 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,$0005 ; 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+$00) ; 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 ($5C5F),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,($5C5F) ; reload IX from X_PTR which will have been
; adjusted down by POINTERS routine.
;; LD-DATA-1
L084C: LD HL,($5C59) ; address E_LINE
DEC HL ; now point to the $80 variables end-marker.
LD C,(IX+$0B) ; fetch new data length
LD B,(IX+$0C) ; 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-$03) ; 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,$FF ; 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,($5C59) ; address E_LINE
DEC HL ; now variables end-marker.
LD ($5C5F),IX ; place the IX header pointer in X_PTR
LD C,(IX+$0B) ; get new length
LD B,(IX+$0C) ; 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,($5C5F) ; reload IX from adjusted X_PTR
INC HL ; point to start of new area.
LD C,(IX+$0F) ; fetch length of BASIC on tape
LD B,(IX+$10) ; from 2nd descriptor
ADD HL,BC ; add to address the start of variables.
LD ($5C4B),HL ; set system variable VARS
LD H,(IX+$0E) ; fetch high byte of autostart line number.
LD A,H ; transfer to A
AND $C0 ; test if greater than $3F.
JR NZ,L08AD ; forward to LD-PROG-1 if so with no autostart.
LD L,(IX+$0D) ; else fetch the low byte.
LD ($5C42),HL ; set system variable to line number NEWPPC
LD (IY+$0A),$00 ; set statement NSPPC to zero.
;; LD-PROG-1
L08AD: POP DE ; ** pop the length
POP IX ; * and start.
SCF ; set carry flag
LD A,$FF ; 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+$0B) ; fetch length
LD B,(IX+$0C) ; 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),$80 ; 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,$FF ; 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,($5C53) ; 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 $C0 ; compare with $3F.
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 $80 ; is it the end-marker ?
RET Z ; return if so as complete. >>>>>
PUSH HL ; save workspace area pointer.
LD HL,($5C4B) ; load HL with VARS - start of variables area.
;; ME-OLD-VP
L08F9: LD A,(HL) ; fetch first byte.
CP $80 ; 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 $E0 ; keep bits 11100000
CP $A0 ; 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,$FF ; indicate a replacement.
; this entry point is when A holds $80 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 ($5C5F),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,($5C5F) ; 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 ($5C5F),HL ; store pointer in X_PTR
LD HL,($5C53) ; 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 ($5C53),DE ; set PROG to original value.
LD DE,($5C5F) ; 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,$FD ; 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+$02) ; TV_FLAG - Signal lower screen requires
; clearing
CALL L15D4 ; routine WAIT-KEY
PUSH IX ; save pointer to descriptor.
LD DE,$0011 ; there are seventeen bytes.
XOR A ; signal a header.
CALL L04C2 ; routine SA-BYTES
POP IX ; restore descriptor pointer.
LD B,$32 ; 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+$0B) ; fetch length of bytes from the
LD D,(IX+$0C) ; descriptor.
LD A,$FF ; 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-$11 IX+$00 0 1 2 3 Type.
; IX-$10 IX+$01 x x x x F ($FF if filename is null).
; IX-$0F IX+$02 x x x x i
; IX-$0E IX+$03 x x x x l
; IX-$0D IX+$04 x x x x e
; IX-$0C IX+$05 x x x x n
; IX-$0B IX+$06 x x x x a
; IX-$0A IX+$07 x x x x m
; IX-$09 IX+$08 x x x x e
; IX-$08 IX+$09 x x x x .
; IX-$07 IX+$0A x x x x (terminal spaces).
; IX-$06 IX+$0B lo lo lo lo Total
; IX-$05 IX+$0C hi hi hi hi Length of datablock.
; IX-$04 IX+$0D Auto - - Start Various
; IX-$03 IX+$0E Start a-z a-z addr ($80 if no autostart).
; IX-$02 IX+$0F lo - - - Length of Program
; IX-$01 IX+$10 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 $80
DEFM "Start tape, then press any key"
L09C0: DEFB '.'+$80
DEFB $0D
DEFM "Program:"
DEFB ' '+$80
DEFB $0D
DEFM "Number array:"
DEFB ' '+$80
DEFB $0D
DEFM "Character array:"
DEFB ' '+$80
DEFB $0D
DEFM "Bytes:"
DEFB ' '+$80
;**************************************************
;** 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 $20 ; is character a space or higher ?
JP NC,L0AD9 ; jump forward to PO-ABLE if so.
CP $06 ; is character in range 00-05 ?
JR C,L0A69 ; to PO-QUEST to print '?' if so.
CP $18 ; 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,$00 ; 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 L0A5F - $ ; 06d offset $4E to Address: PO-COMMA
DEFB L0A69 - $ ; 07d offset $57 to Address: PO-QUEST
DEFB L0A23 - $ ; 08d offset $10 to Address: PO-BACK-1
DEFB L0A3D - $ ; 09d offset $29 to Address: PO-RIGHT
DEFB L0A69 - $ ; 10d offset $54 to Address: PO-QUEST
DEFB L0A69 - $ ; 11d offset $53 to Address: PO-QUEST
DEFB L0A69 - $ ; 12d offset $52 to Address: PO-QUEST
DEFB L0A4F - $ ; 13d offset $37 to Address: PO-ENTER
DEFB L0A69 - $ ; 14d offset $50 to Address: PO-QUEST
DEFB L0A69 - $ ; 15d offset $4F to Address: PO-QUEST
DEFB L0A7A - $ ; 16d offset $5F to Address: PO-1-OPER
DEFB L0A7A - $ ; 17d offset $5E to Address: PO-1-OPER
DEFB L0A7A - $ ; 18d offset $5D to Address: PO-1-OPER
DEFB L0A7A - $ ; 19d offset $5C to Address: PO-1-OPER
DEFB L0A7A - $ ; 20d offset $5B to Address: PO-1-OPER
DEFB L0A7A - $ ; 21d offset $5A to Address: PO-1-OPER
DEFB L0A75 - $ ; 22d offset $54 to Address: PO-2-OPER
DEFB L0A75 - $ ; 23d offset $53 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,$22 ; value $21 is leftmost column.
CP C ; have we passed ?
JR NZ,L0A3A ; to PO-BACK-3 if not and store new position.
BIT 1,(IY+$01) ; 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,$02 ; the rightmost column position.
LD A,$18 ; Note. This should be $19
; 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 $18.
;; PO-BACK-2
L0A38: LD C,$21 ; 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,($5C91) ; fetch P_FLAG value
PUSH AF ; and save it on stack.
LD (IY+$57),$01 ; temporarily set P_FLAG 'OVER 1'.
LD A,$20 ; 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 ($5C91),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+$01) ; test FLAGS - is printer in use ?
JP NZ,L0ECD ; to COPY-BUFF if so, to flush buffer and reset
; the print position.
LD C,$21 ; 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. $21-$01
DEC A ; move right. $20-$00
DEC A ; and again $1F-$00 or $FF if trailing
AND $10 ; will be $00 or $10.
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,$3F ; 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 $10 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 ($5C0F),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 ($5C0E),A ; store control code in TVDATA-lo
;; PO-CHANGE
L0A80: LD HL,($5C51) ; 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,($5C0E) ; TVDATA gives control code and possible
; subsequent character
LD D,A ; save current character
LD A,L ; the stored control code
CP $16 ; 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,$1F ; the value 31d
SUB C ; reverse the column number.
JR C,L0AAC ; to PO-AT-ERR if C was greater than 31d.
ADD A,$02 ; transform to system range $02-$21
LD C,A ; and place in column register.
BIT 1,(IY+$01) ; test FLAGS - is printer in use ?
JR NZ,L0ABF ; to PO-AT-SET as line can be ignored.
LD A,$16 ; 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 $01-$17
LD B,A ; place in line register
INC B ; adjust to system range $02-$18
BIT 0,(IY+$02) ; TV_FLAG - Lower screen in use ?
JP NZ,L0C55 ; exit to PO-SCR to test for scrolling
CP (IY+$31) ; 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), $21 (left)
ADD A,C ; add operand to current column
DEC A ; range 0 - 31+
AND $1F ; make range 0 - 31d
RET Z ; return if result zero
LD D,A ; Counter to D
SET 0,(IY+$01) ; update FLAGS - signal suppress leading space.
;; PO-SPACE
L0AD0: LD A,$20 ; 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+$01) ; Test FLAGS - is printer in use ?
JR NZ,L0AFC ; Forward, if so, to PO-ST-PR
BIT 0,(IY+$02) ; 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 ($5C88),BC ; Update S_POSN - line/column upper screen
LD ($5C84),HL ; Update DF_CC - upper display file address
RET ; Return.
; ---
; This section deals with the lower screen.
;; PO-ST-E
L0AF0: LD ($5C8A),BC ; Update SPOSNL line/column lower screen
LD ($5C82),BC ; Update ECHO_E line/column input buffer
LD ($5C86),HL ; Update DFCCL lower screen memory address
RET ; Return.
; ---
; This section deals with the ZX Printer.
;; PO-ST-PR
L0AFC: LD (IY+$45),C ; Update P_POSN column position printer
LD ($5C80),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+$01) ; 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,($5C88) ; Fetch line/column from S_POSN
LD HL,($5C84) ; Fetch DF_CC display file address
BIT 0,(IY+$02) ; Test TV_FLAG - lower screen in use ?
RET Z ; Return if upper screen in use.
; Overwrite registers with values for lower screen.
LD BC,($5C8A) ; Fetch line/column from SPOSNL
LD HL,($5C86) ; Fetch display file address from DFCCL
RET ; Return.
; ---
; This section deals with the ZX Printer.
;; PO-F-PR
L0B1D: LD C,(IY+$45) ; Fetch column from P_POSN.
LD HL,($5C80) ; 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 $80 ; ASCII ?
JR C,L0B65 ; to PO-CHAR is so.
CP $90 ; 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,$5C92 ; 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,$5C92 ; 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 $00 or $FF
AND $0F ; 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 $00 or $FF
AND $F0 ; mask off left hand side
OR C ; combine with stored pattern
LD C,$04 ; 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 $A5 ; the 'RND' character
JR NC,L0B5F ; to PO-T to print tokens
ADD A,$15 ; add 21d to restore to 0 - 20
PUSH BC ; save current print position
LD BC,($5C7B) ; 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,($5C36) ; 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,$5C3B ; point to FLAGS
RES 0,(HL) ; allow for leading space
CP $20 ; 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,$00 ; 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,$21 ; 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 $21
BIT 1,(IY+$01) ; 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 ($21) 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,($5C91) ; fetch P_FLAG to accumulator
LD B,$FF ; 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,$08 ; prepare to count 8 bytes
AND A ; clear carry to signal screen
BIT 1,(IY+$01) ; test FLAGS - is printer in use ?
JR Z,L0BB6 ; to PR-ALL-3 if screen
SET 1,(IY+$30) ; 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+$01) ; 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,$20 ; 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 $40 - $57
RRCA ; shift
RRCA ; bits 3 and 4
RRCA ; to right.
AND $03 ; range is now 0 - 2
OR $58 ; form correct high byte for third of screen
LD H,A ; HL is now correct
LD DE,($5C8F) ; 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+$57) ; test P_FLAG - is this PAPER 9 ??
JR Z,L0BFA ; skip to PO-ATTR-1 if not.
AND $C7 ; set paper
BIT 2,A ; to contrast with ink
JR NZ,L0BFA ; skip to PO-ATTR-1
XOR $38 ;
;; PO-ATTR-1
L0BFA: BIT 4,(IY+$57) ; test P_FLAG - Is this INK 9 ??
JR Z,L0C08 ; skip to PO-ATTR-2 if not
AND $F8 ; make ink
BIT 5,A ; contrast with paper.
JR NZ,L0C08 ; to PO-ATTR-2
XOR $07 ;
;; 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,$00 ; 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,$20 ; prepare leading space
BIT 0,(IY+$01) ; 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 $7F ; 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 $48 ; was the last character '$' ?
JR Z,L0C35 ; forward to PO-TR-SP to consider trailing
; space if so.
CP $82 ; 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 $03 ; Test against RND, INKEY$ and PI which have no
; parameters and therefore no trailing space.
RET C ; Return if no trailing space.
LD A,$20 ; 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 $10 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 $20 ; return with carry set
RET C ; for all messages and function tokens
LD A,(DE) ; test first character of token
SUB $41 ; 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+$01) ; 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+$02) ; test TV_FLAG - lower screen in use ?
JP NZ,L0D02 ; jump forward to PO-SCR-4 if so.
CP (IY+$31) ; 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+$02) ; test TV_FLAG - Automatic listing ?
JR Z,L0C88 ; forward to PO-SCR-2 if not.
LD E,(IY+$2D) ; 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,$00 ; explicit - select channel zero.
CALL L1601 ; routine CHAN-OPEN opens it.
LD SP,($5C3F) ; set stack pointer to LIST_SP
RES 4,(IY+$02) ; 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 $04 ; Error Report: Out of screen
; continue here if not an automatic listing.
;; PO-SCR-2
L0C88: DEC (IY+$52) ; decrease SCR_CT
JR NZ,L0CD2 ; forward to PO-SCR-3 to scroll display if
; result not zero.
; now produce prompt.
LD A,$18 ; reset
SUB B ; the
LD ($5C8C),A ; SCR_CT scroll count
LD HL,($5C8F) ; L=ATTR_T, H=MASK_T
PUSH HL ; save on stack
LD A,($5C91) ; P_FLAG
PUSH AF ; save on stack to prevent lower screen
; attributes (BORDCR etc.) being applied.
LD A,$FD ; 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+$02) ; set TV_FLAG - signal lower screen requires
; clearing
LD HL,$5C3B ; 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 $20 ; space is considered as BREAK
JR Z,L0D00 ; forward to REPORT-D if so
; 'BREAK - CONT repeats'
CP $E2 ; is character 'STOP' ?
JR Z,L0D00 ; forward to REPORT-D if so
OR $20 ; convert to lower-case
CP $6E ; is character 'n' ?
JR Z,L0D00 ; forward to REPORT-D if so else scroll.
LD A,$FE ; select system channel 'S'
CALL L1601 ; routine CHAN-OPEN
POP AF ; restore original P_FLAG
LD ($5C91),A ; and save in P_FLAG.
POP HL ; restore original ATTR_T, MASK_T
LD ($5C8F),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+$31) ; fetch DF_SZ to B
INC B ; increase to address last line of display
LD C,$21 ; set C to $21 (was $21 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 $03 ;
OR $58 ;
LD H,A ;
LD DE,$5AE0 ; 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,$20 ; 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 $80 ; initial step-over byte.
DEFM "scroll"
DEFB '?'+$80
;; REPORT-D
L0D00: RST 08H ; ERROR-1
DEFB $0C ; Error Report: BREAK - CONT repeats
; continue here if using lower display - A holds line number.
;; PO-SCR-4
L0D02: CP $02 ; is line number less than 2 ?
JR C,L0C86 ; to REPORT-5 if so
; 'Out of Screen'.
ADD A,(IY+$31) ; add DF_SZ
SUB $19 ;
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,($5C8F) ; fetch current ATTR_T, MASK_T to HL.
PUSH HL ; and save
LD HL,($5C91) ; 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,$5C6B ; 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,$5C89 ; 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,$18 ; set count to whole display ??
; Note. should be $17 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+$57),L ; and overwrite system variable P_FLAG.
POP HL ; restore original ATTR_T/MASK_T.
LD ($5C8F),HL ; and update system variables.
LD BC,($5C88) ; fetch S_POSN to BC.
RES 0,(IY+$02) ; signal to TV_FLAG - main screen in use.
CALL L0DD9 ; call routine CL-SET for upper display.
SET 0,(IY+$02) ; 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,($5C8D) ; fetch L=ATTR_P and H=MASK_P
BIT 0,(IY+$02) ; 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+$0E) ; fetch BORDCR to L which is used for lower
; screen.
;; TEMPS-1
L0D5B: LD ($5C8F),HL ; transfer values to ATTR_T and MASK_T
; for the print flag the permanent values are odd bits, temporary even bits.
LD HL,$5C91 ; 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 $55 ; 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,$5C3C ; 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+$31) ; 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,$5AC0 ; set initial attribute address to the leftmost
; cell of second line up.
LD A,($5C8D) ; 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,$20 ; 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+$31),$02 ; 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,$FD ; select system channel 'K'
CALL L1601 ; routine CHAN-OPEN opens it.
LD HL,($5C51) ; 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,$1721 ; 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,$0000 ; Initialize plot coordinates.
LD ($5C7D),HL ; Set system variable COORDS to 0,0.
RES 0,(IY+$30) ; update FLAGS2 - signal main screen is clear.
CALL L0D94 ; routine CL-CHAN makes channel 'K' 'normal'.
LD A,$FE ; 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,$18 ; 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 $21.
LD HL,($5C51) ; 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+$52),$01 ; set SCR_CT - scroll count - to default.
; Note. BC already contains $1821.
LD BC,$1821 ; 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,$5B00 ; the base address of printer buffer
BIT 1,(IY+$01) ; 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+$02) ; test TV_FLAG - lower screen in use ?
JR Z,L0DEE ; skip to CL-SET-1 if handling upper part
ADD A,(IY+$31) ; add DF_SZ for lower screen
SUB $18 ; 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,$21 ; the column $01-$21 is reversed
SUB C ; to range $00 - $20
LD E,A ; now transfer to DE
LD D,$00 ; 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,$17 ; scroll 23 lines, after 'scroll?'.
;; CL-SCROLL
L0E00: CALL L0E9B ; routine CL-ADDR gets screen address in HL.
LD C,$08 ; 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 $07 ; 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 = $4800 or $5000 ) ( but also sometimes $4000 )
;; CL-SCR-2
L0E0D: EX DE,HL ; copy HL to DE.
LD HL,$F8E0 ; subtract $08 from H and add $E0 to L -
ADD HL,DE ; to make destination bottom line of previous
; third.
EX DE,HL ; restore the source and destination.
LD BC,$0020 ; 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,$FFE0 ; 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 $07 ; 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 ($E0 at most)
LD A,B ; store line count to A
LD B,$00 ; make B zero
LDIR ; copy bytes (BC=0, H incremented, L=0)
LD B,$07 ; set B to 7, C is zero.
ADD HL,BC ; add 7 to H to address next third.
AND $F8 ; 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,$FFE0 ; 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,$01 ; 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,$08 ; 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 $07 ; 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,$00 ; 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),$00 ; blank the first byte.
INC DE ; make DE point to next byte.
LDIR ; ldir will clear lines.
LD DE,$0701 ; now address next third adjusting
ADD HL,DE ; register E to address left hand side
DEC A ; decrease the line count.
AND $F8 ; will be 16, 8 or 0 (AND $18 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,($5C8D) ; fetch ATTR_P - permanent attributes
BIT 0,(IY+$02) ; test TV_FLAG - lower screen in use ?
JR Z,L0E80 ; skip to CL-LINE-3 if not.
LD A,($5C48) ; 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 $01-$24.
LD C,$21 ; make column $21. (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 - $48, $50, or $58.
RRCA ; divide by
RRCA ; eight.
RRCA ; $09, $0A or $0B.
DEC A ; $08, $09 or $0A.
OR $50 ; $58, $59 or $5A.
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,$18 ; reverse the line number
SUB B ; to range $00 - $17.
LD D,A ; save line in D for later.
RRCA ; multiply
RRCA ; by
RRCA ; thirty-two.
AND $E0 ; mask off low bits to make
LD L,A ; L a multiple of 32.
LD A,D ; bring back the line to A.
AND $18 ; now $00, $08 or $10.
OR $40 ; 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,$B0 ; top 176 lines.
L0EAF: LD HL,$4000 ; 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 $07 ; 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,$20 ; 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 $F8 ; 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,$5B00 ; the base address of the Printer Buffer.
LD B,$08 ; 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,$04 ; output value 4 to port
OUT ($FB),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,$5B00 ; the location of the buffer.
LD (IY+$46),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+$30) ; set FLAGS2 - signal printer buffer is clear.
LD C,$21 ; 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 $FB -
; 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 $03 ; is it 01 or 02 ?.
SBC A,A ; result is $FF if so else $00.
AND $02 ; result is 02 now else 00.
; bit 1 set slows the printer.
OUT ($FB),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,$04 ; else stop the
OUT ($FB),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 $0C ; Error Report: BREAK - CONT repeats
;; COPY-L-2
L0F0C: IN A,($FB) ; 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,$20 ; 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,$08 ; 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,($FB) ; 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 ($FB),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,($5C3D) ; 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 ($5C3D),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,$00 ; and give a short click based
LD E,(IY-$01) ; on PIP value for duration.
LD HL,$00C8 ; 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 $18 ; range 24 to 255 ?
JR NC,L0F81 ; forward to ADD-CHAR if so.
CP $07 ; 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 $10 ; less than 16 ?
JR C,L0F92 ; forward to ED-KEYS if editing control
; range 7 to 15 dealt with by a table
LD BC,$0002 ; prepare for ink/paper etc.
LD D,A ; save character in D
CP $16 ; 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+$37) ; 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,($5C5B) ; fetch address of keyboard cursor from K_CUR
RES 0,(IY+$07) ; 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+$07) ; set MODE to 'L'
X0F85: LD HL,($5C5B) ; 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 ($5C5B),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,$00 ; prepare to add.
LD HL,L0FA0 - 7 ; base address of editing keys table. $0F99
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,($5C5B) ; load address of cursor from K_CUR.
RET ; Make an indirect jump forward to routine.
; ------------------
; Editing keys table
; ------------------
; For each code in the range $07 to $0F 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 L0FA9 - $ ; 07d offset $09 to Address: ED-EDIT
DEFB L1007 - $ ; 08d offset $66 to Address: ED-LEFT
DEFB L100C - $ ; 09d offset $6A to Address: ED-RIGHT
DEFB L0FF3 - $ ; 10d offset $50 to Address: ED-DOWN
DEFB L1059 - $ ; 11d offset $B5 to Address: ED-UP
DEFB L1015 - $ ; 12d offset $70 to Address: ED-DELETE
DEFB L1024 - $ ; 13d offset $7E to Address: ED-ENTER
DEFB L1076 - $ ; 14d offset $CF to Address: ED-SYMBOL
DEFB L107C - $ ; 15d offset $D4 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,($5C49) ; fetch E_PPC the last line number entered.
; Note. may not exist and may follow program.
BIT 5,(IY+$37) ; 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,$000A ; 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,($5C51) ; address CURCHL
EX (SP),HL ; swap with line address on stack
PUSH HL ; save line address underneath
LD A,$FF ; 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+$0F) ; 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+$0F) ; restore E_PPC_lo to the previous value.
LD HL,($5C59) ; address E_LINE in editing area.
INC HL ; advance
INC HL ; past space
INC HL ; and digit characters
INC HL ; of line number.
LD ($5C5B),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+$37) ; test FLAGX - Input Mode ?
JR NZ,L1001 ; skip to ED-STOP if so
LD HL,$5C49 ; 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+$00),$10 ; 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 $0D ; is it carriage return ?
RET Z ; return if so to ED-LOOP
INC HL ; address next character
;; ED-CUR
L1011: LD ($5C5B),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,$0001 ; 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 ($5C3D),HL ; is restored to ERR_SP system variable
BIT 7,(IY+$00) ; is ERR_NR $FF (= '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 $F0 ; lose the low bits
CP $10 ; is it INK to TAB $10-$1F ?
; 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 $17 ; decimal 23 ('tab')
ADC A,$00 ; 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+$37) ; test FLAGX - input mode ?
RET NZ ; return if not in editor - to ED-LOOP.
LD HL,($5C49) ; 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,$5C4A ; 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,$00 ; 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 '.
; chr$14 would have the same functionality.
; This is chr$ 14.
;; ED-SYMBOL
L1076: BIT 7,(IY+$37) ; 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+$30) ; 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+$00),$FF ; reset ERR_NR to 'OK'.
LD D,$00 ; prepare for beeper.
LD E,(IY-$02) ; use RASP value.
LD HL,$1A90 ; 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 ($5C5B),HL ; set K_CUR to start of empty area
LD (IY+$07),$00 ; 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+$02) ; 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+$01) ; test FLAGS - has a new key been pressed ?
RET Z ; return if not. >>
LD A,($5C08) ; system variable LASTK will hold last key -
; from the interrupt routine.
RES 5,(IY+$01) ; update FLAGS - reset the new key flag.
PUSH AF ; save the input character.
BIT 5,(IY+$02) ; test TV_FLAG - clear lower screen ?
CALL NZ,L0D6E ; routine CLS-LOWER if so.
POP AF ; restore the character code.
CP $20 ; if space or higher then
JR NC,L111B ; forward to KEY-DONE2 and return with carry
; set to signal key-found.
CP $10 ; with 16d INK and higher skip
JR NC,L10FA ; forward to KEY-CONTR.
CP $06 ; 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 $01 ; 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,$12 ; 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,$5C6A ; point to FLAGS2
LD A,$08 ; 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 $0E ; 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 $0D ; subtract 13d leaving 1 and 2
; 1 is 'E' mode, 2 is 'G' mode.
LD HL,$5C41 ; 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),$00 ; 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+$02) ; 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 $07 ; mask to leave bits 0-7
LD C,A ; and store in C.
LD A,$10 ; 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-$2D),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,($5C0D) ; 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,($5C4F) ; 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+$02) ; update TV_FLAG - signal no change in mode
RES 5,(IY+$02) ; update TV_FLAG - signal don't clear lower
; screen.
LD HL,($5C8A) ; fetch SPOSNL
PUSH HL ; and save on stack.
LD HL,($5C3D) ; fetch ERR_SP
PUSH HL ; and save also
LD HL,L1167 ; address: ED-FULL
PUSH HL ; is pushed as the error routine
LD ($5C3D),SP ; and ERR_SP made to point to it.
LD HL,($5C82) ; 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,($5C8A) ; 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,($5C8B) ; 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+$50) ; subtract new in SPOSNL_lo
JR NC,L117C ; forward to ED-C-DONE if no backfilling.
;; ED-SPACES
L115E: LD A,$20 ; 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 $09F4 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,$00 ; prepare to moan.
LD E,(IY-$02) ; fetch RASP value.
LD HL,$1A90 ; set pitch or tone period.
CALL L03B5 ; routine BEEPER.
LD (IY+$00),$FF ; clear ERR_NR.
LD DE,($5C8A) ; 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 ($5C3D),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 ($5C82),HL ; and overwrite ECHO_E
LD (IY+$26),$00 ; 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,($5C61) ; 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,($5C59) ; fetch E_LINE to DE
BIT 5,(IY+$37) ; test FLAGX - Input Mode ?
RET Z ; return now if in editing mode
LD DE,($5C61) ; fetch WORKSP to DE
RET C ; return if carry set ( entry = set-de)
LD HL,($5C63) ; 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 $0E ; is it the CHR$ 14 number marker ?
LD BC,$0006 ; 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 $0D ; 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 |
; +---------+-----------+------------+--------------+-------------+--
; ^ ^ ^ ^ ^ ^
; $0000 $4000 $5800 $5B00 $5C00 $5CB6 = CHANS
;
;
; --+----------+---+---------+-----------+---+------------+--+---+--
; | Channel |$80| BASIC | Variables |$80| Edit Line |NL|$80|
; | Info | | Program | Area | | or Command | | |
; --+----------+---+---------+-----------+---+------------+--+---+--
; ^ ^ ^ ^ ^
; CHANS PROG VARS E_LINE WORKSP
;
;
; ---5--> <---2--- <--3---
; --+-------+--+------------+-------+-------+---------+-------+-+---+------+
; | INPUT |NL| Temporary | Calc. | Spare | Machine | GOSUB |?|$3E| 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,$FF ; Flag coming from NEW.
LD DE,($5CB2) ; Fetch RAMTOP as top value.
EXX ; Switch in alternate set.
LD BC,($5CB4) ; Fetch P-RAMT differs on 16K/48K machines.
LD DE,($5C38) ; Fetch RASP/PIP.
LD HL,($5C7B) ; 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,$07 ; Select a white border
OUT ($FE),A ; and set it now by writing to a port.
LD A,$3F ; 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 $40 - $7F as 'snow'
; appears on the screen.
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 $FFFF, or in the case
; of NEW the supplied top value. The entire screen turns black with
; sometimes red stripes on black paper just visible.
;; ram-check
L11DA: LD H,D ; Transfer the top value to the HL register
LD L,E ; pair.
;; RAM-FILL
L11DC: LD (HL),$02 ; Load memory with $02 - red ink on black paper.
DEC HL ; Decrement memory address.
CP H ; Have we reached ROM - $3F ?
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 ($5CB4),BC ; insert P-RAMT.
LD ($5C38),DE ; insert RASP/PIP.
LD ($5C7B),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 ($5CB4),HL ; set P-RAMT to the highest working RAM
; address.
LD DE,$3EAF ; address of last byte of 'U' bitmap in ROM.
LD BC,$00A8 ; 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 ($5C7B),HL ; make UDG system variable address the first
; bitmap.
DEC HL ; point at RAMTOP again.
LD BC,$0040 ; set the values of
LD ($5C38),BC ; the PIP and RASP system variables.
; The NEW command path rejoins here.
;; RAM-SET
L1219: LD ($5CB2),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,$3C00 ; a strange place to set the pointer to the
LD ($5C36),HL ; character set, CHARS - as no printing yet.
LD HL,($5CB2) ; fetch RAMTOP to HL again as we've lost it.
LD (HL),$3E ; top of user ram holds GOSUB end marker
; an impossible line number - see RETURN.
; no significance in the number $3E. 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 ($5C3D),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,$5C3A ; 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,$5CB6 ; The address of the channels - initially
; following system variables.
LD ($5C4F),HL ; Set the CHANS system variable.
LD DE,L15AF ; Address: init-chan in ROM.
LD BC,$0015 ; 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 ($5C57),HL ; Set DATADD to location before program area.
INC HL ; Increment again.
LD ($5C53),HL ; Set PROG the location where BASIC starts.
LD ($5C4B),HL ; Set VARS to same location with a
LD (HL),$80 ; variables end-marker.
INC HL ; Advance address.
LD ($5C59),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),$0D ; initially just has a carriage return
INC HL ; followed by
LD (HL),$80 ; an end-marker.
INC HL ; address the next location.
LD ($5C61),HL ; set WORKSP - empty workspace.
LD ($5C63),HL ; set STKBOT - bottom of the empty stack.
LD ($5C65),HL ; set STKEND to the end of the empty stack.
; --
LD A,$38 ; the colour system is set to white paper,
; black ink, no flash or bright.
LD ($5C8D),A ; set ATTR_P permanent colour attributes.
LD ($5C8F),A ; set ATTR_T temporary colour attributes.
LD ($5C48),A ; set BORDCR the border colour/lower screen
; attributes.
LD HL,$0523 ; The keyboard repeat and delay values are
LD ($5C09),HL ; loaded to REPDEL and REPPER.
DEC (IY-$3A) ; set KSTATE-0 to $FF - keyboard map available.
DEC (IY-$36) ; set KSTATE-4 to $FF - keyboard map available.
LD HL,L15C6 ; set source to ROM Address: init-strm
LD DE,$5C10 ; set destination to system variable STRMS-FD
LD BC,$000E ; copy the 14 bytes of initial 7 streams data
LDIR ; from ROM to RAM.
SET 1,(IY+$01) ; 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+$31),$02 ; 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+$02) ; update TV_FLAG - signal lower screen will
; require clearing.
JR L12A9 ; forward to MAIN-1
; -------------------------
; THE 'MAIN EXECUTION LOOP'
; -------------------------
;
;
;; MAIN-EXEC
L12A2: LD (IY+$31),$02 ; 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,$00 ; 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+$00) ; test ERR_NR - will be $FF if syntax is OK.
JR NZ,L12CF ; forward, if correct, to MAIN-3.
;
BIT 4,(IY+$30) ; test FLAGS2 - K channel in use ?
JR Z,L1303 ; forward to MAIN-4 if not.
;
LD HL,($5C59) ; an editing error so address E_LINE.
CALL L11A7 ; routine REMOVE-FP removes the hidden
; floating-point forms.
LD (IY+$00),$FF ; 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,($5C59) ; fetch the edit line address from E_LINE.
LD ($5C5D),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 $0D ; 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+$30) ; 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,$19 ; compute scroll count as 25 minus
SUB (IY+$4F) ; value of S_POSN_hi.
LD ($5C8C),A ; update SCR_CT system variable.
SET 7,(IY+$01) ; update FLAGS - signal running program.
LD (IY+$00),$FF ; set ERR_NR to 'OK'.
LD (IY+$0A),$01 ; 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+$01) ; update bit 5 of FLAGS - signal no new key.
BIT 1,(IY+$30) ; 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,($5C3A) ; 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,$0000 ; prepare to clear some system variables.
LD (IY+$37),H ; clear all the bits of FLAGX.
LD (IY+$26),H ; blank X_PTR_hi to suppress error marker.
LD ($5C0B),HL ; blank DEFADD to signal that no defined
; function is currently being evaluated.
LD HL,$0001 ; explicit - inc hl would do.
LD ($5C16),HL ; ensure STRMS-00 is keyboard.
CALL L16B0 ; routine SET-MIN clears workspace etc.
RES 5,(IY+$37) ; update FLAGX - signal in EDIT not INPUT mode.
; Note. all the bits were reset earlier.
CALL L0D6E ; call routine CLS-LOWER.
SET 5,(IY+$02) ; 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 $0A ; is it a print-ready digit ?
JR C,L133C ; forward to MAIN-5 if so.
ADD A,$07 ; add ASCII offset to letters.
;; MAIN-5
L133C: CALL L15EF ; call routine OUT-CODE to print the code.
LD A,$20 ; 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 $10.
LD BC,($5C45) ; fetch PPC the current line number.
CALL L1A1B ; routine OUT-NUM-1 will print that
LD A,$3A ; then a ':' character.
RST 10H ; PRINT-A
LD C,(IY+$0D) ; then SUBPPC for statement
LD B,$00 ; 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,($5C3A) ; fetch ERR_NR again
INC A ; test for no error originally $FF.
JR Z,L1386 ; forward to MAIN-9 if no error.
CP $09 ; is code Report 9 STOP ?
JR Z,L1373 ; forward to MAIN-6 if so
CP $15 ; 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+$0D) ; increment SUBPPC to next statement.
;; MAIN-7
L1376: LD BC,$0003 ; prepare to copy 3 system variables to
LD DE,$5C70 ; address OSPPC - statement for CONTINUE.
; also updating OLDPPC line number below.
LD HL,$5C44 ; 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+$0A),$FF ; update NSPPC - signal 'no jump'.
RES 3,(IY+$01) ; 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 $7F, 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 $80
DEFB 'O','K'+$80 ; 0
DEFM "NEXT without FO"
DEFB 'R'+$80 ; 1
DEFM "Variable not foun"
DEFB 'd'+$80 ; 2
DEFM "Subscript wron"
DEFB 'g'+$80 ; 3
DEFM "Out of memor"
DEFB 'y'+$80 ; 4
DEFM "Out of scree"
DEFB 'n'+$80 ; 5
DEFM "Number too bi"
DEFB 'g'+$80 ; 6
DEFM "RETURN without GOSU"
DEFB 'B'+$80 ; 7
DEFM "End of fil"
DEFB 'e'+$80 ; 8
DEFM "STOP statemen"
DEFB 't'+$80 ; 9
DEFM "Invalid argumen"
DEFB 't'+$80 ; A
DEFM "Integer out of rang"
DEFB 'e'+$80 ; B
DEFM "Nonsense in BASI"
DEFB 'C'+$80 ; C
DEFM "BREAK - CONT repeat"
DEFB 's'+$80 ; D
DEFM "Out of DAT"
DEFB 'A'+$80 ; E
DEFM "Invalid file nam"
DEFB 'e'+$80 ; F
DEFM "No room for lin"
DEFB 'e'+$80 ; G
DEFM "STOP in INPU"
DEFB 'T'+$80 ; H
DEFM "FOR without NEX"
DEFB 'T'+$80 ; I
DEFM "Invalid I/O devic"
DEFB 'e'+$80 ; J
DEFM "Invalid colou"
DEFB 'r'+$80 ; K
DEFM "BREAK into progra"
DEFB 'm'+$80 ; L
DEFM "RAMTOP no goo"
DEFB 'd'+$80 ; M
DEFM "Statement los"
DEFB 't'+$80 ; N
DEFM "Invalid strea"
DEFB 'm'+$80 ; O
DEFM "FN without DE"
DEFB 'F'+$80 ; P
DEFM "Parameter erro"
DEFB 'r'+$80 ; Q
DEFM "Tape loading erro"
DEFB 'r'+$80 ; R
;; comma-sp
L1537: DEFB ',',' '+$80 ; used in report line.
;; copyright
L1539: DEFB $7F ; copyright
DEFM " 1982 Sinclair Research Lt"
DEFB 'd'+$80
; -------------
; 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,$10 ; i.e. 'G' -$30 -$07
LD BC,$0000 ; 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 ($5C49),BC ; set E_PPC to extracted line number.
LD HL,($5C5D) ; 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,($5C61) ; 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,($5C53) ; 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 ($5C53),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,($5C61) ; 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,($5C49) ; 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 - $27 (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 $4B ; 'K'
DEFW L09F4 ; PRINT-OUT
DEFW L15C4 ; REPORT-J
DEFB $53 ; 'S'
DEFW L0F81 ; ADD-CHAR
DEFW L15C4 ; REPORT-J
DEFB $52 ; 'R'
DEFW L09F4 ; PRINT-OUT
DEFW L15C4 ; REPORT-J
DEFB $50 ; 'P'
DEFB $80 ; End Marker
;; REPORT-J
L15C4: RST 08H ; ERROR-1
DEFB $12 ; Error Report: Invalid I/O device
; -------------------------
; THE 'INITIAL STREAM' DATA
; -------------------------
; This is the initial stream data for the seven streams $FD - $03 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 $01, $00 ; stream $FD offset to channel 'K'
DEFB $06, $00 ; stream $FE offset to channel 'S'
DEFB $0B, $00 ; stream $FF offset to channel 'R'
DEFB $01, $00 ; stream $00 offset to channel 'K'
DEFB $01, $00 ; stream $01 offset to channel 'K'
DEFB $06, $00 ; stream $02 offset to channel 'S'
DEFB $10, $00 ; stream $03 offset to channel 'P'
; ------------------------------
; THE 'INPUT CONTROL' SUBROUTINE
; ------------------------------
;
;; WAIT-KEY
L15D4: BIT 5,(IY+$02) ; test TV_FLAG - clear lower screen ?
JR NZ,L15DE ; forward to WAIT-KEY1 if so.
SET 3,(IY+$02) ; 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 $07 ; 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,($5C51) ; 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,$30 ; 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 $09F4.
;; PRINT-A-2
L15F2: EXX ; switch in alternate set
PUSH HL ; save HL register
LD HL,($5C51) ; 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 $FD - $FF, or a user stream $00 - $0F
; in the accumulator.
;; CHAN-OPEN
L1601: ADD A,A ; double the stream ($FF will become $FE etc.)
ADD A,$16 ; add the offset to stream 0 from $5C00
LD L,A ; result to L
LD H,$5C ; 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 $17 ; 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,($5C4F) ; 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 ($5C51),HL ; set CURCHL system variable to the
; address in HL
RES 4,(IY+$30) ; 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,$00 ; 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', L1634-$-1 ; offset $06 to CHAN-K
DEFB 'S', L1642-$-1 ; offset $12 to CHAN-S
DEFB 'P', L164D-$-1 ; offset $1B to CHAN-P
DEFB $00 ; end marker.
; --------------
; Channel K flag
; --------------
; routine to set flags for lower screen/keyboard channel.
;; CHAN-K
L1634: SET 0,(IY+$02) ; update TV_FLAG - signal lower screen in use
RES 5,(IY+$01) ; update FLAGS - signal no new key
SET 4,(IY+$30) ; 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+$02) ; TV_FLAG - signal main screen in use
;; CHAN-S-1
L1646: RES 1,(IY+$01) ; 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+$01) ; 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,$0001 ; 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,($5C65) ; 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,$5C4B ; address VARS the first of the
LD A,$0E ; 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 $80, or
; if variables exist, then the first character of any variable name.
;; LINE-ZERO
L168F: DEFB $00, $00 ; 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 $2F
AND $C0 ; 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,($5C63) ; 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 ($5C61),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,($5C59) ; fetch E_LINE
LD (HL),$0D ; insert carriage return
LD ($5C5B),HL ; make K_CUR keyboard cursor point there.
INC HL ; next location
LD (HL),$80 ; holds end-marker $80
INC HL ; next location becomes
LD ($5C61),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,($5C61) ; fetch WORKSP value
LD ($5C63),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,($5C63) ; fetch STKBOT value
LD ($5C65),HL ; and place in STKEND.
PUSH HL ; perhaps an obsolete entry point.
LD HL,$5C92 ; normal location of MEM-0
LD ($5C68),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,($5C59) ; 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,$0000 ; the stream is to be blanked.
LD DE,$A3E2 ; the number of bytes from stream 4, $5C1E,
; to $10000
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. ($15D4)
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 $00 to $04, 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,($5C4F) ; 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 $10 (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 $10 there!
LD C,(HL) ; transfer the offset to C.
LD B,$00 ; 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', L171C-$-1 ; offset 5 to CLOSE-STR
DEFB 'S', L171C-$-1 ; offset 3 to CLOSE-STR
DEFB 'P', 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 $10 ; is it less than 16d ?
JR C,L1727 ; skip forward to STR-DATA1 if so.
;; REPORT-Ob
L1725: RST 08H ; ERROR-1
DEFB $17 ; Error Report: Invalid stream
;; STR-DATA1
L1727: ADD A,$03 ; 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,$5C10 ; address STRMS - the start of the streams
; data area in system variables.
LD C,A ; transfer the low byte to A.
LD B,$00 ; 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 $01 ;;exchange ;c,s.
DEFB $38 ;;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,($5C4F) ; 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 $4B ; is it 'K' ?
JR Z,L1756 ; forward to OPEN-1 if so
CP $53 ; is it 'S' ?
JR Z,L1756 ; forward to OPEN-1 if so
CP $50 ; 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 $0E ; 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 $DF ; 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,$00 ; 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', L1781-$-1 ; $06 offset to OPEN-K
DEFB 'S', L1785-$-1 ; $08 offset to OPEN-S
DEFB 'P', L1789-$-1 ; $0A offset to OPEN-P
DEFB $00 ; 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 $0001 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,$01 ; 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,$06 ; 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,$10 ; 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 $0008 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 ($5C3F),SP ; save stack pointer in LIST_SP
LD (IY+$02),$10 ; update TV_FLAG set bit 3
CALL L0DAF ; routine CL-ALL.
SET 0,(IY+$02) ; update TV_FLAG - signal lower screen in use
LD B,(IY+$31) ; fetch DF_SZ to B.
CALL L0E44 ; routine CL-LINE clears lower display
; preserving B.
RES 0,(IY+$02) ; update TV_FLAG - signal main screen in use
SET 0,(IY+$30) ; update FLAGS2 - signal will be necessary to
; clear main screen.
LD HL,($5C49) ; fetch E_PPC current edit line to HL.
LD DE,($5C6C) ; 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,$02C0 ; 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 ($5C6C),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 ($5C6C),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,($5C6C) ; 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+$02) ; 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,$03 ; 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,$02 ; default is stream 2 - the upper screen.
;; LIST-1
L17FB: LD (IY+$02),$00 ; 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 $3B ; is it ';' ?
JR Z,L1814 ; skip to LIST-2 if so.
CP $2C ; 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 $3F ; make less than $40 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 ($5C49),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,$01 ; 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+$02) ; 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,($5C6B) ; fetch DF_SZ lower display file size.
SUB (IY+$4F) ; 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,$5C6C ; 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,($5C49) ; 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,$3E ; prepare cursor '>' in D.
JR Z,L1865 ; to OUT-LINE1 if matched or line after.
LD DE,$0000 ; 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+$2D),E ; save flag in BREG which is spare.
LD A,(HL) ; get high byte of line number.
CP $40 ; is it too high ($2F 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+$01) ; 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+$01) ; 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+$30) ; update FLAGS2 - signal NOT in QUOTES.
LD HL,$5C3B ; point to FLAGS.
RES 2,(HL) ; signal 'K' mode. (starts before keyword)
BIT 5,(IY+$37) ; 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,($5C5F) ; 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,$3F ; 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 $0D ; 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 $0D
; -------------------------
; 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 $0E ; 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 $09F4 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,($5C8F) ; 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 ($5C8F),HL ; resave ATTR_T and MASK-T
LD HL,$5C91 ; address P_FLAG
LD D,(HL) ; fetch to D
PUSH DE ; and save.
LD (HL),$00 ; 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+$57),H ; and restore system variable P_FLAG.
POP HL ; restore temporary masks
LD ($5C8F),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,($5C5B) ; 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,($5C41) ; 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,$43 ; 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,$5C3B ; Address FLAGS
RES 3,(HL) ; signal 'K' mode initially.
LD A,$4B ; 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+$30) ; 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,$43 ; 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+$37) ; 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 $FF if spaces are suppressed.
; else $30 ('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 $FF, 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 $21 ; less than quote character ?
JR C,L196C ; to OUT-CH-3 to output controls and space.
RES 2,(IY+$01) ; initialize FLAGS to 'K' mode and leave
; unchanged if this character would precede
; a keyword.
CP $CB ; is character 'THEN' token ?
JR Z,L196C ; to OUT-CH-3 to output if so.
CP $3A ; is it ':' ?
JR NZ,L195A ; to OUT-CH-1 if not statement separator
; to change mode back to 'L'.
BIT 5,(IY+$37) ; 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+$30) ; 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 $22 ; is it quote character '"' ?
JR NZ,L1968 ; to OUT-CH-2 with others to set 'L' mode.
PUSH AF ; save character.
LD A,($5C6A) ; fetch FLAGS2.
XOR $04 ; toggle the quotes flag.
LD ($5C6A),A ; update FLAGS2
POP AF ; and restore character.
;; OUT-CH-2
L1968: SET 2,(IY+$01) ; 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,($5C53) ; 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 ($5C5D),HL ; save HL in CH_ADD
LD C,$00 ; 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 ($5C5D),HL ; save in CH_ADD
CP $22 ; is it quotes '"' ?
JR NZ,L19A5 ; to EACH-S-4 if not
DEC C ; toggle bit 0 of C
;; EACH-S-4
L19A5: CP $3A ; is it ':'
JR Z,L19AD ; to EACH-S-5
CP $CB ; '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 $0D ; 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 $3F and can be distinguished
; also from the variables area end-marker $80.
;
; 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 $40 ; 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,$0005 ; set BC to 5 for floating point number
JR NC,L19CE ; forward to NEXT-O-2 if not a for/next
; variable.
LD C,$12 ; 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,($5C59) ; load HL from system variable E_LINE.
DEC HL ; decrease so that NEXT_CHAR can be used
; without skipping the first digit.
LD ($5C5D),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,$5C92 ; use MEM-0 as a temporary calculator stack
; an overhead of three locations are needed.
LD ($5C65),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,$D8F0 ; 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 $08 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,$FF ; 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,$20 ; signal 'output leading spaces'
;; OUT-NUM-3
L1A30: LD BC,$FC18 ; value -1000
CALL L192A ; routine OUT-SP-NO outputs space or number
LD BC,$FF9C ; value -100
CALL L192A ; routine OUT-SP-NO
LD C,$F6 ; value -10 ( B is still $FF )
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 $CE - $FF
; which is then reduced to range $00 - $31 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 L1AF9 - $ ; B1 offset to Address: P-DEF-FN
DEFB L1B14 - $ ; CB offset to Address: P-CAT
DEFB L1B06 - $ ; BC offset to Address: P-FORMAT
DEFB L1B0A - $ ; BF offset to Address: P-MOVE
DEFB L1B10 - $ ; C4 offset to Address: P-ERASE
DEFB L1AFC - $ ; AF offset to Address: P-OPEN
DEFB L1B02 - $ ; B4 offset to Address: P-CLOSE
DEFB L1AE2 - $ ; 93 offset to Address: P-MERGE
DEFB L1AE1 - $ ; 91 offset to Address: P-VERIFY
DEFB L1AE3 - $ ; 92 offset to Address: P-BEEP
DEFB L1AE7 - $ ; 95 offset to Address: P-CIRCLE
DEFB L1AEB - $ ; 98 offset to Address: P-INK
DEFB L1AEC - $ ; 98 offset to Address: P-PAPER
DEFB L1AED - $ ; 98 offset to Address: P-FLASH
DEFB L1AEE - $ ; 98 offset to Address: P-BRIGHT
DEFB L1AEF - $ ; 98 offset to Address: P-INVERSE
DEFB L1AF0 - $ ; 98 offset to Address: P-OVER
DEFB L1AF1 - $ ; 98 offset to Address: P-OUT
DEFB L1AD9 - $ ; 7F offset to Address: P-LPRINT
DEFB L1ADC - $ ; 81 offset to Address: P-LLIST
DEFB L1A8A - $ ; 2E offset to Address: P-STOP
DEFB L1AC9 - $ ; 6C offset to Address: P-READ
DEFB L1ACC - $ ; 6E offset to Address: P-DATA
DEFB L1ACF - $ ; 70 offset to Address: P-RESTORE
DEFB L1AA8 - $ ; 48 offset to Address: P-NEW
DEFB L1AF5 - $ ; 94 offset to Address: P-BORDER
DEFB L1AB8 - $ ; 56 offset to Address: P-CONT
DEFB L1AA2 - $ ; 3F offset to Address: P-DIM
DEFB L1AA5 - $ ; 41 offset to Address: P-REM
DEFB L1A90 - $ ; 2B offset to Address: P-FOR
DEFB L1A7D - $ ; 17 offset to Address: P-GO-TO
DEFB L1A86 - $ ; 1F offset to Address: P-GO-SUB
DEFB L1A9F - $ ; 37 offset to Address: P-INPUT
DEFB L1AE0 - $ ; 77 offset to Address: P-LOAD
DEFB L1AAE - $ ; 44 offset to Address: P-LIST
DEFB L1A7A - $ ; 0F offset to Address: P-LET
DEFB L1AC5 - $ ; 59 offset to Address: P-PAUSE
DEFB L1A98 - $ ; 2B offset to Address: P-NEXT
DEFB L1AB1 - $ ; 43 offset to Address: P-POKE
DEFB L1A9C - $ ; 2D offset to Address: P-PRINT
DEFB L1AC1 - $ ; 51 offset to Address: P-PLOT
DEFB L1AAB - $ ; 3A offset to Address: P-RUN
DEFB L1ADF - $ ; 6D offset to Address: P-SAVE
DEFB L1AB5 - $ ; 42 offset to Address: P-RANDOM
DEFB L1A81 - $ ; 0D offset to Address: P-IF
DEFB L1ABE - $ ; 49 offset to Address: P-CLS
DEFB L1AD2 - $ ; 5C offset to Address: P-DRAW
DEFB L1ABB - $ ; 44 offset to Address: P-CLEAR
DEFB L1A8D - $ ; 15 offset to Address: P-RETURN
DEFB 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 $01 ; Class-01 - A variable is required.
DEFB $3D ; Separator: '='
DEFB $02 ; Class-02 - An expression, numeric or string,
; must follow.
;; P-GO-TO
L1A7D: DEFB $06 ; Class-06 - A numeric expression must follow.
DEFB $00 ; Class-00 - No further operands.
DEFW L1E67 ; Address: $1E67; Address: GO-TO
;; P-IF
L1A81: DEFB $06 ; Class-06 - A numeric expression must follow.
DEFB $CB ; Separator: 'THEN'
DEFB $05 ; Class-05 - Variable syntax checked
; by routine.
DEFW L1CF0 ; Address: $1CF0; Address: IF
;; P-GO-SUB
L1A86: DEFB $06 ; Class-06 - A numeric expression must follow.
DEFB $00 ; Class-00 - No further operands.
DEFW L1EED ; Address: $1EED; Address: GO-SUB
;; P-STOP
L1A8A: DEFB $00 ; Class-00 - No further operands.
DEFW L1CEE ; Address: $1CEE; Address: STOP
;; P-RETURN
L1A8D: DEFB $00 ; Class-00 - No further operands.
DEFW L1F23 ; Address: $1F23; Address: RETURN
;; P-FOR
L1A90: DEFB $04 ; Class-04 - A single character variable must
; follow.
DEFB $3D ; Separator: '='
DEFB $06 ; Class-06 - A numeric expression must follow.
DEFB $CC ; Separator: 'TO'
DEFB $06 ; Class-06 - A numeric expression must follow.
DEFB $05 ; Class-05 - Variable syntax checked
; by routine.
DEFW L1D03 ; Address: $1D03; Address: FOR
;; P-NEXT
L1A98: DEFB $04 ; Class-04 - A single character variable must
; follow.
DEFB $00 ; Class-00 - No further operands.
DEFW L1DAB ; Address: $1DAB; Address: NEXT
;; P-PRINT
L1A9C: DEFB $05 ; Class-05 - Variable syntax checked entirely
; by routine.
DEFW L1FCD ; Address: $1FCD; Address: PRINT
;; P-INPUT
L1A9F: DEFB $05 ; Class-05 - Variable syntax checked entirely
; by routine.
DEFW L2089 ; Address: $2089; Address: INPUT
;; P-DIM
L1AA2: DEFB $05 ; Class-05 - Variable syntax checked entirely
; by routine.
DEFW L2C02 ; Address: $2C02; Address: DIM
;; P-REM
L1AA5: DEFB $05 ; Class-05 - Variable syntax checked entirely
; by routine.
DEFW L1BB2 ; Address: $1BB2; Address: REM
;; P-NEW
L1AA8: DEFB $00 ; Class-00 - No further operands.
DEFW L11B7 ; Address: $11B7; Address: NEW
;; P-RUN
L1AAB: DEFB $03 ; Class-03 - A numeric expression may follow
; else default to zero.
DEFW L1EA1 ; Address: $1EA1; Address: RUN
;; P-LIST
L1AAE: DEFB $05 ; Class-05 - Variable syntax checked entirely
; by routine.
DEFW L17F9 ; Address: $17F9; Address: LIST
;; P-POKE
L1AB1: DEFB $08 ; Class-08 - Two comma-separated numeric
; expressions required.
DEFB $00 ; Class-00 - No further operands.
DEFW L1E80 ; Address: $1E80; Address: POKE
;; P-RANDOM
L1AB5: DEFB $03 ; Class-03 - A numeric expression may follow
; else default to zero.
DEFW L1E4F ; Address: $1E4F; Address: RANDOMIZE
;; P-CONT
L1AB8: DEFB $00 ; Class-00 - No further operands.
DEFW L1E5F ; Address: $1E5F; Address: CONTINUE
;; P-CLEAR
L1ABB: DEFB $03 ; Class-03 - A numeric expression may follow
; else default to zero.
DEFW L1EAC ; Address: $1EAC; Address: CLEAR
;; P-CLS
L1ABE: DEFB $00 ; Class-00 - No further operands.
DEFW L0D6B ; Address: $0D6B; Address: CLS
;; P-PLOT
L1AC1: DEFB $09 ; Class-09 - Two comma-separated numeric
; expressions required with optional colour
; items.
DEFB $00 ; Class-00 - No further operands.
DEFW L22DC ; Address: $22DC; Address: PLOT
;; P-PAUSE
L1AC5: DEFB $06 ; Class-06 - A numeric expression must follow.
DEFB $00 ; Class-00 - No further operands.
DEFW L1F3A ; Address: $1F3A; Address: PAUSE
;; P-READ
L1AC9: DEFB $05 ; Class-05 - Variable syntax checked entirely
; by routine.
DEFW L1DED ; Address: $1DED; Address: READ
;; P-DATA
L1ACC: DEFB $05 ; Class-05 - Variable syntax checked entirely
; by routine.
DEFW L1E27 ; Address: $1E27; Address: DATA
;; P-RESTORE
L1ACF: DEFB $03 ; Class-03 - A numeric expression may follow
; else default to zero.
DEFW L1E42 ; Address: $1E42; Address: RESTORE
;; P-DRAW
L1AD2: DEFB $09 ; Class-09 - Two comma-separated numeric
; expressions required with optional colour
; items.
DEFB $05 ; Class-05 - Variable syntax checked
; by routine.
DEFW L2382 ; Address: $2382; Address: DRAW
;; P-COPY
L1AD6: DEFB $00 ; Class-00 - No further operands.
DEFW L0EAC ; Address: $0EAC; Address: COPY
;; P-LPRINT
L1AD9: DEFB $05 ; Class-05 - Variable syntax checked entirely
; by routine.
DEFW L1FC9 ; Address: $1FC9; Address: LPRINT
;; P-LLIST
L1ADC: DEFB $05 ; Class-05 - Variable syntax checked entirely
; by routine.
DEFW L17F5 ; Address: $17F5; Address: LLIST
;; P-SAVE
L1ADF: DEFB $0B ; Class-0B - Offset address converted to tape
; command.
;; P-LOAD
L1AE0: DEFB $0B ; Class-0B - Offset address converted to tape
; command.
;; P-VERIFY
L1AE1: DEFB $0B ; Class-0B - Offset address converted to tape
; command.
;; P-MERGE
L1AE2: DEFB $0B ; Class-0B - Offset address converted to tape
; command.
;; P-BEEP
L1AE3: DEFB $08 ; Class-08 - Two comma-separated numeric
; expressions required.
DEFB $00 ; Class-00 - No further operands.
DEFW L03F8 ; Address: $03F8; Address: BEEP
;; P-CIRCLE
L1AE7: DEFB $09 ; Class-09 - Two comma-separated numeric
; expressions required with optional colour
; items.
DEFB $05 ; Class-05 - Variable syntax checked
; by routine.
DEFW L2320 ; Address: $2320; Address: CIRCLE
;; P-INK
L1AEB: DEFB $07 ; Class-07 - Offset address is converted to
; colour code.
;; P-PAPER
L1AEC: DEFB $07 ; Class-07 - Offset address is converted to
; colour code.
;; P-FLASH
L1AED: DEFB $07 ; Class-07 - Offset address is converted to
; colour code.
;; P-BRIGHT
L1AEE: DEFB $07 ; Class-07 - Offset address is converted to
; colour code.
;; P-INVERSE
L1AEF: DEFB $07 ; Class-07 - Offset address is converted to
; colour code.
;; P-OVER
L1AF0: DEFB $07 ; Class-07 - Offset address is converted to
; colour code.
;; P-OUT
L1AF1: DEFB $08 ; Class-08 - Two comma-separated numeric
; expressions required.
DEFB $00 ; Class-00 - No further operands.
DEFW L1E7A ; Address: $1E7A; Address: OUT
;; P-BORDER
L1AF5: DEFB $06 ; Class-06 - A numeric expression must follow.
DEFB $00 ; Class-00 - No further operands.
DEFW L2294 ; Address: $2294; Address: BORDER
;; P-DEF-FN
L1AF9: DEFB $05 ; Class-05 - Variable syntax checked entirely
; by routine.
DEFW L1F60 ; Address: $1F60; Address: DEF-FN
;; P-OPEN
L1AFC: DEFB $06 ; Class-06 - A numeric expression must follow.
DEFB $2C ; Separator: ',' see Footnote *
DEFB $0A ; Class-0A - A string expression must follow.
DEFB $00 ; Class-00 - No further operands.
DEFW L1736 ; Address: $1736; Address: OPEN
;; P-CLOSE
L1B02: DEFB $06 ; Class-06 - A numeric expression must follow.
DEFB $00 ; Class-00 - No further operands.
DEFW L16E5 ; Address: $16E5; Address: CLOSE
;; P-FORMAT
L1B06: DEFB $0A ; Class-0A - A string expression must follow.
DEFB $00 ; Class-00 - No further operands.
DEFW L1793 ; Address: $1793; Address: CAT-ETC
;; P-MOVE
L1B0A: DEFB $0A ; Class-0A - A string expression must follow.
DEFB $2C ; Separator: ','
DEFB $0A ; Class-0A - A string expression must follow.
DEFB $00 ; Class-00 - No further operands.
DEFW L1793 ; Address: $1793; Address: CAT-ETC
;; P-ERASE
L1B10: DEFB $0A ; Class-0A - A string expression must follow.
DEFB $00 ; Class-00 - No further operands.
DEFW L1793 ; Address: $1793; Address: CAT-ETC
;; P-CAT
L1B14: DEFB $00 ; Class-00 - No further operands.
DEFW L1793 ; Address: $1793; 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+$01) ; update FLAGS - signal checking syntax
CALL L19FB ; routine E-LINE-NO >>
; fetches the line number if in range.
XOR A ; clear the accumulator.
LD ($5C47),A ; set statement number SUBPPC to zero.
DEC A ; set accumulator to $FF.
LD ($5C3A),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+$0D) ; increment statement number SUBPPC
JP M,L1C8A ; to REPORT-C to raise
; 'Nonsense in BASIC' if over 127.
RST 18H ; GET-CHAR
LD B,$00 ; set B to zero for later indexing.
; early so any other reason ???
CP $0D ; is character carriage return ?
; i.e. an empty statement.
JR Z,L1BB3 ; forward to LINE-END if so.
CP $3A ; 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 $CE ; 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,($5C74) ; 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 ($5C74),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 $20 ; 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,$00 ; 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 $14 ; Error Report: BREAK into program
;; STMT-R-1
L1B7D: BIT 7,(IY+$0A) ; test NSPPC - will be set if $FF -
; no jump to be made.
JR NZ,L1BF4 ; forward to STMT-NEXT if a program line.
LD HL,($5C42) ; 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,$FFFE ; The dummy value minus two
LD ($5C45),HL ; is set/reset as line number in PPC.
LD HL,($5C61) ; point to end of line + 1 - WORKSP.
DEC HL ; now point to $80 end-marker.
LD DE,($5C59) ; address the start of line E_LINE.
DEC DE ; now location before - for GET-CHAR.
LD A,($5C44) ; 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,($5C44) ; 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 $C0 ; test if using direct command
; a program line is less than $3F
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 $FF ; 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,($5C55) ; fetch NXTLIN to HL.
LD A,$C0 ; test against the
AND (HL) ; system limit $3F.
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 $01 ; will set carry if zero.
ADC A,$00 ; 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 ($5C45),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 ($80) if from LINE-RUN.
;; NEXT-LINE
L1BD1: LD ($5C55),HL ; store pointer in system variable NXTLIN
EX DE,HL ; bring back pointer to previous or edit line
LD ($5C5D),HL ; and update CH_ADD with character address.
LD D,A ; store statement in D.
LD E,$00 ; set E to zero to suppress token searching
; if EACH-STMT is to be called.
LD (IY+$0A),$FF ; set statement NSPPC to $FF signalling
; no jump to be made.
DEC D ; decrement and test statement
LD (IY+$0D),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 $16 ; 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 $0D ; is it carriage return ?
JR Z,L1BB3 ; back to LINE-END if so.
CP $3A ; 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 L1C10 - $ ; 0F offset to Address: CLASS-00
DEFB L1C1F - $ ; 1D offset to Address: CLASS-01
DEFB L1C4E - $ ; 4B offset to Address: CLASS-02
DEFB L1C0D - $ ; 09 offset to Address: CLASS-03
DEFB L1C6C - $ ; 67 offset to Address: CLASS-04
DEFB L1C11 - $ ; 0B offset to Address: CLASS-05
DEFB L1C82 - $ ; 7B offset to Address: CLASS-06
DEFB L1C96 - $ ; 8E offset to Address: CLASS-07
DEFB L1C7A - $ ; 71 offset to Address: CLASS-08
DEFB L1CBE - $ ; B4 offset to Address: CLASS-09
DEFB L1C8C - $ ; 81 offset to Address: CLASS-0A
DEFB 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,($5C74) ; 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+$37),$00 ; set FLAGX to zero
JR NC,L1C30 ; forward to VAR-A-2 if found or checking
; syntax.
SET 1,(IY+$37) ; 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 $01 ; Error Report: Variable not found
;; VAR-A-2
L1C30: CALL Z,L2996 ; routine STK-VAR considers a subscript/slice
BIT 6,(IY+$01) ; 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,$5C71 ; 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 ($5C72),BC ; update STRLEN
LD ($5C4D),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,($5C3B) ; 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+$01) ; post-SCANNING FLAGS to D
XOR D ; xor the two sets of flags
AND $40 ; 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 $9F ; combine with 10011111.
INC A ; test if now $FF 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 $2C ; 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+$01) ; test FLAGS - Numeric or string result ?
RET NZ ; return if result is numeric.
;; REPORT-C
L1C8A: RST 08H ; ERROR-1
DEFB $0B ; 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+$01) ; 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+$01) ; test FLAGS - checking syntax only ?
; Note. there is a subroutine to do this.
RES 0,(IY+$02) ; 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,($5C74) ; T_ADDR_lo to accumulator.
; points to '$07' entry + 1
; e.g. for INK points to $EC 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 $13.
L1CA5: SUB L1AEB-$D8 % 256 ; convert $EB to $D8 ('INK') etc.
; ( is SUB $13 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,($5C8F) ; pick up ATTR_T and MASK_T
LD ($5C8D),HL ; and store in ATTR_P and MASK_P
LD HL,$5C91 ; point to P_FLAG.
LD A,(HL) ; pick up in A
RLCA ; rotate to left
XOR (HL) ; combine with HL
AND $AA ; 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+$02) ; update TV_FLAG - signal main screen in use
CALL L0D4D ; routine TEMPS is called.
LD HL,$5C90 ; point to MASK_T
LD A,(HL) ; fetch mask to accumulator.
OR $F8 ; or with 11111000 paper/bright/flash 8
LD (HL),A ; mask back to MASK_T system variable.
RES 6,(IY+$57) ; 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 $0D ; is character a carriage return ?
JR Z,L1CE6 ; forward to USE-ZERO if so
CP $3A ; 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 $A0 ;;stk-zero ;0.
DEFB $38 ;;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 $08 ; 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 $02 ;;delete .
DEFB $38 ;;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 $CD ; 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 $A1 ;;stk-one v,l,1=s.
DEFB $38 ;;end-calc
;; F-REORDER
L1D16: RST 28H ;; FP-CALC v,l,s.
DEFB $C0 ;;st-mem-0 v,l,s.
DEFB $02 ;;delete v,l.
DEFB $01 ;;exchange l,v.
DEFB $E0 ;;get-mem-0 l,v,s.
DEFB $01 ;;exchange l,s,v.
DEFB $38 ;;end-calc
CALL L2AFF ; routine LET assigns the initial value v to
; the variable altering type if necessary.
LD ($5C68),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,$0006 ; 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,$0D ; 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 $02 ;;delete l.
DEFB $02 ;;delete .
DEFB $38 ;;end-calc
; DE points to STKEND, l.
POP HL ; restore variable position
EX DE,HL ; swap pointers
LD C,$0A ; ten bytes to move
LDIR ; Copy 'deleted' values to variable.
LD HL,($5C45) ; 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+$0D) ; 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+$38) ; get single-character name from STRLEN_lo
LD HL,($5C45) ; get the current line from PPC
LD ($5C42),HL ; and store it in NEWPPC
LD A,($5C47) ; 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,($5C5D) ; get current address from CH_ADD
LD E,$F3 ; search will be for token 'NEXT'
;; F-LOOP
L1D64: PUSH BC ; save variable name.
LD BC,($5C55) ; fetch NXTLIN
CALL L1D86 ; routine LOOK-PROG searches for 'NEXT' token.
LD ($5C55),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 $20 ; 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,$01 ; subtract the negated counter from 1
SUB D ; to give the statement after the NEXT
LD ($5C44),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 $11 ; 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 $3A ; 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 $C0 ; test for program end marker $80 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 ($5C42),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,$00 ; 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+$37) ; 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,($5C4D) ; 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 ($5C68),HL ; and set MEM to point to three 5-byte values
; value, limit, step.
RST 28H ;; FP-CALC add step and re-store
DEFB $E0 ;;get-mem-0 v.
DEFB $E2 ;;get-mem-2 v,s.
DEFB $0F ;;addition v+s.
DEFB $C0 ;;st-mem-0 v+s.
DEFB $02 ;;delete .
DEFB $38 ;;end-calc
CALL L1DDA ; routine NEXT-LOOP tests against limit.
RET C ; return if no more iterations possible.
LD HL,($5C68) ; find start of variable contents from MEM.
LD DE,$000F ; 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 $00 ; 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 $E1 ;;get-mem-1 l.
DEFB $E0 ;;get-mem-0 l,v.
DEFB $E2 ;;get-mem-2 l,v,s.
DEFB $36 ;;less-0 l,v,(1/0) negative step ?
DEFB $00 ;;jump-true l,v.(1/0)
DEFB $02 ;;to L1DE2, NEXT-1 if step negative
DEFB $01 ;;exchange v,l.
;; NEXT-1
L1DE2: DEFB $03 ;;subtract l-v OR v-l.
DEFB $37 ;;greater-0 (1/0)
DEFB $00 ;;jump-true .
DEFB $04 ;;to L1DE9, NEXT-2 if no more iterations.
DEFB $38 ;;end-calc .
AND A ; clear carry flag signalling another loop.
RET ; return
; ---
;; NEXT-2
L1DE9: DEFB $38 ;;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 ($5C5F),HL ; save character position in X_PTR.
LD HL,($5C57) ; 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 $2C ; 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,$E4 ; 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 $0D ; 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 ($5C57),HL ; store back in DATADD
LD HL,($5C5F) ; fetch X_PTR the original READ CH_ADD
LD (IY+$26),$00 ; now nullify X_PTR_hi
CALL L0078 ; routine TEMP-PTR2 restores READ CH_ADD
;; READ-2
L1E1E: RST 18H ; GET-CHAR
CP $2C ; 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 $2C ; 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,$E4 ; 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,$0200 ; 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 $3F
; 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 ($5C57),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,($5C78) ; use the lower two bytes at FRAMES1.
;; RAND-1
L1E5A: LD ($5C76),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,($5C6E) ; fetch OLDPPC line number.
LD D,(IY+$36) ; 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 $F0
; instead of $3F. 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,$00 ; set statement to 0 - first.
LD A,H ; compare high byte only
CP $F0 ; to $F0 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 ($5C42),HL ; save line number in NEWPPC
LD (IY+$0A),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 $0A ; 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,$0000 ; 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,($5CB2) ; use the existing value of RAMTOP if zero.
;; CLEAR-1
L1EB7: PUSH BC ; save ramtop value.
LD DE,($5C4B) ; fetch VARS
LD HL,($5C59) ; 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,($5C65) ; fetch STKEND the start of free memory.
LD DE,$0032 ; 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,($5CB4) ; now P-RAMT ($7FFF 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 $15 ; Error Report: RAMTOP no good
;; CLEAR-2
L1EDC: EX DE,HL ; transfer ramtop value to HL.
LD ($5CB2),HL ; update system variable RAMTOP.
POP DE ; pop the return address STMT-RET.
POP BC ; pop the Error Address.
LD (HL),$3E ; 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 ($5C3D),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+$0D) ; 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,($5C45) ; 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 ($5C3D),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,$0014 ; 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,($5C65) ; fetch STKEND
ADD HL,BC ; add the supplied test value
JR C,L1F15 ; forward to REPORT-4 if over $FFFF
EX DE,HL ; was less so transfer to DE
LD HL,$0050 ; test against another 80 bytes
ADD HL,DE ; anyway
JR C,L1F15 ; forward to REPORT-4 if this passes $FFFF
SBC HL,SP ; if less than the machine stack pointer
RET C ; then return - OK.
;; REPORT-4
L1F15: LD L,$03 ; prepare 'Out of Memory'
JP L0055 ; jump back to ERROR-3 at $0055
; Note. this error can't be trapped at $0008
; ------------------------------
; 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,$0000 ; 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 $00 - $27 is
CP $3E ; compared with the traditional end-marker $3E.
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 ($5C3D),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 $06 ; 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 $FFFF
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+$01) ; test FLAGS - has a new key been pressed ?
JR Z,L1F3D ; back to PAUSE-1 if not.
;; PAUSE-END
L1F4F: RES 5,(IY+$01) ; 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,$7F ; Input address: $7FFE
IN A,($FE) ; read lower right keys
RRA ; rotate bit 0 - SPACE
RET C ; return if not reset
LD A,$FE ; Input address: $FEFE
IN A,($FE) ; 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,$CE ; 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+$01) ; 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 $24 ; is it '$' ?
JR NZ,L1F7D ; to DEF-FN-2 if not as numeric.
RES 6,(IY+$01) ; set FLAGS - Signal string result
RST 20H ; get NEXT-CHAR
;; DEF-FN-2
L1F7D: CP $28 ; is it '(' ?
JR NZ,L1FBD ; to DEF-FN-7 'Nonsense in BASIC'
RST 20H ; NEXT-CHAR
CP $29 ; 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 $24 ; '$' ? 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,$0006 ; the function requires six hidden bytes for
; each parameter passed.
; The first byte will be $0E
; 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),$0E ; 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 $2C ; 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 $29 ; should close with a ')'
JR NZ,L1FBD ; to DEF-FN-7 if not
; 'Nonsense in BASIC'
RST 20H ; get NEXT-CHAR
CP $3D ; is it '=' ?
JR NZ,L1FBD ; to DEF-FN-7 if not 'Nonsense...'
RST 20H ; address NEXT-CHAR
LD A,($5C3B) ; 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+$01) ; xor with FLAGS - bit 6 should be same
; therefore will be reset.
AND $40 ; 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,$03 ; 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,$02 ; 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 $29 ; 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,$0D ; 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 $AC ; 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,$16 ; prepare the 'at' control.
JR L201E ; forward to PR-AT-TAB to print the sequence.
; ---
;; PR-ITEM-2
L200E: CP $AD ; 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,$17 ; 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+$01) ; 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 $29 ; is character a ')' ?
RET Z ; return if so - e.g. INPUT (p$); a$
;; PR-ST-END
L2048: CP $0D ; is it a carriage return ?
RET Z ; return also - e.g. PRINT a
CP $3A ; 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 $3B ; is it ';' ?
; i.e. print from last position.
JR Z,L2067 ; forward to PR-POSN-3 if so.
; i.e. do nothing.
CP $2C ; 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,$06 ; 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 $27 ; 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 $23 ; 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 $10 ; 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,$01 ; 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 $01.
;; INPUT-1
L2096: LD (IY+$02),$01 ; 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,($5C88) ; fetch S_POSN current line/column of
; the upper screen.
LD A,($5C6B) ; 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,$21 ; 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 ($5C88),BC ; set S_POSN update upper screen line/column.
LD A,$19 ; subtract from twenty five
SUB B ; the new line number.
LD ($5C8C),A ; and place result in SCR_CT - scroll count.
RES 0,(IY+$02) ; 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 $28 ; 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 $29 ; 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 $CA ; 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+$37) ; update FLAGX - signal handling INPUT LINE
BIT 6,(IY+$01) ; 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+$37) ; 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,$5C71 ; point to system variable FLAGX
RES 6,(HL) ; signal string result.
SET 5,(HL) ; signal in Input Mode for editor.
LD BC,$0001 ; 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,($5C3B) ; load accumulator from FLAGS
AND $40 ; 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,$03 ; 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),$0D ; 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,$22 ; 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 ($5C5B),HL ; set keyboard cursor K_CUR to HL
BIT 7,(IY+$37) ; 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,($5C5D) ; fetch CH_ADD
PUSH HL ; and save on stack.
LD HL,($5C3D) ; 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+$30) ; test FLAGS2 - is K channel in use ?
JR Z,L2148 ; forward to IN-VAR-2 if not using the
; keyboard for input. (??)
LD ($5C3D),SP ; set ERR_SP to point to IN-VAR-1 on stack.
;; IN-VAR-2
L2148: LD HL,($5C61) ; set HL to WORKSP - start of workspace.
CALL L11A7 ; routine REMOVE-FP removes floating point
; forms when looping in error condition.
LD (IY+$00),$FF ; 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+$01) ; 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+$22),$00 ; 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,($5C82) ; 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,$5C71 ; 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 ($5C3D),HL ; set ERR_SP to point to it.
POP HL ; drop original CH_ADD which points to
; INPUT command in BASIC line.
LD ($5C5F),HL ; save in X_PTR while input is assigned.
SET 7,(IY+$01) ; 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,($5C5F) ; fetch stored CH_ADD value from X_PTR.
LD (IY+$26),$00 ; set X_PTR_hi so that iy is no longer relevant.
LD ($5C5D),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,($5C63) ; STKBOT points to the end of the input.
LD DE,($5C61) ; 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,($5C61) ; fetch WORKSP start of input
LD ($5C5D),HL ; set CH_ADD to first character
RST 18H ; GET-CHAR ignoring leading white-space.
CP $E2 ; is it 'STOP'
JR Z,L21D0 ; forward to IN-STOP if so.
LD A,($5C71) ; 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 $0D ; 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 $0B ; 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 $10 ; 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,($5C51) ; 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 $4B ; 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 $2C ; is it ',' separator ?
JR Z,L21E1 ; back if so to CO-TEMP-1
CP $3B ; 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 $D9 ; is it 'INK' ?
RET C ; return if less.
CP $DF ; compare with 'OUT'
CCF ; Complement Carry Flag
RET C ; return if greater than 'OVER', $DE.
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 $C9 ; reduce to control character $10 (INK)
; thru $15 (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 $10 (INK) to $15 (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 $11 ; reduce range $FF-$04
ADC A,$00 ; add in carry if INK
JR Z,L2234 ; forward to CO-TEMP-7 with INK and PAPER.
SUB $02 ; reduce range $FF-$02
ADC A,$00 ; add carry if FLASH
JR Z,L2273 ; forward to CO-TEMP-C with FLASH and BRIGHT.
CP $01 ; is it 'INVERSE' ?
LD A,D ; fetch parameter for INVERSE/OVER
LD B,$01 ; 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,$04 ; set bit 2 of mask for inverse.
;; CO-TEMP-6
L2228: LD C,A ; save the A
LD A,D ; re-fetch parameter
CP $02 ; 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,$5C91 ; 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,$07 ; 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,$38 ; 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 $0A ; 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 $13 ; Error Report: Invalid colour
;; CO-TEMP-9
L2246: LD HL,$5C8F ; address system variable ATTR_T initially.
CP $08 ; 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 $24 ; 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,$07 ; put 7 in accumulator
CP D ; compare with parameter
SBC A,A ; $00 if 0-7, $FF 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 $50 ; 01000000 or 00010000 (AND 01010000)
LD B,A ; transfer to mask
LD A,$08 ; load A with 8
CP D ; compare with parameter
SBC A,A ; $FF if was 9, $00 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,$80 ; mask for flash 10000000
JR NZ,L227D ; forward to CO-TEMP-D if flash
RRCA ; rotate bit 7 to bit 6
LD B,$40 ; mask for bright 01000000
;; CO-TEMP-D
L227D: LD C,A ; store value in C
LD A,D ; fetch parameter
CP $08 ; compare with 8
JR Z,L2287 ; forward to CO-TEMP-E if 8
CP $02 ; 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,$5C8F ; 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 $08 ; must be in range 0 (black) to 7 (white)
JR NC,L2244 ; back to REPORT-K if not
; 'Invalid colour'.
OUT ($FE),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 $07 ; make the ink white.
;; BORDER-1
L22A6: LD ($5C48),A ; update BORDCR with new paper/ink
RET ; return.
; -----------------
; Get pixel address
; -----------------
;
;
;; PIXEL-ADD
L22AA: LD A,$AF ; 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 $F8 ; 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 $C7 ; 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 $07 ; 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 $01 ; 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 ($5C7D),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,$FE ; 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+$57) ; 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,$01 ; prepare a positive sign byte.
RET Z ; return if FP-TO-BC indicated positive.
LD C,$FF ; 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 $2C ; 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 $2A ;;abs x, y, r.
DEFB $3D ;;re-stack x, y, r.
DEFB $38 ;;end-calc x, y, r.
LD A,(HL) ; Fetch first, floating-point, exponent byte.
CP $81 ; 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 $02 ;;delete x, y.
DEFB $38 ;;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 $A3 ;;stk-pi/2 x, y, r, pi/2.
DEFB $38 ;;end-calc x, y, r, pi/2.
; Change the exponent of pi/2 from $81 to $83 giving 2*PI the central angle.
; This is quicker than multiplying by four.
LD (HL),$83 ; 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 $C5 ;;st-mem-5 store 2*PI in mem-5
DEFB $02 ;;delete x, y, r.
DEFB $38 ;;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 $31 ;;duplicate x, y, r, r.
DEFB $E1 ;;get-mem-1 x, y, r, r, sin(a/2).
DEFB $04 ;;multiply x, y, r, half-chord.
DEFB $38 ;;end-calc x, y, r, half-chord.
LD A,(HL) ; fetch exponent of the half arc to A.
CP $80 ; 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 $02 ;;delete x, y, r.
DEFB $02 ;;delete x, y.
DEFB $38 ;;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 $C2 ;;st-mem-2 x, y, r, half chord to mem-2.
DEFB $01 ;;exchange x, y, hc, r.
DEFB $C0 ;;st-mem-0 x, y, hc, r.
DEFB $02 ;;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 $03 ;;subtract x, y-hc. (The start y-coord)
DEFB $01 ;;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 $E0 ;;get-mem-0 sy, x, r.
DEFB $0F ;;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 $C0 ;;st-mem-0 sy, sx.
DEFB $01 ;;exchange sx, sy.
DEFB $31 ;;duplicate sx, sy, sy.
DEFB $E0 ;;get-mem-0 sx, sy, sy, sx.
DEFB $01 ;;exchange sx, sy, sx, sy.
DEFB $31 ;;duplicate sx, sy, sx, sy, sy.
DEFB $E0 ;;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 $A0 ;;stk-zero sx, sy, sx, sy, sy, sx, 0.
DEFB $C1 ;;st-mem-1 sx, sy, sx, sy, sy, sx, 0.
DEFB $02 ;;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 $38 ;;end-calc tx, ty, ax, ay, sy, sx.
; Use the exponent manipulating trick again to double the value of mem-2.
INC (IY+$62) ; 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 ($5C7D),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 $2C ; 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 $C5 ;;st-mem-5 x, y, A.
; Test the angle for the special case of 360 degrees.
DEFB $A2 ;;stk-half x, y, A, 1/2.
DEFB $04 ;;multiply x, y, A/2.
DEFB $1F ;;sin x, y, sin(A/2).
DEFB $31 ;;duplicate x, y, sin(A/2),sin(A/2)
DEFB $30 ;;not x, y, sin(A/2), (0/1).
DEFB $30 ;;not x, y, sin(A/2), (1/0).
DEFB $00 ;;jump-true x, y, sin(A/2).
DEFB $06 ;;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 $02 ;;delete x, y.
DEFB $38 ;;end-calc x, y.
JP L2477 ; forward to LINE-DRAW
; ---
; An arc can be drawn.
;; DR-SIN-NZ
L23A3: DEFB $C0 ;;st-mem-0 x, y, sin(A/2). store mem-0
DEFB $02 ;;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 $C1 ;;st-mem-1 x, y. store mem-1
DEFB $02 ;;delete x.
DEFB $31 ;;duplicate x, x.
DEFB $2A ;;abs x, x (+ve).
DEFB $E1 ;;get-mem-1 x, X, y.
DEFB $01 ;;exchange x, y, X.
DEFB $E1 ;;get-mem-1 x, y, X, y.
DEFB $2A ;;abs x, y, X, Y (+ve).
DEFB $0F ;;addition x, y, X+Y.
DEFB $E0 ;;get-mem-0 x, y, X+Y, sin(A/2).
DEFB $05 ;;division x, y, X+Y/sin(A/2).
DEFB $2A ;;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 $E0 ;;get-mem-0 x, y, D, sin(A/2).
DEFB $01 ;;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 $3D ;;re-stack (unnecessary)
DEFB $38 ;;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 $81 ; 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 $02 ;;delete
DEFB $02 ;;delete
DEFB $38 ;;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 $02 ;;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 $E1 ;;get-mem-1 x, y, sin(A/2), sin(a/2)
DEFB $01 ;;exchange x, y, sin(a/2), sin(A/2)
DEFB $05 ;;division x, y, sin(a/2)/sin(A/2)
DEFB $C1 ;;st-mem-1 x, y. f.
DEFB $02 ;;delete x, y.
; With the factor stored, scale the x coordinate first.
DEFB $01 ;;exchange y, x.
DEFB $31 ;;duplicate y, x, x.
DEFB $E1 ;;get-mem-1 y, x, x, f.
DEFB $04 ;;multiply y, x, x*f (=xx)
DEFB $C2 ;;st-mem-2 y, x, xx.
DEFB $02 ;;delete y. x.
; Now scale the y coordinate.
DEFB $01 ;;exchange x, y.
DEFB $31 ;;duplicate x, y, y.
DEFB $E1 ;;get-mem-1 x, y, y, f
DEFB $04 ;;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 $E2 ;;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 $E5 ;;get-mem-5 x, y, yy, xx, A.
DEFB $E0 ;;get-mem-0 x, y, yy, xx, A, a.
DEFB $03 ;;subtract x, y, yy, xx, A-a.
DEFB $A2 ;;stk-half x, y, yy, xx, A-a, 1/2.
DEFB $04 ;;multiply x, y, yy, xx, (A-a)/2. (=angle)
DEFB $31 ;;duplicate x, y, yy, xx, angle, angle.
DEFB $1F ;;sin x, y, yy, xx, angle, sin(angle)
DEFB $C5 ;;st-mem-5 x, y, yy, xx, angle, sin(angle)
DEFB $02 ;;delete x, y, yy, xx, angle
DEFB $20 ;;cos x, y, yy, xx, cos(angle).
; Note. mem-0, mem-1 and mem-2 can be used again now...
DEFB $C0 ;;st-mem-0 x, y, yy, xx, cos(angle).
DEFB $02 ;;delete x, y, yy, xx.
DEFB $C2 ;;st-mem-2 x, y, yy, xx.
DEFB $02 ;;delete x, y, yy.
DEFB $C1 ;;st-mem-1 x, y, yy.
DEFB $E5 ;;get-mem-5 x, y, yy, sin(angle)
DEFB $04 ;;multiply x, y, yy*sin(angle).
DEFB $E0 ;;get-mem-0 x, y, yy*sin(angle), cos(angle)
DEFB $E2 ;;get-mem-2 x, y, yy*sin(angle), cos(angle), xx.
DEFB $04 ;;multiply x, y, yy*sin(angle), xx*cos(angle).
DEFB $0F ;;addition x, y, xRotated.
DEFB $E1 ;;get-mem-1 x, y, xRotated, yy.
DEFB $01 ;;exchange x, y, yy, xRotated.
DEFB $C1 ;;st-mem-1 x, y, yy, xRotated.
DEFB $02 ;;delete x, y, yy.
DEFB $E0 ;;get-mem-0 x, y, yy, cos(angle).
DEFB $04 ;;multiply x, y, yy*cos(angle).
DEFB $E2 ;;get-mem-2 x, y, yy*cos(angle), xx.
DEFB $E5 ;;get-mem-5 x, y, yy*cos(angle), xx, sin(angle).
DEFB $04 ;;multiply x, y, yy*cos(angle), xx*sin(angle).
DEFB $03 ;;subtract x, y, yRotated.
DEFB $C2 ;;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 $2A ;;abs x, y, yRotated'.
DEFB $E1 ;;get-mem-1 x, y, yRotated', xRotated.
DEFB $2A ;;abs x, y, yRotated', xRotated'.
DEFB $0F ;;addition x, y, yRotated+xRotated.
DEFB $02 ;;delete x, y.
DEFB $38 ;;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 $81 ; 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 $01 ;;exchange y, x.
DEFB $38 ;;end-calc y, x.
LD A,($5C7D) ; 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 $C0 ;;st-mem-0 y, x, last-x.
DEFB $0F ;;addition y, absolute x.
DEFB $01 ;;exchange tx, y.
DEFB $38 ;;end-calc tx, y.
LD A,($5C7E) ; 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 $C5 ;;st-mem-5 tx, y, last-y.
DEFB $0F ;;addition tx, ty.
; Fetch the moving ax and ay to the calculator stack.
DEFB $E0 ;;get-mem-0 tx, ty, ax.
DEFB $E5 ;;get-mem-5 tx, ty, ax, ay.
DEFB $38 ;;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 $E1 ;;get-mem-1 rx.
DEFB $31 ;;duplicate rx, rx.
DEFB $E3 ;;get-mem-3 cos(a)
DEFB $04 ;;multiply rx, rx*cos(a).
DEFB $E2 ;;get-mem-2 rx, rx*cos(a), ry.
DEFB $E4 ;;get-mem-4 rx, rx*cos(a), ry, sin(a).
DEFB $04 ;;multiply rx, rx*cos(a), ry*sin(a).
DEFB $03 ;;subtract rx, rx*cos(a) - ry*sin(a)
DEFB $C1 ;;st-mem-1 rx, new relative x rotated.
DEFB $02 ;;delete rx.
DEFB $E4 ;;get-mem-4 rx, sin(a).
DEFB $04 ;;multiply rx*sin(a)
DEFB $E2 ;;get-mem-2 rx*sin(a), ry.
DEFB $E3 ;;get-mem-3 rx*sin(a), ry, cos(a).
DEFB $04 ;;multiply rx*sin(a), ry*cos(a).
DEFB $0F ;;addition rx*sin(a) + ry*cos(a).
DEFB $C2 ;;st-mem-2 new relative y rotated.
DEFB $02 ;;delete .
DEFB $38 ;;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 $C0 ;;st-mem-0 ax, ay.
DEFB $02 ;;delete ax.
; Now add the fractional relative x coordinate to the fractional absolute
; x coordinate to obtain a new fractional x-coordinate.
DEFB $E1 ;;get-mem-1 ax, xr.
DEFB $0F ;;addition ax+xr (= new ax).
DEFB $31 ;;duplicate ax, ax.
DEFB $38 ;;end-calc ax, ax.
LD A,($5C7D) ; COORDS-x last x (integer ix 0-255)
CALL L2D28 ; routine STACK-A
RST 28H ;; FP-CALC ax, ax, ix.
DEFB $03 ;;subtract ax, ax-ix = relative DRAW Dx.
; Having calculated the x value for DRAW do the same for the y value.
DEFB $E0 ;;get-mem-0 ax, Dx, ay.
DEFB $E2 ;;get-mem-2 ax, Dx, ay, ry.
DEFB $0F ;;addition ax, Dx, ay+ry (= new ay).
DEFB $C0 ;;st-mem-0 ax, Dx, ay.
DEFB $01 ;;exchange ax, ay, Dx,
DEFB $E0 ;;get-mem-0 ax, ay, Dx, ay.
DEFB $38 ;;end-calc ax, ay, Dx, ay.
LD A,($5C7E) ; COORDS-y last y (integer iy 0-175)
CALL L2D28 ; routine STACK-A
RST 28H ;; FP-CALC ax, ay, Dx, ay, iy.
DEFB $03 ;;subtract ax, ay, Dx, ay-iy ( = Dy).
DEFB $38 ;;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 $02 ;;delete tx, ty, ax.
DEFB $02 ;;delete tx, ty.
DEFB $01 ;;exchange ty, tx.
DEFB $38 ;;end-calc ty, tx.
; First calculate the relative x coordinate to the end-point.
LD A,($5C7D) ; COORDS-x
CALL L2D28 ; routine STACK-A
RST 28H ;; FP-CALC ty, tx, coords_x.
DEFB $03 ;;subtract ty, rx.
; Next calculate the relative y coordinate to the end-point.
DEFB $01 ;;exchange rx, ty.
DEFB $38 ;;end-calc rx, ty.
LD A,($5C7E) ; COORDS-y
CALL L2D28 ; routine STACK-A
RST 28H ;; FP-CALC rx, ty, coords_y
DEFB $03 ;;subtract rx, ry.
DEFB $38 ;;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 $31 ;;duplicate z, z.
DEFB $28 ;;sqr z, sqr(z).
DEFB $34 ;;stk-data z, sqr(z), 2.
DEFB $32 ;;Exponent: $82, Bytes: 1
DEFB $00 ;;(+00,+00,+00)
DEFB $01 ;;exchange z, 2, sqr(z).
DEFB $05 ;;division z, 2/sqr(z).
DEFB $E5 ;;get-mem-5 z, 2/sqr(z), ANGLE.
DEFB $01 ;;exchange z, ANGLE, 2/sqr (z)
DEFB $05 ;;division z, ANGLE*sqr(z)/2 (= No. of lines)
DEFB $2A ;;abs (for arc only)
DEFB $38 ;;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 $FC ; AND 252
; Adding 4 could set carry for arc, for the circle example, 28 becomes 32.
ADD A,$04 ; 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,$FC ; 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 $E5 ;;get-mem-5 z, A, ANGLE.
DEFB $01 ;;exchange z, ANGLE, A.
DEFB $05 ;;division z, ANGLE/A. (Angle/count = a)
DEFB $31 ;;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 $1F ;;sin z, a, sin(a)
DEFB $C4 ;;st-mem-4 z, a, sin(a)
DEFB $02 ;;delete z, a.
DEFB $31 ;;duplicate z, a, a.
DEFB $A2 ;;stk-half z, a, a, 1/2.
DEFB $04 ;;multiply z, a, a/2.
DEFB $1F ;;sin z, a, sin(a/2).
; Note. after second sin, mem-0 and mem-1 become free.
DEFB $C1 ;;st-mem-1 z, a, sin(a/2).
DEFB $01 ;;exchange z, sin(a/2), a.
DEFB $C0 ;;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 $02 ;;delete z, sin(a/2).
DEFB $31 ;;duplicate z, sin(a/2), sin(a/2).
DEFB $04 ;;multiply z, sin(a/2)*sin(a/2).
DEFB $31 ;;duplicate z, sin(a/2)*sin(a/2),
;; sin(a/2)*sin(a/2).
DEFB $0F ;;addition z, 2*sin(a/2)*sin(a/2).
DEFB $A1 ;;stk-one z, 2*sin(a/2)*sin(a/2), 1.
DEFB $03 ;;subtract z, 2*sin(a/2)*sin(a/2)-1.
DEFB $1B ;;negate z, 1-2*sin(a/2)*sin(a/2).
DEFB $C3 ;;st-mem-3 z, cos(a).
DEFB $02 ;;delete z.
DEFB $38 ;;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,$00 ;
;; 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,($5C7D) ; 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 $0A ; 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,$00 ; 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,$00 ; 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 $0D ; is it carriage return ?
; inside a quote.
JP Z,L1C8A ; jump back to REPORT-C if so.
; 'Nonsense in BASIC'.
CP $22 ; is it a quote '"' ?
JR NZ,L250F ; back to S-QUOTE-S if not for more.
CALL L0074 ; routine CH-ADD+1
CP $22 ; 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 $28 ; 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 $29 ; 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+$01) ; 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,($5C36) ; fetch address of CHARS.
LD DE,$0100 ; 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 $E0 ; and with 11100000
XOR B ; combine with column $00 - $1F
LD E,A ; to give the low byte of top line
LD A,C ; column to A range 00000000 to 00011111
AND $18 ; and with 00011000
XOR $40 ; xor with 01000000 (high byte screen start)
LD D,A ; register DE now holds start address of cell.
LD B,$60 ; 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 $FF
; if any other then mismatch
INC A ; set to $00 if inverse
JR NZ,L2573 ; forward to S-SCR-NXT if a mismatch
DEC A ; restore $FF
; a match has been found so seven more to test.
;; S-SC-MTCH
L255A: LD C,A ; load C with inverse mask $00 or $FF
LD B,$07 ; 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 $00 or $FF (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,$80 ; the endpoint of character set
SUB B ; subtract the counter
; to give the code 32-127
LD BC,$0001 ; 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,$0008 ; 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 $00 - $17 (max 00010111)
RRCA ; rotate
RRCA ; bits
RRCA ; left.
LD C,A ; store in C as an intermediate value.
AND $E0 ; pick up bits 11100000 ( was 00011100 )
XOR B ; combine with column $00 - $1F
LD L,A ; low byte now correct.
LD A,C ; bring back intermediate result from C
AND $03 ; mask to give correct third of
; screen $00 - $02
XOR $58 ; 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. $A8 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 $22, L25B3-$-1 ; $1C offset to S-QUOTE
DEFB '(', L25E8-$-1 ; $4F offset to S-BRACKET
DEFB '.', L268D-$-1 ; $F2 offset to S-DECIMAL
DEFB '+', L25AF-$-1 ; $12 offset to S-U-PLUS
DEFB $A8, L25F5-$-1 ; $56 offset to S-FN
DEFB $A5, L25F8-$-1 ; $57 offset to S-RND
DEFB $A7, L2627-$-1 ; $84 offset to S-PI
DEFB $A6, L2634-$-1 ; $8F offset to S-INKEY$
DEFB $C4, L268D-$-1 ; $E6 offset to S-BIN
DEFB $AA, L2668-$-1 ; $BF offset to S-SCREEN$
DEFB $AB, L2672-$-1 ; $C7 offset to S-ATTR
DEFB $A9, L267B-$-1 ; $CE offset to S-POINT
DEFB $00 ; 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,$0000 ; 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 $22 ; 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 $22 ; 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,$5C3B ; 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 $29 ; 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,($5C76) ; fetch system variable SEED
CALL L2D2B ; routine STACK-BC places on calculator stack
RST 28H ;; FP-CALC ;s.
DEFB $A1 ;;stk-one ;s,1.
DEFB $0F ;;addition ;s+1.
DEFB $34 ;;stk-data ;
DEFB $37 ;;Exponent: $87,
;;Bytes: 1
DEFB $16 ;;(+00,+00,+00) ;s+1,75.
DEFB $04 ;;multiply ;(s+1)*75 = v
DEFB $34 ;;stk-data ;v.
DEFB $80 ;;Bytes: 3
DEFB $41 ;;Exponent $91
DEFB $00,$00,$80 ;;(+00) ;v,65537.
DEFB $32 ;;n-mod-m ;remainder, result.
DEFB $02 ;;delete ;remainder.
DEFB $A1 ;;stk-one ;remainder, 1.
DEFB $03 ;;subtract ;remainder - 1. = rnd
DEFB $31 ;;duplicate ;rnd,rnd.
DEFB $38 ;;end-calc
CALL L2DA2 ; routine FP-TO-BC
LD ($5C76),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 $10 ; 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 $A3 ;;stk-pi/2 pi/2.
DEFB $38 ;;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,$105A ; priority $10, operation code $1A ('read-in')
; +$40 for string result, numeric operand.
; set this up now in case we need to use the
; calculator.
RST 20H ; NEXT-CHAR
CP $23 ; '#' ?
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,$5C3B ; 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,$00 ; 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 $FF
; '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,$0001 ; 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,$01 ; set C length to one
;; S-IK$-STK
L2660: LD B,$00 ; 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 $41 ; 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,$0006 ; six locations required
CALL L1655 ; routine MAKE-ROOM
INC HL ; to first new location
LD (HL),$0E ; insert number marker
INC HL ; address next
EX DE,HL ; make DE destination.
LD HL,($5C65) ; STKEND points to end of stack.
LD C,$05 ; result is five locations lower
AND A ; prepare for true subtraction
SBC HL,BC ; point to start of value.
LD ($5C65),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 $0E ; 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 ($5C5D),HL ; update system variable CH_ADD
;; S-NUMERIC
L26C3: SET 6,(IY+$01) ; 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,($5C3B) ; fetch FLAGS value
CP $C0 ; 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
; $C0 = numeric result, numeric operand. e.g. 'sin'
; $80 = numeric result, string operand. e.g. 'code'
; $40 = string result, numeric operand. e.g. 'str$'
; $00 = string result, string operand. e.g. 'val$'
;; S-NEGATE
L26DF: LD BC,$09DB ; prepare priority 09, operation code $C0 +
; 'negate' ($1B) - bits 6 and 7 set for numeric
; result and numeric operand.
CP $2D ; is it '-' ?
JR Z,L270D ; forward if so to S-PUSH-PO
LD BC,$1018 ; prepare priority $10, operation code 'val$' -
; bits 6 and 7 reset for string result and
; string operand.
CP $AE ; is it 'VAL$' ?
JR Z,L270D ; forward if so to S-PUSH-PO
SUB $AF ; subtract token 'CODE' value to reduce
; functions 'CODE' to 'NOT' although the
; upper range is, as yet, unchecked.
; valid range would be $00 - $14.
JP C,L1C8A ; jump back to REPORT-C with anything else
; 'Nonsense in BASIC'
LD BC,$04F0 ; prepare priority $04, operation $C0 +
; 'not' ($30)
CP $14 ; 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,$10 ; priority $10 for all the rest
ADD A,$DC ; make range $DC - $EF
; $C0 + 'code'($1C) thru 'chr$' ($2F)
LD C,A ; transfer 'function' to C
CP $DF ; 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 $EE ; 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 $28 ; is it '(' ?
JR NZ,L2723 ; forward, if not, to S-OPERTR
BIT 6,(IY+$01) ; 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,$00 ; prepare to add
LD C,A ; possible operator to C
LD HL,L2795 ; Address: $2795 - 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 - $C3 ; $26ED 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,$5C3B ; address FLAGS
LD A,E ; new operation to A register
CP $ED ; is it $C0 + 'usr-no' ($2D) ?
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,$99 ; reset bit 6 and substitute $19 '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 $3F ; 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 $3B ;;fp-calc-2
L2758: DEFB $38 ;;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+$01) ; compare with bits of FLAGS
AND $40 ; 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,$5C3B ; 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+$01) ; 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 $3F ; mask to give true calculator literal
ADD A,$08 ; 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 $10 ; 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 $17 ; 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 $03 - $0F
; 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 '+', $CF ; $C0 + 'addition'
DEFB '-', $C3 ; $C0 + 'subtract'
DEFB '*', $C4 ; $C0 + 'multiply'
DEFB '/', $C5 ; $C0 + 'division'
DEFB '^', $C6 ; $C0 + 'to-power'
DEFB '=', $CE ; $C0 + 'nos-eql'
DEFB '>', $CC ; $C0 + 'no-grtr'
DEFB '<', $CD ; $C0 + 'no-less'
DEFB $C7, $C9 ; '<=' $C0 + 'no-l-eql'
DEFB $C8, $CA ; '>=' $C0 + 'no-gr-eql'
DEFB $C9, $CB ; '<>' $C0 + 'nos-neql'
DEFB $C5, $C7 ; 'OR' $C0 + 'or'
DEFB $C6, $C8 ; 'AND' $C0 + 'no-&-no'
DEFB $00 ; zero end-marker.
; -------------------
; Table of priorities
; -------------------
; This table is indexed with the operation code obtained from the above
; table $C3 - $CF to obtain the priority for the respective operation.
;; tbl-priors
L27B0: DEFB $06 ; '-' opcode $C3
DEFB $08 ; '*' opcode $C4
DEFB $08 ; '/' opcode $C5
DEFB $0A ; '^' opcode $C6
DEFB $02 ; 'OR' opcode $C7
DEFB $03 ; 'AND' opcode $C8
DEFB $05 ; '<=' opcode $C9
DEFB $05 ; '>=' opcode $CA
DEFB $05 ; '<>' opcode $CB
DEFB $05 ; '>' opcode $CC
DEFB $05 ; '<' opcode $CD
DEFB $05 ; '=' opcode $CE
DEFB $06 ; '+' opcode $CF
; ----------------------
; 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 $24 ; 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 $28 ; is '(' ?
JR NZ,L27E6 ; forward to SF-RPRT-C if not
; 'Nonsense in BASIC'
RST 20H ; NEXT-CHAR
CP $29 ; 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 $2C ; 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 $29 ; 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,$5C3B ; 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 $DF ; AND 11101111 - reset bit 5 - upper-case.
LD B,A ; save in B
RST 20H ; NEXT-CHAR
SUB $24 ; 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,($5C53) ; fetch start of program area from PROG
DEC HL ; the search starting point is the previous
; location.
;; SF-FND-DF
L2808: LD DE,$00CE ; 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 $18 ; 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 $DF ; 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 $24 ; 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,$0200 ; 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 ($5C5D),DE ; save in CH_ADD
CALL L28AB ; routine FN-SKPOVR advances HL past '('
PUSH HL ; save start address in DEF FN ***
CP $29 ; 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 $0E ; is it the number marker
LD D,$40 ; 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,$00 ; 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+$01) ; xor with FLAGS
AND $40 ; 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,($5C65) ; set HL to STKEND location after value
LD BC,$0005 ; five bytes to move
SBC HL,BC ; decrease HL by 5 to point to start.
LD ($5C65),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 $29 ; 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 $2C ; 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 $29 ; is it a ')' also ?
JR Z,L288D ; forward to SF-VALUE if so.
;; REPORT-Q
L288B: RST 08H ; ERROR-1
DEFB $19 ; 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 ($5C5D),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,($5C0B) ; get original DEFADD address
EX (SP),HL ; swap with DEF FN address on stack ***
LD ($5C0B),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 ($5C5D),HL ; set CH_ADD to this
POP HL ; pop the original DEFADD value
LD ($5C0B),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 $21 ; 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+$01) ; 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 $1F ; 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 $28 ; 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 $24 ; 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+$01) ; update FLAGS - signal string result.
;; V-TEST-FN
L28E3: LD A,($5C0C) ; 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 $E0 ; 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,($5C4B) ; set HL to start of variables from VARS
;; V-EACH
L2900: LD A,(HL) ; get first character
AND $7F ; 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 $20 ; is it a space
JR Z,L2913 ; back to V-SPACES until non-space
OR $20 ; 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 $80 ; 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 $28 ; 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,($5C0B) ; set HL to DEFADD
LD A,(HL) ; load the first character
CP $29 ; 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 $60 ; 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 $0E ; 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 $29 ; 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,($5C65) ; set DE to STKEND
CALL L33C0 ; routine MOVE-FP puts parameters on stack.
EX DE,HL ; new free location to HL.
LD ($5C65),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 $28 ; 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 $2C ; 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 $29 ; 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 $29 ; as above ')' could follow the expression
JR Z,L2A48 ; forward to SV-DIM if so
CP $CC ; 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 ($5C5D),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,$0000 ; 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 $C0 ; 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 $29 ; ')' end of subscripts ?
JR Z,L2A48 ; forward to SV-DIM to consider further slice
CP $CC ; 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 $29 ; 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 $02 ; 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,$0005 ; 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 $29 ; is it ')' ?
JR Z,L2A48 ; forward to SV-DIM to consider a separate
; subscript or/and a slice.
CP $2C ; 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 $28 ; is character '(' ?
JR Z,L2A45 ; loop back if so to SV-SLICE
RES 6,(IY+$01) ; 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 $29 ; 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,$0001 ; default the start point to position 1.
RST 18H ; GET-CHAR
POP HL ; pop length to HL as default end point
; and limit.
CP $CC ; 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 $FF 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 $CC ; is it 'TO' after a start ?
JR Z,L2A81 ; to SL-SECOND to evaluate second parameter
CP $29 ; 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 $29 ; 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 $29 ; 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,$0000 ; 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 $FF.
; '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+$01) ; 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+$01) ; 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,($5C65) ; 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 ($5C65),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 $FF, 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 $FF. 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 $00 or $FF 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 $00 or $FF.
SBC A,$00 ; will set to $FF 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,($5C4D) ; fetch system variable DEST to HL.
BIT 1,(IY+$37) ; 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,$0005 ; 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 $20 ; 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 $10 ; is it $00 - $0F ?
JR C,L2B29 ; forward to L-SPACES if so.
CP $16 ; is it $16 - $1F ?
JR NC,L2B29 ; forward to L-SPACES if so.
; it was $10 - $15 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 $24 ; 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,($5C59) ; 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,($5C4D) ; reload HL with DEST.
DEC DE ; point to first.
SUB $06 ; 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 $21 ; is it space or higher ?
JR C,L2B3E ; back to L-CHAR with space and less.
OR $20 ; 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 $80 ; invert the last character.
LD (DE),A ; and overwrite that in edit line.
; now consider first character which has bit 6 set
LD A,$C0 ; 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,($5C4D) ; fetch DEST - HL addresses first character.
XOR (HL) ; apply variable type indicator mask (above).
OR $20 ; 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 $80 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 $02 ;;delete ; delete variable value
DEFB $38 ;;end-calc
; DE (STKEND) points to start of value.
POP HL ; restore the pointer.
LD BC,$0005 ; 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+$01) ; 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,$0006 ; 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,($5C4D) ; fetch DEST to HL.
; (still set from first instruction)
LD BC,($5C72) ; fetch STRLEN to BC.
BIT 0,(IY+$37) ; 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),$20 ; 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,$DF ; indicator mask %11011111 for
; %010xxxxx will be result
LD HL,($5C4D) ; 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 ($5C4D),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,($5C59) ; 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,($5C4D) ; 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,($5C59) ; 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,($5C65) ; 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 ($5C65),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 $80 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,$00 ; initialize dimensions to zero and
PUSH BC ; save with the type.
LD HL,$0001 ; make elements one character presuming string
BIT 6,C ; is it a string ?
JR NZ,L2C2D ; forward to D-SIZE if so.
LD L,$05 ; 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,$FF ; 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 $2C ; is it ',' ?
JR Z,L2C2E ; loop back to D-NO-LOOP until all dimensions
; have been considered
; when loop complete continue.
CP $29 ; 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,$00 ; 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,($5C59) ; address E_LINE - first location after
; variables area
DEC HL ; point to location before - the $80 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),$00 ; 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),$20 ; 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 $41 ; less than 'A' ?
CCF ; Complement Carry Flag
RET NC ; return if so
CP $5B ; less than 'Z'+1 ?
RET C ; is within first range
CP $61 ; less than 'a' ?
CCF ; Complement Carry Flag
RET NC ; return if so.
CP $7B ; 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 $C4 ; 'BIN' token ?
JR NZ,L2CB8 ; to NOT-BIN if not
LD DE,$0000 ; initialize 16 bit buffer register.
;; BIN-DIGIT
L2CA2: RST 20H ; NEXT-CHAR
SUB $31 ; '1'
ADC A,$00 ; 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 $2E ; '.' - 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 $2E ; '.' - 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 $A0 ;;stk-zero ; 0.
DEFB $38 ;;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 $A1 ;;stk-one ;x or 0,1.
DEFB $C0 ;;st-mem-0 ;x or 0,1.
DEFB $02 ;;delete ;x or 0.
DEFB $38 ;;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 $E0 ;;get-mem-0 ;x or 0,d,1.
DEFB $A4 ;;stk-ten ;x or 0,d,1,10.
DEFB $05 ;;division ;x or 0,d,1/10.
DEFB $C0 ;;st-mem-0 ;x or 0,d,1/10.
DEFB $04 ;;multiply ;x or 0,d/10.
DEFB $0F ;;addition ;x or 0 + d/10.
DEFB $38 ;;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 $45 ; is character 'E' ?
JR Z,L2CF2 ; to SIGN-FLAG if so
CP $65 ; 'e' is acceptable as well.
RET NZ ; return as no exponent.
;; SIGN-FLAG
L2CF2: LD B,$FF ; initialize temporary sign byte to $FF
RST 20H ; NEXT-CHAR
CP $2B ; is character '+' ?
JR Z,L2CFE ; to SIGN-DONE
CP $2D ; 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 ; $FF to $00 or $00 to $01 - 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 $30 ; '0'
RET C ; return if less than zero character.
CP $3A ; 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 $30 ; convert from ASCII to digit
; -----------------
; Stack accumulator
; -----------------
;
;
;; STACK-A
L2D28: LD C,A ; transfer to C
LD B,$00 ; and make B zero
; ----------------------
; Stack BC register pair
; ----------------------
;
;; STACK-BC
L2D2B: LD IY,$5C3A ; 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 $38 ;;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 $A0 ;;stk-zero ; v=0. initial value
DEFB $38 ;;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 $01 ;;exchange ; d, v.
DEFB $A4 ;;stk-ten ; d, v, 10.
DEFB $04 ;;multiply ; d, v*10.
DEFB $0F ;;addition ; d + v*10 = newvalue
DEFB $38 ;;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,$5C92 ; 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 $A4 ;;stk-ten x, 10.
DEFB $38 ;;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 $C1 ;;st-mem-1 x, 10.
DEFB $E0 ;;get-mem-0 x, 10, (0/1).
DEFB $00 ;;jump-true
DEFB $04 ;;to L2D6D, E-DIVSN
DEFB $04 ;;multiply x*10.
DEFB $33 ;;jump
DEFB $02 ;;to L2D6E, E-FETCH
;; E-DIVSN
L2D6D: DEFB $05 ;;division x/10.
;; E-FETCH
L2D6E: DEFB $E1 ;;get-mem-1 x/10 or x*10, 10.
DEFB $38 ;;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 $31 ;;duplicate new x, 10, 10.
DEFB $04 ;;multiply new x, 100.
DEFB $38 ;;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 $02 ;;delete final x.
DEFB $38 ;;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,$00 ; 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 $00 +ve or $FF -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),$00 ; 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),$00 ; 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 $38 ;;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 $A2 ;;stk-half x. 1/2.
DEFB $0F ;;addition x + 1/2.
DEFB $27 ;;int int(x + .5)
DEFB $38 ;;end-calc
; now delete but leave HL pointing at integer
;; FP-DELETE
L2DAD: RST 28H ;; FP-CALC
DEFB $02 ;;delete
DEFB $38 ;;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 $FF if negative or $00
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 $34 ;;stk-data .30103 (log 2)
DEFB $EF ;;Exponent: $7F, Bytes: 4
DEFB $1A,$20,$9A,$85 ;;
DEFB $04 ;;multiply
DEFB $27 ;;int
DEFB $38 ;;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 $31 ;;duplicate
DEFB $36 ;;less-0
DEFB $00 ;;jump-true
DEFB $0B ;;to L2DF2, PF-NEGTVE
DEFB $31 ;;duplicate
DEFB $37 ;;greater-0
DEFB $00 ;;jump-true
DEFB $0D ;;to L2DF8, PF-POSTVE
; must be zero itself
DEFB $02 ;;delete
DEFB $38 ;;end-calc
LD A,$30 ; prepare the character '0'
RST 10H ; PRINT-A
RET ; return. ->
; ---
;; PF-NEGTVE
L2DF2: DEFB $2A ;;abs
DEFB $38 ;;end-calc
LD A,$2D ; the character '-'
RST 10H ; PRINT-A
; and continue to print the now positive number.
RST 28H ;; FP-CALC
;; PF-POSTVE
L2DF8: DEFB $A0 ;;stk-zero x,0. begin by
DEFB $C3 ;;st-mem-3 x,0. clearing a temporary
DEFB $C4 ;;st-mem-4 x,0. output buffer to
DEFB $C5 ;;st-mem-5 x,0. fifteen zeros.
DEFB $02 ;;delete x.
DEFB $38 ;;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 $31 ;;duplicate x,x.
DEFB $27 ;;int x,int x.
DEFB $C2 ;;st-mem-2 x,int x.
DEFB $03 ;;subtract x-int x. fractional part.
DEFB $E2 ;;get-mem-2 x-int x, int x.
DEFB $01 ;;exchange int x, x-int x.
DEFB $C2 ;;st-mem-2 int x, x-int x.
DEFB $02 ;;delete int x.
DEFB $38 ;;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,$10 ; 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,$08 ; 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 $E2 ;;get-mem-2 int x = 0, x-int x.
DEFB $38 ;;end-calc
LD A,(HL) ; fetch exponent of positive fractional number
SUB $7E ; subtract
CALL L2DC1 ; routine LOG(2^A) calculates leading digits.
LD D,A ; transfer count to D
LD A,($5CAC) ; fetch total MEM-5-1
SUB D ;
LD ($5CAC),A ; MEM-5-1
LD A,D ;
CALL L2D4F ; routine E-TO-FP
RST 28H ;; FP-CALC
DEFB $31 ;;duplicate
DEFB $27 ;;int
DEFB $C1 ;;st-mem-1
DEFB $03 ;;subtract
DEFB $E1 ;;get-mem-1
DEFB $38 ;;end-calc
CALL L2DD5 ; routine FP-TO-A
PUSH HL ; save HL
LD ($5CA1),A ; MEM-3-1
DEC A ;
RLA ;
SBC A,A ;
INC A ;
LD HL,$5CAB ; 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 $80 ; make exponent positive
CP $1C ; compare to 28
JR C,L2E6F ; to PF-MEDIUM if integer <= 2^27
CALL L2DC1 ; routine LOG(2^A)
SUB $07 ;
LD B,A ;
LD HL,$5CAC ; 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 $80 ;
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,$5CAA ; set HL to mem-4-5th last byte of buffer
LD C,$05 ; 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,$5CA6 ; address MEM-4-0 byte destination.
LD DE,$5CA1 ; address MEM-3-0 nibble source.
LD B,$09 ; 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,$FF ; 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 $FF
; 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+$71) ; increment MEM-5-1st digit counter
INC (IY+$72) ; increment MEM-5-2nd leading digit counter
LD C,$00 ; 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,($5CAB) ; fetch digit count from MEM-5-1st
SUB $09 ; subtract 9 - max possible
JR C,L2ECB ; forward if less to PF-MORE
DEC (IY+$71) ; decrement digit counter MEM-5-1st to 8
LD A,$04 ; load A with the value 4.
CP (IY+$6F) ; 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 $02 ;;delete .
DEFB $E2 ;;get-mem-2 x - int x = f.
DEFB $38 ;;end-calc f.
;; PF-FRACTN
L2ECF: EX DE,HL ;
CALL L2FBA ; routine FETCH-TWO
EXX ;
LD A,$80 ;
SUB L ;
LD L,$00 ;
SET 7,D ;
EXX ;
CALL L2FDD ; routine SHIFT-FP
;; PF-FRN-LP
L2EDF: LD A,(IY+$71) ; MEM-5-1st
CP $08 ;
JR C,L2EEC ; to PF-FR-DGT
EXX ;
RL D ;
EXX ;
JR L2F0C ; to PF-ROUND
; ---
;; PF-FR-DGT
L2EEC: LD BC,$0200 ;
;; 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,$5CA1 ; MEM-3
LD A,C ;
LD C,(IY+$71) ; MEM-5-1st
ADD HL,BC ;
LD (HL),A ;
INC (IY+$71) ; 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,$5CA1 ; address MEM-3 start of digits
LD C,(IY+$71) ; MEM-5-1st No. of digits to C
LD B,$00 ; 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,$00 ; add carry from the comparison
LD (HL),A ; put back result even if $0A.
AND A ; test A
JR Z,L2F25 ; skip to PF-R-BACK if ZERO?
CP $0A ; 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 $0A.
LD (HL),$01 ; load first location with digit 1.
INC B ; make B hold 1 also.
; could save an instruction byte here.
INC (IY+$72) ; make MEM-5-2nd hold 1.
; and proceed to initialize total digits to 1.
;; PF-COUNT
L2F2D: LD (IY+$71),B ; MEM-5-1st
; now balance the calculator stack by deleting it
RST 28H ;; FP-CALC
DEFB $02 ;;delete
DEFB $38 ;;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,($5CAB) ; set C to MEM-5-1st digit counter.
; set B to MEM-5-2nd leading digit counter.
LD HL,$5CA1 ; set HL to start of digits at MEM-3-1
LD A,B ;
CP $09 ;
JR C,L2F46 ; to PF-NOT-E
CP $FC ;
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,$2E ; prepare the character '.'
;; PF-DEC-0S
L2F64: RST 10H ; PRINT-A outputs the character '.' or '0'
LD A,$30 ; 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,$01 ; load B with 1.
CALL L2F4A ; routine PF-E-SBRN above
LD A,$45 ; 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,$2D ; prepare character '-'
JR L2F85 ; skip to PF-E-SIGN
; ---
;; PF-E-POS
L2F83: LD A,$2B ; prepare character '+'
;; PF-E-SIGN
L2F85: RST 10H ; PRINT-A outputs the sign
LD B,$00 ; 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,$00 ; 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),$00 ; 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,$0005 ; 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,$00 ; 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 $21 ;
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,$00 ;
LD D,A ;
LD E,L ;
EXX ;
LD DE,$0000 ;
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, $00 or $FF
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,$00 ; 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,$01 ;
CALL L2FDD ; routine SHIFT-FP
INC (HL) ;
JR Z,L309F ; to ADD-REP-6
;; TEST-NEG
L307C: EXX ;
LD A,L ;
AND $80 ;
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,$00 ;
LD D,A ;
EXX ;
LD A,E ;
CPL ;
ADC A,$00 ;
LD E,A ;
LD A,D ;
CPL ;
ADC A,$00 ;
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,$10 ; set B to 16
LD A,H ; save H in A high byte
LD C,L ; save L in C low byte
LD HL,$0000 ; 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: $04 '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,$21 ;
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,$80 ;
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,$20 ;
;; 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,$80 ;
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 $05 ; Error Report: Number too big
; ----------------------
; THE 'DIVISION' ROUTINE
; ----------------------
; (offset: $05 '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,$DF ;
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 ($3A)
; ------------------------------------
;
;
;; truncate
L3214: LD A,(HL) ;
AND A ;
RET Z ;
CP $81 ;
JR NC,L3221 ; to T-GR-ZERO
LD (HL),$00 ;
LD A,$20 ;
JR L3272 ; to NIL-BYTES
; ---
;; T-GR-ZERO
L3221: CP $91 ;
JR NZ,L323F ; to T-SMALL
INC HL ;
INC HL ;
INC HL ;
LD A,$80 ;
AND (HL) ;
DEC HL ;
OR (HL) ;
DEC HL ;
JR NZ,L3233 ; to T-FIRST
LD A,$80 ;
XOR (HL) ;
;; T-FIRST
L3233: DEC HL ;
JR NZ,L326C ; to T-EXPNENT
LD (HL),A ;
INC HL ;
LD (HL),$FF ;
DEC HL ;
LD A,$18 ;
JR L3272 ; to NIL-BYTES
; ---
;; T-SMALL
L323F: JR NC,L326D ; to X-LARGE
PUSH DE ;
CPL ;
ADD A,$91 ;
INC HL ;
LD D,(HL) ;
INC HL ;
LD E,(HL) ;
DEC HL ;
DEC HL ;
LD C,$00 ;
BIT 7,D ;
JR Z,L3252 ; to T-NUMERIC
DEC C ;
;; T-NUMERIC
L3252: SET 7,D ;
LD B,$08 ;
SUB B ;
ADD A,B ;
JR C,L325E ; to T-TEST
LD E,D ;
LD D,$00 ;
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 $A0 ;
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),$00 ;
DEC HL ;
DJNZ L327E ; to BYTE-ZERO
;; BITS-ZERO
L3283: AND $07 ;
JR Z,L3290 ; to IX-END
LD B,A ;
LD A,$FF ;
;; 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, $00 +ve, $FF -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: $3D '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,$91 ; set exponent byte +ve $81
; 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,$89 ; 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 $00 or $FF
; 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 $00 ;;Bytes: 1
DEFB $B0 ;;Exponent $00
DEFB $00 ;;(+00,+00,+00)
; used 19 times
;; stk-one 00 00 01 00 00
L32C8: DEFB $40 ;;Bytes: 2
DEFB $B0 ;;Exponent $00
DEFB $00,$01 ;;(+00,+00)
; used 9 times
;; stk-half 80 00 00 00 00
L32CC: DEFB $30 ;;Exponent: $80, Bytes: 1
DEFB $00 ;;(+00,+00,+00)
; used 4 times.
;; stk-pi/2 81 49 0F DA A2
L32CE: DEFB $F1 ;;Exponent: $81, Bytes: 4
DEFB $49,$0F,$DA,$A2 ;;
; used 3 times.
;; stk-ten 00 00 0A 00 00
L32D3: DEFB $40 ;;Bytes: 2
DEFB $B0 ;;Exponent $00
DEFB $00,$0A ;;(+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 ; $00 Address: $368F - jump-true
DEFW L343C ; $01 Address: $343C - exchange
DEFW L33A1 ; $02 Address: $33A1 - delete
; True binary operations.
DEFW L300F ; $03 Address: $300F - subtract
DEFW L30CA ; $04 Address: $30CA - multiply
DEFW L31AF ; $05 Address: $31AF - division
DEFW L3851 ; $06 Address: $3851 - to-power
DEFW L351B ; $07 Address: $351B - or
DEFW L3524 ; $08 Address: $3524 - no-&-no
DEFW L353B ; $09 Address: $353B - no-l-eql
DEFW L353B ; $0A Address: $353B - no-gr-eql
DEFW L353B ; $0B Address: $353B - nos-neql
DEFW L353B ; $0C Address: $353B - no-grtr
DEFW L353B ; $0D Address: $353B - no-less
DEFW L353B ; $0E Address: $353B - nos-eql
DEFW L3014 ; $0F Address: $3014 - addition
DEFW L352D ; $10 Address: $352D - str-&-no
DEFW L353B ; $11 Address: $353B - str-l-eql
DEFW L353B ; $12 Address: $353B - str-gr-eql
DEFW L353B ; $13 Address: $353B - strs-neql
DEFW L353B ; $14 Address: $353B - str-grtr
DEFW L353B ; $15 Address: $353B - str-less
DEFW L353B ; $16 Address: $353B - strs-eql
DEFW L359C ; $17 Address: $359C - strs-add
; Unary follow.
DEFW L35DE ; $18 Address: $35DE - val$
DEFW L34BC ; $19 Address: $34BC - usr-$
DEFW L3645 ; $1A Address: $3645 - read-in
DEFW L346E ; $1B Address: $346E - negate
DEFW L3669 ; $1C Address: $3669 - code
DEFW L35DE ; $1D Address: $35DE - val
DEFW L3674 ; $1E Address: $3674 - len
DEFW L37B5 ; $1F Address: $37B5 - sin
DEFW L37AA ; $20 Address: $37AA - cos
DEFW L37DA ; $21 Address: $37DA - tan
DEFW L3833 ; $22 Address: $3833 - asn
DEFW L3843 ; $23 Address: $3843 - acs
DEFW L37E2 ; $24 Address: $37E2 - atn
DEFW L3713 ; $25 Address: $3713 - ln
DEFW L36C4 ; $26 Address: $36C4 - exp
DEFW L36AF ; $27 Address: $36AF - int
DEFW L384A ; $28 Address: $384A - sqr
DEFW L3492 ; $29 Address: $3492 - sgn
DEFW L346A ; $2A Address: $346A - abs
DEFW L34AC ; $2B Address: $34AC - peek
DEFW L34A5 ; $2C Address: $34A5 - in
DEFW L34B3 ; $2D Address: $34B3 - usr-no
DEFW L361F ; $2E Address: $361F - str$
DEFW L35C9 ; $2F Address: $35C9 - chrs
DEFW L3501 ; $30 Address: $3501 - not
; End of true unary.
DEFW L33C0 ; $31 Address: $33C0 - duplicate
DEFW L36A0 ; $32 Address: $36A0 - n-mod-m
DEFW L3686 ; $33 Address: $3686 - jump
DEFW L33C6 ; $34 Address: $33C6 - stk-data
DEFW L367A ; $35 Address: $367A - dec-jr-nz
DEFW L3506 ; $36 Address: $3506 - less-0
DEFW L34F9 ; $37 Address: $34F9 - greater-0
DEFW L369B ; $38 Address: $369B - end-calc
DEFW L3783 ; $39 Address: $3783 - get-argt
DEFW L3214 ; $3A Address: $3214 - truncate
DEFW L33A2 ; $3B Address: $33A2 - fp-calc-2
DEFW L2D4F ; $3C Address: $2D4F - e-to-fp
DEFW L3297 ; $3D Address: $3297 - re-stack
; The following are just the next available slots for the 128 compound
; literals which are in range $80 - $FF.
DEFW L3449 ; Address: $3449 - series-xx $80 - $9F.
DEFW L341B ; Address: $341B - stk-const-xx $A0 - $BF.
DEFW L342D ; Address: $342D - st-mem-xx $C0 - $DF.
DEFW L340F ; Address: $340F - get-mem-xx $E0 - $FF.
; 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 ($5C67),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 ($5C65),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 $00 - $3D
; 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 $00 - $1F.
; 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 $60 ; 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,$7C ; add ($3E * 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 $1F ; use mask to isolate parameter bits
JR L338E ; forward to ENT-TABLE
; ---
; the branch was here with simple literals.
;; FIRST-3D
L3380: CP $18 ; compare with first unary operations.
JR NC,L338C ; to DOUBLE-A with unary operations
; it is binary so adjust pointers.
EXX ;
LD BC,$FFFB ; 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,$00 ; 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,($5C66) ; 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,($5C67) ; 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,$0005 ; 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,($5C65) ; Load destination from STKEND system variable.
CALL L33C0 ; Routine MOVE-FP puts on calculator stack
; with a memory check.
LD ($5C65),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 ($34)
; -------------------
; 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 $05.
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 $C0 ; isolate bits 7 and 6
RLCA ; rotate
RLCA ; to bits 1 and 0 range $00 - $03.
LD C,A ; transfer to C
INC C ; and increment to give number of bytes
; to read. $01 - $04
LD A,(HL) ; reload the first byte
AND $3F ; 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 ( - $50).
;; FORM-EXP
L33DE: ADD A,$50 ; now add $50 to form actual exponent
LD (DE),A ; and load into first destination byte.
LD A,$05 ; load accumulator with $05 and
SUB C ; subtract C to give count of trailing
; zeros plus one.
INC HL ; increment source
INC DE ; increment destination
LD B,$00 ; 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, $0000
; 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,$0000 ; 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 $00-$1F.
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,$00 ; set high byte to zero.
ADD HL,BC ; add to form address of start of number in HL.
RET ; return.
; ------------------------------
; Get from memory area ($E0 etc.)
; ------------------------------
; Literals $E0 to $FF
; A holds $00-$1F offset.
; The calculator stack increases by 5 bytes.
;; get-mem-xx
L340F: PUSH DE ; save STKEND
LD HL,($5C68) ; 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 ($C0 etc.)
; --------------------------------
; Offsets $C0 to $DF
; Although 32 memory storage locations can be addressed, only six
; $C0 to $C5 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 $00-$1F.
; 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,($5C68) ; 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: $01 '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,$05 ; 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: $86 'series-06')
; (offset: $88 'series-08')
; (offset: $8C '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 $00 - $1F 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 $31 ;;duplicate x,x
DEFB $0F ;;addition x+x
DEFB $C0 ;;st-mem-0 x+x
DEFB $02 ;;delete .
DEFB $A0 ;;stk-zero 0
DEFB $C2 ;;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 $31 ;;duplicate v,v.
DEFB $E0 ;;get-mem-0 v,v,x+2
DEFB $04 ;;multiply v,v*x+2
DEFB $E2 ;;get-mem-2 v,v*x+2,v
DEFB $C1 ;;st-mem-1
DEFB $03 ;;subtract
DEFB $38 ;;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 $0F ;;addition
DEFB $01 ;;exchange
DEFB $C2 ;;st-mem-2
DEFB $02 ;;delete
DEFB $35 ;;dec-jr-nz
DEFB $EE ;;back to L3453, G-LOOP
; when the counted loop is complete the final subtraction yields the result
; for example SIN X.
DEFB $E1 ;;get-mem-1
DEFB $03 ;;subtract
DEFB $38 ;;end-calc
RET ; return with H'L' pointing to location
; after last number in series.
; ---------------------------------
; THE 'ABSOLUTE MAGNITUDE' FUNCTION
; ---------------------------------
; (offset: $2A 'abs')
; This calculator literal finds the absolute value of the last value,
; integer or floating point, on calculator stack.
;; abs
L346A: LD B,$FF ; signal abs
JR L3474 ; forward to NEG-TEST
; ---------------------------
; THE 'UNARY MINUS' OPERATION
; ---------------------------
; (offset: $1B '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,$00 ; 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 $FF=abs, $00=neg.
AND $80 ; now $80 $00
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 ; $FF=abs, $00=neg
OR C ; $FF for abs, no change neg
CPL ; $00 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: $29 '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,$0001 ; 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 $FF if negative, $00 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: $2C '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: $2B '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: $19 '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 $90 ; make UDGs range 0-20d
JR C,L34E7 ; to REPORT-A if too low. e.g. usr " ".
CP $15 ; 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 $A8 ; compare to 21*8
JR NC,L34E7 ; to REPORT-A if originally higher
; than 'U','u' or graphics U.
LD BC,($5C7B) ; 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 $09 ; 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: $37 '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,$FF ; 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: $30 '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: $36 '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,$00 ; 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: $07 '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: $08 '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: $10 '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: $0A 'no-gr-eql')
; (offset: $0B 'nos-neql')
; (offset: $0C 'no-grtr')
; (offset: $0D 'no-less')
; (offset: $0E 'nos-eql')
; (offset: $11 'str-l-eql')
; (offset: $12 'str-gr-eql')
; (offset: $13 'strs-neql')
; (offset: $14 'str-grtr')
; (offset: $15 'str-less')
; (offset: $16 '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 $08 ; subtract eight - which is not useful.
BIT 2,A ; isolate '>', '<', '='.
JR NZ,L3543 ; skip to EX-OR-NOT with these.
DEC A ; else make $00-$02, $08-$0A 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 $A0 ;;stk-zero an initial false value.
DEFB $38 ;;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: $17 '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,($5C65) ; fetch STKEND value from system variable.
LD DE,$FFFB ; 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,$0001 ; 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 $0A ; Error Report: Integer out of range
; ----------------------------
; THE 'VAL and VAL$' FUNCTIONS
; ----------------------------
; (offset: $1d 'val')
; (offset: $18 '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,($5C5D) ; fetch value of system variable CH_ADD
PUSH HL ; and save on the machine stack.
LD A,B ; fetch the literal (either $1D or $18).
ADD A,$E3 ; add $E3 to form $00 (setting carry) or $FB.
SBC A,A ; now form $FF bit 6 = numeric result
; or $00 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 ($5C5D),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),$0D ; insert a carriage return at end.
RES 7,(IY+$01) ; update FLAGS - signal checking syntax.
CALL L24FB ; routine SCANNING evaluates string
; expression and result.
RST 18H ; GET-CHAR fetches next character.
CP $0D ; 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+$01) ; xor with FLAGS now updated by SCANNING.
AND $40 ; 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 ($5C5D),HL ; set CH_ADD to the start of the string again.
SET 7,(IY+$01) ; 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 ($5C5D),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,$0001 ; create an initial byte in workspace
RST 30H ; using BC-SPACES restart.
LD ($5C5B),HL ; set system variable K_CUR to new location.
PUSH HL ; and save start on machine stack also.
LD HL,($5C51) ; fetch value of system variable CURCHL
PUSH HL ; and save that too.
LD A,$FF ; 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,($5C5B) ; 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 $10 ; 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,($5C51) ; 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,$0000 ; 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: $35 '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,$5C67 ; 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: $33 '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 $FF if backward or $00 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: $00 '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: $38 '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: $32 '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 $C0 ;;st-mem-0 17, 3.
DEFB $02 ;;delete 17.
DEFB $31 ;;duplicate 17, 17.
DEFB $E0 ;;get-mem-0 17, 17, 3.
DEFB $05 ;;division 17, 17/3.
DEFB $27 ;;int 17, 5.
DEFB $E0 ;;get-mem-0 17, 5, 3.
DEFB $01 ;;exchange 17, 3, 5.
DEFB $C0 ;;st-mem-0 17, 3, 5.
DEFB $04 ;;multiply 17, 15.
DEFB $03 ;;subtract 2.
DEFB $E0 ;;get-mem-0 2, 5.
DEFB $38 ;;end-calc 2, 5.
RET ; return.
; ------------------
; THE 'INT' FUNCTION
; ------------------
; (offset $27: '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 $31 ;;duplicate x, x.
DEFB $36 ;;less-0 x, (1/0)
DEFB $00 ;;jump-true x, (1/0)
DEFB $04 ;;to L36B7, X-NEG
DEFB $3A ;;truncate trunc 3.4 = 3.
DEFB $38 ;;end-calc 3.
RET ; return with + int x on stack.
; ---
;; X-NEG
L36B7: DEFB $31 ;;duplicate -3.4, -3.4.
DEFB $3A ;;truncate -3.4, -3.
DEFB $C0 ;;st-mem-0 -3.4, -3.
DEFB $03 ;;subtract -.4
DEFB $E0 ;;get-mem-0 -.4, -3.
DEFB $01 ;;exchange -3, -.4.
DEFB $30 ;;not -3, (0).
DEFB $00 ;;jump-true -3.
DEFB $03 ;;to L36C2, EXIT -3.
DEFB $A1 ;;stk-one -3, 1.
DEFB $03 ;;subtract -4.
;; EXIT
L36C2: DEFB $38 ;;end-calc -4.
RET ; return.
; ------------------
; THE 'EXP' FUNCTION
; ------------------
; (offset $26: '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 $3D ;;re-stack (not required - mult will do)
DEFB $34 ;;stk-data
DEFB $F1 ;;Exponent: $81, Bytes: 4
DEFB $38,$AA,$3B,$29 ;;
DEFB $04 ;;multiply
DEFB $31 ;;duplicate
DEFB $27 ;;int
DEFB $C3 ;;st-mem-3
DEFB $03 ;;subtract
DEFB $31 ;;duplicate
DEFB $0F ;;addition
DEFB $A1 ;;stk-one
DEFB $03 ;;subtract
DEFB $88 ;;series-08
DEFB $13 ;;Exponent: $63, Bytes: 1
DEFB $36 ;;(+00,+00,+00)
DEFB $58 ;;Exponent: $68, Bytes: 2
DEFB $65,$66 ;;(+00,+00)
DEFB $9D ;;Exponent: $6D, Bytes: 3
DEFB $78,$65,$40 ;;(+00)
DEFB $A2 ;;Exponent: $72, Bytes: 3
DEFB $60,$32,$C9 ;;(+00)
DEFB $E7 ;;Exponent: $77, Bytes: 4
DEFB $21,$F7,$AF,$24 ;;
DEFB $EB ;;Exponent: $7B, Bytes: 4
DEFB $2F,$B0,$B0,$14 ;;
DEFB $EE ;;Exponent: $7E, Bytes: 4
DEFB $7E,$BB,$94,$58 ;;
DEFB $F1 ;;Exponent: $81, Bytes: 4
DEFB $3A,$7E,$F8,$CF ;;
DEFB $E3 ;;get-mem-3
DEFB $38 ;;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 $05 ; 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 $02 ;;delete
DEFB $A0 ;;stk-zero
DEFB $38 ;;end-calc
RET ; return.
; --------------------------------
; THE 'NATURAL LOGARITHM' FUNCTION
; --------------------------------
; (offset $25: '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 $3D ;;re-stack
DEFB $31 ;;duplicate
DEFB $37 ;;greater-0
DEFB $00 ;;jump-true
DEFB $04 ;;to L371C, VALID
DEFB $38 ;;end-calc
;; REPORT-Ab
L371A: RST 08H ; ERROR-1
DEFB $09 ; Error Report: Invalid argument
;; VALID
L371C: DEFB $A0 ;;stk-zero Note. not
DEFB $02 ;;delete necessary.
DEFB $38 ;;end-calc
LD A,(HL) ;
LD (HL),$80 ;
CALL L2D28 ; routine STACK-A
RST 28H ;; FP-CALC
DEFB $34 ;;stk-data
DEFB $38 ;;Exponent: $88, Bytes: 1
DEFB $00 ;;(+00,+00,+00)
DEFB $03 ;;subtract
DEFB $01 ;;exchange
DEFB $31 ;;duplicate
DEFB $34 ;;stk-data
DEFB $F0 ;;Exponent: $80, Bytes: 4
DEFB $4C,$CC,$CC,$CD ;;
DEFB $03 ;;subtract
DEFB $37 ;;greater-0
DEFB $00 ;;jump-true
DEFB $08 ;;to L373D, GRE.8
DEFB $01 ;;exchange
DEFB $A1 ;;stk-one
DEFB $03 ;;subtract
DEFB $01 ;;exchange
DEFB $38 ;;end-calc
INC (HL) ;
RST 28H ;; FP-CALC
;; GRE.8
L373D: DEFB $01 ;;exchange
DEFB $34 ;;stk-data
DEFB $F0 ;;Exponent: $80, Bytes: 4
DEFB $31,$72,$17,$F8 ;;
DEFB $04 ;;multiply
DEFB $01 ;;exchange
DEFB $A2 ;;stk-half
DEFB $03 ;;subtract
DEFB $A2 ;;stk-half
DEFB $03 ;;subtract
DEFB $31 ;;duplicate
DEFB $34 ;;stk-data
DEFB $32 ;;Exponent: $82, Bytes: 1
DEFB $20 ;;(+00,+00,+00)
DEFB $04 ;;multiply
DEFB $A2 ;;stk-half
DEFB $03 ;;subtract
DEFB $8C ;;series-0C
DEFB $11 ;;Exponent: $61, Bytes: 1
DEFB $AC ;;(+00,+00,+00)
DEFB $14 ;;Exponent: $64, Bytes: 1
DEFB $09 ;;(+00,+00,+00)
DEFB $56 ;;Exponent: $66, Bytes: 2
DEFB $DA,$A5 ;;(+00,+00)
DEFB $59 ;;Exponent: $69, Bytes: 2
DEFB $30,$C5 ;;(+00,+00)
DEFB $5C ;;Exponent: $6C, Bytes: 2
DEFB $90,$AA ;;(+00,+00)
DEFB $9E ;;Exponent: $6E, Bytes: 3
DEFB $70,$6F,$61 ;;(+00)
DEFB $A1 ;;Exponent: $71, Bytes: 3
DEFB $CB,$DA,$96 ;;(+00)
DEFB $A4 ;;Exponent: $74, Bytes: 3
DEFB $31,$9F,$B4 ;;(+00)
DEFB $E7 ;;Exponent: $77, Bytes: 4
DEFB $A0,$FE,$5C,$FC ;;
DEFB $EA ;;Exponent: $7A, Bytes: 4
DEFB $1B,$43,$CA,$36 ;;
DEFB $ED ;;Exponent: $7D, Bytes: 4
DEFB $A7,$9C,$7E,$5E ;;
DEFB $F0 ;;Exponent: $80, Bytes: 4
DEFB $6E,$23,$80,$93 ;;
DEFB $04 ;;multiply
DEFB $0F ;;addition
DEFB $38 ;;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 $39: '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 $3D ;;re-stack (not rquired done by mult)
DEFB $34 ;;stk-data
DEFB $EE ;;Exponent: $7E,
;;Bytes: 4
DEFB $22,$F9,$83,$6E ;; X, 1/(2*PI)
DEFB $04 ;;multiply X/(2*PI) = fraction
DEFB $31 ;;duplicate
DEFB $A2 ;;stk-half
DEFB $0F ;;addition
DEFB $27 ;;int
DEFB $03 ;;subtract now range -.5 to .5
DEFB $31 ;;duplicate
DEFB $0F ;;addition now range -1 to 1.
DEFB $31 ;;duplicate
DEFB $0F ;;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 $31 ;;duplicate Y, Y.
DEFB $2A ;;abs Y, abs(Y). range 1 to 2
DEFB $A1 ;;stk-one Y, abs(Y), 1.
DEFB $03 ;;subtract Y, abs(Y)-1. range 0 to 1
DEFB $31 ;;duplicate Y, Z, Z.
DEFB $37 ;;greater-0 Y, Z, (1/0).
DEFB $C0 ;;st-mem-0 store as possible sign
;; for cosine function.
DEFB $00 ;;jump-true
DEFB $04 ;;to L37A1, ZPLUS with quadrants II and III.
; else the angle lies in quadrant I or IV and value Y is already correct.
DEFB $02 ;;delete Y. delete the test value.
DEFB $38 ;;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 $A1 ;;stk-one Y, Z, 1.
DEFB $03 ;;subtract Y, Z-1. Q3 = 0 to -1
DEFB $01 ;;exchange Z-1, Y.
DEFB $36 ;;less-0 Z-1, (1/0).
DEFB $00 ;;jump-true Z-1.
DEFB $02 ;;to L37A8, YNEG
;;if angle in quadrant III
; else angle is within quadrant II (-1 to 0)
DEFB $1B ;;negate range +1 to 0.
;; YNEG
L37A8: DEFB $38 ;;end-calc quadrants II and III correct.
RET ; return.
; ---------------------
; THE 'COSINE' FUNCTION
; ---------------------
; (offset $20: '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 $39 ;;get-argt X reduce -1 to +1
DEFB $2A ;;abs ABS X. 0 to 1
DEFB $A1 ;;stk-one ABS X, 1.
DEFB $03 ;;subtract now opposite angle
;; although sign is -ve.
DEFB $E0 ;;get-mem-0 fetch the sign indicator
DEFB $00 ;;jump-true
DEFB $06 ;;fwd to L37B7, C-ENT
;;forward to common code if in QII or QIII.
DEFB $1B ;;negate else make sign +ve.
DEFB $33 ;;jump
DEFB $03 ;;fwd to L37B7, C-ENT
;; with quadrants I and IV.
; -------------------
; THE 'SINE' FUNCTION
; -------------------
; (offset $1F: '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 $39 ;;get-argt reduce - sign now correct.
;; C-ENT
L37B7: DEFB $31 ;;duplicate
DEFB $31 ;;duplicate
DEFB $04 ;;multiply
DEFB $31 ;;duplicate
DEFB $0F ;;addition
DEFB $A1 ;;stk-one
DEFB $03 ;;subtract
DEFB $86 ;;series-06
DEFB $14 ;;Exponent: $64, Bytes: 1
DEFB $E6 ;;(+00,+00,+00)
DEFB $5C ;;Exponent: $6C, Bytes: 2
DEFB $1F,$0B ;;(+00,+00)
DEFB $A3 ;;Exponent: $73, Bytes: 3
DEFB $8F,$38,$EE ;;(+00)
DEFB $E9 ;;Exponent: $79, Bytes: 4
DEFB $15,$63,$BB,$23 ;;
DEFB $EE ;;Exponent: $7E, Bytes: 4
DEFB $92,$0D,$CD,$ED ;;
DEFB $F1 ;;Exponent: $81, Bytes: 4
DEFB $23,$5D,$1B,$EA ;;
DEFB $04 ;;multiply
DEFB $38 ;;end-calc
RET ; return.
; ----------------------
; THE 'TANGENT' FUNCTION
; ----------------------
; (offset $21: '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 $31 ;;duplicate x, x.
DEFB $1F ;;sin x, sin x.
DEFB $01 ;;exchange sin x, x.
DEFB $20 ;;cos sin x, cos x.
DEFB $05 ;;division sin x/cos x (= tan x).
DEFB $38 ;;end-calc tan x.
RET ; return.
; ---------------------
; THE 'ARCTAN' FUNCTION
; ---------------------
; (Offset $24: '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 $81 ; compare to that for 'one'
JR C,L37F8 ; forward, if less, to SMALL
RST 28H ;; FP-CALC
DEFB $A1 ;;stk-one
DEFB $1B ;;negate
DEFB $01 ;;exchange
DEFB $05 ;;division
DEFB $31 ;;duplicate
DEFB $36 ;;less-0
DEFB $A3 ;;stk-pi/2
DEFB $01 ;;exchange
DEFB $00 ;;jump-true
DEFB $06 ;;to L37FA, CASES
DEFB $1B ;;negate
DEFB $33 ;;jump
DEFB $03 ;;to L37FA, CASES
;; SMALL
L37F8: RST 28H ;; FP-CALC
DEFB $A0 ;;stk-zero
;; CASES
L37FA: DEFB $01 ;;exchange
DEFB $31 ;;duplicate
DEFB $31 ;;duplicate
DEFB $04 ;;multiply
DEFB $31 ;;duplicate
DEFB $0F ;;addition
DEFB $A1 ;;stk-one
DEFB $03 ;;subtract
DEFB $8C ;;series-0C
DEFB $10 ;;Exponent: $60, Bytes: 1
DEFB $B2 ;;(+00,+00,+00)
DEFB $13 ;;Exponent: $63, Bytes: 1
DEFB $0E ;;(+00,+00,+00)
DEFB $55 ;;Exponent: $65, Bytes: 2
DEFB $E4,$8D ;;(+00,+00)
DEFB $58 ;;Exponent: $68, Bytes: 2
DEFB $39,$BC ;;(+00,+00)
DEFB $5B ;;Exponent: $6B, Bytes: 2
DEFB $98,$FD ;;(+00,+00)
DEFB $9E ;;Exponent: $6E, Bytes: 3
DEFB $00,$36,$75 ;;(+00)
DEFB $A0 ;;Exponent: $70, Bytes: 3
DEFB $DB,$E8,$B4 ;;(+00)
DEFB $63 ;;Exponent: $73, Bytes: 2
DEFB $42,$C4 ;;(+00,+00)
DEFB $E6 ;;Exponent: $76, Bytes: 4
DEFB $B5,$09,$36,$BE ;;
DEFB $E9 ;;Exponent: $79, Bytes: 4
DEFB $36,$73,$1B,$5D ;;
DEFB $EC ;;Exponent: $7C, Bytes: 4
DEFB $D8,$DE,$63,$BE ;;
DEFB $F0 ;;Exponent: $80, Bytes: 4
DEFB $61,$A1,$B3,$0C ;;
DEFB $04 ;;multiply
DEFB $0F ;;addition
DEFB $38 ;;end-calc
RET ; return.
; ---------------------
; THE 'ARCSIN' FUNCTION
; ---------------------
; (Offset $22: '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 $31 ;;duplicate x, x.
DEFB $31 ;;duplicate x, x, x.
DEFB $04 ;;multiply x, x*x.
DEFB $A1 ;;stk-one x, x*x, 1.
DEFB $03 ;;subtract x, x*x-1.
DEFB $1B ;;negate x, 1-x*x.
DEFB $28 ;;sqr x, sqr(1-x*x) = y
DEFB $A1 ;;stk-one x, y, 1.
DEFB $0F ;;addition x, y+1.
DEFB $05 ;;division x/y+1.
DEFB $24 ;;atn a/2 (half the angle)
DEFB $31 ;;duplicate a/2, a/2.
DEFB $0F ;;addition a.
DEFB $38 ;;end-calc a.
RET ; return.
; ---------------------
; THE 'ARCCOS' FUNCTION
; ---------------------
; (Offset $23: '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 $22 ;;asn asn(x).
DEFB $A3 ;;stk-pi/2 asn(x), pi/2.
DEFB $03 ;;subtract asn(x) - pi/2.
DEFB $1B ;;negate pi/2 -asn(x) = acs(x).
DEFB $38 ;;end-calc acs(x).
RET ; return.
; --------------------------
; THE 'SQUARE ROOT' FUNCTION
; --------------------------
; (Offset $28: '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 $31 ;;duplicate
DEFB $30 ;;not
DEFB $00 ;;jump-true
DEFB $1E ;;to L386C, LAST
DEFB $A2 ;;stk-half
DEFB $38 ;;end-calc
; ------------------------------
; THE 'EXPONENTIATION' OPERATION
; ------------------------------
; (Offset $06: '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 $01 ;;exchange Y, X.
DEFB $31 ;;duplicate Y, X, X.
DEFB $30 ;;not Y, X, (1/0).
DEFB $00 ;;jump-true
DEFB $07 ;;to L385D, XIS0 if X is zero.
; else X is non-zero. Function 'ln' will catch a negative value of X.
DEFB $25 ;;ln Y, LN X.
DEFB $04 ;;multiply Y * LN X.
DEFB $38 ;;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 $02 ;;delete Y.
DEFB $31 ;;duplicate Y, Y.
DEFB $30 ;;not Y, (1/0).
DEFB $00 ;;jump-true
DEFB $09 ;;to L386A, ONE if Y is zero.
DEFB $A0 ;;stk-zero Y, 0.
DEFB $01 ;;exchange 0, Y.
DEFB $37 ;;greater-0 0, (1/0).
DEFB $00 ;;jump-true 0.
DEFB $06 ;;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 $A1 ;;stk-one 0, 1.
DEFB $01 ;;exchange 1, 0.
DEFB $05 ;;division 1/0 ouch!
; ---
;; ONE
L386A: DEFB $02 ;;delete .
DEFB $A1 ;;stk-one 1.
;; LAST
L386C: DEFB $38 ;;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
; ---------------------
;; spare
L386E: DEFB $FF, $FF ;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
DEFB $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF;
ORG $3D00
; -------------------------------
; THE 'ZX SPECTRUM CHARACTER SET'
; -------------------------------
;; char-set
; $20 - Character: ' ' CHR$(32)
L3D00: DEFB %00000000
DEFB %00000000
DEFB %00000000
DEFB %00000000
DEFB %00000000
DEFB %00000000
DEFB %00000000
DEFB %00000000
; $21 - Character: '!' CHR$(33)
DEFB %00000000
DEFB %00010000
DEFB %00010000
DEFB %00010000
DEFB %00010000
DEFB %00000000
DEFB %00010000
DEFB %00000000
; $22 - Character: '"' CHR$(34)
DEFB %00000000
DEFB %00100100
DEFB %00100100
DEFB %00000000
DEFB %00000000
DEFB %00000000
DEFB %00000000
DEFB %00000000
; $23 - Character: '#' CHR$(35)
DEFB %00000000
DEFB %00100100
DEFB %01111110
DEFB %00100100
DEFB %00100100
DEFB %01111110
DEFB %00100100
DEFB %00000000
; $24 - Character: '$' CHR$(36)
DEFB %00000000
DEFB %00001000
DEFB %00111110
DEFB %00101000
DEFB %00111110
DEFB %00001010
DEFB %00111110
DEFB %00001000
; $25 - Character: '%' CHR$(37)
DEFB %00000000
DEFB %01100010
DEFB %01100100
DEFB %00001000
DEFB %00010000
DEFB %00100110
DEFB %01000110
DEFB %00000000
; $26 - Character: '&' CHR$(38)
DEFB %00000000
DEFB %00010000
DEFB %00101000
DEFB %00010000
DEFB %00101010
DEFB %01000100
DEFB %00111010
DEFB %00000000
; $27 - Character: ''' CHR$(39)
DEFB %00000000
DEFB %00001000
DEFB %00010000
DEFB %00000000
DEFB %00000000
DEFB %00000000
DEFB %00000000
DEFB %00000000
; $28 - Character: '(' CHR$(40)
DEFB %00000000
DEFB %00000100
DEFB %00001000
DEFB %00001000
DEFB %00001000
DEFB %00001000
DEFB %00000100
DEFB %00000000
; $29 - Character: ')' CHR$(41)
DEFB %00000000
DEFB %00100000
DEFB %00010000
DEFB %00010000
DEFB %00010000
DEFB %00010000
DEFB %00100000
DEFB %00000000
; $2A - Character: '*' CHR$(42)
DEFB %00000000
DEFB %00000000
DEFB %00010100
DEFB %00001000
DEFB %00111110
DEFB %00001000
DEFB %00010100
DEFB %00000000
; $2B - Character: '+' CHR$(43)
DEFB %00000000
DEFB %00000000
DEFB %00001000
DEFB %00001000
DEFB %00111110
DEFB %00001000
DEFB %00001000
DEFB %00000000
; $2C - Character: ',' CHR$(44)
DEFB %00000000
DEFB %00000000
DEFB %00000000
DEFB %00000000
DEFB %00000000
DEFB %00001000
DEFB %00001000
DEFB %00010000
; $2D - Character: '-' CHR$(45)
DEFB %00000000
DEFB %00000000
DEFB %00000000
DEFB %00000000
DEFB %00111110
DEFB %00000000
DEFB %00000000
DEFB %00000000
; $2E - Character: '.' CHR$(46)
DEFB %00000000
DEFB %00000000
DEFB %00000000
DEFB %00000000
DEFB %00000000
DEFB %00011000
DEFB %00011000
DEFB %00000000
; $2F - Character: '/' CHR$(47)
DEFB %00000000
DEFB %00000000
DEFB %00000010
DEFB %00000100
DEFB %00001000
DEFB %00010000
DEFB %00100000
DEFB %00000000
; $30 - Character: '0' CHR$(48)
DEFB %00000000
DEFB %00111100
DEFB %01000110
DEFB %01001010
DEFB %01010010
DEFB %01100010
DEFB %00111100
DEFB %00000000
; $31 - Character: '1' CHR$(49)
DEFB %00000000
DEFB %00011000
DEFB %00101000
DEFB %00001000
DEFB %00001000
DEFB %00001000
DEFB %00111110
DEFB %00000000
; $32 - Character: '2' CHR$(50)
DEFB %00000000
DEFB %00111100
DEFB %01000010
DEFB %00000010
DEFB %00111100
DEFB %01000000
DEFB %01111110
DEFB %00000000
; $33 - Character: '3' CHR$(51)
DEFB %00000000
DEFB %00111100
DEFB %01000010
DEFB %00001100
DEFB %00000010
DEFB %01000010
DEFB %00111100
DEFB %00000000
; $34 - Character: '4' CHR$(52)
DEFB %00000000
DEFB %00001000
DEFB %00011000
DEFB %00101000
DEFB %01001000
DEFB %01111110
DEFB %00001000
DEFB %00000000
; $35 - Character: '5' CHR$(53)
DEFB %00000000
DEFB %01111110
DEFB %01000000
DEFB %01111100
DEFB %00000010
DEFB %01000010
DEFB %00111100
DEFB %00000000
; $36 - Character: '6' CHR$(54)
DEFB %00000000
DEFB %00111100
DEFB %01000000
DEFB %01111100
DEFB %01000010
DEFB %01000010
DEFB %00111100
DEFB %00000000
; $37 - Character: '7' CHR$(55)
DEFB %00000000
DEFB %01111110
DEFB %00000010
DEFB %00000100
DEFB %00001000
DEFB %00010000
DEFB %00010000
DEFB %00000000
; $38 - Character: '8' CHR$(56)
DEFB %00000000
DEFB %00111100
DEFB %01000010
DEFB %00111100
DEFB %01000010
DEFB %01000010
DEFB %00111100
DEFB %00000000
; $39 - Character: '9' CHR$(57)
DEFB %00000000
DEFB %00111100
DEFB %01000010
DEFB %01000010
DEFB %00111110
DEFB %00000010
DEFB %00111100
DEFB %00000000
; $3A - Character: ':' CHR$(58)
DEFB %00000000
DEFB %00000000
DEFB %00000000
DEFB %00010000
DEFB %00000000
DEFB %00000000
DEFB %00010000
DEFB %00000000
; $3B - Character: ';' CHR$(59)
DEFB %00000000
DEFB %00000000
DEFB %00010000
DEFB %00000000
DEFB %00000000
DEFB %00010000
DEFB %00010000
DEFB %00100000
; $3C - Character: '<' CHR$(60)
DEFB %00000000
DEFB %00000000
DEFB %00000100
DEFB %00001000
DEFB %00010000
DEFB %00001000
DEFB %00000100
DEFB %00000000
; $3D - Character: '=' CHR$(61)
DEFB %00000000
DEFB %00000000
DEFB %00000000
DEFB %00111110
DEFB %00000000
DEFB %00111110
DEFB %00000000
DEFB %00000000
; $3E - Character: '>' CHR$(62)
DEFB %00000000
DEFB %00000000
DEFB %00010000
DEFB %00001000
DEFB %00000100
DEFB %00001000
DEFB %00010000
DEFB %00000000
; $3F - Character: '?' CHR$(63)
DEFB %00000000
DEFB %00111100
DEFB %01000010
DEFB %00000100
DEFB %00001000
DEFB %00000000
DEFB %00001000
DEFB %00000000
; $40 - Character: '@' CHR$(64)
DEFB %00000000
DEFB %00111100
DEFB %01001010
DEFB %01010110
DEFB %01011110
DEFB %01000000
DEFB %00111100
DEFB %00000000
; $41 - Character: 'A' CHR$(65)
DEFB %00000000
DEFB %00111100
DEFB %01000010
DEFB %01000010
DEFB %01111110
DEFB %01000010
DEFB %01000010
DEFB %00000000
; $42 - Character: 'B' CHR$(66)
DEFB %00000000
DEFB %01111100
DEFB %01000010
DEFB %01111100
DEFB %01000010
DEFB %01000010
DEFB %01111100
DEFB %00000000
; $43 - Character: 'C' CHR$(67)
DEFB %00000000
DEFB %00111100
DEFB %01000010
DEFB %01000000
DEFB %01000000
DEFB %01000010
DEFB %00111100
DEFB %00000000
; $44 - Character: 'D' CHR$(68)
DEFB %00000000
DEFB %01111000
DEFB %01000100
DEFB %01000010
DEFB %01000010
DEFB %01000100
DEFB %01111000
DEFB %00000000
; $45 - Character: 'E' CHR$(69)
DEFB %00000000
DEFB %01111110
DEFB %01000000
DEFB %01111100
DEFB %01000000
DEFB %01000000
DEFB %01111110
DEFB %00000000
; $46 - Character: 'F' CHR$(70)
DEFB %00000000
DEFB %01111110
DEFB %01000000
DEFB %01111100
DEFB %01000000
DEFB %01000000
DEFB %01000000
DEFB %00000000
; $47 - Character: 'G' CHR$(71)
DEFB %00000000
DEFB %00111100
DEFB %01000010
DEFB %01000000
DEFB %01001110
DEFB %01000010
DEFB %00111100
DEFB %00000000
; $48 - Character: 'H' CHR$(72)
DEFB %00000000
DEFB %01000010
DEFB %01000010
DEFB %01111110
DEFB %01000010
DEFB %01000010
DEFB %01000010
DEFB %00000000
; $49 - Character: 'I' CHR$(73)
DEFB %00000000
DEFB %00111110
DEFB %00001000
DEFB %00001000
DEFB %00001000
DEFB %00001000
DEFB %00111110
DEFB %00000000
; $4A - Character: 'J' CHR$(74)
DEFB %00000000
DEFB %00000010
DEFB %00000010
DEFB %00000010
DEFB %01000010
DEFB %01000010
DEFB %00111100
DEFB %00000000
; $4B - Character: 'K' CHR$(75)
DEFB %00000000
DEFB %01000100
DEFB %01001000
DEFB %01110000
DEFB %01001000
DEFB %01000100
DEFB %01000010
DEFB %00000000
; $4C - Character: 'L' CHR$(76)
DEFB %00000000
DEFB %01000000
DEFB %01000000
DEFB %01000000
DEFB %01000000
DEFB %01000000
DEFB %01111110
DEFB %00000000
; $4D - Character: 'M' CHR$(77)
DEFB %00000000
DEFB %01000010
DEFB %01100110
DEFB %01011010
DEFB %01000010
DEFB %01000010
DEFB %01000010
DEFB %00000000
; $4E - Character: 'N' CHR$(78)
DEFB %00000000
DEFB %01000010
DEFB %01100010
DEFB %01010010
DEFB %01001010
DEFB %01000110
DEFB %01000010
DEFB %00000000
; $4F - Character: 'O' CHR$(79)
DEFB %00000000
DEFB %00111100
DEFB %01000010
DEFB %01000010
DEFB %01000010
DEFB %01000010
DEFB %00111100
DEFB %00000000
; $50 - Character: 'P' CHR$(80)
DEFB %00000000
DEFB %01111100
DEFB %01000010
DEFB %01000010
DEFB %01111100
DEFB %01000000
DEFB %01000000
DEFB %00000000
; $51 - Character: 'Q' CHR$(81)
DEFB %00000000
DEFB %00111100
DEFB %01000010
DEFB %01000010
DEFB %01010010
DEFB %01001010
DEFB %00111100
DEFB %00000000
; $52 - Character: 'R' CHR$(82)
DEFB %00000000
DEFB %01111100
DEFB %01000010
DEFB %01000010
DEFB %01111100
DEFB %01000100
DEFB %01000010
DEFB %00000000
; $53 - Character: 'S' CHR$(83)
DEFB %00000000
DEFB %00111100
DEFB %01000000
DEFB %00111100
DEFB %00000010
DEFB %01000010
DEFB %00111100
DEFB %00000000
; $54 - Character: 'T' CHR$(84)
DEFB %00000000
DEFB %11111110
DEFB %00010000
DEFB %00010000
DEFB %00010000
DEFB %00010000
DEFB %00010000
DEFB %00000000
; $55 - Character: 'U' CHR$(85)
DEFB %00000000
DEFB %01000010
DEFB %01000010
DEFB %01000010
DEFB %01000010
DEFB %01000010
DEFB %00111100
DEFB %00000000
; $56 - Character: 'V' CHR$(86)
DEFB %00000000
DEFB %01000010
DEFB %01000010
DEFB %01000010
DEFB %01000010
DEFB %00100100
DEFB %00011000
DEFB %00000000
; $57 - Character: 'W' CHR$(87)
DEFB %00000000
DEFB %01000010
DEFB %01000010
DEFB %01000010
DEFB %01000010
DEFB %01011010
DEFB %00100100
DEFB %00000000
; $58 - Character: 'X' CHR$(88)
DEFB %00000000
DEFB %01000010
DEFB %00100100
DEFB %00011000
DEFB %00011000
DEFB %00100100
DEFB %01000010
DEFB %00000000
; $59 - Character: 'Y' CHR$(89)
DEFB %00000000
DEFB %10000010
DEFB %01000100
DEFB %00101000
DEFB %00010000
DEFB %00010000
DEFB %00010000
DEFB %00000000
; $5A - Character: 'Z' CHR$(90)
DEFB %00000000
DEFB %01111110
DEFB %00000100
DEFB %00001000
DEFB %00010000
DEFB %00100000
DEFB %01111110
DEFB %00000000
; $5B - Character: '[' CHR$(91)
DEFB %00000000
DEFB %00001110
DEFB %00001000
DEFB %00001000
DEFB %00001000
DEFB %00001000
DEFB %00001110
DEFB %00000000
; $5C - Character: '\' CHR$(92)
DEFB %00000000
DEFB %00000000
DEFB %01000000
DEFB %00100000
DEFB %00010000
DEFB %00001000
DEFB %00000100
DEFB %00000000
; $5D - Character: ']' CHR$(93)
DEFB %00000000
DEFB %01110000
DEFB %00010000
DEFB %00010000
DEFB %00010000
DEFB %00010000
DEFB %01110000
DEFB %00000000
; $5E - Character: '^' CHR$(94)
DEFB %00000000
DEFB %00010000
DEFB %00111000
DEFB %01010100
DEFB %00010000
DEFB %00010000
DEFB %00010000
DEFB %00000000
; $5F - Character: '_' CHR$(95)
DEFB %00000000
DEFB %00000000
DEFB %00000000
DEFB %00000000
DEFB %00000000
DEFB %00000000
DEFB %00000000
DEFB %11111111
; $60 - Character: ' £ ' CHR$(96)
DEFB %00000000
DEFB %00011100
DEFB %00100010
DEFB %01111000
DEFB %00100000
DEFB %00100000
DEFB %01111110
DEFB %00000000
; $61 - Character: 'a' CHR$(97)
DEFB %00000000
DEFB %00000000
DEFB %00111000
DEFB %00000100
DEFB %00111100
DEFB %01000100
DEFB %00111100
DEFB %00000000
; $62 - Character: 'b' CHR$(98)
DEFB %00000000
DEFB %00100000
DEFB %00100000
DEFB %00111100
DEFB %00100010
DEFB %00100010
DEFB %00111100
DEFB %00000000
; $63 - Character: 'c' CHR$(99)
DEFB %00000000
DEFB %00000000
DEFB %00011100
DEFB %00100000
DEFB %00100000
DEFB %00100000
DEFB %00011100
DEFB %00000000
; $64 - Character: 'd' CHR$(100)
DEFB %00000000
DEFB %00000100
DEFB %00000100
DEFB %00111100
DEFB %01000100
DEFB %01000100
DEFB %00111100
DEFB %00000000
; $65 - Character: 'e' CHR$(101)
DEFB %00000000
DEFB %00000000
DEFB %00111000
DEFB %01000100
DEFB %01111000
DEFB %01000000
DEFB %00111100
DEFB %00000000
; $66 - Character: 'f' CHR$(102)
DEFB %00000000
DEFB %00001100
DEFB %00010000
DEFB %00011000
DEFB %00010000
DEFB %00010000
DEFB %00010000
DEFB %00000000
; $67 - Character: 'g' CHR$(103)
DEFB %00000000
DEFB %00000000
DEFB %00111100
DEFB %01000100
DEFB %01000100
DEFB %00111100
DEFB %00000100
DEFB %00111000
; $68 - Character: 'h' CHR$(104)
DEFB %00000000
DEFB %01000000
DEFB %01000000
DEFB %01111000
DEFB %01000100
DEFB %01000100
DEFB %01000100
DEFB %00000000
; $69 - Character: 'i' CHR$(105)
DEFB %00000000
DEFB %00010000
DEFB %00000000
DEFB %00110000
DEFB %00010000
DEFB %00010000
DEFB %00111000
DEFB %00000000
; $6A - Character: 'j' CHR$(106)
DEFB %00000000
DEFB %00000100
DEFB %00000000
DEFB %00000100
DEFB %00000100
DEFB %00000100
DEFB %00100100
DEFB %00011000
; $6B - Character: 'k' CHR$(107)
DEFB %00000000
DEFB %00100000
DEFB %00101000
DEFB %00110000
DEFB %00110000
DEFB %00101000
DEFB %00100100
DEFB %00000000
; $6C - Character: 'l' CHR$(108)
DEFB %00000000
DEFB %00010000
DEFB %00010000
DEFB %00010000
DEFB %00010000
DEFB %00010000
DEFB %00001100
DEFB %00000000
; $6D - Character: 'm' CHR$(109)
DEFB %00000000
DEFB %00000000
DEFB %01101000
DEFB %01010100
DEFB %01010100
DEFB %01010100
DEFB %01010100
DEFB %00000000
; $6E - Character: 'n' CHR$(110)
DEFB %00000000
DEFB %00000000
DEFB %01111000
DEFB %01000100
DEFB %01000100
DEFB %01000100
DEFB %01000100
DEFB %00000000
; $6F - Character: 'o' CHR$(111)
DEFB %00000000
DEFB %00000000
DEFB %00111000
DEFB %01000100
DEFB %01000100
DEFB %01000100
DEFB %00111000
DEFB %00000000
; $70 - Character: 'p' CHR$(112)
DEFB %00000000
DEFB %00000000
DEFB %01111000
DEFB %01000100
DEFB %01000100
DEFB %01111000
DEFB %01000000
DEFB %01000000
; $71 - Character: 'q' CHR$(113)
DEFB %00000000
DEFB %00000000
DEFB %00111100
DEFB %01000100
DEFB %01000100
DEFB %00111100
DEFB %00000100
DEFB %00000110
; $72 - Character: 'r' CHR$(114)
DEFB %00000000
DEFB %00000000
DEFB %00011100
DEFB %00100000
DEFB %00100000
DEFB %00100000
DEFB %00100000
DEFB %00000000
; $73 - Character: 's' CHR$(115)
DEFB %00000000
DEFB %00000000
DEFB %00111000
DEFB %01000000
DEFB %00111000
DEFB %00000100
DEFB %01111000
DEFB %00000000
; $74 - Character: 't' CHR$(116)
DEFB %00000000
DEFB %00010000
DEFB %00111000
DEFB %00010000
DEFB %00010000
DEFB %00010000
DEFB %00001100
DEFB %00000000
; $75 - Character: 'u' CHR$(117)
DEFB %00000000
DEFB %00000000
DEFB %01000100
DEFB %01000100
DEFB %01000100
DEFB %01000100
DEFB %00111000
DEFB %00000000
; $76 - Character: 'v' CHR$(118)
DEFB %00000000
DEFB %00000000
DEFB %01000100
DEFB %01000100
DEFB %00101000
DEFB %00101000
DEFB %00010000
DEFB %00000000
; $77 - Character: 'w' CHR$(119)
DEFB %00000000
DEFB %00000000
DEFB %01000100
DEFB %01010100
DEFB %01010100
DEFB %01010100
DEFB %00101000
DEFB %00000000
; $78 - Character: 'x' CHR$(120)
DEFB %00000000
DEFB %00000000
DEFB %01000100
DEFB %00101000
DEFB %00010000
DEFB %00101000
DEFB %01000100
DEFB %00000000
; $79 - Character: 'y' CHR$(121)
DEFB %00000000
DEFB %00000000
DEFB %01000100
DEFB %01000100
DEFB %01000100
DEFB %00111100
DEFB %00000100
DEFB %00111000
; $7A - Character: 'z' CHR$(122)
DEFB %00000000
DEFB %00000000
DEFB %01111100
DEFB %00001000
DEFB %00010000
DEFB %00100000
DEFB %01111100
DEFB %00000000
; $7B - Character: '{' CHR$(123)
DEFB %00000000
DEFB %00001110
DEFB %00001000
DEFB %00110000
DEFB %00001000
DEFB %00001000
DEFB %00001110
DEFB %00000000
; $7C - Character: '|' CHR$(124)
DEFB %00000000
DEFB %00001000
DEFB %00001000
DEFB %00001000
DEFB %00001000
DEFB %00001000
DEFB %00001000
DEFB %00000000
; $7D - Character: '}' CHR$(125)
DEFB %00000000
DEFB %01110000
DEFB %00010000
DEFB %00001100
DEFB %00010000
DEFB %00010000
DEFB %01110000
DEFB %00000000
; $7E - Character: '~' CHR$(126)
DEFB %00000000
DEFB %00010100
DEFB %00101000
DEFB %00000000
DEFB %00000000
DEFB %00000000
DEFB %00000000
DEFB %00000000
; $7F - Character: ' © ' CHR$(127)
DEFB %00111100
DEFB %01000010
DEFB %10011001
DEFB %10100001
DEFB %10100001
DEFB %10011001
DEFB %01000010
DEFB %00111100
;#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,$4000 ; 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.
| 41.230372 | 121 | 0.457785 |
03d600c22d1748e043dc7d95b6bbce688d5c204d | 299 | asm | Assembly | libsrc/_DEVELOPMENT/sound/sn76489/c/sccz80/PSGRestoreVolumes.asm | ahjelm/z88dk | c4de367f39a76b41f6390ceeab77737e148178fa | [
"ClArtistic"
] | 640 | 2017-01-14T23:33:45.000Z | 2022-03-30T11:28:42.000Z | libsrc/_DEVELOPMENT/sound/sn76489/c/sccz80/PSGRestoreVolumes.asm | C-Chads/z88dk | a4141a8e51205c6414b4ae3263b633c4265778e6 | [
"ClArtistic"
] | 1,600 | 2017-01-15T16:12:02.000Z | 2022-03-31T12:11:12.000Z | libsrc/_DEVELOPMENT/sound/sn76489/c/sccz80/PSGRestoreVolumes.asm | C-Chads/z88dk | a4141a8e51205c6414b4ae3263b633c4265778e6 | [
"ClArtistic"
] | 215 | 2017-01-17T10:43:03.000Z | 2022-03-23T17:25:02.000Z | ; void PSGRestoreVolumes(void)
SECTION code_clib
SECTION code_PSGlib
PUBLIC PSGRestoreVolumes
EXTERN asm_PSGlib_RestoreVolumes
defc PSGRestoreVolumes = asm_PSGlib_RestoreVolumes
; SDCC bridge for Classic
IF __CLASSIC
PUBLIC _PSGRestoreVolumes
defc _PSGRestoreVolumes = PSGRestoreVolumes
ENDIF
| 16.611111 | 50 | 0.862876 |
8feb8cc1ffcb2a0ae87a9cfb52c7f8c2a797659d | 423 | asm | Assembly | programs/oeis/151/A151786.asm | jmorken/loda | 99c09d2641e858b074f6344a352d13bc55601571 | [
"Apache-2.0"
] | 1 | 2021-03-15T11:38:20.000Z | 2021-03-15T11:38:20.000Z | programs/oeis/151/A151786.asm | jmorken/loda | 99c09d2641e858b074f6344a352d13bc55601571 | [
"Apache-2.0"
] | null | null | null | programs/oeis/151/A151786.asm | jmorken/loda | 99c09d2641e858b074f6344a352d13bc55601571 | [
"Apache-2.0"
] | null | null | null | ; A151786: 8^{wt(n)-1} where wt(n) is the binary weight of n (A000120).
; 1,1,8,1,8,8,64,1,8,8,64,8,64,64,512,1,8,8,64,8,64,64,512,8,64,64,512,64,512,512,4096,1,8,8,64,8,64,64,512,8,64,64,512,64,512,512,4096,8,64,64,512,64,512,512,4096,64,512,512,4096,512,4096,4096,32768,1,8,8,64,8,64
add $0,1
mov $2,$0
lpb $0
div $0,2
mov $1,0
pow $3,0
add $1,$3
mul $1,8
sub $2,$0
lpe
pow $1,$2
div $1,56
mul $1,7
add $1,1
| 23.5 | 213 | 0.609929 |
3f10c37d4b0ac29156c9597eb20ea9748add6633 | 36,157 | asm | Assembly | WDL/eel2/asm-nseel-x64-macho.asm | m1cl/synth | c9262512fac4a8083df985342067e4a74ca891a4 | [
"Zlib"
] | 2 | 2017-12-05T04:18:55.000Z | 2021-03-20T03:04:56.000Z | WDL/eel2/asm-nseel-x64-macho.asm | m1cl/synth | c9262512fac4a8083df985342067e4a74ca891a4 | [
"Zlib"
] | null | null | null | WDL/eel2/asm-nseel-x64-macho.asm | m1cl/synth | c9262512fac4a8083df985342067e4a74ca891a4 | [
"Zlib"
] | 2 | 2017-04-24T12:45:33.000Z | 2019-12-22T04:31:51.000Z | ; THIS FILE AUTOGENERATED FROM asm-nseel-x86-gcc.c by a2x64.php
%define AMD64ABI
%define EEL_F_SIZE 8
%define TARGET_X64
SECTION .text
global _nseel_asm_1pdd
_nseel_asm_1pdd:
mov rdi, qword 0xFEFEFEFEFEFEFEFE
%ifdef TARGET_X64
sub rsp, 128
fstp qword [rsp]
movq xmm0, [rsp]
%ifdef AMD64ABI
mov r15, rsi
call rdi
mov rsi, r15
%else
call rdi
%endif
movq [rsp], xmm0
fld qword [rsp]
add rsp, 128
%else
sub rsp, 16
fstp qword [rsp]
call rdi
add rsp, 16
%endif
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_1pdd_end
_nseel_asm_1pdd_end:
global _nseel_asm_2pdd
_nseel_asm_2pdd:
mov rdi, qword 0xFEFEFEFEFEFEFEFE
%ifdef TARGET_X64
sub rsp, 128
fstp qword [rsp+8]
fstp qword [rsp]
movq xmm1, [rsp+8]
movq xmm0, [rsp]
%ifdef AMD64ABI
mov r15, rsi
call rdi
mov rsi, r15
%else
call rdi
%endif
movq [rsp], xmm0
fld qword [rsp]
add rsp, 128
%else
sub rsp, 16
fstp qword [rsp+8]
fstp qword [rsp]
call rdi
add rsp, 16
%endif
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_2pdd_end
_nseel_asm_2pdd_end:
global _nseel_asm_2pdds
_nseel_asm_2pdds:
mov rax, qword 0xFEFEFEFEFEFEFEFE
%ifdef TARGET_X64
sub rsp, 128
fstp qword [rsp]
movq xmm0, [rdi]
movq xmm1, [rsp]
%ifdef AMD64ABI
mov r15, rsi
mov r14, rdi
call rax
mov rsi, r15
movq [r14], xmm0
mov rax, r14 ; set return value
%else
call rax
movq [rdi], xmm0
mov rax, rdi ; set return value
%endif
add rsp, 128
%else
sub rsp, 8
fstp qword [rsp]
push dword [rdi+4] ; push parameter
push dword [rdi] ; push the rest of the parameter
call rax
add rsp, 16
fstp qword [rdi] ; store result
mov rax, rdi ; set return value
%endif
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_2pdds_end
_nseel_asm_2pdds_end:
global _nseel_asm_exec2
_nseel_asm_exec2:
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_exec2_end
_nseel_asm_exec2_end:
global _nseel_asm_invsqrt
_nseel_asm_invsqrt:
mov rdx, 0x5f3759df
fst dword [rsi]
%ifdef TARGET_X64
mov rax, qword 0xFEFEFEFEFEFEFEFE
sub rcx, rcx
fmul qword [rax]
%else
fmul qword [qword 0xFEFEFEFEFEFEFEFE]
%endif
mov ecx, dword [rsi]
sar rcx, 1
sub rdx, rcx
mov dword [rsi], edx
fmul dword [rsi]
fmul dword [rsi]
%ifdef TARGET_X64
mov rax, qword 0xFEFEFEFEFEFEFEFE
fadd qword [rax]
%else
fadd qword [qword 0xFEFEFEFEFEFEFEFE]
%endif
fmul dword [rsi]
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_invsqrt_end
_nseel_asm_invsqrt_end:
global _nseel_asm_sin
_nseel_asm_sin:
fsin
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_sin_end
_nseel_asm_sin_end:
global _nseel_asm_cos
_nseel_asm_cos:
fcos
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_cos_end
_nseel_asm_cos_end:
global _nseel_asm_tan
_nseel_asm_tan:
fptan
fstp st0
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_tan_end
_nseel_asm_tan_end:
global _nseel_asm_sqr
_nseel_asm_sqr:
fmul st0, st0
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_sqr_end
_nseel_asm_sqr_end:
global _nseel_asm_sqrt
_nseel_asm_sqrt:
fabs
fsqrt
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_sqrt_end
_nseel_asm_sqrt_end:
global _nseel_asm_log
_nseel_asm_log:
fldln2
fxch
fyl2x
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_log_end
_nseel_asm_log_end:
global _nseel_asm_log10
_nseel_asm_log10:
fldlg2
fxch
fyl2x
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_log10_end
_nseel_asm_log10_end:
global _nseel_asm_abs
_nseel_asm_abs:
fabs
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_abs_end
_nseel_asm_abs_end:
global _nseel_asm_assign
_nseel_asm_assign:
%ifdef TARGET_X64
mov rdx, qword [rax]
mov rcx, rdx
shr rdx, 32
and rdx, 0x7FF00000
jz label_0
cmp rdx, 0x7FF00000
je label_0
jmp label_1
label_0:
sub rcx, rcx
label_1:
mov qword [rdi], rcx
mov rax, rdi
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
%else
mov edx, dword [rax+4]
mov ecx, dword [rax]
and rdx, 0x7ff00000
jz label_2 ; if exponent=zero, zero
cmp rdx, 0x7ff00000
je label_2 ; if exponent=all 1s, zero
mov edx, dword [rax+4] ; reread
jmp label_3
label_2:
sub rcx, rcx
sub rdx, rdx
label_3:
mov dword [rdi], ecx
mov dword [rdi+4], edx
mov rax, rdi
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
%endif
global _nseel_asm_assign_end
_nseel_asm_assign_end:
global _nseel_asm_assign_fromfp
_nseel_asm_assign_fromfp:
%ifdef TARGET_X64
fstp qword [rdi]
mov rdx, qword [rdi]
mov r15, 0x7FF0000000000000
and rdx, r15
jz label_4
cmp rdx, r15
jne label_5
label_4:
sub rcx, rcx
mov qword [rdi], rcx
label_5:
mov rax, rdi
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
%else
fstp qword [rdi]
mov edx, dword [rdi+4]
and rdx, 0x7ff00000
jz label_6
cmp rdx, 0x7ff00000
jne label_7
label_6:
fldz
fstp qword [rdi]
label_7:
mov rax, rdi
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
%endif
global _nseel_asm_assign_fromfp_end
_nseel_asm_assign_fromfp_end:
global _nseel_asm_assign_fast
_nseel_asm_assign_fast:
%ifdef TARGET_X64
mov rdx, qword [rax]
mov qword [rdi], rdx
mov rax, rdi
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
%else
mov edx, dword [rax+4]
mov ecx, dword [rax]
mov dword [rdi], ecx
mov dword [rdi+4], edx
mov rax, rdi
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
%endif
global _nseel_asm_assign_fast_end
_nseel_asm_assign_fast_end:
global _nseel_asm_add
_nseel_asm_add:
fadd
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_add_end
_nseel_asm_add_end:
global _nseel_asm_add_op
_nseel_asm_add_op:
fadd qword [rdi]
mov rax, rdi
fstp qword [rdi]
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_add_op_end
_nseel_asm_add_op_end:
global _nseel_asm_sub
_nseel_asm_sub:
%ifdef __GNUC__
fsubr ; gnuc has fsub/fsubr backwards, ack
%else
fsub
%endif
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_sub_end
_nseel_asm_sub_end:
global _nseel_asm_sub_op
_nseel_asm_sub_op:
fsubr qword [rdi]
mov rax, rdi
fstp qword [rdi]
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_sub_op_end
_nseel_asm_sub_op_end:
global _nseel_asm_mul
_nseel_asm_mul:
fmul
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_mul_end
_nseel_asm_mul_end:
global _nseel_asm_mul_op
_nseel_asm_mul_op:
fmul qword [rdi]
mov rax, rdi
fstp qword [rdi]
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_mul_op_end
_nseel_asm_mul_op_end:
global _nseel_asm_div
_nseel_asm_div:
%ifdef __GNUC__
fdivr ; gcc inline asm seems to have fdiv/fdivr backwards
%else
fdiv
%endif
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_div_end
_nseel_asm_div_end:
global _nseel_asm_div_op
_nseel_asm_div_op:
fld qword [rdi]
%ifndef __GNUC__
fxch ; gcc inline asm seems to have fdiv/fdivr backwards
%endif
fdiv
mov rax, rdi
fstp qword [rdi]
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_div_op_end
_nseel_asm_div_op_end:
global _nseel_asm_mod
_nseel_asm_mod:
fabs
fisttp dword [rsi]
fabs
fisttp dword [rsi+4]
xor rdx, rdx
%ifdef TARGET_X64
sub rax, rax
%endif
cmp dword [rsi], 0
je label_8 ; skip devide, set return to 0
mov eax, dword [rsi+4]
div dword [rsi]
label_8:
mov dword [rsi], edx
fild dword [rsi]
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_mod_end
_nseel_asm_mod_end:
global _nseel_asm_shl
_nseel_asm_shl:
fisttp dword [rsi]
fisttp dword [rsi+4]
mov ecx, dword [rsi]
mov eax, dword [rsi+4]
shl rax, cl
mov dword [rsi], eax
fild dword [rsi]
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_shl_end
_nseel_asm_shl_end:
global _nseel_asm_shr
_nseel_asm_shr:
fisttp dword [rsi]
fisttp dword [rsi+4]
mov ecx, dword [rsi]
mov eax, dword [rsi+4]
sar rax, cl
mov dword [rsi], eax
fild dword [rsi]
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_shr_end
_nseel_asm_shr_end:
global _nseel_asm_mod_op
_nseel_asm_mod_op:
fld qword [rdi]
fxch
fabs
fisttp dword [rdi]
fabs
fisttp dword [rsi]
%ifdef TARGET_X64
sub rax, rax
%endif
xor rdx, rdx
cmp dword [rdi], 0
je label_9 ; skip devide, set return to 0
mov eax, dword [rsi]
div dword [rdi]
label_9:
mov dword [rdi], edx
fild dword [rdi]
mov rax, rdi
fstp qword [rdi]
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_mod_op_end
_nseel_asm_mod_op_end:
global _nseel_asm_or
_nseel_asm_or:
fisttp qword [rsi]
fisttp qword [rsi+8]
%ifdef TARGET_X64
mov rdi, qword [rsi+8]
or qword [rsi], rdi
%else
mov edi, dword [rsi+8]
mov ecx, dword [rsi+12]
or dword [rsi], edi
or dword [rsi+4], ecx
%endif
fild qword [rsi]
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_or_end
_nseel_asm_or_end:
global _nseel_asm_or0
_nseel_asm_or0:
frndint
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_or0_end
_nseel_asm_or0_end:
global _nseel_asm_or_op
_nseel_asm_or_op:
fld qword [rdi]
fxch
fisttp qword [rdi]
fisttp qword [rsi]
%ifdef TARGET_X64
mov rax, qword [rsi]
or qword [rdi], rax
%else
mov eax, dword [rsi]
mov ecx, dword [rsi+4]
or dword [rdi], eax
or dword [rdi+4], ecx
%endif
fild qword [rdi]
mov rax, rdi
fstp qword [rdi]
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_or_op_end
_nseel_asm_or_op_end:
global _nseel_asm_xor
_nseel_asm_xor:
fisttp qword [rsi]
fisttp qword [rsi+8]
%ifdef TARGET_X64
mov rdi, qword [rsi+8]
xor qword [rsi], rdi
%else
mov edi, dword [rsi+8]
mov ecx, dword [rsi+12]
xor dword [rsi], edi
xor dword [rsi+4], ecx
%endif
fild qword [rsi]
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_xor_end
_nseel_asm_xor_end:
global _nseel_asm_xor_op
_nseel_asm_xor_op:
fld qword [rdi]
fxch
fisttp qword [rdi]
fisttp qword [rsi]
%ifdef TARGET_X64
mov rax, qword [rsi]
xor qword [rdi], rax
%else
mov eax, dword [rsi]
mov ecx, dword [rsi+4]
xor dword [rdi], eax
xor dword [rdi+4], ecx
%endif
fild qword [rdi]
mov rax, rdi
fstp qword [rdi]
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_xor_op_end
_nseel_asm_xor_op_end:
global _nseel_asm_and
_nseel_asm_and:
fisttp qword [rsi]
fisttp qword [rsi+8]
%ifdef TARGET_X64
mov rdi, qword [rsi+8]
and qword [rsi], rdi
%else
mov edi, dword [rsi+8]
mov ecx, dword [rsi+12]
and dword [rsi], edi
and dword [rsi+4], ecx
%endif
fild qword [rsi]
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_and_end
_nseel_asm_and_end:
global _nseel_asm_and_op
_nseel_asm_and_op:
fld qword [rdi]
fxch
fisttp qword [rdi]
fisttp qword [rsi]
%ifdef TARGET_X64
mov rax, qword [rsi]
and qword [rdi], rax
%else
mov eax, dword [rsi]
mov ecx, dword [rsi+4]
and dword [rdi], eax
and dword [rdi+4], ecx
%endif
fild qword [rdi]
mov rax, rdi
fstp qword [rdi]
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_and_op_end
_nseel_asm_and_op_end:
global _nseel_asm_uplus
_nseel_asm_uplus:
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_uplus_end
_nseel_asm_uplus_end:
global _nseel_asm_uminus
_nseel_asm_uminus:
fchs
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_uminus_end
_nseel_asm_uminus_end:
global _nseel_asm_sign
_nseel_asm_sign:
%ifdef TARGET_X64
fst qword [rsp+-8]
mov rdx, qword [rsp+-8]
mov rcx, 0x7FFFFFFFFFFFFFFF
test rdx, rcx
jz label_10 ; zero zero, return the value passed directly
; calculate sign
inc rcx ; rcx becomes 0x80000...
fstp st0
fld1
test rdx, rcx
jz label_10
fchs
label_10:
%else
fst -dword [rsp+4]
mov ecx, -dword [rsp+4]
mov rdx, 0x7FFFFFFF
test rcx, rdx
jz label_11 ; zero zero, return the value passed directly
; calculate sign
inc rdx ; edx becomes 0x8000...
fstp st0
fld1
test rcx, rdx
jz label_11
fchs
label_11:
%endif
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_sign_end
_nseel_asm_sign_end:
global _nseel_asm_bnot
_nseel_asm_bnot:
test rax, rax
setz al
and rax, 0xff
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_bnot_end
_nseel_asm_bnot_end:
global _nseel_asm_if
_nseel_asm_if:
%ifdef TARGET_X64
sub rsp, 8
test rax, rax
jz label_12
mov rax, qword 0xFEFEFEFEFEFEFEFE
call rax
jmp label_13
label_12:
mov rax, qword 0xFEFEFEFEFEFEFEFE
call rax
label_13:
add rsp, 8
%else
sub rsp, 12
test rax, rax
jz label_14
mov rax, qword 0xFEFEFEFEFEFEFEFE
call rax
jmp label_15
label_14:
mov rax, qword 0xFEFEFEFEFEFEFEFE
call rax
label_15:
add rsp, 12
%endif
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_if_end
_nseel_asm_if_end:
global _nseel_asm_repeat
_nseel_asm_repeat:
%ifdef TARGET_X64
fisttp qword [rsi]
mov rcx, qword [rsi]
%else
fisttp dword [rsi]
mov ecx, dword [rsi]
%endif
cmp rcx, 1
jl label_16
cmp rcx, 10000000
jl label_17
mov rcx, 10000000
label_17:
mov rdx, qword 0xFEFEFEFEFEFEFEFE
%ifdef TARGET_X64
sub rsp, 8 ; keep stack aligned to 16 byte
%else
sub rsp, 4 ; keep stack aligned to 16 byte
%endif
push rsi ; revert back to last temp workspace
push rcx
call rdx
pop rcx
pop rsi
%ifdef TARGET_X64
add rsp, 8 ; keep stack aligned to 16 byte
%else
add rsp, 4 ; keep stack aligned to 16 byte
%endif
dec rcx
jnz label_17
label_16:
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_repeat_end
_nseel_asm_repeat_end:
global _nseel_asm_fcall
_nseel_asm_fcall:
mov rdx, qword 0xFEFEFEFEFEFEFEFE
%ifdef TARGET_X64
sub rsp, 8
call rdx
add rsp, 8
%else
sub rsp, 12 ; keep stack 16 byte aligned, 4 bytes for return address
call rdx
add rsp, 12
%endif
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_fcall_end
_nseel_asm_fcall_end:
global _nseel_asm_repeatwhile
_nseel_asm_repeatwhile:
mov rcx, 10000000
label_18:
mov rdx, qword 0xFEFEFEFEFEFEFEFE
%ifdef TARGET_X64
sub rsp, 8 ; keep stack aligned -- required on x86 and x64
%else
sub rsp, 4 ; keep stack aligned -- required on x86 and x64
%endif
push rsi ; revert back to last temp workspace
push rcx
call rdx
pop rcx
pop rsi
%ifdef TARGET_X64
add rsp, 8 ; keep stack aligned -- required on x86 and x64
%else
add rsp, 4 ; keep stack aligned -- required on x86 and x64
%endif
test rax, rax
jz label_19
dec rcx
jnz label_18
label_19:
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_repeatwhile_end
_nseel_asm_repeatwhile_end:
global _nseel_asm_band
_nseel_asm_band:
test rax, rax
jz label_20
mov rcx, qword 0xFEFEFEFEFEFEFEFE
%ifdef TARGET_X64
sub rsp, 8
%else
sub rsp, 12
%endif
call rcx
%ifdef TARGET_X64
add rsp, 8
%else
add rsp, 12
%endif
label_20:
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_band_end
_nseel_asm_band_end:
global _nseel_asm_bor
_nseel_asm_bor:
test rax, rax
jnz label_21
mov rcx, qword 0xFEFEFEFEFEFEFEFE
%ifdef TARGET_X64
sub rsp, 8
%else
sub rsp, 12
%endif
call rcx
%ifdef TARGET_X64
add rsp, 8
%else
add rsp, 12
%endif
label_21:
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_bor_end
_nseel_asm_bor_end:
global _nseel_asm_equal
_nseel_asm_equal:
fsub
fabs
%ifdef TARGET_X64
mov rax, qword 0xFEFEFEFEFEFEFEFE
fcomp qword [rax] ; [g_closefact]
%else
fcomp qword [qword 0xFEFEFEFEFEFEFEFE] ; [g_closefact]
%endif
fstsw ax
and rax, 256 ; old behavior: if 256 set, true (NaN means true)
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_equal_end
_nseel_asm_equal_end:
global _nseel_asm_notequal
_nseel_asm_notequal:
fsub
fabs
%ifdef TARGET_X64
mov rax, qword 0xFEFEFEFEFEFEFEFE
fcomp qword [rax] ; [g_closefact]
%else
fcomp qword [qword 0xFEFEFEFEFEFEFEFE] ; [g_closefact]
%endif
fstsw ax
and rax, 256
xor rax, 256 ; old behavior: if 256 set, FALSE (NaN makes for false)
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_notequal_end
_nseel_asm_notequal_end:
global _nseel_asm_above
_nseel_asm_above:
fcompp
fstsw ax
and rax, 1280 ; (1024+256) old behavior: NaN would mean 1, preserve that
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_above_end
_nseel_asm_above_end:
global _nseel_asm_beloweq
_nseel_asm_beloweq:
fcompp
fstsw ax
and rax, 256 ; old behavior: NaN would be 0 (ugh)
xor rax, 256
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_beloweq_end
_nseel_asm_beloweq_end:
global _nseel_asm_booltofp
_nseel_asm_booltofp:
test rax, rax
jz label_22
fld1
jmp label_23
label_22:
fldz
label_23:
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_booltofp_end
_nseel_asm_booltofp_end:
global _nseel_asm_fptobool
_nseel_asm_fptobool:
fabs
%ifdef TARGET_X64
mov rax, qword 0xFEFEFEFEFEFEFEFE
fcomp qword [rax] ; [g_closefact]
%else
fcomp qword [qword 0xFEFEFEFEFEFEFEFE] ; [g_closefact]
%endif
fstsw ax
and rax, 256
xor rax, 256
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_fptobool_end
_nseel_asm_fptobool_end:
global _nseel_asm_min
_nseel_asm_min:
fld qword [rdi]
fcomp qword [rax]
push rax
fstsw ax
test rax, 256
pop rax
jz label_24
mov rax, rdi
label_24:
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_min_end
_nseel_asm_min_end:
global _nseel_asm_max
_nseel_asm_max:
fld qword [rdi]
fcomp qword [rax]
push rax
fstsw ax
test rax, 256
pop rax
jnz label_25
mov rax, rdi
label_25:
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_max_end
_nseel_asm_max_end:
global _nseel_asm_min_fp
_nseel_asm_min_fp:
fcom
fstsw ax
test rax, 256
jz label_26
fxch
label_26:
fstp st0
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_min_fp_end
_nseel_asm_min_fp_end:
global _nseel_asm_max_fp
_nseel_asm_max_fp:
fcom
fstsw ax
test rax, 256
jnz label_27
fxch
label_27:
fstp st0
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global _nseel_asm_max_fp_end
_nseel_asm_max_fp_end:
global __asm_generic3parm
__asm_generic3parm:
%ifdef TARGET_X64
%ifdef AMD64ABI
mov r15, rsi
mov rdx, rdi ; third parameter = parm
mov rdi, qword 0xFEFEFEFEFEFEFEFE ; first parameter= context
mov rsi, rcx ; second parameter = parm
mov rcx, rax ; fourth parameter = parm
mov rax, qword 0xFEFEFEFEFEFEFEFE ; call function
sub rsp, 128
call rax
mov rsi, r15
add rsp, 128
%else
mov rdx, rcx ; second parameter = parm
mov rcx, qword 0xFEFEFEFEFEFEFEFE ; first parameter= context
mov r8, rdi ; third parameter = parm
mov r9, rax ; fourth parameter = parm
mov rdi, qword 0xFEFEFEFEFEFEFEFE ; call function
sub rsp, 128
call rdi
add rsp, 128
%endif
%else
mov rdx, qword 0xFEFEFEFEFEFEFEFE
push rax ; push parameter
push rdi ; push parameter
push rcx ; push parameter
push rdx ; push context pointer
mov rdi, qword 0xFEFEFEFEFEFEFEFE
call rdi
add rsp, 16
%endif
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global __asm_generic3parm_end
__asm_generic3parm_end:
global __asm_generic3parm_retd
__asm_generic3parm_retd:
%ifdef TARGET_X64
%ifdef AMD64ABI
mov r15, rsi
mov rdx, rdi ; third parameter = parm
mov rdi, qword 0xFEFEFEFEFEFEFEFE ; first parameter= context
mov rsi, rcx ; second parameter = parm
mov rcx, rax ; fourth parameter = parm
mov rax, qword 0xFEFEFEFEFEFEFEFE ; call function
sub rsp, 128
call rax
mov rsi, r15
%else
mov rdx, rcx ; second parameter = parm
mov rcx, qword 0xFEFEFEFEFEFEFEFE ; first parameter= context
mov r8, rdi ; third parameter = parm
mov r9, rax ; fourth parameter = parm
mov rdi, qword 0xFEFEFEFEFEFEFEFE ; call function
sub rsp, 128
call rdi
%endif
movq [rsp], xmm0
fld qword [rsp]
add rsp, 128
%else
sub rsp, 16
mov dword [rsp+8], edi
mov rdx, qword 0xFEFEFEFEFEFEFEFE
mov rdi, qword 0xFEFEFEFEFEFEFEFE
mov dword [rsp+12], eax
mov dword [rsp+4], ecx
mov dword [rsp], edx
call rdi
add rsp, 16
%endif
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global __asm_generic3parm_retd_end
__asm_generic3parm_retd_end:
global __asm_generic2parm
__asm_generic2parm:
%ifdef TARGET_X64
%ifdef AMD64ABI
mov r15, rsi
mov rsi, rdi ; second parameter = parm
mov rdi, qword 0xFEFEFEFEFEFEFEFE ; first parameter= context
mov rdx, rax ; third parameter = parm
mov rcx, qword 0xFEFEFEFEFEFEFEFE ; call function
sub rsp, 128
call rcx
mov rsi, r15
add rsp, 128
%else
mov rcx, qword 0xFEFEFEFEFEFEFEFE ; first parameter= context
mov rdx, rdi ; second parameter = parm
mov r8, rax ; third parameter = parm
mov rdi, qword 0xFEFEFEFEFEFEFEFE ; call function
sub rsp, 128
call rdi
add rsp, 128
%endif
%else
mov rdx, qword 0xFEFEFEFEFEFEFEFE
sub rsp, 4 ; keep stack aligned
push rax ; push parameter
push rdi ; push parameter
push rdx ; push context pointer
mov rdi, qword 0xFEFEFEFEFEFEFEFE
call rdi
add rsp, 16
%endif
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global __asm_generic2parm_end
__asm_generic2parm_end:
global __asm_generic2parm_retd
__asm_generic2parm_retd:
%ifdef TARGET_X64
%ifdef AMD64ABI
mov r15, rsi
mov rsi, rdi ; second parameter = parm
mov rdi, qword 0xFEFEFEFEFEFEFEFE ; first parameter= context
mov rcx, qword 0xFEFEFEFEFEFEFEFE ; call function
mov rdx, rax ; third parameter = parm
sub rsp, 128
call rcx
mov rsi, r15
%else
mov rdx, rdi ; second parameter = parm
mov rcx, qword 0xFEFEFEFEFEFEFEFE ; first parameter= context
mov rdi, qword 0xFEFEFEFEFEFEFEFE ; call function
mov r8, rax ; third parameter = parm
sub rsp, 128
call rdi
%endif
movq [rsp], xmm0
fld qword [rsp]
add rsp, 128
%else
sub rsp, 16
mov rdx, qword 0xFEFEFEFEFEFEFEFE
mov rcx, qword 0xFEFEFEFEFEFEFEFE
mov dword [rsp], edx
mov dword [rsp+4], edi
mov dword [rsp+8], eax
call rcx
add rsp, 16
%endif
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global __asm_generic2parm_retd_end
__asm_generic2parm_retd_end:
global __asm_generic1parm
__asm_generic1parm:
%ifdef TARGET_X64
%ifdef AMD64ABI
mov rdi, qword 0xFEFEFEFEFEFEFEFE ; first parameter= context
mov r15, rsi
mov rsi, rax ; second parameter = parm
sub rsp, 128
mov rcx, qword 0xFEFEFEFEFEFEFEFE ; call function
call rcx
mov rsi, r15
add rsp, 128
%else
mov rcx, qword 0xFEFEFEFEFEFEFEFE ; first parameter= context
mov rdx, rax ; second parameter = parm
mov rdi, qword 0xFEFEFEFEFEFEFEFE ; call function
sub rsp, 128
call rdi
add rsp, 128
%endif
%else
mov rdx, qword 0xFEFEFEFEFEFEFEFE
sub rsp, 8 ; keep stack aligned
push rax ; push parameter
push rdx ; push context pointer
mov rdi, qword 0xFEFEFEFEFEFEFEFE
call rdi
add rsp, 16
%endif
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global __asm_generic1parm_end
__asm_generic1parm_end:
global __asm_generic1parm_retd
__asm_generic1parm_retd:
%ifdef TARGET_X64
sub rsp, 128
%ifdef AMD64ABI
mov rdi, qword 0xFEFEFEFEFEFEFEFE ; first parameter = context pointer
mov rcx, qword 0xFEFEFEFEFEFEFEFE ; function address
mov r15, rsi ; save rsi
mov rsi, rax ; second parameter = parameter
call rcx
mov rsi, r15
%else
mov rcx, qword 0xFEFEFEFEFEFEFEFE ; first parameter= context
mov rdi, qword 0xFEFEFEFEFEFEFEFE ; call function
mov rdx, rax ; second parameter = parm
call rdi
%endif
movq [rsp], xmm0
fld qword [rsp]
add rsp, 128
%else
mov rdx, qword 0xFEFEFEFEFEFEFEFE ; context pointer
mov rdi, qword 0xFEFEFEFEFEFEFEFE ; func-addr
sub rsp, 16
mov dword [rsp+4], eax ; push parameter
mov dword [rsp], edx ; push context pointer
call rdi
add rsp, 16
%endif
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global __asm_generic1parm_retd_end
__asm_generic1parm_retd_end:
global __asm_megabuf
__asm_megabuf:
%ifdef TARGET_X64
%ifdef AMD64ABI
mov rdi, qword 0xFEFEFEFEFEFEFEFE ; first parameter = context pointer
mov rdx, qword 0xFEFEFEFEFEFEFEFE
fadd qword [rdx]
fisttp dword [rsi]
sub rdx, rdx
; check if (%rsi) is in range, and buffer available, otherwise call function
mov edx, dword [rsi]
test rdx, 0xff800000 ; 0xFFFFFFFF - (NSEEL_RAM_BLOCKS*NSEEL_RAM_ITEMSPERBLOCK - 1)
jnz label_28
mov rax, rdx
shr rax, 13 ; log2(NSEEL_RAM_ITEMSPERBLOCK) - log2(sizeof(void*))
and rax, 0x3F8 ; (NSEEL_RAM_BLOCKS-1)*sizeof(void*)
mov rax, qword [rdi+rax]
test rax, rax
jz label_28
and rdx, 0xFFFF ; (NSEEL_RAM_ITEMSPERBLOCK-1)
shl rdx, 3 ; log2(sizeof(EEL_F))
add rax, rdx
jmp label_29
label_28:
mov r15, rsi ; save rsi
mov rsi, rdx ; esi becomes second parameter (edi is first, context pointer)
mov rdx, qword 0xFEFEFEFEFEFEFEFE
sub rsp, 128
call rdx
mov rsi, r15 ; restore rsi
add rsp, 128
label_29:
%else
mov rcx, qword 0xFEFEFEFEFEFEFEFE ; first parameter = context pointer
mov rdx, qword 0xFEFEFEFEFEFEFEFE
sub rdi, rdi
fadd qword [rdx]
fisttp dword [rsi]
; check if (%esi) is in range...
mov edi, dword [rsi]
test rdi, 0xff800000 ; 0xFFFFFFFF - (NSEEL_RAM_BLOCKS*NSEEL_RAM_ITEMSPERBLOCK - 1)
jnz label_30
mov rax, rdi
shr rax, 13 ; log2(NSEEL_RAM_ITEMSPERBLOCK) - log2(sizeof(void*))
and rax, 0x3F8 ; (NSEEL_RAM_BLOCKS-1)*sizeof(void*)
mov rax, qword [rcx+rax]
test rax, rax
jz label_30
and rdi, 0xFFFF ; (NSEEL_RAM_ITEMSPERBLOCK-1)
shl rdi, 3 ; log2(sizeof(EEL_F))
add rax, rdi
jmp label_31
label_30:
mov rdx, rdi ; rdx is second parameter (rcx is first)
mov rdi, qword 0xFEFEFEFEFEFEFEFE ; function ptr
sub rsp, 128
call rdi
add rsp, 128
label_31:
%endif
%else
mov rdx, qword 0xFEFEFEFEFEFEFEFE
fadd qword [qword 0xFEFEFEFEFEFEFEFE]
fisttp dword [rsi]
; check if (%esi) is in range, and buffer available, otherwise call function
mov edi, dword [rsi]
test rdi, 0xff800000 ; 0xFFFFFFFF - (NSEEL_RAM_BLOCKS*NSEEL_RAM_ITEMSPERBLOCK - 1)
jnz label_32
mov rax, rdi
shr rax, 14 ; log2(NSEEL_RAM_ITEMSPERBLOCK) - log2(sizeof(void *))
and rax, 0x1FC ; (NSEEL_RAM_BLOCKS-1)*sizeof(void*)
mov eax, dword [rdx+rax]
test rax, rax
jz label_32
and rdi, 0xFFFF ; (NSEEL_RAM_ITEMSPERBLOCK-1)
shl rdi, 3 ; log2(sizeof(EEL_F))
add rax, rdi
jmp label_33
label_32:
sub rsp, 8 ; keep stack aligned
push rdi ; parameter
push rdx ; push context pointer
mov rdi, qword 0xFEFEFEFEFEFEFEFE
call rdi
add rsp, 16
label_33:
%endif
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global __asm_megabuf_end
__asm_megabuf_end:
global __asm_gmegabuf
__asm_gmegabuf:
%ifdef TARGET_X64
%ifdef AMD64ABI
mov r15, rsi
mov rdi, qword 0xFEFEFEFEFEFEFEFE ; first parameter = context pointer
mov rdx, qword 0xFEFEFEFEFEFEFEFE
fadd qword [rdx]
fisttp dword [r15]
xor rsi, rsi
mov esi, dword [r15] ; r15 = esi (from above)
mov rdx, qword 0xFEFEFEFEFEFEFEFE
sub rsp, 128
call rdx
mov rsi, r15
add rsp, 128
%else
mov rcx, qword 0xFEFEFEFEFEFEFEFE ; first parameter = context pointer
mov rdx, qword 0xFEFEFEFEFEFEFEFE
fadd qword [rdx]
fisttp dword [rsi]
xor rdx, rdx
mov edx, dword [rsi]
mov rdi, qword 0xFEFEFEFEFEFEFEFE
sub rsp, 128
call rdi
add rsp, 128
%endif
%else
mov rdx, qword 0xFEFEFEFEFEFEFEFE
fadd qword [qword 0xFEFEFEFEFEFEFEFE]
fisttp dword [rsi]
sub rsp, 8 ; keep stack aligned
push dword [rsi] ; parameter
push rdx ; push context pointer
mov rdi, qword 0xFEFEFEFEFEFEFEFE
call rdi
add rsp, 16
%endif
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
global __asm_gmegabuf_end
__asm_gmegabuf_end:
global _nseel_asm_stack_push
_nseel_asm_stack_push:
%ifdef TARGET_X64
mov rdi, qword 0xFEFEFEFEFEFEFEFE
mov rcx, qword [rax]
mov rax, qword [rdi]
add rax, 8
mov rdx, qword 0xFEFEFEFEFEFEFEFE
and rax, rdx
mov rdx, qword 0xFEFEFEFEFEFEFEFE
or rax, rdx
mov qword [rax], rcx
mov qword [rdi], rax
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
%else
mov rdi, qword 0xFEFEFEFEFEFEFEFE
mov ecx, dword [rax]
mov edx, dword [rax+4]
mov eax, dword [rdi]
add rax, 8
and rax, qword 0xFEFEFEFEFEFEFEFE
or rax, qword 0xFEFEFEFEFEFEFEFE
mov dword [rax], ecx
mov dword [rax+4], edx
mov dword [rdi], eax
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
%endif
global _nseel_asm_stack_push_end
_nseel_asm_stack_push_end:
global _nseel_asm_stack_pop
_nseel_asm_stack_pop:
%ifdef TARGET_X64
mov rdi, qword 0xFEFEFEFEFEFEFEFE
mov rcx, qword [rdi]
movq xmm0, [rcx]
sub rcx, 8
mov rdx, qword 0xFEFEFEFEFEFEFEFE
and rcx, rdx
mov rdx, qword 0xFEFEFEFEFEFEFEFE
or rcx, rdx
mov qword [rdi], rcx
movq [rax], xmm0
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
%else
mov rdi, qword 0xFEFEFEFEFEFEFEFE
mov ecx, dword [rdi]
fld qword [rcx]
sub rcx, 8
and rcx, qword 0xFEFEFEFEFEFEFEFE
or rcx, qword 0xFEFEFEFEFEFEFEFE
mov dword [rdi], ecx
fstp qword [rax]
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
%endif
global _nseel_asm_stack_pop_end
_nseel_asm_stack_pop_end:
global _nseel_asm_stack_pop_fast
_nseel_asm_stack_pop_fast:
%ifdef TARGET_X64
mov rdi, qword 0xFEFEFEFEFEFEFEFE
mov rcx, qword [rdi]
mov rax, rcx
sub rcx, 8
mov rdx, qword 0xFEFEFEFEFEFEFEFE
and rcx, rdx
mov rdx, qword 0xFEFEFEFEFEFEFEFE
or rcx, rdx
mov qword [rdi], rcx
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
%else
mov rdi, qword 0xFEFEFEFEFEFEFEFE
mov ecx, dword [rdi]
mov rax, rcx
sub rcx, 8
and rcx, qword 0xFEFEFEFEFEFEFEFE
or rcx, qword 0xFEFEFEFEFEFEFEFE
mov dword [rdi], ecx
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
%endif
global _nseel_asm_stack_pop_fast_end
_nseel_asm_stack_pop_fast_end:
global _nseel_asm_stack_peek_int
_nseel_asm_stack_peek_int:
%ifdef TARGET_X64
mov rdi, qword 0xFEFEFEFEFEFEFEFE
mov rax, qword [rdi]
mov rdx, qword 0xFEFEFEFEFEFEFEFE
sub rax, rdx
mov rdx, qword 0xFEFEFEFEFEFEFEFE
and rax, rdx
mov rdx, qword 0xFEFEFEFEFEFEFEFE
or rax, rdx
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
%else
mov rdi, qword 0xFEFEFEFEFEFEFEFE
mov eax, dword [rdi]
mov rdx, qword 0xFEFEFEFEFEFEFEFE
sub rax, rdx
and rax, qword 0xFEFEFEFEFEFEFEFE
or rax, qword 0xFEFEFEFEFEFEFEFE
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
%endif
global _nseel_asm_stack_peek_int_end
_nseel_asm_stack_peek_int_end:
global _nseel_asm_stack_peek
_nseel_asm_stack_peek:
%ifdef TARGET_X64
mov rdi, qword 0xFEFEFEFEFEFEFEFE
fisttp dword [rsi]
mov rax, qword [rdi]
mov rdx, qword [rsi]
shl rdx, 3 ; log2(sizeof(EEL_F))
sub rax, rdx
mov rdx, qword 0xFEFEFEFEFEFEFEFE
and rax, rdx
mov rdx, qword 0xFEFEFEFEFEFEFEFE
or rax, rdx
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
%else
mov rdi, qword 0xFEFEFEFEFEFEFEFE
fisttp dword [rsi]
mov eax, dword [rdi]
mov edx, dword [rsi]
shl rdx, 3 ; log2(sizeof(EEL_F))
sub rax, rdx
and rax, qword 0xFEFEFEFEFEFEFEFE
or rax, qword 0xFEFEFEFEFEFEFEFE
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
%endif
global _nseel_asm_stack_peek_end
_nseel_asm_stack_peek_end:
global _nseel_asm_stack_peek_top
_nseel_asm_stack_peek_top:
%ifdef TARGET_X64
mov rdi, qword 0xFEFEFEFEFEFEFEFE
mov rax, qword [rdi]
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
%else
mov rdi, qword 0xFEFEFEFEFEFEFEFE
mov eax, dword [rdi]
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
%endif
global _nseel_asm_stack_peek_top_end
_nseel_asm_stack_peek_top_end:
global _nseel_asm_stack_exch
_nseel_asm_stack_exch:
%ifdef TARGET_X64
mov rdi, qword 0xFEFEFEFEFEFEFEFE
mov rcx, qword [rdi]
movq xmm0, [rcx]
movq xmm1, [rax]
movq [rax], xmm0
movq [rcx], xmm1
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
%else
mov rdi, qword 0xFEFEFEFEFEFEFEFE
mov ecx, dword [rdi]
fld qword [rcx]
fld qword [rax]
fstp qword [rcx]
fstp qword [rax]
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
%endif
global _nseel_asm_stack_exch_end
_nseel_asm_stack_exch_end:
%ifdef TARGET_X64
global _win64_callcode
_win64_callcode:
%ifdef AMD64ABI
mov rax, rdi
%else
mov rax, rcx
%endif
push rbx
push rbp
%ifndef AMD64ABI
push rdi
push rsi
push r12
push r13
%endif
push r14 ; on AMD64ABI, we'll use r14/r15 to save edi/esi
push r15
call rax
pop r15
pop r14
%ifndef AMD64ABI
pop r13
pop r12
pop rsi
pop rdi
fclex
%endif
pop rbp
pop rbx
ret
db 0x89,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90
%endif
| 19.212009 | 90 | 0.697735 |
b9a6706baa05c18fe3439fc15da0888c47a1bbbe | 7,490 | asm | Assembly | Transynther/x86/_processed/NONE/_xt_/i7-7700_9_0x48.log_21829_806.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 9 | 2020-08-13T19:41:58.000Z | 2022-03-30T12:22:51.000Z | Transynther/x86/_processed/NONE/_xt_/i7-7700_9_0x48.log_21829_806.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 1 | 2021-04-29T06:29:35.000Z | 2021-05-13T21:02:30.000Z | Transynther/x86/_processed/NONE/_xt_/i7-7700_9_0x48.log_21829_806.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 3 | 2020-07-14T17:07:07.000Z | 2022-03-21T01:12:22.000Z | .global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r12
push %r13
push %r15
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_A_ht+0x131ad, %r12
nop
nop
nop
nop
nop
xor %rsi, %rsi
mov $0x6162636465666768, %rcx
movq %rcx, %xmm0
vmovups %ymm0, (%r12)
nop
cmp %r13, %r13
lea addresses_WT_ht+0xe941, %r15
nop
nop
nop
nop
nop
inc %r12
movl $0x61626364, (%r15)
cmp $39021, %r12
lea addresses_normal_ht+0xfd41, %rsi
lea addresses_normal_ht+0x6341, %rdi
lfence
mov $4, %rcx
rep movsw
nop
nop
nop
nop
inc %rdx
lea addresses_WT_ht+0x11126, %rsi
lea addresses_WT_ht+0xdc41, %rdi
clflush (%rsi)
nop
xor $42028, %r10
mov $12, %rcx
rep movsl
and %r10, %r10
lea addresses_WC_ht+0x74d1, %rsi
nop
nop
nop
sub $30755, %r10
vmovups (%rsi), %ymm2
vextracti128 $1, %ymm2, %xmm2
vpextrq $1, %xmm2, %rdi
nop
nop
nop
nop
nop
add $12981, %r10
lea addresses_A_ht+0xe0a1, %r15
nop
nop
nop
nop
nop
dec %rdi
movb $0x61, (%r15)
nop
nop
dec %r12
lea addresses_normal_ht+0x15d81, %rsi
lea addresses_WT_ht+0x8341, %rdi
nop
nop
nop
nop
nop
cmp $63568, %r10
mov $92, %rcx
rep movsw
nop
nop
nop
cmp $1015, %r12
lea addresses_normal_ht+0x16121, %rdx
nop
nop
nop
nop
cmp $7309, %r12
mov (%rdx), %r13
nop
nop
nop
xor $65118, %rsi
lea addresses_UC_ht+0xad41, %r10
nop
nop
nop
nop
and %r15, %r15
mov (%r10), %r13w
nop
xor $43983, %rcx
lea addresses_A_ht+0x13f41, %rsi
lea addresses_UC_ht+0x1eb41, %rdi
nop
nop
cmp $15246, %rdx
mov $94, %rcx
rep movsw
nop
nop
nop
nop
and $48233, %r10
lea addresses_WT_ht+0x16b41, %r15
nop
add $48162, %rdx
movb $0x61, (%r15)
nop
nop
nop
and $33766, %r15
lea addresses_normal_ht+0x1341, %rdx
and %rdi, %rdi
mov (%rdx), %rsi
nop
xor $15782, %r12
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %r15
pop %r13
pop %r12
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r12
push %r14
push %r8
push %rax
push %rbp
push %rdi
push %rdx
// Load
mov $0x1b3d7c0000000a41, %rdx
nop
nop
xor %r8, %r8
movups (%rdx), %xmm5
vpextrq $1, %xmm5, %r14
nop
nop
nop
nop
xor $61848, %rdx
// Load
lea addresses_D+0x9b41, %rax
nop
nop
nop
nop
nop
sub $3986, %r14
movb (%rax), %r12b
nop
inc %rdx
// Faulty Load
lea addresses_D+0x9b41, %rax
nop
nop
nop
and $7322, %r8
movb (%rax), %r12b
lea oracles, %r14
and $0xff, %r12
shlq $12, %r12
mov (%r14,%r12,1), %r12
pop %rdx
pop %rdi
pop %rbp
pop %rax
pop %r8
pop %r14
pop %r12
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_D', 'AVXalign': False, 'congruent': 0, 'size': 1, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_NC', 'AVXalign': False, 'congruent': 5, 'size': 16, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_D', 'AVXalign': False, 'congruent': 0, 'size': 1, 'same': True, 'NT': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_D', 'AVXalign': False, 'congruent': 0, 'size': 1, 'same': True, 'NT': False}}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'AVXalign': False, 'congruent': 2, 'size': 32, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'AVXalign': True, 'congruent': 8, 'size': 4, 'same': True, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 9, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 11, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 0, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 7, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 4, 'size': 32, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'AVXalign': False, 'congruent': 4, 'size': 1, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 3, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 11, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_normal_ht', 'AVXalign': False, 'congruent': 5, 'size': 8, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 9, 'size': 2, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 10, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 8, 'same': True}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'AVXalign': False, 'congruent': 11, 'size': 1, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_normal_ht', 'AVXalign': False, 'congruent': 9, 'size': 8, 'same': False, 'NT': False}}
{'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
*/
| 33.587444 | 2,999 | 0.657276 |
839f843342bd9c3991869eeaa0c18e5636fe5db6 | 268 | asm | Assembly | programs/oeis/086/A086224.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | 1 | 2021-03-15T11:38:20.000Z | 2021-03-15T11:38:20.000Z | programs/oeis/086/A086224.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | null | null | null | programs/oeis/086/A086224.asm | karttu/loda | 9c3b0fc57b810302220c044a9d17db733c76a598 | [
"Apache-2.0"
] | null | null | null | ; A086224: a(n) = 7*2^n-1.
; 6,13,27,55,111,223,447,895,1791,3583,7167,14335,28671,57343,114687,229375,458751,917503,1835007,3670015,7340031,14680063,29360127,58720255,117440511,234881023,469762047,939524095,1879048191,3758096383
mov $1,2
pow $1,$0
mul $1,7
sub $1,1
| 33.5 | 202 | 0.761194 |
dddcafd40cb4ae90a428e5d1ea5de3f6a94b7b33 | 1,014 | asm | Assembly | colib/colib_masm_win_x86.asm | bit-hack/colib | 3151b3041f0c4356efcc0300fb71536a71678254 | [
"MIT"
] | 1 | 2020-04-16T15:40:11.000Z | 2020-04-16T15:40:11.000Z | colib/colib_masm_win_x86.asm | bit-hack/colib | 3151b3041f0c4356efcc0300fb71536a71678254 | [
"MIT"
] | null | null | null | colib/colib_masm_win_x86.asm | bit-hack/colib | 3151b3041f0c4356efcc0300fb71536a71678254 | [
"MIT"
] | null | null | null | ; colib yield for windows x86 __cdecl
; MASM assembly
.386
.MODEL FLAT,C
.CODE
; unused
co_entry_asm PROC
ret
co_entry_asm ENDP
; void yield_( co_thread_t * thread )
; thread pushed on stack
;
co_yield_asm PROC
; pop thread object into eax
mov eax, [esp+4]
; push callee save registers
push esi
push ebx
push ebp
push esi
push edi
mov edi, [eax+4]
mov [edi], esp
mov esp, [eax]
; pop callee save registers
pop edi
pop esi
pop ebp
pop ebx
pop esi
; return to new thread
ret
co_yield_asm ENDP
co_ret_asm PROC
; pop the thread object into eax
pop eax
; switch stack to callee coroutine
mov edi, [eax+4]
mov esp, [edi]
; nullify current coroutine stack pointer
mov DWORD PTR [eax], 0
; pop callee save registers
pop edi
pop esi
pop ebp
pop ebx
pop esi
; return to callee
ret
co_ret_asm ENDP
END
| 15.134328 | 46 | 0.587771 |
43a518329c71625af4420147468d2cfdc7bc1a8f | 3,893 | asm | Assembly | tutorials/part12/src/main.asm | Threetwosevensixseven/ZalaXa | 190cfbc481ff7d3be5500c29c2c027b249a15cca | [
"MIT"
] | 5 | 2018-01-06T21:05:36.000Z | 2019-10-25T09:18:23.000Z | tutorials/part12/src/main.asm | Threetwosevensixseven/ZalaXa | 190cfbc481ff7d3be5500c29c2c027b249a15cca | [
"MIT"
] | null | null | null | tutorials/part12/src/main.asm | Threetwosevensixseven/ZalaXa | 190cfbc481ff7d3be5500c29c2c027b249a15cca | [
"MIT"
] | 2 | 2019-04-30T06:11:48.000Z | 2020-05-15T07:37:04.000Z | ; main.asm
zeusemulate "48K" ; Tell the Zeus emulator to be a 48K Spectrum
zoLogicOperatorsHighPri = false ; Zeus assembler options
zoSupportStringEscapes = false ; (see Config tab
zoAllowFloatingLabels = false ; for details)
Zeus_PC = Start ; Tell the Zeus emulator where to start running code at
org $8000 ; Tell the Zeus assembler where to place the code
Main proc ; A named PROCedure (also our start point)
::Start:
ld sp, Start ; Put our stack right below the program
Border(Black) ; Set the border to black using a helper macro
ei
jp SetupStars
call SetupMenu ; Display the menu and don't return until we press SPACE
call SetupGame ; Everything that might need resetting between the end
Loop: ; of a game and the start of the next one
halt ; Wait until the next 50th second frame
call AnimateDemo ; Animate our monster
call MovePlayer ; Move up/down/left/right
jp Loop ; Go into an endless loop (for now...)
pend
include "menu.asm" ; Routines for displaying the menu and setup the game
include "sprites.asm" ; Routines for displaying the player and NPCs
include "stars.asm" ; Starfield routines
include "utilities.asm" ; General purpose routines
include "database.asm" ; Data tables and graphics tiles
include "constants.asm" ; EQUates to make the code more readable
include "macros.asm" ; Macro definitions to make the code more readable
include "FZXdriver.asm" ; FZX proportional font routine
include "nirvana+.asm" ; The NIRVANA+ multicolour graphics engine
if zeusver < 66 ; Make sure we have a new enough version for bleeding-edge features!
zeuserror "Upgrade to Zeus v3.80 or above, available at http://www.desdes.com/products/oldfiles/zeus.htm."
endif
; Make tape file
End equ NIRVANA_org+9054 ; Calculate the last byte of our program
Size equ End-Start ; Count the bytes to save to tape
output_tap TapFile, "ZalaXa", "seven-fff.com/zalaxa", Start, Size, 2, Start
; Make a .TAP file. Parameters:
; 1) the file name
; 2) the name of the BASIC loader program
; 3) a comment that goes in the TAP header
; 4) Start of machine code program
; 5) Length of machine code program
; 6) Zeus mode 2 files use the standard ROM loader
; 7) Tell the BASIC loader what to run with RANDOMIZE
; USR (like Zeus_PC tells the Zeus emulator)
| 63.819672 | 124 | 0.441562 |
63eee513c98e7f8ff0d8d726bba7e2e9c2d0727e | 707 | asm | Assembly | oeis/292/A292202.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 11 | 2021-08-22T19:44:55.000Z | 2022-03-20T16:47:57.000Z | oeis/292/A292202.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 9 | 2021-08-29T13:15:54.000Z | 2022-03-09T19:52:31.000Z | oeis/292/A292202.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 3 | 2021-08-22T20:56:47.000Z | 2021-09-29T06:26:12.000Z | ; A292202: The n-th iteration of A062028 starting with n.
; Submitted by Jamie Morken(w4)
; 2,8,15,28,25,33,59,77,90,79,109,111,134,137,129,148,184,189,218,197,204,226,250,231,284,284,297,313,325,309,341,398,354,418,418,414,488,440,438,478,529,465,545,554,531,628,658,561,620,677,624,697,697,657,785,818,735,865,835,762,851,851,810,934,964,885,1007,983,948,1003,1048,981,1037,1061,1023,1099,1069,1059,1157,1157,1107,1150,1171,1119,1205,1181,1137,1246,1246,1215,1235,1259,1221,1306,1348,1266,1364,1364,1323,1348
mov $2,$0
add $0,1
mov $3,$0
lpb $3
add $2,1
mov $0,$2
seq $0,7953 ; Digital sum (i.e., sum of digits) of n; also called digsum(n).
sub $2,1
add $2,$0
sub $3,1
lpe
mov $0,$2
add $0,1
| 39.277778 | 420 | 0.700141 |
7da4e3340af7f8fc94075112ebad6a53382e70d2 | 66,380 | asm | Assembly | src/BreathOfTheWild/Graphics/patch_GUIAspectRatio.asm | UltraDragonZord/cemu_graphic_packs | 623703fa69c095250e5999e439c38c589cf7e3a7 | [
"CC0-1.0"
] | 1,002 | 2017-01-10T13:10:55.000Z | 2020-11-20T18:34:19.000Z | src/BreathOfTheWild/Graphics/patch_GUIAspectRatio.asm | UltraDragonZord/cemu_graphic_packs | 623703fa69c095250e5999e439c38c589cf7e3a7 | [
"CC0-1.0"
] | 347 | 2017-01-11T21:13:20.000Z | 2020-11-27T11:33:05.000Z | src/BreathOfTheWild/Graphics/patch_GUIAspectRatio.asm | UltraDragonZord/cemu_graphic_packs | 623703fa69c095250e5999e439c38c589cf7e3a7 | [
"CC0-1.0"
] | 850 | 2017-01-10T06:06:43.000Z | 2020-11-06T21:16:49.000Z | [BotW_GUIAspectRatio_V208]
moduleMatches = 0x6267BFD0
.origin = codecave
const_AspectRatio:
.float ($gameWidth/$gameHeight)/($width/$height)
const_AspectRatioHalf:
.float (($gameWidth/$gameHeight)/($width/$height))/2
const_ReverseAspectRatio:
.float ($width/$height)/($gameWidth/$gameHeight)
const_ReverseAspectRatio2x:
.float (($width/$height)/($gameWidth/$gameHeight))*2
const_PaddingLeftSide:
.float (($gameWidth/$gameHeight)/($width/$height)) * ((($width/($height/720))/2) - 640) * (-1)
const_PaddingRightSide:
.float (($gameWidth/$gameHeight)/($width/$height)) * ((($width/($height/720))/2) - 640)
const_AltPaddingLeftSide:
.float (($gameWidth/$gameHeight)/($width/$height)) * (($width/2) - 640) * (-1)
const_AltPaddingRightSide:
.float (($gameWidth/$gameHeight)/($width/$height)) * (($width/2) - 640)
newLineFormatScreen:
.string "Loading screen %s...%c"
newLineFormatPanes:
.string " Pane: %s...%c"
newLineCharacter:
.int 10
copyScreenString:
.string "PaAppDungeonBtnNextMoveFinalDLC_00" ; longest .blyt name
.align 4
copyScreenStringLen:
.int 34
copySubPanelString:
.string "PaAppDungeonBtnNextMoveFinalDLC_00" ; longest .blyt name
.align 4
copySubPanelStringLen:
.int 34
; free registers = r12, r10, r9, r11, r8 maybe
; r31 has the name of the pane at an offset at 0x80
_scalePaneGUI:
mflr r0
li r10, $ultrawideHUDMode
cmpwi r10, 0
beq exitScale
; Log currently loaded pane to register if logging is enabled
li r10, $enableUltrawideDebugLogging
cmpwi r10, 2
blt skipPaneLogging
mr r10, r3
mr r11, r4
mr r12, r5
crxor 4*cr1+eq, 4*cr1+eq, 4*cr1+eq
lis r3, newLineFormatPanes@ha
addi r3, r3, newLineFormatPanes@l
addi r4, r31, 0x80
lis r5, newLineCharacter@ha
lwz r5, newLineCharacter@l(r5)
bl import.coreinit.OSReport
mr r3, r10
mr r4, r11
mr r5, r12
skipPaneLogging:
; ------------------------------------------------------------------------------------------
; Store whether there's a subpanel name
addi r5, r31, 0x80
lbz r11, 0x0(r5)
cmpwi r11, 0x50
bne checkScreenNames
lbz r11, 0x1(r5)
cmpwi r11, 0x61
bne checkScreenNames
lis r11, copySubPanelStringLen@ha
lwz r11, copySubPanelStringLen@l(r11)
lis r12, copySubPanelString@ha
addi r12, r12, copySubPanelString@l
copySubPanelLoop:
lbzx r10, r5, r11
stbx r10, r12, r11
addi r11, r11, -1
cmpwi r11, -1
bne copySubPanelLoop
; ------------------------------------------------------------------------------------------
; Check which screen is getting loaded by using the copied screen name
checkScreenNames:
lis r5, copyScreenString@ha
addi r5, r5, copyScreenString@l
lis r10, scr_BootUp_00@ha
addi r10, r10, scr_BootUp_00@l
bla _compareString
beq scaleInOutToCenter
lis r10, scr_ChangeController_00@ha
addi r10, r10, scr_ChangeController_00@l
bla _compareString
beq scaleInOutScreenToRightSide
lis r10, scr_ChangeControllerDRC_00@ha
addi r10, r10, scr_ChangeControllerDRC_00@l
bla _compareString
beq scaleInOutScreenToRightSide
lis r10, scr_GamePadBG_00@ha ; Can't be scaled properly, even when scaling individually
addi r10, r10, scr_GamePadBG_00@l
bla _compareString
beq scaleRootToCenter
lis r10, scr_Title_00@ha
addi r10, r10, scr_Title_00@l
bla _compareString
beq scaleTitlePanes
lis r10, scr_SystemWindow_01@ha
addi r10, r10, scr_SystemWindow_01@l
bla _compareString
beq scaleSystemWindowPanes
lis r10, scr_AppSystemWindow_00@ha
addi r10, r10, scr_AppSystemWindow_00@l
bla _compareString
beq scaleAppSystemWindowPanes
lis r10, scr_AppSystemWindowNoBtn_00@ha
addi r10, r10, scr_AppSystemWindowNoBtn_00@l
bla _compareString
beq scaleInOutScreenToRightSide
lis r10, scr_OptionWindow_00@ha
addi r10, r10, scr_OptionWindow_00@l
bla _compareString
beq scaleOptionsMenuPanes
lis r10, scr_AmiiboWindow_00@ha
addi r10, r10, scr_AmiiboWindow_00@l
bla _compareString
beq scaleInOutToCenter
lis r10, scr_Fade@ha
addi r10, r10, scr_Fade@l
bla _compareString
beq scaleLoadingPanes
lis r10, scr_GameOver_00@ha
addi r10, r10, scr_GameOver_00@l
bla _compareString
beq scaleGameOverPanes
lis r10, scr_FadeStatus_00@ha
addi r10, r10, scr_FadeStatus_00@l
bla _compareString
beq scaleLoadingStatusPanes
lis r10, scr_Skip_00@ha
addi r10, r10, scr_Skip_00@l
bla _compareString
beq scaleSkipButtonPanes
lis r10, scr_LoadSaveIcon_00@ha
addi r10, r10, scr_LoadSaveIcon_00@l
bla _compareString
beq scaleLoadSaveIconPanes
lis r10, scr_MainScreen_00@ha
addi r10, r10, scr_MainScreen_00@l
bla _compareString
beq scaleMainScreenPanes
lis r10, scr_MainDungeon_00@ha
addi r10, r10, scr_MainDungeon_00@l
bla _compareString
beq scaleMainDungeonPanes
lis r10, scr_MainScreenMS_00@ha
addi r10, r10, scr_MainScreenMS_00@l
bla _compareString
beq scaleMainScreenMasterSwordPanes
lis r10, scr_WolfLinkHeartGauge_00@ha
addi r10, r10, scr_WolfLinkHeartGauge_00@l
bla _compareString
beq scaleWolfLinkHeartPanes
lis r10, scr_Rupee_00@ha
addi r10, r10, scr_Rupee_00@l
bla _compareString
beq scaleSimpleItemGetPanes
lis r10, scr_AkashNum_00@ha
addi r10, r10, scr_AkashNum_00@l
bla _compareString
beq scaleSimpleItemGetPanes
lis r10, scr_KologNum_00@ha
addi r10, r10, scr_KologNum_00@l
bla _compareString
beq scaleSimpleItemGetPanes
lis r10, scr_MamoNum_00@ha
addi r10, r10, scr_MamoNum_00@l
bla _compareString
beq scaleSimpleItemGetPanes
lis r10, scr_KeyNum_00@ha
addi r10, r10, scr_KeyNum_00@l
bla _compareString
beq scaleSimpleItemGetPanes
lis r10, scr_Time_00@ha
addi r10, r10, scr_Time_00@l
bla _compareString
beq scaleSimpleItemGetPanes
lis r10, scr_MainScreen3D_00@ha
addi r10, r10, scr_MainScreen3D_00@l
bla _compareString
beq scaleMainScreen3DPanes
lis r10, scr_MainShortCut_00@ha
addi r10, r10, scr_MainShortCut_00@l
bla _compareString
beq scaleMainShortCutPanes
lis r10, scr_MainHorse_00@ha
addi r10, r10, scr_MainHorse_00@l
bla _compareString
beq scaleHorseStaminaPanes
lis r10, scr_MainHardMode_00@ha
addi r10, r10, scr_MainHardMode_00@l
bla _compareString
beq scaleMainHardModePanes
lis r10, scr_PauseMenu_00@ha
addi r10, r10, scr_PauseMenu_00@l
bla _compareString
beq scalePauseMenuPanes
lis r10, scr_AppHome_00@ha
addi r10, r10, scr_AppHome_00@l
bla _compareString
beq scalePauseHomePanes
lis r10, scr_AppTool_00@ha
addi r10, r10, scr_AppTool_00@l
bla _compareString
beq scalePauseRunePanes
lis r10, scr_AppAlbum_00@ha
addi r10, r10, scr_AppAlbum_00@l
bla _compareString
beq scalePauseAlbumPanes
lis r10, scr_AppPictureBook_00@ha
addi r10, r10, scr_AppPictureBook_00@l
bla _compareString
beq scalePausePictureBookPanes
lis r10, scr_SystemWindow_00@ha
addi r10, r10, scr_SystemWindow_00@l
bla _compareString
beq scaleSystemWindowInventoryPanes
lis r10, scr_ControllerWindow_00@ha
addi r10, r10, scr_ControllerWindow_00@l
bla _compareString
beq scalePauseMenuAbilityControlsPanes
lis r10, scr_PauseMenuBG_00@ha
addi r10, r10, scr_PauseMenuBG_00@l
bla _compareString
beq scalePauseMenuBGPanes
lis r10, scr_PauseMenuInfo_00@ha
addi r10, r10, scr_PauseMenuInfo_00@l
bla _compareString
beq scalePauseMenuInfoPanes
lis r10, scr_PauseMenuRecipe_00@ha
addi r10, r10, scr_PauseMenuRecipe_00@l
bla _compareString
beq scaleTopInOutToCenterAndPos
lis r10, scr_PauseMenuMantan_00@ha
addi r10, r10, scr_PauseMenuMantan_00@l
bla _compareString
beq scaleTopInOutToCenterAndPos
lis r10, scr_ShopHorse_00@ha
addi r10, r10, scr_ShopHorse_00@l
bla _compareString
beq scaleShopHorsePanes
lis r10, scr_ShopBtnList5_00@ha
addi r10, r10, scr_ShopBtnList5_00@l
bla _compareString
beq scaleShop05Panes
lis r10, scr_ShopBtnList15_00@ha
addi r10, r10, scr_ShopBtnList15_00@l
bla _compareString
beq scaleTopInOutToCenter
lis r10, scr_ShopBtnList20_00@ha
addi r10, r10, scr_ShopBtnList20_00@l
bla _compareString
beq scaleShop20Panes
lis r10, scr_ShopInfo_00@ha
addi r10, r10, scr_ShopInfo_00@l
bla _compareString
beq scaleTopInOutToCenter
lis r10, scr_AppMap_00@ha
addi r10, r10, scr_AppMap_00@l
bla _compareString
beq scaleMapPanes
lis r10, scr_AppMapDungeon_00@ha
addi r10, r10, scr_AppMapDungeon_00@l
bla _compareString
beq scaleDungeonMapPanes
lis r10, scr_AppCamera_00@ha
addi r10, r10, scr_AppCamera_00@l
bla _compareString
beq scaleCameraPanes
lis r10, scr_DoCommand_00@ha
addi r10, r10, scr_DoCommand_00@l
bla _compareString
beq scaleDoCommandPanes
lis r10, scr_PickUp_00@ha
addi r10, r10, scr_PickUp_00@l
bla _compareString
beq scalePickupPanes
lis r10, scr_SousaGuide_00@ha
addi r10, r10, scr_SousaGuide_00@l
bla _compareString
beq scaleRuneGuidePanes
lis r10, scr_MessageDialog@ha
addi r10, r10, scr_MessageDialog@l
bla _compareString
beq scaleMessageDialogPanes
lis r10, scr_MessageSp_00@ha
addi r10, r10, scr_MessageSp_00@l
bla _compareString
beq scaleMessageSpPanes
lis r10, str_MessageSp_00_NoTop@ha
addi r10, r10, str_MessageSp_00_NoTop@l
bla _compareString
beq scaleMessageSpPanes
lis r10, scr_MessageGet_00@ha
addi r10, r10, scr_MessageGet_00@l
bla _compareString
beq scaleMessageGetPanes
lis r10, scr_Message3D_00@ha
addi r10, r10, scr_Message3D_00@l
bla _compareString
beq scaleMessage3DPanes
lis r10, scr_DemoMessage@ha
addi r10, r10, scr_DemoMessage@l
bla _compareString
beq scaleInOutToCenter
lis r10, scr_DemoMessage_00@ha
addi r10, r10, scr_DemoMessage_00@l
bla _compareString
beq scaleInOutToCenter
lis r10, scr_DemoName@ha
addi r10, r10, scr_DemoName@l
bla _compareString
beq scaleInOutToCenter
lis r10, scr_DemoName_00@ha
addi r10, r10, scr_DemoName_00@l
bla _compareString
beq scaleInOutToCenter
lis r10, scr_DemoNameEnemy@ha
addi r10, r10, scr_DemoNameEnemy@l
bla _compareString
beq scaleDemoNameEnemyPanes
lis r10, scr_DemoNameEnemy_00@ha
addi r10, r10, scr_DemoNameEnemy_00@l
bla _compareString
beq scaleDemoNameEnemyPanes
lis r10, scr_LastComplete_00@ha
addi r10, r10, scr_LastComplete_00@l
bla _compareString
beq scaleLastCompletePanes
lis r10, scr_StaffRoll_00@ha
addi r10, r10, scr_StaffRoll_00@l
bla _compareString
beq scaleCreditPanes
lis r10, scr_StaffRollDLC_00@ha
addi r10, r10, scr_StaffRollDLC_00@l
bla _compareString
beq scaleDLCCreditPanes
lis r10, scr_Thanks_00@ha
addi r10, r10, scr_Thanks_00@l
bla _compareString
beq scaleThanksPanes
lis r10, scr_End_00@ha
addi r10, r10, scr_End_00@l
bla _compareString
beq scaleInOutToCenter
lis r10, scr_HardMode_00@ha
addi r10, r10, scr_HardMode_00@l
bla _compareString
beq scaleInOutToCenter
lis r10, scr_DLCWindow_00@ha
addi r10, r10, scr_DLCWindow_00@l
bla _compareString
beq scaleDLCWindowPanes
lis r10, scr_BoxCursorTV@ha
addi r10, r10, scr_BoxCursorTV@l
bla _compareString
beq scaleCursorPanes
lis r10, scr_KeyBoradTextArea_00@ha
addi r10, r10, scr_KeyBoradTextArea_00@l
bla _compareString
beq scaleInOutToCenter
lis r10, scr_GameTitle_00@ha
addi r10, r10, scr_GameTitle_00@l
bla _compareString
beq scaleGameTitlePanes
lis r10, scr_HardModeTextDLC_00@ha
addi r10, r10, scr_HardModeTextDLC_00@l
bla _compareString
beq scaleInOutScreenToLeftSide
lis r10, scr_MessageTipsRunTime_00@ha
addi r10, r10, scr_MessageTipsRunTime_00@l
bla _compareString
beq scaleRuntimeMessagePanes
lis r10, scr_MessageTips_00@ha
addi r10, r10, scr_MessageTips_00@l
bla _compareString
beq scaleMessageTipsPanes
lis r10, scr_OPtext_00@ha
addi r10, r10, scr_OPtext_00@l
bla _compareString
beq scaleInOutToCenter
lis r10, scr_ChallengeWin_00@ha
addi r10, r10, scr_ChallengeWin_00@l
bla _compareString
beq scaleInOutScreenToRightSide
lis r10, scr_EnergyMeterDLC_00@ha
addi r10, r10, scr_EnergyMeterDLC_00@l
bla _compareString
beq scaleEnergyMeterDLCPanes
; lis r10, scr_Message_00@ha
; addi r10, r10, scr_Message_00@l
; bla _compareString
; beq scaleInOutToCenter
; If nothing matched, exit without setting the size or position of this pane
b exitScale
; ------------------------------------------------------------------------------------------
; Methods used to scale a specific pane type
scaleMainScreenPanes:
lis r5, copySubPanelString@ha
addi r5, r5, copySubPanelString@l
lis r10, str_Pa_ArrowPointer_00@ha
addi r10, r10, str_Pa_ArrowPointer_00@l
bla _compareString
beq scaleInOutToCenter
lis r10, str_Pa_ItemPointer_00@ha
addi r10, r10, str_Pa_ItemPointer_00@l
bla _compareString
beq scaleMainScreenRunePointingPanes
lis r10, str_Pa_ThrowingPointer_00@ha
addi r10, r10, str_Pa_ThrowingPointer_00@l
bla _compareString
beq scaleInOutToCenter
lis r10, str_Pa_CameraPointer_00@ha
addi r10, r10, str_Pa_CameraPointer_00@l
bla _compareString
beq scaleMainScreenCameraPointerPanes
lis r10, str_Pa_BtnZR_00@ha
addi r10, r10, str_Pa_BtnZR_00@l
bla _compareString
beq scaleMainScreenScopeFramePanes
lis r10, str_Pa_Deco_00@ha
addi r10, r10, str_Pa_Deco_00@l
bla _compareString
beq scaleMainScreenScopeFramePanes
lis r10, str_Pa_Gauge_00@ha
addi r10, r10, str_Pa_Gauge_00@l
bla _compareString
beq scaleMainScreenGaugePanes
lis r10, str_Pa_Time_00@ha
addi r10, r10, str_Pa_Time_00@l
bla _compareString
beq scaleMainScreenTimePanes
lis r10, str_Pa_Sensor_00@ha
addi r10, r10, str_Pa_Sensor_00@l
bla _compareString
beq scaleSensorMeterPanes
lis r10, str_Pa_SoundGauge_00@ha
addi r10, r10, str_Pa_SoundGauge_00@l
bla _compareString
beq scaleSoundMeterPanes
lis r10, str_Pa_TempMeter_00@ha
addi r10, r10, str_Pa_TempMeter_00@l
bla _compareString
beq scaleTempMeterPanes
lis r10, str_Pa_Weather_00@ha
addi r10, r10, str_Pa_Weather_00@l
bla _compareString
beq scaleMainScreenWeatherPanes
lis r10, str_Pa_Information_00@ha
addi r10, r10, str_Pa_Information_00@l
bla _compareString
beq scaleMainScreenInformationTextPanes
lis r10, str_Pa_LocationName_00@ha
addi r10, r10, str_Pa_LocationName_00@l
bla _compareString
beq scaleMainScreenLocationTextPanes
lis r10, str_Pa_LocationNameS_00@ha
addi r10, r10, str_Pa_LocationNameS_00@l
bla _compareString
beq scaleMainScreenSmallLocationTextPanes
lis r10, str_Pa_QuestName_00@ha
addi r10, r10, str_Pa_QuestName_00@l
bla _compareString
beq scaleMainScreenQuestTextPanes
lis r10, str_Pa_BossGauge_00@ha
addi r10, r10, str_Pa_BossGauge_00@l
bla _compareString
beq scaleMainScreenBossGaugePanes
addi r5, r31, 0x80
lis r10, str_N_State_00@ha
addi r10, r10, str_N_State_00@l
bla _compareString
beq scalePaneToLeftSideIf
lis r10, str_Pa_SinJu_00@ha
addi r10, r10, str_Pa_SinJu_00@l
bla _compareString
beq scalePaneAndKeepPosIf
lis r10, str_Pa_SinJu_01@ha
addi r10, r10, str_Pa_SinJu_01@l
bla _compareString
beq scalePaneAndKeepPosIf
lis r10, str_Pa_SinJu_02@ha
addi r10, r10, str_Pa_SinJu_02@l
bla _compareString
beq scalePaneAndKeepPosIf
lis r10, str_Pa_SinJu_03@ha
addi r10, r10, str_Pa_SinJu_03@l
bla _compareString
beq scalePaneAndKeepPosIf
lis r10, str_Pa_SinJu_03@ha
addi r10, r10, str_Pa_SinJu_03@l
bla _compareString
beq scalePaneAndKeepPosIf
b exitScale
const_SensorsOffset:
.float 392.0
scaleSoundMeterPanes:
addi r5, r31, 0x80
lis r10, const_SensorsOffset@ha
lfs f12, const_SensorsOffset@l(r10)
lis r10, str_N_InOut_00@ha
addi r10, r10, str_N_InOut_00@l
bla _compareString
beq scalePaneAndKeepCustomPosIf
b exitScale
scaleSensorMeterPanes:
addi r5, r31, 0x80
lis r10, const_SensorsOffset@ha
lfs f12, const_SensorsOffset@l(r10)
lis r10, str_N_InOut_00@ha
addi r10, r10, str_N_InOut_00@l
bla _compareString
beq scalePaneAndKeepCustomPosIf
b exitScale
scaleTempMeterPanes:
addi r5, r31, 0x80
lis r10, const_SensorsOffset@ha
lfs f12, const_SensorsOffset@l(r10)
lis r10, str_N_InOut_00@ha
addi r10, r10, str_N_InOut_00@l
bla _compareString
beq scalePaneAndKeepCustomPosIf
b exitScale
const_TimeOffset:
.float (($ultrawideHUDMode == 1) * (342*0.85)) + (($ultrawideHUDMode == 2)*(342*(1/0.85)))
scaleMainScreenTimePanes:
addi r5, r31, 0x80
lis r10, const_TimeOffset@ha
lfs f12, const_TimeOffset@l(r10)
lis r10, str_N_All_00@ha
addi r10, r10, str_N_All_00@l
bla _compareString
beq scalePaneAndKeepCustomPosIf
b exitScale
scaleMainScreenWeatherPanes:
addi r5, r31, 0x80
lis r10, str_N_InOut_00@ha
addi r10, r10, str_N_InOut_00@l
bla _compareString
beq scalePaneAndKeepPosIf
b exitScale
scaleMainScreenInformationTextPanes:
addi r5, r31, 0x80
lis r10, str_Pa_Information_00@ha
addi r10, r10, str_Pa_Information_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleMainScreenLocationTextPanes:
addi r5, r31, 0x80
lis r10, str_Pa_LocationName_00@ha
addi r10, r10, str_Pa_LocationName_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleMainScreenQuestTextPanes:
addi r5, r31, 0x80
lis r10, str_Pa_QuestName_00@ha
addi r10, r10, str_Pa_QuestName_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_P_Base_01@ha
addi r10, r10, str_P_Base_01@l
bla _compareString
beq scalePaneReverse
lis r10, str_P_Base_00@ha
addi r10, r10, str_P_Base_00@l
bla _compareString
beq scalePaneReverse
b exitScale
scaleMainScreenSmallLocationTextPanes:
addi r5, r31, 0x80
lis r10, str_Pa_LocationNameS_00@ha
addi r10, r10, str_Pa_LocationNameS_00@l
bla _compareString
beq scalePaneToLeftSideIf
b exitScale
scaleMainScreenBossGaugePanes:
addi r5, r31, 0x80
lis r10, str_N_All_00@ha
addi r10, r10, str_N_All_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleMainScreenGaugePanes:
addi r5, r31, 0x80
lis r10, str_N_All_00@ha
addi r10, r10, str_N_All_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleMainScreenCameraPointerPanes:
addi r5, r31, 0x80
lis r10, str_N_InOut_01@ha
addi r10, r10, str_N_InOut_01@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_Dungeon_00@ha
addi r10, r10, str_N_Dungeon_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleMainScreenScopeFramePanes:
addi r5, r31, 0x80
lis r10, str_N_TimeLineDemo_00@ha
addi r10, r10, str_N_TimeLineDemo_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_IconSeek_00@ha
addi r10, r10, str_N_IconSeek_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleMainScreenRunePointingPanes:
addi r5, r31, 0x80
lis r10, str_N_SunLight_00@ha
addi r10, r10, str_N_SunLight_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleMainDungeonPanes:
addi r5, r31, 0x80
lis r10, str_Pa_LocationNameS_00@ha
addi r10, r10, str_Pa_LocationNameS_00@l
bla _compareString
beq scalePaneToLeftSideIf
lis r10, str_Pa_Message_00@ha
addi r10, r10, str_Pa_Message_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_Pa_Title_00@ha
addi r10, r10, str_Pa_Title_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleMainDungeonLocationNames:
addi r5, r31, 0x80
lis r10, str_N_In_00@ha
addi r10, r10, str_N_In_00@l
bla _compareString
beq scalePaneToLeftSideIf
b exitScale
scaleSpiritOrbPanes:
addi r5, r31, 0x80
lis r10, str_W_Base_00@ha
addi r10, r10, str_W_Base_00@l
bla _compareString
beq scalePaneAndKeepPosIf
lis r10, str_T_Time_00@ha
addi r10, r10, str_T_Time_00@l
bla _compareString
beq scalePaneAndKeepPosIf
b exitScale
scaleSimpleItemGetPanes:
lis r5, copySubPanelString@ha
lbz r5, copySubPanelString@l(r5)
cmpwi r5, 0
beq scaleItemGetNoPanes
continueSimpleItemGetPanes:
lis r5, copySubPanelString@ha
addi r5, r5, copySubPanelString@l
lis r10, scr_PaPlusMinus_00@ha
addi r10, r10, scr_PaPlusMinus_00@l
bla _compareString
beq scaleItemGetPlusMinusPanes
addi r5, r31, 0x80
lis r10, str_W_Base_00@ha
addi r10, r10, str_W_Base_00@l
bla _compareString
beq scalePaneAndKeepPosIf
lis r10, str_T_Num_00@ha
addi r10, r10, str_T_Num_00@l
bla _compareString
beq scalePaneAndKeepPosIf
lis r10, str_T_Time_00@ha
addi r10, r10, str_T_Time_00@l
bla _compareString
beq scalePaneAndKeepPosIf
lis r10, str_T_Rupee_00@ha
addi r10, r10, str_T_Rupee_00@l
bla _compareString
beq scalePaneAndKeepPosIf
lis r10, str_T_KeyNum_00@ha
addi r10, r10, str_T_KeyNum_00@l
bla _compareString
beq scalePaneAndKeepPosIf
lis r10, str_P_Icon_00@ha
addi r10, r10, str_P_Icon_00@l
bla _compareString
beq scalePaneAndKeepPosIf
lis r10, str_N_Icon_00@ha
addi r10, r10, str_N_Icon_00@l
bla _compareString
beq scalePaneAndKeepPosIf
lis r10, str_P_KologNuts_00@ha
addi r10, r10, str_P_KologNuts_00@l
bla _compareString
beq scalePaneAndKeepPosIf
b exitScale
const_ItemGetPlusMinusOffset:
.float -514.0
scaleItemGetPlusMinusPanes:
addi r5, r31, 0x80
lis r10, const_ItemGetPlusMinusOffset@ha
lfs f12, const_ItemGetPlusMinusOffset@l(r10)
lis r10, str_N_InOut_00@ha
addi r10, r10, str_N_InOut_00@l
bla _compareString
beq scalePaneAndKeepCustomPosIf
b exitScale
scaleItemGetNoPanes:
addi r5, r31, 0x80
lis r10, str_N_Capture_00@ha
addi r10, r10, str_N_Capture_00@l
bla _compareString
beq scalePaneAndKeepPosIf
b continueSimpleItemGetPanes
scaleWolfLinkHeartPanes:
lis r5, copySubPanelString@ha
addi r5, r5, copySubPanelString@l
lis r10, str_Pa_HeartGauge_00@ha
addi r10, r10, str_Pa_HeartGauge_00@l
bla _compareString
beq scaleWolfLinkHeartsPanes
lis r5, copySubPanelString@ha
lbz r5, copySubPanelString@l(r5)
cmpwi r5, 0
beq scaleWolfLinkHeartNoPanes
b exitScale
scaleWolfLinkHeartNoPanes:
addi r5, r31, 0x80
lis r10, str_P_Sh_00@ha
addi r10, r10, str_P_Sh_00@l
bla _compareString
beq scalePaneAndKeepPosIf
lis r10, str_P_Illust_00@ha
addi r10, r10, str_P_Illust_00@l
bla _compareString
beq scalePaneAndKeepPosIf
b exitScale
const_WolfHeartOffset:
.float -468.0
scaleWolfLinkHeartsPanes:
addi r5, r31, 0x80
lis r10, str_T_Name_00@ha
addi r10, r10, str_T_Name_00@l
bla _compareString
beq scalePaneAndKeepPosIf
lis r10, const_WolfHeartOffset@ha
lfs f12, const_WolfHeartOffset@l(r10)
lis r10, str_N_InOut_00@ha
addi r10, r10, str_N_InOut_00@l
bla _compareString
beq scalePaneAndKeepCustomPosIf
b exitScale
scaleMainScreenMasterSwordPanes:
lis r5, copySubPanelString@ha
lbz r5, copySubPanelString@l(r5)
cmpwi r5, 0
beq scaleMainScreenMasterSwordNoPanes
b exitScale
scaleMainScreenMasterSwordNoPanes:
addi r5, r31, 0x80
lis r10, str_N_InOut_00@ha
addi r10, r10, str_N_InOut_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleMainScreen3DPanes:
lis r5, copySubPanelString@ha
addi r5, r5, copySubPanelString@l
lis r10, str_Pa_NoticeItem_00@ha
addi r10, r10, str_Pa_NoticeItem_00@l
bla _compareString
beq scaleMainScreen3DPickupPanes
lis r10, str_Pa_StaminaGauge_00@ha
addi r10, r10, str_Pa_StaminaGauge_00@l
bla _compareString
beq scaleMainScreen3DStaminaPanes
lis r10, str_Pa_EnemyMark_00@ha
addi r10, r10, str_Pa_EnemyMark_00@l
bla _compareString
beq scaleMainScreen3DEnemyNoticePanes
lis r10, str_Pa_EnemyGauge_00@ha
addi r10, r10, str_Pa_EnemyGauge_00@l
bla _compareString
beq scaleMainScreen3DEnemyGaugePanes
lis r10, str_Pa_NoticeZ_00@ha
addi r10, r10, str_Pa_NoticeZ_00@l
bla _compareString
beq scaleInOutToCenter
lis r10, str_Pa_BonusStaminaGauge_00@ha
addi r10, r10, str_Pa_BonusStaminaGauge_00@l
bla _compareString
beq scaleMainScreen3DBonusStaminaPanes
b exitScale
scaleMainScreen3DStaminaPanes:
addi r5, r31, 0x80
lis r10, str_N_All_00@ha
addi r10, r10, str_N_All_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleMainScreen3DBonusStaminaPanes:
addi r5, r31, 0x80
lis r10, str_N_Size_05@ha
addi r10, r10, str_N_Size_05@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleMainScreen3DPickupPanes:
addi r5, r31, 0x80
lis r10, str_N_Capture_00@ha
addi r10, r10, str_N_Capture_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_ModeItem_00@ha
addi r10, r10, str_N_ModeItem_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleMainScreen3DEnemyNoticePanes:
addi r5, r31, 0x80
lis r10, str_N_Change_00@ha
addi r10, r10, str_N_Change_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_Change_01@ha
addi r10, r10, str_N_Change_01@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleMainScreen3DEnemyGaugePanes:
addi r5, r31, 0x80
lis r10, str_N_Gauge_00@ha
addi r10, r10, str_N_Gauge_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleHorseStaminaPanes:
addi r5, r31, 0x80
lis r10, str_N_ExUse_01@ha
addi r10, r10, str_N_ExUse_01@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleMainShortCutPanes:
addi r5, r31, 0x80
lis r10, str_N_MainAll_00@ha ; scales the DPAD guide on the right
addi r10, r10, str_N_MainAll_00@l
bla _compareString
beq scalePaneAndKeepPosIf
lis r10, str_N_Cut_00@ha ; scales the item/rune selection bar
addi r10, r10, str_N_Cut_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_Capture_00@ha
addi r10, r10, str_N_Capture_00@l
bla _compareString
beq scalePaneAndPos
lis r10, str_N_Capture_01@ha
addi r10, r10, str_N_Capture_01@l
bla _compareString
beq scalePaneAndPos
lis r10, str_P_CaptureMask_00@ha
addi r10, r10, str_P_CaptureMask_00@l
bla _compareString
beq scalePaneAndPos
lis r10, str_P_CaptureMask_01@ha
addi r10, r10, str_P_CaptureMask_01@l
bla _compareString
beq scalePaneAndPos
lis r10, str_N_PartsSize_00@ha ; reverse scaling on pane that decides spacing between runes/items
addi r10, r10, str_N_PartsSize_00@l
bla _compareString
beq scalePaneReverse
b exitScale
scaleMainHardModePanes:
addi r5, r31, 0x80
lis r10, str_N_InOut_00@ha
addi r10, r10, str_N_InOut_00@l
bla _compareString
beq scalePaneAndKeepPos
lis r10, str_N_Glow_00@ha
addi r10, r10, str_N_Glow_00@l
bla _compareString
beq scalePaneAndKeepPos
b exitScale
scaleMapPanes:
lis r5, copySubPanelString@ha
lbz r5, copySubPanelString@l(r5)
cmpwi r5, 0
beq scaleMapNoPanes
lis r5, copySubPanelString@ha
addi r5, r5, copySubPanelString@l
lis r10, str_Pa_Map_00@ha
addi r10, r10, str_Pa_Map_00@l
bla _compareString
beq scaleMapTilesPanes
; Scale sensors background back
# lis r10, str_Pa_SensorBox_00@ha
# addi r10, r10, str_Pa_SensorBox_00@l
# bla _compareString
# beq scaleMapSettingsPanes
# lis r10, str_Pa_SubBtnChange_00@ha
# addi r10, r10, str_Pa_SubBtnChange_00@l
# bla _compareString
# beq scaleMapSettingsPanes
# ; Scale stamp box background back
# lis r10, str_Pa_StampBox_00@ha
# addi r10, r10, str_Pa_StampBox_00@l
# bla _compareString
# beq scaleMapSettingsPanes
# lis r10, str_Pa_StampNum_00@ha
# addi r10, r10, str_Pa_StampNum_00@l
# bla _compareString
# beq scaleMapSettingsPanes
addi r5, r31, 0x80
# lis r10, str_N_Cut_01@ha
# addi r10, r10, str_N_Cut_01@l
# bla _compareString
# beq scalePaneReverse
# lis r10, str_N_Sunaarashi_00@ha
# addi r10, r10, str_N_Sunaarashi_00@l
# bla _compareString
# beq scalePaneReverse
# lis r10, str_Pa_MapOpen_00@ha
# addi r10, r10, str_Pa_MapOpen_00@l
# bla _compareString
# beq scalePaneNormal
b exitScale
scaleMapNoPanes:
addi r5, r31, 0x80
lis r10, str_N_InOut_00@ha
addi r10, r10, str_N_InOut_00@l
bla _compareString
beq scaleMapAndStore
lis r10, str_N_Cut_00@ha
addi r10, r10, str_N_Cut_00@l
bla _compareString
beq scaleOnlySizeReverse
lis r10, str_Black8_01@ha
addi r10, r10, str_Black8_01@l
bla _compareString
beq scalePaneReverse
b exitScale
scaleMapTilesPanes:
addi r5, r31, 0x80
lis r10, str_B_MapCapture_00@ha
addi r10, r10, str_B_MapCapture_00@l
bla _compareString
beq scaleOnlySizeReverse
# lis r10, str_N_MiniMap_00@ha
# addi r10, r10, str_N_MiniMap_00@l
# bla _compareString
# beq movePaneToRightSide
b exitScale
scaleMapSettingsPanes:
addi r5, r31, 0x80
lis r10, str_P_FBLayout_00@ha
addi r10, r10, str_P_FBLayout_00@l
bla _compareString
beq scalePaneReverse
lis r10, str_White8_00@ha
addi r10, r10, str_White8_00@l
bla _compareString
beq scalePaneReverse
lis r10, str_White8_01@ha
addi r10, r10, str_White8_01@l
bla _compareString
beq scalePaneReverse
lis r10, str_P_BG_03@ha
addi r10, r10, str_P_BG_03@l
bla _compareString
beq scalePaneReverse
lis r10, str_P_Abstract_00@ha
addi r10, r10, str_P_Abstract_00@l
bla _compareString
beq scalePaneReverse
lis r10, str_P_Abstract_05@ha
addi r10, r10, str_P_Abstract_05@l
bla _compareString
beq scalePaneReverse
lis r10, str_P_SSFrameCore_00@ha
addi r10, r10, str_P_SSFrameCore_00@l
bla _compareString
beq scalePaneReverse
b exitScale
scaleDungeonMapPanes:
; could-fix: hook dungeon map changing too
lis r5, copySubPanelString@ha
lbz r5, copySubPanelString@l(r5)
cmpwi r5, 0
beq scaleDungeonMapNoPanes
lis r5, copySubPanelString@ha
addi r5, r5, copySubPanelString@l
lis r10, str_Pa_SensorBox_00@ha
addi r10, r10, str_Pa_SensorBox_00@l
bla _compareString
beq scaleDungeonMapSensorBoxPanes
lis r10, str_Pa_SubBtnChange_00@ha
addi r10, r10, str_Pa_SubBtnChange_00@l
bla _compareString
beq scaleDungeonMapSensorBoxPanes
lis r10, str_Pa_Btn_00@ha
addi r10, r10, str_Pa_Btn_00@l
bla _compareString
beq scaleDungeonMapSensorBoxPanes
addi r5, r31, 0x80
b exitScale
scaleDungeonMapNoPanes:
addi r5, r31, 0x80
lis r10, str_N_Born_00@ha
addi r10, r10, str_N_Born_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleDungeonMapSensorBoxPanes:
addi r5, r31, 0x80
lis r10, str_Pa_SensorBox_00@ha
addi r10, r10, str_Pa_SensorBox_00@l
bla _compareString
beq scalePaneReverse
lis r10, str_N_BtnPos@ha
addi r10, r10, str_N_BtnPos@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_SubIn_00@ha
addi r10, r10, str_N_SubIn_00@l
bla _compareString
beq scalePaneAndPos
lis r10, str_P_Sh_00@ha
addi r10, r10, str_P_Sh_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_T_SensorTitle_00@ha
addi r10, r10, str_T_SensorTitle_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleCameraPanes:
lis r5, copySubPanelString@ha
addi r5, r5, copySubPanelString@l
lis r10, str_Pa_BtnZR_00@ha
addi r10, r10, str_Pa_BtnZR_00@l
bla _compareString
beq scaleCameraFramePanes
lis r10, str_Pa_Deco_00@ha
addi r10, r10, str_Pa_Deco_00@l
bla _compareString
beq scaleCameraFramePanes
addi r5, r31, 0x80
lis r10, str_N_ModeCamera_00@ha
addi r10, r10, str_N_ModeCamera_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_FirstOut_00@ha
addi r10, r10, str_N_FirstOut_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_Limit_00@ha
addi r10, r10, str_N_Limit_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_P_Capture_00@ha
addi r10, r10, str_P_Capture_00@l
bla _compareString
beq scalePaneReverse
b exitScale
scaleCameraFramePanes:
addi r5, r31, 0x80
lis r10, str_N_TimeLineDemo_00@ha
addi r10, r10, str_N_TimeLineDemo_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_IconSeek_00@ha
addi r10, r10, str_N_IconSeek_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleDoCommandPanes:
addi r5, r31, 0x80
lis r10, str_N_MS_00@ha
addi r10, r10, str_N_MS_00@l
bla _compareString
beq scalePaneNormal
b exitScale
const_590:
.float 25
scalePickupPanes:
addi r5, r31, 0x80
lis r10, const_590@ha
lfs f12, const_590@l(r10)
# lis r10, str_RootPane@ha
# addi r10, r10, str_RootPane@l
# bla _compareString
# beq movePaneToCustomSize
lis r10, str_Pa_PickUpWin_00@ha
addi r10, r10, str_Pa_PickUpWin_00@l
bla _compareString
beq scalePaneAndKeepPosIf
b exitScale
scaleRuneGuidePanes:
addi r5, r31, 0x80
lis r10, str_N_Align_00@ha
addi r10, r10, str_N_Align_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleMessageSpPanes:
addi r5, r31, 0x80
lis r10, str_N_Seeker_00@ha
addi r10, r10, str_N_Seeker_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_Pos_00@ha
addi r10, r10, str_N_Pos_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_BtnNum_00@ha
addi r10, r10, str_N_BtnNum_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_Cursor_00@ha
addi r10, r10, str_N_Cursor_00@l
bla _compareString
beq movePaneToRightSideAlt
lis r10, str_B_Hit_00@ha
addi r10, r10, str_B_Hit_00@l
bla _compareString
beq movePaneToRightSideAlt
b exitScale
scaleMessageDialogPanes:
addi r5, r31, 0x80
lis r10, str_N_Pos_00@ha
addi r10, r10, str_N_Pos_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_Cursor_00@ha
addi r10, r10, str_N_Cursor_00@l
bla _compareString
beq movePaneToRightSideAlt
lis r10, str_B_Hit_00@ha
addi r10, r10, str_B_Hit_00@l
bla _compareString
beq movePaneToRightSideAlt
b exitScale
scaleMessageGetPanes:
lis r5, copySubPanelString@ha
addi r5, r5, copySubPanelString@l
lis r10, str_Pa_Star_00@ha
addi r10, r10, str_Pa_Star_00@l
bla _compareString
beq scaleMessageGetBackgroundAndIconPanes
addi r5, r31, 0x80
lis r10, str_N_DecideOut_00@ha
addi r10, r10, str_N_DecideOut_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_P_Capture_01@ha
addi r10, r10, str_P_Capture_01@l
bla _compareString
beq scalePaneNormal
lis r10, str_P_Capture_04@ha
addi r10, r10, str_P_Capture_04@l
bla _compareString
beq scalePaneNormal
lis r10, str_P_Capture_02@ha
addi r10, r10, str_P_Capture_02@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleMessageGetBackgroundAndIconPanes:
addi r5, r31, 0x80
lis r10, str_W_Base_00@ha
addi r10, r10, str_W_Base_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_Icon_00@ha
addi r10, r10, str_N_Icon_00@l
bla _compareString
beq scalePaneAndPos
lis r10, str_N_State_00@ha
addi r10, r10, str_N_State_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_P_Capture_00@ha
addi r10, r10, str_P_Capture_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_P_Capture_03@ha
addi r10, r10, str_P_Capture_03@l
bla _compareString
beq scalePaneNormal
lis r10, str_Nt_DecoLT_00@ha
addi r10, r10, str_Nt_DecoLT_00@l
bla _compareString
beq scalePaneAndPos
lis r10, str_Nt_DecoLT_01@ha
addi r10, r10, str_Nt_DecoLT_01@l
bla _compareString
beq scalePaneAndPos
lis r10, str_Nt_DecoRT_00@ha
addi r10, r10, str_Nt_DecoRT_00@l
bla _compareString
beq scalePaneAndPos
lis r10, str_Nt_DecoRT_01@ha
addi r10, r10, str_Nt_DecoRT_01@l
bla _compareString
beq scalePaneAndPos
lis r10, str_Nt_DecoLB_00@ha
addi r10, r10, str_Nt_DecoLB_00@l
bla _compareString
beq scalePaneAndPos
lis r10, str_Nt_DecoLB_01@ha
addi r10, r10, str_Nt_DecoLB_01@l
bla _compareString
beq scalePaneAndPos
lis r10, str_Nt_DecoRB_00@ha
addi r10, r10, str_Nt_DecoRB_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_Nt_DecoRB_01@ha
addi r10, r10, str_Nt_DecoRB_01@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleMessage3DPanes:
addi r5, r31, 0x80
lis r10, str_N_Capture_00@ha
addi r10, r10, str_N_Capture_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_All_00@ha
addi r10, r10, str_N_All_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleRuntimeMessagePanes:
addi r5, r31, 0x80
lis r10, str_W_Base_00@ha
addi r10, r10, str_W_Base_00@l
bla _compareString
beq scalePaneAndKeepPosIf
lis r10, str_T_Text_00@ha
addi r10, r10, str_T_Text_00@l
bla _compareString
beq scalePaneAndKeepPosIf
lis r10, str_T_Text_00_JPja@ha
addi r10, r10, str_T_Text_00_JPja@l
bla _compareString
beq scalePaneAndKeepPosIf
lis r10, str_N_GuideOn_00@ha
addi r10, r10, str_N_GuideOn_00@l
bla _compareString
beq scalePaneAndKeepPosIf
b exitScale
scaleCursorPanes:
addi r5, r31, 0x80
lis r10, str_N_Porch_00@ha
addi r10, r10, str_N_Porch_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_Seek_00@ha
addi r10, r10, str_N_Seek_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_Porch_01@ha
addi r10, r10, str_N_Porch_01@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_Seek_01@ha
addi r10, r10, str_N_Seek_01@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_Porch_02@ha
addi r10, r10, str_N_Porch_02@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_Seek_02@ha
addi r10, r10, str_N_Seek_02@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_Porch_03@ha
addi r10, r10, str_N_Porch_03@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_Seek_03@ha
addi r10, r10, str_N_Seek_03@l
bla _compareString
beq scalePaneNormal
b exitScale
scalePauseMenuPanes:
addi r5, r31, 0x80
lis r5, copySubPanelString@ha
lbz r5, copySubPanelString@l(r5)
cmpwi r5, 0
beq scalePauseMenuNoPanes
lis r5, copySubPanelString@ha
addi r5, r5, copySubPanelString@l
lis r10, str_Pa_Quest_00@ha
addi r10, r10, str_Pa_Quest_00@l
bla _compareString
beq scalePauseMenuQuestPanes
addi r5, r31, 0x80
lis r10, str_N_Slide_02@ha ; scales save/controller screen fully
addi r10, r10, str_N_Slide_02@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_InCap_01@ha ; scales masks for inventory tabs
addi r10, r10, str_N_InCap_01@l
bla _compareString
beq scalePaneAndPos
lis r10, str_N_InOutGear_01@ha ; scales category and tabs in inventory screen
addi r10, r10, str_N_InOutGear_01@l
bla _compareString
beq scalePaneAndPos
lis r10, str_N_InOutQuest_02@ha ; scales quest slide
addi r10, r10, str_N_InOutQuest_02@l
bla _compareString
beq scalePaneNormal
lis r10, str_Pa_Page_00@ha
addi r10, r10, str_Pa_Page_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scalePauseMenuNoPanes:
addi r5, r31, 0x80
lis r10, str_B_Page20_00@ha ; Scales inventory placement
addi r10, r10, str_B_Page20_00@l
bla _compareString
beq scalePaneAndPos
lis r10, str_N_InOut_00@ha ; Scales inventory screen
addi r10, r10, str_N_InOut_00@l
bla _compareString
beq scalePaneAndPos
b exitScale
scalePauseMenuQuestPanes:
addi r5, r31, 0x80
lis r10, str_N_Cut_00@ha
addi r10, r10, str_N_Cut_00@l
bla _compareString
beq scalePaneReverse
b exitScale
scalePauseMenuBGPanes: ; TODO: Maybe could look a bit nicer
addi r5, r31, 0x80
; lis r10, str_W_BlackBG_00@ha
; addi r10, r10, str_W_BlackBG_00@l
; bla _compareString
; beq scalePaneAndSize
; lis r10, str_N_Slide_01@ha
; addi r10, r10, str_N_Slide_01@l
; bla _compareString
; beq scalePaneAndSize
; lis r10, str_N_Slide_02@ha
; addi r10, r10, str_N_Slide_02@l
; bla _compareString
; beq scalePaneAndSize
b exitScale
scalePauseMenuInfoPanes:
lis r5, copySubPanelString@ha
lbz r5, copySubPanelString@l(r5)
cmpwi r5, 0
beq scalePauseMenuInfoNoPanes
addi r5, r31, 0x80
lis r10, str_N_InOut_01@ha
addi r10, r10, str_N_InOut_01@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_Slide_00@ha
addi r10, r10, str_N_Slide_00@l
bla _compareString
beq scaleOnlyPos
lis r10, str_Pa_RotateGuide_00@ha
addi r10, r10, str_Pa_RotateGuide_00@l
bla _compareString
beq scalePaneAndKeepPosIf
lis r10, str_N_State_00@ha
addi r10, r10, str_N_State_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_State_03@ha
addi r10, r10, str_N_State_03@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_TitleBar_00@ha
addi r10, r10, str_N_TitleBar_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_TitleBarDown_00@ha
addi r10, r10, str_N_TitleBarDown_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scalePauseMenuInfoNoPanes:
addi r5, r31, 0x80
; lis r10, str_N_InOut_00@ha
; addi r10, r10, str_N_InOut_00@l
; bla _compareString
; beq scalePaneNormal
b exitScale
scalePauseHomePanes:
addi r5, r31, 0x80
lis r10, str_N_IconSeek_00@ha
addi r10, r10, str_N_IconSeek_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_TimeLineDemo_00@ha
addi r10, r10, str_N_TimeLineDemo_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scalePauseRunePanes:
addi r5, r31, 0x80
lis r10, str_N_InOut_00@ha
addi r10, r10, str_N_InOut_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_NoContents_00@ha
addi r10, r10, str_N_NoContents_00@l
bla _compareString
beq movePaneToRightSide
b exitScale
scalePauseAlbumPanes:
addi r5, r31, 0x80
lis r10, str_Pa_Page_00@ha
addi r10, r10, str_Pa_Page_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_InOut_02@ha
addi r10, r10, str_N_InOut_02@l
bla _compareString
beq scalePaneNormal
lis r10, str_Pa_Photo_00@ha
addi r10, r10, str_Pa_Photo_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_NoContents_00@ha
addi r10, r10, str_N_NoContents_00@l
bla _compareString
beq movePaneToRightSide
b exitScale
scalePausePictureBookPanes:
addi r5, r31, 0x80
lis r10, str_Pa_Page_00@ha
addi r10, r10, str_Pa_Page_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_Contents_00@ha
addi r10, r10, str_N_Contents_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_PartsSize_00@ha
addi r10, r10, str_N_PartsSize_00@l
bla _compareString
beq scalePaneReverse
lis r10, str_N_InOut_02@ha
addi r10, r10, str_N_InOut_02@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_NoContents_00@ha
addi r10, r10, str_N_NoContents_00@l
bla _compareString
beq movePaneToRightSide
lis r10, str_N_MapPos_00@ha
addi r10, r10, str_N_MapPos_00@l
bla _compareString
beq moveKeepPos
b exitScale
scaleShopHorsePanes:
lis r5, copySubPanelString@ha
lbz r5, copySubPanelString@l(r5)
cmpwi r5, 0
beq scaleShopHorseNoPanes
addi r5, r31, 0x80
lis r10, str_N_Info_00@ha
addi r10, r10, str_N_Info_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleShopHorseNoPanes:
addi r5, r31, 0x80
lis r10, str_N_InOut_00@ha
addi r10, r10, str_N_InOut_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleShop05Panes:
addi r5, r31, 0x80
lis r10, str_N_InOut_01@ha
addi r10, r10, str_N_InOut_01@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_InOut_02@ha
addi r10, r10, str_N_InOut_02@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleShop20Panes:
addi r5, r31, 0x80
lis r10, str_N_Cut_00@ha
addi r10, r10, str_N_Cut_00@l
bla _compareString
beq scaleOnlyPos
lis r10, str_Pa_Page_4x5_00@ha
addi r10, r10, str_Pa_Page_4x5_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_InOut_02@ha
addi r10, r10, str_N_InOut_02@l
bla _compareString
beq scalePaneNormal
# lis r10, str_N_Cat_01@ha
# addi r10, r10, str_N_Cat_01@l
# bla _compareString
# beq scalePaneReverse
b exitScale
const_SkipButtonOffset:
.float 560
scaleSkipButtonPanes:
addi r5, r31, 0x80
lis r10, const_SkipButtonOffset@ha
lfs f12, const_SkipButtonOffset@l(r10)
lis r10, str_N_InOut_00@ha
addi r10, r10, str_N_InOut_00@l
bla _compareString
beq scalePaneAndKeepCustomPosIf
lis r10, str_N_Glow_00@ha
addi r10, r10, str_N_Glow_00@l
bla _compareString
beq scalePaneAndKeepCustomPosIf
b exitScale
scaleLoadSaveIconPanes:
addi r5, r31, 0x80
lis r10, str_N_InOut_00@ha
addi r10, r10, str_N_InOut_00@l
bla _compareString
beq scalePaneAndKeepPos
lis r10, str_N_Glow_00@ha
addi r10, r10, str_N_Glow_00@l
bla _compareString
beq scalePaneAndKeepPos
b exitScale
scaleLoadingPanes: ; works, but current code is very janky
addi r5, r31, 0x80
lis r10, str_N_RegionTypePos_00@ha
addi r10, r10, str_N_RegionTypePos_00@l
bla _compareString
beq scalePaneToLeftSide
lis r10, str_Pa_GuideA_00@ha
addi r10, r10, str_Pa_GuideA_00@l
bla _compareString
beq scalePaneAndKeepPos
lis r10, str_N_LogoInOut_02@ha
addi r10, r10, str_N_LogoInOut_02@l
bla _compareString
beq scalePaneToRightSide
lis r10, str_T_TipsTitle_00@ha
addi r10, r10, str_T_TipsTitle_00@l
bla _compareString
beq scalePaneAndKeepPos
lis r10, str_T_TipsTitle_00_JPja@ha
addi r10, r10, str_T_TipsTitle_00_JPja@l
bla _compareString
beq scalePaneAndKeepPos
lis r10, str_T_TipsTitle_00_KR@ha
addi r10, r10, str_T_TipsTitle_00_KR@l
bla _compareString
beq scalePaneAndKeepPos
lis r10, str_T_TipsTitle_00_CN@ha
addi r10, r10, str_T_TipsTitle_00_CN@l
bla _compareString
beq scalePaneAndKeepPos
lis r10, str_T_TipsTitle_00_TW@ha
addi r10, r10, str_T_TipsTitle_00_TW@l
bla _compareString
beq scalePaneAndKeepPos
lis r10, str_T_Tips_00@ha
addi r10, r10, str_T_Tips_00@l
bla _compareString
beq scalePaneAndKeepPos
lis r10, str_T_Tips_00_JPja@ha
addi r10, r10, str_T_Tips_00_JPja@l
bla _compareString
beq scalePaneAndKeepPos
lis r10, str_T_Tips_00_KR@ha
addi r10, r10, str_T_Tips_00_KR@l
bla _compareString
beq scalePaneAndKeepPos
lis r10, str_T_Tips_00_CN@ha
addi r10, r10, str_T_Tips_00_CN@l
bla _compareString
beq scalePaneAndKeepPos
lis r10, str_T_Tips_00_TW@ha
addi r10, r10, str_T_Tips_00_TW@l
bla _compareString
beq scalePaneAndKeepPos
b exitScale
scaleLoadingStatusPanes:
addi r5, r31, 0x80
lis r10, str_N_ParamInOut_00@ha
addi r10, r10, str_N_ParamInOut_00@l
bla _compareString
beq scalePaneToRightSide
b exitScale
scaleGameOverPanes:
addi r5, r31, 0x80
lis r10, str_N_Aka_00@ha
addi r10, r10, str_N_Aka_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_Ao_00@ha
addi r10, r10, str_N_Ao_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_Kiiro_00@ha
addi r10, r10, str_N_Kiiro_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_Pa_Btn_00@ha
addi r10, r10, str_Pa_Btn_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_Pa_Btn_02@ha
addi r10, r10, str_Pa_Btn_02@l
bla _compareString
beq scalePaneNormal
lis r10, str_T_SubText_00@ha
addi r10, r10, str_T_SubText_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleSystemWindowInventoryPanes:
addi r5, r31, 0x80
lis r10, str_N_TypeBtn_01@ha
addi r10, r10, str_N_TypeBtn_01@l
bla _compareString
beq scalePaneAndPos
lis r10, str_N_InOut_01@ha
addi r10, r10, str_N_InOut_01@l
bla _compareString
beq scalePaneNormal
b exitScale
scalePauseMenuAbilityControlsPanes:
addi r5, r31, 0x80
lis r10, str_N_Option_00@ha
addi r10, r10, str_N_Option_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_Align_00@ha
addi r10, r10, str_N_Align_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleSystemWindowPanes:
addi r5, r31, 0x80
lis r10, str_N_SlideArea_00@ha
addi r10, r10, str_N_SlideArea_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_InOut_03@ha
addi r10, r10, str_N_InOut_03@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_FileSelect_01@ha
addi r10, r10, str_N_FileSelect_01@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_HardModePos_00@ha
addi r10, r10, str_N_HardModePos_00@l
bla _compareString
beq scalePaneToLeftSide
b exitScale
scaleAppSystemWindowPanes:
addi r5, r31, 0x80
lis r10, str_N_BtnNum_00@ha
addi r10, r10, str_N_BtnNum_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_BtnPos_00@ha
addi r10, r10, str_N_BtnPos_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleOptionsMenuPanes:
addi r5, r31, 0x80
lis r10, str_N_Option_00@ha
addi r10, r10, str_N_Option_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_Option_01@ha
addi r10, r10, str_N_Option_01@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleDLCWindowPanes:
addi r5, r31, 0x80
lis r10, str_N_Option_00@ha
addi r10, r10, str_N_Option_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleTitlePanes:
addi r5, r31, 0x80
lis r10, str_N_RegionType_00@ha ; Logo
addi r10, r10, str_N_RegionType_00@l
bla _compareString
beq scalePaneToRightSide
lis r10, str_N_RegionType_00_JPja@ha ; Logo
addi r10, r10, str_N_RegionType_00_JPja@l
bla _compareString
beq scalePaneToRightSide
lis r10, str_P_Blur_08@ha ; Logo Blur
addi r10, r10, str_P_Blur_08@l
bla _compareString
beq scalePaneToRightSide
lis r10, str_N_HardMode_03@ha ; Hard Mode
addi r10, r10, str_N_HardMode_03@l
bla _compareString
beq scalePaneToLeftSide
lis r10, str_N_CopyRight_00@ha ; Copyright and version number
addi r10, r10, str_N_CopyRight_00@l
bla _compareString
beq scalePaneToRightSide
lis r10, str_N_BtnIn_00@ha ; Menu box
addi r10, r10, str_N_BtnIn_00@l
bla _compareString
beq scalePaneToRightSide
lis r10, str_N_1_Arrow_00@ha ; Backgrounds that have have no edges
addi r10, r10, str_N_1_Arrow_00@l
bla _compareString
beq scalePaneToLeftSide
lis r10, str_N_5_Gardian_00@ha
addi r10, r10, str_N_5_Gardian_00@l
bla _compareString
beq scalePaneToLeftSide
lis r10, str_N_2_Horse_00@ha
addi r10, r10, str_N_2_Horse_00@l
bla _compareString
beq scalePaneToLeftSide
lis r10, str_N_4_SenakaLink_00@ha
addi r10, r10, str_N_4_SenakaLink_00@l
bla _compareString
beq scalePaneToLeftSide
lis r10, str_N_3_Gake_00@ha ; Big backgrounds that have visible borders
addi r10, r10, str_N_3_Gake_00@l
bla _compareString
beq scalePaneOnYScale
lis r10, str_N_0_MainV_00@ha
addi r10, r10, str_N_0_MainV_00@l
bla _compareString
beq scalePaneOnYScale
lis r10, str_N_6_MainVE_00@ha
addi r10, r10, str_N_6_MainVE_00@l
bla _compareString
beq scalePaneOnYScale
b exitScale
scaleDemoNameEnemyPanes:
addi r5, r31, 0x80
lis r10, str_N_Capture_00@ha
addi r10, r10, str_N_Capture_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_Capture_01@ha
addi r10, r10, str_N_Capture_01@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_In_00@ha
addi r10, r10, str_N_In_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_P_BigTextSh_00@ha
addi r10, r10, str_P_BigTextSh_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_P_BigText_00@ha
addi r10, r10, str_P_BigText_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_P_Light_01@ha
addi r10, r10, str_P_Light_01@l
bla _compareString
beq scalePaneNormal
lis r10, str_P_BigText_01@ha
addi r10, r10, str_P_BigText_01@l
bla _compareString
beq scalePaneNormal
lis r10, str_P_BigText_02@ha
addi r10, r10, str_P_BigText_02@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleLastCompletePanes:
addi r5, r31, 0x80
lis r10, str_N_Capture_00@ha
addi r10, r10, str_N_Capture_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_P_Base_03@ha
addi r10, r10, str_P_Base_03@l
bla _compareString
beq scalePaneNormal
lis r10, str_P_Base_01@ha
addi r10, r10, str_P_Base_01@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_In_00@ha
addi r10, r10, str_N_In_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_In_01@ha
addi r10, r10, str_N_In_01@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleCreditPanes:
addi r5, r31, 0x80
lis r10, str_N_PicFade_00@ha
addi r10, r10, str_N_PicFade_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_PicFade_01@ha
addi r10, r10, str_N_PicFade_01@l
bla _compareString
beq scalePaneNormal
lis r10, str_P_Sh_00@ha
addi r10, r10, str_P_Sh_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_P_Sh_01@ha
addi r10, r10, str_P_Sh_01@l
bla _compareString
beq scalePaneNormal
lis r10, str_P_Text_01@ha
addi r10, r10, str_P_Text_01@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_StaffRoll_00@ha
addi r10, r10, str_N_StaffRoll_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_PostOne_03@ha
addi r10, r10, str_N_PostOne_03@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_PostOne_02@ha
addi r10, r10, str_N_PostOne_02@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_PostOne_01@ha
addi r10, r10, str_N_PostOne_01@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_PostOne_00@ha
addi r10, r10, str_N_PostOne_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_NameTriple_00@ha
addi r10, r10, str_N_NameTriple_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_NameOne_00@ha
addi r10, r10, str_N_NameOne_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_CopyRight_00@ha
addi r10, r10, str_N_CopyRight_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleDLCCreditPanes:
addi r5, r31, 0x80
lis r10, str_N_CaptureText_00@ha
addi r10, r10, str_N_CaptureText_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_In_00@ha
addi r10, r10, str_N_In_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_P_BG_00@ha
addi r10, r10, str_P_BG_00@l
bla _compareString
beq scalePaneReverse
b exitScale
scaleThanksPanes:
addi r5, r31, 0x80
lis r10, str_N_In_00@ha
addi r10, r10, str_N_In_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_Capture_00@ha
addi r10, r10, str_N_Capture_00@l
bla _compareString
beq scalePaneNormal
lis r10, str_N_Capture_01@ha
addi r10, r10, str_N_Capture_01@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleGameTitlePanes:
addi r5, r31, 0x80
lis r10, str_N_Region_01@ha
addi r10, r10, str_N_Region_01@l
bla _compareString
beq scalePaneAndKeepPosIf
lis r10, str_N_Region_01_JPja@ha
addi r10, r10, str_N_Region_01_JPja@l
bla _compareString
beq scalePaneAndKeepPosIf
b exitScale
scaleMessageTipsPanes:
lis r5, copySubPanelString@ha
addi r5, r5, copySubPanelString@l
lis r10, str_Pa_Tips_00@ha
addi r10, r10, str_Pa_Tips_00@l
bla _compareString
beq scaleMessageTipsSubTipsPanes
lis r10, str_Pa_TipsAmiibo_00@ha
addi r10, r10, str_Pa_TipsAmiibo_00@l
bla _compareString
beq scaleMessageTipsSubTipsPanes
addi r5, r31, 0x80
lis r10, str_N_DecideOut_00@ha
addi r10, r10, str_N_DecideOut_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleMessageTipsSubTipsPanes:
addi r5, r31, 0x80
lis r10, str_N_InOut_01@ha
addi r10, r10, str_N_InOut_01@l
bla _compareString
beq scalePaneNormal
b exitScale
const_EnergyMeterOffset:
.float 392
scaleEnergyMeterDLCPanes:
addi r5, r31, 0x80
lis r10, const_EnergyMeterOffset@ha
lfs f12, const_EnergyMeterOffset@l(r10)
lis r10, str_N_InOut_00@ha
addi r10, r10, str_N_InOut_00@l
bla _compareString
beq scalePaneNormal
b exitScale
; ------------------------------------------------------------------------------------------
; Generic methods used to scale a specific pane type
scaleRootToCenter:
addi r5, r31, 0x80 ; address to first character of the pane name that's getting loaded
lis r10, str_RootPane@ha
addi r10, r10, str_RootPane@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleInOutToCenter:
addi r5, r31, 0x80
lis r10, str_N_InOut_00@ha
addi r10, r10, str_N_InOut_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleTopInOutToCenter:
lis r5, copySubPanelString@ha
lbz r5, copySubPanelString@l(r5)
cmpwi r5, 0
bne exitScale
addi r5, r31, 0x80
lis r10, str_N_InOut_00@ha
addi r10, r10, str_N_InOut_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleTopInOutToCenterAndPos:
lis r5, copySubPanelString@ha
lbz r5, copySubPanelString@l(r5)
cmpwi r5, 0
bne exitScale
addi r5, r31, 0x80
lis r10, str_N_InOut_00@ha
addi r10, r10, str_N_InOut_00@l
bla _compareString
beq scalePaneAndPos
b exitScale
scaleRootScreenToLeftSide:
addi r5, r31, 0x80
lis r10, str_RootPane@ha
addi r10, r10, str_RootPane@l
bla _compareString
beq scalePaneToLeftSide
b exitScale
scaleInOutScreenToLeftSide:
addi r5, r31, 0x80
lis r10, str_N_InOut_00@ha
addi r10, r10, str_N_InOut_00@l
bla _compareString
beq scalePaneToLeftSide
b exitScale
scaleRootScreenToRightSide:
addi r5, r31, 0x80
lis r10, str_RootPane@ha
addi r10, r10, str_RootPane@l
bla _compareString
beq scalePaneToRightSide
b exitScale
scaleInOutScreenToRightSide:
addi r5, r31, 0x80
lis r10, str_RootPane@ha
addi r10, r10, str_RootPane@l
bla _compareString
beq movePaneToRightSide
lis r10, str_N_InOut_00@ha
addi r10, r10, str_N_InOut_00@l
bla _compareString
beq scalePaneNormal
b exitScale
scaleAllPanes:
addi r5, r31, 0x80
lis r10, str_RootPane@ha
addi r10, r10, str_RootPane@l
bla _compareString
bne scalePaneNormal
b exitScale
; ------------------------------------------------------------------------------------------
; Methods used to scale a single pane
scalePaneAndSize:
lis r10, const_AspectRatio@ha
lfs f9, const_AspectRatio@l(r10)
lfs f0, 0x0(r27)
fmuls f0, f0, f9
stfs f0, 0x0(r27)
lis r10, const_AspectRatio@ha
lfs f0, const_AspectRatio@l(r10)
lfs f9, 0x34(r31)
fmuls f0, f0, f9
stfs f0, 0x34(r31)
b exitScale
scaleOnlySize:
lis r10, const_AspectRatio@ha
lfs f9, const_AspectRatio@l(r10)
lfs f0, 0x0(r27)
fmuls f0, f0, f9
stfs f0, 0x0(r27)
b exitScale
scaleOnlySizeReverse:
lis r10, const_ReverseAspectRatio@ha
lfs f9, const_ReverseAspectRatio@l(r10)
lfs f0, 0x0(r27)
fmuls f0, f0, f9
stfs f0, 0x0(r27)
b exitScale
; Scales pane to left side
scalePaneToLeftSide:
lis r10, const_AspectRatio@ha
lfs f0, const_AspectRatio@l(r10)
lfs f9, 0x34(r31)
fmuls f0, f0, f9
stfs f0, 0x34(r31)
lis r10, const_PaddingLeftSide@ha
lfs f9, const_PaddingLeftSide@l(r10)
lfs f0, 0x1C(r31)
fadds f0, f0, f9
stfs f0, 0x1C(r31)
b exitScale
scalePaneToLeftSideIf:
li r10, $ultrawideHUDMode
cmpwi r10, 1
beq scalePaneToLeftSide
bne scalePaneNormal
movePaneToLeftSide:
lis r10, const_PaddingLeftSide@ha
lfs f9, const_PaddingLeftSide@l(r10)
lfs f0, 0x1C(r31)
fadds f0, f0, f9
stfs f0, 0x1C(r31)
b exitScale
movePaneToLeftSideAlt:
lis r10, const_AltPaddingLeftSide@ha
lfs f9, const_AltPaddingLeftSide@l(r10)
lfs f0, 0x1C(r31)
fadds f0, f0, f9
stfs f0, 0x1C(r31)
b exitScale
; Scales pane to right side
scalePaneToRightSide:
lis r10, const_AspectRatio@ha
lfs f0, const_AspectRatio@l(r10)
lfs f9, 0x34(r31)
fmuls f0, f0, f9
stfs f0, 0x34(r31)
lis r10, const_PaddingRightSide@ha
lfs f9, const_PaddingRightSide@l(r10)
lfs f0, 0x1C(r31)
fadds f0, f0, f9
stfs f0, 0x1C(r31)
b exitScale
movePaneToRightSide:
lis r10, const_PaddingRightSide@ha
lfs f9, const_PaddingRightSide@l(r10)
lfs f0, 0x1C(r31)
fadds f0, f0, f9
stfs f0, 0x1C(r31)
b exitScale
movePaneToRightSideAlt:
lis r10, const_AltPaddingRightSide@ha
lfs f9, const_AltPaddingRightSide@l(r10)
lfs f0, 0x1C(r31)
fadds f0, f0, f9
stfs f0, 0x1C(r31)
b exitScale
scalePaneToRightSideAlt:
lis r10, const_AspectRatio@ha
lfs f0, const_AspectRatio@l(r10)
lfs f9, 0x34(r31)
fmuls f0, f0, f9
stfs f0, 0x34(r31)
lis r10, const_AltPaddingRightSide@ha
lfs f9, const_AltPaddingRightSide@l(r10)
lfs f0, 0x1C(r31)
fadds f0, f0, f9
stfs f0, 0x1C(r31)
b exitScale
scalePaneReverseToLeft:
lis r10, const_ReverseAspectRatio@ha
lfs f0, const_ReverseAspectRatio@l(r10)
lfs f9, 0x34(r31)
fmuls f0, f0, f9
stfs f0, 0x34(r31)
lis r10, const_AltPaddingLeftSide@ha
lfs f9, const_AltPaddingLeftSide@l(r10)
lfs f0, 0x1C(r31)
fadds f0, f0, f9
stfs f0, 0x1C(r31)
b exitScale
scalePaneReverseToRight:
lis r10, const_ReverseAspectRatio@ha
lfs f0, const_ReverseAspectRatio@l(r10)
lfs f9, 0x34(r31)
fmuls f0, f0, f9
stfs f0, 0x34(r31)
lis r10, const_AltPaddingRightSide@ha
lfs f9, const_AltPaddingRightSide@l(r10)
lfs f0, 0x1C(r31)
fadds f0, f0, f9
stfs f0, 0x1C(r31)
b exitScale
; Divides the width of this element with the change in aspect ratio
scalePaneNormal:
lis r10, const_AspectRatio@ha
lfs f0, const_AspectRatio@l(r10)
lfs f9, 0x34(r31)
fmuls f0, f0, f9
stfs f0, 0x34(r31)
b exitScale
scalePaneAndPos:
lis r10, const_AspectRatio@ha
lfs f0, const_AspectRatio@l(r10)
lfs f9, 0x34(r31)
fmuls f0, f0, f9
stfs f0, 0x34(r31)
lis r10, const_AspectRatio@ha
lfs f0, const_AspectRatio@l(r10)
lfs f9, 0x1C(r31)
fmuls f0, f0, f9
stfs f0, 0x1C(r31)
b exitScale
scaleOnlyPos:
lis r10, const_AspectRatio@ha
lfs f0, const_AspectRatio@l(r10)
lfs f9, 0x1C(r31)
fmuls f0, f0, f9
stfs f0, 0x1C(r31)
b exitScale
const_640:
.float $gameWidth/2
const_1:
.float 1.0
scalePaneAndKeepPosIf:
li r10, $ultrawideHUDMode
cmpwi r10, 1
beq scalePaneAndKeepPos
bne scalePaneAndPos
scalePaneAndKeepPos:
lis r10, const_AspectRatio@ha
lfs f0, const_AspectRatio@l(r10)
lfs f9, 0x34(r31)
fmuls f0, f0, f9
stfs f0, 0x34(r31)
; [XPositionOfPane] + ((1280/2 - [XPositionOfPane]) * (1-[AspectRatio])))
lis r10, const_0@ha
lfs f11, const_0@l(r10)
lfs f9, 0x1C(r31)
fcmpu f9, f11
lis r10, const_640@ha
lfs f0, const_640@l(r10)
lfs f9, 0x1C(r31)
bge .+0x08
fsubs f9, f11, f9
fsubs f0, f0, f9
lis r10, const_1@ha
lfs f13, const_1@l(r10)
lis r10, const_AspectRatio@ha
lfs f9, const_AspectRatio@l(r10)
fsubs f13, f13, f9
fmuls f0, f0, f13
lfs f9, 0x1C(r31)
bge .+0x08
fsubs f9, f11, f9
fadds f0, f9, f0
bge .+0x08
fsubs f0, f11, f0
stfs f0, 0x1C(r31)
b exitScale
; Pass custom pos as f12
scalePaneAndKeepCustomPosIf:
li r10, $ultrawideHUDMode
cmpwi r10, 1
beq scalePaneAndKeepCustomPos
bne scalePaneAndCustomPos
scalePaneAndKeepCustomPos:
lis r10, const_AspectRatio@ha
lfs f0, const_AspectRatio@l(r10)
lfs f9, 0x34(r31)
fmuls f0, f0, f9
stfs f0, 0x34(r31)
; [XPositionOfPane] + ((1280/2 - [XPositionOfPane]) * (1-[AspectRatio])))
lis r10, const_0@ha
lfs f11, const_0@l(r10)
lfs f9, 0x1C(r31)
fadds f9, f9, f12
fcmpu f9, f11
lis r10, const_640@ha
lfs f0, const_640@l(r10)
lfs f9, 0x1C(r31)
fadds f9, f9, f12
bge .+0x08
fsubs f9, f11, f9
fsubs f0, f0, f9
lis r10, const_1@ha
lfs f13, const_1@l(r10)
lis r10, const_AspectRatio@ha
lfs f9, const_AspectRatio@l(r10)
fsubs f13, f13, f9
fmuls f0, f0, f13
lfs f9, 0x1C(r31)
fadds f9, f9, f12
bge .+0x08
fsubs f9, f11, f9
fadds f0, f9, f0
bge .+0x08
fsubs f0, f11, f0
fsubs f0, f0, f12
stfs f0, 0x1C(r31)
b exitScale
# ; [XPositionOfPane] + ((1280/2 - [XPositionOfPane]) * (1-[AspectRatio])))
# lis r10, const_640@ha
# lfs f0, const_640@l(r10) ; (1280/2)
# lfs f9, 0x1C(r31)
# fadds f9, f9, f12 ; Create XPositionOfPane (add position of current pane + custom position of parent pane)
# fsubs f0, f0, f9 ; (1280/2) - XPositionOfPane
# lis r10, const_1@ha
# lfs f13, const_1@l(r10)
# lis r10, const_AspectRatio@ha
# lfs f9, const_AspectRatio@l(r10)
# fsubs f13, f13, f9 ; (1-[AspectRatio])
# fmuls f0, f0, f13 ; ((1280/2) - XPositionOfPane) * (1-[AspectRatio])
# lfs f9, 0x1C(r31)
# fadds f9, f9, f12 ; [XPositionOfPane]
# fadds f0, f9, f0 ; [XPositionOfPane] + ((1280/2 - [XPositionOfPane]) * (1-[AspectRatio])))
# fsubs f0, f0, f12
; Explanation: The current position is 3x as big as it should be (let's take 3x at 48:9), so to correct that you scale it back by
; XPositionOfPane*(1-AspectRatio)
scalePaneAndCustomPos:
lis r10, const_AspectRatio@ha
lfs f0, const_AspectRatio@l(r10)
lfs f9, 0x34(r31)
fmuls f0, f0, f9
stfs f0, 0x34(r31)
lis r10, const_1@ha
lfs f9, const_1@l(r10)
lis r10, const_AspectRatio@ha
lfs f0, const_AspectRatio@l(r10)
fsubs f0, f9, f0
lfs f9, 0x1C(r31)
fsubs f9, f9, f12
fmuls f0, f9, f0
stfs f0, 0x1C(r31)
b exitScale
moveKeepPos:
lis r10, const_0@ha
lfs f11, const_0@l(r10)
lfs f9, 0x1C(r31)
fcmpu f9, f11
lis r10, const_640@ha
lfs f0, const_640@l(r10)
lfs f9, 0x1C(r31)
bge .+0x08
fsubs f9, f11, f9
fsubs f0, f0, f9
lis r10, const_1@ha
lfs f13, const_1@l(r10)
lis r10, const_AspectRatio@ha
lfs f9, const_AspectRatio@l(r10)
fsubs f13, f13, f9
fmuls f0, f0, f13
lfs f9, 0x1C(r31)
bge .+0x08
fsubs f9, f11, f9
fadds f0, f9, f0
bge .+0x08
fsubs f0, f11, f0
stfs f0, 0x1C(r31)
b exitScale
; Pass the scale in f0 and position in f12
scalePaneWithCustomPosAndScale:
lfs f9, 0x34(r31)
fmuls f0, f0, f9
stfs f0, 0x34(r31)
lfs f9, 0x1C(r31)
fsubs f0, f9, f12
stfs f12, 0x1C(r31)
b exitScale
movePaneToCustomPos:
lfs f9, 0x1C(r31)
fsubs f0, f9, f12
stfs f12, 0x1C(r31)
b exitScale
scalePaneHalf:
lis r10, const_AspectRatioHalf@ha
lfs f0, const_AspectRatioHalf@l(r10)
lfs f9, 0x34(r31)
fmuls f0, f0, f9
stfs f0, 0x34(r31)
b exitScale
scalePaneReverse:
lis r10, const_ReverseAspectRatio@ha
lfs f0, const_ReverseAspectRatio@l(r10)
lfs f9, 0x34(r31)
fmuls f0, f0, f9
stfs f0, 0x34(r31)
b exitScale
scalePaneAndPosReverse:
lis r10, const_ReverseAspectRatio@ha
lfs f0, const_ReverseAspectRatio@l(r10)
lfs f9, 0x34(r31)
fmuls f0, f0, f9
stfs f0, 0x34(r31)
lis r10, const_ReverseAspectRatio@ha
lfs f0, const_ReverseAspectRatio@l(r10)
lfs f9, 0x1C(r31)
fmuls f0, f0, f9
stfs f0, 0x1C(r31)
b exitScale
scalePaneReverse2x:
lis r10, const_ReverseAspectRatio2x@ha
lfs f0, const_ReverseAspectRatio2x@l(r10)
lfs f9, 0x34(r31)
fmuls f0, f0, f9
stfs f0, 0x34(r31)
b exitScale
scalePaneOnYScale:
lis r10, const_ReverseAspectRatio@ha
lfs f0, const_ReverseAspectRatio@l(r10)
lfs f9, 0x38(r31)
fmuls f0, f0, f9
stfs f0, 0x38(r31)
b exitScale
scalePaneOnYScaleReverse:
lis r10, const_AspectRatio@ha
lfs f0, const_AspectRatio@l(r10)
lfs f9, 0x38(r31)
fmuls f0, f0, f9
stfs f0, 0x38(r31)
b exitScale
scaleReversePaneToRightSide:
lis r10, const_ReverseAspectRatio2x@ha
lfs f0, const_ReverseAspectRatio2x@l(r10)
lfs f9, 0x34(r31)
fmuls f0, f0, f9
stfs f0, 0x34(r31)
lis r10, const_AltPaddingRightSide@ha
lfs f9, const_AltPaddingRightSide@l(r10)
lfs f0, 0x1C(r31)
fadds f0, f0, f9
stfs f0, 0x1C(r31)
b exitScale
exitScale:
mtlr r0
lwz r0, 0x24(r30)
blr
0x03C496B8 = bla _scalePaneGUI
; ------------------------------------------------------------------------------------------
; Specific code required for switching the positions of the minimap and the AppMap
const_0:
.float 0.0
mapXPositionAddr:
.int 0
scaleMapAndStore:
; scale pane and move to right on initialization
lis r10, const_AspectRatio@ha
lfs f0, const_AspectRatio@l(r10)
lfs f9, 0x34(r31)
fmuls f0, f0, f9
stfs f0, 0x34(r31)
; if the ultrawide mode is 1 (edge HUD), add padding so that the map gets initialized at the right edge
li r10, $ultrawideHUDMode
cmpwi r4, 1
lis r10, const_0@ha
lfs f9, const_0@l(r10)
bne noMapPadding
lis r10, const_PaddingRightSide@ha
lfs f9, const_PaddingRightSide@l(r10)
noMapPadding:
lfs f0, 0x1C(r31)
fadds f0, f0, f9
stfs f0, 0x1C(r31)
addi r5, r31, 0x1C
lis r10, mapXPositionAddr@ha
stw r5, mapXPositionAddr@l(r10)
b exitScale
setMapPosition:
li r4, $ultrawideHUDMode
cmpwi r4, 0
beq setNothing
li r4, $ultrawideHUDMode ; if ultramode is centered, keep the map centered
cmpwi r4, 2
beq setToMap
cmpwi r31, 0
beq setToMinimap
setToMap:
cmpwi r3, 0
lis r3, const_0@ha
lfs f12, const_0@l(r3)
lis r3, mapXPositionAddr@ha
lwz r3, mapXPositionAddr@l(r3)
stfs f12, 0(r3)
blr
setToMinimap:
cmpwi r3, 0
lis r3, const_PaddingRightSide@ha
lfs f12, const_PaddingRightSide@l(r3)
lis r3, mapXPositionAddr@ha
lwz r3, mapXPositionAddr@l(r3)
stfs f12, 0(r3)
blr
setNothing:
cmpwi r3, 0
blr
0x02F60204 = bla setMapPosition
; ------------------------------------------------------------------------------------------
; Specific code required for scaling a specific effect called PaneBasedProjection used on the weather panes, which breaks while scaling
proj_PosX:
.float 0.0
proj_PosY:
.float 0.0
proj_ScaleX:
.float ($gameWidth/$gameHeight)/($width/$height)
proj_ScaleY:
.float 1.0
proj_flags:
.int 0x01000000
; other registers used: r11, r9, r12, r11
; empty registers: r5, r6, r8, r0, r9, r11
setPaneBasedProjection:
stw r0, 0x10(r4)
mr r6, r12
mr r8, r10
mflr r0
; if ultrawide mode is set to 0, return early
li r10, $ultrawideHUDMode
cmpwi r10, 0
beq exitPaneBasedProjection
lis r10, copySubPanelString@ha
addi r10, r10, copySubPanelString@l
lis r5, str_Pa_Weather_00@ha
addi r5, r5, str_Pa_Weather_00@l
bla _compareString
bne exitPaneBasedProjection
# lis r11, proj_PosX@ha
# lfs f3, proj_PosX@l(r11)
# stfs f3, 0x0(r4)
# lis r11, proj_PosY@ha
# lfs f3, proj_PosY@l(r11)
# stfs f3, 0x4(r4)
lis r11, proj_ScaleX@ha
lfs f3, proj_ScaleX@l(r11)
stfs f3, 0x8(r4)
# lis r11, proj_ScaleY@ha
# lfs f3, proj_ScaleY@l(r11)
# stfs f3, 0xC(r4)
# lis r11, proj_flags@ha
# lwz r11, proj_flags@l(r11)
# stw r11, 0x10(r4)
exitPaneBasedProjection:
mtlr r0
mr r12, r6
mr r10, r8
blr
0x03C56CD0 = bla setPaneBasedProjection
; ------------------------------------------------------------------------------------------
_createNewScreenHook:
; Copy screen name to buffer
lis r11, copyScreenStringLen@ha
lwz r11, copyScreenStringLen@l(r11)
lis r12, copyScreenString@ha
addi r12, r12, copyScreenString@l
copyNameLoop:
lbzx r10, r24, r11
stbx r10, r12, r11
addi r11, r11, -1
cmpwi r11, -1
bne copyNameLoop
; Erase SubPanel string when a new screen got loaded
lis r11, copySubPanelStringLen@ha
lwz r11, copySubPanelStringLen@l(r11)
lis r12, copySubPanelString@ha
addi r12, r12, copySubPanelString@l
eraseSubPanelLoop:
li r10, 0
stbx r10, r12, r11
addi r11, r11, -1
cmpwi r11, -1
bne eraseSubPanelLoop
li r10, $enableUltrawideDebugLogging
cmpwi r10, 1
blt skipLayoutFileLogging
crxor 4*cr1+eq, 4*cr1+eq, 4*cr1+eq
lis r3, newLineFormatScreen@ha
addi r3, r3, newLineFormatScreen@l
lis r4, copyScreenString@ha
addi r4, r4, copyScreenString@l
lis r5, newLineCharacter@ha
lwz r5, newLineCharacter@l(r5)
mflr r10
bl import.coreinit.OSReport
mtlr r10
mr r3, r11
skipLayoutFileLogging:
lwz r11, 0xC(r30)
blr
0x03A3EDC4 = bla _createNewScreenHook
; ------------------------------------------------------------------------------------------
; compares the string from r5 and r10
; r5 is untouched, so use that to do multiple comparisons
; other registers used: r11, r9, r12, r11
_compareString:
mr r11, r5
startLoop:
lbz r9, 0(r11)
lbz r12, 0(r10)
cmpwi r9, 0
bne checkForMatch
cmpwi r12, 0
bne checkForMatch
li r10, 1
cmpwi r10, 1
blr
checkForMatch:
cmpw r9, r12
bne noMatch
addi r11, r11, 1
addi r10, r10, 1
b startLoop
noMatch:
li r10, 0
cmpwi r10, 1
blr | 22.858127 | 135 | 0.807111 |
84fde7750cd9f789241e96e1253dbcafe6b4dc22 | 1,936 | asm | Assembly | programs/oeis/163/A163383.asm | neoneye/loda | afe9559fb53ee12e3040da54bd6aa47283e0d9ec | [
"Apache-2.0"
] | 22 | 2018-02-06T19:19:31.000Z | 2022-01-17T21:53:31.000Z | programs/oeis/163/A163383.asm | neoneye/loda | afe9559fb53ee12e3040da54bd6aa47283e0d9ec | [
"Apache-2.0"
] | 41 | 2021-02-22T19:00:34.000Z | 2021-08-28T10:47:47.000Z | programs/oeis/163/A163383.asm | neoneye/loda | afe9559fb53ee12e3040da54bd6aa47283e0d9ec | [
"Apache-2.0"
] | 5 | 2021-02-24T21:14:16.000Z | 2021-08-09T19:48:05.000Z | ; A163383: a(n) = (n-1)*2^n - 1.
; -1,3,15,47,127,319,767,1791,4095,9215,20479,45055,98303,212991,458751,983039,2097151,4456447,9437183,19922943,41943039,88080383,184549375,385875967,805306367,1677721599,3489660927,7247757311,15032385535,31138512895,64424509439,133143986175,274877906943,566935683071,1168231104511,2405181685759,4947802324991,10170482556927,20890720927743,42880953483263,87960930222079,180319906955263,369435906932735,756463999909887,1548112371908607,3166593487994879,6473924464345087,13229323905400831,27021597764222975,55169095435288575,112589990684262399,229683580995895295,468374361246531583,954763121002545151,1945555039024054271,3963167672086036479,8070450532247928831,16429131440647569407,33434723633598562303,68022368771803971583,138350580552821637119,281312847124070662143,571849066284996100095,1162144876643701751807,2361183241434822606847,4796153459164483420159,9739880870918643253247,19774909647016639332351,40140115104391984316415,81460821829501379936255,165282826900437582479359,335288020283744810172415,680020773533228910772223,1378931012997936402399231,2795640957858829966508031,5666839779443574256435199,11484795286338977159708671,23271822027581611613093887,47148106964970537813540863,95505139749555704801787903,193428131138340667952988159,391691965555139852604801023,793055337667196738607251455,1605453488448227544009801727,3249592603124123221610201087,6576556458703582710401597439,13307855422317837955165585407,26925195854457020979055951871,54469361728556732095561465855,110176663496398844466022055935,222829207071368449481842360319,450610174299878420063281217535,911123868914039882325755428863,1842054778456645849049896845311,3723723638170423866896565665791,7526675438855112071386675281919,15211807202738752817960438464511,30740527055534562986295052730367,62114879411183240673338457063423,125497409422594710748173617332223
mov $1,2
pow $1,$0
mul $1,$0
sub $1,2
div $1,2
mul $1,4
add $1,3
mov $0,$1
| 161.333333 | 1,826 | 0.918388 |
cee5e767df9a941fd68f4414d8e1781bcc50cdaf | 698 | asm | Assembly | oeis/091/A091914.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 11 | 2021-08-22T19:44:55.000Z | 2022-03-20T16:47:57.000Z | oeis/091/A091914.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 9 | 2021-08-29T13:15:54.000Z | 2022-03-09T19:52:31.000Z | oeis/091/A091914.asm | neoneye/loda-programs | 84790877f8e6c2e821b183d2e334d612045d29c0 | [
"Apache-2.0"
] | 3 | 2021-08-22T20:56:47.000Z | 2021-09-29T06:26:12.000Z | ; A091914: a(n) = 2*a(n-1) + 12*a(n-2).
; Submitted by Jamie Morken(s3)
; 1,2,16,56,304,1280,6208,27776,130048,593408,2747392,12615680,58200064,267788288,1233977344,5681414144,26170556416,120518082560,555082842112,2556382674944,11773759455232,54224111009792,249733335482368,1150156003082240,5297112031952896,24396096100892672,112357536585220096,517468226381152256,2383226891784945664,10976072500143718400,50550867701706784768,232814605405138190336,1072239623230757797888,4938254511323173879808,22743384501415441334272,104745823138708969226240,482412260294403234463744
add $0,1
mov $4,2
lpb $0
sub $0,1
mov $2,$3
mov $3,$1
mul $3,6
add $4,$2
mul $4,2
mov $1,$4
lpe
div $1,4
mov $0,$1
| 38.777778 | 495 | 0.803725 |
29dac1ccdd410be41a4ced09e06344fecb8e684f | 6,105 | asm | Assembly | Transynther/x86/_processed/NONE/_st_/i9-9900K_12_0xca_notsx.log_21829_398.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 9 | 2020-08-13T19:41:58.000Z | 2022-03-30T12:22:51.000Z | Transynther/x86/_processed/NONE/_st_/i9-9900K_12_0xca_notsx.log_21829_398.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 1 | 2021-04-29T06:29:35.000Z | 2021-05-13T21:02:30.000Z | Transynther/x86/_processed/NONE/_st_/i9-9900K_12_0xca_notsx.log_21829_398.asm | ljhsiun2/medusa | 67d769b8a2fb42c538f10287abaf0e6dbb463f0c | [
"MIT"
] | 3 | 2020-07-14T17:07:07.000Z | 2022-03-21T01:12:22.000Z | .global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r12
push %rax
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_UC_ht+0x185b2, %rax
nop
nop
add $21062, %r12
movb $0x61, (%rax)
cmp $39170, %rcx
lea addresses_UC_ht+0x9e30, %rsi
lea addresses_WT_ht+0x199d4, %rdi
nop
nop
nop
nop
nop
xor %r11, %r11
mov $127, %rcx
rep movsb
xor %r12, %r12
lea addresses_A_ht+0x1cc40, %rax
nop
nop
and %rbx, %rbx
mov (%rax), %r11d
cmp $33755, %rcx
lea addresses_normal_ht+0x14200, %r12
nop
nop
cmp %rsi, %rsi
movw $0x6162, (%r12)
nop
nop
nop
and %rax, %rax
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rax
pop %r12
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r14
push %rax
push %rbx
push %rcx
push %rdi
push %rdx
push %rsi
// REPMOV
lea addresses_RW+0x1c59c, %rsi
lea addresses_A+0x1fe00, %rdi
nop
nop
nop
nop
nop
and $16713, %r14
mov $10, %rcx
rep movsq
nop
inc %rsi
// Store
lea addresses_UC+0x8a00, %rdi
nop
nop
nop
nop
nop
cmp %rax, %rax
movw $0x5152, (%rdi)
nop
nop
nop
and %rdx, %rdx
// Store
lea addresses_RW+0xe530, %rcx
nop
nop
nop
nop
sub %r14, %r14
movb $0x51, (%rcx)
nop
nop
xor $10581, %rcx
// Store
lea addresses_WT+0xe600, %rsi
nop
nop
nop
nop
nop
inc %rax
movl $0x51525354, (%rsi)
nop
nop
nop
cmp %rbx, %rbx
// Store
lea addresses_RW+0x16600, %rsi
nop
nop
nop
nop
nop
and $61061, %rax
movw $0x5152, (%rsi)
nop
nop
nop
add $31752, %rsi
// Faulty Load
lea addresses_A+0x1fe00, %r14
nop
nop
nop
nop
and %rcx, %rcx
movups (%r14), %xmm3
vpextrq $1, %xmm3, %rdx
lea oracles, %rcx
and $0xff, %rdx
shlq $12, %rdx
mov (%rcx,%rdx,1), %rdx
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rbx
pop %rax
pop %r14
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_A', 'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 0}}
{'OP': 'REPM', 'src': {'same': False, 'congruent': 2, 'type': 'addresses_RW'}, 'dst': {'same': True, 'congruent': 0, 'type': 'addresses_A'}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_UC', 'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 10}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_RW', 'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 4}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_WT', 'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 7}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_RW', 'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 9}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'same': True, 'type': 'addresses_A', 'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 0}}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_UC_ht', 'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 0}}
{'OP': 'REPM', 'src': {'same': False, 'congruent': 4, 'type': 'addresses_UC_ht'}, 'dst': {'same': False, 'congruent': 0, 'type': 'addresses_WT_ht'}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_A_ht', 'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 6}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_normal_ht', 'NT': True, 'AVXalign': False, 'size': 2, 'congruent': 8}}
{'32': 21829}
32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32
*/
| 35.911765 | 2,999 | 0.654545 |
5aa549b768c2af25c3e7ea2616d030fef65de33f | 94,485 | asm | Assembly | lib/avx512/des_x16_avx512.asm | edtubbs/intel-ipsec-mb | 27bb66dcdf5aec2aec8cc0a6bee9c1da96898d7f | [
"BSD-3-Clause"
] | null | null | null | lib/avx512/des_x16_avx512.asm | edtubbs/intel-ipsec-mb | 27bb66dcdf5aec2aec8cc0a6bee9c1da96898d7f | [
"BSD-3-Clause"
] | null | null | null | lib/avx512/des_x16_avx512.asm | edtubbs/intel-ipsec-mb | 27bb66dcdf5aec2aec8cc0a6bee9c1da96898d7f | [
"BSD-3-Clause"
] | null | null | null | ;
;; Copyright (c) 2017-2021, Intel Corporation
;;
;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions are met:
;;
;; * Redistributions of source code must retain the above copyright notice,
;; this list of conditions and the following disclaimer.
;; * Redistributions in binary form must reproduce the above copyright
;; notice, this list of conditions and the following disclaimer in the
;; documentation and/or other materials provided with the distribution.
;; * Neither the name of Intel Corporation nor the names of its contributors
;; may be used to endorse or promote products derived from this software
;; without specific prior written permission.
;;
;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
;; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
;; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
;; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
;; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;;
;; Authors:
;; Shay Gueron (1, 2), Regev Shemy (2), Tomasz kantecki (2)
;; (1) University of Haifa, Israel
;; (2) Intel Corporation
;; In System V AMD64 ABI
;; callee saves: RBX, RBP, R12-R15
;; Windows x64 ABI
;; callee saves: RBX, RBP, RDI, RSI, RSP, R12-R15
;;
;; Registers: RAX RBX RCX RDX RBP RSI RDI R8 R9 R10 R11 R12 R13 R14 R15
;; -----------------------------------------------------------
;; Windows clobbers: RAX R8 R9 R10 R11
;; Windows preserves: RBX RCX RDX RBP RSI RDI R12 R13 R14 R15
;; -----------------------------------------------------------
;; Linux clobbers: RAX RCX RDX R10 R11
;; Linux preserves: RBX RBP RSI RDI R8 R9 R12 R13 R14 R15
;; -----------------------------------------------------------
;; Clobbers ZMM0-31 and K1 to K7
%include "include/os.asm"
%include "include/reg_sizes.asm"
%include "include/mb_mgr_datastruct.asm"
%include "include/constants.asm"
;%define DO_DBGPRINT
%include "include/dbgprint.asm"
%include "include/clear_regs.asm"
%include "include/cet.inc"
%ifdef LINUX
%define arg1 rdi
%define arg2 rsi
%define arg3 rdx
%define arg4 rcx
%else
%define arg1 rcx
%define arg2 rdx
%define arg3 r8
%define arg4 r9
%endif
%define STATE arg1
%define SIZE arg2
%define OFFSET rax
%define IA0 arg3
%define IA1 arg4
%define IA2 r10
%define INP0 r11
%define INP1 r12
%define INP2 r13
%define INP3 r14
%define INP4 r15
%define KSOFFSET r11
%define ZW0 zmm0
%define ZW1 zmm1
%define ZW2 zmm2
%define ZW3 zmm3
%define ZW4 zmm4
%define ZW5 zmm5
%define ZW6 zmm6
%define ZW7 zmm7
%define ZW8 zmm8
%define ZW9 zmm9
%define ZW10 zmm10
%define ZW11 zmm11
%define ZW12 zmm12
%define ZW13 zmm13
%define ZW14 zmm14
%define ZW15 zmm15
%define ZIV0 zmm16
%define ZIV1 zmm17
%define ZTMP0 zmm18
%define ZTMP1 zmm19
%define ZTMP2 zmm20
%define ZTMP3 zmm21
%define ZTMP4 zmm22
%define ZTMP5 zmm23
%define ZTMP6 zmm24
%define ZTMP7 zmm25
%define ZTMP8 zmm26
%define ZTMP9 zmm27
%define ZTMP10 zmm28
%define ZTMP11 zmm29
%define ZTMP12 zmm30
%define ZTMP13 zmm31
struc STACKFRAME
_key_sched: resq 16*16 ; 16 lanes x 16 qwords; 16 x 128 bytes = 2048
_key_sched2: resq 16*16 ; 16 lanes x 16 qwords; 16 x 128 bytes = 2048
_key_sched3: resq 16*16 ; 16 lanes x 16 qwords; 16 x 128 bytes = 2048
_tmp_iv: resq 16 ; 2 x 64 bytes
_tmp_in: resq 16 ; 2 x 64 bytes
_tmp_out: resq 16 ; 2 x 64 bytes
_tmp_mask: resd 16 ; 1 x 64 bytes
_gpr_save: resq 4 ; r12 to r15
_rsp_save: resq 1
_mask_save: resq 1
_size_save: resq 1
endstruc
;;; ===========================================================================
;;; ===========================================================================
;;; MACROS
;;; ===========================================================================
;;; ===========================================================================
;;; ===========================================================================
;;; CLEAR TRANSPOSED KEY SCHEDULE (if SAFE_DATA is selected)
;;; ===========================================================================
%macro CLEAR_KEY_SCHEDULE 2
%define %%ALG %1 ; [in] DES or 3DES
%define %%ZT %2 ; [clobbered] temporary ZMM register
%ifdef SAFE_DATA
vpxorq %%ZT, %%ZT
%assign rep_num (2048 / 64)
%ifidn %%ALG, 3DES
%assign rep_num (rep_num * 3)
%endif
%assign offset 0
%rep rep_num
vmovdqa64 [rsp + _key_sched + offset], %%ZT
%assign offset (offset + 64)
%endrep
%endif ; SAFE_DATA
%endmacro
;;; ===========================================================================
;;; PERMUTE
;;; ===========================================================================
;;; A [in/out] - zmm register
;;; B [in/out] - zmm register
;;; NSHIFT [in] - constant to shift words by
;;; MASK [in] - zmm or m512 with mask
;;; T0 [clobbered] - temporary zmm register
%macro PERMUTE 5
%define %%A %1
%define %%B %2
%define %%NSHIFT %3
%define %%MASK %4
%define %%T0 %5
vpsrld %%T0, %%A, %%NSHIFT
vpxord %%T0, %%T0, %%B
vpandd %%T0, %%T0, %%MASK
vpxord %%B, %%B, %%T0
vpslld %%T0, %%T0, %%NSHIFT
vpxord %%A, %%A, %%T0
%endmacro
;;; ===========================================================================
;;; INITIAL PERMUTATION
;;; ===========================================================================
;;; L [in/out] - zmm register
;;; R [in/out] - zmm register
;;; T0 [clobbered] - temporary zmm register
%macro IP_Z 3
%define %%L %1
%define %%R %2
%define %%T0 %3
PERMUTE %%R, %%L, 4, [rel init_perm_consts + 0*64], %%T0
PERMUTE %%L, %%R, 16, [rel init_perm_consts + 1*64], %%T0
PERMUTE %%R, %%L, 2, [rel init_perm_consts + 2*64], %%T0
PERMUTE %%L, %%R, 8, [rel init_perm_consts + 3*64], %%T0
PERMUTE %%R, %%L, 1, [rel init_perm_consts + 4*64], %%T0
%endmacro
;;; ===========================================================================
;;; FINAL PERMUTATION
;;; ===========================================================================
;;; L [in/out] - zmm register
;;; R [in/out] - zmm register
;;; T0 [clobbered] - temporary zmm register
%macro FP_Z 3
%define %%L %1
%define %%R %2
%define %%T0 %3
PERMUTE %%L, %%R, 1, [rel init_perm_consts + 4*64], %%T0
PERMUTE %%R, %%L, 8, [rel init_perm_consts + 3*64], %%T0
PERMUTE %%L, %%R, 2, [rel init_perm_consts + 2*64], %%T0
PERMUTE %%R, %%L, 16, [rel init_perm_consts + 1*64], %%T0
PERMUTE %%L, %%R, 4, [rel init_perm_consts + 0*64], %%T0
%endmacro
;;; ===========================================================================
;;; P PHASE
;;; ===========================================================================
;;; W0 [in/out] - zmm register
;;; in: vector of 16 x 32bits from S phase
;;; out: permuted in vector
;;; T0-T3 [clobbered] - temporary zmm register
%macro P_PHASE 5
%define %%W0 %1
%define %%T0 %2
%define %%T1 %3
%define %%T2 %4
%define %%T3 %5
vprord %%T0, %%W0, 3
vpandd %%T0, %%T0, [rel mask_values + 0*64]
vprord %%T1, %%W0, 5
vpandd %%T1, %%T1, [rel mask_values + 1*64]
vpord %%T0, %%T0, %%T1
vprord %%T1, %%W0, 24
vpandd %%T1, %%T1, [rel mask_values + 2*64]
vprord %%T2, %%W0, 26
vpandd %%T2, %%T2, [rel mask_values + 3*64]
vpord %%T1, %%T1, %%T2
vpord %%T0, %%T0, %%T1
vprord %%T1, %%W0, 15
vpandd %%T1, %%T1, [rel mask_values + 4*64]
vprord %%T2, %%W0, 17
vpandd %%T2, %%T2, [rel mask_values + 5*64]
vpord %%T1, %%T1, %%T2
vprord %%T2, %%W0, 6
vpandd %%T2, %%T2, [rel mask_values + 6*64]
vprord %%T3, %%W0, 21
vpandd %%T3, %%T3, [rel mask_values + 7*64]
vpord %%T2, %%T2, %%T3
vpord %%T1, %%T1, %%T2
vpord %%T0, %%T0, %%T1
vprord %%T1, %%W0, 12
vpandd %%T1, %%T1, [rel mask_values + 8*64]
vprord %%T2, %%W0, 14
vpandd %%T2, %%T2, [rel mask_values + 9*64]
vpord %%T1, %%T1, %%T2
vprord %%T2, %%W0, 4
vpandd %%T2, %%T2, [rel mask_values + 10*64]
vprord %%T3, %%W0, 11
vpandd %%T3, %%T3, [rel mask_values + 11*64]
vpord %%T2, %%T2, %%T3
vpord %%T1, %%T1, %%T2
vpord %%T0, %%T0, %%T1
vprord %%T1, %%W0, 16
vpandd %%T1, %%T1, [rel mask_values + 12*64]
vprord %%T2, %%W0, 22
vpandd %%T2, %%T2, [rel mask_values + 13*64]
vpord %%T1, %%T1, %%T2
vprord %%T2, %%W0, 19
vpandd %%T2, %%T2, [rel mask_values + 14*64]
vprord %%T3, %%W0, 10
vpandd %%T3, %%T3, [rel mask_values + 15*64]
vpord %%T2, %%T2, %%T3
vpord %%T1, %%T1, %%T2
vpord %%T0, %%T0, %%T1
vprord %%T1, %%W0, 9
vpandd %%T1, %%T1, [rel mask_values + 16*64]
vprord %%T2, %%W0, 13
vpandd %%T2, %%T2, [rel mask_values + 17*64]
vpord %%T1, %%T1, %%T2
vprord %%T2, %%W0, 25
vpandd %%T2, %%T2, [rel mask_values + 18*64]
vpord %%T1, %%T1, %%T2
vpord %%W0, %%T0, %%T1
%endmacro
;;; ===========================================================================
;;; E PHASE
;;; ===========================================================================
;;;
;;; Expands 16x32-bit words into 16x48-bit words
;;; plus XOR's result with the key schedule.
;;; The output is adjusted to be friendly as S phase input.
;;;
;;; in [in] - zmm register
;;; out0a [out] - zmm register
;;; out0b [out] - zmm register
;;; out1a [out] - zmm register
;;; out1b [out] - zmm register
;;; k0 [in] - key schedule; zmm or m512
;;; k1 [in] - key schedule; zmm or m512
;;; t0-t1 [clobbered] - temporary zmm register
%macro E_PHASE 9
%define %%IN %1
%define %%OUT0A %2
%define %%OUT0B %3
%define %%OUT1A %4
%define %%OUT1B %5
%define %%K0 %6
%define %%K1 %7
%define %%T0 %8
%define %%T1 %9
vprord %%T0, %%IN, 31
vprord %%T1, %%IN, 3
vpshufb %%T0, %%T0, [rel idx_e]
vpshufb %%T1, %%T1, [rel idx_e]
vpunpcklbw %%OUT0A, %%T0, %%T1
vpunpckhbw %%OUT1A, %%T0, %%T1
vpxord %%OUT0A, %%OUT0A, %%K0
vpxord %%OUT1A, %%OUT1A, %%K1
vpandd %%OUT0B, %%OUT0A, [rel and_eu]
vpsrlw %%OUT0B, %%OUT0B, 8
vpandd %%OUT0A, %%OUT0A, [rel and_ed]
vpandd %%OUT1B, %%OUT1A, [rel and_eu]
vpsrlw %%OUT1B, %%OUT1B, 8
vpandd %%OUT1A, %%OUT1A, [rel and_ed]
%endmacro
;;; ===========================================================================
;;; S-BOX
;;; ===========================================================================
;;;
;;; NOTE: clobbers k1-k6 OpMask registers
;;;
;;; IN0A [in] - zmm register; output from E-phase
;;; IN0B [in] - zmm register; output from E-phase
;;; IN1A [in] - zmm register; output from E-phase
;;; IN1B [in] - zmm register; output from E-phase
;;; OUT [out] - zmm register; output from E-phase
;;; T0-T5 [clobbered] - temporary zmm register
%macro S_PHASE 11
%define %%IN0A %1
%define %%IN0B %2
%define %%IN1A %3
%define %%IN1B %4
%define %%OUT %5
%define %%T0 %6
%define %%T1 %7
%define %%T2 %8
%define %%T3 %9
%define %%T4 %10
%define %%T5 %11
vmovdqa64 %%T0, [rel reg_values16bit_7]
vpcmpuw k3, %%IN0A, %%T0, 2 ; 2 -> LE
vpcmpuw k4, %%IN0B, %%T0, 2 ; 2 -> LE
vpcmpuw k5, %%IN1A, %%T0, 2 ; 2 -> LE
vpcmpuw k6, %%IN1B, %%T0, 2 ; 2 -> LE
mov DWORD(IA0), 0x55555555
kmovd k1, DWORD(IA0)
mov DWORD(IA0), 0xaaaaaaaa
kmovd k2, DWORD(IA0)
vmovdqa64 %%T0, [rel S_box_flipped + 0*64]
vmovdqa64 %%T1, [rel S_box_flipped + 1*64]
vmovdqa64 %%T2, [rel S_box_flipped + 4*64]
vmovdqa64 %%T3, [rel S_box_flipped + 5*64]
vpermw %%T0{k1}{z}, %%IN0A, %%T0
vpermw %%T1{k1}{z}, %%IN0A, %%T1
vpermw %%T2{k2}{z}, %%IN0A, %%T2
vpermw %%T3{k2}{z}, %%IN0A, %%T3
vpxord %%T0, %%T0, %%T2
vpxord %%OUT, %%T1, %%T3
vmovdqu16 %%OUT{k3}, %%T0
vmovdqa64 %%T0, [rel S_box_flipped + 2*64]
vmovdqa64 %%T1, [rel S_box_flipped + 3*64]
vmovdqa64 %%T2, [rel S_box_flipped + 6*64]
vmovdqa64 %%T3, [rel S_box_flipped + 7*64]
vpermw %%T0{k1}{z}, %%IN0B, %%T0
vpermw %%T1{k1}{z}, %%IN0B, %%T1
vpermw %%T2{k2}{z}, %%IN0B, %%T2
vpermw %%T3{k2}{z}, %%IN0B, %%T3
vpxord %%T0, %%T0, %%T2
vpxord %%T3, %%T1, %%T3
vmovdqu16 %%T3{k4}, %%T0
vpsllw %%T3, %%T3, 4
vpxord %%OUT, %%OUT, %%T3
vmovdqa64 %%T0, [rel S_box_flipped + 8*64]
vmovdqa64 %%T1, [rel S_box_flipped + 9*64]
vmovdqa64 %%T2, [rel S_box_flipped + 12*64]
vmovdqa64 %%T3, [rel S_box_flipped + 13*64]
vpermw %%T0{k1}{z}, %%IN1A, %%T0
vpermw %%T1{k1}{z}, %%IN1A, %%T1
vpermw %%T2{k2}{z}, %%IN1A, %%T2
vpermw %%T3{k2}{z}, %%IN1A, %%T3
vpxord %%T0, %%T0, %%T2
vpxord %%T4, %%T1, %%T3
vmovdqu16 %%T4{k5}, %%T0
vmovdqa64 %%T0, [rel S_box_flipped + 10*64]
vmovdqa64 %%T1, [rel S_box_flipped + 11*64]
vmovdqa64 %%T2, [rel S_box_flipped + 14*64]
vmovdqa64 %%T3, [rel S_box_flipped + 15*64]
vpermw %%T0{k1}{z}, %%IN1B, %%T0
vpermw %%T1{k1}{z}, %%IN1B, %%T1
vpermw %%T2{k2}{z}, %%IN1B, %%T2
vpermw %%T3{k2}{z}, %%IN1B, %%T3
vpxord %%T0, %%T0, %%T2
vpxord %%T5, %%T1, %%T3
vmovdqu16 %%T5{k6}, %%T0
vpsllw %%T5, %%T5, 4
vpxord %%T4, %%T4, %%T5
vpsllw %%T4, %%T4, 8
vpxord %%OUT, %%OUT, %%T4
vpshufb %%OUT, %%OUT, [rel shuffle_reg]
%endmacro
;;; ===========================================================================
;;; DES encryption/decryption round
;;; ===========================================================================
;;;
;;; Clobbers k1-k6 OpMask registers
;;;
;;; ENC_DEC [in] - ENC for encryption, DEC for decryption
;;; R [in/out] - zmm register; plain text in & cipher text out
;;; L [in/out] - zmm register; plain text in & cipher text out
;;; KS [in] - pointer to the key schedule
;;; T0-T11 [clobbered] - temporary zmm register
%macro DES_ENC_DEC 16
%define %%ENC_DEC %1
%define %%R %2
%define %%L %3
%define %%KS %4
%define %%T0 %5
%define %%T1 %6
%define %%T2 %7
%define %%T3 %8
%define %%T4 %9
%define %%T5 %10
%define %%T6 %11
%define %%T7 %12
%define %%T8 %13
%define %%T9 %14
%define %%T10 %15
%define %%T11 %16
IP_Z %%R, %%L, %%T0
%ifidn %%ENC_DEC, ENC
;; ENCRYPTION
xor KSOFFSET, KSOFFSET
%%_des_enc_loop:
E_PHASE %%R, %%T1, %%T2, %%T3, %%T4, [%%KS + KSOFFSET + (0*64)], [%%KS + KSOFFSET + (1*64)], %%T6, %%T7
S_PHASE %%T1, %%T2, %%T3, %%T4, %%T0, %%T6, %%T7, %%T8, %%T9, %%T10, %%T11
P_PHASE %%T0, %%T1, %%T2, %%T3, %%T4
vpxord %%L, %%L, %%T0
E_PHASE %%L, %%T1, %%T2, %%T3, %%T4, [%%KS + KSOFFSET + (2*64)], [%%KS + KSOFFSET + (3*64)], %%T6, %%T7
S_PHASE %%T1, %%T2, %%T3, %%T4, %%T0, %%T6, %%T7, %%T8, %%T9, %%T10, %%T11
P_PHASE %%T0, %%T1, %%T2, %%T3, %%T4
vpxord %%R, %%R, %%T0
add KSOFFSET, (4*64)
cmp KSOFFSET, (8*(4*64))
jb %%_des_enc_loop
%else
;; DECRYPTION
mov KSOFFSET, (8*(4*64))
%%_des_dec_loop:
E_PHASE %%R, %%T1, %%T2, %%T3, %%T4, [%%KS + KSOFFSET - (2*64)], [%%KS + KSOFFSET - (1*64)], %%T6, %%T7
S_PHASE %%T1, %%T2, %%T3, %%T4, %%T0, %%T6, %%T7, %%T8, %%T9, %%T10, %%T11
P_PHASE %%T0, %%T1, %%T2, %%T3, %%T4
vpxord %%L, %%L, %%T0
E_PHASE %%L, %%T1, %%T2, %%T3, %%T4, [%%KS + KSOFFSET - (4*64)], [%%KS + KSOFFSET - (3*64)], %%T6, %%T7
S_PHASE %%T1, %%T2, %%T3, %%T4, %%T0, %%T6, %%T7, %%T8, %%T9, %%T10, %%T11
P_PHASE %%T0, %%T1, %%T2, %%T3, %%T4
vpxord %%R, %%R, %%T0
sub KSOFFSET, (4*64)
jnz %%_des_dec_loop
%endif ; DECRYPTION
FP_Z %%R, %%L, %%T0
%endmacro
;;; ===========================================================================
;;; DATA TRANSPOSITION AT DATA INPUT
;;; ===========================================================================
;;;
;;; IN00 - IN15 [in/out]:
;;; in: IN00 - lane 0 data, IN01 - lane 1 data, ... IN15 - lane 15 data
;;; out: R0 - 16 x word0, L0 - 16 x word1, ... L7 - 16 x word15
;;; T0-T3 [clobbered] - temporary zmm registers
;;; K0-K5 [clobbered] - temporary zmm registers
;;; H0-H3 [clobbered] - temporary zmm registers
%macro TRANSPOSE_IN 30
%define %%IN00 %1 ; R0
%define %%IN01 %2 ; L0
%define %%IN02 %3 ; R1
%define %%IN03 %4 ; L1
%define %%IN04 %5 ; R2
%define %%IN05 %6 ; L2
%define %%IN06 %7 ; R3
%define %%IN07 %8 ; L3
%define %%IN08 %9 ; R4
%define %%IN09 %10 ; L4
%define %%IN10 %11 ; R5
%define %%IN11 %12 ; L5
%define %%IN12 %13 ; R6
%define %%IN13 %14 ; L6
%define %%IN14 %15 ; R7
%define %%IN15 %16 ; L7
%define %%T0 %17
%define %%T1 %18
%define %%T2 %19
%define %%T3 %20
%define %%K0 %21
%define %%K1 %22
%define %%K2 %23
%define %%K3 %24
%define %%K4 %25
%define %%K5 %26
%define %%H0 %27
%define %%H1 %28
%define %%H2 %29
%define %%H3 %30
vpunpckldq %%K0, %%IN00, %%IN01
vpunpckhdq %%K1, %%IN00, %%IN01
vpunpckldq %%T0, %%IN02, %%IN03
vpunpckhdq %%T1, %%IN02, %%IN03
vpunpckldq %%IN00, %%IN04, %%IN05
vpunpckhdq %%IN01, %%IN04, %%IN05
vpunpckldq %%IN02, %%IN06, %%IN07
vpunpckhdq %%IN03, %%IN06, %%IN07
vpunpcklqdq %%K2, %%K0, %%T0
vpunpckhqdq %%T2, %%K0, %%T0
vpunpcklqdq %%K3, %%K1, %%T1
vpunpckhqdq %%T3, %%K1, %%T1
vpunpcklqdq %%K0, %%IN00, %%IN02
vpunpckhqdq %%K1, %%IN00, %%IN02
vpunpcklqdq %%T0, %%IN01, %%IN03
vpunpckhqdq %%T1, %%IN01, %%IN03
vpunpckldq %%K4, %%IN08, %%IN09
vpunpckhdq %%K5, %%IN08, %%IN09
vpunpckldq %%IN04, %%IN10, %%IN11
vpunpckhdq %%IN05, %%IN10, %%IN11
vpunpckldq %%IN06, %%IN12, %%IN13
vpunpckhdq %%IN07, %%IN12, %%IN13
vpunpckldq %%IN10, %%IN14, %%IN15
vpunpckhdq %%IN11, %%IN14, %%IN15
vpunpcklqdq %%IN12, %%K4, %%IN04
vpunpckhqdq %%IN13, %%K4, %%IN04
vpunpcklqdq %%IN14, %%K5, %%IN05
vpunpckhqdq %%IN15, %%K5, %%IN05
vpunpcklqdq %%IN00, %%IN06, %%IN10
vpunpckhqdq %%IN01, %%IN06, %%IN10
vpunpcklqdq %%IN02, %%IN07, %%IN11
vpunpckhqdq %%IN03, %%IN07, %%IN11
vshufi64x2 %%H0, %%K2, %%K0, 0x44
vshufi64x2 %%H1, %%K2, %%K0, 0xee
vshufi64x2 %%H2, %%IN12, %%IN00, 0x44
vshufi64x2 %%H3, %%IN12, %%IN00, 0xee
vshufi64x2 %%IN00, %%H0, %%H2, 0x88 ; R0
vshufi64x2 %%IN04, %%H0, %%H2, 0xdd ; R2
vshufi64x2 %%IN08, %%H1, %%H3, 0x88 ; R4
vshufi64x2 %%IN12, %%H1, %%H3, 0xdd ; R6
vshufi64x2 %%H0, %%T2, %%K1, 0x44
vshufi64x2 %%H1, %%T2, %%K1, 0xee
vshufi64x2 %%H2, %%IN13, %%IN01, 0x44
vshufi64x2 %%H3, %%IN13, %%IN01, 0xee
vshufi64x2 %%IN01, %%H0, %%H2, 0x88 ; L0
vshufi64x2 %%IN05, %%H0, %%H2, 0xdd ; L2
vshufi64x2 %%IN09, %%H1, %%H3, 0x88 ; L4
vshufi64x2 %%IN13, %%H1, %%H3, 0xdd ; L6
vshufi64x2 %%H0, %%K3, %%T0, 0x44
vshufi64x2 %%H1, %%K3, %%T0, 0xee
vshufi64x2 %%H2, %%IN14, %%IN02, 0x44
vshufi64x2 %%H3, %%IN14, %%IN02, 0xee
vshufi64x2 %%IN02, %%H0, %%H2, 0x88 ; R1
vshufi64x2 %%IN06, %%H0, %%H2, 0xdd ; R3
vshufi64x2 %%IN10, %%H1, %%H3, 0x88 ; R5
vshufi64x2 %%IN14, %%H1, %%H3, 0xdd ; R7
vshufi64x2 %%H0, %%T3, %%T1, 0x44
vshufi64x2 %%H1, %%T3, %%T1, 0xee
vshufi64x2 %%H2, %%IN15, %%IN03, 0x44
vshufi64x2 %%H3, %%IN15, %%IN03, 0xee
vshufi64x2 %%IN03, %%H0, %%H2, 0x88 ; L1
vshufi64x2 %%IN07, %%H0, %%H2, 0xdd ; L3
vshufi64x2 %%IN11, %%H1, %%H3, 0x88 ; L5
vshufi64x2 %%IN15, %%H1, %%H3, 0xdd ; L7
%endmacro
;;; ===========================================================================
;;; DATA TRANSPOSITION AT DATA OUTPUT
;;; ===========================================================================
;;;
;;; IN00-IN15 aka R0/L0 - R7/L7 [in/out]:
;;; in: R0 - 16 x word0, L0 - 16 x word1, ... L7 - 16 x word15
;;; out: R0 - lane 0 data, L0 - lane 1 data, ... L7 - lane 15 data
;;; T0-T3 [clobbered] - temporary zmm registers
;;; K0-K5 [clobbered] - temporary zmm registers
;;; H0-H3 [clobbered] - temporary zmm registers
%macro TRANSPOSE_OUT 30
%define %%IN00 %1 ; R0
%define %%IN01 %2 ; L0
%define %%IN02 %3 ; R1
%define %%IN03 %4 ; L1
%define %%IN04 %5 ; R2
%define %%IN05 %6 ; L2
%define %%IN06 %7 ; R3
%define %%IN07 %8 ; L3
%define %%IN08 %9 ; R4
%define %%IN09 %10 ; L4
%define %%IN10 %11 ; R5
%define %%IN11 %12 ; L5
%define %%IN12 %13 ; R6
%define %%IN13 %14 ; L6
%define %%IN14 %15 ; R7
%define %%IN15 %16 ; L7
%define %%T0 %17
%define %%T1 %18
%define %%T2 %19
%define %%T3 %20
%define %%K0 %21
%define %%K1 %22
%define %%K2 %23
%define %%K3 %24
%define %%K4 %25
%define %%K5 %26
%define %%H0 %27
%define %%H1 %28
%define %%H2 %29
%define %%H3 %30
vpunpckldq %%K0, %%IN01, %%IN00
vpunpckhdq %%K1, %%IN01, %%IN00
vpunpckldq %%T0, %%IN03, %%IN02
vpunpckhdq %%T1, %%IN03, %%IN02
vpunpckldq %%IN00, %%IN05, %%IN04
vpunpckhdq %%IN01, %%IN05, %%IN04
vpunpckldq %%IN02, %%IN07, %%IN06
vpunpckhdq %%IN03, %%IN07, %%IN06
vpunpcklqdq %%K2, %%K0, %%T0
vpunpckhqdq %%T2, %%K0, %%T0
vpunpcklqdq %%K3, %%K1, %%T1
vpunpckhqdq %%T3, %%K1, %%T1
vpunpcklqdq %%K0, %%IN00, %%IN02
vpunpckhqdq %%K1, %%IN00, %%IN02
vpunpcklqdq %%T0, %%IN01, %%IN03
vpunpckhqdq %%T1, %%IN01, %%IN03
vpunpckldq %%K4, %%IN09, %%IN08
vpunpckhdq %%K5, %%IN09, %%IN08
vpunpckldq %%IN04, %%IN11, %%IN10
vpunpckhdq %%IN05, %%IN11, %%IN10
vpunpckldq %%IN06, %%IN13, %%IN12
vpunpckhdq %%IN07, %%IN13, %%IN12
vpunpckldq %%IN10, %%IN15, %%IN14
vpunpckhdq %%IN11, %%IN15, %%IN14
vpunpcklqdq %%IN12, %%K4, %%IN04
vpunpckhqdq %%IN13, %%K4, %%IN04
vpunpcklqdq %%IN14, %%K5, %%IN05
vpunpckhqdq %%IN15, %%K5, %%IN05
vpunpcklqdq %%IN00, %%IN06, %%IN10
vpunpckhqdq %%IN01, %%IN06, %%IN10
vpunpcklqdq %%IN02, %%IN07, %%IN11
vpunpckhqdq %%IN03, %%IN07, %%IN11
vshufi64x2 %%H0, %%K2, %%K0, 0x44
vshufi64x2 %%H1, %%K2, %%K0, 0xee
vshufi64x2 %%H2, %%IN12, %%IN00, 0x44
vshufi64x2 %%H3, %%IN12, %%IN00, 0xee
vshufi64x2 %%IN00, %%H0, %%H2, 0x88 ; R0
vshufi64x2 %%IN04, %%H0, %%H2, 0xdd ; R2
vshufi64x2 %%IN08, %%H1, %%H3, 0x88 ; R4
vshufi64x2 %%IN12, %%H1, %%H3, 0xdd ; R6
vshufi64x2 %%H0, %%T2, %%K1, 0x44
vshufi64x2 %%H1, %%T2, %%K1, 0xee
vshufi64x2 %%H2, %%IN13, %%IN01, 0x44
vshufi64x2 %%H3, %%IN13, %%IN01, 0xee
vshufi64x2 %%IN01, %%H0, %%H2, 0x88 ; L0
vshufi64x2 %%IN05, %%H0, %%H2, 0xdd ; L2
vshufi64x2 %%IN09, %%H1, %%H3, 0x88 ; L4
vshufi64x2 %%IN13, %%H1, %%H3, 0xdd ; L6
vshufi64x2 %%H0, %%K3, %%T0, 0x44
vshufi64x2 %%H1, %%K3, %%T0, 0xee
vshufi64x2 %%H2, %%IN14, %%IN02, 0x44
vshufi64x2 %%H3, %%IN14, %%IN02, 0xee
vshufi64x2 %%IN02, %%H0, %%H2, 0x88 ; R1
vshufi64x2 %%IN06, %%H0, %%H2, 0xdd ; R3
vshufi64x2 %%IN10, %%H1, %%H3, 0x88 ; R5
vshufi64x2 %%IN14, %%H1, %%H3, 0xdd ; R7
vshufi64x2 %%H0, %%T3, %%T1, 0x44
vshufi64x2 %%H1, %%T3, %%T1, 0xee
vshufi64x2 %%H2, %%IN15, %%IN03, 0x44
vshufi64x2 %%H3, %%IN15, %%IN03, 0xee
vshufi64x2 %%IN03, %%H0, %%H2, 0x88 ; L1
vshufi64x2 %%IN07, %%H0, %%H2, 0xdd ; L3
vshufi64x2 %%IN11, %%H1, %%H3, 0x88 ; L5
vshufi64x2 %%IN15, %%H1, %%H3, 0xdd ; L7
%endmacro
;;; ===========================================================================
;;; DATA TRANSPOSITION OF ONE DES BLOCK AT DATA INPUT
;;; ===========================================================================
;;;
;;; IN00-IN15 / R0/L0-R7/L7 [in/out]:
;;; in: IN00 - lane 0 data, IN01 - lane 1 data, ... IN15 - lane 15 data
;;; out: R0 - 16 x word0, L0 - 16 x word1
;;; T0,T2 [clobbered] - temporary zmm registers
;;; K0-K4 [clobbered] - temporary zmm registers
;;; H0,H2 [clobbered] - temporary zmm registers
%macro TRANSPOSE_IN_ONE 24
%define %%IN00 %1 ; R0
%define %%IN01 %2 ; L0
%define %%IN02 %3 ; R1
%define %%IN03 %4 ; L1
%define %%IN04 %5 ; R2
%define %%IN05 %6 ; L2
%define %%IN06 %7 ; R3
%define %%IN07 %8 ; L3
%define %%IN08 %9 ; R4
%define %%IN09 %10 ; L4
%define %%IN10 %11 ; R5
%define %%IN11 %12 ; L5
%define %%IN12 %13 ; R6
%define %%IN13 %14 ; L6
%define %%IN14 %15 ; R7
%define %%IN15 %16 ; L7
%define %%T0 %17
%define %%T2 %18
%define %%K0 %19
%define %%K1 %20
%define %%K2 %21
%define %%K4 %22
%define %%H0 %23
%define %%H2 %24
vpunpckldq %%K0, %%IN00, %%IN01
vpunpckhdq %%K1, %%IN00, %%IN01
vpunpckldq %%T0, %%IN02, %%IN03
vpunpckldq %%IN00, %%IN04, %%IN05
vpunpckhdq %%IN01, %%IN04, %%IN05
vpunpckldq %%IN02, %%IN06, %%IN07
vpunpcklqdq %%K2, %%K0, %%T0
vpunpckhqdq %%T2, %%K0, %%T0
vpunpcklqdq %%K0, %%IN00, %%IN02
vpunpckhqdq %%K1, %%IN00, %%IN02
vpunpckldq %%K4, %%IN08, %%IN09
vpunpckldq %%IN04, %%IN10, %%IN11
vpunpckldq %%IN06, %%IN12, %%IN13
vpunpckldq %%IN10, %%IN14, %%IN15
vpunpcklqdq %%IN12, %%K4, %%IN04
vpunpckhqdq %%IN13, %%K4, %%IN04
vpunpcklqdq %%IN00, %%IN06, %%IN10
vpunpckhqdq %%IN01, %%IN06, %%IN10
vshufi64x2 %%H0, %%K2, %%K0, 0x44
vshufi64x2 %%H2, %%IN12, %%IN00, 0x44
vshufi64x2 %%IN00, %%H0, %%H2, 0x88 ; R0
vshufi64x2 %%H0, %%T2, %%K1, 0x44
vshufi64x2 %%H2, %%IN13, %%IN01, 0x44
vshufi64x2 %%IN01, %%H0, %%H2, 0x88 ; L0
%endmacro
;;; ===========================================================================
;;; DATA TRANSPOSITION OF ONE DES BLOCK AT DATA OUTPUT
;;; ===========================================================================
;;;
;;; IN00-IN15 aka R0/L0 - R7/L7 [in/out]:
;;; in: R0 - 16 x word0, L0 - 16 x word1
;;; out: R0 - lane 0 data, L0 - lane 1 data, ... L7 - lane 15 data
;;; T0-T3 [clobbered] - temporary zmm registers
;;; K0-K3 [clobbered] - temporary zmm registers
;;; H0,H1 [clobbered] - temporary zmm registers
%macro TRANSPOSE_OUT_ONE 25
%define %%IN00 %1 ; R0
%define %%IN01 %2 ; L0
%define %%IN02 %3 ; R1
%define %%IN03 %4 ; L1
%define %%IN04 %5 ; R2
%define %%IN05 %6 ; L2
%define %%IN06 %7 ; R3
%define %%IN07 %8 ; L3
%define %%IN08 %9 ; R4
%define %%IN09 %10 ; L4
%define %%IN10 %11 ; R5
%define %%IN11 %12 ; L5
%define %%IN12 %13 ; R6
%define %%IN13 %14 ; L6
%define %%IN14 %15 ; R7
%define %%IN15 %16 ; L7
%define %%T0 %17
%define %%T2 %18
%define %%T3 %19
%define %%K0 %20
%define %%K1 %21
%define %%K2 %22
%define %%K3 %23
%define %%H0 %24
%define %%H1 %25
vpxord %%T0, %%T0, %%T0
vpunpckldq %%K0, %%IN01, %%IN00
vpunpckhdq %%K1, %%IN01, %%IN00
vpunpcklqdq %%K2, %%K0, %%T0
vpunpckhqdq %%T2, %%K0, %%T0
vpunpcklqdq %%K3, %%K1, %%T0
vpunpckhqdq %%T3, %%K1, %%T0
vshufi64x2 %%H0, %%K2, %%T0, 0x44
vshufi64x2 %%H1, %%K2, %%T0, 0xee
vshufi64x2 %%IN00, %%H0, %%T0, 0x88 ; R0
vshufi64x2 %%IN04, %%H0, %%T0, 0xdd ; R2
vshufi64x2 %%IN08, %%H1, %%T0, 0x88 ; R4
vshufi64x2 %%IN12, %%H1, %%T0, 0xdd ; R6
vshufi64x2 %%H0, %%T2, %%T0, 0x44
vshufi64x2 %%H1, %%T2, %%T0, 0xee
vshufi64x2 %%IN01, %%H0, %%T0, 0x88 ; L0
vshufi64x2 %%IN05, %%H0, %%T0, 0xdd ; L2
vshufi64x2 %%IN09, %%H1, %%T0, 0x88 ; L4
vshufi64x2 %%IN13, %%H1, %%T0, 0xdd ; L6
vshufi64x2 %%H0, %%K3, %%T0, 0x44
vshufi64x2 %%H1, %%K3, %%T0, 0xee
vshufi64x2 %%IN02, %%H0, %%T0, 0x88 ; R1
vshufi64x2 %%IN06, %%H0, %%T0, 0xdd ; R3
vshufi64x2 %%IN10, %%H1, %%T0, 0x88 ; R5
vshufi64x2 %%IN14, %%H1, %%T0, 0xdd ; R7
vshufi64x2 %%H0, %%T3, %%T0, 0x44
vshufi64x2 %%H1, %%T3, %%T0, 0xee
vshufi64x2 %%IN03, %%H0, %%T0, 0x88 ; L1
vshufi64x2 %%IN07, %%H0, %%T0, 0xdd ; L3
vshufi64x2 %%IN11, %%H1, %%T0, 0x88 ; L5
vshufi64x2 %%IN15, %%H1, %%T0, 0xdd ; L7
%endmacro
;;; ===========================================================================
;;; DES INITIALIZATION
;;; key schedule transposition and IV set up
;;; ===========================================================================
;;;
;;; STATE_KEYS [in] - KEYS in DES OOO STATE
;;; STATE_IV [ in] - IV in DES OOO STATE
;;; KS [out] - place to store transposed key schedule or NULL
;;; IV0 [out] - r512; initialization vector
;;; IV1 [out] - r512; initialization vector
;;; T0-T27 [clobbered] - temporary r512
%macro DES_INIT 33
%define %%STATE_KEYS %1
%define %%STATE_IV %2
%define %%KS %3
%define %%IV0 %4
%define %%IV1 %5
%define %%T0 %6
%define %%T1 %7
%define %%T2 %8
%define %%T3 %9
%define %%T4 %10
%define %%T5 %11
%define %%T6 %12
%define %%T7 %13
%define %%T8 %14
%define %%T9 %15
%define %%T10 %16
%define %%T11 %17
%define %%T12 %18
%define %%T13 %19
%define %%T14 %20
%define %%T15 %21
%define %%T16 %22
%define %%T17 %23
%define %%T18 %24
%define %%T19 %25
%define %%T20 %26
%define %%T21 %27
%define %%T22 %28
%define %%T23 %29
%define %%T24 %30
%define %%T25 %31
%define %%T26 %32
%define %%T27 %33
;; set up the key schedule
;; - load first half of the keys & transpose
;; - transpose and store
;; note: we can use IV registers as temporary ones here
%assign IDX 0
%rep 16
mov IA0, [%%STATE_KEYS + (IDX*PTR_SZ)]
vmovdqu64 %%T %+ IDX, [IA0]
%assign IDX (IDX + 1)
%endrep
TRANSPOSE_IN %%T0, %%T1, %%T2, %%T3, %%T4, %%T5, %%T6, %%T7, %%T8, %%T9, %%T10, %%T11, %%T12, %%T13, %%T14, %%T15, %%T16, %%T17, %%T18, %%T19, %%T20, %%T21, %%T22, %%T23, %%T24, %%T25, %%T26, %%T27, %%IV0, %%IV1
%assign IDX 0
%rep 16
vmovdqu64 [%%KS + (IDX * 64)], %%T %+ IDX
%assign IDX (IDX + 1)
%endrep
;; - load second half of the keys & transpose
;; - transpose and store
;; note: we can use IV registers as temporary ones here
%assign IDX 0
%rep 16
mov IA0, [%%STATE_KEYS + (IDX*PTR_SZ)]
vmovdqu64 %%T %+ IDX, [IA0 + 64]
%assign IDX (IDX + 1)
%endrep
TRANSPOSE_IN %%T0, %%T1, %%T2, %%T3, %%T4, %%T5, %%T6, %%T7, %%T8, %%T9, %%T10, %%T11, %%T12, %%T13, %%T14, %%T15, %%T16, %%T17, %%T18, %%T19, %%T20, %%T21, %%T22, %%T23, %%T24, %%T25, %%T26, %%T27, %%IV0, %%IV1
%assign IDX 0
%rep 16
vmovdqu64 [%%KS + (16 * 64) + (IDX * 64)], %%T %+ IDX
%assign IDX (IDX + 1)
%endrep
;; set up IV
;; - they are already kept transposed so this is enough to load them
vmovdqu64 %%IV0, [%%STATE_IV + (0 * 64)]
vmovdqu64 %%IV1, [%%STATE_IV + (1 * 64)]
%endmacro
;;; ===========================================================================
;;; 3DES INITIALIZATION
;;; key schedule transposition and IV set up
;;; ===========================================================================
;;;
;;; STATE_KEYS [in] - KEYS in 3DES OOO STATE
;;; STATE_IV [ in] - IV in 3DES OOO STATE
;;; KS1 [out] - place to store transposed key schedule or NULL
;;; KS2 [out] - place to store transposed key schedule or NULL
;;; KS3 [out] - place to store transposed key schedule or NULL
;;; IV0 [out] - r512; initialization vector
;;; IV1 [out] - r512; initialization vector
;;; T0-T27 [clobbered] - temporary r512
;;; DIR [in] - ENC/DEC (keys arranged in different order for enc/dec)
%macro DES3_INIT 36
%define %%STATE_KEYS %1
%define %%STATE_IV %2
%define %%KS1 %3
%define %%KS2 %4
%define %%KS3 %5
%define %%IV0 %6
%define %%IV1 %7
%define %%T0 %8
%define %%T1 %9
%define %%T2 %10
%define %%T3 %11
%define %%T4 %12
%define %%T5 %13
%define %%T6 %14
%define %%T7 %15
%define %%T8 %16
%define %%T9 %17
%define %%T10 %18
%define %%T11 %19
%define %%T12 %20
%define %%T13 %21
%define %%T14 %22
%define %%T15 %23
%define %%T16 %24
%define %%T17 %25
%define %%T18 %26
%define %%T19 %27
%define %%T20 %28
%define %%T21 %29
%define %%T22 %30
%define %%T23 %31
%define %%T24 %32
%define %%T25 %33
%define %%T26 %34
%define %%T27 %35
%define %%DIR %36
%ifidn %%DIR, ENC
%assign KEY_IDX 0
%else
%assign KEY_IDX 2
%endif
%assign KS_IDX 1
%rep 3
;; set up the key schedule
;; - load first half of the keys & transpose
;; - transpose and store
;; note: we can use IV registers as temporary ones here
%assign IDX 0
%rep 16
mov IA0, [%%STATE_KEYS + (IDX*PTR_SZ)]
mov IA0, [IA0 + (KEY_IDX * PTR_SZ)]
vmovdqu64 %%T %+ IDX, [IA0]
%assign IDX (IDX + 1)
%endrep
TRANSPOSE_IN %%T0, %%T1, %%T2, %%T3, %%T4, %%T5, %%T6, %%T7, %%T8, %%T9, %%T10, %%T11, %%T12, %%T13, %%T14, %%T15, %%T16, %%T17, %%T18, %%T19, %%T20, %%T21, %%T22, %%T23, %%T24, %%T25, %%T26, %%T27, %%IV0, %%IV1
%assign IDX 0
%rep 16
vmovdqu64 [%%KS %+ KS_IDX + (IDX * 64)], %%T %+ IDX
%assign IDX (IDX + 1)
%endrep
;; - load second half of the keys & transpose
;; - transpose and store
;; note: we can use IV registers as temporary ones here
%assign IDX 0
%rep 16
mov IA0, [%%STATE_KEYS + (IDX*PTR_SZ)]
mov IA0, [IA0 + (KEY_IDX * PTR_SZ)]
vmovdqu64 %%T %+ IDX, [IA0 + 64]
%assign IDX (IDX + 1)
%endrep
TRANSPOSE_IN %%T0, %%T1, %%T2, %%T3, %%T4, %%T5, %%T6, %%T7, %%T8, %%T9, %%T10, %%T11, %%T12, %%T13, %%T14, %%T15, %%T16, %%T17, %%T18, %%T19, %%T20, %%T21, %%T22, %%T23, %%T24, %%T25, %%T26, %%T27, %%IV0, %%IV1
%assign IDX 0
%rep 16
vmovdqu64 [%%KS %+ KS_IDX + (16 * 64) + (IDX * 64)], %%T %+ IDX
%assign IDX (IDX + 1)
%endrep
%ifidn %%DIR, ENC
%assign KEY_IDX (KEY_IDX + 1)
%else
%assign KEY_IDX (KEY_IDX - 1)
%endif
%assign KS_IDX (KS_IDX + 1)
%endrep ; KEY_IDX / KS_IDX
;; set up IV
;; - they are already kept transposed so this is enough to load them
vmovdqu64 %%IV0, [%%STATE_IV + (0 * 64)]
vmovdqu64 %%IV1, [%%STATE_IV + (1 * 64)]
%endmacro
;;; ===========================================================================
;;; DES FINISH
;;; Update in/out pointers and store IV
;;; ===========================================================================
;;;
;;; Needs: STATE & SIZE
;;; IV0 [in] - r512; initialization vector
;;; IV1 [in] - r512; initialization vector
;;; T0-T4 [clobbered] - temporary r512 registers
%macro DES_FINISH 7
%define %%IV0 %1
%define %%IV1 %2
%define %%T0 %3
%define %%T1 %4
%define %%T2 %5
%define %%T3 %6
%define %%T4 %7
vpbroadcastq %%T4, SIZE
vmovdqu64 %%T0, [STATE + _des_args_in + (0 * PTR_SZ)]
vmovdqu64 %%T1, [STATE + _des_args_in + (8 * PTR_SZ)]
vmovdqu64 %%T2, [STATE + _des_args_out + (0 * PTR_SZ)]
vmovdqu64 %%T3, [STATE + _des_args_out + (8 * PTR_SZ)]
vpaddq %%T0, %%T0, %%T4
vpaddq %%T1, %%T1, %%T4
vpaddq %%T2, %%T2, %%T4
vpaddq %%T3, %%T3, %%T4
vmovdqu64 [STATE + _des_args_in + (0 * PTR_SZ)], %%T0
vmovdqu64 [STATE + _des_args_in + (8 * PTR_SZ)], %%T1
vmovdqu64 [STATE + _des_args_out + (0 * PTR_SZ)], %%T2
vmovdqu64 [STATE + _des_args_out + (8 * PTR_SZ)], %%T3
vmovdqu64 [STATE + _des_args_IV + (0 * 64)], %%IV0
vmovdqu64 [STATE + _des_args_IV + (1 * 64)], %%IV1
%endmacro
;;; ===========================================================================
;;; DES CFB ENCRYPT/DECRYPT - ONE BLOCK ONLY
;;; ===========================================================================
;;;
;;; Needs: STATE, IA0-IA2
;;; ENC_DEC [in] - encyrpt (ENC) or decrypt (DEC) selection
;;; KS [in] - key schedule
;;; T0-T24 [clobbered] - temporary r512
;;; T_IN [in] - 16 * 8 byte storage
;;; T_OUT [in] - 16 * 8 byte storage
;;; T_MASK [in] - 16 * 4 byte storage
;;; T_IV [in] - 16 * 8 byte storage
;;;
;;; NOTE: clobbers OpMask registers
%macro DES_CFB_ONE 31
%define %%ENC_DEC %1
%define %%KS %2
%define %%T0 %3
%define %%T1 %4
%define %%T2 %5
%define %%T3 %6
%define %%T4 %7
%define %%T5 %8
%define %%T6 %9
%define %%T7 %10
%define %%T8 %11
%define %%T9 %12
%define %%T10 %13
%define %%T11 %14
%define %%T12 %15
%define %%T13 %16
%define %%T14 %17
%define %%T15 %18
%define %%T16 %19
%define %%T17 %20
%define %%T18 %21
%define %%T19 %22
%define %%T20 %23
%define %%T21 %24
%define %%T22 %25
%define %%T23 %26
%define %%T24 %27
%define %%T_IN %28
%define %%T_OUT %29
%define %%T_IV %30
%define %%T_MASK %31
;; - find mask for non-zero partial lengths
vpxord %%T10, %%T10, %%T10
vmovdqu64 %%T0, [STATE + _des_args_PLen]
vpcmpd k3, %%T0, %%T10, 4 ; NEQ
kmovw DWORD(IA0), k3
movzx DWORD(IA0), WORD(IA0)
or DWORD(IA0), DWORD(IA0)
jz %%_des_cfb_one_end ; no non-zero partial lengths
%ifidn %%ENC_DEC, ENC
;; For encyrption case we need to make sure that
;; all full blocks are complete before proceeding
;; with CFB partial block.
;; To do that current out position is compared against
;; calculated last full block position.
vmovdqu64 %%T1, [STATE + _des_args_out + (0*8)]
vmovdqu64 %%T2, [STATE + _des_args_LOut + (0*8)]
vmovdqu64 %%T3, [STATE + _des_args_out + (8*8)]
vmovdqu64 %%T4, [STATE + _des_args_LOut + (8*8)]
vpcmpq k4, %%T1, %%T2, 0 ; EQ
vpcmpq k5, %%T3, %%T4, 0 ; EQ
kmovw DWORD(IA1), k4
movzx DWORD(IA1), BYTE(IA1)
kmovw DWORD(IA2), k5
movzx DWORD(IA2), BYTE(IA2)
shl DWORD(IA2), 8
or DWORD(IA2), DWORD(IA1)
and DWORD(IA0), DWORD(IA2)
jz %%_des_cfb_one_end ; no non-zero lengths left
kmovw k3, DWORD(IA0)
%endif
;; Calculate ((1 << partial_bytes) - 1)
;; in order to get the mask for loads and stores
;; k3 & IA0 - hold valid mask
vmovdqa64 %%T1, [rel vec_ones_32b]
vpsllvd %%T2{k3}{z}, %%T1, %%T0
vpsubd %%T2{k3}{z}, %%T2, %%T1
vmovdqu64 [%%T_MASK], %%T2
;; clear selected partial lens not to do them twice
vmovdqu32 [STATE + _des_args_PLen]{k3}, %%T10
;; copy IV, in and out pointers
vmovdqu64 %%T1, [STATE + _des_args_in + (0*PTR_SZ)]
vmovdqu64 %%T2, [STATE + _des_args_in + (8*PTR_SZ)]
vmovdqu64 %%T3, [STATE + _des_args_out + (0*PTR_SZ)]
vmovdqu64 %%T4, [STATE + _des_args_out + (8*PTR_SZ)]
vmovdqu64 %%T5, [STATE + _des_args_IV + (0*64)]
vmovdqu64 %%T6, [STATE + _des_args_IV + (1*64)]
vmovdqu64 [%%T_IN + (0*PTR_SZ)], %%T1
vmovdqu64 [%%T_IN + (8*PTR_SZ)], %%T2
vmovdqu64 [%%T_OUT + (0*PTR_SZ)], %%T3
vmovdqu64 [%%T_OUT + (8*PTR_SZ)], %%T4
vmovdqu64 [%%T_IV + (0*64)], %%T5
vmovdqu64 [%%T_IV + (1*64)], %%T6
;; calculate last block case mask
;; - first block case requires no modifications to in/out/IV
vmovdqu64 %%T1, [STATE + _des_args_BLen]
vpcmpd k2, %%T1, %%T10, 4 ; NEQ
kmovw DWORD(IA1), k2
and DWORD(IA1), DWORD(IA0)
jz %%_des_cfb_one_no_last_blocks
;; set up IV, in and out for the last block case
;; - Last block needs in and out to be set differently (decryption only)
;; - IA1 holds the last block mask
%ifidn %%ENC_DEC, DEC
mov DWORD(IA0), DWORD(IA1)
mov DWORD(IA2), DWORD(IA1)
shr DWORD(IA1), 8
and DWORD(IA2), 0xff
kmovw k4, DWORD(IA2)
kmovw k5, DWORD(IA1)
vmovdqu64 %%T1, [STATE + _des_args_LOut + (0*PTR_SZ)]
vmovdqu64 %%T2, [STATE + _des_args_LOut + (8*PTR_SZ)]
vmovdqu64 %%T3, [STATE + _des_args_LIn + (0*PTR_SZ)]
vmovdqu64 %%T4, [STATE + _des_args_LIn + (8*PTR_SZ)]
vmovdqu64 [%%T_OUT + (0*PTR_SZ)]{k4}, %%T1
vmovdqu64 [%%T_OUT + (8*PTR_SZ)]{k5}, %%T2
vmovdqu64 [%%T_IN + (0*PTR_SZ)]{k4}, %%T3
vmovdqu64 [%%T_IN + (8*PTR_SZ)]{k5}, %%T4
%endif ; decryption
;; - IV has to be set differently for CFB as well
;; - IA0 holds the last block mask
%assign IDX 0
%rep 16
test DWORD(IA0), (1 << IDX)
jz %%_des_cfb_one_copy_iv_next %+ IDX
%ifidn %%ENC_DEC, ENC
mov IA2, [STATE + _des_args_LOut + (IDX*PTR_SZ)]
%else
mov IA2, [STATE + _des_args_LIn + (IDX*PTR_SZ)]
%endif
mov IA2, [IA2 - 8]
mov [%%T_IV + (0*4) + (IDX*4)], DWORD(IA2)
shr IA2, 32
mov [%%T_IV + (16*4) + (IDX*4)], DWORD(IA2)
%%_des_cfb_one_copy_iv_next %+ IDX:
%assign IDX (IDX + 1)
%endrep
%%_des_cfb_one_no_last_blocks:
;; Uffff ... finally let's do some DES CFB
;; - let's use T_IN, T_OUT, T_IV and T_MASK
;; - load data with the corresponding masks & transpose
;; - T0 to T15 will hold the data
xor IA0, IA0
%assign IDX 0
%assign K_IDX 1
%rep 16
mov IA1, [%%T_IN + (IDX*PTR_SZ)]
mov DWORD(IA0), [%%T_MASK + (IDX*4)]
kmovq k %+ K_IDX, IA0
vmovdqu8 %%T %+ IDX{k %+ K_IDX}{z}, [IA1]
%assign IDX (IDX + 1)
%assign K_IDX (K_IDX + 1)
%if K_IDX > 7
%assign K_IDX 1 ; iterate through K1 to K7
%endif
%endrep
;; - transpose the data in T0 to T15, T16 to T23 are clobbered
TRANSPOSE_IN_ONE %%T0, %%T1, %%T2, %%T3, %%T4, %%T5, %%T6, %%T7, %%T8, %%T9, %%T10, %%T11, %%T12, %%T13, %%T14, %%T15, %%T16, %%T17, %%T18, %%T19, %%T20, %%T21, %%T22, %%T23
;; - set up IV and %%T16 & %%T17 used as IV0 and IV1
vmovdqu64 %%T16, [%%T_IV + (0 * 64)] ;IV0
vmovdqu64 %%T17, [%%T_IV + (1 * 64)] ;IV1
;; DES encrypt
;; - R0 - %%T0
;; - L0 - %%T1
DES_ENC_DEC ENC, %%T16, %%T17, %%KS, %%T2, %%T3, %%T4, %%T5, %%T6, %%T7, %%T8, %%T9, %%T10, %%T11, %%T12, %%T13
;; CFB style xor with R0/L0 with IV
;; - IV0 - %%T16
;; - IV1 - %%T17
vpxord %%T2, %%T17, %%T0 ; R0 ^ IV1
vpxord %%T0, %%T16, %%T1 ; L0 ^ IV0
vmovdqa64 %%T1, %%T2
;; - new R0 = L0 ^ IV0 (%%T0)
;; - new L0 = R0 ^ IV1 (%%T1)
;; Transpose the data out
;; - %%T2 to %%T24 clobbered
TRANSPOSE_OUT_ONE %%T0, %%T1, %%T2, %%T3, %%T4, %%T5, %%T6, %%T7, %%T8, %%T9, %%T10, %%T11, %%T12, %%T13, %%T14, %%T15, %%T16, %%T17, %%T18, %%T19, %%T20, %%T21, %%T22, %%T23, %%T24
;; Store the transposed data
;; - T0 to T15 will hold the data
xor IA0, IA0
%assign IDX 0
%assign K_IDX 1
%rep 16
mov IA1, [%%T_OUT + (IDX*PTR_SZ)]
mov DWORD(IA0), [%%T_MASK + (IDX*4)]
kmovq k %+ K_IDX, IA0
vmovdqu8 [IA1]{k %+ K_IDX}, %%T %+ IDX
%assign IDX (IDX + 1)
%assign K_IDX (K_IDX + 1)
%if K_IDX > 7
%assign K_IDX 1 ; iterate through K1 to K7
%endif
%endrep
%ifdef SAFE_DATA
;; Clear copied IV's
vpxorq %%T5, %%T5
vmovdqu64 [%%T_IV + (0*64)], %%T5
vmovdqu64 [%%T_IV + (1*64)], %%T5
%endif
%%_des_cfb_one_end:
%endmacro
;;; ===========================================================================
;;; Converts length into mask of DES blocks
;;; ===========================================================================
;;;
;;; MASK [out] - mask8 for value; for masked 64b loads and stores (r64)
;;; USES: IA0, IA1 IA2
;;; ASSUMES: SIZE - OFFSET < 64
%macro GET_MASK8 1
%define %%MASK %1
%ifidn IA1, rcx
%define myrcx IA1
%else
%define myrcx rcx
mov IA1, rcx
%endif
mov myrcx, SIZE
sub myrcx, OFFSET
;; - myrcx - remaining length
;; - divide by 8 (DES block size)
;; - create bit mask of the result
mov DWORD(%%MASK), 1
shr DWORD(myrcx), 3
shl DWORD(%%MASK), BYTE(myrcx)
sub DWORD(%%MASK), 1
%ifnidn IA1, rcx
mov rcx, IA1
%endif
%endmacro
;;; ===========================================================================
;;; DES CBC ENCRYPT CIPHER ONLY (1 to 8 DES blocks only)
;;; ===========================================================================
;;;
;;; NUM_DES_BLOCKS [in] - 1 to 8 DES blocks only
;;; DES_KS [in] - pointer to transposed key schedule
;;;
;;; NOTE: clobbers OpMask registers
;;; REQUIRES: ZTMP0 - ZTMP13, ZW0-ZW15 (depends on NUM_DES_BLOCKS), ZIV0, ZIV1
%macro GEN_DES_ENC_CIPHER 2
%define %%NUM_DES_BLOCKS %1
%define %%DES_KS %2
%assign RN 0
%assign LN 1
%assign RNN 2
%assign LNN 3
%rep %%NUM_DES_BLOCKS - 1
DES_ENC_DEC ENC, ZW %+ RN, ZW %+ LN, %%DES_KS, ZTMP0, ZTMP1, ZTMP2, ZTMP3, ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8, ZTMP9, ZTMP10, ZTMP11
vpxord ZW %+ RNN, ZW %+ RNN, ZW %+ LN ; R1 = R1 ^ L0
vpxord ZW %+ LNN, ZW %+ LNN, ZW %+ RN ; L1 = L1 ^ R0
%assign RN (RN + 2)
%assign LN (LN + 2)
%assign RNN (RNN + 2)
%assign LNN (LNN + 2)
%endrep
DES_ENC_DEC ENC, ZW %+ RN, ZW %+ LN, %%DES_KS, ZTMP0, ZTMP1, ZTMP2, ZTMP3, ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8, ZTMP9, ZTMP10, ZTMP11
vmovdqa64 ZIV0, ZW %+ LN ; IV0 = L7
vmovdqa64 ZIV1, ZW %+ RN ; IV1 = R7
%endmacro
;;; ===========================================================================
;;; DES CBC DECRYPT CIPHER ONLY (1 to 8 DES blocks only)
;;; ===========================================================================
;;;
;;; NUM_DES_BLOCKS [in] - 1 to 8 DES blocks only
;;; DES_KS [in] - pointer to transposed key schedule
;;;
;;; NOTE: clobbers OpMask registers
;;; REQUIRES: ZTMP0 - ZTMP13, ZW0-ZW15 (depends on NUM_DES_BLOCKS), ZIV0, ZIV1
%macro GEN_DES_DEC_CIPHER 2
%define %%NUM_DES_BLOCKS %1
%define %%DES_KS %2
%assign RN 0
%assign LN 1
%rep %%NUM_DES_BLOCKS
vmovdqa64 ZTMP12, ZW %+ RN ; keep R0 as IV for the next round
vmovdqa64 ZTMP13, ZW %+ LN ; keep L0 as IV for the next round
DES_ENC_DEC DEC, ZW %+ RN, ZW %+ LN, %%DES_KS, ZTMP0, ZTMP1, ZTMP2, ZTMP3, ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8, ZTMP9, ZTMP10, ZTMP11
vpxord ZW %+ RN, ZW %+ RN, ZIV1 ; R0 = R0 ^ IV1
vpxord ZW %+ LN, ZW %+ LN, ZIV0 ; L0 = L0 ^ IV0
vmovdqa64 ZIV0, ZTMP12
vmovdqa64 ZIV1, ZTMP13
%assign RN (RN + 2)
%assign LN (LN + 2)
%endrep
%endmacro
;;; ===========================================================================
;;; 3DES CBC ENCRYPT CIPHER ONLY (1 to 8 DES blocks only)
;;; ===========================================================================
;;;
;;; NUM_DES_BLOCKS [in] - 1 to 8 DES blocks only
;;; DES_KS1 [in] - pointer to transposed key schedule 1
;;; DES_KS2 [in] - pointer to transposed key schedule 2
;;; DES_KS3 [in] - pointer to transposed key schedule 3
;;;
;;; NOTE: clobbers OpMask registers
;;; REQUIRES: ZTMP0 - ZTMP13, ZW0-ZW15 (depends on NUM_DES_BLOCKS), ZIV0, ZIV1
%macro GEN_3DES_ENC_CIPHER 4
%define %%NUM_DES_BLOCKS %1
%define %%DES_KS1 %2
%define %%DES_KS2 %3
%define %%DES_KS3 %4
%assign RN 0
%assign LN 1
%assign RNN 2
%assign LNN 3
%rep %%NUM_DES_BLOCKS
;; ENC
DES_ENC_DEC ENC, ZW %+ RN, ZW %+ LN, %%DES_KS1, ZTMP0, ZTMP1, ZTMP2, ZTMP3, ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8, ZTMP9, ZTMP10, ZTMP11
;; DEC
DES_ENC_DEC DEC, ZW %+ LN, ZW %+ RN, %%DES_KS2, ZTMP0, ZTMP1, ZTMP2, ZTMP3, ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8, ZTMP9, ZTMP10, ZTMP11
;; ENC
DES_ENC_DEC ENC, ZW %+ RN, ZW %+ LN, %%DES_KS3, ZTMP0, ZTMP1, ZTMP2, ZTMP3, ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8, ZTMP9, ZTMP10, ZTMP11
%if (RNN < (%%NUM_DES_BLOCKS * 2))
vpxord ZW %+ RNN, ZW %+ RNN, ZW %+ LN ; R1 = R1 ^ L0
vpxord ZW %+ LNN, ZW %+ LNN, ZW %+ RN ; L1 = L1 ^ R0
%else
vmovdqa64 ZIV0, ZW %+ LN ; IV0 = L7
vmovdqa64 ZIV1, ZW %+ RN ; IV1 = R7
%endif
%assign RN (RN + 2)
%assign LN (LN + 2)
%assign RNN (RNN + 2)
%assign LNN (LNN + 2)
%endrep
%endmacro
;;; ===========================================================================
;;; 3DES CBC DECRYPT CIPHER ONLY (1 to 8 DES blocks only)
;;; ===========================================================================
;;;
;;; NUM_DES_BLOCKS [in] - 1 to 8 DES blocks only
;;; DES_KS1 [in] - pointer to transposed key schedule 1
;;; DES_KS2 [in] - pointer to transposed key schedule 2
;;; DES_KS3 [in] - pointer to transposed key schedule 3
;;;
;;; NOTE: clobbers OpMask registers
;;; REQUIRES: ZTMP0 - ZTMP13, ZW0-ZW15 (depends on NUM_DES_BLOCKS), ZIV0, ZIV1
%macro GEN_3DES_DEC_CIPHER 4
%define %%NUM_DES_BLOCKS %1
%define %%DES_KS1 %2
%define %%DES_KS2 %3
%define %%DES_KS3 %4
%assign RN 0
%assign LN 1
%rep %%NUM_DES_BLOCKS
vmovdqa64 ZTMP12, ZW %+ RN ; keep R0 as IV for the next round
vmovdqa64 ZTMP13, ZW %+ LN ; keep L0 as IV for the next round
;; DEC
DES_ENC_DEC DEC, ZW %+ RN, ZW %+ LN, %%DES_KS1, ZTMP0, ZTMP1, ZTMP2, ZTMP3, ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8, ZTMP9, ZTMP10, ZTMP11
;; ENC
DES_ENC_DEC ENC, ZW %+ LN, ZW %+ RN, %%DES_KS2, ZTMP0, ZTMP1, ZTMP2, ZTMP3, ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8, ZTMP9, ZTMP10, ZTMP11
;; DEC
DES_ENC_DEC DEC, ZW %+ RN, ZW %+ LN, %%DES_KS3, ZTMP0, ZTMP1, ZTMP2, ZTMP3, ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8, ZTMP9, ZTMP10, ZTMP11
vpxord ZW %+ RN, ZW %+ RN, ZIV1 ; R0 = R0 ^ IV1
vpxord ZW %+ LN, ZW %+ LN, ZIV0 ; L0 = L0 ^ IV0
vmovdqa64 ZIV0, ZTMP12
vmovdqa64 ZIV1, ZTMP13
%assign RN (RN + 2)
%assign LN (LN + 2)
%endrep
%endmacro
;;; ===========================================================================
;;; DES CBC / DOCSIS DES ENCRYPT
;;; ===========================================================================
;;;
;;; DES_DOCSIS [in] - select between DES (DES CBC), DOCSIS (DOCSIS DES) and
;;; 3DES (3DES CBC)
;;;
;;; NOTE: clobbers OpMask registers
%macro GENERIC_DES_ENC 1
%define %%DES_DOCSIS %1
;; push the registers and allocate the stack frame
mov rax, rsp
sub rsp, STACKFRAME_size
and rsp, -64
mov [rsp + _rsp_save], rax ; original SP
mov [rsp + _gpr_save + 0*8], r12
mov [rsp + _gpr_save + 1*8], r13
mov [rsp + _gpr_save + 2*8], r14
mov [rsp + _gpr_save + 3*8], r15
%ifnidn %%DES_DOCSIS, 3DES
;; DES and DOCSIS DES
DES_INIT STATE + _des_args_keys, STATE + _des_args_IV, rsp + _key_sched, ZIV0, ZIV1, ZW0, ZW1, ZW2, ZW3, ZW4, ZW5, ZW6, ZW7, ZW8, ZW9, ZW10, ZW11, ZW12, ZW13, ZW14, ZW15, ZTMP0, ZTMP1, ZTMP2, ZTMP3, ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8, ZTMP9, ZTMP10, ZTMP11
%else
;; 3DES
DES3_INIT STATE + _des_args_keys, STATE + _des_args_IV, rsp + _key_sched, rsp + _key_sched2, rsp + _key_sched3, ZIV0, ZIV1, ZW0, ZW1, ZW2, ZW3, ZW4, ZW5, ZW6, ZW7, ZW8, ZW9, ZW10, ZW11, ZW12, ZW13, ZW14, ZW15, ZTMP0, ZTMP1, ZTMP2, ZTMP3, ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8, ZTMP9, ZTMP10, ZTMP11, ENC
%endif
mov [rsp + _size_save], SIZE
and SIZE, -64
xor OFFSET, OFFSET
;; This loop processes message in blocks of 64 bytes.
;; Anything smaller than 64 bytes is handled separately after the loop.
%%_gen_des_enc_loop:
cmp OFFSET, SIZE
jz %%_gen_des_enc_loop_end
;; run loads
mov IA0, [STATE + _des_args_in + (0*PTR_SZ)]
mov IA1, [STATE + _des_args_in + (1*PTR_SZ)]
mov IA2, [STATE + _des_args_in + (2*PTR_SZ)]
mov INP0, [STATE + _des_args_in + (3*PTR_SZ)]
mov INP1, [STATE + _des_args_in + (4*PTR_SZ)]
mov INP2, [STATE + _des_args_in + (5*PTR_SZ)]
mov INP3, [STATE + _des_args_in + (6*PTR_SZ)]
mov INP4, [STATE + _des_args_in + (7*PTR_SZ)]
vmovdqu64 ZW0, [IA0 + OFFSET]
vmovdqu64 ZW1, [IA1 + OFFSET]
vmovdqu64 ZW2, [IA2 + OFFSET]
vmovdqu64 ZW3, [INP0 + OFFSET]
vmovdqu64 ZW4, [INP1 + OFFSET]
vmovdqu64 ZW5, [INP2 + OFFSET]
vmovdqu64 ZW6, [INP3 + OFFSET]
vmovdqu64 ZW7, [INP4 + OFFSET]
mov IA0, [STATE + _des_args_in + (8*PTR_SZ)]
mov IA1, [STATE + _des_args_in + (9*PTR_SZ)]
mov IA2, [STATE + _des_args_in + (10*PTR_SZ)]
mov INP0, [STATE + _des_args_in + (11*PTR_SZ)]
mov INP1, [STATE + _des_args_in + (12*PTR_SZ)]
mov INP2, [STATE + _des_args_in + (13*PTR_SZ)]
mov INP3, [STATE + _des_args_in + (14*PTR_SZ)]
mov INP4, [STATE + _des_args_in + (15*PTR_SZ)]
vmovdqu64 ZW8, [IA0 + OFFSET]
vmovdqu64 ZW9, [IA1 + OFFSET]
vmovdqu64 ZW10, [IA2 + OFFSET]
vmovdqu64 ZW11, [INP0 + OFFSET]
vmovdqu64 ZW12, [INP1 + OFFSET]
vmovdqu64 ZW13, [INP2 + OFFSET]
vmovdqu64 ZW14, [INP3 + OFFSET]
vmovdqu64 ZW15, [INP4 + OFFSET]
;; Transpose input
TRANSPOSE_IN ZW0, ZW1, ZW2, ZW3, ZW4, ZW5, ZW6, ZW7, ZW8, ZW9, ZW10, ZW11, ZW12, ZW13, ZW14, ZW15, ZTMP0, ZTMP1, ZTMP2, ZTMP3, ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8, ZTMP9, ZTMP10, ZTMP11, ZTMP12, ZTMP13
;; DES CBC ENC comes here
vpxord ZW0, ZW0, ZIV0 ; R0 = R0 ^ IV0
vpxord ZW1, ZW1, ZIV1 ; L0 = L0 ^ IV1
%ifnidn %%DES_DOCSIS, 3DES
GEN_DES_ENC_CIPHER 8, rsp + _key_sched
%else
GEN_3DES_ENC_CIPHER 8, rsp + _key_sched, rsp + _key_sched2, rsp + _key_sched3
%endif
;; transpose data on output
TRANSPOSE_OUT ZW0, ZW1, ZW2, ZW3, ZW4, ZW5, ZW6, ZW7, ZW8, ZW9, ZW10, ZW11, ZW12, ZW13, ZW14, ZW15, ZTMP0, ZTMP1, ZTMP2, ZTMP3, ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8, ZTMP9, ZTMP10, ZTMP11, ZTMP12, ZTMP13
;; run stores
mov IA0, [STATE + _des_args_out + (0*PTR_SZ)]
mov IA1, [STATE + _des_args_out + (1*PTR_SZ)]
mov IA2, [STATE + _des_args_out + (2*PTR_SZ)]
mov INP0, [STATE + _des_args_out + (3*PTR_SZ)]
mov INP1, [STATE + _des_args_out + (4*PTR_SZ)]
mov INP2, [STATE + _des_args_out + (5*PTR_SZ)]
mov INP3, [STATE + _des_args_out + (6*PTR_SZ)]
mov INP4, [STATE + _des_args_out + (7*PTR_SZ)]
vmovdqu64 [IA0 + OFFSET], ZW0
vmovdqu64 [IA1 + OFFSET], ZW1
vmovdqu64 [IA2 + OFFSET], ZW2
vmovdqu64 [INP0 + OFFSET], ZW3
vmovdqu64 [INP1 + OFFSET], ZW4
vmovdqu64 [INP2 + OFFSET], ZW5
vmovdqu64 [INP3 + OFFSET], ZW6
vmovdqu64 [INP4 + OFFSET], ZW7
mov IA0, [STATE + _des_args_out + (8*PTR_SZ)]
mov IA1, [STATE + _des_args_out + (9*PTR_SZ)]
mov IA2, [STATE + _des_args_out + (10*PTR_SZ)]
mov INP0, [STATE + _des_args_out + (11*PTR_SZ)]
mov INP1, [STATE + _des_args_out + (12*PTR_SZ)]
mov INP2, [STATE + _des_args_out + (13*PTR_SZ)]
mov INP3, [STATE + _des_args_out + (14*PTR_SZ)]
mov INP4, [STATE + _des_args_out + (15*PTR_SZ)]
vmovdqu64 [IA0 + OFFSET], ZW8
vmovdqu64 [IA1 + OFFSET], ZW9
vmovdqu64 [IA2 + OFFSET], ZW10
vmovdqu64 [INP0 + OFFSET], ZW11
vmovdqu64 [INP1 + OFFSET], ZW12
vmovdqu64 [INP2 + OFFSET], ZW13
vmovdqu64 [INP3 + OFFSET], ZW14
vmovdqu64 [INP4 + OFFSET], ZW15
add OFFSET, 64
jmp %%_gen_des_enc_loop
%%_gen_des_enc_loop_end:
;; This is where we check if there is anything less than 64 bytes
;; of message left for processing.
mov SIZE, [rsp + _size_save]
cmp OFFSET, SIZE
jz %%_gen_des_enc_part_end
;; calculate min of bytes_left and 64, convert to qword mask
GET_MASK8 IA0 ; IA0 = mask
kmovw k7, DWORD(IA0)
mov [rsp + _mask_save], IA0
;; run masked loads
mov IA0, [STATE + _des_args_in + (0*PTR_SZ)]
mov IA1, [STATE + _des_args_in + (1*PTR_SZ)]
mov IA2, [STATE + _des_args_in + (2*PTR_SZ)]
mov INP0, [STATE + _des_args_in + (3*PTR_SZ)]
mov INP1, [STATE + _des_args_in + (4*PTR_SZ)]
mov INP2, [STATE + _des_args_in + (5*PTR_SZ)]
mov INP3, [STATE + _des_args_in + (6*PTR_SZ)]
mov INP4, [STATE + _des_args_in + (7*PTR_SZ)]
vmovdqu64 ZW0{k7}{z}, [IA0 + OFFSET]
vmovdqu64 ZW1{k7}{z}, [IA1 + OFFSET]
vmovdqu64 ZW2{k7}{z}, [IA2 + OFFSET]
vmovdqu64 ZW3{k7}{z}, [INP0 + OFFSET]
vmovdqu64 ZW4{k7}{z}, [INP1 + OFFSET]
vmovdqu64 ZW5{k7}{z}, [INP2 + OFFSET]
vmovdqu64 ZW6{k7}{z}, [INP3 + OFFSET]
vmovdqu64 ZW7{k7}{z}, [INP4 + OFFSET]
mov IA0, [STATE + _des_args_in + (8*PTR_SZ)]
mov IA1, [STATE + _des_args_in + (9*PTR_SZ)]
mov IA2, [STATE + _des_args_in + (10*PTR_SZ)]
mov INP0, [STATE + _des_args_in + (11*PTR_SZ)]
mov INP1, [STATE + _des_args_in + (12*PTR_SZ)]
mov INP2, [STATE + _des_args_in + (13*PTR_SZ)]
mov INP3, [STATE + _des_args_in + (14*PTR_SZ)]
mov INP4, [STATE + _des_args_in + (15*PTR_SZ)]
vmovdqu64 ZW8{k7}{z}, [IA0 + OFFSET]
vmovdqu64 ZW9{k7}{z}, [IA1 + OFFSET]
vmovdqu64 ZW10{k7}{z}, [IA2 + OFFSET]
vmovdqu64 ZW11{k7}{z}, [INP0 + OFFSET]
vmovdqu64 ZW12{k7}{z}, [INP1 + OFFSET]
vmovdqu64 ZW13{k7}{z}, [INP2 + OFFSET]
vmovdqu64 ZW14{k7}{z}, [INP3 + OFFSET]
vmovdqu64 ZW15{k7}{z}, [INP4 + OFFSET]
;; Transpose input
TRANSPOSE_IN ZW0, ZW1, ZW2, ZW3, ZW4, ZW5, ZW6, ZW7, ZW8, ZW9, ZW10, ZW11, ZW12, ZW13, ZW14, ZW15, ZTMP0, ZTMP1, ZTMP2, ZTMP3, ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8, ZTMP9, ZTMP10, ZTMP11, ZTMP12, ZTMP13
;; DES CBC ENC comes here
vpxord ZW0, ZW0, ZIV0 ; R0 = R0 ^ IV0
vpxord ZW1, ZW1, ZIV1 ; L0 = L0 ^ IV1
mov IA0, [rsp + _mask_save]
cmp BYTE(IA0), 0x0f
ja %%_gt_4
jz %%_blocks_4
cmp BYTE(IA0), 0x03
ja %%_blocks_3
jz %%_blocks_2
;; process one block and move to transpose out
%ifnidn %%DES_DOCSIS, 3DES
GEN_DES_ENC_CIPHER 1, rsp + _key_sched
%else
GEN_3DES_ENC_CIPHER 1, rsp + _key_sched, rsp + _key_sched2, rsp + _key_sched3
%endif
jmp %%_transpose_out
%%_blocks_2:
;; process two blocks and move to transpose out
%ifnidn %%DES_DOCSIS, 3DES
GEN_DES_ENC_CIPHER 2, rsp + _key_sched
%else
GEN_3DES_ENC_CIPHER 2, rsp + _key_sched, rsp + _key_sched2, rsp + _key_sched3
%endif
jmp %%_transpose_out
%%_blocks_3:
;; process three blocks and move to transpose out
%ifnidn %%DES_DOCSIS, 3DES
GEN_DES_ENC_CIPHER 3, rsp + _key_sched
%else
GEN_3DES_ENC_CIPHER 3, rsp + _key_sched, rsp + _key_sched2, rsp + _key_sched3
%endif
jmp %%_transpose_out
%%_blocks_4:
;; process four blocks and move to transpose out
%ifnidn %%DES_DOCSIS, 3DES
GEN_DES_ENC_CIPHER 4, rsp + _key_sched
%else
GEN_3DES_ENC_CIPHER 4, rsp + _key_sched, rsp + _key_sched2, rsp + _key_sched3
%endif
jmp %%_transpose_out
%%_gt_4:
cmp BYTE(IA0), 0x3f
ja %%_blocks_7
jz %%_blocks_6
%%_blocks_5:
;; process five blocks and move to transpose out
%ifnidn %%DES_DOCSIS, 3DES
GEN_DES_ENC_CIPHER 5, rsp + _key_sched
%else
GEN_3DES_ENC_CIPHER 5, rsp + _key_sched, rsp + _key_sched2, rsp + _key_sched3
%endif
jmp %%_transpose_out
%%_blocks_6:
;; process six blocks and move to transpose out
%ifnidn %%DES_DOCSIS, 3DES
GEN_DES_ENC_CIPHER 6, rsp + _key_sched
%else
GEN_3DES_ENC_CIPHER 6, rsp + _key_sched, rsp + _key_sched2, rsp + _key_sched3
%endif
jmp %%_transpose_out
%%_blocks_7:
;; process seven blocks and move to transpose out
%ifnidn %%DES_DOCSIS, 3DES
GEN_DES_ENC_CIPHER 7, rsp + _key_sched
%else
GEN_3DES_ENC_CIPHER 7, rsp + _key_sched, rsp + _key_sched2, rsp + _key_sched3
%endif
%%_transpose_out:
;; transpose data on output
TRANSPOSE_OUT ZW0, ZW1, ZW2, ZW3, ZW4, ZW5, ZW6, ZW7, ZW8, ZW9, ZW10, ZW11, ZW12, ZW13, ZW14, ZW15, ZTMP0, ZTMP1, ZTMP2, ZTMP3, ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8, ZTMP9, ZTMP10, ZTMP11, ZTMP12, ZTMP13
;; run masked stores
mov IA0, [STATE + _des_args_out + (0*PTR_SZ)]
mov IA1, [STATE + _des_args_out + (1*PTR_SZ)]
mov IA2, [STATE + _des_args_out + (2*PTR_SZ)]
mov INP0, [STATE + _des_args_out + (3*PTR_SZ)]
mov INP1, [STATE + _des_args_out + (4*PTR_SZ)]
mov INP2, [STATE + _des_args_out + (5*PTR_SZ)]
mov INP3, [STATE + _des_args_out + (6*PTR_SZ)]
mov INP4, [STATE + _des_args_out + (7*PTR_SZ)]
vmovdqu64 [IA0 + OFFSET]{k7}, ZW0
vmovdqu64 [IA1 + OFFSET]{k7}, ZW1
vmovdqu64 [IA2 + OFFSET]{k7}, ZW2
vmovdqu64 [INP0 + OFFSET]{k7}, ZW3
vmovdqu64 [INP1 + OFFSET]{k7}, ZW4
vmovdqu64 [INP2 + OFFSET]{k7}, ZW5
vmovdqu64 [INP3 + OFFSET]{k7}, ZW6
vmovdqu64 [INP4 + OFFSET]{k7}, ZW7
mov IA0, [STATE + _des_args_out + (8*PTR_SZ)]
mov IA1, [STATE + _des_args_out + (9*PTR_SZ)]
mov IA2, [STATE + _des_args_out + (10*PTR_SZ)]
mov INP0, [STATE + _des_args_out + (11*PTR_SZ)]
mov INP1, [STATE + _des_args_out + (12*PTR_SZ)]
mov INP2, [STATE + _des_args_out + (13*PTR_SZ)]
mov INP3, [STATE + _des_args_out + (14*PTR_SZ)]
mov INP4, [STATE + _des_args_out + (15*PTR_SZ)]
vmovdqu64 [IA0 + OFFSET]{k7}, ZW8
vmovdqu64 [IA1 + OFFSET]{k7}, ZW9
vmovdqu64 [IA2 + OFFSET]{k7}, ZW10
vmovdqu64 [INP0 + OFFSET]{k7}, ZW11
vmovdqu64 [INP1 + OFFSET]{k7}, ZW12
vmovdqu64 [INP2 + OFFSET]{k7}, ZW13
vmovdqu64 [INP3 + OFFSET]{k7}, ZW14
vmovdqu64 [INP4 + OFFSET]{k7}, ZW15
%%_gen_des_enc_part_end:
;; store IV and update pointers
DES_FINISH ZIV0, ZIV1, ZTMP0, ZTMP1, ZTMP2, ZTMP3, ZTMP4
;; CFB part for DOCSIS
%ifidn %%DES_DOCSIS, DOCSIS
DES_CFB_ONE ENC, rsp + _key_sched, ZW0, ZW1, ZW2, ZW3, ZW4, ZW5, ZW6, ZW7, ZW8, ZW9, ZW10, ZW11, ZW12, ZW13, ZW14, ZW15, ZTMP0, ZTMP1, ZTMP2, ZTMP3, ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8, rsp + _tmp_in, rsp + _tmp_out, rsp + _tmp_iv, rsp + _tmp_mask
%endif
CLEAR_KEY_SCHEDULE %%DES_DOCSIS, ZW0
;; restore stack pointer and registers
mov r12, [rsp + _gpr_save + 0*8]
mov r13, [rsp + _gpr_save + 1*8]
mov r14, [rsp + _gpr_save + 2*8]
mov r15, [rsp + _gpr_save + 3*8]
mov rsp, [rsp + _rsp_save] ; original SP
%ifdef SAFE_DATA
clear_all_zmms_asm
%endif ;; SAFE_DATA
%endmacro
;;; ===========================================================================
;;; DES CBC / DOCSIS DES DECRYPT
;;; ===========================================================================
;;;
;;; DES_DOCSIS [in] - select between DES (DES CBC), DOCSIS (DOCSIS DES) and
;;; 3DES (3DES CBC)
;;;
;;; NOTE: clobbers OpMask registers
%macro GENERIC_DES_DEC 1
%define %%DES_DOCSIS %1
;; push the registers and allocate the stack frame
mov rax, rsp
sub rsp, STACKFRAME_size
and rsp, -64
mov [rsp + _rsp_save], rax ; original SP
mov [rsp + _gpr_save + 0*8], r12
mov [rsp + _gpr_save + 1*8], r13
mov [rsp + _gpr_save + 2*8], r14
mov [rsp + _gpr_save + 3*8], r15
%ifnidn %%DES_DOCSIS, 3DES
;; DES and DOCSIS
DES_INIT STATE + _des_args_keys, STATE + _des_args_IV, rsp + _key_sched, ZIV0, ZIV1, ZW0, ZW1, ZW2, ZW3, ZW4, ZW5, ZW6, ZW7, ZW8, ZW9, ZW10, ZW11, ZW12, ZW13, ZW14, ZW15, ZTMP0, ZTMP1, ZTMP2, ZTMP3, ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8, ZTMP9, ZTMP10, ZTMP11
%else
;; 3DES
DES3_INIT STATE + _des_args_keys, STATE + _des_args_IV, rsp + _key_sched, rsp + _key_sched2, rsp + _key_sched3, ZIV0, ZIV1, ZW0, ZW1, ZW2, ZW3, ZW4, ZW5, ZW6, ZW7, ZW8, ZW9, ZW10, ZW11, ZW12, ZW13, ZW14, ZW15, ZTMP0, ZTMP1, ZTMP2, ZTMP3, ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8, ZTMP9, ZTMP10, ZTMP11, DEC
%endif
;; CFB part for DOCSIS
%ifidn %%DES_DOCSIS, DOCSIS
DES_CFB_ONE DEC, rsp + _key_sched, ZW0, ZW1, ZW2, ZW3, ZW4, ZW5, ZW6, ZW7, ZW8, ZW9, ZW10, ZW11, ZW12, ZW13, ZW14, ZW15, ZTMP0, ZTMP1, ZTMP2, ZTMP3, ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8, rsp + _tmp_in, rsp + _tmp_out, rsp + _tmp_iv, rsp + _tmp_mask
%endif
mov [rsp + _size_save], SIZE
and SIZE, -64
xor OFFSET, OFFSET
;; This loop processes message in blocks of 64 bytes.
;; Anything smaller than 64 bytes is handled separately after the loop.
%%_gen_des_dec_loop:
cmp OFFSET, SIZE
jz %%_gen_des_dec_loop_end
;; run loads
mov IA0, [STATE + _des_args_in + (0*PTR_SZ)]
mov IA1, [STATE + _des_args_in + (1*PTR_SZ)]
mov IA2, [STATE + _des_args_in + (2*PTR_SZ)]
mov INP0, [STATE + _des_args_in + (3*PTR_SZ)]
mov INP1, [STATE + _des_args_in + (4*PTR_SZ)]
mov INP2, [STATE + _des_args_in + (5*PTR_SZ)]
mov INP3, [STATE + _des_args_in + (6*PTR_SZ)]
mov INP4, [STATE + _des_args_in + (7*PTR_SZ)]
vmovdqu64 ZW0, [IA0 + OFFSET]
vmovdqu64 ZW1, [IA1 + OFFSET]
vmovdqu64 ZW2, [IA2 + OFFSET]
vmovdqu64 ZW3, [INP0 + OFFSET]
vmovdqu64 ZW4, [INP1 + OFFSET]
vmovdqu64 ZW5, [INP2 + OFFSET]
vmovdqu64 ZW6, [INP3 + OFFSET]
vmovdqu64 ZW7, [INP4 + OFFSET]
mov IA0, [STATE + _des_args_in + (8*PTR_SZ)]
mov IA1, [STATE + _des_args_in + (9*PTR_SZ)]
mov IA2, [STATE + _des_args_in + (10*PTR_SZ)]
mov INP0, [STATE + _des_args_in + (11*PTR_SZ)]
mov INP1, [STATE + _des_args_in + (12*PTR_SZ)]
mov INP2, [STATE + _des_args_in + (13*PTR_SZ)]
mov INP3, [STATE + _des_args_in + (14*PTR_SZ)]
mov INP4, [STATE + _des_args_in + (15*PTR_SZ)]
vmovdqu64 ZW8, [IA0 + OFFSET]
vmovdqu64 ZW9, [IA1 + OFFSET]
vmovdqu64 ZW10, [IA2 + OFFSET]
vmovdqu64 ZW11, [INP0 + OFFSET]
vmovdqu64 ZW12, [INP1 + OFFSET]
vmovdqu64 ZW13, [INP2 + OFFSET]
vmovdqu64 ZW14, [INP3 + OFFSET]
vmovdqu64 ZW15, [INP4 + OFFSET]
;; Transpose input
TRANSPOSE_IN ZW0, ZW1, ZW2, ZW3, ZW4, ZW5, ZW6, ZW7, ZW8, ZW9, ZW10, ZW11, ZW12, ZW13, ZW14, ZW15, ZTMP0, ZTMP1, ZTMP2, ZTMP3, ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8, ZTMP9, ZTMP10, ZTMP11, ZTMP12, ZTMP13
%ifnidn %%DES_DOCSIS, 3DES
;; DES CBC DEC comes here
GEN_DES_DEC_CIPHER 8, rsp + _key_sched
%else
;; 3DES CBC DEC comes here
GEN_3DES_DEC_CIPHER 8, rsp + _key_sched, rsp + _key_sched2, rsp + _key_sched3
%endif
;; transpose data on output
TRANSPOSE_OUT ZW0, ZW1, ZW2, ZW3, ZW4, ZW5, ZW6, ZW7, ZW8, ZW9, ZW10, ZW11, ZW12, ZW13, ZW14, ZW15, ZTMP0, ZTMP1, ZTMP2, ZTMP3, ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8, ZTMP9, ZTMP10, ZTMP11, ZTMP12, ZTMP13
;; run stores
mov IA0, [STATE + _des_args_out + (0*PTR_SZ)]
mov IA1, [STATE + _des_args_out + (1*PTR_SZ)]
mov IA2, [STATE + _des_args_out + (2*PTR_SZ)]
mov INP0, [STATE + _des_args_out + (3*PTR_SZ)]
mov INP1, [STATE + _des_args_out + (4*PTR_SZ)]
mov INP2, [STATE + _des_args_out + (5*PTR_SZ)]
mov INP3, [STATE + _des_args_out + (6*PTR_SZ)]
mov INP4, [STATE + _des_args_out + (7*PTR_SZ)]
vmovdqu64 [IA0 + OFFSET], ZW0
vmovdqu64 [IA1 + OFFSET], ZW1
vmovdqu64 [IA2 + OFFSET], ZW2
vmovdqu64 [INP0 + OFFSET], ZW3
vmovdqu64 [INP1 + OFFSET], ZW4
vmovdqu64 [INP2 + OFFSET], ZW5
vmovdqu64 [INP3 + OFFSET], ZW6
vmovdqu64 [INP4 + OFFSET], ZW7
mov IA0, [STATE + _des_args_out + (8*PTR_SZ)]
mov IA1, [STATE + _des_args_out + (9*PTR_SZ)]
mov IA2, [STATE + _des_args_out + (10*PTR_SZ)]
mov INP0, [STATE + _des_args_out + (11*PTR_SZ)]
mov INP1, [STATE + _des_args_out + (12*PTR_SZ)]
mov INP2, [STATE + _des_args_out + (13*PTR_SZ)]
mov INP3, [STATE + _des_args_out + (14*PTR_SZ)]
mov INP4, [STATE + _des_args_out + (15*PTR_SZ)]
vmovdqu64 [IA0 + OFFSET], ZW8
vmovdqu64 [IA1 + OFFSET], ZW9
vmovdqu64 [IA2 + OFFSET], ZW10
vmovdqu64 [INP0 + OFFSET], ZW11
vmovdqu64 [INP1 + OFFSET], ZW12
vmovdqu64 [INP2 + OFFSET], ZW13
vmovdqu64 [INP3 + OFFSET], ZW14
vmovdqu64 [INP4 + OFFSET], ZW15
add OFFSET, 64
jmp %%_gen_des_dec_loop
%%_gen_des_dec_loop_end:
;; This is where we check if there is anything less than 64 bytes
;; of message left for processing.
mov SIZE, [rsp + _size_save]
cmp OFFSET, SIZE
jz %%_gen_des_dec_part_end
;; calculate min of bytes_left and 64, convert to qword mask
GET_MASK8 IA0 ; IA0 = mask
kmovw k7, DWORD(IA0)
mov [rsp + _mask_save], IA0
;; run masked loads
mov IA0, [STATE + _des_args_in + (0*PTR_SZ)]
mov IA1, [STATE + _des_args_in + (1*PTR_SZ)]
mov IA2, [STATE + _des_args_in + (2*PTR_SZ)]
mov INP0, [STATE + _des_args_in + (3*PTR_SZ)]
mov INP1, [STATE + _des_args_in + (4*PTR_SZ)]
mov INP2, [STATE + _des_args_in + (5*PTR_SZ)]
mov INP3, [STATE + _des_args_in + (6*PTR_SZ)]
mov INP4, [STATE + _des_args_in + (7*PTR_SZ)]
vmovdqu64 ZW0{k7}{z}, [IA0 + OFFSET]
vmovdqu64 ZW1{k7}{z}, [IA1 + OFFSET]
vmovdqu64 ZW2{k7}{z}, [IA2 + OFFSET]
vmovdqu64 ZW3{k7}{z}, [INP0 + OFFSET]
vmovdqu64 ZW4{k7}{z}, [INP1 + OFFSET]
vmovdqu64 ZW5{k7}{z}, [INP2 + OFFSET]
vmovdqu64 ZW6{k7}{z}, [INP3 + OFFSET]
vmovdqu64 ZW7{k7}{z}, [INP4 + OFFSET]
mov IA0, [STATE + _des_args_in + (8*PTR_SZ)]
mov IA1, [STATE + _des_args_in + (9*PTR_SZ)]
mov IA2, [STATE + _des_args_in + (10*PTR_SZ)]
mov INP0, [STATE + _des_args_in + (11*PTR_SZ)]
mov INP1, [STATE + _des_args_in + (12*PTR_SZ)]
mov INP2, [STATE + _des_args_in + (13*PTR_SZ)]
mov INP3, [STATE + _des_args_in + (14*PTR_SZ)]
mov INP4, [STATE + _des_args_in + (15*PTR_SZ)]
vmovdqu64 ZW8{k7}{z}, [IA0 + OFFSET]
vmovdqu64 ZW9{k7}{z}, [IA1 + OFFSET]
vmovdqu64 ZW10{k7}{z}, [IA2 + OFFSET]
vmovdqu64 ZW11{k7}{z}, [INP0 + OFFSET]
vmovdqu64 ZW12{k7}{z}, [INP1 + OFFSET]
vmovdqu64 ZW13{k7}{z}, [INP2 + OFFSET]
vmovdqu64 ZW14{k7}{z}, [INP3 + OFFSET]
vmovdqu64 ZW15{k7}{z}, [INP4 + OFFSET]
;; Transpose input
TRANSPOSE_IN ZW0, ZW1, ZW2, ZW3, ZW4, ZW5, ZW6, ZW7, ZW8, ZW9, ZW10, ZW11, ZW12, ZW13, ZW14, ZW15, ZTMP0, ZTMP1, ZTMP2, ZTMP3, ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8, ZTMP9, ZTMP10, ZTMP11, ZTMP12, ZTMP13
;; DES CBC DEC comes here
mov IA0, [rsp + _mask_save]
cmp BYTE(IA0), 0x0f
ja %%_gt_4
jz %%_blocks_4
cmp BYTE(IA0), 0x03
ja %%_blocks_3
jz %%_blocks_2
;; process one block and move to transpose out
%ifnidn %%DES_DOCSIS, 3DES
GEN_DES_DEC_CIPHER 1, rsp + _key_sched
%else
GEN_3DES_DEC_CIPHER 1, rsp + _key_sched, rsp + _key_sched2, rsp + _key_sched3
%endif
jmp %%_transpose_out
%%_blocks_2:
;; process two blocks and move to transpose out
%ifnidn %%DES_DOCSIS, 3DES
GEN_DES_DEC_CIPHER 2, rsp + _key_sched
%else
GEN_3DES_DEC_CIPHER 2, rsp + _key_sched, rsp + _key_sched2, rsp + _key_sched3
%endif
jmp %%_transpose_out
%%_blocks_3:
;; process three blocks and move to transpose out
%ifnidn %%DES_DOCSIS, 3DES
GEN_DES_DEC_CIPHER 3, rsp + _key_sched
%else
GEN_3DES_DEC_CIPHER 3, rsp + _key_sched, rsp + _key_sched2, rsp + _key_sched3
%endif
jmp %%_transpose_out
%%_blocks_4:
;; process four blocks and move to transpose out
%ifnidn %%DES_DOCSIS, 3DES
GEN_DES_DEC_CIPHER 4, rsp + _key_sched
%else
GEN_3DES_DEC_CIPHER 4, rsp + _key_sched, rsp + _key_sched2, rsp + _key_sched3
%endif
jmp %%_transpose_out
%%_gt_4:
cmp BYTE(IA0), 0x3f
ja %%_blocks_7
jz %%_blocks_6
%%_blocks_5:
;; process five blocks and move to transpose out
%ifnidn %%DES_DOCSIS, 3DES
GEN_DES_DEC_CIPHER 5, rsp + _key_sched
%else
GEN_3DES_DEC_CIPHER 5, rsp + _key_sched, rsp + _key_sched2, rsp + _key_sched3
%endif
jmp %%_transpose_out
%%_blocks_6:
;; process six blocks and move to transpose out
%ifnidn %%DES_DOCSIS, 3DES
GEN_DES_DEC_CIPHER 6, rsp + _key_sched
%else
GEN_3DES_DEC_CIPHER 6, rsp + _key_sched, rsp + _key_sched2, rsp + _key_sched3
%endif
jmp %%_transpose_out
%%_blocks_7:
;; process seven blocks and move to transpose out
%ifnidn %%DES_DOCSIS, 3DES
GEN_DES_DEC_CIPHER 7, rsp + _key_sched
%else
GEN_3DES_DEC_CIPHER 7, rsp + _key_sched, rsp + _key_sched2, rsp + _key_sched3
%endif
%%_transpose_out:
;; transpose data on output
TRANSPOSE_OUT ZW0, ZW1, ZW2, ZW3, ZW4, ZW5, ZW6, ZW7, ZW8, ZW9, ZW10, ZW11, ZW12, ZW13, ZW14, ZW15, ZTMP0, ZTMP1, ZTMP2, ZTMP3, ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8, ZTMP9, ZTMP10, ZTMP11, ZTMP12, ZTMP13
;; run masked stores
mov IA0, [STATE + _des_args_out + (0*PTR_SZ)]
mov IA1, [STATE + _des_args_out + (1*PTR_SZ)]
mov IA2, [STATE + _des_args_out + (2*PTR_SZ)]
mov INP0, [STATE + _des_args_out + (3*PTR_SZ)]
mov INP1, [STATE + _des_args_out + (4*PTR_SZ)]
mov INP2, [STATE + _des_args_out + (5*PTR_SZ)]
mov INP3, [STATE + _des_args_out + (6*PTR_SZ)]
mov INP4, [STATE + _des_args_out + (7*PTR_SZ)]
vmovdqu64 [IA0 + OFFSET]{k7}, ZW0
vmovdqu64 [IA1 + OFFSET]{k7}, ZW1
vmovdqu64 [IA2 + OFFSET]{k7}, ZW2
vmovdqu64 [INP0 + OFFSET]{k7}, ZW3
vmovdqu64 [INP1 + OFFSET]{k7}, ZW4
vmovdqu64 [INP2 + OFFSET]{k7}, ZW5
vmovdqu64 [INP3 + OFFSET]{k7}, ZW6
vmovdqu64 [INP4 + OFFSET]{k7}, ZW7
mov IA0, [STATE + _des_args_out + (8*PTR_SZ)]
mov IA1, [STATE + _des_args_out + (9*PTR_SZ)]
mov IA2, [STATE + _des_args_out + (10*PTR_SZ)]
mov INP0, [STATE + _des_args_out + (11*PTR_SZ)]
mov INP1, [STATE + _des_args_out + (12*PTR_SZ)]
mov INP2, [STATE + _des_args_out + (13*PTR_SZ)]
mov INP3, [STATE + _des_args_out + (14*PTR_SZ)]
mov INP4, [STATE + _des_args_out + (15*PTR_SZ)]
vmovdqu64 [IA0 + OFFSET]{k7}, ZW8
vmovdqu64 [IA1 + OFFSET]{k7}, ZW9
vmovdqu64 [IA2 + OFFSET]{k7}, ZW10
vmovdqu64 [INP0 + OFFSET]{k7}, ZW11
vmovdqu64 [INP1 + OFFSET]{k7}, ZW12
vmovdqu64 [INP2 + OFFSET]{k7}, ZW13
vmovdqu64 [INP3 + OFFSET]{k7}, ZW14
vmovdqu64 [INP4 + OFFSET]{k7}, ZW15
%%_gen_des_dec_part_end:
;; store IV and update pointers
DES_FINISH ZIV0, ZIV1, ZTMP0, ZTMP1, ZTMP2, ZTMP3, ZTMP4
CLEAR_KEY_SCHEDULE %%DES_DOCSIS, ZW0
;; restore stack pointer and registers
mov r12, [rsp + _gpr_save + 0*8]
mov r13, [rsp + _gpr_save + 1*8]
mov r14, [rsp + _gpr_save + 2*8]
mov r15, [rsp + _gpr_save + 3*8]
mov rsp, [rsp + _rsp_save] ; original SP
%ifdef SAFE_DATA
clear_all_zmms_asm
%endif ;; SAFE_DATA
%endmacro
;;; ========================================================
;;; DATA
section .data
default rel
align 64
mask_values:
dd 0x04000000, 0x04000000, 0x04000000, 0x04000000
dd 0x04000000, 0x04000000, 0x04000000, 0x04000000
dd 0x04000000, 0x04000000, 0x04000000, 0x04000000
dd 0x04000000, 0x04000000, 0x04000000, 0x04000000
dd 0x40240202, 0x40240202, 0x40240202, 0x40240202
dd 0x40240202, 0x40240202, 0x40240202, 0x40240202
dd 0x40240202, 0x40240202, 0x40240202, 0x40240202
dd 0x40240202, 0x40240202, 0x40240202, 0x40240202
dd 0x00001110, 0x00001110, 0x00001110, 0x00001110
dd 0x00001110, 0x00001110, 0x00001110, 0x00001110
dd 0x00001110, 0x00001110, 0x00001110, 0x00001110
dd 0x00001110, 0x00001110, 0x00001110, 0x00001110
dd 0x01088000, 0x01088000, 0x01088000, 0x01088000
dd 0x01088000, 0x01088000, 0x01088000, 0x01088000
dd 0x01088000, 0x01088000, 0x01088000, 0x01088000
dd 0x01088000, 0x01088000, 0x01088000, 0x01088000
dd 0x00000001, 0x00000001, 0x00000001, 0x00000001
dd 0x00000001, 0x00000001, 0x00000001, 0x00000001
dd 0x00000001, 0x00000001, 0x00000001, 0x00000001
dd 0x00000001, 0x00000001, 0x00000001, 0x00000001
dd 0x0081000C, 0x0081000C, 0x0081000C, 0x0081000C
dd 0x0081000C, 0x0081000C, 0x0081000C, 0x0081000C
dd 0x0081000C, 0x0081000C, 0x0081000C, 0x0081000C
dd 0x0081000C, 0x0081000C, 0x0081000C, 0x0081000C
dd 0x00000020, 0x00000020, 0x00000020, 0x00000020
dd 0x00000020, 0x00000020, 0x00000020, 0x00000020
dd 0x00000020, 0x00000020, 0x00000020, 0x00000020
dd 0x00000020, 0x00000020, 0x00000020, 0x00000020
dd 0x00000040, 0x00000040, 0x00000040, 0x00000040
dd 0x00000040, 0x00000040, 0x00000040, 0x00000040
dd 0x00000040, 0x00000040, 0x00000040, 0x00000040
dd 0x00000040, 0x00000040, 0x00000040, 0x00000040
dd 0x00400400, 0x00400400, 0x00400400, 0x00400400
dd 0x00400400, 0x00400400, 0x00400400, 0x00400400
dd 0x00400400, 0x00400400, 0x00400400, 0x00400400
dd 0x00400400, 0x00400400, 0x00400400, 0x00400400
dd 0x00000800, 0x00000800, 0x00000800, 0x00000800
dd 0x00000800, 0x00000800, 0x00000800, 0x00000800
dd 0x00000800, 0x00000800, 0x00000800, 0x00000800
dd 0x00000800, 0x00000800, 0x00000800, 0x00000800
dd 0x00002000, 0x00002000, 0x00002000, 0x00002000
dd 0x00002000, 0x00002000, 0x00002000, 0x00002000
dd 0x00002000, 0x00002000, 0x00002000, 0x00002000
dd 0x00002000, 0x00002000, 0x00002000, 0x00002000
dd 0x00100000, 0x00100000, 0x00100000, 0x00100000
dd 0x00100000, 0x00100000, 0x00100000, 0x00100000
dd 0x00100000, 0x00100000, 0x00100000, 0x00100000
dd 0x00100000, 0x00100000, 0x00100000, 0x00100000
dd 0x00004000, 0x00004000, 0x00004000, 0x00004000
dd 0x00004000, 0x00004000, 0x00004000, 0x00004000
dd 0x00004000, 0x00004000, 0x00004000, 0x00004000
dd 0x00004000, 0x00004000, 0x00004000, 0x00004000
dd 0x00020000, 0x00020000, 0x00020000, 0x00020000
dd 0x00020000, 0x00020000, 0x00020000, 0x00020000
dd 0x00020000, 0x00020000, 0x00020000, 0x00020000
dd 0x00020000, 0x00020000, 0x00020000, 0x00020000
dd 0x02000000, 0x02000000, 0x02000000, 0x02000000
dd 0x02000000, 0x02000000, 0x02000000, 0x02000000
dd 0x02000000, 0x02000000, 0x02000000, 0x02000000
dd 0x02000000, 0x02000000, 0x02000000, 0x02000000
dd 0x08000000, 0x08000000, 0x08000000, 0x08000000
dd 0x08000000, 0x08000000, 0x08000000, 0x08000000
dd 0x08000000, 0x08000000, 0x08000000, 0x08000000
dd 0x08000000, 0x08000000, 0x08000000, 0x08000000
dd 0x00000080, 0x00000080, 0x00000080, 0x00000080
dd 0x00000080, 0x00000080, 0x00000080, 0x00000080
dd 0x00000080, 0x00000080, 0x00000080, 0x00000080
dd 0x00000080, 0x00000080, 0x00000080, 0x00000080
dd 0x20000000, 0x20000000, 0x20000000, 0x20000000
dd 0x20000000, 0x20000000, 0x20000000, 0x20000000
dd 0x20000000, 0x20000000, 0x20000000, 0x20000000
dd 0x20000000, 0x20000000, 0x20000000, 0x20000000
dd 0x90000000, 0x90000000, 0x90000000, 0x90000000
dd 0x90000000, 0x90000000, 0x90000000, 0x90000000
dd 0x90000000, 0x90000000, 0x90000000, 0x90000000
dd 0x90000000, 0x90000000, 0x90000000, 0x90000000
align 64
init_perm_consts:
dd 0x0f0f0f0f, 0x0f0f0f0f, 0x0f0f0f0f, 0x0f0f0f0f
dd 0x0f0f0f0f, 0x0f0f0f0f, 0x0f0f0f0f, 0x0f0f0f0f
dd 0x0f0f0f0f, 0x0f0f0f0f, 0x0f0f0f0f, 0x0f0f0f0f
dd 0x0f0f0f0f, 0x0f0f0f0f, 0x0f0f0f0f, 0x0f0f0f0f
dd 0x0000ffff, 0x0000ffff, 0x0000ffff, 0x0000ffff
dd 0x0000ffff, 0x0000ffff, 0x0000ffff, 0x0000ffff
dd 0x0000ffff, 0x0000ffff, 0x0000ffff, 0x0000ffff
dd 0x0000ffff, 0x0000ffff, 0x0000ffff, 0x0000ffff
dd 0x33333333, 0x33333333, 0x33333333, 0x33333333
dd 0x33333333, 0x33333333, 0x33333333, 0x33333333
dd 0x33333333, 0x33333333, 0x33333333, 0x33333333
dd 0x33333333, 0x33333333, 0x33333333, 0x33333333
dd 0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff
dd 0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff
dd 0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff
dd 0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff
dd 0x55555555, 0x55555555, 0x55555555, 0x55555555
dd 0x55555555, 0x55555555, 0x55555555, 0x55555555
dd 0x55555555, 0x55555555, 0x55555555, 0x55555555
dd 0x55555555, 0x55555555, 0x55555555, 0x55555555
;;; S-Box table
align 64
S_box_flipped:
;; SBOX0
dw 0x07, 0x02, 0x0c, 0x0f, 0x04, 0x0b, 0x0a, 0x0c
dw 0x0b, 0x07, 0x06, 0x09, 0x0d, 0x04, 0x00, 0x0a
dw 0x02, 0x08, 0x05, 0x03, 0x0f, 0x06, 0x09, 0x05
dw 0x08, 0x01, 0x03, 0x0e, 0x01, 0x0d, 0x0e, 0x00
dw 0x00, 0x0f, 0x05, 0x0a, 0x07, 0x02, 0x09, 0x05
dw 0x0e, 0x01, 0x03, 0x0c, 0x0b, 0x08, 0x0c, 0x06
dw 0x0f, 0x03, 0x06, 0x0d, 0x04, 0x09, 0x0a, 0x00
dw 0x02, 0x04, 0x0d, 0x07, 0x08, 0x0e, 0x01, 0x0b
;; SBOX1
dw 0x0f, 0x00, 0x09, 0x0a, 0x06, 0x05, 0x03, 0x09
dw 0x01, 0x0e, 0x04, 0x03, 0x0c, 0x0b, 0x0a, 0x04
dw 0x08, 0x07, 0x0e, 0x01, 0x0d, 0x02, 0x00, 0x0c
dw 0x07, 0x0d, 0x0b, 0x06, 0x02, 0x08, 0x05, 0x0f
dw 0x0c, 0x0b, 0x03, 0x0d, 0x0f, 0x0c, 0x06, 0x00
dw 0x02, 0x05, 0x08, 0x0e, 0x01, 0x02, 0x0d, 0x07
dw 0x0b, 0x01, 0x00, 0x06, 0x04, 0x0f, 0x09, 0x0a
dw 0x0e, 0x08, 0x05, 0x03, 0x07, 0x04, 0x0a, 0x09
;; SBOX2
dw 0x05, 0x0b, 0x08, 0x0d, 0x06, 0x01, 0x0d, 0x0a
dw 0x09, 0x02, 0x03, 0x04, 0x0f, 0x0c, 0x04, 0x07
dw 0x00, 0x06, 0x0b, 0x08, 0x0c, 0x0f, 0x02, 0x05
dw 0x07, 0x09, 0x0e, 0x03, 0x0a, 0x00, 0x01, 0x0e
dw 0x0b, 0x08, 0x04, 0x02, 0x0c, 0x06, 0x03, 0x0d
dw 0x00, 0x0b, 0x0a, 0x07, 0x06, 0x01, 0x0f, 0x04
dw 0x0e, 0x05, 0x01, 0x0f, 0x02, 0x09, 0x0d, 0x0a
dw 0x09, 0x00, 0x07, 0x0c, 0x05, 0x0e, 0x08, 0x03
;; SBOX3
dw 0x0e, 0x05, 0x08, 0x0f, 0x00, 0x03, 0x0d, 0x0a
dw 0x07, 0x09, 0x01, 0x0c, 0x09, 0x0e, 0x02, 0x01
dw 0x0b, 0x06, 0x04, 0x08, 0x06, 0x0d, 0x03, 0x04
dw 0x0c, 0x00, 0x0a, 0x07, 0x05, 0x0b, 0x0f, 0x02
dw 0x0b, 0x0c, 0x02, 0x09, 0x06, 0x05, 0x08, 0x03
dw 0x0d, 0x00, 0x04, 0x0a, 0x00, 0x0b, 0x07, 0x04
dw 0x01, 0x0f, 0x0e, 0x02, 0x0f, 0x08, 0x05, 0x0e
dw 0x0a, 0x06, 0x03, 0x0d, 0x0c, 0x01, 0x09, 0x07
;; SBOX4
dw 0x04, 0x02, 0x01, 0x0f, 0x0e, 0x05, 0x0b, 0x06
dw 0x02, 0x08, 0x0c, 0x03, 0x0d, 0x0e, 0x07, 0x00
dw 0x03, 0x04, 0x0a, 0x09, 0x05, 0x0b, 0x00, 0x0c
dw 0x08, 0x0d, 0x0f, 0x0a, 0x06, 0x01, 0x09, 0x07
dw 0x07, 0x0d, 0x0a, 0x06, 0x02, 0x08, 0x0c, 0x05
dw 0x04, 0x03, 0x0f, 0x00, 0x0b, 0x04, 0x01, 0x0a
dw 0x0d, 0x01, 0x00, 0x0f, 0x0e, 0x07, 0x09, 0x02
dw 0x03, 0x0e, 0x05, 0x09, 0x08, 0x0b, 0x06, 0x0c
;; SBOX5
dw 0x03, 0x09, 0x00, 0x0e, 0x09, 0x04, 0x07, 0x08
dw 0x05, 0x0f, 0x0c, 0x02, 0x06, 0x03, 0x0a, 0x0d
dw 0x08, 0x07, 0x0b, 0x00, 0x04, 0x01, 0x0e, 0x0b
dw 0x0f, 0x0a, 0x02, 0x05, 0x01, 0x0c, 0x0d, 0x06
dw 0x05, 0x02, 0x06, 0x0d, 0x0e, 0x09, 0x00, 0x06
dw 0x02, 0x04, 0x0b, 0x08, 0x09, 0x0f, 0x0c, 0x01
dw 0x0f, 0x0c, 0x08, 0x07, 0x03, 0x0a, 0x0d, 0x00
dw 0x04, 0x03, 0x07, 0x0e, 0x0a, 0x05, 0x01, 0x0b
;; SBOX6
dw 0x02, 0x08, 0x0c, 0x05, 0x0f, 0x03, 0x0a, 0x00
dw 0x04, 0x0d, 0x09, 0x06, 0x01, 0x0e, 0x06, 0x09
dw 0x0d, 0x02, 0x03, 0x0f, 0x00, 0x0c, 0x05, 0x0a
dw 0x07, 0x0b, 0x0e, 0x01, 0x0b, 0x07, 0x08, 0x04
dw 0x0b, 0x06, 0x07, 0x09, 0x02, 0x08, 0x04, 0x07
dw 0x0d, 0x0b, 0x0a, 0x00, 0x08, 0x05, 0x01, 0x0c
dw 0x00, 0x0d, 0x0c, 0x0a, 0x09, 0x02, 0x0f, 0x04
dw 0x0e, 0x01, 0x03, 0x0f, 0x05, 0x0e, 0x06, 0x03
;; SBOX7
dw 0x0b, 0x0e, 0x05, 0x00, 0x06, 0x09, 0x0a, 0x0f
dw 0x01, 0x02, 0x0c, 0x05, 0x0d, 0x07, 0x03, 0x0a
dw 0x04, 0x0d, 0x09, 0x06, 0x0f, 0x03, 0x00, 0x0c
dw 0x02, 0x08, 0x07, 0x0b, 0x08, 0x04, 0x0e, 0x01
dw 0x08, 0x04, 0x03, 0x0f, 0x05, 0x02, 0x00, 0x0c
dw 0x0b, 0x07, 0x06, 0x09, 0x0e, 0x01, 0x09, 0x06
dw 0x0f, 0x08, 0x0a, 0x03, 0x0c, 0x05, 0x07, 0x0a
dw 0x01, 0x0e, 0x0d, 0x00, 0x02, 0x0b, 0x04, 0x0d
;;; Used in DOCSIS DES partial block scheduling 16 x 32bit of value 1
align 64
vec_ones_32b:
dd 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
align 64
and_eu:
dd 0x3f003f00, 0x3f003f00, 0x3f003f00, 0x3f003f00
dd 0x3f003f00, 0x3f003f00, 0x3f003f00, 0x3f003f00
dd 0x3f003f00, 0x3f003f00, 0x3f003f00, 0x3f003f00
dd 0x3f003f00, 0x3f003f00, 0x3f003f00, 0x3f003f00
align 64
and_ed:
dd 0x003f003f, 0x003f003f, 0x003f003f, 0x003f003f
dd 0x003f003f, 0x003f003f, 0x003f003f, 0x003f003f
dd 0x003f003f, 0x003f003f, 0x003f003f, 0x003f003f
dd 0x003f003f, 0x003f003f, 0x003f003f, 0x003f003f
align 64
idx_e:
dq 0x0d0c090805040100, 0x0f0e0b0a07060302
dq 0x1d1c191815141110, 0x1f1e1b1a17161312
dq 0x2d2c292825242120, 0x2f2e2b2a27262322
dq 0x3d3c393835343130, 0x3f3e3b3a37363332
align 64
reg_values16bit_7:
dq 0x001f001f001f001f, 0x001f001f001f001f
dq 0x001f001f001f001f, 0x001f001f001f001f
dq 0x001f001f001f001f, 0x001f001f001f001f
dq 0x001f001f001f001f, 0x001f001f001f001f
align 64
shuffle_reg:
dq 0x0705060403010200, 0x0f0d0e0c0b090a08
dq 0x1715161413111210, 0x1f1d1e1c1b191a18
dq 0x2725262423212220, 0x2f2d2e2c2b292a28
dq 0x3735363433313230, 0x3f3d3e3c3b393a38
;;; ========================================================
;;; CODE
section .text
;;; arg 1 : pointer to DES OOO structure
;;; arg 2 : size in bytes
align 64
MKGLOBAL(des_x16_cbc_enc_avx512,function,internal)
des_x16_cbc_enc_avx512:
endbranch64
GENERIC_DES_ENC DES
ret
;;; arg 1 : pointer to DES OOO structure
;;; arg 2 : size in bytes
align 64
MKGLOBAL(des_x16_cbc_dec_avx512,function,internal)
des_x16_cbc_dec_avx512:
endbranch64
GENERIC_DES_DEC DES
ret
;;; arg 1 : pointer to DES OOO structure
;;; arg 2 : size in bytes
align 64
MKGLOBAL(des3_x16_cbc_enc_avx512,function,internal)
des3_x16_cbc_enc_avx512:
endbranch64
GENERIC_DES_ENC 3DES
ret
;;; arg 1 : pointer to DES OOO structure
;;; arg 2 : size in bytes
align 64
MKGLOBAL(des3_x16_cbc_dec_avx512,function,internal)
des3_x16_cbc_dec_avx512:
endbranch64
GENERIC_DES_DEC 3DES
ret
;;; arg 1 : pointer to DES OOO structure
;;; arg 2 : size in bytes
align 64
MKGLOBAL(docsis_des_x16_enc_avx512,function,internal)
docsis_des_x16_enc_avx512:
endbranch64
GENERIC_DES_ENC DOCSIS
ret
;;; arg 1 : pointer to DES OOO structure
;;; arg 2 : size in bytes
align 64
MKGLOBAL(docsis_des_x16_dec_avx512,function,internal)
docsis_des_x16_dec_avx512:
endbranch64
GENERIC_DES_DEC DOCSIS
ret
%ifdef LINUX
section .note.GNU-stack noalloc noexec nowrite progbits
%endif
| 39.10803 | 314 | 0.523427 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.