@@ -43,10 +43,8 @@ beep_until_key_pressed(unsigned freq, unsigned duration, unsigned override)
4343 if (ret == SUCCESS ) {
4444 while (!SysCall (CheckBeepEndEntry ) || paused ) {
4545 if (alpha_pressed ) {
46- if ((paused = !paused )) {
47- gotoxy (2 , 5 );
48- puts ("|| " );
49- }
46+ gotoxy (1 , 7 );
47+ puts ((paused = !paused )? "||" : " " );
5048 } else if (shift_pressed ) {
5149 set_indicator (INDICATOR_REMOTE , (repeat = !repeat ));
5250 } else if (on_pressed ) {
@@ -77,23 +75,60 @@ parse_int(SAT_STRING *str)
7775
7876
7977void
80- print_offset (SAT_STRING * str )
78+ draw_line (unsigned row , int length )
79+ {
80+ uint8_t * p = __display_buf + row * BYTES_PER_ROW + 2 ;
81+ int i ;
82+ for (i = 0 ; i < length / 8 ; i ++ ) {
83+ p [i ] = 0xFF ;
84+ }
85+ p [i ] = 0xFF << (length & 0x7 ) >> 8 ;
86+ }
87+
88+
89+ void
90+ init_progress_bar (SAT_STRING * str )
91+ {
92+ for (int row = BAR_TOP ; row < BAR_TOP + BAR_HEIGHT + 2 ; row ++ ) {
93+ memset (& __display_buf [row * BYTES_PER_ROW ], 0x00 , 16 );
94+ __display_buf [row * BYTES_PER_ROW + 1 ] = 0x80 ; // left border
95+ __display_buf [row * BYTES_PER_ROW + 15 ] = 0x1 ; // right border
96+ }
97+ draw_line (BAR_TOP , BAR_WIDTH + 1 ); // top border
98+ draw_line (BAR_TOP + BAR_HEIGHT + 1 , BAR_WIDTH + 1 ); // bottom border
99+
100+ char buf [7 ];
101+ utoa (str -> end - str -> begin , buf , 10 );
102+ gotoxy (30 - strlen (buf ), 6 );
103+ puts (buf );
104+ }
105+
106+
107+ void
108+ update_progress_bar (SAT_STRING * str , const char * melody )
81109{
110+ unsigned
111+ current = str -> cursor - melody ,
112+ total = str -> end - melody ,
113+ pixels = BAR_WIDTH * current / total ;
114+
115+ for (int row = BAR_TOP + 1 ; row < BAR_TOP + BAR_HEIGHT + 1 ; row ++ ) {
116+ draw_line (row , pixels ); // progress bar
117+ }
118+
82119 char buf [7 ];
83120 utoa (str -> cursor - str -> begin , buf , 10 );
84- putchar (' ' );
85- putchar (' ' );
121+ gotoxy (4 , 6 );
86122 puts (buf );
87123}
88124
89125
90126void
91127raise (SAT_STRING * str )
92128{
93- gotoxy (2 , 2 );
129+ gotoxy (2 , 3 );
94130 puts (str -> cursor >= str -> end ? "End of file" : "Interrupted" );
95- puts (" Press any key to exit\n\n At file position:" );
96- print_offset (str );
131+ puts (" Press any key to exit" );
97132 while (any_key_pressed );
98133 while (!any_key_pressed );
99134 while (any_key_pressed );
@@ -111,25 +146,22 @@ duration_parser(SAT_STRING *str)
111146void
112147melody_parser (SAT_STRING * str )
113148{
114- const char * cursor = str -> cursor ;
115- str -> cursor = str -> end ;
116- print_offset (str );
149+ const char * melody = str -> cursor ;
150+
117151begin :
118- str -> cursor = cursor ;
152+ str -> cursor = melody ;
153+ init_progress_bar (str );
119154
120155 while (TRUE) {
121- gotoxy (0 , 3 );
122- print_offset (str );
123- putchar ('\n' );
156+ update_progress_bar (str , melody );
124157
125158 // get optional duration
126159 int duration = duration_parser (str );
127160
128161 // convert ANSI note to MIDI note
129162 int note = 0 ;
130163 char c = toupper (peek (str ));
131- putchar (' ' );
132- putchar (' ' );
164+ gotoxy (15 , 6 );
133165 putchar (c );
134166 if ('A' <= c && c <= 'G' ) {
135167 const char notes [] = {9 , 11 , 0 , 2 , 4 , 5 , 7 };
@@ -188,6 +220,8 @@ melody_parser(SAT_STRING *str)
188220 if (repeat ) {
189221 goto begin ;
190222 } else {
223+ gotoxy (1 , 7 );
224+ puts ("[]" );
191225 raise (str );
192226 }
193227}
0 commit comments