Writing cheat procedures requires understanding of the cps transformation which is decribed in the appendix. For simple procedures is is possible to get by with extending the code in Figure .
Figure: Writing a cheat procedure
As an example, we will show how the color-me procedure is defined. color-me needs to know which processor it should draw and where to draw it. Getting hold of the simulation and the index of the processor within the simulation is the tricky part. For that reason, we split color-me into two parts: one to get the simulatiuon object and processor index, and a helper procedure %color-me which does the real work and is written as an ordinary Scheme procedure (for an example see club5d.scm in the appendix.)
The file from Figure is compiled as an ordinary Scheme file, but it is loaded into the simulation with simulation.load. Since it is loaded into the simulation load environment (Figure ), the whole file must be written cps converted. This means that the very last expression in the file must be of the form:
(lambda (cont fuel store) ... (cont <file-value> fuel store))
The expression SPMquot
(fix:+ fuel 4)" can be replaced by just fuel.
Doing so will cause the Gunk call to color-me to take a normal
amount of simulated processor time.