\ @(#) savedicd.fth 98/01/26 1.2
\ Save dictionary as data table.
\ Copyright 1987 Phil Burk
\ 970311 PLB Fixed problem with calling SDAD when in HEX mode.
\ 20010606 PLB Fixed AUTO.INIT , started with ';' !!
ANEW TASK-SAVE_DIC_AS_DATA
\ !!! set to 4 for minimally sized dictionary to prevent DIAB
\ compiler from crashing! Allocate more space in pForth.
4 constant SDAD_NAMES_EXTRA \ space for additional names
4 constant SDAD_CODE_EXTRA \ space for additional names
\ buffer the file I/O for better performance
256 constant SDAD_BUFFER_SIZE
create SDAD-BUFFER SDAD_BUFFER_SIZE allot
variable SDAD-BUFFER-INDEX
sdad-buffer sdad-buffer-index @ \ data
sdad-buffer-fid @ write-file
sdad-buffer-index @ sdad_buffer_size >=
sdad.flush abort" SDAD.FLUSH failed!"
sdad-buffer sdad-buffer-index @ + c!
: SDAD.TYPE ( c-addr cnt -- )
dup c@ sdad.emit \ char to buffer
1+ \ advance char pointer
: $SDAD.LINE ( $addr -- )
: (U8.) ( u -- a l , unsigned conversion, at least 8 digits )
: (U2.) ( u -- a l , unsigned conversion, at least 2 digits )
sdad.flush abort" SDAD.FLUSH failed!"
: SDAD.OPEN ( -- ior, open file )
s" pfdicdat.h" r/w create-file dup >r
drop ." Could not create file pfdicdat.h" cr
: SDAD.DUMP.HEX { val -- }
: SDAD.DUMP.HEX.BYTE { val -- }
: SDAD.DUMP.DATA { start-address end-address num-zeros | num-bytes -- }
end-address start-address - -> num-bytes
i $ 7FF and 0= IF ." 0x" i .hex cr THEN \ progress report
THEN \ 16 bytes per line, print offset
i $ 7FF and 0= IF i . cr THEN \ progress report
i 15 and 0= IF EOL sdad.emit THEN \ 15 numbers per line
: SDAD.DEFINE { $name val -- }
: IS.LITTLE.ENDIAN? ( -- flag , is Forth in Little Endian mode? )
sdad.open abort" sdad.open failed!"
c" /* This file generated by the Forth command SDAD */" $sdad.line
c" HEADERPTR" headers-ptr @ namebase - sdad.define
c" RELCONTEXT" context @ namebase - sdad.define
c" CODEPTR" here codebase - sdad.define
c" IF_LITTLE_ENDIAN" IS.LITTLE.ENDIAN? IF 1 ELSE 0 THEN sdad.define
s" static const uint8_t MinDicNames[] = {" sdad.type
namebase headers-ptr @ SDAD_NAMES_EXTRA sdad.dump.data
s" static const uint8_t MinDicCode[] = {" sdad.type
codebase here SDAD_CODE_EXTRA sdad.dump.data
: AUTO.INIT ( -- , init at launch )
auto.init \ daisy chain initialization