Far calls

I filled up my first lib bank (the first non-fixed mapped library bank). I had a far call setup from main/fixed to far lib stuffs, but now that I’m on my second lib bank I needed to figured out a way how to handle call far routines from lib bank 1 and vice versa.

The problem wasn’t so much a problem, until I needed the functionality of nesting far calls. I.e. call in banks, between banks, as if they were some linear mapped large bank. I’ve limited the far code to 8k, with 32k for data, and top 8k for fixed bank stuffs. The macro I have setup, helps keep the code clean – but otherwise it just stores bank:word -> A:X:Y and then JSRs to a fixed bank function. The fixed function basically pushed the return bank# and address onto the real stack. So, I can basically nest up to ~51 far calls. The overhead isn’t that bad:

;##########################################################################
;………………………………………………………………..
;
DoFarCall:

sta FarJSR+2
tma #$02
pha

lda FarJSR+2
tam #$02
stx FarJSR+0
sty FarJSR+1

jsr .CallFar

pla
tam #$02
rts

.CallFar
jmp [FarJSR]

rts
;END_SUB

Of course, routines inside a lib bank don’t need far calls (I’ll probably add testing logic in the macro, so it’ll automatically detect and use a near call or a far call. All on the Assembler program side; no cpu code used). So things are arranged optimally. For this game, a 16K far code page + 24k data page layout would probably be better. But for now, I’ll stick with the 8k far code page. Meh, I’ll probably end up changing it later on. So it goes..

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: