From: baylor@ccwf.cc.utexas.edu (Baylor)
Newsgroups: comp.lang.pascal
Subject: Setting Watches
Date: 28 Dec 92 22:56:18 GMT
Organization: The University of Texas at Austin, Austin TX


	I have written some code to copy everything from 
page 0 to page 1 in ega mode. I'm trying to use assembler
under the venerable 6.0. But it doesn't work and i can't debug
it.
	I have set it's constant and variables in the procedure.
When i do, i can't watch any of these variables - the watch 
windows claims it doesn't know the symbol (below, CurrentPlane,
Page_1_Offset, ScreenHeight&Width, PlaneWords).
	When i move it out of the procedure to global constants
the procedure can't change the constants variables
(constants defined CurrentPlane : word = 8 ), even though the
watch window claims the variable was changed.
	I also think i'm getting the wrong value for tracing
registers. While watching/tracing this statement
	mov di,8000
I can see di = 65,535. Later (after the movsw which affects di)
di claims to be 8,000 then 16,000 as the code goes on.
	The code doesn't properly work. It should copy
all of plane 3 to plane 3 on page 2, plane 2 to plane 2, etc.
If i define CurrentPlane as CurrentPlane : byte = 8, 
nothing happens, and the trace claims that 
	shr CurrentPlane,1   currentplane=8 after, no matter
how often i do this. Page 2 doesn't change at all. If i 
define CurrentPlane as var CurrentPlane : byte then
something radically different happens - any color with 
bit 0 set (like blue, gray, magenta) copies over, but shows as
white, so solid blue bars will show on page 2 as a solid white bar.
	Why does this occur from simply defining a variable 
different (const CP : byte = 8 vs. var CP : byte    mov CP,8)?
	My assembler manual doesn't say too much or i'm
just looking on the wrong pages, but i can't get this to work
and i can't seem to properly trace and watch this.
 
	If anyone can give me some insight as to why position
and definition of variables affects performance and watches, 
please let me know. It's hard to fix without my poor debugger :(


Procedure Copy_Page; assembler;
(* Updates global variable Vis_Page                 *)
(* ES:DI - Destination (to)   DS:SI - Source (from) *)
(* CX    - Plane Loop         CX    - Row Loop      *)
 const
      ScreenWidth          = 320;
      ScreenHeight         = 200;

      Sequencer_Index      = $3C4;
      Color_Plane_Index    = $02;
      CurrentPlane : byte  = 8;

      Screen_Offset        = $0A000;
      ScreenBytes          = ScreenWidth div 8; (* Bytes per scanline *)
      PlaneBytes           = ScreenBytes*ScreenHeight;
      PlaneWords           = PlaneBytes div 2;
      Page_1_Offset        = ScreenBytes*ScreenHeight;
(* var
    CurrentPlane : byte;*)
  Asm
     push ds
     push es

     cld

     mov  CurrentPlane,8
     mov  cx,4   (* Num Planes *)

     mov ax,Screen_Offset
     mov ds,ax

     mov ax,Screen_Offset
     mov es,ax

 @@Set_Address:
     mov di,Page_1_Offset
     xor si,si

     @@Plane_Loop:
         push cx           (* Save Plane Number *)

         mov dx,Sequencer_Index    (* set plane *)
         mov al,Color_Plane_Index
         out dx,al
         inc dx
         mov al,CurrentPlane
         out dx,al

         mov cx,PlaneWords  (* copy that plane *)
         rep movsw

         shr CurrentPlane,1    (* next plane *)
         pop cx                (* set cx back to planes *)

         loop @@Set_Address

     pop es
     pop ds
  End;