Discussion:
Peek & Poke with Power C (64)?
(too old to reply)
RajW
2003-11-02 04:37:19 UTC
Permalink
I'm messing around with Power C (a.k.a. Proline) and have written
several small programs to test it's functionality. I ran into a
roadblock today with it... I do not see that there is a way to do a
PEEK or a POKE with the C64 version of Power C. I find this odd
because the C128 version of Power C does have a PEEK and POKE command.
Am I missing something?

Thanks,
/*Raj*/
Christian Johansson
2003-11-02 13:23:07 UTC
Permalink
I do not see a need for any special PEEK or POKE command in C. You can do
this in C anyway.

For example, the following is equalent with ucValue = PEEK(53281)

unsigned char ucValue;
ucValue = *((unsigned char*)53281);

and the following is equivalent with POKE 53281,15

*((unsigned char*)53281) = 15;

/Christian
Post by RajW
I'm messing around with Power C (a.k.a. Proline) and have written
several small programs to test it's functionality. I ran into a
roadblock today with it... I do not see that there is a way to do a
PEEK or a POKE with the C64 version of Power C. I find this odd
because the C128 version of Power C does have a PEEK and POKE command.
Am I missing something?
Thanks,
/*Raj*/
RajW
2003-11-02 14:05:26 UTC
Permalink
This is why I love this newsgroup and the people in it! Thank you
Christian. I will give it a try. Hopefully the old Power C will
understand that.

/*Raj*/

On Sun, 02 Nov 2003 13:23:07 GMT, "Christian Johansson"
Post by Christian Johansson
I do not see a need for any special PEEK or POKE command in C. You can do
this in C anyway.
For example, the following is equalent with ucValue = PEEK(53281)
unsigned char ucValue;
ucValue = *((unsigned char*)53281);
and the following is equivalent with POKE 53281,15
*((unsigned char*)53281) = 15;
/Christian
RajW
2003-11-02 14:45:44 UTC
Permalink
For the knowledge base and the news archives, Power C (for the C64)
did not like:

*((unsigned char*)53281) = 15;

but it did accept:

*((char*)53281) = 15;

I have not tried a 'peek' yet. The documentation for Power C really
stinks.

Thanks,
/*Raj*/

On Sun, 02 Nov 2003 13:23:07 GMT, "Christian Johansson"
<***@combort.se> wrote:
[snip]
Post by Christian Johansson
unsigned char ucValue;
ucValue = *((unsigned char*)53281);
and the following is equivalent with POKE 53281,15
*((unsigned char*)53281) = 15;
[/snip]
iAN CooG
2003-11-02 17:36:04 UTC
Permalink
Post by RajW
For the knowledge base and the news archives, Power C (for the C64)
*((unsigned char*)53281) = 15;
*((char*)53281) = 15;
This means Power C defaults to signed values, the immediate value 15 is
signed and you are trying to put a signed int into a unsigned char.
try casting also the value:
*((unsigned char*)53281) = (unsigned char)15;
or even better using typedefs
--
-=[]=---iAN CooG/HokutoForce+TWT---=[]=-
Real Programmers use "COPY /B CON FILENAME.EXE"
RajW
2003-11-02 19:21:03 UTC
Permalink
Ian,
Post by iAN CooG
*((unsigned char*)53281) = (unsigned char)15;
or even better using typedefs
Could you post an example of "using typedefs"? I am new to C
programming and have not grasped that concept yet.

Thanks,
/*Raj*/
wildstar
2003-11-02 20:50:01 UTC
Permalink
Post by RajW
Ian,
Post by iAN CooG
*((unsigned char*)53281) = (unsigned char)15;
or even better using typedefs
Could you post an example of "using typedefs"? I am new to C
programming and have not grasped that concept yet.
Thanks,
/*Raj*/
Where can I download Power C ???? You may send the email privately to the
following email address:

***@wavestarinteractive.com (if I got the letters right)

or

***@yahoo.com

The Hotmail account of mine may automatically send you to Bulk and it has
been set to the maximum setting possible which means the Bulk Mail (Junk
Folder) is automatically deleted.
RajW
2003-11-03 14:00:39 UTC
Permalink
Post by wildstar
Where can I download Power C ???? You may send the email privately to the
Right here...

C64 Version
http://www.c64.us/cbmfiles/utils/PWRC64A.D64
http://www.c64.us/cbmfiles/utils/PWRC64B.D64

C128 Version
http://www.c64.us/cbmfiles/utils/PWRC128A.D64
http://www.c64.us/cbmfiles/utils/PWRC128B.D64

Enjoy!
/*Raj*/
Christian Johansson
2003-11-03 18:50:03 UTC
Permalink
Thank you. I just found the manual as well:

http://project64.c64.org/misc/powerc10.zip

/Christian
Post by RajW
Post by wildstar
Where can I download Power C ???? You may send the email privately to the
Right here...
C64 Version
http://www.c64.us/cbmfiles/utils/PWRC64A.D64
http://www.c64.us/cbmfiles/utils/PWRC64B.D64
C128 Version
http://www.c64.us/cbmfiles/utils/PWRC128A.D64
http://www.c64.us/cbmfiles/utils/PWRC128B.D64
Enjoy!
/*Raj*/
wildstar
2003-11-04 05:54:37 UTC
Permalink
Post by Christian Johansson
http://project64.c64.org/misc/powerc10.zip
/Christian
On Sun, 02 Nov 2003 20:50:01 -0000, wildstar
Post by wildstar
Where can I download Power C ???? You may send the email privately
Right here...
C64 Version
http://www.c64.us/cbmfiles/utils/PWRC64A.D64
http://www.c64.us/cbmfiles/utils/PWRC64B.D64
C128 Version
http://www.c64.us/cbmfiles/utils/PWRC128A.D64
http://www.c64.us/cbmfiles/utils/PWRC128B.D64
Enjoy!
/*Raj*/
THANK YOU Raj & THANK YOU Christian.
iAN CooG
2003-11-02 21:20:13 UTC
Permalink
Post by RajW
Could you post an example of "using typedefs"? I am new to C
programming and have not grasped that concept yet.
typedef is used also to abbreviate vars declarations

typedef unsigned char UC;
*(UC*)0xd020 = (UC)0x0f;

this way if you are using a lot of casts like (unsigned char) or
(unsigned short int) you can type less things and obtain the same
result.

Please note how different way of writing the same thing produce
different output, at least with cc65 compiler.

;
; *(UC*)53281 = (UC)15;
;
ldx #$D0
lda #$21
sta sreg
stx sreg+1
lda #$0F
ldy #$00
sta (sreg),y
;
; *(UC*)0xd021 = (UC)0x0f;
;
lda #$0F
sta $D021
--
-=[]=---iAN CooG/HokutoForce+TWT---=[]=-
Backup not found: (A)bort (R)etry (P)anic
Ralph Mason
2003-11-02 21:50:55 UTC
Permalink
Post by iAN CooG
Post by RajW
Could you post an example of "using typedefs"? I am new to C
programming and have not grasped that concept yet.
typedef is used also to abbreviate vars declarations
typedef unsigned char UC;
*(UC*)0xd020 = (UC)0x0f;
this way if you are using a lot of casts like (unsigned char) or
(unsigned short int) you can type less things and obtain the same
result.
Please note how different way of writing the same thing produce
different output, at least with cc65 compiler.
;
; *(UC*)53281 = (UC)15;
;
ldx #$D0
lda #$21
sta sreg
stx sreg+1
lda #$0F
ldy #$00
sta (sreg),y
;
; *(UC*)0xd021 = (UC)0x0f;
;
lda #$0F
sta $D021
This doesn't make much sense to me - the scanner should product the exact
same token from both examples. The compiler will not be aware of these
differences and produce exactly the same code.

Is this just a simple app-

eg

void main(){
*(UC*)0xd021 = (UC)0x0f;
}

and

void main(){
*(UC*)53281 = (UC)15;
}



Ralph
iAN CooG
2003-11-02 22:43:42 UTC
Permalink
Post by Ralph Mason
This doesn't make much sense to me - the scanner should product the
It seems to make sense in cc65, decimal values are treated differently
from hexadecimals.
Any further explanation requests can be redirected to cc65 author.
--
-=[]=---iAN CooG/HokutoForce+TWT---=[]=-
Smith & Wesson...the original point and click interface
Ullrich von Bassewitz
2003-11-03 01:21:05 UTC
Permalink
Post by Ralph Mason
This doesn't make much sense to me - the scanner should product the exact
same token from both examples. The compiler will not be aware of these
differences and produce exactly the same code.
The difference is in something the compiler warns about, when translating the
code in question:

foobar.c(8): Warning: Constant is long

Decimal constants greater than 32767 are actually of type long. Version 2.9
of the compiler is somewhat weak when casting things, this is already fixed in
the development version (which produces the same result for both lines).

Regards


Uz
--
Ullrich von Bassewitz ***@spamtrap.musoftware.de
02:18:04 up 9:44, 11 users, load average: 0.08, 0.12, 0.09
RajW
2003-11-03 17:07:47 UTC
Permalink
Hi Ian,
Post by iAN CooG
typedef unsigned char UC;
*(UC*)0xd020 = (UC)0x0f;
Thanks for your help. This is fun writing programs for the C64 after
all these years!

"Power C" did not like the above example but:

typedef char UC;
*(UC*)0xd020 = (UC)0x0f;

did work. So I'm guessing that "Power C" is brain damaged when it
comet to "unsigned". Should I worry about this? Thanks again!

/*Raj*/
Ullrich von Bassewitz
2003-11-03 21:02:25 UTC
Permalink
Post by RajW
So I'm guessing that "Power C" is brain damaged when it
comet to "unsigned". Should I worry about this? Thanks again!
It is possible that Power C doesn't have an "unsigned char" data type. The
compiler preceeds the C standard by quite some years (the first C standard is
from 1989), so older compilers had no hard rules to follow. And at that time,
even K&R was a moving target.

You can check if unsigned chars are supported by compiling the following
snippet:

main ()
{
unsigned char c;
c = 1;
return c;
}

Regards


Uz
--
Ullrich von Bassewitz ***@spamtrap.musoftware.de
21:58:14 up 1 day, 5:24, 12 users, load average: 0.01, 0.13, 0.15
Kelli Halliburton
2003-11-03 21:50:37 UTC
Permalink
Post by RajW
typedef char UC;
*(UC*)0xd020 = (UC)0x0f;
did work. So I'm guessing that "Power C" is brain damaged when it
comes to "unsigned". Should I worry about this? Thanks again!
I'm not sure, but it's entirely possible that Power C was written with the
concept that a char should be unsigned anyway, since the C64 character set
doesn't exactly list any characters with negative values.
Christian Johansson
2003-11-04 18:36:26 UTC
Permalink
Post by RajW
Hi Ian,
Post by iAN CooG
typedef unsigned char UC;
*(UC*)0xd020 = (UC)0x0f;
Thanks for your help. This is fun writing programs for the C64 after
all these years!
typedef char UC;
*(UC*)0xd020 = (UC)0x0f;
did work. So I'm guessing that "Power C" is brain damaged when it
comet to "unsigned". Should I worry about this? Thanks again!
/*Raj*/
In the manual for Power C (that I gave a link to in another posting in this
thread) it says:

"The following table lists the size in bytes of all data types supported
by the compiler:

Type Size

char 1
short 2
int 2
long 2
unsigned 2
float 5
double 5
pointer 2

Note that short, int, and long are synonyms, as are float and double.

Integers and pointers are stored low byte first, high byte last.
Float quantities are stored in the same format as BASIC variables."

Therefore, it seems like Power C has a special type for unsigned that is
always 2 bytes. You can't put unsigned in front of other types but you must
write only unsigned if you want to declare a variable as unsigned. This
doesn't comply to the C standard very well but as other people have pointed
out, this compiler predates the C standard.

At another place in the manual it says:

"Declare variables unsigned rather than int if they never contain
negative values. For example, variables which are used only as array
indices should always be declared unsigned."

I still don't understand how to read or write a byte. In standard C you
would use unsigned char but that is not possible in Power C. If char is
always signed it means that you can only PEEK or POKE values between -128
and 127. This for example means that if you want to POKE the value 255 you
would instead use -1 and 128 would be written as -128. This seems akward. I
guess some experimenting with Power C would give the answer on how to do it.
Ullrich von Bassewitz
2003-11-04 20:24:23 UTC
Permalink
Post by Christian Johansson
"Declare variables unsigned rather than int if they never contain
negative values. For example, variables which are used only as array
indices should always be declared unsigned."
There's a similar suggestion for cc65. It is based on some limitations of the
6502 CPU:

http://www.cc65.org/doc/coding-5.html
Post by Christian Johansson
I still don't understand how to read or write a byte. In standard C you
would use unsigned char but that is not possible in Power C. If char is
always signed it means that you can only PEEK or POKE values between -128
and 127. This for example means that if you want to POKE the value 255 you
would instead use -1 and 128 would be written as -128. This seems akward. I
guess some experimenting with Power C would give the answer on how to do it.
This is no problem, since converting from signed to unsigned won't change the
bits of the value. Having a signed value is just another interpretation of the
bits, but in this cases it does not matter. Given the assignment

char c = 255;

if c is signed, this would not mean that any conversion is done to the number
255, it will just be left as is, but interpreted as signed (which does not
matter in an assignment). So the binary value

%11111111

is stored into c, regardless of the sign issue.

Regards


Uz
--
Ullrich von Bassewitz ***@spamtrap.musoftware.de
20:52:30 up 2 days, 4:18, 13 users, load average: 1.56, 0.72, 0.52
Christian Johansson
2003-11-05 17:55:36 UTC
Permalink
Post by Ullrich von Bassewitz
Post by Christian Johansson
"Declare variables unsigned rather than int if they never contain
negative values. For example, variables which are used only as array
indices should always be declared unsigned."
There's a similar suggestion for cc65. It is based on some limitations of the
Yes, I think that in general it is good coding practise to do like this.
Otherwise, you may get very unpleasant surprises (bugs) in your code because
a big positive value erroneously is interpreted as a negative value. I have
developed the C coding standard we use at my workplace and I find it very
annoying when people use signed types for variables that can only take
non-negative values.

BlackJack
2003-11-04 22:50:41 UTC
Permalink
Post by Christian Johansson
I still don't understand how to read or write a byte. In standard C you
would use unsigned char but that is not possible in Power C.
In standard C using the standard functions you read single bytes into an
'int' because they need more than 256 values to signal the EOF (usually as
-1).
Post by Christian Johansson
If char is
always signed it means that you can only PEEK or POKE values between -128
and 127.
No, it's no problem to do 'c = 0xff' with signed chars. GCC don't even
give a warning if you invoke it with all warnings turned on. I guess the
"signedness" only affects comparisons but not assigments.

Ciao,
Marc 'BlackJack' Rintsch
wildstar
2003-11-02 20:45:50 UTC
Permalink
Post by RajW
For the knowledge base and the news archives, Power C (for the
C64)
Post by RajW
*((unsigned char*)53281) = 15;
*((char*)53281) = 15;
I have not tried a 'peek' yet. The documentation for Power C
really
Post by RajW
stinks.
I think from your example that Power C for C64 automatically
assumes the
char* is an unsigned. Then again we are dealing with C not C++.
I also
think it is minimal ANSI C not full ANSI C.
Loading...