X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altoslib%2FAltosHexfile.java;h=609d1bcb366f9f3ae747633f1f0a51e8894d04ad;hp=14f660a0bbcb0c4d38f406d31d2029d3fea3c711;hb=HEAD;hpb=ec46adee44ea08120b1940ca55a5fbdf56874bb1 diff --git a/altoslib/AltosHexfile.java b/altoslib/AltosHexfile.java index 14f660a0..71882600 100644 --- a/altoslib/AltosHexfile.java +++ b/altoslib/AltosHexfile.java @@ -287,6 +287,8 @@ public class AltosHexfile { return null; } + private static final int look_around[] = { 0, -2, 2, -4, 4 }; + private long find_usb_descriptors() { AltosHexsym usb_descriptors = lookup_symbol("ao_usb_descriptors"); long a; @@ -294,24 +296,22 @@ public class AltosHexfile { if (usb_descriptors == null) return -1; - try { - /* The address of this has moved depending on - * padding in the linker script. Look forward - * and backwards two bytes to see if we can find it - */ - a = usb_descriptors.address; - - if (get_u8(a) == 0x12 && get_u8(a+1) == AO_USB_DESC_DEVICE) - return a; - else if (get_u8(a+1) == 0x12 && get_u8(a+3) == AO_USB_DESC_DEVICE) - return a + 2; - else if (get_u8(a-2) == 0x12 && get_u8(a-1) == AO_USB_DESC_DEVICE) - return a - 2; + /* The address of this has moved depending on padding + * in the linker script and romconfig symbols. Look + * forward and backwards two and four bytes to see if + * we can find it + */ + a = usb_descriptors.address; - return -1; - } catch (ArrayIndexOutOfBoundsException ae) { - return -1; + for (int look : look_around) { + try { + if (get_u8(a + look) == 0x12 && get_u8(a + look + 1) == AO_USB_DESC_DEVICE) + return a; + } catch (ArrayIndexOutOfBoundsException ae) { + continue; + } } + return -1; } public AltosUsbId find_usb_id() {