6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 15, 2024 2:27 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Mon Jul 22, 2019 6:58 pm 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1485
Location: Scotland
OK, I'm slowing doing some bits and pieces in my little Ruby OS to 816-ify it... and there's one little thing that I'm finding just weird. I'm probably missing something completely obvious, but right now can't see it ...

For the most part I'm running in native 816 mode with 8-bit registers.

I have a memory-fill routine. Thought I'd be clever and use the 816 block-move instruction. The code takes the value from the command line via an 'atoi' routine (understands decimal, $hex or %bin) and stores it in a 16-bit memory location in page 0 called atoi0 and atoi1, so then ...

Code:
; Fill 0000 to the start of RubyOs

        sei                     ; Just in-case

        lda     atoi0
        sta     $0              ; Store at 0

; '816 fill

        aix16

        lda     #rubyCold-1     ; Number of bytes
        ldx     #$0000          ; Start
        ldy     #$0001          ; End
        mvn     0,0             ; block move

        aix8

        jmp     rubyOs


The aix8 and aix16 instructions are macros:

Code:
; aix8: aix16: 
;       Index and A registers into 8 or 16 bit mode

.macro  aix8   
        sep     #$30
        .i8
        .a8     
.endmacro

.macro  aix16
        rep     #$30
        .i16
        .a16   
.endmacro


This is ca65 and .a8/16 and .i8/16 are used to indicate to the assembler to use 16 bit or 8 for Acc or XY.

The assembler list output is as I'd expect:

Code:
00018Br 1  A5 EC                lda     atoi0
00018Dr 1  85 00                sta     $0              ; Store at 0
00018Fr 1               
00018Fr 1               ; '816 fill
00018Fr 1               
00018Fr 1  C2 30                aix16
000191r 1               
000191r 1  A9 FF CF             lda     #rubyCold-1     ; Number of bytes
000194r 1  A2 00 00             ldx     #$0000          ; Start
000197r 1  A0 01 00             ldy     #$0001          ; End
00019Ar 1  54 00 00             mvn     0,0             ; block move
00019Dr 1               
00019Dr 1  E2 30                aix8
00019Fr 1               
00019Fr 1  4C rr rr             jmp     rubyOs



Anyway, here is the odd bit. This works for all values I've tested except zero. If I ask it to fill with zeros, then it crashes in an obscure way and scribbles over memory with a repeating 4-byte pattern: $37, $00, $35, $37 ...

I've tried changing the lda atoi0 with lda #$0 and it fails the same way (but works for other values I've tried).

So have I missed something obvious, being stupid, or something else?

Any clues welcome!

Cheers,

-Gordon

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


Last edited by drogon on Mon Jul 22, 2019 8:08 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: '816 odditys ...
PostPosted: Mon Jul 22, 2019 7:22 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1949
Location: Sacramento, CA, USA
Please forgive me if these are silly questions, but:
1) do you have any NMIs and
2) is your subroutine located in bank 0 RAM, causing you to sled all the way to your cold start after the move?

_________________
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 Jul 22, 2019 7:45 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: '816 odditys ...
PostPosted: Mon Jul 22, 2019 7:44 pm 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1485
Location: Scotland
barrym95838 wrote:
Please forgive me if this is a silly question, but is your subroutine located in bank 0 RAM?


Yes - there is only one bank of 64K in this system. The routine should clear from $0000 to $CFFF.

The code lives in higher RAM - the addresses in the listing output are relocatable ones generated by ca65.

-Gordon

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


Top
 Profile  
Reply with quote  
 Post subject: Re: '816 odditys ...
PostPosted: Mon Jul 22, 2019 8:08 pm 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1485
Location: Scotland
OK. I have worked it out.

It's the count.

According to the book, you set count -1 in the 16-bit A register.

So I was setting the address of the start of the OS ($D000) minus 1. I've "manually" written the first byte, and I'm copying one less (to location 1), so I really ought to have -2 in there.

And when I do that it works.

It wasn't working before because I've not got the '816 BRK vector setup, so if it jumped to $D000 after the copy, it hits a BRK which goes to ($FFE6) in '816 mode which "blows up". With all the other numbers I tried, it seemed to just work - or skipped over them. Lucky I guess, but led me down the wrong path.

So, ok, as you were, please have a chuckle at me in my Gordon is a moron moment (old UK folks will know that one)

Cheers,

-Gordon

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


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 22, 2019 11:34 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1949
Location: Sacramento, CA, USA
Nicely done. I knew you probably had the best chance of solving the issue, being reasonably competent and situated right there and all ... 8)

https://www.youtube.com/watch?v=LTKORcr1jhY

_________________
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  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: Yuri and 10 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: