MYPRINT.C 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /*
  2. Copyright (C) 1994-1995 Apogee Software, Ltd.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #include <stdio.h>
  16. #include <stdarg.h>
  17. #include <stdlib.h>
  18. #include "myprint.h"
  19. static unsigned short disp_offset = 160 * 24;
  20. void DrawText
  21. (
  22. int x,
  23. int y,
  24. int ch,
  25. int foreground,
  26. int background
  27. )
  28. {
  29. char *vid;
  30. vid = ( char * )( 0xb0000 );
  31. vid += y * 160;
  32. vid += x * 2;
  33. if ( ch != NONE )
  34. {
  35. *vid = ch;
  36. }
  37. vid++;
  38. *vid = ( ( background & 0x0f ) << 4 ) | ( foreground & 0x0f );
  39. }
  40. void TextBox
  41. (
  42. int x1,
  43. int y1,
  44. int x2,
  45. int y2,
  46. int ch,
  47. int foreground,
  48. int background
  49. )
  50. {
  51. int x;
  52. int y;
  53. for( x = x1; x <= x2; x++ )
  54. {
  55. for( y = y1; y <= y2; y++ )
  56. {
  57. DrawText( x, y, ch, foreground, background );
  58. }
  59. }
  60. }
  61. void TextFrame
  62. (
  63. int x1,
  64. int y1,
  65. int x2,
  66. int y2,
  67. int type,
  68. int foreground,
  69. int background
  70. )
  71. {
  72. int x;
  73. int y;
  74. if ( type == 0 )
  75. {
  76. for( x = x1 + 1; x < x2; x++ )
  77. {
  78. DrawText( x, y1, type, foreground, background );
  79. DrawText( x, y2, type, foreground, background );
  80. }
  81. for( y = y1 + 1; y < y2; y++ )
  82. {
  83. DrawText( x1, y, type, foreground, background );
  84. DrawText( x2, y, type, foreground, background );
  85. }
  86. }
  87. if ( type == SINGLE_FRAME )
  88. {
  89. DrawText( x1, y1, 'Ú', foreground, background );
  90. DrawText( x2, y1, '¿', foreground, background );
  91. DrawText( x1, y2, 'À', foreground, background );
  92. DrawText( x2, y2, 'Ù', foreground, background );
  93. for( x = x1 + 1; x < x2; x++ )
  94. {
  95. DrawText( x, y1, 'Ä', foreground, background );
  96. DrawText( x, y2, 'Ä', foreground, background );
  97. }
  98. for( y = y1 + 1; y < y2; y++ )
  99. {
  100. DrawText( x1, y, '³', foreground, background );
  101. DrawText( x2, y, '³', foreground, background );
  102. }
  103. }
  104. if ( type == DOUBLE_FRAME )
  105. {
  106. DrawText( x1, y1, 'É', foreground, background );
  107. DrawText( x2, y1, '»', foreground, background );
  108. DrawText( x1, y2, 'È', foreground, background );
  109. DrawText( x2, y2, '¼', foreground, background );
  110. for( x = x1 + 1; x < x2; x++ )
  111. {
  112. DrawText( x, y1, 'Í', foreground, background );
  113. DrawText( x, y2, 'Í', foreground, background );
  114. }
  115. for( y = y1 + 1; y < y2; y++ )
  116. {
  117. DrawText( x1, y, 'º', foreground, background );
  118. DrawText( x2, y, 'º', foreground, background );
  119. }
  120. }
  121. }
  122. void mysetxy
  123. (
  124. int x,
  125. int y
  126. )
  127. {
  128. disp_offset = ( x * 2 ) + ( y * 160 );
  129. }
  130. void myputch
  131. (
  132. char ch
  133. )
  134. {
  135. int j;
  136. char *disp_start = (char *)( 0xb0000 );
  137. if ( disp_offset >= 160 * 24 )
  138. {
  139. for ( j = 160; j < 160 * 24; j += 2 )
  140. {
  141. *( disp_start + j - 160 ) = *( disp_start + j );
  142. }
  143. disp_offset = 160 * 23;
  144. for ( j = disp_offset; j < ( 160 * 24 ); j += 2 )
  145. {
  146. *( disp_start + j ) = ' ';
  147. }
  148. }
  149. if ( ch >= 32 )
  150. {
  151. *( disp_start + disp_offset ) = ch;
  152. disp_offset = disp_offset + 2;
  153. }
  154. if ( ch == '\r' )
  155. {
  156. disp_offset = disp_offset / 160;
  157. disp_offset = disp_offset * 160;
  158. }
  159. if ( ch == '\n' )
  160. {
  161. disp_offset = disp_offset + 160;
  162. if ( disp_offset < 160 * 24 )
  163. {
  164. for ( j = disp_offset; j < ( ( ( disp_offset / 160 ) + 1 ) *
  165. 160 ); j += 2 )
  166. {
  167. *( disp_start + j ) = ' ';
  168. }
  169. }
  170. }
  171. }
  172. int printstring
  173. (
  174. char *string
  175. )
  176. {
  177. int count;
  178. char *ptr;
  179. ptr = string;
  180. count = 0;
  181. while ( *ptr )
  182. {
  183. myputch( *ptr );
  184. count++;
  185. ptr++;
  186. }
  187. return( count );
  188. }
  189. int printnum
  190. (
  191. int number
  192. )
  193. {
  194. char string[ 100 ];
  195. int count;
  196. itoa( number, string, 10 );
  197. count = printstring( string );
  198. return( count );
  199. }
  200. int printunsigned
  201. (
  202. unsigned long number,
  203. int radix
  204. )
  205. {
  206. char string[ 100 ];
  207. int count;
  208. ultoa( number, string, radix );
  209. count = printstring( string );
  210. return( count );
  211. }
  212. int myprintf
  213. (
  214. char *fmt,
  215. ...
  216. )
  217. {
  218. va_list argptr;
  219. int count;
  220. char *ptr;
  221. return( 0 );
  222. // DEBUG
  223. mysetxy( 0, 0 );
  224. va_start( argptr, fmt );
  225. ptr = fmt;
  226. count = 0;
  227. while( *ptr != 0 )
  228. {
  229. if ( *ptr == '%' )
  230. {
  231. ptr++;
  232. switch( *ptr )
  233. {
  234. case 0 :
  235. return( EOF );
  236. break;
  237. case 'd' :
  238. count += printnum( va_arg( argptr, int ) );
  239. break;
  240. case 's' :
  241. count += printstring( va_arg( argptr, char * ) );
  242. break;
  243. case 'u' :
  244. count += printunsigned( va_arg( argptr, int ), 10 );
  245. break;
  246. case 'x' :
  247. case 'X' :
  248. count += printunsigned( va_arg( argptr, int ), 16 );
  249. break;
  250. }
  251. ptr++;
  252. }
  253. else
  254. {
  255. myputch( *ptr );
  256. count++;
  257. ptr++;
  258. }
  259. }
  260. va_end( argptr );
  261. return( count );
  262. }