Skip to content

Commit

Permalink
Update xtask-build-rom & Write a rand-text example
Browse files Browse the repository at this point in the history
  • Loading branch information
zlfn committed Sep 15, 2024
1 parent e80d330 commit ce54e79
Show file tree
Hide file tree
Showing 91 changed files with 10,905 additions and 165 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/target
/out
target/
out/
58 changes: 15 additions & 43 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ resolver = "2"
members = [
"source",
"xtask/*",
"examples/*",
]
exclude = [
"ext/rust-deps"
"ext/rust-deps",
]
6 changes: 6 additions & 0 deletions examples/filltest/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "filltest"
version = "0.1.0"
edition = "2021"


File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions examples/rand-text/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[build]
target = "avr-unknown-gnu-atmega328"
rustflags = ["--emit=llvm-ir"]

# [target.avr-unknown-gnu-atmega328]

[unstable]
build-std = ["core", "alloc"]

[profile.dev]
panic = "abort"

[profile.release]
panic = "abort"
6 changes: 6 additions & 0 deletions examples/rand-text/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "rand-text"
version = "0.1.0"
edition = "2021"


63 changes: 63 additions & 0 deletions examples/rand-text/src/gbdk/gb.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
pub mod gb {
extern "C" {
#[link_name="delay"]
pub fn delay(delay: u16);
#[link_name="waitpad __preserves_regs(b, c, h, l)"]
pub fn waitpad(mask: u8) -> u8;
#[link_name="waitpadup __preserves_regs(a, b, c, d, e, h, l)"]
pub fn waitpadup();
}
}

pub mod drawing {
use core::ffi::c_char;

pub const GRAPHICS_WIDTH: u8 = 160;
pub const GRAPHICS_HEIGHT: u8 = 144;

pub const SOLID: u8 = 0x00;
pub const OR: u8 = 0x01;
pub const XOR: u8 = 0x02;
pub const AND: u8 = 0x03;

pub const WHITE: u8 = 0;
pub const LTGREY: u8 = 1;
pub const DKGREY: u8 = 2;
pub const BLACK: u8 = 3;

pub const M_NOFILL: u8 = 0;
pub const M_FILL: u8 = 1;

pub const SIGNED: u8 = 1;
pub const UNSIGNED: u8 = 0;

extern "C" {
#[link_name="gprint __nonbanked"]
pub fn gprint(str: *const c_char);
//gprintln
//gprintn
//gprintf
#[link_name="plot __sdcccall(0)"]
pub fn plot(x: u8, y: u8, colour: u8, mode: u8);
#[link_name="plot_point __sdcccall(0)"]
pub fn plot_point(x: u8, y:u8);
#[link_name="switch_data __sdcccall(0)"]
pub fn switch_data(x: u8, y: u8, src: *const u8, dst: *const u8);
#[link_name="draw_image"]
pub fn draw_image(data: *const u8);
#[link_name="line __sdcccall(0)"]
pub fn line(x1: u8, y1: u8, x2: u8, y2: u8);
#[link_name="box __sdcccall(0)"]
pub fn r#box(x1: u8, y1: u8, x2: u8, y2: u8, style: u8);
#[link_name="circle __sdcccall(0)"]
pub fn circle(x: u8, y: u8, radius: u8, style: u8);
#[link_name="getpix __sdcccall(0)"]
pub fn getpix(x: u8, y: u8) -> u8;
#[link_name="wrtchr __sdcccall(0)"]
pub fn wrtchr(chr: i8);
#[link_name="gotogxy __sdcccall(0)"]
pub fn gotogxy(x: u8, y: u8);
#[link_name="color __sdcccall(0)"]
pub fn color(forecolor: u8, backcolor: u8, mode: u8);
}
}
2 changes: 2 additions & 0 deletions examples/rand-text/src/gbdk/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod gb;
pub mod rand;
8 changes: 8 additions & 0 deletions examples/rand-text/src/gbdk/rand.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extern "C" {
#[link_name="rand __sdcccall(0)"]
pub fn rand() -> u8;
#[link_name="arand __sdcccall(0)"]
pub fn arand() -> u8;
#[link_name="initarand __sdcccall(0)"]
pub fn initarand(seed: u16);
}
41 changes: 41 additions & 0 deletions examples/rand-text/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#![no_std]
#![no_main]
#![allow(dead_code)]
#![feature(asm_experimental_arch)]

mod gbdk;

use core::ffi::c_char;

use gbdk::{gb::{drawing::{gotogxy, gprint, plot, plot_point, LTGREY, SOLID}, gb::{delay, waitpad, waitpadup}}, rand::{initarand, rand}};

#[no_mangle]
pub extern fn main() {
unsafe {
gprint("Getting seed\0".as_ptr() as *const c_char);
gotogxy(0, 1);
gprint("Push any key (1)\0".as_ptr() as *const c_char);
let a: u8 = waitpad(0xFF);
waitpadup();
let mut seed = a as u16;
gotogxy(0, 2);
gprint("Push any key (2)\0".as_ptr() as *const c_char);
let b: u8 = waitpad(0xFF);
waitpadup();
seed |= (b as u16) << 8;

initarand(seed);

loop {
let r = rand();
gprint([r, 0].as_ptr() as *const c_char);
}
}
}

#[allow(unconditional_recursion)]
#[cfg(not(test))]
#[panic_handler]
fn panic_handler_phony(_info: &core::panic::PanicInfo) -> ! {
loop {}
}
4 changes: 4 additions & 0 deletions ext/include/asm/mos6502/provides.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#define USE_C_MEMCPY 0
#define USE_C_STRCPY 0
#define USE_C_STRCMP 0

18 changes: 18 additions & 0 deletions ext/include/asm/mos6502/stdarg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef ASM_MOS6502_STDARG_INCLUDE
#define ASM_MOS6502_STDARG_INCLUDE

/* sdcc pushes right to left with the real sizes, not cast up
to an int.
so printf(int, char, long)
results in push long, push char, push int
On the 6502 the stack grows down, so the things seem to be in
the correct order.
*/

typedef unsigned char * va_list;
#define va_start(list, last) list = (unsigned char *)&last + sizeof(last)
#define va_arg(list, type) *((type *)((list += sizeof(type)) - sizeof(type)))

#define va_end(list)

#endif
Loading

0 comments on commit ce54e79

Please sign in to comment.