Intro
There are two types of SHP files. One is just a plain
text file with Sheep script, and the other is a binary
file containing, among other things, bytecode. This document
describes the format of the latter.
Format
Header
| Offset | Length | Description |
| 0 |
8 |
Magic (should be "GK3Sheep") |
| 8 |
4 |
?? |
| 12 |
4 |
Extra offset? |
| 16 |
4 |
Data offset |
| 20 |
4 |
Data size |
| 24 |
4 |
Data Count |
Data array
| Offset |
Length |
Description |
| ? |
4 |
?? |
SysImports
| Offset | Length | Description |
| ? + 0 |
12 |
"SysImports\0\0" |
| ? + 12 |
4 |
Extra offset |
| ? + 16 |
4 |
Data offset |
| ? + 22 |
4 |
Data size |
| ? + 26 |
4 |
# of imports |
Array Of Offsets
| Offset | Length | Description |
| ? + 0 |
4 |
Offset (relative to end of this array) to import |
After this array is the array of imports:
Array Of Imports
| Offset | Length | Description |
| ? + 0 |
2 |
Length of import string (n) |
| ? + 2 |
n + 1 |
Import string (name of import?)
|
| ? + n+3 |
1 |
# of returns? |
| ? + n+4 |
1 |
# of parameters? |
Following each entry in this array is another array:
Array of Parameters
| Offset | Length | Description |
| ? + 0 |
1 |
Parameter type |
After all this stuff is the StringConsts section:
StringConsts
| Offset | Length | Description |
| ? + 0 |
12 |
"StringConsts" |
| ? + 12 |
4 |
Extra offset |
| ? + 16 |
4 |
Data offset |
| ? + 20 |
4 |
Data size |
| ? + 24 |
4 |
# of constants |
Array of Constants
| Offset | Length | Description |
| ? |
4 |
Offset to constant (relative to end of this array) |
Functions
| Offset | Length | Description |
| ? + 0 |
12 |
"Functions\0\0\0" |
| ? + 12 |
4 |
Extra offset |
| ? + 16 |
4 |
Data offset |
| ? + 20 |
4 |
Data size |
| ? + 24 |
4 |
# of functions |
Array of Offsets
| Offset | Length | Description |
| ? + 0 |
4 |
Offset to function (relative to end of this array |
Array of Functions
| Offset | Length | Description |
| ? + 0 |
2 |
Size of function name (n) |
| ? + 2 |
n+1 |
Function name |
| ? + 3+n |
1 |
# of returns? |
| ? + 4+n |
1 |
# of parameters? |
| ? + 5+n |
4 |
Offset to code (relative from end of this array) |
Code
| ? |
4 |
Extra offset |
| ? + 4 |
4 |
Data offset |
| ? + 8 |
4 |
Data size |
| ? + 12 |
4 |
Data count |
Opcodes
| Opcode |
Name |
Parameters |
Description |
| 00 |
SitnSpin |
|
Does nothing (no-op) |
| 01 |
Yield |
|
?? |
| 02 |
CallSysFunctionV |
uint32 |
Calls a function? |
| 03 |
CallSysFunctionI |
uint32 |
Calls a function? |
| 04 |
CallSysFunctionF |
uint32 |
|
| 05 |
CallSysFunctionS |
uint32 |
|
| 06 |
Branch |
uint32 |
Jumps to another point in the code |
| 07 |
BranchGoto |
uint32 |
Jumps to another point in the code |
| 08 |
BranchIfZero |
uint32 |
Conditional branch? |
| 09 |
BeginWait |
|
Begins a wait? |
| 0A |
EndWait |
|
Ends wait? |
| 0B |
ReturnV |
|
Returns? |
| 0D |
StoreI |
uint32 |
Pops an integer off the stack and puts it into the specified variable? |
| 0E |
StoreF |
uint32 |
Pops a float off the stack and puts it into the specified variable? |
| 0F |
StoreS |
uint32 |
Stores the string at the top of the stack into a variable |
| 10 |
LoadI |
uint32 |
Loads the value of a variable onto the stack |
| 11 |
LoadF |
float |
Loads the value of a variable onto the stack |
| 12 |
LoadS |
uint32 |
Loads the value of a variable onto the stack |
| 13 |
PushI |
uint32 |
Pushes an integer onto the stack? |
| 14 |
PushF |
float |
Pushes a float onto the stack |
| 15 |
PushS |
uint32 |
Pushes the offset of a string onto the stack |
| 16 |
Pop |
|
Pops the stack |
| 17 |
AddI |
|
Pops two integers off the stack, adds them, and puts the result back onto the stack |
| 18 |
AddF |
|
Pops two floats off the stack, adds them, and puts the result back onto the stack |
| 19 |
SubtractI |
|
Pops two integers off the stack, subtracts them, and puts the result back onto the stack |
| 1A |
SubtractF |
|
Pops two floats off the stack, subtracts them, and puts the result back onto the stack |
| 1B |
MultiplyI |
|
Pops two integers off the stack, subtracts them, and puts the result back onto the stack |
| 1C |
MultiplyF |
|
Pops two floats off the stack, multiplies them, and puts the result back onto the stack |
| 1D |
DivideI |
|
Pops two integers off the stack, divides them, and puts the result back onto the stack |
| 1E |
DivideF |
|
Pops two floats off the stack, divides them, and puts the result back onto the stack |
| 1F |
NegateI |
|
Negates the integer on the top of the stack |
| 20 |
NegateF |
|
Negates the float on the top of the stack |
| 21 |
IsEqualI |
|
?? |
| 22 |
IsEqualF |
|
Pops floats off the stack, compares them, and puts 1 if they're equal, 0 otherwise |
| 23 |
NotEqualI |
|
|
| 24 |
NotEqualF |
|
|
| 25 |
IsGreaterI |
|
Pops the two values on the stack and puts 0 or 1 depending on whether one is greater than the other |
| 26 |
IsGreaterF |
|
?? |
| 27 |
IsLessI |
|
Pops the stack twice and compares the values |
| 28 |
IsLessF |
|
|
| 29 |
IsGreaterEqualI |
|
?? |
| 2A |
IsGreaterEqualF |
|
?? |
| 2B |
IsLessEqualI |
|
|
| 2C |
IsLessEqualF |
|
|
| 2D |
IToF |
uint32 |
?? |
| 2E |
FToI |
uint32 |
?? |
| 30 |
And |
|
?? |
| 31 |
Or |
|
?? |
| 32 |
Not |
|
If value on stack is 0, make it nonzero; if it's nonzero, make it zero? |
| 33 |
GetString |
|
?? |
| 34 |
DebugBreakpoint |
|
|