FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

DRAWING

Write to the screen


Some time ago there was a question about directly writing to screen memory for high-speed graphics. I don't have the original posting, but little or no discussion resulted.
Here is a "starter" for experimentation with this dangerous but exciting technique. FN SetCPixel acts like PLOT(x,y) but is _very_ much faster. Note that the compatibility of the method with dual monitors, graphics cards etc, is doubtful.

If there are screen-blitter assembly-freaks out there, I would like very much to learn tips and improvements from them.

Robert

DIM gBaseAddr&, gRowBytes%, gHOffset, gVOffset
DIM gScrnBot, gScrnRight, gScrnLineAddr&(1024)
DIM gActualDepth
END GLOBALS

LOCAL FN MicroSeconds&
  ` dc.w $A193
END FN

' call this before drawing esp if window may have moved
LOCAL FN GetWindowParameters
  DIM aPoint.4
  gActualDepth=SYSTEM(_crntDepth)
  aPoint.h=0: aPoint.v=0
  CALL LOCALTOGLOBAL(aPoint)
  gHOffset=aPoint.h
  gVOffset=aPoint.v
END FN

' call this at start of program
LOCAL FN GetScreenParameters
  DIM pmHand&,addr&,j
  gScrnBot={REGISTER(a5)+_screenBits+10}
  gScrnRight={REGISTER(a5)+_screenBits+12}
  pmHand&=[[FN GETMAINDEVICE]+22]
  gBaseAddr&=[[pmHand&]]
  gRowBytes%={[pmHand&]+4} AND &1FFF
' 1FFF masks off hi bits indicating pixMap type
  addr&=gBaseAddr&
  FOR j=0 TO gScrnBot
    gScrnLineAddr&(j)=addr&
    addr&=addr&+gRowBytes%
  NEXT j
END FN

LOCAL FN SetCPixel (x,y,pixelByte)
' Fast alternative to MOVETO(x,y): LINE(0,0) toolbox calls
' if monitor is set to 256 colours (depth 8 bits).
' Clipped to screen area
  x= x + gHOffset ' to global coord
  y =y + gVOffset ' to global coord
  LONG IF x>=0
    LONG IF x<= gScrnRight
      IF y<=gScrnBot THEN POKE gScrnLineAddr&(y)+x,pixelByte
    END IF
  END IF
END FN

DIM L, micrs&,j
WINDOW 1

FN GetScreenParameters
FN GetWindowParameters

L=150

micrs&=FN MicroSeconds&
FOR j=1 TO L
  PLOT 200,j
NEXT j
micrs&=FN MicroSeconds&-micrs&
PRINT@(0,0) "PLOT " micrs&

micrs&=FN MicroSeconds&
FOR j=1 TO L
  CALL MOVETO(205,j): CALL LINE (0,0)
NEXT j
micrs&=FN MicroSeconds&-micrs&
PRINT@(0,1) "MOVETO LINE" micrs&"<mu>s"

'not needed here, but a good idea in general..
FN GetWindowParameters

LONG IF gActualDepth=8
  micrs&=FN MicroSeconds&
  FOR j=1 TO L
    FN SetCPixel (210,j,-1)
  NEXT j
  micrs&=FN MicroSeconds&-micrs&
  PRINT@(0,2)"FN SetCPixel" micrs&"<mu>s"
END IF

DO
UNTIL FN BUTTON


Your FN SetCPixel is also much faster than the Toolbox version of SetCPixel. I'm impressed!

Rick