bios_vid.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. #ifdef L_bios_putch
  12. void (*__smart_putch)() = 0;
  13. putch(c)
  14. int c;
  15. {
  16. static int col = 0;
  17. if (__smart_putch)
  18. (*__smart_putch)(c);
  19. else if (c&0xE0) {
  20. col++;
  21. asm_putc(c);
  22. }
  23. else switch(c)
  24. {
  25. case '\t':
  26. do putch(' '); while(col&7);
  27. break;
  28. case '\n':
  29. asm_putc('\r');
  30. case '\r':
  31. col = 0;
  32. asm_putc(c);
  33. break;
  34. case '\f':
  35. col = 0;
  36. #asm
  37. mov ah,#$0F
  38. int $10
  39. mov ah,#$00
  40. int $10
  41. #endasm
  42. break;
  43. }
  44. }
  45. static asm_putc(c)
  46. {
  47. #asm
  48. #if !__FIRST_ARG_IN_AX__
  49. mov bx,sp
  50. mov ax,[bx+2]
  51. #endif
  52. mov ah,#$0E
  53. mov bx,#7
  54. int $10
  55. #endasm
  56. }
  57. #endif
  58. /****************************************************************************/
  59. #ifdef L_bios_getch
  60. getch()
  61. {
  62. #asm
  63. xor ax,ax
  64. int $16
  65. #endasm
  66. }
  67. #endif
  68. /****************************************************************************/
  69. #ifdef L_bios_kbhit
  70. kbhit()
  71. {
  72. #asm
  73. mov ah,#1
  74. int $16
  75. jz nokey
  76. cmp ax,#0
  77. jnz dort
  78. mov ax,#3
  79. dort:
  80. ret
  81. nokey:
  82. xor ax,ax
  83. #endasm
  84. }
  85. #endif
  86. /****************************************************************************/
  87. #ifdef L_bios_cputs
  88. cputs(str)
  89. char * str;
  90. {
  91. while(*str) putch(*str++);
  92. }
  93. #endif
  94. /****************************************************************************/
  95. #ifdef L_bios_getche
  96. getche()
  97. {
  98. static char linebuf[80];
  99. static int nextc = 0, endc=0;
  100. int rv;
  101. if (nextc >= endc)
  102. {
  103. endc = bios_readline(linebuf, sizeof(linebuf));
  104. nextc= 0;
  105. }
  106. if (endc <= nextc) return 3;
  107. rv = linebuf[endc++];
  108. if (endc == nextc) return '\r';
  109. return rv;
  110. }
  111. #endif
  112. /****************************************************************************/
  113. #ifdef L_bios_gotoxy
  114. static gotoxy(x,y)
  115. {
  116. #asm
  117. #if __FIRST_ARG_IN_AX__
  118. mov bx,sp
  119. mov dl,al
  120. mov ax,[bx+2]
  121. mov dh,al
  122. #else
  123. mov bx,sp
  124. mov ax,[bx+4]
  125. mov dh,al
  126. mov ax,[bx+2]
  127. mov dl,al
  128. #endif
  129. mov ah,#$02
  130. mov bx,#7
  131. int $10
  132. #endasm
  133. }
  134. #endif
  135. /****************************************************************************/
  136. #ifdef L_bios_rdline
  137. bios_rdline(buf, len)
  138. char * buf;
  139. int len;
  140. {
  141. int ch;
  142. int pos=0;
  143. if( len < 0 ) { errno = EINVAL; return -1; }
  144. if( len == 0 )
  145. {
  146. if( kbhit() == 0 ) return 0;
  147. errno = EINTR;
  148. return -1;
  149. }
  150. if( len == 1 )
  151. {
  152. buf[0]=((ch=getch())&0xFF?ch&0xFF:((ch>>8)&0xFF|0x80));
  153. return 1;
  154. }
  155. for(ch=0;;)
  156. {
  157. if(ch != '\003')
  158. {
  159. ch = getch();
  160. if( pos == 0 && (ch&0xFF) == 0 )
  161. {
  162. buf[0] = ((ch>>8)|0x80);
  163. return 1;
  164. }
  165. ch &= 0x7F;
  166. }
  167. if( ch == '\r' )
  168. {
  169. putch('\n');
  170. buf[pos++] = '\n';
  171. return pos;
  172. }
  173. if( ch >= ' ' && ch != 0x7F && pos < len-1)
  174. putch(buf[pos++] = ch);
  175. else if( (ch == '\003' || ch == '\b') && pos > 0 )
  176. {
  177. putch('\b'); putch(' '); putch('\b');
  178. pos--;
  179. }
  180. else if( ch == '\003' )
  181. return 0;
  182. else
  183. putch('\007');
  184. }
  185. }
  186. #endif
  187. /****************************************************************************/
  188. #endif
  189. #endif
  190. #endif