Program: Simple Drawing
Write: girl does not cry, 6502 assembly, 6502 Universal Assembler 1.2.6
Usage:
Upper and lower left: Move the paint brush coordinates
Select: Change the name table #0, #3 (because it is a horizontal image)
Start: Clear the current name table.
BB: Mobile accelerator
AA: drawing, pixel Switching
Source code:
; Start: $ bff0
; End: $ FFFF
; Size: $4010
. Start Reset
. Org $ bff0; File Header
. DB "Nes", $ 1A, $01, $01, $00, $00
. Dw $00, $00, $00, $00
Joy_now = $00
Joy_last = $01
Btn_time = $04
Nt_now = $05; cur NT: 0 :$ 2000,1 :$ 2800
Ppu_addr_low = $02
Ppu_addr_hi = $03
. Org $ c000
Pal_data:; color palette data
. DB $ 0f, $03, $11, $ 1A
. DB $ 0f, $ 1A, $11, $03
Reset:
Sei
ClD
Ldx $ ff; initialize the stack sp
TXS
_ Main_vb1:; PPU push twice
LDA $2002
BPL _ main_vb1
_ Main_vb2:
LDA $2002
BPL _ main_vb2
Turn Off NMI and Screen
Stx$ 2000
Stx$ 2001
STX joy_now; memory initialization
STX joy_last
STX ppu_addr_low
STX ppu_addr_hi
STX btn_time
STX nt_now
JSR set_pal; set the color palette
JSR clr_spr; clear genie
JSR clr_nt; clear the name table
LDA # $07; initialize the genie
Sta $0200 + 0
LDA #$01
Sta $0200 + 1
LDA # $00; return of Scroll
Sta $2005
Sta $2005
LDA # $ 1E; on-screen
Sta $2001
LDA # $80; Enable NMI interruption
Sta $2000
Main:
JMP main; reset interrupt Infinite Loop
; <<
NMI:
LDA #$00
Sta $2001
JSR read_joy
JSR check_btn
JSR move_spr
JSR draw_item
LDA # $02; update genie in DMA mode
Sta $4014
LDA # $ 1e
Sta $2001
RRTI
; <<
Check_btn:
LDA joy_now
CMP #$10
Beq _ cb_st1
CMP #$20
Beq _ cb_n1
RTS
_ Cb_st1:
CMP joy_last
BNE _ cb_st2
RTS
_ Cb_st2:
LDA nt_now
CMP # $00; NT: $2000
BNE _ cb_nt1
LDA #$20
JSR _ sub_clr_nt
RTS
_ Cb_nt1:
LDA #$28
JSR _ sub_clr_nt
RTS
_ Cb_n1:
CMP joy_last
BNE _ cb_n2
RTS
_ Cb_n2:
LDA nt_now
CMP #$00
BNE _ cb_nodraw
; No painting
LDA # $01; already drawn
Sta nt_now
LDA #$82
Sta $2000
RTS
_ Cb_nodraw:
; Already drawn
LDA # $00; no painting
Sta nt_now
LDA #$80
Sta $2000
RTS
; <<
Draw_item:
LDA joy_now
And # $80;?
Beq _ di_rts; no press
LDA joy_now
CMP joy_last
Beq _ di_rts
LDA # $00; Initialization
Sta ppu_addr_low
LDA nt_now
CMP # $01; NT: $2800
BNE _ di_nt1
LDA #$28
Sta ppu_addr_hi
JMP _ di_nt2
_ Di_nt1:
LDA #$20
Sta ppu_addr_hi
_ Di_nt2:
Ldy $0200 + 0; y coordinate
Iny; because it is a Y-1
Tya
LSR; A/= 8
LSR
LSR
Tax; Calculate the multiplication, x * $20 =>
LDA #$00
_ Di_loop1:
CLC
ADC #$20
BCC _ di_lab1
INC ppu_addr_hi
_ Di_lab1:
Dex
BNE _ di_loop1
Sta ppu_addr_low
LDA $0200 + 3; X coordinate
LSR; X/= 8
LSR
LSR
CLC
ADC ppu_addr_low; x offset
BCC _ di_lab2
INC ppu_addr_hi
_ Di_lab2:
Sta ppu_addr_low
_ SKIP:
LDA ppu_addr_hi
Sta $2006
LDA ppu_addr_low
Sta $2006
LDA $2007
LDA $2007
CMP # $00; is it painted?
Beq _ di_draw; no
LDA ppu_addr_hi
Sta $2006
LDA ppu_addr_low
Sta $2006
LDA #$00
Sta $2007
JMP _ di_rts
_ Di_draw:
LDA ppu_addr_hi
Sta $2006
LDA ppu_addr_low
Sta $2006
LDA #$01
Sta $2007
_ Di_rts:
LDA #$00
Sta $2005
Sta $2005
RTS
; <<
Move_spr:
LDA joy_now
CMP joy_last
BNE _ ms_n0
Ldx btn_time
Cpx #$14
BNE _ ms_n4
_ Ms_n0:
CMP # $01; Right
BNE _ ms_n1
LDA $0200 + 3
CLC
ADC #$08
Sta $0200 + 3
RTS
_ Ms_n1:
CMP # $02; left
BNE _ ms_n2
LDA $0200 + 3
Sec
SBC #$08
Sta $0200 + 3
RTS
_ Ms_n2:
CMP #$04;
BNE _ ms_n3
LDA $0200 + 0
CLC
ADC #$08
CMP # $ E7
BNE _ unk_1
LDA #$07
_ Unk_1:
Sta $0200 + 0
RTS
_ Ms_n3:
CMP # $08; on
BNE _ ms_n4
LDA $0200 + 0
Sec
SBC #$08
CMP # $ FF
BNE _ unk_2
LDA # $ DF
_ Unk_2:
Sta $0200 + 0
RTS
_ Ms_n4:
RTS
; <<
Read_joy:
LDA joy_now
PHA
LDA #$01
Sta $4016
LSR
Sta $4016
Ldx #$08
Sta joy_now
Sta joy_last
Joy_loop:
LDA $4016
And #$01
Sta joy_last
LDA joy_now
Asl
Ora joy_last
Sta joy_now
Dex
BNE joy_loop
PLA
CMP joy_now; compared with the previous one
BNE _ 0000_n1; non-equal clearing counter
CMP #$00
Beq _ RTS _rts
INC btn_time
Ldy btn_time
CPY # $15; delay length
BNE _ RTS _rts
STX joy_last
_ Performance_n1:
STX btn_time
_ Cmd_rts:
Sta joy_last
RTS
; <<
Set_pal:
LDA # $ 3f
Sta $2006
LDA #$00
Sta $2006
Ldx #$00
_ Sp_loop1:
LDA pal_data, X
Sta $2007
Bytes
Cpx #$04
BNE _ sp_loop1
LDA # $ 3f
Sta $2006
LDA #$10
Sta $2006
Ldx #$00
_ Sp_loop2:
LDA pal_data + 4, X
Sta $2007
Bytes
Cpx #$04
BNE _ sp_loop2
RTS
; <<
Clr_spr:
LDA #$00
Tax
_ Cs_cs: st$ $0200, X
Bytes
BNE _ cs_cs
LDA # $ ef
_ Cs_hide:
Sta $0200, X
Bytes
Bytes
Bytes
Bytes
BNE _ cs_hide
RTS
; <<
Clr_nt:
LDA #$20
JSR _ sub_clr_nt
LDA #$28
_ Sub_clr_nt:
Sta $2006
LDA #$00
Sta $2006
Ldy #$04
Ldx #$00
_ Clr_nt_loop1:
Sta $2007
Bytes
BNE _ clr_nt_loop1
Dey
BNE _ clr_nt_loop1
LDA #$00
Sta $2005
Sta $2005
RTS
; <<
IRQ:
RRTI
; <<
. Org $ fffa
. Dw NMI, reset, IRQ
Dot matrix model data:
$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,
$ Ff, $00, $00, $00, $00, $00, $00, $00, $00