我有一个用 Clojure 编写的小游戏。我对这门语言很陌生,我偶然发现的第一个错误是
调用 clojure.core/defn 不符合规范。
我不知道是什么导致了错误,但是抛出了一个异常:
(ns survival-text.core
(:gen-class))
(def health 10)
(def hunger 10)
(def locations ["plains" "ocean" "mountains" "forest"])
(def currentLocation (atom 0))
(defn walk
(def random rand-int (count locations))
(reset! currentLocation (atom random)))
(defn choices
[input]
(case (input)
"walk" (walk)
"exit" (System/exit 0)
""))
(defn -main
[& args]
(while true
(def input read-line)
(choices input)))
Run Code Online (Sandbox Code Playgroud)
但不是这个:
(ns survival-text.core
(:gen-class))
(def health 10)
(def hunger 10)
(def locations ["plains" "ocean" "mountains" "forest"])
(def currentLocation (atom 0))
(defn …Run Code Online (Sandbox Code Playgroud) 我正在制作 NES 游戏。我正在定义几个常量来帮助我管理精灵。我有
spriteyposition = $0200
spritetile = $0201
spriteattribute = $0202
spritexposition = $0203
sprite1 = $00
sprite2 = $04
sprite3 = $08
sprite4 = $0c
sprite5 = $10
sprite6 = $14
sprite7 = $18
sprite8 = $1c
Run Code Online (Sandbox Code Playgroud)
我的用例如下:
我想修改精灵1的y位置
我愿意:
ldx sprite1
lda spriteyposition, x
adc #$8
sta spriteyposition, x
Run Code Online (Sandbox Code Playgroud)
在我的用例中 spriteyposition 应该是一个内存指针,但我有一种感觉,汇编程序将其视为常规数字
我如何将 spriteyposition 称为内存地址而不是数字?
像在 Go 中那样将错误返回给调用者函数是否被认为是一种好习惯,还是我的程序在遇到错误时应该抛出错误?
我试图在实模式下绘制到屏幕,所以我试图使用分段访问 0xB8000
我的汇编代码是这样的
[BITS 16]
org 0x7c00
begin:
mov ah, 0x01 ; disable cursor
mov ch, 0x3f
int 0x10
mov ch, 0x0000
mov cs, 0xb800
mov ah, 0x0000
mov [cs:ah], ch ; invalid effective address
end:
jmp end
times 510 - ($-$$) db 0
dw 0xaa55
Run Code Online (Sandbox Code Playgroud)
我将如何正确使用分段来解决 0xB8000?