flat assembler
Message board for the users of flat assembler.

Index > Windows > graphic modes?

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
macoln



Joined: 17 Sep 2007
Posts: 6
macoln
Hi all, I'm trying to port the simple vga graphics code from the series by Tim Trussell, of which the first post is
http://groups.google.com/group/comp.lang.forth/browse_thread/thread/ffbe3ac707eee2b0/de6bb8c0f51a9c89

to the Forth that I use (Reva Forth: www.ronware.org/reva) which is built from fasm. First of all I have to translate from a different implementation of data stack, but more importantly, how can I call int10h from Windows?

Here is my effort so far:
Code:
macro PROC xt {
  align 4
xt:    ; the code itself goes here...
}

macro ENDP xt {
}

PROC setmode ;( mode --)
    mov ebx,eax
    xor eax,eax
    mov al,bl
    int 10h
    ret
ENDP setmode

PROC plot ;( x y c --)
    mov ebx,[esi]    ; dx=y
    mov ecx,[esi+04] ; cx=x
    xor ebx,ebx      ; bx=page#
    mov ah,12        ; ah=Plot Pixel function
    int 10h          ; do it
    ret
ENDP plot

PROC CPortOut ;( c addr --)
    mov edx,eax
    mov eax,[esi]
    out dx,al
    ret
ENDP CPortOut

PROC CPortIn ;( addr -- c)
    mov edx,eax
    xor eax,eax
    in al,dx
    ret
ENDP CPortIn
    


Switch to Forth code:
Code:
: GetPalette ( c# -- r g b)
    $03C7 CPortOut        | --
    $03C9 CPortIn         | r
    $03C9 CPortIn         | r g
    $03C9 CPortIn ;       | r g b
    
Post 17 Sep 2007, 09:39
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
are you trying to do this in Windows? It won't work...
Post 17 Sep 2007, 09:54
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
macoln



Joined: 17 Sep 2007
Posts: 6
macoln
Why?

What can I do to draw simple graphics under windows without resorting to external libraries?
Post 17 Sep 2007, 13:11
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
You HAVE to use system libraries. Imagine that every application that is currently running on your computer would switch mode itself and try to draw full screen itself...

Closest you can get to it is using something called DIB, or DirectDraw.
Post 17 Sep 2007, 14:12
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
and it is for that that you need to make a new int 10h handler when you launch a multitask environment to manage the calling of screen functions
Post 17 Sep 2007, 20:25
View user's profile Send private message Visit poster's website Reply with quote
Master0fAsm



Joined: 01 Sep 2007
Posts: 11
Location: Darlington, South Carolina [USA]
Master0fAsm
When a PE file is run, it has this instruction in its code:
Code:
CLI        ; clear interrupts
    


Windows disables DOS interrupts, so:
Code:
    mov ebx,eax
    xor eax,eax
    mov al,bl
    int 10h 
    

just won't work.
Post 17 Sep 2007, 20:30
View user's profile Send private message Yahoo Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Simply DO NOT USE INTERRUPTS IN WINDOWS. Use Windows API, or some it's wrapper.

By the way, BIOS interrupt handler is too only a "external library", just like WinAPI is.

MasterOfAsm: What you wrote is complete nonsense. Windows DOES NOT disable interrupt flag, and disabling interrupt flag has nothing to do with calling interrupts with "int" instruction.
Post 17 Sep 2007, 20:48
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Master0fAsm, the purpose of CLI instruction is not to disable the INT instruction but to disable maskable EXTERNAL interrupts, so if some hardware attempts to signal an IRQ, the CPU will not stop the execution of the current program for starting to execute the appropiate interrupt handler. And CLI is a privileged instruction, on WinXP at least your PE program will crash if you attempt to execute it.

Actually you can call software interrupts on WinNT, check http://www.ctyme.com/intr/rb-4249.htm . But definetively is not the way because Microsoft doesn't really supports using Int 2E and hence you are risking your program to not work on some versions of Windows (Win9x/Me, future NT versions, ...).
Post 17 Sep 2007, 21:00
View user's profile Send private message Reply with quote
Master0fAsm



Joined: 01 Sep 2007
Posts: 11
Location: Darlington, South Carolina [USA]
Master0fAsm
Quote:

MasterOfAsm: What you wrote is complete nonsense. Windows DOES NOT disable interrupt flag, and disabling interrupt flag has nothing to do with calling interrupts with "int" instruction.

1. You missed the point. 32-bit programming is way different than 16-bit DOS programming. Instead of using interrupts in 32-bit programming, you have a Application Programmers Interface to do most tasks, e.g., displaying a message box. So, calling DOS to do something when your in 32-bit programming is pretty useless since you have the Windows API to assist you.

2. I read somewhere in a PE program (showing how PE files were formatted from scratch) where it had the CLI instruction:
Code:
CLI       ; disable DOS interrupts
    

Possibly, I was mistaken to have thought that I meant ALL (hardware and software) interrupts are disabled. Only DOS services\functions\interrupts are disabled.

Then again, I'm only a clueless newbie...
Post 17 Sep 2007, 21:22
View user's profile Send private message Yahoo Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
Quote:
MasterOfAsm: What you wrote is complete nonsense. Windows DOES NOT disable interrupt flag, and disabling interrupt flag has nothing to do with calling interrupts with "int" instruction.
You missed the point. 32-bit programming is way different than 16-bit DOS programming. Instead of using interrupts in 32-bit programming, you have a Application Programmers Interface to do most tasks, e.g., displaying a message box. So, calling DOS to do something when your in 32-bit programming is pretty useless since you have the Windows API to assist you.
:O
man, reread post you was responding to... I said exactly same thing as you in my post(s). Which point did I miss?

Also FYI, "int 10" is not calling DOS, it is calling BIOS, and it is not "useless", it is more like "impossible".

Quote:
2. I read somewhere in a PE program (showing how PE files were formatted from scratch) where it had the CLI instruction:

That one hacky program does it, doesn't mean that Windows does it.

Quote:
Possibly, I was mistaken to have thought that I meant ALL (hardware and software) interrupts are disabled. Only DOS services\functions\interrupts are disabled.

Nonsense again. Only hardware interrupts are disabled by CLI. DOS provided interrupt handlers for some of both hardware and software interrupts, but these are not present in windows at all. And again, "int 10" is not a DOS interrupt anyway.

Quote:
Then again, I'm only a clueless newbie

Then my advice is to only post if you are sure about what you are going to post. Posting nonsense doesn't give you a good name, and may confuse others. Instead, start by reading everything, write your own simple stuff, ask when you have some problem etc. After a while, you will have more experience and then you can help others.
Post 17 Sep 2007, 21:37
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
smoke



Joined: 16 Jan 2006
Posts: 42
smoke
BIOS interrupts can be called but you need to be in the real mode (bit 0 in cr0 register that tells if the processor is running in protected or realmode..). though i dont know what would happen to all the other applications if mode is changed ...
Post 18 Sep 2007, 14:57
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
smoke: This won't work, and even if you could make it work after ENORMOUS work, then it would still be very ugly hack. And it will definitively require some driver.
Post 18 Sep 2007, 15:49
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
smoke



Joined: 16 Jan 2006
Posts: 42
smoke
yeah exactly ... i suppose you could make it work if you make a driver (that raises to the highest irql(so it interrupts the entire system and protects it from screwing up) and then writes to the screen..). Smile
Post 18 Sep 2007, 16:28
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
if you already have a driver, then doing it this way is a stupid idea:
1. there already are mechanisms in Windows to call BIOS (altough undocummented i quess)
2. creating v86 virtual machine (like NTVDM does) is relativily easy...
Post 18 Sep 2007, 17:23
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
smoke



Joined: 16 Jan 2006
Posts: 42
smoke
yeah I suppose it is preety silly to code a demo that runs in ring0 Smile I think you have a point there Smile
Post 18 Sep 2007, 18:41
View user's profile Send private message Reply with quote
macoln



Joined: 17 Sep 2007
Posts: 6
macoln
In his tutorials, the author uses a Forth that operates under DOS-protected mode environment. Using this method he can call the int 10. Does that sound right? If so, I'd like to find a way to enter this mode, so I can follow his tutorials using Reva Forth instead of his other one that uses its own assembler (I can't translate it to FASM well).
Post 23 Sep 2007, 13:56
View user's profile Send private message Reply with quote
Aux



Joined: 27 Aug 2007
Posts: 10
Aux
Let me say a few words on this topic.

1. If you are making Windows application (or application for any other protected mode OS like Linux, Mac OS, BeOS and others), then your application CAN NOT DIRECTLY ACCESS ANY HARDWARE! That includes interrupt (both software and hardware), memory, ports and so on. You can use ONLY API of your operating system. This is because applications run in ring3 and all priveleged commands are available ONLY to ring0 applications! No CLI, no INT, no CPUID and so on.

2. In protected mode OSes ONLY OS kernel and kernel-mode drivers run in ring0! And writting windows driver is not so easy and your book will not help you.

3. DOS applications under Windows are running inside NTVDM emulator which EMULATES all hardware stuff! BUT YOU CAN NOT ACCESS HARDWARE DIRECTLY ANYWAYS! You can write DOS application and try to destroy interrupt table or overwrite all memory - it will not happen.

4. Win95/98/Me technically are NOT operating systems, DOS is still under them, so you can destroy interrupt table there. You can even hook TLS/TLD tables and do whatever you want (:

5. DPMI is DOS Protected Mode Interface. It is kind of addon for MS DOS so 32bit apps can run without Windows. And there you have full access for everything. But ONLY when you are running DPMI application inside clean DOS (not NTVDM or DOSBox).

So what can You do? Install DOS and test your apps there. Install DOS inside VMWARE and run your apps there inside emulated environment. Also you can install Win98, but still you will need to write DOS apps. Or you can start learning WinAPI and forget about everything you just read in your book.
Post 24 Sep 2007, 21:11
View user's profile Send private message Reply with quote
macoln



Joined: 17 Sep 2007
Posts: 6
macoln
Great explanation, thanks!

Is there some code I can look at for how to enter DPMI under NTVDM?
Post 25 Sep 2007, 08:56
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
same as you did in DOS. NTVDM is just a DOS emulator.
Post 25 Sep 2007, 09:32
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Aux



Joined: 27 Aug 2007
Posts: 10
Aux
yes, ntvdm emulates dos with dpmi. but remember, that you should compile your program as dos app, not windows one.
Post 25 Sep 2007, 17:13
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.