summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--loader.c70
-rw-r--r--opcodes.asm2
2 files changed, 69 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));
+}
+
+
diff --git a/opcodes.asm b/opcodes.asm
index 6fd02e3..fe5547c 100644
--- a/opcodes.asm
+++ b/opcodes.asm
@@ -806,6 +806,7 @@ emu_op_48:
;; C <- B
move.w d4,-(sp)
move.b (sp),d4
+ ;; XXX emfasten?
addq.l #2,sp
DONE
;14 cycles
@@ -819,6 +820,7 @@ emu_op_4a:
;; LD C,D
move.w d5,-(sp)
move.b (sp),d4
+ ;; XXX emfasten?
addq.l #2,sp
DONE