Author Topic: How does B_CALLs know which page to look at?  (Read 8474 times)

0 Members and 1 Guest are viewing this topic.

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
How does B_CALLs know which page to look at?
« on: April 16, 2011, 05:38:31 pm »
Let's say that in an application, I use B_CALL _getKey.  Since applications run from $4000, how does the calculator know that the 3-byte _getKey data is in the OS and not in the application?

Offline willrandship

  • Omnimagus of the Multi-Base.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2953
  • Rating: +98/-13
  • Insert sugar to begin programming subroutine.
    • View Profile
Re: How does B_CALLs know which page to look at?
« Reply #1 on: April 16, 2011, 05:41:44 pm »
I believe your answer is found inside ti83p.inc, since that's where all the bcalls are referenced. Might be wrong though :P
« Last Edit: April 16, 2011, 05:41:53 pm by willrandship »

souvik1997

  • Guest
Re: How does B_CALLs know which page to look at?
« Reply #2 on: April 16, 2011, 05:41:55 pm »
If you look at $0028, and follow the code from there, you'll see that the OS swaps out the Flash page that your application is on with a page that has the OS routines. Then, when the routines are finished executing, it swaps the page back.

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: How does B_CALLs know which page to look at?
« Reply #3 on: April 16, 2011, 05:43:18 pm »
If you look at $0028, and follow the code from there, you'll see that the OS swaps out the Flash page that your application is on with a page that has the OS routines. Then, when the routines are finished executing, it swaps the page back.

'Fraid it's not that easy.  Remember that you can create your own B_CALL routines for Multi-page applications

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: How does B_CALLs know which page to look at?
« Reply #4 on: April 16, 2011, 05:45:57 pm »
Because the bcall is really rst 28h followed by a two byte address. The rst 28h is a one byte representation of the three byte call $0028 At 0028h, there is another jump that actually jumps to the bcall call. There, the two bytes following the rst 28h is used to determine which page the call info is on. If the address has bit 7 set, it goes to one page (0**11011b I believe, where ** is 11 on an +SE, 01 on an 83+BE and 10 on an 84+BE) . Either way, on that page, it finds the page number of the actual call as well as the address.

TL;DR
bcall is executed on page 0, not page 1, that is why :)

Offline Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: How does B_CALLs know which page to look at?
« Reply #5 on: April 16, 2011, 05:46:06 pm »
If you look at $0028, and follow the code from there, you'll see that the OS swaps out the Flash page that your application is on with a page that has the OS routines. Then, when the routines are finished executing, it swaps the page back.

'Fraid it's not that easy.  Remember that you can create your own B_CALL routines for Multi-page applications

I'm pretty sure it is that easy. :P And what do you mean by creating your own B_CALL routines? The B_CALLs are the OS routines, so anything you have in your app isn't a B_CALL, and you can't use the B_CALL macro to call a routine in the app of your choice.

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: How does B_CALLs know which page to look at?
« Reply #6 on: April 16, 2011, 05:48:32 pm »
Hehe, actually, apps can create bcalls :) The special thing is that bcalls from apps have to have an address of a multiple of 3, I believe, and bit 6 is reset as opposed to set. I think that is how it works...

*bit 6 of the MSB of the address

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: How does B_CALLs know which page to look at?
« Reply #7 on: April 16, 2011, 05:57:23 pm »
If you look at $0028, and follow the code from there, you'll see that the OS swaps out the Flash page that your application is on with a page that has the OS routines. Then, when the routines are finished executing, it swaps the page back.

'Fraid it's not that easy.  Remember that you can create your own B_CALL routines for Multi-page applications

I'm pretty sure it is that easy. :P And what do you mean by creating your own B_CALL routines? The B_CALLs are the OS routines, so anything you have in your app isn't a B_CALL, and you can't use the B_CALL macro to call a routine in the app of your choice.

Maybe I'm just dead lost.  But here's the deal:

In a multi-page application, you could have a function called PutSprite on page 1.

PutSprite:

.dw 4135
.db 2

Suppose that the application is on flash page 14.  How does the calculator know that PutSprite is a label on page 14
and not an OS routine?  For all it knows, label 4135 could be a function in the Operating System

Offline jnesselr

  • King Graphmastur
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2270
  • Rating: +81/-20
  • TAO == epic
    • View Profile
Re: How does B_CALLs know which page to look at?
« Reply #8 on: April 16, 2011, 05:58:40 pm »
When all else fails, wikiti.

I have many a wondered the same question.

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: How does B_CALLs know which page to look at?
« Reply #9 on: April 16, 2011, 06:02:03 pm »
if 4135h is the address you are looking at, the bcall would be bcall(4135h-4000h) or bcall(0135h)

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: How does B_CALLs know which page to look at?
« Reply #10 on: April 16, 2011, 06:11:00 pm »
And to put it to rest:

bcall address:
  • 0000h - 3FFFh -- Look at the currently running app
  • 4000h - 7FFFh -- Look at page 1Bh/3Bh/7Bh
  • 8000h - BFFFh -- Look at boot code


So depending whichever range the bcall falls into is where the OS will look. And the data is always stored the same: addrLow, addrHigh, page
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: How does B_CALLs know which page to look at?
« Reply #11 on: April 16, 2011, 06:20:30 pm »
And to put it to rest:

bcall address:
  • 0000h - 3FFFh -- Look at the currently running app
  • 4000h - 7FFFh -- Look at page 1Bh/3Bh/7Bh
  • 8000h - BFFFh -- Look at boot code


So depending whichever range the bcall falls into is where the OS will look. And the data is always stored the same: addrLow, addrHigh, page

So to make sure I understand, $4000 is always subtracted from the label?

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: How does B_CALLs know which page to look at?
« Reply #12 on: April 16, 2011, 06:21:13 pm »
Only when the bcall info is in the app

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: How does B_CALLs know which page to look at?
« Reply #13 on: April 16, 2011, 06:24:59 pm »
Ugh, here's a problem I'm confused about.  Sorry I'm still confused.  So, applications are run from $4000, .org $4000 right?

What's the difference between

PutSprite:

.dw 4216h
.db 2

and _OP2ExOP5   EQU 4216h ?  I still don't understand how the calculator tells.

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: How does B_CALLs know which page to look at?
« Reply #14 on: April 16, 2011, 06:25:14 pm »
Yes. For in-app bcalls. You take the <label for the bcall> - $4000. And that's what you throw in bcall. You should probably use some defines to make it less confusing.

Code: [Select]
killCalculatorL:
.dw killRoutine
.db 1
#define killCalculator killCalculatorL-$4000

Edit:
    Ninja'd with a question. But do this for all of them and you should be good.
« Last Edit: April 16, 2011, 06:25:59 pm by thepenguin77 »
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112