ASM programmer to write a simple IDE test loop program ?

News,announcements,programming,fixes,game patches & discussions.

Moderator: troed

User avatar
exxos
Site Admin
Site Admin
Posts: 23707
Joined: Wed Aug 16, 2017 11:19 pm
Location: UK
Contact:

ASM programmer to write a simple IDE test loop program ?

Post by exxos »

Can any of you ASM guys do something like this but in ASM ? Its painfully slow in Basic :(

All it does is write a string loads of times to a file to make 50MB worth of data. Then reads the file back in line by line (about 500bytes per line string) and compares the string in the file to the string in RAM.. then repeats for the whole file.

So if the file is corrupted at any point, the program would report a failure.

I think part of the slowness is a string comparison rather than binary stuff.


Code: Select all

ID=freewind 
WINDOW OPEN ID,"" ,20,20,300,150,1

print "CRAPPY HARD DRIVE TESTER V2.01"

'create string

DIM A$,B$,A,C$,P,C,SZ,MB

A$="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-*!"

B$=""
FOR A=1 TO 13
B$=B$+A$
NEXT A

SZ=100000 ' 50MB

PRINT ""
PRINT " SAVING "+STR$(SZ) +" SECTORS "
PRINT ""

OPEN "BLAH.TXT" for OUTPUT AS #3

FOR A=1 TO SZ
C=C+1
print #3,B$
IF C>5000 THEN PRINT "."; : C=0
NEXT A

close #3

PRINT ""
PRINT " READING & CHECKING SECTOR"
OPEN "BLAH.TXT" FOR INPUT AS #4

F=0

C=0
PRINT ""

FOR A=1 TO SZ
LINE INPUT #4,C$
IF C>5000 THEN PRINT "."; : C=0
	IF C$ = B$ THEN 
		F=F+1
	ELSE
		PRINT "FAILED":END
	END IF

C=C+1
NEXT A

PRINT ""
CLOSE #4

	IF F=SZ THEN 
	PRINT " TESTED OK"
	ELSE
	PRINT " FAILED"  :END
    END IF


PRINT ""


END

https://www.exxosforum.co.uk/atari/ All my hardware guides - mods - games - STOS
https://www.exxosforum.co.uk/atari/store2/ - All my hardware mods for sale - Please help support by making a purchase.
viewtopic.php?f=17&t=1585 Have you done the Mandatory Fixes ?
Just because a lot of people agree on something, doesn't make it a fact. ~exxos ~
People should find solutions to problems, not find problems with solutions.
User avatar
Smonson
Posts: 710
Joined: Sat Oct 28, 2017 10:21 am
Location: Canberra, Australia
Contact:

Re: ASM programmer to write a simple IDE test loop program ?

Post by Smonson »

I ported it to C. Apparently the reads and writes take about the same amount of time, but the comparison takes aaaaaaaaaages.

I sped it up slightly by using 0-255 as the filler data instead of a string. So I can just check each byte against the byte count, which is quicker than comparing two memory reads.

Sorry, I couldn't work out how to attach a file to the forum.

http://smonson.com/unmanaged/atari/HDDTEST.PRG

HDDTEST.zip
(18.25 KiB) Downloaded 8 times
User avatar
exxos
Site Admin
Site Admin
Posts: 23707
Joined: Wed Aug 16, 2017 11:19 pm
Location: UK
Contact:

Re: ASM programmer to write a simple IDE test loop program ?

Post by exxos »

Awesome thanks, love the name! It looks like it is saving a lot faster... Will leave it on for a bit and see what happens..

:thanksyellow:


EDIT:

It saved the sectors already that was fast! The verify, I can see the light flashing like five times faster than my code!

I will put in a iffy CF card and see if it triggers up a error!


EDIT2:

Took like 20mins to verify, takes like 2 hours with my code :lol:
https://www.exxosforum.co.uk/atari/ All my hardware guides - mods - games - STOS
https://www.exxosforum.co.uk/atari/store2/ - All my hardware mods for sale - Please help support by making a purchase.
viewtopic.php?f=17&t=1585 Have you done the Mandatory Fixes ?
Just because a lot of people agree on something, doesn't make it a fact. ~exxos ~
People should find solutions to problems, not find problems with solutions.
User avatar
Smonson
Posts: 710
Joined: Sat Oct 28, 2017 10:21 am
Location: Canberra, Australia
Contact:

Re: ASM programmer to write a simple IDE test loop program ?

Post by Smonson »

Great! Glad I could save you some time 😊
User avatar
exxos
Site Admin
Site Admin
Posts: 23707
Joined: Wed Aug 16, 2017 11:19 pm
Location: UK
Contact:

Re: ASM programmer to write a simple IDE test loop program ?

Post by exxos »

Smonson wrote: Fri Mar 01, 2019 1:05 pm Great! Glad I could save you some time 😊
Oddly this one passes over my program :shrug:
https://www.exxosforum.co.uk/atari/ All my hardware guides - mods - games - STOS
https://www.exxosforum.co.uk/atari/store2/ - All my hardware mods for sale - Please help support by making a purchase.
viewtopic.php?f=17&t=1585 Have you done the Mandatory Fixes ?
Just because a lot of people agree on something, doesn't make it a fact. ~exxos ~
People should find solutions to problems, not find problems with solutions.
User avatar
exxos
Site Admin
Site Admin
Posts: 23707
Joined: Wed Aug 16, 2017 11:19 pm
Location: UK
Contact:

Re: ASM programmer to write a simple IDE test loop program ?

Post by exxos »

Okay tell a lie, fourth time it found a error...

If you are writing 0-255, maybe you could output the number as well ? May help in translating it to binary so we can see if any particular data bit is failing or not..


IMG_3832.JPG
IMG_3832.JPG (66.25 KiB) Viewed 5205 times
https://www.exxosforum.co.uk/atari/ All my hardware guides - mods - games - STOS
https://www.exxosforum.co.uk/atari/store2/ - All my hardware mods for sale - Please help support by making a purchase.
viewtopic.php?f=17&t=1585 Have you done the Mandatory Fixes ?
Just because a lot of people agree on something, doesn't make it a fact. ~exxos ~
People should find solutions to problems, not find problems with solutions.
User avatar
exxos
Site Admin
Site Admin
Posts: 23707
Joined: Wed Aug 16, 2017 11:19 pm
Location: UK
Contact:

Re: ASM programmer to write a simple IDE test loop program ?

Post by exxos »

I've been looking into this a bit more.. Then got it to output the failed line...


The top line is correct, the bottom line is incorrect.. It looks like data isnt corrupted as such, there just is to be too much of it..

fl.jpg
fl.jpg (27.73 KiB) Viewed 5160 times
https://www.exxosforum.co.uk/atari/ All my hardware guides - mods - games - STOS
https://www.exxosforum.co.uk/atari/store2/ - All my hardware mods for sale - Please help support by making a purchase.
viewtopic.php?f=17&t=1585 Have you done the Mandatory Fixes ?
Just because a lot of people agree on something, doesn't make it a fact. ~exxos ~
People should find solutions to problems, not find problems with solutions.
User avatar
Smonson
Posts: 710
Joined: Sat Oct 28, 2017 10:21 am
Location: Canberra, Australia
Contact:

Re: ASM programmer to write a simple IDE test loop program ?

Post by Smonson »

Oh crap! Something's seriously wrong with my error message these. To be honest with you I didn't actually test the failure part, since it was getting quite late.
User avatar
Smonson
Posts: 710
Joined: Sat Oct 28, 2017 10:21 am
Location: Canberra, Australia
Contact:

Re: ASM programmer to write a simple IDE test loop program ?

Post by Smonson »

Try downloading it again, I've hopefully fixed the issues.

Here's my code.

Code: Select all

extern "C" {
#include <gemdos.h>
#include <libc.h>
}

#define BUFFER_SIZE 512
#define BUFFER_REPEATS 100000

uint8_t buffer[BUFFER_SIZE];
uint8_t read_buffer[BUFFER_SIZE];

void check_error(int condition, const char *message) {
  if (condition) {
    printf("Error: %s.\nPress any key to exit.", message);
    Cconin();
    exit(1);
  }
}

void print_binary(uint8_t byte) {
  for (int bit = 1 << 7; bit; bit >>= 1) {
    printf("%c", byte & bit ? '1' : '0');
  }
}

int main(int argc, char **argv)
{
  printf("\x1b");
  printf("E");
  printf("Crappy hard drive tester V2.01 + a bit\n");

  // Fill buffer up with various data values
  for (int a = 0; a < BUFFER_SIZE; a++) {
    buffer[a] = a;
  }

  // Create a 512,000,000-byte file
  FILE handle = Fcreate("FILE.TXT", 0);
  check_error(handle < 0, "Couldn't create file");
  printf("\nSaving %d sectors\n", BUFFER_REPEATS);
  for (uint32_t count = 0; count < BUFFER_REPEATS; count++) {
    int32_t result = Fwrite(handle, BUFFER_SIZE, buffer);
    check_error(result < 0, "Write error");
    if (count % 5000 == 4999) {
      printf(".");
    }
  }
  printf("\n");
  Fclose(handle);

  // Re-read the file and check the contents are the same
  printf("\nReading and checking sectors\n");
  handle = Fopen("FILE.TXT", GEMDOS_RDONLY);
  check_error(handle < 0, "Couldn't open file for read");
  for (uint32_t count = 0; count < BUFFER_REPEATS; count++) {
    int32_t result = Fread(handle, BUFFER_SIZE, read_buffer);
    check_error(result < 0, "Read error");

    /* To test the failure condition */
    if (0) {
      if (count == 10) {
        read_buffer[307] = 128;
      }
    }

    for (int byte = 0; byte < BUFFER_SIZE; byte++) {
      if (read_buffer[byte] != (byte & 0xff)) {
        printf("Data mismatch: expected 0b");
        print_binary(byte & 0xff);

        printf("\n                   read 0b");
        print_binary(read_buffer[byte]);
        printf("\nPress any key to exit.\n");
        Cconin();
        exit(1);
      }
    }
    if (count % 5000 == 4999) {
      printf(".");
    }
  }
  printf("\n");
  Fclose(handle);

  printf("\nTested OK.\n");
  printf("\nPress any key to exit\n");
  Cconin();

  return 0;
}
User avatar
rpineau
Posts: 534
Joined: Thu Aug 17, 2017 6:08 pm
Location: USA
Contact:

Re: ASM programmer to write a simple IDE test loop program ?

Post by rpineau »

You could use memcmp to compare the 2 buffers and only go in the "slow" comparison to display the error if memcmp fails.

Code: Select all

	 if(memcmp(buffer, read_buffer, BUFFER_SIZE) != 0) {
		 for (int byte = 0; byte < BUFFER_SIZE; byte++) {
			if (read_buffer[byte] != (byte & 0xff)) {
			  printf("Data mismatch: expected 0b");
			  print_binary(byte & 0xff);

			  printf("\n                   read 0b");
			  print_binary(read_buffer[byte]);
			  printf("\nPress any key to exit.\n");
			  Cconin();
			  exit(1);
			}
		 }
    }
this should speed up the test as memcmp is most probably faster than going through the array (it's probably written in ASM). You'll probably need to include string.h
Working ones : MegaSTE (68020) / TT030 / Falcon with AB040 & Eclipse / 1040STF
Need testing : Falcon with CT2
Post Reply

Return to “SOFTWARE PROGRAMMING & DISCUSSION”