-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmachine.h
128 lines (98 loc) · 3.36 KB
/
machine.h
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
#ifndef clox_machine_h
#define clox_machine_h
#include <stddef.h>
#ifdef KIT68K
/////////////////////////////////////////////////////////////////
// Wichichote 68008 KIT / IDE68K C compiler specific definitions
/////////////////////////////////////////////////////////////////
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef short int16_t;
typedef int int32_t;
typedef short bool;
typedef int clock_t;
typedef unsigned int steps_t;
#define true 1
#define false 0
#define UINT8_MAX 0xff
#define UINT16_MAX 0xffff
#define INT32_MAX 0x7fffffff
#define WRAP_BIG_ENDIAN
#include "monitor4x.h"
// Real number implementation
typedef int32_t Real; // sic!
#include "ffp_glue.h"
extern Real mod(Real a, Real b); // in native.c
// Replace broken string routines from stdlib
#include "kit_util.h"
// Code at the very beginning of a function to check for stack overflow:
//
// cmp.l STACKLIMIT_ADDR.W,A7
// bge *+6
// jsr __stackoverflow
//
// please adapt the definition of STACKLIMIT_ADDR here when the address
// of variable __stack in the assembler startup file changes, _word only works with constants.
#define STACKLIMIT_ADDR 0x2004
extern void _stackoverflow(void);
#define CHECK_STACKOVERFLOW \
_word(0xbff8); _word(STACKLIMIT_ADDR); \
_word(0x6c06); \
_stackoverflow();
#define STATIC_BREAKPOINT() _trap(1)
// Using the 100 Hz IRQ as a timer and checking for interrupt button
#define clock() (*((int32_t*)tick_100hz))
#define IRQ2_VECTOR (*((int32_t*)0x0068))
#define TRAP1_VECTOR (*((int32_t*)0x0084))
#define ON_KIT() (*((short*)0x0200) == 0x1138)
#define INTERRUPTED() ((*port0 & 0x40) == 0)
#define RESET_INTERRUPTED() // nothing to do
#define handleInterrupts(flag) // nothing to do
extern void ticker(void); // in cstart_lox_rom.asm
extern void rte(void); // in cstart_lox_rom.asm
#else
/////////////////////////////////////////////////////////////////
// Now for the more modern compilers Tiny C and GNU C
/////////////////////////////////////////////////////////////////
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <time.h>
typedef uint64_t steps_t;
// Real number implementation
#include <math.h>
typedef double Real;
#define intToReal(x) ((Real)(x))
#define realToInt(x) ((Int)(x))
#define strToReal(s,e) strtod(s,e)
#define add(x,y) ((x)+(y))
#define sub(x,y) ((x)-(y))
#define mul(x,y) ((x)*(y))
#define div(x,y) ((x)/(y))
#define mod(x,y) (fmod((x),(y)))
#define less(x,y) ((x)<(y))
// use standard routines here
#define fix_memcpy memcpy
#define fix_memcmp memcmp
#define putstr(str) fputs((str),stdout)
// hide Kit's assembly helpers
#define CHECK_STACKOVERFLOW
#define STATIC_BREAKPOINT()
// Set by SIGINT handler
#define INTERRUPTED() (vm.interrupted)
#define RESET_INTERRUPTED() vm.interrupted = false;
#endif
/////////////////////////////////////////////////////////////////
// Common definitions
/////////////////////////////////////////////////////////////////
#define HEAP_SIZE 65536
#define STACK_MAX 4096
#define INPUT_SIZE 16384
#define FRAMES_MAX 224 // Maxed, but keep C heap start below C stack limit
#define GRAY_MAX 1024
#define PRINT_SEPARATOR " "
#define LOWER_CASE_MASK 0x20
#endif