---
# System prepended metadata

title: New copy-paste mecanism.

---

# New copy-paste mecanism.

# Routines

## Module clip

On introduit un nouveau module `clip.o`. Motivation:

- Le module `org.o` gère déjà org_copy et d'autres aspect "block". Mais son role principal reste le codage/decodage de sources z80 orgams.
- L'editeur permettra bientot de travailler avec d'autres types de fichiers (pur texte, autres languages de programmation, ...). On voit bien que la gestion du clipboard doit etre isolee.
- Cela permet d'avoir des modules simples, petits et a responsabilite limitee.

### (gurneyh?) free_clipboard
```
free_clipboard
; Empty clipboard (release associated memory)
; In: A: Clip # (0 from now) 
; Out: Nothing (should BRK if assumptions violated)
```

#### Variables

Global:
`clipboard`: Pointeur vers clipboard. Initialisé a l'invocation d'Orgams.
Local:
As you wish!

See [How to introduce a new variable](https://hackmd.io/m2EuaMKVRyysyjfMaIr38w).


#### Dependencies

Routines that needs to be called. See if you see why!
See [How to call orgams routine](https://hackmd.io/GHAIutTCT52iDAPM8mz7RA)

##### chunk:free_list



### (gurneyh?) copy_to_clipboard

```
copy_to_clipboard
; Copy section of source to clipboard.
; In: A: Clip # (0 from now) 
     ;  HL: Address line start
     ;  C: Bank line end
     ;  DE: Address post line end (that is, everything must be copied up to DE-1 included)
```

#### Implementation.

La structure du clipboard n'a pas besoin d'etre connuee. Les routines fournies permettent de l'initialiser et de le remplir.

Similairement, les details de la structure du source pre-encodes sont hors-sujet. Cela dit, voila ce qu'il faut savoir :
- Le source est decoupé en une liste chainee de chunks de &100 octets alignés.
- Chaque chunk consiste en un header et les donnees proprement dites.
- Un chunk n'est pas forcement rempli, la position du dernier octet est en +2. Le chunk est rempli ssi cette position est &ff.

#### Variables

Global:
`clipboard`: Pointeur vers clipboard. Initialisé a l'invocation d'Orgams.
Local:
As you wish!

See [How to introduce a new variable](https://hackmd.io/m2EuaMKVRyysyjfMaIr38w).


#### Dependencies

Routines that needs to be called. See if you see why!
See [How to call orgams routine](https://hackmd.io/GHAIutTCT52iDAPM8mz7RA)


##### free_clipboard
##### org:connect_line_start_end
##### chunk:newlist
##### chunk:appendraw


### (gurneyh?) copy_from_clipboard
```
; Copy clipboard to current source.
; In: A: Clip # (0 from now) 
     ; B: Bank line start
     ;  DE: Line destination #
     ;  C: Bank line end
     ;  DE: Address post line end (that is, everything must be copied up to DE-1 included)
```

This routines needs to call:
* reset_clipboard  (in: A= clipboard #. 0 For now. Out: HL = chunk ID for start of clipboard)
* insert_new_chunk

#### Variables

Global:
`clipboard`: Same as above.



#### Prerequisite:

(madram) `connect_line_start_end` must return current bank. 
(madram) Find room for variable clipboard.
(madram) Initialize clipboard at 0 at orgams init time.


# Tests

Not needed right now, since there are a **lot** of tests already against `org_copy`. 

### Detach

Not needed right now:
will be used by COPY-X, COPY-DEL and COPY-M.


## Modifications

### org:org_copy

NB: This routine won't be called anymore from the editor.
Yet we want to keep it since a lot of unit-tests rely on it.
That's a way to indirectly validate the new routines.

After `call set_modified`, must replaced all code by a use of `copy_to_clipboard` + `copy_from_clipboard` + `free_clipboard` (that's not striclty necessary, but it's would be closer from the current behavior). 

Note: `call set_modified` must actually moved into copy_from_clipboard.

#### Move org:org_copy

Move the routine with the tests that use it. We don't need it anymore in rom.

