home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 85 / asm / source / zshell / zterm.asm < prev   
Encoding:
Assembly Source File  |  2001-07-01  |  95.5 KB  |  3,804 lines

  1. ;HELLO   Alan Bailey is the name
  2. ;I'm posting this source for a few reasons
  3. ;  1)  people have asked for it
  4. ;  2)  I've decided I'm done with it
  5. ;  3)  the little people in my head told me to
  6. ;
  7. ;So...try to learn something frm it.  It's not commented and I didn't want it to be. 
  8. ;Mostly it is for people trying to implement something like it themselves.
  9. ;
  10. ;contact me if you have any questions:
  11. ;
  12. ;Alan Bailey
  13. ;mailto:bailela@charlie.cns.iit.edu
  14. ;Web: http://www.iit.edu/~bailela/
  15. ;IRC: Abalone on #ticalc, #ti-files on Efnet
  16. ;
  17. ;BYE!!!
  18.  
  19.  
  20.  
  21. #include "ti-85.h"
  22. .org 0
  23. .db "ZTerm v.9b by Alan Bailey",0
  24.  
  25.  
  26.  
  27.  
  28. ;$8BE1
  29. ;$8BE5          ;the real ones thankfully
  30.  
  31. ;finished the vt100 commands1!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
  32. ;FINISHED THE VT100 COMMANDS
  33.  
  34. ;{April 23, 1997...fixed that thing with the cursor...it had to do with getkeys
  35.  
  36.  
  37. ;VARIABLE DEFINITIONS:  length | description
  38. ;------------------------------|--------------------------------
  39. cursorcount = $80DF     ;byte  | counter for the cursor  
  40. state1 = $80E0          ;byte  | ASCII code for cursor displayed ($7C or $20)
  41. state2 = $80E1          ;byte  | ASCII code for cursor not displayed ^^^^ 
  42. cursorstate = $80E2     ;byte  | 0-norm 1-second 2-big 3-small
  43. cursorstate2 = $80E3    ;byte  | same parameters ^^, secondary value used in editing function keys
  44.  
  45. cursorcoords = $80E4    ;word  | coords of cursor($xxyy), $FFFF if not on screen
  46. cursoraddress = $80E6   ;word  | pointer in mem of place to write to
  47.  
  48. startbuffer = $80E8     ;word  | pointer to first line of data
  49. endbuffer = $80EA       ;word  | pointer to line containing cursoraddress   <------\
  50. realendbuffer = $811A   ;word  | the pointer to the actual end, not just the one ^^^^
  51. memend = $80EC          ;word  | pointer to last line that can contain data
  52.  
  53. displaystart = $80EE    ;word  | pointer to line at the top of the screen
  54. currrow = $80F0         ;word  | used in displaystart, first line to put on screen
  55. displaycolumn = $80F2   ;byte  | column number on left of screen
  56. linestodisplay = $80F3  ;byte  | number of lines to display after and inclusive of currrow
  57.  
  58. vt100_on = $80F4        ;byte  | For all of these, 1 if set, 0 if not
  59. localecho_on = $80F5    ;byte  | Preferences of terminal
  60. outboundCRLF_on = $80F6 ;byte  | These MUST stay in the same order,
  61. inboundCRLF_on = $80F7  ;byte  | don't change
  62. splitscreen_on = $80F8  ;byte  | -------------
  63.  
  64. currentpref = $80F9     ;word  | pointer to current pref selected
  65. currentmenu = $80FB     ;word  | pointer to current menu shown
  66.  
  67. currentFkey = $80FD     ;byte  | Fkey chosen in function key edit ($31('1')-$35('5'))   
  68. Fkeyaddress = $80FE     ;word  | pointer to current line of function key chosen
  69. Fkeycursor = $8100      ;byte  | cursor value for editing of function keys
  70.  
  71. sendoutbuffer = $8A11   ; 32   | this is in the graphmem
  72. dispoutbuffer = $89F1   ; 32   | this is before the sendoutbuffer in the graphmem
  73.  
  74. storedcoords = $8101    ;word  | stores the coords from the vt100 command
  75. storedline = $8103      ;word  | stores endbuffer from the vt100 command
  76.  
  77. vt100charattrib = $8105 ;byte  | vt100 command sets display style
  78.                         ;      | bit 0 set - bold on
  79.                         ;      | bit 1 set - underscore on
  80.                         ;      | bit 2 set - blink on
  81.                         ;      | bit 3 set - reverse on
  82.  
  83. inputbufferstart = $8106 ;word | pointer to buffer to store incoming data
  84. buffercursor = $8108    ;word  | pointer of current place to write to
  85. beginbufferdata = $810A ;word  | pointer to beginning of data to process
  86. inputbufferend = $810C  ;word  | pointer to end of place to store incoming data
  87.  
  88. bufferhasdata = $810E   ;byte  | set to 1 if data is waiting to be processed
  89. sendouthasdata = $810F  ;byte  | set to 1 if data waiting to be sent
  90. dispouthasdata = $8110  ;byte  | set to 1 if data waiting to be displayed
  91.  
  92. unpacknumber = $8111    ; 3    | 3 bytes for displaying ascii digits
  93. totallines = $8114      ;word  | totallines for use by ZTerm
  94.  
  95. startoverind = $8116    ;byte  | indicator to tell if should display stuff during beg
  96. absnowork = $8117       ;byte  | set if no mem for program to work at all
  97. absnovt100 = $8118      ;byte  | set if no mem for vt100 to work at all
  98.  
  99. bellcounter = $8119     ;byte  | counter to keep bell on screen
  100.       ;$811A used
  101.       ;$811B used
  102.  
  103. firstline = $811C       ;word  | first line of vt100screen
  104. lastline = $811E        ;word  | last line of vt100 screen
  105.  
  106. firstscroll = $8120     ;word  | first scrolling line
  107. lastscroll = $8122      ;word  | last scrolling line
  108.  
  109. stored_key = $8124      ;byte  | stored key to check for key repeats
  110.  
  111.  
  112.  
  113. ;(------------------Start of the program-------------------)
  114. ;|This is where the program starts.                        |
  115. ;|All the initialization stuff is in here                  |
  116. ;(---------------------------------------------------------) 
  117.     ld a,0              ;these designate that the screen should be displayed this time
  118.     ld (startoverind),a ;if 1, don't display the screen after all initialization
  119. start:
  120.     ld hl,ZS_BITS        ;allows bytes in ZTerm to be changed
  121.     set 0,(hl)           ;/
  122.     ld hl,(PROGRAM_ADDR) ;\
  123.     ld de,savedprefs     ; \
  124.     add hl,de            ;Loads the saved preferences
  125.     ld de,vt100_on       ;  /
  126.     ld bc,00005          ; /
  127.     ldir                 ;/
  128.     ld hl,(PROGRAM_ADDR)
  129.     ld de,tabtable       ;
  130.     add hl,de            ;
  131.     ld (hl),0            ;
  132.     ld b,9               ;loads the tabs into place
  133. loadtabsloop:
  134.     inc hl
  135.     ld (hl),%10000000
  136.     djnz loadtabsloop
  137.     set 0,(hl)           ;and the final tab is there
  138.  
  139.     ld hl,sendoutbuffer  ;zeroes out any stuff in the sendoutbuffer
  140.     ld a,$00             ;and in the dispoutbuffer
  141.     ld (hl),a            ;that's why the 63 is there
  142.     push hl
  143.     pop de
  144.     inc de
  145.     ld bc,00063
  146.     ldir                    ;like that
  147.  
  148.  
  149.     ld hl,$207C             ;  $20 = space  $7C = horizontal bar
  150.     ld (state1),hl          ;initialize stuff
  151.     ld a,0                                   ;\/
  152.     ld (cursorcount),a                       ;\/
  153.     ld (cursorstate),a                       ;\/
  154.     ld (cursorstate2),a                      ;\/
  155.     ld (displaycolumn),a                     ;\/
  156.     ld ($8333),a
  157.     ld ($8334),a
  158.     ld (sendouthasdata),a
  159.     ld (bufferhasdata),a
  160.     ld (dispouthasdata),a   ;all the previous things are started at zero
  161.     ld hl,$0000
  162.     ld (cursorcoords),hl        ;first cursor spot at (0,0)
  163.  
  164.     ld hl,$8BE5         ;this is the end of the free memory
  165.     call LD_HL_MHL
  166.     push hl             ;it's needed twice in the future
  167.     push hl
  168.     ld hl,$8BE1         ;this is the beginning of the free mem
  169.     call LD_HL_MHL
  170.     ld (inputbufferstart),hl        ;beginning of mem for these three variables
  171.     ld (buffercursor),hl
  172.     ld (beginbufferdata),hl
  173.     ld de,$07FF                 ;check if not enough later!!!!       <---------
  174.     add hl,de                ;$07FF+1 is length of the receive byte buffer
  175.     pop de
  176.     push hl                 ;holds hl for 6 lines
  177.     scf
  178.     ccf
  179.     sbc hl,de
  180.     bit 7,h
  181.     JUMP_Z(nomemforbuffer)
  182.     pop hl
  183.     ld (inputbufferend),hl   ;this is the end of it
  184.     inc hl                   ;get to the correct place for displaystart and all that
  185.     pop de                   ;loads the thing that used to be in hl
  186.     ld (displaystart),hl        ;these are all past the 2048 at the beginning
  187.     ld (currrow),hl             ;beginning variables for the display buffer
  188.     ld (cursoraddress),hl
  189.     ld (startbuffer),hl
  190.     ld (endbuffer),hl
  191.     ld (firstline),hl
  192.     ld (firstscroll),hl
  193.     push hl
  194.     ld bc,01520         ;80*19
  195.     add hl,bc
  196.     ld (realendbuffer),hl
  197.     ld (lastline),hl
  198.     ld (lastscroll),hl
  199.     pop hl
  200.     push hl
  201.     ex de,hl                ;now...hl=end buffer de=start buffer
  202.     sbc hl,de               ;this finds the difference
  203.     ld a,h              ;\/All of these things do something like a mod thing
  204.     ld c,l                              ;with 16 bit
  205.     ld de,00080
  206.     CALL_(div)      ;ac outputs with number of lines
  207.     ld d,a              ;\/
  208.     ld e,c
  209.     push de
  210.     pop hl
  211.     ld (totallines),hl      ;puts it in here for use with begin screen
  212.     ld a,80
  213.     CALL_(mult)         ;\/ hl is outputted with the number of lines * 80
  214.     pop de              ;de is the start
  215.     add hl,de           ;add to find the end
  216.     ld bc,00800         ;this subtracts 80 to be sure you don't write over
  217.     scf
  218.     ccf
  219.     sbc hl,bc           ;anything
  220.     ld (memend),hl      ;and there you have it, the last variable for the last line
  221.     add hl,bc           ;this increases it again for this clearing routine
  222.     ex de,hl            ;now de is the end and hl is beginning
  223.     ld hl,(inputbufferstart)
  224. clearmem:
  225.     ld (hl),0           ;clears all the stuff in mem  takes a while..
  226.     inc hl
  227.     call CP_HL_DE
  228.     jr nz,clearmem
  229.  
  230.     ld a,(startoverind)
  231.     cp 1
  232.     JUMP_Z(intsetup)            ;skips the screen, ints back on, terminal time
  233.                         ;used when CLEAR is pressed
  234.  
  235.         ;this is the beginning of displaying things
  236. dispbeginscreen
  237.     CALL_(clearscreen)
  238.     ld hl,(PROGRAM_ADDR)
  239.     ld de,ztermpicture
  240.     add hl,de
  241.     ld de,$FC04
  242.     ld bc,00226
  243.     ldir
  244.     ld hl,$0F24
  245.     ld ($8333),hl
  246.     ld hl,(PROGRAM_ADDR)
  247.     ld de,screenwords
  248.     add hl,de
  249.     ROM_CALL(D_ZM_STR)
  250.     push hl
  251.     ld hl,$0303
  252.     ld ($800C),hl
  253.     pop hl
  254.     ROM_CALL(D_ZT_STR)
  255.     push hl
  256.     ld hl,$2116
  257.     ld ($8333),hl
  258.     pop hl
  259.     ROM_CALL(D_ZM_STR)
  260.     push hl
  261.     ld hl,$2E00
  262.     ld ($8333),hl
  263.     pop hl
  264.     ROM_CALL(D_ZM_STR)
  265.     push hl                 ;saved for lang way off
  266.  
  267.     ld hl,(totallines)         
  268.     ld de,unpacknumber+2
  269.     ld b,3
  270. unpackloop:
  271.     call UNPACK_HL
  272.     add a,'0'
  273.     ld (de),a
  274.     dec de
  275.     djnz unpackloop
  276.     inc de
  277.     ex de,hl
  278.     ld b,3
  279.     ROM_CALL(D_LM_STR)          ;number
  280.     pop hl                  ;saved address for words
  281.     ROM_CALL(D_ZM_STR)          ;"lines"
  282.  
  283.     ld hl,(totallines)
  284.     ld a,l
  285.     add a,$10
  286.     jr c,dispdiag4         ;if after adding 16, it carried over, means over 240
  287.     bit 7,l
  288.     jr nz,dispdiag3         ;if bit 7 of l is set, over 127
  289.     ld a,l
  290.     add a,12
  291.     bit 5,a
  292.     jr nz,dispdiag2         ;if any of the top three bits are set, over 31
  293.     ld a,l
  294.     add a,6
  295.     bit 4,a
  296.     jr nz, dispdiag1        ;if bit 4 set after adding 5, over 10
  297.     jr dispdiag0            ;or go here, NO MEM!!!
  298.  
  299. dispdiag4:
  300.     ld de,diagnosis4
  301.     jr dispdiagnosis
  302. dispdiag3:
  303.     ld de,diagnosis3
  304.     jr dispdiagnosis
  305. dispdiag2:
  306.     ld de,diagnosis2
  307.     jr dispdiagnosis
  308. dispdiag1:
  309.     ld de,diagnosis1            ;no room for vt100 stuff
  310.     ld a,1
  311.     ld (absnovt100),a
  312.     ld a,0
  313.     ld (vt100_on),a
  314.     jr dispdiagnosis
  315. dispdiag0:
  316.     ld de,diagnosis0             ;no room for anything
  317.     ld a,1
  318.     ld (absnowork),a
  319.     jr dispdiagnosis
  320.  
  321. dispdiagnosis:
  322.     ld hl,(PROGRAM_ADDR)
  323.     add hl,de               ;de from previous routines
  324.     ROM_CALL(D_ZM_STR)
  325.  
  326.     ld a,$FF
  327.     ld hl,$FD60
  328.     ld de,$FD61
  329.     ld (hl),a
  330.     ld bc,00015
  331.     ldir            ;this puts a horiz line
  332.  
  333.     CALL_(displaymenu)
  334.     ld hl,$3A05
  335.     ld ($8333),hl
  336.     ld hl,(PROGRAM_ADDR)
  337.     ld de,menuwords
  338.     add hl,de
  339.     ROM_CALL(D_ZM_STR)
  340.     ld a,$1E
  341.     ld ($8333),a
  342.     ROM_CALL(D_ZM_STR)
  343.     ld a,$38
  344.     ld ($8333),a
  345.     ROM_CALL(D_ZM_STR)
  346.     ld a,$51
  347.     ld ($8333),a
  348.     ROM_CALL(D_ZM_STR)
  349. beginkeys:
  350.     call GET_KEY
  351.     cp K_F1
  352.     JUMP_Z(intsetup)        ;start interrupts, analogous to starting terminal
  353.     cp K_F2
  354.     JUMP_Z(showkeys)
  355.     cp K_F3
  356.     JUMP_Z(showhelp)
  357.     cp K_EXIT
  358.     JUMP_Z(exittime)
  359.     cp K_F4
  360.     JUMP_Z(exittime)
  361.     jr beginkeys
  362.  
  363. nomemforbuffer:
  364.     pop hl
  365.     pop hl                  ;get extra things off stack
  366.     ld hl,$0000
  367.     ld (totallines),hl      ;less than enough room
  368.     JUMP_(dispbeginscreen)
  369.  
  370.  
  371.  
  372. exittime:
  373.     im 1
  374.     ret
  375.  
  376. showkeys:
  377.     CALL_(helpkeyscreen)
  378.     JUMP_(start)
  379.  
  380. showhelp:
  381.     CALL_(helpscreen)
  382.     JUMP_(start)
  383.  
  384. helpscreen:
  385.     CALL_(clearscreen)
  386.     ld hl,$0000
  387.     ld ($8333),hl
  388.     ld hl,(PROGRAM_ADDR)
  389.     ld de,helpaddress
  390.     add hl,de
  391.     ld b,6
  392. helpscreenloop:
  393.     ROM_CALL(D_ZM_STR)
  394.     push hl
  395.     ld hl,($8333)
  396.     ld a,7
  397.     add a,h
  398.     ld l,0
  399.     ld h,a
  400.     ld ($8333),hl
  401.     pop hl
  402.     djnz helpscreenloop
  403. helpscreenkeylop:
  404.     call GET_KEY
  405.     cp K_EXIT
  406.     ret z
  407.     jr helpscreenkeylop
  408.  
  409. helpkeyscreen:            
  410.     CALL_(clearscreen)
  411.     ld hl,$0000
  412.     ld ($8333),hl
  413.     ld hl,(PROGRAM_ADDR)
  414.     ld de,keyhelpwords
  415.     add hl,de
  416.     ld b,9
  417. helpkeyloop:
  418.     ROM_CALL(D_ZM_STR)
  419.     push hl
  420.     ld hl,($8333)
  421.     ld a,7
  422.     add a,h
  423.     ld l,0
  424.     ld h,a
  425.     ld ($8333),hl
  426.     pop hl
  427.     djnz helpkeyloop
  428. helpkeykeyloop:
  429.     call GET_KEY
  430.     cp K_EXIT
  431.     ret z
  432.     jr helpkeykeyloop
  433.  
  434. ;(----------Sets up the interrupt routines----------)
  435. ;(--------------------------------------------------)
  436. intsetup:
  437.     ld a,(absnowork)
  438.     bit 0,a
  439.     JUMP_NZ(beginkeys)
  440.     CALL_(clearscreen)          ;right after all that stuff is on the screen
  441.     ld a,$88              ;loads $8888
  442.     ld hl,$8700           ;into 256 bytes 
  443.     ld (hl),a             ;
  444.     ld de,$8701
  445.     ld bc,$00FF
  446.     ldir
  447.     ld hl,(PROGRAM_ADDR)  ;start of the program
  448.     ld de,introut           ;finds the routine sitting at the end
  449.     add hl,de             ; like that
  450.     ld de,$8888           ;and this is the place we want to load it.
  451.     ld bc,introutend+1-introut   ;finds the lentgh of the routine
  452.     ldir                  ;and puts it
  453.     ld a,$87              ;this is the place we want to jump in vector
  454.     ld i,a                ;register
  455.     im 2                  ;starts it up........
  456.  
  457.     ld a,10
  458.     ld (linestodisplay),a
  459.     CALL_(displayscreen)    ;and displsys the screen, which has nothing
  460.                             ;right now
  461.  
  462. ;(--------------------------Main Loop-------------------------)
  463. ;|This is the loop the program is in when it's not doing other|
  464. ;|things.  This loop manages the buffers, the keys, and the   |
  465. ;|port.                                                       |
  466. ;|Input: none                                                 |
  467. ;|Output: none                                                |
  468. ;(------------------------------------------------------------)
  469. mainloop:
  470.     CALL_(recievebyte)      ;this is the most important thing
  471.     or a
  472.     JUMP_NZ(putdatain)      ;jump to store it
  473.     ld a,(sendouthasdata)       ;you want to do these two before processdatabuff
  474.     or a                        ;because it can put stuff in these
  475.     JUMP_NZ(processsendout)
  476.     ld a,(dispouthasdata)
  477.     or a
  478.     JUMP_NZ(processdispout)
  479.     call GET_KEY            ;least important thing is the keypresses :(
  480.     or a
  481.     JUMP_NZ(loopitup)
  482.     ld a,(bufferhasdata)
  483.     or a
  484.     JUMP_NZ(processdatabuff)
  485.     jr mainloop             ;or go back to the main loop
  486.  
  487.  
  488. ;(--------------------------------------------------)
  489. ;|This small loop is here because the routine       |
  490. ;|putindatabuffer is called to, while mainloop jumps|
  491. ;|to everything, so you need this                   |
  492. ;|Input: a contains character to put                |
  493. ;|Output: none                                      |
  494. ;(--------------------------------------------------)
  495. putdatain:
  496.     CALL_(putindatabuffer)
  497.     JUMP_(mainloop)
  498.     
  499.  
  500. ;(----------------Puts data from port to buffer----------------)
  501. ;|Takes data just recieved from port and puts it into buffer   |
  502. ;|to be processed later                                        |
  503. ;|Input: a contains character to put in buffer                 |
  504. ;|Output: (bufferhasdata) is set because data was put in       |
  505. ;(-------------------------------------------------------------)
  506. putindatabuffer:
  507.     ld hl,(buffercursor)
  508.     ld (hl),a
  509.     ld de,(inputbufferend)
  510.     call CP_HL_DE
  511.     jr z,movetobeginning
  512.     inc hl
  513. putindatabuffer2:
  514.     ld (buffercursor),hl
  515.     ld a,$01
  516.     ld (bufferhasdata),a
  517.     ret
  518. movetobeginning:
  519.     ld hl,(inputbufferstart)
  520.     jr putindatabuffer2
  521.  
  522.  
  523. ;(---------------Processes data in buffer------------------)
  524. ;|Takes data in the buffer and acts on it if it's a vt100  |
  525. ;|command sequence, or it just puts it in another buffer to|
  526. ;|put it on the screen.  Changes variables of buffer if    |
  527. ;|necessary NOTE: only jumped to from mainloop:            |
  528. ;|Input: none  }                                           |
  529. ;|Output: none }just data management                       |
  530. ;(---------------------------------------------------------)
  531. processdatabuff:
  532.     ld hl,(beginbufferdata)
  533.     ld a,(hl)
  534.     cp $1B
  535.     CALL_Z(vt100time)
  536.     cp $0D
  537.     CALL_Z(changeCRLF_ifnec)
  538.     ld c,0
  539.     cp $00
  540.     CALL_NZ(putindispout)
  541.     ld hl,(beginbufferdata)
  542.     ld de,(inputbufferend)
  543.     call CP_HL_DE
  544.     jr z,movetobeginning2
  545.     inc hl
  546. processdatabuff2:
  547.     ld (beginbufferdata),hl
  548.     ld de,(buffercursor)
  549.     call CP_HL_DE
  550.     CALL_Z(nomoredata)
  551.     JUMP_(mainloop)
  552. nomoredata:
  553.     ld a,$00
  554.     ld (bufferhasdata),a
  555.     ;ld hl,(inputbufferstart)
  556.     ;ld (buffercursor),hl
  557.     ;ld (beginbufferdata),hl
  558.     ret
  559. movetobeginning2:
  560.     ld hl,(inputbufferstart)
  561.     jr processdatabuff2
  562.  
  563.  
  564.  
  565. ;(---------------------Change CR to CR/LF---------------)
  566. ;|This adds a LF ($0A) if a CR ($0D) is encountered     |
  567. ;|of course, only if necessary.  Puts both in buffer to |
  568. ;|display, or returns with a 0 in a to skip the loop    |
  569. ;|in mainloop.                                          |
  570. ;|Input: none                                           |
  571. ;|Output: a = 0 to skip the check in mainloop           |
  572. ;(------------------------------------------------------)
  573. changeCRLF_ifnec:
  574.     ld hl,inboundCRLF_on
  575.     bit 0,(hl)
  576.     jr z,changeCRLF2
  577.     ld hl,(PROGRAM_ADDR)
  578.     ld de,crlftable
  579.     add hl,de
  580.     ld c,2
  581.     CALL_(putindispout)
  582.     ld a,0
  583. changeCRLF2:
  584.     ret
  585.  
  586.  
  587.  
  588.  
  589. ;(-------------Puts data in buffer waiting to be sent out----------)
  590. ;|This takes strings or single chars and throws them in a buffer to|
  591. ;|wait to be sent out                                              |
  592. ;|Input: c = length of string; hl = pointer to string              |
  593. ;|      if c=0, then a contains single byte to put                 |
  594. ;|Output: puts in buffer, eventually to be put out link port       |
  595. ;(-----------------------------------------------------------------)
  596. putinsendout:           ;is called with address in hl, length in c
  597.     push af                 ;if c is zero, one byte to be sent is in a
  598.     ld a,c                  
  599.     ld de,sendoutbuffer
  600.     cp 0
  601.     jr z,onebytetosend
  602.     ld (sendouthasdata),a
  603.     pop af
  604.     ld b,0
  605.     ldir
  606.     ret
  607. onebytetosend:
  608.     ld a,1
  609.     ld (sendouthasdata),a
  610.     pop af
  611.     ld (de),a
  612.     ret
  613.  
  614. ;(-------------Sends out the stuff in the send out buffer---------)
  615. ;|This takes the first byte in the send out buffer and...sends it.|
  616. ;|Moves all the other waiting data down a byte                    |
  617. ;|Input: none                                                     |
  618. ;|Output: sends stuff finally through the link port               |
  619. ;(----------------------------------------------------------------)
  620. processsendout:
  621.     ld a,(sendoutbuffer)
  622.     CALL_(sendbyte)
  623.     ld hl,sendoutbuffer
  624.     push hl
  625.     pop de
  626.     inc hl
  627.     ld bc,00031
  628.     ldir
  629.     ld a,(sendouthasdata)
  630.     dec a
  631.     ld (sendouthasdata),a
  632.     JUMP_(mainloop)
  633.  
  634.  
  635. ;(-------------Puts data in buffer waiting to be displayed---------)
  636. ;|This takes strings or single chars and throws them in a buffer to|
  637. ;|wait to be displayed on the screen                               |
  638. ;|Input: c = length of string; hl = pointer to string              |
  639. ;|      if c=0, then a contains single byte to put                 |
  640. ;|Output: puts in buffer, eventually to be displayed on screen     |
  641. ;(-----------------------------------------------------------------)
  642. putindispout:           ;is called with address in hl, length in c
  643.     push af                 ;if c is zero, one byte to be sent is in a
  644.     ld a,c                      ;saves a
  645.     ld de,dispoutbuffer
  646.     cp 0
  647.     jr z,onebytetodisp
  648.     ld (dispouthasdata),a
  649.     pop af
  650.     ld b,0              ;c is still untouched
  651.     ldir
  652.     ret
  653. onebytetodisp:
  654.     ld a,1
  655.     ld (dispouthasdata),a
  656.     pop af
  657.     ld (de),a
  658.     ret
  659.  
  660. ;(-------------Displays the stuff in the display out buffer-----------)
  661. ;|This takes the first byte in the display out buffer and displays it.|
  662. ;|Moves all the other waiting data down a byte                        |
  663. ;|Input: none                                                         |
  664. ;|Output: Dislpays stuff finally on the screen                        |
  665. ;(--------------------------------------------------------------------)
  666. processdispout:
  667.     ld a,(dispoutbuffer)
  668.     CALL_(charinbuffer)
  669.     ld hl,dispoutbuffer
  670.     push hl
  671.     pop de
  672.     inc hl
  673.     ld bc,00031
  674.     ldir
  675.     ld a,(dispouthasdata)
  676.     dec a
  677.     ld (dispouthasdata),a
  678.     JUMP_(mainloop)
  679.  
  680.  
  681.  
  682. ;(--------------BIG KEY CHECK LOOP-------------------)
  683. ;|The biggest key check loop you'll ever find.  Jumps|
  684. ;|to many different places, which go back to mainloop|
  685. ;|eventually                                         |
  686. ;|Input: a contains the keypress                     |
  687. ;|Output: none                                       |
  688. ;(---------------------------------------------------)
  689. loopitup:
  690.     cp K_EXIT                   ;this exits after turning the interrupts off
  691.     JUMP_Z(timetogo)
  692.     cp K_RIGHT                  ;go to the scrollright routine
  693.     JUMP_Z(scrollright)
  694.     cp K_LEFT                   ;scrollleft
  695.     JUMP_Z(scrollleft)
  696.     cp K_DOWN
  697.     JUMP_Z(scrolldown)
  698.     cp K_UP
  699.     JUMP_Z(scrollup)
  700.     cp K_CUSTOM                 ;sets preferences
  701.     JUMP_Z(termprefs)
  702.     cp K_MORE                   ;extended chars
  703.     JUMP_Z(sendmorechars)
  704.     cp K_ENTER                  ;enter key
  705.     JUMP_Z(enterkey)
  706.     cp K_DEL                    ;del key
  707.     JUMP_Z(delkey)
  708.     cp K_CLEAR
  709.     JUMP_Z(clearscreenbuff)
  710.     cp K_GRAPH
  711.     JUMP_Z(refreshscreen)
  712.     cp K_STAT
  713.     JUMP_Z(dispthekeyscreen)
  714.     cp K_F1
  715.     JUMP_Z(putF1)
  716.     cp K_F2
  717.     JUMP_Z(putF2)
  718.     cp K_F3
  719.     JUMP_Z(putF3)
  720.     cp K_F4
  721.     JUMP_Z(putF4)
  722.     cp K_F5
  723.     JUMP_Z(putF5)
  724.     cp 0
  725.     JUMP_NZ(figure)
  726.     JUMP_(mainloop)
  727.  
  728. dispthekeyscreen:
  729.     im 1
  730.     CALL_(helpkeyscreen)
  731.     ld a,10
  732.     ld (linestodisplay),a
  733.     ld hl,(displaystart)
  734.     ld (currrow),hl
  735.     CALL_(clearscreen)
  736.     CALL_(displayscreen)
  737.     im 2
  738.     JUMP_(mainloop)
  739.  
  740.  
  741.  
  742. ;(----------------Clears the buffer----------------------)
  743. clearscreenbuff:
  744.     ld a,1
  745.     ld (startoverind),a
  746.     JUMP_(start)
  747.  
  748.  
  749.  
  750.  
  751. ;(--------------Refreshes the screen---------------------)
  752. ;|Displays the whole screen again, based on the variables|
  753. ;|but first clearing screen                              |
  754. ;|Input: none                                            |
  755. ;|Output: new clean screen!!!                            |
  756. ;(-------------------------------------------------------)
  757. refreshscreen:
  758.     ld hl,(displaystart)
  759.     ld (currrow),hl
  760.     ld a,10
  761.     ld (linestodisplay),a
  762.     CALL_(clearscreen)
  763.     CALL_(displayscreen)
  764.     JUMP_(mainloop)
  765.  
  766.  
  767. ;(---------Puts out the strings represented by F keys-----------)
  768. ;|When you press a F key, these are run, putting out the data   |
  769. ;|Input: none                                                   |
  770. ;|Output: puts string in sendoutbuffer and dispoutbuffer if nec.|
  771. ;(--------------------------------------------------------------)
  772. putF1:
  773.     ld a,0
  774.     CALL_(sendfunction)
  775.     JUMP_(mainloop)
  776. putF2:
  777.     ld a,22
  778.     CALL_(sendfunction)
  779.     JUMP_(mainloop)
  780. putF3:
  781.     ld a,44
  782.     CALL_(sendfunction)
  783.     JUMP_(mainloop)
  784. putF4:
  785.     ld a,66
  786.     CALL_(sendfunction)
  787.     JUMP_(mainloop)
  788. putF5:
  789.     ld a,88
  790.     CALL_(sendfunction)
  791.     JUMP_(mainloop)
  792.  
  793. ;(--------------The dirty stuff to manipulate the F keys----------)
  794. ;|Does the dirty work of figureing out the function and length    |
  795. ;|and the like                                                    |
  796. ;|Input: a contains relative address from the five functions above|
  797. ;|Output: stuff put in buffers                                    |
  798. ;(----------------------------------------------------------------)
  799. sendfunction:
  800.     ld e,a
  801.     ld d,0
  802.     ld hl,(PROGRAM_ADDR)
  803.     add hl,de
  804.     ld de,functionkeys
  805.     add hl,de
  806.     ld de,00021
  807.     add hl,de
  808.     ld c,(hl)    
  809.     ld a,c          ;no stuff there causes a problem
  810.     cp 0
  811.     ret z           ;so leave without doing anything
  812.     scf
  813.     ccf
  814.     sbc hl,de
  815.     inc hl          ;bypass the 20 at the beginning
  816.     push hl
  817.     push bc
  818.     CALL_(putinsendout)
  819.     pop bc
  820.     ld hl,localecho_on
  821.     bit 0,(hl)
  822.     pop hl
  823.     jr z,sendfunction2
  824.     CALL_(putindispout)       
  825. sendfunction2:
  826.     ret
  827.     
  828.     
  829. ;(-----------------Accesses more characters---------------)
  830. ;|Pops up that menu to get an extra 20 characters         |
  831. ;|Input: none                                             |
  832. ;|Output: puts the selected character in the buffers      |
  833. ;(--------------------------------------------------------)
  834. sendmorechars:
  835.     im 1
  836.     CALL_(morechars)            ;returns a with character
  837.     cp 0
  838.     JUMP_Z(sendmorechars2)
  839.     ld c,0
  840.     CALL_(putinsendout)
  841.     ld c,0
  842.     ld hl,localecho_on
  843.     bit 0,(hl)
  844.     jr z,sendmorechars2
  845.     CALL_(putindispout)
  846. sendmorechars2:
  847.     im 2
  848.     JUMP_(mainloop)
  849.  
  850.  
  851. ;*****************************
  852. ;*All sorts of routines for the vt100 stuff
  853.  
  854. vt100time:
  855.     ld hl,vt100_on  ;check for vt100
  856.     bit 0,(hl)      ;
  857.     jr z,vt100time2
  858.     ld de,(beginbufferdata)
  859.     ld hl,(buffercursor)
  860.     scf
  861.     ccf
  862.     sbc hl,de               ;hl left with length of stuff in buffer
  863.     dec hl
  864.     ld a,h
  865.     cp 0
  866.     CALL_NZ(makelarge)      ;whether it goes or not, l length of stuff
  867.     ld a,l                  ;now a length of stuff
  868.     ld hl,(PROGRAM_ADDR)
  869.     ld de,vt100table
  870.     add hl,de
  871. vt100time2:
  872.     push af             ;save the length through this loop
  873.     ld b,(hl)               ;cp length with length of command
  874.     ld a,$FF
  875.     cp b
  876.     jr z,vt100timeend
  877.     pop af
  878.     push af
  879.     sub b               ;subtract to see if greater than carry will be set if so
  880.     bit 7,a             ;check other way             <---------
  881.     JUMP_NZ(vt100time3)
  882.     inc hl
  883.     ld de,(beginbufferdata) ;de now caontains place in buffer
  884.     inc de          ;get past ESC
  885.                             ;hl contains vt100table     b contains length
  886.     push bc
  887.     CALL_(checkstring)
  888.     pop bc                  ;this is the length
  889.     jr z,vt100goaddress     ;hl left with pointer
  890.     inc hl
  891.     inc hl
  892.     ld a,(hl)
  893.     pop af              ;now it's needed chud for the next time through the loop
  894.     jr vt100time2
  895. vt100time3:
  896.     ld c,b
  897.     inc c           
  898.     ld b,0
  899.     add hl,bc               ;get it to the next command to check
  900.     inc hl
  901.     inc hl          ;pass the pointer
  902.     pop af          ;get the saved length for next time through loop
  903.     jr vt100time2
  904. vt100timeend:
  905.     pop af
  906.     pop hl              ;premature ending, (no command) get rid of return address
  907.     add a,$06         ;
  908.     bit 4,a
  909.     jr nz,vt100warning
  910.     JUMP_(mainloop)     ;and go back to mainloop
  911.  
  912. makelarge:
  913.     ld l,$FF
  914.     ret
  915.  
  916. vt100warning:
  917.     im 1
  918.     ld hl,$0000
  919.     ld ($800C),hl
  920.     ld hl,(PROGRAM_ADDR)
  921.     ld de,vt100helpmessage
  922.     add hl,de
  923.     ROM_CALL(D_ZT_STR)
  924.     ld hl,$0001
  925.     ld ($800C),hl
  926.     ld hl,(beginbufferdata)         ;this points to the faulty string
  927.     ld (hl),10                        ;get rid of ESC, puts the length there
  928.     ROM_CALL(D_LT_STR)
  929. warnkeys:
  930.     call GET_KEY
  931.     cp $00
  932.     jr z,warnkeys
  933.     ld a,0
  934.     ld (startoverind),a
  935.     JUMP_(start)                ;and might as well start over from beginning
  936.  
  937.  
  938.  
  939. vt100goaddress:
  940.     pop af              ;unneeded chud off stack
  941.     call LD_HL_MHL      ;hl is pointer to place to go
  942.     ex de,hl
  943.     ld hl,(PROGRAM_ADDR)
  944.     add hl,de
  945.     push bc        ;this saves the length, so we can erase the stuff when done
  946.     push hl         ;put it on stack
  947.     ret         ;ret goes to place on stack, removes it.
  948.  
  949. vt100timefinish:
  950.     pop bc                      ;b is length from the vt100table
  951.     ld c,b
  952.     ld b,0
  953.     ld hl,(beginbufferdata)
  954.     add hl,bc
  955.     ld (beginbufferdata),hl
  956.     ld a,0
  957.     ret
  958.  
  959. ;****The rest of this vt100 stuff is different routines that are called from
  960. ;****above, vt100goaddress, through thew location in the table at the bottom.
  961.  
  962. vt100cursorleft:
  963.     ld de,(beginbufferdata)
  964.     inc de
  965.     inc de
  966.     ld a,(de)
  967.     sub $30         ;unascii it
  968.     ld b,a
  969.     ld de,(endbuffer)           ;used later
  970.     ld hl,(cursoraddress)
  971.     jr vt100cursorleft2
  972.  
  973. vt100cursorleftlots:
  974.     ld de,(beginbufferdata)
  975.     inc de
  976.     inc de
  977.     ld a,(de)
  978.     sub $30
  979.     push de     ;\
  980.     ld de,00010 ; \
  981.     CALL_(mult) ;  |mult first digit by ten
  982.             ; /  left in l
  983.     pop de      ;/
  984.     inc de      ;\
  985.     ld a,(de)   ;}add next digit
  986.     sub $30     ;!!!!! unascii the stupid thing, always forget
  987.     add a,l     ;/
  988.     ld b,a
  989.     ld de,(endbuffer)
  990.     ld hl,(cursoraddress)    
  991. vt100cursorleft2:
  992.     call CP_HL_DE
  993.     jr z, vt100cursorleft22
  994.     dec hl
  995.     djnz vt100cursorleft2
  996. vt100cursorleft22:
  997.     ld (cursoraddress),hl
  998.     ld hl,(endbuffer)
  999.     ld (currrow),hl
  1000.     ld a,1
  1001.     ld (linestodisplay),a
  1002.     CALL_(displayscreen)
  1003.     JUMP_(vt100timefinish)
  1004.  
  1005. vt100cursorright:
  1006.     ld de,(beginbufferdata)
  1007.     inc de
  1008.     inc de
  1009.     ld a,(de)
  1010.     sub $30         ;unascii it
  1011.     ld b,a
  1012.     ld hl,00079
  1013.     ld de,(endbuffer)
  1014.     add hl,de
  1015.     ld de,(cursoraddress)
  1016.     ex de,hl
  1017.     jr vt100cursorright2
  1018.  
  1019. vt100cursorrightlots:
  1020.     ld de,(beginbufferdata)         ;no checking yet
  1021.     inc de
  1022.     inc de
  1023.     ld a,(de)
  1024.     sub $30
  1025.     push de     ;\
  1026.     ld de,00010 ; \
  1027.     CALL_(mult) ;  |mult first digit by ten
  1028.             ; /  left in l
  1029.     pop de      ;/
  1030.     inc de      ;\
  1031.     ld a,(de)   ;}add next digit
  1032.     sub $30     ;!!!!! unascii the stupid thing, always forget
  1033.     add a,l     ;/
  1034.     ld b,a
  1035.     ld de,(endbuffer)
  1036.     ld hl,00079
  1037.     add hl,de
  1038.     ex de,hl
  1039.     ld hl,(cursoraddress)
  1040.  
  1041. vt100cursorright2:
  1042.     call CP_HL_DE
  1043.     jr z, vt100cursorright22
  1044.     inc hl
  1045.     djnz vt100cursorright2
  1046. vt100cursorright22:
  1047.     ld (cursoraddress),hl
  1048.     ld hl,(endbuffer)
  1049.     ld (currrow),hl
  1050.     ld a,1
  1051.     ld (linestodisplay),a
  1052.     CALL_(displayscreen)
  1053.     JUMP_(vt100timefinish)
  1054.  
  1055. vt100cursorup:
  1056.     ld de,(beginbufferdata)
  1057.     inc de
  1058.     inc de
  1059.     ld a,(de)
  1060.     sub $30         ;unascii it
  1061.     ld b,a
  1062.     ld de,(startbuffer)
  1063.     ld hl,(endbuffer)
  1064.     ld ix,$0000
  1065.     jr vt100cursorup2
  1066.  
  1067. vt100cursoruplots:
  1068.     ld de,(beginbufferdata)         ;no checking yet
  1069.     inc de
  1070.     inc de
  1071.     ld a,(de)
  1072.     sub $30
  1073.     push de     ;\
  1074.     ld de,00010 ; \
  1075.     CALL_(mult) ;  |mult first digit by ten
  1076.             ; /  left in l
  1077.     pop de      ;/
  1078.     inc de      ;\
  1079.     ld a,(de)   ;}add next digit
  1080.     sub $30     ;!!!!! unascii the stupid thing, always forget
  1081.     add a,l     ;/
  1082.     ld b,a
  1083.     ld de,(startbuffer)
  1084.     ld hl,(endbuffer)
  1085.     ld ix,$0000 
  1086.  
  1087. vt100cursorup2:
  1088.     call CP_HL_DE
  1089.     jr z,vt100cursorup22
  1090.     push bc
  1091.     ld bc,00080
  1092.     scf
  1093.     ccf
  1094.     sbc hl,bc
  1095.     add ix,bc
  1096.     pop bc
  1097.     djnz vt100cursorup2
  1098. vt100cursorup22:
  1099.     ld (endbuffer),hl
  1100.     push ix
  1101.     pop bc
  1102.     ld hl,(cursoraddress)
  1103.     sbc hl,bc
  1104.     ld (cursoraddress),hl
  1105.     ld hl,(endbuffer)
  1106.     ld (currrow),hl
  1107.     ld a,1
  1108.     ld (linestodisplay),a
  1109.     CALL_(displayscreen)
  1110.     JUMP_(vt100timefinish)
  1111.  
  1112. vt100cursordown:
  1113.     ld de,(beginbufferdata)
  1114.     inc de
  1115.     inc de
  1116.     ld a,(de)
  1117.     sub $30         ;unascii it
  1118.     ld b,a
  1119.     jr vt100cursordown2
  1120.  
  1121. vt100cursordownlots:
  1122.     ld de,(beginbufferdata)   
  1123.     inc de
  1124.     inc de
  1125.     ld a,(de)
  1126.     sub $30
  1127.     push de     ;\
  1128.     ld de,00010 ; \
  1129.     CALL_(mult) ;  |mult first digit by ten
  1130.             ; /  left in l
  1131.     pop de      ;/
  1132.     inc de      ;\
  1133.     ld a,(de)   ;}add next digit
  1134.     sub $30     ;!!!!! unascii the stupid thing, always forget
  1135.     add a,l     ;/
  1136.     ld b,a
  1137.     
  1138. vt100cursordown2:           ;do I need the table???
  1139.     ld hl,(PROGRAM_ADDR)      ;check later
  1140.     ld de,lflftable
  1141.     add hl,de
  1142.     ld c,b
  1143.     CALL_(putindispout)
  1144.     JUMP_(vt100timefinish)
  1145.  
  1146.  
  1147.  
  1148.  
  1149. vt100storecoords:
  1150.     ld hl,(cursoraddress)
  1151.     ld (storedcoords),hl
  1152.     ld hl,(endbuffer)
  1153.     ld (storedline),hl
  1154.     JUMP_(vt100timefinish)
  1155.  
  1156. vt100restorecoords:
  1157.     ld hl,(storedcoords)
  1158.     ld (cursoraddress),hl
  1159.     ld hl,(storedline)
  1160.     ld (endbuffer),hl
  1161.     ld (currrow),hl
  1162.     ld a,1
  1163.     ld (linestodisplay),a
  1164.     CALL_(displayscreen)
  1165.     JUMP_(vt100timefinish)
  1166.  
  1167. vt100index:
  1168.     ld a,$0A
  1169.     ld c,0
  1170.     CALL_(putindispout)
  1171.     JUMP_(vt100timefinish)
  1172.  
  1173. vt100reverseindex:
  1174.     ld hl,(startbuffer)
  1175.     ex de,hl
  1176.     ld hl,(endbuffer)
  1177.     call CP_HL_DE
  1178.     jr z,vt100reverseindex2
  1179.     ld bc,00080
  1180.     scf
  1181.     ccf
  1182.     sbc hl,bc
  1183.     ld (endbuffer),hl
  1184.     ld hl,(cursoraddress)
  1185.     sbc hl,bc
  1186.     ld (cursoraddress),hl
  1187.     ld hl,(endbuffer)
  1188.     ld (currrow),hl
  1189.     ld a,1
  1190.     ld (linestodisplay),a
  1191.     CALL_(displayscreen)
  1192.     JUMP_(vt100timefinish)
  1193. vt100reverseindex2:
  1194.     ld de,(startbuffer)
  1195.     ld hl,(memend)
  1196.     scf
  1197.     ccf
  1198.     sbc hl,de
  1199.     push hl             ;amount for lddr
  1200.     ld hl,(memend)
  1201.     ld de,(memend)
  1202.     ld bc,00080
  1203.     add hl,bc
  1204.     dec hl
  1205.     dec de
  1206.     ex de,hl                ;hl = lower one move from     de = higher one move to
  1207.     pop bc
  1208.     lddr
  1209.     ld hl,(startbuffer)
  1210.     ld de,(startbuffer)
  1211.     inc de
  1212.     ld (hl),0
  1213.     ld bc,00079
  1214.     ldir
  1215.     CALL_(clearscreen)
  1216.     ld hl,(displaystart)
  1217.     ld (currrow),hl
  1218.     ld a,10
  1219.     ld (linestodisplay),a
  1220.     CALL_(displayscreen)
  1221.     JUMP_(vt100timefinish)
  1222.     
  1223. vt100nextline:
  1224.     ld hl,(PROGRAM_ADDR)
  1225.     ld de,crlftable
  1226.     add hl,de
  1227.     ld c,2
  1228.     CALL_(putindispout)
  1229.     JUMP_(vt100timefinish)
  1230.  
  1231. vt100eraseline:
  1232.     ld hl,(endbuffer)
  1233.     ld bc,00079
  1234.     ld de,(endbuffer)
  1235.     inc de
  1236.     ld (hl),$20
  1237.     ldir
  1238.     ld hl,(endbuffer)
  1239.     ld (currrow),hl
  1240.     ld a,1
  1241.     ld (linestodisplay),a
  1242.     CALL_(displayscreen)
  1243.     JUMP_(vt100timefinish)
  1244.  
  1245. vt100eraseendline:
  1246.     ld hl,(endbuffer)
  1247.     ld bc,00080
  1248.     add hl,bc
  1249.     ex de,hl
  1250.     ld hl,(cursoraddress)
  1251. vt100eraseendline2:
  1252.     call CP_HL_DE
  1253.     jr z,vt100eraseendline3
  1254.     ld (hl),$20
  1255.     inc hl
  1256.     jr vt100eraseendline2
  1257. vt100eraseendline3:
  1258.     ld hl,(endbuffer)
  1259.     ld (currrow),hl
  1260.     ld a,1
  1261.     ld (linestodisplay),a
  1262.     CALL_(displayscreen)
  1263.     JUMP_(vt100timefinish)
  1264.  
  1265. vt100erasecursor:
  1266.     ld hl,(endbuffer)
  1267.     ld de,(cursoraddress)
  1268. vt100erasecursor2:
  1269.     ld (hl),$20
  1270.     call CP_HL_DE
  1271.     jr z,vt100erasecursor3
  1272.     inc hl
  1273.     jr vt100erasecursor2
  1274. vt100erasecursor3:
  1275.     ld hl,(endbuffer)
  1276.     ld (currrow),hl
  1277.     ld a,1
  1278.     ld (linestodisplay),a
  1279.     CALL_(displayscreen)
  1280.     JUMP_(vt100timefinish)
  1281.  
  1282. vt100cursorstyle:
  1283.     ld hl,vt100charattrib
  1284.     ld de,(beginbufferdata)
  1285.     inc de
  1286. vt100cursorstyle2:
  1287.     inc de
  1288.     ld a,(de)
  1289.     cp 59                   ;equal to <cp ';'>
  1290.     jr z,vt100cursorstyle2
  1291.     cp 'm'
  1292.     JUMP_Z(vt100timefinish)
  1293.     cp '0'
  1294.     jr z,vtcursorstylenone
  1295.     cp '1'
  1296.     jr z,vtcursorstylebold
  1297.     cp '4'
  1298.     jr z,vtcursorstyle_score
  1299.     cp '5'
  1300.     jr z,vtcursorstyleblink
  1301.     cp '7'
  1302.     jr z,vtcursorstylereverse
  1303.     JUMP_(vt100timefinish)
  1304.  
  1305. vtcursorstylenone:
  1306.     ld (hl),0               ;hl is vt100charattrib
  1307.     jr vt100cursorstyle2
  1308. vtcursorstylebold:
  1309.     set 0,(hl)              ;bit 0 of hl is for bold
  1310.     jr vt100cursorstyle2
  1311. vtcursorstyle_score:
  1312.     set 1,(hl)
  1313.     jr vt100cursorstyle2
  1314. vtcursorstyleblink:
  1315.     set 2,(hl)
  1316.     jr vt100cursorstyle2
  1317. vtcursorstylereverse:
  1318.     set 3,(hl)
  1319.     jr vt100cursorstyle2
  1320.  
  1321. vt100settab:
  1322.     ld hl,(cursoraddress)
  1323.     ld de,(endbuffer)
  1324.     scf
  1325.     ccf
  1326.     sbc hl,de
  1327.     push hl
  1328.     ld c,l
  1329.     ld a,h
  1330.     ld de,00008
  1331.     CALL_(div)                          ;bytes to move in c
  1332.     pop hl
  1333.     ld a,l
  1334.     and $07         
  1335.     inc a
  1336.     ld b,a              ;byte counter to go through
  1337.     ld a,0
  1338.     scf
  1339. vt100settab2:
  1340.     rra                 ;%00000000 +C(1)    rotate right
  1341.     djnz vt100settab2
  1342.     ld b,0                  ;c is still untouched
  1343.     ld hl,(PROGRAM_ADDR)
  1344.     ld de,tabtable
  1345.     add hl,de
  1346.     add hl,bc                           ;place to add new tab
  1347.     or (hl)             ;hl contains pointer to tabtable, a contains new tab
  1348.     ld (hl),a          ;new tab has been put
  1349.     JUMP_(vt100timefinish)
  1350.  
  1351. vt100cleartab:
  1352.     ld hl,(cursoraddress)
  1353.     ld de,(endbuffer)
  1354.     scf
  1355.     ccf
  1356.     sbc hl,de
  1357.     push hl
  1358.     ld c,l
  1359.     ld a,h
  1360.     ld de,00008
  1361.     CALL_(div)
  1362.     pop hl
  1363.     ld a,l
  1364.     and $07
  1365.     inc a
  1366.     ld b,a
  1367.     ld a,0
  1368.     scf
  1369. vt100cleartab2:
  1370.     rra
  1371.     djnz vt100cleartab2
  1372.     ld b,0
  1373.     ld hl,(PROGRAM_ADDR)
  1374.     ld de,tabtable
  1375.     add hl,de
  1376.     add hl,bc
  1377.     cpl
  1378.     and (hl)
  1379.     ld (hl),a
  1380.     JUMP_(vt100timefinish)
  1381.  
  1382. vt100clearalltabs:
  1383.     ld hl,(PROGRAM_ADDR)
  1384.     ld de,tabtable
  1385.     add hl,de
  1386.     ld b,10
  1387. clearalltabsloop:
  1388.     ld (hl),0
  1389.     inc hl
  1390.     djnz clearalltabsloop
  1391.     dec hl
  1392.     set 0,(hl)
  1393.     JUMP_(vt100timefinish)
  1394.  
  1395. vt100statusrep:
  1396.     ld hl,(PROGRAM_ADDR)
  1397.     ld de,statusgood
  1398.     add hl,de
  1399.     ld c,4          ;length
  1400.     CALL_(putinsendout)
  1401.     JUMP_(vt100timefinish)
  1402.  
  1403. vt100whatareyou:
  1404.     ld hl,(PROGRAM_ADDR)
  1405.     ld de,whatareyou
  1406.     add hl,de
  1407.     ld c,7
  1408.     CALL_(putinsendout)
  1409.     JUMP_(vt100timefinish)
  1410.  
  1411. vt100cursorreport:
  1412.     ld ix,00006
  1413.     ld hl,(endbuffer)           ;throughout whole routine, ix contains counter
  1414.     ld de,(firstline)
  1415.     scf
  1416.     ccf
  1417.     sbc hl,de
  1418.     ld a,h
  1419.     ld c,l
  1420.     ld de,00080
  1421.     CALL_(div)              ;out in ac
  1422.     ld a,c
  1423.     inc a
  1424.  
  1425.     ld hl,(PROGRAM_ADDR)
  1426.     ld de,cursorresponse
  1427.     add hl,de
  1428.     inc hl
  1429.     inc hl
  1430.     CALL_(putasciivalue)
  1431.     ld (hl),59              ;this is ;
  1432.     inc hl
  1433.     push hl
  1434.  
  1435.     ld hl,(cursoraddress)
  1436.     ld de,(endbuffer)
  1437.     scf
  1438.     ccf
  1439.     sbc hl,de
  1440.     ld a,l
  1441.     inc a
  1442.     pop hl          ;from stack after last putasciivalue
  1443.     CALL_(putasciivalue)
  1444.     ld (hl),82              ;this is R
  1445.  
  1446.     ld hl,(PROGRAM_ADDR)
  1447.     ld de,cursorresponse
  1448.     add hl,de
  1449.     push ix
  1450.     pop bc
  1451.     CALL_(putinsendout)
  1452.     JUMP_(vt100timefinish)
  1453.  
  1454. putasciivalue:              ;asciiizes the value in a  and put it in the place pointed to
  1455.                         ;by hl(cursorresponse)
  1456.     push af
  1457.     ld c,a
  1458.     ld a,0
  1459.     ld de,00010         ;divide by 10
  1460.     push hl
  1461.     CALL_(div)          ;ac/de=ac
  1462.     pop hl
  1463.     cp c                ;a will definitely be 0, because the most in ac would be 8
  1464.                         ;so this will see if c is zero
  1465.     jr nz,putasciivalue2
  1466.     pop af
  1467.     add a,$30
  1468.     ld (hl),a
  1469.     inc hl
  1470.     ret
  1471.     
  1472. putasciivalue2:
  1473.     inc ix
  1474.     pop af
  1475.     push hl
  1476.     ld l,a
  1477.     ld h,0
  1478.     call UNPACK_HL
  1479.     add a,$30
  1480.     ld b,a
  1481.     call UNPACK_HL
  1482.     add a,$30
  1483.     pop hl
  1484.     ld (hl),a
  1485.     inc hl
  1486.     ld (hl),b
  1487.     inc hl
  1488.     ret
  1489.  
  1490.     
  1491.  
  1492. vt100reset:                 ;this is a hard reset, so I checked how many pushes
  1493.     pop hl                ;there were, get them out first
  1494.     pop hl
  1495.     im 1                           ;always redo this when add new stuff!!!!!!!
  1496.     ld a,1
  1497.     ld (startoverind),a
  1498.     JUMP_(start)
  1499.  
  1500. vt100changecursor:
  1501.     ld de,(beginbufferdata)
  1502.     inc de
  1503.     inc de
  1504.     CALL_(vt100changesmall)
  1505.     ld b,a
  1506.     inc de
  1507.     inc de
  1508.     CALL_(vt100changesmall)
  1509.     ld c,a          ;row in b, column in c
  1510.     jr vt100changecur2
  1511.  
  1512. vt100changeud:      ;for cursor-up-down
  1513.     ld de,(beginbufferdata)
  1514.     inc de
  1515.     inc de
  1516.     CALL_(vt100changebig)
  1517.     ld b,a                  ;don't need 'push bc's' because don't have changebig later
  1518.     inc de
  1519.     inc de
  1520.     CALL_(vt100changesmall)
  1521.     ld c,a
  1522.     jr vt100changecur2
  1523.  
  1524. vt100changelr:
  1525.     ld de,(beginbufferdata)
  1526.     inc de
  1527.     inc de
  1528.     CALL_(vt100changesmall)
  1529.     ld b,a
  1530.     push bc
  1531.     inc de
  1532.     inc de
  1533.     CALL_(vt100changebig)
  1534.     pop bc
  1535.     ld c,a
  1536.     jr vt100changecur2
  1537.  
  1538. vt100changeudlr:
  1539.     ld de,(beginbufferdata)
  1540.     inc de
  1541.     inc de
  1542.     CALL_(vt100changebig)
  1543.     ld b,a
  1544.     push bc
  1545.     inc de
  1546.     inc de
  1547.     CALL_(vt100changebig)
  1548.     pop bc
  1549.     ld c,a
  1550.     jr vt100changecur2
  1551.  
  1552. vt100changebig:
  1553.     ld a,(de)
  1554.     sub $30
  1555.     push de
  1556.     ld de,00010
  1557.     CALL_(mult)
  1558.     pop de
  1559.     inc de
  1560.     ld a,(de)
  1561.     sub $30
  1562.     add a,l
  1563.     ret
  1564.  
  1565. vt100changesmall:
  1566.     ld a,(de)
  1567.     sub $30
  1568.     ret
  1569.  
  1570.  
  1571. vt100changecur2:
  1572.     ld a,20
  1573.     sub b
  1574.     CALL_C(vt100changefit)
  1575.     ld a,b
  1576.     dec a
  1577.     ld de,00080
  1578.     CALL_(mult)             ;hl gives it out
  1579.     ld de,(firstline)
  1580.     add hl,de
  1581.     ld (endbuffer),hl
  1582.     ld a,80
  1583.     sub c
  1584.     CALL_C(vt100changefit2)
  1585.     ld b,0          ;c with column
  1586.     dec c           ;so starts on zero
  1587.     add hl,bc
  1588.     ld (cursoraddress),hl
  1589.     ld hl,(endbuffer)
  1590.     ld (currrow),hl
  1591.     ld a,1
  1592.     ld (linestodisplay),a
  1593.     CALL_(displayscreen)
  1594.     JUMP_(vt100timefinish)
  1595.  
  1596. vt100changefit:
  1597.     ld b,20
  1598.     ret
  1599. vt100changefit2:            ;add this soon
  1600.     ld c,1
  1601.     ret
  1602.  
  1603.  
  1604. vt100entirescreen:
  1605.     ld hl,(firstline)
  1606.     ld bc,01599
  1607.     push hl
  1608.     pop de
  1609.     inc de
  1610.     ld a,0
  1611.     ld (hl),a
  1612.     ldir
  1613.     CALL_(clearscreen)
  1614.     ld hl,(displaystart)
  1615.     ld (currrow),hl
  1616.     ld a,10
  1617.     ld (linestodisplay),a
  1618.     CALL_(displayscreen)
  1619.     JUMP_(vt100timefinish)
  1620.  
  1621. vt100erasebegcursor:
  1622.     ld de,(firstline)
  1623.     ld hl,(cursoraddress)
  1624.     scf
  1625.     ccf
  1626.     sbc hl,de
  1627.     push hl
  1628.     pop bc
  1629.     ld hl,(firstline)
  1630.     push hl
  1631.     pop de
  1632.     inc de
  1633.     ld a,0
  1634.     ld (hl),a
  1635.     ldir
  1636.     CALL_(clearscreen)
  1637.     ld hl,(displaystart)
  1638.     ld (currrow),hl
  1639.     ld a,10
  1640.     ld (linestodisplay),a
  1641.     CALL_(displayscreen)
  1642.     JUMP_(vt100timefinish)
  1643.  
  1644. vt100erasecursorend:
  1645.     ld hl,(lastline)
  1646.     ld de,00079
  1647.     add hl,de
  1648.     ld de,(cursoraddress)
  1649.     scf
  1650.     ccf
  1651.     sbc hl,de
  1652.     push hl
  1653.     pop bc
  1654.     ld hl,(cursoraddress)
  1655.     push hl
  1656.     pop de
  1657.     inc de
  1658.     ld a,0
  1659.     ld (hl),a
  1660.     ldir
  1661.     CALL_(clearscreen)
  1662.     ld hl,(displaystart)
  1663.     ld (currrow),hl
  1664.     ld a,10
  1665.     ld (linestodisplay),a
  1666.     CALL_(displayscreen)
  1667.     JUMP_(vt100timefinish)
  1668.  
  1669.  
  1670.  
  1671. vt100setscrolling:
  1672.     ld de,(beginbufferdata)
  1673.     inc de
  1674.     inc de
  1675.     CALL_(scrollingsmall)
  1676.     ld (firstscroll),hl
  1677.     inc de
  1678.     CALL_(scrollingsmall)
  1679.     ld (lastscroll),hl
  1680.     JUMP_(vt100timefinish)
  1681.  
  1682. vt100setscrollingt:
  1683.     ld de,(beginbufferdata)
  1684.     inc de
  1685.     inc de
  1686.     CALL_(scrollingbig)
  1687.     ld (firstscroll),hl
  1688.     inc de
  1689.     CALL_(scrollingsmall)
  1690.     ld (lastscroll),hl
  1691.     JUMP_(vt100timefinish)
  1692.  
  1693. vt100setscrollingb:
  1694.     ld de,(beginbufferdata)
  1695.     inc de
  1696.     inc de
  1697.     CALL_(scrollingsmall)
  1698.     ld (firstscroll),hl
  1699.     inc de
  1700.     CALL_(scrollingbig)
  1701.     ld (lastscroll),hl
  1702.     JUMP_(vt100timefinish)
  1703.  
  1704. vt100setscrollingtb:
  1705.     ld de,(beginbufferdata)
  1706.     inc de
  1707.     inc de
  1708.     CALL_(scrollingbig)
  1709.     ld (firstscroll),hl
  1710.     inc de
  1711.     CALL_(scrollingbig)
  1712.     ld (lastscroll),hl
  1713.     JUMP_(vt100timefinish)
  1714.  
  1715. scrollingsmall:
  1716.     ld a,(de)
  1717.     push de
  1718.     dec a
  1719.     sub $30
  1720.     ld de,00080
  1721.     CALL_(mult)
  1722.     ld de,(firstline)
  1723.     add hl,de
  1724.     pop de
  1725.     inc de
  1726.     ret
  1727.  
  1728. scrollingbig:
  1729.     ld a,(de)
  1730.     push de
  1731.     sub $30
  1732.     ld de,00010
  1733.     CALL_(mult)
  1734.     pop de
  1735.     inc de
  1736.     push de
  1737.     ld a,(de)
  1738.     sub $30
  1739.     add a,l
  1740.     dec a
  1741.     ld de,00080
  1742.     CALL_(mult)
  1743.     ld de,(firstline)
  1744.     add hl,de
  1745.     pop de
  1746.     inc de
  1747.     ret
  1748.  
  1749.  
  1750.  
  1751. ;(---------------------Scrolls the desired direction----------------------)
  1752. ;|These four routines are jumped to from the main key loop, and do their  |
  1753. ;|thing on the screen, then jump back to the beginning of mainloop        |
  1754. ;|Input: nothing                                                          |
  1755. ;|Output: moves the screen the desired direction                          |
  1756. ;(------------------------------------------------------------------------)
  1757. scrollright:                
  1758.     ld a,(displaycolumn)    
  1759.     cp 60
  1760.     JUMP_Z(mainloop)
  1761.     ld b,6
  1762.     add a,b
  1763.     ld (displaycolumn),a
  1764.     ld hl,(displaystart)
  1765.     ld (currrow),hl
  1766.     ld a,10
  1767.     ld (linestodisplay),a
  1768.     CALL_(clearscreen)
  1769.     CALL_(displayscreen)
  1770.     JUMP_(mainloop)
  1771. scrollleft:
  1772.     ld a,(displaycolumn)
  1773.     cp 0
  1774.     JUMP_Z(mainloop)
  1775.     ld b,-6
  1776.     add a,b
  1777.     ld (displaycolumn),a
  1778.     ld hl,(displaystart)
  1779.     ld (currrow),hl
  1780.     ld a,10
  1781.     ld (linestodisplay),a
  1782.     CALL_(clearscreen)
  1783.     CALL_(displayscreen)
  1784.     JUMP_(mainloop)
  1785. scrolldown:
  1786.     ld hl,(realendbuffer)
  1787.     ld de,00720
  1788.     scf
  1789.     ccf
  1790.     sbc hl,de
  1791.     ld de,(displaystart)
  1792.     ex de,hl
  1793.     call CP_HL_DE
  1794.     JUMP_Z(mainloop)
  1795.     ld de,$0050
  1796.     add hl,de
  1797.     ld (displaystart),hl
  1798.     ld hl,(displaystart)
  1799.     ld (currrow),hl
  1800.     ld a,10
  1801.     ld (linestodisplay),a
  1802.     CALL_(clearscreen)
  1803.     CALL_(displayscreen)
  1804.     JUMP_(mainloop)
  1805. scrollup:
  1806.     ld hl,(displaystart)
  1807.     ld de,(startbuffer)
  1808.     call CP_HL_DE
  1809.     JUMP_Z(mainloop)
  1810.     ld de,$0050
  1811.     sbc hl,de
  1812.     ld (displaystart),hl
  1813.     ld hl,(displaystart)
  1814.     ld (currrow),hl
  1815.     ld a,10
  1816.     ld (linestodisplay),a
  1817.     CALL_(clearscreen)
  1818.     CALL_(displayscreen)
  1819.     JUMP_(mainloop)
  1820.  
  1821. ;(-----------------------Exit routine-----------------------------------)
  1822. ;|This routine is jumped to and exits the program, first clearing the   |
  1823. ;|memory that was overwritten                                           |
  1824. ;|Input: nothing                                                        |
  1825. ;|Output: goes back to title                                            |
  1826. ;(----------------------------------------------------------------------)
  1827. timetogo:
  1828.     im 1
  1829.     ld a,0
  1830.     ld (startoverind),a
  1831.     JUMP_(start)
  1832.  
  1833. ;(------------------Get more chars from the menu--------------------------)
  1834. ;|This routine lets you pick one of the 20 characters not accesible on the|
  1835. ;|TI-85 keyboard.  It saves the bottom portion of the screen it writes    |
  1836. ;|over, and then restores it when done.                                   |
  1837. ;|Input: nothing                                                          |
  1838. ;|Output: a has character from menu, 0 if none                            |
  1839. ;(------------------------------------------------------------------------)
  1840. morechars:
  1841.     CALL_(savebottom)
  1842.     ld hl,(PROGRAM_ADDR)
  1843.     ld de,chartable
  1844.     add hl,de
  1845.     ld (currentmenu),hl
  1846.     CALL_(dispmenu)
  1847. morechars2:
  1848.     CALL_(recievebyte)          ;this is the routine to 
  1849.     cp 0
  1850.     CALL_NZ(putindatabuffer)
  1851.     call GET_KEY
  1852.     cp K_MORE
  1853.     jr z,changemenu
  1854.     cp K_F1
  1855.     JUMP_Z(takeF1)
  1856.     cp K_F2
  1857.     JUMP_Z(takeF2)
  1858.     cp K_F3
  1859.     JUMP_Z(takeF3)
  1860.     cp K_F4
  1861.     JUMP_Z(takeF4)
  1862.     cp K_F5
  1863.     JUMP_Z(takeF5)
  1864.     cp K_EXIT
  1865.     jr nz,morechars2
  1866.     ld a,0                  ;didn't get any char
  1867. morechars3:
  1868.     CALL_(restorebottom)
  1869.     ret
  1870. ;(--------------All part of the previous subroutine--------)
  1871. changemenu:
  1872.     ld hl,(PROGRAM_ADDR)
  1873.     ld de,chartable4
  1874.     add hl,de
  1875.     ex de,hl
  1876.     ld hl,(currentmenu)
  1877.     call CP_HL_DE
  1878.     jr z,changemenu2
  1879.     ld bc,00022
  1880.     add hl,bc
  1881.     JUMP_(changemenu3)
  1882. changemenu2:
  1883.     ld hl,(PROGRAM_ADDR)
  1884.     ld de,chartable
  1885.     add hl,de
  1886. changemenu3:
  1887.     ld (currentmenu),hl
  1888.     CALL_(dispmenu)
  1889.     JUMP_(morechars2)
  1890. ;(--------------All part of the previous subroutine--------)
  1891. takeF1:
  1892.     ld a,1
  1893.     jr takeitaway
  1894. takeF2:
  1895.     ld a,5
  1896.     jr takeitaway
  1897. takeF3:
  1898.     ld a,9
  1899.     jr takeitaway
  1900. takeF4:
  1901.     ld a,13
  1902.     jr takeitaway
  1903. takeF5:
  1904.     ld a,17
  1905.     jr takeitaway
  1906. takeitaway:
  1907.     ld hl,(currentmenu)
  1908.     ld c,a
  1909.     ld b,0
  1910.     add hl,bc
  1911.     ld a,(hl)               ;the char is in a
  1912.     JUMP_(morechars3)               
  1913. ;(--------------All part of the previous subroutine--------)
  1914. dispmenu:
  1915.     CALL_(clearbottom)
  1916.     CALL_(displaymenu)
  1917.     ld a,58
  1918.     ld ($8334),a
  1919.     ld hl,(currentmenu)
  1920.     ld b,5
  1921. dispmenu2:
  1922.     ld a,(hl)
  1923.     ld ($8333),a
  1924.     inc hl
  1925.     inc hl
  1926.     ROM_CALL(D_ZM_STR)
  1927.     djnz dispmenu2
  1928.     ret
  1929.  
  1930.  
  1931. ;(---------------Display the preferences screen-------------)
  1932. ;|Displays the screen, does all the work, changes things    |
  1933. ;|lets you change function keys                             |
  1934. ;|Input: none                                               |
  1935. ;|Output: changes the preferences, duhh...                  |
  1936. ;(----------------------------------------------------------)
  1937. termprefs:
  1938.     im 1
  1939.     CALL_(clearscreen)
  1940.     ld de,$0500
  1941.     ld ($800C),de
  1942.     ld hl,(PROGRAM_ADDR)
  1943.     ld de,prefwords
  1944.     add hl,de
  1945.     set 3,(IY+05)
  1946.     ROM_CALL(D_ZT_STR)
  1947.     res 3,(IY+05)
  1948.     ld de,$0002
  1949.     ld ($800C),de
  1950.     ld a,8
  1951. prefsloop:
  1952.     ROM_CALL(D_ZT_STR)
  1953.     inc e
  1954.     ld ($800C),de
  1955.     cp e
  1956.     jr nz,prefsloop
  1957.     ld hl,vt100_on
  1958.     ld de,$0102
  1959.     ld ($800C),de
  1960.     ld a,7
  1961. prefsloop2:
  1962.     bit 0,(hl)
  1963.     CALL_NZ(option_on)
  1964.     inc hl
  1965.     inc e
  1966.     ld ($800C),de
  1967.     cp e
  1968.     jr nz,prefsloop2
  1969.     ld hl,vt100_on
  1970.     ld (currentpref),hl
  1971.     ld hl,$0002
  1972.     ld ($800C),hl
  1973.     ld a,5
  1974.     ROM_CALL(TR_CHARPUT)
  1975.     jr keytime
  1976. option_on:
  1977.     push af
  1978.     ld a,0
  1979.     ROM_CALL(TR_CHARPUT)
  1980.     pop af
  1981.     ret
  1982. ;(--------------All part of the previous subroutine--------)
  1983. keytime:
  1984.     CALL_(recievebyte)          ;this is the routine to 
  1985.     cp 0
  1986.     CALL_NZ(putindatabuffer)
  1987.     call GET_KEY
  1988.     cp K_DOWN
  1989.     jr z,downprefs
  1990.     cp K_UP
  1991.     jr z,upprefs
  1992.     cp K_SECOND
  1993.     JUMP_Z(changepref)
  1994.     cp K_EXIT
  1995.     jr nz,keytime
  1996. go_from_prefs:              ;last piece of code before returns
  1997.     ld hl,(PROGRAM_ADDR)
  1998.     ld de,savedprefs
  1999.     add hl,de
  2000.     ld de,vt100_on
  2001.     ex de,hl
  2002.     ld bc,00005
  2003.     ldir
  2004.     CALL_(clearscreen)
  2005.     ld hl,(displaystart)
  2006.     ld (currrow),hl
  2007.     ld a,10
  2008.     ld (linestodisplay),a
  2009.     CALL_(displayscreen)
  2010.     im 2
  2011.     JUMP_(mainloop)
  2012. ;(--------------All part of the previous subroutine--------)
  2013. downprefs:
  2014.     ld hl,(currentpref)
  2015.     ld de,splitscreen_on+1
  2016.     call CP_HL_DE
  2017.     jr z,keytime
  2018.     inc hl
  2019.     ld (currentpref),hl
  2020.     ld a,$20
  2021.     ROM_CALL(TR_CHARPUT)
  2022.     ld hl,($800C)
  2023.     inc l
  2024.     ld ($800C),hl
  2025.     push hl
  2026.     ld a,5
  2027.     ROM_CALL(TR_CHARPUT)
  2028.     pop hl
  2029.     ld ($800C),hl
  2030.     JUMP_(keytime)
  2031. upprefs:
  2032.     ld hl,(currentpref)
  2033.     ld de,vt100_on
  2034.     call CP_HL_DE
  2035.     JUMP_Z(keytime)
  2036.     dec hl
  2037.     ld (currentpref),hl
  2038.     ld a,$20
  2039.     ROM_CALL(TR_CHARPUT)
  2040.     ld hl,($800C)
  2041.     dec l
  2042.     ld ($800C),hl
  2043.     push hl
  2044.     ld a,5
  2045.     ROM_CALL(TR_CHARPUT)
  2046.     pop hl
  2047.     ld ($800C),hl
  2048.     JUMP_(keytime)
  2049. ;(--------------All part of the previous subroutine--------)
  2050. changepref:
  2051.     ld hl,(currentpref)
  2052.     ld c,l
  2053.     ld b,h
  2054.     ld de,vt100_on
  2055.     ld a,l
  2056.     sub e                   ;a now equals 0-5
  2057.     ld hl,absnovt100
  2058.     sub (hl)                    ;subtract this indicator from a
  2059.     JUMP_C(keytime)             ;a was zero before, which means it's on vt100
  2060.                             ;if one was subtracted, that means NO VT100 allowed, which means 
  2061.                             ;went past 0, which set carry flag, so jump
  2062.     ld l,c
  2063.     ld h,b
  2064.     ld de,splitscreen_on+1
  2065.     call CP_HL_DE
  2066.     jr z,setfunctionkeys
  2067.     bit 0,(hl)
  2068.     jr z,turnon
  2069.     jr turnoff
  2070. changepref2:
  2071.     ROM_CALL(TR_CHARPUT)
  2072.     dec h
  2073.     ld ($800C),hl
  2074.     JUMP_(keytime)
  2075. turnoff:
  2076.     res 0,(hl)
  2077.     ld hl,($800C)
  2078.     inc h
  2079.     ld ($800C),hl
  2080.     ld a,$20
  2081.     JUMP_(changepref2)
  2082. turnon:
  2083.     set 0,(hl)
  2084.     ld hl,($800C)
  2085.     inc h
  2086.     ld ($800C),hl
  2087.     ld a,0
  2088.     JUMP_(changepref2)
  2089.  
  2090.  
  2091. ;(----------------Lets you change functionkeys----------)
  2092. ;|Changes screen, enters them, morechars, del           |
  2093. ;|Input: none                                           |
  2094. ;|Output: changes the function keys if changed          |
  2095. ;(------------------------------------------------------)
  2096. setfunctionkeys:
  2097.     CALL_(dispfunctionkeys)
  2098. setkeyloop:
  2099.     CALL_(recievebyte)          ;this is the routine to 
  2100.     cp 0
  2101.     CALL_NZ(putindatabuffer)
  2102.     call GET_KEY
  2103.     cp K_EXIT
  2104.     JUMP_Z(go_from_prefs)
  2105.     cp K_F1
  2106.     JUMP_Z(changeF1)
  2107.     cp K_F2
  2108.     JUMP_Z(changeF2)
  2109.     cp K_F3
  2110.     JUMP_Z(changeF3)
  2111.     cp K_F4
  2112.     JUMP_Z(changeF4)
  2113.     cp K_F5
  2114.     JUMP_Z(changeF5)
  2115.     jr setkeyloop
  2116. ;(--------------All part of the previous subroutine--------)
  2117. ;(----------------Displays the screen for it---------------)
  2118. dispfunctionkeys:
  2119.     CALL_(clearscreen)
  2120.     ld hl,$0400
  2121.     ld ($800C),hl
  2122.     ld hl,(PROGRAM_ADDR)
  2123.     ld de,funckeywords
  2124.     add hl,de
  2125.     set 3,(IY+05)
  2126.     ROM_CALL(D_ZT_STR)
  2127.     ld hl,$0002
  2128.     ld ($800C),hl
  2129.     ld a,'1'
  2130.     ld b,5
  2131. dispnumbers:
  2132.     ROM_CALL(TR_CHARPUT)
  2133.     inc a
  2134.     inc l
  2135.     ld ($800C),hl
  2136.     djnz dispnumbers
  2137.     res 3,(IY+05)
  2138.     ld hl,$0102
  2139.     ld ($800C),hl
  2140.     ld hl,(PROGRAM_ADDR)
  2141.     ld de,functionkeys
  2142.     add hl,de
  2143.     ld b,5
  2144. dispwords:
  2145.     push bc
  2146.     ROM_CALL(D_LT_STR)
  2147.     pop bc
  2148.     inc hl              ;get pst the lentgh terminator at end
  2149.     push hl
  2150.     ld hl,($800C)
  2151.     inc h
  2152.     ld ($800C),hl
  2153.     pop hl
  2154.     djnz dispwords
  2155.     ld hl,$0007
  2156.     ld ($800C),hl
  2157.     ld hl,(PROGRAM_ADDR)
  2158.     ld de,funckeywords2
  2159.     add hl,de
  2160.     ROM_CALL(D_ZT_STR)
  2161.     ret
  2162. ;(--------------All part of the previous subroutine--------)
  2163. changeF1:
  2164.     ld a,0
  2165.     jr changeFkeys
  2166. changeF2:
  2167.     ld a,22
  2168.     jr changeFkeys
  2169. changeF3:
  2170.     ld a,44
  2171.     jr changeFkeys
  2172. changeF4:
  2173.     ld a,66
  2174.     jr changeFkeys
  2175. changeF5:
  2176.     ld a,88
  2177.     jr changeFkeys
  2178. changeFkeys:
  2179.     ld hl,(cursorstate)
  2180.     ld e,l
  2181.     ld l,h
  2182.     ld h,e
  2183.     ld (cursorstate),hl
  2184.     CALL_(enternewfunc)
  2185.     ld hl,(cursorstate)
  2186.     ld e,l
  2187.     ld l,h
  2188.     ld h,e
  2189.     ld (cursorstate),hl
  2190.     JUMP_(setfunctionkeys)
  2191. ;(--------------All part of the previous subroutine--------)
  2192. ;|This deals with after the beginning screen, and you've   |
  2193. ;|picked the function to edit                              |
  2194. ;(---------------------------------------------------------)
  2195. enternewfunc:
  2196.     CALL_(clearscreen)
  2197.     ld hl,(PROGRAM_ADDR)
  2198.     ld de,functionkeys
  2199.     add hl,de
  2200.     ld e,a
  2201.     ld d,0
  2202.     add hl,de
  2203.     ld (Fkeyaddress),hl
  2204.     ld a,0
  2205.     ld (Fkeycursor),a
  2206.     ld hl,$0000
  2207.     ld ($800C),hl
  2208.     ld hl,(Fkeyaddress)
  2209.     ROM_CALL(D_LT_STR)
  2210.     ld hl,$0101
  2211.     ld ($800C),hl
  2212.     ld hl,(PROGRAM_ADDR)
  2213.     ld de,funckeywords3
  2214.     add hl,de
  2215.     ROM_CALL(D_ZT_STR)
  2216.     ld hl,(Fkeyaddress)
  2217.     inc hl          ;this bypasses the 20 at the brginning
  2218.     ld b,20
  2219. clearlooper:
  2220.     ld (hl),$20
  2221.     inc hl
  2222.     djnz clearlooper
  2223. Fkeykeyloop:
  2224.     CALL_(recievebyte)          ;this is the routine to 
  2225.     cp 0
  2226.     CALL_NZ(putindatabuffer)
  2227.     call GET_KEY
  2228.     cp K_EXIT
  2229.     JUMP_Z(Fkeyenterdone)
  2230.     cp K_MORE
  2231.     JUMP_Z(Fkeymorechars)
  2232.     cp K_DEL
  2233.     JUMP_Z(Fkeydel)
  2234.     cp K_ENTER
  2235.     JUMP_Z(Fkeyenterdone)
  2236.     cp 0
  2237.     JUMP_NZ(Fkeyfigure)
  2238.     jr Fkeykeyloop
  2239. ;(--------------All part of the previous subroutine--------)
  2240. Fkeyenterdone:
  2241.     ld hl,(Fkeyaddress)
  2242.     ld de,00021
  2243.     add hl,de
  2244.     ld a,(Fkeycursor)
  2245.     ld (hl),a
  2246.     ret
  2247. Fkeyfigure:
  2248.     ld l,a
  2249.     ld a,(cursorstate)
  2250.     cp $02
  2251.     CALL_Z(bigalphamode)
  2252.     cp $03
  2253.     CALL_Z(smallalphamode)
  2254.     cp $00
  2255.     CALL_Z(normmode)
  2256.     cp $01
  2257.     CALL_Z(secondmode)
  2258.     ld a,l                      ;all the modes return the value in l
  2259.     cp 0
  2260.     JUMP_Z(Fkeyfigure2)
  2261.     CALL_(loadFkeychar)
  2262. Fkeyfigure2:
  2263.     JUMP_(Fkeykeyloop)
  2264. Fkeymorechars:
  2265.     CALL_(morechars)
  2266.     cp 0
  2267.     CALL_NZ(loadFkeychar)
  2268.     JUMP_(Fkeykeyloop)
  2269. Fkeydel:
  2270.     ld a,(Fkeycursor)
  2271.     cp 0
  2272.     JUMP_Z(Fkeykeyloop)
  2273.     dec a
  2274.     ld (Fkeycursor),a
  2275.     ld a,$20
  2276.     CALL_(loadFkeychar) 
  2277.     ld a,(Fkeycursor)
  2278.     dec a
  2279.     ld (Fkeycursor),a
  2280.     JUMP_(Fkeykeyloop)
  2281. ;(--------------All part of the previous subroutine--------)
  2282. loadFkeychar:
  2283.     push af
  2284.     ld a,(Fkeycursor)
  2285.     cp 20
  2286.     jr z,loadFkeychar2
  2287.     ld e,a
  2288.     ld d,0
  2289.     ld hl,(Fkeyaddress)
  2290.     inc hl
  2291.     add hl,de
  2292.     pop af
  2293.     push af
  2294.     ld (hl),a
  2295.     ld a,(Fkeycursor)
  2296.     ld ($800D),a
  2297.     ld a,2
  2298.     ld ($800C),a
  2299.     pop af
  2300.     ROM_CALL(TX_CHARPUT)
  2301.     ld a,(Fkeycursor)
  2302.     inc a
  2303.     ld (Fkeycursor),a
  2304.     ret
  2305. loadFkeychar2:
  2306.     pop af
  2307.     ret
  2308.  
  2309.  
  2310.  
  2311. ;(-------------Routine to get two special keys from keyboard-----------)
  2312. ;|Gets enterkey and del key and does the necessary stuff               |
  2313. ;|Input: none                                                          |
  2314. ;|Output: stuff put in buffers                                         |
  2315. ;(---------------------------------------------------------------------)
  2316. enterkey:
  2317.     ld a,(outboundCRLF_on)      ;0 if want CR    1 if want  CR/LF
  2318.     inc a                       ;this is the length
  2319.     ld c,a
  2320.     ld hl,(PROGRAM_ADDR)
  2321.     ld de,crlftable
  2322.     add hl,de
  2323.     push hl
  2324.     CALL_(putinsendout)
  2325.     ld hl,localecho_on
  2326.     bit 0,(hl)
  2327.     pop hl
  2328.     jr z,enterkey2
  2329.     ld c,a                  ;a is still okay
  2330.     CALL_(putindispout)
  2331. enterkey2:
  2332.     JUMP_(mainloop)
  2333. delkey:
  2334.     ld a,$08
  2335.     ld c,0
  2336.     CALL_(putinsendout)
  2337.     ld c,0
  2338.     ld hl,localecho_on
  2339.     bit 0,(hl)
  2340.     jr z,delkey2
  2341.     CALL_(putindispout)
  2342. delkey2:
  2343.     JUMP_(mainloop)
  2344.  
  2345.  
  2346. ;*****************************************
  2347. ;****Figure is called to convert the keypress
  2348. ;****into correct ASCII character, based on 
  2349. ;****(cursorstate), and keypress in A.  Sends 
  2350. ;****it if neccesary, and outputs it if neccesary.
  2351. ;****Only used in the terminal screen, not function keys
  2352. ;*************************************************
  2353. figure:
  2354.     ld l,a
  2355.     ld a,(cursorstate)
  2356.     cp $02
  2357.     CALL_Z(bigalphamode)
  2358.     cp $03
  2359.     CALL_Z(smallalphamode)
  2360.     cp $00
  2361.     CALL_Z(normmode)
  2362.     cp $01
  2363.     CALL_Z(secondmode)
  2364.     ld a,l                      ;all the modes return the value in l
  2365.     cp 0
  2366.     JUMP_Z(figure2)
  2367.     ld c,0
  2368.     CALL_(putinsendout)
  2369.     ld c,0
  2370.     ld hl,localecho_on
  2371.     bit 0,(hl)
  2372.     jr z,figure2
  2373.     CALL_(putindispout)
  2374. figure2:
  2375.     JUMP_(mainloop)
  2376.  
  2377. ;++++++++++++++++++++++++++++++++++++++++++++++++++
  2378. ;++++Called when key is pressed during time when
  2379. ;++++cursor is on BIG alpha  KEY IN L, SAVES AF
  2380. ;++++++++++++++++++++++++++++++++++++++++++++++++++
  2381. bigalphamode:
  2382.     push af
  2383.     ld a,l
  2384.     cp K_ALPHA
  2385.     CALL_Z(cursornorm)
  2386.     cp K_SECOND
  2387.     CALL_Z(cursor2nd)
  2388.     ld de,bigalphatable
  2389.     CALL_(convertkey)
  2390.     ld l,a
  2391.     pop af
  2392.     ret
  2393. bigalphatable:                                          
  2394.     .db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,"XTOJE",$00
  2395.     .db $00,$20,"WSNID",$00,$00,"ZVRMHC",$00
  2396.     .db $00,"YUQLGB",$00,$00,$00,"=PKFA",$00
  2397.     .db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  2398.     
  2399. ;++++++++++++++++++++++++++++++++++++++++++++++++++
  2400. ;++++Called when key is pressed during time when
  2401. ;++++cursor is on norm cursor
  2402. ;++++++++++++++++++++++++++++++++++++++++++++++++++
  2403. normmode:
  2404.     push af
  2405.     ld a,l
  2406.     cp K_ALPHA
  2407.     CALL_Z(cursorbigalpha)
  2408.     cp K_SECOND
  2409.     CALL_Z(cursor2nd)
  2410.     ld de,normtable
  2411.     CALL_(convertkey)
  2412.     ld l,a
  2413.     pop af
  2414.     ret
  2415. normtable:
  2416.     .db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,"+-*/^",$00
  2417.     .db $00,$00,"369)",$00,$00,$00,".258(",$00,$00
  2418.     .db $00,"0147",$00,$00,$00,$00,$00,$00,",",$00,$00,$00,$00
  2419.     .db $00,$00,$00,$00,$00,$00,$00,$00,$00
  2420.  
  2421. ;++++++++++++++++++++++++++++++++++++++++++++++++++
  2422. ;++++Called when key is pressed during time when
  2423. ;++++cursor is on small alpha
  2424. ;++++++++++++++++++++++++++++++++++++++++++++++++++
  2425. smallalphamode:
  2426.     push af
  2427.     ld a,l
  2428.     cp K_ALPHA
  2429.     CALL_Z(cursornorm)
  2430.     cp K_SECOND
  2431.     CALL_Z(cursor2nd)
  2432.     ld de,smallalphatable
  2433.     CALL_(convertkey)
  2434.     ld l,a
  2435.     pop af
  2436.     ret
  2437. smallalphatable:
  2438.     .db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,"xtoje",$00
  2439.     .db $00,$20,"wsnid",$00,$00,"zvrmhc",$00
  2440.     .db $00,"yuqlgb",$00,$00,$00,"=pkfa",$00
  2441.     .db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  2442.  
  2443. ;++++++++++++++++++++++++++++++++++++++++++++++++++
  2444. ;++++Called when key is pressed during time when
  2445. ;++++cursor is on 2nd cursor
  2446. ;++++++++++++++++++++++++++++++++++++++++++++++++++
  2447. secondmode:
  2448.     push af
  2449.     ld a,l
  2450.     cp K_ALPHA
  2451.     CALL_Z(cursorsmallalpha)
  2452.     cp K_SECOND
  2453.     CALL_Z(cursornorm)
  2454.     cp K_LEFTPAR
  2455.     JUMP_Z(leftbracket)
  2456.     cp K_RIGHTPAR
  2457.     JUMP_Z(rightbracket)
  2458.     cp K_DOT
  2459.     JUMP_Z(twodots)
  2460.     ld a,0
  2461. secondmode2:
  2462.     ld l,a
  2463.     pop af
  2464.     ret
  2465. leftbracket:
  2466.     ld a,'['
  2467.     JUMP_(secondmode2)
  2468. rightbracket:
  2469.     ld a,']'
  2470.     JUMP_(secondmode2)
  2471. twodots:
  2472.     ld a,':'
  2473.     JUMP_(secondmode2)
  2474.  
  2475.  
  2476.  
  2477.  
  2478.  
  2479. ;*******************************************
  2480. ;****Converts scancode in a to correct TI-ascii character
  2481. ;****according to the table address in de, if nothing
  2482. ;****goes back to beginning loop
  2483. ;*******************************************
  2484. convertkey:
  2485.     ld hl,(PROGRAM_ADDR)
  2486.     add hl,de
  2487.     ld d,0
  2488.     ld e,a
  2489.     add hl,de
  2490.     ld a,(hl)
  2491.     ret
  2492.  
  2493.  
  2494. ;*************************************************
  2495. ;****Puts character in buffer
  2496. ;*************************************************
  2497. charinbuffer:
  2498.     cp $0D                  ;a holds char, see if it is a carriagereturn
  2499.     JUMP_Z(loadcr)             ;goto this special place
  2500.     cp $0A
  2501.     JUMP_Z(loadlf)
  2502.     cp $0B
  2503.     JUMP_Z(loadlf)
  2504.     cp $0C
  2505.     JUMP_Z(loadlf)
  2506.     cp $07
  2507.     JUMP_Z(loadbell)
  2508.     cp $09
  2509.     JUMP_Z(loadtab)
  2510.     cp $08
  2511.     JUMP_Z(loadbkspce)
  2512.     ld hl,vt100charattrib
  2513.     bit 3,(hl)
  2514.     CALL_NZ(makereverse)
  2515.     ld hl,(cursoraddress)
  2516.     ld (hl),a               ;if that went all fine, just load char into buffer
  2517.     inc hl                  ;incs the cursoraddress to the next position
  2518.     ld (cursoraddress),hl   ;loads it back
  2519.     ld de,(endbuffer)
  2520.     ld bc,$0050
  2521.     ex de,hl
  2522.     add hl,bc
  2523.     call CP_HL_DE
  2524.     JUMP_Z(increasebuffer)
  2525.     
  2526.     ld hl,(cursorcoords)
  2527.     ld de,$FFFF
  2528.     call CP_HL_DE
  2529.     jr nz,simpleput
  2530.  
  2531.     ld hl,(cursoraddress)
  2532.     push hl
  2533.     ld hl,(endbuffer)
  2534.     ld a,(displaycolumn)
  2535.     ld e,a
  2536.     ld d,0
  2537.     add hl,de
  2538.     pop de          ;de is cursoraddress, hl is displaycolumn
  2539.     scf
  2540.     ccf         ;makes sure carry flag is off
  2541.     sbc hl,de
  2542.     rlc h
  2543.     JUMP_C(noput)
  2544.  
  2545.     ld hl,(endbuffer)       ;gets the endbuffer, because that's what we want to display
  2546.     ld (currrow),hl         ;currrow is the first line to display 
  2547.     ld a,1                  ;and we just want that line
  2548.     ld (linestodisplay),a   ;into there
  2549.     CALL_(displayscreen)    ;and display the stuff
  2550.     ret                     ;go back
  2551.  
  2552. makereverse:
  2553.     set 7,a
  2554.     ret
  2555.  
  2556. simpleput:
  2557.     ld hl,(cursorcoords)
  2558.     ld ($8333),hl
  2559.     res 7,a
  2560.     ROM_CALL(M_CHARPUT)
  2561.     ld hl,($8333)
  2562.     ld a,6
  2563.     add a,l
  2564.     bit 7,a
  2565.     jr nz,cursornomore
  2566.     ld (cursorcoords),hl
  2567.     ret
  2568. cursornomore:
  2569.     ld hl,$FFFF
  2570.     ld (cursorcoords),hl
  2571.     ret
  2572.  
  2573. noput:
  2574.     ret
  2575.  
  2576.  
  2577.  
  2578. increasebuffer:
  2579.     ld hl,(endbuffer)
  2580.     ld de,(lastscroll)
  2581.     call CP_HL_DE           ;sees if endbuffer is equal to lastscroll before changing endbuffer
  2582.     JUMP_Z(scrollstuff)
  2583.  
  2584.  
  2585.     ld hl,(endbuffer)
  2586.     ld bc,00080
  2587.     add hl,bc                   ;this does the simple increasing of (endbuffer)
  2588.     ld (endbuffer),hl       ;hl equals the endbuffer+80, to increase the buffer
  2589.     ld de,(realendbuffer)       ;\
  2590.     scf                         ;\This sees if endbuffer has passed realendbuffer
  2591.     ccf                         ;\and then increases realendbuffer and lastline
  2592.     ex de,hl                    ;/if it is. remember, realendbuffer=lastline
  2593.     sbc hl,de                   ;/
  2594.     CALL_C(increaserealend)     ;/
  2595.  
  2596.  
  2597.     ld hl,(endbuffer)           ;\
  2598.     ld de,(memend)              ; \this sees if the mem is at the end of the VAT
  2599.     call CP_HL_DE               ; /goes to reached_end if so to move it
  2600.     CALL_Z(reached_end)         ;/
  2601.     ld hl,(endbuffer)           ;\
  2602.     ld de,(displaystart)        ; \
  2603.     scf                         ;  \ This sees if the new line goes past the screen, 
  2604.     ccf                         ;   \and if so, then changes displaystart and redisplays
  2605.     sbc hl,de                   ;   /the screen
  2606.     ld de,00800                 ;  /
  2607.     call CP_HL_DE               ; /
  2608.     JUMP_Z(movescreen)          ;/
  2609.     ld hl,(endbuffer)           ;\
  2610.     scf                         ; \
  2611.     ccf                         ;  \ This displays two lines, the previous line and the
  2612.     sbc hl,bc                   ;   \current line
  2613.     ld (currrow),hl             ;   /
  2614.     ld a,2                      ;  / and then returns
  2615.     ld (linestodisplay),a       ; /
  2616.     CALL_(displayscreen)        ;/
  2617.     ret
  2618.  
  2619. increaserealend:
  2620.     ld hl,(endbuffer)         ;increases realendbuffer and lastline, which are equal
  2621.     ld (realendbuffer),hl     ;in value, but not in definition
  2622.     ld (lastline),hl
  2623.     CALL_(makefirstline)      ;this finds firstline from lastline, and loads it
  2624.     ret                 
  2625.  
  2626. movescreen:
  2627.     ld bc,00080             ;80
  2628.     ld hl,(displaystart)    ;takes displaystart
  2629.     add hl,bc               ;adds 80
  2630.     ld (displaystart),hl    ;and loads it back
  2631.     ld (currrow),hl         ;dispalys the whole screen again
  2632.     ld a,10                 ;\/
  2633.     ld (linestodisplay),a   ;\/
  2634.     CALL_(clearscreen)      ;\/
  2635.     CALL_(displayscreen)    ;\/
  2636.     ret                     ;return
  2637.  
  2638.  
  2639. scrollstuff:
  2640.     ld hl,(firstscroll)     ;de is still lastscroll
  2641.     ex de,hl                    ;sub lastscroll from firstscroll -    
  2642.     scf
  2643.     ccf
  2644.     sbc hl,de           ;this finds size of stuff to move
  2645.     push hl              ;puts the amount on stack later to be put in bc
  2646.     ld hl,(firstscroll)
  2647.     ld bc,00080
  2648.     add hl,bc                ;the source
  2649.     ld de,(firstscroll)      ;the destination
  2650.     pop bc                  ;the length
  2651.     ldir
  2652.     ld hl,(lastscroll)              ;these next few lines clear the last line with zeros
  2653.     ld bc,00079
  2654.     push hl
  2655.     pop de
  2656.     inc de
  2657.     ld a,0
  2658.     ld (hl),a
  2659.     ldir
  2660.     ld hl,(endbuffer)
  2661.     ld (cursoraddress),hl
  2662.     ld hl,(displaystart)
  2663.     ld (currrow),hl
  2664.     ld a,10
  2665.     ld (linestodisplay),a
  2666.     CALL_(clearscreen)
  2667.     CALL_(displayscreen)
  2668.     ret                     ;big return back to whereever
  2669.  
  2670. reached_end:      ;pretty much changes all the variables
  2671.     ld hl,(startbuffer)          ;after moving everything down, should seem unknown
  2672.     ld bc,00080                 ;to rest of the program
  2673.     add hl,bc
  2674.     ld de,(memend)
  2675.     ex de,hl
  2676.     scf
  2677.     ccf
  2678.     sbc hl,de
  2679.     ld b,h
  2680.     ld c,l
  2681.     ld hl,(startbuffer)
  2682.     ex de,hl
  2683.     ldir                ;bc is byte counter(memend-startbuffer+80)
  2684.                         ;hl is startbuffer+80
  2685.                         ;de is startbuffer
  2686.     inc de
  2687.     push de
  2688.     pop hl
  2689.     inc de
  2690.     ld (hl),0
  2691.     ld bc,00079
  2692.     ldir
  2693.     
  2694.     ld bc,00080
  2695.     ld hl,(displaystart)
  2696.     scf                     ;you don't need these later because it's all loads
  2697.     ccf                     ;and they don't do anything to the carrry flag
  2698.     sbc hl,bc
  2699.     ld (displaystart),hl
  2700.     ld hl,(endbuffer)
  2701.     sbc hl,bc
  2702.     ld (endbuffer),hl
  2703.     ld (realendbuffer),hl       ;change this too
  2704.     ld (lastline),hl
  2705.     CALL_(makefirstline)
  2706.     ld hl,(cursoraddress)
  2707.     sbc hl,bc
  2708.     ld (cursoraddress),hl
  2709.     ld hl,(firstscroll)
  2710.     sbc hl,bc
  2711.     ld (firstscroll),hl
  2712.     ld hl,(lastscroll)
  2713.     sbc hl,bc
  2714.     ld (lastscroll),hl
  2715.     ld hl,(storedcoords)
  2716.     sbc hl,bc
  2717.     ld (storedcoords),hl
  2718.     ld hl,(storedline)
  2719.     sbc hl,bc
  2720.     ld (storedline),hl
  2721.     ret
  2722.  
  2723.  
  2724.  
  2725.  
  2726. loadcr:
  2727.     ld hl,(endbuffer)
  2728.     ld (cursoraddress),hl
  2729.     ld (currrow),hl
  2730.     ld a,1
  2731.     ld (linestodisplay),a
  2732.     CALL_(displayscreen)
  2733.     ret
  2734.  
  2735. loadlf:
  2736.     ld bc,$0050
  2737.     ld hl,(cursoraddress)
  2738.     add hl,bc
  2739.     ld (cursoraddress),hl
  2740.     JUMP_(increasebuffer)           ;this will increase endbuffer
  2741.  
  2742. loadtab:           
  2743.     ld hl,(endbuffer)
  2744.     ld bc,00080
  2745.     add hl,bc
  2746.     ex de,hl
  2747.     ld hl,(cursoraddress)             
  2748.     inc hl          ;incs cursoraddress
  2749.     call CP_HL_DE       ;if it is at the last byte of line
  2750.     ret z           ;go back cause tab don't work there
  2751.     dec hl              ;dec it back to normal
  2752.     ld bc,(endbuffer)
  2753.     scf
  2754.     ccf
  2755.     sbc hl,bc
  2756.     ld c,l          ;c=column
  2757.     ld hl,(PROGRAM_ADDR)
  2758.     ld de,tabtable
  2759.     add hl,de       ;hl=tabtable
  2760.     ex de,hl        ;de=tabtable
  2761. loadtab2:
  2762.     push de         ;at the start, de is tabtable
  2763.     ld hl,(cursoraddress)
  2764.     inc hl          ;inc place to put
  2765.     ld (cursoraddress),hl
  2766.     pop hl          ;this puts tabtable in hl
  2767.     inc c           ;and inc column
  2768.     ld a,c          ;put in a to do bit manipultaion
  2769.     and $07         ;this performs a mod(a,7) 
  2770.     xor $07         ;this reverses it 7=0;6=1
  2771.     inc a           ;stead of 0-7, it's 1-8
  2772.     ld b,a          ;b is byte counter
  2773.     ld a,%10000000
  2774. multsimple:
  2775.     rlc a           ;mults %0.1 with %2 b number of times
  2776.     djnz multsimple     ;a is left with correct bit number after
  2777.     push bc
  2778.     srl c           ;divides c by 8 to get byte
  2779.     srl c
  2780.     srl c           ;b is left 0 from djnz
  2781.                 ;so bc is amount tomove. while a still has bit
  2782.     add hl,bc       ;hl=corrected table
  2783.     pop bc
  2784.     and (hl)
  2785.     jr z,loadtab2
  2786.     ld hl,(endbuffer)
  2787.     ld (currrow),hl
  2788.     ld a,1
  2789.     ld (linestodisplay),a
  2790.     CALL_(displayscreen)
  2791.     ret
  2792.  
  2793. ;de=tabtable
  2794. ;bc=column c only actual equals it
  2795.  
  2796.  
  2797. loadbkspce:
  2798.     ld de,(endbuffer)
  2799.     ld hl,(cursoraddress)
  2800.     call CP_HL_DE
  2801.     ret z
  2802.     dec hl
  2803.     ld (cursoraddress),hl
  2804.     ex de,hl
  2805.     ld (currrow),hl
  2806.     ld a,1
  2807.     ld (linestodisplay),a
  2808.     CALL_(displayscreen)
  2809.     ret
  2810.  
  2811. loadbell:
  2812.     ld a,$18
  2813.     ld (bellcounter),a
  2814.     ld hl,(PROGRAM_ADDR)
  2815.     ld de,bellpic
  2816.     add hl,de
  2817.     ld de,$FFCF
  2818.     ex de,hl
  2819.     ld b,4
  2820. loadbell2:
  2821.     push bc
  2822.     ld bc,$0010
  2823.     ld a,(de)
  2824.     or (hl)
  2825.     ld (hl),a
  2826.     add hl,bc
  2827.     inc de
  2828.     pop bc
  2829.     djnz loadbell2
  2830.     ret
  2831.  
  2832.  
  2833. ;***************************************
  2834. makefirstline:              ;finds firstline from lastline
  2835.     ld hl,(lastline)
  2836.     ld de,01520
  2837.     scf
  2838.     ccf
  2839.     sbc hl,de
  2840.     ld (firstline),hl
  2841.     ret
  2842.  
  2843. ;++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2844. ;++++Changes the cursor from white to the 
  2845. ;++++current mode when called to on current
  2846. ;++++coordinates at ($8333) and ($8334)
  2847. ;++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2848. putcursor:
  2849.     ld de,(cursorcoords)
  2850.     ld hl,$FFFF
  2851.     call CP_HL_DE
  2852.     ret z
  2853.     ld ($8333),de
  2854.     ld a,$00
  2855.     ld (cursorcount),a
  2856.     ld hl,(state1)
  2857.     ld a,l
  2858.     ld l,h
  2859.     ld h,a
  2860.     ld (state1),hl
  2861.     ROM_CALL(M_CHARPUT)
  2862.     ret
  2863.  
  2864. ;+++++++++++++++++++++++++++++++++++++++++++++
  2865. ;++++Routines to change cursor from
  2866. ;++++various states
  2867. ;+++++++++++++++++++++++++++++++++++++++++++++
  2868. cursorbigalpha:  
  2869.     push af
  2870.     ld a,$02
  2871.     ld (cursorstate),a
  2872.     pop af
  2873.     ret
  2874. cursorsmallalpha:
  2875.     push af
  2876.     ld a,$03
  2877.     ld (cursorstate),a
  2878.     pop af
  2879.     ret
  2880. cursornorm:
  2881.     push af
  2882.     ld a,$00
  2883.     ld (cursorstate),a
  2884.     pop af
  2885.     ret
  2886. cursor2nd:
  2887.     push af
  2888.     ld a,$01
  2889.     ld (cursorstate),a
  2890.     pop af
  2891.     ret
  2892.  
  2893.  
  2894.  
  2895. ;*************************************************
  2896. ;****Routine to clear the screen,  the same as 
  2897. ;****ROM_CALL(CLEARLCD), but I think it's faster,
  2898. ;****and it doesn't have to go through ZShell
  2899. ;****Input = none
  2900. ;****Output = clears screen
  2901. ;*************************************************
  2902. clearscreen:
  2903.     ld hl,$FC00
  2904.     ld de,$FC01
  2905.     ld bc,$03FF
  2906.     ld (hl),0
  2907.     ldir
  2908.     ret
  2909.  
  2910.  
  2911. ;*************************************************
  2912. ;Routine that displays all or part of the screen,
  2913. ;but does not clear it
  2914. ;Input = (displaystart) = first line of screen
  2915. ;        (currrow) = first line to display
  2916. ;        (linestodisplay) = lines to display
  2917. ;        (displaycolumn) = column to start on
  2918. ;        (cursoraddress) = used to update cursorcoords
  2919. ;Output = stuff displayed
  2920. ;        (cursorcoords) updated
  2921. ;        (currrow) chudded up 
  2922. ;*************************************************
  2923. displayscreen:
  2924.     ;im 1
  2925.     ld hl,$FFFF
  2926.     ld (cursorcoords),hl
  2927.     ld hl,(currrow)
  2928.     ld de,(displaystart)
  2929.     sbc hl,de
  2930.     ld a,h
  2931.     ld c,l
  2932.     ld de,$0050
  2933.     CALL_(div)         ;checks to see ifit is on the screen
  2934.     ld d,a
  2935.     ld e,c
  2936.     ld a,6              ;six pixels per line
  2937.     CALL_(mult)
  2938.     ld a,h
  2939.     cp 0
  2940.     jr nz,skiprest
  2941.     ld a,l
  2942.     add a,4
  2943.     and %11000000
  2944.     cp 0
  2945.     jr nz,skiprest
  2946.     ld a,l
  2947.     ld ($8334),a
  2948.     ld a,0
  2949.     ld ($8333),a
  2950.     ld a,(linestodisplay)
  2951.     ld b,a
  2952. displayscreen2:
  2953.     push bc
  2954.     CALL_(linedisplay)
  2955.     ld hl,(currrow)
  2956.     ld de,$0050
  2957.     add hl,de
  2958.     ld (currrow),hl
  2959.     ld a,0
  2960.     ld ($8333),a
  2961.     ld a,($8334)
  2962.     ld b,6
  2963.     add a,b
  2964.     ld ($8334),a    
  2965.     pop bc
  2966.     djnz displayscreen2
  2967. skiprest:
  2968.     ;im 2
  2969.     ret
  2970.  
  2971. ;*****************************************
  2972. ;Routine to display one line
  2973. ;called from displayscreen
  2974. ;Input = (displaycolumn)
  2975. ;        (currrow)
  2976. ;        (cursoraddress)
  2977. ;Output = line displayed
  2978. ;         (cursorcoords) updated if needed
  2979. ;*****************************************
  2980. linedisplay:            
  2981.     ld hl,$0050             ;de=currrow+dispalycolumn
  2982.     ld de,(currrow)         ;hl=cursoraddress
  2983.     add hl,de               ;topstack=currrow+80
  2984.     push hl
  2985.     ld a,(displaycolumn)
  2986.     ld l,a
  2987.     ld h,0
  2988.     add hl,de
  2989.     ex de,hl
  2990.     ld hl,(cursoraddress)
  2991. linedisplay2:
  2992.     call CP_HL_DE
  2993.     CALL_Z(setcursor)
  2994.     ld a,(de)
  2995.     cp 0
  2996.     jr z,nodisplay
  2997.     cp $0D
  2998.     jr z,nodisplay
  2999.     cp $09
  3000.     CALL_Z(disptab)
  3001.     push de
  3002.     res 7,a
  3003.     ROM_CALL(M_CHARPUT)
  3004.     pop de
  3005.     ld a,($8333)
  3006.     ld b,6
  3007.     add a,b
  3008.     bit 7,a
  3009.     jr nz,finished
  3010. nodisplay:
  3011.     inc de
  3012.     ex (sp),hl
  3013.     call CP_HL_DE
  3014.     jr z,finished
  3015.     ex (sp),hl
  3016.     jr linedisplay2
  3017. disptab:
  3018.     ld a,$20
  3019.     ret
  3020.  
  3021. dispreverse:
  3022.     set 3,(IY+05)
  3023.     ret
  3024.  
  3025. setcursor:
  3026.     ld bc,($8333)
  3027.     ld (cursorcoords),bc
  3028.     ret
  3029.  
  3030. finished:
  3031.     pop hl
  3032.     ret
  3033.  
  3034.  
  3035.  
  3036. ;***************************************************
  3037. ;****Division routine, numerator in AC, denominator
  3038. ;****in DE, answer without remainder in AC.
  3039. ;****Got from Sam Davies who got it from 
  3040. ;****"Programming the z80 by Rodney Zaks"
  3041. ;***************************************************
  3042. div:
  3043.     ld      HL, 0
  3044.     ld      B, 16
  3045.     and     A
  3046. DIVLOOP:
  3047.     rl      C
  3048.     rl      A
  3049.     rl      L
  3050.     rl      H
  3051.     sbc     HL, DE
  3052.     jr      nc, DIVNOADD
  3053.     add     HL, DE
  3054. DIVNOADD:
  3055.     ccf
  3056.     djnz    DIVLOOP
  3057.     rl      C
  3058.     rl      A
  3059.     ret
  3060.  
  3061. ;Multiplication Function
  3062.  
  3063. ; Arguments:
  3064. ; A = to be multiplied by DE
  3065. ; DE = to be multiplied by A
  3066.  
  3067. ; Returns:
  3068. ; HL = A * DE
  3069. mult:
  3070.     ld      HL, 0
  3071.     ld      B, 7
  3072.  
  3073.     srl     A
  3074.     jr      nc, SKIP_BIT0
  3075.     add     HL, DE
  3076.     jr      c, MULT_OVERFLOW
  3077. SKIP_BIT0:
  3078. NEXT_BIT:
  3079.     sla     E
  3080.     rl      D
  3081.     jr      nc, START_HERE
  3082.     cp      0
  3083.     jr      nz, MULT_OVERFLOW
  3084. START_HERE:
  3085.     srl     A
  3086.     jr      nc, SKIP_BIT
  3087.     add     HL, DE
  3088.     jr      c, MULT_OVERFLOW
  3089. SKIP_BIT:
  3090.     djnz    NEXT_BIT
  3091.     ret
  3092. MULT_OVERFLOW:
  3093.     scf
  3094.     ret
  3095.  
  3096. ;****************************************************
  3097. ;****RecieveByte routine from ROM, comments by site@xnet.com
  3098. ;****changed a little by me to allow for no byte coming in
  3099. ;****and changed jp's to JUMP_'s and jr's
  3100. ;****************************************************
  3101. recievebyte:
  3102.     ld b, $08      ; There are 8 bits to recieve
  3103.     ld de, $00FF   ; Setup timeout counter to wait for bit
  3104.               ;if this de reaches 0 it is a time-out and it goes
  3105.               ;to an error handler
  3106.     ;jr WaitLoopEnd ; This jumps to the end of the loop, I have NO idea
  3107.               ;why this "jr" is here???
  3108. WaitLoop:
  3109.     in a, ($07)    ; Read port 7
  3110.     and $03        ; Mask the last two bits
  3111.     cp $00
  3112.     JUMP_Z(Error)    ; Cause an error if BOTH are active
  3113.     cp $03         ; Compare it to 11 (Both NOT active)
  3114.     JUMP_NZ(Continue); If at least one is active, continue.
  3115.               ;Notice if both were active it would have caused an
  3116.               ;error, so this is really only one being active
  3117.     in a, ($07)    ; Read port 7 again
  3118.     and $03        ; Mask the last two bits
  3119.     cp $00
  3120.     JUMP_Z(Error)  ; I think this will cause an error if they are BOTH
  3121.               ;active
  3122.     cp $03
  3123.     JUMP_NZ(Continue); Same as last time, continue if at least 1 is active
  3124.     dec de         ; Decrease counter
  3125.     ld a, d
  3126.     or e           ; or d, e
  3127.     JUMP_NZ(WaitLoop); If counter (de) is not 0 then loop again.
  3128.     JUMP_(Error)   ; Cause an error if we timed out waiting for a bit
  3129. Continue:
  3130.     sub $02        ; This is where is gets interesting.  It will subtract
  3131.               ;10b from the accumulator (or the last two bits of
  3132.               ;what it received)  Remember a W=1 R=0.
  3133.               ;So:    W        R
  3134.               ;      01       10
  3135.               ;     -10 (02) -10
  3136.               ;     ----     ----
  3137.               ;      01 C     00
  3138.               ;The C means the carry flag was set because the result
  3139.               ;was less then 0, (-1h)  So now the Carry flag is set
  3140.              ;if we recieved a W and clear if we recieved a R.  NICE
  3141.     JUMP_NC(Got0) ; Go to the part for receiving a 0 if we had no carry
  3142.               ;flag set (we got an R)
  3143. Got1:
  3144.     ld a, $D4      ; Get ready to send a R ($D4 = Send a R, see above text)
  3145.     out ($07), a   ; Send the W in confirmation that we recieved the bit.
  3146.               ;now, both wires should be pulled
  3147.     rr c           ; This is neat.  We recieved a W or a 1, because of that
  3148.               ;our carry flag was set. so now we are rotating that
  3149.               ;carry flag into the register c.  So each loop will
  3150.               ;rotate the recieved bit into c until we have the
  3151.               ;complete byte.
  3152.     ld de, $FFFF   ; Get counter ready
  3153. LoopR:
  3154.     in a, ($07)    ; Read the link
  3155.     and $03        ; Tell the calc to emmit radio interference
  3156.     cp $02         ; Is the R (and ONLY the R) active?
  3157.               ;The reason it does this is becasue when the sending
  3158.               ;85 receives the confirmation signal it will clear it's
  3159.               ;port, thus the W it sent will not be active when
  3160.               ;the port it clear.  The R will be, however, because
  3161.               ;WE are the ones pulling it.
  3162.     JUMP_Z(ClearLink)
  3163.     dec de         ; lower time-out counter
  3164.     ld a, d
  3165.     or e           ; or e, d
  3166.     JUMP_NZ(LoopR)   ; Loop until sending 85 has cleared it's side of the
  3167.               ;link.
  3168.     JUMP_(Error)  ; We timed out, so cause an error.
  3169. ClearLink:
  3170.     ld a, $C0      ; get ready to clear our side of the link
  3171.     out ($07), a   ; Just Do It!
  3172.     ld d, $04      ; Get counter ready.  The reason it is so low is that
  3173.               ;this time we aren't waiting for the other 85 to do
  3174.               ;anything.  We are just clearing our side, so it SHOULD
  3175.               ;clear AS SOON as we do it.  Thus the 3 loops.
  3176. ClearLoop:
  3177.     dec d          ; Lower counter
  3178.     JUMP_Z(NextBit)  ; If we time-out it says, "oh well" and continues with
  3179.               ;the next loop.  We can do this because if there is an
  3180.               ;error, it will catch it on the next bit.  Note: there
  3181.               ;is no need for the or d, e shtuph because we are
  3182.               ;only dealing with the d, not de.
  3183.     in a, ($07)    ; See a pattern?
  3184.     and $03
  3185.     cp $03         ; Is it clear?
  3186.     JUMP_NZ(ClearLoop); If it's not clear, try again
  3187. NextBit:
  3188.         ld de,$FFFF
  3189.     djnz WaitLoop  ; Go back and do it ALL over again if B is not 0
  3190.               ;i.e. we have more bits to recieve
  3191.     ld a, c        ; We don't have any more bits to recieve, so put the
  3192.               ;received byte in a.
  3193.     ret           ; and return ($C9)
  3194. Got0:
  3195.     ld a, $E8      ; This is where we were sent if we got a R (0)
  3196.               ;Put E8h into a to send a confirming W
  3197.     out ($07), a   ; Confirm
  3198.     rr c           ; rotate the 0 (of the carry flag) into the register c
  3199.     ld de, $FFFF   ; Get counter ready for loop
  3200. LoopW:
  3201.     in a, ($07)    ; perform a memory checksum :)
  3202.     and $03        ; Mask off last two bits.
  3203.     cp $01         ; Is ONLY the W active.  (See above for indepth analysis)
  3204.     JUMP_Z(ClearLink); Go clear link and finish
  3205.     dec de         ; Decrease counter
  3206.     ld a, d
  3207.     or e           ; or e, d
  3208.     JUMP_NZ(LoopW); Keep Looping!
  3209. Error:
  3210.     ld a,$00
  3211.     ret
  3212.     ;jr Error ; This is where we are sent if there is an error
  3213.               ;(except for one time at the beg) It goes off
  3214.               ;somewhere in lala land.
  3215.  
  3216.  
  3217. ;**************************************************
  3218. ;****Send byte routine frm ROM
  3219. ;**************************************************
  3220. sendbyte:
  3221.     push af
  3222.      ld c, a        ; This just puts the byte to send in C
  3223.      ld b, $0008    ; There are 8 bits to send (Seriel remember)
  3224. SendBit:
  3225.      ld de, $FFFF   ; This is for the timing loop
  3226.      rr c           ; This rotates the register c right and puts the right
  3227.               ;bit in the carry flag.  So each loop has it's bit
  3228.               ;put in the carry flag.  Pretty neat.
  3229.      JUMP_NC(SendR)   ; If there is no carry (i.e. the current bit is 0)
  3230.               ;then send a R
  3231.      ld a, $E8      ; Else send a W because we have a 1
  3232.      JUMP_(SendIt)  ; Then actually Send it!!
  3233. SendR:
  3234.      ld a, $D4      ; We have a 0, so send a R (D4h)
  3235. SendIt:
  3236.      out ($07), a   ; This actually sends it!
  3237. WaitConfirmation:
  3238.      in a, ($07)    ; Read the port
  3239.      and $03        ; Mask off bits 1 and 0 (see above text)
  3240.      JUMP_Z(Continue2); If it is zero (both R and W pulled to ground,
  3241.               ;then continue
  3242.      in a, ($07)    ; If not, then read the port and try again
  3243.      and $03
  3244.      JUMP_Z(Continue2)
  3245.      dec de         ; Both wern't active that means the calc on the
  3246.               ;other side hasn't received it (The other TI should
  3247.               ;pull the other one to ground to show that it has
  3248.               ;recieved the bit) so loop through and try again.
  3249.               ;It uses de as a counter (it was set in the beg)
  3250.      ld a, d
  3251.      or e           ; This basiclly does or e,d and will make z 0 if both
  3252.               ;d and e are zero, or de is zero. (i.e. counter is
  3253.               ;0 and we are done with loop, or a time-out)
  3254.      JUMP_NZ(WaitConfirmation)
  3255. Error2:
  3256.     pop af
  3257.     ret
  3258.  
  3259. Continue2:
  3260.      ;jp ErrorHandler; Branislav suggested this was an error handler,
  3261.               ;I don't know, but whatever the case don't include it
  3262.               ;in your implementations.  Instead, put in a jr to your
  3263.               ;own error handlers.
  3264.      ld a, $C0      ; Get ready to clear R & W (C0h = both off, see above)
  3265.      out ($07), a   ; Actually clear them
  3266.      ld de, $FFFF   ; Get de counter ready for next loop to make sure
  3267.               ;link is cleared.  when de reaches 0 it times out.
  3268. Clearloop:
  3269.      dec de
  3270.      ld a, d
  3271.      or e           ; Again this is or e,d and will continue if de is not 0
  3272.      JUMP_Z(Error2) ; We timed out, so go to error handler (see above)
  3273.      in a, ($07)    ; Read the port 7 again
  3274.      and $03        ; Performs a Self-Destruct
  3275.      cp $03         ; makes sure link is cleared, or both are not active
  3276.               ;or both are at 5V
  3277.      JUMP_NZ(Clearloop); If not, then clear and wait again.
  3278.      djnz SendBit   ; Basiclky a 'dec b' & 'jr nz, SendBit'  It will loop
  3279.               ;again to send the next bit
  3280.     pop af
  3281.      ret            ; Goes back to your program
  3282.  
  3283.  
  3284.  
  3285.  
  3286. ;/------------------------------------------------------------------------\
  3287. ;|This routine clears the bottom nine lines, for use with the menu display|
  3288. ;|No nothing for this routine                                             |
  3289. ;\------------------------------------------------------------------------/
  3290. clearbottom:
  3291.     ld hl,$FF70
  3292.     ld bc,$008F
  3293.     ld (hl),0
  3294.     push hl
  3295.     pop de
  3296.     inc de
  3297.     ldir
  3298.     ret
  3299.  
  3300. savebottom:
  3301.     ld hl,$FF70
  3302.     ld bc,$0090
  3303.     ld de,$8641
  3304.     ldir
  3305.     ret
  3306.  
  3307. restorebottom:
  3308.     ld hl,$8641
  3309.     ld bc,$0090
  3310.     ld de,$FF70
  3311.     ldir
  3312.     ret
  3313.  
  3314. ;***************************************************
  3315. ;This routine checks strings of length in b to see if they are equal
  3316. ;Input:  b -length of both strings
  3317. ;        hl-pointer to first string
  3318. ;        de-pointer to second string
  3319. ;Note: a zero($00) in the string will be equal to anything, because this 
  3320. ;   fits my purpose
  3321. ;Output: zflag set or reset
  3322. ;Destroys: a       hl is left at end of string, de destroyed
  3323. ;***************************************************
  3324. checkstring:
  3325.     push bc
  3326.     ld a,(de)
  3327.     cp (hl)
  3328.     jr z,byteequal
  3329.     ld a,(hl)
  3330.     or a
  3331.     jr z,checknumber
  3332. checkstring2:
  3333.     pop bc  
  3334. checkstringend:         ;this accounts for if it stops early
  3335.     inc hl               ;to get hl at end
  3336.     djnz checkstringend
  3337.     ld a,1
  3338.     cp 0
  3339.     ret 
  3340.  
  3341. checknumber:
  3342.     ld a,(de)
  3343.     sub $30
  3344.     res 7,a
  3345.     dec a
  3346.     dec a
  3347.     and %11111000       ;mask to see if anything above bit 3 is set
  3348.     cp 0
  3349.     jr z, byteequal
  3350.     bit 7,a
  3351.     jr nz,byteequal     ;if set, means two decs put number
  3352.     jr checkstring2
  3353.  
  3354. byteequal:
  3355.     inc hl
  3356.     inc de
  3357.     pop bc
  3358.     djnz checkstring
  3359.     ld a,0
  3360.     cp 0
  3361.     ret
  3362.  
  3363.  
  3364.  
  3365. ;********************* Display Menu routine *************************
  3366. ;Description:   Draws the menu bar at the bottom of the screen
  3367. ;Parameters:    none
  3368. ;Destroys:      a, b, hl
  3369.  
  3370. displaymenu:
  3371.         ld      hl, VIDEO_MEM+$380
  3372.         ld      b, 32
  3373. displaymenuloop1:
  3374.         ld      (hl), $FF
  3375.         inc     hl
  3376.         djnz    displaymenuloop1
  3377.  
  3378.         ld      b, 36
  3379.         ld      a, $C0
  3380. displaymenuloop2:
  3381.         ld      (hl), a
  3382.         inc     hl
  3383.         inc     hl
  3384.         inc     hl
  3385.         rra
  3386.         cp      3
  3387.         jr      nz, displaymenuloop2
  3388.         ld      a, $C0
  3389.         dec     hl
  3390.         dec     hl
  3391.         djnz    displaymenuloop2
  3392.  
  3393.         ld      a, $FE
  3394.         ld      (VIDEO_MEM+$38F), a
  3395.         ld      (VIDEO_MEM+$39F), a
  3396.         ret
  3397.  
  3398.  
  3399. erasebell:
  3400.     ld hl,(PROGRAM_ADDR)
  3401.     ld de,bellpic2
  3402.     add hl,de
  3403.     ld de,$FFCF
  3404.     ex de,hl
  3405.     ld b,4
  3406. erasebell2:
  3407.     push bc
  3408.     ld bc,$0010
  3409.     ld a,(de)
  3410.     and (hl)
  3411.     ld (hl),a
  3412.     add hl,bc
  3413.     inc de
  3414.     pop bc
  3415.     djnz erasebell2
  3416.     ret
  3417.  
  3418.  
  3419. getkeys:
  3420.     push bc
  3421.     push hl
  3422.     ld b, 7
  3423.     ld a, %01111111
  3424. getkeyloop:
  3425.     rlca
  3426.     out (1),a
  3427.     nop
  3428.     nop
  3429.     nop
  3430.     nop
  3431.     push af
  3432.     in a, (1)
  3433.     cpl
  3434.     or a
  3435.     jr nz,gotkey
  3436.     pop af
  3437.     djnz getkeyloop
  3438.     xor a
  3439. keyend:
  3440.     ld hl,stored_key
  3441.     ld b,(hl)
  3442.     ld (hl),a
  3443.     cp b
  3444.     jr nz,keyend2
  3445.     ld a,$00
  3446. keyend2:
  3447.     ld b,$40
  3448. keyend3:
  3449.     nop
  3450.     nop
  3451.     djnz keyend3
  3452.     pop hl                    ;if something, in b goes to a
  3453.     pop bc
  3454.     ret
  3455. gotkey:
  3456.     pop hl            ;chud off stack, can I get rid of the use of this hl
  3457.     push af
  3458.     ld a,%00000111
  3459.     xor b            ;7 -> 0, 6->1, 2 -> 5
  3460.     rlca            ;don't need shift cause no chance of hitting top bit
  3461.     rlca
  3462.     rlca
  3463.     pop bc
  3464. gotkeyloop:
  3465.     rr b
  3466.     inc a
  3467.     jr c,keyend
  3468.     jr gotkeyloop
  3469.  
  3470.  
  3471.  
  3472. prefwords:
  3473.     .db "Preferences",0
  3474.     .db "  VT100 (ANSI)",0
  3475.     .db "  Local Echo",0
  3476.     .db "  Outbound CR/LF",0
  3477.     .db "  Inbound CR/LF",0
  3478.     .db "  Split Screen",0
  3479.     .db " Set Function Keys",0
  3480.  
  3481. savedprefs:
  3482.     .db 1,1,1,0,0
  3483.  
  3484. funckeywords:
  3485.     .db "Function Keys",0
  3486. funckeywords2:
  3487.     .db "Press Fkey to change",0
  3488. funckeywords3:
  3489.     .db "to:",0
  3490.  
  3491. tabtable:
  3492.     .db %00000000,%00000000,%00000000,%00000000,%00000000
  3493.     .db %00000000,%00000000,%00000000,%00000000,%00000000
  3494.  
  3495. chartable:
  3496.     .db 13,33,33,0
  3497.     .db 37,34,34,0
  3498.     .db 61,35,35,0
  3499.     .db 86,36,36,0
  3500.     .db 112,37,37,0
  3501.     .db 0,0
  3502. chartable2:
  3503.     .db 12,38,38,0
  3504.     .db 38,39,39,0
  3505.     .db 62,59,59,0
  3506.     .db 87,60,60,0
  3507.     .db 113,62,62,0
  3508.     .db 0,0
  3509. chartable3:
  3510.     .db 12,63,63,0
  3511.     .db 36,64,64,0
  3512.     .db 62,92,92,0
  3513.     .db 87,95,95,0
  3514.     .db 113,96,96,0
  3515.     .db 0,0
  3516. chartable4:
  3517.     .db 12,123,123,0
  3518.     .db 38,124,124,0
  3519.     .db 62,125,125,0
  3520.     .db 87,126,126,0
  3521.     .db 108,$09,"TAB",0
  3522.  
  3523. crlftable:
  3524.     .db $0D,$0A
  3525.  
  3526. bellpic:
  3527.     .db %00000001
  3528.     .db %00000011
  3529.     .db %00000111
  3530.     .db %00001111
  3531. bellpic2:
  3532.     .db %11111110
  3533.     .db %11111100
  3534.     .db %11111000
  3535.     .db %11110000
  3536.  
  3537. statusgood:
  3538.     .db $1B,"[0n"
  3539. statusbad:
  3540.     .db $1B,"[3n"
  3541. whatareyou:
  3542.     .db $1B,'[','?','1',59,'0','C'
  3543.  
  3544. cursorresponse:
  3545.     .db $1B,'[',$00,$00,';',$00,$00,'R'     ;the extra spaces are there to account for
  3546.                                     ;two digit ascii(uggh..) values.  That's probably 
  3547.                                     ;not what it will really look like.
  3548.        
  3549.  
  3550. lflftable:
  3551.     .db $0A,$0A,$0A,$0A,$0A,$0A,$0A,$0A,$0A,$0A,$0A,$0A,$0A,$0A,$0A,$0A
  3552.     .db $0A,$0A,$0A,$0A,$0A,$0A,$0A,$0A,$0A,$0A,$0A,$0A,$0A,$0A,$0A,$0A
  3553.  
  3554.  
  3555. screenwords:
  3556.     .db "v0.9 - (05/06/97)",0
  3557.     .db "By: ",$0A,"lan ",$0B,"ailey",0
  3558.     .db "<bailala@mw.sisna.com>",0
  3559.     .db "Room for: ",0
  3560.     .db " lines  |  ",0
  3561.  
  3562. diagnosis0:                             ;x=(totallines)
  3563.     .db " : (  GET MORE MEM",0          ;0 < x < 10
  3564. diagnosis1:                             ;
  3565.     .db " : [  NO VT100",0              ;9 < x < 32
  3566. diagnosis2:                             ;
  3567.     .db " : )  GREAT!",0                ;31 < x < 128
  3568. diagnosis3:                             ;
  3569.     .db " ;-)  SUPER!!",0              ;127 < x < 240
  3570. diagnosis4:                             ;
  3571.     .db " :^o  WOW!!!",0              ;239 < x < infinity (not really, but...)
  3572.  
  3573. menuwords:
  3574.     .db "TERM",0
  3575.     .db "KEYS",0
  3576.     .db "HELP",0
  3577.     .db "QUIT",0
  3578.  
  3579. keyhelpwords:
  3580.     .db "[2nd & ALPHA] - Change mode",0
  3581.     .db "[Arrows] - Scroll screen",0
  3582.     .db "[F1-F5] - Predefined strings",0
  3583.     .db "[MORE] - More characters",0
  3584.     .db "[CUSTOM] - Terminal prefer"
  3585.     .db "ences",0
  3586.     .db "[GRAPH] - Refresh screen",0
  3587.     .db "[CLEAR] - Clear buffer",0
  3588.     .db "[STAT] - This help screen",0
  3589.     .db "[EXIT] - Exit",0
  3590.  
  3591.  
  3592. helpaddress:
  3593.     .db "Go to this address for help:",0
  3594.     .db "www.mw.sisna.com/users/",0
  3595.     .db "bailala/zterm/",0
  3596.     .db $00
  3597.     .db "Or email me:",0
  3598.     .db "bailala@mw.sisna.com",0
  3599.  
  3600. vt100helpmessage:
  3601.     .db "Email Alan this:",0
  3602.  
  3603.  
  3604. functionkeys:
  3605.     .db 20,"ATDT1234567",$20,$20,$20,$20,$20,$20,$20,$20,$20,$0B
  3606.     .db 20,"ATDT9876543",$20,$20,$20,$20,$20,$20,$20,$20,$20,$0B
  3607.     .db 20,"ATDT-------",$20,$20,$20,$20,$20,$20,$20,$20,$20,$0B
  3608.     .db 20,"/join #calc-ti",$20,$20,$20,$20,$20,$20,$0E
  3609.     .db 20,"/nick BobDole",$20,$20,$20,$20,$20,$20,$20,$0D
  3610.  
  3611.  
  3612.     ;format \/\/\/ - - first byte - length of command
  3613.     ;                  next few from first byte - command
  3614.     ;          next two - place to jump execution
  3615.     ;          last in table - $FF, terminator
  3616.  
  3617. vt100table:
  3618.     .db $04,'[',$00,$00,'D'
  3619.     .dw vt100cursorleftlots
  3620.     .db $03,'[',$00,'D'
  3621.     .dw vt100cursorleft                ;must add to (PROGRAM_ADDR)
  3622.     .db $03,'[',$00,'C'                ;for all \/ \/ \/
  3623.     .dw vt100cursorright
  3624.     .db $04,'[',$00,$00,'C'
  3625.     .dw vt100cursorrightlots
  3626.     .db $03,'[',$00,'A'
  3627.     .dw vt100cursorup
  3628.     .db $04,'[',$00,$00,'A'
  3629.     .dw vt100cursoruplots
  3630.     .db $03,'[',$00,'B'
  3631.     .dw vt100cursordown
  3632.     .db $04,'[',$00,$00,'B'
  3633.     .dw vt100cursordownlots
  3634.     .db $05,'[',$00,';',$00,'H'
  3635.     .dw vt100changecursor
  3636.     .db $06,'[',$00,$00,';',$00,'H'
  3637.     .dw vt100changeud
  3638.     .db $06,'[',$00,';',$00,$00,'H'
  3639.     .dw vt100changelr
  3640.     .db $07,'[',$00,$00,';',$00,$00,'H'
  3641.     .dw vt100changeudlr
  3642.     .db $05,'[',$00,';',$00,'f'
  3643.     .dw vt100changecursor
  3644.     .db $06,'[',$00,$00,';',$00,'f'
  3645.     .dw vt100changeud
  3646.     .db $06,'[',$00,';',$00,$00,'f'
  3647.     .dw vt100changelr
  3648.     .db $07,'[',$00,$00,';',$00,$00,'f'
  3649.     .dw vt100changeudlr
  3650.     .db $03,'[','2','J'
  3651.     .dw vt100entirescreen
  3652.     .db $03,'[','1','J'
  3653.     .dw vt100erasebegcursor
  3654.     .db $02,'[','J'
  3655.     .dw vt100erasecursorend
  3656.     .db $03,'[','0','J'
  3657.     .dw vt100erasecursorend
  3658.     .db $05,'[',$00,';',$00,'r'
  3659.     .dw vt100setscrolling
  3660.     .db $06,'[',$00,';',$00,$00,'r'
  3661.     .dw vt100setscrollingb
  3662.     .db $06,'[',$00,$00,';',$00,'r'
  3663.     .dw vt100setscrollingt
  3664.     .db $07,'[',$00,$00,';',$00,$00,'r'
  3665.     .dw vt100setscrollingtb
  3666.     .db $01,'7'
  3667.     .dw vt100storecoords
  3668.     .db $01,'8'
  3669.     .dw vt100restorecoords
  3670.     .db $01,'D'
  3671.     .dw vt100index
  3672.     .db $01,'M'
  3673.     .dw vt100reverseindex
  3674.     .db $01,'E'
  3675.     .dw vt100nextline
  3676.     .db $03,'[','2','K'
  3677.     .dw vt100eraseline
  3678.     .db $02,'[','K'
  3679.     .dw vt100eraseendline
  3680.     .db $03,'[','0','K'
  3681.     .dw vt100eraseendline
  3682.     .db $03,'[','1','K'
  3683.     .dw vt100erasecursor
  3684.     .db $02,'[','m'
  3685.     .dw vt100cursorstyle
  3686.     .db $03,'[',$00,'m'
  3687.     .dw vt100cursorstyle
  3688.     .db $05,'[',$00,';',$00,'m'
  3689.     .dw vt100cursorstyle
  3690.     .db $07,'[',$00,';',$00,';',$00,'m'
  3691.     .dw vt100cursorstyle
  3692.     .db $09,'[',$00,';',$00,';',$00,';',$00,'m'
  3693.     .dw vt100cursorstyle
  3694.     .db $01,'H'
  3695.     .dw vt100settab
  3696.     .db $02,'[','g'
  3697.     .dw vt100cleartab
  3698.     .db $03,'[','0','g'
  3699.     .dw vt100cleartab
  3700.     .db $03,'[','3','g'
  3701.     .dw vt100clearalltabs
  3702.     .db $03,'[','5','n'
  3703.     .dw vt100statusrep
  3704.     .db $02,'[','c'
  3705.     .dw vt100whatareyou
  3706.     .db $03,'[','0','c'
  3707.     .dw vt100whatareyou
  3708.     .db $01,'c'
  3709.     .dw vt100reset
  3710.     .db $03,'[','6','n'
  3711.     .dw vt100cursorreport
  3712.     .db $02,'#',$00             ;this accounts for vt100 commands impossible on 85
  3713.     .dw vt100timefinish         ;this label just jumps them back to the end of vt100
  3714.     .db $03,'[',$00,'q'
  3715.     .dw vt100timefinish
  3716.     .db $05,'[',$00,';',$00,'q'
  3717.     .dw vt100timefinish
  3718.     .db $07,'[',$00,';',$00,';',$00,'q'
  3719.     .dw vt100timefinish
  3720.     .db $09,'[',$00,';',$00,';',$00,';',$00,'q'
  3721.     .dw vt100timefinish
  3722.     .db $02,'(','A'
  3723.     .dw vt100timefinish
  3724.     .db $02,')','A'
  3725.     .dw vt100timefinish
  3726.     .db $02,'(','B'
  3727.     .dw vt100timefinish
  3728.     .db $02,')','B'
  3729.     .dw vt100timefinish
  3730.     .db $02,'(',$00
  3731.     .dw vt100timefinish
  3732.     .db $02,')',$00
  3733.     .dw vt100timefinish
  3734.     .db $01,'O'
  3735.     .dw vt100timefinish
  3736.     .db $01,'N'
  3737.     .dw vt100timefinish
  3738.     .db $05,'[','2',';',$00,'y'
  3739.     .dw vt100timefinish
  3740.     .db $03,'[',$00,'h'
  3741.     .dw vt100timefinish
  3742.     .db $03,'[',$00,'l'
  3743.     .dw vt100timefinish
  3744.     .db $04,'[',$00,$00,'h'
  3745.     .dw vt100timefinish
  3746.     .db $04,'[',$00,$00,'l'
  3747.     .dw vt100timefinish
  3748.     .db $04,'[','?',$00,'h'
  3749.     .dw vt100timefinish
  3750.     .db $04,'[','?',$00,'l'
  3751.     .dw vt100timefinish
  3752.     .db $05,'[','?',$00,$00,'h'
  3753.     .dw vt100timefinish
  3754.     .db $05,'[','?',$00,$00,'l'
  3755.     .dw vt100timefinish
  3756.     .db $01,'='
  3757.     .dw vt100timefinish
  3758.     .db $01,'>'
  3759.     .dw vt100timefinish
  3760.     .db $FF
  3761.  
  3762.  
  3763. introut:
  3764.     ex af,af'
  3765.     exx
  3766.     ld a,(cursorcount)
  3767.     inc a
  3768.     ld (cursorcount),a
  3769.     cp $40
  3770.     CALL_Z(putcursor)
  3771.     ld a,(bellcounter)
  3772.     dec a
  3773.     ld (bellcounter),a
  3774.     cp 0
  3775.     CALL_Z(erasebell)
  3776.     exx
  3777.     ex af,af'
  3778.     jp $38
  3779. introutend:
  3780.  
  3781.  
  3782. ztermpicture:
  3783.         .db     $70,$00,$00,$00,$00,$00,$00,$00,$00,$00
  3784.         .db     $00,$00,$00,$00,$00,$00,$FF,$FF,$00,$00,$00,$00,$00,$00,$00,$00
  3785.         .db     $00,$00,$00,$00,$00,$00,$FF,$FE,$00,$00,$00,$00,$00,$00,$00,$00
  3786.         .db     $00,$00,$00,$00,$00,$00,$FF,$FC,$00,$00,$00,$00,$00,$00,$00,$00
  3787.         .db     $00,$00,$00,$00,$00,$00,$70,$38,$80,$40,$00,$00,$00,$00,$00,$00
  3788.         .db     $00,$00,$00,$00,$00,$00,$00,$70,$FF,$DF,$F9,$FE,$1F,$1F,$00,$00
  3789.         .db     $00,$00,$00,$00,$00,$00,$00,$E0,$FF,$CF,$F0,$FF,$0F,$BE,$00,$00
  3790.         .db     $00,$00,$00,$00,$00,$00,$01,$C0,$8C,$4C,$00,$C3,$0D,$F6,$00,$00
  3791.         .db     $00,$00,$00,$00,$00,$00,$03,$80,$0C,$0F,$C0,$FE,$0C,$E6,$00,$00
  3792.         .db     $00,$00,$00,$00,$00,$00,$07,$00,$0C,$0F,$E0,$F8,$0C,$46,$00,$00
  3793.         .db     $00,$00,$00,$00,$00,$00,$0E,$07,$0C,$0F,$C0,$DC,$0C,$06,$00,$00
  3794.         .db     $00,$00,$00,$00,$00,$00,$1F,$FF,$8C,$0C,$00,$CE,$0C,$46,$00,$00
  3795.         .db     $00,$00,$00,$00,$00,$00,$3F,$FF,$9E,$0F,$F0,$C7,$0C,$A6,$00,$00
  3796.         .db     $00,$00,$00,$00,$00,$00,$7F,$FF,$BF,$1F,$F9,$E3,$9E,$4F,$00,$00
  3797.         .db     $00,$00,$00,$00,$00,$00,$00,$07
  3798.  
  3799.  
  3800. ;6+7
  3801.     
  3802. .end
  3803. ;drgad
  3804.