Hallo Besucher, der Thread wurde 5,9k mal aufgerufen und enthält 6 Antworten

letzter Beitrag von Bobaflott am

How do I ... on the MEGA65?

  • Greetings all,

    steril asked a question about documentation for the MEGA65, and so it seemed to me to be a good idea to have a topic here where people can ask about how to program using certain features on the MEGA65 etc, and people can post example snippets of code, so that we end up with a kind of scrap book or cook book of how to do things on the MEGA65.


    Some of the examples will likely get written by us as we generate the MEGA65 User Guide and MEGA65 Programmer's Reference Guide. But we also hope that some will get written by the community, and maybe even make it into these books, as we all help one another.


    I'll keep this particular message fairly short, but will soon post an example of how to do 15-colour sprites on the MEGA65, to get the ball rolling.


    LG

    Paul.

  • ok, as promised, here is a little example program that lets you easily define and display a 15-colour sprite on the MEGA65. There are a few interesting things about this program:


    1. The PEEK(53272) part in line 0 is a quick hack to try to work out if a BASIC programme is running in C65 BASIC 10 or C64 BASIC 2, by checking where the screen i in RAM. This is necessary, because in BASIC 10 if you try to POKE the KEY register (53295) to set the IO mode between C64,C65 and M65 modes, it really upsets it. But fortunately the MEGA65 starts C65 BASIC with MEGA65 IO enabled, so we can skip the fiddling with the KEY register in that case.


    2. I wrote the little sprite loader so that you can encode the sprite in a bunch of strings in the DATA statements. This makes it really easy to define the sprite using either @, . or a space for black, and the letters A-O to pick colours 1 -- 15.


    3. The C64-style sprite colour register is used in 15-colour sprite mode to select which colour is actually transparency. That is, you don't just have to leave pink or black out, you can choose whatever colour you want left out.


    4. At the moment, I don't change the palette that the sprite is using. This is left as a future exercise :) It is possible to use a completely separate palette for sprites compared to text/bitmap data, and to use a different 15 colours for each of the 8 sprites.


    5. This program SHOULD work in Xemu and on real hardware. If you hit any problems in either, let me know, so that we can correct it and/or Xemu.


    Have fun making colourful sprites!


    LG

    Paul.


  • Explained here:

    > Loading arbitrary files from SD card:

    > Detecting the presence of a MEGA65



    I'm currently working on making the Freeze Menu support helper programs, so that it can have more functionality than can fit in 64KB. For example, we want the audio mixer to be nicer, and to add a sprite editor and so on. To do this, we need an easy way to load another program from the FAT32 file system on the SD card. Fortunately, we have already implemented a Hypervisor trap to do this a while back. So I thought I would describe here how to do this. The example is in assembly language. I could also be done from BASIC with some creativity with the SYS command (which in BASIC 10 lets you pass values into the registers. I'll leave that for now as an exercise for the reader.


    This particular example looks for a file called FOO.TXT, and loads it to $0400 (= 1,024 decimal, i.e., the screen in C64 mode). It also inlcludes a simple detection routine for the MEGA65, by asking the Hypervisor to report its version.


    The actual loading of the file is done following the onmega65 label until the RTS at the end of that routine. It does three things: (1) Sets the current file name for the Hypervisor to use. This behaves similarly to the equivalent KERNAL routine on the C64. Filename must be on a page boundary (i.e., multiple of 256 bytes) in the lower 32KB of RAM. (2) Close all currently files currently open in the Hypervisor, so we make sure we have a file descriptor available. (3) Call the convenience trap that loads the entire file at the provided address. The adress is stipulated as $ZZYYXX, i.e., you can load a file anywhere into the bottom 16MB of address space.