diff --git a/.gitignore b/.gitignore index 748240b..e1a4c55 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.asm *.o *.seed +/preForth/crc10.forth /preForth/preForth /preForth/seedForth /preForth/__temp__.fs diff --git a/preForth/Makefile b/preForth/Makefile index 71579c2..6cff6b4 100644 --- a/preForth/Makefile +++ b/preForth/Makefile @@ -124,12 +124,13 @@ seedForth.pre \ # a little ugly, because gforth insists upon echoing anything read from # stdin, and also does not allow parsing words to cross a file boundary, # so we will concatenate the tokenizer and source into a *.fs file first -seedForthDemo.seed: seedForth-tokenizer.fs seedForthDemo.seedsource +seedForthDemo.seed: crc10.forth seedForth-tokenizer.fs seedForthDemo.seedsource cat $^ >__temp__.fs gforth __temp__.fs -e bye >$@ rm __temp__.fs seedForthBoot.seed: \ +crc10.forth \ seedForth-tokenizer.fs \ seedForthRuntime.seedsource \ seedForthBoot.seedsource @@ -138,6 +139,7 @@ seedForthBoot.seedsource rm __temp__.fs seedForthInteractive.seed: \ +crc10.forth \ seedForth-tokenizer.fs \ seedForthRuntime.seedsource \ seedForthInteractive.seedsource @@ -145,6 +147,9 @@ seedForthInteractive.seedsource gforth __temp__.fs -e bye >$@ rm __temp__.fs +crc10.forth: crc10_gen.forth + gforth $^ -e bye >$@ + .PHONY=clean clean: rm -f *.asm *.o *.seed preForthdemo preForth seedForth __temp__.fs diff --git a/preForth/crc10_gen.forth b/preForth/crc10_gen.forth new file mode 100644 index 0000000..11b94eb --- /dev/null +++ b/preForth/crc10_gen.forth @@ -0,0 +1,50 @@ +\ run this as follows: +\ ./seedForth seedForthBoot.seed runtime.forth crc10_gen.forth >crc10.forth + +817 Constant poly \ CRC-10/ATM, truncated polynomial 0x233, bit reversed 0x331 + +\ we don't want MS-DOS style line endings in the generated CRC table file +: lf 10 emit ; + +: gen + ." Create crc10_tab" lf + 256 0 ?DO + I 8 0 ?DO + \ split into LSB and the remaining bits + \ in seedForth: 2 u/mod swap + \ in gForth: 2 /mod swap + dup 1 rshift swap 1 and + + IF poly xor THEN + LOOP + . ',' emit + I 7 and 7 = IF lf ELSE space THEN + LOOP + lf + ." : crc10 ( addr len crc -- crc )" lf + ." swap 0 ?DO ( addr crc )" lf + ." \ retrieve next character" lf + ." over I + c@" lf + lf + ." \ xor into low bits of crc" lf + ." xor" lf + lf + ." \ separate into table index and remaining bits" lf + ." \ 256 u/mod swap" lf + ." dup 8 rshift swap 255 and" lf + lf + ." \ look up new bits from table" lf + ." cells crc10_tab + @" lf + lf + ." \ combine with remaining (shifted right) bits" lf + ." xor" lf + ." LOOP" lf + ." nip" lf + ." ;" lf + lf + ." \ testing:" lf + ." \ Create hello 104 c, 101 c, 108 c, 108 c, 111 c," lf + ." \ hello 5 1023 crc10 . ;" lf +; + +gen diff --git a/preForth/seedForth-tokenizer b/preForth/seedForth-tokenizer index 75d6736..420ff59 100755 --- a/preForth/seedForth-tokenizer +++ b/preForth/seedForth-tokenizer @@ -1,2 +1,2 @@ #!/bin/sh -./seedForth seedForthBoot.seed runtime.forth seedForth-tokenizer.fs - +./seedForth seedForthBoot.seed runtime.forth crc10.forth seedForth-tokenizer.fs -