eris2010

Documentation: http://frombelow.net/projects/eris2010/
Clone: git clone https://git.frombelow.net/eris2010.git
Log | Files | Refs | README | LICENSE

dio_test.c (2834B)


      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 #include <conio.h>
      4 #include <errno.h>
      5 #include <dio.h>
      6 #include "../cc65_eris/os.h"
      7 
      8 void print_stack_pointers() {
      9   unsigned cc65_sp, eris_sp;
     10   unsigned char hw_sp;
     11   get_stack_pointers(&hw_sp, &eris_sp, &cc65_sp);
     12   cprintf("CC65 SP: %04X Eris SP: %04X HW SP: %02X\r\n", cc65_sp, eris_sp, hw_sp);
     13 }
     14 
     15 void print_buffer(unsigned char *buffer) {
     16 
     17   unsigned i;
     18 
     19   for (i = 0; i < 512; i++) {
     20     cprintf("%02X ", buffer[i]);
     21   }
     22   cputs("\r\n");
     23 }
     24 
     25 void read_test(dhandle_t handle) {
     26 
     27   unsigned sect_num;
     28   unsigned *irq;
     29   unsigned char *buffer;
     30   buffer = malloc(512);
     31 
     32   handle = (void *) 0x0000;
     33   for(sect_num = 0; sect_num < 5; sect_num++) {
     34     irq = (unsigned *) 0x7FFE;
     35     cprintf("IRQ vector: %04X\r\n", *irq);
     36     cprintf("Reading handle sector %d %d.\r\n", handle, sect_num);
     37     print_stack_pointers();
     38     dio_read(handle, sect_num, buffer);
     39     print_stack_pointers();
     40     if(_oserror != 0) {
     41       cprintf("_oserror is %d\r\n", _oserror);
     42     }
     43     else {
     44       print_buffer(buffer);
     45     }
     46     cputs("\r\n");
     47   }
     48 }
     49 
     50 void write_test(dhandle_t handle) {
     51 
     52   unsigned sect_num;
     53   unsigned i;
     54   unsigned *irq;
     55   unsigned char *buffer;
     56   buffer = malloc(512);
     57 
     58   handle = (void *) 0x000F;
     59   sect_num = 0x0010;
     60   irq = (unsigned *) 0x7FFE;
     61   cprintf("IRQ vector: %04X\r\n", *irq);
     62   cprintf("Reading handle sector %d %d.\r\n", handle, sect_num);
     63   print_stack_pointers();
     64   dio_read(handle, sect_num, buffer);
     65   if(_oserror != 0)
     66     goto error;
     67   print_buffer(buffer);
     68   for (i = 0; i < 512; i ++) {
     69     buffer[i] = 0xAA;
     70   }
     71   cputs("Writing to SD card.\r\n");
     72   dio_write(handle, sect_num, buffer);
     73   if(_oserror != 0)
     74     goto error;
     75   cputs("Reading SD card.\r\n");
     76   dio_read(handle, sect_num, buffer);
     77   if(_oserror != 0)
     78     goto error;
     79   print_buffer(buffer);
     80   for (i = 0; i < 512; i ++) {
     81     buffer[i] = 0xBB;
     82   }
     83   cputs("Writing to SD card.\r\n");
     84   dio_write(handle, sect_num, buffer);
     85   if(_oserror != 0)
     86     goto error;
     87   cputs("Reading SD card.\r\n");
     88   dio_read(handle, sect_num, buffer);
     89   if(_oserror != 0)
     90     goto error;
     91   print_buffer(buffer);
     92   for (i = 0; i < 512; i ++) {
     93     buffer[i] = i;
     94   }
     95   dio_write(handle, sect_num, buffer);
     96   irq = (unsigned *) 0x7FFE;
     97   cprintf("IRQ vector: %04X\r\n", *irq);
     98   print_stack_pointers();
     99   return;
    100 
    101  error:
    102   cprintf("_oserror is %d\r\n", _oserror);
    103 }
    104 
    105 void main(unsigned char app_number) {
    106 
    107   dhandle_t handle;
    108   
    109   cgetc();
    110   clrscr();
    111   cputs("DIO test.\r\n");
    112   cprintf("My application number is %d.\r\n", app_number);
    113   cgetc();
    114   print_stack_pointers();
    115   cputs("Opening card\r\n");
    116   handle = dio_open(app_number);
    117   if(_oserror != 0) {
    118     cprintf("_oserror is %d\r\n", _oserror);
    119     goto done;
    120   }
    121   read_test(handle);
    122   write_test(handle);
    123   dio_close(handle);
    124  done:
    125   cputs("Done.\r\n");
    126   cgetc();
    127 };