6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Oct 06, 2024 11:27 pm

All times are UTC




Post new topic Reply to topic  [ 52 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
PostPosted: Mon Sep 20, 2021 6:28 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8415
Location: Midwestern USA
Jmstein7 wrote:
Just read it. But, it doesn't explain how to get the signature byte. Does that just go into the ether?

C'mon, man, figure it out. The signature is in RAM or ROM, which means it can be read by code in the ISR. Review what gets pushed to the stack as COP is executed. Everything you need to find and load the signature is right there. Hint: stack pointer relative addressing is your friend. This is nothing more than basic assembly language programming. :D

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 20, 2021 6:41 pm 
Offline

Joined: Sat Jan 02, 2016 10:22 am
Posts: 197
I was 1/2 way through typing that you need to retive the return address off the stack, and adjust that back 1 byte. But I see BDD has beaten me to it.


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 20, 2021 6:43 pm 
Offline

Joined: Sun May 30, 2021 2:16 am
Posts: 374
Quote:
C'mon, man, figure it out. The signature is in RAM or ROM, which means it can be read by code in the ISR. Review what gets pushed to the stack as COP is executed. Everything you need to find and load the signature is right there. Hint: stack pointer relative addressing is your friend. This is nothing more than basic assembly language programming. :D


Quote:
I was 1/2 way through typing that you need to retive the return address off the stack, and adjust that back 1 byte. But I see BDD has beaten me to it.

Well, that would be:
-program counter + 2
-status register

So, could I really just decrement the stack PC by one and read that address?

Stack relative indirect indexed addressing is very confusing; I've never used it.

Also, in furtherance of this discussion, and elsewhere in the archives of the forum, I read that, on the hardware side, you can trap COP instructions by qualifying an enable with VPA = 1, VDA = 1, and the op code. Is that true?


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 20, 2021 7:14 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8415
Location: Midwestern USA
Jmstein7 wrote:
Well, that would be:
-program counter + 2
-status register

So, could I really just decrement the stack PC by one and read that address?

Give it a little more thought. You don't want to do anything to the stack copy of PC, right? If you do, things will blow up when you try to exit your ISR and return to the foreground.

I'll give you two clues: 1) You will be interested in the value of PB that was pushed; and 2) a 16-bit index register is also your friend.

Quote:
Stack relative indirect indexed addressing is very confusing; I've never used it.

In principle, S-R indirect indexed is only slightly different than direct page indirect indexed. All that is different is defining where the pointer is located. If it's on direct page, you write LDA (<ptr>),Y, and <ptr> is an actual address. If it's on the stack, you write LDA (<offset>,S),Y, <offset> being relative to the current stack pointer. If SP = $C000 and <offset> = $04, then the pointer to the desired data is at $00C004. The result is LDA (<offset>,S),Y effectively becomes LDA ($00C004),Y.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 20, 2021 7:26 pm 
Offline

Joined: Sun May 30, 2021 2:16 am
Posts: 374
BigDumbDinosaur wrote:
Jmstein7 wrote:
Well, that would be:
-program counter + 2
-status register

So, could I really just decrement the stack PC by one and read that address?

Give it a little more thought. You don't want to do anything to the stack copy of PC, right? If you do, things will blow up when you try to exit your ISR and return to the foreground.

I'll give you two clues: 1) You will be interested in the value of PB that was pushed; and 2) a 16-bit index register is also your friend.

Quote:
Stack relative indirect indexed addressing is very confusing; I've never used it.

In principle, S-R indirect indexed is only slightly different than direct page indirect indexed. All that is different is defining where the pointer is located. If it's on direct page, you write LDA (<ptr>),Y, and <ptr> is an actual address. If it's on the stack, you write LDA (<offset>,S),Y, <offset> being relative to the current stack pointer. If SP = $C000 and <offset> = $04, then the pointer to the desired data is at $00C004. The result is LDA (<offset>,S),Y effectively becomes LDA ($00C004),Y.


Inside the ISR
Code:
 LDY  $01
 LDA  (1,S),Y
 

Will this work?
Then store A wherever?
I’m on my phone, making this is a bit awkward and clumsy, so my apologies :D

Do I need to be out of emulation mode to make this work?


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 20, 2021 7:49 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8521
Location: Southern California
Jmstein7 wrote:
Stack relative indirect indexed addressing is very confusing; I've never used it.

In one of the pages of the 6502 stacks treatise, I show, in 6502 code, what the 816's stack-relative indirect indexed addressing mode does, about 80% of the way down the page, where you'll see in big letters, "stack-relative indirect indexed addressing." Pretty neat.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 20, 2021 7:52 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8415
Location: Midwestern USA
Jmstein7 wrote:
Inside the ISR
Code:
 LDY  $01
 LDA  (1,S),Y
 

Will this work?

What does 1 represent in your instruction's operand?

Quote:
I’m on my phone, making this is a bit awkward and clumsy, so my apologies :D

Just as toilets are lousy drinking fountains, phones are lousy computers. :D

Quote:
Do I need to be out of emulation mode to make this work?

Stack-relative addressing works the same in both modes. Speaking of which...

The 65C816 is really meant to be used in native mode. Emulation mode exists because "compatibility" with the 65C02 was an Apple requirement so Apple ][ software could be run on the ][GS. There is no reason to run in emulation mode, even if you never use 16-bit registers.

Both Garth and I have long recommended that the start of the reset handler in a 65C816 unit put the MPU into native mode and leave it there:

Code:
reset    sei                   ;make sure IRQs are off
         clc                   ;switch MPU to...
         xce                   ;native mode

I do that in my POC units' firmware: the above sequence is the start of the reset handler. Except very early in the development of POC V1.0, when I was debugging the hardware, I have not used emulation mode at all.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 20, 2021 7:57 pm 
Offline

Joined: Sun May 30, 2021 2:16 am
Posts: 374
BigDumbDinosaur wrote:
Jmstein7 wrote:
Inside the ISR
Code:
 LDY  $01
 LDA  (1,S),Y
 

Will this work?

What does 1 represent in your instruction's operand?

Quote:
I’m on my phone, making this is a bit awkward and clumsy, so my apologies :D

Just as toilets are lousy drinking fountains, phones are lousy computers. :D

Indeed!

Anyway... "1" represents the relative address, or location, from where I think you would find the data just pushed on to the stack. I could be, and probably am, wrong. I know you guys can do this in your sleep, which is incredible per se. Remember, I'm just the student, here.


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 20, 2021 8:25 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1948
Location: Sacramento, CA, USA
Jmstein7 wrote:
Inside the ISR
Code:
 LDY  $01
 LDA  (1,S),Y
 

Will this work?
Then store A wherever?

I have very limited experience with this addressing mode, but I'll go out on a limb and say that the chances that A contains your signature byte are at best one in 256. :D

Let me venture further out on that limb and offer:
    An ISR doesn't immediately trash registers without saving them somewhere, but I suppose a COP handler could get away with it.
    LDY $01 is probably a typo, because none of us have any idea what is contained in direct page location $01.
    (1,S) doesn't contain an address because you forgot to skip over your saved P register.
    (2,S) should hold something you can work with, but it's pointing one byte after your signature byte, which is a slight pain.
    If you're in native mode you may be able to make Y 16-bits and load it with #$FFFF to give you the negative one offset you need to reach the signature byte. This might be the best way on a 65c802, or a 65c816 when you know the COP-caller came from the same program bank as your data bank. (Does (d,S),Y cross to a higher bank? dunno ...)
    In emulation mode, you're probably better off copying the return address from the stack to direct page and decrementing it there before trying to grab the signature byte with a LDA (DPP).
I'm far from an experienced '816 user, so I may have royally goofed ... corrections and criticisms are warmly welcomed.

_________________
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!

Mike B. (about me) (learning how to github)


Last edited by barrym95838 on Mon Sep 20, 2021 9:39 pm, edited 3 times in total.

Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 20, 2021 8:36 pm 
Offline

Joined: Sun May 30, 2021 2:16 am
Posts: 374
Quote:
Code:
reset    sei                   ;make sure IRQs are off
         clc                   ;switch MPU to...
         xce                   ;native mode


Wait, SEI? Why are we turning off interrupts?

Quote:
I have very limited experience with this addressing mode, but I'll go out on a limb and say that the chances that A contains your signature byte are at best one in 256. :D


That is VERY funny - I actually laughed out loud when I read that. Thank goodness I wasn't drinking anything at the time.


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 20, 2021 8:42 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8521
Location: Southern California
Jmstein7 wrote:
Wait, SEI? Why are we turning off interrupts?

If it gets there from the hardware reset line, the SEI won't be necessary as it's an automatic part of the reset sequence; however, if you jump there from software for any reason, you'll want to ignore interrupts until things are set up properly again. I've never done it that way myself.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 20, 2021 8:51 pm 
Offline

Joined: Sun May 30, 2021 2:16 am
Posts: 374
GARTHWILSON wrote:
Jmstein7 wrote:
Wait, SEI? Why are we turning off interrupts?

If it gets there from the hardware reset line, the SEI won't be necessary as it's an automatic part of the reset sequence; however, if you jump there from software for any reason, you'll want to ignore interrupts until things are set up properly again. I've never done it that way myself.

Ahhhh. Got it.


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 20, 2021 8:54 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10949
Location: England
(obligatory notice: there's a variety of opinions on how to use the '816, and it will depend on the situation. Don't take anyone's word on a One True Way, because that's always a simplification. We should note that the second post in this thread takes a very different view on how COP can be handled: not as a software interrupt but as a co-processor decoded instruction.)


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 20, 2021 9:09 pm 
Offline

Joined: Sun May 30, 2021 2:16 am
Posts: 374
BigEd wrote:
(obligatory notice: there's a variety of opinions on how to use the '816, and it will depend on the situation. Don't take anyone's word on a One True Way, because that's always a simplification. We should note that the second post in this thread takes a very different view on how COP can be handled: not as a software interrupt but as a co-processor decoded instruction.)

Ed, can you elaborate? How does one handle COP as a co-processor decoded instruction?


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 20, 2021 9:32 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1948
Location: Sacramento, CA, USA
Jmstein7 wrote:
How does one handle COP as a co-processor decoded instruction?

Page one of this thread touches on some ideas, but I have no direct knowledge of anyone actually implementing these ideas in real life.

Naturally, you need some hardware goodies to get the '816 and the co-processor to play nicely with each other, and some software goodies to tell them how to play, but that's about as much as I can offer at this stage of the game.

_________________
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!

Mike B. (about me) (learning how to github)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 52 posts ]  Go to page Previous  1, 2, 3, 4  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 29 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: