├── README.md ├── close.asm ├── cp-esxdos087.asm ├── cp.asm ├── doc └── te.md ├── lib ├── addlines.asm ├── align512.asm ├── atob.asm ├── atoi.asm ├── basename.asm ├── buffer.asm ├── chkdir.asm ├── cpmv-esxdos087.asm ├── cpmv.asm ├── digit.asm ├── empty-usage.asm ├── hooks.asm ├── indexer.asm ├── lputs.asm ├── nextarg.asm ├── numarg.asm ├── options.asm ├── parse2-esxdos087.asm ├── parse2.asm ├── println.asm ├── puts.asm ├── strarg.asm ├── strcpy.asm ├── strlen.asm ├── sysvars.asm ├── tokens.asm └── zxrom.asm ├── load.asm ├── merge.asm ├── mv-esxdos087.asm ├── open.asm ├── save.asm ├── sc2.asm ├── sc2.tab └── te.asm /README.md: -------------------------------------------------------------------------------- 1 | # Dot Commands for esxDOS and UnoDOS3 2 | 3 | Sources for dot commands, reverse engineered and written by myself. 4 | -------------------------------------------------------------------------------- /close.asm: -------------------------------------------------------------------------------- 1 | ; close esxDOS file stream 2 | 3 | include "lib/sysvars.asm" 4 | include "lib/hooks.asm" 5 | include "lib/zxrom.asm" 6 | include "lib/empty-usage.asm" 7 | 8 | execute:ld a,(hl) 9 | cp "#" 10 | jr nz,nohash 11 | inc hl 12 | nohash: call numarg 13 | jr c,usage 14 | jr nz,usage 15 | ld a,e 16 | push af 17 | rst 18h 18 | defw str_data0 19 | pop af 20 | push hl 21 | rst 18h 22 | defw chan_open 23 | ld ix,(curchl) 24 | ld a,(ix+4) 25 | cp "F" 26 | jr z,doclose 27 | pop hl 28 | rst 18h 29 | defw close0a 30 | and a 31 | ret 32 | 33 | doclose:ld a,(ix+5) 34 | rst 8 35 | defb fclose 36 | ; seems to always return with CF set 37 | ; pop hl 38 | ; ret c 39 | ; push hl 40 | ld c,(ix+09h) 41 | ld b,(ix+0ah) 42 | push ix 43 | pop de 44 | ld hl,(chans) 45 | and a 46 | sbc hl,de 47 | ex de,hl 48 | ld hl,strms 49 | ld a,19 50 | closel: ex af,af' 51 | push hl 52 | ld a,(hl) 53 | inc l 54 | ld h,(hl) 55 | ld l,a 56 | add hl,de 57 | jr nc,closelo 58 | and a 59 | sbc hl,bc 60 | ex (sp),hl 61 | dec sp 62 | pop af 63 | ld (hl),a 64 | inc l 65 | dec sp 66 | pop af 67 | ld (hl),a 68 | dec hl 69 | defb 3eh ; ld a, skip one byte 70 | closelo:pop hl 71 | inc l 72 | inc l 73 | ex af,af' 74 | dec a 75 | jr nz,closel 76 | push ix 77 | pop hl 78 | rst 18h 79 | defw reclaim2 80 | pop hl 81 | rst 18h 82 | defw close0 83 | and a 84 | ret 85 | 86 | include "lib/numarg.asm" 87 | include "lib/nextarg.asm" 88 | include "lib/atob.asm" 89 | include "lib/puts.asm" 90 | 91 | usaget: defb "Usage: close [#]stream", 0dh, 00h 92 | f_name: include "lib/align512.asm" 93 | -------------------------------------------------------------------------------- /cp-esxdos087.asm: -------------------------------------------------------------------------------- 1 | ; CP command from esxDOS v0.8.7 2 | 3 | ; Errata: 4 | ; 1. Only the first argument is copied to the last, no check against more than 2 args 5 | ; 2. Arguments buffer overflow 6 | ; 3. No sanitization of file names (maybe esxDOS system calls do it) 7 | 8 | include "lib/sysvars.asm" 9 | include "lib/hooks.asm" 10 | include "lib/empty-usage.asm" 11 | include "lib/cpmv-esxdos087.asm" 12 | 13 | arg_e: equ 2200h 14 | 15 | do: ld hl,f_name 16 | ld a,"*" 17 | ld b,fopen_r 18 | rst 8 19 | defb fopen 20 | ret c 21 | ld (fd_src),a 22 | ld hl,(f_name2) 23 | ld a,"*" 24 | ld b,fopen_we 25 | rst 8 26 | defb fopen 27 | jr c,exit 28 | ld (fd_trg),a 29 | call buf32k 30 | 31 | bufptr: equ $ + 1 32 | copyl: ld hl,arg_e 33 | buflen: equ $ + 1 34 | ld bc,01000h 35 | ld a,(fd_src) 36 | push hl 37 | push bc 38 | rst 8 39 | defb fread 40 | pop de 41 | pop hl 42 | jr c,exit 43 | ld a,(fd_trg) 44 | push de 45 | rst 8 46 | defb fwrite 47 | pop de 48 | jr c,exit 49 | ld a,b 50 | cp d 51 | jr nz,finish 52 | jr copyl 53 | 54 | finish: or a 55 | exit: push af 56 | ld a,(fd_src) 57 | and a 58 | call nz,f_close 59 | ld a,(fd_trg) 60 | and a 61 | call nz,f_close 62 | pop af 63 | ret 64 | 65 | f_close:rst 8 66 | defb fclose 67 | ret 68 | 69 | include "lib/strcpy.asm" 70 | include "lib/parse2-esxdos087.asm" 71 | include "lib/basename.asm" 72 | include "lib/chkdir.asm" 73 | include "lib/puts.asm" 74 | include "lib/buffer.asm" 75 | 76 | usaget: defb "Usage: cp source target", 0dh, 00h 77 | f_name2:defw 0 78 | fd_src: defb 0 79 | fd_trg: defw 0 80 | f_name: defs arg_e - $ 81 | -------------------------------------------------------------------------------- /cp.asm: -------------------------------------------------------------------------------- 1 | ; CP command for esxDOS 2 | 3 | ; Errata: 4 | ; 1. No sanitization of file names (maybe esxDOS system calls do it) 5 | 6 | include "lib/sysvars.asm" 7 | include "lib/hooks.asm" 8 | include "lib/empty-usage.asm" 9 | 10 | arg_e: equ 2400h 11 | 12 | execute:include "lib/parse2.asm" 13 | include "lib/cpmv.asm" 14 | 15 | do: ld hl,f_name 16 | ld a,"*" 17 | ld b,fopen_r 18 | rst 8 19 | defb fopen 20 | ret c 21 | ld (fd_src),a 22 | ld hl,(f_name2) 23 | ld a,"*" 24 | ld b,fopen_w 25 | rst 8 26 | defb fopen 27 | jr c,exit 28 | ld (fd_trg),a 29 | call buf32k 30 | 31 | bufptr: equ $ + 1 32 | copyl: ld hl,arg_e 33 | buflen: equ $ + 1 34 | ld bc,01000h 35 | ld a,(fd_src) 36 | push hl 37 | push bc 38 | rst 8 39 | defb fread 40 | pop de 41 | pop hl 42 | jr c,exit 43 | ld a,(fd_trg) 44 | push de 45 | rst 8 46 | defb fwrite 47 | pop de 48 | jr c,exit 49 | ld a,b 50 | cp d 51 | jr nz,finish 52 | jr copyl 53 | 54 | finish: or a 55 | exit: push af 56 | ld a,(fd_src) 57 | and a 58 | call nz,f_close 59 | ld a,(fd_trg) 60 | and a 61 | call nz,f_close 62 | pop af 63 | ret 64 | 65 | f_close:rst 8 66 | defb fclose 67 | ret 68 | 69 | include "lib/strcpy.asm" 70 | include "lib/basename.asm" 71 | include "lib/chkdir.asm" 72 | include "lib/puts.asm" 73 | include "lib/buffer.asm" 74 | 75 | usaget: defb "Usage: cp source target", 0dh, 00h 76 | f_name2:defw 0 77 | fd_src: defb 0 78 | fd_trg: defw 0 79 | f_name: include "lib/align512.asm" 80 | -------------------------------------------------------------------------------- /doc/te.md: -------------------------------------------------------------------------------- 1 | # TE Text Editor 2 | 3 | ## Command Line 4 | 5 | `.te` \[*path*/\]*filename* ~~[*linenumber*]~~ 6 | 7 | ## General Description 8 | 9 | A tool for editing esxDOS text files, expecially, though not exclusively configuration files. 10 | It works with both CR (ZX Spectrum style) and LF (Unix style) line endings. MSDOS style line endings 11 | CR + LF look like double spacing, but can be managed with some care as well. 12 | 13 | The user interface mostly follows ZX conventions, with an editing area (console) at the bottom 14 | of the screen and the edited document at the top. There is no explicit SAVE functionality, hitting 15 | ENTER immediately commits the changes into the file. In case of a crash, the file might be available 16 | at the /tmp/te.tmp location. 17 | 18 | The editor buffer resides in esxDOS memory, only the edited line takes space from the ZX 19 | Spectrum's OS, so it is possible to edit large files even when there is very little free memory 20 | left. 21 | 22 | ## Keyboard 23 | 24 | Most keys work like in the ZX Spectrum's BASIC editor, with the differences summarized 25 | in this table: 26 | 27 | | Key | Function 28 | | --- | --- 29 | | BREAK | exit `te` 30 | | UP arrow | line cursor one line UP **or** character cursor HOME 31 | | DOWN arrow | line cursor one line DOWN **or** character cursor END 32 | | LEFT arrow | character cursor LEFT **or** ~~page UP~~ 33 | | RIGHT arrow | character cursor RIGHT **or** ~~page DOWN~~ 34 | | DELETE | delete character to the left of character cursor 35 | | G mode DELETE | delete all characters to the left of character cursor 36 | | G mode 0 | delete all characters after character cursor 37 | | EDIT | edit line pointed by line cursor 38 | | ss + SPACE | insert line pointed by line cursor into edited line at character cursor 39 | | ENTER | insert edited line into file **or** replace edited line 40 | | G mode ENTER | split edited line at character cursor and insert both into file 41 | | cs + ENTER | join edited line with the one pointed by line cursor 42 | | ss + ENTER | like ENTER, but toggle line ending between CR (`CHR$ 13`) and LF (`CHR$ 10`) 43 | -------------------------------------------------------------------------------- /lib/addlines.asm: -------------------------------------------------------------------------------- 1 | doopen: ld b,fopen_r 2 | ld a,"*" 3 | ld hl,f_name 4 | rst 8 5 | defb fopen 6 | ret c 7 | ld (fd),a 8 | 9 | nextln: rst 18h 10 | defw set_min 11 | ld a,0ffh 12 | rst 18h 13 | defw chan_open 14 | 15 | copyln: call fgetc 16 | ret c 17 | jr nz,doclose 18 | cp 0ah 19 | jr z,readyln 20 | cp 0dh 21 | jr z,readyln 22 | rst 18h 23 | defw 0010h 24 | jr copyln 25 | 26 | readyln:ld hl,(e_line) 27 | ld e,l 28 | ld d,h 29 | tloop: ld a,(de) 30 | cp "\"" 31 | jr nz,tnq 32 | tquot: ld (hl),a 33 | inc de 34 | inc hl 35 | ld a,(de) 36 | cp "\"" 37 | jr nz,tquot 38 | tnq: call tokenize 39 | ld a,(foundl) 40 | or a 41 | ld a,(de) 42 | jr z,ntoken 43 | ld a,(foundl) 44 | dec a 45 | add e 46 | ld e,a 47 | jr nc, tnc 48 | inc d 49 | tnc: ld a,(found) 50 | ntoken: ld (hl), a 51 | inc hl 52 | inc de 53 | cp 0dh 54 | jr nz,tloop 55 | ld (hl),80h 56 | inc hl 57 | ld (worksp),hl 58 | 59 | scan_ln:rst 18h 60 | defw line_scan 61 | ld a,(err_nr) 62 | sub 0ffh 63 | ret c 64 | 65 | ld hl,(e_line) 66 | ld (ch_add),hl 67 | rst 18h 68 | defw e_line_no 69 | ld a,b 70 | or c 71 | call nz,addline 72 | jr nextln 73 | 74 | doclose:ld a,(fd) 75 | rst 8 76 | defb fclose 77 | ret c 78 | rst 18h 79 | defw 0058h 80 | 81 | fgetc: ld a,(fd) 82 | ld hl,buf 83 | ld bc,1 84 | rst 8 85 | defb fread 86 | ret c 87 | dec bc 88 | ld a, b 89 | or c 90 | ret nz 91 | ld a,(buf) 92 | ret 93 | 94 | tokenize: 95 | xor a 96 | ld (foundl),a 97 | push hl 98 | ld c,tk_spectrum 99 | ld hl,t_spectrum 100 | tsrc: xor a 101 | ex af,af' 102 | push de 103 | ld a,(de) 104 | cp " " 105 | jr nz,tnskp 106 | ex af,af' 107 | inc a 108 | ex af,af' 109 | inc de 110 | tnskp: ld b,(hl) 111 | push hl 112 | tchk: inc hl 113 | ld a,(de) 114 | inc de 115 | ex af,af' 116 | inc a 117 | ex af,af' 118 | rst 18h 119 | defw alpha 120 | jr nc,tsym 121 | and 5fh 122 | tsym: cp (hl) 123 | jr nz,tneq 124 | djnz tchk 125 | ex af,af' 126 | ld b,a 127 | ld a,(de) 128 | cp " " 129 | jr nz,tntrl 130 | inc b 131 | tntrl: ld a,(foundl) 132 | cp b 133 | jr nc,tshort 134 | ld (found),bc 135 | tshort: pop hl 136 | tcont: inc hl 137 | inc c 138 | pop de 139 | jr nz,tsrc 140 | pop hl 141 | ret 142 | 143 | tneq: ld (buf),a 144 | ld a,(hl) 145 | cp " " 146 | ld a,(buf) 147 | jr nz,tnosp 148 | inc hl 149 | dec b 150 | jr tsym 151 | 152 | tnosp: pop hl 153 | ld a,(hl) 154 | add l 155 | ld l,a 156 | jr nc,tcont 157 | inc h 158 | jr tcont 159 | 160 | addline:ld (e_ppc),bc 161 | ld hl,(ch_add) 162 | ex de,hl 163 | ld hl,(worksp) 164 | scf 165 | sbc hl,de 166 | push hl 167 | ld h,b 168 | ld l,c 169 | rst 18h 170 | defw line_addr 171 | jr nz,addln1 172 | rst 18h 173 | defw next_one 174 | rst 18h 175 | defw reclaim2 176 | addln1: pop bc 177 | ld a,c 178 | dec a 179 | or b 180 | ret z 181 | push bc 182 | inc bc 183 | inc bc 184 | inc bc 185 | inc bc 186 | dec hl 187 | ld de,(prog) 188 | push de 189 | rst 18h 190 | defw make_room 191 | pop hl 192 | ld (prog),hl 193 | pop bc 194 | push bc 195 | inc de 196 | ld hl,(worksp) 197 | dec hl 198 | dec hl 199 | lddr 200 | ld hl,(e_ppc) 201 | ex de,hl 202 | pop bc 203 | ld (hl),b 204 | dec hl 205 | ld (hl),c 206 | dec hl 207 | ld (hl),e 208 | dec hl 209 | ld (hl),d 210 | ret 211 | -------------------------------------------------------------------------------- /lib/align512.asm: -------------------------------------------------------------------------------- 1 | defs 200h * (($ + 1ffh) / 200h) - $ 2 | -------------------------------------------------------------------------------- /lib/atob.asm: -------------------------------------------------------------------------------- 1 | ; ASCII decimal to 8-bit integer 2 | ; In: HL = pointer to ascii number 3 | ; Out: CF set on overflow, E = number, HL = pointer to separator 4 | ; Pollutes: AF, D 5 | atoi: ld e,0 6 | atoil: ld a,(hl) 7 | call digit 8 | ccf 9 | ret nc 10 | ld d,a 11 | ld a,e 12 | add a,a 13 | ret c 14 | add a,a 15 | ret c 16 | add a,e 17 | ret c 18 | add a,a 19 | ret c 20 | add a,d 21 | ret c 22 | ld e,a 23 | inc hl 24 | jr atoil 25 | 26 | include "lib/digit.asm" 27 | -------------------------------------------------------------------------------- /lib/atoi.asm: -------------------------------------------------------------------------------- 1 | ; ASCII decimal to 16-bit integer 2 | ; In: HL = pointer to ascii number 3 | ; Out: CF set on overflow, DE = number, HL = pointer to separator 4 | ; Pollutes: AF, BC 5 | atoi: ld de,0 6 | atoil: ld a,(hl) 7 | call digit 8 | ccf 9 | ret nc 10 | ex de,hl 11 | ld c,l 12 | ld b,h 13 | add hl,hl 14 | ret c 15 | add hl,hl 16 | ret c 17 | add hl,bc 18 | ret c 19 | add hl,hl 20 | ret c 21 | ld b,0 22 | ld c,a 23 | add hl,bc 24 | ret c 25 | ex de,hl 26 | inc hl 27 | jr atoil 28 | 29 | include "lib/digit.asm" 30 | -------------------------------------------------------------------------------- /lib/basename.asm: -------------------------------------------------------------------------------- 1 | ; Find file name at the end of null-terminated path string 2 | ; In: HL = pointer to path 3 | ; Out: HL = pointer to file name, A = 0 if no path, "/" otherwise 4 | basename: 5 | ld bc,00080h 6 | bname: xor a 7 | cpir 8 | dec hl 9 | bnamel: dec hl 10 | ld a,(hl) 11 | and a 12 | jr z,bnamee 13 | cp "/" 14 | jr nz,bnamel 15 | bnamee: inc hl 16 | ret 17 | -------------------------------------------------------------------------------- /lib/buffer.asm: -------------------------------------------------------------------------------- 1 | ; Allocate a buffer of at most 32 kilobytes 2 | buf32k: ld hl,08000h 3 | 4 | ; Allocate a buffer of at least 4 kilobytes 5 | ; In: HL = maximum buffer size (must be power of 2, not less than 1000h) 6 | ; Out: CF set if available, HL = pointer to buffer, DE = buffer size 7 | ; Pollutes: AF 8 | buf: call chkmem 9 | jr c,bufok 10 | srl h 11 | ld a,h 12 | cp 010h 13 | ret z 14 | jr buf 15 | 16 | bufok: ld (buflen),hl 17 | ex de,hl 18 | ld (bufptr),hl 19 | ret 20 | 21 | ; Check available memory between (STKEND) and SP 22 | ; In: HL = required memory 23 | ; Out: C set if available, DE = (STKEND) 24 | chkmem: push hl 25 | ld de,(stkend) 26 | add hl,de 27 | inc h 28 | sbc hl,sp 29 | pop hl 30 | ret 31 | -------------------------------------------------------------------------------- /lib/chkdir.asm: -------------------------------------------------------------------------------- 1 | ; Check whether null-termianted path string ends with / 2 | ; In: HL = pointer to path string 3 | ; Out: HL = pointer to terminator, ZF set if it does, A = "/", BC = $80 - length 4 | chkdir: ld bc,00080h 5 | xor a 6 | cpir 7 | dec hl 8 | dec hl 9 | ld a,(hl) 10 | cp "/" 11 | inc hl 12 | ret 13 | -------------------------------------------------------------------------------- /lib/cpmv-esxdos087.asm: -------------------------------------------------------------------------------- 1 | execute:call parsefn 2 | ld hl,(f_name2) 3 | ld a,l 4 | or h 5 | jr z,usage ; missing target 6 | 7 | ld hl,f_name 8 | ld a,(hl) 9 | and a 10 | jr z,usage ; missing source 11 | 12 | ld hl,(f_name2) ; if target is 13 | call chkdir ; not a directory 14 | jr nz,do ; then jump forward 15 | push hl ; otherwise save terminator 16 | ld hl,f_name ; take the source 17 | call basename ; file base name 18 | pop de ; restore terminator in DE 19 | call strcpy ; append to target path 20 | 21 | -------------------------------------------------------------------------------- /lib/cpmv.asm: -------------------------------------------------------------------------------- 1 | ; Common part of cp and mv commands for esxDOS 2 | 3 | ld hl,(f_name2) 4 | ld a,l 5 | or h 6 | jr z,usage ; missing target 7 | 8 | ld hl,f_name 9 | ld a,(hl) 10 | and a 11 | jr z,usage ; missing source 12 | 13 | ld hl,(f_name2) ; if target is 14 | call chkdir ; not a directory 15 | jr nz,do ; then jump forward 16 | push hl ; otherwise save terminator 17 | ld hl,f_name ; take the source 18 | call basename ; file base name 19 | pop de ; restore terminator in DE 20 | call strcpy ; append to target path 21 | -------------------------------------------------------------------------------- /lib/digit.asm: -------------------------------------------------------------------------------- 1 | ; Converts ASCII digit to number 2 | ; In: A = decimal digit 3 | ; Out: CF set on error, A = digit 4 | digit: sub "0" 5 | ret c 6 | cp 0ah 7 | ccf 8 | ret 9 | -------------------------------------------------------------------------------- /lib/empty-usage.asm: -------------------------------------------------------------------------------- 1 | org 02000h 2 | 3 | start: ld a,h 4 | or l 5 | jr nz,execute 6 | 7 | usage: ld hl,usaget 8 | call puts 9 | or a 10 | ret 11 | -------------------------------------------------------------------------------- /lib/hooks.asm: -------------------------------------------------------------------------------- 1 | ; RST 8 errors and hook codes 2 | 3 | bad_fd_err: equ 0dh 4 | 5 | 6 | fopen: equ 9ah 7 | fopen_r: equ 01h 8 | fopen_we: equ 06h 9 | fopen_w: equ 0ch 10 | 11 | fclose: equ 9bh 12 | 13 | fread: equ 9dh 14 | 15 | fwrite: equ 9eh 16 | 17 | fseek: equ 9fh 18 | 19 | funlink: equ 0adh 20 | 21 | frename: equ 0b0h 22 | -------------------------------------------------------------------------------- /lib/indexer.asm: -------------------------------------------------------------------------------- 1 | indexer_1: 2 | inc hl 3 | 4 | ; Finds a byte associated with another byte (see L16DC in ROM1) 5 | ; In: C = code to look for, HL = base address of the table 6 | ; Out: HL = address of the associated byte (if found), CF set if code found 7 | ; Pollutes: AF 8 | indexer:ld a,(hl) 9 | or a 10 | ret z 11 | cp c 12 | inc hl 13 | jr nz,indexer_1 14 | scf 15 | ret 16 | 17 | -------------------------------------------------------------------------------- /lib/lputs.asm: -------------------------------------------------------------------------------- 1 | ; Print null-terminated string with maximum length 2 | ; In: HL = pointer to string, BC = maximum length 3 | ; Out: HL = end of string, A = 0 if reached 0, 1 otherwise, ZF set if A=0, CF=0 4 | 5 | puts: ld bc,0000h 6 | lputs: ld a,(hl) 7 | and a 8 | ret z 9 | rst 10h 10 | inc hl 11 | dec bc 12 | ld a,b 13 | or c 14 | jr nz,lputs 15 | inc a 16 | ret 17 | -------------------------------------------------------------------------------- /lib/nextarg.asm: -------------------------------------------------------------------------------- 1 | ; Next argument 2 | ; In: HL = pointer to space, A = " " 3 | ; Out: CF clear, ZF set if last argument, HL = pointer to next 4 | nxarg: inc hl 5 | cp (hl) 6 | jr z,nxarg 7 | ld a,(hl) 8 | cp ":" 9 | ret z 10 | cp 0dh 11 | ret z 12 | or a 13 | ret 14 | -------------------------------------------------------------------------------- /lib/numarg.asm: -------------------------------------------------------------------------------- 1 | ; Read decimal argument 2 | ; In: HL = pointer to argument 3 | ; Out: CF set on error, ZF set if last arg, DE = numeric argument 4 | numarg: ld a,(hl) 5 | call digit 6 | ret c 7 | call atoi 8 | ret c 9 | ld a,(hl) 10 | cp " " 11 | jr z,nxarg 12 | cp ":" 13 | ret z 14 | cp 0dh 15 | ret z 16 | or a 17 | ret z 18 | scf 19 | ret 20 | -------------------------------------------------------------------------------- /lib/options.asm: -------------------------------------------------------------------------------- 1 | ; Read options 2 | ; In: HL = pointer to current argument 3 | ; Out: CF set if more arguments, HL = pointer to next argument to process, ZF set if options done 4 | options:ld a,(hl) 5 | cp "-" 6 | scf 7 | ret nz 8 | nextop: ld de,optab 9 | inc hl 10 | ld c,(hl) 11 | ex de,hl 12 | call indexer 13 | jr nc,endopt 14 | ld c,(hl) 15 | ld b,0 16 | add hl,bc 17 | call jphl 18 | ex de,hl 19 | jr nextop 20 | 21 | endopt: ex de,hl 22 | inc hl 23 | ld a,c 24 | cp " " 25 | scf 26 | ret z 27 | cp ":" 28 | ret z 29 | cp 00dh 30 | ret z 31 | push af 32 | ld hl,illopt 33 | call puts 34 | pop af 35 | rst 10h 36 | ld a,0dh 37 | rst 10h 38 | pop bc 39 | ld a,22 ; No such COMMAND 40 | scf 41 | ret 42 | 43 | jphl: jp (hl) 44 | 45 | illopt: defm "Illegal option: " 46 | defb 0 47 | -------------------------------------------------------------------------------- /lib/parse2-esxdos087.asm: -------------------------------------------------------------------------------- 1 | ; parse source and target from esxDOS v0.8.7 2 | 3 | parsefn:ld de,f_name 4 | parsel: ld a,(hl) 5 | and a 6 | jr z,parsee 7 | cp ":" 8 | jr z,parsee 9 | cp 00dh 10 | jr z,parsee 11 | cp " " 12 | jr z,parse2 13 | ldi 14 | jr parsel 15 | 16 | parsee: xor a 17 | ld (de),a 18 | ret 19 | 20 | parse2: xor a 21 | ld (de),a 22 | inc hl 23 | inc de 24 | ld (f_name2),de 25 | jr parsel 26 | -------------------------------------------------------------------------------- /lib/parse2.asm: -------------------------------------------------------------------------------- 1 | ; parse source and target 2 | 3 | parsefn:ld de,f_name 4 | parsel: ld a,(hl) 5 | or a 6 | jr z,parsee 7 | cp ":" 8 | jr z,parsee 9 | cp 00dh 10 | jr z,parsee 11 | cp " " 12 | jr z,parse2 13 | ldi 14 | ld a,d 15 | cp arg_e / 100h 16 | jr c,parsel ; guard against buffer overflow 17 | jr usage 18 | 19 | parse2: xor a 20 | ld (de),a 21 | ld a,(f_name2 + 1) 22 | or a 23 | jr nz,usage ; guard against more than two arguments 24 | inc hl 25 | inc de 26 | ld (f_name2),de 27 | jr parsel 28 | 29 | parsee: xor a 30 | ld (de),a 31 | -------------------------------------------------------------------------------- /lib/println.asm: -------------------------------------------------------------------------------- 1 | linepr: set 2,(iy+30h) ; inside quotes 2 | rst 10h 3 | ; Print a line without terminating CR or LF 4 | ; In: DE = line pointer, BC = maximum length 5 | ; Out: CF set if terminated, A = terminator, BC = remaining length, DE = points AFTER terminator 6 | println:ld a,b 7 | or c 8 | ret z 9 | dec bc 10 | ld a,(de) 11 | inc de 12 | cp 0dh ; cr 13 | jr z,prlncr 14 | cp 0ah ; lf 15 | jr nz,linepr 16 | prlncr: scf 17 | ret 18 | -------------------------------------------------------------------------------- /lib/puts.asm: -------------------------------------------------------------------------------- 1 | ; Print null-terminated string 2 | ; In: HL = pointer to string 3 | ; Out: HL = end of string, A = 0, ZF=1, CF=0 4 | 5 | puts: ld a,(hl) 6 | and a 7 | ret z 8 | rst 10h 9 | inc hl 10 | jr puts 11 | 12 | -------------------------------------------------------------------------------- /lib/strarg.asm: -------------------------------------------------------------------------------- 1 | ; Read string argument 2 | ; In: HL = pointer to argument, DE = pointer to string buffer 3 | ; Out: ZF set if last arg, DE = pointer to next string buffer 4 | strarg: ld a,(hl) 5 | or a 6 | jr z,strarge 7 | sub 0dh 8 | jr z,strarge 9 | sub " "-0dh 10 | jr z,strargs 11 | sub ":"-" " 12 | jr z,strarge 13 | ldi 14 | ld a,arg_e / 100h 15 | cp d 16 | jr nc,strarg ; guard against buffer overflow 17 | ret 18 | 19 | strarge:ld (de),a 20 | inc de 21 | ret 22 | 23 | strargs:ld (de),a 24 | inc de 25 | ld a,(hl) 26 | include "lib/nextarg.asm" 27 | -------------------------------------------------------------------------------- /lib/strcpy.asm: -------------------------------------------------------------------------------- 1 | ; Copy null-terminated string 2 | ; In: HL = source pointer, DE = target pointer 3 | ; Out: HL = after source, DE = after target, ZF set, CF reset , A = 0 4 | 5 | strcpy: ld a,(hl) 6 | ld (de),a 7 | inc hl 8 | inc de 9 | and a 10 | ret z 11 | jr strcpy 12 | 13 | -------------------------------------------------------------------------------- /lib/strlen.asm: -------------------------------------------------------------------------------- 1 | ; Length of string 2 | ; In: HL = pointer to string 3 | ; Out: HL = length of string, BC = 65535 - HL, A = 0, CF set, ZF set if zero length 4 | strln: xor a 5 | ld b,a 6 | ld c,a 7 | cpir 8 | ld h,a 9 | ld l,a 10 | scf 11 | sbc hl,bc 12 | ret 13 | -------------------------------------------------------------------------------- /lib/sysvars.asm: -------------------------------------------------------------------------------- 1 | ; system variables 2 | kstate: equ 5c00h 3 | last_k: equ 5c08h 4 | repdel: equ 5c09h 5 | repper: equ 5c0ah 6 | defadd: equ 5c0bh 7 | k_data: equ 5c0dh 8 | tvdata: equ 5c0eh 9 | strms: equ 5c10h 10 | strmfd: equ 5c10h 11 | strmfe: equ 5c12h 12 | strmff: equ 5c14h 13 | strm00: equ 5c16h 14 | strm01: equ 5c18h 15 | strm02: equ 5c1ah 16 | strm03: equ 5c1ch 17 | chars: equ 5c36h 18 | rasp: equ 5c38h 19 | pip: equ 5c39h 20 | err_nr: equ 5c3ah 21 | flags: equ 5c3bh 22 | tv_flag:equ 5c3ch 23 | err_sp: equ 5c3dh 24 | list_sp:equ 5c3fh 25 | mode: equ 5c41h 26 | newppc: equ 5c42h 27 | nsppc: equ 5c44h 28 | ppc: equ 5c45h 29 | subppc: equ 5c47h 30 | bordcr: equ 5c48h 31 | e_ppc: equ 5c49h 32 | vars: equ 5c4bh 33 | dest: equ 5c4dh 34 | chans: equ 5c4fh 35 | curchl: equ 5c51h 36 | prog: equ 5c53h 37 | nxtlin: equ 5c55h 38 | datadd: equ 5c57h 39 | e_line: equ 5c59h 40 | k_cur: equ 5c5bh 41 | ch_add: equ 5c5dh 42 | x_ptr: equ 5c5fh 43 | worksp: equ 5c61h 44 | stkbot: equ 5c63h 45 | stkend: equ 5c65h 46 | breg: equ 5c67h 47 | mem: equ 5c68h 48 | flags2: equ 5c6ah 49 | df_sz: equ 5c6bh 50 | s_top: equ 5c6ch 51 | oldppc: equ 5c6eh 52 | ospcc: equ 5c70h 53 | flagx: equ 5c71h 54 | strlen: equ 5c72h 55 | t_addr: equ 5c74h 56 | seed: equ 5c76h 57 | frames: equ 5c78h 58 | udg: equ 5c7bh 59 | coords: equ 5c7dh 60 | p_posn: equ 5c7fh 61 | pr_cc: equ 5c80h 62 | echo_e: equ 5c82h 63 | df_cc: equ 5c84h 64 | df_ccl: equ 5c86h 65 | s_posn: equ 5c88h 66 | s_posnl:equ 5c8ah 67 | scr_ct: equ 5c8ch 68 | attr_p: equ 5c8dh 69 | mask_p: equ 5c8eh 70 | attr_t: equ 5c8fh 71 | mask_t: equ 5c90h 72 | p_flag: equ 5c91h 73 | membot: equ 5c92h 74 | mem0: equ 5c92h 75 | mem1: equ 5c97h 76 | mem2: equ 5c9ch 77 | mem3: equ 5ca1h 78 | mem4: equ 5ca6h 79 | mem5: equ 5cabh 80 | nmiadd: equ 5cb0h 81 | ramtop: equ 5cb2h 82 | p_ramt: equ 5cb4h 83 | chinfo: equ 5cb6h 84 | -------------------------------------------------------------------------------- /lib/tokens.asm: -------------------------------------------------------------------------------- 1 | tokens128: 2 | defw t_spectrum,t_play 3 | tokens: defw t_rnd,t_inkeys,t_pi 4 | defw t_fn,t_point,t_screens,t_attr,t_at,t_tab,t_vals,t_code 5 | defw t_val,t_len,t_sin,t_cos,t_tan,t_asn,t_acs,t_atn 6 | defw t_ln,t_exp,t_int,t_sqr,t_sgn,t_abs,t_peek,t_in 7 | defw t_usr,t_strs,t_chrs,t_not,t_bin,t_or,t_and,t_le 8 | defw t_ge,t_ne,t_line,t_then,t_to,t_step,t_deffn,t_cat 9 | defw t_format,t_move,t_erase,t_open,t_close,t_merge,t_verify,t_beep 10 | defw t_circle,t_ink,t_paper,t_flash,t_bright,t_inverse,t_over,t_out 11 | defw t_lprint,t_llist,t_stop,t_read,t_data,t_restore,t_new,t_border 12 | defw t_continue,t_dim,t_rem,t_for,t_goto,t_gosub,t_input,t_load 13 | defw t_list,t_let,t_pause,t_next,t_poke,t_print,t_plot,t_run 14 | defw t_save,t_randomize,t_if,t_cls,t_draw,t_clear,t_return,t_copy 15 | 16 | t_spectrum:defb 8,"SPECTRUM" 17 | t_play: defb 4,"PLAY" 18 | t_rnd: defb 3,"RND" 19 | t_inkeys:defb 6,"INKEY$" 20 | t_pi: defb 2,"PI" 21 | t_fn: defb 2,"FN" 22 | t_point:defb 5,"POINT" 23 | t_screens:defb 7,"SCREEN$" 24 | t_attr: defb 4,"ATTR" 25 | t_at: defb 2,"AT" 26 | t_tab: defb 3,"TAB" 27 | t_vals: defb 4,"VAL$" 28 | t_code: defb 4,"CODE" 29 | t_val: defb 3,"VAL" 30 | t_len: defb 3,"LEN" 31 | t_sin: defb 3,"SIN" 32 | t_cos: defb 3,"COS" 33 | t_tan: defb 3,"TAN" 34 | t_asn: defb 3,"ASN" 35 | t_acs: defb 3,"ACS" 36 | t_atn: defb 3,"ATN" 37 | t_ln: defb 2,"LN" 38 | t_exp: defb 3,"EXP" 39 | t_int: defb 3,"INT" 40 | t_sqr: defb 3,"SQR" 41 | t_sgn: defb 3,"SGN" 42 | t_abs: defb 3,"ABS" 43 | t_peek: defb 4,"PEEK" 44 | t_in: defb 2,"IN" 45 | t_usr: defb 3,"USR" 46 | t_strs: defb 4,"STR$" 47 | t_chrs: defb 4,"CHR$" 48 | t_not: defb 3,"NOT" 49 | t_bin: defb 3,"BIN" 50 | t_or: defb 2,"OR" 51 | t_and: defb 3,"AND" 52 | t_le: defb 2,"<=" 53 | t_ge: defb 2,">=" 54 | t_ne: defb 2,"<>" 55 | t_line: defb 4,"LINE" 56 | t_then: defb 4,"THEN" 57 | t_to: defb 2,"TO" 58 | t_step: defb 4,"STEP" 59 | t_deffn:defb 6,"DEF FN" 60 | t_cat: defb 3,"CAT" 61 | t_format:defb 6,"FORMAT" 62 | t_move: defb 4,"MOVE" 63 | t_erase:defb 5,"ERASE" 64 | t_open: defb 6,"OPEN #" 65 | t_close:defb 7,"CLOSE #" 66 | t_merge:defb 5,"MERGE" 67 | t_verify:defb 6,"VERIFY" 68 | t_beep: defb 4,"BEEP" 69 | t_circle:defb 6,"CIRCLE" 70 | t_ink: defb 3,"INK" 71 | t_paper:defb 5,"PAPER" 72 | t_flash:defb 5,"FLASH" 73 | t_bright:defb 6,"BRIGHT" 74 | t_inverse:defb 7,"INVERSE" 75 | t_over: defb 4,"OVER" 76 | t_out: defb 3,"OUT" 77 | t_lprint:defb 6,"LPRINT" 78 | t_llist:defb 5,"LLIST" 79 | t_stop: defb 4,"STOP" 80 | t_read: defb 4,"READ" 81 | t_data: defb 4,"DATA" 82 | t_restore:defb 7,"RESTORE" 83 | t_new: defb 3,"NEW" 84 | t_border:defb 6,"BORDER" 85 | t_continue:defb 8,"CONTINUE" 86 | t_dim: defb 3,"DIM" 87 | t_rem: defb 3,"REM" 88 | t_for: defb 3,"FOR" 89 | t_goto: defb 5,"GO TO" 90 | t_gosub:defb 6,"GO SUB" 91 | t_input:defb 5,"INPUT" 92 | t_load: defb 4,"LOAD" 93 | t_list: defb 4,"LIST" 94 | t_let: defb 3,"LET" 95 | t_pause:defb 5,"PAUSE" 96 | t_next: defb 4,"NEXT" 97 | t_poke: defb 4,"POKE" 98 | t_print:defb 5,"PRINT" 99 | t_plot: defb 4,"PLOT" 100 | t_run: defb 3,"RUN" 101 | t_save: defb 4,"SAVE" 102 | t_randomize:defb 9,"RANDOMIZE" 103 | t_if: defb 2,"IF" 104 | t_cls: defb 3,"CLS" 105 | t_draw: defb 4,"DRAW" 106 | t_clear:defb 5,"CLEAR" 107 | t_return:defb 6,"RETURN" 108 | t_copy: defb 4,"COPY" 109 | 110 | tk_spectrum:equ $a3 111 | tk_play:equ $a4 112 | tk_rnd: equ $a5 113 | tk_inkeys:equ $a6 114 | tk_pi: equ $a7 115 | tk_fn: equ $a8 116 | tk_point:equ $a9 117 | tk_screens:equ $aa 118 | tk_attr:equ $ab 119 | tk_at: equ $ac 120 | tk_tab: equ $ad 121 | tk_vals:equ $ae 122 | tk_code:equ $af 123 | tk_val: equ $b0 124 | tk_len: equ $b1 125 | tk_sin: equ $b2 126 | tk_cos: equ $b3 127 | tk_tan: equ $b4 128 | tk_asn: equ $b5 129 | tk_acs: equ $b6 130 | tk_atn: equ $b7 131 | tk_ln: equ $b8 132 | tk_exp: equ $b9 133 | tk_int: equ $ba 134 | tk_sqr: equ $bb 135 | tk_sgn: equ $bc 136 | tk_abs: equ $bd 137 | tk_peek:equ $be 138 | tk_in: equ $bf 139 | tk_usr: equ $c0 140 | tk_strs:equ $c1 141 | tk_chrs:equ $c2 142 | tk_not: equ $c3 143 | tk_bin: equ $c4 144 | tk_or: equ $c5 145 | tk_and: equ $c6 146 | tk_le: equ $c7 147 | tk_ge: equ $c8 148 | tk_ne: equ $c9 149 | tk_line:equ $ca 150 | tk_then:equ $cb 151 | tk_to: equ $cc 152 | tk_step:equ $cd 153 | tk_deffn:equ $ce 154 | tk_cat: equ $cf 155 | tk_format:equ $d0 156 | tk_move:equ $d1 157 | tk_erase:equ $d2 158 | tk_open:equ $d3 159 | tk_close:equ $d4 160 | tk_merge:equ $d5 161 | tk_verify:equ $d6 162 | tk_beep:equ $d7 163 | tk_circle:equ $d8 164 | tk_ink: equ $d9 165 | tk_paper:equ $da 166 | tk_flash:equ $db 167 | tk_bright:equ $dc 168 | tk_inverse:equ $dd 169 | tk_over:equ $de 170 | tk_out: equ $df 171 | tk_lprint:equ $e0 172 | tk_llist:equ $e1 173 | tk_stop:equ $e2 174 | tk_read:equ $e3 175 | tk_data:equ $e4 176 | tk_restore:equ $e5 177 | tk_new: equ $e6 178 | tk_border:equ $e7 179 | tk_continue:equ $e8 180 | tk_dim: equ $e9 181 | tk_rem: equ $ea 182 | tk_for: equ $eb 183 | tk_goto:equ $ec 184 | tk_gosub:equ $ed 185 | tk_input:equ $ee 186 | tk_load:equ $ef 187 | tk_list:equ $f0 188 | tk_let: equ $f1 189 | tk_pause:equ $f2 190 | tk_next:equ $f3 191 | tk_poke:equ $f4 192 | tk_print:equ $f5 193 | tk_plot:equ $f6 194 | tk_run: equ $f7 195 | tk_save:equ $f8 196 | tk_randomize:equ $f9 197 | tk_if: equ $fa 198 | tk_cls: equ $fb 199 | tk_draw:equ $fc 200 | tk_clear:equ $fd 201 | tk_return:equ $fe 202 | tk_copy:equ $ff 203 | -------------------------------------------------------------------------------- /lib/zxrom.asm: -------------------------------------------------------------------------------- 1 | ; ZX Spectrum ROM entry points 2 | cls: equ 0d6bh 3 | cls_lower: equ 0d6eh 4 | add_char: equ 0f81h 5 | ed_keys: equ 0f92h 6 | clear_sp: equ 1097h 7 | wait_key: equ 15d4h 8 | wait_key1: equ 15deh 9 | chan_open: equ 1601h 10 | make_room: equ 1655h 11 | set_min: equ 16b0h 12 | set_work: equ 16bfh 13 | close0a: equ 16e8h 14 | close0: equ 16ebh 15 | str_data0: equ 1721h 16 | report_o_2: equ 1725h 17 | line_addr: equ 196eh 18 | next_one: equ 19b8h 19 | reclaim1: equ 19e5h 20 | reclaim2: equ 19e8h 21 | e_line_no: equ 19fbh 22 | line_scan: equ 1b17h 23 | report_0: equ 1bb0h 24 | break_key: equ 1f54h 25 | caps_shift: equ 1f5ah 26 | alpha: equ 2c8dh 27 | numeric: equ 2d1bh 28 | stack_bc: equ 2d2bh 29 | print_fp: equ 2de3h 30 | -------------------------------------------------------------------------------- /load.asm: -------------------------------------------------------------------------------- 1 | ; save BASIC program as ASCII file 2 | 3 | include "lib/sysvars.asm" 4 | include "lib/hooks.asm" 5 | include "lib/zxrom.asm" 6 | include "lib/empty-usage.asm" 7 | 8 | arg_e: equ 3400h 9 | 10 | execute:ld a,(hl) 11 | ld de,f_name 12 | call strarg 13 | jr nz,usage 14 | 15 | ld de,(prog) 16 | ld hl,(vars) 17 | rst 18h 18 | defw reclaim1 19 | 20 | include "lib/addlines.asm" 21 | include "lib/tokens.asm" 22 | include "lib/strarg.asm" 23 | include "lib/puts.asm" 24 | 25 | usaget: defb "Usage: load filename", 0dh, 00h 26 | fd: equ $ 27 | buf: equ fd + 1 28 | found: equ buf + 1 29 | foundl: equ found + 1 30 | f_name: equ foundl + 1 31 | include "lib/align512.asm" 32 | -------------------------------------------------------------------------------- /merge.asm: -------------------------------------------------------------------------------- 1 | ; save BASIC program as ASCII file 2 | 3 | include "lib/sysvars.asm" 4 | include "lib/hooks.asm" 5 | include "lib/zxrom.asm" 6 | include "lib/empty-usage.asm" 7 | 8 | arg_e: equ 3400h 9 | 10 | execute:ld a,(hl) 11 | ld de,f_name 12 | call strarg 13 | jr nz,usage 14 | 15 | include "lib/addlines.asm" 16 | include "lib/tokens.asm" 17 | include "lib/strarg.asm" 18 | include "lib/puts.asm" 19 | 20 | usaget: defb "Usage: merge filename", 0dh, 00h 21 | fd: equ $ 22 | buf: equ fd + 1 23 | found: equ buf + 1 24 | foundl: equ found + 1 25 | f_name: equ foundl + 1 26 | include "lib/align512.asm" 27 | -------------------------------------------------------------------------------- /mv-esxdos087.asm: -------------------------------------------------------------------------------- 1 | ; MV command from esxDOS v0.8.7 2 | 3 | ; Errata: 4 | ; 1. Only the first argument is moved to the last, no check against more than 2 args 5 | ; 2. Arguments buffer overflow 6 | ; 3. No sanitization of file names (maybe esxDOS system calls do it) 7 | 8 | include "lib/sysvars.asm" 9 | include "lib/hooks.asm" 10 | include "lib/empty-usage.asm" 11 | include "lib/cpmv-esxdos087.asm" 12 | 13 | arg_e: equ 2200h 14 | 15 | do: ld a,"*" 16 | ld hl,f_name 17 | ld de,(f_name2) 18 | rst 8 19 | defb frename 20 | ret 21 | 22 | include "lib/strcpy.asm" 23 | include "lib/parse2-esxdos087.asm" 24 | include "lib/basename.asm" 25 | include "lib/chkdir.asm" 26 | include "lib/puts.asm" 27 | 28 | usaget: defb "Usage: mv source target", 0dh, 00h 29 | 30 | f_name2:defw 0 31 | defb 0 32 | f_name: defs arg_e - $ 33 | -------------------------------------------------------------------------------- /open.asm: -------------------------------------------------------------------------------- 1 | ; open esxDOS file stream 2 | 3 | include "lib/sysvars.asm" 4 | include "lib/hooks.asm" 5 | include "lib/zxrom.asm" 6 | include "lib/empty-usage.asm" 7 | 8 | arg_e: equ 3400h 9 | 10 | execute:ld a,(hl) 11 | cp "#" 12 | jr nz,nohash 13 | inc hl 14 | nohash: call numarg 15 | jr c,usage 16 | jr z,usage 17 | ld a,e 18 | ld (s_num),a 19 | ld de,f_name 20 | call strarg 21 | jr nz,usage 22 | 23 | ld hl,serv 24 | ld de,chinfo 25 | push hl 26 | push de 27 | ld b,serv_l 28 | openl: ld a,(de) 29 | cp (hl) 30 | jr nz,setserv 31 | inc hl 32 | inc de 33 | djnz openl 34 | pop de 35 | pop hl 36 | jr doopen 37 | 38 | setserv:ld hl,(chans) 39 | bit 7,h 40 | jr nz,rep_o ; ZX85 coroutines cannot do this 41 | ld bc,serv_l 42 | push bc 43 | dec hl ; move CHANS as well 44 | rst 18h 45 | defw make_room 46 | pop bc 47 | pop de 48 | pop hl 49 | push bc 50 | ldir 51 | pop bc 52 | dec hl 53 | ld de,(chans) 54 | dec de 55 | lddr 56 | 57 | doopen: ld b,09h 58 | ld a,"*" 59 | ld hl,f_name 60 | rst 8 61 | defb fopen 62 | ret c 63 | ld (fd),a 64 | 65 | s_num: equ $ + 1 66 | zxopen: ld a,0 67 | rst 18h 68 | defw str_data0 69 | ld a,b 70 | or c 71 | jr z,open1 72 | ex de,hl 73 | ld hl,(chans) 74 | add hl,bc 75 | inc hl 76 | inc hl 77 | inc hl 78 | ld a,(hl) 79 | ex de,hl 80 | cp "K" 81 | jr z,open1 82 | cp "S" 83 | jr z,open1 84 | cp "P" 85 | jr z,open1 86 | rep_o: rst 18h 87 | defw report_o_2 88 | open1: push hl 89 | ld hl,(prog) 90 | dec hl 91 | ld bc,fch_e-fch 92 | push bc 93 | rst 18h 94 | defw make_room 95 | ld hl,fch_e - 1 96 | pop bc 97 | lddr 98 | ld hl,(chans) 99 | ex de,hl 100 | and a 101 | sbc hl,de 102 | inc hl 103 | inc hl 104 | ex de,hl 105 | pop hl 106 | ld (hl),e 107 | inc hl 108 | ld (hl),d 109 | and a 110 | ret 111 | 112 | include "lib/numarg.asm" 113 | include "lib/strarg.asm" 114 | include "lib/atob.asm" 115 | include "lib/puts.asm" 116 | 117 | serv: equ $ 118 | org chinfo 119 | ld ix,(curchl) 120 | ld a,(ix+5) 121 | ld bc,1 122 | ret 123 | fin: call chinfo 124 | ld ix,membot 125 | rst 8 126 | defb fread 127 | dec c 128 | ld a,(membot) 129 | scf 130 | ret z 131 | or c 132 | ret 133 | fout: ld (membot),a 134 | call chinfo 135 | ld ix,membot 136 | rst 8 137 | defb fwrite 138 | ret nc 139 | rst 8 140 | defb 12h 141 | 142 | serv_l: equ $ - chinfo 143 | org serv + serv_l 144 | 145 | usaget: defb "Usage: open [#]stream filename", 0dh, 00h 146 | fch: defw fout 147 | defw fin 148 | defb "F" 149 | fd: defb 0 150 | defs 3 151 | defw fch_e - fch 152 | fch_e: equ $ 153 | f_name: include "lib/align512.asm" 154 | -------------------------------------------------------------------------------- /save.asm: -------------------------------------------------------------------------------- 1 | ; save BASIC program as ASCII file 2 | 3 | include "lib/sysvars.asm" 4 | include "lib/hooks.asm" 5 | include "lib/zxrom.asm" 6 | include "lib/empty-usage.asm" 7 | 8 | arg_e: equ 3400h 9 | 10 | execute:ld a,(hl) 11 | ld de,f_name 12 | call strarg 13 | jr nz,usage 14 | 15 | doopen: ld b,09h 16 | ld a,"*" 17 | ld hl,f_name 18 | rst 8 19 | defb fopen 20 | ret c 21 | ld (fd),a 22 | 23 | ld hl,(prog) 24 | next_ln:ld a,(hl) 25 | cp $40 26 | jr nc, doclose 27 | 28 | ld d,a 29 | inc hl 30 | ld e,(hl) 31 | inc hl 32 | push hl 33 | ex de,hl 34 | ld e," " 35 | ld bc,-1000 36 | call out_dig 37 | ld bc,-100 38 | call out_dig 39 | ld bc,-10 40 | call out_dig 41 | ld a, l 42 | call out_cd 43 | pop hl 44 | 45 | inc hl 46 | inc hl 47 | 48 | next_c: ld a, (hl) 49 | inc hl 50 | cp $0D 51 | jr z,next_l 52 | cp $0E 53 | jr nz,n_skip 54 | inc hl 55 | inc hl 56 | inc hl 57 | inc hl 58 | inc hl 59 | jr next_c 60 | 61 | next_l: ld a,$0A 62 | call out_char 63 | jr next_ln 64 | 65 | n_skip: call out_char 66 | jr next_c 67 | 68 | doclose:ld a,(fd) 69 | rst 8 70 | defb fclose 71 | ret 72 | 73 | out_dig:xor a 74 | out_dl: add hl,bc 75 | inc a 76 | jr c,out_dl 77 | sbc hl,bc 78 | dec a 79 | jr nz,out_cd 80 | ld a, e 81 | jr write_a 82 | out_cd: ld e,"0" 83 | add a,e 84 | write_a:ld bc,1 85 | push de 86 | push hl 87 | ld hl,buf 88 | ld (hl),a 89 | ld a,(fd) 90 | rst 8 91 | defb fwrite 92 | pop hl 93 | pop de 94 | ret 95 | 96 | token: cp tk_rnd 97 | jr c,t_sp 98 | cp tk_line 99 | jr c,t_nosp 100 | t_sp: bit 0,(iy+flags-err_nr) 101 | jr nz,t_nosp 102 | push af 103 | ld a, " " 104 | call write_a 105 | pop af 106 | t_nosp: push af 107 | sub a,tk_spectrum 108 | ld l,a 109 | ld h,0 110 | add hl,hl 111 | ld de,tokens128 112 | add hl,de 113 | ld a,(hl) 114 | inc hl 115 | ld h,(hl) 116 | ld l,a 117 | ld c,(hl) 118 | ld b,0 119 | inc hl 120 | ld a,(fd) 121 | rst 8 122 | defb fwrite 123 | dec hl 124 | ld c,(hl) 125 | pop af 126 | pop hl 127 | cp tk_rnd 128 | jr c,t_sp2 129 | cp tk_fn 130 | ret c 131 | t_sp2: ld a,c 132 | cp "A" 133 | ret c 134 | ld a," " 135 | 136 | out_char: 137 | push hl 138 | ld hl,flags 139 | res 0,(hl) 140 | cp " " 141 | jr nz, nospc 142 | set 0,(hl) 143 | nospc: ld hl,flags2 144 | cp "\"" 145 | jr nz, noquot 146 | noquot: bit 2,(hl) 147 | jr nz,quoted 148 | bit 4,(iy+flags-err_nr) 149 | ld c,tk_rnd 150 | jr z,t48 151 | ld c,tk_spectrum 152 | t48: cp c 153 | jr nc,token 154 | quoted: call write_a 155 | pop hl 156 | ret 157 | 158 | include "lib/tokens.asm" 159 | include "lib/strarg.asm" 160 | include "lib/puts.asm" 161 | 162 | usaget: defb "Usage: save filename", 0dh, 00h 163 | fd: equ $ 164 | buf: equ fd + 1 165 | f_name: equ buf + 1 166 | include "lib/align512.asm" 167 | -------------------------------------------------------------------------------- /sc2.asm: -------------------------------------------------------------------------------- 1 | ; MSX1 SC2 file viewer command for esxDOS 2 | 3 | include "lib/sysvars.asm" 4 | include "lib/hooks.asm" 5 | include "lib/zxrom.asm" 6 | include "lib/empty-usage.asm" 7 | 8 | arg_e: equ 2800h 9 | 10 | execute:call options 11 | jr nc,usage 12 | ld de,f_name 13 | call strarg 14 | jr nz,usage 15 | 16 | ld a,"*" 17 | ld b,fopen_r 18 | ld hl,f_name 19 | rst 8 20 | defb fopen 21 | ret c ; file not found 22 | ld (fd),a 23 | 24 | ld hl,bitmap 25 | push hl 26 | ld bc,0007h 27 | rst 8 28 | defb fread 29 | pop hl 30 | ret c ; any read error 31 | ld de,sc2head 32 | ld b,7 33 | chkhead:ld a,(de) 34 | cp (hl) 35 | jr nz,usage ; invalid file format 36 | inc de 37 | inc hl 38 | djnz chkhead 39 | 40 | ld c,0ffh 41 | in a,(c) 42 | ld (video),a 43 | in b,(c) 44 | or b 45 | inc a 46 | ld a,10 ; Invalid I/O REQUEST 47 | scf 48 | ret z ; no Timex video modes 49 | 50 | ld de,(chans) 51 | ld hl,7800h 52 | sbc hl,de 53 | jr c,noalloc 54 | inc hl 55 | ex de,hl 56 | ld (ochans),hl 57 | ld c,e 58 | ld b,d 59 | rst 18h 60 | defw make_room 61 | inc de 62 | ld (chans),de ; reserve video buffer 63 | 64 | noalloc:ld a,2 65 | out (0ffh),a ; change video mode to hicolor 66 | 67 | ld a,(fd) 68 | ld de,4000h 69 | 70 | thirds: ld bc,0800h 71 | ld hl,bitmap 72 | push de 73 | push hl 74 | rst 8 75 | defb fread 76 | pop hl 77 | pop de 78 | jr c,jcrest ; any read error 79 | thirdl: ld bc,08ffh 80 | push de 81 | cell: ldi 82 | dec de 83 | inc d 84 | djnz cell 85 | pop de 86 | inc e 87 | jr nz,thirdl 88 | ld a,d 89 | add a,8 90 | ld d,a 91 | or 0e7h 92 | inc a 93 | fd: equ $ + 1 94 | ld a,0 95 | jr nz,thirds 96 | 97 | bit 5,d 98 | jr nz,loaded 99 | 100 | ; load characters 101 | ld hl,chars0 102 | ld bc,0300h 103 | rst 8 104 | defb fread 105 | jr c,jcrest 106 | 107 | ; skip to palette 108 | ld hl,6000h 109 | ld bc,0080h 110 | ld a,(fd) 111 | rst 8 112 | defb fread 113 | jr c,jcrest 114 | 115 | ;load palette 116 | paladd: equ $ + 1 117 | ld hl,palette 118 | ld bc,0020h 119 | ld a,(fd) 120 | rst 8 121 | defb fread 122 | jcrest: jr c,restore 123 | 124 | ;set palette 125 | ld bc,0bf3bh 126 | ld a,40h 127 | out (c),a 128 | ld b,0ffh 129 | in a,(c) 130 | in e,(c) 131 | ld (palmod),a 132 | or e 133 | inc a 134 | jr z,jpald 135 | ulaplus:equ $ + 1 136 | ld a,1 137 | out (c),a 138 | or a 139 | jpald: jp z,paldone 140 | 141 | ld e,0 142 | ld hl,palette 143 | pall: ld c,(hl) 144 | inc hl 145 | ld a,(hl) 146 | inc hl 147 | rrca 148 | rrca 149 | rrca 150 | ld b,a 151 | ld a,c 152 | rrca 153 | rrca 154 | and 1ch 155 | or b 156 | ld b,a 157 | ld a,c 158 | rrca 159 | and 03h 160 | or b 161 | ex af,af' ; A' = ULAplus color 162 | 163 | ld d,trantab / 100h 164 | ld a,(de) 165 | rrca 166 | rrca 167 | rrca 168 | bit 3,a 169 | jr z,dark 170 | 171 | add 30h ; 11 paper 172 | call setcol 173 | sub a,8 ; 11 ink 174 | call setcol 175 | sub a,10h ; 10 ink 176 | call setcol 177 | sub a,8 ; 01 paper 178 | jr bright 179 | 180 | loaded: rst 8 181 | defb fclose 182 | 183 | ; translate attributes 184 | ld d,trantab / 100h 185 | ld hl,6000h 186 | transl: ld e,(hl) 187 | ld a,(de) 188 | ld (hl),a 189 | inc hl 190 | ld a,h 191 | cp 78h 192 | jr c,transl 193 | 194 | key: xor a 195 | in a,(0feh) 196 | or 0e0h 197 | inc a 198 | jr z,key 199 | xor a 200 | 201 | restore:push af 202 | 203 | palmod: equ $ + 1 204 | ld a,0 205 | ex af,af' 206 | ld a,40h 207 | call setcol 208 | 209 | ld a,(video) 210 | cp 2 211 | jr z,memok ; if video mode was hicolor, leave it 212 | out (0ffh),a 213 | rst 18h 214 | defw cls 215 | ld hl,(chans) 216 | ld de,(ochans) 217 | ld a,d 218 | or e 219 | jr z,memok ; if no memory was allocated, don't reclaim 220 | rst 18h 221 | defw reclaim1 222 | ld (chans),hl 223 | 224 | memok: pop af 225 | ret 226 | 227 | dark: call setcol ; 00 ink 228 | add a,8 229 | call setcol ; 00 paper 230 | add a,8 231 | call setcol ; 01 ink 232 | add a,18h 233 | bright: call setcol ; 10 paper 234 | 235 | inc e 236 | bit 4,e 237 | jp z,pall 238 | 239 | ; skip to attributes 240 | paldone:call z,timex 241 | ld hl,6000h 242 | ld bc,0460h 243 | ld a,(fd) 244 | rst 8 245 | defb fread 246 | jr c,restore 247 | 248 | ld de,6000h 249 | ld a,(fd) 250 | jp thirds 251 | 252 | setcol: ld bc,0bf3bh 253 | out (c),a 254 | ex af,af' 255 | ld b,0ffh 256 | out (c),a 257 | ex af,af' 258 | ret 259 | 260 | sc2head:defb 0feh, 00h, 00h, 0ffh, 37h, 00h, 00h 261 | 262 | optab: defb "t" 263 | defb timex - $ 264 | defb "s" 265 | defb spectrum - $ 266 | defb "m" 267 | defb msx - $ 268 | defb "h" 269 | defb help - $ 270 | defb 0 271 | 272 | timex: ld hl,trantab 273 | timexl: res 7,(hl) 274 | inc l 275 | jr nz,timexl 276 | xor a 277 | ld (ulaplus),a 278 | ret 279 | 280 | spectrum: 281 | push de 282 | ld hl,approx 283 | ld de,mgreen 284 | ld bc,26 285 | ldir 286 | pop de 287 | msx: ld hl,bitmap 288 | ld (paladd),hl 289 | ret 290 | 291 | help: call usage 292 | ld hl,helpt 293 | call puts 294 | pop bc 295 | pop bc 296 | xor a 297 | ret 298 | 299 | include "lib/strarg.asm" 300 | include "lib/options.asm" 301 | include "lib/puts.asm" 302 | include "lib/indexer.asm" 303 | 304 | usaget: defb "Usage: sc2 [-{tsmh}] source.sc2", 0dh, 00h 305 | helpt: defb 0dh 306 | defb "Display MSX1 SC2 screenshot", 0dh, 0dh 307 | defb "-t Timex 20xx mode, no palette", 0dh 308 | defb " overrides s and m", 0dh 309 | defb "-s ZX Spectrum approx. palette", 0dh 310 | defb " overrides m", 0dh 311 | defb "-m MSX1 default palette", 0dh, 0dh 312 | defb "Without ULAplus, -t is default.", 0dh, 00h 313 | video: defb 0 314 | ochans: defw 0 315 | palette:defw 0000h ; transparent, approx. black 316 | black: defw 0000h ; approx. bright black 317 | mgreen: defw 0522h ; approx. cyan 318 | lgreen: defw 0633h ; approx. bright green 319 | dblue: defw 0226h ; approx. blue 320 | lblue: defw 0337h ; approx. bright blue 321 | dred: defw 0352h ; approx. red 322 | cyan: defw 0637h ; approx. bright cyan 323 | mred: defw 0362h ; approx. magenta 324 | lred: defw 0473h ; approx. bright red 325 | dyellow:defw 0662h ; approx. yellow 326 | lyellow:defw 0665h ; approx. bright yellow 327 | dgreen: defw 0422h ; approx. green 328 | magenta:defw 0355h ; approx. bright magenta 329 | gray: defw 0666h ; approx. white 330 | white: defw 0777h ; approx. bright white 331 | approx: defw 505h,700h,005h,007h,050h,707h,055h,070h,550h,770h,500h,077h,555h 332 | 333 | defs 100h * (($ + 0ffh) / 100h) - $ 334 | trantab:incbin "sc2.tab" 335 | 336 | f_name: include "lib/align512.asm" 337 | bitmap: equ $ 338 | chars0: equ bitmap + 0800h 339 | chars1: equ chars0 + 0100h 340 | chars2: equ chars1 + 0100h 341 | 342 | -------------------------------------------------------------------------------- /sc2.tab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nagydani/dot-commands/a2a0cccfa3b8f6af1b961a938e7548bf8bb95d8b/sc2.tab -------------------------------------------------------------------------------- /te.asm: -------------------------------------------------------------------------------- 1 | ; very simple text file editor for esxDOS 2 | 3 | include "lib/sysvars.asm" 4 | include "lib/hooks.asm" 5 | include "lib/zxrom.asm" 6 | include "lib/empty-usage.asm" 7 | 8 | arg_e: equ 2800h 9 | 10 | execute:ld de,f_name 11 | call strarg 12 | jr nz,usage 13 | 14 | rst 18h 15 | defw cls 16 | 17 | teloop: rst 18h 18 | defw set_work 19 | ld hl,flagx 20 | res 6,(hl) 21 | set 7,(hl) ; INPUT LINE 22 | set 5,(hl) ; INPUT 23 | ld bc,0001h 24 | rst 18h 25 | defw 0030h 26 | ld (hl),0dh 27 | ld (k_cur),hl 28 | ld hl,0 29 | ld (e_num),hl 30 | ld hl,0ffech 31 | add hl,sp 32 | ld (list_sp),hl 33 | 34 | ld a,"*" 35 | ld b,fopen_r 36 | ld hl,f_name 37 | rst 8 38 | defb fopen 39 | ld bc,0000h 40 | ld de,0001h 41 | jr c,redraw 42 | ld (fd),a 43 | ld hl,newfile 44 | ld (hl),e ; file not new 45 | 46 | ld hl,(d_num) 47 | ld a,h 48 | or l 49 | jr z,line0 50 | telp1: push hl 51 | call seekln 52 | ld bc,1000h 53 | ld hl,arg_e 54 | ld a,(fd) 55 | rst 8 56 | defb fread 57 | ld (buffer),bc 58 | pop de 59 | 60 | redraw: ld a,0feh 61 | push bc 62 | push de 63 | rst 18h 64 | defw chan_open 65 | pop de 66 | pop bc 67 | set 4,(iy+tv_flag-err_nr) 68 | ld (iy+breg-err_nr),0 69 | ld a,16h 70 | rst 10h 71 | xor a 72 | rst 10h 73 | rst 10h 74 | ld hl,(c_num) 75 | and a 76 | sbc hl,de 77 | jr nc,curvis 78 | add hl,de ; restore c_num 79 | ld (d_num),hl 80 | push hl 81 | call seek0 82 | pop hl 83 | jr telp1 84 | 85 | curvis: ld de,arg_e 86 | call lines 87 | jr nc,moveup 88 | bit 4,(iy+tv_flag-err_nr) 89 | jr nz,inscr 90 | ; TODO: SLOW 91 | scrdown:call seek0 92 | ld hl,(d_num) 93 | inc hl 94 | ld (d_num),hl 95 | jr telp1 96 | 97 | inscr: ld a,14h 98 | rst 10h 99 | ld a,1 100 | rst 10h 101 | ld hl,1 102 | ld (c_ptr),de 103 | ld (c_len),bc 104 | call lines 105 | jr nc,donescr 106 | bit 4, (iy+tv_flag-err_nr) 107 | jr z,scrdown 108 | line0: ld hl,(s_posn+1) 109 | ld h,0 110 | call lines 111 | 112 | donescr:res 4,(iy+tv_flag-err_nr) 113 | rst 18h 114 | defw cls_lower 115 | ld bc,(c_num) 116 | rst 18h 117 | defw stack_bc 118 | rst 18h 119 | defw print_fp 120 | ld a,":" 121 | rst 10h 122 | 123 | keyloop:rst 18h 124 | defw wait_key 125 | cp " " 126 | jr z,space 127 | cp 18h 128 | jr nc,insert 129 | cp 07h 130 | jr c,insert 131 | jr z,edit 132 | cp 0ah 133 | jr z,down 134 | cp 0bh 135 | jr z,up 136 | cp 0ch 137 | jr z,delete 138 | cp 0dh 139 | jp z,enter 140 | edkeys: rst 18h 141 | defw ed_keys 142 | jr keyloop 143 | 144 | moveup: ld hl,(c_num) 145 | dec hl 146 | ld a,h 147 | or l 148 | jr z,keyloop 149 | jr vert 150 | 151 | edit: rst 18h 152 | defw clear_sp 153 | edit2: ld a,0ffh 154 | rst 18h 155 | defw chan_open 156 | c_ptr: equ $ + 1 157 | ld de,arg_e 158 | c_len: equ $ + 1 159 | ld bc,0000h 160 | call println 161 | ld (terminator),a 162 | ld hl,(c_num) 163 | ld (e_num),hl 164 | jr redraw2 165 | 166 | up: ld hl,(k_cur) 167 | ld de,(worksp) 168 | and a 169 | sbc hl,de 170 | jr z,moveup 171 | ld (k_cur),de 172 | jr keyloop 173 | 174 | space: rst 18h 175 | defw caps_shift 176 | ret nc 177 | call symbol_shift 178 | ld a," " 179 | jr z,insert 180 | jr edit2 181 | 182 | insert: rst 18h 183 | defw add_char 184 | keyloop2: 185 | jr keyloop 186 | 187 | down: ld hl,(k_cur) 188 | ld a,0dh 189 | cp (hl) 190 | jr z,movedown 191 | ld bc,0 192 | cpir 193 | dec hl 194 | ld (k_cur),hl 195 | jr keyloop2 196 | 197 | movedown: 198 | ld hl,(c_num) 199 | inc hl 200 | vert: ld (c_num),hl 201 | redraw2:ld de,(d_num) 202 | buffer: equ $ + 1 203 | ld bc,0000h 204 | jp redraw 205 | 206 | delete: bit 1,(iy+mode-err_nr) 207 | jr z,edkeys 208 | rst 18h 209 | defw caps_shift 210 | ld hl,(k_cur) 211 | jr nc,backdel 212 | ld e,l 213 | ld d,h 214 | ld bc,0 215 | ld a,0dh 216 | cpir 217 | dec hl 218 | jr fwdel 219 | 220 | backdel:ld de,(worksp) 221 | fwdel: rst 18h 222 | defw reclaim1 223 | ld (k_cur),hl 224 | jp keyloop 225 | 226 | enter: ld hl,terminator 227 | rst 18h 228 | defw caps_shift 229 | jr c,enter3 230 | ld (hl),0 231 | jr enter2 ; join 232 | 233 | enter3: call symbol_shift 234 | jr z,enter4 235 | ld a,(hl) 236 | or a 237 | jr nz,enterx 238 | ld a,0ah 239 | enterx: xor 7 240 | ld (hl),a ; switch 241 | 242 | enter4: bit 1,(iy+mode-err_nr) 243 | jr z,enter2 244 | ld a,0dh 245 | rst 18h 246 | defw add_char ; split 247 | 248 | enter2: ld hl,tmpname 249 | ld a,"*" 250 | ld b,fopen_w 251 | rst 8 252 | defb fopen 253 | ret c 254 | ld (ofd),a 255 | 256 | call seek0 257 | ld hl,(c_num) 258 | call copyln 259 | enter0: ld hl,(worksp) 260 | ld bc,1 261 | enterl: ld a,(hl) 262 | cp 0dh 263 | jr z,enter1 264 | ld a,(ofd) 265 | push hl 266 | rst 8 267 | defb fwrite 268 | pop hl 269 | enterl1:inc hl 270 | jr nc,enterl 271 | ret 272 | 273 | seek0: ld a,(fd) 274 | ld bc,0 275 | ld e,c 276 | ld d,c 277 | ld l,c 278 | rst 8 279 | defw fseek 280 | ret 281 | 282 | terminator: equ $ + 1 283 | enter1: ld a,0dh 284 | or a 285 | jr z,entersk 286 | push hl 287 | ld hl,terminator 288 | ld a,(ofd) 289 | rst 8 290 | defb fwrite 291 | pop hl 292 | ret c 293 | entersk:bit 1,(iy+mode-err_nr) 294 | res 1,(iy+mode-err_nr) 295 | jr nz,enterl1 296 | 297 | newfile:equ $ + 1 298 | ld a,0 299 | or a 300 | jr z,enterc 301 | ld hl,(c_num) 302 | ld bc,(e_num) 303 | sbc hl,bc 304 | jr nz,fcopyl 305 | inc l 306 | inc l 307 | call seekln 308 | fcopyl: ld hl,arg_e 309 | ld bc,1000h 310 | ld a,(fd) 311 | push hl 312 | push bc 313 | rst 8 314 | defb fread 315 | pop de 316 | pop hl 317 | ld a,(ofd) 318 | push de 319 | rst 8 320 | defb fwrite 321 | pop de 322 | ret c 323 | ld a,b 324 | cp d 325 | jr z,fcopyl 326 | 327 | enterc: ld a,(fd) 328 | rst 8 329 | defb fclose 330 | enterce:ld a,(ofd) 331 | rst 8 332 | defb fclose 333 | ld a,"*" 334 | ld hl,f_name 335 | push hl 336 | rst 8 337 | defb funlink 338 | ld a,"*" 339 | ld hl,tmpname 340 | pop de 341 | rst 8 342 | defb frename 343 | ret c 344 | ld hl,(c_num) 345 | inc hl 346 | ld (c_num),hl 347 | jp teloop 348 | 349 | ; seek line 350 | ; In: HL = line number 351 | ; Out: ZF set if found 352 | ; Pollutes: everything 353 | ; TODO: SLOW 354 | seekln: ld bc,0001h 355 | seekd: dec hl 356 | ld a,h 357 | or l 358 | ret z 359 | seekl: push hl 360 | ld hl,seekc 361 | fd: equ $ + 1 362 | ld a,0 363 | rst 8 364 | defb fread 365 | pop hl 366 | dec c 367 | ret nz 368 | inc c 369 | seekc: equ $ + 1 370 | ld a,0 371 | cp 0dh ; cr 372 | jr z,seekd 373 | cp 0ah ; lf 374 | jr nz,seekl 375 | jr seekd 376 | 377 | ; copy lines 378 | ; In: HL = line number 379 | ; TODO: SLOW 380 | copyln: ld bc,0001h 381 | copyd: dec hl 382 | ld a,h 383 | or l 384 | ret z 385 | copyl: push hl 386 | ld hl,copyc 387 | ld a,(fd) 388 | rst 8 389 | defb fread 390 | dec c 391 | jr nz,copyr 392 | inc c 393 | dec hl 394 | ofd: equ $ + 1 395 | ld a,0 396 | rst 8 397 | defb fwrite 398 | pop hl 399 | ret c 400 | copyc: equ $ + 1 401 | ld a,0 402 | cp 0dh ; cr 403 | jr z,copyd 404 | cp 0ah ; lf 405 | jr nz,copyl 406 | jr copyd 407 | copyr: pop hl 408 | ret 409 | 410 | ; print lines 411 | ; In: HL = number of lines to print, DE = pointer, BC = bytes till EOF 412 | ; Out: CF clear on EOF 413 | ; Pollutes: everything 414 | lines: ld a,h 415 | or l 416 | jr nz,linel 417 | scf 418 | ret 419 | 420 | linel: call println 421 | ret nc 422 | cp 0dh 423 | jr z,linecr 424 | linelf: ld a,91h 425 | jr line_e 426 | linecr: ld a,90h 427 | line_e: push hl 428 | ld hl,(udg) 429 | push hl 430 | exx 431 | ld hl,crudg 432 | ld de,membot + 9 433 | ld (udg),de 434 | ld bc,10h 435 | ldir 436 | exx 437 | rst 10h 438 | pop hl 439 | ld (udg),hl 440 | pop hl 441 | ld a,0dh 442 | push bc 443 | ld b,(iy+s_posn-err_nr) 444 | call blank 445 | pop bc 446 | dec hl 447 | jr lines 448 | 449 | blank: ld a,80h 450 | jr pad 451 | padl: rst 10h 452 | pad: djnz padl 453 | inv0: ld a,14h 454 | rst 10h 455 | xor a 456 | rst 10h 457 | ret 458 | 459 | symbol_shift: 460 | ld a,7fh 461 | in a,(0feh) 462 | or 0fdh 463 | inc a 464 | ret 465 | 466 | include "lib/strarg.asm" 467 | include "lib/println.asm" 468 | include "lib/puts.asm" 469 | 470 | crudg: defb 00000000b 471 | defb 00000010b 472 | defb 00010010b 473 | defb 00100010b 474 | defb 01111110b 475 | defb 00100000b 476 | defb 00010000b 477 | defb 00000000b 478 | 479 | lfudg: defb 00000000b 480 | defb 01001110b 481 | defb 01001000b 482 | defb 01001110b 483 | defb 01001000b 484 | defb 01001000b 485 | defb 01111000b 486 | defb 00000000b 487 | 488 | d_num: defw 0001h 489 | c_num: defw 0001h 490 | e_num: defw 0000h 491 | usaget: defb "Usage: te filename", 0dh, 00h 492 | tmpname:defb "/tmp/te.tmp", 00h 493 | f_name: include "lib/align512.asm" 494 | --------------------------------------------------------------------------------