co65-4.html
来自「cc65 的编译器文档」· HTML 代码 · 共 126 行
HTML
126 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><HTML><HEAD> <META NAME="GENERATOR" CONTENT="LinuxDoc-Tools 0.9.20"> <TITLE>co65 Users Guide: Converting loadable drivers</TITLE> <LINK HREF="co65-5.html" REL=next> <LINK HREF="co65-3.html" REL=previous> <LINK HREF="co65.html#toc4" REL=contents></HEAD><BODY><A HREF="co65-5.html">Next</A><A HREF="co65-3.html">Previous</A><A HREF="co65.html#toc4">Contents</A><HR><H2><A NAME="s4">4.</A> <A HREF="co65.html#toc4">Converting loadable drivers</A></H2><H2><A NAME="ss4.1">4.1</A> <A HREF="co65.html#toc4.1">Differences between static linking and runtime loading</A></H2><P>One main use of the utility is conversion of loadable drivers, so they may belinked statically to an application. Statically linking will cause a fewthings to be different from runtime loading:</P><P><UL><LI> Without changing the segment names, all segments take the defaultnames used by the standard linker configurations. This means that thedriver code is no longer contingous in memory, instead the codesegment is placed somewhere in between all other code segments, thedata segment is placed with all other data segments and so on. If thedriver doesn't do strange things this shouldn't be a problem.</LI><LI> With statically linked code, data and bss segments will get intializedonce (when the application is loaded), while a loadable driver willget its initialization each time the driver is loaded into memory(which may be more than once in the lifetime of a program). It dependson the driver if this is a problem. Currently, most drivers suppliedwith cc65 behave correctly when linked statically.</LI></UL></P><H2><A NAME="ss4.2">4.2</A> <A HREF="co65.html#toc4.2">Additional requirements</A></H2><P>All loadable drivers used by cc65 have a header and a jump table at the startof the code segment. The header is needed to detect the driver (it may alsocontain some data that is necessary to access the driver). The jump table isused to access the functions in the driver code.</P><P>When loading a driver at runtime, the load address of the driver is also theaddress of the code segment, so the locations of the header and jump table areknown. However, when linking the driver statically, it is up to the programmerto provide this information to the driver API.</P><P>For this purpose, it is necessary to define a code segment label that can beaccessed from the outside later. Please note that the converter does currently<EM>not</EM> create such a label without being ordered to do so, even if the inputfile is a cc65 module.</P><P>To create such a label, use the <CODE>--code-label</CODE> option when calling theconverter. Be sure to begin the label with a leading underscore when accessingit from C code. In your code, define an arbitrary variable with this name. Usethe address of this variable as the address of the code segment of the driver.Be sure to never modify the variable which is in reality the start of yourdriver!</P><H2><A NAME="ss4.3">4.3</A> <A HREF="co65.html#toc4.3">Example: Convert and link a graphics driver</A></H2><P>As an example, here are some instructions to convert and use the c64-hi.tgigraphics driver:</P><P>First, convert the driver, generating a label named "_c64_hi" for the codesegment. Use the assembler to generate an object file from the assembleroutput.</P><P><BLOCKQUOTE><CODE><PRE> co65 --code-label _c64_hi c64-hi.tgi ca65 c64-hi.s </PRE></CODE></BLOCKQUOTE></P><P>Next, change your C code to declare a variable that is actually the first byteof the driver:</P><P><BLOCKQUOTE><CODE><PRE> extern char c64_hi; </PRE></CODE></BLOCKQUOTE></P><P>Instead of loading and unloading the driver, change the code to install anduninstall the driver, which will be already in memory after linking:</P><P><BLOCKQUOTE><CODE><PRE> /* Install the driver */ tgi_install (&c64_hi); ... /* Uninstall the driver */ tgi_uninstall (); </PRE></CODE></BLOCKQUOTE></P><P>Don't forget to link the driver object file to your application, otherwise youwill get an "undefined external" error for the _c64_hi symbol.</P><HR><A HREF="co65-5.html">Next</A><A HREF="co65-3.html">Previous</A><A HREF="co65.html#toc4">Contents</A></BODY></HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?