base:extract_column_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_column_from_tile_based_map [2015-04-17 04:31] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Extract column from tile based maps ====== | ||
+ | by Achim | ||
+ | For a side scrolling game you'll have to extract one row only from your tile data | ||
+ | and print it left or right on the screen. | ||
+ | The following routine can be used to extract columns on either side. | ||
+ | Call it like this: | ||
+ | |||
+ | ldy lo-bytescreen | ||
+ | ldx hi-bytescreen | ||
+ | jsr extractcolumn | ||
+ | |||
+ | To make this work properly a map pointer (always top/left) and tileX (=column 00, 01, 02, 03) | ||
+ | have to be defined. | ||
+ | |||
+ | The main program should use it like this. | ||
+ | |||
+ | Pseudo code for scrolling to the right (player moving left) | ||
+ | |||
+ | < | ||
+ | ldx tileX | ||
+ | dex | ||
+ | bpl !+ // | ||
+ | lda mappointer // | ||
+ | sec | ||
+ | sbc #$01 | ||
+ | sta mappointer | ||
+ | lda mappointer+1 | ||
+ | sbc #$00 | ||
+ | sta mappointer+1 | ||
+ | ldx # | ||
+ | !: stx tileX | ||
+ | |||
+ | lda mappointer // | ||
+ | sta maptmp // | ||
+ | lda mappointer+1 // | ||
+ | sta maptmp+1 | ||
+ | |||
+ | ldy lo-bytescreenleft | ||
+ | ldx lo-bytescreenleft | ||
+ | jsr extract column | ||
+ | </ | ||
+ | |||
+ | To print new data on the right, switch the mappointer to top/right first. | ||
+ | Then extract a new column, finally increment tileX (and mappointer if necessary). | ||
+ | |||
+ | Pseudo code for scrolling to the left (player moving right) | ||
+ | |||
+ | < | ||
+ | lda mappointer // | ||
+ | clc | ||
+ | adc #$0a //#$08 in case of 5x5 | ||
+ | sta maptmp // | ||
+ | lda mappointer+1 | ||
+ | adc #$00 | ||
+ | sta maptmp+1 | ||
+ | |||
+ | ldy lo-bytescreenright | ||
+ | ldx hi-bytescreenright | ||
+ | jsr extract column | ||
+ | |||
+ | ldx tileX | ||
+ | inx | ||
+ | cpx # | ||
+ | bne no | ||
+ | inc mappointer | ||
+ | bne !+ | ||
+ | inc mappointer+1 | ||
+ | !: ldx #$00 //...and start with column 00 | ||
+ | no: stx tileX | ||
+ | </ | ||
+ | |||
+ | Here's the code. MapX and Mappointer have to be handled by your main program. | ||
+ | |||
+ | < | ||
+ | / | ||
+ | Extract colummn from tile data | ||
+ | by A. Volkers, 2011 | ||
+ | |||
+ | y = lo-byte screen column | ||
+ | x = hi-byte screen column | ||
+ | |||
+ | -> | ||
+ | ------------------------------------------------*/ | ||
+ | .pc = $1000 | ||
+ | |||
+ | |||
+ | .const tilemem = 48 // | ||
+ | |||
+ | .var tileX = $02 // | ||
+ | .var mappointer = $03 // | ||
+ | .var mapX = $05 // | ||
+ | .var tiledata = $f9 // | ||
+ | .var screenposition = $fb // | ||
+ | .var maptmp = $fd // | ||
+ | .var numberTiles = $ff // | ||
+ | |||
+ | |||
+ | |||
+ | newcolumn: | ||
+ | stx screenposition+1 | ||
+ | lda #$05 //5 tiles top-bottom, 20 screen rows | ||
+ | sta numberTiles | ||
+ | |||
+ | readcolumn: | ||
+ | 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 tileX | ||
+ | lda (tiledata), | ||
+ | ldy #$00 | ||
+ | sta (screenposition), | ||
+ | lda tileX | ||
+ | clc | ||
+ | adc #$04 | ||
+ | tay | ||
+ | lda (tiledata), | ||
+ | ldy #$28 | ||
+ | sta (screenposition), | ||
+ | lda tileX | ||
+ | clc | ||
+ | adc #$08 | ||
+ | tay | ||
+ | lda (tiledata), | ||
+ | ldy #$50 | ||
+ | sta (screenposition), | ||
+ | lda tileX | ||
+ | clc | ||
+ | adc #$0c | ||
+ | tay | ||
+ | lda (tiledata), | ||
+ | ldy #$78 | ||
+ | sta (screenposition), | ||
+ | |||
+ | lda maptmp // | ||
+ | clc | ||
+ | adc mapX | ||
+ | sta maptmp | ||
+ | bcc !+ | ||
+ | inc maptmp+1 | ||
+ | |||
+ | !: lda screenposition // | ||
+ | clc | ||
+ | adc # | ||
+ | sta screenposition | ||
+ | bcc !+ | ||
+ | inc screenposition+1 | ||
+ | |||
+ | !: dec numberTiles // | ||
+ | bne readcolumn | ||
+ | rts | ||
+ | </ | ||
+ | |||
+ | The following example decodes a whole screen first (using this routine: [[decoding_tile_based_maps|Decoding 4x4 tiles]]), then a map can be scrolled left and right (hard scrolling only). Combine it with soft scrolling and colour RAM shifting. | ||
+ | {{: |
base/extract_column_from_tile_based_map.txt · Last modified: 2015-04-17 04:31 by 127.0.0.1