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:
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
KingInfinity wrote:
tr1p1ea wrote:
So a circle routine for the CE? Will this be using the stock LCD setup? (Not in simulated half-res or palette modes?)

8bpp mode, but otherwise the same.


Should the circle be filled in or just an outline? Should it be filled in with a different color than the outline?
The routine is only for an outline, it can be modded for filling however.
Thank you very much tr1p1ea! This is super helpful! I'll get back to working on this soon!
Does anyone know how to convert an number to a string in ASM? Someone told me to divide by 10, but I'm not sure what this means or how it helps. Any help would be appreciated Smile
You might be interested in this old post for an explanation and some sample code.
Ok, thanks to Mateo and Chickendude I have figured this out. My next question involves this piece of code:

Code:
waitForEnter:
 ld hl,DI_Mode          ; Register for keypad mode
 ld (hl),2              ; Set Single Scan mode
 xor a,a
 cp a,(hl)              ; Wait for Idle mode
 ld a,(kbdG6)
 bit kBitEnter,a
 jp Z,drawFrame
 jp waitForEnter


This code should wait for enter to NOT be pressed to advance to drawFrame, however, it just freezes the program. Any help with fixing this would be appreciated.

Edit: I have solved this by adding some things
KingInfinity wrote:
Ok, thanks to Mateo and Chickendude I have figured this out. My next question involves this piece of code:

Code:
waitForEnter:
 ld hl,DI_Mode          ; Register for keypad mode
 ld (hl),2              ; Set Single Scan mode
 xor a,a
 cp a,(hl)              ; Wait for Idle mode
 ld a,(kbdG6)
 bit kBitEnter,a
 jp Z,drawFrame
 jp waitForEnter

Edit: I have solved this by adding some things

Not quite Wink Here you go; this should work better:


Code:
waitForEnter:
 di
 ld hl,DI_Mode          ; Register for keypad mode
 ld (hl),2              ; Set Single Scan mode
 xor a,a
scan_wait:
 cp a,(hl)              ; Wait for Idle mode
 jr nz,scan_wait
 ld a,(kbdG6)
 bit kBitEnter,a
 jp Z,drawFrame
 jp waitForEnter
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 3 of 3
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement