Tutorial 24
Program creating programs

    This proves the power of Asm. This tutorial will cover the uses of the _CreateProg (_CreateProg = 4339h) and _CreateProtProg (_CreatProtProg = 4E6Dh) ROM calls. Both these ROM calls create programs on the TI-83 Plus. The difference between the two ROM calls is that _CreateProg creates a program that can be edited on the calculator and _CreateProtProg creates a program that cannot be edited on the calculator.

    This program will create an Asm Getkey program and a TIBasic program to run the Getkey program.

.NOLIST                    ;This program may look long, but most of it is the required stuff.
#define equ .equ
#define EQU .equ
#define END .end
#include "ti83PlusAsm.inc"

.org 9D95h

    B_CALL(_Homeup)      ;Clear screen.
    ld hl,prgmcreate        ;Load the Text under the PrgmCreate label
    ld hl,asmcreate        ;Load the Asmcreate text
    B_CALL(_puts)        ;Display the text
    B_CALL(_zeroop1)    ;Set Op1 to zero
    ld hl,progname1       ;the name of the prog
    ld de,op1                ;copy it to op1
    ld bc,5                   ;5 chars in name

    ldir                          ;copying name...
    ld hl,241                  ;length of program (in bytes)
    B_CALL(_createprog) ;create it unprotected program (can be edited on calculator)
    inc de                    ;skip 1st length byte
    inc de                    ;skip 2nd length byte
    ld hl,prog1              ;program data under prog1 label (Asm program data)
    ld bc,241               ;program data length
    ldir                        ;copy program data

    ld hl,basiccreate        ;Load text from Basiccreate label

    ld hl,progname2        ;the name of the prog
    ld de,op1                ;copy it to op1
    ld bc,7                   ;7 chars in name
    ldir                        ;copying name...
    ld hl,6                    ;length of program (in bytes)

    B_CALL(_createprog) ;create it
    inc de                 ;skip 1st length byte
    inc de                 ;skip 2nd length byte
    ld hl,prog2           ;program data

    ld bc,6               ;program data length
    ldir                    ;copy data

    .db PROGOBJ,"ASM",0 ;"ASM" is the name of the Asm Getkey program
prog1:                                        ;Asm program data
    .db t2bytetok,tAsmPrgm,tEnter ;See Tokens section below for explanation
    .db "EF4045EF5845",tEnter
    .db "21EC9DEF0A45",tEnter
    .db "EF7249F5EF40",tEnter
    .db "45EF584521F8",tEnter

    .db "9DEF0A45F1CD",tEnter
    .db "BC9DEF7249EF",tEnter
    .db "2E45C9F5E6F0",tEnter
    .db "1F1F1F1F6F26",tEnter
    .db "0011DC9DD519",tEnter
    .db "7EEF0445D1F1",tEnter
    .db "E60F6F260019",tEnter
    .db "7EEF0445C930",tEnter
    .db "313233343536",tEnter
    .db "373839414243",tEnter
    .db "444546507573",tEnter
    .db "682061206B65",tEnter
    .db "792E004B6579",tEnter
    .db "20636F64653A",tEnter
    .db "2000"

    .db PROGOBJ,"BASIC",0 ;Basic program name
    .db t2bytetok,tAsm,tProg,"ASM" ;Basic program data

    .db "Program Creator!",0
    .db "Creating ASM...",0
    .db "Creating BASIC...",0


    If you wanted to create programs that can't be edited on the calc, replace _createprog with _createprotprog.

New Commands
    _CreateProg - Creates a program that can be edited
    _CreateProtProg - Creates a program that cannot be edited
    ldir - Loads data from one place to another

    The hardest thing about making program creating programs is surprisingly the tokens. Think of the TIBasic commands Clrhome and Disp. They are tokens. So are Cos( and Sin( and Tan( and everything else you paste to the TI's screen by pressing a button or looking in a menu. We all know that each text character you type is 1 byte each. How much memory does the Calculator have? Not much compared to my computer's Hard Drive. So instead of saving the commands (Clrhome, Disp, Cos(, Sin(, Tan(, etc.) by each character, Texas Instruments was smart and saved each of these commands to 1 byte each. Thus, the command stored in the calculators memory is called a Token. What!? We used tEnter, tprog, etc. in the program! Those are the Asm names of the tokens. The "t" stands for Token. Thus tEnter would be the equivalent of pressing Enter, or in our case, creating a new line. For a complete list of TI-83 Plus Tokens, look in the ti83PlusAsm.inc include file.

    Almost every TI-83 Plus Token is 1 byte with the exception of a few. This is where even I needed help. I asked Matthew Roberts for the answer. After a few days, Voila! He had the answer. If you look at the tokens ">" and "tAsm", they have the same addresses in memory. This is because tAsm is a 2 byte token. That's why if you assemble the program with just tAsm, the output would be ">". So to get the Asm( command instead of ">", we had to use the t2ByteTok token. This defines the token as 2 bytes. If you want to know which tokens are 2 byte, look in the ti83PlusAsm.inc include file under 2byteTokens.

    Another thing to know about program data, you must tell the calculator exactly how big the program it's making is. You would load that value to the bc register because that's where the _createprog ROM call looks for the program size. How do you know how big your program data is? Well that's easy. Count how many Tokens and Characters you use inside quotes. Add that up and the total is your program data size in bytes. =)

    Again, I want to thank Matthew Roberts for his help with the 2 byte tokens. Where would I be without him? Don't answer that. On to Checking your memory via an Asm program!

Tutorial 25


    Click to return to the site's menu... or here to get back to the tutorial's menu.