Hi group!

I hope this is the place to discuss code improvement :-)

I've had a look at pata_hard_disk.jal and quickly found some places to
easily increase execution performance.

For example:

--
----------------------------------------------------------------------------
-- Read two bytes from disk.
--
----------------------------------------------------------------------------
procedure pata_hd_read_data(byte out low_byte, byte out high_byte) is
  if (pata_hd_word_count == 0) & (pata_hd_sector_count) == 0
then        -- if we are at beginning of read
    pata_hd_go_to_sector(pata_hd_sector_select,
0)                        -- go to the selected sector
 
pata_hd_register_write(PATA_HD_COMMAND_REG,PATA_HD_READ_SECTORS)
-- send the read command to the command
 
pata_hd_data_request(PATA_HD_WAIT_READ)
-- wait till the drive has data for you
  elsif pata_hd_word_count == 0
then                                     -- if we are at beginning of
a sector
 
pata_hd_data_request(PATA_HD_WAIT_READ)
-- wait for data to be ready for read
  end if


"if pata_hd_word_count==0" is checked two times. reducing this to only
one check speeds up (linear) read performance by one third:

procedure pata_hd_read_data(byte out low_byte, byte out high_byte) is
  if (pata_hd_word_count == 0) then             -- if we are at
beginning of a sector
    if (pata_hd_sector_count) == 0
then                                            -- if we are at
beginning of read
      pata_hd_go_to_sector(pata_hd_sector_select,
0)                        -- go to the selected sector
 
pata_hd_register_write(PATA_HD_COMMAND_REG,PATA_HD_READ_SECTORS)
    end
if
-- we are at the beginning of a sector
 
pata_hd_data_request(PATA_HD_WAIT_READ)
-- wait for data to be ready for read
  end if

For read_sector, large_array is nice and convenient, but slow in
execution. PIC18F devices have RAM pages of 256 bytes each, so one
sector can be easily stored in just two ordinary arrays:

var byte pata_hd_sector_buffer_lo[256]
var byte pata_hd_sector_buffer_hi[256]

procedure pata_hd_read_sector() is
  var word count1
  pata_hd_word_count = 0

[...]
   for 256 loop
      -- get the data trough the ide interface
      pata_hd_iord = high ^ PATA_HD_NO_INVERTER  -- start read pulse
      pata_hd_sector_buffer_hi[count1] = pata_hd_data_high -- get high
data byte
      pata_hd_sector_buffer_lo[count1] = pata_hd_data_low  -- get low
data byte
      pata_hd_iord = low ^ PATA_HD_NO_INVERTER   -- end read pulse
      count1 = count1 + 1
   end loop

This speeds up reading by more than four times! As the sector buffer
is only used by one procedure yet (fat32.jal / fat32_read_dir_info() )
it may be worth discussing to change the data type of sector_buffer.

Here's an example for an auxiliary function one can use if byte
addressing is desired: (untested)

function pata_hd_sector_buffer_read_linear (word in position) return
byte is

  if (position && 1) then -- is an odd memory location requested?
    return pata_hd_sector_buffer_hi[position / 2]  -- yes, return a
high byte
  else
    return pata_hd_sector_buffer_lo[position / 2]  -- no, return a low
byte
  end if
end function

I'm looking forward to any contradiction ;-)

Greets,
Kiste

-- 
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/jallib?hl=en.

Reply via email to