DEV Community

Cover image for Easiest program in 6502 emulator part-1
Yukti Manoj Mulani
Yukti Manoj Mulani

Posted on

Easiest program in 6502 emulator part-1

Hi folks,
I'm back with another update from my Software Portability and Optimization course. This time around, we're diving into some pretty challenging territory. Our task? Writing a program for the 6502 Emulator that fulfills some rather specific requirements:

  1. The program must function seamlessly in the 6502 Emulator.
  2. It needs to output to both the character screen and the graphics (bitmapped) screen.
  3. User input, in some form, must be accepted from the keyboard.
  4. We're required to incorporate arithmetic/math instructions, such as adding, subtracting, doing bitwise operations, or performing rotations/shifts.

Those are quite the demands, straight from the professor. It feels a bit overwhelming, especially considering we're only in the second week of learning assembly language. Just printing a single sentence can take up to 10 lines of code! Take, for instance, the task of printing "6502 was here" on the text display without using ROM subroutines. It's a process that seems to stretch on and on:

  define SCREEN $f000     ; location of screen memory
            ldy #$00      ; index value (character we're currently processing)
  char:     lda text,y    ; get a character from address (text + Y)
            beq done      ; if the character is NULL, branch to done
            sta SCREEN,y  ; store character at (SCREEN + Y)
            iny           ; increment Y (go to next character)
            bne char      ; repeat loop
  done:     brk           ; when we're done, break (stop the program)
  text:                   ; this is the text message
  dcb "6","5","0","2",32,"w","a","s",32,"h","e","r","e",".",00
Enter fullscreen mode Exit fullscreen mode

This is like 10 line already!!.😫

Just reading through that is exhausting, let alone writing it!

I've been wracking my brain for simpler program ideas, ones that require minimal code. But even seemingly straightforward tasks like "Guess the random number" end up demanding a complex structure.

So, here's what I've come up with so far: a program that prompts the user to enter a color. Once entered, the program will display that color by coloring the bitmap display accordingly. It ticks off most of the requirements:

  1. The program runs on the 6502 emulator (that's a given).
  2. It outputs to both the character screen and the graphics (bitmapped) screen (thanks to the prompt for color input and the color display on the bitmap).
  3. User input is accepted from the keyboard (in this case, to input a color).
  4. Here's where I hit a roadblock. I'm not sure how to incorporate arithmetic/math instructions into the program. Maybe some of you savvy readers can lend a hand in the comments section?

I'm all ears for suggestions and insights! If you have any ideas on how to incorporate arithmetic/math instructions into the program or any other tips for simplifying the task, please share them in the comments below. Let's tackle this challenge together!

Thanks in advance!😉

Top comments (0)