Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

inline asm, visual c (1.52),help on using interrupts

Status
Not open for further replies.

pj2003

Programmer
Jun 25, 2003
1
AR
hi,
I am trying to write a simple communication app using interrupts. The idea is to send a intr and a global memory direccion to pass messages. The thing is when I try to send the
offset and segment (of mem, look at code) the driver(driver.c) does not recieve the correct values!!!!
If anyone can help me I would be gratefull, thank in advance
pd: Sorry for my English
bye

------------------- Driver.C -------------------------------------------

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <dos.h>
#include <memory.h>
#include <string.h>
#include <malloc.h>

#define INT_IDLE 0x28
// I have Tried 0x05,0x21 and 0x14
#define INT 0x14

#define SHIFTL(x, n) (_ADDRESS = 0L, _ADDRESS = (long)(x), _ADDRESS << (n))
#define HIBYTE(x) (((unsigned)(x) >> 8) & 0xff)
#define LOWBYTE(x) ((unsigned)(x) & 0x00ff)
#define REGPAK unsigned es, unsigned ds, unsigned di, unsigned si, unsigned bp, unsigned sp, unsigned bx, unsigned dx, unsigned cx, unsigned ax, unsigned ip, unsigned cs, unsigned flags


void (_interrupt _far *func)( void );

void _interrupt _far handler(REGPAK)
{
if (LOWBYTE(ax) == 0x2d || INT!=0x21) {
// Here I get something strange, the value ax,bx,cx does no
// corresponde too the ones that a send in Test.C
cprintf(&quot;Handler %u %u %u\n&quot;,ax,cx,bx);
/*
* pars_message(MK_FP(bx,cx),buffer);
*/
}
_chain_intr(func);
outp(0x20,0x20);
}

void main(int argc,char *argv[])
{
unsigned int _ss;
unsigned int _sp;

cprintf(&quot;Resident 0x%x\n&quot;,INT);

func = _dos_getvect(INT);
_disable();
_dos_setvect(INT,handler);
_enable();
_asm {
mov _ss,SS
mov _sp,SP
}
_dos_keep(0, (_ss + (_sp >> 4) + 1) - _psp);
}



------------------- Test.C -------------------------------------------


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dos.h>
#include <conio.h>
#include <malloc.h>
#include <memory.h>

#define BUFFER_SIZE 1024
#define CANT_ARGUMENT 12
#define ARGUMENT_SIZE 128
#define INT_IDLE 0x28
#define INT 0x14

unsigned int ret;

//extern unsigned _stklen = 64000U;

char str_buffer[BUFFER_SIZE];

void main (int argc,char *argv[])
{
char __far *mem;
union _REGS inregs={0};
union _REGS outregs={0};

if (argc>=3) {
char type = argv[1][0];
int command = atoi(argv[2]);
int i;
sprintf(str_buffer,&quot;%c%i &quot;,type,command);
for(i = 3;i<argc;i++) {
strcat(str_buffer,argv);
strcat(str_buffer,&quot;\\&quot;);
}
mem = (char __far *) _fmalloc(BUFFER_SIZE);
_fstrcpy(mem,str_buffer);
inregs.x.bx = FP_SEG(mem);
inregs.x.cx = FP_OFF(mem);
inregs.x.ax = 0x002d
cprintf (&quot;Sending to:0x%x\n&quot;,INT);
cprintf (&quot;Msg(%u):'%Fs' %u:%u\n&quot;,inregs.x.ax,mem,inregs.x.bx,inregs.x.cx);
// version 1 ( when INT equals to 0x21 in driver.c )
//ret = _intdos(&inregs,&outregs);
// version 2
//ret = _int86(INT,&inregs,&outregs);
// version 3
_asm {
mov AX,0x002d
mov BX,inregs.x.bx
mov CX,inregs.x.cx
int INT
}
} else {
cprintf(&quot;usage: Test <type> <command> <arg1> <arg2> ... <argN>\n\n&quot;);
}
}
 
just a guess !!

why are you using regpack in the driver program ??
Is test.c moving the values to the memory locations assigned to these variables (under REGPACK)???

Instead you program test.c is moving the values to the registers...so the driver program must also read the values from the registers !!

 
Did you actually run this DOS program on a real DOS machine, and not some windows win9x/NT/2K/XP virtual machine?

> strcat(str_buffer,argv);
You need to re-post your code and make sure you use the correct tags for posting code. At present, it's taken your
Code:
[i]
index as interpreted it as italic text.

Make sure you use &quot;Preview Post&quot; to make sure your post is formatted correctly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top