It is currently Sat Nov 18, 2017 3:28 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Tue Jul 25, 2017 6:01 am 
Offline

Joined: Tue Apr 11, 2006 4:08 am
Posts: 248
I would copy the X / Y coordinates to match the positions 8x8 on the BGR (NT PPU) screen. It is a similar method of placing an object on the screen as it is in Bomber Man. I managed to get a LO byte from a PPU address, but I have a problem with HI byte (20xx-23xx). It seemed to me more simple, but of course ...: /

Code:
   CLC
   LDA HERO_1_X         ;X
 
   LSR A
   LSR A
   LSR A

   STA BombX_Temp         ;jest ok, co 8pix daje wartosc o 1

   CLC
   LDA HERO_1_Y
   AND #%11111000
   STA BombY_Temp


   LDA BombY_Temp
   ADC BombX_Temp
   STA BOMB_PPU_TILE1_AddrLO
   CLC
   ADC #1
   STA BOMB_PPU_TILE2_AddrLO

   LDA BOMB_PPU_TILE1_AddrLO
   CLC
   ADC #$20
   STA BOMB_PPU_TILE3_AddrLO
   CLC
   ADC #1
   STA BOMB_PPU_TILE4_AddrLO


   LDA #$20         ;This HiByte is set manually to $ 20xx
   STA BOMB_PPU_TILE1_AddrHI
   STA BOMB_PPU_TILE2_AddrHI
   STA BOMB_PPU_TILE3_AddrHI
   STA BOMB_PPU_TILE4_AddrHI


Last edited by sdm on Fri Jul 28, 2017 1:51 am, edited 1 time in total.

Top
 Profile  
 
PostPosted: Tue Jul 25, 2017 8:53 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10112
Location: Rio de Janeiro - Brazil
You mean you want to convert pixel coordinates into NT addresses? Just look at the bits:

X: XXXXX***
Y: YYYYY***
NT address: 0010NNYY YYYXXXXX

All you have to do is a little bit shifting, ANDing and ORing to get the bits where they need to be.

Code:
  lda #%00001000 ;base value for $2000 (change lower 2 bits for other NTs)
  sta addrhi
  lda ycoord
  and #%11111000
  asl
  rol addrhi
  asl
  rol addrhi
  sta addrlo
  lda xcoord
  lsr
  lsr
  lsr
  ora addrlo
  sta addrlo


Top
 Profile  
 
PostPosted: Tue Jul 25, 2017 12:23 pm 
Offline

Joined: Tue Apr 11, 2006 4:08 am
Posts: 248
Thanks, now works as I wanted. :)


Code:
   lda #%00001000         ;base value for $2000 (change lower 2 bits for other NTs)
   sta BOMB_PPU_TILE1_AddrHI
   lda HERO_1_Y
   clc
   adc #7            ;"centering"
   and #%11110000         ;y bomb in steps of 16pix
   asl A
   rol BOMB_PPU_TILE1_AddrHI
   asl A
   rol BOMB_PPU_TILE1_AddrHI
   sta BOMB_PPU_TILE1_AddrLO
   lda HERO_1_X
   clc
   adc #7            ;"centering"
   and #%11110000         ;x bomb in steps of 16pix
   lsr A
   lsr A
   lsr A
   ora BOMB_PPU_TILE1_AddrLO
   sta BOMB_PPU_TILE1_AddrLO
   clc
   adc #1
   sta BOMB_PPU_TILE2_AddrLO
   clc
   adc #$1F
   sta BOMB_PPU_TILE3_AddrLO
   clc
   adc #1
   sta BOMB_PPU_TILE4_AddrLO



I would still need a method of calculating the PPU address of the tiles to the X / Y coordinate of the sprite. :( I need this to determine the X / Y co-ordinates of a collision during a bomb explosion. Unfortunately, I was not able to simply copy the X / Y of the SPRITE position at the moment the bomb is placed, which is not set to the SPRITE position accuracy (the bomb is set to 16 pixels "step")

I'm trying to create a logical pattern, but of course I'm not going to take it in the code:

X 00,10,20,30,40,50,60,70,80,90,A0,B0,C0,D0,E0,F0
Y 00,10,20,30,40,50,60,70,80,90,A0,B0,C0,D0,E0 (sbc #1)

2000=X00/Y00
2002=X10/Y00
2004=X20/Y00
2006=X30/Y00
(...)

2000=X00/Y00
2040=X00/Y10 (Y sbc #1)
2080=X00/Y20 (Y sbc #1)
20C0=X00/Y30 (Y sbc #1)
2100=X00/Y40 (Y sbc #1)
(...)

2042=X10/Y10 (Y sbc #1)
(...)


Attachments:
ppu2sprxy.png
ppu2sprxy.png [ 12.94 KiB | Viewed 630 times ]
bomb.nes [256.02 KiB]
Downloaded 31 times
Top
 Profile  
 
PostPosted: Wed Jul 26, 2017 9:26 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10112
Location: Rio de Janeiro - Brazil
I'm not sure I understand what you need... Do you want to convert the coordinates back to pixel precision in order to test for collisions against sprites?

Normally, a game engine would not be doing this kind of conversion back and forth, but instead maintaining all objects in "level space", not "sprite space" or "name table space", since sprites and name tables are just details about how your game world is presented to the player, and these details could change significant if for some reason you decide to port the game to another platform. The game's engine should be able to function independently from these details.

The idea is to keep everything in level/world space at all times so that objects can interact with each other and the level map without problems, and do any coordinate conversions one way only, for drawing the objects on screen.


Top
 Profile  
 
PostPosted: Wed Jul 26, 2017 11:23 am 
Offline

Joined: Tue Apr 11, 2006 4:08 am
Posts: 248
tokumaru wrote:
I'm not sure I understand what you need... Do you want to convert the coordinates back to pixel precision.


Yes exactly. PPU address, which is contained in the variables (when the bomb is placed on the screen):

BOMB_PPU_TILE1_AddrHI
BOMB_PPU_TILE1_AddrLO

That is the first (left / top) of the four BGR bomb tiles. Convert this address to match a similar sprite on the screen (exactly as pictured).
For example 21CA addres responds X50, Y70 of sprite position (6F - Considering that the Y position on the screen is not equal).

Generally speaking, a 16x16pix collision field (coordinates corresponding to the sprite position (x, y)) will be inserted on the screen where the
exactly bomb will be placed (16x16pix area)

Maybe it's hard for me to explain it, I hope you understand.


Top
 Profile  
 
PostPosted: Wed Jul 26, 2017 11:43 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19222
Location: NE Indiana, USA (NTSC)
Instead of storing BOMB_PPU_TILE1_AddrHI and BOMB_PPU_TILE1_AddrLO, they're trying to recommend that you instead store the bomb's X and Y positions BOMB_X and BOMB_Y, and then convert those to BOMB_PPU_TILE1_AddrHI and BOMB_PPU_TILE1_AddrLO when updating the bomb's display.


Top
 Profile  
 
PostPosted: Wed Jul 26, 2017 11:49 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10112
Location: Rio de Janeiro - Brazil
You could just reverse the formula and account for the dimensions of the explosion, but like I said, I seriously advise against this. Explosions, after all, exist in the game world and interact with game entities, so there's no reason for them not to be game entities themselves.

Having one of your game objects represented exclusively as a set of NT addresses is a very hacky thing to do, because that information doesn't tell you directly where in the world the object is (hence why you need the conversion), only where in the screen it's drawn.

Keeping track of your objects always in level space is not only the professional thing to do, it's also easier to code and less error prone, since everything is unified and you don't have to constantly think of which space each thing lives in and do all sorts of space conversions to have them interact with each other.

Each object will have only one type of conversion, to translate its coordintes from level space to screen space so they can be displayed to the player. These conversions have to take into consideration whether the game objects are rendered using sprites or background, whether there's any scrolling, and whether there's anything shifting the gameplay window, such as status bars. No matter the type of conversion, they only go one way.


Top
 Profile  
 
PostPosted: Wed Jul 26, 2017 12:49 pm 
Offline

Joined: Tue Apr 11, 2006 4:08 am
Posts: 248
Thanks.
Ok I did it, it was even surprisingly simple:

Button A - place bomb
Button B - copy PPU addres to X/Y co-ord (For the test I gave the sprite)

Code:
   lda #%00001000         ;base value for $2000 (change lower 2 bits for other NTs)
   sta BOMB_PPU_TILE1_AddrHI
   lda HERO_1_Y
   clc
   adc #7            ;"centering"
   and #%11110000         ;y bomb in steps of 16pix
   sta BombY_Temp
   asl A
   rol BOMB_PPU_TILE1_AddrHI
   asl A
   rol BOMB_PPU_TILE1_AddrHI
   sta BOMB_PPU_TILE1_AddrLO
   lda HERO_1_X
   clc
   adc #7            ;"centering"
   and #%11110000         ;x bomb in steps of 16pix
   sta BombX_Temp
   lsr A
   lsr A
   lsr A
   ora BOMB_PPU_TILE1_AddrLO
   sta BOMB_PPU_TILE1_AddrLO
   clc
   adc #1
   sta BOMB_PPU_TILE2_AddrLO
   clc
   adc #$1F
   sta BOMB_PPU_TILE3_AddrLO
   clc
   adc #1
   sta BOMB_PPU_TILE4_AddrLO

   LDA BombY_Temp         ;1pix odejmij od Y
   SEC
   SBC #1
   STA BombY_Temp


Attachments:
demo.nes [256.02 KiB]
Downloaded 42 times


Last edited by sdm on Mon Nov 06, 2017 10:51 am, edited 1 time in total.
Top
 Profile  
 
PostPosted: Mon Nov 06, 2017 2:22 am 
Offline

Joined: Tue Apr 11, 2006 4:08 am
Posts: 248
Two more things which I have a problem:

1. The previous code works fine, but I would like to calculate the address of the currently set bomb in ATTRIBUTE TABLE - so that I could change the color palette for the place where I placed the bomb. Calculating a byte address does not seem to be difficult, HI byte is a constant # $ 23, LO byte calculated by. SpriteX / Y. However, one byte in LO is separate bits for four 16x16 grids and here is the biggest problem.


2. He's trying to animate the bomb tiles. Unfortunately, the method is poor and takes a lot of NMI time. How do you animate background elements (change BGR tiles numbers in VRAM) to minimize the VBLANK time (NMI)?

In CHR bank switch mappers it's easy to do (animations outside of VBLANK), but in UNROM I have a problem with that.

The code that is used for the animation:
I do not know how to do it properly, so any info very helpful.

Code:

;------------------------------------
Bomb_Anim_no:
   RTS
Bomb_Anim:      ;in NMI loop

   INC Bomb_Anim_Timer   ;timer
   INC Bomb_Anim_Timer
   INC Bomb_Anim_Timer
   INC Bomb_Anim_Timer

   LDA Bomb_Anim_Timer
   CMP #$00
   BCC BA_no1

   LDA BOMB_PPU_TILE1_AddrHI
   STA $2006
   LDA BOMB_PPU_TILE1_AddrLO
   STA $2006
   lda #$10         ;pattern table bgr tile1 nr.
   sta $2007
   LDA BOMB_PPU_TILE1_AddrHI
   STA $2006
   LDA BOMB_PPU_TILE2_AddrLO
   STA $2006
   lda #$11         ;pattern table bgr tile2 nr.
   sta $2007
   LDA BOMB_PPU_TILE1_AddrHI
   STA $2006
   LDA BOMB_PPU_TILE3_AddrLO
   STA $2006
   lda #$20         ;pattern table bgr tile3 nr.
   sta $2007
   LDA BOMB_PPU_TILE1_AddrHI
   STA $2006
   LDA BOMB_PPU_TILE4_AddrLO
   STA $2006
   lda #$21         ;pattern table bgr tile4 nr.
   sta $2007
   LDA #$00   ;reset screen
   STA $2006
   LDA #$00
   STA $2006

BA_no1:

   LDA Bomb_Anim_Timer
   CMP #$40
   BCC BA_no2

   LDA BOMB_PPU_TILE1_AddrHI
   STA $2006
   LDA BOMB_PPU_TILE1_AddrLO
   STA $2006
   lda #$12
   sta $2007
   LDA BOMB_PPU_TILE1_AddrHI
   STA $2006
   LDA BOMB_PPU_TILE2_AddrLO
   STA $2006
   lda #$13
   sta $2007
   LDA BOMB_PPU_TILE1_AddrHI
   STA $2006
   LDA BOMB_PPU_TILE3_AddrLO
   STA $2006
   lda #$22
   sta $2007
   LDA BOMB_PPU_TILE1_AddrHI
   STA $2006
   LDA BOMB_PPU_TILE4_AddrLO
   STA $2006
   lda #$23
   sta $2007
   LDA #$00
   STA $2006
   LDA #$00
   STA $2006

BA_no2:

   LDA Bomb_Anim_Timer
   CMP #$80
   BCC BA_no3

   LDA BOMB_PPU_TILE1_AddrHI
   STA $2006
   LDA BOMB_PPU_TILE1_AddrLO
   STA $2006
   lda #$14
   sta $2007
   LDA BOMB_PPU_TILE1_AddrHI
   STA $2006
   LDA BOMB_PPU_TILE2_AddrLO
   STA $2006
   lda #$15
   sta $2007
   LDA BOMB_PPU_TILE1_AddrHI
   STA $2006
   LDA BOMB_PPU_TILE3_AddrLO
   STA $2006
   lda #$24
   sta $2007
   LDA BOMB_PPU_TILE1_AddrHI
   STA $2006
   LDA BOMB_PPU_TILE4_AddrLO
   STA $2006
   lda #$25
   sta $2007
   LDA #$00
   STA $2006
   LDA #$00
   STA $2006

BA_no3:

   LDA Bomb_Anim_Timer
   CMP #$C0
   BCC BA_no4

   LDA BOMB_PPU_TILE1_AddrHI
   STA $2006
   LDA BOMB_PPU_TILE1_AddrLO
   STA $2006
   lda #$12
   sta $2007
   LDA BOMB_PPU_TILE1_AddrHI
   STA $2006
   LDA BOMB_PPU_TILE2_AddrLO
   STA $2006
   lda #$13
   sta $2007
   LDA BOMB_PPU_TILE1_AddrHI
   STA $2006
   LDA BOMB_PPU_TILE3_AddrLO
   STA $2006
   lda #$22
   sta $2007
   LDA BOMB_PPU_TILE1_AddrHI
   STA $2006
   LDA BOMB_PPU_TILE4_AddrLO
   STA $2006
   lda #$23
   sta $2007
   LDA #$00
   STA $2006
   LDA #$00
   STA $2006

BA_no4:
   RTS



Attachments:
demo1.nes [256.02 KiB]
Downloaded 12 times
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 7 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