; Simulate two dice (place on the right side, line 1, columns 35, 36)
IDEAL
MODEL small
STACK 100h
DATASEG  
rand_num db ?
clock         equ  es:6ch
; --------------------------
; Your variables here
; --------------------------
CODESEG
; --------------------------------
; Generates a random number (1-6)
; --------------------------------
PROC RANDOM_NUMBER 
    MOV AH, 00H
    INT 1AH  ; Get system time (CX:DX = clock ticks)

    ; Random number = (DL MOD 6) + 1
    MOV AL, DL
    MOV AH, 0
    MOV BL, 6
    DIV BL
    INC AH  ; AH contains random number (1-6)
    MOV [rand_num], AH
    RET
ENDP RANDOM_NUMBER 


;-----------------------------------------------------------------------------------------------------
proc          delay1                       ; delays execution by parameter X 1/18th of a second
              push bp
              mov  bp,sp 
              xor  cx,cx
              mov  cx,[bp+4]               ;delay amount as parameter
              mov  ax,40h
              mov  es,ax                                                                        
tick:         mov  ax,[clock]
notick:       cmp  ax,[clock]              ; Wait for a clock tic
              je   notick               
              loop tick 
              pop  bp
              ret  2           
endp          delay1
;----------------------------------------------------------------------------------------------------


;The parameter for 1 second delay is 15,000 - so you can play with
;any amount. For example if you want 1/100th of a second delay,
;give a parameter of 150.

;-----------------------------------------------------------------------------------------------------
proc          delay2                       ; delays execution by parameter (loop counter)
              push bp
              mov  bp,sp 
              push cx
              push bx
              push ax
              push dx
              xor  cx,cx
              mov  cx,[bp+4]               ;loop amount  
              mov  ax,60000
outerloop:    cmp  ax,0
              je   enddelay                                               
ticktack:     
              mov  ax,1
              mov  dx,3000  
              mov  bx,dx
              loop ticktack
              dec  ax
              jmp outerloop              
enddelay:              
              pop  dx
              pop  ax
              pop  bx
              pop  cx 
              pop  bp
              ret  2           
endp          delay2
;-----------------------------------------------------------------------------------------------------
start:
	mov ax, @data
	mov ds, ax
	
;graphics mode
    mov  ax,13h
    int  10h
    mov  dl, 35   ;Column
    mov  dh, 1    ;Row
    mov  bh, 0    ;Display page
    mov  ah, 02h  ;SetCursorPosition
    int  10h
    call RANDOM_NUMBER                   ; first die
    mov  al,[rand_num]
    add  al,'0'

    mov  bl, 0Ch  ;Color is red
    mov  bh, 0    ;Display page
    mov  ah, 0Eh  ;Teletype
    int  10h
    
    mov  dl, 36   ;Column
    mov  dh, 1    ;Row
    mov  bh, 0    ;Display page
    mov  ah, 02h  ;SetCursorPosition
    int  10h
    push 36 
    call delay1
    call RANDOM_NUMBER                  ; second die
    mov  al,[rand_num]
    add al,'0'    
    mov  bl, 0Ch  ;Color is red
    mov  bh, 0    ;Display page
    mov  ah, 0Eh  ;Teletype
    int  10h
    

; Wait for key press
    mov  ah,00h  
    int  16h 
; back to text mode    
    mov  ax,3h
    int  10h 


exit:
	mov ax, 4c00h
	int 21h
END start