Skip to content

Commit bc1d6c4

Browse files
committed
fix int32 function 8, used by watcom getch()
1 parent 79c6eb1 commit bc1d6c4

File tree

3 files changed

+99
-53
lines changed

3 files changed

+99
-53
lines changed

ntvdm.cxx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ uint64_t int21_1_code[] = {
105105
0x10690ab4166900b4, 0x0000000000cb01b4,
106106
};
107107
uint64_t int21_8_code[] = {
108-
0x00cb08b416cd00b4,
108+
0xb4c08e0040b85306, 0x8b26fafa74166901, 0x00d03e8026001a1e, 0x2601478a260d7400, 0x9011eb0000d006c6, 0x260975003c078a26, 0x9016eb0100d006c6, 0x832602001a068326,
109+
0xc726077c3e001a3e, 0x08b4fb001e001a06, 0x0000000000cb075b,
109110
};
110111
uint64_t int21_a_code[] = {
111112
0x000144c6f28b5653, 0xcd01b43674003c80, 0x3c16cd00b4fa7416, 0x7400017c800c7508, 0x339010eb014cfeec, 0x3c024088015c8adb, 0xd08a0144fe10740d, 0x3a01448a21cd02b4,
@@ -120,7 +121,7 @@ uint64_t int21_3f_code[] = {
120121
0x0000000000000000,
121122
};
122123
// end of machine code
123-
124+
124125
uint16_t AllocateEnvironment( uint16_t segStartingEnv, const char * pathToExecute, const char * pcmdLineEnv );
125126
uint16_t LoadBinary( const char * app, const char * acAppArgs, uint16_t segment, bool setupRegs,
126127
uint16_t * reg_ss, uint16_t * reg_sp, uint16_t * reg_cs, uint16_t * reg_ip, bool bootSectorLoad );
@@ -4245,9 +4246,9 @@ void handle_int_16( uint8_t c )
42454246
}
42464247

42474248
if ( cpu.get_zero() )
4248-
tracer.Trace( " returning carry flag 1; no character available\n" );
4249+
tracer.Trace( " returning zero flag true; no character available\n" );
42494250
else
4250-
tracer.Trace( " returning carry flag %d, ax %04x, ascii '%c'\n", cpu.get_zero(), cpu.get_ax(), printable( cpu.al() ) );
4251+
tracer.Trace( " returning zero flag false; char available, ax %04x, ascii '%c'\n", cpu.get_ax(), printable( cpu.al() ) );
42514252
return;
42524253
}
42534254
case 2:
@@ -8727,6 +8728,7 @@ int main( int argc, char * argv[] )
87278728
* (uint8_t *) ( pbiosdata + 0x88 ) = 9; // ega feature bits
87288729
* (uint8_t *) ( pbiosdata + 0x89 ) = 0x51; // video display area (400 line mode, vga active)
87298730
* (uint8_t *) ( pbiosdata + 0x8a ) = 0x8; // 2 == CGA color, 8 == VGA color
8731+
* (uint8_t *) ( pbiosdata + 0xd0 ) = 0; // for int 21/8: 1 if consumed ascii and scancode is next.
87308732
* (uint8_t *) ( pbiosdata + 0x10f ) = 0; // where GWBASIC checks if it's in a shelled command.com.
87318733
* (uint8_t *) ( cpu.flat_address8( 0xf000, 0xfff0 ) ) = 0xea; // power on entry point (used by mulisp to detect if it's a standard PC) ea = jmp far
87328734
* (uint8_t *) ( cpu.flat_address8( 0xf000, 0xfff1 ) ) = 0xc0; // "

tasm/asm.txt

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
// machine code for various interrupts. generated with mint.bat.
2-
uint64_t int16_0_code[] = {
3-
0x01b4c08e0040b806, 0x068326fafa741669, 0x001a3e832602001a, 0x001a06c726077c3e, 0x000000cb07fb001e,
4-
};
5-
uint64_t int21_1_code[] = {
6-
0x10690ab4166900b4, 0x0000000000cb01b4,
7-
};
8-
uint64_t int21_8_code[] = {
9-
0x00cb08b416cd00b4,
10-
};
11-
uint64_t int21_a_code[] = {
12-
0x000144c6f28b5653, 0xcd01b43674003c80, 0x3c16cd00b4fa7416, 0x7400017c800c7508, 0x339010eb014cfeec, 0x3c024088015c8adb, 0xd08a0144fe10740d, 0x3a01448a21cd02b4,
13-
0x00cb5b5ef8ca7504,
14-
};
15-
uint64_t int21_3f_code[] = {
16-
0x00f1bf5657525153, 0x0000eb06c72ef28b, 0xc5e9037500f98300, 0x50b9037e50f98300, 0xa12e00e90e892e00, 0x7c00ef063b2e00ed, 0xb4fa7416cd01b46d, 0x00e93e832e16cd00,
17-
0x2e1075083c147401, 0x2ee2740000ef3e83, 0x2e901eeb00ef0eff, 0x2e01882e00ef1e8b, 0x22740d3c00ef06ff, 0xe93e832e0875083c, 0x02b4d08a06740100, 0x3b2e00efa12e21cd,
18-
0x004f3d197400e906, 0x2e00ef1e8b2ea775, 0x00ef06ff2e0a01c6, 0x8b2e21cd02b40ab2, 0x8b2e018b2e00ed1e, 0x06ff2e008900eb1e, 0x2e00ed06ff2e00eb, 0x00ef063b2e00eda1,
19-
0x0000ed06c72e1175, 0x000000ef06c72e00, 0x2e00e9a12e900ceb, 0xa12ec07500eb063b, 0x5b595a5f5ef800eb, 0x00000000000000cb, 0x0000000000000000, 0x0000000000000000,
20-
0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
21-
0x0000000000000000,
22-
};
23-
// end of machine code
24-
1+
// machine code for various interrupts. generated with mint.bat.
2+
uint64_t int16_0_code[] = {
3+
0x01b4c08e0040b806, 0x068326fafa741669, 0x001a3e832602001a, 0x001a06c726077c3e, 0x000000cb07fb001e,
4+
};
5+
uint64_t int21_1_code[] = {
6+
0x10690ab4166900b4, 0x0000000000cb01b4,
7+
};
8+
uint64_t int21_8_code[] = {
9+
0xb4c08e0040b85306, 0x8b26fafa74166901, 0x00d03e8026001a1e, 0x2601478a260d7400, 0x9011eb0000d006c6, 0x260975003c078a26, 0x9016eb0100d006c6, 0x832602001a068326,
10+
0xc726077c3e001a3e, 0x08b4fb001e001a06, 0x0000000000cb075b,
11+
};
12+
uint64_t int21_a_code[] = {
13+
0x000144c6f28b5653, 0xcd01b43674003c80, 0x3c16cd00b4fa7416, 0x7400017c800c7508, 0x339010eb014cfeec, 0x3c024088015c8adb, 0xd08a0144fe10740d, 0x3a01448a21cd02b4,
14+
0x00cb5b5ef8ca7504,
15+
};
16+
uint64_t int21_3f_code[] = {
17+
0x00f1bf5657525153, 0x0000eb06c72ef28b, 0xc5e9037500f98300, 0x50b9037e50f98300, 0xa12e00e90e892e00, 0x7c00ef063b2e00ed, 0xb4fa7416cd01b46d, 0x00e93e832e16cd00,
18+
0x2e1075083c147401, 0x2ee2740000ef3e83, 0x2e901eeb00ef0eff, 0x2e01882e00ef1e8b, 0x22740d3c00ef06ff, 0xe93e832e0875083c, 0x02b4d08a06740100, 0x3b2e00efa12e21cd,
19+
0x004f3d197400e906, 0x2e00ef1e8b2ea775, 0x00ef06ff2e0a01c6, 0x8b2e21cd02b40ab2, 0x8b2e018b2e00ed1e, 0x06ff2e008900eb1e, 0x2e00ed06ff2e00eb, 0x00ef063b2e00eda1,
20+
0x0000ed06c72e1175, 0x000000ef06c72e00, 0x2e00e9a12e900ceb, 0xa12ec07500eb063b, 0x5b595a5f5ef800eb, 0x00000000000000cb, 0x0000000000000000, 0x0000000000000000,
21+
0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
22+
0x0000000000000000,
23+
};
24+
// end of machine code
25+

tasm/int21_8.asm

Lines changed: 68 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,68 @@
1-
; This function implements string input for int 0x21 ah 0x8 -- character input
2-
; On output, al contains the ascii character
3-
; this function blocks until a character is available
4-
;
5-
; build like this:
6-
; ntvdm -c tasm int21_8.asm
7-
; ntvdm -c tlink int21_8.obj
8-
; hd int21_8.exe /q /o:512 /n
9-
; then copy/paste the hex output to int21_8_code[] in ntvdm.cxx
10-
11-
12-
.model large
13-
14-
code segment
15-
assume cs:code
16-
17-
begin:
18-
mov ah, 0
19-
int 16h
20-
mov ah, 8 ; restore the function to ah, which 16/0 overwrote with the scancode
21-
retf
22-
23-
code ends
24-
end
25-
1+
; This function implements string input for int 0x21 ah 0x8 -- character input
2+
; On output, al contains the ascii character
3+
; this function blocks until a character is available
4+
;
5+
; build like this:
6+
; ntvdm -c tasm int21_8.asm
7+
; ntvdm -c tlink int21_8.obj
8+
; hd int21_8.exe /q /o:512 /n
9+
; then copy/paste the hex output to int21_8_code[] in ntvdm.cxx
10+
11+
12+
.model large
13+
14+
code segment
15+
assume cs:code
16+
17+
kbd_head equ 1ah
18+
kbd_tail equ 1ch
19+
kbd_start equ 1eh
20+
kbd_beyond equ 3eh
21+
kbd_midway equ 0d0h ; 1 if ascii consumed already and scancode is next. non-DOS-standard location
22+
bios_seg equ 40h
23+
24+
begin:
25+
push es
26+
push bx
27+
mov ax, bios_seg
28+
mov es, ax
29+
30+
wait_for_kbd: ; wait for a keystroke to be available
31+
mov ah, 1 ; use int16 1 instead of a busy loop to enable the emulator to not pin the CPU
32+
injectcode db 69h, 16h ; fint 16. don't use int 16 because apps like qc 2.0 hook that
33+
; int 16
34+
jz wait_for_kbd
35+
36+
cli ; updating global kbd state, so don't allow interrupts
37+
mov bx, word ptr es: [kbd_head]
38+
cmp byte ptr es: [kbd_midway], 0 ; check if the ascii has been consumed yet
39+
jz return_ascii
40+
41+
mov al, byte ptr es: [bx + 1] ; return the scancode
42+
mov byte ptr es: [kbd_midway], 0 ; clear the midway flag
43+
jmp consume_keystroke
44+
45+
return_ascii:
46+
mov al, byte ptr es: [bx]
47+
cmp al, 0
48+
jnz consume_keystroke ; don't consume if ascii is 0
49+
50+
mov byte ptr es: [kbd_midway], 1 ; remember to return the scancode on the next call
51+
jmp all_done ; don't consume the keystroke yet
52+
53+
consume_keystroke:
54+
add word ptr es: [kbd_head], 2 ; move past the scancode if there was one
55+
cmp word ptr es: [kbd_head], kbd_beyond ; has the head moved beyond the buffer?
56+
jl all_done
57+
mov word ptr es: [kbd_head], kbd_start ; if so, restore it to the start
58+
59+
all_done:
60+
sti
61+
mov ah, 8 ; restore the function to ah since it was destroyed
62+
pop bx
63+
pop es
64+
retf
65+
66+
code ends
67+
end
68+

0 commit comments

Comments
 (0)