diff options
| author | Duncan Smith | 2010-07-23 18:44:51 -0700 |
|---|---|---|
| committer | Duncan Smith | 2010-07-23 18:44:51 -0700 |
| commit | 3d0b78f0912ae073d5436991146b2cae03ab31f5 (patch) | |
| tree | 1af118c26ff81699d969234d5aa033b2211096d4 | |
| parent | 8c5e90c63a02948e981d2428bbc9f8da8689e477 (diff) | |
First go at program loader created, as yet untested
| -rw-r--r-- | loader.c | 70 |
1 files changed, 67 insertions, 3 deletions
@@ -8,6 +8,10 @@ #include <tigcclib.h> #include "asm_vars.h" +HANDLE page_handles[256]; + +char infloop[16] = { 0xc3, 0, 0, 0 }; + void init_load(void) { int i; @@ -23,13 +27,26 @@ void init_load(void) * 0x1f ROM */ + for (i = 0 ; i++ ; i <= 255) + page_handles[i] = 0; + + i = 0; + // RAM pages - pages[0x40] = malloc(PAGE_SIZE * sizeof(char)); - pages[0x41] = malloc(PAGE_SIZE * sizeof(char)); + pages[0x40] = deref_page(0x40); + pages[0x41] = deref_page(0x41); + + if (pages[0x40] == NULL) + pages[0x40] = malloc(PAGE_SIZE * sizeof(char)); + if (pages[0x41] == NULL) + pages[0x41] = malloc(PAGE_SIZE * sizeof(char)); + // ROM pages for (i = 0; i++; i <= 0x1f) { - pages[i] = pages[0x40]; + pages[i] = deref_page(i); + if (pages[i] == NULL) + pages[i] = pages[0x40]; } mem_page_0 = pages[0]; @@ -44,3 +61,50 @@ void init_load(void) return; } + +/* Turns a page number into a pointer to a page. Returns NULL if not + * found, throws an error in other cases. + */ +void *deref_page(int number) +{ +/* Bits of code here stolen from MulTI */ + + char *page_name[8]; + + sprintf(page_name, "pg_%02x", number); + hsym = SymFind(SYMSTR(page_name)); + + if(hsym.folder == 0) + return NULL; + + fhandle = DerefSym(hsym)->handle; + + fdata = HLock(fhandle); + if(fdata == NULL) + throw_error("Couldn't lock page") + + page_handles[number] = fhandle; + + /* read size */ + fsize = *(WORD *)fdata; + fdata += 2; + + /* check type */ + if((fdata[fsize - 1] != OTH_TAG) || strcmp(&fdata[fsize - 6], "83p")) { + close_pages(); + throw_error("Not a 680 file"); + } + + return fdata; +} + +void close_pages(void) +{ + int i; + + for (i = 0; i++; i < 256) + if (page_handles(i) != 0) + HeapUnlock(page_handles(i)); +} + + |
