Skip to content

Commit

Permalink
SAVECPR: better code coverage, code style and few loose ends tightened
Browse files Browse the repository at this point in the history
  • Loading branch information
ped7g committed Mar 16, 2024
1 parent 0f8771d commit 8bbe1f4
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 16 deletions.
4 changes: 2 additions & 2 deletions ContinuousIntegration/test_folder_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ for f in "${TEST_FILES[@]}"; do
else
echo -n -e " \\ \033[92m$ok_tick_text OK\033[0m "
fi
# check binary results, if TAP, CDT, BIN, RAW or TRD are present in source directory
for binext in {'tap','cdt','bin','raw','trd'}; do
# check binary results, if TAP, CDT, CPR, BIN, RAW or TRD are present in source directory
for binext in {'tap','cdt','cpr','bin','raw','trd'}; do
if [[ -f "${CFG_BASE}.${binext}" ]]; then
totalChecks=$((totalChecks + 1)) # +1 for each binary check
! $CMP "${CFG_BASE}.${binext}" "${dst_base}.${binext}" \
Expand Down
17 changes: 14 additions & 3 deletions docs/documentation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@

<para>Thanks to:<itemizedlist>
<listitem>
<para><emphasis>Kurles/HS/CPU, Alexander Kovalenko, Ped7g, Dart Alver, Oli Wilkinson</emphasis> - additional
<para><emphasis>Kurles/HS/CPU, Alexander Kovalenko, Ped7g, Dart Alver, Oli Wilkinson, Laurent Carlier</emphasis> - additional
programming;</para>
</listitem>

Expand Down Expand Up @@ -203,6 +203,17 @@

<para><variablelist>

<varlistentry>
<term>?.?.2024 - 1.20.4</term>

<listitem>
<synopsis>- added Amstrad CPC device <link linkend="po_device">AMSTRADCPCPLUS</link> - by Laurent Carlier
- added Amstrad CPC+ <link linkend="po_savecpr">`SAVECPR`</link> to save CPR cartridge - by Laurent Carlier
- fix: windows cmd.exe console state after running sjasmplus.exe
</synopsis>
</listitem>
</varlistentry>

<varlistentry>
<term>23.6.2023 - 1.20.3</term>

Expand Down Expand Up @@ -3072,7 +3083,7 @@ OUTPUT &lt;filename&gt;,a ; append</synopsis>
<term>SAVECPCSNA<indexterm id="po_savecpcsna"><primary>SAVECPCSNA</primary></indexterm> &lt;filename&gt;[,&lt;startadressofprogram&gt;]</term>

<listitem>
<para><emphasis>Works only in AMSTRADCPC464 / AMSTRADCPC6128 real device emulation mode. See
<para><emphasis>Works only in AMSTRADCPC464 / AMSTRADCPC6128 device emulation mode. See
<link linkend="po_device">DEVICE</link>.</emphasis></para>

<para>Save the snapshot for emulators of Amstrad CPC machines. (If start address is omitted,
Expand Down Expand Up @@ -3101,7 +3112,7 @@ START .... ;some code
&lt;filename&gt;[,&lt;size = 32&gt;]</term>

<listitem>
<para><emphasis>Works only in virtual device emulation mode. See
<para><emphasis>Works only in AMSTRADCPCPLUS device emulation mode. See
<link linkend="po_device">DEVICE</link>.</emphasis></para>

<para>Saves memory per blocks of 16KiB; 1 means 16KiB, 2 means
Expand Down
21 changes: 11 additions & 10 deletions sjasm/io_cpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,8 @@ static int SaveCPR(const char* fname, int cprSize) {
return 1;
}

static const char* err_txt_size = "[SAVECPR] only a size from 1 (16KiB) to 32 (512KiB) is allowed";

void dirSAVECPR() {
if (pass != LASTPASS) {
SkipToEol(lp);
Expand All @@ -844,22 +846,21 @@ void dirSAVECPR() {
}
std::unique_ptr<char[]> fnaam(GetOutputFileName(lp));
if (!fnaam[0]) {
Error("[SAVECPR] CPR file name is empty", NULL, SUPPRESS);
return;
Error("[SAVECPR] CPR file name is empty", NULL, SUPPRESS);
return;
}
int cprSize = 32;
if (anyComma(lp)) {
if (SkipBlanks()) Error(err_txt_size, NULL, SUPPRESS); // return will happen on ParseExpression
aint val;
if (ParseExpression(lp, val)) {
if((val < 1) || (val > 32)) {
Error("[SAVECPR] only a size from 1 (16KiB) to 32 (512KiB) is allowed", NULL, SUPPRESS);
return;
}
cprSize = val;
if (!ParseExpression(lp, val)) return;
if ((val < 1) || (val > 32)) {
Error(err_txt_size, NULL, SUPPRESS);
return;
}
cprSize = val;
}
if (!SaveCPR(fnaam.get(), cprSize))
Error("[SAVECPR] Error writing file (Disk full?)", NULL, IF_FIRST);
if (!SaveCPR(fnaam.get(), cprSize)) Error("[SAVECPR] Error writing file (Disk full?)", NULL, IF_FIRST);
}

// eof io_cpc.cpp
11 changes: 11 additions & 0 deletions tests/devices/amstradcpc/savecpr.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
MARK_PAGE MACRO page?
MMU $C000, page?, $C000
DB "page: ", '0' + page? / 10, '0' + page? % 10
ENDM

DEVICE AMSTRADCPCPLUS
DUP 32, page_i
MARK_PAGE page_i
EDUP
SAVECPR "savecpr.cpr" ; default size = 32
SAVECPR "savecpr.bin", 2 ; try also explicit size 2
Binary file added tests/devices/amstradcpc/savecpr.bin.gz
Binary file not shown.
Binary file added tests/devices/amstradcpc/savecpr.cpr.gz
Binary file not shown.
1 change: 1 addition & 0 deletions tests/devices/amstradcpc/savecprCoverage.asm
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
SAVECPR "file.cpr", & ; invalid (parse) page value
SAVECPR "file.cpr", 33 ; page value out of bound
SAVECPR ".", 19 ; fail to open file for write
SAVECPR "file.cpr", ; missing page value suggested by comma
4 changes: 3 additions & 1 deletion tests/devices/amstradcpc/savecprCoverage.lst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ savecprCoverage.asm(12): error: [SAVECPR] only a size from 1 (16KiB) to 32 (512K
12 0000 SAVECPR "file.cpr", 33 ; page value out of bound
savecprCoverage.asm(13): error: [SAVECPR] Error opening file for write: .
13 0000 SAVECPR ".", 19 ; fail to open file for write
14 0000
savecprCoverage.asm(14): error: [SAVECPR] only a size from 1 (16KiB) to 32 (512KiB) is allowed
14 0000 SAVECPR "file.cpr", ; missing page value suggested by comma
15 0000
# file closed: savecprCoverage.asm

Value Label
Expand Down

0 comments on commit 8bbe1f4

Please sign in to comment.