6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Nov 24, 2024 9:47 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sun Nov 01, 2015 1:37 pm 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
Some of you might have read that the biggest bug (so far) with my Crude 65816 Emulator was that I had coded the routine for LDA Absolute Y Indexed wrong. It's instructive to look at that part of Tali Forth for the 6502 more closely, especially at lines 1321 and 1324 (some whitespace lines omitted):
Code:
1314                 ldy #SP0
1315                 stx TMPX
1317 _loop:          ; ironically, we need the stack for this 
1321                 lda 0,y
1322                 sta 2,x         ; MSB first
1323                 dey
1324                 lda 0,y
1325                 sta 1,x         ; then LSB
This is part of the routine for ".S", the Forth command to print non-destructively what's on the Data Stack. I don't actually remember coding this, but looking at the code, I'm pretty sure I know what I was thinking: I need the stack to print the stack (this calls "." (dot) to print the number), so I'll just use LDA Zero Page Y Indexed so I can preserve X as the Data Stack Pointer. Clever, huh?

Well, no. There is no such instruction, even on the 65c02. In fact, this is really LDA Absolute Indexed Y, which should have been written as
Code:
lda 0000,y
to make that clear. Which is also why I'm sure I was under the impression that there is such an instruction. It just happens to work by accident, no thanks to me.

So what's the big problem? It means that Tali Forth cannot currently run in a different bank of the 65816, because it assumes that Zero Page is in the first page of the program's bank. Loading the program into bank 01, for instance, setting DBR to 01 and then jumping to 01:e0000 will not work (there are other problems like the interrupt routines, but those are obvious). It's an example of why adapting 6502 programs to the 65816 is a pain unless they are cleanly coded. I'm going to have to figure out a different way to do this at some point.

As an aside, this is an example of why I have become disenchanted with the tradition assembler notation for the 6502/65816. The Ophis assembler has no way of knowing that I was trying to code some hypothetical "LDA Zero Page Y Indexed" mode and thinks I'm just too lazy to type three extra zeros for Absolute Y Indexed (which I wish I could claim were true, alas). In the "Typist's Notation" I've been using for my simple Forth assembler, this would have been (with operands switched around here for readability):
Code:
1314                 ldy.# SP0
1315                 stx.z TMPX
1317 -> loop         \ ironically, we need the stack for this 
1321                 lda.zy 0
1322                 sta.zx 2         ; MSB first
1323                 dey
1324                 lda.zy 0
1325                 sta.zx 1         ; then LSB
Even while typing, the "lda.zy" would not have triggered the syntax highlighting rules I have set up in vim, warning me that something is wrong, and the assembler would have aborted because there is no such instruction.


Top
 Profile  
Reply with quote  
PostPosted: Sun Nov 01, 2015 5:35 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1952
Location: Sacramento, CA, USA
I understand your self-frustration, but don't quite follow your decision to code .S in assembly in the first place:
Code:
: .S ( -- ) Print stack contents
    [char] < EMIT DEPTH . BS [char] > EMIT
    SP@ S0 < IF
        SP@ S0 1- DO
            I @ U.
        -1 +LOOP
    THEN
;

(Courtesy of Dr. Brad, and untested, at least by me. I think that a well-placed ?DO might be able to shorten it further, but I'm not qualified to attempt it, at least not yet.)

Mike B.


Last edited by barrym95838 on Sun Nov 01, 2015 5:44 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Sun Nov 01, 2015 5:41 pm 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
barrym95838 wrote:
I understand your self-frustration, but don't quite follow your decision to code .S in assembly in the first place
Yeah, that would have been easier. The idea was to keep it short and fast, but in the next Forth, I'm going to have to revisit that assumption. :D


Top
 Profile  
Reply with quote  
PostPosted: Sun Nov 01, 2015 5:52 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1952
Location: Sacramento, CA, USA
"Fast" is of little importance for a word of that nature, but "short" always has value in my book. Is your assembly version actually shorter than the high-level equivalent?

Mike B.


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

All times are UTC


Who is online

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