diff options
author | Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> | 2017-05-13 13:51:19 +0200 |
---|---|---|
committer | Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> | 2017-05-13 13:51:19 +0200 |
commit | b44c3963e0c57afabe51b7ff01574b87e65048ab (patch) | |
tree | d1b39346d38dc31edc56b7e5d5058368c8f18722 | |
parent | 0238d2ddb51660c01e969236c33c466b145587b4 (diff) |
We gotta start pillaging some stuff.
106 files changed, 3677 insertions, 427 deletions
diff --git a/arch/all/core-sh/include/bits/endian.h b/arch/all/core-sh/include/bits/endian.h new file mode 100644 index 0000000..ff9114b --- /dev/null +++ b/arch/all/core-sh/include/bits/endian.h @@ -0,0 +1,30 @@ +/* ***************************************************************************** + * bits/endian.h -- SuperH endianness. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#ifndef _BITS_ENDIAN_H +# define _BITS_ENDIAN_H 1 +# include <cdefs/compiler.h> + +/* Just use the basic thing. */ +# if defined(_BIG) +# define __BYTE_ORDER __BIG_ENDIAN +# else +# define __BYTE_ORDER __LITTLE_ENDIAN +# endif + +#endif /* _BITS_ENDIAN_H */ diff --git a/arch/all/core-sh/include/cdefs/arch/types.h b/arch/all/core-sh/include/bits/types.h index adbf176..fffe13a 100644 --- a/arch/all/core-sh/include/cdefs/arch/types.h +++ b/arch/all/core-sh/include/bits/types.h @@ -1,5 +1,5 @@ /* ***************************************************************************** - * cdefs/arch/types.h -- SuperH architecture types. + * bits/types.h -- SuperH architecture types. * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> * * This file is part of libcarrot. @@ -16,25 +16,13 @@ * You should have received a copy of the GNU Lesser General Public License * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. * ************************************************************************** */ -#ifndef _CDEFS_ARCH_TYPES_H -# define _CDEFS_ARCH_TYPES_H 1 -# ifndef _CDEFS_ARCH_H -# error "This file should be included by `cdefs/arch.h`!" -# endif -# if __USE_C99 -# define __longlong long long -# define __ulonglong unsigned long long -# endif -# ifdef __longlong -# define __use64 1 -# else -# define __use64 0 -# endif +#ifndef _BITS_TYPES_H +# define _BITS_TYPES_H 1 + /* ************************************************************************** */ -/* stdint/inttypes types */ +/* Exactly N-bits integer types */ /* ************************************************************************** */ -/* These types are for `stdint.h`, - * the associated macros are for `inttypes.h`. */ +/* These are the types that contain exactly N bits. */ typedef signed char __int8_t; typedef unsigned char __uint8_t; @@ -42,56 +30,17 @@ typedef signed short __int16_t; typedef unsigned short __uint16_t; typedef signed long __int32_t; typedef unsigned long __uint32_t; -# if __use64 -typedef __longlong __int64_t; -typedef __ulonglong __uint64_t; -# endif - -typedef __int8_t __int_least8_t; -typedef __uint8_t __uint_least8_t; -typedef __int16_t __int_least16_t; -typedef __uint16_t __uint_least16_t; -typedef __int32_t __int_least32_t; -typedef __uint32_t __uint_least32_t; -# if __use64 -typedef __int64_t __int_least64_t; -typedef __uint64_t __uint_least64_t; -# endif - -typedef __int32_t __int_fast8_t; -typedef __uint32_t __uint_fast8_t; -typedef __int32_t __int_fast16_t; -typedef __uint32_t __uint_fast16_t; -typedef __int32_t __int_fast32_t; -typedef __uint32_t __uint_fast32_t; -# if __use64 -typedef __int64_t __int_fast64_t; -typedef __uint64_t __uint_fast64_t; -# endif - -typedef __int32_t __intptr_t; -typedef __uint32_t __uintptr_t; - -# if __use64 -typedef __int64_t __intmax_t; -typedef __uint64_t __uintmax_t; -# else -typedef __int32_t __intmax_t; -typedef __uint32_t __uintmax_t; -# endif # define __INT8_WIDTH ( 8) # define __INT8_MIN (-127-1) # define __INT8_MAX ( 127) -# define __UINT8_WIDTH ( 8) -# define __UINT8_MIN ( 0) +# define __UINT8_MAX ( 0) # define __UINT8_MAX ( 255) # define __PRI8 "hh" # define __INT16_WIDTH ( 16) # define __INT16_MIN (-32767-1) # define __INT16_MAX ( 32767) -# define __UINT16_WIDTH ( 16) # define __UINT16_MIN ( 0) # define __UINT16_MAX ( 65535) # define __PRI16 "h" @@ -99,27 +48,24 @@ typedef __uint32_t __uintmax_t; # define __INT32_WIDTH ( 32) # define __INT32_MIN (-2147483647-1) # define __INT32_MAX ( 2147483647) -# define __UINT32_WIDTH ( 32) -# define __UINT32_MIN ( 0) +# define __UINT32_MIN (0) # define __UINT32_MAX ( 4294967295) # define __PRI32 "" +/* ************************************************************************** */ +/* At least N-bits integer types */ +/* ************************************************************************** */ +/* These are the types that can contain at least N bits. */ -# if defined(__longlong) -# define __INT64_WIDTH ( 64) -# define __INT64_MIN (-9223372036854775807-1) -# define __INT64_MAX ( 9223372036854775807) -# define __UINT64_WIDTH ( 64) -# define __UINT64_MIN ( 0) -# define __UINT64_MAX ( 18446744073709551615) -# define __PRI64 "ll" -# endif - -/* For the "at least X bits long" types. */ +typedef __int8_t __int_least8_t; +typedef __uint8_t __uint_least8_t; +typedef __int16_t __int_least16_t; +typedef __uint16_t __uint_least16_t; +typedef __int32_t __int_least32_t; +typedef __uint32_t __uint_least32_t; # define __INT_LEAST8_WIDTH __INT8_WIDTH # define __INT_LEAST8_MIN __INT8_MIN # define __INT_LEAST8_MAX __INT8_MAX -# define __UINT_LEAST8_WIDTH __UINT8_WIDTH # define __UINT_LEAST8_MIN __UINT8_MIN # define __UINT_LEAST8_MAX __UINT8_MAX # define __PRILEAST8 __PRI8 @@ -127,7 +73,6 @@ typedef __uint32_t __uintmax_t; # define __INT_LEAST16_WIDTH __INT16_WIDTH # define __INT_LEAST16_MIN __INT16_MIN # define __INT_LEAST16_MAX __INT16_MAX -# define __UINT_LEAST16_WIDTH __UINT16_WIDTH # define __UINT_LEAST16_MIN __UINT16_MIN # define __UINT_LEAST16_MAX __UINT16_MAX # define __PRILEAST16 __PRI16 @@ -135,27 +80,24 @@ typedef __uint32_t __uintmax_t; # define __INT_LEAST32_WIDTH __INT32_WIDTH # define __INT_LEAST32_MIN __INT32_MIN # define __INT_LEAST32_MAX __INT32_MAX -# define __UINT_LEAST32_WIDTH __UINT32_WIDTH # define __UINT_LEAST32_MIN __UINT32_MIN # define __UINT_LEAST32_MAX __UINT32_MAX # define __PRILEAST32 __PRI32 +/* ************************************************************************** */ +/* Fastest integer types for N-bits values */ +/* ************************************************************************** */ +/* These types are the fastest that can contain N-bits values. */ -# if defined(__longlong) -# define __INT_LEAST64_WIDTH __INT64_WIDTH -# define __INT_LEAST64_MIN __INT64_MIN -# define __INT_LEAST64_MAX __INT64_MAX -# define __UINT_LEAST64_WIDTH __UINT64_WIDTH -# define __UINT_LEAST64_MIN __UINT64_MIN -# define __UINT_LEAST64_MAX __UINT64_MAX -# define __PRILEAST64 __PRI64 -# endif - -/* For the "faster type containing X bits long integers" types. */ +typedef __int32_t __int_fast8_t; +typedef __uint32_t __uint_fast8_t; +typedef __int32_t __int_fast16_t; +typedef __uint32_t __uint_fast16_t; +typedef __int32_t __int_fast32_t; +typedef __uint32_t __uint_fast32_t; # define __INT_FAST8_WIDTH __INT32_WIDTH # define __INT_FAST8_MIN __INT32_MIN # define __INT_FAST8_MAX __INT32_MAX -# define __UINT_FAST8_WIDTH __UINT32_WIDTH # define __UINT_FAST8_MIN __UINT32_MIN # define __UINT_FAST8_MAX __UINT32_MAX # define __PRIFAST8 __PRI32 @@ -163,7 +105,6 @@ typedef __uint32_t __uintmax_t; # define __INT_FAST16_WIDTH __INT32_WIDTH # define __INT_FAST16_MIN __INT32_MIN # define __INT_FAST16_MAX __INT32_MAX -# define __UINT_FAST16_WIDTH __UINT32_WIDTH # define __UINT_FAST16_MIN __UINT32_MIN # define __UINT_FAST16_MAX __UINT32_MAX # define __PRIFAST16 __PRI32 @@ -171,69 +112,36 @@ typedef __uint32_t __uintmax_t; # define __INT_FAST32_WIDTH __INT32_WIDTH # define __INT_FAST32_MIN __INT32_MIN # define __INT_FAST32_MAX __INT32_MAX -# define __UINT_FAST32_WIDTH __UINT32_WIDTH # define __UINT_FAST32_MIN __UINT32_MIN # define __UINT_FAST32_MAX __UINT32_MAX # define __PRIFAST32 __PRI32 +/* ************************************************************************** */ +/* Pointer-like integer types */ +/* ************************************************************************** */ +/* These types have the same width as a pointer. */ -# if defined(__longlong) -# define __INT_FAST64_WIDTH __INT64_WIDTH -# define __INT_FAST64_MIN __INT64_MIN -# define __INT_FAST64_MAX __INT64_MAX -# define __UINT_FAST64_WIDTH __UINT64_WIDTH -# define __UINT_FAST64_MIN __UINT64_MIN -# define __UINT_FAST64_MAX __UINT64_MAX -# define __PRIFAST64 __PRI64 -# endif - -/* For pointer integer types. */ +typedef __int32_t __intptr_t; +typedef __uint32_t __uintptr_t; # define __INTPTR_WIDTH __INT32_WIDTH # define __INTPTR_MIN __INT32_MIN # define __INTPTR_MAX __INT32_MAX -# define __UINTPTR_WIDTH __UINT32_WIDTH # define __UINTPTR_MIN __UINT32_MIN # define __UINTPTR_MAX __UINT32_MAX # define __PRIPTR __PRI32 +/* ************************************************************************** */ +/* Greatest-width integer types */ +/* ************************************************************************** */ +/* These types have the greatest width you will ever be able to access. */ + +typedef __int32_t __intmax_t; +typedef __uint32_t __uintmax_t; -/* For greatest-width integer types. */ - -# if defined(__longlong) -# define __INTMAX_WIDTH __INT64_WIDTH -# define __INTMAX_MIN __INT64_MIN -# define __INTMAX_MAX __INT64_MAX -# define __UINTMAX_WIDTH __UINT64_WIDTH -# define __UINTMAX_MIN __UINT64_MIN -# define __UINTMAX_MAX __UINT64_MAX -# define __PRIMAX __PRI64 -# else # define __INTMAX_WIDTH __INT32_WIDTH # define __INTMAX_MIN __INT32_MIN # define __INTMAX_MAX __INT32_MAX -# define __UINTMAX_WIDTH __UINT32_WIDTH # define __UINTMAX_MIN __UINT32_MIN # define __UINTMAX_MAX __UINT32_MAX # define __PRIMAX __PRI32 -# endif -/* ************************************************************************** */ -/* stddef types */ -/* ************************************************************************** */ -/* Check out `stddef.h` to have the full description. */ - -typedef __intptr_t __ptrdiff_t; -typedef __uintptr_t __size_t; -typedef __uint32_t __wchar_t; - -# define __PTRDIFF_WIDTH __INTPTR_WIDTH -# define __PTRDIFF_MIN __INTPTR_MIN -# define __PTRDIFF_MAX __INTPTR_MAX - -# define __SIZE_WIDTH __UINTPTR_WIDTH -# define __SIZE_MIN __UINTPTR_MIN -# define __SIZE_MAX __UINTPTR_MAX - -# define __WCHAR_WIDTH __UINT32_WIDTH -# define __WCHAR_MIN __UINT32_MIN -# define __WCHAR_MAX __UINT32_MAX -#endif /* _CDEFS_TYPES_H */ +#endif /* _BITS_TYPES_H */ diff --git a/arch/all/core/PLATFORM.md b/arch/all/core/PLATFORM.md new file mode 100644 index 0000000..b24cd70 --- /dev/null +++ b/arch/all/core/PLATFORM.md @@ -0,0 +1,63 @@ +# Extending libcarrot to another architecture/platform. +This core includes subheaders in the `bits/` directory, which define the +architecture or platform specific macros and types, so the core can centralize +all of the standard headers. + +This file is a description of all of these specific subheaders. +The subheaders should define their include guard as: `_BITS_<subheader>_H`. + +## Architecture-specific headers +### `bits/endian.h` -- endianness identification. +This header defines the `__BYTE_ORDER` macro, which can expand to those values: + +- `__LITTLE_ENDIAN`: the architecture is little endian; +- `__BIG_ENDIAN`: the architecture is big endian. + +### `bits/types.h` -- architecture types. +This subheader should define the following types (**N** represents 8, 16 or 32): + +- `__intN_t`, `__uintN_t`: + signed and unsigned integer type with width `N`; +- `__int_leastN_t`, `__uint_leastN_t`: + signed and unsigned integer type with at least `N` as the width, such that + no integer type with lesser size has at least the specified width; +- `__int_fastN_t`, `__uint_fastN_t`: + signed and unsigned fastest integer type with a width of at least `N`. +- `__intptr_t`, `__uintptr_t`: + signed and unsigned integer type which are exactly the same width as + a pointer; +- `__intmax_t`, `__uintmax_t`: + signed and unsigned greatest-width integer type; + +For each of the **signed version of the types**, it should also define the +following macros, leading to constant expressions (where `<type>` represents the +all caps type without the `__` prefix and the `_t` suffix, e.g. `INT_FAST8` for +`__int_fast8_t`, and `<suffix>` represents the type suffix, +so what's after `__int_` and before the `_t` for the `__intN_t`, +`__int_leastN_t` and `__int_fastN_t` types, `PTR` for `__intptr_t`, and +`MAX` for `__intmax_t`): + +- `__<type>_WIDTH`: the number of bits of the type + (e.g. `16` for a 16-bit type); +- `__<type>_MIN`: the minimum of the signed version of the type; +- `__<type>_MAX`: the maximum of the signed version of the type; +- `__U<type>_MIN`: the minimum of the unsigned version of the type + (usually 0 with a suffix); +- `__U<type>_MAX`: the maximum of the unsigned version of the type; +- `__PRI<suffix>`: the `printf`/`scanf` type prefix. + +For example, for `__int8_t`: + + typedef char __int8_t; + typedef unsigned char __uint8_t; + + #define __INT8_WIDTH ( 8) + #define __INT8_MIN (-127-1) + #define __INT8_MAX ( 127) + #define __UINT8_MAX ( 255) + #define __PRI8 "hh" + +## Platform-specific headers +### `bits/time.h` -- platform-specific time constants. +This header must define the `__CLOCKS_PER_SEC` constant, which corresponds +to the number of ticks per second. diff --git a/arch/casiowin/fxlib-libc/include/assert.h b/arch/all/core/include/assert.h index 4727094..43eb00f 100644 --- a/arch/casiowin/fxlib-libc/include/assert.h +++ b/arch/all/core/include/assert.h @@ -1,5 +1,5 @@ /* ***************************************************************************** - * assert.h -- Assertions (display an error message and quit). + * assert.h -- Assertions (useful for debugging). * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> * * This file is part of libcarrot. @@ -25,24 +25,38 @@ # define _ASSERT 1 # define __ASSERT 1 # include <cdefs.h> +# include <stddef.h> +/* Here is the nice way to get the function name. */ +# if defined(__cplusplus) ? __GNUC_PREREQ(2, 6) : __GNUC_PREREQ(2, 4) +# define __ASSERT_FUNC __PRETTY_FUNCTION__ +# elif __USE_C99 +# define __ASSERT_FUNC __func__ +# else +# define __ASSERT_FUNC NULL +# endif +/* ************************************************************************** */ +/* Main functions */ +/* ************************************************************************** */ __BEGIN_DECLS -/* make an assertion pop-up */ -extern void __assert_popup OF((const char *__file, int __line, - const char *__expr)) __THROW __nonnull(1) __nonnull(3); -__END_DECLS -/* check if the macro exists */ +extern void __noreturn __assert_fail OF((const char *__assertion, + const char *__file, unsigned int __line, const char *__function)) __THROW; + +__END_DECLS +/* ************************************************************************** */ +/* Macro definition */ +/* ************************************************************************** */ # ifdef assert # undef assert # endif - -/* define it accordingly */ # ifdef NDEBUG # define assert(_IGN) ((void)0) # else -# define assert(_EXPR) { \ - if (!(_EXPR)) __assert_popup(__FILE__, __LINE__, __QUOTE(_EXPR)); } +# define assert(_EXPR) \ + ((_EXPR) \ + ? (void)0 \ + : __assert_fail(#_EXPR, __FILE__, __LINE__, __ASSERT_FUNC)) # endif #endif /* _ASSERT_H */ diff --git a/arch/all/core/include/cdefs.h b/arch/all/core/include/cdefs.h index f13b932..caa2348 100644 --- a/arch/all/core/include/cdefs.h +++ b/arch/all/core/include/cdefs.h @@ -31,15 +31,6 @@ /* Identify the compiler. */ # include <cdefs/compiler.h> /* ************************************************************************** */ -/* Include and validate the architecture-specific headers */ -/* ************************************************************************** */ -/* Define some macros first. */ -# define __LITTLE_ENDIAN 1234 -# define __BIG_ENDIAN 4321 - -/* Include the arch-specific headers. */ -# include <cdefs/arch.h> -/* ************************************************************************** */ /* Include other subheaders */ /* ************************************************************************** */ /* Define the compiler-specific attributes. */ diff --git a/arch/all/core/include/cdefs/attrs.h b/arch/all/core/include/cdefs/attrs.h index 32f904b..ddceae0 100644 --- a/arch/all/core/include/cdefs/attrs.h +++ b/arch/all/core/include/cdefs/attrs.h @@ -30,10 +30,11 @@ /* __THROW: optimize function calls for C++ */ /* ************************************************************************** */ /* <TODO: explanation> */ + # ifdef __THROW # undef __THROW # endif -# if defined(__cplusplus) +# if __USE_CXX98 # define __THROW throw() # elif defined(__GNUC__) # define __THROW __attribute__((nothrow)) @@ -44,6 +45,7 @@ /* __align: align data */ /* ************************************************************************** */ /* When you want to align data for easier management. */ + # ifdef __align # undef __align # endif @@ -57,6 +59,7 @@ /* ************************************************************************** */ /* The `inline` function attribute is simply an indication; this attribute * forces the inlining of a function. */ + # ifdef __inline # undef __inline # endif @@ -70,6 +73,7 @@ /* ************************************************************************** */ /* This attribute forces inlining and enables optimizations suitable for * inline assembly functions/macros such as the ones defined in `machine.h`. */ + # ifdef __asm_inline # undef __asm_inline # endif @@ -84,6 +88,7 @@ /* ************************************************************************** */ /* For a set of arguments, there is a constant (cacheable) result, and * calculating it doesn't require any side effect. */ + # ifdef __pure # undef __pure # endif @@ -109,7 +114,7 @@ # ifdef __notnull # undef __notnull # endif -# if __STDC_VERSION__ >= 199901L +# if __USE_C99 # define __atleast(_N) static (_N) # else # define __atleast(_N) @@ -120,6 +125,7 @@ /* ************************************************************************** */ /* A warning shall be issued when a NULL value is passed as an argument that * shouldn't be. The macro argument is the argument index, starting from 1. */ + # ifdef __nonnull # undef __nonnull # endif @@ -133,6 +139,7 @@ /* ************************************************************************** */ /* A warning shall be issued if the result of the function isn't used. * Note that __pure implies __wur, you don't need to put the two. */ + # ifdef __wur # undef __wur # endif @@ -145,10 +152,11 @@ /* __restrict: portable 'restrict' keyword */ /* ************************************************************************** */ /* Uses 'restrict' if we're in >=C99, or nothing if not. */ + # ifdef __restrict # undef __restrict # endif -# if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L +# if __USE_C99 # define __restrict restrict # else # define __restrict @@ -157,6 +165,7 @@ /* __malloc: is a memory allocation function */ /* ************************************************************************** */ /* TODO: why is this attribute useful? */ + # ifdef __malloc # undef __malloc # endif @@ -168,6 +177,9 @@ /* ************************************************************************** */ /* __format: is a function expecting a printf-like format */ /* ************************************************************************** */ +/* This produces the damn right warnings for when you don't use the standard + * functionnalities of `printf` correctly. */ + # ifdef __format # undef __format # endif @@ -180,6 +192,8 @@ /* ************************************************************************** */ /* __alias: the function is an alias for an other */ /* ************************************************************************** */ +/* TODO: why is using this a good idea? */ + # ifdef __alias # undef __alias # endif @@ -191,6 +205,9 @@ /* ************************************************************************** */ /* __deprecated: a function, structure or structure member is deprecated */ /* ************************************************************************** */ +/* You really shouldn't use what's marked with that argument, it might + * disappear at any time. */ + # ifdef __deprecated # undef __deprecated # endif @@ -200,8 +217,23 @@ # define __deprecated # endif /* ************************************************************************** */ +/* __noreturn: this is the point of. */ +/* ************************************************************************** */ +/* Use this when you know you'll abort or exit or whatever. */ + +# ifdef __noreturn +# undef __noreturn +# endif +# if defined(__GNUC__) +# define __noreturn __attribute__((noreturn)) +# else +# define __noreturn +# endif +/* ************************************************************************** */ /* __section: put this function/data in an ELF section */ /* ************************************************************************** */ +/* Sections are fun. */ + # ifdef __section # undef __section # endif diff --git a/arch/all/core/include/cdefs/compiler.h b/arch/all/core/include/cdefs/compiler.h index 225a93b..314c752 100644 --- a/arch/all/core/include/cdefs/compiler.h +++ b/arch/all/core/include/cdefs/compiler.h @@ -62,6 +62,9 @@ # else # define __HITACHI_PREREQ(_MAJ, _MIN) 0 # endif + +/* This compiler pre-defines some other things, check these out! */ +# include <cdefs/compiler/hitachi.h> /* ************************************************************************** */ /* GNU Compiler Collection */ /* ************************************************************************** */ @@ -145,5 +148,16 @@ # else # define __SDCC_PREREQ(_MAJ, _MIN) 0 # endif +/* ************************************************************************** */ +/* Portable C/C++ Compiler */ +/* ************************************************************************** */ +/* This was a compiler written for BSD. */ + +# if defined(__PCC__) && defined(__PCC_MINOR__) +# define __PCC_PREREQ(_MAJ, _MIN) \ + (__PCC__ > (_MAJ) || (__PCC__ == (_MAJ) && __PCC_MINOR__ >= (_MIN))) +# else +# define __PCC_PREREQ(_MAJ, _MIN) 0 +# endif #endif /* _CDEFS_COMPILER_H */ diff --git a/arch/all/core-sh/include/cdefs/arch.h b/arch/all/core/include/cdefs/compiler/hitachi.h index 6fc92b4..aadc2b7 100644 --- a/arch/all/core-sh/include/cdefs/arch.h +++ b/arch/all/core/include/cdefs/compiler/hitachi.h @@ -1,5 +1,5 @@ /* ***************************************************************************** - * cdefs/arch.h -- SuperH architecture details. + * cdefs/compiler/hitachi.h -- Hitachi/Renesas C/C++ pre-defined macros. * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> * * This file is part of libcarrot. @@ -16,13 +16,8 @@ * You should have received a copy of the GNU Lesser General Public License * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. * ************************************************************************** */ -#ifndef _CDEFS_ARCH_H -# define _CDEFS_ARCH_H 1 -# ifndef _CDEFS_H -# error "This file should be included by `cdefs.h`!" -# endif -# include <cdefs/compiler.h> -# include <cdefs/arch/types.h> +#ifndef _CDEFS_COMPILER_HITACHI_H +# define _CDEFS_COMPILER_HITACHI_H 1 /* ************************************************************************** */ /* DSP-C Interface and options */ @@ -123,13 +118,6 @@ # define _LIT # endif # endif - -/* Macro for `endian.h`. */ -# if defined(_BIG) -# define __BYTE_ORDER __BIG_ENDIAN -# else -# define __BYTE_ORDER __LITTLE_ENDIAN -# endif /* ************************************************************************** */ /* Position-independant code */ /* ************************************************************************** */ @@ -183,4 +171,4 @@ # endif # endif -#endif /* _CDEFS_ARCH_H */ +#endif /* _CDEFS_COMPILER_HITACHI_H */ diff --git a/arch/all/core/include/cdefs/features.h b/arch/all/core/include/cdefs/features.h index 10d1f7f..f3b50b9 100644 --- a/arch/all/core/include/cdefs/features.h +++ b/arch/all/core/include/cdefs/features.h @@ -23,21 +23,40 @@ # endif /* ************************************************************************** */ +/* C89 (ANSI C, ISO C) features */ +/* ************************************************************************** */ +/* A few things changed when C was standardized by the ANSI (later ISO), + * like the type definitions in the function prototypes (see `OF`). + * This macro will help you guess what you should define and use. */ + +# ifdef __USE_C89 +# undef __USE_C89 +# endif +# if !defined(__STDC__) || __STDC__ == 0 +# define __USE_C89 0 +# else +# define __USE_C89 1 +# endif +/* ************************************************************************** */ /* C99, C11 features */ /* ************************************************************************** */ /* These macros are for features we should only provide if the used C * standard includes C99 or C11. */ -# if defined(__USE_C99) -# elif (defined(__GNUC__) && !defined(__STRICT_ANSI__)) \ +# ifdef __USE_C99 +# undef __USE_C99 +# endif +# if (defined(__GNUC__) && !defined(__STRICT_ANSI__)) \ || __STDC_VERSION__ >= 199901L # define __USE_C99 1 # else # define __USE_C99 0 # endif -# if defined(__USE_C11) -# elif __STDC_VERSION__ >= 201112L +# ifdef __USE_C11 +# undef __USE_C11 +# endif +# if __STDC_VERSION__ >= 201112L # define __USE_C11 1 # else # define __USE_C11 0 @@ -48,11 +67,34 @@ /* These macros are for features we should only provide if the used C++ * standard includes one or more versions. */ -# if defined(__USE_CXX11) -# elif __cplusplus >= 201103L +# ifdef __USE_CXX98 +# undef __USE_CXX98 +# endif +# if !defined(__cplusplus) +# define __USE_CXX98 0 +# else +# define __USE_CXX98 1 +# endif + +# ifdef __USE_CXX11 +# undef __USE_CXX11 +# endif +# if __cplusplus >= 201103L # define __USE_CXX11 1 # else # define __USE_CXX11 0 # endif +/* ************************************************************************** */ +/* Renesas/Hitachi libc extensions */ +/* ************************************************************************** */ +/* Renesas/Hitachi defined some extensions in their libc, described in their + * user's manual. This macro makes them defined. */ + +# if !defined(__USE_RENESAS) || __USE_RENESAS != 1 +# ifdef __USE_RENESAS +# undef __USE_RENESAS +# endif +# define __USE_RENESAS 0 +# endif #endif /* _CDEFS_FEATURES_H */ diff --git a/arch/all/core/include/cdefs/utils.h b/arch/all/core/include/cdefs/utils.h index d625aae..b62d09f 100644 --- a/arch/all/core/include/cdefs/utils.h +++ b/arch/all/core/include/cdefs/utils.h @@ -22,13 +22,14 @@ # error "This file should be included by `cdefs.h`!" # endif # include <cdefs/compiler.h> +# include <cdefs/features.h> /* ************************************************************************** */ /* Declaration arguments */ /* ************************************************************************** */ /* ANSI C does not have arguments in function declarations. */ -# ifdef __STDC_VERSION__ +# if __USE_C89 # define OF(_ARGS) _ARGS # else # define OF(_ARGS) () @@ -38,7 +39,7 @@ /* ************************************************************************** */ /* C++ needs to know that types and declarations are C, not C++. */ -# ifdef __cplusplus +# if __USE_CXX98 # define __BEGIN_DECLS extern "C" { # define __END_DECLS } # else @@ -55,7 +56,7 @@ * The C++ wrapper header take case of adding the definition to * the global namespace. */ -# ifdef __cplusplus +# if __USE_CXX98 # define __BEGIN_NAMESPACE_STD namespace std { # define __USING_NAMESPACE_STD(_NAME) using std::_NAME; # define __END_NAMESPACE_STD } diff --git a/arch/all/core/include/complex.h b/arch/all/core/include/complex.h new file mode 100644 index 0000000..304319e --- /dev/null +++ b/arch/all/core/include/complex.h @@ -0,0 +1,49 @@ +/* ***************************************************************************** + * complex.h -- Complex arithmetic. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#if !defined(_COMPLEX_H) && !defined(_COMPLEX_H_) && !defined(__COMPLEX_H) \ + && !defined(__COMPLEX_H__) && !defined(_COMPLEX) && !defined(__COMPLEX) +# define _COMPLEX_H 1 +# define _COMPLEX_H_ 1 +# define __COMPLEX_H 1 +# define __COMPLEX_H__ 1 +# define _COMPLEX 1 +# define __COMPLEX 1 +# include <cdefs.h> + +/* TODO */ + +#endif /* _COMPLEX_H */ +#ifndef _COMPLEX_H +# define _COMPLEX_H 1 +#endif +#ifndef _COMPLEX_H_ +# define _COMPLEX_H_ 1 +#endif +#ifndef __COMPLEX_H +# define __COMPLEX_H 1 +#endif +#ifndef __COMPLEX_H__ +# define __COMPLEX_H__ 1 +#endif +#ifndef _COMPLEX +# define _COMPLEX 1 +#endif +#ifndef __COMPLEX +# define __COMPLEX 1 +#endif diff --git a/arch/casiowin/fxlib-libc/include/dirent.h b/arch/all/core/include/dirent.h index 141532d..aec4320 100644 --- a/arch/casiowin/fxlib-libc/include/dirent.h +++ b/arch/all/core/include/dirent.h @@ -33,22 +33,28 @@ struct dirent { }; /* open and close the directory stream */ -extern DIR *opendir OF((const char __path[__notnull])) - __THROW __nonnull(1) __wur; -extern int closedir OF((DIR *__stream)) - __THROW __nonnull(1); +extern __nonnull(1) __wur +DIR *opendir OF((const char __path[__notnull])) + __THROW; + +extern __nonnull(1) +int closedir OF((DIR *__stream)) + __THROW; /* read from directory */ -extern struct dirent *readdir OF((DIR *__stream)) - __THROW __nonnull(1); +extern __nonnull(1) +struct dirent *readdir OF((DIR *__stream)) + __THROW; /* move in directory */ -void seekdir OF((DIR *__stream, long __index)) - __THROW __nonnull(1); -long telldir OF((DIR *__stream)) - __THROW __nonnull(1); -void rewinddir OF((DIR *__stream)) - __THROW __nonnull(1); +extern __nonnull(1) +void seekdir OF((DIR *__stream, long __index)) __THROW; + +extern __nonnull(1) +long telldir OF((DIR *__stream)) __THROW; + +extern __nonnull(1) +void rewinddir OF((DIR *__stream)) __THROW; __END_DECLS #endif /* _DIRENT_H */ diff --git a/arch/all/core/include/endian.h b/arch/all/core/include/endian.h index 5dbe29d..1f22cac 100644 --- a/arch/all/core/include/endian.h +++ b/arch/all/core/include/endian.h @@ -30,6 +30,10 @@ # include <cdefs.h> # include <byteswap.h> +/* Get the endianness' platform. */ +# define __LITTLE_ENDIAN 1234 +# define __BIG_ENDIAN 4321 +# include <bits/endian.h> /* ************************************************************************** */ /* Endian swapping utilities */ /* ************************************************************************** */ diff --git a/arch/all/core/include/errno.h b/arch/all/core/include/errno.h index 2ed8cde..92edc2a 100644 --- a/arch/all/core/include/errno.h +++ b/arch/all/core/include/errno.h @@ -27,37 +27,89 @@ # include <cdefs.h> __BEGIN_DECLS -# define EPERM 1 /* Operation not permitted */ -# define ENOENT 2 /* No such file or directory */ -# define EIO 5 /* I/O error */ -# define ENXIO 6 /* No such device or address */ -# define ENOMEM 12 /* Out of memory */ -# define EINVAL 22 /* Invalid argument */ +/* the global */ +extern volatile int errno; -/* coming from fxlib; TODO: look for what all of these are */ -# define ERANGE 1100 -# define EDOM 1101 -# define EDIV 1102 -# define ESTRN 1104 -# define PTRERR 1106 -# define SEQERR 1108 -# define ECBASE 1200 -# define ETLN 1202 -# define EEXP 1204 -# define EEXPN 1206 -# define ENUM 1208 -# define EFLOATO 1210 -# define EFLOATU 1220 -# define EDBLO 1250 -# define EDBLU 1260 -# define ELDBLO 1270 -# define ELDBLU 1280 -# define NOTOPN 1300 -# define EBADF 1302 -# define ECSPEC 1304 +/* Errors from the Renesas/Hitachi C/C++ library (version 06.00). */ -/* the global */ -extern int errno; +# define ERANGE 1100 /* `data out of RANGE`: + * result of a function cannot be represented as a float + * type value, or if overflow or underflow occurs. */ +# define EDOM 1101 /* `data out of DOMain`: + * the value of a parameter input to a function is + * outside the range of values defined in the function */ +# define EDIV 1102 /* ??? (XXX) */ +# define ESTRN 1104 /* `Too long string`: + * the length of string literal exceeds 512 chars. */ +# define PTRERR 1106 /* `Invalid file pointer`: + * the NULL pointer constant is specified as the file + * pointer value. */ +# define SEQERR 1108 /* ??? (XXX) */ +# define ECBASE 1200 /* `Invalid radix`: + * an invalid radix was specified. */ +# define ETLN 1202 /* `Number too long`: + * the specified number exceeds the number of + * significiant digits. */ +# define EEXP 1204 /* `Exponent too large`: + * the specified exponent exceeds three digits. */ +# define EEXPN 1206 /* `Normalized exponent too large`: + * the exponent exceeds three digits when the string + * literal is normalized to the IEEE standard decimal + * format. */ +# define ENUM 1208 /* ??? (XXX) */ +# define EFLOATO 1210 /* `Overflow out of float`: + * A float-type decimal value is out of range + * (overflow). */ +# define EFLOATU 1220 /* `Underflow out of float`: + * A float-type decimal value is out of range + * (underflow). */ +# define EDBLO 1250 /* `Overflow out of double`: + * A double-type decimal value is out of range + * (overflow). */ +# define EDBLU 1260 /* `Underflow out of double`: + * A double-type decimal value is out of range + * (underflow). */ +# define ELDBLO 1270 /* `Overflow out of long double`: + * A long double-type decimal value is out of range + * (overflow). */ +# define ELDBLU 1280 /* `Underflow out of long double`: + * A long double-type decimal value is out of range + * (underflow). */ +# define NOTOPN 1300 /* `File not open`: + * The file is not open. */ +# define EBADF 1302 /* `Bad file number`: + * An output function was issued for an input-only file, + * or an input function was issued for an output-only + * file. */ +# define ECSPEC 1304 /* `Error in format`: + * An erroneous format was specified for an input/output + * function using format. */ + +/* Some more functions extracted from the 09.00 manual. */ + +# define EFIXEDO 1400 /* `Overflow out of __fixed` */ +# define EFIXEDU 1410 /* `Underflow out of __fixed` */ +# define EACCUMO 1420 /* `Overflow out of __accum` */ +# define EACCUMU 1430 /* `Underflow out of __accum` */ +# define ELFIXEDO 1440 /* `Overflow out of long __fixed` */ +# define ELFIXEDU 1450 /* `Underflow out of long __fixed` */ +# define ELACCUMO 1460 /* `Overflow out of long __accum` */ +# define ELACCUMU 1470 /* `Underflow out of long __accum` */ + +# define EMALRESM 2100 /* `Error in waiting semaphore`: + * Failed to define semaphore resources for malloc. */ +# define EMALFRSM 2101 /* `Error in signaling semaphore`: + * Failed to define semaphore resources for malloc. */ +# define ETOKRESM 2110 /* `Error in waiting semaphore`: + * Failed to define semaphore resources for strtok. */ +# define ETOKFRSM 2111 /* `Error in signaling semaphore`: + * Failed to release semaphore resources for malloc. */ +# define EIOBRESM 2120 /* `Error in waiting semaphore`: + * Failed to release semaphore resources + * for `_iob` (fopen). */ +# define EIOBFRSM 2121 /* `Error in signaling semaphore`: + * Failed to release semaphore resources + * for `_iob` (fopen). */ __END_DECLS #endif /* _ERRNO_H */ diff --git a/arch/all/core/include/iso646.h b/arch/all/core/include/iso646.h index 9db18fc..44f445c 100644 --- a/arch/all/core/include/iso646.h +++ b/arch/all/core/include/iso646.h @@ -25,20 +25,20 @@ # define _ISO646 1 # define __ISO646 1 # include <cdefs.h> -# ifndef __cplusplus +# if !__USE_CXX98 -# define and && -# define and_eq &= -# define or || -# define or_eq |= -# define not ! -# define not_eq != +# define and && +# define and_eq &= +# define or || +# define or_eq |= +# define not ! +# define not_eq != -# define bitand & -# define bitor | -# define xor ^ -# define xor_eq ^= -# define compl ~ +# define bitand & +# define bitor | +# define xor ^ +# define xor_eq ^= +# define compl ~ # endif #endif /* _ISO646_H */ diff --git a/arch/all/core/include/limits.h b/arch/all/core/include/limits.h index defa8c3..2087224 100644 --- a/arch/all/core/include/limits.h +++ b/arch/all/core/include/limits.h @@ -15,6 +15,9 @@ * * You should have received a copy of the GNU Lesser General Public License * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * + * These values are defined in the C standard, they do not need to have + * platform-specific constants! * ************************************************************************** */ #if !defined(_LIMITS_H) && !defined(_LIMITS_H_) && !defined(__LIMITS_H) \ && !defined(__LIMITS_H__) && !defined(_LIMITS) && !defined(__LIMITS) @@ -30,32 +33,32 @@ # define MB_LEN_MAX 1 /* Char limits */ -# define CHAR_BIT 8 -# define SCHAR_MIN -127 -# define SCHR_MAX +127 -# define UCHAR_MAX 255 +# define CHAR_BIT ( 8) +# define SCHAR_MIN (-127) +# define SCHAR_MAX (+127) +# define UCHAR_MAX ( 255) # define CHAR_MIN SCHAR_MIN # define CHAR_MAX SCHAR_MAX /* Short limits */ -# define SHRT_MIN -32767 -# define SHRT_MAX +32767 -# define USHRT_MAX 65535 +# define SHRT_MIN (-32767) +# define SHRT_MAX (+32767) +# define USHRT_MAX ( 65535) /* Int limits */ -# define INT_MIN -32767 -# define INT_MAX +32767 -# define UINT_MAX 65535 +# define INT_MIN (-32767) +# define INT_MAX (+32767) +# define UINT_MAX ( 65535) /* Long limits */ -# define LONG_MIN -2147483647 -# define LONG_MAX +2147483647 -# define ULONG_MAX 4294967295 +# define LONG_MIN (-2147483647) +# define LONG_MAX (+2147483647) +# define ULONG_MAX ( 4294967295) /* Long long limits */ -# define LLONG_MIN -9223372036854775807 -# define LLONG_MAX +9223372036854775807 -# define ULLONG_MAX 18446744073709551615 +# define LLONG_MIN (-9223372036854775807) +# define LLONG_MAX (+9223372036854775807) +# define ULLONG_MAX ( 18446744073709551615) #endif /* _LIMITS_H */ #ifndef _LIMITS_H diff --git a/arch/all/math/include/math.h b/arch/all/core/include/math.h index 5f26d40..5f26d40 100644 --- a/arch/all/math/include/math.h +++ b/arch/all/core/include/math.h diff --git a/arch/all/math/include/mathf.h b/arch/all/core/include/mathf.h index 9784825..9784825 100644 --- a/arch/all/math/include/mathf.h +++ b/arch/all/core/include/mathf.h diff --git a/arch/all/core/include/printf.h b/arch/all/core/include/printf.h index bbd434e..02f9a94 100644 --- a/arch/all/core/include/printf.h +++ b/arch/all/core/include/printf.h @@ -34,7 +34,7 @@ __BEGIN_DECLS /* ************************************************************************** */ __BEGIN_NAMESPACE_STD /* print in a string */ -# ifdef __STDC__ +# if __USE_C89 extern int sprintf(char __str[__notnull], const char __fmt[__notnull], ...) __THROW __nonnull(1) __nonnull(2) __format(printf, 2, 3); @@ -53,7 +53,7 @@ extern int vsnprintf OF((char __str[__notnull], size_t __size, __THROW __nonnull(1) __nonnull(3); /* print in a stream */ -# ifdef __STDC__ +# if __USE_C89 extern int printf(const char __fmt[__notnull], ...) __THROW __nonnull(1) __format(printf, 1, 2); extern int fprintf(FILE *__stream, const char *__fmt, ...) @@ -109,6 +109,9 @@ extern int find_printf_function OF((int __spec, extern int register_printf_function OF((int __spec, printf_callback_t *__func)) __THROW; +/* reset the callbacks */ +extern void reset_printf_functions OF((void)) __THROW; + __END_DECLS #endif /* _PRINTF_H */ #ifndef _PRINTF_H diff --git a/arch/casiowin/fxlib-libc/include/signal.h b/arch/all/core/include/signal.h index b3584f5..05febc6 100644 --- a/arch/casiowin/fxlib-libc/include/signal.h +++ b/arch/all/core/include/signal.h @@ -27,6 +27,9 @@ # include <cdefs.h> __BEGIN_NAMESPACE_STD +/* ************************************************************************** */ +/* Types and macros */ +/* ************************************************************************** */ /* `sig_atomic_t` is the standard type describing an integer that can be * accessed as an atomic entity, even in the presence of asynchronous * interrupts. */ @@ -37,7 +40,7 @@ typedef volatile int sig_atomic_t; * To the functions taking a pointer, instead of sending a real function, * you can send one of the `SIG_*` macros to make special actions. */ -typedef void __sighandler_t (int __sig); +typedef void __sighandler_t OF((int __sig)); # define SIG_ERR ((__sighandler_t)-1) /* Produce an error. */ # define SIG_DFL ((__sighandler_t) 0) /* Do the default action for @@ -52,13 +55,16 @@ typedef void __sighandler_t (int __sig); # define SIGINT 4 /* Interrupt. */ # define SIGSEGV 5 /* Invalid access to storage. */ # define SIGTERM 6 /* Program termination request. */ +/* ************************************************************************** */ +/* Main functions */ +/* ************************************************************************** */ +__BEGIN_DECLS -/* And here are the main functions. */ +/* Register a signal handler. */ -__BEGIN_DECLS +extern __sighandler_t signal OF((int __sig, __sighandler_t *__handler)) __THROW; -extern __sighandler_t signal OF((int __sig, __sighandler_t *__handler)) - __THROW; +/* Raise a signal. */ extern int raise OF((int __sig)) __THROW; diff --git a/arch/all/core/include/stdarg.h b/arch/all/core/include/stdarg.h index 74b33cc..8a63d0d 100644 --- a/arch/all/core/include/stdarg.h +++ b/arch/all/core/include/stdarg.h @@ -27,13 +27,38 @@ # include <cdefs.h> __BEGIN_DECLS -/* Check if we should define va_copy. */ +/* These macros define the variable argument list managing macros. + * The `_AP` (`ap` in documentation) argument is of type `va_list`. + * + * - `va_start` starts a list, so for example, if your function is the + * the following: + * + * my_function(type1 arg1, type2 arg2, type3 arg3, ...); + * + * To initialize, you will have to do `va_start(ap, arg3)`. + * + * - `va_end` ends a list, deallocating eventual resources. + * - `va_arg` obtains the next argument in the list, then goes after it. + * Use it this way: `var = va_arg(ap, type);` (where `type` is the type + * of `var`); + * - `va_copy` copies the variable argument list from this point. + * Don't forget to `va_end` the copy as well to be portable! + * + * As you could guess, it can be dangerous to use variable argument lists + * from objects compiled using other compilers, so be careful with this. */ + +# define va_start(_AP, _PARAM) __va_start(_AP, _PARAM) +# define va_end(_AP) __va_end(_AP) +# define va_arg(_AP, _TYPE) __va_arg(_AP, _TYPE) # if __USE_C99 || __USE_CXX11 -# define va_copy(_D, _S) __va_copy(_D, _S) +# define va_copy(_D, _S) __va_copy(_D, _S) # endif /* ************************************************************************** */ -/* Hitachi compiler's implementation */ +/* Renesas/Hitachi C/C++ Compiler */ /* ************************************************************************** */ +/* Each argument from the variable argument list of this compiler is aligned + * at 4-bits. */ + # if defined(__HITACHI__) typedef char *va_list; @@ -44,32 +69,106 @@ typedef char *va_list; (va_list)((__uintptr_t)(_ADDR) & ~3) /* Open and close a variable argument list. */ -# define va_start(_AP, _PARAM) \ +# define __va_start(_AP, _PARAM) \ (void)(_AP = __va_ceil((char*)&_PARAM + sizeof(_PARAM))) -# define va_end(_AP) +# define __va_end(_AP) (void)(_AP = NULL) /* Obtain an argument from the variable argument list. */ -# define va_arg(_AP, _TYPE) \ - (_TYPE)(*(_AP = __va_ceil(_AP + sizeof(_TYPE)), \ +# define __va_arg(_AP, _TYPE) \ + (*(_TYPE*)(_AP = __va_ceil(_AP + sizeof(_TYPE)), \ __va_floor(_AP - sizeof(_TYPE)))) /* Copy a variable argument list. */ -# define __va_copy(_D, _S) _D = _S +# define __va_copy(_D, _S) { _D = _S } /* ************************************************************************** */ -/* GCC's implementation */ +/* GNU Compiler Collection */ /* ************************************************************************** */ +/* GCC provides built-ins to make it easier. <3 */ + # elif defined(__GNUC__) typedef __builtin_va_list va_list; /* Open and close a variable argument list. */ -# define va_start(ap, param) __builtin_va_start(ap, param) -# define va_end(ap) __builtin_va_end(ap) +# define __va_start(_AP, _PARAM) __builtin_va_start(_AP, _PARAM) +# define __va_end(_AP) __builtin_va_end(_AP) /* Obtain an argument from the variable argument list. */ -# define va_arg(ap, param) __builtin_va_arg(ap, param) +# define __va_arg(_AP, _TYPE) __builtin_va_arg(_AP, _TYPE) /* Copy a variable argument list. */ -# define __va_copy(_D, _S) __builtin_va_copy(_D, _S) +# define __va_copy(_D, _S) __builtin_va_copy(_D, _S) +/* ************************************************************************** */ +/* Portable C/C++ Compiler */ +/* ************************************************************************** */ +/* PCC provides slightly different built-ins to make it easier, too <3 */ + +# elif defined(__PCC__) +typedef __builtin_va_list va_list; + +/* Open and close a variable argument list. */ +# define __va_start(_AP, _PARAM) __builtin_stdarg_start((_AP), _PARAM) +# define __va_end(_AP) __builtin_va_end((ap)) + +/* Obtain an argument from the variable argument list. */ +# define __va_arg(_AP, _TYPE) __builtin_va_arg((_AP), _TYPE) + +/* Copy a variable argument list. */ +# define __va_copy(_D, _S) __builtin_va_copy((_D), (_S)) +/* ************************************************************************** */ +/* Small Device C Compiler */ +/* ************************************************************************** */ +/* Well, this is a pretty straightforward implementation when you know SDCC + * more, I guess. Taken from there: + * http://svn.code.sf.net/p/sdcc/code/trunk/sdcc/device/include/stdarg.h */ + +# elif defined(__SDCC) +/* Start a list and get an argument, upwards and downwards version. */ +# define __va_start_up(_AP, _PARAM) \ + { _AP = (va_list)&_PARAM + sizeof(_PARAM); } +# define __va_start_dn(_AP, _PARAM) \ + { _AP = (va_list)&_PARAM; } + +# define __va_arg_up(_AP, _TYPE) \ + *((_TYPE __va_attr*)((_AP += sizeof(_TYPE)) - sizeof(_TYPE))) +# define __va_arg_dn(_AP, _TYPE) \ + *((_TYPE __va_attr*)(_AP -= sizeof(_TYPE))) + +/* Target-specific elements */ +# if defined(__SDCC_z80) || defined(__SDCC_z180) || defined(__SDCC_r2k) \ + || defined(__SDCC_r3ka) || defined(__SDCC_tlcs90) || defined(__SDCC_gbz80) \ + || defined(__SDCC_hc08) || defined(__SDCC_s08) || defined(__SDCC_stm8) +# define __va_attr /* no attribute for these architectures! */ +# define __va_start __va_start_up +# define __va_arg __va_arg_up + +# elif defined(__SDCC_ds390) || defined(__SDCC_ds400) +# define __va_attr /* no attribute for these architectures! */ + +# elif defined(__SDCC_USE_XSTACK) +# define __va_attr __pdata + +# endif + +/* Define the default attribute and va_list type. + * TODO: why is this the default attribute? */ +# ifndef __va_attr +# define __va_attr __data +# endif +typedef unsigned char __va_attr* va_list; + +# ifndef __va_start +# define __va_start __va_start_dn +# endif +# ifndef __va_end +# define __va_end(_AP) { _AP = NULL; } +# endif +# ifndef __va_arg +# define __va_arg __va_arg_dn +# endif +# ifndef __va_copy +# define __va_copy(_D, _S) { _D = _S; } +# endif + # endif __END_DECLS diff --git a/arch/all/core/include/stdbool.h b/arch/all/core/include/stdbool.h index 2f0a91b..9c63475 100644 --- a/arch/all/core/include/stdbool.h +++ b/arch/all/core/include/stdbool.h @@ -25,7 +25,7 @@ # define _STDBOOL 1 # define __STDBOOL 1 -# if !defined(__cplusplus) +# if !__USE_CXX98 # define bool _Bool # define true 1 diff --git a/arch/all/core/include/stddef.h b/arch/all/core/include/stddef.h index 25171f9..dad8175 100644 --- a/arch/all/core/include/stddef.h +++ b/arch/all/core/include/stddef.h @@ -25,31 +25,32 @@ # define _STDDEF 1 # define __STDDEF 1 # include <cdefs.h> +# include <bits/types.h> __BEGIN_NAMESPACE_STD /* `ptrdiff_t` is the signed integer type of the result of subtracting two * pointers. */ -typedef __ptrdiff_t ptrdiff_t; +typedef __intptr_t ptrdiff_t; /* `size_t` is the unsigned integer type that should be used to express * the size of a memory area within the address space. * It is defined in C99 as the result of the sizeof operator. */ -typedef __size_t size_t; +typedef __uintptr_t size_t; /* `wchar_t` is the integer type that should be used to express distinct codes * for all members of the largest extended character set supported by * libcarrot, so Unicode (32-bits). */ -typedef __wchar_t wchar_t; +typedef __uint_least32_t wchar_t; /* `NULL` expands to an implementation-defined null-pointer constant. * Use it to express an invalid pointer. */ # if defined(NULL) -/* `NULL` is defined by the architecture/platform header */ -# elif defined(__cplusplus) +/* `NULL` is defined by the architecture/platform */ +# elif __USE_CXX98 # define NULL (0) # else # define NULL ((void*)0) diff --git a/arch/all/core/include/stdint.h b/arch/all/core/include/stdint.h index f3f1f1b..af373e6 100644 --- a/arch/all/core/include/stdint.h +++ b/arch/all/core/include/stdint.h @@ -83,28 +83,28 @@ typedef __uintmax_t uintmax_t; # define INT8_WIDTH __INT8_WIDTH # define INT8_MIN __INT8_MIN # define INT8_MAX __INT8_MAX -# define UINT8_WIDTH __UINT8_WIDTH +# define UINT8_WIDTH __INT8_WIDTH # define UINT8_MIN __UINT8_MIN # define UINT8_MAX __UINT8_MAX # define INT16_WIDTH __INT16_WIDTH # define INT16_MIN __INT16_MIN # define INT16_MAX __INT16_MAX -# define UINT16_WIDTH __UINT16_WIDTH +# define UINT16_WIDTH __INT16_WIDTH # define UINT16_MIN __UINT16_MIN # define UINT16_MAX __UINT16_MAX # define INT32_WIDTH __INT32_WIDTH # define INT32_MIN __INT32_MIN # define INT32_MAX __INT32_MAX -# define UINT32_WIDTH __UINT32_WIDTH +# define UINT32_WIDTH __INT32_WIDTH # define UINT32_MIN __UINT32_MIN # define UINT32_MAX __UINT32_MAX # define INT64_WIDTH __INT64_WIDTH # define INT64_MIN __INT64_MIN # define INT64_MAX __INT64_MAX -# define UINT64_WIDTH __UINT64_WIDTH +# define UINT64_WIDTH __INT64_WIDTH # define UINT64_MIN __UINT64_MIN # define UINT64_MAX __UINT64_MAX @@ -113,28 +113,28 @@ typedef __uintmax_t uintmax_t; # define INT_LEAST8_WIDTH __INT_LEAST8_WIDTH # define INT_LEAST8_MIN __INT_LEAST8_MIN # define INT_LEAST8_MAX __INT_LEAST8_MAX -# define UINT_LEAST8_WIDTH __UINT_LEAST8_WIDTH +# define UINT_LEAST8_WIDTH __INT_LEAST8_WIDTH # define UINT_LEAST8_MIN __UINT_LEAST8_MIN # define UINT_LEAST8_MAX __UINT_LEAST8_MAX # define INT_LEAST16_WIDTH __INT_LEAST16_WIDTH # define INT_LEAST16_MIN __INT_LEAST16_MIN # define INT_LEAST16_MAX __INT_LEAST16_MAX -# define UINT_LEAST16_WIDTH __UINT_LEAST16_WIDTH +# define UINT_LEAST16_WIDTH __INT_LEAST16_WIDTH # define UINT_LEAST16_MIN __UINT_LEAST16_MIN # define UINT_LEAST16_MAX __UINT_LEAST16_MAX # define INT_LEAST32_WIDTH __INT_LEAST32_WIDTH # define INT_LEAST32_MIN __INT_LEAST32_MIN # define INT_LEAST32_MAX __INT_LEAST32_MAX -# define UINT_LEAST32_WIDTH __UINT_LEAST32_WIDTH +# define UINT_LEAST32_WIDTH __INT_LEAST32_WIDTH # define UINT_LEAST32_MIN __UINT_LEAST32_MIN # define UINT_LEAST32_MAX __UINT_LEAST32_MAX # define INT_LEAST64_WIDTH __INT_LEAST64_WIDTH # define INT_LEAST64_MIN __INT_LEAST64_MIN # define INT_LEAST64_MAX __INT_LEAST64_MAX -# define UINT_LEAST64_WIDTH __UINT_LEAST64_WIDTH +# define UINT_LEAST64_WIDTH __INT_LEAST64_WIDTH # define UINT_LEAST64_MIN __UINT_LEAST64_MIN # define UINT_LEAST64_MAX __UINT_LEAST64_MAX @@ -143,28 +143,28 @@ typedef __uintmax_t uintmax_t; # define INT_FAST8_WIDTH __INT_FAST8_WIDTH # define INT_FAST8_MIN __INT_FAST8_MIN # define INT_FAST8_MAX __INT_FAST8_MAX -# define UINT_FAST8_WIDTH __UINT_FAST8_WIDTH +# define UINT_FAST8_WIDTH __INT_FAST8_WIDTH # define UINT_FAST8_MIN __UINT_FAST8_MIN # define UINT_FAST8_MAX __UINT_FAST8_MAX # define INT_FAST16_WIDTH __INT_FAST16_WIDTH # define INT_FAST16_MIN __INT_FAST16_MIN # define INT_FAST16_MAX __INT_FAST16_MAX -# define UINT_FAST16_WIDTH __UINT_FAST16_WIDTH +# define UINT_FAST16_WIDTH __INT_FAST16_WIDTH # define UINT_FAST16_MIN __UINT_FAST16_MIN # define UINT_FAST16_MAX __UINT_FAST16_MAX # define INT_FAST32_WIDTH __INT_FAST32_WIDTH # define INT_FAST32_MIN __INT_FAST32_MIN # define INT_FAST32_MAX __INT_FAST32_MAX -# define UINT_FAST32_WIDTH __UINT_FAST32_WIDTH +# define UINT_FAST32_WIDTH __INT_FAST32_WIDTH # define UINT_FAST32_MIN __UINT_FAST32_MIN # define UINT_FAST32_MAX __UINT_FAST32_MAX # define INT_FAST64_WIDTH __INT_FAST64_WIDTH # define INT_FAST64_MIN __INT_FAST64_MIN # define INT_FAST64_MAX __INT_FAST64_MAX -# define UINT_FAST64_WIDTH __UINT_FAST64_WIDTH +# define UINT_FAST64_WIDTH __INT_FAST64_WIDTH # define UINT_FAST64_MIN __UINT_FAST64_MIN # define UINT_FAST64_MAX __UINT_FAST64_MAX @@ -173,7 +173,7 @@ typedef __uintmax_t uintmax_t; # define INTPTR_WIDTH __INTPTR_WIDTH # define INTPTR_MIN __INTPTR_MIN # define INTPTR_MAX __INTPTR_MAX -# define UINTPTR_WIDTH __UINTPTR_WIDTH +# define UINTPTR_WIDTH __INTPTR_WIDTH # define UINTPTR_MIN __UINTPTR_MIN # define UINTPTR_MAX __UINTPTR_MAX @@ -182,23 +182,23 @@ typedef __uintmax_t uintmax_t; # define INTMAX_WIDTH __INTMAX_WIDTH # define INTMAX_MIN __INTMAX_MIN # define INTMAX_MAX __INTMAX_MAX -# define UINTMAX_WIDTH __UINTMAX_WIDTH +# define UINTMAX_WIDTH __INTMAX_WIDTH # define UINTMAX_MIN __UINTMAX_MIN # define UINTMAX_MAX __UINTMAX_MAX /* For other types defined in `stddef.h`. */ -# define PTRDIFF_WIDTH __PTRDIFF_WIDTH -# define PTRDIFF_MIN __PTRDIFF_MIN -# define PTRDIFF_MAX __PTRDIFF_MAX +# define PTRDIFF_WIDTH __INTPTR_WIDTH +# define PTRDIFF_MIN __INTPTR_MIN +# define PTRDIFF_MAX __INTPTR_MAX -# define SIZE_WIDTH __SIZE_WIDTH -# define SIZE_MIN __SIZE_MIN -# define SIZE_MAX __SIZE_MAX +# define SIZE_WIDTH __UINTPTR_WIDTH +# define SIZE_MIN __UINTPTR_MIN +# define SIZE_MAX __UINTPTR_MAX -# define WCHAR_WIDTH __WCHAR_WIDTH -# define WCHAR_MIN __WCHAR_MIN -# define WCHAR_MAX __WCHAR_MAX +# define WCHAR_WIDTH __UINT32_WIDTH +# define WCHAR_MIN __UINT32_MIN +# define WCHAR_MAX __UINT32_MAX # endif diff --git a/arch/all/core/include/stdio.h b/arch/all/core/include/stdio.h index 474b14c..d594f75 100644 --- a/arch/all/core/include/stdio.h +++ b/arch/all/core/include/stdio.h @@ -30,6 +30,17 @@ __BEGIN_DECLS __BEGIN_NAMESPACE_STD /* ************************************************************************** */ +/* Semaphore interface */ +/* ************************************************************************** */ +/* This interface comes from the Hitachi/Renesas libc. + * TODO: maybe they're in the wrong header, as most of Renesas' + * `stdio.h` functions...? */ + +# if __USE_RENESAS +extern int wait_sem OF((int __num)) __THROW; +extern int signal_sem OF((int __num)) __THROW; +# endif +/* ************************************************************************** */ /* FILE utilities */ /* ************************************************************************** */ /* FILE type, actually hidden */ diff --git a/arch/all/core/include/stdlib.h b/arch/all/core/include/stdlib.h index 02dc60f..58fd8b2 100644 --- a/arch/all/core/include/stdlib.h +++ b/arch/all/core/include/stdlib.h @@ -113,8 +113,8 @@ int atexit OF((atexit_t *__func)) __THROW __nonnull(1); /* Exit */ -void exit OF((int __status)) __THROW; -void abort OF((void)) __THROW; +void __noreturn exit OF((int __status)) __THROW; +void __noreturn abort OF((void)) __THROW; __END_NAMESPACE_STD #endif /* _STDLIB_H */ diff --git a/arch/all/core/include/time.h b/arch/all/core/include/time.h new file mode 100644 index 0000000..0107572 --- /dev/null +++ b/arch/all/core/include/time.h @@ -0,0 +1,115 @@ +/* ***************************************************************************** + * time.h -- time thingies. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#if !defined(_TIME_H) && !defined(_TIME_H_) && !defined(__TIME_H) \ + && !defined(__TIME_H__) && !defined(_TIME) && !defined(__TIME) +# define _TIME_H 1 +# define _TIME_H_ 1 +# define __TIME_H 1 +# define __TIME_H__ 1 +# define _TIME 1 +# define __TIME 1 +# include <cdefs.h> +# include <stddef.h> +# include <bits/time.h> +# define __CLOCKS_PER_SEC CLOCKS_PER_SEC + +/* ************************************************************************** */ +/* Time types */ +/* ************************************************************************** */ +/* This type contains the processor time, i.e. the number of ticks (where + * `CLOCK_PER_SEC` represents the number of ticks that form a second). */ + +typedef __uint32_t clock_t; + +/* This type contains UNIX timestamps, i.e. the number of seconds since the + * Epoch. + * + * FIXME: Y2038 problem, should find a way to use 64-bit integer in pre-C99. */ + +typedef __uint32_t time_t; + +/* This structure holds the broken-down time (components of a calendar time). */ + +struct tm { + int tm_sec; /* seconds after the minute [0, 60] */ + int tm_min; /* minutes after the hour [0, 59] */ + int tm_hour; /* hours since midnight [0, 23] */ + int tm_mday; /* day of the month [0, 31] */ + int tm_mon; /* months since january [0, 11] */ + int tm_year; /* years since 1900 */ + int tm_wday; /* days since sunday [0, 6] */ + int tm_yday; /* days since january 1 [0, 365] */ + int tm_isdst; /* daylight saving time flag */ +}; +/* ************************************************************************** */ +/* Main functions */ +/* ************************************************************************** */ +/* This function to get the processor time. + * Divide the return value by `CLOCKS_PER_SEC` to get the number of seconds. */ + +extern __wur clock_t clock OF((void)) __THROW; + +/* Compute the difference between two calendar times. + * The returned value is the difference expressed in seconds. */ + +extern __pure double difftime OF((time_t __time1, time_t __time0)) __THROW; + +/* Correct a broken-down time, and calculate the timestamp out of it. */ + +extern __wur time_t mktime OF((struct tm *__timep)) __THROW; + +/* Get the current timestamp. */ + +extern time_t time OF((time_t *__timep)) __THROW; + +/* Get static strings out of broken-down time or timestamps. */ + +extern __wur char *asctime OF((const struct tm *__timep)) __THROW; +extern __wur char *ctime OF((const time_t *__timer)) __THROW; + +/* Get the broken-down time out of a timestamp, using the GMT or local time. */ + +extern __wur struct tm *gmtime OF((const time_t *__timer)) __THROW; +extern __wur struct tm *localtime OF((const time_t *__timer)) __THROW; + +/* Get a custom-format date string. */ + +extern size_t strftime OF((char *__restrict __s, + size_t __maxsize, const char *__restrict __format, + const struct tm *__restrict __timep)) __THROW; + +#endif /* _TIME_H */ +#ifndef _TIME_H +# define _TIME_H 1 +#endif +#ifndef _TIME_H_ +# define _TIME_H_ 1 +#endif +#ifndef __TIME_H +# define __TIME_H 1 +#endif +#ifndef __TIME_H__ +# define __TIME_H__ 1 +#endif +#ifndef _TIME +# define _TIME 1 +#endif +#ifndef __TIME +# define __TIME 1 +#endif diff --git a/arch/all/core/src/locales.c b/arch/all/core/src/locales.c new file mode 100644 index 0000000..b415c05 --- /dev/null +++ b/arch/all/core/src/locales.c @@ -0,0 +1,122 @@ +/* ***************************************************************************** + * locales.c -- localization register. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <locale.h> +#include <limits.h> +#include <string.h> + +/* ************************************************************************** */ +/* Built-in locales and registry */ +/* ************************************************************************** */ +/* Default 'C' locale, defined in the C standard. */ + +static const struct lconv c_locale = { + ".", "", "", "", "", "", "", "", "", + CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX, "", + CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX +}; + +/* Main registry. */ + +static const struct lconv *current_locales[5] = { + &c_locale, /* LC_COLLATE */ + &c_locale, /* LC_CTYPE */ + &c_locale, /* LC_MONETARY */ + &c_locale, /* LC_NUMERIC */ + &c_locale /* LC_TIME */ +}; +/* ************************************************************************** */ +/* Main functions */ +/* ************************************************************************** */ +/** + * setlocale: + * Set the current locale. + * + * @arg category the locale category to edit. + * @arg locale the identifier of the locale to set. + * @return a string if the locale was found, NULL otherwise. + */ + +char *setlocale(int category, const char *locale_name) +{ + static char opaque[2]; + const struct lconv *locale; + + /* select the locale */ + if (!locale_name[0] || !memcmp(locale_name, "C", 2)) { + memcpy(opaque, "C", 2); + locale = &c_locale; + } else return (NULL); + + /* set the locale */ + if (!category) { + current_locales[0] = locale; + current_locales[1] = locale; + current_locales[2] = locale; + current_locales[3] = locale; + current_locales[4] = locale; + } else if (category <= 5) + current_locales[category - 1] = locale; + + /* return the opaque string */ + return (opaque); +} + +/** + * localeconv: + * Get the locale numerical conversion thing. + * + * @return the conversion. + */ + +struct lconv *localeconv(void) +{ + static struct lconv locale; + const struct lconv *num = current_locales[LC_NUMERIC - 1]; + const struct lconv *mon = current_locales[LC_MONETARY - 1]; + + /* nonmonetary things */ + locale.decimal_point = num->decimal_point; + locale.thousands_sep = num->thousands_sep; + locale.grouping = num->grouping; + + /* monetary things */ + locale.mon_decimal_point = mon->mon_decimal_point; + locale.mon_thousands_sep = mon->mon_thousands_sep; + locale.mon_grouping = mon->mon_grouping; + locale.positive_sign = mon->positive_sign; + locale.negative_sign = mon->negative_sign; + locale.currency_symbol = mon->currency_symbol; + locale.frac_digits = mon->frac_digits; + locale.p_cs_precedes = mon->p_cs_precedes; + locale.n_cs_precedes = mon->n_cs_precedes; + locale.p_sep_by_space = mon->p_sep_by_space; + locale.n_sep_by_space = mon->n_sep_by_space; + locale.p_sign_posn = mon->p_sign_posn; + locale.n_sign_posn = mon->n_sign_posn; + locale.int_curr_symbol = mon->int_curr_symbol; + locale.int_frac_digits = mon->int_frac_digits; + locale.int_p_cs_precedes = mon->int_p_cs_precedes; + locale.int_n_cs_precedes = mon->int_n_cs_precedes; + locale.int_p_sep_by_space = mon->int_p_sep_by_space; + locale.int_n_sep_by_space = mon->int_n_sep_by_space; + locale.int_p_sign_posn = mon->int_p_sign_posn; + locale.int_n_sign_posn = mon->int_n_sign_posn; + + return (&locale); +} diff --git a/arch/all/core/src/stdio/default.c b/arch/all/core/src/stdio/default.c index 79705da..f960ff7 100644 --- a/arch/all/core/src/stdio/default.c +++ b/arch/all/core/src/stdio/default.c @@ -94,7 +94,7 @@ static int put_padding(FILE *stream, printf_t *info, * @return the number of written bytes. */ -static int printf_default_s(FILE *stream, printf_t *info, va_list ap) +int printf_default_s(FILE *stream, printf_t *info, va_list ap) { /* get the string and length */ const char *s = va_arg(ap, char*); @@ -116,7 +116,7 @@ static int printf_default_s(FILE *stream, printf_t *info, va_list ap) * @return the number of written bytes. */ -static int printf_default_c(FILE *stream, printf_t *info, va_list ap) +int printf_default_c(FILE *stream, printf_t *info, va_list ap) { /* get the character */ char character = va_arg(ap, int) & 0x7F; @@ -125,92 +125,3 @@ static int printf_default_c(FILE *stream, printf_t *info, va_list ap) int n = character != 0; return (put_padding(stream, info, &character, n)); } - -/** - * printf_default_percent: - * Print a percent '%' character. - * - * @arg stream the stream to write to. - * @arg info the format information. - * @arg ap the arguments pointer. - * @return the number of written bytes. - */ - -static int printf_default_percent(FILE *stream, printf_t *info, va_list ap) -{ - char percent = '%'; - - (void)info; (void)ap; - if (!fwrite(&percent, 1, 1, stream)) return (-1); - return (1); -} -/* ************************************************************************** */ -/* Get and set callbacks */ -/* ************************************************************************** */ -/** - * find_printf_function: - * Find a printf function. - * - * In order to later support additional specifications using registering, - * we should use a tab or something like this? - * - * @arg spec the specifier. - * @arg func the double pointer to the function. - * @return -1 if an error occured, 0 otherwise. - */ - -int find_printf_function(int spec, printf_callback_t **func) -{ - switch (spec) { - /* percent */ - case '%': *func = printf_default_percent; break; - -#if 0 - /* integer related callbacks */ - case 'd': case 'i': - *func = printf_default_d; break; - case 'u': *func = printf_default_u; break; - case 'x': case 'X': - *func = printf_default_x; break; - case 'o': *func = printf_default_o; break; - case 'p': *func = printf_default_p; break; - - /* floating-point related callbacks */ - case 'f': case 'F': /* float */ - *func = printf_default_f; break; - case 'e': case 'E': /* double */ - *func = printf_default_e; break; - case 'a': case 'A': /* double in hexadecimal notation? */ - *func = printf_default_a; break; - case 'g': case 'G': - *func = printf_default_g; break; - - /* fixed-point related callbacks */ - case 'r': *func = printf_default_r; break; /* __fixed */ - case 'a': *func = printf_default_a; break; /* __accum? (double hexa?!) */ - case 'P': *func = printf_default_p; break; /* __circ */ -#endif - /* string/character-related callbacks */ - case 's': *func = printf_default_s; break; - case 'c': *func = printf_default_c; break; - default: return (-1); - } - - return (0); -} - -/** - * register_printf_function: - * Register a printf function. - * - * @arg spec the specifier. - * @arg func the callback. - * @return 0 on success, -1 on failure. - */ - -int register_printf_function(int spec, printf_callback_t *func) -{ - (void)spec; - (void)func; - return (-1); -} diff --git a/arch/all/core/src/stdio/register.c b/arch/all/core/src/stdio/register.c new file mode 100644 index 0000000..ba2d206 --- /dev/null +++ b/arch/all/core/src/stdio/register.c @@ -0,0 +1,148 @@ +/* ***************************************************************************** + * stdio/register.c -- Manage printf callbacks. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include "stdio.h" +#include <string.h> +#include <ctype.h> + +/* ************************************************************************** */ +/* `printf` register */ +/* ************************************************************************** */ +/* The `printf` register keeps track of which specifier goes to where. */ + +struct printf_entry { + printf_callback_t *callback; +}; + +/* The register is here. (number of letters) * 2, for upper and lower case. */ + +static struct printf_entry printf_register[52]; +/* ************************************************************************** */ +/* Default callbacks */ +/* ************************************************************************** */ +/** + * printf_default_percent: + * Print a percent '%' character. + * + * @arg stream the stream to write to. + * @arg info the format information. + * @arg ap the arguments pointer. + * @return the number of written bytes. + */ + +static int printf_default_percent(FILE *stream, printf_t *info, va_list ap) +{ + char percent = '%'; + + (void)info; (void)ap; + if (!fwrite(&percent, 1, 1, stream)) return (-1); + return (1); +} +/* ************************************************************************** */ +/* Interact with the registers */ +/* ************************************************************************** */ +/** + * reset_printf_functions: + * Reset the printf functions. + */ + +void reset_printf_functions(void) +{ + /* set NULLs */ + memset(printf_register, 0, 52 * sizeof(struct printf_entry)); + +#if 0 + /* integer related callbacks */ + register_printf_function('d', printf_default_d); + register_printf_function('i', printf_default_i); + register_printf_function('u', printf_default_u); + register_printf_function('x', printf_default_x); + register_printf_function('X', printf_default_X); + register_printf_function('o', printf_default_o); + register_printf_function('p', printf_default_p); + + /* floating-point related callbacks */ + register_printf_function('F', printf_default_f); + register_printf_function('f', printf_default_f); + register_printf_function('E', printf_default_e); + register_printf_function('e', printf_default_e); + register_printf_function('A', printf_default_a); + register_printf_function('a', printf_default_a); + register_printf_function('G', printf_default_g); + register_printf_function('g', printf_default_g); + + /* Hitachi fixed-point related callbacks */ + register_printf_function('r', printf_default_r); /* __fixed */ + register_printf_function('a', printf_default_a); /* __accum */ + register_printf_function('P', printf_default_p); /* __circ */ +#endif + + /* string/character-related callbacks */ + register_printf_function('s', printf_default_s); + register_printf_function('c', printf_default_c); +} + +/** + * find_printf_function: + * Find a printf function. + * + * In order to later support additional specifications using registering, + * we should use a tab or something like this? + * + * @arg spec the specifier. + * @arg func the double pointer to the function. + * @return -1 if an error occured, 0 otherwise. + */ + +int find_printf_function(int spec, printf_callback_t **func) +{ + if (spec == '%') + *func = printf_default_percent; + else { + int lwrspec = tolower(spec), lwr = islower(spec) ? 26 : 0; + + /* check that it is a character */ + if (likely(lwrspec != spec || lwr)) + *func = printf_register[lwrspec - 'a' + (26 - lwr)].callback; + else return (-1); + } + + return (0); +} + +/** + * register_printf_function: + * Register a printf function. + * + * @arg spec the specifier. + * @arg func the callback. + * @return 0 on success, -1 on failure. + */ + +int register_printf_function(int spec, printf_callback_t *func) +{ + int lwrspec = tolower(spec), lwr = islower(spec) ? 26 : 0; + + /* check it's a character */ + if (likely(lwrspec != spec || lwr)) { + printf_register[lwrspec - 'a' + (26 - lwr)].callback = func; + return (0); + } + + return (-1); +} diff --git a/arch/all/core/src/stdio/stdio.h b/arch/all/core/src/stdio/stdio.h index 76e6852..fd5751a 100644 --- a/arch/all/core/src/stdio/stdio.h +++ b/arch/all/core/src/stdio/stdio.h @@ -41,5 +41,13 @@ struct _IO_FILE { /* other internal data */ long offset; }; +/* ************************************************************************** */ +/* #justprintfthings */ +/* ************************************************************************** */ +/* Callbacks. */ +# define __PRINTF_FUNC(_X) printf_callback_t printf_default_ ## _X; + +__PRINTF_FUNC(s) +__PRINTF_FUNC(c) #endif /* _LOCAL_STDIO_H */ diff --git a/arch/all/cpp/include/ios b/arch/all/cpp/include/ios index fde3b4a..67135c8 100644 --- a/arch/all/cpp/include/ios +++ b/arch/all/cpp/include/ios @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Lesser General Public License * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. * ************************************************************************** */ -#if defined(__cplusplus) && !defined(_IOS_HPP) && !defined(_IOS_) +#if __USE_CXX98 && !defined(_IOS_HPP) && !defined(_IOS_) # define _IOS_HPP 1 # define _IOS_ 1 # include <cdefs.h> diff --git a/arch/all/cpp/include/iosfwd b/arch/all/cpp/include/iosfwd index 38a2e68..6e8cd34 100644 --- a/arch/all/cpp/include/iosfwd +++ b/arch/all/cpp/include/iosfwd @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Lesser General Public License * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. * ************************************************************************** */ -#if defined(__cplusplus) && !defined(_IOSFWD_HPP) && !defined(_IOSFWD_) +#if __USE_CXX98 && !defined(_IOSFWD_HPP) && !defined(_IOSFWD_) # define _IOSFWD_HPP 1 # define _IOSFWD_ 1 # include <cdefs.h> diff --git a/arch/all/cpp/include/iostream b/arch/all/cpp/include/iostream index 48569c2..a155730 100644 --- a/arch/all/cpp/include/iostream +++ b/arch/all/cpp/include/iostream @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Lesser General Public License * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. * ************************************************************************** */ -#if !defined(_IOSTREAM_HPP) && !defined(_IOSTREAM_) +#if __USE_CXX98 && !defined(_IOSTREAM_) # define _IOSTREAM_HPP 1 # define _IOSTREAM_ 1 # include <iosfwd> diff --git a/arch/all/cpp/include/mystrbuf b/arch/all/cpp/include/mystrbuf index 0d69cb3..1e36d01 100644 --- a/arch/all/cpp/include/mystrbuf +++ b/arch/all/cpp/include/mystrbuf @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Lesser General Public License * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. * ************************************************************************** */ -#if defined(__cplusplus) && !defined(_MYSTRBUF_HPP) && !defined(_MYSTRBUF_) +#if __USE_CXX98 && !defined(_MYSTRBUF_HPP) && !defined(_MYSTRBUF_) # define _MYSTRBUF_HPP 1 # define _MYSTRBUF_ 1 diff --git a/arch/all/cpp/include/new b/arch/all/cpp/include/new index e412706..677a7d5 100644 --- a/arch/all/cpp/include/new +++ b/arch/all/cpp/include/new @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Lesser General Public License * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. * ************************************************************************** */ -#if defined(__cplusplus) && !defined(_NEW_HPP) && !defined(__NEW__) \ +#if __USE_CXX98 && !defined(_NEW_HPP) && !defined(__NEW__) \ && !defined(_NEW_) && !defined(__NEW_H) # define _NEW_HPP 1 # define __NEW__ 1 diff --git a/arch/all/cpp/include/streambuf b/arch/all/cpp/include/streambuf index 5690322..c98164d 100644 --- a/arch/all/cpp/include/streambuf +++ b/arch/all/cpp/include/streambuf @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Lesser General Public License * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. * ************************************************************************** */ -#if defined(__cplusplus) && !defined(_STREAMBUF_HPP) && !defined(_STREAMBUF_) +#if __USE_CXX98 && !defined(_STREAMBUF_HPP) && !defined(_STREAMBUF_) # define _STREAMBUF_HPP 1 # define _STREAMBUF_ 1 diff --git a/arch/all/cpp/include/string b/arch/all/cpp/include/string index 4566305..5d8920f 100644 --- a/arch/all/cpp/include/string +++ b/arch/all/cpp/include/string @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Lesser General Public License * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. * ************************************************************************** */ -#if defined(__cplusplus) && !defined(_STRING_HPP) && !defined(_STRING_) +#if __USE_CXX98 && !defined(_STRING_HPP) && !defined(_STRING_) # define _STRING_HPP 1 # define _STRING_ 1 # include <cdefs.h> diff --git a/arch/all/math/README.md b/arch/all/math/README.md deleted file mode 100644 index 920f86b..0000000 --- a/arch/all/math/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# `all/math` -- The mathematical functions. -This is the math extension to the libc core. diff --git a/arch/all/math/config.yml b/arch/all/math/config.yml deleted file mode 100644 index b25a8df..0000000 --- a/arch/all/math/config.yml +++ /dev/null @@ -1,4 +0,0 @@ -version: potatosdk-1.0 -description: The maths library. -lang: 'c' -arch: ['sh3', 'sh4a'] diff --git a/arch/casiowin-fxcg/config.yml b/arch/casiowin-fxcg/config.yml new file mode 100644 index 0000000..fae038c --- /dev/null +++ b/arch/casiowin-fxcg/config.yml @@ -0,0 +1,3 @@ +version: potatosdk-1.0 +arch: ['sh4a'] +main: ['casiowin-fxcg/fxlib-libc'] diff --git a/arch/casiowin/easy-input/README.md b/arch/casiowin/easy-input/README.md new file mode 100644 index 0000000..f1ff759 --- /dev/null +++ b/arch/casiowin/easy-input/README.md @@ -0,0 +1,6 @@ +# `casiowin/easy-input` -- Easy input. +This library was made by Louis "Dark Storm" Gatin for easy dialogs. +The original version was `3.2`. + +You can find the original library here: +http://www.planet-casio.com/Fr/logiciels/voir_un_logiciel_casio.php?showid=117 diff --git a/arch/casiowin/easy-input/config.yml b/arch/casiowin/easy-input/config.yml new file mode 100644 index 0000000..303dc2d --- /dev/null +++ b/arch/casiowin/easy-input/config.yml @@ -0,0 +1,4 @@ +version: potatosdk-1.0 +description: Easy input dialogs. +lang: 'c' +deps: ['casiowin/fxlib'] diff --git a/arch/casiowin/easy-input/include/EasyInput.h b/arch/casiowin/easy-input/include/EasyInput.h new file mode 100644 index 0000000..367758b --- /dev/null +++ b/arch/casiowin/easy-input/include/EasyInput.h @@ -0,0 +1,131 @@ +/* ***************************************************************************** + * EasyInput.h -- it's so eaaasyyy. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#if !defined(_EASYINPUT_H) && !defined(_EASYINPUT_H_) \ + && !defined(__EASYINPUT_H) && !defined(__EASYINPUT_H__) \ + && !defined(_EASYINPUT) && !defined(__EASYINPUT) +# define _EASYINPUT_H 1 +# define _EASYINPUT_H_ 1 +# define __EASYINPUT_H 1 +# define __EASYINPUT_H__ 1 +# define _EASYINPUT 1 +# define __EASYINPUT 1 +# include <cdefs.h> +# include <fxlib.h> + +/* ************************************************************************** */ +/* Settings, main operations */ +/* ************************************************************************** */ +/* Among the settings are: + * - the position you want to have the dialog (column, row); + * - the box length; + * - the alignment; + * - the start mode (alpha); + * - whether we want caps or not. + * + * Here are the different values for the start mode (alpha mode): */ + +enum __EI_ALPHA_MODE { + EI_NORMAL = 1, + EI_ALPHA = 2, + EI_ALPHA_LOCKED = 3 +}; + +/* Here are the different values for the alignment. */ + +enum __EI_ALIGN { + EI_ALIGN_LEFT = 1, + EI_ALIGN_CENTER = 2, + EI_ALIGN_RIGHT = 3 +}; + +/* Here are the different type of operations you can do using the + * `EI_manage_config` utility. */ + +enum __EI_PARAM_TYPE { + EI_GET_ALL = -1, + + EI_SET_COLUMN = 0, + EI_SET_ROW = 1, + EI_SET_BOX_LENGTH = 2, + EI_SET_ALIGN = 3, + EI_SET_START_MODE = 4, + EI_SET_Aa_KEY = 5 +}; + +/* And here is the configuration structure. */ + +typedef struct __EI_config { + unsigned int column, row; + unsigned int box_length; + unsigned int align; + unsigned int start_mode; + unsigned int Aa_key; +} EI_config; + +/* Initialize the settings, edit one parameter. */ + +extern void EI_init OF((void)) __THROW; +extern const void *EI_manage_config OF((enum __EI_PARAM_TYPE __param, + int __value)) __THROW; + +/* And here is the central function to get a string, hurray! */ + +extern char *EI_input_string OF((int __length, const char *__allowed)) __THROW; +/* ************************************************************************** */ +/* Private functions */ +/* ************************************************************************** */ +/* These are utilities the author left in the original public header. + * First, here is to check the string. */ + +extern int EI_str_length OF((const char *__str)); +extern int EI_check_char OF((char __c, const char *__allowed)); + +/* Manage the cursor. */ + +typedef struct { + int flashstyle; /* -1 if not flashing, else flashmode */ + int column; /* starts at 1 */ + int row; /* starts at 1 */ + int graphic_mode; +} EI_cursor_settings; + +extern int EI_Cursor_SetPosition OF((char __column, int __mode)); +extern int EI_Cursor_SetFlashOn OF((char __flashstyle)); +extern void EI_Cursor_SetFlashOff OF((void)); +extern int EI_Cursor_GetSettings OF((EI_cursor_settings *__cursor_settings)); + +#endif /* _EASYINPUT_H */ +#ifndef _EASYINPUT_H +# define _EASYINPUT_H 1 +#endif +#ifndef _EASYINPUT_H_ +# define _EASYINPUT_H_ 1 +#endif +#ifndef __EASYINPUT_H +# define __EASYINPUT_H 1 +#endif +#ifndef __EASYINPUT_H__ +# define __EASYINPUT_H__ 1 +#endif +#ifndef _EASYINPUT +# define _EASYINPUT 1 +#endif +#ifndef __EASYINPUT +# define __EASYINPUT 1 +#endif diff --git a/arch/casiowin/easy-input/src/_syscalls.S b/arch/casiowin/easy-input/src/_syscalls.S new file mode 100644 index 0000000..7cbcf8a --- /dev/null +++ b/arch/casiowin/easy-input/src/_syscalls.S @@ -0,0 +1,26 @@ +/* *****************************************************************************
+ * _syscalls.s -- Easy Input syscalls.
+ * Copyright (C) 2015-2016 Louis "Dark Storm" Gatin <l.gatin@neuf.fr>
+ * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
+ *
+ * This file is part of libcarrot.
+ * libcarrot is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 3.0 of the License,
+ * or (at your option) any later version.
+ *
+ * libcarrot is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>.
+ * ************************************************************************** */
+# include <fxlib/syscall.h>
+
+__SYSCALL(0x138, _EI_Cursor_SetPosition)
+__SYSCALL(0x80F, _EI_Cursor_GetSettings)
+__SYSCALL(0x811, _EI_Cursor_SetFlashOn)
+__SYSCALL(0x812, _EI_Cursor_SetFlashOff)
+__SYSCALL(0x910, _EI_KBD_PutKey)
diff --git a/arch/casiowin/easy-input/src/_syscalls.src b/arch/casiowin/easy-input/src/_syscalls.src new file mode 100644 index 0000000..b344e12 --- /dev/null +++ b/arch/casiowin/easy-input/src/_syscalls.src @@ -0,0 +1,36 @@ +; ******************************************************************************
+; _syscalls.s -- Easy Input syscalls.
+; Copyright (C) 2015-2016 Louis "Dark Storm" Gatin <l.gatin@neuf.fr>
+;
+; This file is part of libcarrot.
+; libcarrot is free software; you can redistribute it and/or modify it
+; under the terms of the GNU Lesser General Public License as published by
+; the Free Software Foundation; either version 3.0 of the License,
+; or (at your option) any later version.
+;
+; libcarrot is distributed in the hope that it will be useful,
+; but WITHOUT ANY WARRANTY; without even the implied warranty of
+; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+; See the GNU Lesser General Public License for more details.
+;
+; You should have received a copy of the GNU Lesser General Public License
+; along with the libcarrot; if not, see <http://www.gnu.org/licenses/>.
+; ******************************************************************************
+ .SECTION P,CODE,ALIGN=4
+
+ .MACRO SYSCALL FUNO, SYSCALLNAME, TAIL=nop
+ .export \SYSCALLNAME'
+\SYSCALLNAME'
+ mov.l #h'\FUNO, r0
+ mov.l #H'80010070, r2
+ jmp @r2
+ \TAIL'
+ .ENDM
+
+ SYSCALL 0910, _EI_KBD_PutKey
+ SYSCALL 0138, _EI_Cursor_SetPosition
+ SYSCALL 0811, _EI_Cursor_SetFlashOn
+ SYSCALL 0812, _EI_Cursor_SetFlashOff
+ SYSCALL 080F, _EI_Cursor_GetSettings
+
+ .END
diff --git a/arch/casiowin/easy-input/src/main.c b/arch/casiowin/easy-input/src/main.c new file mode 100644 index 0000000..79b0f5c --- /dev/null +++ b/arch/casiowin/easy-input/src/main.c @@ -0,0 +1,291 @@ +/* ***************************************************************************** + * main.c -- the easy input main file. + * Copyright (C) 2015-2016 Louis "Dark Storm" Gatin <l.gatin@neuf.fr> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <EasyInput.h> + +char *EI_input_string(int string_length, const char *chars_allowed) +{ + char *string = (void*)(0); + EI_config *config = (void*)(0); + EI_cursor_settings cursor_settings; + + unsigned int key = 0; + + int i; + int char_deleted = 0; + int text_displacement = 0; + int cap = 0; + + char arrow[] = {0xE6, 0x9A, 0}; + + + /* Get actual configuration */ + config = (EI_config*)EI_manage_config(EI_GET_ALL, 0); + + /* Allocate RAM for string */ + string = (char*)malloc(sizeof(char) * string_length + 1); + + /* Initialize string */ + for(i = 0; i <= string_length; i++) string[i] = 0; + + /* Setup cursor flash */ + switch(config->align) + { + default: + case EI_ALIGN_LEFT: + EI_Cursor_SetPosition(config->column, config->row); + break; + + case EI_ALIGN_CENTER: + EI_Cursor_SetPosition(config->column + (config->box_length >> 1), config->row); + break; + + case EI_ALIGN_RIGHT: + EI_Cursor_SetPosition(config->column + config->box_length - 1, config->row); + break; + } + + if(config->start_mode == EI_ALPHA_LOCKED) + { + EI_KBD_PutKey(KEY_CTRL_SHIFT, 0); + GetKey(&key); + } + + if(config->start_mode >= EI_ALPHA) + { + EI_KBD_PutKey(KEY_CTRL_ALPHA, 0); + GetKey(&key); + EI_Cursor_SetFlashOn(3); + } + else + { + EI_Cursor_SetFlashOn(0); + } + + + /* Main loop */ + i = 0; + while(key != KEY_CTRL_EXE && key != KEY_CTRL_AC) + { + EI_Cursor_GetSettings(&cursor_settings); + + if(cursor_settings.flashstyle == 3 && !cap) + EI_Cursor_SetFlashOn(4); + + GetKey(&key); /* Getting key pressed */ + + switch(key) /* Analyse key pressed */ + { + case KEY_CTRL_F1: + cap = !cap; + break; + + case KEY_CTRL_DEL: + if(i > 0) + { + i--; + string[i] = 0; + char_deleted = 1; + } + break; + + default: + /* Give correct value to keys with a non-ascii return values */ + if(key == KEY_CHAR_PLUS) key = '+'; + if(key == KEY_CHAR_MINUS || key == KEY_CHAR_PMINUS) key = '-'; + if(key == KEY_CHAR_MULT) key = '*'; + if(key == KEY_CHAR_DIV) key = '/'; + if(key == KEY_CHAR_ANS) key = '_'; + if(key == KEY_CTRL_XTT) key = '#'; + + if(key > 127) /* KEY_CTRL_***, etc. */ + break; + + if(key >= 'A' && key <= 'Z') key += !cap * 32; /* Switch between caps */ + + if(EI_check_char(key, chars_allowed) && EI_str_length(string) != string_length) /* Add char if we can */ + { + string[i] = key; + i++; + } + } + + switch(config->align) /* Print string */ + { + default: + case EI_ALIGN_LEFT: + if(EI_str_length(string) < config->box_length) + { + EI_Cursor_SetPosition(config->column, config->row); + Print((unsigned char*)string); + if(char_deleted && EI_str_length(string) != config->box_length - 1) + { + Print((unsigned char*)" "); + EI_Cursor_SetPosition(cursor_settings.column - 2, config->row); + char_deleted = 0; + } + } + else + { + EI_Cursor_SetPosition(config->column, config->row); + Print((unsigned char*)arrow); + Print((unsigned char*)(string + EI_str_length(string) - config->box_length + 2)); + } + break; + + case EI_ALIGN_CENTER: + if(EI_str_length(string) < config->box_length) + { + if(char_deleted && EI_str_length(string) != config->box_length - 1 && (config->box_length - EI_str_length(string)) >> 1 != ((config->box_length - EI_str_length(string) - 1) >> 1)) + { + EI_Cursor_SetPosition(config->column + ((config->box_length - EI_str_length(string)) >> 1) - 1, config->row); + Print((unsigned char*)" "); + Print((unsigned char*)string); + char_deleted = 0; + } + else if(char_deleted && EI_str_length(string) != config->box_length - 1 && (config->box_length - EI_str_length(string)) >> 1 == ((config->box_length - EI_str_length(string) - 1) >> 1)) + { + EI_Cursor_SetPosition(config->column + ((config->box_length - EI_str_length(string)) >> 1), config->row); + Print((unsigned char*)string); + Print((unsigned char*)" "); + EI_Cursor_SetPosition(cursor_settings.column - 2, config->row); + char_deleted = 0; + } + else + { + EI_Cursor_SetPosition(config->column + ((config->box_length - EI_str_length(string)) >> 1), config->row); + Print((unsigned char*)string); + } + } + else + { + EI_Cursor_SetPosition(config->column, config->row); + Print((unsigned char*)arrow); + Print((unsigned char*)(string + EI_str_length(string) - config->box_length + 2)); + } + break; + + case EI_ALIGN_RIGHT: + if(EI_str_length(string) < config->box_length) + { + EI_Cursor_SetPosition(config->column + config->box_length - EI_str_length(string) - (char_deleted && EI_str_length(string) != config->box_length - 1) - 1, config->row); + if(char_deleted && EI_str_length(string) != config->box_length - 1) + { + Print((unsigned char*)" "); + char_deleted = 0; + } + Print((unsigned char*)string); + } + else + { + EI_Cursor_SetPosition(config->column, config->row); + Print((unsigned char*)arrow); + Print((unsigned char*)(string + EI_str_length(string) - config->box_length + 2)); + } + break; + } + } + + /* Set off cursor mode */ + EI_Cursor_SetFlashOff(); + + + /* Return NULL in case of an input break */ + if(key == KEY_CTRL_AC) + { + free(string); + return (char*)(0); + } + + + /* Return the string */ + return string; +} + +const void *EI_manage_config(int parameter, int value) +{ + static EI_config config; + + if(value) + { + switch(parameter) + { + case EI_SET_COLUMN: config.column = value - 1; + break; + case EI_SET_ROW: config.row = value - 1; + break; + case EI_SET_BOX_LENGTH: config.box_length = (value < 3 ? 3 : value); /* Minimal size is 3 */ + break; + case EI_SET_ALIGN: config.align = value; + break; + case EI_SET_START_MODE: config.start_mode = value; + break; + case EI_SET_Aa_KEY: config.Aa_key = value; + break; + } + } + else + { + switch(parameter) + { + case EI_GET_ALL: return (const void*)(&config); + case EI_SET_COLUMN: return (const void*)&config.column; + case EI_SET_ROW: return (const void*)&config.row; + case EI_SET_BOX_LENGTH: return (const void*)&config.box_length; + case EI_SET_ALIGN: return (const void*)&config.align; + case EI_SET_START_MODE: return (const void*)&config.start_mode; + case EI_SET_Aa_KEY: return (const void*)&config.Aa_key; + } + } + + return (void*)(0); +} + +void EI_init(void) +{ + EI_manage_config(EI_SET_COLUMN, 1); + EI_manage_config(EI_SET_ROW, 1); + EI_manage_config(EI_SET_ALIGN, EI_ALIGN_LEFT); + EI_manage_config(EI_SET_START_MODE, EI_ALPHA_LOCKED); + EI_manage_config(EI_SET_BOX_LENGTH, 21); + EI_manage_config(EI_SET_Aa_KEY, KEY_CTRL_F1); +} + +int EI_str_length(const char *str) +{ + int i = 0; + + while(str[i]) i++; + + return i; +} + +int EI_check_char(char c, const char *chars_allowed) +{ + int i = 0; + + while(chars_allowed[i]) + { + if(c == chars_allowed[i]) + return 1; + i++; + } + + return 0; +} diff --git a/arch/casiowin/fxlib-libc/include/bits/time.h b/arch/casiowin/fxlib-libc/include/bits/time.h new file mode 100644 index 0000000..c9afd3c --- /dev/null +++ b/arch/casiowin/fxlib-libc/include/bits/time.h @@ -0,0 +1,25 @@ +/* ***************************************************************************** + * bits/time.h -- `time.h` platform-specific constants. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#ifndef _BITS_TIME_H +# define _BITS_TIME_H + +/* Number of ticks per second. */ +# define __CLOCKS_PER_SEC 120 + +#endif /* _BITS_TIME_H */ diff --git a/arch/casiowin/fxlib-libc/src/assert.c b/arch/casiowin/fxlib-libc/src/assert.c index 1b542dd..24c614c 100644 --- a/arch/casiowin/fxlib-libc/src/assert.c +++ b/arch/casiowin/fxlib-libc/src/assert.c @@ -23,17 +23,20 @@ #include <fxlib/display.h> /** - * __assert_popup: + * __assert_fail: * Make an assertion failed pop-up. * + * @arg expr the expression that failed. * @arg file the name/path to the source file. * @arg line the line number. - * @arg expr the expression string. + * @arg func the function name. */ -void __assert_popup(const char *file, int line, const char *expr) +void __assert_fail(const char *expr, const char *file, + unsigned int line, const char *func) { char f[22]; size_t n, fn; + (void)func; /* prepare the top line */ sprintf(f, "%d", line); @@ -54,5 +57,5 @@ void __assert_popup(const char *file, int line, const char *expr) locate(5, 3); Print((unsigned char*)"Exiting now."); /* exit */ - exit(0); + abort(); } diff --git a/arch/casiowin/fxlib-libc/src/dirent/error.c b/arch/casiowin/fxlib-libc/src/dirent/error.c index 8ec0b2e..c04b4b4 100644 --- a/arch/casiowin/fxlib-libc/src/dirent/error.c +++ b/arch/casiowin/fxlib-libc/src/dirent/error.c @@ -28,11 +28,6 @@ int __errno_from_fileerr(int ferr) { - switch (ferr) { - case IML_FILEERR_ENTRYNOTFOUND: - return (ENOENT); - /* TODO: add more */ - default: - return (EPERM); - } + (void)ferr; + return (NOTOPN); /* FIXME */ } diff --git a/arch/casiowin/fxlib-libc/src/dirent/open.c b/arch/casiowin/fxlib-libc/src/dirent/open.c index 27bd08f..0da36a1 100644 --- a/arch/casiowin/fxlib-libc/src/dirent/open.c +++ b/arch/casiowin/fxlib-libc/src/dirent/open.c @@ -19,6 +19,7 @@ #include "dirent.h" #include <stdlib.h> #include <string.h> +#define ENOMEM 10 /* FIXME */ /** * opendir: @@ -35,7 +36,7 @@ DIR *opendir(const char *path) /* get the FONTCHARACTER encoded path */ fsize = mbstowcs(NULL, path, 0); - if (fsize == (size_t)-1) { errno = EINVAL; return (NULL); } + if (fsize == (size_t)-1) { errno = EDOM; return (NULL); } fpath = malloc(fsize + 1); if (!fpath) { errno = ENOMEM; return (NULL); } diff --git a/arch/casiowin/fxlib/include/fxlib.h b/arch/casiowin/fxlib/include/fxlib.h index 79c93d0..bc6c954 100644 --- a/arch/casiowin/fxlib/include/fxlib.h +++ b/arch/casiowin/fxlib/include/fxlib.h @@ -28,6 +28,8 @@ # define __FXLIB_H__ 1 # define _FXLIB 1 # define __FXLIB 1 +# include <fxlib/cdefs.h> +# include <stdlib.h> /* All of the subheaders */ # include <fxlib/app.h> @@ -42,7 +44,6 @@ # include <fxlib/timer.h> /* `SetQuitHandler` function */ -# include <fxlib/cdefs.h> __BEGIN_NAMESPACE_FXLIB __BEGIN_DECLS diff --git a/arch/casiowin/fxlib/include/fxlib/app.h b/arch/casiowin/fxlib/include/fxlib/app.h index ff0ef63..6ec5bff 100644 --- a/arch/casiowin/fxlib/include/fxlib/app.h +++ b/arch/casiowin/fxlib/include/fxlib/app.h @@ -25,8 +25,8 @@ __BEGIN_DECLS /* Add-in e-strip information */ typedef struct { - uint16_t _unused; - uint16_t id; + __uint16_t _unused; + __uint16_t id; /* RAM address of the queried add-in in the add-in array */ void *addin_array_start; diff --git a/arch/casiowin/fxlib/include/fxlib/bcd.h b/arch/casiowin/fxlib/include/fxlib/bcd.h index 5b043bc..7046f8a 100644 --- a/arch/casiowin/fxlib/include/fxlib/bcd.h +++ b/arch/casiowin/fxlib/include/fxlib/bcd.h @@ -70,4 +70,5 @@ extern int BCD_GetNotANumberValue OF((const unsigned char *__value, __END_DECLS __END_NAMESPACE_FXLIB +# endif #endif /* _FXLIB_BCD_H */ diff --git a/arch/casiowin/fxlib/include/fxlib/cdefs.h b/arch/casiowin/fxlib/include/fxlib/cdefs.h index 33bf09a..ba6137f 100644 --- a/arch/casiowin/fxlib/include/fxlib/cdefs.h +++ b/arch/casiowin/fxlib/include/fxlib/cdefs.h @@ -27,7 +27,7 @@ # ifdef __END_NAMESPACE_FXLIB # undef __END_NAMESPACE_FXLIB # endif -# ifdef __cplusplus +# ifdef __USE_CXX98 # define __BEGIN_NAMESPACE_FXLIB /* namespace "fx" { */ # define __END_NAMESPACE_FXLIB /* } */ # else diff --git a/arch/casiowin/fxlib/include/fxlib/keyboard.h b/arch/casiowin/fxlib/include/fxlib/keyboard.h index a799789..e63f3d0 100644 --- a/arch/casiowin/fxlib/include/fxlib/keyboard.h +++ b/arch/casiowin/fxlib/include/fxlib/keyboard.h @@ -19,6 +19,7 @@ #ifndef _FXLIB_KEYBOARD_H # define _FXLIB_KEYBOARD_H 1 # include <fxlib/cdefs.h> +# include <keybios.h> __BEGIN_NAMESPACE_FXLIB __BEGIN_DECLS diff --git a/arch/casiowin/fxlib/include/fxlib/serial.h b/arch/casiowin/fxlib/include/fxlib/serial.h index 70f989c..63065a8 100644 --- a/arch/casiowin/fxlib/include/fxlib/serial.h +++ b/arch/casiowin/fxlib/include/fxlib/serial.h @@ -47,7 +47,7 @@ extern int Serial_ResetAndDisable OF((void)) __THROW; /* Set and get a serial interrupt handler */ -extern sinth_t Serial_GetInterruptHandler OF((int __type)) +extern sinth_t *Serial_GetInterruptHandler OF((int __type)) __THROW; extern int Serial_SetInterruptHandler OF((int __type, sinth_t *__handler)) __THROW __nonnull(2); @@ -62,7 +62,7 @@ extern void *Serial_CallTransmitIntHandler OF((void)) __THROW; /* ************************************************************************** */ /* Receive data */ extern int Serial_SpyByte OF((int __offset, unsigned char *__dest)) - __THROW __nonnull(1); + __THROW __nonnull(2); extern int Serial_ReadByte OF((unsigned char *__dest)) __THROW __nonnull(1); extern int Serial_ReadBytes OF((unsigned char *__dest, int __size, diff --git a/arch/casiowin/monochromelib/README.md b/arch/casiowin/monochromelib/README.md new file mode 100644 index 0000000..e515116 --- /dev/null +++ b/arch/casiowin/monochromelib/README.md @@ -0,0 +1,10 @@ +# `casiowin/monochromelib` -- an adaptation of PierrotLL's MonochromeLib. +In 2011, for [Gravity Duck][gduck], PierrotLL made a graphics library for the +fx-9860G, that he then posted independently and called +the [MonochromeLib][homepage]. + +This module is a portage of what he did (also including the header from +libmonochrome, the first portage on Linux of this library). + +[homepage]: http://www.planet-casio.com/Fr/logiciels/voir_un_logiciel_casio.php?showid=86 +[gduck]: http://www.planet-casio.com/Fr/programmes/programme1795-last-gravity-duck-pierrotll-a7.html diff --git a/arch/casiowin/monochromelib/config.yml b/arch/casiowin/monochromelib/config.yml new file mode 100644 index 0000000..d069913 --- /dev/null +++ b/arch/casiowin/monochromelib/config.yml @@ -0,0 +1,4 @@ +version: potatosdk-1.0 +description: Graphics library for the fx-9860G. +lang: 'c' +deps: ['casiowin/fxlib'] diff --git a/arch/casiowin/monochromelib/include/MonochromeLib.h b/arch/casiowin/monochromelib/include/MonochromeLib.h new file mode 100644 index 0000000..952004a --- /dev/null +++ b/arch/casiowin/monochromelib/include/MonochromeLib.h @@ -0,0 +1,19 @@ +/* ***************************************************************************** + * MonochromeLib.h -- MonochromeLib compatibility layer. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> diff --git a/arch/casiowin/monochromelib/include/monochrome.h b/arch/casiowin/monochromelib/include/monochrome.h new file mode 100644 index 0000000..9f5e2cf --- /dev/null +++ b/arch/casiowin/monochromelib/include/monochrome.h @@ -0,0 +1,165 @@ +/* ***************************************************************************** + * monochrome.h -- MonochromeLib [port] compatible interface. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#if !defined(_MONOCHROME_H) && !defined(MONOCHROMELIB) \ + && !defined(_MONOCHROMELIB_H) +# define _MONOCHROME_H 1 +# define MONOCHROMELIB 1 +# define _MONOCHROMELIB_H 1 +# include <cdefs.h> +# include <stdlib.h> +__BEGIN_DECLS + +/* ************************************************************************** */ +/* Constants */ +/* ************************************************************************** */ +/* Screen dimensions */ +# define ML_SCREEN_WIDTH 128 +# define ML_SCREEN_HEIGHT 64 + +/* Contrast */ +# define ML_CONTRAST_MIN 130 +# define ML_CONTRAST_NORMAL 168 +# define ML_CONTRAST_MAX 190 + +/* Colors */ +typedef enum __ML_Color { + ML_TRANSPARENT = -1, + ML_WHITE = 0, + ML_BLACK = 1, + ML_XOR = 2, + ML_CHECKER = 3, +} ML_Color; +/* ************************************************************************** */ +/* Main functions */ +/* ************************************************************************** */ +/* Get the VRAM address */ +extern char *ML_vram_address OF((void)) __THROW; +# define ML_vram_adress() ML_vram_address() + +/* Interact with the VRAM */ +extern void ML_clear_vram OF((void)) __THROW; +extern void ML_clear_screen OF((void)) __THROW; +extern void ML_display_vram OF((void)) __THROW; + +/* Set the contrast */ +extern void ML_set_contrast OF((unsigned char __contrast)) __THROW; +extern unsigned char ML_get_contrast OF((void)) __THROW __wur; + +/* Interact with a pixel in the VRAM */ +extern void ML_pixel OF((int __x, int __y, ML_Color __color)) __THROW; +extern void ML_point OF((int __x, int __y, int __width, ML_Color __color)) + __THROW; +extern ML_Color ML_pixel_test OF((int __x, int __y)) __THROW __wur; + +/* Draw a line in the VRAM */ +extern void ML_line OF((int __x1, int __y1, int __x2, int __y2, + ML_Color __color)) __THROW; +extern void ML_horizontal_line OF((int __y, int __x1, int __x2, + ML_Color __color)) __THROW; +extern void ML_vertical_line OF((int __x, int __y1, int __y2, + ML_Color __color)) __THROW; + +/* Draw a rectangle */ +extern void ML_rectangle OF((int __x1, int __y1, int __x2, int __y2, + int __border_width, ML_Color __border_color, ML_Color __fill_color)) + __THROW; + +/* Draw a polygon */ +extern void ML_polygon OF((const int *__x, const int *__y, + int __nb_vertices, ML_Color __color)) __THROW; +extern void ML_filled_polygon OF((const int *__x, const int *__y, + int __nb_vertices, ML_Color __color)) __THROW; + +/* Draw a circle */ +extern void ML_circle OF((int __x, int __y, int __radius, + ML_Color __color)) __THROW; +extern void ML_filled_circle OF((int __x, int __y, int __radius, + ML_Color __color)) __THROW; + +/* Draw an ellipse */ +extern void ML_ellipse OF((int __x, int __y, int __radius1, + int __radius2, ML_Color __color)) __THROW; +extern void ML_ellipse_in_rect OF((int __x1, int __y1, int __x2, int __y2, + ML_Color __color)) __THROW; + +extern void ML_filled_ellipse OF((int __x, int __y, int __radius1, + int __radius2, ML_Color __color)) __THROW; +extern void ML_filled_ellipse_in_rect OF((int __x, int __y, int __radius1, + int __radius2, ML_Color __color)) __THROW; + +/* Scroll the screen */ +extern void ML_horizontal_scroll OF((int __scroll)) __THROW; +extern void ML_vertical_scroll OF((int __scroll)) __THROW; + +/* Draw a BMP */ +extern void ML_bmp_or OF((const unsigned char __bmp[__notnull], int __x, + int __y, int __width, int __height)) __THROW __nonnull(1); +extern void ML_bmp_and OF((const unsigned char __bmp[__notnull], int __x, + int __y, int __width, int __height)) __THROW __nonnull(1); +extern void ML_bmp_xor OF((const unsigned char __bmp[__notnull], int __x, + int __y, int __width, int __height)) __THROW __nonnull(1); + +extern void ML_bmp_or_cl OF((const unsigned char __bmp[__notnull], int __x, + int __y, int __width, int __height)) __THROW __nonnull(1); +extern void ML_bmp_and_cl OF((const unsigned char __bmp[__notnull], int __x, + int __y, int __width, int __height)) __THROW __nonnull(1); +extern void ML_bmp_xor_cl OF((const unsigned char __bmp[__notnull], int __x, + int __y, int __width, int __height)) __THROW __nonnull(1); + +/* Draw a 8x8 BMP */ +extern void ML_bmp_8_or OF((const unsigned char __bmp[__notnull], int __x, + int __y)) __THROW __nonnull(1); +extern void ML_bmp_8_and OF((const unsigned char __bmp[__notnull], int __x, + int __y)) __THROW __nonnull(1); +extern void ML_bmp_8_xor OF((const unsigned char __bmp[__notnull], int __x, + int __y)) __THROW __nonnull(1); + +extern void ML_bmp_8_or_cl OF((const unsigned char __bmp[__notnull], int __x, + int __y)) __THROW __nonnull(1); +extern void ML_bmp_8_and_cl OF((const unsigned char __bmp[__notnull], int __x, + int __y)) __THROW __nonnull(1); +extern void ML_bmp_8_xor_cl OF((const unsigned char __bmp[__notnull], int __x, + int __y)) __THROW __nonnull(1); + +/* Draw a 16x16 BMP */ +extern void ML_bmp_16_or OF((const unsigned short __bmp[__notnull], int __x, + int __y)) __THROW __nonnull(1); +extern void ML_bmp_16_and OF((const unsigned short __bmp[__notnull], int __x, + int __y)) __THROW __nonnull(1); +extern void ML_bmp_16_xor OF((const unsigned short __bmp[__notnull], int __x, + int __y)) __THROW __nonnull(1); + +extern void ML_bmp_16_or_cl OF((const unsigned short __bmp[__notnull], int __x, + int __y)) __THROW __nonnull(1); +extern void ML_bmp_16_and_cl OF((const unsigned short __bmp[__notnull], int __x, + int __y)) __THROW __nonnull(1); +extern void ML_bmp_16_xor_cl OF((const unsigned short __bmp[__notnull], int __x, + int __y)) __THROW __nonnull(1); + +__END_DECLS +#endif /* _MONOCHROME_H */ +#ifndef _MONOCHROME_H +# define _MONOCHROME_H 1 +#endif +#ifndef MONOCHROMELIB +# define MONOCHROMELIB 1 +#endif +#ifndef _MONOCHROMELIB_H +# define _MONOCHROMELIB_H 1 +#endif diff --git a/arch/casiowin/monochromelib/src/bmp_16_and.c b/arch/casiowin/monochromelib/src/bmp_16_and.c new file mode 100644 index 0000000..d543d10 --- /dev/null +++ b/arch/casiowin/monochromelib/src/bmp_16_and.c @@ -0,0 +1,39 @@ +/* ***************************************************************************** + * bmp_16_and.c -- Display a 16x16 BMP, using ANDs. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_bmp_16_and(const unsigned short *bmp, int x, int y) +{ + unsigned long line; + char i, shift, begin=0, end=16, *screen, *p=(char*)&line+1; + if(!bmp || x<0 || x>112 || y<-15 || y>63) return; + if(y < 0) begin = -y; + if(y > 48) end = 64-y; + shift = 8-(x&7); + screen = ML_vram_adress()+(y+begin<<4)+(x>>3); + for(i=begin ; i<end ; i++) + { + line = ~((unsigned short)~bmp[i]<<shift); + screen[0] &= *p; + screen[1] &= *(p+1); + if(shift!=8) screen[2] &= *(p+2); + screen += 16; + } +} diff --git a/arch/casiowin/monochromelib/src/bmp_16_and_cl.c b/arch/casiowin/monochromelib/src/bmp_16_and_cl.c new file mode 100644 index 0000000..651029b --- /dev/null +++ b/arch/casiowin/monochromelib/src/bmp_16_and_cl.c @@ -0,0 +1,43 @@ +/* ***************************************************************************** + * bmp_16_and_cl.c -- Display a 16x16 BMP, using ANDs and clipping. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_bmp_16_and_cl(const unsigned short *bmp, int x, int y) +{ + unsigned long line; + char i, shift, begin=0, end=16, bool1=1, bool2=1, bool3=1, *screen, + *p=(char*)&line+1; + if(!bmp || x<-15 || x>127 || y<-15 || y>63) return; + if(y < 0) begin = -y; + if(y > 48) end = 64-y; + shift = 8-(x&7); + if(x < 0) bool1 = 0; + if(x<-8 || x>119) bool2 = 0; + if(x>111 || shift==8) bool3 = 0; + screen = ML_vram_adress()+(y+begin<<4)+(x>>3); + for(i=begin ; i<end ; i++) + { + line = ~((unsigned short)~bmp[i]<<shift); + if(bool1) screen[0] &= *p; + if(bool2) screen[1] &= *(p+1); + if(bool3) screen[2] &= *(p+2); + screen += 16; + } +} diff --git a/arch/casiowin/monochromelib/src/bmp_16_or.c b/arch/casiowin/monochromelib/src/bmp_16_or.c new file mode 100644 index 0000000..d2339a0 --- /dev/null +++ b/arch/casiowin/monochromelib/src/bmp_16_or.c @@ -0,0 +1,39 @@ +/* ***************************************************************************** + * bmp_16_or.c -- Display a 16x16 BMP, using ORs. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_bmp_16_or(const unsigned short *bmp, int x, int y) +{ + unsigned long line; + char i, shift, begin=0, end=16, *screen, *p=(char*)&line+1; + if(!bmp || x<0 || x>112 || y<-15 || y>63) return; + if(y < 0) begin = -y; + if(y > 48) end = 64-y; + shift = 8-(x&7); + screen = ML_vram_adress()+(y+begin<<4)+(x>>3); + for(i=begin ; i<end ; i++) + { + line = bmp[i]<<shift; + screen[0] |= *p; + screen[1] |= *(p+1); + if(shift!=8) screen[2] |= *(p+2); + screen += 16; + } +} diff --git a/arch/casiowin/monochromelib/src/bmp_16_or_cl.c b/arch/casiowin/monochromelib/src/bmp_16_or_cl.c new file mode 100644 index 0000000..2e688da --- /dev/null +++ b/arch/casiowin/monochromelib/src/bmp_16_or_cl.c @@ -0,0 +1,43 @@ +/* ***************************************************************************** + * bmp_16_or_cl.c -- Display a 16x16 BMP, using ORs and clipping. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_bmp_16_or_cl(const unsigned short *bmp, int x, int y) +{ + unsigned long line; + char i, shift, begin=0, end=16, bool1=1, bool2=1, bool3=1, *screen, + *p=(char*)&line+1; + if(!bmp || x<-15 || x>127 || y<-15 || y>63) return; + if(y < 0) begin = -y; + if(y > 48) end = 64-y; + shift = 8-(x&7); + if(x < 0) bool1 = 0; + if(x<-8 || x>119) bool2 = 0; + if(x>111 || shift==8) bool3 = 0; + screen = ML_vram_adress()+(y+begin<<4)+(x>>3); + for(i=begin ; i<end ; i++) + { + line = bmp[i]<<shift; + if(bool1) screen[0] |= *p; + if(bool2) screen[1] |= *(p+1); + if(bool3) screen[2] |= *(p+2); + screen += 16; + } +} diff --git a/arch/casiowin/monochromelib/src/bmp_16_xor.c b/arch/casiowin/monochromelib/src/bmp_16_xor.c new file mode 100644 index 0000000..e7e2a1b --- /dev/null +++ b/arch/casiowin/monochromelib/src/bmp_16_xor.c @@ -0,0 +1,39 @@ +/* ***************************************************************************** + * bmp_16_xor.c -- Display a 16x16 BMP, using XORs. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_bmp_16_xor(const unsigned short *bmp, int x, int y) +{ + unsigned long line; + char i, shift, begin=0, end=16, *screen, *p=(char*)&line+1; + if(!bmp || x<0 || x>112 || y<-15 || y>63) return; + if(y < 0) begin = -y; + if(y > 48) end = 64-y; + shift = 8-(x&7); + screen = ML_vram_adress()+(y+begin<<4)+(x>>3); + for(i=begin ; i<end ; i++) + { + line = bmp[i]<<shift; + screen[0] ^= *p; + screen[1] ^= *(p+1); + if(shift!=8) screen[2] ^= *(p+2); + screen += 16; + } +} diff --git a/arch/casiowin/monochromelib/src/bmp_16_xor_cl.c b/arch/casiowin/monochromelib/src/bmp_16_xor_cl.c new file mode 100644 index 0000000..0c425ce --- /dev/null +++ b/arch/casiowin/monochromelib/src/bmp_16_xor_cl.c @@ -0,0 +1,43 @@ +/* ***************************************************************************** + * bmp_16_xor_cl.c -- Display a 16x16 BMP, using XORs and clipping. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_bmp_16_xor_cl(const unsigned short *bmp, int x, int y) +{ + unsigned long line; + char i, shift, begin=0, end=16, bool1=1, bool2=1, bool3=1, *screen, + *p=(char*)&line+1; + if(!bmp || x<-15 || x>127 || y<-15 || y>63) return; + if(y < 0) begin = -y; + if(y > 48) end = 64-y; + shift = 8-(x&7); + if(x < 0) bool1 = 0; + if(x<-8 || x>119) bool2 = 0; + if(x>111 || shift==8) bool3 = 0; + screen = ML_vram_adress()+(y+begin<<4)+(x>>3); + for(i=begin ; i<end ; i++) + { + line = bmp[i]<<shift; + if(bool1) screen[0] ^= *p; + if(bool2) screen[1] ^= *(p+1); + if(bool3) screen[2] ^= *(p+2); + screen += 16; + } +} diff --git a/arch/casiowin/monochromelib/src/bmp_8_and.c b/arch/casiowin/monochromelib/src/bmp_8_and.c new file mode 100644 index 0000000..0484bff --- /dev/null +++ b/arch/casiowin/monochromelib/src/bmp_8_and.c @@ -0,0 +1,38 @@ +/* ***************************************************************************** + * bmp_8_and.c -- Display a 8x8 BMP, using ANDs. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_bmp_8_and(const unsigned char *bmp, int x, int y) +{ + unsigned short line; + char i, shift, begin=0, end=8, *screen, *p=(char*)&line; + if(!bmp || x<0 || x>120 || y<-7 || y>63) return; + if(y < 0) begin = -y; + if(y > 56) end = 64-y; + shift = 8-(x&7); + screen = ML_vram_adress()+(y+begin<<4)+(x>>3); + for(i=begin ; i<end ; i++) + { + line = ~((unsigned char)~bmp[i]<<shift); + screen[0] &= *p; + if(shift!=8) screen[1] &= *(p+1); + screen += 16; + } +} diff --git a/arch/casiowin/monochromelib/src/bmp_8_and_cl.c b/arch/casiowin/monochromelib/src/bmp_8_and_cl.c new file mode 100644 index 0000000..12dc97b --- /dev/null +++ b/arch/casiowin/monochromelib/src/bmp_8_and_cl.c @@ -0,0 +1,40 @@ +/* ***************************************************************************** + * bmp_8_and_cl.c -- Display a 8x8 BMP, using ANDs and clipping. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_bmp_8_and_cl(const unsigned char *bmp, int x, int y) +{ + unsigned short line; + char i, shift, begin=0, end=8, bool1=1, bool2=1, *screen, *p=(char*)&line; + if(!bmp || x<-7 || x>127 || y<-7 || y>63) return; + if(y < 0) begin = -y; + if(y > 56) end = 64-y; + shift = 8-(x&7); + if(x < 0) bool1 = 0; + if(x>120 || shift==8) bool2 = 0; + screen = ML_vram_adress()+(y+begin<<4)+(x>>3); + for(i=begin ; i<end ; i++) + { + line = ~((unsigned char)~bmp[i]<<shift); + if(bool1) screen[0] &= *p; + if(bool2) screen[1] &= *(p+1); + screen += 16; + } +} diff --git a/arch/casiowin/monochromelib/src/bmp_8_or.c b/arch/casiowin/monochromelib/src/bmp_8_or.c new file mode 100644 index 0000000..ba83f89 --- /dev/null +++ b/arch/casiowin/monochromelib/src/bmp_8_or.c @@ -0,0 +1,39 @@ +/* ***************************************************************************** + * bmp_8_or.c -- Display a 8x8 BMP, using ORs. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_bmp_8_or(const unsigned char *bmp, int x, int y) +{ + unsigned short line; + char i, shift, begin=0, end=8, *screen, *p=(char*)&line; + if(!bmp || x<0 || x>120 || y<-7 || y>63) return; + if(y < 0) begin = -y; + if(y > 56) end = 64-y; + shift = 8-(x&7); + screen = ML_vram_adress()+(y+begin<<4)+(x>>3); + for(i=begin ; i<end ; i++) + { + line = bmp[i]<<shift; + screen[0] |= *p; + if(shift!=8) screen[1] |= *(p+1); + screen += 16; + } +} + diff --git a/arch/casiowin/monochromelib/src/bmp_8_or_cl.c b/arch/casiowin/monochromelib/src/bmp_8_or_cl.c new file mode 100644 index 0000000..6319261 --- /dev/null +++ b/arch/casiowin/monochromelib/src/bmp_8_or_cl.c @@ -0,0 +1,40 @@ +/* ***************************************************************************** + * bmp_8_or_cl.c -- Display a 8x8 BMP, using ORs and clipping. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_bmp_8_or_cl(const unsigned char *bmp, int x, int y) +{ + unsigned short line; + char i, shift, begin=0, end=8, bool1=1, bool2=1, *screen, *p=(char*)&line; + if(!bmp || x<-7 || x>127 || y<-7 || y>63) return; + if(y < 0) begin = -y; + if(y > 56) end = 64-y; + shift = 8-(x&7); + if(x < 0) bool1 = 0; + if(x>120 || shift==8) bool2 = 0; + screen = ML_vram_adress()+(y+begin<<4)+(x>>3); + for(i=begin ; i<end ; i++) + { + line = bmp[i]<<shift; + if(bool1) screen[0] |= *p; + if(bool2) screen[1] |= *(p+1); + screen += 16; + } +} diff --git a/arch/casiowin/monochromelib/src/bmp_8_xor.c b/arch/casiowin/monochromelib/src/bmp_8_xor.c new file mode 100644 index 0000000..b0add7b --- /dev/null +++ b/arch/casiowin/monochromelib/src/bmp_8_xor.c @@ -0,0 +1,38 @@ +/* ***************************************************************************** + * bmp_8_xor.c -- Display a 8x8 BMP, using XOR. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_bmp_8_xor(const unsigned char *bmp, int x, int y) +{ + unsigned short line; + char i, shift, begin=0, end=8, *screen, *p=(char*)&line; + if(!bmp || x<0 || x>120 || y<-7 || y>63) return; + if(y < 0) begin = -y; + if(y > 56) end = 64-y; + shift = 8-(x&7); + screen = ML_vram_adress()+(y+begin<<4)+(x>>3); + for(i=begin ; i<end ; i++) + { + line = bmp[i]<<shift; + screen[0] ^= *p; + if(shift<8) screen[1] ^= *(p+1); + screen += 16; + } +} diff --git a/arch/casiowin/monochromelib/src/bmp_8_xor_cl.c b/arch/casiowin/monochromelib/src/bmp_8_xor_cl.c new file mode 100644 index 0000000..6940cbd --- /dev/null +++ b/arch/casiowin/monochromelib/src/bmp_8_xor_cl.c @@ -0,0 +1,40 @@ +/* ***************************************************************************** + * bmp_8_xor_cl.c -- Display a 8x8 BMP, using XOR and clipping. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_bmp_8_xor_cl(const unsigned char *bmp, int x, int y) +{ + unsigned short line; + char i, shift, begin=0, end=8, bool1=1, bool2=1, *screen, *p=(char*)&line; + if(!bmp || x<-7 || x>127 || y<-7 || y>63) return; + if(y < 0) begin = -y; + if(y > 56) end = 64-y; + shift = 8-(x&7); + if(x < 0) bool1 = 0; + if(x>120 || shift==8) bool2 = 0; + screen = ML_vram_adress()+(y+begin<<4)+(x>>3); + for(i=begin ; i<end ; i++) + { + line = bmp[i]<<shift; + if(bool1) screen[0] ^= *p; + if(bool2) screen[1] ^= *(p+1); + screen += 16; + } +} diff --git a/arch/casiowin/monochromelib/src/bmp_and.c b/arch/casiowin/monochromelib/src/bmp_and.c new file mode 100644 index 0000000..bcb0cc8 --- /dev/null +++ b/arch/casiowin/monochromelib/src/bmp_and.c @@ -0,0 +1,45 @@ +/* ***************************************************************************** + * bmp_and.c -- Display a BMP, using ANDs. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_bmp_and(const unsigned char *bmp, int x, int y, int width, int height) +{ + unsigned short line; + char shift, *screen, *p=(char*)&line; + int i, j, begin=0, end=height, real_width=(width-1>>3<<3)+8; + if(!bmp || x<0 || x>128-width || y<1-height || y>63 || width<1 || height<1) return; + if(y < 0) begin = -y; + if(y+height > 64) end = 64-y; + shift = 8-(x&7); + screen = ML_vram_adress()+(y+begin<<4)+(x>>3); + for(i=begin ; i<end ; i++) + { + for(j=0 ; j<width-1>>3 ; j++) + { + line = ~((unsigned char)~bmp[i*(real_width>>3)+j]<<shift); + screen[j] &= *p; + if(shift!=8) screen[j+1] &= *(p+1); + } + line = ~((unsigned char)~(bmp[i*(real_width>>3)+j] | (unsigned char)-1>>8-(width&7))<<shift); + screen[j] &= *p; + if(shift!=8 && x+real_width<129) screen[j+1] &= *(p+1); + screen += 16; + } +} diff --git a/arch/casiowin/monochromelib/src/bmp_and_cl.c b/arch/casiowin/monochromelib/src/bmp_and_cl.c new file mode 100644 index 0000000..a6416b2 --- /dev/null +++ b/arch/casiowin/monochromelib/src/bmp_and_cl.c @@ -0,0 +1,68 @@ +/* ***************************************************************************** + * bmp_and_cl.c -- Display a BMP, using ANDs and clipping. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_bmp_and_cl(const unsigned char *bmp, int x, int y, int width, int height) +{ + unsigned short line; + char shift, *screen, *p; + int i, j, real_width, begin_x, end_x, begin_y, end_y; + char bool1=1, bool2=1, bool3; + if(!bmp || x<1-width || x>127 || y<1-height || y>63 || height<1 || width<1) return; + p = (char*)&line; + real_width = (width-1>>3<<3)+8; + if(y < 0) begin_y = -y; + else begin_y = 0; + if(y+height > 64) end_y = 64-y; + else end_y = height; + shift = 8-(x&7); + if(x<0) + { + begin_x = -x>>3; + if(shift != 8) bool1 = 0; + } else begin_x = 0; + if(x+real_width > 128) end_x = 15-(x>>3), bool2 = 0; + else end_x = real_width-1>>3; + bool3 = (end_x == real_width-1>>3); + screen = ML_vram_adress()+(y+begin_y<<4)+(x>>3); + + for(i=begin_y ; i<end_y ; i++) + { + if(begin_x < end_x) + + { + line = ~((unsigned char)~bmp[i*(real_width>>3)+begin_x]<<shift); + if(bool1) screen[begin_x] &= *p; + if(shift!=8) screen[begin_x+1] &= *(p+1); + for(j=begin_x+1 ; j<end_x ; j++) + { + line = ~((unsigned char)~bmp[i*(real_width>>3)+j]<<shift); + screen[j] &= *p; + if(shift!=8) screen[j+1] &= *(p+1); + } + } + line = (unsigned char)~bmp[i*(real_width>>3)+end_x]; + if(bool3) line &= -1<<real_width-width; + line = ~(line << shift); + if(begin_x < end_x || bool1) screen[end_x] &= *p; + if(bool2) screen[end_x+1] &= *(p+1); + screen += 16; + } +} diff --git a/arch/casiowin/monochromelib/src/bmp_or.c b/arch/casiowin/monochromelib/src/bmp_or.c new file mode 100644 index 0000000..f5ed2ba --- /dev/null +++ b/arch/casiowin/monochromelib/src/bmp_or.c @@ -0,0 +1,45 @@ +/* ***************************************************************************** + * bmp_or.c -- Display a BMP, using ORs. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_bmp_or(const unsigned char *bmp, int x, int y, int width, int height) +{ + unsigned short line; + char shift, *screen, *p=(char*)&line; + int i, j, begin=0, end=height, real_width=(width-1>>3<<3)+8; + if(!bmp || x<0 || x>128-width || y<1-height || y>63 || width<1 || height<1) return; + if(y < 0) begin = -y; + if(y+height > 64) end = 64-y; + shift = 8-(x&7); + screen = ML_vram_adress()+(y+begin<<4)+(x>>3); + for(i=begin ; i<end ; i++) + { + for(j=0 ; j<width-1>>3 ; j++) + { + line = bmp[i*(real_width>>3)+j]<<shift; + screen[j] |= *p; + if(shift!=8) screen[j+1] |= *(p+1); + } + line = (bmp[i*(real_width>>3)+j] & -1<<(real_width-width))<<shift; + screen[j] |= *p; + if(shift!=8 && x+real_width<129) screen[j+1] |= *(p+1); + screen += 16; + } +} diff --git a/arch/casiowin/monochromelib/src/bmp_or_cl.c b/arch/casiowin/monochromelib/src/bmp_or_cl.c new file mode 100644 index 0000000..df054b1 --- /dev/null +++ b/arch/casiowin/monochromelib/src/bmp_or_cl.c @@ -0,0 +1,67 @@ +/* ***************************************************************************** + * bmp_or_cl.c -- Display a BMP, using ORs and clipping. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_bmp_or_cl(const unsigned char *bmp, int x, int y, int width, int height) +{ + unsigned short line; + char shift, *screen, *p; + int i, j, real_width, begin_x, end_x, begin_y, end_y; + char bool1=1, bool2=1, bool3; + if(!bmp || x<1-width || x>127 || y<1-height || y>63 || height<1 || width<1) return; + p = (char*)&line; + real_width = (width-1>>3<<3)+8; + if(y < 0) begin_y = -y; + else begin_y = 0; + if(y+height > 64) end_y = 64-y; + else end_y = height; + shift = 8-(x&7); + if(x<0) + { + begin_x = -x>>3; + if(shift != 8) bool1 = 0; + } else begin_x = 0; + if(x+real_width > 128) end_x = 15-(x>>3), bool2 = 0; + else end_x = real_width-1>>3; + bool3 = (end_x == real_width-1>>3); + screen = ML_vram_adress()+(y+begin_y<<4)+(x>>3); + + for(i=begin_y ; i<end_y ; i++) + { + if(begin_x < end_x) + { + line = bmp[i*(real_width>>3)+begin_x] << shift; + if(bool1) screen[begin_x] |= *p; + if(shift!=8) screen[begin_x+1] |= *(p+1); + for(j=begin_x+1 ; j<end_x ; j++) + { + line = bmp[i*(real_width>>3)+j] << shift; + screen[j] |= *p; + if(shift!=8) screen[j+1] |= *(p+1); + } + } + line = bmp[i*(real_width>>3)+end_x]; + if(bool3) line &= -1<<real_width-width; + line <<= shift; + if(begin_x < end_x || bool1) screen[end_x] |= *p; + if(bool2) screen[end_x+1] |= *(p+1); + screen += 16; + } +} diff --git a/arch/casiowin/monochromelib/src/bmp_xor.c b/arch/casiowin/monochromelib/src/bmp_xor.c new file mode 100644 index 0000000..b34f8aa --- /dev/null +++ b/arch/casiowin/monochromelib/src/bmp_xor.c @@ -0,0 +1,45 @@ +/* ***************************************************************************** + * bmp_xor.c -- Display a BMP, using XORs. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_bmp_xor(const unsigned char *bmp, int x, int y, int width, int height) +{ + unsigned short line; + char shift, *screen, *p=(char*)&line; + int i, j, begin=0, end=height, real_width=(width-1>>3<<3)+8; + if(!bmp || x<0 || x>128-width || y<1-height || y>63 || width<1 || height<1) return; + if(y < 0) begin = -y; + if(y+height > 64) end = 64-y; + shift = 8-(x&7); + screen = ML_vram_adress()+(y+begin<<4)+(x>>3); + for(i=begin ; i<end ; i++) + { + for(j=0 ; j<width-1>>3 ; j++) + { + line = bmp[i*(real_width>>3)+j]<<shift; + screen[j] ^= *p; + if(shift!=8) screen[j+1] ^= *(p+1); + } + line = (bmp[i*(real_width>>3)+j] & -1<<(real_width-width))<<shift; + screen[j] ^= *p; + if(shift!=8 && x+real_width<129) screen[j+1] ^= *(p+1); + screen += 16; + } +} diff --git a/arch/casiowin/monochromelib/src/bmp_xor_cl.c b/arch/casiowin/monochromelib/src/bmp_xor_cl.c new file mode 100644 index 0000000..8ebd71c --- /dev/null +++ b/arch/casiowin/monochromelib/src/bmp_xor_cl.c @@ -0,0 +1,67 @@ +/* ***************************************************************************** + * bmp_xor_cl.c -- Display a BMP, using XORs and clipping. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_bmp_xor_cl(const unsigned char *bmp, int x, int y, int width, int height) +{ + unsigned short line; + char shift, *screen, *p; + int i, j, real_width, begin_x, end_x, begin_y, end_y; + char bool1=1, bool2=1, bool3; + if(!bmp || x<1-width || x>127 || y<1-height || y>63 || height<1 || width<1) return; + p = (char*)&line; + real_width = (width-1>>3<<3)+8; + if(y < 0) begin_y = -y; + else begin_y = 0; + if(y+height > 64) end_y = 64-y; + else end_y = height; + shift = 8-(x&7); + if(x<0) + { + begin_x = -x>>3; + if(shift != 8) bool1 = 0; + } else begin_x = 0; + if(x+real_width > 128) end_x = 15-(x>>3), bool2 = 0; + else end_x = real_width-1>>3; + bool3 = (end_x == real_width-1>>3); + screen = ML_vram_adress()+(y+begin_y<<4)+(x>>3); + + for(i=begin_y ; i<end_y ; i++) + { + if(begin_x < end_x) + { + line = bmp[i*(real_width>>3)+begin_x] << shift; + if(bool1) screen[begin_x] ^= *p; + if(shift!=8) screen[begin_x+1] ^= *(p+1); + for(j=begin_x+1 ; j<end_x ; j++) + { + line = bmp[i*(real_width>>3)+j] << shift; + screen[j] ^= *p; + if(shift!=8) screen[j+1] ^= *(p+1); + } + } + line = bmp[i*(real_width>>3)+end_x]; + if(bool3) line &= -1<<real_width-width; + line <<= shift; + if(begin_x < end_x || bool1) screen[end_x] ^= *p; + if(bool2) screen[end_x+1] ^= *(p+1); + screen += 16; + } +} diff --git a/arch/casiowin/monochromelib/src/circle.c b/arch/casiowin/monochromelib/src/circle.c new file mode 100644 index 0000000..827c96c --- /dev/null +++ b/arch/casiowin/monochromelib/src/circle.c @@ -0,0 +1,63 @@ +/* ***************************************************************************** + * circle.c -- Display a circle. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_circle(int x, int y, int radius, ML_Color color) +{ + int plot_x, plot_y, d; + + if(radius < 0) return; + plot_x = 0; + plot_y = radius; + d = 1 - radius; + + ML_pixel(x, y+plot_y, color); + if(radius) + { + ML_pixel(x, y-plot_y, color); + ML_pixel(x+plot_y, y, color); + ML_pixel(x-plot_y, y, color); + } + while(plot_y > plot_x) + { + if(d < 0) + d += 2*plot_x+3; + else + { + d += 2*(plot_x-plot_y)+5; + plot_y--; + } + plot_x++; + if(plot_y >= plot_x) + { + ML_pixel(x+plot_x, y+plot_y, color); + ML_pixel(x-plot_x, y+plot_y, color); + ML_pixel(x+plot_x, y-plot_y, color); + ML_pixel(x-plot_x, y-plot_y, color); + } + if(plot_y > plot_x) + { + ML_pixel(x+plot_y, y+plot_x, color); + ML_pixel(x-plot_y, y+plot_x, color); + ML_pixel(x+plot_y, y-plot_x, color); + ML_pixel(x-plot_y, y-plot_x, color); + } + } +} diff --git a/arch/casiowin/monochromelib/src/clear_screen.c b/arch/casiowin/monochromelib/src/clear_screen.c new file mode 100644 index 0000000..ac22fd1 --- /dev/null +++ b/arch/casiowin/monochromelib/src/clear_screen.c @@ -0,0 +1,35 @@ +/* ***************************************************************************** + * clear_screen.c -- Clear the screen. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_clear_screen() +{ + char *LCD_register_selector = (char*)0xB4000000, *LCD_data_register = (char*)0xB4010000; + int i, j; + for(i=0 ; i<64 ; i++) + { + *LCD_register_selector = 4; + *LCD_data_register = i|192; + *LCD_register_selector = 4; + *LCD_data_register = 0; + *LCD_register_selector = 7; + for(j=0 ; j<16 ; j++) *LCD_data_register = 0; + } +} diff --git a/arch/casiowin/monochromelib/src/clear_vram.c b/arch/casiowin/monochromelib/src/clear_vram.c new file mode 100644 index 0000000..489ea6d --- /dev/null +++ b/arch/casiowin/monochromelib/src/clear_vram.c @@ -0,0 +1,35 @@ +/* ***************************************************************************** + * clear_vram.c -- Clear the VRAM. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_clear_vram() +{ + int i, end, *pointer_long, vram; + char *pointer_byte; + vram = (int)ML_vram_adress(); + end = 4-vram&3; + pointer_byte = (char*)vram; + for(i=0 ; i<end ; i++) pointer_byte[i] = 0; + pointer_long = (int*) (vram+end); + for(i=0 ; i<255 ; i++) pointer_long[i] = 0; + pointer_byte += 1020+end; + end = vram&3; + for(i=0 ; i<end ; i++) pointer_byte[i] = 0; +} diff --git a/arch/casiowin/monochromelib/src/display_vram.c b/arch/casiowin/monochromelib/src/display_vram.c new file mode 100644 index 0000000..895e7a5 --- /dev/null +++ b/arch/casiowin/monochromelib/src/display_vram.c @@ -0,0 +1,36 @@ +/* ***************************************************************************** + * display_vram.c -- Display the VRAM. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_display_vram() +{ + char *LCD_register_selector = (char*)0xB4000000, *LCD_data_register = (char*)0xB4010000, *vram; + int i, j; + vram = ML_vram_adress(); + for(i=0 ; i<64 ; i++) + { + *LCD_register_selector = 4; + *LCD_data_register = i|192; + *LCD_register_selector = 4; + *LCD_data_register = 0; + *LCD_register_selector = 7; + for(j=0 ; j<16 ; j++) *LCD_data_register = *vram++; + } +} diff --git a/arch/casiowin/monochromelib/src/ellipse.c b/arch/casiowin/monochromelib/src/ellipse.c new file mode 100644 index 0000000..6434e71 --- /dev/null +++ b/arch/casiowin/monochromelib/src/ellipse.c @@ -0,0 +1,68 @@ +/* ***************************************************************************** + * ellipse.c -- Display an ellipse + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_ellipse(int x, int y, int radius1, int radius2, ML_Color color) +{ + int plot_x, plot_y; + float d1, d2; + if(radius1 < 1 || radius2 < 1) return; + plot_x = 0; + plot_y = radius2; + d1 = radius2*radius2 - radius1*radius1*radius2 + radius1*radius1/4; + ML_pixel(x, y+plot_y, color); + ML_pixel(x, y-plot_y, color); + while(radius1*radius1*(plot_y-.5) > radius2*radius2*(plot_x+1)) + { + if(d1 < 0) + { + d1 += radius2*radius2*(2*plot_x+3); + plot_x++; + } else { + d1 += radius2*radius2*(2*plot_x+3) + radius1*radius1*(-2*plot_y+2); + plot_x++; + plot_y--; + } + ML_pixel(x+plot_x, y+plot_y, color); + ML_pixel(x-plot_x, y+plot_y, color); + ML_pixel(x+plot_x, y-plot_y, color); + ML_pixel(x-plot_x, y-plot_y, color); + } + d2 = radius2*radius2*(plot_x+.5)*(plot_x+.5) + radius1*radius1*(plot_y-1)*(plot_y-1) - radius1*radius1*radius2*radius2; + while(plot_y > 0) + { + if(d2 < 0) + { + d2 += radius2*radius2*(2*plot_x+2) + radius1*radius1*(-2*plot_y+3); + plot_y--; + plot_x++; + } else { + d2 += radius1*radius1*(-2*plot_y+3); + plot_y--; + } + ML_pixel(x+plot_x, y+plot_y, color); + ML_pixel(x-plot_x, y+plot_y, color); + if(plot_y > 0) + { + ML_pixel(x+plot_x, y-plot_y, color); + ML_pixel(x-plot_x, y-plot_y, color); + } + } +} diff --git a/arch/casiowin/monochromelib/src/ellipse_in_rect.c b/arch/casiowin/monochromelib/src/ellipse_in_rect.c new file mode 100644 index 0000000..b74533e --- /dev/null +++ b/arch/casiowin/monochromelib/src/ellipse_in_rect.c @@ -0,0 +1,40 @@ +/* ***************************************************************************** + * ellipse_in_rect.c -- Display an ellipse in a rectangle. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_ellipse_in_rect(int x1, int y1, int x2, int y2, ML_Color color) +{ + int radius1, radius2; + if(x1 > x2) + { + int tmp = x1; + x1 = x2; + x2 = tmp; + } + if(y1 > y2) + { + int tmp = y1; + y1 = y2; + y2 = tmp; + } + radius1 = (x2-x1)/2; + radius2 = (y2-y1)/2; + ML_ellipse(x1+radius1, y1+radius2, radius1, radius2, color); +} diff --git a/arch/casiowin/monochromelib/src/filled_circle.c b/arch/casiowin/monochromelib/src/filled_circle.c new file mode 100644 index 0000000..cf616fd --- /dev/null +++ b/arch/casiowin/monochromelib/src/filled_circle.c @@ -0,0 +1,49 @@ +/* ***************************************************************************** + * filled_circle.c -- Display a filled circle. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_filled_circle(int x, int y, int radius, ML_Color color) +{ + int plot_x, plot_y, d; + + if(radius < 0) return; + plot_x = 0; + plot_y = radius; + d = 1 - radius; + + ML_horizontal_line(y, x-plot_y, x+plot_y, color); + while(plot_y > plot_x) + { + if(d < 0) + d += 2*plot_x+3; + else { + d += 2*(plot_x-plot_y)+5; + plot_y--; + ML_horizontal_line(y+plot_y+1, x-plot_x, x+plot_x, color); + ML_horizontal_line(y-plot_y-1, x-plot_x, x+plot_x, color); + } + plot_x++; + if(plot_y >= plot_x) + { + ML_horizontal_line(y+plot_x, x-plot_y, x+plot_y, color); + ML_horizontal_line(y-plot_x, x-plot_y, x+plot_y, color); + } + } +} diff --git a/arch/casiowin/monochromelib/src/filled_ellipse.c b/arch/casiowin/monochromelib/src/filled_ellipse.c new file mode 100644 index 0000000..d2149ca --- /dev/null +++ b/arch/casiowin/monochromelib/src/filled_ellipse.c @@ -0,0 +1,62 @@ +/* ***************************************************************************** + * filled_ellipse.c -- Display a filled ellipse. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_filled_ellipse(int x, int y, int radius1, int radius2, ML_Color color) +{ + int plot_x, plot_y; + float d1, d2; + if(radius1 < 1 || radius2 < 1) return; + plot_x = 0; + plot_y = radius2; + d1 = radius2*radius2 - radius1*radius1*radius2 + radius1*radius1/4; + while(radius1*radius1*(plot_y-.5) > radius2*radius2*(plot_x+1)) + { + if(d1 < 0) + { + d1 += radius2*radius2*(2*plot_x+3); + plot_x++; + } else { + d1 += radius2*radius2*(2*plot_x+3) + radius1*radius1*(-2*plot_y+2); + ML_horizontal_line(y+plot_y, x-plot_x, x+plot_x, color); + ML_horizontal_line(y-plot_y, x-plot_x, x+plot_x, color); + plot_x++; + plot_y--; + } + } + ML_horizontal_line(y+plot_y, x-plot_x, x+plot_x, color); + ML_horizontal_line(y-plot_y, x-plot_x, x+plot_x, color); + d2 = radius2*radius2*(plot_x+.5)*(plot_x+.5) + radius1*radius1*(plot_y-1)*(plot_y-1) - radius1*radius1*radius2*radius2; + while(plot_y > 0) + { + if(d2 < 0) + { + d2 += radius2*radius2*(2*plot_x+2) + radius1*radius1*(-2*plot_y+3); + plot_y--; + plot_x++; + } else { + d2 += radius1*radius1*(-2*plot_y+3); + plot_y--; + } + ML_horizontal_line(y+plot_y, x-plot_x, x+plot_x, color); + if(plot_y > 0) + ML_horizontal_line(y-plot_y, x-plot_x, x+plot_x, color); + } +} diff --git a/arch/casiowin/monochromelib/src/filled_ellipse_in_rect.c b/arch/casiowin/monochromelib/src/filled_ellipse_in_rect.c new file mode 100644 index 0000000..bf250f6 --- /dev/null +++ b/arch/casiowin/monochromelib/src/filled_ellipse_in_rect.c @@ -0,0 +1,40 @@ +/* ***************************************************************************** + * filled_ellipse_in_rect.c -- Display a filled ellipse in a rectangle. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_filled_ellipse_in_rect(int x1, int y1, int x2, int y2, ML_Color color) +{ + int radius1, radius2; + if(x1 > x2) + { + int tmp = x1; + x1 = x2; + x2 = tmp; + } + if(y1 > y2) + { + int tmp = y1; + y1 = y2; + y2 = tmp; + } + radius1 = (x2-x1)/2; + radius2 = (y2-y1)/2; + ML_filled_ellipse(x1+radius1, y1+radius2, radius1, radius2, color); +} diff --git a/arch/casiowin/monochromelib/src/filled_polygon.c b/arch/casiowin/monochromelib/src/filled_polygon.c new file mode 100644 index 0000000..85f8c35 --- /dev/null +++ b/arch/casiowin/monochromelib/src/filled_polygon.c @@ -0,0 +1,100 @@ +/* ***************************************************************************** + * filled_polygon.c -- Display a filled polygon. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +static int ML_filled_polygon_quicksord_partition(int *t, int p, int r) +{ + int i, j, x, tmp; + j = p - 1; + x = t[r]; + for(i=p ; i<r ; i++) + { + if(x > t[i]) + { + j++; + tmp = t[j]; + t[j] = t[i]; + t[i] = tmp; + } + } + t[r] = t[j+1]; + t[j+1] = x; + return j + 1; +} + +static void ML_filled_polygon_quicksord(int* t, int p, int r) +{ + int q; + if(p < r) + { + q = ML_filled_polygon_quicksord_partition(t, p, r); + ML_filled_polygon_quicksord(t, p, q-1); + ML_filled_polygon_quicksord(t, q+1, r); + } +} + + +void ML_filled_polygon(const int *x, const int *y, int nb_vertices, ML_Color color) +{ + int i, j, dx, dy, ymin, ymax; + int *cut_in_line, nb_cut; + if(nb_vertices < 3) return; + cut_in_line = malloc(nb_vertices*sizeof(int)); + if(!cut_in_line) return; + ymin = ymax = y[0]; + for(i=1 ; i<nb_vertices ; i++) + { + if(y[i] < ymin) ymin = y[i]; + if(y[i] > ymax) ymax = y[i]; + } + for(i=ymin ; i<=ymax ; i++) + { + nb_cut = 0; + for(j=0 ; j<nb_vertices ; j++) + { + if((y[j]<=i && y[(j+1)%nb_vertices]>=i) || (y[j]>=i && y[(j+1)%nb_vertices]<=i)) + { + dy = abs(y[j]-y[(j+1)%nb_vertices]); + if(dy) + { + dx = x[(j+1)%nb_vertices]-x[j]; + cut_in_line[nb_cut] = x[j] + rnd(abs(i-y[j]+sgn(i-y[j])/2)*dx/dy); + nb_cut++; + } + } + } + ML_filled_polygon_quicksord(cut_in_line, 0, nb_cut-1); + j = 0; + while(j<nb_cut-2 && cut_in_line[j]==cut_in_line[j+1]) j++; + while(j < nb_cut) + { + if(j == nb_cut-1) ML_horizontal_line(i, cut_in_line[j-1]+1, cut_in_line[j], color); + else + { + dx = 1; + while(j+dx<nb_cut-1 && cut_in_line[j+dx]==cut_in_line[j+dx+1]) dx++; + ML_horizontal_line(i, cut_in_line[j], cut_in_line[j+dx], color); + j += dx; + } + j++; + } + } + free(cut_in_line); +} diff --git a/arch/casiowin/monochromelib/src/get_contrast.c b/arch/casiowin/monochromelib/src/get_contrast.c new file mode 100644 index 0000000..ad19f78 --- /dev/null +++ b/arch/casiowin/monochromelib/src/get_contrast.c @@ -0,0 +1,27 @@ +/* ***************************************************************************** + * get_contrast.c -- Get the screen contrast. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +unsigned char ML_get_contrast() +{ + char *LCD_register_selector = (char*)0xB4000000, *LCD_data_register = (char*)0xB4010000; + *LCD_register_selector = 6; + return *LCD_data_register; +} diff --git a/arch/casiowin/monochromelib/src/horizontal_line.c b/arch/casiowin/monochromelib/src/horizontal_line.c new file mode 100644 index 0000000..cdfffc9 --- /dev/null +++ b/arch/casiowin/monochromelib/src/horizontal_line.c @@ -0,0 +1,86 @@ +/* ***************************************************************************** + * horizontal_line.c -- Draw a horizontal line. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_horizontal_line(int y, int x1, int x2, ML_Color color) +{ + int i; + char checker; + char* vram = ML_vram_adress(); + if(y&~63 || (x1<0 && x2<0) || (x1>127 && x2>127)) return; + if(x1 > x2) + { + i = x1; + x1 = x2; + x2 = i; + } + if(x1 < 0) x1 = 0; + if(x2 > 127) x2 = 127; + switch(color) + { + case ML_BLACK: + if(x1>>3 != x2>>3) + { + vram[(y<<4)+(x1>>3)] |= 255 >> (x1&7); + vram[(y<<4)+(x2>>3)] |= 255 << 7-(x2&7); + for(i=(x1>>3)+1 ; i<x2>>3 ; i++) + vram[(y<<4) + i] = 255; + } + else vram[(y<<4)+(x1>>3)] |= (255>>(x1%8 + 7-x2%8))<<(7-(x2&7)); + break; + case ML_WHITE: + if(x1>>3 != x2>>3) + { + vram[(y<<4)+(x1>>3)] &= 255 << 8-(x1&7); + vram[(y<<4)+(x2>>3)] &= 255 >> 1+(x2&7); + for(i=(x1>>3)+1 ; i<x2>>3 ; i++) + vram[(y<<4) + i] = 0; + } + else vram[(y<<4)+(x1>>3)] &= (255<<8-(x1&7)) | (255>>1+(x2&7)); + break; + case ML_XOR: + if(x1>>3 != x2>>3) + { + vram[(y<<4)+(x1>>3)] ^= 255 >> (x1&7); + vram[(y<<4)+(x2>>3)] ^= 255 << 7-(x2&7); + for(i=(x1>>3)+1 ; i<(x2>>3) ; i++) + vram[(y<<4) + i] ^= 255; + } + else vram[(y<<4)+(x1>>3)] ^= (255>>((x1&7) + 7-(x2&7)))<<(7-(x2&7)); + break; + case ML_CHECKER: + checker = (y&1 ? 85 : 170); + if(x1>>3 != x2>>3) + { + vram[(y<<4)+(x1>>3)] &= 255 << 8-(x1&7); + vram[(y<<4)+(x2>>3)] &= 255 >> 1+(x2&7); + vram[(y<<4)+(x1>>3)] |= checker & 255>>(x1&7); + vram[(y<<4)+(x2>>3)] |= checker & 255<<7-(x2&7); + for(i=(x1>>3)+1 ; i<x2>>3 ; i++) + vram[(y<<4) + i] = checker; + } + else + { + vram[(y<<4)+(x1>>3)] &= (255<<8-(x1&7)) | (255>>1+(x2&7)); + vram[(y<<4)+(x1>>3)] |= checker & (255>>(x1%8 + 7-x2%8))<<(7-(x2&7)); + } + break; + } +} diff --git a/arch/casiowin/monochromelib/src/horizontal_scroll.c b/arch/casiowin/monochromelib/src/horizontal_scroll.c new file mode 100644 index 0000000..22c0122 --- /dev/null +++ b/arch/casiowin/monochromelib/src/horizontal_scroll.c @@ -0,0 +1,47 @@ +/* ***************************************************************************** + * horizontal_scroll.c -- Scroll the screen. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_horizontal_scroll(int scroll) +{ + int i, j; + char line[16], shift, *vram; + unsigned char next; + unsigned short word; + vram = ML_vram_adress(); + scroll %= 128; + shift = 8-(scroll&7); + for(i=0 ; i<64 ; i++) + { + for(j=0 ; j<16 ; j++) line[j] = vram[(i<<4)+((j-(scroll>>3)+15)&15)]; + next = line[15]; + vram[(i<<4)+15] = 0; + for(j=15 ; j>0 ; j--) + { + word = next << shift; + next = line[j-1]; + vram[(i<<4)+j] |= *((char*)&word+1); + vram[(i<<4)+j-1] = *((char*)&word); + } + word = next << shift; + vram[(i<<4)] |= *((char*)&word+1); + vram[(i<<4)+15] |= *((char*)&word); + } +} diff --git a/arch/casiowin/monochromelib/src/line.c b/arch/casiowin/monochromelib/src/line.c new file mode 100644 index 0000000..d1a66b7 --- /dev/null +++ b/arch/casiowin/monochromelib/src/line.c @@ -0,0 +1,64 @@ +/* ***************************************************************************** + * line.c -- Draw a line. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_line(int x1, int y1, int x2, int y2, ML_Color color) +{ + int i, x, y, dx, dy, sx, sy, cumul; + x = x1; + y = y1; + dx = x2 - x1; + dy = y2 - y1; + sx = sgn(dx); + sy = sgn(dy); + dx = abs(dx); + dy = abs(dy); + ML_pixel(x, y, color); + if(dx > dy) + { + cumul = dx / 2; + for(i=1 ; i<dx ; i++) + { + x += sx; + cumul += dy; + if(cumul > dx) + { + cumul -= dx; + y += sy; + } + ML_pixel(x, y, color); + } + } + else + { + cumul = dy / 2; + for(i=1 ; i<dy ; i++) + { + y += sy; + cumul += dx; + if(cumul > dy) + { + cumul -= dy; + x += sx; + } + ML_pixel(x, y, color); + } + } +} diff --git a/arch/casiowin/monochromelib/src/pixel.c b/arch/casiowin/monochromelib/src/pixel.c new file mode 100644 index 0000000..94e0fe4 --- /dev/null +++ b/arch/casiowin/monochromelib/src/pixel.c @@ -0,0 +1,42 @@ +/* ***************************************************************************** + * pixel.c -- Interact with a pixel. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_pixel(int x, int y, ML_Color color) +{ + char* vram = ML_vram_adress(); + if(x&~127 || y&~63) return; + switch(color) + { + case ML_BLACK: + vram[(y<<4)+(x>>3)] |= 128>>(x&7); + break; + case ML_WHITE: + vram[(y<<4)+(x>>3)] &= ~(128>>(x&7)); + break; + case ML_XOR: + vram[(y<<4)+(x>>3)] ^= 128>>(x&7); + break; + case ML_CHECKER: + if(y&1^x&1) vram[(y<<4)+(x>>3)] &= ~(128>>(x&7)); + else vram[(y<<4)+(x>>3)] |= 128>>(x&7); + break; + } +} diff --git a/arch/casiowin/monochromelib/src/pixel_test.c b/arch/casiowin/monochromelib/src/pixel_test.c new file mode 100644 index 0000000..4c5b1aa --- /dev/null +++ b/arch/casiowin/monochromelib/src/pixel_test.c @@ -0,0 +1,30 @@ +/* ***************************************************************************** + * pixel_test.c -- Test a pixel. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +ML_Color ML_pixel_test(int x, int y) +{ + char *vram, byte; + if(x&~127 || y&~63) return ML_TRANSPARENT; + vram = ML_vram_adress(); + byte = 1<<(7-(x&7)); + return (vram[(y<<4)+(x>>3)] & byte ? ML_BLACK : ML_WHITE); + +} diff --git a/arch/casiowin/monochromelib/src/point.c b/arch/casiowin/monochromelib/src/point.c new file mode 100644 index 0000000..d4236a8 --- /dev/null +++ b/arch/casiowin/monochromelib/src/point.c @@ -0,0 +1,33 @@ +/* ***************************************************************************** + * point.c -- Draw a dot. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_point(int x, int y, int width, ML_Color color) +{ + if(width < 1) return; + if(width == 1) ML_pixel(x, y, color); + else + { + int padding, pair; + padding = width>>1; + pair = !(width&1); + ML_rectangle(x-padding+pair, y-padding+pair, x+padding, y+padding, 0, 0, color); + } +} diff --git a/arch/casiowin/monochromelib/src/polygon.c b/arch/casiowin/monochromelib/src/polygon.c new file mode 100644 index 0000000..26bd946 --- /dev/null +++ b/arch/casiowin/monochromelib/src/polygon.c @@ -0,0 +1,29 @@ +/* ***************************************************************************** + * polygon.c -- Draw a polygon. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_polygon(const int *x, const int *y, int nb_vertices, ML_Color color) +{ + int i; + if(nb_vertices < 1) return; + for(i=0 ; i<nb_vertices-1 ; i++) + ML_line(x[i], y[i], x[i+1], y[i+1], color); + ML_line(x[i], y[i], x[0], y[0], color); +} diff --git a/arch/casiowin/monochromelib/src/rectangle.c b/arch/casiowin/monochromelib/src/rectangle.c new file mode 100644 index 0000000..8f28ed5 --- /dev/null +++ b/arch/casiowin/monochromelib/src/rectangle.c @@ -0,0 +1,57 @@ +/* ***************************************************************************** + * rectangle.c -- Draw a rectangle. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_rectangle(int x1, int y1, int x2, int y2, int border_width, ML_Color border_color, ML_Color fill_color) +{ + int i; + if(x1 > x2) + { + i = x1; + x1 = x2; + x2 = i; + } + if(y1 > y2) + { + i = y1; + y1 = y2; + y2 = i; + } + if(border_width > (x2-x1)/2+1) border_width = (x2-x1)/2+1; + if(border_width > (y2-y1)/2+1) border_width = (y2-y1)/2+1; + if(border_color != ML_TRANSPARENT && border_width > 0) + { + for(i=0 ; i<border_width ; i++) + { + ML_horizontal_line(y1+i, x1, x2, border_color); + ML_horizontal_line(y2-i, x1, x2, border_color); + } + for(i=y1+border_width ; i<=y2-border_width ; i++) + { + ML_horizontal_line(i, x1, x1+border_width-1, border_color); + ML_horizontal_line(i, x2-border_width+1, x2, border_color); + } + } + if(fill_color != ML_TRANSPARENT) + { + for(i=y1+border_width ; i<=y2-border_width ; i++) + ML_horizontal_line(i, x1+border_width, x2-border_width, fill_color); + } +} diff --git a/arch/casiowin/monochromelib/src/set_contrast.c b/arch/casiowin/monochromelib/src/set_contrast.c new file mode 100644 index 0000000..b0c365e --- /dev/null +++ b/arch/casiowin/monochromelib/src/set_contrast.c @@ -0,0 +1,29 @@ +/* ***************************************************************************** + * set_contrast.c -- Set the screen contrast. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_set_contrast(unsigned char contrast) +{ + volatile char *LCD_register_selector = (char*)0xB4000000; + volatile char *LCD_data_register = (char*)0xB4010000; + + *LCD_register_selector = 6; + *LCD_data_register = min(contrast, 255); +} diff --git a/arch/casiowin/monochromelib/src/vertical_line.c b/arch/casiowin/monochromelib/src/vertical_line.c new file mode 100644 index 0000000..75bda41 --- /dev/null +++ b/arch/casiowin/monochromelib/src/vertical_line.c @@ -0,0 +1,66 @@ +/* ***************************************************************************** + * vertical_line.c -- Draw a vertical line. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_vertical_line(int x, int y1, int y2, ML_Color color) +{ + int i, j; + char checker, byte, *vram = ML_vram_adress(); + if(x&~127 || (y1<0 && y2<0) || (y1>63 && y2>63)) return; + if(y1 > y2) + { + int tmp = y1; + y1 = y2; + y2 = tmp; + } + if(y1 < 0) y1 = 0; + if(y2 > 63) y2 = 63; + + i = (y1<<4)+(x>>3); + j = (y2<<4)+(x>>3); + switch(color) + { + case ML_BLACK: + byte = 128>>(x&7); + for( ; i<=j ; i+=16) + vram[i] |= byte; + break; + case ML_WHITE: + byte = ~(128>>(x&7)); + for( ; i<=j ; i+=16) + vram[i] &= byte; + break; + case ML_XOR: + byte = 128>>(x&7); + for( ; i<=j ; i+=16) + vram[i] ^= byte; + break; + case ML_CHECKER: + byte = 128>>(x&7); + checker = y1&1^x&1; + for( ; i<=j ; i+=16) + { + if(checker) vram[i] &= ~byte; + else vram[i] |= byte; + checker = !checker; + } + break; + } +} diff --git a/arch/casiowin/monochromelib/src/vertical_scroll.c b/arch/casiowin/monochromelib/src/vertical_scroll.c new file mode 100644 index 0000000..8e5892e --- /dev/null +++ b/arch/casiowin/monochromelib/src/vertical_scroll.c @@ -0,0 +1,32 @@ +/* ***************************************************************************** + * vertical_scroll.c -- Scroll the screen vertically. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +void ML_vertical_scroll(int scroll) +{ + int i, j; + char column[64], *vram = ML_vram_adress(); + scroll %= 64; + for(i=0 ; i<16 ; i++) + { + for(j=0 ; j<64 ; j++) column[j] = vram[(j<<4)+i]; + for(j=0 ; j<64 ; j++) vram[(j<<4)+i] = column[(j-scroll+64)&63]; + } +} diff --git a/arch/casiowin/monochromelib/src/vram_adress.c b/arch/casiowin/monochromelib/src/vram_adress.c new file mode 100644 index 0000000..5c17c78 --- /dev/null +++ b/arch/casiowin/monochromelib/src/vram_adress.c @@ -0,0 +1,25 @@ +/* ***************************************************************************** + * vram_address.c -- Get the VRAM address. + * Copyright (C) 2011 Pierre "PierrotLL" Le Gall <legallpierre89@gmail.com> + * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcarrot. + * libcarrot is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcarrot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************** */ +#include <monochrome.h> + +char* ML_vram_adress() +{ + return (GetVRAMAddress()); +} @@ -5,5 +5,5 @@ modules: './arch' arch: ['sh1', 'sh2', 'sh2e', 'sh2a', 'sh2afpu', 'sh2dsp', 'sh3', 'sh3dsp', 'sh4', 'sh4a', 'sh4aldsp'] default: - c: ['all/core', 'all/core-sh', 'all/sh-intrinsic', 'all/math'] - c++: ['all/core', 'all/core-sh', 'all/sh-intrinsic', 'all/math', 'all/cpp'] + c: ['all/core', 'all/core-sh', 'all/sh-intrinsic'] + c++: ['all/core', 'all/core-sh', 'all/sh-intrinsic', 'all/cpp'] diff --git a/tool/Toolchain/Hitachi.py b/tool/Toolchain/Hitachi.py index a3c738b..02df6b9 100755 --- a/tool/Toolchain/Hitachi.py +++ b/tool/Toolchain/Hitachi.py @@ -135,7 +135,6 @@ class HitachiToolchain(Toolchain): print('exit', file=tmp) tmp.close() - print(open(tmpinfo[1]).read()) # Make the command line. commandline = [self.util['lnk']] commandline += ['-subcommand=' + tmpinfo[1]] diff --git a/tool/Toolchain/__init__.py b/tool/Toolchain/__init__.py index e5ef515..0ceadc7 100755 --- a/tool/Toolchain/__init__.py +++ b/tool/Toolchain/__init__.py @@ -11,3 +11,4 @@ def get_toolchain(name, arch, tooldir): if name.lower() in ["gnu", "gcc"]: return GNUToolchain(*args) print("Toolchain '%s' did not exist."%name) + exit(1) diff --git a/tool/Toolchain/base.py b/tool/Toolchain/base.py index f8c1a0e..6c772ac 100755 --- a/tool/Toolchain/base.py +++ b/tool/Toolchain/base.py @@ -75,7 +75,7 @@ class Toolchain(): def asm(self, obj, src, incdirs=[]): ''' Make an object out of an assembly source file. ''' try: - return self.direct__asm(obj = obj, src = src, incdirs = incdirs) + return self.direct__asm(obj = obj, src = src) except Exception: traceback.print_exc() return 1 |