From: gpcec@westminster.ac.uk (Tom Kirby-Green)
Newsgroups: comp.sys.acorn
Subject: Sprite plotting in C...
Date: 30 Sep 92 10:26:18 GMT
Organization: University of Westminster

Folks,
        Many thanks to those who answered my question about !Edit and C
printed tab chars ( turns out !Edit expands tabs to spaces - yuk ). Would
some kind soul kindly point out which tree I'm barking up with the code
below. I know the sprite area is set up ok, 'cause I can't save it back 
under a new name and it produces a perfect copy of the sprite file. I
suspect its the bit where I get a pointer to the sprite.
        For information. The sprite file is in the project directoy,
"$.User.sprites", it's called "button", and contains a single
34*17 mode 12 sprite called "plain", with palette AND mask.
        Like I said - all seems well until I get the address...

        Many thanks to anyone who can 'elp on this one;

                Just trying to be, Tom.

        P.S. I DON'T want to use Acorn's RISC_OSLib "sprites.h" calls.

-----------------X---- snip snip, C source follows ----X-------------------

#include "kernel.h"
#include "swis.h"

#include <stdio.h>
#include <stdlib.h>

typedef int word;
        _kernel_swi_regs in_regs, out_regs;
        _kernel_oserror  kernel_os_err;

static void check_os_err ( _kernel_oserror *e ) {
        if ( e->errnum > 0 ) {
                fprintf ( stderr, "no %i : %s\n", e->errnum, e->errmess );
                exit ( -1 ); }
}

int main ( int argc, char *argv [] )
{
#define AREA_SIZE 4096
#define MAX_NAME 12

        int *area, addr;
        char name [MAX_NAME];

        area = calloc ( AREA_SIZE, sizeof ( char ));
        area [0] = AREA_SIZE;
        area [8] = 16;
/* init' sprite area */
        in_regs.r [0] = 256 + 9;
        in_regs.r [1] = (int) area;
        kernel_os_err = *_kernel_swi ( OS_SpriteOp, &in_regs, &out_regs );
        check_os_err ( &kernel_os_err );
/* load sprite file */
        in_regs.r [0] = 256 + 10;
        in_regs.r [1] = (int) area;
        in_regs.r [2] = (int) "$.User.sprites.button";
        kernel_os_err = *_kernel_swi ( OS_SpriteOp, &in_regs, &out_regs );
        check_os_err ( &kernel_os_err );
/* return sprite name */
        in_regs.r [0] = 256 + 13;
        in_regs.r [1] = (int) area;
        in_regs.r [2] = (int) name;
        in_regs.r [3] = MAX_NAME;
        in_regs.r [4] = 1;
        kernel_os_err = *_kernel_swi ( OS_SpriteOp, &in_regs, &out_regs );
        check_os_err ( &kernel_os_err );
        printf ( "sprite name : <%s>\n", name );
/* get pointer to sprite */
        in_regs.r [0] = 256 + 14;
        in_regs.r [1] = (int) area;
        in_regs.r [2] = (int) name;
        in_regs.r [3] = 1;              /* include palette */
        kernel_os_err = *_kernel_swi ( OS_SpriteOp, &in_regs, &out_regs );
        check_os_err ( &kernel_os_err );
        addr = out_regs.r [2];
/* plot sprite */
        in_regs.r [0] = 512 + 34;
        in_regs.r [1] = (int) area;
        in_regs.r [2] = (int) addr;
        in_regs.r [3] = 500;
        in_regs.r [4] = 500;
        in_regs.r [5] = 0;
        kernel_os_err = *_kernel_swi ( OS_SpriteOp, &in_regs, &out_regs );
        check_os_err ( &kernel_os_err );
}

--------------------X--- here end'th the C --------X-----------------------

-- 
/---------------------| The University of Westminster |---------------------\
| Tom Kirby-Green           Email : gpcec@sun.pcl.ac.uk  or  Silence@Arcade |
\-------------| "All science is physics, or stamp collecting" |-------------/