| QBASIC - maskinkode - array - INT21 - Current Drive and Directory |
Det aktuelle drev og den aktuelle sti kan vises med API funktionerne:
INT 21, 19 : Get Default Drive
INT 21, 47 : Get Current Directory
Basic-koden
TYPE Tregs ax AS INTEGER bx AS INTEGER cx AS INTEGER dx AS INTEGER si AS INTEGER di AS INTEGER ec AS INTEGER END TYPE |
||
| DECLARE SUB init () DECLARE SUB Int21h () DECLARE FUNCTION Ztrim$ (s AS STRING) DECLARE FUNCTION Lo% (w%) DECLARE FUNCTION CurDrive$ () DECLARE FUNCTION CurDir$ () DECLARE FUNCTION CurPath$ () |
loads machine code calls Int21 trims a zero-terminated string returns low byte of Integer returns Current Drive - fx "C" returns Current Directory - fx "PROG\BAS\QB" returns Current Path - fx "C:\PROG\BAS\QB" |
|
| DIM SHARED i21 AS STRING * 80 DIM SHARED r AS Tregs DIM SHARED int21 AS INTEGER |
buffer for machine code cpu registers machine code offset in data segment |
init |
||
PRINT CurPath$ |
C:\PROG\QBASIC\P\MC\INT\21H |
SUB init int21 = VARPTR(i21) BLOAD "int21.bin", int21 END SUB |
Maskinkoden i int21.bin >MASM: Qbasic - INT21 |
SUB Int21h% CALL ABSOLUTE(r, int21) END SUB |
FUNCTION Ztrim$ (s AS STRING) p% = INSTR(s, CHR$(0)) IF p% THEN Ztrim$ = LEFT$(s, p% - 1) ELSE Ztrim$ = s END IF END FUNCTION |
s er en STRING, som indeholder en 0-afsluttet
(zero-terminated) tekst. Funktionen returnerer teksten fra første tegn til lige før det afsluttende 0-tegn. |
FUNCTION Lo% (w%) Lo% = &HFF AND w% END FUNCTION |
Returnerer den lave byte i en Integer |
FUNCTION CurDrive$ r.ax = &H1900 Int21h CurDrive$ = CHR$(65 + Lo(r.ax)) END FUNCTION |
INT 21 function 19h : Get Default Drive Drive returned in AL (0=A, 1=B, 2=C, ... ) |
FUNCTION CurDir$ DIM Dir AS STRING * 128 r.ax = &H4700 r.dx = 0 r.si = VARPTR(Dir) Int21h CurDir$ = Ztrim$(Dir) END FUNCTION |
Buffer for Directory string INT 21 function 47 : Get Current Directory 0 : Default drive Address of buffer Trim the returned zero-terminated string |
FUNCTION CurPath$ CurPath$ = CurDrive$ + ":\" + CurDir$ END FUNCTION |