OpenCores
URL https://opencores.org/ocsvn/System09/System09/trunk

Subversion Repositories System09

[/] [System09/] [trunk/] [src/] [xrecv/] [XSEND.ASM] - Blame information for rev 223

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 153 davidgb
*
2
** Xmodem Send Utility for Flex9 (xsend.asm)
3
*
4
* WITH ACIA MAPPED AT $E000
5
*
6
* 2020-05-24 JEK Work in progress.
7
*
8
*
9
** FLEX9 FMS CALLS
10
*
11
SYSFCB EQU $C840
12
FMSCLS EQU $D403
13
FMS    EQU $D406
14
*
15
*   FLEX SYSTEM DEFINED ENTRY VECTORS
16
*
17
COLDS      EQU     $CD00               FLEX COLD START ADDRESS
18
WARMS      EQU     $CD03               FLEX WARM START ADDRESS
19
RENTER     EQU     $CD06               RE-ENTER FLEX PROCESSING
20
INCH       EQU     $CD09               INPUT CHARACTER (LOW LEVEL) (MAY BE REDIRECTED)
21
INCH2      EQU     $CD0C               SECONDARY INPUT CHARACTER (NOT REDIRECTED)
22
OUTCH      EQU     $CD0F               OUTPUT CHARACTER (LOW LEVEL) (MAY BE REDIRECTED)
23
OUTCH2     EQU     $CD12               SECONDARY CHAR OUTPUT (NOT REDIRECTED)
24
GETCHR     EQU     $CD15               INPUT CHARACTER ROUTINE (HONOURS TTYSET)
25
PUTCHR     EQU     $CD18               OUTPUT CHARACTER ROUTINE (HONOURS TTYSET)
26
INBUFF     EQU     $CD1B               INPUT LINE BUFFER
27
PSTRNG     EQU     $CD1E               PRINT STRING
28
CLASS      EQU     $CD21               CLASSIFY CHARACTER
29
PCRLF      EQU     $CD24               PRINT CR/LF SEQUENCE
30
NXTCH      EQU     $CD27               GET NEXT CHARACTER FROM INPUT BUFFER
31
RESTIO     EQU     $CD2A               RESTORE I/O VECTORS ON INCH & OUCH
32
GETFIL     EQU     $CD2D               GET FILE SPECIFICATION (X=FCB) (C=1 IF FORMAT ERROR)
33
LOAD       EQU     $CD30               LOAD FILE ENTRY POINT
34
SETEXT     EQU     $CD33               SET UP FILE EXTENSION
35
ADDBX      EQU     $CD36               ADD ACCB TO X INDEX REGISTER
36
OUTDEC     EQU     $CD39               OUTPUT DECIMAL NUMBER
37
OUTHEX     EQU     $CD3C               OUTPUT HEXADECIMAL BYTE POINTED TO BY X
38
RPTERR     EQU     $CD3F               I/O ERROR ABORT ROUTINE
39
GETHEX     EQU     $CD42               GET HEXIDECIMAL SPECIFICATION
40
OUTADR     EQU     $CD45               OUTPUT HEXADECIMAL ADDRESS POINTED TO BY X
41
INDEC      EQU     $CD48               GET DECIMAL NUMBER
42
DOCMD      EQU     $CD4B               DOCMD ENTRY ADDRESS (CALL FLEX AS SUBROUTINE)
43
STATUS     EQU     $CD4E               CHECK TERMINAL INPUT STATUS (Z=1 => NO CHARACTER)
44
*
45
*   FMS FUNCTION CODES
46
*
47
FMSFRW     EQU     0                   READ OR WRITE TO FILE (Z=0 => ERROR)
48
FMSFOR     EQU     1                   OPEN FILE FOR READ    (Z=0 => ERROR)
49
FMSFOW     EQU     2                   OPEN FILE FOR WRITE   (Z=0 => ERROR)
50
FMSFOU     EQU     3                   OPEN FILE FOR UPDATE  (1=SEQ RD, 2=RAND RD, 3=RAND WR, 4=CLOSE)
51
FMSFCL     EQU     4                   CLOSE FILE
52
FMSFRS     EQU     5                   REWIND FILE
53
FMSDOP     EQU     6                   OPEN DIRTECTORY
54
FMSGIR     EQU     7                   GET INFORMATION RECORD (READ DIRECTORY)
55
FMSPIR     EQU     8                   PUT INFORMATION RECORD (WRITE DIRECTORY)
56
FMSRSS     EQU     9                   READ SINGLE SECTOR (SET CURRENT TRACK & SECTOR IN FCB)
57
FMSWSS     EQU     10                  WRITE SINGLE SECTOR
58
FMSFDL     EQU     11                  DELETE FILE
59
FMSRRN     EQU     12                  RENAME FILE
60
FMSNSS     EQU     15                  READ OR WRITE NEXT SEQUENTIAL SECTOR
61
FMSOSR     EQU     16                  OPEN SYSTEM INFORMATION RECORD
62
FMSRRB     EQU     17                  READ RANDOM BYTE FROM SECTOR (SET RANDOM INDEX BYTE IN FCB)
63
FMSWRB     EQU     18                  WRITE RANDOM BYTE IN SECTOR  (ADD 4 TO SKIP SECTOR LINK)
64
FMSFND     EQU     20                  FIND NEXT DRIVE IN READY STATE
65
FMSPRN     EQU     21                  POSITION TO RECORD N (STORE ADDRESS IN CURRENT RECORD NUMBER)
66
FMSBOR     EQU     22                  BACK UP ONE RECORD
67
*
68
*   FMS ERROR CODES
69
*
70
ERRIFC     EQU     1                   ILLEGAL FMS FUNCTION CODE
71
ERRINU     EQU     2                   REQUESTED FILE IN USE
72
ERRFAE     EQU     3                   FILE ALREADY EXISTS (OPEN FOR WRITE EXISTING FILE)
73
ERRFNF     EQU     4                   FILE NOT FOUND (OPEN FOR READ)
74
ERRSDE     EQU     5                   SYSTEM DIRECTORY ERROR - REBOOT SYSTEM
75
ERRSDF     EQU     6                   SYSTEM DIRECTORY FULL
76
ERRDSF     EQU     7                   ALL AVAILBABLE DISK SPACE HAS BEEN USED
77
ERREOF     EQU     8                   READ PAST END OF FILE
78
ERRRDE     EQU     9                   FILE READ ERROR
79
ERRWRE     EQU     10                  FILE WRITE ERROR
80
ERRWRP     EQU     11                  FILE IS WRITE PROTRECTED
81
ERRFND     EQU     12                  FILE IS PROTECTED - FILE NOT DELETED
82
ERRFCB     EQU     13                  ILLEGAL FILE CONTROL BLOCK
83
ERRIDA     EQU     14                  ILLEGAL DISK ADDRESS
84
ERRIDN     EQU     15                  ILLEGAL DRIVE NUMBER
85
ERRBSY     EQU     16                  DRIVE NOT READY
86
ERRFPR     EQU     17                  FILE IS PROTECTED - ACCESS DENIED
87
ERRSFS     EQU     18                  SYSTEM FILE STATUS ERROR
88
ERRDIR     EQU     19                  FMS DATA INDEX RANGE ERROR
89
ERRFMS     EQU     20                  FMS INACTIVE - REBOOT SYSTEM
90
ERRIFS     EQU     21                  ILLEGAL FILE SPECIFICATION
91
ERRSFC     EQU     22                  SYSTEM FILE CLOSE ERROR
92
ERRSMO     EQU     23                  SECTOR MAP OVERFLOW
93
ERRNSR     EQU     24                  NON EXISTAND RECORD NUMBER (NO SUCH RECORD)
94
ERRRNM     EQU     25                  RECORD NUMBER MATCH ERROR (FILE DAMAGED)
95
ERRSYN     EQU     26                  COMMAND SYNTAX ERROR
96
ERRPRN     EQU     27                  COMMAND NOT ALLOWED WHILE PRINTING
97
ERRHWC     EQU     28                  WRONG HARDWARE CONFIGURATION
98
*
99
* Condition Code Flags
100
*
101
CFLAG   EQU $01     CARRY FLAG
102
VFLAG   EQU $02     OVERFLOW FLAG
103
ZFLAG   EQU $04     ZERO FLAG
104
NFLAG   EQU $08     NEGATIVE FLAG
105
IFLAG   EQU $10     IRQ MASK CC
106
HFLAG   EQU $20     HALF CARRY
107
FFLAG   EQU $40     FIRQ MASK CC
108
EFLAG   EQU $80     ENTIRE FLAG
109
*
110
* Serial Port
111
*
112
ACIAS   EQU $E000
113
ACIAC1  EQU ACIAS
114
ACIAD1  EQU ACIAS+1
115
DELCON  EQU 1250    Delay (Processor clock in MHz * 50)
116
*
117
* XMODEM Control characters
118
*
119
SOH     EQU $01     sent for 128 byte block
120
STX     EQU $02     sent for 1024 byte block
121
EOT     EQU $04
122
ACK     EQU $06
123
NAK     EQU $15
124
CAN     EQU $18
125
*
126
* ASCII CONTROL CHARACTERS
127
*
128
HT      EQU $09
129
LF      EQU $0A
130
CR      EQU $0D
131
RETRY   EQU 16
132
*
133
* Start
134
*
135
        ORG $0100
136
START   LBRA  LOAD1
137
*
138
*
139
* RAM SPACE
140
*
141
CHKSUM  FCB  0
142
BLKNUM  FCB  0 Xmodem block number
143
BYTCNT  FCB  0 Xmodem byte count
144
SNDCNT  FCB  0 Send byte count
145
PADCNT  FCB  0 Send byte count
146
DELCNT  FCB  $00,$00,$00 Xmodem Poll timer
147
BUFPTR  FDB  0 Pointer to send buffer
148
TXTFLG  FCB  0 Text file flag
149
SPTEMP  FDB  0 Stack pointer store
150
RETRYC  FCB  0 Retry count
151
LSTCHR  FCB  0 Double CANcel
152
*
153
* SEND BUFFER
154
*
155
BUFSIZ  EQU  128
156
BUFFER  RMB  BUFSIZ
157
*
158
* Program Stack
159
*
160
        RMB  256
161
STACK   EQU  *
162
*
163
** MAIN ENTRY POINT
164
*
165
* Get file specification
166
*
167
LOAD1   STS  SPTEMP
168
        LDS  #STACK
169
        LDX  #SYSFCB
170
        JSR  GETFIL
171
        BCS  FMSERR
172
*
173
* look for 'T' for text file
174
*
175
LOAD2   JSR  NXTCH
176
        ANDA #$5F
177
        CMPA #'T       Is it a Text File ?
178
        BNE  OPENRD   No, open as binary file
179
        STA  TXTFLG
180
        LDX  #TXTMSG
181
        JSR  PSTRNG
182
        LDX  #SYSFCB
183
        LDA  #$01      If text file default to ".TXT"
184
        JSR  SETEXT
185
*
186
** OPEN FILE FOR READ
187
*
188
OPENRD  LDX  #SYSFCB
189
        LDA  #FMSFOR   open file for read
190
        STA  0,X
191
        JSR  FMS
192
        BNE  DSKERR
193
        TST  TXTFLG    Is it a text file ?
194
        BNE  TXTFILE   Yes, space compression
195
        LDX  #SYSFCB   No, binary, no space compression
196
        LDA  #$FF
197
        STA  $3B,X
198
*
199
* Start from Block 1
200
*
201
TXTFILE LDA  #1      Initialize block number
202
        STA  BLKNUM
203
        LDA  #RETRY  Initialize retry count
204
        STA  RETRYC
205
        LBRA RDSTRT  go start transfer
206
*
207
** FINISHED LOAD
208
*
209
* Send EOT until receiver sends an ACK
210
*
211
ABORT  LDA  #EOT     Send EOT
212
       LBSR OUTTER
213
       LBSR INTER    Wait for ACK
214
       BVS  ABORT1   If timeout, terminate
215
       CMPA #ACK     ACK Received ?
216
       BNE  ABORT    No, send another EOT
217
ABORT1 LDX  #ENDMSG  Yes, report file loaded
218
       JSR  PSTRNG
219
*
220
** CLOSE FILE
221
*
222
CLOSE  LDA  #FMSFCL     Close file
223
       LDX  #SYSFCB
224
       STA  0,X
225
       JSR  FMS
226
       BEQ  EXIT
227
*
228
** ERROR IN CLOSING
229
*
230
DSKERR LDA  $01,X
231
FMSERR JSR  RPTERR
232
       JSR  FMSCLS
233
EXIT   LDS  SPTEMP
234
       JMP  WARMS
235
*
236
* READ FILE INTO BUFFER
237
* READ UP TO 128 BYTES
238
*
239
RDSTRT  DEC  RETRYC   decrement the retry count
240
        BEQ  ABORT    terminate transmission if retry count expires
241
        CLR  BYTCNT   Clear byte count
242
        LDX  #BUFFER  Reset buffer pointer to start of buffer
243
        STX  BUFPTR
244
*
245
RDLOOP  LDX  #SYSFCB  Read byte from file
246
        JSR  FMS
247
        BNE  RDERR    Check for end of file
248
*
249
*        TST  TXTFLG   Text file ?
250
*        BEQ  RDLP1    No, output binary
251
*        CMPA #CR      Yes, substitute LF for CR (Linux)
252
*        BNE  RDLP1
253
*        LDA  #LF
254
*
255
RDLP1   LDX  BUFPTR   store character in buffer
256
        STA  ,X+
257
        STX  BUFPTR
258
*
259
        INC  BYTCNT   Increment send buffer byte count
260
        LDA  BYTCNT
261
        CMPA #BUFSIZ  Is send buffer full ?
262
        BEQ  SNDSOH   Yes, send a 128 byte record
263
        BRA  RDLOOP   No, read next byte until EOF
264
*
265
* CHECK FOR END OF FILE
266
* IF SO SEND BUFFER AND PAD WITH NULLS
267
*
268
RDERR   LDA  $01,X
269
        CMPA #ERREOF test for End Of File Error
270
        LBNE ABORT   If not, report disk error and close
271
*
272
* Send bytes in the send buffer
273
*
274
SNDSOH  LDX  #BUFFER Reset buffer pointer to start of buffer
275
        STX  BUFPTR
276
        LDA  #BUFSIZ Work out how many bytes to pad out
277
        SUBA BYTCNT
278
        STA  PADCNT
279
        LDA  BYTCNT
280
        STA  SNDCNT
281
        LBEQ ABORT   Terminate Transfer if no bytes to send
282
*
283
* SEND SOH (START OF HEADER) = $01
284
*
285
        LDA  #SOH    Send start of header
286
        LBSR OUTTER
287
*
288
* SEND BLOCK NUMBER
289
*
290
        LDA  BLKNUM  Send Block number
291
        LBSR OUTTER
292
*
293
* SEND COMPLEMENT OF BLOCK NUMBER
294
*
295
        LDA  BLKNUM  Send complement of block number
296
        COMA
297
        LBSR OUTTER
298
*
299
        CLR  CHKSUM  Clear Checksum
300
*
301
* Send Data Block
302
*
303
SNDDAT  LDX  BUFPTR  Send data byte in buffer
304
        LDA  ,X+
305
        STX  BUFPTR
306
        JSR  OUTTER
307
*
308
        ADDA CHKSUM  Calculate checksum
309
        STA  CHKSUM
310
*
311
        DEC  SNDCNT  Decrement sent byte counter
312
        BNE  SNDDAT  Loop until done
313
*
314
* Send Pad Bytes
315
*
316
        TST  PADCNT  Test if any pad characters
317
        BEQ  SNDCHK  No, send checksum
318
SNDPAD  LDA  #$00    Yes, output nulls
319
        JSR  OUTTER
320
        DEC  PADCNT  Decrement Pad Byte Count
321
        BNE  SNDPAD  Loop until pad byte count == 0
322
*
323
* Send Checksum
324
*
325
SNDCHK  LDA  CHKSUM   Send checksum
326
        LBSR OUTTER
327
*
328
* wait for acknowledgement
329
*
330
SNDWAI  LBSR INTER   Wait for ack, Negative ack, Cancel or timeout
331
        BVS  SNDUPD  If timeout, send block again
332
        CMPA #NAK    If negative acknowledge
333
        BEQ  SNDUPD  send block again
334
        CMPA #CAN    If Cancel
335
        BEQ  SNDCAN  Terminate transmission and close file
336
        CMPA #ACK    If Acknowledgement
337
        BEQ  SNDNXT  advance block count
338
        STA  LSTCHR  Update Last Character
339
        BRA  SNDWAI  Loop.
340
*
341
* Acknowledge received
342
* increment block number,
343
* reset the retry count
344
* and loop for next block
345
*
346
SNDNXT  STA  LSTCHR  Non CAN character
347
        INC  BLKNUM
348
        LDA  #RETRY  reset the retry count
349
        STA  RETRYC
350
        LBRA RDSTRT
351
*
352
* Look for two cancells to terminate
353
*
354
SNDCAN  CMPA LSTCHR
355
        LBEQ ABORT
356
        STA  LSTCHR
357
        BRA  SNDWAI
358
*
359
* Store characetr in LSTCHR
360
* And send SOH again
361
*
362
SNDUPD  STA  LSTCHR
363
        LBRA SNDSOH
364
*
365
* ACIA INPUT TEST
366
*
367
INTEST  LDA ACIAC1
368
        BITA #$01
369
        RTS
370
*
371
* RESET ACIA
372
*
373
ACIRST  LDA #$03 master reset
374
        STA  ACIAC1
375
        LDA #$11
376
        STA ACIAC1
377
        TST ACIAD1
378
        RTS
379
*
380
* ACIA INPUT
381
* SET V FLAG IF TIME OUTADR
382
*
383
INTER   LDA  #16
384
        STA  DELCNT+0
385
        CLR  DELCNT+1
386
        CLR  DELCNT+2
387
INTER0  LDA  ACIAC1
388
        BITA #$01
389
        BNE  INTER1
390
        BITA #$78
391
        BEQ  INTER2
392
        BSR  ACIRST
393
        BRA  INTER
394
*
395
INTER1  LDA  ACIAD1
396
        ANDCC #$FF-VFLAG
397
        RTS
398
*
399
INTER2  DEC  DELCNT+2
400
        BNE  INTER0
401
        DEC  DELCNT+1
402
        BNE  INTER0
403
        DEC  DELCNT+0
404
        BNE  INTER0
405
        CLRA
406
        ORCC #VFLAG
407
        RTS
408
*
409
* ACIA OUTPUT
410
*
411
OUTTER  PSHS A
412
*
413
OUTTE1  LDA ACIAC1
414
        BITA #$02
415
        BNE  OUTTE2
416
        BITA #$78
417
        BEQ  OUTTE1
418
        BSR  ACIRST
419
        BRA  OUTTE1
420
*
421
OUTTE2  PULS A
422
        STA ACIAD1
423
        RTS
424
*
425
** MESSAGES
426
*
427
ENDMSG FCC "FILE LOADED"
428
       FCB $04
429
TXTMSG FCC "TEXT FILE"
430
       FCB $04
431 154 davidgb
       END START

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.