Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: Ashbad on December 14, 2010, 03:54:33 pm

Title: Trio and Niko assembly help
Post by: Ashbad on December 14, 2010, 03:54:33 pm
I just finished a 4 level 8x8 sprite drawing routine, but it does not seem to be working....  the drawing to buffers (appbackupscreen is backbuffer, plotSScreen is front buffer) works, but the coordinate system and address don't work (HL: address to data, b = x position*8, c = y position)

Help?


ALSO, I do know this is rather newbish, but I never really was good at sprite routines :P

Code: [Select]
Drawalignedsprite
push hl
ld a,c
add a,a
add a,c
add a,a
add a,a
ld l,c
        push  af
        ld      a,l
add a,b
        ld      l,a
        pop   af
ld h,0
ld de,appbackupscreen
add hl,de
push de
ld de,plotSScreen
add de,hl
sub a
ld b,8
ld c,16
pop hl
__Drawalignedspriteloop
ld a,(hl)
ex de,hl
ld (hl),a
inc de
add hl,12
ex de,hl
dec c
sub a
cp c
jp z,__Drawalignedspriteend
add 8
cp c
jp z,__Drawalignedspriteloopnext
djnz __Drawalignedspriteloop
__Drawalignedspriteloopnext
ld b,8
pop de
sub a
cp c
jp nz,__Drawalignedspriteloop
__Drawalignedspriteend
ret

EDIT: fixed some bad syntax stuff (this is my incomplete version, left my finished one at school with syntax fixed)  BUT the routine is still dysfunctional :P
Title: Re: aligned 4 level sprite routine (need help)
Post by: nemo on December 14, 2010, 04:44:27 pm
well.. i'm not sure what's wrong with your code but this is what i could come up with. though i wasn't sure what you  meant by b being x position * 8. is x position the number of bytes to the right? that's what i assumed, at least. in which case i assumed x position is a variable i could access. also, this routine xors the sprite.

i'm not 100% sure this routine works, since i haven't taken quigibo's grayscale routine and used it, but it's what i could come up with. it's found here (http://pastebin.com/8sY4RbPE). let me know if it works, if it fails. i haven't programmed in asm in awhile, but this is the routine i made for a little tunnel game i was trying to make. except i modified it to write to appbackupscreen too.
       

       
       
Title: Re: aligned 4 level sprite routine (need help)
Post by: Ashbad on December 14, 2010, 05:01:08 pm
thanks for the help, but I was able to rewrite the routine (that now works) :)

Thanks, though ;)

Maybe I can butcher this thread into a Trio and niko: falling Help-me-plz-thread and I can keep changing the title to get new input on new questions O.o

ALSO: how optimal is my clrbuffers routine?

Code: [Select]
Clrscrn
ld bc,768
ld hl,plotSScreen
ld de,appbackupscreen
sub a
__Clrscrnloop
ld (hl),a
inc hl
ex de,hl
ld (hl),a
inc hl
ex de,hl
dec bc
cp b
jp z,__Clrscrnloop
cp c
jp z,__Clrscrnloop
__Clrscrnend
ret

EDIT: I just realized I can do ld (de),a :P there goes two lines of code:

Code: [Select]
Clrscrn
ld bc,768
ld hl,plotSScreen
ld de,appbackupscreen
sub a
__Clrscrnloop
ld (hl),a
inc hl
ld (de),a
inc de
dec bc
cp b
jp z,__Clrscrnloop
cp c
jp z,__Clrscrnloop
__Clrscrnend
ret
Title: Re: aligned 4 level sprite routine (need help)
Post by: calc84maniac on December 14, 2010, 05:08:33 pm
Yay for special-purpose instructions :)
Code: [Select]
Clrscrn
ld bc,768
ld hl,plotSScreen
ld de,appbackupscreen
sub a
__Clrscrnloop
ld (hl),a
ldi
jp pe,__Clrscrnloop
ret
Title: Re: aligned 4 level sprite routine (need help)
Post by: Ashbad on December 14, 2010, 05:10:11 pm
O.o  what does the pe flag do?  also, I've seen the po flag used before (ahem quigibo's grayscale routine) can you explain to me the fthe different flags (sorry for wasting your time :()

And, cool usage of the ldi instruction, I usually never use it much O.o
Title: Re: aligned 4 level sprite routine (need help)
Post by: calc84maniac on December 14, 2010, 05:12:08 pm
O.o  what does the pe flag do?  also, I've seen the po flag used before (ahem quigibo's grayscale routine) can you explain to me the fthe different flags (sorry for wasting your time :()

And, cool usage of the ldi instruction, I usually never use it much O.o
In the case of the ldi/ldd/cpi/cpd instructions, the parity/overflow flag is set to 1 (PE) if BC is non-zero, or 0 (PO) if BC is zero. In this case, we want to loop if BC is not zero.
Title: Re: Trio and Niko assembly help
Post by: calcdude84se on December 14, 2010, 05:12:32 pm
In the context of ldi, the p/o flag is set (pe) if bc is not zero, and reset (po) if it is. (ldi decrements bc)
Edit: ninja'd
Title: Re: Trio and Niko assembly help
Post by: Ashbad on December 14, 2010, 05:13:31 pm
ooh, cool!  thanks for the helpful insight! :D

that really would save a ton of space if I use that more often O.o
Title: Re: Trio and Niko assembly help
Post by: calc84maniac on December 14, 2010, 05:14:57 pm
One thing to keep in mind is that with JR, only the NZ/Z/NC/C conditions are available. For the PO/PE/P/M conditions, JP must be used.
Title: Re: Trio and Niko assembly help
Post by: Ashbad on December 16, 2010, 01:56:43 pm
quick question, for each of may pages, if I want to include some of my routines in let's say, TaNrout.inc, can I put an include on every page, so I won't have to flip pages and lose speed, or copy and paste them and create a mess of code? like in brass:

Code: [Select]
.page 0
#include TaNrout.inc
.page 1
#include TaNrout.inc
.page 2
#include TaNrout.inc

Like that to put the code in the includes into the current location?
Title: Re: Trio and Niko assembly help
Post by: Ashbad on December 16, 2010, 07:35:18 pm
*bump* ^^^
Title: Re: Trio and Niko assembly help
Post by: calcdude84se on December 16, 2010, 09:09:14 pm
You can. Unless you absolutely need that speed or have the space, though, you might just want to put it on one page.
Also, I'm not sure if you know this or not, so here's a quick tutorial on how to create and format apps: http://benryves.com/bin/brass/tutorials/tiapps.htm (http://benryves.com/bin/brass/tutorials/tiapps.htm)
Title: Re: Trio and Niko assembly help
Post by: Ashbad on December 18, 2010, 06:10:17 pm
Does anybody know of a good gray scale rendering routine, like Dispgraphrr in Axe (and besides the source for that, it doesn't work on it's own)

it would really help me a ton.
Title: Re: Trio and Niko assembly help
Post by: Ashbad on December 20, 2010, 02:03:41 pm
bump
Title: Re: Trio and Niko assembly help
Post by: Munchor on December 20, 2010, 02:09:43 pm
That was a very well-deserved bump. Have you checked Doors CS SDK?
Title: Re: Trio and Niko assembly help
Post by: Ashbad on December 20, 2010, 04:07:11 pm
it doesn't have anything like that, and since it's an app I can't use anything to do with a shell like DCS7
Title: Re: Trio and Niko assembly help
Post by: Munchor on December 20, 2010, 04:10:30 pm
it doesn't have anything like that, and since it's an app I can't use anything to do with a shell like DCS7

Yes, I really can't get why nobody helps you with this :S
Title: Re: Trio and Niko assembly help
Post by: calc84maniac on December 20, 2010, 04:22:48 pm
Does anybody know of a good gray scale rendering routine, like Dispgraphrr in Axe (and besides the source for that, it doesn't work on it's own)

it would really help me a ton.
Wait, why wouldn't that routine work on its own?
Title: Re: Trio and Niko assembly help
Post by: Ashbad on December 20, 2010, 04:34:26 pm
It seems that on wabbit it doesn't display sprites in the right positions (even with a sprite routine from ion) and on mimas, it shows garbage
Title: Re: Trio and Niko assembly help
Post by: calc84maniac on December 20, 2010, 04:46:36 pm
Well, you can't just use a normal sprite routine for grayscale. You have to draw a sprite to each buffer (and did you clear both buffers first?)
Title: Re: Trio and Niko assembly help
Post by: Ashbad on December 20, 2010, 05:59:33 pm
yeah, I cleared both buffers, and I modified the ion one to output the same stuff to both buffers.

EDIT: it gets the byte at flags+asm_flag2 near the beginning; I wonder if a command uses that earlier to set something?

Code: (Disp4 routine) [Select]
Disp4
ld a,i
push af
di
ld (OP2+2),sp
ld a,$80
out ($10),a
ld sp,appbackupscreen - plotSScreen
ld e,(plotSScreen-appbackupscreen+12)&$ff
ld c,-$0C
ex af,af'
ld a,%11011011
ld hl,flags+asm_flag2
inc (hl)
jr z,__Disp4Lvlskip
add a,a
ld b,(hl)
inc b
jr z,__Disp4Lvlskip
rlca
ld (hl),-2
__Disp4Lvlskip
ld l,plotSScreen&$ff-1
ex af,af'
__Disp4Lvlentry
ld a,c
add a,$2C
ld h,plotSScreen>>8
inc l
ld b,64
out ($10),a
__Disp4Lvlloop
ld a,(hl)
add hl,sp
xor (hl)
ex af,af'
cp e
rra
ld d,a
ex af,af'
and d
xor (hl)
out ($11),a
ld d,(plotSScreen-appbackupscreen+12)>>8
add hl,de
djnz __Disp4Lvlloop
inc c
jr nz,__Disp4Lvlentry
__Disp4LvlDone
ld sp,(OP2+2)
pop af
ret po
ei
ret
__Disp4LvlEnd

Code: (clrdraw routine) [Select]
Clrscrn
ld bc,768
ld hl,plotSScreen
ld de,appbackupscreen
sub a
__Clrscrnloop
ld (hl),a
ldi
jp pe,__Clrscrnloop
ret

Code: (draw aligned tile in 4 level gray) [Select]
Drawtilebuffer

    ld    e,l
    ld    h,$00
    ld    d,h
    add    hl,de
    add    hl,de
    add    hl,hl
    add    hl,hl               ;Find the Y displacement offset
    ld    e,a
    and    $07               ;Find the bit number
    ld    c,a
    srl    e
    srl    e
    srl    e
    add    hl,de             ;Find the X displacement offset
    ld    de,plotSScreen
    add    hl,de
putSpriteLoop1:
sl1:    ld    d,(ix)             ;loads image byte into D
    ld    e,$00
    ld    a,c
    or    a
    jr    z,putSpriteSkip1
putSpriteLoop2:
    srl    d                  ;rotate to give out smooth moving
    rr    e
    dec    a
    jr    nz,putSpriteLoop2
putSpriteSkip1:
    ld    a,(hl)
    xor    d
    ld    (hl),a
    inc    hl
    ld    a,(hl)
    xor    e
    ld    (hl),a              ;copy to buffer using XOR logic
    ld    de,$0B
    add    hl,de
    inc    ix                   ;Set for next byte of image
    djnz    putSpriteLoop1
    ret



Drawtilebackbuffer

    ld    e,l
    ld    h,$00
    ld    d,h
    add    hl,de
    add    hl,de
    add    hl,hl
    add    hl,hl               ;Find the Y displacement offset
    ld    e,a
    and    $07               ;Find the bit number
    ld    c,a
    srl    e
    srl    e
    srl    e
    add    hl,de             ;Find the X displacement offset
    ld    de,appbackupscreen
    add    hl,de
putSpriteLoop1:
sl1:    ld    d,(ix)             ;loads image byte into D
    ld    e,$00
    ld    a,c
    or    a
    jr    z,putSpriteSkip1
putSpriteLoop2:
    srl    d                  ;rotate to give out smooth moving
    rr    e
    dec    a
    jr    nz,putSpriteLoop2
putSpriteSkip1:
    ld    a,(hl)
    xor    d
    ld    (hl),a
    inc    hl
    ld    a,(hl)
    xor    e
    ld    (hl),a              ;copy to buffer using XOR logic
    ld    de,$0B
    add    hl,de
    inc    ix                   ;Set for next byte of image
    djnz    putSpriteLoop1
    ret

Tilemap