1 \ @(#) savedicd.fth 98/01/26 1.2
2 \ Save dictionary as data table.
5 \ Copyright 1987 Phil Burk
8 \ 970311 PLB Fixed problem with calling SDAD when in HEX mode.
9 \ 20010606 PLB Fixed AUTO.INIT , started with ';' !!
12 ANEW TASK-SAVE_DIC_AS_DATA
14 \ !!! set to 4 for minimally sized dictionary to prevent DIAB
15 \ compiler from crashing! Allocate more space in pForth.
16 4 constant SDAD_NAMES_EXTRA \ space for additional names
17 4 constant SDAD_CODE_EXTRA \ space for additional names
19 \ buffer the file I/O for better performance
20 256 constant SDAD_BUFFER_SIZE
21 create SDAD-BUFFER SDAD_BUFFER_SIZE allot
22 variable SDAD-BUFFER-INDEX
23 variable SDAD-BUFFER-FID
26 : SDAD.FLUSH ( -- ior )
27 sdad-buffer sdad-buffer-index @ \ data
29 sdad-buffer-fid @ write-file
33 : SDAD.EMIT ( char -- )
34 sdad-buffer-index @ sdad_buffer_size >=
36 sdad.flush abort" SDAD.FLUSH failed!"
39 sdad-buffer sdad-buffer-index @ + c!
40 1 sdad-buffer-index +!
43 : SDAD.TYPE ( c-addr cnt -- )
45 dup c@ sdad.emit \ char to buffer
46 1+ \ advance char pointer
51 : $SDAD.LINE ( $addr -- )
56 : (U8.) ( u -- a l , unsigned conversion, at least 8 digits )
57 0 <# # # # # # # # #S #>
59 : (U2.) ( u -- a l , unsigned conversion, at least 2 digits )
64 SDAD-BUFFER-FID @ ?dup
66 sdad.flush abort" SDAD.FLUSH failed!"
72 : SDAD.OPEN ( -- ior, open file )
74 s" pfdicdat.h" r/w create-file dup >r
76 drop ." Could not create file pfdicdat.h" cr
83 : SDAD.DUMP.HEX { val -- }
95 : SDAD.DUMP.HEX.BYTE { val -- }
101 : SDAD.DUMP.HEX.BYTE,
106 : SDAD.DUMP.DATA { start-address end-address num-zeros | num-bytes -- }
107 end-address start-address - -> num-bytes
110 i $ 7FF and 0= IF ." 0x" i .hex cr THEN \ progress report
118 THEN \ 16 bytes per line, print offset
125 i $ 7FF and 0= IF i . cr THEN \ progress report
126 i 15 and 0= IF EOL sdad.emit THEN \ 15 numbers per line
127 0 sdad.dump.hex.byte,
131 : SDAD.DEFINE { $name val -- }
132 s" #define " sdad.type
133 $name count sdad.type
139 : IS.LITTLE.ENDIAN? ( -- flag , is Forth in Little Endian mode? )
145 sdad.open abort" sdad.open failed!"
147 c" /* This file generated by the Forth command SDAD */" $sdad.line
149 c" HEADERPTR" headers-ptr @ namebase - sdad.define
150 c" RELCONTEXT" context @ namebase - sdad.define
151 c" CODEPTR" here codebase - sdad.define
152 c" IF_LITTLE_ENDIAN" IS.LITTLE.ENDIAN? IF 1 ELSE 0 THEN sdad.define
155 s" static const uint8_t MinDicNames[] = {" sdad.type
156 namebase headers-ptr @ SDAD_NAMES_EXTRA sdad.dump.data
161 s" static const uint8_t MinDicCode[] = {" sdad.type
162 codebase here SDAD_CODE_EXTRA sdad.dump.data
169 if.forgotten sdad.close
171 : AUTO.INIT ( -- , init at launch )
172 auto.init \ daisy chain initialization
174 0 SDAD-BUFFER-INDEX !