aboutsummaryrefslogtreecommitdiff
path: root/source/obc1.c
blob: 0013e3352d70760865e54344a3c0c6679213253f (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "../copyright"

#include <string.h>
#include "memmap.h"
#include "obc1.h"

static uint8_t* OBC1_RAM = NULL;

int OBC1_Address;
int OBC1_BasePtr;
int OBC1_Shift;

uint8_t GetOBC1(uint16_t Address)
{
   switch (Address)
   {
   case 0x7ff0:
      return OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2)];

   case 0x7ff1:
      return OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2) + 1];

   case 0x7ff2:
      return OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2) + 2];

   case 0x7ff3:
      return OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2) + 3];

   case 0x7ff4:
      return OBC1_RAM[OBC1_BasePtr + (OBC1_Address >> 2) + 0x200];
   }

   return OBC1_RAM[Address & 0x1fff];
}

void SetOBC1(uint8_t Byte, uint16_t Address)
{
   switch (Address)
   {
   case 0x7ff0:
   {
      OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2)] = Byte;
      break;
   }

   case 0x7ff1:
   {
      OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2) + 1] = Byte;
      break;
   }

   case 0x7ff2:
   {
      OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2) + 2] = Byte;
      break;
   }

   case 0x7ff3:
   {
      OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2) + 3] = Byte;
      break;
   }

   case 0x7ff4:
   {
      unsigned char Temp;

      Temp = OBC1_RAM[OBC1_BasePtr + (OBC1_Address >> 2) + 0x200];
      Temp = (Temp & ~(3 << OBC1_Shift)) | ((Byte & 3) << OBC1_Shift);
      OBC1_RAM[OBC1_BasePtr + (OBC1_Address >> 2) + 0x200] = Temp;
      break;
   }

   case 0x7ff5:
   {
      if (Byte & 1)
         OBC1_BasePtr = 0x1800;
      else
         OBC1_BasePtr = 0x1c00;

      OBC1_RAM[0x1ff5] = Byte;
      break;
   }

   case 0x7ff6:
   {
      OBC1_Address = Byte & 0x7f;
      OBC1_Shift = (Byte & 3) << 1;
      break;
   }

   default:
      OBC1_RAM[Address & 0x1fff] = Byte;
      break;
   }
}

uint8_t* GetBasePointerOBC1(uint32_t Address)
{
   return Memory.FillRAM;
}

uint8_t* GetMemPointerOBC1(uint32_t Address)
{
   return (Memory.FillRAM + (Address & 0xffff));
}

void ResetOBC1()
{
   OBC1_Address = 0;
   OBC1_BasePtr = 0x1c00;
   OBC1_Shift = 0;
   OBC1_RAM = &Memory.FillRAM[0x6000];

   memset(OBC1_RAM, 0x00, 0x2000);
}