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

  1.  
  2. ; vbl_on:
  3. ; ------
  4. ; enable the vbl interrupt of the VDC
  5.  
  6. vbl_on:
  7.     smb3  <_creg
  8.     vreg  #$5
  9.     lda   <_creg
  10.     sta   $0002
  11.     rts
  12.  
  13. ; vbl_off:
  14. ; -------
  15. ; disable the vbl interrupt of the VDC
  16.  
  17. vbl_off:
  18.     rmb3  <_creg
  19.     vreg  #$5
  20.     lda   <_creg
  21.     sta   $0002
  22.     rts
  23.  
  24. ; set_palette:
  25. ; -----------
  26. ; initialize one or more sub-palette
  27. ;
  28. ; IN :  _AL = index of the first sub-palette (0-31)
  29. ;       _SI = address of the color table
  30. ;       _CL = number of sub_palette to copy
  31.  
  32. set_palette:
  33.     lda   <_al        ; mulitply the sub-palette index by 16
  34.     stz   <_ah        ; and set the color index of the VCE
  35.     asl   A
  36.     asl   A
  37.     asl   A
  38.     asl   A
  39.     rol   <_ah
  40.     sta   $0402
  41.     lda   <_ah
  42.     sta   $0403
  43.  
  44.     cly
  45. .loop_a:
  46.     ldx   #16
  47. .loop_b:
  48.     lda   [_si],Y        ; set a color
  49.     iny
  50.     sta   $0404
  51.     lda   [_si],Y
  52.     sta   $0405
  53.     iny
  54.     bne   .next
  55.     inc   <_si+1
  56. .next:  dex            ; next color
  57.     bne   .loop_b
  58.  
  59.     dec   <_cl        ; next sub-palette
  60.     bne   .loop_a
  61.     rts
  62.  
  63. ; set_sprite:
  64. ; ----------
  65. ; change the attributes of a sprite
  66. ;
  67. ; IN:   A = sprite number (0-63) 
  68. ;       _SI = pointer to a SATB entry 
  69. ;       _CL = number of sprites to copy
  70. ;
  71. ; NOTE: this procedure assumes that the SATB is located
  72. ;       at address $7F00 in the VRAM
  73.  
  74. set_sprite:
  75.     asl   A
  76.     asl   A
  77.     sta   <_di
  78.     lda   #$7F
  79.     sta   <_di+1
  80.     lda   <_cl
  81.     asl   A
  82.     asl   A
  83.     sta   <_cl
  84.     stz   <_ch
  85.     jmp   load_vram
  86.  
  87. ; load_vram:
  88. ; ---------
  89. ; copy a block of memory to the VRAM
  90. ;
  91. ; IN:   _DI = VRAM location
  92. ;       _SI = memory location
  93. ;       _CX = number of words to copy
  94.  
  95. load_vram:
  96.     jsr   set_write
  97.     cly
  98. .loop:    lda   [_si],Y
  99.     sta   $0002
  100.     iny
  101.     lda   [_si],Y
  102.     sta   $0003
  103.     iny
  104.     bne   .next
  105.     inc   <_si+1
  106. .next:  decw  <_cx
  107.     lda   <_cl
  108.     ora   <_ch
  109.     bne   .loop
  110.     rts
  111.  
  112. ; set_read:
  113. ; ---------
  114. ; initialize the VRAM for reading
  115. ;
  116. ; IN:   _DI = VRAM location
  117.  
  118. set_read:
  119.     vreg  #$01
  120.     lda   <_di 
  121.     sta   $0002
  122.     lda   <_di+1
  123.     sta   $0003
  124.     vreg  #$02
  125.     rts 
  126.  
  127. ; set_write:
  128. ; ---------
  129. ; initialize the VRAM for writing
  130. ;
  131. ; IN:   _DI = VRAM location
  132.  
  133. set_write:
  134.     vreg  #$00
  135.     lda   <_di 
  136.     sta   $0002
  137.     lda   <_di+1
  138.     sta   $0003
  139.     vreg  #$02
  140.     rts 
  141.  
  142. ; init_vdc:
  143. ; --------
  144. ; initialize the video controller :
  145. ;   + screen mode to 256x240
  146. ;   + display and sprites off
  147. ;   + no interrupts
  148. ;   + virtual screen size to 512x256
  149. ;   + SATB to $7F00.
  150.  
  151. init_vdc:
  152.     stwi  .table,<_si     ; put the table address into ZP[4]
  153.     cly 
  154. .loop:    lda   [_si],Y        ; select the VDC register
  155.     iny
  156.     sta   <_vreg
  157.     sta   $0000
  158.     lda   [_si],Y        ; send the 16bit data
  159.     iny 
  160.     sta   $0002
  161.     lda   [_si],Y
  162.     iny 
  163.     sta   $0003
  164.     cpy   #36        ; loop if not at the end of the
  165.     bne   .loop        ; table
  166.     rts 
  167.  
  168. .table:    db $05,$00,$00        ; CR    VDC control register
  169.     db $06,$00,$00        ; RCR    scanline interrupt counter
  170.     db $07,$00,$00        ; BXR   background horizontal scroll offset
  171.     db $08,$00,$00        ; BYR        "     vertical       "      "
  172.     db $09,$10,$00        ; MWR   size of the virtual screen
  173.     db $0A,$02,$02        ; HSR |
  174.     db $0B,$1F,$04        ; HDR |    define the size and synchro
  175.     db $0C,$02,$0F        ; VPR |    of the display
  176.     db $0D,$EF,$00        ; VDW |
  177.     db $0E,$04,$00        ; VCR |
  178.     db $0F,$10,$00        ; DCR   DMA control register
  179.     db $13,$00,$7F        ; SATB  address of the SATB
  180.  
  181. ; init_psg:
  182. ; --------
  183. ; initialize the sound generator.
  184.  
  185. init_psg:
  186.     stz   $0801        ; main volume to zero
  187.     stz   $0809        ; disable the LFO
  188.     
  189.     lda   #5        ; set volume to zero for each channel (0-5)
  190. .clear:    sta   $0800
  191.     stz   $0804
  192.     dec   A
  193.     bpl   .clear
  194.     rts
  195.  
  196.