mirror of
https://github.com/irmen/prog8.git
synced 2024-10-19 22:24:17 +00:00
move target() builtin to sys.target constant
This commit is contained in:
parent
87cee7a0fd
commit
025dde264a
@ -474,6 +474,9 @@ _raster_irq_handler
|
|||||||
sys {
|
sys {
|
||||||
; ------- lowlevel system routines --------
|
; ------- lowlevel system routines --------
|
||||||
|
|
||||||
|
const ubyte target = 64 ; compilation target specifier. 64 = C64, 16 = CommanderX16.
|
||||||
|
|
||||||
|
|
||||||
asmsub reset_system() {
|
asmsub reset_system() {
|
||||||
; Soft-reset the system back to Basic prompt.
|
; Soft-reset the system back to Basic prompt.
|
||||||
%asm {{
|
%asm {{
|
||||||
|
@ -473,6 +473,9 @@ asmsub init_system() {
|
|||||||
sys {
|
sys {
|
||||||
; ------- lowlevel system routines --------
|
; ------- lowlevel system routines --------
|
||||||
|
|
||||||
|
const ubyte target = 16 ; compilation target specifier. 64 = C64, 16 = CommanderX16.
|
||||||
|
|
||||||
|
|
||||||
asmsub reset_system() {
|
asmsub reset_system() {
|
||||||
; Soft-reset the system back to Basic prompt.
|
; Soft-reset the system back to Basic prompt.
|
||||||
%asm {{
|
%asm {{
|
||||||
|
@ -6,9 +6,6 @@ import prog8.ast.expressions.*
|
|||||||
import prog8.ast.statements.StructDecl
|
import prog8.ast.statements.StructDecl
|
||||||
import prog8.ast.statements.VarDecl
|
import prog8.ast.statements.VarDecl
|
||||||
import prog8.compiler.CompilerException
|
import prog8.compiler.CompilerException
|
||||||
import prog8.compiler.target.C64Target
|
|
||||||
import prog8.compiler.target.CompilationTarget
|
|
||||||
import prog8.compiler.target.Cx16Target
|
|
||||||
import kotlin.math.*
|
import kotlin.math.*
|
||||||
|
|
||||||
|
|
||||||
@ -146,7 +143,6 @@ private val functionSignatures: List<FSignature> = listOf(
|
|||||||
FSignature("read_flags" , true, emptyList(), DataType.UBYTE),
|
FSignature("read_flags" , true, emptyList(), DataType.UBYTE),
|
||||||
FSignature("progend" , true, emptyList(), DataType.UWORD),
|
FSignature("progend" , true, emptyList(), DataType.UWORD),
|
||||||
FSignature("memory" , true, listOf(FParam("name", setOf(DataType.STR)), FParam("size", setOf(DataType.UWORD))), DataType.UWORD),
|
FSignature("memory" , true, listOf(FParam("name", setOf(DataType.STR)), FParam("size", setOf(DataType.UWORD))), DataType.UWORD),
|
||||||
FSignature("target" , true, emptyList(), DataType.UBYTE, ::builtinTarget),
|
|
||||||
FSignature("swap" , false, listOf(FParam("first", NumericDatatypes), FParam("second", NumericDatatypes)), null),
|
FSignature("swap" , false, listOf(FParam("first", NumericDatatypes), FParam("second", NumericDatatypes)), null),
|
||||||
FSignature("memcopy" , false, listOf(
|
FSignature("memcopy" , false, listOf(
|
||||||
FParam("from", IterableDatatypes + DataType.UWORD),
|
FParam("from", IterableDatatypes + DataType.UWORD),
|
||||||
@ -452,17 +448,6 @@ private fun builtinSgn(args: List<Expression>, position: Position, program: Prog
|
|||||||
return NumericLiteralValue(DataType.BYTE, constval.number.toDouble().sign.toInt().toShort(), position)
|
return NumericLiteralValue(DataType.BYTE, constval.number.toDouble().sign.toInt().toShort(), position)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun builtinTarget(args: List<Expression>, position: Position, program: Program): NumericLiteralValue {
|
|
||||||
if (args.isNotEmpty())
|
|
||||||
throw SyntaxError("target requires no arguments", position)
|
|
||||||
val target = when(CompilationTarget.instance) {
|
|
||||||
is C64Target -> 64
|
|
||||||
is Cx16Target -> 16
|
|
||||||
else -> throw CompilerException("unrecognised compilation target")
|
|
||||||
}
|
|
||||||
return NumericLiteralValue(DataType.UBYTE, target, position)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun numericLiteral(value: Number, position: Position): NumericLiteralValue {
|
private fun numericLiteral(value: Number, position: Position): NumericLiteralValue {
|
||||||
val floatNum=value.toDouble()
|
val floatNum=value.toDouble()
|
||||||
val tweakedValue: Number =
|
val tweakedValue: Number =
|
||||||
|
@ -34,6 +34,17 @@ as ROM/kernal subroutine definitions, memory location constants, and utility sub
|
|||||||
Many of these definitions overlap for the C64 and Commander X16 targets so it is still possible
|
Many of these definitions overlap for the C64 and Commander X16 targets so it is still possible
|
||||||
to write programs that work on both targets without modifications.
|
to write programs that work on both targets without modifications.
|
||||||
|
|
||||||
|
``sys.target``
|
||||||
|
A constant ubyte value designating the target machine that the program is compiled for.
|
||||||
|
Notice that this is a compile-time constant value and is not determined on the
|
||||||
|
system when the program is running.
|
||||||
|
The following return values are currently defined:
|
||||||
|
|
||||||
|
- 16 = compiled for CommanderX16 with 65C02 CPU
|
||||||
|
- 64 = compiled for Commodore-64 with 6502/6510 CPU
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
conv
|
conv
|
||||||
----
|
----
|
||||||
Routines to convert strings to numbers or vice versa.
|
Routines to convert strings to numbers or vice versa.
|
||||||
@ -69,40 +80,40 @@ string
|
|||||||
------
|
------
|
||||||
Provides string manipulation routines.
|
Provides string manipulation routines.
|
||||||
|
|
||||||
length(str) -> ubyte length
|
``length(str) -> ubyte length``
|
||||||
Number of bytes in the string. This value is determined during runtime and counts upto
|
Number of bytes in the string. This value is determined during runtime and counts upto
|
||||||
the first terminating 0 byte in the string, regardless of the size of the string during compilation time.
|
the first terminating 0 byte in the string, regardless of the size of the string during compilation time.
|
||||||
Don't confuse this with ``len`` and ``sizeof``
|
Don't confuse this with ``len`` and ``sizeof``
|
||||||
|
|
||||||
left(source, length, target)
|
``left(source, length, target)``
|
||||||
Copies the left side of the source string of the given length to target string.
|
Copies the left side of the source string of the given length to target string.
|
||||||
It is assumed the target string buffer is large enough to contain the result.
|
It is assumed the target string buffer is large enough to contain the result.
|
||||||
Also, you have to make sure yourself that length is smaller or equal to the length of the source string.
|
Also, you have to make sure yourself that length is smaller or equal to the length of the source string.
|
||||||
Modifies in-place, doesn't return a value (so can't be used in an expression).
|
Modifies in-place, doesn't return a value (so can't be used in an expression).
|
||||||
|
|
||||||
right(source, length, target)
|
``right(source, length, target)``
|
||||||
Copies the right side of the source string of the given length to target string.
|
Copies the right side of the source string of the given length to target string.
|
||||||
It is assumed the target string buffer is large enough to contain the result.
|
It is assumed the target string buffer is large enough to contain the result.
|
||||||
Also, you have to make sure yourself that length is smaller or equal to the length of the source string.
|
Also, you have to make sure yourself that length is smaller or equal to the length of the source string.
|
||||||
Modifies in-place, doesn't return a value (so can't be used in an expression).
|
Modifies in-place, doesn't return a value (so can't be used in an expression).
|
||||||
|
|
||||||
slice(source, start, length, target)
|
``slice(source, start, length, target)``
|
||||||
Copies a segment from the source string, starting at the given index,
|
Copies a segment from the source string, starting at the given index,
|
||||||
and of the given length to target string.
|
and of the given length to target string.
|
||||||
It is assumed the target string buffer is large enough to contain the result.
|
It is assumed the target string buffer is large enough to contain the result.
|
||||||
Also, you have to make sure yourself that start and length are within bounds of the strings.
|
Also, you have to make sure yourself that start and length are within bounds of the strings.
|
||||||
Modifies in-place, doesn't return a value (so can't be used in an expression).
|
Modifies in-place, doesn't return a value (so can't be used in an expression).
|
||||||
|
|
||||||
find(string, char) -> uword address
|
``find(string, char) -> uword address``
|
||||||
Locates the first position of the given character in the string, returns the string starting
|
Locates the first position of the given character in the string, returns the string starting
|
||||||
with this character or $0000 if the character is not found.
|
with this character or $0000 if the character is not found.
|
||||||
|
|
||||||
compare(string1, string2) -> ubyte result
|
``compare(string1, string2) -> ubyte result``
|
||||||
Returns -1, 0 or 1 depeding on wether string1 sorts before, equal or after string2.
|
Returns -1, 0 or 1 depeding on wether string1 sorts before, equal or after string2.
|
||||||
Note that you can also directly compare strings and string values with eachother
|
Note that you can also directly compare strings and string values with eachother
|
||||||
using ``==``, ``<`` etcetera (it will use string.compare for you under water automatically).
|
using ``==``, ``<`` etcetera (it will use string.compare for you under water automatically).
|
||||||
|
|
||||||
copy(from, to) -> ubyte length
|
``copy(from, to) -> ubyte length``
|
||||||
Copy a string to another, overwriting that one. Returns the length of the string that was copied.
|
Copy a string to another, overwriting that one. Returns the length of the string that was copied.
|
||||||
Often you don't have to call this explicitly and can just write ``string1 = string2``
|
Often you don't have to call this explicitly and can just write ``string1 = string2``
|
||||||
but this function is useful if you're dealing with addresses for instance.
|
but this function is useful if you're dealing with addresses for instance.
|
||||||
|
@ -888,15 +888,6 @@ set_irqd() / clear_irqd()
|
|||||||
swap(x, y)
|
swap(x, y)
|
||||||
Swap the values of numerical variables (or memory locations) x and y in a fast way.
|
Swap the values of numerical variables (or memory locations) x and y in a fast way.
|
||||||
|
|
||||||
target()
|
|
||||||
Returns byte value designating the target machine that the program was compiled for.
|
|
||||||
Notice that this is a compile-time constant value and is not determined on the
|
|
||||||
system when the program is running.
|
|
||||||
The following return values are currently defined:
|
|
||||||
|
|
||||||
- 16 = compiled for CommanderX16 with 65C02 CPU
|
|
||||||
- 64 = compiled for Commodore-64 with 6502/6510 CPU
|
|
||||||
|
|
||||||
memory(name, size)
|
memory(name, size)
|
||||||
Statically allocates a fixed portion of memory of the given size in bytes, and returns its address.
|
Statically allocates a fixed portion of memory of the given size in bytes, and returns its address.
|
||||||
Slabs are considered identical if their name and size are the same.
|
Slabs are considered identical if their name and size are the same.
|
||||||
|
@ -2,8 +2,7 @@
|
|||||||
TODO
|
TODO
|
||||||
====
|
====
|
||||||
|
|
||||||
- move all str* builtin functions to a strings library module, mem* to the sys module. update docs.
|
- move all mem* builtins to the sys module. update docs.
|
||||||
- move target() builtin to sys.target constant
|
|
||||||
- use (zp) addressing mode on 65c02 specific code rather than ldy#0 / lda (zp),y
|
- use (zp) addressing mode on 65c02 specific code rather than ldy#0 / lda (zp),y
|
||||||
- optimize pointer access code @(pointer)? use a subroutine? macro? 65c02 vs 6502?
|
- optimize pointer access code @(pointer)? use a subroutine? macro? 65c02 vs 6502?
|
||||||
- allow byte return type with single register for asmsubs, for instance string.compare
|
- allow byte return type with single register for asmsubs, for instance string.compare
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
main {
|
main {
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
|
txt.print_ub(sys.target)
|
||||||
}
|
}
|
||||||
|
|
||||||
sub start2 () {
|
sub start2 () {
|
||||||
|
Loading…
Reference in New Issue
Block a user