Post Reply 
41-MCODE: Copying X-Mem Files
03-13-2014, 04:49 PM (This post was last modified: 03-13-2014 04:56 PM by Ángel Martin.)
Post: #1
41-MCODE: Copying X-Mem Files
A few weeks ago Geir started a thread about copying ASCII files, which is not possible using the standard function set in the CX. Some workarounds involved using the Mass storage functions SAVEAS/GETAS, as well as a FOCAL program from Raymond.

I tried that program but failed to make it work as supposed to, probably my bad. That made me start thinking of a MCODE implementation that would copy a source file into a destination one; and not only ASCII but of any type; like-to-like.

The code below shows the initial implementation - feel free to improve on it as you see fit ;-) Both files need to exist in X-Mem, but they don't have to be of the same size - which pretty much rules it out for program files, of course. Just make sure you know what you're doing...

Enjoy it!

PS. here's the original post:


AF4A    08C    "L"    
AF4B    006    "F"    
AF4C    00D    "M"    Copy X-Mem File
AF4D    019    "Y"    " Source,Destination"  in ALPHA
AF4E    010    "P"    Both Files must exist
AF4F    003    "C"    
AF50    03E    B=0 MS    wildcard type!
AF51    0A5    ?NC XQ    Does [GTFLNA] and [RFLSCH]
AF52    0E8    ->3A29    [FLSHAC]
AF53    046    C=0 S&X    
AF54    270    RAMSLCT    select chip0
AF55    0B0    C=N  ALL    Source File Header
AF56    268    WRIT 9(Q)    saved in rg.9(Q)
AF57    3E9    ?NC XQ    Get Text after comma (!)
AF58    0D0    ->34FA    [ALNAM2]
AF59    008    SETF 3    
AF5A    281    ?NC XQ    General File Search
AF5B    0F0    ->3CA0    [EFLSCH]
AF5C    38C    ?FSET 0    not found?
AF5D    0B5    ?NC GO    nope, say so!
AF5E    0F6    ->3D2D    [FLNOFN]
AF5F    046    C=0 S&X    
AF60    270    RAMSLCT    select chip0
AF61    0B0    C=N ALL    Dest File Header
AF62    128    WRIT 4(L)    save it in 4(L)
AF63    0AE    A<>C ALL    
AF64    278    READ 9(Q)    
AF65    37E    ?A#C MS    
AF66    089    ?C XQ    File Type Error
AF67    0F5    ->3D22    [FTPER]
AF68    244    CLRF 9    equal sizes
AF69    366    ?A#C S&X    different?
AF6A    033    JNC +06    no, skip adjustments
AF6B    248    SETF 9    remember this for later
AF6C    306    ?A<C S&X    is C smaller?
AF6D    013    JNC +02    yes, skip
AF6E    0A6    A<>C S&X    no, get the smaller size
AF6F    106    A=C S&X    into both counters
AF70    158    M=C ALL    Source Header
AF71    0AE    A<>C ALL    
AF72    070    N=C ALL    DestInation header
AF73    198    C=M ALL    source file counters
AF74    0FC    RCR 10    rotate file addr to C[S&X]
AF75    10E    A=C ALL    prepare it as input
AF76    00D    ?NC XQ    Get next register adr
AF77    0D0    ->3403    [NXREG]
AF78    0A6    A<>C S&X    reg to C[S&X]
AF79    270    RAMSLCT    select it
AF7A    0A6    A<>C S&X    rebuild A
AF7B    038    READATA    get reg value
AF7C    0EE    B<>C ALL    save in B
AF7D    0AE    A<>C ALL    
AF7E    07C    RCR 4    
AF7F    158    M=C ALL    Update source counter
AF80    0B0    C=N ALL    Dest file register
AF81    0FC    RCR 10    rotate file addr to C[S&X]
AF82    10E    A=C ALL    prepare it as input
AF83    00D    ?NC XQ    Get next register adr
AF84    0D0    ->3403    [NXREG]
AF85    0A6    A<>C S&X    reg to C[S&X]
AF86    270    RAMSLCT    select it
AF87    0A6    A<>C S&X    rebuild A
AF88    0EE    B<>C ALL    reg value!
AF89    2F0    WRITDATA    copy to destination
AF8A    0AE    A<>C ALL    
AF8B    07C    RCR 4    
AF8C    266    C=C-1 S&X    decrease size count
AF8D    070    N=C ALL    update destination counter
AF8E    266    C=C-1 S&X    last one?
AF8F    323    JNC -28d    no, do next
AF90    24C    ?FSET 9    yes, non-equal sized?
AF91    1F9    ?C GO    yes, Show 'END of FILE" 
AF92    0FB    ->3E7E    [SAVRER]
AF93    3E0    RTN

"To live or die by your own sword one must first learn to wield it aptly."
Find all posts by this user
Quote this message in a reply
03-14-2014, 06:37 AM (This post was last modified: 03-14-2014 06:39 AM by Ángel Martin.)
Post: #2
RE: 41-MCODE: Copying X-Mem Files
Because ASCII files are structured in Records, it's possible that the previous code messes up the destination file when both file sizes are not the same: it will copy registers until reaching the minimum of both sizes, which may leave out an EOR character for the last register.

Here's a safer version that requires both files having the same size - you can choose which one suits you better. Use it safely for all file types, like-to-like and same sizes.


08C    "L"    
006    "F"    
00D    "M"    Copy X-Mem File
019    "Y"    " Source,Destination"  in ALPHA
010    "P"    Both Files must exist
003    "C"    Ángel Martin
03E    B=0 MS    wildcard type!
0A5    ?NC XQ    Does [GTFLNA] and [RFLSCH]
0E8    ->3A29    [FLSHAC]
046    C=0 S&X    
270    RAMSLCT    select chip0
0B0    C=N  ALL    Source File Header
268    WRIT 9(Q)    saved in rg.9(Q)
3E9    ?NC XQ    Get Text after comma (!)
0D0    ->34FA    [ALNAM2]
008    SETF 3    tweak the settings
281    ?NC XQ    General File Search
0F0    ->3CA0    [EFLSCH]
38C    ?FSET 0    not found?
0B5    ?NC GO    nope, say so!
0F6    ->3D2D    [FLNOFN]
046    C=0 S&X    
270    RAMSLCT    select chip0
0B0    C=N ALL    Dest File Header
0AE    A<>C ALL    move to A
278    READ 9(Q)    Source File Header
37E    ?A#C MS    different types?
089    ?C XQ    File Type Error
0F5    ->3D22    [FTPER]
244    CLRF 9    equal sizes
366    ?A#C S&X    different?
063    JNC +12d    no, skip error
20D    ?NC XQ    yes, show error
0FC    ->3F83    [APERMSG]
006    "F"    
00C    "L"    
020    " "    MSG: : FL SIZE"
013    "S"    
009    "I"    
01A    "Z"    
205    "E"    
1D9    ?NC GO    
0FE    ->3F76    [DISERR]
158    M=C ALL    Source Header
0AE    A<>C ALL    
070    N=C ALL    DestInation header
198    C=M ALL    source file counters
0FC    RCR 10    rotate file addr to C[S&X]
10E    A=C ALL    prepare it as input
00D    ?NC XQ    Get next register adr
0D0    ->3403    [NXREG]
0A6    A<>C S&X    reg to C[S&X]
270    RAMSLCT    select it
0A6    A<>C S&X    rebuild A
038    READATA    get reg value
0EE    B<>C ALL    save in B
0AE    A<>C ALL    
07C    RCR 4    
158    M=C ALL    Update source counter
0B0    C=N ALL    Dest file register
0FC    RCR 10    rotate file addr to C[S&X]
10E    A=C ALL    prepare it as input
00D    ?NC XQ    Get next register adr
0D0    ->3403    [NXREG]
0A6    A<>C S&X    reg to C[S&X]
270    RAMSLCT    select it
0A6    A<>C S&X    rebuild A
0EE    B<>C ALL    reg value!
2F0    WRITDATA    copy to destination
0AE    A<>C ALL    
07C    RCR 4    
266    C=C-1 S&X    decrease size count
070    N=C ALL    update destination counter
266    C=C-1 S&X    last one?
323    JNC -28d    no, do next
3E0    RTN


PS. I tried to attach the RAMPAGE ROM image but it appears that file type isn't allowed any longer, ditto with MOD files - is that intended?

"To live or die by your own sword one must first learn to wield it aptly."
Find all posts by this user
Quote this message in a reply
03-15-2014, 09:52 AM
Post: #3
RE: 41-MCODE: Copying X-Mem Files
Changing a File type is a relatively trivial affair, as there's only one digit involved in the file header. Function RETPFL in the RamPage Module does exactly that.

Not because you change the type it means the file can be treated as if it was a "proper" one of that type. A useful examples is sorting MATRIX files using SORTFL (which requires DATA files), since in this case both file types have a compatible structure.


"To live or die by your own sword one must first learn to wield it aptly."
Find all posts by this user
Quote this message in a reply
Post Reply 

User(s) browsing this thread: 1 Guest(s)