--- nitpic-0.1.orig/pu_lib.c
+++ nitpic-0.1/pu_lib.c
@@ -6,18 +6,22 @@
#include <stdio.h>
#include <ctype.h>
+#define PARAMS(x) x
+
+#include <bfd.h>
+
void PU_Clear(PICDEFN *pic)
{
int i;
for(i=0; i<MAXPICSIZE; i++)
- pic->picmemmap[i] = 0xffff;
+ pic->picmemmap[i] = 0x0;
- pic->pictype = 54;
- pic->picid[0] = 0xffff;
- pic->picid[1] = 0xffff;
- pic->picid[2] = 0xffff;
- pic->picid[3] = 0xffff;
+ pic->pictype = 84;
+ pic->picid[0] = 0x00;
+ pic->picid[1] = 0x00;
+ pic->picid[2] = 0x00;
+ pic->picid[3] = 0x00;
pic->osctype = 3;
pic->clock = 1.0e6;
pic->cp_fuse = 1;
@@ -25,7 +29,38 @@
pic->pu_fuse = 1;
}
-int PU_Read(const char *filename, PICDEFN *pic, int *top)
+int PU_Read (const char *filename, PICDEFN *pic, int *top)
+{
+ bfd *file = NULL;
+ asection *section = NULL;
+
+ PU_Clear (pic);
+
+ file = bfd_openr (filename, "ihex");
+ if (file == NULL) {
+ fprintf (stderr, "unable to open file\n");
+ return PU_FAIL;
+ }
+
+ {
+ char **matching;
+ bfd_check_format_matches (file, bfd_object, &matching);
+ }
+
+ for (section = file->sections; section != NULL; section = section->next) {
+ bfd_size_type sz = bfd_section_size (file, section);
+ if ((section->vma % 2) != 0) {
+ fprintf (stderr, "section not on 16-bit boundary: ignoring");
+ break;
+ }
+ bfd_get_section_contents (file, section, pic->picmemmap + (section->vma / 2), 0, sz);
+ }
+
+ bfd_close (file);
+ return PU_OK;
+}
+
+int PU_Read_Orig(const char *filename, PICDEFN *pic, int *top)
{
FILE *filehandle;
int ch;