#include #include #include #include #include #include "asm.h" #include "defines.h" #include "structs.h" #include "externs.h" #include "main.ext" #include "asm.ext" #include "load.pro" UWORD load_module() { UWORD relocation_offset, loop; WORD mem_loc, instr_cnt; clrscr(); printf("\n\n Object Module Loader"); memset(&AssocMem[0], 0, MEMORY_SIZE ); relocation_offset = OrgLoc; instr_cnt = mem_loc = 0; while(Instruction[instr_cnt].pseudo != END ) { if( (relocation_offset+mem_loc) > ( MEMORY_SIZE - 1) ) { printf("\nError. Relocation address exceeds Associative Memory Range."); pause(); return(ERROR); } else { if( Instruction[instr_cnt].pseudo == DS) { for(loop =0; loop < Instruction[instr_cnt].instr_len; loop++) AssocMem[relocation_offset + mem_loc] = 0; mem_loc++; } else { if( (Instruction[instr_cnt].pseudo >= EQU) && (Instruction[instr_cnt].pseudo <= END ) ) { AssocMem[relocation_offset + mem_loc] = (Instruction[instr_cnt].eff_add >> 8); mem_loc++; AssocMem[relocation_offset + mem_loc] = (Instruction[instr_cnt].eff_add & 0x00FF); } else { if( Instruction[instr_cnt].instr_len > 1 ) { AssocMem[relocation_offset + mem_loc] = (UBYTE)(Instruction[instr_cnt].opcode); mem_loc++; Instruction[instr_cnt].eff_add += relocation_offset; // add relocation offset AssocMem[relocation_offset + mem_loc] = (Instruction[instr_cnt].eff_add & 0xFF00); mem_loc++; AssocMem[relocation_offset + mem_loc] = (Instruction[instr_cnt].eff_add & 0xFF); } else AssocMem[relocation_offset + mem_loc] = (UBYTE)(Instruction[instr_cnt].opcode); } } } mem_loc++; instr_cnt++; } gotoxy(25,20); printf("Object Module loaded successfully."); pause(); return(OK); } //////////////////////////////////////////////////////////////////////////// void write_list_file() { WORD instr_cnt, mem_loc, relocation_offset, instr_size; BYTE line[MAX_LINE], count; // write assembler list file to disk if( openfiles("passone.out", "list.out") != ERROR) { relocation_offset = OrgLoc; instr_cnt = mem_loc = 0; while(Instruction[instr_cnt].pseudo != END ) { fgets(line, sizeof(line),In_Ptr); // read in line from input file instr_size = Instruction[instr_cnt].instr_len; fprintf(Out_Ptr,"%2.2X ", Instruction[instr_cnt].lctr); for(count = 0; count < instr_size; count++) fprintf(Out_Ptr,"%2.2X ",AssocMem[relocation_offset+mem_loc + count] ); if( (Instruction[instr_cnt].pseudo >= ORG) && (Instruction[instr_cnt].pseudo <= END) ) fprintf(Out_Ptr," "); if( (Instruction[instr_cnt].opcode > HLT) && (Instruction[instr_cnt].opcode < RET) ) fprintf(Out_Ptr," %d", Instruction[instr_cnt].relocate); else fprintf(Out_Ptr," "); if( instr_size == 1) fprintf(Out_Ptr," "); fprintf(Out_Ptr," %s \n\r", line); mem_loc += instr_size; instr_cnt++; } } fflush(In_Ptr); fflush(Out_Ptr); fcloseall(); }