Your Spectrum
YS MegaBasic manual - Machine Code & YS MegaBasic
Home YS MegaBasic Contents

MACHINE CODE AND YS MegaBasic

DOKE AND CALL

It's still possible to run Z80 machine code programs alongside YS MegaBasic, but there are one or two points worth noting as you make the transition to the MegaSpectrum.
  The top section of memory above address 45000 is used by YS MegaBasic; thus, any machine code routines of your own that use this area will have to be moved down.
  YS MegaBasic uses interrupt mode 2, so any routines that mess about with the interrupts will probably need some attention before they'll work properly.
  When you're dealing with the Z80 processor it's often necessary to POKE two-byte values into memory. YS MegaBasic provides the 'DOKE_' command to perform this task. This is followed by two numeric expressions (separated by commas); the first is the address to be POKEd and the second, the data that's actually going to be placed into memory. The data is stored using the standard Z80 convention - that is, LSB first, MSB second.
  The 'CALL_' command is used to call machine code routines in memory and it too is followed by a numeric expression - the address of the routine to be called. This address can then, if required, be followed by any number of numeric expressions. These expressions are evaluated and the result pushed on to the machine stack. This feature allows parameters to be passed to machine code routines.
19.b

THE FRONT-PANEL

The 'front-panel' is provided to allow users the opportunity to alter memory and registers when using hexadecimal. The front-panel is activated either by executing the 'MON' command, or typing 'Control F' while a program is running. The front-panel uses window three and this should always be at least 40 columns by 20 lines or the display won't function correctly.
  Once the front-panel is activated, you'll be greeted by columns of hexadecimal numbers. On the left (in cyan) is the list of registers with the accumulator at the top; the flags register is shown in binary. The asterisk indicates the current register. On the right is the current piece of memory with the current location shown on the inverse strip; at the bottom is the input line (shown in green).
  The front-panel is controlled by a number of single-letter commands; these may be followed by up to three Hex numbers. All Hex numbers must be typed out in full; if a 16-bit Hex number is required then a four digit number must be typed. Note that 'n' represents an eight-bit Hex number and 'nn' represents a 16-bit Hex number.
Space Returns to Basic.
R nn Loads the current register with a 16-bit Hex number.
P Advances the current register pointer by one byte.
L nn nn nn Moves a block of memory. The first number is the start of the block, the second is the address where the block is to be moved to, and the third is the length of the block.
M nn Sets the address of the current memory location.
S Sets a break-point.
K Continues program execution past a break-point.
U Restores a break-point.
I nn nn n Fills a block of memory. The first number is the start of the block, the second is the length of the block, and the third is the number with which the block is to be filled.
J nn Calls the machine code routine at a given address (nn).
Enter Advances the current memory location by one byte.
'-' Steps the current memory location back by one byte.
If a two-digit Hex number is typed at the beginning of the input line, then it's entered into memory at the current location and the current location is advanced by one byte.
20