Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the cc65 library's new vpoke() function in C demoes. #70

Merged
merged 1 commit into from
Oct 24, 2019

Conversation

greg-king5
Copy link
Contributor

Note that the number and order of vpoke()'s parameters changed.

The VERA address now is a single argument. That makes it slightly easier to see where things are being poked.

@greg-king5 greg-king5 changed the title Use cc65 library's new vpoke() function in C demoes. Use the cc65 library's new vpoke() function in C demoes. Oct 24, 2019
@mist64 mist64 merged commit 2a45950 into commanderx16:master Oct 24, 2019
@mist64
Copy link
Collaborator

mist64 commented Oct 24, 2019

Why does vpoke() have the value as the first and the address as the second argument?

@greg-king5
Copy link
Contributor Author

Why does vpoke() have the value as the first and the address as the second argument?

It allows the implementation to be smaller -- and, both the function and calling programs run faster.
cc65/cc65#934 (comment)

@greg-king5 greg-king5 deleted the vpoke branch October 24, 2019 20:27
@mobluse
Copy link
Contributor

mobluse commented Oct 25, 2019

This order of arguments of vpoke also goes against the ordinary C convention of order dest, src. See e.g. https://www.tutorialspoint.com/c_standard_library/c_function_strcpy.htm

One could change the name of vpoke to e.g. __vpoke and have a macro vpoke with the arguments in the normal order. This would also help people transitioning from BASIC to C.

@greg-king5
Copy link
Contributor Author

There is precedence for the order that I chose:

int fputc(int c, FILE* f);
int fputs(const char* s, FILE* f);
size_t fwrite(const void* buf, size_t size, size_t count, FILE* f);

Some standard functions use the source, destination order.

@greg-king5
Copy link
Contributor Author

One could change the name of vpoke() to, e.g., __vpoke(), and have a macro vpoke() with the arguments in the normal order. That also would help people transitioning from BASIC to C.

We already can do it:

#define VPOKE(dest,src) vpoke(src,dest)

We even can go "overboard", and write:

#define VPOKE(high,address,data) vpoke(data, ((unsigned long)(high) << 16) | (address))

@mobluse
Copy link
Contributor

mobluse commented Oct 26, 2019

I think those examples of reverse order assignment are exceptions because they were afterthoughts, e.g. putchar() probably existed first, and fputc() came as an extension. I don't think the solution with capitals looks like C. conio.h also has macros for textcolor() etc.

Another example from C library with order destination, source:
void * memcpy ( void * destination, const void * source, size_t num );

@mist64
Copy link
Collaborator

mist64 commented Oct 28, 2019

I really like the idea of a macro vpoke() with the "correct" order, and an implementation __vpoke() with the swapped one. (Where would we change this?)

@mobluse
Copy link
Contributor

mobluse commented Nov 13, 2019

vpoke is defined here:
https://github.com/cc65/cc65/blob/master/include/cx16.h#L190-L193

Then one could change the asm source at:
https://github.com/cc65/cc65/blob/master/libsrc/cx16/vpoke.s

Note: the standard PEEK and POKE in cc65 are in all caps and are macros: https://github.com/cc65/cc65/blob/master/include/peekpoke.h
but that's because ordinary PEEK and POKE are not needed in C. They exist only for BASIC programmers learning C.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants