TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: Frank Adam
from: Adam Fitzpatrick
date: 1996-07-09 17:14:30
subject: Regs

Quoting Frank Adam to All:



 FA> {at}MSGID: 3:635/544.0 31d46d18

 FA> Hi guys,





FA>Just curious why is REGS a union and not a struct ? It feels like one.. 



It's a union of two structs I think. :) This is because AX is divided into

AH and AL; it's nice if you can address AH without altering AL, and at the

same time address AX without having to use the two halves separately. One

struct contains the AX, BX, CX, etc, and the other is AL, AH, BL, BH; the

former are all words, the latter bytes. I don't think I've explained this

very clearly, but you should be able to figure it out.



FA>And can anyone show or guide me to a C snippet,on how to retrieve the 

FA>adress of DTA(Disk Transfer Adress) ?  



FA>The following should work ( i thought ), but it just boots.

FA>Perhaps the bit between the braces is wrong ? :o) 



:)



 FA> char* Get_DTA() 

 FA> {

 FA> char far* ptr;

 FA> union REGS regs; 

 FA> struct SREGS sregs;

 FA> 

 FA> regs.x.ax = 0x2f00;



Since you only need to set AH, you could change this. It won't help, but

it'll be "more correct". (I don't like wasting a byte; just one of my

old habits from Z80 assembly language, where you don't have the time or

memory to waste. ) I can't remember exactly what it's called, but have

a look at the definition of REGS again for something like regs.h.ah or

regs.l.ah. (That'll explain why it's a union I think.)



FA> int86x(0x21,®s,®s,&sregs);

 FA> ptr = (char far*) MK_FP((unsigned)sregs.es,(usigned)regs.x.dx);

 FA> };



Two problems:

1) It doesn't return ptr.

2) According to my docs, the INT 21h call returns the address in ES:BX, not

   ES:DX.



How about (completely untested):



char* Get_DTA()

{

  char* dta;



  asm

  {

    push ax

    push bx

    push es

    mov ah,0x2F

    int 0x21

    mov [word ptr dta],bx

    mov [word ptr dta+2],es

    pop es

    pop bx

    pop ax

  }

  return dta;

}



I've always believed you should use assembly language for an assembly

language job like this. Those regs and int86x things annoy the hell out

of me for some reason - I can _feel_ the time wasted passing parameters

and calling the procedure and loading the registers. :) Anyway, the pushes

and pops preserve all the registers that should be affected, because I'm

not sure which ones the compiler really needs you to save.



The syntax of [word ptr dta] (and the next line) might need changing; perhaps

word ptr [dta] might be better (I'm used to TASM's ideal mode syntax, which

is different from MASM's standard. It works in TP6 though...).



... Do Agnostics open their prayers with "To Whom it May Concern"?

--- FMailX 1.02
* Origin: Power BBS - +61-2-858-4114 - Files/Games/EchoMail/Internet (3:711/953)
SEEN-BY: 50/99 620/243 623/630 711/401 409 410 413 430 808 809 932 934 946
SEEN-BY: 711/953 963 712/515 713/888 714/906 800/1
@PATH: 711/953 410 808 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.