Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
chickendude wrote:

lirtosiast: I believe your routine should work for unsigned numbers as is as well.

You mean signed numbers?
As I mentionned before, I'm adapting my own rectangle routine (written for Sprite project v3.2) because I'd like to propose it to the C libraries.

Here's the source:


Code:
_FillRectangle_NoClip:
 Draws an unclipped rectangle with the global color index
 Arguments:
  arg0 : X Coord
  arg1 : Y Coord
  arg2 : Width
  arg3 : Height
 Returns:
  None
       
        ld      iy,0
        add     iy,sp
        ld      a,(iy+12)               ; height
        or      a
        ret     z
        ld      bc,(iy+9)               ; width
        sbc     hl,hl
        adc     hl,bc
        ret     z 
        ld      hl,(iy+3)                       ; hl = x coordinate
        ld      e,(iy+6)                        ; e = y coordinate
_FillRectangle_NoClip_ASM:
        ld      d,lcdWidth/2
        mlt     de
        add     hl,de
        add     hl,de
        ld      de,(currDrawBuffer)
        add     hl,de
        ex      de,hl
        push    de
        ld      (_RectangleWidth1_SMC),bc \.r
        ld      (_RectangleWidth2_SMC),bc \.r
        ld      hl,color1
        ldi                                     ; check if we only need to draw 1 pixel
        pop     hl
        jp      po,_Rectangle_NoClip_Skip \.r
        ldir
_Rectangle_NoClip_Skip:       
        dec     a
        ret     z
        inc     b
        ld      c,$40                  ; = fast "ld bc,lcdWidth"
_Rectangle_Loop_NoClip:
        add     hl,bc
        dec     de
        ex      de,hl
_RectangleWidth1_SMC =$+1       
        ld      bc,0
        lddr
        dec     a
        ret     z
        ld      bc,2*lcdWidth+1
        add     hl,bc
        inc     de
        ex      de,hl
_RectangleWidth2_SMC =$+1       
        ld      bc,0
        ldir
        ld      bc,2*lcdWidth-1
        dec     a
        jr      nz,_Rectangle_Loop_NoClip
        ret

;-------------------------------------------------------------------------------
;_FillRectangle_NoClip:
; Draws an unclipped rectangle with the global color index
; Arguments:
;  arg0 : X Coord
;  arg1 : Y Coord
;  arg2 : Width
;  arg3 : Height
; Returns:
;  None
;       
;        ld      iy,0
;        add     iy,sp
;        ld      bc,(iy+9)                       ; bc = width
;        sbc     hl,hl
;        adc     hl,bc
;        ret     z                               ; make sure width is not 0
;        ld      a,(iy+12)                       ; a = height
;        or      a,a
;        ret     z                               ; make sure height is not 0
;        ld      hl,(iy+3)                       ; hl = x coordinate
;        ld      e,(iy+6)                        ; e = y coordinate
;_FillRectangle_NoClip_ASM:
;        ld      d,lcdWidth/2
;        mlt     de
;        add     hl,de
;        add     hl,de
;        ld      iy,(currDrawBuffer)
;        ex      de,hl                           ; de -> place to begin drawing
;        ld      (_RectangleWidth_SMC),bc \.r
;_Rectangle_Loop_NoClip:
;        add     iy,de
;        lea     de,iy
;_RectangleWidth_SMC =$+1
;        ld      bc,0
;        ld      hl,color1 \.r
;        ldi                                     ; check if we only need to draw 1 pixel
;        jp      po,_Rectangle_NoClip_Skip \.r
;        scf
;        sbc     hl,hl
;        add     hl,de
;        ldir                                    ; draw the current line
;_Rectangle_NoClip_Skip:
;        ld      de,lcdWidth                     ; move to next line
;        dec     a
;        jr      nz,_Rectangle_Loop_NoClip
;        ret
;----------------------------------------------------------------------       


EDIT: here's my final version
I might as well copy/paste Runer's comments from #ez80-dev if he didn't notice the post:
Quote:
[7:46pm] Runer112: I'm confused
[7:46pm] Runer112: why would you include constants in magic number form
[7:47pm] Runer112: but then comment them anyways with their semantic value


But anyway, you should make a PR to replace the existing graphx routine Smile
(and also time it to compare, for instance, how long it takes for 1000 rectangles with graphx and yours)
Before my Pull Request, I have to manage this jump inside the routine
_FillRectangle_NoClip_ASM:
my version needs to allow that...

And concerning comparisons, I'll ask you , Adriweb Wink
Well, I can try comparing things, but give me some 8xp Razz
(or some C code to call the function)
The test of 1000 whole-screen-rectangles takes now 13 seconds !.. (instead of 13.5 seconds)
Here is a fast and accurate arctan routine. It only works on the range [0,1), but it is easy enough to extend the range to any input. It's only good to approximately 8 bits, though.

Input is in E, output is H=256*atan(E/256). For example, E=177 returns H=154. In reality, 256*atan(177/256)=154.8633...

Code:

atan8:
;returns H=256*arctan(E/256)
;48cc if ADL mode
;takes 164cc to call this on the TI-84+CE
  ld c,201
  ld b,e
  mlt bc    ;x*201
  xor a
  sub e
  ld d,a
  mlt de    ;x(256-x)
  ld l,e
  ld h,70
  ld e,h
  mlt de  ;upper bytes
  mlt hl  ;lower bytes
  ld a,e
  add a,h
  ld l,a
  ld h,d
  jr nc,$+3
  inc h
  add hl,bc
  ret
  
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 2 of 2
» All times are GMT - 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