www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/03/31/07:29:25

From: "A.Appleyard" <A DOT APPLEYARD AT fs2 DOT mt DOT umist DOT ac DOT uk>
To: DJGPP AT SUN DOT SOE DOT CLARKSON DOT EDU
Date: Fri, 31 Mar 1995 10:13:30 GMT
Subject: Running Gnu C programs under Windows

  I have Windows for Workgroups (3.1.1). I have a big Gnu C++ program called
AAEMACS that I wrote (an emacs-type text editor), which writes directly to the
text screen, and uses the mouse with my own mouse interrupt routine (thanks to
Leo Zaretski for help getting my mouse interrupt routine to run). To find
where to read its system files from, I have the line `SET AAEMACS=C:\AM' in my
AUTOXEC.BAT, and `T=getenv("AAEMACS")' in AAEMACS. That works OK under DOS.
  Recently I have made a copy of AAEMACS with all accesses to real-mode
addresses (low DOS, text screen, graphics screen) DPMI-ified (see below for
the subroutines I used). On trying to run it under Windows, I find that:-
  (1) Click the `MS-DOS' icon and run on full screen: runs normally, except:-
    (a) getenv() doesn't work and AAEMACS complains that it can't find the
`SET AAEMACS' setting, so I have to type it in (as AAEMACS asks me where its
home directory is if it can't find a `SET AAEMACS' setting).
    (b) The DOS prompt is simply C> with no current directory name.
    (c) A lot more paging in and out of store seems to happen, judging by the
amount of scritching noises from my C: drive.
    (d) Windows intercepts alt-ret. (Luckily I haven't bound any standard
emacs routines to alt-ret yet.)
  (2) Click the `MS-DOS' icon and press alt-ret to switch to running in a
window. Same as (1), the text screen is simulated correctly in the window,
but:-
    (e) Mouse clicks and movements are obeyed by Windows, not by AAEMACS.
  (3) Go into Windows File Manager, find the entry for C:\AMDPMI\EMACS.EXE,
double-click it:-
    It goes into full-screen mode like (1), and seems to behave normally,
but:-
    (f) When I am typing and reading in text mode before the emacs display
appears, print-a-character behaves oddly. (In text (= not emacsing) mode I
don't use <stdio.h> but my own text input and output routines, which use
"ah=2, dx=the character, int21()" to write to screen and "ah=7, int21(),
al:=the character" to read from screen. To echo characters as I type them, I
print each character explicitly as I read it.)
  I have go32 1.12 binutils 2.4 bison 1.22 diffutils 2.6 flex 2.4.7 gas 2.3
gcc 2.6.0 gdb 4.12 gzip 1.2.4 libg++-2.6.0 make-3.71 patch-2.1 sed-1.18
texinfo-3.10
  .................................
  I use these routines to access real-mode addresses:-
#include <dpmi.h>
#include <go32.h>
/*-----*//* conventional memory:- */
class c_mem {public: _go32_dpmi_seginfo x;
inline c_mem(int nbytes){x.size=nbytes; _go32_dpmi_allocate_dos_memory(&x);};
inline ~c_mem(){_go32_dpmi_free_dos_memory(&x);};};
/* typedef struct { u_long size, pm_offset;
      u_short pm_selector, rm_offset, rm_segment; } _go32_dpmi_seginfo; */
/*-----*/
class c_byte_addr; class c_short_addr;
/*-----*/
class c_byte {public: uns int addr;
inline c_byte_addr&adr();
inline char val(){char c; dosmemget(addr,1,&c); return c;};
inline void operator=(char c){dosmemput(&c,1,addr);};
inline char(){char c; dosmemget(addr,1,&c); return c;};};
/*-----*/
class c_byte_addr {public: uns int addr;
inline c_byte_addr(uns int Addr=0){addr=Addr;};
inline c_byte_addr(uns short Seg,uns short Offset){addr=Seg*16+Offset;};
inline c_byte_addr(c_mem m){addr=m.x.rm_segment*16+m.x.rm_offset;};
inline c_byte operator*(){return*(c_byte*)this;};
inline c_byte operator[](int i){c_byte x; x.addr=addr+i; return x;};};
/*-----*/
inline c_byte_addr&c_byte::adr(){return*(c_byte_addr*)this;}
/*-----*/
class c_short {public: uns int addr;
inline short(){short c; dosmemget(addr,2,&c); return c;};
inline short val(){short c; dosmemget(addr,2,&c); return c;};
inline c_short_addr&adr();
inline uns short operator=(short c){dosmemput(&c,2,addr); return c;};
inline void operator+=(int c){*this=(*this).val()+c;};
inline void operator&=(int c){*this=(*this).val()&c;};
inline c_byte Char(){return*(c_byte*)this;}
inline c_byte color(){return *c_byte_addr(addr+1);};};
/*-----*/
class c_short_addr {public: uns int addr;
inline c_short_addr(uns int Addr=0){addr=Addr;};
inline c_short_addr(c_mem m){addr=m.x.rm_segment*16+m.x.rm_offset;};
inline c_short_addr(uns short Seg,uns short Offset){addr=Seg*16+Offset;};
inline c_short_addr operator+(int i){c_short_addr x; x.addr=addr+2*i;return x;};
inline c_short_addr operator-(int i){c_short_addr x; x.addr=addr-2*i;return x;};
inline void operator+=(int i){addr+=2*i;};
inline void operator++(){addr+=2;};
inline c_short push(int i){dosmemput(&i,2,addr); addr+=2;};
inline void operator=(c_short_addr p){addr=p.addr;};
inline int operator-(c_short_addr x){return (addr-x.addr)/2;};
inline int operator>=(c_short_addr p){return addr>=p.addr;};
inline int operator< (c_short_addr p){return addr< p.addr;};
inline c_short operator*(){return*(c_short*)this;};
inline c_short operator[](int i){c_short x; x.addr=addr+2*i; return x;};};
/*-----*/
extern void newcolor(c_short_addr x,int from,int to,char c);
inline c_short_addr&c_short::adr(){return*(c_short_addr*)this;}
inline void c_put(c_short_addr x,short*y,int n){dosmemput(y,n*2,x.addr);};
inline void c_get(short*y,c_short_addr x,int n){dosmemget(x.addr,n*2,y);};
extern void c_put_color(c_short_addr x,char*y,int n,byte color);
/*-----*/
/*-----*/
void c_put_color(c_short_addr x,char*y,int n,byte color){if(n<0) n=strlen(y);
int i; short s[n]; for(i=0;i<n;i++) s[i]=(y[i]&255)+(color<<8); c_put(x,s,n);}
/*-----*/
void newcolor(c_short_addr x,int from,int to, char c) {
short s[to-from]; int i; uns short j; c_get(s,x+from,to-from);
for(i=from;i<to;i++) {j=s[i-from]; if((j>>8)!=Red) s[i-from]=(j&255)+(c<<8);}
c_put(x+from,s,to-from);}

- Raw text -


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