6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Apr 27, 2024 5:42 am

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Sat Feb 17, 2024 1:25 pm 
Offline
User avatar

Joined: Mon Aug 30, 2021 11:52 am
Posts: 251
Location: South Africa
I've been trying a very basic program to access data banks outside of the zero'th (the first 64K) on a 65816 that's still in emulation mode. Long addressing works fine but if I try something like:

Code:
     ORG $0000
     RESET:
                             LONGA OFF
                             LONGI OFF
    00:0000: A9 38           LDA #$38
    00:0002: 48              PHA
    00:0003: AB              PLB
    00:0004: A9 FF           LDA #255
    00:0006: 8D 00 00        STA $0000


It doesn't seem to. Should the above code store 255 at $00:0000 or $38:0000?

And whilst writing this I've realised it's because the stack is still in ROM so I can't push anything to it.

Hopefully this will still be useful for anyone else trying answer the question: Can I change the DBR in emulation mode and then will addressing modes using the DBR reach out of the zero'th bank?

(both the Programming the 65816 and the W65C816S Datasheet seem imply that DBR will always be used regardless of whether or not the processor is in emulation mode or not; and that the DBR is only initialised to zero on reset it is not held to zero while in emulation mode)


Top
 Profile  
Reply with quote  
PostPosted: Sat Feb 17, 2024 3:42 pm 
Offline

Joined: Sat Dec 12, 2015 7:48 pm
Posts: 122
Location: Lake Tahoe
AndrewP wrote:
..
It doesn't seem to. Should the above code store 255 at $00:0000 or $38:0000?

And whilst writing this I've realised it's because the stack is still in ROM so I can't push anything to it.
...


I'm not sure about the DBR in emulation but unless you have ROM in $0100-$01FF (which would seem odd), push and pop should work fine. The stack pointer will be forced into that address space if you are truly in emulation mode.


Top
 Profile  
Reply with quote  
PostPosted: Sat Feb 17, 2024 3:47 pm 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1398
Location: Scotland
Has no effect in emulation mode.

I tried this:

Code:
00002Ar 1  A9 AA                lda     #$AA
00002Cr 1  85 00                sta     $00
00002Er 1               
00002Er 1  A5 00                lda     $00             ; Read and print $00
000030r 1  20 AB FF             jsr     oHex8
000033r 1  20 8C FF             jsr     osNewl
000036r 1               
000036r 1  A9 01                lda     #$01            ; Bank 1
000038r 1  48                   pha
000039r 1  AB                   plb
00003Ar 1               
00003Ar 1  A9 55                lda     #$55            ; Store $55
00003Cr 1  85 00                sta     $00
00003Er 1               
00003Er 1  A9 00                lda     #$00            ; Bank 0
000040r 1  48                   pha
000041r 1  AB                   plb
000042r 1               
000042r 1  A5 00                lda     $00             ; Read and print $00
000044r 1  20 AB FF             jsr     oHex8
000047r 1  4C 8C FF             jmp     osNewl


It printed:

Code:
AA
55


So it ignored the attempted change to bank 1 and the subsequent write and wrote $55 to bank 0...

-Gordon

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


Top
 Profile  
Reply with quote  
PostPosted: Sat Feb 17, 2024 5:51 pm 
Offline

Joined: Sun Jun 29, 2014 5:42 am
Posts: 337
drogon wrote:
Has no effect in emulation mode.
So it ignored the attempted change to bank 1 and the subsequent write and wrote $55 to bank 0...

I think there is an error in your test case.

You are testing using the Direct-Page addressing mode, which doesn't use the data bank register.

If you changed the test to use the Absolute addressing mode, I expect you would see a different result.

Dave


Top
 Profile  
Reply with quote  
PostPosted: Sat Feb 17, 2024 6:25 pm 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1398
Location: Scotland
hoglet wrote:
drogon wrote:
Has no effect in emulation mode.
So it ignored the attempted change to bank 1 and the subsequent write and wrote $55 to bank 0...

I think there is an error in your test case.

You are testing using the Direct-Page addressing mode, which doesn't use the data bank register.

If you changed the test to use the Absolute addressing mode, I expect you would see a different result.

Dave


Ah ... *thud*

Right. I'd overlooked that the OPs assembler was treating $0000 as an absolute address vs. zp/dp address. Doh!

This:

Code:
00002Ar 1  A9 AA                lda     #$AA
00002Cr 1  8D 00 00             sta     a:$0000
00002Fr 1               
00002Fr 1  AD 00 00             lda     a:$0000         ; Read and print $00
000032r 1  20 AB FF             jsr     oHex8
000035r 1  20 8C FF             jsr     osNewl
000038r 1               
000038r 1  A9 01                lda     #$01            ; Bank 1
00003Ar 1  48                   pha
00003Br 1  AB                   plb
00003Cr 1               
00003Cr 1  A9 55                lda     #$55            ; Store $55
00003Er 1  8D 00 00             sta     a:$0000
000041r 1               
000041r 1  A9 00                lda     #$00            ; Bank 0
000043r 1  48                   pha
000044r 1  AB                   plb
000045r 1               
000045r 1  AD 00 00             lda     a:$0000         ; Read and print $00
000048r 1  20 AB FF             jsr     oHex8
00004Br 1  20 8C FF             jsr     osNewl
00004Er 1  60                   rts


Prints

Code:
AA
AA


the a: in ca65 forces absolute mode.

and if I use my mem dump command to dump bank 1:

Code:
* md 1 0000
01.0000: 55 01 01 01:01 01 01 01:01 01 01 01:01 01 01 01  | U                |
01.0010: 01 01 01 01:01 01 01 01:01 01 01 01:01 01 01 01  |                  |
...etc


then the $55 is where it ought to be.

-Gordon

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


Top
 Profile  
Reply with quote  
PostPosted: Sat Feb 17, 2024 7:42 pm 
Offline
User avatar

Joined: Mon Aug 30, 2021 11:52 am
Posts: 251
Location: South Africa
Awesome ! Thanks gents it's great to know DBR does work in emulation mode.

Yup, there is ROM in $0100-$01FF. Actually the whole first 512KB of addresses are ROM because emulation mode forms part of the address decoding and only swaps in RAM into those addresses when native mode (emulation mode = 0) is set. I thought I was quite the genius to work this out ... and then realised Garth had discussed it a decade or two ago :lol:


Top
 Profile  
Reply with quote  
PostPosted: Sat Feb 17, 2024 9:15 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8144
Location: Midwestern USA
AndrewP wrote:
Awesome ! Thanks gents it's great to know DBR does work in emulation mode.

As WDC notes in the data sheet, all instructions work in both modes, although with limited capabilities in some cases.  Being able to direct fetches and stores to extended RAM by tinkering with DB (not DBR—that’s kind of like saying “PIN number” :D) is one such example.  That said, I’ve yet to find any good reason to run the 816 in emulation mode, except momentarily to default the registers to a known state.

Code:
03245  ;===============================================================================
03246  ;SYSTEM RESET, POWER-ON SELF-TEST (POST) & INITIAL SYSTEM LOAD
03247  ;===============================================================================
03248  ;
03249  00D000  78            hrst     sei                   ;no IRQs &...
03250  00D001  D8                     cld                   ;binary mode
03251  00D002  38                     sec                   ;default the...
03252  00D003  FB                     xce                   ;MPU...
03253  ;
03254  ;         —-—-—-—-—-—-—-—-—-—-—-—-—-—-—-—-—-—-—-—-—-—-—-—-—-
03255  ;         Defaulting the MPU is done to revert DP to $0000 &
03256  ;         set the m & x bits in SR, thus reverting register
03257  ;         sizes to 8 bits.  DP & SP will be initialized to
03258  ;         firmware defaults after stage 1 post has success-
03259  ;         fully completed required basic (bank $00) RAM
03260  ;         tests.
03261  ;         —-—-—-—-—-—-—-—-—-—-—-—-—-—-—-—-—-—-—-—-—-—-—-—-—-
03262           
03263           
03264  00D004  18                     clc                   ;return to & stay...
03265  00D005  FB                     xce                   ;in native mode

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


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

All times are UTC


Who is online

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