Skip to content

Commit

Permalink
aline with agn453 hitech C
Browse files Browse the repository at this point in the history
  • Loading branch information
tsupplis committed Mar 28, 2022
1 parent 3e7e1d0 commit 363cfce
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 30 deletions.
59 changes: 32 additions & 27 deletions close.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,44 @@
/*
This is a modified version of close.c to support exact file sizes.
Unfortunately there are two common conventions used to record the exact size in CP/M.
Unfortunately there are two common conventions used to record the
exact size in CP/M.
1) Record the bytes used in the last sector - used by DOSPLUS
2) Record the bytes unused in the last sector - used by ISX for ISIS emulation
2) Record the bytes unused in the last sector - used by ISX for
ISIS emulation
A previous version of this file only supported convention 2.
To support both of these variants an environment variable EXACT is used.
Hi-Tech C supports this through the use of a file ENVIRON
The values for EXACT are noted below, but in reality only the first
character is checked.
EXACT=DOSPLUS This uses convention 1 above
EXACT=ISX This uses convention 2 above
if EXACT is not defined or doesn't start with a 'D' or 'I', exact file size
isn't used.
To support both of these variants, a global variable _exact is
set-up by the start-up module.
The values for _exact are noted below
'D' for DOSPLUS This uses convention 1 above
'I' for ISIS/ISX This uses convention 2 above
'C' for CP/M 2 Exact file size is not used
Under CP/M 3 this defaults to 'D' DOSplus mode. If you wish
to use ISIS mode, you must set _exact to 'I' prior to using
file I/O routines - e.g.
Note you need to take extra care in setting EXACT if you are using an emulator
that can access host files and truncates files to match the exact size.
Using the wrong mode will mean that the value this function passes to the emulator
will be wrong and could result in data losss. If in doubt I recommend exact size isn't used.
extern char _exact;
For the ZXCC emulator, using EXACT=DOSPLUS is safe.
_exact = 'I';
Note you need to take extra care with _exact if you are using an
emulator that can access host files and truncates files to match
the exact size. Using the wrong mode will mean that the value
this function passes to the emulator will be wrong and could
result in data losss. If in doubt I recommend exact size isn't used.
For the ZXCC emulator, using _exact as 'D' is safe.
*/

static char exact = 0; /* 0 = not determined, 'C' = not used (old CP/M),
'D' = DOSPLUS mode, 'I' = ISX mode
*/
extern char _exact; /* 'C' = not used (old CP/M),
'D' = DOSPLUS mode, 'I' = ISX mode
*/

char *getenv(char *);
int toupper(int );
Expand All @@ -36,7 +48,6 @@ int close(uchar fd)
{
register struct fcb *fc;
uchar luid;
char *env;

if (fd >= MAXFILE)
return -1;
Expand All @@ -46,14 +57,8 @@ int close(uchar fd)
if (fc->use == U_WRITE || fc->use == U_RDWR
|| bdos(CPMVERS)&(MPM|CCPM) && fc->use == U_READ)
bdos(CPMCLS, fc);
if (!exact) { /* get the exact size mode, checking only once */
if ((env = getenv("EXACT")))
exact = toupper(*env);
if (exact != 'I' && exact != 'D')
exact = 'C';
}
if (exact != 'C') { /* skip if old CP/M mode */
fc->nr = (exact == 'D' ? fc->fsize : -fc->fsize) & 0x7f; /* Set exact file size */
if (_exact != 'C') { /* skip if old CP/M mode */
fc->nr = (_exact == 'D' ? fc->fsize : -fc->fsize) & 0x7f; /* Set exact file size */
fc->name[5] |= 0x80;
if (fc->use == U_WRITE || fc->use == U_RDWR)
bdos(CPMSATT, fc);
Expand Down
17 changes: 17 additions & 0 deletions testver.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "cpm.h"
#include <stdio.h>

extern char _exact; /* exact file size mode */

int main(int argc, char ** argv)
{
int i;
Expand Down Expand Up @@ -49,6 +51,21 @@ int main(int argc, char ** argv)
printf("BIOS Address (0x%04x)\n",*biosaddr-3);
tpa=((*bdosaddr-6)-0x100);
fprintf(stdout,"TPA Size (%u.%uK)\n",tpa/1024,(tpa % 1024)/100);

switch(_exact) {
case 'C':
printf("Exact file size not used (CP/M 2 mode)\n");
break;
case 'D':
printf("Using DOS Plus exact file size mode\n");
break;
case 'I':
printf("Using ISIS exact file size mode\n");
default:
printf("Unknown exact file size mode 0%xH\n",_exact);
break;
}

return 0;
}

9 changes: 7 additions & 2 deletions zcrtcpm.as
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
defs 100h ;Base of CP/M's TPA
global start,_main,_exit,__Hbss, __Lbss, __argc_, __z3env, startup
global __piped,__initrsx, _getenv
global __piped,__initrsx,__exact
start: ; DOS Protection 8080/Z80 x86
; --------- --------------------
Expand Down Expand Up @@ -99,9 +99,12 @@ memok:
xor a ; CP/M 2.2 has no RSX
jr norsx

iscpm3: ld hl,__exact ; Default exact file size
inc (hl) ; to DOSplus mode ('C' becomes 'D')

;If the PIPEMGR RSX is loaded, initialise it.

iscpm3: ld c,60 ; RSX call
ld c,60 ; RSX call
ld de,rsxpb ; RSX data
call 5
ld a,h
Expand Down Expand Up @@ -152,6 +155,8 @@ __z3env:
defw 0
__piped:
defw 0
__exact: ; Exact file size mode
defb 'C',0 ; 'C' is CP/M 2 (none), 'I' is ISIS, 'D' is DOSPLUS
rsxpb: defb 79h,1
defw pipesgn
pipesgn:
Expand Down
4 changes: 3 additions & 1 deletion zrrtcpm.as
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
psect cpm
defs 100h ;Base of CP/M's TPA
global start,_main,_exit,__Lbss,__Hstack, __z3env
global __piped,__initrsx, _getenv
global __piped,__initrsx,__exact
reloc: ; DOS Protection 8080/Z80 x86
Expand Down Expand Up @@ -235,6 +235,8 @@ __z3env:
defw 0
__piped:
defw 0
__exact: ; Exact file size mode
defb 'C',0 ; 'C' is CP/M 2 (none), 'I' is ISIS, 'D' is DOSPLUS
rsxpb: defb 79h,1
defw pipesgn
pipesgn:
Expand Down

0 comments on commit 363cfce

Please sign in to comment.