User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: Bare Metal Examples

Mon Jul 21, 2014 8:11 pm

krom wrote:Hi guys, sorry for the lack of updates... I have been helping with a new N64 emulator (cen64) & needed todo loads of cpu tests for the system: https://github.com/PeterLemon/N64/

I did not want to leave the Raspberry Pi Bare Metal community out of the loop, so I wrote this simple Nintendo Game Boy CPU Emulator that passes all of GB-Z80 CPU tests by blargg: https://github.com/PeterLemon/Raspberry ... MU/GameBoy

I thought this would be a fun example of how you can emulate an old 8-Bit system, using 100% ARM assembly:
It uses a static GB-Z80 opcode table which I can use to shift to the correct opcode, because I have aligned each one by the shift amount. I then use blx to run the CPU instruction.
I also use a minimum of loads & stores, as I devote ARM registers to contain the main GB-Z80 registers.
I emulate the Game Boy Background screen using DMA 2D Mode & Stride
It is early days for commercial roms to run, but a few do show title screens etc already, which is a surprise because I have only coded the bare minimum of the system to pass all these tests!
(It is also limited to 32Kb roms, because I am not emulating the Game Boy banking modes)

I am going be working on my V3D bare metal assembly triangle demo from scratch using the hackdriver demo by phire: https://github.com/phire/hackdriver
It contains everything we need, including the exact QPU fragment code needed to display a triangle on the screen =D
Great work krom, look forward to seeing your "V3D bare metal assembly triangle demo"
Batteries not included, Some assembly required.

krom
Posts: 61
Joined: Wed Dec 05, 2012 9:12 am
Contact: Website

Re: Bare Metal Examples

Tue Jul 22, 2014 5:21 pm

Cheers Dex! I'll msg you the instant I get it to work =D
P.S I bumped into David Braben again at a developer conference, updated him on my bare metal work, & told him how close we are to getting a bare metal triangle on the screen, and he said "It will be very fast!"

krom
Posts: 61
Joined: Wed Dec 05, 2012 9:12 am
Contact: Website

Re: Bare Metal Examples

Wed Jan 21, 2015 3:39 am

Sorry for the long delay, but I have great news...
Today I have managed to convert the phire Linux triangle code to bare-metal on the Raspberry-Pi, using my old V3D control list Clear Color demo as a template.

I was lucky enough to bump into phire on IRC recently, and he gave me some great advice on howto get a working demo running, by showing me an earlier source version of his triangle demo.
I used the source code here: https://github.com/phire/hackdriver
to get the correct QPU shader code to display a triangle on the screen using an earlier QPU Fill Color Shader.
After I got the face color triangle working, I moved on to the more complex QPU Vertex Color Shader found in the final phire triangle test.

My bare-metal Fill Color NV Triangle demo can be found here:
https://github.com/PeterLemon/Raspberry ... /FillColor

My bare-metal Vertex Color NV Triangle demo can be found here:
https://github.com/PeterLemon/Raspberry ... ertexColor

There is a small bug which I will try to fix tomorrow, which I only noticed when I made a larger triangle to fill the whole screen.
It has something todo with the way I generate the tiles on the screen, but if you run the demos you will see how close it is to being perfect =D

After I fix that bug, I want to explore all the other object types like Lines and Points, & other vertex types, then I shall explore texturing.
Once that is all complete, I can use an unreleased bare metal ARM vector matrix lib I made for a software 3D engine, to transform blender exported objects in 3D space, using the GPU.

Special thanks to phire & DexOS who have helped make this possible.
Last edited by krom on Sat Jan 24, 2015 4:21 am, edited 4 times in total.

krom
Posts: 61
Joined: Wed Dec 05, 2012 9:12 am
Contact: Website

Re: Bare Metal Examples

Fri Jan 23, 2015 6:28 pm

After hacking around, I have got perfect rendering of the Triangle demos above.
I have also fixed the Clear Color Demo to be correct too, using this new knowledge from correcting the Triangle Demos.

I have also updated my config.txt file to use the option framebuffer_swap=0, to be able to use the native GPU color order.
This is because the Raspberry-Pi now defaults to framebuffer_swap=1, with the newest firmware boot files.

I will now explore the Line GPU drawing modes =D

**Edit
I made some Line mode demos, using the same shaders as the Triangle demos:

Fill Color NV Line demo can be found here:
https://github.com/PeterLemon/Raspberry ... /FillColor

Vertex Color NV Line demo can be found here:
https://github.com/PeterLemon/Raspberry ... ertexColor

I'll now try to make some Point mode demos.

**Edit
I made some Point mode demos, using the same shaders as the Triangle demos.
These demos also show off the per-point Point Size NV Shader Record Flag:

Fill Color NV Point demo can be found here:
https://github.com/PeterLemon/Raspberry ... /FillColor

Vertex Color NV Point demo can be found here:
https://github.com/PeterLemon/Raspberry ... ertexColor

I'll now try to make some Triangle Strip mode demos.

**Edit
I made some Triangle Strip mode demos, using the same shaders as the Triangle demos:

Fill Color NV Triangle Strip demo can be found here:
https://github.com/PeterLemon/Raspberry ... /FillColor

Vertex Color NV Triangle Strip demo can be found here:
https://github.com/PeterLemon/Raspberry ... ertexColor

I'll try to make some Triangle Fan mode demos Next =D

**Edit
I made some Triangle Fan mode demos, using the same shaders as the Triangle demos:

Fill Color NV Triangle Fan demo can be found here:
https://github.com/PeterLemon/Raspberry ... /FillColor

Vertex Color NV Triangle Fan demo can be found here:
https://github.com/PeterLemon/Raspberry ... ertexColor

I'll try to make some Line Loop mode demos Next.

**Edit
I made some Line Loop mode demos, using the same shaders as the Triangle demos:

Fill Color NV Line Loop demo can be found here:
https://github.com/PeterLemon/Raspberry ... /FillColor

Vertex Color NV Line Loop demo can be found here:
https://github.com/PeterLemon/Raspberry ... ertexColor

I'll try to make some Line Strip mode demos Next.

**Edit
I made some Line Strip mode demos, using the same shaders as the Triangle demos:

Fill Color NV Line Strip demo can be found here:
https://github.com/PeterLemon/Raspberry ... /FillColor

Vertex Color NV Line Strip demo can be found here:
https://github.com/PeterLemon/Raspberry ... ertexColor

That is all the NV Indexed Primitive List Modes complete, for my next post I'll try to get VG Modes working.

krom
Posts: 61
Joined: Wed Dec 05, 2012 9:12 am
Contact: Website

Re: Bare Metal Examples

Sat Jan 24, 2015 7:44 pm

I have done 2D VG GPU Primitive mode tests, using VG Coordinate Array.

Fill Color VG RHT:
https://github.com/PeterLemon/Raspberry ... /FillColor

Fill Color VG RHT Strip:
https://github.com/PeterLemon/Raspberry ... /FillColor

Fill Color VG Triangle:
https://github.com/PeterLemon/Raspberry ... /FillColor

Fill Color VG Triangle Fan:
https://github.com/PeterLemon/Raspberry ... /FillColor

Fill Color VG Triangle Strip:
https://github.com/PeterLemon/Raspberry ... /FillColor

I am gonna try to get some Vertex Array Primitive demos running now =D

** Edit
I just added lots of NV Vertex Array Primitive demos here:
https://github.com/PeterLemon/Raspberry ... rtex_Array
Uses the same Primitive modes as the NV Coordinate Array demos =D

I am gonna work on some VG Inline Primitive demos now.

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: Bare Metal Examples

Sun Jan 25, 2015 4:00 pm

Great work krom, now i have some free time, i will give your demo's a test run :).
Batteries not included, Some assembly required.

Siekmanski
Posts: 8
Joined: Mon Apr 28, 2014 11:14 pm
Location: Netherlands

Re: Bare Metal Examples

Mon Jan 26, 2015 10:01 pm

Awesome code, thanks !! :D

krom
Posts: 61
Joined: Wed Dec 05, 2012 9:12 am
Contact: Website

Re: Bare Metal Examples

Tue Jan 27, 2015 4:22 am

Thanks for the kind words DexOS & Siekmanski =D

I got a bit stuck on the VG Inline Primitive demos, but I have managed to make a new Multi Sample demo:
https://github.com/PeterLemon/Raspberry ... lti_Sample
So less jaggy edges on primitives =D

I have also used while & if statements in FASMARM to generate the longer tile list needed for this demo.

I am gonna try to make a Z-buffer demo, and do a simple animation to test refreshing the screen.

krom
Posts: 61
Joined: Wed Dec 05, 2012 9:12 am
Contact: Website

Re: Bare Metal Examples

Tue Jan 27, 2015 8:38 pm

I have made a simple Refresh demo, which bounces a multi sampled vertex colored triangle from right to left on the screen:
https://github.com/PeterLemon/Raspberry ... st/Refresh

As the vertex array X coordinates are in 12.4 fixed point format, there are 16 frames of animation from 1 pixel to the next.
Everything looks really smooth, & perfectly V-Synced, with no screen tearing, so I am quite happy with the results =D

I am now gonna try and make a Z-Buffer demo, with 2 intersecting triangles now to show the Zbuffer is working as expected =D

Return to “Bare metal, Assembly language”