tftp proto lib first impl

This commit is contained in:
boykovra 2024-08-10 08:38:18 +03:00
parent 6d9428d988
commit 6aa509d427
10 changed files with 667 additions and 132 deletions

View File

@ -142,6 +142,36 @@
} }
}, },
{
"label": "make CMDTEST (sjasmplus)",
"type": "shell",
"command": "sjasmplus",
"args": [
"--sld=cmdtest.sld",
"--sym=cmdtest.labels",
"--raw=cmdtest.exe",
"--fullpath",
"cmdtest.asm"
],
"problemMatcher": {
"owner": "sjasmplus",
"fileLocation": "autoDetect",
"pattern": {
"regexp": "^(.*)\\((\\d+)\\):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"severity": 3,
"message": 4
}
},
"group": {
"kind": "build",
"isDefault": true
}
},
{ {
"label": "start mame", "label": "start mame",
"type": "shell", "type": "shell",

66
sources/DSS/cmdtest.asm Normal file
View File

@ -0,0 +1,66 @@
DSS EQU 0x10
DSS_PCHARS EQU 0x5C
DSS_EXIT EQU 0x41
EXE_VERSION EQU 0x00
; Print data ASCIIZ string to screen and CR+LF
MACRO PRINTLN data
LD HL,data
LD C,DSS_PCHARS
RST DSS
LD C,DSS_PCHARS
LD HL, MSG_LINE_END
RST DSS
ENDM
MODULE MAIN
ORG 0x8080
; ------------------------------------------------------
EXE_HEADER
DB "EXE"
DB EXE_VERSION ; EXE Version
DW 0x0080 ; Code offset
DW 0
DW 0 ; Primary loader size
DW 0 ; Reserved
DW 0
DW 0
DW START ; Loading Address
DW START ; Entry Point
DW STACK_TOP ; Stack address
DS 106, 0 ; Reserved
ORG 0x8100
@STACK_TOP
; ------------------------------------------------------
START
PRINTLN MSG_CMDLINE
PUSH IX
POP HL
LD C,DSS_PCHARS
RST DSS
PRINTLN MSG_CURPATH
PUSH IY
POP HL
LD C,DSS_PCHARS
RST DSS
LD BC,DSS_EXIT
RST DSS
MSG_CMDLINE
DB "\r\nCommandline:"Z
MSG_CURPATH
DB "\r\nCurrentPath:"Z
MSG_LINE_END
DB "\r\n"Z
ENDMODULE

View File

@ -41,7 +41,7 @@ RST38:
DSS_HANDLER DSS_HANDLER
PUSH HL //PUSH HL
PUSH BC PUSH BC
LD A, C LD A, C
CP DSS_CURDISK CP DSS_CURDISK
@ -119,13 +119,13 @@ NXT_PCHAR
NORM_EXIT NORM_EXIT
AND A ; CF=0 AND A ; CF=0
POP BC POP BC
POP HL //POP HL
RET RET
BAD_EXIT BAD_EXIT
SCF SCF
POP BC POP BC
POP HL //POP HL
RET RET
@ -364,10 +364,10 @@ CMD_LINE_TFTP_D
DB " tftp://tftp.server.ru:1024/file_in.asm c:\\tmp\\file_out.asm"Z DB " tftp://tftp.server.ru:1024/file_in.asm c:\\tmp\\file_out.asm"Z
CMD_LINE_TFTP_D1 CMD_LINE_TFTP_D1
DB " tftp://tftp.server.ru:1024/file_in.asm local.asm"Z DB " tftp://server.ru/file.src sss.dst"Z
CMD_LINE_TFTP_U CMD_LINE_TFTP_U
DB " file_up.txt tftp://tftp.server.ru:9999/file_in.asm "Z DB " file_from.asm tftp://server.ru:9999/file_to.asm"Z
CMD_LINE_TFTP_U1 CMD_LINE_TFTP_U1
DB " file_up.txt"Z DB " file_up.txt"Z

View File

@ -13,6 +13,9 @@ CHECK
RET NC RET NC
PRINT PRINT
PUSH AF
PRINT GET_ERR_MSG.MSG_DSS_ERROR
POP AF
CALL GET_ERR_MSG CALL GET_ERR_MSG
DSS_EXEC DSS_PCHARS DSS_EXEC DSS_PCHARS
LD HL, WCOMMON.LINE_END LD HL, WCOMMON.LINE_END
@ -43,6 +46,9 @@ GET_ERR_MSG
POP AF POP AF
RET RET
.MSG_DSS_ERROR
DB " Error: "Z
.MSG_E01 DB "Invalid function"Z .MSG_E01 DB "Invalid function"Z
.MSG_E02 DB "Invalid drive number"Z .MSG_E02 DB "Invalid drive number"Z
.MSG_E03 DB "File not found"Z .MSG_E03 DB "File not found"Z

View File

@ -503,9 +503,8 @@ MSG_ERROR DB "ERROR", 0
; Received message for Failure ; Received message for Failure
MSG_FAIL DB "FAIL", 0 MSG_FAIL DB "FAIL", 0
IFUSED RS_BUFF
; Buffer to receive response from ESP ; Buffer to receive response from ESP
RS_BUFF DS RS_BUFF_SIZE, 0 RS_BUFF
ENDIF ;DS RS_BUFF_SIZE, 0
ENDMODULE ENDMODULE

View File

@ -15,21 +15,29 @@
CALL CHECK_ERROR CALL CHECK_ERROR
ENDM ENDM
; Print data ASCIIZ string to screen ; Print data forn HL - pointer to ASCIIZ string to screen
MACRO PRINT data MACRO PRINT_HL
LD HL,data
LD C,DSS_PCHARS LD C,DSS_PCHARS
RST DSS RST DSS
ENDM ENDM
; Print data ASCIIZ string to screen and CR+LF ; Print data forn HL - pointer to ASCIIZ string to screen, and <CR><LF>
MACRO PRINTLN_HL
PRINT_HL
LD HL, WCOMMON.LINE_END
PRINT_HL
ENDM
; Print data ASCIIZ string to screen
MACRO PRINT data
LD HL,data
PRINT_HL
ENDM
; Print data ASCIIZ string to screen and <CR><LF>
MACRO PRINTLN data MACRO PRINTLN data
LD HL,data LD HL,data
LD C,DSS_PCHARS PRINTLN_HL
RST DSS
LD C,DSS_PCHARS
LD HL, WCOMMON.LINE_END
RST DSS
ENDM ENDM
; Print data ASCIIZ string to screen if TRACE enabled ; Print data ASCIIZ string to screen if TRACE enabled
@ -51,5 +59,11 @@
RST DSS RST DSS
ENDM ENDM
; If current work mode is upload, go to label
MACRO IF_UPLOAD_GO lbl
LD A,(WORK_MODE)
CP WM_UPLOAD
JR Z,lbl
ENDM
ENDIF ENDIF

163
sources/DSS/tftp.asm Normal file
View File

@ -0,0 +1,163 @@
; ======================================================
; TFTP-protocol support module for WTFTP app
; By Roman Boykov. Copyright (c) 2024
; https://github.com/romychs
; License: BSD 3-Clause
; ======================================================
MODULE TFTP
; ------------------------------------------------------
; Operation codes 2b for tftp packet header
; ------------------------------------------------------
; Opcode Read Request
OP_RRQ EQU '01'
; Opcode Write Request
OP_WRQ EQU '02'
; Opcode Data packet
OP_DATA EQU '03'
; Opcode Acknowledge packet
OP_ACK EQU '04'
; Opcode Error packet
OP_ERROR EQU '05'
; ------------------------------------------------------
; Build packet for request file from TFTF-server
; Out: HL - pointer to buffer to send
; ------------------------------------------------------
BUILD_RRQ_PACKET
PUSH DE
LD DE,OP_RRQ ; opcode
CALL .BUILD_RW_PACKET
POP HL,DE
RET
; ------------------------------------------------------
; Build packet for write file to TFTF-server
; ------------------------------------------------------
!BUILD_WRQ_PACKET
PUSH DE
LD DE,OP_WRQ ; opcode
CALL .BUILD_RW_PACKET
POP HL,DE
RET
; ------------------------------------------------------
; Build packet for write file or receive form TFTF-server
; ------------------------------------------------------
.BUILD_RW_PACKET
LD HL,TFTP_BUFF
PUSH HL
LD (HL), DE
INC HL
INC HL
LD DE,MAIN.REM_FILE
; filename
.BRP_NXT_RF
LD A, (DE)
LD (HL), A
OR A
JR Z,.BRP_MOD
INC HL
INC DE
JR .BRP_NXT_RF
; Mode 'octet'Z
.BRP_MOD
INC HL
LD DE,'ct'
LD (HL),DE
INC HL
LD DE,'et'
LD (HL),DE
INC HL
LD DE,'t'
LD (HL),DE
RET
; ------------------------------------------------------
; Check TFTP Error, out error message if '05' packet
; type received
; Out: CF set if Error
; A - packet type, second byte if no errors
; ------------------------------------------------------
CHK_ERROR
LD HL,TFTP_BUFF
LD A, (HL)
CP '0'
JR NZ, .CKE_UNKNOWN
INC HL
LD A, (HL)
CP '5'
JR Z, .CKE_ERR
OR A
RET
.CKE_ERR
INC HL
LD DE,(HL) ; ErrorCode
LD A, D
OR E
; check for 1..7 range for defined error codes
JR Z,.CKE_UNDEF_ERR
LD A,E
CP 8
JP P,.CKE_UNDEF_ERR
; defined error
ADD A
LD E,A
LD HL,.TFTPE_T
ADD HL,DE
LD A,(HL)
INC HL
LD H,(HL)
LD L,A
; print error message, HL - pointer to message
.CKE_PRINT_ERR
PUSH HL
PRINT .MSG_TFTP_ERR ; Protocol error: ...
POP HL
PRINTLN_HL
JR .CKE_ERR_EXIT
; undefined error, message in datagram
.CKE_UNDEF_ERR
INC HL
INC HL
JR .CKE_PRINT_ERR
.CKE_UNKNOWN
; unknown packet type
PRINTLN .MSG_ERR_UPT
.CKE_ERR_EXIT
SCF
RET
; ------------------------------------------------------
; Defined TFTP Protocol Error messages
; ------------------------------------------------------
;MSG_TFTPE_0 DB "Not defined, see error message (if any)."Z
.MSG_TFTPE_1 DB "File not found."Z
.MSG_TFTPE_2 DB "Access violation."Z
.MSG_TFTPE_3 DB "Disk full or allocation exceeded."Z
.MSG_TFTPE_4 DB "Illegal TFTP operation."Z
.MSG_TFTPE_5 DB "Unknown transfer ID."Z
.MSG_TFTPE_6 DB "File already exists."Z
.MSG_TFTPE_7 DB "No such user."Z
; Table with error messages offsets
.TFTPE_T
DW .MSG_TFTPE_1,.MSG_TFTPE_1,.MSG_TFTPE_2,.MSG_TFTPE_3
DW .MSG_TFTPE_4,.MSG_TFTPE_5,.MSG_TFTPE_7,.MSG_TFTPE_7
.MSG_TFTP_ERR
DB "Protocol error: "Z
.MSG_ERR_UPT
DB "Unknown TFTP packet received!"Z
; Buffer for UDP datagram with TFTP payload
TFTP_BUFF
DS 516,0
ENDMODULE

View File

@ -19,26 +19,26 @@ DELAY
LD A,H LD A,H
OR L OR L
JR NZ,DELAY_NXT JR NZ,.DELAY_NXT
LD HL,20 LD HL,20
DELAY_NXT .DELAY_NXT
CALL DELAY_1MS_INT CALL .DELAY_1MS_INT
DEC HL DEC HL
LD A,H LD A,H
OR L OR L
JP NZ,DELAY_NXT JP NZ,.DELAY_NXT
POP HL,BC,AF POP HL,BC,AF
RET RET
DELAY_1MS_INT .DELAY_1MS_INT
LD BC,400 LD BC,400
SBD_NXT .SBD_NXT
DEC BC DEC BC
LD A, B LD A, B
OR C OR C
JR NZ, SBD_NXT JR NZ, .SBD_NXT
RET RET
; ------------------------------------------------------ ; ------------------------------------------------------
@ -46,7 +46,7 @@ SBD_NXT
; ------------------------------------------------------ ; ------------------------------------------------------
DELAY_1MS DELAY_1MS
PUSH BC PUSH BC
CALL DELAY_1MS_INT CALL DELAY.DELAY_1MS_INT
POP BC POP BC
RET RET
@ -56,7 +56,7 @@ DELAY_1MS
DELAY_100uS DELAY_100uS
PUSH BC PUSH BC
LD BC,40 LD BC,40
CALL SBD_NXT CALL DELAY.SBD_NXT
POP BC POP BC
RET RET
@ -76,33 +76,33 @@ STRLEN
LD BC,HL LD BC,HL
LD A, B LD A, B
OR C OR C
JR Z, STRL_NCOR JR Z, .STRL_NCOR
DEC BC DEC BC
STRL_NCOR .STRL_NCOR
POP HL,DE POP HL,DE
RET RET
ENDIF ENDIF
; ------------------------------------------------------ ; ------------------------------------------------------
; Compare zero-ended strings ; Compare strings
; Inp: HL, DE - pointers to strings to compare ; Inp: HL, DE - pointers to asciiz strings to compare
; Out: CF=0 - equal, CF=1 - not equal ; Out: CF=0 - equal, CF=1 - not equal
; ------------------------------------------------------ ; ------------------------------------------------------
IFUSED STRCMP IFUSED STRCMP
STRCMP STRCMP
PUSH DE,HL PUSH DE,HL
STC_NEXT .STC_NEXT
LD A, (DE) LD A, (DE)
CP (HL) CP (HL)
JR NZ, STC_NE JR NZ,.STC_NE
AND A AND A
JR Z, STC_EQ JR Z,.STC_EQ
INC DE INC DE
INC HL INC HL
JR STC_NEXT JR .STC_NEXT
STC_NE .STC_NE
SCF SCF
STC_EQ .STC_EQ
POP HL,DE POP HL,DE
RET RET
ENDIF ENDIF
@ -161,6 +161,21 @@ STARTSWITH
ENDIF ENDIF
; ------------------------------------------------------
; Skip spaces at start of zero ended string
; Inp: HL - pointer to string
; Out: HL - points to first non space symbol
; ------------------------------------------------------
IFUSED LTRIM
LTRIM
LD A, (HL)
OR A
RET Z
CP 0x21
RET P
INC HL
JR LTRIM
ENDIF
; ------------------------------------------------------ ; ------------------------------------------------------
; Convert string to number ; Convert string to number
@ -171,13 +186,13 @@ STARTSWITH
ATOU ATOU
PUSH BC PUSH BC
LD HL,0x0000 LD HL,0x0000
ATOU_L1 .ATOU_L1
LD A,(DE) LD A,(DE)
AND A AND A
JR Z, ATOU_LE JR Z, .ATOU_LE
SUB 0x30 SUB 0x30
CP 10 CP 10
JR NC, ATOU_LE JR NC, .ATOU_LE
INC DE INC DE
LD B,H LD B,H
LD C,L LD C,L
@ -187,14 +202,149 @@ ATOU_L1
ADD HL,HL ADD HL,HL
ADD A,L ADD A,L
LD L,A LD L,A
JR NC,ATOU_L1 JR NC,.ATOU_L1
INC H INC H
JP ATOU_L1 JP .ATOU_L1
ATOU_LE .ATOU_LE
POP BC POP BC
RET RET
ENDIF ENDIF
; ------------------------------------------------------
; Convert 16 bit unsigned number to string
; Inp: HL - number
; DE - ptr to buffer
; Out: DE -> asciiz string representing a number
; ------------------------------------------------------
IFUSED UTOA
UTOA:
PUSH BC, HL
XOR A
PUSH AF ; END MARKER A=0, Z
.UTOA_L1
CALL DIV_10
ADD '0'
PUSH AF ; DIGIT: A>0, NZ
LD A,H
OR L
JR NZ,.UTOA_L1
.UTOA_L2
POP AF
LD (DE),A
INC DE
JR NZ,.UTOA_L2
POP HL, BC
RET
; ------------------------------------------------------
; Division by 10
; Inp: HL - number
; Out: HL - quotient
; A - remainder
; ------------------------------------------------------
DIV_10:
PUSH BC
LD BC,0x0D0A
XOR A
ADD HL,HL
RLA
ADD HL,HL
RLA
ADD HL,HL
RLA
.DDL1
ADD HL,HL
RLA
CP C
JR C,.DDL2
SUB C
INC L
.DDL2
DJNZ .DDL1
POP BC
RET
ENDIF
; ------------------------------------------------------
; FAST_UTOA
; Inp: HL - number
; DE - Buffer
; CF is set to write leading zeroes
; Out: DE - address of strinf
; ------------------------------------------------------
IFUSED FAST_UTOA
FAST_UTOA
LD BC,0+256
PUSH BC
LD BC,-10+256
PUSH BC
INC H
DEC H
JR Z, .EIGHT_BIT
LD C,0XFF & (-100+256)
PUSH BC
LD BC,-1000+256
PUSH BC
LD BC,-10000
JR C,.LEADING_ZEROES
.NO_LEADING_ZEROES
CALL .DIVIDE
CP '0'
JR NZ,.WRITE
POP BC
DJNZ .NO_LEADING_ZEROES
JR .WRITE1S
.LEADING_ZEROES
CALL .DIVIDE
.WRITE
LD (DE),A
INC DE
POP BC
DJNZ .LEADING_ZEROES
.WRITE1S
LD A,L
ADD A,'0'
LD (DE),A
INC DE
RET
.DIVIDE
LD A,'0'-1
.DIVLOOP
INC A
ADD HL,BC
JR C, .DIVLOOP
SBC HL,BC
RET
.EIGHT_BIT
LD BC,-100
JR NC, .NO_LEADING_ZEROES
; write two leading zeroes to output string
LD A,'0'
LD (DE),A
INC DE
LD (DE),A
INC DE
JR .LEADING_ZEROES
ENDIF
; ------------------------------------------------------ ; ------------------------------------------------------
; Find char in string ; Find char in string
; Inp: HL - ptr to zero endeds string ; Inp: HL - ptr to zero endeds string
@ -205,18 +355,18 @@ ATOU_LE
IFUSED STRCHR IFUSED STRCHR
STRCHR STRCHR
PUSH BC PUSH BC
STCH_NEXT .STCH_NEXT
LD C,A LD C,A
LD A,(HL) LD A,(HL)
AND A AND A
JR Z, STCH_N_FOUND JR Z, .STCH_N_FOUND
CP C CP C
JR Z, STCH_FOUND JR Z, .STCH_FOUND
INC HL INC HL
JR STCH_NEXT JR STCH_NEXT
STCH_N_FOUND .STCH_N_FOUND
SCF SCF
STCH_FOUND .STCH_FOUND
POP BC POP BC
RET RET
ENDIF ENDIF
@ -233,9 +383,10 @@ HEXB
RRA RRA
RRA RRA
RRA RRA
CALL CONV_NIBLE CALL .CONV_NIBLE
LD A,C LD A,C
CONV_NIBLE
.CONV_NIBLE
AND 0x0f AND 0x0f
ADD A,0x90 ADD A,0x90
DAA DAA
@ -296,8 +447,6 @@ ADD_BACK_SLASH
LD (HL),0x0 LD (HL),0x0
RET RET
ENDMODULE ENDMODULE
ENDIF ENDIF

81
sources/DSS/utoa.asm Normal file
View File

@ -0,0 +1,81 @@
; ------------------------------------------------------
; FAST_UTOA
; Inp: HL - number
; A - Radix 2,8,10,16
; DE - Buffer
; CF is set to write leading zeroes
; Out: DE - address of strinf
; ------------------------------------------------------
FAST_UTOA
LD BC,0+256
PUSH BC
LD BC,-10+256
PUSH BC
INC H
DEC H
JR Z, .EIGHT_BIT
LD C,0XFF & (-100+256)
PUSH BC
LD BC,-1000+256
PUSH BC
LD BC,-10000
JR C,.LEADING_ZEROES
.NO_LEADING_ZEROES
CALL .DIVIDE
CP '0'
JR NZ,.WRITE
POP BC
DJNZ .NO_LEADING_ZEROES
JR .WRITE1S
.LEADING_ZEROES
CALL .DIVIDE
.WRITE
LD (DE),A
INC DE
POP BC
DJNZ .LEADING_ZEROES
.WRITE1S
LD A,L
ADD A,'0'
LD (DE),A
INC DE
RET
.DIVIDE
LD A,'0'-1
.DIVLOOP
INC A
ADD HL,BC
JR C, .DIVLOOP
SBC HL,BC
RET
.EIGHT_BIT
LD BC,-100
JR NC, .NO_LEADING_ZEROES
; write two leading zeroes to output string
LD A,'0'
LD (DE),A
INC DE
LD (DE),A
INC DE
JR .LEADING_ZEROES

View File

@ -8,14 +8,13 @@
; Set to 1 to turn debug ON with DeZog VSCode plugin ; Set to 1 to turn debug ON with DeZog VSCode plugin
; Set to 0 to compile .EXE ; Set to 0 to compile .EXE
DEFINE DEBUG ; DEFINE DEBUG
; Set to 1 to output TRACE messages ; Set to 1 to output TRACE messages
DEFINE TRACE DEFINE TRACE
WM_DOWNLOAD EQU 0 WM_DOWNLOAD EQU 0
WM_UPLOAD EQU 1 WM_UPLOAD EQU 1
@ -67,17 +66,29 @@ START
LD SP, STACK_TOP LD SP, STACK_TOP
ENDIF ENDIF
CALL PARSE_CMD_LINE PRINTLN MSG_START
CALL OPEN_LOCAL_FILE CALL PARSE_CMD_LINE
CALL DISPLAY_MODE CALL DISPLAY_MODE
CALL OPEN_LOCAL_FILE
IF_UPLOAD_GO DO_UPLOAD
CALL @TFTP.BUILD_RRQ_PACKET
JP DONE
DO_UPLOAD
CALL @TFTP.BUILD_WRQ_PACKET
DONE
CALL CLOSE_LOCAL_FILE CALL CLOSE_LOCAL_FILE
IFDEF DEBUG ;IFDEF DEBUG
JP MAIN_LOOP LD B,0
ENDIF DSS_EXEC DSS_EXIT
;ENDIF
CALL ISA.ISA_RESET CALL ISA.ISA_RESET
@ -114,15 +125,16 @@ OK_EXIT
; ------------------------------------------------------ ; ------------------------------------------------------
PARSE_CMD_LINE PARSE_CMD_LINE
PUSH IX PUSH IX
POP HL POP HL ; HL -> CMD Line
LD A,(HL) LD A,(HL) ; CMD Line length
OR A OR A
JR Z, OUT_USAGE_MSG JR Z, OUT_USAGE_MSG
CALL SKIP_SPACES INC HL ; skip length byte
CALL @UTIL.LTRIM ; skip leading non-printable characters
; check first parameter for tftp url pattern ; check first parameter for tftp url pattern
LD DE,TFTF_START LD DE,TFTF_START ; check parameter to start from 'tftp://'
CALL @UTIL.STARTSWITH CALL @UTIL.STARTSWITH
JR NZ,.PLC_UPLOAD JR NZ,.PLC_UPLOAD
@ -130,7 +142,7 @@ PARSE_CMD_LINE
; handle parameter URL ; handle parameter URL
CALL GET_SRV_PARAMS CALL GET_SRV_PARAMS
CALL SKIP_SPACES CALL @UTIL.LTRIM ; skip spaces between parameters
; handle lfn ; handle lfn
CALL GET_LFN CALL GET_LFN
@ -143,7 +155,7 @@ PARSE_CMD_LINE
LD (WORK_MODE),A LD (WORK_MODE),A
CALL GET_LFN CALL GET_LFN
CALL SKIP_SPACES CALL @UTIL.LTRIM
LD DE,TFTF_START LD DE,TFTF_START
CALL @UTIL.STARTSWITH CALL @UTIL.STARTSWITH
@ -308,6 +320,7 @@ COPY_LFN
INC (IX+0) INC (IX+0)
LD DE,REM_FILE LD DE,REM_FILE
LD B,12 ; limit filename length nnnnnnnn.exe
.CLFN_NXT .CLFN_NXT
LD A,(DE) LD A,(DE)
LD (HL),A LD (HL),A
@ -315,10 +328,7 @@ COPY_LFN
RET Z RET Z
INC HL INC HL
INC DE INC DE
JR .CLFN_NXT DJNZ .CLFN_NXT
; ------------------------------------------------------ ; ------------------------------------------------------
; Open local file for upload or download ; Open local file for upload or download
@ -331,8 +341,8 @@ OPEN_LOCAL_FILE
OR A OR A
JR NZ,.OLF_SKP_CP JR NZ,.OLF_SKP_CP
LD HL, WIFI.RS_BUFF LD HL, @TMP_BUFF
PUSH HL ;PUSH HL
CALL UTIL.GET_CUR_DIR CALL UTIL.GET_CUR_DIR
LD DE,LOC_FILE LD DE,LOC_FILE
LD B,128 LD B,128
@ -345,25 +355,41 @@ OPEN_LOCAL_FILE
INC DE INC DE
DJNZ .OLF_NXT DJNZ .OLF_NXT
.OLF_EFN .OLF_EFN
POP HL LD HL, @TMP_BUFF
;POP HL
; HL - points to file path name ; HL - points to file path name
.OLF_SKP_CP .OLF_SKP_CP
LD A, (WORK_MODE) IF_UPLOAD_GO .OLF_UPL
CP WM_UPLOAD
JR Z,.OLF_UPL
; create new file for write ; create new file for write
PUSH HL, HL
PRINT MSG_LFN_CR
POP HL
CALL PRINT_FILENAME
POP HL
XOR A XOR A
PUSH HL
LD C,DSS_CREATE_FILE LD C,DSS_CREATE_FILE
RST DSS RST DSS
POP HL
JR NC,.OLF_END JR NC,.OLF_END
CP 0x07 ; file exists? CP 0x07 ; file exists?
JP NZ,DSS_ERROR.PRINT ; print error and exit JP NZ,DSS_ERROR.PRINT ; print error and exit
PUSH HL
PRINTLN MSG_OF_EXISTS
POP HL
LD A,FM_WRITE LD A,FM_WRITE
JR .OLF_FOW JR .OLF_FOW
; open existing file for read ; open existing file for read
.OLF_UPL .OLF_UPL
PUSH HL, HL
PRINT MSG_LFN_OP
POP HL
CALL PRINT_FILENAME
POP HL
LD A,FM_READ LD A,FM_READ
.OLF_FOW .OLF_FOW
LD C,DSS_OPEN_FILE LD C,DSS_OPEN_FILE
@ -376,11 +402,28 @@ OPEN_LOCAL_FILE
RET RET
PRINT_FILENAME
DSS_EXEC DSS_PCHARS
PRINTLN WCOMMON.LINE_END
RET
MSG_OF_EXISTS
DB "Output file already exists!"Z
IFDEF TRACE IFDEF TRACE
MSG_LFN_CR
DB "Create file: "Z
MSG_LFN_OP
DB "Open file: "Z
MSG_LFN_OPEN MSG_LFN_OPEN
DB "Local file succes open/created."Z DB "File successfully accessed."Z
ENDIF ENDIF
; ------------------------------------------------------
; Closes loacal file if it open
; ------------------------------------------------------
CLOSE_LOCAL_FILE CLOSE_LOCAL_FILE
LD A,(LOC_FH) LD A,(LOC_FH)
OR A OR A
@ -389,28 +432,13 @@ CLOSE_LOCAL_FILE
CALL DSS_ERROR.CHECK CALL DSS_ERROR.CHECK
RET RET
; ------------------------------------------------------
; Skip spaces at start of zero ended string
; Inp: HL - pointer to string
; Out: HL - points to first non space symbol
; ------------------------------------------------------
SKIP_SPACES
LD A, (HL)
OR A
RET Z
CP 0x21
RET P
INC HL
JR SKIP_SPACES
; ------------------------------------------------------ ; ------------------------------------------------------
; Display current working mode ; Display current working mode
; ------------------------------------------------------ ; ------------------------------------------------------
DISPLAY_MODE DISPLAY_MODE
LD A,(WORK_MODE) IF_UPLOAD_GO .DM_UPLOAD
CP A,WM_UPLOAD
JR .DM_UPLOAD
; Download ; Download
PRINT MSG_MODE_D PRINT MSG_MODE_D
PRINT REM_FILE PRINT REM_FILE
@ -429,20 +457,6 @@ DISPLAY_MODE
PRINTLN REM_FILE PRINTLN REM_FILE
RET RET
MSG_MODE_D
DB "Download file "Z
MSG_MODE_D_S
DB " from server "Z
MSG_MODE_D_T
DB " to file "Z
MSG_MODE_U
DB "Upload file "Z
MSG_MODE_U_S
DB " to server "Z
MSG_MODE_U_T
DB " to file "Z
; ------------------------------------------------------ ; ------------------------------------------------------
; Custom messages ; Custom messages
; ------------------------------------------------------ ; ------------------------------------------------------
@ -454,8 +468,8 @@ MSG_ERR_CMD
DB "Invalid command line parameters!\r\n"Z DB "Invalid command line parameters!\r\n"Z
MSG_HLP MSG_HLP
DB "\r\nUse: wtftp.exe tftp://server[:port]/filename filename - to download file from server;\r\n" DB "\r\nUse:\r\n wtftp.exe tftp://server[:port]/filename filename - to download from server;\r\n"
DB " wtftp.exe filename tftp://server[:port]/filename - to upload file to server.\r\n"Z DB " wtftp.exe filename tftp://server[:port]/filename - to upload to server.\r\n"Z
MSG_TX_ERROR MSG_TX_ERROR
DB "Transmitter not ready"Z DB "Transmitter not ready"Z
@ -477,6 +491,24 @@ MSG_ERR_RFN
MSG_ERR_LFN MSG_ERR_LFN
DB "Invalid local file name!"Z DB "Invalid local file name!"Z
MSG_MODE_D
DB "Download file "Z
MSG_MODE_D_S
DB " from server "Z
MSG_MODE_D_T
DB " to file "Z
MSG_MODE_U
DB "Upload file "Z
MSG_MODE_U_S
DB " to server "Z
MSG_MODE_U_T
DB " to file "Z
; ------------------------------------------------------
; Variables
; ------------------------------------------------------
; Start of tftf URL ; Start of tftf URL
TFTF_START TFTF_START
DB "tftp://"Z DB "tftp://"Z
@ -489,12 +521,12 @@ WORK_MODE
; Name/IP of the tftp server ; Name/IP of the tftp server
SRV_NAME SRV_NAME
DS 128,0 DS 128,0
CMDLINE
; UDP port of the tftp server ; UDP port of the tftp server
SRV_PORT SRV_PORT
DB 69,0,0,0,0,0 ; udp port number 0..65535 DB 69,0,0,0,0,0 ; udp port number 0..65535
; Name of the source file ; Name of the remote file
REM_FILE REM_FILE
DS 128,0 DS 128,0
@ -506,28 +538,23 @@ LOC_FILE
LOC_FH LOC_FH
DW 0 DW 0
; Not null if local file name contains path ; Non zero, if local file name contains path
HAVE_PATH HAVE_PATH
DB 0 DB 0
; ------------------------------------------------------
; Custom commands
; ------------------------------------------------------
RX_ERR
DB 0
; IFDEF DEBUG
; CMD_TEST1 DB "ATE0\r\n"Z
; BUFF_TEST1 DS RS_BUFF_SIZE,0
; ENDIF
ENDMODULE ENDMODULE
; ------------------------------------------------------
; Includes
; ------------------------------------------------------
INCLUDE "wcommon.asm" INCLUDE "wcommon.asm"
INCLUDE "dss_error.asm" INCLUDE "dss_error.asm"
;INCLUDE "util.asm" ;INCLUDE "util.asm"
INCLUDE "isa.asm" INCLUDE "isa.asm"
INCLUDE "tftp.asm"
INCLUDE "esplib.asm" INCLUDE "esplib.asm"
TMP_BUFF
END MAIN.START END MAIN.START