diff src/memory.s @ 136:e49bd0493baf

Checkpoint updates to immediate mode program editing and some memory handling
author William Astle <lost@l-w.ca>
date Fri, 12 Jul 2024 23:29:45 -0600
parents 3a4cb89a419c
children
line wrap: on
line diff
--- a/src/memory.s	Tue Jul 09 22:18:30 2024 -0600
+++ b/src/memory.s	Fri Jul 12 23:29:45 2024 -0600
@@ -52,4 +52,49 @@
                 leay -1,y                       ; done all source bytes?
                 bne mem_insert3                 ; brif not
                 puls d,x,pc                     ; clean up stack and return
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+; Block copy routines. There are two routines here. One for moving a block upward in memory and one for moving the block
+; downward in memory. Which one is used doesn't matter if the source and destination do not overlap. However, if the
+; source and destination do overlap, the direction that needs to be used depends on whether the source is after or
+; before the destination. There are three entry points below. One is a general block copy, one is for moving upward
+; and one is for moving downward. All entry points have the same input conditions.
+;
+; Entry:
+; X: Destination pointer
+; U: Source pointer
+; Y: Length of the block to copy
+;
+; General copy. This just dispatches either mem_copyup or mem_copydn based on whether the source is before or after
+; the destination.
+mem_copy        pshs u                          ; save source address for compare
+                cmpx ,s++                       ; is the destination below or above?
+                blo mem_copydn                  ; brif destination is below the source - we're copying downward
+                ; fall through                  ; we're copying upward here
+; Copy Y bytes from (U) to (X), working from the top down
+mem_copyup      tfr y,d                         ; need to move pointers to the end of the block
+                leax d,x
+                leau d,u
+mem_copyup0     lda ,-u                         ; copy a byte upward
+                sta ,-x
+                leay -1,y                       ; done yet?
+                bne mem_copyup0
+                rts
+; Copy Y bytes from (U) to (X), working from bottom up
+mem_copydn      lda ,u+                         ; copy a byte downward
+                sta ,x+
+                leay -1,y                       ; done yet?
+                bne mem_copydn                  ; brif not
+mem_checkptr0   rts
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+; Check for D bytes of free memory
+mem_checkd      addd freestart                  ; add to current start of free memory
+                ; fall through to test the resulting pointer
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+; Check if the address in D is within the free memory area allowing for a buffer for the system stack.
+mem_checkptr    addd #stackheadroom             ; add in the stack buffer space to the pointer
+                sts ,--s                        ; get the current stack pointer somewhere
+                cmpd ,s++                       ; did the pointer run into the stack pointer?
+                blo mem_checkptr0               ; brif not - no error
+OMERROR         ldb #err_om                     ; raise an OM error
+                jmp ERROR
                 *pragmapop list