+
+static void WriteLOD(void)
+{
+ D_printf("_START %s 0000 0000 0000 RMAC %01i.%01i.%01i\n\n", firstfname, MAJOR, MINOR, PATCH);
+
+ for(DSP_ORG * l=&dsp_orgmap[0]; l<dsp_currentorg; l++)
+ {
+ if (l->end != l->start)
+ {
+ switch (l->memtype)
+ {
+ case ORG_P: D_printf("_DATA P %.4X\n", l->orgadr); break;
+ case ORG_X: D_printf("_DATA X %.4X\n", l->orgadr); break;
+ case ORG_Y: D_printf("_DATA Y %.4X\n", l->orgadr); break;
+ case ORG_L: D_printf("_DATA L %.4X\n", l->orgadr); break;
+ default:
+ error("Internal error: unknown DSP56001 org'd section");
+ return;
+ }
+
+ CHUNK * cp = l->chunk;
+ uint8_t * p_chunk = l->start;
+ uint8_t * p_chunk_end = p_chunk;
+ uint32_t j = 0;
+
+ while (p_chunk_end != l->end)
+ {
+ if (l->end < (cp->chptr + cp->ch_size) && l->end > cp->chptr)
+ {
+ // If the end of the section is inside the current chunk, just dump everything and stop
+ p_chunk_end = l->end;
+ }
+ else
+ {
+ // If the end of the section is not inside the current chunk, just dump everything from the current chunk and move on to the next
+ p_chunk_end = cp->chptr + cp->ch_size;
+ }
+
+ uint32_t count = (uint32_t)(p_chunk_end - p_chunk);
+
+ for(uint32_t i=0; i<count; i+=3)
+ {
+ if ((j & 7) != 7)
+ {
+ D_printf("%.6X ", (((p_chunk[0] << 8) | p_chunk[1]) << 8) | p_chunk[2]);
+ }
+ else
+ {
+ D_printf("%.6X\n", (((p_chunk[0] << 8) | p_chunk[1]) << 8) | p_chunk[2]);
+ }
+
+ p_chunk += 3;
+ j++;
+ }
+
+ cp = cp->chnext; // Advance chunk
+
+ if (cp != NULL)
+ p_chunk = cp->chptr; // Set dump pointer to start of this chunk
+ }
+
+ if ((j & 7) != 0)
+ D_printf("\n");
+ }
+ }
+
+ // Dump the symbol table into the buf
+ DumpLODSymbols();
+
+ D_printf("\n_END %.4X\n", dsp_orgmap[0].orgadr);
+}
+
+
+static void WriteP56(void)
+{
+ for(DSP_ORG * l=&dsp_orgmap[0]; l<dsp_currentorg; l++)
+ {
+ if (l->end == l->start)
+ continue;
+
+ if ((l->memtype < ORG_P) || (l->memtype > ORG_L))
+ {
+ error("Internal error: unknown DSP56001 org'd section");
+ return;
+ }
+
+ CHUNK * cp = l->chunk;
+ uint8_t * p_chunk = l->start;
+ uint8_t * p_chunk_end = p_chunk;
+
+ // Memory type (P, X, Y or L)
+ D_dsp(l->memtype);
+
+ // Chunk start address (in DSP words)
+ D_dsp(l->orgadr);
+
+ // Chunk length (in DSP words)
+ // We'll fill this field after we write the chunk so we can calculate
+ // how long it is (so if the chunk is split into different CHUNKs we
+ // can deal with this during copy)
+ uint8_t * p_buf_len = chptr;
+ chptr += 3;
+
+ // The chunk itself
+ uint32_t chunk_size = 0;
+
+ while (p_chunk_end != l->end)
+ {
+ if (l->end < (cp->chptr + cp->ch_size) && l->end > cp->chptr)
+ {
+ // If the end of the section is inside the current chunk, just
+ // dump everything and stop
+ p_chunk_end = l->end;
+ }
+ else
+ {
+ // If the end of the section is not inside the current chunk,
+ // just dump everything from the current chunk and move on to
+ // the next
+ p_chunk_end = cp->chptr + cp->ch_size;
+ }
+
+ uint32_t current_chunk_size = p_chunk_end - p_chunk;
+ chunk_size += current_chunk_size;
+ memcpy(chptr, p_chunk, current_chunk_size);
+ chptr += current_chunk_size;
+
+ cp = cp->chnext; // Advance chunk
+
+ if (cp != NULL)
+ p_chunk = cp->chptr; // Set dump pointer to start of this chunk
+ }
+
+ // Now we can mark the chunk's length (DSP word size is 24-bits, so
+ // the byte count needs to be divided by 3)
+ SETBE24(p_buf_len, chunk_size / 3);
+ }
+}
+