Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Need source code put pixel for 16 bit color

If anyone can send me a basic 16bit color putpixel code in pascal I would be very happy so I can try and understand it


Comments

  • First of all, you need to set the video mode using VESA. Mode numbers

    differ by comp, so I'll need to use the following routine to look

    up the 320x240x16b mode I'm looking for...




    Procedure GetVesaInfo;

    var

    S,O,NS,NO:Word;
    begin;

    New(VesaInfo);

    Point2Word(VesaInfo,S,O);

    Mem[S:O] := Ord('V'); Mem[S:O+1] := Ord('B'); Mem[S:O+2] := Ord('E'); Mem[S:O+3] := Ord('2');

    asm;

    MOV AX, 4F00h

    MOV BX, S

    MOV ES, BX

    MOV DI, O

    INT 10h {Call VESA Info, pointed to Array buffer}

    end;

    if (VesaInfo^[1] <> Ord('V')) and (VesaInfo^[1] <> Ord('v')) then VesaPres := False

    else

    begin;

    VesaPres := TRUE;

    VbeFarSeg := MemW[S:O+16]; VbeFarOfs := MemW[S:O+14];

    VesaMaj := VesaInfo^[6]; VesaMin := VesaInfo^[5];

    TotalMem := MemW[S:O+18] * 64; {Number of KB on board}

    NO := MemW[S:(O+6)]; NS := MemW[S:(O+8)]; {Get OEM string address}

    OEMString := '';

    While Mem[NS:NO] <> 0 do

    begin;

    OEMString := OEMString + Chr(Mem[NS:NO]);

    NO := NO + 1;

    end;

    NO := MemW[S:(O+26)]; NS := MemW[S:(O+28)]; {Get OEM string address}

    CardName := '';

    While Mem[NS:NO] <> 0 do

    begin;

    Cardname := Cardname + Chr(Mem[NS:NO]);

    NO := NO + 1;

    end;

    end; {Vesa exists IF}

    end;
    Function ExamineMode(ModeNum:Word): Boolean; {Returns TRUE if 320x240x8}

    var

    S,O:Word;
    begin;

    Point2Word(VesaInfo,S,O);

    asm;

    MOV AX, 4F01h

    MOV CX, ModeNum

    MOV DI, S

    MOV ES, DI

    MOV DI, O

    INT 10h

    end;

    {Window Size correct?}

    ExamineMode := TRUE;

    { Writeln(MemW[S:O+6], ' ', MemW[S:O+18], ' ', Memw[S:O+20], ' ', Mem[S:O+25]);}

    if MemW[S:O+6] <> 64 then ExamineMode := FALSE;

    if MemW[S:O+18] <> 320 then ExamineMode := FALSE;

    if MemW[S:O+20] <> 240 then ExamineMode := FALSE;

    if Mem[S:O+25] <> 16 then ExamineMode := FALSE;

    end;
    Function DriverInit: Boolean;

    {Note: This is MUCH bigger than for Driver13!}

    var

    A,B:Word;
    begin;

    {Search for a usable VESA mode}

    A := 0;

    B := 0;

    While (MemW[VbefarSeg:VbeFarOfs+A] <> $ffff) and (B = 0) do

    if ExamineMode(MemW[VbeFarSeg:VbeFarOfs+A]) = TRUE then B := MemW[VbeFarSeg:VbeFarOfs+A]

    else A := A + 2;

    if B = 0 then DriverInit := FALSE

    else

    begin;

    asm;

    MOV AX, 4F02h

    MOV BX, B

    INT 10h

    end;

    DriverInit := TRUE;

    end;

    end;


    Call GetVesaInfo() and then DriverInit(), to put

    yourself in the video mode. Now that we're there, it

    should be obvious that the screen won't fit in the A000h

    segment all at once (320x240x2 = 153600)

    VESA uses banks as one method of addressing all this

    memory. Only one bank is mapped to the A000h segment at

    a time. You can change them via Function 5h.

    First thing in putting our pixel, we need to determine

    what bank it's in.


    Bank = ((X position * bytes per pixel) + (Bytes per line * Y Position)) DIV 65535


    Bank = ((X*2)+ (Y * 640)) DIV 65535




    Program SetBank(Bank:Byte);

    begin;

    asm;

    MOV AX, 4F05h

    XOR BX, BX

    XOR DH, DH

    MOV DL, Bank

    INT 10h

    end;

    end;


    Then we find the position in the bank:


    Posit = ((X*2) + (Y*640)) MOD 65535


    And just set the pixel:


    MemW[$A000:Posit] := PixelValue


    Matthew Gross

    Acheron@Hotmail.com


    P.S: Didn't have time to test this all the way thru,

    so there may be a bug or two, but that's generally how

    to go about it.


    URL:http://acheronx.resnet.tamu.edu/home/

Sign In or Register to comment.