Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Bitmaps Posted by magaman on 23 May 2005 at 6:04 PM
I would like to know the source code on how to call bitmaps images in a program and print it to the screen.



TMM
Report
Re: Bitmaps Posted by Phat Nat on 25 May 2005 at 5:57 PM
: I would like to know the source code on how to call bitmaps images in a program and print it to the screen.
:
:
:
: TMM
:


Just wrote about this. Try the link below:

http://www.programmersheaven.com/c/msgboard/read.asp?Board=16&MsgID=302690&Setting=A9999F0001

This shows for 8-bit, but the higher ones just don't have a palette usually (although they can I believe).
Also, I posted a unit to show bitmaps here that I wrote. Not perfect, but a good start.

http://www.programmersheaven.com/c/msgboard/read.asp?Board=16&MsgID=300751&Setting=A9999F0003

Enjoy,
Phat Nat

Report
Re: Bitmaps Posted by Phat Nat on 29 May 2005 at 7:32 PM
: : I would like to know the source code on how to call bitmaps images in a program and print it to the screen.
: :
: :
: :
: : TMM
: :
:
:
: Just wrote about this. Try the link below:
:
: http://www.programmersheaven.com/c/msgboard/read.asp?Board=16&MsgID=302690&Setting=A9999F0001
:
: This shows for 8-bit, but the higher ones just don't have a palette usually (although they can I believe).
: Also, I posted a unit to show bitmaps here that I wrote. Not perfect, but a good start.
:
: http://www.programmersheaven.com/c/msgboard/read.asp?Board=16&MsgID=300751&Setting=A9999F0003
:
: Enjoy,
: Phat Nat

I was just writing a game that used my bitmap unit and it worked great until I loaded about 5 bitmaps, then it crashed/gave divide by zero errors & other unexpected results. Turns out I have a mistake in my unit (UNBELIEVABLE!). Anyways, if you're going to use it it has this fix:


     With Info.BMPHeader Do
     If (Bits = 8) Then
     Begin
{        BlockRead(F, Colors[X], PalCount*4);}
{ This should be: }
        BlockRead(F, Colors[0], PalCount*4);


        For X := 0 to PalCount Do
            Begin
                 If DoColors Then SetPal(X, Colors[X,3]*63 DIV 255, Colors[X,2]*63 DIV 255, Colors[X,1]*63 DIV 255);
            End;
        Reset(F,1);
        BlockRead(F, Junk, BitMapOffset);
        Z := (Width*Bits) SHR 3;
          While Z MOD(4) <> 0 Do Inc(Z);
        For Y := Height-1 downto 0 Do


Nothing like loading data into a random spot in memory to crash a program ;)

Enjoy,
Phat Nat
Report
Re: Bitmaps Posted by magaman on 29 May 2005 at 7:48 PM
: : : I would like to know the source code on how to call bitmaps images in a program and print it to the screen.
: : :
: : :
: : :
: : : TMM
: : :
: :
: :
: : Just wrote about this. Try the link below:
: :
: : http://www.programmersheaven.com/c/msgboard/read.asp?Board=16&MsgID=302690&Setting=A9999F0001
: :
: : This shows for 8-bit, but the higher ones just don't have a palette usually (although they can I believe).
: : Also, I posted a unit to show bitmaps here that I wrote. Not perfect, but a good start.
: :
: : http://www.programmersheaven.com/c/msgboard/read.asp?Board=16&MsgID=300751&Setting=A9999F0003
: :
: : Enjoy,
: : Phat Nat
:
: I was just writing a game that used my bitmap unit and it worked great until I loaded about 5 bitmaps, then it crashed/gave divide by zero errors & other unexpected results. Turns out I have a mistake in my unit (UNBELIEVABLE!). Anyways, if you're going to use it it has this fix:
:
:
: 
:      With Info.BMPHeader Do
:      If (Bits = 8) Then
:      Begin
: {        BlockRead(F, Colors[X], PalCount*4);}
: { This should be: }
:         BlockRead(F, Colors[0], PalCount*4);
: 
: 
:         For X := 0 to PalCount Do
:             Begin
:                  If DoColors Then SetPal(X, Colors[X,3]*63 DIV 255, Colors[X,2]*63 DIV 255, Colors[X,1]*63 DIV 255);
:             End;
:         Reset(F,1);
:         BlockRead(F, Junk, BitMapOffset);
:         Z := (Width*Bits) SHR 3;
:           While Z MOD(4) <> 0 Do Inc(Z);
:         For Y := Height-1 downto 0 Do
: 

:
: Nothing like loading data into a random spot in memory to crash a program ;)
:
: Enjoy,
: Phat Nat
:
thx
and can u tell me like the commands to call the bitmaps in the program
a demo program will be fine.
thx

TMM
Report
Virtual Screens Posted by Phat Nat on 16 Jun 2005 at 6:18 PM
This message was edited by Phat Nat at 2005-6-16 18:25:40

: I would like to know the source code on how to call bitmaps images in a program and print it to the screen.
:
:
:
: TMM


Well, since eyou have that figured out, I'm gonna post some Virtual Screen Routines. This will allow you up to 10 Virtual Screens (Although memory probably won't!). Usually you only need 1-3 anyways.
Remember to Save the Code below as VSCREENS.PAS or change the unit name to match the file name.

UNIT VScreens;

INTERFACE

{ Wait for the Monitor Beam to reach the top of the screen }
PROCEDURE WaitRetrace;
{ Clears the Chosen Video Screen to the given color }
PROCEDURE CLRVID(Where : Word;Color : Byte);
{ Tries to allocate "NumPages" Virtual Screens. Returns actual # allocated }
FUNCTION  GetVideoPages(NumPages : Byte) : Byte;
{ Used at the end of the program to free the Virtual Screen Memory }
PROCEDURE DisposeVideoPages;
{ Copies the Video Page from "Source" to "Dest" }
PROCEDURE CopyPage(Source,Dest : Word);

TYPE
    VPage = Array[0..63999] Of Byte;
    VPagePtr = ^VPage;

VAR
   VirScr        : Array[1..10] Of VPagePtr;
   VAddr         : Array[1..10] Of Word;

IMPLEMENTATION

VAR
   NumVidPages   : Byte;

PROCEDURE WaitRetrace; Assembler;
ASM
    Mov dx,3DAh
@l1:
    In al,dx
    And al,08h
    Jnz @l1
@l2:
    In al,dx
    And al,08h
    Jz  @l2
END;

PROCEDURE CLRVID; Assembler;
ASM
   Mov Di, Where
   Mov Es, Di
   Xor Di, Di
   Mov Al, Color
   Mov Ah, Al
   Mov Cx, 32000
   REP STOSW
END;

FUNCTION GetVideoPages;
Begin
     NumVidPages := 0;
     While (NumPages > 0) and (MaxAvail > 64000) Do
     Begin
          Inc(NumVidPages);
          Dec(NumPages);
          New(VirScr[NumVidPages]);
          VAddr[NumVidPages] := Seg(VirScr[NumVidPages]^);
     End;
     GetVideoPages := NumVidPages;
End;

PROCEDURE DisposeVideoPages;
Begin
     While NumVidPages > 0 Do
     Begin
          Dispose(VirScr[NumVidPages]);
          Dec(NumVidPages);
     End;
End;

PROCEDURE CopyPage; Assembler;
ASM
   Push Ds
   Cld
   Mov Si, Source
   Mov Ds, Si
   Xor Si, Si
   Mov Di, Dest
   Mov Es, Di
   Xor Di, Di
   Mov Cx, 32000
  @Transfer:
   LODSW
   STOSW
   Loop @Transfer
   Pop Ds
END;

Begin
End.


These are fairly fast routines for Virtual Screens. I've used them for a long time, so now you can enjoy too. Hmmm, just looking at my code, I think I could've made a faster CopyPage() Procedure. Here's a faster one (uses 32-bit copy instead of 16-bit copy):

PROCEDURE CopyPage; Assembler;
ASM
   Push Ds
   Cld
   Mov Si, Source
   Mov Ds, Si
   Xor Si, Si
   Mov Di, Dest
   Mov Es, Di
   Xor Di, Di
   Mov Cx, 16000
  @Transfer:
   db $66
   LODSW
   db $66
   STOSW
   Loop @Transfer
   Pop Ds
END;


>NOTE<
Just ran a test. On my computer 60,000 VScreen Copies takes 7.9 sec with the first procedure and only 4.1 sec with the new one. sweet.
>NOTE<


A Simple program that uses them would look like this:
PROGRAM TestScreens;
USES Crt, VScreens;

CONST
     VGA = $A000;

VAR
   X : Byte;

PROCEDURE DrawBox(X,Y : Word; Size, Color : Byte; Where : Word);
VAR
   X1,Y1 : Byte;
Begin
     For Y1 := 0 to Size-1 Do
       For X1 := 0 to Size-1 Do
          Mem[Where:X+X1+(Y+Y1)*320] := Color
End;

Begin
     If GetVideoPages(1) <> 1 Then       { Get Memory }
     Begin
          WriteLn('Not Enough Memory!');
          Halt;
     End;
     ASM
        Mov Ax, $13        { Get into Graphics 320x200x256 }
        Int $10
     END;

     { Draw a moving Box, no virtual Screens }
     { I am using 2 WaitRetrace, because otherwise it's too fast and You can't even see the box }
     Repeat
           WaitRetrace;
           ClrVid(VGA,0);
           WaitRetrace;
           DrawBox(X,0,10,12,VGA);
           Inc(X);
     Until Keypressed;
     While Keypressed Do Readkey;

     { Draw a moving Box, using a virtual Screen }
     Repeat
           ClrVid(VAddr[1],0);
           DrawBox(X,0,10,12,VAddr[1]);
           WaitRetrace;
           CopyPage(VAddr[1],VGA);
           Inc(X);
     Until Keypressed;
     While Keypressed Do Readkey;

     ASM
        Mov Ax, $3         { Return to Text Mode }
        Int $10
     END;
     DisposeVideoPages;    { Release Memory }
End.


If you have any questions, just post them.

Phat Nat






 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.