summaryrefslogtreecommitdiff
path: root/vdp.cpp
blob: 632429d11535a751f883c32337a1de4f466cdd93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* SPDX-License-Identifier: Unlicense
 */

#include "vdp.hpp"

uint32_t VDP::Read(const uint32_t offset, const enum bitness bitness)
{
    const uint32_t res{};
    if (DEBUG_TRACE_VDP_ACCESS) {
        printf(
                "VDP r%d%s @0x%08x 0x%0*x\n",
                bitness * 8,
                (bitness <= 1 ? " " : ""),
                base_address + offset,
                bitness * 2,
                res);
    }
    if (bitness == BITNESS_32) {
        // TODO
    } else if (bitness == BITNESS_16) {
        // TODO
    }
    // Ignore 8-bit reads for now
    return 0;
}

void VDP::Write(const uint32_t offset, const enum bitness bitness, const uint32_t value)
{
    if (DEBUG_TRACE_VDP_ACCESS) {
        printf(
                "VDP w%d%s @0x%08x 0x%0*x",
                bitness * 8,
                (bitness <= 1 ? " " : ""),
                base_address + offset,
                bitness * 2,
                value);
    }
    if (bitness == BITNESS_32) {
        if (offset == 4 || offset == 6) {
            writeControl((value >> 16) & 0xffff);
            writeControl(value & 0xffff);
        }
    } else if (bitness == BITNESS_16) {
        if (offset == 4 || offset == 6) {
            writeControl(value & 0xffff);
        }
    }
    if (DEBUG_TRACE_VDP_ACCESS) {
        printf("\n");
    }
    // Ignore 8-bit writes for now
}

void VDP::writeControl(const uint16_t value)
{
    if (((value >> 13) & 0x7) == 4) {
        const uint8_t reg_num = (value >> 8) & 0x1f;
        const uint8_t reg_val = value & 0xff;
        if (DEBUG_TRACE_VDP_ACCESS) {
            printf(": reg 0x%02x w 0x%02x", reg_num, reg_val);
        }
        _reg[reg_num] = reg_val;
    }
}