Skip to content

Commit

Permalink
Add CRC10/ATM (bit reversed) table generator and evaluator
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-lifx committed Apr 24, 2022
1 parent 7115f49 commit 03f5872
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.asm
*.o
*.seed
/preForth/crc10.forth
/preForth/preForth
/preForth/seedForth
/preForth/__temp__.fs
7 changes: 6 additions & 1 deletion preForth/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -138,13 +139,17 @@ seedForthBoot.seedsource
rm __temp__.fs

seedForthInteractive.seed: \
crc10.forth \
seedForth-tokenizer.fs \
seedForthRuntime.seedsource \
seedForthInteractive.seedsource
cat $^ >__temp__.fs
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
50 changes: 50 additions & 0 deletions preForth/crc10_gen.forth
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion preForth/seedForth-tokenizer
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/sh
./seedForth seedForthBoot.seed runtime.forth seedForth-tokenizer.fs -
./seedForth seedForthBoot.seed runtime.forth crc10.forth seedForth-tokenizer.fs -

0 comments on commit 03f5872

Please sign in to comment.