如何在网格中放置2种不同的颜色?

时间:2017-01-08 11:41:22

标签: assembly 68000 easy68k

我尝试为自己做一点运动,但我被卡住了。我想做一个网格(没关系),其中一次拍摄,颜色变化(如图中所示:http://puu.sh/tfgHm/b07843323d.jpg)。我已经有了这个:

    ORG $800
START: 
    MOVE.w #050,D2
    MOVE.w #100,D4
    MOVE.w #0,D6
GRIDLOOP:  
    MOVE.w #0,D5                
    MOVE.w #050,D1        
    MOVE.w #100,D3      
LINE:
    JSR DRAW_FILL_RECT *task 87
    ADD.w  #050,D1
    ADD.w  #050,D3
    ADD.w #1,D5
    CMP.w #6,D5
    BNE LINE
    ADD.w #50,D2
    ADD.w #50,D4
    ADD.w #1,D6
    CMP.w #6,D6
    BNE GRIDLOOP
    RTS

    INCLUDE 'DIRECTORY.X68'

    END START

我尝试了一些东西,但是,它没有正常工作......

1 个答案:

答案 0 :(得分:0)

添加"填充"颜色交替(并使其在Easy68k中可编辑而不包括在内):

    ORG $800
BOARD_SIZE_X    EQU     6
BOARD_SIZE_Y    EQU     8
GRID_OFFSET_X   EQU     100
GRID_OFFSET_Y   EQU     50
GRID_SIZE_X     EQU     50
GRID_SIZE_Y     EQU     25
FIRST_SQUARE_COLOR  EQU $004040FF
SECOND_SQUARE_COLOR EQU $0040FF40

START:
    LEA     GridColorsTable,A0
    MOVEQ   #BOARD_SIZE_Y-1,D6              ; rows counter
    MOVE.w  #GRID_OFFSET_Y,D2               ; Y1
    MOVE.w  #GRID_OFFSET_Y+GRID_SIZE_Y,D4   ; Y2
GridLoopRows:  
    MOVEQ   #BOARD_SIZE_X-1,D5              ; cells per row counter (columns)
    MOVE.w  #GRID_OFFSET_X,D7               ; X1 will reside in D7 (color is using D1 too)
    MOVE.w  #GRID_OFFSET_X+GRID_SIZE_X,D3   ; X2
GridLoopCells:
    ; set fill color
    MOVE.w  D5,D1
    EOR.w   D6,D1
    AND.w   #1,D1                           ; D1 = 0 or 1
    LSL.w   #2,D1                           ; *4
    MOVE.L  (A0,D1.w),D1                    ; fetch color value from table by that index
    MOVEQ   #81,D0                          ; set fill color (task 81)
    TRAP    #15
    MOVE.w  D7,D1                           ; restore X1 before rectangle draw

    ;JSR DRAW_FILL_RECT *task 87
    MOVEQ   #87,D0
    TRAP    #15

    ADD.w   #GRID_SIZE_X,D7
    ADD.w   #GRID_SIZE_X,D3
    DBRA    D5,GridLoopCells
    ADD.w   #GRID_SIZE_Y,D2
    ADD.w   #GRID_SIZE_Y,D4
    DBRA    D6,GridLoopRows
    SIMHALT             ; halt simulator
    RTS

;    INCLUDE 'DIRECTORY.X68'

GridColorsTable:        ; two colors for the grid
    DC.L    FIRST_SQUARE_COLOR, SECOND_SQUARE_COLOR
    ; when grid size is like 7x6, then first square is the second value (swap order in this table)

    END START

(网格定义有意为6x8而非正方形,以验证我将X / Y常数放在正确的位置(对称值,错误会被忽视)。

看起来像这样:

chessboard

没有内存表的第二个版本,因为您在两个值之间交替,这意味着您只需要XOR ...

    ORG $800
BOARD_SIZE_X    EQU     6
BOARD_SIZE_Y    EQU     8
GRID_OFFSET_X   EQU     100
GRID_OFFSET_Y   EQU     50
GRID_SIZE_X     EQU     50
GRID_SIZE_Y     EQU     25
FIRST_SQUARE_COLOR  EQU $004040FF
SECOND_SQUARE_COLOR EQU $0040FF40
SWITCH_COLOR    EQU     (FIRST_SQUARE_COLOR^SECOND_SQUARE_COLOR)

START:
    MOVE.l  #FIRST_SQUARE_COLOR,D1          ; color for first square
    MOVEQ   #BOARD_SIZE_Y-1,D6              ; rows counter
    MOVE.w  #GRID_OFFSET_Y,D2               ; Y1
    MOVE.w  #GRID_OFFSET_Y+GRID_SIZE_Y,D4   ; Y2
GridLoopRows:  
    MOVEQ   #BOARD_SIZE_X-1,D5              ; cells per row counter (columns)
    MOVE.w  #GRID_OFFSET_X,D7               ; X1 will reside in D7 (color is using D1 too)
    MOVE.w  #GRID_OFFSET_X+GRID_SIZE_X,D3   ; X2
GridLoopCells:
    MOVEQ   #81,D0                          ; set fill color (task 81)
    TRAP    #15
    EOR.l   #SWITCH_COLOR,D1                ; alternate between two colors
    EXG.l   D7,D1                           ; D1 = X1, D7 = color
    MOVEQ   #87,D0      ;JSR DRAW_FILL_RECT *task 87
    TRAP    #15
    EXG.l   D7,D1                           ; D1 = color, D7 = X1
    ADD.w   #GRID_SIZE_X,D7
    ADD.w   #GRID_SIZE_X,D3
    DBRA    D5,GridLoopCells
    EOR.l   #SWITCH_COLOR,D1                ; alternate color for "even" board_size_x
        ; for "odd" board_size_x comment out the EOR, color is already "alternative" then
    ADD.w   #GRID_SIZE_Y,D2
    ADD.w   #GRID_SIZE_Y,D4
    DBRA    D6,GridLoopRows
    SIMHALT             ; halt simulator
    RTS

    END START