forked from uli/cascade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hsio.cpp
119 lines (109 loc) · 2.63 KB
/
hsio.cpp
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
117
118
119
/*
* hsio.cpp
*
* (C) Copyright 2014 Ulrich Hecht
*
* This file is part of CASCADE. CASCADE is almost free software; you can
* redistribute it and/or modify it under the terms of the Cascade Public
* License 1.0. Read the file "LICENSE" for details.
*/
#include "hsio.h"
#include <stdlib.h>
#include "debug.h"
Hsio::Hsio()
{
hsi_mode = 0xff;
hso_swt_time[0] = hso_swt_time[1] = hso_swt_time[2] = hso_swt_time[3] = 0;
hso_command = 0;
hso_swt_command[0] = hso_swt_command[1] = hso_swt_command[2] = hso_swt_command[3] = 0;
}
uint8_t Hsio::getMode()
{
DEBUG(HSIO, "HSIO get mode (%02X)\n", hsi_mode);
return hsi_mode;
}
uint8_t Hsio::getTime(int which)
{
switch (which) {
case HSI_TIME_LO:
case HSI_TIME_HI:
case HSO_TIME_LO:
case HSO_TIME_HI:
DEBUG(WARN, "HSIO fake HSI time %d\n", which);
return 0xff;
default:
ERROR("unknown HSIO time %d\n", which);
exit(1);
}
}
void Hsio::setMode(uint8_t mode)
{
DEBUG(HSIO, "HSIO set mode %02X\n", mode);
hsi_mode = mode;
}
void Hsio::setTime(int which, uint8_t value)
{
int swt;
switch (which) {
case HSO_TIME_LO:
case HSO_TIME_HI:
if ((hso_command & 0xf0) != 0x30) {
ERROR("HSO unimp1\n");
//exit(1);
return;
}
swt = (hso_command & 0xf) - 8;
DEBUG(TRACE, "HSIO setting SWT%d time %d to %02X\n", swt, which, value);
if (which == HSO_TIME_LO)
hso_swt_time[swt] = (hso_swt_time[swt] & 0xff00) | value;
else
hso_swt_time[swt] = (hso_swt_time[swt] & 0xff) | (value << 8);
break;
case HSI_TIME_LO:
case HSI_TIME_HI:
ERROR("HSI time write unimplemented\n");
exit(1);
default:
ERROR("HSO unimp2\n");
exit(1);
}
}
void Hsio::setCommand(int which, uint8_t cmd)
{
switch (which) {
case HSO_CMD:
hso_command = cmd;
if ((cmd & 0xf0) != 0x30) {
ERROR("HSO unimp5\n");
//exit(1);
return;
}
switch (cmd & 0xf) {
case 0x8:
case 0x9:
case 0xa:
case 0xb:
hso_swt_command[(cmd & 0xf) - 8] = cmd;
break;
default:
ERROR("HSIO internal error (cmd %02X)\n", cmd);
exit(1);
}
break;
default:
ERROR("unimplemented HSIO cmd for %d\n", which);
exit(1);
}
}
void Hsio::setStatus(int which, uint8_t value)
{
DEBUG(HSIO, "HSIO setStatus(%d, %d) unimplemented\n", which, value);
}
#include "state.h"
void Hsio::loadSaveState(statefile_t fp, bool write)
{
STATE_RW(hsi_mode);
STATE_RWBUF(hso_swt_time, 4 * sizeof(uint16_t));
STATE_RW(hso_command);
STATE_RWBUF(hso_swt_command, 4 * sizeof(uint8_t));
}