Jump to content
  • 0

6502 to Z80 conversion


snake
 Share

Question

6 answers to this question

Recommended Posts

  • 0

!BYTE, !PET & !SCR looks to me like they are pseudo opcodes used by the ACME assembler. You would have to look up the equivalent codes for the assembler you are using for the Z80.

There is no way of directly translating CPY and CPX to Z80 assembly, but the Z80 has its own compare instructions: http://z80-heaven.wikidot.com/instructions-set:cp

disclaimer: I am by no means fluent in Z80 assembly and had to look up the CP instruction before I could write this reply.

Link to comment
Share on other sites

  • 0
On 10/8/2021 at 8:48 PM, JimmyDansbo said:

!BYTE, !PET & !SCR looks to me like they are pseudo opcodes used by the ACME assembler. You would have to look up the equivalent codes for the assembler you are using for the Z80.

There is no way of directly translating CPY and CPX to Z80 assembly, but the Z80 has its own compare instructions: http://z80-heaven.wikidot.com/instructions-set:cp

disclaimer: I am by no means fluent in Z80 assembly and had to look up the CP instruction before I could write this reply.

Thanks for the help, the original source code is quite large. I've converted everything else, yes there is no equivalent for CPY and CPX hence the question. !BYTE, !PET and !SCR are not 6502 commands they are commodore directives and yes they to compile in ACME, they don't compile in XA. I'm think DB may work for !BYTE,!PET,!SCR but will probably have to change the logic. Hopefully someone with experience porting Commodore games to Z80 Machines or Apple II can shed some light.

Link to comment
Share on other sites

  • 0
On 10/8/2021 at 12:08 PM, snake said:

I'm think DB may work for !BYTE,!PET,!SCR

DB will definitely work for !BYTE, but ACME tries to ensure that things that are defined as !PET or !SCR gets put into memory in such a way that characters typed in the source is the same when assembled and run on the target computer. You can you use DB instead of !PET and !SCR, but then you will need to ensure that correct conversion of characters is done. Your assembler may have other ways of storing strings.

Link to comment
Share on other sites

  • 0
On 10/8/2021 at 9:12 PM, JimmyDansbo said:

DB will definitely work for !BYTE, but ACME tries to ensure that things that are defined as !PET or !SCR gets put into memory in such a way that characters typed in the source is the same when assembled and run on the target computer. You can you use DB instead of !PET and !SCR, but then you will need to ensure that correct conversion of characters is done. Your assembler may have other ways of storing strings.

Yes it's compiles ok, but will it run ok? CPY and CPX I will need to get a number of source examples so I can work out what they do and how you would get the Z80 to do it.

Link to comment
Share on other sites

  • 0

Acme is a cross assembler, so the source code you write to feed into it uses ASCII (more or less from the 1967 standard that has been modified slightly over the years). The Commodore 8 bit line uses PETSCII (an extended form of ASCII 1963 standard that is similar to what we know as ASCII today yet different, and all the extensions on top of that).

So !PET is used to convert the ASCII encoded source code into PETSCII encoded object code. If you are porting code to a Z80, likely using CP/M (though not necessarily), you won't want to convert ASCII to PETSCII for the main ASCII characters. Any extended ASCII that a platform might use is going to require a custom conversion.

!SCR is used to convert the ASCII encoded source code into screen codes that can be written directly to screen memory, as they are not compatible with ASCII or PETSCII. Any Z80 based system with video hardware might use ASCII for its memory mapped video (if it has such a thing) or it might use something completely different. There is no universal way to say "this is how !SCR should be translated to another platform".

Link to comment
Share on other sites

  • 0
On 10/8/2021 at 3:08 AM, snake said:

Thanks for the help, the original source code is quite large. I've converted everything else, yes there is no equivalent for CPY and CPX hence the question. !BYTE, !PET and !SCR are not 6502 commands they are commodore directives and yes they to compile in ACME, they don't compile in XA. I'm think DB may work for !BYTE,!PET,!SCR but will probably have to change the logic. Hopefully someone with experience porting Commodore games to Z80 Machines or Apple II can shed some light.

You're not compiling assembly code. You're assembling it. Compilers and assemblers are different things. 😉

Anyway, the !BYTE, !PET, and !SCR are assembler directives for raw data. You're correct that the DB directive is the replacement on other assemblers (including other 6502 assemblers.)

The thing to remember is that non-Commodore computers don't have PETSCII, and everything else you're likely to encounter uses ASCII. (There were some non-ASCII mainframes, such as IBM EBCDIC, but we're not going to talk about that.)

So the !SCR and !PET commands are there to convert ASCII text to the PETSCII or the screen code equivalent. Since an "A" is 65 in ASCII, 96 in upper/lower case PETSCII, and 1 in screen code PETSCII, you have to tell the assembler which code to use for "A". But the Spectrum only talks ASCII, so you don't need to re-encode text. This means you don't have or need any of the cross-platform encoding directives like !PET. Just use the DB directive to encode the ASCII values to binary, or check your assembler manual to see what it uses for text encoding. Since every assembler is a little different, you definitely need to read the manual.

And yes - there are equivalents to CPX and CPY: all the various "ld" instructions, such as LD A,B or LD B,C. The equivalent to indexed instructions is anything using (HL), so something like LD (HL), A copies data from the Accumulator to the address pointed to by the HL register pair.

There are also no indirect operations, so nothing like LDA ($20). Instead, you have to LD HL,20h and then LD A,(HL). 

You'll find that the Z80 has a different way of doing things, and it's actually easier to code for in the long run... the problem is that in the short run, you want to do things like zero page addressing or indexed indirect addressing and can't... but once you translate the concepts to Intel's simpler paradigm, it's actually easier. You have 7 registers to work with, and 16 bit math only takes one instruction. So a lot of things we need to do the hard way just take one operation on Z80. 


 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

Please review our Terms of Use