Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ks6n19
project
Commits
6b809782
Commit
6b809782
authored
4 years ago
by
ks6n19
Browse files
Options
Downloads
Patches
Plain Diff
main.c edited to include button 0 and 1 as x1 ,y1
parent
9b400038
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
software/code/main.c
+64
-156
64 additions, 156 deletions
software/code/main.c
with
64 additions
and
156 deletions
software/code/main.c
+
64
−
156
View file @
6b809782
#define __MAIN_C__
#define __MAIN_C__
#include
<stdint.h>
#include
<stdint.h>
#include
<stdio.h>
#include
<stdbool.h>
#include
<math.h>
// Define bool for MSVC boolean operation
#pragma once
#define false 0
#define true 1
#define bool int
// Define the raw base address values for the i/o devices
// Define the raw base address values for the i/o devices
...
@@ -11,10 +17,9 @@
...
@@ -11,10 +17,9 @@
#define AHB_PIX_BASE 0x50000000
#define AHB_PIX_BASE 0x50000000
// Define pointers with correct type for access to 32-bit i/o devices
// Define pointers with correct type for access to 32-bit i/o devices
volatile
uint
32
_t
*
SW_REGS
=
(
volatile
uint
32
_t
*
)
AHB_SW_BASE
;
volatile
uint
16
_t
*
SW_REGS
=
(
volatile
uint
16
_t
*
)
AHB_SW_BASE
;
volatile
uint
32
_t
*
PIX_REGS
=
(
volatile
uint
32
_t
*
)
AHB_PIX_BASE
;
volatile
uint
16
_t
*
PIX_REGS
=
(
volatile
uint
16
_t
*
)
AHB_PIX_BASE
;
#include
<stdint.h>
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
// Functions provided to access i/o devices
// Functions provided to access i/o devices
...
@@ -24,22 +29,16 @@ void write_pix( int p_x, int p_y, int colour) {
...
@@ -24,22 +29,16 @@ void write_pix( int p_x, int p_y, int colour) {
int
pix_address
;
int
pix_address
;
pix_address
=
p_x
+
640
*
p_y
;
pix_address
=
p_x
+
640
*
p_y
;
PIX_REGS
[
pix_address
]
=
colour
;
PIX_REGS
[
pix_address
]
=
colour
;
}
}
bool
PointinTriangle
(
int
x1
,
int
y1
,
int
x2
,
int
y2
,
int
x3
,
int
y3
,
int
x
,
int
y
){
// Read out (void) removed from the code because
// functionality does not exist in main()
int
L1_detT
=
((
y2
-
y3
)
*
(
x
-
x3
))
+
((
x3
-
x2
)
*
(
y
-
y3
))
;
int
L2_detT
=
((
y3
-
y1
)
*
(
x
-
x3
))
+
((
x1
-
x3
)
*
(
y
-
y3
))
;
int
detT
=
((
y2
-
y3
)
*
(
x1
-
x3
))
+
((
x3
-
x2
)
*
(
y1
-
y3
))
;
if
((
L1_detT
+
L2_detT
)
>
detT
)
return
true
;
else
return
false
;
}
/////////////////////////////////////////////////////////////////
// Functions to interface with switches and buttons
/////////////////////////////////////////////////////////////////
uint
32
_t
read_switches
(
int
addr
)
{
uint
16
_t
read_switches
(
int
addr
)
{
return
SW_REGS
[
addr
];
return
SW_REGS
[
addr
];
...
@@ -70,148 +69,57 @@ void wait_for_any_switch_data(void) {
...
@@ -70,148 +69,57 @@ void wait_for_any_switch_data(void) {
return
;
return
;
}
}
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
// Main Function
// Main Function
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
int
main
(
void
)
{
int
main
(
void
)
{
struct
Screen
screen
;
screen
.
width
=
640
;
screen
.
height
=
480
;
Mole
moles
[
9
];
time_t
seconds
;
int
moleRadius
=
50
;
int
spacing
=
5
;
int
maxHeight
=
90
;
for
(
int
i
=
0
;
i
<
9
;
i
++
){
int
row
=
i
/
3
;
int
column
=
i
%
3
;
struct
Mole
m
;
m
.
centerX
=
(
screen
.
width
/
2
-
moleRadius
*
1
.
5
)
+
row
*
(
moleRadius
+
spacing
);
m
.
centerY
=
(
screen
.
height
/
2
-
moleRadius
*
1
.
5
)
+
row
*
(
moleRadius
+
spacing
);
m
.
radius
=
moleRadius
;
moles
[
i
]
=
m
;
}
while
(
1
){
time
(
&
seconds
);
for
(
int
i
=
0
;
i
<
9
;
i
++
){
struct
Mole
m
=
moles
[
9
];
physics
(
m
,
maxHeight
,
seconds
)
}
}
}
void
drawTriangle
(
int
pos1
,
int
pos2
,
int
pos3
){
}
////////////////////////////
///////// STRUCTURES ///////
////////////////////////////
struct
Screen
{
int
width
;
int
hright
;
while
(
1
)
{
}
int
x1
;
int
y1
=
30
;
struct
Mole
{
int
x2
=
50
;
int
centerX
;
int
y2
=
300
;
int
centerY
;
int
radius
=
30
;
int
x3
=
500
;
int
height
=
0
;
int
y3
=
70
;
int
oldTime
=
0
;
m
.
state
=
random
;
}
int
L1_detT
;
int
L2_detT
;
int
detT
;
int
L1_positive
,
L2_positive
,
L3_positive
;
void
drawCircle
(
int
centerX
,
int
centerY
,
int
radius
,
int
thicknessMax
,
float
angleMax
,
int
color
){
for
(
int
thickness
=
0
;
thickness
<
thicknessMax
;
thickness
++
){
wait_for_any_switch_data
();
for
(
float
angle
=
0
;
angle
<
angleMax
;
angle
++
){
float
posX
=
centerX
+
((
radius
+
thickness
)
*
cos
(
angle
*
PI
/
180
.
0
));
float
posY
=
centerY
+
((
radius
+
thickness
)
*
sin
(
angle
*
PI
/
180
));
write_px
((
int
)
posX
,
(
int
)
posY
,
color
);
}
}
}
void
render
(
struct
Mole
mole
,
int
color
){
drawCircle
(
mole
.
centerX
,
mole
.
centerY
,
mole
.
radius
,
5
,
360
,
1
);
int
newR
=
mole
.
radius
-
5
;
for
(
int
i
=
mole
.
height
;
i
>=
0
;
i
--
){
write_px
((
int
)
mole
.
centerX
+
newR
,
i
+
centerY
,
color
)
write_px
((
int
)
mole
.
centerX
-
newR
,
i
+
centerY
,
color
)
}
drawCircle
(
mole
.
centerX
,
mole
.
centerY
+
mole
.
height
,
newR
,
1
,
180
,
1
);
}
void
physics
(
struct
Mole
m
,
int
maxHeight
,
int
time
){
if
(
time
-
m
.
oldTime
<
200
)
return
;
if
(
m
.
height
<
maxHeight
&&
m
.
state
==
0
){
m
.
height
=
m
.
height
+
1
;
}
else
{
m
.
state
=
1
;
}
if
(
m
.
height
>
0
&&
m
.
state
==
1
){
if
(
check_switches
(
0
)
)
{
m
.
height
--
;
x1
=
read_switches
(
0
)
;
}
else
{
m
.
state
=
0
;
}
}
}
if
(
check_switches
(
1
)
)
{
y1
=
read_switches
(
1
);
}
for
(
int
x
=
0
;
x
<
640
;
x
++
){
for
(
int
y
=
0
;
y
<
480
;
y
++
)
{
L1_detT
=
((
y2
-
y3
)
*
(
x
-
x3
))
+
((
x3
-
x2
)
*
(
y
-
y3
))
;
L2_detT
=
((
y3
-
y1
)
*
(
x
-
x3
))
+
((
x1
-
x3
)
*
(
y
-
y3
))
;
detT
=
((
y2
-
y3
)
*
(
x1
-
x3
))
+
((
x3
-
x2
)
*
(
y1
-
y3
))
;
L1_positive
=
((
L1_detT
>=
0
)
==
(
detT
>=
0
))
;
L2_positive
=
((
L2_detT
>=
0
)
==
(
detT
>=
0
))
;
L3_positive
=
(((
L1_detT
+
L2_detT
)
<=
detT
)
==
(
detT
>=
0
))
;
if
(
L1_positive
&&
L2_positive
&&
L3_positive
)
write_pix
(
x
,
y
,
1
);
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment