- if (!optarg)
- {
- fill_zserial();
- return;
- }
- size_t n = strlen(optarg);
- if (n == sizeof(Config.zserial) - 1)
- {
- char *p = optarg;
- while (*p && isalnum(*p))
- p++;
- if (!*p) /* ..optarg contains alphanumeric only? */
- {
- strncpy(Config.zserial, optarg, sizeof(Config.zserial));
- return;
- }
- }
- wrong_arg("Wrong zserial value %s, must be 6 ascii characters\n", optarg);
+ if (!optarg) {
+ fill_zserial();
+ return;
+ }
+ size_t n = strlen(optarg);
+ if (n == sizeof(Config.zserial) - 1) {
+ char *p = optarg;
+ while (*p && isalnum(*p))
+ p++;
+ if (!*p) { /* ..optarg contains alphanumeric only? */
+ strncpy(Config.zserial, optarg, sizeof(Config.zserial));
+ return;
+ }
+ }
+ wrong_arg("Wrong zserial value %s, must be 6 ascii characters\n", optarg);
+}
+
+void new_file_suffix(char *result, size_t maxlen, const char *src, const char *newsuffix)
+{
+ strncpy(result, src, maxlen);
+ char *p = strrchr(result, '.');
+ if (p && strchr(p, '/'))
+ p = NULL;
+ if (p) {
+ strncpy(p, newsuffix, maxlen - (p - result));
+ } else {
+ strncat(result, newsuffix, maxlen);
+ }
+ result[maxlen] = 0;
+}
+
+char *build_output_filename(const char basename[], const char *suffix)
+{
+ int n = strlen(basename) + strlen(suffix);
+ char *ofile = malloc(n + 1); /* todo!!! check for NULL. free. */
+ new_file_suffix(ofile, n, basename, suffix);
+ return ofile;
+}
+
+int init_assembly(void)
+{
+ /* TODO */
+ return OK;
+}
+
+int assembly(char *output_file)
+{
+ /* TODO */
+ FILE *file = fopen(output_file, "w");
+ if (file)
+ {
+ program_header_reset(6);
+
+ int size = sizeof(Program_header );
+ //Program_header.
+
+ Program_header.mode = 0; // DISPLAY_AVAILABLE | MONOSPACE_AVAILABLE;
+ Program_header.release = 1; // game version
+
+ Program_header.startPC = 64;
+
+ Program_header.dynamic_size = 128;
+ Program_header.h_file_size = 9; //sizeof(Program_header) + zmb->used_size;
+
+ ZMemblock *zmb = zmem_init(Program_header.h_file_size * 8);
+
+ //fprintf(file, "%c", 178); // printi command
+ //fprintf(file, "hello, world!");
+
+ zmem_putbyte(zmb, 186); // quit command
+
+
+
+ outputToFile(&Program_header, file);
+
+ //fprintf(file, "%c", 186);
+ fwrite(zmb->contents, zmb->allocated_size, 1, file);
+ fclose(file);
+ }
+
+ return OK;