From ef4626e970361a583326a51f2722489ccd920ab4 Mon Sep 17 00:00:00 2001 From: Paul Gardner-Stephen Date: Thu, 18 Apr 2019 20:50:57 +0930 Subject: [PATCH] sort routines in appropriate order --- .gitmodules | 3 +++ Makefile | 2 +- Ophis | 1 + src/preprocess.c | 58 +++++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 .gitmodules create mode 160000 Ophis diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..8e08ef3f --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "Ophis"] + path = Ophis + url = git@github.com:gardners/Ophis.git diff --git a/Makefile b/Makefile index 1bd46eaf..0076f84e 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ src/collect_data: src/collect_data.c Makefile gcc -Wall -o src/collect_data src/collect_data.c src/preprocess: src/preprocess.c Makefile - gcc -Wall -o src/preprocess src/preprocess.c + gcc -g -Wall -o src/preprocess src/preprocess.c c64/kernal-disasembly.html: diff --git a/Ophis b/Ophis new file mode 160000 index 00000000..15818e76 --- /dev/null +++ b/Ophis @@ -0,0 +1 @@ +Subproject commit 15818e7666cc4b05993e0f5724c664671b0c1cae diff --git a/src/preprocess.c b/src/preprocess.c index 42e3976c..077e2751 100644 --- a/src/preprocess.c +++ b/src/preprocess.c @@ -13,6 +13,25 @@ #define DO_ERROR(X) { retVal=-1; fprintf(stderr,"%s:%d:%s():%s\n",__FILE__,__LINE__,__func__,X); break; } +#define MAX_FILES (128*1024) +typedef struct source_file { + char *file; + u_int32_t address; +} source_file; + +source_file source_files[MAX_FILES]; +int source_count=0; + +static int compare_source(const void* a, const void* b) +{ + source_file* aa = (source_file*)a; + source_file* bb = (source_file*)b; + + if (aa->addressaddress) return -1; + if (aa->address>bb->address) return 1; + return strcmp(aa->file,bb->file); +} + void usage(void) { fprintf(stderr,"usage: preprocess [-d ]\n"); @@ -39,17 +58,50 @@ int main(int argc,char **argv) exit(-1); } } - + + // Get list of files d=opendir(directory); if (!d) DO_ERROR("opendir() failed"); - while((de=readdir(d))!=NULL) { if (strlen(de->d_name)>2) { if (!strcmp(&de->d_name[strlen(de->d_name)-2],".s")) { - printf("%s\n",de->d_name); + if (source_count>=MAX_FILES) DO_ERROR("Too many source files. Increase MAX_FILES?"); + source_files[source_count].file=strdup(de->d_name); + source_files[source_count].address=0x7fffffff; + source_count++; } } } + if (retVal) break; + closedir(d); d=NULL; + + fprintf(stderr,"Found %d source files\n",source_count); + + // Now get routine addresses of everything + for(int i=0;i