3D-Demo - Source Code V.1.61

Example Code 3D-Demo V.1.61

3D-Demo:right

The following source code resembles V.1.61 of the 3D-Demo from May 2017 and gives all the necessary insights in basic 3D-algorithm design back in the days.

Following versions of the demo kept the basic calculation routines and just got some new features concerning object data handling and soundtrack playback.







   1********************************
   2*           3D-DEMO            *
   3*                              *
   4*      BY MARC GOLOMBECK       *
   5*                              *
   6*   VERSION 1.61 / 07.05.2017  *
   7*                              *
   8* NEEDS THE FOLLOWING DATA     *
   9* ALREADY LOADED INTO MEMORY:  *
  10*                              *
  11* $7000: SINE/COSINE-TABLE     *
  12* $7200: POINT AND LINE DATA   *
  13* $7400: SHAPE TABLE           *
  14* $7A00: MULTIPLICATION TABLE  *
  15* $8200: PROJECTION TABLE      *
  16*                              *
  17* CONTROLLED VIA JOYSTICK AND  *
  18* KEYBOARD:                    *
  19*                              *
  20* PDL(0/1): ROTATION+ZOOM      *
  21* PBN(0/1): RESET+STOP/EXIT    *
  22* KEYS 1-5: CHOOSE 3D-OBJECT   *
  23* KEYS +/-: ALTERNATE ZOOM     *
  24* KEY B   : TOGGLE BENCHMARK   *
  25* KEY Q   : QUIT PROGRAM       *
  26*                              *
  27********************************
  28*
  29               ORG   $6000
  30*
  31HGR2           EQU   $F3D8      ; SWITCH TO HIRES2
  32HGR            EQU   $F3E2      ; SWITCH TO HIRES1
  33HCLR           EQU   $F3F2      ; CLEAR HIRES SCREEN TO BLACK1
  34HCOLOR         EQU   $F6F0      ; SET HCOLOR
  35HPOSN          EQU   $F411      ; SET HIRES-CURSOR NO DRAW
  36HPLOT          EQU   $F457      ; DRAW HIRES-PIXEL
  37HLIN           EQU   $F53A      ; DRAW HIRES-LINE
  38PREAD          EQU   $FB1E      ; READ PADDLES
  39PB0            EQU   $C061      ; PUSH-BUTTON 0
  40PB1            EQU   $C062      ; PUSH-BUTTON 1
  41PB2            EQU   $C063      ; PUSH-BUTTON 2
  42HOME           EQU   $FC58      ; CLEAR SCREEN
  43COUT           EQU   $FDED      ; PRINT CHARACTER
  44KYBD           EQU   $C000      ; READ KEYBOARD
  45STROBE         EQU   $C010      ; CLEAR KEYBOARD
  46SHNUM          EQU   $F730      ; GET ADRESS OF SHAPE NUMBER
  47SHDRAW         EQU   $F605      ; DRAW SHAPE ON SCREEN
  48BELL           EQU   $FBDD      ; RING BELL
  49WAIT           EQU   $FCA8      ; WAIT A BIT
  50*
  51SINTAB         EQU   $7000      ; BASE ADRESS OF SINE TABLE
  52COSTAB         EQU   $7040      ; BASE ADRESS OF COSINE TABLE
  53NUMPNT         EQU   $7200      ; NUMBER OF POINTS TO DRAW
  54TABLE          EQU   $7201      ; BASE ADRESS FOR POINT TABLE
  55SHTAB          EQU   $7400      ; BASE ADRESS OF SHAPES-68
  56SSQLO          EQU   $7A00      ; MULT TAB PART 1
  57SSQHI          EQU   $7C00      ; MULT TAB PART 2
  58DSQLO          EQU   $7E00      ; MULT TAB PART 3
  59DSQHI          EQU   $8000      ; MULT TAB PART 4
  60PROJTAB        EQU   $8200      ; PROJECTION TAB
  61YLOOKLO        EQU   $8300      ; LOOKUP LINE BASE ADRESS
  62EVENCOL        EQU   $83C0      ; APPLESOFT CODE EVEN COLORS
  63ODDCOL         EQU   $83C8      ; APPLESOFT CODE UNEVEN COLORS
  64XORMASK        EQU   $83D0      ; PIXEL MASK
  65ANDMASK        EQU   $83D8      ; PIXEL MASK
  66LEMASK         EQU   $83DF
  67RIMASK         EQU   $83E6
  68YLOOKHI        EQU   $83ED      ; LOOK LINE BASE ADRESS
  69COLLINE        EQU   $84AD
  70DIV7HI         EQU   $84D5      ; DIVISION BY 7 TABLE
  71MOD7HI         EQU   $84ED      ; DIVISION BY 7 TABLE
  72DIV7LO         EQU   $8505      ; DIVISION BY 7 TABLE
  73MOD7LO         EQU   $8605      ; DIVISION BY 7 TABLE
  74*
  75XTRANS         EQU   $8B        ; X-TRANSLATION CENTER SCREEN
  76YTRANS         EQU   $5F        ; Y-TRANSLATION
  77ZTRANS         EQU   $FE        ; MOVE 3D OBJECT AWAY FROM CAMERA
  78*
  79TXTPTR         EQU   $06        ; POINTER FOR TEXT OUTPUT
  80G_PAGE         EQU   $06        ; GRAPHIC PAGE TO DRAW TO
  81PTR            EQU   $08        ; POINTER FOR DOS COMMAND
  82PNTCNT         EQU   $09        ; WHICH POINT TO DRAW?
  83SCALE          EQU   $E7        ; SHAPE SCALE
  84SHTABPTR       EQU   $E8        ; POINTER TO SHAPE-TABLE
  85LOOPCNTY       EQU   $FA        ; Y-ROT-COUNTER
  86ROTSPDY        EQU   $FB        ; Y-ROTATIONAL SPEED
  87LOOPCNTX       EQU   $FC        ; X-ROT-COUNTER
  88ROTSPDX        EQU   $FD        ; X-ROTATIONAL SPEED
  89LOOPCNTZ       EQU   $F4        ; Z-ROT-COUNTER
  90ROTSPDZ        EQU   $F5        ; Z-ROTATIONAL SPEED
  91SCALING        EQU   $FF        ; SCALING
  92*
  93SINX           EQU   $7B
  94XREGSAVE       EQU   $7B        ; DOUBLE USE!
  95COSX           EQU   $7C
  96SINY           EQU   $7D
  97COSY           EQU   $7E
  98SINZ           EQU   $7F
  99COSZ           EQU   $80
 100PX1            EQU   $85
 101PX2            EQU   $87
 102PX3            EQU   $89
 103PX4            EQU   $8B
 104XTO            EQU   $89        ; DOUBLE USE
 105YTO            EQU   $8B        ; DOUBLE USE
 106RX             EQU   $8D
 107RY             EQU   $8F
 108RZ             EQU   $91
 109QX             EQU   $93
 110QY             EQU   $94
 111XPOS           EQU   $95
 112YPOS           EQU   $96
 113ZPOS           EQU   $97
 114XD             EQU   $98
 115YD             EQU   $9A
 116TEMP1          EQU   $EB        ; TEMP STORAGE
 117TEMP2          EQU   $EC        ; TENP STORAGE
 118MKAND          EQU   $ED        ; MULTIPLICANT
 119MATOR          EQU   $EF        ; MULTIPLICATOR
 120*
 121XDRAW          EQU   $300       ; X-POSITION FOR DRAW
 122YDRAW          EQU   $302       ; Y-POSITION FOR DRAW
 123XDRAWO         EQU   $304       ; OLD POSITION X
 124YDRAWO         EQU   $306       ; OLD POSITION Y
 125XDRAW2         EQU   $308       ; UNDRAW CURSOR X
 126YDRAW2         EQU   $30A       ; UNDRAW CURSOR Y
 127ASCR           EQU   $30B       ; ACTIVE SCREEN TO DRAW
 128JOYCNT         EQU   $30C       ; COUNTER FOR JOYSTICK REQUEST
 129BENCHM         EQU   $30D       ; BENCHMARK ON?
 130MAXDRAW        EQU   $30E       ; MAXIMUM LINES TO DRAW
 131HOLDON         EQU   $30F       ; PAUSE PLOTTING
 132STEPON         EQU   $30A       ; STEP FUNCTION
 133*
 134PSLO           EQU   $D8        ; USING FAC-ADRESS RANGE
 135PSHI           EQU   $DA        ; FOR POINTER IN MULT-TAB
 136PDLO           EQU   $DC        ; USING ARG-ADRESS RANGE
 137PDHI           EQU   $DE        ; FOR POINTER IN MULT-TAB
 138*
 139ENTRY          JSR   SETUP      ; SETUP GRAPHIC & VARIABLES
 140*
 141TABLESET       JSR   WLCMTXT    ; DRAW TOP & BOTTOM TEXT
 142*
 143* READ PADDELS
 144*
 145LOOP           INC   JOYCNT     ; MAIN LOOP STARTS HERE
 146               LDA   HOLDON     ; IS HOLDON ACTIVATED?
 147               BEQ   EVJOY      ; NO
 148               LDA   STEPON     ; DO A STEP?
 149               BNE   DOSTEP     ; YES -> ONE STEP
 150               JMP   READKBD
 151DOSTEP         DEC   STEPON     ; RESET STEP-TRIGGER
 152EVJOY          LDA   JOYCNT     ; EAVLUATE JOYSTICK
 153               CMP   #$04
 154               BCC   READ1
 155               LDA   #$00       ; READ PADDLE EVERY 2 CYCLES
 156               STA   JOYCNT
 157*
 158PREAD0         LDX   #$00       ; VARY Y-ROT SPEED
 159               JSR   PREAD ; PADDLE (0)
 160               CPY   #$64
 161               BCC   INCSPDY    ; DECREASE SPEED
 162               CPY   #$9B
 163               BCS   DECSPDY    ; INCREASE SPEED
 164               BCC   PREAD1     ; 256-STEP CIRCLE LOOP
 165*
 166DECSPDY        LDA   ROTSPDY    ; DECREASE ANGLE
 167               CMP   #$02
 168               BCC   PREAD1     ; LOOPCNT STILL POSITIVE
 169               DEC   ROTSPDY
 170               DEC   ROTSPDY
 171               JMP   PREAD1     ; JUMP TO NEXT COMMAND
 172INCSPDY        LDA   ROTSPDY    ; DECREASE WAIT COUNTER
 173               CMP   #$20
 174               BCS   PREAD1     ; MAXIMUM 10
 175               INC   ROTSPDY
 176               INC   ROTSPDY
 177*
 178PREAD1         LDX   #$01       ; VARY X-ROT SPEED
 179               JSR   PREAD      ; PADDLE (1)
 180               CPY   #$64
 181               BCC   DECSPDX    ; DECREASE SPEED
 182               CPY   #$9B
 183               BCS   INCSPDX    ; INCREASE SPEED
 184               BCC   READ1      ; 256-STEP CIRCLE LOOP
 185*
 186DECSPDX        LDA   ROTSPDX    ; DECREASE ANGLE
 187               CMP   #$02
 188               BCC   READ1      ; LOOPCNT STILL POSITIVE
 189               DEC   ROTSPDX
 190               DEC   ROTSPDX
 191               JMP   READ1      ; JUMP TO NEXT COMMAND
 192INCSPDX        LDA   ROTSPDX    ; DECREASE WAIT COUNTER
 193               CMP   #$20
 194               BCS   READ1      ; MAXIMUM 10
 195               INC   ROTSPDX
 196               INC   ROTSPDX
 197*
 198READ1          CLC              ; CALC NEXT STEP
 199               LDX   #$00
 200               LDA   LOOPCNTY
 201               BPL   READ02
 202               INX              ; INIT FOR BENCHMARK
 203READ02         ADC   ROTSPDY    ; ADD NEXT STEP
 204               CLC
 205               ADC   #$F6       ; ACCU = ACCU -10
 206               STA   LOOPCNTY
 207               LDA   LOOPCNTY
 208               BPL   READ01     ;
 209               INX
 210READ01         CPX   #01
 211               BNE   READ03     ; BENCHMARK LOOP START
 212               LDY   BENCHM
 213               BEQ   READ03     ; BENCHMARK OFF
 214               JSR   BELL       ; REING BELL
 215*
 216READ03         CLC              ; X-ROTATION
 217               LDA   LOOPCNTX
 218               ADC   ROTSPDX    ; ADD NEXT STEP
 219               CLC
 220               ADC   #$F6       ; ACCU = ACCU - 10
 221               STA   LOOPCNTX
 222               CLC              ; Z-ROTATION
 223               LDA   LOOPCNTZ
 224               ADC   ROTSPDZ
 225               CLC
 226               ADC   #$F6
 227               STA   LOOPCNTZ
 228*
 229               JSR   INITPNTS   ; CALC NEW POINT POSITIONS
 230               JSR   UDRWLNS    ; UNDRAW LINES
 231               JSR   DRWLNS
 232*
 233* READ KEYBOARD FOR LOADING NEW OBJECTS
 234*
 235READKBD        LDA   KYBD
 236               BPL   NOKEY1     ; NO KEY IS PRESSED
 237KEYPOINT       CMP   #$AE       ; KEY '.' IS PRESSED
 238               BNE   KEYCOMMA
 239INCSPDZ        LDA   ROTSPDZ    ; INCREASE Z-ROTATION SPEED
 240               CMP   #$20
 241               BCS   NOINCZ     ; MAXIMUM 10
 242               INC   ROTSPDZ
 243               INC   ROTSPDZ
 244NOINCZ         JMP   ENDKEY1
 245KEYCOMMA       CMP   #$AC       ; KEY "," IS PRESSED
 246               BNE   KEY1
 247DECSPDZ        LDA   ROTSPDZ    ; DECREASE ANGLE
 248               CMP   #$02
 249               BCC   NODECZ     ; LOOPCNT STILL POSITIVE
 250               DEC   ROTSPDZ
 251               DEC   ROTSPDZ
 252NODECZ         JMP   ENDKEY1
 253KEY1           CMP   #$B1       ; KEY '1' IS PRESSED
 254               BNE   KEY2
 255               JSR   LOAD1      ; LOAD OBJECT 1
 256               JMP   ENDKEY
 257KEY2           CMP   #$B2       ; KEY '2' IS PRESSED
 258               BNE   KEY3
 259               JSR   LOAD2
 260               JMP   ENDKEY
 261KEY3           CMP   #$B3       ; KEY '3' IS PRESSED
 262               BNE   KEY4
 263               JSR   LOAD3
 264               JMP   ENDKEY
 265KEY4           CMP   #$B4       ; KEY '4' IS PRESSED
 266               BNE   KEY5
 267               JSR   LOAD4
 268               JMP   ENDKEY
 269KEY5           CMP   #$B5       ; KEY '5' IS PRESSED
 270               BNE   KEYPLUS
 271               JSR   LOAD5
 272               JMP   ENDKEY
 273NOKEY1         BPL   NOKEY      ; INTERMEDIATE JUMP
 274KEYPLUS        CMP   #$AB       ; KEY '+' IS PRESSED
 275               BNE   KEYMINUS
 276               LDA   STROBE
 277               LDA   ZTRANS     ; INCREASE DISTANCE
 278               CMP   #$30       ; WAS $7F
 279               BCC   ENDKEY1    ; MAIXMUM 127
 280               DEC   ZTRANS
 281               DEC   ZTRANS
 282               DEC   ZTRANS
 283               DEC   ZTRANS
 284               BNE   ENDKEY1
 285KEYMINUS       CMP   #$AD       ; KEY '-' IS PRESSED
 286               BNE   KEYQ
 287               LDA   STROBE
 288               LDA   ZTRANS     ; DECREASE DISTANCE
 289               CMP   #$D0       ; WAS $43
 290               BCS   ENDKEY1    ; LOOPCNT STILL POSITIVE
 291               INC   ZTRANS
 292               INC   ZTRANS
 293               INC   ZTRANS
 294               INC   ZTRANS
 295               BNE   ENDKEY1    ; JUMP TO NEXT COMMAND
 296KEYQ           CMP   #$D1       ; KEY 'Q' IS PRESSED
 297               BNE   KEYB
 298               LDA   STROBE
 299               JMP   END        ; END PROGRAM
 300KEYB           CMP   #$C2       ; KEY 'B' IS PRESSED
 301               BNE   KEYS
 302               LDA   BENCHM     ; TOGGLE BENCHMARK ON/OFF
 303               BEQ   BENCHON
 304               DEC   BENCHM     ; TOGGLE OFF
 305               BEQ   ENDKEY1
 306BENCHON        INC   BENCHM     ; TOGGLE ON
 307               BNE   ENDKEY1
 308KEYS           CMP   #$D3       ; KEY 'S' IS PRESSED
 309               BNE   KEYH
 310               LDA   STEPON     ; TOGGLE BENCHMARK ON/OFF
 311               BEQ   SSTEPON
 312               DEC   STEPON     ; TOGGLE OFF
 313               BEQ   ENDKEY1
 314SSTEPON        INC   STEPON     ; TOGGLE ON
 315               BNE   ENDKEY1
 316KEYH           CMP   #$C8       ; KEY 'H' IS PRESSED
 317               BNE   NOKEY
 318               LDA   HOLDON     ; TOGGLE BENCHMARK ON/OFF
 319               BEQ   HHOLDON
 320               DEC   HOLDON     ; TOGGLE OFF
 321               BEQ   ENDKEY1
 322HHOLDON        INC   HOLDON     ; TOGGLE ON
 323               BNE   ENDKEY1
 324
 325ENDKEY         JSR   SETUP
 326               JSR   WLCMTXT    ; WRITE TOP & BOTTOM TEXT
 327               JSR   INITPNTS   ; SET INITIAL POINT POSITION
 328ENDKEY1        LDA   STROBE     ; CLEAR KEYPRESS
 329*
 330* CHECK PUSHBUTTONS
 331*
 332NOKEY          LDA   PB1        ; PB 1 PRESSED?
 333               BMI   END        ; EXIT PROGRAM!
 334PB0CHK         LDA   PB0        ; PB 0 PRESSED?
 335               BPL   GOLOOP     ; NO -> DO NEXT LOOP
 336               LDA   #$00       ; RESET ASPECT AND STOP ROTATION
 337               STA   LOOPCNTX   ; BACK TO INIT POS
 338               STA   LOOPCNTY
 339               STA   LOOPCNTZ
 340               LDA   #$0A
 341               STA   ROTSPDY    ; STOP ROTATION
 342               STA   ROTSPDX
 343               STA   ROTSPDZ
 344*
 345GOLOOP         JMP   LOOP       ; START AGAIN
 346*
 347END            LDA   #$00       ; END PROGRAM
 348               STA   $C051      ; SWITCH TO TEXT
 349               STA   $C052
 350               STA   $C054
 351               JSR   HOME       ; CLEAR SCREEN
 352               JMP   $03D0      ; DOS WARM START NO RTS HERE!
 353*
 354********************************
 355* SETUP GRAPHICS & DATA        *
 356********************************
 357*
 358SETUP          LDA   #$00
 359               STA   $C050      ; SWITCH ON GRAPHICS
 360               STA   $C057      ; SWITCH TO HIRES
 361               STA   BENCHM     ; BENCHMARK OFF
 362               STA   HOLDON     ; HOLD-FUNCTION DEACTIVATED
 363               STA   STEPON     ; STEP-FUNCTION DEACTIVATED
 364*
 365               LDA   #<SHTAB    ; SET ADRESS FOR SHAPE-TABLE
 366               STA   SHTABPTR
 367               LDA   #>SHTAB
 368               STA   SHTABPTR+1
 369               LDA   #$01
 370               STA   SCALE      ; SCALE = 1
 371*
 372               LDA   #32
 373               STA   $E6        ; DRAW ON 1
 374               STA   $C055      ; SHOW 2
 375               JSR   HCLR       ; CLEAR HGR
 376               JSR   DRAWBOX    ; DRAW BOX ON HIRES 1
 377               LDX   #14
 378               LDY   #01        ; XPOS = 270
 379               LDA   #6
 380               JSR   HPOSN
 381               LDX   #67
 382               JSR   SHNUM
 383               LDA   #00
 384               JSR   SHDRAW
 385*
 386               LDA   #64
 387               STA   $E6        ; DRAW ON 2
 388               STA   $C054
 389               JSR   HCLR       ; CLEAR HGR2
 390               JSR   DRAWBOX    ; DRAW BOX ON HIRES 2
 391               LDX   #14
 392               LDY   #01        ; XPOS = 270
 393               LDA   #6
 394               JSR   HPOSN
 395               LDX   #67
 396               JSR   SHNUM
 397               LDA   #00
 398               JSR   SHDRAW
 399               LDX   #11
 400               LDY   #01        ; XPOS = 267
 401               LDA   #09
 402               JSR   HPOSN
 403               LDX   #69
 404               JSR   SHNUM
 405               LDA   #00
 406               JSR   SHDRAW
 407*
 408               LDA   #$03       ; INIT HCOLOR = 3
 409               JSR   HCOLOR
 410               LDA   #$0A
 411               STA   ROTSPDX    ; INIT X-ROT SPEED = 0
 412               STA   ROTSPDZ    ; INIT Z-ROT SPEED = 0
 413               LDA   #$0F
 414               STA   ROTSPDY    ; INIT Y-ROT SPEED = 1
 415*
 416               LDA   #$00       ; DEFINED POSITIONS AFTER
 417               STA   LOOPCNTY   ; STARTING THE ALGO OR
 418               STA   LOOPCNTZ   ; CHANGING 3D-OBJECTS
 419               LDA   #$10
 420               STA   LOOPCNTX   ; CURRENT X-STEP
 421*
 422               LDA   #$01
 423               STA   ASCR       ; DRAW ON HIRES 1
 424               STA   JOYCNT     ; SET JOYSTICK REQUEST COUNTER
 425*
 426               LDA   #$30       ; SCALING
 427               STA   SCALING
 428               LDA   #$50
 429               STA   ZTRANS     ; MOVE OBJECT AWAY FROM CAMERA
 430*
 431               LDA   #SSQLO/256 ; SETUP MULT-TAB
 432               STA   PSLO+1
 433               LDA   #SSQHI/256
 434               STA   PSHI+1
 435               LDA   #DSQLO/256
 436               STA   PDLO+1
 437               LDA   #DSQHI/256
 438               STA   PDHI+1
 439*
 440*
 441               RTS
 442*
 443********************************
 444* DRAW LINES                   *
 445********************************
 446*
 447DRWLNS         LDA   #$00
 448               STA   PNTCNT
 449               LDA   ASCR       ; CHECK WHICH SCREEN IS ACTIVE
 450               CMP   #$01
 451               BEQ   DRWSCR10
 452               LDA   #$40       ; SCREEN 2 IS ACTIVE
 453               BPL   DP1        ; ALWAYS POSITIVE
 454DRWSCR10 LDA         #$20       ; SCREEN 1 IS ACTIVE
 455DP1            STA   G_PAGE
 456
 457GETPNT2        LDA   PNTCNT
 458               ASL
 459               ASL
 460               ASL
 461               ASL              ; X = CNTR*16
 462               TAX
 463               INX              ; SKIP 3 BYTES
 464               INX
 465               INX
 466               LDA   TABLE,X    ; GET XPOS LO-BYTE
 467               STA   XDRAW
 468               INX
 469               LDA   TABLE,X    ; GET XPOS HI-BYTE
 470               STA   XDRAW+1
 471               INX
 472               LDA   TABLE,X    ; GET YPOS
 473               STA   YDRAW
 474               INX
 475               INX              ; SKIP 6 BYTES
 476               INX
 477               INX
 478               INX
 479               INX
 480               INX
 481               LDA   #$04
 482               STA   MAXDRAW    ; NUMBER OF LINES TO DRAW
 483               STX   XREGSAVE   ; SAVE X-REG ON STACK
 484*
 485* EVALUATE POINTS TO DRAW TO
 486*
 487               LDX   XREGSAVE
 488DRWNXT         LDA   TABLE,X
 489               BEQ   NXTPNT     ; NOTHING MORE TO DRAW
 490               TAY              ; SUBTRACT 1 TO GET CORREC
 491               DEY              ; POINT NUMBER
 492               TYA
 493               ASL              ; CALC BASE ADRESS OF POINT TO
 494               ASL              ; DRAW TO
 495               ASL
 496               ASL
 497               TAY              ; Y = POINNUMBER * 16
 498               INY              ; SKIP 3 BYTES
 499               INY
 500               INY
 501               LDA   TABLE,Y    ; READ OUT POINTS TO DRAW TO
 502               STA   XTO
 503               INY
 504               LDA   TABLE,Y
 505               STA   XTO+1
 506               INY
 507               LDA   TABLE,Y
 508               STA   YTO
 509*
 510               STX   XREGSAVE
 511               JSR   LINEDRAW   ; DO FAST LINE DRAW
 512               LDX   XREGSAVE
 513*
 514               DEC   MAXDRAW    ; MAXIMUM NUMBER OF LINES
 515               BEQ   NXTPNT     ; REACHED? IF YES NEXT POINT
 516               INX              ; NEXT POINT
 517               BNE   DRWNXT
 518*
 519NXTPNT         INC   PNTCNT
 520               LDA   PNTCNT
 521               CMP   NUMPNT
 522               BCS   DRWEND     ; ALL DONE
 523               JMP   GETPNT2
 524DRWEND         LDA   ASCR       ; DISPLAY DRAW-SCREEN
 525               CMP   #$02
 526               BEQ   DISP2      ; SHOW SCREEN 2
 527               LDA   #64
 528               STA   $E6        ; DRAW ON 2
 529               STA   $C054      ; SWITCH TO SCREEN1
 530               INC   ASCR       ; ASCR = 2
 531               BNE   DRWEND2
 532DISP2          STA   $C055      ; SWITCH TO SCREEN2
 533               LDA   #32
 534               STA   $E6        ; DRAW ON 1
 535               DEC   ASCR       ; ASCR = 1
 536DRWEND2        RTS
 537*
 538*
 539********************************
 540* INIT POINT POSITIONS         *
 541********************************
 542*
 543INITPNTS       LDA   #$00
 544               STA   PNTCNT
 545*
 546* EVAL SIN/COS-TAB
 547*
 548               LDX   LOOPCNTX   ; INITIAL POS
 549               LDA   SINTAB,X   ; GET SINUS FOR X
 550               STA   SINX
 551               LDA   COSTAB,X   ; GET COSINUS FOR X
 552               STA   COSX
 553               LDX   LOOPCNTY
 554               LDA   SINTAB,X
 555               STA   SINY
 556               LDA   COSTAB,X
 557               STA   COSY
 558               LDX   LOOPCNTZ
 559               LDA   SINTAB,X
 560               STA   SINZ
 561               LDA   COSTAB,X
 562               STA   COSZ
 563*
 564* ROTATE POINTS AROUND X AND Y
 565*
 566GETPNT         LDA   PNTCNT
 567               ASL
 568               ASL
 569               ASL
 570               ASL              ; X = CNTR*16
 571               TAX
 572               LDA   TABLE,X    ; GET XPOS
 573               STA   XPOS
 574               INX
 575               LDA   TABLE,X    ; GET YPOS
 576               STA   YPOS
 577               INX
 578               LDA   TABLE,X    ; GET ZPOS
 579               STA   ZPOS
 580*
 581* PERFORM Y-ROTATION
 582*
 583STRTROT        LDA   XPOS       ; RX = X * COS(Y) + Z * SIN(Y)
 584               STA   MATOR      ; X * COS(Y)
 585               LDA   COSY
 586               STA   MKAND
 587               JSR   MULT
 588               STA   PX1
 589               STY   PX1+1
 590
 591               LDA   SINY       ; XPOS STILL IN MATOR!
 592               STA   MKAND      ; X * SIN(Y)
 593               JSR   MULT
 594               STA   PX4
 595               STY   PX4+1
 596
 597               LDA   ZPOS       ; Z * SIN(Y)
 598               STA   MATOR
 599               LDA   SINY
 600               STA   MKAND
 601               JSR   MULT
 602               STA   PX2
 603               STY   PX2+1
 604
 605               LDA   COSY       ; RZ = Z * COS(Y) - X * SIN(Y)
 606               STA   MKAND      ; ZPOS STILL IN MATOR
 607               JSR   MULT       ; Z * COS(Y)
 608               STA   PX3
 609               STY   PX3+1
 610
 611               CLC              ; X-CCORD:  ADD
 612               LDA   PX1
 613               ADC   PX2
 614               STA   RX
 615               LDA   PX1+1
 616               ADC   PX2+1
 617               STA   RX+1       ; SAVE HI-BYTE AS XPOS
 618*
 619               SEC              ; Z-COORD: SUB
 620               LDA   PX3
 621               SBC   PX4
 622               STA   RZ
 623               LDA   PX3+1
 624               SBC   PX4+1
 625               STA   RZ+1
 626*
 627               LDA   YPOS       ; RY = YPOS * 1 (=$7F)
 628               STA   MATOR
 629               LDA   #$7F
 630               STA   MKAND
 631               JSR   MULT
 632               STA   RY
 633               STY   RY+1
 634*
 635* PERFORM X-ROTATION
 636*
 637               LDA   RX+1       ; RXNEW = RX+1 * 1 (=$7F)
 638               STA   MATOR
 639               LDA   #$7F
 640               STA   MKAND
 641               JSR   MULT
 642               STA   RX
 643               STY   RX+1
 644*
 645               LDA   RY+1       ; RY = Y * COS(X) - Z * SIN(X)
 646               STA   MATOR      ; Y * COS(X)
 647               LDA   COSX
 648               STA   MKAND
 649               JSR   MULT
 650               STA   PX1
 651               STY   PX1+1
 652*
 653               LDA   SINX       ; CALC Y * SIN(X) FOR Z-COORD
 654               STA   MKAND      ; Y * SIN(X)
 655               JSR   MULT
 656               STA   PX3
 657               STY   PX3+1
 658*
 659               LDA   RZ+1       ; Z * SIN(X)
 660               STA   MATOR
 661               LDA   SINX
 662               STA   MKAND
 663               JSR   MULT
 664               STA   PX2
 665               STY   PX2+1
 666*
 667               LDA   COSX       ; CALC Z * COS(X) FOR Z-CCORD
 668               STA   MKAND      ; Z * COS(X)
 669               JSR   MULT
 670               STA   PX4
 671               STY   PX4+1
 672*
 673               SEC              ; Y-COORD: SUB
 674               LDA   PX1
 675               SBC   PX2
 676               STA   RY
 677               LDA   PX1+1
 678               SBC   PX2+1
 679               STA   RY+1
 680*
 681               CLC              ; Z-COORD: ADD + TRANSLATE
 682               LDA   PX3
 683               ADC   PX4
 684               STA   RZ
 685               LDA   PX3+1
 686               ADC   PX4+1
 687               CLC
 688               ADC   ZTRANS     ; Z-TRANSLATION AND SCALE DOWN
 689               LSR
 690               LSR
 691               STA   RZ+1
 692*
 693* PERFORM Z-ROTATION
 694*
 695* DO NOT TOUCH RZ ANYMORE!
 696*
 697               LDA   RX+1       ; RX = X * COSZ - Y * SINZ
 698               STA   MATOR      ; X * COS(Z)
 699               LDA   COSZ
 700               STA   MKAND
 701               JSR   MULT
 702               STA   PX1
 703               STY   PX1+1
 704*
 705               LDA   SINZ       ; X * SIN(Z)
 706               STA   MKAND
 707               JSR   MULT
 708               STA   PX3
 709               STY   PX3+1
 710*
 711               LDA   RY+1       ; Y * SIN(Z)
 712               STA   MATOR
 713               LDA   SINZ
 714               STA   MKAND
 715               JSR   MULT
 716               STA   PX2
 717               STY   PX2+1
 718*
 719               LDA   COSZ       ; Y * COS(Z)
 720               STA   MKAND
 721               JSR   MULT
 722               STA   PX4
 723               STY   PX4+1
 724*
 725               SEC              ; NOW CALCULATE NEW RX
 726               LDA   PX1        ; SINCE OLD RX IS NEEDED FOR
 727               SBC   PX2        ; RY-CACLULUS BEFORE!
 728               STA   RX
 729               LDA   PX1+1
 730               SBC   PX2+1
 731               STA   RX+1
 732*
 733               CLC              ; Y-COORD: ADD
 734               LDA   PX3
 735               ADC   PX4
 736               STA   RY
 737               LDA   PX3+1
 738               ADC   PX4+1
 739               STA   RY+1
 740*
 741* PERFORM SCALING AND TRANSLATION
 742*
 743               ASL   RX
 744               ROL   RX+1
 745               ASL   RX
 746               ROL   RX+1
 747               ASL   RY
 748               ROL   RY+1
 749               ASL   RY
 750               ROL   RY+1
 751*
 752               LDX   RZ+1       ; LOAD PROJECTION
 753               LDA   PROJTAB,X
 754               STA   MATOR
 755               LDA   RX+1       ; ONLY HI-BYTE!
 756               STA   MKAND
 757               JSR   UMULT
 758               STY   QX
 759*
 760               LDA   RY+1       ; ONLY HI-BYTE!
 761               STA   MKAND
 762               JSR   UMULT
 763               STY   QY
 764*
 765               CLC              ; XD = QX + XT
 766               LDA   QX
 767               ADC   #XTRANS
 768               STA   XD
 769               LDA   #$00
 770               STA   XD+1
 771               LDA   QX
 772               BMI   CALCYD     ; IF QX < 0 THEN DO NOT ADD CARRY!
 773               LDA   #$00
 774               ADC   #$00       ; ADD CARRY BIT
 775               STA   XD+1
 776CALCYD         CLC              ; YD = QY + YT
 777               LDA   QY
 778               ADC   #YTRANS
 779               STA   YD         ; ONLY 1 BYTE HERE, NO CARRY!
 780*
 781* WRITE DATA BACK TO TABLE
 782*
 783WRTPNT         LDA   PNTCNT
 784               ASL
 785               ASL
 786               ASL
 787               ASL              ; X = CNTR*16
 788               TAX
 789               INX
 790               INX
 791               INX              ; SKIP 3 BYTES
 792               LDA   XD         ; SAVE XDRAW POSITION
 793               STA   TABLE,X
 794               INX
 795               LDA   XD+1
 796               STA   TABLE,X
 797               INX
 798               LDA   YD         ; SAVE YDRAW POSITION
 799               STA   TABLE,X
 800*
 801               INC   PNTCNT
 802               LDA   PNTCNT
 803               CMP   NUMPNT
 804               BCS   INITEND    ; ALL DONE
 805               JMP   GETPNT
 806INITEND        RTS
 807*
 808               CYC   OFF
 809*
 810********************************
 811* DRAW BOX AROUND HIRES SCREEN *
 812********************************
 813*
 814DRAWBOX        LDX   #$03
 815               JSR   HCOLOR
 816               LDA   #$00
 817               TAY
 818               TAX
 819               JSR   HPLOT
 820               LDA   #23
 821               LDX   #01
 822               JSR   HLIN
 823*
 824               LDA   #23
 825               LDX   #01
 826               LDY   #$BF
 827               JSR   HLIN
 828*
 829               LDA   #$00
 830               LDX   #$00
 831               LDY   #$BF
 832               JSR   HLIN
 833*
 834               LDA   #$00
 835               TAY
 836               TAX
 837               JSR   HLIN
 838*
 839               LDY   #00
 840               LDX   #00
 841               LDA   #12
 842               JSR   HPOSN
 843*
 844               LDA   #23
 845               LDX   #01
 846               LDY   #12
 847               JSR   HLIN
 848               RTS
 849*
 850********************************
 851*SIGNED  DIVISION 16 BIT/8 BIT *
 852********************************
 853*
 854               CYC
 855*
 856DIVI           STY   DEND       ;
 857               STA   DEND+1
 858               STX   DOR
 859*
 860               LDX   #$00
 861DECHK          LDA   DEND+1     ; DIVIDEND NEG?
 862               BPL   DORCHK
 863               INX              ; INC X-REG FOR NEG SIGN
 864               LDA   DEND
 865               SEC              ; TWO'S COMPLEMENT
 866               SBC   #$01
 867               EOR   #$FF
 868               STA   DEND
 869               LDA   DEND+1
 870               SBC   #$00
 871               EOR   #$FF
 872               STA   DEND+1
 873DORCHK         LDA   DOR        ; DIVISOR NEG?
 874               BPL   DIVIGO
 875               INX              ; INC X-REG FOR NEG SIGN
 876               SEC              ; TWO'S COMPLEMENT
 877               SBC   #$01
 878               EOR   #$FF
 879               STA   DOR
 880*
 881DIVIGO         LDA   DEND+1     ; TOO LARGE OR ZERO?
 882               CMP   DOR        ; CMP HI-BYTE WITH DOR!
 883               BCC   DLOOP      ; NO -> NO ERROR!
 884               JMP   DIVERR     ; YES -> ERROR!
 885DLOOP          ASL   DEND       ; DOUBLE SHIFT DIVIDEND
 886               ROL              ; DEND+1 STILL IN ACCU!
 887               BCS   DSUBTR     ; SUBTRACTION WHEN CARRY IS SET
 888               CMP   DOR
 889               BCC   DLOOP2
 890DSUBTR         SBC   DOR
 891               INC   DEND
 892DLOOP2         ASL   DEND
 893               ROL
 894               BCS   DSUBTR2
 895               CMP   DOR
 896               BCC   DLOOP3
 897DSUBTR2        SBC   DOR
 898               INC   DEND
 899DLOOP3         ASL   DEND
 900               ROL
 901               BCS   DSUBTR3
 902               CMP   DOR
 903               BCC   DLOOP4
 904DSUBTR3        SBC   DOR
 905               INC   DEND
 906DLOOP4         ASL   DEND
 907               ROL
 908               BCS   DSUBTR4
 909               CMP   DOR
 910               BCC   DLOOP5
 911DSUBTR4        SBC   DOR
 912               INC   DEND
 913DLOOP5         ASL   DEND
 914               ROL
 915               BCS   DSUBTR5
 916               CMP   DOR
 917               BCC   DLOOP6
 918DSUBTR5        SBC   DOR
 919               INC   DEND
 920DLOOP6         ASL   DEND
 921               ROL
 922               BCS   DSUBTR6
 923               CMP   DOR
 924               BCC   DLOOP7
 925DSUBTR6        SBC   DOR
 926               INC   DEND
 927DLOOP7         ASL   DEND
 928               ROL
 929               BCS   DSUBTR7
 930               CMP   DOR
 931               BCC   DLOOP8
 932DSUBTR7        SBC   DOR
 933               INC   DEND
 934DLOOP8         ASL   DEND
 935               ROL
 936               BCS   DSUBTR8
 937               CMP   DOR
 938               BCC   DCONT
 939DSUBTR8        SBC   DOR
 940               INC   DEND
 941
 942*
 943* STORE RESULTS
 944*
 945DCONT          STA   DOR        ; MOVE REMAINDER IN DOR
 946               CLC              ; NO ERROR -> CLEAR CARRY
 947               CPX   #$01       ; NEG SIGN FOR RESULT?
 948               BNE   DIVEND     ; NO, SIGN IS POSITIVE -> END
 949               EOR   #$FF       ; TWO'S COMPLEMENT  OF ACCU
 950               CLC
 951               ADC   #$01
 952               STA   DOR
 953               LDA   DEND
 954               EOR   #$FF
 955               ADC   #$01
 956               STA   DEND
 957               LDA   DOR        ; DOR = REMAINDER
 958DIVEND         LDY   DEND       ; DEND = QUOTIENT
 959               BNE   DIVRTS
 960               INY
 961DIVRTS         RTS
 962DIVERR         LDY   #$00       ; RETURN 0 AS RESULT
 963               RTS
 964*
 965               CYC   OFF
 966*
 967DEND           DS    2
 968DOR            DS    1
 969*
 970********************************
 971* 8-BIT UNSIGNED FAST MULTIPLY *
 972********************************
 973*
 974               CYC
 975*
 976UMULT          LDY   MKAND
 977               STY   TEMP1      ; SAVE FOR LATER USE
 978UMTCHK         LDA   MATOR
 979               STA   TEMP2      ; SAVE FOR LATER USE
 980               STA   PSHI
 981               EOR   #$FF
 982               STA   PDHI
 983               SEC
 984               LDA   (PSHI),Y   ; GET (A+Y)^2/4 (HI-BYTE)
 985               SBC   (PDHI),Y   ; SUBTRACT (-A+Y)^2/4 (HI-BYTE)
 986*
 987* STORE RESULTS
 988*
 989               LDY   TEMP1      ; CHECK IF MKAND < 0
 990               BPL   UMDONE     ; NO -> ALL DONE
 991               SEC              ; MATOR STILL IN ACCU!
 992               SBC   TEMP2      ; SUBTRACT TEMP2 FROM MATOR
 993*
 994UMDONE         TAY              ; MOVE ACCU TO Y-REG AS RESULT
 995               RTS
 996*
 997               CYC   OFF
 998*
 999*
1000********************************
1001* 8-BIT SIGNED COMPL MULTIPLY  *
1002********************************
1003*
1004               CYC
1005*
1006MULT           LDY   MKAND
1007               STY   TEMP1      ; SAVE FOR LATER USE
1008MTCHK          LDA   MATOR
1009               STA   TEMP2      ; SAVE FOR LATER USE
1010               STA   PSLO       ; INDEX INTO SUM TABLE BY A
1011               STA   PSHI
1012               EOR   #$FF
1013               STA   PDLO       ; INDEX INTO DIFF TABLE BY -A-1
1014               STA   PDHI
1015               LDA   (PSLO),Y   ; GET (A+Y)^2/4 (LO BYTE)
1016               SEC
1017               SBC   (PDLO),Y   ; SUBTRACT (-A+Y)^2/4 (LO BYTE)
1018               STA   MKAND      ; SAVE IT
1019               LDA   (PSHI),Y   ; GET (A+Y)^2/4 (HI-BYTE)
1020               SBC   (PDHI),Y   ; SUBTRACT (-A+Y)^2/4 (HI-BYTE)
1021*
1022* STORE RESULTS
1023*
1024               LDY   TEMP1      ; CHECK IF MKAND < 0
1025               BPL   CHKT2      ; NO CHECK MATOR
1026               SEC              ; MATOR STILL IN ACCU!
1027               SBC   TEMP2      ; SUBTRACT TEMP2 FROM MATOR
1028*
1029CHKT2          LDY   TEMP2      ; CHECK IF MATOR < 0
1030               BPL   MDONE      ; NO, RTS
1031               SEC              ; MATOR STILL IN ACCU
1032               SBC   TEMP1      ; SUBTRACT TEMP1 FROM MATOR
1033*
1034MDONE          TAY              ; MOVE ACCU TO Y-REG AS RESULT
1035               LDA   MKAND      ; LOAD LO BYTE
1036               RTS
1037*
1038               CYC   OFF
1039*
1040********************************
1041* 8-BIT SIGNED FAST MULTIPLY   *
1042********************************
1043*
1044               CYC
1045*
1046FMULT          LDY   MKAND
1047               STY   TEMP1      ; SAVE FOR LATER USE
1048FMTCHK         LDA   MATOR
1049               STA   TEMP2      ; SAVE FOR LATER USE
1050               STA   PSHI
1051               EOR   #$FF
1052               STA   PDHI
1053               SEC
1054               LDA   (PSHI),Y   ; GET (A+Y)^2/4 (HI-BYTE)
1055               SBC   (PDHI),Y   ; SUBTRACT (-A+Y)^2/4 (HI-BYTE)
1056*
1057* STORE RESULTS
1058*
1059               LDY   TEMP1      ; CHECK IF MKAND < 0
1060               BPL   FCHKT2     ; NO CHECK MATOR
1061               SEC              ; MATOR STILL IN ACCU!
1062               SBC   TEMP2      ; SUBTRACT TEMP2 FROM MATOR
1063*
1064FCHKT2         LDY   TEMP2      ; CHECK IF MATOR < 0
1065               BPL   FMDONE     ; NO, RTS
1066               SEC              ; MATOR STILL IN ACCU
1067               SBC   TEMP1      ; SUBTRACT TEMP1 FROM MATOR
1068*
1069FMDONE         TAY              ; MOVE ACCU TO Y-REG AS RESULT
1070               RTS
1071*
1072               CYC   OFF
1073*
1074********************************
1075* TOP & BOTTOM TEXT MESSAGE    *
1076********************************
1077*
1078* PRINT OUT WELCOME TEXT AS SHAPES ON SCREEN
1079*
1080WLCMTXT        LDX   #$03
1081               JSR   HCOLOR
1082               STX   $F9        ; SET ROT = 0
1083               LDA   #$01
1084               STA   SCALE      ; SET SCALE = 1
1085               LDX   #$00
1086TXTLOOP        LDA   TXTDAT,X
1087               BEQ   TLP2       ; STOP WHEN $00 IS READ
1088               STA   SHPDUMP    ; SAVE SHAPE-NUMBER
1089               STX   XREGDUMP   ; SAVE X-REG COUNTER STATUS
1090               TXA              ; MOVE CHAR POSITION TO ACCU
1091               ASL              ; CHAR-POS * 8 PIXEL
1092               ASL              ; EACH CHAR NEEDS 8 PIXEL
1093               ASL              ; SPACING
1094               CLC
1095               ADC   #26        ; ADD X-OFFSET
1096               TAX              ; MOVE X-POS TO X-REG
1097               STX   SHXPOS     ; SAVE SHAPE X-POS
1098               LDY   #$00       ; HIGH-BYTE = 0
1099               LDA   #09        ; Y-OFFSET FOR TEXT OUTPUT
1100               JSR   HPOSN      ; POSITION THE CURSOR
1101*
1102               LDX   SHPDUMP    ; RETRIEVE SHAPE-NUMBER
1103               JSR   SHNUM      ; GET SHAPE ADRESS
1104               LDA   #32        ; DRAW ON SCREEN 1
1105               STA   $E6
1106               LDA   #$00       ; SET ROT = 0
1107               JSR   SHDRAW     ; DRAW SHAPE
1108*
1109               LDX   SHXPOS     ; GET SHAPE X-POS
1110               LDY   #$00       ; HIGH-BYTE = 0
1111               LDA   #09        ; Y-OFFSET FOR TEXT OUTPUT
1112               JSR   HPOSN      ; POSITION THE CURSOR
1113               LDX   SHPDUMP    ; RETRIEVE SHAPE-NUMBER
1114               JSR   SHNUM      ; GET SHAPE ADRESS
1115               LDA   #64        ; DRAW ON SCREEN 2
1116               STA   $E6
1117               LDA   #$00       ; SET ROT = 0
1118               JSR   SHDRAW     ; DRAW SHAPE
1119*
1120               LDX   XREGDUMP
1121               INX
1122               BNE   TXTLOOP
1123*
1124TLP2           LDX   #$00
1125TXTLOOP2       LDA   TXTDAT2,X
1126               BEQ   SUDONE
1127               STA   SHPDUMP
1128               STX   XREGDUMP
1129               TXA
1130               ASL
1131               ASL
1132               ASL
1133               CLC
1134               ADC   #18
1135               TAX
1136               STX   SHXPOS
1137               LDY   #$00
1138               LDA   #188
1139               JSR   HPOSN
1140*
1141               LDX   SHPDUMP
1142               JSR   SHNUM
1143               LDA   #32
1144               STA   $E6
1145               LDA   #$00
1146               JSR   SHDRAW
1147*
1148               LDX   SHXPOS
1149               LDY   #$00
1150               LDA   #188
1151               JSR   HPOSN
1152               LDX   SHPDUMP
1153               JSR   SHNUM
1154               LDA   #64
1155               STA   $E6
1156               LDA   #$00
1157               JSR   SHDRAW
1158               LDX   XREGDUMP
1159               INX
1160               BNE   TXTLOOP2
1161SUDONE         RTS
1162*
1163* TEXT MESSAGES WHEN LOADING 3D-OBJECTS
1164*
1165TXTOB1         LDA   #<TXTDAT3  ; SET ADRESS FOR MESSAGE
1166               STA   TXTPTR
1167               LDA   #>TXTDAT3
1168               STA   TXTPTR+1
1169               JSR   DLTTXT
1170               JMP   PRTTXT     ; PRINT MESSAGE
1171*
1172TXTOB2         LDA   #<TXTDAT4
1173               STA   TXTPTR
1174               LDA   #>TXTDAT4
1175               STA   TXTPTR+1
1176               JSR   DLTTXT
1177               JMP   PRTTXT
1178*
1179TXTOB3         LDA   #<TXTDAT5
1180               STA   TXTPTR
1181               LDA   #>TXTDAT5
1182               STA   TXTPTR+1
1183               JSR   DLTTXT
1184               JMP   PRTTXT
1185*
1186TXTOB4         LDA   #<TXTDAT6
1187               STA   TXTPTR
1188               LDA   #>TXTDAT6
1189               STA   TXTPTR+1
1190               JSR   DLTTXT
1191               JMP   PRTTXT
1192*
1193TXTOB5         LDA   #<TXTDAT7
1194               STA   TXTPTR
1195               LDA   #>TXTDAT7
1196               STA   TXTPTR+1
1197               JSR   DLTTXT
1198               JMP   PRTTXT
1199*
1200PRTTXT         LDY   #$00
1201               LDX   #$03
1202               JSR   HCOLOR     ; SET HCOLOR = 3
1203TXTLOOP3       LDA   (TXTPTR),Y
1204               BEQ   TXTDONE
1205               STA   SHPDUMP
1206               STY   YREGDUMP
1207               TYA
1208               ASL
1209               ASL
1210               ASL
1211               CLC
1212               ADC   #18
1213               TAY
1214               TAX
1215               STY   SHXPOS
1216               LDY   #$00
1217               LDA   #188
1218               JSR   HPOSN
1219*
1220               LDX   SHPDUMP
1221               JSR   SHNUM
1222               LDA   #32
1223               STA   $E6
1224               LDA   #$00
1225               JSR   SHDRAW
1226*
1227               LDX   SHXPOS
1228               LDY   #$00
1229               LDA   #188
1230               JSR   HPOSN
1231               LDX   SHPDUMP
1232               JSR   SHNUM
1233               LDA   #64
1234               STA   $E6
1235               LDA   #$00
1236               JSR   SHDRAW
1237*
1238               LDY   YREGDUMP
1239               INY
1240               BNE   TXTLOOP3
1241TXTDONE        RTS
1242*
1243TXTDAT         HEX   292231313A01151135
1244               HEX   2901232A33352925223A
1245               HEX   012231312D26013E3C
1246               HEX   00
1247*
1248TXTDAT2        HEX   450114250E25262E3001
1249               HEX   0E012E0F28302D30
1250               HEX   2E2326242C01131112
1251               HEX   18014500
1252*
1253TXTDAT3        HEX   2D3022252A2F28013529
1254               HEX   2601352635332226252633
1255               HEX   0F0F0F010101010101
1256               HEX   010100
1257*
1258TXTDAT4        HEX   2D3022252A2F28013529
1259               HEX   2601362E2333262D2D22
1260               HEX   0F0F0F010101010101
1261               HEX   010100
1262*
1263TXTDAT5        HEX   2D3022252A2F28013529
1264               HEX   2601342A2E312D260124362326
1265               HEX   0F0F0F010101010101
1266               HEX   010100
1267*
1268TXTDAT6        HEX   2D3022252A2F28013529
1269               HEX   2601352635332224362326
1270               HEX   0F0F0F010101010101
1271               HEX   010100
1272*
1273TXTDAT7        HEX   2D3022252A2F28013529
1274               HEX   2601243623260135382A2F34
1275               HEX   0F0F0F010101010101
1276               HEX   010100
1277*
1278LCNT           DS    1
1279XREGDUMP       DS    1
1280YREGDUMP       DS    1
1281SHPDUMP        DS    1
1282SHXPOS         DS    1
1283*
1284* DELETE BOTTOM TEXT
1285*
1286DLTTXT         LDX   #$00
1287               JSR   HCOLOR     ; HCOLOR = 0
1288               LDA   ASCR
1289DLTSTRT        LDA   #180
1290               STA   YDELROW    ; Y OF LINE TO DELETE
1291DLTLOOP        LDA   #32
1292               STA   $E6        ; DELETE ON SCREEN 1
1293               LDX   #$02
1294               LDY   #$00
1295               LDA   YDELROW
1296               JSR   HPOSN
1297               LDA   #$15
1298               LDX   #$01
1299               LDY   YDELROW
1300               JSR   HLIN
1301               LDA   #64
1302               STA   $E6        ; DELETE ON SCREEN 2
1303               LDX   #$02
1304               LDY   #$00
1305               LDA   YDELROW
1306               JSR   HPOSN
1307               LDA   #$15
1308               LDX   #$01
1309               LDY   YDELROW
1310               JSR   HLIN
1311               INC   YDELROW
1312               LDA   YDELROW
1313               CMP   #189       ; LINE 189 REACHED?
1314               BCC   DLTLOOP    ; NO -> DELETE NEXT LINE
1315DLTEND         RTS              ; END OF LOOP
1316*
1317YDELROW        DS    1
1318*
1319********************************
1320* LOAD 3D-OBJECTS IN MEMORY    *
1321********************************
1322*
1323LOAD1          JSR   TXTOB1     ; PRINT LOADING MESSAGE
1324LOAD01         LDA   #$8D       ; LOAD 3D-OBJECT 1 INTO MEMORY
1325               JSR   COUT
1326               JSR   PRINT
1327               HEX   84
1328               ASC   "BLOAD OBJECT1.3D,A$7200"
1329               HEX   8D00
1330               RTS
1331*
1332LOAD2          JSR   TXTOB2
1333LOAD02         LDA   #$8D       ; LOAD 3D-OBJECT 1 INTO MEMORY
1334               JSR   COUT
1335               JSR   PRINT
1336               HEX   84
1337               ASC   "BLOAD OBJECT2.3D,A$7200"
1338               HEX   8D00
1339               RTS
1340*
1341LOAD3          JSR   TXTOB3
1342LOAD03         LDA   #$8D       ; LOAD 3D-OBJECT 1 INTO MEMORY
1343               JSR   COUT
1344               JSR   PRINT
1345               HEX   84
1346               ASC   "BLOAD OBJECT3.3D,A$7200"
1347               HEX   8D00
1348               RTS
1349*
1350LOAD4          JSR   TXTOB4
1351LOAD04         LDA   #$8D       ; LOAD 3D-OBJECT 1 INTO MEMORY
1352               JSR   COUT
1353               JSR   PRINT
1354               HEX   84
1355               ASC   "BLOAD OBJECT4.3D,A$7200"
1356               HEX   8D00
1357               RTS
1358*
1359LOAD5          JSR   TXTOB5
1360LOAD05         LDA   #$8D       ; LOAD 3D-OBJECT 1 INTO MEMORY
1361               JSR   COUT
1362               JSR   PRINT
1363               HEX   84
1364               ASC   "BLOAD OBJECT5.3D,A$7200"
1365               HEX   8D00
1366               RTS
1367*
1368PRINT          PLA
1369               STA   PTR
1370               PLA
1371               STA   PTR+1
1372               LDY   #$01
1373P0             LDA   (PTR),Y
1374               BEQ   PFIN
1375               JSR   COUT
1376               INY
1377               BNE   P0
1378               CHK
1379*
1380PFIN           CLC
1381               TYA
1382               ADC   PTR
1383               STA   PTR
1384               LDA   PTR+1
1385               ADC   #$00
1386               PHA
1387               LDA   PTR
1388               PHA
1389PEXIT          RTS
1390*
1391********************************
1392* UNDRAW LINES                 *
1393********************************
1394*
1395UDRWLNS        LDA   #$00
1396*
1397               LDY   $E6
1398               CPY   #$20
1399               BEQ   UDRWSCR1
1400               JMP   UDRWSCR2
1401UDRWSCR1       LDX   #$0B
1402UDRWLP1        STA   $2200,X
1403               STA   $2600,X
1404               STA   $2A00,X
1405               STA   $2E00,X
1406               STA   $3200,X
1407               STA   $3600,X
1408               STA   $3A00,X
1409               STA   $3E00,X
1410
1411               STA   $2280,X
1412               STA   $2680,X
1413               STA   $2A80,X
1414               STA   $2E80,X
1415               STA   $3280,X
1416               STA   $3680,X
1417               STA   $3A80,X
1418               STA   $3E80,X
1419
1420               STA   $2300,X
1421               STA   $2700,X
1422               STA   $2B00,X
1423               STA   $2F00,X
1424               STA   $3300,X
1425               STA   $3700,X
1426               STA   $3B00,X
1427               STA   $3F00,X
1428
1429               STA   $2380,X
1430               STA   $2780,X
1431               STA   $2B80,X
1432               STA   $2F80,X
1433               STA   $3380,X
1434               STA   $3780,X
1435               STA   $3B80,X
1436               STA   $3F80,X
1437
1438               STA   $2028,X
1439               STA   $2428,X
1440               STA   $2828,X
1441               STA   $2C28,X
1442               STA   $3028,X
1443               STA   $3428,X
1444               STA   $3828,X
1445               STA   $3C28,X
1446
1447               STA   $20A8,X
1448               STA   $24A8,X
1449               STA   $28A8,X
1450               STA   $2CA8,X
1451               STA   $30A8,X
1452               STA   $34A8,X
1453               STA   $38A8,X
1454               STA   $3CA8,X
1455
1456               STA   $2128,X
1457               STA   $2528,X
1458               STA   $2928,X
1459               STA   $2D28,X
1460               STA   $3128,X
1461               STA   $3528,X
1462               STA   $3928,X
1463               STA   $3D28,X
1464
1465               STA   $21A8,X
1466               STA   $25A8,X
1467               STA   $29A8,X
1468               STA   $2DA8,X
1469               STA   $31A8,X
1470               STA   $35A8,X
1471               STA   $39A8,X
1472               STA   $3DA8,X
1473
1474               STA   $2228,X
1475               STA   $2628,X
1476               STA   $2A28,X
1477               STA   $2E28,X
1478               STA   $3228,X
1479               STA   $3628,X
1480               STA   $3A28,X
1481               STA   $3E28,X
1482
1483               STA   $22A8,X
1484               STA   $26A8,X
1485               STA   $2AA8,X
1486               STA   $2EA8,X
1487               STA   $32A8,X
1488               STA   $36A8,X
1489               STA   $3AA8,X
1490               STA   $3EA8,X
1491
1492               STA   $2328,X
1493               STA   $2728,X
1494               STA   $2B28,X
1495               STA   $2F28,X
1496               STA   $3328,X
1497               STA   $3728,X
1498               STA   $3B28,X
1499               STA   $3F28,X
1500
1501               STA   $23A8,X
1502               STA   $27A8,X
1503               STA   $2BA8,X
1504               STA   $2FA8,X
1505               STA   $33A8,X
1506               STA   $37A8,X
1507               STA   $3BA8,X
1508               STA   $3FA8,X
1509*
1510               STA   $2050,X
1511               STA   $2450,X
1512               STA   $2850,X
1513               STA   $2C50,X
1514               STA   $3050,X
1515               STA   $3450,X
1516               STA   $3850,X
1517               STA   $3C50,X
1518
1519               STA   $20D0,X
1520               STA   $24D0,X
1521               STA   $28D0,X
1522               STA   $2CD0,X
1523               STA   $30D0,X
1524               STA   $34D0,X
1525               STA   $38D0,X
1526               STA   $3CD0,X
1527
1528               STA   $2150,X
1529               STA   $2550,X
1530               STA   $2950,X
1531               STA   $2D50,X
1532               STA   $3150,X
1533               STA   $3550,X
1534               STA   $3950,X
1535               STA   $3D50,X
1536
1537               STA   $21D0,X
1538               STA   $25D0,X
1539               STA   $29D0,X
1540               STA   $2DD0,X
1541               STA   $31D0,X
1542               STA   $35D0,X
1543               STA   $39D0,X
1544               STA   $3DD0,X
1545
1546               INX
1547               CPX   #29
1548               BEQ   UDRW1RTS
1549               JMP   UDRWLP1
1550UDRW1RTS       RTS
1551
1552UDRWSCR2       LDX   #$0B
1553UDRWLP2        STA   $4200,X
1554               STA   $4600,X
1555               STA   $4A00,X
1556               STA   $4E00,X
1557               STA   $5200,X
1558               STA   $5600,X
1559               STA   $5A00,X
1560               STA   $5E00,X
1561
1562               STA   $4280,X
1563               STA   $4680,X
1564               STA   $4A80,X
1565               STA   $4E80,X
1566               STA   $5280,X
1567               STA   $5680,X
1568               STA   $5A80,X
1569               STA   $5E80,X
1570
1571               STA   $4300,X
1572               STA   $4700,X
1573               STA   $4B00,X
1574               STA   $4F00,X
1575               STA   $5300,X
1576               STA   $5700,X
1577               STA   $5B00,X
1578               STA   $5F00,X
1579
1580               STA   $4380,X
1581               STA   $4780,X
1582               STA   $4B80,X
1583               STA   $4F80,X
1584               STA   $5380,X
1585               STA   $5780,X
1586               STA   $5B80,X
1587               STA   $5F80,X
1588
1589               STA   $4028,X
1590               STA   $4428,X
1591               STA   $4828,X
1592               STA   $4C28,X
1593               STA   $5028,X
1594               STA   $5428,X
1595               STA   $5828,X
1596               STA   $5C28,X
1597
1598               STA   $40A8,X
1599               STA   $44A8,X
1600               STA   $48A8,X
1601               STA   $4CA8,X
1602               STA   $50A8,X
1603               STA   $54A8,X
1604               STA   $58A8,X
1605               STA   $5CA8,X
1606*
1607               STA   $4128,X
1608               STA   $4528,X
1609               STA   $4928,X
1610               STA   $4D28,X
1611               STA   $5128,X
1612               STA   $5528,X
1613               STA   $5928,X
1614               STA   $5D28,X
1615
1616               STA   $41A8,X
1617               STA   $45A8,X
1618               STA   $49A8,X
1619               STA   $4DA8,X
1620               STA   $51A8,X
1621               STA   $55A8,X
1622               STA   $59A8,X
1623               STA   $5DA8,X
1624
1625               STA   $4228,X
1626               STA   $4628,X
1627               STA   $4A28,X
1628               STA   $4E28,X
1629               STA   $5228,X
1630               STA   $5628,X
1631               STA   $5A28,X
1632               STA   $5E28,X
1633
1634               STA   $42A8,X
1635               STA   $46A8,X
1636               STA   $4AA8,X
1637               STA   $4EA8,X
1638               STA   $52A8,X
1639               STA   $56A8,X
1640               STA   $5AA8,X
1641               STA   $5EA8,X
1642
1643               STA   $4328,X
1644               STA   $4728,X
1645               STA   $4B28,X
1646               STA   $4F28,X
1647               STA   $5328,X
1648               STA   $5728,X
1649               STA   $5B28,X
1650               STA   $5F28,X
1651
1652               STA   $43A8,X
1653               STA   $47A8,X
1654               STA   $4BA8,X
1655               STA   $4FA8,X
1656               STA   $53A8,X
1657               STA   $57A8,X
1658               STA   $5BA8,X
1659               STA   $5FA8,X
1660*
1661               STA   $4050,X
1662               STA   $4450,X
1663               STA   $4850,X
1664               STA   $4C50,X
1665               STA   $5050,X
1666               STA   $5450,X
1667               STA   $5850,X
1668               STA   $5C50,X
1669
1670               STA   $40D0,X
1671               STA   $44D0,X
1672               STA   $48D0,X
1673               STA   $4CD0,X
1674               STA   $50D0,X
1675               STA   $54D0,X
1676               STA   $58D0,X
1677               STA   $5CD0,X
1678
1679               STA   $4150,X
1680               STA   $4550,X
1681               STA   $4950,X
1682               STA   $4D50,X
1683               STA   $5150,X
1684               STA   $5550,X
1685               STA   $5950,X
1686               STA   $5D50,X
1687
1688               STA   $41D0,X
1689               STA   $45D0,X
1690               STA   $49D0,X
1691               STA   $4DD0,X
1692               STA   $51D0,X
1693               STA   $55D0,X
1694               STA   $59D0,X
1695               STA   $5DD0,X
1696
1697               INX
1698               CPX   #29
1699               BEQ   UDRW2RTS
1700               JMP   UDRWLP2
1701UDRW2RTS       RTS
1702*
1703********************************
1704* FAST LINE DRAW               *
1705********************************
1706*
1707*
1708HBASL          EQU   $07        ; DOUBLE ZPAGE ADRESS USE!!!
1709XPOSL          EQU   $7C
1710XPOSH          EQU   $7D
1711YPOSN          EQU   $7E
1712DELTAXL        EQU   $7F
1713DELTAXH        EQU   $80
1714DELTAY         EQU   $85
1715COUNT          EQU   $86
1716COUNTH         EQU   $87
1717DIFF           EQU   $88
1718DIFFH          EQU   $8D
1719ANDMSK         EQU   $8E
1720WIDEFLAG       EQU   $8F
1721*
1722LINEDRAW       LDA   XTO        ; WHICH X-VALUE IS ON THE LEFT?
1723               SEC
1724               SBC   XDRAW
1725               TAX
1726               BEQ   CHKVERT    ; LOW BYTE EVEN CHECK VERTICAL
1727               LDA   XTO+1
1728               SBC   XDRAW+1
1729               BCS   LX0LEFT
1730*
1731LX0RIGHT       EOR   #$FF       ; INVERT HI-BYTE
1732               STA   DELTAXH    ; STORE HI-BYTE
1733               TXA
1734               EOR   #$FF       ; INVERT LO-BYTE
1735               STA   DELTAXL
1736               INC   DELTAXL    ; TWO'S COMPLEMENT
1737               BNE   NOINCHI    ; ROLLED INTO HI-BYTE?
1738               INC   DELTAXH    ; YES
1739NOINCHI        LDA   XTO        ; START WITH XTO
1740               STA   XPOSL
1741               LDA   XTO+1
1742               STA   XPOSH
1743               LDA   YTO
1744               STA   YPOSN
1745               SEC
1746               SBC   YDRAW      ; DELTA-Y?
1747               JMP   LNCOMMON
1748*
1749CHKVERT        LDA   XTO+1      ; DIFF IN HI-BYTES?
1750               SBC   XDRAW+1    ; CARRY STILL SET
1751               BLT   LX0RIGHT   ; WIDTH = 256, XDRAW RIGHT
1752               BNE   LX0LEFT    ; WIDTH = 256, XDRAW LEFT
1753               JMP   VERTLINE
1754*
1755LX0LEFT        STX   DELTAXL    ; XDRAW IS LEFT
1756               STA   DELTAXH
1757               LDA   XDRAW      ; START WITH XDRAW
1758               STA   XPOSL
1759               LDA   XDRAW+1
1760               STA   XPOSH
1761               LDA   YDRAW
1762               STA   YPOSN      ; GET DELTA-Y
1763               SEC
1764               SBC   YTO
1765*
1766LNCOMMON       BCS   LPOSY
1767               EOR   #$FF       ; INVERT IF NEGATIVE
1768               ADC   #$01
1769               STA   DELTAY
1770               LDA   #$E8       ; INX
1771               BNE   GOTDY
1772LPOSY          STA   DELTAY
1773               LDA   #$CA       ; DEX
1774GOTDY          STA   LHMODY     ; SELF-MODIFYING CODE
1775               STA   LVMODY
1776               STA   LWMODY
1777*
1778* CHECK DOMINANCE
1779*
1780               LDY   #$01
1781               LDA   DELTAXL
1782               LDX   DELTAXH
1783               BNE   HORIDOM    ; WIDTH > 256
1784               CMP   #$FF       ; WIDTH = 255
1785               BEQ   HORIDOM
1786               DEY              ; NOT WIDE
1787               CMP   DELTAY
1788               BGE   HORIDOM    ; IF DIAGONAL
1789               JMP   VERTDOM
1790*
1791HORIDOM        STY   WIDEFLAG   ; HORIZONTAL IS DOMINANT
1792               STA   COUNT      ; COUNT = DELTAX + 1
1793               INC   COUNT
1794               LSR              ; DIFF = DELTAX / 2
1795               STA   DIFF
1796*
1797               LDX   XPOSL
1798               LDA   XPOSH      ; >= 256?
1799               BEQ   LOTABLE    ; NO -> USE LO-TABLE
1800               LDY   DIV7HI,X
1801               LDA   MOD7HI,X
1802               BPL   GOTTAB     ; BRANCH ALWAYS
1803LOTABLE        LDY   DIV7LO,X
1804               LDA   MOD7LO,X
1805GOTTAB         TAX
1806               LDA   ANDMASK,X
1807               STA   ANDMSK
1808*
1809               LDX   YPOSN
1810               LDA   YLOOKLO,X
1811               STA   HBASL
1812               LDA   YLOOKHI,X
1813               ORA   G_PAGE
1814               STA   HBASL+1
1815               LDA   WIDEFLAG
1816               BEQ   NOTWIDE
1817               JMP   WIDEDOM
1818NOTWIDE        JMP   HORZLOOP
1819HRTS           RTS
1820*
1821HNOROLL        STA   DIFF       ; LOOP BOTTOM
1822HDECC          DEC   COUNT
1823               BEQ   HRTS
1824*
1825HORZLOOP       LDA   (HBASL),Y  ; PLOT PIXEL
1826               ORA   ANDMSK     ; SET ADDITIONAL POINTS
1827               STA   (HBASL),Y  ; STORE POINTS
1828*
1829               LDA   ANDMSK     ; MOVE RIGHT
1830               ASL              ; SHIFT & LOSE HI-BIT
1831               EOR   #$80       ; SET HI-BIT
1832               BNE   NOH8       ; IF HI-BIT IS CLEARED
1833               INY              ; NEXT BYTE
1834               LDA   #$81       ; RESET
1835NOH8           STA   ANDMSK
1836*
1837               LDA   DIFF       ; UPDATE ERROR DIFFERENCE
1838               SEC
1839               SBC   DELTAY
1840               BCS   HNOROLL
1841               ADC   DELTAXL
1842               STA   DIFF
1843LHMODY         INX              ; MODIFYABLE
1844               LDA   YLOOKLO,X
1845               STA   HBASL
1846               LDA   YLOOKHI,X
1847               ORA   G_PAGE     ; ACTIVE PAGE
1848               STA   HBASL+1
1849               BNE   HDECC
1850*
1851VERTDOM        LDX   YDRAW
1852               CPX   YPOSN
1853               BNE   ENDY0
1854               LDX   YTO
1855ENDY0          STX   LVCHK+1
1856               LDA   DELTAY
1857               LSR
1858               STA   DIFF
1859*
1860               LDX   XPOSL
1861               LDA   XPOSH
1862               BEQ   LOTABLL
1863               LDY   DIV7HI,X
1864               LDA   MOD7HI,X
1865               BPL   GOTTAB2
1866LOTABLL        LDY   DIV7LO,X
1867               LDA   MOD7LO,X
1868GOTTAB2        TAX
1869               LDA   ANDMASK,X
1870               STA   ANDMSK
1871               LDX   YPOSN
1872               JMP   VERTLOOP
1873*
1874VNOROLL        STA   DIFF
1875VERTLOOP       LDA   YLOOKLO,X
1876               STA   HBASL
1877               LDA   YLOOKHI,X
1878               ORA   G_PAGE
1879               STA   HBASL+1
1880LLMDV          LDA   (HBASL),Y  ; PLOT PIXEL
1881               ORA   ANDMSK     ; SET ADDITIONAL POINTS
1882               STA   (HBASL),Y  ; STORE POINTS
1883LVCHK          CPX   #$00
1884               BEQ   VRTS
1885LVMODY         INX
1886               LDA   DIFF
1887               SEC
1888               SBC   DELTAXL
1889               BCS   VNOROLL
1890               ADC   DELTAY
1891               STA   DIFF
1892               LDA   ANDMSK     ; MOVE RIGHT
1893               ASL
1894               EOR   #$80
1895               BEQ   IS8
1896               STA   ANDMSK
1897               BNE   VERTLOOP
1898*
1899IS8            INY
1900               LDA   #$81
1901               STA   ANDMSK
1902               BNE   VERTLOOP
1903VRTS           RTS
1904*
1905WIDEDOM        LDA   DELTAXH
1906               STA   COUNTH
1907               LDX   DELTAXL
1908               STX   COUNT
1909               STX   DIFF
1910               LSR
1911               ROR   DIFF
1912               STA   DIFFH
1913               LDX   YPOSN
1914*
1915WIDELOOP       LDA   (HBASL),Y  ; PLOT PIXEL
1916               ORA   ANDMSK     ; SET ADDITIONAL POINTS
1917               STA   (HBASL),Y  ; STORE POINTS
1918               LDA   ANDMSK
1919               ASL
1920               EOR   #$80
1921               BNE   NOT7
1922               INY
1923               LDA   #$81
1924NOT7           STA   ANDMSK
1925*
1926               LDA   DIFF
1927               SEC
1928               SBC   DELTAY
1929               BCS   WNOROLL
1930               DEC   DIFFH
1931               BPL   WNOROLL
1932               ADC   DELTAXL
1933               STA   DIFF
1934               LDA   DIFFH
1935               ADC   DELTAXH
1936               STA   DIFFH
1937LWMODY         INX
1938               LDA   YLOOKLO,X
1939               STA   HBASL
1940               LDA   YLOOKHI,X
1941               ORA   G_PAGE
1942               STA   HBASL+1
1943               BNE   WDECC
1944*
1945WNOROLL        STA   DIFF
1946WDECC          DEC   COUNT
1947               LDA   COUNT
1948               CMP   #$FF
1949               BNE   WIDELOOP
1950               DEC   COUNTH
1951               BEQ   WIDELOOP
1952               RTS
1953*
1954* PURE VERTICAL LINE
1955*
1956VERTLINE       LDX   YDRAW
1957               LDY   YTO
1958               CPX   YTO
1959               BLT   USEY0
1960               TXA
1961               TAY
1962               LDX   YTO
1963USEY0          STX   YPOSN
1964               INY
1965               STY   LPVYTEST+1
1966               LDX   XDRAW
1967               LDA   XDRAW+1
1968               BEQ   LOTABL2
1969               LDY   DIV7HI,X
1970               LDA   MOD7HI,X
1971               BPL   GOTIT
1972LOTABL2        LDY   DIV7LO,X
1973               LDA   MOD7LO,X
1974GOTIT          TAX
1975               LDA   ANDMASK,X
1976               STA   LPVAND+1
1977               LDX   YPOSN
1978*
1979PVERLOOP       LDA   YLOOKLO,X
1980               STA   HBASL
1981               LDA   YLOOKHI,X
1982               ORA   G_PAGE
1983               STA   HBASL+1
1984LLMDPV         LDA   (HBASL),Y
1985LPVAND         ORA   #$00       ; SELF-MODIFYING
1986               STA   (HBASL),Y
1987               INX
1988LPVYTEST       CPX   #$00
1989               BNE   PVERLOOP
1990               RTS
1991*
1992               LST  OFF
1993*
1994               CHK
1995*