-
Notifications
You must be signed in to change notification settings - Fork 1
/
gcmd.c
157 lines (127 loc) · 3.02 KB
/
gcmd.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <stdio.h>
#include <stdlib.h>
#ifdef __ET__
# include <sys/timer.h>
# include <mb/vga.h>
# include <mb/beep.h>
# include <mb/leds.h>
#else
# include <unistd.h>
#endif
#include "stack.h"
#include "fifth.h"
#include "cmd.h"
#include "gcmd.h"
#define MIN(a,b) ( (a) < (b) ? (a) : (b) )
/** take width, x, y and color from stack and draw rect
*/
int fifth_rect( struct fifth *f, uint8_t size )
{
uint8_t color = stack_pop( &f->stack );
uint8_t y = stack_pop( &f->stack );
uint8_t x = stack_pop( &f->stack );
x = MIN( x, FIFTH_SCREEN_X_MAX );
y = MIN( y, FIFTH_SCREEN_Y_MAX );
#ifdef __ET__
vga_c_fill_rect( x,
y,
MIN( x + size, FIFTH_SCREEN_X_MAX ),
MIN( y + size, FIFTH_SCREEN_Y_MAX ),
color );
disp_refresh( );
#else
printf( "Draw square (size = %u at %u, %u of color %u\n",
size, x, y, color );
#endif
return 0;
}
int fifth_lrect( struct fifth *f )
{
return fifth_rect( f, 10 );
}
int fifth_mrect( struct fifth *f )
{
return fifth_rect( f, 20 );
}
int fifth_brect( struct fifth *f )
{
return fifth_rect( f, 50 );
}
/** print character
*/
int fifth_char( struct fifth *f )
{
uint8_t c = stack_pop( &f->stack );
uint8_t bg_color = stack_pop( &f->stack );
uint8_t fg_color = stack_pop( &f->stack );
uint8_t y = stack_pop( &f->stack );
uint8_t x = stack_pop( &f->stack );
#ifdef __ET__
int _fg_color = vga_fg_color( );
int _bg_color = vga_bg_color( );
vga_set_colors( fg_color, bg_color );
vga_putchar( c, x, y );
vga_set_colors( _fg_color, _bg_color );
#else
printf( "Character %c at %u, %u color %u\n", c, x, y, fg_color );
#endif
return 0;
}
/** take color and fill screen with it
*/
int fifth_fill( struct fifth *f )
{
uint8_t color = stack_pop( &f->stack );
#ifdef __ET__
vga_c_fill_rect( FIFTH_SCREEN_X_MIN,
FIFTH_SCREEN_Y_MIN,
FIFTH_SCREEN_X_MAX,
FIFTH_SCREEN_Y_MAX,
color );
//FIXME: hack to avoid blinking
//disp_refresh( );
#else
printf( "fill with color %d\n", color );
#endif
return 0;
}
/** take beep duration from stack and then beep
*
*/
int fifth_sound( struct fifth *f )
{
// uint8_t tone = stack_pop( &f->stack );
uint8_t dur = stack_pop( &f->stack );
//printf( "\007" );
#ifdef __ET__
beep( (unsigned short)dur * 10 );
#endif
return 0;
}
/** take led number and it's color from stack
* and then burn led
*/
int fifth_led( struct fifth *f )
{
uint8_t led = stack_pop( &f->stack );
uint8_t color = stack_pop( &f->stack );
#ifdef __ET__
led_burn( led, color );
//FIXME: hack to avoid blinking
disp_refresh( );
#else
printf( "burn led #%d with color %d\n", led, color );
#endif
return 0;
}
/** take stack top and sleep for this number of milliseconds
*/
int fifth_delay( struct fifth *f )
{
#ifdef __ET__
NutSleep( 10 * stack_pop( &f->stack ) );
#else
usleep( 10 * 1000 * stack_pop( &f->stack ) );
#endif
return 0;
}