summaryrefslogtreecommitdiff
path: root/src/lpc/figure-checksum
diff options
context:
space:
mode:
authorBdale Garbee <bdale@gag.com>2013-12-19 01:38:40 -0700
committerBdale Garbee <bdale@gag.com>2013-12-19 01:38:40 -0700
commit575bbaf976c5840fd0e308549c45a466fdec1352 (patch)
tree11bfb498348bf7687bffc24699c4b1a998988ee4 /src/lpc/figure-checksum
parentb825116df173b77e2cab217a7b76112c742f9279 (diff)
parentbc3610d8cecbfed40c62d4dcb93fc9a4d2a7c9e3 (diff)
Merge branch 'branch-1.3' into debian
Conflicts: ChangeLog altoslib/AltosRecordMM.java altosui/Makefile.am altosui/altos-windows.nsi.in configure.ac debian/changelog debian/control doc/Makefile doc/altusmetrum.xsl doc/release-notes-1.2.1.xsl doc/release-notes-1.2.xsl
Diffstat (limited to 'src/lpc/figure-checksum')
-rwxr-xr-xsrc/lpc/figure-checksum39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/lpc/figure-checksum b/src/lpc/figure-checksum
new file mode 100755
index 00000000..0b1de578
--- /dev/null
+++ b/src/lpc/figure-checksum
@@ -0,0 +1,39 @@
+#!/usr/bin/env nickle
+
+autoimport Process;
+
+int byteflip(int x) {
+ return ((x >> 24) & 0xff) | ((x >> 8) & 0xff00) | ((x << 8) & 0xff0000) | ((x << 24) & 0xff000000);
+}
+
+void main () {
+ file input = popen(popen_direction.read, true, "objdump",
+ "objdump", "-j", ".text",
+ "--start-address=0",
+ "--stop-address=0x20",
+ "-s", argv[1]);
+ int sum = 0;
+
+ void add_in(int addr, int value) {
+ if (addr < 0x1c) {
+ sum += value;
+ } else if (addr == 0x1c) {
+ printf ("-DCKSUM=0x%08x\n", -sum & 0xffffffff);
+ exit(0);
+ }
+ }
+ while (!File::end(input)) {
+ string line = File::fgets(input);
+ string[] words = String::wordsplit(line, " ");
+
+ if (dim(words) < 5)
+ continue;
+ if (words[0] == "0000" || words[0] == "0010") {
+ int addr = string_to_integer(words[0], 16);
+ for (int i = 0; i < 4; i++)
+ add_in(addr + i * 4, byteflip(string_to_integer(words[i+1], 16)));
+ }
+ }
+}
+
+main();