diff options
author | Jesse Luehrs <doy@tozt.net> | 2018-10-13 02:17:44 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2018-10-13 02:37:01 -0400 |
commit | aa403b978860210fcbace7fcdf5830066f3e14e0 (patch) | |
tree | 0d8cf5a8855765ec2d83a865a12814d3b04454e7 /static/blog | |
parent | ecd7793846441ba90b57140db19474f295f3e6d7 (diff) | |
download | tozt-hugo-aa403b978860210fcbace7fcdf5830066f3e14e0.tar.gz tozt-hugo-aa403b978860210fcbace7fcdf5830066f3e14e0.zip |
import site content
Diffstat (limited to 'static/blog')
-rw-r--r-- | static/blog/cartridge.jpg | bin | 0 -> 274982 bytes | |||
-rw-r--r-- | static/blog/input.s | 135 | ||||
-rw-r--r-- | static/blog/sprites.chr | bin | 0 -> 8192 bytes | |||
-rw-r--r-- | static/blog/sprites.s | 197 |
4 files changed, 332 insertions, 0 deletions
diff --git a/static/blog/cartridge.jpg b/static/blog/cartridge.jpg Binary files differnew file mode 100644 index 0000000..e6d70ae --- /dev/null +++ b/static/blog/cartridge.jpg diff --git a/static/blog/input.s b/static/blog/input.s new file mode 100644 index 0000000..56ccee5 --- /dev/null +++ b/static/blog/input.s @@ -0,0 +1,135 @@ +.ROMBANKMAP +BANKSTOTAL 2 +BANKSIZE $4000 +BANKS 1 +BANKSIZE $2000 +BANKS 1 +.ENDRO + +.MEMORYMAP +DEFAULTSLOT 0 +SLOTSIZE $4000 +SLOT 0 $C000 +SLOTSIZE $2000 +SLOT 1 $0000 +.ENDME + +.ENUM $00 +sleeping DB +color DB +frame_count DB +.ENDE + + .bank 0 slot 0 + .org $0000 +RESET: + SEI + CLD + LDX #$FF + TXS + INX + STX $2000.w + STX $2001.w + STX $4010.w + LDX #$40 + STX $4017.w + +vblankwait1: + BIT $2002 + BPL vblankwait1 + +clrmem: + LDA #$00 + STA $0000, x + STA $0100, x + STA $0300, x + STA $0400, x + STA $0500, x + STA $0600, x + STA $0700, x + LDA #$FE + STA $0200, x + INX + BNE clrmem + + LDA #%10000001 + STA color + +vblankwait2: + BIT $2002 + BPL vblankwait2 + + LDA #%10000000 + STA $2000 + +loop: + INC sleeping +wait_for_vblank_end: + LDA sleeping + BNE wait_for_vblank_end + + ; controller 1 latch + LDA #$01 + STA $4016 + LDA #$00 + STA $4016 + + ; controller 1 clock, reading the state of the A button + LDA $4016 + AND #%00000001 + BNE change_color + JMP loop_end + ; reading the rest of the buttons is unnecessary, so we don't do it + +change_color: + LDA #$00 + STA frame_count + LDX color + CPX #%10000001 + BEQ turn_green + CPX #%01000001 + BEQ turn_red + +turn_blue: + LDA #%10000001 + STA color + JMP loop_end +turn_green: + LDA #%01000001 + STA color + JMP loop_end +turn_red: + LDA #%00100001 + STA color + +loop_end: + JMP loop + +NMI: + PHA + TXA + PHA + TYA + PHA + + LDA color + STA $2001 + + LDA #$00 + STA sleeping + PLA + TAY + PLA + TAX + PLA + + RTI + + .orga $FFFA + .dw NMI + .dw RESET + .dw 0 + + .bank 1 slot 1 + .org $0000 + .incbin "sprites.chr" diff --git a/static/blog/sprites.chr b/static/blog/sprites.chr Binary files differnew file mode 100644 index 0000000..3713c9c --- /dev/null +++ b/static/blog/sprites.chr diff --git a/static/blog/sprites.s b/static/blog/sprites.s new file mode 100644 index 0000000..5f0b3d9 --- /dev/null +++ b/static/blog/sprites.s @@ -0,0 +1,197 @@ +.ROMBANKMAP +BANKSTOTAL 2 +BANKSIZE $4000 +BANKS 1 +BANKSIZE $2000 +BANKS 1 +.ENDRO + +.MEMORYMAP +DEFAULTSLOT 0 +SLOTSIZE $4000 +SLOT 0 $C000 +SLOTSIZE $2000 +SLOT 1 $0000 +.ENDME + +.ENUM $00 +sleeping DB +.ENDE + +; just use the actual locations in our copy of SPR-RAM rather than zero-page +; addresses, to avoid having to do multiple copies +.define sprite_x $0203 +.define sprite_y $0200 + + .bank 0 slot 0 + .org $0000 +RESET: + SEI + CLD + LDX #$FF + TXS + INX + STX $2000.w + STX $2001.w + STX $4010.w + LDX #$40 + STX $4017.w + +vblankwait1: + BIT $2002 + BPL vblankwait1 + +clrmem: + LDA #$00 + STA $0000, x + STA $0100, x + STA $0300, x + STA $0400, x + STA $0500, x + STA $0600, x + STA $0700, x + LDA #$FE + STA $0200, x + INX + BNE clrmem + + ; start with the sprite near the middle of the screen + LDA #$80 + STA sprite_x + STA sprite_y + +vblankwait2: + BIT $2002 + BPL vblankwait2 + + ; PPU is initialized here, so we can start writing data into it. this is safe + ; because we have not yet enabled drawing, and so we don't have to restrain + ; ourselves to vblank. + + ; first, we load the palettes into $3F00 and $3F10 +load_palettes: + LDA $2002 ; read here so that the next byte written to $2006 is the high + LDA #$3F ; byte of the address + STA $2006 ; write the high byte of the base address + LDA #$00 + STA $2006 ; write the low byte of the base address + LDX #$00 +load_palettes_loop: + LDA palette.w, x + STA $2007 + INX + CPX #$20 ; 16 byte background palette plus 16 byte sprite palette + BNE load_palettes_loop + + ; then we draw the background (doing that here because it won't be changing) + LDA #$20 + STA $2006 ; high byte of the starting address + LDA #$00 + STA $2006 ; low byte of the starting address + LDA #$01 ; pattern index 1 is our background tile + LDX #$04 ; this loop will load $2000-$23FF, which includes the + LDY #$00 ; attribute table range, but we can just adjust the +load_background_loop: ; palette to take that into account + STA $2007 + INY + BNE load_background_loop + DEX + BNE load_background_loop + + ; then we set the unchanging parts of our sprite (the pattern index and the + ; attributes) + LDA #$00 + STA $0201 ; pattern index 0 is our sprite + STA $0202 ; don't need any attributes + + ; enable the PPU + LDA #%10000000 + STA $2000 + LDA #%00011000 + STA $2001 + +loop: + INC sleeping +wait_for_vblank_end: + LDA sleeping + BNE wait_for_vblank_end + + LDA #$01 + STA $4016 + LDA #$00 + STA $4016 + + ; we don't care about a, b, select, start + LDA $4016 + LDA $4016 + LDA $4016 + LDA $4016 + +up: + LDA $4016 + AND #%00000001 + BEQ down + LDX sprite_y.w + DEX + STX sprite_y.w +down: + LDA $4016 + AND #%00000001 + BEQ left + LDX sprite_y.w + INX + STX sprite_y.w +left: + LDA $4016 + AND #%00000001 + BEQ right + LDX sprite_x.w + DEX + STX sprite_x.w +right: + LDA $4016 + AND #%00000001 + BEQ loop_end + LDX sprite_x.w + INX + STX sprite_x.w + +loop_end: + JMP loop + +NMI: + PHA + TXA + PHA + TYA + PHA + + ; now the only thing we need to do here is issue a DMA call to transfer our + ; sprite data into SPR-RAM + LDA #$00 + STA $2003 ; reset the SPR-RAM write offset + LDA #$02 + STA $4014 ; start the DMA transfer from $0200 + + LDA #$00 + STA sleeping + PLA + TAY + PLA + TAX + PLA + + RTI + +palette: + .db $0F,$30,$0F,$30,$0F,$30,$0F,$30,$0F,$30,$0F,$30,$0F,$30,$0F,$30 + .db $0F,$30,$0F,$30,$0F,$30,$0F,$30,$0F,$30,$0F,$30,$0F,$30,$0F,$30 + + .orga $FFFA + .dw NMI + .dw RESET + .dw 0 + + .bank 1 slot 1 + .org $0000 + .incbin "sprites.chr" |