Constructor
new Emulator()
Emulator is responsible for running the bytecode from the assembler.
Additional documentation can be found in the GitHub repository.
- Source:
Members
breakpointConditions :Array.<object>
conditions for breakpoints, null means no condition.
Additional documentation.
Type:
- Array.<object>
- Source:
- See:
breakpoints :Array.<boolean>
offsets in ROM which have a breakpoint set
Type:
- Array.<boolean>
- Source:
- See:
breakReason :String
reason for the current break, if any.
Type:
- String
- Default Value:
- null
- Source:
- See:
-
- yasp.Emulator#continue
- yasp.Emulator#break
changeBreakpointData :object
stores the changes to registers, flags, io and so on. Only written if a change-breakpoint for the specific value is set.
Type:
- object
- Source:
changeBreakpoints
Flags for 'change'-breakpoints. If one of these is true write-actions to the specific value will be recored.
- Source:
commandCache :Object
cache for already disassembled commands
Type:
- Object
- Source:
flags :Object
emulator flags set by arithmetic and PIN-Instructions
Type:
- Object
Properties:
| Name | Type | Description |
|---|---|---|
c |
boolean | carry flag |
z |
boolean | zero flag |
- Source:
forceStep :boolean
do not ever execute a tick unless yasp.Emulator#tick is called directly. This is used by the test-suite and should not be used by anything else.
Type:
- boolean
- Source:
- See:
-
- yasp.Emulator#setTickWrapperTimeout
globalBreakpoints :Array.<object>
all breakpoins which do not have a offset-value.
Additional documentation.
Type:
- Array.<object>
- Source:
- See:
initialSP :Number
initial value of the stackpointer
Type:
- Number
- Default Value:
- 80
- Source:
interruptMask :Array.<boolean>
bits of the interrupt-mask
Type:
- Array.<boolean>
- Source:
- See:
interruptToServe :Number
interrupt to execute on the next tick
Type:
- Number
- Source:
- See:
-
- yasp.Emulator#tick
- yasp.Emulator#setIO
- yasp.Emulator#scheduleInterrupt
pc :Number
offset of the last executed instruction in the ROM
Type:
- Number
- Source:
ram :Uint8Array
contains the registers (first 63 bytes), stack and RAM accessible via ReadRAM/WriteRAM
Type:
- Uint8Array
- Source:
rom :Uint8Array
the program code including strings, interrupt-table, etc
Type:
- Uint8Array
- Source:
running :Number|Boolean
indicator of the running-state
Number = execute a number of instructions
true = execute unlimited number of instructions
false = execution halted
Type:
- Number | Boolean
- Default Value:
- false
- Source:
- See:
-
- yasp.Emulator#continue
- yasp.Emulator#break
sp :Number
offset of the top, last pushed byte in the stack. Points to a byte in the ram.
Type:
- Number
- Source:
tickDelay :Number
number of milliseconds between two tickWrapper-calls
Type:
- Number
- Source:
ticks :Number
number of ticks executed in total, used by PWM for timing
Type:
- Number
- Source:
- See:
-
- yasp.Emulator#tick
ticksPerTick :Number
number of ticks inside one tickWrapper call
Type:
- Number
- Source:
tickTimeout :Number
timeout id of the last tickWrapper-setTimeout
Type:
- Number
- Source:
waitTime :Number
time in milliseconds to wait for the next tick
Type:
- Number
- Source:
- See:
-
- yasp.Emulator#wait
- yasp.Emulator#tickWrapper
Methods
break()
Stops the execution
- Source:
Fires:
clearCommandCache(pos, len)
clears the command cache for all bytes in ROM affected by the change of the len
bytes starting at pos. An affected byte is either within that range, or of any
command, which is partly within that range.
Parameters:
| Name | Type | Description |
|---|---|---|
pos |
Number | starting position to clear |
len |
Number | number of types to clear |
- Source:
debugRegister(type, addr)
sends a register to the debugger
Parameters:
| Name | Type | Description |
|---|---|---|
type |
String | the register-type (w or b) |
addr |
Number | the register-number |
- Source:
Fires:
debugString(addr)
sends a string to the debugger
Parameters:
| Name | Type | Description |
|---|---|---|
addr |
Number | ROM-address to read a null-terminated string from |
- Source:
Fires:
getIO() → (nullable) {number}
gets the state of a pin
- Source:
Returns:
the pins state, or null if the pin does not exist
- Type
- number
getTicks() → {Number}
- Source:
Returns:
number of ticks executed, since the emulator has been created. This also takes sleeps into account.
- Type
- Number
isCacheCommand(pos) → {Boolean}
checks if the given byte is the start of a command in ROM
Parameters:
| Name | Type | Description |
|---|---|---|
pos |
Number | the position in ROM to check |
- Source:
Returns:
true, if pos is the start of a command, otherwise false
- Type
- Boolean
isCarryFlagSet() → {boolean}
Reads the carry flag
- Source:
Returns:
true if the carry flag is set, otherwise false
- Type
- boolean
isZeroFlagSet() → {boolean}
Reads the zero flag
- Source:
Returns:
true if the zero flag is set, otherwise false
- Type
- boolean
popByte() → {Number}
gets one byte from the stack and removes it
- Source:
- See:
Returns:
a byte from the top of stack or 0 if the stack is empty
- Type
- Number
popWord() → {Number}
gets two bytes from the stack, combines and removes them
- Source:
- See:
Returns:
a word from the top of stack
- Type
- Number
pushByte(v)
pushes one byte onto the stack
Parameters:
| Name | Type | Description |
|---|---|---|
v |
Number | the byte to push onto the stack |
- Source:
- See:
pushWord(v)
splits the given word into two bytes and pushes them onto the stack. The most significant byte will be pushed last.
Parameters:
| Name | Type | Description |
|---|---|---|
v |
Number | word to push onto the stack |
- Source:
- See:
readByteRegister(r) → {Number}
Reads the value of the given byte-register
Parameters:
| Name | Type | Description |
|---|---|---|
r |
Number | the byte-register to read (must be between 0 and 31) |
- Source:
Returns:
the registers value
- Type
- Number
readFlags() → {object}
Reads the flags
- Deprecated:
- for speed reasons. Use yasp.Emulator#isCarryFlagSet and yasp.Emulator#isZeroFlagSet.
- Source:
Returns:
values of both flags
- Type
- object
readPC() → {Number}
gets the program counter
- Source:
Returns:
the current value of the program counter
- Type
- Number
readRAM(o) → {Number}
reads one byte from the ram
Parameters:
| Name | Type | Description |
|---|---|---|
o |
Number | the offset to read from |
- Source:
Returns:
the bytes value, or 0 if o was out of bounds
- Type
- Number
readROM(o) → {Number}
reads one byte from the rom
Parameters:
| Name | Type | Description |
|---|---|---|
o |
Number | the offset to read from |
- Source:
Returns:
the bytes value, or 0 if o was out of bounds
- Type
- Number
readWordRegister(r) → {Number}
Reads the value of the given word-register
Parameters:
| Name | Type | Description |
|---|---|---|
r |
Number | the word-register to read (must be between 0 and 31) |
- Source:
Returns:
the registers value
- Type
- Number
scheduleInterrupt(i) → {boolean}
schedules an interrupt for the next tick
Parameters:
| Name | Type | Description |
|---|---|---|
i |
Number | the interrupt to schedule |
- Source:
Returns:
true if the interrupt is going to served, false otherwise (depends on the active interrupt-mask)
- Type
- boolean
setBreakpoints(breakpoints) → {Number|Boolean}
updates the internal list of breakpoints
Parameters:
| Name | Type | Description |
|---|---|---|
breakpoints |
Array.<Breakpoint> | the breakpoints to save. Additional documentation. |
- Source:
Returns:
- Type
- Number | Boolean
setInterruptMask(mask)
sets the interrupt-mask
Parameters:
| Name | Type | Description |
|---|---|---|
mask |
Number | mask to set (one byte) |
- Source:
- See:
setIO(p, s, outsideopt) → {Number}
sets the state of a pin
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
p |
Number | pin-number | ||
s |
Number | new state to set | ||
outside |
boolean |
<optional> |
false | true if the pin was set by external hardware |
- Source:
Fires:
Returns:
0 if success, 1 if the pin does not exist, 2 if the pin is an input pin, 3 if s is invalid
- Type
- Number
wait(ticks)
halts the execution for a given time.
Parameters:
| Name | Type | Description |
|---|---|---|
ticks |
Number | number of ticks to wait (1 tick ~= 0.015ms; 60000 ~= 900ms) |
- Source:
writeByteRegister(r, v) → {Number|Boolean}
Writes the given value into the given byte register
Parameters:
| Name | Type | Description |
|---|---|---|
r |
Number | the byte-register to write to (must be between 0 and 31) |
v |
Number | the value to write (must be one byte) |
- Source:
Returns:
- Type
- Number | Boolean
writeFlags(cnullable, znullable)
Write the carry and zero flag
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
c |
boolean |
<nullable> |
the carry flag to be set (or null to not change it) |
z |
boolean |
<nullable> |
the zero flag to be set (or null to not change it) |
- Source:
- See:
writePC(pc)
sets the program counter
Parameters:
| Name | Type | Description |
|---|---|---|
pc |
Number | the new value to set |
- Source:
writeRAM(o, v) → {Number}
writes one byte to the ram
Parameters:
| Name | Type | Description |
|---|---|---|
o |
Number | the position to write the byte to |
v |
Number | the byte to write |
- Source:
Returns:
0 = success, 1 = o was out of bounds
- Type
- Number
writeROM(o, v) → {Number}
writes one byte to the rom. This also clears the yasp.Emulator#commandCache for the affected bytes.
Parameters:
| Name | Type | Description |
|---|---|---|
o |
Number | the position to write the byte to |
v |
Number | the byte to write |
- Source:
- See:
Returns:
0 = success, 1 = o was out of bounds
- Type
- Number
writeWordRegister(r, v) → {Number|Boolean}
Writes the given value into the given word register
Parameters:
| Name | Type | Description |
|---|---|---|
r |
Number | the word-register to write to (must be between 0 and 31) |
v |
Number | the value to write (must be one word) |
- Source:
Returns:
- Type
- Number | Boolean
Events
BREAK
fired when the execution is halted.
- Source:
- See:
CONTINUE
fired when the execution is started or resumed.
Parameters:
| Name | Type | Description |
|---|---|---|
running |
Number |
- Source:
- See:
DEBUG
fired when a DEBUG or ECHO instruction was executed.
Parameters:
| Name | Type | Description |
|---|---|---|
type |
String | |
subtype |
String | |
addr |
Number | |
val |
Number |
- Source:
- See:
IO_CHANGED
fired when the state of an output-pin changed.
Parameters:
| Name | Type | Description |
|---|---|---|
pin |
Number | |
state |
Number | |
mode |
String | |
type |
String |
- Source:
- See:
LOADED
fired when code has been loaded into the rom for execution.
Parameters:
| Name | Type | Description |
|---|---|---|
start |
Number | |
length |
Number |
- Source:
- See: