Move #10
04 сентября 1997

Algorithms - Subroutines associated with the output on screen: the transition to the previous character on-screen at the transition to the next screen line, go to the previous screen line, how to determine the address attribute for a given character with the coordinates XY, transition to the next row attribute. Rapid procedure for multiplication.

<b>Algorithms</b> - Subroutines associated with the output on screen: the transition to the previous character on-screen at the transition to the next screen line, go to the previous screen line, how to determine the address attribute for a given character with the coordinates XY, transition to the next row attribute. Rapid procedure for multiplication.
Algorithms and ideas. Rapid procedure for multiplication.


Ars; KVA from E-Mage / Grodno /


               (OKONCHANIE. HOME IN MOVE # 09)

(C) Ars


    In this section we continue to publish useful procedure.
At this time it will focus on the various routines associated 
with output on screen. If you have any comments,

let us know. And also you can ask to discuss your
version of the algorithms on the pages of MOVE.


    Part of the procedures described below, wrote Rui Ribeiro - 
author WSpecem - Spectrum emulator for Windows.


7) Go to the previous character on-screen address.

Input: HL = screen address
Output: HL = previous char screen address

PrevChr RR H

         RR H

         RR H

         DEC HL

         RL H

         RL H

         RL H

         RET

Two of the following procedure, you probably know by heart, so
often they are used in programs.

8) Go to the next screen line.

Input: HL = screen address
Output: HL = scan inferior address

NextLine INC H

         LD A, H

         AND 7

         RET NZ

         LD A, L

         ADD A, 32

         LD L, A

         RET C

         LD A, H

         SUB 8

         LD H, A

         RET

9) Go to the previous screen line.

Input: HL = screen address
Output: HL = superior scan address

PrevLine DEC H

         LD A, H

         AND 7

         CP 7

         RET NZ

         LD A, L

         SUB 32

         LD L, A

         RET C

         LD A, H

         ADD A, 8

         LD H, A

         RET

10) the following procedure to scan the screen as
This makes ray razverki.
Input: screen address
Output: next visual scan address

NextVAdd INC L

         LD A, L

         AND # 1F

         RET NZ

         INC H

         LD A, H

         AND 7

         LD A, L

         JR NZ, NVALab

         AND # E0

         RET Z

         LD A, H

         SUB 8

         LD H, A

         RET
NVALab SUB 32

         LD L, A

         RET


11) The same operation, but the motion in the opposite 
direction - from bottom up.


Input: HL = screen address
Output: HL = previous visual scan address
PrevVAdd DEC L

         LD A, L

         AND # 1F

         CP # 1F

         RET NZ

         DEC H

         LD A, H

         AND 7

         CP 7

         LD A, L

         JR NZ, PVALab

         AND # E0

         CP # E0

         RET Z

         LD A, H

         ADD A, 8

         LD H, A

         RET
PVALab ADD A, 32

         LD L, A

         RET



And finally, the procedures related to addressing attributes.
Atribute file: Length = 768 bytes. Address: # 5800 .. # 5AFF
(22528 .. 23295)

                                                Colors are 
defined Address attribute is calculated as follows: the 
following bits: 

 adr (C, L) = 22528 + L * 32 + C 7 6543210

                                              -------------- 
Where: L - line (0 .. 23) fbpi 

     C - column (0 .. 31) lran

                                              a i p k
Schematically, the address attribute looks like this: sge

                                              h h r

        0101 10LL LLLC CCCC t
12) How to determine the address attribute for a given 
character with coordinates XY.


Input: BC = YX
Output: HL = attribute address

AdrAttr LD A, B

         RRCA

         RRCA

         RRCA

         LD H, A

         AND # E0

         OR C

         LD L, A

         LD A, H

         AND 3

         OR # 58

         LD H, A

         RET


13) Go to the next row attribute.

Input: HL = attribute address
Output: HL = upper attribute address

DownAttr LD A, L LD DE, 32

         ADD A, 32, or ADD HL, DE

         LD L, A

         RET NC

         INC H

         RET

14) Go to the previous row attributes.

Input: HL = attribute address
Output: HL = lower attribute address

UpAttr LD A, L LD DE, 32

         SUB 32 or AND A

         LD L, A SBC HL, DE

         RET NC

         DEC H

         RET



             Information obtained from Web-page:

          http://www.atlantic.net/ ~ adansby / plot.html



          HOW FAST multiplying two numbers.
           (The concept of multiplication procedures.)

(C) KVA from E-Mage / Grodno /


    Currently, many of you know how quickly multiply two
numbers, but not everyone knows how to work those procedures 
that are they enjoy. If, however, to understand on what basis 
are written all these algorithms, then for each specific case, 
we can write procedure that will be twice as faster than the 
procedure for general case.



    Let us consider how we multiply two numbers in decimal
radix:

    176 * 25 = 100 * (1 * 25) +10 * (7 * 25) +1 * (6 * 25)


       Ie, we decompose one of the numbers into categories 
(units, hundreds, tens, etc.). But you can also do the same and

binary system:

    101101 * 1011 = 100000 * (1 * 1011) +10000 * (0 * 1011 )+...


    Now, note that multiplication is reduced to two operations:

    1. The multiplication of two (the operation in Assembler'e 
- ADD r, r).     2. The addition of the second number.



    Let's try to expand this principle, the previous number:

    101101 * 1011 = 1 * 1011 +10 * (0 * 1011 +10 * (1 * 1011 
+10 * (1 * 1011 +             10 * (0 * 1011 +10 * (1 * 1011 
))))) 

 Consider the process of multiplication of bytes * bytes 
written to the Echo: 

    ADD HL, HL H - number 1
    JR NC, M1 Repeat 8 times. E - Number 2 Log
    ADD HL, DE D and L = 0

    M1: HL = Answer Output


   Team ADD HL, HL performs two functions at once:
    1. Multiplies the contents of the register L for two.
    2. Delivers the last bit of register H to flag C.
       (The first time the team gets 7-bit input numbers,
        in the second - 6 - bit input numbers, etc.)


   Team JR NC, M1 performs the function of multiplication 
(since we use the binary system, we have only two digits to

which we can multiply - 0 and 1)


   Team ADD HL, DE is used for adding to the register L
Register E.


   Teams JR NC, M1 and ADD HL, DE together perform the function
additions to the register of the register L E, multiplied by 
the last bit register H.



     This procedure uses the principle of "the end", ie
first processed bit 7, then 6, etc. And if shorter,
associative law is applied mathematics that
studied in school. You can first take E, multiplied by the 0-th
Bit H. Then add the number 10 * E * [1-th bit of H] (10 - binary
system), then the number 100 * E * [2-th bit of H], then 1000 * 
E * [the third bit H] ... we add 10000000 * E * [7-bit H]. And 
you can do differently. First, we take E * [7-bit H], 
multiplied by 10 (2) add the E * [6-th bit of H], multiply by 
10, add the E * [5-th bit H] ... multiply by 10, add the E * 
[0-th bit of H]. At the end of this operations, we obtain the 
same effect as in the first case, but with the help of Spectrum 
assembler'a second easier to do! 


   Finally, I cite a couple of procedures that I wrote for the 
case B * word = word (the word is 2 bytes), word * word = word

word * word = DWORD (4 bytes), double word * double
word = double word.


   I want to immediately warn all that the texts here
using special assembler directives ALASM v3.8 - DUP
and EDUP (DUP x-repeat x times the lines following this
command and ending with the string with a team EDUP).

; Bytes * word = word
; Log - A number 1, DE-number 2.
; Output - HL-result.

    LD HL, 0
    DUP 8

        ADD HL, HL
      ADD A, A
     JR NC, $ +3
     ADD HL, DE
    EDUP

And the word * word = word
; Log - BC-number 1, DE-number 2.
; Output - HL-result.


        LD HL, 0
    LD A, B
    DUP 8

       ADD HL, HL
     ADD A, A
     JR NC, $ +3
     ADD HL, DE
    EDUP
    LD A, C
    DUP 8
     ADD HL, HL
     ADD A, A
     JR NC, $ +3
     ADD HL, DE
    EDUP

And the word * word = double word
; Log - BC-number 1, DE-number 2
; Output - HL-youngest part of the word, HL'-leading part of 
the word. 


        LD HL, 0
    EXX
    LD HL, 0
    LD DE, 0
    EXX
    LD A, B
    DUP 8
     ADD HL, HL
     EXX
     ADC HL, HL
     EXX
     ADD A, A
     JR NC, $ +6
     ADD HL, DE
     EXX
     ADC HL, DE
    EDUP
    LD A, C
    DUP 8
     ADD HL, HL
     EXX
     ADC HL, HL
     EXX
     ADD A, A
     JR NC, $ +6
     ADD HL, DE
     EXX
     ADC HL, DE
     EXX
    EDUP

; DWORD * dovoynoe word = double word
; Log - DE 'DE-number 1, BC' BC-number 2
; Output - HL 'HL-result


        LD HL, 0

        EXX

        LD HL, 0

        EXX
    DUP 1916
      ADD HL, HL
     EXX
     ADC HL, HL
     EX DE, HL
     ADD HL, HL
     EX DE, HL
     EXX
     JR NC, $ +6
     ADD HL, BC
     EXX
     ADC HL, BC
     EXX
    EDUP
    DUP 1916
     ADD HL, HL
     EXX
     ADC HL, HL
     EXX
     EX DE, HL
     ADD HL, HL
     EX DE, HL
     JR NC, $ +6
     ADD HL, BC
     EXX
     ADC HL, BC
    EDUP



    P.S. If anyone interested in this article (and in general,
this issue), you can write to the editor or contact MOVE
me by phone (0152) 318-721 (Victor), or leave a message
on E-Mage BBS (0152) 441-176. Wait for the following numbers 
MOVE, where I will describe the procedure division.






Other articles:

Echo - Review of letters from readers of the newspaper: Beard, Space5, DarkMax.

System - The Organization-mail C-DOS v1.32.

Algorithms - Subroutines associated with the output on screen: the transition to the previous character on-screen at the transition to the next screen line, go to the previous screen line, how to determine the address attribute for a given character with the coordinates XY, transition to the next row attribute. Rapid procedure for multiplication.

Iron - Galvonicheskaya junction with the telephone line in the C-DOS modem.

Mosaic - Spectrum on the Internet.

BRAVO to rest - Short Stories: The bus, Ode to a mosquito.

Advertising - Advertising and announcements.


Темы: Игры, Программное обеспечение, Пресса, Аппаратное обеспечение, Сеть, Демосцена, Люди, Программирование

Similar articles:
Poll - Questionnaire for the readers.
Software - Description of programs: Visual Turbo Copier.
Humor from Fido - Diary of a user Vasey.
Advertising - EX Russia

В этот день...   21 November