1 \ *****************************************************************************
2 \ * Copyright (c) 2004, 2008 IBM Corporation
3 \ * All rights reserved.
4 \ * This program and the accompanying materials
5 \ * are made available under the terms of the BSD License
6 \ * which accompanies this distribution, and is available at
7 \ * http://www.opensource.org/licenses/bsd-license.php
10 \ * IBM Corporation - initial implementation
11 \ ****************************************************************************/
14 \ package which adds support to read the romfs
15 \ this package is somehow limited as the maximum supported length
16 \ for a file name is hardcoded to 0x100
18 s" rom-files" device-name
20 INSTANCE VARIABLE length
21 INSTANCE VARIABLE next-file
22 INSTANCE VARIABLE buffer
23 INSTANCE VARIABLE buffer-size
24 INSTANCE VARIABLE file
25 INSTANCE VARIABLE file-size
26 INSTANCE VARIABLE found
29 100 dup buffer-size ! alloc-mem buffer ! false found ! ;
30 : close buffer @ buffer-size @ free-mem ;
32 : read ( addr len -- actual ) s" read" $call-parent ;
34 : seek ( lo hi -- status ) s" seek" $call-parent ;
36 : .read-file-name ( offset -- str len )
37 \ move to the file name offset
39 \ read <buffer-size> bytes from that address
40 buffer @ buffer-size @ read drop
41 \ write a 0 to make sure it is a 0 terminated string
42 buffer-size @ 1 - buffer @ + 0 swap c!
45 : .print-info ( offset -- )
46 dup 2 spaces 6 0.r 2 spaces dup
47 8 + 0 seek drop length 8 read drop
48 6 length @ swap 0.r 2 spaces
49 20 + .read-file-name type cr ;
52 s" --offset---size-----file-name----" type cr ;
57 .print-info dup 0 seek drop
58 next-file 8 read drop next-file @
61 : (find-file) ( name len -- offset | -1 )
62 0 0 seek drop false found !
63 file-size ! file ! 0 0 BEGIN + dup
64 20 + .read-file-name file @ file-size @
65 str= IF true found ! THEN
67 next-file 8 read drop next-file @
68 dup 0= found @ or UNTIL drop found @ 0=
71 : load ( addr -- size )
72 my-parent instance>args 2@ [char] \ left-parse-string 2drop
73 (find-file) dup -1 = IF 2drop 0 ELSE
74 \ got to the beginning
78 here 8 read drop here @ ( dest-addr offset file-size )
79 \ read data start offset
81 here 8 read drop here @ ( dest-addr offset file-size data-offset )
82 rot + 0 seek drop ( dest-addr file-size )