Author Topic: WizardC8  (Read 4319 times)

0 Members and 1 Guest are viewing this topic.

Offline Ephraim B

  • LV2 Member (Next: 40)
  • **
  • Posts: 28
  • Rating: +1/-1
    • View Profile
WizardC8
« on: February 04, 2015, 08:14:04 pm »
This is a continuation of the WizardC8 Topic from Cemetech: http://www.cemetech.net/forum/viewtopic.php?t=10852

I'm still having a hard time comparing a 9 byte floating-point Variable to the CP instruction.

Can anyone please help me?

Edit: WizardC8 is a Harry Potter Currency Converter which i'm trying to write in ASM for experience. I already wrote it in TI-Basic as WizardC7. I'm now stuck with comparing a 9 byte floating-point Variable. I want to start with comparing the integer to make sure it doesn't go below zero followed by the first digit after the decimal followed by the second digit.
« Last Edit: March 01, 2015, 12:32:25 pm by Ephraim B »





Offline Iambian

  • Coder Of Tomorrow
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 739
  • Rating: +216/-3
  • Cherry Flavoured Nommer of Fishies
    • View Profile
Re: WizardC8
« Reply #1 on: February 04, 2015, 08:58:38 pm »
There are several ways of going about doing this, and very few of them actually use the CP instruction, since that only works between two one byte values, whereas an OP "register" is a memory construct and is not directly supported by the CPU (meaning you have to do this in several steps to simulate support, which is what ASM is really about)

1. Compare the two OP registers directly by first comparing the exponent. If one is greater than the other, you can stop already. If not, then compare each byte afterwards until something happens. What that something is... is up to you.
Code: [Select]
ld DE,ADDRESSOFFIRSTOPREG+
 ld HL,ADDRESSOFSECONDOPREG+
 ld b,8
Loop:
 ld a,(de)
 cp (hl)
 jr nz,SomethingHappened
 djnz Loop
 ret
SomethingHappened:
;carry=(DE)<(HL)
;your code here
 ret

2. If your numbers are integers, use the romcall ConvOP1 to convert to DE, swap out to HL, preserve it, move second value to OP1 and do the call again, then use the or a \ sbc hl,de sequence, since that works best as a two-byte CP instruction.
Code: [Select]
bcall(_convop1)
 push de
   ;move other value to Op1
   bcall(_convop1)
 pop hl
 or a
 sbc hl,de
 ;carry if second value was greater than first convOp1 value
 ;insert your code here
 ret

3. Get the OS to do the comparison for you BASIC-style, except you're directly calling a parser function. Today, it's _BinOPExec (for two-argument functions), where the first argument is in Op1 and the other pushed to the FPS. You then load register A with the function to execute before using the romcall.
Code: [Select]
;arguments are assumed to be in place already
 ld a,FUNCTION
 bcall(_BinOPExec)
; Op1 will contain the result of the operation. If you use something
; like OPEq, OPGt, or OPLt, you'll get 0 for false or 1 for true.
; You can then use ConvOP1 to reduce that to register A then compare it.

As with all unfamiliar romcalls, you must read the documentation for further information.





A Cherry-Flavored Iambian draws near... what do you do? ...

Offline Ephraim B

  • LV2 Member (Next: 40)
  • **
  • Posts: 28
  • Rating: +1/-1
    • View Profile
Re: WizardC8
« Reply #2 on: February 05, 2015, 06:31:54 pm »
I want to make sure the first byte of my 9 byte floating-point Variable doesn't go below zero and when I press the right arrow key, compare the second byte. Again would be the third byte. Pressing left would make it check for the second byte and pressing left again would make it check for the first byte. Pressing Enter would go to the Results screen.

Edit: So how do I make sure the integer doesn't go below zero?
« Last Edit: March 01, 2015, 12:43:38 pm by Ephraim B »





Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: WizardC8
« Reply #3 on: February 06, 2015, 04:54:05 pm »
Hey Ephraim.  I know you linked to the Cemetech topic, but I would suggest editing your first post and give a brief description of what WizardC8 is. It'll be a lot nicer and neater than simply linking to another forum topic,(which people may not want to check) and will have all the info available here. ;)
« Last Edit: February 06, 2015, 04:59:43 pm by Art_of_camelot »

Offline Ephraim B

  • LV2 Member (Next: 40)
  • **
  • Posts: 28
  • Rating: +1/-1
    • View Profile
Re: WizardC8
« Reply #4 on: March 01, 2015, 12:51:08 pm »
There are several ways of going about doing this, and very few of them actually use the CP instruction, since that only works between two one byte values, whereas an OP "register" is a memory construct and is not directly supported by the CPU (meaning you have to do this in several steps to simulate support, which is what ASM is really about)

1. Compare the two OP registers directly by first comparing the exponent. If one is greater than the other, you can stop already. If not, then compare each byte afterwards until something happens. What that something is... is up to you.
Code: [Select]
ld DE,ADDRESSOFFIRSTOPREG+
 ld HL,ADDRESSOFSECONDOPREG+
 ld b,8
Loop:
 ld a,(de)
 cp (hl)
 jr nz,SomethingHappened
 djnz Loop
 ret
SomethingHappened:
;carry=(DE)<(HL)
;your code here
 ret


I want to start with comparing the integer to make sure it doesn't go below zero



I made a new ASM program to try debugging my code:

Code: [Select]
#include "ti83plus.inc"
.org $9D93
.db $BB,$6D

item1UserInputLoop: ; label item1UserInputLoop

b_call(_GetKey) ; Waits for a key to be pressed

CP kUp ; If the up arrow key is pressed,
JR Z,Increase ; goto label Increase

CP kDown ; If the down arrow key is pressed,
JR Z,Decrease ; goto label Decrease

CP kEnter ; If the Enter key is pressed,
JP Z,DollarsToGallionsResults ; goto label DollarsToGallionsResults.

JR item1UserInputLoop ; Else, loop back to
; label item1UserInputLoop
Increase: ; label Increase

LD HL,DollarsValue
b_call(_Mov9ToOP1)

LD A,DollarsValue

CP 255 ; If Register A=255,
JR Z,item1UserInputLoop ; goto label item1UserInputLoop

LD HL,DollarsValueChange
b_call(_Mov9ToOP2)
b_call(_FPAdd)

LD HL,OP1
LD DE,DollarsValue
LD BC,9
LDIR

JR item1UserInputDisplay ; goto label item1UserInputDisplay

Decrease: ; label Decrease

LD HL,DollarsValue
b_call(_Mov9ToOP1)

LD DE,Zero

DecreaseLoop:

LD A,(DE)

CP (HL)
JR Z,item1UserInputLoop

ContinueDecrease:

LD HL,DollarsValueChange
b_call(_Mov9ToOP2)
b_call(_FPSub)

LD HL,OP1
LD DE,DollarsValue
LD BC,9
LDIR

item1UserInputDisplay: ; label item1UserInputDisplay

LD A,16
LD (penRow),A
LD A,44
LD (penCol),A

LD A,$F3
b_call(_VPutMap)

LD A,30
LD (penRow),A
LD A,44
LD (penCol),A

LD A,$07
b_call(_VPutMap)

LD A,23 ; 23->Register A
LD (penRow),A ; Register A->(penRow)
LD A,45 ; 45->Register A
LD (penCol),A ; Register A->(penCol)

LD HL,DollarsValue
b_call(_Mov9ToOP1)

LD A,6
b_call(_DispOP1A)

JP item1UserInputLoop ; goto label item1UserInputLoop

DollarsToGallionsResults:

RET

;---------Variables-----------

DollarsValue:

.db $00,$80,$00,$00,$00,$00,$00,$00,$00

Zero:

.db $00,$80,$00,$00,$00,$00,$00,$00,$00

DollarsValueChange:

.db $00,$80,$10,$00,$00,$00,$00,$00,$00

DollarRateInGallions:

.db $00,$7E,$99,$30,$48,$65,$93,$84,$31

GallionsValue:

.db 0,0

SicklesValue:

.db 0

KnutsValue:

.db 0

GallionRateInDollars:

.db $00,$81,$10,$07,$00,$00,$00,$00,$00

SickleRateInDollars:

.db $00,$7F,$59,$00,$00,$00,$00,$00,$00

KnutRateInDollars:

.db $00,$7E,$20,$00,$00,$00,$00,$00,$00

;------------Data-------------

txtSelect1UserInputDS:    ; label txtSelect1UserInputDS

.db $F2," ",0    ; TI's ASCII: $F2=$


.end
END

The number stopped decrementing when I pressed the down key. I want it to decrement when it's at any number except zero.

What did I do wrong?

Edit Sorunome: merged double post



Development reset. I'm starting again from scratch and doing it without a #include file this time.
« Last Edit: March 22, 2015, 09:08:33 pm by Ephraim B »