39 of 318
ZBasic System Library 29 ZX Microcontroller Family BusWrite Type Subroutine Invocation BusWrite(addr, data, count) BusWrite(addr, data, count, delta) Parameter Method Type Description addr ByVal integral The bus address at which to begin writing. data ByRef anyType The data to be written. count ByVal integral The number of bytes to write. delta ByVal integral The amount by which the address should be changed after each byte is written. Discussion For ZX models that support external RAM (e.g. ZX-1281), if the external RAM interface is enabled and bus has not been defined using DefineBus(), then the external RAM interface is used for the write operation. In this case, the full 16 bits of the specified address are used and the delta parameter is interpreted as a signed 8-bit value that is sign-extended before adding it to the address with each iteration. For ZX models that do not support external RAM or if the external RAM interface is not enabled, this routine performs a series of write operations on the bus previously defined with the DefineBus() call. This is called the “bit bang” mode. For each write cycle, the low 8-bits of the address is output on the previously specified port and then the ALE pin is strobed (high, then back low). Then, the next data value to be written is output on the port and the WR pin is strobed (low then back high). Finally, the specified delta is added to the bus address and the cycle is repeated until the specified number of bytes has been written. It is important to remember that in the bit bang mode only 8 bits of the address are used. Depending on the values of the addr, count and delta parameters, the effective address may wrap around to zero. For example, with delta=1 specifying a count parameter larger than (256 – LoByte(addr)) will result in the effective address wrapping around to zero. In either mode, if the optional delta parameter is not specified, the value of 1 is assumed. Specifying the delta as zero will result in multiple writes to the same address. A delta of –¹ or &Hff will result in the address being decremented after each write. Example Dim data(1 to 20) as Byte Call DefineBus(Port.A, C.0, C.1, C.2) Call BusWrite(0, data, SizeOf(data)) Compatibility This subroutine is not available on ZX models that are based on the ATmega32 processor (e.g. the ZX- 24) nor is is available on ATxmega-based ZX devices. Moreover, it is not available in BasicX compatibility mode. See Also BusRead, DefineBus