~matboutigny/hangman8086/two_players_mode

« back to all changes in this revision

Viewing changes to hangman.emu8086.asm

  • Committer: Fabien LOISON
  • Date: 2011-02-15 15:41:59 UTC
  • Revision ID: flo@flogisoft.com-20110215154159-pasbzl824vcibuw0
Initial commit
* Print the header
* Main menu implemented

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
2
;;                                                                        ;;
 
3
;; HangMan - An implementation of the Hang Man game in assembly (Emu8086) ;;
 
4
;;                                                                        ;;
 
5
;; Copyright (C) 2011  Fabien LOISON, Mathilde BOUTIGNY,                  ;;
 
6
;; Vincent PEYROUSE and Germain CARR�                                     ;;
 
7
;;                                                                        ;;
 
8
;; HangMan is free software: you can redistribute it and/or modify        ;;
 
9
;; it under the terms of the GNU General Public License as published by   ;;
 
10
;; the Free Software Foundation, either version 3 of the License, or      ;;
 
11
;; (at your option) any later version.                                    ;;
 
12
;;                                                                        ;;
 
13
;; This program is distributed in the hope that it will be useful,        ;;
 
14
;; but WITHOUT ANY WARRANTY; without even the implied warranty of         ;;
 
15
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          ;;
 
16
;; GNU General Public License for more details.                           ;;
 
17
;;                                                                        ;;
 
18
;; You should have received a copy of the GNU General Public License      ;;
 
19
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.  ;;
 
20
;;                                                                        ;;
 
21
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
22
 
 
23
 
 
24
 
 
25
name "hangman"  ;Output file name
 
26
 
 
27
org  0x100      ;Set location counter to 0x100
 
28
 
 
29
COLS equ 80     ;Terminal width
 
30
ROWS equ 25     ;Terminal height
 
31
 
 
32
 
 
33
 
 
34
;================================================================ Main ====
 
35
_main:
 
36
;Set the video mode to 80x25, 16 colors, 8 pages
 
37
mov ah, 0x00
 
38
mov al, 0x03
 
39
int 0x10    
 
40
 
 
41
;Hide the cursor
 
42
mov ah, 0x01
 
43
mov ch, 32
 
44
int 0x10
 
45
 
 
46
;Let's go !
 
47
call _print_header
 
48
call _main_menu
 
49
 
 
50
;Exit
 
51
mov ah, 0x4C
 
52
int 0x21
 
53
 
 
54
 
 
55
;=========================================================== Functions ====
 
56
;--------------------------------------------------------------------------
 
57
_print_header:
 
58
 
 
59
mov pos_x, 6
 
60
mov pos_y, 0
 
61
 
 
62
mov ah, 0x09  
 
63
mov dx, offset header
 
64
 
 
65
;Header                        
 
66
header_loop:
 
67
    call _move
 
68
    int 0x21
 
69
    inc pos_y
 
70
    add dx, header_len
 
71
    cmp pos_y, header_height
 
72
    jne header_loop
 
73
 
 
74
;Line
 
75
mov pos_x, 0
 
76
add pos_y, 1
 
77
call _move
 
78
 
 
79
mov ah, 0x0A
 
80
mov al, 0xC4
 
81
mov bh, 0
 
82
mov cx, 80
 
83
int 0x10
 
84
 
 
85
ret
 
86
 
 
87
     
 
88
;--------------------------------------------------- _draw_main_menu ------
 
89
_draw_main_menu:
 
90
 
 
91
;Center the menu
 
92
mov pos_x, (80-menuitem_len)/2
 
93
mov pos_y, header_height
 
94
add pos_y, 5
 
95
 
 
96
;Prepare the print
 
97
mov ah, 0x09  
 
98
mov dx, offset menuitem
 
99
 
 
100
mov cx, menuitem_numb
 
101
 
 
102
;Draw items                        
 
103
menuDr_loop:
 
104
    call _move
 
105
    int 0x21
 
106
    add pos_y, 2
 
107
    add dx, menuitem_len
 
108
    dec cx
 
109
    cmp cx, 0
 
110
    jne menuDr_loop
 
111
 
 
112
 
 
113
;Display the arrow on the selected item
 
114
mov pos_y, header_height
 
115
add pos_y, 5
 
116
mov ah, 0x00
 
117
mov al, menu_select
 
118
mov bl, 2
 
119
mul bl
 
120
add pos_y, al
 
121
 
 
122
call _move
 
123
 
 
124
mov ah, 0x09
 
125
mov al, 0x10
 
126
mov bh, 0
 
127
mov bl, 00001010b
 
128
mov cx, 1
 
129
int 0x10
 
130
 
 
131
ret
 
132
 
 
133
 
 
134
;---------------------------------------------------------- _main_menu ----
 
135
_main_menu:
 
136
 
 
137
;Move the cursor at the bottom of the screen
 
138
mov pos_x, 1
 
139
mov pos_y, ROWS-2
 
140
call _move
 
141
 
 
142
;Print the help message
 
143
mov ah, 0x09  
 
144
mov dx, offset menuhelp
 
145
int 0x21
 
146
 
 
147
;The main menu
 
148
main_menu_st: 
 
149
    ;Draw the menu
 
150
    call _draw_main_menu
 
151
    
 
152
    ;Wait for input
 
153
    mov ah, 0x07
 
154
    int 0x21
 
155
    
 
156
    ;Test the input
 
157
    cmp al, ' '         ;Space
 
158
    je menu_kb_space
 
159
    cmp al, 0x0D        ;Enter
 
160
    je menu_kb_enter
 
161
    
 
162
    ;Not a valid input... try again ! :p     
 
163
    jmp main_menu_st         
 
164
    
 
165
    ;Space key pressed     
 
166
    menu_kb_space:
 
167
        inc menu_select
 
168
    
 
169
        cmp menu_select, menuitem_numb
 
170
        jne main_menu_st
 
171
    
 
172
        mov menu_select, 0 
 
173
    
 
174
        jmp main_menu_st
 
175
    
 
176
    ;Enter key pressed
 
177
    menu_kb_enter:
 
178
        cmp menu_select, 4      ;Exit
 
179
        je menu_end
 
180
        
 
181
        jmp main_menu_st
 
182
 
 
183
menu_end:
 
184
 
 
185
ret     
 
186
 
 
187
 
 
188
     
 
189
;====================================================== Main Functions ====
 
190
;--------------------------------------------------------------- _move ----
 
191
;Move cursor to (pos_x, pos_y)
 
192
_move:
 
193
 
 
194
;Backup registers
 
195
push ax
 
196
push bx
 
197
push dx
 
198
 
 
199
;Move the cursor
 
200
mov ah, 0x02     
 
201
mov dh, pos_y   ; Row
 
202
mov dl, pos_x   ; Column
 
203
mov bh, 0       ; Page
 
204
int 0x10
 
205
 
 
206
;Restore registers
 
207
pop dx
 
208
pop bx
 
209
pop ax 
 
210
 
 
211
ret
 
212
 
 
213
           
 
214
 
 
215
;================================================================ Vars ====
 
216
;Cursor Position
 
217
pos_x db 0          
 
218
pos_y db 0
 
219
 
 
220
;Menu
 
221
menu_select db 1
 
222
 
 
223
 
 
224
           
 
225
;=============================================================== Datas ==== 
 
226
;Header
 
227
header db " _   _       ___   __   _   _____       ___  ___       ___   __   _ $"
 
228
       db "| | | |     /   | |  \ | | /  ___|     /   |/   |     /   | |  \ | |$"
 
229
       db "| |_| |    / /| | |   \| | | |        / /|   /| |    / /| | |   \| |$"
 
230
       db "|  _  |   / /_| | | |\   | | |  _    / / |__/ | |   / /_| | | |\   |$"
 
231
       db "| | | |  / ___  | | | \  | | |_| |  / /       | |  / ___  | | | \  |$"
 
232
       db "|_| |_| /_/   |_| |_|  \_| \_____/ /_/        |_| /_/   |_| |_|  \_|$"
 
233
header_len    equ 69
 
234
header_height equ  6  
 
235
 
 
236
;Menu
 
237
menuhelp db "<Space> Select the next item    <Enter> Validate the item$"
 
238
menuitem db "  Single Player$"
 
239
         db "  Two players  $"
 
240
         db "  Options      $" 
 
241
         db "  credits      $"
 
242
         db "  Quit         $"
 
243
menuitem_len  equ 16
 
244
menuitem_numb equ 5
 
245