473,396 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Give color and sound

Hi!!!

Question 1!
========
I want to make a program to print in the screen the numbers from 1 to 10 with deferent colors .For example 1(white) 2(red) 3(yellow) 4(green) ......
Is that possible through the cmd ????

Question 2!
========
How i can produce some sounds in defernet tones ,like beeps except for the '\a' ?

Are these two things possible in c++ while executing through the cmd panel?
Jan 20 '07 #1
6 1790
willakawill
1,646 1GB
Hi!!!

Question 1!
========
I want to make a program to print in the screen the numbers from 1 to 10 with deferent colors .For example 1(white) 2(red) 3(yellow) 4(green) ......
Is that possible through the cmd ????

Question 2!
========
How i can produce some sounds in defernet tones ,like beeps except for the '\a' ?

Are these two things possible in c++ while executing through the cmd panel?
Hi. I did this for a project way back in college. I am looking for the source code for you. It may not be around and, if it is, I will post it. Hopefully someone else will help you out in the meantime.
Jan 21 '07 #2
willakawill
1,646 1GB
OK. Found the files. They are quite big so I have cut them down to more or less essentials. Firstly 'video.h' has definitions of note frequencies and screen colors that will be used in the implementation.
Expand|Select|Wrap|Line Numbers
  1. /*VIDEO.H*/
  2.  
  3.  
  4.  
  5.  
  6. #ifndef __VIDEO_H
  7. #define __VIDEO_H
  8.  
  9. #define F1 59
  10. #define F2 60
  11. #define F3 61
  12. #define F4 62
  13. #define F5 63
  14. #define F6 64
  15. #define F7 65
  16. #define F8 66
  17. #define F9 67
  18. #define F10 68
  19. #define CTR_F1 94
  20.  
  21. #define BLACK 0
  22. #define BLUE 1
  23. #define GREEN 2
  24. #define CYAN 3
  25. #define RED 4
  26. #define MAGENTA 5
  27. #define BROWN 6
  28. #define WHITE 7
  29. #define GREY 8
  30. #define LIGHTBLUE 9
  31. #define LIGHTGREEN 10
  32. #define LIGHTCYAN 11
  33. #define LIGHTRED 12
  34. #define LIGHTMAGENTA 13
  35. #define YELLOW 14
  36.  
  37. #define BRIGHTWIGHT 15
  38. #define BLANK ' '
  39. #define SPACE ' '
  40. #define NEWLINE '\n'
  41. #define TAB '\t'
  42. #define EOS 0
  43. #define YES 1
  44. #define NO 0
  45. #define TRUE 1
  46. #define FALSE 0
  47. #define CR 13
  48. #define LF 10
  49. #define EOL 13
  50. #define CTR_STR 1
  51.  
  52. #define HOME 71
  53. #define UP_ARROW 72
  54. #define PAGE_UP 73
  55. #define LT_ARROW 75
  56. #define RT_ARROW 77
  57. #define END 79
  58. #define DN_ARROW 80
  59. #define PAGE_DN 81
  60. #define INS 82
  61. #define DEL 83
  62. #define SHIFT_TAB 15
  63. #define ENTER_KEY 28
  64. #define BK_SP_KEY 8
  65. #define ESC_KEY 27
  66. #define CR_KEY 13
  67. #define TAB_KEY 9
  68. #define SPACE_BAR 32
  69.  
  70. #define DOUBLE_BOX 1
  71. #define SINGLE_BOX 2
  72. #define BLANK_BOX  3
  73.  
  74. #define BORDER_ONLY 0
  75. #define FILL_BOX 1
  76.  
  77. #define SET_DEFAULTS 0
  78. #define SET_NORMAL 1
  79. #define SET_UNDERLINE 2
  80. #define SET_INS 3
  81. #define GET_ALPHA 6
  82. #define GET_NUM 7
  83. #define CLEAR_FIELD 8
  84. #define SET_EXIT_KEYS 9
  85.  
  86. #define _C1 262
  87. #define _D1 294
  88. #define _E1 330
  89. #define _F1 349
  90. #define _G1 392
  91. #define _A1 221
  92. #define _B1 247
  93. #define _C2 523
  94. #define _D2 587
  95. #define _E2 659
  96. #define _F2 697
  97. #define _G2 783
  98. #define _A2 441
  99. #define _B2 493
  100. #define _C3 1045
  101. #define _D3 1173
  102. #define _A3 881
  103. #define _B3 985
  104. #define CLOCKFREQ 1193180L
  105. #define SPKRMODE  0x86
  106. #define T_MODEPORT 0x43
  107. #define FREQPORT 0x42
  108. #define FREQ0 0x12c
  109. #define DIV0 CLOCKFREQ / FREQ0
  110. #define SPKRPORT 0x61
  111. #define SPKRON 0x03
  112.  
  113.  
  114.  
  115. #endif
Jan 21 '07 #3
willakawill
1,646 1GB
Next we work out a tune on a keyboard and substitute the notes in an array and play them in sequence. Have to put in a delay between each note or we will get the fastest tune in the west :)
Expand|Select|Wrap|Line Numbers
  1. /* MUSIC.CPP*/
  2.  
  3.  
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <dos.h>
  8. #include <conio.h>
  9. #include "video.h"
  10.  
  11. int motd_notes[152] =   {_G1, _G1, _C2, _C1, _E2, _E1, _G2, _G2, _G1, _E2,
  12.             _E1, _E2, _E1, _E2, _E1, _E2, _E2, _E2, _E1, _E2,
  13.             _F2, _F1, _G2, _G1, _G2, _E2, _D2, _D1, _E2, _E1,
  14.             _F2, _F1,
  15.  
  16.             _G1, _G1, _B2, _B1, _D2, _D1, _F2, _F2, _F1, _D2,
  17.             _D1, _D2, _D1, _D2, _D1, _D2, _D2, _D2, _D1, _D2,
  18.             _E2, _E1, _F2, _F1, _F2, _D2, _C2, _C1, _D2, _D1,
  19.             _E2, _E1,
  20.  
  21.             _G1, _G1, _C2, _C1, _E2, _E1, _G2, _G2, _G1, _E2,
  22.             _E1, _E2, _E1, _E2, _E1, _E2, _E2, _E2, _E1, _E2,
  23.             _F2, _F1, _G2, _G1, _G2, _E2, _F2, _F1, _G2, _G1,
  24.             _A3, _A3, _A2, _A3, _A3, _A2,
  25.  
  26.             _B3, _B2, _C3, _C2, _C3, _B3, _B2, _B3, _A3, _A3,
  27.             _C3, _C3, _G2, _G1, _G2, _G1, _A2, _A2, _G2, _G1,
  28.             _G2, _F2, _F1, _F2, _D2, _D2, _C2, _C1, _C2, _C1,
  29.             _C2, _G1, _G2, _G1,
  30.  
  31.             _C2, _C1, _G1, _G1, _E2, _E1, _C2, _C1, _G2, _G1,
  32.             _E2, _E1, _C2, _C1, _D2, _D1, _C2, _C2};
  33.  
  34.  
  35.  
  36. void motd_full(int sounds)
  37. {
  38.    if(sounds == 1)
  39.    {
  40.  
  41.    int a, b = 0;
  42.    for(a=0;a<152;a++)
  43.      {
  44.         if(kbhit() == NO)
  45.         {
  46.           sound(motd_notes[a]);
  47.           delay(100);
  48.  
  49.         }
  50.      }
  51.      nosound();
  52.  
  53.    }
  54. }
  55.  
Jan 21 '07 #4
willakawill
1,646 1GB
And here is part of the code used to control the screen. There is far more code than this. I have just posted some to give you a quick look at what you can do with the screen and the computer speaker. You have to do the learning.
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #include <dos.h>
  5. #include "string.h"
  6. #include "video.h"
  7.  
  8.  
  9. void set_video(int display_mode)
  10. {
  11.    union REGS inreg;
  12.  
  13.    inreg.h.ah = 0x00;
  14.    inreg.h.al = display_mode;
  15.  
  16.    int86(0x10, &inreg, &inreg);
  17. }
  18.  
  19. void cursor(int row, int column)
  20. {
  21.    union REGS inregs;
  22.  
  23.    inregs.h.ah = 0x02;
  24.    inregs.h.bh = 0;
  25.    inregs.h.dh = row;
  26.    inregs.h.dl = column;
  27.  
  28.    int86(0x10, &inregs, &inregs);
  29.  
  30. }
  31.  
  32. void clear_prompt(int cursa, int cursb, int colf, int colb)
  33. {
  34.  
  35.    cursor(cursa, cursb);
  36.    repeat_char(255, 66, colf, colb);
  37.    cursor(cursa+1, 6);
  38.    repeat_char(255, 66, colf, colb);
  39.    cursor(cursa+2, 6);
  40.    repeat_char(255, 66, colf, colb);
  41.    cursor(cursa+3, 6);
  42.    repeat_char(255, 66, colf, colb);
  43.    cursor(cursa+4, 6);
  44.    repeat_char(255, 66, colf, colb);
  45.    cursor(cursa+5, 6);
  46.    repeat_char(255, 66, colf, colb);
  47.    cursor(cursa+6, 6);
  48.    repeat_char(255, 66, colf, colb);
  49.    cursor(2, 8);
  50. }
  51.  
  52. void repeat_char(char ch, int howmany, int fcolour, int bcolour)
  53. {
  54.    union REGS inregs;
  55.  
  56.    inregs.h.ah = 0x09;
  57.    inregs.h.al = ch;
  58.    inregs.h.bh = 0;
  59.    inregs.h.bl = (bcolour << 4) |  fcolour;
  60.    inregs.x.cx = howmany;
  61.  
  62.    int86(0x10, &inregs, &inregs);
  63. }
  64.  
  65. void clr_scr(int fcolour, int bcolour)
  66. {
  67.    union REGS ireg;
  68.  
  69.    ireg.h.ah = 0x07;
  70.    ireg.h.al = 0;
  71.    ireg.h.ch = 0;
  72.    ireg.h.cl = 0;
  73.    ireg.h.dh = 24;
  74.    ireg.h.dl = 79;
  75.    ireg.h.bh = (bcolour <<4) | fcolour;
  76.  
  77.    int86(0x10, &ireg, &ireg);
  78.  
  79. }
  80.  
  81. void write_string(char *string, int fcolour, int bcolour, int row,
  82.                 int column)
  83. {
  84.    int len = strlen(string);
  85.    int i;
  86.  
  87.    for(i=0; i < len; i++)
  88.    {
  89.      cursor(row, column+i);
  90.      write_char((char)*(string+i), fcolour, bcolour);
  91.    }
  92. }
  93.  
  94. void write_char(char ch, int fcolour, int bcolour)
  95. {
  96.    union REGS inreg;
  97.  
  98.    inreg.h.ah = 0x09;
  99.    inreg.h.al = ch;
  100.    inreg.h.bh = 0;
  101.    inreg.h.bl = (bcolour << 4) | fcolour;
  102.    inreg.x.cx = 1;
  103.  
  104.    int86(0x10, &inreg, &inreg);
  105. }
  106.  
  107. void cursor_off(void)
  108. {
  109.    union REGS inreg, outreg;
  110.    inreg.h.ah = 1;
  111.    inreg.x.cx = 0x0F00;
  112.  
  113.    int86(0x10, &inreg, &outreg);
  114. }
  115.  
  116. void cursor_on(void)
  117. {
  118.    union REGS inreg, outreg;
  119.    inreg.h.ah = 1;
  120.    inreg.x.cx = 0x0607;
  121.  
  122.    int86(0x10, &inreg, &outreg);
  123. }
  124.  
  125. void set_border_colour(int colour = 0)
  126. {
  127.    union REGS inreg;
  128.  
  129.    inreg.h.ah = 0x0B;
  130.    inreg.h.bh = 0;
  131.    inreg.h.bl = colour;
  132.  
  133.    int86(0x10, &inreg, &inreg);
  134. }
  135.  
  136. void dreamt_display(int a, int b)
  137. {
  138.    char *buff = "DREAM TEAM FOOTBALL";
  139.  
  140.    if((a % 2) == 0)
  141.    {
  142.      set_border_colour(b);
  143.      clear_prompt(b+2,6,0, b);
  144.      clear_prompt((16-b),6,0, b);
  145.      write_string(buff,b+1,b,12,29);
  146.    }
  147.    write_string(buff,b+1,b,b+4,b+29);
  148.    write_string(buff,b+1,b,20-b,29-b);
  149. }
  150.  
Jan 21 '07 #5
Thanks !!!!!!!!
You are great man and great programmer!!!!!!!
Jan 22 '07 #6
willakawill
1,646 1GB
Thanks !!!!!!!!
You are great man and great programmer!!!!!!!
Well that is a great thank you.
This was all from several years back. I am sure I stole most of the code from books etc. Looking at it now I don't understand half of it :)
I am sure I would never dream of writing code today that uses interupts to code registers directly.
Jan 22 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Put 030516 in email subj to get thru | last post by:
I'm trying to learn about Java MIDI programming. Specifically, I'm interested in playing with Java MIDI sequencers (all puns intended). I'm looking at...
4
by: Robert Gravereaux | last post by:
I'm putting together a C# .Net forms project on win2k. The application requires some sort of horn sound. I've never implemented any audio in .Net, so I'm not sure how best to accomplish this. ...
0
by: June Li | last post by:
H I got a problem with detecting sound card with Windows xp I am working on an application to test microphone. First I need detect if there is a sound card installed (or integrated audio...
4
by: Larry Serflaten | last post by:
I'm adding a bit of sound to a simple game I've got going, and I want to have several sounds on at the same time, so I go looking to use the MCISendString commands and find they CRASH MY COMPUTER...
1
by: anadiks | last post by:
Problem 2: Threading: Requirements: In a particular system there are two threads T1 and T2. T1 is the master thread that periodically sends messages to the worker thread T2. The system...
6
by: laredotornado | last post by:
Hi, Is there a cross-browser way to play short (< 25K) sound files without spawning new windows or embedding any visual controls on the page? I would like to click a button and hear my short...
6
by: =?Utf-8?B?VmVybm9uIFBlcHBlcnM=?= | last post by:
I have an application that is designed for using with a bar code scanner. I want the user to know that the scan was complete and the data was entered, so I am playing a system sound after data...
26
by: Jake Barnes | last post by:
I did a search on the newsgroup comp.lang.javascript. I was searching for "how to play a sound with Javascript". I'm somewhat suprised that the majority of entries are from the 1990s, and there are...
4
by: kid joe | last post by:
Hello I've got interested in learning some basic sound programming bits in C... mainly I want to know how to go about accessing the sound devices - reading from them mainly - in windows and...
8
by: chromis | last post by:
Hi, I've been struggling to get sounds to work with attachSound when the sounds are stored in a swf loaded into another swf. I came across a post on a forum which supposedly explains how to to do...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.