Annotation of nono/vm/sprite.cpp, revision 1.1.1.4

1.1       root        1: //
                      2: // nono
1.1.1.3   root        3: // Copyright (C) 2020 nono project
                      4: // Licensed under nono-license.txt
1.1       root        5: //
                      6: 
                      7: #include "sprite.h"
1.1.1.4 ! root        8: #include "mpu.h"
1.1       root        9: #include <sys/time.h>
                     10: 
                     11: SpriteDevice::SpriteDevice()
                     12: {
                     13:        logname = "sprite";
                     14:        devname = "Sprite";
                     15:        devaddr = baseaddr;
                     16:        devlen  = 0x010000;
                     17: 
1.1.1.2   root       18:        mem.reset(new uint8[4 * 8192]);
1.1       root       19: }
                     20: 
                     21: SpriteDevice::~SpriteDevice()
                     22: {
                     23: }
                     24: 
                     25: uint64
                     26: SpriteDevice::Read8(uint32 addr)
                     27: {
                     28:        if (addr >= 0xeb8000) {
                     29:                return mem[HB(addr - 0xeb8000)];
                     30:        }
                     31:        PANIC("not impl");
                     32: }
                     33: 
                     34: uint64
                     35: SpriteDevice::Read16(uint32 addr)
                     36: {
1.1.1.4 ! root       37:        // スプライトの Read はレジスタ、VRAM とも 17 ウェイト。
        !            38:        // InsideOut p.135
        !            39:        gMPU->AddCycle(17);
        !            40: 
1.1       root       41:        if (addr >= 0xeb8000) {
                     42:                return *(uint16 *)&mem[addr - 0xeb8000];
                     43:        }
                     44:        if (addr < 0xeb0400) {
                     45:                int n = (addr - 0xeb0000) / 8;
                     46:                switch (addr % 8) {
                     47:                 case 0:
                     48:                        return reg.sprite[n].xpos;
                     49:                 case 2:
                     50:                        return reg.sprite[n].ypos;
                     51:                 case 4:
                     52:                        return reg.sprite[n].col;
                     53:                 case 6:
                     54:                        return reg.sprite[n].prw;
                     55:                }
                     56:        }
                     57:        if (0xeb0800 <= addr && addr < 0xeb0812) {
                     58:                switch (addr) {
                     59:                 case 0xeb0800:
                     60:                        return reg.bg0x;
                     61:                 case 0xeb0802:
                     62:                        return reg.bg0y;
                     63:                 case 0xeb0804:
                     64:                        return reg.bg1x;
                     65:                 case 0xeb0806:
                     66:                        return reg.bg1y;
                     67:                 case 0xeb0808:
                     68:                        return reg.bgctrl;
                     69:                 case 0xeb080a:
                     70:                        return reg.htotal;
                     71:                 case 0xeb080c:
                     72:                        return reg.hdisp;
                     73:                 case 0xeb080e:
                     74:                        return reg.vdisp;
                     75:                 case 0xeb0810:
                     76:                        return reg.res;
                     77:                }
                     78:        }
                     79: 
                     80:        return (uint64)-1;
                     81: }
                     82: 
                     83: uint64
                     84: SpriteDevice::Write8(uint32 addr, uint32 data)
                     85: {
                     86:        if (addr >= 0xeb8000) {
1.1.1.4 ! root       87:                // スプライト VRAM への書き込み (InsideOut p.135)
        !            88:                gMPU->AddCycle(18);
1.1       root       89:                mem[HB(addr - 0xeb8000)] = data;
                     90:                return 0;
                     91:        }
1.1.1.4 ! root       92: 
        !            93:        // スプライトレジスタへの書き込み (InsideOut p.135)
        !            94:        gMPU->AddCycle(20);
        !            95: 
1.1       root       96:        PANIC("not impl");
                     97: }
                     98: 
                     99: uint64
                    100: SpriteDevice::Write16(uint32 addr, uint32 data)
                    101: {
                    102:        putlog(2, "Write16 $%06x <- $%04x", addr, data);
                    103:        if (addr >= 0xeb8000) {
                    104:                *(uint16 *)&mem[addr - 0xeb8000] = data;
                    105:                return 0;
                    106:        }
                    107:        if (addr < 0xeb0400) {
                    108:                int n = (addr - 0xeb0000) / 8;
                    109:                switch (addr % 8) {
                    110:                 case 0:
                    111:                        reg.sprite[n].xpos = data & 0x3ff;
                    112:                        break;
                    113:                 case 2:
                    114:                        reg.sprite[n].ypos = data & 0x3ff;
                    115:                        break;
                    116:                 case 4:
                    117:                        reg.sprite[n].col = data & 0xcfff;
                    118:                        break;
                    119:                 case 6:
                    120:                        reg.sprite[n].prw = data & 0x3;
                    121:                        break;
                    122:                }
                    123:                return 0;
                    124:        }
                    125:        if (0xeb0800 <= addr && addr < 0xeb0812) {
                    126:                switch (addr) {
                    127:                 case 0xeb0800:
                    128:                        reg.bg0x = data & 0x3ff;
                    129:                        break;
                    130:                 case 0xeb0802:
                    131:                        reg.bg0y = data & 0x3ff;
                    132:                        break;
                    133:                 case 0xeb0804:
                    134:                        reg.bg1x = data & 0x3ff;
                    135:                        break;
                    136:                 case 0xeb0806:
                    137:                        reg.bg1y = data & 0x3ff;
                    138:                        break;
                    139:                 case 0xeb0808:
                    140:                        reg.bgctrl = data & 0x23f;
                    141:                        break;
                    142:                 case 0xeb080a:
                    143:                        reg.htotal = data & 0xff;
                    144:                        break;
                    145:                 case 0xeb080c:
                    146:                        reg.hdisp = data & 0x3f;
                    147:                        break;
                    148:                 case 0xeb080e:
                    149:                        reg.vdisp = data & 0xff;
                    150:                        break;
                    151:                 case 0xeb0810:
                    152:                        reg.res = data & 0x1f;
                    153:                        break;
                    154:                }
                    155:                return 0;
                    156:        }
                    157: 
                    158:        return (uint64)-1;
                    159: }
                    160: 
                    161: uint64
                    162: SpriteDevice::Peek8(uint32 addr)
                    163: {
                    164:        if (addr >= 0xeb8000) {
                    165:                return mem[HB(addr - 0xeb8000)];
                    166:        }
                    167:        if (addr < 0xeb0400) {
                    168:                int n = (addr - 0xeb0000) / 8;
                    169:                switch (addr % 8) {
                    170:                 case 0:
                    171:                        return reg.sprite[n].xpos;
                    172:                 case 2:
                    173:                        return reg.sprite[n].ypos;
                    174:                 case 4:
                    175:                        return reg.sprite[n].col;
                    176:                 case 6:
                    177:                        return reg.sprite[n].prw;
                    178:                }
                    179:        }
                    180:        if (0xeb0800 <= addr && addr < 0xeb0812) {
                    181:                switch (addr) {
                    182:                 case 0xeb0800:
                    183:                        return reg.bg0x;
                    184:                 case 0xeb0802:
                    185:                        return reg.bg0y;
                    186:                 case 0xeb0804:
                    187:                        return reg.bg1x;
                    188:                 case 0xeb0806:
                    189:                        return reg.bg1y;
                    190:                 case 0xeb0808:
                    191:                        return reg.bgctrl;
                    192:                 case 0xeb080a:
                    193:                        return reg.htotal;
                    194:                 case 0xeb080c:
                    195:                        return reg.hdisp;
                    196:                 case 0xeb080e:
                    197:                        return reg.vdisp;
                    198:                 case 0xeb0810:
                    199:                        return reg.res;
                    200:                }
                    201:        }
                    202: 
                    203:        return (uint64)-1;
                    204: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.