home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / programs / emulaton / utilities / magicasm / pce_code / asm / demo next >
Encoding:
Text File  |  1998-04-14  |  10.2 KB  |  542 lines

  1.     .include "library.inc"
  2.     .include "macro.inc"
  3.     .include "equ.inc"
  4.     .nomlist
  5.     .list
  6.  
  7. ; variables
  8.  
  9.      .rsset $2000
  10. scanline .rs 2        ; the line number for the scanline interrupt
  11. vsync    .rs 1        ; vbl synchro flag
  12.  
  13.     ; wavy scroll
  14.  
  15. wave_base .rs 1        ; base index for the wave table
  16. wave_idx  .rs 1        ; index in the wave table
  17.  
  18.     ; scroll text
  19.  
  20. st_flag   .rs 1        ; event flag
  21. st_offset .rs 2        ; scroll offset
  22. st_ptr    .rs 2        ; pointer in the text string
  23. st_pos    .rs 1        ; screen position for the next character
  24. st_width  .rs 1        ; width of a character
  25. st_char   .rs 1        ; current character
  26.  
  27.     ; sprites
  28.  
  29. spr_idx    .rs 1    ; index of rotating stars
  30. spr_base   .rs 1    ; base of the circle
  31. spr_angle  .rs 1    ; circle rotation angle
  32. spr_frac   .rs 1    ; for adjusting the angle
  33. spr_radius .rs 1    ; radius of the circle
  34. spr_dir    .rs 1    ; direction of the zoom
  35. spr_ptr    .rs 2    ; pointer in the sprite table
  36.  
  37.          .rsset $2200
  38. spr_info .rs 64        ; the eight sprites
  39.  
  40. ; first, we initialize the interrupt vectors
  41.  
  42.     .bank 0
  43.     .org  $FFF6
  44.  
  45.     .dw null_int    ;IRQ2,  used by the BRK instruction
  46.     .dw vdc_int    ;IRQ1,  interrupt from the VDC
  47.     .dw null_int    ;TIMER, not used in this demo
  48.     .dw null_int    ;NMI,   never used (or may be by a HuCard!?)
  49.     .dw reset_int    ;RESET, the most important one :)
  50.  
  51.     .org $E000
  52.  
  53. null_int:
  54.     rti
  55.  
  56. ; reset_int:
  57. ; ---------
  58. ; it's here that everything starts!
  59.  
  60. reset_int:
  61.     sei            ; disable interrupts 
  62.     csh            ; select the 7.16 MHz clock
  63.     cld            ; clear the decimal flag 
  64.     ldx   #$FF        ; initialize the stack
  65.     txs 
  66.     lda   #$FF        ; map the first page to the I/O bank
  67.     tam   #0
  68.     lda   #$F8        ; and the second to the RAM bank
  69.     tam   #1
  70.     stz   $2000        ; clear all the RAM
  71.     tii   $2000,$2001,$1FFF
  72.     jsr   init_vdc        ; initialize the video controller
  73.     jsr   init_psg        ; and the sound generator
  74.     stz   $C01        ; stop the timer
  75.     stz   $1402        ; unmask and enable interrupts
  76.     cli
  77.  
  78. ; now that all the hardware is initialized we can copy our
  79. ; sprite and character patterns into the VRAM.
  80.  
  81.     map   spr_data        ; map the sprite bank and the font
  82.     map   font_data        ; bank in the memory
  83.  
  84.     ; copy all the data to the VRAM
  85.  
  86.     vload $1000,spr_data,64*4
  87.     vload $1800,water_data,16*4
  88.     vload $2000,font_data,16*256
  89.  
  90.     ; initialize the palette
  91.  
  92.     setpal 16,spr_pal,3
  93.     setpal 0,water_pal,2
  94.     setpal 2,font_pal,1
  95.  
  96. ; fill the background
  97.  
  98.     stwi  .scrtab,<_si    ; address of the character table
  99.     stwi  $0,<_di        ; set the VRAM address
  100.     jsr   set_write
  101.  
  102.     lda   #32        ; size 32 lines of 32 blocks, each block
  103. .l1:    ldx   #32        ; is two 8x8 characters
  104.     pha 
  105. .l2:    cly            ; we fill each line with two words
  106.     lda   [_si],Y        ; from the table
  107.     iny            
  108.     sta   $0002
  109.     lda   [_si],Y
  110.     iny
  111.     sta   $0003
  112.     lda   [_si],Y
  113.     iny
  114.     sta   $0002
  115.     lda   [_si],Y
  116.     iny
  117.     sta   $0003
  118.     dex            ; next block
  119.     bne   .l2
  120.     addwi 4,<_si        ; update the pointer in the table
  121.     pla
  122.     dec   A            ; next line
  123.     bne   .l1
  124.  
  125. ; initialize the variables and enable the display
  126.  
  127.     lda   #32        ; initialize the scroll-text
  128.     sta   <st_pos
  129.     stwi  stext,<st_ptr
  130.  
  131.     lda   #65        ; initialize the sprites
  132.     sta   <spr_radius
  133.     tii   .sprtab,spr_info,8*12
  134.  
  135.     vreg  #5        ; enable the display and
  136.     lda   #$CC        ; interrupts
  137.     sta   <_creg
  138.     sta   $0002
  139.  
  140. ; the main loop, here we rotate the stars and scroll
  141. ; the text window
  142.  
  143. .loop:    stz   <vsync        ; vbl synchro
  144. .wait:  lda   <vsync
  145.     beq   .wait
  146.  
  147.     jsr   star_circle    ; update the sprite position
  148.     jsr   scroll_text    ; update the scroll text
  149.  
  150.     bra   .loop        ; continue again and again!!
  151.  
  152. ; table for initializing the background;
  153. ; two words per line
  154.  
  155. .scrtab:.dw   $0180,$0181,$0182,$0183,$0180,$0181,$0182,$0183
  156.     .dw   $0180,$0181,$0182,$0183,$0180,$0181,$0182,$0183
  157.     .dw   $0180,$0181,$0182,$0183,$0180,$0181,$0182,$0183
  158.     .dw   $0180,$0181,$0182,$0183,$0180,$0181,$0182,$0183
  159.     .dw   $0180,$0181,$0182,$0183,$0180,$0181,$0182,$0183
  160.     .dw   $2200,$2200,$2220,$2220,$1180,$1181,$0182,$0183
  161.     .dw   $0180,$0181,$0182,$0183,$0180,$0181,$0182,$0183
  162.     .dw   $0180,$0181,$0182,$0183,$0180,$0181,$0182,$0183
  163.  
  164. ; table for initializing the sprite informations
  165.  
  166. .sprtab:.dw   120,152,0,$0080
  167.     .dw   120,152,0,$0081
  168.     .dw   120,152,0,$0082
  169.     .dw   120,152,0,$0080
  170.     .dw   120,152,0,$0081
  171.     .dw   120,152,0,$0082
  172.     .dw   120,152,0,$0080
  173.     .dw   120,152,0,$0081
  174.     .dw   120,152,0,$0082
  175.     .dw   120,152,0,$0080
  176.     .dw   120,152,0,$0081
  177.     .dw   120,152,0,$0082
  178.  
  179. ; vdc_int:
  180. ; -------
  181. ; interrupt for the VDC
  182.  
  183. vdc_int:
  184.     pha
  185.     phx
  186.     phy
  187.     lda   $0000        ; load the status register
  188.  
  189. ; vertical blanking interrupt code
  190.  
  191. .vbl:    bit   #$20        ; vbl?
  192.     beq   .hbl
  193.  
  194.     st0   #6        ; restart the scanline counter on the first
  195.     stwi  $40,$0002        ; line
  196.     stwi  $40,<scanline
  197.     lda   <wave_base    ; change the index base for the wavy
  198.     add   #4        ; scrolling
  199.     sta   <wave_base
  200.     sta   <wave_idx
  201.     inc   <vsync        ; vsync flag
  202.     jmp   .exit
  203.  
  204. ; scanline interrupt code
  205.  
  206. .hbl:    bit   #$04        ; scanline?
  207.     bne   .h1
  208.     jmp   .exit
  209.  
  210.     ; update the scrolling
  211.  
  212. .h1:    lda   <scanline        ; check in what area we are
  213.     cmp   #224
  214.     blo   .h2
  215.     cmp   #239
  216.     bhs   .h2
  217.  
  218.     st0   #7        ; text area
  219.     movw  <st_offset,$0002
  220.     bra   .h3
  221.  
  222. .h2:    st0   #7        ; wavy area
  223.     lda   <wave_idx
  224.     lsr   A
  225.     lsr   A
  226.     tax
  227.     lda   .wave,X
  228.     sta   $0002
  229.     stz   $0003
  230.  
  231. .h3:    lda   <scanline        ; update the index in the
  232.     bit   #$03        ; wave table
  233.     bne   .h4
  234.     inc   <wave_idx
  235.  
  236.     ; reprogram the scanline counter for the next line
  237.  
  238. .h4:    st0   #6
  239.     incw  <scanline
  240.     movw  <scanline,$0002
  241.     jmp   .exit
  242.  
  243.     ; the wave table
  244.  
  245. .wave:    .db   5,6,7,8,8,9,9,10,10,10,9,9,8,8,7,6
  246.     .db   5,4,3,2,2,1,1,0,0,0,1,1,2,2,3,4
  247.     .db   5,6,7,7,8,8,9,9,9,9,9,8,8,7,7,6
  248.     .db   5,4,3,3,2,2,1,1,1,1,1,2,2,3,3,4
  249.  
  250. ; exit of the interrupt handler
  251.  
  252. .exit:    lda   <_vreg
  253.     sta   $0000
  254.     ply
  255.     plx
  256.     pla
  257.     rti
  258.  
  259. ; star_circle:
  260. ; -----------
  261. ; update the circle.
  262.  
  263. star_circle:
  264.     ; initialize the variables
  265.  
  266.     stwi  spr_info,<spr_ptr
  267.     lda   <spr_base
  268.     sta   <spr_angle
  269.     inc   <spr_base
  270.     inc   <spr_idx
  271.     stz   <spr_frac
  272.  
  273.     ; update the radius; zoom effect
  274.  
  275.     lda   <spr_radius
  276.     ldx   <spr_dir
  277.     bne   .z1
  278.     inc   A            ; add
  279.     cmp   #106
  280.     blo   .z2
  281.     dec   <spr_dir
  282. .z1:    dec   A            ; sub
  283.     cmp   #65
  284.     bhs   .z2
  285.     inc   <spr_dir
  286.     inc   A
  287. .z2:    sta   <spr_radius
  288.  
  289.     ; calculate the position for the 12 stars
  290.  
  291.     lda   #12
  292. .v1:    pha
  293.     lda   <spr_radius    ; the angle
  294.     sta   <_al
  295.     lda   <spr_angle
  296.     sta   <_bl
  297.     jsr   rotate
  298.  
  299.     lda   <spr_frac        ; update the angle for
  300.     add   #86        ; the next star
  301.     sta   <spr_frac
  302.     lda   <spr_angle
  303.     adc   #21
  304.     sta   <spr_angle
  305.  
  306.     cly            ; center the Y position
  307.     lda   #140
  308.     add   <_cl
  309.     sta   [spr_ptr],Y
  310.     cla
  311.     adc   <_ch
  312.     iny
  313.     sta   [spr_ptr],Y
  314.     iny
  315.  
  316.     lda   #152        ; center the X position
  317.     add   <_dl
  318.     sta   [spr_ptr],Y
  319.     cla
  320.     adc   <_dh
  321.     iny
  322.     sta   [spr_ptr],Y
  323.     iny
  324.  
  325.     lda   <spr_idx        ; the sprite number
  326.     lsr   A
  327.     and   #$6
  328.     add   #$80
  329.     sta   [spr_ptr],Y
  330.  
  331.     addwi 8,<spr_ptr    ; go to the next sprite
  332.     pla
  333.     dec   A
  334.     bne   .v1
  335.  
  336.     ; copy the sprite data into the SATB
  337.  
  338.     setspr 0,spr_info,12
  339.     rts
  340.  
  341. ; rotate:
  342. ; ------
  343. ; rotate a point.
  344. ;
  345. ; IN:   _AL = radius  (0 - 127)
  346. ;       _BL = angle in degree (0-255)
  347. ;
  348. ; OUT:  _CX/_DX = signed 16bit coordinates
  349.  
  350. rotate:
  351.     ; calculate Y coordinate
  352.  
  353. .y:    ldx   <_bl
  354.     lda   .sinus,X
  355.     bsr   .muls
  356.     sta   <_cl
  357.     stz   <_ch
  358.     bit   #$80
  359.     beq   .x
  360.     lda   #$FF
  361.     sta   <_ch
  362.  
  363.     ; calculate X coordinate
  364.  
  365. .x:    lda   <_bl
  366.     add   #64
  367.     tax
  368.     lda   .sinus,X
  369.     bsr   .muls
  370.     sta   <_dl
  371.     stz   <_dh
  372.     bit   #$80
  373.     beq   .exit
  374.     lda   #$FF
  375.     sta   <_dh
  376.     
  377.     ; return results
  378.  
  379. .exit:    rts
  380.  
  381. ; multiplication sub_routine
  382.  
  383. .muls:
  384.     clx
  385.     bit   #$80
  386.     beq   .s1
  387.     inx
  388.     neg
  389. .s1:    asl   A
  390.     sta   <_ah
  391.  
  392.     cla
  393.     ldy   #7
  394. .l1:
  395.     asl   a
  396.     rol   <_ah
  397.     bcc   .s2
  398.     add   <_al
  399.     bcc   .s2
  400.     inc   <_ah
  401. .s2:
  402.     dey
  403.     bne   .l1
  404.     lda   <_ah
  405.     cpx   #0
  406.     beq   .s3
  407.     neg
  408. .s3:    rts
  409.  
  410. .sinus: .include "sin.inc"
  411.  
  412. ; scroll_text:
  413. ; -----------
  414. ; update the scroll text.
  415.  
  416. scroll_text:
  417.     lda   <st_offset
  418.     and   #$7
  419.     bne   .s3
  420.  
  421.     ; check if a new character is needed
  422.  
  423.     inc   <st_char
  424.     dec   <st_width
  425.     bpl   .s2
  426.  
  427.     ; extract a character from the text string
  428.  
  429.     lda   [st_ptr]        ; get the character
  430.     bne   .s1        ; loop if end reached
  431.     stwi  stext,<st_ptr
  432.     lda   stext
  433. .s1:    incw  <st_ptr        ; update the index
  434.     tax            ; get the width of the character
  435.     ldy   swidth-32,X
  436.     sty   <st_width
  437.     asl   A            ; store the character number
  438.     sta   <st_char
  439.  
  440.     ; adjust the character number to match the font
  441.  
  442. .s2:    lda   <st_char
  443.     sec
  444.     sbc   #64
  445.     sta   <_al
  446.     and   #$60
  447.     asl   A
  448.     sta   <_ah
  449.     lda   <_al
  450.     and   #$1F
  451.     ora   <_ah
  452.  
  453.     ; copy the character
  454.  
  455.     ldx   #5        ; change the VRAM increment to 64
  456.     stx   <_vreg
  457.     st0   #5
  458.     st2   #$10
  459.     ldx   #0        ; set the VRAM write address
  460.     stx   <_vreg
  461.     st0   #0
  462.     ldx   <st_pos
  463.     stx   $0002
  464.     st2   #$05
  465.     ldx   #2        ; copy the data
  466.     stx   <_vreg
  467.     st0   #2
  468.     sta   $0002
  469.     st2   #$22
  470.     add   #$20
  471.     sta   $0002
  472.     st2   #$22
  473.     ldx   #5        ; VRAM increment back to 1
  474.     stx   <_vreg
  475.     st0   #5
  476.     st2   #$00
  477.  
  478.     ; incremente the counters
  479.  
  480.     lda   <st_pos        ; character position
  481.     inc   A
  482.     and   #$3F
  483.     sta   <st_pos
  484.  
  485. .s3:    addwi 2,<st_offset    ; scroll offset
  486.     rts
  487.  
  488.     ; string for the scroll
  489.  
  490. stext:    .db "                                "
  491.     .db "YO!!  THE MAGIC TEAM IS PROUD TO PRESENT... THE FIRST "
  492.     .db "PC ENGINE DEMO!    "
  493.     .db "IT'S NOT MUCH AND SOUND IS MISSING "
  494.     .db "BUT IT'S JUST THE BEGINNING :)    "
  495.     .db "AT LEAST WE HOPE IT WILL "
  496.     .db "GIVE YOU THE ENVY TO MAKE NEW DEMOS!    "
  497.     .db "AND PERHAPS WE WILL HAVE SOON "
  498.     .db "A GREAT DEMO SCENE ON THE PC ENGINE...  WHO KNOWS!"
  499.     .db "                                "
  500.     .db "CREDITS :  CODE BY RONY AND GFX BY PHOENIX."
  501.     .db "                                "
  502.     .db "GREETINGS TO ALL OUR FRIENDS "
  503.     .db "AND TO ALL THE TGHACK-LIST MEMBERS!!"
  504.     .db "                                "
  505.     .db "PERSONAL MESSAGES :  FROM RONY  "
  506.     .db "- TO SHAUN J. \"OK, NEXT TIME I WILL ENCODE THE TEXT! ;)\"    "
  507.     .db "                                "
  508.     .db "                                "
  509.     .db " RESTARTING..."
  510.     .db "                                "
  511.     .db 0
  512.  
  513.     ; info on the width of a character (8 or 16)
  514.  
  515. swidth: .db 0,0,1,1,1,1,1,0,0,0,1,1,0,1,0,1
  516.     .db 1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1
  517.     .db 1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1
  518.     .db 1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,1
  519.  
  520. ;±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±
  521.  
  522.     .include "library.asm"
  523.  
  524. ;±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±
  525.  
  526.     .bank 1
  527.     .org $8000
  528.  
  529. spr_data:   .incspr "block.pcx",0,80,4,1
  530. spr_pal:    .incpal "block.pcx",1
  531.         .incpal "block.pcx",4,2
  532. water_data: .incchr "block.pcx",0,96,2,2
  533. water_pal:  .incpal "block.pcx",0
  534.             .incpal "block.pcx",3
  535. font_pal:   .incpal "block.pcx",2
  536.  
  537.     .bank 2
  538.     .org $A000
  539.  
  540. font_data:  .incchr "block.pcx",0,0,32,8
  541.  
  542.