skyfish4tb / masm2c

x86 assembler (MASM syntax) to C translator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MASM x86 to C translator 0.8

Translator may be used to port your DOS assembler code to SDL C. Since there is no working decompiler for 16 bit DOS code yet. Your porting path: DOS binary 16 bit real or 32 bit protected modes -> IDA Pro (disassembly) -> export assembler (masm format) -> Tasmx to compile (dosbox debugger to fix) -> this MASM to C translator -> C SDL source.

Optionally you can recompile resulting C to 32 bits with optimization and recompile to get cleaner C code without dead code and flags update.

Key features:

  • Most of x86 instructions (except FPU) are supported (well tested with QEMU tests). flags: Carry, Zero, Sign are supported for most of x86 instructions.
  • Segment memory model and 16bit offsets.
  • Some BIOS/DOS Int 10h, 21h interrupts are supported. Also DOS memory manager and stack.
  • CGA text mode is supported using Curses (PDcurses or NCurses).
  • VGA 320x200x256 support (partial)

3 party code used: ASM2C (x86 instruction emulation), tasm-recover (from SCUMMVM project; highly modified), QEMU x86 test suit, FreeDOS memory manager.

License: GPL2.

Sure ASM2C have cleaner code and good parser but it written on Swift and less instructions supported, also only protected mode.

TODO:

  • equ out of segment/proceedure
  • macros support
  • full VGA/EGA
  • better parser based on Masm EBNF
  • proper SB emulation or use DOSBOX as library
  • add FPU instructions support
  • better keyboard

Also to easier disassembling (exe to asm) need to collect run-time information from dosbox or other emulator to annotate IDA disassembly. Maybe modify dosbox debugger tracing mechanism to collect:

  • current instruction is code
  • access to memory (which segment), offset which segment
  • segement register value

To build resulting disassembly I use uasm(jwasm)/masm6, link5/tlink. See uasm\Samples\Dos\ for examples.

See list of DOS games with debug information http://bringerp.free.fr/forum/viewtopic.php?f=1&t=128

Execute to convert your masm 16 bit source to C:

masm-recover <some.asm>

(Some small resulting source code modification will be also required to build)

IDA Pro Free https://www.scummvm.org/news/20180331/

Inertia Player 1.22 source code

Famous reverse engenerred MOD, S3M player. Currently platform DOS (ASM), SDL2 (C++) There is source code for MASM, TASM Ideal and Nasm, gcc which can be built and running

TODO: fix sound on SDL, finish porting (keyboard, graphics mode,...)

Binary is available on releases page

Building Inertia for SDL from source:

  1. get PDCurses or other curses library+headers, SDL2, mingw32
  2. build_mingw.bat
  3. execute: iplay_masm.exe HACKER4.S3M

About

x86 assembler (MASM syntax) to C translator


Languages

Language:Assembly 55.7%Language:C 24.2%Language:C++ 18.4%Language:Python 0.7%Language:Perl 0.6%Language:ANTLR 0.2%Language:Shell 0.0%Language:Batchfile 0.0%Language:Makefile 0.0%