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.
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.
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:
The text screen is located at $E800 (as in the standard setup).
The C runtime stack is located at $B1FF and growing downwards.
The C heap is located at the end of the program and grows towards the C runtime stack.
Programs containing EC-65K specific code may use the ec65k.h
header file.
The functions listed below are special for the EC-65K. See the function reference for declaration and usage.
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.
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.
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.
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.
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);
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.
Command line arguments can be passed to main()
.
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.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).
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: