SPLIT_INT.BAS, Use of MemAdress with RAMpeek


' Program SPLIT_INT.BAS
'
' Illustrates how to split an integer into high and low bytes.
'
' Provides a good example of passing by value and by reference.
'
' Note that in SplitInt, the RAM address of the variable is determined 
' using the MemAddress command.  The low and high bytes are then 
' fetched using the RAMpeek command.  Note that the BasicX stores integers
' in two consecutive bytes, with the low byte first.
'
' Compile with SerialPort.Bas
'
' Copyright, Peter H. Anderson, Baltimore, Sept, 99


Public Sub Main()

   Dim mem_adr as Integer
   Dim RAM_Ptr as Integer
   Dim mem_adr_hi as byte
   Dim mem_adr_lo as byte

   Call OpenSerialPort(2, 9600)

   mem_adr=700

   Call SplitInt(mem_adr, mem_adr_hi, mem_adr_lo)	' Split the integer
   Call PutI(mem_adr)		' display the integer
   Call PutByte(32)		' space
   Call PutB(mem_adr_hi)	' high byte
   Call PutByte(32)		' space
   Call PutB(mem_adr_lo)	' low byte

End Sub

Public Sub SplitInt(ByVal a as Integer, _
                    ByRef hi as Byte, _
                    ByRef lo as Byte)

Dim RAM_Ptr as Integer

      RAM_Ptr = MemAddress(a)
      lo = RAMpeek(RAM_Ptr)		' lo byte followed by high byte
      hi = RAMpeek(RAM_Ptr+1)
End Sub