Skip to content

Commit 2e4fcf7

Browse files
committed
build (and works) with Open Watcom or Borland/Turbo C/C++
1 parent 0ceb5da commit 2e4fcf7

File tree

16 files changed

+542
-230
lines changed

16 files changed

+542
-230
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
*.sym
2+
*.lst
3+
*.com

src/amishelp.asm

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
%if 0 ; based on:
77

8-
Resident code of TSR example
8+
Transient code of TSR example
99
2020 by C. Masloch
1010

1111
Usage of the works is permitted provided that this
@@ -62,8 +62,8 @@ s.text
6262

6363
; uint16_t impx_install_check(uint16_t multiplex_no, uint16_t multiplex_id) NON_RES_TEXT;
6464
; for int 0x2f and 0x2d install check, al=0, ah=id
65-
global impx_install_check
66-
impx_install_check:
65+
global _impx_install_check
66+
_impx_install_check:
6767

6868
lframe near
6969
lpar word, mpx_id
@@ -98,8 +98,8 @@ cleanup:
9898
retn
9999

100100

101-
global asm_find_resident
102-
asm_find_resident:
101+
global _asm_find_resident
102+
_asm_find_resident:
103103
push ds
104104
push es
105105
push si
@@ -176,8 +176,8 @@ ssReserved: resb 4
176176
endstruc
177177

178178

179-
global asm_get_status
180-
asm_get_status:
179+
global _asm_get_status
180+
_asm_get_status:
181181
lframe near
182182
lpar word, struct
183183
lpar word, mpx
@@ -257,8 +257,8 @@ asm_get_status:
257257
lret
258258

259259

260-
global asm_enable
261-
asm_enable:
260+
global _asm_enable
261+
_asm_enable:
262262

263263
lframe near
264264
lpar word, mpx
@@ -314,8 +314,8 @@ asm_enable:
314314
retn
315315

316316

317-
global asm_disable
318-
asm_disable:
317+
global _asm_disable
318+
_asm_disable:
319319

320320
lframe near
321321
lpar word, mpx
@@ -416,8 +416,8 @@ zero_out_data:
416416
retn
417417

418418

419-
global asm_uninstall
420-
asm_uninstall:
419+
global _asm_uninstall
420+
_asm_uninstall:
421421

422422
uninstall:
423423
push ds
@@ -594,8 +594,8 @@ unhookerrorcritical:
594594
lleave ctx
595595

596596

597-
global asm_init
598-
asm_init:
597+
global _asm_init
598+
_asm_init:
599599
push ds
600600
push es
601601
push si

src/amisstub.asm

Lines changed: 68 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ OUT: al = 00h
115115

116116
s.data.resident
117117

118-
global iregs
119-
iregs:
118+
global _iregs
119+
_iregs:
120120
.bp: resw 1
121121
.di: resw 1
122122
.si: resw 1
@@ -130,12 +130,12 @@ iregs:
130130
.cs: resw 1
131131
.flags: resw 1 ; (not used by us)
132132

133-
global need_to_chain
134-
need_to_chain:
133+
global _need_to_chain
134+
_need_to_chain:
135135
resw 1
136136

137-
global top_of_stack
138-
top_of_stack:
137+
global _top_of_stack
138+
_top_of_stack:
139139
resw 1
140140

141141
old_ss:
@@ -165,34 +165,34 @@ amisintr: ; AMIS list of hooked interrupts, 2Dh marks end of list
165165

166166
; These variables are used as globals
167167
; by the C code. Each is an uint16_t.
168-
global file_table_size
169-
global file_table_size_bytes
170-
global file_table_free
171-
global file_table ;_offset
172-
global lock_table_size
173-
global lock_table_size_bytes
174-
global lock_table_free
175-
global lock_table ;_offset
168+
global _file_table_size
169+
global _file_table_size_bytes
170+
global _file_table_free
171+
global _file_table ;_offset
172+
global _lock_table_size
173+
global _lock_table_size_bytes
174+
global _lock_table_free
175+
global _lock_table ;_offset
176176

177177
extern _end_resident
178178

179179

180180
align 2, db 0
181181
ctrl2:
182-
file_table_size: dw 0
183-
file_table_free: dw 0
184-
lock_table_size: dw 20
185-
lock_table_free: dw 20
182+
_file_table_size: dw 0
183+
_file_table_free: dw 0
184+
_lock_table_size: dw 20
185+
_lock_table_free: dw 20
186186
ctrl2.end:
187187

188188
align 2, db 0
189189
ctrl3:
190-
file_table:
191-
file_table_offset: dw OFFSET _end_resident ; WARNING: this will overwrite startup/transient code
192-
file_table_size_bytes: dw 0
193-
lock_table:
194-
lock_table_offset: dw 0
195-
lock_table_size_bytes: dw 0
190+
_file_table:
191+
_file_table_offset: dw OFFSET _end_resident ; WARNING: this will overwrite startup/transient code
192+
_file_table_size_bytes: dw 0
193+
_lock_table:
194+
_lock_table_offset: dw 0
195+
_lock_table_size_bytes: dw 0
196196
ctrl3.end:
197197

198198
ctrl1:
@@ -246,8 +246,8 @@ s.text.resident
246246

247247
; invoke DOS critical error handler for given drive & error code
248248
; void critical_error(uint16_t error_code, uint16_t drive) __gcc16;
249-
global critical_error
250-
critical_error:
249+
global _critical_error
250+
_critical_error:
251251

252252
lframe near
253253
lpar word, error_code
@@ -265,7 +265,7 @@ critical_error:
265265

266266
i2D.uninstall:
267267
%if _SUPPORTGENERALUNINSTALLER
268-
mov al, 04h ; safe to remove, no resident uninstaller,
268+
mov al, 04h ; safe to remove, no resident uninstaller,
269269
; TSR now disabled
270270
push es
271271
push ds
@@ -315,23 +315,23 @@ i2D.hwreset equ $-1 ; (second byte of mov bx, cs is same as the retf opcode)
315315
sub bx, 10h ; memory block to dealloc is PSP, so subtract sizeof(PSP) from CS
316316
iret
317317

318-
global i2D_handler
319-
global i2D_next
320-
i2D_handler equ i2D
321-
i2D_next equ i2D.next
318+
global _i2D_handler
319+
global _i2D_next
320+
_i2D_handler equ i2D
321+
_i2D_next equ i2D.next
322322

323323
iispentry i2D, 0, i2D
324324
cmp ah, 0
325-
global amisnum
326-
amisnum equ $-1 ; AMIS multiplex number (data for cmp opcode)
327-
je .handle ; our multiplex number -->
328-
jmp far [cs:.next] ; else go to next handler -->
325+
global _amisnum
326+
_amisnum equ $-1 ; AMIS multiplex number (data for cmp opcode)
327+
je .handle ; our multiplex number -->
328+
jmp far [cs:.next] ; else go to next handler -->
329329

330330
.handle:
331331
test al, al
332332
jz .installationcheck ; installation check -->
333333
cmp al, 02h
334-
je .uninstall ; uninstallation -->
334+
je .uninstall ; uninstallation -->
335335
cmp al, 04h
336336
je .determineinterrupts ; determine hooked interrupts -->
337337
cmp al, 21h
@@ -342,20 +342,20 @@ amisnum equ $-1 ; AMIS multiplex number (data for cmp opcode)
342342
je .ctrl3
343343
; all other functions are reserved or not supported by TSR
344344
.nop:
345-
mov al, 0 ; show not implemented
345+
mov al, 0 ; show not implemented
346346
iret
347347

348348
.installationcheck:
349-
dec al ; (= FFh) show we're here
350-
mov cx, 10Ah ; = version
351-
mov di, amissig ; dx:di -> AMIS signature strings of this program
349+
dec al ; (= FFh) show we're here
350+
mov cx, 10Ah ; = version
351+
mov di, amissig ; dx:di -> AMIS signature strings of this program
352352
.iret_dx_cs:
353353
mov dx, cs
354354
.iret:
355355
iret
356356

357357
.determineinterrupts: ; al = 04h, always returns list
358-
mov bx, amisintr ; dx:bx -> hooked interrupts list
358+
mov bx, amisintr ; dx:bx -> hooked interrupts list
359359
jmp short .iret_dx_cs
360360

361361
.ctrl1:
@@ -385,12 +385,12 @@ End of C. Masloch TSR example code
385385

386386
s.text.resident
387387

388-
extern inner_handler
388+
extern _(inner_handler)
389389

390-
global handler2f
391-
global old_handler2f
392-
handler2f equ i2F
393-
old_handler2f equ i2F.next
390+
global _handler2f
391+
global _old_handler2f
392+
_handler2f equ i2F
393+
_old_handler2f equ i2F.next
394394

395395
; IBM Interrupt Sharing Protocol header
396396
iispentry i2F, 0 ; *** can use i2D for 3rd argument but exceeds jmp short
@@ -422,17 +422,17 @@ iispentry i2F, 0 ; *** can use i2D for 3rd argument but exceeds jmp short
422422
.enter_c_handler:
423423

424424
; save the input DS
425-
pop word [iregs.ds]
425+
pop word [_iregs.ds]
426426

427427
; save regs
428-
mov [iregs.bp], BP
429-
mov [iregs.di], DI
430-
mov [iregs.si], SI
431-
mov [iregs.es], ES
432-
mov [iregs.dx], DX
433-
mov [iregs.cx], CX
434-
mov [iregs.bx], BX
435-
mov [iregs.ax], AX
428+
mov [_iregs.bp], BP
429+
mov [_iregs.di], DI
430+
mov [_iregs.si], SI
431+
mov [_iregs.es], ES
432+
mov [_iregs.dx], DX
433+
mov [_iregs.cx], CX
434+
mov [_iregs.bx], BX
435+
mov [_iregs.ax], AX
436436
; don't need IP or CS or flags
437437
; (flags weren't ever read or written,
438438
; and setting flags before iret is pointless.
@@ -444,27 +444,27 @@ iispentry i2F, 0 ; *** can use i2D for 3rd argument but exceeds jmp short
444444
mov [old_sp], SP
445445
push CS
446446
pop SS
447-
mov SP, [top_of_stack]
447+
mov SP, [_top_of_stack]
448448

449449
; insure UP (Direction Flag = 0) for our C code
450450
cld
451451

452452
; call our handler
453-
call inner_handler
453+
call _(inner_handler)
454454

455455
; restore stack
456456
mov SS, [old_ss]
457457
mov SP, [old_sp]
458458

459459
; restore register input values
460-
mov BP, [iregs.bp]
461-
mov DI, [iregs.di]
462-
mov SI, [iregs.si]
463-
mov ES, [iregs.es]
464-
mov DX, [iregs.dx]
465-
mov CX, [iregs.cx]
466-
mov BX, [iregs.bx]
467-
mov AX, [iregs.ax]
460+
mov BP, [_iregs.bp]
461+
mov DI, [_iregs.di]
462+
mov SI, [_iregs.si]
463+
mov ES, [_iregs.es]
464+
mov DX, [_iregs.dx]
465+
mov CX, [_iregs.cx]
466+
mov BX, [_iregs.bx]
467+
mov AX, [_iregs.ax]
468468

469469
; Although this is a 16-bit variable it is
470470
; valid to check only the low 8 bits as
@@ -473,18 +473,18 @@ iispentry i2F, 0 ; *** can use i2D for 3rd argument but exceeds jmp short
473473
; the jnz. This is a small optimisation to
474474
; avoid a cs override prefix. The Zero Flag
475475
; is unaffected by the mov.
476-
cmp byte [need_to_chain], 0
476+
cmp byte [_need_to_chain], 0
477477

478478
; restore caller's DS
479-
mov DS, [iregs.ds]
479+
mov DS, [_iregs.ds]
480480

481481
; return from interrupt if we handled it
482482
jnz .run_old
483483
iret
484484

485485
.run_old:
486486
; jump to old handler that will iret
487-
jmp far [CS:old_handler2f]
487+
jmp far [CS:_old_handler2f]
488488

489489

490490
numdef CMPSTR, 1

src/buildbcc.bat

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@REM builds updated share
2+
::set LDFLAGS=/m /s /c /t %BASEPATH%\lib\c0t.obj $(EXTRA_OBJS) share.obj,share.com,,%BASEPATH%\lib\cs.lib
3+
::set CFLAGS=-I../kitten -I../tnyprntf -I%BASEPATH%/include -mt -1 -c -o
4+
@:: -q quiet, -1- 8086 / -1 80186 instructions -mt tiny memmodel CS=DS=SS and DOS exe, -Fs force SS=DS -N- no stack checks -v debug info -c compile only -o= name of obj file -I include dir -zl no default lib
5+
@:: -S list file with asm (-s not supported with BC5), -Os optmize for size (default), -u- disable underscores, -X no default libs?
6+
@:: -zPDGROUP code (_TEXT) is part of DGROUP (cs=ds)
7+
8+
nasm -f obj -g -D__TURBOC__ startup.asm -o startup.obj
9+
nasm -f obj -g -I ../lmacros/ -D__TURBOC__ amisstub.asm -o amisstub.obj
10+
bcc -1- -mt -Os -Fs -N- -v -zPDGROUP -c -osharetsr.obj sharetsr.c
11+
nasm -f obj -g -D__TURBOC__ dossup.asm -o dossup.obj
12+
bcc -1- -mt -Os -Fs -N- -v -zPDGROUP -c -oclib.obj clib.c
13+
nasm -f obj -g -I ../lmacros/ -D__TURBOC__ amishelp.asm -o amishelp.obj
14+
bcc -1- -mt -Os -Fs -N- -v -zPDGROUP -c -oshareprg.obj shareprg.c
15+
bcc -1- -mt -Os -Fs -N- -v -zPDGROUP -c -otnyprntf.obj -I..\tnyprntf ..\tnyprntf\tnyprntf.c
16+
bcc -1- -mt -Os -Fs -N- -v -zPDGROUP -c -okitten.obj -I..\kitten ..\kitten\kitten.c
17+
bcc -1- -mt -Os -Fs -N- -v -zPDGROUP -I..\kitten -I..\tnyprntf -c -osharemsg.obj sharemsg.c
18+
@rem nasm -f obj -g -D__TURBOC__ messages.asm -o messages.obj
19+
::#LINK obj[,out[,map[,lib[,def[,res]]]]]
20+
tlink @share.cfg

src/buildme.bat

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
@REM builds updated share
2+
@:: -q quiet, -0 8086 instructions -ms small memmodel -btdos DOS exe, -s no stack checks -os optimize smaller code, -d3 max debug info -fo= name of obj file -I include dir -zl no default lib
23
nasm -f obj -g -D__WATCOM__ startup.asm -o startup.obj
3-
nasm -f obj -g -I ../lmacros/ -D__WATCOM__ amisstub.asm -o amisstub.obj
4+
nasm -f obj -g -l amisstub.lst -Lf -I ../lmacros/ -D__WATCOM__ amisstub.asm -o amisstub.obj
45
wcc -q -0 -ms -btdos -s -os -d3 -fo=sharetsr.obj sharetsr.c
5-
nasm -f obj -g -D__WATCOM__ dossup.asm -o dossup.obj
6+
nasm -f obj -g -l dossup.lst -D__WATCOM__ dossup.asm -o dossup.obj
67
wcc -q -0 -ms -btdos -s -os -d3 -fo=clib.obj clib.c
78
nasm -f obj -g -I ../lmacros/ -D__WATCOM__ amishelp.asm -o amishelp.obj
89
wcc -q -0 -ms -btdos -s -os -d3 -fo=shareprg.obj shareprg.c

src/clib.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ extern char * _heap;
1515
extern char * _environ;
1616
extern char sstack;
1717

18+
#ifdef __TURBOC__
19+
/* external reference created by Borland compiler when using int main(int argc, char **argv){} */
20+
void _setargv__() { }
21+
#endif
22+
1823

1924
void *malloc(size_t size)
2025
{

0 commit comments

Comments
 (0)