Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: blue_bear_94 on May 20, 2012, 09:03:36 pm

Title: Sprite is not showing up right
Post by: blue_bear_94 on May 20, 2012, 09:03:36 pm
I was making a movement example and everything works except that the sprite is showing up as a line instead of a box. If anyone could help me, thanks in advance!
Code: [Select]
#include    "ti83plus.inc"
#define     progStart   $9D95
.org        progStart-2
.db         $BB,$6D
x .equ AppBackUpScreen
y .equ AppBackUpScreen+1
push bc
    push de
    ld hl,x
    ld (hl),0
    ld hl,y
    ld (hl),0
MainLoop:
    call EraseSpr
    ld a,%11111110
    out ($01),a
    in a,($01)
    ld b,a
    bit 0,b
    call z,Down
    bit 1,b
    call z,Left
    bit 2,b
    call z,Right
    bit 3,b
    call z,Up
    call DrawSpr
    ld a,%11111101
    out ($01),a
    in a,($01)
    cp %10111111
    jr nz,MainLoop
    pop de
    pop bc
    ret
Down:
    ld hl,y
    ld a,(hl)
    cp 55
    ret z
    inc (hl)
    ret
Up:
ld hl,y
    ld a,(hl)
    cp 0
    ret z
dec (hl)
    ret
Left:
ld hl,x
    ld a,(hl)
    cp 0
    ret z
dec (hl)
    ret
Right:
ld hl,x
    ld a,(hl)
    cp 87
    ret z
inc (hl)
    ret
BoxPic:
.db 1,8
.db %11111111
.db %10000001
.db %10000001
.db %10000001
.db %10000001
.db %11111111
BoxErase:
.db 1,8
.db 0
.db 0
.db 0
.db 0
.db 0
.db 0
DrawSpr:
ld hl,y
    ld d,(hl)
    ld hl,x
    ld e,(hl)
    ld hl,BoxPic
    bcall(_DisplayImage)
    ret
EraseSpr:
    ld hl,y
    ld d,(hl)
    ld hl,x
    ld e,(hl)
    ld hl,BoxErase
    bcall(_DisplayImage)
    ret
Title: Re: Sprite is not showing up right
Post by: thepenguin77 on May 20, 2012, 10:55:58 pm
I've never seen the bcall _displayImage before. It looks really useful for you, just be warned that since it's a drawing routine by TI, it is going to be super super slow.

In any case, I don't have that much time to look at it right now, but I think you got the input for the bcall wrong. The bcall says your data structure needs to be height, width, data. So, for each of your sprites, the height is set to 1. Set that back to 8 and I think you'll have a box.
Title: Re: Sprite is not showing up right
Post by: chickendude on May 21, 2012, 04:37:20 am
Also, why do you push bc/de at the start of the program? I've never heard of the _displayImage BCALL before either, i'd recommend checking out ion's putsprite routine (copying/pasting the code into your program somewhere):
Quote
ionPutSprite:
   Draw a sprite to the graph buffer (XOR).
   Input:   b=sprite height
      a=x coordinate
      l=y coordinate
      ix->sprite
   Output:   Sprite is XORed to the graph buffer.
      ix->next sprite
   Destroys: af bc de hl ix

Code: [Select]
putSprite:
    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,gbuf
    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

If your program is just drawing one line, like thepenguin said it's probably from bad parameters that you're passing to the BCALL and drawing only the first row of the sprite.