flat assembler
Message board for the users of flat assembler.
Index
> Windows > graphic modes? Goto page 1, 2 Next |
Author |
|
macoln 17 Sep 2007, 09:39
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 |
|||
17 Sep 2007, 09:39 |
|
vid 17 Sep 2007, 09:54
are you trying to do this in Windows? It won't work...
|
|||
17 Sep 2007, 09:54 |
|
macoln 17 Sep 2007, 13:11
Why?
What can I do to draw simple graphics under windows without resorting to external libraries? |
|||
17 Sep 2007, 13:11 |
|
edfed 17 Sep 2007, 20:25
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
|
|||
17 Sep 2007, 20:25 |
|
Master0fAsm 17 Sep 2007, 20:30
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. |
|||
17 Sep 2007, 20:30 |
|
vid 17 Sep 2007, 20:48
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. |
|||
17 Sep 2007, 20:48 |
|
LocoDelAssembly 17 Sep 2007, 21:00
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, ...). |
|||
17 Sep 2007, 21:00 |
|
Master0fAsm 17 Sep 2007, 21:22
Quote:
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... |
|||
17 Sep 2007, 21:22 |
|
vid 17 Sep 2007, 21:37
Quote:
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. |
|||
17 Sep 2007, 21:37 |
|
smoke 18 Sep 2007, 14:57
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 ...
|
|||
18 Sep 2007, 14:57 |
|
vid 18 Sep 2007, 15:49
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.
|
|||
18 Sep 2007, 15:49 |
|
smoke 18 Sep 2007, 16:28
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..).
|
|||
18 Sep 2007, 16:28 |
|
vid 18 Sep 2007, 17:23
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... |
|||
18 Sep 2007, 17:23 |
|
smoke 18 Sep 2007, 18:41
yeah I suppose it is preety silly to code a demo that runs in ring0 I think you have a point there
|
|||
18 Sep 2007, 18:41 |
|
macoln 23 Sep 2007, 13:56
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).
|
|||
23 Sep 2007, 13:56 |
|
Aux 24 Sep 2007, 21:11
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. |
|||
24 Sep 2007, 21:11 |
|
macoln 25 Sep 2007, 08:56
Great explanation, thanks!
Is there some code I can look at for how to enter DPMI under NTVDM? |
|||
25 Sep 2007, 08:56 |
|
vid 25 Sep 2007, 09:32
same as you did in DOS. NTVDM is just a DOS emulator.
|
|||
25 Sep 2007, 09:32 |
|
Aux 25 Sep 2007, 17:13
yes, ntvdm emulates dos with dpmi. but remember, that you should compile your program as dos app, not windows one.
|
|||
25 Sep 2007, 17:13 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.