-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Games development on ELKS #871
Comments
The topic of porting graphic libraries and 90's games to ELKS should be preceded by a more substantial discussion regarding the graphics in ELKS in general. I never had occasion to work with nx before meeting ELKS (my past experience with NuttX from which nx originated never went beyond the nsh command line sessions), so I can't really say how good or bad this library is. I just have impression that I already saw things more mature than nx, like Photon on QNX or DirectFB on Linux. Even things like GUILib for multiplatform SDL library seemed more mature despite all of its limitations. And there is also John Elliott's SdSDL library for SDL which emulates GSX and VDI graphics that originates from CP/M and DOS (before MS Windows). And that was the direction I was looking for: John Elliot's fork of GSX/VDI-based GEM (the mighty FreeGEM) works really lovely on both of my XT machines (one 8088, one 8086 based), far better than nx on ELKS on the same machines, though I suspect the secret is in the underlying OS: there's no multitasking in DOS, hence GEM can consume all of the CPU time for handling mouse-driven graphics operations. Yet anyway, it only shows that doing GUI on XT is possible and the user experience does not need to suffer. BTW, Windows 3.0 was the last version of MS Windows that could be installed on 8086 and it offered some kind of multitasking, still being capable of providing good enough user experience. One more thing I remember from the past. My very first Linux back in the 90s (some very early version of RedHat) was installed on some very low end i386 machine equipped with ISA 8-bit VGA graphics card (probably the same I've installed during ELKS times into my Turbo XT to replace Hercules mono graphics card that was installed into it originally). Running X at 640x480x16 offered terrible user experience and 16-color palette looked awful. Yet I managed to force X server to run with 320x200x256 mode and it really started to fly! The user experience was amazing. I guess two factors were playing their role here: lower resolution and a whole byte per pixel which simplified all of the graphic operations. I think it's one of the possible directions nx on ELKS could also explore. In the end, those demos don't really display much of the content on screen. See how GEOS looks like on C64, it's low resolution and it's still really cool (speaking of GEOS, it was ported to 8086 XT's too, yet to my disappointment its final XT-compatible version was working much slower than FreeGEM). |
Hello @toncho11, hello @pawosm-arm, Well, the graphics stuff aside --- I think @ghaerr can comment further on that --- it is obvious that porting Turbo C++ specific code to, well, anything that is not Turbo C++, is going to take some effort. I do not see this as a bug per se: there is no real urgent need for ELKS to be compatible with a non-standard programming interface (even if it will be a "nice thing to have"). |
I remember the times when porting from Turbo C++ was all about getting rid of '#include <conio.h>' :) |
Hello @toncho11 , hello @pawosm-arm,
Well, I guess there are different ways of doing the porting task. :-| In case you missed it: on the MS-DOS front, I have been working on a I am currently keeping this library separate from the underlying C library ( ( If there is real demand, perhaps I can look into extending the scope of Thank you! |
I wonder how far we can go with this... It's like with Fuzix for Z80 machines where ability to run CP/M programs was considered. |
I wonder how far we can go with this... It's like with Fuzix for Z80 machines where ability to run CP/M programs was considered.
Interesting digression @pawosm-arm, I'm curious: anything in particular from cp/m you're interested in?
It may be worthwhile remembering that cp/m and fuzix ran on a different and incompatible architecture (from x86), and most programs were written in assembler. Still, I have 3 operating cp/m machines...
…-Mellvik
|
Nice digression. We need that 👍 By the way is it possible to change the priority of a process in ELKS? There is a nice sys call, but no nice command? Maybe this will make a game run a bit faster. While we wait for @ghaerr I think making a layer that allows for quick porting of turbo C programs and games will be interesting. I mean I want to use ELKS and have software for it. Ok some people are focused only on the kernel and they do not care about userland, but not me. |
@toncho11 I think the 'bug' label here is slightly misleading.
Although interesting, this digression should not grow here as it barely touches the matter of this ticket.
I'm slightly confused here. Both Fuzix and CP/M were originally targeting Z80 machines hence the idea of running CP/M software in Fuzix wasn't that terrible (considering simplicity of CP/M). And this simplicity was a key here: I suspect providing similar compatibility layer in ELKS to enable running 8088/8086 DOS programs would be more difficult. In case of CP/M, attempts to support other architectures (e.g. CP/M-86 or CP/M-68k) never gained popularity due to competition from the natively developed operating systems that were better suited to those machines. Anyway, there is some trace of the feature I've mentioned here in Fuzix's git repo: https://github.com/EtchedPixels/FUZIX/blob/master/Applications/cpm/runcpm.c EOOT. |
Hello everyone, Well, there's a lot that got discussed today, here's a few of my thoughts...
Yes, defining a distinct set of graphics functions, preferably across more than just one game, is a great way to start. Then, the entire function-set can be analyzed a bit and a graphics engine/library used as an API-bridge. Having done a heck of a lot of graphics engine programming, I also highly recommend keeping things simple in the beginning, and adding complexity only after getting the initial game(s) initially drawing. For instance, fill, draw poly and rectangle are pretty basic, but floodfill can get complicated. Text output is a whole 'nother discussion, but if a fixed-size font can be used, things are simplified considerably.
Yes, a lot of the graphics could be mapped to Nano-X, but it will likely be too slow. The biggest reasons for this (to be covered in more detail later) are 1) the lower level routines are written in C, not ASM, and 2) Nano-X has an additional layer of overlapping window management and clipping support. I have a number of graphics translation libraries for various embedded systems like Arduino, but what is really needed here is an (older) 8086 graphics library with direct, fast EGA support.
Actually, Nano-X originated from NanoGUI, which itself was based on some very early code by David I. Bell, the same guy that interestingly enough wrote But I digress. Back to @pawosm-arm's points, SDL, DirectFB, etc - are all too large for ELKS. Since the ELKS applications (not the kernel) will be writing directly to the EGA, what we should seriously consider would be an older, fast EGA library. Those libraries would likely use a different assembler than ia16-gcc-as (which is gcc compatible and AT&T syntax). Another option would be to use the EGA draw routines from Nano-X written in ASM (elkcmd/nano-X/drivers/asmplan4.s), but they would need to be ported from the BCC/AS86 assembler, and the speed would likely improve considerably. Nano-X is written as three layers (driver, engine and API), and the driver and engine could be used without the window-management API overhead, which would help. Its all a bit complicated, but doable.
There's no way to change the priority of a process in ELKS (yet); but when a single program is running, which is usually the case, there's no need for it - the system runs the single process as fast as can be, only taking timer interrupts, which increment a few counters, and then the interrupted process is immediately continued. |
There is another solution: Alfonso Martone found a way to convert DOS Turbo-C programs to enable these to run with ELKS. For this he developed the exe2elks DOS utility program and a small libc without DOS system calls. You compile your C program with this small libc library instead of the standard Turbo-C libc. Then you use the exe2elks utility to convert the generated executable in the DOS EXE format to a 16bit OMAGIC aout file as required by ELKS. So if we accept that the Turbo C graphics.h is not using DOS system calls (I actually do not know) then we could compile a game with Turbo C and:
So again:
What do you think? Are the differences in compiling linking and function parameters handling so different ? |
Argh, this name reuse, so common in Open Source world. Indeed nx graphics in NuttX and nx graphics in ELKS are completely different things of completely different origins. Both had the same purpose in common which is being lightweight, and that confused me. So porting nx from NuttX may be one more path to follow or avoid. Anyway, ability to change resolution (and bytes per pixel) would be a great addition to current graphics layer in ELKS, but only if it doesn't overcomplicate the current codebase. |
Speaking of Turbo C++, it brings me some of my late school days memories, you can have a glimpse here, https://www.youtube.com/watch?v=N8z5kQFhJ9A yet note I'll probably pull it down soon, there's too much cringe in this :) Anyway, looking forward, if you're serious about DOS compatibility in ELKS, IPX would be a nice addition, we had a lot of fun playing those early multiplayer games back in the 90's. |
I have to say, somewhat amazing piece of work by Alfonso. He's definitely provided the basics, that should, possibly without modifications, work today (we upgraded the ELKS a.out format slightly earlier this year, but still support the original a.out format, calling it "v0"). The bigger issue with this approach is that the development is all done on DOS, right? So TurboC is run on DOS to compile and link any TC program, along with the TC graphics library, and Alfonso's DOS-to-ELKS conversion libc which allows the program to run on ELKS without modification. It's a slick way to solve this problem. Perhaps you should try running his sample programs and see if/how they run on ELKS today, for a start. |
I compiled a minimal program that draws a rectangle with Turbo C and then applied exe2elks. It says "invalid argument" on ELKS. |
This is very likely due to the |
Here it is: |
If this is the correct disassembly: then it means that there are 19 int $0x21 DOS calls ... more than I have hoped. |
OK I see now ... probably I need to use the .bat file provided by Alfonso to set the proper options of tcc and tlink ... to generate a better executable ... I was using the IDE with .map file generation enabled. |
Yes, the idea is to compile with TC but link with Alfonso's special library that replaces all the TC libc calls to int 21h with ELKS system calls, and then rewrite the .EXE MZ format to ELKS a.out format. |
Ok it is going to take much more time. |
This is a direct example of Alfonso: It says "invalid argument". We need to fix that first before going deeper into the graphics library. How do you disassemble it? |
I'm not exactly sure what the problem is with ELKS running that (v0 format a.out header) executable, but I have a workaround that works:
It appears we don't have a way to disassemble linked binaries... the |
It is far more complicated ... I can not even compile a normal exe with the integrated bgi driver. @pawosm-arm Do you know how to do that? How to compile from command line with graphics.lib, egavga.obj and registerbgidriver(EGAVGA_driver) ? I can not make it to work. |
Interesting ... I tried to contact Alfonso ... but there is no working email ... nor any other contact information ... |
Can you specify more details? Which 'command line': DOS, Linux, ELKS? (well, ELKS command line doesn't seem to have a linker). What kind of binary do you want to have in effect? |
Compile or link error? You're using TC on DOS so there should be no issues having TC compiling TC programs, including those with graphics.h. Alfonso's trickery is all at the link stage, linking with additional libraries, right? You'll probably need to study TC a bit and understand what options it has for graphics programs, should there be compilation issues with it. |
@Vutshi - I tried the FYI here's the patch I used to get
|
Thank you @ghaerr. First I try to employ the newly available GPT-4o. When it doesn't work I will switch to more conventional tools :) |
ChatGPT doesn't want to just do a plain conversion it tries to optimize :)
converted to:
|
Well, it kind of works... ELKS_GAS_Mandel.movhere is the GAS code |
What did you use for conversion, Something to consider during Intel to AT&T conversion: input NASM syntax like
could mean
or instead the less likely
I think NASM does not require the [foo] syntax for the memory move is foo is a label, instead of an EQU. The translator would not know the difference between them, while an assembler would. This might be an issue to check into. |
Actually, I mainly used ChatGPT because it understands macros. Although it has a mind of its own and tends to reorganize functions ordering according to its liking. I cleaned up the code to match the objdump of the NASM-generated object file. Now, I have a one-to-one matching of NASM and GAS codes except for the .data section. Essentially
so instead of this in NASM:
I do this in GAS:
and compile as follows:
It works but the .data section reserves 16 bytes and everything is shifted because program assumes that .bss is at DS:0. |
@Vutshi: You are indeed making great progress traveling fairly deep into an interesting linking rabbit hole :)
I'm thinking of two possibilities to consider: 1) remove the check for .data and .bss section overlap in The first option will be easiest at first, and if it works I could come up with allowing an overlap iff the size of .data == 0. It appears that
(Section .nildata is linked first in the linker script into the data segment). To try the elf2elks mod, edit
Run The possibly better way might be to modify the elks-small.ld linker script, but they are a bit of black magic. Here's the portion that may need to be renamed and/or deleted:
The changed linker script can then be passed to the linker as
Wow, impressive!!
I see, very nice. It sounds like you're getting quite close to having this fully worked out! |
It's done. ELKS_GAS_Mandel_final.movThe bug with stripes was due to SP reset to 0x1c00. One should not touch SP in a multitasking OS indeed. I just use @FrenkelS thanks for the trick, now I use it as well ;) There is a couple of weird quirks left.
But the CPU (or MartyPC) sees it differently:
it complains about the last two lines as follows Best |
@ghaerr, I forgot to say that I used the first option to fix .data section problem
|
This is great, well done!!
I see, was this previously using SP to determine the calculation depth of the fractal? I haven't studied your source code yet, does this final version leave SS & SP alone, or it SP still being reset to within the lower part of the data segment?
What trick is that, I didn't see it.
In the 8086, 0x0F is an invalid opcode that in early versions of the 8086 was a "POP CS". Since that instruction, changing the code segment, but not the IP at the same time, is useless, the same instruction prefix was used in later CPUs as the beginning of a new multi-byte opcode. To fix this, either use
I'll make a note to enhance
I'm not sure what that is, perhaps rearrange the lines or add a few blank lines or spaces in each line to see whether that changes the error message. |
Yes. The reason is probably to just save one byte. At least, I don't see any speed decrease.
Yes.
The black and white Mandelbrot turns green in the end. Thank you. |
Were you saying that the top 7 lines work, and the lower 7 do not, with GAS? Certainly GAS will not like the C++ // comments apparently used for division for NASM? |
No, here lines 6 and 7 are the problem for GAS. NASM likes them. Commented lines are my attempts to fix it with GAS. |
Hi @ghaerr,
It happens after addition of the following line:
Best |
I would guess that by adding 32K bytes to .bss with the .comm directive you've overflowed .bss and / or the data section but the modified |
@ghaerr is advancing the watcom support for ELKS in #1924 and so this might allow this stripped down version of Doom: https://github.com/FrenkelS/doomtd3 to be compiled on ELKS. I see the watcom makefile for Doom: https://github.com/FrenkelS/doomtd3/blob/main/makefile.w16 |
It seems that at least i_ibm.c need to be modified for pc-98. |
The Watcom build only uses C, no assembly. I didn't want to spend time on figuring out how to support assembly in both gcc-ia16 and Watcom at the same time.
That's correct. The platform specific code is mostly in one file ( |
Using the Watcom C-only build (but using
For ELKS, all DOS-oriented routines (timer, keyboard, interrupt handlers, OS calls, but not EGA graphics) will need to be replaced by Doom source files from Linux Doom, which should then also work for both IBM PC and PC-98. After that, an alternative screen-drawing routine for PC-98 will be required, as PC-98 does not support EGA hardware graphics. |
There maybe still some more syscalls from ELKS that need to be mapped to Watcom? Just having the demo https://github.com/FrenkelS/doomtd3 on ELKS will be a great progress! Doom is a AAA game in our case! :) |
Hello all, As I wrote in This version is built with gcc-ia16, medium model. I will try to build with OpenWatcom large model for next release. Enjoy! |
Hello, Thank you. |
I am excited to announce that Doom (Doom88) has been ported to ELKS: https://github.com/FrenkelS/elksdoom |
Wow! |
I've just released a new version of ElksDoom. It grabs 2 large contiguous memory blocks instead of 1. |
Wow, thank you @FrenkelS and @toncho11 I could run the image that @toncho11 posted here by the v86 emulator. |
Huge thanks to @ghaerr for enabling the Open Watcom compiler for ELKS and @FrenkelS for the Doom88 port to ELKS. |
This screenshot looks great @toncho11!! :) It's actually higher resolution than I thought would work. Really super! And also thank you @toncho11 for your ongoing support for ELKS and constant pushing for enhancing the platform, it is appreciated. Thank you @FrenkelS for spending the time getting your Doom source running on ELKS. I plan on playing with it just after I finish a deep dive into a QEMU-based bug that affects the ELKS kernel. Its super that OpenWatcom is being successfully used for this large game! :) I remain a bit surprised at how/why ia16-elf-gcc won't work, since you're using medium model, but I'm actually glad you switched over to OpenWatcom as that proves the OW support for ELKS is fully working, as @toncho11 has already pointed out. Thank you! |
With regards to running large games on ELKS, I just had an idea that could be a game-changer, no pun intended, lol: For any 286/386+ system that has more than 1M memory installed, why not put the ELKS kernel data section, normally 64K up in the first 64K bytes of that memory, otherwise known as the HMA (High Memory Area)? This would free up an extra full 64K block of memory for the game to use. Likewise, for 8088/8086 systems that have UMB memory, the ELKS kernel data section (either full sized, or trimmed down with the new options) could be put into the UMB area. Either of these options could have the same effect of increasing contiguous main memory by up to 64K bytes - huge. Both these options would effectively be very similar to using DOS's config.sys with the When the kernel data segment is decreased using the new heap= and other options, the default 64 (or even just minimally 8) EXT kernel buffers could also be placed into HMA or UMB memory. If a game does lots of disk I/O, having more than 8 buffers would probably help. There's quite a few combinations that could be worked out using a few new /bootopts options that would specify what portions of memory buffers and kernel data segment could go into that would greatly help increasing memory available for apps. Even if the extra memory wasn't required by a running game, the ability for ELKS to respond to, say FTP requests or even have Thoughts? |
Sounds good. BTW, ElksDoom doesn't need one contiguous block of memory anymore. It now calls |
Let's take this example of Snake compiled by Turbo C:
https://github.com/ashmew2/snake-game/blob/master/Final.cpp
delay
,sound
andnosound
are used. We can omit sound for now.kbhit
,clrscr
andgetch
are used in this game! So 3 out 8 functions from conio.h.fillpoly
,drawpoly
,settextstyle
,outtextstyle
,outtextxy
,setfillstyle
,floodfill
,setcolor
,rectangle
@ghaerr Maybe graphics.h can be mapped to Nano-X? But on 8086 computers Naxo-X looks slow for games. For example
The text was updated successfully, but these errors were encountered: