home *** CD-ROM | disk | FTP | other *** search
-
- /* */
- /* DeSmet C (C-Ware) interface to the Btrieve Record Manager, version 4 */
- /* */
-
- struct REGVAL { int AX, BX, CX, DX, SI, DI, D_SEG, E_SEG; };
-
- struct SEGREG { int CS, SS, DS, ES; };
-
- segread (sreg)
- struct SEGREG *sreg;
- {
- #asm
- mov bx,[bp+4] ;address of return structure
- mov [bx],cs
- mov [bx+2],ss
- mov [bx+4],ds
- mov [bx+6],es
- #
- }
-
- peek (offset, segment)
- unsigned offset, segment;
- {
- #asm
- push es ;save es
- mov bx,[bp+4] ;offset
- mov es,[bp+6] ;segment
- mov ax,es:[bx] ;what's the word?
- pop es ;restore es
- #
- }
-
- sysint(int_vector, regs_before, regs_after)
- unsigned int_vector;
- struct REGVAL *regs_before, *regs_after;
- {
- #asm
- mov ax,[bp+4] ;interrupt type
- mov cs:vec_id+1,al ;modify the INT instruction
- mov bx,[bp+6] ;address of register contents
- push ds ;save ds
- mov ax,[bx] ;load ax
- mov cx,[bx+2] ;save bx
- push cx ; on the stack
- mov cx,[bx+4] ;load cx
- mov dx,[bx+6] ;load dx
- mov si,[bx+8] ;load si
- mov di,[bx+10] ;load di
- mov ds,[bx+12] ;load ds
- mov es,[bx+14] ;load es
- pop bx ;load bx
- vec_id: int 00h ;the interrupt instruction
- pop ds ;restore ds
- push bx ;save bx
- mov bx,[bp+8] ;address of register contents
- mov [bx],ax ;store ax
- pop ax ;get saved value of bx
- mov [bx+02],ax ;store bx
- mov [bx+04],cx ;store cx
- mov [bx+06],dx ;store dx
- mov [bx+08],si ;store si
- mov [bx+10],di ;store di
- mov [bx+12],ds ;store ds
- mov [bx+14],es ;store es
- #
- }
-
- /* ProcId is used for communicating with the Multi Tasking Version of */
- /* Btrieve. It contains the process id returned from BMulti and should */
- /* not be changed once it has been set. */
- /* */
- int ProcId = 0; /* initialize to no process id */
- char MULTI = 0;
- char VSet = 0;
-
- BTRV (OP, POS_BLK, DATA_BUF, DATA_LEN, KEY_BUF, KEY_NUM)
- int OP;
- char POS_BLK[];
- char DATA_BUF[];
- int *DATA_LEN;
- char KEY_BUF[];
- int KEY_NUM;
-
- {
- #define BTR_ERR 20 /* record manager not started */
- #define BTR_VECTOR 0x7B * 4 /* offset for interrupt */
- #define VARIABLE_ID 0x6176 /* id for variable length records - 'va' */
- #define POS_LEN_ERR 23 /* invalid position block length */
-
- struct REGVAL REGS; /* register values for sysint function */
- struct SEGREG SREGS; /* current contents of the segment regs */
-
- struct BTRIEVE_PARMS /* structure passed to Record Man */
- {char *USER_BUF_OFFSET; /* callers data buffer offset */
- int USER_BUF_SEG; /* callers data buffer segment */
- int USER_BUF_LEN; /* length of data buffer */
- char *USER_CUR_OFFSET; /* user position block offset */
- int USER_CUR_SEG; /* user position block segment */
- char *USER_FCB_OFFSET; /* offset of disk FCB */
- int USER_FCB_SEG; /* segment of disk FCB */
- int USER_FUNCTION; /* requested function */
- char *USER_KEY_OFFSET; /* offset of user's key buffer */
- int USER_KEY_SEG; /* segment of user's key buffer */
- char USER_KEY_LENGTH; /* length of user's key buffer */
- char USER_KEY_NUMBER; /* key of reference for request */
- int *USER_STAT_OFFSET; /* offset of status word */
- int USER_STAT_SEG; /* segment of status word */
- int XFACE_ID;}; /* language identifier */
-
- struct BTRIEVE_PARMS XDATA;
- int STAT; /* status of Btrieve call */
-
- /* */
- /* Check to see that the Btrieve Record Manager has been started. */
- /* */
-
- REGS.AX = 0x357B;
- sysint (0x21, ®S, ®S);
- if (REGS.BX != 0x33)
- return (BTR_ERR);
-
- if (!VSet)
- {
- VSet = 1;
- REGS.AX = 0x3000;
- sysint (0x21, ®S, ®S);
- if ((REGS.AX & 0x00FF) >= 3)
- {
- REGS.AX = 0xAB00;
- sysint(0x2F, ®S, ®S);
- MULTI = ((REGS.AX & 0x00FF) == 'M');
- }
- }
-
- /* Read segment registers and initialize segment part of addresses to */
- /* user's data segment. */
- /* */
-
- segread(&SREGS);
- XDATA.USER_BUF_SEG = XDATA.USER_CUR_SEG = XDATA.USER_FCB_SEG =
- XDATA.USER_KEY_SEG = XDATA.USER_STAT_SEG = SREGS.DS;
-
- /* */
- /* Move user parameters to XDATA, the block where Btrieve expects them.*/
- /* */
-
- XDATA.USER_FUNCTION = OP;
- XDATA.USER_STAT_OFFSET = &STAT;
- XDATA.USER_FCB_OFFSET = POS_BLK;
- XDATA.USER_CUR_OFFSET = POS_BLK + 38;
- XDATA.USER_BUF_OFFSET = DATA_BUF;
- XDATA.USER_BUF_LEN = *DATA_LEN;
- XDATA.USER_KEY_OFFSET = KEY_BUF;
- XDATA.USER_KEY_LENGTH = 255; /* use max since we don't know */
- XDATA.USER_KEY_NUMBER = KEY_NUM;
- XDATA.XFACE_ID = VARIABLE_ID;
-
- /* */
- /* Make call to Btrieve Record Manager */
- /* */
-
- REGS.DX = (unsigned) &XDATA; /* parameter block is expected to be in DX */
- REGS.D_SEG = SREGS.DS;
- REGS.E_SEG = SREGS.ES;
- if (!MULTI)
- sysint(0x7b, ®S, ®S);
- else
- {
- while (1)
- {
- REGS.AX = 1; /* initialize to no process id */
- if ((REGS.BX = ProcId) != 0) /* have a process id already? */
- REGS.AX = 2; /* yes, make sure BMulti knows */
- REGS.AX += 0xAB00;
- sysint(0x2F, ®S, ®S);
- if ((REGS.AX & 0x00FF) == 0) break;
- REGS.AX = 0x0200;
- sysint(0x7F, ®S, ®S);
- }
- if (ProcId == 0) /* Did we need a PID? */
- ProcId = REGS.BX; /* Yes, save it for next call */
- }
-
- *DATA_LEN = XDATA.USER_BUF_LEN;
- return(STAT);
- }