    include ti83asm.inc
    include tokens.inc

kenter equ  05h

    org     9327h

    call    _clrlcdfull           ; clear home screen
    call    _homeup               ; cursor to upper left
;
;   this section of code will display the entire
;   for the ti-83. 1 line at a time
;
    xor     a                     ; acc=0
..loop0:
    ld      b,15
..loop1:
    inc     a                     ; next char
    call    _putc                 ; display char
    cp      0DEh                  ; done with all
    jr      z,..done1             ; yes
;
    djnz    ..loop1               ; decr count for line
;
    push    af                    ; save char #
    call    wait_for_enter        ; wait for enter key
    pop     af                    ; restore it
    jr      ..loop0
;
..done1:
    call    _newline
    ld      hl,char_test_dn
    call    _puts                 ; show done with char test
;
    call    wait_for_enter        ; wait for enter key
;
;   this section of code will load HL with a value and
;   use the system routine DISPHL to display it
;
;
    ld      hl,123d               ; hl = 123 dec
    call    _disphl
    call    wait_for_enter        ; wait for enter key
;
    call    _pdspgrph             ; go to graph
;
;   variable font writes to the display have
;   location (0,0) in the upper left corner of the display
;
    set     write_on_graph,(iy+sgrflags)  ; signal writing to graph
    ld      hl,0                  ; set to upper
    ld      (pencol),hl           ; (penrow)=0,
    LD      HL,THIS_IS_COOL
;
;   This call will only write to the graph display screen and not to the
;   graph backup buffer.
;
    CALL    _VPUTS
;
;   If you want the writes to also go to the graph backup buffer
;   then the "textwrite" flag must be set and the string must
;   be written again and this time it will only write to the
;   backup buffer.
;
;   You only need to write to the backup buffer if you want
;   what is writen to "stick" until the next regraph happens.
;   Otherwise when the backup buffer gets copied to the
;   display, what was written will be gone. This copy happens
;   often under normal calc use.
;
    set     textwrite,(iy+sgrflags)  ; signal going to graph backup buffer
    ld      hl,0                  ; set to upper
    ld      (pencol),hl           ; (penrow)=0,
    LD      HL,THIS_IS_COOL
    CALL    _VPUTS                ; write to backup buffer
    res     textwrite,(iy+sgrflags)  ; signal not going to graph backup buffer
    res     write_on_graph,(iy+sgrflags)  ; signal not writing to graph
;
;   The variable font routines were originally intened for
;   test screens only and were modified for graph screen writes,
;   so you must set the plotdisp flag to indicate the
;   graph screen is in the display. The variable font
;   writes had reset it
;
    set     plotdisp,(iy+plotflags)          ; sognal graph is in display
;
;   let's draw a line under our cool msg
;
;   This next call uses the graph pixel mapping which has
;   location (1,0) in the lower left corner
;
    ld      bc,57                 ; x=0,y=57 1st point
    ld      de,94*256+57          ; x=94,y=57 2nd point
    ld      h,1                   ; turn on line
;
;   this is the pixel line routines
;
    call    _iline                ; draw line connecting points
;
    call    wait_for_enter_gr
;
;   go back to home screen
;
    res     plotdisp,(iy+plotflags)  ; graph srceen not in disp
;
;   The next 2 calls will restore the home screen to what it
;   was before we went to the graph screen.
;
;
;
    call    _saveshadow           ; save cursor info
    call    _rstrshadow           ; restore cursor info and homescreen shadow
;
;   back on the home screen now
;
    ld      a,xmint
    call    _rclsystok            ; op1 = xmin value
;
;   Here we are going to format the value in op1 for
;   display on the home screen
;
    ld      a,15                  ; 15 chars to format max
;
;   This formats fp# in op1 into displayable string
;
    call    _formreal             ; op3 = start of formatted string
    ld      hl,op3                ; point to string
    call    _puts                 ; display it
    call    _newline              ; line feed
;
    call    _sin                  ; op1 = sin(xmin)
    ld      a,15                  ;
    call    _formreal             ; op3 = start of formatted string
    ld      hl,op3                ; point to string
    call    _puts                 ; display sin(xmin)
    call    wait_for_enter        ;
;
;   Here we are going to set xmin=-1, xmax=5, ymin=-2.5,ymax=.3333333333333
;
    call    _op1set1              ; op1 = 1
    call    _invop1s              ; op1 = -1
    ld      a,xmint
    call    _stosystok            ; xmin = -1
    call    _op2set5              ; op2 = 5
    call    _op2toop1             ; move to op1 = 5
    ld      a,xmaxt
    call    _stosystok            ; xmax = 5
    call    _timespt5             ; op1*.5 = 2.5
    call    _invop1s              ; op1 = -2.5
    ld      a,ymint
    call    _stosystok            ; ymin = -2.5
    call    _op1set3              ; op1 = 3
    call    _fprecip              ; op1 = 1/3 = .333333333333
    ld      a,ymaxt
    call    _stosystok            ; ymax = 1/3
    call    _pdspgrph             ; back to graph srceen
;
;   now let's draw a line using graph coordinates
;
    ld      a,xmint
    call    _rclsystok            ; op1 = xmin
    call    _op1toop3
    ld      a,ymint
    call    _rclsystok            ; op1 = ymin
    call    _op1toop4             ; (op3,op4) = one end of line
    ld      a,ymaxt
    call    _rclsystok            ; op1 = ymax
    call    _op1toop2
    ld      a,xmaxt
    call    _rclsystok            ; (op1,op2) = other end of line
    call    _cline                ; draw a line connecting the coord points
    call    wait_for_enter_gr     ; wait for enter key
    call    _grbufcpy_v           ; get backup graph, removes "press enter"
;
;   now let's use the graph coord point routine, different from pixel point
;   turn a point on @ (1,-2)
;
    call    _op1set1              ; op1 = 1
    call    _pushrealo1           ; read doc for 'CPOINTS', put on stack
    call    _op1set2
    call    _invop1s              ; op1 = -2
    call    _pushrealo1           ; read doc for 'CPOINTS', put on stack
    ld      a,1
    call    _cpoints              ; turn point on
    call    wait_for_enter_gr     ; wait for enter key
    call    _grbufcpy_v           ; get backup graph, removes "press enter"
    RET

;
wait_for_enter:
    call    _newline              ; move to next
    ld      hl,hit_enter          ; hl = ptr to
    call    _puts                 ; display stri
;
    ei                            ; renable inte
;
;   this section of code will go to low power mo
;   waiting for a key press, if the key press is
;   the enter key then the next section of code
;   is executed, otherwise go back to keyscan
;
;
..key_loop:
    call    _getkey               ; wait for key
    cp      kenter                ; enter key ?
    jr      nz,..key_loop         ; no
;
    call    _newline
    ret
;
;
;
wait_for_enter_gr:
    ld      hl,7*256
    ld      (pencol),hl
    ld      hl,hit_enter          ; hl = ptr to string
    call    _vputs                ; display string
;
;   remember that most of the display routines will disable interrupts
;
    ei                            ; renable interrupts
;
;   this section of code will go to low power mode
;   waiting for a key press, if the key press is
;   the enter key then the next section of code
;   is executed, otherwise go back to keyscan
;
;
..key_loop:
    call    _getkey               ; wait for key
    cp      kenter                ; enter key ?
    jr      nz,..key_loop         ; no
;
    ret


char_test_dn db     'char test done',0
hit_enter   db      'press enter',0
this_is_cool db     'Yeah Yeah this is cool',0
