Image Map Image Map
Results 1 to 2 of 2

Thread: help with disk I/O routines

  1. #1

    Default help with disk I/O routines

    I'm trying to write a simple routine to write a buffer to disk using DOS and not getting anywhere;


    Code:
    uchar ioBuf[256];
    static FCB fileIO;
    
    static void _setFile(const char* name)
    {
        char* q = fileIO;
        char c;
        while ((c = *name++) != 0)
        {
            c = toupper(c);
            if (c == '.') c = '/';
            *q++ = c;
        }
    
        *q++ = ':';
        *q++ = '1';
        *q = 0x0d; // terminator
    }
    
    static void _fileError(const char* name, uchar r)
    {
        printf("Can't open file '%s' (%d)\n", name, (int)r);
    }
    
    
    int writeFile(const char* name, char* buf, int bz)
    {
        int cc = 0;
    
        _setFile(name);
    
        uchar r = fopen(fileIO);
        if (!r)
        {
            while (bz)
            {
                r = fputc(*buf++, fileIO);
                if (r)
                {
                    printf("Error %d writing file '%s' ", r, name);
                    switch (r)
                    {
                    case 27:
                        printf("disk full");
                    }
                    outchar('\n');
                    break;
                }
                --bz;
                ++cc;
            }
    
            fclose(fileIO);
        }
        else _fileError(name, r);
        return cc;    
    }
    with IO implementation like this:
    Code:
        .module fios
    	.globl	_ioBuf
        
        .area   _CODE
    
    dos_open        .equ  0x4420
    dos_open_exist  .equ  0x4424    
    dos_read_byte   .equ  0x13
    dos_write_byte  .equ  0x1B
    dos_close       .equ  0x4428
    dos_seek        .equ  0x4442
        
        ;; uchar fopen_exist(FCB f)
    _fopen_exist::
        pop  hl
        pop  de                     ;f 
        push de
        push hl
        ld   hl, #_ioBuf
        ld   b,#0
        call dos_open_exist
        jr   nz,.fiofinish
        xor  a,a
        
    .fiofinish:
        ;; A contains error
        ld  l,a
        ret
    
        ;; uchar fopen(FCB f)
    _fopen::
        pop  hl
        pop  de                     ;f 
        push de
        push hl
        ld   hl, #_ioBuf
        ld   b,#0                   ;lrl
        call dos_open
        jr   nz,.fiofinish
        xor  a,a
        jp  .fiofinish
    
        ;; int fgetc(FCB f)
    _fgetc::
        pop  hl
        pop  de                     ; f
        push de
        push hl
        call dos_read_byte
        jr  nz,.readError
        ld  h,#0
        ld  l,a                     ; -> HL
        ret
    .readError:
        ld  h,#0xff
        ret
    
        ;; char fputc(char c, FCB f)
    _fputc::
        pop  hl
        pop  de                     ; f
        pop  af                     ; a = c
        push af
        push de
        push hl
        call dos_write_byte
        jr  nz,.fiofinish
        xor a,a
        jp  .fiofinish
    
        ;; void fclose(FDB f)
    _fclose::
        pop  hl
        pop  de                     ;f
        push de
        push hl
        call dos_close
        ret
    The idea is to get character IO going. the "fopen" works (at least it creates the file), but "fputc" gives error 38, which is file not open!

    Wondering if it's related to b=0 which is the LRL. setting 0 means 256 records. If i set to something else, eg 128 in fopen, i get the same error. Overall im trying to write 224 bytes, so it shouldn't be a problem.

    any help or pointers appreciated.

  2. #2

    Default

    Fixed it!

    Duh! silly me, got the stack paramers wrong wat round! no wonder it says "file not open",. wrong DCB.

    fixed now https://github.com/voidware/scott19

    save/load games work, except for M4 (for some reason...)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •