Jump to content
  • 0

Howto use FETCH, the KERNAL function


Stefan
 Share

Question

I've been trying to use the KERNAL FETCH function for some time. But I can't get it to work.

This is my test code:

lda #$c0
ldy #$00
ldx #$06
jsr $ff74
sta $6000
rts

Reading the KERNAL source code, it seems that the calling address is $ff74, not $ff77 as stated in the PRG.

Following the path of execution from ROM bank 0/$ff74, it seems that the value in .A is stored in the FETVEC, and that you need not store it yourself before calling the function as stated in the PRG.

When running this, I expect the function to fetch the value in bank 6 (.X) at address $c000 (MSB in .A) + .Y and store it in RAM address $6000.

But it doesn't.

Neither does it work when I try following exactly what's said in the PRG.

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

The markdown code in the PRG is mis-formatted; the list of routines should look like this:

$FF4A: CLOSE_ALL – close all files on a device
$FF8D: 
LKUPLA – search tables for given LA
$FF8A: 
LKUPSA – search tables for given SA
$FF62: 
DLCHR - activate a text mode font in the video hardware [not yet implemented]
$FF65: PFKEY – program a function key [not yet implemented]
$FF74: FETCH – LDA (fetvec),Y from any bank
$FF77: 
STASH – STA (stavec),Y to any bank
$FF7A: 
CMPARE – CMP (cmpvec),Y to any bank
$FF7D: 
PRIMM – print string following the caller’s code

The current markdown code lacks two spaces at the end of the line, and so the rendering has them all smashed together, making it look like this:

$FF4A: CLOSE_ALL – close all files on a device $FF8D: LKUPLA – search tables for given LA $FF8A: LKUPSA – search tables for given SA $FF62: DLCHR - activate a text mode font in the video hardware [not yet implemented] $FF65: PFKEY – program a function key [not yet implemented] $FF74: FETCH – LDA (fetvec),Y from any bank $FF77: STASH – STA (stavec),Y to any bank $FF7A: CMPARE – CMP (cmpvec),Y to any bank $FF7D: PRIMM – print string following the caller’s code

Link to comment
Share on other sites

  • 0

I think I finally got it.

FETVEC should not contain the MSB of the address you want to look up, but a zero page address that in its turn points to the address you want to read.

A working example reading bank 6/address $c000:

;Setup ZP pointer
stz $22
lda #$c0
sta $23

;Call FETCH
lda #$22    ;ZP pointer
ldx #$06    ;ROM bank
ldy #$00    ;Index for the indirect load
jsr $ff74   ;Fetch call address

;Store return value
sta $6000
rts

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

Please review our Terms of Use