1
0
mirror of https://github.com/rkujawa/rk65c02.git synced 2024-12-22 15:31:12 +00:00

Add functions to assemble mnemonics into machine code (into buffer).

This commit is contained in:
Radosław Kujawa 2017-02-02 14:45:06 +01:00
parent 941036615e
commit 9eff6d535b
2 changed files with 49 additions and 0 deletions

View File

@ -108,6 +108,52 @@ instruction_print(instruction_t *i)
}
}
bool
assemble_single_implied(uint8_t **buf, uint8_t *bsize, const char *mnemonic)
{
return assemble_single(buf, bsize, mnemonic, IMPLIED, 0, 0);
}
bool
assemble_single(uint8_t **buf, uint8_t *bsize, const char *mnemonic, addressing_t mode, uint8_t op1, uint8_t op2)
{
instrdef_t id;
uint8_t opcode;
bool found;
found = false;
opcode = 0;
/* find the opcode for given mnemonic and addressing mode */
while (opcode < 0xFF) {
id = instruction_decode(opcode);
if ((strcmp(mnemonic, id.mnemonic) == 0) && (id.mode == mode)) {
found = true;
break;
}
opcode++;
}
if (!found) {
fprintf(stderr, "Couldn't find opcode for mnemonic %s mode %x\n", mnemonic, mode);
return false;
}
*buf = malloc(id.size);
if(*buf == NULL) {
fprintf(stderr, "Error allocating assembly buffer\n");
return false;
}
memset(*buf, 0, id.size);
*bsize = id.size;
*buf[0] = opcode;
return found;
}
void
disassemble(bus_t *b, uint16_t addr)
{

View File

@ -55,4 +55,7 @@ void program_counter_increment(rk65c02emu_t *, instrdef_t *);
bool instruction_modify_pc(instrdef_t *);
void program_counter_branch(rk65c02emu_t *, int8_t);
bool assemble_single_implied(uint8_t **, uint8_t *, const char *);
bool assemble_single(uint8_t **, uint8_t *, const char *, addressing_t, uint8_t, uint8_t);
#endif /* _INSTRUCTION_H_ */