-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
273 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
.default .public NEX_BORDER_COLOR = 7 | ||
.default .public NEX_LOAD_BANK_DELAY = 0 | ||
.default .public NEX_LOAD_START_DELAY = 0 | ||
|
||
bank_start(bank) = bank * $4000 | ||
bank_end(bank) = bank * $4000 + $3fff | ||
bank(address) = (address) >> 14 | ||
|
||
.macro bank bank, data_start, data_end { | ||
.if bank(data_start) <= bank && bank(data_end) >= bank { | ||
.memory bank_start(bank), bank_end(bank) | ||
} | ||
} | ||
|
||
.output { | ||
; Header | ||
.data "NextV1.2" ; signature and version | ||
.data 0 ; 768k RAM is enough | ||
.data bank(.data_end) - bank(.data_start) + 1 ; number of 16k banks | ||
.data 0 ; TODO: loading screens | ||
.data NEX_BORDER_COLOR | ||
.data $ff58 ; stack pointer | ||
.data start:2 ; entry point | ||
.data 0:2 ; number of extra files | ||
.repeat j, 112 { ; included 16k banks | ||
.if bank(.data_start) <= j && bank(.data_end) >= j { | ||
.data 1 | ||
} | ||
.else { | ||
.data 0 | ||
} | ||
} | ||
.data 0, 0 ; loading bar enable and color | ||
.data NEX_LOAD_BANK_DELAY, NEX_LOAD_START_DELAY ; loading delays in frames | ||
.data 0 ; reset machine state | ||
.data 0, 0, 0 ; TODO: required core version | ||
.data 0 ; Timex Hires mode color | ||
.data 0 ; entry bank | ||
.data 0:2 ; close file | ||
.data .fill(370, 0) ; reserved | ||
; TODO: loading screen | ||
bank 5, .data_start, .data_end | ||
bank 2, .data_start, .data_end | ||
bank 0, .data_start, .data_end | ||
bank 1, .data_start, .data_end | ||
bank 3, .data_start, .data_end | ||
bank 4, .data_start, .data_end | ||
; TODO: banks 6 - 111 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
.define ZX_SPECTRUM_NEXT | ||
.cpu "z80" | ||
|
||
.include "zx-spectrum-encoding.inc" | ||
.include "zx-spectrum-nex.inc" | ||
|
||
.default .public program_start = $8000 | ||
.default .public program_end = $ffff | ||
|
||
.segment program { | ||
address: program_start - program_end | ||
} | ||
|
||
.section code { | ||
segment: program | ||
} | ||
|
||
.section data { | ||
segment: program | ||
} | ||
|
||
.section reserved { | ||
type: reserve_only | ||
segment: program | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,4 @@ class FillExpression: public BaseExpression { | |
Expression value; | ||
}; | ||
|
||
|
||
|
||
#endif //FILLEXPRESSION_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
MinMaxExpression.cc -- | ||
Copyright (C) Dieter Baron | ||
The authors can be contacted at <accelerate@tpau.group> | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions | ||
are met: | ||
1. Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
2. The names of the authors may not be used to endorse or promote | ||
products derived from this software without specific prior | ||
written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS | ||
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY | ||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE | ||
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | ||
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN | ||
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include "MinMaxExpression.h" | ||
|
||
#include "ParseException.h" | ||
|
||
Expression MinMaxExpression::create(bool minimum, const std::vector<Expression>& arguments) { | ||
if (arguments.size() != 2) { | ||
throw ParseException(Location(), "invalid number of arguments"); | ||
} | ||
return create(arguments[0], arguments[1], minimum); | ||
} | ||
|
||
Expression MinMaxExpression::create(const Expression& a, const Expression& b, bool minimum) { | ||
// TODO: validate and propagate types. | ||
if (a.has_value() && b.has_value()) { | ||
return Expression(min_max(minimum, *a.value(), *b.value())); | ||
} | ||
else { | ||
return Expression(std::make_shared<MinMaxExpression>(a, b, minimum)); | ||
} | ||
} | ||
|
||
std::optional<Expression> MinMaxExpression::evaluated(const EvaluationContext& context) const { | ||
auto new_a = a.evaluated(context); | ||
auto new_b = b.evaluated(context); | ||
if (new_a || new_b) { | ||
return create(new_a.value_or(a), new_b.value_or(b), minimum); | ||
} | ||
else { | ||
return {}; | ||
} | ||
} | ||
|
||
void MinMaxExpression::serialize_sub(std::ostream& stream) const { | ||
stream << (minimum ? ".min" : ".max") << "(" << a << ", " << b << ")"; | ||
} | ||
|
||
std::optional<Value> MinMaxExpression::minimum_value() const { | ||
const auto a_min = a.minimum_value(); | ||
const auto b_min = b.minimum_value(); | ||
|
||
if (a_min && b_min) { | ||
return min_max(minimum, *a_min, *b_min); | ||
} | ||
else { | ||
return {}; | ||
} | ||
} | ||
|
||
std::optional<Value> MinMaxExpression::maximum_value() const { | ||
const auto a_max = a.maximum_value(); | ||
const auto b_max = b.maximum_value(); | ||
|
||
if (a_max && b_max) { | ||
return min_max(minimum, *a_max, *b_max); | ||
} | ||
else { | ||
return {}; | ||
} | ||
} | ||
|
||
Value MinMaxExpression::min_max(bool minimum, const Value& a, const Value& b) { | ||
auto a_smaller = a < b; | ||
|
||
return (minimum && a_smaller) || (!minimum && !a_smaller) ? a : b; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#ifndef MIN_MAX_EXPRESSION_H | ||
#define MIN_MAX_EXPRESSION_H | ||
|
||
/* | ||
MinMaxExpression.h -- | ||
Copyright (C) Dieter Baron | ||
The authors can be contacted at <accelerate@tpau.group> | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions | ||
are met: | ||
1. Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
2. The names of the authors may not be used to endorse or promote | ||
products derived from this software without specific prior | ||
written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS | ||
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY | ||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE | ||
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | ||
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN | ||
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include "BaseExpression.h" | ||
#include "Expression.h" | ||
|
||
class MinMaxExpression: public BaseExpression { | ||
public: | ||
explicit MinMaxExpression(Expression a, Expression b, bool minimum): a{std::move(a)}, b{std::move(b)}, minimum{minimum} {} | ||
|
||
static Expression create_min(const std::vector<Expression>& arguments) {return create(true, arguments);} | ||
static Expression create_max(const std::vector<Expression>& arguments) {return create(false, arguments);} | ||
static Expression create(const Expression& a, const Expression& b, bool minimum); | ||
|
||
[[nodiscard]] std::optional<Expression> evaluated(const EvaluationContext& context) const override; | ||
|
||
[[nodiscard]] std::optional<Value> minimum_value() const override; | ||
[[nodiscard]] std::optional<Value> maximum_value() const override; | ||
|
||
protected: | ||
void serialize_sub(std::ostream& stream) const override; | ||
|
||
private: | ||
static Expression create(bool minimum, const std::vector<Expression>& arguments); | ||
static Value min_max(bool minimum, const Value& a, const Value& b); | ||
|
||
Expression a; | ||
Expression b; | ||
bool minimum; | ||
}; | ||
|
||
|
||
#endif // MIN_MAX_EXPRESSION_H |
Oops, something went wrong.