## 目前在学习这些，有谁有源码或资料的发下，谢谢！

Chinese-language board. 为NES/FC开发商的中国语言论坛 | 為NES/FC開發商的中國語言論壇

Moderator: Moderators

zgh4000
Posts: 29
Joined: Tue May 30, 2006 10:11 am

### 目前在学习这些，有谁有源码或资料的发下，谢谢！

16位运算

......

rand:
CLC ; C=0
LDA \$6003 ; A=\$6003
STA \$6004 ; \$6004=A
STA \$6005 ; \$6005=A
STA \$6006 ; \$6006=A
CLC ; C=0
LDA \$6003 ; A=\$6003
STA \$6003 ; \$6003=A
LDA \$6004 ; A=\$6004
STA \$6004 ; \$6004=A
PHA ; A入栈
LDA \$6005 ; A=\$6005
STA \$6005 ; \$6005=A
AND #\$7F ; A&=7F
TAX ; X=A
LDA \$6006 ; A=\$6006
STA \$6006 ; \$6006=A
PLA ; A出栈
RTS

SRAM选上
\$6003
\$6004
\$6005
\$6006

Last edited by zgh4000 on Sun Jun 11, 2006 10:23 am, edited 2 times in total.

tpu
Posts: 9
Joined: Sat Nov 05, 2005 6:38 pm
Location: china

zgh4000
Posts: 29
Joined: Tue May 30, 2006 10:11 am
tpu wrote:随机数算法一般都是给一个种子，即初始值，然后返回一系列的伪随机数。只要种子一样，产生的结果就一样。把地址放在sram里面，可以保证种子每次开机都不一样。

Last edited by zgh4000 on Fri Jun 09, 2006 9:40 pm, edited 2 times in total.

zgh4000
Posts: 29
Joined: Tue May 30, 2006 10:11 am
16位运算

tpu
Posts: 9
Joined: Sat Nov 05, 2005 6:38 pm
Location: china

math.asm
--------8<----------------------------

Code: Select all

``````
.dataseg
;math
.public mtht0 .byte
.public mtht1 .byte
.public mtht2 .byte
.public mtht3 .byte
;result
.public mthr0 .byte
.public mthr1 .byte
.public mthr2 .byte
.public mthr3 .byte
.codeseg

;;
;; 24bitx8bit->24bit
;;    mtht[210] x a => mthr[210]
;;
.proc mul24x8

sta mtht3
txa
pha

lda #\$00
sta mthr0
sta mthr1
sta mthr2
tax

-:	lda #\$01
and mtht3
beq +

clc
lda mthr0
sta mthr0
lda mthr1
sta mthr1
lda mthr2
sta mthr2

+:	cpx #\$07
beq +

clc
rol mtht0
rol mtht1
rol mtht2
clc
ror mtht3
inx
jmp -

+:	pla
tax
rts
.endp

;;
;; 24bit/16bit => 24bit,16bit
;;    mtht[210] / mthr[10] => mtht[210], mthr[32]
;;

.proc div24d16
txa
pha

lda #\$00
sta mthr2
sta mthr3
ldx #\$18

-:	clc
rol mtht0
rol mtht1
rol mtht2
rol mthr2
rol mthr3
bcs +

lda mthr3
cmp mthr1
bne +
lda mthr2
cmp mthr0
+:	bcc +
sec
lda mthr2
sbc mthr0
sta mthr2
lda mthr3
sbc mthr1
sta mthr3
lda mtht0
ora #\$01
sta mtht0

+:	dex
bne -

pla
tax
rts
.endp

;;
;; 24bit/8bit => 24bit,8bit
;;    mtht[210] / a => mtht[210], mtht[3]
;;
.proc div24d8
txa
pha

lda #\$00
sta mtht3
ldx #\$18

-:	clc
rol mtht0
rol mtht1
rol mtht2
rol mtht3
lda mtht3
bcs ++
bcc +

++:	sec
sta mtht3
lda mtht0
ora #\$01
sta mtht0

+:	dex
bne -

pla
tax
rts
.endp

;;
;; 24bit+8bit => 24bit
;;    x[210] + a => x[210]
;;
clc
sta \$00,x
lda \$01,x
sta \$01,x
lda \$02,x
sta \$02,x
rts
.endp

;;
;; 24bit-8bit => 24bit
;;    x[210] - a => x[210]
;;
.proc sub24s8
sec
lda \$00,x
sta \$00,x
lda \$01,x
sbc #\$00
sta \$01,x
lda \$02,x
sbc #\$00
sta \$02,x
rts
.endp

.public mul24x8, div24d8, div24d16, add24a8, sub24s8

``````

zgh4000
Posts: 29
Joined: Tue May 30, 2006 10:11 am

tpu
Posts: 9
Joined: Sat Nov 05, 2005 6:38 pm
Location: china

luoli83
Posts: 1
Joined: Thu Jun 01, 2006 4:00 pm
Will....... I really can not understand how NES works, it's just too complex.
I mean I can not manage asm will. so I tend to learn gameboy dev. Any way, the lay out of gameboy Ram is very similar as NES.

zgh4000
Posts: 29
Joined: Tue May 30, 2006 10:11 am
tpu wrote:光枪你知道原理的话，编程实现应该很容易的