├── examples ├── wswan │ ├── pong │ │ ├── res │ │ │ ├── palette.bin │ │ │ ├── game_bg.png │ │ │ └── game_tiles.png │ │ └── Makefile │ ├── simple_image │ │ ├── res │ │ │ ├── image.pal.bin │ │ │ ├── image.png │ │ │ └── logo.png │ │ ├── README.md │ │ ├── Makefile │ │ └── src │ │ │ └── main.c │ └── template │ │ ├── src │ │ └── template.c │ │ └── Makefile └── wwitch │ └── template │ ├── src │ └── template.c │ └── Makefile ├── libc ├── README.md ├── src │ ├── errno │ │ └── _errno.c │ ├── ctype │ │ ├── iscntrl.c │ │ ├── isalnum.c │ │ ├── isgraph.c │ │ ├── ispunct.c │ │ ├── isspace.c │ │ ├── isdigit.c │ │ ├── isblank.c │ │ ├── tolower.c │ │ ├── toupper.c │ │ ├── islower.c │ │ ├── isupper.c │ │ ├── isxdigit.c │ │ ├── isprint.c │ │ └── isalpha.c │ ├── stdlib │ │ ├── abs.c │ │ ├── labs.c │ │ ├── llabs.c │ │ ├── div.c │ │ ├── ldiv.c │ │ ├── lldiv.c │ │ └── rand.c │ └── string │ │ ├── strlen.c │ │ ├── strcpy.c │ │ ├── strchr.c │ │ ├── strcat.c │ │ ├── strcmp.c │ │ ├── strncmp.c │ │ ├── strrchr.c │ │ ├── strncpy.c │ │ ├── strncat.c │ │ ├── strcspn.c │ │ ├── strpbrk.c │ │ ├── _fmemset.c │ │ ├── strspn.c │ │ ├── _nmemset.c │ │ ├── _nmemchr.c │ │ ├── strstr.c │ │ ├── _nmemcpy.c │ │ ├── _fmemchr.c │ │ ├── _fmemcpy.c │ │ ├── _nmemset_i8086.S │ │ ├── _nmemcmp.c │ │ ├── _nmemcpy_i8086.S │ │ ├── _fmemcmp.c │ │ ├── _nmemmove.c │ │ ├── _fmemmove.c │ │ ├── _fmemset_i8086.S │ │ ├── _fmemcpy_i8086.S │ │ └── _nmemmove_i8086.S ├── include │ ├── errno.h │ ├── assert.h │ ├── ctype.h │ ├── stdlib.h │ └── string.h └── Makefile ├── support ├── wswan.mk ├── wwitch.mk ├── src │ ├── wonderful-wwitch.h │ ├── wonderful-wswan.h │ ├── wonderful-asm-wswan.h │ ├── wonderful-asm-wwitch.h │ ├── crt0.S │ ├── crt0_ww.S │ └── wonderful-asm-common.h ├── wonderful-i8086.mk ├── wfcommon.py ├── wwitch.ld ├── wswan.ld.template ├── Makefile └── bin2c.py ├── toolchain ├── defs.sh ├── defs-cross-win64.sh ├── README.md └── fetch.sh ├── liblzsa ├── include │ └── lzsa.h ├── Makefile └── README.md ├── docs └── COPYING.ZLIB ├── libww ├── include │ ├── sys │ │ ├── fcntl.h │ │ ├── bank.h │ │ ├── types.h │ │ ├── bios.h │ │ ├── libwwc.h │ │ ├── key.h │ │ ├── sound.h │ │ ├── system.h │ │ └── timer.h │ └── stdio.h ├── src │ ├── wwc_get_hardarch.S │ ├── wwc_set_color_mode.S │ ├── wwc_palette_get_color.S │ ├── wwc_palette_set_color.S │ ├── wwc_clear_font.S │ └── wwc_font_set_colordata.S └── Makefile ├── libws ├── src │ ├── util │ │ ├── inportw.S │ │ ├── outportb.S │ │ ├── outportw.S │ │ ├── inportb.S │ │ └── busywait.S │ ├── eeprom │ │ ├── ieep_read_owner_name.c │ │ ├── eeprom_handle_internal.c │ │ ├── eeprom_read_byte.S │ │ ├── eeprom_write_lock.S │ │ ├── eeprom_write_unlock.S │ │ ├── eeprom_erase_word.S │ │ ├── eeprom_read_word.S │ │ ├── eeprom_write_word.S │ │ ├── eeprom_read_data.c │ │ ├── ieep_name_color_to_rgb.c │ │ ├── ieep_read_owner_name_ascii.c │ │ └── eeprom_utils.S │ ├── system │ │ ├── hwint_enable.c │ │ ├── hwint_disable.c │ │ ├── mode_set.c │ │ ├── cpuint_set_handler.c │ │ ├── hwint_set_handler.c │ │ ├── hwint_default_handler1.S │ │ ├── hwint_default_handler4.S │ │ ├── hwint_default_handler6.S │ │ ├── hwint_default_handler5.S │ │ ├── hwint_default_handler7.S │ │ ├── hwint_default_handler0.S │ │ └── hwint_default_handler3.S │ ├── serial │ │ ├── serial_putc.c │ │ ├── serial_getc.c │ │ └── serial_getc_nonblock.c │ ├── display │ │ ├── display_set_shade_lut.S │ │ ├── screen_fill.c │ │ └── screen_put_map.c │ ├── dma │ │ ├── dma_copy_words_linear.c │ │ └── dma_opt_copy_words.c │ ├── rtc │ │ ├── rtc_low_write_byte.S │ │ ├── rtc_low_write_ctrl.S │ │ ├── rtc_low_read_byte.S │ │ └── rtc_utils.S │ ├── cartridge │ │ └── cart_gpo.c │ └── keypad │ │ └── keypad_scan.S ├── include │ ├── ws.h │ └── ws │ │ ├── util.h │ │ ├── keypad.h │ │ ├── serial.h │ │ ├── rtc.h │ │ └── dma.h └── Makefile └── README.md /examples/wswan/pong/res/palette.bin: -------------------------------------------------------------------------------- 1 | u -------------------------------------------------------------------------------- /examples/wswan/simple_image/res/image.pal.bin: -------------------------------------------------------------------------------- 1 | u -------------------------------------------------------------------------------- /examples/wswan/template/src/template.c: -------------------------------------------------------------------------------- 1 | void main() { 2 | while(1); 3 | } 4 | -------------------------------------------------------------------------------- /examples/wswan/pong/res/game_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WonderfulToolchain/wonderful-i8086/HEAD/examples/wswan/pong/res/game_bg.png -------------------------------------------------------------------------------- /examples/wswan/pong/res/game_tiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WonderfulToolchain/wonderful-i8086/HEAD/examples/wswan/pong/res/game_tiles.png -------------------------------------------------------------------------------- /libc/README.md: -------------------------------------------------------------------------------- 1 | # wonderful-i8086 libc 2 | 3 | Based in part on the following projects: 4 | 5 | * [PDCLib](https://github.com/DevSolar/pdclib) 6 | -------------------------------------------------------------------------------- /support/wswan.mk: -------------------------------------------------------------------------------- 1 | WONDERFUL_TARGET := wswan 2 | 3 | include $(WONDERFUL_TOOLCHAIN)/i8086/wonderful-i8086.mk 4 | 5 | CFLAGS += -mcmodel=medium 6 | -------------------------------------------------------------------------------- /examples/wswan/simple_image/res/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WonderfulToolchain/wonderful-i8086/HEAD/examples/wswan/simple_image/res/image.png -------------------------------------------------------------------------------- /examples/wswan/simple_image/res/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WonderfulToolchain/wonderful-i8086/HEAD/examples/wswan/simple_image/res/logo.png -------------------------------------------------------------------------------- /toolchain/defs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | PREFIX=$WONDERFUL_TOOLCHAIN/i8086 4 | GMP_VERSION=6.1.2 5 | ISL_VERSION=0.16.1 6 | MPC_VERSION=1.0.3 7 | MPFR_VERSION=3.1.5 8 | -------------------------------------------------------------------------------- /examples/wswan/simple_image/README.md: -------------------------------------------------------------------------------- 1 | # simple_image 2 | 3 | * `res/image.png`: ["Girl with Cat" by Bogdan Gerasymenko, CC0](https://openclipart.org/detail/250142/girl-with-cat) 4 | -------------------------------------------------------------------------------- /toolchain/defs-cross-win64.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CROSS_HOST=x86_64-w64-mingw32 4 | CROSS_CC="$CROSS_HOST"-gcc 5 | CROSS_CXX="$CROSS_HOST"-g++ 6 | HOST_EXECUTABLE_SUFFIX=.exe 7 | -------------------------------------------------------------------------------- /liblzsa/include/lzsa.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | uint16_t lzsa1_decompress(void __far* dest, const void __far* src); 5 | uint16_t lzsa2_decompress(void __far* dest, const void __far* src); 6 | -------------------------------------------------------------------------------- /examples/wwitch/template/src/template.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main(int argc, char** argv) { 4 | text_screen_init(); 5 | text_put_string((LCD_CHAR_WIDTH - 13) / 2, LCD_CHAR_HEIGHT / 2, "Hello, World!"); 6 | while (key_wait() != KEY_START); 7 | } 8 | -------------------------------------------------------------------------------- /toolchain/README.md: -------------------------------------------------------------------------------- 1 | # wonderful-i8086 toolchain buildscripts 2 | 3 | $ ./fetch.sh 4 | $ ./build.sh all 5 | 6 | ## Detailed information 7 | 8 | * `fetch.sh` fetches and updates Git repositories, as well as archives of other libraries and software used in the toolchain. 9 | * `build.sh` rebuilds the specified components. `all` rebuilds all components, but they can also be specified individually. 10 | -------------------------------------------------------------------------------- /libc/src/errno/_errno.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | int _errno = 0; 13 | -------------------------------------------------------------------------------- /libc/src/ctype/iscntrl.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "ctype.h" 14 | 15 | int iscntrl(int c) { 16 | return c < 32; 17 | } -------------------------------------------------------------------------------- /libc/src/stdlib/abs.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "stdlib.h" 14 | 15 | int abs(int j) { 16 | return (j >= 0) ? j : -j; 17 | } 18 | -------------------------------------------------------------------------------- /libc/src/ctype/isalnum.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "ctype.h" 14 | 15 | int isalnum(int c) { 16 | return isalpha(c) || isdigit(c); 17 | } -------------------------------------------------------------------------------- /libc/src/ctype/isgraph.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "ctype.h" 14 | 15 | int isgraph(int c) { 16 | return isprint(c) && (c != ' '); 17 | } -------------------------------------------------------------------------------- /libc/src/stdlib/labs.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "stdlib.h" 14 | 15 | long int labs(long int j) { 16 | return (j >= 0) ? j : -j; 17 | } 18 | -------------------------------------------------------------------------------- /libc/src/ctype/ispunct.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "ctype.h" 14 | 15 | int ispunct(int c) { 16 | return isprint(c) && !isspace(c) && !isalnum(c); 17 | } -------------------------------------------------------------------------------- /libc/src/stdlib/llabs.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "stdlib.h" 14 | 15 | long long int llabs(long long int j) { 16 | return (j >= 0) ? j : -j; 17 | } 18 | -------------------------------------------------------------------------------- /libc/include/errno.h: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #pragma once 13 | #include 14 | 15 | extern int _errno; 16 | #define errno (_errno) 17 | 18 | #define ERANGE -1 19 | #define EDOM -2 20 | #define EILSEQ -3 -------------------------------------------------------------------------------- /libc/src/string/strlen.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "string.h" 14 | 15 | size_t strlen(const char __far* s) { 16 | size_t l = 0; 17 | 18 | while (s[l]) l++; 19 | 20 | return l; 21 | } 22 | -------------------------------------------------------------------------------- /libc/src/ctype/isspace.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "ctype.h" 14 | 15 | int isspace(int c) { 16 | return (c == ' ') || (c == '\f') || (c == '\n') || (c == '\r') || (c == '\t') || (c == '\v'); 17 | } -------------------------------------------------------------------------------- /libc/src/stdlib/div.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "stdlib.h" 14 | 15 | div_t div(int numer, int denom) { 16 | div_t result; 17 | result.quot = numer / denom; 18 | result.rem = numer % denom; 19 | return result; 20 | } 21 | -------------------------------------------------------------------------------- /libc/src/string/strcpy.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "string.h" 14 | 15 | char __far* strcpy(char __far* s1, const char __far* s2) { 16 | char __far* st = s1; 17 | 18 | while (*(s1++) = *(s2++)); 19 | return st; 20 | } 21 | -------------------------------------------------------------------------------- /support/wwitch.mk: -------------------------------------------------------------------------------- 1 | WONDERFUL_TARGET := wwitch 2 | 3 | include $(WONDERFUL_TOOLCHAIN)/i8086/wonderful-i8086.mk 4 | 5 | WF_LDSCRIPT := $(WONDERFUL_TOOLCHAIN)/i8086/wwitch/lib/wwitch.ld 6 | 7 | WF_CRT0_ASC1 := $(WONDERFUL_TOOLCHAIN)/i8086/wwitch/lib/crt0_asc1.o 8 | WF_CRT0_ASC2 := $(WONDERFUL_TOOLCHAIN)/i8086/wwitch/lib/crt0_asc2.o 9 | WF_CRT0_JPN1 := $(WONDERFUL_TOOLCHAIN)/i8086/wwitch/lib/crt0_jpn1.o 10 | WF_CRT0_JPN2 := $(WONDERFUL_TOOLCHAIN)/i8086/wwitch/lib/crt0_jpn2.o 11 | 12 | CFLAGS += -mcmodel=small -mno-callee-assume-ss-data-segment 13 | 14 | # Allow outputting Shift-JIS string literals. 15 | CFLAGS += -fexec-charset=shift-jis 16 | -------------------------------------------------------------------------------- /libc/src/stdlib/ldiv.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "stdlib.h" 14 | 15 | ldiv_t ldiv(long int numer, long int denom) { 16 | ldiv_t result; 17 | result.quot = numer / denom; 18 | result.rem = numer % denom; 19 | return result; 20 | } 21 | -------------------------------------------------------------------------------- /libc/src/stdlib/lldiv.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "stdlib.h" 14 | 15 | lldiv_t lldiv(long long int numer, long long int denom) { 16 | lldiv_t result; 17 | result.quot = numer / denom; 18 | result.rem = numer % denom; 19 | return result; 20 | } 21 | -------------------------------------------------------------------------------- /libc/include/assert.h: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #pragma once 13 | 14 | // TODO: Actually implement assert(). 15 | 16 | #undef assert 17 | #define assert(ignore) ((void)0) 18 | 19 | #if defined(__USE_ISOC11) 20 | # undef static_assert 21 | # define static_assert _Static_assert 22 | #endif -------------------------------------------------------------------------------- /libc/src/ctype/isdigit.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "ctype.h" 14 | 15 | int isdigit(int c) { 16 | #if defined(LIBC_LOCALE_ASCII) || defined(LIBC_LOCALE_SJIS) 17 | return (c >= '0') && (c <= '9'); 18 | #else 19 | # error Please define LIBC_LOCALE! 20 | #endif 21 | } -------------------------------------------------------------------------------- /libc/src/string/strchr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "string.h" 14 | 15 | char __far* strchr(const char __far* s, int c) { 16 | do { 17 | if (*s == (char) c) { 18 | return (char __far*) s; 19 | } 20 | } while (*(s++)); 21 | 22 | return NULL; 23 | } 24 | -------------------------------------------------------------------------------- /libc/src/ctype/isblank.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "ctype.h" 14 | 15 | int isblank(int c) { 16 | #if defined(LIBC_LOCALE_ASCII) || defined(LIBC_LOCALE_SJIS) 17 | return (c == ' ') || (c == '\t'); 18 | #else 19 | # error Please define LIBC_LOCALE! 20 | #endif 21 | } -------------------------------------------------------------------------------- /libc/src/string/strcat.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "string.h" 14 | 15 | char __far* strcat(char __far* s1, const char __far* s2) { 16 | char __far* sp = s1; 17 | 18 | if (*sp) while (*(++sp)); 19 | while (*(s1++) = *(s2++)); 20 | 21 | return sp; 22 | } 23 | -------------------------------------------------------------------------------- /libc/src/string/strcmp.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "string.h" 14 | 15 | int strcmp(const char __far* s1, const char __far* s2) { 16 | while ((*s1) && (*s1 == *s2)) { 17 | s1++; 18 | s2++; 19 | } 20 | return ((unsigned char) (*s1)) - ((unsigned char) (*s2)); 21 | } 22 | -------------------------------------------------------------------------------- /libc/src/ctype/tolower.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "ctype.h" 14 | 15 | int tolower(int c) { 16 | #if defined(LIBC_LOCALE_ASCII) || defined(LIBC_LOCALE_SJIS) 17 | return ((c >= 'A') && (c <= 'Z')) ? (c | 0x20) : c; 18 | #else 19 | # error Please define LIBC_LOCALE! 20 | #endif 21 | } -------------------------------------------------------------------------------- /libc/src/ctype/toupper.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "ctype.h" 14 | 15 | int toupper(int c) { 16 | #if defined(LIBC_LOCALE_ASCII) || defined(LIBC_LOCALE_SJIS) 17 | return ((c >= 'a') && (c <= 'z')) ? (c & (~0x20)) : c; 18 | #else 19 | # error Please define LIBC_LOCALE! 20 | #endif 21 | } -------------------------------------------------------------------------------- /libc/src/stdlib/rand.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include 14 | #include "stdlib.h" 15 | 16 | uint16_t _rand_seed = 1; 17 | 18 | int rand(void) { 19 | _rand_seed = (_rand_seed * 25173) + 13849; 20 | return _rand_seed & 0x7FFF; 21 | } 22 | 23 | void srand(unsigned int seed) { 24 | _rand_seed = seed; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /libc/src/string/strncmp.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "string.h" 14 | 15 | int strncmp(const char __far* s1, const char __far* s2, size_t n) { 16 | while (n && (*s1) && (*s1 == *s2)) { 17 | s1++; 18 | s2++; 19 | n--; 20 | } 21 | return (n == 0) ? 0 : (((unsigned char) (*s1)) - ((unsigned char) (*s2))); 22 | } 23 | -------------------------------------------------------------------------------- /libc/src/string/strrchr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "string.h" 14 | 15 | char __far* strrchr(const char __far* s, int c) { 16 | size_t i = 0; 17 | while (s[i++]); 18 | 19 | do { 20 | if (s[--i] == (char)c) { 21 | return &((char __far*) s)[i]; 22 | } 23 | } while (i > 0); 24 | 25 | return NULL; 26 | } 27 | -------------------------------------------------------------------------------- /libc/src/ctype/islower.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "ctype.h" 14 | 15 | int islower(int c) { 16 | #if defined(LIBC_LOCALE_ASCII) 17 | return (c >= 'a') && (c <= 'z'); 18 | #elif defined(LIBC_LOCALE_SJIS) 19 | // TODO 20 | return (c >= 'a') && (c <= 'z'); 21 | #else 22 | # error Please define LIBC_LOCALE! 23 | #endif 24 | } -------------------------------------------------------------------------------- /libc/src/ctype/isupper.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "ctype.h" 14 | 15 | int isupper(int c) { 16 | #if defined(LIBC_LOCALE_ASCII) 17 | return (c >= 'A') && (c <= 'Z'); 18 | #elif defined(LIBC_LOCALE_SJIS) 19 | // TODO 20 | return (c >= 'A') && (c <= 'Z'); 21 | #else 22 | # error Please define LIBC_LOCALE! 23 | #endif 24 | } -------------------------------------------------------------------------------- /libc/src/ctype/isxdigit.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "ctype.h" 14 | 15 | int isxdigit(int c) { 16 | #if defined(LIBC_LOCALE_ASCII) || defined(LIBC_LOCALE_SJIS) 17 | return ((c >= '0') && (c <= '9')) || ((c >= 'a') && (c <= 'f')) || ((c >= 'A') && (c <= 'F')); 18 | #else 19 | # error Please define LIBC_LOCALE! 20 | #endif 21 | } -------------------------------------------------------------------------------- /libc/src/string/strncpy.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "string.h" 14 | 15 | char __far* strncpy(char __far* s1, const char __far* s2, size_t n) { 16 | char __far* st = s1; 17 | 18 | while (n && (*(s1++) = *(s2++))) { 19 | n--; 20 | } 21 | 22 | while ((n--) > 1) { 23 | *(s1++) = '\0'; 24 | } 25 | 26 | return st; 27 | } 28 | -------------------------------------------------------------------------------- /libc/src/ctype/isprint.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "ctype.h" 14 | 15 | int isprint(int c) { 16 | #if defined(LIBC_LOCALE_ASCII) 17 | return ((c >= 32) && (c <= 127)); 18 | #elif defined(LIBC_LOCALE_SJIS) 19 | return ((c >= 32) && (c <= 127)) || ((c >= 0xA1) && (c <= 0xDF)); 20 | #else 21 | # error Please define LIBC_LOCALE! 22 | #endif 23 | } -------------------------------------------------------------------------------- /libc/src/string/strncat.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "string.h" 14 | 15 | char __far* strncat(char __far* s1, const char __far* s2, size_t n) { 16 | char __far* sp = s1; 17 | 18 | if (*sp) while (*(++sp)); 19 | while (n && (*(s1++) = *(s2++))) { 20 | n--; 21 | } 22 | if (n == 0) { 23 | *s1 = '\0'; 24 | } 25 | 26 | return sp; 27 | } 28 | -------------------------------------------------------------------------------- /libc/src/string/strcspn.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "string.h" 14 | 15 | size_t strcspn(const char __far* s1, const char __far* s2) { 16 | size_t len = 0; 17 | const char __far* p; 18 | 19 | while (s1[len]) { 20 | p = s2; 21 | while (*p) { 22 | if (s1[len] == *(p++)) { 23 | return len; 24 | } 25 | } 26 | len++; 27 | } 28 | 29 | return len; 30 | } 31 | -------------------------------------------------------------------------------- /libc/src/string/strpbrk.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "string.h" 14 | 15 | char __far* strpbrk(const char __far* s1, const char __far* s2) { 16 | const char __far* p1 = s1; 17 | const char __far* p2; 18 | 19 | while (*p1) { 20 | p2 = s2; 21 | while (*p2) { 22 | if (*p1 == *(p2++)) { 23 | return (char __far*) p1; 24 | } 25 | } 26 | p1++; 27 | } 28 | 29 | return NULL; 30 | } 31 | -------------------------------------------------------------------------------- /libc/include/ctype.h: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #pragma once 13 | #include 14 | 15 | int isalnum(int c); 16 | int isalpha(int c); 17 | int isblank(int c); 18 | int iscntrl(int c); 19 | int isdigit(int c); 20 | int isgraph(int c); 21 | int islower(int c); 22 | int isprint(int c); 23 | int ispunct(int c); 24 | int isspace(int c); 25 | int isupper(int c); 26 | int isxdigit(int c); 27 | int tolower(int c); 28 | int toupper(int c); -------------------------------------------------------------------------------- /libc/src/ctype/isalpha.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "ctype.h" 14 | 15 | int isalpha(int c) { 16 | #if defined(LIBC_LOCALE_SJIS) 17 | return ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) || ((c >= 0xA6) && (c <= 0xDF)); 18 | #elif defined(LIBC_LOCALE_ASCII) 19 | return ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')); 20 | #else 21 | # error Please define LIBC_LOCALE! 22 | #endif 23 | } -------------------------------------------------------------------------------- /libc/src/string/_fmemset.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | 14 | #if 0 15 | 16 | void __far* _fmemset(void __far* s, int c, size_t n) { 17 | unsigned char __far* p = (unsigned char __far*) s; 18 | while (n--) { 19 | *(p++) = (unsigned char) c; 20 | } 21 | return s; 22 | } 23 | 24 | #ifdef __IA16_CMODEL_IS_FAR_DATA 25 | __attribute__ ((alias ("_fmemset"))) 26 | void* memset(void* s, int c, size_t n); 27 | #endif 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /libc/src/string/strspn.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "string.h" 14 | 15 | size_t strspn(const char __far* s1, const char __far* s2) { 16 | size_t len = 0; 17 | const char __far* p; 18 | 19 | while (s1[len]) { 20 | p = s2; 21 | while (*p) { 22 | if (s1[len] == *p) { 23 | break; 24 | } 25 | p++; 26 | } 27 | if (!(*p)) { 28 | return len; 29 | } 30 | len++; 31 | } 32 | 33 | return len; 34 | } 35 | -------------------------------------------------------------------------------- /libc/src/string/_nmemset.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "string.h" 14 | 15 | #if 0 16 | 17 | void* _nmemset(void* s, int c, size_t n) { 18 | unsigned char* p = (unsigned char*) s; 19 | while (n--) { 20 | *(p++) = (unsigned char) c; 21 | } 22 | return s; 23 | } 24 | 25 | #ifndef __IA16_CMODEL_IS_FAR_DATA 26 | __attribute__ ((alias ("_nmemset"))) 27 | void* memset(void* s, int c, size_t n); 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /libc/src/string/_nmemchr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | 14 | void* _nmemchr(const void* s, int c, size_t n) { 15 | unsigned char* p = (unsigned char*) s; 16 | while (n--) { 17 | if ( *p == (unsigned char) c) { 18 | return (void*) p; 19 | } 20 | 21 | p++; 22 | } 23 | return NULL; 24 | } 25 | 26 | #ifndef __IA16_CMODEL_IS_FAR_DATA 27 | __attribute__ ((alias ("_nmemchr"))) 28 | void* memchr(const void* s, int c, size_t n); 29 | #endif 30 | -------------------------------------------------------------------------------- /libc/src/string/strstr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | #include "string.h" 14 | 15 | char __far* strstr(const char __far* s1, const char __far* s2) { 16 | const char __far* p1 = s1; 17 | const char __far* p2; 18 | 19 | while (*s1) { 20 | p2 = s2; 21 | while (*p2 && (*p1 == *p2)) { 22 | p1++; 23 | p2++; 24 | } 25 | if (!(*p2)) { 26 | return (char __far*) s1; 27 | } 28 | s1++; 29 | p1 = s1; 30 | } 31 | 32 | return NULL; 33 | } 34 | -------------------------------------------------------------------------------- /libc/src/string/_nmemcpy.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | 14 | #if 0 15 | 16 | void* _nmemcpy(void* restrict s1, const void* restrict s2, size_t n) { 17 | char* dest = (char*) s1; 18 | const char* src = (const char*) s2; 19 | 20 | while (n--) { 21 | *dest++ = *src++; 22 | } 23 | 24 | return s1; 25 | } 26 | 27 | #ifndef __IA16_CMODEL_IS_FAR_DATA 28 | __attribute__ ((alias ("_nmemcpy"))) 29 | void* memcpy(void* s1, const void* s2, size_t n); 30 | #endif 31 | 32 | #endif -------------------------------------------------------------------------------- /libc/src/string/_fmemchr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | 14 | void __far* _fmemchr(const void __far* s, int c, size_t n) { 15 | unsigned char __far* p = (unsigned char __far*) s; 16 | while (n--) { 17 | if ( *p == (unsigned char) c) { 18 | return (void __far*) p; 19 | } 20 | 21 | p++; 22 | } 23 | return NULL; 24 | } 25 | 26 | #ifdef __IA16_CMODEL_IS_FAR_DATA 27 | __attribute__ ((alias ("_fmemchr"))) 28 | void* memchr(const void* s, int c, size_t n); 29 | #endif 30 | -------------------------------------------------------------------------------- /docs/COPYING.ZLIB: -------------------------------------------------------------------------------- 1 | This software is provided 'as-is', without any express or implied 2 | warranty. In no event will the authors be held liable for any damages 3 | arising from the use of this software. 4 | 5 | Permission is granted to anyone to use this software for any purpose, 6 | including commercial applications, and to alter it and redistribute it 7 | freely, subject to the following restrictions: 8 | 9 | 1. The origin of this software must not be misrepresented; you must not 10 | claim that you wrote the original software. If you use this software 11 | in a product, an acknowledgment in the product documentation would be 12 | appreciated but is not required. 13 | 2. Altered source versions must be plainly marked as such, and must not be 14 | misrepresented as being the original software. 15 | 3. This notice may not be removed or altered from any source distribution. 16 | -------------------------------------------------------------------------------- /libc/src/string/_fmemcpy.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | 14 | #if 0 15 | 16 | void __far* _fmemcpy(void __far* restrict s1, const void __far* restrict s2, size_t n) { 17 | char __far* dest = (char __far*) s1; 18 | const char __far* src = (const char __far*) s2; 19 | 20 | while (n--) { 21 | *dest++ = *src++; 22 | } 23 | 24 | return s1; 25 | } 26 | 27 | #ifdef __IA16_CMODEL_IS_FAR_DATA 28 | __attribute__ ((alias ("_fmemcpy"))) 29 | void* memcpy(void* s1, const void* s2, size_t n); 30 | #endif 31 | 32 | #endif -------------------------------------------------------------------------------- /libc/src/string/_nmemset_i8086.S: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include "wonderful-asm.h" 13 | 14 | .arch i8086 15 | .code16 16 | .intel_syntax noprefix 17 | 18 | .global _nmemset 19 | _nmemset: 20 | #ifndef __IA16_CMODEL_IS_FAR_DATA 21 | .global memset 22 | memset: 23 | #endif 24 | push di 25 | push es 26 | push ax 27 | mov di, ax 28 | mov al, dl 29 | mov ah, al 30 | mov dx, ds 31 | mov es, dx 32 | shr cx, 1 33 | cld 34 | rep stosw 35 | jnc _nmemset_no_byte 36 | stosb 37 | _nmemset_no_byte: 38 | pop ax 39 | pop es 40 | pop di 41 | ASM_PLATFORM_RET 42 | -------------------------------------------------------------------------------- /libc/src/string/_nmemcmp.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | 14 | int _nmemcmp(const void* s1, const void* s2, size_t n) { 15 | const unsigned char* p1 = (const unsigned char*) s1; 16 | const unsigned char* p2 = (const unsigned char*) s2; 17 | while (n--) { 18 | if ( *p1 != *p2) { 19 | return *p1 - *p2; 20 | } 21 | p1++; 22 | p2++; 23 | } 24 | return 0; 25 | } 26 | 27 | #ifndef __IA16_CMODEL_IS_FAR_DATA 28 | __attribute__ ((alias ("_nmemcmp"))) 29 | void* memcmp(const void* s1, const void* s2, size_t n); 30 | #endif 31 | 32 | -------------------------------------------------------------------------------- /libc/src/string/_nmemcpy_i8086.S: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include "wonderful-asm.h" 13 | 14 | .arch i8086 15 | .code16 16 | .intel_syntax noprefix 17 | 18 | .global _nmemcpy 19 | _nmemcpy: 20 | #ifndef __IA16_CMODEL_IS_FAR_DATA 21 | .global memcpy 22 | memcpy: 23 | #endif 24 | push si 25 | push di 26 | push ds 27 | push es 28 | mov di, ax 29 | mov si, dx 30 | mov dx, ds 31 | mov es, dx 32 | shr cx, 1 33 | cld 34 | rep movsw 35 | jnc _nmemcpy_no_byte 36 | movsb 37 | _nmemcpy_no_byte: 38 | pop es 39 | pop ds 40 | pop di 41 | pop si 42 | ASM_PLATFORM_RET 43 | -------------------------------------------------------------------------------- /libc/src/string/_fmemcmp.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | 14 | int _fmemcmp(const void __far* s1, const void __far* s2, size_t n) { 15 | const unsigned char __far* p1 = (const unsigned char __far*) s1; 16 | const unsigned char __far* p2 = (const unsigned char __far*) s2; 17 | while (n--) { 18 | if ( *p1 != *p2) { 19 | return *p1 - *p2; 20 | } 21 | p1++; 22 | p2++; 23 | } 24 | return 0; 25 | } 26 | 27 | #ifdef __IA16_CMODEL_IS_FAR_DATA 28 | __attribute__ ((alias ("_fmemcmp"))) 29 | void* memcmp(const void* s1, const void* s2, size_t n); 30 | #endif 31 | 32 | -------------------------------------------------------------------------------- /libc/src/string/_nmemmove.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | 14 | #if 0 15 | 16 | void* _nmemmove(void* s1, const void* s2, size_t n) { 17 | char* dest = (char*) s1; 18 | const char* src = (const char*) s2; 19 | 20 | if (dest < src) { 21 | while (n--) { 22 | *dest++ = *src++; 23 | } 24 | } else if (dest > src) { 25 | src += n; 26 | dest += n; 27 | while (--n) { 28 | *(--dest) = *(--src); 29 | } 30 | } 31 | 32 | return s1; 33 | } 34 | 35 | #ifndef __IA16_CMODEL_IS_FAR_DATA 36 | __attribute__ ((alias ("_nmemmove"))) 37 | void* memmove(void* s1, const void* s2, size_t n); 38 | #endif 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /libc/src/string/_fmemmove.c: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include 13 | 14 | void __far* _fmemmove(void __far* s1, const void __far* s2, size_t n) { 15 | char __far* dest = (char __far*) s1; 16 | const char __far* src = (const char __far*) s2; 17 | 18 | if (dest < src) { 19 | while (n--) { 20 | *dest++ = *src++; 21 | } 22 | } else if (dest > src) { 23 | src += n; 24 | dest += n; 25 | while (--n) { 26 | *(--dest) = *(--src); 27 | } 28 | } 29 | 30 | return s1; 31 | } 32 | 33 | #ifdef __IA16_CMODEL_IS_FAR_DATA 34 | __attribute__ ((alias ("_fmemmove"))) 35 | void* memmove(void* s1, const void* s2, size_t n); 36 | #endif 37 | -------------------------------------------------------------------------------- /libc/include/stdlib.h: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #pragma once 13 | #include 14 | 15 | int abs(int j); 16 | long int labs(long int j); 17 | long long int llabs(long long int j); 18 | 19 | typedef struct { 20 | int quot; 21 | int rem; 22 | } div_t; 23 | div_t div(int numer, int denom); 24 | 25 | typedef struct { 26 | long int quot; 27 | long int rem; 28 | } ldiv_t; 29 | ldiv_t ldiv(long int numer, long int denom); 30 | 31 | typedef struct { 32 | long long int quot; 33 | long long int rem; 34 | } lldiv_t; 35 | lldiv_t lldiv(long long int numer, long long int denom); 36 | 37 | #define RAND_MAX 32767 38 | int rand(void); 39 | void srand(unsigned int seed); 40 | -------------------------------------------------------------------------------- /libc/src/string/_fmemset_i8086.S: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include "wonderful-asm.h" 13 | 14 | .arch i8086 15 | .code16 16 | .intel_syntax noprefix 17 | 18 | .global _fmemset 19 | _fmemset: 20 | #ifdef __IA16_CMODEL_IS_FAR_DATA 21 | .global memset 22 | memset: 23 | #endif 24 | push di 25 | push es 26 | push ax 27 | push bp 28 | mov bp, sp 29 | mov es, dx 30 | mov di, ax 31 | mov al, cl 32 | mov ah, al 33 | #ifdef __IA16_CMODEL_IS_FAR_TEXT 34 | mov cx, [bp + 12] 35 | #else 36 | mov cx, [bp + 10] 37 | #endif 38 | shr cx, 1 39 | cld 40 | rep stosw 41 | jnc _fmemset_no_byte 42 | stosb 43 | _fmemset_no_byte: 44 | pop bp 45 | pop ax 46 | pop es 47 | pop di 48 | ASM_PLATFORM_RET 0x2 49 | -------------------------------------------------------------------------------- /support/src/wonderful-wwitch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include "wonderful-asm.h" 26 | -------------------------------------------------------------------------------- /support/src/wonderful-wswan.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include "wonderful-asm.h" 26 | #include "ws.h" 27 | -------------------------------------------------------------------------------- /libww/include/sys/fcntl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | /** \file sys/fcntl.h 24 | */ 25 | 26 | #pragma once 27 | #include 28 | 29 | // TODO -------------------------------------------------------------------------------- /libww/include/stdio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | /** \file stdio.h 24 | * WonderWitch I/O operations. 25 | */ 26 | 27 | #pragma once 28 | #include 29 | -------------------------------------------------------------------------------- /support/src/wonderful-asm-wswan.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #pragma once 24 | 25 | #define __WONDERFUL_WSWAN__ 26 | 27 | #include "wonderful-asm-common.h" 28 | -------------------------------------------------------------------------------- /support/src/wonderful-asm-wwitch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #pragma once 24 | 25 | #define __WONDERFUL_WWITCH__ 26 | 27 | #include "wonderful-asm-common.h" 28 | -------------------------------------------------------------------------------- /libc/src/string/_fmemcpy_i8086.S: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include "wonderful-asm.h" 13 | 14 | .arch i8086 15 | .code16 16 | .intel_syntax noprefix 17 | 18 | .global _fmemcpy 19 | _fmemcpy: 20 | #ifdef __IA16_CMODEL_IS_FAR_DATA 21 | .global memcpy 22 | memcpy: 23 | #endif 24 | push si 25 | push di 26 | push ds 27 | push es 28 | push bp 29 | mov bp, sp 30 | mov es, dx 31 | mov di, ax 32 | #ifdef __IA16_CMODEL_IS_FAR_TEXT 33 | lds si, [bp + 14] 34 | mov cx, [bp + 18] 35 | #else 36 | lds si, [bp + 12] 37 | mov cx, [bp + 16] 38 | #endif 39 | shr cx, 1 40 | cld 41 | rep movsw 42 | jnc _fmemcpy_no_byte 43 | movsb 44 | _fmemcpy_no_byte: 45 | // dx:ax is already set to destination 46 | pop bp 47 | pop es 48 | pop ds 49 | pop di 50 | pop si 51 | ASM_PLATFORM_RET 0x6 52 | -------------------------------------------------------------------------------- /libww/src/wwc_get_hardarch.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | .arch i186 24 | .code16 25 | .intel_syntax noprefix 26 | 27 | .global wwc_get_hardarch 28 | wwc_get_hardarch: 29 | in al, 0xa0 30 | and al, 0x02 31 | shr al, 1 32 | ret 33 | -------------------------------------------------------------------------------- /examples/wswan/template/Makefile: -------------------------------------------------------------------------------- 1 | ifndef WONDERFUL_TOOLCHAIN 2 | $(error Please define WONDERFUL_TOOLCHAIN to point to the location of the Wonderful toolchain.) 3 | endif 4 | include $(WONDERFUL_TOOLCHAIN)/i8086/wswan.mk 5 | 6 | TARGET := $(notdir $(shell pwd)).ws 7 | OBJDIR := obj 8 | SRCDIRS := src 9 | MKDIRS := $(OBJDIR) 10 | LIBS := -lws -lc -lgcc 11 | CFLAGS += -O2 12 | 13 | CSOURCES := $(foreach dir,$(SRCDIRS),$(notdir $(wildcard $(dir)/*.c))) 14 | ASMSOURCES := $(foreach dir,$(SRCDIRS),$(notdir $(wildcard $(dir)/*.S))) 15 | OBJECTS := $(CSOURCES:%.c=$(OBJDIR)/%.o) $(ASMSOURCES:%.S=$(OBJDIR)/%.o) 16 | 17 | DEPS := $(OBJECTS:.o=.d) 18 | CFLAGS += -MMD -MP 19 | 20 | vpath %.c $(SRCDIRS) 21 | vpath %.S $(SRCDIRS) 22 | 23 | .PHONY: all clean install 24 | 25 | all: $(TARGET) 26 | 27 | $(TARGET): $(OBJECTS) 28 | $(SWANLINK) -v -o $@ --output-elf $@.elf --linker-args $(LDFLAGS) $(WF_CRT0) $(OBJECTS) $(LIBS) 29 | 30 | $(OBJDIR)/%.o: %.c | $(OBJDIR) 31 | $(CC) $(CFLAGS) -c -o $@ $< 32 | 33 | $(OBJDIR)/%.o: %.S | $(OBJDIR) 34 | $(AS) $(ASFLAGS) -o $@ $< 35 | 36 | $(OBJDIR): 37 | $(info $(shell mkdir -p $(MKDIRS))) 38 | 39 | clean: 40 | rm -r $(OBJDIR)/* 41 | rm $(TARGET) $(TARGET).elf 42 | 43 | -include $(DEPS) 44 | -------------------------------------------------------------------------------- /libws/src/util/inportw.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | .arch i8086 25 | .code16 26 | .intel_syntax noprefix 27 | 28 | .global inportw 29 | inportw: 30 | xor ah, ah 31 | mov dx, ax 32 | in ax, dx 33 | ASM_PLATFORM_RET 34 | -------------------------------------------------------------------------------- /libws/src/eeprom/ieep_read_owner_name.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | #include "ws/eeprom.h" 25 | 26 | void ws_ieep_read_owner_name(uint8_t *data) { 27 | ws_eeprom_read_data(ws_eeprom_handle_internal(), IEEP_ADDR_OWNER_NAME, data, 16); 28 | } -------------------------------------------------------------------------------- /libws/src/util/outportb.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | .arch i8086 25 | .code16 26 | .intel_syntax noprefix 27 | 28 | .global outportb 29 | outportb: 30 | xor ah, ah 31 | xchg ax, dx 32 | out dx, al 33 | ASM_PLATFORM_RET 34 | -------------------------------------------------------------------------------- /libws/src/util/outportw.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | .arch i8086 25 | .code16 26 | .intel_syntax noprefix 27 | 28 | .global outportw 29 | outportw: 30 | xor ah, ah 31 | xchg ax, dx 32 | out dx, ax 33 | ASM_PLATFORM_RET 34 | -------------------------------------------------------------------------------- /libc/src/string/_nmemmove_i8086.S: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #include "wonderful-asm.h" 13 | 14 | .arch i8086 15 | .code16 16 | .intel_syntax noprefix 17 | 18 | .global _nmemmove 19 | _nmemmove: 20 | #ifndef __IA16_CMODEL_IS_FAR_DATA 21 | .global memmove 22 | memmove: 23 | #endif 24 | push si 25 | push di 26 | push ds 27 | push es 28 | mov di, ax 29 | mov si, dx 30 | mov bx, ds 31 | mov es, bx 32 | cmp ax, dx 33 | ja _nmemmove_reversed 34 | shr cx, 1 35 | cld 36 | rep movsw 37 | jnc _nmemmove_no_byte 38 | movsb 39 | _nmemmove_no_byte: 40 | pop es 41 | pop ds 42 | pop di 43 | pop si 44 | ASM_PLATFORM_RET 45 | 46 | _nmemmove_reversed: 47 | // TODO: use rep movsw for performance 48 | dec cx 49 | add si, cx 50 | add di, cx 51 | inc cx 52 | std 53 | rep movsb 54 | pop es 55 | pop ds 56 | pop di 57 | pop si 58 | ASM_PLATFORM_RET 59 | -------------------------------------------------------------------------------- /libww/include/sys/bank.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | /** \file sys/bank.h 24 | * FreyaBIOS cartridge calls. 25 | */ 26 | 27 | #pragma once 28 | #include 29 | 30 | /** 31 | * @addtogroup Int18 BIOS - INT 18h - Cartridge 32 | * @{ 33 | */ 34 | 35 | /**@}*/ 36 | -------------------------------------------------------------------------------- /libww/src/wwc_set_color_mode.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | .arch i186 24 | .code16 25 | .intel_syntax noprefix 26 | 27 | .global wwc_set_color_mode 28 | wwc_set_color_mode: 29 | mov ah, al 30 | in al, 0x60 31 | and al, 0x1F 32 | or al, ah 33 | out 0x60, al 34 | ret 35 | -------------------------------------------------------------------------------- /libws/src/system/hwint_enable.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include "ws/system.h" 27 | 28 | void ws_hwint_enable(uint8_t mask) { 29 | outportb(IO_HWINT_ENABLE, inportb(IO_HWINT_ENABLE) | mask); 30 | } -------------------------------------------------------------------------------- /libws/src/serial/serial_putc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | #include "ws/util.h" 25 | #include "ws/hardware.h" 26 | #include "ws/serial.h" 27 | 28 | void ws_serial_putc(uint8_t ch) { 29 | while (!ws_serial_is_writable()) { } 30 | outportb(IO_SERIAL_DATA, ch); 31 | } -------------------------------------------------------------------------------- /libws/src/system/hwint_disable.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include "ws/system.h" 27 | 28 | void ws_hwint_disable(uint8_t mask) { 29 | outportb(IO_HWINT_ENABLE, inportb(IO_HWINT_ENABLE) & (~mask)); 30 | } -------------------------------------------------------------------------------- /libws/src/util/inportb.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | .arch i8086 25 | .code16 26 | .intel_syntax noprefix 27 | 28 | .global inportb 29 | inportb: 30 | xor ah, ah 31 | mov dx, ax 32 | in al, dx 33 | // xor ah, ah - cleared above 34 | ASM_PLATFORM_RET 35 | -------------------------------------------------------------------------------- /libws/src/display/display_set_shade_lut.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | .arch i186 25 | .code16 26 | .intel_syntax noprefix 27 | 28 | .global ws_display_set_shade_lut 29 | ws_display_set_shade_lut: 30 | out 0x1C, ax 31 | mov ax, dx 32 | out 0x1E, ax 33 | ASM_PLATFORM_RET 34 | -------------------------------------------------------------------------------- /libww/src/wwc_palette_get_color.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | .arch i186 24 | .code16 25 | .intel_syntax noprefix 26 | 27 | .global wwc_palette_get_color 28 | wwc_palette_get_color: 29 | mov ah, 0x7F 30 | shl al, 4 31 | add al, dl 32 | shl ax, 1 33 | mov bx, ax 34 | mov ax, word ptr ss:[bx] 35 | ret 36 | -------------------------------------------------------------------------------- /libww/src/wwc_palette_set_color.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | .arch i186 24 | .code16 25 | .intel_syntax noprefix 26 | 27 | .global wwc_palette_set_color 28 | wwc_palette_set_color: 29 | mov ah, 0x7F 30 | shl al, 4 31 | add al, dl 32 | shl ax, 1 33 | mov bx, ax 34 | mov word ptr ss:[bx], cx 35 | ret 36 | -------------------------------------------------------------------------------- /support/wonderful-i8086.mk: -------------------------------------------------------------------------------- 1 | CC := $(WONDERFUL_TOOLCHAIN)/toolchain/gcc-ia16-elf/bin/ia16-elf-gcc 2 | AR := $(WONDERFUL_TOOLCHAIN)/toolchain/gcc-ia16-elf/bin/ia16-elf-ar 3 | AS := $(WONDERFUL_TOOLCHAIN)/toolchain/gcc-ia16-elf/bin/ia16-elf-as 4 | LD := $(WONDERFUL_TOOLCHAIN)/toolchain/gcc-ia16-elf/bin/ia16-elf-ld 5 | NM := $(WONDERFUL_TOOLCHAIN)/toolchain/gcc-ia16-elf/bin/ia16-elf-nm 6 | OBJCOPY := $(WONDERFUL_TOOLCHAIN)/toolchain/gcc-ia16-elf/bin/ia16-elf-objcopy 7 | RANLIB := $(WONDERFUL_TOOLCHAIN)/toolchain/gcc-ia16-elf/bin/ia16-elf-ranlib 8 | SUPERFAMICONV := $(WONDERFUL_TOOLCHAIN)/bin/wf-superfamiconv 9 | BIN2C := $(WONDERFUL_TOOLCHAIN)/i8086/bin/wf-bin2c 10 | LZSA := $(WONDERFUL_TOOLCHAIN)/bin/wf-lzsa 11 | 12 | # wswan target tools 13 | FSBANKPACK := $(WONDERFUL_TOOLCHAIN)/i8086/bin/wf-fsbankpack 14 | SWANLINK := $(WONDERFUL_TOOLCHAIN)/i8086/bin/wf-swanlink 15 | 16 | # wwitch target tools 17 | MKFENT := $(WONDERFUL_TOOLCHAIN)/i8086/bin/wf-mkfent 18 | 19 | CFLAGS := -ffunction-sections -march=v30mz -mtune=v30mz -mregparmcall -msegelf -nostdlib -ffreestanding 20 | CFLAGS += -isystem $(WONDERFUL_TOOLCHAIN)/i8086/$(WONDERFUL_TARGET)/include 21 | ASFLAGS := --32-segelf 22 | LDFLAGS := -L$(WONDERFUL_TOOLCHAIN)/i8086/$(WONDERFUL_TARGET)/lib 23 | 24 | WF_CRT0 := $(WONDERFUL_TOOLCHAIN)/i8086/$(WONDERFUL_TARGET)/lib/crt0.o 25 | -------------------------------------------------------------------------------- /libws/src/system/mode_set.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | #include 25 | #include "ws/system.h" 26 | 27 | bool ws_mode_set(ws_mode_t mode) { 28 | if (!ws_system_is_color()) { 29 | return mode == 0; 30 | } 31 | outportb(IO_SYSTEM_CTRL2, (inportb(IO_SYSTEM_CTRL2) & 0x1F) | mode); 32 | return true; 33 | } 34 | 35 | -------------------------------------------------------------------------------- /libws/src/eeprom/eeprom_handle_internal.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | #include "ws/util.h" 25 | #include "ws/hardware.h" 26 | #include "ws/eeprom.h" 27 | 28 | ws_eeprom_handle_t ws_eeprom_handle_internal(void) { 29 | ws_eeprom_handle_t handle = {0xBA, inportb(IO_SYSTEM_CTRL2) ? (10 - 2) : (6 - 2)}; 30 | return handle; 31 | } 32 | -------------------------------------------------------------------------------- /libws/src/util/busywait.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | .arch i186 25 | .code16 26 | .intel_syntax noprefix 27 | 28 | .global ws_busywait 29 | ws_busywait: 30 | inc ax // round up 31 | shr ax, 1 // 1 us = ~3 cycles 32 | mov cx, ax 33 | ws_busywait_loop: 34 | nop // 1 cycle 35 | loop ws_busywait_loop // 2-5 cycles 36 | ASM_PLATFORM_RET -------------------------------------------------------------------------------- /libws/src/serial/serial_getc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | #include "ws/util.h" 25 | #include "ws/hardware.h" 26 | #include "ws/serial.h" 27 | 28 | uint8_t ws_serial_getc(void) { 29 | do { 30 | if (ws_serial_is_overrun()) { 31 | ws_serial_ack_overrun(); 32 | } 33 | } while (!ws_serial_is_readable()); 34 | return inportb(IO_SERIAL_DATA); 35 | } -------------------------------------------------------------------------------- /libws/src/system/cpuint_set_handler.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include "ws/system.h" 27 | 28 | void ws_cpuint_set_handler(uint8_t idx, ws_int_handler_t handler) { 29 | uint16_t *ptr = ((uint16_t*) (idx << 2)); 30 | *(ptr++) = FP_OFF(handler); 31 | *(ptr++) = FP_SEG(handler); 32 | } -------------------------------------------------------------------------------- /libww/include/sys/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | /** \file sys/types.h 24 | * General system types. 25 | */ 26 | 27 | #pragma once 28 | #include 29 | #include 30 | 31 | typedef uint8_t BYTE; 32 | typedef uint16_t WORD; 33 | typedef uint8_t BOOL; 34 | 35 | #define FALSE 0 36 | #define TRUE 1 37 | 38 | #define far __far 39 | #define near 40 | -------------------------------------------------------------------------------- /libws/include/ws.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | 27 | #ifndef __ASSEMBLER__ 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #endif 38 | -------------------------------------------------------------------------------- /libws/src/serial/serial_getc_nonblock.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | #include "ws/util.h" 25 | #include "ws/hardware.h" 26 | #include "ws/serial.h" 27 | 28 | int16_t ws_serial_getc_nonblock(void) { 29 | if (ws_serial_is_overrun()) { 30 | ws_serial_ack_overrun(); 31 | } 32 | if (!ws_serial_is_readable()) return -1; 33 | return inportb(IO_SERIAL_DATA); 34 | } 35 | -------------------------------------------------------------------------------- /libws/src/eeprom/eeprom_read_byte.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | 25 | .arch i186 26 | .code16 27 | .intel_syntax noprefix 28 | 29 | .global ws_eeprom_read_byte 30 | ws_eeprom_read_byte: 31 | test dl, 0x01 32 | jz ws_eeprom_read_word // Returns with AX = word (incl. low byte) 33 | ASM_PLATFORM_CALL ws_eeprom_read_word 34 | mov al, ah 35 | ASM_PLATFORM_RET 36 | -------------------------------------------------------------------------------- /libww/Makefile: -------------------------------------------------------------------------------- 1 | ifndef WONDERFUL_TOOLCHAIN 2 | $(error Please define WONDERFUL_TOOLCHAIN to point to the location of the Wonderful toolchain.) 3 | endif 4 | include $(WONDERFUL_TOOLCHAIN)/i8086/wwitch.mk 5 | 6 | TARGET := libww.a 7 | OBJDIR := obj 8 | SRCDIRS := src src/cartridge src/dma src/keypad src/system src/util src/video 9 | MKDIRS := $(OBJDIR) 10 | CFLAGS += -O2 11 | 12 | CSOURCES := $(foreach dir,$(SRCDIRS),$(notdir $(wildcard $(dir)/*.c))) 13 | ASMSOURCES := $(foreach dir,$(SRCDIRS),$(notdir $(wildcard $(dir)/*.S))) 14 | OBJECTS := $(CSOURCES:%.c=$(OBJDIR)/%.o) $(ASMSOURCES:%.S=$(OBJDIR)/%.o) 15 | 16 | DEPS := $(OBJECTS:.o=.d) 17 | CFLAGS += -MMD -MP 18 | 19 | CFLAGS += -Iinclude 20 | 21 | vpath %.c $(SRCDIRS) 22 | vpath %.S $(SRCDIRS) 23 | 24 | .PHONY: all clean doc install 25 | 26 | all: $(TARGET) 27 | 28 | $(TARGET): $(OBJECTS) 29 | $(AR) rcs $@ $(OBJECTS) 30 | 31 | $(OBJDIR)/%.o: %.c | $(OBJDIR) 32 | $(CC) $(CFLAGS) -c -o $@ $< 33 | 34 | $(OBJDIR)/%.o: %.S | $(OBJDIR) 35 | $(CC) $(CFLAGS) -c -o $@ $< 36 | 37 | $(OBJDIR): 38 | $(info $(shell mkdir -p $(MKDIRS))) 39 | 40 | clean: 41 | rm $(TARGET) $(OBJECTS) 42 | 43 | doc: 44 | @ mkdir -p build/doc 45 | doxygen 46 | 47 | install: $(TARGET) 48 | cp -r include/* $(WONDERFUL_TOOLCHAIN)/i8086/wwitch/include/ 49 | install -m 644 $(TARGET) $(WONDERFUL_TOOLCHAIN)/i8086/wwitch/lib 50 | 51 | -include $(DEPS) 52 | -------------------------------------------------------------------------------- /liblzsa/Makefile: -------------------------------------------------------------------------------- 1 | ifndef WONDERFUL_TOOLCHAIN 2 | $(error Please define WONDERFUL_TOOLCHAIN to point to the location of the Wonderful toolchain.) 3 | endif 4 | include $(WONDERFUL_TOOLCHAIN)/i8086/wswan.mk 5 | 6 | OBJDIR := obj 7 | MKDIRS := $(OBJDIR) 8 | CFLAGS += -O2 9 | 10 | SOURCES_SMALL := decompress_small_v1.S decompress_small_v2.S 11 | OBJECTS_SMALL := $(SOURCES_SMALL:%.S=$(OBJDIR)/%.o) 12 | 13 | SOURCES_FAST := decompress_speed_v1.S decompress_speed_v2.S 14 | OBJECTS_FAST := $(SOURCES_FAST:%.S=$(OBJDIR)/%.o) 15 | 16 | DEPS := $(OBJECTS_SMALL:.o=.d) $(OBJECTS_FAST:.o=.d) 17 | CFLAGS += -MMD -MP 18 | 19 | CFLAGS += -Iinclude 20 | 21 | vpath %.c src 22 | vpath %.S src 23 | 24 | all: liblzsa_small.a liblzsa.a 25 | 26 | liblzsa_small.a: $(OBJECTS_SMALL) 27 | $(AR) rcs $@ $(OBJECTS_SMALL) 28 | 29 | liblzsa.a: $(OBJECTS_FAST) 30 | $(AR) rcs $@ $(OBJECTS_FAST) 31 | 32 | $(OBJDIR)/%.o: %.c | $(OBJDIR) 33 | $(CC) $(CFLAGS) -c -o $@ $< 34 | 35 | $(OBJDIR)/%.o: %.S | $(OBJDIR) 36 | $(CC) $(CFLAGS) -c -o $@ $< 37 | 38 | $(OBJDIR): 39 | $(info $(shell mkdir -p $(MKDIRS))) 40 | 41 | clean: 42 | rm $(TARGET) $(OBJECTS_SMALL) $(OBJECTS_FAST) 43 | 44 | install: $(TARGET) 45 | cp -r include/* $(WONDERFUL_TOOLCHAIN)/i8086/wswan/include/ 46 | install -m 644 liblzsa_small.a $(WONDERFUL_TOOLCHAIN)/i8086/wswan/lib 47 | install -m 644 liblzsa.a $(WONDERFUL_TOOLCHAIN)/i8086/wswan/lib 48 | 49 | -include $(DEPS) 50 | -------------------------------------------------------------------------------- /libws/src/system/hwint_set_handler.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include "ws/hardware.h" 27 | #include "ws/system.h" 28 | 29 | void ws_hwint_set_handler(uint8_t idx, ws_int_handler_t handler) { 30 | uint16_t *ptr = ((uint16_t*) (((inportb(IO_HWINT_VECTOR) & 0xF8) | idx) << 2)); 31 | *(ptr++) = FP_OFF(handler); 32 | *(ptr++) = FP_SEG(handler); 33 | } -------------------------------------------------------------------------------- /libws/src/eeprom/eeprom_write_lock.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | 25 | .arch i186 26 | .code16 27 | .intel_syntax noprefix 28 | 29 | .global ws_eeprom_write_lock 30 | ws_eeprom_write_lock: 31 | mov dx, ax 32 | mov bl, 0x13 33 | call ws_eeprom_internal_addr_to_command 34 | add dl, 2 35 | out dx, ax 36 | mov ax, 0x40 37 | add dl, 2 38 | out dx, ax 39 | call ws_eeprom_internal_wait_ready 40 | ASM_PLATFORM_RET 41 | -------------------------------------------------------------------------------- /libww/src/wwc_clear_font.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | .arch i186 24 | .code16 25 | .intel_syntax noprefix 26 | 27 | // TODO: Is this accurate? 28 | .global wwc_clear_font 29 | wwc_clear_font: 30 | push di 31 | push es 32 | // ES:DI - destination pointer 33 | // CX - length (0x8000 / 2 = 0x4000) 34 | // AX - zeroes 35 | xor ax, ax 36 | mov es, ax 37 | mov cx, 0x4000 38 | mov di, cx 39 | cld 40 | rep movsw 41 | pop es 42 | pop di 43 | ret 44 | -------------------------------------------------------------------------------- /libws/src/eeprom/eeprom_write_unlock.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | 25 | .arch i186 26 | .code16 27 | .intel_syntax noprefix 28 | 29 | .global ws_eeprom_write_unlock 30 | ws_eeprom_write_unlock: 31 | mov dx, ax 32 | mov bl, 0x13 33 | call ws_eeprom_internal_addr_to_command 34 | add dl, 2 35 | out dx, ax 36 | mov ax, 0x40 37 | add dl, 2 38 | out dx, ax 39 | call ws_eeprom_internal_wait_ready 40 | ASM_PLATFORM_RET 41 | -------------------------------------------------------------------------------- /libws/src/dma/dma_copy_words_linear.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | #include "ws/util.h" 25 | #include "ws/hardware.h" 26 | #include "ws/dma.h" 27 | 28 | void ws_dma_copy_words_linear(void *dest, uint32_t src, uint16_t length) { 29 | outportw(IO_DMA_SOURCE_L, src); 30 | outportb(IO_DMA_SOURCE_H, src >> 16); 31 | outportw(IO_DMA_DEST, (uint16_t) dest); 32 | outportw(IO_DMA_LENGTH, length); 33 | outportb(IO_DMA_CTRL, DMA_TRANSFER_ENABLE); 34 | } 35 | -------------------------------------------------------------------------------- /libws/src/rtc/rtc_low_write_byte.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | 25 | .arch i186 26 | .code16 27 | .intel_syntax noprefix 28 | 29 | .global ws_rtc_low_write_byte 30 | .global ws_rtc_internal_low_write_byte 31 | ws_rtc_low_write_byte: 32 | mov cx, dx 33 | ws_rtc_internal_low_write_byte: 34 | call ws_rtc_internal_wait_ready_timeout 35 | and cx, cx 36 | jz ws_rtc_low_write_byte_fail 37 | out 0xCB, al 38 | ws_rtc_low_write_byte_fail: 39 | ASM_PLATFORM_RET -------------------------------------------------------------------------------- /libws/src/rtc/rtc_low_write_ctrl.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | 25 | .arch i186 26 | .code16 27 | .intel_syntax noprefix 28 | 29 | .global ws_rtc_low_write_ctrl 30 | .global ws_rtc_internal_low_write_ctrl 31 | ws_rtc_low_write_ctrl: 32 | mov cx, dx 33 | ws_rtc_internal_low_write_ctrl: 34 | call ws_rtc_internal_wait_ready_timeout 35 | and cx, cx 36 | jz ws_rtc_low_write_data_fail 37 | out 0xCA, al 38 | ws_rtc_low_write_data_fail: 39 | ASM_PLATFORM_RET -------------------------------------------------------------------------------- /libws/src/system/hwint_default_handler1.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | 25 | .arch i186 26 | .code16 27 | .intel_syntax noprefix 28 | .global ws_hwint_set_default_handler_key 29 | 30 | ws_hwint_internal_default_handler1: 31 | push ax 32 | mov al, 0x02 33 | out 0xB6, al 34 | pop ax 35 | iret 36 | 37 | ws_hwint_set_default_handler_key: 38 | mov ax, 1 39 | mov dx, offset "ws_hwint_internal_default_handler1" 40 | mov cx, cs 41 | ASM_PLATFORM_JMP ws_hwint_set_handler -------------------------------------------------------------------------------- /libws/src/dma/dma_opt_copy_words.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | #include 25 | #include "ws/util.h" 26 | #include "ws/hardware.h" 27 | #include "ws/system.h" 28 | #include "ws/dma.h" 29 | 30 | void ws_dma_opt_copy_words(void *dest, const void __far* src, uint16_t length) { 31 | if (ws_system_is_color()) { 32 | ws_dma_copy_words_linear(dest, (((uint32_t) src) >> 12) + ((uint16_t) ((uint32_t) src)), length); 33 | } else { 34 | memcpy(dest, src, length); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /libws/src/system/hwint_default_handler4.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | 25 | .arch i186 26 | .code16 27 | .intel_syntax noprefix 28 | .global ws_hwint_set_default_handler_line 29 | 30 | ws_hwint_internal_hwint_default_handler4: 31 | push ax 32 | mov al, 0x10 33 | out 0xB6, al 34 | pop ax 35 | iret 36 | 37 | ws_hwint_set_default_handler_line: 38 | mov ax, 4 39 | mov dx, offset "ws_hwint_internal_hwint_default_handler4" 40 | mov cx, cs 41 | ASM_PLATFORM_JMP ws_hwint_set_handler -------------------------------------------------------------------------------- /examples/wwitch/template/Makefile: -------------------------------------------------------------------------------- 1 | ifndef WONDERFUL_TOOLCHAIN 2 | $(error Please define WONDERFUL_TOOLCHAIN to point to the location of the Wonderful toolchain.) 3 | endif 4 | include $(WONDERFUL_TOOLCHAIN)/i8086/wwitch.mk 5 | 6 | TARGET := $(notdir $(shell pwd)).fx 7 | TARGET_NAME := $(notdir $(shell pwd)) 8 | TARGET_INFO := $(TARGET_NAME) 9 | 10 | OBJDIR := obj 11 | SRCDIRS := src 12 | MKDIRS := $(OBJDIR) 13 | LIBS := -lww -lc 14 | CFLAGS += -Os 15 | 16 | #WF_CRT0 := $(WF_CRT0_ASC1) 17 | #WF_CRT0 := $(WF_CRT0_ASC2) 18 | #WF_CRT0 := $(WF_CRT0_JPN1) 19 | WF_CRT0 := $(WF_CRT0_JPN2) 20 | 21 | CSOURCES := $(foreach dir,$(SRCDIRS),$(notdir $(wildcard $(dir)/*.c))) 22 | ASMSOURCES := $(foreach dir,$(SRCDIRS),$(notdir $(wildcard $(dir)/*.S))) 23 | OBJECTS := $(CSOURCES:%.c=$(OBJDIR)/%.o) $(ASMSOURCES:%.S=$(OBJDIR)/%.o) 24 | 25 | DEPS := $(OBJECTS:.o=.d) 26 | CFLAGS += -MMD -MP 27 | 28 | vpath %.c $(SRCDIRS) 29 | vpath %.S $(SRCDIRS) 30 | 31 | .PHONY: all clean install 32 | 33 | all: $(TARGET) 34 | 35 | $(TARGET): $(OBJECTS) 36 | $(LD) -o $@.elf -T$(WF_LDSCRIPT) $(LDFLAGS) $(WF_CRT0) $(OBJECTS) $(LIBS) 37 | $(MKFENT) -o $@ --name "$(TARGET_NAME)" --info "$(TARGET_INFO)" $@.elf 38 | 39 | $(OBJDIR)/%.o: %.c | $(OBJDIR) 40 | $(CC) $(CFLAGS) -c -o $@ $< 41 | 42 | $(OBJDIR)/%.o: %.S | $(OBJDIR) 43 | $(AS) $(ASFLAGS) -o $@ $< 44 | 45 | $(OBJDIR): 46 | $(info $(shell mkdir -p $(MKDIRS))) 47 | 48 | clean: 49 | -$(RM) -r $(OBJDIR)/* 50 | -$(RM) $(TARGET) $(TARGET).elf 51 | 52 | -include $(DEPS) 53 | -------------------------------------------------------------------------------- /libws/src/eeprom/eeprom_erase_word.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | 25 | .arch i186 26 | .code16 27 | .intel_syntax noprefix 28 | 29 | .global ws_eeprom_erase_word 30 | ws_eeprom_erase_word: 31 | xchg ax, dx // AX = address, DL = port, DH = dwords 32 | 33 | mov bl, 0x1C 34 | call ws_eeprom_internal_addr_to_command 35 | 36 | add dl, 2 // 0xBC 37 | out dx, ax 38 | mov ax, 0x40 39 | add dl, 2 // 0xBE 40 | out dx, ax 41 | call ws_eeprom_internal_wait_ready 42 | ASM_PLATFORM_RET 43 | -------------------------------------------------------------------------------- /libws/src/system/hwint_default_handler6.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | 25 | .arch i186 26 | .code16 27 | .intel_syntax noprefix 28 | .global ws_hwint_set_default_handler_vblank 29 | 30 | ws_hwint_internal_hwint_default_handler6: 31 | push ax 32 | mov al, 0x40 33 | out 0xB6, al 34 | pop ax 35 | iret 36 | 37 | ws_hwint_set_default_handler_vblank: 38 | mov ax, 6 39 | mov dx, offset "ws_hwint_internal_hwint_default_handler6" 40 | mov cx, cs 41 | ASM_PLATFORM_JMP ws_hwint_set_handler -------------------------------------------------------------------------------- /libws/src/system/hwint_default_handler5.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | 25 | .arch i186 26 | .code16 27 | .intel_syntax noprefix 28 | .global ws_hwint_set_default_handler_vblank_timer 29 | 30 | ws_hwint_internal_hwint_default_handler5: 31 | push ax 32 | mov al, 0x20 33 | out 0xB6, al 34 | pop ax 35 | iret 36 | 37 | ws_hwint_set_default_handler_vblank_timer: 38 | mov ax, 5 39 | mov dx, offset "ws_hwint_internal_hwint_default_handler5" 40 | mov cx, cs 41 | ASM_PLATFORM_JMP ws_hwint_set_handler -------------------------------------------------------------------------------- /libws/src/system/hwint_default_handler7.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | 25 | .arch i186 26 | .code16 27 | .intel_syntax noprefix 28 | .global ws_hwint_set_default_handler_hblank_timer 29 | 30 | ws_hwint_internal_hwint_default_handler7: 31 | push ax 32 | mov al, 0x80 33 | out 0xB6, al 34 | pop ax 35 | iret 36 | 37 | ws_hwint_set_default_handler_hblank_timer: 38 | mov ax, 7 39 | mov dx, offset "ws_hwint_internal_hwint_default_handler7" 40 | mov cx, cs 41 | ASM_PLATFORM_JMP ws_hwint_set_handler -------------------------------------------------------------------------------- /libws/src/rtc/rtc_low_read_byte.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | 25 | .arch i186 26 | .code16 27 | .intel_syntax noprefix 28 | 29 | .global ws_rtc_low_read_byte 30 | .global ws_rtc_internal_low_read_byte 31 | ws_rtc_low_read_byte: 32 | mov cx, ax 33 | ws_rtc_internal_low_read_byte: 34 | xor ah, ah 35 | call ws_rtc_internal_wait_ready_timeout 36 | and cx, cx 37 | jz ws_rtc_low_read_byte_fail 38 | in al, 0xCB 39 | ASM_PLATFORM_RET 40 | ws_rtc_low_read_byte_fail: 41 | mov ax, 0xFFFF 42 | ASM_PLATFORM_RET 43 | -------------------------------------------------------------------------------- /libws/src/cartridge/cart_gpo.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | #include 25 | #include "ws/cartridge.h" 26 | 27 | void ws_cart_gpo_enable(uint8_t id) { 28 | outportb(IO_CART_GPO_CTRL, inportb(IO_CART_GPO_CTRL) | (1 << id)); 29 | } 30 | 31 | void ws_cart_gpo_disable(uint8_t id) { 32 | outportb(IO_CART_GPO_CTRL, inportb(IO_CART_GPO_CTRL) & (~(1 << id))); 33 | } 34 | 35 | void ws_cart_gpo_set(uint8_t id, bool val) { 36 | outportb(IO_CART_GPO_DATA, inportb(IO_CART_GPO_DATA) & (~(1 << id)) | ((val & 1) << id)); 37 | } 38 | -------------------------------------------------------------------------------- /libws/src/eeprom/eeprom_read_word.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | 25 | .arch i186 26 | .code16 27 | .intel_syntax noprefix 28 | 29 | .global ws_eeprom_read_word 30 | ws_eeprom_read_word: 31 | xchg ax, dx // AX = address, DL = port, DH = dwords 32 | 33 | mov bl, 0x18 34 | call ws_eeprom_internal_addr_to_command 35 | add dl, 2 36 | out dx, ax // 0xBC 37 | mov ax, 0x10 38 | add dl, 2 39 | out dx, ax // 0xBE 40 | call ws_eeprom_internal_wait_done 41 | sub dl, 4 42 | in ax, dx // 0xBA 43 | ASM_PLATFORM_RET 44 | -------------------------------------------------------------------------------- /libws/src/keypad/keypad_scan.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | .arch i186 25 | .code16 26 | .intel_syntax noprefix 27 | 28 | .global ws_keypad_scan 29 | ws_keypad_scan: 30 | mov dx, 0x00B5 31 | 32 | mov al, 0x10 33 | out dx, al 34 | daa 35 | in al, dx 36 | and al, 0x0F 37 | mov ch, al 38 | 39 | mov al, 0x20 40 | out dx, al 41 | daa 42 | in al, dx 43 | shl al, 4 44 | mov cl, al 45 | 46 | mov al, 0x40 47 | out dx, al 48 | daa 49 | in al, dx 50 | and al, 0x0F 51 | or cl, al 52 | 53 | mov ax, cx 54 | ASM_PLATFORM_RET 55 | -------------------------------------------------------------------------------- /libws/src/system/hwint_default_handler0.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | 25 | .arch i186 26 | .code16 27 | .intel_syntax noprefix 28 | .global ws_hwint_set_default_handler_serial_tx 29 | 30 | ws_hwint_internal_default_handler0: 31 | push ax 32 | in al, 0xB2 33 | and al, 0xFE 34 | out 0xB2, al 35 | mov al, 0x01 36 | out 0xB6, al 37 | pop ax 38 | iret 39 | 40 | ws_hwint_set_default_handler_serial_tx: 41 | mov ax, 0 42 | mov dx, offset "ws_hwint_internal_default_handler0" 43 | mov cx, cs 44 | ASM_PLATFORM_JMP ws_hwint_set_handler -------------------------------------------------------------------------------- /libws/src/system/hwint_default_handler3.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | 25 | .arch i186 26 | .code16 27 | .intel_syntax noprefix 28 | .global ws_hwint_set_default_handler_serial_rx 29 | 30 | ws_hwint_internal_hwint_default_handler3: 31 | push ax 32 | in al, 0xB2 33 | and al, 0xF7 34 | out 0xB2, al 35 | mov al, 0x08 36 | out 0xB6, al 37 | pop ax 38 | iret 39 | 40 | ws_hwint_set_default_handler_serial_rx: 41 | mov ax, 3 42 | mov dx, offset "ws_hwint_internal_hwint_default_handler3" 43 | mov cx, cs 44 | ASM_PLATFORM_JMP ws_hwint_set_handler -------------------------------------------------------------------------------- /libws/src/eeprom/eeprom_write_word.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | 25 | .arch i186 26 | .code16 27 | .intel_syntax noprefix 28 | 29 | .global ws_eeprom_write_word 30 | ws_eeprom_write_word: 31 | xchg ax, dx // AX = address, DL = port, DH = dwords 32 | 33 | push cx 34 | mov bl, 0x14 35 | call ws_eeprom_internal_addr_to_command 36 | pop cx 37 | add dl, 2 38 | out dx, ax // 0xBC 39 | mov ax, cx 40 | sub dl, 2 41 | out dx, ax // 0xBA 42 | mov ax, 0x20 43 | add dl, 4 44 | out dx, ax // 0xBE 45 | call ws_eeprom_internal_wait_ready 46 | ASM_PLATFORM_RET 47 | -------------------------------------------------------------------------------- /libws/src/display/screen_fill.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | #include "ws/display.h" 25 | 26 | #define NEXT_ROW(i) ((uint16_t*) ( ((uint16_t) (v_dest + SCR_WIDTH) & 0x7FF) | ((uint16_t) (v_dest) & 0xF800) )) 27 | 28 | void ws_screen_fill(void *dest, uint16_t src, uint8_t x, uint8_t y, uint8_t width, uint8_t height) { 29 | uint16_t* v_dest = ((uint16_t*) dest) + ((y & 0x1F) * SCR_WIDTH); 30 | 31 | for (uint8_t iy = height; iy > 0; iy--, v_dest = NEXT_ROW(v_dest)) { 32 | for (uint8_t ix = 0; ix < width; ix++) { 33 | v_dest[(ix + x) & 0x1F] = src; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /libww/include/sys/bios.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | /** \file sys/bios.h 24 | * FreyaBIOS calls. 25 | */ 26 | 27 | #pragma once 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | /** 39 | * @addtogroup Int10 BIOS - INT 10h - Exit 40 | * @{ 41 | */ 42 | 43 | static inline void bios_exit(void) { 44 | __asm volatile ( 45 | "int $0x10" 46 | : 47 | : 48 | : 49 | ); 50 | } 51 | 52 | /**@}*/ -------------------------------------------------------------------------------- /libws/src/eeprom/eeprom_read_data.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | #include "ws/eeprom.h" 25 | 26 | void ws_eeprom_read_data(ws_eeprom_handle_t handle, uint16_t address, uint8_t *data, uint16_t length) { 27 | uint16_t address_last = address + length; 28 | uint16_t i = 0; 29 | if (address & 1) { 30 | data[i++] = ws_eeprom_read_byte(handle, address++); 31 | } 32 | for (; address < (address_last & (~1)); i += 2, address += 2) { 33 | *((uint16_t*) (data + i)) = ws_eeprom_read_word(handle, address); 34 | } 35 | if (address_last & 1) { 36 | data[i] = ws_eeprom_read_byte(handle, address); 37 | } 38 | } -------------------------------------------------------------------------------- /libws/Makefile: -------------------------------------------------------------------------------- 1 | ifndef WONDERFUL_TOOLCHAIN 2 | $(error Please define WONDERFUL_TOOLCHAIN to point to the location of the Wonderful toolchain.) 3 | endif 4 | 5 | WONDERFUL_TARGET ?= wswan 6 | include $(WONDERFUL_TOOLCHAIN)/i8086/$(WONDERFUL_TARGET).mk 7 | 8 | OBJDIR := obj/$(WONDERFUL_TARGET) 9 | TARGETDIR := build/$(WONDERFUL_TARGET) 10 | TARGET := $(TARGETDIR)/libws.a 11 | SRCDIRS := src src/cartridge src/display src/dma src/eeprom src/keypad src/rtc src/serial src/system src/util 12 | MKDIRS := $(OBJDIR) build/$(WONDERFUL_TARGET) 13 | CFLAGS += -O2 -ffunction-sections 14 | 15 | CSOURCES := $(foreach dir,$(SRCDIRS),$(notdir $(wildcard $(dir)/*.c))) 16 | ASMSOURCES := $(foreach dir,$(SRCDIRS),$(notdir $(wildcard $(dir)/*.S))) 17 | OBJECTS := $(CSOURCES:%.c=$(OBJDIR)/%.o) $(ASMSOURCES:%.S=$(OBJDIR)/%.o) 18 | 19 | DEPS := $(OBJECTS:.o=.d) 20 | CFLAGS += -MMD -MP 21 | 22 | CFLAGS += -Iinclude 23 | 24 | vpath %.c $(SRCDIRS) 25 | vpath %.S $(SRCDIRS) 26 | 27 | .PHONY: all clean doc install 28 | 29 | all: $(TARGET) 30 | 31 | $(TARGET): $(OBJECTS) 32 | $(AR) rcs $@ $(OBJECTS) 33 | 34 | $(OBJDIR)/%.o: %.c | $(OBJDIR) 35 | $(CC) $(CFLAGS) -c -o $@ $< 36 | 37 | $(OBJDIR)/%.o: %.S | $(OBJDIR) 38 | $(CC) $(CFLAGS) -c -o $@ $< 39 | 40 | $(OBJDIR): 41 | $(info $(shell mkdir -p $(MKDIRS))) 42 | 43 | clean: 44 | rm $(TARGET) $(OBJECTS) 45 | 46 | doc: 47 | @ mkdir -p build/doc 48 | doxygen 49 | 50 | install: $(TARGET) 51 | cp -r include/* $(WONDERFUL_TOOLCHAIN)/i8086/$(WONDERFUL_TARGET)/include/ 52 | install -m 644 $(TARGET) $(WONDERFUL_TOOLCHAIN)/i8086/$(WONDERFUL_TARGET)/lib 53 | 54 | -include $(DEPS) 55 | -------------------------------------------------------------------------------- /libws/include/ws/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #pragma once 24 | #include 25 | #include 26 | 27 | /** \file util.h 28 | * Various utility functions for working with the WonderSwan hardware. 29 | */ 30 | 31 | /** 32 | * @brief Busy wait. 33 | * 34 | * This is not recommended - use only when necessary! 35 | * Not halting the CPU can lead to higher power consumption. 36 | * The recommended approach is configuring an interrupt handler 37 | * and using cpu_halt() - which will then sleep until any interrupt 38 | * occurs. 39 | * 40 | * @param us Approximate number of microseconds. 41 | */ 42 | void ws_busywait(uint16_t us); -------------------------------------------------------------------------------- /libws/src/eeprom/ieep_name_color_to_rgb.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | #include "ws/display.h" 25 | #include "ws/eeprom.h" 26 | 27 | static const uint16_t __far ieep_name_color_to_rgb_map[16] = { 28 | RGB(0, 0, 0), 29 | RGB(15, 0, 0), 30 | RGB(15, 7, 0), 31 | RGB(15, 15, 0), 32 | RGB(7, 15, 0), 33 | RGB(0, 15, 0), 34 | RGB(0, 15, 7), 35 | RGB(0, 15, 15), 36 | RGB(0, 7, 15), 37 | RGB(0, 0, 15), 38 | RGB(7, 0, 15), 39 | RGB(15, 0, 15), 40 | RGB(15, 0, 7), 41 | RGB(15, 15, 15), 42 | RGB(7, 7, 7), 43 | RGB(7, 7, 7) 44 | }; 45 | 46 | uint16_t ws_ieep_name_color_to_rgb(uint8_t value) { 47 | return ieep_name_color_to_rgb_map[value & 0x0F]; 48 | } 49 | -------------------------------------------------------------------------------- /libws/src/display/screen_put_map.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | #include "ws/display.h" 25 | 26 | #define NEXT_ROW(i) ((uint16_t*) ( ((uint16_t) (v_dest + SCR_WIDTH) & 0x7FF) | ((uint16_t) (v_dest) & 0xF800) )) 27 | 28 | void ws_screen_put_map(void *dest, const void __far* src, uint8_t x, uint8_t y, uint8_t width, uint8_t height) { 29 | uint16_t* v_dest = ((uint16_t*) dest) + ((y & 0x1F) * SCR_WIDTH); 30 | const uint16_t __far* v_src = (const uint16_t __far*) src; 31 | 32 | for (uint8_t iy = height; iy > 0; iy--, v_dest = NEXT_ROW(v_dest)) { 33 | for (uint8_t ix = 0; ix < width; ix++) { 34 | v_dest[(ix + x) & 0x1F] = *(v_src++); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /libc/Makefile: -------------------------------------------------------------------------------- 1 | ifndef WONDERFUL_TOOLCHAIN 2 | $(error Please define WONDERFUL_TOOLCHAIN to point to the location of the Wonderful toolchain.) 3 | endif 4 | 5 | WONDERFUL_TARGET ?= wswan 6 | include $(WONDERFUL_TOOLCHAIN)/i8086/$(WONDERFUL_TARGET).mk 7 | 8 | OBJDIR := obj/$(WONDERFUL_TARGET) 9 | TARGETDIR := build/$(WONDERFUL_TARGET) 10 | TARGET := $(TARGETDIR)/libc.a 11 | SRCDIRS := src src/ctype src/errno src/stdlib src/string 12 | MKDIRS := $(OBJDIR) build/$(WONDERFUL_TARGET) 13 | CFLAGS += -ffunction-sections 14 | 15 | ifeq ($(WONDERFUL_TARGET), wwitch) 16 | CFLAGS += -Os -DLIBC_LOCALE_SJIS 17 | else 18 | CFLAGS += -O2 -DLIBC_LOCALE_ASCII 19 | endif 20 | 21 | CSOURCES := $(foreach dir,$(SRCDIRS),$(notdir $(wildcard $(dir)/*.c))) 22 | ASMSOURCES := $(foreach dir,$(SRCDIRS),$(notdir $(wildcard $(dir)/*.S))) 23 | OBJECTS := $(CSOURCES:%.c=$(OBJDIR)/%.o) $(ASMSOURCES:%.S=$(OBJDIR)/%.o) 24 | 25 | DEPS := $(OBJECTS:.o=.d) 26 | CFLAGS += -MMD -MP 27 | 28 | CFLAGS += -Iinclude 29 | 30 | vpath %.c $(SRCDIRS) 31 | vpath %.S $(SRCDIRS) 32 | 33 | .PHONY: all clean install 34 | 35 | all: $(TARGET) 36 | 37 | $(TARGET): $(OBJECTS) | $(OBJDIR) 38 | $(AR) rcs $@ $(OBJECTS) 39 | 40 | $(OBJDIR)/%.o: %.c | $(OBJDIR) 41 | $(CC) $(CFLAGS) -c -o $@ $< 42 | 43 | $(OBJDIR)/%.o: %.S | $(OBJDIR) 44 | $(CC) $(CFLAGS) -c -o $@ $< 45 | 46 | $(OBJDIR): 47 | $(info $(foreach dir,$(MKDIRS),$(shell mkdir -p $(dir)))) 48 | 49 | clean: 50 | rm $(TARGET) $(OBJECTS) 51 | 52 | install: $(TARGET) 53 | cp -r include/* $(WONDERFUL_TOOLCHAIN)/i8086/$(WONDERFUL_TARGET)/include/ 54 | install -m 644 $(TARGET) $(WONDERFUL_TOOLCHAIN)/i8086/$(WONDERFUL_TARGET)/lib 55 | 56 | -include $(DEPS) 57 | -------------------------------------------------------------------------------- /libww/src/wwc_font_set_colordata.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | .arch i186 24 | .code16 25 | .intel_syntax noprefix 26 | 27 | // TODO: Does this routine check color_mode? 28 | .global wwc_font_set_colordata 29 | wwc_font_set_colordata: 30 | push si 31 | push di 32 | push ds 33 | push es 34 | push bp 35 | mov bp, sp 36 | // ES:DI - destination pointer 37 | xor bx, bx 38 | mov es, bx 39 | shl ax, 4 40 | mov di, ax 41 | // DS:SI - source pointer 42 | #ifdef __IA16_CMODEL_IS_FAR_TEXT 43 | lds si, [bp + 14] 44 | #else 45 | lds si, [bp + 12] 46 | #endif 47 | // CX - length 48 | mov cx, dx 49 | shl cx, 4 50 | cld 51 | rep movsw 52 | pop bp 53 | pop es 54 | pop ds 55 | pop di 56 | pop si 57 | ret 0x4 58 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # wonderful-i8086 2 | 3 | Experimental C toolchain for the WonderSwan. Early development. 4 | 5 | ## Known limitations 6 | 7 | * Read-only data (const arrays, etc.) will only end up in ROM if declared as `__far`. 8 | * To be more precise, by default, pointers are near pointers. In wonderful-i8086, this means they can only point to the console RAM. To point to SRAM or the console ROM, far pointers must be utilized. 9 | * The WonderWitch target has compilation issues on non-trivial code, due to the necessary logic to handle DS ≠ SS. This is unlikely to be resolved shortly. 10 | * tkchia: "Yes, unfortunately support for %ss ≠ .data code is still extremely hacky and involves some not-quite-reliable deep black magic. (GCC was never quite designed in the first place to work with non-flat address spaces. Plus, the libgcc library was definitely not written with a %ss ≠ .data environment in mind.)" ([source](https://github.com/tkchia/gcc-ia16/issues/102)) 11 | 12 | ## Installation instructions 13 | 14 | Check back later. 15 | 16 | ## Licensing information 17 | 18 | All source files have their licensing terms stated in the file itself. Crucially, for runtime components linked with a compiled binary, the licenses are as follows: 19 | 20 | ### Core libraries 21 | 22 | * libgcc runtime library: [GPLv3 w/ Runtime Library Exception](https://www.fsf.org/news/2009-01-gcc-exception) 23 | * startup/support code (`support/src/`): [zlib license](docs/COPYING.ZLIB) 24 | * wonderful-i8086 C library (`libc/`): [CC0/public domain-like](docs/COPYING.CC0) 25 | * wonderful-i8086 platform library (`libws/`, `libww/`): [zlib license](docs/COPYING.ZLIB) 26 | 27 | ### Additional libraries 28 | 29 | * lzsa decompression library (`liblzsa/`): [zlib license](liblzsa/README.md) 30 | -------------------------------------------------------------------------------- /libws/include/ws/keypad.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | /** \file keypad.h 24 | * Functionality related to the keypad. 25 | */ 26 | 27 | #pragma once 28 | #include 29 | 30 | /** 31 | * @addtogroup Keypad Functions - Keypad 32 | * @{ 33 | */ 34 | 35 | /** 36 | * @brief Query the current state of the keypad. 37 | * 38 | * @return uint16_t A bitfield representing currently pressed keys. 39 | */ 40 | uint16_t ws_keypad_scan(void); 41 | 42 | #define KEY_Y4 0x0800 43 | #define KEY_Y3 0x0400 44 | #define KEY_Y2 0x0200 45 | #define KEY_Y1 0x0100 46 | #define KEY_X4 0x0080 47 | #define KEY_X3 0x0040 48 | #define KEY_X2 0x0020 49 | #define KEY_X1 0x0010 50 | #define KEY_B 0x0008 51 | #define KEY_A 0x0004 52 | #define KEY_START 0x0002 53 | 54 | /**@}*/ -------------------------------------------------------------------------------- /libws/src/rtc/rtc_utils.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | 25 | .arch i186 26 | .code16 27 | .intel_syntax noprefix 28 | 29 | // CX = timeout value 30 | // preserves AX 31 | // if CX = 0, timeout occured 32 | .global ws_rtc_wait_ready_timeout 33 | ws_rtc_internal_wait_ready_timeout: 34 | push ax 35 | shr cx, 2 // 3 cycles ~= 1 us 36 | ws_rtc_internal_wait_ready_loop: 37 | // 15 cycles per iteration, or so 38 | dec cx // 1 cycle 39 | jz ws_rtc_internal_wait_ready_done // 1 cycle (branch not taken) 40 | in al, 0xCA // 6 cycles 41 | test al, 0x10 // 1 cycle 42 | jz ws_rtc_internal_wait_ready_done // 1-4 cycles 43 | test al, 0x80 // 1 cycle 44 | jz ws_rtc_internal_wait_ready_loop // 1-4 cycles 45 | ws_rtc_internal_wait_ready_done: 46 | pop ax 47 | ret 48 | -------------------------------------------------------------------------------- /libws/src/eeprom/ieep_read_owner_name_ascii.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | #include "ws/eeprom.h" 25 | 26 | const char __far ws_ieep_internal_owner_to_ascii_map[] = { 27 | ' ', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 28 | 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 29 | 'V', 'W', 'X', 'Y', 'Z', 3/* heart */, 13/* music note */, '+', '-', '?', '.' 30 | }; 31 | 32 | void ws_ieep_read_owner_name_ascii(char *str) { 33 | uint8_t i, len; 34 | 35 | ws_ieep_read_owner_name((uint8_t*) str); 36 | for (i = 0; i < 16; i++) { 37 | if (str[i] == 0x00 || str[i] >= sizeof(ws_ieep_internal_owner_to_ascii_map)) break; 38 | str[i] = ws_ieep_internal_owner_to_ascii_map[str[i]]; 39 | } 40 | str[i] = 0; 41 | } 42 | -------------------------------------------------------------------------------- /libww/include/sys/libwwc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | /** \file sys/libwwc.h 24 | * WonderWitch Color support. 25 | */ 26 | 27 | #pragma once 28 | #include 29 | 30 | /** 31 | * @addtogroup LibWWC WonderWitch Color routines 32 | * @{ 33 | */ 34 | 35 | #define HARDARCH_WS 0 36 | #define HARDARCH_WSC 1 37 | 38 | uint8_t wwc_get_hardarch(); 39 | 40 | #define COLOR_MODE_GRAYSCALE 0x00 41 | #define COLOR_MODE_4COLOR 0x80 42 | #define COLOR_MODE_16COLOR 0xC0 43 | #define COLOR_MODE_16PACKED 0xE0 44 | 45 | void wwc_set_color_mode(uint8_t color_mode); 46 | void wwc_palette_set_color(uint8_t idx, uint8_t sub_idx, uint16_t color); 47 | uint16_t wwc_palette_get_color(uint8_t idx, uint8_t sub_idx); 48 | void wwc_font_set_colordata(uint16_t start, uint16_t count, const void __far* data); 49 | void wwc_clear_font(void); 50 | 51 | /**@}*/ -------------------------------------------------------------------------------- /examples/wswan/pong/Makefile: -------------------------------------------------------------------------------- 1 | ifndef WONDERFUL_TOOLCHAIN 2 | $(error Please define WONDERFUL_TOOLCHAIN to point to the location of the Wonderful toolchain.) 3 | endif 4 | include $(WONDERFUL_TOOLCHAIN)/i8086/wswan.mk 5 | 6 | TARGET := $(notdir $(shell pwd)).ws 7 | OBJDIR := obj 8 | RESDIR := res 9 | SRCDIRS := src 10 | MKDIRS := $(OBJDIR) 11 | LIBS := -lws -lc -lgcc 12 | CFLAGS += -O2 13 | 14 | CSOURCES := $(foreach dir,$(SRCDIRS),$(notdir $(wildcard $(dir)/*.c))) 15 | ASMSOURCES := $(foreach dir,$(SRCDIRS),$(notdir $(wildcard $(dir)/*.S))) 16 | EARLY_OBJECTS := $(OBJDIR)/assets.o 17 | OBJECTS := $(CSOURCES:%.c=$(OBJDIR)/%.o) $(ASMSOURCES:%.S=$(OBJDIR)/%.o) $(EARLY_OBJECTS) 18 | CFLAGS += -I$(OBJDIR) 19 | 20 | DEPS := $(OBJECTS:.o=.d) 21 | CFLAGS += -MMD -MP 22 | 23 | vpath %.c $(SRCDIRS) 24 | vpath %.S $(SRCDIRS) 25 | 26 | .PHONY: all clean install 27 | 28 | all: $(TARGET) 29 | 30 | $(TARGET): $(OBJECTS) 31 | $(SWANLINK) -v -o $@ --output-elf $@.elf --linker-args $(LDFLAGS) $(WF_CRT0) $(OBJECTS) $(LIBS) 32 | 33 | $(OBJDIR)/%.o: %.c $(EARLY_OBJECTS) | $(OBJDIR) 34 | $(CC) $(CFLAGS) -c -o $@ $< 35 | 36 | $(OBJDIR)/%.o: %.S $(EARLY_OBJECTS) | $(OBJDIR) 37 | $(AS) $(ASFLAGS) -o $@ $< 38 | 39 | $(OBJDIR)/assets.c: $(RESDIR)/game_tiles.png $(RESDIR)/game_bg.png $(RESDIR)/palette.bin | $(OBJDIR) 40 | $(SUPERFAMICONV) tiles -i $(RESDIR)/game_tiles.png -M ws -p $(RESDIR)/palette.bin -d $(OBJDIR)/game_tiles.tiles.bin 41 | $(SUPERFAMICONV) tiles -i $(RESDIR)/game_bg.png -M ws -p $(RESDIR)/palette.bin -d $(OBJDIR)/game_bg.tiles.bin 42 | $(SUPERFAMICONV) map -i $(RESDIR)/game_bg.png -M ws -p $(RESDIR)/palette.bin -t $(OBJDIR)/game_bg.tiles.bin -d $(OBJDIR)/game_bg.map.bin 43 | $(BIN2C) $@ $(OBJDIR)/game_tiles.tiles.bin $(OBJDIR)/game_bg.tiles.bin $(OBJDIR)/game_bg.map.bin 44 | 45 | $(OBJDIR): 46 | $(info $(shell mkdir -p $(MKDIRS))) 47 | 48 | clean: 49 | rm -r $(OBJDIR)/* 50 | rm $(TARGET) $(TARGET).elf 51 | 52 | -include $(DEPS) 53 | -------------------------------------------------------------------------------- /support/wfcommon.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # Copyright (c) 2022 Adrian "asie" Siekierka 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | from pathlib import Path 24 | import math 25 | import os 26 | import sys 27 | 28 | executable_location = Path(sys.argv[0]) 29 | if executable_location.is_file(): 30 | executable_location = executable_location.parent 31 | executable_extension = '' 32 | if os.name == 'nt': 33 | executable_extension = '.exe' 34 | 35 | def align_up_to(i, alignment: int): 36 | if isinstance(i, int): 37 | return int(math.ceil(i / alignment) * alignment) 38 | else: 39 | append_bytes = align_up_to(len(i), alignment) - len(i) 40 | return i + (b'\x00' * append_bytes) 41 | 42 | def power_of_two_up_to(i: int, min_size: int = None): 43 | if (min_size is not None) and (i < min_size): 44 | i = min_size 45 | i = int(2 ** math.ceil(math.log(i, 2))) 46 | return i -------------------------------------------------------------------------------- /examples/wswan/simple_image/Makefile: -------------------------------------------------------------------------------- 1 | ifndef WONDERFUL_TOOLCHAIN 2 | $(error Please define WONDERFUL_TOOLCHAIN to point to the location of the Wonderful toolchain.) 3 | endif 4 | include $(WONDERFUL_TOOLCHAIN)/i8086/wswan.mk 5 | 6 | TARGET := $(notdir $(shell pwd)).ws 7 | OBJDIR := obj 8 | RESDIR := res 9 | SRCDIRS := src 10 | MKDIRS := $(OBJDIR) 11 | LIBS := -llzsa -lws -lc -lgcc 12 | CFLAGS += -Os 13 | 14 | CSOURCES := $(foreach dir,$(SRCDIRS),$(notdir $(wildcard $(dir)/*.c))) 15 | ASMSOURCES := $(foreach dir,$(SRCDIRS),$(notdir $(wildcard $(dir)/*.S))) 16 | OBJECTS := $(CSOURCES:%.c=$(OBJDIR)/%.o) $(ASMSOURCES:%.S=$(OBJDIR)/%.o) 17 | CFLAGS += -I$(OBJDIR) 18 | 19 | DEPS := $(OBJECTS:.o=.d) 20 | CFLAGS += -MMD -MP 21 | 22 | vpath %.c $(SRCDIRS) 23 | vpath %.S $(SRCDIRS) 24 | 25 | .PHONY: all clean install 26 | 27 | all: $(TARGET) 28 | 29 | $(TARGET): $(OBJECTS) $(OBJDIR)/fs.bin 30 | $(SWANLINK) -v -o $@ -a $(OBJDIR)/fs.bin --output-elf $@.elf --linker-args $(LDFLAGS) $(WF_CRT0) $(OBJECTS) $(LIBS) 31 | 32 | $(OBJDIR)/fs.bin: $(OBJDIR)/image.tiles.bin.lzsa2 $(OBJDIR)/image.map.bin $(OBJDIR)/logo.tiles.bin 33 | $(FSBANKPACK) -v -o $@ $^ 34 | 35 | $(OBJDIR)/image.tiles.bin.lzsa2: $(RESDIR)/image.png | $(OBJDIR) 36 | $(SUPERFAMICONV) tiles -i $< -M ws -p $(RESDIR)/image.pal.bin -d $(OBJDIR)/image.tiles.bin 37 | $(SUPERFAMICONV) map -i $< -M ws -p $(RESDIR)/image.pal.bin -t $(OBJDIR)/image.tiles.bin -d $(OBJDIR)/image.map.bin 38 | $(LZSA) -r -f 2 $(OBJDIR)/image.tiles.bin $(OBJDIR)/image.tiles.bin.lzsa2 39 | 40 | $(OBJDIR)/logo.tiles.bin: $(RESDIR)/logo.png | $(OBJDIR) 41 | $(SUPERFAMICONV) tiles -i $< -M ws -D -F -p $(RESDIR)/image.pal.bin -d $(OBJDIR)/logo.tiles.bin 42 | 43 | $(OBJDIR)/%.o: %.c $(OBJDIR)/fs.bin | $(OBJDIR) 44 | $(CC) $(CFLAGS) -c -o $@ $< 45 | 46 | $(OBJDIR)/%.o: %.S $(OBJDIR)/fs.bin | $(OBJDIR) 47 | $(CC) $(CFLAGS) -c -o $@ $< 48 | 49 | $(OBJDIR): 50 | $(info $(shell mkdir -p $(MKDIRS))) 51 | 52 | clean: 53 | rm -r $(OBJDIR)/* 54 | rm $(TARGET) $(TARGET).elf 55 | 56 | -include $(DEPS) 57 | -------------------------------------------------------------------------------- /toolchain/fetch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . defs.sh 4 | 5 | fetch_http_tar () { 6 | if [ ! -f "$1" ] || [ ! tar tf "$1" >/dev/null 2>/dev/null ]; then 7 | echo "=== Downloading "$1"... ===" 8 | if [ -d "$2" ]; then 9 | rm -r "$2" 10 | fi 11 | rm -f "$1" 12 | if ! wget -O "$1" "$3"; then 13 | echo "Error!" 14 | exit 1 15 | fi 16 | fi 17 | if [ ! -d "$2" ]; then 18 | echo "=== Extracting "$1"... ===" 19 | if ! tar xf "$1"; then 20 | echo "Error!" 21 | exit 1 22 | fi 23 | fi 24 | } 25 | 26 | fetch_git () { 27 | if [ ! -d "$1" ]; then 28 | echo "=== Cloning "$1"... ===" 29 | if git clone "$2"; then 30 | return 0 31 | else 32 | echo "Error!" 33 | exit 1 34 | fi 35 | else 36 | echo "=== Updating "$1"... ===" 37 | cd "$1" 38 | if git pull; then 39 | cd ".." 40 | return 0 41 | else 42 | echo "Error!" 43 | exit 1 44 | fi 45 | fi 46 | } 47 | 48 | fetch_git_shallow () { 49 | if [ ! -d "$1" ]; then 50 | echo "=== Cloning "$1" (shallow)... ===" 51 | if git clone --depth=1 "$2"; then 52 | return 0 53 | else 54 | echo "Error!" 55 | exit 1 56 | fi 57 | else 58 | echo "=== Updating "$1" (shallow)... ===" 59 | cd "$1" 60 | if git pull --depth=1; then 61 | cd ".." 62 | return 0 63 | else 64 | echo "Error!" 65 | exit 1 66 | fi 67 | fi 68 | } 69 | 70 | fetch_git_shallow binutils-ia16 https://github.com/WonderfulToolchain/binutils-ia16 71 | fetch_git_shallow gcc-ia16 https://github.com/WonderfulToolchain/gcc-ia16 72 | fetch_git lzsa https://github.com/WonderfulToolchain/lzsa 73 | fetch_git SuperFamiconv https://github.com/WonderfulToolchain/SuperFamiconv 74 | fetch_http_tar gmp-$GMP_VERSION.tar.bz2 gmp-$GMP_VERSION https://gmplib.org/download/gmp/gmp-$GMP_VERSION.tar.bz2 75 | fetch_http_tar mpfr-$MPFR_VERSION.tar.bz2 mpfr-$MPFR_VERSION https://www.mpfr.org/mpfr-$MPFR_VERSION/mpfr-$MPFR_VERSION.tar.bz2 76 | fetch_http_tar mpc-$MPC_VERSION.tar.gz mpc-$MPC_VERSION https://ftp.gnu.org/gnu/mpc/mpc-$MPC_VERSION.tar.gz 77 | fetch_http_tar isl-$ISL_VERSION.tar.bz2 isl-$ISL_VERSION https://gcc.gnu.org/pub/gcc/infrastructure/isl-$ISL_VERSION.tar.bz2 78 | -------------------------------------------------------------------------------- /libws/include/ws/serial.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | /** \file serial.h 24 | * Functionality related to the serial port. 25 | */ 26 | 27 | #pragma once 28 | #include 29 | #include 30 | #include "hardware.h" 31 | #include "util.h" 32 | 33 | /** 34 | * @addtogroup SerialPort Functions - Serial port 35 | * @{ 36 | */ 37 | 38 | static inline void ws_serial_open(uint8_t baud_rate) { 39 | outportb(IO_SERIAL_STATUS, SERIAL_ENABLE | SERIAL_OVERRUN_RESET | baud_rate); 40 | } 41 | 42 | static inline void ws_serial_close(void) { 43 | outportb(IO_SERIAL_STATUS, 0x00); 44 | } 45 | 46 | static inline bool ws_serial_is_overrun(void) { 47 | return inportb(IO_SERIAL_STATUS) & SERIAL_OVERRUN; 48 | } 49 | 50 | static inline void ws_serial_ack_overrun(void) { 51 | outportb(IO_SERIAL_STATUS, inportb(IO_SERIAL_STATUS) | SERIAL_OVERRUN); 52 | } 53 | 54 | static inline bool ws_serial_is_readable(void) { 55 | return inportb(IO_SERIAL_STATUS) & SERIAL_RX_READY; 56 | } 57 | 58 | static inline bool ws_serial_is_writable(void) { 59 | return inportb(IO_SERIAL_STATUS) & SERIAL_TX_READY; 60 | } 61 | 62 | uint8_t ws_serial_getc(void); 63 | int16_t ws_serial_getc_nonblock(void); 64 | void ws_serial_putc(uint8_t value); 65 | 66 | /**@}*/ 67 | -------------------------------------------------------------------------------- /support/src/crt0.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | .arch i186 24 | .code16 25 | .intel_syntax noprefix 26 | 27 | .section .ivt 28 | .global _ivt 29 | _ivt: 30 | .fill 16, 4, 0 31 | 32 | .section .start 33 | .global _start 34 | _start: 35 | cli 36 | 37 | #ifdef __IA16_CMODEL_IS_FAR_TEXT 38 | // set DS to the location of rodata 39 | .byte 0xB8 40 | .reloc ., R_386_SEG16, "__erom!" 41 | .word 0 42 | mov ds, ax 43 | #endif 44 | 45 | // configure sp 46 | mov sp, offset "__eheap" 47 | 48 | // copy rodata/data from ROM to RAM 49 | xor ax, ax 50 | mov es, ax 51 | mov ss, ax 52 | mov si, offset "__erom&" 53 | mov di, offset "__sdata" 54 | mov cx, offset "__ldata_words" 55 | #ifndef __IA16_CMODEL_IS_FAR_TEXT 56 | // set DS to the location of rodata 57 | push cs 58 | pop ds 59 | #endif 60 | cld 61 | rep movsw 62 | 63 | // initialize segments 64 | // (es/ss) initialized above 65 | // xor ax, ax - done above 66 | mov ds, ax 67 | 68 | // clear int enable 69 | out 0xB2, al 70 | 71 | // clear bss 72 | mov di, offset "__edata" 73 | mov cx, offset "__lbss_words" 74 | rep stosw 75 | 76 | // configure default interrupt base 77 | mov al, 0x08 78 | out 0xB0, al 79 | 80 | #ifdef __IA16_CMODEL_IS_FAR_TEXT 81 | //.reloc .+3, R_386_SEG16, main 82 | //jmp 0:main 83 | .byte 0xEA 84 | .word main 85 | .reloc ., R_386_SEG16, "main!" 86 | .word 0 87 | #else 88 | jmp main 89 | #endif 90 | -------------------------------------------------------------------------------- /libc/include/string.h: -------------------------------------------------------------------------------- 1 | /** 2 | * wonderful-i8086 libc 3 | * 4 | * To the extent possible under law, the person who associated CC0 with 5 | * wonderful-i8086 libc has waived all copyright and related or neighboring rights 6 | * to wonderful-i8086 libc. 7 | * 8 | * You should have received a copy of the CC0 legalcode along with this 9 | * work. If not, see . 10 | */ 11 | 12 | #pragma once 13 | #include 14 | 15 | void __far* _fmemchr(const void __far* s, int c, size_t n); 16 | void* _nmemchr(const void* s, int c, size_t n); 17 | int _fmemcmp(const void __far* s1, const void __far* s2, size_t n); 18 | int _nmemcmp(const void* s1, const void* s2, size_t n); 19 | void __far* _fmemcpy(void __far* restrict s1, const void __far* restrict s2, size_t n); 20 | void* _nmemcpy(void* restrict s1, const void* restrict s2, size_t n); 21 | void __far* _fmemmove(void __far* s1, const void __far* s2, size_t n); 22 | void* _nmemmove(void* s1, const void* s2, size_t n); 23 | void __far* _fmemset(void __far* s, int c, size_t n); 24 | void* _nmemset(void* s, int c, size_t n); 25 | 26 | #ifdef __STRICT_ANSI__ 27 | void* memchr(const void* s, int c, size_t n); 28 | int memcmp(const void* s1, const void* s2, size_t n); 29 | void* memcpy(void* restrict s1, const void* restrict s2, size_t n); 30 | void* memmove(void* s1, const void* s2, size_t n); 31 | void* memset(void*s, int c, size_t n); 32 | #else 33 | // TODO: Can we use macros to automatically select between near and far variants for performance? 34 | #define memchr _fmemchr 35 | #define memcmp _fmemcmp 36 | #define memcpy _fmemcpy 37 | #define memmove _fmemmove 38 | #define memset _fmemset 39 | #endif 40 | 41 | char __far* strcat(char __far* s1, const char __far* s2); 42 | char __far* strchr(const char __far* s, int c); 43 | int strcmp(const char __far* s1, const char __far* s2); 44 | char __far* strcpy(char __far* s1, const char __far* s2); 45 | size_t strcspn(const char __far* s1, const char __far* s2); 46 | size_t strlen(const char __far* s); 47 | char __far* strncat(char __far* s1, const char __far* s2, size_t n); 48 | int strncmp(const char __far* s1, const char __far* s2, size_t n); 49 | char __far* strncpy(char __far* s1, const char __far* s2, size_t n); 50 | char __far* strpbrk(const char __far* s1, const char __far* s2); 51 | char __far* strrchr(const char __far* s, int c); 52 | size_t strspn(const char __far* s1, const char __far* s2); 53 | char __far* strstr(const char __far* s1, const char __far* s2); -------------------------------------------------------------------------------- /liblzsa/README.md: -------------------------------------------------------------------------------- 1 | # liblzsa 2 | 3 | Library for decompressing binary data packed with [LZSA1 and/or LZSA2](https: github.com/emmanuel-marty/lzsa/). 4 | 5 | There are two variants provided: 6 | 7 | * `-llzsa`: default, optimized for speed, 8 | * `-llzsa_small`: alternate, optimized for size (~130-200 bytes smaller per algorithm). 9 | 10 | ## License 11 | 12 | Both variants are licensed under the terms of the zlib license, however the notices differ: 13 | 14 | ### liblzsa.a 15 | 16 | Copyright (C) 2019 Jim Leonard, Emmanuel Marty 17 | 18 | This software is provided 'as-is', without any express or implied 19 | warranty. In no event will the authors be held liable for any damages 20 | arising from the use of this software. 21 | 22 | Permission is granted to anyone to use this software for any purpose, 23 | including commercial applications, and to alter it and redistribute it 24 | freely, subject to the following restrictions: 25 | 26 | 1. The origin of this software must not be misrepresented; you must not 27 | claim that you wrote the original software. If you use this software 28 | in a product, an acknowledgment in the product documentation would be 29 | appreciated but is not required. 30 | 2. Altered source versions must be plainly marked as such, and must not be 31 | misrepresented as being the original software. 32 | 3. This notice may not be removed or altered from any source distribution. 33 | 34 | ### liblzsa_small.a 35 | 36 | Copyright (C) 2019 Emmanuel Marty 37 | 38 | This software is provided 'as-is', without any express or implied 39 | warranty. In no event will the authors be held liable for any damages 40 | arising from the use of this software. 41 | 42 | Permission is granted to anyone to use this software for any purpose, 43 | including commercial applications, and to alter it and redistribute it 44 | freely, subject to the following restrictions: 45 | 46 | 1. The origin of this software must not be misrepresented; you must not 47 | claim that you wrote the original software. If you use this software 48 | in a product, an acknowledgment in the product documentation would be 49 | appreciated but is not required. 50 | 2. Altered source versions must be plainly marked as such, and must not be 51 | misrepresented as being the original software. 52 | 3. This notice may not be removed or altered from any source distribution. 53 | -------------------------------------------------------------------------------- /support/wwitch.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-i386") 2 | ENTRY(_start) 3 | SECTIONS 4 | { 5 | /* segelf segment start markers for target text section. */ 6 | ".text!" . (NOLOAD) : 7 | { 8 | "__stext!" = .; 9 | KEEP(*(".crt0!")) 10 | *(".text!*" ".text.*!") 11 | *(".fartext!*" ".fartext.*!") 12 | *(".farrodata!*" ".farrodata.*!") 13 | "__etext!" = .; 14 | } 15 | 16 | /* Target text section. */ 17 | .text . : 18 | { 19 | __stext = .; 20 | KEEP(*(".crt0")) 21 | *(.text ".text.*[^&]") 22 | *(".fartext.*[^&]") 23 | *(".farrodata.*[^&]") 24 | __etext = .; 25 | } 26 | 27 | /* segelf segment end markers for target text section. */ 28 | ".text&" . (NOLOAD) : 29 | { 30 | "__stext&" = .; 31 | KEEP(*(".crt0&")) 32 | *(".text&*" ".text.*&") 33 | *(".fartext&*" ".fartext.*&") 34 | *(".farrodata&*" ".farrodata.*&") 35 | "__etext&" = .; 36 | . = ALIGN (16); 37 | } 38 | 39 | .erom . (NOLOAD) : 40 | { 41 | . = ALIGN (16); 42 | "__erom" = .; 43 | "__erom!" = .; 44 | "__erom&" = .; 45 | . = .; 46 | } 47 | 48 | /* segelf segment start markers for target data section. */ 49 | ".data!" 0x10000 (NOLOAD) : AT(ADDR(".erom") + SIZEOF(".erom")) 50 | { 51 | "__sdata!" = .; 52 | KEEP(*(".crt0_data!")) 53 | *(".rodata!*" ".rodata.*!") 54 | *(".data!*" ".data.*!") 55 | *(".bss!*" ".bss.*!") 56 | "__edata!" = .; 57 | "__ebss!" = .; 58 | } 59 | 60 | /* Target data section. */ 61 | ".data" 0x10000: AT(ADDR(".erom") + SIZEOF(".erom")) 62 | { 63 | __sdata = .; 64 | KEEP(*(".crt0_data")) 65 | *(.rodata ".rodata.*[^&]") 66 | *(.data ".data.*[^&]") 67 | . = ALIGN (4); 68 | __edata = .; 69 | } 70 | "__ldata!" = 0; 71 | __ldata = SIZEOF(.data); 72 | "__ldata_words!" = 0; 73 | __ldata_words = (__ldata + 1) / 2; 74 | 75 | /* Target BSS section, with same segment bases as data section. */ 76 | .bss . (NOLOAD) : 77 | { 78 | *(.bss ".bss.*[^&]") 79 | . = ALIGN (4); 80 | __ebss = .; 81 | } 82 | _heap = .; /* TODO: Is this a WWitch symbol? */ 83 | "__lbss!" = 0; 84 | __lbss = SIZEOF(.bss); 85 | "__lbss_words!" = 0; 86 | __lbss_words = (__lbss + 1) / 2; 87 | 88 | /* segelf segment end markers for target data section. */ 89 | ".data&" . (NOLOAD) : 90 | { 91 | "__sdata&" = .; 92 | KEEP(*(".crt0_data&")) 93 | *(".rodata&*" ".rodata.*&") 94 | *(".data&*" ".data.*&") 95 | *(".bss&*" ".bss.*&") 96 | "__edata&" = .; 97 | "__ebss& " = .; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /libws/include/ws/rtc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | /** \file rtc.h 24 | * Functionality related to the cartridge RTC. 25 | */ 26 | 27 | #pragma once 28 | #include 29 | #include 30 | #include "hardware.h" 31 | #include "util.h" 32 | 33 | /** 34 | * @addtogroup RTC Functions - RTC 35 | * @{ 36 | */ 37 | 38 | #define RTC_MONTH_AMPM 0x80 39 | #define RTC_MONTH_AM 0x80 40 | #define RTC_MONTH_PM 0x80 41 | 42 | typedef struct { 43 | uint8_t year; 44 | uint8_t month; 45 | uint8_t date; 46 | uint8_t day; 47 | } ws_rtc_date_t; 48 | 49 | typedef struct { 50 | uint8_t hour; 51 | uint8_t minute; 52 | uint8_t second; 53 | } ws_rtc_time_t; 54 | 55 | typedef struct { 56 | ws_rtc_date_t date; 57 | ws_rtc_time_t time; 58 | } ws_rtc_datetime_t; 59 | 60 | #define RTC_STATUS_POWER_LOST 0x80 61 | #define RTC_STATUS_12_HOUR 0x00 62 | #define RTC_STATUS_24_HOUR 0x40 63 | #define RTC_STATUS_INTAE 0x20 64 | #define RTC_STATUS_INTME 0x08 65 | #define RTC_STATUS_INTFE 0x02 66 | #define RTC_STATUS_INT_OFF 0 67 | #define RTC_STATUS_INT_FREQ_STEADY (RTC_STATUS_INTFE) 68 | #define RTC_STATUS_INT_MINUTE_EDGE (RTC_STATUS_INTME) 69 | #define RTC_STATUS_INT_MINUTE_STEADY (RTC_STATUS_INTME | RTC_STATUS_INTFE) 70 | #define RTC_STATUS_INT_ALARM (RTC_STATUS_INTAE) 71 | 72 | int16_t ws_rtc_low_read_byte(uint16_t timeout); 73 | bool ws_rtc_low_write_byte(uint8_t value, uint16_t timeout); 74 | bool ws_rtc_low_write_ctrl(uint8_t value, uint16_t timeout); 75 | 76 | // TODO: high-level commands 77 | 78 | /**@}*/ 79 | -------------------------------------------------------------------------------- /libws/include/ws/dma.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | /** \file dma.h 24 | * Functionality related to DMA transfers. 25 | */ 26 | 27 | #pragma once 28 | #include 29 | #include "hardware.h" 30 | #include "util.h" 31 | 32 | /** 33 | * @addtogroup DMA Functions - DMA 34 | * @{ 35 | */ 36 | 37 | /** 38 | * @brief Copy words from a source linear address to a destination pointer using DMA. 39 | * 40 | * Note that this only works if Color mode is enabled - see @ref system_is_color 41 | * 42 | * @param dest Destination pointer, in RAM. 43 | * @param src Source linear (20-bit) address. 44 | * @param length Length, in bytes. Must be a multiple of 2. 45 | */ 46 | void ws_dma_copy_words_linear(void *dest, uint32_t src, uint16_t length); 47 | 48 | /** 49 | * @brief Copy words from a source pointer to a destination pointer using DMA. 50 | * 51 | * Note that this only works if Color mode is enabled - see @ref system_is_color 52 | * 53 | * @param dest Destination pointer, in RAM. 54 | * @param src Source pointer, in any location. 55 | * @param length Length, in bytes. Must be a multiple of 2. 56 | */ 57 | static inline void ws_dma_copy_words(void *dest, const void __far* src, uint16_t length) { 58 | ws_dma_copy_words_linear(dest, (((uint32_t) src) >> 12) + ((uint16_t) ((uint32_t) src)), length); 59 | } 60 | 61 | /** 62 | * @brief Copy words from a source pointer to a destination pointer, using DMA if present. 63 | * 64 | * @param dest Destination pointer, in RAM. 65 | * @param src Source pointer, in any location. 66 | * @param length Length, in bytes. Must be a multiple of 2. 67 | */ 68 | void ws_dma_opt_copy_words(void *dest, const void __far* src, uint16_t length); 69 | 70 | /**@}*/ 71 | -------------------------------------------------------------------------------- /libws/src/eeprom/eeprom_utils.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #include 24 | 25 | .arch i186 26 | .code16 27 | .intel_syntax noprefix 28 | 29 | // DL = port, DH = dwords (bits - 2) 30 | // BL = SB/opcode/subop 31 | // AX = address, in bytes 32 | // returns AX = command 33 | // trashes BX, CL + clears DH 34 | .global ws_eeprom_internal_addr_to_command 35 | ws_eeprom_internal_addr_to_command: 36 | shr ax, 1 37 | mov cl, dh 38 | xor dh, dh 39 | xor bh, bh 40 | cmp bl, 0x14 // 0x10-0x13 => address-free commands 41 | jae ws_eeprom_internal_addr_to_command_address 42 | xor ax, ax 43 | ws_eeprom_internal_addr_to_command_address: 44 | shl bx, cl 45 | or ax, bx 46 | ret 47 | 48 | // AL = 1 if IEEP ready, 0 otherwise 49 | // trashes CX, DX 50 | .global ws_eeprom_internal_wait_ready 51 | ws_eeprom_internal_wait_ready: 52 | // Cartridge EEPROM requires a slight delay here. 53 | mov cx, 50 54 | ws_eeprom_internal_wait_ready_l0: 55 | loop ws_eeprom_internal_wait_ready_l0 56 | mov cx, 3413 // 10 ms / 9 cycles at 3 MHz 57 | ws_eeprom_internal_wait_ready_l1: 58 | in ax, dx // 6 59 | test al, 0x02 // 1 60 | jnz ws_eeprom_internal_wait_ready_ok // 1 61 | loop ws_eeprom_internal_wait_ready_l1 // 1 62 | mov al, 1 63 | ret 64 | ws_eeprom_internal_wait_ready_ok: 65 | xor al, al 66 | ret 67 | 68 | // AL = 1 if IEEP done, 0 otherwise 69 | // trashes CX, DX 70 | .global ws_eeprom_internal_wait_done 71 | ws_eeprom_internal_wait_done: 72 | // Cartridge EEPROM requires a slight delay here. 73 | mov cx, 50 74 | ws_eeprom_internal_wait_done_l0: 75 | loop ws_eeprom_internal_wait_done_l0 76 | mov cx, 50 77 | ws_eeprom_internal_wait_done_l1: 78 | in ax, dx // 6 79 | and al, 0x01 // 1 80 | jnz ws_eeprom_internal_wait_done_ok // 1 81 | loop ws_eeprom_internal_wait_done_l1 // 1 82 | ws_eeprom_internal_wait_done_ok: 83 | ret 84 | -------------------------------------------------------------------------------- /examples/wswan/simple_image/src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | * To the extent possible under law, the person who associated CC0 with 3 | * this example has waived all copyright and related or neighboring rights 4 | * to this example. 5 | * 6 | * You should have received a copy of the CC0 legalcode along with this 7 | * work. If not, see . 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "fs.h" 16 | 17 | ws_sprite_t sprites[12] __attribute__((aligned(0x200))); 18 | uint16_t screen[0x400] __attribute__((aligned(0x800))); 19 | 20 | const uint8_t __far sin_table[] = { 21 | 40, 42, 44, 46, 48, 50, 52, 53, 55, 57, 59, 61, 62, 64, 65, 67, 68, 70, 71, 72, 73, 74, 75, 76, 77, 78, 78, 79, 79, 80, 80, 80, 80, 80, 80, 80, 79, 79, 78, 78, 77, 76, 75, 74, 73, 72, 71, 70, 68, 67, 65, 64, 62, 61, 59, 57, 55, 53, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 27, 25, 23, 21, 19, 18, 16, 15, 13, 12, 10, 9, 8, 7, 6, 5, 4, 3, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 15, 16, 18, 19, 21, 23, 25, 27, 28, 30, 32, 34, 36, 38 22 | }; 23 | 24 | void main() { 25 | // Configure shade LUT 26 | ws_display_set_shade_lut(SHADE_LUT_DEFAULT); 27 | // Configure palettes 28 | outportw(IO_SCR_PAL_0, 0x7520); 29 | outportw(IO_SPR_PAL_4, MONO_PAL_COLORS(0, 0, 0, 1)); 30 | outportw(IO_SPR_PAL_5, MONO_PAL_COLORS(0, 0, 0, 6)); 31 | 32 | // Copy tiles (image) 33 | lzsa2_decompress(MEM_TILE(0), wf_asset_map(ASSET_IMAGE_TILES_BIN_LZSA2)); 34 | 35 | // Copy screen map (image) 36 | ws_screen_put_map(screen, wf_asset_map(ASSET_IMAGE_MAP_BIN), 0, 0, 28, 28); 37 | 38 | // Configure SCR1 memory location and initial Y scroll. 39 | outportb(IO_SCR_BASE, SCR1_BASE((uint16_t)screen)); 40 | outportb(IO_SCR1_SCRL_Y, sin_table[0]); 41 | 42 | // Copy tiles (logo) 43 | memcpy(MEM_TILE(512 - 6), 44 | wf_asset_map(ASSET_LOGO_TILES_BIN), 45 | ASSET_LOGO_TILES_BIN_SIZE); 46 | 47 | // Configure sprites. 48 | for (int i = 0; i < 12; i++) { 49 | sprites[i].x = 222 - 8 - ((5 - (i % 6)) << 3); 50 | sprites[i].y = 142 - 8; 51 | sprites[i].palette = 4; 52 | if (i >= 6) { 53 | sprites[i].x++; 54 | sprites[i].y++; 55 | sprites[i].palette++; 56 | } 57 | sprites[i].tile = 512 - 6 + (i % 6); 58 | sprites[i].flip_h = false; 59 | sprites[i].flip_v = false; 60 | } 61 | outportb(IO_SPR_BASE, SPR_BASE((uint16_t)sprites)); 62 | outportb(IO_SPR_FIRST, 0); 63 | outportb(IO_SPR_COUNT, 12); 64 | 65 | // Enable SCR1 and SPR. 66 | outportw(IO_DISPLAY_CTRL, DISPLAY_SCR1_ENABLE | DISPLAY_SPR_ENABLE); 67 | 68 | uint8_t pos = 0; 69 | 70 | while (1) { 71 | // TODO: better vblank wait 72 | while (inportb(IO_LCD_LINE) != 144); 73 | pos++; 74 | 75 | outportb(IO_SCR1_SCRL_Y, sin_table[pos >> 1]); 76 | 77 | while (inportb(IO_LCD_LINE) == 144); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /support/wswan.ld.template: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-i386") 2 | ENTRY(_start) 3 | MEMORY 4 | { 5 | ROM (rx) : ORIGIN = %ROM_AREA_START%, LENGTH = %ROM_AREA_LENGTH% 6 | RAM (wx) : ORIGIN = %RAM_HEAP_START%, LENGTH = %RAM_HEAP_LENGTH% 7 | } 8 | SECTIONS 9 | { 10 | /* segelf segment start markers for target text section. */ 11 | ".text!" %ROM_AREA_START% (NOLOAD) : 12 | { 13 | "__stext!" = .; 14 | KEEP(*(".start!")) 15 | *(".text!*" ".text.*!") 16 | "__etext!" = .; 17 | } >ROM 18 | 19 | /* Target text section. */ 20 | .text . : 21 | { 22 | __stext = .; 23 | KEEP(*(".start")) 24 | *(.text ".text.*[^&]") 25 | __etext = .; 26 | . = ALIGN (16); 27 | } 28 | 29 | "__rom_bank_offset!" = 0; 30 | "__rom_bank_offset" = ABSOLUTE(%ROM_BANK_OFFSET%); 31 | 32 | /* segelf segment end markers for target text section. */ 33 | ".text&" . (NOLOAD) : 34 | { 35 | "__stext&" = .; 36 | KEEP(*(".start&")) 37 | *(".text&*" ".text.*&") 38 | "__etext&" = .; 39 | } 40 | 41 | .fartext ALIGN (0x10) : SUBALIGN (0x10) { 42 | *(SORT (".fartext!*")) 43 | *(SORT (".fartext$*")) 44 | *(SORT (".fartext&*")) 45 | *(SORT (".fartext.*")) 46 | . = .; 47 | } 48 | 49 | .farrodata ALIGN (0x10) : SUBALIGN (0x10) { 50 | *(SORT (".farrodata!*")) 51 | *(SORT (".farrodata$*")) 52 | *(SORT (".farrodata&*")) 53 | *(SORT (".farrodata.*")) 54 | . = .; 55 | } 56 | 57 | .erom . (NOLOAD) : 58 | { 59 | . = ALIGN (16); 60 | "__erom" = .; 61 | "__erom!" = .; 62 | "__erom&" = .; 63 | . = .; 64 | } 65 | 66 | /* segelf segment start markers for target data section. */ 67 | ".data!" %RAM_HEAP_START% (NOLOAD) : AT(ADDR(".erom") + SIZEOF(".erom")) 68 | { 69 | "__sdata!" = .; 70 | KEEP(*(".ivt!")) 71 | *(".rodata!*" ".rodata.*!") 72 | *(".data!*" ".data.*!") 73 | *(".bss!*" ".bss.*!") 74 | "__edata!" = .; 75 | "__ebss!" = .; 76 | } >RAM 77 | 78 | /* IVT header - we don't want to store it in ROM. */ 79 | .ivt %RAM_HEAP_START% (NOLOAD) : 80 | { 81 | KEEP(*(.ivt)) 82 | } 83 | 84 | /* Target data section. */ 85 | __sdata = .; 86 | ".data" . : AT(ADDR(".erom") + SIZEOF(".erom")) 87 | { 88 | *(.rodata ".rodata.*[^&]") 89 | *(.data ".data.*[^&]") 90 | } 91 | __edata = .; 92 | "__ldata!" = 0; 93 | __ldata = SIZEOF(.data); 94 | "__ldata_words!" = 0; 95 | __ldata_words = (__ldata + 1) / 2; 96 | 97 | __sbss = .; 98 | /* Target BSS section. */ 99 | .bss . (NOLOAD) : 100 | { 101 | *(.bss ".bss.*[^&]") 102 | } 103 | __ebss = .; 104 | "__lbss!" = 0; 105 | __lbss = SIZEOF(.bss); 106 | "__lbss_words!" = 0; 107 | __lbss_words = (__lbss + 1) / 2; 108 | 109 | /* segelf segment end markers for target data section. */ 110 | ".data&" . (NOLOAD) : 111 | { 112 | "__sdata&" = .; 113 | KEEP(*(".ivt&")) 114 | *(".rodata&*" ".rodata.*&") 115 | *(".data&*" ".data.*&") 116 | *(".bss&*" ".bss.*&") 117 | "__edata&" = .; 118 | "__ebss& " = .; 119 | } 120 | 121 | "__eheap!" = 0; 122 | __eheap = %RAM_HEAP_LENGTH%; 123 | } 124 | -------------------------------------------------------------------------------- /libww/include/sys/key.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | /** \file sys/key.h 24 | * FreyaBIOS keypad calls. 25 | */ 26 | 27 | #pragma once 28 | #include 29 | 30 | /** 31 | * @addtogroup Int11 BIOS - INT 11h - Keypad 32 | * @{ 33 | */ 34 | 35 | #define KEY_Y4 0x0800 36 | #define KEY_Y3 0x0400 37 | #define KEY_Y2 0x0200 38 | #define KEY_Y1 0x0100 39 | #define KEY_X4 0x0080 40 | #define KEY_X3 0x0040 41 | #define KEY_X2 0x0020 42 | #define KEY_X1 0x0010 43 | #define KEY_B 0x0008 44 | #define KEY_A 0x0004 45 | #define KEY_START 0x0002 46 | 47 | #define KEY_UP1 KEY_X1 48 | #define KEY_RIGHT1 KEY_X2 49 | #define KEY_DOWN1 KEY_X3 50 | #define KEY_LEFT1 KEY_X4 51 | #define KEY_UP2 KEY_Y1 52 | #define KEY_RIGHT2 KEY_Y2 53 | #define KEY_DOWN2 KEY_Y3 54 | #define KEY_LEFT2 KEY_Y4 55 | 56 | static inline uint16_t key_press_check(void) { 57 | uint16_t result; 58 | __asm volatile ( 59 | "int $0x11" 60 | : "=a" (result) 61 | : "Rah" ((uint8_t) 0x00) 62 | : "cc", "memory" 63 | ); 64 | return result; 65 | } 66 | 67 | static inline uint16_t key_hit_check(void) { 68 | uint16_t result; 69 | __asm volatile ( 70 | "int $0x11" 71 | : "=a" (result) 72 | : "Rah" ((uint8_t) 0x01) 73 | : "cc", "memory" 74 | ); 75 | return result; 76 | } 77 | 78 | static inline uint16_t key_wait(void) { 79 | uint16_t result; 80 | __asm volatile ( 81 | "int $0x11" 82 | : "=a" (result) 83 | : "Rah" ((uint8_t) 0x02) 84 | : "cc", "memory" 85 | ); 86 | return result; 87 | } 88 | 89 | static inline void key_set_repeat(uint8_t rate, uint8_t delay) { 90 | uint16_t ax_clobber; 91 | __asm volatile ( 92 | "int $0x11" 93 | : "=a" (ax_clobber) 94 | : "Rah" ((uint8_t) 0x03), "b" ((delay << 8) | rate) 95 | : "cc", "memory" 96 | ); 97 | } 98 | 99 | // TODO: key_get_repeat (0x04) 100 | 101 | static inline uint16_t key_hit_check_with_repeat(void) { 102 | uint16_t result; 103 | __asm volatile ( 104 | "int $0x11" 105 | : "=a" (result) 106 | : "Rah" ((uint8_t) 0x05) 107 | : "cc", "memory" 108 | ); 109 | return result; 110 | } 111 | 112 | /**@}*/ -------------------------------------------------------------------------------- /support/Makefile: -------------------------------------------------------------------------------- 1 | ifndef WONDERFUL_TOOLCHAIN 2 | $(error Please define WONDERFUL_TOOLCHAIN to point to the location of the Wonderful toolchain.) 3 | endif 4 | WONDERFUL_TARGET := wswan 5 | include $(WONDERFUL_TOOLCHAIN)/i8086/wonderful-i8086.mk 6 | 7 | OBJDIR := obj 8 | SRCDIRS := src 9 | MKDIRS := $(OBJDIR) 10 | 11 | OBJECTS := $(OBJDIR)/crt0.o \ 12 | $(OBJDIR)/crt0_ww_asc1.o \ 13 | $(OBJDIR)/crt0_ww_asc2.o \ 14 | $(OBJDIR)/crt0_ww_jpn1.o \ 15 | $(OBJDIR)/crt0_ww_jpn2.o 16 | 17 | vpath %.c $(SRCDIRS) 18 | vpath %.S $(SRCDIRS) 19 | 20 | .PHONY: all clean install 21 | 22 | all: $(OBJECTS) 23 | 24 | $(OBJDIR)/%.o: %.c $(OBJDIR) 25 | $(CC) $(CFLAGS) -mcmodel=medium -c -o $@ $< 26 | 27 | $(OBJDIR)/%.o: %.S $(OBJDIR) 28 | $(CC) $(CFLAGS) -mcmodel=medium -c -o $@ $< 29 | 30 | $(OBJDIR)/crt0_ww_asc1.o: crt0_ww.S $(OBJDIR) 31 | $(CC) $(CFLAGS) -mcmodel=small -DDISPLAY_MODE_ASCII1 -c -o $@ $< 32 | 33 | $(OBJDIR)/crt0_ww_asc2.o: crt0_ww.S $(OBJDIR) 34 | $(CC) $(CFLAGS) -mcmodel=small -DDISPLAY_MODE_ASCII2 -c -o $@ $< 35 | 36 | $(OBJDIR)/crt0_ww_jpn1.o: crt0_ww.S $(OBJDIR) 37 | $(CC) $(CFLAGS) -mcmodel=small -DDISPLAY_MODE_JAPANESE1 -c -o $@ $< 38 | 39 | $(OBJDIR)/crt0_ww_jpn2.o: crt0_ww.S $(OBJDIR) 40 | $(CC) $(CFLAGS) -mcmodel=small -DDISPLAY_MODE_JAPANESE2 -c -o $@ $< 41 | 42 | $(OBJDIR): 43 | $(info $(shell mkdir -p $(MKDIRS))) 44 | 45 | clean: 46 | rm $(OBJECTS) 47 | 48 | install: $(OBJECTS) 49 | install -d $(WONDERFUL_TOOLCHAIN)/i8086/wswan/include 50 | install -d $(WONDERFUL_TOOLCHAIN)/i8086/wswan/lib 51 | install -d $(WONDERFUL_TOOLCHAIN)/i8086/wwitch/include 52 | install -d $(WONDERFUL_TOOLCHAIN)/i8086/wwitch/lib 53 | install -m 644 $(OBJDIR)/crt0.o $(WONDERFUL_TOOLCHAIN)/i8086/wswan/lib/crt0.o 54 | install -m 644 $(OBJDIR)/crt0_ww_asc1.o $(WONDERFUL_TOOLCHAIN)/i8086/wwitch/lib/crt0_asc1.o 55 | install -m 644 $(OBJDIR)/crt0_ww_asc2.o $(WONDERFUL_TOOLCHAIN)/i8086/wwitch/lib/crt0_asc2.o 56 | install -m 644 $(OBJDIR)/crt0_ww_jpn1.o $(WONDERFUL_TOOLCHAIN)/i8086/wwitch/lib/crt0_jpn1.o 57 | install -m 644 $(OBJDIR)/crt0_ww_jpn2.o $(WONDERFUL_TOOLCHAIN)/i8086/wwitch/lib/crt0_jpn2.o 58 | install -m 644 wswan.ld.template $(WONDERFUL_TOOLCHAIN)/i8086/wswan/lib 59 | install -m 644 wonderful-i8086.mk $(WONDERFUL_TOOLCHAIN)/i8086 60 | install -m 644 wswan.mk $(WONDERFUL_TOOLCHAIN)/i8086 61 | install -m 644 wwitch.mk $(WONDERFUL_TOOLCHAIN)/i8086 62 | install -m 644 wwitch.ld $(WONDERFUL_TOOLCHAIN)/i8086/wwitch/lib 63 | install -m 755 bin2c.py $(WONDERFUL_TOOLCHAIN)/i8086/bin/wf-bin2c 64 | install -m 755 fsbankpack.py $(WONDERFUL_TOOLCHAIN)/i8086/bin/wf-fsbankpack 65 | install -m 755 mkfent.py $(WONDERFUL_TOOLCHAIN)/i8086/bin/wf-mkfent 66 | install -m 755 swanlink.py $(WONDERFUL_TOOLCHAIN)/i8086/bin/wf-swanlink 67 | install -m 755 wfcommon.py $(WONDERFUL_TOOLCHAIN)/i8086/bin/wfcommon.py 68 | install -m 644 src/wonderful-asm-wswan.h $(WONDERFUL_TOOLCHAIN)/i8086/wswan/include/wonderful-asm.h 69 | install -m 644 src/wonderful-asm-wwitch.h $(WONDERFUL_TOOLCHAIN)/i8086/wwitch/include/wonderful-asm.h 70 | install -m 644 src/wonderful-asm-common.h $(WONDERFUL_TOOLCHAIN)/i8086/wswan/include 71 | install -m 644 src/wonderful-asm-common.h $(WONDERFUL_TOOLCHAIN)/i8086/wwitch/include 72 | install -m 644 src/wonderful-wswan.h $(WONDERFUL_TOOLCHAIN)/i8086/wswan/include/wonderful.h 73 | install -m 644 src/wonderful-wwitch.h $(WONDERFUL_TOOLCHAIN)/i8086/wwitch/include/wonderful.h 74 | -------------------------------------------------------------------------------- /support/bin2c.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | # 3 | # Copyright (c) 2022 Adrian Siekierka 4 | # 5 | # Permission to use, copy, modify, and/or distribute this software for any 6 | # purpose with or without fee is hereby granted. 7 | # 8 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 11 | # SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER 12 | # RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF 13 | # CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 14 | # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | 16 | from collections import OrderedDict 17 | from datetime import datetime 18 | from pathlib import Path 19 | from wfcommon import * 20 | import argparse 21 | import re 22 | import struct 23 | import sys 24 | 25 | OUTPUT_TYPES = [ 26 | ('int8', 'b', 1), 27 | ('uint8', 'B', 1), 28 | ('int16', 'h', 2), 29 | ('uint16', 'H', 2), 30 | ('int32', 'i', 4), 31 | ('uint32', 'I', 4) 32 | ] 33 | OUTPUT_TYPE_KEYS = {x[0]:x for x in OUTPUT_TYPES} 34 | 35 | def main(args): 36 | current_date_str = datetime.now().strftime("%Y-%m-%d %H:%M:%S") 37 | far_prefix = "" if args.near else "__far " 38 | attribute_suffix = "" 39 | if args.align is not None: 40 | attribute_suffix = f" __attribute__((aligned({args.align})))" 41 | files = OrderedDict() 42 | for input_str in args.input: 43 | inp = input_str.split(":", maxsplit=3) 44 | out_type = None 45 | if (len(inp) >= 2) and (inp[-1] in OUTPUT_TYPE_KEYS): 46 | out_type = OUTPUT_TYPE_KEYS[inp[-1]] 47 | inp = inp[:-1] 48 | if len(inp) >= 2: 49 | file_name = inp[1] 50 | file_key = inp[0] 51 | else: 52 | file_name = inp[0] 53 | file_key = re.sub(r"[^a-zA-Z0-9]", "_", Path(file_name).name) 54 | with open(file_name, "rb") as f: 55 | data = f.read() 56 | if out_type is not None: 57 | if len(data) != out_type[2]: 58 | raise Exception(f"invalid length for type {out_type[0]}: {len(data)} bytes != {out_type[2]} bytes") 59 | files[file_key] = int(struct.unpack(f'<{out_type[1]}', data)[0]) 60 | else: 61 | files[file_key] = bytearray(data) 62 | 63 | # generate header file 64 | header_name = Path(args.output).with_suffix('.h') 65 | if args.header is not None: 66 | header_name = args.header 67 | with open(header_name, "w") as f: 68 | f.write(f"// autogenerated by bin2c.py on {current_date_str}\n") 69 | f.write("#pragma once\n") 70 | f.write("#include \n") 71 | for field_name, data in files.items(): 72 | f.write("\n") 73 | if isinstance(data, int): 74 | f.write("#define %s %d\n" % (field_name, data)) 75 | else: 76 | f.write("#define %s_size %d\n" % (field_name, len(data))) 77 | f.write("extern const uint8_t %s%s[%s_size];\n" % (far_prefix, field_name, field_name)) 78 | 79 | # generate C file 80 | line_step = 16 81 | with open(args.output, "w") as f: 82 | f.write(f"// autogenerated by bin2c.py on {current_date_str}\n") 83 | f.write("#include \n") 84 | for field_name, data in files.items(): 85 | if not isinstance(data, int): 86 | f.write("\n") 87 | f.write("const uint8_t %s%s[] = {\n" % (far_prefix, field_name)) 88 | for i in range(0, len(data), line_step): 89 | data_part = data[i:(i + line_step)] 90 | data_part_str = ", ".join([str(x) for x in data_part]) 91 | if (i + line_step) < len(data): 92 | f.write("\t%s, // %d\n" % (data_part_str, i)) 93 | else: 94 | f.write("\t%s // %d\n" % (data_part_str, i)) 95 | f.write("}%s;\n" % attribute_suffix) 96 | 97 | if __name__ == '__main__': 98 | args_parser = argparse.ArgumentParser( 99 | description="Convert a collection of binary files to a .c/.h pair" 100 | ) 101 | args_parser.add_argument("--header", metavar="output.h", help="Output header file. If not provided, will be in the same location as the output C file.") 102 | args_parser.add_argument("--align", type=int, help="Force alignment in the compiler.") 103 | args_parser.add_argument("--near", action="store_true", help="If present, do not emit __far keyword.") 104 | args_parser.add_argument("output", help="Output C file.") 105 | args_parser.add_argument("input", nargs="+", help="Input binary files. Can be of the form 'file.bin', 'file_bin:file.bin', 'file.bin:int8' or 'file_bin:file.bin:int8'.") 106 | args = args_parser.parse_args() 107 | main(args) 108 | -------------------------------------------------------------------------------- /support/src/crt0_ww.S: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | .arch i8086 24 | .code16 25 | .intel_syntax noprefix 26 | 27 | #define DCM_SCR1 0x0001 28 | #define DCM_SCR2 0x0002 29 | #define DCM_SPR 0x0004 30 | 31 | #define TEXT_MODE_ANK 0 32 | #define TEXT_MODE_ANK_SJIS 1 33 | #define TEXT_MODE_SJIS 2 34 | 35 | #if defined(DISPLAY_MODE_JAPANESE2) 36 | # define DISPLAY_CONTROL_VAL (DCM_SCR1 | DCM_SCR2) 37 | # define SCR1_ADDR 0x1000 38 | # define SCR2_ADDR 0x1800 39 | # define SPR_ADDR 0xe00 40 | # define STACK_ADDR 0xe00 41 | # define TEXT_MODE TEXT_MODE_ANK_SJIS 42 | #elif defined(DISPLAY_MODE_JAPANESE1) 43 | # define DISPLAY_CONTROL_VAL (DCM_SCR2) 44 | # define SCR1_ADDR 0x1800 45 | # define SCR2_ADDR 0x1800 46 | # define SPR_ADDR 0x1600 47 | # define STACK_ADDR 0x1600 48 | # define TEXT_MODE TEXT_MODE_ANK_SJIS 49 | #elif defined(DISPLAY_MODE_ASCII2) 50 | # define DISPLAY_CONTROL_VAL (DCM_SCR1 | DCM_SCR2) 51 | # define SCR1_ADDR 0x3000 52 | # define SCR2_ADDR 0x2800 53 | # define SPR_ADDR 0x2600 54 | # define STACK_ADDR 0x2600 55 | # define TEXT_MODE TEXT_MODE_ANK 56 | #elif defined(DISPLAY_MODE_ASCII1) 57 | # define DISPLAY_CONTROL_VAL (DCM_SCR2) 58 | # define SCR1_ADDR 0x3000 59 | # define SCR2_ADDR 0x3000 60 | # define SPR_ADDR 0x2e00 61 | # define STACK_ADDR 0x2e00 62 | # define TEXT_MODE TEXT_MODE_ANK_SJIS 63 | #else 64 | # error Must specify DISPLAY_MODE! 65 | #endif 66 | 67 | .section .crt0 68 | .global _start 69 | _start: 70 | push ds 71 | push si 72 | push di 73 | push cx 74 | 75 | xor si, si 76 | xor di, di 77 | mov ax, 0x1000 // data offset 78 | mov es, ax 79 | mov ax, cs 80 | mov dx, ax 81 | //add ax, offset "__erom!" 82 | .byte 0x05 83 | .reloc ., R_386_SEG16, "__erom!" 84 | .word 0 85 | //^ 86 | mov ds, ax 87 | mov cx, offset "__ldata_words" 88 | cld 89 | rep movsw 90 | mov cx, offset "__lbss_words" 91 | xor ax, ax 92 | rep stosw 93 | 94 | mov [es:0x58], di // end of program data 95 | mov [es:0x5e], di // TODO: end of program data? 96 | 97 | mov ax, offset "_premain" 98 | 99 | pop cx 100 | pop di 101 | pop si 102 | pop ds 103 | retf 104 | 105 | _premain: 106 | mov bp, sp 107 | 108 | // hardware initialization 109 | // 1. disable display_control 110 | xor ax, ax 111 | xor bx, bx 112 | xor cx, cx 113 | int 0x12 114 | // 2. disable SCR2 and SPR window 115 | mov ax, 0x1500 116 | int 0x12 117 | mov ax, 0x1700 118 | int 0x12 119 | // 3. disable sprites 120 | mov ax, 0x0b00 121 | int 0x12 122 | // 4. reset scroll on SCR1, SCR2 123 | mov ax, 0x1300 124 | int 0x12 125 | mov ax, 0x1301 126 | int 0x12 127 | // 5. initialize SCR1, SCR2, SPR VRAM locations 128 | mov ax, 0x2100 129 | mov bl, (SCR1_ADDR >> 11) 130 | int 0x12 131 | mov ax, 0x2101 132 | mov bl, (SCR2_ADDR >> 11) 133 | int 0x12 134 | mov ah, 0x22 135 | mov bl, (SPR_ADDR >> 9) 136 | int 0x12 137 | // 6. initialize text mode 138 | mov ah, 0x02 139 | mov bl, TEXT_MODE 140 | int 0x13 141 | mov ax, 0x0e01 142 | int 0x13 143 | // 7. enable display_control 144 | xor ax, ax 145 | mov bl, (DISPLAY_CONTROL_VAL) 146 | int 0x12 147 | 148 | // configure ds to point to sram 149 | // (reusing al = 0x00 from step 7) 150 | mov ax, 0x1000 151 | mov ds, ax 152 | mov es, ax 153 | 154 | // configure ss to point to iram 155 | mov ax, (STACK_ADDR) 156 | mov sp, ax 157 | 158 | // pass argc/argv 159 | mov ax, word ptr [bp + 0x8] 160 | mov dx, word ptr [bp + 0x6] 161 | call main 162 | 163 | // exit to FreyaBIOS 164 | int 0x10 165 | retf 166 | 167 | .section .crt0_data 168 | _start_data: 169 | .byte 'G' 170 | .byte 'C' 171 | .byte 'C' 172 | .fill 0x5D, 1, 0x00 173 | -------------------------------------------------------------------------------- /libww/include/sys/sound.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | /** \file sys/sound.h 24 | * FreyaBIOS sound calls. 25 | */ 26 | 27 | #pragma once 28 | #include 29 | 30 | /** 31 | * @addtogroup Int15 BIOS - INT 15h - Sound 32 | * @{ 33 | */ 34 | 35 | static inline void sound_init(void) { 36 | uint16_t ax_clobber; 37 | __asm volatile ( 38 | "int $0x15" 39 | : "=a" (ax_clobber) 40 | : "Rah" ((uint8_t) 0x00) 41 | : "cc", "memory" 42 | ); 43 | } 44 | 45 | static inline void sound_set_channel(uint8_t flags) { 46 | uint16_t ax_clobber; 47 | __asm volatile ( 48 | "int $0x15" 49 | : "=a" (ax_clobber) 50 | : "Rah" ((uint8_t) 0x01), "lb" (flags) 51 | : "cc", "memory" 52 | ); 53 | } 54 | 55 | static inline uint8_t sound_get_channel(void) { 56 | uint16_t result; 57 | __asm volatile ( 58 | "int $0x15" 59 | : "=a" (result) 60 | : "Rah" ((uint8_t) 0x02) 61 | : "cc", "memory" 62 | ); 63 | return result; 64 | } 65 | 66 | static inline void sound_set_output(uint8_t flags) { 67 | uint16_t ax_clobber; 68 | __asm volatile ( 69 | "int $0x15" 70 | : "=a" (ax_clobber) 71 | : "Rah" ((uint8_t) 0x03), "lb" (flags) 72 | : "cc", "memory" 73 | ); 74 | } 75 | 76 | static inline uint8_t sound_get_output(void) { 77 | uint16_t result; 78 | __asm volatile ( 79 | "int $0x15" 80 | : "=a" (result) 81 | : "Rah" ((uint8_t) 0x04) 82 | : "cc", "memory" 83 | ); 84 | return result; 85 | } 86 | 87 | static inline void sound_set_wave(uint8_t channel, const uint8_t __far* data) { 88 | uint16_t ax_clobber; 89 | __asm volatile ( 90 | "int $0x13" 91 | : "=a" (ax_clobber) 92 | : "a" (0x0500 | channel), "d" (FP_OFF(data)), "Rds" (FP_SEG(data)) 93 | : "cc", "memory" 94 | ); 95 | } 96 | 97 | static inline void sound_set_pitch(uint8_t channel, uint16_t frequency) { 98 | uint16_t ax_clobber; 99 | __asm volatile ( 100 | "int $0x15" 101 | : "=a" (ax_clobber) 102 | : "a" (0x0600 | channel), "b" (frequency) 103 | : "cc", "memory" 104 | ); 105 | } 106 | 107 | static inline uint16_t sound_get_pitch(uint8_t channel) { 108 | uint16_t result; 109 | __asm volatile ( 110 | "int $0x15" 111 | : "=a" (result) 112 | : "a" (0x0700 | channel) 113 | : "cc", "memory" 114 | ); 115 | return result; 116 | } 117 | 118 | static inline void sound_set_volume(uint8_t channel, uint8_t volume) { 119 | uint16_t ax_clobber; 120 | __asm volatile ( 121 | "int $0x15" 122 | : "=a" (ax_clobber) 123 | : "a" (0x0800 | channel), "lb" (volume) 124 | : "cc", "memory" 125 | ); 126 | } 127 | 128 | static inline uint8_t sound_get_volume(uint8_t channel) { 129 | uint16_t result; 130 | __asm volatile ( 131 | "int $0x15" 132 | : "=a" (result) 133 | : "a" (0x0900 | channel) 134 | : "cc", "memory" 135 | ); 136 | return result; 137 | } 138 | 139 | static inline void sound_set_sweep(uint8_t sweep, uint8_t step_time) { 140 | uint16_t ax_clobber; 141 | __asm volatile ( 142 | "int $0x15" 143 | : "=a" (ax_clobber) 144 | : "Rah" ((uint8_t) 0x0a), "lb" (sweep), "lc" (step_time) 145 | : "cc", "memory" 146 | ); 147 | } 148 | 149 | static inline void sound_set_noise(uint8_t flags) { 150 | uint16_t ax_clobber; 151 | __asm volatile ( 152 | "int $0x15" 153 | : "=a" (ax_clobber) 154 | : "Rah" ((uint8_t) 0x0c), "lb" (flags) 155 | : "cc", "memory" 156 | ); 157 | } 158 | 159 | static inline uint8_t sound_get_noise(void) { 160 | uint16_t result; 161 | __asm volatile ( 162 | "int $0x15" 163 | : "=a" (result) 164 | : "Rah" ((uint8_t) 0x0d) 165 | : "cc", "memory" 166 | ); 167 | return result; 168 | } 169 | 170 | static inline uint16_t sound_get_random(void) { 171 | uint16_t result; 172 | __asm volatile ( 173 | "int $0x15" 174 | : "=a" (result) 175 | : "Rah" ((uint8_t) 0x0e) 176 | : "cc", "memory" 177 | ); 178 | return result; 179 | } 180 | 181 | /**@}*/ 182 | -------------------------------------------------------------------------------- /libww/include/sys/system.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | /** \file sys/system.h 24 | * FreyaBIOS system calls. 25 | */ 26 | 27 | #pragma once 28 | #include 29 | 30 | /** 31 | * @addtogroup Int17 BIOS - INT 17h - System 32 | * @{ 33 | */ 34 | 35 | struct intvector { 36 | void (*callback)(void); 37 | uint16_t cs; 38 | uint16_t ds; 39 | uint16_t unknown; /* ? */ 40 | }; 41 | typedef struct intvector intvector_t; 42 | 43 | #define SYS_INT_SENDREADY 0x00 44 | #define SYS_INT_KEY 0x01 45 | #define SYS_INT_CASETTE 0x02 46 | #define SYS_INT_RECEIVEREADY 0x03 47 | #define SYS_INT_DISPLINE 0x04 48 | #define SYS_INT_TIMER_COUNTUP 0x05 49 | #define SYS_INT_VBLANK 0x06 50 | #define SYS_INT_HBLANK_COUNTUP 0x07 51 | 52 | static inline void sys_interrupt_set_hook(uint8_t id, intvector_t *new_vector, intvector_t *old_vector) { 53 | uint16_t ax_clobber; 54 | __asm volatile ( 55 | "int $0x17" 56 | : "=a" (ax_clobber) 57 | : "a" ((uint16_t) (0x0000 | id)), "b" (FP_OFF(new_vector)), "d" (FP_OFF(old_vector)), "Rds" (FP_SEG(new_vector)) 58 | : "cc", "memory" 59 | ); 60 | } 61 | 62 | static inline void sys_interrupt_reset_hook(uint8_t id, intvector_t *old_vector) { 63 | uint16_t ax_clobber; 64 | __asm volatile ( 65 | "int $0x17" 66 | : "=a" (ax_clobber) 67 | : "a" ((uint16_t) (0x0100 | id)), "b" (FP_OFF(old_vector)), "Rds" (FP_SEG(old_vector)) 68 | : "cc", "memory" 69 | ); 70 | } 71 | 72 | static inline void sys_wait(uint16_t v /* TODO */) { 73 | uint16_t ax_clobber; 74 | __asm volatile ( 75 | "int $0x17" 76 | : "=a" (ax_clobber) 77 | : "Rah" ((uint8_t) 0x02), "c" (v) 78 | : "cc", "memory" 79 | ); 80 | } 81 | 82 | /** 83 | * @brief Read the current tick count. 84 | * 85 | * Under FreyaBIOS, one tick equals one frame. Note that the WonderSwan runs at 75Hz. 86 | * 87 | * @return uint32_t The current tick count. 88 | */ 89 | static inline uint32_t sys_get_tick_count(void) { 90 | uint32_t result; 91 | __asm volatile ( 92 | "int $0x17" 93 | : "=A" (result) 94 | : "Rah" ((uint8_t) 0x03) 95 | : "cc", "memory" 96 | ); 97 | return result; 98 | } 99 | 100 | static inline void sys_sleep(void) { 101 | uint16_t ax_clobber; 102 | __asm volatile ( 103 | "int $0x17" 104 | : "=a" (ax_clobber) 105 | : "Rah" ((uint8_t) 0x04) 106 | : "cc", "memory" 107 | ); 108 | } 109 | 110 | static inline void sys_set_sleep_time(uint16_t time) { 111 | uint16_t ax_clobber; 112 | __asm volatile ( 113 | "int $0x17" 114 | : "=a" (ax_clobber) 115 | : "Rah" ((uint8_t) 0x05), "b" (time) 116 | : "cc", "memory" 117 | ); 118 | } 119 | 120 | static inline uint16_t sys_get_sleep_time(void) { 121 | uint16_t result; 122 | __asm volatile ( 123 | "int $0x17" 124 | : "=a" (result) 125 | : "Rah" ((uint8_t) 0x06) 126 | : "cc", "memory" 127 | ); 128 | return result; 129 | } 130 | 131 | static inline void sys_set_awake_key(uint16_t key) { 132 | uint16_t ax_clobber; 133 | __asm volatile ( 134 | "int $0x17" 135 | : "=a" (ax_clobber) 136 | : "Rah" ((uint8_t) 0x07), "b" (key) 137 | : "cc", "memory" 138 | ); 139 | } 140 | 141 | static inline uint16_t sys_get_awake_key(void) { 142 | uint16_t result; 143 | __asm volatile ( 144 | "int $0x17" 145 | : "=a" (result) 146 | : "Rah" ((uint8_t) 0x08) 147 | : "cc", "memory" 148 | ); 149 | return result; 150 | } 151 | 152 | static inline void sys_set_keepalive_int(uint16_t value) { 153 | uint16_t ax_clobber; 154 | __asm volatile ( 155 | "int $0x17" 156 | : "=a" (ax_clobber) 157 | : "Rah" ((uint8_t) 0x09), "b" (value) 158 | : "cc", "memory" 159 | ); 160 | } 161 | 162 | static inline uint16_t sys_get_version(void) { 163 | uint16_t result; 164 | __asm volatile ( 165 | "int $0x17" 166 | : "=a" (result) 167 | : "Rah" ((uint8_t) 0x12) 168 | : "cc", "memory" 169 | ); 170 | return result; 171 | } 172 | 173 | /**@}*/ 174 | -------------------------------------------------------------------------------- /libww/include/sys/timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | /** \file sys/timer.h 24 | * FreyaBIOS timer calls. 25 | */ 26 | 27 | #pragma once 28 | #include 29 | 30 | /** 31 | * @addtogroup Int16 BIOS - INT 16h - Timer 32 | * @{ 33 | */ 34 | 35 | #define RTC_YEAR 0x00 36 | #define RTC_MONTH 0x01 37 | #define RTC_DATE 0x02 38 | #define RTC_DAY_OF_WEEK 0x03 39 | #define RTC_HOUR 0x04 40 | #define RTC_MIN 0x05 41 | #define RTC_SEC 0x06 42 | 43 | static inline void rtc_set_datetime(uint16_t field, uint16_t value) { 44 | uint16_t ax_clobber; 45 | __asm volatile ( 46 | "int $0x16" 47 | : "=a" (ax_clobber) 48 | : "Rah" ((uint8_t) 0x01), "b" (field), "c" (value) 49 | : "cc", "memory" 50 | ); 51 | } 52 | 53 | static inline void rtc_set_year(uint16_t value) { 54 | rtc_set_datetime(RTC_YEAR, value); 55 | } 56 | 57 | static inline void rtc_set_month(uint16_t value) { 58 | rtc_set_datetime(RTC_MONTH, value); 59 | } 60 | 61 | static inline void rtc_set_date(uint16_t value) { 62 | rtc_set_datetime(RTC_DATE, value); 63 | } 64 | 65 | static inline void rtc_set_day_of_week(uint16_t value) { 66 | rtc_set_datetime(RTC_DAY_OF_WEEK, value); 67 | } 68 | 69 | static inline void rtc_set_hour(uint16_t value) { 70 | rtc_set_datetime(RTC_HOUR, value); 71 | } 72 | 73 | static inline void rtc_set_minute(uint16_t value) { 74 | rtc_set_datetime(RTC_MIN, value); 75 | } 76 | 77 | static inline void rtc_set_second(uint16_t value) { 78 | rtc_set_datetime(RTC_SEC, value); 79 | } 80 | 81 | static inline uint16_t rtc_get_datetime(uint16_t field) { 82 | uint16_t result; 83 | __asm volatile ( 84 | "int $0x16" 85 | : "=a" (result) 86 | : "Rah" ((uint8_t) 0x02), "b" (field) 87 | : "cc", "memory" 88 | ); 89 | } 90 | 91 | static inline uint16_t rtc_get_year(void) { 92 | return rtc_get_datetime(RTC_YEAR); 93 | } 94 | 95 | static inline uint16_t rtc_get_month(void) { 96 | return rtc_get_datetime(RTC_MONTH); 97 | } 98 | 99 | static inline uint16_t rtc_get_date(void) { 100 | return rtc_get_datetime(RTC_DATE); 101 | } 102 | 103 | static inline uint16_t rtc_get_day_of_week(void) { 104 | return rtc_get_datetime(RTC_DAY_OF_WEEK); 105 | } 106 | 107 | static inline uint16_t rtc_get_hour(void) { 108 | return rtc_get_datetime(RTC_HOUR); 109 | } 110 | 111 | static inline uint16_t rtc_get_minute(void) { 112 | return rtc_get_datetime(RTC_MIN); 113 | } 114 | 115 | static inline uint16_t rtc_get_second(void) { 116 | return rtc_get_datetime(RTC_SEC); 117 | } 118 | 119 | static inline void rtc_enable_alarm(uint8_t hour, uint8_t minute) { 120 | uint16_t ax_clobber; 121 | __asm volatile ( 122 | "int $0x16" 123 | : "=a" (ax_clobber) 124 | : "Rah" ((uint8_t) 0x05), "b" ((minute << 8) | hour) 125 | : "cc", "memory" 126 | ); 127 | } 128 | 129 | static inline void rtc_disable_alarm(void) { 130 | uint16_t ax_clobber; 131 | __asm volatile ( 132 | "int $0x16" 133 | : "=a" (ax_clobber) 134 | : "Rah" ((uint8_t) 0x06) 135 | : "cc", "memory" 136 | ); 137 | } 138 | 139 | #define TIMER_HBLANK 0 140 | #define TIMER_VBLANK 1 141 | #define TIMER_ONESHOT 0 142 | #define TIMER_AUTOPRESET 1 143 | 144 | static inline void timer_enable(uint8_t type, uint16_t reload, uint16_t count) { 145 | uint16_t ax_clobber; 146 | __asm volatile ( 147 | "int $0x16" 148 | : "=a" (ax_clobber) 149 | : "a" ((uint16_t) (0x0700 | type)), "b" (reload), "c" (count) 150 | : "cc", "memory" 151 | ); 152 | } 153 | 154 | static inline void timer_disable(uint8_t type) { 155 | uint16_t ax_clobber; 156 | __asm volatile ( 157 | "int $0x16" 158 | : "=a" (ax_clobber) 159 | : "a" ((uint16_t) (0x0800 | type)) 160 | : "cc", "memory" 161 | ); 162 | } 163 | 164 | static inline uint16_t timer_get_count(uint8_t type) { 165 | uint16_t result; 166 | __asm volatile ( 167 | "int $0x16" 168 | : "=a" (result) 169 | : "a" ((uint16_t) (0x0900 | type)) 170 | : "cc", "memory" 171 | ); 172 | return result; 173 | } 174 | 175 | /**@}*/ 176 | -------------------------------------------------------------------------------- /support/src/wonderful-asm-common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Adrian "asie" Siekierka 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #pragma once 24 | 25 | #define __WONDERFUL__ 26 | 27 | /** Memory model helpers. */ 28 | #ifdef __ASSEMBLER__ 29 | 30 | #ifdef __IA16_CMODEL_IS_FAR_TEXT 31 | #define ASM_PLATFORM_RET retf 32 | #else 33 | #define ASM_PLATFORM_RET ret 34 | #endif 35 | 36 | #ifdef __IA16_CMODEL_IS_FAR_TEXT 37 | .macro ASM_PLATFORM_CALL tgt:req 38 | .byte 0x9A 39 | .word \tgt 40 | .reloc ., R_386_SEG16, "\tgt\()!" 41 | .word 0 42 | .endm 43 | 44 | .macro ASM_PLATFORM_JMP tgt:req 45 | .byte 0xEA 46 | .word \tgt 47 | .reloc ., R_386_SEG16, "\tgt\()!" 48 | .word 0 49 | .endm 50 | #else 51 | .macro ASM_PLATFORM_CALL tgt:req 52 | call \tgt 53 | .endm 54 | 55 | .macro ASM_PLATFORM_JMP tgt:req 56 | jmp \tgt 57 | .endm 58 | #endif 59 | 60 | #endif 61 | 62 | #ifndef __ASSEMBLER__ 63 | #include 64 | 65 | /** IA16 helpers. */ 66 | #define FP_SEG(x) __builtin_ia16_selector ((uint16_t) (((uint32_t) ((void __far*) (x))) >> 16)) 67 | #define FP_OFF(x) __builtin_ia16_FP_OFF ((x)) 68 | #define MK_FP(seg, ofs) ((void __far*) (((uint16_t) ofs) | (((uint32_t) ((uint16_t) seg)) << 16))) 69 | #define _CS __builtin_wonderful_cs() 70 | #define _DS __builtin_wonderful_ds() 71 | #define _ES __builtin_wonderful_es() 72 | #define _SS __builtin_wonderful_ss() 73 | 74 | static inline uint16_t __builtin_wonderful_cs() { 75 | uint16_t result; 76 | __asm ( 77 | "mov %%cs, %0" 78 | : "=r" (result) 79 | ); 80 | return result; 81 | } 82 | 83 | static inline uint16_t __builtin_wonderful_ds() { 84 | uint16_t result; 85 | __asm ( 86 | "mov %%ds, %0" 87 | : "=r" (result) 88 | ); 89 | return result; 90 | } 91 | 92 | static inline uint16_t __builtin_wonderful_es() { 93 | uint16_t result; 94 | __asm ( 95 | "mov %%es, %0" 96 | : "=r" (result) 97 | ); 98 | return result; 99 | } 100 | 101 | static inline uint16_t __builtin_wonderful_ss() { 102 | uint16_t result; 103 | __asm ( 104 | "mov %%ss, %0" 105 | : "=r" (result) 106 | ); 107 | return result; 108 | } 109 | 110 | /** 111 | * @brief Read a byte from the given port. 112 | * 113 | * @param port Port ID. For more information, see @ref DefinesIOPorts 114 | * @return uint8_t The value read. 115 | */ 116 | static inline uint8_t inportb(uint8_t port) { 117 | uint8_t result; 118 | __asm volatile ( 119 | "inb %1, %0" 120 | : "=Ral" (result) 121 | : "Nd" ((uint16_t) port) 122 | ); 123 | return result; 124 | } 125 | 126 | /** 127 | * @brief Read a word from the given port. 128 | * 129 | * @param port Port ID. For more information, see @ref DefinesIOPorts 130 | * @return uint8_t The value read. 131 | */ 132 | static inline uint16_t inportw(uint8_t port) { 133 | uint16_t result; 134 | __asm volatile ( 135 | "inw %1, %0" 136 | : "=a" (result) 137 | : "Nd" ((uint16_t) port) 138 | ); 139 | return result; 140 | } 141 | 142 | /** 143 | * @brief Write a byte to the given port. 144 | * 145 | * @param port Port ID. For more information, see @ref DefinesIOPorts 146 | * @param value The value to write. 147 | */ 148 | static inline void outportb(uint8_t port, uint8_t value) { 149 | __asm volatile ( 150 | "outb %0, %1" 151 | : 152 | : "Ral" (value), "Nd" ((uint16_t) port) 153 | ); 154 | } 155 | 156 | /** 157 | * @brief Write a word to the given port. 158 | * 159 | * @param port Port ID. For more information, see @ref DefinesIOPorts 160 | * @param value The value to write. 161 | */ 162 | static inline void outportw(uint8_t port, uint16_t value) { 163 | __asm volatile ( 164 | "outw %0, %1" 165 | : 166 | : "a" (value), "Nd" ((uint16_t) port) 167 | ); 168 | } 169 | 170 | static inline void cpu_halt(void) { 171 | __asm volatile ("hlt"); 172 | } 173 | #define hlt cpu_halt 174 | 175 | static inline void cpu_irq_enable(void) { 176 | __asm volatile ("sti"); 177 | } 178 | #define sti cpu_irq_enable 179 | 180 | static inline void cpu_irq_disable(void) { 181 | __asm volatile ("cli"); 182 | } 183 | #define cli cpu_irq_disable 184 | 185 | #endif 186 | --------------------------------------------------------------------------------