Author Topic: Drawing an overwrite black/white sprite  (Read 1559 times)

0 Members and 1 Guest are viewing this topic.

Online Hot_Dog

  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2988
  • Rating: +445/-10
    • View Profile
Drawing an overwrite black/white sprite
« on: October 21, 2010, 03:46:26 pm »
How do I go about drawing a sprite so that 1s are black and 0s are white?  All I need is the basics behind it, no code or anything.

I tried writing my own routine, but as I draw byte by byte, there's either some transparency, or the next byte of pixel data messes up what's in the previous byte of pixel data.  I'm trying to duplicate "B_CALL DisplayImage." Oh, and by the way, I don't care if there's a "white square" appearing around the sprite like Ti's DisplayImage.  In fact, I'm trying to achieve the same effect with no results.

Offline jnesselr

  • King Graphmastur
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2270
  • Rating: +81/-20
  • TAO == epic
    • View Profile
Re: Drawing an overwrite black/white sprite
« Reply #1 on: October 21, 2010, 07:02:34 pm »
Can you give a pic of what it is doing, and what you want it to do?

From what I'm reading, I think you just clear the background first, unless I don't understand your post correctly.

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Drawing an overwrite black/white sprite
« Reply #2 on: October 23, 2010, 02:29:18 pm »
Hm... I can give a general ASM tip to help with the messed up pixels problem. (Unless I have misunderstood, of course. Credit for this method, AFAIK, goes to calc84maniac)
Code: [Select]
xor b
and c
xor b
It effectively selects bits from b to put in a.
A set bit in c corresponds to leaving the original corresponding bit in a, and a reset bit corresponds to overwriting that bit in a with b.
For example, if a=%10100110, b=%01101011, and c=%11001101, then the result would be %10100110 in a, with bits 0, 2, 3, 6, and 7 coming from a and bits 1, 4, and 5 coming from b.
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Online Hot_Dog

  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2988
  • Rating: +445/-10
    • View Profile
Re: Drawing an overwrite black/white sprite
« Reply #3 on: October 23, 2010, 02:45:13 pm »
So, say this is my sprite routine, which causes messed up pixels:

Code: [Select]
Put_Sprite_Overwrite:
; A = x coordinate
; L = y coordinate
; B = number of rows
;
; IX = address of sprite
    LD     H, 0
    LD     D, H
    LD     E, L
    ADD    HL, HL
    ADD    HL, DE
    ADD    HL, HL
    ADD    HL, HL

    LD     E, A
    SRL    E
    SRL    E
    SRL    E
    ADD    HL, DE

    LD     DE, plotsscreen
    ADD    HL, DE
   
   
    AND    7
    JR     Z, _AlignedOverwrite

    LD     C, A
    PUSH HL
    LD A, 12
    LD HL, Sprite_Width
    SUB (HL)
    LD D,0
    LD E, A
    POP HL   
   
_RowLoopOverwrite:

    PUSH   BC
   
    ;Stores width into B, which will be decreased 1 by 1 until one row is complete
    LD A, (Sprite_Width)
    LD B, A
   

_ColumnLoopOverwrite:
    PUSH BC
       
    LD     B, C
    LD     C, (IX)
    XOR    A

_ShiftLoopOverwrite:
    SRL    C
    RRA
 
    DJNZ   _ShiftLoopOverwrite
 

    INC    HL
 
    LD     (HL), A

    DEC    HL
    LD     A, C

    LD     (HL), A

    POP BC
    INC HL
    INC IX
 
    DJNZ _ColumnLoopOverwrite
   
    ADD    HL, DE
   
    POP    BC
    DJNZ   _RowLoopOverwrite
   
    RET

_AlignedOverwrite:
   
    PUSH HL
    LD A, 12
    LD HL, Sprite_Width
    SUB (HL)
    LD D,0
    LD E, A
    POP HL 
     
_PutLoopOverwrite:
    PUSH BC
    LD A, (Sprite_Width)
    LD B, A

_PutLoopOverwrite2:
   
    LD     A, (IX)
   
    LD     (HL), A
    INC  IX
 
    INC HL
    DJNZ _PutLoopOverwrite2
_PutLoopOverwriteAdd:
    POP BC
   
    ;ADD    HL, DE
    ;DJNZ _PutLoop
 ADD HL, DE
 DJNZ _PutLoopOverwrite
 RET

What do I plug in for "xor b, and c, xor b"?

SirCmpwn

  • Guest
Re: Drawing an overwrite black/white sprite
« Reply #4 on: October 23, 2010, 02:46:42 pm »
This should just work with overwrite routine, shouldn't it?