BitMap

Description of your first forum.
Post Reply
User avatar
drone84
Posts: 14
Joined: Sat Apr 13, 2019 2:05 pm
Location: On Earth

BitMap

Post by drone84 » Thu Feb 20, 2020 11:07 pm

Hi, I'm trying to display a bit map of 640*480, I have the data loaded from 0xB1:000 up to B4:B000 (640*480 => 0x4B000). The issue I have is that the screen don't look fine at all. I guess the pallet is loaded properly at the color arr kind of matching what I have in the BMP source file.

https://ibb.co/rxHT8qR

That's the original data

https://ibb.co/sRWvPWC

(sorry the link for the picture are not working)
I enabled the BM with this parametter:

BM_CONTROL_REG = 3
BM_START_ADDY = 0xB10000
BM_X_SIZE = 640
BM_Y_SIZE = 480

What should be the data organization in the Video ram?

Code: Select all

INIT_DISPLAY
                .as
                ; set the display size - 128 x 64
                LDA #128
                STA COLS_PER_LINE
                LDA #64
                STA LINES_MAX

                ; set the visible display size - 80 x 60
                LDA #80
                STA COLS_VISIBLE
                LDA #60
                STA LINES_VISIBLE
                LDA #32
                STA BORDER_X_SIZE
                STA BORDER_Y_SIZE

                ; set the border to purple
                setas
                LDA #$20
                STA BORDER_COLOR_B
                STA BORDER_COLOR_R
                LDA #0
                STA BORDER_COLOR_G

                ; enable the border
                LDA #Border_Ctrl_Enable
                STA BORDER_CTRL_REG

                ; enable graphics, tiles and sprites display
                LDA #Mstr_Ctrl_Graph_Mode_En + Mstr_Ctrl_Bitmap_En; + Mstr_Ctrl_TileMap_En + Mstr_Ctrl_Sprite_En ; + Mstr_Ctrl_Text_Mode_En + Mstr_Ctrl_Text_Overlay
                STA MASTER_CTRL_REG_L

                ; display intro screen
                ; wait for user to press a key or joystick button

                ; load tiles
                setaxl
                LDX #<>TILES
                LDY #0
                LDA #$2000 ; 256 * 32 - this is two rows of tiles
                MVN <`TILES,$B0

                ; load LUT
                LDX #<>PALETTE
                LDY #<>GRPH_LUT0_PTR
                LDA #1024
                MVN <`PALETTE,<`GRPH_LUT0_PTR

                LDX #<>PALETTE
                LDY #<>GRPH_LUT1_PTR
                LDA #1024
                MVN <`PALETTE,<`GRPH_LUT1_PTR

                LDX #<>HL_1
                LDY #<>$B10000
                LDA #$FFFF
                MVN <`HL_1,<`$B10000

                LDX #<>HL_2
                LDY #<>$B00000
                LDA #$FFFF
                MVN <`HL_2,<`$B20000

                LDX #<>HL_3
                LDY #<>$B30000
                LDA #$FFFF
                MVN <`HL_3,<`$B30000

                LDX #<>HL_4
                LDY #<>$B40000
                LDA #$B000
                MVN <`HL_4,<`$B40000

                setas
                LDA #1+2
                STA @l BM_CONTROL_REG

                setal
                LDA #0000
                STA @l BM_START_ADDY_L
                STA @l BM_START_ADDY_M
                LDA #01
                STA @l BM_START_ADDY_H

                LDA #640
                STA @l BM_X_SIZE_L
                LDA #0000 ; <>(640*480/10000)
                STA @l BM_X_SIZE_H
                LDA #480
                STA @l BM_Y_SIZE_L
                LDA #0000
                STA @l BM_Y_SIZE_H
Give me anything with electronic and I will make it crash/bug
User avatar
PJW
Posts: 42
Joined: Wed Apr 24, 2019 12:44 am

Re: BitMap

Post by PJW » Thu Feb 20, 2020 11:41 pm

As for the layout of bitmap data: the bytes are laid out in left-to-right, top-to-bottom order. So, in your case, $B1:0000 contains the color index value of the top left pixel. $B1:0001 contains the color of the pixel next on the right. $B1:0280 contains left-most pixel on the second row... and so on.

A couple of things I might suggest:

1. If you want a 640x480 image, I would turn off the border:

Code: Select all

                ; diable the border
                LDA #0
                STA BORDER_CTRL_REG
2. In a couple of places, you are setting both the high and the low bytes of Vicky registers in separate STA instructions with the CPU in wide accumulator mode:

Code: Select all

                setal
                LDA #0000
                STA @l BM_START_ADDY_L
                STA @l BM_START_ADDY_M
                LDA #01
                STA @l BM_START_ADDY_H
and

Code: Select all

                LDA #640
                STA @l BM_X_SIZE_L
                LDA #0000 ; <>(640*480/10000)
                STA @l BM_X_SIZE_H
                LDA #480
                STA @l BM_Y_SIZE_L
                LDA #0000
                STA @l BM_Y_SIZE_H
I'd suggest something like this:

Code: Select all

                setas
                LDA #00
                STA @l BM_START_ADDY_L
                STA @l BM_START_ADDY_M
                LDA #01
                STA @l BM_START_ADDY_H
and

Code: Select all

                LDA #640
                STA @l BM_X_SIZE_L
                LDA #480
                STA @l BM_Y_SIZE_L
That said, I don't think this would cause the problem you are seeing. Still, it might be worth giving it a try.
User avatar
drone84
Posts: 14
Joined: Sat Apr 13, 2019 2:05 pm
Location: On Earth

Re: BitMap

Post by drone84 » Fri Feb 21, 2020 3:26 pm

The issue was the wrong size of the A register as you spotted.

This is the working code. The BitMap data are extracted from a BMP file I saved in 640*480 256 color , it's why the picture is up side down.

Code: Select all

INIT_DISPLAY
                setas
                ; diable the border
                LDA #0
                STA BORDER_CTRL_REG

                ; enable graphics hardware and the BitMap
                LDA #Mstr_Ctrl_Graph_Mode_En + Mstr_Ctrl_Bitmap_En; + Mstr_Ctrl_TileMap_En + Mstr_Ctrl_Sprite_En ; + Mstr_Ctrl_Text_Mode_En + Mstr_Ctrl_Text_Overlay
                STA MASTER_CTRL_REG_L

				;for debug purpos, erase the screen before loading (usefull to see if the code is properly loades by the IDE)
                setaxl
                LDX #<>$0

                LDX #<>$0
                LDA #$0
              erase_Byte_00:
                STA @l $B00000,x
                INX
                CPX #0
                BNE erase_Byte_00
              erase_Byte_01:
                STA @l $B10000,x
                INX
                CPX #0
                BNE erase_Byte_01
              erase_Byte_02:
                STA @l $B20000,x
                INX
                CPX #0
                BNE erase_Byte_02
              erase_Byte_03:
                STA @l $B30000,x
                INX
                CPX #0
                BNE erase_Byte_03
              erase_Byte_04:
                STA @l $B40000,x
                INX
                CPX #0
                BNE erase_Byte_04

				;Load the color palet
                setaxl
                ; load LUT
                LDX #<>PALETTE
                LDY #<>GRPH_LUT0_PTR
                LDA #1024
                MVN <`PALETTE,<`GRPH_LUT0_PTR

                LDX #<>PALETTE
                LDY #<>GRPH_LUT1_PTR
                LDA #1024
                MVN <`PALETTE,<`GRPH_LUT1_PTR
				
				;Load the Bitmap in VRAM starting at B0:0000
				:not sure if LDA #$FFFF will copy 0x1:0000 byte si I doing it in 2 passes
                ;----------------------
                LDX #<>HL_1
                LDY #<>$B00000
                LDA #$8000
                MVN <`HL_1,<`$B00000

                LDX #<>HL_1+$8000
                LDY #<>$B08000
                LDA #$8000
                MVN <`HL_1,<`$B08000
                ;----------------------
                LDX #<>HL_2
                LDY #<>$B10000
                LDA #$8000
                MVN <`HL_2,<`$B10000

                LDX #<>HL_2+$8000
                LDY #<>$B18000
                LDA #$8000
                MVN <`HL_2,<`$B18000
                ;----------------------
                LDX #<>HL_3
                LDY #<>$B20000
                LDA #$8000
                MVN <`HL_3,<`$B20000

                LDX #<>HL_3+$8000
                LDY #<>$B28000
                LDA #$8000
                MVN <`HL_3,<`$B28000
                ;----------------------
                LDX #<>HL_4
                LDY #<>$B30000
                LDA #$8000
                MVN <`HL_4,<`$B30000

                LDX #<>HL_4+$8000
                LDY #<>$B38000
                LDA #$8000
                MVN <`HL_4,<`$B38000
                ;----------------------
                LDX #<>HL_5
                LDY #<>$B40000
                LDA #$B000
                MVN <`HL_5,<`$B40000
                ;----------------------

				; enable the Bitmap harware and sellect the first pallete(LUT)
                setas
                LDA #1+2
                STA @l BM_CONTROL_REG
				
				; set the address where the bitmap is starting from the VRAM point of vue
				: ex : 
				; VRAM : 0x00:0000 <=> CPU 0xB0:0000
				; VRAM : 0x01:0000 <=> CPU 0xB0:1000
				; VRAM : 0x01:0000 <=> CPU 0xB1:0000
				; VRAM : 0x01:0020 <=> CPU 0xB1:0020
				; etc
				
                LDA #00
                STA @l BM_START_ADDY_L
                STA @l BM_START_ADDY_M
                LDA #00
                STA @l BM_START_ADDY_H

                setal
                LDA #640
                STA @l BM_X_SIZE_L
                LDA #480
                STA @l BM_Y_SIZE_L


                RTS
				
				
PALETTE
.binary "assets/halflife.pal"
* = $1a0000
TILES
.binary "assets/simple-tiles.data"
;BITMAP
* = $1B0000
HL_1
.binary "assets/halflife_1.pixel"
* = $1C0000
HL_2
.binary "assets/halflife_2.pixel"
* = $1D0000
HL_3
.binary "assets/halflife_3.pixel"
* = $1E0000
HL_4
.binary "assets/halflife_4.pixel"
* = $1F0000
HL_5
.binary "assets/halflife_5.pixel"
This is the project with the picture stored in binary
https://mega.nz/#!648jSLbY!s9zxs3QaIQBy ... morSYrbZco
Give me anything with electronic and I will make it crash/bug
Post Reply