mads 2.1.0 build 8 (23 Dec 19) Source: mod_disp80.s 1 ; Altirra Acid800 test suite 2 ; Copyright (C) 2010 Avery Lee, All Rights Reserved. 3 ; 4 ; Permission is hereby granted, free of charge, to any person obtaining a copy 5 ; of this software and associated documentation files (the "Software"), to deal 6 ; in the Software without restriction, including without limitation the rights 7 ; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 ; copies of the Software, and to permit persons to whom the Software is 9 ; furnished to do so, subject to the following conditions: 10 ; 11 ; The above copyright notice and this permission notice shall be included in 12 ; all copies or substantial portions of the Software. 13 ; 14 ; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 ; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 ; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 ; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 ; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 ; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 ; SOFTWARE. 21 22 opt h+o+ 23 24 icl 'library.s' Source: library.s 1 ; Altirra Acid800 test suite 2 ; Copyright (C) 2010 Avery Lee, All Rights Reserved. 3 ; 4 ; Permission is hereby granted, free of charge, to any person obtaining a copy 5 ; of this software and associated documentation files (the "Software"), to deal 6 ; in the Software without restriction, including without limitation the rights 7 ; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 ; copies of the Software, and to permit persons to whom the Software is 9 ; furnished to do so, subject to the following conditions: 10 ; 11 ; The above copyright notice and this permission notice shall be included in 12 ; all copies or substantial portions of the Software. 13 ; 14 ; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 ; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 ; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 ; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 ; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 ; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 ; SOFTWARE. 21 22 ;========================================================================== 23 ; MEMORY MAP (800) 24 ; 25 ; $0000-007F OS zero page 26 ; $0080-00BF Module zero page 27 ; $00C0-00DF Library zero page 28 ; $00E0-00EF 80-column zero page 29 ; $0100-01FF 6502 stack 30 ; $0200-03FF OS database 31 ; $0400-09FF Boot loader / unused 32 ; $0A00-0AFF Boot loader / Veronica support resident page 33 ; $0B00-0BFF Boot loader / sector load buffer 34 ; $0C00-0FFF Boot loader / 16K display 35 ; $1000-18FF Resident test driver (full suite only) 36 ; $1900-19FF Segment tables (full suite only) 37 ; $1A00-1FFF Library code 38 ; $2000-3FFF Module run area 39 ; $4000-5FFF Segment load area / Extended memory window 40 ; $6000-7FFF 80-column screen A / Extended memory window 41 ; $9000-9BFF 80-column driver 42 ; $9C00-9FFF Unused (display list if cart) 43 ; $A000-BFFF 80-column screen B 44 ; 45 ; MEMORY MAP (5200) 46 ; 47 ; $0000-001F OS zero page 48 ; $0020-003F Display zero page 49 ; $0080-00BF Module zero page 50 ; $00C0-00DF Library zero page 51 ; $0100-01FF 6502 stack 52 ; $0200-021F OS database 53 ; $0220-027F Unused 54 ; $0280-02FF Library database 55 ; $0300-07FF Display memory 56 ; $0800-0FFF Unused 57 ; $1000-1FFF LZ decompression history window 58 ; $2000-3FFF Module run area 59 ; $4000-BFFF Cartridge library code and module store 60 ; 61 ; MEMORY MAP (SAP) 62 ; 63 ; $0080-00BF Module zero page 64 ; $00C0-00DF Library zero page 65 ; $0280-02FF Library database 66 ; $0300-07FF Display memory 67 ; $2000-3FFF Module run area 68 ; $4000-BFFF Module store 69 70 ;========================================================================== 71 ; CONFIGURATION 72 ; 73 .ifndef SYS800 74 SEGS_IN_ROM = 1 75 .else 76 = 0001 SEGS_MIN_MEM = 1 77 .endif 78 79 .ifdef SYS5200 80 SEGS_LZPACK = 1 81 .endif 82 83 ;========================================================================== 84 ; HARDWARE INCLUDES 85 ; 86 .ifdef SYS5200 87 ;GTIA 88 gtia = $c000 89 m0pf equ $c000 90 m1pf equ $c001 91 m2pf equ $c002 92 m3pf equ $c003 93 p0pf equ $c004 94 p1pf equ $c005 95 p2pf equ $c006 96 p3pf equ $c007 97 m0pl equ $c008 98 m1pl equ $c009 99 m2pl equ $c00a 100 m3pl equ $c00b 101 p0pl equ $c00c 102 p1pl equ $c00d 103 p2pl equ $c00e 104 p3pl equ $c00f 105 hposp0 equ $c000 106 hposp1 equ $c001 107 hposp2 equ $c002 108 hposp3 equ $c003 109 hposm0 equ $c004 110 hposm1 equ $c005 111 hposm2 equ $c006 112 hposm3 equ $c007 113 sizep0 equ $c008 114 sizep1 equ $c009 115 sizep2 equ $c00a 116 sizep3 equ $c00b 117 sizem equ $c00c 118 grafp0 equ $c00d 119 grafp1 equ $c00e 120 grafp2 equ $c00f 121 grafp3 equ $c010 122 trig0 equ $c010 123 grafm equ $c011 124 colpm0 equ $c012 125 colpm1 equ $c013 126 colpm2 equ $c014 127 pal equ $c014 128 colpm3 equ $c015 129 colpf0 equ $c016 130 colpf1 equ $c017 131 colpf2 equ $c018 132 colpf3 equ $c019 133 colbk equ $c01a 134 prior equ $c01b 135 vdelay equ $c01c 136 gractl equ $c01d 137 hitclr equ $c01e 138 consol equ $c01f 139 140 ;POKEY 141 pokey = $e800 142 audf1 equ $e800 143 audc1 equ $e801 144 audf2 equ $e802 145 audc2 equ $e803 146 audf3 equ $e804 147 audc3 equ $e805 148 audf4 equ $e806 149 audc4 equ $e807 150 audctl equ $e808 151 stimer equ $e809 152 random equ $e80a 153 skres equ $e80a 154 serin equ $e80d 155 serout equ $e80d 156 irqen equ $e80e 157 irqst equ $e80e 158 skctl equ $e80f 159 skstat equ $e80f 160 .else 161 ;GTIA 162 = D000 gtia = $d000 163 = D000 m0pf equ $d000 164 = D001 m1pf equ $d001 165 = D002 m2pf equ $d002 166 = D003 m3pf equ $d003 167 = D004 p0pf equ $d004 168 = D005 p1pf equ $d005 169 = D006 p2pf equ $d006 170 = D007 p3pf equ $d007 171 = D008 m0pl equ $d008 172 = D009 m1pl equ $d009 173 = D00A m2pl equ $d00a 174 = D00B m3pl equ $d00b 175 = D00C p0pl equ $d00c 176 = D00D p1pl equ $d00d 177 = D00E p2pl equ $d00e 178 = D00F p3pl equ $d00f 179 = D000 hposp0 equ $d000 180 = D001 hposp1 equ $d001 181 = D002 hposp2 equ $d002 182 = D003 hposp3 equ $d003 183 = D004 hposm0 equ $d004 184 = D005 hposm1 equ $d005 185 = D006 hposm2 equ $d006 186 = D007 hposm3 equ $d007 187 = D008 sizep0 equ $d008 188 = D009 sizep1 equ $d009 189 = D00A sizep2 equ $d00a 190 = D00B sizep3 equ $d00b 191 = D00C sizem equ $d00c 192 = D00D grafp0 equ $d00d 193 = D00E grafp1 equ $d00e 194 = D00F grafp2 equ $d00f 195 = D010 grafp3 equ $d010 196 = D010 trig0 equ $d010 197 = D011 grafm equ $d011 198 = D012 colpm0 equ $d012 199 = D013 colpm1 equ $d013 200 = D014 colpm2 equ $d014 201 = D014 pal equ $d014 202 = D015 colpm3 equ $d015 203 = D016 colpf0 equ $d016 204 = D017 colpf1 equ $d017 205 = D018 colpf2 equ $d018 206 = D019 colpf3 equ $d019 207 = D01A colbk equ $d01a 208 = D01B prior equ $d01b 209 = D01C vdelay equ $d01c 210 = D01D gractl equ $d01d 211 = D01E hitclr equ $d01e 212 = D01F consol equ $d01f 213 214 ;POKEY 215 = D200 pokey = $d200 216 = D200 audf1 equ $d200 217 = D201 audc1 equ $d201 218 = D202 audf2 equ $d202 219 = D203 audc2 equ $d203 220 = D204 audf3 equ $d204 221 = D205 audc3 equ $d205 222 = D206 audf4 equ $d206 223 = D207 audc4 equ $d207 224 = D208 audctl equ $d208 225 = D209 stimer equ $d209 226 = D209 kbcode equ $d209 227 = D20A random equ $d20a 228 = D20A skres equ $d20a 229 = D20D serin equ $d20d 230 = D20D serout equ $d20d 231 = D20E irqen equ $d20e 232 = D20E irqst equ $d20e 233 = D20F skctl equ $d20f 234 = D20F skstat equ $d20f 235 236 ;PIA 237 = D300 porta equ $d300 238 = D301 portb equ $d301 239 = D302 pactl equ $d302 240 = D303 pbctl equ $d303 241 .endif 242 243 ;ANTIC 244 = D400 dmactl equ $d400 245 = D401 chactl equ $d401 246 = D402 dlistl equ $d402 247 = D403 dlisth equ $d403 248 = D404 hscrol equ $d404 249 = D405 vscrol equ $d405 250 = D407 pmbase equ $d407 251 = D409 chbase equ $d409 252 = D40A wsync equ $d40a 253 = D40B vcount equ $d40b 254 = D40E nmien equ $d40e 255 = D40F nmires equ $d40f 256 = D40F nmist equ $d40f 257 258 ;========================================================================== 259 ; OS INCLUDES (5200) 260 ; 261 .ifdef SYS5200 262 pokmsk equ $00 263 rtclok equ $01 264 ; equ $02 265 critic equ $03 266 atract equ $04 267 sdlstl equ $05 268 sdlsth equ $06 269 sdmctl equ $07 270 pcolr0 equ $08 271 pcolr1 equ $09 272 pcolr2 equ $0a 273 pcolr3 equ $0b 274 color0 equ $0c 275 color1 equ $0d 276 color2 equ $0e 277 color3 equ $0f 278 color4 equ $10 279 280 vimirq equ $0200 ;IRQ immediate vector 281 vvblki equ $0202 ;VBI immediate vector 282 vvblkd equ $0204 ;VBI deferred vector 283 vdslst equ $0206 ;display list vector 284 vkybdi equ $0208 ;keyboard immediate vector 285 vkybdf equ $020a ;keyboard deferred vector 286 .endif 287 288 ;========================================================================== 289 ; OS INCLUDES (800) 290 ; 291 .ifndef SYS5200 292 = 0010 pokmsk equ $10 293 = 0012 rtclok equ $12 294 = 0058 savmsc equ $58 295 = 006A ramtop equ $6a 296 297 = 0200 vdslst equ $0200 298 = 0208 vkeybd equ $0208 299 = 0216 vimirq equ $0216 300 = 0218 cdtmv1 equ $0218 301 = 0222 vvblki equ $0222 302 = 0224 vvblkd equ $0224 303 = 0226 cdtma1 equ $0226 304 = 022F sdmctl equ $022f 305 = 0230 sdlstl equ $0230 306 = 0231 sdlsth equ $0231 307 = 0232 sskctl equ $0232 308 = 02E0 runad equ $02e0 309 = 02E2 initad equ $02e2 310 = 02E5 memtop equ $02e5 311 = 02F2 ch1 equ $02f2 312 = 02FC ch equ $02fc 313 314 = 0300 ddevic equ $0300 315 = 0301 dunit equ $0301 316 = 0302 dcomnd equ $0302 317 = 0303 dstats equ $0303 318 = 0304 dbuflo equ $0304 319 = 0305 dbufhi equ $0305 320 = 0306 dtimlo equ $0306 321 = 0308 dbytlo equ $0308 322 = 0309 dbythi equ $0309 323 = 030A daux1 equ $030a 324 = 030B daux2 equ $030b 325 326 = 0340 ichid equ $0340 327 = 0342 iccmd equ $0342 328 = 0344 icbal equ $0344 329 = 0345 icbah equ $0345 330 = 0346 icptl equ $0346 331 = 0347 icpth equ $0347 332 = 0348 icbll equ $0348 333 = 0349 icblh equ $0349 334 = 034A icax1 equ $034a 335 = 034B icax2 equ $034b 336 337 = 03F8 basicf equ $03f8 338 339 = E453 dskinv equ $e453 340 = E456 ciov equ $e456 341 = E459 siov equ $e459 342 = E462 xitvbv equ $e462 343 .endif 344 345 ;========================================================================== 346 ; LIBRARY ZP 347 ; 348 = 00C0 a0 equ $c0 349 = 00C2 a1 equ $c2 350 = 00C4 a2 equ $c4 351 = 00C6 a3 equ $c6 352 = 00C8 d0 equ $c8 353 = 00C9 d1 equ $c9 354 = 00CA d2 equ $ca 355 = 00CB d3 equ $cb 356 = 00CC d4 equ $cc 357 = 00CD d5 equ $cd 358 = 00CE d6 equ $ce 359 = 00CF d7 equ $cf 360 361 ;========================================================================== 362 ; LIBRARY VARS 363 ; 364 opt o- 365 366 .ifdef SYS5200 367 opt f- 368 .else 369 .ifdef STANDALONE 370 opt o+ 371 .endif 372 .ifdef GENLIBRARY 373 opt o+ 374 .endif 375 .endif 376 377 .ifdef SYSSAP 378 org $0280 379 .endif 380 381 .ifdef SYS5200 382 org $0280 383 .endif 384 385 .ifdef SYS800 386 org $1a20 387 .endif 388 _intsOff dta 0 389 _scrnOff dta 0 390 _prevIRQ dta a(0) 391 _prevVBI dta a(0) 392 _exitTest dta a(0) 393 _exitTestS dta $ff 394 _vputchar dta a(0) 395 396 .ifdef SYS800 397 _vputunhook dta a(0) 398 .endif 399 400 = 0000 CPUMODE_6502 = 0 401 = 0001 CPUMODE_65C02 = 1 402 = 0080 CPUMODE_65C816_16 = 0x80 403 = 0081 CPUMODE_65C816_24 = 0x81 404 _cpuMode dta 0 405 406 _veronica dta 0 407 408 .ifdef SYS5200 409 sskctl dta 0 410 ch dta 0 411 keydel dta 0 412 413 org $02e0 414 runad dta a(0) 415 initad dta a(0) 416 .endif 417 418 .ifdef SEGS_IN_ROM 419 _lastMod dta 0 420 .endif 421 .ifdef SEGS_MIN_MEM 422 _lastMod dta 0 423 .endif 424 425 .ifdef SYS5200 426 .ifdef STANDALONE 427 opt o+f+ 428 .endif 429 .ifdef GENLIBRARY 430 opt o+f+ 431 .endif 432 433 .ifdef LIBBASE 434 org LIBBASE 435 .else 436 org $4000 437 .endif 438 .endif 439 440 .ifdef SYSSAP 441 org $4000 442 .endif 443 444 ;========================================================================== 445 ; MACROS 446 ; 447 .macro _INITTEST 448 jsr _imTestInit 449 dta :1,0 450 .endm 451 452 .macro _ASSERT1 453 lda :1 454 cmp #:2 455 beq pass 456 457 sta d1 458 jsr _testFailed 459 dta :3,0 460 pass: 461 .endm 462 463 .macro _ASSERT1_DUAL 464 lda :1 465 cmp #:2 466 beq pass 467 cmp #:3 468 beq pass 469 470 sta d1 471 jsr _testFailed 472 dta :4,0 473 pass: 474 .endm 475 476 .macro _ASSERTA 477 cmp #:1 478 beq pass 479 480 sta d1 481 jsr _testFailed 482 dta :2,0 483 pass: 484 .endm 485 486 .macro _ASSERTX 487 cpx #:1 488 beq pass 489 490 stx d1 491 jsr _testFailed 492 dta :2,0 493 pass: 494 .endm 495 496 .macro _ASSERTY 497 cpy #:1 498 beq pass 499 500 sty d1 501 jsr _testFailed 502 dta :2,0 503 pass: 504 .endm 505 506 .macro _FAIL 507 jsr _testFailed 508 dta :1,0 509 .endm 510 511 .macro _SKIP 512 jsr _testSkipped 513 dta :1,0 514 .endm 515 516 .macro _SAP_HEADER 517 .ifdef GENSAP 518 opt o+h-f- 519 org $0700 520 dta c"SAP",$0d,$0a 521 dta c"AUTHOR ",$22,c"Avery Lee",$22,$0d,$0a 522 dta c"NAME ",$22,c":1",$22,$0d,$0a 523 dta c"TYPE D",$0d,$0a 524 dta c"INIT 2000",$0d,$0a 525 dta c"TIME 00:",c"05",$0d,$0a 526 dta a($ffff) 527 .endif 528 .endm 529 530 ;========================================================================== 531 .nowarn .proc _crt0init 532 .ifdef SYSSAP 533 jsr _crt0init_sap 534 .endif 535 536 ;clear zero page and database 537 .ifdef SYS5200 538 ldx #$20 539 lda #0 540 zploop: 541 sta 0,x 542 inx 543 bne zploop 544 ldx #$80 545 dbloop: 546 sta $0200,x 547 inx 548 bne dbloop 549 .endif 550 551 ;clear options (keep in sync with options.s) 552 ldx #6 553 lda #0 554 .ifdef SYS5200 555 sta:rpl $02f0,x- 556 .else 557 sta:rpl $1a00,x- 558 .endif 559 560 ;detect CPU 561 ldy #CPUMODE_6502 562 sed 563 lda #$99 564 clc 565 adc #$01 566 cld 567 bne detdone 568 569 ;we have at least a 65C02... check for 65C816 570 ldy #CPUMODE_65C02 571 572 sec 573 opt c+ 574 rep #$01 575 bcs detdone 576 sep #$01 577 bcc detdone 578 579 ldy #CPUMODE_65C816_16 580 581 ;check for 24-bit addressing 582 lda d3+$10000 583 tax 584 eor #$f5 585 sta d3 586 txa 587 cmp d3+$10000 588 sne 589 iny 590 591 opt c- 592 593 detdone: 594 sty _cpuMode 595 596 .ifdef SYS5200 597 jsr _crt0init_5200 598 .endif 599 600 .ifdef SYS800 601 ;init putchar handler 602 mwa icptl _vputchar 603 inw _vputchar 604 .endif 605 606 rts 607 .endp 608 609 ;========================================================================== 610 .nowarn .proc _interruptsOff 611 lda _intsOff 612 bmi xit 613 sei 614 mwa vimirq _prevIRQ 615 mva #$ff _intsOff 616 xit: 617 rts 618 .endp 619 620 ;========================================================================== 621 .nowarn .proc _interruptsOn 622 lda _intsOff 623 bpl xit 624 sei 625 mwa _prevIRQ vimirq 626 mva pokmsk irqen 627 mva #$00 _intsOff 628 cli 629 xit: 630 rts 631 .endp 632 633 ;========================================================================== 634 .nowarn .proc _screenOn 635 .ifndef SYSSAP 636 lda _scrnOff 637 bpl xit 638 639 jsr _waitVBL 640 641 sei 642 lda #0 643 sta wsync 644 sta nmien 645 mva #$22 dmactl 646 mwa sdlstl dlistl 647 mwa _prevVBI vvblki 648 lda #$40 649 sta nmien 650 cli 651 652 jsr _waitVBL 653 sta wsync 654 sta wsync 655 jsr _waitVBL 656 .endif 657 658 mva #$00 _scrnOff 659 xit: 660 rts 661 .endp 662 663 ;========================================================================== 664 .nowarn .proc _screenOff 665 .ifndef SYSSAP 666 lda _scrnOff 667 bmi xit 668 669 jsr _waitVBL 670 671 php 672 sei 673 lda #0 674 sta wsync 675 sta nmien 676 sta dmactl 677 mwa vvblki _prevVBI 678 plp 679 .endif 680 681 mva #$ff _scrnOff 682 xit: 683 rts 684 .endp 685 686 ;========================================================================== 687 .nowarn .proc _waitVBL 688 lda #123 689 cmp:rne vcount 690 cmp:req vcount 691 rts 692 .endp 693 694 ;========================================================================== 695 .nowarn .proc _waitFrame 696 inc wsync 697 inc wsync 698 jmp _waitVBL 699 .endp 700 701 ;========================================================================== 702 .nowarn .proc _waitKeyPrompt 703 jsr _imprint 704 dta c"Press a key...",0 705 .ifdef SYS5200 706 mva #$ff ch 707 lda:rmi ch 708 .else 709 lda #0 710 sta ch 711 sta ch1 712 lda:req ch 713 .endif 714 jsr _imprint 715 dta $9c,0 716 rts 717 .endp 718 719 ;========================================================================== 720 .nowarn .proc _resetAV 721 lda #0 722 sta gractl 723 sta grafp0 724 sta grafp1 725 sta grafp2 726 sta grafp3 727 sta grafm 728 sta audc1 729 sta audc2 730 sta audc3 731 sta audc4 732 rts 733 .endp 734 735 ;========================================================================== 736 .nowarn .proc _imprint 737 pla 738 tax 739 pla 740 tay 741 inx 742 sne:iny 743 txa 744 jsr _print 745 lda a0+1 746 pha 747 lda a0 748 pha 749 rts 750 .endp 751 752 ;========================================================================== 753 .nowarn .proc _imprintf 754 pla 755 tax 756 pla 757 tay 758 inx 759 sne:iny 760 txa 761 jsr _printf 762 lda a0+1 763 pha 764 lda a0 765 pha 766 rts 767 .endp 768 769 ;========================================================================== 770 .nowarn .proc _print 771 sta a0 772 sty a0+1 773 charloop: 774 ldy #0 775 lda (a0),y 776 beq done 777 inw a0 778 jsr _printf.putbyte 779 jmp charloop 780 done: 781 rts 782 .endp 783 784 ;========================================================================== 785 .nowarn .proc _println 786 jsr _imprint 787 dta $9b,0 788 rts 789 .endp 790 ;========================================================================== 791 .nowarn .proc _printf 792 sta a0 793 sty a0+1 794 ldy #0 795 sty d0 796 charloop: 797 lda (a0),y 798 beq done 799 inw a0 800 cmp #'%' 801 beq special 802 escaped: 803 jsr putbyte 804 nextchar: 805 ldy #0 806 jmp charloop 807 done: 808 rts 809 special: 810 inc d0 811 ldx d0 812 lda (a0),y 813 inw a0 814 cmp #'d' 815 bne notdec 816 tya 817 sty a1 818 ldy #6 819 sei 820 sed 821 decloop1: 822 rol d0,x 823 adc a1 824 sta a1 825 dey 826 bne decloop1 827 sty a1+1 828 ldy #2 829 decloop2: 830 rol d0,x 831 adc a1 832 sta a1 833 rol a1+1 834 dey 835 bne decloop2 836 cld 837 cli 838 lda a1+1 839 beq decdigit2 840 tax 841 lda _hexdig,x 842 jsr putbyte 843 lda a1 844 jsr puthex 845 jmp nextchar 846 decdigit2: 847 lda a1 848 cmp #$10 849 bcc decdigit1 850 jsr puthex 851 jmp nextchar 852 decdigit1: 853 tax 854 lda _hexdig,x 855 jmp escaped 856 857 notdec: 858 cmp #'x' 859 bne nothex 860 lda d0,x 861 jsr puthex 862 jmp nextchar 863 864 nothex: 865 cmp #'X' 866 bne nothexword 867 inc d0 868 lda d1,x 869 jsr puthex 870 ldx d0 871 lda d0-1,x 872 jsr puthex 873 jmp nextchar 874 875 nothexword: 876 cmp #'D' 877 bne notdecword 878 879 ldy #8 880 lda #0 881 sta a1 882 sta a1+1 883 sta a2 884 sei 885 sed 886 decword1: 887 rol d1,x 888 lda a1 889 adc a1 890 sta a1 891 lda a1+1 892 adc a1+1 893 sta a1+1 894 dey 895 bne decword1 896 897 ldy #8 898 decword2: 899 rol d0,x 900 lda a1 901 adc a1 902 sta a1 903 lda a1+1 904 adc a1+1 905 sta a1+1 906 lda a2 907 adc a2 908 sta a2 909 dey 910 bne decword2 911 cld 912 cli 913 914 tax 915 beq decword3 916 jsr puthexcond 917 lda a1+1 918 jsr puthex 919 lda a1 920 jsr puthex 921 jmp nextchar 922 923 decword3: 924 lda a1+1 925 beq decword4 926 lda a1 927 jsr puthex 928 jmp nextchar 929 930 decword4: 931 lda a1 932 jsr puthex 933 jmp nextchar 934 935 notdecword: 936 cmp #'c' 937 bne notchar 938 inc d0 939 lda d0,x 940 jsr putbyte 941 jmp nextchar 942 943 notchar: 944 cmp #'s' 945 bne notstr 946 947 inc d0 948 lda d0,x 949 sta a1 950 lda d0+1,x 951 sta a1+1 952 953 strloop: 954 ldy #0 955 lda (a1),y 956 beq strdone 957 jsr putbyte2 958 inw a1 959 jmp strloop 960 961 strdone: 962 jmp nextchar 963 964 notstr: 965 dec d0 966 jmp escaped 967 968 puthexcond: 969 cmp #$10 970 bcs puthex 971 tax 972 lda _hexdig,x 973 jmp putbyte 974 puthex: 975 pha 976 lsr 977 lsr 978 lsr 979 lsr 980 tax 981 lda _hexdig,x 982 jsr putbyte 983 pla 984 and #$0f 985 tax 986 lda _hexdig,x 987 jmp putbyte 988 989 putbyte: 990 tax 991 jsr putbyte2 992 txa 993 rts 994 995 putbyte2: 996 jmp (_vputchar) 997 .endp 998 999 ;========================================================================== 1000 .nowarn .proc _jam 1001 loop: 1002 jmp loop 1003 .endp 1004 1005 ;========================================================================== 1006 .nowarn .proc _waitVCount 1007 cmp:rne vcount 1008 rts 1009 .endp 1010 1011 ;========================================================================= 1012 .nowarn .proc _imTestInit 1013 pla 1014 sta a0 1015 tay 1016 pla 1017 sta a0+1 1018 1019 inw a0 1020 1021 mva #0 a1 1022 mva a0+1 a1+1 1023 skiploop: 1024 lda (a1),y 1025 beq skipdone 1026 iny 1027 sne:inc a1+1 1028 jmp skiploop 1029 skipdone: 1030 lda a1+1 1031 pha 1032 tya 1033 pha 1034 lda a0 1035 ldy a0+1 1036 jmp _testInit 1037 .endp 1038 1039 ;========================================================================= 1040 .nowarn .proc _testInit 1041 .ifdef STANDALONE 1042 pha 1043 tya 1044 pha 1045 1046 .ifdef SYS800 1047 ;MaxFlash carts run executables with E: closed. Check for this and 1048 ;reopen it if necessary. 1049 lda ichid 1050 bpl iocb0_open 1051 1052 ;reopen IOCB 0 1053 mva #$03 iccmd 1054 mwa #e_name icbal 1055 ldx #0 1056 stx icax1 1057 mva #$0c icax2 1058 jsr ciov 1059 1060 iocb0_open: 1061 .endif 1062 1063 jsr _crt0init 1064 1065 pla 1066 tay 1067 pla 1068 .endif 1069 1070 jsr _print 1071 jsr _imprint 1072 dta c"...",0 1073 1074 .ifdef STANDALONE 1075 mwa #_testEnd _exitTest 1076 .else 1077 :10 nop 1078 .endif 1079 1080 rts 1081 1082 msg: 1083 dta c"...",0 1084 e_name: 1085 dta 'E',$9B 1086 .endp 1087 1088 ;========================================================================= 1089 .nowarn .proc _testEnd 1090 .ifdef SYSSAP 1091 .ifdef STANDALONE 1092 jmp _sap_testEnd 1093 .else 1094 jmp _jam 1095 .endif 1096 .else 1097 .ifdef SYS5200 1098 jmp _jam 1099 .else 1100 ;wait for key 1101 sei 1102 lda #0 1103 sta nmien 1104 sta irqen 1105 mva #3 skctl 1106 mva #$40 irqen 1107 bit:rne irqst 1108 1109 ;initiate soft reset 1110 jmp ($fffc) 1111 .endif 1112 .endif 1113 .endp 1114 1115 ;========================================================================= 1116 .nowarn .proc _testRestore 1117 cld 1118 php 1119 sei 1120 1121 ;check if the screen is off; if so, make sure we kill DLIs 1122 lda _scrnOff 1123 beq scrnOK 1124 1125 lda #0 1126 inc wsync 1127 sta nmien 1128 1129 scrnOK: 1130 1131 mva sskctl skctl 1132 1133 .ifdef SYSSAP 1134 ;kill PIA port A interrupt 1135 mva #$3c pactl 1136 1137 ;force kernel ROMs back _out_ 1138 mva #$38 pbctl 1139 mva #$ff portb 1140 mva #$3c pbctl 1141 mva #$82 portb 1142 .endif 1143 1144 .ifdef SYS5200 1145 mva #$00 prior 1146 mva #$f8 chbase 1147 mva #$02 chactl 1148 mva #$04 consol 1149 .endif 1150 1151 .ifdef SYS800 1152 ;kill PIA port A interrupt 1153 mva #$3c pactl 1154 1155 ;force kernel ROMs back in 1156 mva #$38 pbctl 1157 mva #$00 portb 1158 mva #$3c pbctl 1159 mva #$83 portb 1160 1161 ;kill OS timer 1 1162 ldx #$ff 1163 stx wsync 1164 stx cdtmv1 1165 inx 1166 stx cdtmv1 1167 stx cdtmv1+1 1168 .endif 1169 1170 plp 1171 jsr _interruptsOn 1172 jsr _screenOn 1173 jsr _resetAV 1174 1175 ;unmask interrupts 1176 cli 1177 rts 1178 .endp 1179 1180 ;========================================================================= 1181 .nowarn .proc _testPassed 1182 jsr _testRestore 1183 1184 jsr _imprint 1185 dta c"Pass",$9b,0 1186 1187 ldx _exitTestS 1188 txs 1189 ldy #0 1190 jmp (_exitTest) 1191 .endp 1192 1193 ;========================================================================= 1194 .nowarn .proc _testFailed 1195 jsr _testRestore 1196 1197 jsr _imprint 1198 dta c"FAIL.",$9b,0 1199 1200 nomsgentry: 1201 pla 1202 tax 1203 pla 1204 tay 1205 inx 1206 sne:iny 1207 txa 1208 jsr _printf 1209 jsr _println 1210 1211 ldx _exitTestS 1212 txs 1213 ldy #$80 1214 jmp (_exitTest) 1215 1216 msg2: 1217 dta $9b,0 1218 .endp 1219 1220 ;========================================================================= 1221 .nowarn .proc _testFailed2 1222 jsr _testRestore 1223 jmp _testFailed.nomsgentry 1224 .endp 1225 1226 ;========================================================================= 1227 .nowarn .proc _testSkipped 1228 jsr _testRestore 1229 1230 jsr _imprint 1231 dta c"Skipped",$9b,0 1232 1233 pla 1234 tax 1235 pla 1236 tay 1237 inx 1238 sne:iny 1239 txa 1240 jsr _printf 1241 1242 jsr _println 1243 1244 ldx _exitTestS 1245 txs 1246 ldy #$40 1247 jmp (_exitTest) 1248 .endp 1249 1250 ;========================================================================== 1251 ; _loadSeg() 1252 ; 1253 ; Module loader. 1254 ; 1255 ; X = index of module to load 1256 ; 1257 .ifdef SEGS_MIN_MEM 1258 .nowarn .proc _loadSeg 1259 ;get starting sector 1260 mva segaddrlo,x daux1 1261 mva segaddrhi,x daux2 1262 1263 ;get ending sector 1264 lda segaddrlo+1,x 1265 sub daux1 1266 sta d7 1267 1268 ;setup sector load command and relocation 1269 mva #'R' dcomnd 1270 mva #1 dunit 1271 lda #$00 1272 sta dbuflo 1273 sta a0 1274 sta runad+1 1275 lda #$0b 1276 sta dbufhi 1277 sta a0+1 1278 1279 ;preload first two sectors 1280 jsr step_sector 1281 relocloop: 1282 ;load starting address 1283 mva (a0),y a1 1284 iny:sne:jsr step_sector 1285 mva (a0),y a1+1 1286 iny:sne:jsr step_sector 1287 1288 ;skip $ffff words 1289 lda a1 1290 and a1+1 1291 cmp #$ff 1292 beq relocloop 1293 1294 ;load ending address 1295 mva (a0),y a2 1296 iny:sne:jsr step_sector 1297 mva (a0),y a2+1 1298 iny:sne:jsr step_sector 1299 inw a2 1300 1301 mwa #definit initad 1302 1303 ;copy data (slow, but oh well) 1304 ldx #0 1305 copyloop: 1306 lda (a0),y 1307 sta (a1,x) 1308 iny:sne:jsr step_sector 1309 inw a1 1310 lda a1 1311 cmp a2 1312 bne copyloop 1313 lda a1+1 1314 cmp a2+1 1315 bne copyloop 1316 1317 ;init a segment 1318 jsr doinit 1319 1320 ;check if we're done 1321 lda runad+1 1322 beq relocloop 1323 rts 1324 1325 doinit: 1326 jmp (initad) 1327 1328 step_sector: 1329 lda d7 1330 beq no_sectors_left 1331 jsr dskinv 1332 dec d7 1333 inw daux1 1334 lda dbuflo 1335 eor #$80 1336 sta dbuflo 1337 bne step_sector 1338 no_sectors_left: 1339 ldy #0 1340 ldx #0 1341 definit: 1342 rts 1343 .endp 1344 .else 1345 .nowarn .proc _loadSeg 1346 .ifdef SEGS_IN_ROM 1347 stx _lastMod 1348 rts 1349 .else 1350 ;get starting sector 1351 mva segaddrlo,x daux1 1352 mva segaddrhi,x daux2 1353 1354 ;get ending sector 1355 mva segaddrlo+1,x a0 1356 mva segaddrhi+1,x a0+1 1357 1358 ;load sectors starting at $4000 1359 sectorloop: 1360 mva #'R' dcomnd 1361 mva #1 dunit 1362 mwa #$4000 dbuflo 1363 1364 jsr dskinv 1365 tya 1366 bmi sectorloop 1367 1368 lda #$80 1369 eor dbuflo 1370 sta dbuflo 1371 sne:inc dbufhi 1372 1373 inc daux1 1374 sne:inc daux2 1375 1376 lda daux1 1377 cmp a0 1378 bne sectorloop 1379 lda daux2 1380 cmp a0+1 1381 bne sectorloop 1382 rts 1383 .endif 1384 .endp 1385 .endif 1386 1387 ;========================================================================== 1388 ; _runSeg() 1389 ; 1390 ; Module relocator and executor. 1391 ; 1392 ; The last segment loaded by _loadSeg() is relocated and executed. 1393 ; 1394 1395 .ifdef SEGS_MIN_MEM 1396 1397 ;----------------------------------------------- 1398 ; Minimum memory implementation. 1399 .nowarn .proc _runSeg 1400 jmp (runad) 1401 .endp 1402 1403 .else 1404 1405 ;----------------------------------------------- 1406 .nowarn .proc _runSeg 1407 1408 ;begin relocation 1409 mwa #relocloop runad 1410 1411 .ifdef SEGS_IN_ROM 1412 ldx _lastMod 1413 mva segaddrlo,x a0 1414 mva segaddrhi,x a0+1 1415 .else 1416 mwa #$4000 a0 1417 .endif 1418 1419 .ifndef SEGS_LZPACK 1420 1421 ;==== uncompressed version 1422 1423 ldy #0 1424 relocloop: 1425 ;load starting address 1426 mva (a0),y a1 1427 inw a0 1428 mva (a0),y a1+1 1429 inw a0 1430 1431 ;skip $ffff words 1432 lda a1 1433 and a1+1 1434 cmp #$ff 1435 beq relocloop 1436 1437 ;load ending address 1438 mva (a0),y a2 1439 inw a0 1440 mva (a0),y a2+1 1441 inw a0 1442 inw a2 1443 1444 ;copy data (slow, but oh well) 1445 copyloop: 1446 lda (a0),y 1447 sta (a1),y 1448 inw a0 1449 inw a1 1450 lda a1 1451 cmp a2 1452 bne copyloop 1453 lda a1+1 1454 cmp a2+1 1455 bne copyloop 1456 1457 ;init a segment 1458 mwa #definit initad 1459 jsr doinit 1460 jmp (runad) 1461 1462 doinit: 1463 jmp (initad) 1464 1465 definit: 1466 rts 1467 1468 .else 1469 1470 ;==== compressed version 1471 ; 1472 ;loader: 1473 ; a3 destination 1474 ; d6/d7 segment end address 1475 ; 1476 ;decompressor: 1477 ; a0 raw source stream 1478 ; a1 run source pointer 1479 ; a2 window pointer ($1000-1fff) 1480 ; d0 literal/run flag bits 1481 ; d1 remaining flag bits shifter 1482 ; d2 run length counter 1483 ; d3 temporary 1484 ; d4 superflag bits 1485 ; d5 superflag shifter 1486 1487 lda #0 1488 sta d0 1489 sta d1 1490 sta d2 1491 sta d5 1492 sta a2 1493 lda #$10 1494 sta a2+1 1495 relocloop: 1496 ldy #0 1497 ;load starting address 1498 jsr getbyte 1499 sta a3 1500 jsr getbyte 1501 sta a3+1 1502 1503 ;skip $ffff words 1504 and a3 1505 cmp #$ff 1506 beq relocloop 1507 1508 ;load ending address 1509 jsr getbyte 1510 sta d6 1511 jsr getbyte 1512 sta d7 1513 inw d6 1514 1515 ;copy data (slow, but oh well) 1516 copyloop: 1517 jsr getbyte 1518 sta (a3),y 1519 inw a3 1520 lda a3 1521 cmp d6 1522 bne copyloop 1523 lda a3+1 1524 cmp d7 1525 bne copyloop 1526 1527 ;init a segment 1528 mwa #definit initad 1529 jsr doinit 1530 jmp (runad) 1531 1532 doinit: 1533 jmp (initad) 1534 1535 getbyte: 1536 ;check if we have a run in progress 1537 lda d2 1538 bne getrunbyte 1539 1540 ;check if we need to reload flag bits 1541 asl d1 1542 bne havebits 1543 1544 ;check if we need to reload superflag bits 1545 asl d5 1546 bne havesuperbits 1547 1548 ;load next superflag byte 1549 jsr getrawbyte 1550 sta d4 1551 lda #$7f 1552 sta d5 1553 1554 havesuperbits: 1555 ;pull next superflag and check if it's all literals (0) 1556 asl d4 1557 bcc all_literals 1558 1559 ;nope... read next byte as flags byte 1560 jsr getrawbyte 1561 sta d0 1562 1563 all_literals: 1564 lda #$7f 1565 sta d1 1566 havebits: 1567 asl d0 1568 bcs isrun 1569 1570 ;store byte into window 1571 jsr getrawbyte 1572 jmp putwinbyte 1573 1574 isrun: 1575 ;load offset/run bytes 1576 jsr getrawbyte 1577 sta d3 1578 jsr getrawbyte 1579 sta d2 1580 1581 ;compute run source from current position and offset 1582 lda a2 1583 clc 1584 sbc d3 1585 sta a1 1586 lda a2+1 1587 sbc d2 1588 and #$0f 1589 ora #$10 1590 sta a1+1 1591 1592 ;compute length and stash run length 1593 lda d2 1594 lsr 1595 lsr 1596 lsr 1597 lsr 1598 add #3 1599 sta d2 1600 getrunbyte: 1601 dec d2 1602 ldy #0 1603 lda (a1),y 1604 inc a1 1605 bne putwinbyte 1606 inc a1+1 1607 pha 1608 lda a1+1 1609 and #$0f 1610 ora #$10 1611 sta a1+1 1612 pla 1613 jmp putwinbyte 1614 1615 getrawbyte: 1616 lda (a0),y 1617 inw a0 1618 rts 1619 1620 putwinbyte: 1621 sta (a2),y 1622 inc a2 1623 seq:rts 1624 ldy a2+1 1625 iny 1626 cpy #$20 1627 sne:ldy #$10 1628 sty a2+1 1629 ldy #0 1630 definit: 1631 rts 1632 1633 .endif 1634 .endp 1635 .endif 1636 1637 ;========================================================================== 1638 _hexdig dta c"0123456789ABCDEF" 1639 1640 ;========================================================================== 1641 ; segment table 1642 ; 1643 .ifndef SYS800 1644 segaddrlo equ $bf00 1645 segaddrhi equ $bf80 1646 .else 1647 = 1900 segaddrlo equ $1900 1648 = 1980 segaddrhi equ $1980 1649 .endif 1650 1651 = 0900 _veronicaLaunch = $0900 1652 1653 ;========================================================================== 1654 ; platform-specific library 1655 ; 1656 .ifdef SYS5200 1657 icl 'lib5200.s' 1658 .endif 1659 .ifdef SYSSAP 1660 icl 'libsap.s' 1661 .endif 1662 1663 ;========================================================================== 1664 .ifndef STANDALONE 1665 .ifdef SYS5200 1666 opt o+ 1667 .else 1668 opt h+o+ 1669 .endif 1670 .endif 25 26 org $e0 27 FFFF> 00E0-00EB> 00 row dta 0 28 00E1 00 col dta 0 29 00E2 00 00 rowptr1 dta a(0) 30 00E4 00 00 rowptr2 dta a(0) 31 00E6 00 00 chaddr dta a(0) 32 00E8 00 cha dta 0 33 00E9 00 chb dta 0 34 00EA 00 rowcntr dta 0 35 00EB 00 mask dta 0 36 37 ;========================== NON-RESIDENT SECTION ========================== 38 39 00EC org $2000 40 41 2000 .proc main 42 ;check if we have a cartridge 43 2000-2109> AD 00 A0 lda $a000 44 2003 AA tax 45 2004 49 FF eor #$ff 46 2006 8D 00 A0 sta $a000 47 2009 CD 00 A0 cmp $a000 48 200C 8E 00 A0 stx $a000 49 200F F0 50 beq mem_ok 50 51 ;check if we have an XL or newer 52 2011 AD D8 FC lda $fcd8 53 2014 C9 A2 cmp #$a2 54 2016 D0 03 4C A3 20 sne:jmp damn_cart 55 56 ;check if BASIC is enabled 57 201B AD F8 03 lda basicf 58 201E F0 03 4C A3 20 seq:jmp damn_cart 59 60 ;see if we can disable basic 61 2023 AD 03 D3 lda pbctl 62 2026 AA tax 63 2027 29 FB and #$fb ;switch to DDR 64 2029 8D 03 D3 sta pbctl 65 202C AD 01 D3 lda portb ;read DDR 66 202F 29 02 and #$02 ;test BASIC bit 67 2031 F0 6D beq damn_cart_pbres ;set to input, so can't be BASIC 68 2033 8A txa 69 2034 09 04 ora #$04 ;switch to IOR 70 2036 8D 03 D3 sta pbctl 71 2039 AD 01 D3 lda portb ;read IOR 72 203C 29 02 and #$02 ;test BASIC bit 73 203E D0 60 bne damn_cart_pbres ;set to high, so can't be BASIC 74 2040 AD 01 D3 lda portb ;read IOR 75 2043 09 02 ora #$02 ;clear BASIC bit (enable BASIC) 76 2045 8D 01 D3 sta portb 77 2048 8A txa 78 2049 29 FB and #$fb ;switch to DDR 79 204B 8D 03 D3 sta pbctl 80 204E AD 01 D3 lda portb ;read DDR 81 2051 09 02 ora #$02 ;enable BASIC bit for output 82 2053 8D 01 D3 sta portb 83 2056 8E 03 D3 stx pbctl ;restore control mode 84 85 2059 A9 FF 8D F8 03 mva #$ff basicf ;mark basic as not enabled in OS 86 205E 4C 00 20 jmp main ;restart 87 88 2061 mem_ok: 89 ;create new display list and clear screen memory 90 2061 20 89 91 jsr rewriteDisplayList 91 2064 20 F2 91 jsr clearScreen 92 93 ;swap in new display list 94 2067 78 sei 95 2068 A9 00 8D 30 02 A9 + mwa #dlist1 sdlstl 96 2072 A9 13 8D 24 02 A9 + mwa #vbiHandler vvblkd 97 207C 58 cli 98 99 ;wait for vertical blank 100 207D 20 1F 1B jsr _waitVBL 101 102 ;init params 103 2080 A9 00 85 E0 mva #0 row 104 2084 A9 02 85 E1 mva #2 col 105 2088 20 CF 90 jsr recompRowAddr 106 107 ;replace putchar vector 108 208B A9 0D 8D 29 1A A9 + mwa #putchar80 _vputchar 109 2095 A9 00 8D 2B 1A A9 + mwa #unhook80 _vputunhook 110 209F 60 rts 111 112 20A0 damn_cart_pbres: 113 20A0 8E 03 D3 stx pbctl 114 20A3 damn_cart: 115 20A3 20 7B 1B jsr _imprint 116 20A6 43 61 6E 6E 6F 74 + dta c"Cannot enter 80 column mode because a cartridge is present or there is no memory at $A000-BFFF.",$9B,0 117 2107 4C 35 1B jmp _waitKeyPrompt 118 119 .endp 120 121 ;============================ RESIDENT SECTION ============================ 122 210A org $9000 123 124 9000 .proc unhook80 125 9000-924D> 78 sei 126 9001 A9 62 8D 24 02 A9 + mwa #xitvbv vvblkd 127 900B 58 cli 128 900C 60 rts 129 .endp 130 131 900D .proc putchar80 132 900D 85 E8 sta cha 133 900F 98 tya 134 9010 48 pha 135 136 9011 20 5C 91 jsr toggleCursor80 137 138 9014 A5 E8 lda cha 139 140 ;check for newline 141 9016 C9 9B cmp #$9b 142 9018 F0 30 beq newline 143 144 ;check for clear line 145 901A C9 9C cmp #$9c 146 901C F0 26 beq isclearline 147 148 ;check for clear screen 149 901E C9 7D cmp #$7d 150 9020 F0 11 beq isclearscrn 151 152 ;draw raw character 153 9022 20 E4 90 jsr putraw80 154 155 ;update position and exit 156 9025 E6 E1 inc col 157 9027 A5 E1 lda col 158 9029 C9 4E cmp #78 159 902B B0 1D bcs newline 160 902D alldone: 161 902D 20 5C 91 jsr toggleCursor80 162 163 9030 68 pla 164 9031 A8 tay 165 9032 60 rts 166 167 9033 isclearscrn: 168 9033 20 F2 91 jsr clearScreen 169 9036 A9 00 85 E0 mva #0 row 170 903A A9 02 85 E1 mva #2 col 171 903E 20 CF 90 jsr recompRowAddr 172 9041 4C 2D 90 jmp alldone 173 174 9044 isclearline: 175 9044 20 63 90 jsr clearLine 176 9047 4C 2D 90 jmp alldone 177 178 904A newline: 179 ;reset X position 180 904A A9 02 85 E1 mva #2 col 181 182 ;increment Y position 183 904E E6 E0 inc row 184 185 ;check if we've gone over 186 9050 A5 E0 lda row 187 9052 C9 18 cmp #24 188 9054 90 07 bcc noscroll 189 190 ;whoops... looks like we'll have to scroll 191 9056 A9 17 85 E0 mva #23 row 192 905A 20 7E 90 jsr scroll80 193 194 905D noscroll: 195 905D 20 CF 90 jsr recompRowAddr 196 9060 4C 2D 90 jmp alldone 197 .endp 198 199 ;========================================================================== 200 9063 .proc clearLine 201 9063 A9 00 lda #0 202 9065 A2 08 ldx #8 203 9067 xloop: 204 9067 A0 28 ldy #40 205 9069 yloop: 206 9069 91 E2 sta (rowptr1),y 207 906B 91 E4 sta (rowptr2),y 208 906D 88 dey 209 906E D0 F9 bne yloop 210 9070 E6 E3 inc rowptr1+1 211 9072 E6 E5 inc rowptr2+1 212 9074 CA dex 213 9075 D0 F0 bne xloop 214 215 9077 A9 02 85 E1 mva #2 col 216 217 907B 4C CF 90 jmp recompRowAddr 218 .endp 219 220 ;========================================================================== 221 907E .proc scroll80 222 ;rotate row lines 223 907E AD 1E 92 lda rowaddrlo 224 9081 48 pha 225 9082 AD 36 92 lda rowaddrhi 226 9085 48 pha 227 228 9086 A2 E9 ldx #$e9 229 9088 shiftloop: 230 9088 BD 36 91 lda rowaddrlo-$e8,x 231 908B 9D 35 91 sta rowaddrlo-$e9,x 232 908E BD 4E 91 lda rowaddrhi-$e8,x 233 9091 9D 4D 91 sta rowaddrhi-$e9,x 234 9094 E8 inx 235 9095 D0 F1 bne shiftloop 236 237 9097 68 pla 238 9098 8D 4D 92 sta rowaddrhi+23 239 909B 68 pla 240 909C 8D 35 92 sta rowaddrlo+23 241 242 ;remake display list 243 909F 20 89 91 jsr rewriteDisplayList 244 245 ;clear row 23 246 90A2 AD 4D 92 lda rowaddrhi+23 247 90A5 09 60 ora #$60 248 90A7 85 E3 sta rowptr1+1 249 90A9 49 C0 eor #$c0 250 90AB 85 E5 sta rowptr2+1 251 90AD AD 35 92 lda rowaddrlo+23 252 90B0 85 E2 sta rowptr1 253 90B2 85 E4 sta rowptr2 254 255 90B4 A9 00 lda #0 256 90B6 A2 08 ldx #8 257 90B8 yloop: 258 90B8 A0 27 ldy #39 259 90BA xloop: 260 90BA 91 E2 sta (rowptr1),y 261 90BC 91 E4 sta (rowptr2),y 262 90BE 88 dey 263 90BF 10 F9 bpl xloop 264 90C1 E6 E3 inc rowptr1+1 265 90C3 E6 E5 inc rowptr2+1 266 90C5 CA dex 267 90C6 D0 F0 bne yloop 268 269 90C8 A9 17 lda #23 270 90CA 85 E0 sta row 271 90CC 4C CF 90 jmp recompRowAddr 272 .endp 273 274 ;========================================================================== 275 90CF .proc recompRowAddr 276 90CF A6 E0 ldx row 277 90D1 BD 1E 92 lda rowaddrlo,x 278 90D4 85 E2 sta rowptr1 279 90D6 85 E4 sta rowptr2 280 90D8 BD 36 92 lda rowaddrhi,x 281 90DB 09 60 ora #$60 282 90DD 85 E3 sta rowptr1+1 283 90DF 49 C0 eor #$c0 284 90E1 85 E5 sta rowptr2+1 285 90E3 60 rts 286 .endp 287 288 ;========================================================================== 289 90E4 .proc putraw80 290 ;convert to internal encoding 291 90E4 48 pha 292 90E5 4A lsr 293 90E6 4A lsr 294 90E7 4A lsr 295 90E8 4A lsr 296 90E9 4A lsr 297 90EA 29 03 and #3 298 90EC AA tax 299 90ED 68 pla 300 90EE 5D 58 91 eor convtab,x 301 302 ;compute character address 303 90F1 2A rol 304 90F2 2A rol 305 90F3 2A rol 306 90F4 AA tax 307 90F5 29 F8 and #$f8 308 90F7 85 E6 sta chaddr 309 90F9 8A txa 310 90FA 2A rol 311 90FB 29 03 and #$03 312 90FD 09 E0 ora #$e0 313 90FF 85 E7 sta chaddr+1 314 315 ;start row loop 316 9101 A9 00 lda #0 317 9103 85 EA sta rowcntr 318 9105 rowloop: 319 ;convert a row 320 9105 A4 EA ldy rowcntr 321 9107 B1 E6 lda (chaddr),y 322 9109 0A asl 323 910A A2 04 ldx #4 324 910C bitloop: 325 910C 6A ror 326 910D 66 E8 ror cha 327 910F 6A ror 328 9110 66 E9 ror chb 329 9112 CA dex 330 9113 D0 F7 bne bitloop 331 332 ;shift down if needed 333 9115 A5 E1 lda col 334 9117 A2 F0 ldx #$f0 335 9119 4A lsr 336 911A A8 tay 337 911B 90 0B bcc leftside 338 339 911D A2 04 ldx #4 340 911F shiftloop: 341 911F 46 E8 lsr cha 342 9121 46 E9 lsr chb 343 9123 CA dex 344 9124 D0 F9 bne shiftloop 345 9126 A2 0F ldx #$0f 346 9128 leftside: 347 348 ;merge in character 349 9128 86 EB stx mask 350 351 912A B1 E2 lda (rowptr1),y 352 912C 45 E8 eor cha 353 912E 25 EB and mask 354 9130 51 E2 eor (rowptr1),y 355 9132 91 E2 sta (rowptr1),y 356 9134 E6 E3 inc rowptr1+1 357 358 9136 B1 E4 lda (rowptr2),y 359 9138 45 E9 eor chb 360 913A 25 EB and mask 361 913C 51 E4 eor (rowptr2),y 362 913E 91 E4 sta (rowptr2),y 363 9140 E6 E5 inc rowptr2+1 364 365 ;do more rows 366 9142 E6 EA inc rowcntr 367 9144 A5 EA lda rowcntr 368 9146 C9 08 cmp #8 369 9148 D0 BB bne rowloop 370 371 ;restore row pointers 372 914A 38 sec 373 914B A5 E3 lda rowptr1+1 374 914D E9 08 sbc #$08 375 914F 85 E3 sta rowptr1+1 376 9151 A5 E5 lda rowptr2+1 377 9153 E9 08 sbc #$08 378 9155 85 E5 sta rowptr2+1 379 380 ;all done 381 9157 60 rts 382 383 9158 convtab: 384 9158 40 dta $40 385 9159 20 dta $20 386 915A 60 dta $60 387 915B 00 dta $00 388 389 .endp 390 391 ;========================================================================== 392 915C .proc toggleCursor80 393 915C A2 08 ldx #8 394 915E A5 E1 lda col 395 9160 4A lsr 396 9161 A8 tay 397 9162 A9 F0 lda #$f0 398 9164 90 02 A9 0F scc:lda #$0f 399 9168 85 E9 sta chb 400 916A loop: 401 916A B1 E2 lda (rowptr1),y 402 916C 45 E9 eor chb 403 916E 91 E2 sta (rowptr1),y 404 9170 B1 E4 lda (rowptr2),y 405 9172 45 E9 eor chb 406 9174 91 E4 sta (rowptr2),y 407 9176 E6 E3 inc rowptr1+1 408 9178 E6 E5 inc rowptr2+1 409 917A CA dex 410 917B D0 ED bne loop 411 917D A5 E3 lda rowptr1+1 412 917F 38 sec 413 9180 E9 08 sbc #$08 414 9182 85 E3 sta rowptr1+1 415 9184 49 C0 eor #$c0 416 9186 85 E5 sta rowptr2+1 417 9188 60 rts 418 .endp 419 420 ;========================================================================= 421 9189 .proc rewriteDisplayList 422 9189 A9 00 lda #0 423 918B 85 E2 sta rowptr1 424 918D 85 E4 sta rowptr2 425 918F A9 98 85 E3 mva #>dlist1 rowptr1+1 426 9193 A9 9C 85 E5 mva #>dlist2 rowptr2+1 427 9197 A0 00 ldy #0 428 9199 A2 00 ldx #0 429 430 ;24 blank lines 431 919B A9 70 lda #$70 432 919D 20 E6 91 jsr putbyte 433 91A0 20 E6 91 jsr putbyte 434 91A3 20 E6 91 jsr putbyte 435 436 ;192 LMS lines 437 91A6 lineloop: 438 91A6 A9 00 85 E8 mva #0 cha 439 91AA rowloop: 440 91AA A9 4F lda #$4F 441 91AC 20 E6 91 jsr putbyte 442 91AF BD 1E 92 lda rowaddrlo,x 443 91B2 20 E6 91 jsr putbyte 444 91B5 BD 36 92 lda rowaddrhi,x 445 91B8 18 clc 446 91B9 65 E8 adc cha 447 91BB 09 60 ora #$60 448 91BD 91 E2 sta (rowptr1),y 449 91BF 49 C0 eor #$c0 450 91C1 91 E4 sta (rowptr2),y 451 91C3 20 EA 91 jsr putbyte1 452 91C6 E6 E8 inc cha 453 91C8 A5 E8 lda cha 454 91CA C9 08 cmp #8 455 91CC D0 DC bne rowloop 456 91CE E8 inx 457 91CF E0 18 cpx #24 458 91D1 D0 D3 bne lineloop 459 460 ;add wait for VBL insn 461 91D3 A9 41 lda #$41 462 91D5 20 E6 91 jsr putbyte 463 91D8 A9 00 lda #dlist2 466 91DF 91 E2 sta (rowptr1),y 467 91E1 A9 98 lda #>dlist1 468 91E3 91 E4 sta (rowptr2),y 469 91E5 60 rts 470 471 91E6 putbyte: 472 91E6 91 E2 sta (rowptr1),y 473 91E8 91 E4 sta (rowptr2),y 474 91EA putbyte1: 475 91EA C8 iny 476 91EB D0 04 bne putbyte2 477 91ED E6 E3 inc rowptr1+1 478 91EF E6 E5 inc rowptr2+1 479 91F1 putbyte2: 480 91F1 60 rts 481 .endp 482 483 ;========================================================================= 484 91F2 .proc clearScreen 485 91F2 A9 60 lda #$60 486 91F4 85 E3 sta rowptr1+1 487 91F6 A9 A0 lda #$a0 488 91F8 85 E5 sta rowptr2+1 489 91FA A9 00 lda #0 490 91FC 85 E2 sta rowptr1 491 91FE 85 E4 sta rowptr2 492 9200 A2 20 ldx #$20 493 9202 xloop: 494 9202 A0 00 ldy #0 495 9204 yloop: 496 9204 91 E2 sta (rowptr1),y 497 9206 91 E4 sta (rowptr2),y 498 9208 C8 iny 499 9209 D0 F9 bne yloop 500 920B E6 E3 inc rowptr1+1 501 920D E6 E5 inc rowptr2+1 502 920F CA dex 503 9210 D0 F0 bne xloop 504 9212 60 rts 505 .endp 506 507 ;========================================================================= 508 9213 .proc vbiHandler 509 9213 AD 31 02 lda sdlsth 510 9216 49 04 eor #$04 511 9218 8D 31 02 sta sdlsth 512 921B 4C 62 E4 jmp xitvbv 513 .endp 514 ;========================================================================= 515 ; We use a bit of a screwed up memory layout here, reminiscent of the 516 ; Apple II. Six lines are packed at a time into a page, and four pages 517 ; make up one row across all 24 lines. The row pages are arranged such 518 ; stepping down a character row simply involves incrementing the high 519 ; byte. 520 ; 521 921E rowaddrlo: 522 921E 00 28 50 78 A0 C8 + :4 dta $00, $28, $50, $78, $a0, $c8 523 524 9236 rowaddrhi: 525 9236 00 00 00 00 00 00 :6 dta $00 526 923C 08 08 08 08 08 08 :6 dta $08 527 9242 10 10 10 10 10 10 :6 dta $10 528 9248 18 18 18 18 18 18 :6 dta $18 529 530 ;========================================================================= 531 532 = 9800 dlist1 equ $9800 533 = 9C00 dlist2 equ $9c00 534 535 02E0-02E1> 00 20 run main 536 end