Give color and sound

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maradona
    New Member
    • Dec 2006
    • 9

    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?
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Originally posted by maradona
    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.

    Comment

    • willakawill
      Top Contributor
      • Oct 2006
      • 1646

      #3
      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.
      Code:
      /*VIDEO.H*/
      
      
      
      
      #ifndef __VIDEO_H
      #define __VIDEO_H
      
      #define F1 59
      #define F2 60
      #define F3 61
      #define F4 62
      #define F5 63
      #define F6 64
      #define F7 65
      #define F8 66
      #define F9 67
      #define F10 68
      #define CTR_F1 94
      
      #define BLACK 0
      #define BLUE 1
      #define GREEN 2
      #define CYAN 3
      #define RED 4
      #define MAGENTA 5
      #define BROWN 6
      #define WHITE 7
      #define GREY 8
      #define LIGHTBLUE 9
      #define LIGHTGREEN 10
      #define LIGHTCYAN 11
      #define LIGHTRED 12
      #define LIGHTMAGENTA 13
      #define YELLOW 14
      
      #define BRIGHTWIGHT 15
      #define BLANK ' '
      #define SPACE ' '
      #define NEWLINE '\n'
      #define TAB '\t'
      #define EOS 0
      #define YES 1
      #define NO 0
      #define TRUE 1
      #define FALSE 0
      #define CR 13
      #define LF 10
      #define EOL 13
      #define CTR_STR 1
      
      #define HOME 71
      #define UP_ARROW 72
      #define PAGE_UP 73
      #define LT_ARROW 75
      #define RT_ARROW 77
      #define END 79
      #define DN_ARROW 80
      #define PAGE_DN 81
      #define INS 82
      #define DEL 83
      #define SHIFT_TAB 15
      #define ENTER_KEY 28
      #define BK_SP_KEY 8
      #define ESC_KEY 27
      #define CR_KEY 13
      #define TAB_KEY 9
      #define SPACE_BAR 32
      
      #define DOUBLE_BOX 1
      #define SINGLE_BOX 2
      #define BLANK_BOX  3
      
      #define BORDER_ONLY 0
      #define FILL_BOX 1
      
      #define SET_DEFAULTS 0
      #define SET_NORMAL 1
      #define SET_UNDERLINE 2
      #define SET_INS 3
      #define GET_ALPHA 6
      #define GET_NUM 7
      #define CLEAR_FIELD 8
      #define SET_EXIT_KEYS 9
      
      #define _C1 262
      #define _D1 294
      #define _E1 330
      #define _F1 349
      #define _G1 392
      #define _A1 221
      #define _B1 247
      #define _C2 523
      #define _D2 587
      #define _E2 659
      #define _F2 697
      #define _G2 783
      #define _A2 441
      #define _B2 493
      #define _C3 1045
      #define _D3 1173
      #define _A3 881
      #define _B3 985
      #define CLOCKFREQ 1193180L
      #define SPKRMODE  0x86
      #define T_MODEPORT 0x43
      #define FREQPORT 0x42
      #define FREQ0 0x12c
      #define DIV0 CLOCKFREQ / FREQ0
      #define SPKRPORT 0x61
      #define SPKRON 0x03
      
      
      
      #endif

      Comment

      • willakawill
        Top Contributor
        • Oct 2006
        • 1646

        #4
        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 :)
        Code:
        /* MUSIC.CPP*/
        
        
        
        #include <stdio.h>
        #include <stdlib.h>
        #include <dos.h>
        #include <conio.h>
        #include "video.h"
        
        int motd_notes[152] =   {_G1, _G1, _C2, _C1, _E2, _E1, _G2, _G2, _G1, _E2,
        			_E1, _E2, _E1, _E2, _E1, _E2, _E2, _E2, _E1, _E2,
        			_F2, _F1, _G2, _G1, _G2, _E2, _D2, _D1, _E2, _E1,
        			_F2, _F1,
        
        			_G1, _G1, _B2, _B1, _D2, _D1, _F2, _F2, _F1, _D2,
        			_D1, _D2, _D1, _D2, _D1, _D2, _D2, _D2, _D1, _D2,
        			_E2, _E1, _F2, _F1, _F2, _D2, _C2, _C1, _D2, _D1,
        			_E2, _E1,
        
        			_G1, _G1, _C2, _C1, _E2, _E1, _G2, _G2, _G1, _E2,
        			_E1, _E2, _E1, _E2, _E1, _E2, _E2, _E2, _E1, _E2,
        			_F2, _F1, _G2, _G1, _G2, _E2, _F2, _F1, _G2, _G1,
        			_A3, _A3, _A2, _A3, _A3, _A2,
        
        			_B3, _B2, _C3, _C2, _C3, _B3, _B2, _B3, _A3, _A3,
        			_C3, _C3, _G2, _G1, _G2, _G1, _A2, _A2, _G2, _G1,
        			_G2, _F2, _F1, _F2, _D2, _D2, _C2, _C1, _C2, _C1,
        			_C2, _G1, _G2, _G1,
        
        			_C2, _C1, _G1, _G1, _E2, _E1, _C2, _C1, _G2, _G1,
        			_E2, _E1, _C2, _C1, _D2, _D1, _C2, _C2};
        
        
        
        void motd_full(int sounds)
        {
           if(sounds == 1)
           {
        
           int a, b = 0;
           for(a=0;a<152;a++)
        	 {
        	    if(kbhit() == NO)
        	    {
        		  sound(motd_notes[a]);
        		  delay(100);
        
        	    }
        	 }
        	 nosound();
        
           }
        }

        Comment

        • willakawill
          Top Contributor
          • Oct 2006
          • 1646

          #5
          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.
          Code:
          #include <stdio.h>
          #include <stdlib.h>
          #include <conio.h>
          #include <dos.h>
          #include "string.h"
          #include "video.h"
          
          
          void set_video(int display_mode)
          {
             union REGS inreg;
          
             inreg.h.ah = 0x00;
             inreg.h.al = display_mode;
          
             int86(0x10, &inreg, &inreg);
          }
          
          void cursor(int row, int column)
          {
             union REGS inregs;
          
             inregs.h.ah = 0x02;
             inregs.h.bh = 0;
             inregs.h.dh = row;
             inregs.h.dl = column;
          
             int86(0x10, &inregs, &inregs);
          
          }
          
          void clear_prompt(int cursa, int cursb, int colf, int colb)
          {
          
             cursor(cursa, cursb);
             repeat_char(255, 66, colf, colb);
             cursor(cursa+1, 6);
             repeat_char(255, 66, colf, colb);
             cursor(cursa+2, 6);
             repeat_char(255, 66, colf, colb);
             cursor(cursa+3, 6);
             repeat_char(255, 66, colf, colb);
             cursor(cursa+4, 6);
             repeat_char(255, 66, colf, colb);
             cursor(cursa+5, 6);
             repeat_char(255, 66, colf, colb);
             cursor(cursa+6, 6);
             repeat_char(255, 66, colf, colb);
             cursor(2, 8);
          }
          
          void repeat_char(char ch, int howmany, int fcolour, int bcolour)
          {
             union REGS inregs;
          
             inregs.h.ah = 0x09;
             inregs.h.al = ch;
             inregs.h.bh = 0;
             inregs.h.bl = (bcolour << 4) |  fcolour;
             inregs.x.cx = howmany;
          
             int86(0x10, &inregs, &inregs);
          }
          
          void clr_scr(int fcolour, int bcolour)
          {
             union REGS ireg;
          
             ireg.h.ah = 0x07;
             ireg.h.al = 0;
             ireg.h.ch = 0;
             ireg.h.cl = 0;
             ireg.h.dh = 24;
             ireg.h.dl = 79;
             ireg.h.bh = (bcolour <<4) | fcolour;
          
             int86(0x10, &ireg, &ireg);
          
          }
          
          void write_string(char *string, int fcolour, int bcolour, int row,
          			    int column)
          {
             int len = strlen(string);
             int i;
          
             for(i=0; i < len; i++)
             {
          	 cursor(row, column+i);
          	 write_char((char)*(string+i), fcolour, bcolour);
             }
          }
          
          void write_char(char ch, int fcolour, int bcolour)
          {
             union REGS inreg;
          
             inreg.h.ah = 0x09;
             inreg.h.al = ch;
             inreg.h.bh = 0;
             inreg.h.bl = (bcolour << 4) | fcolour;
             inreg.x.cx = 1;
          
             int86(0x10, &inreg, &inreg);
          }
          
          void cursor_off(void)
          {
             union REGS inreg, outreg;
             inreg.h.ah = 1;
             inreg.x.cx = 0x0F00;
          
             int86(0x10, &inreg, &outreg);
          }
          
          void cursor_on(void)
          {
             union REGS inreg, outreg;
             inreg.h.ah = 1;
             inreg.x.cx = 0x0607;
          
             int86(0x10, &inreg, &outreg);
          }
          
          void set_border_colour(int colour = 0)
          {
             union REGS inreg;
          
             inreg.h.ah = 0x0B;
             inreg.h.bh = 0;
             inreg.h.bl = colour;
          
             int86(0x10, &inreg, &inreg);
          }
          
          void dreamt_display(int a, int b)
          {
             char *buff = "DREAM TEAM FOOTBALL";
          
             if((a % 2) == 0)
             {
          	 set_border_colour(b);
          	 clear_prompt(b+2,6,0, b);
          	 clear_prompt((16-b),6,0, b);
          	 write_string(buff,b+1,b,12,29);
             }
             write_string(buff,b+1,b,b+4,b+29);
             write_string(buff,b+1,b,20-b,29-b);
          }

          Comment

          • maradona
            New Member
            • Dec 2006
            • 9

            #6
            Thanks !!!!!!!!
            You are great man and great programmer!!!!! !!

            Comment

            • willakawill
              Top Contributor
              • Oct 2006
              • 1646

              #7
              Originally posted by maradona
              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.

              Comment

              Working...