Skip to content

Commit

Permalink
Merge pull request #164 from davidgiven/cpmfs
Browse files Browse the repository at this point in the history
Avoid a weird mkfs.cpm bug where it doesn't always create the directory.
  • Loading branch information
davidgiven authored Sep 5, 2024
2 parents 0397fad + 85ca1ef commit d0220fc
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
run: make LLVM=$HOME/llvm-mos/bin -j`nproc` +all +mametest

- name: Upload build artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: ${{ github.event.repository.name }}.${{ github.sha }}
path: |
Expand Down
2 changes: 1 addition & 1 deletion build/zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def zip(self, name, flags="", items: TargetsMap = {}):
for k, v in items.items():
cs += [
"cat %s | $(ZIP) -q %s {outs[0]} -" % (filenameof(v), flags),
"echo '@ -\\n@=%s\\n' | $(ZIPNOTE) -w {outs[0]}" % k,
"printf '@ -\\n@=%s\\n' | $(ZIPNOTE) -w {outs[0]}" % k,
]
ins += [v]

Expand Down
37 changes: 26 additions & 11 deletions tools/build.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
from build.ab import Rule, Target, simplerule, filenameof, TargetsMap, filenamesof
from build.ab import (
Rule,
Target,
simplerule,
filenameof,
TargetsMap,
filenamesof,
)
from build.c import cxxprogram, cprogram

cxxprogram(name="multilink", srcs=["./multilink.cc"], deps=["+libfmt"])
cxxprogram(name="xextobin", srcs=["./xextobin.cc"], deps=["+libfmt"])
cxxprogram(name="shuffle", srcs=["./shuffle.cc"], deps=["+libfmt"])
cxxprogram(name="mkoricdsk", srcs=["./mkoricdsk.cc"], deps=["+libfmt"])
cxxprogram(name="mkcombifs", srcs=["./mkcombifs.cc"], deps=["+libfmt"])
cxxprogram(name="fillfile", srcs=["./fillfile.cc"], deps=["+libfmt"])
cprogram(name="unixtocpm", srcs=["./unixtocpm.c"])
cprogram(name="mkdfs", srcs=["./mkdfs.c"])
cprogram(name="mkimd", srcs=["./mkimd.c"])
cprogram(
name="fontconvert", srcs=["./fontconvert.c", "./libbdf.c", "./libbdf.h"]
)


@Rule
def unixtocpm(
self, name, src:Target=None):
def unixtocpm(self, name, src: Target = None):
simplerule(
replaces=self,
ins=[src],
outs=[f"={name}.txt"],
deps=["tools+unixtocpm"],
commands=[
"{deps[0]} < {ins[0]} > {outs[0]}"],
label="UNIXTOCPM")
commands=["{deps[0]} < {ins[0]} > {outs[0]}"],
label="UNIXTOCPM",
)


@Rule
def multilink(
Expand Down Expand Up @@ -65,6 +74,9 @@ def mkcpmfs(
if template:
cs += ["cp %s {outs[0]}" % filenameof(template)]
else:
# Some versions of mkfs.cpm don't work right if the input file
# doesn't exist.
cs += ["{deps[1]} -f {outs[0]} -b 0xe5 -n 100000"]
mkfs = "mkfs.cpm -f %s" % format
if bootimage:
mkfs += " -b %s" % filenameof(bootimage)
Expand All @@ -89,11 +101,14 @@ def mkcpmfs(
replaces=self,
ins=ins,
outs=[f"={name}.img"],
deps=["diskdefs"] + [bootimage]
if bootimage
else [] + [template]
if template
else [],
deps=(
["diskdefs", "tools+fillfile"]
+ (
[bootimage]
if bootimage
else [] + [template] if template else []
)
),
commands=cs,
label="MKCPMFS",
)
Expand Down
56 changes: 56 additions & 0 deletions tools/fillfile.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <stdio.h>
#include <unistd.h>
#include <fstream>
#include <fmt/format.h>

static std::string filename;
static int byteCount;
static int byteValue;

static void parseArgs(int argc, char* argv[])
{
for (;;)
{
switch (getopt(argc, argv, "f:n:b:"))
{
case -1:
return;

case 'f':
filename = optarg;
break;

case 'n':
byteCount = strtol(optarg, nullptr, 0);
break;

case 'b':
byteValue = strtol(optarg, nullptr, 0);
break;

default:
fmt::print(stderr,
"Usage: fillfile -f <img> -n <count> -b <byte>\n");
exit(1);
}
}
}

int main(int argc, char* argv[])
{
parseArgs(argc, argv);

std::ofstream of(filename);
if (!of)
{
fmt::print(stderr,
"fillfile: cannot open output file: {}\n", strerror(errno));
exit(1);
}

for (int i=0; i<byteCount; i++)
of.put(byteValue);

of.close();
return 0;
}

0 comments on commit d0220fc

Please sign in to comment.