- 146
- Posts
- 11
- Years
- CO
- Seen Mar 16, 2023
This looks very interesting ^_^
I have just started to learn programming through C from a very great site called computerscienceforeveryone.com
So far I am still in the basics but am wondering how long it took you to learn C#?
and how easy is it going from C to C#?
Another question I have is why not use C++, wouldn't that be more efficient?
I ask because I came across a page on the net named "Why pokemon is so buggy" so I clicked and read on and it goes to say that the gb/gbc/gba games are programmed entirely in Assembly and that its amazing that they even work as the difference in ASM to C is quite significant.
I have just started to learn programming through C from a very great site called computerscienceforeveryone.com
So far I am still in the basics but am wondering how long it took you to learn C#?
and how easy is it going from C to C#?
Another question I have is why not use C++, wouldn't that be more efficient?
I ask because I came across a page on the net named "Why pokemon is so buggy" so I clicked and read on and it goes to say that the gb/gbc/gba games are programmed entirely in Assembly and that its amazing that they even work as the difference in ASM to C is quite significant.
Spoiler:
BECAUSE IT IS WRITTEN IN ASSEMBLY.
Most commercial games for the Game Boy were written in assembly. This is because it is much more efficient than compiled C programs for that platform. For those of you who have no idea what I'm talking about, assembly can be written in binary. Think about that for a second. These programmers were writing basically the 1s and 0s that were being executed on the Game Boy's puny Z80 processor.
Most code nowadays is written in higher-level programming languages such as C and C++. They sort of look like English. This sorta-English is compiled, which means it is turned into assembly for whatever processor you want to run it on. Every processor, be it Intel's x86 architecture, IBM's PowerPC, or the Cell processor all have their own assembly languages, or instruction sets. So you can write a program in C and use different compilers to turn your C code into assembly for whatever processor you're going to be using. The Game Boy's was a stripped-down Zilog 80.
At any rate, compilers, while usually pretty good about making optimized machine code, aren't perfect and when you have extremely scare resources, like on the Game Boy, you need a human to do the instruction-level optimization. Unfortunately, this is like building a house out of twigs. You can do it, but it will be hard, take a long time, will be really easy to screw up, and the result will be easy to break.
Let's compare something really simple: Hello World.
In C:
/* Hello World program */
#include<stdio.h>
void main()
{
printf("Hello World");
}
Pretty self-explanatory, right? This will print the words "Hello World" to the screen.
In Game Boy Assembly (this is an EXCERPT, full program is here):
; ********************************************************
; Main code:
; Print a character string in the middle of the screen
; ********************************************************
ld hl,Title0
ld de, _SCRN0+1+(SCRN_VY_B*5) ;
ld bc, Title0End-Title0
call mem_CopyVRAM
ld hl,Title1
ld de, _SCRN0+6+(SCRN_VY_B*8) ; spaced over
ld bc, Title1End-Title1
call mem_CopyVRAMv
This does the same thing, but instead of just asking for a built-in function to print a string to the screen for you, you have to load each individual letter from memory (which you have to fill yourself), and call a whole separate function to copy your characters into video memory so it can draw it on the screen for you.
So already you can see there is a lot a compiler does for you.
Also remember that that huge chunk of code could, if you really wanted to, be written in 1s and 0s.
Now let's talk about Pokemon.
Imagine a game as vast as Pokemon being written in this fashion. Every time you want to add two numbers together, you have to load them into registers from memory, add them, and stick them back into memory. Think about what it takes to draw sprites on screen, talk to NPCs, load up the Pokedex, play music, and generate random encounters.
Armed with this knowledge, I think it's incredible that Pokemon works at all.
Most commercial games for the Game Boy were written in assembly. This is because it is much more efficient than compiled C programs for that platform. For those of you who have no idea what I'm talking about, assembly can be written in binary. Think about that for a second. These programmers were writing basically the 1s and 0s that were being executed on the Game Boy's puny Z80 processor.
Most code nowadays is written in higher-level programming languages such as C and C++. They sort of look like English. This sorta-English is compiled, which means it is turned into assembly for whatever processor you want to run it on. Every processor, be it Intel's x86 architecture, IBM's PowerPC, or the Cell processor all have their own assembly languages, or instruction sets. So you can write a program in C and use different compilers to turn your C code into assembly for whatever processor you're going to be using. The Game Boy's was a stripped-down Zilog 80.
At any rate, compilers, while usually pretty good about making optimized machine code, aren't perfect and when you have extremely scare resources, like on the Game Boy, you need a human to do the instruction-level optimization. Unfortunately, this is like building a house out of twigs. You can do it, but it will be hard, take a long time, will be really easy to screw up, and the result will be easy to break.
Let's compare something really simple: Hello World.
In C:
/* Hello World program */
#include<stdio.h>
void main()
{
printf("Hello World");
}
Pretty self-explanatory, right? This will print the words "Hello World" to the screen.
In Game Boy Assembly (this is an EXCERPT, full program is here):
; ********************************************************
; Main code:
; Print a character string in the middle of the screen
; ********************************************************
ld hl,Title0
ld de, _SCRN0+1+(SCRN_VY_B*5) ;
ld bc, Title0End-Title0
call mem_CopyVRAM
ld hl,Title1
ld de, _SCRN0+6+(SCRN_VY_B*8) ; spaced over
ld bc, Title1End-Title1
call mem_CopyVRAMv
This does the same thing, but instead of just asking for a built-in function to print a string to the screen for you, you have to load each individual letter from memory (which you have to fill yourself), and call a whole separate function to copy your characters into video memory so it can draw it on the screen for you.
So already you can see there is a lot a compiler does for you.
Also remember that that huge chunk of code could, if you really wanted to, be written in 1s and 0s.
Now let's talk about Pokemon.
Imagine a game as vast as Pokemon being written in this fashion. Every time you want to add two numbers together, you have to load them into registers from memory, add them, and stick them back into memory. Think about what it takes to draw sprites on screen, talk to NPCs, load up the Pokedex, play music, and generate random encounters.
Armed with this knowledge, I think it's incredible that Pokemon works at all.