RE: [cc65] Simple PEEK & POKE question.

Date view Thread view Subject view

From: Raj Wurttemberg (raj_at_starbase-01.com)
Date: 2001-03-05 23:59:10


Mike,

I only used that poke statement as an example. I just wanted to know how to
peek and poke values with cc65. While I understand and agree with your
statement, "I recommend that people NOT implement PEEK and POKE at all."
Unfortunately with the Commodore series or computers many values *have* to
be peeked and poked because the functions I am trying to do are not machine
portable. For example if I wanted to create my own character set or create
sprites on a Commodore 64 I know that code would not be portable to an Apple
//e.

I do thank you for your input and your stressing of "direct C" makes a lot
of *good* sense to a PC programmer where sprites, sound, etc. all have well
documented API calls... but the Commodore never had that luxury. :(

Thanks,
-Raj

-----Original Message-----
From: owner-cc65_at_musoftware.de [mailto:owner-cc65_at_musoftware.de]On
Behalf Of Mike McCarty
Sent: Monday, March 05, 2001 12:25 PM
To: cc65_at_musoftware.de
Subject: Re: [cc65] Simple PEEK & POKE question.

It's wonderful that you've gotten started like that. I take exception
to your statement

	For better readability you may want to use macros:

	#define POKE(addr,val)	(*(unsigned char *)(addr)=(val))

This definitely REDUCES readability and obscures what the code
is doing.

Which code is easier for you to read?

(a)	VideoMode = VIDEO_REVERSE;

(b)	POKE(199,1)	/* Set video mode to reverse */

I agree that macros may enhance readability in this area, but not these
particular macros. The suggested answer I give is:

	#include "video.h"
	...
	VideoMode = VIDEO_REVERSE;
	...


and in video.h we have

	#define VIDEO_REVERSE 1

	#define VideoMode (*(unsigned char *)199)

C has the capability to make code readable and understandable.
Providing macros with names like PEEK and POKE is an undesireable step
into the past.

I recommend that people NOT implement PEEK and POKE at all. The direct C
is more readable than the macros. Even better is to implement macros
which make the code understandable without having to add comments.

----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.


Date view Thread view Subject view

This archive was generated by hypermail 2.1.3 : 2001-12-14 22:05:39 CET