Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Another _Mem function program
#1
Here is my first stab at yet another _Mem function set program:

This is my first lame attempt of using _Mem functions.. Wink 

Let me know if anything needs to be added or is incorrect..

-ejo

Code: (Select All)

Rem example using _mem functions. v1.0a 01/30/2025 QB64 PD 2025.
Rem  written by Erik Jon Oredson at eoredson@gmail.com
Rem new version 2.0a adds display function.
$Checking:Off
_ScreenMove _Middle
Width 80, 25
Dim m As _MEM
Dim n As _MEM
Dim p As _Offset
Color 15
Print "Mem sample program v2.0a"
Print "Mem value(10-32767)";
Input t
If t >= 10 And t <= 32767 Then
Else
  End
End If
l$ = LTrim$(Str$(t))
l = Len(l$) ' length of mem value

' define length of memory buffer
m = _MemNew(t * l + l)
n = _MemNew(t * l + l)
p = m.TYPE

' perform the memory functions
GoSub PutMem
GoSub CopyMem
GoSub GetMem
GoSub FreeMem

' take apart the memory buffer
Color 14
Print "Display memory buffer."
Print " Memtype:"; p ' ; "("; _Bin$(p); ")"
For q = 1 To t
  z = Int(Val(Mid$(b$, (q - 1) * l + 1, l)))
  Print z;
Next
Print
x = More
Color 7
End

' store the memory buffer
PutMem:
Color 14
For q = 1 To t
  x$ = String$(l, "0")
  s$ = s$ + Right$(x$ + LTrim$(Str$(q)), l)
Next
Print "Store memory buffer."
x = Display(s$)
_MemPut m, m.OFFSET, s$
Return

' copy the memory buffer
CopyMem:
Color 14
s$ = Space$(t * l)
_MemGet m, m.OFFSET, s$
Print "Copy memory buffer."
x = Display(s$)
_MemCopy m, m.OFFSET, m.SIZE To n, n.OFFSET
Return

' read the memory buffer
GetMem:
Color 14
b$ = Space$(t * l)
_MemGet n, n.OFFSET, b$
Print "Read memory buffer."
x = Display(b$)
Return

' always clear the memory when done
FreeMem:
Color 14
Print "Free memory buffer."
_MemFree m: _MemFree n
x = More
Return

' prompt for next display
Function More
  Color 15
  Print "-more-";
  Do
      _Limit 50
      x$ = InKey$
      If Len(x$) Then
        Print
        Exit Do
      End If
  Loop
  More = -1
End Function

' prompt for next display
Function MoreX
  Color 15
  Print "-next-";
  Do
      _Limit 50
      x$ = InKey$
      If Len(x$) Then
        Print
        Exit Do
      End If
  Loop
  MoreX = -1
End Function

Function Display (o$)
  c = -1
  For d = 1 To Len(o$)
      c = c + 1
      If c >= 22 * 80 Then
        c = 0
        Print
        x = MoreX
      End If
      Color 14
      Print Mid$(o$, d, 1);
  Next
  Print
  x = More
  Display = -1
End Function


[Image: memory.png]


Attached Files
.zip   MEMORY.ZIP (Size: 1.03 KB / Downloads: 37)
Reply


Messages In This Thread
Another _Mem function program - by eoredson - 01-30-2025, 05:30 AM
RE: Another _Mem function program - by eoredson - 01-31-2025, 05:35 AM



Users browsing this thread: 1 Guest(s)