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

MEMORY

View the memory


Recent questions about poking values directly into Gworlds got me thinking about what you could do with that. I remembered a program I wrote on my Atari 800 in 1985. With that computer there was a memory location that told the system where in memory the screen was located. Poke a different value in there and you viewed a different block of memory on the screen. The program below duplicates this on the Mac, using a gWorld and blockmove. When it starts you are viewing the low memory with address 0 at the upper left corner. As I understand, this area of memory holds the system global variables. You can see some changes from time to time. Move the mouse and you see some bytes change. If you scroll down to where the gWorld that this program creates is located you see some interesting feed back effects, sort of like holding two mirrors facing each other.

You control the program with the arrow keys. They move one pixel in any direction. When you holding down the option key and an arrow key at the same time you move 10 pixels. The command key moves you 100 pixels, 1,000 pixels for the shift key and 10,000 for the control key. Press the mouse button to exit the program.

I would like to flesh this out into a useful (or at least interesting) program that would label selected memory locations, jump you to selected memory locations, resize the window and display memory in different bit depths. To start with I would like to be able to find out exactly how much memory there is so I can prevent attempting to view higher memory than exists in the computer. Right now if you use the program to look too high in memory it crashes. Does anyone know how I can find important memory locations such as the starting and ending locations of each running program and the last memory location?

COMPILE 0,_caseinsensitive
DIM gkeys(7)
END GLOBALS
_WindWidth@0
_WindHeight=300
_bitDepth=32
'-----------
LOCAL FN buildGWorld(rectPtr&,depth)
  DIM t,l,b,r
  t;8 = rectPtr&
  QDErr = FN NEWGWORLD(theWorld&,depth,#@t,0,0,0)
  LONG IF QDErr : t$ = "Insufficient memory for GWorld"
    CALL PARAMTEXT(t$,"","","") : ctrl%=FN NOTEALERT(128,0)
  END IF
END FN = theWorld&
'-----------
CLEAR LOCAL
  DIM rect;8
LOCAL FN viewMemory
  WINDOW 1, "", (0,0)-(_WindWidth, _WindHeight), _dialogFrame
  CALL SETRECT(rect, 0,0,_WindWidth, _WindHeight)
  gWorldAdr&=FN buildGWorld(@rect,_bitDepth)
  LONG IF gWorldAdr&
    CALL GETGWORLD(currPort&,currDevice&)
    mapHand& = FN GETGWORLDPIXMAP(gWorldAdr&)
    locked = FN LOCKPIXELS(mapHand&)
    pixMapAdr&=FN GETPIXBASEADDR(mapHand&)
    y&=0 : x&=0
    remainderOfDivide = _WindWidth MOD 4
    wdNum=_WindWidth+4-remainderOfDivide
    bytesToMove&=_WindWidth*_WindHeight*(_bitDepth/8)
    DO
      adr&=(wdNum*(_bitDepth/8))*y&+x&*(_bitDepth/8)
      BLOCKMOVE adr&, pixMapAdr&, bytesToMove&
      CALL COPYBITS(#gWorldAdr&+2,#currPort&+2,rect.top%,rect.top%,_srcCopy,0)
      CALL GETKEYS(gkeys(0))
      adder=1
      IF gkeys(3)=1 THEN adder= 1000 'Shift key down
      IF gkeys(3)=8 THEN adder= 10000 'control key down
      IF gkeys(3)=4 THEN adder= 10 'option key down
      IF gkeys(3)=-32768 THEN adder= 100 'command key down
      SELECT
        CASE gkeys(7)=8 : x&=x&-adder 'left arrow
        CASE gkeys(7)=16 : x&=x&+adder 'right arrow
        CASE gkeys(7)=32 : y&=y&+adder 'down arrow
        CASE gkeys(7)=64 : y&=y&-adder 'up arrow
      END SELECT
      IF y&<0 THEN y&=0
      IF x&<0 THEN x&=0
    UNTIL FN BUTTON
  END IF
END FN
'-----------
FN viewMemory

Joe Lertola