summaryrefslogtreecommitdiff
path: root/command_line/CmdLine/Src/Project/CLOverlays.c
diff options
context:
space:
mode:
authorAsh Wolf <ninji@wuffs.org>2022-10-19 21:16:13 +0100
committerAsh Wolf <ninji@wuffs.org>2022-10-19 21:16:13 +0100
commitd1f153d34b023d81768f6087f67dbfff714bafc9 (patch)
treea694d470a60655d0cda15a70791fbdb90a2398cf /command_line/CmdLine/Src/Project/CLOverlays.c
parent775b6861666af36d317fb577cf489e2c6377f878 (diff)
downloadMWCC-d1f153d34b023d81768f6087f67dbfff714bafc9.tar.gz
MWCC-d1f153d34b023d81768f6087f67dbfff714bafc9.zip
let's commit all this before my VM blows up and nukes my work
Diffstat (limited to 'command_line/CmdLine/Src/Project/CLOverlays.c')
-rw-r--r--command_line/CmdLine/Src/Project/CLOverlays.c296
1 files changed, 296 insertions, 0 deletions
diff --git a/command_line/CmdLine/Src/Project/CLOverlays.c b/command_line/CmdLine/Src/Project/CLOverlays.c
index e69de29..3437366 100644
--- a/command_line/CmdLine/Src/Project/CLOverlays.c
+++ b/command_line/CmdLine/Src/Project/CLOverlays.c
@@ -0,0 +1,296 @@
+#include "cmdline.h"
+
+Boolean Overlays_Initialize(Overlays *this) {
+ OvlGroup *grp;
+ Overlay *ovl;
+ OvlAddr addr;
+ SInt32 idx;
+
+#line 24
+ OPTION_ASSERT(this);
+
+ this->groups = NULL;
+ this->lastgrp = NULL;
+ this->grpcnt = 0;
+ addr.hi = 0;
+ addr.lo = 0;
+
+ grp = OvlGroup_New("main_application", addr);
+ if (!grp)
+ return 0;
+
+ ovl = Overlay_New("MAIN");
+ if (!ovl)
+ return 0;
+
+ OvlGroup_AddOverlay(grp, ovl, &idx);
+#line 42
+ OPTION_ASSERT(idx==0);
+
+ Overlays_AddOvlGroup(this, grp, &idx);
+#line 45
+ OPTION_ASSERT(idx==0);
+
+ return 1;
+}
+
+Boolean Overlays_Terminate(Overlays *this) {
+ OvlGroup *grp;
+ OvlGroup *nxtgrp;
+
+#line 54
+ OPTION_ASSERT(this);
+
+ for (grp = this->groups; grp; grp = nxtgrp) {
+ nxtgrp = grp->next;
+ OvlGroup_Delete(grp);
+ xfree(grp);
+ }
+
+ this->groups = NULL;
+ return 1;
+}
+
+Boolean Overlays_AddOvlGroup(Overlays *this, OvlGroup *grp, SInt32 *grpnum) {
+#line 70
+ OPTION_ASSERT(this);
+ OPTION_ASSERT(grp);
+
+ if (this->groups == NULL)
+ this->groups = grp;
+ else
+ this->lastgrp->next = grp;
+ this->lastgrp = grp;
+
+ if (grpnum)
+ *grpnum = this->grpcnt;
+ this->grpcnt++;
+
+ return 1;
+}
+
+OvlGroup *Overlays_GetOvlGroup(Overlays *this, SInt32 grpnum) {
+ OvlGroup *grp;
+ SInt32 cnt = 0;
+
+#line 93
+ OPTION_ASSERT(this);
+
+ grp = this->groups;
+ while (grp && cnt < grpnum) {
+ grp = grp->next;
+ cnt++;
+ }
+
+ if (cnt == grpnum)
+ return grp;
+ else
+ return NULL;
+}
+
+SInt32 Overlays_CountGroups(Overlays *this) {
+ OvlGroup *scan;
+ int num = 0;
+
+#line 112
+ OPTION_ASSERT(this);
+
+ scan = this->groups;
+ while (scan) {
+ scan = scan->next;
+ num++;
+ }
+
+ return num;
+}
+
+Boolean Overlays_AddFileToOverlay(Overlays *this, SInt32 grpnum, SInt32 ovlnum, SInt32 filenum) {
+ Overlay *oly;
+
+#line 130
+ OPTION_ASSERT(this);
+
+ oly = Overlays_GetOverlayInGroup(this, grpnum, ovlnum);
+ if (oly)
+ return Overlay_AddFile(oly, filenum, NULL);
+ else
+ return 0;
+}
+
+Overlay *Overlays_GetOverlayInGroup(Overlays *this, SInt32 grpnum, SInt32 ovlnum) {
+ OvlGroup *grp;
+
+#line 144
+ OPTION_ASSERT(this);
+
+ grp = Overlays_GetOvlGroup(this, grpnum);
+ if (grp)
+ return OvlGroup_GetOverlay(grp, ovlnum);
+ else
+ return NULL;
+}
+
+SInt32 Overlays_GetFileInOverlay(Overlays *this, SInt32 grpnum, SInt32 ovlnum, SInt32 filnum) {
+ Overlay *oly;
+
+#line 160
+ OPTION_ASSERT(this);
+
+ oly = Overlays_GetOverlayInGroup(this, grpnum, ovlnum);
+ if (oly)
+ return Overlay_GetFile(oly, filnum);
+ else
+ return -1;
+}
+
+OvlGroup *OvlGroup_New(const char *name, OvlAddr addr) {
+ OvlGroup *grp;
+
+#line 175
+ OPTION_ASSERT(name);
+
+ grp = xmalloc(NULL, sizeof(OvlGroup));
+ if (grp) {
+ strncpy(grp->name, name, sizeof(grp->name));
+ grp->name[sizeof(grp->name) - 1] = 0;
+ grp->addr = addr;
+ grp->lastoly = NULL;
+ grp->olys = NULL;
+ grp->olycnt = 0;
+ grp->next = NULL;
+ } else {
+#line 188
+ DO_INTERNAL_ERROR("Could not allocate %s", "overlay group");
+ }
+ return grp;
+}
+
+void OvlGroup_Delete(OvlGroup *grp) {
+ Overlay *scan;
+ Overlay *next;
+
+#line 197
+ OPTION_ASSERT(grp);
+
+ for (scan = grp->olys; scan; scan = next) {
+ next = scan->next;
+ Overlay_Delete(scan);
+ xfree(scan);
+ }
+
+ grp->olys = NULL;
+}
+
+Boolean OvlGroup_AddOverlay(OvlGroup *this, Overlay *oly, SInt32 *olynum) {
+#line 211
+ OPTION_ASSERT(this);
+ OPTION_ASSERT(oly);
+
+ if (!this->lastoly)
+ this->olys = oly;
+ else
+ this->lastoly->next = oly;
+ this->lastoly = oly;
+
+ if (olynum)
+ *olynum = this->olycnt;
+ this->olycnt++;
+
+ return 1;
+}
+
+Overlay *OvlGroup_GetOverlay(OvlGroup *this, SInt32 olynum) {
+ Overlay *oly;
+ SInt32 cnt = 0;
+
+#line 234
+ OPTION_ASSERT(this);
+
+ oly = this->olys;
+ while (oly && cnt < olynum) {
+ oly = oly->next;
+ cnt++;
+ }
+
+ if (cnt == olynum)
+ return oly;
+ else
+ return NULL;
+}
+
+SInt32 OvlGroup_CountOverlays(OvlGroup *this) {
+ Overlay *scan;
+ int num = 0;
+
+#line 254
+ OPTION_ASSERT(this);
+
+ scan = this->olys;
+ while (scan) {
+ scan = scan->next;
+ num++;
+ }
+
+ return num;
+}
+
+Overlay *Overlay_New(const char *name) {
+ Overlay *oly;
+
+ oly = xmalloc(NULL, sizeof(Overlay));
+ if (oly) {
+ strncpy(oly->name, name, sizeof(oly->name));
+ oly->name[sizeof(oly->name) - 1] = 0;
+ oly->list = NULL;
+ oly->max = 0;
+ oly->cnt = 0;
+ oly->next = NULL;
+ } else {
+#line 281
+ DO_INTERNAL_ERROR("Could not allocate %s", "overlay");
+ }
+ return oly;
+}
+
+void Overlay_Delete(Overlay *oly) {
+#line 288
+ OPTION_ASSERT(oly);
+
+ if (oly->list)
+ xfree(oly->list);
+ oly->list = NULL;
+}
+
+Boolean Overlay_AddFile(Overlay *oly, SInt32 filenum, SInt32 *filnum) {
+#line 296
+ OPTION_ASSERT(oly);
+
+ if (oly->cnt >= oly->max) {
+ oly->max += 16;
+ oly->list = xrealloc("overlay file list", oly->list, sizeof(SInt32) * oly->max);
+ }
+ oly->list[oly->cnt] = filenum;
+
+ if (filnum)
+ *filnum = oly->cnt;
+ oly->cnt++;
+
+ return 1;
+}
+
+SInt32 Overlay_GetFile(Overlay *oly, SInt32 filnum) {
+#line 314
+ OPTION_ASSERT(oly);
+
+ if (filnum < oly->cnt)
+ return oly->list[filnum];
+ else
+ return -1;
+}
+
+SInt32 Overlay_CountFiles(Overlay *oly) {
+#line 323
+ OPTION_ASSERT(oly);
+
+ return oly->cnt;
+}