-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbios.c
185 lines (157 loc) · 4.34 KB
/
bios.c
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
* TOSEMU - an emulated environment for TOS applications
* Copyright (C) 2014 Johan Thelin <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "bios.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "tossystem.h"
#include "cpu.h"
#include "m68k.h"
#include "utils.h"
#define BIOS_TRACE_CONTEXT
#include "config.h"
uint32_t BIOS_Setexc()
{
uint16_t nm = peek_u16(2);
uint32_t vec = peek_u32(4);
uint32_t old;
FUNC_TRACE_ENTER_ARGS {
printf(" nm: 0x%x, vec: 0x%x\n", nm, vec);
}
old = m68k_read_memory_32(4*nm);
m68k_write_memory_32(4*nm, vec);
return old;
}
uint32_t BIOS_Bconin()
{
uint16_t dev = peek_u16(2);
FUNC_TRACE_ENTER_ARGS {
printf(" 0x%x\n", dev);
}
switch(dev)
{
case 2: /* console */
if (console_input_available())
return getchar() & 0xff;
else
return 0;
default:
return 0; /* TODO support reading from additional devices */
}
}
uint32_t BIOS_Bconout()
{
uint16_t dev = peek_u16(2);
uint16_t c = peek_u16(4);
FUNC_TRACE_ENTER_ARGS {
printf(" dev: 0x%x, c: 0x%x '%c'\n", dev, c, c);
}
switch(dev)
{
case 2: /* console */
putchar(c);
default:
return 0; /* TODO support writing to additional devices */
}
}
uint32_t BIOS_Bconstat()
{
uint16_t dev = peek_u16(2);
FUNC_TRACE_ENTER_ARGS {
printf(" 0x%x\n", dev);
}
switch(dev)
{
case 2: /* console */
if (console_input_available())
return -1;
else
return 0;
default:
return 0; /* TODO support additional devices */
}
}
uint32_t BIOS_Bcostat()
{
uint16_t dev = peek_u16(2);
FUNC_TRACE_ENTER_ARGS {
printf(" 0x%x\n", dev);
}
switch(dev)
{
case 2: /* console */
return -1; /* Always ready */
default:
return 0; /* TODO support additional devices */
}
}
/* Table of non-implemented BIOS functions */
#define BIOS_Drvmap NULL
#define BIOS_Getbpb NULL
#define BIOS_Getmpb NULL
#define BIOS_Kbshift NULL
#define BIOS_Mediach NULL
#define BIOS_Rwabs NULL
#define BIOS_Tickcal NULL
/* BIOS function table according to
* http://www.yardley.cc/atari/compendium/atari-compendium-BIOS-Function-Reference.htm
*/
struct BIOS_function {
char *name;
uint32_t (*fnct)();
uint16_t id;
};
struct BIOS_function BIOS_functions[] = {
{"Bconin", BIOS_Bconin, 0x02},
{"Bconout", BIOS_Bconout, 0x03},
{"Bconstat", BIOS_Bconstat, 0x01},
{"Bcostat", BIOS_Bcostat, 0x08},
{"Drvmap", BIOS_Drvmap, 0x0A},
{"Getbpb", BIOS_Getbpb, 0x07},
{"Getmpb", BIOS_Getmpb, 0x00},
{"Kbshift", BIOS_Kbshift, 0x0B},
{"Mediach", BIOS_Mediach, 0x09},
{"Rwabs", BIOS_Rwabs, 0x04},
{"Setexc", BIOS_Setexc, 0x05},
{"Tickcal", BIOS_Tickcal, 0x06}
};
void bios_trap()
{
uint16_t fnct = peek_u16(0);
int i;
for(i=0; i<=sizeof(BIOS_functions)/sizeof(struct BIOS_function); ++i) {
if (BIOS_functions[i].id == fnct) {
if (BIOS_functions[i].fnct) {
uint32_t r = BIOS_functions[i].fnct();
#ifdef ENABLE_BIOS_TRACE
printf("Return from %s: %d = 0x%x\n",
BIOS_functions[i].name, r, r);
#endif
m68k_set_reg(M68K_REG_D0, r);
} else {
halt_execution();
printf("BIOS %s (0x%x) not implemented\n", BIOS_functions[i].name, fnct);
}
return;
}
}
halt_execution();
printf("BIOS Unknown function called 0x%x\n", fnct);
}