Very simple circle routine for the CE. Note that it expects the LCD to be in 8-bit palette mode:
Note that this is 'lazy clipped' and even then the bounds checking is 16-bit when technically the rest isnt ... but it should still work. Obviously rough cut and its just a bresenham type algorithm so it can be improved - but it should work ... (uses exx so no interrupts etc).
Code:
Note that this is 'lazy clipped' and even then the bounds checking is 16-bit when technically the rest isnt ... but it should still work. Obviously rough cut and its just a bresenham type algorithm so it can be improved - but it should work ... (uses exx so no interrupts etc).
Code:
drawCircle:
di
; outline
; hl = cx, de = cy, bc = r, a = colour
;
push hl
push de
exx
pop de
pop hl
exx
push bc
push bc
pop de
pop hl
add hl,hl
push hl
pop bc
ld hl,3
or a
sbc hl,bc
push hl
pop ix
ld hl,0
drawCircle_Loop:
; hl = x, de = y, ix = d
;
or a
sbc hl,de
add hl,de
ret nc
ld c,ixh
bit 7,c
jr z,_dc_else
push hl
add hl,hl
add hl,hl
ld bc,6
add hl,bc
push hl
pop bc
add ix,bc
pop hl
jr _dc_end
_dc_else:
push hl
or a
sbc hl,de
add hl,hl
add hl,hl
ld bc,10
add hl,bc
push hl
pop bc
add ix,bc
pop hl
dec de
_dc_end:
call drawCircleSection
inc hl
jr drawCircle_Loop
drawCircleSection:
call drawCirclePoints
ex de,hl
call drawCirclePoints
ex de,hl
ret
drawCirclePoints:
push hl
exx
pop bc
push hl
add hl,bc ; xc+x
exx
push de
exx
pop bc
ex de,hl
push hl
add hl,bc
ex de,hl
call drawPixel ; yc+y
pop de
pop hl
exx
push hl
exx
pop bc
push hl
or a
sbc hl,bc ; xc-x
exx
push de
exx
pop bc
ex de,hl
push hl
add hl,bc
ex de,hl
call drawPixel ; yc+y
pop de
pop hl
exx
push hl
exx
pop bc
push hl
add hl,bc ; xc+x
exx
push de
exx
pop bc
ex de,hl
push hl
or a
sbc hl,bc
ex de,hl
call drawPixel ; yc-y
pop de
pop hl
exx
push hl
exx
pop bc
push hl
or a
sbc hl,bc ; xc-x
exx
push de
exx
pop bc
ex de,hl
push hl
or a
sbc hl,bc
ex de,hl
call drawPixel ; yc-y
pop de
pop hl
exx
ret
drawPixel:
; hl = x, de = y, a = colour (8-bit palette)
;
bit 7,h
ret nz ; return if negative
bit 7,d
ret nz ; return if negative
push bc
ld bc,320
or a
sbc hl,bc
add hl,bc
pop bc
ret nc ; return if offscreen
ex de,hl
push bc
ld bc,240
or a
sbc hl,bc
add hl,bc
pop bc
ret nc ; return if offscreen
ld h,160
mlt hl
add hl,hl
add hl,de
ld de,VRAM
add hl,de
ld (hl),a
ret