fork of PCE focusing on macplus, supporting DaynaPort SCSI network emulation
1/*****************************************************************************
2 * pce *
3 *****************************************************************************/
4
5/*****************************************************************************
6 * File name: src/utils/pri/edit.c *
7 * Created: 2013-12-19 by Hampa Hug <hampa@hampa.ch> *
8 * Copyright: (C) 2013-2019 Hampa Hug <hampa@hampa.ch> *
9 *****************************************************************************/
10
11/*****************************************************************************
12 * This program is free software. You can redistribute it and / or modify it *
13 * under the terms of the GNU General Public License version 2 as published *
14 * by the Free Software Foundation. *
15 * *
16 * This program is distributed in the hope that it will be useful, but *
17 * WITHOUT ANY WARRANTY, without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
19 * Public License for more details. *
20 *****************************************************************************/
21
22
23#include "main.h"
24
25#include <stdio.h>
26#include <string.h>
27#include <stdlib.h>
28
29#include <drivers/pri/pri.h>
30
31
32static
33int pri_edit_clock_cb (pri_img_t *img, pri_trk_t *trk, unsigned long c, unsigned long h, void *p)
34{
35 pri_trk_set_clock (trk, *(unsigned long *) p);
36 return (0);
37}
38
39static
40int pri_edit_data_cb (pri_img_t *img, pri_trk_t *trk, unsigned long c, unsigned long h, void *p)
41{
42 pri_trk_clear (trk, *(unsigned long *) p);
43 return (0);
44}
45
46static
47int pri_edit_size_cb (pri_img_t *img, pri_trk_t *trk, unsigned long c, unsigned long h, void *p)
48{
49 pri_trk_set_size (trk, *(unsigned long *) p);
50 return (0);
51}
52
53static
54int pri_edit_image (pri_img_t *img, const char *what, unsigned long val)
55{
56 if (strcmp (what, "readonly") == 0) {
57 img->readonly = (val != 0);
58 return (0);
59 }
60 else if (strcmp (what, "woz-cleaned") == 0) {
61 img->woz_cleaned = (val != 0);
62 return (0);
63 }
64 else if (strcmp (what, "woz-track-sync") == 0) {
65 img->woz_track_sync = (val != 0);
66 return (0);
67 }
68 else {
69 return (-1);
70 }
71}
72
73static
74int pri_edit_tracks (pri_img_t *img, const char *what, unsigned long val)
75{
76 int r;
77 pri_trk_cb fct;
78
79 if (strcmp (what, "clock") == 0) {
80 fct = pri_edit_clock_cb;
81 }
82 else if (strcmp (what, "data") == 0) {
83 fct = pri_edit_data_cb;
84 }
85 else if (strcmp (what, "size") == 0) {
86 fct = pri_edit_size_cb;
87 }
88 else {
89 return (-1);
90 }
91
92 r = pri_for_all_tracks (img, fct, &val);
93
94 if (r) {
95 fprintf (stderr, "%s: editing failed (%s = %lu)\n",
96 arg0, what, val
97 );
98 }
99
100 return (r);
101}
102
103int pri_edit (pri_img_t *img, const char *what, const char *val)
104{
105 int r;
106 unsigned long v;
107
108 v = strtoul (val, NULL, 0);
109
110 if ((r = pri_edit_image (img, what, v)) >= 0) {
111 return (r);
112 }
113
114 if ((r = pri_edit_tracks (img, what, v)) >= 0) {
115 return (r);
116 }
117
118 fprintf (stderr, "%s: unknown field (%s)\n", arg0, what);
119
120 return (1);
121}