53 |
53 |
54 ObjWriter::ObjWriter (str path) { |
54 ObjWriter::ObjWriter (str path) { |
55 MainBuffer = new DataBuffer; |
55 MainBuffer = new DataBuffer; |
56 MainLoopBuffer = new DataBuffer; |
56 MainLoopBuffer = new DataBuffer; |
57 OnEnterBuffer = new DataBuffer; |
57 OnEnterBuffer = new DataBuffer; |
|
58 RecordBuffer = NULL; // created on demand |
58 numWrittenBytes = 0; |
59 numWrittenBytes = 0; |
59 numWrittenReferences = 0; |
60 numWrittenReferences = 0; |
60 filepath = path; |
61 filepath = path; |
61 } |
62 } |
62 |
63 |
107 Write<long> (stringcount); |
108 Write<long> (stringcount); |
108 |
109 |
109 for (unsigned int a = 0; a < stringcount; a++) |
110 for (unsigned int a = 0; a < stringcount; a++) |
110 WriteString (g_StringTable[a]); |
111 WriteString (g_StringTable[a]); |
111 } |
112 } |
112 |
|
113 printf ("%u / %u string%s written\n", stringcount, MAX_LIST_STRINGS, PLURAL (stringcount)); |
|
114 } |
113 } |
115 |
114 |
116 // Write main buffer to file |
115 // Write main buffer to file |
117 void ObjWriter::WriteToFile () { |
116 void ObjWriter::WriteToFile () { |
118 fp = fopen (filepath, "w"); |
117 fp = fopen (filepath, "w"); |
119 CHECK_FILE (fp, filepath, "writing"); |
118 CHECK_FILE (fp, filepath, "writing"); |
120 |
|
121 if (sizeof (unsigned char) != 1) |
|
122 error ("size of unsigned char isn't 1, but %d!\n", sizeof (unsigned char)); |
|
123 |
119 |
124 // First, resolve references |
120 // First, resolve references |
125 numWrittenReferences = 0; |
121 numWrittenReferences = 0; |
126 for (unsigned int u = 0; u < MAX_MARKS; u++) { |
122 for (unsigned int u = 0; u < MAX_MARKS; u++) { |
127 ScriptMarkReference* ref = MainBuffer->refs[u]; |
123 ScriptMarkReference* ref = MainBuffer->refs[u]; |
132 union_t<word> uni; |
128 union_t<word> uni; |
133 uni.val = static_cast<word> (MainBuffer->marks[ref->num]->pos); |
129 uni.val = static_cast<word> (MainBuffer->marks[ref->num]->pos); |
134 memset (MainBuffer->buffer + ref->pos + v, uni.b[v], 1); |
130 memset (MainBuffer->buffer + ref->pos + v, uni.b[v], 1); |
135 } |
131 } |
136 |
132 |
|
133 /* |
|
134 printf ("reference %u at %d resolved to %u at %d\n", |
|
135 u, ref->pos, ref->num, MainBuffer->marks[ref->num]->pos); |
|
136 */ |
137 numWrittenReferences++; |
137 numWrittenReferences++; |
138 } |
138 } |
139 |
139 |
140 // Then, dump the main buffer to the file |
140 // Then, dump the main buffer to the file |
141 for (unsigned int x = 0; x < MainBuffer->writesize; x++) |
141 for (unsigned int x = 0; x < MainBuffer->writesize; x++) |
144 printf ("-- %u byte%s written to %s\n", numWrittenBytes, PLURAL (numWrittenBytes), filepath.chars()); |
144 printf ("-- %u byte%s written to %s\n", numWrittenBytes, PLURAL (numWrittenBytes), filepath.chars()); |
145 fclose (fp); |
145 fclose (fp); |
146 } |
146 } |
147 |
147 |
148 DataBuffer* ObjWriter::GetCurrentBuffer() { |
148 DataBuffer* ObjWriter::GetCurrentBuffer() { |
149 return (g_CurMode == MODE_MAINLOOP) ? MainLoopBuffer : |
149 return RecordBuffer ? RecordBuffer : |
|
150 (g_CurMode == MODE_MAINLOOP) ? MainLoopBuffer : |
150 (g_CurMode == MODE_ONENTER) ? OnEnterBuffer : |
151 (g_CurMode == MODE_ONENTER) ? OnEnterBuffer : |
151 MainBuffer; |
152 MainBuffer; |
152 } |
153 } |
153 |
154 |
154 ScriptMark* g_ScriptMark = NULL; |
155 ScriptMark* g_ScriptMark = NULL; |