Admin Password
    1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// This program emulates an absolute loader for an SIC Machine. It requires
// the presence of an 'objcode.txt' file in C:\CPROGS directory containing the
// object code produced by an assembler from any given source code. This
// program outputs machine code in the same order as would be expected
//from a real loader and stores the result in 'machcode.txt', also in the same dir.
#include <stdio.h>
#include <stdlib.h>
// GLOBAL VARIABLES
char outputString[30], gotLine[50][50];
int nLines = 0, startAddress = 0;
FILE *fpIN, *fpOUT;
char startAddressAsString[7] = {'0','0','0','0','\0'};
int processFile() {
char c;
int location = 0, endNow = 0;
if((fpIN = fopen("c:/CPROGS/OBJCOD1P.TXT", "r+")) == NULL) {
printf("Error! File not found!\n" );
return(1);
}
printf("File Opened! Reading contents...\n\n"); getch();
c = getc(fpIN);
while(endNow != 1) {
if(c != '\n') {
gotLine[nLines][location] = c;
location++;
}
else {
gotLine[nLines][location] = '\0';
location = 0;
while(gotLine[nLines][location] != '\0') {
printf("%c", gotLine[nLines][location]);
location++;
}
printf("\n");
location = 0;
nLines++;
}
if((c = getc(fpIN)) == EOF) {
endNow = 1;
}
}
printf("\nFile has ended! Contents have been stored in local array. Closing file...");
getch();
fclose(fpIN);
return(0);
}
int main() {
int fileReadError = 0, currentLine = 0, currentLetter = 7, outputLetter = 0, locationCounter = 1, startAddress;
char programName[10], startAddressAsString[10] = {'0','0','0','0','\0'}, outputString[6], gotLetter;
clrscr();
fileReadError = processFile();
if(fileReadError == 1) {
printf("\nPlease ensure that 'assemble.txt' is present in root of C drive.\nPress any key to exit...");
getch();
return(1);
}
if(gotLine[currentLine][0] == 'H') {
while(gotLine[currentLine][locationCounter] != ' ' && locationCounter <= 6) {
programName[locationCounter - 1] = gotLine[currentLine][locationCounter];
locationCounter++;
}
programName[locationCounter - 1] = '\0';
printf("\n\nProgram Name: %s", programName);
locationCounter = 7;
while(locationCounter <= 13) {
startAddressAsString[locationCounter - 7] = gotLine[currentLine][locationCounter];
locationCounter++;
}
startAddressAsString[locationCounter - 7] = '\0';
startAddress = atoi(startAddressAsString);
printf("\nStart Address: %d", startAddress);
getch();
}
currentLine++;
fpOUT = fopen("c:/CPROGS/MACHCODE.TXT", "w+");
while(gotLine[currentLine][0] != 'E') {
gotLetter = gotLine[currentLine][currentLetter];
if(gotLetter == '\0') {
currentLine++;
currentLetter = 7;
startAddressAsString[0] = gotLine[currentLine][1];
startAddressAsString[1] = gotLine[currentLine][2];
startAddressAsString[2] = gotLine[currentLine][3];
startAddressAsString[3] = gotLine[currentLine][4];
startAddressAsString[4] = '\0';
startAddress = atoi(startAddressAsString);
}
else {
outputString[outputLetter] = gotLetter;
outputLetter++;
if(outputLetter == 4) {
outputString[4] = '\n';
outputString[5] = '\0';
itoa(startAddress, startAddressAsString, 10);
startAddressAsString[4] = ' ';
startAddressAsString[5] = '\0';
fputs(startAddressAsString, fpOUT);
fputs(outputString, fpOUT);
startAddress += 2;
outputLetter = 0;
}
currentLetter++;
}
}
if(outputLetter != 0) {
outputString[outputLetter] = '\n';
outputString[outputLetter + 1] = '\0';
itoa(startAddress, startAddressAsString, 10);
startAddressAsString[4] = ' ';
startAddressAsString[5] = '\0';
fputs(startAddressAsString, fpOUT);
fputs(outputString, fpOUT);
}
printf("\n\nLoading procedure completed. Press any key to exit..."); getch();
return(0);
}
This page has been viewed 138 times
Free Text Host is brought to you by Dagon Design
This site contains no adware, spyware, or popups
Questions? Comments?