QB / QB64 Discussion Forum      Other Subforums, Links and Downloads
 

 Return to Index  

example...

December 15 2005 at 3:43 PM
Michael Calkins  (Login MCalkins)
R


Response to Tool for including asm inside QBASIC programs. (requires NASM)

 
The result of this work is here:
http://www.network54.com/Forum/182035/message/1134687517/XMS+in+QBASIC+1.1

however, these files demonstrate how this process works:
-------------------------Example asm file:---
;Written by Michael Calkins.
cpu 8086        ;guarentee 8086 instructions
org 0000h       ;This will NOT be a .com file. Start offsets at 0000
_npars dw 0h    ;number of paragraphs
_errn dw 0h     ;error code
_bseg dw 0h     ;base segment of conventional block
_ctrl dw 0h     ;XMS driver control function (offset)
_ctrls dw 0h    ;... (segment)
_ver dw 0h      ;XMS version number (BCD)
_handle dw 0h   ;extended memory block handle
_nkb dw 0h      ;number of KB
_length dd 0h   ;legnth
_sourcehandle dw 0h     ;source handle
_sourceo dd 0h  ;source offset
_desthandle dw 0h       ;destination handle
_desto dd 0h    ;destination offset
_info dw 0h     ;information
_errflag dw 0h  ;error indicator

        ;code starts here! (line 20)

_error0
mov [_npars],bx
_error1
mov [_errn],ax
mov word [_errflag],0ffffh
retf

_getconv        ;allocate conventional memory
mov ah,48h
mov bx,[_npars]
int 21h
jc _error0
mov word [_errflag],0h
mov [_bseg],ax
retf

_freeconv       ;release conventional memory
mov ah,49h
mov es,[_bseg]
int 21h
jc _error1
mov word [_errflag],0h
retf

_sizeconv       ;resize conventional memory block
mov ah,4Ah
mov bx,[_npars]
push es
mov es,[_bseg]
int 21h
pop es
jc _error0
mov word [_errflag],0h
retf

_detectxms      ;detect XMS, get control func, get version number
mov ax,4300h
int 2fh
cmp al,80h
jne _error2
mov word [_errflag],0h
push es
mov ax,4310h
int 2fh
mov [_ctrls],es
pop es
mov [_ctrl],bx
xor ah,ah
call far [_ctrl]
mov [_ver],ax
retf

_queryxms       ;query Extended Memory
mov ah,8h
xor bl,bl
call far [_ctrl]
mov [_nkb],ax
mov [_info],dx
mov [_errn],bx
test bl,80h
jnz _error2
mov word [_errflag], 0000h
retf

_getxms         ;allocate Extended Memory
mov ah,9h
mov dx,[_nkb]
call far [_ctrl]
mov [_handle],dx
mov bh,al
mov [_errn],bx
jmp _testal

_freexms        ;release Extended Memory
mov ah,0ah
mov dx,[_handle]
call far [_ctrl]
mov bh,al
mov [_errn],bx
jmp _testal

_error2
mov word [_errflag],0ffffh
retf

_movexms        ;move memory (from/to regular/Extended)
mov ah,0bh
push si
mov si,_length
call far [_ctrl]
pop si
mov bh,al
mov [_errn],bx
jmp _testal

_infoxms        ;get information for an Extended Memory block
mov ah,0eh
mov dx,[_handle]
call far [_ctrl]
mov [_nkb],dx
mov [_info],bx
mov bh,al
mov [_errn],bx
jmp _testal

_resizexms      ;resize an Extended Memory block
mov ah,0fh
mov bx,[_nkb]
mov dx,[_handle]
call far [_ctrl]
mov bh,al
mov [_errn],bx
_testal
test al,al
jz _error2
mov word [_errflag], 0000h
retf

-------------------------Example list file generated by NASM:-----
     1                                  ;Written by Michael Calkins.
     2                                  cpu 8086        ;guarentee 8086 instructions
     3                                  org 0000h       ;This will NOT be a .com file. Start offsets at 0000
     4 00000000 0000                    _npars dw 0h    ;number of paragraphs
     5 00000002 0000                    _errn dw 0h     ;error code
     6 00000004 0000                    _bseg dw 0h     ;base segment of conventional block
     7 00000006 0000                    _ctrl dw 0h     ;XMS driver control function (offset)
     8 00000008 0000                    _ctrls dw 0h    ;... (segment)
     9 0000000A 0000                    _ver dw 0h      ;XMS version number (BCD)
    10 0000000C 0000                    _handle dw 0h   ;extended memory block handle
    11 0000000E 0000                    _nkb dw 0h      ;number of KB
    12 00000010 00000000                _length dd 0h   ;legnth
    13 00000014 0000                    _sourcehandle dw 0h     ;source handle
    14 00000016 00000000                _sourceo dd 0h  ;source offset
    15 0000001A 0000                    _desthandle dw 0h       ;destination handle
    16 0000001C 00000000                _desto dd 0h    ;destination offset
    17 00000020 0000                    _info dw 0h     ;information
    18 00000022 0000                    _errflag dw 0h  ;error indicator
    19                                  
    20                                          ;code starts here! (line 20)
    21                                  
    22                                  _error0
    23 00000024 891E[0000]              mov [_npars],bx
    24                                  _error1
    25 00000028 A3[0200]                mov [_errn],ax
    26 0000002B C706[2200]FFFF          mov word [_errflag],0ffffh
    27 00000031 CB                      retf
    28                                  
    29                                  _getconv        ;allocate conventional memory
    30 00000032 B448                    mov ah,48h
    31 00000034 8B1E[0000]              mov bx,[_npars]
    32 00000038 CD21                    int 21h
    33 0000003A 72E8                    jc _error0
    34 0000003C C706[2200]0000          mov word [_errflag],0h
    35 00000042 A3[0400]                mov [_bseg],ax
    36 00000045 CB                      retf
    37                                  
    38                                  _freeconv       ;release conventional memory
    39 00000046 B449                    mov ah,49h
    40 00000048 8E06[0400]              mov es,[_bseg]
    41 0000004C CD21                    int 21h
    42 0000004E 72D8                    jc _error1
    43 00000050 C706[2200]0000          mov word [_errflag],0h
    44 00000056 CB                      retf
    45                                  
    46                                  _sizeconv       ;resize conventional memory block
    47 00000057 B44A                    mov ah,4Ah
    48 00000059 8B1E[0000]              mov bx,[_npars]
    49 0000005D 06                      push es
    50 0000005E 8E06[0400]              mov es,[_bseg]
    51 00000062 CD21                    int 21h
    52 00000064 07                      pop es
    53 00000065 72BD                    jc _error0
    54 00000067 C706[2200]0000          mov word [_errflag],0h
    55 0000006D CB                      retf
    56                                  
    57                                  _detectxms      ;detect XMS, get control func, get version number
    58 0000006E B80043                  mov ax,4300h
    59 00000071 CD2F                    int 2fh
    60 00000073 3C80                    cmp al,80h
    61 00000075 7568                    jne _error2
    62 00000077 C706[2200]0000          mov word [_errflag],0h
    63 0000007D 06                      push es
    64 0000007E B81043                  mov ax,4310h
    65 00000081 CD2F                    int 2fh
    66 00000083 8C06[0800]              mov [_ctrls],es
    67 00000087 07                      pop es
    68 00000088 891E[0600]              mov [_ctrl],bx
    69 0000008C 30E4                    xor ah,ah
    70 0000008E FF1E[0600]              call far [_ctrl]
    71 00000092 A3[0A00]                mov [_ver],ax
    72 00000095 CB                      retf
    73                                  
    74                                  _queryxms       ;query Extended Memory
    75 00000096 B408                    mov ah,8h
    76 00000098 30DB                    xor bl,bl
    77 0000009A FF1E[0600]              call far [_ctrl]
    78 0000009E A3[0E00]                mov [_nkb],ax
    79 000000A1 8916[2000]              mov [_info],dx
    80 000000A5 891E[0200]              mov [_errn],bx
    81 000000A9 F6C380                  test bl,80h
    82 000000AC 7531                    jnz _error2
    83 000000AE C706[2200]0000          mov word [_errflag], 0000h
    84 000000B4 CB                      retf
    85                                  
    86                                  _getxms         ;allocate Extended Memory
    87 000000B5 B409                    mov ah,9h
    88 000000B7 8B16[0E00]              mov dx,[_nkb]
    89 000000BB FF1E[0600]              call far [_ctrl]
    90 000000BF 8916[0C00]              mov [_handle],dx
    91 000000C3 88C7                    mov bh,al
    92 000000C5 891E[0200]              mov [_errn],bx
    93 000000C9 E95D00                  jmp _testal
    94                                  
    95                                  _freexms        ;release Extended Memory
    96 000000CC B40A                    mov ah,0ah
    97 000000CE 8B16[0C00]              mov dx,[_handle]
    98 000000D2 FF1E[0600]              call far [_ctrl]
    99 000000D6 88C7                    mov bh,al
   100 000000D8 891E[0200]              mov [_errn],bx
   101 000000DC E94A00                  jmp _testal
   102                                  
   103                                  _error2
   104 000000DF C706[2200]FFFF          mov word [_errflag],0ffffh
   105 000000E5 CB                      retf
   106                                  
   107                                  _movexms        ;move memory (from/to regular/Extended)
   108 000000E6 B40B                    mov ah,0bh
   109 000000E8 56                      push si
   110 000000E9 BE[1000]                mov si,_length
   111 000000EC FF1E[0600]              call far [_ctrl]
   112 000000F0 5E                      pop si
   113 000000F1 88C7                    mov bh,al
   114 000000F3 891E[0200]              mov [_errn],bx
   115 000000F7 E92F00                  jmp _testal
   116                                  
   117                                  _infoxms        ;get information for an Extended Memory block
   118 000000FA B40E                    mov ah,0eh
   119 000000FC 8B16[0C00]              mov dx,[_handle]
   120 00000100 FF1E[0600]              call far [_ctrl]
   121 00000104 8916[0E00]              mov [_nkb],dx
   122 00000108 891E[2000]              mov [_info],bx
   123 0000010C 88C7                    mov bh,al
   124 0000010E 891E[0200]              mov [_errn],bx
   125 00000112 E91400                  jmp _testal
   126                                  
   127                                  _resizexms      ;resize an Extended Memory block
   128 00000115 B40F                    mov ah,0fh
   129 00000117 8B1E[0E00]              mov bx,[_nkb]
   130 0000011B 8B16[0C00]              mov dx,[_handle]
   131 0000011F FF1E[0600]              call far [_ctrl]
   132 00000123 88C7                    mov bh,al
   133 00000125 891E[0200]              mov [_errn],bx
   134                                  _testal
   135 00000129 84C0                    test al,al
   136 0000012B 74B2                    jz _error2
   137 0000012D C706[2200]0000          mov word [_errflag], 0000h
   138 00000133 CB                      retf

-------------------------Example output file generated by my program:-----
type machinet
 npars as integer
 errn as integer
 bseg as integer
 ctrl as integer
 ctrls as integer
 ver as integer
 handle as integer
 nkb as integer
 length as long
 sourcehandle as integer
 sourceo as long
 desthandle as integer
 desto as long
 info as integer
 errflag as integer
 code as string * 272
 installed as integer
end type
dim shared machine as machinet


t$=mki$(&h1E89)+mki$(varptr(machine.npars))
t$=t$+chr$(&hA3)+mki$(varptr(machine.errn))
t$=t$+mki$(&h06C7)+mki$(varptr(machine.errflag))+mki$(&hFFFF)
t$=t$+chr$(&hCB)
t$=t$+mki$(&h48B4)
t$=t$+mki$(&h1E8B)+mki$(varptr(machine.npars))
t$=t$+mki$(&h21CD)
t$=t$+mki$(&hE872)
t$=t$+mki$(&h06C7)+mki$(varptr(machine.errflag))+mki$(&h0000)
t$=t$+chr$(&hA3)+mki$(varptr(machine.bseg))
t$=t$+chr$(&hCB)
t$=t$+mki$(&h49B4)
t$=t$+mki$(&h068E)+mki$(varptr(machine.bseg))
t$=t$+mki$(&h21CD)
t$=t$+mki$(&hD872)
t$=t$+mki$(&h06C7)+mki$(varptr(machine.errflag))+mki$(&h0000)
t$=t$+chr$(&hCB)
t$=t$+mki$(&h4AB4)
t$=t$+mki$(&h1E8B)+mki$(varptr(machine.npars))
t$=t$+chr$(&h06)
t$=t$+mki$(&h068E)+mki$(varptr(machine.bseg))
t$=t$+mki$(&h21CD)
t$=t$+chr$(&h07)
t$=t$+mki$(&hBD72)
t$=t$+mki$(&h06C7)+mki$(varptr(machine.errflag))+mki$(&h0000)
t$=t$+chr$(&hCB)
t$=t$+mki$(&h00B8)+chr$(&h43)
t$=t$+mki$(&h2FCD)
t$=t$+mki$(&h803C)
t$=t$+mki$(&h6875)
t$=t$+mki$(&h06C7)+mki$(varptr(machine.errflag))+mki$(&h0000)
t$=t$+chr$(&h06)
t$=t$+mki$(&h10B8)+chr$(&h43)
t$=t$+mki$(&h2FCD)
t$=t$+mki$(&h068C)+mki$(varptr(machine.ctrls))
t$=t$+chr$(&h07)
t$=t$+mki$(&h1E89)+mki$(varptr(machine.ctrl))
t$=t$+mki$(&hE430)
t$=t$+mki$(&h1EFF)+mki$(varptr(machine.ctrl))
t$=t$+chr$(&hA3)+mki$(varptr(machine.ver))
t$=t$+chr$(&hCB)
t$=t$+mki$(&h08B4)
t$=t$+mki$(&hDB30)
t$=t$+mki$(&h1EFF)+mki$(varptr(machine.ctrl))
t$=t$+chr$(&hA3)+mki$(varptr(machine.nkb))
t$=t$+mki$(&h1689)+mki$(varptr(machine.info))
t$=t$+mki$(&h1E89)+mki$(varptr(machine.errn))
t$=t$+mki$(&hC3F6)+chr$(&h80)
t$=t$+mki$(&h3175)
t$=t$+mki$(&h06C7)+mki$(varptr(machine.errflag))+mki$(&h0000)
t$=t$+chr$(&hCB)
t$=t$+mki$(&h09B4)
t$=t$+mki$(&h168B)+mki$(varptr(machine.nkb))
t$=t$+mki$(&h1EFF)+mki$(varptr(machine.ctrl))
t$=t$+mki$(&h1689)+mki$(varptr(machine.handle))
t$=t$+mki$(&hC788)
t$=t$+mki$(&h1E89)+mki$(varptr(machine.errn))
t$=t$+mki$(&h5DE9)+chr$(&h00)
t$=t$+mki$(&h0AB4)
t$=t$+mki$(&h168B)+mki$(varptr(machine.handle))
t$=t$+mki$(&h1EFF)+mki$(varptr(machine.ctrl))
t$=t$+mki$(&hC788)
t$=t$+mki$(&h1E89)+mki$(varptr(machine.errn))
t$=t$+mki$(&h4AE9)+chr$(&h00)
t$=t$+mki$(&h06C7)+mki$(varptr(machine.errflag))+mki$(&hFFFF)
t$=t$+chr$(&hCB)
t$=t$+mki$(&h0BB4)
t$=t$+chr$(&h56)
t$=t$+chr$(&hBE)+mki$(varptr(machine.length))
t$=t$+mki$(&h1EFF)+mki$(varptr(machine.ctrl))
t$=t$+chr$(&h5E)
t$=t$+mki$(&hC788)
t$=t$+mki$(&h1E89)+mki$(varptr(machine.errn))
t$=t$+mki$(&h2FE9)+chr$(&h00)
t$=t$+mki$(&h0EB4)
t$=t$+mki$(&h168B)+mki$(varptr(machine.handle))
t$=t$+mki$(&h1EFF)+mki$(varptr(machine.ctrl))
t$=t$+mki$(&h1689)+mki$(varptr(machine.nkb))
t$=t$+mki$(&h1E89)+mki$(varptr(machine.info))
t$=t$+mki$(&hC788)
t$=t$+mki$(&h1E89)+mki$(varptr(machine.errn))
t$=t$+mki$(&h14E9)+chr$(&h00)
t$=t$+mki$(&h0FB4)
t$=t$+mki$(&h1E8B)+mki$(varptr(machine.nkb))
t$=t$+mki$(&h168B)+mki$(varptr(machine.handle))
t$=t$+mki$(&h1EFF)+mki$(varptr(machine.ctrl))
t$=t$+mki$(&hC788)
t$=t$+mki$(&h1E89)+mki$(varptr(machine.errn))
t$=t$+mki$(&hC084)
t$=t$+mki$(&hB274)
t$=t$+mki$(&h06C7)+mki$(varptr(machine.errflag))+mki$(&h0000)
t$=t$+chr$(&hCB)

if len(t$)<>len(machine.code) then print "Error!":system
machine.code=t$:machine.installed=-1

const error0offset = &h0
const error1offset = &h4
const getconvoffset = &hE
const freeconvoffset = &h22
const sizeconvoffset = &h33
const detectxmsoffset = &h4A
const queryxmsoffset = &h72
const getxmsoffset = &h91
const freexmsoffset = &hA8
const error2offset = &hBB
const movexmsoffset = &hC2
const infoxmsoffset = &hD6
const resizexmsoffset = &hF1
const testaloffset = &h105


    
This message has been edited by MCalkins on Dec 15, 2005 4:09 PM


 
 Respond to this message   
Responses

 Copyright © 1999-2014 Network54. All rights reserved.   Terms of Use   Privacy Statement  

Newbies usually go to www.qbasic.com and click on The QBasic Forum
Forum regulars have their own ways, which include The QBasic Community Forums