-
Notifications
You must be signed in to change notification settings - Fork 2
/
cc65 Library file.tcl
84 lines (64 loc) · 1.34 KB
/
cc65 Library file.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
# https://github.com/cc65/cc65
requires 0 "6E 61 55 7a"
little_endian
proc read_var { {name ""} } {
set rv 0
set shift 0
set p1 [pos]
while 1 {
set x [uint8]
set rv [expr $rv | (($x & 0x7f) << $shift) ]
if {! ($x & 0x80) } break;
set shift [expr $shift + 7]
}
set p2 [pos]
if { [expr { $name ne "" }] } {
entry $name $rv [expr $p2-$p1] $p1
}
return $rv
}
proc read_string { {name ""} } {
set p1 [pos]
set len [read_var]
# if expr returns empty string if no matching case
set str [if { $len > 0 } { ascii $len }]
set p2 [pos]
if { [expr { $name ne "" }] } {
entry $name $str [expr $p2-$p1] $p1
}
return $str
}
section "Header" {
uint32 -hex Magic
uint16 -hex Version
uint16 -hex Flags
set index_offset [uint32 "Index Offfset"]
}
set Entries {}
goto $index_offset
section "Index" {
set count [read_var "Count"]
for {set i 0} {$i < $count} {incr i} {
section -collapsed "" {
set name [read_string "Name"]
sectionname $name
uint16 -hex Flags
unixtime32 MTime
set offset [uint32 Offset]
set size [uint32 Size]
if {$size} {
lappend Entries [list $name $offset $size]
}
}
}
}
set Entries [lsort -integer -index 1 $Entries]
foreach e $Entries {
set name [lindex $e 0]
set offset [lindex $e 1]
set size [lindex $e 2]
goto $offset
section -collapsed $name {
bytes $size "Data"
}
}