- 注册时间
- 2004-12-25
- 最后登录
- 1970-1-1
|
发表于 2008-1-17 19:03:22
|
显示全部楼层
键盘io操作
testa:测试参数
testb:返回
lda #$00
sta $15
lda #$00
sta $08
lda #$f0
sta $0f
lda testa
sta $08
lda $09
sta testb
lda #$00
sta $0f
rts
瞬间检测
按键对应关系
testa=01h 测试开关键,若该键被按下,返回1
testa=02h 测试以下键(热键名以nc2600为例):
时间、行程、名片、英汉、剑桥、计算、网络 依次返回:01h,02h,04h,08h,10h,20h,40h
testa=04h 测试以下键: f1,f2,f3,f4,复读,发音
(若上面的键被按下,则依次返回01h,02h,04h,08h,10h,20h)
testa=08h 测试: o,l,方向上,方向下,p,输入,翻页下,方向右
返回:01h,02h,04h,08h,10h,20h,40h,80h
testa=10h 测试: q,w,e,r,t,y,u,i 返回:
01h,02h,04h,08h,10h,20h,40h,80h
testa=20h 测试: a,s,d,f,g,h,j,k 返回;
01h,02h,04h,08h,10h,20h,40h,80h
testa=40h 测试:z,x,c,v,b,n,m,翻页上 返回:
01h,02h,04h,08h,10h,20h,40h,80h
testa=80h 测试:求助,中英数,输入法,跳出,符号,.,空格,方向左 返回:
01h,02h,04h,08h,10h,20h,40h,80h
这样,就可以完全通过io来读取键盘输入了!
NANDFLASH的擦除:
入口参数:A00,A01 :虚拟块地址。
ldx #$07
jsr $e024//cspeed
lda #$00
sta $08ac
lda #$00
sta $08ad
lda $0a00
sta $08ae
lda $0a01
sta $08af
lsr $08af
ror $08ae
ror $08ad
lsr $08af
ror $08ae
ror $08ad
lsr $08af
ror $08ae
ror
$08ad//经过一系列的位移运算,我们得出了实际上的FLASH地址,即乘于了32,再减去32(因为要避开0000扇区,擦写那是危险的,所以加上一个16K,从此得出,我们用WQXHEX读出的0000
不是真的0000)
php
sei //设置禁止中断,硬件操作时用来防止外界的干扰。
lda $0435
and #$bc
ora #$09
sta $18 //打开端口
lda #$60
sta $29
lda $0435
and #$bc
ora #$0a
sta $18 //发送准备檫写的命令,是直接的硬件口位操作,不必深究。
lda $08ad
sta $29
lda $08ae
sta $29
lda $08af
sta $29 //定位NAND
lda $0435
and #$bc
ora #$09
sta $18
lda #$d0
sta $29 //檫!
lda #$00
sta $08f7
lda #$0f
sta $08f8 //檫的数量,这里连续擦了32块512B的FLASH。
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop//10个
ldy #$00
ldx #$ff
bb:
lda $18
and #$20 //擦完就跳转
bne aa
dex
bne bb
dey
bne bb //执行中
aa:
lda $0435
and #$bc
ora #$01
sta $18
lda #$70 //read flash id
sta $29
lda $0435
and #$bc
sta $18
ee:
lda $29
sta $08bd
and #$40
bne cc
lda $08f7
bne l1
dec $08b8
l1:
dec $08f7
ora $08f8
bne ee
cc:
lda $08b0
and #$01
bne dd //成功了,挑到 DD 去关端口
lda $0435 //失败,关掉IO
and #$bc
ora #$01
sta $18
lda #$ff
sta $29
lda $0435
and #$94
ora #$40
sta $18
sta $0435 //关闭
plp
clc //失败的标志
rts
dd:
lda $0435 //成功,关掉IO
and #$bc
ora #$01
sta $18
lda #$ff
sta $29
lda $0435
and #$94
ora #$40
sta $18
sta $0435 //关闭
plp
sec //成功的标志
rts
写NAND FLASH
入口参数:
0a00,0a01: 扇区的虚拟地址,指向开头处
0a02:这是要写如数据的FLASH 块,因为虚拟的地址,所以我们通常说的一扇区是
16K。但 NAND 一次只能写 512B 的东西,16K
有20个512B。0a02指的就是第几个512B,即实际块。
比如要写第一个 512B ,就将 0a02置00
ldx #$07
jsr $e024//cspeed
lda #$00
sta $08ac
lda #$00
sta $08ad
lda $0a00
sta $08ae
lda $0a01
sta $08af
lsr $08af
ror $08ae
ror $08ad
lsr $08af
ror $08ae
ror $08ad
lsr $08af
ror $08ae
ror
$08ad//经过一系列的位移运算,我们得出了实际上的FLASH地址,即乘于了32,再减去32(因为要避开0000扇区,擦写那是危险的,所以加上一个16K,从此得出,我们用WQXHEX读出的0000
不是真的0000)
lda $0a02
and #$1f
sta $08ad //0---1f 是32 个数,就是那 32
块。不能超过,不然就写到下一个扇区了,这里用 and 运算置零某些位。
php
sei //设置禁止中断,硬件操作时用来防止外界的干扰。
lda $0435
adn #$bc
sta $0435
lda $0435
and #$bc
ora #$09
sta $18 //打开端口
lda #$00
sta $29 //注意:这里要LDA #00
lda $0435
and #$bc
ora #$09
sta $18
lda #$80
sta $29 //发送准备写的命令
lda $0435
and #$bc
ora #$0a
sta $18
lda $08ac
sta $29
lda $08ad
sta $29
lda $08ae
sta $29
lda $08af
sta $29 //定位NAND
lda $0435
and #$bc
ora #$08
sta $18
-------------
******************************************
这里要自己写程序,将要写数据依次发送到$29.
******************************************
最多 512 B
-------------
lda $0435
and #$bc
ora #$09
sta $18
lda #$10
sta $29 //命令,开始写!~
nop
nop
nop
nop
nop //给出时间让芯片写数据
ldy #$00
ldx #$ff
bb:
lda $18
and #$20
bne aa
dex
bne bb
dey
bne bb //执行中
aa:
lda $0435
and #$bc
ora #$01
sta $18
lda #$70
sta $29 //read flash id
cc:
lda $0435
and #$bc
sta $18
lda $29
sta $08bd
and #$40
beq cc //一大段的验证程序
lda $08b0
and #$01
bne dd
lda $0435
and #$bc
ora #$01
sta $18
lda #$ff
sta $29
lda $0435
and #$94
ora #$40
sta $18
sta $0435
plp
clc
rts //失败了,关掉 IO 口
dd:
lda $0435
and #$bc
ora #$01
sta $18
lda #$ff
sta $29
lda $0435
and #$94
ora #$40
sta $18
sta $0435
plp
sec
rts //成功了,关掉 IO 口
注:要16K的话就要循环写 32 次了。
任意位置(精确到象素)任意大小图片显示子程序
混乱羽翼
入参:$80,81图片数据开始地址
$82图片宽度以byte为单位
$83图片高度以象素为单位
$84,85图片显示位置以最左上点为0,0长高都以象素为单位
出参:无
CODE $2010
2010- LDA #$C0
2012- STA $7E
2014- LDA #$19(如为1020则把此处改为LDA #$09)
2016- STA $7F
2018- LDY $85
201A- BEQ $202A
201C- CLC
201D- LDA $7E
201F- ADC #$14
2021- STA $7E
2023- BCC $2027
2025- INC $7F
2027- DEY
2028- BNE $201C
202A- LDA $84
202C- LSR
202D- LSR
202E- LSR
202F- CLC
2030- ADC $7E
2032- STA $7E
2034- BCC $2038
2036- INC $7F
2038- LDA $84
203A- LDX #$03
203C- LSR
203D- BCS $2069
203F- DEX
2040- BNE $203C
2042- LDX $83
2044- LDY #$00
2046- LDA ($80),Y
2048- STA ($7E),Y
204A- INY
204B- CPY $82
204D- BNE $2046
204F- CLC
2050- LDA $7E
2052- ADC #$14
2054- STA $7E
2056- BCC $205A
2058- INC $7F
205A- CLC
205B- LDA $80
205D- ADC $82
205F- STA $80
2061- BCC $2065
2063- INC $81
2065- DEX
2066- BNE $2044
2068- RTS
2069- LDA $84
206B- LSR
206C- LSR
206D- LSR
206E- ASL
206F- ASL
2070- ASL
2071- STA $3000
2074- LDA $84
2076- SEC
2077- SBC $3000
207A- STA $3000
207D- LDA $83
207F- STA $86
2081- LDY #$14
2083- LDA #$00
2085- STA $3000,Y
2088- DEY
2089- BNE $2085
208B- LDY #$00
208D- LDA ($80),Y
208F- STA $3001,Y
2092- INY
2093- CPY $82
2095- BNE $208D
2097- LDX $3000
209A- LDY #$00
209C- CLC
209D- LDA $3001,Y
20A0- ROR
20A1- STA $3001,Y
20A4- PHP
20A5- INY
20A6- CPY $82
20A8- BEQ $20AF
20AA- PLP
20AB- LDA #$00
20AD- BEQ $209D
20AF- PLP
20B0- LDA $3001,Y
20B3- ROR
20B4- STA $3001,Y
20B7- DEX
20B8- BNE $209A
20BA- LDY $82
20BC- LDA $3001,Y
20BF- ORA ($7E),Y
20C1- STA ($7E),Y
20C3- DEY
20C4- BPL $20BC
20C6- CLC
20C7- LDA $7E
20C9- ADC #$14
20CB- STA $7E
20CD- BCC $20D1
20CF- INC $7F
20D1- CLC
20D2- LDA $80
20D4- ADC $82
20D6- STA $80
20D8- BCC $20DC
20DA- INC $81
20DC- DEC $86
20DE- BNE $2081
20E0- RTS
sun:
多看多写点程序, 有助增进编程技巧! 楼主这段程序我只看了一点,
没真正去了解其运作, 有以下几点建议由于没有试过,可能会有点错误)
在2018有程序中若改为:
2018 LDY $85
201A BEQ $202A
201C LDA $7E
201E CLC
201F ADC #$14
2021 BCC $2025
2023 INC $7F
2025 DEY
2026 BNE $201E
2028 STA $7E
亦可改为
2018 LDY $85
201A LDA $7E
201C CLC
201D DEY
201E BMI $2028
2020 ADC #$14
2022 BCC $201D
2024 INC $7F
2026 BCS $201C
2028 STA $7E
在206B中的
LSR
LSR
LSR
ASL
ASL
ASL (按思考应可以用一个AND #$F8来取代)
208B中 由于$82基本上值是由$0-$13,因此可用
208B LDY $82
208D LDA ($80),Y
208F STA $3001,Y
2092 DEY
2093 BPL $208D (省了CPY $82 ,而CPY $82每次执行时间为3个cycle,
虽是作用不大)
最后是2097, 可改为
2097 LDY $3000
209A LDA $82
209C STA $87
209E LDX #$00
20A0 CLC
20A1 ROR $3001,X
20A4 INX
20A5 DEC $87
20A7 BNE $20A1
20A9 ROR $3001,X
20AC DEY
20AD BNE $209C (php/plp每次一入一出, 用了7个cycle,
因此在循环执行多次的程序中, 如非必要就最好不要使用,
不过当不是要求以最佳速度地方使用也亦可, 若要再加快速度, 可考虑用零页地址[ZEROPAGE]取代$30xx作有关数据存放) |
|