-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.c
125 lines (101 loc) · 2.65 KB
/
utils.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#ifdef __SPECTRUM__
#include <z80.h>
#endif
#include "utils.h"
#include "utils_asm.h"
#include "common.h"
#include "input.h"
#include "PutSprite.h"
/* ********************************************* */
int8_t _ExitIfKeyPressed = 0;
/* ********************************************* */
#if 0
int8_t DelayFrames( uint8_t frames ) {
while ( frames-- ) {
WaitFrame();
#ifdef __ZX81__
readSysKeys();
#endif
if ( _ExitIfKeyPressed && syskey.keyPressed ) return 1;
}
return 0;
}
#endif
/* ********************************************* */
char buff[ 16 ];
#if 0
void PrintNumAt( uint8_t x, uint8_t y, int16_t num, uint8_t flags ) {
unsigned char *p = &buff[ 14 ];
int8_t d, c = 0, is_negative = 0, leftzero = flags & NUM_LEFTZERO, digits = flags & 7;
p[ 1 ] = '\0';
if ( !( flags & NUM_UNSIGNED ) && num < 0 ) {
is_negative = 1;
num = -num;
digits--;
}
uint16_t n = ( uint16_t ) num;
while ( digits-- && p >= buff ) {
d = n % 10;
n /= 10;
if ( !( n | d ) && !leftzero && c ) {
if ( is_negative ) {
is_negative = 0;
*p-- = '-';
digits++;
} else {
*p-- = ' ';
}
} else {
*p-- = '0' + d;
}
c = 1;
}
if ( is_negative ) *p-- = '-';
p++;
PrintAt( x, y, p );
}
#else
void PrintNumAt( uint8_t x, uint8_t y, uint16_t num, uint8_t flags ) {
unsigned char *p = &buff[ 14 ];
int8_t d, c = 0, leftzero = flags & NUM_LEFTZERO, digits = flags & 7;
p[ 1 ] = '\0';
uint16_t n = ( uint16_t ) num;
while ( digits-- && p >= buff ) {
d = n % 10;
n /= 10;
if ( !( n | d ) && !leftzero && c ) {
*p-- = ' ';
} else {
*p-- = '0' + d;
}
c = 1;
}
p++;
PrintAt( x, y, p );
}
#endif
/* ********************************************* */
void PrintAt( uint8_t x, uint8_t y, unsigned char * msg ) {
while ( *msg ) {
PrintChar( x, y, *msg++, 0 );
x += 8;
}
}
/* ********************************************* */
int PrintAtDelay( uint8_t x, uint8_t y, unsigned char * msg, uint8_t delay ) {
while ( *msg ) {
if ( DelayFrames( delay ) ) return 1;
PrintChar( x, y, *msg++, 0 );
x += 8;
}
return 0;
}
/* ********************************************* */
void PutChars( uint8_t x, uint8_t y, uint8_t ch, uint8_t cnt, uint8_t method ) {
while( cnt-- ) {
PrintChar( x, y, ch, method );
if ( x >= 256u - 8 ) break;
x += 8;
}
}
/* ********************************************* */