-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjump.c
More file actions
140 lines (113 loc) · 2.42 KB
/
jump.c
File metadata and controls
140 lines (113 loc) · 2.42 KB
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
/* File: jump.c */
/* (C)opyright 1987 InfoTaskforce. */
#include "infocom.h"
gosub ( address,var1,var2,var3,num_params )
word address,var1,var2,var3,num_params ;
{
extern word pc_offset ;
extern word pc_page ;
extern word *stack_base ;
extern word *stack_var_ptr ;
extern word *stack ;
byte vars ;
word parameter ;
if ( address == 0 )
store ( address ) ;
else
{
*(--stack) = pc_page ;
*(--stack) = pc_offset ;
/* Push offset of old stack_var_ptr from stack_base onto stack */
*(--stack) = stack_base - stack_var_ptr ;
pc_page = address >> 8 ;
pc_offset = ( address & 0xFF ) << 1 ;
fix_pc () ;
/*
The value of the current stack pointer is the
new value of stack_var_ptr.
*/
stack_var_ptr = stack ;
--stack_var_ptr ;
/*
Global variables 1 to 15 are Local variables, which
reside on the stack (and so are local to each procedure).
Get number of local variables to push onto the stack.
var1, var2 and var3, if defined, are the first 3 local
variables. There are also bytes reserved after the
gosub opcode in the calling procedure to initialise
all local variables - including the first 3 local
variables ( and so are ignored ).
The use of parameters also allows procedures to be
passed variables by value.
*/
vars = next_byte () ;
if ( vars == 0 )
return ;
parameter = next_word () ;
if ( (--num_params) != 0 )
{
*(--stack) = var1 ;
if ( (--vars) == 0 )
return ;
parameter = next_word () ;
if ( (--num_params) != 0 )
{
*(--stack) = var2 ;
if ( (--vars) == 0 )
return ;
parameter = next_word () ;
if ( (--num_params) != 0 )
{
*(--stack) = var3 ;
if ( (--vars) == 0 )
return ;
parameter = next_word () ;
}
}
}
*(--stack) = parameter ;
while ( (--vars) != 0 )
*(--stack) = next_word () ;
}
}
rtn ( value )
word value ;
{
extern word pc_offset ;
extern word pc_page ;
extern word *stack_base ;
extern word *stack_var_ptr ;
extern word *stack ;
stack = stack_var_ptr ;
++stack ;
stack_var_ptr = stack_base - *stack++ ;
pc_offset = *stack++ ;
pc_page = *stack++ ;
fix_pc () ;
store ( value ) ;
}
ret_true ()
{
rtn ( true ) ;
}
ret_false ()
{
rtn ( false ) ;
}
jump ( offset )
word offset ;
{
extern word pc_offset ;
pc_offset += offset - 2 ;
fix_pc () ;
}
rts ()
{
extern word *stack ;
rtn ( *stack++ ) ;
}
pop_stack ()
{
extern word *stack ;
++stack ;
}