Not Exactly Translating The Dead Sea Scrolls, But...

This is a discussion on Not Exactly Translating The Dead Sea Scrolls, But... within the Tech Board forums, part of the Community Boards category; Hello, I'm trying to provide an instruction-accurate port of some code that runs on a 6502 CPU to x86. I'm ...

  1. #1
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,255

    Question Not Exactly Translating The Dead Sea Scrolls, But...

    Hello,

    I'm trying to provide an instruction-accurate port of some code that runs on a 6502 CPU to x86. I'm pretty good on the x86 assembly side (though don't really know FPU opcodes or anything added since 1996), but know zip about the 6502 side of life.

    At the moment I'm building a table that provides the x86 equivalent of 6502 instructions. Most are pretty straightforward (e.g. ADC = ADC), but others are a bit more of a mystery.

    CLI clears the "interrupt disable" flag on a 6502, but the flag works the opposite (enable) on an Intel, so the equivalent is STI, yes?

    I also have no clues about "decimal mode" on the 6502, whether that translates to anything at all on the Intel. Any ideas?

    Quite handy that it only has three registers though (X, Y and SP), makes things fairly economical.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,563
    I also have no clues about "decimal mode" on the 6502,
    Do you mean Binary Coded Decimal? Have you looked at some of the information from this site: 6502.org?

    Jim

  3. #3
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,255
    Ah, BCD. That makes sense. I know there are some x86 opcodes that deal with BCD but there's no "decimal flag" on x86, is there?

  4. #4
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,383
    Yeah. Instead you use x86 usual arithmetic opcodes in conjunction with x86 supported BCD opcodes (AAA, AAS, DAA, DAS, etc). It will be your task to know that the stored values are in BCD format. But can you avoid doing BCD on the x86? I'd rather skip it entirely and perform normal binary operations. You'll just have to concern yourself with translating the values from the 6502 BCD code (here's a full description).

    In any case, a good introductory tutorial for BCD in x86 is here. It's a whole lot of inefficient cycles.

    As for STI, yes. Or POPF, depending on your needs.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  5. #5
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,255
    tbh the code doesn't feature any BCD opcodes, but I'm a bit obsessive when it comes to completeness of a solution.
    I'm quite pleased, this doesn't look as difficult as I thought it might be.

  6. #6
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,383
    I'm more familiar with the Z80 but both have some similarities (well the 6510 more than the 6502). But you are right, it's pretty straightforward (and fun!). You'll only have to worry with the x86 side of things. 8bit assembly is the "Hello World" of assemblies. I just hope the program that you are trying to translate doesn't have any access to graphics memory. You will have to scrap entirely that part of the code.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. First two Elder Scrolls for Free
    By Mario F. in forum General Discussions
    Replies: 2
    Last Post: 07-12-2009, 03:50 PM
  2. The Elder Scrolls V: Fallout
    By SlyMaelstrom in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 11-03-2008, 08:16 AM
  3. [OT] help translating and phrazing
    By jabka in forum C++ Programming
    Replies: 1
    Last Post: 05-04-2007, 11:37 AM
  4. Code translating
    By Liger86 in forum C Programming
    Replies: 3
    Last Post: 12-27-2002, 08:31 AM
  5. Elder Scrolls III: Morrowind
    By xds4lx in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 05-24-2002, 10:43 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21