added the f!() macro to the library to make shure that all random text can be written to the progmem to save the important ram

This commit is contained in:
Zenn 2023-08-07 20:40:06 +02:00
parent b00ee76ef1
commit 990ae0c03c
11 changed files with 71 additions and 97 deletions

View file

@ -1,4 +1,5 @@
#![no_std]
#![allow(non_upper_case_globals)]
//Include the Arduboy Library
//Initialize the arduboy object
use arduboy_rust::prelude::*;
@ -8,7 +9,7 @@ pub unsafe extern "C" fn setup() {
// put your setup code here, to run once:
arduboy.begin();
arduboy.clear();
arduboy.print("Holmes is cool!\0");
arduboy.print(f!(b"Holmes is cool!\0"));
arduboy.display();
}
#[no_mangle]

View file

@ -43,7 +43,7 @@ pub unsafe extern "C" fn loop_() {
//Move the cursor to the position 30, 30 of the screen
arduboy.set_cursor(30, 30);
//Printing the yay (important always put the \0 at the end for &str)
arduboy.print("Yay!\0");
arduboy.print(f!(b"Yay!\0"));
}
//Move the cursor back to the top-left of the screen
arduboy.set_cursor(0, 0);

View file

@ -33,9 +33,9 @@ pub unsafe extern "C" fn loop_() {
if attempts == 7 {
//Game Over screen
arduboy.set_cursor(0, 0);
arduboy.print("You lost!\0");
arduboy.print("\n\0");
arduboy.print("Correct Number: \0");
arduboy.print(f!(b"You lost!\0"));
arduboy.print(f!(b"\n\0"));
arduboy.print(f!(b"Correct Number: \0"));
arduboy.print(randomnumber);
if A.just_pressed() {
randomnumber = random_between(1, 101) as i16;
@ -59,30 +59,30 @@ pub unsafe extern "C" fn loop_() {
}
}
arduboy.set_cursor(0, 0);
arduboy.print("Attempt: \0");
arduboy.print(f!(b"Attempt: \0"));
arduboy.print(attempts);
arduboy.print("\n\0");
arduboy.print("Number to guess: \0");
arduboy.print(f!(b"\n\0"));
arduboy.print(f!(b"Number to guess: \0"));
arduboy.print(guessednumber);
arduboy.print("\n\0");
arduboy.print(f!(b"\n\0"));
if attempts == 0 {
arduboy.print("Good luck!\0");
arduboy.print(f!(b"Good luck!\0"));
} else {
arduboy.print(lastguess);
if lastguess > randomnumber {
arduboy.print(" is too high!\0");
arduboy.print(f!(b" is too high!\0"));
}
if lastguess < randomnumber {
arduboy.print(" is too low!\0");
arduboy.print(f!(b" is too low!\0"));
}
}
}
} else {
//Tell the player that they won!
arduboy.set_cursor(0, 0);
arduboy.print("You won!\0");
arduboy.print("\n\0");
arduboy.print("Correct Number: \0");
arduboy.print(f!(b"You won!\0"));
arduboy.print(f!(b"\n\0"));
arduboy.print(f!(b"Correct Number: \0"));
arduboy.print(randomnumber);
if A.just_pressed() {

View file

@ -48,10 +48,10 @@ pub unsafe extern "C" fn loop_() {
arduboy.print(count as u16);
arduboy.set_cursor(0, 30);
arduboy.print("Memory:\0");
arduboy.print(f!(b"Memory:\0"));
arduboy.print(MEM as u16);
arduboy.set_cursor(0, 40);
arduboy.print("eeprom:\0");
arduboy.print(f!(b"eeprom:\0"));
arduboy.print(eeprom.read() as u16);

View file

@ -62,58 +62,6 @@ progmem!(
TONES_REPEAT,
];
);
//#[link_section = ".progmem.data"]
//static player_sprite1: [u8; 34] = [
// 16, 16, 0xfe, 0x01, 0x3d, 0x25, 0x25, 0x3d, 0x01, 0x01, 0xc1, 0x01, 0x3d, 0x25, 0x25, 0x3d,
// 0x01, 0xfe, 0x7f, 0x80, 0x9c, 0xbc, 0xb0, 0xb0, 0xb2, 0xb2, 0xb3, 0xb0, 0xb0, 0xb0, 0xbc, 0x9c,
// 0x80, 0x7f,
//];
// #[link_section = ".progmem.data"]
// static tones: [u16; 43] = [
// NOTE_E4,
// 400,
// NOTE_D4,
// 200,
// NOTE_C4,
// 400,
// NOTE_REST,
// 200,
// NOTE_D4,
// 200,
// NOTE_C4,
// 300,
// NOTE_REST,
// 100,
// NOTE_C4,
// 300,
// NOTE_REST,
// 100,
// NOTE_E4,
// 300,
// NOTE_REST,
// 100,
// NOTE_G4,
// 300,
// NOTE_REST,
// 100,
// NOTE_F4,
// 300,
// NOTE_REST,
// 100,
// NOTE_A4,
// 300,
// NOTE_REST,
// 100,
// NOTE_D5H,
// 200,
// NOTE_REST,
// 200,
// NOTE_D5H,
// 200,
// NOTE_REST,
// 1500,
// TONES_REPEAT,
// ];
// dynamic ram variables
static mut playerx: c_int = 5;

View file

@ -341,7 +341,7 @@ pub unsafe extern "C" fn loop_() {
sound.tone(1000, 0);
arduboy.clear();
arduboy.print("tone(1000)\n\nB: no_tone()\n delay(1000)\n break\0");
arduboy.print(f!(b"tone(1000)\n\nB: no_tone()\n delay(1000)\n break\0"));
while sound.playing() {
move_circle();
if arduboy.pressed(B_BUTTON) {
@ -353,7 +353,7 @@ pub unsafe extern "C" fn loop_() {
sound.tone(500, 4000);
arduboy.clear();
arduboy.print("tone(500, 4000)\n\nB: break\0");
arduboy.print(f!(b"tone(500, 4000)\n\nB: break\0"));
while sound.playing() {
move_circle();
if arduboy.pressed(B_BUTTON) {
@ -364,7 +364,7 @@ pub unsafe extern "C" fn loop_() {
sound.tone2(NOTE_C4, 500, NOTE_C5H, 5000);
arduboy.clear();
arduboy.print("tone(C4,500,C5H,5000)\n\nB: no_tone(), break\0");
arduboy.print(f!(b"tone(C4,500,C5H,5000)\n\nB: no_tone(), break\0"));
while sound.playing() {
move_circle();
if arduboy.pressed(B_BUTTON) {
@ -376,7 +376,7 @@ pub unsafe extern "C" fn loop_() {
sound.tone3(NOTE_C7H, 500, NOTE_REST, 1000, NOTE_C6, 5000);
arduboy.clear();
arduboy.print("tone(C7H,500,\n REST,1000,\n C6,6000)\n\nB: no_tone(), break\0");
arduboy.print(f!(b"tone(C7H,500,\n REST,1000,\n C6,6000)\n\nB: no_tone(), break\0"));
while sound.playing() {
move_circle();
if arduboy.pressed(B_BUTTON) {
@ -388,7 +388,7 @@ pub unsafe extern "C" fn loop_() {
sound.tones(get_tones_addr!(allNotes));
arduboy.clear();
arduboy.print("tones(allNotes)\n\nA: no_tone(), again\nUP: again\nB: break\0");
arduboy.print(f!(b"tones(allNotes)\n\nA: no_tone(), again\nUP: again\nB: break\0"));
while sound.playing() {
move_circle();
if arduboy.pressed(A_BUTTON) {
@ -407,7 +407,7 @@ pub unsafe extern "C" fn loop_() {
new_notes = false;
sound.tones_in_ram(get_tones_addr!(in_ram) as *mut u32);
arduboy.clear();
arduboy.print("tonesInRAM(inRAM)\n\nA: change notes\nB: break\0");
arduboy.print(f!(b"tonesInRAM(inRAM)\n\nA: change notes\nB: break\0"));
while sound.playing() {
move_circle();
if arduboy.pressed(A_BUTTON) {
@ -429,7 +429,7 @@ pub unsafe extern "C" fn loop_() {
sound.tones(get_tones_addr!(sound1));
arduboy.clear();
arduboy.print("volume_mode(IN_TONES)\ntones(sound1)\n\nB: break\0");
arduboy.print(f!(b"volume_mode(IN_TONES)\ntones(sound1)\n\nB: break\0"));
while sound.playing() {
move_circle();
if arduboy.pressed(B) {
@ -441,7 +441,7 @@ pub unsafe extern "C" fn loop_() {
sound.volume_mode(VOLUME_ALWAYS_NORMAL);
sound.tones(get_tones_addr!(sound1));
arduboy.clear();
arduboy.print("volume_mode(NORMAL)\ntones(sound1)\n\nB: no_tone(), break\0");
arduboy.print(f!(b"volume_mode(NORMAL)\ntones(sound1)\n\nB: no_tone(), break\0"));
while sound.playing() {
move_circle();
if arduboy.pressed(B) {
@ -454,7 +454,7 @@ pub unsafe extern "C" fn loop_() {
sound.volume_mode(VOLUME_ALWAYS_HIGH);
sound.tones(get_tones_addr!(sound1));
arduboy.clear();
arduboy.print("volume_mode(HIGH)\ntones(sound1)\n\nB: break\0");
arduboy.print(f!(b"volume_mode(HIGH)\ntones(sound1)\n\nB: break\0"));
while sound.playing() {
move_circle();
if arduboy.pressed(B) {
@ -480,13 +480,13 @@ fn move_circle() {
fn display_audio() {
arduboy.clear();
arduboy.print("Audio enabled: \0");
arduboy.print(f!(b"Audio enabled: \0"));
if arduboy.audio_enabled() {
arduboy.print("YES\0");
arduboy.print(f!(b"YES\0"));
} else {
arduboy.print("NO\0")
arduboy.print(f!(b"NO\0"))
}
arduboy.print("\n\nUP: enable\nDOWN: disable\nB: break\0");
arduboy.print(f!(b"\n\nUP: enable\nDOWN: disable\nB: break\0"));
arduboy.invert(!arduboy.audio_enabled());
}