#77 patches to support gb/z80 bank switching

open
z80 port (10)
5
2015-11-07
2006-11-16
No

Attached please find the patches to the code I had to make in order to make bank switching work for the Gameboy/GameboyColor.

a) I didn't change the functionality as it is in the compiler. It works as described in the manual - to the extent it is described at all. That is, I did the minimum changes necessary to make it work.

b) I also removed the start/end extra global symbols which didn't add anything but clutter to the map listing in my opinion.

c) I've used the compiler - with the attached patches on a small test program for the Gameboy as well as a large "real world" program. This program has been run on the VGB simulator and downloaded into a cartridge which supports bank switching. I quite confident that it works as one would hope.

d) Personally, I think that bank switching support could be improved a lot with different bank syntax that would permit bank switching to be resolved at compile time. When I first built my "real" program it was very slow due to bank switching in interrupts (a facility I HAD to have). I was able to resolve it by modest reorganization of my code modules. But with a different system this would not have been necessary. As currently implemented - bank switch calls are made when code is in different modules even though the code is in the same bank.

e) Needs to be added to the documentation:

"#pragma bank <bank #>" is used to specify that all code and const data in the current module will be placed in the indicated memory bank."

f) The usage of bank switching requires support from the runtime library. Currently, this support is only available in the GameboyDevelopmentKit gbdk. Note that i have my own moderatly modified version of the gbdk which supports this. I would be willing to upload this somewhere - but I'm not sure where to do it.

Robert Ramey

Discussion

  • Robert Ramey

    Robert Ramey - 2006-11-16

    Patches to correct bank switching on z80/gbz80

     
  • Maarten Brock

    Maarten Brock - 2006-12-31
    • assigned_to: nobody --> maartenbrock
     
  • Maarten Brock

    Maarten Brock - 2006-12-31

    Logged In: YES
    user_id=888171
    Originator: NO

    Robert,

    Can you please describe the modifications you made to the runtime library or gbdk? Or better upload them here attached to this patch?

    This patch looks ok and I will apply it with only a slight modification to check for target z80/gbz80 in SDCCglue.c.

    Maarten

     
  • Maarten Brock

    Maarten Brock - 2007-02-25

    Logged In: YES
    user_id=888171
    Originator: NO

    Robert,

    I'm still waiting for your modifications to the runtime library.

    Also I have trouble reading/applying the diffs on some files. Can you please generate a unified patch/diff with at least 3 lines of context (diff -u)?

    Maarten

     
  • Robert Ramey

    Robert Ramey - 2007-02-26

    latest copy of crt0.s which supports bank switching

     
  • Robert Ramey

    Robert Ramey - 2007-02-26

    Logged In: YES
    user_id=396141
    Originator: YES

    File Added: crt0.s

     
  • Robert Ramey

    Robert Ramey - 2007-02-26

    Logged In: YES
    user_id=396141
    Originator: YES

    File Added: global.s

     
  • Robert Ramey

    Robert Ramey - 2007-02-26

    Latest changes to support bank switching on gameboy

     
  • Robert Ramey

    Robert Ramey - 2007-02-26

    permits divide to be used in interrupt driven code

     
  • Robert Ramey

    Robert Ramey - 2007-02-26

    Logged In: YES
    user_id=396141
    Originator: YES

    I've uploaded two files crt0.s and global.s from my system. These files are modifications of those found in the gbdk 2.95. I included the whole file rather than the diffs as I wasn't sure what to diff them against. The files aren't very long in any case.

    This change implements bank switching and permits "nested" disable/enable interrupt instructions. Lack of this caused problems with interrupt driven code.

    I've also included a modified version of div.s I don't know if I modified the one with the SDCC package or the one from the gbdk - the might even be the same. This patch solves a problem where by if one invokes a division from an interrupt handler and also from the main line code - results are unpredicatble. This was due to the usage of static varible in the divide routine. This static variable has been elimated in favor a stack based one. The results are not correct but the divide code is a little bit longer. Note that the z80 could also benefit from a modification such as this.

    I have one more file which I could upload if you wish. I haven't tested it.
    File Added: div.s

     
  • Maarten Brock

    Maarten Brock - 2008-05-29

    Logged In: YES
    user_id=888171
    Originator: NO

    Applied modified div.s in SDCC 2.8.1 #5187.

     
  • Philipp Klaus Krause

    • labels: --> z80 port
     
  • Tom Li

    Tom Li - 2015-07-13

    Why such useful patch is still not merged after 7 years?

     
  • Maarten Brock

    Maarten Brock - 2015-11-07

    After all this time and with Philipp having done most Z80 related development, I have no idea what to patch where anymore. I would unassign myself if I could.

    Philipp, can you have a look and apply or close as you see appropriate?

     

Log in to post a comment.