Page 8 of 10
Re: question
Posted: Mon May 08, 2006 2:02 pm
by tokumaru
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.
new question
Posted: Tue Jun 06, 2006 1:13 pm
by lord_Chile
My question is about relative addressing:
Code: Select all
$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]
Posted: Tue Jun 06, 2006 1:48 pm
by blargg
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).
questions.. im programming a nes 6502 simulator
Posted: Thu Jun 15, 2006 3:36 pm
by lord_Chile
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: Select all
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??..
Re: questions.. im programming a nes 6502 simulator
Posted: Thu Jun 15, 2006 3:44 pm
by Disch
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.
thanks 3 is
Posted: Thu Jun 15, 2006 3:53 pm
by lord_Chile
3.- each how many cpu cycles, i execute irqs???
Posted: Thu Jun 15, 2006 4:57 pm
by Disch
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.
Posted: Fri Jun 16, 2006 4:54 am
by Bregalad
Dragon Quest and Dragon Quest II uses IRQ for sound driver I think (but not Dragon Warrior u.s. counterpart).
Thanks
Posted: Fri Jun 16, 2006 12:45 pm
by lord_Chile
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: Select all
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
Posted: Fri Jun 16, 2006 1:10 pm
by Bregalad
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.
thanks!.. mm
Posted: Sat Jun 17, 2006 4:57 pm
by lord_Chile
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??..
Posted: Sun Jun 18, 2006 9:46 am
by Bregalad
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.
Posted: Sun Jun 18, 2006 3:14 pm
by lord_Chile
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?
Posted: Sun Jun 18, 2006 3:25 pm
by Disch
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: Select all
BRK
NOP ; RTI will not return here -- this byte is skipped
LDA #$00 ; RTI will return here!
Posted: Sun Jun 18, 2006 5:19 pm
by tepples
The most obvious test case for BRK behavior is as follows:
Code: Select all
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: Select all
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?