-1

I've been trying to write a simple script compiler for a custom language used by the Game Boy Advance's Z80 processor.

All I want it to do is look at a human-readable command, take it and its arguments and convert it into a hexadecimal value into a ROM file. That's it. Each command is a byte, and each may take a different number of arguments - arguments can be either 8, 16, or 32 bits and each command has a specific number of arguments that it takes.

All of this sort of code is handled by the game and converted into workable machine code within the game's memory, so I'm not writing a full-on assembly compiler if you will. The game automatically knows how many args a command has, what each command does, exactly how to execute it as it is, etc.

For instance, you have command 0x4E, which takes in one 8-bit argument and another 32-bit argument. In hex that would obviously be 4E XX YY YY YY YY. I want my compiler to read it from text as foo 0xXX 0xYYYYYYYY and directly write it into a file as the former.

My question is, how would I do that in VB.NET? I know it's probably a very simple answer, but I see a lot of different options to write it to a file--some work and most don't for me. Could you give me some sample code as to how I would do this?

AlexTheRose
  • 125
  • 1
  • 1
  • 8
  • 2
    The purpose of SO is NOT to supply or write code for you. You write code; you find a problem; you ask on SO. – Mitch Wheat May 25 '13 at 02:57
  • _"used by the Game Boy Advance's Z80 processor"_. As far as I can recall, the GB-Z80 in the GBA is active only in backwards compatibility mode, i.e. when you've got a regular Gameboy / Gameboy Color cartridge plugged in. So I don't think it's possible to use it as a sort-of coprocessor to the ARM in GBA mode, if that's what you were planning to do. – Michael Jun 28 '13 at 17:35

2 Answers2

1

Writing an assembly compiler as I understand it is not so simple. I recomed you to use one already written see: Software Development Tools for Z80 Family

If you are still interested in writing it here are instructions:

  1. Write the text you want to translate to some file (or memory stream)
  2. Read it line by line
  3. Parse the line either splitting it to an array or with regular expressions
  4. Identify command and arguments (as far as I remember it some commands does not have arguments)
  5. Translate the command to Hex (with a collection or dictionary of commands)
  6. Write results to an array remembering the references for jump addresses
  7. When everything is translated resolve addresses and write them to right places.

I think that the most tricky part is to deal with symbolic addressees. If you are still interested write a first piece of code (or ask how to do it) and continue with next ones.

IvanH
  • 5,039
  • 14
  • 60
  • 81
0

This sounds like an assembler, even if it for a 'custom language'. Start by parsing the command lines. use string.split method to convert the string to an array of strings. the first element in the array is your foo, you can then look that up and output 4E, then convert the subsequent elements to bytes.

Paul Anderson
  • 1,120
  • 3
  • 11
  • 22