| 1 |
21 |
robfinch |
; ============================================================================
|
| 2 |
|
|
; __
|
| 3 |
|
|
; \\__/ o\ (C) 2022 Robert Finch, Waterloo
|
| 4 |
|
|
; \ __ / All rights reserved.
|
| 5 |
|
|
; \/_// robfinch@opencores.org
|
| 6 |
|
|
; ||
|
| 7 |
|
|
;
|
| 8 |
|
|
;
|
| 9 |
|
|
; BSD 3-Clause License
|
| 10 |
|
|
; Redistribution and use in source and binary forms, with or without
|
| 11 |
|
|
; modification, are permitted provided that the following conditions are met:
|
| 12 |
|
|
;
|
| 13 |
|
|
; 1. Redistributions of source code must retain the above copyright notice, this
|
| 14 |
|
|
; list of conditions and the following disclaimer.
|
| 15 |
|
|
;
|
| 16 |
|
|
; 2. Redistributions in binary form must reproduce the above copyright notice,
|
| 17 |
|
|
; this list of conditions and the following disclaimer in the documentation
|
| 18 |
|
|
; and/or other materials provided with the distribution.
|
| 19 |
|
|
;
|
| 20 |
|
|
; 3. Neither the name of the copyright holder nor the names of its
|
| 21 |
|
|
; contributors may be used to endorse or promote products derived from
|
| 22 |
|
|
; this software without specific prior written permission.
|
| 23 |
|
|
;
|
| 24 |
|
|
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 25 |
|
|
; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 26 |
|
|
; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 27 |
|
|
; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
| 28 |
|
|
; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 29 |
|
|
; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 30 |
|
|
; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 31 |
|
|
; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
| 32 |
|
|
; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 33 |
|
|
; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 34 |
|
|
;
|
| 35 |
|
|
; ============================================================================
|
| 36 |
|
|
;
|
| 37 |
|
|
; S19 variables
|
| 38 |
|
|
;
|
| 39 |
|
|
s19Address EQU $940 ; to $943
|
| 40 |
|
|
s19StartAddress EQU $944 ; to $947
|
| 41 |
|
|
s19Rectype EQU $948
|
| 42 |
|
|
s19Reclen EQU $949
|
| 43 |
|
|
s19Abort EQU $94A
|
| 44 |
|
|
s19Checksum EQU $94B
|
| 45 |
|
|
s19SummaryChecksum EQU $94C
|
| 46 |
|
|
s19Source EQU $94E
|
| 47 |
|
|
s19XferAddress EQU $950 ; to $951
|
| 48 |
|
|
|
| 49 |
|
|
; ------------------------------------------------------------------------------
|
| 50 |
|
|
; Input a character either from a file in memory or from the serial port.
|
| 51 |
|
|
;
|
| 52 |
|
|
; Parameters:
|
| 53 |
|
|
; none
|
| 54 |
|
|
; Returns:
|
| 55 |
|
|
; accb = character input
|
| 56 |
|
|
; ------------------------------------------------------------------------------
|
| 57 |
|
|
|
| 58 |
|
|
s19InputChar:
|
| 59 |
|
|
tst s19Source
|
| 60 |
|
|
beq s19ic1
|
| 61 |
|
|
ldb [s19XferAddress]
|
| 62 |
|
|
inc s19XferAddress+1 ; increment low byte of address pointer
|
| 63 |
|
|
bne s19ic2
|
| 64 |
|
|
inc s19XferAddress ; increment high byte of address pointer
|
| 65 |
|
|
s19ic2:
|
| 66 |
|
|
rts
|
| 67 |
|
|
s19ic1:
|
| 68 |
|
|
ldd #-1 ; block until input is available
|
| 69 |
|
|
swi
|
| 70 |
|
|
fcb MF_INCH ; monitor input rout
|
| 71 |
|
|
rts
|
| 72 |
|
|
|
| 73 |
|
|
; ------------------------------------------------------------------------------
|
| 74 |
|
|
; Skip over input to the next record.
|
| 75 |
|
|
; ------------------------------------------------------------------------------
|
| 76 |
|
|
|
| 77 |
|
|
s19NextRecord:
|
| 78 |
|
|
bsr s19InputChar
|
| 79 |
|
|
cmpb #LF ; line feed marks end of record
|
| 80 |
|
|
beq s19nr1
|
| 81 |
|
|
cmpb #CTRLC ; should not get this in a file transfer
|
| 82 |
|
|
bne s19nr2
|
| 83 |
|
|
stb s19Abort
|
| 84 |
|
|
s19nr2:
|
| 85 |
|
|
cmpb #CTRLZ ; end of file marker?
|
| 86 |
|
|
bne s19nr3
|
| 87 |
|
|
stb s19Abort
|
| 88 |
|
|
s19nr3:
|
| 89 |
|
|
tst s19Abort
|
| 90 |
|
|
beq s19NextRecord
|
| 91 |
|
|
s19nr1:
|
| 92 |
|
|
rts
|
| 93 |
|
|
|
| 94 |
|
|
; ------------------------------------------------------------------------------
|
| 95 |
|
|
; Update the checksum.
|
| 96 |
|
|
; ------------------------------------------------------------------------------
|
| 97 |
|
|
|
| 98 |
|
|
s19AddCheck:
|
| 99 |
|
|
pshs b
|
| 100 |
|
|
addb s19Checksum
|
| 101 |
|
|
stb s19Checksum
|
| 102 |
|
|
puls b,pc
|
| 103 |
|
|
|
| 104 |
|
|
; ------------------------------------------------------------------------------
|
| 105 |
|
|
; Input a byte. There are three characters per byte since things are 12-bit.
|
| 106 |
|
|
;
|
| 107 |
|
|
; Parameters:
|
| 108 |
|
|
; none
|
| 109 |
|
|
; Returns:
|
| 110 |
|
|
; accb = byte value converted from text
|
| 111 |
|
|
; ------------------------------------------------------------------------------
|
| 112 |
|
|
|
| 113 |
|
|
s19GetByte:
|
| 114 |
|
|
bsr s19InputChar ; get the first character
|
| 115 |
|
|
lbsr AsciiToHexNybble ; convert to nybble
|
| 116 |
|
|
tst s19Abort ; check for abort
|
| 117 |
|
|
beq s19gb1
|
| 118 |
|
|
clra
|
| 119 |
|
|
rts
|
| 120 |
|
|
s19gb1: ; shift the value four bits
|
| 121 |
|
|
aslb
|
| 122 |
|
|
aslb
|
| 123 |
|
|
aslb
|
| 124 |
|
|
aslb
|
| 125 |
|
|
pshs b ; save off value
|
| 126 |
|
|
bsr s19InputChar ; get the second character
|
| 127 |
|
|
lbsr AsciiToHexNybble ; convert to nybble
|
| 128 |
|
|
tst s19Abort ; check for abort
|
| 129 |
|
|
bne s19gb2
|
| 130 |
|
|
orb ,s+ ; merge new nybble into value
|
| 131 |
|
|
aslb ; shift the value four more bits
|
| 132 |
|
|
aslb
|
| 133 |
|
|
aslb
|
| 134 |
|
|
aslb
|
| 135 |
|
|
pshs b ; save off value
|
| 136 |
|
|
bsr s19InputChar ; get the third character
|
| 137 |
|
|
lbsr AsciiToHexNybble ; convert to nybble
|
| 138 |
|
|
orb ,s+ ; merge in value
|
| 139 |
|
|
clra ; make byte 000 to FFF in D
|
| 140 |
|
|
rts
|
| 141 |
|
|
s19gb2:
|
| 142 |
|
|
leas 1,s ; discard saved byte
|
| 143 |
|
|
clra
|
| 144 |
|
|
rts
|
| 145 |
|
|
|
| 146 |
|
|
; ------------------------------------------------------------------------------
|
| 147 |
|
|
; Zero out address
|
| 148 |
|
|
; ------------------------------------------------------------------------------
|
| 149 |
|
|
|
| 150 |
|
|
s19ClearAddress:
|
| 151 |
|
|
clr s19Address
|
| 152 |
|
|
clr s19Address+1
|
| 153 |
|
|
clr s19Address+2
|
| 154 |
|
|
clr s19Address+3
|
| 155 |
|
|
rts
|
| 156 |
|
|
|
| 157 |
|
|
; ------------------------------------------------------------------------------
|
| 158 |
|
|
; Get an address composed of two bytes (24 bit)
|
| 159 |
|
|
;
|
| 160 |
|
|
; Side Effects:
|
| 161 |
|
|
; updates s19Address variable
|
| 162 |
|
|
; Returns:
|
| 163 |
|
|
; none
|
| 164 |
|
|
; ------------------------------------------------------------------------------
|
| 165 |
|
|
|
| 166 |
|
|
s19GetAddress2:
|
| 167 |
|
|
bsr s19ClearAddress
|
| 168 |
|
|
bsr s19GetByte
|
| 169 |
|
|
bsr s19AddCheck
|
| 170 |
|
|
stb s19Address+2
|
| 171 |
|
|
tst s19Abort
|
| 172 |
|
|
bne s19ga1
|
| 173 |
|
|
bsr s19GetByte
|
| 174 |
|
|
bsr s19AddCheck
|
| 175 |
|
|
stb s19Address+3
|
| 176 |
|
|
s19ga1:
|
| 177 |
|
|
rts
|
| 178 |
|
|
|
| 179 |
|
|
; ------------------------------------------------------------------------------
|
| 180 |
|
|
; Get an address composed of three bytes (36 bit)
|
| 181 |
|
|
;
|
| 182 |
|
|
; Side Effects:
|
| 183 |
|
|
; updates s19Address variable
|
| 184 |
|
|
; Returns:
|
| 185 |
|
|
; none
|
| 186 |
|
|
; ------------------------------------------------------------------------------
|
| 187 |
|
|
|
| 188 |
|
|
s19GetAddress3:
|
| 189 |
|
|
bsr s19ClearAddress
|
| 190 |
|
|
bsr s19GetByte
|
| 191 |
|
|
bsr s19AddCheck
|
| 192 |
|
|
stb s19Address+1
|
| 193 |
|
|
tst s19Abort
|
| 194 |
|
|
bne s19ga2
|
| 195 |
|
|
bsr s19GetByte
|
| 196 |
|
|
bsr s19AddCheck
|
| 197 |
|
|
stb s19Address+2
|
| 198 |
|
|
tst s19Abort
|
| 199 |
|
|
bne s19ga2
|
| 200 |
|
|
bsr s19GetByte
|
| 201 |
|
|
bsr s19AddCheck
|
| 202 |
|
|
stb s19Address+3
|
| 203 |
|
|
s19ga2:
|
| 204 |
|
|
rts
|
| 205 |
|
|
|
| 206 |
|
|
; ------------------------------------------------------------------------------
|
| 207 |
|
|
; Put a byte to memory.
|
| 208 |
|
|
; ------------------------------------------------------------------------------
|
| 209 |
|
|
|
| 210 |
|
|
s19PutMem:
|
| 211 |
|
|
clrb ; accb = current byte count
|
| 212 |
|
|
s19pm3:
|
| 213 |
|
|
pshs b ; save byte count
|
| 214 |
|
|
bsr s19GetByte
|
| 215 |
|
|
bsr s19AddCheck
|
| 216 |
|
|
tst s19Abort
|
| 217 |
|
|
bne s19pm1
|
| 218 |
|
|
stb far [s19Address+1] ; store the byte using far addressing
|
| 219 |
|
|
inc s19Address+3
|
| 220 |
|
|
bne s19pm2
|
| 221 |
|
|
inc s19Address+2
|
| 222 |
|
|
bne s19pm2
|
| 223 |
|
|
inc s19Address+1
|
| 224 |
|
|
s19pm2:
|
| 225 |
|
|
puls b ; get back byte count
|
| 226 |
|
|
incb ; increment and
|
| 227 |
|
|
cmpb s19Reclen ; compare to record length
|
| 228 |
|
|
blo s19pm3
|
| 229 |
|
|
bsr s19GetByte ; get the checksum byte
|
| 230 |
|
|
bra s19AddCheck
|
| 231 |
|
|
s19pm1:
|
| 232 |
|
|
leas 1,s ; faster than actual pull
|
| 233 |
|
|
bsr s19GetByte ; get the checksum byte
|
| 234 |
|
|
bra s19AddCheck
|
| 235 |
|
|
|
| 236 |
|
|
; ------------------------------------------------------------------------------
|
| 237 |
|
|
; Processing for S1 record type.
|
| 238 |
|
|
; ------------------------------------------------------------------------------
|
| 239 |
|
|
|
| 240 |
|
|
s19ProcessS1:
|
| 241 |
|
|
bsr s19GetAddress2
|
| 242 |
|
|
bsr s19PutMem
|
| 243 |
|
|
tst s19Checksum
|
| 244 |
|
|
beq s19p11
|
| 245 |
|
|
inc s19SummaryChecksum
|
| 246 |
|
|
ldd #msgChecksumErr
|
| 247 |
|
|
swi
|
| 248 |
|
|
fcb MF_DisplayString
|
| 249 |
|
|
s19p11:
|
| 250 |
|
|
bra s19lnr
|
| 251 |
|
|
|
| 252 |
|
|
; ------------------------------------------------------------------------------
|
| 253 |
|
|
; Processing for S2 record type.
|
| 254 |
|
|
; ------------------------------------------------------------------------------
|
| 255 |
|
|
|
| 256 |
|
|
s19ProcessS2:
|
| 257 |
|
|
bsr s19GetAddress3
|
| 258 |
|
|
bsr s19PutMem
|
| 259 |
|
|
tst s19Checksum
|
| 260 |
|
|
beq s19p21
|
| 261 |
|
|
inc s19SummaryChecksum
|
| 262 |
|
|
ldd #msgChecksumErr
|
| 263 |
|
|
swi
|
| 264 |
|
|
fcb MF_DisplayString
|
| 265 |
|
|
s19p21:
|
| 266 |
|
|
bra s19lnr
|
| 267 |
|
|
|
| 268 |
|
|
; S3,4,5,6 not processed
|
| 269 |
|
|
|
| 270 |
|
|
; ------------------------------------------------------------------------------
|
| 271 |
|
|
; Processing for S7 record type. Gets a two byte (24 bit) start address.
|
| 272 |
|
|
; ------------------------------------------------------------------------------
|
| 273 |
|
|
|
| 274 |
|
|
s19ProcessS9:
|
| 275 |
|
|
bsr s19GetAddress2
|
| 276 |
|
|
ldd s19Address+2
|
| 277 |
|
|
std s19StartAddress+2
|
| 278 |
|
|
ldd s19Address+0
|
| 279 |
|
|
std s19StartAddress+0
|
| 280 |
|
|
bra s19l2
|
| 281 |
|
|
|
| 282 |
|
|
; ------------------------------------------------------------------------------
|
| 283 |
|
|
; Processing for S8 record type. Gets a three byte (36 bit) start address.
|
| 284 |
|
|
; ------------------------------------------------------------------------------
|
| 285 |
|
|
|
| 286 |
|
|
s19ProcessS8:
|
| 287 |
|
|
bsr s19GetAddress3
|
| 288 |
|
|
ldd s19Address+2
|
| 289 |
|
|
std s19StartAddress+2
|
| 290 |
|
|
ldd s19Address+0
|
| 291 |
|
|
std s19StartAddress+0
|
| 292 |
|
|
bra s19l2
|
| 293 |
|
|
|
| 294 |
|
|
; ------------------------------------------------------------------------------
|
| 295 |
|
|
; S19 Loader
|
| 296 |
|
|
;
|
| 297 |
|
|
; Not all record types are processed. Some are skipped over.
|
| 298 |
|
|
; ------------------------------------------------------------------------------
|
| 299 |
|
|
|
| 300 |
|
|
S19Loader:
|
| 301 |
|
|
clr s19Source
|
| 302 |
|
|
lbsr GetNumber ; check for a file storage address
|
| 303 |
|
|
tstb
|
| 304 |
|
|
beq s19l4 ; if not a memory file
|
| 305 |
|
|
inc s19Source ; set flag indicating a memory file
|
| 306 |
|
|
ldd mon_numwka+2 ; set transfer address variable
|
| 307 |
|
|
std s19XferAddress
|
| 308 |
|
|
s19l4:
|
| 309 |
|
|
clr s19Abort ; clear the abort flag
|
| 310 |
|
|
ldd #msgS19Loader ; signon banner
|
| 311 |
|
|
swi
|
| 312 |
|
|
fcb MF_DisplayString
|
| 313 |
|
|
clr s19SummaryChecksum
|
| 314 |
|
|
s19l3:
|
| 315 |
|
|
bsr s19InputChar ; get a character from input
|
| 316 |
|
|
cmpb #CTRLZ ; is it CTRL-Z?
|
| 317 |
|
|
beq s19l2
|
| 318 |
|
|
clr s19Checksum
|
| 319 |
|
|
cmpb #'C' ; records must start with the letter C
|
| 320 |
|
|
bne s19lnr
|
| 321 |
|
|
bsr s19InputChar ; get the next character
|
| 322 |
|
|
cmpb #'0' ; must be a numeric digit
|
| 323 |
|
|
blo s19lnr
|
| 324 |
|
|
cmpb #'9'
|
| 325 |
|
|
bhi s19lnr
|
| 326 |
|
|
stb s19Rectype ; save off in record type
|
| 327 |
|
|
bsr s19GetByte ; get a byte indicating record length
|
| 328 |
|
|
bsr s19AddCheck
|
| 329 |
|
|
stb s19Reclen
|
| 330 |
|
|
tst s19Abort ; check for abort
|
| 331 |
|
|
bne s19l2
|
| 332 |
|
|
ldb s19Rectype ; process according to record type
|
| 333 |
|
|
cmpb #'0'
|
| 334 |
|
|
beq s19lnr
|
| 335 |
|
|
cmpb #'1'
|
| 336 |
|
|
beq s19ProcessS1 ; data record with a two byte address
|
| 337 |
|
|
cmpb #'2'
|
| 338 |
|
|
beq s19ProcessS2 ; data record with a three byte address
|
| 339 |
|
|
cmpb #'3'
|
| 340 |
|
|
beq s19lnr
|
| 341 |
|
|
cmpb #'5' ; record count? ignore
|
| 342 |
|
|
beq s19lnr
|
| 343 |
|
|
cmpb #'7' ; ignore record with 48 bit address
|
| 344 |
|
|
beq s19l2
|
| 345 |
|
|
cmpb #'8'
|
| 346 |
|
|
beq s19ProcessS8 ; two byte start address
|
| 347 |
|
|
cmpb #'9'
|
| 348 |
|
|
beq s19ProcessS9 ; three byte start address
|
| 349 |
|
|
s19lnr:
|
| 350 |
|
|
ldb #'.' ; output a progress indicator
|
| 351 |
|
|
swi
|
| 352 |
|
|
fcb MF_OUTCH
|
| 353 |
|
|
bsr s19NextRecord ; skip to the next record
|
| 354 |
|
|
tst S19Abort ; check for abort
|
| 355 |
|
|
bne s19l2
|
| 356 |
|
|
bra s19l3 ; loop back to process more records
|
| 357 |
|
|
s19l2:
|
| 358 |
|
|
lbra Monitor
|
| 359 |
|
|
|
| 360 |
|
|
msgS19Loader:
|
| 361 |
|
|
fcb "S19 Loader Active",CR,LF,0
|
| 362 |
|
|
msgChecksumErr:
|
| 363 |
|
|
fcb "S19 Checksum Err",CR,LF,0
|
| 364 |
|
|
|
| 365 |
|
|
|