📄 mmind.asm
字号:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Project : FDOS 0.0.8
;; Author : Ottonello, Santiago
;; E-Mail : sanotto@yahoo.com
;; Webpage : http://www.visual-opal.de
;; Date : 8.8.2003
;; Caption : Hello World
;; Function : This is a program to test FDOS.INC
;; Filename : mmind.asm
;; Notes : The Ramdon Number Routine was shamelesly stolen from
;; MTROOP.ASM - Mars Trooper Created by Misha Koshelev
;; for the 256-byte game contest on rec.games.programmer
;; Thank you Misha... And forgive me ...
;; -----------------------------------------------------
;; Story:
;; Master Mind (?) was one of the first programs
;; i've come across while learning BASIC on my
;; TK85 (CZ1500).
;; I've found it in a magazine called K64.
;; I've seen it with the same name in other
;; maganzines.
;; It's quite a simple game for teaching purpouses
;;
;; Compile Syntax : nasm mmind.asm -f bin -I FDOS.INC -o mmind.bin
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
%include "FDOS.INC" ;System service "wrappers"
%include "STRPGM.INC" ;"Structured programming" Macros
;------------------------------------------------------------------------------
; Main Program Begins Here
;------------------------------------------------------------------------------
BEGPGM ;Load segment registers
CLRSCR ;FDOS Service Clear Screen a Set cursor at (0,0) Int 21 Func 4
PRTSTR Welcme ;Print Welcome Banner
GETSTR AuxBuf ;Wait for User Intro
CLRSCR ;Clear Screen again
EXSR INZRND ;Init Random Generator
EXSR GETRND ;Get Random Number
CVTW2S [RndSed], TgtStr ;Convert it to text
REPEAT ;Loop Begin
EXSR GETNBR ; Get User Input
sub [Score], word 1 ; One trie left
PRTSTR YourSco ; Print Your Score message
EXSR PRTSCO ; Print Score
cmp [Score], word 0 ; No more tries ?
UNTIL Z ;Loop End
CLRSCR
PRTSTR Sorry ;Print "Sorry" message
EXSR ShwNbr ;Show The Correct Number
ENDPGM ;Call FDOS Service "End Program"
;-----------------------------------------------------------------------------
;--------------
;PRTSCO: Converts SCORE to String and Print It
;--------------
BEGSR PRTSCO ;Macro Begin Subroutine
CVTW2S [Score], AuxBuf ; FDOS Service Converts Word to String Int 21 Func 12
PRTSTR AuxBuf ; FDOS Service Prints an ASCIIZ String Int 21 Func 1
PRTSTR CRLF ; Print NewLine
ENDSR ;Macro End Subroutine
;--------------
;GETNBR: Get User Input and Check It
;--------------
BEGSR GETNBR
PRTSTR Prompt ;Print Prompt
GETSTR Buffer ;FDOS Service Read an String Int 21 Func 2
xor ax, ax ;AX = 0 => Equal Count
xor cx, cx ;CX = 0 => Digits Count
mov SI, Buffer - 1 ;Set Source Register to Buffer
mov DI, TgtStr - 1 ;Set Destination Register to Target String
REPEAT ;Repeat
cmpsb ; Compare Bytes
IF Z ; Are the equal ?
inc ax ; Incremet Equals Count
ENDIF
inc cx ; Incremet digit count
cmp cx, 6 ; It's the last char ?
UNTIL Z
cmp ax, 5 ;Well positioned digits = Number of digits ?
IF Z ;if so..
EXSR YOUWIN ; You won
ELSE ;if not
CVTW2S AX, AuxBuf ;Convert it to text
PRTSTR WelPos ;Inform user
PRTSTR AuxBuf
ENDIF
mov si, TgtStr ;Source => Target String
xor bx, bx ;Correct Digits Counter = 0
xor cx, cx ;Iteration Counter = 0
REPEAT ;For each digit in Target String
lodsb ; Load digit
mov dx, ax ; Preserve it in DX
push cx ; Preserve Counter
push si ; Preserve SI
xor cx, cx ; Clear Counter
mov si, Buffer ; Source = Input String
REPEAT ; For each digit
lodsb ; Load it
cmp al,dl ; Compare to Target digit
IF Z ; If equal
inc bx ; Increment Correct Digit Counter
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -