LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-05-2008, 02:46 PM   #1
gvp87
Member
 
Registered: Mar 2007
Location: Boston
Distribution: Ubuntu Gutsy
Posts: 50

Rep: Reputation: 15
using memset() functions for graphics


I'm pretty new to programming, so I've been reading like, almost every HOWTO on C++.

I'm tring to run a program that uses the memset() function. It compiles fine, but during runtime, i get the ever-notorious "Segementation fault(core dumped)" error - which i've googled and read a million reasons why that error occurs. Usually due to accessing memory that hasn't yet been initialized.

the program sets up MCGA mode, sets up a function to set the screen a certain color, and sets up a funtion to put a pixel on the screen.

i put a small Main() function at the bottom to test out the functions.


#include <iostream>
#include <stdlib.h>
#include <cstring>


char vga[0xffff];

void setMCGA() {
asm("mov $0x13, %ax");
asm("int $0x10");
}

void screenSet(int color) { //int color is a number between 0 and 255

memset(vga, color, 0xffff);//0xffff = 64000
}

void pixelPut (int x, int y, unsigned char color) {

memset(vga-x-(y*320), color, 1);
}

int main() {
setMCGA();
screenSet(200);
pixelPut(300, 200, 0);
return 0;
}


I somehow think that my runtime error is due to my lack of knowledge on the memset() function. I've looked up usage for it, and I believe I'm doing this right, but apparently not.

Does anyone know??

thanks
giuseppe
 
Old 02-05-2008, 04:24 PM   #2
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
A quick look tells me this is the suspect code
Quote:
void pixelPut (int x, int y, unsigned char color) {
memset(vga-x-(y*320), color, 1);
}

Last edited by dmail; 02-05-2008 at 04:31 PM. Reason: bold tags not working in code or quote tags??
 
Old 02-05-2008, 05:10 PM   #3
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
I agree with dmail.

To elaborate:
There's no such thing as "x=320, y=200" in a 320x200 video buffer. The coordinate range is "x=0..319, y=0..199".

'Hope that helps .. pSM
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
graphic function with memset() gvp87 Programming 1 01-31-2008 12:04 AM
warning: passing argument 2 of ‘memset’ makes integer from pointer without a cast nasim751 Programming 3 01-30-2008 09:16 AM
LXer: OpenOffice.org Calc functions, part 1: Understanding functions LXer Syndicated Linux News 0 03-31-2007 12:01 PM
memset vs char arr initialization syseeker Programming 4 03-29-2006 09:01 AM
pointers to functions/member functions champ Programming 2 03-28-2003 06:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration