2
/////////////////////////////////////////////////////////////
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
/////////////////////////////////////////////////////////////
12
// zcc +zx -vn ex1.c -o ex1.bin -create-app -lsp1 -lmalloc
14
#include <sprites/sp1.h>
18
#pragma output STACKPTR=53248 // place stack at $d000 at startup
19
long heap; // malloc's heap pointer
22
// Memory Allocation Policy
24
void *u_malloc(uint size) {
28
void u_free(void *addr) {
32
// Clipping Rectangle for Sprites
34
struct sp1_Rect cr = {0, 0, 32, 24}; // full screen
36
// Table Holding Movement Data for Each Sprite
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
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}
49
// A Hashed UDG for Background
51
uchar hash[] = {0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa};
53
// Attach C Variable to Sprite Graphics Declared in ASM at End of File
55
extern uchar gr_window[];
68
// Initialize MALLOC.LIB
70
heap = 0L; // heap is empty
71
sbrk(40000, 10000); // make available memory from 40000-49999
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
79
sp1_Invalidate(&cr); // invalidate entire screen so that it is all initially drawn
80
sp1_UpdateNow(); // draw screen area managed by sp1 now
82
// Create Ten Masked Software-Rotated Sprites
84
for (i=0; i!=10; i++) {
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);
93
while (1) { // main loop
95
sp1_UpdateNow(); // draw screen now
97
for (i=0; i!=10; i++) { // move all sprites
101
sp1_MoveSprRel(se->s, &cr, 0, 0, 0, se->dy, se->dx);
103
if (se->s->row > 21) // if sprite went off screen, reverse direction
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
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
125
; ASM source file created by SevenuP v1.20
126
; SevenuP (C) Copyright 2002-2006 by Jaime Tejedor Gomez, aka Metalbrain
129
;Pixel Size: ( 16, 24)
131
;Sort Priorities: Mask, Char line, Y char, X char
134
;Mask: Yes, before graphic
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
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