flat assembler
Message board for the users of flat assembler.

flat assembler > DOS > PSR Invaders 1.1

Author
Thread Post new topic Reply to topic
rugxulo



Joined: 09 Aug 2005
Posts: 2292
Location: Usono (aka, USA)
Ever played PSR Invaders 1.1 (circa 1995)? invadr11.zip (27 kb) mirror #2

In 2004, I manually (but sloppily) converted it to work with free assemblers. But this new script is much simpler, smaller, and more accurate than the full quirky, modified source.

Tested with either GNU sed or Cheap sed.

EDIT: Minor .BAT cleanups, now builds in Windows, too.
EDIT#2: Minor simplifications.

Code:
@echo off

::#--- fix2.sed begins ---
:: 1i\
:: OFFSET equ\
:: Offset equ\
:: Ptr equ\
:: LEA equ MOV
:: /^;/b
:: /CODE_SEG/d
:: /END /d
:: / ENDP/d
:: s/40://
:: s/\]\[/+/
:: s/\[0\]//
:: s/\][+]BX/+BX/
:: s/ES:\[/[ES:/
:: s/[ ][ ]*PROC .*/:/
:: s/\[\[/[/
::#--- fix2.sed ends ---

::#--- fix3.sed begins ---
:: /RemoveNewInt9:/,/ RET/s/OldInt9Addr/cs:&/
:: /NewInt9Handler:/,/NotIntercept:/s/\[/[cs:/
:: /NotIntercept:/,/CLC/s/StoreAX/cs:&/
::#--- fix3.sed ends ---

::#--- vars.sed begins ---
:: /^;/b
:: / D[BWD] /b
:: /,OFFSET/b
:: /LEA /b
::#--- vars.sed ends ---

if not exist invaders.asm goto end
if not exist %0 %0.bat %1

if "%SED%"=="" set SED=sed
echo %%SED%% = '%SED%'

set B1=begins ---
set E1=ends ---
set S1=fix2.sed fix3.sed vars.sed
for %%a in (%S1%) do %SED% -n -e "/%%a %B1%/,/ %E1%$/s/^::[ ][ ]*//w %%a" %0
for %%z in (S1 E1 B1) do set %%z=

for %%a in (fix2 fix3 vars) do if not exist %%a.sed goto end

set I0=invaders.asm
%SED% -n -e "/ D[BWD] /s@^\([^ ][^ ]*\).*@s/\\<\1\\>/[\&]/@p" %I0%>>vars.sed
%SED% -f vars.sed %I0% | %SED% -f fix2.sed -f fix3.sed >inv-fasm.asm
set I0=

REM cwsdpmi
fasm inv-fasm.asm inv-fasm.com >NUL
if not exist inv-fasm.com goto end

echo.
echo INV-FASM.COM    FFF22EF9
crc32 inv-fasm.com
echo.

if "%1"=="notclean" goto end
del vars.sed >NUL
del fix?.sed >NUL
del inv-fasm.asm >NUL

:end
if "%SED%"=="sed" set SED=
    


Since I'm also sometimes using antiX Linux, which comes with DOSBox, I also whipped up a quick makefile in order to cross-build.

EDIT: Very minor makefile cleanups.
EDIT#2: Minor simplifications.

Code:
# GNUmakefile
.RECIPEPREFIX := _

#=== fix2.sed begins ===
# 1i\
# OFFSET equ\
# Offset equ\
# Ptr equ\
# LEA equ MOV
# /^;/b
# /CODE_SEG/d
# /END /d
# / ENDP/d
# s/40://
# s/\]\[/+/
# s/\[0\]//
# s/\][+]BX/+BX/
# s/ES:\[/[ES:/
# s/[ ][ ]*PROC .*/:/
# s/\[\[/[/
#=== fix2.sed ends ===

#=== fix3.sed begins ===
# /RemoveNewInt9:/,/ RET/s/OldInt9Addr/cs:&/
# /NewInt9Handler:/,/NotIntercept:/s/\[/[cs:/
# /NotIntercept:/,/CLC/s/StoreAX/cs:&/
#=== fix3.sed ends ===

.PHONY: all check clean cleanall

PROG=inv-fasm
GAMEZIP=invadr11.zip
OLDASM=INVADERS.ASM
SED=sed
FASM=fasm
MD5SUM=md5sum
WGET=wget
WGETOPT=-q
UNZIPPER=unzip
UNZIPFLAGS=-qjan

#GAMEURL=ftp.lanet.lv/ftp/mirror/x2ftp/msdos/programming/gamesrc/
GAMEURL=www.ibiblio.org/pub/micro/pc-stuff/freedos/files/games/invaders/

all: $(PROG).com check

$(PROG).com: $(PROG).asm
_@$(FASM) $< $@

fix2.sed fix3.sed: $(lastword $(MAKEFILE_LIST))
_@$(SED) -n -e '/$@ begins ===/,/$@ ends ===/s/^#[ ][ ]*//w $@' $<

asmvars.sed: $(OLDASM)
_@$(SED) -n -e 's|^\([^ ][^ ]*\)[ ][ ]*D[BWD] ..*|s/\\<\1\\>/[\&]/|p' $^ >$@

$(PROG).asm: $(OLDASM) asmvars.sed fix2.sed fix3.sed
_@$(SED) -e '/^;/b' -e '/ D[BWD] /b' -e '/,OFFSET/b' -e '/LEA /b'\
 -f asmvars.sed $< | $(SED) -f fix2.sed -f fix3.sed >$@

$(GAMEZIP):
_@$(WGET) $(WGETOPT) $(GAMEURL)$(GAMEZIP)

$(OLDASM): $(GAMEZIP)
_@$(UNZIPPER) $(UNZIPFLAGS) $< INVADERS/$@ >/dev/null

check: $(PROG).com
_@$(MD5SUM) $<
_@echo 5d6fa26af01606feb90f17e014390139 \ $<

clean:
_@$(RM) $(PROG).asm fix?.sed asmvars.sed

cleanall: clean
_@$(RM) $(PROG).com $(OLDASM)

# EOF
    


Last edited by rugxulo on 20 Feb 2018, 04:55; edited 3 times in total
Post 08 Feb 2017, 09:30
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2292
Location: Usono (aka, USA)
I thought GNU sed and Cheap sed would be good enough for everyone (not that anyone complained). Both are GPL with ports to DOS, Windows, Linux, et al. But apparently "\<" "\>" is not truly portable nor standardized (yet??).

Cheap sed (2004) is a modified version of HHsed (1991), which was based upon Eric Raymond's sed. Another improved derivative of his by Rene Rebe is called minised (2014, BSD), which lacks the non-standard feature mentioned above.

So, in the interest of perfection, I toyed with the idea of making a working script that didn't need the non-standard kludge. (I already did the same for NASM but instead using its preprocessor.)

Just for completeness ....

P.S. Happy 40th anniversary, Space Invaders!

INV-FAS2.BAT
Code:
@echo off

::#--- fix2.sed begins ---
:: 1i\
:: OFFSET equ\
:: Offset equ\
:: Ptr equ\
:: LEA equ MOV
:: /^;/b
:: /CODE_SEG/d
:: /END /d
:: / ENDP/d
:: s/[ ][ ]*PROC .*/:/
:: s/ES:\[/[ES:/
:: s/ DD / DW 0,/
:: s/\[0\]$//
:: s/40://
:: s/,,,*/,/
:: s/,\[\([0-9]\)\],\(\[.*\)\]/,\2+\1]/
:: s/\],\[/+/
:: /INC /s/\[\([0-9]\)\]/+\1/
:: /[+]BX/!s/\([ID].C\)[ ][ ]*\([^ ][^ ][^ ][^ ]*\)/\1 [\2]/
::#--- fix2.sed ends ---

::#--- fix3.sed begins ---
:: /RemoveNewInt9:/,/ RET/s/OldInt9Addr/cs:&/
:: /NewInt9Handler:/,/NotIntercept:/s/\[/[cs:/
:: /NotIntercept:/,/CLC/s/StoreAX/cs:&/
::#--- fix3.sed ends ---

::#--- vars1.sed begins ---
:: /^;/b
:: / D[BWD] /b
:: /,OFFSET/b
:: /LEA /b
:: s/ *;.*$//
:: s/Word Ptr //
:: s/\[[0-9]\],/,&/
:: s/\(,.*\)\(\[[0-9]\]\)/,\2\1/
::#--- vars1.sed ends ---

set INV=invaders.asm
if not exist %INV% goto end
if not exist %0 %0.bat %1

if "%SED%"=="" set SED=minised
echo %%SED%% = '%SED%'

set B1=begins ---
set E1=ends ---
set S1=fix2.sed fix3.sed vars1.sed
for %%a in (%S1%) do %SED% -n -e "/%%a %B1%/,/ %E1%$/s/^::[ ][ ]*//w %%a" %0
for %%z in (S1 E1 B1) do set %%z=

for %%a in (fix2 fix3 vars1) do if not exist %%a.sed goto end

set V1=vars1.sed
set V2=vars2.sed
set F2=fix2.sed
set F3=fix3.sed
%SED% -n -e "/ D[BWD] /s|^\([^ ][^ ]*\).*|s/,\\(\1\\)$/,[\\1]/|p" %INV%>>%V1%
%SED% -e "s|^s/,|s/ |" -e "s|\$/,\[\\1\]/|,/[\\1],/|" %V1% >%V2%
%SED% -f %V1% %INV% | %SED% -f %V2% | %SED% -f %F2% -f %F3% >inv-fasm.asm
for %%z in (V1 V2 F2 F3) do set %%z=

REM cwsdpmi
fasm inv-fasm.asm inv-fasm.com >NUL
if not exist inv-fasm.com goto end

echo.
echo INV-FASM.COM    FFF22EF9
crc32 inv-fasm.com
echo.

if "%1"=="notclean" goto end
del vars?.sed >NUL
del fix?.sed >NUL
del inv-fasm.asm >NUL

:end
set INV=
if "%SED%"=="minised" set SED=
    


FASM2.MAK
Code:
# GNUmakefile
.NOTPARALLEL:
.RECIPEPREFIX := _

#=== fix2.sed begins ===
# 1i\
# OFFSET equ\
# Offset equ\
# Ptr equ\
# LEA equ MOV
# /^;/b
# /CODE_SEG/d
# /END /d
# / ENDP/d
# s/[ ][ ]*PROC .*/:/
# s/ES:\[/[ES:/
# s/ DD / DW 0,/
# s/\[0\]$//
# s/40://
# s/,,,*/,/
# s/,\[\([0-9]\)\],\(\[.*\)\]/,\2+\1]/
# s/\],\[/+/
# /INC /s/\[\([0-9]\)\]/+\1/
# /[+]BX/!s/\([ID].C\)[ ][ ]*\([^ ][^ ][^ ][^ ]*\)/\1 [\2]/
#=== fix2.sed ends ===

#=== fix3.sed begins ===
# /RemoveNewInt9:/,/ RET/s/OldInt9Addr/cs:&/
# /NewInt9Handler:/,/NotIntercept:/s/\[/[cs:/
# /NotIntercept:/,/CLC/s/StoreAX/cs:&/
#=== fix3.sed ends ===

#=== vars0.sed begins ===
# /^;/b
# / D[BWD] /b
# /,OFFSET/b
# /LEA /b
# s/ *;.*$//
# s/Word Ptr //
# s/\[[0-9]\],/,&/
# s/\(,.*\)\(\[[0-9]\]\)/,\2\1/
#=== vars0.sed ends ===

.PHONY: all check clean cleanall

#http://exactcode.com/opensource/minised/
#http://dl.exactcode.de/oss/minised/minised-1.15.tar.gz
SED=minised

PROG=inv-fasm
GAMEZIP=invadr11.zip
OLDASM=INVADERS.ASM
FASM=fasm
MD5SUM=md5sum
WGET=wget
WGETOPT=-q
UNZIPPER=unzip
UNZIPFLAGS=-qjan

#GAMEURL=ftp.lanet.lv/ftp/mirror/x2ftp/msdos/programming/gamesrc/
GAMEURL=www.ibiblio.org/pub/micro/pc-stuff/freedos/files/games/invaders/

all: $(PROG).com check

$(PROG).com: $(PROG).asm
_$(FASM) $< $@

fix2.sed fix3.sed vars0.sed: $(lastword $(MAKEFILE_LIST))
_@$(SED) -n -e '/$@ begins ===/,/$@ ends ===/s/^#[ ][ ]*//w $@' $<

vars1.sed: $(OLDASM)
_@$(SED) -n -e '/ D[BWD] /s|^\([^ ][^ ]*\).*|s/,\\(\1\\)$$/,[\\1]/|p' $< >$@

vars2.sed: vars1.sed
_@$(SED) -e 's|^s/,|s/ |' -e 's|\$$/,\[\\1\]/|,/[\\1],/|' $< >$@

$(PROG).asm: vars0.sed vars1.sed vars2.sed fix2.sed fix3.sed $(OLDASM)
_$(SED) -f $(word 1,$^) -f $(word 2,$^) $(lastword $^)\
 | $(SED) -f $(word 1,$^) -f $(word 3,$^)\
 | $(SED) -f $(word 4,$^) -f $(word 5,$^) >$@

$(GAMEZIP):
_@$(WGET) $(WGETOPT) $(GAMEURL)$(GAMEZIP)

$(OLDASM): $(GAMEZIP)
_@$(UNZIPPER) $(UNZIPFLAGS) $< INVADERS/$@ >/dev/null

check: $(PROG).com
_@$(MD5SUM) $<
_@echo 5d6fa26af01606feb90f17e014390139 \ $<

clean:
_@$(RM) $(PROG).asm vars?.sed fix?.sed

cleanall: clean
_@$(RM) $(PROG).com $(OLDASM)

# EOF
    


Last edited by rugxulo on 16 Feb 2018, 20:12; edited 1 time in total
Post 07 Feb 2018, 21:34
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2292
Location: Usono (aka, USA)
rugxulo wrote:
But apparently "\<" "\>" is not truly portable nor standardized.


Ugh, apparently "\+" isn't standard either, so I amended my newer script to avoid that. I thought it was only misunderstood in really ancient implementations (e.g. hhsed [1991] or sedmod [1987]), but apparently various modern *BSD seds also get confused.

Sedcheck dislikes "\<" (which it reports as "\'" for some odd reason), "\]" (only, which I consider spurious ... should I prefer "[]]" ?? doubt it!), and also "\+" (although "\{1,\}" isn't necessary here, and sedmod hates it).

Due to legibility issues, I prefer kludgy "[ ][ ]*" instead of (two-space) " *".

Also, GNU sed "--posix" has no problems now.

I haven't retested *BSD yet again, but I should try old FreeBSD 6.4 (with doscmd and X11), just in case that works.
Post 12 Feb 2018, 21:38
View user's profile Send private message Visit poster's website Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 1203
Reading about all these limitations of various sed versions makes me understand why autoconf is such a nightmare, I suppose. Smile (I've only used GNU sed)
Post 13 Feb 2018, 13:26
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2292
Location: Usono (aka, USA)
It was all in the spirit of minimalism, keeping things small with few dependencies, doing so as simply and portably as possible.

I guess I could've used Devore's NOMYSO (Perl), but Perl is much heavier, and the DJGPP port is abandoned (stuck at old 5.8.8).

GNU sed still gets ports to DJGPP (barely), but it looks annoying to rebuild (haven't tried). Also, it's bloated. But it does work. But so does Cheap Sed.

Latest GNU sed 4.4 (32-bit, DJGPP 2.05) is 291 kb (or 140 kb UPX'd).
Old GNU sed 4.2.2 (32-bit, DJGPP 2.03p2) is 220 kb (or 105 kb UPX'd).
Cheap sed (16-bit, 2004) is 26 kb (or 15 kb UPX'd).

I was naive and forgot that "\<" wasn't standard. I guess that's not BRE, only ERE? Introduced in ex/vi, presumably (while sed originally came from ed).

It just seems silly, to me, to require GNU sed when *BSD sed is 90% compatible already. Nobody wants to require two different seds just because software is too stupid to be compatible. It's like relying on both Perl and Python, or multiple assemblers. Sure, some projects do it, but it's "bad". Redundancy is bad.
Post 16 Feb 2018, 19:37
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2018, Tomasz Grysztar.

Powered by rwasa.