├── .gitignore ├── src ├── main.prg ├── compile.sh └── main.rs ├── screenshot.png ├── Cargo.toml ├── README.md └── Cargo.lock /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | **/*.rs.bk -------------------------------------------------------------------------------- /src/main.prg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xTibor/rs-on-c64/HEAD/src/main.prg -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xTibor/rs-on-c64/HEAD/screenshot.png -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust-on-c64" 3 | version = "0.1.0" 4 | authors = ["Tibor Nagy "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | libc = "0.2.48" 9 | -------------------------------------------------------------------------------- /src/compile.sh: -------------------------------------------------------------------------------- 1 | # This is a mess, needs proper build system. 2 | 3 | rm main.o main.c main.prg 4 | 5 | ~/git/rust-c64/mrustc/bin/mrustc -L /home/tibor/git/rust-c64/mrustc/output/ main.rs 6 | 7 | ~/git/rust-c64/cc65/bin/cl65 main.c -o main.prg && x64 main.prg 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # rs-on-c64 2 | 3 | An experiment of running Rust language code on the Commodore 64 using an alternate unofficial toolchain. There's a demo PRG executable in the src directory. 4 | 5 | This project is not affiliated with or endorsed by the Rust Foundation or the Rust Project. 6 | 7 | ![](screenshot.png) 8 | 9 | **Requires**: 10 | * https://github.com/xTibor/mrustc 11 | * https://github.com/xTibor/cc65 12 | 13 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "libc" 3 | version = "0.2.48" 4 | source = "registry+https://github.com/rust-lang/crates.io-index" 5 | 6 | [[package]] 7 | name = "test-project" 8 | version = "0.1.0" 9 | dependencies = [ 10 | "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", 11 | ] 12 | 13 | [metadata] 14 | "checksum libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)" = "e962c7641008ac010fa60a7dfdc1712449f29c44ef2d4702394aea943ee75047" 15 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | #![feature(lang_items, core_intrinsics)] 2 | #![feature(start)] 3 | #![no_std] 4 | use core::intrinsics; 5 | 6 | extern crate libc; 7 | 8 | #[start] 9 | fn start(_argc: isize, _argv: *const *const u8) -> isize { 10 | unsafe { 11 | let border_color = 0xD020 as *mut u8; 12 | let background_color = 0xD021 as *mut u8; 13 | 14 | let screen_ptr = 0x0400 as *mut u8; 15 | let color_ptr = 0xD800 as *mut u8; 16 | 17 | *border_color = 0x0A; 18 | *background_color = 0x00; 19 | 20 | core::intrinsics::write_bytes(screen_ptr, 0x20, 1000); 21 | 22 | let text = b"hello from rust"; 23 | let mut n = 0; 24 | 25 | loop { 26 | let position = n * 40 + n; 27 | 28 | core::intrinsics::copy(text.as_ptr(), screen_ptr.offset(position), text.len()); 29 | core::intrinsics::write_bytes(color_ptr.offset(position), *border_color, text.len()); 30 | 31 | n = (n + 1) % 25; 32 | 33 | let i = 0; 34 | while i < 63 { 35 | *border_color += 1; 36 | i += 1; 37 | } 38 | } 39 | } 40 | 0 41 | } 42 | 43 | #[lang = "eh_personality"] 44 | #[no_mangle] 45 | pub extern fn rust_eh_personality() { 46 | } 47 | 48 | #[lang = "panic_fmt"] 49 | #[no_mangle] 50 | pub extern fn rust_begin_panic(_msg: core::fmt::Arguments, 51 | _file: &'static str, 52 | _line: u32) -> ! { 53 | unsafe { intrinsics::abort() } 54 | } 55 | --------------------------------------------------------------------------------