-
Notifications
You must be signed in to change notification settings - Fork 1
/
fsb2-mgt.sh
executable file
·128 lines (95 loc) · 2.96 KB
/
fsb2-mgt.sh
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
#!/bin/bash
# fsb2-mgt.sh
# This file is part of fsb2
# http://programandala.net/en.program.fsb2.html
# Last modified: 201702271853
# ==============================================================
# Author and license
# Copyright (C) 2015,2016,2017 Marcos Cruz (programandala.net)
# You may do whatever you want with this work, so long as you
# retain the copyright notice(s) and this license in all
# redistributed copies and derived works. There is no warranty.
# ==============================================================
# Description
# This program converts a Forth source file from the FSB format
# to a ZX Spectrum phony MGT disk image (suitable for GDOS,
# G+DOS or Beta DOS). The disk image will contain the source
# file directly on the sectors, without file system, to be
# directly accessed by a Forth system. This is the format used
# by the library disk of Solo Forth
# (http://programandala.net/en.program.solo_forth.html).
# ==============================================================
# Requirements
# fsb2:
# <http://programandala.net/en.program.fsb2.html>
# ==============================================================
# Usage (after installation)
# fsb2-mgt filename
# ==============================================================
# History
# 2015-10-10: Adapted from fsb
# (http://programandala.net/en.program.fsb.html).
#
# 2015-11-21: Typo.
#
# 2016-05-02: Start implementing the size check.
#
# 2016-05-03: Finish the size check.
#
# 2016-08-03: Fix typo.
#
# 2017-02-27: Don't assume the extension of the source filename
# is "fsb" anymore. Don't reuse it as secondary extension of the
# blocks file. Update the messages.
# ==============================================================
# Error checking
if [ "$#" -ne 1 ] ; then
echo "Convert a Forth source file from FSB format"
echo "to a block disk in a MGT disk image."
echo
echo 'Usage:'
echo " ${0##*/} sourcefile"
exit 1
fi
if [ ! -e "$1" ] ; then
echo "Error: <$1> does not exist"
exit 1
fi
if [ ! -f "$1" ] ; then
echo "Error: <$1> is not a regular file"
exit 1
fi
if [ ! -r "$1" ] ; then
echo "Error: <$1> can not be read"
exit 1
fi
if [ ! -s "$1" ] ; then
echo "Error: <$1> is empty"
exit 1
fi
# ==============================================================
# Main
fsb2 --verbose $1
# Get the filenames:
basefilename=${1%.*}
blocksfile=$basefilename.fb
mgtfile=$basefilename.mgt
# Get the size of the file:
du_size=$(du -sk $blocksfile)
# Extract the size from the left of the string:
file_size=${du_size%%[^0-9]*}
#echo "File size=($file_size)"
#echo "$blocksfile is $file_size Kib"
if [ $file_size -gt "800" ]
then
echo "Error:"
echo "The size of the intermediate blocks file $blocksfile"
echo "is $file_size KiB."
echo "The maximum capacity of an MGT disk image is 800 KiB."
exit 64
fi
# Do it:
dd if=$blocksfile of=$mgtfile bs=819200 cbs=819200 conv=block,sync 2>> /dev/null
# Remove the temporary file:
rm -f $blocksfile
# vim:tw=64:ts=2:sts=2:et: