Help with binary (loops?)
Help with binary (loops?)
I've made a exe file with Turbo C++ 3.0 and then used exe2bin. I tried to run on boot and it kept going off from the memory location at where the program is. The exe is fine though, the words come up to the screen. Any help?
- Attachments
-
- VGA_TEST.CPP
- The source file.
- (36.33 KiB) Downloaded 238 times
Re: Help with binary (loops?)
maybe your screen base address wrong.
BTS, your exe may include some dos functions maybe occurs some crash.
BTS, your exe may include some dos functions maybe occurs some crash.
Re: Help with binary (loops?)
Are you sure CS:EIP is pointing to where this code is loaded? You've to manually setup your CS:EIP to pointer to this location. I don't think it is possible to do that while compiling with Turbo C++.
By the way, do you've a functional bootloader?
By the way, do you've a functional bootloader?
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
Re: Help with binary (loops?)
Hi,
Quick code review:
Better solution? Change your check to:
Cheers,
James
Quick code review:
- Your loop to count the number of characters in the string is compeletely broken - it will only exit if the string ends with a '/'. Otherwise it will keep going off the end of the string.
- Your chained "if"s would be better rewritten as a switch statement.
- Your font writing code assumes that it is writing on a pre-blanked background, which is not necessarily true as there is no blanking code in the draw_text function.
- The string that you send to draw_text is, uh, interesting - it ends with the two characters "/" and "0" - why don't you just rely on the NULL-termination you get for free when defining a C-string?
Better solution? Change your check to:
Code: Select all
while(string[i]) {
i++;
}
James
Re: Help with binary (loops?)
But how come it works good as an exe, but as a disaster as a binary?
Re: Help with binary (loops?)
Does it really matter? Broken code can work by accident, but good code doesn't break.
Every good solution is obvious once you've found it.
Re: Help with binary (loops?)
Huh
The problem is that it doesn't work as a binary; how else should to bootloader read it?
I tried to debug it using emu8086, but I still could figure out why it escaped the program.
Can somebody use compile the code with Turbo C, use exe2bin, and try to boot it to see if I did anything wrong in the process?
The problem is that it doesn't work as a binary; how else should to bootloader read it?
I tried to debug it using emu8086, but I still could figure out why it escaped the program.
Can somebody use compile the code with Turbo C, use exe2bin, and try to boot it to see if I did anything wrong in the process?
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Help with binary (loops?)
There's more than a single problem here:
- Your drawing code would even fail basic programming courses for programming language abuse. Do you even have the required knowledge?
- You don't use the official way of far pointer creation (use the MK_FP macro)
- You include the DOS header
- You build a DOS executable, not a platform independent executable
- You change an EXE into a binary file. The result is still something that requires DOS, as well as rather specific compiler settings.
- Emu8086 is old and never was worth the price with all the obvious hacks (it does not even have a bios), Turbo C is also old and nonstandard.
Please, learn proper C, use a sane compiler, and learn how your tools work before trying to make them do something they were not intended to do.
- Your drawing code would even fail basic programming courses for programming language abuse. Do you even have the required knowledge?
- You don't use the official way of far pointer creation (use the MK_FP macro)
- You include the DOS header
- You build a DOS executable, not a platform independent executable
- You change an EXE into a binary file. The result is still something that requires DOS, as well as rather specific compiler settings.
- Emu8086 is old and never was worth the price with all the obvious hacks (it does not even have a bios), Turbo C is also old and nonstandard.
Please, learn proper C, use a sane compiler, and learn how your tools work before trying to make them do something they were not intended to do.
Re: Help with binary (loops?)
Yes master!
Your drawing code would even fail basic programming courses for programming language abuse. Do you even have the required knowledge?
There might be a way to simlify it, or make a better design, but as long as it works, I'm ok with it; making it work is more important than making it perfect. Although I did really get the abuse part
You don't use the official way of far pointer creation (use the MK_FP macro)
What I like is creating stuff on my own. MK_FP might do or have advantages over what I'm using, but I'd prefer me doing my own pointers.
You include the DOS header
I had suspition by looking at the DOS header.
You build a DOS executable, not a platform independent executable
You change an EXE into a binary file. The result is still something that requires DOS, as well as rather specific compiler settings.
I use Borland or Mingw, how do I set those specific compiler settings?
Please, learn proper C, use a sane compiler
What would be your suggestion of proper C? Unfortunatly TC 3.1 is the only 16 bit compiler I could find, and it allows me do ring 0 opperations/simulations splendidly!
Learn how your tools work before trying to make them do something they were not intended to do.
Any links to walkthroughs/tutorials? I've been through most of them, none of them stating how to make an OS using C, and if they do they stated it poorly.
Your drawing code would even fail basic programming courses for programming language abuse. Do you even have the required knowledge?
There might be a way to simlify it, or make a better design, but as long as it works, I'm ok with it; making it work is more important than making it perfect. Although I did really get the abuse part
You don't use the official way of far pointer creation (use the MK_FP macro)
What I like is creating stuff on my own. MK_FP might do or have advantages over what I'm using, but I'd prefer me doing my own pointers.
You include the DOS header
I had suspition by looking at the DOS header.
You build a DOS executable, not a platform independent executable
You change an EXE into a binary file. The result is still something that requires DOS, as well as rather specific compiler settings.
I use Borland or Mingw, how do I set those specific compiler settings?
Please, learn proper C, use a sane compiler
What would be your suggestion of proper C? Unfortunatly TC 3.1 is the only 16 bit compiler I could find, and it allows me do ring 0 opperations/simulations splendidly!
Learn how your tools work before trying to make them do something they were not intended to do.
Any links to walkthroughs/tutorials? I've been through most of them, none of them stating how to make an OS using C, and if they do they stated it poorly.
Re: Help with binary (loops?)
That answers the question in the negative, it seems.abraker95 wrote:...as long as it works, I'm ok with it; making it work is more important than making it perfect.Combuster wrote:Do you even have the required knowledge?
There are canonically accepted ways of "making it work". Deviating from them should only be done for a very good reason. Deviating from them without a good reason is a strong indication of a person not having the experience required to "get things done" regarding OS development.Although I did really get the abuse part
Your way of terminating a string with "/0" is such a deviation from the canonical way, with a suspicion of a huge misunderstanding of your textbooks lingering beneath it. (C strings are terminated by '\0', and there's a world of difference between the two.)
Not only did you apparently not consider that including a header from any operating system ("dos.h") might not be a good idea if you're attempting to write your own OS. Your code in draw_text() is also highly inefficient, which does not bode well for further attempts at OS development. Not because OS code needs to be highly efficient, but because it points at a lack of experience in C coding.
All in all, it seems like you should try your hand at a couple of user-space projects before you attempt developing your own OS.
Every good solution is obvious once you've found it.
Re: Help with binary (loops?)
How about a tutorial on how to:
Correctly compile the source file, and what header to and not to use (no need to mention dos.h twice)
Correctly compile the source file, and what header to and not to use (no need to mention dos.h twice)
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Help with binary (loops?)
They already exist. There is even a link at the very top of this page
Re: Help with binary (loops?)
I've been through most of them, none of them stating how to make an OS using C, and if they do they stated it poorly.
Re: Help with binary (loops?)
I've always noticed a pattern: I start out slow and poor, but with given support and materials I take off faster than a bullet. In this case I just need a few examples of how people started out with there OS (how they compiled and booted their first 10 - 50 lines of code). I learn better from working examples. I also would like staight foward stuff; People know how to do it yet they still send me to tutorial (back to square 1).
Opening a nutshell might be a VERY big struggle, but with a nutcracker or another reasonable tool you can easily get to the good stuff inside... in this case I'm trying to do it with bare hands, with everybody turning their back on me
Opening a nutshell might be a VERY big struggle, but with a nutcracker or another reasonable tool you can easily get to the good stuff inside... in this case I'm trying to do it with bare hands, with everybody turning their back on me
- JackScott
- Member
- Posts: 1032
- Joined: Thu Dec 21, 2006 3:03 am
- Location: Hobart, Australia
- Mastodon: https://aus.social/@jackscottau
- GitHub: https://github.com/JackScottAU
- Contact:
Re: Help with binary (loops?)
A very small nut to get started with: http://wiki.osdev.org/Barebones
The nutcracker: http://wiki.osdev.org/GCC_Cross-Compiler
The nutcracker: http://wiki.osdev.org/GCC_Cross-Compiler