textview.4th 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. \ textview.4th
  2. decimal
  3. : get-text-file ( b u -- )
  4. cr r/o open-file ?dup
  5. if cr ." open error = " dec. drop exit
  6. then
  7. >r \ save fileid
  8. begin
  9. here 30 blank
  10. here 30 r@ read-line ?dup \ u2 f ior ior?
  11. if cr ." read error = " dec. 2drop
  12. r> close-file drop exit
  13. then
  14. while \ u2
  15. drop
  16. \ here swap type cr
  17. here
  18. 30 0 ?do
  19. dup c@ bl < if
  20. dup bl swap c!
  21. then
  22. char+
  23. loop
  24. drop
  25. 30 allot
  26. repeat
  27. drop
  28. r> close-file drop
  29. ;
  30. : get-text ( -- \ <string><space> )
  31. lcd-cls s" loading: " lcd-type
  32. bl parse 2dup lcd-type get-text-file ;
  33. variable top
  34. variable last-x
  35. variable last-y
  36. variable cursor-t
  37. variable cursor-b
  38. : home-page ( -- )
  39. lcd-cls
  40. top @ dup cursor-t !
  41. dup cursor-b !
  42. 30 16 * >r r@ lcd-type
  43. r> cursor-b +!
  44. ;
  45. : next-line ( -- )
  46. lcd-scroll
  47. 0 lcd-height-pixels font-height - lcd-move-to
  48. cursor-b @ 30 lcd-type
  49. 30 dup cursor-t +! cursor-b +!
  50. ;
  51. : prev-line ( -- )
  52. cursor-t @ top @ <> if
  53. lcd-scroll>
  54. 0 0 lcd-move-to
  55. cursor-t @ 30 - dup cursor-t !
  56. 30 lcd-type
  57. -30 cursor-b +!
  58. then
  59. ;
  60. : scroll
  61. home-page
  62. begin
  63. ctp-pos? if
  64. ctp-pos dup 0<
  65. if
  66. 2drop 0 last-y ! 0 last-x !
  67. else
  68. last-y @ if
  69. >r \ y
  70. last-y @ r@ - dup abs font-height >
  71. if
  72. 0<
  73. if
  74. prev-line
  75. else
  76. next-line
  77. then
  78. r> last-y !
  79. else
  80. drop r> drop
  81. then
  82. else
  83. last-y !
  84. then
  85. last-x @ if
  86. >r \ x
  87. last-x @ r@ - dup abs 150 >
  88. if
  89. 0<
  90. if
  91. 15 0 ?do next-line loop
  92. else
  93. home-page
  94. then
  95. r> last-x !
  96. else
  97. drop r> drop
  98. then
  99. else
  100. last-x !
  101. then
  102. then
  103. then
  104. P6_P6D p@ $07 and
  105. case
  106. $02 of \ left button
  107. home-page
  108. endof
  109. $04 of \ centre button
  110. endof
  111. $01 of \ right button
  112. exit
  113. endof
  114. endcase
  115. again
  116. ;
  117. here top !
  118. get-text tf.txt
  119. .( scroll - using function keys L=down C=home R=up )
  120. scroll