#define ULAS_ASMSTR_PAD ".pad"
#define ULAS_ASMSTR_INCBIN ".incbin"
#define ULAS_ASMSTR_DEF ".def"
+#define ULAS_ASMSTR_CHKSM ".chksm"
// configurable tokens
#define ULAS_TOK_COMMENT ';'
// this is a bit of a hack to get the int expression to evaluate anyway
// because expressions only work in the final pass
// Beware that this can cause unforseen writes to the file and should really
-// only be uesd to evalulate an expression that needs to be evaled during
+// only be uesd to evalulate an expression that needs to be evaled during
// all passes and nothing else!
#define ULAS_EVALEXPRS(...) \
{ \
// internal counter
// used whenever a new unique number might be needed
int icntr;
+
+ char chksm;
};
extern struct ulas ulas;
ULAS_ASMDIR_INCBIN,
// .def name = value
ULAS_ASMDIR_DEF,
+ // inserts checksum into rom
+ ULAS_ASMDIR_CHKSM,
};
// amount of registers
ulas.line = 0;
ulas.icntr = 0;
ulas.address = 0;
+ ulas.chksm = 0;
ulas.filename = ulas.initial_filename;
}
if (ulas.pass == ULAS_PASS_FINAL) {
fwrite(outbuf, 1, n, dst);
}
+
+ if (ulas.address < 0x14C) {
+ for (int i =0; i < n; i++) {
+ ulas.chksm = ulas.chksm - outbuf[i] - 1;
+ }
+ }
}
int ulas_asmdirbyte(FILE *dst, const char **line, unsigned long n, int *rc) {
}
if (ulas.tok.buf[0] == ULAS_TOK_ASMDIR_BEGIN) {
- const char *dirstrs[] = {
- ULAS_ASMSTR_ORG, ULAS_ASMSTR_SET, ULAS_ASMSTR_BYTE,
- ULAS_ASMSTR_STR, ULAS_ASMSTR_FILL, ULAS_ASMSTR_PAD,
- ULAS_ASMSTR_INCBIN, ULAS_ASMSTR_DEF, NULL};
+ const char *dirstrs[] = {ULAS_ASMSTR_ORG, ULAS_ASMSTR_SET,
+ ULAS_ASMSTR_BYTE, ULAS_ASMSTR_STR,
+ ULAS_ASMSTR_FILL, ULAS_ASMSTR_PAD,
+ ULAS_ASMSTR_INCBIN, ULAS_ASMSTR_DEF,
+ ULAS_ASMSTR_CHKSM, NULL};
enum ulas_asmdir dirs[] = {
- ULAS_ASMDIR_ORG, ULAS_ASMDIR_SET, ULAS_ASMDIR_BYTE, ULAS_ASMDIR_STR,
- ULAS_ASMDIR_FILL, ULAS_ASMDIR_PAD, ULAS_ASMDIR_INCBIN, ULAS_ASMDIR_DEF};
+ ULAS_ASMDIR_ORG, ULAS_ASMDIR_SET, ULAS_ASMDIR_BYTE,
+ ULAS_ASMDIR_STR, ULAS_ASMDIR_FILL, ULAS_ASMDIR_PAD,
+ ULAS_ASMDIR_INCBIN, ULAS_ASMDIR_DEF, ULAS_ASMDIR_CHKSM};
enum ulas_asmdir dir = ULAS_ASMDIR_NONE;
case ULAS_ASMDIR_INCBIN:
other_writes += ulas_asmdirincbin(dst, &line, n, &rc);
break;
+ case ULAS_ASMDIR_CHKSM:
+ ulas_asmout(dst, &ulas.chksm, 1);
+ other_writes += 1;
+ break;
case ULAS_ASMDIR_PAD:
// TODO: pad is the same as .fill n, $ - n
case ULAS_ASMDIR_NONE: