]> git.sesse.net Git - pistorm/blob - platforms/amiga/cdtv-dmac.c
f41adf1ebc29b7c4dcd72c4203c09938e8af4459
[pistorm] / platforms / amiga / cdtv-dmac.c
1 #include <stdio.h>
2 #include <stdint.h>
3 #include <stdlib.h>
4 #include "config_file/config_file.h"
5
6 uint8_t dmac_reg_idx = 0;
7 uint8_t dmac_reg_values[0xFFFF];
8
9 uint8_t cdtv_dmac_reg_idx_read() {
10     return dmac_reg_idx;
11 }
12
13 /* DMAC Registers
14 R   0x06 [B]    - Something
15
16     0x40 [W]    - ISTR
17 RW  0x42 [W]    - CNTR
18
19     0x80 [L]    - WTC
20     0x84 [L]    - ACR
21
22     0x8E [B]    - SASR
23 W   0x8F [B]    - Something
24     0x90        - SCMD
25     0x91 [B]    - Something
26     0x92 [B]    - Something?
27 RW  0x93 [B]    - Something
28
29 R   0xA2?[W?]   - Some status thing?
30 W   0xA4?[W?]   - Something
31 W   0xA6?[W?]   - Something
32 W   0xA8?[W?]   - Something
33
34     0xDE [W]    - ST_DMA
35     0xE0 [W]    - SP_DMA
36     0xE2 [W]    - CINT
37     0xE4 [W]    - Something
38     0xE4-0xE5   - Nothing
39     0xE6 [W]    - Flush
40 */
41
42 void cdtv_dmac_reg_idx_write(uint8_t value) {
43     dmac_reg_idx = value;
44 }
45
46 uint32_t cdtv_dmac_read(uint32_t address, uint8_t type) {
47     uint32_t ret = 0;
48
49     switch (type) {
50         case OP_TYPE_BYTE:
51             return dmac_reg_values[address];
52         case OP_TYPE_WORD:
53             return be16toh(*((uint16_t *)&dmac_reg_values[address]));
54         default:
55             break;
56     }
57
58     return ret;
59 }
60
61 void cdtv_dmac_write(uint32_t address, uint32_t value, uint8_t type) {
62     switch (type) {
63         case OP_TYPE_BYTE:
64             dmac_reg_values[address] = (uint8_t)value;
65             return ;
66         case OP_TYPE_WORD:
67             printf("Help, it's a scary word write.\n");
68             *((uint16_t *)&dmac_reg_values[address]) = htobe16(value);
69             return;
70     }
71 }