cc65 function reference

cc65 is a C compiler for 6502 based systems. This function reference describes the C functions available in the standard library.

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, close and write are not provided. Use openn for numbered, read-only cart access, then read/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

stdlib.h

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

stdlib.h

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, calloc or realloc.

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

stdlib.h

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

stdlib.h

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

stdlib.h

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

rand, srand

Example

None.

3.6. _swap

Function

Swap the contents of memory areas.

Header

stdlib.h

Declaration

void __fastcall__ _swap (void* p, void* q, size_t size);

Description

_swap will swap (exchange) the contents of the two memory areas pointed to by p and q. Both memory areas are assumed to be size bytes 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

memcpy, memmove

Example

None.

3.7. _sys

Function

Call a subroutine passing register values.

Header

6502.h

Declaration

void __fastcall__ _sys (struct regs* r);

Description

The function will call the subroutine at the address specified in the pc member of the passed regs structure. All registers and the CPU flags are set to the values given in the regs structure. 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 regs structure 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

6502.h

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

CLI, SEI

Example

None.

3.9. CLI

Function

Insert a 6502 CLI instrunction into the code.

Header

6502.h

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

BRK, SEI

Example

None.

3.10. PEEK

Function

Read a byte from memory.

Header

peekpoke.h

Declaration

unsigned char PEEK (unsigned addr);

Description

The function will read the absolute memory given by addr and return the value read.

Notes
  • The function is actually a macro.

  • This function depends highly on the platform and environment.

Availability

cc65

See also

PEEKW, POKE

Example

None.

3.11. PEEKW

Function

Read a word (two bytes) from memory.

Header

peekpoke.h

Declaration

unsigned PEEKW (unsigned addr);

Description

The function will read the absolute memory given by addr and 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

PEEK, POKE

Example

None.

3.12. POKE

Function

Write a byte to memory.

Header

peekpoke.h

Declaration

void POKE (unsigned addr, unsigned char val);

Description

The function writes the value val to the absolute memory address given by addr.

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

PEEK, POKEW

Example

None.

3.13. POKEW

Function

Write a word (two bytes) to memory.

Header

peekpoke.h

Declaration

void POKEW (unsigned addr, unsigned val);

Description

The function writes the value val to the absolute memory address given by addr. The low byte of val is written to the addr, the high byte is written to addr+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

PEEK, POKE

Example

None.

3.14. SEI

Function

Insert a 6502 SEI instrunction into the code.

Header

6502.h

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

BRK, CLI

Example

None.

3.15. abs

Function

Returns the absolute value of an integer.

Header

stdlib.h

Declaration

int __fastcall__ abs (int v);

Description

abs returns the absolute value of the argument passed to the function.

Notes
  • The return value is undefined if INT_MIN is 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

labs

Example

None.

3.16. atoi

Function

Convert a string to an integer.

Header

stdlib.h

Declaration

int __fastcall__ atoi (const char* s);

Description

atoi converts 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

atol, itoa, ltoa, ultoa, utoa

Example

None.

3.17. atol

Function

Convert a string to a long integer.

Header

stdlib.h

Declaration

long __fastcall__ atol (const char* s);

Description

atol converts 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

atoi, itoa, ltoa, ultoa, utoa

Example

None.

3.18. bsearch

Function

Do a binary search in a sorted array.

Header

stdlib.h

Declaration

void* __fastcall__ bsearch (const void* key, const void* base, size_t n, size_t size, int __fastcall__ (* cmp) (const void*, const void*));

Description

bsearch searches a sorted array for a member that matches the one pointed to by key. base is the address of the array, n is the number of elements, size the size of an element and cmp the function used to compare the members against the key. The function returns a pointer to the member found, or NULL if 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 cmp points must have the fastcall calling convention.

Availability

ISO 9899

See also

qsort

Example

None.

3.19. bzero

Function

Fill a memory area with zeroes.

Header

string.h

Declaration

void __fastcall__ bzero (void* p, size_t count);

Description

bzero fills the memory area pointed to by p with zero.

Notes
  • You should use memset instead.

  • The function is only available as fastcall function, so it may only be used in presence of a prototype.

Availability

cc65

See also

_swap, memcpy, memmove, memset,

Example

None.

3.20. calloc

Function

Allocate and clear memory.

Header

stdlib.h

Declaration

void* __fastcall__ calloc (size_t n, size_t size);

Description

calloc allocates memory for an array of n elements of size size, clears the whole block with binary zeroes and returns a pointer to it. On error (not enough memory available), calloc returns NULL.

Notes
  • Clearing the memory may not have the expected effect on all platforms: pointers in the block may not be NULL and 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

time.h

Declaration

clock_t clock (void);

Description

The clock function 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 macro CLOCKS_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

sleep

Example

None.

3.22. decompress_lz4

Function

Uncompress a LZ4-compressed buffer.

Header

lynx/lz4.h

Declaration

void decompress_lz4 (const unsigned char* src, unsigned char* const dst, const unsigned short uncompressed_size);

Description

decompress_lz4 uncompresses 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

stdlib.h

Declaration

div_t __fastcall__ div (int numer, int denom);

Description

div divides numer by denom and returns the quotient and remainder in a div_t structure.

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

lynx/lynx.h

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

eeprom_93c46_write

Example

None.

3.25. eeprom_93c46_write

Function

Write a word to a 93C46 EEPROM.

Header

lynx/lynx.h

Declaration

void __fastcall__ eeprom_93c46_write (unsigned addr, unsigned val);

Description

Writes the 16-bit val at addr (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

eeprom_93c46_read

Example

None.

3.26. eeprom_93c66_read

Function

Read a word from a 93C66 EEPROM.

Header

lynx/lynx.h

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

eeprom_93c66_write

Example

None.

3.27. eeprom_93c66_write

Function

Write a word to a 93C66 EEPROM.

Header

lynx/lynx.h

Declaration

void __fastcall__ eeprom_93c66_write (unsigned addr, unsigned val);

Description

Writes the 16-bit val at addr (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

eeprom_93c66_read

Example

None.

3.28. eeprom_93c86_read

Function

Read a word from a 93C86 EEPROM.

Header

lynx/lynx.h

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

eeprom_93c86_write

Example

None.

3.29. eeprom_93c86_write

Function

Write a word to a 93C86 EEPROM.

Header

lynx/lynx.h

Declaration

void __fastcall__ eeprom_93c86_write (unsigned addr, unsigned val);

Description

Writes the 16-bit val at addr (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

eeprom_93c86_read

Example

None.

3.30. free

Function

Free a block of dynamic memory.

Header

stdlib.h

Declaration

void __fastcall__ free (void* block);

Description

Free a block of dynamic memory previously allocated with malloc, calloc or realloc. As an exception, if the passed pointer is NULL, no action is performed.

Notes
  • Passing an already free'd block to free again 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

lynx/gfx.h

Declaration

unsigned char gfx_busy (void);

Description

Returns nonzero while a swap requested by gfx_updatedisplay has 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 through gfx_sprite is synchronous and has already finished when the call returns.

Availability

cc65 (Lynx)

See also

gfx_updatedisplay, gfx_setviewpage, gfx_setdrawpage

3.32. gfx_clear

Function

Clear the draw page.

Header

lynx/gfx.h

Declaration

void gfx_clear (void);

Description

Clears the whole draw page to the current drawing color set with gfx_setcolor. Because gfx_init selects black (pen 0), gfx_init followed by gfx_clear yields 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

gfx_clearrows, gfx_setcolor, gfx_init

3.33. gfx_clearrows

Function

Clear a band of rows of the draw page.

Header

lynx/gfx.h

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 a count of 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

gfx_clear, gfx_setcolor

3.34. gfx_flip

Function

Rotate the display by 180 degrees.

Header

lynx/gfx.h

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

gfx_updatedisplay, gfx_setviewpage

3.35. gfx_getcolor

Function

Return the current drawing pen.

Header

lynx/gfx.h

Declaration

unsigned char gfx_getcolor (void);

Description

Returns the drawing pen (0-15) last set with gfx_setcolor.

Availability

cc65 (Lynx)

See also

gfx_setcolor, gfx_setbgcolor

3.36. gfx_getcolorcount

Function

Return the number of available colors.

Header

lynx/gfx.h

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

gfx_getmaxcolor

3.37. gfx_getdefpalette

Function

Return the default palette.

Header

lynx/gfx.h

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_setdefpalette installs.

Availability

cc65 (Lynx)

See also

gfx_getpalette, gfx_setdefpalette, gfx_setpalette

3.38. gfx_getmaxcolor

Function

Return the highest color number.

Header

lynx/gfx.h

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

gfx_getcolorcount, gfx_setcolor

3.39. gfx_getmaxx

Function

Return the highest X coordinate.

Header

lynx/gfx.h

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

gfx_getxres, gfx_getmaxy

3.40. gfx_getmaxy

Function

Return the highest Y coordinate.

Header

lynx/gfx.h

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

gfx_getyres, gfx_getmaxx

3.41. gfx_getpagecount

Function

Return the number of screen pages.

Header

lynx/gfx.h

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

gfx_setviewpage, gfx_setdrawpage

3.42. gfx_getpalette

Function

Return the current palette.

Header

lynx/gfx.h

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

gfx_getdefpalette, gfx_setpalette

3.43. gfx_gettextheight

Function

Return the height of a text string in pixels.

Header

lynx/gfx.h

Declaration

unsigned __fastcall__ gfx_gettextheight (const char* s);

Description

Returns the height in pixels that the string s would occupy if drawn at the current text scale set with gfx_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

gfx_gettextwidth, gfx_settextscale, gfx_outtext

3.44. gfx_gettextwidth

Function

Return the width of a text string in pixels.

Header

lynx/gfx.h

Declaration

unsigned __fastcall__ gfx_gettextwidth (const char* s);

Description

Returns the width in pixels that the string s would occupy if drawn at the current text scale set with gfx_settextscale.

Notes
  • For the fixed-pitch fonts (GFX_FONT_BITMAP, GFX_FONT_COMPACT) the width is strlen×pitch scaled; for the proportional font (GFX_FONT_VARIABLE) it is the sum of each glyph’s advance, so it matches the spacing gfx_outtext actually 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

gfx_gettextheight, gfx_settextscale, gfx_outtext

3.45. gfx_getxres

Function

Return the X resolution of the screen.

Header

lynx/gfx.h

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

gfx_getmaxx, gfx_getyres

3.46. gfx_getyres

Function

Return the Y resolution of the screen.

Header

lynx/gfx.h

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

gfx_getmaxy, gfx_getxres

3.47. gfx_gotoxy

Function

Set the text output cursor.

Header

lynx/gfx.h

Declaration

void __fastcall__ gfx_gotoxy (int x, int y);

Description

Moves the text cursor used by gfx_outtext to (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

gfx_outtext, gfx_outtextxy

3.48. gfx_init

Function

Initialize the graphics system.

Header

lynx/gfx.h

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_init followed by gfx_clear yields 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_setcolor must now set its color first.

  • gfx_init no longer loads the default palette — it clears every pen to black. Call gfx_setdefpalette after it for the built-in 16-colour default, or gfx_setpalette for your own.

Availability

cc65 (Lynx)

See also

gfx_clear, gfx_setcolor, gfx_setdefpalette, gfx_setpalette

3.49. gfx_outtext

Function

Output text at the current cursor position.

Header

lynx/gfx.h

Declaration

void __fastcall__ gfx_outtext (const char* s);

Description

Draws the string s at 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

gfx_outtextxy, gfx_gotoxy, gfx_setfont, gfx_settextscale

3.50. gfx_outtextxy

Function

Output text at a given position.

Header

lynx/gfx.h

Declaration

void __fastcall__ gfx_outtextxy (int x, int y, const char* s);

Description

Moves the text cursor to (x, y) and draws the string s there; see gfx_outtext for 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

gfx_outtext, gfx_gotoxy

3.51. gfx_setbgcolor

Function

Set the text background pen.

Header

lynx/gfx.h

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

gfx_setcolor, gfx_outtext

3.52. gfx_setbpp

Function

Select the display color depth.

Header

lynx/gfx.h

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_sprite and gfx_outtext display garbled in 2bpp. gfx_clear stays valid only for colors 0, 5, 10 and 15, which map to the 2bpp pens 0-3.

  • The mode relies on a DISPCTL bit 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

gfx_clear, gfx_sprite

3.53. gfx_setcollisiondetection

Function

Enable or disable sprite collision detection.

Header

lynx/gfx.h

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_clear and gfx_clearrows also erase the corresponding rows of the collision buffer. A program that uses it must link with lynx-coll.cfg to 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

gfx_clear, gfx_clearrows, gfx_sprite

3.54. gfx_setcolor

Function

Set the drawing pen.

Header

lynx/gfx.h

Declaration

void __fastcall__ gfx_setcolor (unsigned char color);

Description

Sets the drawing pen (0-15) used by gfx_clear, gfx_clearrows and 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

gfx_getcolor, gfx_setbgcolor, gfx_clear

3.55. gfx_setdefpalette

Function

Load the built-in default palette.

Header

lynx/gfx.h

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_init clears the palette to black, so call gfx_setdefpalette after it to obtain the historical default colours. The default palette table is only linked into programs that call this (or gfx_getdefpalette).

Availability

cc65 (Lynx)

See also

gfx_setpalette, gfx_getdefpalette

3.56. gfx_setdrawpage

Function

Select the page drawn into.

Header

lynx/gfx.h

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

gfx_setviewpage, gfx_updatedisplay, gfx_getpagecount

3.57. gfx_setfont

Function

Select the active text font.

Header

lynx/gfx.h

Declaration

void __fastcall__ gfx_setfont (unsigned char font);

Description

Selects the active text font, one of the GFX_FONT_XXX constants. GFX_FONT_BITMAP is the system 8x8 font (the default); GFX_FONT_COMPACT is the 5x5 font with a transparent background, drawn in the current pen at a 6-pixel pitch; GFX_FONT_VARIABLE is 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 and gfx_gettextwidth sums per-glyph advances instead of strlen×pitch.

Notes
  • Linking gfx_setfont pulls 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

gfx_outtext, gfx_settextstyle

3.58. gfx_setframerate

Function

Set the display refresh rate.

Header

lynx/gfx.h

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

gfx_init

3.59. gfx_setpalette

Function

Set the palette.

Header

lynx/gfx.h

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

lynx/gfx.h

Declaration

void __fastcall__ gfx_setpalette16 (const unsigned short* palette);

Description

Installs a new palette from the condensed form: 16 entries, one unsigned short per pen, each a packed 12-bit colour of the form 0x0GBR (green nibble in bits 8–11, blue in bits 4–7, red in bits 0–3). Each entry is split into the two GCOLMAP halves as it loads, so this installs the same colours as gfx_setpalette does 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

gfx_setpalette, gfx_getpalette, gfx_setdefpalette

3.61. gfx_settextdir

Function

Set the text output direction.

Header

lynx/gfx.h

Declaration

void __fastcall__ gfx_settextdir (unsigned char dir);

Description

Sets the direction in which the text cursor advances between gfx_outtext calls, one of the GFX_TEXT_XXX constants. It affects only how the cursor advances; the glyphs themselves are not rotated. GFX_TEXT_HORIZONTAL advances the cursor right by the string width; GFX_TEXT_VERTICAL advances 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

gfx_settextstyle, gfx_outtext

3.62. gfx_settextscale

Function

Set the text scaling.

Header

lynx/gfx.h

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

gfx_settextstyle, gfx_gettextwidth, gfx_gettextheight

3.63. gfx_settextstyle

Function

Set text scaling and direction.

Header

lynx/gfx.h

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 font argument is ignored; use gfx_setfont to 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

gfx_settextscale, gfx_settextdir, gfx_setfont

3.64. gfx_setviewpage

Function

Select the visible page.

Header

lynx/gfx.h

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

gfx_setdrawpage, gfx_updatedisplay, gfx_getpagecount

3.65. gfx_sprite

Function

Draw a sprite control block.

Header

lynx/gfx.h

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

gfx_setcollisiondetection, gfx_clear

3.66. gfx_updatedisplay

Function

Request a page swap at the next VBL.

Header

lynx/gfx.h

Declaration

void gfx_updatedisplay (void);

Description

Requests that the draw page and the view page be swapped at the next VBL interrupt. Poll gfx_busy to learn when the swap has happened.

Availability

cc65 (Lynx)

See also

gfx_busy, gfx_setviewpage, gfx_setdrawpage, gfx_flip

3.67. handymusic_init

Function

Initialize the HandyMusic engine and audio hardware.

Header

lynx/handymusic.h

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_init and CLI()), 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

handymusic_play_music, handymusic_stop_all

3.68. handymusic_pause

Function

Pause HandyMusic and mute all channels.

Header

lynx/handymusic.h

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

handymusic_unpause

3.69. handymusic_pcm_playing

Function

Report whether a PCM sample is currently playing.

Header

lynx/handymusic.h

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

handymusic_play_pcm

3.70. handymusic_play_music

Function

Start the song resident in the reserved music region.

Header

lynx/handymusic.h

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 with handymusic_stop_music before loading and playing another.

Availability

cc65 (Lynx)

See also

handymusic_stop_music, handymusic_init

3.71. handymusic_play_pcm

Function

Play an 8 kHz PCM sample from a RAM buffer.

Header

lynx/handymusic.h

Declaration

void __fastcall__ handymusic_play_pcm (const unsigned char* buf, unsigned int len);

Description

Streams the len-byte signed 8-bit sample at buf straight 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. buf must stay resident until playback ends. No-op if PCM is muted (handymusic_disable_pcm) or len is zero.

Availability

cc65 (Lynx)

See also

handymusic_register_pcm, handymusic_pcm_playing

3.72. handymusic_play_sfx

Function

Queue a sound effect to start on the next frame.

Header

lynx/handymusic.h

Declaration

void __fastcall__ handymusic_play_sfx (unsigned char n);

Description

n is an SFX_* index from the hmcc-generated .equ file. 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

handymusic_stop_sfx

3.73. handymusic_register_pcm

Function

Register a PCM sample so the music “play sample” command can trigger it.

Header

lynx/handymusic.h

Declaration

void __fastcall__ handymusic_register_pcm (unsigned char num, const unsigned char* buf, unsigned int len);

Description

Records the len-byte sample at buf in slot num (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; buf must stay resident. A slot left unregistered plays nothing.

Availability

cc65 (Lynx)

See also

handymusic_play_pcm

3.74. handymusic_stop_all

Function

Stop every music track and sound effect.

Header

lynx/handymusic.h

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_music only frees channels the music still controls.

Availability

cc65 (Lynx)

See also

handymusic_stop_music, handymusic_stop_sfx

3.75. handymusic_stop_music

Function

Stop the current song.

Header

lynx/handymusic.h

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_all for a full stop.

Availability

cc65 (Lynx)

See also

handymusic_play_music, handymusic_stop_all

3.76. handymusic_stop_sfx

Function

Stop the first sound whose priority matches.

Header

lynx/handymusic.h

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

handymusic_play_sfx

3.77. handymusic_unpause

Function

Resume HandyMusic after a pause.

Header

lynx/handymusic.h

Declaration

void handymusic_unpause (void);

Description

Restores every channel muted by handymusic_pause. Double-call safe.

Availability

cc65 (Lynx)

See also

handymusic_pause

3.78. isalnum

Function

Check if a given character is a letter or digit.

Header

ctype.h

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

ctype.h

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

ctype.h

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

ctype.h

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

ctype.h

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

ctype.h

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

ctype.h

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

ctype.h

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

ctype.h

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

ctype.h

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

ctype.h

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

ctype.h

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

stdlib.h

Declaration

char* __fastcall__ itoa (int val, char* buf, int radix);

Description

itoa converts the integer val into a string using radix as the base.

Notes
  • There are no provisions to prevent a buffer overflow.

  • If val contains INT_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

atoi, atol, ltoa, ultoa, utoa

Example

None.

3.91. joy_read

Function

Read the complete joypad input state.

Header

lynx/joystick.h

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_xxx masks and macros from lynx/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

stdlib.h

Declaration

long __fastcall__ labs (long v);

Description

labs returns the absolute value of the argument passed to the function.

Notes
  • The return value is undefined if LONG_MIN is 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

abs

Example

None.

3.93. longjmp

Function

Non local goto.

Header

setjmp.h

Declaration

void __fastcall__ longjmp (jmp_buf buf, int retval);

Description

The longjmp function restores a program context from the data in buf, which must have been set by a preceeding call to setjmp. Program execution continues as if the call to setjmp has just returned the value retval.

Notes
  • If the parameter retval is 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

setjmp

Example

None.

3.94. ltoa

Function

Convert a long integer into a string.

Header

stdlib.h

Declaration

char* __fastcall__ ltoa (long val, char* buf, int radix);

Description

itoa converts the long integer val into a string using radix as the base.

Notes
  • There are no provisions to prevent a buffer overflow.

  • If val contains LONG_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

atoi, atol, itoa, ultoa, utoa

Example

None.

3.95. lynx_exec

Function

Load a cartridge file into RAM and run it.

Header

lynx/lynx.h

Declaration

void __fastcall__ lynx_exec (int fileno);

Description

Loads numbered directory entry fileno like lynx_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

lynx_load, openn

Example

None.

3.96. lynx_load

Function

Load a cartridge file into RAM.

Header

lynx/lynx.h

Declaration

void __fastcall__ lynx_load (int fileno);

Description

Opens numbered directory entry fileno with openn and reads the whole file to the RAM address recorded in its directory entry. The first entry is fileno 0.

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

lynx_exec, openn

Example

None.

3.97. malloc

Function

Allocate dynamic memory.

Header

stdlib.h

Declaration

void* __fastcall__ malloc (size_t size);

Description

malloc allocates size bytes on the heap and returns a pointer to the allocated memory block. On error (not enough memory available), malloc returns NULL.

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

string.h

Declaration

void* __fastcall__ strchr (const void* mem, int c, size_t count);

Description

The memchr function locates the first occurrence of c (converted to a char) in the block of raw memory string pointed to by mem that is of size count. 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

strchr

Example

None.

3.99. memcmp

Function

Compare two memory areas.

Header

string.h

Declaration

int __fastcall__ memcmp (const void* p1, const void* p2, size_t count);

Description

memcmp compares count bytes from the memory area pointed to by p1 into the memory area pointed to by p2. It returns a value that is less than zero if p1 is less than p2, zero if p1 is the same as p2, and a value greater than zero if p1 is greater than p2.

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

strcmp, memmove, memset

Example

None.

3.100. memcpy

Function

Copy a memory area.

Header

string.h

Declaration

void* __fastcall__ memcpy (void* dest, const void* src, size_t count);

Description

memcpy copies count bytes from the memory area pointed to by src into the memory area pointed to by dest. It returns dest.

Notes
  • The result is undefined if the memory areas do overlap. Use memmove to 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

_swap, memmove, memset

Example

None.

3.101. memmove

Function

Copy a memory area.

Header

string.h

Declaration

void* __fastcall__ memmove (void* dest, const void* src, size_t count);

Description

memmove copies count bytes from the memory area pointed to by src into the memory area pointed to by dest. It returns dest.

Notes
  • While memmove allows the memory areas to overlap, it has some additional overhead compared to memcpy.

  • The function is only available as fastcall function, so it may only be used in presence of a prototype.

Availability

ISO 9899

See also

_swap, memcpy, memset

Example

None.

3.102. memset

Function

Fill a memory area.

Header

string.h

Declaration

void* __fastcall__ memset (void* p, int val, size_t count);

Description

memset fills the memory area pointed to by p with the value val. The function returns p.

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

_swap, bzero, memcpy, memmove

Example

None.

3.103. mikey_snd_integrate

Function

Set or clear a Mikey channel's integrate (waveform-shape) bit.

Header

lynx/lynx.h

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): val 0 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

mikey_snd_volume, snd_play

Example

None.

3.104. mikey_snd_octave

Function

Set a Mikey channel's clock-divider (octave) band.

Header

lynx/lynx.h

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) to val (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

mikey_snd_pitch

Example

None.

3.105. mikey_snd_pitch

Function

Set a Mikey channel's timer reload (pitch within the octave).

Header

lynx/lynx.h

Declaration

void __fastcall__ mikey_snd_pitch (unsigned char chan, unsigned char val);

Description

Writes the BACKUP (timer reload) register of channel chan (0–3) to val (0–255). Together with mikey_snd_octave this 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

mikey_snd_octave

Example

None.

3.106. mikey_snd_taps

Function

Select a Mikey channel's LFSR feedback taps (timbre / noise colour).

Header

lynx/lynx.h

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. val ranges 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

mikey_snd_integrate

Example

None.

3.107. mikey_snd_volume

Function

Set a Mikey channel's output volume.

Header

lynx/lynx.h

Declaration

void __fastcall__ mikey_snd_volume (unsigned char chan, unsigned char val);

Description

Writes the signed VOLUME register of channel chan (0–3) to val (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

mikey_snd_pitch, mikey_snd_octave

Example

None.

3.108. multicart_run

Function

Launch a bundled game ROM from a multicart menu; does not return.

Header

lynx/multicart.h

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 $0040 and 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

lynx_exec, openn

Example

None.

3.109. offsetof

Function

Calculate the offset of a struct or union member.

Header

stddef.h

Declaration

size_t offsetof (type, member);

Description

offsetof calculates the address offset of a struct or union member.

Notes
  • The function is actually a macro.

Availability

ISO 9899

Example

None.

3.110. openn

Function

Open a numbered file on the cartridge.

Header

lynx/lynx.h

Declaration

void __fastcall__ openn (int fileno);

Description

openn locates directory entry fileno on the cart and positions it at that file's first byte, ready for read and lseek. 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. openn is the Lynx replacement for the POSIX open, 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

lynx/lynx.h

Declaration

void poweroff (void);

Description

poweroff clears the power bit (bit 1) of the SYSCTL1 register at 0xFD87. That bit powers up as 1 at 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.

  • SYSCTL1 is write-only and its bit 0 is the cartridge address strobe, so the register cannot be read-modify-written; poweroff writes 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

stdlib.h

Declaration

void __fastcall__ qsort (void* base, size_t count, size_t size, int __fastcall__ (* compare) (const void*, const void*));

Description

qsort sorts an array according to a given compare function compare. base is the address of the array, count is the number of elements, size the size of an element and compare the 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 compare points must have the fastcall calling convention.

Availability

ISO 9899

See also

bsearch

Example

None.

3.113. rand

Function

Return a pseudo random number.

Header

stdlib.h

Declaration

int rand (void);

Description

The function returns a pseudo random number between 0 and RAND_MAX (exclusive).

Notes
  • Without using srand, always the same flow of numbers is generated.

  • On startup, the function behaves as if srand had been used with an argument of 1.

Availability

ISO 9899

See also

_randomize, srand

Example

None.

3.114. realloc

Function

Change the size of an allocated memory block.

Header

stdlib.h

Declaration

void* __fastcall__ realloc (void* block, size_t size);

Description

realloc changes the size of the memory block pointed to by block to size bytes. If block is NULL, realloc behaves as if malloc had been called. If size is zero, realloc behaves as if free had been called. On error (not enough memory available), realloc returns NULL.

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 ptr if realloc returns NULL.

  • 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

6502.h

Declaration

void reset_irq (void);

Description

reset_irq resets 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

set_irq

Example

None.

3.116. sdcard_gd_clear

Function

Erase a range of cart-ROM blocks.

Header

lynx/sdcard-gd.h

Declaration

FRESULT __fastcall__ sdcard_gd_clear (unsigned int nStartBlock, unsigned int nBlocks, unsigned char b512BlockCard);

Description

Erases nBlocks cart-ROM blocks starting at nStartBlock, with no source file. Set b512BlockCard non-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 original LynxSD_* names remain as deprecated aliases. See SD / GD flash cart.

Availability

cc65 (Atari Lynx only)

See also

sdcard_gd_program

Example

None.

3.117. sdcard_gd_close

Function

Close the open file.

Header

lynx/sdcard-gd.h

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 original LynxSD_* names remain as deprecated aliases. See SD / GD flash cart.

Availability

cc65 (Atari Lynx only)

See also

sdcard_gd_open

Example

None.

3.118. sdcard_gd_init

Function

Wake the SD/GD cart MCU.

Header

lynx/sdcard-gd.h

Declaration

void sdcard_gd_init (void);

Description

Initialises communication with the cart MCU (sets IODIR to input, sends the $AA magic byte). Call once before any other sdcard_gd_ function.

Notes
  • Part of the RetroHQ SD/GD flash-cart API (lynx/sdcard-gd.h); the original LynxSD_* names remain as deprecated aliases. See SD / GD flash cart.

Availability

cc65 (Atari Lynx only)

See also

sdcard_gd_lowpower

Example

None.

3.119. sdcard_gd_lowpower

Function

Power the SD card down.

Header

lynx/sdcard-gd.h

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 original LynxSD_* names remain as deprecated aliases. See SD / GD flash cart.

Availability

cc65 (Atari Lynx only)

See also

sdcard_gd_init

Example

None.

3.120. sdcard_gd_open

Function

Open a file on the SD card.

Header

lynx/sdcard-gd.h

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 original LynxSD_* names remain as deprecated aliases. See SD / GD flash cart.

Availability

cc65 (Atari Lynx only)

See also

sdcard_gd_close

Example

None.

3.121. sdcard_gd_opendir

Function

Open a directory on the SD card.

Header

lynx/sdcard-gd.h

Declaration

FRESULT __fastcall__ sdcard_gd_opendir (const char* pDir);

Description

Opens the directory at pDir (relative to the card root). Follow with repeated sdcard_gd_readdir calls.

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 original LynxSD_* names remain as deprecated aliases. See SD / GD flash cart.

Availability

cc65 (Atari Lynx only)

See also

sdcard_gd_readdir

Example

None.

3.122. sdcard_gd_program

Function

Program a ROM image into cart ROM.

Header

lynx/sdcard-gd.h

Declaration

FRESULT __fastcall__ sdcard_gd_program (unsigned int nStartBlock, unsigned char nBlockSize, unsigned int nBlockCount, unsigned char b512BlockCard);

Description

Programs nBlockCount blocks of nBlockSize (in 256-byte units: 1/2/4/8) into cart ROM starting at nStartBlock, sourced from the current position of the open file. Set b512BlockCard non-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 original LynxSD_* names remain as deprecated aliases. See SD / GD flash cart.

Availability

cc65 (Atari Lynx only)

See also

sdcard_gd_clear

Example

None.

3.123. sdcard_gd_read

Function

Read bytes from the open file.

Header

lynx/sdcard-gd.h

Declaration

FRESULT __fastcall__ sdcard_gd_read (void* pBuffer, unsigned int nSize);

Description

Reads nSize bytes from the open file into pBuffer. 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 original LynxSD_* names remain as deprecated aliases. See SD / GD flash cart.

Availability

cc65 (Atari Lynx only)

See also

sdcard_gd_write

Example

None.

3.124. sdcard_gd_readdir

Function

Read the next directory entry.

Header

lynx/sdcard-gd.h

Declaration

FRESULT __fastcall__ sdcard_gd_readdir (SFileInfo* pInfo);

Description

Reads the next entry from the directory opened by sdcard_gd_opendir into *pInfo (a 22-byte packed record). Returns FR_OK while 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 original LynxSD_* names remain as deprecated aliases. See SD / GD flash cart.

Availability

cc65 (Atari Lynx only)

See also

sdcard_gd_opendir

Example

None.

3.125. sdcard_gd_seek

Function

Seek within the open file.

Header

lynx/sdcard-gd.h

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 original LynxSD_* names remain as deprecated aliases. See SD / GD flash cart.

Availability

cc65 (Atari Lynx only)

See also

sdcard_gd_size

Example

None.

3.126. sdcard_gd_size

Function

Return the open file's size.

Header

lynx/sdcard-gd.h

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 original LynxSD_* names remain as deprecated aliases. See SD / GD flash cart.

Availability

cc65 (Atari Lynx only)

See also

sdcard_gd_seek

Example

None.

3.127. sdcard_gd_write

Function

Write bytes to the open file.

Header

lynx/sdcard-gd.h

Declaration

FRESULT __fastcall__ sdcard_gd_write (const void* pBuffer, unsigned int nSize);

Description

Writes nSize bytes from pBuffer to 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 original LynxSD_* names remain as deprecated aliases. See SD / GD flash cart.

Availability

cc65 (Atari Lynx only)

See also

sdcard_gd_read

Example

None.

3.128. ser_close

Function

Close the port and disable interrupts

Header

lynx/serial.h

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(&params);
}

3.129. ser_get

Function

Read a character from serial port.

Header

lynx/serial.h

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

lynx/serial.h

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(&params);
}

3.131. ser_put

Function

Write a character to a serial port.

Header

lynx/serial.h

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

lynx/serial.h

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

6502.h

Declaration

void __fastcall__ set_irq (irq_handler f, void *stack_addr, size_t stack_size);

Description

set_irq allows 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 value IRQ_HANDLED if and only if it has verified that the current interrupt request actually stems from that source. In all other cases it must return the value IRQ_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_irq as a part of your clean-up when exiting the program.

Availability

cc65

See also

reset_irq

Example

None.

3.134. setjmp

Function

Save the context for use with longjmp.

Header

setjmp.h

Declaration

int __fastcall__ setjmp (jmp_buf buf);

Description

The setjmp function saves the current context in buf for subsequent use by the longjmp function and returns zero.

Notes
  • The function is only available as fastcall function, so it may only be used in presence of a prototype.

  • setjmp is actually a macro as required by the ISO standard.

  • setjmp will not save the signal context.

Availability

ISO 9899

See also

longjmp

Example

None.

3.135. sleep

Function

Sleep for a specified amount of time.

Header

unistd.h

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

lynx/lynx.h

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

snd_play

Example

None.

3.137. snd_continue

Function

Resume sound after a pause.

Header

lynx/lynx.h

Declaration

void snd_continue (void);

Description

Resumes playback previously suspended with snd_pause.

Notes
Availability

cc65 (Atari Lynx only)

See also

snd_pause

Example

None.

3.138. snd_init

Function

Initialize the sound engine.

Header

lynx/lynx.h

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

snd_play, snd_stop

Example

None.

3.139. snd_pause

Function

Pause sound.

Header

lynx/lynx.h

Declaration

void snd_pause (void);

Description

Suspends playback on all channels. Resume with snd_continue.

Notes
Availability

cc65 (Atari Lynx only)

See also

snd_continue

Example

None.

3.140. snd_play

Function

Play a compiled tune stream on a channel.

Header

lynx/lynx.h

Declaration

void __fastcall__ snd_play (unsigned char channel, const unsigned char* stream);

Description

Starts playing the compiled event stream on channel (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 the abccc tune 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 to snd_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 the SFX_* ca65 macros in asminc/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

snd_stop_channel, snd_active

Example

None.

3.141. snd_stop

Function

Stop sound on all channels.

Header

lynx/lynx.h

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

snd_stop_channel

Example

None.

3.142. snd_stop_channel

Function

Stop sound on one channel.

Header

lynx/lynx.h

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

snd_stop

Example

None.

3.143. snprintf

Function

Format data into a string buffer, with a size limit.

Header

stdio.h

Declaration

int snprintf (char* buf, size_t size, const char* format, ...);

Description

snprintf formats its arguments according to format and writes the result into buf, storing at most size bytes 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 of size or greater indicates that the output was truncated.

Notes
  • The conversions c d i n o p s u x X are supported, together with flags, field width, precision and the h l z t j L length modifiers. Because cc65 has no floating-point support, the floating-point conversions (e E f F g G a A) are not available.

  • If size is zero, nothing is written into buf (which may then be NULL), but the return value is still computed.

  • size must not exceed INT_MAX; a larger value sets errno to ERANGE and returns -1.

Availability

ISO 9899

See also

sprintf, sscanf, vsnprintf, vsprintf

Example

None.

3.144. sprintf

Function

Format data into a string buffer.

Header

stdio.h

Declaration

int sprintf (char* buf, const char* format, ...);

Description

sprintf formats its arguments according to format and writes the result, terminated by a '\0', into buf. It returns the number of characters written, not counting the terminating '\0'.

Notes
  • The conversions c d i n o p s u x X are supported, together with flags, field width, precision and the h l z t j L length 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: buf must be large enough to hold the formatted result. Use snprintf if a bound is required.

  • At most INT_MAX characters can be produced.

Availability

ISO 9899

See also

snprintf, sscanf, vsprintf

Example

None.

3.145. srand

Function

Initialize the pseudo random number generator.

Header

stdlib.h

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 srand has 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

_randomize, rand

Example

None.

3.146. sscanf

Function

Read formatted data from a string.

Header

stdio.h

Declaration

int sscanf (const char* s, const char* format, ...);

Description

sscanf parses the string s according to format and stores the converted values through the pointer arguments that follow. It returns the number of input items successfully matched and assigned, or EOF if an input failure occurs before the first conversion.

Notes
  • The conversions d i u o x X c s p n and the [ character-set scanset are supported, together with assignment suppression (*), a field width and the h l z t j L length 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 set errno to ENOSYS and return EOF.

  • An invalid conversion specification sets errno to EINVAL and returns EOF.

Availability

ISO 9899

See also

snprintf, sprintf, vsscanf

Example

None.

3.147. strcasecmp

Function

Compare two strings case insensitive.

Header

string.h

Declaration

int __fastcall__ strcasecmp (const char* s1, const char* s2);

Description

The strcasecmp function compares the two strings passed as parameters without case sensitivity. It returns a value that is less than zero if s1 is less than s2, zero if s1 is the same as s2, and a value greater than zero if s1 is greater than s2.

Notes
  • The function is only available as fastcall function, so it may only be used in presence of a prototype.

Availability

cc65

See also

strcmp, strcoll, stricmp, strncmp, strxfrm

Example

None.

3.148. strcat

Function

Concatentate two strings.

Header

string.h

Declaration

char* __fastcall__ strcat (char* s1, const char* s2);

Description

The strcat function 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

strcpy, strncat, strncpy

Example

None.

3.149. strchr

Function

Search for a character in a string.

Header

string.h

Declaration

char* __fastcall__ strchr (const char* s, int c);

Description

The strchr function locates the first occurrence of c (converted to a char) in the string pointed to by s. 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

memchr, strrchr

Example

None.

3.150. strcmp

Function

Compare two strings.

Header

string.h

Declaration

int __fastcall__ strcmp (const char* s1, const char* s2);

Description

The strcmp function compares the two strings passed as parameters. It returns a value that is less than zero if s1 is less than s2, zero if s1 is the same as s2, and a value greater than zero if s1 is greater than s2.

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

strcasecmp, strcoll, stricmp, strncmp strxfrm

Example

None.

3.151. strcoll

Function

Compare two strings.

Header

string.h

Declaration

int __fastcall__ strcoll (const char* s1, const char* s2);

Description

The strcoll function compares the two strings passed as parameters, according to the standard character collating sequence (equivalent to strcmp). It returns a value that is less than zero if s1 is less than s2, zero if s1 is the same as s2, and a value greater than zero if s1 is greater than s2.

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

strcasecmp, strcmp, stricmp, strncmp, strxfrm

Example

None.

3.152. strcpy

Function

Copy a string.

Header

string.h

Declaration

char* __fastcall__ strcpy (char* s1, const char* s2);

Description

The strcpy function copies the string pointed to by s2 (including the terminating null byte) into the array pointed to by s1. The function will always return 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

strcat, strncat, strncpy

Example
#include <string.h>

static char hello[14];

strcpy (hello, "Hello world!\n");

3.153. strcspn

Function

Compute the length of a substring.

Header

string.h

Declaration

size_t __fastcall__ strcspn (const char* s, const char* set);

Description

The strcspn function computes and returns the length of the substring pointed to by s which does not consist of characters contained in the string set.

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

strpbrk, strqtok, strspn, strstr, strtok

Example

None.

3.154. strdup

Function

Allocate a copy of a string on the heap.

Header

string.h

Declaration

char* __fastcall__ strdup (const char* s);

Description

strdup allocates a memory block on the heap, big enough to hold a copy of s including the terminating zero. If the allocation fails, NULL is returned, otherwise s is 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

free, malloc

Example

None.

3.155. strerror

Function

Return a string describing an error code.

Header

string.h

Declaration

char* __fastcall__ strerror (int errcode);

Description

The strerror function returns a string describing the given error code. If an invalid error code is passed, the string "Unknown error" is returned, and errno is set to EINVAL. In all other cases, errno is 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

string.h

Declaration

int __fastcall__ stricmp (const char* s1, const char* s2);

Description

The stricmp function compares the two strings passed as parameters without case sensitivity. It returns a value that is less than zero if s1 is less than s2, zero if s1 is the same as s2, and a value greater than zero if s1 is greater than s2.

Notes
  • The function is only available as fastcall function, so it may only be used in presence of a prototype.

Availability

cc65

See also

strcasecmp, strcmp, strcoll, strncmp, strxfrm

Example

None.

3.157. strlen

Function

Return the length of a string.

Header

string.h

Declaration

size_t __fastcall__ strlen (const char* s);

Description

The strlen function 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

strcpy

Example

None.

3.158. strlower

Function

Make a string lower case.

Header

string.h

Declaration

char* __fastcall__ strlower (char* s);

Description

The strlower function will apply the tolower function to each character of a string. The function will always return s.

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

strupper, tolower

Example

None.

3.159. strlwr

See strlower.

3.160. strncasecmp

Function

Compare two strings case insensitive.

Header

string.h

Declaration

int __fastcall__ strncasecmp (const char* s1, const char* s2, size_t count);

Description

The strncasecmp function compares the two strings passed as parameters without case sensitivity. It returns a value that is less than zero if s1 is less than s2, zero if s1 is the same as s2, and a value greater than zero if s1 is greater than s2.

Notes
  • The function is only available as fastcall function, so it may only be used in presence of a prototype.

Availability

cc65

See also

strcmp, strcoll, stricmp, strncmp, strxfrm

Example

None.

3.161. strncat

Function

Concatentate two strings.

Header

string.h

Declaration

char* __fastcall__ strncat (char* s1, const char* s2, size_t n);

Description

The strncat function 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

strcpy, strncat, strncpy

Example

None.

3.162. strncmp

Function

Compare two strings.

Header

string.h

Declaration

int __fastcall__ strncmp (const char* s1, const char* s2, size_t count);

Description

The strncmp function compares not more than count characters of the two strings passed as parameters. It returns a value that is less than zero if the first count characters of s1 are less than s2, 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

strcasecmp, strcmp, strcoll, stricmp, strxfrm

Example

None.

3.163. strncpy

Function

Copy part of a string.

Header

string.h

Declaration

char* __fastcall__ strncpy (char* s1, const char* s2, size_t n);

Description

The strncpy function copies not more than n bytes from the array pointed to by s2 to the array pointed to by s1. If the array pointed to by s2 is a string that is shorter than n bytes, null bytes are appended to the copy in the array pointed to by s1, until n bytes are written. The function always will return s1.

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 n bytes of the array pointed to by s2, the result is not null-terminated!

  • If copying takes place between objects that overlap, the behaviour is undefined.

Availability

ISO 9899

See also

memcpy, strcat, strcpy, strncat

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

string.h

Declaration

int __fastcall__ strnicmp (const char* s1, const char* s2, size_t count);

Description

The strnicmp function compares the two strings passed as parameters without case sensitivity. It returns a value that is less than zero if s1 is less than s2, zero if s1 is the same as s2, and a value greater than zero if s1 is greater than s2.

Notes
  • The function is only available as fastcall function, so it may only be used in presence of a prototype.

Availability

cc65

See also

strcasecmp, strcmp, strcoll, strncmp, strxfrm

Example

None.

3.165. strpbrk

Function

Find a character in a string, from a set of characters.

Header

string.h

Declaration

char* __fastcall__ strpbrk (const char* str, const char* set);

Description

strpbrk() searches within str for the first occurance of any character from set. It returns a pointer to that character if found; otherwise, it returns NULL.

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

strchr, strcspn, strqtok, strspn, strtok

Example

None.

3.166. strqtok

Function

Break a string into tokens.

Header

string.h

Declaration

char* __fastcall__ strqtok (char* s1, const char* s2);

Description

strqtok() will break the string s1 into a sequence of tokens, which are delimited by either quotation marks or characters from the string s2. Tokens inside quotation marks may contain characters from s2 (they aren't delimiters there). The first call to strqtok() will return a pointer to the first token in the string s1. The following calls must pass a NULL pointer as s1, in order to get the next token in the string. Different sets of delimiters may be used for the subsequent calls to strqtok().

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 string s1.

  • The function will forget where it is in the s1 string if it is given a second s1 string before it finishes the first one.

Availability

cc65

See also

strcspn, strpbrk, strspn, strtok

Example

None.

3.167. strrchr

Function

Search for a character in a string.

Header

string.h

Declaration

char* __fastcall__ strrchr (const char* s, int c);

Description

The strrchr function locates the last occurrence of c (converted to a char) in the string pointed to by s. 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

strchr

Example

None.

3.168. strspn

Function

Compute the length of a substring.

Header

string.h

Declaration

size_t __fastcall__ strspn (const char* s, const char* set);

Description

The strspn function computes and returns the length of the substring pointed to by s which does consist only of characters contained in the string set.

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

strcspn, strpbrk, strstr

Example

None.

3.169. strstr

Function

Find a substring.

Header

string.h

Declaration

char* __fastcall__ strstr (const char* str, const char* substr);

Description

strstr searches for the first occurance of the string substr within str. If found, it returns a pointer to the copy, otherwise it returns NULL.

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

strcspn, strspn

Example

None.

3.170. strtok

Function

Break a string into tokens.

Header

string.h

Declaration

char* __fastcall__ strtok (char* s1, const char* s2);

Description

strtok() will break the string s1 into a sequence of tokens, which are delimited by characters from the string s2. The first call to strtok() will return a pointer to the first token in the string s1. The following calls must pass a NULL pointer as s1, in order to get the next token in the string. Different sets of delimiters may be used for the subsequent calls to strtok().

Notes
  • The function is only available as fastcall function, so it may only be used in presence of a prototype.

  • strtok() will modify the string s1.

  • The function will forget where it is in the s1 string if it is given a second s1 string before it finishes the first one.

Availability

ISO 9899

See also

strcspn, strpbrk, strqtok, strspn

Example

None.

3.171. strupper

Function

Make a string upper case.

Header

string.h

Declaration

char* __fastcall__ strupper (char* s);

Description

The strupper function will apply the toupper function to each character of a string. The function will always return s.

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

strlower toupper

Example

None.

3.172. strupr

See strupper.

3.173. strxfrm

Function

Transform a string.

Header

string.h

Declaration

size_t __fastcall__ strxfrm (char* s1, const char* s2, size_t n);

Description

The strxfrm function 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 the strcmp function is applied to two transformed strings, it returns a value greater than, equal to, or less than zero, corresponding to the result of the strcoll function 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
  • s1 and s2 must not point to the same memory area, otherwise the behaviour is undefined.

  • If n is zero, s1 may 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, strxfrm will just copy s2 to s1 using strncpy.

Availability

ISO 9899

See also

strcmp, strcoll, strncpy

Example

None.

3.174. suzy_div_result

Function

Harvest the result of an asynchronous signed Suzy divide.

Header

lynx/suzymath.h

Declaration

int __fastcall__ suzy_div_result (void);

Description

Returns the signed quotient of the divide started by suzy_div_start and 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_start and 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

suzy_div_start, suzy_udiv_result, suzy_math_busy

3.175. suzy_div_start

Function

Begin an asynchronous signed Suzy divide.

Header

lynx/suzymath.h

Declaration

void __fastcall__ suzy_div_start (int n, int d);

Description

Writes the operands for the signed divide n / d into 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 with suzy_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

suzy_div_result, suzy_udiv_start, suzy_math_busy

3.176. suzy_math_busy

Function

Test whether the Suzy math unit is still computing.

Header

lynx/suzymath.h

Declaration

unsigned char suzy_math_busy (void);

Description

Returns nonzero while an asynchronous Suzy operation is still in progress (the MATHWORKING bit, bit 7 of SPRSYS at $FC92), and zero once the result is ready. Use it to decide whether worthwhile interleaved work remains before harvesting; the *_result routines 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

suzy_udiv_start, suzy_udiv_result

3.177. suzy_mod_result

Function

Harvest the result of an asynchronous signed Suzy modulo.

Header

lynx/suzymath.h

Declaration

int __fastcall__ suzy_mod_result (void);

Description

Polls the overlapped divide to completion, then runs the short (n/d)*d multiply and subtract that finish the modulo and returns n % d with 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_start and 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

suzy_mod_start, suzy_umod_result

3.178. suzy_mod_start

Function

Begin an asynchronous signed Suzy modulo.

Header

lynx/suzymath.h

Declaration

void __fastcall__ suzy_mod_start (int n, int d);

Description

Saves n and d, records the sign-fixup state and starts the divide that the modulo is built on, then returns immediately. The remainder is computed as n - (n/d)*d; the divide overlaps your interleaved work and the rest is finished by suzy_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

suzy_mod_result, suzy_umod_start

3.179. suzy_mul_result

Function

Harvest the result of an asynchronous Suzy multiply (signed alias).

Header

lynx/suzymath.h

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

suzy_mul_start, suzy_umul_result

3.180. suzy_mul_start

Function

Begin an asynchronous Suzy multiply (signed alias).

Header

lynx/suzymath.h

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 as int; 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

suzy_mul_result, suzy_umul_start

3.181. suzy_muldiv_result

Function

Harvest the result of an asynchronous signed Suzy fused multiply-divide.

Header

lynx/suzymath.h

Declaration

int __fastcall__ suzy_muldiv_result (void);

Description

Polls the overlapped divide to completion and returns the 16-bit signed quotient of (a*b)/c with 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

suzy_muldiv_start, suzy_umuldiv_result

3.182. suzy_muldiv_start

Function

Begin an asynchronous signed Suzy fused multiply-divide.

Header

lynx/suzymath.h

Declaration

void __fastcall__ suzy_muldiv_start (int a, int b, int c);

Description

Computes (a*b)/c in 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 with suzy_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

suzy_muldiv_result, suzy_umuldiv_start

3.183. suzy_udiv_result

Function

Harvest the result of an asynchronous unsigned Suzy divide.

Header

lynx/suzymath.h

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_start and 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

suzy_udiv_start, suzy_div_result, suzy_math_busy

3.184. suzy_udiv_start

Function

Begin an asynchronous unsigned Suzy divide.

Header

lynx/suzymath.h

Declaration

void __fastcall__ suzy_udiv_start (unsigned n, unsigned d);

Description

Writes the operands for the unsigned divide n / d into 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 with suzy_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

suzy_udiv_result, suzy_div_start, suzy_math_busy

3.185. suzy_umod_result

Function

Harvest the result of an asynchronous unsigned Suzy modulo.

Header

lynx/suzymath.h

Declaration

unsigned __fastcall__ suzy_umod_result (void);

Description

Polls the overlapped divide to completion, then runs the short (n/d)*d multiply and subtract and returns n % 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_start and 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

suzy_umod_start, suzy_mod_result

3.186. suzy_umod_start

Function

Begin an asynchronous unsigned Suzy modulo.

Header

lynx/suzymath.h

Declaration

void __fastcall__ suzy_umod_start (unsigned n, unsigned d);

Description

Saves n and d and starts the divide that the modulo is built on, then returns immediately. The remainder is computed as n - (n/d)*d; the divide overlaps your interleaved work and the rest is finished by suzy_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

suzy_umod_result, suzy_mod_start

3.187. suzy_umul_result

Function

Harvest the result of an asynchronous unsigned Suzy multiply.

Header

lynx/suzymath.h

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 why suzy_mul_result is 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

suzy_umul_start, suzy_mul_result

3.188. suzy_umul_start

Function

Begin an asynchronous unsigned Suzy multiply.

Header

lynx/suzymath.h

Declaration

void __fastcall__ suzy_umul_start (unsigned a, unsigned b);

Description

Writes the factors a and b, triggers the hardware multiply and returns immediately; harvest the low 16 bits with suzy_umul_result. Suzy's SIGNMATH mode 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

suzy_umul_result, suzy_mul_start

3.189. suzy_umuldiv_result

Function

Harvest the result of an asynchronous unsigned Suzy fused multiply-divide.

Header

lynx/suzymath.h

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

suzy_umuldiv_start, suzy_muldiv_result

3.190. suzy_umuldiv_start

Function

Begin an asynchronous unsigned Suzy fused multiply-divide.

Header

lynx/suzymath.h

Declaration

void __fastcall__ suzy_umuldiv_start (unsigned a, unsigned b, unsigned c);

Description

Computes (a*b)/c in 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 with suzy_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

suzy_umuldiv_result, suzy_muldiv_start

3.191. tolower

Function

Convert a character into its lower case representation.

Header

ctype.h

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

islower, isupper, toupper

Example

None.

3.192. toupper

Function

Convert a character into its upper case representation.

Header

ctype.h

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

islower, isupper, tolower

Example

None.

3.193. ultoa

Function

Convert an unsigned long integer into a string.

Header

stdlib.h

Declaration

char* __fastcall__ ultoa (unsigned long val, char* buf, int radix);

Description

itoa converts the unsigned long integer val into a string using radix as 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

atoi, atol, itoa, ltoa, utoa

Example

None.

3.194. utoa

Function

Convert an unsigned integer into a string.

Header

stdlib.h

Declaration

char* __fastcall__ utoa (unsigned val, char* buf, int radix);

Description

itoa converts the unsigned integer val into a string using radix as 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

atoi, atol, itoa, ltoa, ultoa

Example

None.

3.195. vsnprintf

Function

Format data into a string buffer, with a size limit, from a va_list.

Header

stdio.h

Declaration

int __fastcall__ vsnprintf (char* buf, size_t size, const char* format, va_list ap);

Description

vsnprintf works exactly like snprintf, except that the variable arguments are taken from the va_list ap instead of from a variable argument list.

Notes
  • The conversions c d i n o p s u x X are supported, together with flags, field width, precision and the h l z t j L length 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

snprintf, vsprintf, vsscanf

Example

None.

3.196. vsprintf

Function

Format data into a string buffer, from a va_list.

Header

stdio.h

Declaration

int __fastcall__ vsprintf (char* buf, const char* format, va_list ap);

Description

vsprintf works exactly like sprintf, except that the variable arguments are taken from the va_list ap instead of from a variable argument list.

Notes
  • The conversions c d i n o p s u x X are supported, together with flags, field width, precision and the h l z t j L length 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

sprintf, vsnprintf, vsscanf

Example

None.

3.197. vsscanf

Function

Read formatted data from a string, into a va_list.

Header

stdio.h

Declaration

int __fastcall__ vsscanf (const char* s, const char* format, va_list ap);

Description

vsscanf works exactly like sscanf, except that the pointer arguments are taken from the va_list ap instead 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

sprintf, sscanf, vsnprintf

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.

  • system and the non-standard exec: the Lynx has no shell or command processor. To run another cart image, use lynx_load/lynx_exec from <lynx/lynx.h>.

  • All functions that handle floating-point numbers in some manner.

  • The ldiv function (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 SIGSEGV would 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 the time function is not available. The other functions from <time.h> are available.

  • exit, abort and atexit: there is no host to return to, so the Lynx has no public exit() and the runtime runs no teardown (hence no atexit either). Return from main() to terminate; the runtime's internal trap then just masks interrupts and halts the machine. (The non-standard doesclrscrafterexit is 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.

  • _stroserror and the _DE_ISREG/_DE_ISDIR/_DE_ISLBL/_DE_ISLNK directory-entry macros: leftovers of the mapped-errno and directory-stream machinery, neither of which exists on the cart. strerror and struct dirent remain.

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 FILE object, 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/fputs and perror — 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/fflush and fdopen/fileno. For on-screen text use gfx_outtext from <lynx/gfx.h>.

  • The only <stdio.h> functions that remain are the in-RAM string routines: sprintf/snprintf (and vsprintf/vsnprintf) format into a buffer, and sscanf (and vsscanf) 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, and sscanf additionally rejects the wide-character conversions (S C). To stream raw bytes from the cart, use read()/lseek() on a handle from openn() (see <unistd.h> and <lynx/lynx.h>).

  • remove/rename and the name-based open/creat/close/write are 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 strlen function works for only strings with a maximum length of 255 characters.

  • The isXXX character 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).