Re: [cc65] Re: cbm_read blocks on empty rs232 buffer

From: Greg King <greg.king51verizon.net>
Date: 2013-11-01 19:06:53
From: "Payton Byrd"; on Friday, November 01, 2013; at 9:19 AM -0400
>
> On Fri, Nov 1, 2013 at 8:13 AM, Payton Byrd wrote:
>>
>> OK, more info.  I've put in the following code:
>>
>>  result = cbm_open(2,2,3,file);
>> if (result == 240) {
>>   POKE(53281, 0);
>>   cbm_k_chkin(2);
>>   key = cbm_k_basin();
>>   status = cbm_k_readst();
>>   lastx = wherex();
>>   lasty = wherey();
>>   gotoxy(31, 24);
>>   printf("[%02X][%02X]", key, status);
>>   gotoxy(lastx, lasty);
>> }
>>
>> The screen turns black, so I know the RS232 channel is opened;
>> but, the display code at the bottom never executes until the RS232
>> buffer receives at least one incoming byte.  So, it appears that
>> cbm_k_basin() is doing the blocking.
>
> Using cbm_k_getin() instead of cbm_k_basin() does not block.
> I've resolved my problem by calling the Kernal directly;
> but, it would be good if cbm_read() did not block.

There is a second problem:  That virtual device needs two 256-byte buffers.
Normally, they're put at the top of BASIC's RAM space when the device is
openned (that "240" result code is a special signal that tells the BASIC
interpreter to protect those buffers by adjusting its top-of-memory
pointers).

But, CC65 programs turn off the BASIC ROM.  That location is in the middle
of the program's address space; therefore, you don't want the device.to
create the buffers.  Your program must provide buffers before it opens the
device.  Here is some C-language code that does the job:

/* VIC-20 and C64 addresses */
#define pGET_BUF (*(unsigned char* *)0xF7)
#define pSEND_BUF (*(unsigned char* *)0xF9)
...
static unsigned char get_buf[256];
static unsigned char send_buf[256];
static unsigned char rs232_options[2] = {
    ...
};

...
...

    pGET_BUF = get_buf;
    pSEND_BUF = send_buf;
    (void)cbm_open(2, 2, 3, rs232_options);

----------------------------------------------------------------------
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 Nov 1 20:10:01 2013

This archive was generated by hypermail 2.1.8 : 2013-11-01 20:10:03 CET