Timex Tips

Author(s): Chuck Dawson
Publication: ZX-Appeal
Date: October 1986
Pages: 19

QUESTION: I am new to machine code programs and I would like to ask a basic question: If I call a short MC routine from within a BASIC program, how do I get the result back to a BASIC variable so I can use it?

ANSWER: This question keeps being asked, so I am glad to try to help. There are two ways to approach this problem. When a number has been manipulated by the various registers, it can be stored for later use by loading it into an unused memory location (or more usually two). After returning to BASIC, the number can be recovered by LET A=PEEK loc + 256*PEEK (loc+1). Several numbers could be calculated by the MC part of the program and stored in different locations. All you have to do is remember where you put them. If the MC routine produces only one answer to be transferred to the BASIC program, a short-cut method is to leave the answer in the BC register (TS-2068 and Spectrum) or the HL register (TS-1000 or TS-1500). If the routine was called by the line LET a=USR (64000), then when the MC routine RETURNs control to BASIC, the value that was in BC will now be in the BASIC variable A. If you called the routine with PRINT USR (64000), then the answer will be printed on the screen upon RETURN

QUESTION: I have a problem with a program which includes user defined characgers. It works just fine in the normal mode, but when run with the OS-64 (64 column cartridge), the user characters do not work.

ANSWER: When the TS-2068 is switched into one of the enhanced display modes like the 64 column, the user defined graphics are moved from 65386 to 63256. If you have defined a character for GRAPHIC A, for example, by POKING values into addresses starting at 65386, then you have poked the wrong location when in enhanced mode. It should have been 63256. You would have to change that location each time you switch from one mode to the other. A good way out of this is to use the built-in GRAPHIC ADDRESS CALCULATOR. That is, calculate the starting address of GRAPHIC A by the expression LET address=USR ‘A’. Then you can POKE address and address+1 and address+2, etc. No more changing the program by hand each time you plug in or out the 64 column cartidge. By the way, if you like to put machine code in a REM statement at the beginning of your program, it, too, will move when in enhanced mode. Always use PEEK 23635+256*PEEK 23636 to calculate the beginning of the program listing. Add five to get the correct USR call location if the MC starts just after the REM keyword in the first line of the program.

Reprinted from the August/86 issue of THE DATA EXPANSION — the newsletter of the T/S Users Group of Fort Worth.

Also printed in ZX-Appeal September 1986.