I did a poor lunar lander to demo the ili9341 read_pixel function.
It is a useful function but the demo only applies to ili9341 but is commented for pic or uno. I chose uno.
The code checks the 4 corners of the sprite which are black against the background. If a corner is not black then it is the landscape.. test next sprite x,y before drawing.
Also the sprite has black pixels around it so it does not need erasing before it's redrawn as it erases itself when redrawn as it only moves 1 pixel at a time.
The game was supposed to have inertia but I got bored...and I didn't debounce the buttons either.
It has a fuel bar..no fuel..no thrust. Change to 1000 to make it harder or redraw the landscape.
I even used goto as it seemed so elegant and simple. Structured is hard. https://www.youtube.com/watch?v=SGJFApFqx1Q
;ili9341 ReadPixel_ILI9341 test for pic and avr 328p;#chip 18f25k22,64;#config MCLRE=on;#option Explicit;#include <glcd.h>;#define GLCD_TYPE GLCD_TYPE_ILI9341'Pin mappings for ILI9341;#define GLCD_DC portc.2;#define GLCD_CS portc.0;#define GLCD_RESET portc.1'As we are using Harware SPI this cannot be change on this chip. This is a non-PPS chip.;#define GLCD_DI portc.4;#define GLCD_DO portc.5;#define GLCD_SCK portc.3;#define ILI9341_hardwarespi;this 328p setup
#chipmega328p,16
#include<glcd.h>
#optionexplicit;--------------
#defineGLCD_TYPEGLCD_TYPE_ILI9341
#defineGLCD_DCportb.0; DIGITAL_8 ' Data command line
#defineGLCD_CSportb.2; DIGITAL_10 ' Chip select line
#defineGLCD_RESETportb.1; DIGITAL_9 ' Reset line
#defineGLCD_DIportb.4; DIGITAL_12 ' Data in | MISO - Not used therefore not really required
#defineGLCD_DOportb.3; DIGITAL_11 ' Data out | MOSI
#defineGLCD_SCKportb.5; DIGITAL_13 ' Clock Line
#defineILI9341_HardwareSPI' remove/comment out if you want to use software SPI.;rename colours to make less typeing
#definebkILI9341_BLACK
#definereILI9341_RED
#definegrILI9341_GREEN
#defineblILI9341_BLUE
#definewhILI9341_WHITE
#definepuILI9341_PURPLE
#defineyeILI9341_YELLOW
#definecyILI9341_CYAN
#definedgILI9341_D_GRAY
#definelgILI9341_L_GRAY
#definesiILI9341_SILVER
#definemaILI9341_MAROON
#defineolILI9341_OLIVE
#defineliILI9341_LIME
#defineaqILI9341_AQUA
#defineteILI9341_TEAL
#definenaILI9341_NAVY
#definefuILI9341_FUCHSIA
#defineGLCD_EXTENDEDFONTSET1;pic button ports, all buttons held hi by 10k resistors;#define left_thrust_button portb.5;#define vertical_thrust_button portb.4;#define right_thrust_button portb.3;uno button ports, all buttons held hi by 10k resistors
#defineleft_thrust_buttonportc.0
#definevertical_thrust_buttonportc.1
#defineright_thrust_buttonportc.2dirleft_thrust_buttonindirvertical_thrust_buttonindirright_thrust_buttonin;dimtempasBytedimpixel_colour_left_top,pixel_colour_right_top,pixel_colour_left_bottom,pixel_colour_right_bottomaslong;test pixel colourdim ,sprite_height,sprite_widthasbyte;height and width of sprite in pixelsdimsprite_x,sprite_yasWord;xy position of spritedimptr,spritedata_ptr,pixel,x_dir,fuelasworddimgravity,gravity_count,x_driftasByte;start:
wait5sGLCDRotate(Portrait);xy=0 top left,;optionally you can rotate the screen.GLCDRotate ( Portrait_Rev )GLCDCLSbk;black backgroundfuel=1400sprite_x=120:sprite_y=40; sprite x,y startsprite_height=24:sprite_width=24gravity_count=20x_drift=20x_dir=0;;draw lanscapeline0,16,16,80,whline16,80,48,100,whline48,100,30,200,whline30,200,40,210,whline40,210,50,290,whline50,290,200,319,whline200,319,230,319,whline230,319,230,290,whline230,290,210,240,whline210,240,120,230,whline120,230,120,200,whline120,200,220,210,whline220,210,239,16,whGLCDfntDefaultsize=2GLCDPrint0,0,"FUEL"line60,8,fuel/10,8,wh;sprite (sprite_x,sprite_y) ;draw sprite;----------------------------------do;main looppset60+(fuel/10),8,bkpixel_colour_left_bottom=ReadPixel_ILI9341(sprite_x ,sprite_y+23)and0xfffff;left bottom pixel colourpixel_colour_right_bottom=ReadPixel_ILI9341(sprite_x+23,sprite_y+23)and0xfffff;right bottom pixel colourpixel_colour_left_top=ReadPixel_ILI9341(sprite_x ,sprite_y)and0xfffff;left top pixel colourpixel_colour_right_top=ReadPixel_ILI9341(sprite_x+23,sprite_y)and0xfffff;right top pixel colourifpixel_colour_left_bottom>0thenifpixel_colour_right_bottom>0then;both pixels lit so flatGLCDPrint70,100,"LANDED",whgotostartendifendififpixel_colour_left_top>0thencrashedGLCDPrint40,100,"top left",whgotostartendififpixel_colour_right_top>0thencrashedGLCDPrint40,100,"top right",whgotostartendififpixel_colour_left_bottom>0thencrashedGLCDPrint40,100,"left bottom",wh;hit left bottomgotostartendififpixel_colour_right_bottom>0thencrashedGLCDPrint40,100,"right bottom",wh;hit right bottomgotostartendifgravity_count=gravity_count+1iffuel>2thenifvertical_thrust_button=0thengravity_count=gravity_count-2flamefuel=fuel-2endififleft_thrust_button=0thenflamefuel=fuel-1x_drift=x_drift+1elseifright_thrust_button=0thenflamefuel=fuel-1x_drift=x_drift-1endifendif;ifx_drift=15thenx_drift=20x_dir=65535sprite_x=sprite_x+x_direlseifx_drift=25thenx_drift=20x_dir=1sprite_x=sprite_x+x_direndifsprite(sprite_x,sprite_y);draw sprite;ifgravity_count=15thengravity_count=20sprite_y=sprite_y-1elseifgravity_count=25thengravity_count=20sprite_y=sprite_y+1endififsprite_y<30thensprite_y=30loop;----------------------------------subsprite(sprite_x,sprite_y);fills box with sprite data; SetAddressWindow_ILI9341 ( sprite_x,sprite_y,sprite_x + sprite_width-1,sprite_y + sprite_height - 1 )SetAddressWindow_ILI9341(sprite_x,sprite_y,sprite_x+23,sprite_y+23)forptr=1to576;(sprite_width * sprite_height)ReadTablelander,ptr,pixelSendWord_ILI9341pixelnextptrendsub;subflamelinesprite_x+6,sprite_y+12,sprite_x+11,sprite_y+21,whlinesprite_x+16,sprite_y+12,sprite_x+13,sprite_y+21,whendsub;subcrashedforptr=1to20circlesprite_x+11,sprite_Y+11, ptr, whwait100msnextptrforptr=1to20circlesprite_x+11,sprite_Y+11, ptr, bkwait100msnextptrendsub;;sprite data;1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 21 23 24tablelanderbk,bk,bk,bk,bk,bk,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,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,wh,bk,bk;15bk,wh,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,wh,bk;16bk,wh,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,wh,bk;17bk,bk,wh,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,wh,bk,bk;18bk,bk,bk,wh,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,wh,bk,bk,bk;19bk,bk,bk,wh,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,wh,bk,bk,bk;20bk,bk,bk,wh,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,wh,bk,bk,bk;21bk,bk,wh,wh,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,wh,wh,bk,bk;22bk,wh,wh,wh,wh,wh,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,wh,wh,wh,wh,wh,bk;23bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk;24endtable;
Last edit: stan cartwright 2020-03-11
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Cheers. It was supposed to help others using ili9341, which Evan has put much work into.
His demo, though practical doesn't inspire you. I hoped this would.
Maybe glcd games is not what pics were meant for as there are better alternatives but once the hardware is set up, it's fun.
Checking a line is lit can lead to it not actually being lit as lines are made of pixels and not pixels and a condition can occur when it scans a pixel on a line and it's not lit and the next position is not lit.so it misses it.
I was gonna write the land scape to a table, draw it once then offset it x+1.y+1 and draw it again so the landscape was thicker.
Plenty to play with and enjoy the ili9341. h.
Missile command would be easy..ish
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am wondering if 80's style 3d graphics would be possible. The trig functions are there.
Credit to Evan for the ili9341 include and features.
i got another glcd display that Evan has supported,uses 8 pin data and other clock etc. but don't run that much faster than using spi really it seems....side by side comparison needed.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Re 3d Graphics. I would be using a table to draw the 3D effects, The maths of the TRIG ops could be very slow. As you can only have a limited number of rotational positions for the 'object' you could put all the possible data into a table... But, I would test both methods.
Re SPI, 8Bit performance. It all depends. There are many parameters that impact performance but a full port (NOT AN UNO which does two write per byte) would be fastest.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I think pacman would involve a lot more than you'd think. Those old sinclair Z80 games were quite good for the hardware they had ie non but they worked by knowing the screen memory, which was refreshed regularly. No AYxxx sound chip and no graphic acceration, which the commode 64 did have and 6502 asm was simpler than Z80 but the Z80 had commands like LDIR which speeded code up.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Re 3d graphics.
yes a table of pre defined 3D graphics would be better for drawing shapes.
Maybe no trig to define the data, just a win prog that rotates a shape and scales it.
The scaleing function might be useful depending how fast it is.
Calculations between frames slow graphics display.
Using a tiny ssd oled with the display as 1K ram is a nicer model to work on but it's so tiny!!
You can mess with screen ram in theory directly. The include is a bit hackable if you want to, again another Evan effort to create an include. Who else would have?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
A thoughts regarding the calc timing between frames. Why not test using an interrupt to update the frames every 1/25th of second. Then you may have time to do the calcs - try on on a working solution like the lander.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I remember Elite for the BBC micro, which was too expensive for me. It was released on spectrum later. Apparently it's done with matrices which are like arrays of data. I remember being asked to write for the Electron micro but it used an ULA like the Spectrum and was much slower than BBC micro, using the same code...10X slower.
Amstrad 464 was z80 but it had pallette switching meaning you could draw different shapes in different colours and animate by changing the colour values even though they were all on screen at once. https://www.youtube.com/watch?v=AuvbZpH1QuE
Last edit: stan cartwright 2020-03-17
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Probably on a bbc puter which was nice hardware and well documented.
Spectrum we sort of worked how it worked but the hardware was totally different, ie non.
but the z80 pissed all over a 6502 :)
would supporting AY-3-8910 be interesting or has been done or are better chips to use?
I do not know the 3d stuff that can be done with gcb. An illusion with lines and going left right and forward I will test but will be too slow I think without palette switching ie re drawing and erasing stuff
The ili displays were cheap and gcb does a good job of supporting them.
Pity about 3.3V logic levels. Apart from that very nice and more interesting than mono 2 line displays...which if you had the method could do crude graphics. I got a psion 2 line hand held thing some where that you can program...yawn
Using a pic at 3.3V is a simple hardware solution
I don't know why I chose a uno and a logic level converter
If you want to see what a pic/uno can do using #include <glcd.h> an ILI9341 is a nice display to play with.
You could find the sprite code your self in the ili9341.h and see how the pixel read works.
It's a fun display to play with and like most gcb progs quick to alter and see results</glcd.h>
Last edit: stan cartwright 2020-03-18
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I was up to 3.30 am searching for 3d graphic tutorials but they are mostly direct x and open gl, not old school. Anyway self isolating even though I feel ok...even after drinking Russian standard vodka cos I needed to relax. I get irate staying in. I can go into my garden but the rain has made it very wet and it's a pain to go to my shed and get the galllon of isopropanol to make hand cleanser. I don't keep much indoors as it's 99.5% and inflammable.
Get back when I sort a matrix for a cube. Take care all.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I did a poor lunar lander to demo the ili9341 read_pixel function.
It is a useful function but the demo only applies to ili9341 but is commented for pic or uno. I chose uno.
The code checks the 4 corners of the sprite which are black against the background. If a corner is not black then it is the landscape.. test next sprite x,y before drawing.
Also the sprite has black pixels around it so it does not need erasing before it's redrawn as it erases itself when redrawn as it only moves 1 pixel at a time.
The game was supposed to have inertia but I got bored...and I didn't debounce the buttons either.
It has a fuel bar..no fuel..no thrust. Change to 1000 to make it harder or redraw the landscape.
I even used goto as it seemed so elegant and simple. Structured is hard.
https://www.youtube.com/watch?v=SGJFApFqx1Q
Last edit: stan cartwright 2020-03-11
As Brucie might have said... Good game, good game!
Well done, I like that.
Cheers. It was supposed to help others using ili9341, which Evan has put much work into.
His demo, though practical doesn't inspire you. I hoped this would.
Maybe glcd games is not what pics were meant for as there are better alternatives but once the hardware is set up, it's fun.
Checking a line is lit can lead to it not actually being lit as lines are made of pixels and not pixels and a condition can occur when it scans a pixel on a line and it's not lit and the next position is not lit.so it misses it.
I was gonna write the land scape to a table, draw it once then offset it x+1.y+1 and draw it again so the landscape was thicker.
Plenty to play with and enjoy the ili9341. h.
Missile command would be easy..ish
I am wondering if 80's style 3d graphics would be possible. The trig functions are there.
I am wondering if 80's style 3d graphics would be possible. The trig functions are there.
Credit to Evan for the ili9341 include and features.
i got another glcd display that Evan has supported,uses 8 pin data and other clock etc. but don't run that much faster than using spi really it seems....side by side comparison needed.
Cheers.
PACMAN first surely?
Re 3d Graphics. I would be using a table to draw the 3D effects, The maths of the TRIG ops could be very slow. As you can only have a limited number of rotational positions for the 'object' you could put all the possible data into a table... But, I would test both methods.
Re SPI, 8Bit performance. It all depends. There are many parameters that impact performance but a full port (NOT AN UNO which does two write per byte) would be fastest.
I think pacman would involve a lot more than you'd think. Those old sinclair Z80 games were quite good for the hardware they had ie non but they worked by knowing the screen memory, which was refreshed regularly. No AYxxx sound chip and no graphic acceration, which the commode 64 did have and 6502 asm was simpler than Z80 but the Z80 had commands like LDIR which speeded code up.
Re 3d graphics.
yes a table of pre defined 3D graphics would be better for drawing shapes.
Maybe no trig to define the data, just a win prog that rotates a shape and scales it.
The scaleing function might be useful depending how fast it is.
Calculations between frames slow graphics display.
Using a tiny ssd oled with the display as 1K ram is a nicer model to work on but it's so tiny!!
You can mess with screen ram in theory directly. The include is a bit hackable if you want to, again another Evan effort to create an include. Who else would have?
A thoughts regarding the calc timing between frames. Why not test using an interrupt to update the frames every 1/25th of second. Then you may have time to do the calcs - try on on a working solution like the lander.
I remember Elite for the BBC micro, which was too expensive for me. It was released on spectrum later. Apparently it's done with matrices which are like arrays of data. I remember being asked to write for the Electron micro but it used an ULA like the Spectrum and was much slower than BBC micro, using the same code...10X slower.
Amstrad 464 was z80 but it had pallette switching meaning you could draw different shapes in different colours and animate by changing the colour values even though they were all on screen at once. https://www.youtube.com/watch?v=AuvbZpH1QuE
Last edit: stan cartwright 2020-03-17
Anything is possible.... I remember Elite.
Probably on a bbc puter which was nice hardware and well documented.
Spectrum we sort of worked how it worked but the hardware was totally different, ie non.
but the z80 pissed all over a 6502 :)
would supporting AY-3-8910 be interesting or has been done or are better chips to use?
https://www.youtube.com/watch?v=GpWoF5uVgbA
Last edit: stan cartwright 2020-03-18
I do not know the 3d stuff that can be done with gcb. An illusion with lines and going left right and forward I will test but will be too slow I think without palette switching ie re drawing and erasing stuff
The ili displays were cheap and gcb does a good job of supporting them.
Pity about 3.3V logic levels. Apart from that very nice and more interesting than mono 2 line displays...which if you had the method could do crude graphics. I got a psion 2 line hand held thing some where that you can program...yawn
Using a pic at 3.3V is a simple hardware solution
I don't know why I chose a uno and a logic level converter
If you want to see what a pic/uno can do using #include <glcd.h> an ILI9341 is a nice display to play with.
You could find the sprite code your self in the ili9341.h and see how the pixel read works.
It's a fun display to play with and like most gcb progs quick to alter and see results</glcd.h>
Last edit: stan cartwright 2020-03-18
The editor seems behaving strangely
I was up to 3.30 am searching for 3d graphic tutorials but they are mostly direct x and open gl, not old school. Anyway self isolating even though I feel ok...even after drinking Russian standard vodka cos I needed to relax. I get irate staying in. I can go into my garden but the rain has made it very wet and it's a pain to go to my shed and get the galllon of isopropanol to make hand cleanser. I don't keep much indoors as it's 99.5% and inflammable.
Get back when I sort a matrix for a cube. Take care all.
I found this freebasic code for a rotating cube and will try converting it to gcb.
lines like this will be hard but no trig. rx = -0.1 : rem rotation angle x
http://retro64.altervista.org/ProgrammingExamples/Freebasic/3dcube_04.bas