Studies - Short procedure indicating the amplitude channel music. coprocessor. Way to subtract a constant from a register pair HL.

ZX Review #7-8-9-10
(C) Andryashkin A., Ulyanovsk
reg., r.p.Staraya Maina


   I fully agree with the opinion
that before you send the log their procedures, you should first 
optimize them in terms of or speed.


   Here, for example, the procedure
Alexander Soloviev (ZX REVIEW
N5/1995 str.51) to indicate
amplitude channels of music
coprocessor, which he occupies 70 bytes. If it hold 
unpretentious permutation (Remove unneeded routines) and

replace operations on shorter, you can shorten it to
10 - 15 bytes, but in my opinion, it is possible to go further.
140.
ANAL LD HL, # 58E2

          LD A, 3
AN1 PUSH AF

          LD HL, # FFFD

          ADD A, 7

          OUT (C), A

          IN A, (C)

          PUSH HL

          LD C, 4
AN2 LD B, 4
AN3 DEC H

          DEC H

          OR A

          LD (HL), A

          JR Z, AN4

          LD (HL), 126

          DEC A
AN4 DJNZ AN3

          LD DE, # 07E0

          ADD HL, DE

          DEC C

          JR NZ, AN2

          POP HL

          POP AF

          DEC L

          DEC A

          JR NZ, AN1

          RET
2

   This procedure will work
in any third of the screen (the address of the indicator 3 
channel recorded in the HL [Label ANAL]).



   I take this opportunity to recall the same unpretentious
design, if you want to take away from the register pair HL any 
number (constant), then usually uses the following

Design:


          LD DE, NN

          AND A; because unknown state carry flag

          SBC HL, DE


   But this construction can be shortened to 2 bytes (not to 
mention speed of execution), if instead of subtracting using 
addition and constant overeat in the extra code: 


          LD DE ,0-NN

          ADD HL, DE

Since the digital technology holds the subtraction operation.


           *