Hallo Besucher, der Thread wurde 1,6k mal aufgerufen und enthält 2 Antworten

letzter Beitrag von Snoopy am

Problem with JSRFAR ($FF6E)

  • Unfortunately, I stuck with one thing while playing something with the JSRFAR kernel routine ($FF6E). I'll try to describe it as good as I can:


    I have a little routine in bank 3 (ROM) which should display a 'B' at $0801 (second col in first raw of textscreen):

    Code: routine in bank 3 (ROM):
    1. routine in bank 3 (ROM):
    2. 3ac40 a9 02 lda #$02 ; display "B" at $0801 for debug
    3. 3ac42 8d 01 08 sta $0801
    4. 3ac45 60 rts


    Then I want to call this routine with this code in bank 0:

    It should work as this: Store all needed parameters for jsr_far in $02 to $0A, the display an 'A', call the subroutine in $3AC40 which display a 'B' then return to the routine in bank 0 which display now a 'C'.


    If I call it from BASIC10 like this

    Code
    1. BANK 0
    2. SYS DEC("D06E")

    only the "A" is being display and then the C65 (xc65) freezes. So the routine in $34c40 do nothing or can't be called at all.


    Did I miss something? I can't find any more detailed info in the documentations I had. ?(

  • I don't know about C65/M65, but on the C128 this would fail because you first select BANK 0 but then try to call a kernal function (but the kernal is banked out). Use a bank where the kernal is active, or activate it yourself at the start of your routine.

    As the kernal stub only jumps to $02cd (again, this is the C128 value), one might try to directly jump there instead, without need for the kernal. Unfortunately, on a C128 even that would fail, because the routine at $02cd calls another kernal function to convert the desired bank number to the value for the mmu configuration register.

    In the end it is much easier to just ignore JMPFAR/JSRFAR and write your own functions. JMPFAR/JSRFAR are only really useful for implementing the SYS instruction of Basic.

  • Mac Bacon : Many thanks for your hint! :thumbup:


    The C65 DOS copy the JSR_FAR and JMP_FAR kernel routines from $F212-$F28B to the RAM in bank 0 to $0380-$03FC every boot up or at wish.


    So they can be called also in bank 0.


    Okay, I know that. But that doesn't necessarly mean, that I program suitable for it. :D


    The error was that I jump to $ff6e for JSR_FAR, that - like you write - of course will not be found in bank 0.


    If I use the address in RAM (bank 0) jsr $03a8 (the copied jsr_far routine) at line 19 it works fine. :)

    Here it is: The magic "ABC"! :D



    Okay, what I have learned:


    If a routine doesn't work, try it again and again and again. Read your code as often as you can. Be "100% sure" that "all is correct"! :)


    If nothing helps, ask your grandmother for help. And if even she knows no solution to your problem, ask in Forum64. There you get an helpful answer and the feeling that you are a blind mole! :D


    Mac Bacon : Many thousand thanks! :thumbup: