Refactoring to support (future) string asm.

This commit is contained in:
Radosław Kujawa 2018-06-25 14:05:47 +02:00
parent dfb3bd1fca
commit dc1e2bf829
No known key found for this signature in database
GPG Key ID: 18A71CD0FD7270D7
4 changed files with 30 additions and 18 deletions

View File

@ -27,13 +27,13 @@ assemble_init(bus_t *b, uint16_t pc)
}
bool
assemble_single_implied(assembler_t *a, const char *mnemonic)
assemble_single_implied(assembler_t *a, char *mnemonic)
{
return assemble_single(a, mnemonic, IMPLIED, 0, 0);
}
bool
assemble_single(assembler_t *a, const char *mnemonic, addressing_t mode, uint8_t op1, uint8_t op2)
assemble_single(assembler_t *a, char *mnemonic, addressing_t mode, uint8_t op1, uint8_t op2)
{
uint8_t *asmbuf;
uint8_t bsize;
@ -50,31 +50,22 @@ assemble_single(assembler_t *a, const char *mnemonic, addressing_t mode, uint8_t
}
bool
assemble_single_buf_implied(uint8_t **buf, uint8_t *bsize, const char *mnemonic)
assemble_single_buf_implied(uint8_t **buf, uint8_t *bsize, char *mnemonic)
{
return assemble_single_buf(buf, bsize, mnemonic, IMPLIED, 0, 0);
}
bool
assemble_single_buf(uint8_t **buf, uint8_t *bsize, const char *mnemonic, addressing_t mode, uint8_t op1, uint8_t op2)
assemble_single_buf(uint8_t **buf, uint8_t *bsize, 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) { /* this is stupid */
id = instruction_decode(opcode);
if ((strcmp(mnemonic, id.mnemonic) == 0) && (id.mode == mode)) {
found = true;
break;
}
opcode++;
}
found = instruction_opcode_by_mnemonic(mnemonic, mode, &opcode, &id);
if (!found) {
rk65c02_log(LOG_ERROR,

View File

@ -11,12 +11,12 @@ struct assembler {
typedef struct assembler assembler_t;
bool assemble_single_buf_implied(uint8_t **, uint8_t *, const char *);
bool assemble_single_buf(uint8_t **, uint8_t *, const char *, addressing_t, uint8_t, uint8_t);
bool assemble_single_buf_implied(uint8_t **, uint8_t *, char *);
bool assemble_single_buf(uint8_t **, uint8_t *, char *, addressing_t, uint8_t, uint8_t);
assembler_t assemble_init(bus_t *, uint16_t);
bool assemble_single(assembler_t *, const char *, addressing_t, uint8_t, uint8_t);
bool assemble_single_implied(assembler_t *, const char *);
bool assemble_single(assembler_t *, char *, addressing_t, uint8_t, uint8_t);
bool assemble_single_implied(assembler_t *, char *);
#endif /* _ASSEMBLER_H_ */

View File

@ -311,3 +311,23 @@ instruction_modify_pc(instrdef_t *id)
return id->modify_pc;
}
/* find instr definition (and opcode) searching by mnemonic and addr mode */
bool
instruction_opcode_by_mnemonic(char *mnemonic, addressing_t mode, uint8_t *opcode, instrdef_t *id)
{
bool found;
found = false;
while ((*opcode) <= 0xFF) { /* this is stupid */
*id = instruction_decode(*opcode);
if ((strcmp(mnemonic, id->mnemonic) == 0) && (id->mode == mode)) {
found = true;
break;
}
(*opcode)++;
}
return found;
}

View File

@ -56,5 +56,6 @@ uint8_t stack_pop(rk65c02emu_t *);
void program_counter_increment(rk65c02emu_t *, instrdef_t *);
bool instruction_modify_pc(instrdef_t *);
void program_counter_branch(rk65c02emu_t *, int8_t);
bool instruction_opcode_by_mnemonic(char *, addressing_t, uint8_t *, instrdef_t *);
#endif /* _INSTRUCTION_H_ */