Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does a machine determine what is displayed on a screen (6502 specifically)? [closed]

I know this is an incredibly vague question, and it might not be a good question for programmers, since this is really a hardware related thing, but I guess some assembly/machinecode comes into play which would be appropriate for this site.

So what I'm wondering is; imagine the 6502 processor. It has some registers, an instruction set, and access to a certain amount of memory. Then imagine that you have some LCD screen with an arbitrary resolution. How is it determined what is shown on this screen? How is it determined which pixels at which position is given what color? Does the screen always display, for instance, a pixel with the value in the accumulator of the 6502, and with x position stored in register x, and y position stored in y? Or is it interpreted differently by every machine?

Someone wrote a JavaScript 6502 emulator, and the device displays a pixel with its value at some memory position starting with $200. So for instance:

LDA #$08 
STA $200 

would display a pinkish pixel at position x:0, y:0.

LDA #$01
STA $205

would display a white pixel at position x:5, y:0.

If you look at the NES, however, it has a dedicated PPU which displays certain pixels with a certain value at a certain area on the screen.

So how does it work? Is it interpreted differently by every machine (i.e. Apple II, C64, NES), or is there some kind of consistency of how it is interpreted?

As a matter of fact, what would happen if a program compiled for an Apple II was somehow executed on a C64? The machine should be able to read the instructions, right?

like image 580
ZimZim Avatar asked Jun 15 '13 17:06

ZimZim


1 Answers

How the graphics is displayed is machine dependent, so therte is no definite answer. For example on the C64, the graphics hardware was mapped into the normal address space, So you had to write to a specific part of the memory in order to print characters on the screen. If you wanted to display graphics, then you had to switch the mode, by writing to registers of the display hardware, and also the mapped memory could change. Because of this, the normally accessible memory of the C64 was lower than the 64KB. You could switch off the memory mapping though, and thus get access to the full memory below the graphics memory, so it turned into a machine with no display.

However, on the PC you had e.g. VGA, EGA, Hercules cards and so, which were written to by accessing a specific port and sending commands to it via these ports. A totally different approach. But this is a system design decision, and doesn't depend on the CPU.

As a matter of fact, what would happen if a program compiled for an Apple II was somehow executed on a C64? The machine should be able to read the instructions, right?

Well, the answer is pretty clear. It would most likely crash, because even if the instruction set might be the same (I don't know which CPU the Apples had), the hardware details would differ.

like image 91
Devolus Avatar answered Sep 28 '22 05:09

Devolus