Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
fortuna-mines
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
be1g19
fortuna-mines
Commits
14d5848d
Commit
14d5848d
authored
May 7, 2021
by
Bradley Eaton
Browse files
Options
Downloads
Patches
Plain Diff
Now fakes a random seed by writing RNG values to EEPROM
parent
e5e12bf2
No related branches found
No related tags found
No related merge requests found
Pipeline
#7421
passed
May 7, 2021
Stage: build
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
mines.c
+14
-4
14 additions, 4 deletions
mines.c
with
14 additions
and
4 deletions
mines.c
+
14
−
4
View file @
14d5848d
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
#include
"os.h"
#include
"os.h"
#include
"mines.h"
#include
"mines.h"
#include
<stdlib.h>
#include
<stdlib.h>
#include
<avr/eeprom.h>
int
blink
(
int
);
int
blink
(
int
);
...
@@ -21,6 +22,7 @@ int position = 0;
...
@@ -21,6 +22,7 @@ int position = 0;
// Minesweeper stuff
// Minesweeper stuff
volatile
uint16_t
rng_state
=
0
;
volatile
uint16_t
rng_state
=
0
;
static
uint16_t
EEMEM
RNG_STATE
;
volatile
rectangle
selection_position
;
volatile
rectangle
selection_position
;
volatile
uint8_t
position_states
[
BOARD_ITEMS
];
volatile
uint8_t
position_states
[
BOARD_ITEMS
];
volatile
uint8_t
scroll_direction
=
0
;
volatile
uint8_t
scroll_direction
=
0
;
...
@@ -28,6 +30,7 @@ volatile uint8_t game_started = 0;
...
@@ -28,6 +30,7 @@ volatile uint8_t game_started = 0;
volatile
uint8_t
mines_untagged
=
0
;
volatile
uint8_t
mines_untagged
=
0
;
volatile
uint8_t
cells_tagged
=
0
;
volatile
uint8_t
cells_tagged
=
0
;
volatile
uint16_t
cells_discovered
=
0
;
volatile
uint16_t
cells_discovered
=
0
;
volatile
uint16_t
rng_count
=
0
;
//XORSHIFT16
//XORSHIFT16
uint16_t
rng
()
{
uint16_t
rng
()
{
...
@@ -36,6 +39,7 @@ uint16_t rng() {
...
@@ -36,6 +39,7 @@ uint16_t rng() {
x
^=
x
>>
9
;
x
^=
x
>>
9
;
x
^=
x
<<
8
;
x
^=
x
<<
8
;
rng_state
=
x
;
rng_state
=
x
;
//writes to EEPROM in generate mines to decrease wear on EEPROm
return
x
;
return
x
;
}
}
...
@@ -81,6 +85,9 @@ void generate_mines(int pos){
...
@@ -81,6 +85,9 @@ void generate_mines(int pos){
position_states
[
rngValue
-
1
]
=
4
;
position_states
[
rngValue
-
1
]
=
4
;
}
}
//update eeprom RNG
eeprom_update_word
(
&
RNG_STATE
,
rng_state
);
rng_count
++
;
}
}
uint16_t
noOfMines
(){
uint16_t
noOfMines
(){
...
@@ -479,7 +486,11 @@ void main(void) {
...
@@ -479,7 +486,11 @@ void main(void) {
// WDTCSR |= (1<<WDCE) | (1<<WDIE) | (1<<WDP2) | (1<<WDP1);
// WDTCSR |= (1<<WDCE) | (1<<WDIE) | (1<<WDP2) | (1<<WDP1);
//Enable ADC and start conversion
//Enable ADC and start conversion
ADCSRA
|=
(
1
<<
ADEN
)
|
(
1
<<
ADSC
);
// ADCSRA |= (1<<ADEN) | (1<<ADSC);
//random seed inspired from https://www.avrfreaks.net/forum/random-number-generation-0
rng_state
=
eeprom_read_word
(
&
RNG_STATE
);
printGrid
();
printGrid
();
...
@@ -506,7 +517,7 @@ int collect_delta(int state) {
...
@@ -506,7 +517,7 @@ int collect_delta(int state) {
uint16_t
oldPosColour
;
uint16_t
oldPosColour
;
char
output
[
30
];
char
output
[
30
];
sprintf
(
output
,
"stat:%d
\n
pos:%d
\n
rng:%d;%d"
,
position_states
[
position
],
position
,
ADCL
,
ADCH
);
sprintf
(
output
,
"stat:%d
\n
pos:%d
\n
rng:%d;%d"
,
position_states
[
position
],
position
,
rng_state
,
rng_count
);
display_string_xy
(
output
,
0
,
210
);
display_string_xy
(
output
,
0
,
210
);
printCell
(
oldPos
);
printCell
(
oldPos
);
update_selection_position
(
position
,
BLUE
);
update_selection_position
(
position
,
BLUE
);
...
@@ -537,8 +548,7 @@ int check_switches(int state) {
...
@@ -537,8 +548,7 @@ int check_switches(int state) {
if
(
!
game_started
){
if
(
!
game_started
){
//setup seed based on time to press the first button
//setup seed based on time to press the first button
if
(
rng_state
==
0
){
if
(
rng_state
==
0
){
rng_state
=
TCNT1L
;
rng_state
=
0x0bae
;
TCCR1B
&=
~
4
;
}
}
generate_mines
(
position
);
generate_mines
(
position
);
...
...
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