'*******************************************************************************
'
' Copyright Michael Koecher aka six1 8/2010
' -> http://www.six1.net/ michael@koecher-web.de
'
' http://creativecommons.org/licenses/by-sa/3.0/de/
'
' Sie dьrfen:
'
' * das Werk bzw. den Inhalt vervielfдltigen, verbreiten und цffentlich zugдnglich machen
'
' * Abwandlungen und Bearbeitungen des Werkes bzw. Inhaltes anfertigen
'
' Zu Den Folgenden Bedingungen:
'
' * Namensnennung.
' Sie mьssen den Namen des Autors/Rechteinhabers in der von ihm festgelegten Weise nennen.
'
' * Keine kommerzielle Nutzung.
' Dieses Werk darf nicht fьr kommerzielle Zwecke verwendet werden.
'
' * Weitergabe unter gleichen Bedingungen.
' Wenn Sie das lizenzierte Werk bzw. den lizenzierten Inhalt bearbeiten
' oder in anderer Weise erkennbar als Grundlage fьr eigenes Schaffen verwenden,
' dьrfen Sie die daraufhin neu entstandenen Werke bzw. Inhalte nur
' unter Verwendung von Lizenzbedingungen weitergeben, die mit denen
' dieses Lizenzvertrages identisch oder vergleichbar sind.
'
' Wobei gilt:
'
' * Verzichtserklдrung
' Jede der vorgenannten Bedingungen kann aufgehoben werden, sofern Sie
' die ausdrьckliche Einwilligung des Rechteinhabers dazu erhalten.
'
' * Sonstige Rechte
' Die Lizenz hat keinerlei Einfluss auf die folgenden Rechte:
' - Die gesetzlichen Schranken des Urheberrechts und sonstigen
' Befugnisse zur privaten Nutzung
' - Das Urheberpersцnlichkeitsrecht des Rechteinhabers
' - Rechte anderer Personen, entweder am Lizenzgegenstand selber oder
' bezьglich seiner Verwendung, zum Beispiel Persцnlichkeitsrechte abgebildeter Personen.
'
' Hinweis
'
' Im Falle einer Verbreitung mьssen Sie anderen alle Lizenzbedingungen
' mitteilen, die fьr dieses Werk gelten. Am einfachsten ist es,
' einen Link auf http://creativecommons.org/licenses/by-sa/3.0/de/ einzubinden.
'
'*******************************************************************************
$nocompile
Sub Esf_spi_cs(byval Avtivate As Byte)
' Avtivate MUST BE! 0 or 1
If Avtivate = 0 Then
Set Esf_cs
Else
#if _xmega = 0
Spcr = &B01010000
Spsr.spi2x = 1
#endif
Reset Esf_cs
End If
End sub
Sub Read_file_block(byval Filename As String , Byval Startpos As Dword , Byval Length As Dword , Byval Bufferstart As Word , Byval Buffer As Dword)
Local Esf_block As Word , Esf_pos As Word , Esf_readpos As Dword
Local Payload_pos As dWord , B_b As Byte , No_of_bytes As Word
Local X_x As Word, Esf_help_block As dword
local tmp_filename as string * 40
If Esf_pfad <> "" Then
Tmp_filename = Esf_pfad + "/" + Filename
Else
Tmp_filename = Filename
End If
B_b = Esf_find_file(Tmp_filename)
B_b = 1
If B_b = 1 then
Esf_readpos = Esf_file_start + Startpos
Decr Esf_readpos
Esf_help_block = Esf_readpos ' / 256
Shift Esf_help_block , Right , 8
Esf_block = Esf_help_block
' add offset Startaddress for Filedata in ESF
Esf_block = Esf_block + 513
Esf_pos = Esf_readpos Mod 256
Call Df_pagetobuffer(1 , Esf_block)
Payload_pos = Bufferstart + 1
Length = Length + Bufferstart
'(
Print #1 , "Filename " ; Filename
Print #1 , "Startpos " ; Startpos
Print #1 , "Length " ; Length
Print #1 , "Esf_readpos " ; Esf_readpos
Print #1 , "Esf_block " ; Esf_block
Print #1 , "Esf_pos " ; Esf_pos
Print #1 , "Payload_pos " ; Payload_pos
')
' // with loop
' Buffer_address = Buffer + Bufferstart
' // with SPIIN
Buffer_address = 1
Do
Call Esf_spi_cs(1)
B_b = Buf1read ' Buffer 1 Read Op -code
Spiout B_b , 1 ' Buffer 1 Read Op -code
B_b = 0
Spiout B_b , 1
B_b = High(esf_pos) ' Don't cares
Spiout B_b , 1 ' Upper Part Of Internal Buffer Address
B_b = Low(esf_pos) ' Don't cares
Spiout B_b , 1 ' Lower Part Of Internal Buffer Address
B_b = 0
Spiout B_b , 1
No_of_bytes = 256 - Esf_pos
X_x = No_of_bytes + Payload_pos
If X_x > Length Then
No_of_bytes = Length - Payload_pos
Incr No_of_bytes
End If
'Print #1 , "No_of_bytes " ; No_of_bytes
' // with SPIIN
If No_of_bytes > 255 Then
Spiin Eth_buffer(buffer_address) , 1
Spiin Eth_buffer(buffer_address + 1) , 255
Else
Spiin Eth_buffer(buffer_address) , No_of_bytes
End If
'(
' // with loop
For X_x = 1 To No_of_bytes
Spiin B_b , 1
Out Buffer_address , B_b
'Print #1 , Chr(b_b)
Incr Buffer_address
Next
')
Call Esf_spi_cs(0)
Buffer_address = Buffer_address + No_of_bytes
Payload_pos = Payload_pos + No_of_bytes
Incr Esf_block
Call Df_pagetobuffer(1 , Esf_block)
Esf_pos = 0
Loop Until Payload_pos >= Length
'Print #1 , "Payload_pos " ; Payload_pos
End If
End Sub
Sub Chg_dir(byval Directory As String)
' nothing to do. There is NO DIR on ESF
Esf_pfad = Trim(directory)
End Sub
Function Get_filelen(byval Filename As String) As Dword
local tmp_filename as string * 40
If Esf_pfad <> "" Then
Tmp_filename = Esf_pfad + "/" + Filename
Else
Tmp_filename = Filename
End If
If Esf_find_file(tmp_filename) = 1 Then
Get_filelen = Esf_file_len
Else
Get_filelen = 0
End If
End Function
Function Read_file(byval Filename As String , Byval Directory As String) As String
local tmp_filename as string * 40
Local Esf_block As Word , Esf_pos As Word , Esf_readpos As Dword
Local Payload_pos As dWord , B_b As Byte , No_of_bytes As Word
Local X_x As Word, Esf_help_block As dword
Read_file = ""
If Directory <> "" Then
Tmp_filename = Directory + "/" + Filename
Else
Tmp_filename = Filename
End If
B_b = Esf_find_file(tmp_filename)
If B_b = 1 And Esf_file_len < 256 Then
Esf_readpos = Esf_file_start
' Decr Esf_readpos
Esf_help_block = Esf_readpos ' / 256
Shift Esf_help_block , Right , 8
Esf_block = Esf_help_block
' add offset Startaddress for Filedata in ESF
Esf_block = Esf_block + 513
Esf_pos = Esf_readpos Mod 256
Call Df_pagetobuffer(1 , Esf_block)
Payload_pos = 1
'(
Print #1 , "Filename " ; Filename
Print #1 , "Length " ; Length
Print #1 , "Esf_readpos " ; Esf_readpos
Print #1 , "Esf_block " ; Esf_block
Print #1 , "Esf_pos " ; Esf_pos
Print #1 , "Payload_pos " ; Payload_pos
')
' // with loop
' Buffer_address = Buffer + Bufferstart
' // with SPIIN
Buffer_address = 1
Do
Call Esf_spi_cs(1)
B_b = Buf1read ' Buffer 1 Read Op -code
Spiout B_b , 1 ' Buffer 1 Read Op -code
B_b = 0
Spiout B_b , 1
B_b = High(esf_pos) ' Don't cares
Spiout B_b , 1 ' Upper Part Of Internal Buffer Address
B_b = Low(esf_pos) ' Don't cares
Spiout B_b , 1 ' Lower Part Of Internal Buffer Address
B_b = 0
Spiout B_b , 1
No_of_bytes = 256 - Esf_pos
X_x = No_of_bytes + Payload_pos
If X_x > Esf_file_len Then
No_of_bytes = Esf_file_len - Payload_pos
Incr No_of_bytes
End If
For X_x = 1 To No_of_bytes
Spiin B_b , 1
Read_file = Read_file + Chr(b_b)
Next
Call Esf_spi_cs(0)
Payload_pos = Payload_pos + No_of_bytes
Incr Esf_block
Call Df_pagetobuffer(1 , Esf_block)
Esf_pos = 0
Loop Until Payload_pos >= Esf_file_len
End If
End Function
Function Read_line(byval Filename As String , Byval Directory As String, byval art as byte) As String
local tmp_filename as string * 40
Local Esf_block As Word , Esf_pos As Word , Esf_readpos As Dword
Local Payload_pos As dWord , B_b As Byte , No_of_bytes As Word
Local X_x As Word, Esf_help_block As dword
Local Total As Word
Read_line = ""
If Directory <> "" Then
Tmp_filename = Directory + "/" + Filename
Else
Tmp_filename = Filename
End If
B_b = Esf_find_file(tmp_filename)
If B_b = 1 Then
' Reset Pointer to first line
If Art = 1 Then File_read_line_pos = 0
Esf_readpos = Esf_file_start + File_read_line_pos
Total = File_read_line_pos
If Total >= Esf_file_len Then
Read_line = ""
Exit Function
End If
' Decr Esf_readpos
Esf_help_block = Esf_readpos ' / 256
Shift Esf_help_block , Right , 8
Esf_block = Esf_help_block
' add offset Startaddress for Filedata in ESF
Esf_block = Esf_block + 513
Esf_pos = Esf_readpos Mod 256
Call Df_pagetobuffer(1 , Esf_block)
Payload_pos = 1
'(
Print #1 , "Filename " ; Filename
Print #1 , "Length " ; Length
Print #1 , "Esf_readpos " ; Esf_readpos
Print #1 , "Esf_block " ; Esf_block
Print #1 , "Esf_pos " ; Esf_pos
Print #1 , "Payload_pos " ; Payload_pos
')
' // with loop
' Buffer_address = Buffer + Bufferstart
' // with SPIIN
Buffer_address = 1
Do
Call Esf_spi_cs(1)
B_b = Buf1read ' Buffer 1 Read Op -code
Spiout B_b , 1 ' Buffer 1 Read Op -code
B_b = 0
Spiout B_b , 1
B_b = High(esf_pos) ' Don't cares
Spiout B_b , 1 ' Upper Part Of Internal Buffer Address
B_b = Low(esf_pos) ' Don't cares
Spiout B_b , 1 ' Lower Part Of Internal Buffer Address
B_b = 0
Spiout B_b , 1
No_of_bytes = 256 - Esf_pos
X_x = No_of_bytes + Payload_pos
If X_x > Esf_file_len Then
No_of_bytes = Esf_file_len - Payload_pos
Incr No_of_bytes
End If
For X_x = 1 To No_of_bytes
Spiin B_b , 1
If B_b <> 13 Then
Read_line = Read_line + Chr(b_b)
Else
Incr X_x
Exit For
End If
Next
Call Esf_spi_cs(0)
Total = Total + x_x
Payload_pos = Payload_pos + x_x
File_read_line_pos = File_read_line_pos + X_x
If B_b <> 13 Then
Incr Esf_block
Call Df_pagetobuffer(1 , Esf_block)
Esf_pos = 0
End If
Loop Until Payload_pos >= 255 Or B_b = 13 Or Total >= Esf_file_len
End If
End Function
Sub Get_filedate(byval Filename As String , Byref File_date As String)
File_date = "00.00.0000"
End Sub
Sub Get_filetime(byval Filename As String , Byref File_time As String)
File_time = "00:00:00"
End Sub
Sub List_first_file(byref Filename As String)
End Sub
Sub List_next_file(byref Filename As String)
End Sub
'Look -up Table For These Sizes - > 512k , 1m , 2m , 4m , 8m , 16m , 32m , 64m
Df_pagebits_data:
Data 9 , 9 , 9 , 9 , 9 , 10 , 10 , 11
'Look -up Table For These Sizes - > 512k , 1m , 2m , 4m , 8m , 16m , 32m , 64m
Df_pagesize_data:
Data 264% , 264% , 264% , 264% , 264% , 528% , 528% , 1056%
Sub Df_init()
Local B_b As Byte
Local Index_copy As Byte
Local Res_byte As Byte
' Set Esf_cs
' Call Deactivate_all_spi_units
' Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 4 , Noss = 1 , Spiin = 0 ' Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = High , Phase = 1 , Clockrate = 4 , Noss = 1 , Spiin = 0
' Set Spsr.spi2x
' Spiinit
'256 Byte Mode
Call Esf_spi_cs(1)
B_b = &H3D
Spiout B_b , 1
B_b = &H2A
Spiout B_b , 1
B_b = &H80
Spiout B_b , 1
B_b = &HA6
Spiout B_b , 1
'with special Thanks to Erwin who find out, that the 4ms delay is missing!
Waitms 4
'Power cycle the device...
Call Esf_spi_cs(0)
Status_register_value = Df_read_status()
Index_copy = Df_read_status() And &H38 ' Get The Size Info From Status Register
Shift Index_copy , Right , 3
'Print #1 , "Status: " ; Index_copy
Decr Index_copy
Pagesize = Lookup(index_copy , Df_pagesize_data)
Pagebits = Lookup(index_copy , Df_pagebits_data)
'Print #1 , "Pagebits: " ; Pagebits
'Print #1 , "Pagesize: " ; Pagesize
'Erase sector protect
Call Esf_spi_cs(1)
B_b = &H3D
Spiout B_b , 1
B_b = &H2A
Spiout B_b , 1
B_b = &H7F
Spiout B_b , 1
B_b = &HCF
Spiout B_b , 1
B_b = 0
Spiout B_b , 1
Spiout B_b , 1
Spiout B_b , 1
Spiout B_b , 1
Spiout B_b , 1
Spiout B_b , 1
Spiout B_b , 1
Spiout B_b , 1
Call Esf_spi_cs(0)
End Sub
Sub Df_chip_erase()
Local B_b As Byte
Call Esf_spi_cs(1)
B_b = &HC7
Spiout B_b , 1
B_b = &H94
Spiout B_b , 1
B_b = &H80
Spiout B_b , 1
B_b = &H9A
Spiout B_b , 1
Call Esf_spi_cs(0)
End Sub
Function Df_bufferreadbyte(byval Bufferno As Byte , Byval Intpageadr As Word) As Byte
Local B_b As Byte
Call Esf_spi_cs(1)
If Bufferno = 1 Then ' Read Byte From Buffer 1
B_b = Buf1read
Else
B_b = Buf2read
End If
Spiout B_b , 1 ' Buffer 1 Read Op -code
B_b = 0
Spiout B_b , 1
B_b = High(intpageadr) ' Don't cares
Spiout B_b , 1 ' Upper Part Of Internal Buffer Address
B_b = Low(intpageadr)
Spiout B_b , 1 ' Lower Part Of Internal Buffer Address
B_b = 0
Spiout B_b , 1
Spiin Df_bufferreadbyte , 1 ' Read Byte
Call Esf_spi_cs(0)
End Function
Sub Df_bufferwritebyte(byval Bufferno As Byte , Byval Intpageadr As Word , Byval Databyte As Byte)
Local B_b As Byte
Call Esf_spi_cs(1)
If Bufferno = 1 Then ' write Byte to Buffer 1
B_b = Buf1write
Else
B_b = Buf2write ' write Byte to Buffer 2
End If
Spiout B_b , 1
B_b = 0
Spiout B_b , 1
B_b = High(intpageadr) ' Don't cares
Spiout B_b , 1 ' Upper Part Of Internal Buffer Address
B_b = Low(intpageadr)
Spiout B_b , 1 ' Lower Part Of Internal Buffer Address
Spiout Databyte , 1
Call Esf_spi_cs(0)
End Sub
'--------------------------------------------------------------------------------
' Function name : df_read_status
'
' Returns : One status byte. Consult Dataflash datasheet for further decoding info
'
' Parameters : None
'
' Purpose : Status info concerning the Dataflash is busy or not.
' Status info concerning compare between buffer and flash page
' Status info concerning size of actual device
'
'Table 11-1. Status Register Format
'Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
'RDY/BUSY COMP 0 1 1 1 PROTECT PAGE SIZE
'--------------------------------------------------------------------------------
Function Df_read_status() As Byte
Local B_b As Byte
Call Esf_spi_cs(1)
B_b = Statusreg
Spiout B_b , 1 ' Send Status Register Read Op -code
Spiin Df_read_status , 1 ' Send Status Register Read Op -code
B_b = 0
Spiout B_b , 1 ' Dummy Write To Get Result
Spiin Df_read_status , 1 ' Dummy Write To Get Result
Call Esf_spi_cs(0)
End Function
'--------------------------------------------------------------------------------
'
' Function name : DF_PageToBuffer
'
' Returns : None
'
' Parameters : BufferNo -> Decides usage of either buffer 1 or 2
' PageAdr -> Address of page to be transferred to buffer
'
' Purpose : Transfers a page from flash to dataflash SRAM buffer
'
'--------------------------------------------------------------------------------
Sub Df_pagetobuffer(byval Bufferno As Byte , Byval Pageadr As Word)
Local B_b As Byte , B_c As Byte
Call Esf_spi_cs(1)
If Bufferno = 1 Then
B_b = Flashtobuf1transfer
Else
B_b = Flashtobuf2transfer
End If
Spiout B_b , 1
B_c = High(pageadr)
Spiout B_c , 1 ' Dummy Write To Get Result
B_c = Low(pageadr)
Spiout B_c , 1
B_b = 0
Spiout B_b , 1 ' Dummy Write
Call Esf_spi_cs(0)
Call Esf_spi_cs(1)
Do
B_b = Df_read_status()
Loop Until B_b.7 = 1
Call Esf_spi_cs(0)
End Sub
Sub Df_buffertopage(byval Bufferno As Byte , Byval Pageadr As Word)
Local B_b As Byte , B_c As Byte
Call Esf_spi_cs(1)
If Bufferno = 1 Then
B_b = Buf1toflashwe
Else
B_b = Buf2toflashwe
End If
Spiout B_b , 1
B_c = High(pageadr)
Spiout B_c , 1 ' Dummy Write To Get Result
B_c = Low(pageadr)
Spiout B_c , 1
B_b = 0
Spiout B_b , 1 ' Dummy Write
Call Esf_spi_cs(0)
Waitus 10
Call Esf_spi_cs(1)
Do
B_b = Df_read_status()
Loop Until B_b.7 = 1
Call Esf_spi_cs(0)
End Sub
'--------------------------------------------------------------------------------
'
' Function name : DF_BufferReadArray
'
' Returns : None
'
' Parameters : BufferNo -> Decides usage of either buffer 1 or 2
' IntPageAdr -> Internal page address
' No_of_bytes -> Number of bytes to be read
' *BufferPtr -> address of buffer to be used for read bytes
'
' Purpose : Reads one or more bytes from one of the dataflash
' internal SRAM buffers, and puts read bytes into
' buffer pointed to by *BufferPtr
'
'--------------------------------------------------------------------------------
Sub Df_bufferreadarray(byval Bufferno As Byte , Byval Intpageadr As Word , Byval No_of_bytes As Word , Byref Bufferptr As Word)
Local B_b As Byte
Call Esf_spi_cs(1)
If Bufferno = 1 Then ' Read Byte From Buffer 1
B_b = Buf1read ' Buffer 1 Read Op -code
Else
B_b = Buf2read ' Buffer 2 Read Op -code
End If
Spiout B_b , 1 ' Buffer 1 Read Op -code
B_b = 0
Spiout B_b , 1
B_b = High(intpageadr) ' Don't cares
Spiout B_b , 1 ' Upper Part Of Internal Buffer Address
B_b = Low(intpageadr) ' Don't cares
Spiout B_b , 1 ' Lower Part Of Internal Buffer Address
Spiin Bufferptr , No_of_bytes
Call Esf_spi_cs(0)
End Sub
'--------------------------------------------------------------------------------
'
' Function name : DF_BufferWriteEnable
'
' Returns : None
'
' Parameters : IntPageAdr -> Internal page address to start writing from
' BufferAdr -> Decides usage of either buffer 1 or 2
'
' Purpose : Enables continous write functionality to one of the dataflash buffers
' buffers. NOTE : User must ensure that CS goes high to terminate
' this mode before accessing other dataflash functionalities
'
'--------------------------------------------------------------------------------
Sub Df_bufferwriteenable(byval Bufferno As Byte , Byval Intpageadr As Word)
Local B_b As Byte
Call Esf_spi_cs(1)
If Bufferno = 1 Then ' Read Byte From Buffer 1
B_b = Buf1write ' Buffer 1 Read Op -code
Else
B_b = Buf2write ' Buffer 2 Read Op -code
End If
Spiout B_b , 1 ' Buffer 1 Read Op -code
B_b = 0
Spiout B_b , 1 ' Don't cares
B_b = High(intpageadr)
Spiout B_b , 1 ' Upper Part Of Internal Buffer Address
B_b = Low(intpageadr)
Spiout B_b , 1 ' Lower Part Of Internal Buffer Address
Call Esf_spi_cs(0)
End Sub
'--------------------------------------------------------------------------------
'
' Function name : DF_BufferWriteStr
'
' Returns : None
'
' Parameters : BufferNo -> Decides usage of either buffer 1 or 2
' IntPageAdr -> Internal page address
' No_of_bytes -> Number of bytes to be written
' *BufferPtr -> address of buffer to be used for copy of bytes
' from AVR buffer to dataflash buffer 1 (or 2)
'
' Purpose : Copies one or more bytes to one of the dataflash
' internal SRAM buffers from AVR SRAM buffer
' pointed to by *BufferPtr
'
'--------------------------------------------------------------------------------
Sub Df_bufferwritestr(byval Bufferno As Byte , Byval Intpageadr As Word , Byval No_of_bytes As Word , Byref Bufferptr As Word)
Local B_b As Byte
Call Esf_spi_cs(1)
If Bufferno = 1 Then ' Read Byte From Buffer 1
B_b = Buf1read ' Buffer 1 Read Op -code
Else
B_b = Buf2read ' Buffer 2 Read Op -code
End If
Spiout B_b , 1 ' Buffer 1 Read Op -code
B_b = 0
Spiout B_b , 1 ' Don't cares
B_b = High(intpageadr)
Spiout B_b , 1 ' Upper Part Of Internal Buffer Address
B_b = Low(intpageadr)
Spiout B_b , 1 ' Lower Part Of Internal Buffer Address
Spiout Bufferptr() , No_of_bytes
Call Esf_spi_cs(0)
End Sub
'--------------------------------------------------------------------------------
'
' Function name : Cont_Flash_Read_Enable
'
' Returns : None
'
' Parameters : PageAdr -> Address of flash page where cont.read starts from
' IntPageAdr -> Internal page address where cont.read starts from
'
' Purpose : Initiates a continuous read from a location in the DataFlash
'
'--------------------------------------------------------------------------------
Sub Cont_flash_read_enable(byval Pageadr As Word , Byval Intpageadr As Word)
Local B_b As Byte , W_w As Word
Call Esf_spi_cs(1)
B_b = Contarrayread
Spiout B_b , 1
W_w = Pageadr ' Upper Part Of Page Address
B_b = 16 - Pagebits
Shift W_w , Right , B_b
Spiout W_w , 1 ' Dummy Write To Get Result
W_w = Pageadr ' Lower Part Of Page Address
B_b = Pagebits - 8
Shift W_w , Left , B_b
Spiout W_w , 1
B_b = 0
Spiout B_b , 1 ' Perform 4 Dummy Writes
Spiout B_b , 1 ' In Order To Intiate Dataflash
Spiout B_b , 1 ' Address Pointers
Spiout B_b , 1
Call Esf_spi_cs(0)
End Sub
'-------------------------------------------------------------------------------
' ESF_filelist show filelist in ESF
'-------------------------------------------------------------------------------
Sub Esf_filelist()
' Structure of Filetable:
' &H5A <-- valid Filetable
' 1 Byte length filename|filename|3 Byte size|3 Bytes Startpos|
' 1 Byte length filename|filename|3 Byte size|3 Bytes Startpos|
' ...
' $00 <-- end of filetable
Local Filesize As Dword , Filepos As Dword , Filname As String * 30 , Filenamelen As Byte
Local Page As Word , Pagepos As Word , Valid_files As Byte ', Count_pos As Dword
Local Rx_byte As Byte , Ready As Byte , X As Byte
Pagepos = 0
Ready = 0
Page = 513
Call Df_pagetobuffer(1 , Page)
Valid_files = Df_bufferreadbyte(1 , 0)
Call Esf_check_pagepos(pagepos , Page)
If Valid_files = &H5A Then
Do
Filenamelen = Df_bufferreadbyte(1 , Pagepos)
Call Esf_check_pagepos(pagepos , Page)
If Filenamelen = 0 Then
Ready = 1
End If
If Ready = 0 Then
Filname = ""
For X = 1 To Filenamelen
Rx_byte = Df_bufferreadbyte(1 , Pagepos)
Filname = Filname + Chr(rx_byte)
Call Esf_check_pagepos(pagepos , Page)
Next
Esf_file_len = 0
Esf_file_len_1 = Df_bufferreadbyte(1 , Pagepos)
Call Esf_check_pagepos(pagepos , Page)
Esf_file_len_2 = Df_bufferreadbyte(1 , Pagepos)
Call Esf_check_pagepos(pagepos , Page)
Esf_file_len_3 = Df_bufferreadbyte(1 , Pagepos)
Call Esf_check_pagepos(pagepos , Page)
Esf_file_start = 0
Esf_file_start_1 = Df_bufferreadbyte(1 , Pagepos)
Call Esf_check_pagepos(pagepos , Page)
Esf_file_start_2 = Df_bufferreadbyte(1 , Pagepos)
Call Esf_check_pagepos(pagepos , Page)
Esf_file_start_3 = Df_bufferreadbyte(1 , Pagepos)
Call Esf_check_pagepos(pagepos , Page)
Print #1 , Filname ; " Size: " ; Str(Esf_file_len) ; " Pos: " ; Str(esf_file_start)
End If
Loop Until Ready = 1
End If
End Sub
Function Esf_find_file(byval Searchfile As String) As Byte
' Structure of Filetable:
' &H5A <-- valid Filetable
' 1 Byte length filename|filename|3 Byte size|3 Bytes Startpos|
' 1 Byte length filename|filename|3 Byte size|3 Bytes Startpos|
' ...
' $00 <-- end of filetable
Local Filename As String * 50 , Filenamelen As Byte
Local Page As Word , Pagepos As Word , Valid_files As Byte ' , Count_pos As Dword
Local Rx_byte As Byte , Ready As Byte , X As Byte
Pagepos = 0
Ready = 0
Esf_file_len = 0
Esf_file_start = 0
Esf_find_file = 0
Page = 513
Call Df_pagetobuffer(1 , Page)
Searchfile = Ucase(searchfile)
Valid_files = Df_bufferreadbyte(1 , 0)
If Valid_files = &H5A Then
Call Esf_check_pagepos(pagepos , Page)
Do
Filenamelen = Df_bufferreadbyte(1 , Pagepos)
If Filenamelen = 0 Then
Ready = 1
End If
If Ready = 0 Then
Call Esf_check_pagepos(pagepos , Page)
Filename = ""
If Filenamelen > 50 Then Filenamelen = 50
For X = 1 To Filenamelen
Rx_byte = Df_bufferreadbyte(1 , Pagepos)
Filename = Filename + Chr(rx_byte)
Call Esf_check_pagepos(pagepos , Page)
Next
Esf_file_len = 0
Esf_file_len_1 = Df_bufferreadbyte(1 , Pagepos)
Call Esf_check_pagepos(pagepos , Page)
Esf_file_len_2 = Df_bufferreadbyte(1 , Pagepos)
Call Esf_check_pagepos(pagepos , Page)
Esf_file_len_3 = Df_bufferreadbyte(1 , Pagepos)
Call Esf_check_pagepos(pagepos , Page)
Esf_file_start = 0
Esf_file_start_1 = Df_bufferreadbyte(1 , Pagepos)
Call Esf_check_pagepos(pagepos , Page)
Esf_file_start_2 = Df_bufferreadbyte(1 , Pagepos)
Call Esf_check_pagepos(pagepos , Page)
Esf_file_start_3 = Df_bufferreadbyte(1 , Pagepos)
Call Esf_check_pagepos(pagepos , Page)
Filename = Ucase(filename)
If Filename = Searchfile Then
Esf_find_file = 1
Ready = 1
Else
Esf_file_len = 0
Esf_file_start = 0
End If
End If
Loop Until Ready = 1
If Esf_find_file = 0 Then
Esf_file_len = 0
Esf_file_start = 0
End If
End If
End Function
Sub Esf_check_pagepos(byref Pagepos As Word , Byref Page As Word)
Incr Pagepos
If Pagepos > 255 Then
Incr Page
Pagepos = 0
Call Df_pagetobuffer(1 , Page)
End If
End Sub