LZ: a line source program


[Prev][Next][Index][Thread]

LZ: a line source program



Here is the source to a new line routine. If you are drawing lines
vertically or horizontally, this routine is smaller and faster than
Stephanie's line.asm, and it even includes 2 types of diagonal lines. I've
been having trouble with Stephanie's line.asm, so I made this. Note: if
line.asm works for you, and if you want lines that this program doesn't
support, use Stephanie's source. I'm releasing the source code, so anyone
can edit it to fit their own uses. Basically it works like this: the
beginning point is stored in hl, and the ending point is stored in de, with
the c register determining what type of line to draw. If c is 0, then it
draws a vertical line from hl (x,y format) to de (actually, d is not even
used in the vertical line routine, it draws a line from (h,l) to (h,e)). If
c is 1, it draws a horizontal line from (h,l) to (d,l)- e is not used here.
If c is 2 or 3, it draws the respective diagonal line from (h,l) to (d,e).


Now for the problems. This program works by incrementing (h,l) and comparing
it to (d,e). Therefore if de is less than hl, this program will draw a line
forever, thus effectively crashing your calc. This works for all four types
of lines, so you have to be careful to work within the program limitations.
If you don't like this feature, use Stephanie's line routine, or else I give
permission to anyone to change it in any way short of stealing credit. (It'd
be nice if you included me in your credit documentation if you use it, but
I'm not going to hunt you down if you don't, so oh well). Another feature
that might confuse people is the way the diagonal lines are drawn. It
basically draws a series of short horizontal lines 2 points long and then
checks to see if hl is equal to de, so here's some examples.


this works:                          these don't and will crash your calc:
      ..                             ..               .                 ...
    ..                              .               ..              ...
  ..                              ..              ..             ...
..                               .              ..            ...


Again, you could always modify this program to suite your own needs. Here it
is (finally) and have fun!


Clear:
        push af
        push bc
        push hl
        push de
        ROM_CALL(CLEARLCD)
        pop de
        pop hl
        pop bc
        pop af
        ret
Line:
        push af
        push bc
        push de
        push hl
DoLine:
        push bc
        ld b, h
        ld c, l
        CALL_(PointOn)
        pop bc
        ld a, c
        or a
        jr z, VertLine
        cp 1
        jr z, HorzLine
        cp 2
        jr z, ObLine
ExtraLine:
        push de
        push hl
        pop de
        dec d
        ld c, 1
        ex de, hl
        CALL_(Line)
        ex de, hl
        dec h
        pop de
        call CP_HL_DE
        jr z, EndLine
        inc l
        dec h
        jr ExtraLine
HorzLine:        
        ld a, d
        sub h
        or a
        jr z, EndLine
        inc h
        jr DoLine
VertLine:
        ld a, e
        sub l
        jr z, EndLine
        inc l
        jr DoLine
ObLine:
        push de
        push hl
        pop de
        inc d
        push bc
        ld c, 1
        CALL_(Line)
        inc h
        pop bc
        pop de
        call CP_HL_DE
        jr z, EndLine
        inc l
        inc h
        jr ObLine
EndLine:
        pop hl
        pop de
        pop bc
        pop af
        ret
PointOn:
        push af
        push de
        push hl
        ROM_CALL(FIND_PIXEL)
        ld de, $FC00
        add hl, de
        or (HL)
        ld (HL), a
        pop hl
        pop de
        pop af
        ret


David Kristensen at the University of Missouri - Kansas City
dkristensen@cctr.umkc.edu


The Mind conquers All...


Follow-Ups: