Page 1 of 2
ASM programmer to write a simple IDE test loop program ?
Posted: 28 Feb 2019 22:14
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
Re: ASM programmer to write a simple IDE test loop program ?
Posted: 01 Mar 2019 11:19
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
Re: ASM programmer to write a simple IDE test loop program ?
Posted: 01 Mar 2019 11:28
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:
Re: ASM programmer to write a simple IDE test loop program ?
Posted: 01 Mar 2019 13:05
by Smonson
Great! Glad I could save you some time 😊
Re: ASM programmer to write a simple IDE test loop program ?
Posted: 01 Mar 2019 13:10
by exxos
Smonson wrote: 01 Mar 2019 13:05
Great! Glad I could save you some time 😊
Oddly this one passes over my program :shrug:
Re: ASM programmer to write a simple IDE test loop program ?
Posted: 01 Mar 2019 13:36
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
Re: ASM programmer to write a simple IDE test loop program ?
Posted: 01 Mar 2019 22:06
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
Re: ASM programmer to write a simple IDE test loop program ?
Posted: 02 Mar 2019 01:44
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.
Re: ASM programmer to write a simple IDE test loop program ?
Posted: 02 Mar 2019 02:01
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;
}
Re: ASM programmer to write a simple IDE test loop program ?
Posted: 02 Mar 2019 02:36
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