CPCWiki forum

General Category => Programming => Topic started by: AMSDOS on 10:31, 28 July 10

Title: 16bit Poke in [whatever Language you prefer]! :)
Post by: AMSDOS on 10:31, 28 July 10
Probably the only one here who found this useful:


Procedure memw(address, data : integer);
begin
Inline($ED/$5B/data/
         $2A/address/
         $73/
         $23/
         $72);
end;


The assembly looks like this:


poke16: LD DE,(data)
LD HL,(addr)
LD (HL),E
INC HL
LD (HL),D
RET


The BASIC interactive version could look like this (use a Memory Editor to Poke the bytes in):


LD E,(IX+00) --> DD,5E,00
LD D,(IX+01) --> DD,56,01
LD L,(IX+02) --> DD,6E,02
LD H,(IX+03) --> DD,66,03
LD (HL),E --> 73
INC HL --> 23
LD (HL),D --> 72
RET --> C9
 

I was using this a few years ago in Turbo Pascal & BASIC to poke 16bit values from an Array (in Turbo Pascal), and in BASIC using the memory to store a series of values (16bit in origin). The resulting program which was simply a Circle routine which originally came from the Amstrad CPC464 Manual. In BASIC the program was okay because of it's Lookup table to make everything display faster. In Turbo Pascal 3 the same program (in it's Pascal equivalent) was noticibly slower due to it been entirely calculated and nothing was going to change that unless it all the values were stored into an array. Remarkibly the resulting program was much faster.

In BASIC storing the result in memory and having a M/C routine in my BASIC program to take that information and drawing it would also prove to run faster than allowing BASIC to utilise it's lookup table. If I ever find that example again I'll send it in.

Unsure if a 16bit Poke proves to be faster than simply apply too BASIC pokes, perhaps because I'm taking a routine which takes straight to the machine.
Powered by SMFPacks Menu Editor Mod