Copy Paste Specifications.

TODO: Discuss the best way, UI-WISE, to handle multiple clipboards.

  • E.g. show the start of the contents of the last 8 copied/moved blocs, and let pick one. Which shortcuts?
  • Make sure the most recent clipboard is easy to access.
  • Just check what is done in other editors / OS?

Goal / Motivation

We want to replace current behaviour:

  • COPY-C: copy selected bloc at cursor position (org_copy_bloc).
  • COPY-DEL: delete permanently bloc (done by editor by looping on org_delete_line! arglll. slow)

By standard copy-paste:

  • COPY-C: copy selected bloc in clipboard.
  • COPY-V: copy clipboard at cursor position.
  • COPY-X: move select bloc in clipboard.
  • COPY-DEL would be conserved to delete permanently a bloc, but reusing the fast mechanism of COPY-X

When several tabs are used, it would allow to copy blocs cross sources.
That's also the opportunity to replace the very slow routines by super fast ones (copying full chunks rather than line per line).
Deluxe version [optional in first approach]: use several clipboards, to allow copy from e.g. one of last 8 copied/deleted stuff.

We introduce a new module (clip.o) (ask mdr for template).

interaction with other modules

clip.o will make the link between org.o (which know how to locate / insert source lines} and {chunk.o}} (which know how to handle generic chunks and linked lists of chunks).

The routines to be will be called by the editor, but one shouldn't be concerned by that.
What's important important are the existing routines and variables to use.

Existing Routines

See their complete description in their respective modules.

  • org_connect_bk_base, to access your variable v_clip
  • org.select_line, to get pointer to given line in source.
  • org.select_line_start_end, idem with end point.
  • org.insert_raw_lines
  • chunk.copy_chunk
  • chunk.copy_sublist (TODO)

How to call them

For now, we connect ORGEXT rom, and use a jump table (like firmware callbloc).
See guidelines and example/template source.

Soon enough, we'll be to import modules definitions.

Existing Variables

v_curbk = &7cfd  ; Needed after org_select_line* to form the complete source 24 bits pointer of a given line.

Routines To Be Coded (your turn)


No hard bank connections

You musn't connect banks by yourself (out &7fxx).
Use org.connect_bk_base to connect main work bank.
For source banks, the available routines would take the chunk id (BK + MSB) as input, and will do connection by themselves.

Use existing macros to call far ROMs.

Similarly, do not connect ROMs by yourself (even via the firmware)
Some routines (chunk*) are not in work ROM (ORGEXT). Use CALL_BRIC(adr) from template source to call them.

Write unit tests rather than testing manually

See also Testing section.

Have fun

Internal variables

There should be at least one variable, if I'm not mistaken:

v_clipboard word   ; id of first chunk of clipboard

That variable should sit in base bank, for persistence across reset (hence the need for org.connect_bk_base to access it).

TODO(madram): give an address.

You can define as many variables as you wish, out of bank (e.g. &9000) for easier handling (since managing source/chunks will swap bank, you don't want to lose track of your variable).


Tl;dr: Nothing to do!

v_clipboard should be set to 0, so that first `free` is a no-op.
That will be actually done by org.o, as part of a more thorough initialisation.
Note: this is done globally rather than module by module, to gain ROM space.


The source is encoded as linked list of specific chunks (i.e chunk knows how to traverse or copy such a list, but doesn't know about the specific "org chunk" header needed for source encoding and housekeeping).

The general idea is that whenever the bloc to copy spans over several chunks, we want to do the following (for speed purpose):

  • Free current clipboard (needed anyway to avoid memory leak)
  • Copy from bloc_start to end of chunk into a generic chunk (that's the new v_clipboard).
  • Copy linked chunks except the last as-is (and attach them to v_clipboard). E.g. using chunk.copy_sublist and chunk.append, or chunk.append_sublist.
  • Copy from start of last chunk to last line and append it.
; In: hl: line_start (included)
     ; de: line_end (included)
  ; Pre-condition: 1 <= hl <= de <= total_lines
; Out: Carry if ok.
        ; NC otherwise, A = error code (e.g. memory full)


; In: de: dest line for insertion. 
  ; Pre-condition: 1 <= de <= total_lines
; Out: Carry if ok.
        ; NC otherwise, A = error code (e.g. memory full)


Note: should use an internal routine move_to_dest.

  • COPY-X is:
      • free v_clipboard
      • move_to_dest with dest = v_clipboard
  • COPY-DEL is:
      • move_to_dest with dest = tmp
      • free tmp
; In: hl: line_start (included)
     ; de: line_end (included)
  ; Pre-condition: 1 <= hl <= de <= total_lines
; Out: Carry if ok.
        ; NC otherwise, A = error code (e.g. memory full)
        ; Other side effect: line hl-de removed from source.


There already are tons of tests around org_copy_bloc.
Replacing the existing code by ++copy_to_clip + copy_from_clip++ would already cover a lot.

Tests should be added for move_to_clip. Ask mdr for precisions how to do that.

Ask mdr for precisions about how to run tests.

Sauf mention contraire, le contenu de cette page est protégé par la licence Creative Commons Attribution-ShareAlike 3.0 License