123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832 |
- #define BUILDING_OPENDOORS
- #include <stdlib.h>
- #include <string.h>
- #include <stdio.h>
- #include "OpenDoor.h"
- #include "ODCore.h"
- #include "ODGen.h"
- #include "ODScrn.h"
- #include "ODKrnl.h"
- static BOOL bScrollAction = TRUE;
- ODAPIDEF BOOL ODCALL od_puttext(INT nLeft, INT nTop, INT nRight, INT nBottom,
- void *pBlock)
- {
- INT nRowLength = nRight - nLeft +1;
- INT nRowBytes = nRowLength * 2;
- char *pchTest;
- char *pchMemory;
- char *pBuffer=NULL;
- char *pchScreenBlock;
- INT nBlockRow = 0;
- INT nOutRow;
- INT nOutColour = 999;
- INT nOutColumn, nCheckColumn;
- char *pchMemBlock;
- INT nMoveCost = od_control.user_avatar ? 4 : 7;
- BYTE btMaxRight, btMaxBottom;
-
- TRACE(TRACE_API, "od_puttext()");
-
- if(!bODInitialized) od_init();
- OD_API_ENTRY();
-
- ODScrnGetTextInfo(&ODTextInfo);
-
- btMaxRight=ODTextInfo.winright-ODTextInfo.winleft+1;
- btMaxBottom=ODTextInfo.winbottom-ODTextInfo.wintop+1;
-
- if(nLeft<1 || nTop<1 || nRight>btMaxRight || nBottom>btMaxBottom
- || nTop > nBottom || nLeft > nRight || pBlock==NULL)
- {
- od_control.od_error = ERR_PARAMETER;
- OD_API_EXIT();
- return(FALSE);
- }
-
- if(!od_control.user_ansi && !od_control.user_avatar)
- {
- od_control.od_error = ERR_NOGRAPHICS;
- OD_API_EXIT();
- return(FALSE);
- }
-
- if(od_control.baud != 0)
- {
-
-
- if((pBuffer=malloc(nRowBytes*(nBottom-nTop+1)))==NULL)
- {
- od_control.od_error = ERR_MEMORY;
- OD_API_EXIT();
- return(FALSE);
- }
-
-
- if(!ODScrnGetText((BYTE)nLeft, (BYTE)nTop, (BYTE)nRight, (BYTE)nBottom,
- pBuffer))
- {
- od_control.od_error = ERR_PARAMETER;
- free(pBuffer);
- OD_API_EXIT();
- return(FALSE);
- }
- }
-
- if(!ODScrnPutText((BYTE)nLeft, (BYTE)nTop, (BYTE)nRight, (BYTE)nBottom,
- pBlock))
- {
- od_control.od_error = ERR_PARAMETER;
- if(pBuffer)
- free(pBuffer);
- OD_API_EXIT();
- return(FALSE);
- }
-
- if(od_control.baud != 0)
- {
-
- for(nOutRow=nTop;nOutRow<=nBottom;++nOutRow,++nBlockRow)
- {
-
- pchScreenBlock=(char *)pBuffer+(nRowBytes*nBlockRow);
-
- pchMemBlock=(char *)pBlock+(nRowBytes*nBlockRow);
-
- for(nOutColumn=0;nOutColumn<nRowLength;)
- {
-
-
- nCheckColumn=nOutColumn;
- pchMemory=((char *)pchMemBlock)+(nCheckColumn<<1);
- pchTest=((char *)pchScreenBlock)+(nCheckColumn<<1);
- for(;nCheckColumn<nRowLength;++nCheckColumn)
- {
- if(od_control.od_full_put) break;
-
- if((*pchMemory==' ' || *pchMemory==0) && (*pchTest==' ' || *pchTest=='\0'))
- {
-
- if((pchTest[1]&0x70) != (pchMemory[1]&0x70))
- {
- break;
- }
- }
-
- else if(*((WORD *)pchTest) != *((WORD *)pchMemory))
- {
-
- break;
- }
-
- pchTest+=2;
- pchMemory+=2;
- }
-
- if(nCheckColumn==nRowLength)
- {
-
- goto next_line;
- }
-
- if(nOutColumn == 0)
- {
-
- nOutColumn = nCheckColumn;
-
- if(od_control.user_avatar)
- {
-
- szODWorkString[0]=22;
- szODWorkString[1]=8;
- szODWorkString[2]=nOutRow;
- szODWorkString[3]=nLeft+nOutColumn;
- od_disp(szODWorkString,4,FALSE);
- }
- else
- {
-
- sprintf(szODWorkString,"x[%d;%dH",nOutRow,nLeft + nOutColumn);
- szODWorkString[0]=27;
- od_disp(szODWorkString, strlen(szODWorkString), FALSE);
- }
- }
-
-
-
-
- else if((nCheckColumn-nOutColumn)>nMoveCost)
- {
- nOutColumn=nCheckColumn;
-
- if(od_control.user_avatar)
- {
-
-
- szODWorkString[0]=22;
- szODWorkString[1]=8;
- szODWorkString[2]=nOutRow;
- szODWorkString[3]=nLeft+nOutColumn;
- od_disp(szODWorkString,4,FALSE);
- }
- else
- {
-
-
- sprintf(szODWorkString,"x[%d;%dH",nOutRow,nLeft + nOutColumn);
- szODWorkString[0]=27;
- od_disp(szODWorkString,strlen(szODWorkString),FALSE);
- }
- }
-
-
- pchTest=(char *)&pchMemBlock[nOutColumn*2];
- for(;nOutColumn<=nCheckColumn;++nOutColumn)
- {
- if(pchTest[1] != nOutColour)
- {
- od_set_attrib(nOutColour=pchTest[1]);
- }
- od_disp(pchTest,1,FALSE);
- pchTest++;
- pchTest++;
- }
- }
- next_line:
- ;
- }
-
- if(bScrollAction)
- {
- od_set_cursor(ODTextInfo.cury,ODTextInfo.curx);
- }
-
- free(pBuffer);
- }
-
- od_set_attrib(ODTextInfo.attribute);
-
- OD_API_EXIT();
- return(TRUE);
- }
- ODAPIDEF BOOL ODCALL od_gettext(INT nLeft, INT nTop, INT nRight, INT nBottom,
- void *pBlock)
- {
- BYTE btMaxRight, btMaxBottom;
-
- TRACE(TRACE_API, "od_gettext()");
-
- if(!bODInitialized) od_init();
- OD_API_ENTRY();
- ODScrnGetTextInfo(&ODTextInfo);
- btMaxRight=ODTextInfo.winright-ODTextInfo.winleft+1;
- btMaxBottom=ODTextInfo.winbottom-ODTextInfo.wintop+1;
- if(nLeft<1 || nTop<1 || nRight>btMaxRight || nBottom>btMaxBottom || !pBlock)
- {
- od_control.od_error = ERR_PARAMETER;
- OD_API_EXIT();
- return(FALSE);
- }
- if(!od_control.user_ansi && !od_control.user_avatar)
- {
- od_control.od_error = ERR_NOGRAPHICS;
- OD_API_EXIT();
- return(FALSE);
- }
- OD_API_EXIT();
- return(ODScrnGetText((BYTE)nLeft, (BYTE)nTop, (BYTE)nRight, (BYTE)nBottom,
- pBlock));
- }
- ODAPIDEF BOOL ODCALL od_scroll(INT nLeft, INT nTop, INT nRight, INT nBottom,
- INT nDistance, WORD nFlags)
- {
- BYTE btWidth, btHeight;
- BYTE btCount;
- BYTE btFirst, btLast;
- char szAVTSeq[7];
- void *pBlock;
- char szBlank[81];
- BYTE btKeepHeight;
- BYTE btMaxRight;
- BYTE btMaxBottom;
- tODScrnTextInfo TextState;
-
- TRACE(TRACE_API, "od_scroll()");
-
- if(!bODInitialized) od_init();
- OD_API_ENTRY();
-
- ODScrnGetTextInfo(&TextState);
-
- btWidth=nRight-nLeft+1;
- btHeight=nBottom-nTop+1;
-
-
- btKeepHeight=btHeight-((nDistance>=0) ? nDistance : -nDistance);
-
-
- btMaxRight=TextState.winright-TextState.winleft+1;
- btMaxBottom=TextState.winbottom-TextState.wintop+1;
-
- if(nLeft<1 || nTop<1 || nRight>btMaxRight || nBottom>btMaxBottom ||
- nLeft > nRight || nTop > nBottom)
- {
- od_control.od_error = ERR_PARAMETER;
- OD_API_EXIT();
- return(FALSE);
- }
-
- if(!od_control.user_ansi && !od_control.user_avatar)
- {
- od_control.od_error = ERR_NOGRAPHICS;
- OD_API_EXIT();
- return(FALSE);
- }
-
-
- if(nDistance == 0)
- {
- OD_API_EXIT();
- return(TRUE);
- }
-
- if(nDistance>0)
- {
-
- if(nDistance>btHeight)
- {
- nDistance=btHeight;
- }
-
- btFirst=nBottom-(nDistance-1);
- btLast=nBottom;
- }
-
- else
- {
-
- if(nDistance<-btHeight)
- {
- nDistance=-btHeight;
- }
-
- btFirst=nTop;
- btLast=nTop-nDistance-1;
- }
-
- if(od_control.user_avatar)
- {
-
-
- szAVTSeq[0]=22;
-
- if(nDistance>0)
- {
-
- szAVTSeq[1]=10;
- szAVTSeq[2]=nDistance;
-
- ODScrnCopyText((BYTE)nLeft, (BYTE)(nTop + nDistance), (BYTE)nRight,
- (BYTE)nBottom, (BYTE)nLeft, (BYTE)nTop);
- }
-
- else
- {
-
- szAVTSeq[1]=11;
- szAVTSeq[2]=-nDistance;
-
- ODScrnCopyText((BYTE)nLeft, (BYTE)nTop, (BYTE)nRight,
- (BYTE)(nBottom + nDistance), (BYTE)nLeft, (BYTE)(nTop - nDistance));
- }
-
- szAVTSeq[3]=nTop;
- szAVTSeq[4]=nLeft;
- szAVTSeq[5]=nBottom;
- szAVTSeq[6]=nRight;
-
- od_disp(szAVTSeq,7,FALSE);
-
- for(btCount=0;btCount<btWidth;++btCount) szBlank[btCount]=' ';
- szBlank[btCount]='\0';
-
- for(;btFirst<=btLast;++btFirst)
- {
- ODScrnSetCursorPos((BYTE)nLeft, btFirst);
- ODScrnDisplayString(szBlank);
- }
-
- ODScrnSetCursorPos(TextState.curx,TextState.cury);
- }
-
- else
- {
-
-
- if(btKeepHeight>0)
- {
-
- if((pBlock=malloc(btKeepHeight*btWidth*2))==NULL)
- {
-
- od_control.od_error = ERR_MEMORY;
- OD_API_EXIT();
- return(FALSE);
- }
-
- if(nDistance > 0)
- {
-
-
- od_gettext(nLeft,nTop+nDistance,nRight,nBottom,pBlock);
- bScrollAction=FALSE;
- od_puttext(nLeft,nTop,nRight,nBottom-nDistance,pBlock);
- bScrollAction=TRUE;
- }
-
- else
- {
-
-
- od_gettext(nLeft,nTop,nRight,nBottom+nDistance,pBlock);
- bScrollAction=FALSE;
- od_puttext(nLeft,nTop-nDistance,nRight,nBottom,pBlock);
- bScrollAction=TRUE;
- }
-
- free(pBlock);
- }
-
- if(!(nFlags&SCROLL_NO_CLEAR))
- {
-
- for(;btFirst<=btLast;++btFirst)
- {
-
- od_set_cursor(btFirst,nLeft);
-
-
-
- if(nRight == 80)
- {
- od_clr_line();
- }
-
-
-
- else
- {
- od_repeat(' ',btWidth);
- }
- }
- }
-
- od_set_cursor(TextState.cury,TextState.curx);
- }
-
- OD_API_EXIT();
- return(TRUE);
- }
- ODAPIDEF BOOL ODCALL od_save_screen(void *pBuffer)
- {
- char btHeight;
- tODScrnTextInfo TextState;
-
- TRACE(TRACE_API, "od_save_screen()");
-
- if(!bODInitialized) od_init();
- OD_API_ENTRY();
-
- ODScrnGetTextInfo(&TextState);
- if(TextState.winleft!=1 || TextState.winright!=80 || !pBuffer)
- {
- od_control.od_error = ERR_PARAMETER;
- OD_API_EXIT();
- return(FALSE);
- }
-
- ((char *)pBuffer)[0]=TextState.curx;
- ((char *)pBuffer)[1]=TextState.cury;
-
- ((char *)pBuffer)[2]=TextState.attribute;
-
- ((char *)pBuffer)[3]=btHeight=TextState.winbottom-TextState.wintop+1;
-
- OD_API_EXIT();
- return(ODScrnGetText(1,1,80,btHeight,(char *)pBuffer+4));
- }
- ODAPIDEF BOOL ODCALL od_restore_screen(void *pBuffer)
- {
- char *pch;
- char btPos;
- char chLast;
- char *pchTextBuffer;
- char btHeight;
- int nToReturn=TRUE;
- tODScrnTextInfo TextState;
- char btLine;
- char btDistance=0;
- char btCursorRow;
-
- TRACE(TRACE_API, "od_restore_screen()");
-
- if(!bODInitialized) od_init();
- OD_API_ENTRY();
-
- ODScrnGetTextInfo(&TextState);
- if(TextState.winleft!=1 || TextState.winright!=80 || !pBuffer)
- {
- od_control.od_error = ERR_PARAMETER;
- OD_API_EXIT();
- return(FALSE);
- }
-
- btHeight=TextState.winbottom-TextState.wintop+1;
-
-
- if(btHeight<((char *)pBuffer)[3])
- {
-
-
- btDistance = btHeight - ((char *)pBuffer)[3];
- }
- else if(btHeight > ((char *)pBuffer)[3])
- {
-
-
- btHeight=((char *)pBuffer)[3];
- }
-
- od_clr_scr();
-
- if(od_control.user_avatar || od_control.user_ansi)
- {
-
- bScrollAction=FALSE;
- nToReturn=od_puttext(1,1,80,btHeight,(char *)pBuffer+(4+((int)btDistance*160)));
- bScrollAction=TRUE;
-
- od_set_cursor(((char *)pBuffer)[1],((char *)pBuffer)[0]);
-
- od_set_attrib(((char *)pBuffer)[2]);
- }
-
- else
- {
-
-
-
- pchTextBuffer=(char *)pBuffer+4;
-
- btCursorRow=((char *)pBuffer)[1];
-
- for(btLine=1;btLine<=btHeight;++btLine)
- {
-
- pch=(char *)pchTextBuffer+158;
-
-
- for(chLast=80;chLast>1;)
- {
-
- if(*pch==32 || *pch==0)
- {
-
- --chLast;
- pch-=2;
- }
-
- else
- {
- break;
- }
- }
-
- if(btLine==btCursorRow)
- {
-
-
-
-
-
-
-
- if(chLast>=((char *)pBuffer)[0])
- {
- chLast=((char *)pBuffer)[0]-1;
- }
- }
-
- pch = (char *)pchTextBuffer;
- for(btPos=1;btPos<=chLast;++btPos)
- {
- od_putch(*pch);
- pch+=2;
- }
-
-
- if(btLine==btCursorRow)
- {
- break;
- }
-
-
- if(chLast != 80)
- {
- od_disp_str("\n\r");
- pchTextBuffer+=160;
- }
- }
- }
-
- OD_API_EXIT();
- return(nToReturn);
- }
|