Friday, December 21, 2012

HL code example

Soon I'm going to release the macro code I've been working on. I don't understand this code algorithm in detail, (there is a lot of data to go with it that is not posted here) it is used as an example. I recently added the ability to scan for a known identifier and if found, default to "not zero" for the condition, ( BNE/BEQ ). Here is an example of what it can do:


001 .proc AreaParserCore 002 003 if BackloadingFlag 004 jsr ProcessAreaData 005 endif 006 007 ldx #$0c 008 lda #$00 009 010 repeat 011 mb MetatileBuffer[ x ] := a ; clear out metatile buffer 012 until dex == negative 013 014 if ldy BackgroundScenery ; do we need to render the background scenery? 015 016 lda CurrentPageLoc ; otherwise check for every third page 017 do 018 if cmp #$03 == negative break ; if less than three we're there 019 mb a := a - #3 ; if 3 or more, subtract 3 and 020 021 while positive ; unconditional 022 023 mb a := a << 4 ; move results to higher nybble 024 025 mb x := a ++ BSceneDataOffsets[ y - 1 ] ++ CurrentColumnPos ; add with carry 026 027 if lda BackSceneryData[ x ] ; load data from sum of offsets - if zero, no scenery 028 029 pha 030 031 mb temp_byte := a & #$0f - #1 ; clear h.nybble and subtract one (because low nybble is $01-$0c) 032 mb x := a * 2 ++ temp_byte ; multiply by three (shift to left and add old result) c is clear 033 034 pla ; get high nybble from stack, move low 035 036 mb y := a >> 4 ; use as second offset (used to determine height) 037 mb temp_byte := #3 ; use previously saved memory location for counter 038 039 repeat 040 mb MetatileBuffer[ y ] := BackSceneryMetatiles[ x ] ; load metatile data from offset of (lsb - 1) * 3 041 inx 042 iny 043 until y = #$0b || dec temp_byte == zero ; decrement until counter expires, or y = $0b 044 045 endif 046 endif 047 048 if ldx ForegroundScenery ; check for foreground data needed or not 049 050 mb y := FSceneDataOffsets[ x - 1 ] ; load offset from location offset by header value, then 051 ldx #$00 ; reinit X 052 repeat 053 if lda ForeSceneryData[ y ] != zero ; load data until counter expires 054 sta MetatileBuffer,x ; do not store if zero found 055 endif 056 iny 057 inx 058 until x = #$0d ; store up to end of metatile buffer 059 060 endif 061 062 063 if ldy AreaType == zero && WorldNumber = #World8 ; if set as water level and world number eight, 064 lda #$62 ; use castle wall metatile as terrain type 065 else 066 lda TerrainMetatiles,y ; otherwise get appropriate metatile for area type 067 if ldy CloudTypeOverride ; check for cloud type override , if not set, keep value 068 lda #$88 ; use cloud block terrain 069 endif 070 endif 071 072 mb temp_byte[ 7 ] := a ; store value here 073 ldx #$00 ; initialize X, use as metatile buffer offset 074 075 mb y := TerrainControl * 2 ; multiply by 2 and use as yet another offset 076 077 do 078 mb temp_byte := TerrainRenderBits[ y ] ; get one of the terrain rendering bit data 079 mb temp_byte[ 1 ] := y + 1 ; increment Y and use as offset next time around 080 081 if CloudTypeOverride && x <> #$00 ; skip if value here is zero, and check if we're doing 082 mb temp_byte := temp_byte & #%00001000 ; the ceiling byte, if not, mask out all but d3 083 endif 084 085 ldy #$00 ; start at beginning of bitmasks 086 repeat 087 088 if lda Bitmasks[ y ] : bit temp_byte ; if set, write terrain to buffer 089 mb MetatileBuffer[ x ] := temp_byte[ 7 ] ; load terrain type metatile number and store into buffer here 090 endif 091 092 inx ; continue until end of buffer 093 if x = #$0d goto exitloop ; if we're at the end, break out of this loop 094 095 if AreaType = #$02 && x = #$0b ; check area for undergd area, and if at the bottom of the screen 096 mb temp_byte[ 7 ] := #$54 ; override old terrain type with ground level terrain type 097 endif 098 099 iny ; increment bitmasks offset in Y 100 until y = #$08 ; if not all bits checked, loop back 101 102 ldy $01 103 104 while Z clear ; unconditional branch, use Y to load next byte 105 106 exitloop: 107 108 jsr ProcessAreaData ; do the area data loading routine now 109 lda BlockBufferColumnPos 110 jsr GetBlockBufferAddr ; get block buffer address from where we're at 111 ldx #$00 112 ldy #$00 ; init index regs and start at beginning of smaller buffer 113 114 repeat 115 sty temp_byte 116 117 mb a := MetatileBuffer[ x ] & #%11000000 << 1 118 rol ; make %xx000000 into 0000xx 119 rol 120 tay ; use as offset in Y 121 122 if MetatileBuffer[ x ] < BlockBuffLowBounds[ y ] ; reload original unmasked value here, 123 lda #$00 ; if less, init value before storing 124 endif 125 126 ldy temp_byte ; get offset for block buffer 127 mb ($06)[ y ] := a ; store value into block buffer 128 129 mb a := y 130 mb y := a + #$10 ; add 16 (move down one row) to offset 131 inx ; increment column value 132 until x >= #$0d ; continue until we pass last row, then leave 133 134 rts 135 136 .endproc

No comments:

Post a Comment