It is currently Wed Sep 19, 2018 10:56 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Thu May 11, 2006 11:50 am 
Offline
User avatar

Joined: Sat Jul 09, 2005 6:03 am
Posts: 85
I use jump absolute in a few places in my project, and was wondering if there was a good workaround for the jmp ($xxFF) bug. Really, I just need the ability to get to a routine variably (I'm not a very good explainer). But when the needed routines address is stored in temp memory.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 11, 2006 12:08 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10814
Location: Rio de Janeiro - Brazil
I don't think you can get around the bug (and some say it's not even a bug)... Why not just make sure the addresses are stored at even memory locations? You'll never have to worry about this "bug" if you do this.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 11, 2006 12:19 pm 
Offline
User avatar

Joined: Sat Jul 09, 2005 6:03 am
Posts: 85
Ok, thats fine. I'm just readjusting them with NOPs. How would I make sure they're at even address other going to the listing file after compilation and finding the bad ones.

I'm using ca65 by the way.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 11, 2006 12:26 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10814
Location: Rio de Janeiro - Brazil
How are you ordering them? Are these addresses at random locations? If you have many of them, the organized thing to do would be to place them all in a list, one after the other. That way, if the first is at an even address, all the others will too.

These are RAM values right? When you create labels to point to these locations make sure the labels represent even numbers.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 11, 2006 12:37 pm 
Offline
User avatar

Joined: Sat Jul 09, 2005 6:03 am
Posts: 85
The values to jump are yes. But its a 2 byte storage area, not a list of address/pointer type vars. I just use the .proc command to close the scope around the routines. All of the them that need to be jumped to are stored in the same basic area, one after the other, depending on use.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 11, 2006 2:19 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20562
Location: NE Indiana, USA (NTSC)
mbrenaman wrote:
How would I make sure they're at even address
[...]
I'm using ca65 by the way.

.ALIGN


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 11, 2006 2:46 pm 
Offline
User avatar

Joined: Mon Sep 27, 2004 8:33 am
Posts: 3715
Location: Central Texas, USA
I think you are misunderstanding the basic opcodes. JMP absolute has no pathological behavior. JMP indirect does when the low byte of the intermediate address is $FF. You will almost always store the target address in RAM, so it's easy to avoid having it cross a page boundary.

Code:
lda #$34
sta $200
lda #$12
sta $201
JMP ($200) ; JMP $1234


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 12, 2006 12:22 am 
Offline
User avatar

Joined: Sat Jul 09, 2005 6:03 am
Posts: 85
Quote:
mbrenaman wrote:
How would I make sure they're at even address
[...]
I'm using ca65 by the way.

.ALIGN


Excellent. This is something I was looking for.

Quote:
I think you are misunderstanding the basic opcodes. JMP absolute has no pathological behavior. JMP indirect does when the low byte of the intermediate address is $FF. You will almost always store the target address in RAM, so it's easy to avoid having it cross a page boundary.

Code:

lda #$34
sta $200
lda #$12
sta $201
JMP ($200) ; JMP $1234



Yesterday was a long day. I don't know why I kept writing Absolute. I meant Absolute Indirect.

Wait a minute. Its not the address to jump to that messes it up. Its the pointer's address in RAM. Doh!

Example :

Code:
lda #$34
sta $2FF
lda #$12
sta $300
JMP ($2FF) ; JMP "Not really where it would jump to"


Right?


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 12, 2006 5:29 am 
Offline
User avatar

Joined: Mon Sep 27, 2004 8:33 am
Posts: 3715
Location: Central Texas, USA
Code:
lda #$11
sta $200
lda #$22
sta $2FF
lda #$33
sta $300
JMP ($2FF) ; JMP $1122


The reason people encounter problems with this instruction is that JMP ADDR is often incorrectly defined to fetch the address from ADDR and ADDR+1, when it really fetches it from ADDR and ((ADDR + 1) AND $FF) OR (ADDR AND $FF00), that is, only incrementing the lower 8 bits without any carry. Correct the documentation and the claimed bug in the processor goes away.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 12, 2006 9:01 am 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7517
Location: Chexbres, VD, Switzerland
Usually, you'll want to store the adress to jump in a two-var pointer. And if you keep all yours two vars pointers in zero-page, you will be sure that the high byte of jmp ($xxxx) is always $00, so it won't cross RAM page boundaries.
If you want to do this out of page zero, you have one change out of 256 that this bug happens to you. That is fairly low, but to keep sure, I think .align 2 will do the work.
Doing this out of ram is just stupid, since as long as you can read an adress in ROM you can use jmp absolute. The only exeption to this is if you want a kind of software interupt, where you'd use jmp ($fffa) for a software NMI or jmp (£fffc) for a software reset. Since the adresses are fix, you won't meet that bug. You could also use jmp NMI and jmp Reset in absolute.

_________________
Life is complex: it has both real and imaginary components.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 12, 2006 9:18 am 
Offline
User avatar

Joined: Sat Jul 09, 2005 6:03 am
Posts: 85
I understand. Thank you for your help everyone. I plan to just make use of .ALIGN.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 12, 2006 10:24 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20562
Location: NE Indiana, USA (NTSC)
blargg wrote:
JMP ADDR is often incorrectly defined to fetch the address from ADDR and ADDR+1, when it really fetches it from ADDR and ((ADDR + 1) AND $FF) OR (ADDR AND $FF00)

You mean "JMP (ADDR) is incorrectly defined", right?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group