forked from PlaneteCasio/Casio_asm
19 lines
448 B
C
Executable File
19 lines
448 B
C
Executable File
#include "opcode.h"
|
|
|
|
//reads an opcode
|
|
int readOpcode(char* data, int pos, int max, opcode_t *opcode) {
|
|
if(pos>=max||pos<0) return -1;
|
|
opcode->byte0=data[pos];
|
|
if(opcode->nArgs) { //if we have arguments, read them
|
|
if(pos+1>=max) return -1;
|
|
opcode->byte1=data[pos+1];
|
|
if(opcode->nArgs-1) { //we either have 2 args or an immediate value
|
|
if(pos+2>=max) return -1;
|
|
opcode->byte2=data[pos+2];
|
|
return 3;
|
|
}
|
|
return 2;
|
|
}
|
|
return 1;
|
|
}
|