VERSION 5.00
Begin VB.Form Form1 
   BorderStyle     =   1  'Œ()
   Caption         =   "Sample system area"
   ClientHeight    =   5295
   ClientLeft      =   3750
   ClientTop       =   2910
   ClientWidth     =   8280
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   5295
   ScaleWidth      =   8280
   Begin VB.CheckBox chkAuto 
      Caption         =   "Auto update"
      Height          =   375
      Left            =   2880
      TabIndex        =   7
      Top             =   1080
      Width           =   1455
   End
   Begin VB.CommandButton cmdRead 
      Caption         =   "Read"
      Height          =   375
      Left            =   6720
      TabIndex        =   6
      Top             =   600
      Width           =   975
   End
   Begin VB.TextBox txtData 
      BeginProperty Font 
         Name            =   "lr SVbN"
         Size            =   12
         Charset         =   128
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   3135
      Left            =   240
      MultiLine       =   -1  'True
      ScrollBars      =   2  '
      TabIndex        =   3
      Top             =   1560
      Width           =   7935
   End
   Begin VB.TextBox txtOffset 
      BeginProperty Font 
         Name            =   "lr SVbN"
         Size            =   12
         Charset         =   128
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   4080
      TabIndex        =   2
      Top             =   600
      Width           =   2535
   End
   Begin VB.CommandButton cmdCurRead 
      Caption         =   "Update"
      Height          =   375
      Left            =   2880
      TabIndex        =   0
      Top             =   600
      Width           =   975
   End
   Begin VB.Timer Timer1 
      Enabled         =   0   'False
      Interval        =   100
      Left            =   7560
      Top             =   0
   End
   Begin VB.Label Label2 
      Caption         =   "SET OFFSET"
      Height          =   255
      Left            =   4080
      TabIndex        =   5
      Top             =   240
      Width           =   2415
   End
   Begin VB.Label lblCurOffset 
      BeginProperty Font 
         Name            =   "lr SVbN"
         Size            =   12
         Charset         =   128
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   735
      Left            =   240
      TabIndex        =   4
      Top             =   600
      Width           =   2415
   End
   Begin VB.Label Label1 
      Caption         =   "SYSTEM CURRENT OFFSET"
      Height          =   255
      Left            =   240
      TabIndex        =   1
      Top             =   240
      Width           =   2415
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private m_CurOffset As Long
Private intData As Integer

Private Function getCurrentOffset() As Long
    Dim curOffset As Long
    ' JgItZbg̎擾֐Ăяo
    If fcrasSRAMGetSystemCurrent(curOffset) = 0 Then
        lblCurOffset.Caption = Right("00000000" & Hex(curOffset), 8) & IIf(Timer1.Enabled, vbCrLf & "Auto", "")
        txtOffset.Text = Right("00000000" & Hex(curOffset), 8)
        getCurrentOffset = curOffset
    
    Else
        lblCurOffset.Caption = "Failed"
        getCurrentOffset = -1
    End If
    
End Function

Private Sub dispData(dwOffset As Long)
    Dim intCount As Integer
    Dim intCountData As Integer
    Dim datData As Date
    Dim strData As String
    Dim byDate(5) As Byte
    Dim byReadData(57) As Byte
    Dim workOffset As Long
    Dim strTxtDat As String
    
    ' OǂݏoOffsetƈقȂ邩A
    ' ܂́AXVłȂ΁Aĕ\sB
    If (m_CurOffset <> dwOffset) Or (Not Timer1.Enabled) Then
        strTxtDat = ""
        workOffset = dwOffset
        For intCount = 0 To 10
            ' [Üǂݏo
            If fcrasSRAMRead(workOffset, byDate(0), byReadData(0)) = 0 Then
                '@f[^̕ϊ
                strData = 2000 + byDate(0) & "/" & byDate(1) & "/" & byDate(2) & " " & _
                          byDate(3) & ":" & byDate(4) & ":" & byDate(5) & vbCrLf
                If IsDate(strData) Then
                    datData = CDate(strData)
                Else
                    Exit For
                End If
                strTxtDat = strTxtDat & "Date:" & Format(datData, "yyyy/mm/dd hh:nn:ss") & vbCrLf

                strTxtDat = strTxtDat & "          00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F" & vbCrLf
                strTxtDat = strTxtDat & "----------------------------------------------------------" & vbCrLf
                strTxtDat = strTxtDat & Right("00000000" & Hex(workOffset), 8) & ":"
                
                
                ' ǂݏof[^2sɂB
                For intCountData = 0 To 5
                    strTxtDat = strTxtDat & " " & Right("0" & Hex(byDate(intCountData)), 2)
                Next intCountData
                
                For intCountData = 0 To 57
                    strTxtDat = strTxtDat & " " & Right("0" & Hex(byReadData(intCountData)), 2)
                    If ((((intCountData + 6 + 1) Mod 16) = 0) And (intCountData <> 57)) Then
                        strTxtDat = strTxtDat & vbCrLf & Space(9)
                    End If
                Next intCountData

                strTxtDat = strTxtDat & vbCrLf
                strTxtDat = strTxtDat & "----------------------------------------------------------" & vbCrLf
                strTxtDat = strTxtDat & vbCrLf
                
                m_CurOffset = dwOffset
                
                ' 1ÕR[hǂݏoB
                workOffset = workOffset - FCSRAM_RECORD_SIZE
                If workOffset < FCSRAM_USER_START Then
                    workOffset = FCSRAM_USER_END + 1 - FCSRAM_RECORD_SIZE
                End If
            Else
                Exit For
            End If
            
        Next intCount
        '@ǂݏof[^ݒ肷B
        txtData.Text = strTxtDat
    
    End If

End Sub

Private Sub chkAuto_Click()

    Timer1.Enabled = IIf(chkAuto.Value = vbChecked, True, False)
    ' XV́Aǂݏo{^𖳌ɂB
    cmdRead.Enabled = Not Timer1.Enabled
    
    ' XVɂȂAuXVv\߂ɁAOffsetl
    'ĕ\B
    If Not (Timer1.Enabled) Then
        lblCurOffset.Caption = Right("00000000" & Hex(m_CurOffset), 8)
    End If

End Sub

Private Sub cmdCurRead_Click()
    Dim curOffset As Long
    
    curOffset = getCurrentOffset
    If curOffset >= 0 Then
        dispData (curOffset)
    End If
End Sub

Private Sub cmdRead_Click()
    Dim curOffset As Long
    
    curOffset = Val("&h" & txtOffset)
    If FCSRAM_SYSTEM_START <= curOffset And FCSRAM_SYSTEM_END >= curOffset And _
       (curOffset - FCSRAM_SYSTEM_START) Mod FCSRAM_RECORD_SIZE = 0 Then
        dispData (curOffset)
    Else
        Call MsgBox("User area is from " & Right("00000000" & Hex(FCSRAM_SYSTEM_START), 8) & " to " & Right("00000000" & Hex(FCSRAM_SYSTEM_END), 8) & ".")
    End If
End Sub

Private Sub Form_Load()
    Dim curOffset As Long
    m_CurOffset = -1
    
    Call fcsoftrasOpen

    ' Jg̏Ԃǂ
    curOffset = getCurrentOffset
    If curOffset >= 0 Then
        dispData (curOffset)
    End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Call fcsoftrasClose
End Sub

Private Sub Timer1_Timer()
    Dim curOffset As Long
    
    curOffset = getCurrentOffset
    If curOffset >= 0 Then
        dispData (curOffset)
    End If
End Sub

