ALGORITHMS
(C) Ars
In this section we continue
publish useful procedure. This
times will discuss the various routines
associated with the output on screen. If you have
encounter any comments, please
us. And also can you suggest to
discussion of his version of the algorithms
contact the editor MOVE.
Part of the procedures described below,
wrote Rui Ribeiro - author WSpecem -
Spectrum emulator for Windows.
Primarily on addressing
Spectrum screen. Despite
some inconsistencies in his
structure, the address of any byte-screen
Region (# 4000 .. # 57FF) can be given
scheme:
010S SLLL RRRB BBBB
where: S - Section, or three (0 .. 2);
L - number of lines character (0 .. 7)
R - The vertical position within
Section (0 .. 7);
B - column number (0 .. 31).
Coordinates of any point (x, y) screen in these
notations have the structure:
y - 11,111,111 x - 11 111 111
S R L B bit number
y = 0 .. 191 x = 0 .. 255
And here's how you describe the address of the screen
following formula:
adr (x, y) = 16384 +2048 * INT (L / 8) +
+32 * (L-8 * INT (L / 8)) +256 * R + C
Now - the main procedure.
1) As from the coordinates of the points to get it
display the address and number of pixels per byte.
Input: BC = yx
Output: HL = screen address, A = bit
PixAdr1 LD A, B
AND A
RRA
SCF
RRA
AND A
RRA
XOR B
AND # F8
XOR B
LD H, A
LD A, C
RLCA
RLCA
RLCA
XOR B
AND # C7
XOR B
RLCA
RLCA
LD L, A
LD A, C
AND 7
RET
2) The same problem, but instead coordinates x
given column number.
Input: B = pixel line number (0 .. 191)
C = column number (0 .. 31)
Output: HL = screen address
PixAdr2 LD A, B
AND A
RRA
SCF
RRA
AND A
RRA
XOR B
AND # F8
XOR B
LD H, A
LD A, B
RLCA
RLCA
AND # E0
OR C
LD L, A
RET
The position of any text characters on
screen is given by the following scheme:
Y - 000 11111 X - 000 11 111
S R B
Y = 0 .. 23 X = 0 .. 31
3) As of the character position to get
display address.
Input: BC = YX
Output: HL = screen address
ChrAdr1 LD A, B
AND # 18
OR # 40
LD H, A
LD A, B
AND 7
RRCA
RRCA
RRCA
ADD A, C
LD L, A
RET
Or another option:
ChrAdr2 LD A, B
AND # 18
OR # 40
LD H, A
LD A, B
RRCA
RRCA
RRCA
AND # E0
OR C
LD L, A
RET
The following procedures relate to the text output
4) The descent down to the symbol.
Input: HL = screen address
Output: HL = down char screen address
DownChr LD A, L
ADD A, 32
LD L, A
RET NC
LD A, H
ADD A, 8
LD H, A
RET
5) Climb up the symbol.
Input: HL = screen address
Output: HL = upper char screen address
UpChar LD A, L
SUB 32
LD L, A
RET NC
LD A, H
SUB 8
LD H, A
RET
6) Go to the next character to
a display address.
Input: HL = screen address
Output: HL = next char screen address
NextChr RR H
RR H
RR H
INC HL
RL H
RL H
RL H
RET
7) Go to the previous character in
a display 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
Information obtained from Web-page:
http://www.atlantic.net/ ~ adansby / plot.html
(Continued in the next issue.)