www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/08/14/00:12:02

Original-Received: by jvdsys.nextjk.stuyts.nl
(FSUUCP-1.3r2) id A8029SQ Mon Aug 14, 1995 00:13:35 EDT
PP-warning: Illegal Received field on preceding line
From: jerry AT jvdsys DOT nextjk DOT stuyts DOT nl (Jerry van Dijk)
Date: Mon Aug 14, 1995 00:13:35 EDT
Subject: Optimizing problem
To: djgpp AT sun DOT soe DOT clarkson DOT edu

I took a big leap today and started to look at doing graphics using
1.12m4. However, my first program ran into problems when I tried
optimizing as mentioned in <sys/farptr>.

The program runs fine when compiled with either tcc or gcc (without any
optimizing). When any of the -O options is used, the screen results
become rather weird...

I tried _farpokeb() instead of _farnspokeb() without any difference.
Knowing a little (is there such a thing ?) 386 assembler I looked at the
generated code, but the optimized code leaves me without a clue.

(note: tabsize is set to 2!)

/*
** Graphics test program
** Should switch to VGA and draw 16 differently colored vertical bands
** For tcc 2.01 and djgpp 1.12m4
*/

#include <dos.h>
#include <stdio.h>

#ifdef __GNUC__
#include <go32.h>
#include <dpmi.h>
#include <sys/farptr.h>
#endif

void v_ver( unsigned short x,
            unsigned short y1,
            unsigned short y2,
            unsigned char color );

int main()
{
  short x;

#ifdef __GNUC__
  _go32_dpmi_registers regs;
#else
  union REGS regs;
#endif

  regs.x.ax = 0x0012;
#ifdef __GNUC__
  regs.x.ss = regs.x.sp = 0;
  _go32_dpmi_simulate_int( 0x10, &regs );
#else
  int86( 0x10, &regs, &regs );
#endif
  for ( x = 0; x < 640; x++) {
    v_ver( x, 0, 479, x / 40 );
  }

  getchar();

  regs.x.ax = 0x0003;
#ifdef __GNUC__
  regs.x.ss = regs.x.sp = 0;
  _go32_dpmi_simulate_int( 0x10, &regs );
#else
  int86( 0x10, &regs, &regs );
#endif

  return 0;
}

void v_ver( unsigned short x,
						unsigned short y1,
						unsigned short y2,
						unsigned char color )
{
  unsigned char t;
#ifdef __GNUC__
  unsigned long offset = y1 * 0x50 + x / 8 + 0xa0000;
#else
  unsigned offset = y1 * 0x50 + x / 8;
#endif
  outportb( 0x3c4, 2 );
  outportb( 0x3c5, color );
  outportb( 0x3ce, 8 );
  outportb( 0x3cf, 0x80 >> ( x & 7 ) );
#ifdef __GNUC__
  _farsetsel( _go32_conventional_mem_selector() );
#endif
  for ( ; y1 <= y2; y1++, offset += 0x50 ) {
#ifdef __GNUC__
    _farnspeekb(  offset );
    _farnspokeb(  offset, 255 );
#else
    /*
    ** Note: if the result of peekb is not assigned to something
    ** tcc seems to optimize the pokeb() out of existence...
    */
    t = peekb( 0xa000, offset );
    pokeb( 0xa000, offset, 255 );
#endif
  }
}

- Raw text -


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