From 300c3b5144c388e1167aebf3103dee4f734dada1 Mon Sep 17 00:00:00 2001 From: Daniel Serpell Date: Sat, 27 Oct 2018 12:07:44 -0300 Subject: [PATCH] Adds MSET statement to clear/set memory areas. --- Makefile | 1 + manual.md | 17 +++++++++++++ src/basic.syn | 3 ++- src/clearmem.asm | 7 ++++-- src/interp/mset.asm | 61 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 src/interp/mset.asm diff --git a/Makefile b/Makefile index 34a0df9..e285179 100644 --- a/Makefile +++ b/Makefile @@ -140,6 +140,7 @@ COMMON_AS_SRC=\ src/interp/lnot.asm\ src/interp/lor.asm\ src/interp/move.asm\ + src/interp/mset.asm\ src/interp/mul.asm\ src/interp/negax.asm\ src/interp/nmove.asm\ diff --git a/manual.md b/manual.md index 6875c4e..d21d895 100644 --- a/manual.md +++ b/manual.md @@ -1381,6 +1381,23 @@ modify memory. Use with care. NEXT I +**Sets memory to a value** +**MSET _address_, _length_, _value_ / MS.** + + Writes _length_ bytes in memory at + given _address_ with _value_. + + This is useful to clear graphics + or P/M data, or simply to set an + string to a repeated value. + + `MSET a, b, c` is equivalent to: + + FOR I=0 to b-1 + POKE a+I, c + NEXT I + + **Writes a byte to memory** **POKE _address_, _value_ / P.** diff --git a/src/basic.syn b/src/basic.syn index a6d785d..e56a41e 100644 --- a/src/basic.syn +++ b/src/basic.syn @@ -39,7 +39,7 @@ TOKENS { # Convert from int to bool TOK_COMP_0 # Low level statements - TOK_POKE, TOK_DPOKE, TOK_MOVE, TOK_NMOVE, TOK_INC, TOK_DEC + TOK_POKE, TOK_DPOKE, TOK_MOVE, TOK_NMOVE, TOK_MSET, TOK_INC, TOK_DEC # Graphic support statements TOK_GRAPHICS, TOK_PLOT, TOK_DRAWTO # Print statements @@ -553,6 +553,7 @@ PARSE_LINE_COMMAND: "CLS" IO_CHAN_OPT_NOCOMMA emit TOK_BYTE emit CLS emit TOK_PUT "Poke" EXPR_2 emit TOK_POKE "Dpoke" EXPR_2 emit TOK_DPOKE + "MSet" EXPR_2 "," EXPR emit TOK_MSET "Move" EXPR_2 "," EXPR emit TOK_MOVE "-move" EXPR_2 "," EXPR emit TOK_NMOVE "DO" emit LT_DO_LOOP E_PUSH_LT diff --git a/src/clearmem.asm b/src/clearmem.asm index 440f2b6..9174ff1 100644 --- a/src/clearmem.asm +++ b/src/clearmem.asm @@ -27,7 +27,7 @@ ; Clear Memory ; ------------ - .export clear_data, alloc_array + .export clear_data, alloc_array, mem_set .import move_dwn_src, move_dwn_dst, move_dwn, putc, EXE_END .importzp mem_end, var_buf, tmp1, tmp2, array_ptr, var_count @@ -83,11 +83,14 @@ alloc_size= tmp1 bcs err_nomem ; Clears memory from (tmp2) of (alloc_size) size + ldy #0 ; Value to set + +::mem_set: txa ; X = (alloc_size+1) clc adc tmp2+1 sta tmp2+1 - lda #0 + tya inx ldy alloc_size beq nxt diff --git a/src/interp/mset.asm b/src/interp/mset.asm new file mode 100644 index 0000000..9c8f408 --- /dev/null +++ b/src/interp/mset.asm @@ -0,0 +1,61 @@ +; +; FastBasic - Fast basic interpreter for the Atari 8-bit computers +; Copyright (C) 2017,2018 Daniel Serpell +; +; This program is free software; you can redistribute it and/or modify +; it under the terms of the GNU General Public License as published by +; the Free Software Foundation, either version 2 of the License, or +; (at your option) any later version. +; +; This program 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 General Public License for more details. +; +; You should have received a copy of the GNU General Public License along +; with this program. If not, see +; +; In addition to the permissions in the GNU General Public License, the +; authors give you unlimited permission to link the compiled version of +; this file into combinations with other programs, and to distribute those +; combinations without any restriction coming from the use of this file. +; (The General Public License restrictions do apply in other respects; for +; example, they cover modification of the file, and distribution when not +; linked into a combine executable.) + + +; MSET: sets a range of memory to a value +; --------------------------------------- + + ; From interpreter.asm + .import stack_l, stack_h, pop_stack_3 + .import mem_set + .importzp tmp1, tmp2 + + .include "atari.inc" + + .segment "RUNTIME" + +.proc EXE_MSET + pha ; Store value to set into stack + + lda stack_l, y + sta tmp1 + ldx stack_h, y + + lda stack_l+1, y + sta tmp2 + lda stack_h+1, y + sta tmp2+1 + + pla ; Recover value to set into Y + tay + jsr mem_set + + jmp pop_stack_3 +.endproc + + .include "../deftok.inc" + deftoken "MSET" + +; vi:syntax=asm_ca65