[gforth] / gforth / fi2c.fs  

gforth: gforth/fi2c.fs


1 : pazsan 1.1 \ Convert image to C include file
2 :    
3 : anton 1.2 \ Copyright (C) 1998 Free Software Foundation, Inc.
4 :    
5 :     \ This file is part of Gforth.
6 :    
7 :     \ Gforth is free software; you can redistribute it and/or
8 :     \ modify it under the terms of the GNU General Public License
9 :     \ as published by the Free Software Foundation; either version 2
10 :     \ of the License, or (at your option) any later version.
11 :    
12 :     \ This program is distributed in the hope that it will be useful,
13 :     \ but WITHOUT ANY WARRANTY; without even the implied warranty of
14 :     \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 :     \ GNU General Public License for more details.
16 :    
17 :     \ You should have received a copy of the GNU General Public License
18 :     \ along with this program; if not, write to the Free Software
19 :     \ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 :    
21 : pazsan 1.1 0 Value image
22 :     0 Value bitmap
23 :    
24 :     Create magicbuf 8 allot
25 :    
26 :     : search-magic ( fd -- ) >r
27 :     BEGIN magicbuf 8 r@ read-file throw 8 = WHILE
28 :     magicbuf s" Gforth1" tuck compare 0= UNTIL
29 :     ELSE true abort" No magic found" THEN
30 :     rdrop ;
31 :    
32 :     Create image-header 4 cells allot
33 :     Variable image-cells
34 :     Variable bitmap-chars
35 :    
36 :     : read-header ( fd -- )
37 :     image-header 4 cells rot read-file throw drop
38 :     image-header 2 cells + @ dup cell / image-cells ! 1- 8 cells / 1+ bitmap-chars !
39 :     image-cells @ cells allocate throw to image
40 :     bitmap-chars @ allocate throw to bitmap ;
41 :    
42 :     : read-dictionary ( fd -- ) >r
43 :     image image-cells @ cells r> read-file throw drop ;
44 :    
45 :     : read-bitmap ( fd -- ) >r
46 :     bitmap bitmap-chars @ r> read-file throw drop ;
47 :    
48 :     : .08x ( n -- ) 0 <# # # # # # # # # 'x hold '0 hold #> type ;
49 :     : .02x ( n -- ) 0 <# # # 'x hold '0 hold #> type ;
50 :    
51 :     : .image ( -- )
52 :     image-cells @ 0 ?DO
53 :     I 4 + I' min I ?DO space image I cells + @ .08x ." ," LOOP cr
54 :     4 +LOOP ;
55 :    
56 :     : .reloc ( -- )
57 :     bitmap-chars @ 0 ?DO
58 :     I 8 + I' min I ?DO space bitmap I + c@ .02x ." ," LOOP cr
59 :     8 +LOOP ;
60 :    
61 :     : read-image ( addr u -- )
62 :     r/o bin open-file throw >r
63 :     r@ search-magic
64 :     r@ file-position throw r@ read-header r@ reposition-file throw
65 :     r@ read-dictionary r@ read-bitmap r> close-file throw ;
66 :    
67 :     : .imagesize ( -- )
68 :     image-header 3 cells + @ 1 cells / .08x ;
69 :    
70 :     : .relocsize ( -- )
71 :     bitmap-chars @ .08x ;
72 :    
73 :     : fi2c ( addr u -- ) base @ >r hex
74 :     read-image
75 :     ." #include " '" emit ." forth.h" '" emit cr
76 :     ." Cell image[" .imagesize ." ] = {" cr .image ." };" cr
77 :     ." const char reloc_bits[" .relocsize ." ] = {" cr .reloc ." };" cr
78 :     r> base ! ;
79 :    

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help