SPO600 실습 3 - 수학 및 문자열 - 숫자 추측.
나는 6502 Emulator에서 구할 수 있는 http://6502.cdot.systems/을 사용할 것입니다.
실습 3에서 작업은 6502 Emulator를 사용하여 값을 계산하거나 변환하는 게임 또는 프로그램을 작성하는 것이었습니다.
나는 플레이어가 임의의 숫자를 추측해야 하는 숫자 추측 게임을 코딩하기로 결정했습니다. 목표는 단서가 가장 적은 숫자를 추측하는 것입니다.
두 가지 주요 작업은 다음과 같습니다.
; Comparing two numbers
; ROM routine entry points
define SCINIT $ff81 ; initialize/clear screen
define CHRIN $ffcf ; input character from keyboard
define CHROUT $ffd2 ; output character to screen
define SCREEN $ffed ; get screen size
define PLOT $fff0 ; get/set cursor coordinates
; zeropage variables
define PRINT_PTR $10
define PRINT_PTR_H $11
define value $14
define value_h $15
; absolute variables
define GETNUM_1 $0080
define GETNUM_2 $0081
; constants
; --------------------------------------------------------
jsr SCINIT
jsr CHRIN
jsr PRINT
dcb "C","o","m","p","a","r","i","n","g",32,"t","w","o",32,
dcb "n","u","m","b","e","r","s",00
start: jsr PRINT
dcb $0d,$0d,"E","n","t","e","r",32,"a",32,"n","u","m","b","e","r"
dcb "(","0","-","9","9",")",":"
dcb 32,32,32,32,32,32,32,32,00
lda #$00
sta value_h
jsr GETNUM
sta value
jsr PRINT
dcb "E","n","t","e","r",32,"a","n","o","t","h","e","r"
dcb 32,"n","u","m","b","e","r",32,"(","0","-","9","9",")",":",32,00
jsr GETNUM
sed ; set decimal
cmp value
cld ; clear decimal flag (switches into binary math mode)
bcc toohigh ; if second value is less than the first value, go to toohigh
beq identical ; if second value is same as first one,
inc value_h ; increment memory
toolow: pha ; push the accumulator
jsr PRINT
dcb "N","u","m","b","e","r",32,"o","n","e",32,
dcb "i","s",32,"s","m","a","l","l","e","r",32
dcb 32,32,32,32,32,32,32
dcb 32,32,32,32,32,32,32
dcb 32,32,32,32,32,32,32
dcb 00
jsr start
identical: pha ; push the accumulator
jsr PRINT
dcb "C","o","r","r","e","c","t",32
dcb 32,32,32,32,32,32,32
dcb 32,32,32,32,32,32,32
dcb 32,32,32,32,32,32,32
dcb 00
jsr start
toohigh: pha ; push the accumulator
jsr PRINT
dcb "N","u","m","b","e","r",32,"o","n","e",32,
dcb "i","s",32,"g","r","e","a","t","e","r",32
dcb 32,32,32,32,32,32,32
dcb 32,32,32,32,32,32,32
dcb 32,32,32,32,32,32,32
dcb 00
jsr start
; --------------------------------------------------------
; Print a message
;
; Prints the message in memory immediately after the
; JSR PRINT. The message must be null-terminated and
; 255 characters maximum in length.
PRINT: pla ; pull the accumulator
clc ; clear carry flag (C) - required before using ADC
adc #$01 ; add with carry
;sec ; set carry flag (C) - required before using SBC
;sbc #$01
sta PRINT_PTR
pla
sta PRINT_PTR_H
tya ; transfer Y to A
pha ; push the accumulator
ldy #$00
print_next: lda (PRINT_PTR),y
beq print_done
jsr CHROUT
iny
jmp print_next
print_done: tya
clc
adc PRINT_PTR
sta PRINT_PTR
lda PRINT_PTR_H
adc #$00
sta PRINT_PTR_H
pla
tay
lda PRINT_PTR_H
pha
lda PRINT_PTR
pha
rts
; ---------------------------------------------------
; GETNUM - get a 2-digit decimal number
;
; Returns A containing 2-digit BCD value
GETNUM: txa ; transfer X to accumulator
pha ; push the accumulator
tya ; transfer Y to A
pha
ldx #$00 ; count of digits received
stx GETNUM_1 ; store the X register
stx GETNUM_2
getnum_cursor: lda #$a0 ; black square
jsr CHROUT
lda #$83 ; left cursor
jsr CHROUT
getnum_key: jsr CHRIN
cmp #$00
beq getnum_key
cmp #$08 ; BACKSPACE
beq getnum_bs
cmp #$0d ; ENTER
beq getnum_enter
cmp #$30 ; "0"
bmi getnum_key
cmp #$3a ; "9" + 1
bmi getnum_digit
jmp getnum_key
getnum_enter: cpx #$00
beq getnum_key
lda #$20
jsr CHROUT
lda #$0d
jsr CHROUT
lda GETNUM_1
cpx #$01
beq getnum_done
asl
asl
asl
asl
ora GETNUM_2
getnum_done: sta GETNUM_1
pla
tay
pla
tax
lda GETNUM_1
rts
getnum_digit: cpx #$02
bpl getnum_key
pha
jsr CHROUT
pla
and #$0f
sta GETNUM_1,x
inx
jmp getnum_cursor
getnum_bs: cpx #$00
beq getnum_key
lda #$20
jsr CHROUT
lda #$83
jsr CHROUT
jsr CHROUT
lda #$20
jsr CHROUT
lda #$83
jsr CHROUT
dex
lda #$00
sta GETNUM_1,x
jmp getnum_cursor
다음은 프로그램의 결과입니다.
그래서 이 블로그에서 4개의 작업 중 2개가 완료되었습니다.
추측 게임을 완료하기 위해 블로그를 하나 더 작성하겠습니다.
Reference
이 문제에 관하여(SPO600 실습 3 - 수학 및 문자열 - 숫자 추측.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/smitgabani/spo600-lab-3-math-and-strings-guessing-numbers-5po텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)