summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAstrid Smith2010-07-23 18:44:51 -0700
committerAstrid Smith2010-07-23 18:44:51 -0700
commit79eeb77d1599400a505aaf433d7654c0f0d4f969 (patch)
tree1040dd46f92022d463b853fe6dd83eb13568ce3e
parent2faa021f8bca174284069fecdf1896660b32700d (diff)
First go at program loader created, as yet untested
-rw-r--r--loader.c70
1 files changed, 67 insertions, 3 deletions
diff --git a/loader.c b/loader.c
index 3a292a3..256e790 100644
--- a/loader.c
+++ b/loader.c
@@ -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));
+}
+
+