# HG changeset patch # User boisy@tee-boy.com # Date 1443901837 18000 # Node ID 83bf26264aa616b4a2ba7d99db1b02de87ba6cd1 # Parent a9311007b1b26d6222eed480078e622f6c95972a Added brainfuck interpreter diff -r a9311007b1b2 -r 83bf26264aa6 3rdparty/packages/brainfuck/ReadMe --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/3rdparty/packages/brainfuck/ReadMe Sat Oct 03 14:50:37 2015 -0500 @@ -0,0 +1,8 @@ +Brainfuck is a dead-simple, Turing complete computer language. +This is a dead-simple interpreter for the language. It takes a single parameter: the name of the source file. + +e.g. + +brainfuck helloworld.bf + +Learn more about Brainfuck here: https://en.wikipedia.org/wiki/Brainfuck diff -r a9311007b1b2 -r 83bf26264aa6 3rdparty/packages/brainfuck/b.asm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/3rdparty/packages/brainfuck/b.asm Sat Oct 03 14:50:37 2015 -0500 @@ -0,0 +1,379 @@ +******************************************************************** +* NGU - The "Next Great Utility" +* +* $Id$ +* +* NGU is a template for writing utilities under OS-9/6809. It has +* robust option handling and is littered with comments to help you +* write your own utilities. +* +* NGU uses a two-pass method for parsing the command line. On the +* first pass, dash options are processed and internal flags are set +* accordingly. As the options are processed, they are cleared to +* spaces so that they won't be present on the second pass. +* +* e.g. +* 1st pass: ngu -x foo1 -y foo2 -t=bar1 -ab +* 2nd pass: ngu foo1 foo2 +* +* For the second pass, NGU parses the remaining arguments, which don't +* begin with -. Presumably these are filenames or other names that are to be +* processed. +* +* Features: +* - Written for 6809 and 6309 processors in fast, compact +* assembly language. +* +* - Both options and files can be specified anywhere +* on the command line +* (i.e ngu -a test1 -b test2 -c=foo) +* +* - Multiple options can be combined behind one dash: +* (i.e ngu -ab test1 -c=foo test2 test3) +* +* - Several useful assembly routines are provided for +* copying strings and determining string length. +* +* Limitations: +* - Only single character option names can be processed. +* Multi-character option names (i.e. -delete) aren't supported. +* +* - The current file counter is one byte, counting a maximum +* of 255 files. +* +* Edt/Rev YYYY/MM/DD Modified by +* Comment +* ------------------------------------------------------------------ +* 1 2003/01/11 Boisy G. Pitre +* Put your development info here. + + nam NGU + ttl The "Next Great Utility" + + ifp1 + use defsfile + endc + +* Here are some tweakable options +DOHELP set 1 1 = include help info +STACKSZ set 128 estimated stack size in bytes +PARMSZ set 256 estimated parameter size in bytes +COPTSIZ set 64 max size of C option's parameter + +* Module header definitions +tylg set Prgrm+Objct +atrv set ReEnt+rev +rev set $00 +edition set 1 + + mod eom,name,tylg,atrv,start,size + +* Your utility's static storage vars go here + org 0 +* These vars are used by the base template and shouldn't be removed +parmptr rmb 2 pointer to our command line params +bufptr rmb 2 pointer to user expandable buffer +bufsiz rmb 2 size of user expandable buffer +filecnt rmb 1 +* These vars are used for this example, it will probably change for you +gota rmb 1 +gotb rmb 1 +coptflg rmb 1 1 = this option has been processed once already +cleartop equ . everything up to here gets cleared at start +copt rmb COPTSIZ buffer for what follows after -c= +* Next is a user adjustable buffer with # modifier on command line. +* Some utilities won't need this flexibility, some will. +* Currently set up to be larger for Level 2 than Level 1 +* Note: this buffer must come just before the stack + IFGT Level-1 +bigbuff rmb 8*1024 8K default buffer for Level 2 + ELSE +bigbuff rmb 512 512 byte default buffer for Level 1 + ENDC +* Finally the stack for any PSHS/PULS/BSR/LBSRs that we might do + rmb STACKSZ+PARMSZ +size equ . + +* The utility name and edition goes here +name fcs /NGU/ + fcb edition + +* Place constant strings here + IFNE DOHELP +HlpMsg fcb C$LF + fcc /Use: NGU [] [] []/ + fcb C$LF + fcc / -a option 1/ + fcb C$LF + fcc / -b option 2/ + fcb C$LF + fcc / -c=f option 3/ + fcb C$LF +CR fcb C$CR +HlpMsgL equ *-HlpMsg + ENDC +UnkOpt fcc /unknown option: / +UnkOptL equ *-UnkOpt + +* Here's how registers are set when this process is forked: +* +* +-----------------+ <-- Y (highest address) +* ! Parameter ! +* ! Area ! +* +-----------------+ <-- X, SP +* ! Data Area ! +* +-----------------+ +* ! Direct Page ! +* +-----------------+ <-- U, DP (lowest address) +* +* D = parameter area size +* PC = module entry point abs. address +* CC = F=0, I=0, others undefined + +* The start of the program is here. +* Before any command line processing is done, we clear out +* our static memory from U to cleartop, then determine the +* size of our data area (minus the stack). +start pshs u,x save registers for later + leax HlpMsg,pcr point to help message + ldy #HlpMsgL get length + lda #$02 std error + os9 I$WritLn write it + ENDC +ExitOk clrb clear carry +Exit os9 F$Exit and exit + +* This routine counts the number of non-whitespace characters +* starting at X +* +* Entry: +* X = ptr to string (space, nul byte or CR terminated) +* Exit: +* Y = length of string +* X = ptr to byte after string +StrLen pshs a + ldy #$0000 +StrLenLp lda ,x+ + beq StrLenEx + cmpa #C$SPAC + beq StrLenEx + cmpa #C$CR + beq StrLenEx + leay 1,y + bra StrLenLp +StrLenEx puls a,pc + +* This routine copies a string of text from X to Y until +* a whitespace character or CR is encountered +* +* Entry: +* X = ptr to src string +* Y = ptr to dest string +* Exit: +* D = number of bytes copied +* X = ptr to byte after original string +* Y = ptr to byte after copied string +StrCpy pshs u + ldu #$0000 +CopyFnLp lda ,x+ + beq CopyFnEx + cmpa #C$SPAC + beq CopyFnEx + cmpa #C$CR + beq CopyFnEx + sta ,y+ + leau 1,u + bra CopyFnLp +CopyFnEx tfr u,d + puls u,pc + +* This routine skip over spaces and nul bytes +* +* Entry: +* X = ptr to data to parse +* Exit: +* X = ptr to first non-whitespace char +* A = non-whitespace char +SkipSpcs lda ,x+ + beq SkipSpcs + cmpa #C$SPAC + beq SkipSpcs + leax -1,x + rts + +* This routine skips over everything but spaces, nul bytes and CRs +* +* Entry: +* X = ptr to data to parse +* Exit: +* X = ptr to first whitespace char +* A = whitespace char +SkipNSpc lda ,x+ + beq EatOut + cmpa #C$SPAC + beq EatOut + cmpa #C$CR + bne SkipNSpc +EatOut leax -1,x + rts + + emod +eom equ * + end diff -r a9311007b1b2 -r 83bf26264aa6 3rdparty/packages/brainfuck/bf.asm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/3rdparty/packages/brainfuck/bf.asm Sat Oct 03 14:50:37 2015 -0500 @@ -0,0 +1,177 @@ +******************************************************************** +* bf - Brainfuck Language Interpreter +* +* $Id$ +* +* This is a simple interpreter for the Brainfuck language: +* https://en.wikipedia.org/wiki/Brainfuck +* +* Edt/Rev YYYY/MM/DD Modified by +* Comment +* ------------------------------------------------------------------ +* 1 2015/10/02 Boisy G. Pitre +* Created. +* + + ifp1 + use defsfile + endc + +tylg set Prgrm+Objct +atrv set ReEnt+rev +rev set $00 +edition set 1 + + mod eom,name,tylg,atrv,start,size + +pSize equ 12000 +dSize equ 3000 + + org 0 +pmem rmb pSize +dmem rmb dSize +stack rmb 200 +size equ . + +name fcs /bfp/ + fcb edition + +* initialize interpreter +* clear program memory +start + lda #READ. + os9 I$Open + lbcs error + ldy #pSize + leax pmem,u + os9 I$Read + lbcs error + os9 I$Close + tfr y,d nul terminate program string in memory + clr d,x + + leay dmem,u + ldd #dSize +clrloop clr ,y+ + subd #$0001 + bne clrloop + leay dmem,u + bra parse + +ptrInc + leay 1,y + bra parse + +ptrDec + leay -1,y + bra parse + +dataInc + inc ,y + bra parse + +dataDec + dec ,y + bra parse + +putChar + pshs d,x,y + lda #1 + tfr y,x + ldy #1 + os9 I$Write + puls d,x,y,pc + +getChar + pshs d,x,y + clra + tfr y,x + ldy #1 + os9 I$Read + puls d,x,y,pc + + +brOpen lda #1 + pshs a + tst ,y + bne brOpenBye +brOpenDo + lda ,x+ + cmpa #'[ + bne brOpenCkClose + inc ,s + bra brOpenDoTest +brOpenCkClose + cmpa #'] + bne brOpenDoTest + dec ,s +brOpenDoTest + tst ,s + bne brOpenDo +brOpenBye + puls a,pc + +brClose + clr ,-s +brCloseDo + lda ,-x + cmpa #'[ + bne brCloseCkClose + inc ,s + bra brCloseDoCont +brCloseCkClose + cmpa #'] + bne brCloseDoCont + dec ,s +brCloseDoCont + tst ,s + bne brCloseDo + puls a,pc + +* X = Brainfuck program pointer (nul byte terminates) +* Y = Brainfuck data pointer +parse + lda ,x+ + beq parseEnd + cmpa #'> + bne a1 + leay 1,y + bra parse +a1 cmpa #'< + bne a2 + leay -1,y + bra parse +a2 cmpa #'+ + bne a3 + inc ,y + bra parse +a3 cmpa #'- + bne a4 + dec ,y + bra parse +a4 cmpa #'. + bne a5 + bsr putChar + bra parse +a5 cmpa #', + bne a6 + bsr getChar + bra parse +a6 cmpa #'[ + bne a7 + bsr brOpen + bra parse +a7 cmpa #'] + bne parse unrecognized character -- keep parsing + bsr brClose + bra parse + + +parseEnd + clrb +error + os9 F$Exit + + EMOD +eom EQU * + END diff -r a9311007b1b2 -r 83bf26264aa6 3rdparty/packages/brainfuck/defsfile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/3rdparty/packages/brainfuck/defsfile Sat Oct 03 14:50:37 2015 -0500 @@ -0,0 +1,2 @@ + use os9.d + use scf.d diff -r a9311007b1b2 -r 83bf26264aa6 3rdparty/packages/brainfuck/donothing.bf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/3rdparty/packages/brainfuck/donothing.bf Sat Oct 03 14:50:37 2015 -0500 @@ -0,0 +1,2 @@ +[ This program does nothing. ] +[,.] diff -r a9311007b1b2 -r 83bf26264aa6 3rdparty/packages/brainfuck/helloworld.bf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/3rdparty/packages/brainfuck/helloworld.bf Sat Oct 03 14:50:37 2015 -0500 @@ -0,0 +1,44 @@ +[ This program prints "Hello World!" and a newline to the screen, its + length is 106 active command characters. [It is not the shortest.] + + This loop is a "comment loop", a simple way of adding a comment + to a BF program such that you don't have to worry about any command + characters. Any ".", ",", "+", "-", "<" and ">" characters are simply + ignored, the "[" and "]" characters just have to be balanced. This + loop and the commands it contains are ignored because the current cell + defaults to a value of 0; the 0 value causes this loop to be skipped. +] ++++++ +++ Set Cell #0 to 8 +[ + >++++ Add 4 to Cell #1; this will always set Cell #1 to 4 + [ as the cell will be cleared by the loop + >++ Add 2 to Cell #2 + >+++ Add 3 to Cell #3 + >+++ Add 3 to Cell #4 + >+ Add 1 to Cell #5 + <<<<- Decrement the loop counter in Cell #1 + ] Loop till Cell #1 is zero; number of iterations is 4 + >+ Add 1 to Cell #2 + >+ Add 1 to Cell #3 + >- Subtract 1 from Cell #4 + >>+ Add 1 to Cell #6 + [<] Move back to the first zero cell you find; this will + be Cell #1 which was cleared by the previous loop + <- Decrement the loop Counter in Cell #0 +] Loop till Cell #0 is zero; number of iterations is 8 + +The result of this is: +Cell No : 0 1 2 3 4 5 6 +Contents: 0 0 72 104 88 32 8 +Pointer : ^ + +>>. Cell #2 has value 72 which is 'H' +>---. Subtract 3 from Cell #3 to get 101 which is 'e' ++++++++..+++. Likewise for 'llo' from Cell #3 +>>. Cell #5 is 32 for the space +<-. Subtract 1 from Cell #4 for 87 to give a 'W' +<. Cell #3 was set to 'o' from the end of 'Hello' ++++.------.--------. Cell #3 for 'rl' and 'd' +>>+. Add 1 to Cell #5 gives us an exclamation point +>++. And finally a newline from Cell #6 + diff -r a9311007b1b2 -r 83bf26264aa6 3rdparty/packages/brainfuck/inout.bf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/3rdparty/packages/brainfuck/inout.bf Sat Oct 03 14:50:37 2015 -0500 @@ -0,0 +1,2 @@ +[ This program takes one byte of input and immediately outputs it. ] +,. diff -r a9311007b1b2 -r 83bf26264aa6 3rdparty/packages/brainfuck/makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/3rdparty/packages/brainfuck/makefile Sat Oct 03 14:50:37 2015 -0500 @@ -0,0 +1,50 @@ +include $(NITROS9DIR)/rules.mak + +DSK = brainfuck.dsk + +# NitrOS-9 +H6309 = $(AFLAGS) -DH6309=1 +# Non-NitrOS-9 +M6809 = $(AFLAGS) + +DEPENDS = ./makefile + +TEXTFILES = ReadMe inout.bf helloworld.bf donothing.bf +OBJS = bf +ALLOBJS = $(OBJS) + +all: banner $(ALLOBJS) $(DEPENDS) + +banner: + @$(ECHO) "**************************************************" + @$(ECHO) "* *" + @$(ECHO) "* Brainfuck *" + @$(ECHO) "* *" + @$(ECHO) "**************************************************" + +bf: bf.asm + $(AS) $(ASOUT)$@ $< $(H6309) + +clean: dskclean + $(RM) $(ALLOBJS) + +dsk: $(DSK) + +$(DSK): all + $(RM) $@ + $(OS9FORMAT_SS35) $@ -n"brainfuck" + $(MAKDIR) $@,CMDS + $(OS9COPY) $(ALLOBJS) $@,CMDS + $(OS9ATTR_EXEC) $(foreach file,$(ALLOBJS),$@,CMDS/$(file)) + $(CPL) $(TEXTFILES) $@,. + $(OS9ATTR_TEXT) $(foreach file,$(TEXTFILES),$@,$(file)) + +dskcopy: $(DSK) + $(CP) $(DSK) $(DSKDIR) + +dskclean: + $(RM) $(DSK) + +info: + @$(ECHO) "*** brainfuck ***" + @$(ECHO) $(DSK) diff -r a9311007b1b2 -r 83bf26264aa6 3rdparty/packages/makefile --- a/3rdparty/packages/makefile Sun Jul 26 10:39:02 2015 +0200 +++ b/3rdparty/packages/makefile Sat Oct 03 14:50:37 2015 -0500 @@ -1,6 +1,6 @@ include $(NITROS9DIR)/rules.mak -dirs = arcadepak basic09 deskmate3 cc fsim2 koronis kyumgai mm multivue os9l2bbs pacos9 raakatu rof sierra subsim uucpbb +dirs = arcadepak basic09 brainfuck deskmate3 cc fsim2 koronis kyumgai mm multivue os9l2bbs pacos9 raakatu rof sierra subsim uucpbb # Make all components all: