Author Topic: Sprite is not showing up right  (Read 2052 times)

0 Members and 1 Guest are viewing this topic.

Offline blue_bear_94

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 801
  • Rating: +25/-35
  • Touhou Enthusiast / Former Troll / 68k Programmer
    • View Profile
Sprite is not showing up right
« 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
Due to dissatisfaction, I will be inactive on Omnimaga until further notice. (?? THP hasn't been much success and there's also the CE. I might possibly be here for a while.)
If you want to implore me to come back, or otherwise contact me, I can be found on GitHub (bluebear94), Twitter (@melranosF_), Reddit (/u/Fluffy8x), or e-mail (if you know my address). As a last resort, send me a PM on Cemetech (bluebear94) or join Touhou Prono (don't be fooled by the name). I've also enabled notifications for PMs on Omnimaga, but I don't advise using that since I might be banned.
Elvyna (Sunrise) 4 5%
TI-84+SE User (2.30 2.55 MP 2.43)
TI-89 Titanium User (3.10)
Casio Prizm User? (1.02)
Bag  東方ぷろの

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: Sprite is not showing up right
« Reply #1 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.
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline chickendude

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 817
  • Rating: +90/-1
  • Pro-Riot Squad
    • View Profile
Re: Sprite is not showing up right
« Reply #2 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.