5 // Created by Matt Parsons on 06/03/2019.
6 // Copyright © 2019 Matt Parsons. All rights reserved.
9 //Write Byte to Gayle Space 0xda9000 (0x0000c3)
10 //Read Byte From Gayle Space 0xda9000
11 //Read Byte From Gayle Space 0xdaa000
21 #define CLOCKBASE 0xDC0000
23 //#define GSTATUS 0xda201c
24 //#define GCLOW 0xda2010
25 //#define GDH 0xda2018
33 #define GERROR 0xda2004 //Error
34 #define GSTATUS 0xda201c //Status
36 #define GFEAT 0xda2004 //Write : Feature
37 #define GCMD 0xda201c //Write : Command
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
47 #define GIDENT 0xDE1000
50 #define GCS 0xDA8000 //Card Control
51 #define GIRQ 0xDA9000 // IRQ
52 #define GINT 0xDAA000 //Int enable
53 #define GCONF 0xDAB00 //Gayle Config
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 */
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 */
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 */
95 static uint8_t gayle_irq, gayle_int, gayle_cs, gayle_cs_mask, gayle_cfg;
96 static struct ide_controller *ide0;
100 ide0 = ide_allocate("cf");
101 fd = open("hd0.img", O_RDWR);
103 printf("HDD Image hd0.image failed open\n");
105 ide_attach(ide0, 0, fd);
106 ide_reset_begin(ide0);
107 printf("HDD Image hd0.image attached\n");
111 uint8_t CheckIrq(void){
114 irq = ide0->drive->intrq;
116 // printf("IDE IRQ: 0\n");
121 void writeGayleB(unsigned int address, unsigned int value){
124 if (address == GFEAT) {
125 ide_write8(ide0, ide_feature_w, value);
128 if (address == GCMD) {
129 ide_write8(ide0, ide_command_w, value);
132 if (address == GSECTCNT) {
133 ide_write8(ide0, ide_sec_count, value);
136 if (address == GSECTNUM) {
137 ide_write8(ide0, ide_sec_num, value);
140 if (address == GCYLLOW) {
141 ide_write8(ide0, ide_cyl_low, value);
144 if (address == GCYLHIGH) {
145 ide_write8(ide0, ide_cyl_hi, value);
148 if (address == GDEVHEAD) {
149 ide_write8(ide0, ide_dev_head, value);
152 if (address == GCTRL) {
153 ide_write8(ide0, ide_devctrl_w, value);
157 if (address == GIDENT){
159 // printf("Write Byte to Gayle Ident 0x%06x (0x%06x)\n",address,value);
164 if (address == GIRQ){
165 // printf("Write Byte to Gayle GIRQ 0x%06x (0x%06x)\n",address,value);
166 gayle_irq = (gayle_irq & value) | (value & (GAYLE_IRQ_RESET | GAYLE_IRQ_BERR));
171 printf("Write Byte to Gayle GCS 0x%06x (0x%06x)\n",address,value);
172 gayle_cs_mask = value & ~3;
174 gayle_cs |= value & 3;
178 if (address == GINT){
179 printf("Write Byte to Gayle GINT 0x%06x (0x%06x)\n",address,value);
184 if (address == GCONF){
185 printf("Write Byte to Gayle GCONF 0x%06x (0x%06x)\n",address,value);
194 printf("Write Byte to Gayle Space 0x%06x (0x%06x)\n",address,value);
197 void writeGayle(unsigned int address, unsigned int value){
198 if (address == GDATA) {
199 ide_write16(ide0, ide_data, value);
203 printf("Write Word to Gayle Space 0x%06x (0x%06x)\n",address,value);
206 void writeGayleL(unsigned int address, unsigned int value){
207 printf("Write Long to Gayle Space 0x%06x (0x%06x)\n",address,value);
210 uint8_t readGayleB(unsigned int address){
212 if (address == GERROR) {
213 return ide_read8(ide0, ide_error_r);
215 if (address == GSTATUS) {
216 return ide_read8(ide0, ide_status_r);
219 if (address == GSECTCNT) {
220 return ide_read8(ide0, ide_sec_count);
223 if (address == GSECTNUM) {
224 return ide_read8(ide0, ide_sec_num);
227 if (address == GCYLLOW) {
228 return ide_read8(ide0, ide_cyl_low);
231 if (address == GCYLHIGH) {
232 return ide_read8(ide0, ide_cyl_hi);
235 if (address == GDEVHEAD) {
236 return ide_read8(ide0, ide_dev_head);
239 if (address == GCTRL) {
240 return ide_read8(ide0, ide_altst_r);
243 if (address == GIDENT){
245 //printf("Read Byte from Gayle Ident 0x%06x (0x%06x)\n",address,counter);
246 if (counter == 0 || counter == 1 || counter == 3){
247 val= 0x80;//80; to enable gayle
255 if (address == GIRQ){
256 // printf("Read Byte From GIRQ Space 0x%06x\n",gayle_irq);
257 return 0x80;//gayle_irq;
261 printf("Read Byte From GCS Space 0x%06x\n",0x1234);
263 v = gayle_cs_mask | gayle_cs;
267 if (address == GINT){
268 // printf("Read Byte From GINT Space 0x%06x\n",gayle_int);
272 if (address == GCONF){
273 printf("Read Byte From GCONF Space 0x%06x\n",gayle_cfg & 0x0f);
274 return gayle_cfg & 0x0f;
278 printf("Read Byte From Gayle Space 0x%06x\n",address);
282 uint16_t readGayle(unsigned int address){
283 if (address == GDATA){
285 value = ide_read16 (ide0, ide_data);
286 // value = (value << 8) | (value >> 8);
291 printf("Read Word From Gayle Space 0x%06x\n",address);
295 uint32_t readGayleL(unsigned int address){
296 printf("Read Long From Gayle Space 0x%06x\n",address);