base:extract_row_from_tile_based_map
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | base:extract_row_from_tile_based_map [2015-04-17 04:31] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Extract row from tile based map ====== | ||
+ | by Achim | ||
+ | Example 4x4 tile: | ||
+ | < | ||
+ | ccdd | ||
+ | eeff | ||
+ | gghh | ||
+ | </ | ||
+ | Tile data stored in memory: | ||
+ | < | ||
+ | |||
+ | In order to read and plot the correct tile row for a vertical scrolling | ||
+ | game, tileY has to be defined. | ||
+ | < | ||
+ | tileY: 00, ... aabb | ||
+ | 04, ... ccdd | ||
+ | 08, ... eeff | ||
+ | 0c, ... gghh | ||
+ | </ | ||
+ | |||
+ | Again a map pointer is needed (top-left) and mapX (=map width) for correct map data handling. | ||
+ | For a straight vertical scrolling game | ||
+ | |||
+ | mapX = number of tiles left to right. In case of 4x4 tiles: mapX=#$0a, in case of 5x5 tiles mapX=#$08. | ||
+ | |||
+ | |||
+ | Pseudo code for scrolling down (player moving up): | ||
+ | |||
+ | < | ||
+ | lda tileY | ||
+ | bne samemaprow // | ||
+ | |||
+ | lda map //map - mapX | ||
+ | sec | ||
+ | sbc mapX | ||
+ | sta map | ||
+ | lda map+1 | ||
+ | sbc #$00 | ||
+ | sta map+1 | ||
+ | lda # | ||
+ | samemaprow: | ||
+ | sbc #$04 | ||
+ | sta tileY | ||
+ | |||
+ | lda map // | ||
+ | sta maptmp | ||
+ | lda map+1 | ||
+ | sta maptmp+1 | ||
+ | |||
+ | lda lo-bytescreentop | ||
+ | ldx hi-bytescreentop | ||
+ | jsr extractrow | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | Pseudo code for scrolling up (player moving down): | ||
+ | |||
+ | < | ||
+ | lda map // | ||
+ | sta maptmp | ||
+ | lda map+1 | ||
+ | sta maptmp+1 | ||
+ | |||
+ | ldx numbertiles // | ||
+ | !: lda maptmp // | ||
+ | clc | ||
+ | adc mapX | ||
+ | sta maptmp | ||
+ | lda maptmp+1 | ||
+ | adc #$00 | ||
+ | sta maptmp+1 | ||
+ | dex | ||
+ | bpl !- | ||
+ | |||
+ | lda lo-bytescreenbottom | ||
+ | ldx hi-bytescreenbottom | ||
+ | jsr extractrow | ||
+ | |||
+ | lda tileY | ||
+ | cmp # | ||
+ | bne !+ | ||
+ | lda map //map + mapX | ||
+ | clc | ||
+ | adc mapX | ||
+ | sta map | ||
+ | lda map+1 | ||
+ | adc #$00 | ||
+ | sta map+1 | ||
+ | lda # | ||
+ | !: clc | ||
+ | adc #$04 | ||
+ | sta tileY | ||
+ | ... | ||
+ | </ | ||
+ | Extracting a row is pretty simple... | ||
+ | < | ||
+ | / | ||
+ | Extract row from tile data | ||
+ | by A. Volkers, 2011 | ||
+ | |||
+ | a = lo-bytescreen | ||
+ | x = hi-bytescreen | ||
+ | |||
+ | -> | ||
+ | --------------------------------------------------------------------------*/ | ||
+ | .pc = $1000 | ||
+ | |||
+ | .const tilemem = 48 // | ||
+ | |||
+ | .var tileY = $02 // | ||
+ | .var map = $03 // | ||
+ | .var mapX = $04 // | ||
+ | .var tiledata = $fc // | ||
+ | .var maptmp = $fe // | ||
+ | |||
+ | |||
+ | |||
+ | extractrow: | ||
+ | clc | ||
+ | adc #$28 | ||
+ | sta check+1 | ||
+ | stx plotrow+2 | ||
+ | |||
+ | extract: | ||
+ | lda (maptmp), | ||
+ | and #$0f //use tables for 5x5 tiles instead | ||
+ | asl | ||
+ | asl | ||
+ | asl | ||
+ | asl | ||
+ | sta tiledata // | ||
+ | lda (maptmp),y | ||
+ | and #$f0 | ||
+ | lsr | ||
+ | lsr | ||
+ | lsr | ||
+ | lsr | ||
+ | clc | ||
+ | adc # | ||
+ | sta tiledata+1 | ||
+ | |||
+ | ldy tileY // | ||
+ | ldx # | ||
+ | readtile: | ||
+ | plotrow: | ||
+ | inc plotrow+1 | ||
+ | bne !+ | ||
+ | inc plotrow+2 | ||
+ | !: lda plotrow+1 | ||
+ | check: cmp #$28 //40 chars done? | ||
+ | beq exit | ||
+ | iny | ||
+ | dex | ||
+ | bpl readtile | ||
+ | inc maptmp // | ||
+ | bne !+ | ||
+ | inc maptmp+1 | ||
+ | !: clv | ||
+ | bvc extract | ||
+ | exit: rts | ||
+ | </ | ||
+ | |||
+ | Check out this program which uses the same routine. Hardscrolling only, no colour RAM shifting: {{: |
base/extract_row_from_tile_based_map.txt · Last modified: 2015-04-17 04:31 by 127.0.0.1