Last active
October 15, 2015 02:18
-
-
Save honux77/faf8c1a6730349f876bf to your computer and use it in GitHub Desktop.
6502 stack example code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ; ___ _ __ ___ __ ___ | |
| ; / __|_ _ __ _| |_____ / /| __|/ \_ ) | |
| ; \__ \ ' \/ _` | / / -_) _ \__ \ () / / | |
| ; |___/_||_\__,_|_\_\___\___/___/\__/___| | |
| ; Change direction: W A S D | |
| define appleL $00 ; screen location of apple, low byte | |
| define appleH $01 ; screen location of apple, high byte | |
| define snakeHeadL $10 ; screen location of snake head, low byte | |
| define snakeHeadH $11 ; screen location of snake head, high byte | |
| define snakeBodyStart $12 ; start of snake body byte pairs | |
| define snakeDirection $02 ; direction (possible values are below) | |
| define snakeLength $03 ; snake length, in bytes | |
| ; Directions (each using a separate bit) | |
| define movingUp $01 | |
| define movingRight $02 | |
| define movingDown $04 | |
| define movingLeft $08 | |
| ; ASCII values of keys controlling the snake | |
| define ASCII_w $77 | |
| define ASCII_a $61 | |
| define ASCII_s $73 | |
| define ASCII_d $64 | |
| ; System variables | |
| define sysRandom $fe | |
| define sysLastKey $ff | |
| jsr init | |
| jsr test | |
| brk | |
| init: | |
| jsr initSnake | |
| rts | |
| initSnake: | |
| lda #movingRight ;start direction | |
| sta snakeDirection | |
| lda #$04 ;start length (2 segments) | |
| sta snakeLength | |
| lda #$11 | |
| sta snakeHeadL | |
| lda #$10 | |
| sta snakeBodyStart | |
| lda #$0f | |
| sta $14 ; body segment 1 | |
| lda #$04 | |
| sta snakeHeadH | |
| sta $13 ; body segment 1 | |
| sta $15 ; body segment 2 | |
| rts | |
| test: | |
| lda #$01 ;white | |
| ldx #$00 | |
| sta (snakeHeadL,X) | |
| ldx snakeLength | |
| body: | |
| dex | |
| dex | |
| sta (snakeBodyStart,X) | |
| cpx #$00 | |
| bne body | |
| rts |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
코드 실행은 여기에서: https://skilldrick.github.io/easy6502/simulator.html