Solved

question regard biosequip() and how change bg,fg color

Posted on 2011-02-24
10
457 Views
Last Modified: 2012-05-11
I'm trying to learn how to rewrite the video display for ms-dos, but it's not working...I don't want to use pokeb(), I just want to use a far pointer can you please help here is my code

NOTE:

I'm using turboC 16bit for far pointer, so no worries there that I'm using the wrong compiler as I have already tested far pointers before with a different program.

I would imagine that my problem has to do with the fact that each column consist of 16 bit 8 for character and another 8 for attributes.

I know that the high 4 bits are for the background and the low 4 bits are for the foreground
then we have as you can see inside my struct
1 bit ==> blink
3 bits==>background
1 bit==>intensity
3bits==> foreground

when I assign the union of the struct which is x.att_byte to my far pointer(*position) how do I know that I'm adding the right sequince let's say I want
no blink
white background
no intensity
black foreground
so ==> 0 000 0 111 ==> 00000111

I know there is an 8 color and 16 color system, I'm assuming this is an 8 color system how to know if it's 8 or 16? and which colors is assigned to which bit?
#include <conio.h>
#include <dos.h>
#include <stdlib.h>
#include <bios.h>

char far *position;
int offset;
int row;
int col;
int seg;

#define black 8
#define white 15


///////////prototype///////////
char get_attribute(char , char);
//////////////////////////////////////
struct attrib_bits
{
int fg;
int bg;
int intensity;
int blink;
} attribute;

union attribute
{
struct attrib_bits att_bits;
char att_byte;
};

void disp_init()
{

directvideo = 1;
seg = (biosequip() & 0x30) == 0x30 ? 0xB000 : 0xB800 ;


}

void display(int row, int col,char ch)
{

offset = 160 * row + col * 2;
position = (char*) MK_FP(seg,offset);
//#ifdef using_far_pointer
union attribute x;
x.att_bits.blink = 1;
x.att_bits.bg = white;
x.att_bits.intensity = 1;
x.att_bits.fg = 3;
*position= x.att_byte;
//*position= get_attribute(x.att_bits.bg,x.att_bits.fg);
*position++= ch ;
//#endif
}

#ifdef use_get_attribute_func
char get_attribute(char bg, char fg)
{
return (bg<<4) | fg;
}
#endif
//don't want to use pokeb()
/* 
pokeb(seg,offset,ch);
pokeb(seg,offset+1,attribute);
*/

//#ifdef _testvideo
void main()
{
disp_init();
display(1,10,'s');
display(2,5,'l');  
display(3,4,'f');
}
//#endif

Open in new window

0
Comment
Question by:logicallayer
  • 6
  • 4
10 Comments
 
LVL 45

Accepted Solution

by:
Kdo earned 500 total points
ID: 34971184
Hi LL,

Wow.  You're certainly taxing my memory with 16-bit C and direct console I/O.  :)

There are a set of built-in functions to read and write a single location on the screen.  You can also read/write a "window" (rectangular block) on the screen.  The data to/from this "window" is 2 bytes per cell.  One byte contains the Ascii character, the other byte is color, blink, underline, etc.

Would that work for you?


Kent
0
 

Author Comment

by:logicallayer
ID: 34971812
loool...sorry about that but it's an assignment in school.

I understand what you are saying but still doesn't help me to solve the problem.

for example check this code for me please and tell me if you see anything wrong with it
#include <conio.h>
#include <dos.h>
#include <stdlib.h>
#include <bios.h>

char far *position;
int offset;
int row;
int col;
int seg;

#define black 0
#define white 7



int bg = white;
int fg = black;
int byte;


void disp_init()
{

directvideo = 1;
seg = (biosequip() & 0x30) == 0x30 ? 0xB000 : 0xB800 ;
}

void display(int row, int col,char ch)
{
//this offset is right for sure
offset = 160 * row + col * 2;
//pretty sure I'm setting the position char ptr address right
position = (char*) MK_FP(seg,offset);

//here I'm not sure what I'm doing

//I added my bg shifted it by 4 and added the fg
//then assigned it to byte of type char
byte = (bg<<4) | fg;

*position = byte;

*position++= ch ;

}

void main()
{
disp_init();
display(1,10,'s');
display(2,5,'l'); 
display(3,4,'f');
}

Open in new window

0
 

Assisted Solution

by:logicallayer
logicallayer earned 0 total points
ID: 34971862
btw, variable byte is of type char

char byte,

the code above has a typo
0
 

Author Comment

by:logicallayer
ID: 34971936
forgot to mention, my anticipation that I'm not getting any letters on the screen because my attribute is being set wrong and it's black by default this why I'm trying to fix it. but I could be wrong about that....

0
 
LVL 45

Assisted Solution

by:Kdo
Kdo earned 500 total points
ID: 34972540
Hi LL,

If you can acquire the address of the console buffer, you should be able to write directly to the buffer and see it reflected on the monitor.


  char *Screen;   // Address of console buffer

  *Screen = 0x05;
  *(Screen+1) = 'A';

That should put an 'A' on the screen, though I don't recall the color palette.

I'm not sure if modern 32-bit and 64-bit Windows operating systems actually have a console buffer any more.  It might be that you need to run it on a 16-bit O/S.  (I'll dig around a bit.)


Kent
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Assisted Solution

by:logicallayer
logicallayer earned 0 total points
ID: 34979411
I had to go and check with the prof

first there is another mistake in the code as the character comes before the attribute in the offset

so it should be

*position = ch;
*position++ = attribute

although I have already switched them many times before this it wasn't the actual problem with my code...the problem was

to cast the MK_FP() as a char far* instead of just char*

position = (char far*) MK_FP(seg,offset);

thanks for trying kod, you get points for the effort

0
 
LVL 45

Expert Comment

by:Kdo
ID: 34981811
Hi LL,

Silly byte swapping.... :)

  *position = ch;
  *position++ = attribute;

Load the two bytes into an integer and the architecture swaps the bytes.  (I told you it has been quite a while....)


Your solution:

  position = (char far*) MK_FP(seg,offset);


I'm really surprised that it works.  position is declared as [char far *] and MK_FP should return a far pointer, though probably type [void].  I cannot image how the recast is helping.  Perhaps you made another change at the same time that the recast was inserted into the source?

Also, I find it very interesting that Windows still has a console buffer in the 32 and/or 64 bit O/S.  I learned something here.  Thanks!


Good Luck,
Kent
0
 

Author Comment

by:logicallayer
ID: 34984142
yea, I knew that ch has to come before attribute I just was using my prof notes and it had swaped so I was trying both I guess,

yes I'm sure it's the casting, do you know I'm using Turboc for this assignment but when I was doing an assignment before it, I did it half way using borland 5.02 until I found out that it has a problem using debugging if you are using 16bit environment, anyway the thing is when I used to compile with borland without casting MK_FP to char far* it used to give me error...almost sure this how it was I will give it a try at some point to confirm but I still remember it gave a hard time then and for the irony I repeated the same mistake :D

but thanks for your help , I'm giving you 250pts for the effort, and let me know if I can come of any help if you need a memory refreshment with 16bit programming as it's the main point behind the course and I wouldn't mind to go through some discussion as the course is about programming a kernel so in this assignment we did rewrite the keyboard keystroke software,clock software, a queue all using interrupt functions. this why I wanted to learn how to handle this using far pointer instead of using pokeb() as probably it will come handy in later assignments
0
 
LVL 45

Expert Comment

by:Kdo
ID: 34984225
Hi LL,

That's rather ambitious.  :)  I hope that you enjoy the course.

I'm going to track down my old Borland compiler and see what trouble I can create.  Memory is an awful thing to lose....


Kent
0
 

Author Closing Comment

by:logicallayer
ID: 35015376
my comment is the actual solution to my problem as casting MK_FP() with char* instead of char far* was causing problems, how even kdo comments where very right and could be helpful for future referencing to this problem.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now