News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Convert a com asm to a win32 asm

Started by hfheatherfox07, July 17, 2011, 07:07:01 PM

Previous topic - Next topic

hfheatherfox07

Hi, First off let me apologize if this is not in the 16bit section , but I am trying to know how to  Convert a com asm to a win32 asm , and I am not looking to Convert an already assembled .com to a .exe ....

Is there any body that knows a formula for this? or is really good at it .... I would not even know were to begin ....

But this is sooo Cool  :bg

I saw this and I had to have it, Also is there a way  to include The Unicode Macro so you can have other language characters like Oriental

dedndave

16-bit code doesn't easily convert to 32-bit
in this program, he accesses the video buffer directly
that isn't very practical in 32-bit
also, it is full-screen graphics - that means the display dimensions are fixed
in a win32 environment, windows change sizes, as you know

that doesn't mean it can't be done
you have learned enough to make it happen in a back-buffer, then display it

hfheatherfox07

Quote from: dedndave on July 18, 2011, 12:50:54 AM
he accesses the video buffer directly
that isn't very practical in 32-bit
also, it is full-screen graphics - that means the display dimensions are fixed
in a win32 environment, windows change sizes, as you know

Couple of the examples That I did did not work with windows change size , the window needed to be fixed, I don't mind that....

Quote from: dedndave on July 18, 2011, 12:50:54 AM
you have learned enough to make it happen in a back-buffer, then display it

What gets me is the use of 16 bit registers, how do Convert that? no experience with 16bit code ... "bl" = ? ...is it   edi? what is "al"  "es" ... is it esi?

I have some very very old tuts  that I must find in order to figure this out....
At the risk of sounding stupid ....I guess If you do not ask ...you do not learn... I never compiled a .com before with MASM ... Link some TASM  ans FASM( but they ere the examples that came with the program and I just ran the bat) I don't know much about com's at all ....
From  a compile com bat that I have ... this is what it looks like :

@ECHO OFF
@CLS
@ECHO _
@SET MASMDIR=\MASM32
@SET INCL1=C:\PROGRA~1\MICROS~1\VC98\INCLUDE
@SET INCL2=C:\PROGRA~1\MICROS~1\VC98\MFC\INCLUDE

@SET FN=comasm

@IF EXIST "%FN%.exe" del "%FN%.exe"

@ECHO.
@ECHO þ Compiling resources "%FN%"
%MASMDIR%\BIN\rc.exe rc.rc

@ECHO.
@ECHO þ Compiling the program "%FN%"

%MASMDIR%\BIN\ml /c /coff /Cp /nologo %4 %5 "%FN%.asm"
@IF NOT EXIST "%FN%.obj" GOTO error

@ECHO.
@ECHO þ Linking Program "%FN%"
%MASMDIR%\BIN\Link /SUBSYSTEM:WINDOWS /nologo %3 "%FN%.obj" "rc.res"
@IF NOT EXIST "%FN%.exe" GOTO error

@GOTO end

:error
@ECHO _
@ECHO þ error "%FN%" !!!
@GOTO end

:end

@IF EXIST "rc.res"   del "rc.res"
@IF EXIST "%FN%.obj" del "%FN%.obj"


Is this correct?

Also For the the 32 bit version I would like to add a flickering underscore in front of the text as it is typing ...I seen this done here on the MASM forum but I have  no idea were, it must have been a console app...at the time I passed it ...I figured I will never use it LOL

hfheatherfox07

Ever since I saw this Example, I wanted to know How it is Made .... See the cursor effect?

MichaelW

It's going to be difficult to convert because it's VGA-specific, runs the display in alphanumeric mode, loads a user-specified character set, etc.
eschew obfuscation

hutch--

hfheatherfox07,

This is not what you want to hear but the solution is not to convert it but to create a description of what it should do in 32 bit then simple write that code. The architecture and hardware differences make a close conversion impractical where a rewrite is the fastest and most successful way to get the result.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Neil

I have converted a couple of 16 bit programs to 32 bit & the many problems I came across are well documented in previous posts on this forum. As stated above you cannot address the video buffer directly & there are no interrupts, so all that code has to be rewritten. Some parts of the program can be used by changing register & data sizes (about 25%) the rest as I said is a rewrite. Knowing what I know now I would do as hutch says & start from scratch. I was converting to 32 bit console mode & that was bad enough, a GUI well..... forget it.

bomz

There is no necessity to convert 16 to 32, 16 is good work under 32 system (windows). You want do 32 application that do the same as 16 bit

hfheatherfox07

Quote from: bomz on July 18, 2011, 07:36:30 AM
There is no necessity to convert 16 to 32, 16 is good work under 32 system (windows). You want do 32 application that do the same as 16 bit

Yes

hfheatherfox07

Quote from: hutch-- on July 18, 2011, 03:36:08 AM
hfheatherfox07,

This is not what you want to hear but the solution is not to convert it but to create a description of what it should do in 32 bit then simple write that code. The architecture and hardware differences make a close conversion impractical where a rewrite is the fastest and most successful way to get the result.

LOL I spent 2 days with this straight and came to the same conclusion.... Although this looks like a console app...for sure

Although what I am trying to do is at least get a console app 32 version of this working so I can use
some of the procs , thanks to the consistently updated masm32 version I think I can do a way with the proc to wait and just use "invoke sleep , 1000" for example
Also I am very lucky in that I actually have an example that takes chars an prints it (with font and color if I want ) to a static in win32...
I also noticed that for example little things like the green color is "0A" for light green and "02" for the dark green, In a win32 console app it is "10" for light green although the "02" remains valid
how ever I had one problem that I could not solve on my own

How do I convert: mov es:[di],bh  is it ->  mov esi,byte PTR [edi]  ???

Also How do I easily add a blinking cursor in front of the text as it types? I have an example that replaces the cursor in an edit box with what ever you want and with icons...

Also just out of curiosity  how do I make an MS DOS.pif short cut like this guy did to run console apps full screen? in 32bit?

I'd Love to know if some has an example of that please

Magnum

This matrix com file runs full screen if you "send it" to desktop.

Tasm source included.
Have a great day,
                         Andy

hfheatherfox07

Quote from: Magnum on July 19, 2011, 11:09:50 PM
This matrix com file runs full screen if you "send it" to desktop.

Tasm source included.


Thanks but I am looking to create the com that I have in win32 , that one runs perfect too (nicer) ...don't want a com, I what to make a win32 not a console either ....don't know TASM

Neil

mov es:[di],bh  this is a segment override with es pointing at the start of a memory block (Video buffer perhaps?), di is the offset from the start of that memory block.
You cannot convert this code to 32 bit as there are no segment overrides. Using console mode & the available API's you have complete control of what is displayed (position, colour etc).

MichaelW

Quote from: Neil on July 20, 2011, 08:01:51 AM
You cannot convert this code to 32 bit as there are no segment overrides.

There are segment overrides, but normally the only place they're used is with the FS segment register and exception handling. The problem is that you cannot create your own segments or selectors.

AFAIK doing this as a console app would require a special font. The source includes the bit patterns for the user-specified 9x16 character set. It should be possible to create a bitmap from the patterns, and use the bitmap to draw the characters on a window.
eschew obfuscation

mineiro

Quote from: hfheatherfox07 on July 18, 2011, 02:42:37 AM
What gets me is the use of 16 bit registers, how do Convert that? no experience with 16bit code ... "bl" = ? ...is it   edi? what is "al"  "es" ... is it esi?
... I don't know much about com's at all ....
Dot com files are the most simply,these files don't have a header. They fit only in one segment(like default win32 executables), so I'm saying they have a maximum lenght of 64kb(win32 uses 32 bits, so they can address more space). Dot com files starts every time in offset 100h in memory(one approach is some programs to win32 that have an entrypoint at 401000h).
When you run your .com file, the first line of code that you see are in the address:
XXXX:YYYY (or if you prefer segment:offset)(in ms-dos, offset is 16 bits, in win32, offset is 32 bits, so, in win64 you have offset of 64 bits)
where XXXX is pointed to CS(code segment)(ms-dos choose this value to your program, and put your code in this segment) and YYYY is 0100h(because is a .com file,here is the entrypoint of your program). What have betwen cs:0000 and cs:00ffh is some structure that ms-dos keep(PSP- prefix segment program).
In 16 bits world, eax doesn't exist. So you have to play with AX register. AX register (word = 16 bits) can be div into 2 parts. The higher part is "AH" and the lower part is "AL". So AX = AHAL, each ah and al holds 8 bits. These apply to general registers, like bx,cx,dx.
In ms-dos, you can control all the hardware, so to write something in screen, you can use a ms-dos interruption, but, if you don't like, you can use a bios interruption, but if you don't like, you can write direct in video memory address(you need know their address and actual resolution), but..., you can do your own IO(in/out) manipulation.
Win32 prevent you to write direct in video memory and do some IO instructions in user land.
I have looked the matrix and that code use some bios interruptions (int 10h). Interruptions you can assimilate like libraries(dll) in windows. They can perform functions, and one interruption can offer to you different related functions. So, if you like to call some function, you set up some registers and after do a "int ??h". The contents of registers(generally AX,ah or al) tell what code(function) the interruption will do.
To convert 16 bits code to win32 world, you need find one function inside some dll in windows that correlates with the interruption. Probably, int 10h(video) you can use textout in windows,. The delay you can use settimer... .But you need take care of what one interruption can return to you(it can differ from what one function in windows return to you).
The hard part is just because the program write direct to video memory and you don't have access in user mode. Old guys write in this way to get speed in their code, so, they only set the screen dimensions using interruption and after, deal with a array_screen (collumns x lines).
In the code matrix you have posted, have a line like:
mov es:[di],al
This tell that previously the programmer have put the video segment address in the es register, and used di(like edi, but 16 bits version) to hold some offset (the array of video).
In win32, you generaly don't change the es,cs,ds,ss,gs registers, some exceptions are if you code some SEH(you use fs segment register).

mov ax,0B800h
mov es,ax
Take a look, 0b800h is the video segment address, and the person is moving it to es(extra data segment). So to write something in screen you need only store some bytes in that address:offset, and magicaly, it appear on screen.

Why about segment registers? Well, a .com file can hold cs:0000h to cs:ffffh(16 bits), so if you program get bigger, you need put some data in another segment(not your case, this one is like .exe ms-dos files). If your code is bigger than 64 kb (the segment is fully filled), you start playing with segment registers, because it can hold only 64kb, and when this happens, you need know about memory addressing ways.
Some code can be easyly ported to win32 when they don't call interruptions, or uses some hardware addresses. When this matches, you need preserve the registers used by windows before call that procedure. Another point is when you have IO operations (like receive(in) of printer port some data or send(out) to that port some data). These codes can be ported to windows, but you need deal with device drivers.