Jump to content

Z80 -> 6502 recompiler used with Pentagram port

Recommended Posts

Sorry for warming up this old thread. I found this very fascinating and compiled this source yesterday.

after some problems with visual studio 2019 I add the line:

#include "stdafx.h"

as first line in z80compiler and get the exe file finished.


Now I´m wondering , which disassembly file I need to proceed ?

How should the format going ? Label, opcode ?

is there a sample Z80 disassembly for testing ?




  • Like 1
Link to comment
Share on other sites


I tied z80dasm disassembler - no luck

I tried Dos DASMz80 - no luck

which disassembler is producing a correct file for this compiler ?

here some official z80 disassembly from win32 z80dasm...




	ld b,010h
	ld hl,06000h
	xor a	
	ld c,a	
	ld (hl),a	
	inc hl	
	dec c	
	jr nz,l026dh
	djnz l026ch
	ld b,004h
	ld hl,07000h
	ld c,a	
	ld (hl),a	
	inc hl	
	dec c	
	jr nz,l027ah
	djnz l0279h
	ld b,004h
	ld a,010h
	ld hl,07400h
	ld c,000h
	ld (hl),a	
	inc hl	
	dec c	
	jr nz,l028ah
	djnz l0288h
	ld hl,060c0h
	ld b,040h
	ld a,0ffh
	ld (hl),a	
	inc hl	
	djnz l0298h
	ld a,0c0h
	ld (060b0h),a
	ld (060b1h),a
	xor a	
	ld (07d83h),a
	ld (07d86h),a
	ld (07d87h),a
	inc a	
	ld (07d82h),a
	ld sp,06c00h
	call sub_011ch
	ld a,001h
	ld (07d84h),a


Link to comment
Share on other sites

On 1/26/2020 at 2:55 PM, mariuszw said:

Published recompiler is quite picky about format of disassembly and actually accepts only the format produced by my own disassembly tool. With the time, I updated recompiler to accept different formats of disassembly. Chances are I skoolkit produced disassembly listings can work now. If they don't, I can update recompiler.



Link to comment
Share on other sites


ah thank you. I missed the line. ok I will check this skoolish.

last night I tried to recompile the attached pg_disassembly and this will have trouble too. For instance a simple  " LD reg, Val" creates an error...

But slowly I get a feeling about that tool.... best willl be a sourcecode transformer to "mariuszdasm" format ;-)

;Start   XOR  A
;AF88:   OUT  (FE),A
;AF8A:   LD   HL,ScratchMem
;AF8D:   LD   BC,0726
;AF90:   CALL ClrMem
;LAF93   LD   HL,LA70E
;AF96:   LD   BC,0721
;AF99:   CALL ClrMem
;AF9C:   CALL ClrScr
;AF9F:   LD   A,43
;AFA1:   CALL FillAttr
;AFA7:   LD   A,05
;AFA9:   LD   (LA721),A
;AFAC:   LD   A,R
÷G     lda #$00 ; XOR   A
; Syntax Error: OUT   (FE),A
        sta z80_l
        lda #>SCRATCHMEM
        sta z80_h
        lda #<L0726CHMEM ; LD   BC,0726
        sta z80_c
        lda #>L0726CHMEM
        sta z80_b
        jsr CLRMEM ; CALL   CLRMEM
÷G     lda #<LA70E ; LD   HL,LA70E
        sta z80_l
        lda #>LA70E
        sta z80_h
        lda #<L0721 ; LD   BC,0721
        sta z80_c
        lda #>L0721
        sta z80_b
        jsr CLRMEM ; CALL   CLRMEM
        jsr CLRSCR ; CALL   CLRSCR
; Syntax Error: LD   A,43
        jsr LB29A ; CALL   LB29A
; Syntax Error: LD   A,05
        sta LA721 ; LD   (LA721),A; Warning: A read but not set by previous instruction
        ld_a_r ; LD   A,R


Edited by MarcoSantos
In the meantime I fixed some errors ....
Link to comment
Share on other sites

  • 1 month later...
  • 1 year later...
On 1/6/2016 at 8:39 PM, mariuszw said:



Some people were asking for recompiler I created for preparing Pentagram, so I decided to release it.


z80compiler.zip is a compiler. It takes Pentagram disassembly as input and creates 6502 listing ready to be compiled by MADS. Recompiler is very simple, it just takes every single Z80 instruction and just creates equivalent 6502 code from it. Recompiler performs basic code analysis and issues warning, where it thinks code needs to be reviewed and eventually changed. Following checks are done:

- usage of A register. Since 6502 uses A to emulate A of Z80 but also uses A to emulate many other instructions, a situation where Z80 instruction reads A register but previous Z80 instruction doesn't write the instruction is detected, as previous 6502 instruction may pollute A

- usage of ZERO flag: on Z80, ZERO flag is affected by very few instructions, while no 6502 almost all instructions affect ZERO flag. Warning is issued while Z80 instructions read ZERO flag but previous Z80 instruction does not write it

- usage of CARRY flag: check similar to ZERO flag is done. Also, since for CARRY for subtraction and comparison are reverted between Z80 and 6502, but the same for addition, recompiler inverts CARRY checks (because CMP/SBC are more common than ADD) and issues a warning when not CMP/SBC affects CARRY


Recompiler does not detect self-modifying code (2 instances in Pentagram). Recompiler also issues a warning for SP (Stack Pointer) manipulation, but cannot compile code which makes tricks with the stack directly (in Pentagram, sprite drawing codes reads directly using stack pointer).


Recompiler is not mean to be generic, so not all instructions are compiled. Basically it is prepared to work with Pentagram source only, while it should be expanded quite easily to support other games. It needs Z80 disassembly with code, data and pointers clearly recognized and identified in order to work.


The other tool is z80run.zip. It takes binary image of Z80 code and 6502 code, and executes them, logging all accesses (reads and writes) to memory, apart from:

- opcode fetching

- reading/writing data on zero page on 6502 (ZP registers are used to hold Z80 registers)

- stack reading/writing on both Z80 and 6502

Then, all accesses are compared to find errors. This turned out to be very effective tool to debug 6502 code.


z80run uses 6502 and Z80 emulators Copyright © Marat Fayzullin.


Both projects are written in C++ and compiled in Microsoft Visual Studio 2012.



z80run.zip 97.72 kB · 564 downloads

z80compiler.zip 11.58 kB · 631 downloads

just got interested into it...

is there a tool for the other way around probably? Does anybody know one? so my 6502 code to Z80?


Link to comment
Share on other sites

  • 1 year later...

This Z80 to 6502 recompilor sounds really cool on paper,but how good is it? Could you for instance translate a source code from a master system game into a nes game ???

sure you may have to do some manual tweaking and debugging all unsupported features or find some alternative features to get around it,but how smooth and stable could it run?

i can imagine that if recompilors already existed in the 1980’s that game developers might have used recompilors to translate one source code from a game from a certain system and recompile to them to other computer languanges with some manual tweaking and debugging to make them run on other systems,another option might be to use a similar game engine from a different game from a target system and adjust and moddify it to port that wanted game to that target platform,

Considering how long it already takes to create a source code for a certain game,i just cannot imagine why you would ever want to do all stuff all over and over again for different platform systems if semi automatic convertor tools should already exist right,

Sure you also need to take the amount of ram,ram and graphical as well as audio capabilities in mind from each system but there are semi automatic convertfor tools for that as well like shrunking down the resolution and color nut for the target system etc,, and with that in mind i just can’t instance imagine that those supermario advances series and supermariobros dx were rewritten from scratch by hand,why would you do that if it only takes more time and money to do so if semi automatic tool kits already exists,or if you do already have a similar game engine from another game for the target system to your disposal,i just cannot imagine how and why there could be otherwise be sooo many games on the market including ports.

Link to comment
Share on other sites

Programmers doing conversions in the 80s usually worked without any source code at all. The problem with recompilers is that most 80s home computer and console games only worked by tweaking everything to make optimum use of very limited and very machine-specific system resources. Using a recompilers would bloat the code and thus slow it down and you’d have to adapt it to the target system’s sound and graphics system anyway. When you have code that is tightly written around a specific system’s peculiarities, there isn’t much left to reuse. 

While not recompiled, some Apple II to Atari (and maybe C64) ports like Choplifter! reused the Apple code and just changed the video output code to work on a similar graphics mode on the target machine.

Norbert Kehrer did some working binary code translation to JavaScript but that’s for much faster target machines.

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

Z80 to Motorola 68000



This is a 1:1 arcade port of the game FROGGER by KONAMI from 1981 for the Amiga 500. The game is written in 68k assembler, based on the original Z80 code.





Edited by tebe
Link to comment
Share on other sites

  • 5 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...