Re: [fpc-pascal]Direct writes to console buffer
In reply to your message of August 3, 2003 I'm trying to port some old Turbo Pascal programs to Windows 32-bit console utilities. They write directly to the screen buffer, which in the DOS world an array of Word starting at ptr(SegB800,0) (for a color display) or ptr(SegB000,0) for a monochrome one. Now, as Windows console utilities, I don't suppose it's so easy to get a pointer to the upper left corner of the console window, or is it? There's an additional complication... ME, NT, 2000 and XP won't let you write directly to the screen memory. You'll probably need to re-work the screen access to use the through-the-drivers approach unless you are only interested in having your stuff work on 95 and 98. - L D Blake ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal]Direct writes to console buffer
On Sun, Aug 03, 2003 at 02:52:57AM -0400, L D Blake wrote: In reply to your message of August 3, 2003 I'm trying to port some old Turbo Pascal programs to Windows 32-bit console utilities. They write directly to the screen buffer, which in the DOS world an array of Word starting at ptr(SegB800,0) (for a color display) or ptr(SegB000,0) for a monochrome one. Now, as Windows console utilities, I don't suppose it's so easy to get a pointer to the upper left corner of the console window, or is it? There's an additional complication... ME, NT, 2000 and XP won't let you write directly to the screen memory. You'll probably need to re-work the screen access to use the through-the-drivers approach unless you are only interested in having your stuff work on 95 and 98. In addition, I suggest using SDL which will work for windows. SDL is probably a much better approach than trying to directly access video RAM. And to makes things easier for you, once you learn to use SDL, you could write a wrapper module so you don't have to even rewrite your old programs :) cheers James - L D Blake ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal -- - -Zero Defect Software Engineers Group - ZDSEG - -You need only two tools. WD-40 and duct tape. -If it doesn't move and it should, use WD-40. -If it moves and shouldn't, use the tape. ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal]Direct writes to console buffer
Rich Pasco wrote: I'm trying to port some old Turbo Pascal programs to Windows 32-bit console utilities. They write directly to the screen buffer, which in the DOS world an array of Word starting at ptr(SegB800,0) (for a color display) or ptr(SegB000,0) for a monochrome one. Now, as Windows console utilities, I don't suppose it's so easy to get a pointer to the upper left corner of the console window, or is it? Anu suggestions would be appreciated. - Rich Unit Video is exactly what you are looking for - it lets you write/read characters and their attributes (text color + background + blink attribute) directly to/from a buffer in memory and then use simple UpdateScreen procedure to flush contents of this memory buffer to the console. This way you can write console programs using the same approach as under DOS (with these ptr(SegB800,0) / ptr(SegB000,0)) BUT it works under many platforms - in particular, it works under Win32. For more information, look at the FPC documentation for this unit. Regards, -- Michalis Kamburelis [EMAIL PROTECTED] http://www.camelot.homedns.org/~michalis/ ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal]Direct writes to console buffer
James Mills wrote: In addition, I suggest using SDL which will work for windows. SDL is probably a much better approach than trying to directly access video RAM. And to makes things easier for you, once you learn to use SDL, you could write a wrapper module so you don't have to even rewrite your old programs :) What is SDL? Where can I get documentation about it? Google turned up Simple DirectMedia Layer -- http://www.libsdl.org/ -- is that what you meant? It could also be Specification and Description Language -- http://www.sdl-forum.org/SDL/ -- but that seems less likely. - Rich ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal]Direct writes to console buffer
Karl Brandt wrote: Grab the win32 API documentation and take a look at Console Functions: ReadConsoleOutput, WriteConsoleOutput ... Yes, I saw those, thanks.. But they don't support treating the screen buffer as an linear array of words, starting with a pointer to the first (upper left corner). For new code, these would be the way to go, but for porting my old code, they're too high-level. - Rich ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal]Direct writes to console buffer
On Sun, Aug 03, 2003 at 07:26:35AM -0700, Rich Pasco wrote: James Mills wrote: In addition, I suggest using SDL which will work for windows. SDL is probably a much better approach than trying to directly access video RAM. And to makes things easier for you, once you learn to use SDL, you could write a wrapper module so you don't have to even rewrite your old programs :) What is SDL? Where can I get documentation about it? Google turned up Simple DirectMedia Layer -- http://www.libsdl.org/ -- is that what you meant? Yes this is the SDL Library. There is also an FPC port of this library (version 1.2.0.0). I cannot find the home page for it though, so if you can't find it also, I'll mail it to you. Also I don't think there are any suitable tutorials (The ones provided in the FPC port aren't that great) for using SDL with FPC except for the C documentation at the libsdl website and others you may find. cheers James It could also be Specification and Description Language -- http://www.sdl-forum.org/SDL/ -- but that seems less likely. Not this. - Rich ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal -- - -Zero Defect Software Engineers Group - ZDSEG - -You need only two tools. WD-40 and duct tape. -If it doesn't move and it should, use WD-40. -If it moves and shouldn't, use the tape. ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal]Direct writes to console buffer
Rich Pasco wrote: Michalis Kamburelis wrote: Unit Video is exactly what you are looking for - it lets you write/read characters and their attributes (text color + background + blink attribute) directly to/from a buffer in memory and then use simple UpdateScreen procedure to flush contents of this memory buffer to the console. This way you can write console programs using the same approach as under DOS (with these ptr(SegB800,0) / ptr(SegB000,0)) BUT it works under many platforms - in particular, it works under Win32. For more information, look at the FPC documentation for this unit. This unit looks most like what I want to do, except that the document says that it should not be used together with the CRT unit, and that doing so will result in very strange behaviour, possibly program crashes. Since the rest of my code uses the CRT unit (probably even more than I use the direct video stuff), I am stuck. - Rich That's true, unit Video can't be used together with Crt unit because they both use the system console and using them both at the same time could make one of them not synchronized with the current console state (and maybe there are also others, possibly some platform-specific issues that I'm not aware of). One solution is to implement the Crt functionality using the Video unit - in most cases it should be pretty simple, e.g. you can implement GotoXY by calling Video.SetCursorPos, you can implement WhereX / WhereY to return the values of Video.CursorX / CursorY etc. Functions dealing with keyboard (ReadKey and KeyPressed) may be implemented using the Keyboard unit. Functions dealing with sound (Sound, NoSound) are not implemented properly in FPC Win32 Crt, and I can't help you with these - I don't know how to implement such functions properly using Win32 API, there seems to be no easy solution for this. The only thing that remains and that is a litlle more difficult is to force Write[ln] functions to be also implemented by writing to screen using the Video unit. You can do this by changing some internal fields within Output variable (typecasting it to TTextRec) at the initialization of your program/unit, you should see examples of this in the implementation of Crt unit. Then you can implement Write[ln] by writing string to the VideoBuf, starting at current cursor position, and using some default color attributes (if you still want to be compatible with Crt, yoy should declare some global variable named TextAttr for this purpose). Similarly, if you want to handle Read[ln] calls by yourself (to implement them using the mixture of Video/Keyboard units) you can do similiar trick with the Input variable. And remember to add calls to the Video.UpdateScreen procedure to flush VideoBuf to console at appropriate times, since this is something entirely new that was not needed with Crt unit. If you still want to use direct memory access to write to the console AND use Crt-like calls at the same time then this looks to be the best solution. Hope this helps, -- Michalis Kamburelis [EMAIL PROTECTED] http://www.camelot.homedns.org/~michalis/ ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal]Direct writes to console buffer
On Sun, 3 Aug 2003, Michalis Kamburelis wrote: Rich Pasco wrote: Michalis Kamburelis wrote: Unit Video is exactly what you are looking for - it lets you write/read characters and their attributes (text color + background + blink attribute) directly to/from a buffer in memory and then use simple UpdateScreen procedure to flush contents of this memory buffer to the console. This way you can write console programs using the same approach as under DOS (with these ptr(SegB800,0) / ptr(SegB000,0)) BUT it works under many platforms - in particular, it works under Win32. For more information, look at the FPC documentation for this unit. This unit looks most like what I want to do, except that the document says that it should not be used together with the CRT unit, and that doing so will result in very strange behaviour, possibly program crashes. Since the rest of my code uses the CRT unit (probably even more than I use the direct video stuff), I am stuck. - Rich That's true, unit Video can't be used together with Crt unit because they both use the system console and using them both at the same time could make one of them not synchronized with the current console state (and maybe there are also others, possibly some platform-specific issues that I'm not aware of). One solution is to implement the Crt functionality using the Video unit - in most cases it should be pretty simple, e.g. you can implement GotoXY by calling Video.SetCursorPos, you can implement WhereX / WhereY to return the values of Video.CursorX / CursorY etc. Functions dealing with keyboard (ReadKey and KeyPressed) may be implemented using the Keyboard unit. The idea is that in future the CRT unit will be 100% based on the video and keyboard units. The only reason it is not yet so is that none of the core team has had time to do it. It should be a pretty simple job, but it just takes time. Michael. ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal