home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff369.lzh / VaxTerm / src / funcs.c < prev    next >
C/C++ Source or Header  |  1990-08-15  |  8KB  |  340 lines

  1. #include <exec/types.h>
  2. #include <exec/io.h>
  3. #include <devices/keymap.h>
  4. #include <hardware/blit.h>
  5. #include <graphics/text.h>
  6. #include <graphics/sprite.h>
  7. #include <graphics/rastport.h>
  8. #include <intuition/intuition.h>
  9. #include <proto/intuition.h>
  10. #include <proto/dos.h>
  11. #include <proto/exec.h>
  12. #include <proto/graphics.h>
  13.  
  14. #include "main.h"
  15.  
  16. void reset(register struct console *con)
  17. {
  18. register struct so  *sop;
  19. register USHORT     cnt;
  20.  
  21. con->gstat = ON;
  22. con->tstat = 0;
  23. con->stat = 0;
  24. con->top = 1;
  25. con->bot = rows;
  26. con->row = 1;
  27. con->col = 1;
  28. for (cnt = 0; cnt < rows; cnt++) *(con->rows + cnt + 1) = 0;
  29. con->attr = 0;
  30. con->gset[0] = ASCII;
  31. con->gset[1] = GRAPHICS;
  32. con->gset[2] = SUPPLEMENTAL;
  33. con->gset[3] = TECHNICAL;
  34. setlset(con,0);
  35. setrset(con,2);
  36. con->s_row = con->row;
  37. con->s_col = con->col;
  38. con->s_attr = con->attr;
  39. for (cnt = 0; cnt < SETS; cnt++)
  40.     con->s_mset[cnt] = con->mset[cnt] = con->s_gset[cnt] = con->gset[cnt];
  41. con->slset = con->s_lset = con->lset;
  42. con->s_rset = con->rset;
  43. con->s_tstat = con->tstat;
  44. con->nstat = 0;
  45. con->ordc = 0;
  46. con->ordcol = 1;
  47. setmem(con->tabs,COLUMNS,0);
  48. for (cnt=0; cnt < COLUMNS; cnt+=8) con->tabs[cnt] = 1;
  49. modifyattr(con);
  50. showcursor(con);
  51. SetRast(con->rp,BACKGROUND_PEN);
  52. sop = &res;
  53. while (sop != NULL) {
  54.     if (sop->type == SO_SETUP) sop->active = FALSE;
  55.     sop = sop->next;
  56.     }
  57. num.active = TRUE;
  58. over.active = TRUE;
  59. cret.active = TRUE;
  60. trunc.active = TRUE;
  61. mult.active = TRUE;
  62. bit_8.active = TRUE;
  63. curson.active = TRUE;
  64. }
  65.  
  66. void cursorup(register struct console *con,USHORT cnt)
  67. {
  68. register UBYTE  *src,*dst;
  69. USHORT          lines = 0;
  70.  
  71. while (cnt--) {
  72.     if (con->row == con->top) {
  73.         ScrollRaster(con->rp,0,-YSIZE,0,(con->top - 1) * YSIZE,
  74.                                 WIDTH-1,con->bot * YSIZE - 1);
  75.         lines++;
  76.         }
  77.     else if (con->row > 1) con->row--;
  78.     }
  79. if (lines) {
  80.     cnt = con->bot - con->top + 1;
  81.     if (lines > cnt) lines = cnt;
  82.     cnt -= lines;
  83.     dst = con->rows + con->bot;
  84.     src = con->rows + (con->bot - lines);
  85.     while (cnt--) *dst-- = *src--;
  86.     while (lines--) *dst-- = 0;
  87.     }
  88. }
  89.  
  90. void cursordown(register struct console *con,USHORT cnt)
  91. {
  92. register UBYTE  *src,*dst;
  93. USHORT          lines = 0;
  94.  
  95. while (cnt--) {
  96.     if (con->row == con->bot) {
  97.         ScrollRaster(con->rp,0,YSIZE,0,(con->top - 1) * YSIZE,
  98.                                 WIDTH - 1,con->bot * YSIZE - 1);
  99.         lines++;
  100.         }
  101.     else if (con->row < rows) con->row++;
  102.     }
  103. if (lines) {
  104.     cnt = con->bot - con->top + 1;
  105.     if (lines > cnt) lines = cnt;
  106.     cnt -= lines;
  107.     dst = con->rows + con->top;
  108.     src = con->rows + (con->top + lines);
  109.     while (cnt--) *dst++ = *src++;
  110.     while (lines--) *dst++ = 0;
  111.     }
  112. }
  113.  
  114. void cursorleft(register struct console *con,register USHORT cnt)
  115. {
  116. while (cnt--) {
  117.     if (con->col <= 1) {
  118.         if (con->tstat & WRAP) cursoraboveline(con);
  119.         }
  120.     else con->col--;
  121.     }
  122. }
  123.  
  124. void cursorright(register struct console *con,register USHORT cnt)
  125. {
  126. while (cnt--) {
  127.     if (con->col >= COLUMNS) {
  128.         if (con->tstat & WRAP) cursornextline(con);
  129.         }
  130.     else con->col++;
  131.     }
  132. }
  133.  
  134. void cursornextline(register struct console *con)
  135. {
  136. con->col = 1;
  137. cursordown(con,1);
  138. }
  139.  
  140. void cursoraboveline(register struct console *con)
  141. {
  142. con->col = COLUMNS;
  143. cursorup(con,1);
  144. }
  145.  
  146. void hidecursor(register struct console *con)
  147. {
  148. SetRGB4(&con->scr->ViewPort,17 + (con->sp->num >> 1) * 4,0,0,0);
  149. SetRGB4(&con->scr->ViewPort,18 + (con->sp->num >> 1) * 4,0,0,0);
  150. SetRGB4(&con->scr->ViewPort,19 + (con->sp->num >> 1) * 4,0,0,0);
  151. }
  152.  
  153. void showcursor(register struct console *con)
  154. {
  155. SetRGB4(&con->scr->ViewPort,17 + (con->sp->num >> 1) * 4,12,6,0);
  156. SetRGB4(&con->scr->ViewPort,18 + (con->sp->num >> 1) * 4,12,12,12);
  157. SetRGB4(&con->scr->ViewPort,19 + (con->sp->num >> 1) * 4,15,15,15);
  158. }
  159.  
  160. void modifyattr(register struct console *con)
  161. {
  162. SetSoftStyle(con->rp,con->attr,FSF_BOLD|FSF_ITALIC|FSF_UNDERLINED);
  163. }
  164.  
  165. void insertlines(register struct console *con,USHORT cnt)
  166. {
  167. register UBYTE  *src,*dst;
  168. USHORT          lines = 0;
  169.  
  170. if ((con->row >= con->top)&&(con->row <= con->bot)) {
  171.     if (cnt) {
  172.         lines = con->bot - con->row;
  173.         if (cnt > lines) cnt = lines;
  174.         ScrollRaster(con->rp,0,-YSIZE * cnt,0,
  175.                      (con->row - 1) * YSIZE,WIDTH - 1,con->bot * YSIZE - 1);
  176.         lines -= cnt;
  177.         dst = con->rows + con->bot + 1;
  178.         src = con->rows + (con->bot - cnt);
  179.         while (lines--) *dst-- = *src--;
  180.         while (cnt--) *dst-- = 0;
  181.         }
  182.     }
  183. }
  184.  
  185. void insertchars(register struct console *con,USHORT cnt)
  186. {
  187. USHORT y;
  188.  
  189. if (con->col < COLUMNS) {
  190.     y = con->row * YSIZE;
  191.     ScrollRaster(con->rp,-XSIZE * cnt,0,
  192.                  (con->col - 1) * XSIZE,y - YSIZE,WIDTH - 1,y - 1);
  193.     }
  194. }
  195.  
  196. void deletechars(register struct console *con,USHORT cnt)
  197. {
  198. USHORT y;
  199.  
  200. if (con->col < COLUMNS) {
  201.     y = con->row * YSIZE;
  202.     ScrollRaster(con->rp,XSIZE * cnt,0,
  203.                  (con->col - 1) * XSIZE,y - YSIZE,WIDTH - 1,y - 1);
  204.     }
  205. *(con->rows + con->row) = 0;
  206. }
  207.  
  208. void deletelines(register struct console *con,USHORT cnt)
  209. {
  210. register UBYTE  *src,*dst;
  211. USHORT          lines = 0;
  212.  
  213. if ((con->row >= con->top)&&(con->row <= con->bot)) {
  214.     if (cnt) {
  215.         lines = con->bot - con->row + 1;
  216.         if (cnt > lines) cnt = lines;
  217.         ScrollRaster(con->rp,0,YSIZE * cnt,0,
  218.                      (con->row - 1) * YSIZE,WIDTH - 1,con->bot * YSIZE - 1);
  219.         lines -= cnt;
  220.         dst = con->rows + con->row;
  221.         src = con->rows + (con->row + cnt);
  222.         while (lines--) *dst++ = *src++;
  223.         while (cnt--) *dst++ = 0;
  224.         }
  225.     }
  226. }
  227.  
  228. void erasechars(register struct console *con,register USHORT cnt)
  229. {
  230. register USHORT col,y;
  231.  
  232. col = con->col + cnt - 1;
  233. if (col > COLUMNS) col = COLUMNS;
  234. y = con->row * YSIZE;
  235. cleararea(con->rp,(USHORT)((con->col - 1) * XSIZE),
  236.             (USHORT)(y - YSIZE),(USHORT)(col * XSIZE),y);
  237. *(con->rows + con->row) = 0;
  238. }
  239.  
  240. void eraselines(register struct console *con,register USHORT cnt)
  241. {
  242. register UBYTE  *dst = con->rows + con->row;
  243. register USHORT row;
  244.  
  245. row = con->row + cnt;
  246. if (row > rows) row = rows;
  247. cleararea(con->rp,0,(USHORT)((con->row-1)*YSIZE),WIDTH,(USHORT)(row * YSIZE));
  248. while (cnt--) *dst++ = 0;
  249. }
  250.  
  251. void eraselinebeg(register struct console *con)
  252. {
  253. register USHORT y;
  254.  
  255. if (con->col > 1) {
  256.     y = con->row * YSIZE;
  257.     cleararea(con->rp,0,(USHORT)(y - YSIZE),(USHORT)(con->col * XSIZE),y);
  258.     }
  259. *(con->rows + con->row) = 0;
  260. }
  261.  
  262. void erasescrbeg(register struct console *con)
  263. {
  264. register UBYTE  *dst = con->rows;
  265. register USHORT cnt = con->row - 1;
  266.  
  267. if (con->row > 1) cleararea(con->rp,0,0,WIDTH,(USHORT)(cnt * YSIZE));
  268. eraselinebeg(con);
  269. while (cnt--) *(++dst) = 0;
  270. }
  271.  
  272. void newline(register struct console *con)
  273. {
  274. cursornextline(con);
  275. insertlines(con,1);
  276. }
  277.  
  278. void cleararea(struct RastPort *rp,USHORT x1,USHORT y1,USHORT x2,USHORT y2)
  279. {
  280. ClipBlit(rp,x1,y1,rp,x1,y1,x2 - x1,y2 - y1,0);
  281. }
  282.  
  283. void textout(register struct console *con)
  284. {
  285. register USHORT col = con->ordcol;
  286. register SHORT  chars = con->ordc;
  287. register UBYTE  width = *(con->rows + con->row);
  288. register USHORT tcol;
  289.  
  290. if (width) {
  291.     col <<= 1;
  292.     col--;
  293.     if (con->tstat & INSERT) {
  294.         tcol = con->col;
  295.         con->col = col;
  296.         insertchars(con,(USHORT)(chars << 1));
  297.         con->col = tcol;
  298.         }
  299.     }
  300. else {
  301.     if (con->tstat & INSERT) {
  302.         tcol = con->col;
  303.         con->col = col;
  304.         insertchars(con,chars);
  305.         con->col = tcol;
  306.         }
  307.     }
  308. MOVE(con->rp,con->row,col);
  309. if (con->attr & NEGATIVE) {
  310.     SetAPen(con->rp,BACKGROUND_PEN);
  311.     SetBPen(con->rp,FOREGROUND_PEN);
  312.     Text(con->rp,con->ordtext,chars);
  313.     SetAPen(con->rp,FOREGROUND_PEN);
  314.     SetBPen(con->rp,BACKGROUND_PEN);
  315.     }
  316. else Text(con->rp,con->ordtext,chars);
  317. if (width) {
  318.     if (col + (chars << 1) > (COLUMNS+1)) chars = ((COLUMNS+1) - col) >> 1;
  319.     if (chars > 0)
  320.         stretch(con->rp,(col - 1) * XSIZE,(con->row - 1) * YSIZE,
  321.                 chars * XSIZE,YSIZE,width);
  322.     }
  323. con->ordc = 0;
  324. }
  325.  
  326. void cursorout(register struct console *con)
  327. {
  328. USHORT col;
  329.  
  330. col = con->col;
  331. if (col < 1) col = 1;
  332. if (*(con->rows + con->row)) col <<= 1;
  333. if (col > COLUMNS) col = COLUMNS;
  334. if (con->ordc) textout(con);
  335. MoveSprite(NULL,con->sp
  336.             ,con->scr->LeftEdge + (col - 1) * (XSIZE / 2) - 2,
  337.             con->scr->TopEdge + (con->row - 1) * YSIZE);
  338. DRAWCURSOR(con->rp,&con->srp,con->row,col);
  339. }
  340.