1 REM Ins{nd av: Patric Ljung <5455>    1986-11-09 13.54.04 (WRITE)
hrline    zprog linje-generator f|r hr-grafik
;
;         *-------------------------------------------------------
;         * line - linjegenerator f|r hr-grafik
;         * Datum: 1986-11-09
;         *-------------------------------------------------------
;         * Patric Ljung / MI Software
;         *   Stigl|tsgatan 56
;         *   582 40 Link|ping   Tfn: 013 - 13 14 82/12 16 88
;         *-------------------------------------------------------
;         * In:    A      = Linjetyp
;         *        Start- och slutkoordinater i variabler i minnet
;         *        (_x1)
;         *        (_y1)
;         *        (_x2)
;         *        (_y2)
;         *-------------------------------------------------------
;         * Ut:    ---
;         *-------------------------------------------------------
;         * Anv{nda register:
;         *   hl    = adress i bildminnet * 2
;         *   bc    = delta x f|r bildminnet (1 alt -1)
;         *   de    = delta y f|r bildminnet (256 alt -256)
;         *   hl'   = q
;         *   bc'   = dfdx * 2
;         *   de'   = dfdy * 2
;         *-------------------------------------------------------
;
;
          global _line,_x1,_x2,_y1,_y2,_slask
;
;
;         Function start !
;
_line
          ld    bc,(_x2)
          ld    de,(_y2)
          ld    h,e
          ld    l,c
          ld    (_slask+4),hl     Slutaddress
          ld    ix,_slask
;
          ld    bc,(_x1)
          ld    de,(_y1)
          ld    h,e               HR-address * 2
          ld    l,c
          push  hl
;
          ld    de,(_x1)
          ld    hl,(_x2)
          or    a
          sbc   hl,de
          ld    (_slask+0),hl
          bit   7,h
          jr    z,dx_pos
          ld    bc,-1
          jr    dy_sgn
dx_pos
          ld    bc,1
dy_sgn
          ld    de,(_y1)
          ld    hl,(_y2)
          or    a
          sbc   hl,de
          ld    (_slask+2),hl
          bit   7,h
          jr    z,dy_pos
          ld    de,-256
          jr    dfd_def
dy_pos
          ld    de,256
;
dfd_def
          exx
          ld    de,(_slask+0)     Dfdy
          ld    h,d
          ld    l,e
          bit   7,d
          jr    z,dfdy_pos
          ld    hl,0
          or    a
          sbc   hl,de
dfdy_pos
          ex    de,hl
;
          ld    bc,(_slask+2)     Dfdx
          ld    h,b
          ld    l,c
          bit   7,b
          jr    nz,dfdx_neg
          ld    hl,0
          or    a
          sbc   hl,bc
dfdx_neg
;
          add   hl,hl
          ld    b,h
          ld    c,l
          add   hl,de
          ex    de,hl
          add   hl,hl
          ex    de,hl
          exx
;
          pop   hl
          call  plota
;
draw
          add   hl,bc
          exx
          bit   7,h
          jr    nz,step_xy
;
          add   hl,bc
          exx
          jr    draw_c
step_xy
          add   hl,bc
          add   hl,de
          exx
          add   hl,de
draw_c
          call  plota
;
          ld    a,l
          cp    (ix+4)
          jr    nz,draw
;
          ret
;
;
plota
          push  hl
          push  bc
          ld    b,1
          srl   h
          rr    l
          jr    nc,plotah
          ld    a,(hl)
          and   0f0h
          or    b
          jr    plota_ex
plotah
          sla   b
          sla   b
          sla   b
          sla   b
          ld    a,(hl)
          and   00fh
          or    b
plota_ex
          ld    (hl),a
          pop   bc
          pop   hl
          ret
;
;
_x1       defw  0
_x2       defw  0
_y1       defw  0
_y2       defw  0
;
_slask    defs  10
;
;
          end
;
; OBS! Rutinen {r {n s} l{nga bara definierad f|r vinklar mindre {n 45 
;      grader. Vinkeln {r definierad mellan linjen och x-axeln.
;      Se kommentar i m|tet Z80
