Compile with wcl386.exe
to use the protected mode wrapper and skip all the DOS memory model junk.
This is the C/C++ compiler I've been using the most lately. It installs pretty cleanly into a virtual directory using DosBox-X.
https://open-watcom.github.io/
export WATCOM=~/Applications/open-watcom-v2/rel export INCLUDE=$WATCOM/h export LIB=$WATCOM/lib286/dos:$WATCOM/lib286 export PATH=$WATCOM/binl64:$WATCOM/binl:$PATH
int myCode(int); #pragma aux myCode = \ "mov eax,ebx" \ value [eax] \ modify [eax] \ parm [ebx]; int main(void) { printf("%d\n", myCode(10)); //=> 10 return 0; }
Labels should start with an alphanumeric character. Starting them with a .
dot won't work.
Compile with wasm
PUBLIC _myCode PUBLIC myData_ .386 .model flat,c .DATA myData_: BYTE 32 .CODE _myCode: push ebp mov ebp, esp mov eax, [ebp + 8] pop ebp ret end
Two object files are linked using wcl386
// main.c extern void __cdecl far interrupt keyboardHandler(); extern char keyboardPressed; void far (interrupt *int9Save)(); int main(void) { int9Save = _dos_getvect(9); _dos_setvect(9, keyboardHandler); while (keyboardPressed == 0) { printf("%d\n", keyboardPressed); } printf("wow\n"); delay(200); _dos_setvect(9, int9Save); return 0; }
; kb.asm PUBLIC _keyboardPressed PUBLIC _keyboardHandler .386 .model flat,c .DATA _keyboardPressed db 0 .CODE _keyboardHandler: cli push eax push ebx in al, 0x60 mov bl, al ; acknowledge keyboard in al, 0x61 mov ah, al or al, 0x80 out 0x61, al xchg ah, al out 0x61, al and bl,0x80 jne _keyboardHandler_notKeydown mov [_keyboardPressed], 1 _keyboardHandler_notKeydown: ; acknowledge interrupt mov al, 0x20 out 0x20, al pop ebx pop eax sti iretd ; needed for 32 bit protected mode