.. stubs/generic/target/debugtest.c

File last touched at: 22.09.2003

 

//-------------------------------------------------------------------------------------------

#include "rrdebug.h"
#include "rrdebug.c"

//-------------------------------------------------------------------------------------------

int test_mainmenu(void){
unsigned char key=0;

       dbgPuts("\n\rretargetable replay general debug-library test\n\r\n\r");
       dbgPuts(" 1. keyboard loop test (^ to exit)\n\r");
       dbgPuts(" 2. file-services test (dbgload/dbgsave...)\n\r");
       dbgPuts(" 3. file-services test (dbgopen/dbgclose/dbgread/dbgwrite...)\n\r");
       dbgPuts(" 4. file-services test (dbgchdir/dbggetcwd/dbgfindfirst/dbgfindnext...)\n\r");
       dbgPuts(" 5. system-services test (dbgsystem...)\n\r");
       dbgPuts("\n\r x. exit\n\r");

       while((key!='1')&
             (
key!='2')&
             (
key!='3')&
             (
key!='4')&
             (
key!='5')&
             (
key!='x')) {
               key=dbgKbHit(1);
//               printf("key:%02x:%c\n",key,key);
       }

       return (key);

}

void test_keyloop(void){
int key=0;

       dbgPuts("\n\rkeyboard loop test:\n\r\n\r");

       while(key!='^'){
            key=dbgKbHit(0);
            dbgPut(key);
       }

       dbgPuts("\n\r");

}

void test_system(void){

       dbgPuts("\n\rsystem test...:\n\r\n\r");

       dbgSystem("dir /p");

       dbgPuts("\n\r...ok\n\r");

}

void test_fileserve1(void){
int i;
unsigned char *test;
unsigned long size;

       dbgPuts("\n\rfileserver test, load/save...:\n\r\n\r");

       test=(unsigned char*)malloc(0x1000);

       size=dbgLoad("testfile.txt",(unsigned long)&test[0]);

       dbgPrintf("\n\r%ld bytes loaded.\n\r",size);

       for(i=0;i<size;i++) dbgPut(test[i]);

       dbgSave("testsave.txt",(unsigned long)&test[0],size);

       dbgPrintf("\n\r%ld bytes saved.\n\r",size);

       free(test);

}

void test_fileserve2(void){
int f,i;
char *test;
long size;

       dbgPuts("\n\rfileserver test, open/read/write/close ...:\n\r\n\r");

       f=dbgOpen("testfile.txt",dbgO_RDONLY|dbgO_BINARY);

       dbgLseek(f,0,dbgSEEK_END);
       size=dbgTell(f);
       dbgLseek(f,0,dbgSEEK_SET);

       test=(char*)malloc(size);

       if(f>0) {

            dbgRead(f,test,size);
            for(i=0;i<size;i++) dbgPut(test[i]);
            dbgClose(f);

            f=dbgOpen("testsave.txt",dbgO_WRONLY|dbgO_BINARY);
            dbgWrite(f,test,size);
            dbgClose(f);

       }
else dbgPrintf("error:couldn't open testfile.txt\n\r");

       free(test);

}

void test_fileserve3(void){
DBG_ffblk info;
char *test;
int stat;

       dbgPuts("\n\rfileserver test, directory stuff ...:\n\r\n\r");

       test=(char*)malloc(0x101*sizeof(char));

       if(dbgGetcwd(test,0x100)!=NULL){
            dbgPrintf("cwd is: %s\n\r",test);
       }
else {
            dbgPrintf("error: couldn't read current working dir\n\r");
       }

       dbgMkdir("testdir");

       dbgChdir("testdir");

       if(dbgGetcwd(test,0x100)!=NULL){
            dbgPrintf("cwd is: %s\n\r",test);
       }
else {
            dbgPrintf("error: couldn't read current working dir\n\r");
       }

       dbgChdir("..");

       dbgRmdir("testdir");

       dbgFindfirst("*.*",&info,dbgFA_DIREC);
       dbgPrintf(">\n\r");

       stat=0;while(stat==0) {
            stat=dbgFindnext(&info);
            dbgPrintf("%d,%13s %02x %08x %08x %08x\n\r",stat,info.ff_name,info.ff_attrib,info.ff_ftime,info.ff_fdate,info.ff_fsize);
       }


       free(test);

}


//-------------------------------------------------------------------------------------------

void mainloop(void){
unsigned char test=0;

    while(test!='x'){

        test=test_mainmenu();

        if(test!='x'){

            switch(test){

                case '1':
                    test_keyloop();
                 break;
                case '2':
                    test_fileserve1();
                 break;
                case '3':
                    test_fileserve2();
                 break;
                case '4':
                    test_fileserve3();
                 break;
                case '5':
                    test_system();
                 break;

            }

        }

    }

}

void main(void) {
int err;

    printf("retargetable replay debug-library test...\n\r");

    err=dbgInit();

    printf("port init ok.\n\r");

    dbgPuts("retargetable replay debug-library test...\n\r");

    dbgPrintf("all ok.\n\r");

    printf("all ok.\n\r");

    mainloop();

    dbgDeInit();

    printf("port deinit ok.\n\r");

    printf("all ok.\n\r");

}

 

generated by txt2htm v0.1a (w)2001 Groepaz/Hitmen