EDIT: ok i try write in english. thank you for your time and over all to tokumaru for give a possible solution.
in the post i said that the problem i have is that my emu write in the frame only color cero and only draw image grey, all the times.
i have seen that the emu have ever only ceros in tables, name and atributte and palettes. The pattern tables seem loaded.
p.d: i use a translator for the bocabulary...jaja (jaja is universal)
The information you gave was very vague. If it only shows color 0 there could be a million of things going wrong. For all we know, the CPU core could be bad and the games don't even get the chance to write usefull information to the palettes, tables, etc.
How well does your CPU core work?
About the spanish... I don't know if the moderators will have anything against it, but if you can read english, wich means you know some, you should try and write in english anyway. There are users here that are not very good on the english. I, for example, make several mistakes, as my first language is portuguese. Lord Chile writes very strangelly, but people manage to understand him. You're likely to get more responses by writing in english, but that's my opinion.
Quote:
About the spanish... I don't know if the moderators will have anything against it, but if you can read english, wich means you know some, you should try and write in english anyway. There are users here that are not very good on the english. I, for example, make several mistakes, as my first language is portuguese. Lord Chile writes very strangelly, but people manage to understand him. You're likely to get more responses by writing in english, but that's my opinion.
Spanish version:
Creo que lo que dice él esta bien, es un foro en inglés, yo también hablo español y mi ingles no es muy bueno, pero trato de darme a entender.
Escribí en ingles y la gente seguro te va a entender.
Si no conocés mi acento es porque soy argentino.
Saludos.
Versión en ingles:
I think what he says is pretty well, this is an english forum. I speak spanish too and my english is not to good, but i try to express my self the best i can.
You should write in english and the people here sure will understand you.
cisco, your english message is very understandable, so don't worry.
But you didn't answer me... =)
If it's all zeroed out, most likely the program (game) is not writing a thing to those memory locations. You must be sure your CPU core is working well. You should debug it somehow to follow the program flow, and see if the writes to the PPU are beeing executed at all. If they are, then it's a PPU bug, if not, it's a CPU bug.
The fact that pattern tables are loaded does not mean much, as most of the time they come ready from the ROM image, unless the game uses CHR RAM, wich I don't think is the case here.
You must be more specific... what game are you trying? The information you gave is still pretty vague.
Well, you still have to put some step by step debugger, or log (easier), so you can follow the program flow and find out where/if things go wrong. Compare it to the program flow of a working emulator and maybe you'll see what yours is doing wrong.
i don´t now what good is my cpu emulator
i have used nestest.nes for testing the cpu, my emu starts the program, initial pc, in address 0xc004, where the memory have 0x78, this opcode is SEI or no?, but i have done the same test with another emu, how you said me, and he shows initial pc = 0xc004, same that mine, memory[0xc004]=0x78 that mine but he starts with instruccion BEQ !!! why??
when nes starts after load the rom, what is the things to do??
load rom
interrupt_reset
executing_cpu
that is correct???
Yes, $C004 is the correct place to start and $78 is SEI. This is to prevent IRQ's. After you have loaded a ROM, set the program counter to the reset vector (i.e. pc = memory[$FFFC] + memory[$FFFD] * $100). Since nestest.nes has only 1 page of PRG make sure that you load it at both $8000 and $C000. As for the other emulator's BEQ, that I can't explain.
yes,two banks of prg are loaded with the same 16Kb.
any emu with good debugger???
i put the instructions that they are facts when load nestest
1-SEI
2-CLD
3-LDX
4-TSX
5-LDA
6-BPL
7-opcode 0x02
8-AND
9-opcode 0xC7
etc....
any instructions after , cycling with BRK-RTI, all this without take any button.
cisco wrote:
6-BPL
7-opcode 0x02
There's your problem. You must not be handling branches correctly. Just a bit into the program... the ROM has:
AD 02 20 10 FB AD 02 20
which is:
Code:
LDA $2002 (AD 02 20)
BPL $FB (10 FB)
LDA $2002 (AD 02 20)
The branch, should jump back to that first LDA instruction. You seem to be branching
FORWARD $FB bytes... but branches are in fact signed... so with $FB you want to branch
backwards 5 bytes ($FB = -5, not +251)
In an emu, this is as easy as typecasting the byte to a signed char:
Code:
if(branch_condition_true)
{
PC += (signed char)operand;
}
Disch wrote:
You seem to be branching
FORWARD $FB bytes... but branches are in fact signed... so with $FB you want to branch
backwards 5 bytes ($FB = -5, not +251)
In an emu, this is as easy as typecasting the byte to a signed char:
Code:
if(branch_condition_true)
{
PC += (signed char)operand;
}
And handle page crossing delay like this:
Code:
if(branch_condition_true)
{
int oldPC = PC;
/* eat one cycle to compute destination address */
CPU_Read(PC);
PC += (signed char)operand;
/* if the addition carried, eat another cycle */
if((oldPC ^ PC) & 0xFF00)
{
CPU_Read((PC & 0x00FF) | (oldPC & 0xFF00));
}
}
thanks, now ciclyng in bpl-lda. But i continue without having nothing in the name/atributtes/palette tables, when write this dates the program in this tables?? i think that they do it with the code, i mean that they have been loaded with the code....mmmm i don´t know explain me..... should do somewhat the code in special for load this tables???
disch, the mistake of the branch is for use java, that not have unsigned and i use int.
LDA $2002
BPL $FB
is a common "wait for VBlank" loop. If you do not have $2002 emulated in your emu, simply have $2002 return a value of $80 -- that should get the rest of the ROM running.
1-any body can say me when write the nestest bytes in sprites/tiles palettes?? or write bytes in name tables?
2-this algoritm is correct for PAL ?????
_make_reset
_for 106,52 cpu cycles do
___execute_instruction_cpu
_end for
_if scanline is 0
___prerender scanline
_else if scanline is betwen 1 and 240
___render current scanline
_else if scanline is 241
___draw frame ( using dummy scanline to do it )
_else if scanline is 242
___set bit 2002.7
___if 2000.7 is one then
_____make_nmi
_____for 106,52 * 70 scanlines do
_______execute_instruction_cpu
_____end for
___end if
___clean_bits_2002.5/6/7
_end if
3-what happend when x=0 and make DEX??
x=0
DEX
x=?? wrap?? maybe 255??
anybody can answer to me???
al least, say me if the algorithm may works
your questions are very difficult to understand. i suggest trying it and see what happens. if you dont have a ppu or cpu then i would just work on the cpu and get that working. you can out put that to a file and compare the output to this....
http://nesdev.com/bbs/viewtopi ... ht=nestest
matt
yes, i saw this post any times , but the link about logs don´t work , i will read again. have you the logs??
when i question about algorithm i mean in general, not for nestest. i want know if i have any problem with cycles or if i haven´t any call to any functionality.
blarggs is still there, try that. i might not have the one from quietust, i can look later.
i dont know that i can help too much with your algorithm as i am still working on mine. i would suggest that you understand the difference between cpu and ppu clock cycles. and dont mix cpu and ppu in the same loop. i would write some code and learn from it. start with the cpu.
matt
if i have code of cpu and ppu but i try know why not show graphics, therefore i questioned for the moment when nestest writes in tables, but now with block.nes ( thanks to your post ) i am debugging to search the problem....
apart of clear happened anything if mix cpu and ppu in the same loop???
suppose that no ,no? and the cycles, if only mark the cpu cycles only loss accuracy , no??
if i conform with shows graphics, jeje
your replies here are most difficult to read and understand.
you can work on the cpu without the ppu, just dump to stdout or stderr, and redirect to a file. thats what i did.
then work on the ppu. i am still working on mine so i dont think i can help much.
matt
"your replies here are most difficult to read and understand."
jajaja,i know, sorry, but i am spanish and don`t speak very well in english.
thanks by trying to help me.
have you used BLOCK.NES demo???
can you tell me what is the "block table"??
;block table [$20 entries] ($100 bytes, $F000-$F0FF)<---see it at final of block.txt
i have used blocks.nes, not sure what you are asking.
in bolck.txt there is the nes asembly code, in final of text there is tables of bytes: BG blocks , Block Table and palettes.
palettes are the sprite palette and background palette
bg blocks are blocks for background
and block table?? in what address of vram must be write??
when execute this demo, my name tables $2000 and $2400 has a lot of $24, what have appear in name tables??? "bg blocks"???
p.d:"bg blocks" there are bottom of block.txt
EDIT: I see that you don´t undestand what i want....
only want know what bytes there will be in name tables in the vram
EDIT 2:mmm i responded myself....
$24 is SMB1's space character.
i have verified that the problem there isn´t in cpu code,
vram have the data of background, then the problem is in ppu code, i think.
the emu runs some demos, but very badly, i have seen that after scanline rendered of background rendered a scanline all with transparent color ( color used to transparence ), i think i have badly implement the scroll.
with registers $2005 and $2006 the posicion is established for begining to render, establishing X,Y,NT,xfine and yfine.
when a pixel is rendered xfine is increased in 1 and when have 7 wrap around to 0 and X increased in 1 and when it have 31 wrap around to 0 and low bit of NT is swapped
when scanline is rendered (when occuring HBlank) yfine is increased in 1 and when have 7 wrap around to 0 and Y increased in 1 and when have 29 wrap around to 0 and high bit of NT is swapped
with NT is obtained the name table, according to mirroring
and the address of tile index would be : nameTable[NT] + Y<<5 + X
and finally with yfine and xfine set the pixel into tile
it´s ok all this?????
in "The Skinny on NES Scrolling" by loopy, put:
scanline start (if background and sprites are enabled):
v:0000010000011111=t:0000010000011111
according this, address is: nameTable[01] + $1f ??????
other questions:
register $2005 is only for scroll or can be use for read/write in the vram with $2007???
and when is activated bit 4 of $2002???? (bit of ignore writes in vram)
with nameTable[NT] is physical address of name table
cisco wrote:
it´s ok all this?????
yfine should not be an actual value -- but rather bits 12-14 of the ppu address determine the fine y scroll.
So after every scanline you'll want to do something like:
Code:
if( (ppu_addr & 0x7000) == 0x7000 )
{
ppu_addr &= ~0x7000; //wrap fine Y scroll to 0
//fine Y wraps .. increase Y
if( (ppu_addr & 0x03E0) == 0x03A0 ) // wrap at 29, toggle NT
ppu_addr ^= (0x03A0 | 0x0800);
else if( (ppu_addr & 0x03E0) == 0x03E0 ) // also wrap at 31, but don't toggle NT
ppu_addr ^= 0x03E0;
else // no wrap, just increase
ppu_addr += 0x0020;
}
else // fine Y didn't wrap -- just increase
ppu_addr += 0x1000;
Also -- fineX never
really changes except on the first $2005 write. But for purposes of emulation, you should be okay with counting it up every pixel -- just be sure to reset it properly between scanlines (you might get some minor distortion in games that change it mid-scanline though).
What you have to understand is that the 'ppu_addr' in the above example is the SAME ppu address that is used with $2006. That is... the same address that is used for $2007 read/writes
is also used for fetching tiles for rendering.
Quote:
in "The Skinny on NES Scrolling" by loopy, put:
scanline start (if background and sprites are enabled):
v:0000010000011111=t:0000010000011111
according this, address is: nameTable[01] + $1f ??????
Loopy's example there is how the X scroll is reset every scanline. In code, this will probably look something like:
Code:
ppu_addr = (ppu_addr & ~0x041F) | (ppu_temp & 0x041F);
ppu_addr being Loopy's 'v', and ppu_temp being Loopy's 't'
Quote:
register $2005 is only for scroll or can be use for read/write in the vram with $2007???
Both. Although because $2005 never changes ppu_addr directly, it's hard (but not impossible) to use it that way.
Quote:
and when is activated bit 4 of $2002???? (bit of ignore writes in vram)
Never. As far as I know that bit doesn't really exist.
OOOOOOH!!! you are big Disch , very big......
ppu_addr = (ppu_addr & ~0x041F) | (ppu_temp & 0x041F);
this was my problem.......( one of them , jaja )
now in some demos can see the image, and i have problems with color, the colors of sprites are correct but the colors of background no.....
thank you disch for your explanation, first the branchs and now helps me with this.....you are big, very big.......jajaja
now, i fixed color and another problems that i had, but i haven´t scroll
i read in an occasion, that nes rendered 34 tiles/scanline, it don´t i do
not render this two extra tiles affects at scroll????
fetch 34.
if the horizontal scroll is zero then only 32 are used.
if there is a horizontal scroll the part of the left tile and part of the rigth tile are used and the 21 in the middle are used.
i think am right as i just got scrolling working last week.
matt
when cpu reads register 2002 , registers $2005 and $2006 has writen whith 0, this mean that loopy_T and loopy_V will be 0 too?????
if i clean 2005 and 2006 when cpu reads 2002 scroll don´t work me but if i don´t clean registers scroll works fine, what is the problem???
cisco wrote:
when cpu reads register 2002 , registers $2005 and $2006 has writen whith 0,
No no. Reading $2002 does not change $2005 or $2006
What happens is the
toggle is reset... meaning the next write is the "first" write (the registers themselves are not changed).
Example:
Code:
STA $2005 ; first write
STA $2005 ; second write
STA $2005 ; first write
BIT $2002 ; reset toggle ($2005 not changed!)
STA $2005 ; FIRST write -- not second
STA $2005 ; second write
that explains many things, thanks
i am testing with NEStress and the cpu test, fail this:
ADC -> v flag
sbc -> v flag
cpx -> v flag
cpy -> v flag
brk return adr -> error
1- how do I put the condition for the flag v works???
i have this: if ((short)tmp > 0x7f || (short)tmp < -0x0080)
is java and tmp is int
2- cpx and cpy error in v flag?????????
3-what is the return address in brk???? the address of return is in stack and pop it using rti , don´t?
cisco wrote:
ADC -> v flag
sbc -> v flag
for ADC, V flag is set when:
Positive + Positive = Negative
or
Negative + Negative = Positive
and is cleared on all other conditions.
for SBC, it's:
Positive - Negative = Negative
or
Negative - Positive = Positive
and is cleared on all other conditions.
In code this can be implimented like so:
Code:
/* for ADC */
v_flag = (temp ^ val) & (temp ^ A) & 0x80;
/* for SBC */
v_flag = (A ^ val) & (A ^ temp) & 0x80;
where:
A = the accumulator (before addition/subtraction)
val = the value being added/subtracted
temp = the accumulator AFTER addition/subtraction
that code will set v_flag to 0 when the V flag is to be cleared, and will set it to nonzero (0x80 to be exact) when it's to be set.
Quote:
cpx -> v flag
cpy -> v flag
CMP, CPX, and CPY do
NOT change the V flag in any way.
Quote:
brk return adr -> error
BRK has a padding byte after it. the address pushed to the stack on BRK is 1 higher than you might expect.
for example:
$8000: BRK
$8001: NOP ; <-- this byte is skipped!
$8002: LDA #$01 ; <-- BRK will actually return HERE after RTI
Disch wrote:
BRK has a padding byte after it. the address pushed to the stack on BRK is 1 higher than you might expect.
Which is why, for instance, the Apple IIGS computer's built-in disassembler treats BRK as a two-byte instruction. A disassembly might look a bit like this:
Code:
00/8000: BRK #$00
00/8002: LDA #$01
My tracer categorizes it as immediate mode as well =)
i fix it
error about v flag in cpx/cpy leaves when leave in sbc, it´s curious
now only fail in sbc with c flag
in other post i read than sbc can implemented with adc
" load the operand from memory as normal, invert it (^ 0xff), and then do your ADC code" said by tepples
if i do it nesstres don´t fail, but the doubt has remained me
if (result > 255) set c flag; else clear c flag;<<-----why fail this in sbc without use adc code?????
super mario bros work with sky all black and he freeze when mario arrives under the third block of interrogation......
EDIT: and scores desappear too......thanks again disch.....and cycling in this point
8150 LDA $2002
8153 AND #$40
8155 BEQ $8150
EDIT2: block of interrogation = block with question mark, jeje, thanks for explain it , tokumaru
cisco wrote:
" load the operand from memory as normal, invert it (^ 0xff), and then do your ADC code" said by tepples
That will work too. That's actually why SBC logic is so weird -- it acts like an inverted ADC.
Quote:
if (result > 255) set c flag; else clear c flag;<<-----why fail this in sbc without use adc code?????
Borrow acts backwards on SBC.
For SBC: if result < 0, you CLEAR the C flag, else you set it
But if it's easier to use the inverted ADC logic as tepples mentioned, just stick with that.
Quote:
block of interrogation......
hehe, that's a very funny translation XD
Anyway, I don't know what the problem could be here. Sorry.
Disch wrote:
for ADC, V flag is set when:
Positive + Positive = Negative
or
Negative + Negative = Positive
and is cleared on all other conditions.
for SBC, it's:
Positive - Negative = Negative
or
Negative - Positive = Positive
and is cleared on all other conditions.
Isn't it a bit complicated explaining it like this? Isn't it simpler to say the V flag is set when bit 7 (sign) changes? When a negative number turns positive or when a positive number turns negative. And it'd work the same for ADC and SBC... woudn't it work like this?
Disch wrote:
Quote:
block of interrogation......
hehe, that's a very funny translation XD
Well, "interrogation point" (direct translation), in portuguese, is how we call a question mark. I guess it is the same in spanish then.
tokumaru wrote:
Isn't it a bit complicated explaining it like this? Isn't it simpler to say the V flag is set when bit 7 (sign) changes?
That's not specific enough.
Positive+Negative=Negative
would result in a changing sign -- but would not set the V flag.
Oh, sorry. I was wrong then. But you know... I'm sure I've heard a simpler explanation of how the V flag works before...
How about this: if the signs of the operands are the same but the result has a different sign, overflow occurred. That is, for C = A + B, overflow set if (B XOR $80 XOR A) AND (C XOR A) AND $80 is non-zero.
but that's only for ADC :P
Quote:
but that's only for ADC :P
Well, since SBC simply XORs the operand with $FF, just flip the sign of B. But I did leave out carry, which complimicates. You have to fall back on a verbose description.
I put it for if interests someone
super mario runs ok
black sky --->> problem was that not write in $3f00 when write in $3f10
freeze --->> problem was that in second write in $2005 i put name tables with bits of $2000 and this produces freeze the game......i don´t know why...
EDIT: in game 1942 in second frame instead of show sea it shows ship again, seems that scroll don´t work well and instead it agrees the table correct, it agrees at same table or the table mirror of same table....some comment respect it???
i have a black sky in SMB. thanks, ill look at that.
matt
Quote:
i have a black sky in SMB. thanks, ill look at that.
works????
why if i put bits of name table since bits 1 & 0 of $2000 in first write in register $2005 super mario will freeze???
bits of name table in loopy_T when change????
when first write in $2006
when first write in $2005 since $2000
when x wrap
when y wrap
when start frame
when start scanline
another question: if put loopy_V since $2006 ( only, whitout $2005 )
and later it write register $2000, in next frame is change bits of name tables of loopy_V with bits 0 and 1 of $2000??????????
cisco wrote:
bits of name table in loopy_T when change????
when first write in $2005 since $2000
No. Loopy_T is changed on the $2000 write. Bits 10,11 of Loopy_T are never changed by $2005. Ever.
Quote:
if put loopy_V since $2006 ( only, whitout $2005 )
and later it write register $2000, in next frame is change bits of name tables of loopy_V with bits 0 and 1 of $2000??????????
This sounds like the same problem as above. $2000 changes loopy_T, so if the game writes to $2000, it will change loopy_T, which will change loopy_V at the start of the next frame.
once more thanks, Disch, when grow I want to be like you jajaja