A83: Lists


[Prev][Next][Index][Thread]

A83: Lists




here are my two list programs. the first one creates a list and stores a
floating point number to each element. the second one displays all the
elements in a list. enjoy!

zlist.z80:

.NOLIST
#define equ .equ
#define EQU .equ
#define end .end
#include "ti83asm.inc"
#include "tokens.inc"
.LIST

_createrlist .equ 445Ah
rlstobj .equ 01h

.org 9327h

     call _zerooop1         ; clear op1
     ld hl,listname         ; load var name for list IAN into op1
     ld de,op1              ;
     ld bc,6                ;
     ldir                   ;
     call _chkfindsym       ; look up list
     call nc,_delvar        ; if it is there delete it
     ld hl,2                ; number of elements (1-999)
     call _createrlist      ; create list

; store to elements
;
; takes less space than _puttol because you
; copy the data directly to the element
; instead of to op1, then to the element

     push de                ; save list address
     ld hl,1                ; element 1
     call _adrlele          ; calculate element address
     ex de,hl               ; de -> element address
     ld hl,element1         ; hl -> num
     ld bc,9                ; 9 bytes
     ldir                   ; copy num to element

     pop de                 ; restore list address
     ld hl,2                ; element 2
     call _adrlele          ; calculate element address
     ex de,hl               ; de -> element address
     ld hl,element2         ; hl -> num
     ld bc,9                ; 9 bytes
     ldir                   ; copy num to element

     ret

listname:

     .db rlstobj,tvarlst,"IAN",$00  ; the user list IAN

element1:

     .db $00,$80,$75,$00,$00,$00,$00,$00,$00  ; 7.5

element2:

     .db $80,$82,$73,$45,$67,$23,$89,$00,$00  ; -734.5672389

; notes:
;
;  1) if the list name is 5 chars long it
;     doesn't need to be 0 terminated
;
;     less than 5 chars:
;     list IAN would be    rlistobj,tvarlst,"IAN",$00
;
;     5 chars:
;     list HELLO would be  rlistobj,tvarlst,"HELLO"
;
;  2) L1 - L6 use this format
;
;     L1 would be  rlstobj,tvarlst,tl1
;     L2 would be  rlstobj,tvarlst,tl2
;     L3 would be  rlstobj,tvarlst,tl3
;     L4 would be  rlstobj,tvarlst,tl4
;     L5 would be  rlstobj,tvarlst,tl5
;     L6 would be  rlstobj,tvarlst,tl6

.end
END

------------------------------------------------------------------------

zlist.z80:

.NOLIST
#define equ .equ
#define EQU .equ
#define end .end
#include "ti83asm.inc"
#include "tokens.inc"
.LIST

_errundefined .equ 467Bh
rlstobj .equ 01h

.org 9327h

     call _zerooop1      ; clear op1
     ld hl,listname      ; copy var name for list IAN into op1
     ld de,op1           ;
     ld bc,6             ;
     ldir                ;
     call _chkfindsym    ; look up list
     jp c,_errundefined  ; error if not found
     push de             ;
     pop hl              ; hl -> list address
     call _ldhlind       ; hl -> list length
     push hl             ;
     pop bc              ; bc -> list length
     ld hl,1             ; hl -> element number

lloop:

     push bc             ; store count
     push hl             ; store element num
     push de             ; store list address
     call _getltoop1     ; get element to op1
     ld a,16             ; format number for display
     call _formreal      ;
     ld hl,16            ;
     sbc hl,bc           ;
     ld a,l              ;
     ld (curcol),a       ;
     ld hl,op3           ;
     call _puts          ; display it
     pop de              ; restore list address
     pop hl              ; restore element number
     inc hl              ; increment element number
     pop bc              ; restore count
     dec bc              ; decrement count
     ld a,b              ; see if count is at 0
     or c                ;
     jr nz,lloop         ;
     ret

listname:

     .db rlstobj,tvarlst,"IAN",$00  ; the user list IAN

; notes:
;
;  1) if the list name is 5 chars long it
;     doesn't need to be 0 terminated
;
;     less than 5 chars:
;     list IAN would be    rlstobj,tvarlst,"IAN",$00
;
;     5 chars:
;     list HELLO would be  rlstobj,tvarlst,"HELLO"
;
;  2) L1 - L6 use this format
;
;     L1 would be  rlstobj,tvarlst,tl1
;     L1 would be  rlstobj,tvarlst,tl2
;     L1 would be  rlstobj,tvarlst,tl3
;     L1 would be  rlstobj,tvarlst,tl4
;     L1 would be  rlstobj,tvarlst,tl5
;     L1 would be  rlstobj,tvarlst,tl6

.end
END


References: