Code - studies: calling procedures using a list of addresses.

Info Guide #12
Sketches
 1.
 (from Screw)
 Binding for calling threaded code (calling
procedures for a list of addresses) without using─
Stack information:
LD E,(HL)
INC L
LD D,(HL)
INC L
 EX DE,HL
 JP (HL)
 It is assumed that each callable
the procedure will doEX DE,HL when it is convenient for her─
but.
   If you can use a stack, then that's enough─
exactly RET or (if the procedures themselves re─
put stack)LD SP,HL:INC L,L:RET or LD
SP,HL:INC H:RET with "vertical" placement
laying out the threaded code. IfHL is busy, then
possibleLD IX,next:JP patched_addr:next.

                    2.
 (from JtN)
How to invert in BASIC1 bit to
8-bit variable:
POKE 16384,s
 PLOT OVER 1;q,175
 LET s=PEEK 16384
 And to take the high or low byte
double-byte numbern, just do
RANDOMIZE n and readPEEK 23670 (junior) 
and23671 (senior). And through RANDOMIZE N*8:
... PEEK 23670/8 can be discarded─
removal of the three most significant bits - useful when sampling
all keyboards.

                    3.
 (from LVD)
 If your variables are saved in co─
de, and their initial values are not important, then:
LD BC,#0101
 LD DE,#1111
 LD HL,#2121
packed better than
LD BC,0
 LD DE,0
LD HL,0
This can be extended toLD r,n,
SUB n, CP n, and in what other form are there in─
line variables.

                    4.
 (from Fyrex)
 How to make a loop with a 16-bit counter?
Usually they do this:
DEC BC
 LD A,B
OR C
 JP NZ,loop
(6 bytes, 24 clock cycles)
But the code from old games comes out at255:
DEC BC
INC B
 DJNZ loop
(4 bytes, 23 clock cycles)
 If there is an extra register pair:
ADD HL,DE;-1
JP C,loop
(4 bytes, 21 clock cycles)
 If speed unevenness is not important
(but the initial contents of the counter must be
prepare):
 DJNZ loop
DEC C
 JR NZ,loop
(5 bytes, on average 13 clock cycles with kopecks)
 If you need to increment at the same time
(or decrement)HL:
CPI(or CPD)
JP PE,loop
(5 bytes, 26 clock cycles with INC/DEC HL savings)

                    5.
 (from Alone Coder)
 DS .(#E0-$) - in ALASM, alignment to
nearest forward#XXEO. In other assemblies─
pax can be used instead of a dot&255
or built-in assembler functions.
DS -$&mask - analogueALIGN mask+1 (alas─
Movie version forALIGN 256:DS .(-$) )

                    6.
 (from LVD)
 Addition of two signed 8-bit numbers:
ADD A,...
RLCA
RRCA
JP PO,$+4;PE=overflow
CCF
;CY=9th bit of the result 
   Next you can doRRA to gain weight─
ty number to normal 8-bit signed
form of division by2.
 Absolute value of signed 8-bit
The numbers can be calculated like this:
 XOR A
 SUB H
 RET P
 LD A,H
 RET

Share your thoughts about the article