Solved

URGENT! Is there a possibility to use classic 80x25 (or alternative 80x30) in Delphi 8 for .NET ?

Posted on 2004-08-13
20
353 Views
Last Modified: 2010-04-05
Hi,

How to emulate textmode in Delphi 8 for .NET ? I'm not talking about console here, but about classic direct memory access to 0xB800.
I'm aware that it's not possible to achieve directly, but what about some windows APIs, DirectX maybe ?
What I need is true textmode, not just graphical emulation thru sprites (like 640x400) ?

I don't know, so any thought will be appreciated..

regards,
Kate
0
Comment
Question by:_Katka_
  • 10
  • 6
  • 2
  • +2
20 Comments
 
LVL 17

Expert Comment

by:Wim ten Brink
Comment Utility
Sorry, but in the 32-bits memory model you don't have direct access to the video memory. It doesn't exist. Use a console instead, which is technically speaking a true textmode environment.

And, btw... The old DOS textmode screen never really existed. These were still graphics and it was even possible to draw things in the textmode! I've seen sprite animations and a "graphical" game in textmode. This was just a matter of redefining the sprites that were used for the characters... And at 0xB000 you just said in which order the sprites should be.

It's even worse in your situation. You're using Delphi 8 which will provide you even less access to sensitive memory areas.

But what are you trying to do anyway?
0
 
LVL 10

Author Comment

by:_Katka_
Comment Utility
Thanks, for quick answer..but:

1) I'm the gal who was writing such graphical demos for textmode.. And yeah, it's done thru reserving some characters to fontset change..
2) I'm aware that text-mode is in fact special graphical mode for CGA,EGA internal..
3) Console lacks the ability to manipulate blocks of text and anyway is practically useless unless you just want to writeln the text forward..
4) I'm also aware that there's no possibility to access text/graphical memory directly thru interrupts or mem[] like in good old times..
5) I know that there's possibility to use alternate compilers like (Free Pascal, which is in my current use) which supports the direct memory access even when in LMA..

What I'm trying to do:

1) To get access to true text-mode (to be precise, the one your bios is using) withing Delphi 8..
2) Alternately access any kind of text-mode (I'll be happy even with 640x400) with possibility to directly emulate text-mode (fontset generated as sprites)
3) These conditions for any of those modes must be satisfied:

 3a) have direct access (doesn't mean direct access to memory, but direct access to what I see)
 3b) It have to be able to manipulate blocks of pixels or characters
 3c) Manipulation with single pixel, character
 3d) support color palettes (truecolor doesn't mind) for single element

Practically I want to be able perform the way the FAR Manager did: http://farmanager.com/screens.asp

I'm not working on file manager, but this is the closest example of abilities I need (text-mode related)
Be aware the FAR Manager is written in 32-bit language. I need to know the way he get the access to such textmode (it's not console definitelly).

Kate :)

0
 
LVL 17

Accepted Solution

by:
Wim ten Brink earned 75 total points
Comment Utility
Well, it is very simple. Windows 32 does not have the "true textmode" that you're looking for. It only has support for consoles, and a console is very similar to what you're familiar with from MS-DOS.

However, the console functionality should offer you very similar results. I'm not sure about Delphi 8 but in Delphi 7 you can use the Windows API methods for consoles. More onformation about these functions and related items can be found at MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/console_reference.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/console_functions.asp for a complete list of functions.

And no, you will never have direct access to the console memory because Window's has a completely different memory model, shielding access to these areas.

And the Far manager? It looks like a clone of the Norton Commaner. :)
This look can "easily" be done with the console functions of Windows. All you need to do is write a wrapper around these functions.

Now the bigger problem... How to do this in Delphi 8? Well, I just don't know but assume .NET might have a console assembly somewhere with required functionality. If not, you have to write one yourself, wrapping around this "unsafe" code from the Windows API.
0
 
LVL 10

Author Comment

by:_Katka_
Comment Utility
I'm prepared to write any wrapper to whatever that gives me described abilities with text-mode.. Now in consideration (sorted by elegance):

1) DirectX - DirectDraw wrapper for emulation of text-mode (I'm not much into DirectX and it'll require much of work + I can't find any API for Delphi 8)
2) Your opinion about console - (I'm still not sure if it supports simple GetChar(X,Y):Char, SetChar(X,Y,Char), SetScreen(Buffer) like commands)
3) In case the of emergency (if nothing will work) there's always a standart TCanvas :))
4) EGA/VGA is still inside, so there is always a way to get thru any system to it (I'm not sure how and moreover it causes an instability)

But I'm convinced there's GDI-based textmode, across all versions of Windows.. It's true textmode enough for me ;)

What about that console, is there any proof that is it at least capable of (as mentioned) GetChar,SetChar,SetScreen,GetScreen,SetColor,GetColor,SetBKColor,GetBKColor,ChangeCharacterSet meta-code commands (I figured out that those are all I practically need) ?

Kate :)
0
 
LVL 3

Expert Comment

by:BJThomsen
Comment Utility
Write the functions in a non .net dll and use as unmanaged code in Delphi 8?

Don't know much about it, just something I've heard.
0
 
LVL 14

Expert Comment

by:DragonSlayer
Comment Utility
Goto http://www.overbyte.be/frame_index.html

Download the ICS package, install it, and you will notice that there is a Terminal Emulator component installed. Check out the source code (emulvt.pas) to see how a component is derived from TCustomControl and is even set to handle ANSI emulation (coloring, blinking, etc).



DragonSlayer.
0
 
LVL 10

Author Comment

by:_Katka_
Comment Utility
Hi,

to BJThomsen: Sounds promising have you got some further info ?

to DragonSlayer:

1) ICS package for Delphi 8 .NET doesn't contain TEmulVT component
2) It's not capable of almost none of needed abilities

any other suggestions ?

btw: I downloaded DirectX 9 SDK and MDX is working under Delphi 8 :) but I'm total newbie here and it's not definitely text-mode :(

Kate
0
 
LVL 3

Expert Comment

by:Tyrsis
Comment Utility
Using consoles mentioned above will do everything you need to do.  I am also unclear as to whether Delphi 8 allows access to win32 functions at all, but if it does, then you can do all those functions you mentioned pretty easily.  

Just scanning over it quickly.  All the "Set" functions you need can be done with WriteConsoleOutput() and all the "Get" functions can be done with ReadConsoleOutput().

I would suggest trying that first, as it'll probably do everything you need, before trying to emulate a console mode completely.  
0
 
LVL 10

Author Comment

by:_Katka_
Comment Utility
to Tyris:

That's for sure.. but I downloaded mentioned components and the package for Delphi 8 .NET doesn't contains TEmulVT component.. So I was unable to test it properly,
I determined it has no functionality for me just from sources.. that's (I admit) not sufficient, but anyway it simply doesn't compile under D8..

Kate
0
 
LVL 3

Expert Comment

by:Tyrsis
Comment Utility
Oops, I was talking about Workshop_Alex's response.  Using the Console functionality he lists given in Win32 will allow you to do all the functions you listed.  I don't believe .NET has sufficient support for the Console, so you may have to use unmanaged code to accomplish this.  
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 10

Author Comment

by:_Katka_
Comment Utility
Well I've found some more information about that console and it seems you both were right, but what is needed to be downloaded in order to get it functional ?
0
 
LVL 3

Assisted Solution

by:Tyrsis
Tyrsis earned 160 total points
Comment Utility
Unfortunately, I don't use Delphi.NET, so I'm not entirely certain what needs to be done to create unmanaged code.  Basically all those console functions reside in Kernal32.dll.  Delphi 7 wrapped all the functions in the win32 dlls to allow access to the win32 API.  Since I don't believe you can use win32 code directly in .NET, you'll have to load those functions from the DLL directly, I assume in unmanaged code.  Hopefully someone else who has more experience with win32 and .NET interoperability can expand on this.  Once you figure out how you can get access to those functions in the DLL, all you'll need access to are the following functions:

GetStdHandle(), WriteConsoleOutput() and ReadConsoleOutput().  And possibly a few other functions that you may find handy there.  Basically you just do a

hInHandle := GetStdHandle(STD_INPUT_HANDLE);
hOutHandle := GetStdHandle(STD_OUTPUT_HANDLE);

And you can use those handles in WriteConsoleOutput and ReadConsoleOutput.

I have code for Delphi 7 that I required when writing a few Console Apps to allow moving the cursor and drawing on the console screen.  But they probably won't be any help in Delphi 8.  Hopefully this can put you on the path to discover what you are looking for though.  The links given by Workshop_Alex is a good reference to the WIN32 functions that are required though.

Tyrsis
0
 
LVL 10

Author Comment

by:_Katka_
Comment Utility
Ok.. this sounds really promising I linked GetStdHandle function externally

function GetStdHandle(nStdHandle:Longword):Longint; external 'Kernel32.dll';

and called:

begin
  inHandle:=GetStdHandle(Longword(-10));
  outHandle:=GetStdHandle(Longword(-11));
end;

Is it possible that handles are equal to 0 ?
Do I have to initialize console first somehow (actually it's just common {$APPTYPE CONSOLE} console) ?

Kate
0
 
LVL 3

Expert Comment

by:Tyrsis
Comment Utility
Yes, you should use $APPTYPE CONSOLE.  After you get the handles, they should be different values, though very low values.  Once you successfully get the handles, you should be able to use any of the Console functions that are listed on the MSDN site above.  

Tyrsis
0
 
LVL 10

Author Comment

by:_Katka_
Comment Utility
Both values are zero, but anyway I was able to SetConsoleCursorPosition and WriteConsole using these handles ;) that's positive..
In the end, Windows unit is able to treat those console functions as managed code so there's no need to manually link the Kernel32.dll.

My last question is how to get use of WriteConsoleOutput (I'm not able to setup data buffer properly it's IntPtr [equivalent of managed pointer]) ?

Kate
0
 
LVL 10

Author Comment

by:_Katka_
Comment Utility
Now I noticed, is there a way to change fontset ?
0
 
LVL 3

Expert Comment

by:Tyrsis
Comment Utility
It's probably easier if you used the following functions:

WriteConsoleOutputCharacter()
GetConsoleScreenBufferInfo()
SetConsoleCursorPosition()

These will allow you to move the cursor around the screen and output characters without having to worry about RECTs.  Experiment with these functions, but I think you'll find everything you need to do in the console can be done with them.  

Tyrsis
0
 
LVL 10

Author Comment

by:_Katka_
Comment Utility
The point about WriteConsoleOutput is that I want to generate a buffer (in memory) and then just paste it to the whole console screen..It's faster and in fact single writing of elements is not needed.

What about that fonset change, it'll be also possible to create my user truetype font, but I don't see any SetCurrentConsoleFont function (this is the most important element without it, it has no meaning to me) ?

Kate
0
 
LVL 3

Expert Comment

by:Tyrsis
Comment Utility
Sadly you can't change the fontset in console.  It is a user selectable option when running a console app, but you can't set it pragmatically.  

Basically, if you want a full screen console app, with the ability to change fonts, you'll have to use DirectX, which I can see being a nightmare.  If you don't need it to be full screen, then you can just emulate it by directly drawing the characters onto a canvas, which would be a lot easier.

Sorry I could not be of more assistance.

Tyrsis



0
 
LVL 10

Author Comment

by:_Katka_
Comment Utility
Well, never mind, I'll split up points 160 Tyrsis/75 Workshop_Alex even I'll use managed DirectX 9 in the end, it's pretty easy to use and moreover it'll bring me on the edge of programming (which is cool :), almost no examples provided on net, yet ,:-/). Somehow MDX is much friendlier than its predecessors thus I'm able to grasp it. Actually full library for emulation of textmode works pretty well and HW accelerated. It is NOT an old text-mode but (my gosh) I have to move forward ;).

Thank you all very much for your opinions..

regards,
Kate
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now