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

DEBUGS.S (9861B)


      1 * debugs
      2 EditorDisk = 0
      3 org = $fc00
      4 load = $4c00
      5  lst off
      6 *-------------------------------
      7 *
      8 *  " D E B U G S "
      9 *
     10 *  Sits in aux language card--called from auxmem
     11 *
     12 *-------------------------------
     13  org org
     14 
     15  jmp _SHOWPAGE
     16  jmp DEBUGKEYS
     17 
     18  clc
     19  bcc MOVEAUXLC ;must be relocatable
     20 
     21  jmp _TITLESCREEN
     22 
     23 *-------------------------------
     24 *
     25 *  M O V E A U X L C
     26 *  (Move to auxiliary language card)
     27 *
     28 *  This code is loaded into mainmem, where MASTER calls it
     29 *  to move itself & all other aux l.c. stuff to aux l.c.
     30 *
     31 *  WARNING--once in aux l.c. this code is useless!
     32 *
     33 *  Returns control to main l.c. bank 1
     34 *
     35 *-------------------------------
     36 MOVEAUXLC
     37  sta $c009 ;ALTZP on (aux l.c.)
     38 
     39  bit $c083
     40  bit $c083 ;bank 2
     41 
     42  lda #$d0
     43  ldx #$20
     44  ldy #$50
     45  jsr Tmovemem
     46 
     47  bit $c08b
     48  bit $c08b ;bank 1
     49 
     50  do EditorDisk
     51  else
     52 
     53  lda #$d0
     54  ldx #$50
     55  ldy #$60
     56  jsr Tmovemem
     57 
     58  fin
     59 
     60  sta $c008 ;ALTZP off (main l.c.)
     61  rts
     62 
     63 *-------------------------------
     64 * "MOVEMEM"
     65 
     66  dum $00
     67 ]dest ds 2
     68 ]source ds 2
     69 ]endsourc ds 2
     70  dend
     71 
     72 movemem sta ]dest+1
     73  stx ]source+1
     74  sty ]endsourc+1
     75 
     76  ldy #0
     77  sty ]dest
     78  sty ]source
     79  sty ]endsourc
     80 
     81 :loop lda (]source),y
     82  sta (]dest),y
     83 
     84  iny
     85  bne :loop
     86 
     87  inc ]source+1
     88  inc ]dest+1
     89 
     90  lda ]source+1
     91  cmp ]endsourc+1
     92  bne :loop
     93  rts
     94 
     95 Tmovemem = movemem-$fc00+$4c00
     96 
     97 *-------------------------------
     98 lastpage ds 1
     99 
    100 _SHOWPAGE jsr pre
    101  jsr SHOWPAGE
    102  jmp post
    103 
    104 _TITLESCREEN jsr pre
    105  jsr TITLESCREEN
    106  jmp post
    107 
    108 *-------------------------------
    109 pre
    110  pha
    111 
    112  jsr saveregs
    113  jsr mainmem
    114  jsr savezero
    115 
    116  pla
    117 ]rts rts
    118 
    119 post
    120  jsr loadzero
    121  jsr auxmem
    122  jmp loadregs
    123 
    124 *-------------------------------
    125 mainmem
    126  sta $c004
    127  sta $c002
    128  rts
    129 
    130 *-------------------------------
    131 auxmem
    132  sta $c005
    133  sta $c003
    134 ]rts rts
    135 
    136 *-------------------------------
    137 regs ds 3
    138 *-------------------------------
    139  dum $00
    140 
    141 base ds 2
    142 tab ds 1
    143 line ds 1
    144 inverse ds 1
    145 bytenum ds 1
    146 mempage ds 1
    147 oldpage ds 1
    148 strptr ds 2
    149 xsave ds 1
    150 ysave ds 1
    151 nextbytenum ds 1
    152 direcptr ds 1
    153 ztemp ds 1
    154 old80col ds 1
    155 
    156  dend
    157 
    158 zerodump = $fa00 ;mainmem
    159 pagedump = $fb00 ;mainmem
    160 
    161 eol = $8d ;string delimiter
    162 
    163 *-------------------------------
    164 * Keys within routines
    165 
    166 kesc = $9b
    167 kpageup = $8b
    168 kpagedown = $8a
    169 k4kup = $95
    170 k4kdown = $88
    171 khires = "H"
    172 
    173 *-------------------------------
    174 *
    175 *  D E B U G   K E Y S
    176 *
    177 *  In:  A = kbd value
    178 *
    179 *-------------------------------
    180 kshowzero = "=
    181 kshowpage3 = "\
    182 kshowlastpage = "-
    183 
    184 DEBUGKEYS
    185  cmp #kshowzero
    186  bne :1
    187 
    188  lda #0
    189  jmp _SHOWPAGE
    190 
    191 :1 cmp #kshowpage3
    192  bne :4
    193 
    194  lda #3
    195  jmp _SHOWPAGE
    196 :4
    197  cmp #kshowlastpage
    198  bne ]rts
    199 
    200  lda lastpage
    201  jmp _SHOWPAGE
    202 
    203 *-------------------------------
    204 *
    205 *  S H O W P A G E
    206 *
    207 *  Show page on text page 1; any key to exit
    208 *  Keys 0-9 to change page #
    209 *
    210 *  In: A = initial page #
    211 *
    212 *-------------------------------
    213 SHOWPAGE
    214  pha
    215  jsr pretext
    216  pla
    217 
    218 newdump  ;A = page #
    219  jsr  PageDump ;dump a page of memory
    220  jsr RegsDump ;dump registers
    221 
    222 :loop jsr waitloop
    223 
    224  cmp #"0
    225  bcc :1
    226  cmp #":
    227  bcs :1
    228 
    229  sec
    230  sbc #"0
    231  jmp newdump ;dump new page
    232 
    233 :1 cmp #kpageup
    234  bne :2
    235  lda #-1
    236  jmp chgpg ;change page
    237 
    238 :2 cmp #kpagedown
    239  bne :3
    240  lda #1
    241  jmp chgpg
    242 
    243 :3 cmp #k4kup
    244  bne :4
    245  lda #$10
    246  jmp chgpg
    247 
    248 :4 cmp #k4kdown
    249  bne :5
    250  lda #$f0
    251  jmp chgpg
    252 
    253 :5 cmp #khires
    254  bne :6
    255 
    256  jsr showhires
    257  jsr waitloop
    258  jsr showtext
    259  jmp :loop
    260 
    261 :6
    262 :exit
    263  jmp posttext
    264 
    265 *-------------------------------
    266 * Change page
    267 *
    268 * In: A = increment
    269 *
    270 * Lock out pages C0-CF
    271 *-------------------------------
    272 chgpg
    273  sta ztemp
    274 
    275  lda mempage
    276 :loop clc
    277  adc ztemp
    278 
    279  cmp #$c0
    280  bcc :ok
    281  cmp #$d0
    282  bcc :loop
    283 
    284 :ok sta mempage
    285 
    286  jmp newdump
    287 
    288 *-------------------------------
    289 *
    290 *  P R E T E X T / P O S T T E X T
    291 *
    292 *-------------------------------
    293 pretext
    294  lda $c01f ;read 80COL
    295  sta old80col
    296 
    297  lda $c01c ;read PAGE2
    298  sta oldpage
    299 
    300  jsr textcls
    301 
    302 showtext
    303  lda $c054 ;page 1
    304  lda $c051 ;text
    305  sta $c00c ;40-column
    306 
    307  rts
    308 
    309 *-------------------------------
    310 posttext
    311  lda mempage
    312  sta lastpage ;for next time
    313 
    314  jsr showhires
    315 
    316  lda #$00 ;black
    317  jmp cls40
    318 
    319 *-------------------------------
    320 * Show orig. hires page
    321 
    322 showhires
    323  lda oldpage ;original page
    324  bpl :1 ;page 1
    325  lda $c055 ;page 2
    326 :1
    327  lda old80col
    328  bpl :2
    329  sta $c00d ;80-col on
    330 :2
    331  lda $c050 ;graphics
    332  rts
    333 
    334 *-------------------------------
    335 *
    336 *  P A G E D U M P
    337 *
    338 *  In: A = page # (auxmem)
    339 *
    340 *  Locks out $c0-cf
    341 *
    342 *-------------------------------
    343 PageDump
    344  sta mempage
    345 
    346  cmp #$c0
    347  bcc :ok
    348  cmp #$d0
    349  bcs :ok
    350  rts  ;lock out $c0-cf
    351 :ok
    352  jsr copypage ;to mainmem
    353 
    354  jsr home
    355  jsr normal
    356 
    357  lda #STRpage
    358  ldx #>STRpage
    359  jsr prline ;"Page "
    360 
    361  lda mempage
    362  jsr prhexbyte
    363 
    364  jsr inv
    365 
    366  lda #0
    367  sta bytenum
    368 
    369  lda #8
    370  sta tab
    371 
    372 :rulerloop
    373  lda #" "
    374  jsr prchar
    375 
    376  lda bytenum
    377  jsr prhexdig
    378 
    379  jsr toggle
    380 
    381  inc bytenum
    382 
    383  lda bytenum
    384  cmp #$10
    385  bne :rulerloop
    386 
    387  jsr cr
    388  jsr cr
    389 
    390  lda #0
    391  sta bytenum
    392 :nextline
    393  jsr normal
    394  lda #"$"
    395  jsr prchar
    396 
    397  lda mempage
    398  jsr prhexbyte
    399 
    400  lda bytenum
    401  jsr prhexbyte
    402 
    403  lda #":"
    404  jsr prchar
    405 
    406  lda #8
    407  sta tab
    408 
    409 * Print next 16 byte values
    410 
    411  lda bytenum
    412  tax
    413  clc
    414  adc #$10
    415  sta nextbytenum
    416 
    417 :loop stx xsave
    418 
    419  jsr toggle
    420 
    421  lda pagedump,x
    422  jsr prhexbyte
    423 
    424  ldx xsave
    425  inx
    426  cpx nextbytenum
    427  bne :loop
    428 
    429 * Next line
    430 
    431  cpx #0
    432  beq :rts
    433  stx bytenum
    434 
    435  jsr cr
    436 
    437  jmp :nextline
    438 
    439 :rts rts
    440 
    441 *-------------------------------
    442 *
    443 *  R E G S D U M P
    444 *
    445 *-------------------------------
    446 RegsDump
    447  jsr normal
    448 
    449  ldx #19
    450  jsr setline
    451 
    452  ldx #0
    453  lda #"A"
    454  jsr printreg
    455 
    456  ldx #1
    457  lda #"X"
    458  jsr printreg
    459 
    460  ldx #2
    461  lda #"Y"
    462  jsr printreg
    463 
    464  rts
    465 
    466 *-------------------------------
    467 printreg
    468  stx xsave
    469 
    470  jsr prchar
    471  inc tab
    472 
    473  lda #"="
    474  jsr prchar
    475  inc tab
    476 
    477  ldx xsave
    478  lda regs,x
    479  jsr prhexbyte
    480 
    481  lda tab
    482  clc
    483  adc #5
    484  sta tab
    485  rts
    486 
    487 *-------------------------------
    488 *
    489 *  W A I T L O O P
    490 *
    491 *  Wait for keypress (return in A, hibit set)
    492 *
    493 *-------------------------------
    494 waitloop
    495  sta $c010
    496 
    497 :loop lda $c000
    498  bpl :loop
    499 
    500  rts
    501 
    502 *-------------------------------
    503 *  C R
    504 *-------------------------------
    505 cr
    506  lda #0
    507  sta tab
    508 
    509  inc line
    510  ldx line
    511  jmp bascalc
    512 
    513 *-------------------------------
    514 *
    515 *  P R L I N E
    516 *
    517 *  Print a line of normal text
    518 *
    519 *  In: A-X = string ptr
    520 *
    521 *-------------------------------
    522 prline
    523  sta strptr
    524  stx strptr+1
    525 :loop
    526  ldy #0
    527  lda (strptr),y
    528  cmp #eol
    529  beq :rts
    530 
    531  jsr prcharn
    532 
    533  inc strptr
    534  bne :loop
    535  inc strptr+1
    536  bne :loop
    537 
    538 :rts rts
    539 
    540 *-------------------------------
    541 *
    542 *  P R H E X B Y T E
    543 *
    544 *  Print a hex byte (in A)
    545 *
    546 *-------------------------------
    547 prhexbyte
    548  pha
    549  lsr
    550  lsr
    551  lsr
    552  lsr
    553  jsr prhexdig
    554 
    555  pla
    556  and #$0f
    557  jmp prhexdig
    558 
    559 *-------------------------------
    560 *
    561 *  P R H E X D I G
    562 *
    563 *  Print a hex digit (in A)
    564 *  Trashes X
    565 *
    566 *-------------------------------
    567 prhexdig
    568  tax
    569  lda hextoasc,x
    570  jmp prchar
    571 
    572 *-------------------------------
    573 *
    574 *  P R C H A R
    575 *
    576 *  Print an ASCII character (in A)
    577 *
    578 *-------------------------------
    579 prchar
    580  ldy tab
    581  and #%00111111
    582  ora inverse
    583  sta (base),y
    584 
    585  inc tab
    586 
    587  rts
    588 
    589 prcharn ;normal
    590  ldy tab
    591  sta (base),y
    592 
    593  inc tab
    594 
    595  rts
    596 
    597 *-------------------------------
    598 *
    599 *  H O M E
    600 *
    601 *-------------------------------
    602 home
    603  lda #0
    604  sta tab
    605 
    606  ldx #0
    607  stx line
    608 
    609  jmp bascalc
    610 
    611 *-------------------------------
    612 *
    613 *  I N V E R S E / N O R M A L
    614 *
    615 *-------------------------------
    616 normal
    617  lda #$80
    618  sta inverse
    619  rts
    620 
    621 inv
    622  lda #0
    623  sta inverse
    624  rts
    625 
    626 toggle
    627  lda inverse
    628  eor #$80
    629  sta inverse
    630  rts
    631 
    632 *-------------------------------
    633 *
    634 *  S E T L I N E
    635 *
    636 *  In: X = line #
    637 *
    638 *-------------------------------
    639 setline
    640  lda #0
    641  sta tab
    642 
    643  stx line
    644 
    645 *-------------------------------
    646 *
    647 *  B A S C A L C
    648 *
    649 *  In: X = line # (0-24)
    650 *
    651 *-------------------------------
    652 bascalc
    653  cpx #24
    654  bcs :rts
    655 
    656  lda textl,x
    657  sta base
    658 
    659  lda texth,x
    660  sta base+1
    661 
    662 :rts rts
    663 
    664 *-------------------------------
    665 *
    666 *  T E X T C L S
    667 *
    668 *  Clear text page 1 to black
    669 *
    670 *-------------------------------
    671 textcls lda #$a0 ;space
    672 
    673 cls40 ldy #$f7
    674 :2 sta $400,y
    675  sta $500,y
    676  sta $600,y
    677  sta $700,y
    678 
    679  dey
    680  cpy #$7f
    681  bne :3
    682 
    683  ldy #$77
    684 :3 cpy #$ff
    685  bne :2
    686 
    687  rts
    688 
    689 *-------------------------------
    690 *  S A V E / L O A D  R E G S
    691 *-------------------------------
    692 saveregs sta regs
    693  stx regs+1
    694  sty regs+2
    695  rts
    696 
    697 loadregs lda regs
    698  ldx regs+1
    699  ldy regs+2
    700  rts
    701 
    702 *-------------------------------
    703 *  S A V E Z E R O
    704 *-------------------------------
    705 savezero
    706  ldx #0
    707 
    708 :loop lda $00,x
    709  sta zerodump,x
    710 
    711  inx
    712  bne :loop
    713  rts
    714 
    715 *-------------------------------
    716 *  L O A D Z E R O
    717 *-------------------------------
    718 loadzero
    719  ldx #0
    720 
    721 :loop lda zerodump,x
    722  sta $00,x
    723 
    724  inx
    725  bne :loop
    726  rts
    727 
    728 *-------------------------------
    729 *  C O P Y P A G E
    730 *
    731 *  Copy desired auxmem page to "pagedump" in mainmem
    732 *
    733 *  In: A = page #
    734 *-------------------------------
    735 copypage
    736  tax
    737  beq :pagezero
    738 
    739  sta :loop+2 ;self-mod
    740 
    741  sta $c003 ;read auxmem
    742 
    743  ldx #0
    744 
    745 :loop lda $300,x
    746  sta pagedump,x
    747 
    748  inx
    749  bne :loop
    750 
    751  sta $c002 ;read mainmem
    752 
    753  rts
    754 
    755 * Read original page 0 from pagedump, not the current page 0
    756 
    757 :pagezero
    758  ldx #0
    759 :loop0 lda zerodump,x
    760  sta pagedump,x
    761  inx
    762  bne :loop0
    763  rts
    764 
    765 *-------------------------------
    766 * 40-column text base addresses
    767 *-------------------------------
    768 
    769 textl hex 00,80,00,80,00,80,00,80
    770  hex 28,a8,28,a8,28,a8,28,a8
    771  hex 50,d0,50,d0,50,d0,50,d0
    772 
    773 texth hex 04,04,05,05,06,06,07,07
    774  hex 04,04,05,05,06,06,07,07
    775  hex 04,04,05,05,06,06,07,07
    776 
    777 *-------------------------------
    778 * Hex to ASCII
    779 *-------------------------------
    780 
    781 hextoasc asc "0123456789ABCDEF"
    782 
    783 *-------------------------------
    784 TITLESCREEN
    785  jsr pretext
    786  jsr textcls
    787 
    788  jsr home
    789  jsr normal
    790 
    791  lda #title
    792  ldx #>title
    793  jsr prline
    794 
    795  ldx #3
    796  jsr setline
    797  lda #date
    798  ldx #>date
    799  jsr prline
    800 
    801  ldx #11
    802  jsr setline
    803  lda #please
    804  ldx #>please
    805  jsr prline
    806 
    807  ldx #23
    808  jsr setline
    809  lda #copyr
    810  ldx #>copyr
    811  jsr prline
    812 
    813 :loop lda $c061
    814  ora $c062
    815  bpl :loop
    816  sta $c010
    817  rts
    818 
    819 *-------------------------------
    820 *
    821 *  S T R I N G   D A T A
    822 *
    823 *-------------------------------
    824 STRpage asc "Page "
    825  db #eol
    826 
    827 title asc "PRINCE OF PERSIA Level Editor"
    828  db #eol
    829 date asc "Working Copy"
    830  db #eol
    831 please asc "PLEASE DO NOT COPY!!"
    832  db #eol
    833 copyr asc "Copyright 1989 Jordan Mechner"
    834  db #eol
    835 
    836 *-------------------------------
    837  lst
    838 eof ds 1
    839  usr $a9,21,$e00,*-org
    840  lst off