Back to Reference Information

Calc On Routine

by Ciaran McCreesh

This page contains a listing for a simple program that displays a message when the calculator is turned on. To use this program simply assembly it and send it to the calculator. Run it using Asm(progname) and then you can delete the program.

The Theory

To enable the CalcOn program we need to do three things. Firstly we need to set a specific flag (bit of a memory location). Secondly we need to copy our routine to a certain area of memory. Finally we need to set a checksum up. The flag can be set using res 3,(iy + $23) and the code should be copied to memory location $d48e (_alt_on_exec). The checksum is memory location $d48d (_alt_on_chksum) and the code for setting it is shown below.

Problems

There are two possible problems with the routine. The first is that the memory location is only 200 bytes wide and the second is that the normal ROM pages may not be set. You must also exit the routine with the same ROM page set as when you entered. As the page varies from ROM version to ROM version you must remember (using the stack is best) which page was set.

The Routine

#include "ti86asm.inc"
.org _asm_exec_ram

ProgStart:
  call _flushallmenus             ;clear all menus
  call _runindicoff               ;disable run indicator

LoadRoutine:
  ld hl,RoutineStart              ;copy user routine to the place
  ld de,_alt_on_exec              ;it will be executed from
  ld bc,200                       ;maximum of 200 bytes
  ldir

  ld de,$28                       ;set up check digit
  ld a,(_alt_on_exec)
  ld hl,_alt_on_chksum + $28
  add a,(hl)
  add hl,de
  add a,(hl)
  add hl,de
  add a,(hl)
  add hl,de
  add a,(hl)
  add hl,de
  add a,(hl)
  ld (_alt_on_chksum),a

  set 3,(iy + $23)                ;enable user on routine
  ret                             ;return to main program

RoutineStart:
.org _alt_on_exec                 ;routine executed from here

  in a,(5)                        ;get current low area memory page
  push af                         ;and push it to the stack

  ld a,$0d                        ;set low area memory page to
  out (5),a                       ;ROM page $0d (normal)

  call _clrScrn                   ;clear screen
  call _homeup                    ;cursor to top left

  ld hl,TextToDisplay             ;hl points to null-terminated string
  call _puts                      ;display string starting at hl
  call _newline                   ;new line
 
  pop af                          ;get value from stack
  out (5),a                       ;and set low area memory page

  ret                             ;leave routine

TextToDisplay:
.db "This ti86 belongs to Fred the "
.db "Fish, so    leave it alone.   "
.db "   ---------------------",0

.end