Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: joshuarpl on March 24, 2019, 09:53:49 pm

Title: Help with loops?
Post by: joshuarpl on March 24, 2019, 09:53:49 pm
I think I learned that jr F1 is to loop an assembly program, but how do you loop an assembly program but have the option to press CLEAR to quit?
Title: Re: Help with loops?
Post by: Xeda112358 on March 24, 2019, 10:12:01 pm
A simple way is to do something like:
Code: [Select]
loop:
  bcall(_GetCSC)
  cp 15     ; check [clear]
  jr nz,loop
  ret
But if you want the more complicated (and less energy efficient :P) way:
Code: [Select]
  di   ;disables interrupts since the OS will mess with port 1
  ld a,$FD ;we'll be polling for keys [ENTER] up to [CLEAR]
  out (1),a
loop:
  in a,(1)
  and $40 ;checks bit 6 which corresponds to clear. Set if not pressed, reset if pressed
  jr nz,loop
  ret
But my preferred way is:
Code: [Select]
  ei     ;keep OS interrupts active
loop:
  halt    ;
  ld a,(kbdScanCode)
  cp 15
  jr nz,loop
  ret
Title: Re: Help with loops?
Post by: joshuarpl on March 24, 2019, 11:51:19 pm
Found my own way!
Hex
Code: [Select]
:AsmPrgm
:EF1840
:FE0F
:C8
:18F1
:C9

Assembly
Code: [Select]
bcall $4018
cp 0F
ret z
jr F1
ret

Didn't try your code, but still, thanks for helping me out a little bit.
Also, I tested it on my physical TI-84+ and Wabbitemu, and they both act the same, they both work.
Title: Re: Help with loops?
Post by: Sue Doenim on March 25, 2019, 08:34:59 pm
Found my own way!
Hex
Code: [Select]
:AsmPrgm
:EF1840
:FE0F
:C8
:18F1
:C9

Assembly
Code: [Select]
bcall $4018
cp 0F
ret z
jr F1
ret

Didn't try your code, but still, thanks for helping me out a little bit.
Also, I tested it on my physical TI-84+ and Wabbitemu, and they both act the same, they both work.
Note that jr $F1 will only work if the opcode is always at the exact same spot in the program (i.e. 7 bytes into the program).  Also, it kinda seems to me like you're trying to do coding on-calc/without a computer.  If that's the case, I would advise using Mimas.  It's a really nice app where you can write and compile ASM programs on-calc, and it's definitely much better than working in raw hex.
Title: Re: Help with loops?
Post by: Xeda112358 on March 25, 2019, 08:52:43 pm
Actually, jp points to a fixed location whereas jr is relative. So in this case, jr $F1 (18F1) just states that it will jump back 15 bytes from the end of the instruction.
Title: Re: Help with loops?
Post by: Sue Doenim on March 25, 2019, 11:26:00 pm
Actually, jp points to a fixed location whereas jr is relative. So in this case, jr $F1 (18F1) just states that it will jump back 15 bytes from the end of the instruction.
Yeah, I meant the opcode itself, not the address it jumps to.  In hindsight, that wasn't the best way to put it, but my point about writing in hex still stands.
Title: Re: Help with loops?
Post by: TIfanx1999 on March 27, 2019, 07:36:16 pm
@Sue Doenim : It's true that most would prefer writing in ASM over hex, but in replying to Xeda you may have found one of the few people that started off in writing things in hex and was comfortable doing it for quite some time. Just a funny coincidence. ;)
Title: Re: Help with loops?
Post by: joshuarpl on April 09, 2019, 08:19:33 pm
Regardless, it still works.