### Hello World C Example for Custom Hardware Source: https://cc65.github.io/doc/customizing.html This C code demonstrates basic I/O operations for a custom hardware setup with a UART and FIFO buffer. It waits for an interrupt, checks for a specific input character, and transmits a string via a hardware driver. ```c #define FIFO_DATA (*(unsigned char *) 0x1000) #define FIFO_STATUS (*(unsigned char *) 0x1001) #define TX_FIFO_FULL (FIFO_STATUS & 0x01) #define RX_FIFO_EMPTY (FIFO_STATUS & 0x02) extern void wait (); extern void __fastcall__ rs232_tx (char *str); int main () { while (1) { // Run forever wait (); // Wait for an RX FIFO interrupt while (RX_FIFO_EMPTY == 0) { // While the RX FIFO is not empty if (FIFO_DATA == '?') { // Does the RX character = '?' rs232_tx ("Hello World!"); // Transmit "Hello World!" } // Discard any other RX characters } } return (0); // We should never get here! } ``` -------------------------------- ### Example of Command Line Option Processing Source: https://cc65.github.io/doc/cl65.html Demonstrates how options are processed from left to right and applied to files. This example shows different optimization levels for two source files. ```bash cl65 -Oirs main.c -O -g module.c ``` -------------------------------- ### mouse_install Source: https://cc65.github.io/doc/funcref.html Installs a pre-loaded mouse driver, allowing interaction with mouse hardware. ```APIDOC ## mouse_install ### Description Installs an already loaded mouse driver and returns an error code. It accepts a structure of callbacks for mouse pointer control and a pointer to the driver itself. ### Declaration `unsigned char __fastcall__ mouse_install (const struct mouse_callbacks* c, void* driver);` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **c** (const struct mouse_callbacks*) - Description: A pointer to a structure containing callback routines for mouse pointer operations. - **driver** (void*) - Description: A pointer to the mouse driver to be installed. ### Request Example None ### Response #### Success Response (0) - **Return Value** (unsigned char) - Description: An error code indicating the success or failure of the installation. 0 typically means success. #### Response Example None ``` -------------------------------- ### Scope Search Order Example Source: https://cc65.github.io/doc/ca65.html Demonstrates scope visibility and search order. A scope must be defined before it can be referenced. This example shows how 'foo::bar' resolves to the globally defined 'bar' because the local 'foo' scope is not yet visible. ```assembly .scope foo bar = 3 .endscope .scope outer lda #foo::bar ; Will load 3, not 2! .scope foo bar = 2 .endscope .endscope ``` -------------------------------- ### Install Serial Driver (C) Source: https://cc65.github.io/doc/funcref.html Installs a pre-loaded or statically linked serial driver. Returns an error code, with SER_ERR_OK indicating success. Requires a prototype due to fastcall. ```c ser_install(lynx_comlynx); //Include the driver statically instead of loading it. ``` -------------------------------- ### Set Program Start Address Source: https://cc65.github.io/doc/apple2.html Use the -S option to specify a different program start address than the default $803. ```bash -S ``` -------------------------------- ### Set Default Start Address Source: https://cc65.github.io/doc/ld65.html Sets the default start address for the linker to $1000, which can be referenced by the %S symbol. ```plaintext FEATURES { # Default start address is $1000 STARTADDRESS: default = $1000; } ``` -------------------------------- ### chrcvt65 Verbose Example Source: https://cc65.github.io/doc/chrcvt65.html Demonstrates calling chrcvt65 with the --verbose option to increase output detail during font conversion. This example shows the command and the expected header output from the input file. ```bash chrcvt65 --verbose LITT.CHR ``` ```text BGI Stroked Font V1.1 - Aug 12, 1991 Copyright (c) 1987,1988 Borland International ``` -------------------------------- ### Install and Uninstall Driver in C Source: https://cc65.github.io/doc/co65.html Use these functions to install and uninstall the statically linked driver. The driver is already in memory after linking, so no loading or unloading is required. ```c /* Install the driver */ tgi_install (c64_hi); ... /* Uninstall the driver */ tgi_uninstall (); ``` -------------------------------- ### Example of Placeholder Usage with Potential Disassembly Issues Source: https://cc65.github.io/doc/smc.html Demonstrates using multiple placeholders which can lead to unidentifiable code for a debugger/disassembler if not handled carefully. The example shows how '$DE' might be misinterpreted. ```assembly SMC Example, { SMC_Opcode SMC_AbsAdr } ``` -------------------------------- ### ser_install Source: https://cc65.github.io/doc/funcref.html Installs an already loaded serial driver. Returns an error code. ```APIDOC ## ser_install ### Description Installs a serial driver that has already been loaded into memory or linked statically to the program. Returns an error code, with `SER_ERR_OK` indicating success. ### Declaration `unsigned char __fastcall__ ser_install (const void* driver);` ### Parameters * **driver** (const void*) - A pointer to the serial driver to install. ### Return Value * `unsigned char` - An error code, `SER_ERR_OK` on success. ### Notes * This function is only available as a fastcall function and requires a prototype. ### Example ```c ser_install(lynx_comlynx); // Include the driver statically instead of loading it. ``` ``` -------------------------------- ### Original Code Example Source: https://cc65.github.io/doc/smc.html This is a standard assembly code snippet before applying SMC. ```assembly PHA JSR SUBROUTINE PLA ``` -------------------------------- ### Customize Cheap Local Label Start Character Source: https://cc65.github.io/doc/ca65.html Use `.LOCALCHAR` to define the starting character for 'cheap' local labels, choosing between '@' (default) and '?'. Cheap local labels are visible only between two non-cheap labels, allowing identifier reuse. ```assembly .localchar '?' Clear: lda #$00 ; Global label ?Loop: sta Mem,y ; Local label dey bne ?Loop ; Ok rts Sub: ... ; New global label bne ?Loop ; ERROR: Unknown identifier! ``` -------------------------------- ### Assemble Program with ca65 Source: https://cc65.github.io/doc/ca65.html Assemble a program using cl65, specifying the start address and target format. Adjust start address for CBM load address. ```shell cl65 --start-addr 0x0ffe -t none myprog.s -o myprog.prg ``` -------------------------------- ### ld65: Start Library Group Source: https://cc65.github.io/doc/ld65.html Starts a library group, enabling multiple passes over libraries to resolve cross-references. This is useful when libraries depend on each other. ```bash -( --start-group ``` -------------------------------- ### Linker Expression Example Source: https://cc65.github.io/doc/ca65.html Demonstrates how the linker can resolve arbitrary expressions, including symbol imports and arithmetic operations. ```assembly .import S1, S2 .export Special Special = 2*S1 + S2/7 ``` -------------------------------- ### joy_install Source: https://cc65.github.io/doc/funcref.html Installs an already loaded driver and returns an error code. The function is only available as fastcall. ```APIDOC ## joy_install ### Description Install an already loaded driver and return an error code. ### Declaration `unsigned char __fastcall__ joy_install (const void* driver);` ### Description The function installs a driver that was already loaded into memory (or linked statically to the program). It returns an error code (`JOY_ERR_OK` in case of success). ### Notes * The function is only available as fastcall function, so it may only be used in presence of a prototype. ### See also * joy_load_driver * joy_uninstall * joy_unload ``` -------------------------------- ### Cheap Local Labels Example Source: https://cc65.github.io/doc/ca65.html Demonstrates the usage of cheap local labels, which are scoped between non-cheap labels. The '@Loop' label is reused effectively. ```assembly Clear: lda #$00 ; Global label ldy #$20 @Loop: sta Mem,y ; Local label dey bne @Loop ; Ok rts Sub: ... ; New global label bne @Loop ; ERROR: Unknown identifier! ``` -------------------------------- ### tgi_install Source: https://cc65.github.io/doc/tgi.html Installs a graphics driver that has already been loaded into memory or linked statically. Returns an error code. ```APIDOC ## tgi_install ### Description Install an already loaded driver and return an error code. ### Declaration `unsigned char __fastcall__ tgi_install (const void* driver); ### Notes The function installs a driver that was already loaded into memory (or linked statically to the program). It returns an error code (`TGI_ERR_OK` in case of success). The function is only available as fastcall function, so it may only be used in presence of a prototype. ### Availability cc65 ### See also tgi_load_driver, tgi_uninstall, tgi_unload ### Example ``` tgi_install(tgi_static_stddrv); tgi_init(); ``` ``` -------------------------------- ### sim65 Verbose Output Example Source: https://cc65.github.io/doc/sim65.html Demonstrates the verbose output of sim65 when running a program. This output includes details about program loading and paravirtualization calls. ```bash sim65 --verbose --verbose samples/gunzip65 ``` ```text Loaded 'samples/gunzip65' at $0200-$151F PVWrite ($0001, $13C9, $000F) GZIP file name:PVWrite ($0001, $151F, $0001) PVRead ($0000, $FFD7, $0001) PVOpen ("", $0001) PVRead ($0003, $1520, $6590) PVClose ($0003) PVWrite ($0001, $13D9, $000F) Not GZIP formatPVWrite ($0001, $151F, $0001) PVExit ($01) ``` -------------------------------- ### em_install Source: https://cc65.github.io/doc/funcref.html Installs an already loaded extended memory driver. This function is available as a fastcall function and requires a prototype. ```APIDOC ## em_install ### Description Installs an already loaded extended memory driver and returns an error code. This function can be used to install a driver linked statically to the program. ### Declaration `unsigned char _fastcall__ em_install (const void* driver);` ### Parameters * **driver** (const void*) - Description of the driver to install. ### Notes * Not all drivers can detect if the supported hardware is present. * This function is only available as a fastcall function and requires a prototype. ### Availability cc65 ### See also em_load_driver, em_uninstall, em_unload ``` -------------------------------- ### Assembler Input Examples Source: https://cc65.github.io/doc/ca65.html Demonstrates valid input lines for the cc65 assembler, including labels, comments, instructions, control commands, and symbol definitions. ```assembly Label: ; A label and a comment lda #$20 ; A 6502 instruction plus comment L1: ldx #$20 ; Same with label L2: .byte "Hello world" ; Label plus control command mymac $20 ; Macro expansion MySym = 3*L1 ; Symbol definition MaSym = Label ; Another symbol ``` -------------------------------- ### Define Macro with .MACRO Source: https://cc65.github.io/doc/ca65.html Start a classic macro definition using .MACRO, followed by the macro name and optional parameters. Terminate the definition with .ENDMACRO. ```assembly .macro ldax arg ; Define macro ldax lda arg ldx arg+1 ``` -------------------------------- ### cpeeks Source: https://cc65.github.io/doc/funcref.html Gets a fixed-length string from the display memory starting at the current cursor location. The string is converted to an encoding suitable for `cputs()`. ```APIDOC ## cpeeks ### Description Gets a fixed-length string ('\0'-terminated) of characters that start at the current location of the cursor in the display screen RAM. Those characters are converted, if needed, into the encoding that can be passed to `cputs()`. The first argument must point to a RAM area that's large enough to hold "length + 1" bytes. ### Declaration `void __fastcall__ cpeeks (char* s, unsigned length);` ### Notes * Conio peek functions do not have `cpeek...xy()` versions. This is to make it obvious that peeking does not move the cursor. Your program must place the cursor where it wants to peek before calling any of these functions. * The function is available as only a fastcall function; so, it may be used only in the presence of a prototype. ### Availability cc65 ### See also cpeekc, cpeekcolor, cpeekrevers, cputc, cputs ``` -------------------------------- ### StartMouseMode Source: https://cc65.github.io/doc/geos.html Initializes the mouse system by setting up mouse vectors and calling `MouseUp` to make the pointer visible. ```APIDOC ## StartMouseMode ### Description Initializes the mouse system by setting up the `mouseVector` and `mouseFaultVec` and then calls `MouseUp` to activate the mouse pointer. ### Signature `void StartMouseMode (void)` ``` -------------------------------- ### Setting Fixed Start Address for a Segment Source: https://cc65.github.io/doc/ld65.html Use the 'start' attribute to specify a fixed starting address for a segment, commonly used for critical areas like interrupt vectors. ```assembly SEGMENTS { VECTORS: load = ROM2, type = ro, start = $FFFA; } ``` -------------------------------- ### Example cc65 Info File Source: https://cc65.github.io/doc/da65.html This info file demonstrates various directives for defining output, input, memory layout, segments, ranges, labels, and vectors. ```assembly # This is a comment. It extends to the end of the line GLOBAL { OUTPUTNAME "kernal.s"; INPUTNAME "kernal.bin"; STARTADDR $E000; PAGELENGTH 0; # No paging CPU "6502"; }; # One segment for the whole stuff SEGMENT { START $E000; END $FFFF; NAME "kernal"; }; RANGE { START $E612; END $E631; TYPE Code; }; RANGE { START $E632; END $E640; TYPE ByteTable; }; RANGE { START $EA51; END $EA84; TYPE RtsTable; }; RANGE { START $EC6C; END $ECAB; TYPE RtsTable; }; RANGE { START $ED08; END $ED11; TYPE AddrTable; }; # Zero-page variables LABEL { NAME "fnadr"; ADDR $90; SIZE 3; }; LABEL { NAME "sal"; ADDR $93; }; LABEL { NAME "sah"; ADDR $94; }; LABEL { NAME "sas"; ADDR $95; }; # Stack LABEL { NAME "stack"; ADDR $100; SIZE 255; }; # Indirect vectors LABEL { NAME "cinv"; ADDR $300; SIZE 2; }; # IRQ LABEL { NAME "cbinv"; ADDR $302; SIZE 2; }; # BRK LABEL { NAME "nminv"; ADDR $304; SIZE 2; }; # NMI # Jump table at end of kernal ROM LABEL { NAME "kscrorg"; ADDR $FFED; }; LABEL { NAME "kplot"; ADDR $FFF0; }; LABEL { NAME "kiobase"; ADDR $FFF3; }; LABEL { NAME "kgbye"; ADDR $FFF6; }; # Hardware vectors LABEL { NAME "hanmi"; ADDR $FFFA; }; LABEL { NAME "hares"; ADDR $FFFC; }; LABEL { NAME "hairq"; ADDR $FFFE; }; ``` -------------------------------- ### Display Help Text Source: https://cc65.github.io/doc/co65.html Prints the short option summary, providing a quick reference for available command-line arguments. ```bash -h, --help ``` -------------------------------- ### Customizing Run-Time Library Source: https://cc65.github.io/doc/customizing.html Steps to create a custom run-time library by copying an existing one, compiling new startup code, and updating the library archive. This is useful when the target hardware lacks standard I/O features. ```bash $ copy "C:\\Program Files\\cc65\\lib\\supervision.lib" sbc.lib $ ca65 crt0.s $ ar65 a sbc.lib crt0.o ``` -------------------------------- ### Access Default Start Address Source: https://cc65.github.io/doc/ld65.html The symbol %S can be used to access the default start address of a memory section. ```linker script %S ``` -------------------------------- ### ld65: Display Help Source: https://cc65.github.io/doc/ld65.html Prints a summary of the short command-line options for the ld65 linker. ```bash -h --help ``` -------------------------------- ### Create a ProDOS Text File with Custom Attributes Source: https://cc65.github.io/doc/apple2enh.html This example demonstrates how to create a sequential text file in ProDOS by setting the _filetype to PRODOS_T_TXT and _auxtype to PRODOS_AUX_T_TXT_SEQ before calling fopen(). It includes error handling for file operations. ```c #include #include #include #include void main(void) { FILE *out; char *name = "MY.FAVS"; /*-----------------------------*/ _filetype = PRODOS_T_TXT; _auxtype = PRODOS_AUX_T_TXT_SEQ; /*-----------------------------*/ if ((out = fopen(name, "w")) != NULL) { fputs("Jorah Mormont\r", out); fputs("Brienne of Tarth\r", out); fputs("Daenerys Targaryen\r", out); fputs("Sandor Clegane\r", out); if (fclose(out) == EOF) { fprintf(stderr, "fclose failed for %s: %s", name, strerror(errno)); } } else { fprintf(stderr, "fopen failed for %s: %s", name, strerror(errno)); } } ``` -------------------------------- ### Complex SMC Example for memset Implementation Source: https://cc65.github.io/doc/smc.html Demonstrates advanced SMC usage for modifying code, including modifying the code modifications themselves. This example is from a memset() implementation. ```assembly 1: ... 2: SMC_StoreAddress StoreAccuFirstSection 3: 4: StoreToFirstSection: 5: SMC StoreAccuFirstSection, { sta SMC_AbsAdr, Y } 6: ... 7: RestoreCodeBranchBaseAdr: 8: SMC FirstIncHighByte, { SMC_OperateOnHighByte inc, StoreAccuFirstSection } ; code will be overwritten to 'beq RestoreCode' (*) 9: ... 10: SMC_TransferOpcode FirstIncHighByte, OPC_BEQ , x ; change code marked above with (*) 11: SMC_TransferValue FirstIncHighByte, #(restoreCode - RestoreCodeBranchBaseAdr-2), x ; set relative address to 'RestoreCode' 12: ... 13: restoreCode: 14: SMC_TransferOpcode FirstIncHighByte, OPC_INC_abs , x ; restore original code... 15: SMC_TransferValue FirstIncHighByte, #(<(StoreToFirstSection+2)), x ; (second byte of inc contained low-byte of address) 16: ... ``` -------------------------------- ### Build Commands for Custom cc65 Project Source: https://cc65.github.io/doc/customizing.html These commands demonstrate the build process for a cc65 project targeting custom hardware. They show the sequence of compilation, assembly, and linking required to create a ROM image. ```bash $ cc65 -t none -O --cpu 65sc02 main.c $ ca65 --cpu 65sc02 main.s $ ca65 --cpu 65sc02 rs232_tx.s $ ca65 --cpu 65sc02 interrupt.s $ ca65 --cpu 65sc02 vectors.s $ ca65 --cpu 65sc02 wait.s $ ld65 -C sbc.cfg -m main.map interrupt.o vectors.o wait.o rs232_tx.o main.o sbc.lib ``` -------------------------------- ### CX16 Assembly Configuration Source: https://cc65.github.io/doc/cx16.html Configuration file for CX16 assembly. Note that changing the start address is not recommended as the program must be loaded to BASIC's start address. ```assembly ` ``` -------------------------------- ### Compiler Command Line Overview Source: https://cc65.github.io/doc/cc65.html Provides a general overview of cc65 command line options. ```bash ` ``` -------------------------------- ### Unnamed Labels Example Source: https://cc65.github.io/doc/ca65.html Illustrates the use of unnamed labels with forward and backward references using '+' and '-' respectively. This example shows branching to a previous unnamed label. ```assembly cpy #0 beq :++ : sta $2007 dey bne :- : rts ``` -------------------------------- ### Compile VIC-20 Hi-Res TGI Driver Source: https://cc65.github.io/doc/vic20.html Example command line for compiling a C program using the vic20-hi.tgi driver with cc65. Ensure the vic20-tgi.cfg configuration file is used for linking. ```bash cl65 -D DYN_DRV=0 -t vic20 -C vic20-tgi.cfg samples/mandelbrot.c ``` -------------------------------- ### Initialize and Open Serial Port Source: https://cc65.github.io/doc/funcref.html Initializes serial parameters and opens the serial port for communication. Ensure to call `ser_install` before `ser_open` and disable interrupts during initialization. ```c #include static void initialize(){ struct ser_params params = { SER_BAUD_9600, SER_BITS_8, SER_STOP_1, SER_PAR_MARK, SER_HS_NONE }; ser_install(lynx_comlynx); // This will activate the ComLynx CLI(); ser_open(¶ms); } ``` -------------------------------- ### File Option Insertion Examples Source: https://cc65.github.io/doc/ca65.html Demonstrates the use of the '.FILEOPT' and '.FOPT' directives to insert keyword-based option strings into the object file. These options are written but not actively used by the assembler. ```assembly .fileopt comment, "Code stolen from my brother" .fileopt compiler, "BASIC 2.0" .fopt author, "J. R. User" ``` -------------------------------- ### Passing Arguments to a Program Source: https://cc65.github.io/doc/apple2.html Demonstrates the syntax for passing command-line arguments to a program after BLOAD. Arguments are space-separated and can be quoted. The first argument is the program name, and a maximum of 10 arguments are supported. ```assembly CALL2051:REM ARG1 " ARG2 IS QUOTED" ARG3 "" ARG5 ``` -------------------------------- ### Scope Resolution Example in cc65 Assembly Source: https://cc65.github.io/doc/ca65.html This example demonstrates how to define nested scopes and access symbols within them using the `::` namespace token. It shows how the assembler resolves `::outer::inner::bar` by searching through scopes. ```assembly .scope foo .scope outer .scope inner bar = 1 .endscope .endscope .scope another .scope nested lda #::outer::inner::bar ; 2 .endscope .endscope .endscope .scope outer .scope inner bar = 2 .endscope .endscope ``` -------------------------------- ### Attribute List Syntax Example Source: https://cc65.github.io/doc/sp65.html Demonstrates the general syntax for attribute lists, which are used to configure sp65 modules. Commas or colons can separate attribute/value pairs. ```shell attr1=val1[,attr2=val2[,...]] ``` -------------------------------- ### tgi_init Source: https://cc65.github.io/doc/tgi.html Initializes the graphics driver and sets the default hardware palette. Does not clear the screen by default. ```APIDOC ## tgi_init ### Description Initialize the already loaded graphics driver. ### Declaration `void tgi_init (void);` ### Notes The tgi_init function will set the default palette to the hardware. `tgi_init` will not clear the screen. This allows switching between text and graphics mode on platforms that have separate memory areas for the screens. If you want the screen cleared, call `tgi_clear` after `tgi_init`. ### Availability cc65 ### See also Other tgi functions. ### Example ``` tgi_install(tgi_static_stddrv); tgi_init(); ``` ``` -------------------------------- ### GEOSLib Data Initialization Example Source: https://cc65.github.io/doc/geos.html Demonstrates GEOSLib's use of cc65 non-ANSI extensions for initializing data in memory with an array of unspecified length and type. This method allows for direct byte and word assignments. ```c void example = { (char)3, (unsigned)3, (char)0 }; ``` ```assembly _example: .byte 3 .word 3 .byte 0 ``` -------------------------------- ### Hello World Application for Atari Lynx Source: https://cc65.github.io/doc/lynx.html A basic 'Hello World' program for the Atari Lynx using cc65. It initializes the Tiny Graphics Interface (TGI), clears the screen, sets the color to green, displays 'Hello World', and updates the display. Requires lynx.h, tgi.h, and 6502.h. ```c #include #include #include <6502.h> void main(void) { tgi_install(tgi_static_stddrv); tgi_init(); CLI(); while (tgi_busy()) ; tgi_clear(); tgi_setcolor(COLOR_GREEN); tgi_outtextxy(0, 0, "Hello World"); tgi_updatedisplay(); while (1) ; } ``` -------------------------------- ### SIM65 Trace Output Example Source: https://cc65.github.io/doc/sim65.html This is an example of the detailed trace output generated by SIM65 when tracing is enabled. It shows instruction counter, clock cycles, program counter, instruction bytes, assembly, CPU registers, and CC65 stack pointer. ```text 70 232 022E A2 12 ldx #$12 A=7F X=00 Y=04 S=FD Flags=nvdizC SP=FFBC 71 234 0230 A9 34 lda #$34 A=7F X=12 Y=04 S=FD Flags=nvdizC SP=FFBC 72 236 0232 8D C8 02 sta $02C8 A=34 X=12 Y=04 S=FD Flags=nvdizC SP=FFBC 73 240 0235 8E C9 02 stx $02C9 A=34 X=12 Y=04 S=FD Flags=nvdizC SP=FFBC 74 244 0238 A9 00 lda #$00 A=34 X=12 Y=04 S=FD Flags=nvdizC SP=FFBC 75 246 023A 8D CB FF sta $FFCB A=00 X=12 Y=04 S=FD Flags=nvdiZC SP=FFBC ``` -------------------------------- ### rewinddir Source: https://cc65.github.io/doc/funcref.html Resets a directory stream to the start of the directory. ```APIDOC ## rewinddir ### Description Reset a directory stream. `rewinddir` sets the position of the directory stream pointed to by `dir` to the start of the directory. ### Declaration `void __fastcall__ rewinddir (DIR* dir);` ### Notes The function is only available as fastcall function, so it may only be used in presence of a prototype. ### Availability POSIX 1003.1 ### See also seekdir, telldir ``` -------------------------------- ### creat Source: https://cc65.github.io/doc/funcref.html Creates a new file and returns a file descriptor. It is equivalent to calling open with specific flags. ```APIDOC ## creat ### Description Create a file. ### Declaration `int __fastcall__ creat (const char* name, unsigned mode);` ### Details `creat` creates a new file and returns the file descriptor associated with it. On error, -1 is returned and an error code is stored in `errno`. ### Notes * `creat` is identical to calling `open` with `flags` equal to `O_WRONLY | O_CREAT | O_TRUNC`. * The function is only available as fastcall function, so it may only be used in presence of a prototype. ### Availability POSIX 1003.1 ### See also close, open ``` -------------------------------- ### chline Source: https://cc65.github.io/doc/funcref.html Outputs a horizontal line with the given length starting at the current cursor position. ```APIDOC ## chline ### Description Outputs a horizontal line with the given length starting at the current cursor position. ### Declaration `void __fastcall__ chline (unsigned char length);` ### Parameters #### Path Parameters - **length** (unsigned char) - Description: The length of the horizontal line to draw. ### Notes - The character used to draw the horizontal line is system dependent. If available, a line drawing character is used. - Drawing a line that is partially off screen leads to undefined behaviour. - The function is only available as fastcall function, so it may only be used in presence of a prototype. ### Availability cc65 ``` -------------------------------- ### ser_load_driver Source: https://cc65.github.io/doc/funcref.html Loads and installs a serial driver by its name. It verifies if the driver was loaded successfully. ```APIDOC ## ser_load_driver ### Description Load and install the driver by name. Will just load the driver and check if loading was successful. ### Declaration `unsigned char __fastcall__ ser_load_driver (const char *name);` ### Notes * The function is only available as fastcall function, so it may only be used in presence of a prototype. ``` -------------------------------- ### Using Alternative I/O Buffer Allocation Source: https://cc65.github.io/doc/apple2.html Example of linking a cc65 program with the apple2-iobuf-0800.o module for ProDOS 8 I/O buffer allocation. This reduces code size compared to default heap allocation. ```bash cl65 -t apple2 -C apple2-system.cfg myprog.c apple2-iobuf-0800.o ``` -------------------------------- ### Get Size of Inner Procedure Source: https://cc65.github.io/doc/ca65.html Calculates the size of the 'Inner' procedure, which is 1 byte. ```assembly .sizeof(Code::Inner) ``` -------------------------------- ### joy_load_driver Source: https://cc65.github.io/doc/funcref.html Loads a driver from disk and installs it, returning an error code. The function is only available as fastcall. ```APIDOC ## joy_load_driver ### Description Load a driver from disk and install it. ### Declaration `unsigned char __fastcall__ joy_load_driver (const char* driver);` ### Description The function loads a driver with the given name from disk and installs it. An error code is returned, which is `JOY_ERR_OK` if the driver was successfully loaded and installed. ### Notes * The function is only available as fastcall function, so it may only be used in presence of a prototype. ### See also * joy_install * joy_uninstall * joy_unload ``` -------------------------------- ### Initialize Disk for GEOS Source: https://cc65.github.io/doc/geos.html Initializes GEOS for a new disk, loading TurboDos if necessary, and checking the disk format. ```c char OpenDisk (void) ``` ```c char NewDisk (void) ``` -------------------------------- ### Get Size of Struct Source: https://cc65.github.io/doc/ca65.html Calculates the size of the 'Point' struct, which is 4 bytes (two words). ```assembly .sizeof(Point) ``` -------------------------------- ### joy_uninstall Source: https://cc65.github.io/doc/funcref.html Uninstalls the currently installed joystick driver without removing it from memory. Returns an error code. ```APIDOC ## joy_uninstall ### Description Uninstalls the currently installed joystick driver. It does not remove the driver from memory. The function returns an error code, which is `JOY_ERR_OK` if the driver was successfully uninstalled. ### Declaration `unsigned char joy_uninstall (void);` ``` -------------------------------- ### tgi_load_driver Source: https://cc65.github.io/doc/tgi.html Loads and installs a graphics driver by its name. It checks for successful loading but does not switch to graphics mode. ```APIDOC ## tgi_load_driver ### Description Load and install the driver by name. Will just load the driver and check if loading was successful. Will not switch to graphics mode. ### Declaration `void __fastcall__ tgi_load_driver (const char *name);` ### Parameters - **name** (const char *) - The name of the driver to load. ### Notes - The function is only available as fastcall function, so it may only be used in presence of a prototype. ``` -------------------------------- ### DbgInit Source: https://cc65.github.io/doc/funcref.html Initializes the debugger. This function prepares the debugger to be used, typically before encountering a breakpoint. ```APIDOC ## DbgInit ### Description Initialize the debugger. `DbgInit` initializes the debugger. ### Declaration `void __fastcall__ DbgInit (unsigned unused);` ### Parameters * `unused` (unsigned) - Use 0 as parameter. ### Notes * The debugger will popup on next brk encountered. ### Availability cc65 ``` -------------------------------- ### Passing Arguments to Programs Source: https://cc65.github.io/doc/c16.html Demonstrates the syntax for passing command-line arguments to a program, which are then accessible in the main() function. Arguments are space-separated and can be quoted. ```assembly RUN:REM ARG1 " ARG2 IS QUOTED" ARG3 "" ARG5 ``` -------------------------------- ### od65 Command Line Usage Overview Source: https://cc65.github.io/doc/od65.html Displays the general usage and available short and long options for the od65 command-line tool. Use -h or --help for this summary. ```bash Usage: od65 [options] file [options] [file] Short options: -h Help (this text) -H Dump the object file header -S Dump segments sizes -V Print the version number and exit Long options: --dump-all Dump all object file information --dump-dbgsyms Dump debug symbols --dump-exports Dump exported symbols --dump-files Dump the source files --dump-header Dump the object file header --dump-imports Dump imported symbols --dump-lineinfo Dump line information --dump-options Dump object file options --dump-segments Dump the segments in the file --dump-segsize Dump segments sizes --help Help (this text) --version Print the version number and exit ``` -------------------------------- ### tgi_getpalette Source: https://cc65.github.io/doc/tgi.html Retrieves a pointer to the currently installed color palette. This allows inspection of the available colors and their mapping. ```APIDOC ## tgi_getpalette ### Description Get the palette installed. ### Declaration `const unsigned char* tgi_getpalette (void);` ### Availability cc65 ### See also Other tgi functions ``` -------------------------------- ### Retrieve Value from an SMC Line Source: https://cc65.github.io/doc/smc.html Retrieves the value of a SMC line. This example loads the value from `LoadDefault`. ```assembly ShowDefault: SMC_LoadValue LoadDefault JSR PrintValue RTS ... SMC LoadDefault, { LDX #25 } ``` -------------------------------- ### Passing Arguments to Main() on Atmos Source: https://cc65.github.io/doc/atmos.html Demonstrates the syntax for passing command-line arguments to the main() function on Atmos, which is not directly supported by BASIC. Arguments are space-separated and can be quoted. ```BASIC RUN:REM arg1 " ARG2 IS QUOTED" ARG3 "" ARG5 ``` -------------------------------- ### Get Size of Label Source: https://cc65.github.io/doc/ca65.html Calculates the size of the data associated with the label 'P', which is 4 bytes in the same segment. ```assembly .sizeof(P) ``` -------------------------------- ### Check String Start with .STRAT Source: https://cc65.github.io/doc/ca65.html Use .STRAT to check if a string begins with a specific character. The index is zero-based. ```assembly .macro M Arg ; Check if the argument string starts with '#' .if (.strat (Arg, 0) = '#') ... .endif .endmacro ``` -------------------------------- ### ld65 Command-Line Usage Overview Source: https://cc65.github.io/doc/ld65.html Provides a summary of all available short and long command-line options for the ld65 linker. ```bash Usage: ld65 [options] module ... Short options: -( Start a library group -) End a library group -C name Use linker config file -D sym=val Define a symbol -L path Specify a library search path -Ln name Create a VICE label file -S addr Set the default start address -V Print the linker version -h Help (this text) -m name Create a map file -o name Name the default output file -t sys Set the target system -u sym Force an import of symbol 'sym' -v Verbose mode -vm Verbose map file Long options: --allow-multiple-definition Allow multiple definitions --cfg-path path Specify a config file search path --color [on|auto|off] Color diagnostics (default: auto) --config name Use linker config file --dbgfile name Generate debug information --define sym=val Define a symbol --end-group End a library group --force-import sym Force an import of symbol 'sym' --help Help (this text) --large-alignment Don't warn about large alignments --lib file Link this library --lib-path path Specify a library search path --mapfile name Create a map file --module-id id Specify a module id --no-utf8 Disable use of UTF-8 in diagnostics --obj file Link this object file --obj-path path Specify an object file search path --start-addr addr Set the default start address --start-group Start a library group --target sys Set the target system --version Print the linker version --warn-align-waste Print bytes "wasted" for alignment --warnings-as-errors Treat warnings as errors ``` -------------------------------- ### grc65 Command-Line Options Source: https://cc65.github.io/doc/grc65.html Use this to display help text, version information, or specify output file names and target systems for grc65. ```bash Usage: grc65 [options] file Short options: -V Print the version number -h Help (this text) -o name Name the C output file -s name Name the asm output file -t sys Set the target system Long options: --help Help (this text) --target sys Set the target system --version Print the version number ``` -------------------------------- ### Change Value of an SMC Line Source: https://cc65.github.io/doc/smc.html Changes the value of a SMC line. This example sets the value of `LoadDefault` to 0. ```assembly ClearDefault: SMC_TransferValue LoadDefault, 0 RTS ... SMC LoadDefault, { LDX #25 } ``` -------------------------------- ### Compile C and Assembly to Executable Source: https://cc65.github.io/doc/intro.html Use the cl65 utility to compile C and assembly files into a single executable. cl65 handles the compiler, assembler, and linker steps automatically. ```bash cl65 -O hello.c text.s ``` -------------------------------- ### Compressing data with ZX02 Source: https://cc65.github.io/doc/decompression.html Command-line example for compressing data using ZX02. The output file is named DATA.ZX02. ```shell zx02 -f input.bin DATA.ZX02 ``` -------------------------------- ### Get Size of Data Segment Source: https://cc65.github.io/doc/ca65.html Calculates the size of the 'Data' procedure, which is 0 bytes because the segment was switched after entry. ```assembly .sizeof(Data) ``` -------------------------------- ### Link Object Files and Libraries in Order Source: https://cc65.github.io/doc/ld65.html Demonstrates the correct order for specifying object files and libraries on the command line. The linker processes modules from left to right, so libraries can only satisfy references from modules listed before them. ```bash ld65 crt0.o clib.lib test.o ``` ```bash ld65 crt0.o test.o clib.lib ``` -------------------------------- ### Get Size of Procedure Source: https://cc65.github.io/doc/ca65.html Calculates the size of the 'Code' procedure, which is 3 bytes, including data in child scopes. ```assembly .sizeof(Code) ```