Skip to content

Commit e0ad37f

Browse files
committed
Fix broken signed right shift
Plus fix broken stack top swap and add stack manipulation keys
1 parent a5f1796 commit e0ad37f

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/bigint.asm

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,6 @@ BigIntShiftRight:
672672
xor a,a
673673
bisruiploop:
674674
dec hl
675-
bisripentry:
676675
rr (hl)
677676
djnz bisruiploop
678677
adc a,a
@@ -688,12 +687,12 @@ _BigIntSignedShiftRight:
688687
BigIntSignedShiftRight:
689688
; Input:
690689
; - HL
690+
xor a,a
691691
ld bc,BIG_INT_SIZE - 1
692692
add hl,bc
693693
ld b,c
694694
sra (hl)
695-
xor a,a
696-
jr bisripentry
695+
jr bisruiploop
697696
;-------------------------------------------------------------------------------
698697
_BigIntShiftBitInOnRight:
699698
pop bc

src/rpnui.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ bool Rpn_SendKey(sk_key_t k)
197197
case sk_Ins:
198198
if (EntryMode == RPN_NO_INPUT)
199199
if (BigIntStack_GetSize(MainStack) > 0)
200-
BigIntStack_Push(MainStack, topOfStack);
200+
BigIntStack_Push(MainStack, BigIntStack_Peek(MainStack));
201201
else
202202
return false;
203203
else
@@ -209,6 +209,15 @@ bool Rpn_SendKey(sk_key_t k)
209209
case sk_DecPnt:
210210
BigIntNot(BigIntStack_Peek(MainStack));
211211
break;
212+
case sk_Comma:
213+
BigIntStack_Exchange(MainStack);
214+
break;
215+
case sk_LParen:
216+
BigIntStack_RotateDown(MainStack);
217+
break;
218+
case sk_RParen:
219+
BigIntStack_RotateUp(MainStack);
220+
break;
212221
case sk_Add:
213222
case sk_Sub:
214223
case sk_Mul:

src/stack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void BigIntStack_RotateUp(BigIntStack_t* this)
112112
BigInt_t temp;
113113
if (this->Size <= 1)
114114
return;
115-
BigIntStack_Pop(this, &temp);
115+
BigIntCopyFromTo(this->Stack + this->Size - 1, &temp);
116116
memmove(this->Stack + 1, this->Stack, (this->Size - 1) * sizeof(BigInt_t));
117117
BigIntCopyFromTo(&temp, this->Stack);
118118
}
@@ -138,7 +138,7 @@ void BigIntStack_Exchange(BigIntStack_t* this)
138138
top = BigIntStack_Peek(this);
139139
BigIntCopyFromTo(top, &temp);
140140
BigIntCopyFromTo(top - 1, top);
141-
BigIntCopyFromTo(&temp, top);
141+
BigIntCopyFromTo(&temp, top - 1);
142142
}
143143

144144

0 commit comments

Comments
 (0)