It is currently Fri Jun 22, 2018 2:13 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 33 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
PostPosted: Thu Jun 07, 2018 7:05 am 
Offline
User avatar

Joined: Fri Nov 19, 2004 7:35 pm
Posts: 4051
Just remember NNyyyyyxxxxx, and you're good.

_________________
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!


Top
 Profile  
 
PostPosted: Thu Jun 07, 2018 7:17 am 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 2092
Location: DIGDUG
And you might have to add 1 or 2 to the sprite's y before converting to nametable address, to get it to visually line up. Otherwise the block might disappear when the Sprite is still 1 pixel away.

_________________
nesdoug.com -- blog/tutorial on programming for the NES


Top
 Profile  
 
PostPosted: Thu Jun 07, 2018 10:39 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10522
Location: Rio de Janeiro - Brazil
You shouldn't be converting sprite coordinates into NT addresses directly, though... The "correct" thing to do would be to run the game logic in "game world space", a space that contains all your game objects and doesn't care about sprite evaluation delays or scrolling, and convert coordinatrs from that space into sprite space or NT addresses when needed.

Some simpler games (single screen without scrolling) do end up unifying all these spaces to simplify things, and will even set the scroll to -1 (i.e. 239 or 255) to push the background 1 pixel down so it'll align with sprite coordinates, eliminating the need to compensate for that 1 scanline delay that sprites have.


Top
 Profile  
 
PostPosted: Thu Jun 07, 2018 10:56 am 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 2092
Location: DIGDUG
Quote:
You shouldn't be converting sprite coordinates into NT addresses directly


Yes he should. He needs to change a tile. That requires an address.

EDIT, and I always forget about setting Y scroll to -1. I remember that Shiru's example game Chase sets the X scroll to 4 (on a transition screen) so that text is exactly lined up to the middle of the screen. Another thing I frequently forget is possible.

_________________
nesdoug.com -- blog/tutorial on programming for the NES


Top
 Profile  
 
PostPosted: Thu Jun 07, 2018 2:01 pm 
Offline
User avatar

Joined: Thu Jul 23, 2015 7:54 pm
Posts: 180
Location: USA
[quote="dougeff”]Yes he should. He needs to change a tile. That requires an address.[/quote]
You wanna treat the ball as an object with a hitbox though; not as a sprite.

A full-fledged metasprite system probably isn’t necessary for this game. Kikutano, you could probably get by with just having variables for the ball’s X and Y, as well as the X and Y for the hitbox. In the ball’s code you’d just update both one after the other. This way you can check for collisions on all the corners. Then after the ball’s done running, you can have a simple routine that just stores the ball’s X and Y coordinates into the OAM shadow. You can even subtract 1 from the ball’s Y position to fix the scanline offset problem people were talking about.

Code:
DrawBall:
  lda ball_x
  sta $0203
  lda ball_y
  sec
  sbc #1   ;account for the 1 scanline delay for sprite rendering
  sta $0200
  rts

Directly working with OAM like this is bad practice for an actual game, but at the same time it’s good practice to separate “object code” from “drawing code”.

Edit: BBcode isnt working for some reason. Maybe it’s something I did.


Last edited by Sogona on Thu Jun 07, 2018 2:32 pm, edited 2 times in total.

Top
 Profile  
 
PostPosted: Thu Jun 07, 2018 2:19 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20165
Location: NE Indiana, USA (NTSC)
Might you have put a checkmark in [ ] Disable BBCode next to Options: below that post?


Top
 Profile  
 
PostPosted: Thu Jun 07, 2018 2:31 pm 
Offline
User avatar

Joined: Thu Jul 23, 2015 7:54 pm
Posts: 180
Location: USA
Maybe :wink:


Top
 Profile  
 
PostPosted: Thu Jun 07, 2018 4:28 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10522
Location: Rio de Janeiro - Brazil
dougeff wrote:
Yes he should. He needs to change a tile. That requires an address.

What I meant is that, ideally, he shouldn't be converting sprite coordinates in order to get that address. Positions, collisions, etc. should normally be processed in world space, and that's what you'd convert to other spaces (sprite, NT) as necessary.


Top
 Profile  
 
PostPosted: Thu Jun 07, 2018 6:47 pm 
Offline
User avatar

Joined: Sat Feb 16, 2013 11:52 am
Posts: 283
Coordinate space translation reminds me a lot of working with OpenGL shaders.

Anyway, for a single screen game like his, the translation matrix from world to screen space is simply [{1,0,0},{0,1,-1},{0,0,1}], ie. simply decreasing the Y coordinates of all sprites by 1 when writing the OAM table should be fine. The only relevant coord translation he should be doing right now is playfield space to/from screen space, unless he plans to add multi-screen playfields to the game which would be something incredibly stupid for Arkanoid.

I know you guys like to go deep into discussing things and this is mostly a strength of this forum, but right now discussing metasprite systems, world coordinates, etc. will only confuse him in a simple game concept which only needs basic collision detection and video RAM writes.

_________________
This is a block of text that can be added to posts you make. There is a 255 character limit.


Top
 Profile  
 
PostPosted: Fri Jun 08, 2018 12:38 am 
Offline

Joined: Sat May 26, 2018 6:14 am
Posts: 13
Location: Italy
I'm reading! :mrgreen: I hope to implement the collision detection with the background this weekend and I will update you. Thanks for all suggests! :) I will release the source code on Github when I finish the project. Now I'm reading the code from BrickBreaker to steal some idea :).


Top
 Profile  
 
PostPosted: Sat Jun 09, 2018 3:41 am 
Offline

Joined: Sat May 26, 2018 6:14 am
Posts: 13
Location: Italy
What's the best way to do the division in ASM 6052? I can't find any instructions, just ADC and SBC.


Top
 Profile  
 
PostPosted: Sat Jun 09, 2018 5:39 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10522
Location: Rio de Janeiro - Brazil
You have to code division routines yourself, the 6502 doesn't know how to do divisions or multiplications. Here's a page with tons of math routines: http://codebase64.org/doku.php?id=base:6502_6510_maths

You want to keep divisions and multiplications to a minimum in 6502 programs, since they're pretty slow compared to addition and subtraction.


Top
 Profile  
 
PostPosted: Sat Jun 09, 2018 6:13 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20165
Location: NE Indiana, USA (NTSC)
There are 8x8 bit multiplication and 0.8/0.8 bit division routines in math.s of Thwaite. This is targeted mostly at calculating slopes as part of an arctangent routine.

There are 16x16 bit multiplication and 32/16 bit division routines in muldiv.s of 240p Test Suite, used in the Overclock activity.

There are various multiplication and divisions in the hardware-independent portion of cc65's runtime library.

But for collision with elements of a matrix whose sizes are powers of 2, such as translating pixel positions into which brick was hit in a Breakout clone, you'll probably need only division by powers of 2. To divide A by 2, use the LSR A instruction, which is much faster than the above generic dividers. To divide by larger powers of 2, use more shifts. To divide by 4, shift twice; by 8, thrice; and so on.


Top
 Profile  
 
PostPosted: Sat Jun 09, 2018 6:42 am 
Offline

Joined: Sat May 26, 2018 6:14 am
Posts: 13
Location: Italy
tepples wrote:
There are 8x8 bit multiplication and 0.8/0.8 bit division routines in math.s of Thwaite. This is targeted mostly at calculating slopes as part of an arctangent routine.

There are 16x16 bit multiplication and 32/16 bit division routines in muldiv.s of 240p Test Suite, used in the Overclock activity.

There are various multiplication and divisions in the hardware-independent portion of cc65's runtime library.

But for collision with elements of a matrix whose sizes are powers of 2, such as translating pixel positions into which brick was hit in a Breakout clone, you'll probably need only division by powers of 2. To divide A by 2, use the LSR A instruction, which is much faster than the above generic dividers. To divide by larger powers of 2, use more shifts. To divide by 4, shift twice; by 8, thrice; and so on.


Yeah, I need to divide by 16 so I can do something like this:

Code:

  LSR A
   LSR A
   LSR A
   LSR A ;Divide by 16



Top
 Profile  
 
PostPosted: Sat Jun 09, 2018 6:49 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20165
Location: NE Indiana, USA (NTSC)
Yes. You're getting the hang of it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 33 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group