Jump to content
IGNORED

Understanding RESPx


andre_nho

Recommended Posts

Hello,

 

I'm new to this forum and to Atari programming, and I'm still trying to understand a few things.

 

Let's say that in my kernal I have the following simple code (I set GRP0 in the VBLANK):

 

  SLEEP 23
  sta RESP0
  sta WSYNC

  REPEAT 191
  sta WSYNC
  REPEND

 

I see that my player 0 sprite appears in the horizontal position 15 (or absolute position 83 [15+68]).

 

My code for positioning my sprite is:

 

SLEEP 23 ; 23 cycles [69 TIA cycles]

sta RESP0 ; 3 cycles [9 TIA cycles]

 

This amounts to 78 TIA cycles. But my sprite is positioning after 83 cycles. Where those 5 cycles come from?

 

Thank you in advance!

 

André

Link to comment
Share on other sites

If it helps any, its not your fault. TIA execution time I assume. This delay also differs for the missilies and the ball.

 

One thing I learned lately, is that any 6502 instruction can actually last 2 cycles longer than you think. You just never notice this, as the CPU already piplines the next instruction those 2 cycles earlier. Might be that this effect is responsible for 2 of those delay cycles already.

Link to comment
Share on other sites

How did you find that out??

 

Someone recently quoted the relevant passages from the original MCS6500 manual on nesdev :)

Oh

 

My

 

Gawd

 

:-o

 

Thanks for the link, I'm going to bookmark this stuff. I wonder if this might help to explain some of the "delays" that need to be accounted for when updating the PF registers in an asymmetrical playfield? :?

 

MR

Link to comment
Share on other sites

And if you really want to know the reason, read this: http://www.bjars.com/resources/tia_hw_notes.doc

Yes, that's another excellent doc to have-- although I don't think I've fully grasped all of it yet (and it utterly amazes me that people can figure this stuff out by looking at schematics... but then, schematics look like gibberish to me-- I really ought to take some courses in that stuff, or buy "Schematics for Dummies"). :D

 

MR

Link to comment
Share on other sites

  • 2 weeks later...

If it helps any, its not your fault. TIA execution time I assume. This delay also differs for the missilies and the ball.

 

One thing I learned lately, is that any 6502 instruction can actually last 2 cycles longer than you think. You just never notice this, as the CPU already piplines the next instruction those 2 cycles earlier. Might be that this effect is responsible for 2 of those delay cycles already.

Hmmm...that actually makes sense, and is somewhat implied from this document.

 

For example, check this out:

Zero page addressing

 Read instructions (LDA, LDX, LDY, EOR, AND, ORA, ADC, SBC, CMP, BIT,
					LAX, NOP)

	#  address R/W description
   --- ------- --- ------------------------------------------
	1	PC	 R  fetch opcode, increment PC
	2	PC	 R  fetch address, increment PC
	3  address  R  read from effective address


 Read-Modify-Write instructions (ASL, LSR, ROL, ROR, INC, DEC,
								 SLO, SRE, RLA, RRA, ISB, DCP)

	#  address R/W description
   --- ------- --- ------------------------------------------
	1	PC	 R  fetch opcode, increment PC
	2	PC	 R  fetch address, increment PC
	3  address  R  read from effective address
	4  address  W  write the value back to effective address,
				   and do the operation on it
	5  address  W  write the new value to effective address

For example, note that ADC is grouped with "Read" instructions but it really should be a Read-Modify instruction - an ADC $80 instruction, according to this chart, first fetches the opcode, then fetches the address, then reads from the address and then...is done? Obviously, it needs to actually perform the addition at some point and then, according to that post on nesdev, transfer that result to the accumulator.

 

Interesting...just looking through that document, it looks like these instructions are pipelined:

EOR, AND, ORA, ADC, SBC, CMP, BIT, and all instructions that use implied addressing.

 

Assuming that document is correct, this generally shouldn't have an effect when writing to the TIA since you generally don't use any of those instructions to write to TIA registers (since you can't read from them).

 

So I don't think this has any effect on the TIA delays.

 

EDIT: Just noticed this for the first time at the very bottom of that "Documentation for the NMOS 65xx/85xx Instruction Set":

				Notes

 See the MCS 6500 Microcomputer Family Programming Manual for less
information.

:lol:

Edited by vdub_bobby
Link to comment
Share on other sites

For example, note that ADC is grouped with "Read" instructions but it really should be a Read-Modify instruction - an ADC $80 instruction, according to this chart, first fetches the opcode, then fetches the address, then reads from the address and then...is done? Obviously, it needs to actually perform the addition at some point and then, according to that post on nesdev, transfer that result to the accumulator.

 

The 6502 must know the address for any read cycle, and the address and data for any write cycle, before the previous cycle is complete. The only exception is that the high or low order 8 bits of the address may be taken directly from the data returned by the preceding read. No other modification is possible.

 

Thus, if I do "LDA $84", the CPU fetches the opcode and operand; having just fetched $84, it can route that directly to the LSB of the address bus (the MSB simply gets zeroed). If I do "LDA $1234", the CPU can transfer the $12 directly from the data bus to the MSB of the address bus (having read and buffered $34 the cycle before).

 

Indexed zero-page operations require an extra cycle because the address value to be output isn't the same as the value fetched the cycle before. Indexed non-zero-page operations usually don't require an extra cycle, since the MSB of the address will usually be the last thing fetched from the data bus while the processor was computing the LSB. Note that even if the processor had a 16-bit ALU, indexes across page boundaries would still require the extra cycle; the only thing a 16-bit ALU would do is reduce the cost of a branch across page boundaries from two extra cycles to one.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...