From 0b26c3f18f51c2591b4a90fd5dcfc746a7e3c5a6 Mon Sep 17 00:00:00 2001 From: Bart Oldeman Date: Mon, 18 Dec 2017 13:06:21 -0500 Subject: [PATCH] NLS: clean up to use the struct more and fewer relocations. --- hdr/nls.h | 12 +++--------- hdr/portab.h | 5 +++++ kernel/config.c | 31 ++++++++++++++++++------------- kernel/init-dat.h | 3 +++ kernel/init-mod.h | 4 ++-- 5 files changed, 31 insertions(+), 24 deletions(-) diff --git a/hdr/nls.h b/hdr/nls.h index fda3336..26779ff 100644 --- a/hdr/nls.h +++ b/hdr/nls.h @@ -430,7 +430,8 @@ struct nlsPackage { /* the contents of one chain item of the UWORD yeschar; /* yes / no character DOS-65-23 */ UWORD nochar; unsigned numSubfct; /* number of supported sub-functions */ - struct nlsPointer nlsPointers[1]; /* grows dynamically */ + struct nlsPointer nlsPointers[5]; /* may grow dynamically */ + struct nlsExtCntryInfo nlsExt; }; struct nlsDBCS { /* The internal structure is unknown to me */ @@ -479,14 +480,7 @@ struct nlsInfoBlock { /* This block contains all information }; extern struct nlsInfoBlock ASM nlsInfo; -extern struct nlsPackage FAR ASM nlsPackageHardcoded; - /* These are the "must have" tables within the hard coded NLS pkg */ -extern struct nlsFnamTerm FAR ASM nlsFnameTermHardcoded; -extern struct nlsDBCS FAR ASM nlsDBCSHardcoded; -extern struct nlsCharTbl FAR ASM nlsUpcaseHardcoded; -extern struct nlsCharTbl FAR ASM nlsFUpcaseHardcoded; -extern struct nlsCharTbl FAR ASM nlsCollHardcoded; -extern struct nlsExtCntryInfo FAR ASM nlsCntryInfoHardcoded; +extern struct nlsPackage DOSFAR ASM nlsPackageHardcoded; extern BYTE FAR hcTablesStart[], hcTablesEnd[]; /*********************************************************************** diff --git a/hdr/portab.h b/hdr/portab.h index 1a34d90..25cb76b 100644 --- a/hdr/portab.h +++ b/hdr/portab.h @@ -198,6 +198,11 @@ typedef unsigned size_t; #define ASMCFUNC CDECL #define ASMPASCAL PASCAL #define ASM ASMCFUNC + +/* variables that can be near or far: redefined in init-dat.h */ +#define DOSFAR +#define DOSTEXTFAR + /* */ /* Boolean type & definitions of TRUE and FALSE boolean values */ /* */ diff --git a/kernel/config.c b/kernel/config.c index 59bc1ea..580b896 100644 --- a/kernel/config.c +++ b/kernel/config.c @@ -1511,23 +1511,24 @@ STATIC BOOL LoadCountryInfo(char *filenam, UWORD ctryCode, UWORD codePage) } subf_data; struct subf_tbl { char sig[8]; /* signature for each subfunction data */ - void FAR *p; /* pointer to data in nls_hc.asm to be copied to */ + int idx; /* index of pointer in nls_hc.asm to be copied to */ }; static struct subf_tbl table[8] = { - {"\377 ", NULL}, /* 0, unused */ - {"\377CTYINFO", &nlsCntryInfoHardcoded},/* 1 */ - {"\377UCASE ", &nlsUpcaseHardcoded}, /* 2 */ - {"\377LCASE ", NULL}, /* 3, not supported [yet] */ - {"\377FUCASE ", &nlsFUpcaseHardcoded}, /* 4 */ - {"\377FCHAR ", &nlsFnameTermHardcoded},/* 5 */ - {"\377COLLATE", &nlsCollHardcoded}, /* 6 */ - {"\377DBCS ", &nlsDBCSHardcoded} /* 7, not supported [yet] */ + {"\377 ", -1}, /* 0, unused */ + {"\377CTYINFO", 5}, /* 1 */ + {"\377UCASE ", 0}, /* 2 */ + {"\377LCASE ", -1}, /* 3, not supported [yet] */ + {"\377FUCASE ", 1}, /* 4 */ + {"\377FCHAR ", 2}, /* 5 */ + {"\377COLLATE", 3}, /* 6 */ + {"\377DBCS ", 4} /* 7, not supported [yet] */ }; static struct subf_hdr hdr[8]; static int entries, count; int fd, i; char *filename = filenam == NULL ? "\\COUNTRY.SYS" : filenam; BOOL rc = FALSE; + BYTE FAR *ptable; if ((fd = open(filename, 0)) < 0) { @@ -1586,25 +1587,29 @@ err:printf("%s has invalid format\n", filename); subf_data.length = /* MS-DOS "CTYINFO" is up to 38 bytes */ min(subf_data.length, sizeof(struct CountrySpecificInfo)); } + if (hdr[i].id == 1) + ptable = (BYTE FAR *)&nlsPackageHardcoded.nlsExt.size; + else + ptable = nlsPackageHardcoded.nlsPointers[table[hdr[i].id].idx].pointer; if (hdr[i].id == 7) { if (subf_data.length == 0) { /* if DBCS table (in country.sys) is empty, clear internal table */ *(DWORD *)(subf_data.buffer) = 0L; - fmemcpy((BYTE FAR *)(table[hdr[i].id].p), subf_data.buffer, 4); + fmemcpy(ptable, subf_data.buffer, 4); } else { - fmemcpy((BYTE FAR *)(table[hdr[i].id].p) + 2, subf_data.buffer, subf_data.length); + fmemcpy(ptable + 2, subf_data.buffer, subf_data.length); /* write length */ *(UWORD *)(subf_data.buffer) = subf_data.length; - fmemcpy((BYTE FAR *)(table[hdr[i].id].p), subf_data.buffer, 2); + fmemcpy(ptable, subf_data.buffer, 2); } continue; } - fmemcpy((BYTE FAR *)(table[hdr[i].id].p) + 2, subf_data.buffer, + fmemcpy(ptable + 2, subf_data.buffer, /* skip length ^*/ subf_data.length); } rc = TRUE; diff --git a/kernel/init-dat.h b/kernel/init-dat.h index cda5e05..1e4960b 100644 --- a/kernel/init-dat.h +++ b/kernel/init-dat.h @@ -1,3 +1,6 @@ +#undef DOSFAR +#undef DOSTEXTFAR + /* Included by initialisation functions */ #if _MSC_VER != 0 diff --git a/kernel/init-mod.h b/kernel/init-mod.h index cd506da..8e60e2c 100644 --- a/kernel/init-mod.h +++ b/kernel/init-mod.h @@ -16,12 +16,12 @@ #include "tail.h" #include "process.h" #include "pcb.h" -#include "nls.h" #include "buffer.h" #include "dcb.h" #include "lol.h" #include "init-dat.h" +#include "nls.h" #include "kconfig.h" @@ -275,7 +275,7 @@ extern struct { struct CountrySpecificInfo C; -} FAR ASM nlsCountryInfoHardcoded; +} DOSFAR ASM nlsCountryInfoHardcoded; /* data shared between DSK.C and INITDISK.C