-
Notifications
You must be signed in to change notification settings - Fork 2
/
IIgs Resource Fork.tcl
174 lines (139 loc) · 3 KB
/
IIgs Resource Fork.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# Apple IIgs Toolbox Reference Volume 3, 45-14
little_endian
# these keys are strings not ints.
set rTypes [dict create \
0x8001 rIcon \
0x8002 rPicture \
0x8003 rControlList \
0x8004 rControlTemplate \
0x8005 rC1InputString \
0x8006 rPString \
0x8007 rStringList \
0x8008 rMenuBar \
0x8009 rMenu \
0x800A rMenuItem \
0x800B rTextForLETextBox2 \
0x800C rCtlDefProc \
0x800D rCtlColorTbl \
0x800E rWindParam1 \
0x800F rWindParam2 \
0x8010 rWindColor \
0x8011 rTextBlock \
0x8012 rStyleBlock \
0x8013 rToolStartup \
0x8014 rResName \
0x8015 rAlertString \
0x8016 rText \
0x8017 rCodeResource \
0x8018 rCDEVCode \
0x8019 rCDEVFlags \
0x801A rTwoRects \
0x801B rFileType \
0x801C rListRef \
0x801D rCString \
0x801E rXCMD \
0x801F rXFCN \
0x8020 rErrorString \
0x8021 rKTransTable \
0x8022 rWString \
0x8023 rC1OutputString \
0x8024 rSoundSample \
0x8025 rTERuler \
0x8026 rFSequence \
0x8027 rCursor \
0x8028 rItemStruct \
0x8029 rVersion \
0x802A rComment \
0x802B rBundle \
0x802C rFinderPath \
0x802D rPaletteWindow \
0x802E rTaggedStrings \
0x802F rPatternList \
0xC001 rRectList \
0xC002 rPrintRecord \
0xC003 rFont
]
proc fmt_type {x} {
global rTypes
set x [format "0x%04X" $x]
if {[dict exists $rTypes $x]} { return [dict get $rTypes $x]}
return $x
}
proc fmt_id {x} {
return [format "0x%08X" $x]
}
proc rname { type id} {
return [format "\$%04x - \$%08x" $type $id]
}
# Res Header Rec
section "Header" {
uint32 -hex "Version"
set to_map [uint32 -hex "To Map"]
set map_size [uint32 "Map Size"]
bytes 128 "Memo"
}
goto $to_map
section "Resource Map" {
set p [pos]
uint32 -hex "Next"
uint16 -hex "Flag"
uint32 "Offset"
uint32 "Size"
set to_index [uint16 "To Index"]
uint16 "File Num"
uint16 "ID"
set index_size [uint32 "Index Size"]
set index_used [uint32 "Index Used"]
set free_size [uint16 "Free List Size"]
set free_used [uint16 "Free List Used"]
}
section "Free List" {
# map free list ...
for {set i 0 } { $i < $free_used} {incr i} {
section "" {
uint32 -hex "Offset"
uint32 "Size"
}
}
# bytes [expr $free_size * 8] "Free List"
set tmp [expr $free_size - $free_used]
if {$tmp} { bytes [expr $tmp * 8] "Spare" }
}
goto [expr $p + $to_index]
set ResMap {}
section "Index List" {
for {set i 0 } { $i < $index_used} {incr i} {
set type [uint16]
set id [uint32]
move -6
set rType [fmt_type $type]
set rID [fmt_id $id]
section $rType {
sectionvalue $rID
uint16 -hex "Type"
uint32 -hex "ID"
set offset [uint32 -hex "Offset"]
uint16 -hex "Attr"
set size [uint32 "Size"]
uint32 -hex "Handle"
if {$size} {
lappend ResMap [list $rType $rID $offset $size]
}
}
}
# unused
set tmp [expr $index_size - $index_used]
if {$tmp} { bytes [expr $tmp * 0x14] "Spare" }
}
set ResMap [lsort -integer -index 2 $ResMap]
foreach r $ResMap {
set rType [lindex $r 0]
set rID [lindex $r 1]
set offset [lindex $r 2]
set size [lindex $r 3]
goto $offset
section $rType {
sectionvalue $rID
bytes $size "Data"
}
}