flat assembler
Message board for the users of flat assembler.

Index > Projects and Ideas > another Befunge interpreter for DOS (BEFI.COM)


What do you think of this?
Waste of time, esolangs are boring.
20%
 20%  [ 3 ]
Partially 16-bit? OBSOLETE!
20%
 20%  [ 3 ]
I hate DOS, it should die.
6%
 6%  [ 1 ]
Befunge98 is SO much more interesting.
0%
 0%  [ 0 ]
Very nice, tiny size, fun, cool beans!
53%
 53%  [ 8 ]
Total Votes : 15

Author
Thread Post new topic Reply to topic
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 30 Oct 2009, 17:54
Instead of cluttering up Pinecone_'s Win32 interpreter project thread or the (dead?) Esoteric language challenge thread, I'm putting this here (not that anybody cares besides me, though, *sniff*).

Current size: 1023 bytes uncompressed w/ simple LFN support

N.B. Doesn't work in DOSEMU 1.4.0 under XUbuntu x86-64 (most likely due to self-modifying code confusing the 16-bit emulation), but it works everywhere else I tried (32-bit DOSEMU, DOSBox, Vista, XP, DR-DOS, FreeDOS, MS-DOS).

EDIT: Deleted attachment.
Post 30 Oct 2009, 17:54
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 06 Nov 2009, 21:57
Okay, I got bored and hacked it a little bit more. Mostly I wanted to add a 386 check so that it wouldn't just blindly crash on old computers. (Yeah, I know, who the heck still runs those? But just in case ....) So I did (tested under Joris' Retro, didn't crash). And it seems to still work okay, so I guess I didn't break anything. Laughing

1024 bytes uncompressed (or 1023 aPACK'd or 1016 w/ 624 -s)

P.S. I still dream of maybe converting it entirely to 16-bit (as it's mostly 16-bit code anyways), e.g. 8086, but that would be annoying (only 'cause I'm not confident that I'd do it correctly, I hate bugs!!). Almost definitely wouldn't be < 1024 bytes, but then again, I said that before too. Laughing Oh, and I noticed for the first time that the official BEF.C claims to support Borland C 3.1 16-bit, so I compiled with Turbo C++ 1.01, and it seemed to surprisingly work okay, 17k (or 10k UPX'd), much smaller than OpenWatcom (24k or 17k UPX'd). So I guess 8086 users aren't completely out in the cold (MTFI 8086 version mostly works but seems possibly limited to 16-bit stack, e.g. BENCHMARK.BEF doesn't work correctly but TC version handles it okay).

EDIT: (Nov 17) Minor .BAT tweaks, minor B98-compatible tweaks for examples, no code changes.


Last edited by rugxulo on 17 Apr 2010, 01:14; edited 1 time in total
Post 06 Nov 2009, 21:57
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 14 Apr 2010, 17:28
Another update, minor bugfix (e.g. didn't ignore uppercase letters correctly, which also apparently fixes official befunge[3x].bf), somewhat improved examples. Still 1024 bytes (but due to bugfix I had to make it where it always returns a bogus errorlevel, to save a byte, which isn't ideal but will be fixed eventually ... hopefully). Also now can build with newer JWasm versions (unlike older since JWasm now uses shorter "cmp sp,..." encoding by default).

P.S. I know it's confusing having the version "number" be "2k" (previously "2j"), but whatever, just go with it for now. Wink


Last edited by rugxulo on 17 Apr 2010, 01:15; edited 1 time in total
Post 14 Apr 2010, 17:28
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 17 Apr 2010, 01:13
Another update, hopefully (??) the "idiv" bug (see NEGMOD.BEF) seems gone. I also fixed the errorlevel issue. Only 1014 bytes now, ironically, because I was doing things the wrong way, it bloated to 1040, and I was forced to shrink to 1033 before seeing my mistake.

Feel free to stress test it with various examples, and please post any snippets (re: bugs) here.


Last edited by rugxulo on 24 Apr 2010, 01:15; edited 1 time in total
Post 17 Apr 2010, 01:13
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 22 Apr 2010, 21:34
Well, I think I'm going to "bloat" it a bit (four extra bytes) to increase speed. Technically, I've not optimized for speed at all, but self-modifying code (found in original, not added by me) just hurts too much.

Code:
v   benchmk2.bef (remove this line + all 'v<^>' to revert to benchmark.bef)
>91+:*-:0`#@ #._v
^               <
    


EDIT: Those 'v^<>' chars change IP direction, which is what the self-modifying code was used for. So it was self-modifying quite a lot!

Quote:

[ WinXP ] c:\tmp> runtime befi1014 benchmk2.bef
2147483596 41.87 seconds elapsed

[ WinXP ] c:\tmp> runtime befi1018 benchmk2.bef
2147483596 10.28 seconds elapsed

CPU brand is GenuineIntel / CPU is family f model 2 revision 7
This CPU calls itself: [ Intel(R) Celeron(R) CPU 2.40GHz_]


Quote:

[ DR-DOS 7.03 ] P166 no MMX> runtime befi1014 benchmk2.bef
2147483596 02:29.84 elapsed

[ DR-DOS ] Thu 4-22-2010> runtime befi1018 benchmk2.bef
2147483596 01:54.29 elapsed

CPU brand is GenuineIntel / CPU is family 5 model 2 revision c
Pentium 166 no MMX, DR-DOS 7.03


EDIT: I should post results for my Athlon64x2, it's even worse! Shocked
Post 22 Apr 2010, 21:34
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 24 Apr 2010, 01:19
Well, another release, and I was actually able to shrink it back to 1014 uncompressed (although I know that's confusing for the unaware user, heh, same size as before!) while still keeping it fast. Wink
Post 24 Apr 2010, 01:19
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 05 May 2010, 22:50
Another update, now shrank down to 982 bytes, but it slowed down the benchmark again on this P4 (argh). Added some other misc. files too (Rexx version(s), two more examples).

EDIT: (July 20) No .ASM changes, just basically added some other binaries from my Pascal version, plus adjusted and added some examples.
Post 05 May 2010, 22:50
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 01 Sep 2010, 01:50
Well, I feel silly attaching a 100 kb .ZIP that contains a lot of non-assembly cruft. So I guess I'll just attach the latest (final?) (F)ASM src here instead (smaller, at least). Anybody who cares (unlikely) can get the full file from my site. (Still no x86 asm changes since May 5.)


Description:
Download
Filename: befi.asm
Filesize: 10.08 KB
Downloaded: 1091 Time(s)

Post 01 Sep 2010, 01:50
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 16 May 2012, 21:38
Two silly changes, but it saved nine bytes. (I know, big whoop, and for various reasons the whole thing needs a rewrite anyways, bah.)

EDIT: removed obsolete diff.
Post 16 May 2012, 21:38
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 26 May 2012, 06:29
Bah, I'm such a doofus. Sure, I shrank it, but I introduced a (rare) bug that my existing tests didn't uncover. I don't know what I was thinking.

Code:
<v_,#! #:<"Should be: 625 0 "+91::::::::::" "
>>5:*:*:.!.@
    


Well, anyways, here's a newer diff, and it fixes that plus is now only 970 bytes (whee!). Yes, I realize this is fairly useless at this point (and horribly ugly / obfuscated due to relying on anarchy instead of a stable calling convention, heh, probably not the best thing for further maintenance, but it's still fun).

Code:
diff -wasruN old/befi.asm new/befi.asm
--- old/befi.asm  2010-05-04 09:34:02 +0000
+++ new/befi.asm   2012-05-26 00:20:46 +0000
@@ -3,9 +3,9 @@
 ; ***************************************************************
 ;
 ; old  TASM version:     1280 bytes   ( 1082 bytes aPACK'd      )
-; this FASM version:      982 bytes   (  999 aPACK,  998 w/ 624 )
+; this FASM version:      970 bytes   (  993 aPACK,  990 w/ 624 )
 ;
-; Tuesday, May 4, 2010  2:33pm
+; Saturday, May 26, 2012
 ;
 ; "Ad Maiorem Gloriam Dei" && "Christus Rex"
 ;
@@ -284,7 +284,7 @@
 
 lvif:
  call pop1
- and eax,eax
+ test eax,eax
  jnz lup
 
 ldn:
@@ -365,15 +365,15 @@
 lnot:
  call pop1
  test eax,eax
- lea eax,[0]
  setz al
- jmp push_jump
+ jmp and_push_jump
 
 lgreat:
  call pop2
  cmp eax,edx
- lea eax,[0]
  setg al
+and_push_jump:
+ and eax,1
  jmp push_jump
 
 lrt:
@@ -400,13 +400,16 @@
  shl cl,3
  shl ax,cl
  add al,al
- mov magx,al
- mov magy,ah
+
+; mov magx,al
+; mov magy,ah
+ mov [my_magx],ax
+
  jmp lnop1
 
 lhif:
  call pop1
- and eax,eax
+ test eax,eax
  jz lrt
 
 llt:
@@ -495,7 +498,21 @@
 
 rand:
  cmp word [F1],179
- jnz seed
+ jz rn
+
+seed:
+ mov word [F1],179 ; use the BIOS clock as a seed
+ xor ah,ah
+ int 1Ah
+
+; mov [S1],dx
+; mov [S2],cx
+ mov di,S1
+ xchg ax,dx
+ stosw
+ xchg ax,cx
+ stosw
+
 rn:
  push si
  mov si,S1
@@ -522,21 +539,6 @@
  pop si
  ret
 
-seed:
- mov word [F1],179 ; use the BIOS clock as a seed
- xor ah,ah
- int 1Ah
-
-; mov [S1],dx
-; mov [S2],cx
- mov di,S1
- xchg ax,dx
- stosw
- xchg ax,cx
- stosw
-
- jmp rn
-
 inch:
  cmp byte [ib+1],0
  jnz inch_ugc
@@ -742,12 +744,21 @@
 ;dw lnop,lswap,lnop,lup,lhif,lgreat
 
 table1:
-db lnot-200h,lstr-200h,lbridge-200h,lpop-200h,lmod-200h,linval-200h,lnop-200h
-db lnop-200h,lnop-200h,lmul-200h,ladd-200h,loutchr-200h,lsub-200h,loutval-200h,ldiv-200h
-db lpush-200h,lpush-200h,lpush-200h,lpush-200h,lpush-200h,lpush-200h,lpush-200h,lpush-200h,lpush-200h,lpush-200h
-db ldup-200h,lnop-200h,llt-200h,lnop-200h,lrt-200h,lrand-200h,lend-200h
+db lnot-200h,lstr-200h,lbridge-200h,lpop-200h,lmod-200h
+db linval-200h,lnop-200h
+
+db lnop-200h,lnop-200h,lmul-200h,ladd-200h,loutchr-200h
+db lsub-200h,loutval-200h,ldiv-200h
+
+db lpush-200h,lpush-200h,lpush-200h,lpush-200h,lpush-200h
+db lpush-200h,lpush-200h,lpush-200h,lpush-200h,lpush-200h
+
+db ldup-200h,lnop-200h,llt-200h,lnop-200h,lrt-200h
+db lrand-200h,lend-200h
+
 table2:
-db lnop-200h,lswap-200h,lnop-200h,lup-200h,lhif-200h,lgreat-200h
+db lnop-200h,lswap-200h,lnop-200h,lup-200h,lhif-200h
+db lgreat-200h
 
 ;badfilemsg: db '?$'
 ;badfilemsg: db 'Bad file',13,10,'$'
    
Post 26 May 2012, 06:29
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.