Help me please....

This is a discussion on Help me please.... within the A Brief History of Cprogramming.com forums, part of the Community Boards category; What wrong here? Code: #include <conio.h> #include <dos.h> #define WIDTH 640 #define HEIGHT 480 typedef unsigned char byte; byte *SCR=(byte ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    3

    Unhappy Help me please....

    What wrong here?
    Code:
    #include <conio.h>
    #include <dos.h>
    
    #define WIDTH  640
    #define HEIGHT 480
    
    typedef unsigned char  byte;
    
    byte *SCR=(byte *) MK_FP (0xA000,0); 
    
    void svga() {
    	 asm	mov ax,0x4f02;
    	 asm	mov bx,0x101;
    	 asm	int 0x10;
    }
    
    void textmode() {
    	 asm	mov ax,0x03;
    	 asm	int 0x10;
    }
    
    void putpixel (int x, int y, byte color){
    		unsigned long pixel_offset = 1.0 * (y * 640 + x);
    		int bank_num = (pixel_offset >> 16);
    		asm mov ax, 0x4F05;
    		asm mov bx, 0x0;
    		asm mov dx, bank_num;
    		asm int 0x10;
    		SCR[(pixel_offset & 0xFFFF)] = color;
    }
    
    int main(void) {
    	svga();
    
    	byte color=0;
    	for (int y=0;y<HEIGHT;y++)  {
    		color=0;
    		for(int x=0;x<WIDTH;x++)
    			putpixel(x,y,color++);
    	}
    
    	getch();
    	textmode();
    	return 0;
    }

  2. #2
    twm
    twm is offline
    root
    Join Date
    Sep 2003
    Posts
    232
    Are you gonna tell us what OS/compiler you use? Or do we have to guess and most likely ignore you due to lack of useful information?
    The information given in this message is known to work on FreeBSD 4.8 STABLE.
    *The above statement is false if I was too lazy to test it.*
    Please take note that I am not a technical writer, nor do I care to become one.
    If someone finds a mistake, gleaming error or typo, do me a favor...bite me.
    Don't assume that I'm ever entirely serious or entirely joking.

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    3
    compiler: turbo c
    os: dos

    this is the result:
    http://uploaded.fresh.co.il/3f65febb34c60223.rar

  4. #4
    Registered User
    Join Date
    Sep 2003
    Posts
    3
    ....
    this code do his job but very slowly
    Code:
    void putpixel(int x, int y, byte color) {
    	 asm	mov ah,0x0c;
    	 asm	mov al,color;
    	 asm	mov cx,x;
    	 asm	mov dx,y;
    	 asm	mov bx,0x01;
    	 asm	int 0x10;
    }

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    I would say your problem is here w/o even testing the code:

    unsigned long pixel_offset = 1.0 * (y * 640 + x);
    Why 1.0??? This forces a conversion to double, y is double, 640 is double, and x is double. Then you are assigning a double to an unsigned long which is yet another conversion, probably one in which the result is 0 since you cannot assign a double to an unsigned long.

    As well you cannot shift a double left or right but you can an unsigned long -> again, why are you using a double? There is no need.

    1*(y*640+x)
    or
    1*((y<<9)+(y<<7)+x)

    is the same as

    (y*640+x)
    or
    ((y<<9)+(y<<7)+x)


    One times any number is that number. Why the 1.0????

    My guess is that if you print out pixel_offset it will be 0.


    Here is what you are doing:

    Converting all operands to doubles.
    Trying to convert the entire result into an unsigned long.


    All SVGA functions can be done using integer arithmetic - no need for doubles or floats.

    Code:
    ;put original y into eax
    mov    eax,[y]
    
    ;multiply eax by 512
    shl      eax,9
    
    ;put original y into eax
    mov    ebx,[y]
    
    ;multiply ebx by 128
    shl      ebx,7
    
    ;add result of ebx to eax - (y*512)+(y*128) = (y*(512+128))
    ;=(y*640)
    add     eax,ebx
    
    ;add x to eax = (y*640)+x
    ;leave result in eax
    add     eax,x
    or in C:
    Code:
    pixel_offset=((y<<9)+(y<<7)+x);

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21