~z88dk-team/z88dk-pkg/trunk

« back to all changes in this revision

Viewing changes to libsrc/sprites/software/sp1/spectrum/examples/ex1.c

  • Committer: Bazaar Package Importer
  • Author(s): Krystian Wlosek, Krystian Wlosek
  • Date: 2008-03-25 11:46:11 UTC
  • mfrom: (1.1.2 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080325114611-u89smn2ccknl8avt
Tags: 1.8.ds1-2
[ Krystian Wlosek ]
* Enable 64bit architecture.
* Added '-m32' switch to CFLAGS and LDFLAGS for 64bit machines.
* Changed Architecture: to `any' in z88dk and z88dk-bin package.
* Added gcc-multilib to Build-Depends: for 64bit
* Fixed problem with x11.lib
  - created symlink from include/x11 to include/X11
  - improved Makefile for x11.lib
    patch debian/patches/03_libsrc_graphics_x11_Makefile.diff
* Fixed library ozansi.lib
  - patch debian/patches/03_libsrc_oz_ozinput_Makefile.diff
* Changed Copyright notice.
* Fixed gcc warnings:
  - in src/appmake dir - debian/patches/04_src_appmake.diff
  - in src/zcc/zcc.c - debian/patches/04_src_zcc_zcc.c.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/////////////////////////////////////////////////////////////
 
3
// EXAMPLE PROGRAM #1
 
4
// 04.2006 aralbrec
 
5
//
 
6
// Ten software-rotated masked sprites move in straight lines
 
7
// at various speeds, bouncing off screen edges.  All ten
 
8
// share the same sprite graphic which is not animated in
 
9
// this first test program.
 
10
/////////////////////////////////////////////////////////////
 
11
 
 
12
// zcc +zx -vn ex1.c -o ex1.bin -create-app -lsp1 -lmalloc
 
13
 
 
14
#include <sprites/sp1.h>
 
15
#include <malloc.h>
 
16
#include <spectrum.h>
 
17
 
 
18
#pragma output STACKPTR=53248                    // place stack at $d000 at startup
 
19
long heap;                                       // malloc's heap pointer
 
20
 
 
21
 
 
22
// Memory Allocation Policy
 
23
 
 
24
void *u_malloc(uint size) {
 
25
   return malloc(size);
 
26
}
 
27
 
 
28
void u_free(void *addr) {
 
29
    free(addr);
 
30
}
 
31
 
 
32
// Clipping Rectangle for Sprites
 
33
 
 
34
struct sp1_Rect cr = {0, 0, 32, 24};             // full screen
 
35
 
 
36
// Table Holding Movement Data for Each Sprite
 
37
 
 
38
struct sprentry {
 
39
   struct sp1_ss  *s;                            // sprite handle returned by sp1_CreateSpr()
 
40
   char           dx;                            // signed horizontal speed in pixels
 
41
   char           dy;                            // signed vertical speed in pixels
 
42
};
 
43
 
 
44
struct sprentry sprtbl[] = {
 
45
   {0,1,0}, {0,0,1}, {0,1,2}, {0,2,1}, {0,1,3},
 
46
   {0,3,1}, {0,2,3}, {0,3,2}, {0,1,1}, {0,2,2}
 
47
};
 
48
 
 
49
// A Hashed UDG for Background
 
50
 
 
51
uchar hash[] = {0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa};
 
52
 
 
53
// Attach C Variable to Sprite Graphics Declared in ASM at End of File
 
54
 
 
55
extern uchar gr_window[];
 
56
 
 
57
main()
 
58
{
 
59
   uchar i;
 
60
   struct sp1_ss *s;
 
61
   struct sprentry *se;
 
62
   void *temp;
 
63
   
 
64
   #asm
 
65
   di
 
66
   #endasm
 
67
 
 
68
   // Initialize MALLOC.LIB
 
69
   
 
70
   heap = 0L;                  // heap is empty
 
71
   sbrk(40000, 10000);         // make available memory from 40000-49999
 
72
   
 
73
   // Initialize SP1.LIB
 
74
   
 
75
   zx_border(BLACK);
 
76
   sp1_Initialize(SP1_IFLAG_MAKE_ROTTBL | SP1_IFLAG_OVERWRITE_TILES | SP1_IFLAG_OVERWRITE_DFILE, INK_BLACK | PAPER_WHITE, ' ');
 
77
   sp1_TileEntry(' ', hash);   // redefine graphic associated with space character
 
78
 
 
79
   sp1_Invalidate(&cr);        // invalidate entire screen so that it is all initially drawn
 
80
   sp1_UpdateNow();            // draw screen area managed by sp1 now
 
81
   
 
82
   // Create Ten Masked Software-Rotated Sprites
 
83
   
 
84
   for (i=0; i!=10; i++) {
 
85
 
 
86
      s = sprtbl[i].s = sp1_CreateSpr(SP1_DRAW_MASK2LB, SP1_TYPE_2BYTE, 3, 0, i);
 
87
      sp1_AddColSpr(s, SP1_DRAW_MASK2, 0, 48, i);
 
88
      sp1_AddColSpr(s, SP1_DRAW_MASK2RB, 0, 0, i);
 
89
      sp1_MoveSprAbs(s, &cr, gr_window, 10, 14, 0, 4);
 
90
 
 
91
   };
 
92
   
 
93
   while (1) {                                  // main loop
 
94
   
 
95
      sp1_UpdateNow();                          // draw screen now
 
96
      
 
97
      for (i=0; i!=10; i++) {                    // move all sprites
 
98
 
 
99
         se = &sprtbl[i];
 
100
         
 
101
         sp1_MoveSprRel(se->s, &cr, 0, 0, 0, se->dy, se->dx);
 
102
         
 
103
         if (se->s->row > 21)                    // if sprite went off screen, reverse direction
 
104
            se->dy = - se->dy;
 
105
            
 
106
         if (se->s->col > 29)                    // notice if coord moves less than 0, it becomes
 
107
            se->dx = - se->dx;                   //   255 which is also caught by these cases
 
108
 
 
109
      }
 
110
      
 
111
   }  // end main loop
 
112
 
 
113
}
 
114
 
 
115
#asm
 
116
 
 
117
   defb @11111111, @00000000
 
118
   defb @11111111, @00000000
 
119
   defb @11111111, @00000000
 
120
   defb @11111111, @00000000
 
121
   defb @11111111, @00000000
 
122
   defb @11111111, @00000000
 
123
   defb @11111111, @00000000
 
124
 
 
125
; ASM source file created by SevenuP v1.20
 
126
; SevenuP (C) Copyright 2002-2006 by Jaime Tejedor Gomez, aka Metalbrain
 
127
 
 
128
;GRAPHIC DATA:
 
129
;Pixel Size:      ( 16,  24)
 
130
;Char Size:       (  2,   3)
 
131
;Sort Priorities: Mask, Char line, Y char, X char
 
132
;Data Outputted:  Gfx
 
133
;Interleave:      Sprite
 
134
;Mask:            Yes, before graphic
 
135
 
 
136
._gr_window
 
137
 
 
138
        DEFB    128,127,  0,192,  0,191, 30,161
 
139
        DEFB     30,161, 30,161, 30,161,  0,191
 
140
        DEFB      0,191, 30,161, 30,161, 30,161
 
141
        DEFB     30,161,  0,191,  0,192,128,127
 
142
        DEFB    255,  0,255,  0,255,  0,255,  0
 
143
        DEFB    255,  0,255,  0,255,  0,255,  0
 
144
        
 
145
        DEFB      1,254,  0,  3,  0,253,120,133
 
146
        DEFB    120,133,120,133,120,133,  0,253
 
147
        DEFB      0,253,120,133,120,133,120,133
 
148
        DEFB    120,133,  0,253,  0,  3,  1,254
 
149
        DEFB    255,  0,255,  0,255,  0,255,  0
 
150
        DEFB    255,  0,255,  0,255,  0,255,  0
 
151
        
 
152
#endasm