From: Ullrich von Bassewitz (uz_at_musoftware.de)
Date: 1999-10-19 19:55:31
Hi! > I used to do much ASM on 65xx and I was wondering how > zeropage is handled in C and with cc65. I know some > optimization by cc65 probably tries to use this space > when possible, but is it possible I can access this > when I want to. If I decide to free and use areas like the > basic and tape space in zeropage, can I let cc65 know > to use this space for optimization? The current development version uses 26 bytes in the zeropage. About half of this space is temporary storage, used by many of the library routines. The other half is used for specific purposes like the stackpointer (the runtime uses a software stack) or an extended accumulator. A new feature in the development version is the use of register variables. If register variables are enabled, a few zero page cells are used to store local variables with storage class "register". However, this has some drawbacks, since the old contents of the zeropage locations have to be saved on the stack on function entry and restored on function exit. If you really need to use zero page locations within your program, you have two possibilities: 1. Use fixed memory locations. You may define pseudo variables using fixed addresses with the help of macros like this: /* X/Y value of pacman sprite stored in $FB/$FC */ #define PacmanX (*((unsigned char*)0xFB)) #define PacmanY (*((unsigned char*)0xFC)) Then use it like normal variables: PacmanX = 10; PacmanY = 10; ... if (PacmanY > 200) ... You may also put complete structs or arrays into specific memory locations using this method. For an example, have a look into the c64.h include file. It declares several macros that places structs at the hardware register addresses. You may then use stuff like: static void StartNoise (void) /* Start noise if configured */ { /* Configure noise on voice three if requested */ if (Effects & efNoise) { SID.v3.freq = 0x4000; SID.v3.ad = 0x00; SID.v3.sr = 0xA8; SID.flt_freq = 0xA000; SID.flt_ctrl = 0x44; SID.amp = 0x1F; SID.v3.ctrl = 0x81; } } (This was taken from the morse trainer software). 2. Define zero pages variables in an assembler file and declare them via a normal C extern declaration (do not forget to prepend the underscore in the assembler file). You have to place the segment containing the variables in the zero page by a linker configuration file. To make sure that the variables are actually imported as zeropage variables, use the zpsym #pragma: extern unsigned char PacmanX; extern unsigend char PacmanY; #pragma zpsym ("PacmanX"); #pragma zpsym ("PacmanY"); The first solution is probably the easier one for small programs. You may want to put the macros into a header file, so that all modules access the same memory locations. Be sure not use use any of the zero page locations that are used by the compiler! Regards Uz -- Ullrich von Bassewitz uz_at_musoftware.de ---------------------------------------------------------------------- To unsubscribe from the list send mail to majordomo_at_musoftware.de with the string "unsubscribe cc65" in the body(!) of the mail.
This archive was generated by hypermail 2.1.3 : 2001-12-14 22:05:45 CET