FDOS / fdisk

Fixed Disk Setup Program - manages partitions using the MBR partitioning scheme
GNU General Public License v2.0
44 stars 13 forks source link

Replace Inline Assembly Code for Single Key Input #10

Closed micahcochran closed 1 year ago

micahcochran commented 3 years ago

The code has a number of inline assembly calls for AH=7/INT 21h. Some of these are "press a key" instances. Others use it for accepting keyboard input.

getch() from conio.h is the closest equivalent. But Watcom C uses AH=8/INT 21h, which is similar.

AH=7/INT 21 is direct character input. AH=8/INT 21 is character input checks for Ctrl+Break Ctrl+C and upon those key combos raises INT 23h.

The proposal is to replace inline assembly for AH=7/INT 21h with a keypress function that does the same thing.

Put this probably into USERINT1.C:

/* Read a single character from the keyboard, not buffered.
   Functionally very similar to getch() fron conio.h.
   returns an unsigned char for the key press. */
unsigned char Get_Keypress(void) {
        union REGS r;

    regs.h.ah = 7;        /* Direct Console Character Input without Echo. */
    intdos(&regs, &regs); /* Won't raise INT 23h on Ctrl+C or Ctrl+Break. */

    return regs.h.al;
}

Making this one fuction has an additional benefit that one could more easily place an #ifdef __COMPILER__ here for a compiler doesn't support intdos() or uses a different syntax. Also, the function could be easily edited to allow yielding.

The effect of this change would be to remove some of the inline assembly code in an effort to make the code a little more portable. Since, Watcom C uses a different inline assembly syntax.

If the 1.3.1 BETA is to be merged or not, this code should be done after that decision.

Sources: http://spike.scu.edu.au/~barry/interrupts.html#ah07 https://dos4gw.org/08h_8_Console_Character_Input_without_Echo

mateuszviste commented 1 year ago

quick comment just to say that a single int 21h, ah=7 is not enough for a "press any key" routine, as it won't handle extended keys (thus pressing an arrow key or any other extended key would be processed as two key presses).

I fixed this in this commit: https://github.com/FDOS/fdisk/pull/39/commits/85840c63577dab47c647a424d2645e8191bb6278

But this would certainly need to be put in one single place as a dedicated function. Perhaps translated to C with intdos(), as suggested in this issue.

mateuszviste commented 1 year ago

I replaced all wait-for-keypress assembly calls by a single function in userint0.c https://github.com/FDOS/fdisk/pull/41/commits/55ad5962dbabc666eb6aed63a4984bab8d7b3797

I think this issue can be closed now.