Jump to content
IGNORED

cc65: Graphics 8 pixel plotters...


Recommended Posts

I just tried a compile using both with and without a cast to memset()  and the output is identical.

Must have been something else causing the problem.

 

000083r 1  AD rr rr         lda     L0030
000086r 1  85 rr            sta     ptr1
000088r 1  A0 4F            ldy     #$4F
00008Ar 1  A9 AA            lda     #$AA
00008Cr 1  91 rr        L0035:    sta     (ptr1),y
00008Er 1  88               dey
00008Fr 1  10 FB            bpl     L0035
 

Link to comment
Share on other sites

I had a quick look at your code and couldn't find PST .

But I did find your definition of SAVMSC .

#define SAVMSC *((word *) 0x0058)

 

I guess you wanted to do something like SAVMSC=0xff at some point.
The leftmost * in the define makes SAVMSC equivalent to an integer variable (not a pointer), so this works.
But it doesn't work for memset(), which expects a pointer.

#define SAVMSC *((word *) 0x0058)
SAVMSC = 0xff; // saves 0xff to SAVMSC, ie *(0x58) = 0xff
memset( SAVMSC, 0, 1); // writes 0 to whatever is at address 0xff, ie reads SAVMSC and uses that as the address to write 0xff to
memset( (byte*)SAVMSC, 0, 1); // writes 0 to whatever is at address 0xff

 

Instead try either of the following techniques:

#define SAVMSC *((word *) 0x0058)
SAVMSC = 0xff; // saves 0xff to SAVMSC, ie *(0x58) = 0xff
memset(
&SAVMSC, 0, 1); // writes 0 to address 0x58
 

Or

#define SAVMSC ((word *) 0x0058)
*SAVMSC = 0xff; // saves 0xff to SAVMSC, ie *(0x58) = 0xff
memset( SAVMSC, 0, 1); // writes 0 address 0x58

 

Link to comment
Share on other sites

I would really recommend switching to use stdint.h which defines:

typedef signed char         int8_t;
typedef int                 int16_t;
typedef long                int32_t;
typedef unsigned char       uint8_t;
typedef unsigned            uint16_t;
typedef unsigned long       uint32_t;

 

Link to comment
Share on other sites

21 hours ago, TGB1718 said:

You shouldn't need the cast as long as PST has been defined as char *PST

Also all pointers are unsigned, they are purely 16 bit addresses so "unsigned" is also not needed.

I think that definition may have somehow confused the compiler

That is a quite good idea, but PST is #defined as PEEKW(88). I guess I will have to create a definition that works without the use of the PEEK statements.

Link to comment
Share on other sites

Still can still use PEEKW, just change the code to something like this.

 

int *PST;

 

PST=(int *)PEEKW(88);

 

or even

 

char *PST;

 

PST=(char *)PEEKW(88)

 

a char pointer is still 2 bytes, so will act just the same as the int pointer, you can still use POKEW to a char pointer

or even something like

char *PST;

PST=(char *)PEEKW(88);

*PST=0xaa55; // still pokes 2 bytes

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...