73 lines
1.8 KiB
ArmAsm
Executable file
73 lines
1.8 KiB
ArmAsm
Executable file
;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
|
|
|
|
;; Sets memory in 'A'-registry to all addresses from 'A_start' until 'A_start' + 'length'
|
|
;; Modifies A, X and A_start
|
|
.proc memset
|
|
.include "mem.inc"
|
|
|
|
;; big_set sets the memory in $ff chunks.
|
|
;; skipp if length >= $ff
|
|
LDX length +1
|
|
BNE big_set
|
|
JMP small_set
|
|
|
|
big_set: ;sets $ff of memory
|
|
;; Y value do not matter, will go through all anyway!
|
|
.repeat $ff
|
|
STA (A_start), Y
|
|
DEY
|
|
.endrepeat
|
|
STA (A_start), Y ; dont forget Y =0
|
|
NOP
|
|
NOP
|
|
big_set_end:
|
|
;;set all hole $ff memory chunks!
|
|
INC A_start + 1
|
|
DEX ;; length +1 --
|
|
BEQ small_set
|
|
JMP big_set
|
|
|
|
|
|
small_set:
|
|
STA data_to_write
|
|
LDA length
|
|
STA length_copy
|
|
|
|
;; calculate rts-position
|
|
LDA #$00
|
|
STA length + 1
|
|
;; 4 bytes = STA DEY NOP = seting 1 byte of memory.
|
|
;; So we need to calculate: length*4
|
|
Mult_16 length, length + 1
|
|
Add_16 length, length + 1, length_copy, #$00
|
|
;; Now RTS_pointer = length*4 + big_set_label
|
|
CLC
|
|
LDA #<big_set
|
|
ADC length
|
|
STA RTS_pointer
|
|
LDA #>big_set
|
|
ADC length + 1
|
|
STA RTS_pointer + 1
|
|
|
|
;; read data we will change to RTS
|
|
LDY #$00
|
|
LDA (RTS_pointer), Y
|
|
STA instruction_backup
|
|
|
|
;; set RTS in big_set
|
|
LDA #$60
|
|
STA (RTS_pointer), Y
|
|
|
|
;; JSR to modified big_set
|
|
LDY length_copy
|
|
DEY ; because we want to count to Y=0 :)
|
|
LDA data_to_write
|
|
JSR big_set
|
|
|
|
;; revert changes
|
|
LDY #$00
|
|
LDA instruction_backup
|
|
STA (RTS_pointer), Y
|
|
|
|
RTS
|
|
.endproc
|