eris2010

Documentation: http://frombelow.net/projects/eris2010/
Clone: git clone https://git.frombelow.net/eris2010.git
Log | Files | Refs | README | LICENSE

board_test.asm (3632B)


      1 ;;; Copyright 2021 Gerd Beuster (gerd@frombelow.net). This is free
      2 ;;; software under the GNU GPL v3 license or any later version. See
      3 ;;; COPYING in the root directory for details.
      4 
      5 ;;; Expected value is given in res.
      6 ;;; A is compared to this value.
      7 CHECK_ERROR .macro
      8         cmp #\1
      9         beq no_error
     10         #io.PRINTSNL "Error"
     11 stop_loop
     12         jmp stop_loop
     13 no_error
     14         .endm
     15 
     16 PLAYER_WIN_ROW .macro
     17         jsr init_board
     18         ldx #\2
     19         lda #\1
     20         jsr set_field
     21         ldx #(\2+1)
     22         lda #\1
     23         jsr set_field
     24         ldx #(\2+2)
     25         lda #\1
     26         jsr set_field
     27         jsr print_board
     28         jsr get_game_state
     29         #CHECK_ERROR \1
     30         jsr print_game_state
     31         .endm
     32         
     33 PLAYER_WIN_COLUMN .macro
     34         jsr init_board
     35         lda #\1
     36         ldx #\2
     37         jsr set_field
     38         lda #\1
     39         ldx #(\2+3)
     40         jsr set_field
     41         lda #\1
     42         ldx #(\2+6)
     43         jsr set_field
     44         jsr print_board
     45         jsr get_game_state
     46         #CHECK_ERROR \1
     47         jsr print_game_state
     48         .endm
     49 
     50 PLAYER_WIN_SECOND_DIAGONAL	.macro
     51         jsr init_board
     52         lda #\1
     53         ldx #$00
     54         jsr set_field
     55         lda #\1
     56         ldx #$04
     57         jsr set_field
     58         lda #\1
     59         ldx #$08
     60         jsr set_field
     61         jsr print_board
     62         jsr get_game_state
     63         #CHECK_ERROR \1
     64         jsr print_game_state
     65 	.endm
     66         
     67 PLAYER_WIN_FIRST_DIAGONAL	.macro
     68         jsr init_board
     69         lda #\1
     70         ldx #$02
     71         jsr set_field
     72         lda #\1
     73         ldx #$04
     74         jsr set_field
     75         lda #\1
     76         ldx #$06
     77         jsr set_field
     78         jsr print_board
     79         jsr get_game_state
     80         #CHECK_ERROR \1
     81         jsr print_game_state
     82 	.endm
     83                 
     84 ;;; Place some pieces
     85 ;;; and print the field.
     86 game_board_test:
     87         .block
     88         ;; 
     89         ;; Unfinished game.
     90         ;;
     91         jsr init_board
     92         ;; Place "X" pieces
     93         #SET_FIELD piece_x,$00
     94         #SET_FIELD piece_x,$01
     95         #SET_FIELD piece_x,$08
     96         ;; Place "O" pieces
     97         #SET_FIELD piece_o,$04
     98         #SET_FIELD piece_o,$05
     99         #SET_FIELD piece_o,$06
    100         ;; Print board
    101         jsr print_board
    102         jsr get_game_state
    103         #CHECK_ERROR $ff
    104         jsr print_game_state
    105         ;; 
    106         ;; Finished game.
    107         ;;
    108         jsr init_board
    109         #SET_FIELD piece_x,$00
    110         #SET_FIELD piece_x,$01
    111         #SET_FIELD piece_o,$02
    112         #SET_FIELD piece_o,$03
    113         #SET_FIELD piece_o,$04
    114         #SET_FIELD piece_x,$05
    115         #SET_FIELD piece_x,$06
    116         #SET_FIELD piece_x,$07
    117         #SET_FIELD piece_o,$08
    118         jsr print_board
    119         jsr get_game_state
    120         #CHECK_ERROR piece_none
    121         jsr print_game_state
    122         ;; Let each player win in
    123         ;; each row
    124         #PLAYER_WIN_ROW piece_x,$00
    125         #PLAYER_WIN_ROW piece_x,$03
    126         #PLAYER_WIN_ROW piece_x,$06
    127         #PLAYER_WIN_ROW piece_o,$00
    128         #PLAYER_WIN_ROW piece_o,$03
    129         #PLAYER_WIN_ROW piece_o,$06
    130         ;; Let each player win in
    131         ;; each column
    132         #PLAYER_WIN_COLUMN piece_x,$00
    133         #PLAYER_WIN_COLUMN piece_x,$01
    134         #PLAYER_WIN_COLUMN piece_x,$02
    135         #PLAYER_WIN_COLUMN piece_o,$00
    136         #PLAYER_WIN_COLUMN piece_o,$01
    137         #PLAYER_WIN_COLUMN piece_o,$02
    138         ;; Let each player win in
    139         ;; each diagonal
    140         #PLAYER_WIN_SECOND_DIAGONAL piece_x
    141         #PLAYER_WIN_FIRST_DIAGONAL piece_x
    142         #PLAYER_WIN_SECOND_DIAGONAL piece_o
    143         #PLAYER_WIN_FIRST_DIAGONAL piece_o
    144         #io.PRINTSNL "Board tests completed. No errors found!"
    145         rts
    146         .bend