Ok, in an effort to (re)learn z80, i've decided to recode instcirc in z80 (it was in C). I got it to work, but i'm curious as to ways to make this smaller...


Code:
.module Program
.export

   Main
      ; Program entry point
      bcall(_rclans)
      ld a, (hl)
      cp ListObj
      ret nz
      
      ld a, (de)
      cp $03
      ret nz
      
      ex de, hl
      inc hl
      inc hl
      push hl
      
      bcall(_mov9toop1)
      bcall(_convop1)
      ld (circ_x), a
      
      ;restore HL and add 9
      pop hl
      inc hl
      inc hl
      inc hl
      inc hl
      inc hl
      inc hl
      inc hl
      inc hl
      inc hl
      push hl
      
      bcall(_mov9toop1)
      bcall(_convop1)
      ld (circ_y), a
      
      ;restore HL and add 9
      pop hl
      inc hl
      inc hl
      inc hl
      inc hl
      inc hl
      inc hl
      inc hl
      inc hl
      inc hl
      
      bcall(_mov9toop1)
      bcall(_convop1)
      
      ld c, a
      ld a, (circ_x)
      ld d, a
      ld a, (circ_y)
      ld e, a
      
      call FastCircle
      bcall(_grbufcpy)
      ret
   circ_x
      .db 0
   circ_y
      .db 0
.endmodule

.include "FastCirc.inc"


FastCirc.inc contains the routine on ticalc.org, so i didn't copy its contents here as I didn't code that part Wink FastCircle takes 3 arguments, D = center_x, E = center_y, C = radius

Code:
.module Program
.export

   Main
      ; Program entry point
      bcall(_rclans)
      ld a, (hl)
      cp ListObj
      ret nz
     
      ld a, (de)
      cp $03
      ret nz
     
      ex de, hl
      inc hl
      inc hl
      push hl
     
      bcall(_mov9toop1)
      bcall(_convop1)
      ld (circ_x), a
     
      ;restore HL and add 9
      pop hl
      ld de,9
      add hl,de
      push hl
     
      bcall(_mov9toop1)
      bcall(_convop1)
      ld (circ_y), a
     
      ;restore HL and add 9
      pop hl
      ld de,9
      add hl,de
      rst 20h
      bcall(_convop1)
     
      ld c, a
      ld a, (circ_x)
      ld d, a
      ld a, (circ_y)
      ld e, a
     
      call FastCircle
      bcall(_grbufcpy)
      ret
   circ_x
      .db 0
   circ_y
      .db 0
.endmodule

.include "FastCirc.inc"


Saves 12 bytes.
what is "rst 20h"?
Don't use bcall(_mov9toop1). Instead use rst 20h (smaller and faster).

Edit: woops multipost. To clarify rst 20h = bcall(_mov9toop1). Kerm just missed one Wink
Kllrnohj wrote:
what is "rst 20h"?
rst 20h called the reset vector at $0020 in RAM, which is a shortcut to copy 9 bytes from (hl) to (Op1).
ok, sweet - down to 338 bytes, anymore space-saving suggestions?
Kerm, you should have changed the other two bcall(_mov9toop1)s. Corrected code:



Code:
.module Program
.export

   Main
      ; Program entry point
      bcall(_rclans)
      ld a, (hl)
      cp ListObj
      ret nz
     
      ld a, (de)
      cp $03
      ret nz
     
      ex de, hl
      inc hl
      inc hl
      push hl
     
      rst 20h
      bcall(_convop1)
      ld (circ_x), a
     
      ;restore HL and add 9
      pop hl
      ld de,9
      add hl,de
      push hl
     
      rst 20h
      bcall(_convop1)
      ld (circ_y), a
     
      ;restore HL and add 9
      pop hl
      ld de,9
      add hl,de
      rst 20h
      bcall(_convop1)
     
      ld c, a
      ld a, (circ_x)
      ld d, a
      ld a, (circ_y)
      ld e, a
     
      call FastCircle
      bcall(_grbufcpy)
      ret
   circ_x
      .db 0
   circ_y
      .db 0
.endmodule

.include "FastCirc.inc"
Chipmaster wrote:
Kerm, you should have changed the other two bcall(_mov9toop1)s.


don't worry, i figured that part out and changed it on mine.

Saved 4 more bytes (by loading de at once instead of loading each to a then to d or e) - down to 334 bytes


Code:
.module Program
.export

   Main
      ; Program entry point
      ;rcl ans and check its a list
      bcall(_rclans)
      ld a, (hl)
      cp ListObj
      ret nz
      
      ;make sure dim(list = 3
      ld a, (de)
      cp $03
      ret nz
      
      ;inc past the size info and save HL
      ex de, hl
      inc hl
      inc hl
      push hl
      
      rst $20
      bcall(_convop1)
      ld (circ_x), a
      
      ;restore HL and add 9
      pop hl
      ld de, 9
      add hl, de
      push hl
      
      rst $20
      bcall(_convop1)
      ld (circ_y), a
      
      ;restore HL and add 9
      pop hl
      ld de, 9
      add hl, de
      
      rst $20
      bcall(_convop1)
      
      ld c, a
      ld de, (circ_y)
      
      call FastCircle
      bcall(_grbufcpy)
      ret
   circ_y
      .db 0
   circ_x
      .db 0
.endmodule

.include "FastCirc.inc"
That looks pretty optomized to me. The only other thing you could do would be to have circ_x and circ_y in AppBackUpScreen so that they don't take up space in your program. That would save another 2 bytes.
Yup, other than that, pwnsomeness.
Alright, cool, now to actually make sure this won't destroy your calc if given bad numbers....
Haha, definitely. How about adding clipping?
  
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 1 of 1
» 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