Page 2 of 2

Re: A Simple NES Game

Posted: Tue Apr 23, 2013 10:42 am
by Falco Girgis
Hell yeah! I'd hit it! :mrgreen:

Re: A Simple NES Game

Posted: Mon Aug 04, 2014 10:46 pm
by Light-Dark
EDIT: Here's a video of it in action



Adding on to the sine-wave like movement pattern discussion in this thread:

There is in fact a way to create a more precise replica of a sinusoidal curve on the NES through the use of a lookup table in ROM. This is how I've gone about generating a smooth curve for ai movemnt in my new platformer engine:
void Generate_Table(){
    int i;
    float angle = 0.0;
    for(i = 0;i <256;i++){
        table = ((sin(angle)*127.0)+128.0);
        printf("8bit value:%i\n",table);
        angle += 0.125;
    }
}


Here is how I use it in my NES engine:
;SOMEWHERE IN ROM
sine:
   .incbin "sinetable.bin" ; 256 byte binary file consisting of the generated sine table

And here is how the table is used

Code: Select all

Sine_Wave:
	ldy #$05					;Set xVel to 3
	lda #$03
	sta (AI_PTR),y
	ldy #$08
	lda (AI_PTR),y				; action frame
	tax						
	lda sine,x					; do sine table lookup
	lsr							; divide  by 2 to compress the arc size
    sta Test					; temporary test variable
	clc							
	adc #$40					; add a decent y offset
	ldy #$00					
	sta (AI_PTR),y				; save it to the Y-position of AI

	ldy #$08					; reload action frame 
	lda (AI_PTR),y				; ^ I know this seems inefficient lol
	tax						
	inx							; increment it
	txa
	sta (AI_PTR),y				; save it back
	jmp AI_ActionDone			; exit from the jumptable routine