添加了交替的“填充”颜色(并使其可以在 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 常数放在正确的位置(使用对称值,错误会被忽视))。
看起来像这样:

没有内存表的第二个版本,因为您在两个值之间交替,这意味着您只需要 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