Megalextoria
Retro computing and gaming, sci-fi books, tv and movies and other geeky stuff.

Home » Digital Archaeology » Computer Arcana » Commodore » Commodore 8-bit » Problem with MemBank128 demo!
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Problem with MemBank128 demo! [message #209832] Mon, 06 May 2013 13:16 Go to next message
Harry Potter is currently offline  Harry Potter
Messages: 1301
Registered: March 2012
Karma: 0
Senior Member
I am working on a demo for my MemBank128 memory expander for cc65 and am running into a roblem with a drive write. Basically, when I try to create a file using the erroneous code, the drive readout counts from track 18 to 1 and back to 18, then the LED blinks quickly. I exit the program and type "?ds$" and get a read error at Track 18, Sector 1. I then type "diR" and got no information. I reattach the disk image and type "diR," and the written file simply wasn't closed properly. I've been able to isolate the code that produces the bug, and it is not specific to the MemBank128 environment. I am working using WinVice 2.4. The following is the emulator configuration:

* Drive 8: 1571
* True drive emulation: on
* Virtual device traps: on

Example code to cause the error, in cc65 C, follows:
--------------------------
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>

#include <conio.h>

#include <c128.h>

char magic[4]="hi!";
unsigned w=2;

char *filename="@0:out,s,w";
struct _a {
unsigned v1;
char v2[12];
} a [2] = {
{1, "number # 1"},
{2, "number # 2"}
};
void file_error ()
{
puts ("A file error occured!");
}
void file_save ()
{
unsigned i;
static char f[17];
retry:
clrscr();
puts ("Type in name of file:");
//if (GetInput(f, 17))
{
strcpy (filename, "@:");
strcat (filename, f);
strcat (filename, ",s,w");
cbm_open (1,8,CBM_WRITE, filename);
if (cbm_k_readst()) {file_error(); return;}
cbm_write (1, magic, strlen(magic)-1);
if (cbm_k_readst()) {file_error(); return;}
cbm_write (1, &w, 2);
if (cbm_k_readst()) {file_error(); return;}
//cbm_close (1);
for (i=0; i<2; ++i) {
putchar ('.');
cbm_write (1, &a[i], sizeof(struct _a));
//if (cbm_k_readst()) {file_error(); return;}
}
cbm_close (1);
}
}

void main ()
{
puts ("Test!");
file_save ();
puts ("End!");
}
--------------------------
Re: Problem with MemBank128 demo! [message #209834 is a reply to message #209832] Mon, 06 May 2013 18:46 Go to previous messageGo to next message
Anton Treuenfels is currently offline  Anton Treuenfels
Messages: 105
Registered: December 2011
Karma: 0
Senior Member
"Harry Potter" <rose.joseph12@yahoo.com> wrote in message
news:57d05d0a-ff92-4e8b-89ef-1c20fd182190@googlegroups.com...
I am working on a demo for my MemBank128 memory expander for cc65 and am
running into a roblem with a drive write. Basically, when I try to create a
file using the erroneous code, the drive readout counts from track 18 to 1
and back to 18, then the LED blinks quickly. I exit the program and type
"?ds$" and get a read error at Track 18, Sector 1. I then type "diR" and
got no information. I reattach the disk image and type "diR," and the
written file simply wasn't closed properly. I've been able to isolate the
code that produces the bug, and it is not specific to the MemBank128
environment. I am working using WinVice 2.4. The following is the emulator
configuration:

* Drive 8: 1571
* True drive emulation: on
* Virtual device traps: on

Example code to cause the error, in cc65 C, follows:
--------------------------
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>

#include <conio.h>

#include <c128.h>

char magic[4]="hi!";
unsigned w=2;

char *filename="@0:out,s,w";
struct _a {
unsigned v1;
char v2[12];
} a [2] = {
{1, "number # 1"},
{2, "number # 2"}
};
void file_error ()
{
puts ("A file error occured!");
}
void file_save ()
{
unsigned i;
static char f[17];
retry:
clrscr();
puts ("Type in name of file:");
//if (GetInput(f, 17))
{
strcpy (filename, "@:");
strcat (filename, f);
strcat (filename, ",s,w");
cbm_open (1,8,CBM_WRITE, filename);
if (cbm_k_readst()) {file_error(); return;}
cbm_write (1, magic, strlen(magic)-1);
if (cbm_k_readst()) {file_error(); return;}
cbm_write (1, &w, 2);
if (cbm_k_readst()) {file_error(); return;}
//cbm_close (1);
for (i=0; i<2; ++i) {
putchar ('.');
cbm_write (1, &a[i], sizeof(struct _a));
//if (cbm_k_readst()) {file_error(); return;}
}
cbm_close (1);
}
}

void main ()
{
puts ("Test!");
file_save ();
puts ("End!");
}
--------------------------

What a mess. If the code was correct you might be able to blame cc65, but
certainly not until then.

Of a number of mistakes and misconceptions the most egregious is perhaps:

char *filename="@0:out,s,w";

not because it's wrong in itself but because later you do this:

strcpy (filename, "@:");
strcat (filename, f);
strcat (filename, ",s,w");

which causes the storage allocated for the literal constant "@:out,s,w" to
be overwritten with something else. So you're messing with your own
program's data.

Anton Treuenfels
Re: Problem with MemBank128 demo! [message #209835 is a reply to message #209834] Tue, 07 May 2013 09:26 Go to previous messageGo to next message
Harry Potter is currently offline  Harry Potter
Messages: 1301
Registered: March 2012
Karma: 0
Senior Member
Thank you, Anton, for your insight. However, the code as given still doesn't work; and I need the user to *choose* the filename, which was the original purpose or the str*() lines.
Re: Problem with MemBank128 demo! [message #209836 is a reply to message #209835] Tue, 07 May 2013 09:59 Go to previous messageGo to next message
winston19842005@yahoo is currently offline  winston19842005@yahoo
Messages: 180
Registered: December 2011
Karma: 0
Senior Member
If you're having that many issues with user input, first try it with a fixed file name. Debug that first, then mod your code to accept the file name from the user.
Re: Problem with MemBank128 demo! [message #209837 is a reply to message #209836] Tue, 07 May 2013 11:15 Go to previous messageGo to next message
Harry Potter is currently offline  Harry Potter
Messages: 1301
Registered: March 2012
Karma: 0
Senior Member
On Tuesday, May 7, 2013 9:59:49 AM UTC-4, winston...@yahoo.com wrote:
> If you're having that many issues with user input, first try it with a fixed file name. Debug that first, then mod your code to accept the file name from the user.

I made a mistake with the last post: I disabled the str*() lines, and the code *still* doesn't work.
Re: Problem with MemBank128 demo! [message #209860 is a reply to message #209837] Wed, 15 May 2013 09:41 Go to previous messageGo to next message
Harry Potter is currently offline  Harry Potter
Messages: 1301
Registered: March 2012
Karma: 0
Senior Member
On Tuesday, May 7, 2013 11:15:53 AM UTC-4, Harry Potter wrote:
> On Tuesday, May 7, 2013 9:59:49 AM UTC-4, winston...@yahoo.com wrote: > If you're having that many issues with user input, first try it with a fixed file name. Debug that first, then mod your code to accept the file name from the user. I made a mistake with the last post: I disabled the str*() lines, and the code *still* doesn't work.

I think it may be a problem with cc65: another program that used to work now dislays garbage on the screen. It seems to happen in my programs that access the CBM drives. I have version V2.13.3, SVN:5495.
Re: Problem with MemBank128 demo! [message #209861 is a reply to message #209860] Wed, 15 May 2013 09:49 Go to previous message
Harry Potter is currently offline  Harry Potter
Messages: 1301
Registered: March 2012
Karma: 0
Senior Member
On Wednesday, May 15, 2013 9:41:01 AM UTC-4, Harry Potter wrote:
> I think it may be a problem with cc65: another program that used to work now dislays garbage on the screen. It seems to happen in my programs that access the CBM drives. I have version V2.13.3, SVN:5495.

Or maybe it's due to the emulator: I use WinVice 2.4. BTW, the second file is for the C64 and run on a C64 emulator.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: fpga 6502
Next Topic: Interactive Raycaster For the Commodore 64 Under 256 Bytes
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Tue Sep 27 22:10:52 EDT 2022

Total time taken to generate the page: 0.02216 seconds