Re: What am I doing wrong here? Trying to draw 10 lines, multiple colors
- From: Herbert Kleebauer <klee@xxxxxxxxx>
- Date: Tue, 26 Feb 2008 20:50:07 +0100
nobody wrote:
What am I doing wrong here? Trying to draw 10 lines, multiple colors
I got the 10 lines, but I can't get multiple colors working. What am I
doing wrong?
Your problem is, that you suppose that the palette is only used when
the pixel is plotted and after that the screen pixel keeps it's color.
Therefore you change the color of the palette entry 1 and then plot
the new pixels with color 1. But actual it is so, that the palette
color is looked up every time the screen is drawn (about 60 times in
a second), so when you change palette entry 1, then all pixels
plotted with color 1 are displayed with the new color.
To correct your code with minimal changes, replace the constant
"COLOR_INDEX = 1" by a variable and increment this variable in
your loop:
@=$100
VIDEO_PALLETE_PORT = $3C8
COLOR_SELECTION_PORT = $3C9
;COLOR_INDEX = 1
PALLETE_INDEX_BACKGROUND = 0
SET_VIDEO_MODE = 0
GET_VIDEO_MODE = $0F
VIDE0_SEGMENT = $0A000
WAIT_FOR_KEYSTROKE = $10
MODE_13 = $13
0100: e8 004c bsr.w SetVideoMode
0103: e8 0036 bsr.w SetScreenBackground
; Display a greeting message.
0106: ba 01ba move.w #msg,r1 ; DOS calls work also
0109: e8 00a9 bsr.w WriteString
010c: b9 000a move.w #10,r2
MULTIPLELINES:
010f: 81 06 01d3 001e add.w #30,addToX
0115: 89 0e 01da move.w r2,loopCount
0119: e8 0052 bsr.w Draw_Some_Pixels
011c: 8b 0e 01da move.w loopCount,r2
0120: 81 06 01d0 0014 add.w #20,redValue
0126: 81 06 01d1 003c add.w #60,greenValue
012c: 81 06 01d2 0032 add.w #50,blueValue
0132: fe 06 01cf inc.b COLOR_INDEX
0136: e2 d7 dbf.w r2, MULTIPLELINES
0138: e8 0026 bsr.w RestoreVideoMode
013b: c3 rts.w
;------------------------------------------------
; Sets the screen's background color. Video
; palette index 0 is the background color.
;------------------------------------------------
SetScreenBackground:
013c: ba 03c8 move.w #VIDEO_PALLETE_PORT,r1
013f: b0 00 move.b #PALLETE_INDEX_BACKGROUND,r0
0141: ee out.b r0,r1
; Set the screen background color to dark blue.
0142: ba 03c9 move.w #COLOR_SELECTION_PORT,r1
0145: b0 00 move.b #0,r0 ; red
0147: ee out.b r0,r1
0148: b0 00 move.b #0,r0 ; green
014a: ee out.b r0,r1
014b: b0 23 move.b #35,r0 ; blue (intensity 35/63)
014d: ee out.b r0,r1
014e: c3 rts.w
;-----------------------------------------------
; Saves the current video mode, switches to a
; new mode, and points ES to the video segment.
;-----------------------------------------------
SetVideoMode:
014f: b4 0f move.b #GET_VIDEO_MODE,m0
0151: cd 10 trap #$10
0153: a2 01d5 move.b r0,saveMode ; save it
0156: b4 00 move.b #SET_VIDEO_MODE,m0
0158: b0 13 move.b #MODE_13,r0 ; to mode 13h
015a: cd 10 trap #$10
015c: 68 a000 move.w #VIDE0_SEGMENT,-(sp) ; video segment address
015f: 07 move.w (sp)+,s1 ; ES points to video segment
0160: c3 rts.w
;---------------------------------------------
; Waits for a key to be pressed and restores
; the video mode to its original value.
;----------------------------------------------
RestoreVideoMode:
0161: b4 10 move.b #WAIT_FOR_KEYSTROKE,m0
0163: cd 16 trap #$16
0165: b4 00 move.b #SET_VIDEO_MODE,m0 ; reset video mode
0167: 8a 26 01d5 move.b saveMode,m0 ; to saved mode
016b: cd 10 trap #$10
016d: c3 rts.w
;-----------------------------------------------
; Sets individual palette colors and draws
; several pixels.
;------------------------------------------------
Draw_Some_Pixels:
; Change the color at index 1 to white (63,53,43).
016e: ba 03c8 move.w #VIDEO_PALLETE_PORT,r1
0171: a0 01cf move.b COLOR_INDEX,r0 ; set palette index 1
0174: ee out.b r0,r1
0175: 8b 16 03c9 move.w COLOR_SELECTION_PORT,r1
0179: a0 01d0 move.b redValue,r0 ; red
017c: ee out.b r0,r1
017d: a0 01d1 move.b greenValue,r0 ; green
0180: ee out.b r0,r1
0181: a0 01d2 move.b blueValue,r0 ; blue
0184: ee out.b r0,r1
; Calculate the video buffer offset of the first pixel.
; Method is specific to mode 13h, which is 320 X 200.
0185: c7 06 01d6 0000 move.w #0,xVal ; middle of screen
018b: a1 01d3 move.w addToX,r0
018e: 01 06 01d6 add.w r0,xVal
0192: c7 06 01d8 0014 move.w #20,yVal
0198: b8 0140 move.w #320,r0 ; 320 for video mode 13h
019b: f7 26 01d8 mulu.w yVal,r0,r1|r0 ; y-coordinate
019f: 03 06 01d6 add.w xVAl,r0 ; x-coordinate
; Place the color index into the video buffer.
01a3: b9 0096 move.w #150,r2 ; draw 10 pixels
01a6: 89 c7 move.w r0,r6 ; AX contains buffer offset
; Draw the pixels now. By default, the assembler assumes
; DI is an offset from the segment address in DS. The
; segment override ES:[DI] tells the CPU to use the segment
; address in ES instead. ES currently points to VRAM.
01a8: a0 01cf DP1: move.b COLOR_INDEX,r0
01ab: 26 88 05 move.b r0,(r6.w){s1}
01ae: 81 c7 0140 add.w #320,r6 ;move 5 pixels to the right
;add.w #5,r6
01b2: e2 f4 dbf.w r2,DP1
01b4: c3 rts.w
WriteString:
01b5: b4 09 move.b #$09,m0
01b7: cd 21 trap #$21
01b9: c3 rts.w
01ba: 57 65 6c 63 6f 6d
01c0: 65 20 74 6f 20 4d
01c6: 6f 64 65 20 31 33
01cc: 21 24 00 msg: dc.b "Welcome to Mode 13!$",0
01cf: 01 COLOR_INDEX: dc.b 1
01d0: 00 redValue: dc.b 0
01d1: 00 greenValue: dc.b 0
01d2: 00 blueValue: dc.b 0
01d3: 0000 addToX: dc.w 0
saveMode: blk.b 1 ; saved video mode
xVal: blk.w 1 ; x-coordinate
yVal: blk.w 1 ; y-coordinate
loopCount: blk.w 1
.
- References:
- Prev by Date: Re: What am I doing wrong here? Trying to draw 10 lines, multiple colors
- Next by Date: Cause IRQ5 programmatically
- Previous by thread: Re: What am I doing wrong here? Trying to draw 10 lines, multiple colors
- Next by thread: Cause IRQ5 programmatically
- Index(es):
Relevant Pages
|