Mail Archives: djgpp/1998/08/07/16:17:11
Hi,
George Foot told me how to generate a BIOS int 16h (keyboard) in inline AT&T
assembler in DJGPP:
>__dpmi_int is just a function, so you pass parameters in the usual
>way. For the parameters to __dpmi_int, which are nice parameters,
>you just push them onto the stack, four bytes each, right-to-left,
>and then do the (near) call:
> movl _regs, %eax /* address of register block */
> pushl %eax
> movl $0x10, %eax /* interrupt number (example) */
> pushl %eax
> call ___dpmi_int /* (0x10, ®s) */
> addl $8, %esp /* or popl twice */
> /* now EAX is the return value */
>Since you're calling GCC-compiled code (or rather, code written to
>be called by GCC-compiled code) you must make sure the normal
>assumptions hold, e.g. ES=DS=CS=SS. Also note that it can clobber
>ECX, EDX, FS and GS without restoring them; if you care about their
>values, save them (perhaps on the stack before pushing parameters).
My questions:
1) What are "nice parameters"?
2) How do I "make sure the normal assumptions hold"?
3) What kind of entry and exit code is needed if the "assumptionss do not
hold" e.g. if ES NOT egual to ES=DS=CS=SS in the routine I want to call the
int in?
My problem is that the code works 100% when in total isolation, but as soon
as I put it in my routine where I want to do the BIOS int (check for key
down during a loop to break the loop) it crashes the whole DOS box, dropping
me into W95.
Like this:
//D2 - Simple small fire with great smoke - quit with CTRL-BREAK
#include <stdio.h>
#include <conio.h>
#include <go32.h>
#include <dpmi.h>
#include <pc.h>
<-snip->
__dpmi_regs r;
<-snip->
void waitkey() Here it works fine - why?<--------------------------
{
__asm__ __volatile__
("
movw $0x0,_r+28
pushl $_r
pushl $0x16
call ___dpmi_int
addl $8,%esp
");
}
int main(void)
{
__asm__ __volatile__
("
pushw %%ds
pushl %%ebp
pushl %%esp
movw %%ds,_dssave
movl %%ebp,_ebpsave
movl %%esp,_espsave
movw _vid_descriptor,%%es
movw _vid_descriptor,%%ds --------->Is this the problem?
xorw %%bx,%%bx
mainloop:
movw $320,%%si
movb $0x7d,%%ch
pushw %%si
pushw %%cx
smoothloop:
lodsb
movb (%%esi),%%bl
addw %%bx,%%ax
movb 319(%%esi),%%bl
addw %%bx,%%ax
movb -2(%%esi),%%bl
addw %%bx,%%ax
shrw $2,%%ax
movb %%al,-321(%%esi)
loop smoothloop
popw %%di
popw %%cx
randline:
mulw (%%edi)
incw %%ax
stosw
decw %%di
loop randline
-------->If i put it here it crashes totally - what kind of entry and exit
code is needed to
-------->be able to push parameters for __dpmi_int HERE and call __dpmi_int
HERE
-------->in this stack register context?
-------->I've tried restoring DS,ES,FS,GS before calling but __dpmi_int
still crashes
-------->I want the loop to exit on a keypress (i. e. int 16h func 01h, then
jz mainloop)
-------->but I can't execute the int, no matter what.
jmp mainloop
finish:
popl %%esp
popl %%ebp
popw %%ds
"
:
:
: "ax","bx","cx","di","bp","sp","memory"
);
waitkey();
unsetmode();
exit(0);
}
Any help at all sincerely appreciated!
--
Spawned By Rylan
Is truth beauty or beauty truth?
- Raw text -