~z88dk-team/z88dk-pkg/trunk

« back to all changes in this revision

Viewing changes to libsrc/sprites/software/sp1/ts2068hr/examples/ex4c.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 #4C
 
4
// 04.2006 aralbrec
 
5
//
 
6
// Up to this point we have been using a single clipping
 
7
// rectangle in all the sp1_MoveSpr*() calls we have been
 
8
// making with little explanation of what this clipping rectangle
 
9
// is for.  It's exactly what you think it is -- the sprite
 
10
// is drawn such that only the parts of the sprite inside
 
11
// the rectangle get drawn.  By using the full screen as
 
12
// clipping rectangle up to this point we have been
 
13
// accomplishing one important function of the clipping
 
14
// rectangle and that is preventing the sprite engine from
 
15
// drawing into non-existent areas of the screen.
 
16
//
 
17
// Now we are going to use the clipping rectangle for a
 
18
// second purpose which is to control where the sprites
 
19
// can appear on screen.  Two new clipping rectangles are
 
20
// defined and the sp1_MoveSprAbs() call in the main loop
 
21
// uses clipping rectangle #1 for the first five sprites
 
22
// created (the MASKed sprites) and clipping rectangle #2
 
23
// for the rest (the XOR sprites).  The result is,
 
24
// although the rectangles are freely moving across the
 
25
// entire screen, they are only drawn when they appear
 
26
// in their respective clipping rectangles.
 
27
//
 
28
// Clipping can only be done to character cell boundaries.
 
29
//
 
30
// Among applications of this, consider a vertical gate
 
31
// hidden in a doorway.  As the player approaches it drops
 
32
// closed.  If the gate is a sprite with clipping rectangle
 
33
// covering the doorway only, it can appear to drop into
 
34
// place by being moved from over the doorway onto the
 
35
// doorway.
 
36
/////////////////////////////////////////////////////////////
 
37
 
 
38
// zcc +ts2068 -vn ex4c.c -o ex4c.bin -create-app -lsp1 -lmalloc
 
39
 
 
40
#include <sprites/sp1.h>
 
41
#include <malloc.h>
 
42
#include <ts2068.h>
 
43
#include <string.h>
 
44
 
 
45
#pragma output STACKPTR=47104                    // place stack at $b800 at startup
 
46
long heap;                                       // malloc's heap pointer
 
47
 
 
48
 
 
49
// Memory Allocation Policy
 
50
 
 
51
void *u_malloc(uint size) {
 
52
   return malloc(size);
 
53
}
 
54
 
 
55
void u_free(void *addr) {
 
56
    free(addr);
 
57
}
 
58
 
 
59
// Clipping Rectangle for Sprites
 
60
 
 
61
struct sp1_Rect cr = {0, 0, 64, 24};             // full screen
 
62
struct sp1_Rect clip1 = {1, 2, 24, 12};          // clip region 1
 
63
struct sp1_Rect clip2 = {10, 36, 24, 12};        // clip region 2
 
64
 
 
65
// Table Holding Movement Data for Each Sprite
 
66
 
 
67
struct sprentry {
 
68
   struct sp1_ss  *s;                            // sprite handle returned by sp1_CreateSpr()
 
69
   char           dx;                            // signed horizontal speed in pixels
 
70
   char           dy;                            // signed vertical speed in pixels
 
71
};
 
72
 
 
73
struct sprentry sprtbl[] = {
 
74
   {0,2,0}, {0,0,1}, {0,2,2}, {0,4,1}, {0,2,3},  // double the spectrum's dx speed as we have
 
75
   {0,6,1}, {0,4,3}, {0,6,2}, {0,2,1}, {0,4,2}   // double the horizontal resolution
 
76
};
 
77
 
 
78
// A Hashed UDG for Background
 
79
 
 
80
uchar hash[] = {0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa};
 
81
 
 
82
// Attach C Variable to Sprite Graphics Declared in ASM at End of File
 
83
 
 
84
extern uchar gr_window[];
 
85
 
 
86
main()
 
87
{
 
88
   uchar i;
 
89
   struct sp1_ss *s;
 
90
   struct sprentry *se;
 
91
   void *temp;
 
92
   
 
93
   #asm
 
94
   di
 
95
   #endasm
 
96
 
 
97
   // Initialize MALLOC.LIB
 
98
   
 
99
   heap = 0L;                  // heap is empty
 
100
   sbrk(40000, 6000);          // make available memory from 40000-45999
 
101
   
 
102
   // Set 512x192 Video Mode
 
103
   
 
104
   memset(16384, 0, 6144);     // clear both halves of the display file before switching video mode
 
105
   memset(24576, 0, 6144);
 
106
   ts_vmod(PAPER_BLACK | VMOD_HIRES);   // select 64-col mode with black background
 
107
 
 
108
   // Initialize SP1.LIB
 
109
   
 
110
   sp1_Initialize(SP1_IFLAG_MAKE_ROTTBL | SP1_IFLAG_OVERWRITE_TILES | SP1_IFLAG_OVERWRITE_DFILE, ' ');
 
111
   sp1_TileEntry(' ', hash);   // redefine graphic associated with ' ' character
 
112
 
 
113
   // mark the two rectangular areas on screen so we can see them
 
114
 
 
115
   sp1_ClearRect(&clip1, '+', SP1_RFLAG_TILE);
 
116
   sp1_ClearRect(&clip2, '+', SP1_RFLAG_TILE);
 
117
 
 
118
   sp1_Invalidate(&cr);        // invalidate entire screen so that it is all initially drawn
 
119
   sp1_UpdateNow();            // draw screen area managed by sp1 now
 
120
   
 
121
   // Create Ten Masked Software-Rotated Sprites
 
122
   
 
123
   for (i=0; i!=10; i++) {
 
124
 
 
125
      if (i < 5)
 
126
      {
 
127
         s = sprtbl[i].s = sp1_CreateSpr(SP1_DRAW_MASK2LB, SP1_TYPE_2BYTE, 3, 0, i);
 
128
         sp1_AddColSpr(s, SP1_DRAW_MASK2, 0, 48, i);
 
129
         sp1_AddColSpr(s, SP1_DRAW_MASK2RB, 0, 0, i);
 
130
         sp1_MoveSprAbs(s, &cr, gr_window, 10, 14, 0, 4);
 
131
      }
 
132
      else
 
133
      {
 
134
         s = sprtbl[i].s = sp1_CreateSpr(SP1_DRAW_XOR2LB, SP1_TYPE_2BYTE, 3, 0, i);
 
135
         sp1_AddColSpr(s, SP1_DRAW_XOR2, 0, 48, i);
 
136
         sp1_AddColSpr(s, SP1_DRAW_XOR2RB, 0, 0, i);
 
137
         sp1_MoveSprAbs(s, &cr, gr_window, 10, 14, 0, 4);
 
138
      }
 
139
 
 
140
   };
 
141
   
 
142
   while (1) {                                  // main loop
 
143
   
 
144
      sp1_UpdateNow();                          // draw screen now
 
145
      
 
146
      for (i=0; i!=10; i++) {                    // move all sprites
 
147
 
 
148
         se = &sprtbl[i];
 
149
         
 
150
         if (i < 5)
 
151
            sp1_MoveSprRel(se->s, &clip1, 0, 0, 0, se->dy, se->dx);
 
152
         else
 
153
            sp1_MoveSprRel(se->s, &clip2, 0, 0, 0, se->dy, se->dx);
 
154
         
 
155
         if (se->s->row > 21)                    // if sprite went off screen, reverse direction
 
156
            se->dy = - se->dy;
 
157
            
 
158
         if (se->s->col > 61)                    // notice if coord moves less than 0, it becomes
 
159
            se->dx = - se->dx;                   //   255 which is also caught by these cases
 
160
 
 
161
      }
 
162
      
 
163
   }  // end main loop
 
164
 
 
165
}
 
166
 
 
167
#asm
 
168
 
 
169
   defb @11111111, @00000000
 
170
   defb @11111111, @00000000
 
171
   defb @11111111, @00000000
 
172
   defb @11111111, @00000000
 
173
   defb @11111111, @00000000
 
174
   defb @11111111, @00000000
 
175
   defb @11111111, @00000000
 
176
 
 
177
; ASM source file created by SevenuP v1.20
 
178
; SevenuP (C) Copyright 2002-2006 by Jaime Tejedor Gomez, aka Metalbrain
 
179
 
 
180
;GRAPHIC DATA:
 
181
;Pixel Size:      ( 16,  24)
 
182
;Char Size:       (  2,   3)
 
183
;Sort Priorities: Mask, Char line, Y char, X char
 
184
;Data Outputted:  Gfx
 
185
;Interleave:      Sprite
 
186
;Mask:            Yes, before graphic
 
187
 
 
188
._gr_window
 
189
 
 
190
        DEFB    128,127,  0,192,  0,191, 30,161
 
191
        DEFB     30,161, 30,161, 30,161,  0,191
 
192
        DEFB      0,191, 30,161, 30,161, 30,161
 
193
        DEFB     30,161,  0,191,  0,192,128,127
 
194
        DEFB    255,  0,255,  0,255,  0,255,  0
 
195
        DEFB    255,  0,255,  0,255,  0,255,  0
 
196
        
 
197
        DEFB      1,254,  0,  3,  0,253,120,133
 
198
        DEFB    120,133,120,133,120,133,  0,253
 
199
        DEFB      0,253,120,133,120,133,120,133
 
200
        DEFB    120,133,  0,253,  0,  3,  1,254
 
201
        DEFB    255,  0,255,  0,255,  0,255,  0
 
202
        DEFB    255,  0,255,  0,255,  0,255,  0
 
203
        
 
204
#endasm