Prince-of-Persia-Apple-II

A running-jumping-swordfighting game Jordan Mechner made on the Apple II from 1985-89
Log | Files | Refs | README | LICENSE

UNPACK525.S (7472B)


      1 * unpack
      2 ThreeFive = 0
      3 org = $ea00
      4  lst off
      5 *-------------------------------
      6 *
      7 *  U  N  P  A  C  K
      8 *
      9 *  Sits in main l.c. bank 2
     10 *
     11 *-------------------------------
     12  org org
     13 
     14  jmp SNGEXPAND
     15  jmp DBLEXPAND
     16  jmp DELTAEXPPOP
     17  jmp INVERTY
     18  jmp DELTAEXPWIPE
     19 
     20  jmp PURPLE
     21  jmp PROMPT
     22  jmp BLACKOUT
     23  jmp CLR
     24  jmp TEXT
     25 
     26  jmp SETDHIRES
     27 
     28 *-------------------------------
     29  lst
     30  put gameeq
     31  lst
     32  put eq
     33  lst off
     34 
     35 IOUDISoff = $c07f
     36 IOUDISon = $c07e
     37 DHIRESoff = $c05f
     38 DHIRESon = $c05e
     39 HIRESon = $c057
     40 HIRESoff = $c056
     41 PAGE2on = $c055
     42 PAGE2off = $c054
     43 MIXEDon = $c053
     44 MIXEDoff = $c052
     45 TEXTon = $c051
     46 TEXToff = $c050
     47 ALTCHARon = $c00f
     48 ALTCHARoff = $c00e
     49 ADCOLon = $c00d
     50 ADCOLoff = $c00c
     51 ALTZPon = $c009
     52 ALTZPoff = $c008
     53 RAMWRTaux = $c005
     54 RAMWRTmain = $c004
     55 RAMRDaux = $c003
     56 RAMRDmain = $c002
     57 ADSTOREon = $c001
     58 ADSTOREoff = $c000
     59 
     60 RWBANK2 = $c083
     61 RWBANK1 = $c08b
     62 
     63 POPside1 = $a9
     64 POPside2 = $ad
     65 
     66 *-------------------------------
     67 *
     68 *  Unpack single hi-res screen into page 1
     69 *  (Sorry about the code--it's lifted directly from DRAZ)
     70 *
     71 *-------------------------------
     72  dum $00
     73 
     74 PAC ds 2
     75 PIC ds 2
     76 V2 ds 1
     77 V3 ds 1
     78 V4 ds 1
     79 V5 ds 1
     80 V8 ds 1
     81 V9 ds 1
     82 VA ds 1
     83 VB ds 1
     84 VC ds 1
     85 
     86  dend
     87 
     88 *-------------------------------
     89 SNGEXPAND
     90  sta RAMRDaux
     91  sta RAMWRTmain
     92 
     93  STA PAC+1 ;org addr
     94 
     95  LDA #$20
     96  STA PIC+1 ;dest addr
     97 
     98  LDA #0
     99  STA PAC
    100  STA PIC
    101 
    102  LDA #$FE
    103  STA V8
    104  LDA #0
    105  STA VA
    106  LDY #$27
    107 :4 LDA #$78
    108  STA V2
    109  LDA #$20
    110  STA V3
    111 :0 LDA V2
    112  SEC
    113  SBC #$28
    114  STA V2
    115  BCS :1
    116  DEC V3
    117 :1 LDA V2
    118  STA V4
    119  LDA V3
    120  CLC
    121  ADC #4
    122  STA V5
    123 :2 LDA V4
    124  SEC
    125  SBC #$80
    126  STA V4
    127  BCS :3
    128  DEC V5
    129 :3 LDA V4
    130  STA PIC
    131  LDA V5
    132  CLC
    133  ADC #$20
    134  STA PIC+1
    135 :5 LDA PIC+1
    136  SEC
    137  SBC #4
    138  STA PIC+1
    139  CLC
    140  BCC :6
    141 :13 LDA PIC+1
    142  CMP V5
    143  BNE :5
    144  LDA V4
    145  CMP V2
    146  BNE :2
    147  LDA V5
    148  CMP V3
    149  BNE :2
    150  LDA V2
    151  BNE :0
    152  DEY
    153  BPL :4
    154  RTS
    155 :6 BIT VA
    156  BMI :11
    157  LDX #0
    158  LDA (PAC,X)
    159  STA VB
    160  CMP V8
    161  BNE :10
    162  INC PAC
    163  BNE :7
    164  INC PAC+1
    165 :7 LDA (PAC,X)
    166  STA V9
    167  INC PAC
    168  BNE :8
    169  INC PAC+1
    170 :8 LDA (PAC,X)
    171  STA VB
    172  INC PAC
    173  BNE :9
    174  INC PAC+1
    175 :9 LDA #$80
    176  STA VA
    177  CLC
    178  BCC :11
    179 :10 LDA VB
    180  ORA #$80
    181  STA (PIC),Y
    182  INC PAC
    183  BNE :12
    184  INC PAC+1
    185 :12 CLC
    186  BCC :13
    187 :11 LDA VB
    188  ORA #$80
    189  STA (PIC),Y
    190  DEC V9
    191  BNE :13
    192  LDA #0
    193  STA VA
    194  BEQ :13
    195 
    196 *-------------------------------
    197 *
    198 *  Unpack crunched double hi-res screen
    199 *
    200 *  Robert A. Cook 3/89
    201 *
    202 *  In: A = hi byte of crunched data address
    203 *      RAMRD set to main/aux depending on where crunched
    204 *        data is stored
    205 *
    206 *-------------------------------
    207 
    208  dum $f0
    209 
    210 CrnDatPtr ds 2
    211 XClmPos ds 1
    212 YScrPos ds 1
    213 ByteHld ds 1
    214 RepeatCdn ds 1
    215 ScrBasPtr ds 2
    216 
    217  dend
    218 
    219 *-------------------------------
    220 DBLEXPAND
    221  sta CrnDatPtr+1
    222 
    223  lda #1
    224  sta CrnDatPtr
    225 ;(CrnDatPtr),0 is crunch type (unused)
    226  jmp WipeRgtExp
    227 
    228 *-------------------------------
    229 *
    230 *  Wipe Right Expand
    231 *
    232 *-------------------------------
    233 WipeRgtExp
    234  lda #0
    235  sta XClmPos
    236 
    237 :Loop lda #0
    238  sta YScrPos
    239  jsr ExpandClm
    240 
    241  lda #1
    242  sta YScrPos
    243  jsr ExpandClm
    244 
    245  inc XClmPos
    246 
    247  lda XClmPos
    248  cmp #80
    249  bne :Loop
    250 
    251 ]rts rts
    252 
    253 *-------------------------------
    254 *
    255 *  Delta Expand
    256 *
    257 *  In: A = hi byte of crunched data address (in auxmem)
    258 *
    259 *-------------------------------
    260 DeltaExp
    261  sta RAMRDaux
    262 
    263  sta CrnDatPtr+1
    264 
    265  lda #0
    266  sta CrnDatPtr
    267 
    268  sta XClmPos
    269 
    270 :Loop ldy #0
    271  lda (CrnDatPtr),y
    272  cmp #-1
    273  beq :Done
    274 
    275  sta ByteHld
    276  and #$80
    277  beq :ExpandOne
    278 
    279  lda ByteHld
    280  and #$7f
    281  beq :NewCoord
    282 
    283  tax
    284 
    285  ldy #1
    286  lda (CrnDatPtr),y
    287  jsr ExpClmSeq1
    288 
    289  clc
    290  lda CrnDatPtr
    291  adc #2
    292  sta CrnDatPtr
    293  bcc :a4
    294  inc CrnDatPtr+1
    295 :a4
    296  jmp :Next
    297 
    298 :NewCoord
    299  ldy #1
    300  lda (CrnDatPtr),y
    301  sta XClmPos
    302 
    303  ldy #2
    304  lda (CrnDatPtr),y
    305  sta YScrPos
    306 
    307  clc
    308  lda CrnDatPtr
    309  adc #3
    310  sta CrnDatPtr
    311  bcc :a7
    312  inc CrnDatPtr+1
    313 :a7
    314  jmp :Next
    315 
    316 :ExpandOne
    317  lda ByteHld
    318  ldx #1
    319  jsr ExpClmSeq1
    320 
    321  inc CrnDatPtr
    322  bne :sysi8
    323  inc CrnDatPtr+1
    324 :sysi8
    325 
    326 :Next lda XClmPos
    327  cmp #$80
    328  bne :Loop
    329 
    330 :Done sta RAMRDmain
    331 ]rts rts
    332 
    333 *-------------------------------
    334 *
    335 *  Expand Column
    336 *
    337 *-------------------------------
    338 ExpandClm
    339 
    340 :Loop ldy #0
    341  lda (CrnDatPtr),y
    342  sta ByteHld
    343  and #$80
    344  beq :ExpandOne
    345 
    346  ldy #1
    347  lda (CrnDatPtr),y
    348  tax
    349  lda ByteHld
    350  and #$7f
    351  jsr ExpClmSeq
    352 
    353  clc
    354  lda CrnDatPtr
    355  adc #2
    356  sta CrnDatPtr
    357  bcc :a4
    358  inc CrnDatPtr+1
    359 :a4
    360  jmp :Next
    361 
    362 :ExpandOne
    363  lda ByteHld
    364  ldx #1
    365  jsr ExpClmSeq
    366 
    367  inc CrnDatPtr
    368  bne :sysi5
    369  inc CrnDatPtr+1
    370 :sysi5
    371 
    372 :Next lda YScrPos
    373  cmp #192
    374  bcc :Loop
    375 
    376  rts
    377 
    378 *-------------------------------
    379 *
    380 *  Expand Column Sequence
    381 *
    382 *-------------------------------
    383 *
    384 *  In: XClmPos
    385 *      YScrPos
    386 *      A (byte pattern)
    387 *      X (repeat count)
    388 *
    389 *  Out: YScrPos (modified)
    390 *
    391 *-------------------------------
    392 ExpClmSeq
    393  sta ByteHld
    394  stx RepeatCdn
    395 
    396 :Loop ldx XClmPos
    397  ldy YScrPos
    398  lda ByteHld
    399  jsr PutScrByte
    400 
    401  lda YScrPos
    402  clc
    403  adc #2
    404  sta YScrPos
    405 
    406  dec RepeatCdn
    407  bne :Loop
    408 
    409  rts
    410 
    411 *-------------------------------
    412 *
    413 * Expand Column Sequence 1
    414 *
    415 *-------------------------------
    416 ExpClmSeq1
    417  sta ByteHld
    418  stx RepeatCdn
    419 
    420 :Loop ldx XClmPos
    421  ldy YScrPos
    422  lda ByteHld
    423  bmi :Next
    424 
    425  jsr PutScrByte
    426 
    427 :Next inc YScrPos
    428 
    429  lda YScrPos
    430  cmp #192
    431  bne :SkipXInc
    432 
    433  lda #0
    434  sta YScrPos
    435 
    436  inc XClmPos
    437 
    438 :SkipXInc
    439  dec RepeatCdn
    440  bne :Loop
    441 
    442  rts
    443 
    444 *-------------------------------
    445 *
    446 *  Put DHires Byte Value
    447 *
    448 *-------------------------------
    449 *
    450 *  In:  X (XClmPos)
    451 *       Y (YScrPos)
    452 *       A (Byte value)
    453 *
    454 *-------------------------------
    455 PutScrByte
    456  sta ByteHld
    457  ;YScrPos in Y
    458  lda YLO,y
    459  sta ScrBasPtr
    460  lda YHI,y
    461  ora #$20 ;DHires page 1
    462  sta ScrBasPtr+1
    463 
    464  txa ;XClmPos in X
    465  lsr
    466  tay
    467  bcs NoAuxSet
    468 
    469  sta RAMWRTaux
    470 
    471 NoAuxSet lda ByteHld
    472  sta (ScrBasPtr),y
    473 
    474  sta RAMWRTmain
    475 
    476 ]rts rts
    477 
    478 *-------------------------------
    479 *
    480 * P U R P L E
    481 *
    482 *-------------------------------
    483  do ThreeFive
    484 PURPLE rts
    485 
    486  else
    487  put purple
    488  fin
    489 
    490 *-------------------------------
    491 *
    492 *  Delta Expand (Pop or Wipe)
    493 *
    494 *  In: A = hi byte of crunched data address (in auxmem)
    495 *
    496 *-------------------------------
    497 DELTAEXPPOP
    498  sta PAGE2on
    499 ]DE jsr DeltaExp
    500  sta PAGE2off
    501  sta RAMRDaux
    502  sta RAMWRTaux
    503 ]rts rts
    504 
    505 DELTAEXPWIPE
    506  sta PAGE2off
    507  jmp ]DE
    508 
    509 *-------------------------------
    510 *
    511 * Invert Y-tables
    512 *
    513 *-------------------------------
    514 INVERTY
    515  ldx #191 ;low line
    516  ldy #0 ;high line
    517 
    518 * Switch low & high lines
    519 
    520 :loop lda YLO,x
    521  pha
    522  lda YLO,y
    523  sta YLO,x
    524  pla
    525  sta YLO,y
    526 
    527  lda YHI,x
    528  pha
    529  lda YHI,y
    530  sta YHI,x
    531  pla
    532  sta YHI,y
    533 
    534 * Move 1 line closer to ctr
    535 
    536  dex
    537  iny
    538  cpy #96
    539  bcc :loop
    540 ]rts rts
    541 
    542 *-------------------------------
    543 *
    544 * Prompt user to insert correct disk side
    545 *
    546 *-------------------------------
    547  do ThreeFive
    548 msg1 asc "    Insert Prince of Persia Disk@"
    549  else
    550 msg1 asc "Insert Prince of Persia Disk, Side "
    551  fin
    552 
    553 msg2 asc "C@"
    554 
    555 *-------------------------------
    556 PROMPT
    557  lda #"A"
    558  ldx BBundID
    559  cpx #POPside1
    560  beq :1
    561  lda #"B"
    562 :1 sta msg2 ;side A or B?
    563 
    564  jsr blackout
    565 
    566  sta RAMWRTmain
    567 
    568  ldx #0
    569 :loop lda msg1,x
    570  cmp #"@"
    571  beq :done
    572  sta $528+2,x ;midscrn
    573  inx
    574  bpl :loop
    575 
    576 :done sta RAMWRTaux
    577  jsr whoop ;whoop spkr
    578 
    579 :wloop lda $c000
    580  ora $c061
    581  ora $c062
    582  bpl :wloop
    583  sta $c010
    584 
    585  jmp clr ;clear screen
    586 
    587 *-------------------------------
    588 CLR bit RWBANK2
    589  bit RWBANK2
    590 
    591  sta $c010
    592 
    593  lda #" "
    594  jmp _lrcls ;in hires
    595 
    596 *-------------------------------
    597 *
    598 * Show black screen (text page 1)
    599 *
    600 *-------------------------------
    601 BLACKOUT
    602  jsr CLR
    603 
    604 TEXT sta RAMRDaux
    605  jsr vblank
    606  sta TEXTon
    607  sta ADCOLoff
    608  sta PAGE2off
    609 ]rts rts
    610 
    611 *-------------------------------
    612 * Set dbl hires
    613 *-------------------------------
    614 SETDHIRES
    615  sta RAMRDaux
    616  sta RAMWRTaux
    617  jsr vblank
    618  sta ADCOLon
    619  bit HIRESon
    620 
    621  bit DHIRESon
    622  bit DHIRESoff
    623  bit DHIRESon
    624  bit DHIRESoff
    625  bit DHIRESon ;for old Apple RGB card
    626 
    627  sta TEXToff
    628  rts
    629 
    630 *-------------------------------
    631  lst
    632 eof ds 1
    633  usr $a9,2,$a00,*-org
    634  lst off