Solved

TP7 and interrupts

Posted on 2003-11-15
9
485 Views
Last Modified: 2010-04-16
Hi,
Okay, here is a good question. Here is the info of a interrupt I want to use from the FreeDOS interuppt list, the MKDIR interrupt, see the info below. I've tinkered and mess with this stuff several days and have gotten to a point were I can call some of the simpler ones. Like oh say figure out  how many bytes per sector.

This is what I try to use:
INT 21 - DOS 2+ - "MKDIR" - CREATE SUBDIRECTORY
      AH = 39h
      DS:DX -> ASCIZ pathname
Return: CF clear if successful
          AX destroyed
      CF set on error
          AX = error code (03h,05h) (see #1545 at AH=59h/BX=0000h)
Notes:      all directories in the given path except the last must exist
      fails if the parent directory is the root and is full
      DOS 2.x-3.3 allow the creation of a directory sufficiently deep that
        it is not possible to make that directory the current directory
        because the path would exceed 64 characters
      under the FlashTek X-32 DOS extender, the pointer is in DS:EDX
SeeAlso: AH=3Ah,AH=3Bh,AH=6Dh,AX=7139h,AH=E2h/SF=0Ah,AX=43FFh/BP=5053h
SeeAlso: INT 2F/AX=1103h,INT 60/DI=0511h

Here is the current attempt and more info. I know DS:DX means I have to put the Segment(longint), which points to a pchar that holds the name of the dir I want to create. See cod epost below.

Program Interrupter;

uses Dos;

var
 ecode:string;
 dir:pchar;
 regs: Registers;  { For Windows: TRegisters }
 i:integer;

begin
 regs.ah := $39;
 dir := 'C:\test';
 regs.dx := Seg(dir); {seems to work creates a dir name @ in the current dir, some how it doesn't get the name right}
 writeln(Seg(dir),' ',Ofs(dir)); {I figure one of the two is right}
 with regs do
 intr($21,regs);
 with regs do
 str(ax ,ecode);
 writeln(ecode);
end.

Anyone have a clue? Or better yet and answer?
0
Comment
Question by:kake26
  • 3
  • 3
  • 3
9 Comments
 
LVL 47

Expert Comment

by:dbrunton
Comment Utility
DS:DX -> ASCIZ pathname

 dir := 'C:\test';

 regs.dx := Seg(dir)

There are problems here.

dir is a Pascal string.  It is not an ASCIZ string.  A Pascal string starts with a number that tells the Pascal routines how long it is.

An ASCIZ string is a string that is finished when it encounters the zero char, that is a char that has the byte value of 0.

So you have to add another byte to the end of the dir string.  And this byte must contain the 0 byte.  That's your ASCIZ string.

Now DS:DX is a segment:offset pointer.  DS needs to point to the data segment you are using in Pascal.   I think it is initialised for you.  DX points to the offset  within the data segment.

So it is

regs.dx := ofs(dir);
inc(regs.dx);       { increment it by 1 because regs.dx points to the number part of a Pascal string.  After you increment it you point it at the start of the letters }
0
 
LVL 47

Accepted Solution

by:
dbrunton earned 260 total points
Comment Utility
DS:DX -> ASCIZ pathname

 dir := 'C:\test';

 regs.dx := Seg(dir)

There are problems here.

dir is a Pascal string.  It is not an ASCIZ string.  A Pascal string starts with a number that tells the Pascal routines how long it is.

An ASCIZ string is a string that is finished when it encounters the zero char, that is a char that has the byte value of 0.

So you have to add another byte to the end of the dir string.  And this byte must contain the 0 byte.  That's your ASCIZ string.

Now DS:DX is a segment:offset pointer.  DS needs to point to the data segment you are using in Pascal.   I think it is initialised for you.  DX points to the offset  within the data segment.

So it is

regs.dx := ofs(dir);
inc(regs.dx);       { increment it by 1 because regs.dx points to the number part of a Pascal string.  After you increment it you point it at the start of the letters }
0
 

Author Comment

by:kake26
Comment Utility
Thanks, but didn't work. I tried and made it a pchar which should have solved it and and use Ofs like you suggested. It still doesn't work. I know a asciz string is null terminated with #0, is that the same as char(0)? Could you give me a example. I've been on this for days and get no firther still. Tnx for the help sp far.
0
 
LVL 47

Expert Comment

by:dbrunton
Comment Utility
Yep, Null terminated string.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:kake26
Comment Utility
Okay, trying more stuff. It turns out I over locked something.  Alright here is my current code.

Program Interrupter;

uses Dos,Strings;

var
 ecode:string;
 dir:pchar;
 regs: Registers;  { For Windows: TRegisters }
 i:string;

begin
 regs.ah := $39;
 dir := 'C:\test';
 writeln(dir);
 regs.dx := Ofs(dir);
 inc(regs.dx);
 writeln(Seg(dir),' ',Ofs(dir));
 with regs do
 intr($21,regs);
 with regs do
 str(ax ,ecode); {err code, in the current state it returns the number 5 }
 writeln(ecode);
end.

Now as far as I think I'm doing it right if anyone sees a flub let me know. Its odd AX seems to contain and error code. Or at least the docs say so. I still don't get why it doesn't work.
0
 
LVL 6

Assisted Solution

by:MannSoft
MannSoft earned 240 total points
Comment Utility
You're still missing the null terminator.  Try:

dir := 'C:\TEST' + #0;
0
 
LVL 6

Expert Comment

by:MannSoft
Comment Utility
Oh, I just noticed that dir is a PCHAR and not STRING type.  Before you can assign a value to a PCHAR you need to allocate some memory for it.  It's probably easier to switch to a STRING instead, and then you can use the code from my previous post.
0
 

Author Comment

by:kake26
Comment Utility
Hi,
Yes and no about the pchar. You're a few days to late, I've figured it out all by now through lots of research and digging through code examples. You can closest to a real answer so I give you the points. Incase you want to see the ANSWER I've bothered to paste my findings

Program Interrupter;

uses Dos;

type
varstring:string[80];

var
 ecode:string;
 dir:varstring;
 regs: Registers;  { For Windows: TRegisters }

begin
regs.ah := $39;
dir := 'C:\test'+#0;
regs.ds := Seg(dir);
regs.dx := Ofs(dir);
inc(regs.dx);
with regs do
intr($21,regs);
with regs do
str(ax ,ecode);
writeln(ecode);
end.

PRESTO and enough said.
0
 
LVL 6

Expert Comment

by:MannSoft
Comment Utility
There shouldn't be the need to create and use the varstring type.  Making dir a plain old string should work as well, but if that's what's working, that's all that matters.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Veeam Backup & Replication has added a new integration – Veeam Backup for Microsoft Office 365.  In this blog, we will discuss how you can benefit from Office 365 email backup with the Veeam’s new product and try to shed some light on the needs and …
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now