E-mail Address
Password

Register
arasian > support > education > tutorial

Ti-83 and Ti-84 Assembly Programming
Getting Started
     1.1: About This Tutorial
     1.2: About TI-ASM
     1.3: Writing Your First Program
     1.4: Compiling
     1.5: Debugging
ASM Basics
     2.1: Calls and Jumps
     2.2: Registers
     2.3: Displaying Text
System Controls and Calls
     3.1: Data
     3.2: Register Stack
     3.3: If Statements (Comparing)
     3.4: GetKey and GetCSC
     3.5: System Flags
     3.6: Menus
     3.7: Displaying Pictures
     3.8: For Loops (djnz)
     3.9: White Loops
     3.10: OP Registers
Applications
     4.1: Apps vs ASM
     4.5: KeyHooks
Menus

With the knowledge you have now, you can create a menu. Now we can finally see the amount of code that actually goes into the BASIC Menu( command. Everything in the code below you should understand from last section. The AppGuru tutorial on menus has a different way of creating a menu. Their way is more efficient, but I find this way easier to understand and program.

 
.NOLIST
#define EQU .equ
#define equ .equ
#define END .end
#include "ti83plus.inc"
.LIST

     .org 9D93h
     .db $BB,$6D

StartProg:
     B_CALL(_ClrLCDFull)
     res textInverse,(IY+textFlags)
     ld bc,0
     push bc
     ld a,0
     ld (CURROW),a
     ld a,0
     ld (CURCOL),a
     set textInverse,(IY+textFlags)
     ld hl,txtMenuHeader
     B_CALL(_PutS)

     res textInverse,(IY+textFlags)
     ld a,0
     ld (CURCOL),a
     ld a,1
     ld (CURROW),a
     ld hl,txtMenu
     B_CALL(_PutS)

MenuLoop:
     pop bc
     push bc
     ld a,b
     cp 1
     call z,SetTI
     ld a,0
     ld (CURCOL),a
     ld a,1
     ld (CURROW),a
     ld hl,txt1m
     B_CALL(_PutS)
     res textInverse,(IY+textFlags)

     pop bc
     push bc
     ld a,b
     cp 2
     call z,SetTI
     ld a,0
     ld (CURCOL),a
     ld a,2
     ld (CURROW),a
     ld hl,txt2m
     B_CALL(_PutS)
     res textInverse,(IY+textFlags)

     pop bc
     push bc
     ld a,b
     cp 3
     call z,SetTI
     ld a,0
     ld (CURCOL),a
     ld a,3
     ld (CURROW),a
     ld hl,txt3m
     B_CALL(_PutS)
     res textInverse,(IY+textFlags)

MenuGetKey:
     B_CALL(_GetKey)
     cp kDown
     jp z,MoveDown
     cp kUp
     jp z,MoveUp
     cp kEnter
     jp z,Select
     cp kClear
     jp z,ExitProg
     cp kQuit
     jp z,ExitProg
     jp MenuGetKey

MoveDown:
     pop bc
     ld a,b
     cp 3
     jp z,MoveTop
     inc b
     push bc
     jp MenuLoop

MoveUp:
     pop bc
     ld a,b
     cp 1
     jp z,MoveBottom
     dec b
     push bc
     jp MenuLoop

MoveTop:
     ld b,1
     push bc
     jp MenuLoop

MoveBottom:
     ld b,3
     push bc
     jp MenuLoop

Select:
     pop bc
     ld a,b
     cp 1
     jp z,Select1
     cp 2
     jp z,Select2
     cp 3
     jp z,ExitProg
     push bc
     jp MenuLoop

Select1:
     B_CALL(_ClrLCDFull)
     ld a,0
     ld (CURROW),a
     ld (CURCOL),a
     ld hl,txtSelect1
     B_CALL(_PutS)
     B_CALL(_GetKey)
     jp StartProg

Select2:
     B_CALL(_ClrLCDFull)
     ld a,0
     ld (CURROW),a
     ld (CURCOL),a
     ld hl,txtSelect2
     B_CALL(_PutS)
     B_CALL(_GetKey)
     jp StartProg

SetTI:
     set textInverse,(IY+textFlags)
     ret

ExitProg:
     B_CALL(_ClrLCDFull)
     B_CALL(_ClrTxtShd)
     ret


txtMenuHeader:
     .db "MENU",0
txtMenu:
     .db "1:Option1       "
     .db "2:Option2       "
     .db "3:Quit          ",0
txt1m:
     .db "1:",0
txt2m:
     .db "2:",0
txt3m:
     .db "3:",0
txtSelect1:
     .db "You chose 1",0
txtSelect2:
     .db "You chose 2",0

.end

This menu has 3 options. Explanations of things are above. The register b stores the current menu position. Since registers are not preserved for a long time, the bc register pair is pushed onto the register stack.
Creative Commons License
The text in this tutorial is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.

Privacy Policy | Contact Us
(c) 1999-2010 Arasian. All rights reserved.