// Tom's User Defined Loading stuff... // Checks for an Atari ST '.PRG' file // From: thayes@iglou.com (Thomas Wm Hayes) ======= File USERLOAD.IDC =============== #define USERLOAD_IDC static userload(input_file,real_file,filetype) { auto fileext; auto x, lowx, highx; auto tseg, dseg, symt, relt, bseg; auto botmem, topmem, bpsx, xsx; auto expandfrom, expandto; auto reltbl, newval; auto i, j, tmp; if (filetype == FT_BIN) { fileext = GetInputFile(); fileext = substr(fileext,strstr(fileext,".")+1,-1); if ( (strlen(fileext) == 3) && ( ( (strstr(fileext,"prg") == 0) || (strstr(fileext,"tos") == 0) ) || (strstr(fileext,"ttp") == 0) ) ) { x = MinEA(); MakeWord(x); if ( Word(x) == 0x601A ) { Message("Atari ST executable signature detected.\n"); highx = (x >> 16); lowx = (x & 0xFFFF); Message(" Loaded into memory at %04x%04x ...\n", highx, lowx); DeleteAll(); //preserve stuff we need before playing with memory topmem = MaxEA(); botmem = x - 0x100; bpsx = (botmem >> 4); xsx = (x >> 4); tseg = Dword(x + 0x02); dseg = Dword(x + 0x06); bseg = Dword(x + 0x0A); symt = Dword(x + 0x0E); relt = topmem - (x + tseg + dseg + symt); Message(" Creating Base Page Segment ...\n"); //create the basepage segment here PatchDword(botmem, botmem); PatchDword(botmem + 0x04, bpsx); PatchDword(botmem + 0x08, x); PatchDword(botmem + 0x0C, tseg); PatchDword(botmem + 0x10, x + tseg); PatchDword(botmem + 0x14, dseg); PatchDword(botmem + 0x18, x + tseg + dseg + symt); PatchDword(botmem + 0x1C, bseg); // 0x20 and up can be 0's for our purposes for (i=0x20; i<0x100; i++) PatchByte(botmem + i, 0); SegCreate(botmem, x, bpsx, 1, saRelPage, scPub); SegRename(botmem, "bpseg"); Message(" Moving file data downward ...\n"); //move file data down 0x1C bytes to get it at 0 for (i=x + 0x1C; i<=topmem + 1; i++) PatchByte(i - 0x1C, Byte(i)); Message(" Creating code segment ...\n"); SegCreate(x, x + tseg, xsx, 1, saRelPage, scPub); SegRename(x, "tseg"); if (dseg > 0) { Message(" Creating data segment ...\n"); SegCreate(x + tseg, x + tseg + dseg, xsx, 1, saRelPage, scPub); SegRename(x + tseg, "dseg"); } if (relt > 0) { Message(" Performing relocation fixups ...\n"); // We don't do anything here as we have already created a 'fake segment' to // align our code at address 0 which requires no fixups. Message(" ... nothing to do, code is already at 0!!!\n"); // //need to do fixups/relocation table here // //using our x and xsx // //however, we simply ignore it right now // // reltbl = x + tseg + dseg + symt; // j = x + Dword(reltbl); // newval = Dword(j) + x; // PatchDword(j, newval); // for (i=reltbl + 0x4; Byte(i) != 0; i++) // { // tmp = Byte(i); // if (tmp == 1) // j = j + 0xFF; // else // { // j = j + tmp; // newval = Dword(j) + x; // PatchDword(j, newval); // } // } // Message(" ... processed %ul relocation entries\n", i - reltbl); } if (symt > 0) { // We don't do anything here either, as I didn't actually write this section yet... Message(" Parsing though symbol table ...\n"); //need to parse through symbol table here //in order to add meaningful names/comments //however, we simply ignore it right now SegCreate(x + tseg + dseg, x + tseg + dseg + symt, xsx, 1, saRelPage, scPub); SegRename(x + tseg + dseg, "symt"); } if (bseg > 0) { Message(" Zeroing out BSS segment ...\n"); //we blank out the bss segment with 0's here //it used to hold our relocation fixups data expandfrom = x + tseg + dseg + symt; expandto = expandfrom + bseg; for (i=expandfrom; i