?login_element?

Subversion Repositories NedoOS

Rev

Rev 576 | Rev 588 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;EXPORT:
  2. ;initstdio
  3. ;receivechar (macro GETCHAR_) - read char from stdin (out: A=char, CY=error)
  4. ;receivekey (macro GETKEY_) - read key from stdin (out: A=keylang, C=keynolang(???TODO), CY=error)
  5. ;yieldgetkeyloop - wait key from stdin (out: A=keylang, C=keynolang(???TODO), CY=error)
  6. ;setcolor (macro SETCOLOR_) - set color attribute (in: d=paper, e=ink)
  7. ;setcolor_invisible
  8. ;setcolor_visible
  9. ;scrolldown ;de=topyx, hl=hgt,wid ;x, wid even
  10. ;scrollup ;de=topyx, hl=hgt,wid ;x, wid even
  11. ;setxy (macro SETXY_) - set cursor position (in: de=YX, top left is 0;0)
  12. ;sendchar (macro PRCHAR_) - send char to stdout (in: A=char)
  13. ;sendchars - send chars to stdout (in: de=buf, hl=size, out: A=error)
  14. ;setstdouthandle - in: A=handle
  15. ;setstdinhandle - in: A=handle
  16. ;clearterm - print 25 lines of spaces except one
  17.  
  18. STDINBUF_SZ=255
  19.  
  20. initstdio
  21.         OS_GETSTDINOUT ;e=stdin, d=stdout, h=stderr
  22.         ld a,e
  23.         ld (stdinhandle),a
  24.         ld a,d
  25. setstdouthandle
  26.         ld (stdouthandle),a
  27.         ret
  28. setstdinhandle
  29.         ld (stdinhandle),a
  30.         ret
  31.  
  32. yieldgetkeyloop
  33. ;wait key from stdin (out: A=keylang, C=keynolang(???TODO), CY=error)
  34. ;т юфэюь ЇЁхщьх ьюцхЄ яЁшщЄш ьэюую ъэюяюъ (єяЁрты ■∙шщ esc-ъюф)!
  35.         YIELDKEEP
  36.         jr yieldgetkey_afteryield
  37. yieldgetkey_nokey
  38. ;ьюцхЄ с√Є№, ь√ т ёхЁхфшэх esc-ъюфр? Єюуфр эрфю yieldgetkeyloop
  39.         ld a,(term_prfsm_curstate)
  40.         dec a
  41.         jr nz,yieldgetkeyloop
  42.         ;ld a,7
  43.         ;out (0xfe),a
  44.         YIELD ;хёыш т яЁю°ы√щ Ёрч эшўхую эх с√ыю, Єю YIELD, р эх YIELDKEEP
  45. yieldgetkey_afteryield
  46.         ;ld a,5
  47.         ;out (0xfe),a
  48.         xor a
  49.         ld (wasmouseevent),a
  50.         call receivekey
  51.          ret c ;error
  52. ;с√ы mouse event? ёўшЄрхь чр эрцрЄшх, р яЁшыюцхэшх сєфхЄ ёьюЄЁхЄ№ ъююЁфшэрЄ√ ш ъэюяъє ь√°ш
  53. stdio_mousebuttons=$+1
  54.         ld l,0
  55. stdio_mousex=$+1
  56. stdio_mousey=$+2
  57.         ld de,0
  58. wasmouseevent=$
  59.         ret ;NC=no error
  60.         or a ;cp NOKEY ;keylang==0?
  61.         jr nz,$+3
  62.         cp c ;keynolang==0?
  63.         jr z,yieldgetkey_nokey
  64.          scf
  65.          ccf ;no error
  66.         ret
  67.  
  68. ;яюёыхфютрЄхы№эюёЄш ёырЄ№ юфэшь ъєёъюь!
  69.  
  70. setcolor
  71. ;set color attribute (in: d=paper, e=ink)
  72. ;CSI Pm m Character Attributes (SGR)
  73. ;Ps = 30  Set foreground color to Black.
  74. ;Ps = 31  Set foreground color to Red.
  75. ;Ps = 32  Set foreground color to Green.
  76. ;Ps = 33  Set foreground color to Yellow.
  77. ;Ps = 34  Set foreground color to Blue.
  78. ;Ps = 35  Set foreground color to Magenta.
  79. ;Ps = 36  Set foreground color to Cyan. (Grey?)
  80. ;Ps = 37  Set foreground color to White.
  81. ;Ps = 39  Set foreground color to default, ECMA-48 3rd.
  82. ;Ps = 40  Set background color to Black.
  83. ;Ps = 41  Set background color to Red.
  84. ;Ps = 42  Set background color to Green.
  85. ;Ps = 43  Set background color to Yellow.
  86. ;Ps = 44  Set background color to Blue.
  87. ;Ps = 45  Set background color to Magenta.
  88. ;Ps = 46  Set background color to Cyan.
  89. ;Ps = 47  Set background color to White.
  90. ;Ps = 49  Set background color to default, ECMA-48 3rd.
  91. ;Ps = 8   Invisible, i.e., hidden, ECMA-48 2nd, VT300.
  92. ;Ps = 28  Visible, i.e., not hidden, ECMA-48 3rd, VT300.
  93. ;Assume that xtermТs resources are set so that the ISO color codes are the first 8 of a set of 16. Then the aixterm colors are the bright versions of the ISO colors:
  94. ;Ps = 90  Set foreground color to Black.
  95. ;Ps = 91  Set foreground color to Red.
  96. ;Ps = 92  Set foreground color to Green.
  97. ;Ps = 93  Set foreground color to Yellow.
  98. ;Ps = 94  Set foreground color to Blue.
  99. ;Ps = 95  Set foreground color to Magenta.
  100. ;Ps = 96  Set foreground color to Cyan.
  101. ;Ps = 97  Set foreground color to White.
  102. ;TODO 1  -  BRIGHT ON: ┬ъы■ўхэшх  ЁъюёЄш INK. (Bold, VT100.)
  103. ;TODO 22 - Normal (neither bold nor faint), ECMA-48 3rd. [21  -  BRIGHT OFF: ┬√ъы■ўхэшх  ЁъюёЄш INK. (Doubly-underlined, ECMA-48 3rd.)]
  104.         ld hl,stdoutbuf
  105.        push hl
  106.         ;push de
  107.         ;ld a,0x1b
  108.         ;call sendchar_byte_a
  109.         ld (hl),0x1b
  110.         inc hl
  111.         ;ld a,'['
  112.         ;call sendchar_byte_a
  113.         ld (hl),'['
  114.         inc hl
  115.         ;pop de
  116.         ;push de
  117.         ld a,e ;a=ink
  118.         cp 8
  119.         jr c,$+4
  120.         add a,90-30-8
  121.         add a,30
  122.         call sendchar_num
  123.         ;ld a,';'
  124.         ;call sendchar_byte_a
  125.         ld (hl),';'
  126.         inc hl
  127.         ;pop de
  128.         ld a,d ;a=paper
  129.         and 7
  130.         add a,40
  131. setcolorq
  132.         call sendchar_num
  133.         ;ld a,'m'
  134.         ;call sendchar_byte_a
  135.         ld (hl),'m'
  136. setcolorqq
  137.         inc hl
  138.        pop de
  139.        or a
  140.        sbc hl,de ;de=buf, hl=size
  141.         jp sendchars
  142.  
  143. setcolor_invisible
  144.         ld hl,stdoutbuf
  145.        push hl
  146.         ld (hl),0x1b
  147.         inc hl
  148.         ld (hl),'['
  149.         inc hl
  150.         ld a,8
  151.         jr setcolorq
  152.        
  153. setcolor_visible
  154.         ld hl,stdoutbuf
  155.        push hl
  156.         ld (hl),0x1b
  157.         inc hl
  158.         ld (hl),'['
  159.         inc hl
  160.         ld a,28
  161.         jr setcolorq
  162.  
  163. scrolldown
  164. ;de=topyx, hl=hgt,wid
  165. ;x, wid even
  166.         ld b,h ;hgt
  167.         ld c,l ;wid
  168.         ld hl,stdoutbuf
  169.        push hl
  170.         ld (hl),0x1b
  171.         inc hl
  172.         ld (hl),'['
  173.         inc hl
  174.         ld a,c ;wid
  175.         call sendchar_num
  176.         ld (hl),';'
  177.         inc hl
  178.         ld a,b ;hgt
  179.         call sendchar_num
  180.         ld (hl),';'
  181.         inc hl
  182.         ld a,e ;topx
  183.         call sendchar_num
  184.         ld (hl),';'
  185.         inc hl
  186.         ld a,d ;topy
  187.         call sendchar_num
  188.         ld (hl),'d' ;NON-STANDARD!!!
  189.         jr setcolorqq
  190.        
  191. scrollup
  192. ;de=topyx, hl=hgt,wid
  193. ;x, wid even
  194.         ld b,h ;hgt
  195.         ld c,l ;wid
  196.         ld hl,stdoutbuf
  197.        push hl
  198.         ld (hl),0x1b
  199.         inc hl
  200.         ld (hl),'['
  201.         inc hl
  202.         ld a,c ;wid
  203.         call sendchar_num
  204.         ld (hl),';'
  205.         inc hl
  206.         ld a,b ;hgt
  207.         call sendchar_num
  208.         ld (hl),';'
  209.         inc hl
  210.         ld a,e ;topx
  211.         call sendchar_num
  212.         ld (hl),';'
  213.         inc hl
  214.         ld a,d ;topy
  215.         call sendchar_num
  216.         ld (hl),'u' ;NON-STANDARD!!!
  217.         jr setcolorqq
  218.        
  219. clearterm
  220.         ld b,24
  221. clearterm0
  222.         push bc
  223.         ld de,clearterm_data
  224.         ld hl,80
  225.         call sendchars
  226.         pop bc
  227.         djnz clearterm0
  228.         ld de,clearterm_data
  229.         ld hl,79
  230.         call sendchars
  231.         ld de,0
  232.         jp setxy
  233. clearterm_data
  234.         ds 80,' '
  235.  
  236. setxy
  237. ;set cursor position (in: de=YX, top left is 0;0)
  238.         ld hl,stdoutbuf
  239.        push hl
  240.         ;push de
  241.         ;ld a,0x1b
  242.         ;call sendchar_byte_a
  243.         ld (hl),0x1b
  244.         inc hl
  245.         ;ld a,'['
  246.         ;call sendchar_byte_a
  247.         ld (hl),'['
  248.         inc hl
  249.         ;pop de
  250.         ;push de
  251.         ld a,d ;y
  252.         inc a
  253.         call sendchar_num
  254.         ;ld a,';'
  255.         ;call sendchar_byte_a
  256.          ld (hl),';'
  257.          inc hl
  258.         ;pop de
  259.         ld a,e ;x
  260.         inc a
  261.         call sendchar_num
  262.         ;ld a,'H'
  263.         ld (hl),'H'
  264.         jp setcolorqq
  265.  
  266. sendchar_num
  267. ;a=num
  268.         push bc
  269.         ld c,'0'-1
  270.         inc c
  271.         sub 10
  272.         jr nc,$-3
  273.         ;push af
  274.         ;ld a,c
  275.         ;call sendchar_byte_a
  276.         ;pop af
  277.          ld (hl),c
  278.          inc hl
  279.         add a,'0'+10
  280.         ;jr sendchar_byte_a
  281.          ld (hl),a
  282.          inc hl
  283.         pop bc
  284.         ret
  285.  
  286. sendchar
  287.         ;cp 0x80
  288.         ;jr nc,sendchar_rustoutf8
  289. ;sendchar_byte_a
  290.         ld (stdoutbuf),a
  291.         ld hl,1
  292.         ld de,stdoutbuf
  293. sendchars
  294. ;send chars to stdout (in: de=buf, hl=size, out: A=error)
  295.         ;ld a,6
  296.         ;out (0xfe),a
  297. sendchars0
  298.         push de
  299.         push hl
  300. stdouthandle=$+1
  301.         ld b,0
  302.         OS_WRITEHANDLE ;1436t ;[2718t (1225 before BDOS_writehandle + 195 before BDOS_writehandle_pipe + 477 ..findpipe_byhandle + 301 pipe + 192 end BDOS_writehandle + 326 end BDOS)]
  303.       ;push af
  304.       ;push hl
  305.       ;YIELDKEEP ;2158t
  306.       ;pop bc ;bytes actually written
  307.       ;pop af
  308.         ld b,h
  309.         ld c,l ;bytes actually written
  310.         pop hl
  311.         pop de
  312.          or a
  313.           ret nz ;error ;TODO юсЁрсюЄрЄ№? р Єръ яюър яЁюёЄю шчсхурхь чрЎшъыштрэш 
  314.          sbc hl,bc ;datasize-byteswritten
  315.          ret z
  316.          ex de,hl
  317.          add hl,bc ;dataaddr+byteswritten
  318.          ex de,hl
  319. ;hl=remaining data size
  320. ;de=remaining data addr
  321.         push de
  322.         push hl
  323.         ;ld a,5
  324.         ;out (0xfe),a
  325.         YIELDKEEP ;2158t
  326.         pop hl
  327.         pop de
  328.         jr sendchars0
  329.  
  330. receivechar
  331. ;read char from stdin (out: A=char, CY=error)
  332. stdindatacount=$+1
  333.         ld a,0
  334.         or a
  335.         jr z,receivechar_doreceive
  336.         dec a
  337.         ld (stdindatacount),a
  338. stdindatapointer=$+1
  339.         ld hl,0
  340.         ld a,(hl)
  341.         inc hl
  342.         ld (stdindatapointer),hl
  343.         or a ;NC=no error
  344.         ret
  345. receivechar_doreceive
  346.         ld hl,STDINBUF_SZ
  347.         ld de,stdinbuf
  348.         ld (stdindatapointer),de
  349. stdinhandle=$+1
  350.         ld b,0
  351.         OS_READHANDLE ;hl=size actually received
  352.         or a
  353.         scf
  354.         ret nz ;error
  355.         ld a,h
  356.         or l
  357.         ;ld c,a
  358.         ret z ;NC=no error
  359.         ;ld a,l
  360.         ld (stdindatacount),a
  361.         jr receivechar
  362.  
  363. receivekey
  364. ;read key from stdin (out: A=keylang, C=keynolang(???TODO), CY=error)
  365.         call receivechar
  366.         ret c ;error
  367. ;a=char
  368. TERM_ST_SINGLE=1 ;1: wait for single symbol
  369. TERM_ST_AFTERESC=2 ;2: after 0x1b
  370. TERM_ST_AFTERESCBRACKET=3 ;3: after 0x1b [ [number] (might be more digits)
  371. TERM_ST_AFTERMOUSE=4
  372. TERM_ST_AFTERMOUSEb=5
  373. TERM_ST_AFTERMOUSEbx=6
  374. term_prfsm_curstate=$+1
  375.         ld b,TERM_ST_SINGLE
  376.         djnz term_prfsm_nosingle
  377.          ;cp 0x0a
  378.          ;ld c,0x0d
  379.          ;jp z,term_prfsm_keycok
  380.         cp 0x1b
  381.         ld c,a
  382.         jp nz,term_prfsm_keycok
  383.         ld hl,term_prfsm_curstate
  384.         inc (hl) ;TERM_ST_AFTERESC
  385.         jr term_prfsm_nokey
  386. term_prfsm_nosingle
  387.         djnz term_prfsm_noafteresc
  388.         cp '['
  389.         ld c,0x1b
  390.         jp nz,term_prfsm_keycok ;esc esc -> esc_key
  391.         ld hl,term_prfsm_curstate
  392.         inc (hl) ;TERM_ST_AFTERESCBRACKET
  393. term_prfsm_0curnumber_nokey
  394.         xor a
  395.         ld (term_prfsm_curnumber),a
  396.         ;xor a ;no key, no error
  397.         ld c,a
  398.         ret
  399. term_prfsm_noafteresc
  400.         djnz term_prfsm_noafterescbracket
  401.         sub '0'
  402.         cp 10
  403.         jr nc,term_prfsm_afterescbracket_nonumber
  404.         ld e,a
  405.         ld hl,term_prfsm_curnumber
  406.         ld a,(hl)
  407.         add a,a
  408.         add a,a
  409.         add a,(hl)
  410.         add a,a ;*10
  411.         add a,e
  412.         ld (hl),a
  413.         jr term_prfsm_nokey
  414. term_prfsm_afterescbracket_nonumber
  415.         add a,'0'
  416.         cp ';'
  417.         jr nz,term_prfsm_afterescbracket_nosemicolon
  418.         ld a,(term_prfsm_curnumber)
  419.         ld (term_prfsm_curnumber1),a
  420.         jr term_prfsm_0curnumber_nokey
  421. term_prfsm_afterescbracket_nosemicolon
  422.         ld hl,term_prfsm_curstate
  423.         ld (hl),TERM_ST_SINGLE
  424.         ;cp 'H'
  425.         cp '~'
  426.         jr z,term_prfsm_afterescbracket_tilde
  427.         cp 'A'
  428.         ld c,key_up
  429.         jr z,term_prfsm_keycok
  430.         cp 'B'
  431.         ld c,key_down
  432.         jr z,term_prfsm_keycok
  433.         cp 'C'
  434.         ld c,key_right
  435.         jr z,term_prfsm_keycok
  436.         cp 'D'
  437.         ld c,key_left
  438.         jr z,term_prfsm_keycok
  439.         cp 'M'
  440.         jr z,term_prfsm_mouse
  441. term_prfsm_nokey
  442.         xor a ;no key, no error
  443.         ld c,a
  444.         ret
  445. term_prfsm_noafterescbracket
  446.         djnz term_prfsm_noaftermouse
  447.         ld hl,term_prfsm_curstate
  448.         inc (hl) ;TERM_ST_AFTERMOUSEb
  449.          ld l,0xff
  450.          dec a
  451.          jr nz,$+3
  452.          dec l
  453.          dec a
  454.          jr nz,$+4
  455.          res 1,l
  456.          dec a
  457.          jr nz,$+4
  458.          res 2,l
  459.          ld a,l
  460.          ld (stdio_mousebuttons),a
  461.         xor a ;no key, no error
  462.         ld c,a
  463.         ret
  464. term_prfsm_noaftermouse
  465.         djnz term_prfsm_aftermousebx;term_prfsm_noaftermouseb
  466.         ld hl,term_prfsm_curstate
  467.         inc (hl) ;TERM_ST_AFTERMOUSEbx
  468.          ld (stdio_mousex),a
  469.         xor a ;no key, no error
  470.         ld c,a
  471.         ret
  472. term_prfsm_aftermousebx
  473.         ld hl,term_prfsm_curstate
  474.         ld (hl),TERM_ST_SINGLE
  475.          ld (stdio_mousey),a
  476.         ld a,0xc9
  477.         ld (wasmouseevent),a
  478.         xor a ;no key, no error
  479.         ld c,a
  480.         ret
  481. term_prfsm_afterescbracket_tilde
  482.         ld a,(term_prfsm_curnumber)
  483.         cp 3
  484.         ld c,key_del
  485.         jr z,term_prfsm_keycok
  486.         cp 1
  487.         ld c,key_home
  488.         jr z,term_prfsm_keycok
  489.         cp 4
  490.         ld c,key_end
  491.         jr z,term_prfsm_keycok
  492.         cp 2
  493.         ld c,key_ins
  494.         jr z,term_prfsm_keycok
  495.         jr term_prfsm_nokey
  496.  
  497. term_prfsm_keycok
  498.         ld hl,term_prfsm_curstate
  499.         ld (hl),TERM_ST_SINGLE
  500.         xor a
  501.         or c ;NC=no error
  502.         ret
  503. term_prfsm_mouse
  504.         ld hl,term_prfsm_curstate
  505.         ld (hl),TERM_ST_AFTERMOUSE
  506.         xor a ;no key, no error
  507.         ld c,a
  508.         ret
  509.  
  510. term_prfsm_curnumber
  511.          db 0
  512. term_prfsm_curnumber1
  513.          db 0
  514.  
  515. stdoutbuf
  516.         db "-[00;00m"
  517.  
  518. stdinbuf
  519.         ds STDINBUF_SZ
  520.