]> git.sesse.net Git - pistorm/blob - Gayle.c
irq handling simplified
[pistorm] / Gayle.c
1 //
2 //  Gayle.c
3 //  Omega
4 //
5 //  Created by Matt Parsons on 06/03/2019.
6 //  Copyright © 2019 Matt Parsons. All rights reserved.
7 //
8
9 //Write Byte to Gayle Space 0xda9000 (0x0000c3)
10 //Read Byte From Gayle Space 0xda9000
11 //Read Byte From Gayle Space 0xdaa000
12
13
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <fcntl.h>
17 #include <unistd.h>
18 #include "Gayle.h"
19 #include "ide.h"
20
21 #define CLOCKBASE 0xDC0000
22
23 //#define GSTATUS 0xda201c 
24 //#define GCLOW   0xda2010
25 //#define GDH   0xda2018
26
27
28
29
30 //Gayle Addresses
31
32 //Gayle IDE Reads
33 #define  GERROR 0xda2004        //Error
34 #define  GSTATUS 0xda201c       //Status
35 //Gayle IDE Writes
36 #define  GFEAT 0xda2004         //Write : Feature
37 #define  GCMD   0xda201c        //Write : Command
38 //Gayle IDE RW
39 #define  GDATA 0xda2000         //Data
40 #define  GSECTCNT 0xda2008      //SectorCount
41 #define  GSECTNUM 0xda200c      //SectorNumber
42 #define  GCYLLOW 0xda2010       //CylinderLow
43 #define  GCYLHIGH 0xda2014      //CylinderHigh
44 #define  GDEVHEAD 0xda2018      //Device/Head
45 #define  GCTRL 0xda3018         //Control
46 // Gayle Ident
47 #define GIDENT 0xDE1000
48
49 // Gayle IRQ/CC
50 #define GCS 0xDA8000  //Card Control
51 #define GIRQ 0xDA9000 // IRQ
52 #define GINT 0xDAA000 //Int enable
53 #define GCONF 0xDAB00 //Gayle Config
54
55 /* DA8000 */
56 #define GAYLE_CS_IDE    0x80    /* IDE int status */
57 #define GAYLE_CS_CCDET  0x40    /* credit card detect */
58 #define GAYLE_CS_BVD1   0x20    /* battery voltage detect 1 */
59 #define GAYLE_CS_SC     0x20    /* credit card status change */
60 #define GAYLE_CS_BVD2   0x10    /* battery voltage detect 2 */
61 #define GAYLE_CS_DA     0x10    /* digital audio */
62 #define GAYLE_CS_WR     0x08    /* write enable (1 == enabled) */
63 #define GAYLE_CS_BSY    0x04    /* credit card busy */
64 #define GAYLE_CS_IRQ    0x04    /* interrupt request */
65 #define GAYLE_CS_DAEN   0x02    /* enable digital audio */ 
66 #define GAYLE_CS_DIS    0x01    /* disable PCMCIA slot */ 
67
68 /* DA9000 */
69 #define GAYLE_IRQ_IDE       0x80
70 #define GAYLE_IRQ_CCDET     0x40    /* credit card detect */
71 #define GAYLE_IRQ_BVD1      0x20    /* battery voltage detect 1 */
72 #define GAYLE_IRQ_SC        0x20    /* credit card status change */
73 #define GAYLE_IRQ_BVD2      0x10    /* battery voltage detect 2 */
74 #define GAYLE_IRQ_DA        0x10    /* digital audio */
75 #define GAYLE_IRQ_WR        0x08    /* write enable (1 == enabled) */
76 #define GAYLE_IRQ_BSY       0x04    /* credit card busy */
77 #define GAYLE_IRQ_IRQ       0x04    /* interrupt request */
78 #define GAYLE_IRQ_RESET     0x02    /* reset machine after CCDET change */ 
79 #define GAYLE_IRQ_BERR      0x01    /* generate bus error after CCDET change */ 
80
81 /* DAA000 */
82 #define GAYLE_INT_IDE       0x80    /* IDE interrupt enable */
83 #define GAYLE_INT_CCDET     0x40    /* credit card detect change enable */
84 #define GAYLE_INT_BVD1      0x20    /* battery voltage detect 1 change enable */
85 #define GAYLE_INT_SC        0x20    /* credit card status change enable */
86 #define GAYLE_INT_BVD2      0x10    /* battery voltage detect 2 change enable */
87 #define GAYLE_INT_DA        0x10    /* digital audio change enable */
88 #define GAYLE_INT_WR        0x08    /* write enable change enabled */
89 #define GAYLE_INT_BSY       0x04    /* credit card busy */
90 #define GAYLE_INT_IRQ       0x04    /* credit card interrupt request */
91 #define GAYLE_INT_BVD_LEV   0x02    /* BVD int level, 0=lev2,1=lev6 */ 
92 #define GAYLE_INT_BSY_LEV   0x01    /* BSY int level, 0=lev2,1=lev6 */ 
93
94 int counter;
95 static uint8_t gayle_irq, gayle_int, gayle_cs, gayle_cs_mask, gayle_cfg;
96 static struct ide_controller *ide0;
97 int fd;
98
99 void InitGayle(void){
100    ide0 = ide_allocate("cf");
101    fd = open("hd0.img", O_RDWR);
102    if (fd == -1){
103         printf("HDD Image hd0.image failed open\n");
104    }else{
105         ide_attach(ide0, 0, fd);
106         ide_reset_begin(ide0);
107         printf("HDD Image hd0.image attached\n");
108    }
109 }
110
111 uint8_t CheckIrq(void){
112 uint8_t irq;
113
114
115  if (gayle_int  & (1<<7)){ 
116         irq = ide0->drive->intrq;
117 //      if (irq==0)
118 //      printf("IDE IRQ: %x\n",irq);
119         return irq;
120         };
121   return 0;
122 }
123
124 void writeGayleB(unsigned int address, unsigned int value){
125
126
127     if (address == GFEAT) {
128         ide_write8(ide0, ide_feature_w, value);
129         return;
130         }
131     if (address == GCMD) {
132         ide_write8(ide0, ide_command_w, value);
133         return;
134         }
135     if (address == GSECTCNT) {
136         ide_write8(ide0, ide_sec_count, value);
137         return;
138         }
139     if (address == GSECTNUM) {
140         ide_write8(ide0, ide_sec_num, value);
141         return;
142         }
143     if (address == GCYLLOW) {
144         ide_write8(ide0, ide_cyl_low, value);
145         return;
146         }
147     if (address == GCYLHIGH) {
148         ide_write8(ide0, ide_cyl_hi, value);
149         return;
150         }
151     if (address == GDEVHEAD) {
152         ide_write8(ide0, ide_dev_head, value);
153         return;
154         }
155     if (address == GCTRL) {
156         ide_write8(ide0, ide_devctrl_w, value);
157         return;
158         }
159
160     if (address == GIDENT){
161          counter = 0;
162         // printf("Write Byte to Gayle Ident 0x%06x (0x%06x)\n",address,value);
163         return;
164         }
165
166
167     if (address == GIRQ){
168 //       printf("Write Byte to Gayle GIRQ 0x%06x (0x%06x)\n",address,value);
169         gayle_irq = (gayle_irq & value) | (value & (GAYLE_IRQ_RESET | GAYLE_IRQ_BERR));
170         
171         return;
172         }
173
174       if (address == GCS){
175         printf("Write Byte to Gayle GCS 0x%06x (0x%06x)\n",address,value);
176         gayle_cs_mask = value & ~3;
177         gayle_cs &= ~3;
178         gayle_cs |= value & 3;
179         return;
180         }
181
182       if (address == GINT){
183         printf("Write Byte to Gayle GINT 0x%06x (0x%06x)\n",address,value);
184         gayle_int = value;
185         return;
186         }
187
188       if (address == GCONF){
189         printf("Write Byte to Gayle GCONF 0x%06x (0x%06x)\n",address,value);
190         gayle_cfg = value;
191         return;
192         }
193
194
195
196
197
198     printf("Write Byte to Gayle Space 0x%06x (0x%06x)\n",address,value);
199 }
200
201 void writeGayle(unsigned int address, unsigned int value){
202         if (address == GDATA) {
203         ide_write16(ide0, ide_data, value);
204         return;
205         }
206
207     printf("Write Word to Gayle Space 0x%06x (0x%06x)\n",address,value);
208 }
209
210 void writeGayleL(unsigned int address, unsigned int value){
211     printf("Write Long to Gayle Space 0x%06x (0x%06x)\n",address,value);
212 }
213
214 uint8_t readGayleB(unsigned int address){
215
216     if (address == GERROR) {
217         return ide_read8(ide0, ide_error_r);
218         }
219     if (address == GSTATUS) {
220         return ide_read8(ide0, ide_status_r);
221         }
222
223     if (address == GSECTCNT) {
224         return ide_read8(ide0, ide_sec_count);
225         }
226
227     if (address == GSECTNUM) {
228         return ide_read8(ide0, ide_sec_num);
229         }
230
231     if (address == GCYLLOW) {
232         return ide_read8(ide0, ide_cyl_low);
233         }
234
235     if (address == GCYLHIGH) {
236         return ide_read8(ide0, ide_cyl_hi);
237         }
238
239     if (address == GDEVHEAD) {
240         return ide_read8(ide0, ide_dev_head);
241         }
242
243     if (address == GCTRL) {
244         return ide_read8(ide0, ide_altst_r);
245         }
246
247     if (address == GIDENT){
248         uint8_t val;
249         //printf("Read Byte from Gayle Ident 0x%06x (0x%06x)\n",address,counter);
250           if (counter == 0 || counter == 1 || counter == 3){
251                 val= 0x80;//80; to enable gayle
252           }else{
253                 val= 0x00;
254           }
255          counter++;
256          return val;
257         }
258
259      if (address == GIRQ){
260 //      printf("Read Byte From GIRQ Space 0x%06x\n",gayle_irq);
261
262         uint8_t irq;
263         irq = ide0->drive->intrq;
264
265         if (irq == 1){
266         //printf("IDE IRQ: %x\n",irq);
267         return 0x80;//gayle_irq;
268         }
269
270         return 0;
271      }
272
273       if (address == GCS){
274         printf("Read Byte From GCS Space 0x%06x\n",0x1234);
275          uint8_t v;
276          v = gayle_cs_mask | gayle_cs;
277          return v;
278         }
279
280       if (address == GINT){
281 //      printf("Read Byte From GINT Space 0x%06x\n",gayle_int);
282         return gayle_int;
283         }
284
285       if (address == GCONF){
286          printf("Read Byte From GCONF Space 0x%06x\n",gayle_cfg & 0x0f);
287         return gayle_cfg & 0x0f;
288         }
289
290
291     printf("Read Byte From Gayle Space 0x%06x\n",address);
292     return 0xFF;
293 }
294
295 uint16_t readGayle(unsigned int address){
296         if (address == GDATA){
297         uint16_t value;
298         value = ide_read16 (ide0, ide_data);
299 //      value = (value << 8) | (value >> 8);
300         return value;
301         }
302
303
304     printf("Read Word From Gayle Space 0x%06x\n",address);
305     return 0x8000;
306 }
307
308 uint32_t readGayleL(unsigned int address){
309     printf("Read Long From Gayle Space 0x%06x\n",address);
310     return 0x8000;
311 }