Page 2 of 2

Re: Pong tutorial failure

Posted: Fri Aug 10, 2012 3:06 pm
by tepples
The solution that 3gengames gave works, and I use it in my own games. But it'll run into flicker problems once you start doing raster effects, such as scrolling with a still status bar.

Re: Pong tutorial failure

Posted: Sat Aug 11, 2012 9:02 am
by tokumaru
That is indeed the most straightforward way to make use of NMIs, but like tepples said, it might screw up raster effects (i.e. mid-screen changes to the scroll, palettes, etc.) in case your frame logic takes longer than the time of a NES frame (in most games that happens only when lots of objects are active at the same time). If you are sure your frame calculations will never take too long to finish (usually the case of most puzzle games and games with little variation in the number of on-screen objects), that NMI solution is safe to use.

Re: Pong tutorial failure

Posted: Sat Aug 11, 2012 3:38 pm
by Movax12
This isn't hard to change is it? You could have the NMI routine take care of screen updates and split screen and exit and return to the selected engine with the same basic structure. I'm actually working on this right now. This may be a bit much for the OP (not really that complex) but I use something like this:

Code: Select all

main_jump_vector:     .res 3 ; 3 bytes for jmp (lo)(hi)

.proc reset

  standard_init     ;video + sound is off
	
  set_new_engine_state state_titlescreen     ; initial gamecode pointer
	
  set_PPU_CTRL CR_NMI,1     ; Turn on NMI before MainLoop, never turn it off (video still off)
	
  Mainloop: 

	: bit NMIhit		; Wait for a  
	bpl :-			; NMI to occur
	clrflag NMIhit 	; before proceeding
		
	jsr main_jump_vector
		
 jmp Mainloop ;} 
	
	
.endproc

; -----------------------------------------------

.proc	state_titlescreen
	[do stuff, then:]
	set_new_engine_state state_readyscreen
	rts
.endproc

.proc	state_readyscreen
	[do stuff, then:]
	set_new_engine_state state_gameplay
	rts
.endproc


.proc	state_gameplay
	[do stuff, then:]	
	set_new_engine_state state_gameover   
	rts
.endproc



.proc	state_gameover
        [do stuff, then:]	
	set_new_engine_state state_titlescreen
	rts
.endproc

;----------------------


.macro set_new_engine_state engine_state
	
	lda #_RTS_
	sta main_jump_vector
	lda #<(engine_state)
	sta main_jump_vector+1
	lda #>(engine_state)
	sta main_jump_vector+2
	lda #_JMP_
	sta main_jump_vector
	
.endmacro
I am working on it now, but I have decided that every engine should expect rendering to be off when started and should turn it off before changing to a new state - but no changes are made directly - nothing happens to the PPU side of the NES until NMI - it updates all changes based on flags marking data that is ready.