#68218 - HyperHacker - Mon Jan 23, 2006 3:05 am
It's been my plan for a while to write some emulators for the DS... however given the CPU-intensive nature of emulation, I imagine it might be better to code in ARM/Thumb ASM. The question is how? Like what do I have to put in my source files for the assembler to accept it properly, and what do I assemble it with? (I have DevkitPro, which I imagine must include an assembler...) I've done programs in raw ASM on the old Gameboy (Z80; in fact, all my GB programs were ASM) but it was with a very simplified assembler, basically you just had to do this:
Code: |
CPU GBZ80
FNAME "something.gbc"
whatever: EQU $C000
ld a,whatever
ldi (hl),a
etc etc etc |
In most other ASM source I find I see all this .section and .bss and such, and I have no idea what any of that's supposed to mean...
#68223 - El Hobito - Mon Jan 23, 2006 3:23 am
check out the hexends source code i believe thats got some assembler in it
#68234 - sajiimori - Mon Jan 23, 2006 3:54 am
Also try writing some things in C and compiling them with -S to see how they're implemented in assembly.
#68236 - DekuTree64 - Mon Jan 23, 2006 4:15 am
Here's a very basic assembly function that you can put into a .s file and compile:
Code: |
.text
.arm
.align 2
.global ThisIsAFunction
ThisIsAFunction:
bx lr |
Which can then be externed in a .c file like so, and called like a normal function:
Code: |
extern void ThisIsAFunction(); |
Or if it's in a .cpp file, you'll need to tell the compiler that the function's name isn't mangled:
Code: |
extern "C" void ThisIsAFunction(); |
If you want to pass arguments into a function, they go into r0-r3. Arguments above that go onto the stack, which is kind of complicated so just keep it to 4 args or less for now.
r0 is the return value for the function, so if you want to add 2 numbers together and return the result, you could do something like:
Code: |
.text
.arm
.align 2
.global AddSomeNumbers
AddSomeNumbers:
add r0, r0, r1 @ r0 and r1 are the first 2 args passed
bx lr @ in, and r0 is the return value |
And the C prototype would look something like this:
Code: |
extern int AddSomeNumbers(int number1, int number2); |
Pretty straightforward. Just start writing some code and you'll get the hang of it in no time :)
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku
#68238 - Dwedit - Mon Jan 23, 2006 4:58 am
For an example of a well-written emulator, read the source code to an open-source GBA emulator, such as PocketNES, Goomba, SMSAdvance, or Foon.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."
#68239 - HyperHacker - Mon Jan 23, 2006 5:04 am
Oh, you can include ASM source files? I knew you could have it inline... How do you do this, just write the code in a .s file and #include it?
Also why does every message board ever made get flood control wrong? Editing isn't posting! -_-
#68241 - DekuTree64 - Mon Jan 23, 2006 5:28 am
No, don't #include it in a .c file, that's no different than just typing the assembly code in the .c file in the first place. Compile the .s file by itself, either by calling as.exe directly, or calling gcc on it and letting that figure out it's an assembly file by the extension.
The nice thing about calling gcc is that if you name it with an uppercase .S extension, it will run the C preprocessor on it before passing down to as.exe.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku
#68255 - agentq - Mon Jan 23, 2006 10:22 am
An example of inline assembler can be found in the ScummVM source code. Do a search for asm in all the files to find it, I'm sorry I don't have access to the code base at the moment to tell you exactly where it is.
#68306 - Ethos - Mon Jan 23, 2006 6:16 pm
Also this source has asm files, gasm compatible...
Here
_________________
Ethos' Homepage (Demos/NDS 3D Tutorial)