problem with VESA putpixel

problem with VESA putpixel

Post by Conr » Sun, 10 Jan 1999 04:00:00



Hi,

I'm trying to make a game that uses vesa graphics. I wrote this
procedure in TP 6.0:

Procedure PutPixel(X, Y: Integer; Color: Byte);
Begin
     Asm
        MOV AX,$a000
        MOV ES,AX
        MOV BX,Y
        MOV AX,800
        MUL BX
        MOV DI,AX
        ADD DI,X                        ; dx holds the vesa bank

        XOR BX,BX

        CALL VesaFunc

        MOV AL, Color

        STOSB
     End;
End;

where VESAFUNC is declared as

Var VesaFunc: LongInt;

to serve as DWORD far pointer to vesa bank procedure, somewhere in
memory. I'm getting this pointer thru vesa function 01h (vesa
information), bytes 12 to 14 in the buffer.

There is no problem with this putpixel procedure. It works fine.
Then, i wrote the same procedure, but in ASM:

.MODEL SMALL
.386
.CODE

EXTRN VesaFunc: DWORD
PUBLIC PutPixel

PutPixel PROC NEAR X : WORD, Y : WORD, COLOR : BYTE
        MOV AX,0a000h
        MOV ES,AX
        MOV BX,Y
        MOV AX,800
        MUL BX
        MOV DI,AX
        ADD DI,X

        XOR BX,BX

        CALL VesaFunc

        MOV AL, Color
        STOSB

        RET
PutPixel ENDP

END

and declared it in pascal as

Procedure PutPixel(X, Y: Integer; Color: Byte); external;

But when i use this procedure in assembler, my computer stops
responding. If i use the 05h vesa interupt function instead the far
call function, the assembler procedure works fine.

Why is this procedure in assembler not working? Does anyone know a
good sample source that uses VESA in ASM? Thank you for yor help.

 
 
 

problem with VESA putpixel

Post by Stefan Goehle » Sun, 10 Jan 1999 04:00:00


Quote:>> Hi,

>> I'm trying to make a game that uses vesa graphics. I wrote this
>> procedure in TP 6.0:

>> Procedure PutPixel(X, Y: Integer; Color: Byte);
>> Begin
>>      Asm
>>         MOV AX,$a000
>>         MOV ES,AX
>>         MOV BX,Y
>>         MOV AX,800
>>         MUL BX
>>         MOV DI,AX
>>         ADD DI,X                        ; dx holds the vesa bank

>>         XOR BX,BX

>>         CALL VesaFunc

>>         MOV AL, Color

>>         STOSB
>>      End;
>> End;

>> where VESAFUNC is declared as

>> Var VesaFunc: LongInt;

>> to serve as DWORD far pointer to vesa bank procedure, somewhere in
>> memory. I'm getting this pointer thru vesa function 01h (vesa
>> information), bytes 12 to 14 in the buffer.

>> There is no problem with this putpixel procedure. It works fine.
>> Then, i wrote the same procedure, but in ASM:

>> .MODEL SMALL
>> .386
>> .CODE

>> EXTRN VesaFunc: DWORD
>> PUBLIC PutPixel

>> PutPixel PROC NEAR X : WORD, Y : WORD, COLOR : BYTE
>>         MOV AX,0a000h
>>         MOV ES,AX
>>         MOV BX,Y
>>         MOV AX,800
>>         MUL BX
>>         MOV DI,AX
>>         ADD DI,X

>>         XOR BX,BX

>>         CALL VesaFunc

>>         MOV AL, Color
>>         STOSB

>>         RET
>> PutPixel ENDP

>> END

>> and declared it in pascal as

>> Procedure PutPixel(X, Y: Integer; Color: Byte); external;

>> But when i use this procedure in assembler, my computer stops
>> responding. If i use the 05h vesa interupt function instead the far
>> call function, the assembler procedure works fine.

>> Why is this procedure in assembler not working? Does anyone know a
>> good sample source that uses VESA in ASM? Thank you for yor help.

>  This doesn't really answer your question, but it's much simpler in VBE
>2.0. No bankswitching or anything - just one nice big block of memory
>for the video card. The programming ease of mode 13h with decent screen
>resolutions.

Have you seen that he uses Borland Pascal??
Even if he could access LFB easily, he should include also support
for banked modes.
The answer why this putpixel of him doesn't work, may be the fact
that ES and/or DI are destroyed after the function call.
He could write it this way:

 PutPixel PROC NEAR X : WORD, Y : WORD, COLOR : BYTE
         MOV   BX,Y
         MOV   AX,800
         MUL   BX
         ADD   AX,X
         XOR   BX,BX
         PUSH  AX

         CALL VesaFunc     ;far from optimal!

         MOV   AX,segA000h
         MOV   BL,Color    ;pairable in this order -> faster
         MOV   ES,AX
         POP   DI
         MOV   ES:[DI],BL  ;mostly faster, since DI isn't increased
         RET
 PutPixel ENDP

Conrad, what you should do to increase the speed is to save after
each switched bank the bank you switched to. Now you can check in
each procedure if the bank is already setted. If so, overjump the
switching, otherwise switch. Also you need to take into
consideration, that the bytes per line in 800 pixel modes is NOT
always 800 bytes nor a bank is always sized 64K. Check out the
vesa comments about the window granularity and fix that.

Bye,
Stefan
---
please remove the P in my email-adress to answer me


 
 
 

problem with VESA putpixel

Post by Conr » Sun, 10 Jan 1999 04:00:00


On Sat, 9 Jan 1999 17:32:54 +0100, "Stefan Goehler"


>>> Hi,

>>> I'm trying to make a game that uses vesa graphics. I wrote this
>>> procedure in TP 6.0:

>>> Procedure PutPixel(X, Y: Integer; Color: Byte);
>>> Begin
>>>      Asm
>>>         MOV AX,$a000
>>>         MOV ES,AX
>>>         MOV BX,Y
>>>         MOV AX,800
>>>         MUL BX
>>>         MOV DI,AX
>>>         ADD DI,X                        ; dx holds the vesa bank

>>>         XOR BX,BX

>>>         CALL VesaFunc

>>>         MOV AL, Color

>>>         STOSB
>>>      End;
>>> End;

>>> where VESAFUNC is declared as

>>> Var VesaFunc: LongInt;

>>> to serve as DWORD far pointer to vesa bank procedure, somewhere in
>>> memory. I'm getting this pointer thru vesa function 01h (vesa
>>> information), bytes 12 to 14 in the buffer.

>>> There is no problem with this putpixel procedure. It works fine.
>>> Then, i wrote the same procedure, but in ASM:

>>> .MODEL SMALL
>>> .386
>>> .CODE

>>> EXTRN VesaFunc: DWORD
>>> PUBLIC PutPixel

>>> PutPixel PROC NEAR X : WORD, Y : WORD, COLOR : BYTE
>>>         MOV AX,0a000h
>>>         MOV ES,AX
>>>         MOV BX,Y
>>>         MOV AX,800
>>>         MUL BX
>>>         MOV DI,AX
>>>         ADD DI,X

>>>         XOR BX,BX

>>>         CALL VesaFunc

>>>         MOV AL, Color
>>>         STOSB

>>>         RET
>>> PutPixel ENDP

>>> END

>>> and declared it in pascal as

>>> Procedure PutPixel(X, Y: Integer; Color: Byte); external;

>>> But when i use this procedure in assembler, my computer stops
>>> responding. If i use the 05h vesa interupt function instead the far
>>> call function, the assembler procedure works fine.

>>> Why is this procedure in assembler not working? Does anyone know a
>>> good sample source that uses VESA in ASM? Thank you for yor help.

>>  This doesn't really answer your question, but it's much simpler in VBE
>>2.0. No bankswitching or anything - just one nice big block of memory
>>for the video card. The programming ease of mode 13h with decent screen
>>resolutions.
>Have you seen that he uses Borland Pascal??
>Even if he could access LFB easily, he should include also support
>for banked modes.
>The answer why this putpixel of him doesn't work, may be the fact
>that ES and/or DI are destroyed after the function call.
>He could write it this way:

> PutPixel PROC NEAR X : WORD, Y : WORD, COLOR : BYTE
>         MOV   BX,Y
>         MOV   AX,800
>         MUL   BX
>         ADD   AX,X
>         XOR   BX,BX
>         PUSH  AX

>         CALL VesaFunc     ;far from optimal!

>         MOV   AX,segA000h
>         MOV   BL,Color    ;pairable in this order -> faster
>         MOV   ES,AX
>         POP   DI
>         MOV   ES:[DI],BL  ;mostly faster, since DI isn't increased
>         RET
> PutPixel ENDP

>Conrad, what you should do to increase the speed is to save after
>each switched bank the bank you switched to. Now you can check in
>each procedure if the bank is already setted. If so, overjump the
>switching, otherwise switch. Also you need to take into
>consideration, that the bytes per line in 800 pixel modes is NOT
>always 800 bytes nor a bank is always sized 64K. Check out the
>vesa comments about the window granularity and fix that.

>Bye,
>Stefan
>---
>please remove the P in my email-adress to answer me


Hi again

I've checked your idea. ES and DI registeres are not destroyed after a
function call. There is nothing wrong with STOSB instruction. The
program halts when executing CALL. (if I delete the STOSB line from
the code, the program still halts. But if i delete CALL from it, it
does not).

I know my code is not optimized, and i know i should insert a check
for current bank, but all this optimizing does not help if the CALL is
not working...

Oh, and what's wrong with borland pascal??

Thanks anyway...

 
 
 

problem with VESA putpixel

Post by Stefan Goehle » Sun, 10 Jan 1999 04:00:00


Hello!

Quote:>I've checked your idea. ES and DI registeres are not destroyed after a

As you call directly the winfuncptr. But believe me, there are alot
of situations where you need your OWN procedure which is to be
called to switch a bank.

Quote:>function call. There is nothing wrong with STOSB instruction. The
>program halts when executing CALL. (if I delete the STOSB line from
>the code, the program still halts. But if i delete CALL from it, it
>does not).

I never told about stosb made any problems. It's just rubbish to
call it if you don't need DI to be increased. That just steals
valueable CPU time.

Quote:>I know my code is not optimized, and i know i should insert a check
>for current bank, but all this optimizing does not help if the CALL is
>not working...

For this I'd need to have the sources myself.

Quote:>Oh, and what's wrong with borland pascal??

Also this you misunderstood. There's nothing wrong. Maybe you
don't know about the fact that BP is NOT directly able to
access a linear frame buffer in Vesa2, like Bob told you about,
so he gave you a suggestion which may confuse you.

Bye,
Stefan
---
please remove the P in my email-adress to answer me

 
 
 

problem with VESA putpixel

Post by Osmo Ronkan » Sun, 10 Jan 1999 04:00:00




>Hi,

>I'm trying to make a game that uses vesa graphics. I wrote this
>procedure in TP 6.0:

>Procedure PutPixel(X, Y: Integer; Color: Byte);
>Begin
>     Asm
>        MOV AX,$a000
>        MOV ES,AX
>        MOV BX,Y
>        MOV AX,800
>        MUL BX
>        MOV DI,AX
>        ADD DI,X                    ; dx holds the vesa bank

>        XOR BX,BX

>        CALL VesaFunc

>        MOV AL, Color

>        STOSB
>     End;
>End;

>where VESAFUNC is declared as

>Var VesaFunc: LongInt;

>to serve as DWORD far pointer to vesa bank procedure, somewhere in
>memory. I'm getting this pointer thru vesa function 01h (vesa
>information), bytes 12 to 14 in the buffer.

>There is no problem with this putpixel procedure. It works fine.
>Then, i wrote the same procedure, but in ASM:

>.MODEL SMALL

Is that mode compatible with TP?

Quote:>.386

Why 386?

Quote:>.CODE

>EXTRN VesaFunc: DWORD
>PUBLIC PutPixel

>PutPixel PROC NEAR X : WORD, Y : WORD, COLOR : BYTE
>        MOV AX,0a000h

Where do you establish the stack frame? Have you checked whether the
parameters haver to be declared in reversed order?

- Show quoted text -

Quote:>        MOV ES,AX
>        MOV BX,Y
>        MOV AX,800
>        MUL BX
>        MOV DI,AX
>        ADD DI,X

>        XOR BX,BX

>        CALL VesaFunc

>        MOV AL, Color
>        STOSB

>        RET
>PutPixel ENDP

Where do you remove the parameters.

You might try .Model Tpascal. That could solve the problems.

Though IMO the right way to learn ASM is to do everything by hand at
first (no models, parameters defined in procedures etc.) and when one
knows how to do it so then one can start learning models etc.

Use TASM /L to check what the assembler generates.

Btw Such a thing is not the way to start constructing graphics. Make at
least line the basic element then make sure that you do not need to
call the VESA function on each pixel.

Osmo

 
 
 

problem with VESA putpixel

Post by Wolfgang Ehrhar » Sun, 10 Jan 1999 04:00:00




Quote:>Hi,

>I'm trying to make a game that uses vesa graphics. I wrote this
>procedure in TP 6.0:
[Snip]

>where VESAFUNC is declared as

>Var VesaFunc: LongInt;

>to serve as DWORD far pointer to vesa bank procedure, somewhere in
>memory. I'm getting this pointer thru vesa function 01h (vesa
>information), bytes 12 to 14 in the buffer.

>There is no problem with this putpixel procedure. It works fine.
>Then, i wrote the same procedure, but in ASM:

>.MODEL SMALL
>.386
>.CODE

>EXTRN VesaFunc: DWORD
>PUBLIC PutPixel

>PutPixel PROC NEAR X : WORD, Y : WORD, COLOR : BYTE

[snip]

Hi,

The variable VesaFunc is declared in the Pascal data segment, so your
ASM code should look like

.MODEL SMALL, PASCAL
.386

.DATA
EXTRN VesaFunc: DWORD

.CODE
PUBLIC PutPixel

PutPixel PROC NEAR X : WORD, Y : WORD, COLOR : BYTE
...

Hope, that helps

Wolfgang
-----
In order to e-mail me a reply to this message, you will have
to remove PLEASE.REMOVE from the address shown in the header.

 
 
 

problem with VESA putpixel

Post by Bob » Mon, 11 Jan 1999 04:00:00



> Hi,

> I'm trying to make a game that uses vesa graphics. I wrote this
> procedure in TP 6.0:

> Procedure PutPixel(X, Y: Integer; Color: Byte);
> Begin
>      Asm
>         MOV AX,$a000
>         MOV ES,AX
>         MOV BX,Y
>         MOV AX,800
>         MUL BX
>         MOV DI,AX
>         ADD DI,X                        ; dx holds the vesa bank

>         XOR BX,BX

>         CALL VesaFunc

>         MOV AL, Color

>         STOSB
>      End;
> End;

> where VESAFUNC is declared as

> Var VesaFunc: LongInt;

> to serve as DWORD far pointer to vesa bank procedure, somewhere in
> memory. I'm getting this pointer thru vesa function 01h (vesa
> information), bytes 12 to 14 in the buffer.

> There is no problem with this putpixel procedure. It works fine.
> Then, i wrote the same procedure, but in ASM:

> .MODEL SMALL
> .386
> .CODE

> EXTRN VesaFunc: DWORD
> PUBLIC PutPixel

> PutPixel PROC NEAR X : WORD, Y : WORD, COLOR : BYTE
>         MOV AX,0a000h
>         MOV ES,AX
>         MOV BX,Y
>         MOV AX,800
>         MUL BX
>         MOV DI,AX
>         ADD DI,X

>         XOR BX,BX

>         CALL VesaFunc

>         MOV AL, Color
>         STOSB

>         RET
> PutPixel ENDP

> END

> and declared it in pascal as

> Procedure PutPixel(X, Y: Integer; Color: Byte); external;

> But when i use this procedure in assembler, my computer stops
> responding. If i use the 05h vesa interupt function instead the far
> call function, the assembler procedure works fine.

> Why is this procedure in assembler not working? Does anyone know a
> good sample source that uses VESA in ASM? Thank you for yor help.

  This doesn't really answer your question, but it's much simpler in VBE
2.0. No bankswitching or anything - just one nice big block of memory
for the video card. The programming ease of mode 13h with decent screen
resolutions.

  You can download a (shareware) VBE 2 driver for Sci-tech software's
homepage :

  www.scitechsoft.com

        - Bob

 
 
 

problem with VESA putpixel

Post by Jason Burgo » Mon, 11 Jan 1999 04:00:00





>>Hi,

>>I'm trying to make a game that uses vesa graphics. I wrote this
>>procedure in TP 6.0:
>>There is no problem with this putpixel procedure. It works fine.
>>Then, i wrote the same procedure, but in ASM:

>>.MODEL SMALL

>Is that mode compatible with TP?

Yes, as long as the functions are declared and called as near

Quote:>You might try .Model Tpascal. That could solve the problems.

Borland don't recommend this anymore. Better to use:

.MODEL SMALL,PASCAL

for modules that only contain functions that are only referenced from the
IMPLEMENTATION section, or

.MODEL LARGE,PASCAL

for asm modules that contain global functions (declared in the INTERFACE
section of a unit).

If you have a mix you can always use the assembler's NEAR or FAR directive
when declaring a PROC.

Quote:>Though IMO the right way to learn ASM is to do everything by hand at
>first (no models, parameters defined in procedures etc.) and when one
>knows how to do it so then one can start learning models etc.

IMO you are better off using BASM (TP's built-in assembler) for learning the
basics. One you feel brave enough to use TASM you should IMO use models and
parameters in procedures from day 1 (if they are required), as not doing so
makes the code very messy and more low-level than it needs to be. The
following is a general template for writing ASM for TP. It uses TASM's IDEAL
mode which I would strongly recommend, as it is less ambiguous that the
default MASM compatible mode:

IDEAL
Model Small,Pascal
P386N ; if you want to use 386 instructions
LOCALS

DATASEG

; Declare externals (Global variables declared in your Pascal code) here.
eg:

extrn SvgaBank   : dword          ; Current 1'st Video Window Image offset

ENDS

CODESEG

; Declare your Public's and code here. eg:

  public   CalcVidXY8a            ; 256 colour packed-pixel (no broken
lines)

proc CalcVidXY8a

             mov   eax,[SvgaBank]
             ...etc
             ret
endp CalcVidXY8a

ENDS

Quote:>Btw Such a thing is not the way to start constructing graphics. Make at
>least line the basic element then make sure that you do not need to
>call the VESA function on each pixel.

Agreed. Horizontal Line is the first building block of a graphics library.

Jay
--

Jason Burgon - author of Graphic Vision

http://www.jayman.demon.co.uk

 
 
 

problem with VESA putpixel

Post by Christian Froeschli » Tue, 12 Jan 1999 04:00:00



> EXTRN VesaFunc: DWORD
> PUBLIC PutPixel

> PutPixel PROC NEAR X : WORD, Y : WORD, COLOR : BYTE
>         MOV AX,0a000h
>         MOV ES,AX
>         MOV BX,Y
>         MOV AX,800
>         MUL BX
>         MOV DI,AX
>         ADD DI,X

>         XOR BX,BX

>         CALL VesaFunc

These things sometimes make knots in your brain, but
I think you are jumping into your DWORD variable.

Try :

          CALL [VesaFunc]

   __/  __/   -  Christian Froeschlin  -
  /    /
 /     _/     * If you eliminate the impossible, whatever remains, *
___/ _/       * however improbable, must be the bug !              *

 
 
 

problem with VESA putpixel

Post by Conr » Tue, 12 Jan 1999 04:00:00


Quote:>.MODEL TPASCAL
>.386
>.DATA
>EXTRN VesaFunc: DWORD
>.CODE
>PUBLIC PutPixel

>PutPixel PROC NEAR X : WORD, Y : WORD, COLOR : BYTE
>        MOV AX,0a000h
>        MOV ES,AX
>        MOV BX,Y
>        MOV AX,800
>        MUL BX
>        MOV DI,AX
>        ADD DI,X

>        XOR BX,BX

>        CALL [VesaFunc]

>        MOV AL, Color
>        STOSB

>        RET
>PutPixel ENDP

>END

Hi

This is my modifed code. It's working fine now.

Thanks a lot for all your help!

Bye ( until the next problem :) )
---------------------------------------------------
Computers make very fast, very accurate mistakes...


http://www.geocities.com/SiliconValley/Lab/2503    
---------------------------------------------------

 
 
 

problem with VESA putpixel

Post by Herman Dulli » Fri, 15 Jan 1999 04:00:00


Quote:>>PutPixel PROC NEAR X : WORD, Y : WORD, COLOR : BYTE
>>        MOV AX,0a000h
>>        MOV ES,AX
>>        MOV BX,Y
>>        MOV AX,800
>>        MUL BX
>>        MOV DI,AX
>>        ADD DI,X

>>        XOR BX,BX

>>        CALL [VesaFunc]

>>        MOV AL, Color
>>        STOSB

>>        RET
>>PutPixel ENDP

One remark on this code, it assumes too much: (write) window at
0A0000h, window size 64KB.
Use the values found in the ModeInfoBlock structure. They may
vary per VBE implementation.

Herman

 
 
 

problem with VESA putpixel

Post by Osmo Ronkan » Sun, 24 Jan 1999 04:00:00




>>Though IMO the right way to learn ASM is to do everything by hand at
>>first (no models, parameters defined in procedures etc.) and when one
>>knows how to do it so then one can start learning models etc.

>IMO you are better off using BASM (TP's built-in assembler) for learning the
>basics. One you feel brave enough to use TASM you should IMO use models and
>parameters in procedures from day 1 (if they are required), as not doing so
>makes the code very messy and more low-level than it needs to be.

The point of using ASM is to get low level. I hate those models as it is
hard to remember what model does what. I really do not get one can
learn ASM well without getting hands dirty. Giving modern assemblers to
someone who learns ASM is like giving a calculator to kid who learns
math. Too bad that computers with hex wheel interface are not available
anymore :-)

Osmo

 
 
 

problem with VESA putpixel

Post by Osmo Ronkan » Sun, 24 Jan 1999 04:00:00





>> EXTRN VesaFunc: DWORD
>> PUBLIC PutPixel

>> PutPixel PROC NEAR X : WORD, Y : WORD, COLOR : BYTE
...

>>         CALL VesaFunc

>These things sometimes make knots in your brain, but
>I think you are jumping into your DWORD variable.

That is not the case. What you propose is identical to what he wrote.

Quote:>Try :

>          CALL [VesaFunc]

Osmo
 
 
 

1. Asm language putpixel for 640x480x256 (VESA 101h) mode?

I'm trying to write a putpixel routine for 640x480x256 (VESA 101h)
mode in assembly.
        .A.) Is this the best mode to use? Is there a better way to
access a (relatively) standard 640x480x256 mode? The material I'm
reading is a bit old.
        .B.) My main problem is the memory, Video memory starts at
0A000h right?, for mode 13h, all you need is 64k of memory, but for
640x480x256 you need to swap the memory banks or something. I
understand why this is necessary, I just have no idea how to do it.
        .C.) Is this bank switching (?) specific to the video card
or is it standard?

Any help would be greatly appreciated.
Please reply as soon as possible, as I am currently scaming my way on
here at work and will not have access for much longer. (after 25th)

2. VL library and Galileo

3. Fast PUTPIXEL IN VESA?

4. Fractals

5. VESA PUTPIXEL?

6. WANTED BMP FILES COMPRESSION SOFTWARES

7. Fast Vesa putpixel?

8. @@@ VESA VESA VESA @@@

9. 32bit vesa calls & vesa 2.0+

10. Diamond FireGL 1000 Dos Vesa mode problems

11. VESA Problem with Moray 2.0