VOGONS

Common searches


First post, by FlatAssembler

User metadata
Rank Newbie
Rank
Newbie

Hey, guys!
I've made a program in my own programming language targeting DOS. It's available in this ZIP-archive, the executable is "analogClockForDOS.exe", and the source code is "analogClockForDOS.aec". It's important for me that this program works in DosBox so that people can test it. While it works in VirtualBox and QEMU, DosBox is a lot easier to use (no need to install DOS there). Can you please diagnose the problem (I am almost sure it's somewhere in the ton of inline assembly I've included in that program).

Last edited by FlatAssembler on 2020-06-23, 19:44. Edited 1 time in total.

Reply 2 of 14, by FlatAssembler

User metadata
Rank Newbie
Rank
Newbie

Why does it output different from FreeDOS running under QEMU?

Attachments

  • analogClockForDOS.png
    Filename
    analogClockForDOS.png
    File size
    7.06 KiB
    Views
    2542 views
    File comment
    What it outputs in QEMU
    File license
    Public domain

Reply 3 of 14, by ripsaw8080

User metadata
Rank DOSBox Author
Rank
DOSBox Author

If you run your program in a debug build of DOSBox, the log messages it produces give you an excellent clue about one problem. The compiled program is using FPU opcodes that DOSBox does not emulate, e.g. FCOMIP that is only found on Pentium Pro and later. I think you may need to set the target CPU to 486 or Pentium when compiling in DJGPP, but I don't know the details of how to do that. Anyway, the CPU/FPU compile target is a good place to start, but there may be other issues after you fix that one. The fact that you have long filenames also suggests you're not using MS-DOS 5 or 6, which is what DOSBox targets.

Reply 4 of 14, by FlatAssembler

User metadata
Rank Newbie
Rank
Newbie
ripsaw8080 wrote on 2020-06-23, 20:28:

If you run your program in a debug build of DOSBox, the log messages it produces give you an excellent clue about one problem. The compiled program is using FPU opcodes that DOSBox does not emulate, e.g. FCOMIP that is only found on Pentium Pro and later. I think you may need to set the target CPU to 486 or Pentium when compiling in DJGPP, but I don't know the details of how to do that. Anyway, the CPU/FPU compile target is a good place to start, but there may be other issues after you fix that one. The fact that you have long filenames also suggests you're not using MS-DOS 5 or 6, which is what DOSBox targets.

Damn, the compiler I've made for my programming language relies on "fcomip" for every floating-point comparison.

Reply 5 of 14, by ripsaw8080

User metadata
Rank DOSBox Author
Rank
DOSBox Author

Ah, well, if running in DOSBox is important to you then perhaps recoding for FCOMP is a possibility, although you may find working with the FPU flags more cumbersome than with EFLAGS.

Reply 6 of 14, by FlatAssembler

User metadata
Rank Newbie
Rank
Newbie
ripsaw8080 wrote on 2020-06-23, 21:06:

Ah, well, if running in DOSBox is important to you then perhaps recoding for FCOMP is a possibility, although you may find working with the FPU flags more cumbersome than with EFLAGS.

Well, it's not that important to me. I assumed it had something to do with the inline assembly I put in my program, not with the code my compiler generates.

Reply 8 of 14, by FlatAssembler

User metadata
Rank Newbie
Rank
Newbie
_Rob wrote on 2020-06-24, 12:29:

@FlatAssembler you may want to try with dosbox-x, it has a cputype=ppro_slow

I mean, I can run my program in QEMU and VirtualBox. It's just that I hoped DosBox was an easy way for my future employers who will review my code to run it. Now they will most likely say they don't know if it works. Well, fair enough, I've done enough stuff already, I think.

Reply 9 of 14, by FlatAssembler

User metadata
Rank Newbie
Rank
Newbie

Do you perhaps happen to know, what would be the easiest way to modify my AEC-to-x86 compiler (you can run the core of it in browser: https://flatassembler.github.io/compiler ) to be able to target i486? Right now, I think it targets i486, except relying on the `fcomip` instruction which exists only on i686 and newer. At first I thought I might replace `fcomip` with something like:

fsubp
fist dword [result]
cmp dword [result],0

But the problem with that is that I'd also need to replace every `ja` with `jg` and every `jb` with `jl`, which, given the way the compiler is structured, is not a simple task (I'm afraid it's too error-prone). Do you have a better idea?
Is there a way to push FPU flags (ones affected by `fcomp`) and pop them into CPU flags that would work on both i486 and 64-bit x86 processors?

Reply 10 of 14, by ripsaw8080

User metadata
Rank DOSBox Author
Rank
DOSBox Author

FCOMIP just saves you the work of manipulating EFLAGS, so you could use FCOMP and merge the condition flags the hard way, for example:

fcomp
push ax
fstsw ax
mov al,ah
lahf
and ax,0ba45h
or ah,al
sahf
pop ax

Maybe make it a subroutine if used a lot.

Reply 11 of 14, by FlatAssembler

User metadata
Rank Newbie
Rank
Newbie
ripsaw8080 wrote on 2023-01-06, 16:59:
FCOMIP just saves you the work of manipulating EFLAGS, so you could use FCOMP and merge the condition flags the hard way, for ex […]
Show full quote

FCOMIP just saves you the work of manipulating EFLAGS, so you could use FCOMP and merge the condition flags the hard way, for example:

fcomp
push ax
fstsw ax
mov al,ah
lahf
and ax,0ba45h
or ah,al
sahf
pop ax

Maybe make it a subroutine if used a lot.

Thank you, I've tried it and now the Analog Clock program works under DosBox. I don't quite understand your code, though. What does `0ba45h` mean?

Reply 12 of 14, by ripsaw8080

User metadata
Rank DOSBox Author
Rank
DOSBox Author

0ba45h masks the EFLAGS bits in AH to retain and the FPU condition flag bits in AL to merge. It takes advantage of the fact that the condition flags (carry, parity, zero) are in the same relative positions in both registers, which is almost certainly by design. Note that I didn't include the overflow flag because I'm not sure it has the same meaning in both registers.

Reply 13 of 14, by DaveDDS

User metadata
Rank Newbie
Rank
Newbie

Not sure what exactly this program is supposed to do ... seems to just draw an analog clock.
(although at 60+k it seems kinda big to just do that -- must be some other functions? - sorry
haven't spend the time to go through all the files)

FWIW You definitely don't need floating point to do an analog clock.

I threw together a very simple program to do this, it just draws a clock (in VGA 640 x 480), and
updates it to keep matching the current time - quick job, no guarantees of "bug free" etc.
-- and yes, it works fine in DosBox

I've included both the executable, and Micro-C source code - available from my site!

Dave Dunfield ::: https://dunfield.themindfactory.com
or: "Daves Old Computers" -> Personal (near bottom)

Attachments

  • Filename
    ANACLK.ZIP
    File size
    3.83 KiB
    Downloads
    59 downloads
    File license
    Public domain

Reply 14 of 14, by DaveDDS

User metadata
Rank Newbie
Rank
Newbie
DaveDDS wrote on 2023-02-03, 05:51:

- quick job, no guarantees of "bug free" etc.

Yeah - about line 96 - "(i*2333)/1000" should have been: "(i*2333)/100"

I have replaced the .ZIP in the original post with a corrected one.

Kinda fun to play with - I don't recall ever doing such a straight analog time display before!

Dave Dunfield ::: https://dunfield.themindfactory.com
or: "Daves Old Computers" -> Personal (near bottom)