-
Notifications
You must be signed in to change notification settings - Fork 6
/
cpu.c
110 lines (95 loc) · 2.6 KB
/
cpu.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
/*
* 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 "cpu.h"
#include "utils.h"
#include "m68k.h"
void enable_supervisor_mode()
{
m68k_set_reg(M68K_REG_SR, m68k_get_reg(0, M68K_REG_SR) | 0x2000); /* set the CPU in supervisor mode */
}
void disable_supervisor_mode()
{
m68k_set_reg(M68K_REG_SR, m68k_get_reg(0, M68K_REG_SR) & (~0x2000)); /* set the CPU in supervisor mode */
}
int is_supervisor_mode_enabled()
{
if ((m68k_get_reg(0, M68K_REG_SR) & 0x2000) == 0x2000) {
return 1;
} else {
return 0;
}
}
void push_u16(uint16_t value)
{
uint32_t sp = m68k_get_reg(0, M68K_REG_A7);
sp -= 2;
m68k_write_memory_16(sp, value);
m68k_set_reg(M68K_REG_A7, sp);
}
void push_u32(uint32_t value)
{
uint32_t sp = m68k_get_reg(0, M68K_REG_A7);
sp -= 4;
m68k_write_memory_32(sp, value);
m68k_set_reg(M68K_REG_A7, sp);
}
uint16_t pop_u16()
{
uint32_t sp = m68k_get_reg(0, M68K_REG_A7);
uint16_t value = m68k_read_disassembler_16(sp);
sp += 2;
m68k_set_reg(M68K_REG_A7, sp);
return value;
}
uint32_t pop_u32()
{
uint32_t sp = m68k_get_reg(0, M68K_REG_A7);
uint16_t value = m68k_read_disassembler_32(sp);
sp += 4;
m68k_set_reg(M68K_REG_A7, sp);
return value;
}
uint8_t peek_u8(int offset)
{
uint32_t sp = m68k_get_reg(0, M68K_REG_A7);
return m68k_read_disassembler_8(sp+offset);
}
uint16_t peek_u16(int offset)
{
uint32_t sp = m68k_get_reg(0, M68K_REG_A7);
return m68k_read_disassembler_16(sp+offset);
}
uint32_t peek_u32(int offset)
{
uint32_t sp = m68k_get_reg(0, M68K_REG_A7);
return m68k_read_disassembler_32(sp+offset);
}
int8_t peek_s8(int offset)
{
return (int8_t)peek_u8(offset);
}
int16_t peek_s16(int offset)
{
return (int16_t)peek_u16(offset);
}
int32_t peek_s32(int offset)
{
return (int32_t)peek_u32(offset);
}