Skip to content

Instantly share code, notes, and snippets.

@jacobly0
Last active November 5, 2016 02:05
Show Gist options
  • Save jacobly0/0f7d58cf1394c50ade403f7851429bcf to your computer and use it in GitHub Desktop.
Save jacobly0/0f7d58cf1394c50ade403f7851429bcf to your computer and use it in GitHub Desktop.
Unclipped Line in ez80
Line:
ld iy,-1
add iy,sp
ld hl,(iy+4) ; hl = x1
ld c,(iy+7) ; c = y1
ld de,(iy+10) ; de = x2
ld b,(iy+13) ; b = y2
ex.s de,hl ; de = x1, hl = x2
ld a,c
sbc a,b
jr c,_
scf
ld a,b
sbc a,c ; a = -dy-1 = -|y1-y2|-1
ld c,b ; c = ys = min(y1,y2)
ex de,hl ; de = xs, hl = xe
_: push hl
ld hl,(currentDrawingBuffer)
add hl,de
ld b,lcdWidth/2
mlt bc
add hl,bc
add hl,bc
ex (sp),hl ; (iy-3) = &currentDrawingBuffer[xs][ys]
ld c,a ; c = -dy
sbc hl,de
sbc a,a
jr nc,_
add hl,de
ex de,hl
and a,8
sbc hl,de
_: push hl ; (iy-6) = hl = dx = |xe-xs|
add hl,hl ; hl = 2dx
ex de,hl ; de = 2dx
scf
sbc hl,hl
ld l,c
push hl
pop iy ; iy = -dy-1
adc hl,hl ; hl = -2dy-1
inc de ; de = 2dx+1
add hl,de
or a,$a1
sbc hl,de
jr nc,_ ; if (dx >= dy)
ld (LineHD),a \.r
ld (LineHH),hl \.r
ex de,hl
ld (LineHW),hl \.r
pop iy
pop hl
lea bc,iy+1
ld a,(color6) \.r
LineH: ld (hl),a
cpi
LineHD = $ - 1
ret po
add iy,de
jr c,LineH
ld de,0
LineHW = $ - 3
add iy,de
ld de,lcdWidth
add hl,de
ld de,-1
LineHH = $ - 3
jr LineH
_: dec de ; de = 2dx
inc hl
xor a,$23^$a1
ld (LineVD),a \.r
ld (LineVH),hl \.r
pop hl
pop hl
ld a,iyl
_: ld bc,lcdWidth
LineV: ld (hl),0
color6 = $ - 1
inc a
ret z
add hl,bc
add iy,de
jr nc,LineV
inc hl
LineVD = $ - 1
ld bc,-1
LineVH = $ - 3
add iy,bc
jr -_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment