fork of PCE focusing on macplus, supporting DaynaPort SCSI network emulation
1/*****************************************************************************
2 * pce *
3 *****************************************************************************/
4
5/*****************************************************************************
6 * File name: src/utils/pri/new.c *
7 * Created: 2013-12-19 by Hampa Hug <hampa@hampa.ch> *
8 * Copyright: (C) 2013-2015 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
28#include <drivers/pri/pri.h>
29
30
31int pri_half_step (pri_img_t *img)
32{
33 unsigned c, ci, cn;
34 pri_cyl_t *cyl1, *cyl2;
35
36 cn = pri_img_get_cyl_cnt (img);
37
38 for (c = 0; c < cn; c++) {
39 ci = cn - c - 1;
40
41 cyl1 = pri_img_rmv_cylinder (img, ci);
42 cyl2 = pri_cyl_clone (cyl1);
43
44 pri_img_set_cylinder (img, cyl1, 2 * ci);
45 pri_img_set_cylinder (img, cyl2, 2 * ci + 1);
46 }
47
48 return (0);
49}
50
51static
52int pri_new_tracks (pri_img_t *img, pri_cyl_t *cyl, unsigned c)
53{
54 unsigned h, h0, h1;
55 pri_trk_t *trk;
56
57 if (par_trk_all) {
58 h0 = 0;
59 h1 = cyl->trk_cnt;
60 }
61 else {
62 h0 = par_trk[0];
63 h1 = par_trk[1] + 1;
64 }
65
66 for (h = h0; h < h1; h++) {
67 trk = pri_img_get_track (img, c, h, 0);
68
69 if (trk != NULL) {
70 continue;
71 }
72
73 trk = pri_img_get_track (img, c, h, 1);
74
75 if (trk == NULL) {
76 return (1);
77 }
78
79 pri_trk_set_clock (trk, par_data_rate);
80 }
81
82 return (0);
83}
84
85static
86int pri_new_cylinders (pri_img_t *img)
87{
88 unsigned c, c0, c1;
89 pri_cyl_t *cyl;
90
91 if (par_cyl_all) {
92 c0 = 0;
93 c1 = img->cyl_cnt;
94 }
95 else {
96 c0 = par_cyl[0];
97 c1 = par_cyl[1] + 1;
98 }
99
100 for (c = c0; c < c1; c++) {
101 cyl = pri_img_get_cylinder (img, c, 1);
102
103 if (cyl == NULL) {
104 return (1);
105 }
106
107 if (pri_new_tracks (img, cyl, c)) {
108 return (1);
109 }
110 }
111
112 return (0);
113}
114
115int pri_new (pri_img_t *img)
116{
117 if (pri_new_cylinders (img)) {
118 fprintf (stderr, "%s: creating failed\n", arg0);
119 }
120
121 return (0);
122}