From: ljsebald <ljs...@us...> - 2023-12-29 20:32:30
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via 7094ca6e7f15a31e0aefc111ce3c16c8b784bd38 (commit) from e1c2a4a3124fb40019c1dd4857e0f4a5d1641339 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 7094ca6e7f15a31e0aefc111ce3c16c8b784bd38 Author: SiZiOUS <si...@gm...> Date: Fri Dec 29 20:30:25 2023 +0000 Adding examples for `mruby` KallistiOS Port (#436) * `mruby`: Adding dreampresent! Source: https://github.com/yujiyokoo/dreampresent * `dreampresent`: minor changes before committing the sample to KOS * `mrbtris`: initial commit of the sample Source: https://github.com/yujiyokoo/mrbtris-dreamcast * `mruby`: updating readme file * `mruby` examples: small final updates * `dreampresent`: updating headers/license * `mrbtris`: adding license * `dreampresent` - updating all headers * `mruby` examples: final update on license * `mrbtris`: updating README ----------------------------------------------------------------------- Summary of changes: examples/dreamcast/mruby/Makefile | 17 + examples/dreamcast/mruby/dreampresent/.gitignore | 1 + examples/dreamcast/mruby/dreampresent/LICENSE | 22 + examples/dreamcast/mruby/dreampresent/Makefile | 57 ++ examples/dreamcast/mruby/dreampresent/README.md | 39 ++ examples/dreamcast/mruby/dreampresent/dc_kos_rb.rb | 166 +++++ examples/dreamcast/mruby/dreampresent/dckos.c | 349 ++++++++++ examples/dreamcast/mruby/dreampresent/dckos.h | 35 + .../dreamcast/mruby/dreampresent/dreampresent.rb | 40 ++ examples/dreamcast/mruby/dreampresent/main.c | 69 ++ examples/dreamcast/mruby/dreampresent/page_data.rb | 530 ++++++++++++++++ .../dreamcast/mruby/dreampresent/presentation.rb | 68 ++ .../dreampresent/romdisk/DCSerialConnector.png | Bin 0 -> 268873 bytes .../mruby/dreampresent/romdisk/DCToSerial.png | Bin 0 -> 165933 bytes .../mruby/dreampresent/romdisk/bg_dark.png | Bin 0 -> 40364 bytes .../dreampresent/romdisk/content.dreampresent | 404 ++++++++++++ .../mruby/dreampresent/romdisk/dreamcast_photo.png | Bin 0 -> 366961 bytes .../dreampresent/romdisk/emulator_console.png | Bin 0 -> 53811 bytes .../dreampresent/romdisk/mruby_logo_32x35.png | Bin 0 -> 13655 bytes .../dreampresent/romdisk/soldered_connector.png | Bin 0 -> 284943 bytes .../dreampresent/romdisk/swirl_blue_32x28.png | Bin 0 -> 1638 bytes .../mruby/dreampresent/romdisk/yuji_avatar.png | Bin 0 -> 57460 bytes .../dreamcast/mruby/dreampresent/rsrc/mruby.gif | Bin 0 -> 5826 bytes .../dreamcast/mruby/dreampresent/rsrc}/mruby.mr | Bin examples/dreamcast/mruby/dreampresent/start.rb | 36 ++ examples/dreamcast/mruby/mrbtris/.gitignore | 1 + examples/dreamcast/mruby/mrbtris/LICENSE | 22 + examples/dreamcast/mruby/mrbtris/Makefile | 57 ++ examples/dreamcast/mruby/mrbtris/README.md | 33 + examples/dreamcast/mruby/mrbtris/block_shapes.rb | 116 ++++ examples/dreamcast/mruby/mrbtris/dckos.c | 361 +++++++++++ examples/dreamcast/mruby/mrbtris/dckos.h | 35 + examples/dreamcast/mruby/mrbtris/main.c | 68 ++ examples/dreamcast/mruby/mrbtris/mrbtris.rb | 701 +++++++++++++++++++++ .../dreamcast/mruby/mrbtris/romdisk/.keep | 0 examples/dreamcast/mruby/mrbtris/start.rb | 36 ++ 36 files changed, 3263 insertions(+) create mode 100644 examples/dreamcast/mruby/Makefile create mode 100644 examples/dreamcast/mruby/dreampresent/.gitignore create mode 100644 examples/dreamcast/mruby/dreampresent/LICENSE create mode 100644 examples/dreamcast/mruby/dreampresent/Makefile create mode 100644 examples/dreamcast/mruby/dreampresent/README.md create mode 100644 examples/dreamcast/mruby/dreampresent/dc_kos_rb.rb create mode 100644 examples/dreamcast/mruby/dreampresent/dckos.c create mode 100644 examples/dreamcast/mruby/dreampresent/dckos.h create mode 100644 examples/dreamcast/mruby/dreampresent/dreampresent.rb create mode 100644 examples/dreamcast/mruby/dreampresent/main.c create mode 100644 examples/dreamcast/mruby/dreampresent/page_data.rb create mode 100644 examples/dreamcast/mruby/dreampresent/presentation.rb create mode 100644 examples/dreamcast/mruby/dreampresent/romdisk/DCSerialConnector.png create mode 100644 examples/dreamcast/mruby/dreampresent/romdisk/DCToSerial.png create mode 100644 examples/dreamcast/mruby/dreampresent/romdisk/bg_dark.png create mode 100644 examples/dreamcast/mruby/dreampresent/romdisk/content.dreampresent create mode 100644 examples/dreamcast/mruby/dreampresent/romdisk/dreamcast_photo.png create mode 100644 examples/dreamcast/mruby/dreampresent/romdisk/emulator_console.png create mode 100644 examples/dreamcast/mruby/dreampresent/romdisk/mruby_logo_32x35.png create mode 100644 examples/dreamcast/mruby/dreampresent/romdisk/soldered_connector.png create mode 100644 examples/dreamcast/mruby/dreampresent/romdisk/swirl_blue_32x28.png create mode 100644 examples/dreamcast/mruby/dreampresent/romdisk/yuji_avatar.png create mode 100644 examples/dreamcast/mruby/dreampresent/rsrc/mruby.gif copy {utils/makeip/rsrc/iplogos => examples/dreamcast/mruby/dreampresent/rsrc}/mruby.mr (100%) create mode 100644 examples/dreamcast/mruby/dreampresent/start.rb create mode 100644 examples/dreamcast/mruby/mrbtris/.gitignore create mode 100644 examples/dreamcast/mruby/mrbtris/LICENSE create mode 100644 examples/dreamcast/mruby/mrbtris/Makefile create mode 100644 examples/dreamcast/mruby/mrbtris/README.md create mode 100644 examples/dreamcast/mruby/mrbtris/block_shapes.rb create mode 100644 examples/dreamcast/mruby/mrbtris/dckos.c create mode 100644 examples/dreamcast/mruby/mrbtris/dckos.h create mode 100644 examples/dreamcast/mruby/mrbtris/main.c create mode 100644 examples/dreamcast/mruby/mrbtris/mrbtris.rb copy addons/lib/.keepme => examples/dreamcast/mruby/mrbtris/romdisk/.keep (100%) create mode 100644 examples/dreamcast/mruby/mrbtris/start.rb diff --git a/examples/dreamcast/mruby/Makefile b/examples/dreamcast/mruby/Makefile new file mode 100644 index 0000000..3b846bd --- /dev/null +++ b/examples/dreamcast/mruby/Makefile @@ -0,0 +1,17 @@ +# KallistiOS ##version## +# +# examples/dreamcast/mruby/Makefile +# + +all: + $(KOS_MAKE) -C dreampresent + $(KOS_MAKE) -C mrbtris + +clean: + $(KOS_MAKE) -C dreampresent clean + $(KOS_MAKE) -C mrbtris clean + +dist: + $(KOS_MAKE) -C dreampresent dist + $(KOS_MAKE) -C mrbtris dist + diff --git a/examples/dreamcast/mruby/dreampresent/.gitignore b/examples/dreamcast/mruby/dreampresent/.gitignore new file mode 100644 index 0000000..30bea79 --- /dev/null +++ b/examples/dreamcast/mruby/dreampresent/.gitignore @@ -0,0 +1 @@ +dreampresent.c diff --git a/examples/dreamcast/mruby/dreampresent/LICENSE b/examples/dreamcast/mruby/dreampresent/LICENSE new file mode 100644 index 0000000..70b32ce --- /dev/null +++ b/examples/dreamcast/mruby/dreampresent/LICENSE @@ -0,0 +1,22 @@ +MIT License + +Copyright (c) 2019-2024 Yuji Yokoo +Copyright (C) 2020-2024 Mickaël "SiZiOUS" Cardoso + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/examples/dreamcast/mruby/dreampresent/Makefile b/examples/dreamcast/mruby/dreampresent/Makefile new file mode 100644 index 0000000..ef35245 --- /dev/null +++ b/examples/dreamcast/mruby/dreampresent/Makefile @@ -0,0 +1,57 @@ +# Dreampresent +# A simple presentation tool for Sega Dreamcast written in Ruby +# Copyright (C) 2019-2024 Yuji Yokoo +# Copyright (C) 2020-2024 Mickaël "SiZiOUS" Cardoso + +# Project Name +PROJECT = dreampresent + +# Generated Programs +TARGET = $(PROJECT).elf +BINARY = $(PROJECT).bin +BOOTFILE = 1ST_READ.BIN + +# Objects used in this project +# "$(PROJECT).o" is a transpiled C source file generated using MRB_BYTECODE +OBJS = $(PROJECT).o main.o dckos.o romdisk.o + +# Libraries used by the project +LIBS = -lmruby -lm -lpng -lkosutils -lz + +# ROM Disk directory used for resources +KOS_ROMDISK_DIR = romdisk + +# Ruby sources +# The order here is important! +MRB_SOURCES = dc_kos_rb.rb page_data.rb presentation.rb $(PROJECT).rb start.rb + +# mruby script output (transpiled source from MRB_SOURCES) +MRB_BYTECODE = $(PROJECT).c + +# Name of the compiled mruby script +# This should match the definition in "main.c" +MRB_BYTECODE_IREP_NAME = $(PROJECT)_bytecode + +all: rm-elf $(TARGET) + +include $(KOS_BASE)/Makefile.rules + +clean: rm-elf + -rm -f $(OBJS) + +rm-elf: + -rm -f $(TARGET) $(BINARY) $(BOOTFILE) $(MRB_BYTECODE) romdisk.* + +$(TARGET): $(OBJS) + kos-cc -o $(TARGET) $(OBJS) $(LIBS) + +$(MRB_BYTECODE): $(MRB_SOURCES) + mrbc -g -B $(MRB_BYTECODE_IREP_NAME) -o $(MRB_BYTECODE) $(MRB_SOURCES) + +run: $(TARGET) + $(KOS_LOADER) $(TARGET) + +dist: $(TARGET) + -rm -f $(OBJS) romdisk.img + $(KOS_BASE)/utils/elf2bin/elf2bin $(TARGET) $(BINARY) -f + $(KOS_BASE)/utils/scramble/scramble $(BINARY) $(BOOTFILE) diff --git a/examples/dreamcast/mruby/dreampresent/README.md b/examples/dreamcast/mruby/dreampresent/README.md new file mode 100644 index 0000000..b6450c6 --- /dev/null +++ b/examples/dreamcast/mruby/dreampresent/README.md @@ -0,0 +1,39 @@ +# Dreampresent: The Dreamcast Presentation Tool + +This is a presentation tool that runs on **Sega Dreamcast**. It's written in +**Ruby** and uses [mruby](https://mruby.org/). + +This tool was initially developed by [Yuji Yokoo](https://github.com/yujiyokoo) +for the **RubyConf TW 2019** event; then it was later updated for the +**RubyConf AU 2020** event. This project has been refactored by [Mickaël +"SiZiOUS" Cardoso](https://github.com/sizious). + +## Compiling + +To compile this, you need to install the `mruby`, `libpng` and `zlib` KallistiOS +Port, using the `kos-ports` repository. + +## Usage + +You can use `A` or `START` to move forward, and use `B` to go back to the +previous page. + +Hold `A + B + Start` to quit. + +The bottom of the screen shows the page progress and time progress (blue +dreamcast swirl for page, red mruby for time). + +The time is currently hardcoded to `35` minutes. + +If you press `Right` on the D-pad, you move the time forward by 5 minutes, +and back by 5 minutes if you press `Left`. + +## License + +This example is under the MIT License. See `LICENSE` for details. + +## Final note + +The initial source is available [here](https://github.com/yujiyokoo/dreampresent). +This version of the source code is almost the same but adapted to be included as +an example in KallistiOS, with Yuji Yokoo approval, the original author. diff --git a/examples/dreamcast/mruby/dreampresent/dc_kos_rb.rb b/examples/dreamcast/mruby/dreampresent/dc_kos_rb.rb new file mode 100644 index 0000000..5b78045 --- /dev/null +++ b/examples/dreamcast/mruby/dreampresent/dc_kos_rb.rb @@ -0,0 +1,166 @@ +# KallistiOS ##version## +# +# dc_kos_rb.rb - Ruby-level wrapper to KallistiOS +# Copyright (C) 2019-2024 Yuji Yokoo +# Copyright (C) 2020-2024 Mickaël "SiZiOUS" Cardoso +# +# Dreampresent +# A simple presentation tool for Sega Dreamcast written in Ruby +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +module Commands + NEXT_PAGE = 1 + PREVIOUS_PAGE = -1 + QUIT = -2 + FWD = -3 + REW = -4 + SWITCH_VIDEO_MODE = -5 + RESET_TIMER = -6 +end + +# Ruby-level wrapper to DcKos +class DcKosRb + include Commands + + def initialize(dc_kos) + @dc_kos = dc_kos + end + + LINE_HEIGHT = 30 + # this understands '\n' as linebreak + def draw_str(str, x, y, line_height = LINE_HEIGHT, colour, show_bg) + # TODO: let's make a colour lookup class... See LineContent + rgb = + case colour + when 'red' + [255, 0, 0] + when 'magenta' + [255, 0, 255] + when 'ltblue' + [135, 206, 250] + when 'yellow' + [255, 255, 0] + when 'ltgreen' + [144, 238, 144] + when 'cyan' + [0, 255, 255] + else # unknown colours default to white + [255, 255, 255] + end + + bg_on = + if ['true', 'yes'].include? show_bg + 1 + else + 0 + end + + str.split("\n").each_with_index { |line, idx| + @dc_kos.draw_str(line, x, y + (line_height * idx+1), *rgb, bg_on) + } + end + + # this is for 512x512 images + def load_fullscreen_png(filepath) + load_png(filepath, 1, 1, 640, 640) + end + + # This and method_missing are for delegating functions not defined here to @dc_kos + def respond_to?(method) + if method == :respond_to? + true + else + self.respond_to?(method) || @dc_kos.respond_to?(method) + end + end + + # This and respond_to? are for delegating functions not defined here to @dc_kos + def method_missing(method, *args, &block) + if @dc_kos.respond_to?(method) + @dc_kos.send(method, *args, &block) + else + fail NoMethodError, "undefined method '#{method}'" + end + end + + def next_or_back + previous_state = @dc_kos::get_button_state + while true do + button_state = @dc_kos::get_button_state + + # NOTE order is important here. + + return QUIT if quit_combination?(previous_state, button_state) + + return SWITCH_VIDEO_MODE if switch_video_mode_combination?(previous_state, button_state) + + # press STRAT or A to go forward + return NEXT_PAGE if start_or_a_pressed?(previous_state, button_state) + + # press B to go back + return PREVIOUS_PAGE if b_pressed?(previous_state, button_state) + + # left and right on dpad for skipping or rewinding the time indicator + return FWD if right_pressed?(previous_state, button_state) + return REW if left_pressed?(previous_state, button_state) + + previous_state = button_state + end + end + + # NOTE: This requires the source to be 512x512 png! + # x, y are zero-based but note the pvr uses 1-based coordinates (hence the '+ 1') + # NOTE: Before calling this, you need to initialise PVR like: dc_kos.pvr_initialise() + # @dc_kos.show_512x512_png('/rd/dc_controller_orig400x362.png', 0, 0, 640, 480) + def show_512x512_png(path, x, y, w, h) + @dc_kos::load_png(path, x+1, y+1, x+w, y+h) + end + + # press A + B + Start + def quit_combination?(previous, current) + (@dc_kos::btn_a?(current) && @dc_kos::btn_b?(current) && @dc_kos::btn_start?(current)) + end + + def switch_video_mode_combination?(previous, current) + !(@dc_kos::dpad_down?(previous) && @dc_kos::btn_a?(previous)) && + (@dc_kos::dpad_down?(current) && @dc_kos::btn_a?(current)) + end + + def start_or_a_pressed?(previous, current) + (!@dc_kos::btn_start?(previous) && @dc_kos::btn_start?(current)) || + (!@dc_kos::btn_a?(previous) && @dc_kos::btn_a?(current)) + end + + def b_pressed?(previous, current) + !@dc_kos::btn_b?(previous) && @dc_kos::btn_b?(current) + end + + def b_pressed?(previous, current) + !@dc_kos::btn_b?(previous) && @dc_kos::btn_b?(current) + end + + def right_pressed?(previous, current) + !@dc_kos::dpad_right?(previous) && @dc_kos::dpad_right?(current) + end + + def left_pressed?(previous, current) + !@dc_kos::dpad_left?(previous) && @dc_kos::dpad_left?(current) + end +end diff --git a/examples/dreamcast/mruby/dreampresent/dckos.c b/examples/dreamcast/mruby/dreampresent/dckos.c new file mode 100644 index 0000000..e34c1e8 --- /dev/null +++ b/examples/dreamcast/mruby/dreampresent/dckos.c @@ -0,0 +1,349 @@ +/* KallistiOS ##version## + + dckos.c - Exposed functions for mruby: using KOS features (implementation) + Copyright (C) 2019-2024 Yuji Yokoo + Copyright (C) 2020-2024 Mickaël "SiZiOUS" Cardoso + + Dreampresent + A simple presentation tool for Sega Dreamcast written in Ruby + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#include <assert.h> +#include <kos.h> +#include <kos/img.h> +#include <mruby/mruby.h> +#include <mruby/mruby/internal.h> +#include <mruby/mruby/data.h> +#include <mruby/mruby/string.h> +#include <mruby/mruby/error.h> +#include <stdio.h> +#include <inttypes.h> +#include <png/png.h> + +// Convert ARGB1555 to RGB565 - drops the A bit and G is exapanded to 6 bits +#define CONV1555TO565(colour) ( (((colour) & 0x7C00) << 1) | (((colour) & 0x03E0) << 1) | ((colour) & 0x001F) ) + +// CONVERT R, G, B to RGB565 +#define PACK_PIXEL(r, g, b) ( ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3) ) + +int PX_PER_LINE = 640; + +int _is_in_screen(int x, int y) { + return x >= 0 && x < PX_PER_LINE && y >= 0 && y < 480; +} + +// Be careful with this function. It'll attempt to read the entire file. +static mrb_value read_whole_txt_file(mrb_state *mrb, mrb_value self) { + char buffer[2048]; + int length; + file_t f; + mrb_value m_path; + char *path; + + char *result = NULL; + result = mrb_malloc(mrb, sizeof(char)); + *result = '\0'; + + mrb_get_args(mrb, "S", &m_path); + path = mrb_str_to_cstr(mrb, m_path); + f = fs_open(path, O_RDONLY); + + if(f < 0) { + printf("Failed to open %s.\n", path); + return mrb_nil_value(); + } + + while((length = fs_read(f, buffer, 2048))) { + printf("read %i chars into buf.\n", length); + result = mrb_realloc(mrb, result, strlen(result) + length + 1); // 1 for '\0' + strncat(result, buffer, length); + } + + fs_close(f); + mrb_value whole_str_mrb = mrb_str_new_cstr(mrb, result); + mrb_free(mrb, result); + + return whole_str_mrb; +} + +mrb_value get_button_state(mrb_state *mrb, mrb_value self) { + maple_device_t *cont1; + cont_state_t *state; + if((cont1 = maple_enum_type(0, MAPLE_FUNC_CONTROLLER))){ + state = (cont_state_t *)maple_dev_status(cont1); + return mrb_fixnum_value(state->buttons); + } + return mrb_nil_value(); ...<truncated>... hooks/post-receive -- A pseudo Operating System for the Dreamcast. |