Advertisement
NovaYoshi

main loop

Jul 15th, 2015
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .proc VBlankUpdates
  2.   jsr WaitVblank
  3.   lda #2
  4.   sta OAM_DMA
  5.   bit PPUSTATUS
  6.  
  7.   lda IsScrollUpdate ; update the side if needed, also use vertical writes for it since it's vertical
  8.   jeq NotScrollUpdate
  9.     lda #VBLANK_NMI | NT_2000 | OBJ_8X8 | BG_0000 | OBJ_1000 | VRAM_DOWN
  10.     sta PPUCTRL
  11.     lda ThirtyUpdateAddr+0
  12.     sta PPUADDR
  13.     lda ThirtyUpdateAddr+1
  14.     sta PPUADDR
  15.     .repeat 30, I
  16.       lda ThirtyUpdateTile+I
  17.       sta PPUDATA
  18.     .endrep
  19.   ; do attribute updates if needed
  20.   ; note: vertical writes are still on!
  21.   lda IsScrollUpdate
  22.   cmp #4
  23.   bne Not4
  24.     .repeat 4, I
  25.       lda AttributeWriteA1
  26.       sta PPUADDR
  27.       lda AttributeWriteA2+I
  28.       sta PPUADDR
  29.       lda AttributeWriteD+I
  30.       sta PPUDATA
  31.       lda AttributeWriteD+I+4
  32.       sta PPUDATA
  33.     .endrep
  34.   Not4:
  35.   NotScrollUpdate:
  36.  
  37.   lda #VBLANK_NMI | NT_2000 | OBJ_8X8 | BG_0000 | OBJ_1000
  38.   sta PPUCTRL
  39.  
  40.   lda UploadTileAddress+1
  41.   jeq NoUploadTile
  42.     sta PPUADDR
  43.     lda UploadTileAddress+0
  44.     sta PPUADDR
  45.     .repeat 64, I
  46.       lda UploadTileSpace+I
  47.       sta PPUDATA
  48.     .endrep
  49.     lda #0
  50.     sta UploadTileAddress+1
  51.   NoUploadTile:
  52.  
  53.   .repeat 4, I ; change if the max number of tile changes per frame is changed
  54.     lda TileUpdateA1+I
  55.     beq :+
  56.       sta PPUADDR
  57.       lda TileUpdateA2+I
  58.       sta PPUADDR
  59.       lda TileUpdateT+I
  60.       sta PPUDATA
  61.       lda #0
  62.       sta TileUpdateA1+I
  63.     :
  64.   .endrep
  65.   .repeat 3, I
  66.     lda BlockUpdateA1+I
  67.     beq :+
  68.       sta PPUADDR
  69.       lda BlockUpdateA2+I
  70.       sta PPUADDR
  71.       lda BlockUpdateT1+I
  72.       sta PPUDATA
  73.       lda BlockUpdateT2+I
  74.       sta PPUDATA
  75.  
  76.       lda BlockUpdateB1+I
  77.       sta PPUADDR
  78.       lda BlockUpdateB2+I
  79.       sta PPUADDR
  80.       lda BlockUpdateT3+I
  81.       sta PPUDATA
  82.       lda BlockUpdateT4+I
  83.       sta PPUDATA
  84.       lda #0
  85.       sta BlockUpdateA1+I
  86.     :
  87.   .endrep
  88.  
  89.   ; set the scroll
  90.   lda ScrollX+1
  91.   sta 0
  92.   lda ScrollX
  93.   .repeat 4
  94.     lsr 0
  95.     ror
  96.   .endrep
  97.   sta PPUSCROLL
  98.   lda #0
  99.   sta PPUSCROLL
  100.   lda 0
  101.   and #1 ; bit 0 is most significant bit of scroll
  102.   ora #VBLANK_NMI | NT_2000 | OBJ_8X8 | BG_0000 | OBJ_1000
  103.   sta PPUCTRL
  104. .endproc
  105. ; don't put anything else here
  106. .proc MainLoop
  107.   lda #OBJ_CLIP | BG_CLIP | 1 ; turn grayscale on for CPU usage meter
  108.   sta PPUMASK
  109.   lda IsScrollUpdate ; decrease scroll update stage
  110.   beq :+
  111.   dec IsScrollUpdate
  112. : jsr ReadJoy
  113.   jsr ClearOAM
  114.  
  115.   lda #MAINLOOP_BANK
  116.   jsr SetPRG
  117.   jsr RunPlayer
  118.   jsr AdjustCamera
  119.   jsr DisplayPlayer
  120.   jsr RunObjects
  121.   jsr FlickerEnemies
  122.  
  123.   lda #SOUND_BANK
  124.   jsr SetPRG
  125.   jsr FamiToneUpdate
  126.   lda NeedSFX
  127.   bpl :+
  128.     and #63
  129.     ldx #FT_SFX_CH0
  130.     jsr FamiToneSfxPlay
  131.     lda #0
  132.     sta NeedSFX
  133.   :
  134.   lda #OBJ_CLIP | BG_CLIP
  135.   sta PPUMASK
  136.  
  137.   jmp VBlankUpdates
  138. .endproc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement