Author |
Message |
|
Tyler
Advanced Member
Joined: 29 May 2003 Posts: 352
|
Posted: 13 Aug 2003 08:13:38 pm Post subject: |
|
|
I've been looking a sprite coding to figure out why on earth people multiply things by 128, and what does all that stuff do, can someone explain in detail about sprite placement, what all that multiplying does, and how to get the binary (.db %0000...) to display as dots on the screen, I'm sorta trying to make one but without this information I won't be able to. Any help would be greatly appreciated! |
|
Back to top |
|
|
Adm.Wiggin aka Tianon
Know-It-All
Joined: 02 Jun 2003 Posts: 1874
|
Posted: 13 Aug 2003 10:01:57 pm Post subject: |
|
|
well, the binary is definatly the easy part... just like this :
.db %10101010
will be a dotted line... get it?
to put an aligned sprite, u could just put it in the correct place in the plotsscreen... if u wanted that is... |
|
Back to top |
|
|
John Barrus
Member
Joined: 25 May 2003 Posts: 131
|
Posted: 13 Aug 2003 10:27:50 pm Post subject: |
|
|
Please paste code, there are many things that multiplying can do regarding sprites. |
|
Back to top |
|
|
Tyler
Advanced Member
Joined: 29 May 2003 Posts: 352
|
Posted: 14 Aug 2003 07:36:56 am Post subject: |
|
|
Alright, here's a sample that Justin gave to me a few posts back-
And BTW Adm Wiggin, that's my problem, I don't understand the plotsScreen and its alighments and all that stuff, it confuses me like crazy!
Code: ld a,2 ;X=2
ld l,2 ;Y=2
ld ix,mouse1 ;Pointer
ld e,l ;E=X (E=2) ;He needs HL, so hes copying to other registers
ld h,0 ;H=0 ;But why not just put the Y coord in e to begin with?
ld d,h ;D=0
add hl,de ;02+02 = 4
add hl,de ;04+04 = 8
add hl,hl ;08+08 = 16
add hl,hl ;16+16 = 32
ld e,a ;e = 32
add hl,de ;32+04=36 or is it 32+32? //Confused Area
ld de,plotsscreen; Not why would he want to load 4 into the plotsscreen? //Confused Area
add hl,de //Confused Area
ld b,8 ;B=8
put8by8loop:
ld a,(ix) //Confused Area
xor (hl) //Confused Area
ld (hl),a //Confused Area...
inc ix
ld de,12
add hl,de
djnz put8by8loop //End of Confused Area
bcall(_grbufcpy) //Copy grBuf to plotsScreen
bcall(_getKey) //Wait for keypress
ret;Exit program //End
mouse1:
.db %10000000
.db %11100000
.db %11111000
.db %11111100
.db %11111110
.db %00010000
.db %00011000
.db %00001000
.end
Last edited by Guest on 14 Aug 2003 07:38:54 am; edited 1 time in total |
|
Back to top |
|
|
Shoester
Newbie
Joined: 02 Jun 2003 Posts: 8
|
Posted: 16 Aug 2003 10:05:55 pm Post subject: |
|
|
Ok i'm going to try and explain sprites as best i can.
First off you need to understand that the plotsscreen is just a long list of numbers that are copyed to the ram in the lcd driver. Each byte is a peice of the screen that is 1 row *8 columns big. So if you were to load %11111111 into the first byte of the plotsscreen there would be a line starting from {0,0} and going to {0,7}. Now since there are 96 pixels going across the screen there are 12 bytes on each "row" (96 / 8 bits), 64 different "rows" of bytes, and 768 bytes altogether (12 * 64).
Now that you understand how the plotsscreen works, i'll tell you how to find the location of the sprite. First you should calculate the y cord. So think, since the plotsscreen is just a long list of bytes and each row is 12 bytes across, the byte right below you should be the 12th byte (if you start with 0), and the next would be 24, 36, 48, and so on. So to calculate the y cord you just need to multiply the y by 12. Now for the x cord i'm just going to explain how to do it for alinged sprite. So you need to divide the x cord by 8 because you need to find what BYTE the sprite starts at and there are 8 bits in a byte. You add what you got from the x cord to what you got from the y cord to the starting point of the plotsscreen (which should be defined in your include as plotsscrean or gbuf) and you have the starting location for your sprite!
Now you can actually start blitting the sprite onto the plotsscreen. It's fairly simple really. You just have a loop that goes around 8 times (or however tall your sprite is) which does the following:
1. It lds the sprite data and the byte which is currently at that location in the plotsscreen
2. It XORs (or ORs or ANDs) those two bytes together
3. It lds the result of that back into the plotsscreen
4. It increments the pointer of the sprite data and adds 12 (moves down 1 row) to the pointer to the plotssceen
Now you can use ionFastCopy to copy the plotsscreen to the lcd driver and the sprite will appear onscreen.
You should, if you understood all that i said, be able to make an aligned sprite routine now. If you didn't understand or want to know about unaligned sprites, clipping, or masking just ask. |
|
Back to top |
|
|
Justin W. Shattered Silence
Advanced Member
Joined: 24 May 2003 Posts: 429
|
Posted: 17 Aug 2003 12:27:53 am Post subject: |
|
|
ld a,2 ;X=2
ld l,2 ;Y=2
ld ix,mouse1 ;Pointer
ld e,l ;E=X (E=2) ;He needs HL, so hes copying to other registers
ld h,0 ;H=0 ;But why not just put the Y coord in e to begin with?
ld d,h ;D=0
add hl,de ;02+02 = 4
add hl,de ;04+04 = 8
add hl,hl ;08+08 = 16
add hl,hl ;16+16 = 32
ld e,a ;e now = x coord
add hl,de ;d is 0 so add hl and de together to get offset in buffer
ld de,plotsscreen; load address of plotsscreen into de
add hl,de ; add offset to the plotsscreen and store it in hl
ld b,8 ;number of executions it = 8 (8 pixels high)
ld de,12 ;ld de with 12 bytes
put8by8loop:
ld a,(ix) ;load a with the byte from the pointer (ix)
xor (hl) ;xor it with buffer offset
ld (hl),a ; load product of xoring back into the buffer
inc ix ;move to the next byte of the sprite
add hl,de ; add the 12 bytes (#from de) to the offset to move to the next row of the plotsscreen directly under the previous position
djnz put8by8loop ;if b doesn't = 0 go back and repeat above code.
bcall(_grbufcpy) //Copy grBuf to plotsScreen
bcall(_getKey) //Wait for keypress
ret;Exit program //End
mouse1:
.db %10000000
.db %11100000
.db %11111000
.db %11111100
.db %11111110
.db %00010000
.db %00011000
.db %00001000
.end
Hope that explains it a little better. |
|
Back to top |
|
|
JacobdeHaan
Member
Joined: 10 Jul 2003 Posts: 165
|
Posted: 17 Aug 2003 12:51:12 am Post subject: |
|
|
Thanks for the explanation Justin, the only thing I think I still don't understand is what the offset is. (is that the x,y vars?) |
|
Back to top |
|
|
John Barrus
Member
Joined: 25 May 2003 Posts: 131
|
Posted: 17 Aug 2003 07:06:39 pm Post subject: |
|
|
plotsscreen+offset=place in plotsscreen ram to start drawing |
|
Back to top |
|
|
Justin W. Shattered Silence
Advanced Member
Joined: 24 May 2003 Posts: 429
|
Posted: 17 Aug 2003 08:32:34 pm Post subject: |
|
|
((Y coord*buffer width)+X coord)=offset
the buffer is 12 bytes wide.
plottscreen+offset=byte to start reading/writing from/to
Last edited by Guest on 17 Aug 2003 08:33:37 pm; edited 1 time in total |
|
Back to top |
|
|
JacobdeHaan
Member
Joined: 10 Jul 2003 Posts: 165
|
Posted: 18 Aug 2003 09:37:40 pm Post subject: |
|
|
Thanks guys, this is a sprite routine I think I actually understand, so now I should be able to make my first ASM game. |
|
Back to top |
|
|
tr1p1ea
Elite
Joined: 03 Aug 2003 Posts: 870
|
Posted: 19 Aug 2003 11:20:05 pm Post subject: |
|
|
shouldnt this:
add hl,de ;02+02 = 4
add hl,de ;04+04 = 8
add hl,hl ;08+08 = 16
add hl,hl ;16+16 = 32
be this:
add hl,de ;02+02 = 4
add hl,de ;04+02 = 6
add hl,hl ;06+06 = 12
add hl,hl ;12+12 = 24
?
Last edited by Guest on 19 Aug 2003 11:22:46 pm; edited 1 time in total |
|
Back to top |
|
|
JacobdeHaan
Member
Joined: 10 Jul 2003 Posts: 165
|
Posted: 19 Aug 2003 11:59:36 pm Post subject: |
|
|
I agree, that looks better. |
|
Back to top |
|
|
Tyler
Advanced Member
Joined: 29 May 2003 Posts: 352
|
Posted: 20 Aug 2003 09:40:57 am Post subject: |
|
|
I'm so good at math
Thanks for the help, I think I completely understand what all of that nonsense is doing now! |
|
Back to top |
|
|
|