Drawing, Vblank, and NMI - A doc I whipped up

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

User avatar
Bregalad
Posts: 7766
Joined: Fri Nov 12, 2004 2:49 pm
Location: Chexbres, VD, Switzerland

Post by Bregalad » Mon Apr 20, 2009 3:42 am

Hey, just something about the doc...
Dish says it's good to never disable the NMI is good, but I can see two reasons to disable it :
- When redrawing something when the screen is turned off, if an NMI happens between two $2006 writes, the NMI will acknownledge the interrupt by reading $2002 and the result would be very bad (this has actually happened to me once).
- When starting a sound effect/a new piece of music if the music engine is called while the sound effect/music is initiated, BAD things could happen.

Unless you programm the NMI to not even acknownledge the interrupt depending on the state of the main engine, and because that NMIs on the 6502 are edge based and not state based, I guess it would be a workarround to issue 1, algouth it's not really "clean".
Life is complex: it has both real and imaginary components.

User avatar
Disch
Posts: 1849
Joined: Wed Nov 10, 2004 6:47 pm

Post by Disch » Mon Apr 20, 2009 8:17 am

1) Which is why you don't unconditionally read $2002 or set the scroll. Note that I made both of those conditional in my latest version.

2) The music engine should do all of that anyway. Starting a new track or playing a sound effect should equate to changing a single area of RAM.

Only real concern I had that was unavoidable was for mappers which require serial writes to a register. MMC3 style address/data regs can be guarded against easily enough:

Code: Select all

swapmmc3:
  lda #$81
  sta soft8000     ; nmi would then copy this to $8000 before exit
  sta $8000
  lda pagenumber
  sta somewhere  ; if this is necessary
  sta $8001
Howver MMC1 style serial writes are pretty much impossible to guard against, and so you'd need to disable NMIs around them

User avatar
Jarhmander
Formerly ~J-@D!~
Posts: 488
Joined: Sun Mar 12, 2006 12:36 am
Location: Rive nord de Montréal

Post by Jarhmander » Mon Apr 20, 2009 9:35 am

Drag wrote:
tokumaru wrote:
frantik wrote:here is a buffer read routine i came up with based on a simplified version of SMB's routine..
The only problem with your code is that it's quite slow... INY, DEX and BNE for every copied byte is terribly inneficient. Unfortunately I don't have a better suggestion that doesn't require much more ROM.

If there's more ROM available, I can always recommend my pseudo-DMA idea. In my current project, I use a variation of it that is limited to 32 bytes at a time, so it doesn't need so much ROM.
You could kinda compromise and do it both ways at the same time, like StarTropics II. :P

Assume X is the loop count (the number of bytes remaining that we need to transfer).

Basically, it has an unrolled loop of:

Code: Select all

<subtract 8 from X>
LDA buffer,Y
STA $2007
LDA buffer+1,Y
STA $2007
...
LDA buffer+7,Y
STA $2007
<add 8 to Y>
plus the normal loop:

Code: Select all

LDA buffer,Y
STA $2007
INY
DEX
BNE -
The unrolled loop is the equivalent of a loop of 8, so what the program does is use the unrolled loop, copying 8 bytes each time, (subtracting 8 from the loop count each time), until the loop count is < 8, in which it just uses the normal loop for the remaining bytes.

So basically, if you need to transfer 5 bytes, it uses the normal loop with an X of 5.
If you need to transfer 8 bytes, it uses the unrolled loop once.
For 16 bytes, it uses the unrolled loop twice.
For 20 bytes, it's the unrolled loop twice, and the normal loop with an X of 4.

It doesn't rely on huge unrolled loops, indirect jumps, tables, or anything of the sort, yet offers a better efficiency for transfers that are >= 8 bytes in length.
This is exactly the Duff device! http://en.wikipedia.org/wiki/Duff%27s_device

User avatar
ehguacho
Posts: 83
Joined: Tue Mar 09, 2010 11:12 pm
Location: Rosario, Argentina
Contact:

Re: Drawing, Vblank, and NMI - A doc I whipped up

Post by ehguacho » Thu Mar 11, 2010 8:03 pm

Disch wrote:...I was bored and needed a break from my other project...
thanks mate! (a.k.a. "you should get bored more frequently") :lol:
sorry about my english, i'm from argentina...

http://nestate.uuuq.com

User avatar
No Carrier
Posts: 290
Joined: Tue Dec 13, 2005 4:19 pm
Location: Gainesville, FL - USA
Contact:

Post by No Carrier » Sun Mar 14, 2010 10:09 am

Disch wrote:http://nesdevhandbook.googlepages.com/index.html

It's a start! We'll see how much I can actually get done before getting bored and moving on. XD
Since this thread was brought back from the dead, I'll mention that this link isn't working. You can get to the index, but subpage links are dead.

User avatar
Disch
Posts: 1849
Joined: Wed Nov 10, 2004 6:47 pm

Post by Disch » Sun Mar 14, 2010 10:13 am

Yeah apparently googlepages doesn't work anymore. Talk about lame.

I don't have any free webhosting these days =(

tepples
Posts: 21748
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples » Sun Mar 14, 2010 10:16 am

Disch wrote:I don't have any free webhosting these days =(
wiki.nesdev.com

User avatar
Disch
Posts: 1849
Joined: Wed Nov 10, 2004 6:47 pm

Post by Disch » Sun Mar 14, 2010 11:13 am

Well I didn't mean for nesdev stuff, I meant for general filesharing.

WJYkK
Posts: 60
Joined: Thu Dec 24, 2009 12:23 am
Location: Igloo and Bear Land (Canada)
Contact:

Post by WJYkK » Sun Mar 14, 2010 4:51 pm

Oh, it works, except you have to download http://nesdevhandbook.googlepages.com/theframe.html (AKA chapter 1 AKA the only chapter).

User avatar
comegordas
Posts: 53
Joined: Sat Aug 14, 2010 7:12 pm

Post by comegordas » Thu Aug 19, 2010 8:11 pm

thanks a lot Disch. hat's off. it's a great doc this one you whipped up.

jarrodparkes
Posts: 1
Joined: Fri Oct 12, 2012 1:29 pm

Re: Drawing, Vblank, and NMI - A doc I whipped up

Post by jarrodparkes » Sat Dec 29, 2012 6:47 pm

Does anyone still have access or a copy to this guide?

Thanks!
Jarrod

Hangin10
Posts: 37
Joined: Thu Jun 04, 2009 9:07 am

Re: Drawing, Vblank, and NMI - A doc I whipped up

Post by Hangin10 » Sat Dec 29, 2012 11:11 pm

I managed to find this, not sure if that's all of it. I also don't have the stylesheet.

Also, it won't let me attach html nor .txt, but zipping it is ok?

EDIT: Sorry koitsu, apparently it's false positive-ing, calling it an attack vector if I don't zip it regardless of extension.
Attachments
theframe.zip
(11.6 KiB) Downloaded 200 times
Last edited by Hangin10 on Sat Dec 29, 2012 11:43 pm, edited 1 time in total.

User avatar
koitsu
Posts: 4215
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: Drawing, Vblank, and NMI - A doc I whipped up

Post by koitsu » Sat Dec 29, 2012 11:24 pm

.txt attachments should absolutely work. .html or .htm don't work, but I'm planning on fixing that in a moment.

User avatar
koitsu
Posts: 4215
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: Drawing, Vblank, and NMI - A doc I whipped up

Post by koitsu » Sat Dec 29, 2012 11:26 pm

Like I said, .txt works just fine. .htm, .html, and .css have been added.
Attachments
cider_pork_stew.txt
(1.4 KiB) Downloaded 394 times

Post Reply