Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import "std.zh" //Keyboard.zh is included
- /* Beam=Style TBA Text Parser
- I hope to support the full Beam 'Inglish' with this, eventually, but
- if not, it should be a modest text parser tor TBA style quests, or even
- normal quests where the developer can read strings to find command keywords and
- act on them.
- At present, there is a five WORD stack, and a heap that can support caching
- commands, offsetting them, and acting on them later.
- This is not fully-considered, as Beam's 'Inglish' parser supported conjunctions
- and prepositions. Adding those, or at least the logic for those will require a
- larger stack, and some unconventional memory management.
- Beam's maximum parse string length was 128-characters.
- Command procedure:
- User types commands to the commandline[]
- Scan the commands, each time we hit a space, determine what command it is, and
- add its numeric value to the heap.
- When we reach tne edn of the line, scan the heap
- place instructions onto the stack, ignoring preopositions until we hit an AND instruction
- When we hit an AND instruction, process the stack instructions, pop them off
- then return to the heap, and repeat until we are out of instructions.
- When we are out of instructions, pop off the stack, clear the heap, and end the turn.
- */
- //int instructions[214747];
- int GAMERAM[214747]; //Holds values of the game engine.
- //need arrays and getptr for each typed array, too.
- int TURN; //remember to handle rollover
- void IncrementTurn(){ TURN += 2;}
- void BattleTurn(){ TURN++; }
- bool PlayerTurn() { return ( TURN % 2 == 0 ); }
- bool EnemyTurn() { return ( TURN % 2 != 0 ) ; }
- int tempbuffer[55];
- int outputbuffers[10];
- void OutputText(int bufferID, int outoutID){
- //copy text from input to output
- }
- void GameText(){
- //string processor
- }
- //v0.22, new
- //Unmeric instruction values to match cases.
- int HEAP[32]; //What is the maximum number of instructions with conjunctions?
- int STACK[32]; //What is the maximum number of instructions, without conjunctions?
- int ram[64]; //RAM
- //String buffers
- int CURWORD[18]; //Current operational instruction WORD, for when converting a word to an instruction.
- int commandline[129];//128 chars max on the line, plus NULL.
- int commandlineoverlay[129]; //128 + NULL
- int command[18]; //Holds the present action command. Deprecated by stack procedure.
- int VARS[256]; //holds code support variables.
- int timer = KEY_DELAY; bool cantype = true;
- bool ShiftKey; int q;
- int temp_q; int cursorblink = 0;
- int ram[32];
- //int curbuffer = 0;
- //Vars indices:
- const int RAM_q = 0;
- /*
- int stack[5]; //holds the four possible command components
- int heap[32]; //May not need it, but it might be good for something.
- int ADJ_NOUN[36]; //buffer for a combined adjective and noun pairing.
- //Used to compare the names of screen items, and enemies.
- //36 chars = 17+17+space+NULL Probably too long for any pair, but that is a minor waste.
- */
- int buffer[214747]; //={CURSOR_POINT_CHAR, CHAR_SPACE};
- int bufferoverlay[214747]; //handles the cursor.
- //Perhaps a SAY string?
- //ASM TYPES
- #define INVALID -1;
- #define GLOBAL 0; //Pause, Unpause, Save, Load, Inventory, Score, Print, NoPrint
- #define ACTION 1;
- #define NOUN 2;
- #define ADJECTIVE 3;
- #define ENEMY
- #define NPC
- #define OBJECT
- #define PREPOSITION
- #define CONJUNCTION
- /* Do we want to allow constructing very complex chains, such as OLD KEY as two
- compinents, or do we want to hardcode OLD KEY or HIDEOUS TROLL as one string?
- Clearly, the latter is easier.
- */
- //ASM DEFINE - List priority ( length ) ( alpha ) -- or ( length ) ( common ) ?
- /* We sort this based on the number of characters, and then alphabetic, so that we speed up
- parse string compares. Smaller strings compare and resolve faster, and characters
- are checked in sequence, so the sooner it finds a match, the sooner it returns,
- similar to a short-circuit, but code-controlled.
- */
- #define D 1;
- #define E 2;
- #define I 3;
- #define L 4;
- #define N 5;
- #define S 6;
- #define U 7;
- #define W 8;
- #define GO 9;
- #define NE 10;
- #define NW 11;
- #define SE 12;
- #define SW 13;
- #define UP 14;
- #define ASK 15;
- #define DIG 16;
- #define EAT 17;
- #define GET 18;
- #define PUT 19;
- #define SAY 20;
- #define TIE 21;
- #define USE 22;
- #define RUN 23;
- #define DOWN 24;
- #define DROP 25;
- #define EAST 26;
- #define FILL 27;
- #define GIVE 28;
- #define HELP 29;
- #define KILL 30;
- #define LOAD 31;
- #define LOCK 32;
- #define LOOK 33;
- #define OPEN 34;
- #define PICK 35;
- #define QUIT 36;
- #define SAVE 37;
- #define SWIM 38;
- #define TAKE 39;
- #define TURN 40;
- #define WAIT 41;
- #define WEAR 42;
- #define WEST 43;
- #define BREAK 44;
- #define CARRY 45;
- #define CLIMB 46;
- #define CLOSE 47;
- #define CROSS 48;
- #define DRINK 49;
- #define EMPTY 50;
- #define ENTER 51;
- #define EQUIP 52;
- #define NORTH 53;
- #define PAUSE 54;
- #define PRINT 55; //output every instruction to allegro.log
- #define SCORE 56;
- #define SHOOT 57;
- #define SOUTH 58;
- #define THROW 59;
- #define UNTIE 60;
- #define ATTACK 61;
- #define FOLLOW 62;
- #define UNLOCK 63;
- #define EXAMINE 64;
- #define NOPRINT 65; //stop sending instructions to allegro.log
- #define INVENTORY 66;
- #define NORTHEAST 67;
- #define NORTHWEST 68;
- #define SOUTHEAST 69;
- #define SOUTHWEST 70;
- #define DICTIONARY 71;
- #define MAXCOMMANDS 72;
- //! These need to become defines.
- const int SFX_KEYPRESS = 58;
- const int LINKTILEOFFSET = -261; const int KEY_DELAY = 65; //Trying this as 6.5 and timer changes as 1.0, using 65 and 10
- const int LINE_LENGTH = 54; const int BUFFER_LENGTH = 55;
- //int b1[55]; int b2[55]; int b3[55]; int b4[55]; int b5[55];
- //int b6[55]; int b7[55]; int b8[55]; int b9[55]; int b10[55];
- //int bufptr;
- const int CHAR_WIDTH = 4;
- const int CURSOR_WIDTH = 4;
- const int CURSOR_POINT_CHAR = 62;
- const int CURSOR_Y_OFFSET = 4;
- const int CURSOR_X_OFFSET = 4;
- const int BUFFER_OUTPUT_X = 0;
- const int BUFFER_OUTPUT_Y = 0;
- const int CURSOR_BLINK_DUR = 70;
- const int CURSOR_Y_OFS = 1;
- int matchaction(int command){
- }
- //Returns how many total WORDS are in one instruction set.
- int numinstructions(int _buffer){
- ///count the number of spaces in the buffer. THe number of total instructions
- ///equals the number of spaces, plus onwe
- int spc; int nextchar; bool trailspacedone;
- INSTRUCTIONS_SIZE = SizeOfArray(_buffer);
- for ( int q = SizeOfArray(_buffer); q >= 0; q-- ) {
- //don't count trailing spaces, or contiguous spaces.
- if ( _buffer[q] == CHAR_SPACE ) {
- if ( __buffer[q-1] !isLetter() && !trailspacedone ) {
- trailspacedone = false; continue;
- }
- else if ( __buffer[q-1] isLetter() && !trailspacedone ) {
- trailspacedone = true;
- spc++; continue;
- }
- else if ( __buffer[q-1] !isLetter() && trailspacedone ) continue;
- else if ( __buffer[q-1] isLetter() && trailspacedone ) {
- spc++;
- }
- }
- }
- //WORDCOUNT[0] = spc+1; //store the total number of words.
- return spc+1;
- }
- //int WORDS[4];
- //holds the indices of each word?
- #define MAX_WORDS 5; //Max words per instruction. SAY GANDALF GIVE OLD KEY
- //Store each word in these buffers.
- int WORD_1[18];
- int WORD_2[18];
- int WORD_3[18];
- int WORD_4[18];
- int WORD_5[18];
- int WordCount; //how many words this time, and the index at which they occur.
- int INSTRUCTIONS_SIZE; //Used by functions to minimise loop wastage.
- //Stores the present commands in the text parsing buffer into command slots.
- void GetInstructions(int _buffer){
- int wordcount = numinstructions(_buffer);
- int WORDS[5]={WORD_1, WORD_2, WORD_3, WORD4, WORD_5}; //holds the array pointers.
- //This time, read the array forward.
- int spc; int nextchar; bool trailspacedone; int curword = 0;
- for ( ram[RAM_q] = 0; ram[RAM_q] < INSTRUCTIONS_SIZE; ram[RAM_q]++ ) {
- //don't count trailing spaces, or contiguous spaces.
- if ( curword < wordcount ) {
- do {
- int ptr = WORDS[curword];
- ptr[q] = _buffer[q];
- }
- while ( _buffer[q] != CHAR_SPACE && spc < wordcount );
- curword++;
- }
- }
- }
- //Add instructions to the 'stack', starting with a COMMAND, then its variables.
- void StringToCommand(){
- int buf[3] = "0"; int buf2[2];
- //one string per command
- //command lengths
- //this speeds up matching the string to a command by finding one of the same length
- int commandlengths[]={5, 4, 4, 5, 2, 4, 4, 4, 4, 4, 3, 3, 6, 3}; //list the length of each command in order.
- //match the
- int legalcommands[]="
- 01NORTH
- 2EAST
- 3WEST
- 4SOUTH
- 5UP
- 6DOWN
- 7LOOK
- 8TAKE
- 9WAIT
- 10ASK
- 11SAY
- 12ATTACK
- 13USE
- ";
- //We then check the length of the command
- /* We probably don't need a switch for this. Just do:
- */
- //Do we want a switch for this?
- //switch (INSTRUCTIONS_SIZE){
- // case 1:
- //COMMAND only, no verb, no say.
- //Parse WORD_1
- int curWord = 0;
- int WORDS[5]={WORD_1, WORD_2, WORD_3, WORD4, WORD_5}; //holds the array pointers.
- //First, the command
- strcpy(WORDS[curWord], temp_command); //store the present word
- for ( int q = 0; q < SizeOfArray(commandlengths); q++ ) {
- bool match;
- if ( commandlengths[q] == strlen(temp_command) {
- //if the position of q is < 10, append a leading 0
- if ( q < 10 ) {
- itoa(q,buf2);
- strcat(buf2, but);
- }
- //otherwise, just store it
- itoa(q, buf); //overwrite the temp buffer.
- //find that number in legal commands
- for ( int w = 0; 2 < SizeOfArraylegalcommands; w++ ){
- //! stringparser finds a matching string, and returns its position?
- //if ( stringparser(buf) ) return q; //if the string matches
- //This is the inverse of the old string parser, so instead, let's do this
- int bufcompare[18];
- stringparser(q, bufcompare); //copy instruction q into the compare buffer
- for ( int e = 0; e < strlen(bufcompare); e++ ) {
- //compare each index
- if ( temp_command[e] != bufcompare[3] ) {
- //failed to compare
- match = false;
- break;
- }
- match = true; //we found the match.
- //return atoi(buf); //return the command ID.
- //! no, we want to store the commcomamnd, to parse,
- //! and add variables to it.
- stack[curWord] = atoi(buf);
- break;
- }
- //the parsed string, thast is its command number.
- //so, return it.
- }
- break; //if we fail, we fall through.
- }
- if ( !match ) stack[curWord] = INVALID; //return INVALID; //invalid command
- //!! no, put INVALID into the stack.
- }
- curWord++; //Increase the SP.
- int legal_variables="
- ";
- //Then, its VARIABLES, if any.
- for ( int q = 1; q < WordCount; q++ ) {
- strcpy(WORDS[curWord], temp_command); //store the present word
- for ( int q = 0; q < SizeOfArray(commandlengths); q++ ) {
- bool match;
- if ( commandlengths[q] == strlen(temp_command) {
- //if the position of q is < 10, append a leading 0
- if ( q < 10 ) {
- itoa(q,buf2);
- strcat(buf2, but);
- }
- //otherwise, just store it
- itoa(q, buf); //overwrite the temp buffer.
- //find that number in legal commands
- for ( int w = 0; 2 < SizeOfArraylegalcommands; w++ ){
- //! stringparser finds a matching string, and returns its position?
- //if ( stringparser(buf) ) return q; //if the string matches
- //This is the inverse of the old string parser, so instead, let's do this
- int bufcompare[18];
- stringparser(q, bufcompare); //copy instruction q into the compare buffer
- for ( int e = 0; e < strlen(bufcompare); e++ ) {
- //compare each index
- if ( temp_command[e] != bufcompare[3] ) {
- //failed to compare
- match = false;
- break;
- }
- match = true; //we found the match.
- //return atoi(buf); //return the command ID.
- //! no, we want to store the commcomamnd, to parse,
- //! and add variables to it.
- stack[curWord] = atoi(buf);
- break;
- }
- //the parsed string, thast is its command number.
- //so, return it.
- }
- break; //if we fail, we fall through.
- }
- if ( !match ) stack[curWord] = INVALID; //return INVALID; //invalid command
- //!! no, put INVALID into the stack.
- }
- currWord++; //Increase the SP.
- }
- }
- void doaction(int action){
- //get actions off the stack, and pop them
- int tempheap[5]; int command;
- for ( int q = 0; q <= MAX_WORDS; q++ ){
- hempheap[q] = stack[q];
- stack[q] = 0; //popped
- }
- switch(NUMWORDS){
- case 1:
- //actions only
- command = tempheap[0];
- switch(command){
- }
- case 2:
- //action and noun
- int command = tempstack[0];
- int adjective = tempstack[1];
- int noun = tempstack[2];
- switch(noun){
- //find the object by checking for NOUN on screen
- case 1:
- switch(command){
- case 1:
- //perform action on noun
- }
- }
- }
- case 3: //command, and two words
- //can be 'command adjective noun'
- int command = tempstack[0];
- int adjective = tempstack[1];
- int noun = tempstack[2];
- //append adjective to ADJECTIVE_NOUN[36]
- //and append a space
- //append the noun to the ADCECTIVE_NOUN string
- switch(noun){
- //!!!!!!!
- //! it might improve performance to do the adjective and noun first, and perform the command
- //case, on those.
- //determine of the noun is an enemy, or an item.
- case 1:
- case 2:
- case 3: //items
- //item cases go here
- //check for items matchint the ADJECTIVE_NOUN string by name
- //if they exist, perform the action on them, if possible
- //if they are not on screen, but are in inventory, perform the action.
- switch(action){
- case TAKE:
- break;
- case GIVE;
- break;
- case USE:
- break;
- case EQUIP:
- break;
- default:
- SyntaxErr();
- break;
- //Perform the action on the target.
- }
- break;
- //enemies
- case TROLL:
- case GOBLIN:
- case GOLLUM:
- case SMAUG:
- switch(action){
- case ATTACK:
- break;
- default:
- SyntaxErr();
- break;
- //Perform the action on the target.
- }
- break;
- //Scan the screen for an npc that matches the string ADJECTIVE_NOUN
- case OTHER:
- SyntaxErr();
- break;
- /*
- switch(adjective){
- //narrow the field? Do we ever need to do this?
- case 1:
- int noun = tempstack[2];
- //append adjective to ADJECTIVE_NOUN[36]
- //and append a space
- switch(noun){
- //append the noun to the ADCECTIVE_NOUN string
- case 1:
- //item cases go here
- //check for items matchint the ADJECTIVE_NOUN string by name
- //if they exist, perform the action on them, if possible
- //if they are not on screen, but are in inventory, perform the action.
- }
- }
- switch(action){
- Perform the action on the target.
- }
- */
- default:
- SyntaxErr();
- break;
- }
- case 4: //command and three words
- /* this is where things become quite complex, as this includes the SAY
- instruction. In fact... I believe that 4 must alays be the say instruction.
- //! Don;t forget 'CARRY'
- */
- int person = tempstack[1];
- int action = tempstack[2];
- int noun = tempstack[3];
- switch (command){
- case SAY:
- //if the command isn't say, then we're doing something else, likely syntax err.,
- case (person){
- //check to see if the person is present.
- case GANDALF:
- if ( !isGandalfPresent() ) break;
- case THORIN:
- if ( !isThorinPresent() ) break;
- case ELROND:
- if ( !isElrondPresent() ) break;
- case GOLLUM
- if ( !isTHorinPresent() ) break;
- case BEORN:
- if ( !isBeornPresent() ) break;
- case BARD:
- if ( !isTHorinPresent() ) break;
- case SMAUG
- if ( !isTHorinPresent() ) break;
- //Each character gets this block, with legal actions and such.
- switch(action){
- case GIVE:
- switch(noun){
- case 1:
- //check objects in inventory
- //if we give the object to a character, mark their inventory
- //array and remove the object from our own
- }
- case ATTACK;
- switch(noun){
- //check the screen for some creature that matches
- //noun by name.
- case 1:
- }
- }
- }
- default:
- //not the say command, return an error.
- }
- case 5:
- //say, person, action, adjective, noun
- //! Don;t forget 'CARRY'
- switch (command){
- case SAY:
- int person = tempstack[1];
- case (person){
- case 1:
- int action = tempstack[2];
- switch(action){
- int adj = tempstack[3];
- case 1:
- switch(adj){
- int noun = tempstack[4];
- case 1:
- switch(noun){
- case 1:
- }
- }
- }
- }
- default:
- //not the say command, return an error.
- }
- switch(action){
- case :
- default:
- break;
- }
- }
- //ASM VARIABLES
- //NOUNS
- //Items
- #define KEY 1;
- #define MAP 2;
- #define GOLD 3;
- #define SWORD 4;
- #define TORCH 5;
- #define DAGGER 6;
- #define ME 7;
- #define CHEST 8;
- #define ROPE 9;
- #define LUNCH 10;
- #define FOOD 11;
- #define WINE 12;
- #define BARREL 13;
- //NPCs (person)
- #define GANDALF 1;
- #define THORIN 2;
- #define BARD 3;
- #define BEORN 4;
- #define ELROND 5;
- #define ELF 6; //WOOD ELF
- #define WOOD 6; //WOOD ELF
- #define BUTLER 7;
- //Enemies
- #define TROLL 1;
- #define GOBLIN 2;
- #define GOLLUM 3;
- #define WARG 4;
- #define EYES 5; //PALE BULBOUS EYES
- #define SMAUG 6;
- #define DRAGON 6;
- //ADJECTIVES and ADVERBS
- #define STRANGE 1;
- #define OLD 2;
- #define UNUSUAL 3;
- #define GOLDEN 4;
- #define UGLY 5;
- #define MAGICAL 6;
- #define HIDEOUS 7;
- #define SHINY 8;
- #define CURIOUS 9;
- #define LARGE 10;
- #define SHORT 11;
- #define VICIOUSLY 12;
- #define CAREFULLY 13;
- GENTLY
- QUICKLY
- SOFTLY
- VICIOUSLY
- //Prepositions
- //! If we scan a perposition, just ignore it. ATTACK GOBLIN WITH THE SHORT SWORD == ATACK GOBLIN SHORT SWORD
- //! Prepositions exist only to facilitate natural language, not to be parsd. !!!
- //! We **DO** need to store the ACTIVE PREPOSITION somewhere, so that our outut story string USES it to
- //! describe the action.
- //! if the player says: PUT ROPE IN BARREL
- //! We need to respond: THE ROPE IS **IN** THE BARREL, or something of that sort.
- #define WITH 20;
- #define OF 21;
- #define AT 22;
- ACROSS
- FROM
- IN
- INTO
- ON
- OUT
- OFF
- THROUGH
- TO
- UP
- WITH
- //onjunctions
- #define AND
- #define THEN
- //Special
- int navi[]="HEY LISTEN";
- //Parse types, based on number of commands issued
- #define COMMAND 1;
- #define VERB 2;
- #define NOUN 3;
- #define SPEAK 4;
- //Constructs
- //ACTION
- //ACTION NOUN
- //ACTION VERB NOUN
- //SAY NPC SPEAK
- /*
- GAME DICTIONARY
- Movements:
- DOWN D, EAST E, NORTH N, NORTHEAST NE, NORTHWEST NW, SOUTH S,
- SOUTHEAST SE, SOUTHWEST SW, UP U, WEST W.
- Special verbs:
- EXAMINE, HELP, INVENTORY I, LOAD, LOOK L, NOPRINT, PAUSE, PRINT,
- QUIT, SAVE, SCORE.
- DICTIONARY
- Action verbs:
- BREAK, CLIMB, CLOSE, CROSS, DIG, DROP, DRINK, EMPTY, ENTER, EAT,
- FILL, FOLLOW, GIVE, GO, KILL, LOCK, PICK, PUT, OPEN, RUN, SAY,
- SHOOT, SWIM, TIE, TAKE, THROW, TURN, UNLOCK, UNTIE, WEAR.
- Prepositions:
- ACROSS, AT, FROM, IN, INTO, ON, OUT, OFF, THROUGH, TO, UP, WITH
- Adverbs:
- CAREFULLY, GENTLY, QUICKLY, SOFTLY, VICIOUSLY
- */
- //SPEAK
- //ONE WORD
- //TWO WORDS
- //"GIVE" item
- //item NOUN
- //item VERB NOUN
- //"CARRY" item, person
- //item NOUN, person
- //item VERB NOUN, person
- //"ATTACK" npc
- //attack, NPC
- //attack VERB NPC
- bool Parse(int inputBuffer){
- int
- /*
- switch (strlen(temp_command)){
- int buf[3] = "0"; int buf2[2];
- case 3:
- //check commands with a length of 3...
- for ( int q = 0; q < SizeOfArray(commandlengths); q++ ) {
- if ( commandlengths[q] == 3 ) {
- //if the position of q is < 10, append a leading 0
- if ( q < 10 ) {
- itoa(q,buf2);
- strcat(buf2, but);
- }
- //otherwise, just store it
- itoa(q, buf); //overwrite the temp buffer.
- //find that number in legal commands
- for ( int w = 0; 2 < SizeOfArraylegalcommands; w++ ){
- if ( stringparser(buf) ) return q; //if the string matches
- //the parsed string, thast is its command number.
- //so, return it.
- }
- break; //if we fail, we fall through.
- }
- break; //fall though
- }
- case 4:
- //check commands with a length of 3.
- for ( int q = 0; q < SizeOfArray(commandlengths); q++ ) {
- if ( commandlengths[q] == 4 ) {
- //if the position of q is < 10, append a leading 0
- if ( q < 10 ) {
- itoa(q,buf2);
- strcat(buf2, but);
- }
- //otherwise, just store it
- itoa(q, buf); //overwrite the temp buffer.
- //find that number in legal commands
- for ( int w = 0; 2 < SizeOfArraylegalcommands; w++ ){
- if ( stringparser(buf) ) return q; //if the string matches
- //the parsed string, thast is its command number.
- //so, return it.
- }
- break; //if we fail, we fall through.
- }
- break; //fall though
- }
- case 5:
- //check commands with a length of 3.
- for ( int q = 0; q < SizeOfArray(commandlengths); q++ ) {
- if ( commandlengths[q] == 4 ) {
- //if the position of q is < 10, append a leading 0
- if ( q < 10 ) {
- itoa(q,buf2);
- strcat(buf2, but);
- }
- //otherwise, just store it
- itoa(q, buf); //overwrite the temp buffer.
- //find that number in legal commands
- for ( int w = 0; 2 < SizeOfArraylegalcommands; w++ ){
- if ( stringparser(buf) ) return q; //if the string matches
- //the parsed string, thast is its command number.
- //so, return it.
- }
- break; //if we fail, we fall through.
- }
- break; //fall though
- }
- case 6:
- default:
- //invalid command.
- }
- */
- //Global script for text buffer
- //preliminary
- global script a{
- void run(){
- //int buffers[]={b1, b2, b3, b4, b5, b6, b7, b8, b9, b10};
- //bufptr = buffers;
- //int curbuffer = bufptr[q];
- int buffersize = SizeOfArray(buffer);
- Link->Y = 90;
- //Game->Cheat = 4;
- while(true){
- //Link->PressMap = false;
- Link->InputMap = false;
- if ( timer ) cantype = false;
- if ( !timer ) cantype = true;
- if ( Game->KeyPress[115] || Game->KeyPress[116] ) ShiftKey = true;
- else ShiftKey = false;
- if ( timer > 0 ) timer -10;
- if ( timer <= 0 ) timer = 0;
- if ( cursorblink > 0 ) cursorblink--;
- if ( cursorblink <= 0 ) cursorblink = 100;
- if ( cantype ) {
- //if we are not over the arbitrary buffer limit
- if ( ram[RAM_q] < buffersize ) {
- //int keystroke;
- for ( int qq = 1; qq <= KEY_COMMAND; q++ ) {
- if ( qq < KEY_DEL ) {
- if ( ( buffer[q] = CheckKeyToChar(qq,true) ) != CHAR_BACKSPC ) {
- if ( buffer[q] == CHAR_TAB ) {
- for ( int w = 0; w < 4; w++ ) { buffer[q] = CHAR_SPACE; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
- timer = KEY_DELAY;
- }
- else {
- CursorAdv(RAM_q); temp_q++;
- if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
- timer = KEY_DELAY;
- }
- break;
- }
- }
- if ( ( buffer[q] = CheckKeyToChar(qq,true) ) == CHAR_BACKSPC ) {
- buffer[q] = 0; CursorRev(RAM_q); temp_q--;
- if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
- timer = KEY_DELAY;
- break;
- }
- if ( ( buffer[q] = CheckKeyToChar(qq,true) ) == CHAR_DEL ) {
- for ( int w = qq; w >=0; w-- ) buffer[w] = 0;
- for ( int w = qq; w >=0; w-- ) bufferoverlay[w] = 0;
- ram[RAM_q] = 0;
- if ( SFX_CLEARBUFFER > 0 ) Game->PlaySound(SFX_CLEARBUFFER);
- timer = KEY_DELAY;
- break;
- }
- if ( ( buffer[q] = CheckKeyToChar(qq,true) ) == CHAR_HOME ) {
- //used for tilde and grave, as that key is used by the ZC UI.
- if ( (Game->KeyPress[KEY_LSHIFT] || Game->KeyPress[KEY_RSHIFT])){
- buffer[q] = '~'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
- }
- else {
- buffer[q] = '`'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
- }
- timer = KEY_DELAY;
- }
- if ( ( buffer[q] = CheckKeyToChar(qq,true) ) == CHAR_ARROW_U ) {
- Link->PressUp = false; Link->InputUp = false;
- LeapInstruction("UP");
- break;
- }
- if ( ( buffer[q] = CheckKeyToChar(qq,true) ) == CHAR_ARROW_D ) {
- Link->PressDown = false; Link->InputDown = false;
- LeapInstruction("DOWN");
- break;
- }
- if ( ( buffer[q] = CheckKeyToChar(qq,true) ) == CHAR_ARROW_L ) {
- Link->PressLeft = false; Link->InputLeft = false;
- LeapInstruction("LEFT");
- break;
- }
- if ( ( buffer[q] = CheckKeyToChar(qq,true) ) == CHAR_ARROW_R ) {
- Link->PressRight = false; Link->InputRight = false;
- LeapInstruction("RIGHT");
- break;
- }
- bufferoverlay[q] = '_'; //Cursor
- }
- }
- }
- Screen->DrawString(6,0,0,2, 0x01, -1, 0, GetBuffer(),128);
- //draw buffer overlay, with blink
- //We can replace the null char in the loop with something that can be a cursor.
- //Perhaps something greyed out or translucent, like an underscore, and make it blink?
- if ( cursorblink > CURSOR_BLINK_DUR ) {
- Screen->DrawString(6,0,0+CURSOR_Y_OFS,2, 0x01, -1, 0, GetCursorOverlay(),128); //cursor
- /*
- Screen->Line(6,
- 0+0+(q*CHAR_WIDTH),
- //BUFFER_OUTPUT_X+CURSOR_X_OFFSET+(q*CHAR_WIDTH),
- //BUFFER_OUTPUT_Y+CURSOR_Y_OFFSET,
- 6,
- 0+0+(q*CHAR_WIDTH)+4,
- //BUFFER_OUTPUT_X+CURSOR_X_OFFSET+(q*CHAR_WIDTH) + CURSOR_WIDTH,
- 6,
- //BUFFER_OUTPUT_Y+CURSOR_Y_OFFSET,
- 0x01, 1, 0, 0, 0, 128);
- */
- }
- Waitdraw(); Waitframe();
- }
- }
- }
- int GetBuffer(){
- //int ptr = bufptr;
- //return bufptr[buffer];
- return buffer;
- }
- int GetCursorOverlay(){
- return bufferoverlay;
- }
- //CursorAdv(RAM_q);
- void CursorAdv(int n){
- bufferoverlay[ram[n]] = CHAR_SPACE;
- ram[n]++;
- bufferoverlay[ram[n]] = '_'; //Cursor.
- }
- //CursorRev(RAM_q);
- void CursorRev(int n){
- bufferoverlay[ram[n]] = 0;
- ram[n]--;
- bufferoverlay[ram[n]] = '_'; //Cursor.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement