Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's z80 & ez80 Assembly subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. Z80 & 68k Assembly => z80 & ez80 Assembly
Author Message
Fallen Ghost


Elite


Joined: 15 Jun 2006
Posts: 955

Posted: 19 Jan 2007 06:11:40 pm    Post subject:

I have a bunch of new routines, here they are for your entertainement (and Z80 assembly purpose I guess...)

PutSprite10

PutSprite8 I modified to PutSprite10. Might be useless for you, but if you have some slightly larger than 8 sprites, then you can use PutSprite10. As it is faster than PutSprite16 and allows you not to destroy shadow registers too, and run interrupts during, and smaller. So if you have unconventional sprite size...

Input:
L=Y coordinates
A=X coordinates
b=height of sprite
ix=sprite location. IX+1 being the other 2 bits

Output:
IX=data after the sprite's data

Destroyed
-AF, BC, DE, HL


Code:
putsprite_10_bits:
   ld   e,l
   ld   h,00h
   ld   d,h
   add   hl,de
   add   hl,de
   add   hl,hl
   add   hl,hl
   ld   e,a
   and   07h
   ld   c,a
   srl   e
   srl   e
   srl   e
   add   hl,de
   ld   de,plotSScreen
   add   hl,de
putSprite10Loop1:
   ld   d,(ix)
   ld   e,(ix+1)      ;modified this
   ld   a,c
   or   a
   jr   z,putSprite10Skip1
putSprite10Loop2:
   srl   d
   rr   e
   dec   a
   jr   nz,putSprite10Loop2
putSprite10Skip1:
   push    af  ;save carry. Will be 0 if bit
              ;was not destroyed or
              ;if you skipped loop2
   ld   a,(hl)
   xor   d
   ld   (hl),a
   inc   hl
   ld   a,(hl)
   xor   e
   ld   (hl),a
   pop af
   jr     nc,putSprite10skip3
   ld     a,(hl)
   xor   %10000000
   ld     (hl),a
putSprite10skip3:
   ld   de,0Bh
   add   hl,de
   inc   ix
   inc   ix                            ;added this
   djnz   putSprite10Loop1
   ret



Masked Sprite routine
This is a routine by me, as a response to Kerm's routine

I have made a routine that does exactly the same, with the same base (Joe Wingbermuehle's Ion putSprite), and the same inputs. Note: Interrupts are disabled.

Inputs:
a = X coordinate
b = Y coordinate
b= height of sprite
ix = sprite address
ix+b = mask address (same length as sprite, please)

Outputs:
Mask and then sprite displayed at specified location on the graph buffer

Destroys:
-AF, BC, DE, HL, IX, DE', HL' (shadow registers)

Improvements from Kerm's DCS version:
-Permits any height sprite (found out by looking at it's code)
-3 bytes less
-Faster


Code:
 
PutMask_di:
   di
PutMask:
   ld   e,l
   ld   h,000h
   ld   d,h
   add   hl,de
   add   hl,de
   add   hl,hl
   add   hl,hl
   ld   e,a
   and   007h
   ld   c,a
   srl   e
   srl   e
   srl   e
   add   hl,de
   ld   de,plotSScreen
   add   hl,de
   ld a,b                
   exx                    
   ld d,0              
   ld e,a
   push IX
   pop HL
   add hl,de
   ex de,hl                
   exx                    
putMaskLoop1:
   ld   d,(ix)
   ld   e,00h
   exx
   ld      h,0FFh
   ld      a,(de)
   ld      l,a
   inc de
   exx
   ld   a,c
   or   a
   jr   z,putMaskSkip1
putMaskLoop2:
   srl   d
   rr   e
   exx
   SCF
   rr l
   rr h
   exx
   dec   a
   jr   nz,putMaskLoop2
putMaskSkip1:
   ld   a,(hl)
   exx
   and l
   exx
   or   d
   ld   (hl),a
   inc   hl
   ld   a,(hl)
   exx
   and     h
   exx
   or   e
   ld   (hl),a
   ld   de,00Bh
   add   hl,de
   inc   ix
   djnz   putMaskLoop1
   ret


Last edited by Guest on 19 Jan 2007 06:29:14 pm; edited 1 time in total
Back to top
cjgone
Aw3s0m3


Active Member


Joined: 24 May 2006
Posts: 693

Posted: 19 Jan 2007 06:22:20 pm    Post subject:

Wait, if your running an interrupt, do you need to disable them to run the masked sprite routine so it doesn't screw with the shadow registers?

Last edited by Guest on 19 Jan 2007 06:22:49 pm; edited 1 time in total
Back to top
Fallen Ghost


Elite


Joined: 15 Jun 2006
Posts: 955

Posted: 19 Jan 2007 06:30:42 pm    Post subject:

Yes, definitely, I also modified the code so you could decide where to jump if you wanted to disable interrupts or if you didn't want (in case of extreme-time saving and that you don't need interrupts) or that you just want to see the result (might be fun, never know)
Back to top
Fallen Ghost


Elite


Joined: 15 Jun 2006
Posts: 955

Posted: 02 Feb 2007 09:42:35 pm    Post subject:

PutSprite16

PutSprite8 I modified to PutSprite16. From what I've seen on Ticalc, it's the fastest.

Input:
L=Y coordinates
A=X coordinates
b=height of sprite
ix=sprite location. IX+1 being the other 8 bits

Output:
IX=data after the sprite's data

Destroyed:
-AF, BC, DE, HL


Code:
putSprite16:
   ld   e,l
   ld   h,$00
   ld   d,h
   add   hl,de
   add   hl,de
   add   hl,hl
   add   hl,hl
   ld   e,a
   and   $07
   ld   c,a
   srl   e
   srl   e
   srl   e
   add   hl,de
   ld   de,gbuf
   add   hl,de
putSprite16Loop1:
        ld a,(ix+0)
   ld   d,(ix+1)
   ld   e,$00
   dec c
   inc c
   jr   z,putSprite16Skip1
        push bc
putSprite16Loop2:
   srl   a
        rr d
   rr   e
   dec   c
   jr   nz,putSprite16Loop2
        pop bc
putSprite16Skip1:
        xor (hl)
        ld (hl),a
        inc hl
   ld   a,(hl)
   xor   d
   ld   (hl),a
   inc   hl
   ld   a,(hl)
   xor   e
   ld   (hl),a
   ld   de,10
   add   hl,de
   inc   ix
        inc ix
   djnz   putSprite16Loop1
   ret


Last edited by Guest on 02 Feb 2007 09:43:06 pm; edited 1 time in total
Back to top
WikiGuru
ADOS (Attention deficit... Oh! Shiny!)


Elite


Joined: 15 Sep 2005
Posts: 923

Posted: 08 Feb 2007 07:06:55 pm    Post subject:

for those who are writing flash applications, here's a routine that will center small text. Note that it is actually several routines that can be each called individually, but also rely on each other.
This function is similar to my previous center text function, except it is much more inline due to the specifications for writting flash applications.

Note: I did NOT write all of these routines (for example, VPutS and String Length were written by TI), but am including them inline to make flash application programming easier.
String Length

Code:
;_StrLength inline
;
;inputs:   hl pointer to null-terminating string
;
;outputs:   bc=string length, not including null term
;      hl points to null term
;

StrLength
 ld c,0
StrLoop
 ld a,(hl)      ;get character
 or a         ;check if it's the end
 ret z         ;if zero, return
 inc hl
 inc c         ;increase counter
 jr StrLoop      ;repeat

null-terminating String Length
note: could someone check my counting for the offsets table? I'm not sure if I got the count right on all of them.

Code:
;Find the pixels needed to display a null-terminating string
;
;inputs:    hl points to string in Ram
;
;outputs:    b and c=pixels needed to display string
;

nStrLength
 push hl
 call StrLength      ;get the string length
 pop hl
 
 push hl
 ld b,c         ;set character counter
 ld c,0         ;set pixel counter
 
nStrLengthLoop
 ld a,(hl)         ;get character
 
 ld e,a         ;put it into de so it can be added
 ld d,0
 
 inc hl         ;point to next character and save string pointer
 push hl
 
 ld hl,charLengths      ;point to offsets table
 add hl,de
 
 ld a,(hl)         ;get offset
 add a,c         ;add it to total length
 ld c,a         ;swap 'a' and 'c'
 
 pop hl         ;get back string pointer
 djnz nStrLengthLoop

 ld b,c
 pop hl         ;get back string pointer to start of string
 
 ret

charLengths
 .db 3,6,4,4,4,4,6,6,4,4,4,4,3,4,5,5
 .db 4,5,4,4,5,5,4,5,6,5,4,4,5,6,4,4
 .db 1,2,4,6,6,4,5,2,3,3,6,4,3,4,2,4
 .db 4,4,4,4,4,4,4,4,4,4,2,3,4,4,4,4
 .db 6,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4
 .db 4,4,4,4,4,4,4,4,4,4,4,4,4,3,4,4
 .db 3,4,4,4,4,4,3,4,4,2,4,4,3,6,4,4
 .db 4,4,4,3,3,4,4,6,4,4,5,4,2,4,5,4
 .db 4,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5
 .db 5,5,5,5,4,4,4,4,4,4,4,4,4,4,4,4
 .db 4,4,6,6,6,6,6,6,6,6,4,4,4,4,4,4
 .db 4,4,4,4,5,5,3,3,4,4,2,5,4,5,6,4
 .db 4,3,4,5,6,5,5,5,5,6,6,4,4,4,4,4
 .db 3,4,3,4,4,4,4,4,4,4,4,4,4,4,5,3
 .db 4,7,5,7,6,7,6,7,6,7,6,7,5,4,6,6
 .db 6,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3

VPutS

Code:
;VPutS inline
;
;inputs:   hl pointer to null-terminating string
;      (penRow) and (penCol) must be preset
;
;outputs:   hl points to null term of string
;      string displayed
VPutS:
 push af
 push de
 push ix
VPutS10:
 ld a,(hl) ; get a character of string name
 inc hl
 or a ; end of string?
 jr z, VputS20 ; yes --->
 bcall(_VPutMap) ; display one character of string
 jr nc, VPutS10 ; display rest of string IF FITS
VputS20:
 pop ix
 pop de
 pop af
 ret

VPutS_Center

Code:
;Centers the string to the display.
;
;inputs:    hl pointer to null-terminating string
;      (penRow) must be set before calling
;
;outputs:    hl points to null term of the string
;      Text centered on string
;

VPutS_Center
 push hl
 call nStrLength
 pop hl

 ld a,96      ;width of screen
 sub b         ;subtract width of string
 rra         ;divide by 2 to be centered
 ld (pencol),a

 ld (penCol),a   ;display it
 call VPutS
 ret


Last edited by Guest on 08 Feb 2007 07:08:21 pm; edited 1 time in total
Back to top
Jim e


Advanced Member


Joined: 05 Sep 2005
Posts: 360

Posted: 11 Feb 2007 09:58:52 am    Post subject:

You can find the width of a string with out a table. You can use TI's buit in routines for that task.


Code:
;in:
; hl = string
;
;out:
; c = width in pixels

StrPixLeng:
    ld c,0
splloop:
    ld a,(hl)
    inc hl
    or a
    ret z
    push hl
    push bc
    ld l,a
    ld h,0
    add hl,hl
    add hl,hl
    add hl,hl
    bcall(_sfont_len)
    pop bc
    pop hl
    add a,c
    ld c,a
    jr splloop


It'd be fairly easy to add in things like a variable delimiter or maximum number of characters to read.
Back to top
WikiGuru
ADOS (Attention deficit... Oh! Shiny!)


Elite


Joined: 15 Sep 2005
Posts: 923

Posted: 11 Feb 2007 01:54:50 pm    Post subject:

You're absolutely right. I forgot about the bcall that lets you get the length of 1 character Sad

Why did you add hl to hl 3 times?
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 11 Feb 2007 04:01:23 pm    Post subject:

The _SFont_Len bcall wants HL to be the character's value multiplied by 8. This is completely arbitrary from the programmer's POV, and it's done that way because this makes HL an "offset into the font look-up table" that is, the bcall will add the address of the font data to HL and then be exactly at the data for the character we want to look up.
If I were TI, I'd have put the five commands preceding the bcall in Jim's routine into the bcall code, which would be much more intuitive.
Back to top
ForthReich


Member


Joined: 02 May 2007
Posts: 228

Posted: 07 Jun 2007 07:40:25 pm    Post subject:

Fallen Ghost wrote:
PutSprite16

Code:
putSprite16:
...code
   ld   de,gbuf
code...

[post="96333"]<{POST_SNAPBACK}>[/post]

I run spasm and DSC 6, and I got an error here
Label error in gbuf


Last edited by Guest on 07 Jun 2007 07:40:57 pm; edited 1 time in total
Back to top
Harrierfalcon
The Raptor of Calcs


Super Elite (Last Title)


Joined: 25 Oct 2006
Posts: 2535

Posted: 07 Jun 2007 07:55:44 pm    Post subject:

That would be a mislabel in the include. Change "gbuf" to "plotsscreen" or add "gbuf .equ plotsscreen" to the beginning and it'll work.
Back to top
luby
I want to go back to Philmont!!


Calc Guru


Joined: 23 Apr 2006
Posts: 1477

Posted: 07 Jun 2007 08:05:53 pm    Post subject:

I believe you can replace gbuf with plotsscreen.

[edit] Ahhh, I had the computer stolen by my dad. Still, if it's said twice, it must be true


Last edited by Guest on 07 Jun 2007 08:06:59 pm; edited 1 time in total
Back to top
calc84maniac


Elite


Joined: 22 Jan 2007
Posts: 770

Posted: 12 Jun 2007 10:38:02 am    Post subject:

The Better CP HL,DE
compares hl to de, same flag outputs as 8-bit compare

Code:
or a
sbc hl,de
add hl,de
Back to top
Fallen Ghost


Elite


Joined: 15 Jun 2006
Posts: 955

Posted: 12 Jun 2007 02:46:42 pm    Post subject:

Calc84, have you noticed on Detached Solutions, first post of 2nd page, from Jman, he posted two routines for CP HL,DE and one is even faster than yours considering he saves HL and not you.

You substract, he compares.
Back to top
DigiTan
Unregistered HyperCam 2


Super Elite (Last Title)


Joined: 10 Nov 2003
Posts: 4468

Posted: 12 Jun 2007 02:54:51 pm    Post subject:

Fallen Ghost wrote:
Calc84, have you noticed on Detached Solutions, first post of 2nd page, from Jman, he posted two routines for CP HL,DE and one is even faster than yours considering he saves HL and not you.

You substract, he compares.
[post="107823"]<{POST_SNAPBACK}>[/post]

Please tell me you didn't post this just to crap on calc84's version. Wink (and where's the link?)


Last edited by Guest on 12 Jun 2007 02:55:51 pm; edited 1 time in total
Back to top
Fallen Ghost


Elite


Joined: 15 Jun 2006
Posts: 955

Posted: 12 Jun 2007 03:10:35 pm    Post subject:

Nope, here's the link, he even posted it in the list of Detached's useful routines, even if it was already there.
Back to top
DigiTan
Unregistered HyperCam 2


Super Elite (Last Title)


Joined: 10 Nov 2003
Posts: 4468

Posted: 12 Jun 2007 03:17:27 pm    Post subject:

Fair enough. Though I should point out calc 84's routine is only 4 bytes @ 33 cycles. Jman's routines are 5 bytes @ 40 cycles and 5 bytes @ 27/21 cycles respectivly. The second routine finishes in 21 cycles only if D and H are equal. So each has a size or speed advantage.

Last edited by Guest on 12 Jun 2007 03:19:29 pm; edited 1 time in total
Back to top
Fallen Ghost


Elite


Joined: 15 Jun 2006
Posts: 955

Posted: 12 Jun 2007 04:07:31 pm    Post subject:

Oh, didn't see the add hl,de, so yeah, it's a bit optimized. but still, the second one is faster, so it's "The better" considering speed.

Another way of doing it...
Back to top
Jim e


Advanced Member


Joined: 05 Sep 2005
Posts: 360

Posted: 12 Jun 2007 04:53:16 pm    Post subject:

Count the tstates again.

Code:
   or a        ;4
   sbc hl,de   ;15
   add hl,de   ;11
;always 30


Cmp_HL_DE:
    ld a,h     ;4
    cp d       ;4
    ret nz     ;5
    ld a,l     ;4
    cp e       ;4
    ret        ;10
;Best case 30, worst 48
The first has the advantage of only being 4 bytes, making it reasonable to be a macro. The second on the other hand has to be a call and is no faster. In other words the first is better in all cases.


why is this being posted on every forum.
Back to top
calc84maniac


Elite


Joined: 22 Jan 2007
Posts: 770

Posted: 12 Jun 2007 08:17:37 pm    Post subject:

Dunno. I guess I really liked it! (It affects all flags that 8-bit compare does).
Back to top
Fallen Ghost


Elite


Joined: 15 Jun 2006
Posts: 955

Posted: 12 Jun 2007 08:55:27 pm    Post subject:

Anyway, good routine. Will be useful. Should have counted myself. Cool

Last edited by Guest on 12 Jun 2007 08:59:08 pm; edited 1 time in total
Back to top
Display posts from previous:   
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
    » Goto page Previous  1, 2, 3, 4, 5  Next
» View previous topic :: View next topic  
Page 3 of 5 » All times are GMT - 5 Hours

 

Advertisement