delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1993/08/23/22:13:48

Date: Mon, 23 Aug 93 21:53:11 EDT
From: peprbv AT cfa0 DOT harvard DOT edu (Bob Babcock)
To: WEIMER AT JUNCOL DOT JUNIATA DOT EDU
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Far Pointers

>I'd try using MK_FP, but DJGPP gives a 'parse error' before '_seg' anda 'parse
>error' before 'ofs'. Any clues on how to get this working?

If you are not using DPMI, try the following definition of MK_FP
   #define MK_FP(seg,ofs)  ((void far *) \
          (((unsigned long)(seg) << 4) + (unsigned)(ofs)) + 0xe0000000)

The first MB of memory gets mapped to 0xe0000000.  But if you are using DPMI,
this will not work because DPMI 0.9 does not allow mapping the first MB into
the address space.  What I did was to take code which worked under Borland C,
got assembly language output from gcc, modified the assembly language code to
load a selector for the first MB into gs and added gs: overrides to the memory
references.  Following is a simple example of the C original and the modified
assembly language.  This code works with or without DPMI, requires djgpp 1.10.

/* normal_out(n) - set n characters already on screen to normal color
   starting at the current cursor position.  If n=0, do one character.
   No action if doing screen output with DOS calls
 */
void normal_out(short n)
   {
   char *scrptr;

   scrptr = 1 + (char *)MK_FP(Screen_seg, Screen);
   if(DOS_CALLS == Display_type)
      return;
   do {
      *scrptr = Norm_attr;
      scrptr += 2;
      } while(--n > 0);
   }

.globl  _normal_out
_normal_out:
        pushl   %ebp
        movl    %esp,%ebp
        pushl   %ebx
        movw    8(%ebp),%cx
        movzwl  _Screen_seg,%edx
        sall    $4,%edx
        movzwl  __core_select,%eax   /* __core_select is set up by go32 */
        mov     %ax,%gs
        movzwl  _Screen,%eax
        leal    1(%eax,%edx),%edx
        cmpw    $0,_Display_type
        je      L87
        .align  2,0x90
L89:
        movb    _Norm_attr,%bl
        movb    %bl,%gs:(%edx)      /* I added gs: override here */
        addl    $2,%edx
        decw    %cx
        testw   %cx,%cx
        jg      L89
L87:
        movl    -4(%ebp),%ebx
        leave
        ret

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019