Skip to content

Commit 58f79db

Browse files
committed
build updates so Watcom compiled version runs
WARNING! TSR functionality may not be fully functional, memory usage not validated (may use too much or free too much when goes resident)
1 parent 6a735ba commit 58f79db

File tree

4 files changed

+103
-44
lines changed

4 files changed

+103
-44
lines changed

build.bat

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ set CC=wcc
5454
set LD=wlink
5555
5656
set LDFLAGS=system com name share.com file share,kitten,tnyprntf,amishelp option quiet,map,statics,verbose,artificial,symfile
57-
set CFLAGS=-I..\kitten -I..\tnyprntf -q -0 -ms -btdos -os -fo=
57+
::set LDFLAGS=system dos name share.com file share,kitten,tnyprntf,amishelp option quiet,map,statics,verbose,artificial,symfile
58+
set CFLAGS=-I..\kitten -I..\tnyprntf -q -0 -ms -btdos -s -os -d3 -fo=
59+
set ASMFLAGS=-D__WATCOM__
5860
set EXTRA_OBJS=amishelp.obj
5961
goto doit
6062

@@ -77,6 +79,7 @@ rem if you use UPX: then options are
7779
rem --8086 for 8086 compatibility
7880
rem or
7981
rem --best for smallest
82+
::set UPXARGS=-rem
8083

8184
rem We use GNU make for all targets
8285
%MAKE% -C src
@@ -88,6 +91,7 @@ set MAKE=
8891
set BASEPATH=
8992
set CC=
9093
set CFLAGS=
94+
set ASMFLAGS=
9195
set LD=
9296
set LDFLAGS=
9397
set EXTRA_OBJS=

src/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ share.obj: share.c
2222
$(CC) $(CFLAGS)$@ $^
2323

2424
ifeq "$(COMPILER)" "gcc"
25-
amishelp.obj: amishelp.asm
25+
amishelp.obj: amishelp.asm amis.mac
2626
nasm -f elf -I ../lmacros/ -I lmacros/ $< -o $@
2727
else
28-
amishelp.obj: amishelp.asm
29-
nasm -f obj -I ../lmacros/ -I lmacros/ $< -o $@
28+
amishelp.obj: amishelp.asm amis.mac
29+
nasm -f obj -I ../lmacros/ -I lmacros/ $(ASMFLAGS) $< -o $@
3030

3131
kitten.obj: ..\kitten\kitten.c
3232
$(CC) $(CFLAGS)$@ $^

src/amishelp.asm

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@ bits 16
44

55
cpu 8086
66

7+
8+
%ifdef __WATCOM__
9+
group DGROUP _TEXT _DATA _TEXT_STARTUP _BSS _bss_startup
10+
section _TEXT CLASS=CODE
11+
section _DATA class=DATA
12+
section _TEXT_STARTUP CLASS=CODE
13+
section _BSS class=BSS
14+
%else
715
section .bss
16+
%endif
17+
818

919
global iregs
1020
iregs:
@@ -34,7 +44,11 @@ old_ss:
3444
old_sp:
3545
resw 1
3646

47+
%ifdef __WATCOM__
48+
section _TEXT
49+
%else
3750
section .text
51+
%endif
3852

3953

4054
%if 0
@@ -185,14 +199,26 @@ ctrl1:
185199

186200

187201
%if _SUPPORTGENERALUNINSTALLER
188-
section .text
202+
%ifdef __WATCOM__
203+
section _TEXT
204+
%else
205+
section .text
206+
%endif
189207
%else
190-
section .data.startup
208+
%ifdef __WATCOM__
209+
section _DATA
210+
%else
211+
section .data.startup
212+
%endif
191213
%endif
192214
sft_size: dw 0
193215

194216

217+
%ifdef __WATCOM__
218+
section _TEXT
219+
%else
195220
section .text
221+
%endif
196222

197223
i2D.uninstall:
198224
%if _SUPPORTGENERALUNINSTALLER
@@ -304,7 +330,12 @@ amisnum equ $-1 ; AMIS multiplex number (data for cmp opcode)
304330
jmp short .iret_dx_cs
305331

306332

333+
%ifdef __WATCOM__
334+
section _TEXT_STARTUP
335+
%else
307336
section .text.startup
337+
%endif
338+
308339

309340
global asm_find_resident
310341
asm_find_resident:
@@ -1140,13 +1171,21 @@ SearchIISPChain:
11401171
retn
11411172

11421173

1174+
%ifdef __WATCOM__
1175+
section _DATA
1176+
%else
11431177
section .data.startup
1178+
%endif
11441179
align 2, db 0
11451180
debuggeramissig:
11461181
.ven: fill 8,32,db "ecm" ; vendor
11471182
.prod: fill 8,32,db "lDebug" ; product
11481183

1184+
%ifdef __WATCOM__
1185+
section _bss_startup nobits class DATA
1186+
%else
11491187
section .bss.startup nobits
1188+
%endif
11501189
alignb 2
11511190
debuggerfunction:
11521191
resw 1 ; = 0 if unused
@@ -1158,7 +1197,11 @@ End of C. Masloch TSR example code
11581197
%endif
11591198

11601199

1200+
%ifdef __WATCOM__
1201+
section _TEXT
1202+
%else
11611203
section .text
1204+
%endif
11621205

11631206
extern inner_handler
11641207

@@ -1353,9 +1396,17 @@ seq_setting:
13531396

13541397

13551398
%if _SUPPORTGENERALUNINSTALLER
1356-
section .text
1399+
%ifdef __WATCOM__
1400+
section _TEXT
1401+
%else
1402+
section .text
1403+
%endif
13571404
%else
1358-
section .text.startup
1405+
%ifdef __WATCOM__
1406+
section _TEXT_STARTUP
1407+
%else
1408+
section .text.startup
1409+
%endif
13591410
%endif
13601411

13611412
clear_sft_shroff:

src/share.c

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#if defined(__TURBOC__) || (__WATCOMC__)
1515
#include <io.h> /* write (what else?) */
1616
#include <stdlib.h> /* _psp, NULL, malloc, free, atol */
17+
#include <stdio.h> /* printf */
1718
#define NON_RES_TEXT
1819
#define NON_RES_DATA
1920
#define NON_RES_RODATA
@@ -22,6 +23,7 @@ typedef unsigned char uint8_t;
2223
typedef unsigned short uint16_t;
2324

2425
#if (__WATCOMC__)
26+
#pragma pack (1) /* structures are packed */
2527
//void far * getvect(unsigned char intno);
2628
//void setvect(unsigned char intno, void far * vector);
2729
#define getvect(x) _dos_getvect(x)
@@ -182,11 +184,15 @@ static char progname[9] NON_RES_BSS;
182184
#pragma aux old_handler2f "*"
183185
#pragma aux handler2f "*"
184186

185-
/* same as __cdecl except don't preceed with _ underscore */
187+
/* gcc-ia16 version of __cdecl, similar to OW except don't preceed with _ underscore & doesn't modify __es
188+
__caller [] -- all arguments are passed on the stack, caller pops off on return
189+
__value ... -- return result in __ax
190+
__modify [__ax __bx __cx __dx] -- may be modified, all other registers unchanged
191+
*/
186192
#pragma aux __gcc16 "*" \
187193
__parm __caller [] \
188194
__value __struct __float __struct __routine [__ax] \
189-
__modify [__ax __bx __cx __dx __es]
195+
__modify [__ax __bx __cx __dx]
190196
#pragma aux (__gcc16) inner_handler
191197

192198
#endif
@@ -200,9 +206,16 @@ extern uint16_t lock_table_size_bytes; /* amount bytes */
200206
extern uint16_t lock_table_free;
201207
extern uint16_t lock_table_offset;
202208
#else
203-
static unsigned int file_table_size_bytes NON_RES_DATA = 2048;
204209
uint16_t file_table_size = 0; /* # of file_t we can have */
205210
uint16_t lock_table_size = 20; /* # of lock_t we can have */
211+
212+
uint16_t file_table_size_bytes; /* amount bytes */
213+
uint16_t file_table_free;
214+
uint16_t file_table_offset;
215+
uint16_t lock_table_size_bytes; /* amount bytes */
216+
uint16_t lock_table_free;
217+
uint16_t lock_table_offset;
218+
206219
#endif
207220
static file_t *file_table = NULL;
208221
static lock_t *lock_table = NULL;
@@ -733,50 +746,37 @@ static int is_file_open(char far *filename)
733746
unsigned short init_tables(void) {
734747
unsigned short paras;
735748
char far *fptr;
736-
#if defined(__TURBOC__)
737-
char *onebyte;
749+
char *p;
738750

739751
file_table_size = file_table_size_bytes / sizeof(file_t);
740-
if ((file_table = malloc(file_table_size_bytes)) == NULL)
741-
return 0;
742-
memset(file_table, 0, file_table_size_bytes);
752+
lock_table_size_bytes = lock_table_size * sizeof(lock_t);
753+
file_table_free = file_table_size;
754+
lock_table_free = lock_table_size;
743755

744-
if ((lock_table = malloc(lock_table_size * sizeof(lock_t))) == NULL) {
745-
free(file_table);
746-
file_table = NULL;
756+
if ((p = malloc(file_table_size_bytes + lock_table_size_bytes)) == NULL)
747757
return 0;
748-
}
749-
memset(lock_table, 0, lock_table_size * sizeof(lock_t));
758+
memset(p, 0, file_table_size_bytes + lock_table_size_bytes);
759+
760+
file_table = (void *)p;
761+
lock_table = (void *)(p + file_table_size_bytes);
762+
763+
#if defined(__TURBOC__)
764+
{
765+
char *onebyte;
750766

751767
/* Allocate a single byte. This tells us the size of the TSR.
752768
Free the byte when we know the address. */
753769
onebyte = malloc(1);
754770
if (onebyte == NULL) {
755-
free(file_table);
771+
free(p);
756772
file_table = NULL;
757-
free(lock_table);
758773
lock_table = NULL;
759774
return 0;
760775
}
761776
fptr = (char far *)onebyte;
762777
free(onebyte);
763-
778+
}
764779
#else /* GNUC */
765-
char *p;
766-
767-
file_table_size = file_table_size_bytes / sizeof(file_t);
768-
lock_table_size_bytes = lock_table_size * sizeof(lock_t);
769-
file_table_free = file_table_size;
770-
lock_table_free = lock_table_size;
771-
772-
p = sbrk(file_table_size_bytes + lock_table_size_bytes);
773-
if (p == (void *)-1)
774-
return 0;
775-
776-
// No need to memset() as sbrk() does it for us
777-
778-
file_table = (void *)p;
779-
lock_table = (void *)(p + file_table_size_bytes);
780780
file_table_offset = (uint16_t)file_table;
781781
lock_table_offset = (uint16_t)lock_table;
782782

@@ -945,9 +945,7 @@ int main(int argc, char **argv) {
945945
int i;
946946
uint8_t ii;
947947

948-
#if defined(__GNUC__) || defined(__WATCOMC__)
949948
file_table_size_bytes = 2048;
950-
#endif
951949

952950
cat = catopen("share", 0);
953951

@@ -1212,16 +1210,22 @@ int main(int argc, char **argv) {
12121210
/* Hook the interrupt for the handler routine. */
12131211
/* disable(); */
12141212
i2D_next = getvect(0x2D);
1215-
setvect(0x2D, i2D_handler); /* TODO this causes relocation on TC & OW */
1213+
#if defined(__WATCOMC__)
1214+
printf("cs=ds=_psp=%04x : i2D_handler=%04x\n", _psp, FP_OFF((void near *)i2D_handler));
1215+
/* Note: in tiny memory model, _psp == cs == ds */
1216+
setvect(0x2D, MK_FP(_psp, FP_OFF((void near *)i2D_handler)));
1217+
#else
1218+
setvect(0x2D, i2D_handler); /* this causes relocation on TC & OW */
1219+
#endif
12161220
#endif
12171221
old_handler2f = getvect(MUX_INT_NO);
1218-
#if defined(__TURBOC__) && (__TURBOC__ >= 0x0300)
1222+
#if (defined(__TURBOC__) && (__TURBOC__ >= 0x0300))
12191223
{
12201224
void (near *isr)() = FP_OFF(handler2f);
12211225
setvect(MUX_INT_NO,(void (interrupt far *)())MK_FP(_DS,isr));
12221226
}
12231227
#elif defined(__WATCOMC__)
1224-
setvect(MUX_INT_NO,handler2f); // TODO get handler2f without relocation
1228+
setvect(MUX_INT_NO,MK_FP(_psp, FP_OFF((void near *)handler2f)));
12251229
#else /* causes relocations when built with Turbo C/C++ 3 and OW */
12261230
setvect(MUX_INT_NO,handler2f);
12271231
#endif

0 commit comments

Comments
 (0)