Re: [cc65] Why does this work in 128 mode but not 64 mode?

From: Payton Byrd <plbyrd1gmail.com>
Date: 2010-04-30 05:52:46
On Thu, Apr 29, 2010 at 4:20 PM, Ullrich von Bassewitz <uz@musoftware.de>wrote:

>
> Hi!
>
> On Thu, Apr 29, 2010 at 12:15:11PM -0500, Payton Byrd wrote:
> >    I've got some simple drive code that works fine in 128 mode, but does
> not
> >    work correctly in 64 mode. �What happens is that when in 64 mode, the
> >    first time it enounters a drive number without a device it locks up.
> �In
> >    128 mode it gracefully encounters an error and moves on to the next
> drive
> >    number.
>
> My suggestion would be to check it on a real C64. If it doesn't work there
> either, then the behaviour of the C128 in C64 mode is correct (since it is
> fully compatible :-).
>
>
After a lot of digging, it appears to be a problem in the libraries.
 According to cbm.h, all of the disk operations (cbm_open, etc) should
update the _oserror global variable which you can read by including
errorno.h.  The little table in cbm.h indicates that if a drive doesn't
exist, that _oserror should have a 5 in it, which I would assume would be
the case when calling cbm_open on a drive number with no drive attached.
 The following program shows this is not the case.  After calling cbm_open
on a non-existent drive _oserror contains 0 and so the code attempts to read
from the channel which then locks up in 64 mode.  128 mode allows the read
but returns an empty string in the buffer which is easy enough to handle.
 The problem for me is that there's no way to know whether or not cbm_open
failed since _oserror doesn't get populated as expected.

Code showing the problem:
#include <errno.h>
#include <cbm.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

void main(void)
{
  int dr = 15;
  int size;
  unsigned char message[39];

  cbm_open(15,dr,15,"");
  printf("_oserror: %d\n", _oserror);

  if(_oserror == 0)
  {
    size = cbm_read(15, message, 39);
    if(size >= 0) message[size] = '\0';
    else message[0] = '\0';

    printf("%s\n", message);
  }

  cbm_close(15);
}


-- 
Payton Byrd
<http://www.paytonbyrd.com>
<http://it.toolbox.com/blogs/paytonbyrd>

----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Fri Apr 30 05:53:10 2010

This archive was generated by hypermail 2.1.8 : 2010-04-30 05:53:14 CEST