Author Topic: Help with loops?  (Read 5914 times)

0 Members and 1 Guest are viewing this topic.

Offline joshuarpl

  • LV2 Member (Next: 40)
  • **
  • Posts: 23
  • Rating: +0/-0
    • View Profile
Help with loops?
« 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?

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Help with loops?
« Reply #1 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

Offline joshuarpl

  • LV2 Member (Next: 40)
  • **
  • Posts: 23
  • Rating: +0/-0
    • View Profile
Re: Help with loops?
« Reply #2 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.

Offline Sue Doenim

  • LV2 Member (Next: 40)
  • **
  • Posts: 27
  • Rating: +0/-0
    • View Profile
Re: Help with loops?
« Reply #3 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.
« Last Edit: March 25, 2019, 11:26:22 pm by Sue Doenim »

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Help with loops?
« Reply #4 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.

Offline Sue Doenim

  • LV2 Member (Next: 40)
  • **
  • Posts: 27
  • Rating: +0/-0
    • View Profile
Re: Help with loops?
« Reply #5 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.

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: Help with loops?
« Reply #6 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. ;)

Offline joshuarpl

  • LV2 Member (Next: 40)
  • **
  • Posts: 23
  • Rating: +0/-0
    • View Profile
Re: Help with loops?
« Reply #7 on: April 09, 2019, 08:19:33 pm »
Regardless, it still works.