MODIFYING THE ZP-150 & TANDY 600 DBCALLS FUNCTION LIBRARY By Jack Thompson Buffalo User's Group CIS PPN- 70665,222 ------------------ Adapted for Tandy 600 users on the Model 100 SIG; 27-Jan-86 Sysop Dave Thomas The Microsoft Basic, while a nearly complete version of GW-Basic, is missing all the needed functions to explore the inner workings of the machine. PEEK, POKE, INP, OUT and VARPTR are not present in this version of Basic. There is however a CALL function which is used to call machine language extensions provided in a library provided to give Basic the capability of dealing with files generated by the Database program included in the machines firmware. I found that this file could be uploaded to my Z-100 where I used DEBUG to modify it. I renamed it and downloaded it to the ZP-150 and was able to access the modified functions. I therefore decided to modify the library to offer the missing Basic functions so that I could start to explore the inner workings of the ZP-150. The library provided with the ZP-150 and Tandy 600 is called DBCALLS.LIB and is set up with a table of routine names and their addresses near the start of the file. At first I thought I could just replace an existing name with a new name having the same length and that it would be accessible. It turns out that this is not true and is the reason that the names chosen are a little strange. Nothing is published regarding the structure of the library and I have not spent a lot of time in trying to determine it as I wanted to implement the new functions as expeditiously as possible. As a result the new library is the same size as the original and contains a lot of unused code, but the functions provided do appear to work as I had hoped and provide a way of exploring the secrets of the ZP-150 and Tandy 600. I hope that with this as a starting point we can learn how this machine operates and implement some interesting software for it. The UTILITY.LIB file The UTILITY.LIB file is located in DL 4 of the Model 100 SIG as a binary file named UTILTY.LIB. Download this file with Tandy 600/ZP-150 with the command: DOW UTILTY.LIB/PROTO:XMODEM/TYPE:BIN See TEL004.600 in DL 1 for details on downloading procedures for the Tandy 600/ZP-150 if necessary. Below is given a description of the new routines in the UTILITY.LIB file. These have replaced many of the original routines in DBCALLS.LIB and any not replaced have been changed to point to a null entry if called. This means that you must still use DBCALLS.LIB to access database functions from Basic. NOTE: The instructions for creation of UTILITY.LIB are contained in the file MAKLIB.DOC; the source code is in MAKLIB.TXT, but note that those files are necessary ONLY for the technical programmer searching for tips on creation of another Library file. ***** WARNING ****** WARNING ****** WARNING ****** WARNING **** Several of the new functions have the potential to cause the ZP-150 or Tandy 600 to crash when used, especially if you are experimenting in unknown areas of memory or with unknown interrupts. You should always upload all files from the ZP-150 or Tandy 600 to another computer before experimenting using the functiopns presented here. Some crashes can be cured by pressing the reset button, but others require a complete cold restart of the system. FUNCTIONS 1) RPEEK returns the contents of a byte of memory. 2) RPOKE stores a byte in memory. 3) FPIN reads a byte or word of data from an I/O port 4) RPOUT writes a byte or word of data to an I/O port 5) FVARPTR returns the address of a simple numeric variable 6) DSVARPTR returns the length and address of a simple string variable. 7) QREGS returns the register contents for the library 8) DBSYSINT calls a specified interrupt with specified register contents. The register contents returned by the interrupt routine are returned. 9) DBMCALL used to make a near or far call to a specified routine with specified register contents. The registers returned by the called routine are returned by the function. The functions QREGS,DBSYSINT, and DBMCALL use string variables to pass and return register values. These strings should be preinitialized to be 26 characters long using the STRING$ function of Basic. The order of the registers in the string are AX,BX,CX,DX,SI,DI,BP,ES,DS,FLAGS,CS,SS,SP. Register strings reyurned by the functions contain all of these. While register strings passed to the functions DBSYSINT and DBMCALL contain all 13 registers only the first 9 are passed to the called interrupt or Machine language routine. It is recommended that when using the DBSYSINT or DBMCALL functions that a call first be made to the QREGS function to initialize the source register string. QREGS simply returns the register contents of the processor when it is in the QREGS function. FUNCTION DESCRIPTIONS 1) RPEEK CALL RPEEK(SEGMENT%,OFFSET%,BYTE%) SEGMENT% and OFFSET% define the location in memory that is to be read. The value of this byte is returned in BYTE%. An example below shows the use of this function to dump selected portions of machine memory. 2) RPOKE CALL RPOKE(SEGMENT%,OFFSET%,BYTE%) The value of BYTE% is stored at the location in memory defined by SEGMENT% and OFFSET%. 3) FPIN CALL FPIN(MODE%,PORT%,VALUE%) The I/O port PORT% is read and the value is returned in VALUE%. MODE% determines whether a byte or a word is read. If MODE%=0 a byte is read if MODE%=1 a word is read. 4) RPOUT CALL RPOUT(MODE%,PORT%,VALUE%) VALUE% is written to port PORT%. If MODE%=0 a byte representing value% MOD 256 is written. If MODE%=1 the word value of VALUE% is written. 5) FVARPTR CALL FVARPTR(VAR,SEGMENT%,OFFSET%) The address of the simple numeric variable VAR is returned in SEGMENT% and OFFSET%. This function is only for simple(Non-array) variables. 6) DSVARPTR CALL DSVARPTR(SVAR$,LENGTH%,SEGMENT%,OFFSET%) The length and address of the string variable SVAR$ is returned. This function is only for simple (Non-array) String variables. 7) QREGS Call QREGS(RREGS$) RREGS$ is a string variable initilized to 26 blanks as described above. On return RREGS$ contains the values of the registers in the library. The example below shows the use of this function to display the registers. 8) DBSYSINT Call DBSYSINT(INTERRUPT%,SREGS$,RREGS$) Executes software interrupt INTERRUPT% passing the values in SREGS$ in the machine registers and returning the register values after the interrupt in RREGS$. SREGS$ and RREGS$ are 26 character strings as mentioned above. An example is given below which allows checking various interrupts. 9) DBMCALL Call DBMCALL(MODE%,[SEGMENT%],OFFSET%,SREGS$,RREGS$) Calls a machine language routine. The routine may be a "NEAR" routine in which case MODE%=0 and SEGMENT% is not used, or a "FAR routine in which case MODE%=1 and SEGMENT% contains the segment for the call. in all cases OFFSET% contains the offset for the routine. SREGS$ contains the source register values for the routine and RREGS$ contains the returned register values. In all cases the RETURN instruction for the called routine must match the type of the call to the routine. A routine called with mode=0 (NEAR call) must end with a "RET" instruction, and a routine called with MODE%=1 (FAR call) must end with a "RETF" instruction. An example is given below in which the code to swap two registers and a "RETF" instruction are stored into a string, the function DBSVARPTR is used to find the address of the string and the function DBMCALL is used to execute the code. Example programs: The following programs are available in the DL 4 database of the Model 100 SIG. They are binary programs and must be downloaded with XMODEM protocol; see TEL004.600 in DL 1 for assistance. Download with Tandy 600 or ZP-150 and RECEIVE with .BAS extension for immediate run capability. 1) PEEK.600: This program will dump selected sections of memory to the screen. Download as PEEK.BAS 2) GETREG.600: This program will read the library machine registers and list the values on the screen. Download as GETREGS.BAS 3) CALLTT.600: This program stores machine code into a string variable and then uses library functions to get the address of the code, and to execute it. Download as CALLTEST.BAS 4) INTEST.600: This program can be used to call software interrupts. Download as INTTEST.BAS