Search code examples
assemblykeyboarddosx86-16turbo-basic

How can I include a ASM program into my Turbo Basic Program?


I found this ASM routine to get the key pressed. ASM routine to get key pressed Now I would like to include it to a Turbo Basic routine, but do not know how to do this. Can anyone here tell me how it is be done? THanks

EDIT: I found a way: $INLINE, but How can I convert my asm code to Machine Language, that I can inline it into my basic program?

EDIT: I had no success in putting this QBASIC with Asm Code in it into an TURBO BASIC Program. I would be thankful for any help how to do it:

DECLARE FUNCTION GetKeyH% ()

CLS
DO
  LOCATE 10, 10
  PRINT "Key = "; HEX$(GetKeyH%); "    "
LOOP UNTIL INKEY$ = CHR$(27)
END

and the ASM PART:

Dosseg
.model medium, basic
.286
.stack
.code
Even
           public    getkeyh            ; make getkeyh public
getkeyh    proc far basic uses bp dx    ; save registers

           in   al,60h
           xchg dx,ax
           xor  ax,ax                   ; assume no key
           test dl,10000000b
           jnz  short getkeyhD
           mov  al,dl
getkeyhD:  ret
getkeyh    endp                         ; end of procedure
           end                          ; end of assembly code

enter image description here

EDIT: THANKS a lot to the Answer of Mr Michael Petch below. Moreover I could see that this ASM routine is also a solution to CTL and ALT KEYS pressed


Solution

  • You can use DEBUG.COM to enter the Assembly code, then perform a hexadecimal dump to get the machine code.

    It looks like this:

    D:\>DEBUG
    -A 100
    0ABD:0100 IN AL,60
    0ABD:0102 XCHG DX,AX
    0ABD:0103 XOR AX,AX
    0ABD:0105 TEST DL,80
    0ABD:0108 JNZ 10C
    0ABD:010A MOV AL,DL
    0ABD:010C RET
    0ABD:010D
    -R CX
    CX 0000  :D
    -N KEY.COM
    -W
    Writing 000D bytes
    -Q
    
    D:\>HEXDUMP KEY.COM
    00000000    E4  60  92  31  C0  F6  C2  80  75  02  88  D0  C3                  .`.1....u....
    
    D:\>
    

    So that now you can encapsulate each machine code with $INLINE.

    $INLINE &HE4, &H60, &H92, &H31, &HC0, &HF6, &HC2, &H80, &H75, &H02, &H88, &HD0 
    

    As suggested by @Michael Petch, do not include the last machine code (&HC3) in your $INLINE metastatement.

    Note: While HEXDUMP.EXE is my own program, you can easily find any hex editor available on the Internet to view the content of a binary file.