Atari Lynx Library Reference

Note: All content on this page is from www.monlynx.de/lynx, before it was taken down.

C Library Functions

Lynx Library Functions

Predefined Macros

 

  • C-library functions:

    Please add :
    #include <stdlib.h>
    to your C-source.
    memset
    isalnum isalpha isascii isatty iscntrl iscons
    isdigit isgraph islower isodigit isprint ispunct
    isspace isupper iswhite isxdigit

    atoi

      int atoi(char *s);

    atoib

      int atoib(char *s, int b);

    dtoi

      int dtoi(char *decstr, int *nbr);

    utoi

      int utoi(char *decstr,int *nbr);

    otoi

      int otoi(char *octstr, int *nbr);

    xtoi

      int xtoi(char *hexstr, int *nbr);

    itoa

      void itoa(int n, char * pstr);

    itoab

      void itoab(int n, char *s, int b);

    itod

      char * itod(int nbr, char str[], int sz);

    itoo

      char * itoo(int nbr, char str[], int sz);

    itou

      char * itou(int nbr, char str[], int sz);

    itox

      char * itox(int nbr, char str[], int sz);

    bcopy

      void bcopy(char *pSrc, char *pDest, int num);

    bzero

      int bzero(char * ptr, int nbytes);

    memset

      void memset(char *pMem, char ch, int num);
      Fills a memory-area (num bytes from address pMem) with the given byte-value ch.

    reverse

      void reverse(char *s);

    strcat

      void strcat(char * str1,char * str2);

    strchr

      char * strchr(char * str, int chr);

    strcmp

      int strcmp(char *s, char *t);

    toascii

      int toascii(int c);

    tolower

      int tolower(int c);

    toupper

      int toupper(int c);

    is-family

      Syntax
        int isalnum( int c );
        int isalpha( int c );
        int isascii( int c );
        int isatty( int c );
        int iscntrl( int c );
        int iscons( int c );
        int isdigit( int c );
        int isgraph( int c );
        int islower( int c );
        int isodigit( int c );
        int isprint( int c );
        int ispunct( int c );
        int isspace( int c );
        int isupper( int c );
        int isxdigit( int c );
        int iswhite( int c );
      Parameter Description
        c: Integer to be tested

      Each function in the is family tests a given integer value, returning a nonzero value if the integer satisfies the test condition and 0 if it does not. The ASCII character set is assumed.

      The is functions and their test conditions are listed below:


        Function

        Test Condition
        isalnum Alphanumeric ('A'-'Z', 'a'-'z', or '0'-'9')
        isalpha Letter ('A'-'Z' or 'a'-'z')
        isascii ASCII character (0x00 - 0x7F)
        isatty c is a device
        iscntrl Control character (0x00 - 0x1F or 0x7F)
        iscons c is the console device
        isdigit Digit ('0'-'9')
        isgraph Printable character except space (0x21 - 0x7E)
        islower Lowercase letter ('a'-'z')
        isodigit Octal digit ('0'-'7')
        isprint Printable character (0x20 - 0x7E)
        ispunct Punctuation character (all but alphanumeric and control characters)
        isspace White-space character (0x09 - 0x0D or 0x20)
        isupper Uppercase letter ('A'-'Z')
        iswhite c <= 0x20, c >= 0x7F
        isxdigit Hexadecimal digit ('A'-'F','a'-'f', or '0'-'9')

        The isascii routine produces meaningful results for all integer values. However, the remaining routines produce a defined result only for integer values corresponding to the ASCII character set (that is, only where isascii holds true).

      Return Value

        These routines return a nonzero value if the integer satisfies the test condition and 0 if it does not.

         


    HOME
    (c) M. Domin and Bastian Schick
    last modified 1998/01/28

     

     

     

    LYNX-library functions:

    Please add :
    #include <lynxlib.h>
    to your C-source.
    BCDAdd BCDAddConst BCDSub BCDSubConst BCDToASCII
    DrawFBox DrawLine GetPixel SetPixel DrawSprite
    EE_Erase EE_Read EE_Write
    Flip SetBuffers SwapBuffers
    SetRGB random
    InitIRQ InstallIRQ DeInstallIRQ InstallUploader
    TextOut TextOutExt
    SmpInit SmpStart SmpStop SmpActive

    BCDAdd

      int BCDAdd(BCD *pBCDVal1, BCD *pBCDVal2);
      Returns the sum of the addition of the BCD-value pointed to by pBCDVal1 and the BCD-value pointed to by pBCDVal2.
      The BCD-values can be stored in normal integer-variables.

    BCDAddConst

      int BCDAddConst(BCD *pBCDVal1, BCD BCDVal2);
      Returns the sum of the addition of the BCD-constant BCDVal2 and the BCD-value pointed to by pBCDVal1.
      The BCD-values can be stored in normal integer-variables.

    BCDSub

      int BCDSub(BCD *pBCDVal1, BCD *pBCDVal2);
      Returns the sum of the subtraction of the BCD-value pointed to by pBCDVal2 from the BCD-value pointed to by pBCDVal1.
      The BCD-values can be stored in normal integer-variables.

    BCDSubConst

      int BCDSubConst(BCD *pBCDVal1, BCD BCDVal2);
      Returns the sum of the subtraction of the BCD-constant BCDVal2 from the BCD-value pointed to by pBCDVal1.
      The BCD-values can be stored in normal integer-variables.

    BCDToASCII

      void BCDToASCII(BCD *pBCDVal, char *pText);
      Converts the BCD-value pointed to by pBCDVal into four ASCII-characters at the location pointed to by pText.
      It does not append a trailing zero!

    DrawFBox

      void DrawFBox(int x, int y, int width, int height, char col);
      Draws a filled box with width width and height height at pixel position x,y.
      The colour index col is used to fill the box.

    DrawLine

      void DrawLine(int x1, int y1, int x2, int y2, char col);
      Draws a line from x1,y1 to x2,y2 in colour col.

    GetPixel

      char GetPixel(char x, char y);
      Returns the colour index of the pixel at position x,y.

    SetPixel

      void SetPixel(int x, int y, char col);
      Sets the pixel at the position x,y to the colour index col.

    DrawSprite

      void DrawSprite(char *pSCB);
      Draws a sprite (defined through the SpriteControlBlock at pSCB) into the render buffer.
      See Chapter 6.4: Sprite Data Structure for a description.

    EE_Erase

      void EE_Erase(char cell);
      Erases the given EEPROM-cell.

    EE_Read

      int EE_Read(char cell);
      Reads the contents of a given EEPROM-cell.

    EE_Write

      void EE_Write(char cell, int value);
      Writes the integer value to a given EEPROM-cell.

    Flip

      void Flip();
      Changes the orientation of the screen and of the joypad buttons.

    SetBuffers

      void SetBuffers(char * pScreen, char * pRender, char *pCollide);
      Sets the address of the current screen to pScreen and (to allow double-buffering) the address of the rendering-buffer to pRender.
      If you don't want double-buffering you can set pRender to 0.
      If you want to use collision-detection, you can set pCollide to the address of the collision-buffer, else set it to 0.

      All three addresses should point to arrays of 8160 bytes, aligned to a 4 byte border.

    SwapBuffers

      void SwapBuffers();
      Swaps the addresses of the rendering and the current screen buffer.

    SetRGB

      void SetRGB(char * pPalette);
      Sets the colour palette to the 16 RGB values pointed to by pPalette.
      32 bytes are representing the new palette:
      GREEN0, GREEN1, ... GREENE, GREENF, BLUERED0, BLUERED1, ... , BLUEREDE, BLUEREDF
      See Hardware addresses FDA0-FDBF.

    random

      int random();
      Returns a random number out of 0..32767.

    InitIRQ

      void InitIRQ();
      Initializes an IRQ-handler. It is needed by the 3 following routines, so use it first.

    InstallIRQ

      void InstallIRQ(int num, int (* funptr)() );
      Point interrupt num (0 .. 7) to funptr. This routine does not enable the interrupt.

    DeInstallIRQ

      void DeInstallIRQ(int num);
      Set interrupt num back to a dummy-ISR, which simply returns. It does not disable the specific Interrupt.

    Example:

    ...     InitIRQ();	    /* now we may use IRQs */     Install(0,HBL);  /* HBL is called every horizontal line interrupt */     EnableIRQ(0);    /* use a macro defined in lynxlib.h */     CLI;             /* another macro */  ...  

    InstallUploader

      void InstallUploader (char divider);
      This installs a ComLynx-uploader like the BLL-loader.The baudrate is set to 1MHz/16/(divider+1) with the same format :8E1.
      lynxlib.h contains #defines:
      • _62500Bd
      • _31250Bd
      • _9600Bd
      Note:Do not call prior to InitIRQ !

    TextOut

      void TextOut(int x, int y, char forecol, char backcol, char *pText);
      Prints up to 20 characters from the address pointed to by pText at the pixel-position x,y with the foreground colour index forecol and the background colour index backcol. If backcol = 0, the text is printed in transparency-mode.

      At the moment there is only one font with height of 11 pixels and width of 8 pixels.

      There is always a 11*8 pixel block of backcol-pixels appended to the text.

    TextOutExt

      void TextOutExt(int x, int y, char forecol, char backcol, char *pText, int stretchx, int stretchy);
      Prints up to 20 characters from the address pointed to by pText at the pixel-position x,y with the foreground colour index forecol and the background colour index backcol. If backcol = 0, the text is printed in transparency-mode.
      stretchx is used to stretch the horizontal text-dimension and stretchy is used to stretch the vertical text-dimension.

      At the moment there is only one font with height of 11 pixels and width of 8 pixels.

      There is always a 11*8 pixel block of backcol-pixels appended to the text.

    SmpInit

      void SmpInit(char channel,char timer);

      Initialize the sample-player.
      channel is the desired audio-channel (0..3)
      timer is the timer-number (0..7, 4 should not be used, 0 and 2 make no sense)

    SmpStart

      void SmpStart(char *sample);

      sample is a pointer to a signed sample-header. To convert WAV samples use wav2lsf.
      The sample - header is defined like this

      struct {    char unpacked;    char lenhi;    char lenlo;    char divider;    char stereo;    char data[len];  }sample;  

    SmpStop

      void SmpStop();

      Stop the current sample.No need to call this function before SmpStart !

      Tip: To halt the sample e.g. during pause:

      void MyPause()  {    int sample;      if ( (sample = SmpActive()) ) // Note : "=" is correct here !!      DisableIRQ(my_smp_timer);    // do some other stuff.  // ...  // now leaving MyPause    if ( sample )      EnableIRQ(my_smp_timer);  }  

    SmpActive

      int SmpActive();

      Returns TRUE if a sample is playing.


    HOME
    (c) M. Domin and Bastian Schick
    last modified 1998/01/28

     

    Predefined Macros

     

    lynx.h

    1. uchar and uint In most case unsigned variables are ok, for these case, I found uchar or uint more convinient.

    2. POKE(char *,char) and POKEW(int *,int)
      Use these macros only to store data in unusual places. Don't use them for hardware-addresse. Use the defined names instead.

    3. PEEK(addr)
      Read a byte from addr. Don't use this for hardware-addresses !

    4. SCB-macros
      SCB * is a pointer to a SpriteCcontrolBlock.
      • SCBCTL0(SCB *)
      • SCBCTL1(SCB *)
      • SCBCOLL(SCB *)
      • SCBNEXT(SCB *)
      • SCBDATA(SCB *)
      • SCBX(SCB *)
      • SCBY(SCB *)
      • SCBH(SCB *)
      • SCBV(SCB *)
      Example
         SCBX(my_sprite) = 10;     SCBNEXT(cls) = my_sprite;  
      Note:Do not define a scb as struct, it is a horrible waste of space due to the way cc65 treats structs.

    5. CLI and SEI
      Clear or set the interrupt-disable bit in the 65SC02-P register.

    6. EnableIRQ(num) and DisableIRQ(num)
      Enable/Disable the timer-interrupt of timer num. (Set/clear bit 7 in timctl0).

    7. BRK(num)
      Insert a 65SC02-brk #num command.

    8. _SetRGB(pal)
      Inline version of SetRGB.
    9. WAITSUZY
      Waits until Suzy is finished.
    10. _POKE(addr,val) and POKEW(addr,val)
      Special versions of POKE and POKEW.
      addr and val must be either a constant value or a global static variable.

    lynxlib.h

    1. _62500Bd,_31250Bd and _9600Bd
      Reload-values for the serial-timer.

    2. IRQ_ENTRY and IRQ_EXIT
      These macros are needed if and irq-routine uses C.
      IRQ routines must not use register variables.
      IRQ_ENTRY must be before any declaration of auto-variables !
      Example
      void MyTimer() interrupt // don't forget this key-word !!  {    static hello; // this is ok    IRQ_ENTRY;    // set up for C    {             // start a new compound, so that we might use auto-variables    int a,b,c;    // now we can do what ever we want      //...    }    IRQ_EXIT;     // no C beyond this point !!!  }  

    HOME
    (c) Bastian Schick
    last modified 1998/01/24

     

     

  • .