vt52.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /* Copyright (C) 1996 Robert de Bath <robert@mayday.compulink.co.uk>
  2. * This file is part of the Linux-8086 C library and is distributed
  3. * under the GNU Library General Public License.
  4. */
  5. #if !__FIRST_ARG_IN_AX__
  6. #ifdef __AS386_16__
  7. #ifdef __STANDALONE__
  8. #include <bios.h>
  9. #include <errno.h>
  10. int errno;
  11. extern void (*__smart_putch)();
  12. #define CTRL(x) ((x)&0x1F)
  13. static int last_attr = 0x07;
  14. static int con_mode;
  15. static unsigned char con_height = 24, con_width = 79;
  16. static int con_colour = 0;
  17. static unsigned char con_row, con_col;
  18. vt52_putch(c)
  19. int c;
  20. {
  21. static int ctrl = 0;
  22. int new_attr;
  23. __smart_putch = vt52_putch();
  24. if( con_mode==0 ) asm_coninit();
  25. switch( ctrl )
  26. {
  27. case 1:
  28. ctrl=0;
  29. switch(c)
  30. {
  31. case 'A': if( con_row ) con_row--; asm_cpos(con_row, con_col); break;
  32. case 'B': if( con_row != con_height ) con_row++;
  33. asm_cpos(con_row, con_col); break;
  34. case 'C': if( con_col != con_height ) con_col++;
  35. asm_cpos(con_row, con_col); break;
  36. case 'D': if( con_col ) con_col--; asm_cpos(con_row, con_col); break;
  37. case 'E': last_attr = 0x07; asm_cls();
  38. case 'H': asm_cpos(0,0); break;
  39. case 'J': asm_cls(); break;
  40. case 'K': break;
  41. case 'R': ctrl = 2; break; /* Foreground */
  42. case 'S': ctrl = 3; break; /* Background */
  43. case 'Y': ctrl = 4; break; /* ttypos */
  44. }
  45. break;
  46. case 2: ctrl=0; new_attr = (last_attr & 0xF0) + (c&0xF);
  47. if(0) {
  48. case 3: ctrl=0; new_attr = (last_attr & 0x0F) + (c<<4);
  49. }
  50. switch(c)
  51. {
  52. case '_': if( !con_colour ) last_attr = (last_attr&0x88) + 1;
  53. break;
  54. case '!': last_attr = (last_attr&0x88) + 0x70; break;
  55. case ' ': last_attr = 0x07; break;
  56. case '+': last_attr |= 0x08; break;
  57. case '*': last_attr |= 0x80; break;
  58. default: if( con_colour )
  59. last_attr = new_attr;
  60. }
  61. break;
  62. case 4: ctrl=5; con_col = c-' '; break;
  63. case 5: ctrl=0; con_row = c-' '; asm_cpos(con_row, con_col); break;
  64. break;
  65. default:
  66. if( c & 0xE0 )
  67. { asm_colour(last_attr) ; asm_putc(c); }
  68. else switch(c)
  69. {
  70. default:
  71. asm_putc(c);
  72. break;
  73. case CTRL('I'):
  74. asm_gpos();
  75. con_col = ((con_col+8)& -8);
  76. asm_cpos(con_row, con_col);
  77. break;
  78. case CTRL('L'):
  79. asm_cpos(0,0);
  80. asm_cls();
  81. break;
  82. case CTRL('['):
  83. ctrl = 1;
  84. asm_gpos();
  85. break;
  86. }
  87. break;
  88. }
  89. }
  90. static asm_coninit()
  91. {
  92. #asm
  93. mov ax,#$0F00
  94. int $10
  95. mov _con_mode,ax
  96. #endasm
  97. if( (con_mode &0xFF) > 39 ) con_width = (con_mode>>8);
  98. if( (con_mode&0xFF) != 0x7)
  99. con_colour = 1;
  100. }
  101. static asm_putc(c)
  102. {
  103. #asm
  104. #if !__FIRST_ARG_IN_AX__
  105. mov bx,sp
  106. mov ax,[bx+2]
  107. #endif
  108. cmp al,#$0A
  109. jne not_nl
  110. mov ax,#$0E0D
  111. mov bx,#7
  112. int $10
  113. mov al,#$0A
  114. not_nl:
  115. mov ah,#$0E
  116. mov bx,#7
  117. int $10
  118. #endasm
  119. }
  120. static asm_cls()
  121. {
  122. #asm
  123. push bp ! Bug in some old BIOS`s
  124. !mov ax,#$0500
  125. !int $10
  126. mov ax,#$0600
  127. mov bh,_last_attr
  128. mov cx,#$0000
  129. mov dl,_con_width
  130. mov dh,_con_height
  131. int $10
  132. pop bp
  133. #endasm
  134. }
  135. static asm_cpos(r,c)
  136. {
  137. #asm
  138. #if __FIRST_ARG_IN_AX__
  139. mov bx,sp
  140. mov dh,al
  141. mov ax,[bx+2]
  142. mov dl,al
  143. #else
  144. mov bx,sp
  145. mov ax,[bx+2]
  146. mov dh,al
  147. mov ax,[bx+4]
  148. mov dl,al
  149. #endif
  150. mov ah,#$02
  151. mov bx,#7
  152. int $10
  153. #endasm
  154. }
  155. static asm_colour(c)
  156. {
  157. #asm
  158. #if __FIRST_ARG_IN_AX__
  159. mov bx,ax
  160. #else
  161. mov bx,sp
  162. mov bx,[bx+2]
  163. #endif
  164. mov ah,#$08
  165. int $10
  166. mov ah,#$09
  167. mov cx,#1
  168. int $10
  169. #endasm
  170. }
  171. static asm_gpos()
  172. {
  173. #asm
  174. mov ah,#$03
  175. mov bx,#7
  176. int $10
  177. mov [_con_row],dh
  178. mov [_con_col],dl
  179. mov ax,cx
  180. #endasm
  181. }
  182. #endif
  183. #endif
  184. #endif