Skip to content

Commit 013bfd1

Browse files
committed
6章までの成果を反映させた。
1 parent 9683fcb commit 013bfd1

File tree

9 files changed

+33
-87
lines changed

9 files changed

+33
-87
lines changed

Cargo.lock

Lines changed: 0 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,3 @@ lto = true
1717
panic = "abort"
1818
opt-level = 2
1919
lto = true
20-
21-
[dependencies]
22-
rlibc = "1.0.0"
23-
compiler_builtins = { git = "https://github.com/rust-lang-nursery/compiler-builtins" }

Makefile

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,20 @@ default:
1313
mkdir -p $(BUILD_DIR)
1414
make $(BUILD_DIR)/$(BUILD_NAME).mb
1515

16-
$(BUILD_DIR)/$(BUILD_NAME).mb: $(BUILD_DIR)/$(BUILD_NAME).elf Makefile
17-
$(TARGET_ARCH)-objcopy -O binary $(BUILD_DIR)/$(BUILD_NAME).elf $(BUILD_DIR)/$(BUILD_NAME).mb
16+
$(BUILD_DIR)/$(BUILD_NAME).mb: $(BUILD_DIR)/$(BUILD_NAME).elf
17+
$(TARGET_ARCH)-objcopy -O binary $(BUILD_DIR)/$(BUILD_NAME).elf \
18+
$(BUILD_DIR)/$(BUILD_NAME).mb
1819

19-
$(BUILD_DIR)/$(BUILD_NAME).elf: $(BUILD_DIR)/crt.o rom.ld target/$(TARGET_ARCH_RUST)/$(BUILD_MODE)/librust_basemetal_gba.a
20-
$(TARGET_ARCH)-ld --gc-sections -t -T rom.ld -o $(BUILD_DIR)/$(BUILD_NAME).elf $(BUILD_DIR)/crt.o --library-path=target/$(TARGET_ARCH_RUST)/$(BUILD_MODE) -lrust_basemetal_gba -Map $(BUILD_DIR)/$(BUILD_NAME).map
20+
$(BUILD_DIR)/$(BUILD_NAME).elf: $(BUILD_DIR)/crt.o rom.ld \
21+
target/$(TARGET_ARCH_RUST)/$(BUILD_MODE)/librust_basemetal_gba.a
22+
$(TARGET_ARCH)-ld --gc-sections -t -T rom.ld -o $(BUILD_DIR)/$(BUILD_NAME).elf \
23+
$(BUILD_DIR)/crt.o --library-path=target/$(TARGET_ARCH_RUST)/$(BUILD_MODE) \
24+
-lrust_basemetal_gba -Map $(BUILD_DIR)/$(BUILD_NAME).map
2125

22-
target/$(TARGET_ARCH_RUST)/$(BUILD_MODE)/librust_basemetal_gba.a: $(TARGET_ARCH_RUST).json Cargo.toml src/*.rs
23-
RUST_TARGET_PATH=$(PWD) rustup run nightly `which xargo` build -v --target=$(TARGET_ARCH_RUST)
26+
target/$(TARGET_ARCH_RUST)/$(BUILD_MODE)/librust_basemetal_gba.a: \
27+
$(TARGET_ARCH_RUST).json Cargo.toml src/*.rs
28+
RUST_TARGET_PATH=$(PWD) rustup run nightly `which xargo` build -v \
29+
--target=$(TARGET_ARCH_RUST)
2430

2531
$(BUILD_DIR)/crt.o: crt.S
2632
$(TARGET_ARCH)-as crt.S -o $(BUILD_DIR)/crt.o

arm-none-eabi.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"relocation-model": "static",
1010
"archive-format": "gnu",
1111
"target-env": "gnu",
12-
"no-compiler-rt": false,
12+
"no-compiler-rt": true,
1313
"linker-is-gnu": true,
1414
"disable-redzone": true,
1515
"cpu": "arm7tdmi"

crt.S

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,7 @@
11
.text
22

3-
.global _start
3+
.global _start
44
_start:
5-
b entry @ Branch to entry()
5+
b entry @ Branch to entry()
66
loop:
7-
b loop
8-
9-
@ multi-threading is also not supportd
10-
.global __sync_val_compare_and_swap_1
11-
.global __sync_val_compare_and_swap_2
12-
.global __sync_val_compare_and_swap_4
13-
__sync_val_compare_and_swap_1:
14-
__sync_val_compare_and_swap_2:
15-
__sync_val_compare_and_swap_4:
16-
1: b 1b
17-
18-
@ floating point operations are not supported
19-
.global __aeabi_ul2f
20-
.global __aeabi_ul2d
21-
.global __aeabi_fmul
22-
.global __aeabi_fdiv
23-
.global __aeabi_dmul
24-
.global __aeabi_ddiv
25-
__aeabi_ul2f:
26-
__aeabi_ul2d:
27-
__aeabi_fmul:
28-
__aeabi_fdiv:
29-
__aeabi_dmul:
30-
__aeabi_ddiv:
31-
1: b 1b
7+
b loop

src/gba_color.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ pub trait GBAColor {
1010

1111
impl GBAColor for RGB {
1212
fn convert_u16_color(&self) -> u16{
13-
return (((self.b >> 3) as u16) << 10) + (((self.g >> 3) as u16) << 5) + (self.r >> 3) as u16;
13+
return (((self.b & 0x1F) as u16) << 10) +
14+
(((self.g & 0x1F) as u16) << 5) +
15+
(self.r & 0x1F) as u16;
1416
}
1517
}

src/graphics.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ impl Graphics {
3434
pub fn draw_box(&self, x:u16, y:u16, width:u16, height:u16, color:&RGB) {
3535
for offset_y in 0..height {
3636
for offset_x in 0..width {
37-
let valid_x = if x + offset_x > self.screen_x { self.screen_x } else { x + offset_x };
38-
let valid_y = if y + offset_y > self.screen_y { self.screen_y } else { y + offset_y };
39-
self.draw_dot(valid_x, valid_y, color);
37+
if (x + offset_x > self.screen_x) || (y + offset_y > self.screen_y) {
38+
continue;
39+
}
40+
self.draw_dot(x + offset_x, y + offset_y, color);
4041
}
4142
}
4243
}
@@ -46,9 +47,6 @@ impl Graphics {
4647
let mut y: u16 = 0;
4748
let mut f: i32 = 3 - ((r as i32) * 2);
4849

49-
// draw center
50-
self.draw_dot(center_x, center_y, color);
51-
5250
loop {
5351
if x < y {
5452
break;
@@ -72,7 +70,7 @@ impl Graphics {
7270
}
7371
}
7472

75-
pub fn draw_char(&self, ch:char, x:u16, y:u16, color:&RGB) {
73+
pub fn draw_char(&self, ch:char, x:u16, y:u16, color:&RGB) {
7674
let char_data:[u8; 16] = self.font.get_character(ch);
7775
for index in 0..15 {
7876
let byte_data:u8 = char_data[index];

src/lib.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44

55
#![feature(lang_items)]
66
#![no_std]
7-
#![feature(asm)]
8-
#![feature(compiler_builtins_lib)]
9-
10-
extern crate compiler_builtins;
11-
extern crate rlibc;
127

138
mod rgb;
149
mod gba_color;
@@ -51,10 +46,9 @@ fn init_graphic() {
5146
}
5247
}
5348

54-
#[allow(private_no_mangle_fns)]
5549
#[no_mangle]
5650
#[lang = "panic_fmt"]
57-
extern "C" fn panic_fmt() -> ! {
51+
pub extern fn panic_fmt() -> ! {
5852
loop {}
5953
}
6054

src/rgb.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,35 @@ impl RGBDef for RGB {
3333
}
3434

3535
fn light_red() -> RGB {
36-
return RGB { r: 0xff, g: 0x00, b: 0x00,};
36+
return RGB { r: 0xFF, g: 0x00, b: 0x00,};
3737
}
3838

3939
fn light_green() -> RGB {
40-
return RGB { r: 0x00, g: 0xff, b: 0x00,};
40+
return RGB { r: 0x00, g: 0xFF, b: 0x00,};
4141
}
4242

4343
fn light_yellow() -> RGB {
44-
return RGB { r: 0xff, g: 0xff, b: 0x00,};
44+
return RGB { r: 0xFF, g: 0xFF, b: 0x00,};
4545
}
4646

4747
fn light_blue() -> RGB {
48-
return RGB { r: 0x00, g: 0x00, b: 0xff,};
48+
return RGB { r: 0x00, g: 0x00, b: 0xFF,};
4949
}
5050

5151
fn light_purple() -> RGB {
52-
return RGB { r: 0xff, g: 0x00, b: 0xff,};
52+
return RGB { r: 0xFF, g: 0x00, b: 0xFF,};
5353
}
5454

5555
fn light_pale_blue() -> RGB {
56-
return RGB { r: 0x00, g: 0xff, b: 0xff,};
56+
return RGB { r: 0x00, g: 0xFF, b: 0xFF,};
5757
}
5858

5959
fn white() -> RGB {
60-
return RGB { r: 0xff, g: 0xff, b: 0xff,};
60+
return RGB { r: 0xFF, g: 0xFF, b: 0xFF,};
6161
}
6262

6363
fn light_gray() -> RGB {
64-
return RGB { r: 0xc6, g: 0xc6, b: 0xc6,};
64+
return RGB { r: 0xC6, g: 0xC6, b: 0xC6,};
6565
}
6666

6767
fn dark_red() -> RGB {

0 commit comments

Comments
 (0)