Код:
; LINE DRAWING/ETC.
;buffer: H - y, L - x
LNBUF EQU #B000 ;strt of lin buffer
LINDRAW ;draw line
;HL - BEGIN COORDS
;DE - END COORDS
;
;H,D - Y
;L,E - X
;
; deltaX and deltaY < 128 !!!
;brezenham algorithm
;idea of SET N,(HL) taken from SPAZM
LD A,D
SUB H
JR NC,NOSWAP
NEG
EX DE,HL
NOSWAP
;HL - UPPER THAN DE (H<=D)
LD D,A ; DELTA Y
LD A,E
SUB L
JP NC,LNRT ; LINE TO RIGHT
;LINE TO LEFT
LNLF
NEG
LD E,A ; DELTA X
LD A,D
SUB E
JR C,LFHZ ; HORIZONTAL
;VERTICAL LEFT
LFVR
LD A,L ; CALC ENTRY POINT
CPL
AND 7
LD C,A
ADD A,A
ADD A,A
ADD A,A
ADD A,C
LD (VRLF_J+1),A
LD A,L ; X BUFFER POS
RRA
RRA
RRA
AND #1F
LD L,A
LD A,'LNBUF; Y BUFFER POS
ADD A,H
LD H,A
LD B,D ; LOOP COUNTER
LD A,D
SLA D
SLA E ;MIDDLE CORRECTION
VRLF_J JR $
MACRO VRLF
SET \0,(HL)
INC H
DEC B
RET M
SUB E
JR NC,$-6
ADD A,D
ENDM
VRLF_L
VRLF 0
VRLF 1
VRLF 2
VRLF 3
VRLF 4
VRLF 5
VRLF 6
VRLF 7
DEC L
JR VRLF_L
;HORIZONTAL LEFT
LFHZ
LD A,L ; CALC ENTRY POINT
CPL
AND 7
LD C,A
ADD A,A
ADD A,A
ADD A,A
ADD A,C
LD (HZLF_J+1),A
LD A,L ; X BUFFER POS
RRA
RRA
RRA
AND #1F
LD L,A
LD A,'LNBUF; Y BUFFER POS
ADD A,H
LD H,A
LD B,E ; LOOP COUNTER
LD A,E
SLA E ;MIDDLE CORRECTION
SLA D
HZLF_J JR $
MACRO HZLF
SET \0,(HL)
DEC B
RET M
SUB D
JR NC,$+4
ADD A,E
INC H
ENDM
HZLF_L
HZLF 0
HZLF 1
HZLF 2
HZLF 3
HZLF 4
HZLF 5
HZLF 6
HZLF 7
DEC L
JR HZLF_L
LNRT
LD E,A ; DELTA X
LD A,D
SUB E
JR C,RTHZ ; HORIZONTAL
;VERTICAL RIGHT
RTVR
LD A,L ; CALC ENTRY POINT
AND 7
LD C,A
ADD A,A
ADD A,A
ADD A,A
ADD A,C
LD (VRRT_J+1),A
LD A,L ; X BUFFER POS
RRA
RRA
RRA
AND #1F
LD L,A
LD A,'LNBUF; Y BUFFER POS
ADD A,H
LD H,A
LD B,D ; LOOP COUNTER
LD A,D
SLA D
SLA E ;MIDDLE CORRECTION
VRRT_J JR $
MACRO VRRT
SET \0,(HL)
INC H
DEC B
RET M
SUB E
JR NC,$-6
ADD A,D
ENDM
VRRT_L
VRRT 7
VRRT 6
VRRT 5
VRRT 4
VRRT 3
VRRT 2
VRRT 1
VRRT 0
INC L
JR VRRT_L
;HORIZONTAL RIGHT
RTHZ
LD A,L ; CALC ENTRY POINT
AND 7
LD C,A
ADD A,A
ADD A,A
ADD A,A
ADD A,C
LD (HZRT_J+1),A
LD A,L ; X BUFFER POS
RRA
RRA
RRA
AND #1F
LD L,A
LD A,'LNBUF; Y BUFFER POS
ADD A,H
LD H,A
LD B,E ; LOOP COUNTER
LD A,E
SLA E ;MIDDLE CORRECTION
SLA D
HZRT_J JR $
MACRO HZRT
SET \0,(HL)
DEC B
RET M
SUB D
JR NC,$+4
ADD A,E
INC H
ENDM
HZRT_L
HZRT 7
HZRT 6
HZRT 5
HZRT 4
HZRT 3
HZRT 2
HZRT 1
HZRT 0
INC L
JR HZRT_L
Небольшой комментарий: буфер имеет вид: H - y-координата, L - x-координата. Конечно зажор памяти афуенный, но окошко было маленькое, а вывод из такого буфера чуть быстрее, чем ld e,(hl):inc h:ld d,(hl):inc h : push de ....