NESDev and Strangulation Records messageboards
Forum Index | FAQ | New User | Login | Search

Previous ThreadView All ThreadsNext Thread*Show in Threaded Mode


SubjectNMI problems new  
Posted bybeneficii
Posted on7/17/03 04:54 AM
From IP68.18.219.125  



I know that this is something wrong with the NMI code, because if I put rti before all the rest of the nmi code, it works fine. Now with this code it cause blue and black flicker. I cannot find the problem:

nmi:
ldy #$01
sty $4016
dey
sty $4016
ldx #$08

read_buttons:
lda $4016
sta a.button, y
iny
dex
bne read_buttons

ensure_one:
lda #$01
and a.button, x
sta a.button, x
inx
dey
bne ensure_one

lda #$00
dec up.button
beq up
dec down.button
beq down
dec left.button
beq left
dec right.button
beq right
sta y.move
sta x.move
jmp obstructions

up:
sta x.move
lda #$f8
sta y.move
jmp obstructions

down:
sta x.move
lda #$08
sta y.move
jmp obstructions

left:
sta y.move
lda #$f8
sta x.move
jmp obstructions

right:
sta y.move
lda #$08
sta x.move

obstructions:
lda #$00
sta address_hi
lda x.pos
adc x.move
sta address_lo
lda y.pos
adc y.move
adc #004
sta temp
ldx #$03
ldy #$02

set_address_x:
lsr address_lo
dex
bne set_address_x

set_address_y:
asl temp
rol address_hi
dey
bne set_address_y

lda temp
ora address_lo
sta address_lo

clc
lda #low(mapdata)
adc address_lo
sta address_lo
lda #high(mapdata)
adc address_hi
sta address_hi

lda [address_lo], y
tax
dex
bne delete_move
jmp process

delete_move:
lda #$00
sta y.move
sta x.move

process:
clc
lda y.pos
adc y.move
sta y.pos
sta sprite.y
clc
lda x.pos
adc x.move
sta x.pos
sta sprite.x

jsr time

lda #$07
sta $4014

rti

time:
jsr eattime
jsr eattime
jsr eattime
jsr eattime
jsr eattime
jsr eattime
jsr eattime
jsr eattime
jsr eattime
jsr eattime
jsr eattime
jsr eattime
jsr eattime
jsr eattime
jsr eattime
jsr eattime
jsr eattime
jsr eattime
jsr eattime
jsr eattime
jsr eattime
jsr eattime
jsr eattime
jsr eattime
jsr eattime
jsr eattime
jsr eattime
jsr eattime
rts

eattime:
jsr timehog
jsr timehog
jsr timehog
jsr timehog
jsr timehog
jsr timehog
jsr timehog
jsr timehog
jsr timehog
jsr timehog
jsr timehog
jsr timehog
jsr timehog
jsr timehog
jsr timehog
jsr timehog
jsr timehog
jsr timehog
jsr timehog
jsr timehog
jsr timehog
jsr timehog
jsr timehog
jsr timehog
rts

timehog:
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
rts

If you can help me, then thanks. ^_^




SubjectRe: NMI problems new  
Posted bybeneficii
Posted on7/17/03 09:13 AM
From IP68.18.219.125  



I did some adjustments. The graphics appears fine when the RTI is not at the beginning of the NMI blocking the rest of the code. I did some tests, however, and now it seems that I can't even get the NMI to execute! Here's the code:

wait_vblank:
lda $2002
bpl wait_vblank
rts

wait_novblank:
lda $2002
bmi wait_novblank
rts

main:
sei
cld

ldx #$00

clearzp:
lda #$00
sta $00, x
inx
bne clearzp

dex
txs
ldx #$07
ldy #$01
lda #$00
sty address_hi
dey
sty address_lo

clearwram:
sta [address_lo], y
iny
bne clearwram
inc address_hi
dex
bne clearwram

jsr wait_vblank
jsr wait_novblank
jsr wait_vblank
jsr wait_novblank
jsr wait_vblank

lda #$00
sta $2000
sta $2001

ldy #$20
ldx #$3f
lda $2002
stx $2006
ldx #$00
stx $2006

loadpal:
lda paldata, x
sta $2007
inx
dey
bne loadpal

lda $2002
stx $2006
sty $2006

ldx #$08

clearppu:
lda #$00
sta $2007
iny
bne clearppu
dex
bne clearppu

jsr wait_vblank
jsr wait_novblank
jsr wait_vblank
jsr wait_novblank
jsr wait_vblank

ldx #$20
lda $2002
stx $2006
sty $2006
ldx #$04
lda #low(mapdata)
sta address_lo
lda #high(mapdata)
sta address_hi

loadmap:
lda [address_lo], y
sta $2007
iny
bne loadmap
inc address_hi
dex
bne loadmap

lda #212
sta y.pos
sta sprite.y
lda #016
sta x.pos
sta sprite.x
ldx #001
stx sprite.tile
dex
stx sprite.attributes

jsr wait_vblank
jsr wait_novblank
jsr wait_vblank
jsr wait_novblank
jsr wait_vblank

lda #$07
sta $4014

lda $2002
lda #%10001000
sta $2000
lda #%00011000
sta $2001

refresh:
jmp refresh

; tnx, ^_^




SubjectRe: NMI problems new  
Posted byWhoaMan
Posted on7/18/03 03:25 AM
From IP68.134.169.134  



is it set to execute the nmi routine on vblank? i was having a problem with this, seems i forgot to turn it on :P




SubjectRe: NMI problems new  
Posted byWhoaMan
Posted on7/18/03 03:48 AM
From IP68.134.169.134  



nm, ignore that, when i first read your code i diddnt see where you turned it on, seems you turned it on at the bottom




SubjectRe: NMI problems new  
Posted byloopy
Posted on7/18/03 05:27 AM
From IP192.156.53.34  



Are you aware that your time: function eats up about 2 frames' worth of CPU cycles?




SubjectRe: NMI problems  
Posted bybeneficii
Posted on7/18/03 9:31 PM
From IP68.18.219.125  



Yes! I went through and corrected it! I then added a new feature: the moving from space to space is animated! It works! It takes four NMI frames to do the actual walking, but I got it to work! ^_^ Now, when the sprite gets to the goal of the maze I want the game to make a beeping sound, but how to do that I do not know. May you recommend to me a doc about sound? I'm going ahead and will look through the NESDEV index.

Thanks. ^_^






SubjectRe: NMI problems new  
Posted byBuffPipes
Posted on7/20/03 2:31 PM
From IP66.183.101.204  



What a real problem is that you don't do a reg push/pop. When ANY code is executed, NMI can pop up, and will destroy any registers. You need to do this:

NMI:
pha
tya
pha
txa
pha
..
pla
tax
pla
tay
pla
rts




SubjectRe: NMI problems new  
Posted byquietust
Posted on7/20/03 3:54 PM



I assume you meant for that last instruction to be RTI...

--
Quietust
P.S. If you don't get this note, let me know and I'll write you another.


SubjectRe: NMI problems new  
Posted byBuffPipes
Posted on7/28/03 09:45 AM
From IP66.183.101.204  



yeah, rti




Previous ThreadView All ThreadsNext Thread*Show in Threaded Mode
Jump to

Memblers' homepage             Contact Me

Forums powered by WWWThreads Demo