viernes, 28 de diciembre de 2018

Meet the CPUs

Welcome to my blog, where I'll teach you how to program not one but various SEGA systems at once (if possible)

Before we start, this blog is meant for people with some programming experience, if you at least know BASIC, it's fine.

Keep in mind that you'll need a good amount of time to understand this (it took me 6 years), know the hexadecimal numbers (0-9,A,B,C,D,E,F) and binary (0 and 1), also interact with bits ( OR, AND, XOR/EOR ) and... the desire to do this.

These are the CPUs we are going to use:
  • Motorola 68000
  • Zilog Z80
  • Hitachi SH-2 (SH7095)
 And these are the setups of each console:
  • Master System and Game Gear:
    • Zilog Z80
  • Genesis
    • Main: 68000
    • Sound: Z80
    • If the Sega CD is connected:
      • Another 68000, nicknamed "Sub-CPU" (and the Genesis 68000 is now the "Main-CPU")
    • If the Sega 32X is connected:
      • 2 Hitachi SH-2 (SH7095) processors, "dual-core" type
**In these tutorials we are going to use 68000 as a base

- Each CPU consists of registers, condition bits and memory: the registers are like the variables that you normally use in other programming languages:

Variable = 1

All the registers are in hexadecimal and limited in size depending of the CPU:

BYTE (12)
WORD (1234)
LONG (12345678)


- The condition bits are when you make conditions to the registers:

Nothing = 0
if Nothing == 0:
  Z = 1
else:
  Z = 0

A CPU at least has these bits:

Z - Zero
Set when a register is in zeros, on conditions this is used if a value is Equal (==) or Not equal (!=)

C - Carry
This bit is set if a register runs out of bits (depending of the byte size) for example: in a BYTE where the maxium value is 255 (1111 1111) and you increment by 1, it returns to 0 (0000 0000) but the bit that makes the number 256 (1 0000 0000) stays on Carry temporally. And in conditions it's used if the value is larger than (>) and lower than (<)

N - Negative
Set if the value is negative, for example: -24, depending of the register size: gets active when the Most Significative Bit (8-bit: 1000 0000, 16-bit: 1000 0000 0000 0000) is set

V - oVerflow
Set if the value went from positive to negative in foward, example: if in 8-bit you have the number +127 (0111 1111) and increment by 1, it turns into -128 becuase the value of 128 in binary sets the negative bit (1000 0000).

The 68000 also includes a bit called X - eXtended but this can be manually set by the user

If you wanna learn more about each CPU, especially the instruction set, i'll leave these links:
https://retrocdn.net/images/3/3a/Motorola_68000_Programmer%27s_Reference_Manual.pdf
http://wpage.unina.it/rcanonic/didattica/ce1/docs/68000.pdf
http://www.z80.info/zip/z80cpu_um.pdf
https://www.renesas.com/us/en/doc/products/mpumcu/001/rej09b0171_superh.pdf

In the next post, I'll explain how to work with the memory of each console, and also to how to really start making your code...

No hay comentarios:

Publicar un comentario