Skip to content

Commit

Permalink
Adds MSET statement to clear/set memory areas.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmsc committed Oct 27, 2018
1 parent 4202fab commit 300c3b5
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 3 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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\
Expand Down
17 changes: 17 additions & 0 deletions manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.**

Expand Down
3 changes: 2 additions & 1 deletion src/basic.syn
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/clearmem.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
61 changes: 61 additions & 0 deletions src/interp/mset.asm
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>
;
; 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

0 comments on commit 300c3b5

Please sign in to comment.