Difference between revisions of "6502 Emulator Example Code"

From CDOT Wiki
Jump to: navigation, search
(Created page with "This is a collection of simple examples of 6502 code which will run in the emulator. == Fill the Bitmapped Display == lda #$00 ; set pointer...")
 
(Type on the Screen)
Line 41: Line 41:
 
== Type on the Screen ==
 
== Type on the Screen ==
  
  ; let the user type on the first page of character screen
+
; let the user type on the first page of character screen
  ; has blinking cursor!
+
; has blinking cursor!
  ; backspace works, arrows and ENTER do not
+
; backspace works (non-destructive), arrows/ENTER don't
 
    
 
    
 
  next:    ldx #$00
 
  next:    ldx #$00

Revision as of 13:30, 8 January 2020

This is a collection of simple examples of 6502 code which will run in the emulator.

Fill the Bitmapped Display

      lda #$00     ; set pointer at $10 to $0200
      sta $10
      lda #$02
      sta $11
      
      ldx #$06     ; max value for $11
      
      ldy #$00     ; index

loop: sta ($10),y  ; store colour
      iny          ; increment index
      bne loop     ; branch until overflow
      
      inc $11      ; increment hi byte of pointer
      lda $11      ; load page number as colour
      cpx $11      ; compare with max value
      bne loop     ; continue if not done 
      
      rts          ; return

Place a Message on the Character Display

 define SCREEN $f000
           ldy #$00
 
 char:     lda text,y
           beq done
           sta SCREEN,y
           iny
           bne char
 
 con e:    brk
 
 text:
 dcb "6","5","0","2",32,"w","a","s",32,"h","e","r","e",".",00

Type on the Screen

; let the user type on the first page of character screen
; has blinking cursor!
; backspace works (non-destructive), arrows/ENTER don't
 
next:     ldx #$00
idle:     inx
          cpx #$10
          bne check
          lda $f000,y
          eor #$80
          sta $f000,y

check:    lda $ff
          beq idle

          ldx #$00
          stx $ff

          cmp #$08 ; bs
          bne print

          lda $f000,y
          and #$7f
          sta $f000,y

          dey
          jmp next

print:    sta $f000,y
          iny
          jmp next