| 38 | | keyscnlnk: |
| 39 | | di |
| 40 | | res enableHW2Timer,(iy+interruptFlags) |
| 41 | | call NZIf83Plus |
| 42 | | jr nz,$F |
| 43 | | ld b,a |
| 44 | | ld a,(9CAFh) |
| 45 | | or a |
| 46 | | ld a,b |
| 47 | | jr nz,keyscnlnk1 |
| 48 | | $$: call CheckLinkLines |
| 49 | | jr nz,eiRet |
| 50 | | keyscnlnk1: |
| 51 | | call MachineIDTo73h |
| 52 | | ld a,(ioErrState) |
| 53 | | push af |
| 54 | | ld a,(sndRecState) |
| 55 | | push af |
| 56 | | ld a,(ioFlag) |
| 57 | | push af |
| 58 | | ld hl,ioFlag |
| 59 | | res 1,(hl) |
| 60 | | ld a,7 |
| 61 | | ld (sndRecState),a |
| 62 | | ld a,(iy+curFlags) |
| 63 | | push af |
| 64 | | res 2,(iy+curFlags) |
| 65 | | call EnableLinkAssist |
| 66 | | ld hl,keyscnlnkHandler |
| 67 | | call APP_PUSH_ERRORH |
| 68 | | set indicOnly,(iy+indicFlags) |
| 69 | | in a,(2) |
| 70 | | and 80h |
| 71 | | jr z,$F |
| 72 | | ld a,(9CAFh) |
| 73 | | or a |
| 74 | | jr z,$F |
| 75 | | dec a |
| 76 | | ld (9CAFh),a |
| 77 | | ld a,(9CB2h) |
| 78 | | ld de,9CB2h |
| 79 | | ld hl,9CB3h |
| 80 | | ld bc,15 |
| 81 | | ldir |
| 82 | | cp 41h |
| 83 | | jr nz,keyscnlnkEnd |
| 84 | | xor a |
| 85 | | ld (9CAFh),a |
| 86 | | ld a,(9CB2h) |
| 87 | | jr kscnlnkGet3Bytes |
| 88 | | $$: ld a,(ioData) |
| 89 | | call ContinueGetByte |
| 90 | | bit 5,(iy+3Dh) |
| 91 | | jr z,kscnlnkGet3Bytes |
| 92 | | in a,(2) |
| 93 | | and 80h |
| 94 | | jr z,keyscnlnkEnd |
| 95 | | $$: in a,(9) |
| 96 | | and 19h |
| 97 | | jr z,disableLAEnd |
| 98 | | ld a,(9CAFh) |
| 99 | | cp 15 |
| 100 | | jr nc,keyscnlnkEnd |
| 101 | | inc a |
| 102 | | ld (9CAFh),a |
| 103 | | call ContinueGetByte |
| 104 | | ld hl,9CAFh |
| 105 | | ld e,(hl) |
| 106 | | ld d,0 |
| 107 | | ld hl,9CB1h |
| 108 | | add hl,de |
| 109 | | bit 5,(iy+3Dh) |
| 110 | | jr nz,kscnlnkContinue |
| 111 | | ld b,a |
| 112 | | ld a,41h |
| 113 | | ld (hl),a |
| 114 | | inc hl |
| 115 | | ld a,b |
| 116 | | ld (hl),a |
| 117 | | jr keyscnlnkEnd |
| 118 | | kscnlnkContinue: |
| 119 | | ld (hl),a |
| 120 | | jr $B |
| 121 | | kscnlnkGet3Bytes: |
| 122 | | ; call Get3Bytes |
| 123 | | call RecAByteIO |
| 124 | | ld (header+1),a |
| 125 | | call RecAByteIO |
| 126 | | ld (header+2),a |
| 127 | | call RecAByteIO |
| 128 | | ld (header+3),a |
| 129 | | ld hl,cmdTable |
| 130 | | ld b,(hl) |
| 131 | | inc hl |
| 132 | | $$: cp (hl) |
| 133 | | inc hl |
| 134 | | jr z,$F |
| 135 | | inc hl |
| 136 | | inc hl |
| 137 | | djnz $B |
| 138 | | ld a,(header+1) |
| 139 | | call DispHexA |
| 140 | | di |
| 141 | | halt |
| 142 | | jp JErrorNo |
| 143 | | $$: call LdHLInd |
| 144 | | jp (hl) |
| 145 | | disableLAEnd: |
| 146 | | call DisableLinkAssist |
| 147 | | jr keyscnlnkEnd |
| 148 | | sendAcknowledgeEnd: |
| 149 | | call SendAcknowledge |
| 150 | | keyscnlnkEnd: |
| 151 | | call APP_POP_ERRORH |
| 152 | | keyscnlnkHandler: |
| 153 | | di |
| 154 | | call DisableLinkAssist |
| 155 | | pop af |
| 156 | | bit 2,a |
| 157 | | jr z,$F |
| 158 | | set curAble,(iy+curFlags) |
| 159 | | $$: pop af |
| 160 | | ld (ioFlag),a |
| 161 | | pop af |
| 162 | | ld (sndRecState),a |
| 163 | | pop af |
| 164 | | ld (ioErrState),a |
| 165 | | set apdRunning,(iy+apdFlags) |
| 166 | | di |
| 167 | | res indicOnly,(iy+indicFlags) |
| 168 | | ld a,5 |
| 169 | | out (LCDinstPort),a |
| 170 | | eiRet: ei |
| 171 | | ret |
| 172 | | cmdTable: |
| 173 | | DB (cmdTableEnd-cmdTableStart)/3 |
| 174 | | cmdTableStart: |
| 175 | | DB 68h |
| 176 | | DW sendAcknowledgeEnd |
| 177 | | DB 2Dh |
| 178 | | DW sendInfoPacket |
| 179 | | DB 06h |
| 180 | | DW receivedVariableHeader |
| 181 | | DB 87h |
| 182 | | DW remoteControlPacket |
| 183 | | cmdTableEnd: |
| 184 | | |
| 185 | | remoteControlPacket: |
| 186 | | call SendAcknowledge |
| 187 | | jr keyscnlnkEnd |
| 188 | | receivedVariableHeader: |
| 189 | | call ReceiveHeaderPacket |
| 190 | | ld a,(867Fh) |
| 191 | | cp 23h |
| 192 | | jr z,receivingOS |
| 193 | | ld de,1 |
| 194 | | ld a,0Ch |
| 195 | | call SendSkipExitPacket |
| 196 | | jr keyscnlnkEnd |
| 197 | | receivingOS: |
| 198 | | call EnableLinkAssist |
| 199 | | ld a,0FFh |
| 200 | | ld (appSearchPage),a |
| 201 | | xor a |
| 202 | | ld (ramCodeEnd),a |
| 203 | | ld (83A4h),a |
| 204 | | B_CALL MD5Init |
| 205 | | B_CALL ReceiveOS |
| 206 | | |
| 207 | | sendInfoPacket: |
| 208 | | call SendAcknowledge |
| 209 | | call Get4BytesNC |
| 210 | | cp 09h |
| 211 | | jr nz,JErrorNo |
| 212 | | call SendAcknowledge |
| 213 | | ld hl,ioData |
| 214 | | ld (hl),OS2_VERSION_MAJOR |
| 215 | | inc hl |
| 216 | | ld (hl),OS2_VERSION_MINOR |
| 217 | | inc hl |
| 218 | | B_CALL GetBootVer |
| 219 | | ld (hl),a |
| 220 | | inc hl |
| 221 | | ld (hl),b |
| 222 | | inc hl |
| 223 | | ld (hl),2 |
| 224 | | inc hl |
| 225 | | B_CALL GetHWVer |
| 226 | | ld (hl),a |
| 227 | | inc hl |
| 228 | | ld (hl),09h |
| 229 | | inc hl |
| 230 | | ld (hl),01h |
| 231 | | inc hl |
| 232 | | ld (hl),0 |
| 233 | | inc hl |
| 234 | | ld (hl),0 |
| 235 | | inc hl |
| 236 | | ld (hl),0 |
| 237 | | ld a,15h |
| 238 | | ld hl,11 |
| 239 | | call SendCommandA |
| 240 | | jr keyscnlnkEnd |
| 241 | | SendCommandA: |
| 242 | | ex de,hl |
| 243 | | ld hl,ioData |
| 244 | | SendACommand: |
| 245 | | ld b,0 |
| 246 | | ex de,hl |
| 247 | | call SetupPagedPtr |
| 248 | | ex de,hl |
| 249 | | ld (iMathPtr5),hl |
| 250 | | ld (header+2),de |
| 251 | | ld h,a |
| 252 | | call EnableLinkAssist |
| 253 | | set indicOnly,(iy+indicFlags) |
| 254 | | call MachineIDToL |
| 255 | | ld (header),hl |
| 256 | | call Send4Bytes |
| 257 | | ld hl,(iMathPtr5) |
| 258 | | ld de,(header+2) |
| 259 | | ld bc,0 |
| 260 | | ld (header+4),bc |
| 261 | | jr startSendCmdLoop |
| 262 | | sendCmdLoop: |
| 263 | | push de |
| 264 | | ld a,(pagedPN) |
| 265 | | or a |
| 266 | | jr z,$F |
| 267 | | call PagedGet |
| 268 | | ld c,a |
| 269 | | jr sendCmdByte |
| 270 | | $$: ld c,(hl) |
| 271 | | sendCmdByte: |
| 272 | | call SendCAndAddToChecksum |
| 273 | | pop de |
| 274 | | dec de |
| 275 | | inc hl |
| 276 | | startSendCmdLoop: |
| 277 | | ld a,d |
| 278 | | or e |
| 279 | | jr nz,sendCmdLoop |
| 280 | | SendChecksumGetAcknowledge: |
| 281 | | ld hl,(header+4) |
| 282 | | ld a,l |
| 283 | | push hl |
| 284 | | call SendAByte |
| 285 | | pop af |
| 286 | | call SendAByte |
| 287 | | ReceiveAcknowledge: |
| 288 | | call Get4BytesNC |
| 289 | | ld a,(header+1) |
| 290 | | cp 56h |
| 291 | | ret z |
| 292 | | jp JErrorNo |
| 293 | | SendCAndAddToChecksum: |
| 294 | | ld b,0 |
| 295 | | ex de,hl |
| 296 | | ld hl,(header+4) |
| 297 | | add hl,bc |
| 298 | | ld (header+4),hl |
| 299 | | ex de,hl |
| 300 | | jr SendCByte |
| 301 | | |
| 302 | | SendSkipExitPacket: |
| 303 | | ld hl,867Ch |
| 304 | | ld (hl),a |
| 305 | | ld a,36h |
| 306 | | jr SendACommand |
| 307 | | |
| 308 | | ReceiveHeaderPacket: |
| 309 | | xor a |
| 310 | | ld (ioNewData-1),a |
| 311 | | ld (ioNewData),a |
| 312 | | ld hl,ioData |
| 313 | | jr $F |
| 314 | | ReceiveDataPacket: |
| 315 | | ld (iMathPtr5),de |
| 316 | | push bc |
| 317 | | call Get4BytesNC |
| 318 | | pop bc |
| 319 | | ld hl,ioFlag |
| 320 | | ld a,(header+1) |
| 321 | | jp nz,JErrorNo |
| 322 | | ld hl,(header+2) |
| 323 | | or a |
| 324 | | sbc hl,bc |
| 325 | | jp nz,JErrorNo |
| 326 | | jr receiveRestOfDataPacket |
| 327 | | GetSmallDataPacket: |
| 328 | | ld hl,ioData-1 |
| 329 | | $$: ld (iMathPtr5),hl |
| 330 | | ld hl,(header+2) |
| 331 | | ld de,15 |
| 332 | | or a |
| 333 | | sbc hl,de |
| 334 | | jr c,receiveRestOfDataPacket |
| 335 | | jp JErrorNo |
| 336 | | receiveRestOfDataPacket: |
| 337 | | ld bc,(header+2) |
| 338 | | ld de,0 |
| 339 | | ld (header+4),de |
| 340 | | ld a,b |
| 341 | | or c |
| 342 | | jr z,receiveDataDone |
| 343 | | ld hl,pagedBuf |
| 344 | | ld (pagedGetPtr),hl |
| 345 | | xor a |
| 346 | | ld (pagedCount),a |
| 347 | | ld hl,(iMathPtr5) |
| 348 | | receiveDataLoop: |
| 349 | | in a,(4) |
| 350 | | bit 3,a |
| 351 | | jr z,JErrorNo |
| 352 | | push bc |
| 353 | | call RecAByteIO |
| 354 | | bit 7,h |
| 355 | | jr nz,$F |
| 356 | | push hl |
| 357 | | ld hl,(pagedGetPtr) |
| 358 | | ld (hl),a |
| 359 | | inc hl |
| 360 | | ld (pagedGetPtr),hl |
| 361 | | pop hl |
| 362 | | ld a,(pagedCount) |
| 363 | | inc a |
| 364 | | ld (pagedCount),a |
| 365 | | cp 16 |
| 366 | | call z,SaveFlashBytes |
| 367 | | jr receiveDataContinue |
| 368 | | $$: ld (hl),a |
| 369 | | inc hl |
| 370 | | receiveDataContinue: |
| 371 | | ex de,hl |
| 372 | | ld b,0 |
| 373 | | ld hl,(header+4) |
| 374 | | add hl,bc |
| 375 | | ld (header+4),hl |
| 376 | | ex de,hl |
| 377 | | pop bc |
| 378 | | dec bc |
| 379 | | ld a,b |
| 380 | | or c |
| 381 | | jr nz,receiveDataLoop |
| 382 | | ld a,(pagedCount) |
| 383 | | or a |
| 384 | | call nz,SaveFlashBytes |
| 385 | | receiveDataDone: |
| 386 | | call RecAByteIO |
| 387 | | push af |
| 388 | | call RecAByteIO |
| 389 | | ld b,a |
| 390 | | pop af |
| 391 | | call ValidateChecksum |
| 392 | | jr SendAcknowledge |
| 393 | | ValidateChecksum: |
| 394 | | ld c,a |
| 395 | | in a,(statusPort) |
| 396 | | and STATUS_NON_83P_MASK |
| 397 | | jr z,vcNotSE |
| 398 | | in a,(speedPort) |
| 399 | | and 1 |
| 400 | | jr z,vcNotSE |
| 401 | | xor a |
| 402 | | out (speedPort),a |
| 403 | | ld de,0FEh |
| 404 | | $$: dec de |
| 405 | | ld a,d |
| 406 | | or e |
| 407 | | jr nz,$B |
| 408 | | ld a,1 |
| 409 | | out (speedPort),a |
| 410 | | jr $F |
| 411 | | vcNotSE: |
| 412 | | ld de,100h |
| 413 | | $$: dec de |
| 414 | | ld a,d |
| 415 | | or e |
| 416 | | jr nz,$B |
| 417 | | $$: ld hl,(header+4) |
| 418 | | or a |
| 419 | | sbc hl,bc |
| 420 | | or a |
| 421 | | ret ;UH?! |
| 422 | | jr nz,$F |
| 423 | | ret |
| 424 | | $$: ld hl,(header+2) |
| 425 | | push hl |
| 426 | | ld h,5Ah |
| 427 | | call SendHCommand |
| 428 | | jp JErrorNo |
| 429 | | SendHCommand: |
| 430 | | set indicOnly,(iy+indicFlags) |
| 431 | | call MachineIDToL |
| 432 | | ld (header),hl |
| 433 | | di |
| 434 | | call Send4Bytes |
| 435 | | ei |
| 436 | | jr ReceiveAcknowledge |
| 437 | | SaveFlashBytes: |
| 438 | | push bc |
| 439 | | push de |
| 440 | | push hl |
| 441 | | ld a,(pagedCount) |
| 442 | | ld c,a |
| 443 | | xor a |
| 444 | | ld (pagedCount),a |
| 445 | | ld hl,pagedBuf |
| 446 | | ld (pagedGetPtr),hl |
| 447 | | ld de,(iMathPtr5) |
| 448 | | ld a,(arcInfo) |
| 449 | | push de |
| 450 | | ld (Abackup),a |
| 451 | | ld a,i |
| 452 | | jp pe,$F |
| 453 | | ld a,i |
| 454 | | $$: di |
| 455 | | push af |
| 456 | | ld a,(Abackup) |
| 457 | | push af |
| 458 | | ld a,1 |
| 459 | | nop |
| 460 | | di |
| 461 | | nop |
| 462 | | nop |
| 463 | | im 1 |
| 464 | | di |
| 465 | | out (14h),a |
| 466 | | di |
| 467 | | pop af |
| 468 | | ld b,0 |
| 469 | | B_CALL WriteFlash |
| 470 | | call LockFlash |
| 471 | | ld (Abackup),a |
| 472 | | pop af |
| 473 | | jp po,$F |
| 474 | | ei |
| 475 | | $$: ld a,(83EBh) |
| 476 | | ld (iMathPtr5),de |
| 477 | | pop hl |
| 478 | | or a |
| 479 | | sbc hl,de |
| 480 | | jr c,$F |
| 481 | | ld a,(arcInfo) |
| 482 | | inc a |
| 483 | | ld (arcInfo),a |
| 484 | | $$: pop hl |
| 485 | | pop de |
| 486 | | pop bc |
| 487 | | ret |
| 488 | | |
| 489 | | Get4BytesNC: |
| 490 | | call Rec1stByteNC |
| 491 | | Get3Bytes: |
| 492 | | ld (header),a |
| 493 | | Get3From4BytePacket: |
| 494 | | call RecAByteIO |
| 495 | | ld (header+1),a |
| 496 | | call RecAByteIO |
| 497 | | ld (header+2),a |
| 498 | | call RecAByteIO |
| 499 | | ld (header+3),a |
| 500 | | ld a,(header+1) |
| 501 | | ret |
| 502 | | |
| 503 | | CheckLinkLines: |
| 504 | | ld bc,15 |
| 505 | | ld hl,ioData |
| 506 | | ld (hl),a |
| 507 | | call NZIf83Plus |
| 508 | | jr nz,$F |
| 509 | | bit linkAssistEnabled,(iy+linkAssistFlags) |
| 510 | | jr nz,xorAret |
| 511 | | in a,(speedPort) |
| 512 | | and 1 |
| 513 | | jr z,$F |
| 514 | | ld bc,32 |
| 515 | | $$: in a,(0) |
| 516 | | and 3 |
| 517 | | cp (hl) |
| 518 | | ret nz |
| 519 | | dec bc |
| 520 | | ld a,b |
| 521 | | or c |
| 522 | | jr nz,$B |
| 523 | | ret |
| 524 | | xorAret: |
| 525 | | xor a |
| 526 | | ret |
| 527 | | |
| 528 | | EnableLinkAssist: |
| 529 | | call NZIf83Plus |
| 530 | | ret nz |
| 531 | | bit linkAssistEnabled,(iy+linkAssistFlags) |
| 532 | | ret nz |
| 533 | | set linkAssistEnabled,(iy+linkAssistFlags) |
| 534 | | in a,(laStatusPort) |
| 535 | | xor a |
| 536 | | out (laEnPort),a |
| 537 | | ret |
| 538 | | |
| 539 | | DisableLinkAssist: |
| 540 | | in a,(statusPort) |
| 541 | | and STATUS_NON_83P_MASK |
| 542 | | ret z |
| 543 | | in a,(laStatusPort) |
| 544 | | and 99h |
| 545 | | ret nz |
| 546 | | res linkAssistEnabled,(iy+linkAssistFlags) |
| 547 | | ld a,80h |
| 548 | | out (laEnPort),a |
| 549 | | ret |
| 550 | | |
| 551 | | MachineIDTo73h: |
| 552 | | push af |
| 553 | | ld a,(iy+linkFlags) |
| 554 | | and 0E1h |
| 555 | | ld (iy+linkFlags),a |
| 556 | | pop af |
| 557 | | ret |
| 558 | | |
| 559 | | RecAByteIO: |
| 560 | | di |
| 561 | | call ReceiveByteToC |
| 562 | | call RecAByteIO_1 |
| 563 | | ret c |
| 564 | | ret nz |
| 565 | | jr z,RecAByteIO |
| 566 | | RecAByteIO_1: |
| 567 | | ;I think this is a TI-Keyboard routine, let it fail |
| 568 | | cp 1 |
| 569 | | ld a,c |
| 570 | | ; jr nz,$F |
| 571 | | cp 0E0h |
| 572 | | ret nz |
| 573 | | scf |
| 574 | | ret |
| 575 | | ReceiveByteToC: |
| 576 | | ld b,8 |
| 577 | | receiveByteLoop: |
| 578 | | call NZIf83Plus |
| 579 | | jr z,ReceiveLAByteToC |
| 580 | | ld de,0FFFh |
| 581 | | jr startReceiveLoop |
| 582 | | receiveLoop: |
| 583 | | in a,(0) |
| 584 | | and 3 |
| 585 | | jp z,JErrorNo |
| 586 | | cp 3 |
| 587 | | jr nz,ReceiveByteToC_Ready |
| 588 | | in a,(0) |
| 589 | | and 3 |
| 590 | | jr z,JErrorNo |
| 591 | | cp 3 |
| 592 | | jr nz,ReceiveByteToC_Ready |
| 593 | | startReceiveLoop: |
| 594 | | dec de |
| 595 | | ld a,d |
| 596 | | or e |
| 597 | | jr nz,receiveLoop |
| 598 | | jp JErrorNo |
| 599 | | ReceiveByteToC_Ready: |
| 600 | | cp 2 |
| 601 | | jr z,RBTC_1 |
| 602 | | ld a,1 |
| 603 | | out (0),a |
| 604 | | rr c |
| 605 | | ld de,0FFFFh |
| 606 | | $$: in a,(0) |
| 607 | | and 3 |
| 608 | | cp 2 |
| 609 | | jr z,RBTC_2 |
| 610 | | dec de |
| 611 | | ld a,d |
| 612 | | or e |
| 613 | | jr nz,$B |
| 614 | | jp JErrorNo |
| 615 | | RBTC_2:xor a |
| 616 | | out (0),a |
| 617 | | ld d,4 |
| 618 | | $$: dec d |
| 619 | | jr z,$F |
| 620 | | in a,(0) |
| 621 | | and 3 |
| 622 | | cp 3 |
| 623 | | jr nz,$B |
| 624 | | $$: djnz receiveByteLoop |
| 625 | | ld a,0 |
| 626 | | ret |
| 627 | | RBTC_1:ld a,2 |
| 628 | | out (0),a |
| 629 | | rr c |
| 630 | | ld de,0FFFFh |
| 631 | | $$: in a,(0) |
| 632 | | and 3 |
| 633 | | cp 1 |
| 634 | | jr z,RBTC_2 |
| 635 | | dec de |
| 636 | | ld a,d |
| 637 | | or e |
| 638 | | jr nz,$B |
| 639 | | jp JErrorNo |
| 640 | | ReceiveLAByteToC: |
| 641 | | call EnableLinkAssist |
| 642 | | call ResetLATimeout |
| 643 | | $$: xor a |
| 644 | | ld (9C86h),a |
| 645 | | call NZIfTimeout |
| 646 | | jp nz,JErrorNo |
| 647 | | in a,(9) |
| 648 | | bit 6,a |
| 649 | | jr nz,$F |
| 650 | | and 11h |
| 651 | | jr z,$B |
| 652 | | in a,(0Ah) |
| 653 | | ld c,a |
| 654 | | ld a,0 |
| 655 | | ret |
| 656 | | $$: and 11h |
| 657 | | jp z,JErrorNo |
| 658 | | in a,(0Ah) |
| 659 | | ld c,a |
| 660 | | ld a,1 |
| 661 | | ret |
| 662 | | NZIfTimeout: |
| 663 | | push hl |
| 664 | | ld h,2 |
| 665 | | $$: dec h |
| 666 | | jr nz,$B |
| 667 | | ld hl,(linkDelay) |
| 668 | | dec hl |
| 669 | | ld (linkDelay),hl |
| 670 | | ld a,h |
| 671 | | or l |
| 672 | | jr nz,$F |
| 673 | | ld a,1 |
| 674 | | jr NZIT_1 |
| 675 | | $$: ld a,0 |
| 676 | | NZIT_1:or a |
| 677 | | pop hl |
| 678 | | ret |
| 679 | | ResetLATimeout: |
| 680 | | push hl |
| 681 | | ld hl,0FFFFh |
| 682 | | in a,(speedPort) |
| 683 | | and 1 |
| 684 | | jr nz,$F |
| 685 | | ld hl,6800h |
| 686 | | $$: ld (linkDelay),hl |
| 687 | | pop hl |
| 688 | | ret |
| 689 | | ContinueGetByte: |
| 690 | | set indicOnly,(iy+indicFlags) |
| 691 | | di |
| 692 | | res 5,(iy+3Dh) |
| 693 | | call NZIf83Plus |
| 694 | | jr nz,cgbNoAssist |
| 695 | | di |
| 696 | | call ReceiveLAByteToC |
| 697 | | ret |
| 698 | | cgbNoAssist: |
| 699 | | ld b,8 |
| 700 | | call ReceiveByteToC_Ready |
| 701 | | ret |
| 702 | | SendAcknowledge: |
| 703 | | ld hl,0 |
| 704 | | SendAcknowledgeHL: |
| 705 | | ld (header+2),hl |
| 706 | | call MachineIDToL |
| 707 | | ld h,56h |
| 708 | | ld (header),hl |
| 709 | | Send4Bytes: |
| 710 | | call EnableLinkAssist |
| 711 | | ld hl,250 |
| 712 | | $$: dec hl |
| 713 | | ld a,h |
| 714 | | or l |
| 715 | | jr nz,$B |
| 716 | | send4Loop: |
| 717 | | call NZIf83Plus |
| 718 | | jr z,send4LA |
| 719 | | xor a |
| 720 | | out (0),a |
| 721 | | in a,(0) |
| 722 | | and 3 |
| 723 | | cp 3 |
| 724 | | jr z,sendBytes |
| 725 | | send4ReceivedByte: |
| 726 | | call ReceiveByteToC |
| 727 | | jr send4Loop |
| 728 | | send4LA: |
| 729 | | in a,(9) |
| 730 | | and 19h |
| 731 | | jr nz,send4ReceivedByte |
| 732 | | sendBytes: |
| 733 | | ld hl,0 |
| 734 | | ld (header+4),hl |
| 735 | | ld a,(header) |
| 736 | | call SendAByte |
| 737 | | ld a,(header+1) |
| 738 | | call SendAByte |
| 739 | | ld a,(header+2) |
| 740 | | call SendAByte |
| 741 | | ld a,(header+3) |
| 742 | | SendAByte: |
| 743 | | ld c,a |
| 744 | | SendCByte: |
| 745 | | call NZIf83Plus |
| 746 | | jr z,sendByteLA |
| 747 | | ld b,8 |
| 748 | | sendLoop: |
| 749 | | ld de,0FFFFh |
| 750 | | rr c |
| 751 | | jr nc,$F |
| 752 | | ld a,2 |
| 753 | | jr sendContinue |
| 754 | | $$: ld a,1 |
| 755 | | sendContinue: |
| 756 | | out (0),a |
| 757 | | bitLoop: |
| 758 | | in a,(0) |
| 759 | | and 3 |
| 760 | | jr z,bitDone |
| 761 | | in a,(0) |
| 762 | | and 3 |
| 763 | | jr z,bitDone |
| 764 | | dec de |
| 765 | | ld a,d |
| 766 | | or e |
| 767 | | jr nz,bitLoop |
| 768 | | jp JErrorNo |
| 769 | | bitDone: |
| 770 | | xor a |
| 771 | | out (0),a |
| 772 | | ld de,0FFFFh |
| 773 | | bitReallyDone: |
| 774 | | dec de |
| 775 | | ld a,d |
| 776 | | or e |
| 777 | | jp z,JErrorNo |
| 778 | | in a,(0) |
| 779 | | and 3 |
| 780 | | cp 3 |
| 781 | | jr nz,bitReallyDone |
| 782 | | djnz sendLoop |
| 783 | | ret |
| 784 | | sendByteLA: |
| 785 | | call EnableLinkAssist |
| 786 | | call ResetLATimeout |
| 787 | | sendByteLA_1: |
| 788 | | ld a,0FAh |
| 789 | | ld (9C86h),a |
| 790 | | in a,(9) |
| 791 | | bit 5,a |
| 792 | | jr z,$F |
| 793 | | ld a,c |
| 794 | | out (0Dh),a |
| 795 | | ret |
| 796 | | $$: call NZIfTimeout |
| 797 | | jr z,sendByteLA_1 |
| 798 | | jp JErrorNo |
| 799 | | MachineIDToL: |
| 800 | | ld (iy+linkFlags),0 |
| 801 | | ld l,82h |
| 802 | | bit 2,(iy+linkFlags) |
| 803 | | ret nz |
| 804 | | ld l,95h |
| 805 | | bit 1,(iy+linkFlags) |
| 806 | | ret nz |
| 807 | | ld l,83h |
| 808 | | bit 3,(iy+linkFlags) |
| 809 | | ret nz |
| 810 | | ld l,03h |
| 811 | | bit 4,(iy+linkFlags) |
| 812 | | ret nz |
| 813 | | ld l,73h |
| 814 | | ret |
| 815 | | Rec1stByteNC: |
| 816 | | di |
| 817 | | res indicOnly,(iy+indicFlags) |
| 818 | | ld a,5 |
| 819 | | out (LCDinstPort),a |
| 820 | | ei |
| 821 | | call NZIf83Plus |
| 822 | | jr nz,$F |
| 823 | | call EnableLinkAssist |
| 824 | | call LAReceiveByteToC |
| 825 | | ld a,c |
| 826 | | ret |
| 827 | | $$: bit 4,(iy+9) |
| 828 | | jp nz,JErrorNo |
| 829 | | call HandleLinkKeyActivity |
| 830 | | in a,(0) |
| 831 | | and 3 |
| 832 | | cp 3 |
| 833 | | jr z,$B |
| 834 | | set indicOnly,(iy+indicFlags) |
| 835 | | call ReceiveByteToC_Ready |
| 836 | | ld a,c |
| 837 | | ret |
| 838 | | LAReceiveByteToC: |
| 839 | | bit 4,(iy+9) |
| 840 | | jp nz,JErrorNo |
| 841 | | call HandleLinkKeyActivity |
| 842 | | in a,(9) |
| 843 | | and 58h |
| 844 | | jr z,LAReceiveByteToC |
| 845 | | set indicOnly,(iy+indicFlags) |
| 846 | | jr ReceiveLAByteToC |
| 847 | | |