Question: Task:using C++ program to do this 1) Draw a horizontal line (initially in the center of the screen). 2) Hold at the current position for

Task:using C++ program to do this 1) Draw a horizontal line (initially in the center of the screen). 2) Hold at the current position for 250 milliseconds 3) Calculate the next position of the line by incrementing its y-position by 1. If the next position is at or beyond the screen boundary, reverse direction. 4) Erase the old line 5) Draw the new line 6) Go to step 2

#include

/* these globals are written by interrupt service routines; we have to declare * these as volatile to avoid the compiler caching their values in registers */ extern volatile char byte1, byte2; /* modified by PS/2 interrupt service routine */ extern volatile int timeout; // used to synchronize with the timer

/*Color a pixel */ void drawpixel(int x_vga, int y_vga, short color) { volatile char *pixel_address = (volatile char*) (0x08000000 + (y_vga <<7) + (x_vga)); *pixel_address = color; }

/* For DE0-CV * * void drawpixel(int x_vga, int, y_vga, short color) { volatile short *pixel_address = (volatile short*)(0x08000000 + (y_vga<<10) + (x_vga<<1)); *pixel_address = color; } * */

/* Paint the screen BLACK * DE0 Limits x= 79, y=59 * DE0-CV x= 319, y=239 */

void clearscreen () { int x_vga, y_vga; for (x_vga = 0; x_vga <=79; x_vga = x_vga + 1) { for (y_vga = 0; y_vga <=59; y_vga = y_vga + 1) { drawpixel(x_vga, y_vga, 0x0); } } }

/* Draw a single character on the screen */

void drawcharacter(int x_char, int y_char, char mychar) { volatile char* character_buffer = (char *) (0x09000000 + (y_char <<7) + x_char); *character_buffer = mychar; }

int main() { char* fullstring = "Welcome to ELEC2850 !!!"; char* fullstring2 = "YES !!!"; clearscreen(); int x_max, y_max, x_start, y_start; /* Draw an orange horzontal line */ for (x_max = 0; x_max < 78; x_max = x_max + 1) { drawpixel(x_max, 50, 248); } /* Draw an red vertical line */ for (y_max = 0; y_max < 49; y_max = y_max + 1) { drawpixel(79, y_max, 224); } /* Write text to the monitor beginning at (col=x_start, row=y_start) fullstring */ x_start = 28; y_start = 5; while (*fullstring) { drawcharacter(x_start, y_start, *fullstring); x_start = x_start + 1; fullstring = fullstring + 1; } /* Write text to the monitor beginning at (col=x_start, row=y_start) fullstring2*/ x_start = 31; y_start = 10; while (*fullstring2) { drawcharacter(x_start, y_start, *fullstring2); x_start = x_start + 1; fullstring2 = fullstring2 + 1; } return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!