6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri May 10, 2024 9:47 am

All times are UTC




Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Thu Aug 26, 2021 7:33 am 
Offline

Joined: Sun Jul 11, 2021 9:12 am
Posts: 137
Hi guys!

I've started coding some routines. For my homebrew but I'm still getting stuck on some of the addressing types.

The problem I am experiencing is when I try to store a value at a particular memory address.

Attempting to store 'FF' at location $0002 works for me by doing this;
Code:
       
        ldx #$00
        lda #$ff
        sta ($02,x)


But doesn't work if I do this;
Code:
       
        lda #$ff
        sta $02


Any idea why the latter doesn't work? (Or should it?)

Many thanks in advance!


Top
 Profile  
Reply with quote  
PostPosted: Thu Aug 26, 2021 7:47 am 
Offline

Joined: Sun Jul 11, 2021 9:12 am
Posts: 137
Gah, just realised I am storing at the location pointed to in $0002 for the first example (which is actually what I wanted). Noob mistake.

Is there any way to to do an STA($02,x) without having to have the offset x?


Top
 Profile  
Reply with quote  
PostPosted: Thu Aug 26, 2021 7:53 am 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1411
Location: Scotland
J64C wrote:
Gah, just realised I am storing at the location pointed to in $0002 for the first example (which is actually what I wanted). Noob mistake.

Is there any way to to do an STA($02,x) without having to have the offset x?


A 65C02 can simply:

Code:
  sta ($02)


-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Thu Aug 26, 2021 8:33 am 
Offline

Joined: Sun Jul 11, 2021 9:12 am
Posts: 137
Awesome, good to know. The IDE I am using only knows about the 6502. I'll have to see if there is a way the instruction set can be extended.

I guess I could look up the opcode and put the hex codes inline at worst.

Thanks again!


Top
 Profile  
Reply with quote  
PostPosted: Thu Aug 26, 2021 8:40 am 
Online
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8433
Location: Southern California
Maybe use a macro, and call it something like STAind.

_________________
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: Thu Aug 26, 2021 8:47 am 
Offline

Joined: Sun Jul 11, 2021 9:12 am
Posts: 137
Will certainly look at doing that :)


Top
 Profile  
Reply with quote  
PostPosted: Thu Aug 26, 2021 10:03 am 
Offline

Joined: Sun Jul 11, 2021 9:12 am
Posts: 137
Thanks guys! 0x92 sta(zpg) worked well.

Currently writing an emulator for my hardware. I am using the mos6502 framework here - https://github.com/gianlucag/mos6502

Unfortunately it only supports 6502 and not W65C02. But I managed to wrangle the 0x92 opcode to it and it seems to be performing as intended. So all is going well.

I might look at adding the other W65C02 opcodes to it at a later date.

Many thanks once again. You guys are legendary!


Top
 Profile  
Reply with quote  
PostPosted: Fri Aug 27, 2021 8:12 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10800
Location: England
Sounds like good progress!


Top
 Profile  
Reply with quote  
PostPosted: Fri Sep 10, 2021 4:40 pm 
Offline
User avatar

Joined: Fri Dec 12, 2008 10:40 pm
Posts: 1001
Location: Canada
Hang about!

Why did:

STA $02

Not work?

_________________
Bill


Top
 Profile  
Reply with quote  
PostPosted: Fri Sep 10, 2021 5:40 pm 
Offline

Joined: Fri Jul 09, 2021 10:12 pm
Posts: 741
BillO wrote:
Why did:

STA $02

Not work?

STA $02 did work, but didn't do what he actually wanted, which was indirect addressing.


Top
 Profile  
Reply with quote  
PostPosted: Fri Sep 10, 2021 6:43 pm 
Offline
User avatar

Joined: Fri Dec 12, 2008 10:40 pm
Posts: 1001
Location: Canada
gfoot wrote:
STA $02 did work, but didn't do what he actually wanted, which was indirect addressing.


Ahh, okay. To what advantage? I'm still missing something, but in my defense I'm not one of the worlds better known 65(C)02 code hounds.

_________________
Bill


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

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1411
Location: Scotland
BillO wrote:
gfoot wrote:
STA $02 did work, but didn't do what he actually wanted, which was indirect addressing.


Ahh, okay. To what advantage? I'm still missing something, but in my defense I'm not one of the worlds better known 65(C)02 code hounds.


He was after using $02 and $03 as a 16-bit pointer to a memory location - the low byte stored in $02 and the high byte in $03. In 65C02 land you can simply

Code:
    sta    ($02)


in non C land, then you need to use an index register (set to zero for this case).

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Sat Sep 11, 2021 12:16 am 
Offline

Joined: Thu Jan 21, 2016 7:33 pm
Posts: 269
Location: Placerville, CA
In NMOS-ville, you can also leave the LSB of the pointer in memory zeroed, load the real LSB in Y, and do STA ($02),Y instead.


Top
 Profile  
Reply with quote  
PostPosted: Sat Sep 11, 2021 2:14 pm 
Offline

Joined: Sun Nov 08, 2009 1:56 am
Posts: 387
Location: Minnesota
Quote:
In NMOS-ville, you can also leave the LSB of the pointer in memory zeroed, load the real LSB in Y, and do STA ($02),Y instead.


...and also never pay an extra cycle for crossing a page boundary.

BTW, for an NMOS 6502, you can store (or load) a value at the address pointed to by a lo/hi pointer in zero page by either:

Code:
ldx #$00
sta (ptr_lo, x)


(which may actually be the most common use of the rarely-used pre-indexed indirect address mode)

or

Code:
ldy #$00
sta (ptr_lo),y


But if you don't want to mess with the index registers at all, you'll need to use a CMOS 6502.


Top
 Profile  
Reply with quote  
PostPosted: Sat Sep 11, 2021 3:08 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3354
Location: Ontario, Canada
teamtempest wrote:
[...] the rarely-used pre-indexed indirect address mode
Actually, some of us rely quite heavily on the pre-indexed indirect mode, and find it to be a real boon! But on an NMOS 65xx I can also see the case for using it with X=0.

Quote:
But if you don't want to mess with the index registers at all, you'll need to use a CMOS 6502.
Or Self Modifying Code (which can simulate all sorts of novel and useful address modes). Garth wrote about that and oiher aspects of SMC here.

-- Jeff

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


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

All times are UTC


Who is online

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