Shop OBEX P1 Docs P2 Docs Learn Events
Tile Graphics Renderer — Parallax Forums

Tile Graphics Renderer

maccamacca Posts: 718
edited 2014-10-28 07:49 in Propeller 1
Hello All,

During the past weeks I wrote a graphics renderer for the vga driver.

Specifications:
  • 256x192 or 256x256 pixels, 6bpp resolution
  • 8x8 pixels tiles
  • 16x16 pixels sprites
  • 16 (out of 64) colors palettes
  • Up to 256 tiles, 64 sprites and 64 palettes

Notes:
  • Tiles map is 34x34 tiles (instead of 32x32 for 256x256 pixels) to allow scrolling and offscreen background updates.
  • Sprites are drawn on a virtual screen with a 16 pixels border around the physical screen to allow objects to move out of the screen. Coordinates 0,0 are out of screen, 16,16 is the top-left corner.
  • Sprites palettes are actually 15 colors, with color 0 used as transparency.
  • The number of sprites on screen and on a single scanline depends on the number of rendering COGs.

Attached is a small project demonstrating some of the capabilities. It runs on VGA and should be compatibile with the existing demo boards.

My intentions are to write an engine usable as a base for games development so designers can concentrate on the game and graphics instead of understanding how the drivers and renderers work. I also started to write a rudimentary tile and sprite editor in Java.

I whish to thanks all whose code examples and indirect suggestions have contributed to this code (you'll recognize kuroneko's VGA driver and memory transfer code, sid cog from Johannes Ahlebrand, and inspirations from other code examples).

Feel free to make suggestions and code optimizations.

Hope you enjoy.

demo-bst-archive-130316-114946.zip

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2013-03-16 03:14
    There seems to be a timing issue. What's up with that? The pattern is repeated vertically so it looks like a renderer issue. Just checked, it's the graphics driver.
    951 x 590 - 1M
  • maccamacca Posts: 718
    edited 2013-03-16 03:31
    I don't understand the problem from your thumbnail (seems more like a composite video interference), on my VGA monitor (an old Sony Multiscan 100ES) the image is perfect.
    Based on my tests, the renderer should have plenty of time to do everything, but you can increase the number of rendering cogs (graphics_renderer.spin, COGS constant, set it to 5).
  • kuronekokuroneko Posts: 3,623
    edited 2013-03-16 03:41
    The problem is that you removed code which shouldn't have been removed. Putting it back in fixes the problem.
  • maccamacca Posts: 718
    edited 2013-03-16 04:01
    Whops, that's the result of (failed) experiments with the driver. Forgot I had removed that NOPs. Archive updated.

    Wondering why I don't see any difference on my monitor.
  • JT CookJT Cook Posts: 487
    edited 2013-03-19 20:10
    Monitors very in tolerance. For example, a raster monitor will have more tolerance than an LCD monitor since you are controlling the gun instead of just interpreting a signal. And the signal interpretation may very per monitor.

    That said, the driver sounds pretty nice. I think a 4bpp is the right compromise because you still have a good amount of colors, but can store twice as much data as an 8bpp image. For my game I wish I would have made a 4bpp driver because visually there would have been little, if any, visual difference.

    The other important key which it sounds like you are addressing is an easy way to get images into the program. Sure, those of us who are hard core can figure out these scripts and converters, but for a beginner these are daunting and you have to have a good understanding of how it wants the image. Before I made the game, I had an image editor i wrote for Linux which was to be a campanion to the driver to make things easier. This I did not finish, but that is definitely the right direction if you want more than 3 people to use it ;)
  • maccamacca Posts: 718
    edited 2013-05-11 09:32
    Just a note to say that the project was much evolved since the last post, I forgot to update this thread for all those interested.

    All drivers were ported to C and optimized a bit with configuration options to save some bytes when certain features are not used, the engine can be used for both spin and C projects.

    A multiplatform Game Tools application can be used to draw tile and sprite graphics as well as import from graphics files. Starting from the last release, it has an integrated code editor that allows to write sketch-like code in C. The application can also call the GCC tools to compile, link and upload the code to a propeller board. The editor doesn't have much features yet, it just has a basic syntax highlight, and gets slow as the code grows, but it is usable. As you may guess, this was largely inspired by the Arduino IDE, from which I borrowed some code, and uses the .pge extension to identify its own files.

    The project is hosted on http://dev.maccasoft.com/propge from which you can access the downloadable binaries as well as the source code repository and some documentation. The application is downloadable as tar.gz or .zip files, complete with the spin and c libraries. It requires Propeller GCC and BSTC on the command path to compile and upload code (not included).

    Enjoy!
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2014-10-28 07:49
    @macca,

    First, this is a wonderful object for the Propeller. I'm using this in my current project. Thank you!

    Second, is there any way possible to squeeze a COG away from the Tile Graphics Renderer?
    I've tried reducing sprites, and reducing cogs, but this seems to have negative effects on the object's functionality.

    Thank you
    Jeff
  • I tried your Propge on my PropBOE but i have these parallel lines
    frogger.jpg

    here are what i have done to compile
    inside the Makefile i removed the option -q for bstc because bstc complained that this option doesn't exist.

    for the pingroup i put 1 inside the vga_driver
    vgrp    = 1                                   ' pin group
    

    what should i have to change in this vga_driver or elsewhere?
    640 x 360 - 77K
  • laurent974 wrote: »
    I tried your Propge on my PropBOE but i have these parallel lines

    here are what i have done to compile
    inside the Makefile i removed the option -q for bstc because bstc complained that this option doesn't exist.

    for the pingroup i put 1 inside the vga_driver
    vgrp    = 1                                   ' pin group
    

    what should i have to change in this vga_driver or elsewhere?

    Check the pins for the other elements, pin group 1 should be 8-15, the audio driver uses pins 10 and 11, if you haven't changed that it will conflict (sound.c initialize_sound).
  • laurent974laurent974 Posts: 77
    edited 2017-03-27 08:45
    thank you, i changed the pin inside the file sound.c and now the screen is ok.

    but i don't have any sound. For the PropBOE right and left are 26 and 27. So i change only this
    void initialize_sound() {
        ay3891_start(26, 27);
    

    but i haven't any music. Note : i'm not at the game screen, i' m at the starting screen.
  • laurent974 wrote: »
    thank you, i change the pin inside the file sound.c and now the screen is ok.

    but i don't have any sound. For the PropBOE right and left are 26 and 27. So i change only this
    void initialize_sound() {
        ay3891_start(26, 27);
    

    but i haven't any music. Note : i'm not at the game screen, i' m at the starting screen.

    Yes, the starting screen doesn't have any sound.
    It plays a song when starting the game by pressing start and another while playing.

  • Great that works.

    Now the next move is to adapt the controller. Instead of a NES/pad, i have a tilt sensor dual axis 2125 and 2 pushbuttons. I have never played with the dual axis since now. I have tested the 2125 on simple-Ide, it works.

    is there any simple way to convert tilt to your nes/pad code?
  • laurent974 wrote: »
    Great that works.

    Now the next move is to adapt the controller. Instead of a NES/pad, i have a tilt sensor dual axis 2125 and 2 pushbuttons. I have never played with the dual axis since now. I have tested the 2125 on simple-Ide, it works.

    is there any simple way to convert tilt to your nes/pad code?

    I never worked with such sensors, I guess you have to set a threshold to detect the direction and avoid false triggers with small movements. Assuming 0 is the central value and +/-128 is the range, I would write something like:
    if (valueX > 32) nes_bits |= NES0_RIGHT;
    if (valueX < -32) nes_bits |= NES0_LEFT;
    if (valueY > 32) nes_bits |= NES0_UP;
    if (valueY < -32) nes_bits |= NES0_DOWN;
    

    With +/-32 being the threshold.

    There is the wii classic controller code that does something similar with the analog joystick. I never tested that code so it may not work as expected but it could be used as a base for your sensor.
  • laurent974laurent974 Posts: 77
    edited 2017-03-28 12:30
    Great it works !
    i copy your nes_padctrl.c to a new file 2125.c, i replaced the read_gamepad by this
    void read_gamepad() {
        int x = mx_tilt(6);                          // X-axis tilt
        int y = mx_tilt(7);                          // Y-axis tilt
        int button_B = input(1);           // 2 push buttons connected to 
        int button_A = input(0);          // Pin 0 and 1
        
        // data is now ready to shift out, clear storage
        nes_bits = 0;
           
        if (y > 32)  nes_bits |= NES0_RIGHT;
        if (y < -32) nes_bits |= NES0_LEFT;
        if (x > 32)  nes_bits |= NES0_DOWN;
        if (x < -32) nes_bits |= NES0_UP;
        
        if (button_B==1) nes_bits |= NES0_B|NES0_SELECT;
        if (button_A==1) nes_bits |= NES0_A|NES0_START;
        
    }
    

    and now i have a frogger game for my son. i won't tell him now otherwise i won't be able to get back my propBoe.

    I'll try to port some of your other games.
    I wish to have pacman but it will be long before i can port the pacman found in this forum.


    if you don't mind i'll share the code to the dedicate thread i post sometime ago on PropBOe and VGA game.


    Note: i ported your code to simpleIde. for me it's simpler since i use both windows and linux with different PC.


    Edit: i had to modify also the include inside the main.c
    #include "controller.h"   // change from initial code to include dual axis gamepad
    //#include "nes_gamepad_ctrl.h"
    
    I don't know if it's the best way to do it. maybe something with
    #ifdef nameofboard
    
    should be better but i don't know how to retrive the boardname from simpleIde config file
  • laurent974 wrote: »
    if you don't mind i'll share the code to the dedicate thread i post sometime ago on PropBOe and VGA game.

    I'm glad it worked. Feel free to share it as you like.
    Note: i ported your code to simpleIde. for me it's simpler since i use both windows and linux with different PC.

    Edit: i had to modify also the include inside the main.c
    #include "controller.h"   // change from initial code to include dual axis gamepad
    //#include "nes_gamepad_ctrl.h"
    
    I don't know if it's the best way to do it. maybe something with
    #ifdef nameofboard
    
    should be better but i don't know how to retrive the boardname from simpleIde config file

    I don't think the board selection is passed to the compiler, as far as I know it is used only by the loader.
Sign In or Register to comment.