X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altoslib%2FAltosRomconfig.java;h=ccd01274427b9520bb4622a532cf2db4b5523deb;hp=46ee2b6e66bc225ce8deddd488d5a3eb34a4852b;hb=3c48b0fd504ae97dfaca91d2064b5822ca6e1344;hpb=a61217f0a6d0ef48b6471f632c4600255867e831 diff --git a/altoslib/AltosRomconfig.java b/altoslib/AltosRomconfig.java index 46ee2b6e..ccd01274 100644 --- a/altoslib/AltosRomconfig.java +++ b/altoslib/AltosRomconfig.java @@ -16,7 +16,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_12; +package org.altusmetrum.altoslib_13; import java.io.*; @@ -26,20 +26,27 @@ public class AltosRomconfig { public int check; public int serial_number; public int radio_calibration; + public AltosUsbId usb_id; + public String usb_product; - static private int find_offset(AltosHexfile hexfile, String name, int len) throws AltosNoSymbol { + static private long find_address(AltosHexfile hexfile, String name, int len) throws AltosNoSymbol { AltosHexsym symbol = hexfile.lookup_symbol(name); - if (symbol == null) - throw new AltosNoSymbol(name); - int offset = (int) symbol.address - hexfile.address; - if (offset < 0 || hexfile.data.length < offset + len) + if (symbol == null) { throw new AltosNoSymbol(name); - return offset; + } + if (hexfile.address <= symbol.address && symbol.address + len <= hexfile.max_address) { + return symbol.address; + } + throw new AltosNoSymbol(name); + } + + static private int find_offset(AltosHexfile hexfile, String name, int len) throws AltosNoSymbol { + return (int) (find_address(hexfile, name, len) - hexfile.address); } static int get_int(AltosHexfile hexfile, String name, int len) throws AltosNoSymbol { byte[] bytes = hexfile.data; - int start = find_offset(hexfile, name, len); + int start = (int) find_offset(hexfile, name, len); int v = 0; int o = 0; @@ -128,6 +135,9 @@ public class AltosRomconfig { break; } } + usb_id = hexfile.find_usb_id(); + usb_product = hexfile.find_usb_product(); + } catch (AltosNoSymbol missing) { valid = false; } @@ -137,9 +147,16 @@ public class AltosRomconfig { ao_romconfig_version, ao_romconfig_check, ao_serial_number, - ao_radio_cal + ao_radio_cal, + ao_usb_descriptors, }; + private static int fetch_len(String name) { + if (name.equals(ao_usb_descriptors)) + return 256; + return 2; + } + private final static String[] required_names = { ao_romconfig_version, ao_romconfig_check, @@ -153,11 +170,13 @@ public class AltosRomconfig { return false; } - public static int fetch_base(AltosHexfile hexfile) throws AltosNoSymbol { - int base = 0x7fffffff; + public static long fetch_base(AltosHexfile hexfile) throws AltosNoSymbol { + long base = 0xffffffffL; for (String name : fetch_names) { try { - int addr = find_offset(hexfile, name, 2) + hexfile.address; + int len = fetch_len(name); + long addr = find_address(hexfile, name, len); + if (addr < base) base = addr; } catch (AltosNoSymbol ns) { @@ -168,11 +187,12 @@ public class AltosRomconfig { return base; } - public static int fetch_bounds(AltosHexfile hexfile) throws AltosNoSymbol { - int bounds = 0; + public static long fetch_bounds(AltosHexfile hexfile) throws AltosNoSymbol { + long bounds = 0; for (String name : fetch_names) { try { - int addr = find_offset(hexfile, name, 2) + hexfile.address; + int len = fetch_len(name); + long addr = find_address(hexfile, name, len) + len; if (addr > bounds) bounds = addr; } catch (AltosNoSymbol ns) { @@ -180,7 +200,8 @@ public class AltosRomconfig { throw (ns); } } - return bounds + 2; + + return bounds; } public void write (AltosHexfile hexfile) throws IOException {