Advertisement
NovaYoshi

DecodeLevelMap

Jul 20th, 2013
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .proc DecodeLevelMap
  2. BufPos = 0
  3. Param = 1
  4. Temp = 2
  5. Code = 3
  6. Width = 4
  7. Height = 5
  8. Pointer = 6 ;is also 7
  9. BlockId = 8
  10.   lda LevelMapPointer+0 ; LevelMapPointer isn't in zeropage, so copy it there
  11.   sta Pointer+0
  12.   lda LevelMapPointer+1
  13.   sta Pointer+1
  14.  
  15.   lda #1
  16.   sta IsMappedLevel
  17.   ldy #0
  18. Loop:
  19.   lda (Pointer),y
  20.   sta BufPos
  21.   iny
  22.   lda (Pointer),y
  23.   bne :+
  24.     lda BufPos ; reload the position, we need that
  25.     unpack LevelEditStartX, LevelEditStartY
  26.     rts
  27. : iny
  28.  
  29.   pha ; get param
  30.   and #15
  31.   sta Param
  32.   tax ; just in case this needs to use the param as a block number
  33.   lda LevelData_MetaList,x
  34.   sta BlockId
  35.   pla
  36.  
  37.   and #$f0 ; get function
  38.   lsr
  39.   lsr
  40.   lsr
  41.  
  42.   sty Temp
  43.   jsr Call
  44.   ldy Temp
  45.   jmp Loop
  46. Call:
  47.   tax
  48.   lsr
  49.   sta Code
  50.   lda ObjectTypeTable+1,x
  51.   pha
  52.   lda ObjectTypeTable+0,x
  53.   pha
  54.   lda Code
  55.   ldx BufPos
  56.   rts
  57. ObjectTypeTable:
  58.   .raddr ZeroType
  59.   .raddr HorzRepeat
  60.   .raddr HorzRepeat
  61.   .raddr HorzRepeat
  62.   .raddr VertRepeat
  63.   .raddr VertRepeat
  64.   .raddr RectFill
  65. ZeroType:
  66.   lda BlockId
  67.   sta LevelBuf,x
  68.   rts
  69. HorzRepeat:
  70.   sub #1
  71.   tay
  72.   lda FillTypeTable,y
  73.   ldy Param
  74.   iny
  75. : sta LevelBuf,x
  76.   inx
  77.   dey
  78.   bne :-
  79.   rts
  80. VertRepeat:
  81.   sub #4
  82.   tay
  83.   lda FillTypeTable,y
  84.   ldy Param
  85.   iny
  86. : sta LevelBuf,x
  87.   pha
  88.   txa
  89.   axs #-16
  90.   pla
  91.   dey
  92.   bne :-
  93.   rts
  94. RectFill:
  95.   inc Temp
  96.   lda (Pointer),y
  97.   unpack Width,Height
  98.   inc Width
  99.   inc Height
  100.  
  101. HeightLoop:
  102.   ldy Width
  103.   lda BlockId
  104.   stx BufPos
  105. WidthLoop:
  106.   sta LevelBuf,x
  107.   inx
  108.   dey
  109.   bne WidthLoop
  110.  
  111.   lax BufPos
  112.   axs #-16
  113.  
  114.   dec Height
  115.   bne HeightLoop
  116.   rts
  117. FillTypeTable:
  118.   .byt METATILE_SOLID, METATILE_EMPTY, METATILE_PLATFM
  119. .endproc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement