;Date:     Fri, 24 Nov 1995 18:41:26 +0100 (GMT+0100)
;From:     Magnus Hagander  [e95_mha@e.kth.se]
;Subject:  LZ: ZShell example source

;This message comes from the List-ZShell mailing list:

;Hello!

;I was asked for the source code to the function tester for ZShell 4.0. It
;is posted here. It might be good for those trying to learn ZShell
;assembly. However, it is NOT well documented. And as usual, no
;guarantees. It is the exact program that was released with ZShell 4.0. Enjoy.

;; Tests all the functions in ZShell..
;; (C) 1995 The ZShell Development Team, written by e95_mha@e.kth.se

#include "ti-85.h"

.org 0
   .db "FunctionTest",0
   ROM_CALL(CLEARLCD)
   ld hl,0
   ld ($800C),hl
   ld hl,(PROGRAM_ADDR)
   ld de,TestStr1
   add hl,de
   ROM_CALL(D_ZT_STR)
   ld hl,$0101
   ld ($800C),hl
   ld hl,(PROGRAM_ADDR)
   ld de,TestStr2
   add hl,de
   ROM_CALL(D_LT_STR)
   CALL_(WaitEnter)
   sub a
   ld ($8B2F),a
   ld  a,8
   ld ($8B30),a
   ROM_CALL(SCROLL_UP)
   ROM_CALL(BUSY_ON)
   CALL_(WaitEnter)
   ROM_CALL(BUSY_OFF)
   ROM_CALL(CLEARLCD)
   ld  hl,0
   ld  ($8333),hl
   ld  hl,(PROGRAM_ADDR)
   ld  de,TestStr1
   add hl,de
   ROM_CALL(D_ZM_STR)
   ld  hl,$1010
   ld  ($8333),hl
   ld  hl,(PROGRAM_ADDR)
   ld  de,TestStr2
   add hl,de
   ld  b,(hl)
   inc hl
   ROM_CALL(D_LM_STR)
   CALL_(WaitEnter)
   ld  a,'A'
   ld  hl,0
   ld  ($800C),hl
   ROM_CALL(TR_CHARPUT)
   CALL_(WaitEnter)
   ld  hl,($2020)
   ld  ($8333),hl
   ld  a,'B'
   ROM_CALL(M_CHARPUT)
   CALL_(WaitEnter)
   ROM_CALL(CLEARLCD)
   ld  hl,0
   ld  ($800C),hl
   ld  hl,12345
   ROM_CALL(D_HL_DECI)
   CALL_(WaitEnter)
   ld  a,4
   out (5),a            ;Flip memory page
   ld  b,0
   ld  c,0
PixelLoop:
   push bc
   CALL_(PixelOn)
   pop  bc
   inc  b
   inc  c
   ld   a,b
   cp   32
   jr   nz,PixelLoop
   CALL_(WaitEnter)
   ld   hl,(PROGRAM_ADDR)
   CALL LD_HL_MHL
   cp   'F'         ;Compare to first byte..
   jr   nz,ErrorExit ;Didn't work...
   CALL_(NextEnter)
   ld   hl,1010
   ld   de,1010
   CALL CP_HL_DE
   jr   nz,ErrorExit ;Didn't work...
   CALL_(NextEnter)
   ld   a,'G'
   CALL STORE_KEY
   CALL GET_KEY
   cp   'G'
   jr   nz,ErrorExit
   CALL_(NextEnter)
   ret

NextEnter:
   sub   a
   ld    ($800D),a
   ld    hl,$800C
   inc   (hl)
   ld    hl,(PROGRAM_ADDR)
   ld    de,EnterStr
   add   hl,de
   ROM_CALL(D_ZT_STR)
   jr    WaitEnter

ErrorExit:
   ROM_CALL(CLEARLCD)
   ld   hl,0
   ld   ($800C),hl
   ld   hl,(PROGRAM_ADDR)
   ld   de,ErrorStr
   ROM_CALL(D_ZT_STR)
   jr   WaitEnter

PixelOn:
   ROM_CALL(Find_Pixel)
   ld  de, $FC00
   add hl,de
   or  (hl)
   ld  (hl),a
   ret


WaitEnter:
   CALL Get_Key
   or   0
   jr   z,WaitEnter
   ret

TestStr1: .db "ZeroTerminated",0
TestStr2: .db 13,"LengthIndexed"
EnterStr: .db "Press Enter",0
ErrorStr: .db "Error!",0
.end
