Hi,
Post by Mike GontaSPACE INVADERS by PAUL S. REID Version 1.1
Ever so slightly updated version to assemble with FASM / NASM
Just to be complete, here's my NASM script to reassemble the
vanilla (unmodified) DOS version (tested with either GNU sed or
Laurent Vogel's Cheap sed):
*****************************************************************
@echo off
if "%SED%"=="" set SED=sed
if "%NASM%"=="" set NASM=nasm
if not exist invaders.asm goto end
echo %%SED%% = '%SED%'
echo %%NASM%% = '%NASM%'
:fix1
echo /^ *\([^ ]\+\) \+[dD]\([bBwWdD]\) .\+/!d>fix1.sed
echo "s||\1\\>/\2[\&]/|"| %SED% -e "s/^.//" -e "s/.$//">>fix1.sed
echo s/B\[/byte ptr [/>>fix1.sed
echo s/W\[/word ptr [/>>fix1.sed
echo s/D\[/dword ptr [/>>fix1.sed
echo "s|^|s/\\<|"| %SED% -e "s/^.//" -e "s/.$//">>fix1.sed
if not exist fix1.sed goto end
:fix2
echo 1i\>fix2.sed
echo %idefine offset\>>fix2.sed
echo %idefine ptr>>fix2.sed
echo /^ *;/b>>fix2.sed
echo s/LEA \+\([^ ]\+\), *\([^ ]\+\)/MOV \1,OFFSET \2/>>fix2.sed
echo /CODE_SEG/d>>fix2.sed
echo /^ *END/d>>fix2.sed
echo s/\]\[\([1-9]\)\]/+\1]/>>fix2.sed
echo s/\[0\]//>>fix2.sed
echo s/\]\(+BX\)/\1/>>fix2.sed
echo s/\[\([^ ]\+ ptr\)/\1/>>fix2.sed
echo s/\(ES:\)\(\[\)/\2\1/>>fix2.sed
echo s/ \+PROC/: ;&/>>fix2.sed
echo / ENDP/s/^/;/>>fix2.sed
echo s/\(Word Ptr\) dword ptr/\1/>>fix2.sed
if not exist fix2.sed goto cleanup
:fix3
echo /RemoveNewInt9:/,/ RET/s/OldInt9Addr/cs:&/>fix3.sed
echo /NewInt9Handler:/,/NotIntercept:/{>>fix3.sed
echo s/byte ptr \[/&cs:/>>fix3.sed
echo /cs:/!s/\(MOV \+\)\([^,]\+\)/\1cs:\2/>>fix3.sed
echo }>>fix3.sed
echo /NotIntercept:/,/^ *$/{>>fix3.sed
echo s/StoreAX/cs:&/>>fix3.sed
echo s/40://>>fix3.sed
echo }>>fix3.sed
if not exist fix3.sed goto cleanup
:asmvars
echo /^ *;/b>asmvars.sed
echo / [dD][bBwWdD] /b>>asmvars.sed
echo /, *OFFSET/b>>asmvars.sed
echo /LEA /b>>asmvars.sed
%SED% -f fix1.sed invaders.asm >>asmvars.sed
if not exist asmvars.sed goto cleanup
%SED% -f asmvars.sed invaders.asm|%SED% -f fix2.sed -f fix3.sed >inv-nasm.asm
if not exist inv-nasm.asm goto cleanup
:build
%NASM% -O9 -o inv-nasm.com inv-nasm.asm
if not exist inv-nasm.com goto cleanup
echo.
dir inv-nasm.com | grep -i "com"
echo.
echo INV-NASM.COM FFF22EF9
crc32 inv-nasm.com
echo.
:cleanup
if "%1"=="notclean" goto end
del fix*.sed >NUL
del asmvars.sed >NUL
:end
if "%SED%"=="sed" set SED=
if "%NASM%"=="nasm" set NASM=
*****************************************************************
And here's a makefile for cross-building atop Linux (e.g. antiX):
*****************************************************************
# GNUmakefile
.RECIPEPREFIX := _
#=== fix1.sed begins ===
# /^ *\([^ ]\+\) \+[dD]\([bBwWdD]\) .\+/!d
# s||\1\\>/\2[\&]/|
# s/B\[/byte ptr [/
# s/W\[/word ptr [/
# s/D\[/dword ptr [/
# s|^|s/\\<|
#=== fix1.sed ends ===
#=== fix2.sed begins ===
# 1i\
# %idefine offset\
# %idefine ptr
# /^ *;/b
# s/LEA \+\([^ ]\+\), *\([^ ]\+\)/MOV \1,OFFSET \2/
# /CODE_SEG/d
# /^ *END/d
# s/\]\[\([1-9]\)\]/+\1]/
# s/\[0\]//
# s/\]\(+BX\)/\1/
# s/\[\([^ ]\+ ptr\)/\1/
# s/\(ES:\)\(\[\)/\2\1/
# s/ \+PROC/: ;&/
# / ENDP/s/^/;/
# s/\(Word Ptr\) dword ptr/\1/
#=== fix2.sed ends ===
#=== fix3.sed begins ===
# /RemoveNewInt9:/,/ RET/s/OldInt9Addr/cs:&/
# /NewInt9Handler:/,/NotIntercept:/{
# s/byte ptr \[/&cs:/
# /cs:/!s/\(MOV \+\)\([^,]\+\)/\1cs:\2/
# }
# /NotIntercept:/,/^ *$/{
# s/StoreAX/cs:&/
# s/40://
# }
#=== fix3.sed ends ===
.PHONY: all clean
unexport UNZIP
SED=sed
NASM=nasm
NASMFLAGS=-fbin -O9v
MD5SUM=md5sum
WGET=wget
WGETOPT=-q
UNZIP=unzip
UNZIPOPT=-qjLan
GAMEURL=ftp.lanet.lv/ftp/mirror/x2ftp/msdos/programming/gamesrc/
GAMEZIP=invadr11.zip
all: inv-nasm.com
inv-nasm.com: inv-nasm.asm
_@$(NASM) $(NASMFLAGS) $< -o $@
_@$(MD5SUM) $@
***@echo 5d6fa26af01606feb90f17e014390139 \ inv-nasm.com
fix1.sed fix2.sed fix3.sed: $(lastword $(MAKEFILE_LIST))
_@$(SED) -e '/$@ begins ===/,/$@ ends ===/!d' $< | $(SED) -e 's/^# *//' >$@
asmvars.sed: fix1.sed invaders.asm
***@echo '/^ *;/b' >$@
***@echo '/ [dD][bBwWdD] /b' >>$@
***@echo '/, *OFFSET/b' >>$@
***@echo '/LEA /b' >>$@
_@$(SED) -f $^ >>$@
inv-nasm.asm: invaders.asm asmvars.sed fix2.sed fix3.sed
_@$(SED) -f asmvars.sed $< | $(SED) -f fix2.sed -f fix3.sed >$@
$(GAMEZIP):
_@$(WGET) $(WGETOPT) $(GAMEURL)$(GAMEZIP)
invaders.asm: $(GAMEZIP)
_@$(UNZIP) $(UNZIPOPT) $< "*/$@"
clean:
_@$(RM) inv-nasm.* fix?.sed asmvars.sed
*****************************************************************