Skip to content

Commit e33e12c

Browse files
v1.0.0
0 parents  commit e33e12c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+11728
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Example: Basic Chip32
2+
This example demonstrates basic use of Chip32 to load a small descriptor file, parsing its header, and use it to make decisions about what images to load onto the screen.
3+
The display is split into 4 horizontal regions. One of three possible images can be loaded into each of the 4 regions. Additional error handling is present to prevent loading invalid data.
4+
The Chip32 program is smart enough to handle warm reloads, where it puts the core back into reset before loading new data, and takes it out of reset when complete. The bitstream is only loaded once on the first boot.
5+
6+
* Chip32-assisted asset load
7+
* SDRAM controller
8+
* Video generation
9+
* Reload assets during runtime via the Core Settings menu
10+
11+
12+
13+
## Legal
14+
Analogue’s Development program was created to further video game hardware preservation with FPGA technology. Analogue does not support or endorse the use of infringing content.
15+
16+
Analogue Developers have access to Analogue Pocket I/O’s so Developers can utilize cartridge adapters or interface with other pieces of original or bespoke hardware to support legacy media.

audio.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"audio": {
3+
"magic": "APF_VER_1"
4+
}
5+
}

core.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"core": {
3+
"magic": "APF_VER_1",
4+
"metadata": {
5+
"platform_ids": [
6+
"ex_platform"
7+
],
8+
"shortname": "Basic Chip32",
9+
"description": "APF core example. Displays image strips loaded via Chip32.",
10+
"author": "Example Author",
11+
"url": "https://github.com/open-fpga",
12+
"version": "1.0.0",
13+
"date_release": "2022-09-29"
14+
},
15+
"framework": {
16+
"target_product": "Analogue Pocket",
17+
"version_required": "1.1",
18+
"sleep_supported": false,
19+
"chip32_vm": "example_chip32.bin",
20+
"dock": {
21+
"supported": true,
22+
"analog_output": false
23+
},
24+
"hardware": {
25+
"link_port": false,
26+
"cartridge_adapter": -1
27+
}
28+
},
29+
"cores": [
30+
{
31+
"name": "default",
32+
"id": 0,
33+
"filename": "bitstream.rbf_r"
34+
}
35+
]
36+
}
37+
}

data.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"data": {
3+
"magic": "APF_VER_1",
4+
"data_slots": [
5+
{
6+
"name": "Configuration",
7+
"id": 1,
8+
"required": true,
9+
"parameters": 3,
10+
"extensions": [
11+
"dat"
12+
]
13+
},
14+
{
15+
"name": "Audio",
16+
"id": 99,
17+
"required": true,
18+
"parameters": 2,
19+
"filename": "ex_audio_1.wav",
20+
"extensions": [
21+
"wav"
22+
],
23+
"size_maximum": "0x3C00000",
24+
"address": "0x00400000"
25+
},
26+
{
27+
"name": "Image: Dots",
28+
"id": "0x20",
29+
"required": true,
30+
"parameters": 2,
31+
"filename": "ex_image_1.bin",
32+
"address": "0x00000000"
33+
},
34+
{
35+
"name": "Image: Grid",
36+
"id": "0x21",
37+
"required": true,
38+
"parameters": 2,
39+
"filename": "ex_image_2.bin",
40+
"address": "0x12345678"
41+
},
42+
{
43+
"name": "Image: 12 Colors",
44+
"id": "0x22",
45+
"required": true,
46+
"parameters": 2,
47+
"filename": "ex_image_3.bin"
48+
}
49+
]
50+
}
51+
}

dist/.gitkeep

Whitespace-only changes.

dist/assets/.keep

Whitespace-only changes.

dist/assets/ex_audio_1.wav

1.28 MB
Binary file not shown.

dist/assets/ex_image_1.bin

180 KB
Binary file not shown.

dist/assets/ex_image_2.bin

180 KB
Binary file not shown.

dist/assets/ex_image_3.bin

180 KB
Binary file not shown.

dist/icon.bin

2.53 KB
Binary file not shown.
168 KB
Binary file not shown.

dist/platforms/ex_platform.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"platform": {
3+
"category": "Example Cores",
4+
"name": "Example Platform",
5+
"year": 2022,
6+
"manufacturer": "Example Manufacturer"
7+
}
8+
}

info.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Example Core - Basic Chip32
2+
3+
This example demonstrates basic use of Chip32 to load a small descriptor file, parsing its header, and use it to make decisions about what images to load onto the screen.
4+
The display is split into 4 horizontal regions. One of three possible images can be loaded into each of the 4 regions. Additional error handling is present to prevent loading invalid data.
5+
The Chip32 program is smart enough to handle warm reloads, where it puts the core back into reset before loading new data, and takes it out of reset when complete. The bitstream is only loaded once on the first boot.
6+
7+
* Chip32-assisted asset load
8+
* SDRAM controller
9+
* Video generation
10+
* Reload assets during runtime via the Core Settings menu

input.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"input": {
3+
"magic": "APF_VER_1",
4+
"controllers": [
5+
{
6+
"type": "default",
7+
"mappings": [ ]
8+
}
9+
]
10+
}
11+
}

interact.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"interact": {
3+
"magic": "APF_VER_1",
4+
"variables": [
5+
{
6+
"name": "Screen Border",
7+
"id": 1,
8+
"type": "check",
9+
"enabled": true,
10+
"persist": true,
11+
"address": "0x50000000",
12+
"defaultval": 1,
13+
"value": 1,
14+
"mask": "0xFFFF0000"
15+
}
16+
]
17+
}
18+
}

output/.gitkeep

Whitespace-only changes.

output/bitstream.rbf_r

840 KB
Binary file not shown.

output/example_chip32.bin

425 Bytes
Binary file not shown.

src/chip32/example_chip32.asm

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
architecture chip32.vm
2+
output "example_chip32.bin", create
3+
4+
// Example Chip32 project
5+
6+
// we will put data into here that we're working on. It's the last 1K of the 8K chip32 memory
7+
constant rambuf = 0x1b00
8+
9+
// json slot ID
10+
constant datslot = 0x1
11+
constant soundslot = 99
12+
13+
// core ID as listed in the core.json file
14+
constant core_id = 0x0
15+
16+
// host commands
17+
constant host_reset = 0x4000
18+
constant host_run = 0x4001
19+
constant host_init = 0x4002
20+
21+
// bridge address of our "video enable" register
22+
constant videoenable = 0x51000000
23+
24+
// how many picture slots we have
25+
constant numslots = 0x3
26+
27+
// bitfield entries
28+
variable bit_coreloaded = 0x1
29+
30+
// how large the slot files are
31+
constant slotsize = 184320
32+
// how many bytes we'll load
33+
constant copysize = 46080
34+
35+
36+
// the error handler always starts here. (0x0000) DO NOT MOVE OR CHANGE ITS LOCATION
37+
jp error // jump to error handler
38+
39+
// code execution always starts here. (0x0002) DO NOT MOVE OR CHANGE ITS LOCATION
40+
start:
41+
cmp r0,#datslot // does our slot ID match the one we're looking for?
42+
jp z,loaddata
43+
exit 0 // other slots- do nothing and just exit
44+
45+
loaddata:
46+
bit r13,#bit_coreloaded // is the core already loaded? if so, skip loading it
47+
jp nz,was_loaded
48+
ld r0,#core_id // load core ID 0
49+
core r0 // we will set the bit_coreloaded later. you'll see why
50+
51+
was_loaded:
52+
ld r3,#datslot // get data slot into R3
53+
ld r2,#file_err // point to file error message preemptively
54+
open r3,r0 // open file R3, length goes into R0
55+
jp nz,spec_err // file could not be open for some reason
56+
ld r2,#size_err
57+
cmp r0,#8
58+
jp nz,spec_err // it has to be exactly 8 bytes
59+
ld r0,#rambuf // point to our RAM buffer
60+
ld r1,#8 // read 8 bytes
61+
ld r2,#file_err
62+
read r0,r1 // read in the header
63+
close
64+
jp nz,spec_err // if there was an issue reading, show the file error
65+
66+
ld r2,#head_err // point to error message
67+
ld r1,#header // point to header that we will test against
68+
ld r0,#rambuf // point to the RAM buffer where our header we loaded lives
69+
test r1,r0 // test to see if they match
70+
jp nz,spec_err // jump if they don't, showing the error in R2
71+
72+
ld r0,#host_reset // we're reasonably sure that our files are OK, so reset if this is not the first run.
73+
bit r13,#bit_coreloaded // check to see if the core's been loaded before
74+
jp z,firstrun
75+
host r0,r0 // stop CPU if not the first time
76+
77+
ld r0,#videoenable // if not the first run, disable the video scanout to prevent ram clobbering during loads
78+
ld r9,#0
79+
pmpw r0,r9 // write 0 to the display enable register (disable video scanout)
80+
81+
firstrun:
82+
ld r4,#0 // start loading slots, at ID 0
83+
ld r5,#rambuf+4 // start at slot 0 (next byte after the 4 byte header)
84+
85+
slotloop:
86+
ld.b r0,(r5) // get slot ID
87+
ld r2,#index_err // point to the index error message
88+
cmp r0,#numslots // is our slot ID larger or equal to the total number?
89+
jp nc,spec_err // carry will be set if we can successfully subtract the count and not underflow
90+
91+
asl r0,#1 // the slot ID table is 16 bit words, so we multiply by 2
92+
add r0,#picslots // add the start of the table to our index
93+
ld.w r3,(r0) // get the slot ID
94+
95+
ld r0,r4
96+
asl r0,#2 // we need to multiply the slot ID by 4, so we can index our 32 bit offset table
97+
add r0,#offsets // add the start of the table to our index
98+
ld.l r1,(r0) // load the buffer start address to put the data we're going to write
99+
100+
ld r2,#file_err // point to file error message preemptively
101+
open r3,r0 // open the file
102+
jp nz,spec_err // if the file didn't exist or there was some other problem, error out
103+
ld r2,#slot_err
104+
cmp r0,#slotsize // it must be the right size
105+
jp nz,spec_err
106+
107+
108+
ld r2,#file_err
109+
seek r1 // seek to the same offset in the file
110+
jp nz,spec_err // if something went wrong, error out
111+
112+
ld r0,#copysize // we will copy 1/4th of the image
113+
copy r1,r0 // copy the data from the file, into the frame buffer (pointed to by R1) for length R0
114+
jp nz,spec_err // if something went wrong, show an error
115+
close // close the file we copied over
116+
117+
add r5,#1 // increment entry in our .dat
118+
add r4,#1 // increment count
119+
cmp r4,#4
120+
jp nz,slotloop // do all slots
121+
122+
ld r2,#sound_err // sound playback is not implemented in the core. you may add it if you wish from the "Basic Assets" example
123+
ld r0,#soundslot // for demo purposes, show loading an additional file the easier way with LOADF
124+
loadf r0 // load the sound slot's data (sound is not implemented in the core itself)
125+
jp nz,spec_err
126+
127+
ld r0,#videoenable
128+
ld r9,#0x123456FF
129+
pmpw r0,r9 // write 1 to the display enable register (enable video scanout)
130+
131+
ld r0,#host_run // we will just run if the coreloaded bit is set
132+
bit r13,#bit_coreloaded // this is why we didn't set the bit first.
133+
jp nz,runonly
134+
135+
ld r0,#host_init
136+
or r13,#bit_coreloaded // NOW set the bit, so we only run host_init once. then call host_run after that point.
137+
runonly:
138+
host r0,r0 // run the core
139+
exit 0 // done
140+
141+
// specific errors we will display
142+
spec_err:
143+
printf r2
144+
exit 1
145+
146+
// main error handler if something REALLY BAD happened
147+
error:
148+
ld r0,#err1 // print "Error 0x12 at 0x1234"
149+
printf r0
150+
err r0,r1
151+
hex.b r0
152+
ld r0,#err2
153+
printf r0
154+
hex.w r1
155+
ld r0,#err3
156+
printf r0
157+
exit 1
158+
159+
160+
161+
// table of offsets into the frame buffer where our segments should be loaded
162+
offsets:
163+
dl 0x00000
164+
dl 0x0B400
165+
dl 0x16800
166+
dl 0x21C00
167+
168+
// table of picture slot IDs in the json file
169+
picslots:
170+
dw 0x20
171+
dw 0x21
172+
dw 0x22
173+
174+
// header for our .dat files
175+
header:
176+
db "TEST",0x0
177+
178+
// error messages
179+
size_err:
180+
db "File Not 8 Bytes!",10,0
181+
file_err:
182+
db "Error Opening File!",10,0
183+
head_err:
184+
db "Invalid Header!",10,0
185+
index_err:
186+
db "Invalid Index!",10,0
187+
slot_err:
188+
db "Slot Size Error!",10,0
189+
sound_err:
190+
db "Sound Slot Error!",10,0
191+
192+
// parts for showing the error message
193+
err1:
194+
db "Error 0x",0
195+
err2:
196+
db " at 0x",0
197+
err3:
198+
db 10,0
199+
200+

src/fpga/.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
*/db/
2+
*/incremental_db/
3+
*/simulation/
4+
*/greybox_tmp/
5+
incremental_db/
6+
db/
7+
PLLJ_PLLSPE_INFO.txt
8+
c5_pin_model_dump.txt
9+
cr_ie_info.json
10+
*.pin
11+
*.pof
12+
*.ptf.*
13+
*.qar
14+
*.qarlog
15+
*.qws
16+
*.rpt
17+
*.smsg
18+
*.sof
19+
*.sopc_builder
20+
*.summary
21+
*.txt
22+
*.bak
23+
*.cmp
24+
*.done
25+
*.xml
26+
*.sld
27+
*.cdf
28+

0 commit comments

Comments
 (0)