├── README.pdf ├── CPMUTools-v091-20231021-1542.zip ├── CPMUTools-v091-20231030-1632.zip ├── CPMUTools-v091-20231112-1325.zip ├── screenshots ├── umount - drives.png ├── umount - version.png ├── uconfig - edithost.png ├── uconfig - settarget.png ├── umount - mainscreen.png ├── uconfig - editoffset.png ├── uconfig - mainscreen.png ├── uconfig - toggletime.png ├── umount - diskcontents.png ├── umount - mountsuccess.png ├── umount - savereusize.png ├── utime - verboseoutput.png ├── uconfig - toggleoverride.png ├── uconfig - toggletargets.png ├── umount - savereufilename.png └── umount - savereufileexists.png ├── include ├── mount_common.h ├── ultimate_time_lib.h ├── core.h ├── ultimate_dos_lib.h ├── ultimate_network_lib.h ├── defines.h └── ultimate_common_lib.h ├── .vscode ├── c_cpp_properties.json └── settings.json ├── .gitignore ├── src ├── ultimate_time_lib.c ├── mount_common.c ├── ultimate_common_lib.c ├── ultimate_network_lib.c ├── ultimate_dos_lib.c ├── core.c ├── config.c ├── time.c └── mount.c ├── Makefile ├── README.md └── LICENSE /README.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xahmol/CPMUTools/HEAD/README.pdf -------------------------------------------------------------------------------- /CPMUTools-v091-20231021-1542.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xahmol/CPMUTools/HEAD/CPMUTools-v091-20231021-1542.zip -------------------------------------------------------------------------------- /CPMUTools-v091-20231030-1632.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xahmol/CPMUTools/HEAD/CPMUTools-v091-20231030-1632.zip -------------------------------------------------------------------------------- /CPMUTools-v091-20231112-1325.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xahmol/CPMUTools/HEAD/CPMUTools-v091-20231112-1325.zip -------------------------------------------------------------------------------- /screenshots/umount - drives.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xahmol/CPMUTools/HEAD/screenshots/umount - drives.png -------------------------------------------------------------------------------- /screenshots/umount - version.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xahmol/CPMUTools/HEAD/screenshots/umount - version.png -------------------------------------------------------------------------------- /screenshots/uconfig - edithost.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xahmol/CPMUTools/HEAD/screenshots/uconfig - edithost.png -------------------------------------------------------------------------------- /screenshots/uconfig - settarget.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xahmol/CPMUTools/HEAD/screenshots/uconfig - settarget.png -------------------------------------------------------------------------------- /screenshots/umount - mainscreen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xahmol/CPMUTools/HEAD/screenshots/umount - mainscreen.png -------------------------------------------------------------------------------- /screenshots/uconfig - editoffset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xahmol/CPMUTools/HEAD/screenshots/uconfig - editoffset.png -------------------------------------------------------------------------------- /screenshots/uconfig - mainscreen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xahmol/CPMUTools/HEAD/screenshots/uconfig - mainscreen.png -------------------------------------------------------------------------------- /screenshots/uconfig - toggletime.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xahmol/CPMUTools/HEAD/screenshots/uconfig - toggletime.png -------------------------------------------------------------------------------- /screenshots/umount - diskcontents.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xahmol/CPMUTools/HEAD/screenshots/umount - diskcontents.png -------------------------------------------------------------------------------- /screenshots/umount - mountsuccess.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xahmol/CPMUTools/HEAD/screenshots/umount - mountsuccess.png -------------------------------------------------------------------------------- /screenshots/umount - savereusize.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xahmol/CPMUTools/HEAD/screenshots/umount - savereusize.png -------------------------------------------------------------------------------- /screenshots/utime - verboseoutput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xahmol/CPMUTools/HEAD/screenshots/utime - verboseoutput.png -------------------------------------------------------------------------------- /screenshots/uconfig - toggleoverride.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xahmol/CPMUTools/HEAD/screenshots/uconfig - toggleoverride.png -------------------------------------------------------------------------------- /screenshots/uconfig - toggletargets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xahmol/CPMUTools/HEAD/screenshots/uconfig - toggletargets.png -------------------------------------------------------------------------------- /screenshots/umount - savereufilename.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xahmol/CPMUTools/HEAD/screenshots/umount - savereufilename.png -------------------------------------------------------------------------------- /screenshots/umount - savereufileexists.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xahmol/CPMUTools/HEAD/screenshots/umount - savereufileexists.png -------------------------------------------------------------------------------- /include/mount_common.h: -------------------------------------------------------------------------------- 1 | #ifndef __MOUNT_COMMON_H_ 2 | #define __MOUNT_COMMON_H_ 3 | 4 | // Global variables 5 | extern unsigned char validdrive[4]; 6 | extern char entrytypes[7][4]; 7 | extern unsigned char targetdrive; 8 | extern unsigned char firmwareflag; 9 | 10 | // Function prototypes 11 | unsigned char CheckUCIStatus(); 12 | void SetValidDrives(); 13 | 14 | #endif -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "WSL2 Ubuntu", 5 | "includePath": [ 6 | "${workspaceFolder}/**", 7 | "/home/xahmol/z88dk/include/" 8 | ], 9 | "defines": [], 10 | "cStandard": "c17", 11 | "cppStandard": "c++98", 12 | "intelliSenseMode": "linux-gcc-x64" 13 | } 14 | ], 15 | "version": 4 16 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "conio.h": "c", 4 | "cia.h": "c", 5 | "mount_common.h": "c" 6 | }, 7 | "C_Cpp.default.compilerPath": "/home/xahmol/z88dk/bin/zcc", 8 | "cSpell.words": [ 9 | "Autodetection", 10 | "CPMU", 11 | "ctools", 12 | "firmwareflag", 13 | "Hutter", 14 | "Jochen", 15 | "Leeuwen", 16 | "Metzinger", 17 | "Plap", 18 | "printstrvdc", 19 | "selectionlines", 20 | "sidsingh", 21 | "Succes", 22 | "ypos", 23 | "Zweijtzer" 24 | ] 25 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | -------------------------------------------------------------------------------- /include/ultimate_time_lib.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | Ultimate 64/II+ Command Library - Time functions 3 | Scott Hutter, Francesco Sblendorio 4 | 5 | Based on ultimate_dos-1.2.docx and command interface.docx 6 | https://github.com/markusC64/1541ultimate2/tree/master/doc 7 | 8 | Disclaimer: Because of the nature of DOS commands, use this code 9 | soley at your own risk. 10 | 11 | Patches and pull requests are welcome 12 | ******************************************************************/ 13 | 14 | #ifndef _ULTIMATE_TIME_LIB_H_ 15 | #define _ULTIMATE_TIME_LIB_H_ 16 | 17 | // prototypes 18 | void uii_get_time(void); 19 | void uii_set_time(char *); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /include/core.h: -------------------------------------------------------------------------------- 1 | #ifndef __CORE_H_ 2 | #define __CORE_H_ 3 | 4 | // Define steering variables 5 | #define MAXDRIVES 5 6 | 7 | // Global variables 8 | extern char buffer[81]; 9 | extern char version[25]; 10 | extern unsigned char vdcDispMem; 11 | extern char filename[13]; 12 | struct ConfigStruct 13 | { 14 | char ntphost[81]; 15 | long secondsfromutc; 16 | unsigned char verbose; 17 | unsigned char ntpon; 18 | unsigned char auto_override; 19 | unsigned char valid[MAXDRIVES]; 20 | unsigned char target; 21 | }; 22 | extern struct ConfigStruct config; 23 | 24 | // Function prototypes 25 | void init(); 26 | void done(unsigned char exitcode); 27 | void delay(ushort D); 28 | int textInput(ushort xpos, ushort ypos, char *str, ushort size); 29 | void ClearArea(ushort x, ushort y, ushort width, ushort height); 30 | void headertext(char *subtitle); 31 | void WriteConfigfile(unsigned char vdcmode); 32 | void ReadConfigfile(unsigned char vdcmode); 33 | 34 | #endif -------------------------------------------------------------------------------- /src/ultimate_time_lib.c: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | Ultimate 64/II+ Command Library - Time functions 3 | Scott Hutter, Francesco Sblendorio 4 | 5 | Based on ultimate_dos-1.2.docx and command interface.docx 6 | https://github.com/markusC64/1541ultimate2/tree/master/doc 7 | 8 | Disclaimer: Because of the nature of DOS commands, use this code 9 | soley at your own risk. 10 | 11 | Patches and pull requests are welcome 12 | ******************************************************************/ 13 | #include 14 | #include "include/ultimate_common_lib.h" 15 | #include "include/ultimate_time_lib.h" 16 | 17 | #pragma code - name("BANKACCESS"); 18 | 19 | void uii_get_time(void) 20 | { 21 | unsigned char cmd[] = {0x00, DOS_CMD_GET_TIME}; 22 | uii_settarget(TARGET_DOS1); 23 | uii_sendcommand(cmd, 2); 24 | 25 | uii_readdata(); 26 | uii_readstatus(); 27 | uii_accept(); 28 | } 29 | 30 | void uii_set_time(char *data) 31 | { 32 | int x = 0; 33 | uii_command[0] = 0x00; 34 | uii_command[1] = DOS_CMD_SET_TIME; 35 | 36 | for (x = 0; x < 6; x++) 37 | uii_command[x + 2] = data[x]; 38 | 39 | uii_settarget(TARGET_DOS1); 40 | uii_sendcommand((unsigned char *)uii_command, 8); 41 | 42 | uii_readstatus(); 43 | uii_accept(); 44 | } -------------------------------------------------------------------------------- /include/ultimate_dos_lib.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | Ultimate 64/II+ Command Library - DOS functions 3 | Scott Hutter, Francesco Sblendorio 4 | 5 | Based on ultimate_dos-1.2.docx and command interface.docx 6 | https://github.com/markusC64/1541ultimate2/tree/master/doc 7 | 8 | Disclaimer: Because of the nature of DOS commands, use this code 9 | soley at your own risk. 10 | 11 | Patches and pull requests are welcome 12 | ******************************************************************/ 13 | 14 | #ifndef _ULTIMATE_DOS_LIB_H_ 15 | #define _ULTIMATE_DOS_LIB_H_ 16 | 17 | // prototypes 18 | 19 | void uii_get_path(void); 20 | void uii_open_dir(void); 21 | void uii_get_dir(void); 22 | void uii_change_dir(char* directory); 23 | void uii_change_dir_home(void); 24 | void uii_mount_disk(unsigned char id, char *filename); 25 | void uii_unmount_disk(unsigned char id); 26 | void uii_open_file(unsigned char attrib, char *filename); 27 | void uii_close_file(void); 28 | void uii_write_file(unsigned char* data, int length); 29 | void uii_read_file(unsigned char length); 30 | void uii_delete_file(char* filename); 31 | void uii_load_reu(unsigned char size); 32 | void uii_save_reu(unsigned char size); 33 | void uii_get_deviceinfo(void); 34 | unsigned char uii_parse_deviceinfo(void); 35 | char* uii_device_tyoe(unsigned char typeval); 36 | void uii_enable_drive_a(void); 37 | void uii_disable_drive_a(void); 38 | void uii_enable_drive_b(void); 39 | void uii_disable_drive_b(void); 40 | void uii_get_drive_a_power(void); 41 | void uii_get_drive_b_power(void); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /include/ultimate_network_lib.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | Ultimate 64/II+ Command Library _ Network functions 3 | Scott Hutter, Francesco Sblendorio 4 | 5 | Based on ultimate_dos-1.2.docx and command interface.docx 6 | https://github.com/markusC64/1541ultimate2/tree/master/doc 7 | 8 | Disclaimer: Because of the nature of DOS commands, use this code 9 | soley at your own risk. 10 | 11 | Patches and pull requests are welcome 12 | ******************************************************************/ 13 | 14 | #ifndef _ULTIMATE_NETWORK_LIB_H_ 15 | #define _ULTIMATE_NETWORK_LIB_H_ 16 | 17 | // prototypes 18 | unsigned char uii_tcpconnect(char *host, unsigned short port); 19 | unsigned char uii_udpconnect(char *host, unsigned short port); 20 | void uii_socketclose(unsigned char socketid); 21 | int uii_socketread(unsigned char socketid, unsigned short length); 22 | void uii_socketwrite(unsigned char socketid, char *data); 23 | void uii_socketwritechar(unsigned char socketid, char one_char); 24 | void uii_socketwrite_ascii(unsigned char socketid, char *data); 25 | 26 | int uii_tcplistenstart(unsigned short port); 27 | int uii_tcplistenstop(void); 28 | int uii_tcpgetlistenstate(void); 29 | unsigned char uii_tcpgetlistensocket(void); 30 | 31 | void uii_logtext(char *text); 32 | void uii_logstatusreg(void); 33 | void uii_sendcommand(unsigned char *bytes, int count); 34 | int uii_readdata(void); 35 | int uii_readstatus(void); 36 | void uii_accept(void); 37 | void uii_abort(void); 38 | int uii_isdataavailable(void); 39 | int uii_isstatusdataavailable(void); 40 | 41 | char uii_tcp_nextchar(unsigned char socketid); 42 | int uii_tcp_nextline(unsigned char socketid, char *); 43 | int uii_tcp_nextline_ascii(unsigned char socketid, char *); 44 | void uii_tcp_emptybuffer(void); 45 | void uii_reset_uiidata(void); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Path to ctools 2 | # Obatin and get from: https://github.com/mist64/ctools 3 | CTOOLS = /home/xahmol/ctools/bin/ 4 | 5 | # Application name 6 | SUITE = cpmutools 7 | MOUNT = umount 8 | TIME = utime 9 | CONFIG = uconfig 10 | 11 | # Deploy list 12 | DEPLOYS = $(MOUNT).com $(TIME).com $(CONFIG).com 13 | 14 | # Zip file data 15 | README = README.pdf 16 | ZIP = CPMUTools-v091-$(shell date "+%Y%m%d-%H%M").zip 17 | ZIPLIST = $(SUITE).d64 $(SUITE).d71 README.pdf 18 | 19 | # Sources for CPM UMount 20 | MOUNTSRC = src/mount.c src/core.c src/mount_common.c src/ultimate_common_lib.c src/ultimate_dos_lib.c src/ultimate_time_lib.c 21 | 22 | # Sources for CPM UTime 23 | TIMESRC = src/time.c src/core.c src/ultimate_common_lib.c src/ultimate_dos_lib.c src/ultimate_time_lib.c src/ultimate_network_lib.c 24 | 25 | # Sources for CPM UConfig 26 | CONFIGSRC = src/config.c src/core.c src/mount_common.c src/ultimate_common_lib.c src/ultimate_dos_lib.c src/ultimate_time_lib.c 27 | 28 | # Hostname of Ultimate II+ target for deployment. Edit for proper IP and usb number 29 | ULTHOST = ftp://192.168.1.19/usb1/cpm/ 30 | ULTHOST2 = ftp://192.168.1.31/usb1/cpm/ 31 | 32 | # Just the usual way to find out if we're 33 | # using cmd.exe to execute make rules. 34 | ifneq ($(shell echo),) 35 | CMD_EXE = 1 36 | endif 37 | 38 | ifdef CMD_EXE 39 | NULLDEV = nul: 40 | DEL = -del /f 41 | RMDIR = rmdir /s /q 42 | else 43 | NULLDEV = /dev/null 44 | DEL = $(RM) 45 | RMDIR = $(RM) -r 46 | endif 47 | 48 | ######################################## 49 | 50 | .SUFFIXES: 51 | .PHONY: all clean deploy 52 | all: $(DEPLOYS) $(SUITE).d64 $(SUITE).d71 $(ZIP) 53 | 54 | # Building CPMUMount 55 | $(MOUNT).com: $(MOUNTSRC) 56 | zcc +cpm -lm -DAMALLOC -lc128cpm -o $@ $^ 57 | 58 | $(TIME).com: $(TIMESRC) 59 | zcc +cpm -lm -DAMALLOC -lc128cpm -o $@ $^ 60 | 61 | $(CONFIG).com: $(CONFIGSRC) 62 | zcc +cpm -lm -DAMALLOC -lc128cpm -o $@ $^ 63 | 64 | # Building .d64 disk image 65 | $(SUITE).d64: $(DEPLOYS) 66 | $(DEL) $(SUITE).d64 2>$(NULLDEV) 67 | $(CTOOLS)cformat $(SUITE).d64 68 | $(CTOOLS)ctools $(SUITE).d64 p $(DEPLOYS) 69 | 70 | # Building .d71 disk image 71 | $(SUITE).d71: $(DEPLOYS) 72 | $(DEL) $(SUITE).d71 2>$(NULLDEV) 73 | $(CTOOLS)cformat -2 $(SUITE).d71 74 | $(CTOOLS)ctools $(SUITE).d71 p $(DEPLOYS) 75 | 76 | # Creating ZIP file for distribution 77 | $(ZIP): $(ZIPLIST) 78 | zip $@ $^ 79 | 80 | clean: 81 | $(DEL) -f *.bin *.d64 *.d71 *.com *.def 2>$(NULLDEV) 82 | 83 | # To deploy software to UII+ enter make deploy. Obviously C128 needs to powered on with UII+ and USB drive connected. 84 | deploy: $(SUITE).d71 85 | wput -u $(SUITE).d71 $(ULTHOST) 86 | # wput -u $(SUITE).d71 $(ULTHOST2) 87 | -------------------------------------------------------------------------------- /include/defines.h: -------------------------------------------------------------------------------- 1 | #ifndef __DEFINES_H_ 2 | #define __DEFINES_H_ 3 | 4 | // Defines for PEEK and POKE functions 5 | #define POKE(addr, val) (*(unsigned char *)(addr) = (val)) 6 | #define POKEW(addr, val) (*(unsigned *)(addr) = (val)) 7 | #define PEEK(addr) (*(unsigned char *)(addr)) 8 | #define PEEKW(addr) (*(unsigned *)(addr)) 9 | 10 | // Defines for default colours 11 | #define colorText vdcLightYellow + vdcAltChrSet 12 | #define colorError vdcLightRed + vdcAltChrSet 13 | #define colorSuccess vdcLightGreen + vdcAltChrSet 14 | #define colorDirEntry vdcWhite + vdcAltChrSet 15 | #define colorSelect vdcDarkCyan + vdcRvsVid + vdcAltChrSet 16 | #define colorHeader1 vdcDarkGreen + vdcRvsVid + vdcAltChrSet 17 | #define colorHeader2 vdcLightGreen + vdcRvsVid + vdcAltChrSet 18 | 19 | // Define cursor key codes 20 | 21 | // Cursor keys right under 22 | #define CURS_LEFT 0x01 23 | #define CURS_RIGHT 0x06 24 | #define CURS_UP 0x1A 25 | #define CURS_DOWN 0x17 26 | 27 | // Cursor keys upper 28 | #define CURU_RIGHT 0x04 29 | #define CURU_UP 0x05 30 | #define CURU_LEFT 0x13 31 | #define CURU_DOWN 0x18 32 | 33 | // Other keys 34 | #define K_BACKKSPACE 0x08 35 | #define K_RETURN 0x0A 36 | #define K_CR 0x0D 37 | #define K_ESCAPE 0x1B 38 | #define K_DEL 0x7F 39 | 40 | /* Defines for versioning */ 41 | 42 | // Config file version 43 | #define configfileversion 1 44 | 45 | /* Version number */ 46 | #define VERSION_MAJOR 0 47 | #define VERSION_MINOR 91 48 | /* Build year */ 49 | #define BUILD_YEAR_CH0 (__DATE__[7]) 50 | #define BUILD_YEAR_CH1 (__DATE__[8]) 51 | #define BUILD_YEAR_CH2 (__DATE__[9]) 52 | #define BUILD_YEAR_CH3 (__DATE__[10]) 53 | /* Build month */ 54 | #define BUILD_MONTH_IS_JAN (__DATE__[0] == 'J' && __DATE__[1] == 'a' && __DATE__[2] == 'n') 55 | #define BUILD_MONTH_IS_FEB (__DATE__[0] == 'F') 56 | #define BUILD_MONTH_IS_MAR (__DATE__[0] == 'M' && __DATE__[1] == 'a' && __DATE__[2] == 'r') 57 | #define BUILD_MONTH_IS_APR (__DATE__[0] == 'A' && __DATE__[1] == 'p') 58 | #define BUILD_MONTH_IS_MAY (__DATE__[0] == 'M' && __DATE__[1] == 'a' && __DATE__[2] == 'y') 59 | #define BUILD_MONTH_IS_JUN (__DATE__[0] == 'J' && __DATE__[1] == 'u' && __DATE__[2] == 'n') 60 | #define BUILD_MONTH_IS_JUL (__DATE__[0] == 'J' && __DATE__[1] == 'u' && __DATE__[2] == 'l') 61 | #define BUILD_MONTH_IS_AUG (__DATE__[0] == 'A' && __DATE__[1] == 'u') 62 | #define BUILD_MONTH_IS_SEP (__DATE__[0] == 'S') 63 | #define BUILD_MONTH_IS_OCT (__DATE__[0] == 'O') 64 | #define BUILD_MONTH_IS_NOV (__DATE__[0] == 'N') 65 | #define BUILD_MONTH_IS_DEC (__DATE__[0] == 'D') 66 | #define BUILD_MONTH_CH0 ((BUILD_MONTH_IS_OCT || BUILD_MONTH_IS_NOV || BUILD_MONTH_IS_DEC) ? '1' : '0') 67 | #define BUILD_MONTH_CH1 ((BUILD_MONTH_IS_JAN) ? '1' : (BUILD_MONTH_IS_FEB) ? '2' \ 68 | : (BUILD_MONTH_IS_MAR) ? '3' \ 69 | : (BUILD_MONTH_IS_APR) ? '4' \ 70 | : (BUILD_MONTH_IS_MAY) ? '5' \ 71 | : (BUILD_MONTH_IS_JUN) ? '6' \ 72 | : (BUILD_MONTH_IS_JUL) ? '7' \ 73 | : (BUILD_MONTH_IS_AUG) ? '8' \ 74 | : (BUILD_MONTH_IS_SEP) ? '9' \ 75 | : (BUILD_MONTH_IS_OCT) ? '0' \ 76 | : (BUILD_MONTH_IS_NOV) ? '1' \ 77 | : (BUILD_MONTH_IS_DEC) ? '2' \ 78 | : '?') 79 | 80 | /* Build day */ 81 | #define BUILD_DAY_CH0 ((__DATE__[4] >= '0') ? (__DATE__[4]) : '0') 82 | #define BUILD_DAY_CH1 (__DATE__[5]) 83 | /* Build hour */ 84 | #define BUILD_HOUR_CH0 (__TIME__[0]) 85 | #define BUILD_HOUR_CH1 (__TIME__[1]) 86 | /* Build minute */ 87 | #define BUILD_MIN_CH0 (__TIME__[3]) 88 | #define BUILD_MIN_CH1 (__TIME__[4]) 89 | 90 | #endif // __DEFINES_H_ -------------------------------------------------------------------------------- /src/mount_common.c: -------------------------------------------------------------------------------- 1 | /* 2 | CPMUMount 3 | Disk mounter for the Ultimate II+ in CPMS 4 | Written in 2023 by Xander Mol 5 | 6 | https://github.com/xahmol/CPMUTools 7 | 8 | https://www.idreamtin8bits.com/ 9 | 10 | Code and resources from others used: 11 | 12 | - Scott Hutter - Ultimate II+ library: 13 | https://github.com/xlar54/ultimateii-dos-lib/ 14 | (library for the UII+ UCI functions) 15 | 16 | - z88dk C cross compiler for Z80 targets, including C128 CP/M 17 | https://github.com/z88dk/z88dk/wiki 18 | 19 | - Jochen Metzinger - ctools 20 | https://github.com/mist64/ctools 21 | 22 | - ntp2ultimate by MaxPlap 23 | https://github.com/MaxPlap/ntp2ultimate 24 | Time via NTP code 25 | 26 | - EPOCH-to-time-date-converter by sidsingh78 27 | https://github.com/sidsingh78/EPOCH-to-time-date-converter/blob/master/epoch_conv.c 28 | 29 | - Bart van Leeuwen for providing CP/M images, testing and advice 30 | 31 | - Gideon Zweijtzer for creating the Ultimate II+ cartridge and the Ultimate64, and the Ultimate Command Interface enabling this software. 32 | 33 | - Tested using real hardware (C128D, C128DCR) using CP/M 3.0 and ZP/M+. 34 | 35 | Licensed under the GNU General Public License v3.0 36 | 37 | The code can be used freely as long as you retain 38 | a notice describing original source and author. 39 | 40 | THE PROGRAMS ARE DISTRIBUTED IN THE HOPE THAT THEY WILL BE USEFUL, 41 | BUT WITHOUT ANY WARRANTY. USE THEM AT YOUR OWN RISK! 42 | */ 43 | 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include "include/defines.h" 54 | #include "include/core.h" 55 | #include "include/mount_common.h" 56 | #include "include/ultimate_common_lib.h" 57 | #include "include/ultimate_dos_lib.h" 58 | #include "include/ultimate_time_lib.h" 59 | 60 | // Global variables 61 | unsigned char validdrive[MAXDRIVES]; 62 | char entrytypes[7][4] = { 63 | "DIR", 64 | "D64", 65 | "D71", 66 | "D81", 67 | "DNP", 68 | "!TL"}; 69 | unsigned char targetdrive; 70 | unsigned char firmwareflag; 71 | 72 | // UCI routines 73 | 74 | unsigned char CheckUCIStatus() 75 | { 76 | // Function to check UII+ status and print error box if applicable 77 | 78 | if (!uii_success()) 79 | { 80 | ClearArea(0, 24, 80, 1); 81 | printstrvdc(0, 24, colorError, "Error: "); 82 | sprintf(buffer, "%s. Press key.", uii_status); 83 | printstrvdc(7, 24, colorText, buffer); 84 | cgetc(); 85 | ClearArea(0, 24, 80, 1); 86 | return 1; 87 | } 88 | return 0; 89 | } 90 | 91 | void SetValidDrives() 92 | { 93 | // Initialise variables to defines which drive IDs are valid targets 94 | 95 | unsigned char drive; 96 | 97 | memset(&validdrive, 0, MAXDRIVES); 98 | targetdrive = 0; 99 | firmwareflag = 0; 100 | 101 | if (!uii_detect()) 102 | { 103 | printf("No Ultimate Command Interface.\n\r"); 104 | exit(1); 105 | } 106 | 107 | uii_settarget(TARGET_DOS1); 108 | if (uii_isdataavailable()) 109 | { 110 | uii_abort(); 111 | } 112 | 113 | // Set dir at home dir 114 | uii_change_dir_home(); 115 | 116 | // Get device info from UCI 117 | if (!uii_parse_deviceinfo()) 118 | { 119 | config.auto_override = 1; 120 | firmwareflag = 2; 121 | } 122 | 123 | if (config.auto_override) 124 | { 125 | // Set valid drives with the override settings in the config data 126 | 127 | for (drive = 0; drive < 4; drive++) 128 | { 129 | validdrive[drive] = config.valid[drive]; 130 | } 131 | } 132 | else 133 | { 134 | // Set valid drives with auto detection 135 | 136 | for (drive = 0; drive < MAXDRIVES; drive++) 137 | { 138 | validdrive[drive] = 0; 139 | 140 | // Check if drive ID is a Ultimate emulated drive 141 | if (uii_devinfo[0].id == drive + 8) 142 | { 143 | validdrive[drive] = 1; 144 | } 145 | if (uii_devinfo[1].id == drive + 8) 146 | { 147 | validdrive[drive] = 2; 148 | } 149 | if (uii_devinfo[2].id == drive + 8) 150 | { 151 | validdrive[drive] = 3; 152 | } 153 | if (validdrive[drive] && !targetdrive) 154 | { 155 | targetdrive = drive + 1; 156 | } 157 | } 158 | } 159 | 160 | // Set target drive to override if set and valid 161 | if (config.target && validdrive[config.target - 1]) 162 | { 163 | targetdrive = config.target; 164 | } 165 | } -------------------------------------------------------------------------------- /src/ultimate_common_lib.c: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | Ultimate 64/II+ Command Library - Core functions 3 | Scott Hutter, Francesco Sblendorio 4 | 5 | Based on ultimate_dos-1.2.docx and command interface.docx 6 | https://github.com/markusC64/1541ultimate2/tree/master/doc 7 | 8 | Disclaimer: Because of the nature of DOS commands, use this code 9 | soley at your own risk. 10 | 11 | Patches and pull requests are welcome 12 | ****************************************************************** 13 | 14 | Adapted for z88dk by Xander Mol, 2023 */ 15 | 16 | #include 17 | #include 18 | #include "include/ultimate_common_lib.h" 19 | 20 | #pragma code - name("BANKACCESS"); 21 | 22 | // Commented out as these need to be addressed as IO register via IN and OUT on Z80 23 | // unsigned char *id_reg = (unsigned char *)ID_REG; 24 | // unsigned char *cmddatareg = (unsigned char *)CMD_DATA_REG; 25 | // unsigned char *controlreg = (unsigned char *)CONTROL_REG; 26 | // unsigned char *statusreg = (unsigned char *)STATUS_REG; 27 | // unsigned char *respdatareg = (unsigned char *)RESP_DATA_REG; 28 | // unsigned char *statusdatareg = (unsigned char *)STATUS_DATA_REG; 29 | 30 | char uii_status[STATUS_QUEUE_SZ + 1]; 31 | char uii_data[(DATA_QUEUE_SZ * 2) + 1]; 32 | char uii_command[128]; 33 | char temp_string_onechar[2]; 34 | int uii_data_index; 35 | int uii_data_len; 36 | 37 | unsigned char uii_target = TARGET_DOS1; 38 | struct DevInfo uii_devinfo[4]; 39 | 40 | // Core functions 41 | unsigned char uii_detect(void) 42 | { 43 | // Detect present of UCI via ID_REG. Value should be $C9 44 | if (inp(ID_REG) == 0xc9) 45 | { 46 | // Reset UCI 47 | uii_abort(); 48 | 49 | // Return 1 for detected = true 50 | return 1; 51 | } 52 | else 53 | { 54 | // Return 0 for detected = false 55 | return 0; 56 | } 57 | } 58 | 59 | void uii_settarget(unsigned char id) 60 | { 61 | uii_target = id; 62 | } 63 | 64 | void uii_freeze(void) 65 | { 66 | unsigned char cmd[] = {0x00, 0x05}; 67 | 68 | uii_settarget(TARGET_CONTROL); 69 | 70 | uii_sendcommand(cmd, 2); 71 | uii_readdata(); 72 | uii_readstatus(); 73 | uii_accept(); 74 | } 75 | 76 | void uii_identify(void) 77 | { 78 | unsigned char cmd[] = {0x00, DOS_CMD_IDENTIFY}; 79 | uii_settarget(TARGET_DOS1); 80 | uii_sendcommand(cmd, 2); 81 | uii_readdata(); 82 | uii_readstatus(); 83 | uii_accept(); 84 | } 85 | 86 | void uii_echo(void) 87 | { 88 | unsigned char cmd[] = {0x00, DOS_CMD_ECHO}; 89 | uii_settarget(TARGET_DOS1); 90 | uii_sendcommand(cmd, 2); 91 | 92 | uii_readdata(); 93 | uii_readstatus(); 94 | uii_accept(); 95 | } 96 | 97 | void uii_getinterfacecount(void) 98 | { 99 | unsigned char tempTarget = uii_target; 100 | unsigned char cmd[] = {0x00, NET_CMD_GET_INTERFACE_COUNT}; 101 | 102 | uii_settarget(TARGET_NETWORK); 103 | uii_sendcommand(cmd, 0x02); 104 | 105 | uii_readdata(); 106 | uii_readstatus(); 107 | uii_accept(); 108 | 109 | uii_target = tempTarget; 110 | } 111 | 112 | void uii_sendcommand(unsigned char *bytes, int count) 113 | { 114 | int x = 0; 115 | int success = 0; 116 | 117 | bytes[0] = uii_target; 118 | 119 | while (success == 0) 120 | { 121 | // Wait for idle state 122 | while (inp(STATUS_REG) & 0x35) 123 | { 124 | ; 125 | }; 126 | 127 | // Write byte by byte to data register 128 | while (x < count) 129 | outp(CMD_DATA_REG, bytes[x++]); 130 | 131 | // Send PUSH_CMD 132 | outp(CONTROL_REG, inp(CONTROL_REG) | 0x01); 133 | 134 | // check ERROR bit. If set, clear it via ctrl reg, and try again 135 | if ((inp(STATUS_REG) & 4) == 4) 136 | { 137 | outp(CONTROL_REG, inp(CONTROL_REG) | 0x08); 138 | } 139 | else 140 | { 141 | // check for cmd busy 142 | while (((inp(STATUS_REG) & 32) == 0) && ((inp(STATUS_REG) & 16) == 16)) 143 | { 144 | ; 145 | } 146 | success = 1; 147 | } 148 | } 149 | } 150 | 151 | void uii_accept(void) 152 | { 153 | // Acknowledge the data 154 | outp(CONTROL_REG, inp(CONTROL_REG) | 0x02); 155 | while (!(inp(STATUS_REG) & 2) == 0) 156 | { 157 | ; 158 | }; 159 | } 160 | 161 | int uii_isdataavailable(void) 162 | { 163 | if (((inp(STATUS_REG) & 128) == 128)) 164 | return 1; 165 | else 166 | return 0; 167 | } 168 | 169 | int uii_isstatusdataavailable(void) 170 | { 171 | if (((inp(STATUS_REG) & 64) == 64)) 172 | return 1; 173 | else 174 | return 0; 175 | } 176 | 177 | void uii_abort(void) 178 | { 179 | // abort the command 180 | outp(CONTROL_REG, inp(CONTROL_REG) | 0x04); 181 | } 182 | 183 | int uii_readdata(void) 184 | { 185 | int count = 0; 186 | uii_data[0] = 0; 187 | 188 | // If there is data to read 189 | while (uii_isdataavailable() && count < DATA_QUEUE_SZ * 2) 190 | { 191 | uii_data[count++] = inp(RESP_DATA_REG); 192 | } 193 | uii_data[count] = 0; 194 | return count; 195 | } 196 | 197 | int uii_readstatus(void) 198 | { 199 | int count = 0; 200 | uii_status[0] = 0; 201 | 202 | while (uii_isstatusdataavailable() && count < STATUS_QUEUE_SZ) 203 | { 204 | uii_status[count++] = inp(STATUS_DATA_REG); 205 | } 206 | 207 | uii_status[count] = 0; 208 | return count; 209 | } -------------------------------------------------------------------------------- /include/ultimate_common_lib.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | Ultimate 64/II+ Command Library - Core functions 3 | Scott Hutter, Francesco Sblendorio 4 | 5 | Based on ultimate_dos-1.2.docx and command interface.docx 6 | https://github.com/markusC64/1541ultimate2/tree/master/doc 7 | 8 | Disclaimer: Because of the nature of DOS commands, use this code 9 | soley at your own risk. 10 | 11 | Patches and pull requests are welcome 12 | ****************************************************************** 13 | 14 | Adapted for z88dk by Xander Mol, 2023 */ 15 | 16 | #ifndef _ULTIMATE_COMMON_LIB_H_ 17 | #define _ULTIMATE_COMMON_LIB_H_ 18 | 19 | #include 20 | #include 21 | 22 | // bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 23 | #define CONTROL_REG 0xDF1C // --------reserved------ --------- CLR_ERR ABORT DATA_ACC PUSH_CMD 24 | #define STATUS_REG 0xDF1C // DATA_AV STAT_AV [ STATE ] ERROR ABORT_P DATA_ACC CMD_BUSY 25 | #define CMD_DATA_REG 0xDF1D 26 | #define ID_REG 0xDF1D 27 | #define RESP_DATA_REG 0xDF1E 28 | #define STATUS_DATA_REG 0xDF1F 29 | 30 | #define DATA_QUEUE_SZ 256 31 | #define STATUS_QUEUE_SZ 256 32 | 33 | #define TARGET_DOS1 0x01 34 | #define TARGET_DOS2 0x02 35 | #define TARGET_NETWORK 0x03 36 | #define TARGET_CONTROL 0x04 37 | 38 | #define DOS_CMD_IDENTIFY 0x01 39 | #define DOS_CMD_OPEN_FILE 0x02 40 | #define DOS_CMD_CLOSE_FILE 0x03 41 | #define DOS_CMD_READ_DATA 0x04 42 | #define DOS_CMD_WRITE_DATA 0x05 43 | #define DOS_CMD_FILE_SEEK 0x06 44 | #define DOS_CMD_FILE_INFO 0x07 45 | #define DOS_CMD_FILE_STAT 0x08 46 | #define DOS_CMD_DELETE_FILE 0x09 47 | #define DOS_CMD_RENAME_FILE 0x0a 48 | #define DOS_CMD_COPY_FILE 0x0b 49 | #define DOS_CMD_CHANGE_DIR 0x11 50 | #define DOS_CMD_GET_PATH 0x12 51 | #define DOS_CMD_OPEN_DIR 0x13 52 | #define DOS_CMD_READ_DIR 0x14 53 | #define DOS_CMD_COPY_UI_PATH 0x15 54 | #define DOS_CMD_CREATE_DIR 0x16 55 | #define DOS_CMD_COPY_HOME_PATH 0x17 56 | #define DOS_CMD_LOAD_REU 0x21 57 | #define DOS_CMD_SAVE_REU 0x22 58 | #define DOS_CMD_MOUNT_DISK 0x23 59 | #define DOS_CMD_UMOUNT_DISK 0x24 60 | #define DOS_CMD_SWAP_DISK 0x25 61 | #define DOS_CMD_GET_TIME 0x26 62 | #define DOS_CMD_SET_TIME 0x27 63 | #define DOS_CMD_LOAD_INTO_RAMDISK 0x41 64 | #define DOS_CMD_SAVE_RAMDISK 0x42 65 | #define CTRL_CMD_DEVICE_INFO 0x29 66 | #define CTRL_CMD_ENABLE_DISK_A 0x30 67 | #define CTRL_CMD_DISABLE_DISK_A 0x31 68 | #define CTRL_CMD_ENABLE_DISK_B 0x32 69 | #define CTRL_CMD_DISABLE_DISK_B 0x33 70 | #define CTRL_CMD_DRIVE_A_POWER 0x34 71 | #define CTRL_CMD_DRIVE_B_POWER 0x35 72 | #define CTRL_CMD_GET_RAMDISK_INFO 0x40 73 | #define DOS_CMD_ECHO 0xf0 74 | 75 | #define NET_CMD_GET_INTERFACE_COUNT 0x02 76 | #define NET_CMD_GET_IP_ADDRESS 0x05 77 | #define NET_CMD_TCP_SOCKET_CONNECT 0x07 78 | #define NET_CMD_UDP_SOCKET_CONNECT 0x08 79 | #define NET_CMD_SOCKET_CLOSE 0x09 80 | #define NET_CMD_SOCKET_READ 0x10 81 | #define NET_CMD_SOCKET_WRITE 0x11 82 | #define NET_CMD_TCP_LISTENER_START 0x12 83 | #define NET_CMD_TCP_LISTENER_STOP 0x13 84 | #define NET_CMD_GET_LISTENER_STATE 0x14 85 | #define NET_CMD_GET_LISTENER_SOCKET 0x15 86 | 87 | #define NET_LISTENER_STATE_NOT_LISTENEING 0x00 88 | #define NET_LISTENER_STATE_LISTENING 0x01 89 | #define NET_LISTENER_STATE_CONNECTED 0x02 90 | #define NET_LISTENER_STATE_BIND_ERROR 0x03 91 | #define NET_LISTENER_STATE_PORT_IN_USE 0x04 92 | 93 | // #define DEBUG 94 | #define DISPLAY_READ 95 | 96 | #define uii_success() (uii_status[0] == '0' && uii_status[1] == '0') 97 | 98 | // Commented out as these need to be addressed as IO register via IN and OUT on Z80 99 | // extern unsigned char *id_reg; 100 | // extern unsigned char *cmddatareg; 101 | // extern unsigned char *controlreg; 102 | // extern unsigned char *statusreg; 103 | // extern unsigned char *respdatareg; 104 | // extern unsigned char *statusdatareg; 105 | extern char uii_status[STATUS_QUEUE_SZ + 1]; 106 | extern char uii_data[(DATA_QUEUE_SZ * 2) + 1]; 107 | extern char uii_command[128]; 108 | extern char temp_string_onechar[2]; 109 | extern int uii_data_index; 110 | extern int uii_data_len; 111 | extern unsigned char uii_target; 112 | struct DevInfo 113 | { 114 | // Structure to parse drive info 115 | unsigned char exist; 116 | // Does it exist? 0 = no 1 = yes 117 | unsigned char type; 118 | // Type (hex): 119 | // 00 = 1541 120 | // 01 - 1571 121 | // 02 = 1581 122 | // 0F = SoftIEC 123 | // 50 = Printer 124 | unsigned char power; 125 | // Power 0 = off 1 = on 126 | unsigned char id; 127 | // IEC ID 128 | }; 129 | extern struct DevInfo uii_devinfo[4]; 130 | // Array of info per device 131 | // 0 = drive A 132 | // 1 = drive B 133 | // 2 = SoftIEC 134 | // 3 = Printerindo 135 | 136 | // prototypes 137 | unsigned char uii_detect(void); 138 | 139 | void uii_logtext(char *text); 140 | void uii_logstatusreg(void); 141 | 142 | void uii_settarget(unsigned char id); 143 | void uii_freeze(void); 144 | void uii_identify(void); 145 | void uii_echo(void); 146 | void uii_getinterfacecount(void); 147 | 148 | void uii_sendcommand(unsigned char *bytes, int count); 149 | void uii_accept(void); 150 | int uii_isdataavailable(void); 151 | int uii_isstatusdataavailable(void); 152 | void uii_abort(void); 153 | int uii_readdata(void); 154 | int uii_readstatus(void); 155 | 156 | #endif 157 | -------------------------------------------------------------------------------- /src/ultimate_network_lib.c: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | Ultimate 64/II+ Command Library - Network functions 3 | Scott Hutter, Francesco Sblendorio 4 | 5 | Based on ultimate_dos-1.2.docx and command interface.docx 6 | https://github.com/markusC64/1541ultimate2/tree/master/doc 7 | 8 | Disclaimer: Because of the nature of DOS commands, use this code 9 | soley at your own risk. 10 | 11 | Patches and pull requests are welcome 12 | ******************************************************************/ 13 | #include 14 | #include "include/ultimate_common_lib.h" 15 | #include "include/ultimate_network_lib.h" 16 | 17 | #pragma code - name("CODE2"); 18 | #pragma rodata - name("RODATA2"); 19 | 20 | // Network functions 21 | void uii_getipaddress(void) 22 | { 23 | unsigned char tempTarget = uii_target; 24 | unsigned char cmd[] = {0x00, NET_CMD_GET_IP_ADDRESS, 0x00}; // interface 0 (theres only one) 25 | 26 | uii_settarget(TARGET_NETWORK); 27 | uii_sendcommand(cmd, 0x03); 28 | 29 | uii_readdata(); 30 | uii_readstatus(); 31 | uii_accept(); 32 | 33 | uii_target = tempTarget; 34 | } 35 | 36 | unsigned char uii_connect(char *host, unsigned short port, char cmd) 37 | { 38 | unsigned char tempTarget = uii_target; 39 | int x = 0; 40 | uii_command[0] = 0x00; 41 | uii_command[1] = cmd; 42 | uii_command[2] = port & 0xff; 43 | uii_command[3] = (port >> 8) & 0xff; 44 | 45 | for (x = 0; x < strlen(host); x++) 46 | uii_command[x + 4] = host[x]; 47 | 48 | uii_command[4 + strlen(host)] = 0x00; 49 | 50 | uii_settarget(TARGET_NETWORK); 51 | uii_sendcommand((unsigned char *)uii_command, 4 + strlen(host) + 1); 52 | 53 | uii_readdata(); 54 | uii_readstatus(); 55 | uii_accept(); 56 | 57 | uii_target = tempTarget; 58 | 59 | uii_data_index = 0; 60 | uii_data_len = 0; 61 | return uii_data[0]; 62 | } 63 | 64 | unsigned char uii_tcpconnect(char *host, unsigned short port) 65 | { 66 | return uii_connect(host, port, NET_CMD_TCP_SOCKET_CONNECT); 67 | } 68 | 69 | unsigned char uii_udpconnect(char *host, unsigned short port) 70 | { 71 | return uii_connect(host, port, NET_CMD_UDP_SOCKET_CONNECT); 72 | } 73 | 74 | void uii_socketclose(unsigned char socketid) 75 | { 76 | unsigned char tempTarget = uii_target; 77 | unsigned char cmd[] = {0x00, NET_CMD_SOCKET_CLOSE, 0x00}; 78 | cmd[2] = socketid; 79 | 80 | uii_settarget(TARGET_NETWORK); 81 | uii_sendcommand(cmd, 0x03); 82 | 83 | uii_readdata(); 84 | uii_readstatus(); 85 | uii_accept(); 86 | 87 | uii_target = tempTarget; 88 | } 89 | 90 | int uii_socketread(unsigned char socketid, unsigned short length) 91 | { 92 | unsigned char tempTarget = uii_target; 93 | unsigned char cmd[] = {0x00, NET_CMD_SOCKET_READ, 0x00, 0x00, 0x00}; 94 | 95 | cmd[2] = socketid; 96 | cmd[3] = length & 0xff; 97 | cmd[4] = (length >> 8) & 0xff; 98 | 99 | uii_settarget(TARGET_NETWORK); 100 | uii_sendcommand(cmd, 0x05); 101 | 102 | uii_readdata(); 103 | uii_readstatus(); 104 | uii_accept(); 105 | 106 | uii_target = tempTarget; 107 | return uii_data[0] | (uii_data[1] << 8); 108 | } 109 | 110 | int uii_tcplistenstart(unsigned short port) 111 | { 112 | unsigned char tempTarget = uii_target; 113 | unsigned char cmd[] = {0x00, NET_CMD_TCP_LISTENER_START, 0x00, 0x00}; 114 | cmd[2] = port & 0xff; 115 | cmd[3] = (port >> 8) & 0xff; 116 | 117 | uii_settarget(TARGET_NETWORK); 118 | uii_sendcommand(cmd, 0x04); 119 | 120 | uii_readdata(); 121 | uii_readstatus(); 122 | uii_accept(); 123 | 124 | uii_target = tempTarget; 125 | return uii_data[0] | (uii_data[1] << 8); 126 | } 127 | 128 | int uii_tcplistenstop() 129 | { 130 | unsigned char tempTarget = uii_target; 131 | unsigned char cmd[] = {0x00, NET_CMD_TCP_LISTENER_STOP}; 132 | 133 | uii_settarget(TARGET_NETWORK); 134 | uii_sendcommand(cmd, 0x02); 135 | 136 | uii_readdata(); 137 | uii_readstatus(); 138 | uii_accept(); 139 | 140 | uii_target = tempTarget; 141 | return uii_data[0] | (uii_data[1] << 8); 142 | } 143 | 144 | int uii_tcpgetlistenstate() 145 | { 146 | unsigned char tempTarget = uii_target; 147 | unsigned char cmd[] = {0x00, NET_CMD_GET_LISTENER_STATE}; 148 | 149 | uii_settarget(TARGET_NETWORK); 150 | uii_sendcommand(cmd, 0x02); 151 | 152 | uii_readdata(); 153 | uii_readstatus(); 154 | uii_accept(); 155 | 156 | uii_target = tempTarget; 157 | return uii_data[0] | (uii_data[1] << 8); 158 | } 159 | 160 | unsigned char uii_tcpgetlistensocket() 161 | { 162 | unsigned char tempTarget = uii_target; 163 | unsigned char cmd[] = {0x00, NET_CMD_GET_LISTENER_SOCKET}; 164 | 165 | uii_settarget(TARGET_NETWORK); 166 | uii_sendcommand(cmd, 0x02); 167 | 168 | uii_readdata(); 169 | uii_readstatus(); 170 | uii_accept(); 171 | 172 | uii_target = tempTarget; 173 | return uii_data[0] | (uii_data[1] << 8); 174 | } 175 | 176 | void uii_socketwrite_convert_parameter(unsigned char socketid, char *data, int ascii) 177 | { 178 | unsigned char tempTarget = uii_target; 179 | int x; 180 | char c; 181 | uii_command[0] = 0x00; 182 | uii_command[1] = NET_CMD_SOCKET_WRITE; 183 | uii_command[2] = socketid; 184 | 185 | for (x = 0; x < strlen(data); x++) 186 | { 187 | c = data[x]; 188 | if (ascii) 189 | { 190 | if ((c >= 97 && c <= 122) || (c >= 193 && c <= 218)) 191 | c &= 95; 192 | else if (c >= 65 && c <= 90) 193 | c |= 32; 194 | else if (c == 13) 195 | c = 10; 196 | } 197 | uii_command[x + 3] = c; 198 | } 199 | 200 | uii_command[3 + strlen(data) + 1] = 0; 201 | 202 | uii_settarget(TARGET_NETWORK); 203 | uii_sendcommand((unsigned char *)uii_command, 3 + strlen(data)); 204 | 205 | uii_readdata(); 206 | uii_readstatus(); 207 | uii_accept(); 208 | 209 | uii_target = tempTarget; 210 | 211 | uii_data_index = 0; 212 | uii_data_len = 0; 213 | } 214 | 215 | void uii_socketwritechar(unsigned char socketid, char one_char) 216 | { 217 | temp_string_onechar[0] = one_char; 218 | temp_string_onechar[1] = 0; 219 | 220 | uii_socketwrite(socketid, temp_string_onechar); 221 | } 222 | 223 | void uii_socketwrite(unsigned char socketid, char *data) 224 | { 225 | uii_socketwrite_convert_parameter(socketid, data, 0); 226 | } 227 | 228 | void uii_socketwrite_ascii(unsigned char socketid, char *data) 229 | { 230 | uii_socketwrite_convert_parameter(socketid, data, 1); 231 | } 232 | 233 | char uii_tcp_nextchar(unsigned char socketid) 234 | { 235 | char result; 236 | if (uii_data_index < uii_data_len) 237 | { 238 | result = uii_data[uii_data_index + 2]; 239 | uii_data_index++; 240 | } 241 | else 242 | { 243 | do 244 | { 245 | uii_data_len = uii_socketread(socketid, DATA_QUEUE_SZ - 4); 246 | if (uii_data_len == 0) 247 | return 0; // EOF 248 | } while (uii_data_len == -1); 249 | result = uii_data[2]; 250 | uii_data_index = 1; 251 | } 252 | return result; 253 | } 254 | 255 | int uii_tcp_nextline_convert_parameter(unsigned char socketid, char *result, int swapCase) 256 | { 257 | int c, count = 0; 258 | *result = 0; 259 | while ((c = uii_tcp_nextchar(socketid)) != 0 && c != 0x0A) 260 | { 261 | if (c == 0x0D) 262 | { 263 | continue; 264 | } 265 | else if (swapCase) 266 | { 267 | if ((c >= 97 && c <= 122) || (c >= 193 && c <= 218)) 268 | c &= 95; 269 | else if (c >= 65 && c <= 90) 270 | c |= 32; 271 | } 272 | result[count++] = c; 273 | } 274 | result[count] = 0; 275 | return c != 0 || count > 0; 276 | } 277 | 278 | int uii_tcp_nextline(unsigned char socketid, char *result) 279 | { 280 | return uii_tcp_nextline_convert_parameter(socketid, result, 0); 281 | } 282 | 283 | int uii_tcp_nextline_ascii(unsigned char socketid, char *result) 284 | { 285 | return uii_tcp_nextline_convert_parameter(socketid, result, 1); 286 | } 287 | 288 | void uii_reset_uiidata() 289 | { 290 | uii_data_len = 0; 291 | uii_data_index = 0; 292 | memset(uii_data, 0, DATA_QUEUE_SZ * 2); 293 | memset(uii_status, 0, STATUS_QUEUE_SZ); 294 | } 295 | 296 | void uii_tcp_emptybuffer() 297 | { 298 | uii_data_index = 0; 299 | } 300 | -------------------------------------------------------------------------------- /src/ultimate_dos_lib.c: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | Ultimate 64/II+ Command Library - DOS functions 3 | Scott Hutter, Francesco Sblendorio 4 | 5 | Based on ultimate_dos-1.2.docx and command interface.docx 6 | https://github.com/markusC64/1541ultimate2/tree/master/doc 7 | 8 | Disclaimer: Because of the nature of DOS commands, use this code 9 | soley at your own risk. 10 | 11 | Patches and pull requests are welcome 12 | ******************************************************************/ 13 | #include 14 | #include "include/ultimate_common_lib.h" 15 | #include "include/ultimate_dos_lib.h" 16 | 17 | void uii_get_path(void) 18 | { 19 | unsigned char cmd[] = {0x00, DOS_CMD_GET_PATH}; 20 | uii_settarget(TARGET_DOS1); 21 | uii_sendcommand(cmd, 2); 22 | uii_readdata(); 23 | uii_readstatus(); 24 | uii_accept(); 25 | } 26 | 27 | void uii_open_dir(void) 28 | { 29 | unsigned char cmd[] = {0x00, DOS_CMD_OPEN_DIR}; 30 | uii_settarget(TARGET_DOS1); 31 | uii_sendcommand(cmd, 2); 32 | uii_readstatus(); 33 | uii_accept(); 34 | } 35 | 36 | void uii_get_dir(void) 37 | { 38 | unsigned char cmd[] = {0x00, DOS_CMD_READ_DIR}; 39 | int count = 0; 40 | uii_settarget(TARGET_DOS1); 41 | uii_sendcommand(cmd, 2); 42 | } 43 | 44 | void uii_change_dir(char *directory) 45 | { 46 | int x = 0; 47 | uii_command[0] = 0x00; 48 | uii_command[1] = DOS_CMD_CHANGE_DIR; 49 | 50 | for (x = 0; x < strlen(directory); x++) 51 | uii_command[x + 2] = directory[x]; 52 | 53 | uii_settarget(TARGET_DOS1); 54 | uii_sendcommand((unsigned char *)uii_command, strlen(directory) + 2); 55 | 56 | uii_readstatus(); 57 | uii_accept(); 58 | } 59 | 60 | void uii_change_dir_home(void) 61 | { 62 | unsigned char cmd[] = {0x00, DOS_CMD_COPY_HOME_PATH}; 63 | int count = 0; 64 | 65 | uii_settarget(TARGET_DOS1); 66 | uii_sendcommand(cmd, 2); 67 | uii_readstatus(); 68 | uii_accept(); 69 | } 70 | 71 | void uii_mount_disk(unsigned char id, char *filename) 72 | { 73 | int x = 0; 74 | uii_command[0] = 0x00; 75 | uii_command[1] = DOS_CMD_MOUNT_DISK; 76 | uii_command[2] = id; 77 | 78 | for (x = 0; x < strlen(filename); x++) 79 | uii_command[x + 3] = filename[x]; 80 | 81 | uii_settarget(TARGET_DOS1); 82 | uii_sendcommand((unsigned char *)uii_command, strlen(filename) + 3); 83 | 84 | uii_readdata(); 85 | uii_readstatus(); 86 | uii_accept(); 87 | } 88 | 89 | void uii_unmount_disk(unsigned char id) 90 | { 91 | unsigned char cmd[] = {0x00, DOS_CMD_UMOUNT_DISK, 0x00}; 92 | 93 | cmd[2] = id; 94 | 95 | uii_settarget(TARGET_DOS1); 96 | uii_sendcommand(cmd, 3); 97 | 98 | uii_readdata(); 99 | uii_readstatus(); 100 | uii_accept(); 101 | } 102 | 103 | void uii_open_file(unsigned char attrib, char *filename) 104 | { 105 | // Attrib will be: 106 | // 0x01 = Read 107 | // 0x02 = Write 108 | // 0x06 = Create new file 109 | // 0x0E = Create (overwriting an existing file) 110 | 111 | int x = 0; 112 | uii_command[0] = 0x00; 113 | uii_command[1] = DOS_CMD_OPEN_FILE; 114 | uii_command[2] = attrib; 115 | 116 | for (x = 0; x < strlen(filename); x++) 117 | uii_command[x + 3] = filename[x]; 118 | 119 | uii_settarget(TARGET_DOS1); 120 | uii_sendcommand((unsigned char *)uii_command, strlen(filename) + 3); 121 | 122 | uii_readdata(); 123 | uii_readstatus(); 124 | uii_accept(); 125 | } 126 | 127 | void uii_close_file(void) 128 | { 129 | unsigned char cmd[] = {0x00, DOS_CMD_CLOSE_FILE}; 130 | 131 | uii_settarget(TARGET_DOS1); 132 | uii_sendcommand(cmd, 2); 133 | 134 | uii_readdata(); 135 | uii_readstatus(); 136 | uii_accept(); 137 | } 138 | 139 | void uii_write_file(unsigned char *data, int length) 140 | { 141 | int x = 0; 142 | uii_command[0] = 0x00; 143 | uii_command[1] = DOS_CMD_WRITE_DATA; 144 | uii_command[2] = 0x00; 145 | uii_command[3] = 0x00; 146 | 147 | for (x = 0; x < length; x++) 148 | uii_command[x + 4] = data[x]; 149 | 150 | uii_settarget(TARGET_DOS1); 151 | uii_sendcommand((unsigned char *)uii_command, length + 4); 152 | 153 | uii_readdata(); 154 | uii_readstatus(); 155 | uii_accept(); 156 | } 157 | 158 | void uii_read_file(unsigned char length) 159 | { 160 | unsigned char cmd[] = {0x00, DOS_CMD_READ_DATA, 0x00, 0x00}; 161 | 162 | cmd[2] = length & 0xFF; 163 | cmd[3] = length >> 8; 164 | 165 | uii_settarget(TARGET_DOS1); 166 | uii_sendcommand(cmd, 2); 167 | 168 | // As with _get_dir(), read this in a loop, and _accept() the data 169 | // in order to get the next packet 170 | // 171 | // each data packet is 512 bytes each 172 | } 173 | 174 | void uii_delete_file(char *filename) 175 | { 176 | int x = 0; 177 | uii_command[0] = 0x00; 178 | uii_command[1] = DOS_CMD_DELETE_FILE; 179 | 180 | for (x = 0; x < strlen(filename); x++) 181 | uii_command[x + 2] = filename[x]; 182 | 183 | uii_settarget(TARGET_DOS1); 184 | uii_sendcommand((unsigned char *)uii_command, strlen(filename) + 2); 185 | 186 | uii_readstatus(); 187 | uii_accept(); 188 | } 189 | 190 | void uii_load_reu(unsigned char size) 191 | { 192 | // REU sizes on UII+: 193 | // 0 = 128 KB 194 | // 1 = 256 KB 195 | // 2 = 512 KB 196 | // 3 = 1 MB 197 | // 4 = 2 MB 198 | // 5 = 4 MB 199 | // 6 = 8 MB 200 | // 7 = 16 MB 201 | 202 | unsigned char cmd[] = {0x00, DOS_CMD_LOAD_REU, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00}; 203 | unsigned char sizes[8] = {0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff}; 204 | 205 | cmd[8] = sizes[size]; 206 | 207 | uii_settarget(TARGET_DOS1); 208 | uii_sendcommand(cmd, 10); 209 | uii_readdata(); 210 | uii_readstatus(); 211 | uii_accept(); 212 | } 213 | 214 | void uii_save_reu(unsigned char size) 215 | { 216 | // Function to save REU memory to REU file 217 | // Size is memory length to save in 64k blocks - 1 218 | 219 | unsigned char cmd[] = {0x00, DOS_CMD_SAVE_REU, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00}; 220 | 221 | cmd[8] = size; 222 | uii_settarget(TARGET_DOS1); 223 | uii_sendcommand(cmd, 10); 224 | uii_readdata(); 225 | uii_readstatus(); 226 | uii_accept(); 227 | } 228 | 229 | void uii_enable_drive_a(void) 230 | { 231 | unsigned char cmd[] = {0x00, CTRL_CMD_ENABLE_DISK_A}; 232 | 233 | uii_settarget(TARGET_CONTROL); 234 | uii_sendcommand(cmd, 2); 235 | 236 | uii_readdata(); 237 | uii_readstatus(); 238 | uii_accept(); 239 | } 240 | 241 | void uii_disable_drive_a(void) 242 | { 243 | #define CTRL_CMD_DISABLE_DISK_A 0x31 244 | unsigned char cmd[] = {0x00, CTRL_CMD_DISABLE_DISK_A}; 245 | 246 | uii_settarget(TARGET_CONTROL); 247 | uii_sendcommand(cmd, 2); 248 | 249 | uii_readdata(); 250 | uii_readstatus(); 251 | uii_accept(); 252 | } 253 | 254 | void uii_enable_drive_b(void) 255 | { 256 | unsigned char cmd[] = {0x00, CTRL_CMD_ENABLE_DISK_B}; 257 | 258 | uii_settarget(TARGET_CONTROL); 259 | uii_sendcommand(cmd, 2); 260 | 261 | uii_readdata(); 262 | uii_readstatus(); 263 | uii_accept(); 264 | } 265 | 266 | void uii_disable_drive_b(void) 267 | { 268 | unsigned char cmd[] = {0x00, CTRL_CMD_DISABLE_DISK_B}; 269 | 270 | uii_settarget(TARGET_CONTROL); 271 | uii_sendcommand(cmd, 2); 272 | 273 | uii_readdata(); 274 | uii_readstatus(); 275 | uii_accept(); 276 | } 277 | 278 | void uii_get_drive_a_power(void) 279 | { 280 | unsigned char cmd[] = {0x00, CTRL_CMD_DRIVE_A_POWER}; 281 | 282 | uii_settarget(TARGET_CONTROL); 283 | uii_sendcommand(cmd, 2); 284 | 285 | uii_readdata(); 286 | uii_readstatus(); 287 | uii_accept(); 288 | } 289 | 290 | void uii_get_drive_b_power(void) 291 | { 292 | unsigned char cmd[] = {0x00, CTRL_CMD_DRIVE_B_POWER}; 293 | 294 | uii_settarget(TARGET_CONTROL); 295 | uii_sendcommand(cmd, 2); 296 | 297 | uii_readdata(); 298 | uii_readstatus(); 299 | uii_accept(); 300 | } 301 | 302 | void uii_get_deviceinfo(void) 303 | { 304 | unsigned char cmd[] = {0x00, CTRL_CMD_DEVICE_INFO}; 305 | 306 | uii_settarget(TARGET_CONTROL); 307 | uii_sendcommand(cmd, 2); 308 | 309 | uii_readdata(); 310 | uii_readstatus(); 311 | uii_accept(); 312 | } 313 | 314 | unsigned char uii_parse_deviceinfo(void) 315 | { 316 | unsigned char devicecount, count, temp; 317 | 318 | // Execute UCI 29 : CTRL_CMD_GET_DRVINFO 319 | uii_get_deviceinfo(); 320 | 321 | // Return with success code = 0 if no success 322 | if (!uii_success()) 323 | { 324 | return 0; 325 | } 326 | 327 | // Get number of devices to parse 328 | devicecount = uii_data[0]; 329 | if (!devicecount) 330 | { 331 | return 0; 332 | } 333 | 334 | // Parse first type 335 | count = 1; 336 | temp = uii_data[count++]; 337 | 338 | // Parse drive A 339 | if (temp < 0x0f) 340 | { 341 | // Drive A found 342 | uii_devinfo[0].exist = 1; 343 | uii_devinfo[0].type = temp; 344 | uii_devinfo[0].id = uii_data[count++]; 345 | uii_devinfo[0].power = uii_data[count++]; 346 | temp = uii_data[count++]; 347 | } 348 | 349 | // Parse drive B 350 | if (temp < 0x0f) 351 | { 352 | // Drive A found 353 | uii_devinfo[1].exist = 1; 354 | uii_devinfo[1].type = temp; 355 | uii_devinfo[1].id = uii_data[count++]; 356 | uii_devinfo[1].power = uii_data[count++]; 357 | temp = uii_data[count++]; 358 | } 359 | 360 | // Parse SoftIEC 361 | if (temp == 0x0f) 362 | { 363 | // SoftIEC 364 | uii_devinfo[2].exist = 1; 365 | uii_devinfo[2].type = temp; 366 | uii_devinfo[2].id = uii_data[count++]; 367 | uii_devinfo[2].power = uii_data[count++]; 368 | temp = uii_data[count++]; 369 | } 370 | 371 | // Parse soft printer 372 | if (temp == 0x50) 373 | { 374 | // SoftPrinter 375 | uii_devinfo[3].exist = 1; 376 | uii_devinfo[3].type = temp; 377 | uii_devinfo[3].id = uii_data[count++]; 378 | uii_devinfo[3].power = uii_data[count]; 379 | } 380 | 381 | return 1; 382 | } 383 | 384 | char *uii_device_tyoe(unsigned char typeval) 385 | { 386 | switch (typeval) 387 | { 388 | case 0: 389 | return "1541"; 390 | break; 391 | 392 | case 1: 393 | return "1571"; 394 | break; 395 | 396 | case 2: 397 | return "1581"; 398 | break; 399 | 400 | case 0x0f: 401 | return "SIEC"; 402 | break; 403 | 404 | default: 405 | return ""; 406 | break; 407 | } 408 | } -------------------------------------------------------------------------------- /src/core.c: -------------------------------------------------------------------------------- 1 | /* 2 | CPMUMount 3 | Disk mounter for the Ultimate II+ in CPMS 4 | Written in 2023 by Xander Mol 5 | 6 | https://github.com/xahmol/CPMUTools 7 | 8 | https://www.idreamtin8bits.com/ 9 | 10 | Code and resources from others used: 11 | 12 | - Scott Hutter - Ultimate II+ library: 13 | https://github.com/xlar54/ultimateii-dos-lib/ 14 | (library for the UII+ UCI functions) 15 | 16 | - z88dk C cross compiler for Z80 targets, including C128 CP/M 17 | https://github.com/z88dk/z88dk/wiki 18 | 19 | - Jochen Metzinger - ctools 20 | https://github.com/mist64/ctools 21 | 22 | - ntp2ultimate by MaxPlap 23 | https://github.com/MaxPlap/ntp2ultimate 24 | Time via NTP code 25 | 26 | - EPOCH-to-time-date-converter by sidsingh78 27 | https://github.com/sidsingh78/EPOCH-to-time-date-converter/blob/master/epoch_conv.c 28 | 29 | - Bart van Leeuwen for providing CP/M images, testing and advice 30 | 31 | - Gideon Zweijtzer for creating the Ultimate II+ cartridge and the Ultimate64, and the Ultimate Command Interface enabling this software. 32 | 33 | - Tested using real hardware (C128D, C128DCR) using CP/M 3.0 and ZP/M+. 34 | 35 | Licensed under the GNU General Public License v3.0 36 | 37 | The code can be used freely as long as you retain 38 | a notice describing original source and author. 39 | 40 | THE PROGRAMS ARE DISTRIBUTED IN THE HOPE THAT THEY WILL BE USEFUL, 41 | BUT WITHOUT ANY WARRANTY. USE THEM AT YOUR OWN RISK! 42 | */ 43 | 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include "include/defines.h" 54 | #include "include/core.h" 55 | #include "include/ultimate_common_lib.h" 56 | #include "include/ultimate_dos_lib.h" 57 | #include "include/ultimate_time_lib.h" 58 | 59 | // Global variables 60 | char buffer[81]; // Buffer memory for tempory storage 61 | char version[25]; // Version info string 62 | ushort vdcDispMem; // Variable for VDC display memory start, to be set with vdcmap() 63 | char filename[13] = "cpmutool.cfg"; // Filename for configuration file 64 | 65 | // Default config settings 66 | // NTP server host name: pool.ntp.org is default 67 | // Seconds from UTC: 3600 is Central European Time (Central European Summer Time would be 7200) 68 | // UTime verbosoty: UTime gives textual feedback (1) or remains silent (0, default) 69 | // NTP on: set time via NTP server on (1, default) or synch with UII+ RTC only (0) 70 | // Auto pverride: Detect valid drives for mounting images automatically (1) or manually (0) 71 | // Valid: manual setting of drive validity, 1=valid, 0=no target. 72 | // Target: target drive on starting UMount, 0 is default and sets on first valid drive as target 73 | struct ConfigStruct config = {"pool.ntp.org", 3600, 1, 1, 0, {0, 0, 0, 0}, 0}; 74 | 75 | // Common routines for CPMUMount and CPMUConfig 76 | 77 | // Generic routiens 78 | void init() 79 | { 80 | savevdc(); // Saveguard VDC registers 81 | mapvdc(); // Get VDC environment 82 | outvdc(vdcFgBgColor, vdcBlack); // Set background to black 83 | setcursorvdc(0, 0, vdcCurNone); // No curor 84 | clrattrvdc(colorText); // Clear attributes with standard text color 85 | clrscrvdc(0x20); // Clear screen with spaces 86 | } 87 | 88 | void done(unsigned char exitcode) 89 | { 90 | clrattrvdc(colorText); // Clear attributes with standard text color 91 | clrscrvdc(0x20); // Clear screen with spaces 92 | restorevdc(); // Restore VDC registers 93 | setcursorvdc(7, 7, vdcCurRate32); // Restore cursor 94 | exit(exitcode); // Exit to CP/M 95 | } 96 | 97 | void delay(ushort D) 98 | { 99 | /* delay in tens of seconds (1/10sec) */ 100 | setintctrlcia(cia2, ciaClearIcr); /* disable all cia 2 interrupts */ 101 | settimerbcia(cia2, D, ciaCountA); /* timer b counts timer a underflows */ 102 | settimeracia(cia2, timervalcia(10), ciaCPUCont); /* set timer a 1/1000 sec */ 103 | while ((inp(cia2 + ciaIntCtrl) & 0x02) == 0) 104 | ; /* wait for count down */ 105 | } 106 | 107 | /** 108 | * input/modify a string. 109 | * based on version 1.0e, then modified. 110 | * @param[in] xpos screen x where input starts. 111 | * @param[in] ypos screen y where input starts. 112 | * @param[in,out] str string that is edited, it can have content and must have at least @p size + 1 bytes. Maximum size if 255 bytes. 113 | * @param[in] size maximum length of @p str in bytes. 114 | * @return -1 if input was aborted. 115 | * @return >= 0 length of edited string @p str. 116 | */ 117 | int textInput(ushort xpos, ushort ypos, char *str, ushort size) 118 | { 119 | ushort idx = strlen(str); 120 | ushort b, c, flag; 121 | 122 | printstrvdc(xpos, ypos, colorDirEntry, str); 123 | printstrvdc(xpos + idx, ypos, colorSelect, " "); 124 | 125 | while (1) 126 | { 127 | c = cgetc(); 128 | switch (c) 129 | { 130 | case K_ESCAPE: 131 | return -1; 132 | 133 | case K_RETURN: 134 | idx = strlen(str); 135 | str[idx] = 0; 136 | return idx; 137 | 138 | case K_DEL: 139 | if (idx) 140 | { 141 | fillattrvdc(xpos, ypos, idx + 1, colorDirEntry); 142 | --idx; 143 | filldspvdc(xpos + idx, ypos, 2, ' '); 144 | for (c = idx; 1; ++c) 145 | { 146 | b = str[c + 1]; 147 | str[c] = b; 148 | if (b == 0) 149 | break; 150 | } 151 | printstrvdc(xpos, ypos, colorDirEntry, str); 152 | printstrvdc(xpos + idx, ypos, colorSelect, " "); 153 | } 154 | break; 155 | 156 | // case CH_INS: 157 | // c = strlen(str); 158 | // if (c < size && 159 | // c > 0 && 160 | // idx < c) 161 | // { 162 | // ++c; 163 | // while(c >= idx) 164 | // { 165 | // str[c+1] = str[c]; 166 | // if (c == 0) 167 | // break; 168 | // --c; 169 | // } 170 | // str[idx] = ' '; 171 | // cputsxy(xpos, ypos, str); 172 | // gotoxy(xpos + idx, ypos); 173 | // } 174 | // break; 175 | 176 | case CURS_LEFT: 177 | case CURU_LEFT: 178 | if (idx) 179 | { 180 | fillattrvdc(xpos + idx, ypos, 1, colorDirEntry); 181 | --idx; 182 | fillattrvdc(xpos + idx, ypos, 1, colorSelect); 183 | } 184 | break; 185 | 186 | case CURS_RIGHT: 187 | case CURU_RIGHT: 188 | if (idx < strlen(str) && 189 | idx < size) 190 | { 191 | fillattrvdc(xpos + idx, ypos, 1, colorDirEntry); 192 | ++idx; 193 | fillattrvdc(xpos + idx, ypos, 1, colorSelect); 194 | } 195 | break; 196 | 197 | default: 198 | if (isprint(c) && 199 | idx < size) 200 | { 201 | flag = (str[idx] == 0); 202 | str[idx] = c; 203 | printstrvdc(xpos, ypos, colorDirEntry, str); 204 | ++idx; 205 | fillattrvdc(xpos + idx, ypos, 1, colorSelect); 206 | if (flag) 207 | str[idx + 1] = 0; 208 | break; 209 | } 210 | break; 211 | } 212 | } 213 | return 0; 214 | } 215 | 216 | // Screen routines 217 | 218 | void ClearArea(ushort x, ushort y, ushort width, ushort height) 219 | { 220 | ushort line; 221 | 222 | for (line = 0; line < height; line++) 223 | { 224 | filldspvdc(x, y + line, width, ' '); 225 | fillattrvdc(x, y + line, width, colorText); 226 | } 227 | } 228 | 229 | void headertext(char *subtitle) 230 | { 231 | // Draw header text 232 | // Input: subtitle is text to draw on second line 233 | 234 | sprintf(buffer, "%-80s", "CPM UTools: Tootset for using the Ultimate II+ with CP/M"); 235 | printstrvdc(0, 0, colorHeader1, buffer); 236 | 237 | sprintf(buffer, "%-80s", subtitle); 238 | printstrvdc(0, 1, colorHeader2, buffer); 239 | 240 | uii_get_time(); 241 | if (uii_success()) 242 | { 243 | printstrvdc(80 - strlen(uii_data), 1, colorHeader2, uii_data); 244 | } 245 | } 246 | 247 | // Config file routimes 248 | 249 | void ErrorMessage(char *stage, unsigned char vdcmode) 250 | { 251 | // Config file handling error handling message 252 | 253 | sprintf(buffer, "Error in %s of config file. Press key.", stage); 254 | 255 | if (vdcmode) 256 | { 257 | // Error message in VDC mode 258 | printstrvdc(0, 24, colorError, "Error! "); 259 | printstrvdc(7, 24, colorText, buffer); 260 | cgetc(); 261 | done(1); 262 | } 263 | else 264 | { 265 | printf("%s", buffer); 266 | exit(1); 267 | } 268 | } 269 | 270 | void WriteConfigfile(unsigned char vdcmode) 271 | { 272 | // Write config file 273 | 274 | FILE *file; 275 | 276 | if (vdcmode) 277 | { 278 | printstrvdc(0, 24, colorText, "Writing configuration file. Please wait."); 279 | } 280 | else 281 | { 282 | if (config.verbose) 283 | { 284 | printf("\nWriting configuration file."); 285 | } 286 | } 287 | 288 | // Open file for write 289 | file = fopen(filename, "w"); 290 | if (!file) 291 | { 292 | ErrorMessage("opeming for write", 1); 293 | } 294 | 295 | // Write to file 296 | if (!fwrite(&config, sizeof(config), 1, file)) 297 | { 298 | fclose(file); 299 | ErrorMessage("writing", 1); 300 | } 301 | 302 | // Close file 303 | fclose(file); 304 | } 305 | 306 | void ReadConfigfile(unsigned char vdcmode) 307 | { 308 | // Read config file 309 | 310 | FILE *file; 311 | 312 | if (vdcmode) 313 | { 314 | printstrvdc(0, 24, colorText, "Reading configuration file. Please wait."); 315 | } 316 | 317 | // Open file for read 318 | file = fopen(filename, "r"); 319 | 320 | // Check if file exists, write one instead 321 | if (!file) 322 | { 323 | ClearArea(0, 24, 80, 1); 324 | WriteConfigfile(vdcmode); 325 | return; 326 | } 327 | 328 | // Reading file 329 | if (!fread(&config, sizeof(config), 1, file)) 330 | { 331 | fclose(file); 332 | ErrorMessage("reading", 1); 333 | } 334 | 335 | // Close file 336 | if (vdcmode) 337 | { 338 | ClearArea(0, 24, 80, 1); 339 | } 340 | fclose(file); 341 | } 342 | -------------------------------------------------------------------------------- /src/config.c: -------------------------------------------------------------------------------- 1 | /* 2 | CPMUMount 3 | Disk mounter for the Ultimate II+ in CP/M 4 | Written in 2023 by Xander Mol 5 | 6 | https://github.com/xahmol/CPMUTools 7 | 8 | https://www.idreamtin8bits.com/ 9 | 10 | Code and resources from others used: 11 | 12 | - Scott Hutter - Ultimate II+ library: 13 | https://github.com/xlar54/ultimateii-dos-lib/ 14 | (library for the UII+ UCI functions) 15 | 16 | - z88dk C cross compiler for Z80 targets, including C128 CP/M 17 | https://github.com/z88dk/z88dk/wiki 18 | 19 | - Jochen Metzinger - ctools 20 | https://github.com/mist64/ctools 21 | 22 | - ntp2ultimate by MaxPlap 23 | https://github.com/MaxPlap/ntp2ultimate 24 | Time via NTP code 25 | 26 | - EPOCH-to-time-date-converter by sidsingh78 27 | https://github.com/sidsingh78/EPOCH-to-time-date-converter/blob/master/epoch_conv.c 28 | 29 | - Bart van Leeuwen for providing CP/M images, testing and advice 30 | 31 | - Gideon Zweijtzer for creating the Ultimate II+ cartridge and the Ultimate64, and the Ultimate Command Interface enabling this software. 32 | 33 | - Tested using real hardware (C128D, C128DCR) using CP/M 3.0 and ZP/M+. 34 | 35 | Licensed under the GNU General Public License v3.0 36 | 37 | The code can be used freely as long as you retain 38 | a notice describing original source and author. 39 | 40 | THE PROGRAMS ARE DISTRIBUTED IN THE HOPE THAT THEY WILL BE USEFUL, 41 | BUT WITHOUT ANY WARRANTY. USE THEM AT YOUR OWN RISK! 42 | */ 43 | 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include "include/defines.h" 54 | #include "include/core.h" 55 | #include "include/mount_common.h" 56 | #include "include/ultimate_common_lib.h" 57 | #include "include/ultimate_dos_lib.h" 58 | #include "include/ultimate_time_lib.h" 59 | 60 | unsigned char selectionlines[] = {7, 9, 10, 11, 12, 13, 14, 18, 19, 20, 21}; 61 | 62 | void PrintTargetDrive(unsigned char target, unsigned char ypos) 63 | { 64 | // Print target drive setting 65 | 66 | ClearArea(20, ypos, 20, 1); 67 | if (target) 68 | { 69 | sprintf(buffer, "%c", target - 1 + 'A'); 70 | } 71 | else 72 | { 73 | sprintf(buffer, "Not set"); 74 | } 75 | printstrvdc(20, ypos, colorText, buffer); 76 | } 77 | 78 | void PrintConfigData() 79 | { 80 | // Print present config data 81 | 82 | unsigned char ypos = 3; 83 | unsigned char drive; 84 | 85 | sprintf(buffer, "Version: %s", version); 86 | printstrvdc(0, ypos++, colorText, buffer); 87 | printstrvdc(0, ypos++, colorText, "Present configuration."); 88 | 89 | ypos++; 90 | printstrvdc(0, ypos++, colorSuccess, "UMount settings:"); 91 | sprintf(buffer, "Detection override: %s", config.auto_override ? "Yes" : "No"); 92 | printstrvdc(0, ypos++, colorText, buffer); 93 | 94 | if (firmwareflag == 2) 95 | { 96 | sprintf(buffer, "Autodetection not supported in firmware."); 97 | } 98 | else 99 | { 100 | sprintf(buffer, "Autodetection of valid drives succeeded."); 101 | } 102 | printstrvdc(0, ypos++, colorText, buffer); 103 | 104 | for (drive = 0; drive < MAXDRIVES; drive++) 105 | { 106 | sprintf(buffer, " %c ", 'A' + drive); 107 | if (!validdrive[drive]) 108 | { 109 | sprintf(buffer + 18, ": No target"); 110 | } 111 | else 112 | { 113 | if (!config.auto_override) 114 | { 115 | sprintf(buffer + 18, ": %02d, %s %s", drive + 8, uii_device_tyoe(uii_devinfo[validdrive[drive] - 1].type), (uii_device_tyoe(uii_devinfo[validdrive[drive] - 1].power)) ? "On " : "Off"); 116 | } 117 | else 118 | { 119 | sprintf(buffer + 18, ": %02d, manual", drive + 8); 120 | } 121 | } 122 | printstrvdc(0, ypos++, colorText, buffer); 123 | } 124 | 125 | printstrvdc(0, ypos, colorText, "Target drive :"); 126 | PrintTargetDrive(targetdrive, ypos++); 127 | 128 | ypos++; 129 | printstrvdc(0, ypos++, colorSuccess, "UTime settings:"); 130 | printstrvdc(0, ypos++, colorText, "NTP host:"); 131 | printstrvdc(0, ypos++, colorText, config.ntphost); 132 | sprintf(buffer, "UTC offset : %ld", config.secondsfromutc); 133 | printstrvdc(0, ypos++, colorText, buffer); 134 | sprintf(buffer, "Update from NTP : %sabled", config.ntpon ? "En" : "Dis"); 135 | printstrvdc(0, ypos++, colorText, buffer); 136 | sprintf(buffer, "Verbose : %sabled", config.verbose ? "En" : "Dis"); 137 | printstrvdc(0, ypos++, colorText, buffer); 138 | } 139 | 140 | unsigned char SelectConfigOption(unsigned char select) 141 | { 142 | // Selection of which config option to edit. 0 = exit 143 | 144 | unsigned char key, xpos, ypos, length; 145 | 146 | do 147 | { 148 | xpos = (select == 8) ? 0 : 20; 149 | ypos = selectionlines[select - 1]; 150 | length = (select == 8) ? 80 : 12; 151 | fillattrvdc(xpos, ypos, length, colorSelect); 152 | key = cgetc(); 153 | fillattrvdc(xpos, ypos, length, colorText); 154 | if (key == CURS_DOWN || key == CURU_DOWN) 155 | { 156 | if (select == 11) 157 | { 158 | select = 1; 159 | } 160 | else 161 | { 162 | select++; 163 | } 164 | if (select > 1 && select < 7 && !config.auto_override) 165 | { 166 | select = 7; 167 | } 168 | } 169 | if (key == CURS_UP || key == CURU_UP) 170 | { 171 | if (select == 1) 172 | { 173 | select = 11; 174 | } 175 | else 176 | { 177 | select--; 178 | } 179 | if (select > 1 && select < 7 && !config.auto_override) 180 | { 181 | select = 1; 182 | } 183 | } 184 | } while (key != K_RETURN && key != K_ESCAPE); 185 | 186 | if (key == K_RETURN) 187 | { 188 | return select; 189 | } 190 | else 191 | { 192 | return 0; 193 | } 194 | } 195 | 196 | void main() 197 | { 198 | unsigned char select = 1; 199 | unsigned char changed = 0; 200 | unsigned char key, newval; 201 | char offsetinput[10] = ""; 202 | char *ptrend; 203 | 204 | // Set version number in string variable 205 | sprintf(version, 206 | "v%2d.%2d - %c%c%c%c%c%c%c%c-%c%c%c%c", 207 | VERSION_MAJOR, VERSION_MINOR, 208 | BUILD_YEAR_CH0, BUILD_YEAR_CH1, BUILD_YEAR_CH2, BUILD_YEAR_CH3, 209 | BUILD_MONTH_CH0, BUILD_MONTH_CH1, BUILD_DAY_CH0, BUILD_DAY_CH1, 210 | BUILD_HOUR_CH0, BUILD_HOUR_CH1, BUILD_MIN_CH0, BUILD_MIN_CH1); 211 | 212 | // Initialize screen 213 | init(); 214 | headertext("UConfig: Configuration tool"); 215 | 216 | // Read config file 217 | ReadConfigfile(1); 218 | 219 | // Get valid UII+ drives 220 | SetValidDrives(); 221 | 222 | // Print present data 223 | PrintConfigData(); 224 | 225 | do 226 | { 227 | // Select option to edit 228 | ClearArea(0, 24, 80, 1); 229 | printstrvdc(0, 24, colorText, "Select option to edit using Cursor Up and Down. RETURN to select, ESC to quit."); 230 | select = SelectConfigOption(select); 231 | ClearArea(0, 24, 80, 1); 232 | 233 | switch (select) 234 | { 235 | // Toggle manual override 236 | case 1: 237 | config.auto_override = !config.auto_override; 238 | changed = 1; 239 | SetValidDrives(); 240 | ClearArea(0, 3, 80, 21); 241 | PrintConfigData(); 242 | break; 243 | 244 | // Set drive validity manual 245 | case 2: 246 | case 3: 247 | case 4: 248 | case 5: 249 | case 6: 250 | if (config.auto_override) 251 | { 252 | config.valid[select - 2] = !config.valid[select - 2]; 253 | changed = 1; 254 | if (config.valid[select - 2]) 255 | { 256 | sprintf(buffer, "%02d, manual", select + 6); 257 | } 258 | else 259 | { 260 | sprintf(buffer, "No target "); 261 | } 262 | printstrvdc(20, selectionlines[select - 1], colorSelect, buffer); 263 | } 264 | break; 265 | 266 | // Set target drive 267 | case 7: 268 | printstrvdc(0, 24, colorText, "Select target drive using Cursor Up and Down. RETURN to select, ESC to quit."); 269 | newval = config.target; 270 | do 271 | { 272 | key = cgetc(); 273 | if (key == CURS_DOWN || key == CURU_DOWN) 274 | { 275 | if (newval == MAXDRIVES) 276 | { 277 | newval = 0; 278 | } 279 | else 280 | { 281 | newval++; 282 | } 283 | } 284 | if (key == CURS_UP || key == CURU_UP) 285 | { 286 | if (newval == 0) 287 | { 288 | newval = MAXDRIVES; 289 | } 290 | else 291 | { 292 | newval--; 293 | } 294 | } 295 | PrintTargetDrive(newval, selectionlines[select - 1]); 296 | } while (key != K_RETURN && key != K_ESCAPE); 297 | if (key = K_RETURN) 298 | { 299 | changed = 1; 300 | config.target = newval; 301 | } 302 | else 303 | { 304 | PrintTargetDrive(newval, selectionlines[select - 1]); 305 | } 306 | break; 307 | 308 | // Enter NTP server host name 309 | case 8: 310 | printstrvdc(0, 24, colorText, "Enter hostname of NTP server, ESC to quit."); 311 | if (textInput(0, selectionlines[select - 1], config.ntphost, 80) != -1) 312 | { 313 | changed = 1; 314 | } 315 | break; 316 | 317 | // Enter NTP offset to UTC 318 | case 9: 319 | printstrvdc(0, 24, colorText, "Enter NTP time offset in seconds to UTC, ESC to quit."); 320 | sprintf(offsetinput, "%ld", config.secondsfromutc); 321 | if (textInput(20, selectionlines[select - 1], offsetinput, 80) != -1) 322 | { 323 | config.secondsfromutc = strtol(offsetinput, &ptrend, 10); 324 | changed = 1; 325 | } 326 | break; 327 | 328 | // Toggle enable/disable update via NTP or enable/disable verbosity 329 | case 10: 330 | case 11: 331 | if (select == 10) 332 | { 333 | config.ntpon = !config.ntpon; 334 | newval = config.ntpon; 335 | } 336 | else 337 | { 338 | config.verbose = !config.verbose; 339 | newval = config.verbose; 340 | } 341 | changed = 1; 342 | sprintf(buffer, "%sabled ", newval ? "En" : "Dis"); 343 | printstrvdc(20, selectionlines[select - 1], colorText, buffer); 344 | break; 345 | 346 | default: 347 | break; 348 | } 349 | } while (select != 0); 350 | 351 | if (changed) 352 | { 353 | WriteConfigfile(1); 354 | } 355 | 356 | // Exit program 357 | done(0); 358 | } -------------------------------------------------------------------------------- /src/time.c: -------------------------------------------------------------------------------- 1 | /* 2 | CPMUMount 3 | Disk mounter for the Ultimate II+ in CPMS 4 | Written in 2023 by Xander Mol 5 | 6 | https://github.com/xahmol/CPMUTools 7 | 8 | https://www.idreamtin8bits.com/ 9 | 10 | Code and resources from others used: 11 | 12 | - Scott Hutter - Ultimate II+ library: 13 | https://github.com/xlar54/ultimateii-dos-lib/ 14 | (library for the UII+ UCI functions) 15 | 16 | - z88dk C cross compiler for Z80 targets, including C128 CP/M 17 | https://github.com/z88dk/z88dk/wiki 18 | 19 | - Jochen Metzinger - ctools 20 | https://github.com/mist64/ctools 21 | 22 | - ntp2ultimate by MaxPlap 23 | https://github.com/MaxPlap/ntp2ultimate 24 | Time via NTP code 25 | 26 | - EPOCH-to-time-date-converter by sidsingh78 27 | https://github.com/sidsingh78/EPOCH-to-time-date-converter/blob/master/epoch_conv.c 28 | 29 | - Jay Cotton - inettools-z80 30 | https://github.com/jayacotton/inettools-z80 31 | Inspiration for time set and NTP code for Z80 / CP/M 32 | 33 | - Bart van Leeuwen for providing CP/M images, testing and advice 34 | 35 | - Gideon Zweijtzer for creating the Ultimate II+ cartridge and the Ultimate64, and the Ultimate Command Interface enabling this software. 36 | 37 | - Tested using real hardware (C128D, C128DCR) using CP/M 3.0 and ZP/M+. 38 | 39 | Licensed under the GNU General Public License v3.0 40 | 41 | The code can be used freely as long as you retain 42 | a notice describing original source and author. 43 | 44 | THE PROGRAMS ARE DISTRIBUTED IN THE HOPE THAT THEY WILL BE USEFUL, 45 | BUT WITHOUT ANY WARRANTY. USE THEM AT YOUR OWN RISK! 46 | */ 47 | 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include "include/defines.h" 58 | #include "include/core.h" 59 | #include "include/mount_common.h" 60 | #include "include/ultimate_common_lib.h" 61 | #include "include/ultimate_dos_lib.h" 62 | #include "include/ultimate_time_lib.h" 63 | #include "include/ultimate_network_lib.h" 64 | 65 | #define NTP_TIMESTAMP_DELTA 2208988800l // 0x83AA7E80 66 | #define CPM_SETDATETIME 104 67 | 68 | struct NTPFormat 69 | { 70 | uint8_t li_vn_mode; // Byte 0: Eight bits. li, vn, and mode. 71 | // li. Two bits. Leap indicator. 72 | // vn. Three bits. Version number of the protocol. 73 | // mode. Three bits. Client will pick mode 3 for client. 74 | uint8_t stratum; // Byte 1: Eight bits. Stratum level of the local clock. 75 | uint8_t poll; // Byte 2: Eight bits. Maximum interval between successive messages. 76 | uint8_t precision; // Byte 3: Eight bits. Precision of the local clock. 77 | uint32_t rootDelay; // Bytr 4-7: 32 bits. Total round trip delay time. 78 | uint32_t rootDispersion; // Byte 8-11: 32 bits. Max error aloud from primary clock source. 79 | uint32_t refId; // Byte 12-15: 32 bits. Reference clock identifier. 80 | uint32_t refTm_s; // Byte 16-23: 64 bits. Reference time-stamp seconds. 81 | uint32_t refTm_f; 82 | uint32_t origTm_s; // Byte 24-31: 64 bits. Originate time-stamp seconds. 83 | uint32_t origTm_f; 84 | uint32_t rcTm_s; // Byte 32-39: 64 bits. Received time-stamp seconds. 85 | uint32_t rcTm_f; 86 | uint32_t txTm_s; // Byte 40-47: 64 bits and the most important field the client cares 87 | uint32_t txTm_f; 88 | }; // Total: 384 bits or 48 bytes. 89 | struct NTPFormat ntp_packet; 90 | 91 | // Get NTP time functions 92 | unsigned char CheckStatusTime() 93 | { 94 | // Function to check UII+ status 95 | 96 | if (uii_status[0] != '0' || uii_status[1] != '0') 97 | { 98 | printf("\nStatus: %s Data:%s", uii_status, uii_data); 99 | return 1; 100 | } 101 | return 0; 102 | } 103 | 104 | char *UNIX_epoch_to_UII_time(uint32_t epoch) 105 | { 106 | // Convert UNIX time epoch to UII readable time format 107 | 108 | static unsigned char month_days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 109 | 110 | unsigned char ntp_hour, ntp_minute, ntp_second, ntp_day, ntp_month; 111 | unsigned char leap_days = 0; 112 | unsigned char leap_year_ind = 0; 113 | unsigned int temp_days, i; 114 | unsigned int ntp_year, days_since_epoch, day_of_year; 115 | char settime[6]; 116 | 117 | // printf("\nEpoch input: %lu",epoch); 118 | 119 | // Adjust for timezone 120 | epoch += config.secondsfromutc; 121 | // printf("\nOffset: %ld New epoch: %lu",config.secondsfromutc,epoch); 122 | 123 | // Calculate time 124 | ntp_second = (unsigned char)(epoch - (epoch / 60) * 60); 125 | epoch /= 60; 126 | // printf("\nSeconds: %u Epoch in minutes: %lu",ntp_second,epoch); 127 | 128 | ntp_minute = (unsigned char)(epoch - (epoch / 60) * 60); 129 | epoch /= 60; 130 | // printf("\nMinutes: %u Epoch in hours: %lu",ntp_minute,epoch); 131 | 132 | ntp_hour = (unsigned char)(epoch - (epoch / 24) * 24); 133 | epoch /= 24; 134 | // printf("\nHours: %u Epoch in days: %lu",ntp_hour,epoch); 135 | 136 | // Calculate date 137 | 138 | // Number of days since epoch 139 | days_since_epoch = epoch; 140 | // ball parking year, may not be accurate! 141 | ntp_year = 1970 + (days_since_epoch / 365); 142 | // Calculating number of leap days since epoch/1970 143 | for (i = 1972; i < ntp_year; i += 4) 144 | { 145 | if (((i % 4 == 0) && (i % 100 != 0)) || (i % 400 == 0)) 146 | leap_days++; 147 | } 148 | // Calculating accurate current year by (days_since_epoch - extra leap days) 149 | ntp_year = 1970 + ((days_since_epoch - leap_days) / 365); 150 | day_of_year = ((days_since_epoch - leap_days) % 365) + 1; 151 | 152 | if (((ntp_year % 4 == 0) && (ntp_year % 100 != 0)) || (ntp_year % 400 == 0)) 153 | { 154 | month_days[1] = 29; // February = 29 days for leap years 155 | leap_year_ind = 1; // if current year is leap, set indicator to 1 156 | } 157 | else 158 | { 159 | month_days[1] = 28; 160 | } // February = 28 days for non-leap years 161 | 162 | // Calculating current Month 163 | temp_days = 0; 164 | for (ntp_month = 0; ntp_month <= 11; ntp_month++) 165 | { 166 | if (day_of_year <= temp_days) 167 | break; 168 | temp_days = temp_days + month_days[ntp_month]; 169 | } 170 | 171 | // Calculating current Date 172 | temp_days = temp_days - month_days[ntp_month - 1]; 173 | ntp_day = day_of_year - temp_days; 174 | 175 | // Build UII time 176 | settime[0] = ntp_year - 1900; 177 | settime[1] = ntp_month; 178 | settime[2] = ntp_day; 179 | settime[3] = ntp_hour; 180 | settime[4] = ntp_minute; 181 | settime[5] = ntp_second; 182 | 183 | return settime; 184 | } 185 | 186 | uint32_t Reverse32(uint32_t value) 187 | { 188 | // Reverse endianness 189 | 190 | return (((value & 0x000000FF) << 24) | 191 | ((value & 0x0000FF00) << 8) | 192 | ((value & 0x00FF0000) >> 8) | 193 | ((value & 0xFF000000) >> 24)); 194 | } 195 | 196 | uint32_t ConvertTS(uint32_t timestamp) 197 | { 198 | // Convert NTP timestamp to UNIX epoch 199 | 200 | return Reverse32(timestamp) - NTP_TIMESTAMP_DELTA; 201 | } 202 | 203 | void get_ntp_time() 204 | { 205 | // Function to get time from NTP server and set UII+ time with this 206 | 207 | unsigned char attempt = 1; 208 | unsigned char clock; 209 | unsigned char fullcmd[] = {0x00, NET_CMD_SOCKET_WRITE, 0x00, 210 | 0x1b, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 211 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 212 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 213 | unsigned char socket = 0; 214 | unsigned long t; 215 | 216 | if (config.verbose) 217 | { 218 | ("\nUpdating UII+ time from NTP Server."); 219 | } 220 | 221 | uii_get_time(); 222 | 223 | if (config.verbose) 224 | { 225 | printf("\nUltimate datetime: %s", uii_data); 226 | printf("\nConnecting to: %s", config.ntphost); 227 | } 228 | 229 | socket = uii_udpconnect(config.ntphost, 123); // https://github.com/markusC64/1541ultimate2/blob/master/software/io/network/network_target.cc 230 | if (CheckStatusTime()) 231 | { 232 | uii_socketclose(socket); 233 | return; 234 | } 235 | 236 | if (config.verbose) 237 | { 238 | printf("\nSending NTP request"); 239 | } 240 | 241 | fullcmd[2] = socket; 242 | uii_settarget(TARGET_NETWORK); 243 | uii_sendcommand(fullcmd, 51); // 3 + sizeof( ntp_packet )); 244 | uii_readstatus(); 245 | uii_accept(); 246 | if (CheckStatusTime()) 247 | { 248 | uii_socketclose(socket); 249 | return; 250 | } 251 | 252 | // Do maximum of 4 attempts at receiving data 253 | do 254 | { 255 | // Add delay of a second to avoid time to wait on response being too short 256 | delay(10); 257 | 258 | // Print attempt number 259 | if (config.verbose) 260 | { 261 | printf("\nReading result attempt %d", attempt); 262 | } 263 | 264 | // Try to read incoming data 265 | uii_socketread(socket, 50); // 2 + sizeof( ntp_packet )); 266 | 267 | // If data received, end loop. Else do new attempt till counter = 5 268 | if (uii_success()) 269 | { 270 | attempt = 5; 271 | } 272 | else 273 | { 274 | attempt++; 275 | } 276 | 277 | } while (attempt < 5); 278 | 279 | if (CheckStatusTime()) 280 | { 281 | uii_socketclose(socket); 282 | return; 283 | } 284 | 285 | memcpy(&ntp_packet, &uii_data + 2, 48); 286 | 287 | // printf("\nLI VN MODE: %u",ntp_packet.li_vn_mode); 288 | // printf("\nStratum : %u",ntp_packet.stratum); 289 | // printf("\nPol : %u",ntp_packet.poll); 290 | // printf("\nPrecision : %u",ntp_packet.precision); 291 | // printf("\nRoot delay: %lu",ConvertTS(ntp_packet.rootDelay)); 292 | // printf("\nRoot disp : %lu",ConvertTS(ntp_packet.rootDispersion)); 293 | // printf("\nrefId : %lu",ConvertTS(ntp_packet.refId)); 294 | // printf("\nrefTm_s : %lu",ConvertTS(ntp_packet.refTm_s)); 295 | // printf("\nrefTm_f : %lu",ConvertTS(ntp_packet.refTm_f)); 296 | // printf("\norigTm_s : %lu",ConvertTS(ntp_packet.origTm_s)); 297 | // printf("\nOrigTm_f : %lu",ConvertTS(ntp_packet.origTm_f)); 298 | // printf("\nrcTm_s : %lu",ConvertTS(ntp_packet.rcTm_s)); 299 | // printf("\nrcTm_f : %lu",ConvertTS(ntp_packet.rcTm_f)); 300 | // printf("\ntxTm_s : %lu",ConvertTS(ntp_packet.txTm_s)); 301 | // printf("\ntxTm_f : %lu",ConvertTS(ntp_packet.txTm_f)); 302 | 303 | // Convert time received to UCI format 304 | // Bytes 32-35 of NTP packet, rcTm_s = received time in seconds, Big Endian order 305 | 306 | // t = uii_data[37] | (((unsigned long)uii_data[36])<<8)| (((unsigned long)uii_data[35])<<16)| (((unsigned long)uii_data[34])<<24); 307 | // t -= NTP_TIMESTAMP_DELTA; 308 | 309 | t = ConvertTS(ntp_packet.rcTm_s); 310 | 311 | // Close socket 312 | uii_socketclose(socket); 313 | 314 | // Print time received and parse to UII+ format 315 | if (config.verbose) 316 | { 317 | printf("\nUnix epoch %lu", t); 318 | } 319 | 320 | // Set UII+ RTC clock 321 | uii_set_time(UNIX_epoch_to_UII_time(t)); 322 | 323 | if (config.verbose) 324 | { 325 | printf("\nStatus: %s", uii_status); 326 | } 327 | 328 | uii_get_time(); 329 | 330 | if (config.verbose) 331 | { 332 | printf("\nRTC clock set to %s", uii_data); 333 | } 334 | } 335 | 336 | unsigned char int2bcd(unsigned char input) 337 | { 338 | // Conversion of an integer number to BCD 339 | // Adapted from source: https://github.com/jayacotton/inettools-z80/ 340 | 341 | unsigned char high = 0; 342 | 343 | while (input >= 10) 344 | { 345 | high++; 346 | input -= 10; 347 | } 348 | 349 | return ((high << 4) | input); 350 | } 351 | 352 | unsigned char isleap(unsigned int year) 353 | { 354 | // Calculate if year is leap year 355 | return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)); 356 | } 357 | 358 | void CPMSetDateTime(unsigned char seconds, unsigned char minutes, unsigned char hour, unsigned char day, unsigned char month, unsigned int year) 359 | { 360 | // Set date and time in CP/M OS 361 | // Adapted from source: https://github.com/jayacotton/inettools-z80/ 362 | 363 | /* year - real years binary 364 | month - real month binary 365 | day - real day binary @DATE jan 1 1978 366 | hour - hour (24 hr clock) binary @HOUR bcd 367 | minute - minute binary @MIN bcd 368 | second - second binary @SEC bcd 369 | */ 370 | 371 | unsigned char bcd_buffer[8]; 372 | unsigned char mtab[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // Days per month 373 | unsigned int y; 374 | unsigned int c_leaps; 375 | unsigned int c_noleaps; 376 | unsigned int days; 377 | 378 | c_leaps = 0; 379 | c_noleaps = 0; 380 | 381 | /* run through all the years from 1978 and count up leap years */ 382 | for (y = 1978; y <= year; y++) 383 | { 384 | if (isleap(y)) 385 | { 386 | c_leaps++; 387 | } 388 | } 389 | c_noleaps = (year - 1978) - c_leaps; 390 | 391 | /* compute days since jan 1 1978 */ 392 | 393 | /* days for the years */ 394 | days = (c_noleaps * 365) + (c_leaps * 366); 395 | 396 | /* days for this week */ 397 | days += day; 398 | 399 | /* days for all the months this year */ 400 | for (y = 1; y <= month - 1; y++) 401 | { 402 | days += mtab[y]; 403 | } 404 | 405 | /* deal with possible leap year this year */ 406 | if (isleap(year)) 407 | { 408 | days++; 409 | } 410 | 411 | if (config.verbose) 412 | { 413 | printf("\nCP/M: days since Jan 1, 1978: %u", days); 414 | } 415 | 416 | /* set up the set time buffer for CP/M 3 */ 417 | bcd_buffer[0] = days & 0xff; /* low high order ? */ 418 | bcd_buffer[1] = ((days >> 8) & 0xff); 419 | bcd_buffer[2] = int2bcd(hour); 420 | bcd_buffer[3] = int2bcd(minutes); 421 | bcd_buffer[4] = int2bcd(seconds); 422 | bdos(CPM_SETDATETIME, (int)&bcd_buffer); // BDOS function call 104: Set date and Time 423 | } 424 | 425 | void timeSynch() 426 | { 427 | // Synch system time with UII+ RTC 428 | char *ptrend; 429 | unsigned int year; 430 | unsigned char month, day, hour, minutes, seconds; 431 | 432 | // Get UII+ RTC time 433 | uii_get_time(); 434 | 435 | if (!CheckStatusTime()) 436 | { 437 | if (config.verbose) 438 | { 439 | printf("\nGet UII+ RTC. Time: %s", uii_data); 440 | } 441 | 442 | // Copy year 443 | strlcpy(buffer, uii_data, 5); 444 | buffer[4] = 0; 445 | year = strtol(buffer, &ptrend, 10); 446 | 447 | // Copy month 448 | buffer[0] = uii_data[5]; 449 | buffer[1] = uii_data[6]; 450 | buffer[2] = 0; 451 | month = strtol(buffer, &ptrend, 10); 452 | 453 | // Copy day 454 | buffer[0] = uii_data[8]; 455 | buffer[1] = uii_data[9]; 456 | day = strtol(buffer, &ptrend, 10); 457 | 458 | // Copy hour 459 | buffer[0] = uii_data[11]; 460 | buffer[1] = uii_data[12]; 461 | hour = strtol(buffer, &ptrend, 10); 462 | 463 | // Copy minutes 464 | buffer[0] = uii_data[14]; 465 | buffer[1] = uii_data[15]; 466 | minutes = strtol(buffer, &ptrend, 10); 467 | 468 | // Copy seconds 469 | buffer[0] = uii_data[17]; 470 | buffer[1] = uii_data[18]; 471 | seconds = strtol(buffer, &ptrend, 10); 472 | 473 | // Set CP/M system time 474 | CPMSetDateTime(seconds, minutes, hour, day, month, year); 475 | 476 | if (config.verbose) 477 | { 478 | printf("\nDate and time set."); 479 | } 480 | } 481 | } 482 | 483 | // Main program 484 | void main() 485 | { 486 | 487 | // Read config file 488 | ReadConfigfile(0); 489 | 490 | // If enabled, get NTP time 491 | if (config.ntpon) 492 | { 493 | get_ntp_time(); 494 | } 495 | 496 | // Synch CP/M with UII+ RTC 497 | timeSynch(); 498 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CPM UTools 2 | Toolset for using the Ultimate II+ cartridge for C128 CP/M 3 | 4 | ## Contents 5 | 6 | [Version history and download](#version-history-and-download) 7 | 8 | [Firmware and setting prerequisites and known issues](#firmware-and-setting-prerequisites-and-known-issues) 9 | 10 | [Introduction](#introduction) 11 | 12 | [What is on the disk](#what-is-on-the-disk) 13 | 14 | [CPM UConfig instructions](#cpm-uconfig-instructions) 15 | 16 | [CPM UTime instructions](#cpm-utime-instructions) 17 | 18 | [CPM UMount instructions](#cpm-umount-instructions) 19 | 20 | [Credits](#credits) 21 | 22 | ![CPM UMount main interface](https://github.com/xahmol/CPMUTools/blob/main/screenshots/umount%20-%20mainscreen.png?raw=true) 23 | 24 | ## Version history and download 25 | ([Back to contents](#contents)) 26 | 27 | [Link to latest build](https://github.com/xahmol/CPMUTools/raw/main/CPMUTools-v091-20231030-1632.zip) 28 | 29 | Version v091-20231030-1632: 30 | 31 | - Added CPM UTime: Utility to retrieve present date and time from an NTP server and synch this time to both the Ultimate II+ Real Time Clock as the CP/M system time 32 | - Added CPM UConfig: Utility to set the configuration options for UTime and UMount 33 | - UMount: Bugfixes and added Save REU option 34 | - Added documentation 35 | 36 | Version v091-20231021-1542: 37 | 38 | - First public alpha of CPM UMount: Utility to mount disk images stored on the Ultimate II+ filesystem in CP/M 39 | 40 | ## Firmware and setting prerequisites and known issues 41 | ([Back to contents](#contents)) 42 | 43 | ### Ultimate II/II+/II+L firmware requirements 44 | 45 | - Firmware 3.10f or newer: fully automatic drive detection and support to detect/mount/save CP/M RAM drives 46 | - Firmware 3.xx: automatic device detection possible. But in firmware older than 3.10f automatic device detection is based on hardware drive IDs of the emulated A and B drives of the Ultimate II/II+/II+L cartridge, instead of the software ID. This might give issues if device IDs have been changed by software. To fix this, choose manual override of the automated detected targets using UConfig. 47 | - Firmware before 3.xx: Automatic target detection is not possible, so setting valid drive targets via UConfig is always needed for CPM UMount to work. 48 | 49 | Link to Ultimate II/II+/II+L firmware: 50 | 51 | - Official released versions: https://ultimate64.com/Firmware 52 | - GitHub: https://github.com/GideonZ/ultimate_releases (might contain newer not yet officially released firmware, or firmware that were temporarily retracted) 53 | 54 | ### Ultimate II/II+/II+L setting requirements 55 | 56 | ![Ultimate Cartridge Settings](https://github.com/xahmol/GeoUTools/blob/main/screenshots/u2p-settings.png?raw=true) 57 | 58 | For CPM UTools it is important to check these settings in the C64 and Cartridge Settings menu after pressing F2 from the UI: 59 | - Command Interface: **IMPORTANT** This setting has to be set to 'enabled' for anything in CPM UTools to work 60 | - UltiDOS: Allow SetDate: This setting has to be set to 'enabled' to allow CPM UTime to change the Ultimate Real Time Clock time 61 | - RAM Expansion Unit: Should be set to 'enabled' to support saving REU memory to a file. 62 | - REU Size: set the desired size of the REU here, maximum is 16 megabytes. 63 | 64 | ## Introduction 65 | ([Back to contents](#contents)) 66 | 67 | **CPM UTools** is a little suite of (for now) three utilities to help using the Ultimate II+ cartridge from within CP/M. 68 | 69 | ### CPM UTime 70 | 71 | Utility to set the CP/M system time (and the UII+ RTC clock) the time received from a user defined NTP server. 72 | 73 | ### CPM UMount 74 | This utility can be used to swap and mount virtual disks on your UII+ cartridge, helpful because the UII+ menu is not available under CP/M 80 column mode. 75 | 76 | Images can be selected from a file browser, that filters on showing only directories and disk image files. 77 | 78 | ### CPM UConfig 79 | 80 | Utility to set the configuration for CPM UTime and CPM UMount. 81 | For CPM UTime, enabling or disabling time query of an NTP server, the NTP server hostname, offset from UTC time in seconds and verbosity on or off can be set. 82 | For CPM UMount, automatic valid target detection can be manually overridden, and the default target drive can be set. 83 | 84 | ## What is on the disk 85 | ([Back to contents](#contents)) 86 | 87 | In the ZIP file package of a CPM UTools build, two disk images are present, next to the PDF version of this readme file. The .d64 disk image is a C128 CP/M formatted single sided disk image, the .d71 a double sided one. 88 | As a real 1571 drive is way faster than a 1541 drive, also the emulated 1571 drive is faster than the 1541. So if your firmware allows it, using the .d71 is recommended for higher speed. The .d64 is provided for compatibility with older firmwares (or the non-+ version of the Ultimate cartridge). 89 | 90 | Contents of both images: 91 | 92 | ![CPM UTools disk](https://github.com/xahmol/CPMUTools/blob/main/screenshots/umount%20-%20diskcontents.png?raw=true) 93 | 94 | |Filename|Program|Description| 95 | |---|---|---| 96 | |UMOUNT.COM|**CPM UMount**|Disk mounting tool| 97 | |UTIME.COM|**CPM UTime**|NTP time synching tool 98 | |UCONFIG.COM|**CPM UConfig**|Utility to set configuration options for CPM UTime| 99 | |CPMUTOOL.CFG|Coniguration file|File containing configuration settings for the tools| 100 | 101 | Note that on first use, both CPM UTime and CPM UConfig create a configuration file on the disk if no one is yet present. A new file called CPMUTOOL.CFG is added to store configuration data. 102 | 103 | Obviously, you are free (even encouraged) to copy these files to another disk target, such as your main RAM drive. 104 | 105 | You can start UMount, UTime, or UConfig by typing the filename (typing the .com is not needed) and enter. 106 | 107 | ## CPM UConfig instructions 108 | ([Back to contents](#contents)) 109 | 110 | This application sets the configuration options for CPM UTIme and saves them in the CPMUTOOL.CFG configuration file. It creates this file on first start if no file is present already. 111 | 112 | Interface after application start, showing the present configuration settings: 113 | 114 | ![CPM UConfig main interface](https://github.com/xahmol/CPMUTools/blob/main/screenshots/uconfig%20-%20mainscreen.png?raw=true) 115 | 116 | Navigate through the editable options by pressing the **CURSOR DOWN** or **CURSOR UP** cursor keys. 117 | 118 | **ESC** will quit the configuration program and save the settings if changed. 119 | 120 | **RETURN** selects the highlighted option for editing. 121 | 122 | ### UMount settings 123 | 124 | |Option|Explanation|How to edit| 125 | |---|---|---| 126 | |Detection override|Rely on automated detection of valid target drives (setting is **No**), or manually select valid targets (setting is **Yes**)|Press **RETURN** to toggle between **Yes** and **No**| 127 | |Autodetection of valid drives succeeded|Shows if firnware support automatic drive detection|Not an option to change| 128 | |A B C D|Setting per CP/M drive: either is **No target** or it is a valid target, in which case it shows the drive ID, type and power status|If Detection override is set as Yes, **RETURN** toggles between No target and Manual Target| 129 | |Target drive|Drive to which images will be mounted|Press **RETURN** to edit this option, then press **CURSOR DOWN** or **CURSOR UP** to change the drive letter, press **RETURN** to confirm, or press **ESC** to cancel.| 130 | 131 | ***Screenshots*** 132 | 133 | - Detection override 134 | 135 | ![Detection override](https://github.com/xahmol/CPMUTools/blob/main/screenshots/uconfig%20-%20toggleoverride.png?raw=true) 136 | 137 | - Toggle targets 138 | 139 | ![Toggle targets](https://github.com/xahmol/CPMUTools/blob/main/screenshots/uconfig%20-%20toggletargets.png?raw=true) 140 | 141 | - Set target 142 | 143 | ![Set target](https://github.com/xahmol/CPMUTools/blob/main/screenshots/uconfig%20-%20settarget.png?raw=true) 144 | 145 | ### UTime Settings 146 | 147 | |Option|Explanation|How to edit| 148 | |---|---|---| 149 | |NTP host|Host name of the desired NTP server. The default server is pool.ntp.org.|Press **RETURN** to select option, then enter desired host by typing it, edit by using the **CURSOR LEFT** and **CURSOR RIGHT** keys, **DEL** to delete, **RETURN** to confirm entry, **ESC** to cancel.| 150 | |UTC offset|Time offset to UTC (Universal standard time) in seconds.|Press **RETURN** to select option, then enter desired offset by typing it (noting the signing, so do not forget the minus sign if offsets are negative to UTC), edit by using the **CURSOR LEFT** and **CURSOR RIGHT** keys, **DEL** to delete, **RETURN** to confirm entry, **ESC** to cancel.| 151 | |Update from HTP|Sets if time should be synched with the selected NTP server (setting is 'Enabled'), or if only the CP/M system time should be synched to the UII+ Real Time Clock without an NTP request (Disabled).|Press **RETURN** to toggle between Enabled and Disabled.| 152 | |Verbose|Enabling this option makes the CPM UTime give visual feedback on the steps it performs, disabling will make CPM UTime perform its actions without any visual feedback.|Press **RETURN** to toggle between Enabled and Disabled.| 153 | 154 | ***Detailed explanation and screenshots*** 155 | 156 | - NTP Host: The application will not check validity of the input, to check if it works and the hostname resolves and results in a successful connection the verbose mode is suggested. 157 | 158 | ![NTP host](https://github.com/xahmol/CPMUTools/blob/main/screenshots/uconfig%20-%20edithost.png?raw=true) 159 | 160 | - UTC offset: Offset is set in seconds (to allow for half hour difference time zones and also for finetuning if desired), so multiply the UTC offset in hours by 3600. And note that the offset is signed, so start with a minus for offsets negative to UTC. Default is set on Central European Time, which requires an offset of 3600. Setting to Central European Summer Time would require 7200. Another example: setting to Eastern Standard Time (EST, time zone for a.o. New York City) would be UTC -5, so -5*3600 = -18000. See https://www.timeanddate.com/time/zones/ for all offsets in hours (multiply by 3600 to get to seconds). No inout validation is performed. 161 | 162 | ![UTC offset](https://github.com/xahmol/CPMUTools/blob/main/screenshots/uconfig%20-%20editoffset.png?raw=true) 163 | 164 | - Update from NTP and verbose: 165 | 166 | ![Time toggles](https://github.com/xahmol/CPMUTools/blob/main/screenshots/uconfig%20-%20toggletime.png?raw=true) 167 | 168 | ## CPM UTime instructions 169 | ([Back to contents](#contents)) 170 | 171 | This application is driven by the options stored in the configuration file and does not need further user interaction. 172 | 173 | If verbosity is set to no in the configuration file options, nothing will be shown on the screen. If verbosity mode is 'Enabled' and NTP enable is 'Enabled', something like this will be shown on the screen: 174 | 175 | ![CPM UTime verbosity output](https://github.com/xahmol/CPMUTools/blob/main/screenshots/utime%20-%20verboseoutput.png?raw=true) 176 | 177 | This mode is meant to either debug your configuration settings, or if you are simply curious what happens: 178 | - Connecting to the selected hostname of the desired NTP server 179 | - Sending the data request to that server 180 | - Reiving the data and interpreting result 181 | - Showing UNIX epoch received 182 | - Converting that output to time in selected time zone using the UTC offset 183 | - Setting the UII+ Real Time Clock with that time 184 | - Synching CP/M system time with the UII+ RTC clock. 185 | - Confirming success 186 | 187 | Note that on any NTP connection error, the CP/M clock will be synched to the unchanged UII+ RTC clock as fallback. 188 | 189 | If NTP enable is switched to off, only the synch between UII+ RTC and the CP/M system time takes place, no NTP time request will be performed. 190 | 191 | ## CPM UMount instructions 192 | ([Back to contents](#contents)) 193 | 194 | This application enables to mount disk images on the UII+ filesystem to an UII+ emulated drive in CP/M via a file browser. 195 | 196 | ### Application limitations and considerations 197 | 198 | To facilitate to find disk images quicker and easier in the filebrowsers, all entries not being directories and file images are filtered out. 199 | 200 | To properly enable filtering, image filenames should end with the proper corresponding .dxx extension: 201 | 202 | - .d64 for 1541 drive type or 1571 drive type 203 | - .g64 for 1541 drive type or 1571 drive type 204 | - .d71 for 1571 drive type 205 | - .d81 for 1581 drive type 206 | 207 | Other image types are not presently supported. 208 | 209 | Also note that file and dirnames can only be selected if they have a maximum name length of 20 characters, including extension. Reason is memory constraints: allowing for longer filenames would cause less filenames that can be loaded in memory. If you need to select dirs or files with longer names, shorten them first to 20 chars (including extension) at most. 210 | 211 | Maximum number of files shown is dependent on the free memory on the target system used. If you have more valid images or subdirectories in your present directory, any entry over that number will not be shown. If you need to reach these dirs or files, consider reorganizing your dir to place the files in subdirs with fewer entries. 212 | 213 | ### Main interface 214 | 215 | After start, this main interface is shown: 216 | 217 | ![CPM UMount main interface](https://github.com/xahmol/CPMUTools/blob/main/screenshots/umount%20-%20mainscreen.png?raw=true) 218 | 219 | On the left the filebrowser is shown. First line is the ID of the Ultimate file system detected, second line shows the present path on that filesystem. 220 | Below those two lines the filtered file list is shown in two columns. You can navigate to images and browse through directories here. 221 | 222 | In the filebrowser section, entries are shown with a three letter explanation of the type: 223 | 224 | |Code|Description| 225 | |---|---| 226 | |DIR|Directory| 227 | |D64|1541 images with .d64 extension| 228 | |D71|1571 images with .d71 extension| 229 | |D81|1581 images with .d81 extension| 230 | |!TL|Name too long to be fully shown. Can not be selected without shortening name| 231 | 232 | On the right top, the detected drives and present target drive is shown. 233 | 234 | ![Drives](https://github.com/xahmol/CPMUTools/blob/main/screenshots/umount%20-%20drives.png?raw=true) 235 | 236 | Below that help for the available key commands is shown: 237 | 238 | |Key|Function| 239 | |---|---| 240 | |**A-D**|Select another drive as target by pressing the key to the corresponding drive letter| 241 | |**CURSOR KEYS**|Navigate the filebrowser area: move in the corresponding direction up, down, left or right| 242 | |**RETURN**|Select the highlighted file to mount (is ignored if a dir (DIR) or if the filename is too long (!TL) ) | 243 | |**P** / **U**|Navigate one page up (**U**) or one page down (**P**)| 244 | |**T** / **E**|Navigate to the first item (**T**) or to the last one (**E**)| 245 | |**DEL**|Navigate to the parent directory| 246 | |**R**|Navigate to the root directory| 247 | |**H**|Navigate to the home directory| 248 | |**S**|Save REU file in present directory| 249 | |**I**|Show version information| 250 | |**ESC**|Quit program| 251 | 252 | *** Detailed explanation*** 253 | 254 | **Moving to a subdirectory** 255 | 256 | Move to a subdirectory by clicking on the desired directory name shown. 257 | 258 | **Selecting an image to mount** 259 | 260 | Select an image to mount by pressing **RETURN** when a valid filename is highlighted (so type .d64, .d71 or .d81). 261 | 262 | On success, the following dialogue is presented: 263 | 264 | ![Image mount dialogue](https://github.com/xahmol/CPMUTools/blob/main/screenshots/umount%20-%20mountsuccess.png?raw=true) 265 | 266 | If this is shown, the selected image is already mounted. 267 | 268 | Press **ESC** to exit the CPM UMount application and go back to the CP/M prompt with the new image mounted to the selected target drive. 269 | 270 | Press any other key if you want to proceed with CPM UMount (for example if you selected a wrong image or if you want to mount images on other targets as well). 271 | 272 | **S: Save REU** 273 | 274 | By pressing **S**, the contents of the REU memory can be saved to a .reu file in the presently active directory. 275 | 276 | First, enter the filename (without .reu extension). 277 | 278 | ![Enter REU filename](https://github.com/xahmol/CPMUTools/blob/main/screenshots/umount%20-%20savereufilename.png?raw=true) 279 | 280 | If a file already exists with this name this is shown: 281 | 282 | ![REU file exists](https://github.com/xahmol/CPMUTools/blob/main/screenshots/umount%20-%20savereufileexists.png?raw=true) 283 | 284 | In this case, press **Y** to proceed and overwrite, **No** to cancel. 285 | 286 | Finally, select the memory size to save using the **+** (increase size) and **-** (decrease size) keys, press **RETURN** to confirm: 287 | 288 | ![Save REU choose memory size to save](https://github.com/xahmol/CPMUTools/blob/main/screenshots/umount%20-%20savereusize.png?raw=true) 289 | 290 | Depending on selected memory size, saving can take a while. 291 | 292 | **I: Version** 293 | 294 | Pressing **I** shows the version information. Press a key to continue. 295 | 296 | ![Version info](https://github.com/xahmol/CPMUTools/blob/main/screenshots/umount%20-%20version.png?raw=true) 297 | 298 | ## Credits 299 | ([Back to contents](#contents)) 300 | 301 | ### CPMUMount 302 | Disk mounter for the Ultimate II+ in CP/M 303 | 304 | Written in 2023 by Xander Mol 305 | 306 | https://github.com/xahmol/CPMUTools 307 | 308 | https://www.idreamtin8bits.com/ 309 | 310 | Code and resources from others used: 311 | 312 | - Scott Hutter - Ultimate II+ library: 313 | https://github.com/xlar54/ultimateii-dos-lib/ 314 | (library for the UII+ UCI functions) 315 | 316 | - z88dk C cross compiler for Z80 targets, including C128 CP/M 317 | https://github.com/z88dk/z88dk/wiki 318 | 319 | - Jochen Metzinger - ctools 320 | https://github.com/mist64/ctools 321 | 322 | - ntp2ultimate by MaxPlap 323 | https://github.com/MaxPlap/ntp2ultimate 324 | Time via NTP code 325 | 326 | - EPOCH-to-time-date-converter by sidsingh78 327 | https://github.com/sidsingh78/EPOCH-to-time-date-converter/blob/master/epoch_conv.c 328 | 329 | - Bart van Leeuwen for providing CP/M images, testing and advice 330 | 331 | - Gideon Zweijtzer for creating the Ultimate II+ cartridge and the Ultimate64, and the Ultimate Command Interface enabling this software. 332 | 333 | - Tested using real hardware (C128D, C128DCR) using CP/M 3.0 and ZP/M+. 334 | 335 | Licensed under the GNU General Public License v3.0 336 | 337 | The code can be used freely as long as you retain 338 | a notice describing original source and author. 339 | 340 | THE PROGRAMS ARE DISTRIBUTED IN THE HOPE THAT THEY WILL BE USEFUL, 341 | BUT WITHOUT ANY WARRANTY. USE THEM AT YOUR OWN RISK! 342 | 343 | -------------------------------------------------------------------------------- /src/mount.c: -------------------------------------------------------------------------------- 1 | /* 2 | CPMUMount 3 | Disk mounter for the Ultimate II+ in CP/M 4 | Written in 2023 by Xander Mol 5 | 6 | https://github.com/xahmol/CPMUTools 7 | 8 | https://www.idreamtin8bits.com/ 9 | 10 | Code and resources from others used: 11 | 12 | - Scott Hutter - Ultimate II+ library: 13 | https://github.com/xlar54/ultimateii-dos-lib/ 14 | (library for the UII+ UCI functions) 15 | 16 | - z88dk C cross compiler for Z80 targets, including C128 CP/M 17 | https://github.com/z88dk/z88dk/wiki 18 | 19 | - Jochen Metzinger - ctools 20 | https://github.com/mist64/ctools 21 | 22 | - ntp2ultimate by MaxPlap 23 | https://github.com/MaxPlap/ntp2ultimate 24 | Time via NTP code 25 | 26 | - EPOCH-to-time-date-converter by sidsingh78 27 | https://github.com/sidsingh78/EPOCH-to-time-date-converter/blob/master/epoch_conv.c 28 | 29 | - Bart van Leeuwen for providing CP/M images, testing and advice 30 | 31 | - Gideon Zweijtzer for creating the Ultimate II+ cartridge and the Ultimate64, and the Ultimate Command Interface enabling this software. 32 | 33 | - Tested using real hardware (C128D, C128DCR) using CP/M 3.0 and ZP/M+. 34 | 35 | Licensed under the GNU General Public License v3.0 36 | 37 | The code can be used freely as long as you retain 38 | a notice describing original source and author. 39 | 40 | THE PROGRAMS ARE DISTRIBUTED IN THE HOPE THAT THEY WILL BE USEFUL, 41 | BUT WITHOUT ANY WARRANTY. USE THEM AT YOUR OWN RISK! 42 | */ 43 | 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include "include/defines.h" 54 | #include "include/core.h" 55 | #include "include/mount_common.h" 56 | #include "include/ultimate_common_lib.h" 57 | #include "include/ultimate_dos_lib.h" 58 | #include "include/ultimate_time_lib.h" 59 | 60 | // Global variables 61 | 62 | // Directory entry struct 63 | struct DirElement 64 | { 65 | unsigned char type; // Type: 1=dir, 2=D64, 3=D71, 4=D81 66 | char filename[21]; 67 | struct DirElement *next; 68 | struct DirElement *prev; 69 | }; 70 | struct DirElement *presentdirelement; 71 | 72 | struct Directory 73 | { 74 | struct DirElement *firstelement; 75 | struct DirElement *firstprint; 76 | ushort position; 77 | }; 78 | struct Directory presentdir; 79 | 80 | // Progress bar 81 | static const char progressBar[4] = {0xA5, 0xA1, 0xA7, ' '}; 82 | static const char progressRev[4] = {0, 0, 1, 1}; 83 | 84 | // Filebrowser dimensions 85 | unsigned char DirH = 18; // Number of entries per column 86 | unsigned char DirC = 2; // Number of columns 87 | unsigned char DirW = 25; // Width of one column 88 | 89 | // REU size variables 90 | char reuname[21] = "cpm"; // Set cpm.reu as default 91 | unsigned char reusize = 7; // Set 16 MB as default 92 | char *reusizelist[8] = {"128 KB", "256 KB", "512 KB", "1 MB", "2 MB", "4 MB", "8 MB", "16 MB"}; 93 | unsigned char reusizes[8] = {1, 3, 7, 15, 31, 63, 127, 255}; 94 | 95 | // Directory reading 96 | 97 | void Freedir() 98 | { 99 | // Free memory of presently loaded dir 100 | 101 | struct DirElement *next = 0; 102 | struct DirElement *present; 103 | 104 | present = presentdir.firstelement; 105 | 106 | do 107 | { 108 | presentdirelement = present; 109 | next = presentdirelement->next; 110 | free(present); 111 | present = next; 112 | } while (next); 113 | } 114 | 115 | void Readdir() 116 | { 117 | // Read present dir of UCI DOS target 118 | 119 | struct DirElement *previous = 0; 120 | struct DirElement *present = 0; 121 | unsigned char presenttype; 122 | unsigned char datalength, count; 123 | unsigned char xpos = 0; 124 | 125 | // Free memory of previous dir if any 126 | if (presentdir.firstelement) 127 | { 128 | Freedir(); 129 | } 130 | 131 | // Clear directory values 132 | presentdir.firstelement = 0; 133 | presentdir.firstprint = 0; 134 | presentdir.position = 0; 135 | 136 | // Initialise reading dir 137 | uii_open_dir(); 138 | if (!uii_success()) 139 | { 140 | uii_abort(); 141 | // ClearArea(0,24,80,1); 142 | // printstrvdc(0,24,colorText,uii_status); 143 | // cgetc(); 144 | return; 145 | } 146 | uii_get_dir(); 147 | 148 | // Loop while dir data is available or memory is full 149 | while (uii_isdataavailable()) 150 | { 151 | // Reset entry type 152 | presenttype = 0; 153 | 154 | // Get next dir entry 155 | uii_readdata(); 156 | uii_accept(); 157 | 158 | datalength = strlen(uii_data); 159 | 160 | // print progress bar 161 | if ((count >> 2) >= DirW * DirC) 162 | { 163 | xpos = 0; 164 | count = 0; 165 | ClearArea(0, 24, DirW * DirC, 1); 166 | } 167 | else 168 | { 169 | fillattrvdc(xpos + (count >> 2), 24, 1, progressRev[count & 3] ? colorText + vdcRvsVid : colorText); 170 | filldspvdc(xpos + (count >> 2), 24, 1, progressBar[count & 3]); 171 | count++; 172 | } 173 | 174 | // ClearArea(0,23,80,2); 175 | // printstrvdc(0,24,colorText,uii_status); 176 | // printstrvdc(0,24,colorText,uii_data); 177 | // cgetc(); 178 | 179 | // Check if entry is a dir by checking if bit 4 of first byte is set 180 | if (uii_data[0] & 0x10) 181 | { 182 | presenttype = 1; 183 | } 184 | 185 | // Check if file is a matching image type 186 | if (!presenttype && datalength > 4) 187 | { 188 | 189 | // Check for filename extension of a disk image (D64/G64, D71/G71 or D81) 190 | 191 | // First check for D or G as first letter of extension after a dot 192 | if ((uii_data[datalength - 4] == '.') && 193 | (uii_data[datalength - 3] == 'd' || uii_data[datalength - 3] == 'D' || 194 | uii_data[datalength - 3] == 'g' || uii_data[datalength - 3] == 'G')) 195 | { 196 | 197 | // Check for D64/G64 198 | if ((uii_data[datalength - 2] == '6') && (uii_data[datalength - 1] == '4')) 199 | { 200 | presenttype = 2; 201 | } 202 | 203 | // Check for D71/G71 204 | if ((uii_data[datalength - 2] == '7') && (uii_data[datalength - 1] == '1')) 205 | { 206 | presenttype = 3; 207 | } 208 | 209 | // Check for D81 210 | if ((uii_data[datalength - 2] == '8') && (uii_data[datalength - 1] == '1')) 211 | { 212 | presenttype = 4; 213 | } 214 | 215 | // Check for DNP 216 | if ((uii_data[datalength - 2] == 'N' || uii_data[datalength - 2] == 'n') && 217 | (uii_data[datalength - 1] == 'P' || uii_data[datalength - 1] == 'p')) 218 | { 219 | presenttype = 5; 220 | } 221 | } 222 | } 223 | 224 | if (presenttype) 225 | { 226 | // Get file or dir name to buffer 227 | datalength--; // Minus 1 for first attribute byte 228 | if (datalength > 20) 229 | { 230 | datalength = 20; 231 | presenttype = 6; 232 | } // Truncate for max 20 233 | memset(buffer, 0, 21); 234 | strlcpy(buffer, uii_data + 1, datalength + 1); 235 | 236 | // Allocate memory for dir entry 237 | present = calloc(1, 26); 238 | 239 | // Break loop if memory is full 240 | if (!present) 241 | { 242 | // Abort UCI dir reading 243 | uii_abort(); 244 | // ClearArea(0,24,80,1); 245 | // printstrvdc(0,24,colorError,"Memory full"); 246 | // cgetc(); 247 | return; 248 | } 249 | 250 | // Set direntry data 251 | presentdirelement = present; 252 | strcpy(presentdirelement->filename, buffer); 253 | presentdirelement->type = presenttype; 254 | 255 | // Set direntry pointers 256 | if (!previous) 257 | { 258 | presentdir.firstelement = present; 259 | presentdir.firstprint = present; 260 | previous = present; 261 | } 262 | else 263 | { 264 | presentdirelement->prev = previous; // Set prev in new entry 265 | presentdirelement = previous; // Load previous element 266 | presentdirelement->next = present; // Set next in this prev element 267 | previous = present; // Update previous pointer 268 | } 269 | 270 | // ClearArea(0,24,80,1); 271 | // sprintf(buffer,"%-20s %d %3d %3d",uii_data+1,presenttype,datalength,strlen(uii_data)); 272 | // printstrvdc(0,24,colorText,buffer); 273 | // cgetc(); 274 | } 275 | } 276 | present = presentdir.firstelement; 277 | presentdirelement = presentdir.firstelement; 278 | ClearArea(0, 24, DirW * DirC, 1); 279 | } 280 | 281 | // Screen printing 282 | 283 | void DrawIDandPath() 284 | { 285 | // Draw UCI ID and pathname. 286 | 287 | ushort length; 288 | 289 | // Clear area 290 | ClearArea(0, 3, DirW * DirC, 2); 291 | 292 | // Get ID from UCI and print 293 | uii_identify(); 294 | sprintf(buffer, "ID: %s", uii_data); 295 | printstrvdc(0, 3, colorText, buffer); 296 | 297 | // Get present path from UCI and print 298 | uii_get_path(); 299 | 300 | // Check if it fits else shorten 301 | length = strlen(uii_data); 302 | if (length > DirW * DirC) 303 | { 304 | strcpy(buffer, uii_data + length - (DirW * DirC)); 305 | } 306 | else 307 | { 308 | strcpy(buffer, uii_data); 309 | } 310 | printstrvdc(0, 4, colorText, buffer); 311 | } 312 | 313 | void DrawDrivetypes() 314 | { 315 | // Draw the drive types of the targets 316 | 317 | unsigned char drive; 318 | 319 | printstrvdc(51, 3, colorText, "Drives:"); 320 | for (drive = 0; drive < MAXDRIVES; drive++) 321 | { 322 | sprintf(buffer, "%c: ", 'A' + drive); 323 | if (!validdrive[drive]) 324 | { 325 | sprintf(buffer + 3, "No target"); 326 | } 327 | else 328 | { 329 | if (!config.auto_override) 330 | { 331 | sprintf(buffer + 3, "%02d, %s %s", drive + 8, uii_device_tyoe(uii_devinfo[validdrive[drive] - 1].type), (uii_device_tyoe(uii_devinfo[validdrive[drive] - 1].power)) ? "On " : "Off"); 332 | } 333 | else 334 | { 335 | sprintf(buffer + 3, "%02d, manual."); 336 | } 337 | } 338 | printstrvdc(51, 4 + drive, colorText, buffer); 339 | } 340 | } 341 | 342 | void DrawTargetdrive() 343 | { 344 | // Draw presently selected target. 345 | 346 | ClearArea(51, 9, 29, 1); 347 | if (targetdrive) 348 | { 349 | sprintf(buffer, "Target is drive %c", targetdrive - 1 + 'A'); 350 | } 351 | else 352 | { 353 | sprintf(buffer, "No valid target"); 354 | } 355 | printstrvdc(51, 9, colorText, buffer); 356 | } 357 | 358 | void PrintDirEntry(struct DirElement *present, unsigned char printpos) 359 | { 360 | // Print entry 361 | 362 | unsigned char xpos = (printpos > DirH - 1) ? DirW : 0; 363 | unsigned char ypos = (printpos > DirH - 1) ? printpos - 13 : 5 + printpos; 364 | unsigned char color = (printpos == presentdir.position) ? colorSelect : colorDirEntry; 365 | 366 | sprintf(buffer, "%-20s %-3s", present->filename, entrytypes[present->type - 1]); 367 | printstrvdc(xpos, ypos, color, buffer); 368 | } 369 | 370 | void DrawDir(unsigned char readdir) 371 | { 372 | // Draw the dirlisting. Read dir is flag for 0 = just reprint same dir, 1 = read new dir 373 | 374 | unsigned char printpos = 0; 375 | struct DirElement *present; 376 | 377 | // Clear area 378 | ClearArea(0, 5, DirW * DirC, DirH); 379 | 380 | // Read directory contents 381 | if (readdir) 382 | { 383 | DrawIDandPath(); 384 | Readdir(); 385 | } 386 | 387 | // Print no data if no valid entries in dir are found 388 | if (!presentdir.firstprint) 389 | { 390 | printstrvdc(1, 5, colorError, "No data."); 391 | } 392 | // Print entries until area is filled or last item is reached 393 | else 394 | { 395 | // Get direlement 396 | present = presentdir.firstprint; 397 | 398 | // Loop while area is not full and further direntries are still present 399 | do 400 | { 401 | // Print entry and increase printpos 402 | PrintDirEntry(present, printpos++); 403 | 404 | // Check if next dir entry is present, if no: break. If yes: update present pointer 405 | if (!present->next) 406 | { 407 | break; 408 | } 409 | else 410 | { 411 | present = present->next; 412 | } 413 | 414 | } while (printpos < (DirH * DirC)); 415 | } 416 | 417 | present = presentdir.firstelement; 418 | } 419 | 420 | void DrawMenu() 421 | { 422 | unsigned char ypos = 11; 423 | 424 | printstrvdc(51, ypos++, colorText, "A-E : Select target"); 425 | printstrvdc(51, ypos++, colorText, "Curs : Navigation"); 426 | printstrvdc(51, ypos++, colorText, "RETURN: Select"); 427 | printstrvdc(51, ypos++, colorText, "P / U : Page Down/Up"); 428 | printstrvdc(51, ypos++, colorText, "T / L : Go Top/Last"); 429 | printstrvdc(51, ypos++, colorText, "DEL : Parent dir"); 430 | printstrvdc(51, ypos++, colorText, "R : Root dir"); 431 | printstrvdc(51, ypos++, colorText, "H : Home dir"); 432 | printstrvdc(51, ypos++, colorText, "S : Save REU"); 433 | printstrvdc(51, ypos++, colorText, "I : Version"); 434 | printstrvdc(51, ypos++, colorText, "ESC : Quit"); 435 | } 436 | 437 | // Mounting routines 438 | 439 | void EnableDrivePower(unsigned char ab) 440 | { 441 | // Toggle power for the Ultimate drives 442 | // - ab: Drive A = 0, Drive B = 1 443 | 444 | if (uii_devinfo[ab].exist) 445 | { 446 | // Drive selected and existing 447 | 448 | if (!uii_devinfo[ab].power) 449 | { 450 | // Power on drive A if needed 451 | if (!ab) 452 | { 453 | uii_enable_drive_a(); 454 | } 455 | else 456 | { 457 | uii_enable_drive_b(); 458 | } 459 | delay(20); 460 | } 461 | CheckUCIStatus(); 462 | } 463 | } 464 | 465 | void MountImage(ushort target, char *image) 466 | { 467 | 468 | ushort ult_drive = (validdrive[target - 1] && validdrive[target - 1] < 3); 469 | 470 | if (!validdrive[target - 1]) 471 | { 472 | return; 473 | } 474 | 475 | if (ult_drive) 476 | { 477 | // Recheck drive statusses and see if power on/off is supported 478 | if (uii_parse_deviceinfo()) 479 | { 480 | EnableDrivePower((uii_devinfo[0].id == target + 7) ? 0 : 1); // Enable drive A if powered off 481 | } 482 | // Mount image 483 | uii_mount_disk(target + 7, image); 484 | } 485 | else 486 | { 487 | uii_change_dir(image); 488 | } 489 | 490 | // Print error message or Success message 491 | if (!CheckUCIStatus()) 492 | { 493 | if (ult_drive) 494 | { 495 | uii_parse_deviceinfo(); // Recheck drive statusses 496 | ClearArea(51, 3, 29, 5); 497 | DrawDrivetypes(); // Redraw drive statusses 498 | } 499 | printstrvdc(0, 23, colorSuccess, "Success!"); 500 | sprintf(buffer, "%s mounted on %c, ID %2d", image, target + 'A' - 1, target + 7); 501 | printstrvdc(9, 23, colorText, buffer); 502 | printstrvdc(0, 24, colorText, "Press ESC to exit or any other key to mount another image."); 503 | if (cgetc() == K_ESCAPE) 504 | { 505 | done(0); 506 | } // Exit program if ESCAPE is pressed 507 | ClearArea(0, 23, 80, 2); 508 | } 509 | } 510 | 511 | void saveREU() 512 | { 513 | // Function to save present REU expanded memory to REU file 514 | 515 | unsigned char namelen, key; 516 | char savename[21]; 517 | 518 | // Ask for filename 519 | printstrvdc(0, 23, colorText, "Enter filename for the image:"); 520 | if (textInput(0, 24, reuname, 16) == -1) 521 | { 522 | ClearArea(0, 23, 80, 2); 523 | return; 524 | } 525 | ClearArea(0, 23, 80, 2); 526 | 527 | // Add extention based on RAM disk type 528 | strcpy(savename, reuname); 529 | namelen = strlen(savename); 530 | savename[namelen] = '.'; 531 | strcpy(savename + 1 + namelen, "reu"); 532 | 533 | // Check if file exists 534 | uii_open_file(1, savename); 535 | if (uii_success()) 536 | { 537 | uii_close_file(); 538 | printstrvdc(0, 24, colorText, "File exists. Overwrite? Y=Yes or N=No"); 539 | do 540 | { 541 | key = cgetc(); 542 | } while (key != 'y' && key != 'n'); 543 | ClearArea(0, 24, 80, 1); 544 | 545 | if (key == 'n') 546 | { 547 | // Exit function on NO on overwrite 548 | return; 549 | } 550 | else 551 | { 552 | // Delete existing file if YES on overwrite 553 | uii_delete_file(savename); 554 | if (CheckUCIStatus()) 555 | { 556 | return; 557 | } 558 | } 559 | } 560 | else 561 | { 562 | uii_abort(); 563 | } 564 | 565 | // Select REU size 566 | printstrvdc(0, 23, colorText, "Select REU size (+/-/ENTER):"); 567 | do 568 | { 569 | sprintf(buffer, "REU file size: (%d) %s ", reusize, reusizelist[reusize]); 570 | printstrvdc(0, 24, colorText, buffer); 571 | key = cgetc(); 572 | if (key == '+') 573 | { 574 | reusize++; 575 | if (reusize > 7) 576 | { 577 | reusize = 0; 578 | } 579 | } 580 | if (key == '-') 581 | { 582 | if (reusize == 0) 583 | { 584 | reusize = 7; 585 | } 586 | else 587 | { 588 | reusize--; 589 | } 590 | } 591 | } while (key != K_RETURN); 592 | ClearArea(0, 23, 80, 2); 593 | 594 | // Print saving message 595 | sprintf(buffer, "Saving: %d KB to %s. Please wait.", (reusizes[reusize] + 1) * 64, savename); 596 | printstrvdc(0, 24, colorText, buffer); 597 | 598 | // Save REU image 599 | uii_open_file(0x06, savename); 600 | if (CheckUCIStatus()) 601 | { 602 | return; 603 | } 604 | uii_save_reu(reusizes[reusize]); 605 | if (CheckUCIStatus()) 606 | { 607 | return; 608 | } 609 | uii_close_file(); 610 | ClearArea(0, 24, 80, 1); 611 | 612 | // Print result 613 | if (CheckUCIStatus()) 614 | { 615 | printstrvdc(0, 24, colorSuccess, "Success! "); 616 | sprintf(buffer, "Saved %d KB to %s. Press key.", (reusizes[reusize] + 1) * 64, savename); 617 | printstrvdc(9, 24, colorText, buffer); 618 | cgetc(); 619 | ClearArea(0, 24, 80, 1); 620 | } 621 | } 622 | 623 | // Main 624 | 625 | void main(void) 626 | { 627 | 628 | unsigned char key, element; 629 | struct DirElement *present; 630 | 631 | // Set version number in string variable 632 | sprintf(version, 633 | "v%2d.%2d - %c%c%c%c%c%c%c%c-%c%c%c%c", 634 | VERSION_MAJOR, VERSION_MINOR, 635 | BUILD_YEAR_CH0, BUILD_YEAR_CH1, BUILD_YEAR_CH2, BUILD_YEAR_CH3, 636 | BUILD_MONTH_CH0, BUILD_MONTH_CH1, BUILD_DAY_CH0, BUILD_DAY_CH1, 637 | BUILD_HOUR_CH0, BUILD_HOUR_CH1, BUILD_MIN_CH0, BUILD_MIN_CH1); 638 | 639 | // Set presentdir pointer at zero 640 | presentdir.firstelement = 0; 641 | 642 | // Get config data 643 | ReadConfigfile(0); 644 | 645 | // Get valid UII+ drives 646 | SetValidDrives(); 647 | if (!targetdrive) 648 | { 649 | printf("No targets detected or set. Press OK to abort."); 650 | exit(1); 651 | } 652 | 653 | // Initialize screen 654 | init(); 655 | headertext("UMount: Image mounter"); 656 | DrawDrivetypes(); 657 | DrawTargetdrive(); 658 | DrawMenu(); 659 | DrawDir(1); 660 | 661 | // Main loop 662 | presentdirelement = presentdir.firstelement; 663 | do 664 | { 665 | present = presentdirelement; 666 | 667 | // sprintf(buffer,"Pos : %02d",presentdir.position); 668 | // printstrvdc(51,20,colorText,buffer); 669 | // sprintf(buffer,"Present: %4X",present); 670 | // printstrvdc(51,21,colorText,buffer); 671 | // sprintf(buffer,"PrDirEl: %4X",presentdirelement); 672 | // printstrvdc(51,22,colorText,buffer); 673 | // sprintf(buffer,"FirstEl: %4X",presentdir.firstelement); 674 | // printstrvdc(51,23,colorText,buffer); 675 | // sprintf(buffer,"FirstPr: %4X",presentdir.firstprint); 676 | // printstrvdc(51,24,colorText,buffer); 677 | 678 | key = cgetc(); 679 | 680 | // sprintf(buffer,"Key : %02X",key); 681 | // printstrvdc(51,19,colorText,buffer); 682 | 683 | switch (key) 684 | { 685 | case CURS_DOWN: 686 | case CURU_DOWN: 687 | // Go down 688 | if (presentdirelement && presentdirelement->next) 689 | { 690 | present = presentdirelement->next; 691 | presentdirelement = present; 692 | presentdir.position++; 693 | if (presentdir.position > (DirH * DirC) - 1) 694 | { 695 | // Next page 696 | presentdir.firstprint = present; 697 | presentdir.position = 0; 698 | DrawDir(0); 699 | presentdirelement = present; 700 | } 701 | else 702 | { 703 | // Next line same page 704 | presentdirelement = present->prev; 705 | PrintDirEntry(presentdirelement, presentdir.position - 1); 706 | presentdirelement = present; 707 | PrintDirEntry(presentdirelement, presentdir.position); 708 | } 709 | } 710 | break; 711 | 712 | case CURS_UP: 713 | case CURU_UP: 714 | // Go up 715 | if (presentdirelement && presentdirelement->prev) 716 | { 717 | present = presentdirelement->prev; 718 | presentdirelement = present; 719 | if (presentdir.position == 0) 720 | { 721 | // Previous page 722 | // Go back positions for one page - 1 723 | for (element = 0; element < (DirH * DirC) - 1; element++) 724 | { 725 | if (present->prev) 726 | { 727 | present = present->prev; 728 | presentdir.position++; 729 | } 730 | } 731 | presentdir.firstprint = present; 732 | DrawDir(0); 733 | } 734 | else 735 | { 736 | // Previous line same page 737 | presentdir.position--; 738 | presentdirelement = present->next; 739 | PrintDirEntry(presentdirelement, presentdir.position + 1); 740 | presentdirelement = present; 741 | PrintDirEntry(presentdirelement, presentdir.position); 742 | } 743 | } 744 | break; 745 | 746 | case CURS_RIGHT: 747 | case CURU_RIGHT: 748 | // Go right 749 | if (presentdir.position < DirH && DirC == 2) 750 | { 751 | // Check if not already right 752 | presentdir.position++; 753 | PrintDirEntry(present, presentdir.position - 1); 754 | presentdir.position--; 755 | // Scroll 18 positions forward or to last element 756 | for (element = 0; element < DirH; element++) 757 | { 758 | if (present->next) 759 | { 760 | present = present->next; 761 | presentdir.position++; 762 | } 763 | } 764 | PrintDirEntry(present, presentdir.position); 765 | presentdirelement = present; 766 | } 767 | break; 768 | 769 | case CURS_LEFT: 770 | case CURU_LEFT: 771 | // Go left 772 | if (presentdir.position > DirH - 1) 773 | { 774 | // Check if not allready left 775 | presentdir.position++; 776 | PrintDirEntry(present, presentdir.position - 1); 777 | presentdir.position--; 778 | // Scroll 18 positions back or to first element 779 | for (element = 0; element < DirH; element++) 780 | { 781 | if (present->prev) 782 | { 783 | present = present->prev; 784 | presentdir.position--; 785 | } 786 | } 787 | PrintDirEntry(present, presentdir.position); 788 | presentdirelement = present; 789 | } 790 | break; 791 | 792 | case K_RETURN: 793 | case K_CR: 794 | // RETURN for select dir or image 795 | if (presentdir.firstelement && presentdirelement->type != 6) 796 | // Check if a valid type 797 | { 798 | if (presentdirelement->type == 1) 799 | { 800 | // Change directory 801 | uii_change_dir(presentdirelement->filename); 802 | CheckUCIStatus(); 803 | DrawDir(1); 804 | } 805 | else 806 | { 807 | // Mount image 808 | MountImage(targetdrive, presentdirelement->filename); 809 | } 810 | } 811 | break; 812 | 813 | case K_BACKKSPACE: 814 | case K_DEL: 815 | // Go to parent dir 816 | uii_change_dir(".."); 817 | CheckUCIStatus(); 818 | DrawDir(1); 819 | break; 820 | 821 | case 'p': 822 | if (presentdirelement->next) 823 | { 824 | // Check if not allready last item 825 | presentdir.position = 0; 826 | // Go forward one page in positions 827 | for (element = 0; element < (DirH * DirC); element++) 828 | { 829 | if (present->next) 830 | { 831 | present = present->next; 832 | } 833 | } 834 | presentdir.firstprint = present; 835 | DrawDir(0); 836 | presentdirelement = present; 837 | } 838 | break; 839 | 840 | case 'u': 841 | if (presentdirelement->prev) 842 | { 843 | // Check if not allready first item 844 | presentdir.position = 0; 845 | // Go back one page in positions 846 | for (element = 0; element < (DirH * DirC); element++) 847 | { 848 | if (present->prev) 849 | { 850 | present = present->prev; 851 | } 852 | } 853 | presentdir.firstprint = present; 854 | DrawDir(0); 855 | presentdirelement = present; 856 | } 857 | break; 858 | 859 | case 'r': 860 | // Go to root dir 861 | uii_change_dir("/"); 862 | CheckUCIStatus(); 863 | DrawDir(1); 864 | break; 865 | 866 | case 'h': 867 | // Go to home dir 868 | uii_change_dir_home(); 869 | CheckUCIStatus(); 870 | DrawDir(1); 871 | break; 872 | 873 | case 't': 874 | // Go to first entry 875 | if (presentdir.firstelement && presentdirelement->prev) 876 | { 877 | // Check if a dir is loaded and if not already first item 878 | presentdirelement = presentdir.firstelement; 879 | presentdir.firstprint = presentdir.firstelement; 880 | presentdir.position = 0; 881 | DrawDir(0); 882 | } 883 | break; 884 | 885 | case 'l': 886 | // Go to last entry 887 | if (presentdir.firstelement && presentdirelement->next) 888 | { 889 | // Check if a dir is loaded and if not already last item 890 | 891 | // Go to last item and update position and first printed 892 | element = presentdir.position; 893 | do 894 | { 895 | present = present->next; 896 | element++; 897 | if (element > (DirH * DirC) - 1) 898 | { 899 | element = 0; 900 | presentdir.firstprint = present; 901 | } 902 | } while (present->next); 903 | presentdir.position = element; 904 | presentdirelement = present; 905 | DrawDir(0); 906 | } 907 | break; 908 | 909 | case 'a': 910 | case 'b': 911 | case 'c': 912 | case 'd': 913 | case 'e': 914 | if (validdrive[key - 'a']) 915 | { 916 | targetdrive = key - 'a' + 1; 917 | DrawTargetdrive(); 918 | } 919 | break; 920 | 921 | case 's': 922 | saveREU(); 923 | break; 924 | 925 | case 'i': 926 | sprintf(buffer, "Version: %s. Press key.", version); 927 | printstrvdc(0, 24, colorText, buffer); 928 | cgetc(); 929 | ClearArea(0, 24, 80, 1); 930 | break; 931 | 932 | default: 933 | break; 934 | } 935 | } while (key != K_ESCAPE); 936 | 937 | // Exit program 938 | done(0); 939 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------