eris2010

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

human_player.asm (1513B)


      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 ;;; No initialization necessary
      6 human_player_init:
      7         rts
      8 
      9 ;;; Ask human player for his/her next
     10 ;;; move. A contains the piece_x or
     11 ;;; piece_o, depending which
     12 ;;; piece the human plays
     13 human_player_ply:
     14         .block
     15         ;; Print board
     16         pha
     17         jsr print_board
     18         ;; Print question for move
     19         #io.PRINTS "Player "
     20         pla
     21         pha
     22         clc
     23         adc #'0'
     24         jsr io.putc
     25         #io.PRINTS ": "
     26         ;; Get move and check
     27         ;; if move is valid.
     28         jsr io.getc
     29         jsr io.putc
     30 	;; Check for quit
     31 	cmp #"q"
     32 	bne not_quit
     33 	jmp ($fffc)		; Reset
     34 not_quit:	
     35         ;; Check if user input
     36         ;; is in range [1..9]
     37         cmp #"1"
     38         bcc invalid
     39         cmp #":"                ; Follows 9 in ASCII table
     40         bcs invalid
     41         ;; Check if field is already
     42         ;; occuped
     43         sec
     44         sbc #"1"
     45         sta tmp                 ; Field number
     46         tax
     47         jsr get_field
     48         cmp #piece_none
     49         bne invalid
     50         jsr io.putnl
     51         jsr io.putnl
     52         ;; Set the piece
     53         ldx tmp                 ; Field number
     54         pla                     ; Piece
     55         jsr set_field
     56         rts
     57 invalid:        
     58         jsr io.putnl
     59         #io.PRINTSNL "Not a valid move."
     60         pla
     61         jmp human_player_ply
     62         .bend