Hello there everyone
Okay, just a heads up. I haven't been coding for the nes for very long so I'm pretty clueless about most the technical stuff about it.
A while back I started on my first NES game, which I put together using NBasic and Nesasm. I modified Nespaint and the famitracker sound driver to work with the project. Everything was working smoothly until I encountered a problem with the background tiles and random variables changing by themselfes whenever there is a lot happening in the game at once. I have already put all the $2006 $2007 writes in a buffer that is written during the VBlank NMI and all the sprites are drawn to a shadow OAM. I have tried just about everything to get the variables not to get corrupted, like I tried turning off the rendering and waiting for the VBlank flag in the main game loop instead of in the NMI, and that didn't help either.
Here is the most importent sections of the program.
I'd be most grateful if someone had any idea what could be causing this. I'm just about ready to give up on this project by now.
You can download the NES file plus source at http://hamsterworld.no-ip.info/mygame.rar. If you test it, try blowing up as many blocks as quickly as possible. Also, I haven't tried troubleshooting the game in any other emulator than nestopia.
![Very Happy :D](./images/smilies/icon_biggrin.gif)
Okay, just a heads up. I haven't been coding for the nes for very long so I'm pretty clueless about most the technical stuff about it.
A while back I started on my first NES game, which I put together using NBasic and Nesasm. I modified Nespaint and the famitracker sound driver to work with the project. Everything was working smoothly until I encountered a problem with the background tiles and random variables changing by themselfes whenever there is a lot happening in the game at once. I have already put all the $2006 $2007 writes in a buffer that is written during the VBlank NMI and all the sprites are drawn to a shadow OAM. I have tried just about everything to get the variables not to get corrupted, like I tried turning off the rendering and waiting for the VBlank flag in the main game loop instead of in the NMI, and that didn't help either.
Here is the most importent sections of the program.
Code:
//set buffer value
set_buffer_value:
if next_buffer_index > 250 return
set [background_draw_buffer next_buffer_index] first_value
inc next_buffer_index
set [background_draw_buffer next_buffer_index] second_value
inc next_buffer_index
set [background_draw_buffer next_buffer_index] ppu_value
inc next_buffer_index
return
//ingame loop
ingame_loop:
//update joysticks
gosub joystick1
gosub joystick2
//handle units
gosub handle_units
after_unit_handle:
//handle level blocks
gosub handle_blocks
after_block_handle:
//set the can draw flag
set waiting_for_vblank_flag 1
set can_draw_flag 1
//wait for the vblank flag
wait_for_vblank_loop:
if waiting_for_vblank_flag = 1 goto wait_for_vblank_loop
//gosub handle_sound
goto ingame_loop
//ingame nmi loop
ingame_nmi_loop:
//check if can draw flag is true
if can_draw_flag = 0 goto cant_draw_yet
set can_draw_flag 0
//set the ppu to not render anything
set $2001 0
//set sprite dma
set SPRITE_DMA 5
//draw the buffer
if next_buffer_index < 3 goto stop_buffer_loop
set x 0
draw_buffer_loop:
set $2006 [background_draw_buffer x]
inc x
set $2006 [background_draw_buffer x]
inc x
set $2007 [background_draw_buffer x]
inc x
//set $2006 [background_draw_buffer x]
//inc x
//set $2006 [background_draw_buffer x]
//inc x
//set $2007 [background_draw_buffer x]
//inc x
//set $2006 [background_draw_buffer x]
//inc x
//set $2006 [background_draw_buffer x]
//inc x
//set $2007 [background_draw_buffer x]
//inc x
//set $2006 [background_draw_buffer x]
//inc x
//set $2006 [background_draw_buffer x]
//inc x
//set $2007 [background_draw_buffer x]
//inc x
if x < next_buffer_index goto draw_buffer_loop
set next_buffer_index 0
stop_buffer_loop:
//set scroll
set $2005 0
set $2005 248
//clear the waiting for vblank flag
set waiting_for_vblank_flag 0
//set the ppu to render everything
set $2000 %10010000
set $2001 level_ppu
//can't draw yet label
cant_draw_yet:
//rti
asmline rti
set_buffer_value:
if next_buffer_index > 250 return
set [background_draw_buffer next_buffer_index] first_value
inc next_buffer_index
set [background_draw_buffer next_buffer_index] second_value
inc next_buffer_index
set [background_draw_buffer next_buffer_index] ppu_value
inc next_buffer_index
return
//ingame loop
ingame_loop:
//update joysticks
gosub joystick1
gosub joystick2
//handle units
gosub handle_units
after_unit_handle:
//handle level blocks
gosub handle_blocks
after_block_handle:
//set the can draw flag
set waiting_for_vblank_flag 1
set can_draw_flag 1
//wait for the vblank flag
wait_for_vblank_loop:
if waiting_for_vblank_flag = 1 goto wait_for_vblank_loop
//gosub handle_sound
goto ingame_loop
//ingame nmi loop
ingame_nmi_loop:
//check if can draw flag is true
if can_draw_flag = 0 goto cant_draw_yet
set can_draw_flag 0
//set the ppu to not render anything
set $2001 0
//set sprite dma
set SPRITE_DMA 5
//draw the buffer
if next_buffer_index < 3 goto stop_buffer_loop
set x 0
draw_buffer_loop:
set $2006 [background_draw_buffer x]
inc x
set $2006 [background_draw_buffer x]
inc x
set $2007 [background_draw_buffer x]
inc x
//set $2006 [background_draw_buffer x]
//inc x
//set $2006 [background_draw_buffer x]
//inc x
//set $2007 [background_draw_buffer x]
//inc x
//set $2006 [background_draw_buffer x]
//inc x
//set $2006 [background_draw_buffer x]
//inc x
//set $2007 [background_draw_buffer x]
//inc x
//set $2006 [background_draw_buffer x]
//inc x
//set $2006 [background_draw_buffer x]
//inc x
//set $2007 [background_draw_buffer x]
//inc x
if x < next_buffer_index goto draw_buffer_loop
set next_buffer_index 0
stop_buffer_loop:
//set scroll
set $2005 0
set $2005 248
//clear the waiting for vblank flag
set waiting_for_vblank_flag 0
//set the ppu to render everything
set $2000 %10010000
set $2001 level_ppu
//can't draw yet label
cant_draw_yet:
//rti
asmline rti
I'd be most grateful if someone had any idea what could be causing this. I'm just about ready to give up on this project by now.
You can download the NES file plus source at http://hamsterworld.no-ip.info/mygame.rar. If you test it, try blowing up as many blocks as quickly as possible. Also, I haven't tried troubleshooting the game in any other emulator than nestopia.