Question 1:
i read about any games load in $8000 where prg start.. then if i open a .nes rom in a hexadecimal editor..... it means that prg start at $8000..
i am getting conffused... cpu address??? nes address???
my question is because... i have readchr.. i can know where chr data start in rom... but when open rom with hex editor.. is same address???
or exists a mathematic expression in order to translate it to roms address?? in order to i find exactly address with a hex editor??
$8000 is the CPU address. In a .nes file the PRG is right after the header (so it starts at $0010). If the PRG is 32kB, then the CHR would start at $8010 in the .nes file. You have to know how many PRG banks there are to see where CHR starts, the header has that info.
This question is a bit confusing...
Well, when you run games, the NES maps ROM to the space $8000-$FFFF (32k). If you have only 16k of PRG, it is duplicated to fill all the space. Many games have their reset vector pointing to $8000, because that's where PRG ROM starts, but that is not mandatory.
In the ines files, PRG will start right after the header, wich would be offset 16 (after the 16 bytes of header). They will be arranged in banks of 16k, one after the other.
EDIT: Oh, Memblers answered. I got a call while writing and it took some time =)
thanks!!
yes.. then cpu address is cpu 6502 address.. i was thinking cpu address = cpu intel pc address haahahaaa...
.nes is address in file then when i open with a hex edit .nes file i search by .nes address....
ANOTHER QUESTION
Question 2:
i made my demo of hello world... but in nesasm is possible making a sound player????...
in order to load a nsf and play it???..
how can i loading a nsf on nesasm src code???
and what steps i do in order to play a tone in a asm 6502-... i noticed that only writing tone is not valid!!.. i have set another thing first!! which???
Question 3: do you know Ben Fry's Mario Deconstructulator.. it's a java emu that visually show how sprites are managed in nes 6502 memory!!
i cannot getting any link.. do you know a direct link to dowload it??
one question about nes 8 sprites limit in a row
all documents speak about nes 8 sprite limit.. then did you play any time nes game called "LEMMINGS"??
how lemmings show more than 10 lemmings in a row???... each lemmings is an autonomist.. each lemming is
a object... i imagine that lemmings takes 2 lemmings or more than 1 lemming like one sprite.. but if each lemming is an autonomist object, my imagination is a error.. what type of technique use lemmings??.. the most funny and headache game of nintendo????
I haven't played the NES version of lemmings in a while... I didn't even remember it existed!
I bet it does it like any other game that shows more than 8 sprites in a scanline do: OAM cycling.
You have to rearrange the sprites in different SPR RAM slots every frame so that their priorities cycle. Then, when you have more than 8 in the same scanline, not the same 8 will be shown every frame, they will cycle. That's why sprites flicker some times. It may not be very noticeable if lemmings are flickering as they're usually so grouped together.
I doubt the game draws lemmings to the background or something like this, it most likely uses the good old OAM cycling method.
can you explain OAM cycling method for a newbie please???
i dont get good it..
lord wrote:
can you explain OAM cycling method for a newbie please???
There is a discussion about it here:
http://nesdev.com/bbs/viewtopic.php?t=469
A few different methods are presented there. I can't tell you what the best one is as I haven't played much with OAM cycling myself. I'll just try a few different methods when the time is right, and decide what works best for me.
Bregalad seems to have a very interesting technique. Maybe he can explain it to you?
Each lemming is a sprite. When more that 8 lemmings comes on a row, they flicker (this actually happen fairly often).
However, usually, a single people/object is more than one sprite whide (often 2 or 3). The only "trick" used in Lemmings is to not take more than one single sprite for one single lemming.
yeah.. documents saying: "nes system dont accept more than 8 sprites by scanline"... then... "more than 8 sprites" what mean?? more than 8 sprites with a width of??? 2 tiles, 1 tile or 3 maybe????..
1 sprite width = 8 tiles..??
then nes dont accept more than 64 tiles (8 sprite) by scanline??
Bregalad wrote:
The only "trick" used in Lemmings is to not take more than one single sprite for one single lemming.
They're probably 8x16 too, right? That fits the size of a lemming pretty well, and would allow for a good number of lemmings on screen. I remember the PC version, and I can imagine how they flicker on the NES as lemmings usually gather up in huge packs...
yeah.. documents saying: "nes system dont accept more than 8 sprites by scanline"... then... "more than 8 sprites" what mean?? more than 8 sprites with a width of??? 2 groups of 8 tiles in width, 1 group of 8 tile width or 3 groups maybe????..
tile layer pro shows me that each lemming is one single sprite.. (8x8 tiles)
lord wrote:
1 sprite width = 8 tiles..??
NES sprites are always 8
pixels (not tiles) wide. That means you can only have 64 pixels worth of sprites in a scanline.
In the NES, the player is not 1 sprite. It's made of multiple sprites (well, the lemmings are only 1 sprite each). One sprite is always 1 tile wide.
You can place more than 8 in a scanline, but the ones with lower priority will simply not be displayed. They're there, but invisible. That's why you should cycle the priorities, so that the ones that were invisible the last frame will be visible in the next, and vice-versa.
tokumaru wrote:
You can place more than 8 in a scanline, but the ones with lower priority will simply not be displayed. They're there, but invisible. That's why you should cycle the priorities, so that the ones that were invisible the last frame will be visible in the next, and vice-versa.
yeah but if all sprites are animated.. when you going to cycle.. how you can animate all sprites to same time... you must drawing all or no? or sprites of 1st cycle must stop animation?? and sprite of 2nd cycle going to move??
Just animate normally, every frame. If you cycle well, the sprites will not be invisible for more than one frame at a time. It's very unlikely that the player will sense a difference in the animation. The player's brain will compensate for any frame of animation that may be lost. The movement may not feel as smoth, but will not affect gameplay at all.
If you played NES before you must have seen this effect before. And the fact that you seem to not remember it just proves it's not of great impact to the player! =)
i remember great amounts of lemmings in a same row.. They was like flashing lemmings!!.. but they dont see dissapears they appears and disappears so fast that you dont notice that a group of them are invisible for a little time...
yeah i get the idea..
thanks
change flashing lemmings for "phantom lemmings"
I just noticed that sprite cycling is much less visible on a real television than on an emulator.
Bregalad wrote:
I just noticed that sprite cycling is much less visible on a real television than on an emulator.
I guess subsequent frames are somewhat "merged" on a television in the form of fields, while a PC monitor shows all 60 frames per second. I'm not a TV guru though.
a question about .chr sprite order..
Just i noticed that all sprites in super mario bros are a "unsort sprites" inside .chr..
But my question is if nes have any type of format to insert in.CHR people/objects to know by example where is "the head left", "the head right", the "middle left body", etc..
for what reason sprites dont be arrange or "sorted" in .chr???.. because editing is very hard with unsorted sprites.. i see mario head on bottom "by example", but mario foots are in middle!!!. and yeah, i can sorting it manually but since all sprites are in different locations i cannot finding difference between big mario, and small mario using tile layer pro!!
what is the sort format????
there is any program for automatic rearrange of tiles?
Nope.
All sprites are customly arranged by software. If you want to reconstitue sprites, you have to play trough Nesticle, disable BG and dump sprites or to work youreself with a tile editor.
But there is most probably already a thousand of mario sprites available on the net.
Bregalad wrote:
play trough Nesticle, disable BG and dump sprites
then Nesticle dumps sprites in order?
which is the dump format??
I think he meant a screenshot. Take a screenshot when the sprite you want is beeing displayed. If you disable the background the screenshots will contain only sprites. So, play with mario frame by frame for a while and you'll have all his sprites to put in whatever order you want. But you can probably find Mario sprites in many many webpages, as Bregalad said.
BTW, the sprites are probably all messed up in the pattern tables because there is no way to have them arranged, since many parts are used in more than 1 frame. I believe the head, for example, remains the same for all frames, wich means it's defined only once in the pattern table. It would be a waste of pattern space to have the same thing stored over and over.
i dont want taking a screenshot.. i wanna knows how sprites are inserted..in a chr.. i know now that it's by software..
im trying taking smb sprites.. and making walking a smb for learning about sprites..
Each game order them customly to spare pattern table space in a differen way.
I belive some games change frames dynamicly (like Battletoads), but this is much more common to SNES games.
Try YY-CHR. It comes with a file that defines the sprites for Super Mario Bros, it displays them as they're displayed on the screen in-game and you can edit them like that and have them saved back in the games sorted format.
And of couse there's a way to edit the file to define the sorting for other games (or your own).
Cool idea for emulators: have them dump palette RAM and OAM each frame (272 bytes per frame total, using the "unused" bytes of palette memory for $2000 and the like) and then put a feature into a tile editor allowing display of the sprites at any given moment with the current CHR.
im trying making a PHP script in order to decode pattern tables. and show characters in a 8x8 table of colors in html. yes i can decode .chrs manually then i fully understand that..
My question is: what instruction in php help to me to read a "binary file"??. and how can i reading a "16 byte" (8x8) pixels???.. i wanna to know only how read... because i know the another stuff
..
string fread ( resource gestor, int longitud )
yeah.. but string is like aSusdil@xaqa??
i wanna getting strings like C6DE0123FF221300.... or just getting 11111001 11001100.. Is it possible in php reading binary files???
And another question.. i haver read here about something called "the latch", what is it?.. how important it is?? when set it?? 0, or to 1???
ps: There are girls on nesdev?? do you know anyone???
hahaahaha..
god luck
lord_Chile wrote:
And another question.. i haver read here about something called "the latch", what is it?.. how important it is?? when set it?? 0, or to 1???
ps: There are girls on nesdev?? do you know anyone???
hahaahaha..
god luck
Check this out:
http://nesdev.com/bbs/viewtopic.php?t=1009&postdays=0&postorder=asc&highlight=latch&start=15
I had the same question.
EDIT: About latch .. not girls on nesdev.
For file access with PHP, how about an SQL database? I haven't used PHP except for extremely simple ('hello world' type) stuff, so I don't know of any other way.
lord wrote:
im trying making a PHP script in order to decode pattern tables. and show characters in a 8x8 table of colors in html. yes i can decode .chrs manually then i fully understand that..
My question is: what instruction in php help to me to read a "binary file"??. and how can i reading a "16 byte" (8x8) pixels???.. i wanna to know only how read... because i know the another stuff
..
use fread:
http://us2.php.net/manual/en/function.fread.php
EDIT: nevermind ... see you already have that.
You seem to be reading the data just fine... just don't expect it to come arranged as hexadecimal numbers or even as bits...
Just convert each character from the string into values... each character is a byte. I don't know how to do it in php though, I only know asp, but surelly there must be a function for that.
only any little stuff remain me.. i dont know good working with matrix in php!!!.. then my program lost the "1"s and "0s" in matrix..
but 1st bpp (first 8 bytes are showed good),.. im still working...
i can get 0s and 1s representation of file!..
working...
thanks
just now i read web design using php4!!.. and i read parameters by reference.. i was very stupid because, i was replacing my matrix each time then matrix didnt load completely.. but know.. i have 0.1 stable version of code hehehe.. full art.. it's currently only a test, but it seem good!
In my university named "Universidad tecnica federico santa maria" from Chile exist a page for students of this university.. I think that people loving programming can subscribe here clicking on "crear cuenta" (create account).. but this page is in spagnol..
i post the output of my program here, currently it draw sprite number 1 (i give spritenumber 1 like parameter) and it was read of smb.chr!!. link called "next" is BAD because now i dont have a server then i send only output to this page... opinions.. i am starting to making more funtionality to it, because it can show any chr without compression.. put your attention on 1s and 0s, because it's real, and was ripped directly from bytes by bytes..
IT'S THE URL!!!
[url]
http://www.inf.jmc.utfsm.cl/contenidos/ ... 0210135535[/url]
good luck
ps: memblers sorry, width of this post is very large...
but url of my university is so large!.
Use the [url=...]...[/url] syntax for really long urls, or use tinyurl.com.
yeah, im making a decoder of nametables and patterntables.. i use rocknes's emu and i export nametable of super mario bros 1. i get .chr and reading .nam file in binary mode i draw to great scale background of smb1 using a php script with a output in html tables!!!.. my another decoder in php is for really good sprites to scale, too.. i have smb, toadstool, koopa hehe.. it's really slow.. it takes 20 minutes on draw.. how can i improve my code???..
but i have any questions... .nam file is 4 kb.... for what??.. when i read documents they give to me understand that nes has space for only two nametables, this space is 2kb.. for what???.. then each nametable is 1kb??? or is space of 2kb for each nametable???.. then when rocknes exports nametables it's exporting 2 nametables????? (4 kb??)..
another question: i read nametable for 32 bytes * 30 bytes.. yeah.. and where are attribute tables???.. i know that it's inside .nam.. but where?? how many bytes???
Pattern tables, attribute tables and nametables are very well documented, after all. I already knew all how they worked before startring coding my very first NES programm attempt. I really think you're asking very stupid questions.
Quote:
another question: i read nametable for 32 bytes * 30 bytes.. yeah.. and where are attribute tables???.. i know that it's inside .nam.. but where?? how many bytes???
Yeah but if english is something hard for you.. and any documents are bivalents!!!!... reading documents i understand that each nametable is 1kb because documents says that meaximum memory is 2kb...
reading documents i understand that attribute table is inside nametable and it will at the end of the 4 kb i dont know for what..
but i wanna that you know
just humility is the thing that make you more person.. sorry.. i am very newbie... i only did wish a response to mys ask..
I probably didn't understood english better than what you do back in the time. No excuse, really.
Just avoid asking stupid questions before examining the stuff a bit before and that way avoid getting too stupid.
Also, ask questions clearly, write sentences and not just words, use commas, puncts, etc... and that's it. That way people will most certainly be pleased to answer to your questions instead of telling you that you're stupid. I hope I don't ask too much from you. I don't want to get too much angry. Thanks.
i understand sorry...
i will try.. but the point is that you cannot say that questions are stupid.. you can changing it and saying.. this question is out of focus, because if you say of this form, it's not offensive..
not dont get angry.. i have friend in switzerland and i know that is nice people.. it's only that i get angry when people says words in bad form...
good luck bregalad.
What do you mean by "say word in bad form" ?
And please use the shift key of your keyboard to write CAPS ! It isn't all that hard either, and makes what you say a lot more understandible. Also use the enter key to make
line breaks when needed. This hasen't to do anything with stupid/intelligent but with readable/ununderstandible.
I don't think it belong only to engish language, I think there is also caps and returns in spain (which would normally be your native language isn't it ?). Oh, don't take it bad, please, but it really get anoying when we don't understand what you want to say.
If you got trouble speaking english, I would personally recommand to practice, practice and practice again. Yeah, when I started developping for the NES I knew nearly nothing about english, only basics.
The docs were like in chineese for me. Additionally, I did knew a lot less in electronics that I do now. So yeah, it only make things harder.
But scince I didn't knew enough of english to go on the boards to ask questions, I was forced to figure out everything on my own. And that forced me to practice again and again english. Until I eventually asked questions on the boards...
Bad form... or say something that sounds offensive..
---------------------------------------------------------
Like: "yeah, it's very stupid question.,.. i suggest you"..
good form.... or say same thing but it's sound very friendly..
-------------------------------------------------------------------
"yeah, but lord your question is out of focus... i think that
you must.. read more.you must read
documents any more time until you get it"
my english is not good.
So I think use the "bad form" can act much more significantly on the reciver than the "good form". Someone telling the "bad form" will seem rude, but will say what he thinks. Someone using the "good form" will sure be kind, friendly, etc... but the reciver could just piss off what they say if they really are getting to sweety.
lord_Chile, as I explained to you before, each name table + attribute table pair is 1kb long. The NES has memory for 2 of these pairs, so 2kb. However, the PPU can address 4 name tables, and that's why we have to use mirroring. Mirroring will define wich 2 name tables will be repeated (mirrored), vertically or horizontally.
The dump you got probably is 4kb because the NES can address 4 name tables. If you look at them closelly, 2 of the tables in that dump are probably copies of the other 2. If you were using a 4-screen mirroring game, the 4 tables in the dump would be different from each other.
ok fully understood.. i understand all now.
i wanna ask to bregalad something..
my question is "what is a nes"????
hahaha (joke).. now speaking more seriously...
i read on nesdev about the word "metatile", and i read "metatile engines", too. What is a "metatile"???
lord wrote:
What is a "metatile"???
What the hell? Only Bregalad can answer now?
Well, a metatile is a block, larger than 8x8 pixels, formed by more than 1 tile (wich is 8x8 pixels). Metatiles exist to make the level maps smaller. If you were to define a screen for a game directly using tiles, it would take 1kb (1024 bytes) to define the whole screen (tiles + attributes). But if you use 16x16 pixels (2x2 tiles) metatiles, there will be only 240 of them in a screen, wich means a screen can now be defined by only 240 bytes. That's a huge gain, 1024 to 240, don't you think?
You have to define the metatiles in a separate space, of course. If you're using 16x16 pixels (2x2 tiles) metatiles, you'll have to define what 4 tiles that metatile uses. A common format for 16x16 metatiles uses 5 bytes for each, with 4 bytes indicating the tiles used to draw it, and the 5th byte indicating the palette to use for the block, and the type of the block (solid, sky, water, etc - stuff used for collision and physics)
So, when you decode the map to the screen, you don't copy directly. You read a byte from the map, check what tiles make up that block and draw those tiles to the screen. And don't forget to properly set the attributes too.
The most common size for metatiles is 16x16 pixels, but there are others like 32x16, 32x32, etc. Each one has it's pro's and con's. I guess that's it.
thanks tokumaru.. !!
about bregalad it was a "joke thing" making a question to him like
"what is a nes"..
anyway all people can giving responses...
sometimes my english is bad.. then people get confuse here..
anyway tokumaru you are from brazil, i speak spanish.. do brazilian people understand spanish??... sometimes chilean people understand portuguese of brazilian people..
then 1 tile is created by 8x8 pixels.. then 1 tile = 1 sprite????
lord wrote:
i speak spanish.. do brazilian people understand spanish??... sometimes chilean people understand portuguese of brazilian people
Brazillians usually understand spanish very well. I understand with no problems. Good that Chileans can understand portuguese, many spanish-speaking people can't. Anyway, "Portuñol" is a very common way for brazillians to communicate, but since this is an english board, it may not be a very polite thing to do.
lord wrote:
then 1 tile is created by 8x8 pixels.. then 1 tile = 1 sprite????
Sprites have nothing to do with this. We're talking about level maps, so, background. The tiles can also be used for sprites, but that's not the point here. Tiles are that little 8x8 pixel things you see in the pattern tables, wich you use to build the background of your game.
A metatile is just a group of regular tiles, with extra info for palette, collision and physics, used to make the level maps smaller.
Saludos tokumaru!!!. Good nesdev people, i have a question very very hard, but it's easy for you... i know.. i wanna to know something:
example: if you play final fantasy, imagine that you have the background.. then at the same time of background appears a dialogue..
you press a, then appears another dialogue..
My specific question is:
do you have a different nametable for each dialogue???
it would be a crazyness....
i read about pointers, but i dont know if say "pointers" is technically correct because romhackers says pointers.. but it's not nametable or something??? and i dont understand that romhack pointers...
No, you wouldn't use a different name table for each dialog. You should be writing the new dialog over the first one. Just rewrite the dialog during VBlank.
Pointers would be usefull in this case only to point to the strings used in the dialog. I mean, when the characters speak to each other you must specify what they're going to say, you should do that by pointing to the strings you want to use.
About the placement of the dialog box, you have many options for that. If the screen is moderatelly aligned to the 8 pixel grid you could just draw the box where you want it to be, relative to the camera's position. But that would erase your background and you'd have to redraw it once the dialog box was gone. If you use 1-screen mirroring or horizontal mirroring you could just pick a place in the name tables that's not beeing displayed at the moment and draw the text box there. Then change the scroll mid-frame to place the text box wherever you want.
But that's a bit to advanced for you right now, if you allow me to say so. Well, advanced for you to do, but that doesn't mean you don't deserve an explanation of how it's done. You must have an idea of how the effects are done so you can do it too, someday. Watch the name tables in an emulator while playing the games so you can have an idea of how it's done.
I haven't played or analyzed Final Fantasy much, though. Bregalad is the FF master here, I guess... =)
ok, muchas gracias por la respuesta tokumaru.
another question is:
any people says that super mario bros uses horizontal mirroring.
i see in ines header readers of emulators that super mario bros is vertical mirroring.. it's correct???
Because, I agree that smb is vertical mirroring. smb is vertical because if smb was horizontal, all graphics behind (left) of super mario bros would get messed up on left side when super mario is walking to right side!!! because of the mirroring, no??
SMB uses vertical mirroring...
you probably had 'horizontal scrolling' mixed up with mirroring.
Another reason for the mixup: Does Nintendo's terminology for the mirroring solder pads on NROM boards match the homebrew community's terminology?
tepples wrote:
Does Nintendo's terminology for the mirroring solder pads on NROM boards match the homebrew community's terminology?
No, it does not - Nintendo-made NES cart PCBs all label their mirroring pads "H" for Horizontal Scrolling (i.e. Vertical Mirroring) and "V" for Vertical Scrolling (i.e. Horizontal Mirroring).
lord of chile wrote:
ok, muchas gracias por la respuesta tokumaru.
You're welcome.
Quote:
Because, I agree that smb is vertical mirroring. smb is vertical because if smb was horizontal, all graphics behind (left) of super mario bros would get messed up on left side when super mario is walking to right side!!! because of the mirroring, no??
For a horizontal scroller, you'd want to use vertical mirroring to avoid glitches at the sides of the screen, that's right. However, many official games seem to use horizontal mirroring when scrolling horizontally, such as SMB3 and Kirby's Adventure. And the glitches do show a lot.
SMB3 and Kirby's Adventure also do a heck of a lot of vertical scrolling and free 2D scrolling, and you can't easily do that and have a status bar if you use vertical mirroring.
About textboxes, I have several info for you.
Do you want to build a RPG for the NES later ? You already asked questions about batteries, so this definitely becomes "suspicious" hehe. Good luck.
Because the NES has only one BG layer, most games writes the textboxes "above" the background. They do need to write 2 or 4 rows at time to have no attribute glitches (because the box won't have the same color bits as the background behind).
Then, when the window closes, you'll also have to rewrite the map data that is behind the box to the name table, and the map's color to the attribute table.
The "easy" way to do it is to read the old nametable and attribute table via $2007 and store it to RAM, to be restored later. This is lazy, waste RAM abd VBlank time for hardcore vblanktimesavers, but works well.
It is not so hard to read the map cordinates and rewrite it to the screen. I do that in my current game when the menu closes, and it is actually very easy to do, just some math is involved.
About writing text, each game has its own engine. Final Fantasy works pretty lazy, they write the whole string of text one row at time, wait to the player push A and shows what's next. Dragon Quest games have a better text phraser, that write letters after letters, and have a blinking cursor to wait the player to press A. It's up to you to determine what is the most confortable for the player.
Final Fantasy I is doing a special trick : It does write the window in the alternate nametable. Because it uses vertical mirroring, the engine still couldn't allow to scroll while a textbox is open, but it allow a cool effect when they pop up that isn't there in Final Fantasy II and III.
To allow scrolling when a textbox is open, you'll have to use one-screen mirroring (or maybe horizontal, but needs to be tricky, especially on a PAL system that doesn't hide the top and bottom 8 scanlines).
I do have no RPG that does that in mind, but I was thinking doing that in Ecological Evolution (not sure yet).
Hey, I have a suggestion for the text boxes. Let me show a picture of the idea first:
Now, this represents the 2 name tables, in vertical mirroring mode. The dotted red line is splitting the 2 name tables. The green parts are the map that was previously rendered to the name tables. The light part is where the camera is (the red spot represents the scroll values). The gray part is where you
would draw the text box if you were to draw it in place (I'm assuming the text box stays at the bottom of the screen). But if instead you draw it in the yellow part, you can have it appear with the "sliding" effect (by splitting the screen). The background wouldn't be overwritten, so, when the text box goes away you just keep scrolling normally. And you could have all of that using vertical mirroring, the best for scrolling without any visible glitches. Of course, you woudn't be able to scroll when the text box is active.
I don't usually play RPG's, but I'd guess at least some have already done it like this.
That's just what FF1 does. It also copies the tiles of the border of the screen to the second name table to not have the text box take the full screen.
This wasn't maintened in FF2 and FF3.
Bregalad wrote:
Because it uses vertical mirroring, the engine still couldn't allow to scroll while a textbox is open
Sorry. For some reason I missed the "vertical" part and assumed it used horizontal mirroring. I guess it's because you said "alternate name table", and it sounded like it used only one name table for the text box, but it usually spans across the 2 of them, at the parts not currently showing.
i like rpgs, some day i am going to make a rpg game of my life..
just im very creative, i dont like final fantasy 19, no..
just it will be "Luis's hidden life crystals" or another.. and just nesdev guys are going to appears in my game =o).. and i dream with a sequel for snes and n64... some day... more later..
im fanatic of terranigma in spanish for snes.
i play super mario bros 3, i think that it uses horizontal mirroring because it's more easy to designers get mario going to left and going to right using horizontal M..
it's because smb3 can go around all the stage for left and right..
smb1 only was walking into right then it uses vertical, but smb3 walking into two directions is good use horizontal mirroring here..
are correct my conclusions??
yeah, the glitch is very notorious in smb3, horizontal scrolling with horizontal mirroring.. but i think that programmers take control of this because this glitch without control is ultra notorious and would messed up very much part of screen.. there is control of this glitch on smb3 no??
and another is: what is the official megaman 3 bug???
i dont see bugs in megaman 3
lord_Chile wrote:
i think that it uses horizontal mirroring because it's more easy to designers get mario going to left and going to right using horizontal M..
it's actually related to the fact that SMB3 can move up and down. And it has a status bar. If you scroll up and down using vertical mirroring, there is no way you can have an area in the name tables reserved for a status bar, it would be overwritten all the time. The solution used in SMB3 was to use horizontal mirroring, with the status bar fixed at the very bottom of the second screen.
Quote:
smb1 only was walking into right then it uses vertical, but smb3 walking into two directions is good use horizontal mirroring here..
SMB1 has the limitation of not scrolling to the left because of the way the levels are decompressed, it has nothing to do with mirroring.
Quote:
yeah, the glitch is very notorious in smb3, horizontal scrolling with horizontal mirroring.. but i think that programmers take control of this because this glitch without control is ultra notorious and would messed up very much part of screen.. there is control of this glitch on smb3 no??
Well, the programmers know the glitches are there, and there is no way to get rid of them in that situation (horizontal mirroring + side scrolling). It happens because when using horizontal mirroring, you get a drawing space that's 256 pixels wide and 480 pixels tall. 256 is exactly the ammount of pixels displayed in a line on the TV, so if you scroll even a little bit to the right, what will show on the right is exactly what was just left behind, on the left.
You don't get any extra space to use as a drawing buffer, hidden from the player. The NES has the option to hide the leftmost 8 pixels. This way you get a hidden place to draw things, but it's only wide enough to avoid glitches related to patterns (since you can draw columns of tiles that are 8 pixels wide, just as the buffer) but not the ones related to color, since the color resolution in the NES is 16 pixels, not 8.
So, in SMB3 you'll often see that the colors are wrong in the righmost column. The colors will be the ones that belonged to the blocks that are disappearing at the left.
Question about nametables.. i understand pattern tbl, name tbl, because im programming a graphic decoder in php. But my problem is with attribute table.. am i calculating correctly????
see it, each (*) is representing one tile.:
********************************
********************************
********************************
********************************
fig 1.0 (showing 4 rows of tiles and cols of 32 tiles) (representing 8 bytes for attr table)
For each 4 rows of tiles=8 bytes in attribute table
groups of 4x4 tiles (each group=1 byte) in attribute table.
1-4 row of tiles 8 bytes
5-8 row of tiles 16 bytes
9-12 row of tiles 24 bytes
13-16 row of tiles 32 bytes
17-20 row of tiles 40 bytes
21-24 row of tiles 48 bytes
25-28 row of tiles 56 bytes
29-32 row of tiles 64 bytes
but if nametable is 32 cols x 30 rows of tiles......
30 rows of tiles doesnt match with my calculations, because the byte number 64 in attribute table contains high color bits for 31-32 row of tiles, too. This area is unused?????
I think it would be 4 bytes unused, am i calculating correctly????
On a past post, Disch wrote:
"The bottom 2 rows of the attribute table are used when the attribute table is used as nametable data."
what mean, "when attribute table is used as nametable data??", when it is?
lord_Chile wrote:
what mean, "when attribute table is used as nametable data??", when it is?
If I understand correctly, this is how it normally works:
- The nametable is located from $000 to $3BF in its "page" (so nametable 0 is in $2000-$23BF), it's only 30 tiles tall, leaving the space from $3C0-$3FF for attributes
- The PPU is smart enough to skip over the attribute bytes and go directly back to the top of the nametable after drawing the bottom tiles
The PPU only skips the attribute bytes when it gets there on its own. If you set the vertical scroll between 240 and 255, it will start in the attribute area instead of the nametable area. Since it never hit the line 240 boundary, the PPU will mistakenly read the attribute bytes and use them as nametable bytes. When this happens, it also uses the (normally useless) last few attribute bits to select colors for the tiles.
Is this correct / did it make sense?
talking about nes 16 color palette for background.
we are taking 1 color: by example, we are taking 2nd byte.
by example 2nd byte is $22 = 00100010 (BGR) colors..
i wanna to knowing the algorithm in order to map it to computer screen (RGB color). any idea?
The NES palette is not RGB or BGR; it's closer to HSV (hue saturation value). The easiest way to translate from NES HSV to PC sRGB is to load a palette file, which contains a suitable lookup table. Some of the older palette files floating around the net are hand-made, but newer emulators generate a more accurate palette by emulating the NES output signal and an NTSC TV's decoder. Details are in
NESdevWiki:NTSC Video.
one scrolling in Y or X advance is 8 pixels?
Then.... in sprite ram, sprite position X or Y, can be not 8 multiple number???
lord_Chile wrote:
one scrolling in Y or X advance is 8 pixels?
You can scroll 1 pixel at a time. The scroll registers are 8-bits, meaning they can hold values from 0 to 255 (256 unique values). The NES screen is 256 pixels wide by 240 pixels tall. The 8 bits per axis is enough to represent any point in the screen where you'd want the rendering to start.
Quote:
Then.... in sprite ram, sprite position X or Y, can be not 8 multiple number???
Sprite RAM has nothing to do with the scroll registers. Writes to $2005 only affect the background. For the sprites to scroll you have to manipulate their X and/or Y positions every frame. But you can also place sprites anywhere in the screen with pixel precision. The only thing you can't do with sprites is having them scroll smoothly from the left or from the top of the screen, as they can not have negative X/Y positions.
when you make emulation of nes... do you use classes for creating 6502 nes registers like x, y, a.?. or just can you use directly processor registers of x86 or another arquitecture in order to get fast speed?
You typically would make a subroutine/function/method to emulate the 6502 and then use local variables inside that. This may end up translating into host CPU registers, or it may end up translating into stack memory if you're on a register-starved architecture (such as x86).
i mean asm inline for c. just manually work x86 processor registers.. i see many emulators, but they need a lot of cpu power. the fastest is virtuanes. i think that coders dont take into account that emus would be running good in machines like pentium 3, 550 mhz.. (because in my machine, pentium 3, 550 mhz any emus are very slow). any nes emus need 800 mhz..
I run NES, SNES, Genesis/Megadrive and Master System emulators on an old K6II 533 I reassembled just for old games and they work very well. I may have trouble running Nintendulator, for example, but haven't tried.
There must be something wrong with your PIII. Too much spyware, maybe. Most of the time I use FCEU, ZSNES, GENS and DEGA with the computer I mentioned. The newest windows versions, and they still run full speed, even with the 4MB video card I put there.
I don't think you'll benefit much from using the x86's registers and flags. The slowest thing in an emulator of an old console like the NES is the rendering of the screen, I guess, with all the details you have to pay attention to to keep the emulator accurate. Well, I'm not an emulator author so I'd better shut my mouth before I say too much crap.
rendering slow?, yes. imagine... i made a script php for view one capture of .nam file of super mario bros. 1st version reading .nam and .chr was very slow (35 minutes in draw image by ie 5). now i make all work in memory. it take 1 minute 10 seconds. i process attribute table correctly
(thanks for your explanations tokumaru) then i can see accurate colors for background. i dont process sprite ram, then you can only see background. processing attribute table is a very funny routine in php, it was hard think on it, i read .nam 64 bytes after 960 bytes of one of four nametables. it generate a type of rare string, i translate string into binary, then i have a string with 64*8= 512 bits or positions, then i scan this string and i send attr tbl to memory detecting positions and 2x2 tile squares 0,1,2 and 3 creating a 32x32 matrix with a value of 2 bits for each position hehehe
.. then easily i say something like:
if im going to show tile in coords (y=32,x=30)..
get_4color_palette(attr_tbl[y][x],&$color0,&$c1,&$c2,&$c3,$arraypalette)
show_sprite_image($color0,$c1,$c2,$c3,pattern,nametbl,$arraypalette,.. )
when i have my webpage, i will show my html generated.
if you wanna to access one byte in 512 bit string:
$byte_number=1; //we want getting 1st byte
$byte_value=substr($byte_number, ($byte_numberx8)-8 , 8 )
PHP
--substr: extract a substring from string
--substr(string,start_pos. note that 1st string pos is 0,how many chars)
Yes, then you can see how complicated rendering can be. Of course, the speed of a compiled program running on it's native processor can't be compared to an interpreted scripting language such as php.
And with your php program you're just dealing with a static screen. You're not dealing with scrolling, mid-screen PPU operations, and other things that require you to use a scanline-based approach for rendering, instead of a block-based one. Well, you can see how complicated it can be.
I really believe you'll get much more speed from improvements made to PPU emulation than to CPU emulation.
what is the best language for emulator programming??
The best language for implementing a virtual machine is the language in which you can most easily communicate the behavior of the virtual machine to the compiler. If that's BASIC, then so be it. Most PC based NES emulators that I've read about are written in C.
i dont know very much about EPROMS.. if i buy eproms, i can saving prg or chr on it, but EPROMS not are rewritable in order to save my stuff, play my homebrew game on nes, clear my chip, and save my another stuff homebrew games i have to using EEPROMS (rewritable eproms), but can i use EEPROMS on nes boards???, or just it's limited to EPROMS?
and another question is : how can i put nsf in my demo??
im using nesasm.. which bank is best to say: .incbin "music.nsf" , imagine a music.nsf cut off in order to contain only 1 song... yeah i know 128 byte header of nsf.. i need init, play and another stuff.. but how can i implement it on code?? can you give me a quick explanation on it, how can i implement it??
thanks.
for what any games (nes roms on internet) say PRG 0 , PRG1.
example: super mario bros 3 [PRG0], super mario bros 3 [PRG1]?????
what is difference??
EPROMs and EEPROMs are pinout compatible. The only difference is that EEPROMs are Electricaly Erasable, and EPROMs are only Erasable, that mean you need a UV light machina to erase them.
Play an nsf would be nothing more complicated than this :
Code:
PlayNMI
jsr Init
*: jmp *
NMI
jsr Play
rti
The Init and Play ardress are found in the header.
Also, make sure that you ORG your include at the load adress.
I don't know by hear which byte # in the header is the load, play and init adress. Look at NSF format specifications by Neil Cornett.
lord_Chile wrote:
example: super mario bros 3 [PRG0], super mario bros 3 [PRG1]?????
what is difference??
It's a revision, the differences could be anything (bug fixes, or any other changes). I know Tecmo Bowl had a revision to change a player in the game, and Castlevania had one that changed at least one of the levels.
Super Mario 3 fixed a typo, and changed the names of the worlds in the ending. During the ending, the prg0 version displays the same names as the Japanese version, while the prg1 version uses the names found in the US instruction manual. So instead of "Ocean Side", "Big Island" and "Pipe Maze", they are called "Water Land", "Giant Land" and "Pipe Land".
Bregalad wrote:
Play an nsf would be nothing more complicated than this :
Code:
PlayNMI
jsr Init
*: jmp *
NMI
jsr Play
rti
You mean:
i will load from knowed address in nsf 128 byte header format, then
Code:
PlayNMI
jsr Init (i know format.. ok init address)
What mean: "*: jmp *"?
NMI
jsr Play (ok play address)
rti
can i say to NESASM jsr $8000?, because i will load nsf file, then it's binary file.
jmp * is an intinite loop. If you want to do anything else that playing the NSF, you can of course.
Yeah, you can either read the adress yourself and write them back in your asm file, but a more professional way to use indirect jump [$xxx] to jump to the specified adress in the header if you include it too. If you don't then do it manually.
Since the 6502 don't have inirect jsr [$xxx], you'll have to do this :
Code:
jsr IndirectInit
IndirectInit:
jmp [$800x]
For the load adress, you'll have to org it manually. I cannot have a automatic way to have it done. Also, you'll have to remove $80 from the load adress if you include the header. In most NSF it is $8000, so you'll most likely HAVE to not include the header.
i get it working nsf-nes conversion using DASM and covell script (nes music ripping).. but a strange problem is present.. when init and play dont be default values init=$8003, play=$8000 games doesnt work... i get working 2 nsfs to nes (batman and another catridge)......
double dragon 3.. nsf to nes i cannot get conversion.. some games having rare init or play like $BC03 (this extrange address doesnt work on covell script when i write it).. anyway, mnore later i will present you my conversion process and you will can see what im doing good or bad.. because dd3 doesnt work, i dont know,. it's new for me.. nsf
anyway, can give any details or things that only experts nsf man knows??
i dont mean that you teach me, i like reading very much! only tips. because i cannot get working on dd3 and i think that im doing correct all process because i get batman working.. it must be a detail that i dont know...
ps: any games says on header... 03BC, then i switch it.. because nsf format says lo/hi
lord
My question is about static status bar. Im trying make a status bar just like mario bros detecting sprite 0 hit in a part of the money. I can see static status bar while scrolling because i read a topic about it, i understand it, but my static status bar is flickering too much while scrolling. Can someone help to me on it??
I handle code in my main loop, i get vblank by bpl $2002.. it can be my mistake because it miss any frames, i know..
or just im doing something bad??.. My NMI handles to play songs loaded in first 16kb of prg, then i prefer make scrolling in my main loop.
I have loaded 2 nametables with vertical mirror. my scroll goes from a side to another.. and when it reaches the second nametable
it come back to first nametable, it's a loop.
Code:
xxxxx initialitation, etc
turn_screen_on:
include "SLPE/00.00_to2005.asm"
lda #%10001000
sta $2000
lda #%00011110
sta $2001
loop:
ldx #$00
.infin ; our infinite loop that make scroll
lda $2002
bpl .infin
.infin2
lda $2002
bpl .infin2
lda #$00
sta $2005
sta $2005
jsr w_sprite0_hit
inx
stx $2005
ldy $2002
ldy #%10001000
sty $2000
txa
cmp #$FF
bne .infin
inc sng_ctr ; inc song
lda #$00
sta int_en
lda sng_ctr
jsr INIT_ADD
lda #$01
sta int_en
.go_back
lda $2002
bpl .go_back
lda #$00
sta $2005
sta $2005
jsr w_sprite0_hit
dex
stx $2005
ldy $2002
ldy #%10001000
sty $2000
txa
cmp #$00
bne .go_back
inc sng_ctr ; inc song
lda #MAX_SONG ;Max Song.
cmp sng_ctr
bne .no_scr
lda #$00
sta sng_ctr
jmp loop
w_sprite0_hit:
bit $2002
bvc w_sprite0_hit
rts
lord_Chile wrote:
My question is about static status bar. Im trying make a status bar just like mario bros detecting sprite 0 hit in a part of the money. I can see static status bar while scrolling because i read a topic about it, i understand it, but my static status bar is flickering too much while scrolling. Can someone help to me on it??
I handle code in my main loop, i get vblank by bpl $2002
You meant the following, right?
Code:
:
bit $2002
bpl :-
Quote:
or just im doing something bad??.. My NMI handles to play songs loaded in first 16kb of prg
Vblank time is no time to play music. You have only 2200 cycles to upload all your graphics into the PPU; use them wisely.
Quote:
then i prefer make scrolling in my main loop.
You can do it that way too. Have your NMI handler write to a zero page location, and then do your test/branch spin loop on that. Then after you've done all the game logic, you can call the music player.
Quote:
I have loaded 2 nametables with vertical mirror. my scroll goes from a side to another.. and when it reaches the second nametable
it come back to first nametable, it's a loop.
You need to set the nametable horizontal base address bit (bit 0) of $2000 when the left side of the screen is in the second nametable.
The Sprite 0 hit flag doesn't clear at the start of VBlank, it clears at the end of VBlank. So if you check it before the end of VBlank and it yet in the previous frame, it will show high when you read it (even though it hasn't been hit in the upcoming frame yet).
To solve this, when waiting for Sprite 0 hit, unless you're 100% sure VBlank is over when you're checking... first wait for it to go low, then wait for it to come high again:
Code:
w_sprite0_hit:
: bit $2002
bvs :- ; wait for it to clear
: bit $2002
bvc :- ; wait for it to be set again
rts
Tepples said: "You need to set the nametable horizontal base address bit (bit 0) of $2000 when the left side of the screen is in the second nametable."
When it is??
I have left nametable and right nametable... x scroll increments from #$00 to #$ff. and then it decrements from #$ff to #$00..
Oh, more later i will ask to you something.. because i changue palette like smb1, i try imitate smb1 using smb1 nametables... i imitate sprite 0 hit (static status bar), i imitate sound handling routine.. but imitation of palette changue is difficult for me because i dont know which scroll values can i use in order to send to $2006 for restore scroll. (i made it manually, but i get small glitches)
More later, because i dont have internet in my home. thanks for all..
PS off topic: Nes asm is not so bad... I made a cnrom demo in nes assembler 2.51 hehe.. i will post it more later..
lord_Chile wrote:
I have left nametable and right nametable... x scroll increments from #$00 to #$ff. and then it decrements from #$ff to #$00..
When the scroll wraps from $ff to $00 (adc turns on carry flag or inc turns on zero flag), toggle bit 0 of the value that you write to $2000. Assuming cur_2000 is a variable in RAM, do this:
Code:
lda #%00000001
eor cur_2000
sta cur_2000
lord_Chile wrote:
imitation of palette changue is difficult for me because i dont know which scroll values can i use in order to send to $2006 for restore scroll. (i made it manually, but i get small glitches)
To restore scroll, do this:
Code:
lda #0
sta $2005
sta $2005
lda cur_2000
sta $2000
Currently, im working in a algorithm for convert from hex to binary (8 bits): I have programmed 3 algorithms (perfectly working and tested). I would like that if you have best methods for making this conversion, you can share it with me. I have tried each time get more speed. Idea is save each 1 or 0 in one space of 1 byte in order to show more easy it on screen. It is a simulation, using 6502 simulator, then .ORG $0000 would be changed when us are using nes addrs.
Code:
Algorithm 1:
; Program to convert hex 8bit to bin 8bit in 151 cycles
.ORG $0000
start:
LDA #$0A
JSR HexToBin8
BRK
HexToBin8:
LDY #$08
.check_end_routine
DEY
BMI .end_HexToBin8
.convert_HexToBin8
ROR
BCS .save_1
.save_0
LDX #$00
STX HexToBin8_output,y
JMP .check_end_routine
.save_1
LDX #$01
STX HexToBin8_output,y
JMP .check_end_routine
.end_HexToBin8
RTS
HexToBin8_output:
.DB $00,$00,$00,$00,$00,$00,$00,$00
-------------------------------------------------------------------------
Algorithm 2:
; Program to convert hex 8bit to bin 8bit in 137 cycles
.ORG $0000 ; Store machine code starting here
start:
LDA #$0A ; load hex number to convert
JSR HexToBin8
BRK
HexToBin8:
LDY #$07
.convert_HexToBin8
LDX #$00
ROR
BCC .save_0 ; you must use PHP, if you are using NMIS or it can fail
.save_1
INX
.save_0
STX HexToBin8_output,y
DEY
BPL .convert_HexToBin8
RTS
HexToBin8_output:
.DB $00,$00,$00,$00,$00,$00,$00,$00
------------------------------------------------------------------------
Algorithm 3:
; Program to convert hex 8bit to bin 8bit in 88 cycles
;(no counting rts, jsr = 12)
.ORG $0000 ; Store machine code starting here
start:
LDA #$0A ; load hex number to convert
JSR HexToBin8
BRK
HexToBin8:
LDY #$00
.convert_HexToBin8
ROL
ROL
TAX
AND #$01
STA HexToBin8_output+0
TXA
ROL
TAX
AND #$01
STA HexToBin8_output+1
TXA
ROL
TAX
AND #$01
STA HexToBin8_output+2
TXA
ROL
TAX
AND #$01
STA HexToBin8_output+3
TXA
ROL
TAX
AND #$01
STA HexToBin8_output+4
TXA
ROL
TAX
AND #$01
STA HexToBin8_output+5
TXA
ROL
TAX
AND #$01
STA HexToBin8_output+6
TXA
ROL
AND #$01
STA HexToBin8_output+7
RTS
HexToBin8_output:
.DB $00,$00,$00,$00,$00,$00,$00,$00
bitshifting moves each bit into the C flag. And bit rolling moves bits out of the C flag. The way I'd do it would take advantage of those two facts.
Assuming 'HexToBin8_output+0' is to receive the high bit:
Code:
HexToBin8:
LDX #$00
STX HexToBin8_output+0
STX HexToBin8_output+1
STX HexToBin8_output+2
STX HexToBin8_output+3
STX HexToBin8_output+4
STX HexToBin8_output+5
STX HexToBin8_output+6
STX HexToBin8_output+7 ;clear output
ASL A
ROL HexToBin8_output+0
ASL A
ROL HexToBin8_output+1
ASL A
ROL HexToBin8_output+2
ASL A
ROL HexToBin8_output+3
ASL A
ROL HexToBin8_output+4
ASL A
ROL HexToBin8_output+5
ASL A
ROL HexToBin8_output+6
ASL A
ROL HexToBin8_output+7
RTS
That's the "loops unrolled" version (faster, bigger). For the loop version (slower, smaller):
Code:
HexToBin8:
LDY #$00
LDX #$07
: STY HexToBin8_output,X
LSR A
ROL HexToBin8_output,X
DEX
BPL :-
RTS
EDIT - just realized -- STY only has zero page,X mode -- so that will only work if HexToBin8_Output is in zero page.
my question is for emulator developers in visual basic. what is the difference between:
1.-if (var1 and &H56)
2.- if (var1 and &H56&)
what mean ampersands??
1. &H56 is an Integer (2 bytes)
2. &H56& is a Long (4 bytes)
how super mario bros keep nametables?. where in rom start nametables?. how many nametables use smb?.
i did try seeing nametables in rom, but i didnt finding nametables starting with hex chain 24 24 24, etc...
I don't think SMB stores any screens in the exact form as seen in the name tables. That would take too much space. No serious game does it that way.
Mario's levels are stored compressed, in the form of rows of objects, if I remember correctly, and the data that goes to the name tables is generated on the fly as it decompresses the screens.
My question is about relative addressing:
Code:
$81FF = BNE
$8200 = +6
*
*
*
$8207 = RTS
My question is: OLD Program counter is $81FF? or $8200?. I want to determine page crossing, then
it's important for me.
[/code]
Branch behavior and page-crossing is concisely summed up in
another thread. In your example, OLD program counter is $8201 (the address of the next instruction).
1.- PHP set I flag? Then i can disable IRQs by PHP if i previously did CLI?
2.- If BRK is executed it save to stack PCH, PCL, Processor status and call IRQ. But I think that if BRK is executed and it call IRQ, software int IRQ wont save newly PCH, PCL and P. But when hardware int IRQ is executed it save the 3 values on stack. In another words...
Code:
Public Sub INT6502_IRQ()
If ((P And &H4) = 0) Then 'If I is clear, then accept int requests..
If (b_flag = 0) Then 'Is right this check?..
PCH = PC And &HFF00&
PCL = PC And &HFF
memory_write (&H100 + S), (PCH \ 256)
S = S - 1
memory_write (&H100 + S), PCL
S = S - 1
memory_write (&H100 + S), (P Or &H4) 'Set I flag, clear flag b
S = S - 1
End If
PCL = memory_read(&HFFFE&)
PCH = memory_read(&HFFFF&)
PC = (PCH * 256) + PCL
End If
Is right it?.
3.- I did read 6502 documentation. I understand that IRQ doesnt interrupt IRQ. But NMI can interrupt NMI. Is right that the one instruction that is interrupted before end is BRK ( in 4th cycle?). NMI are interrupted for NMIs, too?
I would trigger NMI on Vblank time.. and When i trigger IRQS??, how i can predict it? cycle=??
4.- I read in nesdev forums xx lines are vblank. But i dont understand. Nes resolution is 256x240 for NTSC. vblank definition is: "when light gun of tv draw last right bottom point of TV and it comes back to first TV point", then if i render 256 scanlines and i come back with light gun until fist point of first scanline i think that vblank are 256 scanlines!... can someone explain me for what it is said that vblank are 20 scanlines??..
1) PHP does NOT change the I flag.
2) Your example code is good for IRQs, but IRQs (as well as NMI, RESET, and BRK) set the I flag after the status is pushed (otherwise IRQs would fire nonstop). BRK operates exactly like an IRQ, only the 'B' status bit is set when pushed, and the I flag is ignored (BRK will still work even when I is set)
3) I don't understand this question
4) A "scanline" is one rendered line on the screen, but it is ALSO used as a measurement of time. 1 "scanline" = 341 PPU cycles. So when people say that VBlank is 20 scanlines long, that means VBlank is 341*20=6820 PPU cycles long.
3.- each how many cpu cycles, i execute irqs???
It's not a fixed amount of cycles. An IRQ happens only when triggered by one of 3 events:
1) the DMC (audio related). If the game enables DMC IRQs by setting $4010.7, an IRQ will happen just after the last DMC byte is fetched. Bee 52, The Guardian Legend, MiG 29 Soviet Fighter, and Fire Hawk are a few example games which use this method of IRQs. The latter two being especially picky about the timing.
2) APU frame IRQs. If enabled by clearing $4017.6 and also having the "4-step mode" set by clearing $4017.7, APU frame IRQs will fire roughly 60 times per second. See blargg's docs and test ROMs for exact timing information. The only game I know of that uses these IRQs is Shin 4 Nin Uchi Mahjong - Yakuman Tengoku, which uses them for its music driver.
3) The most common -- mapper related IRQs. Such as MMC3's scanline counter, which will fire on a specific scanline. There are hundreds of games which use mapper-driven IRQs, so I won't bother listing any.
Dragon Quest and Dragon Quest II uses IRQ for sound driver I think (but not Dragon Warrior u.s. counterpart).
Then i present my interrupt code to you. any documents are contradictory.
My new interrupt code is right logically??, flags setted and cleared right?
NMI, sets I flag no?
Code:
Public Sub INT6502_NMI()
PCH = PC And &HFF00&
PCL = PC And &HFF
memory_write (&H100 + S), (PCH \ 256)
S = S - 1
memory_write (&H100 + S), PCL
S = S - 1
memory_write (&H100 + S), (P And &HEF) 'Push B flag cleared
S = S - 1
P = P Or &H4 'Set I flag
PCL = memory_read(&HFFFA&)
PCH = memory_read(&HFFFB&)
PC = (PCH * 256) + PCL
End Sub
Public Sub INT6502_IRQ()
If ((P And &H4) = 0) Then 'If I flag is cleared
PCH = PC And &HFF00&
PCL = PC And &HFF
memory_write (&H100 + S), (PCH \ 256)
S = S - 1
memory_write (&H100 + S), PCL
S = S - 1
memory_write (&H100 + S), (P And &HEF) 'Push B flag cleared
P = P Or &H4 'Set I flag
S = S - 1
PCL = memory_read(&HFFFE&)
PCH = memory_read(&HFFFF&)
PC = (PCH * 256) + PCL
End If
End Sub
Case INS6502_BRK:
PCH = (PC + 1) And &HFF00&
PCL = (PC + 1) And &HFF
memory_write (&H100 + S), PCH \ 256
S = S - 1
memory_write (&H100 + S), PCL
S = S - 1
memory_write (&H100 + S), (P Or &H10) 'Set B flag
P = P Or &H4 'Set I flag
b_flag = 1
S = S - 1
PCL = memory_read(&HFFFE&)
PCH = memory_read(&HFFFF&)
PC = (PCH * 256) + PCL
Case INS6502_RTI:
S = S + 1
P = memory_read(&H100 + S) 'Each pop of P is restored with b flag= 0?, i assume it
b_flag = 0
S = S + 1
PCL = memory_read(&H100 + S)
S = S + 1
PCH = memory_read(&H100 + S)
PC = (PCH * 256) + PCL
PC = PC + 1
Yes, when any interrupt (NMI, IRQ or even RESET) is detected the status register is saved on the stack after the adress, THEN the I flag is automatically set.
what is the utility of nes constants like nes src freq = 21477272.7272 and nes freq ntsc = 1789772.7272.
when i use this contants??
how many cycles by second my nes cpu have to execute in 1 second???
i want synchronization in my nes simulator.
can someone speak me about it??..
The main clock is 21,... MHz. If you divide if by 4, you found the PPU clock, and if you divide it by 12, you get the CPU clock. This makes the CPU clock is 3 PPU clocks.
That is only valid in NTSC. In pal, all frequencies and division ration are totally different.
1.- how many cycles by second my nes cpu have to execute in 1 second???
2.- nes games are assembled with brk = 1 byte?
but emu assume brk 2 bytes because if brk is assembled like 1 byte, i must expecting that programmer manually decrease return address? (brad taylor 'b flag)
then "interrupt routine called by brk always return 2 bytes after actual brk opcode"? is right it?
1) "1789772.7272 cycles per second" means that in 1 second, the CPU executes 1789772.7272 cycles. (must be some kind of language/translation problem here)
2) The address pushed to the stack on BRK is one higher than expected. So when the game RTI's from a BRK, it will return two bytes after BRK:
Code:
BRK
NOP ; RTI will not return here -- this byte is skipped
LDA #$00 ; RTI will return here!
The most obvious test case for BRK behavior is as follows:
Code:
clc
brk $38 ; $38 is the opcode for instruction SEC
bcs incorrectBRKBehavior
A non-conforming disassembler sees this, turning the $38 into
an opcode:
Code:
clc
brk
sec
bcs incorrectBRKBehavior
The disassembler in the Apple II/II+/IIe/IIc BIOS treated BRK as a 1-byte instruction, and so did the mini-assembler in Integer BASIC and the enhanced IIe. Later, when they both were extended to support 65C816 instructions for the Apple IIGS, the BRK interpretation was corrected at the same time.
But do any NES games actually use the BRK opcode?
Thanks to disch for explain loopy docs, i understand format, but i can see a exception here:
2000 write:
t:0000110000000000=d:00000011
2006 first write:
t:0011111100000000=d:00111111
t:1100000000000000=0
---??? what mean this line??, it is not = d (data).
It is =0?, i dont understand
t:1100000000000000=0
That means the high 2 bits are filled with 0 ($FFFF becomes $3FFF)
I assume (ppu_ctrlreg_1 And H4) =0...
Vram access test of blargg said that "SansaNES" (my emu) fail with error 6 (blargg_ppu_tests_2005.09.15b).
Error 6 is "Palette read should also read VRAM into read buffer".
Then, now i am analyzing blargg asm code in order to see where my knowledge and logic fails, please if any expert can help me
and see where i fail in my analyze, i will be happy, thanks. I start from reset...
Code:
set_vram_pos:
'this set vram_pos at $2f00 + A
'i wont write it for space
reset:
lda #6
A=#$6
sta result
result= #$6
lda #$12
A=#$12
jsr set_vram_pos
vram_pos=$2F12
lda #$9a
A=#$9A
sta $2007
VRAM[$2F12]=#$9A
vram_pos= incremented to $2F13
lda $2007
It is not palette, then i use a "vram buffer"
A="vram buffer"
vram_buffer=VRAM[$2F13] ("i dont know what contains buffer")
vram_pos= incremented to $2F14
lda #$3f
sta $2006
lda #$12
sta $2006
vram_pos=$3F12
lda $2007 ; fills buffer with VRAM hidden by palette
It is palette, then i dont load from "vram buffer"
A=VRAM[$3F12] ("now, i dont know what contains A")
vram_pos=incremented to $3F13
lda #$13 ; change back to non-palette addr to enable buffer
A=#$13
jsr set_vram_pos
vram_pos=$2F13
lda $2007
It is not palette, then i use a "vram buffer"
A= VRAM[$2F13] (last vram buffer did contains it)
vram_buffer=VRAM[$2F13] (last vram pos is $2F13 no?)
vram_pos= incremented to $2F14
"Here i assume that blargg says: if A=#$9a then test is passed.
cmp #$9a
"But VRAM[$2F13] never can contains #$9A
since i never did send #$9A to it. VRAM[$2F12] contains #$9A.
Then test never is passed, but Nintendulator and FCEUdx did pass this test.
What am i doing bad??? ps: First beta schpune of disch,
didnt pass this test. The test contains errors?
jsr error_if_ne
lord_Chile wrote:
I assume (ppu_ctrlreg_1 And H4) =0...
Vram access test of blargg said that "SansaNES" (my emu) fail with error 6 (blargg_ppu_tests_2005.09.15b).
Error 6 is "Palette read should also read VRAM into read buffer".
Then, now i am analyzing blargg asm code in order to see where my knowledge and logic fails, please if any expert can help me
and see where i fail in my analyze, i will be happy, thanks. I start from reset...
asm code deleted
Just for reference, the answer is here:
http://nesdev.com/bbs/viewtopic.php?t=1721
Thanks disch, thanks guys.
Today i bring a new question. My emu didnt pass many blargg timing test, then i decide increase accuracy. I am programming my cpu emu cycle per cycle. I get official manual 6502.
It says:
Code:
Example 5.3: Illustration of implied addressing
clockcycle addrbus PC data bus comments
1 PC PC+1 opcode fetch opcode
2 PC+1 PC+1 new opcode ignore new opcode;
decode old opcode
3 PC+1 PC+2 new opcode fetch new opcode;
execute old opcode
Notes: 2nd cycle: the memory fetch is worthless and any PC increment is supressed.
Then my questions:
1.- for what we can see three cpu cycles, if implied addressing is 2 cpu cycles?
2.- the third cycle is taken in account for calculate cpu cycles?
3.- the third cycle is for internals operations of cpu but it is not from implied addressing?
4.- do i execute opcode instruction (lda, etc) immediatelly after fetch and decode it or i do buffer execution?
I did imagine a type of buffer for execute old opcodes, but if a new opcode is not executed, then
old opcode never execute: example
LDA
#$40
(I did pass for here but i didnt execute LDA, only fetch it)
NOP
"nop" is new instruction, i fetch and save it, i know addressing for this instruction too.
now i execute old opcode LDA and addressing mode.
(imagine that LDA be last instruction and nop doesnt be here: LDA never will be executed)
Implementing this is overhead and i am not sure that 6502 behaviour is like it.
Can you giving clear to my ideas??
6502 instructions are pipelined by 1 cycle - when you do "LDA #$FF", the first cycle grabs the opcode (A9), the second cycle loads the operand (FF), and the 3rd cycle copies the operand (FF) into the accumulator while fetching the next opcode. For emulation purposes, the "copy operand to accumulator" can be performed at the end of the 2nd cycle (actually emulating the pipelining is unnecessary, since the software can't tell the difference AND it'd be slower).
i am new in direct x. I was using gdi (but it's slow). setpixel was the procedure in order to put a pixel on screen.
But, emulator authors use pixel per pixel render?
what procedure set a pixel on screen using direct x?
do i use direct 3d? im confused
or i use direct draw for render?
i wanna good render speed.
i will use directx 8.
lord_Chile wrote:
But, emulator authors use pixel per pixel render?
what procedure set a pixel on screen using direct x?
do i use direct 3d? im confused
[...]
i will use directx 8.
In DirectX 8, you build a texture representing the screen as an array of pixels, and then you draw the texture to the screen. DirectX 8 doesn't have DirectDraw except as a wrapper around Direct3D.
I did read brad taylor documents, but im a little confuse. About sprite 0 hit and ppu timing.
1.- ppu fetch valid data during 256 ppu clocks and at end of clock 256 it send valid pixel data to video output for render? or ppu fetch one valid data and immediatelly send it to video output pin?
2.- Sprite 0 hit with no transparent background collision is detected using temporary memories (in fetch time)? or when video contents are being drawed (in rendering real time)?
3.- At end of 256 ppu clock do i wait for "one delay (16 ppu cycles - fine horizontal scroll)" in order to wait for sprite 0 collision?, or when i wait for this delay?
lord_Chile wrote:
or ppu fetch one valid data and immediatelly send it to video output pin?
I don't know how "immediate" it is. But the PPU will output 1 pixel every PPU cycle. (1 cycle = 1 pixel). Since there are 256 rendering cycles, this means 256 pixels are output.
Quote:
or when video contents are being drawed (in rendering real time)?
This is right.
Sprite 0 hit will happen on the cycle the sprite 0 pixel is being rendered.
Quote:
3.- At end of 256 ppu clock do i wait for "one delay (16 ppu cycles - fine horizontal scroll)" in order to wait for sprite 0 collision?, or when i wait for this delay?
This delay does not really affect sprite 0 hit at all. (It's not even really a "delay").
The PPU has to have a tile fully ready to draw before it can actually start drawing it. Because of this, tiles need to be
loaded some time before they're actually
rendered.
Here is a little diagram to help portray the idea:
Code:
Scanline Cycles What is happening
--------------------------------------
0 320-327 PPU loading 1st tile for scanline 1 (no pixels output)
0 328-335 PPU loading 2nd tile for scanline 1 (no pixels output)
0 336-341 PPU performing dummy reads (no pixels output)
1 0-7 PPU loading 3rd tile for scanline 1 (output proper pixels from 1st+2nd tiles)
1 8-15 PPU loading 4th tile for scanline 1 (output proper pixels from 2nd+3rd tiles)
Once the tiles are loaded, they're stored in a temporary shift register until the pixels are actually output.
My emu fails when i load super mario bros. I can see background, sprite 0 hit has good y coord, but mario sprites has 248=y coord everytime. I dont see super mario sprite. Ballon fight works fine. what can be the problem??
my problem was sbc inst of cpu. i fix it.
Im trying emulate mapper 7 for battletoads. All is right, but one screen mirroring is emulated with errors. I dont understand... if bit says: mirror from $2400, or mirror from $2000 what is the difference?..
If is mirror from $2400:
1.- If i write to nametable address $2003.. whaT HAPPEN?
If is mirror from $2000:
1.- If i write to nametable address $2403.. whaT HAPPEN?
Actually i copy all $2400 nametable area to another 3 nametables
if is mirror from $2400..
and if is $2000 copy all from $2000 to another nams.. But it appears that there are errors in my logic because text are joined on screen when i execute game.. example:
Licensed by Nintendo
A Rare Production..
I dont want a rare production, i dont know from where comes it.
Someone can explain me one screen mirroring with more detail???
The "Mirror from $2000" and "Mirror from $2400" descriptions are misleading. What really happens is that all four pages $2000, $2400, $2800, and $2C00 are mirrored from page LO or page HI depending on the mapper setting.
1.- mmc1 ports are 1 bit.. But if i wanna reset register 0 i would write eight times to register 0, no? But what values are written to bits 5 and 6 (unknow bits)??
$8000 - $9FFF (Register 0)
RxxCFHPM
When i write first 5 bits, register is ready to execute.. i think..
Someone can explain this to me, please?
2.- mmc3 bankwitch are 8kb for prg.... but i have problems switching vrom..
If command is 3, The $8001 page number assume 1024kb vroms pages??
by example if rom have 2 pages of chr, each one 8kb, Then max value for $8001 is (2*8)-1=15???
lord_Chile wrote:
1.- mmc1 ports are 1 bit.. But if i wanna reset register 0 i would write eight times to register 0, no? But what values are written to bits 5 and 6 (unknow bits)??
MMC1 ports are 1-bit, but you write
five times to register 0. The upper bit just resets the shift register and twiddles some bits in register 0.
Quote:
$8000 - $9FFF (Register 0)
RxxCFHPM
When i write first 5 bits, register is ready to execute.. i think..
Someone can explain this to me, please?
That depiction is misleading. There's nothing 8-bit about any of the MMC1 registers.
The wiki article is easier to understand IMHO.
Quote:
2.- mmc3 bankwitch are 8kb for prg.... but i have problems switching vrom..
If command is 3, The $8001 page number assume 1024kb vroms pages??
by example if rom have 2 pages of chr, each one 8kb, Then max value for $8001 is (2*8)-1=15???
A lot of the mapper docs out there are severely outdated. Does the wiki agree?
why are all these questions in 1 long thread? having different smaller threads with topics makes it alot easier to search. but..... the search is broke.... maybe 1 indefinite thread is better.
Hi. Today my question is about mapper MMC3. My emu fails to execute double dragon 3 (sacred stones).
My emu executes all good (title screen) until where it is starting to say press start. I did debug my emu.
Problem I think is that bankswitch in order that BANK_A=$1A000 never is completed.. Then take a look to my
comments in debug:
(Note: branches are ok, they are relative, but i did a simple debug
and i want minus kb for the file, then any op dont have registers or addresses)
Only the most importants parts for understand are here.
We are executing code
Code:
$FF25: A9 LDA #$1 A:0 X:BC Y:5F P:32
$FF27: 8D STA $6D8 A:1 X:BC Y:5F P:30
$FF2A: A9 LDA #$7 A:1 X:BC Y:5F P:30
$FF2C: 8D STA $A2 A:7 X:BC Y:5F P:30
$FF2F: 8D STA $8000 A:7 X:BC Y:5F P:30
(We can see that STA $8000 is sended with command number 7, then i will be waiting STA $8001 to select BANK A)..
Theorically for select bank A=$1A000, i have to send value 13 ($0D) because DD3 has around(8*2)=16 banks of 8kb..
But after $FF2F is executed, one NMI is triggered!
***NMI TRIGGERED***
Code:
$FF5F: 24 BIT $A3 A:7 X:BC Y:5F P:34
$FF61: 10 BPL
$FF6B: 50 BVC
$FF6D: 4C JMP $E070 A:7 X:BC Y:5F P:76
$E070: 48 PHA
$E071: 8A TXA
$E072: 48 PHA
$E073: 98 TYA
$E074: 48 PHA
$E075: 20 JSR $FE75 A:5F X:BC Y:5F P:74
$FE75: A9 LDA #$0 A:5F X:BC Y:5F P:74
$FE77: 8D STA $2003 A:0 X:BC Y:5F P:76
$FE7A: A9 LDA #$2 A:0 X:BC Y:5F P:76
$FE7C: 8D STA $4014 A:2 X:BC Y:5F P:74
$FE7F: 60 RTS
$E078: E6 INC $A8 A:2 X:BC Y:5F P:74
$E07A: A6 LDX $AB A:2 X:BC Y:5F P:74
*
$FC59: 20 JSR $FF1B A:5 X:FF Y:0 P:74
*
* We still in NMI, i think that this code is called from NMI, too
$FF2F: 8D STA $8000 A:7 X:FF Y:0 P:74
$FF32: BA TSX
$FF33: BD LDA $1ED,X A:7 X:EB Y:0 P:F4
$FF36: A ASL A
$FF37: 9 ORA #$1 A:2 X:EB Y:0 P:74 (registers before opcode processed)
$FF39: 8D STA $8001 A:3 X:EB Y:0 P:74 (registers before opcode processed)
(here STA $8001 send 3 in order to BANK_A=$6000
$FF3C: A9 LDA #$6 A:3 X:EB Y:0 P:74
$FF3E: 8D STA $A2 A:6 X:EB Y:0 P:74
$FF41: 8D STA $8000 A:6 X:EB Y:0 P:74
$FF44: BD LDA $1ED,X A:6 X:EB Y:0 P:74
$FF47: A ASL A
$FF48: 8D STA $8001 A:2 X:EB Y:0 P:74
$FF4B: A9 LDA #$0 A:2 X:EB Y:0 P:74
$FF4D: 8D STA $6D8 A:0 X:EB Y:0 P:76
$FF50: 68 PLA
$FF51: AA TAX
$FF52: 68 PLA
$FF53: CD CMP $BFFF A:1 X:FF Y:0 P:74
$FF56: D0 BNE
$FF58: 60 RTS
$FC52: 60 RTS
$E0A2: 4C JMP $E169 A:1 X:FF Y:0 P:77
$E169: 68 PLA
$E16A: A8 TAY
$E16B: 68 PLA
$E16C: AA TAX
$E16D: 68 PLA
$E16E: 40 RTI
***NMI ENDS***
$FF32: BA TSX
$FF33: BD LDA $1F9,X A:7 X:F7 Y:5F P:A0
$FF36: A ASL A
$FF37: 9 ORA #$1 A:C X:F7 Y:5F P:20
$FF39: 8D STA $8001 A:D X:F7 Y:5F P:20
(Here is right value=13 to select in bank A. Remember $8000 at start of code (It is the complement of this!),
but since NMI was triggered. NMI did send value 3 to $8001, also NMI change $8000 command number to 6!
and now BANK_A=$6000 (3*8192) (incorrect address), then game crashes)
How can i repair it?.
If i write to $8000 command 7, but just after it NMI is triggered and i cannot complete my next $8001
to execute command. And NMI uses $8000 and $8001 newly. what can i do?. My problem is bad timing?
I am ok with nmi supression.
Know guys?, when dd3 rom crashes, i patch it doing PC=$FF53 and manually doing a bankswitch using $0D for A=$1A000
and game run good!, but i dont like patches...
what is so hard about starting a new thread ?
It makes more little threads to scroll through when looking for a specific old thread. Trust me, he's doing us all a favor.
since im newbie, i dont want many threads with my basic questions, it is more easy for nesdev people read all my basic questions in this only thread.
Please answer my question about double dragon 3
Your problem is quite bizare. It looks just like a bug in the game (normally, the game would disable NMI while writing to the mapper just like MMC1 games does when writing to the serial ports).
Maybe your speed isn't exact, maybe you're emulating the PAL card in NTSC or vice-versa.
Hi, a question. Im newbie in directx, i did read many things about directx, then i think use directx 7 for my emulator. I dont want to use direct3d (direct8), then i will use directdraw 7 for now. But i did start my emu using GDI. In GDI i send RGB Colors (32 bit long values) to one matrix of pixels and then i use one function to show it on screen. It is slow, but i dont know how to start with directx. I understand surfaces, backbuffer and primary buffer, flipping, rects. I did search 2d directdraw examples in visual basic 6, but all examples create one surface from file (to load sprites and backgrounds from bmp files). You know that in emulators sprites and background are taken and we send pixels to screen in runtime.
Then surfaces only accept bitmaps?... i did think in create bitmaps at start of the game reading the chr. But the problem is when game uses chr ram and another problem is how i change the palette of created bitmap?. Can you give me one logic pseudocode to make it?, how you implement directdraw in your emu?, I dont want directdraw code, i know it, but i want that you can give me one idea about how sending 32 bit (Long RGB) pixels in runtime to one surface in order to show it one screen. there is a method for make something similar like when i did use GDI?:
1.- sending rgb values to one matrix
2.- show it on screen using Blt
lord_Chile wrote:
1.- sending rgb values to one matrix
2.- show it on screen using Blt
If you're using DirectDraw7 windowed, it's pretty much exactly as you described - you Lock() the secondary surface, write raw RGB data into the array provided (lpSurface), Unlock() it, then finally Blt() it into the primary surface (or Flip(), if you're doing fullscreen).