]> git.sesse.net Git - pistorm/blob - Gayle.c
5c16da3ba95120b1dd836996d083a57456492d9e
[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 //Write Byte to Gayle Space 0xda2018 (0x000000)
30 //Read Byte From Gayle Space 0xda2010
31 //Read Byte From Gayle Space 0xda201c
32 //Write Byte to Gayle Space 0xdaa000 (0x00002c)
33 //Write Byte to Gayle Space 0xda8000 (0x000000)
34 //Write Byte to Gayle Space 0xda2018 (0x000000)
35 //Write Byte to Gayle Space 0xda2010 (0x000012)
36
37
38
39 /*
40 Write Byte to Gayle Space 0xda3018 (0x000000)
41
42 Read Byte from Gayle Ident 0xde1000 (0x000004)
43 Write ide_dev_head: 0x0000a0
44 Write Byte to Gayle Space 0xda2018 (0x0000a0)
45 Write ide_cyl_low: 0x000012
46 Write Byte to Gayle Space 0xda2010 (0x000012)
47 Write ide_cyl_low: 0x000034
48 Write Byte to Gayle Space 0xda2010 (0x000034)
49 Write Byte to Gayle Space 0xda3018 (0x000000)
50 Write ide_status_r: 0x000010
51 Write Byte to Gayle Space 0xda201c (0x000010)
52 */
53
54
55 int counter;
56 static struct ide_controller *ide0;
57 int fd;
58
59 void InitGayle(void){
60    ide0 = ide_allocate("cf");
61    fd = open("hd0.img", O_RDWR);
62    if (fd == -1){
63         printf("HDD Image hd0.image failed open\n");
64    }else{
65         ide_attach(ide0, 0, fd);
66         ide_reset_begin(ide0);
67         printf("HDD Image hd0.image attached\n");
68    }
69 }
70
71 uint8_t CheckIrq(void){
72 uint8_t irq;
73
74         irq = ide0->drive->intrq;
75 //      if (irq==0)
76 //      printf("IDE IRQ: 0\n");
77
78 return irq;
79 }
80
81 void writeGayleB(unsigned int address, unsigned int value){
82
83
84     if (address == GSTATUS) {
85         ide_write8(ide0, ide_status_r, value);
86 //      printf("Write ide_status_r: 0x%06x IRQ:0x%06x\n",value, ide0->drive->intrq);
87         return;
88         }
89
90    if (address == GDH) {
91         ide_write8(ide0, ide_dev_head, value);
92 //      printf("Write ide_dev_head: 0x%06x\n",value);
93         return;
94         }
95
96     if (address == GCLOW) {
97         ide_write8(ide0, ide_cyl_low, value);
98 //        printf("Write ide_cyl_low: 0x%06x\n",value);
99         return;
100         }
101
102
103     if (address == 0xDE1000){
104          counter = 0;
105 //       printf("Write Byte to Gayle Ident 0x%06x (0x%06x)\n",address,value);
106         return;
107         }
108
109     if (address == 0xda9000){
110         return;
111         }
112
113       if (address == 0xda8000){
114         return;
115         }
116
117       if (address == 0xdaa000){
118         return;
119         }
120
121       if (address == 0xdab000){
122         return;
123         }
124
125
126
127
128
129     printf("Write Byte to Gayle Space 0x%06x (0x%06x)\n",address,value);
130 }
131
132 void writeGayle(unsigned int address, unsigned int value){
133 //    printf("Write to Gayle Space 0x%06x (0x%06x)\n",address,value);
134 }
135
136 void writeGayleL(unsigned int address, unsigned int value){
137 //    printf("Write Long to Gayle Space 0x%06x (0x%06x)\n",address,value);
138 }
139
140 uint8_t readGayleB(unsigned int address){
141
142         if (address == GSTATUS) {
143 //      printf("Read ide_status_r\n");
144         return ide_read8(ide0, ide_status_r);
145         }
146
147         if (address == GCLOW) {
148 //      printf("Read ide_cyl_low\n");
149         return ide_read8(ide0, ide_cyl_low);
150         }
151
152         if (address == GDH) {
153 //      printf("Read ide_dev_head\n");
154         return ide_read8(ide0, ide_dev_head);
155         }
156
157
158     if (address == 0xDE1000){
159         counter++;
160 //      printf("Read Byte from Gayle Ident 0x%06x (0x%06x)\n",address,counter);
161
162         if (counter == 3){ 
163 //              printf("Gayle Ident cycle\n");
164                 return 0xFF;//7F; to enable gayle
165         }else{
166                 return 0xFF;
167         }
168
169         }
170
171       if (address == 0xda9000){
172         return 0;
173         }
174
175       if (address == 0xdaa000){
176         return 0;
177         }
178
179     printf("Read Byte From Gayle Space 0x%06x\n",address);
180     return 0xFF;
181 }
182
183 uint16_t readGayle(unsigned int address){
184     printf("Read From Gayle Space 0x%06x\n",address);
185     return 0x8000;
186 }
187
188 uint32_t readGayleL(unsigned int address){
189     printf("Read Long From Gayle Space 0x%06x\n",address);
190     return 0x8000;
191 }