10REM *MOVE command with temporary 20REM filing systems using a free 30REM sideways RAM as a buffer 40: 50REM (C) John Robinson 1988 60: 70REM Written as 2 modules, so the 80REM program must be in the 90REM current directory or the 100REM library directory 110: 120REM For B/B+/E with disc drive 130REM and sideways RAM 140: 150REM Syntax: *MOVE () () (O) () 160: 170DIM code &A00 180origin1$="FFFF08C0" 190origin2$="FFFF08C0" 200: 210REM OS call names 220oscli = &FFF7 230osbyte = &FFF4 240osword = &FFF1 250oswrch = &FFEE 260osnewl = &FFE7 270osrdch = &FFE0 280osfile = &FFDD 290osargs = &FFDA 300osgbpb = &FFD1 310osfind = &FFCE 320gsread = &FFC5 330gsinit = &FFC2 340 350REM Vectors used 360cmmdln = &00F2 370brkv = &0202 380 390REM Hardware control 400ramsel = &00F4 410romsel = &FE30 420 430REM Workspace allocation 440 450REM Zero-page 460zpworkspace = &00A8 470freezp = zpworkspace+0 480memptr1 = zpworkspace+0 490gsptr = zpworkspace+0 500desttxptr = zpworkspace+1 510initfs = zpworkspace+2 520ramnumber = zpworkspace+3 530options = zpworkspace+4 540retfsno = zpworkspace+5 550memptr2 = zpworkspace+6 560 570REM General 580brkbuff = &0100 590 600REM Main workspace 610workspace = &0750 620srcfsp = workspace+&00 630destfsp = workspace+&35 640savecmmdln = workspace+&6A 650tempfsbuf = workspace+&6C 660rams = workspace+&6A 670rambuf = workspace+&7A 680temp = workspace+&8A 690memstart = workspace+&6A 700membytes = workspace+&6C 710srcgbpbb = workspace+&6E 720destgbpbb = workspace+&7B 730srcfileb = workspace+&88 740destfileb = workspace+&9A 750sourcefs = workspace+&AC 760destfs = workspace+&AD 770oldbrkv = workspace+&AE 780 790REM Note: 176 bytes of main 800REM workspace is required but 810REM only 8 bytes of zero-page. 820: 830FOR pass=4 TO 7 STEP 3 840error=240 850P%=EVAL("&"+origin1$) 860O%=code 870[OPT pass 880 890.move 900LDA #1 910LDX #freezp 920LDY #0 930JSR osargs 940LDY freezp+1 950LDX freezp 960STY cmmdln+1 970STX cmmdln 980LDA #0 990LDY #0 1000JSR osargs 1010STA initfs 1020LDY #0 1030CLC 1040JSR gsinit 1050STY gsptr 1060LDX #srcfsp-workspace 1070JSR input_string 1080BCC source_name_ok 1090JSR brk 1100EQUB FNerror 1110EQUS "Source filename missing" 1120EQUB 0 1130.source_name_ok 1140STA sourcefs 1150LDX #destfsp-workspace 1160JSR input_string 1170\ Read destination filename 1180BCC dest_name_ok 1190JSR brk 1200\ Error 1210EQUB FNerror 1220EQUS "Destination filename missing" 1230EQUB 0 1240.dest_name_ok 1250STA destfs 1260LDY gsptr 1270CLC 1280JSR gsinit 1290BNE P%+5:JMP no_other_params 1300JSR gsread 1310ORA #&20 1320CMP #ASC "o" 1330BNE is_it_romnum 1340JSR gsread 1350BCS optionsparamok 1360JSR brk 1370EQUB FNerror 1380EQUS "Bad options parameter" 1390EQUW &D0A 1400EQUS "Just give ""O""" 1410EQUB 0 1420.optionsparamok 1430LDA #&FF 1440STA options 1450CLC 1460JSR gsinit 1470BEQ set_romnum 1480JSR gsread 1490BCC here_we_go 1500.is_it_romnum 1510PHA 1520LDA #0 1530STA options 1540PLA 1550.here_we_go 1560CMP #ASC "0" 1570BCC badromnum 1580CMP #ASC "9" +1 1590BCC romnumok 1600CMP #ASC "a" 1610BCS checkromnumletter 1620.badromnum 1630JSR brk 1640EQUB FNerror 1650EQUS "Bad RAM id (0-F only)" 1660EQUB 0 1670.checkromnumletter 1680CMP #ASC "f" +1 1690BCS badromnum 1700SEC 1710SBC #ASC "a"-ASC "9"-1 1720.romnumok 1730SEC 1740SBC #ASC "0" 1750STA ramnumber 1760JSR get_rams 1770LDX ramnumber 1780LDA rams,X 1790BMI checkfree 1800.ram_unavailable 1810JSR brk 1820EQUB FNerror 1830EQUS "RAM unavailable" 1840EQUB 0 1850.checkfree 1860LDA &2A1,X 1870BNE ram_unavailable 1880JMP no_more_params 1890.no_other_params 1900LDA #0 1910STA options 1920.set_romnum 1930JSR get_rams 1940LDX #0 1950.find_free_ram 1960LDA rams,X 1970BPL notthis 1980LDA &2A1,X 1990BNE notthis 2000STX ramnumber 2010JMP no_more_params 2020.notthis 2030INX 2040CPX #&10 2050BCC find_free_ram 2060BCS ram_unavailable 2070.no_more_params 2080CLC 2090JSR gsinit 2100BEQ continue 2110JSR brk 2120EQUB FNerror 2130EQUS "Too many parameters" 2140EQUB 0 2150.continue 2160LDA #&8F 2170LDX #&12 2180LDY initfs 2190JSR osbyte 2200JSR mprint 2210EQUS "Using RAM slot " 2220EQUB 0 2230LDA ramnumber 2240JSR pnybble 2250JSR osnewl 2260LDY #runmodule2 DIV 256 2270LDX #runmodule2 MOD 256 2280JMP oscli 2290 2300.runmodule2 2310EQUS "/Move2" 2320EQUB &D 2330 2340.input_string 2350LDA initfs 2360STA retfsno 2370LDY gsptr 2380TYA 2390CLC 2400ADC cmmdln 2410STA cmmdln 2420LDA cmmdln+1 2430ADC #0 2440STA cmmdln+1 2450LDY #0 2460CLC 2470JSR gsinit 2480BEQ no_string 2490.get_the_string_in 2500JSR gsread 2510STA workspace,X 2520BCS finished_getting_string 2530CMP #ASC "-" 2540BEQ tempfs 2550INX 2560CPY #destfsp-srcfsp 2570BCC get_the_string_in 2580JSR brk 2590EQUB FNerror 2600EQUS "Filename string too long (maximum "+STR$(destfsp-srcfsp)+" characters not including fs name)" 2610EQUB 0 2620.finished_getting_string 2630CPX #0 2640BEQ no_string 2650LDA #&D 2660STA workspace,X 2670CLC 2680STY gsptr 2690LDA retfsno 2700RTS 2710.no_string 2720SEC 2730STY gsptr 2740RTS 2750.tempfs 2760STX desttxptr 2770LDA retfsno 2780CMP initfs 2790BEQ get_fs 2800JSR brk 2810EQUB FNerror 2820EQUS "Already got temporary filing system" 2830EQUB 0 2840.get_fs 2850LDX #0 2860.gettempfsname 2870JSR gsread 2880BCS badtempfsname 2890CMP #ASC "-" 2900BEQ got_tempfsname 2910STA tempfsbuf,X 2920INX 2930BNE gettempfsname 2940.got_tempfsname 2950LDA #&D 2960STA tempfsbuf,X 2970STY gsptr 2980LDY brkv+1 2990LDX brkv 3000STY oldbrkv+1 3010STX oldbrkv 3020LDY #newbrk DIV 256 3030LDX #newbrk MOD 256 3040STY brkv+1 3050STX brkv 3060LDY cmmdln+1 3070LDX cmmdln 3080STY savecmmdln+1 3090STX savecmmdln 3100LDA #&8C 3110LDX #3 3120JSR osbyte 3130LDY #tempfsbuf DIV 256 3140LDX #tempfsbuf MOD 256 3150JSR oscli 3160.selected_newfs 3170LDY oldbrkv+1 3180LDX oldbrkv 3190STY brkv+1 3200STX brkv 3210LDY savecmmdln+1 3220LDX savecmmdln 3230STY cmmdln+1 3240STX cmmdln 3250LDA #0 3260LDY #0 3270JSR osargs 3280CMP #2 3290BEQ badtempfsname 3300STA retfsno 3310LDY gsptr 3320LDX desttxptr 3330JMP get_the_string_in 3340.badtempfsname 3350JSR brk 3360EQUB FNerror 3370EQUS "Bad temporary filing system name" 3380EQUB 0 3390.newbrk 3400PLA 3410PLA 3420PLA 3430JMP selected_newfs 3440 3450.get_rams 3460STX temp 3470LDA ramsel 3480PHA 3490LDX #0 3500.check_rams 3510STX ramsel 3520STX romsel 3530LDA &8000 3540STA rambuf,X 3550EOR #&FF 3560STA &8000 3570CMP &8000 3580PHP 3590EOR #&FF 3600STA &8000 3610PLP 3620BEQ found_a_ram 3630LDA #0 3640BEQ set_flag_for_ram 3650.found_a_ram 3660TXA 3670STA &8000 3680LDA #&FF 3690.set_flag_for_ram 3700STA rams,X 3710INX 3720CPX #&10 3730BCC check_rams 3740LDX #&F 3750.check_ghost_loop 3760LDA rams,X 3770BPL not_this_one 3780STX ramsel 3790STX romsel 3800CPX &8000 3810PHP 3820LDA rambuf,X 3830STA &8000 3840PLP 3850BEQ not_this_one 3860LDA #0 3870STA rams,X 3880.not_this_one 3890DEX 3900BPL check_ghost_loop 3910PLA 3920STA ramsel 3930STA romsel 3940LDX temp 3950RTS 3960 3970.brk 3980\ Error handler 3990\ Gives specific error and syntax 4000\ message 4010PLA 4020STA memptr1 4030PLA 4040STA memptr1+1 4050\ Routine was JSRed to, so get 4060\ address of parameters 4070LDY #0 4080\ 0 is also opcode for BRK 4090STY brkbuff 4100.copybrkdata 4110INY 4120LDA (memptr1),Y 4130STA brkbuff,Y 4140BNE copybrkdata 4150TAX 4160.copysyntaxdata 4170LDA syntaxdata,X 4180STA brkbuff,Y 4190INX 4200INY 4210CMP #0 4220BNE copysyntaxdata 4230JMP brkbuff 4240 4250.syntaxdata 4260EQUW &D0A 4270EQUS "Syntax: *MOVE () () (O) ()" 4280EQUW &D0A 4290EQUS "Filing system names enclosed in hyphens, eg -DISC- or -ADFS-" 4300EQUW &D0A 4310EQUS "Ram id hex number 0-F" 4320EQUB 0 4330 4340.pnybble 4350CMP #(ASC "9" +1) AND &0F 4360BCC noadd 4370ADC #ASC "A"-ASC "9"-1 -1 4380\ Extra -1 because carry is 4390\ already set 4400.noadd 4410ADC #ASC "0" 4420JMP oswrch 4430 4440.mprint 4450PLA 4460STA memptr2 4470PLA 4480STA memptr2+1 4490TYA 4500PHA 4510LDY #1 4520.mprintloop 4530LDA (memptr2),Y 4540BEQ donestring 4550JSR oswrch 4560INY 4570BNE mprintloop 4580.donestring 4590TYA 4600CLC 4610ADC memptr2 4620STA memptr2 4630PLA 4640TAY 4650LDA memptr2+1 4660ADC #0 4670PHA 4680LDA memptr2 4690PHA 4700RTS 4710 4720] 4730end_of_module1=O% 4740start_of_module2=O% 4750P%=EVAL("&"+origin2$) 4760[OPT pass 4770 4780.module2 4790LDA #&83 4800JSR osbyte 4810STY memstart+1 4820STX memstart 4830LDA #&84 4840JSR osbyte 4850TXA 4860SEC 4870SBC memstart 4880STA membytes 4890TYA 4900SBC memstart+1 4910STA membytes+1 4920CMP #64 4930BCC nolimit16K 4940LDA #64 4950STA membytes+1 4960LDA #0 4970STA membytes 4980.nolimit16K 4990JSR copy_up_ram 5000JSR copy_file 5010JSR copy_down_ram 5020LDY initfs 5030JSR change_to_fs 5040LDA #18 5050JMP osbyte 5060\ *FX18 = clear soft key buffer 5070 5080.copy_file 5090JSR source_fs 5100JSR osbyte 5110LDY #srcfsp DIV 256 5120LDX #srcfsp MOD 256 5130STY srcfileb+1 5140STX srcfileb 5150LDY #srcfileb DIV 256 5160LDX #srcfileb MOD 256 5170LDA #5 5180JSR osfile 5190CMP #1 5200BEQ file_found 5210BRK 5220EQUB FNerror 5230EQUS "File not found" 5240EQUB 0 5250.promptmessage 5260EQUS " ? (Y/N) " 5270EQUB 0 5280.file_found 5290LDX #0 5300.pname 5310LDA srcfsp,X 5320CMP #&D 5330BEQ done_srcname 5340JSR oswrch 5350INX 5360BNE pname 5370.done_srcname 5380LDA options 5390BEQ copy_the_file_now 5400LDX #0 5410.printstring 5420LDA promptmessage,X 5430BEQ doneprompt 5440JSR oswrch 5450INX 5460BNE printstring 5470.doneprompt 5480JSR osrdch 5490BCS escape 5500AND #&DF 5510CMP #ASC "Y" 5520BEQ copy_the_file_now 5530CMP #ASC "N" 5540BNE doneprompt 5550JSR oswrch 5560JMP osnewl 5570.escape 5580BRK 5590EQUB 17 5600EQUS "Escape" 5610EQUB 0 5620.copy_the_file_now 5630JSR oswrch 5640JSR osnewl 5650LDA memstart 5660STA srcfileb+2 5670STA destfileb+&A 5680CLC 5690ADC srcfileb+&A 5700STA destfileb+&E 5710LDA memstart+1 5720STA srcfileb+3 5730STA destfileb+&B 5740ADC srcfileb+&B 5750STA destfileb+&F 5760LDA #0 5770STA srcfileb+6 5780LDA #&FF 5790STA srcfileb+4 5800STA srcfileb+5 5810STA destfileb+&C 5820STA destfileb+&D 5830STA destfileb+&10 5840STA destfileb+&11 5850JSR check_size 5860BCS P%+5:JMP nousegbpb 5870\ Doing it using multiple OSGBPB 5880\ calls 5890LDA #&40 5900LDY #srcfsp DIV 256 5910LDX #srcfsp MOD 256 5920JSR osfind 5930STA srcgbpbb 5940JSR dest_fs 5950LDA #&80 5960LDY #destfsp DIV 256 5970LDX #destfsp MOD 256 5980JSR osfind 5990CMP #0 6000BNE openedfileok 6010JSR source_fs 6020LDA #0 6030LDY srcgbpbb 6040JSR osfind 6050BRK 6060EQUB FNerror 6070EQUS "Couldn't open file for save" 6080EQUB 0 6090.openedfileok 6100STA destgbpbb 6110.move_using_gbpb_loop 6120LDY membytes+1 6130LDX membytes 6140JSR gbpbs 6150LDA srcfileb+&A 6160SEC 6170SBC membytes 6180STA srcfileb+&A 6190LDA srcfileb+&B 6200SBC membytes+1 6210STA srcfileb+&B 6220LDA srcfileb+&C 6230SBC #0 6240STA srcfileb+&C 6250LDA srcfileb+&D 6260SBC #0 6270STA srcfileb+&D 6280JSR check_size 6290BCS move_using_gbpb_loop 6300LDY srcfileb+&B 6310LDX srcfileb+&A 6320JSR gbpbs 6330JSR source_fs 6340LDA #0 6350LDY srcgbpbb 6360JSR osfind 6370JSR dest_fs 6380LDA #0 6390LDY destgbpbb 6400JSR osfind 6410JMP write_file_attrs 6420.nousegbpb 6430\ Doing it using one OSFILE call 6440LDA #&FF 6450LDY #srcfileb DIV 256 6460LDX #srcfileb MOD 256 6470JSR osfile 6480JSR dest_fs 6490LDY #destfsp DIV 256 6500LDX #destfsp MOD 256 6510STY destfileb+1 6520STX destfileb 6530LDY #destfileb DIV 256 6540LDX #destfileb MOD 256 6550LDA #0 6560JSR osfile 6570.write_file_attrs 6580LDY #destfsp DIV 256 6590LDX #destfsp MOD 256 6600STY srcfileb+1 6610STX srcfileb 6620LDY #srcfileb DIV 256 6630LDX #srcfileb MOD 256 6640LDA #1 6650JSR osfile 6660RTS 6670 6680.gbpbs 6690STY srcgbpbb+6 6700STX srcgbpbb+5 6710STY destgbpbb+6 6720STX destgbpbb+5 6730LDA #0 6740STA srcgbpbb+7 6750STA srcgbpbb+8 6760STA destgbpbb+7 6770STA destgbpbb+8 6780LDX #3 6790.set_up_gbpbbs 6800LDA srcfileb+2,X 6810STA srcgbpbb+1,X 6820STA destgbpbb+1,X 6830DEX 6840BPL set_up_gbpbbs 6850JSR source_fs 6860LDY #srcgbpbb DIV 256 6870LDX #srcgbpbb MOD 256 6880LDA #4 6890JSR osgbpb 6900JSR dest_fs 6910LDY #destgbpbb DIV 256 6920LDX #destgbpbb MOD 256 6930LDA #2 6940JSR osgbpb 6950RTS 6960 6970.copy_up_ram 6980LDA ramsel 6990PHA 7000LDA ramnumber 7010STA ramsel 7020STA romsel 7030JSR initptrs 7040.copy_up_ram_loop 7050LDA (memptr1),Y 7060STA (memptr2),Y 7070INY 7080BNE copy_up_ram_loop 7090INC memptr1+1 7100INC memptr2+1 7110DEX 7120BNE copy_up_ram_loop 7130LDY brkv+1 7140LDX brkv 7150STY oldbrkv+1 7160STX oldbrkv 7170LDY #protectbrk DIV 256 7180LDX #protectbrk MOD 256 7190STY brkv+1 7200STX brkv 7210.restore_rom 7220PLA 7230STA ramsel 7240STA romsel 7250RTS 7260 7270.protectbrk 7280JSR copy_down_ram 7290LDY initfs 7300JSR change_to_fs 7310JMP (brkv) 7320 7330.copy_down_ram 7340LDA ramsel 7350PHA 7360LDA ramnumber 7370STA ramsel 7380STA romsel 7390JSR initptrs 7400.copy_down_ram_loop 7410LDA (memptr2),Y 7420STA (memptr1),Y 7430INY 7440BNE copy_down_ram_loop 7450INC memptr1+1 7460INC memptr2+1 7470DEX 7480BNE copy_down_ram_loop 7490LDY oldbrkv+1 7500LDX oldbrkv 7510STY brkv+1 7520STX brkv 7530JMP restore_rom 7540 7550.initptrs 7560LDY #&80 7570LDX #0 7580STY memptr2+1 7590STX memptr2 7600LDY memstart+1 7610LDX memstart 7620STY memptr1+1 7630STX memptr1 7640LDX membytes+1 7650LDY #0 7660RTS 7670 7680.copyfilename 7690LDA workspace,X 7700STA workspace,Y 7710INX 7720INY 7730CMP #&D 7740BNE copyfilename 7750RTS 7760 7770.check_size 7780LDA srcfileb+&D 7790BNE too_big 7800LDA srcfileb+&C 7810BNE too_big 7820LDA srcfileb+&B 7830CMP membytes+1 7840BCC will_fit 7850LDA srcfileb+&A 7860CMP membytes 7870BCC will_fit 7880.too_big 7890SEC 7900RTS 7910.will_fit 7920CLC 7930RTS 7940 7950.source_fs 7960LDY sourcefs 7970.change_to_fs 7980CPY #3 7990BEQ change_to_RFS 8000BCC otherfss 8010LDA #&8F 8020LDX #&12 8030JMP osbyte 8040.dest_fs 8050LDY destfs 8060JMP change_to_fs 8070.change_to_RFS 8080LDA #&8D 8090JMP osbyte 8100.otherfss 8110CPY #1 8120BEQ cfs1200 8130BCC nofs 8140LDX #3 8150.cfs 8160LDA #&8C 8170JMP osbyte 8180.cfs1200 8190LDX #0 8200BEQ cfs 8210.nofs 8220RTS 8230 8240] 8250NEXT pass 8260: 8270save1$="*SAVE Move "+STR$~code+" "+STR$~end_of_module1+" "+STR$~(move OR &FFFF0000)+" "+origin1$ 8280save2$="*SAVE Move2 "+STR$~start_of_module2+" "+STR$~O%+" "+STR$~(module2 OR &FFFF0000)+" "+origin2$ 8290PRINT save1$'save2$'"Yes/No? "; 8300IF (GET OR &20)=ASC "y" THEN PRINT "Yes"'"Saving...":OSCLI save1$:OSCLI save2$:PRINT "OK." ELSE PRINT "No" 8310: 8320END 8330: 8340DEFFNerror 8350error=error+1 8360=error-1 8370: