├── .gitignore ├── 3d └── pcb_case.stl ├── LICENSE ├── Makefile ├── README.md ├── dist ├── RetroStore_gerber.zip ├── bootloader.bin ├── partitions_two_ota.bin ├── rsclient.cmd └── trs-io.bin ├── doc ├── README.md ├── build.md ├── rs_bodge_fix.jpg ├── rs_fix.md ├── rsc-architecture.odg ├── rsc-architecture.png ├── rsc.odg ├── rsc.png ├── rsclient-1.png ├── tcp_ip.md ├── trs-io-architecture.odg ├── trs-io-architecture.png ├── trs-io-card-v1-labels.png ├── trs-io-card-v1.png └── trs-io-web-ui.png ├── examples ├── trs-fs │ └── CAT.BAS └── trs-nic │ └── WHOIS.BAS ├── fritzing ├── RetroStore.fzz └── RetroStore_gerber │ ├── RetroStore_contour.gm1 │ ├── RetroStore_copperBottom.gbl │ ├── RetroStore_copperTop.gtl │ ├── RetroStore_drill.txt │ ├── RetroStore_maskBottom.gbs │ ├── RetroStore_maskTop.gts │ ├── RetroStore_pnp.txt │ ├── RetroStore_silkBottom.gbo │ └── RetroStore_silkTop.gto ├── gal ├── .gitignore ├── README.md ├── TRS-IO.jed ├── TRS-IO.pld ├── TRS-IO_noFreHD.jed └── TRS-IO_noFreHD.pld ├── kicad └── v1 │ ├── HiLetgoESP32s.dcm │ ├── HiLetgoESP32s.lib │ ├── TRSIO-B.Cu.gbr │ ├── TRSIO-B.Mask.gbr │ ├── TRSIO-B.SilkS.gbr │ ├── TRSIO-Edge.Cuts.gbr │ ├── TRSIO-F.Cu.gbr │ ├── TRSIO-F.Mask.gbr │ ├── TRSIO-F.SilkS.gbr │ ├── TRSIO-NPTH.drl │ ├── TRSIO-cache.lib │ ├── TRSIO.dcm │ ├── TRSIO.drl │ ├── TRSIO.kicad_pcb │ ├── TRSIO.lib │ ├── TRSIO.net │ ├── TRSIO.pdf │ ├── TRSIO.pretty │ ├── DIP-30_W25.4mm.kicad_mod │ ├── DIP-38_W22.9mm.kicad_mod │ ├── DIP-38_W24.0mm.kicad_mod │ ├── DIP-38_W25.4mm.kicad_mod │ └── Pin_Header_Straight_2x25_Pitch2.54mm.kicad_mod │ ├── TRSIO.pro │ ├── TRSIO.sch │ └── fp-lib-table └── src ├── Makefile ├── esp ├── .cproject ├── .gitignore ├── .project ├── .settings │ ├── language.settings.xml │ └── org.eclipse.cdt.core.prefs ├── Makefile ├── components │ ├── frehd │ │ ├── component.mk │ │ ├── dsk.c │ │ ├── frehd.c │ │ ├── include │ │ │ ├── action.h │ │ │ ├── frehd.h │ │ │ ├── integer.h │ │ │ ├── loader_xtrs.h │ │ │ ├── reed.h │ │ │ ├── socket-io.h │ │ │ ├── trs_extra.h │ │ │ ├── trs_hard.h │ │ │ ├── trs_hard_defs.h │ │ │ └── version-frehd.h │ │ ├── io.c │ │ ├── test.c │ │ ├── trs_extra.c │ │ └── trs_hard.c │ ├── html │ │ ├── .gitignore │ │ ├── component.mk │ │ └── index.html │ ├── libsmb2 │ │ ├── CMakeLists.txt │ │ ├── COPYING │ │ ├── LICENCE-LGPL-2.1.txt │ │ ├── Makefile.am │ │ ├── README │ │ ├── bootstrap │ │ ├── cmake │ │ │ ├── ConfigureChecks.cmake │ │ │ ├── FindSMB2.cmake │ │ │ ├── Modules │ │ │ │ └── FindGSSAPI.cmake │ │ │ ├── config.h.cmake │ │ │ └── libsmb2.pc.cmake │ │ ├── component.mk │ │ ├── configure.ac │ │ ├── examples │ │ │ ├── CMakeLists.txt │ │ │ ├── Makefile.am │ │ │ ├── smb2-cat-async.c │ │ │ ├── smb2-cat-sync.c │ │ │ ├── smb2-ftruncate-sync.c │ │ │ ├── smb2-ls-async.c │ │ │ ├── smb2-ls-sync.c │ │ │ ├── smb2-put-async.c │ │ │ ├── smb2-put-sync.c │ │ │ ├── smb2-raw-fsstat-async.c │ │ │ ├── smb2-raw-getsd-async.c │ │ │ ├── smb2-raw-stat-async.c │ │ │ ├── smb2-share-enum.c │ │ │ ├── smb2-stat-sync.c │ │ │ ├── smb2-statvfs-sync.c │ │ │ └── smb2-truncate-sync.c │ │ ├── include │ │ │ ├── Makefile.am │ │ │ ├── asprintf.h │ │ │ ├── esp │ │ │ │ └── config.h │ │ │ ├── libsmb2-private.h │ │ │ ├── msvc │ │ │ │ ├── poll.h │ │ │ │ └── sys │ │ │ │ │ └── socket.h │ │ │ ├── portable-endian.h │ │ │ ├── slist.h │ │ │ └── smb2 │ │ │ │ ├── libsmb2-dcerpc-srvsvc.h │ │ │ │ ├── libsmb2-dcerpc.h │ │ │ │ ├── libsmb2-raw.h │ │ │ │ ├── libsmb2.h │ │ │ │ ├── smb2-errors.h │ │ │ │ └── smb2.h │ │ ├── lib │ │ │ ├── CMakeLists.txt │ │ │ ├── Makefile.am │ │ │ ├── aes.c │ │ │ ├── aes.h │ │ │ ├── alloc.c │ │ │ ├── compat.c │ │ │ ├── dcerpc-srvsvc.c │ │ │ ├── dcerpc.c │ │ │ ├── errors.c │ │ │ ├── hmac-md5.c │ │ │ ├── hmac-md5.h │ │ │ ├── hmac.c │ │ │ ├── init.c │ │ │ ├── krb5-wrapper.c │ │ │ ├── krb5-wrapper.h │ │ │ ├── libsmb2.c │ │ │ ├── libsmb2.syms │ │ │ ├── md4.h │ │ │ ├── md4c.c │ │ │ ├── md5.c │ │ │ ├── md5.h │ │ │ ├── ntlmssp.c │ │ │ ├── ntlmssp.h │ │ │ ├── pdu.c │ │ │ ├── sha-private.h │ │ │ ├── sha.h │ │ │ ├── sha1.c │ │ │ ├── sha224-256.c │ │ │ ├── sha384-512.c │ │ │ ├── smb2-cmd-close.c │ │ │ ├── smb2-cmd-create.c │ │ │ ├── smb2-cmd-echo.c │ │ │ ├── smb2-cmd-error.c │ │ │ ├── smb2-cmd-flush.c │ │ │ ├── smb2-cmd-ioctl.c │ │ │ ├── smb2-cmd-logoff.c │ │ │ ├── smb2-cmd-negotiate.c │ │ │ ├── smb2-cmd-query-directory.c │ │ │ ├── smb2-cmd-query-info.c │ │ │ ├── smb2-cmd-read.c │ │ │ ├── smb2-cmd-session-setup.c │ │ │ ├── smb2-cmd-set-info.c │ │ │ ├── smb2-cmd-tree-connect.c │ │ │ ├── smb2-cmd-tree-disconnect.c │ │ │ ├── smb2-cmd-write.c │ │ │ ├── smb2-data-file-info.c │ │ │ ├── smb2-data-filesystem-info.c │ │ │ ├── smb2-data-security-descriptor.c │ │ │ ├── smb2-share-enum.c │ │ │ ├── smb2-signing.c │ │ │ ├── smb2-signing.h │ │ │ ├── socket.c │ │ │ ├── sync.c │ │ │ ├── timestamps.c │ │ │ ├── unicode.c │ │ │ └── usha.c │ │ ├── packaging │ │ │ └── RPM │ │ │ │ └── makerpms.sh │ │ └── tests │ │ │ └── ntlmssp_generate_blob.c │ ├── retrostore │ │ ├── .gitignore │ │ ├── ApiProtos.pb.c │ │ ├── backend.cpp │ │ ├── cJSON.cpp │ │ ├── component.mk │ │ ├── esp_mock.cpp │ │ ├── include │ │ │ ├── ApiProtos.pb.h │ │ │ ├── backend.h │ │ │ ├── cJSON.h │ │ │ ├── defs.h │ │ │ ├── esp_mock.h │ │ │ ├── pb.h │ │ │ ├── pb_common.h │ │ │ ├── pb_decode.h │ │ │ ├── retrostore.h │ │ │ └── utils.h │ │ ├── pb_common.cpp │ │ ├── pb_decode.cpp │ │ ├── proto │ │ │ ├── ApiProtos.options │ │ │ └── ApiProtos.proto │ │ ├── retrostore.cpp │ │ └── utils.cpp │ ├── tcpip │ │ ├── component.mk │ │ ├── include │ │ │ └── tcpip.h │ │ └── tcpip.cpp │ ├── trs-fs │ │ ├── component.mk │ │ ├── fileio.cpp │ │ ├── include │ │ │ ├── fileio.h │ │ │ ├── serial.h │ │ │ ├── smb.h │ │ │ └── trs-fs.h │ │ ├── serial.cpp │ │ ├── smb.cpp │ │ └── trs-fs.cpp │ └── trs-io │ │ ├── component.mk │ │ ├── core.cpp │ │ ├── include │ │ ├── trs-io.h │ │ └── version.h │ │ └── trs-io.cpp ├── main │ ├── Kconfig │ ├── button.cpp │ ├── component.mk │ ├── event.cpp │ ├── include │ │ ├── button.h │ │ ├── event.h │ │ ├── io.h │ │ ├── led.h │ │ ├── mongoose.h │ │ ├── ntp_sync.h │ │ ├── ota.h │ │ ├── storage.h │ │ └── wifi.h │ ├── io.cpp │ ├── led.cpp │ ├── main.cpp │ ├── mongoose.cpp │ ├── ntp_sync.cpp │ ├── ota-dummy.cpp │ ├── ota.cpp │ ├── storage.cpp │ └── wifi.cpp ├── reset_to_factory.sh └── sdkconfig ├── ihex2cmd ├── .gitignore ├── Makefile └── ihex2cmd.cpp ├── loader ├── Makefile ├── basic │ ├── .gitignore │ ├── Makefile │ ├── crt0.s │ ├── defs.h │ ├── main.c │ └── mem-dump-4000-4200.c └── cmd │ ├── .gitignore │ ├── Makefile │ └── loader_cmd.asm ├── modules ├── Makefile └── trs-io-fs │ ├── .gitignore │ ├── .idea │ └── misc.xml │ ├── Makefile │ ├── build.gradle │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle │ └── src │ └── main │ └── java │ └── org │ └── trsio │ └── fs │ ├── BaseIO.java │ ├── ChannelIO.java │ ├── FRESULT.java │ ├── FileIO.java │ ├── Main.java │ ├── OpenMode.java │ ├── SerialIO.java │ └── SocketIO.java └── trs ├── .gitignore ├── Makefile ├── about.c ├── about.h ├── browse.c ├── browse.h ├── crt0.s ├── defs.h ├── esp.c ├── esp.h ├── font.c ├── form.c ├── form.h ├── hardware.h ├── header.c ├── header.h ├── help.c ├── help.h ├── inout.c ├── inout.h ├── key.c ├── key.h ├── list.c ├── list.h ├── main.c ├── menu.c ├── menu.h ├── panic.c ├── panic.h ├── retrostore.h ├── version.h ├── wifi.c ├── wifi.h ├── window.c └── window.h /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.o 3 | .DS_Store 4 | -------------------------------------------------------------------------------- /3d/pcb_case.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pski/trsnic/6ae25e1bb3c1a476fea5f019afc2290e951aeb3e/3d/pcb_case.stl -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | MAKE = make 3 | 4 | DIRS = src 5 | 6 | 7 | all: 8 | for i in $(DIRS); do $(MAKE) -C $$i || exit 1; done 9 | mkdir -p dist 10 | cp src/esp/build/partitions_two_ota.bin dist 11 | cp src/esp/build/trs-io.bin dist 12 | cp src/esp/build/bootloader/bootloader.bin dist 13 | cp src/trs/rsclient.cmd dist 14 | zip -rj dist/RetroStore_gerber.zip fritzing/RetroStore_gerber 15 | 16 | clean: 17 | for i in $(DIRS); do $(MAKE) -C $$i clean || exit 1; done 18 | rm -rf dist 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # trsnic 2 | 3 | **trsnic** is a general purpose WiFi [TCP/IP](https://en.wikipedia.org/wiki/Internet_protocol_suite) network interface for the TRS-80 line of microcomputers. It is a fork of Arno Puder's amazing [TRS-IO](https://github.com/apuder/TRS-IO). The product will initially support the TRS-80 Model III and 4 as this is the current support level of the TRS-IO source repository. The long term goal is to support all TRS-80s, including the Models I/II/III/4/12/16/16B/6000. 4 | 5 | **trsnic** provides the foundational protocols required to implement existing network interactions on the TRS-80 microcomputer. The first such protocol provided is TCP/IP via an implementation of the [Berekely Sockets API](https://en.wikipedia.org/wiki/Berkeley_sockets). TCP/IP is the dominant low level network protocol in use today. Many of today's higher level network protocols like HTTP and FTP are implemented on top of TCP/IP. This means many modern networking systems can be built upon the base TCP/IP support provided by **trsnic**. 6 | 7 | Additional protocols can be provided as demand requires. If desired, any protocol can be implemented by a contributer or forker of this repository. 8 | 9 | **trsnic** is currently implemented on the TRS-IO architecture. However, the API will endeavor to be hardware agnostic through the use of client-side adapters to allow support for other TRS-80 hardware networking alternatives, such as serial-IP converters, like the ATC-1000, the MISE/M3SE ethernet WIZnet module, legacy ARCNET controllers, Tandy's Network 4, etc. In this way, software can be written using a single networking API that could potentially use different physical network interfaces, both modern and vintage OEM. Adapters can be developed for new interfaces that may be developed in the future with no application side changes required. 10 | 11 | #### TRS-IO Card 12 | ![TRS-IO](./doc/trs-io-card-v1.png) 13 | 14 | **Note** If you have the previous generation RestroStoreCard or **trsnic** card then you need to [make some modifications to the circuit wiring](./doc/rs_fix.md) in order to work with TRS-IO architecture. 15 | 16 | ## Building the Hardware 17 | 18 | 1. Make the [circuit board](./kicad/v1). 19 | 2. Get the [parts](./doc/build.md). 20 | 3. Program the [GAL](./gal). 21 | 4. Install the [ESP-IDF v3.2.2](https://github.com/espressif/esp-idf/tree/v3.2.2). 22 | 5. Run `make` in the project root. 23 | 6. Run `make menuconfig`in the [/src/esp directory](./src/esp). 24 | 7. Run `make flash monitor`. 25 | 8. Follow the setup directions on the [TRS-IO](https://github.com/apuder/TRS-IO) site. 26 | 27 | 28 | ## Programming 29 | 30 | See [TCP/IP API](./doc/tcp_ip.md) 31 | 32 | ----- 33 | Have questions? [@pski](https://github.com) 34 | 35 | 36 | -------------------------------------------------------------------------------- /dist/RetroStore_gerber.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pski/trsnic/6ae25e1bb3c1a476fea5f019afc2290e951aeb3e/dist/RetroStore_gerber.zip -------------------------------------------------------------------------------- /dist/bootloader.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pski/trsnic/6ae25e1bb3c1a476fea5f019afc2290e951aeb3e/dist/bootloader.bin -------------------------------------------------------------------------------- /dist/partitions_two_ota.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pski/trsnic/6ae25e1bb3c1a476fea5f019afc2290e951aeb3e/dist/partitions_two_ota.bin -------------------------------------------------------------------------------- /dist/rsclient.cmd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pski/trsnic/6ae25e1bb3c1a476fea5f019afc2290e951aeb3e/dist/rsclient.cmd -------------------------------------------------------------------------------- /dist/trs-io.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pski/trsnic/6ae25e1bb3c1a476fea5f019afc2290e951aeb3e/dist/trs-io.bin -------------------------------------------------------------------------------- /doc/README.md: -------------------------------------------------------------------------------- 1 | ### TRS-IO Documentation 2 | 3 | 4 | [TCP/IP](tcp_ip.md) - details about the tsrnic TCP/IP API implemented by TRS-IO 5 | 6 | [BOM](build.md) - a detailed list of all components you need to build a TRS-IO board 7 | 8 | [Old Board Fix](rs_fix.md) - bodge wire updates to make the original RS board compatible with TRS-IO 9 | -------------------------------------------------------------------------------- /doc/build.md: -------------------------------------------------------------------------------- 1 | #### TRS-IO - Circuit Board Bill of Materials 2 | 3 | |Qty|Digikey Part#|Manuf Part #|Description| 4 | |:---|:---|:---|:---| 5 | |1|[ATF16V8B-15PU-ND](https://www.digikey.com/product-detail/en/microchip-technology/ATF16V8B-15PU/ATF16V8B-15PU-ND/1118926)|ATF16V8B-15PU|IC PLD 8MC 15NS 20DIP 6 | |2|[296-8503-5-ND](https://www.digikey.com/product-detail/en/texas-instruments/SN74LVC245AN/296-8503-5-ND/377483)|SN74LVC245AN|IC TXRX NON-INVERT 3.6V 20DIP 7 | |3|[2N7000-G-ND](https://www.digikey.com/product-detail/en/microchip-technology/2N7000-G/2N7000-G-ND/4902350)|2N7000-G|MOSFET N-CH 60V 0.2A TO92-3 8 | |1|[1830-1014-ND](https://www.digikey.com/product-detail/en/inolux/HV-5RGB60/1830-1014-ND/7604616)|HV-5RGB60|LED RGB DIFFUSED 5MM T/H 9 | |1|[450-1650-ND](https://www.digikey.com/product-detail/en/te-connectivity-alcoswitch-switches/1825910-6/450-1650-ND/1632536)|1825910-6|SWITCH TACTILE SPST-NO 0.05A 24V 10 | |3|[ED3054-5-ND](https://www.digikey.com/product-detail/en/on-shore-technology-inc/ED20DT/ED3054-5-ND/4147598)|ED20DT|CONN IC DIP SOCKET 20POS TIN 11 | |1|[ED10530-ND](https://www.digikey.com/product-detail/en/on-shore-technology-inc/302-S501/ED10530-ND/2794241)|302-S501|CONN HEADER VERT 50POS 2.54MM 12 | |1|[HDR100IMP40F-G-V-TH-ND](https://www.digikey.com/product-detail/en/chip-quik-inc/HDR100IMP40F-G-V-TH/HDR100IMP40F-G-V-TH-ND/5978200)|HDR100IMP40F-G-V-TH|CONN HDR 40POS 0.1 GOLD PCB 13 | |4|[490-8809-ND](https://www.digikey.com/short/pvj15w)|RDER71E104K0P1H03B|CAP CER 0.1UF 25V X7R RADIAL 14 | 15 | -------------------------------------------------------------------------------- /doc/rs_bodge_fix.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pski/trsnic/6ae25e1bb3c1a476fea5f019afc2290e951aeb3e/doc/rs_bodge_fix.jpg -------------------------------------------------------------------------------- /doc/rs_fix.md: -------------------------------------------------------------------------------- 1 | ### RetroStoreCard Wiring Fix 2 | 3 | If you have the original RetroStoreCard it can be made compatible with TRS-IO by adding a number of bodge wires. 4 | 5 | 6 | 7 | 8 | The original RetroStoreCard looks like the one above. If you have one of these, then you need to add the following wire connections to bring it up to spec with TRS-IO. 9 | 10 | 11 | 12 | #### Wire Table 13 | 14 | |From |To| 15 | |:---|:---| 16 | |ESP 23| IC3 15 17 | |ESP 24| IC3 13 18 | |ESP 25| IC3 14 19 | |ESP 26| IC3 11 20 | |ESP 27| IC3 12 21 | |IC1 6| IC3 6 22 | |IC1 7| IC3 7 23 | |IC1 8| IC3 8 24 | |IC1 9| IC3 9 25 | |IC1 16| IC3 5 26 | 27 | 28 | -------------------------------------------------------------------------------- /doc/rsc-architecture.odg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pski/trsnic/6ae25e1bb3c1a476fea5f019afc2290e951aeb3e/doc/rsc-architecture.odg -------------------------------------------------------------------------------- /doc/rsc-architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pski/trsnic/6ae25e1bb3c1a476fea5f019afc2290e951aeb3e/doc/rsc-architecture.png -------------------------------------------------------------------------------- /doc/rsc.odg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pski/trsnic/6ae25e1bb3c1a476fea5f019afc2290e951aeb3e/doc/rsc.odg -------------------------------------------------------------------------------- /doc/rsc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pski/trsnic/6ae25e1bb3c1a476fea5f019afc2290e951aeb3e/doc/rsc.png -------------------------------------------------------------------------------- /doc/rsclient-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pski/trsnic/6ae25e1bb3c1a476fea5f019afc2290e951aeb3e/doc/rsclient-1.png -------------------------------------------------------------------------------- /doc/trs-io-architecture.odg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pski/trsnic/6ae25e1bb3c1a476fea5f019afc2290e951aeb3e/doc/trs-io-architecture.odg -------------------------------------------------------------------------------- /doc/trs-io-architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pski/trsnic/6ae25e1bb3c1a476fea5f019afc2290e951aeb3e/doc/trs-io-architecture.png -------------------------------------------------------------------------------- /doc/trs-io-card-v1-labels.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pski/trsnic/6ae25e1bb3c1a476fea5f019afc2290e951aeb3e/doc/trs-io-card-v1-labels.png -------------------------------------------------------------------------------- /doc/trs-io-card-v1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pski/trsnic/6ae25e1bb3c1a476fea5f019afc2290e951aeb3e/doc/trs-io-card-v1.png -------------------------------------------------------------------------------- /doc/trs-io-web-ui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pski/trsnic/6ae25e1bb3c1a476fea5f019afc2290e951aeb3e/doc/trs-io-web-ui.png -------------------------------------------------------------------------------- /examples/trs-fs/CAT.BAS: -------------------------------------------------------------------------------- 1 | 10 REM THIS IS A TEST OF TRS_FS 2 | 20 PRINT "ENTER FILE NAME ";:INPUT Q$ 3 | 30 OUT 236,16 :REM ENABLE MODEL III BUS 4 | 40 OUT 31,4 5 | 50 OUT 31,1 :REM OPEN COMMAND 6 | 60 L = LEN(Q$) 7 | 70 FOR T = 1 TO L:T$=MID$(Q$,T,1):OUT 31,ASC(T$):NEXT T 8 | 80 OUT 31,0 9 | 90 OUT 31,1 :REM READ 10 | 100 GOSUB 1000 11 | 110 Y=INP(31) :REM GET THE STATUS 12 | 120 IF Y <> 0 THEN PRINT "ERROR OPENING FILE": END 13 | 130 FD=INP(31) :REM STORE THE FILE DESCRIPTOR 14 | 140 REM READ FROM FILE 15 | 150 OUT 31,4 16 | 160 OUT 31,3 17 | 170 OUT 31,FD 18 | 180 OUT 31,255:OUT 31,255:OUT 31,0:OUT 31,0 :REM DATA LENGTH REQUESTED 19 | 190 GOSUB 1000 20 | 200 Y = INP(31) 21 | 210 IF Y <> 0 THEN PRINT "ERROR READING": GOTO 500 22 | 220 L1 = INP(31):L2 = INP(31):L3 = INP(31):L4 = INP(31) 23 | 230 L = (L2 * 256) + L1 24 | 240 FOR T = 1 TO L: Y=INP(31): PRINT CHR$(Y);:NEXT T 25 | 500 REM CLOSE 26 | 505 OUT 31,4 27 | 510 OUT 31,4 28 | 520 OUT 31,FD 29 | 525 GOSUB 1000 30 | 530 Y = INP(31) 31 | 540 IF Y <> 0 THEN PRINT "ERROR ON CLOSE" 32 | 550 END 33 | 1000 IF (INP(224) AND 8) <> 0 THEN GOTO 1000 34 | 1010 RETURN 35 | -------------------------------------------------------------------------------- /examples/trs-nic/WHOIS.BAS: -------------------------------------------------------------------------------- 1 | 10 REM THIS IS A TEST OF TRSNIC CONNECTING TO WHOIS 2 | 12 H$ = "whois.iana.org" 3 | 15 REM OPEN A TCP/IP SOCKET 4 | 20 OUT 236,16 :REM ENABLE MODEL III BUS 5 | 25 OUT 31,1 6 | 30 OUT 31,1 :REM SOCKET COMMAND 7 | 40 OUT 31,1 :REM USE IPV4 8 | 50 OUT 31,1 :REM 9 | 57 GOSUB 1000 10 | 60 Y=INP(31) :REM GET THE STATUS 11 | 70 IF Y <> 0 THEN PRINT "ERROR OPENING SOCKET": GOTO 500 12 | 80 SOCKFD=INP(31) :REM STORE THE SOCKET FILE DESCRIPTOR 13 | 90 PRINT "THE SOCKET IS OPEN " 14 | 100 REM CONNECT TO THE SERVER 15 | 105 OUT 31,1 16 | 110 OUT 31,3 :REM CONNECT COMMAND 17 | 115 OUT 31,SOCKFD 18 | 117 L = LEN(H$) 19 | 118 FOR T = 1 TO L 20 | 119 T$ = MID$(H$,T,1) 21 | 120 OUT 31,ASC(T$) 22 | 121 NEXT T 23 | 122 OUT 31,0 :REM NULL ENDS HOSTNAME 24 | 123 OUT 31,43 :REM PORT LSB 25 | 124 OUT 31,0 :REM PORT MSB 26 | 125 GOSUB 1000 27 | 130 Y = INP(31) 28 | 140 IF Y <> 0 THEN PRINT "ERROR CONNECTING TO WHOIS SERVER": GOTO 500 29 | 150 PRINT "YOU ARE CONNECTED TO WHOIS SERVER" 30 | 160 REM SEND QUERY 31 | 165 INPUT Q$ 32 | 166 L = LEN(Q$) 33 | 167 OUT 31,1 34 | 170 OUT 31,4 35 | 171 OUT 31,SOCKFD 36 | 172 OUT 31,L+2:OUT 31,0: OUT 31,0: OUT 31,0 37 | 180 FOR T = 1 TO L:T$=MID$(Q$,T,1):OUT 31,ASC(T$):NEXT T 38 | 184 OUT 31,13 39 | 185 OUT 31,10 40 | 186 GOSUB 1000 41 | 187 FOR T = 1 TO 5: Y=INP(31): NEXT T 42 | 190 PRINT "RECEIVING DATA FROM WHOIS..." 43 | 200 REM RECEIVE THE DATA 44 | 201 OUT 31,1 45 | 202 OUT 31,6 46 | 204 OUT 31,SOCKFD 47 | 206 OUT 31,0 :REM USE BLOCKING FOR NIST DAYTIME SERVICE 48 | 208 OUT 31,255:OUT 31,255:OUT 31,0:OUT 31,0 :REM DATA LENGTH REQUESTED 49 | 210 GOSUB 1000 50 | 220 Y = INP(31) 51 | 230 IF Y <> 0 THEN PRINT "ERROR RECEIVING": GOTO 500 52 | 240 L1 = INP(31):L2 = INP(31):L3 = INP(31):L4 = INP(31) 53 | 250 L = (L2 * 256) + L1 54 | 260 FOR T = 1 TO L: Y=INP(31): PRINT CHR$(Y);:NEXT T 55 | 300 PRINT 56 | 310 PRINT "...DONE RECEIVING DATA FROM WHOIS" 57 | 500 REM CLOSE 58 | 505 OUT 31,1 59 | 510 OUT 31,8 60 | 520 OUT 31,SOCKFD 61 | 525 GOSUB 1000 62 | 530 Y = INP(31) 63 | 540 IF Y = 0 THEN PRINT "THE SOCKET IS CLOSED" ELSE PRINT "ERROR ON CLOSE" 64 | 550 END 65 | 1000 IF (INP(224) AND 8) <> 0 THEN GOTO 1000 66 | 1010 RETURN 67 | -------------------------------------------------------------------------------- /fritzing/RetroStore.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pski/trsnic/6ae25e1bb3c1a476fea5f019afc2290e951aeb3e/fritzing/RetroStore.fzz -------------------------------------------------------------------------------- /fritzing/RetroStore_gerber/RetroStore_contour.gm1: -------------------------------------------------------------------------------- 1 | G04 MADE WITH FRITZING* 2 | G04 WWW.FRITZING.ORG* 3 | G04 DOUBLE SIDED* 4 | G04 HOLES PLATED* 5 | G04 CONTOUR ON CENTER OF CONTOUR VECTOR* 6 | %ASAXBY*% 7 | %FSLAX23Y23*% 8 | %MOIN*% 9 | %OFA0B0*% 10 | %SFA1.0B1.0*% 11 | %ADD10R,3.543310X3.149610*% 12 | %ADD11C,0.008000*% 13 | %ADD10C,0.008*% 14 | %LNCONTOUR*% 15 | G90* 16 | G70* 17 | G54D10* 18 | G54D11* 19 | X4Y3146D02* 20 | X3539Y3146D01* 21 | X3539Y4D01* 22 | X4Y4D01* 23 | X4Y3146D01* 24 | D02* 25 | G04 End of contour* 26 | M02* -------------------------------------------------------------------------------- /fritzing/RetroStore_gerber/RetroStore_pnp.txt: -------------------------------------------------------------------------------- 1 | *Pick And Place List 2 | *Company= 3 | *Author= 4 | *eMail= 5 | * 6 | *Project=RetroStore 7 | *Date=12:51:58 8 | *CreatedBy=Fritzing 0.9.3b.04.19.5c895d327c44a3114e5fcc9d8260daf0cbb52806 9 | * 10 | * 11 | *Coordinates in mm, always center of component 12 | *Origin 0/0=Lower left corner of PCB 13 | *Rotation in degree (0-360, math. pos.) 14 | * 15 | *No;Value;Package;X;Y;Rotation;Side;Name 16 | 1;;;42.6401;-29.0172;0;Bottom;TXT2 17 | 2;;;27.1272;-43.1192;0;Bottom;Via27 18 | 3;;;31.3331;-16.5608;-90;Bottom;TXT1 19 | 4;;;32.6136;-45.5576;0;Bottom;Via8 20 | 5;;;28.8154;-17.648;-90;Bottom;TXT1 21 | 6;;;21.6408;-46.7768;0;Bottom;Via18 22 | 7;;;16.6455;-54.3405;0;Bottom;TXT2 23 | 8;;;34.0486;-16.1899;-90;Bottom;TXT1 24 | 9;;5 mm [THT];23.6875;-69.4826;90;Bottom;LED1 25 | 10;;;85.6488;-56.5304;0;Bottom;Via22 26 | 11;;[THT];9.4191;-69.3331;90;Bottom;S1 27 | 12;;;85.4568;-14.2972;-90;Bottom;TXT1 28 | 13;;;81.9912;-56.5304;0;Bottom;Via21 29 | 14;;TO92;10.9663;-35.371;-90;Bottom;FET1 30 | 15;;DIP (Dual Inline) [THT];17.3375;-54.4385;-90;Bottom;IC3 31 | 16;;;41.4038;-15.078;-90;Bottom;TXT1 32 | 17;;DIP (Dual Inline) [THT];42.7376;-29.0385;-90;Bottom;IC1 33 | 18;;;59.2522;-62.0534;0;Bottom;ESP32 34 | 19;;;17.3736;-29.708;0;Bottom;Via12 35 | 20;;;14.8389;-35.3749;-90;Bottom;TXT5 36 | 21;;;28.7769;-69.4855;-90;Bottom;TXT4 37 | 22;;;52.7304;-54.092;0;Bottom;Via15 38 | 23;;;67.2447;-77.5735;0;Bottom;TXT1 39 | 24;;;32.6136;-65.0648;0;Bottom;Via4 40 | 25;;;34.4424;-68.7224;0;Bottom;Via3 41 | 26;;;60.0456;-17.516;0;Bottom;Via1 42 | 27;;;51.7841;-4.91674;0;Bottom;TXT1 43 | 28;;;51.5817;-3.3871;0;Bottom;TXT1 44 | 29;;;56.9976;-42.5096;0;Bottom;Via17 45 | 30;;;26.2136;-14.7916;-90;Bottom;TXT1 46 | 31;;;23.6846;-73.6512;0;Bottom;TXT3 47 | 32;;;8.8392;-46.1672;0;Bottom;Via25 48 | 33;;;35.052;-28.4888;0;Bottom;Via19 49 | 34;;;14.9054;-25.3029;-90;Bottom;TXT5 50 | 35;;TO92;21.1651;-35.3673;-90;Bottom;FET3 51 | 36;;;51.4606;-12.2435;0;Bottom;TXT1 52 | 37;;;72.9367;-29.0172;0;Bottom;TXT2 53 | 38;;;53.9496;-39.4616;0;Bottom;Via24 54 | 39;;;23.7799;-15.1621;-90;Bottom;TXT1 55 | 40;;;26.5176;-29.0984;0;Bottom;Via10 56 | 41;;;33.2232;-41.2904;0;Bottom;Via7 57 | 42;;;42.9768;-37.0232;0;Bottom;Via6 58 | 43;;;86.7493;-76.7473;0;Bottom;Hole1 59 | 44;;;67.3608;-41.2904;0;Bottom;Via14 60 | 45;;;38.1;-71.1608;0;Bottom;Via9 61 | 46;;;13.716;-24.2216;0;Bottom;Via11 62 | 47;;;25.2984;-36.4136;0;Bottom;Via26 63 | 48;;DIP (Dual Inline) [THT];73.2176;-29.0385;-90;Bottom;IC2 64 | 49;;;71.628;-36.4136;0;Bottom;Via5 65 | 50;;;38.9431;-15.4488;-90;Bottom;TXT1 66 | 51;;;70.4088;-38.2424;0;Bottom;Via2 67 | 52;;;21.4302;-16.274;-90;Bottom;TXT1 68 | 53;;;56.9976;-69.9416;0;Bottom;Via16 69 | 54;;;86.7493;-3.33479;0;Bottom;Hole3 70 | 55;;;23.4696;-32.756;0;Bottom;Via13 71 | 56;;;47.8536;-30.3176;0;Bottom;Via23 72 | 57;;TO92;10.9663;-25.211;-90;Bottom;FET2 73 | 58;;;36.4526;-16.1899;-90;Bottom;TXT1 74 | 59;;;3.25283;-3.33479;0;Bottom;Hole4 75 | 60;;;60.6552;-14.468;0;Bottom;Via20 76 | 61;;;3.25283;-76.7473;0;Bottom;Hole2 77 | 62;;;25.1225;-35.1436;-90;Bottom;TXT5 78 | 63;;THT;51.6276;-8.71854;90;Bottom;J1 79 | 64;;;62.7589;-14.3184;0;Bottom;TXT1 80 | -------------------------------------------------------------------------------- /fritzing/RetroStore_gerber/RetroStore_silkBottom.gbo: -------------------------------------------------------------------------------- 1 | G04 MADE WITH FRITZING* 2 | G04 WWW.FRITZING.ORG* 3 | G04 DOUBLE SIDED* 4 | G04 HOLES PLATED* 5 | G04 CONTOUR ON CENTER OF CONTOUR VECTOR* 6 | %ASAXBY*% 7 | %FSLAX23Y23*% 8 | %MOIN*% 9 | %OFA0B0*% 10 | %SFA1.0B1.0*% 11 | %ADD10R,3.543310X3.149610X3.527310X3.133610*% 12 | %ADD11C,0.008000*% 13 | %LNSILK0*% 14 | G90* 15 | G70* 16 | G54D11* 17 | X4Y3146D02* 18 | X3539Y3146D01* 19 | X3539Y4D01* 20 | X4Y4D01* 21 | X4Y3146D01* 22 | D02* 23 | G04 End of Silk0* 24 | M02* -------------------------------------------------------------------------------- /gal/.gitignore: -------------------------------------------------------------------------------- 1 | *.abs 2 | *.pdf 3 | *.sim 4 | -------------------------------------------------------------------------------- /gal/README.md: -------------------------------------------------------------------------------- 1 | ### gal 2 | 3 | This is the program that is run on the ATF16V8B GAL. There are two versions, one with FreHD support and one without. The PLD is the source code that gets compiled into the JED file using a compiler. The JED is then programmed into the GAL using a chip programmer. You only need the appropriate JED file to program the GAL, unless you want to hack TRS-IO by changing the circuit logic. 4 | 5 | **TRS-IO.jed**: Use this version if you want to use the built in FreHD support. 6 | 7 | **TRS-IO_noFreHD.jed**: Use this version if you want to use TRS-IO on the same bus with an existing hard drive, such as an OEM Radio Shack Hard Drive, a [M3SE](http://bartlettlabs.com/M3SE/index.html), a [Lo-tech IDE](https://www.lo-tech.co.uk/wiki/Lo-tech_TRS-80_IDE_Adapter_rev.2) or a standlone [FreHD](http://www.frehd.com). You cannot use the built-in FreHD in this configuration. 8 | 9 | Use a chip programmer to program the ATF16V8B with the desired JED file. The [TL866](http://www.autoelectric.cn/en/tl866_main.html) works fine for this purpose. 10 | 11 | If you want to modify the GAL program, you can get the free [WinCUPL](https://www.microchip.com/design-centers/programmable-logic/spld-cpld/tools/software/wincupl) to compile the desired PLD into a JED file. 12 | -------------------------------------------------------------------------------- /gal/TRS-IO.jed: -------------------------------------------------------------------------------- 1 |  2 | CUPL(WM) 5.0a Serial# 60008009 3 | Device g16v8as Library DLIB-h-40-2 4 | Created Fri May 10 13:29:00 2019 5 | Name TRS-IO 6 | Partno ATF16V8B 7 | Revision 02 8 | Date 02/27/2018 9 | Designer AP 10 | Company SFSU 11 | Assembly None 12 | Location None 13 | *QP20 14 | *QF2194 15 | *G0 16 | *F0 17 | *L00768 10111010101101100111011101110111 18 | *L00800 10111010101001110111011101110111 19 | *L01024 01110110101010111111111111101111 20 | *L01056 01110110101110101111111111101111 21 | *L01088 10111010101001110111011101100111 22 | *L01120 10111010101101100111011101100111 23 | *L01280 01110110101110101111111111111111 24 | *L01312 10111010101101100111011101110111 25 | *L01536 10111010101101100111011101110111 26 | *L01568 10111010101001110111011101110111 27 | *L01600 01110110101110101111111111111111 28 | *L01632 01110110101010111111111111111111 29 | *L02048 00011100010000010101010001000110 30 | *L02080 00110001001101100101011000111000 31 | *L02112 01000010111000011111111111111111 32 | *L02144 11111111111111111111111111111111 33 | *L02176 111111111111111110 34 | *C2E35 35 | *D003 -------------------------------------------------------------------------------- /gal/TRS-IO.pld: -------------------------------------------------------------------------------- 1 | Name TRS-IO; 2 | Partno ATF16V8B; 3 | Date 02/27/2018; 4 | Rev 02; 5 | Designer AP; 6 | Company SFSU; 7 | Assembly None; 8 | Location None; 9 | Device g16v8a; 10 | 11 | /* Inputs */ 12 | Pin [2..9] = [A7..0]; 13 | Pin 17 = !RD_N; 14 | Pin 18 = !WR_N; 15 | Pin 19 = !IORQ_N; 16 | Pin 12 = !ESP_WAIT_N; 17 | 18 | /* Outputs */ 19 | Pin 14 = EXTIO_SEL; 20 | Pin 15 = WAIT; 21 | Pin 13 = !ESP_SEL_N; 22 | Pin 16 = ESP_SEL_TRS_IO; 23 | 24 | 25 | /* Equations */ 26 | io_bus_sel = IORQ_N & (RD_N # WR_N); 27 | 28 | /* ESP is selected at port 31 for TRS-IO */ 29 | esp_sel_trs_io = !A7 & !A6 & !A5 & A4 & A3 & A2 & A1 & A0 & io_bus_sel; 30 | ESP_SEL_TRS_IO = esp_sel_trs_io; 31 | 32 | /* ESP is selected at ports 0xC0-0xCF for FreHD */ 33 | esp_sel_frehd = A7 & A6 & !A5 & !A4 & io_bus_sel; 34 | 35 | /* ESP is selected at either TRS-IO or FreHD ports */ 36 | esp_sel = esp_sel_trs_io # esp_sel_frehd; 37 | ESP_SEL_N = esp_sel; 38 | 39 | /* ESP_WAIT_N is generated by the ESP */ 40 | WAIT = esp_sel & ESP_WAIT_N; 41 | 42 | /* EXTIO_SEL_N allows the TRS-80 to read */ 43 | EXTIO_SEL = esp_sel & RD_N; 44 | -------------------------------------------------------------------------------- /gal/TRS-IO_noFreHD.jed: -------------------------------------------------------------------------------- 1 |  2 | CUPL(WM) 5.0a Serial# 60008009 3 | Device g16v8as Library DLIB-h-40-2 4 | Created Fri Nov 22 13:30:01 2019 5 | Name TRS-IO_NOFREHD 6 | Partno ATF16V8B 7 | Revision 03 8 | Date 11/22/2019 9 | Designer AP 10 | Company SFSU 11 | Assembly None 12 | Location None 13 | *QP20 14 | *QF2194 15 | *G0 16 | *F0 17 | *L00768 10111010101101100111011101110111 18 | *L00800 10111010101001110111011101110111 19 | *L01024 10111010101001110111011101100111 20 | *L01056 10111010101101100111011101100111 21 | *L01280 10111010101101100111011101110111 22 | *L01536 10111010101101100111011101110111 23 | *L01568 10111010101001110111011101110111 24 | *L02048 00011100010000010101010001000110 25 | *L02080 00110001001101100101011000111000 26 | *L02112 01000010111000011111111111111111 27 | *L02144 11111111111111111111111111111111 28 | *L02176 111111111111111110 29 | *C1F68 30 | *ABB3 -------------------------------------------------------------------------------- /gal/TRS-IO_noFreHD.pld: -------------------------------------------------------------------------------- 1 | Name TRS-IO_NOFREHD; 2 | Partno ATF16V8B; 3 | Date 11/22/2019; 4 | Rev 03; 5 | Designer AP; 6 | Company SFSU; 7 | Assembly None; 8 | Location None; 9 | Device g16v8a; 10 | 11 | /* Inputs */ 12 | Pin [2..9] = [A7..0]; 13 | Pin 17 = !RD_N; 14 | Pin 18 = !WR_N; 15 | Pin 19 = !IORQ_N; 16 | Pin 12 = !ESP_WAIT_N; 17 | 18 | /* Outputs */ 19 | Pin 14 = EXTIO_SEL; 20 | Pin 15 = WAIT; 21 | Pin 13 = !ESP_SEL_N; 22 | Pin 16 = ESP_SEL_TRS_IO; 23 | 24 | 25 | /* Equations */ 26 | io_bus_sel = IORQ_N & (RD_N # WR_N); 27 | 28 | /* ESP is selected at port 31 for TRS-IO */ 29 | esp_sel_trs_io = !A7 & !A6 & !A5 & A4 & A3 & A2 & A1 & A0 & io_bus_sel; 30 | ESP_SEL_TRS_IO = esp_sel_trs_io; 31 | 32 | /* ESP is selected at the TRS-IO port only! */ 33 | esp_sel = esp_sel_trs_io; 34 | ESP_SEL_N = esp_sel; 35 | 36 | /* ESP_WAIT_N is generated by the ESP */ 37 | WAIT = esp_sel & ESP_WAIT_N; 38 | 39 | /* EXTIO_SEL_N allows the TRS-80 to read */ 40 | EXTIO_SEL = esp_sel & RD_N; 41 | -------------------------------------------------------------------------------- /kicad/v1/HiLetgoESP32s.dcm: -------------------------------------------------------------------------------- 1 | EESchema-DOCLIB Version 2.0 2 | # 3 | #End Doc Library 4 | -------------------------------------------------------------------------------- /kicad/v1/TRSIO-B.SilkS.gbr: -------------------------------------------------------------------------------- 1 | G04 #@! TF.FileFunction,Legend,Bot* 2 | %FSLAX46Y46*% 3 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 4 | G04 Created by KiCad (PCBNEW 4.0.7) date 07/07/19 07:38:13* 5 | %MOMM*% 6 | %LPD*% 7 | G01* 8 | G04 APERTURE LIST* 9 | %ADD10C,0.100000*% 10 | G04 APERTURE END LIST* 11 | D10* 12 | M02* 13 | -------------------------------------------------------------------------------- /kicad/v1/TRSIO-Edge.Cuts.gbr: -------------------------------------------------------------------------------- 1 | G04 #@! TF.FileFunction,Profile,NP* 2 | %FSLAX46Y46*% 3 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 4 | G04 Created by KiCad (PCBNEW 4.0.7) date 07/07/19 07:38:13* 5 | %MOMM*% 6 | %LPD*% 7 | G01* 8 | G04 APERTURE LIST* 9 | %ADD10C,0.100000*% 10 | %ADD11C,0.150000*% 11 | G04 APERTURE END LIST* 12 | D10* 13 | D11* 14 | X219075000Y-68961000D02* 15 | X125730000Y-68961000D01* 16 | X219075000Y-140970000D02* 17 | X219075000Y-68961000D01* 18 | X125730000Y-140970000D02* 19 | X219075000Y-140970000D01* 20 | X125730000Y-68961000D02* 21 | X125730000Y-140970000D01* 22 | M02* 23 | -------------------------------------------------------------------------------- /kicad/v1/TRSIO-NPTH.drl: -------------------------------------------------------------------------------- 1 | M48 2 | ;DRILL file {KiCad 4.0.7} date 07/07/19 07:38:17 3 | ;FORMAT={-:-/ absolute / inch / decimal} 4 | FMAT,2 5 | INCH,TZ 6 | T1C0.126 7 | % 8 | G90 9 | G05 10 | M72 11 | T1 12 | X5.15Y-2.9 13 | X5.15Y-5.35 14 | X8.45Y-2.9 15 | X8.45Y-5.35 16 | T0 17 | M30 18 | -------------------------------------------------------------------------------- /kicad/v1/TRSIO.dcm: -------------------------------------------------------------------------------- 1 | EESchema-DOCLIB Version 2.0 2 | # 3 | $CMP GAL16V8 4 | D Programmable Logic Array, DIP-20/SOIC-20/PLCC-20 5 | K GAL PLD 16V8 6 | $ENDCMP 7 | # 8 | #End Doc Library 9 | -------------------------------------------------------------------------------- /kicad/v1/TRSIO.lib: -------------------------------------------------------------------------------- 1 | EESchema-LIBRARY Version 2.3 2 | #encoding utf-8 3 | # 4 | # GAL16V8 5 | # 6 | DEF GAL16V8 U 0 40 Y Y 1 F N 7 | F0 "U" -350 650 50 H V L CNN 8 | F1 "GAL16V8" 50 650 50 H V L CNN 9 | F2 "" 0 0 50 H I C CNN 10 | F3 "" 0 0 50 H I C CNN 11 | $FPLIST 12 | DIP* 13 | PDIP* 14 | SOIC* 15 | SO* 16 | PLCC* 17 | $ENDFPLIST 18 | DRAW 19 | X GND 10 0 -600 0 U 50 50 0 0 W 20 | X VCC5 20 0 600 0 D 50 50 0 0 W 21 | S -350 600 350 -600 0 1 10 f 22 | X I1/CLK 1 -500 500 150 R 50 50 1 1 I 23 | X I2 2 -500 400 150 R 50 50 1 1 I 24 | X I3 3 -500 300 150 R 50 50 1 1 I 25 | X I4 4 -500 200 150 R 50 50 1 1 I 26 | X I5 5 -500 100 150 R 50 50 1 1 I 27 | X I6 6 -500 0 150 R 50 50 1 1 I 28 | X I7 7 -500 -100 150 R 50 50 1 1 I 29 | X I8 8 -500 -200 150 R 50 50 1 1 I 30 | X I9 9 -500 -300 150 R 50 50 1 1 I 31 | X I10/~OE~ 11 -500 -400 150 R 50 50 1 1 I 32 | X IO8 12 500 -200 150 L 50 50 1 1 T 33 | X IO7 13 500 -100 150 L 50 50 1 1 T 34 | X IO6 14 500 0 150 L 50 50 1 1 T 35 | X IO5 15 500 100 150 L 50 50 1 1 T 36 | X IO4 16 500 200 150 L 50 50 1 1 T 37 | X I03 17 500 300 150 L 50 50 1 1 T 38 | X IO2 18 500 400 150 L 50 50 1 1 T 39 | X IO1 19 500 500 150 L 50 50 1 1 T 40 | ENDDRAW 41 | ENDDEF 42 | # 43 | #End Library 44 | -------------------------------------------------------------------------------- /kicad/v1/TRSIO.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pski/trsnic/6ae25e1bb3c1a476fea5f019afc2290e951aeb3e/kicad/v1/TRSIO.pdf -------------------------------------------------------------------------------- /kicad/v1/TRSIO.pro: -------------------------------------------------------------------------------- 1 | update=16/06/2019 7:10:19 PM 2 | version=1 3 | last_client=kicad 4 | [pcbnew] 5 | version=1 6 | LastNetListRead= 7 | UseCmpFile=1 8 | PadDrill=0.600000000000 9 | PadDrillOvalY=0.600000000000 10 | PadSizeH=1.500000000000 11 | PadSizeV=1.500000000000 12 | PcbTextSizeV=1.500000000000 13 | PcbTextSizeH=1.500000000000 14 | PcbTextThickness=0.300000000000 15 | ModuleTextSizeV=1.000000000000 16 | ModuleTextSizeH=1.000000000000 17 | ModuleTextSizeThickness=0.150000000000 18 | SolderMaskClearance=0.000000000000 19 | SolderMaskMinWidth=0.000000000000 20 | DrawSegmentWidth=0.200000000000 21 | BoardOutlineThickness=0.100000000000 22 | ModuleOutlineThickness=0.150000000000 23 | [cvpcb] 24 | version=1 25 | NetIExt=net 26 | [general] 27 | version=1 28 | [eeschema] 29 | version=1 30 | LibDir= 31 | [eeschema/libraries] 32 | LibName1=TRSIO 33 | LibName2=power 34 | LibName3=device 35 | LibName4=switches 36 | LibName5=relays 37 | LibName6=motors 38 | LibName7=transistors 39 | LibName8=conn 40 | LibName9=linear 41 | LibName10=regul 42 | LibName11=74xx 43 | LibName12=cmos4000 44 | LibName13=adc-dac 45 | LibName14=memory 46 | LibName15=xilinx 47 | LibName16=microcontrollers 48 | LibName17=dsp 49 | LibName18=microchip 50 | LibName19=analog_switches 51 | LibName20=motorola 52 | LibName21=texas 53 | LibName22=intel 54 | LibName23=audio 55 | LibName24=interface 56 | LibName25=digital-audio 57 | LibName26=philips 58 | LibName27=display 59 | LibName28=cypress 60 | LibName29=siliconi 61 | LibName30=opto 62 | LibName31=atmel 63 | LibName32=contrib 64 | LibName33=valves 65 | LibName34=logic_programmable 66 | LibName35=HiLetgoESP32s 67 | LibName36=Power_Management 68 | [schematic_editor] 69 | version=1 70 | PageLayoutDescrFile= 71 | PlotDirectoryName= 72 | SubpartIdSeparator=0 73 | SubpartFirstId=65 74 | NetFmtName=Pcbnew 75 | SpiceForceRefPrefix=0 76 | SpiceUseNetNumbers=0 77 | LabSize=60 78 | -------------------------------------------------------------------------------- /kicad/v1/fp-lib-table: -------------------------------------------------------------------------------- 1 | (fp_lib_table 2 | (lib (name HiLetGoESP32s)(type KiCad)(uri ${KIPRJMOD}/HiLetGoESP32s.pretty)(options "")(descr "")) 3 | (lib (name TRSIO)(type KiCad)(uri ${KIPRJMOD}/TRSIO.pretty)(options "")(descr "")) 4 | ) 5 | -------------------------------------------------------------------------------- /src/Makefile: -------------------------------------------------------------------------------- 1 | 2 | MAKE = make 3 | 4 | DIRS = ihex2cmd loader trs esp modules 5 | 6 | 7 | all: 8 | for i in $(DIRS); do echo "\n>>> Running $(MAKE) on [$$i] <<<"; $(MAKE) -C $$i || exit 1; done 9 | 10 | clean: 11 | for i in $(DIRS); do $(MAKE) -C $$i clean || exit 1; done 12 | -------------------------------------------------------------------------------- /src/esp/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | sdkconfig.old 3 | 4 | -------------------------------------------------------------------------------- /src/esp/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | retrostore 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.core.ccnature 24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/esp/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/esp/.settings/org.eclipse.cdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | environment/project/cdt.managedbuild.toolchain.gnu.cross.base.1528323475/BATCH_BUILD/delimiter=\: 3 | environment/project/cdt.managedbuild.toolchain.gnu.cross.base.1528323475/BATCH_BUILD/operation=append 4 | environment/project/cdt.managedbuild.toolchain.gnu.cross.base.1528323475/BATCH_BUILD/value=1 5 | environment/project/cdt.managedbuild.toolchain.gnu.cross.base.1528323475/IDF_PATH/delimiter=\: 6 | environment/project/cdt.managedbuild.toolchain.gnu.cross.base.1528323475/IDF_PATH/operation=append 7 | environment/project/cdt.managedbuild.toolchain.gnu.cross.base.1528323475/IDF_PATH/value=/home/arno/git/esp32/esp-idf 8 | environment/project/cdt.managedbuild.toolchain.gnu.cross.base.1528323475/append=true 9 | environment/project/cdt.managedbuild.toolchain.gnu.cross.base.1528323475/appendContributed=true 10 | -------------------------------------------------------------------------------- /src/esp/Makefile: -------------------------------------------------------------------------------- 1 | 2 | PROJECT_NAME := trs-io 3 | 4 | include $(IDF_PATH)/make/project.mk 5 | 6 | -------------------------------------------------------------------------------- /src/esp/components/frehd/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main component makefile. 3 | # 4 | # This Makefile can be left empty. By default, it will take the sources in the 5 | # src/ directory, compile them and link them into lib(subdirectory_name).a 6 | # in the build directory. This behaviour is entirely configurable, 7 | # please read the ESP-IDF documents if you need to do this. 8 | # 9 | 10 | COMPONENT_ADD_LDFLAGS=-Wl,--whole-archive build/$(COMPONENT_NAME)/lib$(COMPONENT_NAME).a -Wl,--no-whole-archive 11 | 12 | -------------------------------------------------------------------------------- /src/esp/components/frehd/frehd.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include "trs_hard.h" 5 | #include "trs_extra.h" 6 | #include "action.h" 7 | #include "fileio.h" 8 | 9 | //#define RUN_FILE_IO_TESTS 10 | void test_file_io(); 11 | 12 | /* Global variables */ 13 | Drive state_d[TRS_HARD_MAXDRIVES]; 14 | FIL state_file2; 15 | #if EXTRA_IM_SUPPORT 16 | #if _USE_FASTSEEK 17 | DWORD im_stbl[FAST_SEEK_LEN]; 18 | #endif 19 | FIL im_file; 20 | BYTE im_buf[0x80]; 21 | #endif 22 | BYTE sector_buffer[MAX_SECTOR_SIZE]; 23 | #if EXTRA_IM_SUPPORT 24 | image_t im[8]; 25 | #endif 26 | 27 | BYTE extra_buffer[EXTRA_SIZE]; 28 | DIR_ state_dir; 29 | FILINFO state_fno; 30 | UCHAR state_dir_open; 31 | UCHAR state_file2_open; 32 | UCHAR fs_mounted; 33 | UCHAR cur_unit; 34 | UCHAR led_count; 35 | 36 | BYTE action_flags; 37 | BYTE action_type; 38 | BYTE action_status; 39 | UCHAR state_busy; 40 | UCHAR state_status; 41 | UCHAR state_present; 42 | UCHAR state_control; 43 | UCHAR state_error; 44 | UCHAR state_seccnt; 45 | UCHAR state_secnum; 46 | USHORT state_cyl; 47 | UCHAR state_drive; 48 | UCHAR state_head; 49 | UCHAR state_wp; 50 | UCHAR state_command; 51 | USHORT state_bytesdone; 52 | UCHAR state_secsize; 53 | USHORT state_secsize16; 54 | UCHAR state_command2; 55 | UCHAR state_error2; 56 | USHORT state_size2; 57 | USHORT state_bytesdone2; 58 | UCHAR state_romdone; 59 | UCHAR state_rom; 60 | UCHAR val_1F; 61 | UCHAR crc7; 62 | USHORT crc16; 63 | UCHAR foo; 64 | 65 | void pic_init(void) 66 | { 67 | /* globals init */ 68 | val_1F = 0x1F; 69 | action_flags = 0; 70 | fs_mounted = FS_NOT_MOUNTED; 71 | state_file2_open = 0; 72 | state_dir_open = 0; 73 | for (int i = 0; i < TRS_HARD_MAXDRIVES; i++) { 74 | state_d[i].filename[0] = '\0'; 75 | } 76 | } 77 | 78 | void frehd_check_action() 79 | { 80 | if (action_flags & ACTION_TRS) { 81 | action_flags &= ~ACTION_TRS; 82 | trs_action(); 83 | } 84 | } 85 | 86 | void init_frehd() 87 | { 88 | pic_init(); 89 | frehd_init(); 90 | 91 | #ifdef RUN_FILE_IO_TESTS 92 | test_file_io(); 93 | #endif 94 | 95 | /* Set READY status */ 96 | state_busy = 0; 97 | update_status(TRS_HARD_READY); 98 | } 99 | 100 | void frehd_main(void) 101 | { 102 | while (1) { 103 | /* hard drive and extra functions actions */ 104 | frehd_check_action(); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/esp/components/frehd/include/action.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Frederic Vecoven 3 | * 4 | * This file is part of trs_hard 5 | * 6 | * trs_hard is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * trs_hard is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef _ACTION_H 21 | #define _ACTION_H 22 | 23 | #include "integer.h" 24 | 25 | #define ACTION_DS1307_RELOAD 0x01 26 | #define ACTION_TICK 0x02 27 | #define ACTION_TRS 0x04 28 | 29 | 30 | /* hard drive actions */ 31 | #define ACTION_HARD_SEEK 0x1 32 | #define ACTION_HARD_READ 0x2 33 | #define ACTION_HARD_WRITE 0x3 34 | 35 | /* extra function actions : 0x80 + command2 */ 36 | #define ACTION_EXTRA 0x80 37 | 38 | 39 | extern BYTE action_flags; 40 | extern BYTE action_type; 41 | extern BYTE action_status; 42 | 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /src/esp/components/frehd/include/frehd.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __FREHD_H__ 3 | #define __FREHD_H__ 4 | 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | void frehd_check_action(); 12 | void init_frehd(); 13 | uint8_t frehd_in(uint8_t p); 14 | void frehd_out(uint8_t p, uint8_t v); 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /src/esp/components/frehd/include/integer.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __INTEGER_H__ 3 | #define __INTEGER_H__ 4 | 5 | #include 6 | 7 | typedef uint8_t Uchar; 8 | typedef uint8_t UCHAR; 9 | typedef char CHAR; 10 | typedef uint8_t BYTE; 11 | typedef uint16_t UINT; 12 | typedef uint16_t USHORT; 13 | typedef uint32_t DWORD; 14 | typedef int16_t WORD; 15 | 16 | #endif 17 | 18 | -------------------------------------------------------------------------------- /src/esp/components/frehd/include/loader_xtrs.h: -------------------------------------------------------------------------------- 1 | static unsigned char loader[] = { 2 | 0xfe, 0xfe, 0xff, 0x18, 0x02, 0x18, 0x19, 0x3a, 3 | 0x40, 0x38, 0xe6, 0x80, 0xc0, 0x11, 0x16, 0x50, 4 | 0x06, 0x09, 0xcd, 0x1f, 0x50, 0xc0, 0xe9, 0x46, 5 | 0x52, 0x45, 0x48, 0x44, 0x2e, 0x52, 0x4f, 0x4d, 6 | 0x21, 0x00, 0x00, 0x39, 0xe5, 0xdd, 0xe1, 0xeb, 7 | 0x3e, 0x03, 0xd3, 0xc4, 0xcd, 0xa4, 0x50, 0x78, 8 | 0x3c, 0x3c, 0xd3, 0xc3, 0x0e, 0xc2, 0x3e, 0x01, 9 | 0xed, 0x79, 0xed, 0xb3, 0xaf, 0xed, 0x79, 0xcd, 10 | 0xa4, 0x50, 0xc0, 0x0e, 0xff, 0xcd, 0x7f, 0x50, 11 | 0x3d, 0x20, 0x0c, 0xcd, 0x70, 0x50, 0xcd, 0x7f, 12 | 0x50, 0x77, 0x23, 0x10, 0xf9, 0x18, 0xee, 0x3d, 13 | 0x28, 0x0b, 0xcd, 0x7f, 0x50, 0x47, 0xcd, 0x7f, 14 | 0x50, 0x10, 0xfb, 0x18, 0xe0, 0xcd, 0x70, 0x50, 15 | 0x3e, 0x06, 0xd3, 0xc4, 0xcd, 0xa4, 0x50, 0xaf, 16 | 0xc9, 0xcd, 0x7f, 0x50, 0x47, 0xcd, 0x7f, 0x50, 17 | 0x6f, 0x05, 0xcd, 0x7f, 0x50, 0x67, 0x05, 0xc9, 18 | 0x0c, 0x20, 0x03, 0xcd, 0x88, 0x50, 0xdb, 0xc2, 19 | 0xc9, 0xaf, 0xd3, 0xc3, 0x3e, 0x04, 0xd3, 0xc4, 20 | 0xcd, 0xa4, 0x50, 0x20, 0x05, 0xdb, 0xcf, 0xe6, 21 | 0x08, 0xc0, 0x3e, 0x06, 0xd3, 0xc4, 0xcd, 0xa4, 22 | 0x50, 0xdd, 0xf9, 0x3c, 0xc9, 0xdb, 0xcf, 0x07, 23 | 0x38, 0xfb, 0xdb, 0xcf, 0xe6, 0x01, 0xc9, 0xff, 24 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 25 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 26 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 27 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 28 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 29 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 30 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 31 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 32 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 33 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 34 | }; 35 | -------------------------------------------------------------------------------- /src/esp/components/frehd/include/reed.h: -------------------------------------------------------------------------------- 1 | /* Matthew Reed's hard drive format. Thanks to Matthew for providing 2 | documentation. The comments below are copied from his mail 3 | messages, with some additions. */ 4 | 5 | /* see http://www.trs-80emulators.com/hdv1-format/ */ 6 | 7 | #ifndef _REED_H 8 | #define _REED_H 9 | 10 | #include "integer.h" 11 | 12 | typedef struct { 13 | UCHAR id1; /* 0: Identifier #1: 56H */ 14 | UCHAR id2; /* 1: Identifier #2: CBH */ 15 | UCHAR ver; /* 2: Version of format: 10H = version 1.0 */ 16 | UCHAR cksum; /* 3: Simple checksum: 17 | To calculate, add together bytes 0 to 31 of header 18 | (excepting byte 3), then XOR result with 4CH */ 19 | UCHAR blks; /* 4: Number of 256 byte blocks in header: should be 1 */ 20 | UCHAR mb4; /* 5: Not used, but HDFORMAT sets to 4 */ 21 | UCHAR media; /* 6: Media type: 0 for hard disk */ 22 | UCHAR flag1; /* 7: Flags #1: 23 | bit 7: Write protected: 0 for no, 1 for yes 24 | [xtrshard/dct ignores for now] 25 | bit 6: Must be 0 26 | bit 5 - 0: reserved */ 27 | UCHAR flag2; /* 8: Flags #2: reserved */ 28 | UCHAR flag3; /* 9: Flags #3: reserved */ 29 | UCHAR crtr; /* 10: Created by: 30 | 14H = HDFORMAT 31 | 42H = xtrs mkdisk 32 | 80H = Cervasio xtrshard port to Vavasour M4 emulator */ 33 | UCHAR dfmt; /* 11: Disk format: 0 = LDOS/LS-DOS */ 34 | UCHAR mm; /* 12: Creation month: mm */ 35 | UCHAR dd; /* 13: Creation day: dd */ 36 | UCHAR yy; /* 14: Creation year: yy (offset from 1900) */ 37 | UCHAR res1[11]; /* 15 - 25: reserved */ 38 | UCHAR heads; /* 26: Heads */ 39 | UCHAR dparm; /* 27: Disk parameters: (unused with hard drives) 40 | bit 7: Density: 0 = double, 1 = single 41 | bit 6: Sides: 0 = one side, 1 = 2 sides 42 | bit 5: First sector: 0 if sector 0, 1 if sector 1 43 | bit 4: DAM convention: 0 if normal (LDOS), 1 if reversed (TRSDOS 1.3) 44 | bit 3 - 0: reserved */ 45 | UCHAR cyl; /* 28: Number of cylinders per disk */ 46 | UCHAR sec; /* 29: Number of sectors per track (floppy); cyl (hard) */ 47 | UCHAR gran; /* 30: Number of granules per track (floppy); cyl (hard)*/ 48 | UCHAR dcyl; /* 31: Directory cylinder [mkdisk sets to 1; xtrs ignores]*/ 49 | char label[32]; /* 32: Volume label: 31 bytes terminated by 0 */ 50 | char filename[8];/* 64 - 71: 8 characters of filename (without extension) 51 | [Cervasio addition. xtrs actually doesn't limit this 52 | to 8 chars or strip the extension] */ 53 | UCHAR autoboot[32]; /* 72-103 : autoboot data */ 54 | UCHAR res2[152]; /* 103 - 255: reserved */ 55 | } ReedHardHeader; 56 | 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/esp/components/frehd/include/socket-io.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FILEIO_SOCKET_IO_H 3 | #define FILEIO_SOCKET_IO_H 4 | 5 | #include 6 | 7 | int16_t read_byte(); 8 | void read_blob(void* buf, int32_t btr); 9 | void write_byte(uint8_t b); 10 | void write_blob(void* buf, int32_t btw); 11 | void init_socket_io(); 12 | 13 | #endif //FILEIO_SOCKET_IO_H 14 | -------------------------------------------------------------------------------- /src/esp/components/frehd/include/trs_extra.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Frederic Vecoven 3 | * 4 | * This file is part of trs_hard 5 | * 6 | * trs_hard is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * trs_hard is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef _TRS_EXTRA 21 | #define _TRS_EXTRA 22 | 23 | #define TRS_EXTRA_VERSION 0x00 24 | #define TRS_EXTRA_GETTIME 0x01 25 | #define TRS_EXTRA_SETTIME 0x02 26 | #define TRS_EXTRA_OPENFILE 0x03 27 | #define TRS_EXTRA_READFILE 0x04 28 | #define TRS_EXTRA_WRITEFILE 0x05 29 | #define TRS_EXTRA_CLOSEFILE 0x06 30 | #define TRS_EXTRA_BOOTLOADER 0x07 31 | #define TRS_EXTRA_OPENDIR 0x08 32 | #define TRS_EXTRA_READDIR 0x09 33 | #define TRS_EXTRA_MOUNTDRIVE 0x0A 34 | #define TRS_EXTRA_SEEKFILE 0x0B 35 | #define TRS_EXTRA_INFODRIVE 0x0C 36 | #define TRS_EXTRA_IMAGE 0x0D 37 | #define TRS_EXTRA_READ_HEADER 0x0E 38 | 39 | // LSDOS time : 6 bytes 40 | #define TRS80_SEC 0 41 | #define TRS80_MIN 1 42 | #define TRS80_HOUR 2 43 | #define TRS80_YEAR 3 44 | #define TRS80_DAY 4 45 | #define TRS80_MONTH 5 46 | 47 | // TRS_EXTRA_MOUNTDRIVE options 48 | #define TRS_EXTRA_MOUNT_SLOW 0x01 // no fast seek 49 | #define TRS_EXTRA_MOUNT_CREATE 0x02 // create if needed 50 | #define TRS_EXTRA_MOUNT_RO 0x04 // read-only 51 | 52 | typedef enum { 53 | IM_NONE, 54 | IM_DMK, 55 | IM_JV3, 56 | IM_JV1 57 | } im_type_t; 58 | 59 | typedef struct { 60 | USHORT tlen; 61 | UCHAR cur_track; 62 | UCHAR cur_side; 63 | UCHAR sside; // 1 if single side in header flag 64 | UCHAR sdensity; // 1 if single density in header flag 65 | UCHAR nsectors; 66 | long offset; 67 | } dmk_t; 68 | 69 | typedef struct { 70 | UCHAR nsectors; 71 | UCHAR dam; 72 | DWORD offset; 73 | } jv3_t; 74 | 75 | typedef struct { 76 | DWORD offset; 77 | } jv1_t; 78 | 79 | typedef struct { 80 | im_type_t type; 81 | char filename[13]; 82 | union { 83 | dmk_t dmk; 84 | jv3_t jv3; 85 | jv1_t jv1; 86 | } u; 87 | } image_t; 88 | 89 | 90 | extern UCHAR (*trs_extra[])(UCHAR); 91 | 92 | UCHAR trs_extra_ignored(UCHAR); 93 | UCHAR trs_extra_version(UCHAR); 94 | UCHAR trs_extra_gettime(UCHAR); 95 | UCHAR trs_extra_settime(UCHAR); 96 | UCHAR trs_extra_openfile(UCHAR); 97 | UCHAR trs_extra_readfile(UCHAR); 98 | UCHAR trs_extra_writefile(UCHAR); 99 | UCHAR trs_extra_closefile(UCHAR); 100 | UCHAR trs_extra_bootloader(UCHAR); 101 | UCHAR trs_extra_opendir(UCHAR); 102 | UCHAR trs_extra_readdir(UCHAR); 103 | UCHAR trs_extra_mountdrive(UCHAR); 104 | UCHAR trs_extra_infodrive(UCHAR); 105 | UCHAR trs_extra_seekfile(UCHAR); 106 | UCHAR trs_extra_image(UCHAR); 107 | UCHAR trs_extra_read_header(UCHAR); 108 | 109 | // dsk.c 110 | void process_image_cmd(void); 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /src/esp/components/frehd/include/trs_hard_defs.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef _TRS_HARD_DEFS_H 4 | #define _TRS_HARD_DEFS_H 5 | 6 | #define TRS_HARD_BBDERR 0x80 7 | #define TRS_HARD_DATAERR 0x40 8 | #define TRS_HARD_IDERR 0x20 9 | #define TRS_HARD_NFERR 0x10 10 | #define TRS_HARD_MCRERR 0x08 11 | #define TRS_HARD_ABRTERR 0x04 12 | #define TRS_HARD_TRK0ERR 0x02 13 | #define TRS_HARD_MARKERR 0x01 14 | 15 | #define TRS_HARD_BUSY 0x80 16 | #define TRS_HARD_READY 0x40 17 | #define TRS_HARD_WRERR 0x20 18 | #define TRS_HARD_SEEKDONE 0x10 19 | #define TRS_HARD_DRQ 0x08 20 | #define TRS_HARD_ECC 0x04 21 | #define TRS_HARD_CIP 0x02 22 | #define TRS_HARD_ERR 0x01 23 | 24 | #define TRS_HARD_CMDMASK 0xf0 25 | #define TRS_HARD_RESTORE 0x10 26 | #define TRS_HARD_READ 0x20 27 | #define TRS_HARD_DMA 0x08 28 | #define TRS_HARD_MULTI 0x04 29 | #define TRS_HARD_WRITE 0x30 30 | #define TRS_HARD_VERIFY 0x40 31 | #define TRS_HARD_FORMAT 0x50 32 | #define TRS_HARD_INIT 0x60 33 | #define TRS_HARD_SEEK 0x70 34 | 35 | 36 | #define ACTION_DS1307_RELOAD 0x01 37 | #define ACTION_DS1307_BIT 0 38 | #define ACTION_TICK 0x02 39 | #define ACTION_TICK_BIT 1 40 | #define ACTION_TRS 0x04 41 | #define ACTION_TRS_BIT 2 42 | 43 | #define ACTION_HARD_SEEK 0x1 44 | #define ACTION_HARD_READ 0x2 45 | #define ACTION_HARD_WRITE 0x3 46 | 47 | #define ACTION_EXTRA2 0x40 48 | #define ACTION_EXTRA2_BIT 6 49 | #define ACTION_EXTRA 0x80 50 | #define ACTION_EXTRA_BIT 7 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/esp/components/frehd/include/version-frehd.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _VERSION_H 3 | #define _VERSION_H 4 | 5 | #define VERSION_MAJOR 2 6 | #define VERSION_MINOR 14 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/esp/components/html/.gitignore: -------------------------------------------------------------------------------- 1 | *.c 2 | -------------------------------------------------------------------------------- /src/esp/components/html/component.mk: -------------------------------------------------------------------------------- 1 | 2 | %.c: %.html 3 | cp $< `basename $<` 4 | xxd -i `basename $<` $@ 5 | rm -f `basename $<` 6 | 7 | COMPONENT_OBJS := index.o 8 | 9 | index.c: $(COMPONENT_PATH)/index.html 10 | 11 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2) 2 | 3 | project(libsmb2 4 | LANGUAGES C 5 | VERSION 3.0.0) 6 | 7 | set(SOVERSION 1 CACHE STRING "" FORCE) 8 | 9 | set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}" CACHE PATH "Installation directory for libraries") 10 | set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers") 11 | set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files") 12 | set(INSTALL_CMAKE_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/cmake/libsmb2" CACHE PATH "Installation directory for cmake (.cmake) files") 13 | 14 | option(BUILD_SHARED_LIBS "Build shared libraries" ON) 15 | option(ENABLE_EXAMPLES "Build example programs" OFF) 16 | 17 | list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules) 18 | 19 | find_package(GSSAPI) 20 | find_package(OpenSSL) 21 | 22 | if(GSSAPI_FOUND) 23 | add_definitions(-DHAVE_LIBKRB5) 24 | endif() 25 | 26 | if(OPENSSL_FOUND) 27 | add_definitions(-DHAVE_OPENSSL_LIBS) 28 | endif() 29 | 30 | include(cmake/ConfigureChecks.cmake) 31 | 32 | include_directories(${CMAKE_CURRENT_BINARY_DIR} 33 | include 34 | include/smb2 35 | ${OPENSSL_INCLUDE_DIR}) 36 | 37 | set(core_DEPENDS ${GSSAPI_LIBRARIES} CACHE STRING "" FORCE) 38 | 39 | if(CMAKE_SYSTEM_NAME MATCHES Windows) 40 | list(APPEND CORE_LIBRARIES ws2_32.lib) 41 | add_definitions(-DWIN32_LEAN_AND_MEAN -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -DHAVE_SOCKADDR_IN6) 42 | include_directories(include/msvc) 43 | elseif(CMAKE_SYSTEM_NAME STREQUAL Solaris) 44 | find_library(SOCKET_LIBRARY socket) 45 | find_library(NSL_LIBRARY nsl) 46 | list(APPEND CORE_LIBRARIES ${SOCKET_LIBRARY} ${NSL_LIBRARY}) 47 | endif() 48 | 49 | if(ENABLE_EXAMPLES) 50 | add_subdirectory(examples) 51 | endif() 52 | 53 | add_subdirectory(lib) 54 | 55 | include(CMakePackageConfigHelpers) 56 | write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/libsmb2-config-version.cmake 57 | VERSION ${PROJECT_VERSION} 58 | COMPATIBILITY AnyNewerVersion) 59 | 60 | configure_file(cmake/libsmb2.pc.cmake 61 | ${CMAKE_CURRENT_BINARY_DIR}/libsmb2.pc @ONLY) 62 | 63 | install(DIRECTORY include/smb2 64 | DESTINATION ${INSTALL_INC_DIR}) 65 | 66 | install(FILES cmake/FindSMB2.cmake 67 | ${CMAKE_CURRENT_BINARY_DIR}/libsmb2-config-version.cmake 68 | DESTINATION ${INSTALL_CMAKE_DIR}) 69 | 70 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libsmb2.pc 71 | DESTINATION ${INSTALL_PKGCONFIG_DIR}) 72 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/COPYING: -------------------------------------------------------------------------------- 1 | Libsmb2 components fall under two separate licences 2 | 3 | 4 | The lib and include directories 5 | =============================== 6 | The smb2 client library itself, i.e. the lib and include directories, 7 | is licenced under GNU Lesser General Public License as published by 8 | the Free Software Foundation; either version 2.1 of the License, or 9 | (at your option) any later version. 10 | 11 | A copy of LGPL 2.1 is included in the file LICENCE-LGPL-2.1.txt but can also be downloaded from http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 12 | 13 | This is the licence that applies to the libsmb2 library and its use. 14 | 15 | 16 | 17 | The examples directory 18 | ====================== 19 | The example applications using this library, i.e. the examples directory, 20 | is licenced under 2-Clause BSD License. 21 | 22 | These are executable applications that link with the libsmb2 library. 23 | 24 | To avoid any confusion, every source file also contain a licence boilerplate. 25 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = include lib . $(MAYBE_EXAMPLES) 2 | ACLOCAL_AMFLAGS = -I m4 3 | 4 | pkgconfigdir = $(libdir)/pkgconfig 5 | pkgconfig_DATA = libsmb2.pc 6 | 7 | EXTRA_DIST = \ 8 | examples \ 9 | libsmb2.pc.in 10 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | autoreconf -vif 3 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/cmake/ConfigureChecks.cmake: -------------------------------------------------------------------------------- 1 | include(CheckIncludeFile) 2 | check_include_file("arpa/inet.h" HAVE_ARPA_INET_H) 3 | check_include_file("dlfcn.h" HAVE_DLFCN_H) 4 | check_include_file("gssapi/gssapi.h" HAVE_GSSAPI_GSSAPI_H) 5 | check_include_file("inttypes.h" HAVE_INTTYPES_H) 6 | check_include_file("memory.h" HAVE_MEMORY_H) 7 | check_include_file("netdb.h" HAVE_NETDB_H) 8 | check_include_file("netinet/in.h" HAVE_NETINET_IN_H) 9 | check_include_file("netinet/tcp.h" HAVE_NETINET_TCP_H) 10 | check_include_file("net/if.h" HAVE_NET_IF_H) 11 | check_include_file("poll.h" HAVE_POLL_H) 12 | check_include_file("stdint.h" HAVE_STDINT_H) 13 | check_include_file("stdlib.h" HAVE_STDLIB_H) 14 | check_include_file("strings.h" HAVE_STRINGS_H) 15 | check_include_file("string.h" HAVE_STRING_H) 16 | check_include_file("sys/filio.h" HAVE_SYS_FILIO_H) 17 | check_include_file("sys/ioctl.h" HAVE_SYS_IOCTL_H) 18 | check_include_file("sys/socket.h" HAVE_SYS_SOCKET_H) 19 | check_include_file("sys/sockio.h" HAVE_SYS_SOCKIO_H) 20 | check_include_file("sys/statvfs.h" HAVE_SYS_STATVFS_H) 21 | check_include_file("sys/stat.h" HAVE_SYS_STAT_H) 22 | check_include_file("sys/sysmacros.h" HAVE_SYS_SYSMACROS_H) 23 | check_include_file("sys/time.h" HAVE_SYS_TIME_H) 24 | check_include_file("sys/types.h" HAVE_SYS_TYPES_H) 25 | check_include_file("sys/uio.h" HAVE_SYS_UIO_H) 26 | check_include_file("sys/vfs.h" HAVE_SYS_VFS_H) 27 | check_include_file("unistd.h" HAVE_UNISTD_H) 28 | check_include_file("utime.h" HAVE_UTIME_H) 29 | check_include_file("stddef.h" STDC_HEADERS) 30 | 31 | include(CheckStructHasMember) 32 | check_struct_has_member("struct sockaddr" sa_len sys/socket.h HAVE_SOCKADDR_LEN) 33 | check_struct_has_member("struct sockaddr_storage" ss_family sys/socket.h HAVE_SOCKADDR_STORAGE) 34 | 35 | include(CheckSymbolExists) 36 | check_symbol_exists("makedev" "sys/mkdev.h" MAJOR_IN_MKDEV) 37 | check_symbol_exists("makedev" "sys/sysmacros.h" MAJOR_IN_SYSMACROS) 38 | 39 | include(CheckCCompilerFlag) 40 | if(CMAKE_COMPILER_IS_GNUCC) 41 | check_c_compiler_flag(-Wall C_ACCEPTS_WALL) 42 | 43 | if(C_ACCEPTS_WALL) 44 | add_definitions(-Wall) 45 | endif() 46 | endif() 47 | 48 | # We always want 64 bit file offsets 49 | add_definitions(-D_FILE_OFFSET_BITS=64) 50 | 51 | configure_file(cmake/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h) 52 | add_definitions(-DHAVE_CONFIG_H) 53 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/cmake/FindSMB2.cmake: -------------------------------------------------------------------------------- 1 | #.rst: 2 | # FindSMB2 3 | # ------- 4 | # Finds the libsmb2 library 5 | # 6 | # This will will define the following variables:: 7 | # 8 | # SMB2_FOUND - system has libsmb2 9 | # SMB2_INCLUDE_DIRS - the libsmb2 include directory 10 | # SMB2_LIBRARIES - the libsmb2 libraries 11 | # SMB2_DEFINITIONS - the libsmb2 compile definitions 12 | 13 | if(PKG_CONFIG_FOUND) 14 | pkg_check_modules(PC_SMB2 libsmb2 QUIET) 15 | endif() 16 | 17 | find_path(SMB2_INCLUDE_DIR smb2/libsmb2.h 18 | PATHS ${PC_SMB2_INCLUDEDIR}) 19 | 20 | set(SMB2_VERSION ${PC_SMB2_VERSION}) 21 | 22 | include(FindPackageHandleStandardArgs) 23 | 24 | find_library(SMB2_LIBRARY NAMES smb2 25 | PATHS ${PC_SMB2_LIBDIR}) 26 | 27 | find_package_handle_standard_args(SMB2 28 | REQUIRED_VARS SMB2_LIBRARY SMB2_INCLUDE_DIR 29 | VERSION_VAR SMB2_VERSION) 30 | 31 | if(SMB2_FOUND) 32 | set(SMB2_LIBRARIES ${SMB2_LIBRARY}) 33 | set(SMB2_INCLUDE_DIRS ${SMB2_INCLUDE_DIR}) 34 | set(SMB2_DEFINITIONS -DHAVE_LIBSMB2=1) 35 | endif() 36 | 37 | mark_as_advanced(SMB2_INCLUDE_DIR SMB2_LIBRARY) 38 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/cmake/Modules/FindGSSAPI.cmake: -------------------------------------------------------------------------------- 1 | #.rst: 2 | # FindGSSAPI 3 | # ------- 4 | # Finds the gssapi library 5 | # 6 | # This will will define the following variables:: 7 | # 8 | # GSSAPI_FOUND - system has gssapi 9 | # GSSAPI_INCLUDE_DIRS - the gssapi include directory 10 | # GSSAPI_LIBRARIES - the gssapi libraries 11 | 12 | find_library(GSSAPI_LIBRARY NAMES gssapi_krb5) 13 | 14 | find_path(GSSAPI_INCLUDE_DIR NAMES gssapi.h 15 | gssapi/gssapi.h) 16 | 17 | include(FindPackageHandleStandardArgs) 18 | find_package_handle_standard_args(GSSAPI 19 | REQUIRED_VARS GSSAPI_LIBRARY GSSAPI_INCLUDE_DIR) 20 | 21 | if (GSSAPI_LIBRARY AND GSSAPI_INCLUDE_DIRS) 22 | set(GSSAPI_FOUND TRUE) 23 | endif () 24 | 25 | if(GSSAPI_FOUND) 26 | set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARY}) 27 | set(GSSAPI_INCLUDE_DIRS ${GSSAPI_INCLUDE_DIR}) 28 | endif() 29 | 30 | mark_as_advanced(GSSAPI_LIBRARIES GSSAPI_INCLUDE_DIRS) 31 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/cmake/config.h.cmake: -------------------------------------------------------------------------------- 1 | /* config.h.cmake */ 2 | 3 | /* Define to 1 if you have the header file. */ 4 | #cmakedefine HAVE_ARPA_INET_H 5 | 6 | /* Define to 1 if you have the header file. */ 7 | #cmakedefine HAVE_DLFCN_H 8 | 9 | /* Define to 1 if you have the header file. */ 10 | #cmakedefine HAVE_GSSAPI_GSSAPI_H 11 | 12 | /* Define to 1 if you have the header file. */ 13 | #cmakedefine HAVE_INTTYPES_H 14 | 15 | /* Define to 1 if you have the `nsl' library (-lnsl). */ 16 | #cmakedefine HAVE_LIBNSL 17 | 18 | /* Define to 1 if you have the `socket' library (-lsocket). */ 19 | #cmakedefine HAVE_LIBSOCKET 20 | 21 | /* Define to 1 if you have the header file. */ 22 | #cmakedefine HAVE_MEMORY_H 23 | 24 | /* Define to 1 if you have the header file. */ 25 | #cmakedefine HAVE_NETDB_H 26 | 27 | /* Define to 1 if you have the header file. */ 28 | #cmakedefine HAVE_NETINET_IN_H 29 | 30 | /* Define to 1 if you have the header file. */ 31 | #cmakedefine HAVE_NETINET_TCP_H 32 | 33 | /* Define to 1 if you have the header file. */ 34 | #cmakedefine HAVE_NET_IF_H 35 | 36 | /* Define to 1 if you have the header file. */ 37 | #cmakedefine HAVE_POLL_H 38 | 39 | /* Whether sockaddr struct has sa_len */ 40 | #cmakedefine HAVE_SOCKADDR_LEN 41 | 42 | /* Whether we have sockaddr_Storage */ 43 | #cmakedefine HAVE_SOCKADDR_STORAGE 44 | 45 | /* Define to 1 if you have the header file. */ 46 | #cmakedefine HAVE_STDINT_H 47 | 48 | /* Define to 1 if you have the header file. */ 49 | #cmakedefine HAVE_STDLIB_H 50 | 51 | /* Define to 1 if you have the header file. */ 52 | #cmakedefine HAVE_STRINGS_H 53 | 54 | /* Define to 1 if you have the header file. */ 55 | #cmakedefine HAVE_STRING_H 56 | 57 | /* Define to 1 if you have the header file. */ 58 | #cmakedefine HAVE_SYS_FILIO_H 59 | 60 | /* Define to 1 if you have the header file. */ 61 | #cmakedefine HAVE_SYS_IOCTL_H 62 | 63 | /* Define to 1 if you have the header file. */ 64 | #cmakedefine HAVE_SYS_SOCKET_H 65 | 66 | /* Define to 1 if you have the header file. */ 67 | #cmakedefine HAVE_SYS_SOCKIO_H 68 | 69 | /* Define to 1 if you have the header file. */ 70 | #cmakedefine HAVE_SYS_STATVFS_H 71 | 72 | /* Define to 1 if you have the header file. */ 73 | #cmakedefine HAVE_SYS_STAT_H 74 | 75 | /* Define to 1 if you have the header file. */ 76 | #cmakedefine HAVE_SYS_TIME_H 77 | 78 | /* Define to 1 if you have the header file. */ 79 | #cmakedefine HAVE_SYS_TYPES_H 80 | 81 | /* Define to 1 if you have the header file. */ 82 | #cmakedefine HAVE_SYS_UIO_H 83 | 84 | /* Define to 1 if you have the header file. */ 85 | #cmakedefine HAVE_SYS_VFS_H 86 | 87 | /* Define to 1 if you have the header file. */ 88 | #cmakedefine HAVE_UNISTD_H 89 | 90 | /* Define to 1 if you have the header file. */ 91 | #cmakedefine HAVE_UTIME_H 92 | 93 | /* Define to 1 if `major', `minor', and `makedev' are declared in . */ 94 | #cmakedefine MAJOR_IN_MKDEV 95 | 96 | /* Define to 1 if `major', `minor', and `makedev' are declared in . */ 97 | #cmakedefine MAJOR_IN_SYSMACROS 98 | 99 | /* Define to 1 if you have the ANSI C header files. */ 100 | #cmakedefine STDC_HEADERS 101 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/cmake/libsmb2.pc.cmake: -------------------------------------------------------------------------------- 1 | # libsmb2 pkg-config file 2 | 3 | prefix=@CMAKE_INSTALL_PREFIX@ 4 | exec_prefix=@CMAKE_INSTALL_PREFIX@ 5 | libdir=@INSTALL_LIB_DIR@ 6 | includedir=@INSTALL_INC_DIR@ 7 | 8 | Name: libsmb2 9 | Description: libsmb2 is a client library for accessing SMB shares over a network. 10 | Version: @PROJECT_VERSION@ 11 | Requires: 12 | Conflicts: 13 | Libs: -L${libdir} -lsmb2 14 | Cflags: -I${includedir} 15 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/component.mk: -------------------------------------------------------------------------------- 1 | 2 | COMPONENT_SRCDIRS=lib 3 | COMPONENT_PRIV_INCLUDEDIRS=lib include/esp 4 | COMPONENT_ADD_INCLUDEDIRS=include include/smb2 5 | 6 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_library(POPT_LIBRARY popt) 2 | 3 | list(APPEND CORE_LIBRARIES ${POPT_LIBRARY}) 4 | 5 | set(SOURCES smb2-cat-async 6 | smb2-cat-sync 7 | smb2-ftruncate-sync 8 | smb2-ls-async 9 | smb2-ls-sync 10 | smb2-put-async 11 | smb2-put-sync 12 | smb2-raw-stat-async 13 | smb2-raw-getsd-async 14 | smb2-share-enum 15 | smb2-stat-sync 16 | smb2-truncate-sync) 17 | 18 | foreach(TARGET ${SOURCES}) 19 | add_executable(${TARGET} ${TARGET}.c) 20 | target_link_libraries(${TARGET} ${CORE_LIBRARIES}) 21 | add_dependencies(${TARGET} smb2) 22 | endforeach() 23 | 24 | add_definitions(-Werror "-D_U_=__attribute__((unused))") 25 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/examples/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_PROGRAMS = smb2-cat-async smb2-cat-sync \ 2 | smb2-ftruncate-sync \ 3 | smb2-ls-async smb2-ls-sync \ 4 | smb2-put-async \ 5 | smb2-put-sync \ 6 | smb2-raw-fsstat-async \ 7 | smb2-raw-getsd-async \ 8 | smb2-raw-stat-async \ 9 | smb2-share-enum \ 10 | smb2-stat-sync \ 11 | smb2-statvfs-sync \ 12 | smb2-truncate-sync 13 | 14 | AM_CPPFLAGS = \ 15 | -I$(abs_top_srcdir)/include \ 16 | -I$(abs_top_srcdir)/include/smb2 \ 17 | "-D_U_=__attribute__((unused))" \ 18 | -Wall -Werror 19 | 20 | COMMON_LIBS = ../lib/libsmb2.la -lpopt 21 | smb2_cat_async_LDADD = $(COMMON_LIBS) 22 | smb2_cat_sync_LDADD = $(COMMON_LIBS) 23 | smb2_ftruncate_sync_LDADD = $(COMMON_LIBS) 24 | smb2_ls_async_LDADD = $(COMMON_LIBS) 25 | smb2_ls_sync_LDADD = $(COMMON_LIBS) 26 | smb2_put_async_LDADD = $(COMMON_LIBS) 27 | smb2_put_sync_LDADD = $(COMMON_LIBS) 28 | smb2_raw_fsstat_async_LDADD = $(COMMON_LIBS) 29 | smb2_raw_getsd_async_LDADD = $(COMMON_LIBS) 30 | smb2_raw_stat_async_LDADD = $(COMMON_LIBS) 31 | smb2_share_enum_LDADD = $(COMMON_LIBS) 32 | smb2_stat_sync_LDADD = $(COMMON_LIBS) 33 | smb2_statvfs_sync_LDADD = $(COMMON_LIBS) 34 | smb2_truncate_sync_LDADD = $(COMMON_LIBS) 35 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/examples/smb2-truncate-sync.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) 2016 by Ronnie Sahlberg 4 | 5 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 8 | 9 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 10 | 11 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 12 | */ 13 | 14 | #define _GNU_SOURCE 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "smb2.h" 27 | #include "libsmb2.h" 28 | #include "libsmb2-raw.h" 29 | 30 | int usage(void) 31 | { 32 | fprintf(stderr, "Usage:\n" 33 | "smb2-truncate-sync \n\n" 34 | "URL format: " 35 | "smb://[@]>[:]//\n"); 36 | exit(1); 37 | } 38 | 39 | int main(int argc, char *argv[]) 40 | { 41 | struct smb2_context *smb2; 42 | struct smb2_url *url; 43 | 44 | if (argc < 3) { 45 | usage(); 46 | } 47 | 48 | smb2 = smb2_init_context(); 49 | if (smb2 == NULL) { 50 | fprintf(stderr, "Failed to init context\n"); 51 | exit(0); 52 | } 53 | 54 | url = smb2_parse_url(smb2, argv[1]); 55 | if (url == NULL) { 56 | fprintf(stderr, "Failed to parse url: %s\n", 57 | smb2_get_error(smb2)); 58 | exit(0); 59 | } 60 | 61 | smb2_set_security_mode(smb2, SMB2_NEGOTIATE_SIGNING_ENABLED); 62 | 63 | if (smb2_connect_share(smb2, url->server, url->share, url->user) != 0) { 64 | printf("smb2_connect_share failed. %s\n", smb2_get_error(smb2)); 65 | exit(10); 66 | } 67 | 68 | if (smb2_truncate(smb2, url->path, strtoll(argv[2], NULL, 10)) < 0) { 69 | printf("smb2_truncate failed. %s\n", smb2_get_error(smb2)); 70 | exit(10); 71 | } 72 | 73 | smb2_disconnect_share(smb2); 74 | smb2_destroy_url(url); 75 | smb2_destroy_context(smb2); 76 | 77 | return 0; 78 | } 79 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/include/Makefile.am: -------------------------------------------------------------------------------- 1 | smb2dir = $(includedir)/smb2 2 | dist_smb2_HEADERS = \ 3 | smb2/libsmb2.h \ 4 | smb2/libsmb2-raw.h \ 5 | smb2/smb2.h \ 6 | smb2/smb2-errors.h 7 | 8 | dist_noinst_HEADERS = \ 9 | libsmb2-private.h \ 10 | slist.h 11 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/include/asprintf.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ASPRINTF_H_ 3 | #define _ASPRINTF_H_ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #ifndef _vscprintf 11 | /* For some reason, MSVC fails to honour this #ifndef. */ 12 | /* Hence function renamed to _vscprintf_so(). */ 13 | static inline int _vscprintf_so(const char * format, va_list pargs) { 14 | int retval; 15 | va_list argcopy; 16 | va_copy(argcopy, pargs); 17 | retval = vsnprintf(NULL, 0, format, argcopy); 18 | va_end(argcopy); 19 | return retval; 20 | } 21 | #endif // _vscprintf 22 | 23 | #ifndef vasprintf 24 | static inline int vasprintf(char **strp, const char *fmt, va_list ap) { 25 | int len = _vscprintf_so(fmt, ap); 26 | if (len == -1) return -1; 27 | char *str = malloc((size_t)len + 1); 28 | if (!str) return -1; 29 | int r = vsnprintf(str, len + 1, fmt, ap); /* "secure" version of vsprintf */ 30 | if (r == -1) return free(str), -1; 31 | *strp = str; 32 | return r; 33 | } 34 | #endif // vasprintf 35 | 36 | #ifndef asprintf 37 | static inline int asprintf(char *strp[], const char *fmt, ...) { 38 | va_list ap; 39 | va_start(ap, fmt); 40 | int r = vasprintf(strp, fmt, ap); 41 | va_end(ap); 42 | return r; 43 | } 44 | #endif // asprintf 45 | 46 | #endif // ! _ASPRINTF_H_ 47 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/include/msvc/poll.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _MSVC_POLL_H_ 3 | #define _MSVC_POLL_H_ 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | #include 10 | 11 | static inline int poll(struct pollfd pfd[], uint32_t size, int nvecs) 12 | { 13 | return WSAPoll(pfd, size, nvecs); 14 | } 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | #endif /* !_MSVC_POLL_H_ */ 20 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/include/msvc/sys/socket.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _MSVC_SYS_SOCKET_H_ 3 | #define _MSVC_SYS_SOCKET_H_ 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | #ifndef WIN32_LEAN_AND_MEAN 10 | #define WIN32_LEAN_AND_MEAN 11 | #endif // !WIN32_LEAN_AND_MEAN 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | #define EBADF WSAENOTSOCK 20 | 21 | typedef SSIZE_T ssize_t; 22 | 23 | struct iovec 24 | { 25 | unsigned long iov_len; // from WSABUF 26 | void *iov_base; 27 | }; 28 | 29 | inline int writev(t_socket sock, struct iovec *iov, int nvecs) 30 | { 31 | DWORD ret; 32 | 33 | int res = WSASend(sock, (LPWSABUF)iov, nvecs, &ret, 0, NULL, NULL); 34 | 35 | if (res == 0) { 36 | return (int)ret; 37 | } 38 | return -1; 39 | } 40 | 41 | inline int readv(t_socket sock, struct iovec *iov, int nvecs) 42 | { 43 | DWORD ret; 44 | DWORD flags = 0; 45 | 46 | int res = WSARecv(sock, (LPWSABUF)iov, nvecs, &ret, &flags, NULL, NULL); 47 | 48 | if (res == 0) { 49 | return (int)ret; 50 | } 51 | return -1; 52 | } 53 | 54 | inline int close(t_socket sock) 55 | { 56 | return closesocket(sock); 57 | } 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | #endif /* !_MSVC_SYS_SOCKET_H_ */ 63 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/include/slist.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 by Ronnie Sahlberg 3 | 4 | This program is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation; either version 2.1 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program; if not, see . 16 | */ 17 | 18 | #ifndef __smb2_slist_h__ 19 | #define __smb2_slist_h__ 20 | 21 | #define SMB2_LIST_ADD(list, item) \ 22 | do { \ 23 | (item)->next = (*list); \ 24 | (*list) = (item); \ 25 | } while (0); 26 | 27 | #define SMB2_LIST_ADD_END(list, item) \ 28 | if ((*list) == NULL) { \ 29 | SMB2_LIST_ADD((list), (item)); \ 30 | } else { \ 31 | void *head = (*list); \ 32 | while ((*list)->next) \ 33 | (*list) = (*list)->next; \ 34 | (*list)->next = (item); \ 35 | (item)->next = NULL; \ 36 | (*list) = head; \ 37 | } 38 | 39 | #define SMB2_LIST_REMOVE(list, item) \ 40 | if ((*list) == (item)) { \ 41 | (*list) = (item)->next; \ 42 | } else { \ 43 | void *head = (*list); \ 44 | while ((*list)->next && (*list)->next != (item)) \ 45 | (*list) = (*list)->next; \ 46 | if ((*list)->next != NULL) { \ 47 | (*list)->next = (*list)->next->next; \ 48 | } \ 49 | (*list) = head; \ 50 | } 51 | 52 | #define SMB2_LIST_LENGTH(list, length) \ 53 | do { \ 54 | (length) = 0; \ 55 | void *head = (*list); \ 56 | while ((*list)) { \ 57 | (*list) = (*list)->next; \ 58 | (length)++; \ 59 | } \ 60 | (*list) = head; \ 61 | } while (0); 62 | 63 | #endif /* __smb2_slist_h__ */ 64 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/include/smb2/libsmb2-dcerpc-srvsvc.h: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) 2018 by Ronnie Sahlberg 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this program; if not, see . 17 | */ 18 | 19 | #ifndef _LIBSMB2_DCERPC_SRVSVC_H_ 20 | #define _LIBSMB2_DCERPC_SRVSVC_H_ 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #define SRVSVC_NETSHAREENUMALL 15 27 | 28 | struct dcerpc_context; 29 | struct dcerpc_pdu; 30 | 31 | int srvsvc_netshareenumall_decoder(struct dcerpc_context *dce, 32 | struct dcerpc_pdu *pdu, 33 | struct smb2_iovec *iov, int offset, 34 | void *ptr); 35 | int srvsvc_netshareenumall_encoder(struct dcerpc_context *ctx, 36 | struct dcerpc_pdu *pdu, 37 | struct smb2_iovec *iov, int offset, 38 | void *ptr); 39 | 40 | #endif /* !_LIBSMB2_DCERPC_SRVSVC_H_ */ 41 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SOURCES aes.c 2 | alloc.c 3 | dcerpc.c 4 | dcerpc-srvsvc.c 5 | errors.c 6 | init.c 7 | hmac.c 8 | hmac-md5.c 9 | krb5-wrapper.c 10 | libsmb2.c 11 | md4c.c 12 | md5.c 13 | ntlmssp.c 14 | pdu.c 15 | sha1.c 16 | sha224-256.c 17 | sha384-512.c 18 | smb2-cmd-close.c 19 | smb2-cmd-create.c 20 | smb2-cmd-echo.c 21 | smb2-cmd-error.c 22 | smb2-cmd-flush.c 23 | smb2-cmd-ioctl.c 24 | smb2-cmd-logoff.c 25 | smb2-cmd-negotiate.c 26 | smb2-cmd-query-directory.c 27 | smb2-cmd-query-info.c 28 | smb2-cmd-read.c 29 | smb2-cmd-session-setup.c 30 | smb2-cmd-set-info.c 31 | smb2-cmd-tree-connect.c 32 | smb2-cmd-tree-disconnect.c 33 | smb2-cmd-write.c 34 | smb2-data-file-info.c 35 | smb2-data-filesystem-info.c 36 | smb2-data-security-descriptor.c 37 | smb2-share-enum.c 38 | smb2-signing.c 39 | socket.c 40 | sync.c 41 | timestamps.c 42 | unicode.c 43 | usha.c) 44 | 45 | add_library(smb2 ${SOURCES}) 46 | target_link_libraries(smb2 PUBLIC ${core_DEPENDS} ${CORE_LIBRARIES}) 47 | set_target_properties(smb2 PROPERTIES 48 | VERSION ${PROJECT_VERSION} 49 | SOVERSION ${SOVERSION}) 50 | if(NOT MSVC) 51 | add_definitions("-D_U_=__attribute__((unused))") 52 | else() 53 | add_definitions("-D_U_=") 54 | if(CMAKE_SYSTEM_NAME STREQUAL WindowsStore) 55 | add_definitions("-D_MSC_UWP") 56 | endif() 57 | endif() 58 | 59 | install(TARGETS smb2 EXPORT smb2 60 | RUNTIME DESTINATION bin 61 | ARCHIVE DESTINATION lib${LIB_SUFFIX} 62 | LIBRARY DESTINATION lib${LIB_SUFFIX}) 63 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/lib/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CFLAGS=$(WARN_CFLAGS) 2 | 3 | lib_LTLIBRARIES = libsmb2.la 4 | 5 | libsmb2_la_CPPFLAGS = -I$(abs_top_srcdir)/include \ 6 | -I$(abs_top_srcdir)/include/smb2 \ 7 | "-D_U_=__attribute__((unused))" 8 | 9 | libsmb2_la_SOURCES = \ 10 | aes.c \ 11 | alloc.c \ 12 | dcerpc.c \ 13 | dcerpc-srvsvc.c \ 14 | errors.c \ 15 | init.c \ 16 | hmac.c \ 17 | hmac-md5.c \ 18 | krb5-wrapper.c \ 19 | libsmb2.c \ 20 | md4c.c \ 21 | md5.c \ 22 | ntlmssp.c \ 23 | pdu.c \ 24 | sha1.c \ 25 | sha224-256.c \ 26 | sha384-512.c \ 27 | smb2-cmd-close.c \ 28 | smb2-cmd-create.c \ 29 | smb2-cmd-echo.c \ 30 | smb2-cmd-error.c \ 31 | smb2-cmd-flush.c \ 32 | smb2-cmd-ioctl.c \ 33 | smb2-cmd-logoff.c \ 34 | smb2-cmd-negotiate.c \ 35 | smb2-cmd-query-directory.c \ 36 | smb2-cmd-query-info.c \ 37 | smb2-cmd-read.c \ 38 | smb2-cmd-session-setup.c \ 39 | smb2-cmd-set-info.c \ 40 | smb2-cmd-tree-connect.c \ 41 | smb2-cmd-tree-disconnect.c \ 42 | smb2-cmd-write.c \ 43 | smb2-data-file-info.c \ 44 | smb2-data-filesystem-info.c \ 45 | smb2-data-security-descriptor.c \ 46 | smb2-share-enum.c \ 47 | smb2-signing.c \ 48 | socket.c \ 49 | sync.c \ 50 | timestamps.c \ 51 | unicode.c \ 52 | usha.c 53 | 54 | SOCURRENT=3 55 | SOREVISION=0 56 | SOAGE=0 57 | libsmb2_la_LDFLAGS = \ 58 | -version-info $(SOCURRENT):$(SOREVISION):$(SOAGE) -bindir $(bindir) \ 59 | -no-undefined -export-symbols ${srcdir}/libsmb2.syms $(MAYBE_LIBKRB5) 60 | 61 | dist_noinst_DATA = libsmb2.syms 62 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/lib/aes.h: -------------------------------------------------------------------------------- 1 | /* From https://github.com/bitdust/tiny-AES128-C 2 | * Licenced as Public Domain 3 | */ 4 | 5 | #ifndef _AES_H_ 6 | #define _AES_H_ 7 | 8 | #include 9 | 10 | 11 | // #define the macros below to 1/0 to enable/disable the mode of operation. 12 | // 13 | // CBC enables AES128 encryption in CBC-mode of operation and handles 0-padding. 14 | // ECB enables the basic ECB 16-byte block algorithm. Both can be enabled simultaneously. 15 | 16 | // The #ifndef-guard allows it to be configured before #include'ing or at compile time. 17 | #ifndef CBC 18 | #define CBC 1 19 | #endif 20 | 21 | #ifndef ECB 22 | #define ECB 1 23 | #endif 24 | 25 | 26 | 27 | #if defined(ECB) && ECB 28 | 29 | void AES128_ECB_encrypt(uint8_t* input, const uint8_t* key, uint8_t *output); 30 | void AES128_ECB_decrypt(uint8_t* input, const uint8_t* key, uint8_t *output); 31 | 32 | #endif // #if defined(ECB) && ECB 33 | 34 | 35 | #if defined(CBC) && CBC 36 | 37 | void AES128_CBC_encrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv); 38 | void AES128_CBC_decrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv); 39 | 40 | #endif // #if defined(CBC) && CBC 41 | 42 | 43 | 44 | #endif //_AES_H_ 45 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/lib/compat.c: -------------------------------------------------------------------------------- 1 | 2 | #ifdef ESP_PLATFORM 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | ssize_t writev(int fd, const struct iovec *iov, int iovcnt) 13 | { 14 | int total = 0; 15 | for (int i = 0; i < iovcnt; i++) { 16 | int left = iov[i].iov_len; 17 | while (left > 0) { 18 | int count = write(fd, iov[i].iov_base, left); 19 | if (count == -1) { 20 | return -1; 21 | } 22 | total += count; 23 | left -= count; 24 | } 25 | } 26 | return total; 27 | } 28 | 29 | 30 | ssize_t readv(int fd, const struct iovec *iov, int iovcnt) 31 | { 32 | ssize_t total = 0; 33 | for (int i = 0; i < iovcnt; i++) { 34 | int left = iov[i].iov_len; 35 | while (left > 0) { 36 | int count = read(fd, iov[i].iov_base, left); 37 | if (count == -1) { 38 | return -1; 39 | } 40 | if (count == 0) { 41 | return total; 42 | } 43 | total += count; 44 | left -= count; 45 | } 46 | } 47 | return total; 48 | } 49 | 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/lib/hmac-md5.c: -------------------------------------------------------------------------------- 1 | /* From RFC2104 */ 2 | 3 | /* 4 | ** Function: hmac_md5 5 | */ 6 | #ifndef _MSC_VER 7 | #include 8 | #endif 9 | 10 | #include "md5.h" 11 | 12 | #ifdef _MSC_VER 13 | #define bzero(s, n) memset((s), 0, (n)) 14 | 15 | #define bcopy(s1, s2, n) memmove((s2), (s1), (n)) 16 | #endif // _MSC_VER 17 | 18 | /* 19 | * unsigned char* text; pointer to data stream/ 20 | * int text_len; length of data stream 21 | * unsigned char* key; pointer to authentication key 22 | * int key_len; length of authentication key 23 | * caddr_t digest; caller digest to be filled in 24 | */ 25 | void 26 | smb2_hmac_md5(unsigned char *text, int text_len, unsigned char *key, int key_len, 27 | unsigned char *digest) 28 | { 29 | struct MD5Context context; 30 | unsigned char k_ipad[65]; /* inner padding - 31 | * key XORd with ipad 32 | */ 33 | unsigned char k_opad[65]; /* outer padding - 34 | * key XORd with opad 35 | */ 36 | unsigned char tk[16]; 37 | int i; 38 | /* if key is longer than 64 bytes reset it to key=MD5(key) */ 39 | if (key_len > 64) { 40 | struct MD5Context tctx; 41 | 42 | MD5Init(&tctx); 43 | MD5Update(&tctx, key, key_len); 44 | MD5Final(tk, &tctx); 45 | 46 | key = tk; 47 | key_len = 16; 48 | } 49 | 50 | /* 51 | * the HMAC_MD5 transform looks like: 52 | * 53 | * MD5(K XOR opad, MD5(K XOR ipad, text)) 54 | * 55 | * where K is an n byte key 56 | * ipad is the byte 0x36 repeated 64 times 57 | * and text is the data being protected 58 | */ 59 | 60 | /* start out by storing key in pads */ 61 | bzero( k_ipad, sizeof k_ipad); 62 | bzero( k_opad, sizeof k_opad); 63 | bcopy( key, k_ipad, key_len); 64 | bcopy( key, k_opad, key_len); 65 | 66 | /* XOR key with ipad and opad values */ 67 | for (i=0; i<64; i++) { 68 | k_ipad[i] ^= 0x36; 69 | k_opad[i] ^= 0x5c; 70 | } 71 | /* 72 | * perform inner MD5 73 | */ 74 | MD5Init(&context); /* init context for 1st 75 | * pass */ 76 | MD5Update(&context, k_ipad, 64); /* start with inner pad */ 77 | MD5Update(&context, text, text_len); /* then text of datagram */ 78 | MD5Final(digest, &context); /* finish up 1st pass */ 79 | /* 80 | * perform outer MD5 81 | */ 82 | MD5Init(&context); /* init context for 2nd 83 | * pass */ 84 | MD5Update(&context, k_opad, 64); /* start with outer pad */ 85 | MD5Update(&context, digest, 16); /* then results of 1st 86 | * hash */ 87 | MD5Final(digest, &context); /* finish up 2nd pass */ 88 | } 89 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/lib/hmac-md5.h: -------------------------------------------------------------------------------- 1 | /* From RFC1204 HMAC-MD5 2 | */ 3 | 4 | #ifndef HMAC_MD5_H 5 | #define HMAC_MD5_H 6 | 7 | #include 8 | #include 9 | #include 10 | #if (__BYTE_ORDER == __BIG_ENDIAN) 11 | # define WORDS_BIGENDIAN 1 12 | #endif 13 | 14 | typedef uint32_t UWORD32; 15 | 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | void 22 | smb2_hmac_md5(unsigned char *text, int text_len, unsigned char *key, int key_len, 23 | unsigned char *digest); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | #endif /* !HMAC_MD5_H */ 30 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/lib/krb5-wrapper.h: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) 2018 by Ronnie Sahlberg 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this program; if not, see . 17 | */ 18 | #ifdef HAVE_CONFIG_H 19 | #include "config.h" 20 | #endif 21 | 22 | #ifdef HAVE_LIBKRB5 23 | 24 | #ifndef _GNU_SOURCE 25 | #define _GNU_SOURCE 26 | #endif 27 | 28 | #ifndef _KRB5_WRAPPER_H_ 29 | #define _KRB5_WRAPPER_H_ 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | #include 36 | 37 | static const gss_OID_desc gss_mech_spnego = { 38 | 6, "\x2b\x06\x01\x05\x05\x02" 39 | }; 40 | 41 | static const gss_OID_desc spnego_mech_krb5 = { 42 | 9, "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02" 43 | }; 44 | 45 | static const gss_OID_desc spnego_mech_ntlmssp = { 46 | 10, "\x2b\x06\x01\x04\x01\x82\x37\x02\x02\x0a" 47 | }; 48 | 49 | struct private_auth_data { 50 | gss_ctx_id_t context; 51 | gss_cred_id_t cred; 52 | gss_name_t user_name; 53 | gss_name_t target_name; 54 | gss_const_OID mech_type; 55 | uint32_t req_flags; 56 | gss_buffer_desc output_token; 57 | char *g_server; 58 | }; 59 | 60 | void 61 | krb5_free_auth_data(struct private_auth_data *auth); 62 | 63 | unsigned char * 64 | krb5_get_output_token_buffer(struct private_auth_data *auth_data); 65 | 66 | int 67 | krb5_get_output_token_length(struct private_auth_data *auth_data); 68 | 69 | struct private_auth_data * 70 | krb5_negotiate_reply(struct smb2_context *smb2, 71 | const char *server, 72 | const char *domain, 73 | const char *user_name, 74 | const char *password); 75 | 76 | int 77 | krb5_session_get_session_key(struct smb2_context *smb2, 78 | struct private_auth_data *auth_data); 79 | 80 | int 81 | krb5_session_request(struct smb2_context *smb2, 82 | struct private_auth_data *auth_data, 83 | unsigned char *buf, int len); 84 | 85 | void 86 | krb5_set_gss_error(struct smb2_context *smb2, char *func, 87 | uint32_t maj, uint32_t min); 88 | 89 | #ifdef __cplusplus 90 | } 91 | #endif 92 | 93 | #endif /* _KRB5_WRAPPER_H_ */ 94 | 95 | #endif /* HAVE_LIBKRB5 */ 96 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/lib/libsmb2.syms: -------------------------------------------------------------------------------- 1 | compound_file_id 2 | nterror_to_str 3 | nterror_to_errno 4 | smb2_add_compound_pdu 5 | smb2_close 6 | smb2_close_async 7 | smb2_closedir 8 | smb2_cmd_close_async 9 | smb2_cmd_create_async 10 | smb2_cmd_echo_async 11 | smb2_cmd_logoff_async 12 | smb2_cmd_negotiate_async 13 | smb2_cmd_query_directory_async 14 | smb2_cmd_query_info_async 15 | smb2_cmd_session_setup_async 16 | smb2_cmd_set_info_async 17 | smb2_cmd_tree_connect_async 18 | smb2_cmd_tree_disconnect_async 19 | smb2_connect_async 20 | smb2_connect_share 21 | smb2_connect_share_async 22 | smb2_destroy_context 23 | smb2_destroy_url 24 | smb2_disconnect_share 25 | smb2_disconnect_share_async 26 | smb2_fh_from_file_id 27 | smb2_free_data 28 | smb2_free_pdu 29 | smb2_fstat 30 | smb2_fstat_async 31 | smb2_ftruncate 32 | smb2_ftruncate_async 33 | smb2_get_client_guid 34 | smb2_get_error 35 | smb2_get_fd 36 | smb2_get_file_id 37 | smb2_get_max_read_size 38 | smb2_get_max_write_size 39 | smb2_init_context 40 | smb2_mkdir 41 | smb2_mkdir_async 42 | smb2_share_enum_async 43 | smb2_open 44 | smb2_open_async 45 | smb2_opendir 46 | smb2_opendir_async 47 | smb2_parse_url 48 | smb2_pread 49 | smb2_pread_async 50 | smb2_pwrite 51 | smb2_pwrite_async 52 | smb2_queue_pdu 53 | smb2_read 54 | smb2_read_async 55 | smb2_readdir 56 | smb2_rewinddir 57 | smb2_rmdir 58 | smb2_rmdir_async 59 | smb2_lseek 60 | smb2_seekdir 61 | smb2_service 62 | smb2_set_security_mode 63 | smb2_set_user 64 | smb2_set_password 65 | smb2_set_domain 66 | smb2_set_workstation 67 | smb2_stat 68 | smb2_stat_async 69 | smb2_statvfs 70 | smb2_statvfs_async 71 | smb2_telldir 72 | smb2_truncate 73 | smb2_truncate_async 74 | smb2_rename 75 | smb2_rename_async 76 | smb2_unlink 77 | smb2_unlink_async 78 | smb2_which_events 79 | smb2_write 80 | smb2_write_async 81 | smb2_echo 82 | smb2_echo_async 83 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/lib/md4.h: -------------------------------------------------------------------------------- 1 | /* From RFC1320 */ 2 | 3 | /* MD4.H - header file for MD4C.C 4 | */ 5 | 6 | /* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All 7 | rights reserved. 8 | 9 | License to copy and use this software is granted provided that it 10 | is identified as the "RSA Data Security, Inc. MD4 Message-Digest 11 | Algorithm" in all material mentioning or referencing this software 12 | or this function. 13 | 14 | License is also granted to make and use derivative works provided 15 | that such works are identified as "derived from the RSA Data 16 | Security, Inc. MD4 Message-Digest Algorithm" in all material 17 | mentioning or referencing the derived work. 18 | 19 | RSA Data Security, Inc. makes no representations concerning either 20 | the merchantability of this software or the suitability of this 21 | software for any particular purpose. It is provided "as is" 22 | without express or implied warranty of any kind. 23 | 24 | These notices must be retained in any copies of any part of this 25 | documentation and/or software. 26 | */ 27 | 28 | /* MD4 context. */ 29 | typedef struct { 30 | uint32_t state[4]; /* state (ABCD) */ 31 | uint32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */ 32 | unsigned char buffer[64]; /* input buffer */ 33 | } MD4_CTX; 34 | 35 | void MD4Init(MD4_CTX *); 36 | void MD4Update(MD4_CTX *, unsigned char *, unsigned int); 37 | void MD4Final(unsigned char [16], MD4_CTX *); 38 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/lib/md5.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This is the header file for the MD5 message-digest algorithm. 3 | * The algorithm is due to Ron Rivest. This code was 4 | * written by Colin Plumb in 1993, no copyright is claimed. 5 | * This code is in the public domain; do with it what you wish. 6 | * 7 | * Equivalent code is available from RSA Data Security, Inc. 8 | * This code has been tested against that, and is equivalent, 9 | * except that you don't need to include two pages of legalese 10 | * with every copy. 11 | * 12 | * To compute the message digest of a chunk of bytes, declare an 13 | * MD5Context structure, pass it to MD5Init, call MD5Update as 14 | * needed on buffers full of bytes, and then call MD5Final, which 15 | * will fill a supplied 16-byte array with the digest. 16 | * 17 | * Changed so as no longer to depend on Colin Plumb's `usual.h' 18 | * header definitions; now uses stuff from dpkg's config.h 19 | * - Ian Jackson . 20 | * Still in the public domain. 21 | */ 22 | 23 | #ifndef MD5_H 24 | #define MD5_H 25 | 26 | #if defined(_WIN32) 27 | #else 28 | #include 29 | #endif 30 | 31 | #include 32 | #include 33 | #include 34 | #if !defined(_WIN32) && (__BYTE_ORDER == __BIG_ENDIAN) 35 | # define WORDS_BIGENDIAN 1 36 | #endif 37 | 38 | typedef uint32_t UWORD32; 39 | 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | 46 | #define md5byte unsigned char 47 | 48 | struct MD5Context { 49 | UWORD32 buf[4]; 50 | UWORD32 bytes[2]; 51 | UWORD32 in[16]; 52 | }; 53 | 54 | void MD5Init(struct MD5Context *context); 55 | void MD5Update(struct MD5Context *context, md5byte const *buf, unsigned len); 56 | void MD5Final(unsigned char digest[16], struct MD5Context *context); 57 | void MD5Transform(UWORD32 buf[4], UWORD32 const in[16]); 58 | 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | 64 | #endif /* !MD5_H */ 65 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/lib/ntlmssp.h: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) 2018 by Ronnie Sahlberg 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this program; if not, see . 17 | */ 18 | #ifdef HAVE_CONFIG_H 19 | #include "config.h" 20 | #endif 21 | 22 | #ifndef HAVE_LIBKRB5 23 | 24 | #ifndef _GNU_SOURCE 25 | #define _GNU_SOURCE 26 | #endif 27 | 28 | #ifndef _GSSAPI_WRAPPER_H_ 29 | #define _GSSAPI_WRAPPER_H_ 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | struct auth_data; 36 | 37 | struct auth_data * 38 | ntlmssp_init_context(const char *user, 39 | const char *password, 40 | const char *domain, 41 | const char *workstation, 42 | const char *client_challenge); 43 | 44 | int 45 | ntlmssp_generate_blob(struct smb2_context *smb2, time_t t, 46 | struct auth_data *auth_data, 47 | unsigned char *input_buf, int input_len, 48 | unsigned char **output_buf, uint16_t *output_len); 49 | 50 | void 51 | ntlmssp_destroy_context(struct auth_data *auth); 52 | 53 | int ntlmssp_get_session_key(struct auth_data *auth, uint8_t **key, uint8_t *key_size); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | 59 | #endif /* _GSSAPI_WRAPPER_H_ */ 60 | 61 | #endif /* HAVE_LIBKRB5 */ 62 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/lib/sha-private.h: -------------------------------------------------------------------------------- 1 | /*************************** sha-private.h ***************************/ 2 | /********************** See RFC 4634 for details *********************/ 3 | #ifndef _SHA_PRIVATE__H 4 | #define _SHA_PRIVATE__H 5 | /* 6 | * These definitions are defined in FIPS-180-2, section 4.1. 7 | * Ch() and Maj() are defined identically in sections 4.1.1, 8 | * 4.1.2 and 4.1.3. 9 | * 10 | * The definitions used in FIPS-180-2 are as follows: 11 | */ 12 | 13 | #ifndef USE_MODIFIED_MACROS 14 | #define SHA_Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z))) 15 | #define SHA_Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) 16 | 17 | #else /* USE_MODIFIED_MACROS */ 18 | /* 19 | * The following definitions are equivalent and potentially faster. 20 | */ 21 | 22 | #define SHA_Ch(x, y, z) (((x) & ((y) ^ (z))) ^ (z)) 23 | #define SHA_Maj(x, y, z) (((x) & ((y) | (z))) | ((y) & (z))) 24 | #endif /* USE_MODIFIED_MACROS */ 25 | 26 | #define SHA_Parity(x, y, z) ((x) ^ (y) ^ (z)) 27 | 28 | #endif /* _SHA_PRIVATE__H */ 29 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/lib/smb2-cmd-echo.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) 2016 by Ronnie Sahlberg 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this program; if not, see . 17 | */ 18 | #ifdef HAVE_CONFIG_H 19 | #include "config.h" 20 | #endif 21 | 22 | #ifndef _GNU_SOURCE 23 | #define _GNU_SOURCE 24 | #endif 25 | 26 | #ifdef HAVE_STDINT_H 27 | #include 28 | #endif 29 | 30 | #ifdef HAVE_STDLIB_H 31 | #include 32 | #endif 33 | 34 | #ifdef HAVE_STRING_H 35 | #include 36 | #endif 37 | 38 | #ifdef STDC_HEADERS 39 | #include 40 | #endif 41 | 42 | #include "smb2.h" 43 | #include "libsmb2.h" 44 | #include "libsmb2-private.h" 45 | 46 | static int 47 | smb2_encode_echo_request(struct smb2_context *smb2, 48 | struct smb2_pdu *pdu) 49 | { 50 | uint8_t *buf; 51 | int len; 52 | struct smb2_iovec *iov; 53 | 54 | len = 4; 55 | 56 | buf = malloc(len); 57 | if (buf == NULL) { 58 | smb2_set_error(smb2, "Failed to allocate echo buffer"); 59 | return -1; 60 | } 61 | memset(buf, 0, len); 62 | 63 | iov = smb2_add_iovector(smb2, &pdu->out, buf, len, free); 64 | 65 | smb2_set_uint16(iov, 0, SMB2_ECHO_REQUEST_SIZE); 66 | 67 | return 0; 68 | } 69 | 70 | struct smb2_pdu * 71 | smb2_cmd_echo_async(struct smb2_context *smb2, 72 | smb2_command_cb cb, void *cb_data) 73 | { 74 | struct smb2_pdu *pdu; 75 | 76 | pdu = smb2_allocate_pdu(smb2, SMB2_ECHO, cb, cb_data); 77 | if (pdu == NULL) { 78 | return NULL; 79 | } 80 | 81 | if (smb2_encode_echo_request(smb2, pdu)) { 82 | smb2_free_pdu(smb2, pdu); 83 | return NULL; 84 | } 85 | 86 | if (smb2_pad_to_64bit(smb2, &pdu->out) != 0) { 87 | smb2_free_pdu(smb2, pdu); 88 | return NULL; 89 | } 90 | 91 | return pdu; 92 | } 93 | 94 | int 95 | smb2_process_echo_fixed(struct smb2_context *smb2, 96 | struct smb2_pdu *pdu) 97 | { 98 | return 0; 99 | } 100 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/lib/smb2-cmd-error.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) 2016 by Ronnie Sahlberg 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this program; if not, see . 17 | */ 18 | #ifdef HAVE_CONFIG_H 19 | #include "config.h" 20 | #endif 21 | 22 | #ifndef _GNU_SOURCE 23 | #define _GNU_SOURCE 24 | #endif 25 | 26 | #ifdef HAVE_STDINT_H 27 | #include 28 | #endif 29 | 30 | #ifdef HAVE_STDLIB_H 31 | #include 32 | #endif 33 | 34 | #ifdef HAVE_STRING_H 35 | #include 36 | #endif 37 | 38 | #ifdef STDC_HEADERS 39 | #include 40 | #endif 41 | 42 | #include 43 | 44 | #include "smb2.h" 45 | #include "libsmb2.h" 46 | #include "libsmb2-private.h" 47 | 48 | int 49 | smb2_process_error_fixed(struct smb2_context *smb2, 50 | struct smb2_pdu *pdu) 51 | { 52 | struct smb2_error_reply *rep; 53 | struct smb2_iovec *iov = &smb2->in.iov[smb2->in.niov - 1]; 54 | uint16_t struct_size; 55 | 56 | rep = malloc(sizeof(*rep)); 57 | if (rep == NULL) { 58 | smb2_set_error(smb2, "Failed to allocate error reply"); 59 | return -1; 60 | } 61 | pdu->payload = rep; 62 | 63 | smb2_get_uint16(iov, 0, &struct_size); 64 | if (struct_size != SMB2_ERROR_REPLY_SIZE || 65 | (struct_size & 0xfffe) != iov->len) { 66 | smb2_set_error(smb2, "Unexpected size of Error " 67 | "reply. Expected %d, got %d", 68 | SMB2_ERROR_REPLY_SIZE, 69 | (int)iov->len); 70 | return -1; 71 | } 72 | 73 | smb2_get_uint8(iov, 2, &rep->error_context_count); 74 | smb2_get_uint32(iov, 4, &rep->byte_count); 75 | 76 | return rep->byte_count; 77 | } 78 | 79 | int 80 | smb2_process_error_variable(struct smb2_context *smb2, 81 | struct smb2_pdu *pdu) 82 | { 83 | struct smb2_error_reply *rep = pdu->payload; 84 | struct smb2_iovec *iov = &smb2->in.iov[smb2->in.niov - 1]; 85 | 86 | rep->error_data = &iov->buf[0]; 87 | 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/lib/smb2-cmd-flush.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) 2016 by Ronnie Sahlberg 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this program; if not, see . 17 | */ 18 | #ifdef HAVE_CONFIG_H 19 | #include "config.h" 20 | #endif 21 | 22 | #ifndef _GNU_SOURCE 23 | #define _GNU_SOURCE 24 | #endif 25 | 26 | #ifdef HAVE_STDINT_H 27 | #include 28 | #endif 29 | 30 | #ifdef HAVE_STDLIB_H 31 | #include 32 | #endif 33 | 34 | #ifdef HAVE_STRING_H 35 | #include 36 | #endif 37 | 38 | #ifdef STDC_HEADERS 39 | #include 40 | #endif 41 | 42 | #include 43 | 44 | #include "smb2.h" 45 | #include "libsmb2.h" 46 | #include "libsmb2-private.h" 47 | 48 | static int 49 | smb2_encode_flush_request(struct smb2_context *smb2, 50 | struct smb2_pdu *pdu, 51 | struct smb2_flush_request *req) 52 | { 53 | int len; 54 | uint8_t *buf; 55 | struct smb2_iovec *iov; 56 | 57 | len = SMB2_FLUSH_REQUEST_SIZE & 0xfffffffe; 58 | buf = malloc(len); 59 | if (buf == NULL) { 60 | smb2_set_error(smb2, "Failed to allocate flush buffer"); 61 | return -1; 62 | } 63 | memset(buf, 0, len); 64 | 65 | iov = smb2_add_iovector(smb2, &pdu->out, buf, len, free); 66 | 67 | smb2_set_uint16(iov, 0, SMB2_FLUSH_REQUEST_SIZE); 68 | memcpy(iov->buf + 8, req->file_id, SMB2_FD_SIZE); 69 | 70 | return 0; 71 | } 72 | 73 | struct smb2_pdu * 74 | smb2_cmd_flush_async(struct smb2_context *smb2, 75 | struct smb2_flush_request *req, 76 | smb2_command_cb cb, void *cb_data) 77 | { 78 | struct smb2_pdu *pdu; 79 | 80 | pdu = smb2_allocate_pdu(smb2, SMB2_FLUSH, cb, cb_data); 81 | if (pdu == NULL) { 82 | return NULL; 83 | } 84 | 85 | if (smb2_encode_flush_request(smb2, pdu, req)) { 86 | smb2_free_pdu(smb2, pdu); 87 | return NULL; 88 | } 89 | 90 | if (smb2_pad_to_64bit(smb2, &pdu->out) != 0) { 91 | smb2_free_pdu(smb2, pdu); 92 | return NULL; 93 | } 94 | 95 | return pdu; 96 | } 97 | 98 | int 99 | smb2_process_flush_fixed(struct smb2_context *smb2, 100 | struct smb2_pdu *pdu) 101 | { 102 | return 0; 103 | } 104 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/lib/smb2-cmd-logoff.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) 2016 by Ronnie Sahlberg 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this program; if not, see . 17 | */ 18 | #ifdef HAVE_CONFIG_H 19 | #include "config.h" 20 | #endif 21 | 22 | #ifndef _GNU_SOURCE 23 | #define _GNU_SOURCE 24 | #endif 25 | 26 | #ifdef HAVE_STDINT_H 27 | #include 28 | #endif 29 | 30 | #ifdef HAVE_STDLIB_H 31 | #include 32 | #endif 33 | 34 | #ifdef HAVE_STRING_H 35 | #include 36 | #endif 37 | 38 | #ifdef STDC_HEADERS 39 | #include 40 | #endif 41 | 42 | #include "smb2.h" 43 | #include "libsmb2.h" 44 | #include "libsmb2-private.h" 45 | 46 | static int 47 | smb2_encode_logoff_request(struct smb2_context *smb2, 48 | struct smb2_pdu *pdu) 49 | { 50 | uint8_t *buf; 51 | int len; 52 | struct smb2_iovec *iov; 53 | 54 | len = 4; 55 | 56 | buf = malloc(len); 57 | if (buf == NULL) { 58 | smb2_set_error(smb2, "Failed to allocate logoff buffer"); 59 | return -1; 60 | } 61 | memset(buf, 0, len); 62 | 63 | iov = smb2_add_iovector(smb2, &pdu->out, buf, len, free); 64 | 65 | smb2_set_uint16(iov, 0, SMB2_LOGOFF_REQUEST_SIZE); 66 | 67 | return 0; 68 | } 69 | 70 | struct smb2_pdu * 71 | smb2_cmd_logoff_async(struct smb2_context *smb2, 72 | smb2_command_cb cb, void *cb_data) 73 | { 74 | struct smb2_pdu *pdu; 75 | 76 | pdu = smb2_allocate_pdu(smb2, SMB2_LOGOFF, cb, cb_data); 77 | if (pdu == NULL) { 78 | return NULL; 79 | } 80 | 81 | if (smb2_encode_logoff_request(smb2, pdu)) { 82 | smb2_free_pdu(smb2, pdu); 83 | return NULL; 84 | } 85 | 86 | if (smb2_pad_to_64bit(smb2, &pdu->out) != 0) { 87 | smb2_free_pdu(smb2, pdu); 88 | return NULL; 89 | } 90 | 91 | return pdu; 92 | } 93 | 94 | int 95 | smb2_process_logoff_fixed(struct smb2_context *smb2, 96 | struct smb2_pdu *pdu) 97 | { 98 | return 0; 99 | } 100 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/lib/smb2-cmd-tree-disconnect.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) 2016 by Ronnie Sahlberg 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this program; if not, see . 17 | */ 18 | #ifdef HAVE_CONFIG_H 19 | #include "config.h" 20 | #endif 21 | 22 | #ifndef _GNU_SOURCE 23 | #define _GNU_SOURCE 24 | #endif 25 | 26 | #ifdef HAVE_STDINT_H 27 | #include 28 | #endif 29 | 30 | #ifdef HAVE_STDLIB_H 31 | #include 32 | #endif 33 | 34 | #ifdef HAVE_STRING_H 35 | #include 36 | #endif 37 | 38 | #ifdef STDC_HEADERS 39 | #include 40 | #endif 41 | 42 | #include "smb2.h" 43 | #include "libsmb2.h" 44 | #include "libsmb2-private.h" 45 | 46 | static int 47 | smb2_encode_tree_disconnect_request(struct smb2_context *smb2, 48 | struct smb2_pdu *pdu) 49 | { 50 | uint8_t *buf; 51 | int len; 52 | struct smb2_iovec *iov; 53 | 54 | len = 4; 55 | 56 | buf = malloc(len); 57 | if (buf == NULL) { 58 | smb2_set_error(smb2, "Failed to allocate tree disconnect " 59 | "buffer"); 60 | return -1; 61 | } 62 | memset(buf, 0, len); 63 | 64 | iov = smb2_add_iovector(smb2, &pdu->out, buf, len, free); 65 | 66 | smb2_set_uint16(iov, 0, SMB2_TREE_DISCONNECT_REQUEST_SIZE); 67 | 68 | return 0; 69 | } 70 | 71 | struct smb2_pdu * 72 | smb2_cmd_tree_disconnect_async(struct smb2_context *smb2, 73 | smb2_command_cb cb, void *cb_data) 74 | { 75 | struct smb2_pdu *pdu; 76 | 77 | pdu = smb2_allocate_pdu(smb2, SMB2_TREE_DISCONNECT, cb, cb_data); 78 | if (pdu == NULL) { 79 | return NULL; 80 | } 81 | 82 | if (smb2_encode_tree_disconnect_request(smb2, pdu)) { 83 | smb2_free_pdu(smb2, pdu); 84 | return NULL; 85 | } 86 | 87 | if (smb2_pad_to_64bit(smb2, &pdu->out) != 0) { 88 | smb2_free_pdu(smb2, pdu); 89 | return NULL; 90 | } 91 | 92 | return pdu; 93 | } 94 | 95 | int 96 | smb2_process_tree_disconnect_fixed(struct smb2_context *smb2, 97 | struct smb2_pdu *pdu) 98 | { 99 | return 0; 100 | } 101 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/lib/smb2-signing.h: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) 2018 by Ronnie Sahlberg 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this program; if not, see . 17 | */ 18 | #ifdef HAVE_CONFIG_H 19 | #include "config.h" 20 | #endif 21 | 22 | #ifndef _GNU_SOURCE 23 | #define _GNU_SOURCE 24 | #endif 25 | 26 | #ifndef _SMB2_SIGNING_H_ 27 | #define _SMB2_SIGNING_H_ 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | #include "slist.h" 34 | #include "smb2.h" 35 | #include "libsmb2.h" 36 | #include "libsmb2-raw.h" 37 | #include "libsmb2-private.h" 38 | 39 | int 40 | smb2_pdu_add_signature(struct smb2_context *smb2, 41 | struct smb2_pdu *pdu); 42 | 43 | int 44 | smb2_pdu_check_signature(struct smb2_context *smb2, 45 | struct smb2_pdu *pdu); 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif /* _SMB2_SIGNING_H_ */ 52 | -------------------------------------------------------------------------------- /src/esp/components/libsmb2/lib/timestamps.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ 2 | /* 3 | Copyright (C) 2016 by Ronnie Sahlberg 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this program; if not, see . 17 | */ 18 | #ifdef HAVE_CONFIG_H 19 | #include "config.h" 20 | #endif 21 | 22 | #ifndef _GNU_SOURCE 23 | #define _GNU_SOURCE 24 | #endif 25 | 26 | #ifdef HAVE_STDINT_H 27 | #include 28 | #endif 29 | 30 | #ifdef HAVE_STDLIB_H 31 | #include 32 | #endif 33 | 34 | #ifdef HAVE_STRING_H 35 | #include 36 | #endif 37 | 38 | #ifdef STDC_HEADERS 39 | #include 40 | #endif 41 | 42 | #include "portable-endian.h" 43 | 44 | #include 45 | #include 46 | #include "libsmb2-private.h" 47 | 48 | uint64_t 49 | timeval_to_win(struct smb2_timeval *tv) 50 | { 51 | return ((uint64_t)tv->tv_sec * 10000000) + 52 | 116444736000000000 + tv->tv_usec * 10; 53 | } 54 | 55 | void 56 | win_to_timeval(uint64_t smb2_time, struct smb2_timeval *tv) 57 | { 58 | tv->tv_usec = (smb2_time / 10) % 1000000; 59 | tv->tv_sec = (smb2_time - 116444736000000000) / 10000000; 60 | } 61 | -------------------------------------------------------------------------------- /src/esp/components/retrostore/.gitignore: -------------------------------------------------------------------------------- 1 | rsclient.c 2 | loader_cmd.c 3 | loader_basic.c 4 | -------------------------------------------------------------------------------- /src/esp/components/retrostore/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main component makefile. 3 | # 4 | # This Makefile can be left empty. By default, it will take the sources in the 5 | # src/ directory, compile them and link them into lib(subdirectory_name).a 6 | # in the build directory. This behaviour is entirely configurable, 7 | # please read the ESP-IDF documents if you need to do this. 8 | # 9 | 10 | COMPONENT_ADD_LDFLAGS=-Wl,--whole-archive build/$(COMPONENT_NAME)/lib$(COMPONENT_NAME).a -Wl,--no-whole-archive 11 | 12 | -------------------------------------------------------------------------------- /src/esp/components/retrostore/esp_mock.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "retrostore.h" 3 | #include "esp_mock.h" 4 | 5 | #ifndef ESP_PLATFORM 6 | 7 | uint8_t* get_wifi_status() 8 | { 9 | // RS_STATUS_WIFI_NOT_NEEDED 10 | static uint8_t status = 0; 11 | return &status; 12 | } 13 | 14 | void set_wifi_credentials(const char* ssid, const char* passwd) 15 | { 16 | // Do nothing 17 | } 18 | 19 | const char* get_wifi_ssid() 20 | { 21 | return "-"; 22 | } 23 | 24 | const char* get_wifi_ip() 25 | { 26 | return "-"; 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /src/esp/components/retrostore/include/backend.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #ifdef ESP_PLATFORM 5 | #include "esp_system.h" 6 | #endif 7 | 8 | #include 9 | #include 10 | 11 | void set_query(const char* query); 12 | char* get_app_title(int idx); 13 | char* get_app_details(int idx); 14 | bool get_app_code(int idx, int* type, unsigned char** buf, int* size); 15 | void get_last_app_code(unsigned char** buf, int* size); 16 | -------------------------------------------------------------------------------- /src/esp/components/retrostore/include/defs.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __DEFS_H__ 3 | #define __DEFS_H__ 4 | 5 | #ifdef ESP_PLATFORM 6 | #include "esp_system.h" 7 | #else 8 | 9 | typedef signed char int8_t; 10 | typedef unsigned char uint8_t; 11 | typedef signed short int16_t; 12 | typedef unsigned short uint16_t; 13 | //typedef uint8_t bool; 14 | 15 | #define true 1 16 | #define false 0 17 | 18 | #endif 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /src/esp/components/retrostore/include/esp_mock.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "defs.h" 5 | 6 | uint8_t* get_wifi_status(); 7 | void set_wifi_credentials(const char* ssid, const char* passwd); 8 | const char* get_wifi_ssid(); 9 | const char* get_wifi_ip(); 10 | -------------------------------------------------------------------------------- /src/esp/components/retrostore/include/pb_common.h: -------------------------------------------------------------------------------- 1 | /* pb_common.h: Common support functions for pb_encode.c and pb_decode.c. 2 | * These functions are rarely needed by applications directly. 3 | */ 4 | 5 | #ifndef PB_COMMON_H_INCLUDED 6 | #define PB_COMMON_H_INCLUDED 7 | 8 | #include "pb.h" 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | /* Iterator for pb_field_t list */ 15 | struct pb_field_iter_s { 16 | const pb_field_t *start; /* Start of the pb_field_t array */ 17 | const pb_field_t *pos; /* Current position of the iterator */ 18 | unsigned required_field_index; /* Zero-based index that counts only the required fields */ 19 | void *dest_struct; /* Pointer to start of the structure */ 20 | void *pData; /* Pointer to current field value */ 21 | void *pSize; /* Pointer to count/has field */ 22 | }; 23 | typedef struct pb_field_iter_s pb_field_iter_t; 24 | 25 | /* Initialize the field iterator structure to beginning. 26 | * Returns false if the message type is empty. */ 27 | bool pb_field_iter_begin(pb_field_iter_t *iter, const pb_field_t *fields, void *dest_struct); 28 | 29 | /* Advance the iterator to the next field. 30 | * Returns false when the iterator wraps back to the first field. */ 31 | bool pb_field_iter_next(pb_field_iter_t *iter); 32 | 33 | /* Advance the iterator until it points at a field with the given tag. 34 | * Returns false if no such field exists. */ 35 | bool pb_field_iter_find(pb_field_iter_t *iter, uint32_t tag); 36 | 37 | #ifdef __cplusplus 38 | } /* extern "C" */ 39 | #endif 40 | 41 | #endif 42 | 43 | -------------------------------------------------------------------------------- /src/esp/components/retrostore/include/retrostore.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __RETROSTORE_H__ 3 | #define __RETROSTORE_H__ 4 | 5 | #include "defs.h" 6 | 7 | #define RS_VERSION_MAJOR 2 8 | #define RS_VERSION_MINOR 0 9 | 10 | #define RETROSTORE_MODULE_ID 3 11 | 12 | #define RS_SEND_VERSION 0 13 | #define RS_SEND_LOADER_CMD 1 14 | #define RS_SEND_BASIC 2 15 | #define RS_SEND_CMD 3 16 | #define RS_SEND_APP_TITLE 4 17 | #define RS_SEND_APP_DETAILS 5 18 | #define RS_CMD_SET_QUERY 6 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /src/esp/components/retrostore/include/utils.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __UTILS_H__ 3 | #define __UTILS_H__ 4 | 5 | #include "defs.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #define RETROSTORE_HOST "retrostore.org" 12 | #define RETROSTORE_PORT 80 13 | 14 | #define LOG(msg) printf("%s\n", msg) 15 | 16 | bool connect_server(int* fd); 17 | bool skip_to_body(int fd); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/esp/components/retrostore/pb_common.cpp: -------------------------------------------------------------------------------- 1 | /* pb_common.c: Common support functions for pb_encode.c and pb_decode.c. 2 | * 3 | * 2014 Petteri Aimonen 4 | */ 5 | 6 | #include "pb_common.h" 7 | 8 | bool pb_field_iter_begin(pb_field_iter_t *iter, const pb_field_t *fields, void *dest_struct) 9 | { 10 | iter->start = fields; 11 | iter->pos = fields; 12 | iter->required_field_index = 0; 13 | iter->dest_struct = dest_struct; 14 | iter->pData = (char*)dest_struct + iter->pos->data_offset; 15 | iter->pSize = (char*)iter->pData + iter->pos->size_offset; 16 | 17 | return (iter->pos->tag != 0); 18 | } 19 | 20 | bool pb_field_iter_next(pb_field_iter_t *iter) 21 | { 22 | const pb_field_t *prev_field = iter->pos; 23 | 24 | if (prev_field->tag == 0) 25 | { 26 | /* Handle empty message types, where the first field is already the terminator. 27 | * In other cases, the iter->pos never points to the terminator. */ 28 | return false; 29 | } 30 | 31 | iter->pos++; 32 | 33 | if (iter->pos->tag == 0) 34 | { 35 | /* Wrapped back to beginning, reinitialize */ 36 | (void)pb_field_iter_begin(iter, iter->start, iter->dest_struct); 37 | return false; 38 | } 39 | else 40 | { 41 | /* Increment the pointers based on previous field size */ 42 | size_t prev_size = prev_field->data_size; 43 | 44 | if (PB_HTYPE(prev_field->type) == PB_HTYPE_ONEOF && 45 | PB_HTYPE(iter->pos->type) == PB_HTYPE_ONEOF && 46 | iter->pos->data_offset == PB_SIZE_MAX) 47 | { 48 | /* Don't advance pointers inside unions */ 49 | return true; 50 | } 51 | else if (PB_ATYPE(prev_field->type) == PB_ATYPE_STATIC && 52 | PB_HTYPE(prev_field->type) == PB_HTYPE_REPEATED) 53 | { 54 | /* In static arrays, the data_size tells the size of a single entry and 55 | * array_size is the number of entries */ 56 | prev_size *= prev_field->array_size; 57 | } 58 | else if (PB_ATYPE(prev_field->type) == PB_ATYPE_POINTER) 59 | { 60 | /* Pointer fields always have a constant size in the main structure. 61 | * The data_size only applies to the dynamically allocated area. */ 62 | prev_size = sizeof(void*); 63 | } 64 | 65 | if (PB_HTYPE(prev_field->type) == PB_HTYPE_REQUIRED) 66 | { 67 | /* Count the required fields, in order to check their presence in the 68 | * decoder. */ 69 | iter->required_field_index++; 70 | } 71 | 72 | iter->pData = (char*)iter->pData + prev_size + iter->pos->data_offset; 73 | iter->pSize = (char*)iter->pData + iter->pos->size_offset; 74 | return true; 75 | } 76 | } 77 | 78 | bool pb_field_iter_find(pb_field_iter_t *iter, uint32_t tag) 79 | { 80 | const pb_field_t *start = iter->pos; 81 | 82 | do { 83 | if (iter->pos->tag == tag && 84 | PB_LTYPE(iter->pos->type) != PB_LTYPE_EXTENSION) 85 | { 86 | /* Found the wanted field */ 87 | return true; 88 | } 89 | 90 | (void)pb_field_iter_next(iter); 91 | } while (iter->pos != start); 92 | 93 | /* Searched all the way back to start, and found nothing. */ 94 | return false; 95 | } 96 | 97 | 98 | -------------------------------------------------------------------------------- /src/esp/components/retrostore/proto/ApiProtos.options: -------------------------------------------------------------------------------- 1 | ApiResponseApps.message max_size:128 2 | ApiResponseMediaImages.message max_size:128 3 | MediaImage.filename max_size:128 4 | MediaImage.description max_size:128 5 | App.id max_size:37 6 | App.name max_size:64 7 | App.version max_size:24 8 | App.description max_size:1024 9 | App.screenshot_url max_size:64 10 | App.author max_size:64 11 | -------------------------------------------------------------------------------- /src/esp/components/retrostore/proto/ApiProtos.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option java_package = "org.retrostore.client.common.proto"; 4 | option java_outer_classname = "ApiProtos"; 5 | option java_multiple_files = true; 6 | 7 | // Response for APIs that receive a list of apps. 8 | message ApiResponseApps { 9 | // Whether the request was a success. 10 | bool success = 1; 11 | // An optional (error) message, human-readable. 12 | string message = 2; 13 | // A list of apps returned by the request. 14 | repeated App app = 3; 15 | } 16 | 17 | message ApiResponseMediaImages { 18 | // Whether the request was a success. 19 | bool success = 1; 20 | // An optional (error) message, human-readable. 21 | string message = 2; 22 | // The media images returnes by this respone. 23 | repeated MediaImage mediaImage = 3; 24 | } 25 | 26 | // A RetroStore app item. 27 | message App { 28 | // The ID to uniquely identify an app. 29 | string id = 1; 30 | // The name of the app. 31 | string name = 2; 32 | // The human readable version of this app. 33 | string version = 3; 34 | // The description of this app. 35 | string description = 4; 36 | // The original release year of the app. 37 | int32 release_year = 5; 38 | // URLs to screenshots for this app. 39 | repeated string screenshot_url = 6; 40 | // The author of the app (not the uploader). 41 | string author = 7; 42 | // Extension set for TRS80 apps. 43 | Trs80Extension ext_trs80 = 8; 44 | 45 | // NEXT ID: 9; 46 | } 47 | 48 | // Parameters specific to TRS-80 apps. 49 | message Trs80Extension { 50 | // The TRS-80 model type. 51 | Trs80Model model = 1; 52 | 53 | // The TRS-80 model types. 54 | enum Trs80Model { 55 | UNKNOWN_MODEL = 0; 56 | MODEL_I = 1; 57 | MODEL_III = 2; 58 | MODEL_4 = 3; 59 | MODEL_4P = 4; 60 | } 61 | } 62 | 63 | // A media image for an app. 64 | message MediaImage { 65 | // The type of this media image. 66 | MediaType type = 1; 67 | // The file name of this media image. 68 | string filename = 2; 69 | // The actual data of this media image. 70 | bytes data = 3; 71 | // When the image was uploaded. 72 | int64 uploadTime = 4; 73 | // An optional description of this media image describing its contents. 74 | string description = 5; 75 | } 76 | 77 | // Types of MediaImages. 78 | enum MediaType { 79 | UNKNOWN = 0; 80 | DISK = 1; 81 | CASSETTE = 2; 82 | COMMAND = 3; 83 | BASIC = 4; 84 | } 85 | -------------------------------------------------------------------------------- /src/esp/components/retrostore/retrostore.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "retrostore.h" 4 | #include "version.h" 5 | #include "backend.h" 6 | #include "esp_mock.h" 7 | #include 8 | 9 | // Defined in loader_cmd.c 10 | extern unsigned char loader_cmd_bin[]; 11 | extern unsigned int loader_cmd_bin_len; 12 | 13 | // Defined in loader_basic.c 14 | extern unsigned char loader_basic_cmd[]; 15 | extern unsigned int loader_basic_cmd_len; 16 | 17 | // Defined in rsclient.c 18 | extern unsigned char rsclient_cmd[]; 19 | extern unsigned int rsclient_cmd_len; 20 | 21 | 22 | class RetroStoreModule : public TrsIO { 23 | public: 24 | RetroStoreModule(int id) : TrsIO(id) { 25 | addCommand(static_cast(&RetroStoreModule::sendVersion), ""); 26 | addCommand(static_cast(&RetroStoreModule::sendLoaderCMD), ""); 27 | addCommand(static_cast(&RetroStoreModule::sendBASIC), ""); 28 | addCommand(static_cast(&RetroStoreModule::sendCMD), "I"); 29 | addCommand(static_cast(&RetroStoreModule::sendAppTitle), "I"); 30 | addCommand(static_cast(&RetroStoreModule::sendAppDetails), "I"); 31 | addCommand(static_cast(&RetroStoreModule::setQuery), "S"); 32 | } 33 | 34 | void sendVersion() { 35 | addByte(RS_VERSION_MAJOR); 36 | addByte(RS_VERSION_MINOR); 37 | } 38 | 39 | void sendLoaderCMD() { 40 | addBlob16(loader_cmd_bin, loader_cmd_bin_len); 41 | } 42 | 43 | void sendBASIC() { 44 | unsigned char* buf; 45 | int size; 46 | get_last_app_code(&buf, &size); 47 | addBlob16(buf, size); 48 | } 49 | 50 | void sendCMD() { 51 | uint16_t idx = I(0); 52 | if (idx == 0xffff) { 53 | addBlob16(rsclient_cmd, rsclient_cmd_len); 54 | } else { 55 | int type; 56 | unsigned char* buf; 57 | int size; 58 | bool ok = get_app_code(idx, &type, &buf, &size); 59 | if (!ok) { 60 | // Error happened. Just send rsclient again so we send something legal 61 | addBlob16(rsclient_cmd, rsclient_cmd_len); 62 | } else { 63 | if (type == 3 /* CMD */) { 64 | addBlob16(buf, size); 65 | } else { 66 | // BASIC loader 67 | addBlob16(loader_basic_cmd, loader_basic_cmd_len); 68 | } 69 | } 70 | } 71 | } 72 | 73 | void sendAppTitle() { 74 | uint16_t idx = I(0); 75 | char* title = get_app_title(idx); 76 | addStr(title); 77 | } 78 | 79 | void sendAppDetails() { 80 | uint16_t idx = I(0); 81 | char* details = get_app_details(idx); 82 | addStr(details); 83 | } 84 | 85 | void setQuery() { 86 | set_query(S(0)); 87 | } 88 | }; 89 | 90 | static RetroStoreModule theRetroStoreModule(RETROSTORE_MODULE_ID); 91 | -------------------------------------------------------------------------------- /src/esp/components/retrostore/utils.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "utils.h" 3 | #include 4 | 5 | bool connect_server(int* fd) 6 | { 7 | const char* host = RETROSTORE_HOST; 8 | const int port = RETROSTORE_PORT; 9 | 10 | struct sockaddr_in serv_addr; 11 | struct hostent* server; 12 | 13 | 14 | *fd = socket(AF_INET, SOCK_STREAM, 0); 15 | if (*fd < 0) { 16 | // Error opening socket 17 | return false; 18 | } 19 | server = gethostbyname(host); 20 | if (server == NULL) { 21 | // No such host 22 | return false; 23 | } 24 | bzero((char*) &serv_addr, sizeof(serv_addr)); 25 | serv_addr.sin_family = AF_INET; 26 | bcopy((char*) server->h_addr, 27 | (char*) &serv_addr.sin_addr.s_addr, 28 | server->h_length); 29 | serv_addr.sin_port = htons(port); 30 | if (connect(*fd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) { 31 | // Error connecting 32 | return false; 33 | } 34 | return true; 35 | } 36 | 37 | bool skip_to_body(int fd) 38 | { 39 | char buf[3]; 40 | while (true) { 41 | int result = recv(fd, buf, 1, MSG_WAITALL); 42 | if (result < 1) { 43 | return false; 44 | } 45 | if (buf[0] != '\r') { 46 | continue; 47 | } 48 | result = recv(fd, buf, 3, MSG_WAITALL); 49 | if (result < 3) { 50 | return false; 51 | } 52 | if (buf[0] == '\n' && buf[1] == '\r' && buf[2] == '\n') { 53 | break; 54 | } 55 | } 56 | return true; 57 | } 58 | -------------------------------------------------------------------------------- /src/esp/components/tcpip/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main component makefile. 3 | # 4 | # This Makefile can be left empty. By default, it will take the sources in the 5 | # src/ directory, compile them and link them into lib(subdirectory_name).a 6 | # in the build directory. This behaviour is entirely configurable, 7 | # please read the ESP-IDF documents if you need to do this. 8 | # 9 | 10 | COMPONENT_ADD_LDFLAGS=-Wl,--whole-archive build/$(COMPONENT_NAME)/lib$(COMPONENT_NAME).a -Wl,--no-whole-archive 11 | 12 | -------------------------------------------------------------------------------- /src/esp/components/tcpip/include/tcpip.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __TCPIP_H__ 3 | #define __TCPIP_H__ 4 | 5 | //#include "defs.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #define IP_VERSION_MAJOR 1 14 | #define IP_VERSION_MINOR 0 15 | 16 | #define IP_COMMAND_SUCCESS 0 17 | #define IP_COMMAND_ERROR 1 18 | 19 | #define IP_SOCKET_FAMILY_AF_INET 1 20 | #define IP_SOCKET_FAMILY_AF_INET6 2 21 | 22 | #define IP_SOCKET_TYPE_SOCK_STREAM 1 23 | #define IP_SOCKET_TYPE_SOCK_DGRAM 2 24 | 25 | #define IP_RECV_BLOCKING 0 26 | #define IP_RECV_NONBLOCKING 1 27 | 28 | #define IP_HOST_FORMAT_IP_ADDRESS 0 29 | #define IP_HOST_FORMAT_HOSTNAME 1 30 | 31 | #define IP_STATE_READY 0 32 | #define IP_STATE_READ_COMMAND 1 33 | #define IP_STATE_READ_SOCKET_FAMILY 2 34 | #define IP_STATE_READ_SOCKET_TYPE 3 35 | #define IP_STATE_READ_IP_ADDR 4 36 | #define IP_STATE_READ_SOCKFD 5 37 | #define IP_STATE_READ_PORT 6 38 | #define IP_STATE_READ_DATA 7 39 | #define IP_STATE_READ_LENGTH 8 40 | #define IP_STATE_SEND_TO_Z80 9 41 | #define IP_STATE_READ_RECV_OPTION 10 42 | #define IP_STATE_READ_VERSION 11 43 | #define IP_STATE_READ_HOSTNAME 12 44 | #define IP_STATE_READ_HOST_FORMAT 13 45 | 46 | #define IP_COMMAND_SOCKET 1 47 | #define IP_COMMAND_CONNECT 2 48 | #define IP_COMMAND_SEND 3 49 | #define IP_COMMAND_SENDTO 4 50 | #define IP_COMMAND_RECV 5 51 | #define IP_COMMAND_RECVFROM 6 52 | #define IP_COMMAND_CLOSE 7 53 | 54 | #define IP_ERROR_NONE 0 55 | #define IP_ERROR_UNKNOWN_COMMAND 100 56 | #define IP_ERROR_UNSUPPORTED_PROTOCOL 101 57 | #define IP_ERROR_UNSUPPORTED_COMMAND_OPTION 102 58 | #define IP_ERROR_BAD_SOCKET_FD 103 59 | #define IP_ERROR_UNKNOWN_HOST 104 60 | 61 | int tcp_z80_out(uint8_t value); 62 | void tcp_get_send_buffer(uint8_t** buf, int* size); 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /src/esp/components/trs-fs/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main component makefile. 3 | # 4 | # This Makefile can be left empty. By default, it will take the sources in the 5 | # src/ directory, compile them and link them into lib(subdirectory_name).a 6 | # in the build directory. This behaviour is entirely configurable, 7 | # please read the ESP-IDF documents if you need to do this. 8 | # 9 | 10 | COMPONENT_ADD_LDFLAGS=-Wl,--whole-archive build/$(COMPONENT_NAME)/lib$(COMPONENT_NAME).a -Wl,--no-whole-archive 11 | 12 | -------------------------------------------------------------------------------- /src/esp/components/trs-fs/include/serial.h: -------------------------------------------------------------------------------- 1 | #ifndef TRS_FS_SERIAL_H 2 | #define TRS_FS_SERIAL_H 3 | 4 | #include "trs-fs.h" 5 | 6 | class TRS_FS_SERIAL : virtual public TRS_FS { 7 | public: 8 | TRS_FS_SERIAL(); 9 | void f_log(const char* msg); 10 | FRESULT f_open ( 11 | FIL* fp, /* [OUT] Pointer to the file object structure */ 12 | const TCHAR* path, /* [IN] File name */ 13 | BYTE mode /* [IN] Mode flags */ 14 | ); 15 | FRESULT f_opendir ( 16 | DIR_* dp, /* [OUT] Pointer to the directory object structure */ 17 | const TCHAR* path /* [IN] Directory name */ 18 | ); 19 | FRESULT f_write ( 20 | FIL* fp, /* [IN] Pointer to the file object structure */ 21 | const void* buff, /* [IN] Pointer to the data to be written */ 22 | UINT btw, /* [IN] Number of bytes to write */ 23 | UINT* bw /* [OUT] Pointer to the variable to return number of bytes written */ 24 | ); 25 | FRESULT f_read ( 26 | FIL* fp, /* [IN] File object */ 27 | void* buff, /* [OUT] Buffer to store read data */ 28 | UINT btr, /* [IN] Number of bytes to read */ 29 | UINT* br /* [OUT] Number of bytes read */ 30 | ); 31 | FRESULT f_readdir ( 32 | DIR_* dp, /* [IN] Directory object */ 33 | FILINFO* fno /* [OUT] File information structure */ 34 | ); 35 | FSIZE_t f_tell ( 36 | FIL* fp /* [IN] File object */ 37 | ); 38 | FRESULT f_sync ( 39 | FIL* fp /* [IN] File object */ 40 | ); 41 | FRESULT f_lseek ( 42 | FIL* fp, /* [IN] File object */ 43 | FSIZE_t ofs /* [IN] File read/write pointer */ 44 | ); 45 | FRESULT f_close ( 46 | FIL* fp /* [IN] Pointer to the file object */ 47 | ); 48 | FRESULT f_unlink ( 49 | const TCHAR* path /* [IN] Object name */ 50 | ); 51 | FRESULT f_stat ( 52 | const TCHAR* path, /* [IN] Object name */ 53 | FILINFO* fno /* [OUT] FILINFO structure */ 54 | ); 55 | 56 | }; 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/esp/components/trs-fs/include/smb.h: -------------------------------------------------------------------------------- 1 | #ifndef TRS_FS_SMB_H 2 | #define TRS_FS_SMB_H 3 | 4 | #include "trs-fs.h" 5 | 6 | #define SMB_KEY_URL "smb_url" 7 | #define SMB_KEY_USER "smb_user" 8 | #define SMB_KEY_PASSWD "smb_passwd" 9 | 10 | 11 | class TRS_FS_SMB : virtual public TRS_FS { 12 | public: 13 | TRS_FS_SMB(); 14 | void f_log(const char* msg); 15 | FRESULT f_open ( 16 | FIL* fp, /* [OUT] Pointer to the file object structure */ 17 | const TCHAR* path, /* [IN] File name */ 18 | BYTE mode /* [IN] Mode flags */ 19 | ); 20 | FRESULT f_opendir ( 21 | DIR_* dp, /* [OUT] Pointer to the directory object structure */ 22 | const TCHAR* path /* [IN] Directory name */ 23 | ); 24 | FRESULT f_write ( 25 | FIL* fp, /* [IN] Pointer to the file object structure */ 26 | const void* buff, /* [IN] Pointer to the data to be written */ 27 | UINT btw, /* [IN] Number of bytes to write */ 28 | UINT* bw /* [OUT] Pointer to the variable to return number of bytes written */ 29 | ); 30 | FRESULT f_read ( 31 | FIL* fp, /* [IN] File object */ 32 | void* buff, /* [OUT] Buffer to store read data */ 33 | UINT btr, /* [IN] Number of bytes to read */ 34 | UINT* br /* [OUT] Number of bytes read */ 35 | ); 36 | FRESULT f_readdir ( 37 | DIR_* dp, /* [IN] Directory object */ 38 | FILINFO* fno /* [OUT] File information structure */ 39 | ); 40 | FSIZE_t f_tell ( 41 | FIL* fp /* [IN] File object */ 42 | ); 43 | FRESULT f_sync ( 44 | FIL* fp /* [IN] File object */ 45 | ); 46 | FRESULT f_lseek ( 47 | FIL* fp, /* [IN] File object */ 48 | FSIZE_t ofs /* [IN] File read/write pointer */ 49 | ); 50 | FRESULT f_close ( 51 | FIL* fp /* [IN] Pointer to the file object */ 52 | ); 53 | FRESULT f_unlink ( 54 | const TCHAR* path /* [IN] Object name */ 55 | ); 56 | FRESULT f_stat ( 57 | const TCHAR* path, /* [IN] Object name */ 58 | FILINFO* fno /* [OUT] FILINFO structure */ 59 | ); 60 | 61 | }; 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /src/esp/components/trs-fs/include/trs-fs.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "fileio.h" 5 | #include 6 | #include 7 | #include 8 | 9 | #define F_LOG 99 10 | #define F_OPEN 0 11 | #define F_READ 1 12 | #define F_WRITE 2 13 | #define F_CLOSE 3 14 | #define F_UNLINK 4 15 | #define F_LSEEK 5 16 | #define F_OPENDIR 6 17 | #define F_READDIR 7 18 | #define F_STAT 8 19 | 20 | 21 | const char* init_trs_fs(); 22 | const char* get_smb_err_msg(); 23 | 24 | 25 | class TRS_FS { 26 | protected: 27 | const char* err_msg; 28 | 29 | public: 30 | virtual ~TRS_FS() {} 31 | 32 | const char* get_err_msg() { 33 | return err_msg; 34 | } 35 | 36 | virtual void f_log(const char* msg) = 0; 37 | 38 | virtual FRESULT f_open(FIL* fp, /* [OUT] Pointer to the file object structure */ 39 | const TCHAR* path, /* [IN] File name */ 40 | BYTE mode) = 0; /* [IN] Mode flags */ 41 | 42 | virtual FRESULT f_opendir(DIR_* dp, /* [OUT] Pointer to the directory object structure */ 43 | const TCHAR* path) = 0; /* [IN] Directory name */ 44 | 45 | virtual FRESULT f_write(FIL* fp, /* [IN] Pointer to the file object structure */ 46 | const void* buff, /* [IN] Pointer to the data to be written */ 47 | UINT btw, /* [IN] Number of bytes to write */ 48 | UINT* bw) = 0; /* [OUT] Pointer to the variable to return number of bytes written */ 49 | 50 | virtual FRESULT f_read(FIL* fp, /* [IN] File object */ 51 | void* buff, /* [OUT] Buffer to store read data */ 52 | UINT btr, /* [IN] Number of bytes to read */ 53 | UINT* br) = 0; /* [OUT] Number of bytes read */ 54 | 55 | virtual FRESULT f_readdir(DIR_* dp, /* [IN] Directory object */ 56 | FILINFO* fno) = 0; /* [OUT] File information structure */ 57 | 58 | virtual FSIZE_t f_tell(FIL* fp) = 0; /* [IN] File object */ 59 | 60 | virtual FRESULT f_sync(FIL* fp) = 0; /* [IN] File object */ 61 | 62 | virtual FRESULT f_lseek(FIL* fp, /* [IN] File object */ 63 | FSIZE_t ofs) = 0; /* [IN] File read/write pointer */ 64 | 65 | virtual FRESULT f_close(FIL* fp) = 0; /* [IN] Pointer to the file object */ 66 | 67 | virtual FRESULT f_unlink(const TCHAR* path) = 0; /* [IN] Object name */ 68 | 69 | virtual FRESULT f_stat(const TCHAR* path, /* [IN] Object name */ 70 | FILINFO* fno) = 0; /* [OUT] FILINFO structure */ 71 | }; 72 | 73 | extern TRS_FS* trs_fs; 74 | -------------------------------------------------------------------------------- /src/esp/components/trs-fs/trs-fs.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include "serial.h" 5 | #include "smb.h" 6 | 7 | #include "fileio.h" 8 | 9 | #define TRS_FS_VERSION_MAJOR 1 10 | #define TRS_FS_VERSION_MINOR 0 11 | 12 | #define TRS_FS_MODULE_ID 4 13 | 14 | TRS_FS* trs_fs = NULL; 15 | 16 | const char* init_trs_fs() { 17 | if (trs_fs != NULL) { 18 | delete trs_fs; 19 | } 20 | trs_fs = new TRS_FS_SMB(); 21 | return trs_fs->get_err_msg(); 22 | //trs_fs = new TRS_FS_SERIAL(); 23 | } 24 | 25 | const char* get_smb_err_msg() { 26 | if (trs_fs == NULL) { 27 | return "SMB not connected"; 28 | } 29 | return trs_fs->get_err_msg(); 30 | } 31 | 32 | using namespace std; 33 | 34 | 35 | class TrsFileSystemModule : public TrsIO { 36 | public: 37 | TrsFileSystemModule(int id) : TrsIO(id) { 38 | //trs_fs = new TRS_FS_SMB(); 39 | addCommand(static_cast(&TrsFileSystemModule::doVersion), "BB"); 40 | addCommand(static_cast(&TrsFileSystemModule::doOpen), "SB"); 41 | addCommand(static_cast(&TrsFileSystemModule::doWrite), "BX"); 42 | addCommand(static_cast(&TrsFileSystemModule::doRead), "BL"); 43 | addCommand(static_cast(&TrsFileSystemModule::doClose), "B"); 44 | } 45 | 46 | uint8_t clientVersionMajor; 47 | uint8_t clientVersionMinor; 48 | 49 | uint8_t nextFd = 0; 50 | unordered_map fileMap; 51 | 52 | public: 53 | void doVersion() { 54 | clientVersionMajor = B(0); 55 | clientVersionMinor = B(1); 56 | addByte(TRS_FS_VERSION_MAJOR); 57 | addByte(TRS_FS_VERSION_MINOR); 58 | } 59 | 60 | void doOpen() { 61 | const char* path = S(0); 62 | uint8_t mode = B(0); 63 | uint8_t fd = nextFd++; 64 | FRESULT result = f_open(&fileMap[fd], path, mode); 65 | addByte(result); 66 | if (result == FR_OK) { 67 | addByte(fd); 68 | } else { 69 | nextFd--; 70 | } 71 | } 72 | 73 | void doWrite() { 74 | FIL* fp = &fileMap[B(0)]; 75 | uint32_t bufferLen = XL(0); 76 | uint8_t* buffer = X(0); 77 | UINT bw; 78 | FRESULT result = f_write(fp, buffer, bufferLen, &bw); 79 | addByte(result); 80 | if (result == FR_OK) { 81 | addLong(bw); 82 | } 83 | } 84 | 85 | void doRead() { 86 | FIL* fp = &fileMap[B(0)]; 87 | uint32_t length = L(0); 88 | 89 | addByte(FR_OK); 90 | uint8_t* buf = startBlob32(); 91 | if (length > getSendBufferFreeSize()) { 92 | length = getSendBufferFreeSize(); 93 | } 94 | UINT br; 95 | FRESULT result = f_read(fp, buf, length, &br); 96 | if (result != FR_OK) { 97 | rewind(); 98 | addByte(result); 99 | } else { 100 | skip(br); 101 | endBlob32(); 102 | } 103 | } 104 | 105 | void doClose() { 106 | FIL* fp = &fileMap[B(0)]; 107 | fileMap.erase(B(0)); 108 | FRESULT result = f_close(fp); 109 | addByte(result); 110 | } 111 | }; 112 | 113 | static TrsFileSystemModule theTrsFileSystemModule(TRS_FS_MODULE_ID); 114 | -------------------------------------------------------------------------------- /src/esp/components/trs-io/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main component makefile. 3 | # 4 | # This Makefile can be left empty. By default, it will take the sources in the 5 | # src/ directory, compile them and link them into lib(subdirectory_name).a 6 | # in the build directory. This behaviour is entirely configurable, 7 | # please read the ESP-IDF documents if you need to do this. 8 | # 9 | 10 | COMPONENT_ADD_LDFLAGS=-Wl,--whole-archive build/$(COMPONENT_NAME)/lib$(COMPONENT_NAME).a -Wl,--no-whole-archive 11 | 12 | -------------------------------------------------------------------------------- /src/esp/components/trs-io/core.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "esp_mock.h" 4 | #include "version.h" 5 | 6 | 7 | class TrsIOCoreModule : public TrsIO { 8 | public: 9 | TrsIOCoreModule(int id) : TrsIO(id) { 10 | addCommand(static_cast(&TrsIOCoreModule::sendVersion), ""); 11 | addCommand(static_cast(&TrsIOCoreModule::sendStatus), ""); 12 | addCommand(static_cast(&TrsIOCoreModule::configureWifi), "SS"); 13 | addCommand(static_cast(&TrsIOCoreModule::sendWifiSSID), ""); 14 | addCommand(static_cast(&TrsIOCoreModule::sendWifiIP), ""); 15 | } 16 | 17 | void sendVersion() { 18 | addByte(TRS_IO_HARDWARE_REVISION); 19 | addByte(TRS_IO_VERSION_MAJOR); 20 | addByte(TRS_IO_VERSION_MINOR); 21 | } 22 | 23 | void sendStatus() { 24 | addByte(*get_wifi_status()); 25 | } 26 | 27 | void configureWifi() { 28 | const char* ssid = S(0); 29 | const char* passwd = S(1); 30 | set_wifi_credentials(ssid, passwd); 31 | } 32 | 33 | void sendWifiSSID() { 34 | const char* ssid = get_wifi_ssid(); 35 | addStr(ssid); 36 | } 37 | 38 | void sendWifiIP() { 39 | const char* ip = get_wifi_ip(); 40 | addStr(ip); 41 | } 42 | }; 43 | 44 | static TrsIOCoreModule theTrsIOCoreModule(TRS_IO_CORE_MODULE_ID); 45 | -------------------------------------------------------------------------------- /src/esp/components/trs-io/include/version.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #define TRS_IO_HARDWARE_REVISION 1 5 | 6 | #define TRS_IO_VERSION_MAJOR 1 7 | #define TRS_IO_VERSION_MINOR 0 8 | -------------------------------------------------------------------------------- /src/esp/main/Kconfig: -------------------------------------------------------------------------------- 1 | menu "TRS-IO" 2 | 3 | config TRS_IO_USE_RETROSTORE_PCB 4 | bool "Use RetroStoreCard settings" 5 | default n 6 | help 7 | Enable backward compatibility with the original 8 | RetroStoreCard. By default, the TRS-IO settings will be used. 9 | 10 | config TRS_IO_USE_RETROSTORE_LED_PINS 11 | bool "Use RetroStoreCard LED pin assignments" 12 | default n 13 | help 14 | Use the GPIO pin assignments for LED as used by the 15 | RetroStoreCard. By default, the TRS-IO GPIO assignments 16 | will be used. Note that setting this option with not 17 | deactivate other TRS-IO functionality such as FreHD. 18 | 19 | config TRS_IO_ENABLE_OTA 20 | bool "Enable OTA for TRS-IO" 21 | default n 22 | help 23 | Select this if the OTA mechanism should be enabled. 24 | This might immediately overwrite the flashed firmware. 25 | Should be disabled during development. 26 | 27 | config TRS_IO_USE_COMPILE_TIME_WIFI_CREDS 28 | bool "Use compile-time credentials for WiFi" 29 | default n 30 | help 31 | If enabled, TRS-IO will use hard-coded credentials to 32 | connect to the specified WiFi network. If disabled, 33 | TRS-IO will create a WiFi Access Point to allow 34 | provisioning of WiFi credentials at runtime. 35 | 36 | config TRS_IO_SSID 37 | string "WiFi SSID" 38 | depends on TRS_IO_USE_COMPILE_TIME_WIFI_CREDS 39 | default "" 40 | help 41 | Sets a compile-time SSID that TRS-IO will connect to. 42 | 43 | config TRS_IO_PASSWD 44 | string "WiFi password" 45 | depends on TRS_IO_USE_COMPILE_TIME_WIFI_CREDS 46 | default "" 47 | help 48 | Set a compile-time password that TRS-IO will use 49 | to connect to a given WiFi. 50 | 51 | config TRS_IO_TEST_LED 52 | bool "Test LED" 53 | default n 54 | help 55 | If enabled, run LED test (cycle through RGB colors). In that 56 | mode, TRS-IO will not do anything else besides the test. 57 | 58 | endmenu 59 | -------------------------------------------------------------------------------- /src/esp/main/button.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "button.h" 3 | #include "driver/gpio.h" 4 | #include "esp_event.h" 5 | 6 | #define GPIO_BUTTON GPIO_NUM_22 7 | 8 | #define ESP_INTR_FLAG_DEFAULT 0 9 | 10 | #define BUTTON_LONG_PRESS BIT0 11 | #define BUTTON_SHORT_PRESS BIT1 12 | 13 | static volatile uint8_t button_status = 0; 14 | 15 | bool is_button_long_press() 16 | { 17 | bool yes = (button_status & BUTTON_LONG_PRESS) != 0; 18 | button_status &= ~ BUTTON_LONG_PRESS; 19 | return yes; 20 | } 21 | 22 | bool is_button_short_press() 23 | { 24 | bool yes = (button_status & BUTTON_SHORT_PRESS) != 0; 25 | button_status &= ~ BUTTON_SHORT_PRESS; 26 | return yes; 27 | } 28 | 29 | #ifndef TRS_IO_BUTTON_ONLY_AT_STARTUP 30 | static void IRAM_ATTR isr_button(void* arg) 31 | { 32 | static int64_t then; 33 | 34 | if (is_button_pressed()) { 35 | then = esp_timer_get_time(); 36 | } else { 37 | int64_t now = esp_timer_get_time(); 38 | int64_t delta_ms = (now - then) / 1000; 39 | if (delta_ms < 50) { 40 | // Bounce 41 | return; 42 | } 43 | if (delta_ms < 1000) { 44 | button_status |= BUTTON_SHORT_PRESS; 45 | } 46 | if (delta_ms > 3000) { 47 | button_status |= BUTTON_LONG_PRESS; 48 | } 49 | } 50 | } 51 | #endif 52 | 53 | void init_button() 54 | { 55 | gpio_config_t gpioConfig; 56 | 57 | // Configure push button 58 | gpioConfig.pin_bit_mask = (1ULL << GPIO_BUTTON); 59 | gpioConfig.mode = GPIO_MODE_INPUT; 60 | gpioConfig.pull_up_en = GPIO_PULLUP_ENABLE; 61 | gpioConfig.pull_down_en = GPIO_PULLDOWN_DISABLE; 62 | #ifdef TRS_IO_BUTTON_ONLY_AT_STARTUP 63 | gpioConfig.intr_type = GPIO_INTR_DISABLE; 64 | #else 65 | gpioConfig.intr_type = GPIO_INTR_ANYEDGE; 66 | #endif 67 | gpio_config(&gpioConfig); 68 | #ifndef TRS_IO_BUTTON_ONLY_AT_STARTUP 69 | gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT); 70 | gpio_isr_handler_add(GPIO_BUTTON, isr_button, NULL); 71 | #endif 72 | } 73 | 74 | bool is_button_pressed() 75 | { 76 | return (GPIO.in & (1 << GPIO_BUTTON)) == 0; 77 | } 78 | -------------------------------------------------------------------------------- /src/esp/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main component makefile. 3 | # 4 | # This Makefile can be left empty. By default, it will take the sources in the 5 | # src/ directory, compile them and link them into lib(subdirectory_name).a 6 | # in the build directory. This behaviour is entirely configurable, 7 | # please read the ESP-IDF documents if you need to do this. 8 | # 9 | 10 | $(call compile_only_if,$(CONFIG_TRS_IO_ENABLE_OTA),ota.o) 11 | $(call compile_only_if_not,$(CONFIG_TRS_IO_ENABLE_OTA),ota-dummy.o) 12 | -------------------------------------------------------------------------------- /src/esp/main/event.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "freertos/FreeRTOS.h" 4 | #include "freertos/task.h" 5 | #include "freertos/event_groups.h" 6 | #include "event.h" 7 | 8 | static const int WIFI_UP_BIT = BIT0; 9 | 10 | static EventGroupHandle_t eg; 11 | 12 | void evt_signal_wifi_up() { 13 | xEventGroupSetBits(eg, WIFI_UP_BIT); 14 | } 15 | 16 | void evt_wait_wifi_up() { 17 | xEventGroupWaitBits(eg, WIFI_UP_BIT, pdFALSE, pdFALSE, portMAX_DELAY); 18 | } 19 | 20 | void init_events() { 21 | eg = xEventGroupCreate(); 22 | } 23 | -------------------------------------------------------------------------------- /src/esp/main/include/button.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | //#define TRS_IO_BUTTON_ONLY_AT_STARTUP 1 5 | 6 | #include "esp_system.h" 7 | 8 | void init_button(); 9 | bool is_button_long_press(); 10 | bool is_button_short_press(); 11 | bool is_button_pressed(); 12 | 13 | -------------------------------------------------------------------------------- /src/esp/main/include/event.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | void evt_signal_wifi_up(); 5 | void evt_wait_wifi_up(); 6 | void init_events(); 7 | -------------------------------------------------------------------------------- /src/esp/main/include/io.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "esp_system.h" 5 | 6 | void io_core1_enable_intr(); 7 | void io_core1_disable_intr(); 8 | void init_io(); 9 | -------------------------------------------------------------------------------- /src/esp/main/include/led.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "esp_system.h" 5 | 6 | void init_led(); 7 | void set_led(bool r, bool g, bool b, bool blink, bool auto_off); 8 | -------------------------------------------------------------------------------- /src/esp/main/include/ntp_sync.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #define NTP_KEY_TZ "tz" 5 | 6 | void set_timezone(); 7 | void init_time(); 8 | -------------------------------------------------------------------------------- /src/esp/main/include/ota.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | void switch_to_factory(); 5 | void init_ota(); 6 | -------------------------------------------------------------------------------- /src/esp/main/include/storage.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "esp_system.h" 5 | 6 | void init_storage(); 7 | void storage_erase(); 8 | bool storage_has_key(const char* key, size_t* len); 9 | bool storage_has_key(const char* key); 10 | void storage_get_str(const char* key, char* out, size_t* len); 11 | void storage_set_str(const char* key, const char* value); 12 | int32_t storage_get_i32(const char* key); 13 | void storage_set_i32(const char* key, int value); 14 | -------------------------------------------------------------------------------- /src/esp/main/include/wifi.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "defs.h" 5 | 6 | #define RS_STATUS_WIFI_NOT_NEEDED 0 7 | #define RS_STATUS_WIFI_CONNECTING 1 8 | #define RS_STATUS_WIFI_CONNECTED 2 9 | #define RS_STATUS_WIFI_NOT_CONNECTED 3 10 | #define RS_STATUS_WIFI_NOT_CONFIGURED 4 11 | #define RS_STATUS_NO_RETROSTORE_CARD 0xff 12 | 13 | void start_mg(); 14 | void set_wifi_credentials(const char* ssid, const char* passwd); 15 | uint8_t* get_wifi_status(); 16 | const char* get_wifi_ssid(); 17 | void init_wifi(); 18 | -------------------------------------------------------------------------------- /src/esp/main/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "io.h" 3 | #include "led.h" 4 | #include "button.h" 5 | #include "wifi.h" 6 | #include "ota.h" 7 | #include "storage.h" 8 | #include "event.h" 9 | #include "esp_event.h" 10 | 11 | #include "retrostore.h" 12 | #include "backend.h" 13 | #include "trs-io.h" 14 | #include "ntp_sync.h" 15 | 16 | 17 | extern "C" { 18 | void app_main(void); 19 | } 20 | 21 | 22 | void app_main(void) 23 | { 24 | init_events(); 25 | init_trs_io(); 26 | init_led(); 27 | init_button(); 28 | init_storage(); 29 | 30 | if (is_button_pressed()) { 31 | #ifdef TRS_IO_BUTTON_ONLY_AT_STARTUP 32 | storage_erase(); 33 | #else 34 | switch_to_factory(); 35 | #endif 36 | } 37 | 38 | init_ota(); 39 | init_wifi(); 40 | init_io(); 41 | 42 | init_time(); 43 | 44 | vTaskDelete(NULL); 45 | } 46 | 47 | -------------------------------------------------------------------------------- /src/esp/main/ntp_sync.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include "storage.h" 5 | #include "ntp_sync.h" 6 | #include "lwip/apps/sntp.h" 7 | 8 | 9 | void set_timezone() { 10 | if (!storage_has_key(NTP_KEY_TZ)) { 11 | return; 12 | } 13 | static char tz[33]; 14 | size_t len = sizeof(tz); 15 | storage_get_str(NTP_KEY_TZ, tz, &len); 16 | char* p = tz; 17 | while(*p != '\0') { 18 | if (*p == '-') { 19 | *p = '+'; 20 | } else if (*p == '+') { 21 | *p = '-'; 22 | } 23 | p++; 24 | } 25 | setenv("TZ", tz, 1); 26 | tzset(); 27 | } 28 | 29 | void init_time() { 30 | set_timezone(); 31 | sntp_setoperatingmode(SNTP_OPMODE_POLL); 32 | sntp_setservername(0, "pool.ntp.org"); 33 | sntp_init(); 34 | } 35 | -------------------------------------------------------------------------------- /src/esp/main/ota-dummy.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "freertos/FreeRTOS.h" 3 | #include "freertos/task.h" 4 | #include "wifi.h" 5 | #include "event.h" 6 | #include "retrostore.h" 7 | 8 | 9 | void switch_to_factory() 10 | { 11 | } 12 | 13 | static void ota_task(void* p) 14 | { 15 | evt_wait_wifi_up(); 16 | start_mg(); 17 | vTaskDelete(NULL); 18 | } 19 | 20 | void init_ota() 21 | { 22 | xTaskCreatePinnedToCore(ota_task, "ota", 4096, NULL, 1, NULL, 0); 23 | } 24 | -------------------------------------------------------------------------------- /src/esp/main/storage.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "storage.h" 3 | #include "nvs_flash.h" 4 | #include "io.h" 5 | 6 | static nvs_handle storage; 7 | 8 | void init_storage() 9 | { 10 | // Initialize NVS 11 | esp_err_t err = nvs_flash_init(); 12 | if (err == ESP_ERR_NVS_NO_FREE_PAGES) { 13 | // NVS partition was truncated and needs to be erased 14 | // Retry nvs_flash_init 15 | ESP_ERROR_CHECK(nvs_flash_erase()); 16 | err = nvs_flash_init(); 17 | } 18 | ESP_ERROR_CHECK(err); 19 | 20 | err = nvs_open("retrostore", NVS_READWRITE, &storage); 21 | ESP_ERROR_CHECK(err); 22 | } 23 | 24 | void storage_erase() 25 | { 26 | io_core1_enable_intr(); 27 | ESP_ERROR_CHECK(nvs_erase_all(storage)); 28 | ESP_ERROR_CHECK(nvs_commit(storage)); 29 | io_core1_disable_intr(); 30 | } 31 | 32 | bool storage_has_key(const char* key, size_t* len) 33 | { 34 | io_core1_enable_intr(); 35 | if (nvs_get_str(storage, key, NULL, len) == ESP_ERR_NVS_NOT_FOUND) { 36 | int32_t dummy_i32; 37 | bool ok = nvs_get_i32(storage, key, &dummy_i32) != ESP_ERR_NVS_NOT_FOUND; 38 | io_core1_disable_intr(); 39 | return ok; 40 | } 41 | io_core1_disable_intr(); 42 | return true; 43 | } 44 | 45 | bool storage_has_key(const char* key) 46 | { 47 | size_t len = 0; 48 | return storage_has_key(key, &len); 49 | } 50 | 51 | void storage_get_str(const char* key, char* out, size_t* len) 52 | { 53 | io_core1_enable_intr(); 54 | ESP_ERROR_CHECK(nvs_get_str(storage, key, out, len)); 55 | io_core1_disable_intr(); 56 | } 57 | 58 | void storage_set_str(const char* key, const char* value) 59 | { 60 | io_core1_enable_intr(); 61 | ESP_ERROR_CHECK(nvs_set_str(storage, key, value)); 62 | ESP_ERROR_CHECK(nvs_commit(storage)); 63 | io_core1_disable_intr(); 64 | } 65 | 66 | int32_t storage_get_i32(const char* key) 67 | { 68 | int32_t value; 69 | io_core1_enable_intr(); 70 | ESP_ERROR_CHECK(nvs_get_i32(storage, key, &value)); 71 | io_core1_disable_intr(); 72 | return value; 73 | } 74 | 75 | void storage_set_i32(const char* key, int32_t value) 76 | { 77 | io_core1_enable_intr(); 78 | ESP_ERROR_CHECK(nvs_set_i32(storage, key, value)); 79 | ESP_ERROR_CHECK(nvs_commit(storage)); 80 | io_core1_disable_intr(); 81 | } 82 | -------------------------------------------------------------------------------- /src/esp/reset_to_factory.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # The following command will erase the OTA data partition thus resetting 4 | # the ESP32 to the factory image 5 | 6 | esptool.py --chip esp32 --port /dev/ttyS11 --baud 115200 erase_region 0xd000 0x2000 7 | 8 | -------------------------------------------------------------------------------- /src/ihex2cmd/.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | ihex2cmd 3 | -------------------------------------------------------------------------------- /src/ihex2cmd/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ihex2cmd 3 | 4 | ihex2cmd: ihex2cmd.cpp 5 | g++ ihex2cmd.cpp -o ihex2cmd 6 | 7 | clean: 8 | rm -rf ihex2cmd *~ 9 | -------------------------------------------------------------------------------- /src/ihex2cmd/ihex2cmd.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | #define CMD_CHECK(condition, errno) \ 8 | if (!(condition)) { \ 9 | cmd_error(errno); \ 10 | } 11 | 12 | /* 13 | * Class IHEX2CMD converts a file in Intel's HEX format 14 | * to a TRS-80 CMD executable. The conversion is primitive 15 | * in the sense that an IHEX record is converted to a 16 | * TRS-80 segment. That should be improved at some point. 17 | */ 18 | class IHEX2CMD { 19 | private: 20 | int argc; 21 | char** argv; 22 | ifstream ihex; 23 | ofstream cmd; 24 | string rec; 25 | int pos; 26 | int entry_addr_msb; 27 | int entry_addr_lsb; 28 | 29 | void cmd_error(int errnum) { 30 | switch (errnum) { 31 | case -1: 32 | throw "Usage: ihex2cmd "; 33 | case -2: 34 | throw "Input file does not exist"; 35 | case -3: 36 | throw "Could not open output file"; 37 | case -4: 38 | throw "Bad ihex format"; 39 | default: 40 | throw "UNKNOWN ERROR"; 41 | } 42 | } 43 | 44 | void parse_args() { 45 | CMD_CHECK(argc == 3, -1); 46 | } 47 | 48 | unsigned char next_nibble() { 49 | CMD_CHECK(pos != rec.length(), -4); 50 | char ch = rec[pos++]; 51 | CMD_CHECK((ch >= '0' && ch <='9') || (ch >= 'A' && ch <= 'F'), -4); 52 | ch -= '0'; 53 | if (ch > 9) { 54 | ch -= 'A' - '0' - 10; 55 | } 56 | return ch; 57 | } 58 | 59 | unsigned char next_byte() { 60 | unsigned char h = next_nibble(); 61 | unsigned char l = next_nibble(); 62 | return (h << 4) | l; 63 | } 64 | 65 | void parse_record() { 66 | char header[4]; 67 | char len = next_byte(); 68 | header[3] = next_byte(); 69 | header[2] = next_byte(); 70 | if (entry_addr_lsb == 256) { 71 | entry_addr_lsb = header[2]; 72 | entry_addr_msb = header[3]; 73 | } 74 | char type = next_byte(); 75 | CMD_CHECK((type == 0) || (type == 1), -4); 76 | if (type == 1) { 77 | // Entry address 78 | char entry[4]; 79 | entry[0] = 2; 80 | entry[1] = 2; 81 | entry[2] = entry_addr_lsb; 82 | entry[3] = entry_addr_msb; 83 | cmd.write(entry, 4); 84 | return; 85 | } 86 | // Write segment 87 | header[0] = 1; 88 | header[1] = len + 2; 89 | cmd.write(header, 4); 90 | for (int i = 0; i < len; i++) { 91 | char b = next_byte(); 92 | cmd.write(&b, 1); 93 | } 94 | } 95 | 96 | void parse_ihex() { 97 | while (ihex >> rec) { 98 | CMD_CHECK(rec.length() > 10 && rec[0] == ':', -4); 99 | pos = 1; 100 | parse_record(); 101 | } 102 | } 103 | 104 | public: 105 | IHEX2CMD(int argc, char* argv[]) { 106 | this->argc = argc; 107 | this->argv = argv; 108 | } 109 | 110 | int convert() { 111 | try { 112 | entry_addr_lsb = 256; 113 | parse_args(); 114 | ihex.open(argv[1]); 115 | CMD_CHECK(ihex, -2); 116 | cmd.open(argv[2], ios::out | ios::binary); 117 | parse_ihex(); 118 | ihex.close(); 119 | cmd.close(); 120 | } catch(const char* msg) { 121 | cerr << msg << endl; 122 | return -1; 123 | } 124 | return 0; 125 | } 126 | }; 127 | 128 | int main(int argc, char* argv[]) 129 | { 130 | IHEX2CMD converter(argc, argv); 131 | 132 | return converter.convert(); 133 | } 134 | -------------------------------------------------------------------------------- /src/loader/Makefile: -------------------------------------------------------------------------------- 1 | 2 | MAKE = make 3 | 4 | DIRS = cmd basic 5 | 6 | 7 | all: 8 | for i in $(DIRS); do $(MAKE) -C $$i || exit 1; done 9 | 10 | clean: 11 | for i in $(DIRS); do $(MAKE) -C $$i clean || exit 1; done 12 | -------------------------------------------------------------------------------- /src/loader/basic/.gitignore: -------------------------------------------------------------------------------- 1 | *.rel 2 | *.lk 3 | *.lst 4 | *~ 5 | *.noi 6 | *.ihx 7 | *.map 8 | *.asm 9 | *.sym 10 | *.cmd 11 | loader_basic.c 12 | -------------------------------------------------------------------------------- /src/loader/basic/Makefile: -------------------------------------------------------------------------------- 1 | 2 | CC = sdcc 3 | AS = sdasz80 4 | LD = sdldz80 5 | IHEX2CMD = ../../ihex2cmd/ihex2cmd 6 | CFLAGS = -mz80 --std-sdcc99 --opt-code-size 7 | ASFLAGS = -l 8 | LDFLAGS = -mjwx -b _CODE=0xfa00 -l $(SDCC_PATH)/lib/z80/z80.lib 9 | 10 | OBJS = \ 11 | crt0.rel \ 12 | main.rel 13 | 14 | %.rel: %.c 15 | $(CC) $(CFLAGS) -c $< 16 | 17 | %.rel: %.s 18 | $(AS) $(ASFLAGS) -o $@ $< 19 | 20 | %.cmd: %.ihx 21 | $(IHEX2CMD) $< $@ 22 | 23 | all: loader_basic.c 24 | 25 | loader_basic.c: loader_basic.cmd 26 | xxd -i loader_basic.cmd loader_basic.c 27 | cp loader_basic.c ../../esp/components/retrostore/ 28 | 29 | loader_basic.ihx : $(OBJS) Makefile 30 | $(LD) $(LDFLAGS) -i loader_basic.ihx $(OBJS) 31 | 32 | 33 | clean: 34 | rm -f *.rel 35 | rm -f *.lk 36 | rm -f *.lst 37 | rm -f *~ 38 | rm -f *.noi 39 | rm -f *.ihx 40 | rm -f *.map 41 | rm -f *.asm 42 | rm -f *.sym 43 | rm -f *.cmd 44 | rm -f loader_basic.c 45 | -------------------------------------------------------------------------------- /src/loader/basic/crt0.s: -------------------------------------------------------------------------------- 1 | ;-------------------------------------------------------------------------- 2 | ; crt0.s - Generic crt0.s for a Z80 3 | ; 4 | ; Copyright (C) 2000, Michael Hope 5 | ; 6 | ; This library is free software; you can redistribute it and/or modify it 7 | ; under the terms of the GNU General Public License as published by the 8 | ; Free Software Foundation; either version 2, or (at your option) any 9 | ; later version. 10 | ; 11 | ; This library is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this library; see the file COPYING. If not, write to the 18 | ; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, 19 | ; MA 02110-1301, USA. 20 | ; 21 | ; As a special exception, if you link this library with other files, 22 | ; some of which are compiled with SDCC, to produce an executable, 23 | ; this library does not by itself cause the resulting executable to 24 | ; be covered by the GNU General Public License. This exception does 25 | ; not however invalidate any other reasons why the executable file 26 | ; might be covered by the GNU General Public License. 27 | ;-------------------------------------------------------------------------- 28 | 29 | ; Modified by AP for TRS-80 30 | 31 | .module crt0 32 | .globl _main 33 | .globl l__INITIALIZER 34 | .globl s__INITIALIZER 35 | .globl s__INITIALIZED 36 | .globl l__DATA 37 | .globl s__DATA 38 | 39 | init: 40 | ;; Set stack pointer directly above top of memory. 41 | ld sp,#0x0000 42 | 43 | ;; Initialise global variables 44 | call gsinit 45 | call _main 46 | _halt: 47 | jp _halt 48 | 49 | ;; Ordering of segments for the linker. 50 | .area _HOME 51 | .area _CODE 52 | .area _INITIALIZER 53 | .area _GSINIT 54 | .area _GSFINAL 55 | 56 | .area _DATA 57 | .area _INITIALIZED 58 | .area _BSEG 59 | .area _BSS 60 | .area _HEAP 61 | 62 | .area _CODE 63 | 64 | .area _GSINIT 65 | gsinit:: 66 | ld bc, #l__INITIALIZER 67 | ld a, b 68 | or a, c 69 | jr Z, gsinit_next 70 | ld de, #s__INITIALIZED 71 | ld hl, #s__INITIALIZER 72 | ldir 73 | gsinit_next: 74 | 75 | .area _GSFINAL 76 | ret 77 | 78 | -------------------------------------------------------------------------------- /src/loader/basic/defs.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __DEFS_H__ 3 | #define __DEFS_H__ 4 | 5 | #include 6 | 7 | typedef signed char int8_t; 8 | typedef unsigned char uint8_t; 9 | typedef signed int int16_t; 10 | typedef unsigned int uint16_t; 11 | typedef uint8_t bool; 12 | 13 | #define true 1 14 | #define false 0 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/loader/basic/main.c: -------------------------------------------------------------------------------- 1 | 2 | #include "defs.h" 3 | 4 | #define PEEK_W(addr) (uint8_t*) *((uint16_t*) (addr)) 5 | #define POKE_W(addr, val) *((uint16_t*) addr) = (uint16_t) (val) 6 | 7 | #define ORG 0xfa00 8 | 9 | #define BAS_BEGIN 0x40a4 10 | #define BAS_END 0x40f9 11 | #define ARRAY_START 0x40fb 12 | #define MEM_START 0x40fd 13 | 14 | #define TRS_IO_RETROSTORE_MODULE_ID 3 15 | #define TRS_IO_PORT 31 16 | 17 | #define RS_SEND_BASIC 2 18 | 19 | #define COMMUNICATIONS_REGION 0x4000 20 | 21 | #include "mem-dump-4000-4200.c" 22 | 23 | static void out(uint8_t port, uint8_t val) 24 | { 25 | __asm 26 | pop hl ; ret 27 | pop bc ; port->c, val->b 28 | push bc 29 | push hl 30 | out (c),b 31 | __endasm; 32 | } 33 | 34 | static uint8_t in(uint8_t port) 35 | { 36 | __asm 37 | pop hl ; ret 38 | pop bc ; port->c 39 | push bc 40 | push hl 41 | in l,(c) 42 | __endasm; 43 | } 44 | 45 | static void wait_for_esp() 46 | { 47 | while (in(0xe0) & 8) ; 48 | } 49 | 50 | 51 | static void init_ram() 52 | { 53 | int i; 54 | 55 | // Copy communication region 56 | uint8_t* p = (uint8_t*) COMMUNICATIONS_REGION; 57 | for (i = 0; i < mem_dump_4000_4200_len; i++) { 58 | *p++ = mem_dump_4000_4200[i]; 59 | } 60 | 61 | // Zero out rest of RAM 62 | for (i = 0; i < ORG - 0x4200; i++) { 63 | *p++ = 0; 64 | } 65 | } 66 | 67 | static void run() 68 | { 69 | __asm 70 | ; Turn off cursor 71 | ld hl,#0x4022 72 | ld (hl),#0 73 | ; Copy 'RUN' to input buffer 74 | ld hl,(0x40a7) 75 | push hl 76 | ld (hl),#'R' 77 | inc hl 78 | ld (hl),#'U' 79 | inc hl 80 | ld (hl),#'N' 81 | inc hl 82 | ld (hl),#0 83 | pop hl 84 | dec hl 85 | ; Enter interpreter loop 86 | jp 0x1a81 87 | __endasm; 88 | } 89 | 90 | static void di() 91 | { 92 | __asm 93 | di 94 | __endasm; 95 | } 96 | 97 | void main() 98 | { 99 | uint8_t* last_line; 100 | uint8_t* p; 101 | uint8_t b; 102 | uint16_t w; 103 | 104 | di(); 105 | init_ram(); 106 | out(TRS_IO_PORT, TRS_IO_RETROSTORE_MODULE_ID); 107 | out(TRS_IO_PORT, RS_SEND_BASIC); 108 | wait_for_esp(); 109 | // Ignore blob length 110 | in(TRS_IO_PORT); 111 | in(TRS_IO_PORT); 112 | b = in(TRS_IO_PORT); 113 | while (b != 0xff) ; 114 | last_line = PEEK_W(BAS_BEGIN); 115 | p = last_line; 116 | while (1) { 117 | w = in(TRS_IO_PORT) | (in(TRS_IO_PORT) << 8); 118 | if (w == 0) { 119 | break; 120 | } 121 | p++; 122 | p++; 123 | *p++ = in(TRS_IO_PORT); 124 | *p++ = in(TRS_IO_PORT); 125 | do { 126 | b = in(TRS_IO_PORT); 127 | *p++ = b; 128 | } while (b != 0); 129 | POKE_W(last_line, p); 130 | last_line = p; 131 | } 132 | *last_line++ = 0; 133 | *last_line++ = 0; 134 | POKE_W(BAS_END, last_line); 135 | POKE_W(ARRAY_START, last_line); 136 | POKE_W(MEM_START, last_line); 137 | run(); 138 | } 139 | -------------------------------------------------------------------------------- /src/loader/basic/mem-dump-4000-4200.c: -------------------------------------------------------------------------------- 1 | unsigned char mem_dump_4000_4200[] = { 2 | 0xc3, 0x96, 0x1c, 0xc3, 0x78, 0x1d, 0xc3, 0x90, 0x1c, 0xc3, 0xd9, 0x25, 3 | 0xc9, 0x00, 0x00, 0xc9, 0x00, 0x00, 0xc3, 0x18, 0x30, 0x01, 0x24, 0x30, 4 | 0x00, 0x01, 0x04, 0x00, 0x00, 0x07, 0x73, 0x04, 0x81, 0x3d, 0x20, 0xb0, 5 | 0x00, 0x06, 0xc2, 0x03, 0x43, 0x01, 0x00, 0xff, 0x52, 0xc3, 0x00, 0x50, 6 | 0xc7, 0x00, 0x00, 0xaf, 0xc9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 7 | 0x00, 0xc3, 0xfa, 0x35, 0xc3, 0xfa, 0x35, 0xc3, 0xfa, 0x35, 0xc3, 0x29, 8 | 0x35, 0xc7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 9 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x91, 0x35, 0x91, 0x35, 0xf1, 0x35, 0x00, 10 | 0x00, 0x15, 0x40, 0x91, 0x35, 0xf1, 0x35, 0x00, 0x00, 0x00, 0x34, 0xcd, 11 | 0x05, 0x80, 0x3c, 0x8e, 0x04, 0x94, 0x06, 0x1d, 0x40, 0x00, 0x00, 0xfe, 12 | 0x37, 0x00, 0x00, 0xb2, 0x37, 0x00, 0x00, 0x00, 0xd6, 0x00, 0x6f, 0x7c, 13 | 0xde, 0x00, 0x67, 0x78, 0xde, 0x00, 0x47, 0x3e, 0x00, 0xc9, 0x4a, 0x1e, 14 | 0x40, 0xe6, 0x4d, 0xdb, 0x00, 0xc9, 0xd3, 0x00, 0xc9, 0x00, 0x00, 0x00, 15 | 0x00, 0x40, 0x30, 0x00, 0xcd, 0xff, 0xff, 0xff, 0xe9, 0x43, 0x00, 0xe8, 16 | 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0xff, 0xff, 0xb5, 17 | 0x40, 0x06, 0x29, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 18 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 19 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x29, 0x19, 0xff, 0xff, 20 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe8, 0x43, 0x00, 0x00, 0x00, 21 | 0x00, 0x00, 0x00, 0x00, 0xcb, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 22 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xeb, 0x43, 0xeb, 23 | 0x43, 0xeb, 0x43, 0xe8, 0x43, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 24 | 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 25 | 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 26 | 0x00, 0xb5, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 27 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 28 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 29 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 30 | 0x00, 0x00, 0xc3, 0x2d, 0x01, 0xc3, 0x2d, 0x01, 0xc3, 0x2d, 0x01, 0xc3, 31 | 0x2d, 0x01, 0xc3, 0x2d, 0x01, 0xc3, 0x2d, 0x01, 0xc3, 0x2d, 0x01, 0xc3, 32 | 0x2d, 0x01, 0xc3, 0x2d, 0x01, 0xc3, 0x2d, 0x01, 0xc3, 0x2d, 0x01, 0xc3, 33 | 0x2d, 0x01, 0xc3, 0x30, 0x30, 0xc3, 0x2d, 0x01, 0xc3, 0x2d, 0x01, 0xc3, 34 | 0x2d, 0x01, 0xc3, 0x2d, 0x01, 0xc3, 0x2d, 0x01, 0xc3, 0x2d, 0x01, 0xc3, 35 | 0x2d, 0x01, 0xc3, 0x2d, 0x01, 0xc3, 0x2d, 0x01, 0xc3, 0x2d, 0x01, 0xc3, 36 | 0x2d, 0x01, 0xc3, 0x2d, 0x01, 0xc3, 0x2d, 0x01, 0xc3, 0x2d, 0x01, 0xc3, 37 | 0x2d, 0x01, 0xc9, 0x00, 0x00, 0xc9, 0x00, 0x00, 0xc9, 0x00, 0x00, 0xc9, 38 | 0x00, 0x00, 0xc9, 0x00, 0x00, 0xc9, 0x00, 0x00, 0xc9, 0x00, 0x00, 0xc9, 39 | 0x00, 0x00, 0xc9, 0x00, 0x00, 0xc9, 0x00, 0x00, 0xc9, 0x00, 0x00, 0xc9, 40 | 0x00, 0x00, 0xc9, 0x00, 0x00, 0xc9, 0x00, 0x00, 0xc9, 0x00, 0x00, 0xc9, 41 | 0x00, 0x00, 0xc9, 0x00, 0x00, 0xc9, 0x00, 0x00, 0xc9, 0x00, 0x00, 0xc9, 42 | 0x00, 0x00, 0xc9, 0x00, 0x00, 0x01, 0x1e, 0x30, 0x00, 0x00, 0x00, 0x52, 43 | 0x49, 0x02, 0x21, 0x30, 0x00, 0x00, 0x00, 0x52, 0x4f, 0x02, 0x1b, 0x30, 44 | 0x55, 0x6c, 0xff, 0x52, 0x4e, 0x3c, 0x01, 0xdc 45 | }; 46 | unsigned int mem_dump_4000_4200_len = 512; 47 | -------------------------------------------------------------------------------- /src/loader/cmd/.gitignore: -------------------------------------------------------------------------------- 1 | *.bin 2 | *.c 3 | -------------------------------------------------------------------------------- /src/loader/cmd/Makefile: -------------------------------------------------------------------------------- 1 | 2 | .SUFFIXES: .asm .bin .c 3 | 4 | %.bin: %.asm 5 | %.c: %.bin 6 | 7 | 8 | GEN = loader_cmd.c 9 | 10 | %.bin: %.asm 11 | z80asm -i $< -o $@ 12 | 13 | %.c: %.bin 14 | xxd -i $< $@ 15 | 16 | all: $(GEN) 17 | cp $(GEN) ../../esp/components/retrostore/ 18 | 19 | clean: 20 | rm -f *.bin *.c 21 | 22 | -------------------------------------------------------------------------------- /src/loader/cmd/loader_cmd.asm: -------------------------------------------------------------------------------- 1 | 2 | CLS: equ 01c9h 3 | 4 | org 4300h 5 | 6 | ld hl,0ffffh 7 | ld a,56 8 | out (236),a 9 | ld a,3 10 | out (31),a 11 | out (31),a 12 | ld a,l 13 | out (31),a 14 | ld a,h 15 | out (31),a 16 | 17 | WAIT: 18 | in a,(0e0h) 19 | and 8 20 | jr nz,WAIT 21 | in a,(31) 22 | in a,(31) 23 | LOOP: 24 | in a,(31) 25 | ld e,a 26 | in a,(31) 27 | ld b,0 28 | ld c,a 29 | dec e 30 | jr nz,check_entry 31 | or a 32 | jr z,need_offset 33 | dec a 34 | jr z,need_offset 35 | dec a 36 | jr z,need_offset 37 | jr no_offset 38 | need_offset: 39 | ld hl,256 40 | add hl,bc 41 | ld c,l 42 | ld b,h 43 | no_offset: 44 | dec bc 45 | dec bc 46 | in a,(31) 47 | ld l,a 48 | in a,(31) 49 | ld h,a 50 | load_cmd: 51 | ld a,b 52 | or c 53 | jr z,LOOP 54 | in a,(31) 55 | ld (hl),a 56 | inc hl 57 | dec bc 58 | jr load_cmd 59 | check_entry: 60 | dec e 61 | jr nz,check_skip 62 | in a,(31) 63 | ld l,a 64 | in a,(31) 65 | ld h,a 66 | jp (hl) 67 | check_skip: 68 | dec e 69 | dec e 70 | dec e 71 | jr nz,bad_cmd 72 | skip: 73 | ld a,b 74 | or c 75 | jr z,LOOP 76 | in a,(31) 77 | dec bc 78 | jr skip 79 | bad_cmd: 80 | ld a,'*' 81 | call 033Ah 82 | endless_loop: 83 | jr endless_loop 84 | 85 | -------------------------------------------------------------------------------- /src/modules/Makefile: -------------------------------------------------------------------------------- 1 | 2 | MAKE = make 3 | 4 | #DIRS = trs-io-fs 5 | DIRS = 6 | 7 | 8 | all: 9 | for i in $(DIRS); do $(MAKE) -C $$i || exit 1; done 10 | 11 | clean: 12 | for i in $(DIRS); do $(MAKE) -C $$i clean || exit 1; done 13 | -------------------------------------------------------------------------------- /src/modules/trs-io-fs/.gitignore: -------------------------------------------------------------------------------- 1 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 2 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 3 | 4 | # User-specific stuff 5 | .idea/**/workspace.xml 6 | .idea/**/tasks.xml 7 | .idea/**/usage.statistics.xml 8 | .idea/**/dictionaries 9 | .idea/**/shelf 10 | 11 | # Generated files 12 | .idea/**/contentModel.xml 13 | 14 | # Sensitive or high-churn files 15 | .idea/**/dataSources/ 16 | .idea/**/dataSources.ids 17 | .idea/**/dataSources.local.xml 18 | .idea/**/sqlDataSources.xml 19 | .idea/**/dynamic.xml 20 | .idea/**/uiDesigner.xml 21 | .idea/**/dbnavigator.xml 22 | 23 | # Gradle 24 | .idea/**/gradle.xml 25 | .idea/**/libraries 26 | 27 | # Gradle and Maven with auto-import 28 | # When using Gradle or Maven with auto-import, you should exclude module files, 29 | # since they will be recreated, and may cause churn. Uncomment if using 30 | # auto-import. 31 | # .idea/modules.xml 32 | # .idea/*.iml 33 | # .idea/modules 34 | 35 | # CMake 36 | cmake-build-*/ 37 | 38 | # Mongo Explorer plugin 39 | .idea/**/mongoSettings.xml 40 | 41 | # File-based project format 42 | *.iws 43 | 44 | # IntelliJ 45 | out/ 46 | 47 | # mpeltonen/sbt-idea plugin 48 | .idea_modules/ 49 | 50 | # JIRA plugin 51 | atlassian-ide-plugin.xml 52 | 53 | # Cursive Clojure plugin 54 | .idea/replstate.xml 55 | 56 | # Crashlytics plugin (for Android Studio and IntelliJ) 57 | com_crashlytics_export_strings.xml 58 | crashlytics.properties 59 | crashlytics-build.properties 60 | fabric.properties 61 | 62 | # Editor-based Rest Client 63 | .idea/httpRequests 64 | 65 | # Android studio 3.1+ serialized cache file 66 | .idea/caches/build_file_checksums.ser 67 | 68 | build/ 69 | 70 | .gradle/ 71 | 72 | -------------------------------------------------------------------------------- /src/modules/trs-io-fs/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/modules/trs-io-fs/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: 3 | ./gradlew fatJar 4 | 5 | clean: 6 | ./gradlew clean 7 | 8 | -------------------------------------------------------------------------------- /src/modules/trs-io-fs/build.gradle: -------------------------------------------------------------------------------- 1 | 2 | apply plugin: 'java' 3 | apply plugin: 'application' 4 | 5 | mainClassName = 'org.trsio.fs.Main' 6 | 7 | repositories { 8 | jcenter() 9 | } 10 | 11 | task fatJar(type: Jar) { 12 | manifest { 13 | attributes 'Main-Class': mainClassName 14 | } 15 | baseName = project.name + '-all' 16 | from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } 17 | with jar 18 | } 19 | 20 | dependencies { 21 | compile 'org.slf4j:slf4j-api:1.7.13' 22 | compile 'com.fazecast:jSerialComm:[2.0.0,3.0.0)' 23 | 24 | testCompile 'junit:junit:3.8.2' 25 | } 26 | -------------------------------------------------------------------------------- /src/modules/trs-io-fs/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pski/trsnic/6ae25e1bb3c1a476fea5f019afc2290e951aeb3e/src/modules/trs-io-fs/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /src/modules/trs-io-fs/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Apr 12 13:17:08 PDT 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip 7 | -------------------------------------------------------------------------------- /src/modules/trs-io-fs/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /src/modules/trs-io-fs/settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This settings file was auto generated by the Gradle buildInit task 3 | * by 'arno' at '4/12/19 8:10 PM' with Gradle 2.10 4 | * 5 | * The settings file is used to specify which projects to include in your build. 6 | * In a single project build this file can be empty or even removed. 7 | * 8 | * Detailed information about configuring a multi-project build in Gradle can be found 9 | * in the user guide at https://docs.gradle.org/2.10/userguide/multi_project_builds.html 10 | */ 11 | 12 | /* 13 | // To declare projects as part of a multi-project build use the 'include' method 14 | include 'shared' 15 | include 'api' 16 | include 'services:webservice' 17 | */ 18 | 19 | rootProject.name = 'trsio-fs' 20 | -------------------------------------------------------------------------------- /src/modules/trs-io-fs/src/main/java/org/trsio/fs/BaseIO.java: -------------------------------------------------------------------------------- 1 | package org.trsio.fs; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.io.OutputStream; 6 | import java.util.Arrays; 7 | 8 | public class BaseIO { 9 | 10 | protected OutputStream out; 11 | protected InputStream in; 12 | 13 | public boolean isOpen() { 14 | return (in != null) && (out != null); 15 | } 16 | 17 | public byte readByte() { 18 | try { 19 | while (true) { 20 | int b = in.read(); 21 | if (b == -1) { 22 | continue; 23 | } 24 | return (byte) b; 25 | } 26 | } catch (IOException e) { 27 | return 0; 28 | } 29 | } 30 | 31 | public byte[] readBlob() { 32 | int btr = ((readByte() & 0xff) | ((readByte() & 0xff) << 8)) & 0xffff; 33 | byte[] data = new byte[btr]; 34 | try { 35 | int read = 0; 36 | while (read != btr) { 37 | int br = in.read(data, read, btr - read); 38 | if (br == -1) { 39 | //TODO actually, this shouldn't happen since the client is expected to send that many bytes 40 | return Arrays.copyOfRange(data, 0, read); 41 | } 42 | read += br; 43 | } 44 | } catch (IOException e) { 45 | return new byte[0]; 46 | } 47 | return data; 48 | } 49 | 50 | public void writeByte(byte b) { 51 | try { 52 | out.write((int) b & 0xff); 53 | out.flush(); 54 | } catch (IOException e) { 55 | } 56 | } 57 | 58 | public void writeBlob(byte[] data) { 59 | int len = data.length; 60 | writeByte((byte) (len & 0xff)); 61 | writeByte((byte) ((len >> 8) & 0xff)); 62 | try { 63 | out.write(data); 64 | out.flush(); 65 | } catch (IOException e) { 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/modules/trs-io-fs/src/main/java/org/trsio/fs/ChannelIO.java: -------------------------------------------------------------------------------- 1 | package org.trsio.fs; 2 | 3 | public interface ChannelIO { 4 | byte readByte(); 5 | byte[] readBlob(); 6 | void writeByte(byte b); 7 | void writeBlob(byte[] data); 8 | } 9 | -------------------------------------------------------------------------------- /src/modules/trs-io-fs/src/main/java/org/trsio/fs/FRESULT.java: -------------------------------------------------------------------------------- 1 | package org.trsio.fs; 2 | 3 | public class FRESULT { 4 | final public static byte FR_OK = 0; /* (0) Succeeded */ 5 | final public static byte FR_DISK_ERR = 1; /* (1) A hard error occurred in the low level disk I/O layer */ 6 | final public static byte FR_INT_ERR = 2; /* (2) Assertion failed */ 7 | final public static byte FR_NOT_READY = 3; /* (3) The physical drive cannot work */ 8 | final public static byte FR_NO_FILE = 4; /* (4) Could not find the file */ 9 | final public static byte FR_NO_PATH = 5; /* (5) Could not find the path */ 10 | final public static byte FR_INVALID_NAME = 6; /* (6) The path name format is invalid */ 11 | final public static byte FR_DENIED = 7; /* (7) Access denied due to prohibited access or directory full */ 12 | final public static byte FR_EXIST = 8; /* (8) Access denied due to prohibited access */ 13 | final public static byte FR_INVALID_OBJECT = 9; /* (9) The file/directory object is invalid */ 14 | final public static byte FR_WRITE_PROTECTED = 10;/* (10) The physical drive is write protected */ 15 | final public static byte FR_INVALID_DRIVE = 11; /* (11) The logical drive number is invalid */ 16 | final public static byte FR_NOT_ENABLED = 12; /* (12) The volume has no work area */ 17 | final public static byte FR_NO_FILESYSTEM = 13; /* (13) There is no valid FAT volume */ 18 | final public static byte FR_MKFS_ABORTED = 14; /* (14) The f_mkfs() aborted due to any problem */ 19 | final public static byte FR_TIMEOUT = 15; /* (15) Could not get a grant to access the volume within defined period */ 20 | final public static byte FR_LOCKED = 16; /* (16) The operation is rejected according to the file sharing policy */ 21 | final public static byte FR_NOT_ENOUGH_CORE = 17;/* (17) LFN working buffer could not be allocated */ 22 | final public static byte FR_TOO_MANY_OPEN_FILES = 18;/* (18) Number of open files > FF_FS_LOCK */ 23 | final public static byte FR_INVALID_PARAMETER = 19; /* (19) Given parameter is invalid */ 24 | final public static byte FR_DISK_FULL = 20; 25 | } 26 | -------------------------------------------------------------------------------- /src/modules/trs-io-fs/src/main/java/org/trsio/fs/Main.java: -------------------------------------------------------------------------------- 1 | package org.trsio.fs; 2 | 3 | 4 | public class Main { 5 | 6 | public static void main(String[] args) { 7 | if (args.length != 1) { 8 | System.err.println("Usage: trs-io-fs "); 9 | System.exit(-1); 10 | } 11 | //SocketIO channel = new SocketIO(); 12 | SerialIO channel = new SerialIO(args[0]); 13 | if (!channel.isOpen()) { 14 | System.err.println("Could not open " + args[0]); 15 | System.exit(-1); 16 | } 17 | FileIO fileIO = new FileIO(channel); 18 | fileIO.start(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/modules/trs-io-fs/src/main/java/org/trsio/fs/OpenMode.java: -------------------------------------------------------------------------------- 1 | package org.trsio.fs; 2 | 3 | public class OpenMode { 4 | final public static byte FA_READ = 0x01; 5 | final public static byte FA_WRITE = 0x02; 6 | final public static byte FA_OPEN_EXISTING = 0x00; 7 | final public static byte FA_CREATE_NEW = 0x04; 8 | final public static byte FA_CREATE_ALWAYS = 0x08; 9 | final public static byte FA_OPEN_ALWAYS = 0x10; 10 | final public static byte FA_OPEN_APPEND = 0x30; 11 | } 12 | -------------------------------------------------------------------------------- /src/modules/trs-io-fs/src/main/java/org/trsio/fs/SerialIO.java: -------------------------------------------------------------------------------- 1 | package org.trsio.fs; 2 | 3 | 4 | import com.fazecast.jSerialComm.SerialPort; 5 | 6 | public class SerialIO extends BaseIO implements ChannelIO { 7 | 8 | public SerialIO(String portName) { 9 | connect(portName); 10 | } 11 | 12 | private void connect(String portName) { 13 | SerialPort comPort = SerialPort.getCommPort(portName); 14 | comPort.setBaudRate(115200); 15 | comPort.setNumDataBits(8); 16 | comPort.setNumStopBits(1); 17 | comPort.setParity(SerialPort.NO_PARITY); 18 | comPort.openPort(); 19 | comPort.setComPortTimeouts(SerialPort.TIMEOUT_READ_SEMI_BLOCKING, 0, 0); 20 | in = comPort.getInputStream(); 21 | out = comPort.getOutputStream(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/modules/trs-io-fs/src/main/java/org/trsio/fs/SocketIO.java: -------------------------------------------------------------------------------- 1 | package org.trsio.fs; 2 | 3 | import java.io.*; 4 | import java.net.ServerSocket; 5 | import java.net.Socket; 6 | 7 | public class SocketIO extends BaseIO implements ChannelIO { 8 | 9 | public SocketIO() { 10 | in = null; 11 | out = null; 12 | ServerSocket serverSocket = null; 13 | try { 14 | serverSocket = new ServerSocket(8088); 15 | Socket clientSocket = serverSocket.accept(); 16 | out = clientSocket.getOutputStream(); 17 | in = clientSocket.getInputStream(); 18 | } catch (IOException e) { 19 | in = null; 20 | out = null; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/trs/.gitignore: -------------------------------------------------------------------------------- 1 | *.rel 2 | *.lk 3 | *.lst 4 | *~ 5 | *.noi 6 | *.ihx 7 | *.map 8 | *.asm 9 | *.sym 10 | *.cmd 11 | rsclient.c 12 | -------------------------------------------------------------------------------- /src/trs/Makefile: -------------------------------------------------------------------------------- 1 | 2 | CC = sdcc 3 | AS = sdasz80 4 | LD = sdldz80 5 | IHEX2CMD = ../ihex2cmd/ihex2cmd 6 | CFLAGS = -mz80 --std-sdcc99 --opt-code-size 7 | ASFLAGS = -l 8 | LDFLAGS = -mjwx -b _CODE=0x5200 -l $(SDCC_PATH)/lib/z80/z80.lib 9 | 10 | OBJS = \ 11 | crt0.rel \ 12 | main.rel \ 13 | inout.rel \ 14 | key.rel \ 15 | window.rel \ 16 | browse.rel \ 17 | form.rel \ 18 | header.rel \ 19 | list.rel \ 20 | menu.rel \ 21 | wifi.rel \ 22 | esp.rel \ 23 | help.rel \ 24 | about.rel \ 25 | panic.rel \ 26 | font.rel 27 | 28 | %.rel: %.c 29 | $(CC) $(CFLAGS) -c $< 30 | 31 | %.rel: %.s 32 | $(AS) $(ASFLAGS) -o $@ $< 33 | 34 | %.cmd: %.ihx 35 | $(IHEX2CMD) $< $@ 36 | 37 | all: rsclient.c 38 | 39 | rsclient.c: rsclient.cmd 40 | xxd -i rsclient.cmd rsclient.c 41 | cp rsclient.c ../esp/components/retrostore/ 42 | 43 | rsclient.ihx : $(OBJS) Makefile 44 | $(LD) $(LDFLAGS) -i rsclient.ihx $(OBJS) 45 | 46 | 47 | clean: 48 | rm -f *.rel 49 | rm -f *.lk 50 | rm -f *.lst 51 | rm -f *~ 52 | rm -f *.noi 53 | rm -f *.ihx 54 | rm -f *.map 55 | rm -f *.asm 56 | rm -f *.sym 57 | rm -f *.cmd 58 | 59 | -------------------------------------------------------------------------------- /src/trs/about.c: -------------------------------------------------------------------------------- 1 | #include "retrostore.h" 2 | #include "version.h" 3 | 4 | static window_t wnd; 5 | 6 | static void print_details(window_t* wnd, uint8_t cmd, const char* label) 7 | { 8 | char ch[2] = "."; 9 | 10 | wnd_print(wnd, false, label); 11 | out(TRS_IO_PORT, TRS_IO_CORE_MODULE_ID); 12 | out(TRS_IO_PORT, cmd); 13 | wait_for_esp(); 14 | while (true) { 15 | ch[0] = in(TRS_IO_PORT); 16 | if (ch[0] == '\0') { 17 | break; 18 | } 19 | wnd_print(wnd, false, ch); 20 | } 21 | wnd_cr(wnd); 22 | } 23 | 24 | void about() 25 | { 26 | char* status; 27 | uint8_t scan_result; 28 | uint8_t revision; 29 | uint16_t version; 30 | 31 | init_window(&wnd, 0, 3, 0, 0); 32 | header(&wnd, "About"); 33 | 34 | scan_result = scan(); 35 | get_trs_io_version(&revision, &version); 36 | 37 | wnd_print(&wnd, false, "TRS-IO hardware revision : "); 38 | if (scan_result == RS_STATUS_NO_RETROSTORE_CARD) { 39 | wnd_print(&wnd, false, "not present"); 40 | } else { 41 | wnd_print_int(&wnd, revision); 42 | } 43 | wnd_cr(&wnd); 44 | 45 | wnd_print(&wnd, false, "TRS-IO core module version : "); 46 | if (scan_result == RS_STATUS_NO_RETROSTORE_CARD) { 47 | wnd_print(&wnd, false, "-"); 48 | } else { 49 | wnd_print_int(&wnd, version >> 8); 50 | wnd_print(&wnd, false, "."); 51 | wnd_print_int(&wnd, version & 0xff); 52 | } 53 | wnd_cr(&wnd); 54 | 55 | get_retrostore_version(&version); 56 | wnd_print(&wnd, false, "RetroStore module version : "); 57 | if (scan_result == RS_STATUS_NO_RETROSTORE_CARD) { 58 | wnd_print(&wnd, false, "-"); 59 | } else { 60 | wnd_print_int(&wnd, version >> 8); 61 | wnd_print(&wnd, false, "."); 62 | wnd_print_int(&wnd, version & 0xff); 63 | } 64 | wnd_cr(&wnd); 65 | 66 | wnd_print(&wnd, false, "RetroStore client version : "); 67 | wnd_print_int(&wnd, RS_CLIENT_VERSION_MAJOR); 68 | wnd_print(&wnd, false, "."); 69 | wnd_print_int(&wnd, RS_CLIENT_VERSION_MINOR); 70 | wnd_cr(&wnd); 71 | 72 | switch(scan_result) { 73 | case RS_STATUS_WIFI_NOT_NEEDED: 74 | status = "emulation mode"; 75 | break; 76 | case RS_STATUS_WIFI_CONNECTING: 77 | status = "WiFi connecting"; 78 | break; 79 | case RS_STATUS_WIFI_CONNECTED: 80 | status = "WiFi connected"; 81 | break; 82 | case RS_STATUS_WIFI_NOT_CONNECTED: 83 | status = "WiFi not connected"; 84 | break; 85 | case RS_STATUS_WIFI_NOT_CONFIGURED: 86 | status = "WiFi not configured"; 87 | break; 88 | case RS_STATUS_NO_RETROSTORE_CARD: 89 | status = "not present"; 90 | break; 91 | default: 92 | status = ""; 93 | } 94 | wnd_print(&wnd, false, "TRS-IO online status : "); 95 | wnd_print(&wnd, false, status); 96 | wnd_cr(&wnd); 97 | 98 | print_details(&wnd, TRS_IO_SEND_WIFI_SSID, "WiFi SSID: "); 99 | print_details(&wnd, TRS_IO_SEND_WIFI_IP, "WiFi IP : "); 100 | 101 | wnd_show(&wnd, false); 102 | get_key(); 103 | } 104 | -------------------------------------------------------------------------------- /src/trs/about.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __ABOUT_H__ 3 | #define __ABOUT_H__ 4 | 5 | void about(); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /src/trs/browse.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __BROWSE_H__ 3 | #define __BROWSE_H__ 4 | 5 | #include "window.h" 6 | 7 | uint16_t browse_retrostore(window_t* wnd); 8 | uint16_t search_retrostore(window_t* wnd); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/trs/crt0.s: -------------------------------------------------------------------------------- 1 | ;-------------------------------------------------------------------------- 2 | ; crt0.s - Generic crt0.s for a Z80 3 | ; 4 | ; Copyright (C) 2000, Michael Hope 5 | ; 6 | ; This library is free software; you can redistribute it and/or modify it 7 | ; under the terms of the GNU General Public License as published by the 8 | ; Free Software Foundation; either version 2, or (at your option) any 9 | ; later version. 10 | ; 11 | ; This library is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this library; see the file COPYING. If not, write to the 18 | ; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, 19 | ; MA 02110-1301, USA. 20 | ; 21 | ; As a special exception, if you link this library with other files, 22 | ; some of which are compiled with SDCC, to produce an executable, 23 | ; this library does not by itself cause the resulting executable to 24 | ; be covered by the GNU General Public License. This exception does 25 | ; not however invalidate any other reasons why the executable file 26 | ; might be covered by the GNU General Public License. 27 | ;-------------------------------------------------------------------------- 28 | 29 | ; Modified by AP for TRS-80 30 | 31 | .module crt0 32 | .globl _main 33 | .globl l__INITIALIZER 34 | .globl s__INITIALIZER 35 | .globl s__INITIALIZED 36 | .globl l__DATA 37 | .globl s__DATA 38 | 39 | init: 40 | ;; Set stack pointer directly above top of memory. 41 | ld sp,#0x0000 42 | 43 | ;; Initialise global variables 44 | call gsinit 45 | call _main 46 | _halt: 47 | jp _halt 48 | 49 | ;; Ordering of segments for the linker. 50 | .area _HOME 51 | .area _CODE 52 | .area _INITIALIZER 53 | .area _GSINIT 54 | .area _GSFINAL 55 | 56 | .area _DATA 57 | .area _INITIALIZED 58 | .area _BSEG 59 | .area _BSS 60 | .area _HEAP 61 | 62 | .area _CODE 63 | 64 | .area _GSINIT 65 | gsinit:: 66 | ld bc, #l__INITIALIZER 67 | ld a, b 68 | or a, c 69 | jr Z, gsinit_next 70 | ld de, #s__INITIALIZED 71 | ld hl, #s__INITIALIZER 72 | ldir 73 | gsinit_next: 74 | 75 | .area _GSFINAL 76 | ret 77 | 78 | -------------------------------------------------------------------------------- /src/trs/defs.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __DEFS_H__ 3 | #define __DEFS_H__ 4 | 5 | #include 6 | 7 | typedef signed char int8_t; 8 | typedef unsigned char uint8_t; 9 | typedef signed int int16_t; 10 | typedef unsigned int uint16_t; 11 | typedef uint8_t bool; 12 | 13 | #define true 1 14 | #define false 0 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/trs/esp.c: -------------------------------------------------------------------------------- 1 | 2 | #include "retrostore.h" 3 | 4 | void wait_for_esp() 5 | { 6 | while (in(0xe0) & 8) ; 7 | } 8 | 9 | uint8_t scan() 10 | { 11 | uint16_t i = 0; 12 | uint8_t status = RS_STATUS_NO_RETROSTORE_CARD; 13 | 14 | out(TRS_IO_PORT, TRS_IO_CORE_MODULE_ID); 15 | out(TRS_IO_PORT, TRS_IO_SEND_STATUS); 16 | 17 | while (++i != 0 && status == RS_STATUS_NO_RETROSTORE_CARD) { 18 | status = in(TRS_IO_PORT); 19 | } 20 | return status; 21 | } 22 | 23 | void get_trs_io_version(uint8_t* revision, uint16_t* version) 24 | { 25 | uint8_t version_minor; 26 | uint8_t version_major; 27 | 28 | out(TRS_IO_PORT, TRS_IO_CORE_MODULE_ID); 29 | out(TRS_IO_PORT, RS_SEND_VERSION); 30 | wait_for_esp(); 31 | *revision = in(TRS_IO_PORT); 32 | version_major = in(TRS_IO_PORT); 33 | version_minor = in(TRS_IO_PORT); 34 | *version = (version_major << 8) | version_minor; 35 | } 36 | 37 | void get_retrostore_version(uint16_t* version) 38 | { 39 | uint8_t version_minor; 40 | uint8_t version_major; 41 | 42 | out(TRS_IO_PORT, RETROSTORE_MODULE_ID); 43 | out(TRS_IO_PORT, RS_SEND_VERSION); 44 | wait_for_esp(); 45 | version_major = in(TRS_IO_PORT); 46 | version_minor = in(TRS_IO_PORT); 47 | *version = (version_major << 8) | version_minor; 48 | } 49 | -------------------------------------------------------------------------------- /src/trs/esp.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __ESP_H__ 3 | #define __ESP_H__ 4 | 5 | #include "defs.h" 6 | 7 | #define RS_STATUS_WIFI_NOT_NEEDED 0 8 | #define RS_STATUS_WIFI_CONNECTING 1 9 | #define RS_STATUS_WIFI_CONNECTED 2 10 | #define RS_STATUS_WIFI_NOT_CONNECTED 3 11 | #define RS_STATUS_WIFI_NOT_CONFIGURED 4 12 | #define RS_STATUS_NO_RETROSTORE_CARD 0xff 13 | 14 | void wait_for_esp(); 15 | uint8_t scan(); 16 | void get_trs_io_version(uint8_t* revision, uint16_t* version); 17 | void get_retrostore_version(uint16_t* version); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/trs/form.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __FORM_H__ 3 | #define __FORM_H__ 4 | 5 | #include "defs.h" 6 | #include "window.h" 7 | #include "key.h" 8 | #include "panic.h" 9 | 10 | #define FORM_OK 0 11 | #define FORM_ABORT 1 12 | 13 | #define FORM_TYPE_END 0 14 | #define FORM_TYPE_TEXT 1 15 | #define FORM_TYPE_INPUT 2 16 | 17 | #define FORM_CURSOR "\260" 18 | 19 | typedef struct { 20 | uint8_t len; 21 | const char* buf; 22 | } form_input_t; 23 | 24 | typedef struct { 25 | uint8_t type; 26 | int8_t x, y; 27 | union { 28 | const char* text; 29 | form_input_t input; 30 | } u; 31 | } form_t; 32 | 33 | uint8_t form(window_t* wnd, const char* title, form_t* form, 34 | bool show_from_left); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/trs/hardware.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __HARDWARE_H__ 3 | #define __HARDWARE_H__ 4 | 5 | #define SCREEN_BASE 0x3c00 6 | #define SCREEN_WIDTH 64 7 | #define SCREEN_HEIGHT 16 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/trs/header.c: -------------------------------------------------------------------------------- 1 | 2 | #include "header.h" 3 | 4 | extern unsigned char console_font_5x8[]; 5 | 6 | #define FONT_WIDTH 5 7 | #define FONT_HEIGHT 8 8 | #define FONT_HEIGHT_OFFSET 2 9 | 10 | static void set_pixel(window_t* wnd, uint8_t x, uint8_t y) { 11 | uint8_t b, ox, oy; 12 | uint8_t* p; 13 | 14 | p = wnd->buffer + (y / 3) * 64 + (x / 2); 15 | b = *p; 16 | if (b < 128 || b > 191) { 17 | b = 128; 18 | } 19 | ox = x % 2; 20 | oy = y % 3; 21 | b |= 1 << (ox + oy * 2); 22 | *p = b; 23 | } 24 | 25 | static void cls(window_t* wnd) { 26 | uint8_t* p = wnd->buffer; 27 | int i; 28 | 29 | for (i = 0; i < SCREEN_WIDTH * SCREEN_HEIGHT; i++) { 30 | *p++ = ' '; 31 | } 32 | } 33 | 34 | static void draw_text(window_t* wnd, uint8_t x, uint8_t y, char* txt) { 35 | int i, j; 36 | char b; 37 | 38 | while (*txt != '\0') { 39 | unsigned int idx = *txt++ * FONT_HEIGHT + FONT_HEIGHT_OFFSET; 40 | for (i = 0; i < FONT_HEIGHT - FONT_HEIGHT_OFFSET; i++) { 41 | b = console_font_5x8[idx++]; 42 | for (j = 0; j < FONT_WIDTH; j++) { 43 | if (b & (1 << (7 - j))) { 44 | set_pixel(wnd, x + j, y + i); 45 | } 46 | } 47 | } 48 | x += FONT_WIDTH + 1; 49 | } 50 | } 51 | 52 | static void draw_horizontal_line(window_t* wnd, uint8_t x0, uint8_t x1, 53 | uint8_t y) { 54 | int i; 55 | for (i = x0; i < x1; i++) { 56 | set_pixel(wnd, i, y); 57 | } 58 | } 59 | 60 | void header(window_t* wnd, const char* banner) { 61 | cls(wnd); 62 | draw_text(wnd, 0, 0, banner); 63 | draw_horizontal_line(wnd, 0, 128, FONT_HEIGHT - FONT_HEIGHT_OFFSET + 1); 64 | } 65 | -------------------------------------------------------------------------------- /src/trs/header.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __HEADER_H__ 3 | #define __HEADER_H__ 4 | 5 | #include "window.h" 6 | 7 | void header(window_t* wnd, const char* banner); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/trs/help.c: -------------------------------------------------------------------------------- 1 | 2 | #include "retrostore.h" 3 | 4 | static window_t wnd; 5 | 6 | void help() 7 | { 8 | init_window(&wnd, 0, 3, 0, 0); 9 | header(&wnd, "Help"); 10 | wnd_print(&wnd, false, "\nVisit https://github.com/apuder/TRS-IO for " 11 | "complete online documentation."); 12 | wnd_show(&wnd, false); 13 | get_key(); 14 | } 15 | -------------------------------------------------------------------------------- /src/trs/help.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __HELP_H__ 3 | #define __HELP_H__ 4 | 5 | void help(); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /src/trs/inout.c: -------------------------------------------------------------------------------- 1 | 2 | #include "inout.h" 3 | #include "hardware.h" 4 | 5 | void out(uint8_t port, uint8_t val) 6 | { 7 | __asm 8 | pop hl ; ret 9 | pop bc ; port->c, val->b 10 | push bc 11 | push hl 12 | out (c),b 13 | __endasm; 14 | } 15 | 16 | uint8_t in(uint8_t port) 17 | { 18 | __asm 19 | pop hl ; ret 20 | pop bc ; port->c 21 | push bc 22 | push hl 23 | in l,(c) 24 | __endasm; 25 | } 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/trs/inout.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __INOUT_H__ 3 | #define __INOUT_H__ 4 | 5 | #include "defs.h" 6 | 7 | void out(uint8_t port, uint8_t val); 8 | uint8_t in(uint8_t port); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/trs/key.c: -------------------------------------------------------------------------------- 1 | 2 | #include "key.h" 3 | 4 | char get_key() { 5 | __asm 6 | push de 7 | call 0x0049 8 | pop de 9 | ld l,a 10 | __endasm; 11 | } 12 | -------------------------------------------------------------------------------- /src/trs/key.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __KEY_H__ 3 | #define __KEY_H__ 4 | 5 | #define KEY_ENTER 0x0d 6 | #define KEY_BREAK 0x01 7 | #define KEY_CLEAR 0x1f 8 | 9 | #define KEY_UP 0x5b 10 | #define KEY_DOWN 0x0a 11 | #define KEY_RIGHT 0x09 12 | #define KEY_LEFT 0x08 13 | 14 | char get_key(); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/trs/list.c: -------------------------------------------------------------------------------- 1 | 2 | #include "retrostore.h" 3 | 4 | 5 | static window_t wnd_sel; 6 | static window_t wnd_desc; 7 | 8 | void init_list(list_t* list, const char* title, 9 | list_get_item_t get_item) { 10 | list->title = title; 11 | list->get_item = get_item; 12 | list->sel = 0; 13 | list->start_idx = 0; 14 | } 15 | 16 | uint16_t list(window_t* wnd, 17 | list_t* list, 18 | bool show_from_left, 19 | bool can_abort) 20 | { 21 | const char* name; 22 | uint16_t i; 23 | wnd_switch_to_background(wnd); 24 | header(wnd, list->title); 25 | init_window(&wnd_sel, 0, 3, 2, 0); 26 | init_window(&wnd_desc, 3, 3, 0, 0); 27 | wnd_print(&wnd_sel, false, LIST_HIGHLIGHT); 28 | for (i = 0; i < list->sel; i++) { 29 | wnd_scroll_down(&wnd_sel); 30 | } 31 | for (i = 0; i < wnd_desc.h; i++) { 32 | if (!list->get_item(list->start_idx + i, &name)) { 33 | break; 34 | } 35 | wnd_print(&wnd_desc, true, name); 36 | wnd_cr(&wnd_desc); 37 | } 38 | if (i == 0) { 39 | wnd_popup(wnd, "No items"); 40 | } 41 | wnd_show(wnd, show_from_left); 42 | if (i == 0) { 43 | get_key(); 44 | return LIST_EXIT; 45 | } 46 | wnd_sel.buffer = wnd->buffer; 47 | wnd_desc.buffer = wnd->buffer; 48 | 49 | while (true) { 50 | char ch = get_key(); 51 | switch(ch) { 52 | case KEY_BREAK: 53 | case KEY_LEFT: 54 | case KEY_CLEAR: 55 | if (can_abort) { 56 | return LIST_EXIT; 57 | } 58 | break; 59 | case KEY_ENTER: 60 | case KEY_RIGHT: 61 | return list->start_idx + list->sel; 62 | case KEY_UP: 63 | if (list->sel == 0 && list->start_idx == 0) { 64 | continue; 65 | } 66 | if (list->sel == 0) { 67 | wnd_scroll_down(&wnd_desc); 68 | list->start_idx--; 69 | list->get_item(list->start_idx, &name); 70 | wnd_print(&wnd_desc, true, name); 71 | } else { 72 | list->sel--; 73 | wnd_scroll_up(&wnd_sel); 74 | } 75 | break; 76 | case KEY_DOWN: 77 | if (list->sel == wnd_sel.h - 1) { 78 | if (list->get_item(list->start_idx + list->sel + 1, &name)) { 79 | wnd_scroll_up(&wnd_desc); 80 | list->start_idx++; 81 | wnd_print(&wnd_desc, true, name); 82 | } 83 | } else { 84 | if (list->get_item(list->start_idx + list->sel + 1, &name)) { 85 | wnd_scroll_down(&wnd_sel); 86 | list->sel++; 87 | } 88 | } 89 | break; 90 | default: 91 | break; 92 | } 93 | } 94 | 95 | return LIST_EXIT; 96 | } 97 | -------------------------------------------------------------------------------- /src/trs/list.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __LIST_H__ 3 | #define __LIST_H__ 4 | 5 | #include "window.h" 6 | 7 | #define LIST_EXIT ((uint16_t) 0xffff) 8 | 9 | #define LIST_HIGHLIGHT1 "->" 10 | #define LIST_HIGHLIGHT2 "\214\235" 11 | #define LIST_HIGHLIGHT LIST_HIGHLIGHT1 12 | 13 | typedef bool (*list_get_item_t)(uint16_t, const char** name); 14 | 15 | typedef struct { 16 | const char* title; 17 | list_get_item_t get_item; 18 | uint8_t sel; 19 | uint16_t start_idx; 20 | } list_t; 21 | 22 | void init_list(list_t* menu, const char* title, list_get_item_t get_item); 23 | uint16_t list(window_t* wnd, list_t* list, bool show_from_left, bool can_abort); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /src/trs/menu.c: -------------------------------------------------------------------------------- 1 | 2 | #include "menu.h" 3 | 4 | static menu_t* the_menu; 5 | 6 | static bool menu_get_item(uint16_t idx, const char** name) { 7 | if (idx >= the_menu->num) { 8 | return false; 9 | } 10 | *name = the_menu->items[idx].option; 11 | return true; 12 | } 13 | 14 | uint8_t menu(window_t* wnd, menu_t* menu, bool show_from_left, bool can_abort) 15 | { 16 | uint16_t idx; 17 | the_menu = menu; 18 | if (!menu->list_initialized) { 19 | init_list(&menu->list, menu->title, menu_get_item); 20 | menu->list_initialized = true; 21 | } 22 | idx = list(wnd, &menu->list, show_from_left, can_abort); 23 | return (idx == LIST_EXIT) ? MENU_EXIT : menu->items[idx].id; 24 | } 25 | -------------------------------------------------------------------------------- /src/trs/menu.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __MENU_H__ 3 | #define __MENU_H__ 4 | 5 | #include "window.h" 6 | #include "list.h" 7 | 8 | #define MENU_EXIT 0xff 9 | 10 | #define MENU(name, title) \ 11 | static menu_t name = { \ 12 | title, \ 13 | sizeof(name ## _items) / sizeof(menu_item_t), \ 14 | name ## _items, \ 15 | false \ 16 | } 17 | 18 | typedef struct { 19 | uint8_t id; 20 | const char* option; 21 | } menu_item_t; 22 | 23 | typedef struct { 24 | const char* title; 25 | uint8_t num; 26 | menu_item_t* items; 27 | bool list_initialized; 28 | list_t list; 29 | } menu_t; 30 | 31 | uint8_t menu(window_t* wnd, menu_t* menu, bool show_from_left, bool can_abort); 32 | 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/trs/panic.c: -------------------------------------------------------------------------------- 1 | 2 | #include "panic.h" 3 | 4 | void panic(uint8_t errno) { 5 | //TODO show error 6 | while(1); 7 | } 8 | -------------------------------------------------------------------------------- /src/trs/panic.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __PANIC_H__ 3 | #define __PANIC_H__ 4 | 5 | #include "defs.h" 6 | 7 | #define ERR_BAD_FORM_TYPE 0 8 | #define ERR_TOO_MANY_INPUT_FIELDS 1 9 | 10 | void panic(uint8_t errno); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /src/trs/retrostore.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __RETROSTORE_H__ 3 | #define __RETROSTORE_H__ 4 | 5 | #include "inout.h" 6 | #include "key.h" 7 | #include "window.h" 8 | #include "form.h" 9 | #include "header.h" 10 | #include "list.h" 11 | #include "menu.h" 12 | #include "wifi.h" 13 | #include "browse.h" 14 | #include "about.h" 15 | #include "help.h" 16 | #include "panic.h" 17 | #include "esp.h" 18 | #include "version.h" 19 | 20 | 21 | #define TRS_IO_PORT 31 22 | 23 | #define TRS_IO_CORE_MODULE_ID 0 24 | 25 | #define TRS_IO_SEND_VERSION 0 26 | #define TRS_IO_SEND_STATUS 1 27 | #define TRS_IO_CMD_CONFIGURE_WIFI 2 28 | #define TRS_IO_SEND_WIFI_SSID 3 29 | #define TRS_IO_SEND_WIFI_IP 4 30 | 31 | 32 | #define RETROSTORE_MODULE_ID 3 33 | 34 | #define RS_SEND_VERSION 0 35 | #define RS_SEND_LOADER_CMD 1 36 | #define RS_SEND_BASIC 2 37 | #define RS_SEND_CMD 3 38 | #define RS_SEND_APP_TITLE 4 39 | #define RS_SEND_APP_DETAILS 5 40 | #define RS_CMD_SET_QUERY 6 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/trs/version.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __VERSION_H__ 3 | #define __VERSION_H__ 4 | 5 | #define RS_CLIENT_VERSION_MAJOR 2 6 | #define RS_CLIENT_VERSION_MINOR 0 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/trs/wifi.c: -------------------------------------------------------------------------------- 1 | 2 | #include "wifi.h" 3 | #include "inout.h" 4 | #include "retrostore.h" 5 | 6 | static char ssid[32 + 1] = ""; 7 | static char passwd[32 + 1] = ""; 8 | 9 | static form_t form_wifi[] = { 10 | { FORM_TYPE_TEXT, 0, 0, .u.text = "SSID: "}, 11 | { FORM_TYPE_INPUT, -1, -1, .u.input.len = 32, .u.input.buf = ssid}, 12 | { FORM_TYPE_TEXT, -1, -1, .u.text = "\nPassword: "}, 13 | { FORM_TYPE_INPUT, -1, -1, .u.input.len = 32, .u.input.buf = passwd}, 14 | { FORM_TYPE_END } 15 | }; 16 | 17 | static window_t wnd; 18 | 19 | void configure_wifi() 20 | { 21 | uint16_t i, j; 22 | 23 | init_window(&wnd, 0, 0, 0, 0); 24 | if (form(&wnd, "Configure WiFi", form_wifi, false) == FORM_ABORT) { 25 | return; 26 | } 27 | if (ssid[0] == '\0') { 28 | // No SSID provided. Exit 29 | return; 30 | } 31 | out(TRS_IO_PORT, TRS_IO_CORE_MODULE_ID); 32 | out(TRS_IO_PORT, TRS_IO_CMD_CONFIGURE_WIFI); 33 | i = 0; 34 | do { 35 | out(TRS_IO_PORT, ssid[i]); 36 | } while (ssid[i++] != '\0'); 37 | i = 0; 38 | do { 39 | out(TRS_IO_PORT, passwd[i]); 40 | } while (passwd[i++] != '\0'); 41 | wnd_popup(&wnd, "Reconfiguring WiFi..."); 42 | for (i = 0; i < 10; i++) { 43 | for (j = 0; j < 65000; j++) { 44 | if(0); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/trs/wifi.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __WIFI_H__ 3 | #define __WIFI_H__ 4 | 5 | #include "header.h" 6 | #include "form.h" 7 | 8 | void configure_wifi(); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/trs/window.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __WINDOW_H__ 3 | #define __WINDOW_H__ 4 | 5 | #include "hardware.h" 6 | #include "defs.h" 7 | 8 | typedef struct { 9 | uint16_t buffer; 10 | uint8_t x; 11 | uint8_t y; 12 | uint8_t w; 13 | uint8_t h; 14 | uint8_t cx; 15 | uint8_t cy; 16 | } window_t; 17 | 18 | void init_window(window_t* wnd, uint8_t x, uint8_t y, int8_t w, int8_t h); 19 | void wnd_print(window_t* wnd, bool single_line, const char* str); 20 | void wnd_print_int(window_t* wnd, uint16_t v); 21 | void wnd_cls(window_t* wnd); 22 | void wnd_scroll_down(window_t* wnd); 23 | void wnd_scroll_up(window_t* wnd); 24 | void wnd_cr(window_t* wnd); 25 | void wnd_goto(window_t* wnd, uint8_t x, uint8_t y); 26 | void wnd_switch_to_background(window_t* wnd); 27 | void wnd_switch_to_foreground(window_t* wnd); 28 | void wnd_show(window_t* wnd, bool from_left); 29 | void wnd_popup(window_t* wnd, const char* msg); 30 | 31 | #endif 32 | --------------------------------------------------------------------------------