Questions about x86

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Questions about x86

Post by lidnariq »

Developing your own kernel from scratch is a not-infrequent CS class at college.

Yes, you're mostly programming it in C instead of asm, but whatever.
User avatar
rainwarrior
Posts: 8735
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Questions about x86

Post by rainwarrior »

dougeff wrote:When was the last time someone programmed an OS all by himself? 1970?
Oh I think we can find more recent examples than that. ;)
http://www.templeos.org/

Edit: oh, gauauu already mentioned it.
Joe
Posts: 650
Joined: Mon Apr 01, 2013 11:17 pm

Re: Questions about x86

Post by Joe »

DementedPurple wrote:How would I know what memory addresses to use for variables?
You would reserve space for them in your data section and then access them by label. The label is replaced with the exact address either when you link your executable file (in most cases), or when the executable file is loaded by Windows (for position-independent code). If you really wanted to, you could tell the linker to put your data at a specific address, but the defaults are good enough most of the time.
DementedPurple wrote:I'll have to keep in mind that I'll have to have RAM to store the code, and that Windows will be running in the background as well as a few other apps. You could say that I've been spoiled by NES programming by having the code stored in a ROM as well as having the entire system dedicated to your program and not having to share system resources.
Well then, I've got good news for you: Windows provides a dedicated virtual computer for your program to run. You don't have to worry about sharing resources at all.
DementedPurple wrote:I also want to get into programming BIOS' and operating systems, which leads me to even more questions.
BIOS programming depends on a lot of hardware documentation, which isn't always available. By comparison, operating system programming is a lot more reasonable. Most of the information you need for that is freely available (someone else already linked osdev.org).
DementedPurple wrote:How do I read and write from a hard disk or CD?
This is not something I could explain in a single post!
DementedPurple wrote:And how do I know what memory addresses to use for code and variables?
If you're developing a BIOS, you would know what memory is available because you've configured the hardware and determined how much memory is available and where it's mapped. If you're developing an operating system, you would know because the BIOS will tell you (but you might need to ask it in a specific way).
DementedPurple wrote:How would I run C code?
Load the code to its expected memory address (applying relocations if necessary), set up any other initial things it expects (e.g. a stack), and call its entry point.
DementedPurple wrote:I'm kind of a noob.
We all start somewhere.
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: 🇫🇮
Contact:

Re: Questions about x86

Post by thefox »

Joe wrote:The label is replaced with the exact address (...) when the executable file is loaded by Windows (for position-independent code).
Pedantry: You described relocatable code. Position-independent can execute at an arbitrary address, without needing relocation patches.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: Questions about x86

Post by dougeff »

nesdoug.com -- blog/tutorial on programming for the NES
User avatar
Punch
Posts: 365
Joined: Sat Feb 16, 2013 11:52 am

Re: Questions about x86

Post by Punch »

I've always wondered if a vanity OS project for the NES would be possible, especially one of the multitasking kind. How would you switch between processes? APU timer? How do you protect the system against code writing to hardware directly when there's absolutely no way you'd be able to check code against it in a viable manner?
This is a block of text that can be added to posts you make. There is a 255 character limit.
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Questions about x86

Post by lidnariq »

Punch wrote:I've always wondered if a vanity OS project for the NES would be possible, especially one of the multitasking kind.
There used to be a port of Contiki to the NES (and a bunch of other ridiculous other 6502-based systems) but they weren't very useful and weren't maintained when Contiki went from version 1.0 to version 2.0
How would you switch between processes? APU timer?
Preemptive multitasking isn't necessarily required...
How do you protect the system against code writing to hardware directly when there's absolutely no way you'd be able to check code against it in a viable manner?
You're correct; you can't provide protection without a hardware assist, or running everything in a VM of some sort.
DementedPurple
Posts: 318
Joined: Mon Jan 30, 2017 5:20 pm
Location: Colorado USA

Re: Questions about x86

Post by DementedPurple »

One of the problems I have is that when I look up how to do stuff, It comes up with a bombardment of big words I don't understand, and when I look up those terms, I get one bombardment answered with another bombardment of complicated terms, in other words, It's practically impossible to get basic answers to basic questions.
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Questions about x86

Post by lidnariq »

x86, such as it is, is the result of 36 years of gradual evolution and rarely any deprecation. Learning, from scratch, how to write something for the modern version we interact with is going to be much harder than, say, trying to write something that would target the PCjr's game cartridges.
User avatar
Punch
Posts: 365
Joined: Sat Feb 16, 2013 11:52 am

Re: Questions about x86

Post by Punch »

DementedPurple wrote:One of the problems I have is that when I look up how to do stuff, It comes up with a bombardment of big words I don't understand, and when I look up those terms, I get one bombardment answered with another bombardment of complicated terms, in other words, It's practically impossible to get basic answers to basic questions.
You'd love Graph Theory where everyone uses their own incompatible terms... complex papers are basically 50% explaining your own notation :lol:
This is a block of text that can be added to posts you make. There is a 255 character limit.
adam_smasher
Posts: 271
Joined: Sun Mar 27, 2011 10:49 am
Location: Victoria, BC

Re: Questions about x86

Post by adam_smasher »

Put another way, you're trying to do really hard stuff, so questions you think are basic just plain aren't, and that's why there's no basic answers.
User avatar
GradualGames
Posts: 1106
Joined: Sun Nov 09, 2008 9:18 pm
Location: Pennsylvania, USA
Contact:

Re: Questions about x86

Post by GradualGames »

The following book may interest you: Assembly Language: Step by Step. With the modern version, you'd have to install VirtualBox and put Linux on it on your windows machine (or dual boot) to work through the tutorials. Alternatively, you could use the old Dos version of the book and a VirtualBox image I prepared with all the necessary tools (except the text editor shown in the old book, instead edit.com is provided).

One problem with getting into coding at a young age today is I imagine one feels quite overwhelmed with options. When I was 13, pretty much the only thing readily available at the time with a reasonable learning curve was QBasic. As mentioned in another thread, I personally think Pico-8 (also: video series) probably is best these days, but, dive into a few things and see which one you enjoy most/progress in most and then stick with that for a while. :)
na_th_an
Posts: 558
Joined: Mon May 27, 2013 9:40 am

Re: Questions about x86

Post by na_th_an »

I agree. Pico-8 is the best platform to get started in game programming nowadays.
Post Reply