EC-65K specific information for cc65

Michiel Broek, mbse@mbse.eu

13-Apr-2009
An overview over the EC-65K runtime system as it is implemented for the cc65 C compiler.

1. Overview

2. Binary format

3. Memory layout

4. Platform specific header files

5. Loadable drivers

6. Limitations

7. Other hints

8. Bugs/Feedback

9. License


1. Overview

This file contains an overview of the EC-65K runtime system as it comes with the cc65 C compiler. It describes the memory layout, EC-65K specific header files, available drivers, and any pitfalls specific to that platform. The target OS used on the EC-65K is DOS/65.

Please note that EC-65K specific functions are just mentioned here, they are described in detail in the separate function reference. Even functions marked as "platform dependent" may be available on more than one platform. Please see the function reference for more information.

2. Binary format

The standard binary output format generated by the linker for the EC-65K target is a machine language program without a header. The standard load and autostart address is $0200.

3. Memory layout

In the standard setup, cc65 generated programs use the memory from $0200 to $B1FF, so nearly 44K of memory (including the stack) is available. ROM calls are possible without further precautions.

Special locations:

Text screen

The text screen is located at $E800 (as in the standard setup).

Stack

The C runtime stack is located at $B1FF and growing downwards.

Heap

The C heap is located at the end of the program and grows towards the C runtime stack.

4. Platform specific header files

Programs containing EC-65K specific code may use the ec65k.h header file.

4.1 EC-65K specific functions

The functions listed below are special for the EC-65K. See the function reference for declaration and usage.

4.2 Hardware access

The following pseudo variables declared in the ec65k.h header file do allow access to hardware located in the address space. Some variables are structures, accessing the struct fields will access the chip registers.

KBDPIA

The PIA structure allows read access to the PIA 6821 at $E400. See the _pia.h header file located in the include directory for the declaration of the structure. Port A is used for the keyboard, port B is free to use.

PRTPIA

The PIA structure allows read access to the PIA 6821 at $E420. See the _pia.h header file located in the include directory for the declaration of the structure. This PIA is used for the Centronics port, warn lamp and to read the jumpers on the I/O card.

ACIA

Access to the ACIA (the RS232 chip) at $E410 is available via the ACIA variable. See the _6551.h header file located in the include directory for the declaration of the structure.

CRTC

The CRTC structure allows access to the CRTC (the video controller) at $E140. See the _6545.h header file located in the include directory for the declaration of the structure.

MOSI IO card

The optional MOSI I/O card gives access to 4 PIA's.

  1. MOSIP1 at $E118
  2. MOSIP2 at $E11C (most used for a Centronics printer).
  3. MOSIP3 at $E110
  4. MOSIP4 at $E114 (most used for a EPROM programmer).

5. Loadable drivers

5.1 Extended memory drivers

ec65k-auxmem.emd

A driver for the Extended Memory card, AKA 64K dynamic RAM card. This card must be present to boot DOS/65, so there are no checks if this card is installed. Because the card is used by DOS/65, there are only 96 free 256 byte pages. There are no checks, so if your program knows better, you are able to manipulate the DOS/65 buffers.

5.2 RS232 device drivers

ec65k-serial.ser

Driver for the serial port on the IOcard at $E410. Supports upto 19200 baud, hardware flow control (RTS/CTS) and interrupt driven receives. Note that because of the peculiarities of the 6551 chip transmits are not interrupt driven, and the transceiver blocks if the receiver asserts flow control because of a full buffer.

6. Limitations

6.1 DIO implementation

The underlying DOS/65 filesystem is based on CP/M and uses 128 bytes sectors even if the physical sectors on the disks have a different size. Therefore, the DIO read and write functions allways transfer only 128 bytes at a time.

6.2 Directories

The DOS/65 Operating System is based on CP/M 1.4 and has no knowledge of directories, only drive names. The implementation of the directory functions is based on drive names instead of directory paths.

DIR *opendir(char *name)

The opendir function should be called with a directory search pattern and may include a drive name. The search is not case sensitive. Examples:


#include <dirent.h>

DIR  *dp;

dp = opendir((char *)"A:*.Com");
closedir(dp);

dp = opendir((char *)"C:*.*");
closedir(dp);

You can only open one directory at a time. This limitation is on purpose because DOS/65 just doesn't allow more then one directory open at a time. Another limitation is that during the read of the directory, no other file operations may take place. To work around this limitation, open the directory, read the directory and save the results and then close the directory.

int closedir(DIR *dirp)

Close the directory that was opened with opendir(), see above for an example.

struct dirent *readdir(DIR *dirp)

The readdir() function returns a pointer to a dirent structure representing the next directory entry in the directory stream pointed to by dirp. It returns NULL on reaching the end of the directory stream or if an error occurred. The dirent structure is defined as follows:


struct dirent {
    char         d_name[12];        /* filename      */
};

void rewinddir(DIR *dirp)

The rewinddir() function resets the position of the directory stream dirp to the beginning of the directory.

char *getcwd(char *buf, size_t size)

Return the working directory, in this implementation the drive name is returned like "A:".


#include <unistd.h>

char *wd;

wd = calloc(20, sizeof(char));
getcwd(wd, 19);
printf("%s", wd);
free(wd);

int chdir(const char *path)

This function is used to select the drive. It needs a two characters string like "A:" or "c:".

int mkdir(const char *pathname, mode_t mode)

Because real directories are not implemented, this function returns -1 and sets the "Function not implemented" error.

int rmdir(const char *pathname)

Because real directories are not implemented, this function returns -1 and sets the "Function not implemented" error.

7. Other hints

7.1 Passing arguments to the program

Command line arguments can be passed to main().

  1. Arguments are separated by spaces.
  2. Arguments may be quoted.
  3. Leading and trailing spaces around an argument are ignored. Spaces within a quoted argument are allowed.
  4. The first argument passed to main() is the program name. Unfortunatly DOS/65 only saves the command line arguments, so a fake program name is set to fill in argv[0]. This name is MYNAME.COM.
  5. A maximum number of 10 arguments (including the program name) are supported.

8. Bugs/Feedback

If you have problems using the library, if you find any bugs, or if you're doing something interesting with it, I would be glad to hear from you. Feel free to contact me by email ( mbse@mbse.eu).

9. License

This software is provided 'as-is', without any expressed or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  3. This notice may not be removed or altered from any source distribution.