EC-65K specific information for cc65 <author>Michiel Broek, <htmlurl url="mailto:mbse@mbse.eu" name="mbse@mbse.eu"> <date>13-Apr-2009 <abstract> An overview over the EC-65K runtime system as it is implemented for the cc65 C compiler. </abstract> <!-- Table of contents --> <toc> <!-- Begin the document --> <sect>Overview<p> 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 <htmlurl url="funcref.html" name="function reference">. Even functions marked as "platform dependent" may be available on more than one platform. Please see the function reference for more information. <sect>Binary format<p> 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. <sect>Memory layout<p> 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: <descrip> <tag/Text screen/ The text screen is located at $E800 (as in the standard setup). <tag/Stack/ The C runtime stack is located at $B1FF and growing downwards. <tag/Heap/ The C heap is located at the end of the program and grows towards the C runtime stack. </descrip><p> <sect>Platform specific header files<p> Programs containing EC-65K specific code may use the <tt/ec65k.h/ header file. <sect1>EC-65K specific functions<p> The functions listed below are special for the EC-65K. See the <htmlurl url="funcref.html" name="function reference"> for declaration and usage. <itemize> <item>get_ostype </itemize> <sect1>Hardware access<p> The following pseudo variables declared in the <tt/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. <descrip> <tag><tt/KBDPIA/</tag> The <tt/PIA/ structure allows read access to the PIA 6821 at $E400. See the <tt/_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. <tag><tt/PRTPIA/</tag> The <tt/PIA/ structure allows read access to the PIA 6821 at $E420. See the <tt/_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. <tag><tt/ACIA/</tag> Access to the ACIA (the RS232 chip) at $E410 is available via the <tt/ACIA/ variable. See the <tt/_6551.h/ header file located in the include directory for the declaration of the structure. <tag><tt/CRTC/</tag> The <tt/CRTC/ structure allows access to the CRTC (the video controller) at $E140. See the <tt/_6545.h/ header file located in the include directory for the declaration of the structure. <tag><tt/MOSI IO card/</tag> The optional MOSI I/O card gives access to 4 PIA's. <enum> <item><bf/MOSIP1/ at $E118 <item><bf/MOSIP2/ at $E11C (most used for a Centronics printer). <item><bf/MOSIP3/ at $E110 <item><bf/MOSIP4/ at $E114 (most used for a EPROM programmer). </enum> </descrip><p> <sect>Loadable drivers<p> <sect1>Extended memory drivers<p> <descrip> <tag><tt/ec65k-auxmem.emd/</tag> 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. </descrip><p> <sect1>RS232 device drivers<p> <descrip> <tag><tt/ec65k-serial.ser/</tag> 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. </descrip><p> <sect>Limitations<label id="limitations"><p> <sect1>DIO implementation<label id="dio"><p> 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. <sect1>Directories<label id="dirs"><p> 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. <descrip> <tag><tt/DIR *opendir(char *name)/</tag> The opendir function should be called with a directory search pattern and may include a drive name. The search is not case sensitive. Examples: <code> #include <dirent.h> DIR *dp; dp = opendir((char *)"A:*.Com"); closedir(dp); dp = opendir((char *)"C:*.*"); closedir(dp);</code> 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. <tag><tt/int closedir(DIR *dirp)/</tag> Close the directory that was opened with opendir(), see above for an example. <tag><tt/struct dirent *readdir(DIR *dirp)/</tag> 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: <code> struct dirent { char d_name[12]; /* filename */ };</code> <tag><tt/void rewinddir(DIR *dirp)/</tag> The rewinddir() function resets the position of the directory stream dirp to the beginning of the directory. <tag><tt/char *getcwd(char *buf, size_t size)/</tag> Return the working directory, in this implementation the drive name is returned like <sq/A:/. <code> #include <unistd.h> char *wd; wd = calloc(20, sizeof(char)); getcwd(wd, 19); printf("%s", wd); free(wd);</code> <tag><tt/int chdir(const char *path)/</tag> This function is used to select the drive. It needs a two characters string like <sq/A:/ or <sq/c:/. <tag><tt/int mkdir(const char *pathname, mode_t mode)/</tag> Because real directories are not implemented, this function returns -1 and sets the <sq/Function not implemented/ error. <tag><tt/int rmdir(const char *pathname)/</tag> Because real directories are not implemented, this function returns -1 and sets the <sq/Function not implemented/ error. </descrip><p> <sect>Other hints<p> <sect1>Passing arguments to the program<p> Command line arguments can be passed to <tt/main()/. <enum> <item>Arguments are separated by spaces. <item>Arguments may be quoted. <item>Leading and trailing spaces around an argument are ignored. Spaces within a quoted argument are allowed. <item>The first argument passed to <tt/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. <item>A maximum number of 10 arguments (including the program name) are supported. </enum> <sect>Bugs/Feedback<p> 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 (<htmlurl url="mailto:mbse@mbse.eu" name="mbse@mbse.eu">). <sect>License<p> 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: <enum> <item> 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. <item> Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. <item> This notice may not be removed or altered from any source distribution. </enum> </article>