# Sprite to Bitmap

Página 1/3
| 2 | 3

Can someone post some code.

Say I make a pattern bitmap of 768 bytes in memory

Map
db 20,10,20,30,40----
0-31
.....
23......

Of course each one corresponds to a pattern in the pattern table

Well if I give the y and x position of the sprite I need the tile that is at that y and x position.

This is what I use to get it from VRAM but I want to move away from that and grab it directly from a pointer.
This will save on resources and speed up access

LD A, (PLAYER_Y)
AND \$F8
LD H, 0
LD L, A
LD DE, \$1800
LD A, (PLAYER_X)
SRL A
SRL A
SRL A
OR L
LD L, A

DI
LD A,L
OUT (98h),A
LD A,H
AND 3FH
OUT (99h),A
EI

IN A, (98h)

I know L gives 0-255 and H will return 0, 1 or 2

If someone has already figured out the math then please post this.
Someone else gave me this formula so I am lost on such things.

TIA

Login sesión o register para postear comentarios

your question is unclear: what do you need?
do you need to get the vram addr of the tile at a given x,y position?
or whatever?

No..
I have a screen table I can send directly to VRAM that displays the screen.

I want to parse the table while it is in Ram or ROM, NOT VRAM

So if the table name is
DANNY:
and Danny is 0-767 positions
I want to give it my y/x position of my sprite and have it return which value is at DANNY+???

So after I divide y/8+x I should get a value I can add to Danny: and get whatever data is in that position.

So if y/x of my sprite equals to position 730 in the table and 48 is at position 730 then it should return 48

The routine I provided will grab from VRAM but I need it to grab from a Table in Ram or Rom.

I know I am over explaining it but somehow I did not get that across the first time.
Maybe my English is off but I am learning.

you mean you want a collision detection between a sprite and a tile in the nametable, so you know wich tile is in that position...

this routine isn't mine (but I use it a lot). It is a jltursan routine I found time ago on Karoshi forum

```	ld	hl,sat+1				;point to player (sprite 0) xpos
ld	e,(hl)					;xpos in E
ld	l,0					;point to player ypos
ld	d,(hl)					;ypos in D
ld	a,d					;ypos in A
and	0F8h
ld	h,0
ld	l,a
ld	a,e					;xpos in A
and	0F8h
rrca
rrca
rrca						; X/8
ld	l,a
sub	l
ld	h,a					;hl=(x/8)+(y/8)*32
ld 	de,video_buffer				;video_buffer start address in DE
ld	a,(hl)					;check actual position content
```

obviously sat is128 bytes buffer and its address is aligned aligned (forgot to tell it before)
video buffer is 768 bytes buffer in RAM

Take a look at `COORDS_TO_OFFSET` and `OFFSET_TO_COORDS` in https://github.com/theNestruo/msx-msxlib/blob/master/lib/gam...

After I rewrote the routine it looks like it works but if something is off please let me know.

LD A, (PLAYER_Y) ; POINT TO PLAYER YPOS
AND \$F8
LD H, 0
LD L, A

LD A, (PLAYER_X) ; POINT TO PLAYER (SPRITE 0) XPOS
AND \$F8
RRCA
RRCA
RRCA ; X/8
LD L, A
SUB L
LD H, A ; HL=(X/8)+(Y/8)*32

LD DE, PLAYFIELD ; VIDEO_BUFFER START ADDRESS IN DE
LD A, (HL) ; CHECK ACTUAL POSITION CONTENT

Chilly Willy wrote:

SUB L

Clever .

This is what Konami used:
(buffer must be aligned)

```; In: HL = XY
; Out: HL = Pointer to buffer

ld	    a, l
rra
rra
rra
rra
rr	    h
rra
rr	    h
rra
rr	    h
ld	    l, h
and	    3
ld	    h, a
```
Grauw wrote:
Chilly Willy wrote:

SUB L

Clever .

Yes, I also used this clever ADD HL,A operation a few times myself.
But I found out it is quicker to do :