cc65 function reference
1. Introduction
cc65 is a C compiler for 6502-based systems. It implements a subset of the ISO C standard plus additional functions specially crafted for 6502 systems or just some of the supported machines. This function reference describes the available functions together with any limitations.
For an overview of which standard functions are missing or limited on this target, see section 5. Functions that are not listed here or in the header files behave as defined in the C standard.
Note: Standard C functions are listed here, but not described in detail. Because those functions behave identically on all standard-compliant systems, they are described in any book covering standard C.
Each entry for a function contains a detailed description
- Function
Summary of what function does.
- Header
The header file that contains the declaration.
- Declaration
Describes the needed header files and declaration of the function.
- Description
Description of the function.
- Notes
Notes on the function.
- Availability
The availability of the function.
- See also
Other related functions.
- Example
A piece of actual code using the function.
2. Functions by header file
2.1. 6502.h
2.2. cc65.h
(incomplete)
2.3. ctype.h
2.4. dirent.h
No callable functions; this header only defines struct dirent and the zero-page FileEntry for the cart's per-file directory entry.
2.5. errno.h
(incomplete)
2.6. fcntl.h
-
No callable functions on this target: the Lynx cart is read-only ROM addressed by number, so
open,creat,closeandwriteare not provided. Use openn for numbered, read-only cart access, thenread/lseek.
2.7. lynx/joystick.h
2.8. lynx/lynx.h
2.9. lynx/lz4.h
2.10. lynx/multicart.h
2.11. peekpoke.h
2.12. lynx/sdcard-gd.h
Driver for the RetroHQ Lynx SD / GD flash cartridge MCU — directory listing, file streaming and cart-ROM programming. See SD / GD flash cart for the protocol and the SD card layout.
2.13. lynx/serial.h
This header file contains definitions for initializing serial
communication, see also testcode/lib/ser-test.c.
2.14. setjmp.h
2.15. stdarg.h
(incomplete)
2.16. stdbool.h
(incomplete)
2.17. stddef.h
2.18. stdio.h
2.19. stdlib.h
(incomplete)
2.20. string.h
2.21. lynx/suzymath.h
Asynchronous (non-blocking) access to the Suzy hardware math unit: start a
multiply, divide or modulo, run unrelated CPU work while Suzy computes, then
harvest the result. These are the start/poll/harvest counterpart of the
!* / !/ / !% operators. See
section 4 for how they work and why they are safe.
2.22. lynx/gfx.h
The static Lynx graphics library: one fixed 160x102x16 display mode, Suzy sprite drawing, pages, palette and bitmap, compact and proportional font text.
The functions are named with the gfx_ prefix (constants GFX_). The former tgi_/TGI_ names are still available as deprecated aliases by including <lynx/tgi.h>; they map one-to-one to the gfx_ names and will be removed in a future release. See the TGI Deprecation section of the migration guide.
2.23. time.h
(incomplete)
2.24. unistd.h
(incomplete)
2.25. lynx/zlib.h
(incomplete)
2.26. lynx/handymusic.h
3. Alphabetical function reference
3.1. _heapadd
- Function
Add a block to the heap.
- Header
- Declaration
void __fastcall__ _heapadd (void* mem, size_t size);- Description
The function adds a block of raw memory to the heap.
- Notes
The minimum blocksize that can be added is 6 bytes; the function will ignore smaller blocks.
The function is available only as a fastcall function; so, it may be used only in the presence of a prototype.
- Availability
cc65
- See also
_heapblocksize, _heapmaxavail, _heapmemavail, calloc, free, malloc, realloc
- Example
None.
3.2. _heapblocksize
- Function
Return the size of an allocated block.
- Header
- Declaration
size_t __fastcall__ _heapblocksize (const void* block);- Description
The function returns the size of a block that must have previously been allocated by
malloc,callocorrealloc.- Notes
Passing a pointer to a block that was is not the result of one of the allocation functions, or that has been free'd will give unpredicable results.
The function is available only as a fastcall function; so, it may be used only in the presence of a prototype.
- Availability
cc65
- See also
_heapadd, _heapmaxavail, _heapmemavail, calloc, free, malloc, realloc
- Example
None.
3.3. _heapmaxavail
- Function
Return the largest block that is available on the heap.
- Header
- Declaration
size_t _heapmaxavail (void);- Description
The function returns the size of the largest block that may be allocated from the heap using
malloc.- Availability
cc65
- See also
_heapadd, _heapblocksize, _heapmemavail, calloc, free, malloc, realloc
- Example
None.
3.4. _heapmemavail
- Function
Return the total available space on the heap.
- Header
- Declaration
size_t _heapmemavail (void);- Description
The function returns the total number of bytes available on the heap.
- Notes
This function is of less use than usually assumed, since the returned heap space may be available but not in one block. So even if this function says that several times more heap space is available than needed, malloc may still return
NULL.- Availability
cc65
- See also
_heapadd, _heapblocksize, _heapmaxavail, calloc, free, malloc, realloc
- Example
None.
3.5. _randomize
- Function
Initialize the pseudo random number generator.
- Header
- Declaration
void _randomize (void);- Description
The function initializes the random number generator with a seed derived from fast changing hardware events, so the seed itself can be considered random to a certain degree.
- Notes
The randomness of the seed depends on the machine hardware.
- Availability
cc65
- See also
- Example
None.
3.6. _swap
- Function
Swap the contents of memory areas.
- Header
- Declaration
void __fastcall__ _swap (void* p, void* q, size_t size);- Description
_swapwill swap (exchange) the contents of the two memory areas pointed to bypandq. Both memory areas are assumed to besizebytes in size.- Notes
The memory areas may not overlap, otherwise the results are undefined.
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65
- See also
- Example
None.
3.7. _sys
- Function
Call a subroutine passing register values.
- Header
- Declaration
void __fastcall__ _sys (struct regs* r);- Description
The function will call the subroutine at the address specified in the
pcmember of the passedregsstructure. All registers and the CPU flags are set to the values given in theregsstructure. On return from the subroutine, the new values of the registers and flags are stored back overwriting the old values.- Notes
Bits 4 and 5 of the flags value in the
regsstructure are ignored when calling the subroutine (they are unchanged from their current values).The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65
- Example
None.
3.8. BRK
- Function
Insert a 6502 BRK instrunction into the code.
- Header
- Declaration
void BRK (void);- Description
The function will insert a 6502 BRK instruction into the code which may be used to trigger a debugger.
- Notes
The function is actually a macro.
The inserted instruction may lead to unexpected results if no debugger is present.
- Availability
cc65
- See also
- Example
None.
3.9. CLI
- Function
Insert a 6502 CLI instrunction into the code.
- Header
- Declaration
void CLI (void);- Description
The function will insert a 6502 CLI instruction into the code, so interrupts are enabled. Enabling interrupts has no effects if they are already enabled (the default).
- Notes
The function is actually a macro.
Disabling interrupts may lead to unexpected results.
- Availability
cc65
- See also
- Example
None.
3.10. PEEK
- Function
Read a byte from memory.
- Header
- Declaration
unsigned char PEEK (unsigned addr);- Description
The function will read the absolute memory given by
addrand return the value read.- Notes
The function is actually a macro.
This function depends highly on the platform and environment.
- Availability
cc65
- See also
- Example
None.
3.11. PEEKW
- Function
Read a word (two bytes) from memory.
- Header
- Declaration
unsigned PEEKW (unsigned addr);- Description
The function will read the absolute memory given by
addrand return the value read. The byte read from the higher address is the high byte of the return value.- Notes
The function is actually a macro.
This function depends highly on the platform and environment.
The order in which the two bytes are read is unspecified and may depend of the address expression used.
- Availability
cc65
- See also
- Example
None.
3.12. POKE
- Function
Write a byte to memory.
- Header
- Declaration
void POKE (unsigned addr, unsigned char val);- Description
The function writes the value
valto the absolute memory address given byaddr.- Notes
The function is actually a macro.
This function depends highly on the platform and environment.
Careless use will cause the program to act strange or may crash the machine.
- Availability
cc65
- See also
- Example
None.
3.13. POKEW
- Function
Write a word (two bytes) to memory.
- Header
- Declaration
void POKEW (unsigned addr, unsigned val);- Description
The function writes the value
valto the absolute memory address given byaddr. The low byte ofvalis written to theaddr, the high byte is written toaddr+1.- Notes
The function is actually a macro.
This function depends highly on the platform and environment.
Careless use will cause the program to act strange or may crash the machine.
The order in which the two bytes are written is unspecified and may depend of the address expression used.
- Availability
cc65
- See also
- Example
None.
3.14. SEI
- Function
Insert a 6502 SEI instrunction into the code.
- Header
- Declaration
void SEI (void);- Description
The function will insert a 6502 SEI instruction into the code, so interrupts are disabled. Note that non maskable interrupts cannot be disabled.
- Notes
The function is actually a macro.
Disabling interrupts may lead to unexpected results.
- Availability
cc65
- See also
- Example
None.
3.15. abs
- Function
Returns the absolute value of an integer.
- Header
- Declaration
int __fastcall__ abs (int v);- Description
absreturns the absolute value of the argument passed to the function.- Notes
The return value is undefined if
INT_MINis passed to the function.The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
ISO 9899
- See also
- Example
None.
3.16. atoi
- Function
Convert a string to an integer.
- Header
- Declaration
int __fastcall__ atoi (const char* s);- Description
atoiconverts the given string into an integer. Conversion stops as soon as any invalid character is encountered.- Notes
There is no way to detect any conversion errors.
The function does not check for an numerical overflow when converting.
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
ISO 9899
- See also
- Example
None.
3.17. atol
- Function
Convert a string to a long integer.
- Header
- Declaration
long __fastcall__ atol (const char* s);- Description
atolconverts the given string into a long integer. Conversion stops as soon as any invalid character is encountered.- Notes
There is no way to detect any conversion errors.
The function does not check for an numerical overflow when converting.
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
ISO 9899
- See also
- Example
None.
3.18. bsearch
- Function
Do a binary search in a sorted array.
- Header
- Declaration
void* __fastcall__ bsearch (const void* key, const void* base, size_t n, size_t size, int __fastcall__ (* cmp) (const void*, const void*));- Description
bsearchsearches a sorted array for a member that matches the one pointed to bykey.baseis the address of the array,nis the number of elements,sizethe size of an element andcmpthe function used to compare the members against the key. The function returns a pointer to the member found, orNULLif there was no match.- Notes
The contents of the array must be sorted in ascending order according to the compare function given.
If there are multiple members that match the key, the function will return one of the members.
The function is only available as fastcall function, so it may only be used in presence of a prototype.
The function to which
cmppoints must have thefastcallcalling convention.- Availability
ISO 9899
- See also
- Example
None.
3.19. bzero
- Function
Fill a memory area with zeroes.
- Header
- Declaration
void __fastcall__ bzero (void* p, size_t count);- Description
bzerofills the memory area pointed to bypwith zero.- Notes
You should use
memsetinstead.The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65
- See also
- Example
None.
3.20. calloc
- Function
Allocate and clear memory.
- Header
- Declaration
void* __fastcall__ calloc (size_t n, size_t size);- Description
callocallocates memory for an array ofnelements of sizesize, clears the whole block with binary zeroes and returns a pointer to it. On error (not enough memory available),callocreturnsNULL.- Notes
Clearing the memory may not have the expected effect on all platforms: pointers in the block may not be
NULLand floating point variables may not be zero (0.0). In other words: The "clearing" effect of this function should be used with care for portable programs.The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
ISO 9899
- See also
_heapadd, _heapblocksize, _heapmaxavail, _heapmemavail, free, malloc, realloc
- Example
None.
3.21. clock
- Function
Determine the processor time used.
- Header
- Declaration
clock_t clock (void);- Description
The
clockfunction returns an approximaton of processor time used by the program. The time is returned in implementation-defined units. It can be converted to seconds by dividing by the value of the macroCLOCKS_PER_SEC.- Notes
Since the machines that cc65-generated programs run on cannot run multiple processes, the function actually will return the time since some implementation-defined point in the past.
The Jiffy clock must be "running", in order for this function to return changing values.
- Availability
ISO 9899
- See also
- Example
None.
3.22. decompress_lz4
- Function
Uncompress a LZ4-compressed buffer.
- Header
- Declaration
void decompress_lz4 (const unsigned char* src, unsigned char* const dst, const unsigned short uncompressed_size);- Description
decompress_lz4uncompresses a LZ4-compressed buffer.- Notes
Use LZ4_compress_HC with compression level 16 for best compression.
- Availability
cc65
- Example
None.
3.23. div
- Function
Divide two ints and return quotient and remainder.
- Header
- Declaration
div_t __fastcall__ div (int numer, int denom);- Description
divdividesnumerbydenomand returns the quotient and remainder in adiv_tstructure.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
ISO 9899
- See also
ldiv
- Example
None.
3.24. eeprom_93c46_read
- Function
Read a word from a 93C46 EEPROM.
- Header
- Declaration
unsigned __fastcall__ eeprom_93c46_read (unsigned char cell);- Description
Reads and returns the 16-bit word at
cell(0–63) from a 93C46 part (64 words).- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
Part of the size-selectable EEPROM family; pick the variant that matches the chip fitted to the cart (93C46 = 64 words, 93C66 = 256, 93C86 = 1024). To clear a word, write the value you want; there is no separate erase call. The former
lynx_ee*names (e.g.lynx_eeread_93c46) remain as deprecated aliases for backward compatibility.- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.25. eeprom_93c46_write
- Function
Write a word to a 93C46 EEPROM.
- Header
- Declaration
void __fastcall__ eeprom_93c46_write (unsigned addr, unsigned val);- Description
Writes the 16-bit
valataddr(0–63) of a 93C46 part and waits for the write to complete.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
Part of the size-selectable EEPROM family; pick the variant that matches the chip fitted to the cart (93C46 = 64 words, 93C66 = 256, 93C86 = 1024). To clear a word, write the value you want; there is no separate erase call. The former
lynx_ee*names (e.g.lynx_eeread_93c46) remain as deprecated aliases for backward compatibility.- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.26. eeprom_93c66_read
- Function
Read a word from a 93C66 EEPROM.
- Header
- Declaration
unsigned __fastcall__ eeprom_93c66_read (unsigned addr);- Description
Reads and returns the 16-bit word at
addr(0–255) from a 93C66 part (256 words).- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
Part of the size-selectable EEPROM family; pick the variant that matches the chip fitted to the cart (93C46 = 64 words, 93C66 = 256, 93C86 = 1024). To clear a word, write the value you want; there is no separate erase call. The former
lynx_ee*names (e.g.lynx_eeread_93c46) remain as deprecated aliases for backward compatibility.- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.27. eeprom_93c66_write
- Function
Write a word to a 93C66 EEPROM.
- Header
- Declaration
void __fastcall__ eeprom_93c66_write (unsigned addr, unsigned val);- Description
Writes the 16-bit
valataddr(0–255) of a 93C66 part and waits for the write to complete.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
Part of the size-selectable EEPROM family; pick the variant that matches the chip fitted to the cart (93C46 = 64 words, 93C66 = 256, 93C86 = 1024). To clear a word, write the value you want; there is no separate erase call. The former
lynx_ee*names (e.g.lynx_eeread_93c46) remain as deprecated aliases for backward compatibility.- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.28. eeprom_93c86_read
- Function
Read a word from a 93C86 EEPROM.
- Header
- Declaration
unsigned __fastcall__ eeprom_93c86_read (unsigned addr);- Description
Reads and returns the 16-bit word at
addr(0–1023) from a 93C86 part (1024 words).- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
Part of the size-selectable EEPROM family; pick the variant that matches the chip fitted to the cart (93C46 = 64 words, 93C66 = 256, 93C86 = 1024). To clear a word, write the value you want; there is no separate erase call. The former
lynx_ee*names (e.g.lynx_eeread_93c46) remain as deprecated aliases for backward compatibility.- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.29. eeprom_93c86_write
- Function
Write a word to a 93C86 EEPROM.
- Header
- Declaration
void __fastcall__ eeprom_93c86_write (unsigned addr, unsigned val);- Description
Writes the 16-bit
valataddr(0–1023) of a 93C86 part and waits for the write to complete.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
Part of the size-selectable EEPROM family; pick the variant that matches the chip fitted to the cart (93C46 = 64 words, 93C66 = 256, 93C86 = 1024). To clear a word, write the value you want; there is no separate erase call. The former
lynx_ee*names (e.g.lynx_eeread_93c46) remain as deprecated aliases for backward compatibility.- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.30. free
- Function
Free a block of dynamic memory.
- Header
- Declaration
void __fastcall__ free (void* block);- Description
Free a block of dynamic memory previously allocated with
malloc,callocorrealloc. As an exception, if the passed pointer isNULL, no action is performed.- Notes
Passing an already free'd block to
freeagain will cause undefined behaviour and may crash your program.The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
ISO 9899
- See also
_heapadd, _heapblocksize, _heapmaxavail, _heapmemavail, calloc, malloc, realloc
- Example
None.
3.31. gfx_busy
- Function
Test whether a requested page swap is still pending.
- Header
- Declaration
unsigned char gfx_busy (void);- Description
Returns nonzero while a swap requested by
gfx_updatedisplayhas not yet been carried out by the VBL interrupt, and zero once it has. It reports the pending swap request only, not sprite-engine activity: all drawing throughgfx_spriteis synchronous and has already finished when the call returns.- Availability
cc65 (Lynx)
- See also
3.32. gfx_clear
- Function
Clear the draw page.
- Header
- Declaration
void gfx_clear (void);- Description
Clears the whole draw page to the current drawing color set with
gfx_setcolor. Becausegfx_initselects black (pen 0),gfx_initfollowed bygfx_clearyields a black screen.- Notes
The old loadable driver always cleared with pen 0 regardless of the drawing color; this version honours the current color.
When collision detection is enabled the matching rows of the collision buffer are erased as well.
- Availability
cc65 (Lynx)
- See also
3.33. gfx_clearrows
- Function
Clear a band of rows of the draw page.
- Header
- Declaration
void __fastcall__ gfx_clearrows (unsigned char first, unsigned char count);- Description
Clears rows
[first, first+count)of the draw page to the current drawing color. Bands that reach below the bottom of the screen are clipped, and acountof 0 is a no-op.- Notes
When collision detection is enabled the corresponding rows of the collision buffer are erased as well.
The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.34. gfx_flip
- Function
Rotate the display by 180 degrees.
- Header
- Declaration
void gfx_flip (void);- Description
Switches the hardware into left-handed mode, rotating the displayed image by 180 degrees. This is not a page flip; for double buffering see
gfx_updatedisplay.- Availability
cc65 (Lynx)
- See also
3.35. gfx_getcolor
- Function
Return the current drawing pen.
- Header
- Declaration
unsigned char gfx_getcolor (void);- Description
Returns the drawing pen (0-15) last set with
gfx_setcolor.- Availability
cc65 (Lynx)
- See also
3.36. gfx_getcolorcount
- Function
Return the number of available colors.
- Header
- Declaration
unsigned char gfx_getcolorcount (void);- Description
Returns the number of colors of the one and only display mode, which is always 16 (
GFX_COLORCOUNT).- Notes
Implemented as a zero-cost macro in
lynx/gfx.h; it expands to a compile-time constant and generates no code.- Availability
cc65 (Lynx)
- See also
3.37. gfx_getdefpalette
- Function
Return the default palette.
- Header
- Declaration
const unsigned char* gfx_getdefpalette (void);- Description
Returns a pointer to the default 32-byte palette (16 green bytes followed by 16 blue/red bytes) that
gfx_setdefpaletteinstalls.- Availability
cc65 (Lynx)
- See also
3.38. gfx_getmaxcolor
- Function
Return the highest color number.
- Header
- Declaration
unsigned char gfx_getmaxcolor (void);- Description
Returns the highest valid pen number, which is always 15 (
GFX_COLORCOUNT - 1).- Notes
Implemented as a zero-cost macro in
lynx/gfx.h; it expands to a compile-time constant and generates no code.- Availability
cc65 (Lynx)
- See also
3.39. gfx_getmaxx
- Function
Return the highest X coordinate.
- Header
- Declaration
unsigned gfx_getmaxx (void);- Description
Returns the highest valid X coordinate, which is always 159 (
GFX_XRES - 1).- Notes
Implemented as a zero-cost macro in
lynx/gfx.h; it expands to a compile-time constant and generates no code.- Availability
cc65 (Lynx)
- See also
3.40. gfx_getmaxy
- Function
Return the highest Y coordinate.
- Header
- Declaration
unsigned gfx_getmaxy (void);- Description
Returns the highest valid Y coordinate, which is always 101 (
GFX_YRES - 1).- Notes
Implemented as a zero-cost macro in
lynx/gfx.h; it expands to a compile-time constant and generates no code.- Availability
cc65 (Lynx)
- See also
3.41. gfx_getpagecount
- Function
Return the number of screen pages.
- Header
- Declaration
unsigned char gfx_getpagecount (void);- Description
Returns the number of available screen pages, which is always 2 (
GFX_PAGECOUNT).- Notes
Implemented as a zero-cost macro in
lynx/gfx.h; it expands to a compile-time constant and generates no code.- Availability
cc65 (Lynx)
- See also
3.42. gfx_getpalette
- Function
Return the current palette.
- Header
- Declaration
const unsigned char* gfx_getpalette (void);- Description
Returns a pointer to the current 32-byte palette read back from the hardware.
- Availability
cc65 (Lynx)
- See also
3.43. gfx_gettextheight
- Function
Return the height of a text string in pixels.
- Header
- Declaration
unsigned __fastcall__ gfx_gettextheight (const char* s);- Description
Returns the height in pixels that the string
swould occupy if drawn at the current text scale set withgfx_settextscale.- Notes
The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.44. gfx_gettextwidth
- Function
Return the width of a text string in pixels.
- Header
- Declaration
unsigned __fastcall__ gfx_gettextwidth (const char* s);- Description
Returns the width in pixels that the string
swould occupy if drawn at the current text scale set withgfx_settextscale.- Notes
For the fixed-pitch fonts (
GFX_FONT_BITMAP,GFX_FONT_COMPACT) the width isstrlen×pitchscaled; for the proportional font (GFX_FONT_VARIABLE) it is the sum of each glyph’s advance, so it matches the spacinggfx_outtextactually draws. As with drawing, at most 20 characters are measured.The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.45. gfx_getxres
- Function
Return the X resolution of the screen.
- Header
- Declaration
unsigned gfx_getxres (void);- Description
Returns the horizontal resolution in pixels, which is always 160 (
GFX_XRES).- Notes
Implemented as a zero-cost macro in
lynx/gfx.h; it expands to a compile-time constant and generates no code.- Availability
cc65 (Lynx)
- See also
3.46. gfx_getyres
- Function
Return the Y resolution of the screen.
- Header
- Declaration
unsigned gfx_getyres (void);- Description
Returns the vertical resolution in pixels, which is always 102 (
GFX_YRES).- Notes
Implemented as a zero-cost macro in
lynx/gfx.h; it expands to a compile-time constant and generates no code.- Availability
cc65 (Lynx)
- See also
3.47. gfx_gotoxy
- Function
Set the text output cursor.
- Header
- Declaration
void __fastcall__ gfx_gotoxy (int x, int y);- Description
Moves the text cursor used by
gfx_outtextto(x, y).- Notes
The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.48. gfx_init
- Function
Initialize the graphics system.
- Header
- Declaration
void gfx_init (void);- Description
Initializes graphics: it enables the VBL timer interrupt, sets up the collision buffer, resets the display (4bpp, unflipped, page 0 both viewed and drawn), clears the hardware palette to black and selects black (pen 0) as the drawing color, so
gfx_initfollowed bygfx_clearyields a black screen. The hardware is fixed, so this cannot fail.- Notes
The old loadable driver defaulted to white; code that drew after init without an explicit
gfx_setcolormust now set its color first.
gfx_initno longer loads the default palette — it clears every pen to black. Callgfx_setdefpaletteafter it for the built-in 16-colour default, orgfx_setpalettefor your own.- Availability
cc65 (Lynx)
- See also
3.49. gfx_outtext
- Function
Output text at the current cursor position.
- Header
- Declaration
void __fastcall__ gfx_outtext (const char* s);- Description
Draws the string
sat the current text cursor and advances the cursor to the end of the text. At most 20 characters are drawn per call.- Notes
The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.50. gfx_outtextxy
- Function
Output text at a given position.
- Header
- Declaration
void __fastcall__ gfx_outtextxy (int x, int y, const char* s);- Description
Moves the text cursor to
(x, y)and draws the stringsthere; seegfx_outtextfor the 20-character limit and cursor behaviour.- Notes
The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.51. gfx_setbgcolor
- Function
Set the text background pen.
- Header
- Declaration
void __fastcall__ gfx_setbgcolor (unsigned char color);- Description
Sets the background pen (0-15) used behind text drawn by
gfx_outtext.- Notes
The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.52. gfx_setbpp
- Function
Select the display color depth.
- Header
- Declaration
void __fastcall__ gfx_setbpp (unsigned char bpp);- Description
Selects the display depth: 4 (the default) or 2 bits per pixel. 2bpp is a CPU-rendered framebuffer mode in which Mikey scans out 40 bytes per line (4080 bytes per page, leaving the upper 4080 bytes of each page free).
- Notes
The sprite engine always renders 4bpp, so
gfx_spriteandgfx_outtextdisplay garbled in 2bpp.gfx_clearstays valid only for colors 0, 5, 10 and 15, which map to the 2bpp pens 0-3.The mode relies on a
DISPCTLbit outside the documented guarantees and is unverified on real hardware.The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.53. gfx_setcollisiondetection
- Function
Enable or disable sprite collision detection.
- Header
- Declaration
void __fastcall__ gfx_setcollisiondetection (unsigned char active);- Description
Enables (nonzero) or disables (zero) Suzy's sprite collision detection. It is off by default. While enabled,
gfx_clearandgfx_clearrowsalso erase the corresponding rows of the collision buffer. A program that uses it must link withlynx-coll.cfgto reserve the buffer; see Collision detection for the full mechanism and a worked example.- Notes
The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.54. gfx_setcolor
- Function
Set the drawing pen.
- Header
- Declaration
void __fastcall__ gfx_setcolor (unsigned char color);- Description
Sets the drawing pen (0-15) used by
gfx_clear,gfx_clearrowsand the compact font.- Notes
The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.55. gfx_setdefpalette
- Function
Load the built-in default palette.
- Header
- Declaration
void gfx_setdefpalette (void);- Description
Installs the built-in default palette — the 16 pens named by the
COLOR_*constants — into the hardware palette.gfx_initclears the palette to black, so callgfx_setdefpaletteafter it to obtain the historical default colours. The default palette table is only linked into programs that call this (orgfx_getdefpalette).- Availability
cc65 (Lynx)
- See also
3.56. gfx_setdrawpage
- Function
Select the page drawn into.
- Header
- Declaration
void __fastcall__ gfx_setdrawpage (unsigned char page);- Description
Selects the page (0 or 1) that drawing operations render into.
- Notes
The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.57. gfx_setfont
- Function
Select the active text font.
- Header
- Declaration
void __fastcall__ gfx_setfont (unsigned char font);- Description
Selects the active text font, one of the
GFX_FONT_XXXconstants.GFX_FONT_BITMAPis the system 8x8 font (the default);GFX_FONT_COMPACTis the 5x5 font with a transparent background, drawn in the current pen at a 6-pixel pitch;GFX_FONT_VARIABLEis the proportional all-caps font (transparent background, current pen) whose glyphs are 1–5 px wide with a 1-px gap, so each character advances by its own width andgfx_gettextwidthsums per-glyph advances instead ofstrlen×pitch.- Notes
Linking
gfx_setfontpulls in the compact and proportional fonts; programs that stay with the 8x8 font need not call it.The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.58. gfx_setframerate
- Function
Set the display refresh rate.
- Header
- Declaration
unsigned char __fastcall__ gfx_setframerate (unsigned char rate);- Description
Sets the display refresh rate to 50, 60 or 75 (Hz). Returns 0 on success and nonzero for an invalid rate.
- Notes
The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.59. gfx_setpalette
- Function
Set the palette.
- Header
- Declaration
void __fastcall__ gfx_setpalette (const unsigned char* palette);- Description
Installs a new palette of 32 bytes: 16 green bytes followed by 16 blue/red bytes.
- Notes
The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
gfx_getpalette, gfx_setpalette16, gfx_setdefpalette, gfx_getdefpalette
3.60. gfx_setpalette16
- Function
Set the palette from the condensed 16-entry array.
- Header
- Declaration
void __fastcall__ gfx_setpalette16 (const unsigned short* palette);- Description
Installs a new palette from the condensed form: 16 entries, one
unsigned shortper pen, each a packed 12-bit colour of the form0x0GBR(green nibble in bits 8–11, blue in bits 4–7, red in bits 0–3). Each entry is split into the twoGCOLMAPhalves as it loads, so this installs the same colours asgfx_setpalettedoes from the 32-byte array. The palette generator emits both arrays.- Notes
The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.61. gfx_settextdir
- Function
Set the text output direction.
- Header
- Declaration
void __fastcall__ gfx_settextdir (unsigned char dir);- Description
Sets the direction in which the text cursor advances between
gfx_outtextcalls, one of theGFX_TEXT_XXXconstants. It affects only how the cursor advances; the glyphs themselves are not rotated.GFX_TEXT_HORIZONTALadvances the cursor right by the string width;GFX_TEXT_VERTICALadvances it down by one text line (the scaled font height), so successive calls stack top to bottom.- Notes
The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.62. gfx_settextscale
- Function
Set the text scaling.
- Header
- Declaration
void __fastcall__ gfx_settextscale (unsigned width, unsigned height);- Description
Sets the text scaling factors. They are 8.8 fixed point (
$100= 1.0) and fully fractional: Suzy scales the text sprite natively in 8.8.- Notes
The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.63. gfx_settextstyle
- Function
Set text scaling and direction.
- Header
- Declaration
void __fastcall__ gfx_settextstyle (unsigned width, unsigned height, unsigned char dir, unsigned char font);- Description
Sets the scaling and direction for text output in a single call. The
fontargument is ignored; usegfx_setfontto choose a font.- Notes
The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.64. gfx_setviewpage
- Function
Select the visible page.
- Header
- Declaration
void __fastcall__ gfx_setviewpage (unsigned char page);- Description
Selects the visible page (0 or 1). This is best done during vertical blank; see
gfx_updatedisplay.- Notes
The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.65. gfx_sprite
- Function
Draw a sprite control block.
- Header
- Declaration
void __fastcall__ gfx_sprite (const void* sprite);- Description
Draws a sprite control block (or SCB chain) into the draw page and returns after the sprite engine has finished (synchronous).
- Notes
An SCB pen-index palette of 8 bytes must not begin at address
$xxFA— a hardware bug loses its last 2 bytes (pens C-F keep stale values). Align or pad the SCB.Do not interleave raw game-cart strobes with sprite calls: after a cart write, Suzy must not be accessed for 12 ticks.
The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.66. gfx_updatedisplay
- Function
Request a page swap at the next VBL.
- Header
- Declaration
void gfx_updatedisplay (void);- Description
Requests that the draw page and the view page be swapped at the next VBL interrupt. Poll
gfx_busyto learn when the swap has happened.- Availability
cc65 (Lynx)
- See also
3.67. handymusic_init
- Function
Initialize the HandyMusic engine and audio hardware.
- Header
- Declaration
void handymusic_init (void);- Description
Enables stereo output, leaves all four channels idle, and turns the engine on. Call once, after the VBL interrupt is running (for example after
gfx_initandCLI()), before any play call. HandyMusic installs its own per-frame update on the VBL interrupt chain, so the game never calls the update routine itself.- Availability
cc65 (Lynx)
- See also
3.68. handymusic_pause
- Function
Pause HandyMusic and mute all channels.
- Header
- Declaration
void handymusic_pause (void);- Description
Backs up and silences every channel. Double-call safe (pausing an already-paused engine does nothing). Resume with
handymusic_unpause.- Availability
cc65 (Lynx)
- See also
3.69. handymusic_pcm_playing
- Function
Report whether a PCM sample is currently playing.
- Header
- Declaration
unsigned char handymusic_pcm_playing (void);- Description
Returns nonzero while a PCM sample is streaming out channel 0, and zero once playback has finished and channel 0 has been handed back to the music engine. Useful for waiting on a one-shot or gating a follow-up sample.
- Availability
cc65 (Lynx)
- See also
3.70. handymusic_play_music
- Function
Start the song resident in the reserved music region.
- Header
- Declaration
void handymusic_play_music (void);- Description
Plays the song whose compiled blob has been copied to
__HMMUS_START__(see HandyMusic §3). Stop the current song withhandymusic_stop_musicbefore loading and playing another.- Availability
cc65 (Lynx)
- See also
3.71. handymusic_play_pcm
- Function
Play an 8 kHz PCM sample from a RAM buffer.
- Header
- Declaration
void __fastcall__ handymusic_play_pcm (const unsigned char* buf, unsigned int len);- Description
Streams the
len-byte signed 8-bit sample atbufstraight away, out channel 0, driven by a timer-3 8 kHz interrupt (see HandyMusic §4). The sample borrows channel 0 from the music engine and returns it automatically when finished; a new call pre-empts any sample still playing.bufmust stay resident until playback ends. No-op if PCM is muted (handymusic_disable_pcm) orlenis zero.- Availability
cc65 (Lynx)
- See also
3.72. handymusic_play_sfx
- Function
Queue a sound effect to start on the next frame.
- Header
- Declaration
void __fastcall__ handymusic_play_sfx (unsigned char n);- Description
nis anSFX_*index from the hmcc-generated.equfile. The effect is slotted into a channel by priority next frame; a higher-priority request wins a busy channel. Point the driver at the SFX tables (handymusic_set_sfx_tables) before the first call.- Availability
cc65 (Lynx)
- See also
3.73. handymusic_register_pcm
- Function
Register a PCM sample so the music “play sample” command can trigger it.
- Header
- Declaration
void __fastcall__ handymusic_register_pcm (unsigned char num, const unsigned char* buf, unsigned int len);- Description
Records the
len-byte sample atbufin slotnum(0..7) of the PCM sample registry. The song’s “play sample” command then streams the slot by number. Call before the song references the slot;bufmust stay resident. A slot left unregistered plays nothing.- Availability
cc65 (Lynx)
- See also
3.74. handymusic_stop_all
- Function
Stop every music track and sound effect.
- Header
- Declaration
void handymusic_stop_all (void);- Description
Force-frees all four channels, so nothing is left ringing. Use this for a hard stop;
handymusic_stop_musiconly frees channels the music still controls.- Availability
cc65 (Lynx)
- See also
3.75. handymusic_stop_music
- Function
Stop the current song.
- Header
- Declaration
void handymusic_stop_music (void);- Description
Stops music decoding and frees the channels the song still controls. A note whose priority no longer matches its track is left to ring out; call
handymusic_stop_allfor a full stop.- Availability
cc65 (Lynx)
- See also
3.76. handymusic_stop_sfx
- Function
Stop the first sound whose priority matches.
- Header
- Declaration
void __fastcall__ handymusic_stop_sfx (unsigned char prio);- Description
Finds the first channel whose priority equals
prio— a sound effect or even a note — and disables it. Use distinct priority bands for notes and effects to keep this useful.- Availability
cc65 (Lynx)
- See also
3.77. handymusic_unpause
- Function
Resume HandyMusic after a pause.
- Header
- Declaration
void handymusic_unpause (void);- Description
Restores every channel muted by
handymusic_pause. Double-call safe.- Availability
cc65 (Lynx)
- See also
3.78. isalnum
- Function
Check if a given character is a letter or digit.
- Header
- Declaration
int __fastcall__ isalnum (int c);- Description
The function returns a non zero value if the given argument is a letter or digit. The return value is zero if the character is anything else.
- Notes
When compiling without
-Os, the function is only available as fastcall function, so it may only be used in presence of a prototype.- Availability
ISO 9899
- See also
isalpha, isascii, isblank, isdigit, isgraph, islower, isprint, ispunct, isspace, isupper, isxdigit
- Example
None.
3.79. isalpha
- Function
Check if a given character is a letter.
- Header
- Declaration
int __fastcall__ isalpha (int c);- Description
The function returns a non zero value if the given argument is a letter. The return value is zero if the character is anything else.
- Notes
When compiling without
-Os, the function is only available as fastcall function, so it may only be used in presence of a prototype.- Availability
ISO 9899
- See also
isalnum, isascii, isblank, isdigit, isgraph, islower, isprint, ispunct, isspace, isupper, isxdigit
- Example
None.
3.80. isascii
- Function
Check if a given character is in the ASCII (0..127) range.
- Header
- Declaration
int __fastcall__ isascii (int c);- Description
The function returns a non zero value if the given argument is in the range 0..127 (the range of valid ASCII characters), and zero if not.
- Notes
When compiling without
-Os, the function is only available as fastcall function, so it may only be used in presence of a prototype.- Availability
ISO 9899
- See also
isalnum, isalpha, isblank, isdigit, isgraph, islower, isprint, ispunct, isspace, isupper, isxdigit
- Example
None.
3.81. isblank
- Function
Check if a given character is a space or tab.
- Header
- Declaration
int __fastcall__ isblank (int c);- Description
The function returns a non zero value if the given argument is a space or tab character. The return value is zero if the character is anything else.
- Notes
When compiling without
-Os, the function is only available as fastcall function, so it may only be used in presence of a prototype.- Availability
ISO 9899
- See also
isalnum, isalpha, isascii, isdigit, isgraph, islower, isprint, ispunct, isspace, isupper, isxdigit
- Example
None.
3.82. isdigit
- Function
Check if a given character is a digit.
- Header
- Declaration
int __fastcall__ isdigit (int c);- Description
The function returns a non zero value if the given argument is a digit. The return value is zero if the character is anything else.
- Notes
When compiling without
-Os, the function is only available as fastcall function, so it may only be used in presence of a prototype.- Availability
ISO 9899
- See also
isalnum, isalpha, isascii, isblank, isgraph, islower, isprint, ispunct, isspace, isupper, isxdigit
- Example
None.
3.83. isgraph
- Function
Check if a given character is a printable character (except space).
- Header
- Declaration
int __fastcall__ isgraph (int c);- Description
The function returns a non zero value if the given argument is a printable character with the exception of space. The return value is zero if the character is anything else.
- Notes
When compiling without
-Os, the function is only available as fastcall function, so it may only be used in presence of a prototype.- Availability
ISO 9899
- See also
isalnum, isalpha, isascii, isblank, isdigit, islower, isprint, ispunct, isspace, isupper, isxdigit
- Example
None.
3.84. islower
- Function
Check if a given character is a lower case letter.
- Header
- Declaration
int __fastcall__ islower (int c);- Description
The function returns a non zero value if the given argument is a lower case letter. The return value is zero if the character is anything else.
- Notes
When compiling without
-Os, the function is only available as fastcall function, so it may only be used in presence of a prototype.- Availability
ISO 9899
- See also
isalnum, isalpha, isascii, isblank, isdigit, isgraph, isprint, ispunct, isspace, isupper, isxdigit
- Example
None.
3.85. isprint
- Function
Check if a given character is a printable character.
- Header
- Declaration
int __fastcall__ isprint (int c);- Description
The function returns a non zero value if the given argument is a printable character (this includes the space character). The return value is zero if the character is anything else.
- Notes
When compiling without
-Os, the function is only available as fastcall function, so it may only be used in presence of a prototype.- Availability
ISO 9899
- See also
isalnum, isalpha, isascii, isblank, isdigit, isgraph, islower, ispunct, isspace, isupper, isxdigit
- Example
None.
3.86. ispunct
- Function
Check if a given character is a printable character but not a space or an alphanumeric character.
- Header
- Declaration
int __fastcall__ ispunct (int c);- Description
The function returns a non zero value if the given argument is a printable character, but not a space or anything alphanumeric. The return value is zero if the character is anything else.
- Notes
When compiling without
-Os, the function is only available as fastcall function, so it may only be used in presence of a prototype.- Availability
ISO 9899
- See also
isalnum, isalpha, isascii, isblank, isdigit, isgraph, islower, isprint, isspace, isupper, isxdigit
- Example
None.
3.87. isspace
- Function
Check if a given character is a white-space character.
- Header
- Declaration
int __fastcall__ isspace (int c);- Description
The function returns a non zero value if the given argument is a white space character. The return value is zero if the character is anything else. The standard white space characters are: space, formfeed ('\f'), newline ('\n'), carriage return ('\r'), horizontal tab ('\t'), and vertical tab ('\v').
- Notes
When compiling without
-Os, the function is only available as fastcall function, so it may only be used in presence of a prototype.- Availability
ISO 9899
- See also
isalnum, isalpha, isascii, isblank, isdigit, isgraph, islower, isprint, ispunct, isupper, isxdigit
- Example
None.
3.88. isupper
- Function
Check if a given character is an upper case letter.
- Header
- Declaration
int __fastcall__ isupper (int c);- Description
The function returns a non zero value if the given argument is an upper case letter. The return value is zero if the character is anything else.
- Notes
When compiling without
-Os, the function is only available as fastcall function, so it may only be used in presence of a prototype.- Availability
ISO 9899
- See also
isalnum, isalpha, isascii, isblank, isdigit, isgraph, islower, isprint, ispunct, isspace, isxdigit
- Example
None.
3.89. isxdigit
- Function
Check if a given character is a hexadecimal digit.
- Header
- Declaration
int __fastcall__ isxdigit (int c);- Description
The function returns a non zero value if the given argument is a hexadecimal digit (0..9, a..f and A..F). The return value is zero if the character is anything else.
- Notes
When compiling without
-Os, the function is only available as fastcall function, so it may only be used in presence of a prototype.- Availability
ISO 9899
- See also
isalnum, isalpha, isascii, isblank, isdigit, isgraph, islower, isprint, ispunct, isspace, isupper
- Example
None.
3.90. itoa
- Function
Convert an integer into a string.
- Header
- Declaration
char* __fastcall__ itoa (int val, char* buf, int radix);- Description
itoaconverts the integervalinto a string usingradixas the base.- Notes
There are no provisions to prevent a buffer overflow.
If
valcontainsINT_MIN, the behaviour is undefined.You should probably use sprintf instead.
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65
- See also
- Example
None.
3.91. joy_read
- Function
Read the complete joypad input state.
- Header
- Declaration
unsigned joy_read (void);- Description
Returns all nine Lynx inputs in one call: d-pad, A, B, Opt 1 and Opt 2 in the low byte and Pause in bit 8. It takes no argument (there is exactly one joypad). Examine the result with the
JOY_xxxmasks and macros fromlynx/lynx.h.- Notes
The function takes no argument: the Lynx has exactly one joypad.
- Availability
cc65
- See also
None.
- Example
None.
3.92. labs
- Function
Returns the absolute value of a long integer.
- Header
- Declaration
long __fastcall__ labs (long v);- Description
labsreturns the absolute value of the argument passed to the function.- Notes
The return value is undefined if
LONG_MINis passed to the function.The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
ISO 9899
- See also
- Example
None.
3.93. longjmp
- Function
Non local goto.
- Header
- Declaration
void __fastcall__ longjmp (jmp_buf buf, int retval);- Description
The
longjmpfunction restores a program context from the data inbuf, which must have been set by a preceeding call tosetjmp. Program execution continues as if the call tosetjmphas just returned the valueretval.- Notes
If the parameter
retvalis zero, the function will behave as if it was called with a value of one.The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
ISO 9899
- See also
- Example
None.
3.94. ltoa
- Function
Convert a long integer into a string.
- Header
- Declaration
char* __fastcall__ ltoa (long val, char* buf, int radix);- Description
itoaconverts the long integervalinto a string usingradixas the base.- Notes
There are no provisions to prevent a buffer overflow.
If
valcontainsLONG_MIN, the behaviour is undefined.You should probably use sprintf instead.
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65
- See also
- Example
None.
3.95. lynx_exec
- Function
Load a cartridge file into RAM and run it.
- Header
- Declaration
void __fastcall__ lynx_exec (int fileno);- Description
Loads numbered directory entry
filenolikelynx_load, then jumps to the RAM load address recorded in that entry. Often used by “compilation” carts that chain several small programs.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.96. lynx_load
- Function
Load a cartridge file into RAM.
- Header
- Declaration
void __fastcall__ lynx_load (int fileno);- Description
Opens numbered directory entry
filenowithopennand reads the whole file to the RAM address recorded in its directory entry. The first entry isfileno0.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.97. malloc
- Function
Allocate dynamic memory.
- Header
- Declaration
void* __fastcall__ malloc (size_t size);- Description
mallocallocates size bytes on the heap and returns a pointer to the allocated memory block. On error (not enough memory available),mallocreturnsNULL.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
ISO 9899
- See also
_heapadd, _heapblocksize, _heapmaxavail, _heapmemavail, calloc, free, realloc, strdup
- Example
None.
3.98. memchr
- Function
Search for a character in a block of raw memory.
- Header
- Declaration
void* __fastcall__ strchr (const void* mem, int c, size_t count);- Description
The
memchrfunction locates the first occurrence ofc(converted to a char) in the block of raw memory string pointed to bymemthat is of sizecount. Upon completion, the function returns a pointer to the character found, or a null pointer if the character was not found.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
ISO 9899
- See also
- Example
None.
3.99. memcmp
- Function
Compare two memory areas.
- Header
- Declaration
int __fastcall__ memcmp (const void* p1, const void* p2, size_t count);- Description
memcmpcomparescountbytes from the memory area pointed to byp1into the memory area pointed to byp2. It returns a value that is less than zero ifp1is less thanp2, zero ifp1is the same asp2, and a value greater than zero ifp1is greater thanp2.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
ISO 9899
- See also
- Example
None.
3.100. memcpy
- Function
Copy a memory area.
- Header
- Declaration
void* __fastcall__ memcpy (void* dest, const void* src, size_t count);- Description
memcpycopiescountbytes from the memory area pointed to bysrcinto the memory area pointed to bydest. It returnsdest.- Notes
The result is undefined if the memory areas do overlap. Use
memmoveto copy overlapping memory areas.The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
ISO 9899
- See also
- Example
None.
3.101. memmove
- Function
Copy a memory area.
- Header
- Declaration
void* __fastcall__ memmove (void* dest, const void* src, size_t count);- Description
memmovecopiescountbytes from the memory area pointed to bysrcinto the memory area pointed to bydest. It returnsdest.- Notes
While
memmoveallows the memory areas to overlap, it has some additional overhead compared tomemcpy.The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
ISO 9899
- See also
- Example
None.
3.102. memset
- Function
Fill a memory area.
- Header
- Declaration
void* __fastcall__ memset (void* p, int val, size_t count);- Description
memsetfills the memory area pointed to bypwith the valueval. The function returnsp.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
ISO 9899
- See also
- Example
None.
3.103. mikey_snd_integrate
- Function
Set or clear a Mikey channel's integrate (waveform-shape) bit.
- Header
- Declaration
void __fastcall__ mikey_snd_integrate (unsigned char chan, unsigned char val);- Description
Writes the integrate bit (CONTROL bit 5) of channel
chan(0–3):val0 selects the square wave, non-zero the integrated (smoother) wave. A direct register helper, independent of the stream engine; the other control bits are preserved.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.104. mikey_snd_octave
- Function
Set a Mikey channel's clock-divider (octave) band.
- Header
- Declaration
void __fastcall__ mikey_snd_octave (unsigned char chan, unsigned char val);- Description
Writes the clock-divider bits (CONTROL bits 0–2) of channel
chan(0–3) toval(0–6), selecting the octave band, and sets the timer-enable bits ($18= reload + count) so the channel's poly counter is actually clocked. A direct register helper; integrate (bit 5) and the 9th tap (bit 7) are preserved. The channel still needs a non-zero feedback tap (mikey_snd_taps) to oscillate; with no taps it emits only a DC level, i.e. silence.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.105. mikey_snd_pitch
- Function
Set a Mikey channel's timer reload (pitch within the octave).
- Header
- Declaration
void __fastcall__ mikey_snd_pitch (unsigned char chan, unsigned char val);- Description
Writes the BACKUP (timer reload) register of channel
chan(0–3) toval(0–255). Together withmikey_snd_octavethis fixes the channel's frequency. A direct register helper.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.106. mikey_snd_taps
- Function
Select a Mikey channel's LFSR feedback taps (timbre / noise colour).
- Header
- Declaration
void __fastcall__ mikey_snd_taps (unsigned char chan, unsigned int val);- Description
Programs the 9-bit feedback-tap selection of channel
chan(0–3): the low 8 taps go to the FEEDBACK register and the 9th tap to CONTROL bit 7.valranges 0–511; small tap sets give pure tones, wider sets give buzzy or noisy timbres. A direct register helper.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.107. mikey_snd_volume
- Function
Set a Mikey channel's output volume.
- Header
- Declaration
void __fastcall__ mikey_snd_volume (unsigned char chan, unsigned char val);- Description
Writes the signed VOLUME register of channel
chan(0–3) toval(0–127). A direct register helper, independent of the stream engine; handy for one-call sound effects or hand-built instruments.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.108. multicart_run
- Function
Launch a bundled game ROM from a multicart menu; does not return.
- Header
- Declaration
void __fastcall__ multicart_run (unsigned char romNum);- Description
Launches bundled game ROM number
romNum(0 = the first game in the directory the ROM builder laid down). Masks interrupts, stops the display timers, blanks the palette, copies the relocatable runtime loader to$0040and jumps to it; the loader reads the selected game off the cartridge and runs it over the top of the menu. Because it overwrites the menu it never returns, and must be called only from a program that was itself built and bundled as a multicart menu. See the Multicart reference.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
Does not return: the launched game runs in place of the caller.
- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.109. offsetof
- Function
Calculate the offset of a struct or union member.
- Header
- Declaration
size_t offsetof (type, member);- Description
offsetofcalculates the address offset of astructorunionmember.- Notes
The function is actually a macro.
- Availability
ISO 9899
- Example
None.
3.110. openn
- Function
Open a numbered file on the cartridge.
- Header
- Declaration
void __fastcall__ openn (int fileno);- Description
opennlocates directory entryfilenoon the cart and positions it at that file's first byte, ready forreadandlseek. The cart is read-only ROM and its files are addressed by number — entry 0 is the boot executable, entry 1 the next file appended after it, and so on — so there is no name to parse.opennis the Lynx replacement for the POSIXopen, which is not provided on this target.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
Access is read-only; the cart cannot be written. To copy a whole file into RAM in one step (optionally running it), use
lynx_load/lynx_exec(see the Lynx-specific manual).Only bank 0 of the cart is read.
- Availability
cc65 (Atari Lynx only)
- See also
open
- Example
None.
3.111. poweroff
- Function
Turn the Lynx off in software (soft power-off).
- Header
- Declaration
void poweroff (void);- Description
poweroffclears the power bit (bit 1) of theSYSCTL1register at0xFD87. That bit powers up as1at reset and drives the “soft” on/off input of the Lynx voltage regulator; clearing it makes the regulator disconnect the system from the battery. It is the same mechanism the hardware uses to power a unit off automatically when it has been idle. The function masks interrupts before the store so nothing can run in the instant before power is cut.- Notes
On hardware this call does not return: the machine powers down. Save any persistent state (see the
eeprom_*family) before calling.
SYSCTL1is write-only and its bit 0 is the cartridge address strobe, so the register cannot be read-modify-written;poweroffwrites the whole byte with both bits low.Emulators generally do not model the regulator soft-off, so under emulation the call is effectively a no-op (execution simply stops in a spin loop).
- Availability
cc65 (Atari Lynx only)
- See also
None.
- Example
None.
3.112. qsort
- Function
Sort an array.
- Header
- Declaration
void __fastcall__ qsort (void* base, size_t count, size_t size, int __fastcall__ (* compare) (const void*, const void*));- Description
qsortsorts an array according to a given compare functioncompare.baseis the address of the array,countis the number of elements,sizethe size of an element andcomparethe function used to compare the members.- Notes
If there are multiple members with the same key, the order after calling the function is undefined.
The function is only available as fastcall function, so it may only be used in presence of a prototype.
The function to which
comparepoints must have thefastcallcalling convention.- Availability
ISO 9899
- See also
- Example
None.
3.113. rand
- Function
Return a pseudo random number.
- Header
- Declaration
int rand (void);- Description
The function returns a pseudo random number between 0 and
RAND_MAX(exclusive).- Notes
- Availability
ISO 9899
- See also
- Example
None.
3.114. realloc
- Function
Change the size of an allocated memory block.
- Header
- Declaration
void* __fastcall__ realloc (void* block, size_t size);- Description
reallocchanges the size of the memory block pointed to byblocktosizebytes. IfblockisNULL,reallocbehaves as ifmallochad been called. Ifsizeis zero,reallocbehaves as iffreehad been called. On error (not enough memory available),reallocreturnsNULL.- Notes
The part of the memory block that is returned will have its contents unchanged.
This function is somewhat dangerous to use. Be careful to save the pointer you're passing somewhere else, otherwise
ptr = realloc (ptr, size);will loose your only copy of
ptrifreallocreturnsNULL.The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
ISO 9899
- See also
_heapadd, _heapblocksize, _heapmaxavail, _heapmemavail, calloc, free, realloc
- Example
None.
3.115. reset_irq
- Function
Resets the C level interrupt request vector.
- Header
- Declaration
void reset_irq (void);- Description
reset_irqresets the C level interrupt request vector.- Notes
The interrupt vector is reset on program termination, so it's not strictly necessary to call this function as a part of your clean-up when exiting the program.
- Availability
cc65
- See also
- Example
None.
3.116. sdcard_gd_clear
- Function
Erase a range of cart-ROM blocks.
- Header
- Declaration
FRESULT __fastcall__ sdcard_gd_clear (unsigned int nStartBlock, unsigned int nBlocks, unsigned char b512BlockCard);- Description
Erases
nBlockscart-ROM blocks starting atnStartBlock, with no source file. Setb512BlockCardnon-zero for a 512-block card. Blocks until the erase completes; the returned status is the result.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
Part of the RetroHQ SD/GD flash-cart API (
lynx/sdcard-gd.h); the originalLynxSD_*names remain as deprecated aliases. See SD / GD flash cart.- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.117. sdcard_gd_close
- Function
Close the open file.
- Header
- Declaration
FRESULT sdcard_gd_close (void);- Description
Closes the currently open file, flushing any buffered writes. Returns the MCU status byte.
- Notes
Part of the RetroHQ SD/GD flash-cart API (
lynx/sdcard-gd.h); the originalLynxSD_*names remain as deprecated aliases. See SD / GD flash cart.- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.118. sdcard_gd_init
- Function
Wake the SD/GD cart MCU.
- Header
- Declaration
void sdcard_gd_init (void);- Description
Initialises communication with the cart MCU (sets IODIR to input, sends the
$AAmagic byte). Call once before any othersdcard_gd_function.- Notes
Part of the RetroHQ SD/GD flash-cart API (
lynx/sdcard-gd.h); the originalLynxSD_*names remain as deprecated aliases. See SD / GD flash cart.- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.119. sdcard_gd_lowpower
- Function
Power the SD card down.
- Header
- Declaration
void sdcard_gd_lowpower (void);- Description
Powers the SD card down and enters low-power mode. Typically the last call before launching a freshly programmed ROM. Sends no response.
- Notes
Part of the RetroHQ SD/GD flash-cart API (
lynx/sdcard-gd.h); the originalLynxSD_*names remain as deprecated aliases. See SD / GD flash cart.- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.120. sdcard_gd_open
- Function
Open a file on the SD card.
- Header
- Declaration
FRESULT __fastcall__ sdcard_gd_open (const char* pFile);- Description
Opens the file at
pFile(DOS-style path, one file open at a time) for reading and writing.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
Part of the RetroHQ SD/GD flash-cart API (
lynx/sdcard-gd.h); the originalLynxSD_*names remain as deprecated aliases. See SD / GD flash cart.- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.121. sdcard_gd_opendir
- Function
Open a directory on the SD card.
- Header
- Declaration
FRESULT __fastcall__ sdcard_gd_opendir (const char* pDir);- Description
Opens the directory at
pDir(relative to the card root). Follow with repeatedsdcard_gd_readdircalls.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
Part of the RetroHQ SD/GD flash-cart API (
lynx/sdcard-gd.h); the originalLynxSD_*names remain as deprecated aliases. See SD / GD flash cart.- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.122. sdcard_gd_program
- Function
Program a ROM image into cart ROM.
- Header
- Declaration
FRESULT __fastcall__ sdcard_gd_program (unsigned int nStartBlock, unsigned char nBlockSize, unsigned int nBlockCount, unsigned char b512BlockCard);- Description
Programs
nBlockCountblocks ofnBlockSize(in 256-byte units: 1/2/4/8) into cart ROM starting atnStartBlock, sourced from the current position of the open file. Setb512BlockCardnon-zero for a 512-block card. Blocks until the flash completes; the returned status is the result.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
Part of the RetroHQ SD/GD flash-cart API (
lynx/sdcard-gd.h); the originalLynxSD_*names remain as deprecated aliases. See SD / GD flash cart.- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.123. sdcard_gd_read
- Function
Read bytes from the open file.
- Header
- Declaration
FRESULT __fastcall__ sdcard_gd_read (void* pBuffer, unsigned int nSize);- Description
Reads
nSizebytes from the open file intopBuffer. The payload is always fully transferred; the return value is the trailing status byte.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
Part of the RetroHQ SD/GD flash-cart API (
lynx/sdcard-gd.h); the originalLynxSD_*names remain as deprecated aliases. See SD / GD flash cart.- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.124. sdcard_gd_readdir
- Function
Read the next directory entry.
- Header
- Declaration
FRESULT __fastcall__ sdcard_gd_readdir (SFileInfo* pInfo);- Description
Reads the next entry from the directory opened by
sdcard_gd_opendirinto*pInfo(a 22-byte packed record). ReturnsFR_OKwhile entries remain; any other result ends the walk.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
Part of the RetroHQ SD/GD flash-cart API (
lynx/sdcard-gd.h); the originalLynxSD_*names remain as deprecated aliases. See SD / GD flash cart.- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.125. sdcard_gd_seek
- Function
Seek within the open file.
- Header
- Declaration
FRESULT __fastcall__ sdcard_gd_seek (unsigned long nSeekPos);- Description
Sets the read/write position of the open file to the absolute byte offset
nSeekPos.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
Part of the RetroHQ SD/GD flash-cart API (
lynx/sdcard-gd.h); the originalLynxSD_*names remain as deprecated aliases. See SD / GD flash cart.- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.126. sdcard_gd_size
- Function
Return the open file's size.
- Header
- Declaration
unsigned long sdcard_gd_size (void);- Description
Returns the size in bytes of the currently open file.
- Notes
Part of the RetroHQ SD/GD flash-cart API (
lynx/sdcard-gd.h); the originalLynxSD_*names remain as deprecated aliases. See SD / GD flash cart.- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.127. sdcard_gd_write
- Function
Write bytes to the open file.
- Header
- Declaration
FRESULT __fastcall__ sdcard_gd_write (const void* pBuffer, unsigned int nSize);- Description
Writes
nSizebytes frompBufferto the open file.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
Part of the RetroHQ SD/GD flash-cart API (
lynx/sdcard-gd.h); the originalLynxSD_*names remain as deprecated aliases. See SD / GD flash cart.- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.128. ser_close
- Function
Close the port and disable interrupts
- Header
- Declaration
unsigned char ser_close (void);- Description
Close the port by clearing buffers and disable interrupts.
- Availability
cc65
- See also
Other serial functions.
- Example
#include <lynx/serial.h> static void initialize(){ struct ser_params params = { SER_BAUD_9600, SER_BITS_8, SER_STOP_1, SER_PAR_MARK, SER_HS_NONE }; CLI(); ser_open(¶ms); }
3.129. ser_get
- Function
Read a character from serial port.
- Header
- Declaration
unsigned char __fastcall__ ser_get (char* b);- Description
Get a character from the serial port. If no characters are available, the function will return SER_ERR_NO_DATA, so this is not a fatal error.
- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65
- See also
Other serial functions.
- Example
Wait for a character to be available from a serial port.
char ch; while (ser_get(&ch) == SER_ERR_NO_DATA) ;
3.130. ser_open
- Function
Open the port by setting the port parameters and enable interrupts
- Header
- Declaration
unsigned char __fastcall__ ser_open (const struct ser_params* params);- Description
Open the port by setting the port parameters and enable interrupts.
- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65
- See also
Other serial functions.
- Example
#include <lynx/serial.h> static void initialize(){ struct ser_params params = { SER_BAUD_9600, SER_BITS_8, SER_STOP_1, SER_PAR_MARK, SER_HS_NONE }; CLI(); ser_open(¶ms); }
3.131. ser_put
- Function
Write a character to a serial port.
- Header
- Declaration
unsigned char __fastcall__ ser_put (char b);- Description
Send a character via the serial port. There is a transmit buffer, but transmitting is not done via interrupt. The function returns SER_ERR_OVERFLOW if there is no space left in the transmit buffer.
- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65
- See also
Other serial functions.
- Example
ser_put('A');
3.132. ser_status
- Function
Return the serial port status.
- Header
- Declaration
unsigned char __fastcall__ ser_status (unsigned char* status);- Description
Return the serial port status.
- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65
- See also
Other serial functions.
- Example
None
3.133. set_irq
- Function
Set the C level interrupt request vector to the given address.
- Header
- Declaration
void __fastcall__ set_irq (irq_handler f, void *stack_addr, size_t stack_size);- Description
set_irqallows a user program to handle interrupt requests (IRQs) within the program code by letting the vector point to a user written C function. The runtime library installs a small stub that saves the zero page registers used by the C runtime before calling the handler function and restores them after the handler function returns. Additionally the stub temporarily switches the C runtime stack to the stack area provided as parameter. If the handler function was set up to handle a "private", "exclusive" interrupt request source it must return the valueIRQ_HANDLEDif and only if it has verified that the current interrupt request actually stems from that source. In all other cases it must return the valueIRQ_NOT_HANDLED.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
The stub saves the registers and zero page locations used by the C runtime and switches to the provided stack area. As a consequence, there is some runtime overhead, but it it is safe to execute C code, even if other C code was interrupted. Be careful however not to call C library functions, and do not enable stack checks for the handler function or any other function called from it.
The interrupt vector is reset on program termination, so it's not strictly necessary to call
reset_irqas a part of your clean-up when exiting the program.- Availability
cc65
- See also
- Example
None.
3.134. setjmp
- Function
Save the context for use with
longjmp.- Header
- Declaration
int __fastcall__ setjmp (jmp_buf buf);- Description
The
setjmpfunction saves the current context inbuffor subsequent use by thelongjmpfunction and returns zero.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
setjmpis actually a macro as required by the ISO standard.
setjmpwill not save the signal context.- Availability
ISO 9899
- See also
- Example
None.
3.135. sleep
- Function
Sleep for a specified amount of time.
- Header
- Declaration
void __fastcall__ sleep (unsigned seconds);- Description
The function will return after the specified number of seconds have elapsed.
- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
POSIX 1003.1
- Example
None.
3.136. snd_active
- Function
Report which sound channels are active.
- Header
- Declaration
unsigned char snd_active (void);- Description
Returns a non-zero value while any of the four Mikey audio channels is still playing, so a program can wait for a tune to finish.
- Notes
- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.137. snd_continue
- Function
Resume sound after a pause.
- Header
- Declaration
void snd_continue (void);- Description
Resumes playback previously suspended with
snd_pause.- Notes
- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.138. snd_init
- Function
Initialize the sound engine.
- Header
- Declaration
void snd_init (void);- Description
Sets up the four Mikey audio channels, programs the dedicated sound timer (~240 Hz) and installs the sound-interrupt handler that drives playback. Call once before any other
snd_*function.- Notes
Playback runs from a dedicated Mikey timer interrupt (not the VBL); the handler is installed as an interruptor and stays resident. See the Sound page and
design/LYNX_SND_ENGINE_DESIGN.md.- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.139. snd_pause
- Function
Pause sound.
- Header
- Declaration
void snd_pause (void);- Description
Suspends playback on all channels. Resume with
snd_continue.- Notes
- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.140. snd_play
- Function
Play a compiled tune stream on a channel.
- Header
- Declaration
void __fastcall__ snd_play (unsigned char channel, const unsigned char* stream);- Description
Starts playing the compiled event
streamonchannel(0–3). If that channel is already sounding, it is retriggered in place: the old stream is force-stopped (see snd_stop for the fade-out this involves) and the new one starts on the same channel. The stream is produced offline by theabccctune compiler (see the Sound page). Playback then proceeds automatically under the sound-timer interrupt.The reusable sound-effect library (
<lynx/sfx.h>) is a pack of ready-made streams played this way:sfx_<name>(ch)expands tosnd_play(ch, sfx_<name>_data). The 56 effects (sfx_coin,sfx_laser,sfx_explosion_small,sfx_alarm, …) are catalogued on the Sound page; author your own with theSFX_*ca65 macros inasminc/lynx/sfx.inc.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.141. snd_stop
- Function
Stop sound on all channels.
- Header
- Declaration
void snd_stop (void);- Description
Silences every channel. Each channel's volume is faded out over a few sound-timer ticks (at most ~17 ms at the default 240 Hz rate) rather than cut instantly, to avoid an audible click; snd_active reports a channel busy until its fade finishes. See the Sound page §6.5.
- Notes
- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.142. snd_stop_channel
- Function
Stop sound on one channel.
- Header
- Declaration
void __fastcall__ snd_stop_channel (unsigned char channel);- Description
Silences the given
channel(0–3), leaving the others playing. Fades the volume out over a few ticks rather than cutting it instantly — same as snd_stop.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Atari Lynx only)
- See also
- Example
None.
3.143. snprintf
- Function
Format data into a string buffer, with a size limit.
- Header
- Declaration
int snprintf (char* buf, size_t size, const char* format, ...);- Description
snprintfformats its arguments according toformatand writes the result intobuf, storing at mostsizebytes including the terminating'\0'. The return value is the number of characters that would have been written had the buffer been unlimited, not counting the terminating'\0'; so a return value ofsizeor greater indicates that the output was truncated.- Notes
The conversions
c d i n o p s u x Xare supported, together with flags, field width, precision and theh l z t j Llength modifiers. Because cc65 has no floating-point support, the floating-point conversions (e E f F g G a A) are not available.If
sizeis zero, nothing is written intobuf(which may then beNULL), but the return value is still computed.
sizemust not exceedINT_MAX; a larger value setserrnotoERANGEand returns -1.- Availability
ISO 9899
- See also
- Example
None.
3.144. sprintf
- Function
Format data into a string buffer.
- Header
- Declaration
int sprintf (char* buf, const char* format, ...);- Description
sprintfformats its arguments according toformatand writes the result, terminated by a'\0', intobuf. It returns the number of characters written, not counting the terminating'\0'.- Notes
The conversions
c d i n o p s u x Xare supported, together with flags, field width, precision and theh l z t j Llength modifiers. Because cc65 has no floating-point support, the floating-point conversions (e E f F g G a A) are not available.There are no provisions to prevent a buffer overflow:
bufmust be large enough to hold the formatted result. Use snprintf if a bound is required.At most
INT_MAXcharacters can be produced.- Availability
ISO 9899
- See also
- Example
None.
3.145. srand
- Function
Initialize the pseudo random number generator.
- Header
- Declaration
void __fastcall__ srand (unsigned seed);- Description
The function initializes the random number generator using the given seed. On program startup, the generator behaves as if
srandhas been called with an argument of 1.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
ISO 9899
- See also
- Example
None.
3.146. sscanf
- Function
Read formatted data from a string.
- Header
- Declaration
int sscanf (const char* s, const char* format, ...);- Description
sscanfparses the stringsaccording toformatand stores the converted values through the pointer arguments that follow. It returns the number of input items successfully matched and assigned, orEOFif an input failure occurs before the first conversion.- Notes
The conversions
d i u o x X c s p nand the[character-set scanset are supported, together with assignment suppression (*), a field width and theh l z t j Llength modifiers.Because cc65 has no floating-point support, the floating-point conversions (
e E f F g G a A) and the wide-character conversions (S C) are not implemented: they seterrnotoENOSYSand returnEOF.An invalid conversion specification sets
errnotoEINVALand returnsEOF.- Availability
ISO 9899
- See also
- Example
None.
3.147. strcasecmp
- Function
Compare two strings case insensitive.
- Header
- Declaration
int __fastcall__ strcasecmp (const char* s1, const char* s2);- Description
The
strcasecmpfunction compares the two strings passed as parameters without case sensitivity. It returns a value that is less than zero ifs1is less thans2, zero ifs1is the same ass2, and a value greater than zero ifs1is greater thans2.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65
- See also
- Example
None.
3.148. strcat
- Function
Concatentate two strings.
- Header
- Declaration
char* __fastcall__ strcat (char* s1, const char* s2);- Description
The
strcatfunction appends a copy of the string pointed to by s2 (including the terminating null byte) to the end of the string pointed to by s1. The initial byte of s2 overwrites the null byte at the end of s1.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
If copying takes place between objects that overlap, the behaviour is undefined.
- Availability
ISO 9899
- See also
- Example
None.
3.149. strchr
- Function
Search for a character in a string.
- Header
- Declaration
char* __fastcall__ strchr (const char* s, int c);- Description
The
strchrfunction locates the first occurrence ofc(converted to a char) in the string pointed to bys. The terminating null byte is considered to be part of the string. Upon completion, the function returns a pointer to the byte, or a null pointer if the byte was not found.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
ISO 9899
- See also
- Example
None.
3.150. strcmp
- Function
Compare two strings.
- Header
- Declaration
int __fastcall__ strcmp (const char* s1, const char* s2);- Description
The
strcmpfunction compares the two strings passed as parameters. It returns a value that is less than zero ifs1is less thans2, zero ifs1is the same ass2, and a value greater than zero ifs1is greater thans2.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
ISO 9899
- See also
- Example
None.
3.151. strcoll
- Function
Compare two strings.
- Header
- Declaration
int __fastcall__ strcoll (const char* s1, const char* s2);- Description
The
strcollfunction compares the two strings passed as parameters, according to the standard character collating sequence (equivalent tostrcmp). It returns a value that is less than zero ifs1is less thans2, zero ifs1is the same ass2, and a value greater than zero ifs1is greater thans2.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
ISO 9899
- See also
- Example
None.
3.152. strcpy
- Function
Copy a string.
- Header
- Declaration
char* __fastcall__ strcpy (char* s1, const char* s2);- Description
The
strcpyfunction copies the string pointed to bys2(including the terminating null byte) into the array pointed to bys1. The function will always returns1.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
If copying takes place between objects that overlap, the behaviour is undefined.
- Availability
ISO 9899
- See also
- Example
#include <string.h> static char hello[14]; strcpy (hello, "Hello world!\n");
3.153. strcspn
- Function
Compute the length of a substring.
- Header
- Declaration
size_t __fastcall__ strcspn (const char* s, const char* set);- Description
The
strcspnfunction computes and returns the length of the substring pointed to byswhich does not consist of characters contained in the stringset.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
ISO 9899
- See also
- Example
None.
3.154. strdup
- Function
Allocate a copy of a string on the heap.
- Header
- Declaration
char* __fastcall__ strdup (const char* s);- Description
strdupallocates a memory block on the heap, big enough to hold a copy ofsincluding the terminating zero. If the allocation fails,NULLis returned, otherwisesis copied into the allocated memory block, and a pointer to the block is returned.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
It is up to the caller to free the allocated memory block.
- Availability
ISO 9899
- See also
- Example
None.
3.155. strerror
- Function
Return a string describing an error code.
- Header
- Declaration
char* __fastcall__ strerror (int errcode);- Description
The
strerrorfunction returns a string describing the given error code. If an invalid error code is passed, the string "Unknown error" is returned, anderrnois set toEINVAL. In all other cases,errnois left untouched.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
While the return type of the function is a
char*, the returned string must not be modified by the caller!- Availability
ISO 9899
- See also
None.
- Example
None.
3.156. stricmp
- Function
Compare two strings case insensitive.
- Header
- Declaration
int __fastcall__ stricmp (const char* s1, const char* s2);- Description
The
stricmpfunction compares the two strings passed as parameters without case sensitivity. It returns a value that is less than zero ifs1is less thans2, zero ifs1is the same ass2, and a value greater than zero ifs1is greater thans2.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65
- See also
- Example
None.
3.157. strlen
- Function
Return the length of a string.
- Header
- Declaration
size_t __fastcall__ strlen (const char* s);- Description
The
strlenfunction computes the number of bytes in the string to which s points, not including the terminating null byte.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
When compiling with
-Os(inline known standard functions), the function does not work correctly for strings with more than 255 characters.- Availability
ISO 9899
- See also
- Example
None.
3.158. strlower
- Function
Make a string lower case.
- Header
- Declaration
char* __fastcall__ strlower (char* s);- Description
The
strlowerfunction will apply thetolowerfunction to each character of a string. The function will always returns.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
An alias name for this function is
strlwr.- Availability
cc65
- See also
- Example
None.
3.159. strlwr
See
strlower.
3.160. strncasecmp
- Function
Compare two strings case insensitive.
- Header
- Declaration
int __fastcall__ strncasecmp (const char* s1, const char* s2, size_t count);- Description
The
strncasecmpfunction compares the two strings passed as parameters without case sensitivity. It returns a value that is less than zero ifs1is less thans2, zero ifs1is the same ass2, and a value greater than zero ifs1is greater thans2.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65
- See also
- Example
None.
3.161. strncat
- Function
Concatentate two strings.
- Header
- Declaration
char* __fastcall__ strncat (char* s1, const char* s2, size_t n);- Description
The
strncatfunction appends not more than n characters of the string pointed to by s2 to the end of the string pointed to by s1. The terminating null character at the end of s1 is overwritten. A terminating null character is appended to the result, even if not all of s2 is appended to s1.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
If copying takes place between objects that overlap, the behaviour is undefined.
- Availability
ISO 9899
- See also
- Example
None.
3.162. strncmp
- Function
Compare two strings.
- Header
- Declaration
int __fastcall__ strncmp (const char* s1, const char* s2, size_t count);- Description
The
strncmpfunction compares not more thancountcharacters of the two strings passed as parameters. It returns a value that is less than zero if the firstcountcharacters ofs1are less thans2, zero if they are identical, and a value greater than zero they are greater.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
ISO 9899
- See also
- Example
None.
3.163. strncpy
- Function
Copy part of a string.
- Header
- Declaration
char* __fastcall__ strncpy (char* s1, const char* s2, size_t n);- Description
The
strncpyfunction copies not more thannbytes from the array pointed to bys2to the array pointed to bys1. If the array pointed to bys2is a string that is shorter thannbytes, null bytes are appended to the copy in the array pointed to bys1, untilnbytes are written. The function always will returns1.- Notes
The function is available only as a fastcall function; so, it may be used only in the presence of a prototype.
If there is no null byte in the first
nbytes of the array pointed to bys2, the result is not null-terminated!If copying takes place between objects that overlap, the behaviour is undefined.
- Availability
ISO 9899
- See also
- Example
#include <string.h> static char hello[6]; strncpy (hello, "Hello world!\n", sizeof hello - 1)[5] = '\0';
3.164. strnicmp
- Function
Compare two strings case insensitive.
- Header
- Declaration
int __fastcall__ strnicmp (const char* s1, const char* s2, size_t count);- Description
The
strnicmpfunction compares the two strings passed as parameters without case sensitivity. It returns a value that is less than zero ifs1is less thans2, zero ifs1is the same ass2, and a value greater than zero ifs1is greater thans2.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65
- See also
- Example
None.
3.165. strpbrk
- Function
Find a character in a string, from a set of characters.
- Header
- Declaration
char* __fastcall__ strpbrk (const char* str, const char* set);- Description
strpbrk()searches withinstrfor the first occurance of any character fromset. It returns a pointer to that character if found; otherwise, it returnsNULL.- Notes
The function is available only as a fastcall function; so, it should be used only in the presence of a prototype.
- Availability
ISO 9899
- See also
- Example
None.
3.166. strqtok
- Function
Break a string into tokens.
- Header
- Declaration
char* __fastcall__ strqtok (char* s1, const char* s2);- Description
strqtok()will break the strings1into a sequence of tokens, which are delimited by either quotation marks or characters from the strings2. Tokens inside quotation marks may contain characters froms2(they aren't delimiters there). The first call tostrqtok()will return a pointer to the first token in the strings1. The following calls must pass aNULLpointer ass1, in order to get the next token in the string. Different sets of delimiters may be used for the subsequent calls tostrqtok().- Notes
The function is available only as a fastcall function; so, it may be used only in the presence of a prototype.
strqtok()will modify the strings1.The function will forget where it is in the
s1string if it is given a seconds1string before it finishes the first one.- Availability
cc65
- See also
- Example
None.
3.167. strrchr
- Function
Search for a character in a string.
- Header
- Declaration
char* __fastcall__ strrchr (const char* s, int c);- Description
The
strrchrfunction locates the last occurrence ofc(converted to a char) in the string pointed to bys. The terminating null byte is considered to be part of the string. Upon completion, the function returns a pointer to the byte, or a null pointer if the byte was not found.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
ISO 9899
- See also
- Example
None.
3.168. strspn
- Function
Compute the length of a substring.
- Header
- Declaration
size_t __fastcall__ strspn (const char* s, const char* set);- Description
The
strspnfunction computes and returns the length of the substring pointed to byswhich does consist only of characters contained in the stringset.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
ISO 9899
- See also
- Example
None.
3.169. strstr
- Function
Find a substring.
- Header
- Declaration
char* __fastcall__ strstr (const char* str, const char* substr);- Description
strstrsearches for the first occurance of the stringsubstrwithinstr. If found, it returns a pointer to the copy, otherwise it returnsNULL.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
ISO 9899
- See also
- Example
None.
3.170. strtok
- Function
Break a string into tokens.
- Header
- Declaration
char* __fastcall__ strtok (char* s1, const char* s2);- Description
strtok()will break the strings1into a sequence of tokens, which are delimited by characters from the strings2. The first call tostrtok()will return a pointer to the first token in the strings1. The following calls must pass aNULLpointer ass1, in order to get the next token in the string. Different sets of delimiters may be used for the subsequent calls tostrtok().- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
strtok()will modify the strings1.The function will forget where it is in the
s1string if it is given a seconds1string before it finishes the first one.- Availability
ISO 9899
- See also
- Example
None.
3.171. strupper
- Function
Make a string upper case.
- Header
- Declaration
char* __fastcall__ strupper (char* s);- Description
The
strupperfunction will apply thetoupperfunction to each character of a string. The function will always returns.- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
An alias name for this function is
strupr.- Availability
cc65
- See also
- Example
None.
3.172. strupr
See
strupper.
3.173. strxfrm
- Function
Transform a string.
- Header
- Declaration
size_t __fastcall__ strxfrm (char* s1, const char* s2, size_t n);- Description
The
strxfrmfunction transforms the string pointed to by s2 and places the resulting string into the string pointed to by s1. The transformation is such that if thestrcmpfunction is applied to two transformed strings, it returns a value greater than, equal to, or less than zero, corresponding to the result of thestrcollfunction applied to the same two original strings. No more than n characters are placed into the resulting array pointed to by s1, including the terminating null character.- Notes
s1ands2must not point to the same memory area, otherwise the behaviour is undefined.If
nis zero,s1may be a NULL pointer.The function is only available as fastcall function, so it may only be used in presence of a prototype.
Since cc65 doesn't support different charcter sets,
strxfrmwill just copy s2 to s1 usingstrncpy.- Availability
ISO 9899
- See also
- Example
None.
3.174. suzy_div_result
- Function
Harvest the result of an asynchronous signed Suzy divide.
- Header
- Declaration
int __fastcall__ suzy_div_result (void);- Description
Returns the signed quotient of the divide started by
suzy_div_startand applies the sign fixup. If the math unit is still busy the routine spins until it finishes, so calling it early simply degrades to a synchronous divide rather than returning a half-computed value. A divisor of zero yields the same result as the!/operator ($FFFF).- Notes
Between the matching
suzy_div_startand this call, the overlapped code must touch no Suzy state at all (see section 4).The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.175. suzy_div_start
- Function
Begin an asynchronous signed Suzy divide.
- Header
- Declaration
void __fastcall__ suzy_div_start (int n, int d);- Description
Writes the operands for the signed divide
n / dinto the Suzy math registers, records the sign-fixup state, triggers the hardware divide and returns immediately. The caller may then run unrelated, non-Suzy CPU work before reading the quotient withsuzy_div_result.- Notes
At most one asynchronous operation may be in flight at a time, and the overlapped code must touch no Suzy state (see section 4).
The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.176. suzy_math_busy
- Function
Test whether the Suzy math unit is still computing.
- Header
- Declaration
unsigned char suzy_math_busy (void);- Description
Returns nonzero while an asynchronous Suzy operation is still in progress (the
MATHWORKINGbit, bit 7 ofSPRSYSat$FC92), and zero once the result is ready. Use it to decide whether worthwhile interleaved work remains before harvesting; the*_resultroutines also poll defensively, so reading too early is always safe.- Notes
The function is actually a macro, cheap enough to inline in a poll loop.
- Availability
cc65 (Lynx)
- See also
3.177. suzy_mod_result
- Function
Harvest the result of an asynchronous signed Suzy modulo.
- Header
- Declaration
int __fastcall__ suzy_mod_result (void);- Description
Polls the overlapped divide to completion, then runs the short
(n/d)*dmultiply and subtract that finish the modulo and returnsn % dwith the correct sign. Only the divide overlaps your interleaved work; this trailing multiply and subtract run here, at harvest.- Notes
Between the matching
suzy_mod_startand this call, the overlapped code must touch no Suzy state (see section 4).The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.178. suzy_mod_start
- Function
Begin an asynchronous signed Suzy modulo.
- Header
- Declaration
void __fastcall__ suzy_mod_start (int n, int d);- Description
Saves
nandd, records the sign-fixup state and starts the divide that the modulo is built on, then returns immediately. The remainder is computed asn - (n/d)*d; the divide overlaps your interleaved work and the rest is finished bysuzy_mod_result.- Notes
At most one asynchronous operation may be in flight at a time, and the overlapped code must touch no Suzy state (see section 4).
The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.179. suzy_mul_result
- Function
Harvest the result of an asynchronous Suzy multiply (signed alias).
- Header
- Declaration
#define suzy_mul_result suzy_umul_result- Description
An alias for
suzy_umul_result. The low 16 bits of a two's-complement product are identical for signed and unsigned operands, so the signed and unsigned multiply harvests are the same routine.- Availability
cc65 (Lynx)
- See also
3.180. suzy_mul_start
- Function
Begin an asynchronous Suzy multiply (signed alias).
- Header
- Declaration
#define suzy_mul_start suzy_umul_start- Description
An alias for
suzy_umul_start. Because only the low 16 bits of the product are kept, signed multiply is the unsigned routine reinterpreted asint; no separate signed variant is needed.- Notes
Multiply is so fast (~11 cycles) that overlapping it rarely pays; it is provided for symmetry with the divide.
- Availability
cc65 (Lynx)
- See also
3.181. suzy_muldiv_result
- Function
Harvest the result of an asynchronous signed Suzy fused multiply-divide.
- Header
- Declaration
int __fastcall__ suzy_muldiv_result (void);- Description
Polls the overlapped divide to completion and returns the 16-bit signed quotient of
(a*b)/cwith the parity sign fixup applied. The 32-bit intermediate product avoids the overflow a separate!*followed by!/would suffer.- Notes
Only the divide phase overlaps your interleaved work; the multiply and the poll between the two phases run inside
suzy_muldiv_start.The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.182. suzy_muldiv_start
- Function
Begin an asynchronous signed Suzy fused multiply-divide.
- Header
- Declaration
void __fastcall__ suzy_muldiv_start (int a, int b, int c);- Description
Computes
(a*b)/cin one chained operation. All three operands are taken here because the divisor must be in place before the divide is triggered: the routine reduces the operands to magnitudes, runs the multiply, polls it, starts the divide on the settled 32-bit product and returns. The divide is the part that overlaps your interleaved work; harvest withsuzy_muldiv_result.- Notes
At most one asynchronous operation may be in flight at a time, and the overlapped code must touch no Suzy state (see section 4).
The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.183. suzy_udiv_result
- Function
Harvest the result of an asynchronous unsigned Suzy divide.
- Header
- Declaration
unsigned __fastcall__ suzy_udiv_result (void);- Description
Returns the unsigned quotient of the divide started by
suzy_udiv_start. If the unit is still busy the routine spins until it finishes, so a premature harvest degrades to a synchronous divide rather than returning garbage. A divisor of zero yields$FFFF, as with the!/operator. This is the cleanest and cheapest async operation: the unsigned divide carries no sign or operand state across the gap.- Notes
Between the matching
suzy_udiv_startand this call, the overlapped code must touch no Suzy state (see section 4).The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.184. suzy_udiv_start
- Function
Begin an asynchronous unsigned Suzy divide.
- Header
- Declaration
void __fastcall__ suzy_udiv_start (unsigned n, unsigned d);- Description
Writes the operands for the unsigned divide
n / dinto the Suzy math registers, triggers the hardware divide and returns immediately. This is the primary asynchronous operation: the divide takes the most hardware time (~44–100 CPU cycles), so the most useful work can be overlapped before harvesting withsuzy_udiv_result.- Notes
At most one asynchronous operation may be in flight at a time, and the overlapped code must touch no Suzy state (see section 4).
The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.185. suzy_umod_result
- Function
Harvest the result of an asynchronous unsigned Suzy modulo.
- Header
- Declaration
unsigned __fastcall__ suzy_umod_result (void);- Description
Polls the overlapped divide to completion, then runs the short
(n/d)*dmultiply and subtract and returnsn % d. As with signed modulo, only the divide overlaps your interleaved work; the trailing multiply and subtract run here.- Notes
Between the matching
suzy_umod_startand this call, the overlapped code must touch no Suzy state (see section 4).The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.186. suzy_umod_start
- Function
Begin an asynchronous unsigned Suzy modulo.
- Header
- Declaration
void __fastcall__ suzy_umod_start (unsigned n, unsigned d);- Description
Saves
nanddand starts the divide that the modulo is built on, then returns immediately. The remainder is computed asn - (n/d)*d; the divide overlaps your interleaved work and the rest is finished bysuzy_umod_result.- Notes
At most one asynchronous operation may be in flight at a time, and the overlapped code must touch no Suzy state (see section 4).
The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.187. suzy_umul_result
- Function
Harvest the result of an asynchronous unsigned Suzy multiply.
- Header
- Declaration
unsigned __fastcall__ suzy_umul_result (void);- Description
Returns the low 16 bits of the product started by
suzy_umul_start. The result is identical whether the operands are treated as signed or unsigned, which is whysuzy_mul_resultis an alias for this routine.- Notes
The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.188. suzy_umul_start
- Function
Begin an asynchronous unsigned Suzy multiply.
- Header
- Declaration
void __fastcall__ suzy_umul_start (unsigned a, unsigned b);- Description
Writes the factors
aandb, triggers the hardware multiply and returns immediately; harvest the low 16 bits withsuzy_umul_result. Suzy'sSIGNMATHmode is left off, so the same routine serves signed and unsigned multiply.- Notes
The multiply finishes in ~11 cycles, before the next few instructions retire, so overlapping it rarely pays; it is offered only for symmetry with the divide.
The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.189. suzy_umuldiv_result
- Function
Harvest the result of an asynchronous unsigned Suzy fused multiply-divide.
- Header
- Declaration
unsigned __fastcall__ suzy_umuldiv_result (void);- Description
Polls the overlapped divide to completion and returns the 16-bit quotient of
(a*b)/c. The full 32-bit intermediate product means the multiply cannot overflow the way a separate!*then!/would.- Notes
Only the divide phase overlaps your interleaved work; the multiply and the inter-phase poll run inside
suzy_umuldiv_start.The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.190. suzy_umuldiv_start
- Function
Begin an asynchronous unsigned Suzy fused multiply-divide.
- Header
- Declaration
void __fastcall__ suzy_umuldiv_start (unsigned a, unsigned b, unsigned c);- Description
Computes
(a*b)/cin one chained operation. All three operands are taken here because the divisor must be in the math registers before the divide is triggered: the routine runs the multiply, polls it, starts the divide on the 32-bit product and returns. The divide overlaps your interleaved work; harvest withsuzy_umuldiv_result.- Notes
At most one asynchronous operation may be in flight at a time, and the overlapped code must touch no Suzy state (see section 4).
The function is only available as a fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65 (Lynx)
- See also
3.191. tolower
- Function
Convert a character into its lower case representation.
- Header
- Declaration
int __fastcall__ tolower (int c);- Description
The function returns the given character converted to lower case. If the given character is not a letter, it is returned unchanged.
- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
ISO 9899
- See also
- Example
None.
3.192. toupper
- Function
Convert a character into its upper case representation.
- Header
- Declaration
int __fastcall__ toupper (int c);- Description
The function returns the given character converted to upper case. If the given character is not a letter, it is returned unchanged.
- Notes
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
ISO 9899
- See also
- Example
None.
3.193. ultoa
- Function
Convert an unsigned long integer into a string.
- Header
- Declaration
char* __fastcall__ ultoa (unsigned long val, char* buf, int radix);- Description
itoaconverts the unsigned long integervalinto a string usingradixas the base.- Notes
There are no provisions to prevent a buffer overflow.
You should probably use sprintf instead.
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65
- See also
- Example
None.
3.194. utoa
- Function
Convert an unsigned integer into a string.
- Header
- Declaration
char* __fastcall__ utoa (unsigned val, char* buf, int radix);- Description
itoaconverts the unsigned integervalinto a string usingradixas the base.- Notes
There are no provisions to prevent a buffer overflow.
You should probably use sprintf instead.
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
cc65
- See also
- Example
None.
3.195. vsnprintf
- Function
Format data into a string buffer, with a size limit, from a va_list.
- Header
- Declaration
int __fastcall__ vsnprintf (char* buf, size_t size, const char* format, va_list ap);- Description
vsnprintfworks exactly like snprintf, except that the variable arguments are taken from theva_listapinstead of from a variable argument list.- Notes
The conversions
c d i n o p s u x Xare supported, together with flags, field width, precision and theh l z t j Llength modifiers. Because cc65 has no floating-point support, the floating-point conversions (e E f F g G a A) are not available.The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
ISO 9899
- See also
- Example
None.
3.196. vsprintf
- Function
Format data into a string buffer, from a va_list.
- Header
- Declaration
int __fastcall__ vsprintf (char* buf, const char* format, va_list ap);- Description
vsprintfworks exactly like sprintf, except that the variable arguments are taken from theva_listapinstead of from a variable argument list.- Notes
The conversions
c d i n o p s u x Xare supported, together with flags, field width, precision and theh l z t j Llength modifiers. Because cc65 has no floating-point support, the floating-point conversions (e E f F g G a A) are not available.There are no provisions to prevent a buffer overflow; use vsnprintf if a bound is required.
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
ISO 9899
- See also
- Example
None.
3.197. vsscanf
- Function
Read formatted data from a string, into a va_list.
- Header
- Declaration
int __fastcall__ vsscanf (const char* s, const char* format, va_list ap);- Description
vsscanfworks exactly like sscanf, except that the pointer arguments are taken from theva_listapinstead of from a variable argument list.- Notes
The same conversions and the same floating-point / wide-character limitations as sscanf apply.
The function is only available as fastcall function, so it may only be used in presence of a prototype.
- Availability
ISO 9899
- See also
- Example
None.
4. How the Suzy math functions work
The Suzy chip contains a hardware multiply/divide unit that runs concurrently
with the 65C02. The synchronous !*, !/ and
!% operators already use it, but they spend the whole operation in a
poll loop, throwing that concurrency away — a divide can burn roughly 44 to
100 CPU cycles doing nothing while the unit works. The functions in
lynx/suzymath.h expose the same hardware as a
non-blocking, intrinsic-level API so those cycles can be spent on useful work
instead.
4.1. The hardware unit and the start / poll / harvest model
Each operation is split across three steps. A *_start call writes
the operand registers and triggers the unit, then returns immediately. The unit
computes while the CPU runs ahead. suzy_math_busy
reports whether the unit is still working by testing the MATHWORKING
bit (bit 7 of SPRSYS at $FC92). Finally a matching
*_result call harvests the registers, applies any sign fixup and
returns the value. The single math unit means the model is a simple three-state
machine — idle, running, done — and that exactly one asynchronous
operation may be in flight at any time, process-wide.
The typical use, and the one worth writing, is the divide:
#include <lynx/suzymath.h>
suzy_udiv_start(distance, speed); /* start the slow divide */
update_score(); /* ~80 cycles of NON-Suzy work */
ticks = suzy_udiv_result(); /* unit is already idle: free read */
Modulo and fused multiply-divide are two-phase: only their divide overlaps the
interleaved work, and the trailing multiply/subtract (modulo) or the multiply and
inter-phase poll (muldiv) run inside the start or result
call. The fused forms therefore take all three operands at start,
because the divisor must be in the registers before the divide is triggered.
4.2. Why only the divide is worth overlapping
The economics decide which operations have a useful async form. A multiply
finishes in about 11 cycles — before the next few instructions retire
— so the call and return overhead exceeds anything that could be hidden;
the multiply functions exist only for symmetry and are documented as rarely worth
it. A divide takes long enough (up to ~100 cycles) that a real chunk of unrelated
work fits in its shadow, which makes suzy_udiv_start
the headline feature. Modulo and fused muldiv are built on a divide, so they hide
that divide but still pay a short, fixed tail when the result is harvested. The
unsigned divide is the cleanest case of all: it carries no sign or operand state
across the gap and needs no SPRSYS setup.
4.3. Why they are safe to use
Safety rests on three properties. First, early or late harvest cannot
return garbage. Every *_result routine begins with the same
defensive poll the synchronous operators use, so harvesting before the unit
finishes simply blocks until it does — the async path degrades to a
synchronous operation rather than reading a half-computed value.
suzy_math_busy lets you skip that spin when you have real work to
interleave, but the spin is always the floor. Harvesting late, or never, leaves a
stale result in the registers that is harmlessly overwritten by the next
start.
Second, the results are verified equal to the synchronous operators.
The async routines share the operand-placement code and the hardware contracts of
!*/!//!%: divide-by-zero yields
$FFFF, signed results get the same sign fixup, and a host model of
all seven routines was checked against the synchronous reference with zero
mismatches across thousands of corner cases (including narrow divisors, the 256
boundary, and the 32-bit muldiv product). Signed state that must outlive the gap
is parked in a small dedicated memory block, not the general runtime scratch the
overlapped C code may reuse.
Third, the one new rule is auditable. Because you are
voluntarily holding the math unit open across a span of your own code, that span
must touch no Suzy state at all: no Lynx graphics drawing, no sprite launch, no other Suzy
math (operator or async start), and no SPRSYS write,
because the sprite engine shares the very same math registers. Every async use is
an explicit suzy_*_start / suzy_*_result pair, so a
reviewer can scan the code between a pair for forbidden Suzy use by eye or by
grep. The usual operator contracts also carry over: the routines are not
interrupt-safe, and the sprite engine must be idle while a math operation runs.
5. What is not in the library
The C library contains a large subset of the ISO C library. Functions are usually missing in areas where there is no support on a ROM-based, console-less 6502 system such as the Lynx — wide-character sets are an example. If a function is not mentioned below and is not flagged in its per-function entry, expect it to be available and to behave as defined in the C standard.
5.1. Functions that are not available
-
tmpfile/tmpnam. -
systemand the non-standardexec: the Lynx has no shell or command processor. To run another cart image, uselynx_load/lynx_execfrom<lynx/lynx.h>. -
All functions that handle floating-point numbers in some manner.
-
The
ldivfunction (cc65 currently is not able to return structs by value with a size not equal to 1, 2, or 4 bytes). -
All functions handling wide-character strings.
-
Signals and all related functions (having
SIGSEGVwould be cool. :-) -
setbuf/setvbuf. -
getenv/putenv: there is no environment on the Lynx, so these functions are not provided. -
time: there is no real-time clock, so thetimefunction is not available. The other functions from<time.h>are available. -
exit,abortandatexit: there is no host to return to, so the Lynx has no publicexit()and the runtime runs no teardown (hence noatexiteither). Return frommain()to terminate; the runtime's internal trap then just masks interrupts and halts the machine. (The non-standarddoesclrscrafterexitis likewise gone: nothing happens after the program stops.) -
iscntrl: dropped from<ctype.h>. The Lynx has no character console, so control characters carry no meaning; the other classification functions are still provided. -
_stroserrorand the_DE_ISREG/_DE_ISDIR/_DE_ISLBL/_DE_ISLNKdirectory-entry macros: leftovers of the mapped-errno and directory-stream machinery, neither of which exists on the cart.strerrorandstruct direntremain.
5.2. File I/O is read-only
File I/O on the Lynx is read-only, because the cart is ROM and there is no character console:
-
There is no
FILEobject, so none of the byte-stream functions are provided. The output family is absent —fopen/freopen/fclose,fwrite,printf/fprintf/vprintf/vfprintf,putchar/puts/fputc/fputsandperror— and so is the input FILE family:fread/fgets/fgetc,fscanf/scanf/vfscanf/vscanf,fseek/ftell/fgetpos/fsetpos/rewind,getchar/gets/ungetc,feof/ferror/clearerr/fflushandfdopen/fileno. For on-screen text usegfx_outtextfrom<lynx/gfx.h>. -
The only
<stdio.h>functions that remain are the in-RAM string routines:sprintf/snprintf(andvsprintf/vsnprintf) format into a buffer, andsscanf(andvsscanf) parses one. Because cc65 has no floating-point support, the floating-point conversions (e E f F g G a A) are absent from all of them, andsscanfadditionally rejects the wide-character conversions (S C). To stream raw bytes from the cart, useread()/lseek()on a handle fromopenn()(see<unistd.h>and<lynx/lynx.h>). -
remove/renameand the name-basedopen/creat/close/writeare not provided: cart files are ROM and are addressed by number, not by name.
5.3. Functions that are limited
-
strcspn/strpbrk/strspn: these functions have a length limitation of 256 for the second string argument. Since that string gives a character set, and there are only 256 distinct characters, that shouldn't be a problem. -
locale: there is no locale other than the "C" locale. The native locale is identical to the "C" locale.
5.4. Extra limits when inlining with -Os
Some more functions are limited if inlined versions are requested by using the
-Os command-line option:
-
The
strlenfunction works for only strings with a maximum length of 255 characters. -
The
isXXXcharacter classification functions from<ctype.h>will give unpredictable results if the argument is not in character range (0..255). That limitation may be removed by#undef'ing the function name (when using-Os, the functions are actually macros that expand to inline assembly code, but the real functions still are available if the macro definition is removed).
5.5. Removed driver APIs
The em (extended memory), mouse, conio
and dbg APIs that ship with the stock cc65 library are not
part of this tree: the Lynx has a flat 64 KB address space, no pointing
device and no text mode, so those headers and their drivers have been removed
entirely. Text output goes through the Lynx graphics bitmap-font functions instead
(see lynx/gfx.h). The generic loadable joystick driver is
likewise replaced by a small static implementation; a single
joy_read call returns every input the
console has (see lynx/joystick.h and
design/LYNX_JOY_SER_DESIGN.md).