536 } |
536 } |
537 this->stack[this->position] = GB(word, 0, 8); |
537 this->stack[this->position] = GB(word, 0, 8); |
538 this->stack[this->position + 1] = GB(word, 8, 8); |
538 this->stack[this->position + 1] = GB(word, 8, 8); |
539 } |
539 } |
540 |
540 |
541 void ResetStack() { this->used = true; this->position = 0; } |
541 void ResetStack() { this->position = 0; this->used = true; } |
|
542 void RewindStack() { this->position = 0; } |
542 }; |
543 }; |
543 |
544 |
|
545 static TextRefStack _newgrf_normal_textrefstack; |
|
546 static TextRefStack _newgrf_error_textrefstack; |
|
547 |
544 /** The stack that is used for TTDP compatible string code parsing */ |
548 /** The stack that is used for TTDP compatible string code parsing */ |
545 static TextRefStack _newgrf_textrefstack; |
549 static TextRefStack *_newgrf_textrefstack = &_newgrf_normal_textrefstack; |
546 |
550 |
547 /** Prepare the TTDP compatible string code parsing */ |
551 /** |
548 void PrepareTextRefStackUsage() |
552 * Prepare the TTDP compatible string code parsing |
|
553 * @param numEntries number of entries to copy from the registers |
|
554 */ |
|
555 void PrepareTextRefStackUsage(byte numEntries) |
549 { |
556 { |
550 extern TemporaryStorageArray<uint32, 0x110> _temp_store; |
557 extern TemporaryStorageArray<uint32, 0x110> _temp_store; |
551 |
558 |
552 _newgrf_textrefstack.ResetStack(); |
559 _newgrf_textrefstack->ResetStack(); |
553 |
560 |
554 byte *p = _newgrf_textrefstack.stack; |
561 byte *p = _newgrf_textrefstack->stack; |
555 for (uint i = 0; i < 6; i++) { |
562 for (uint i = 0; i < numEntries; i++) { |
556 for (uint j = 0; j < 32; j += 8) { |
563 for (uint j = 0; j < 32; j += 8) { |
557 *p = GB(_temp_store.Get(0x100 + i), j, 8); |
564 *p = GB(_temp_store.Get(0x100 + i), j, 8); |
558 p++; |
565 p++; |
559 } |
566 } |
560 } |
567 } |
561 } |
568 } |
562 |
569 |
563 /** Stop using the TTDP compatible string code parsing */ |
570 /** Stop using the TTDP compatible string code parsing */ |
564 void StopTextRefStackUsage() { _newgrf_textrefstack.used = false; } |
571 void StopTextRefStackUsage() { _newgrf_textrefstack->used = false; } |
|
572 |
|
573 void SwitchToNormalRefStack() |
|
574 { |
|
575 _newgrf_textrefstack = &_newgrf_normal_textrefstack; |
|
576 } |
|
577 |
|
578 void SwitchToErrorRefStack() |
|
579 { |
|
580 _newgrf_textrefstack = &_newgrf_error_textrefstack; |
|
581 } |
|
582 |
|
583 void RewindTextRefStack() |
|
584 { |
|
585 _newgrf_textrefstack->RewindStack(); |
|
586 } |
565 |
587 |
566 /** |
588 /** |
567 * FormatString for NewGRF specific "magic" string control codes |
589 * FormatString for NewGRF specific "magic" string control codes |
568 * @param scc the string control code that has been read |
590 * @param scc the string control code that has been read |
569 * @param stack the current "stack" |
591 * @param stack the current "stack" |
570 * @return the string control code to "execute" now |
592 * @return the string control code to "execute" now |
571 */ |
593 */ |
572 uint RemapNewGRFStringControlCode(uint scc, char **buff, const char **str, int64 *argv) |
594 uint RemapNewGRFStringControlCode(uint scc, char **buff, const char **str, int64 *argv) |
573 { |
595 { |
574 if (_newgrf_textrefstack.used) { |
596 if (_newgrf_textrefstack->used) { |
575 switch (scc) { |
597 switch (scc) { |
576 default: NOT_REACHED(); |
598 default: NOT_REACHED(); |
577 case SCC_NEWGRF_PRINT_SIGNED_BYTE: *argv = _newgrf_textrefstack.PopSignedByte(); break; |
599 case SCC_NEWGRF_PRINT_SIGNED_BYTE: *argv = _newgrf_textrefstack->PopSignedByte(); break; |
578 case SCC_NEWGRF_PRINT_SIGNED_WORD: *argv = _newgrf_textrefstack.PopSignedWord(); break; |
600 case SCC_NEWGRF_PRINT_SIGNED_WORD: *argv = _newgrf_textrefstack->PopSignedWord(); break; |
579 case SCC_NEWGRF_PRINT_QWORD_CURRENCY: *argv = _newgrf_textrefstack.PopUnsignedQWord(); break; |
601 case SCC_NEWGRF_PRINT_QWORD_CURRENCY: *argv = _newgrf_textrefstack->PopUnsignedQWord(); break; |
580 |
602 |
581 case SCC_NEWGRF_PRINT_DWORD_CURRENCY: |
603 case SCC_NEWGRF_PRINT_DWORD_CURRENCY: |
582 case SCC_NEWGRF_PRINT_DWORD: *argv = _newgrf_textrefstack.PopSignedDWord(); break; |
604 case SCC_NEWGRF_PRINT_DWORD: *argv = _newgrf_textrefstack->PopSignedDWord(); break; |
583 |
605 |
584 case SCC_NEWGRF_PRINT_WORD_SPEED: |
606 case SCC_NEWGRF_PRINT_WORD_SPEED: |
585 case SCC_NEWGRF_PRINT_WORD_LITRES: |
607 case SCC_NEWGRF_PRINT_WORD_LITRES: |
586 case SCC_NEWGRF_PRINT_UNSIGNED_WORD: *argv = _newgrf_textrefstack.PopUnsignedWord(); break; |
608 case SCC_NEWGRF_PRINT_UNSIGNED_WORD: *argv = _newgrf_textrefstack->PopUnsignedWord(); break; |
587 |
609 |
588 case SCC_NEWGRF_PRINT_DATE: |
610 case SCC_NEWGRF_PRINT_DATE: |
589 case SCC_NEWGRF_PRINT_MONTH_YEAR: *argv = _newgrf_textrefstack.PopSignedWord() + DAYS_TILL_ORIGINAL_BASE_YEAR; break; |
611 case SCC_NEWGRF_PRINT_MONTH_YEAR: *argv = _newgrf_textrefstack->PopSignedWord() + DAYS_TILL_ORIGINAL_BASE_YEAR; break; |
590 |
612 |
591 case SCC_NEWGRF_DISCARD_WORD: _newgrf_textrefstack.PopUnsignedWord(); break; |
613 case SCC_NEWGRF_DISCARD_WORD: _newgrf_textrefstack->PopUnsignedWord(); break; |
592 |
614 |
593 case SCC_NEWGRF_ROTATE_TOP_4_WORDS: _newgrf_textrefstack.RotateTop4Words(); break; |
615 case SCC_NEWGRF_ROTATE_TOP_4_WORDS: _newgrf_textrefstack->RotateTop4Words(); break; |
594 case SCC_NEWGRF_PUSH_WORD: _newgrf_textrefstack.PushWord(Utf8Consume(str)); break; |
616 case SCC_NEWGRF_PUSH_WORD: _newgrf_textrefstack->PushWord(Utf8Consume(str)); break; |
595 case SCC_NEWGRF_UNPRINT: *buff -= Utf8Consume(str); break; |
617 case SCC_NEWGRF_UNPRINT: *buff -= Utf8Consume(str); break; |
596 |
618 |
597 case SCC_NEWGRF_PRINT_STRING_ID: |
619 case SCC_NEWGRF_PRINT_STRING_ID: |
598 *argv = _newgrf_textrefstack.PopUnsignedWord(); |
620 *argv = _newgrf_textrefstack->PopUnsignedWord(); |
599 if (*argv == STR_NULL) *argv = STR_EMPTY; |
621 if (*argv == STR_NULL) *argv = STR_EMPTY; |
600 break; |
622 break; |
601 } |
623 } |
602 } |
624 } |
603 |
625 |