Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDCard performance improvements #107

Merged
merged 2 commits into from
Nov 10, 2023

Conversation

stevesims
Copy link
Contributor

This is work done by @leighbb - I've just made sure it can merge with and run with the latest MOS codebase.

In testing this provides significant performance improvements for SD card access, allowing reads to happen up to twice as fast as they had with the previous C-based code.

SD card access speed had become a bottleneck, which gets hilit by tools that do things like upload bitmaps to the VDP, which this addresses.

1. Replace spi.c with spi.asm
   Maximise performance as much as possible by structuring the code so
   that:
   a) The SPI transmission is initiated as quickly as possible
   b) When transferring multiple bytes, minimising the time between
      the the first byte being sent/received and the next transmission
      being initiated.
   c) Do as much as possible whilst the SPI byte is being transmitted
   Introduces spi_read() and spi_write() functions to reduce overhead
   of transmitting multiple bytes.

2. Replace sd.c with sd.asm
   Maximimise performance by:
   a) Using spi_read() and spi_write() where possible.
   b) Create static buffers for SD command sequences that are fixed
   c) Make the byte swapping of the sector address as efficient as
      possible
   d) Avoid martialing parameters off and on the stack by using non-C
      calling conventions and referencing the parameters on the
      calling function's stack
   Uses timer functions and macros instead of counted loops. This also
   makes the code to do things until a timeout occurs simpler and
   quicker. We also use compile-time convertion of milliseconds to
   number of timer counts to avoid unnecessary arithmetic.
Whilst testing, I had been exporting some of the functions that are
part of the internal interface, remove those exports now.
@breakintoprogram breakintoprogram added the enhancement New feature or request label Nov 5, 2023
@breakintoprogram
Copy link
Owner

Okay, makes sense. The original goal of MOS was to demonstrate how to write a simple OS layer, and C seemed like the best way to do that. Think that goalpost has moved somewhat now. Will merge later.

@breakintoprogram breakintoprogram self-assigned this Nov 8, 2023
@breakintoprogram breakintoprogram merged commit b9555dc into breakintoprogram:main Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants