Adventurer #07
31 января 1998

Exchange of experience - Quick procedure line.

<b>Exchange of experience</b> - Quick procedure line.
     (C) Yevgeny Veselov (VEKA / CPU)

     (C) Music ALOS jnr. / Spark



        Rapid procedure line.


     I present to you two programs draw a line, running faster 
than located in ROM. 

     The first of them - to set point,
invoke an external routine that you can use it to display any 
objects. 

     The coordinates of the end of the line are given in
registers HL and DE (E and L - x, D and H - y).

LINE LD A, H; calculation of displacements

        SUB D

        JR NC, LINE1

        EX DE, HL; line is drawn from the bottom up

        NEG; change in sign of bias
LINE1 LD H, A; H = dy = y2-y1

        LD A, L

        SUB E

        LD BC, # 141C; INC D [# 14], INC E [# 1C]

        JR NC, LINE2

        INC C; if x1 <x2 then DEC E [# 1D]

        NEG; change in sign of bias
LINE2 CP H

        LD L, A; L = dx = x2-x1

        JR C, LINE3; if dx  dy

        LD H, A

        LD A, B; replacement INC D <-> INC / DEC E

        LD B, C

        LD C, A
LINE3 LD A, B; code modification

        LD (LINE5), A

        LD A, C

        LD (LINE6), A

        LD B, H; number of points in line

        LD A, H

        INC L

        INC B
LINE4 CALL PLOT; installation point
LINE5 NOP
; Change coordinates with a large displacement
; Direction depends on the sign of the bias

        SUB L

        JR NC, LINE7
LINE6 NOP
; Change coordinates with a smaller displacement

        ADD A, H
LINE7 DJNZ LINE4

        RET


     IN PLOT must be maintained following
Registers: HL, DE, B, A. Coordinates are
in register DE (E = x, D = y).


     The next program is similar to the previous one, but works 
directly with address of the display file. Also, instead of

samomodifitsirueschegosya code used
parts of the program for each of the
four directions. Due to this significantly increases the speed, 
and more length ;-).


     And where are the four directions? Have a look at the line 
after the first JR. See EX DE, HL? Now look at the picture. If 
D (y1)> H (y2), then the line should be drawn from top to 
bottom (lines 5 .. 8 on the figure), but it runs EX DE, HL, and 
all line drawn from the bottom up

(Both lines 1 .. 4).

     All this applies to the first procedure line. If you want 
the line has always been in a given direction, then you

will have to redo the initial block of the program (calculation 
of bias) or write to Editor, and will be published an amended 
version. 

     Another important point: in the second
procedure, the display address is calculated
once before the withdrawal line (see the four locations CALL 
GET_ADR). Coordinates are specified in register DE, and the 
results of calculation entered in the register HL (e) and C 
(mask) and you can use all the registers.

Most importantly, the origin for
This should be at the bottom of the screen (note the second and 
third lines in the procedure GET_ADR). 

LINE LD A, H

        SUB D

        JR NC, LINE1

        EX DE, HL

        NEG
LINE1 LD H, A

        LD A, L

        SUB E

        JR NC, LINER


        NEG

        CP H

        LD L, A

        JR C, LINELU


        PUSH HL

        CALL GET_ADR

        POP DE

        LD B, E

        LD A, E

        INC D

        INC B

        EX AF, AF '

LINELD1 LD A, (HL)

        OR C

        LD (HL), A

        RLC C

        JP NC, LINELD2

        DEC L
LINELD2 EX AF, AF '

        SUB D

        JR NC, LINELD4

        ADD A, E

        EX AF, AF '

        LD A, H

        DEC H

        AND 7

        JP NZ, LINELD3

        LD A, L

        SUB # 20

        LD L, A

        JR C, LINELD3

        LD A, H

        ADD A, 8

        LD H, A
LINELD3 DJNZ LINELD1

        RET
LINELD4 EX AF, AF '

        DJNZ LINELD1

        RET

LINELU PUSH HL

        CALL GET_ADR

        POP DE

        LD B, D

        LD A, D

        INC E

        INC B

        EX AF, AF '

LINELU1 LD A, (HL)

        OR C

        LD (HL), A

        LD A, H

        DEC H

        AND 7

        JP NZ, LINELU2

        LD A, L

        SUB # 20

        LD L, A

        JR C, LINELU2

        LD A, H

        ADD A, 8

        LD H, A
LINELU2 EX AF, AF '

        SUB E

        JR NC, LINELU3

        ADD A, D

        RLC C

        JP NC, LINELU3

        DEC L
LINELU3 EX AF, AF '

        DJNZ LINELU1

        RET

LINER CP H

        LD L, A

        JR C, LINERU


        PUSH HL

        CALL GET_ADR

        POP DE

        LD B, E

        LD A, E

        INC D

        INC B

        EX AF, AF '

LINERD1 LD A, (HL)

        OR C

        LD (HL), A

        RRC C

        JP NC, LINERD2

        INC L
LINERD2 EX AF, AF '

        SUB D

        JR NC, LINERD4

        ADD A, E

        EX AF, AF '

        LD A, H

        DEC H

        AND 7

        JP NZ, LINERD3

        LD A, L

        SUB # 20

        LD L, A

        JR C, LINERD3

        LD A, H

        ADD A, 8

        LD H, A
LINERD3 DJNZ LINERD1

        RET
LINERD4 EX AF, AF '

        DJNZ LINERD1

        RET

LINERU PUSH HL

        CALL GET_ADR

        POP DE

        LD B, D

        LD A, D

        INC E

        INC B

        EX AF, AF '

LINERU1 LD A, (HL)

        OR C

        LD (HL), A

        LD A, H

        DEC H

        AND 7

        JP NZ, LINERU2

        LD A, L

        SUB # 20

        LD L, A

        JR C, LINERU2

        LD A, H

        ADD A, 8

        LD H, A
LINERU2 EX AF, AF '

        SUB E

        JR NC, LINERU3

        ADD A, D

        RRC C

        JP NC, LINERU3

        INC L
LINERU3 EX AF, AF '

        DJNZ LINERU1

        RET


     Here are some routines of calculation
address in the screen and set the point used when drawing lines 
(set point is needed only for the first procedure).



PLOT PUSH HL; installation point

        PUSH DE

        EX AF, AF '

        CALL GET_ADR

        OR (HL)

        LD (HL), A

        EX AF, AF '

        POP DE

        POP HL

        RET

GET_ADR LD A, # BF; calculation of addresses in the screen

        SUB D

        LD D, A

        SRL A

        SCF

        RRA

        SRL A

        XOR D

        AND # F8

        XOR D

        LD H, A

        LD A, E

        RLCA

        RLCA

        RLCA

        XOR D

        AND # C7

        XOR D

        RLCA

        RLCA

        LD L, A

        LD A, E

        AND 7

        INC A

        LD C, B; preserving B

        LD B, A

        LD A, 1
GETADR1 RRCA

        DJNZ GETADR1

        LD B, C; restore B

        LD C, A; mask c

        RET


     These routines are only
for example. In practice, the better to insert
address calculation and installation point directly into the 
line and used to calculate the table (see ZX-Format N7, "Coding 
for Beginners"). 


     In the Appendix you will find the source
these procedures (LINE1 and LINE2).





Other articles:

From the authors - Features a new shell.

From the authors - Opening remarks.

From the authors - cyberpunk - who is it?

From the authors - What is cyberpunk?

Authors - the list of sponsors of the magazine and the editorial office.

Presentation - All programs: Inter Mode Player v1.1

Presentation - All programs: SPRITES GENERATOR v. 4. 7

Presentation - All programs: Real COMMANDER v 1. 4

Presentation - All programs: Labyrinth of Death

Presentation - All programs: Rubik's Cube (DEMO)

Presentation - All programs: DONKEY

Presentation - All programs: Tic-Tac-Toe

Presentation - All programs: SQUARDS

Presentation - All programs: ISLAND OF DARKNESS

Presentation - All programs: SpectrumGuide v1. 0

Presentation - All programs: TOP COPY

Presentation - All programs: What can FORTH?

Presentation - All programs: LAST COURIER

Presentation - All programs: Oragon

Novella - COMPUTER Novella.

Letters - letters from readers.

Interface - computer interfaces.

Interface - On the buttons, mice and more.

Interface - A little bit about DOMEN OS.

Softmaking - the territory of law. On the problems of piracy on the Speccy.

Spectrum - Brad on SPECCY & PC. Reflections on the future.

Rybinsk news - project WAR ROBOTS.

System - Overview of system software.

System - Overview of System Software: archivers ZXZIP & ZXUNZIP v1.2

System - Overview of System Software: copyist Turbo Copier v 2. 0

System - Overview of System Software: copyist REAL COPY

System - Overview of System Software: copyist SOFT COPY v 1.3

System - Overview of System Software: copyist McDonald v 2. 7

System - Overview of system programming: ZX Tools DeLuxe v 2.0

System - Overview of system software: assembler XAS v 7.432

System - Overview of system software: assembler TASM v 4.12

System - Overview of system software: audio editor SOUND FX v 1. 0

System - Overview of System Software: SUPER CATALOG v 1. 22

System - Overview of System Software: Text-Designer v 2.0

System - Overview of system software: Smart boot

System - Overview of System Software: Total Commander v 1.4

System - Overview of System Software: ART Studio v 2. 1

System - Overview of System Software: Advancer Text Editor v 1.24

System - Overview of system software: audio editor, Digital Wave v 0. 2

System - Overview of system software: assembler XAS v 9.06 +

System - Overview of System Software: copyist Faster DiskCopyer v 2.0

System - Overview of System Software: copyist RCOPY v 4.1

System - Overview of System Software: copyist Master Fast Track Copyer v 2. 2

System - Overview of System Software: Sample Compiler v 0.3

System - Overview of System Software: TEST RAMDOCTOR v 2. 0

System - Overview of system software: assembler ZXASM v 3.10 demo

System - TEST CHAMBER: the operating system for Spectrum PINK FLOYD v3 (2.31)

System - TEST CHAMBER: CONSUL COMMANDER v2.7

Guests - The presentation of the group JURASSIC SOFT from Ulyanovsk.

Guests - On the origin of ACCEPT CORP from the city of Armavir.

Promotion - The description and recommendations for the passage of the game MAGICIAN LAND.

Promotion - Tips for lazy people to survive in the game MURK 3320.

Toy Review - An overview of new gaming software: LAST adventure.

Promotion - The description and recommendations for the passage of the game of medieval history.

about the virus - Virus 6.05b & Virus 7.06b.

Exchange of experience - Error Handling TR DOS.

Exchange of experience - DIGITAL MUSEC + SCORPION - wiring diagrams AY.

Exchange of experience - QUILL editor adventyur - advantages and disadvantages.

Exchange of experience - Quick procedure line.

Ottyag - entry.

Ottyag - What is a complete freak.

Ottyag - Instructions for getting acquainted with a girl for dummies ...

Ottyag - 20 things that girl can stuff yourself to hell.

Ottyag - test "How well do you know Spectrum scene?

Ottyag - Test "How much do you love beer."

Ottyag - Beer revue.

Ottyag - Winnie - the Pooh and all - all - all.

Ottyag - Eastern Ballad of the Valiant cops.

Novella - Novella MARATHON ZOMBIES "(inspired by the game" ZOMBI ").

Toy Review - An overview of new gaming software: TECHNODROM

Toy Review - An overview of new gaming software: PRO GOLF SINULATOR

Toy Review - An overview of new gaming software: The Last Adventure

Toy Review - An overview of new gaming software: ELOPEMENT

Toy Review - An overview of new game programs: CATCH 23

Toy Review - An overview of new gaming software: ARENA

Toy Review - An overview of new gaming software: VINDICATORS

Toy Review - An overview of new gaming software: SWORD OF THE SAMURAI

Toy Review - An overview of new gaming software: Q10 TANK BUSTER

Toy Review - An overview of new gaming software: NINJA SPIRIT

Toy Review - An overview of new gaming software: STALKER

Contest - Results of the contest artists.

Advertising - Advertising and announcements.


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

Similar articles:
Coding - the implementation of Phong Bump Mapping on the Speccy.
Consul'99? - enough to fuck your eyes on the monitors! It's time pizdohat the sea!
Poems - Corrosion of snow

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