Friday, March 15, 2024

Exploring Assembly Language Programming with "Kids Learn Numbers" Project

Introduction:

Welcome back to my lab, where I delve into the fascinating world of assembly language programming! In today's session, I'll be exploring a fun project called "Kids Learn Numbers," aimed at teaching young learners to recognize and input numeric values using simple assembly language code. This is the second Lab from my SPO600 course.


Project Overview:

The "Kids Learn Numbers" project is a simple yet engaging program designed to prompt kids to enter specific numbers and get feedback based on their input. This blog, will guide you through the assembly code implementation step by step, explaining the logic behind each instruction.


Setting Up the Environment:

Before we dive into the code, let's ensure that our development environment is properly configured. We'll be using a online 6502 assembly language web simulator, it is hosted here https://matrix.senecapolytechnic.ca/~chris.tyler/6502/, and it provides a user-friendly interface for writing and running 6502 assembly code.


Understanding the Objective:

Our goal is to create a program that prompts the user to enter the number "One" and provide feedback based on their input. If the user enters the correct number, the program will display a congratulatory message; otherwise, it will prompt the user to try again.


Coding the Solution:

Now, let's start coding our solution! We'll break down the assembly code into manageable chunks and explain the purpose of each instruction.


1. Displaying the Prompt:

We begin by displaying a prompt asking the user to enter the number "One." This is achieved using the ldy (load y) to keep track of character displayed, beq instruction to, branch if all the characters are displayed, jsr to put each character on screen, iny to increment the y register so we display the next character, and bne to loop back if whole message is not displayed yet,  now we have  displayed the prompt message on screen.


beginTwo:  ldy #$00

charTwo:   lda textTwo,y

           beq next

           jsr CHROUT  ; put the character in A on to the screen

           iny

           bne charTwo

 done:     brk

 textTwo:

 dcb $0D, "E","n","t","e", "r",32,"T","h","i", "s", 32, "'", "O", "n", "e", "'",  32, "N", "u", "m", "b", "e", "r", ":", 32,00


2. Reading User Input:

Next, we read the user's input from the keyboard and store it in a buffer using the instructions below,  it basically initializes the x register, increments it every time a character is entered, pushed into the accumulator, and persists the location there to be used afterwards to determine the location of the cursor. 


next:    ldx #$00


idle:    inx

           cpx #$10;

           bne check


           txa

           pha

           tya

           pha


           sec

           jsr PLOT

           eor #$80

  jsr CHROUT

           lda #$83    ; cursor left

           jsr CHROUT


           pla

           tay

           pla

           tax


 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


 3. Verifying the Input:

We compare the user's input with the expected value "One" character by character. If the input matches, we display a congratulatory message; otherwise, we prompt the user to try again. Also we mark the graphic screen green if the user answered correctly, and marked the screen red if the user answered incorrectly. 


print:    jsr CHROUT

           cmp #$31               ; Compare with 1

      beq trueone

  jmp notone

           lda #$83    ; cursor left

  pla

           tay

           pla

           tax ;sta $f000,y

           

  iny

jmp next


4. Learning the next number:

After marking the screen, green if the value entered is correct, it would first prompt for the next number, and then follow the same steps shown above for the next number. 


green: lda #$00 ; set a pointer in memory location $40 to point to $0200

  sta $40 ; ... low byte ($00) goes in address $40

  lda #$02

  sta $41 ; ... high byte ($02) goes into address $41

  lda #$05 ; colour number 2

  ldy #$00 ; set index to 0

 loop: sta ($40),y ; set pixel colour at the address (pointer)+Y

iny ; increment index

  bne loop ; continue until done the page (256 pixels)

  inc $41 ; increment the page

  ldx $41 ; get the current page number

  cpx #$06 ; compare with 6

  bne loop ; continue until done all pages

jmp nexttwo


notone:   ldy #$00

charnone:   lda textnone,y

           beq red

           jsr CHROUT  ; put the character in A on to the screen

           iny

           bne charnone

 done:     brk

 textnone:

 dcb $0D, "T", "h", "a", "t", 32, "w", "a", "s", 32, "i", "n", "c", "o", "r", "r", "e", "c", "t", 32, "e", "n", "t", "e", "r", 32,  "'", "O", "n", "e", "'", 32, "A", "g", "a", "i", "n", ":", 32,00


red: lda #$00 ; set a pointer in memory location $40 to point to $0200

  sta $40 ; ... low byte ($00) goes in address $40

  lda #$02

  sta $41 ; ... high byte ($02) goes into address $41

  lda #$02 ; colour number 2

  ldy #$00 ; set index to 0

 loop: sta ($40),y ; set pixel colour at the address (pointer)+Y

iny ; increment index

  bne loop ; continue until done the page (256 pixels)

  inc $41 ; increment the page

  ldx $41 ; get the current page number

  cpx #$06 ; compare with 6

  bne loop


jmp next


nexttwo:     ldx #$00


 idletwo:     inx

           cpx #$10;

           bne checktwo


           txa

           pha

           tya

           pha


           sec

           jsr PLOT

           eor #$80

  jsr CHROUT

           lda #$83    ; cursor left

           jsr CHROUT


           pla

           tay

           pla

           tax


 checktwo:    lda $ff

           beq idletwo

           ldx #$00

           stx $ff


           cmp #$08 ; bs

           bne printtwo

           lda $f000,y

           and #$7f

           sta $f000,y

           dey

           jmp nexttwo


 printtwo:    jsr CHROUT

           cmp #$32               ; Compare with 2

      beq truetwo

  jmp nottwo

           lda #$83    ; cursor left

  pla

           tay

           pla

           tax ;sta $f000,y

           

  iny

           jmp nexttwo


truetwo:   ldy #$00

chartwo:   lda texttwo,y

           beq greentwo

           jsr CHROUT  ; put the character in A on to the screen

           iny

           bne chartwo

 done:     brk

 texttwo:

 dcb $0D, "T", "h", "a", "t", 32, "w", "a", "s", 32, "c", "o", "r", "r", "e", "c", "t", 32, "e", "n", "t", "e", "r", 32,  "'", "T", "h", "r", "e", "e", "'", 32, "N", "o", "w",":", 32,00


6. The end of the program

The end of this program would be that, it would congratulate that you can count till 9 and will give you an option to restart the game. It would like this:







This is the complete code if you want to run and test the code yourself:

; Kids Learn Numbers


 define SCINIT $ff81 ; initialize/clear screen

 define CHRIN $ffcf ; input character from keyboard

 define CHROUT $ffd2 ; output character to screen

 define SCREEN $ffed ; get screen size

 define PLOT $fff0 ; get/set cursor coordinates

  

; ROM routines

 

beginOne:  jsr SCINIT  ; initialize and clear the 2screen

           ldy #$00

 char:     lda text,y

           beq beginTwo

           jsr CHROUT  ; put the character in A on to the screen

           iny

           bne char

 done:     brk

 text:

 dcb "K","i","d","s",32,"L","e","a", "r", "n",32,"N","u","m","b","e", "r", "s",00


beginTwo:  ldy #$00

charTwo:   lda textTwo,y

           beq next

           jsr CHROUT  ; put the character in A on to the screen

           iny

           bne charTwo

 done:     brk

 textTwo:

 dcb $0D, "E","n","t","e", "r",32,"T","h","i", "s", 32, "'", "O", "n", "e", "'",  32, "N", "u", "m", "b", "e", "r", ":", 32,00



; let the user type on the first page of character screen

 ; has blinking cursor!

 ; does not use ROM routines

 ; backspace works (non-destructive), arrows/ENTER don't

 next:     ldx #$00


 idle:     inx

           cpx #$10;

           bne check


           txa

           pha

           tya

           pha


           sec

           jsr PLOT

           eor #$80

  jsr CHROUT

           lda #$83    ; cursor left

           jsr CHROUT


           pla

           tay

           pla

           tax


 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:    jsr CHROUT

           cmp #$31               ; Compare with 1

      beq trueone

  jmp notone

           lda #$83    ; cursor left

  pla

           tay

           pla

           tax ;sta $f000,y

           

  iny

jmp next


trueone:   ldy #$00

charone:   lda textone,y

           beq green

           jsr CHROUT  ; put the character in A on to the screen

           iny

           bne charone

 done:     brk

 textone:

 dcb $0D, "T", "h", "a", "t", 32, "w", "a", "s", 32, "c", "o", "r", "r", "e", "c", "t", 32, "e", "n", "t", "e", "r", 32,  "'", "T", "w", "o", "'", 32, "N", "o", "w",":", 32,00


green: lda #$00 ; set a pointer in memory location $40 to point to $0200

  sta $40 ; ... low byte ($00) goes in address $40

  lda #$02

  sta $41 ; ... high byte ($02) goes into address $41

  lda #$05 ; colour number 2

  ldy #$00 ; set index to 0

 loop: sta ($40),y ; set pixel colour at the address (pointer)+Y

iny ; increment index

  bne loop ; continue until done the page (256 pixels)

  inc $41 ; increment the page

  ldx $41 ; get the current page number

  cpx #$06 ; compare with 6

  bne loop ; continue until done all pages

jmp nexttwo


notone:   ldy #$00

charnone:   lda textnone,y

           beq red

           jsr CHROUT  ; put the character in A on to the screen

           iny

           bne charnone

 done:     brk

 textnone:

 dcb $0D, "T", "h", "a", "t", 32, "w", "a", "s", 32, "i", "n", "c", "o", "r", "r", "e", "c", "t", 32, "e", "n", "t", "e", "r", 32,  "'", "O", "n", "e", "'", 32, "A", "g", "a", "i", "n", ":", 32,00


red: lda #$00 ; set a pointer in memory location $40 to point to $0200

  sta $40 ; ... low byte ($00) goes in address $40

  lda #$02

  sta $41 ; ... high byte ($02) goes into address $41

  lda #$02 ; colour number 2

  ldy #$00 ; set index to 0

 loop: sta ($40),y ; set pixel colour at the address (pointer)+Y

iny ; increment index

  bne loop ; continue until done the page (256 pixels)

  inc $41 ; increment the page

  ldx $41 ; get the current page number

  cpx #$06 ; compare with 6

  bne loop


jmp next


; 2 2222222


nexttwo:     ldx #$00


 idletwo:     inx

           cpx #$10;

           bne checktwo


           txa

           pha

           tya

           pha


           sec

           jsr PLOT

           eor #$80

  jsr CHROUT

           lda #$83    ; cursor left

           jsr CHROUT


           pla

           tay

           pla

           tax


 checktwo:    lda $ff

           beq idletwo

           ldx #$00

           stx $ff


           cmp #$08 ; bs

           bne printtwo

           lda $f000,y

           and #$7f

           sta $f000,y

           dey

           jmp nexttwo


 printtwo:    jsr CHROUT

           cmp #$32               ; Compare with 2

      beq truetwo

  jmp nottwo

           lda #$83    ; cursor left

  pla

           tay

           pla

           tax ;sta $f000,y

           

  iny

           jmp nexttwo


truetwo:   ldy #$00

chartwo:   lda texttwo,y

           beq greentwo

           jsr CHROUT  ; put the character in A on to the screen

           iny

           bne chartwo

 done:     brk

 texttwo:

 dcb $0D, "T", "h", "a", "t", 32, "w", "a", "s", 32, "c", "o", "r", "r", "e", "c", "t", 32, "e", "n", "t", "e", "r", 32,  "'", "T", "h", "r", "e", "e", "'", 32, "N", "o", "w",":", 32,00


greentwo: lda #$00 ; set a pointer in memory location $40 to point to $0200

  sta $40 ; ... low byte ($00) goes in address $40

  lda #$02

  sta $41 ; ... high byte ($02) goes into address $41

  lda #$05 ; colour number 2

  ldy #$00 ; set index to 0

 looptwo: sta ($40),y ; set pixel colour at the address (pointer)+Y

iny ; increment index

  bne looptwo ; continue until done the page (256 pixels)

  inc $41 ; increment the page

  ldx $41 ; get the current page number

  cpx #$06 ; compare with 6

  bne looptwo ; continue until done all pages

jmp nextthree


nottwo:   ldy #$00

charntwo:   lda textntwo,y

           beq redtwo

           jsr CHROUT  ; put the character in A on to the screen

           iny

           bne charntwo

 done:     brk

 textntwo:

 dcb $0D, "T", "h", "a", "t", 32, "w", "a", "s", 32, "i", "n", "c", "o", "r", "r", "e", "c", "t", 32, "e", "n", "t", "e", "r", 32,  "'", "T", "w", "o", "'", 32, "A", "g", "a", "i", "n", ":", 32,00


redtwo: lda #$00 ; set a pointer in memory location $40 to point to $0200

  sta $40 ; ... low byte ($00) goes in address $40

  lda #$02

  sta $41 ; ... high byte ($02) goes into address $41

  lda #$02 ; colour number 2

  ldy #$00 ; set index to 0

 looptwo: sta ($40),y ; set pixel colour at the address (pointer)+Y

iny ; increment index

  bne looptwo ; continue until done the page (256 pixels)

  inc $41 ; increment the page

  ldx $41 ; get the current page number

  cpx #$06 ; compare with 6

  bne looptwo ; continue until done all pages

jmp nexttwo


;3333333333

nextthree:     ldx #$00


 idlethree:     inx

           cpx #$10;

           bne checkthree


           txa

           pha

           tya

           pha


           sec

           jsr PLOT

           eor #$80

  jsr CHROUT

           lda #$83    ; cursor left

           jsr CHROUT


           pla

           tay

           pla

           tax


 checkthree:    lda $ff

           beq idlethree

           ldx #$00

           stx $ff


           cmp #$08 ; bs

           bne printthree

           lda $f000,y

           and #$7f

           sta $f000,y

           dey

           jmp nextthree


 printthree:    jsr CHROUT

           cmp #$33               ; Compare with 2

      beq truethree

  jmp notthree

           lda #$83    ; cursor left

  pla

           tay

           pla

           tax ;sta $f000,y

           

  iny

           jmp nextthree


truethree:   ldy #$00

charthree:   lda textthree,y

           beq greenthree

           jsr CHROUT  ; put the character in A on to the screen

           iny

           bne charthree

 done:     brk

 textthree:

 dcb $0D, "T", "h", "a", "t", 32, "w", "a", "s", 32, "c", "o", "r", "r", "e", "c", "t", 32, "e", "n", "t", "e", "r", 32,  "'", "F", "o", "u", "r", "'", 32, "N", "o", "w",":", 32,00


greenthree: lda #$00 ; set a pointer in memory location $40 to point to $0200

  sta $40 ; ... low byte ($00) goes in address $40

  lda #$02

  sta $41 ; ... high byte ($02) goes into address $41

  lda #$05 ; colour number 2

  ldy #$00 ; set index to 0

 loopthree: sta ($40),y ; set pixel colour at the address (pointer)+Y

iny ; increment index

  bne loopthree ; continue until done the page (256 pixels)

  inc $41 ; increment the page

  ldx $41 ; get the current page number

  cpx #$06 ; compare with 6

  bne loopthree ; continue until done all pages

jmp nextfour


notthree:   ldy #$00

charnthree:   lda textnthree,y

           beq redthree

           jsr CHROUT  ; put the character in A on to the screen

           iny

           bne charnthree

 done:     brk

 textnthree:

 dcb $0D, "T", "h", "a", "t", 32, "w", "a", "s", 32, "i", "n", "c", "o", "r", "r", "e", "c", "t", 32, "e", "n", "t", "e", "r", 32,  "'", "T", "h", "r", "e", "e", "'", 32, "A", "g", "a", "i", "n", ":", 32,00



redthree: lda #$00 ; set a pointer in memory location $40 to point to $0200

  sta $40 ; ... low byte ($00) goes in address $40

  lda #$02

  sta $41 ; ... high byte ($02) goes into address $41

  lda #$02 ; colour number 2

  ldy #$00 ; set index to 0

 loopthree: sta ($40),y ; set pixel colour at the address (pointer)+Y

iny ; increment index

  bne loopthree ; continue until done the page (256 pixels)

  inc $41 ; increment the page

  ldx $41 ; get the current page number

  cpx #$06 ; compare with 6

  bne loopthree ; continue until done all pages

jmp nextthree


;44444


nextfour:     ldx #$00


 idlefour:     inx

           cpx #$10;

           bne checkfour


           txa

           pha

           tya

           pha


           sec

           jsr PLOT

           eor #$80

  jsr CHROUT

           lda #$83    ; cursor left

           jsr CHROUT


           pla

           tay

           pla

           tax


 checkfour:    lda $ff

           beq idlefour

           ldx #$00

           stx $ff


           cmp #$08 ; bs

           bne printfour

           lda $f000,y

           and #$7f

           sta $f000,y

           dey

           jmp nextfour


 printfour:    jsr CHROUT

           cmp #$34               ; Compare with 2

      beq truefour

  jmp notfour

           lda #$83    ; cursor left

  pla

           tay

           pla

           tax ;sta $f000,y

           

  iny

           jmp nextfour


truefour:   ldy #$00

charfour:   lda textfour,y

           beq greenfour

           jsr CHROUT  ; put the character in A on to the screen

           iny

           bne charfour

 done:     brk

 textfour:

 dcb $0D, "T", "h", "a", "t", 32, "w", "a", "s", 32, "c", "o", "r", "r", "e", "c", "t", 32, "e", "n", "t", "e", "r", 32,  "'", "F", "i", "v", "e", "'", 32, "N", "o", "w",":", 32,00


greenfour: lda #$00 ; set a pointer in memory location $40 to point to $0200

  sta $40 ; ... low byte ($00) goes in address $40

  lda #$02

  sta $41 ; ... high byte ($02) goes into address $41

  lda #$05 ; colour number 2

  ldy #$00 ; set index to 0

 loopfour: sta ($40),y ; set pixel colour at the address (pointer)+Y

iny ; increment index

  bne loopfour ; continue until done the page (256 pixels)

  inc $41 ; increment the page

  ldx $41 ; get the current page number

  cpx #$06 ; compare with 6

  bne loopfour ; continue until done all pages

jmp nextfive


notfour:   ldy #$00

charnfour:   lda textnfour,y

           beq redfour

           jsr CHROUT  ; put the character in A on to the screen

           iny

           bne charnfour

 done:     brk

 textnfour:

 dcb $0D, "T", "h", "a", "t", 32, "w", "a", "s", 32, "i", "n", "c", "o", "r", "r", "e", "c", "t", 32, "e", "n", "t", "e", "r", 32,  "'", "F", "o", "u", "r", "'", 32, "A", "g", "a", "i", "n", ":", 32,00



redfour: lda #$00 ; set a pointer in memory location $40 to point to $0200

  sta $40 ; ... low byte ($00) goes in address $40

  lda #$02

  sta $41 ; ... high byte ($02) goes into address $41

  lda #$02 ; colour number 2

  ldy #$00 ; set index to 0

 loopfour: sta ($40),y ; set pixel colour at the address (pointer)+Y

iny ; increment index

  bne loopfour ; continue until done the page (256 pixels)

  inc $41 ; increment the page

  ldx $41 ; get the current page number

  cpx #$06 ; compare with 6

  bne loopfour ; continue until done all pages

jmp nextfour


;55555


nextfive:     ldx #$00


 idlefive:     inx

           cpx #$10;

           bne checkfive


           txa

           pha

           tya

           pha


           sec

           jsr PLOT

           eor #$80

  jsr CHROUT

           lda #$83    ; cursor left

           jsr CHROUT


           pla

           tay

           pla

           tax


 checkfive:    lda $ff

           beq idlefive

           ldx #$00

           stx $ff


           cmp #$08 ; bs

           bne printfive

           lda $f000,y

           and #$7f

           sta $f000,y

           dey

           jmp nextfive


 printfive:    jsr CHROUT

           cmp #$35               ; Compare with 2

      beq truefive

  jmp notfive

           lda #$83    ; cursor left

  pla

           tay

           pla

           tax ;sta $f000,y

           

  iny

           jmp nextfive


truefive:   ldy #$00

charfive:   lda textfive,y

           beq greenfive

           jsr CHROUT  ; put the character in A on to the screen

           iny

           bne charfive

 done:     brk

 textfive:

 dcb $0D, "T", "h", "a", "t", 32, "w", "a", "s", 32, "c", "o", "r", "r", "e", "c", "t", 32, "e", "n", "t", "e", "r", 32,  "'", "S", "i", "x", "'", 32, "N", "o", "w",":", 32,00


greenfive: lda #$00 ; set a pointer in memory location $40 to point to $0200

  sta $40 ; ... low byte ($00) goes in address $40

  lda #$02

  sta $41 ; ... high byte ($02) goes into address $41

  lda #$05 ; colour number 2

  ldy #$00 ; set index to 0

 loopfive: sta ($40),y ; set pixel colour at the address (pointer)+Y

iny ; increment index

  bne loopfive ; continue until done the page (256 pixels)

  inc $41 ; increment the page

  ldx $41 ; get the current page number

  cpx #$06 ; compare with 6

  bne loopfive ; continue until done all pages

jmp nextsix


notfive:   ldy #$00

charnfive:   lda textnfive,y

           beq redfive

           jsr CHROUT  ; put the character in A on to the screen

           iny

           bne charnfive

 done:     brk

 textnfive:

 dcb $0D, "T", "h", "a", "t", 32, "w", "a", "s", 32, "i", "n", "c", "o", "r", "r", "e", "c", "t", 32, "e", "n", "t", "e", "r", 32,  "'", "F", "i", "v", "e", "'", 32, "A", "g", "a", "i", "n", ":", 32,00



redfive: lda #$00 ; set a pointer in memory location $40 to point to $0200

  sta $40 ; ... low byte ($00) goes in address $40

  lda #$02

  sta $41 ; ... high byte ($02) goes into address $41

  lda #$02 ; colour number 2

  ldy #$00 ; set index to 0

 loopfive: sta ($40),y ; set pixel colour at the address (pointer)+Y

iny ; increment index

  bne loopfive ; continue until done the page (256 pixels)

  inc $41 ; increment the page

  ldx $41 ; get the current page number

  cpx #$06 ; compare with 6

  bne loopfive ; continue until done all pages

jmp nextfive

;6666666

nextsix:     ldx #$00


 idlesix:     inx

           cpx #$10;

           bne checksix


           txa

           pha

           tya

           pha


           sec

           jsr PLOT

           eor #$80

  jsr CHROUT

           lda #$83    ; cursor left

           jsr CHROUT


           pla

           tay

           pla

           tax


 checksix:    lda $ff

           beq idlesix

           ldx #$00

           stx $ff


           cmp #$08 ; bs

           bne printsix

           lda $f000,y

           and #$7f

           sta $f000,y

           dey

           jmp nextsix


 printsix:    jsr CHROUT

           cmp #$36               ; Compare with 6

      beq truesix

  jmp notsix

           lda #$83    ; cursor left

  pla

           tay

           pla

           tax ;sta $f000,y

           

  iny

           jmp nextsix


truesix:   ldy #$00

charsix:   lda textsix,y

           beq greensix

           jsr CHROUT  ; put the character in A on to the screen

           iny

           bne charsix

 done:     brk

 textsix:

 dcb $0D, "T", "h", "a", "t", 32, "w", "a", "s", 32, "c", "o", "r", "r", "e", "c", "t", 32, "e", "n", "t", "e", "r", 32,  "'", "S", "e", "v", "e", "n", "'", 32, "N", "o", "w",":", 32,00


greensix: lda #$00 ; set a pointer in memory location $40 to point to $0200

  sta $40 ; ... low byte ($00) goes in address $40

  lda #$02

  sta $41 ; ... high byte ($02) goes into address $41

  lda #$05 ; colour number 2

  ldy #$00 ; set index to 0

 loopsix: sta ($40),y ; set pixel colour at the address (pointer)+Y

iny ; increment index

  bne loopsix ; continue until done the page (256 pixels)

  inc $41 ; increment the page

  ldx $41 ; get the current page number

  cpx #$06 ; compare with 6

  bne loopsix ; continue until done all pages

jmp nextseven


notsix:   ldy #$00

charnsix:   lda textnsix,y

           beq redsix

           jsr CHROUT  ; put the character in A on to the screen

           iny

           bne charnsix

 done:     brk

 textnsix:

 dcb $0D, "T", "h", "a", "t", 32, "w", "a", "s", 32, "i", "n", "c", "o", "r", "r", "e", "c", "t", 32, "e", "n", "t", "e", "r", 32,  "'", "S", "i", "x", "'", 32, "A", "g", "a", "i", "n", ":", 32,00



redsix: lda #$00 ; set a pointer in memory location $40 to point to $0200

  sta $40 ; ... low byte ($00) goes in address $40

  lda #$02

  sta $41 ; ... high byte ($02) goes into address $41

  lda #$02 ; colour number 2

  ldy #$00 ; set index to 0

 loopsix: sta ($40),y ; set pixel colour at the address (pointer)+Y

iny ; increment index

  bne loopsix ; continue until done the page (256 pixels)

  inc $41 ; increment the page

  ldx $41 ; get the current page number

  cpx #$06 ; compare with 6

  bne loopsix ; continue until done all pages

jmp nextsix


;777777

nextseven:     ldx #$00


idleseven:     inx

           cpx #$10;

           bne checkseven


           txa

           pha

           tya

           pha


           sec

           jsr PLOT

           eor #$80

  jsr CHROUT

           lda #$83    ; cursor left

           jsr CHROUT


           pla

           tay

           pla

           tax


 checkseven:    lda $ff

           beq idleseven

           ldx #$00

           stx $ff


           cmp #$08 ; bs

           bne printseven

           lda $f000,y

           and #$7f

           sta $f000,y

           dey

           jmp nextseven


 printseven:    jsr CHROUT

           cmp #$37               ; Compare with 7

      beq trueseven

  jmp notseven

           lda #$83    ; cursor left

  pla

           tay

           pla

           tax ;sta $f000,y

           

  iny

           jmp nextseven


trueseven:   ldy #$00

charseven:   lda textseven,y

           beq greenseven

           jsr CHROUT  ; put the character in A on to the screen

           iny

           bne charseven

 done:     brk

 textseven:

 dcb $0D, "T", "h", "a", "t", 32, "w", "a", "s", 32, "c", "o", "r", "r", "e", "c", "t", 32, "e", "n", "t", "e", "r", 32,  "'", "E", "i", "g", "h", "t", "'", 32, "N", "o", "w",":", 32,00


greenseven: lda #$00 ; set a pointer in memory location $40 to point to $0200

  sta $40 ; ... low byte ($00) goes in address $40

  lda #$02

  sta $41 ; ... high byte ($02) goes into address $41

  lda #$05 ; colour number 2

  ldy #$00 ; set index to 0

 loopseven: sta ($40),y ; set pixel colour at the address (pointer)+Y

iny ; increment index

  bne loopseven ; continue until done the page (256 pixels)

  inc $41 ; increment the page

  ldx $41 ; get the current page number

  cpx #$06 ; compare with 6

  bne loopseven ; continue until done all pages

jmp nexteight


notseven:   ldy #$00

charnseven:   lda textnseven,y

           beq redseven

           jsr CHROUT  ; put the character in A on to the screen

           iny

           bne charnseven

 done:     brk

 textnseven:

 dcb $0D, "T", "h", "a", "t", 32, "w", "a", "s", 32, "i", "n", "c", "o", "r", "r", "e", "c", "t", 32, "e", "n", "t", "e", "r", 32,  "'", "S", "e", "v", "e", "n", "'", 32, "A", "g", "a", "i", "n", ":", 32,00



redseven: lda #$00 ; set a pointer in memory location $40 to point to $0200

  sta $40 ; ... low byte ($00) goes in address $40

  lda #$02

  sta $41 ; ... high byte ($02) goes into address $41

  lda #$02 ; colour number 2

  ldy #$00 ; set index to 0

 loopseven: sta ($40),y ; set pixel colour at the address (pointer)+Y

iny ; increment index

  bne loopseven ; continue until done the page (256 pixels)

  inc $41 ; increment the page

  ldx $41 ; get the current page number

  cpx #$06 ; compare with 6

  bne loopseven ; continue until done all pages

jmp nextseven

;88888


nexteight:     ldx #$00


idleeight:     inx

           cpx #$10;

           bne checkeight


           txa

           pha

           tya

           pha


           sec

           jsr PLOT

           eor #$80

  jsr CHROUT

           lda #$83    ; cursor left

           jsr CHROUT


           pla

           tay

           pla

           tax


 checkeight:    lda $ff

           beq idleeight

           ldx #$00

           stx $ff


           cmp #$08 ; bs

           bne printeight

           lda $f000,y

           and #$7f

           sta $f000,y

           dey

           jmp nexteight


 printeight:    jsr CHROUT

           cmp #$38               ; Compare with 7

      beq trueeight

  jmp noteight

           lda #$83    ; cursor left

  pla

           tay

           pla

           tax ;sta $f000,y

           

  iny

           jmp nexteight


trueeight:   ldy #$00

chareight:   lda texteight,y

           beq greeneight

           jsr CHROUT  ; put the character in A on to the screen

           iny

           bne chareight

 done:     brk

 texteight:

 dcb $0D, "T", "h", "a", "t", 32, "w", "a", "s", 32, "c", "o", "r", "r", "e", "c", "t", 32, "e", "n", "t", "e", "r", 32,  "'", "N", "i", "n", "e", "'", 32, "N", "o", "w",":", 32,00


greeneight: lda #$00 ; set a pointer in memory location $40 to point to $0200

  sta $40 ; ... low byte ($00) goes in address $40

  lda #$02

  sta $41 ; ... high byte ($02) goes into address $41

  lda #$05 ; colour number 2

  ldy #$00 ; set index to 0

 loopeight: sta ($40),y ; set pixel colour at the address (pointer)+Y

iny ; increment index

  bne loopeight ; continue until done the page (256 pixels)

  inc $41 ; increment the page

  ldx $41 ; get the current page number

  cpx #$06 ; compare with 6

  bne loopeight ; continue until done all pages

jmp nextnine


noteight:   ldy #$00

charneight:   lda textneight,y

           beq redeight

           jsr CHROUT  ; put the character in A on to the screen

           iny

           bne charneight

 done:     brk

 textneight:

 dcb $0D, "T", "h", "a", "t", 32, "w", "a", "s", 32, "i", "n", "c", "o", "r", "r", "e", "c", "t", 32, "e", "n", "t", "e", "r", 32,  "'", "E", "i", "g", "h", "t", "'", 32, "A", "g", "a", "i", "n", ":", 32,00



redeight: lda #$00 ; set a pointer in memory location $40 to point to $0200

  sta $40 ; ... low byte ($00) goes in address $40

  lda #$02

  sta $41 ; ... high byte ($02) goes into address $41

  lda #$02 ; colour number 2

  ldy #$00 ; set index to 0

 loopeight: sta ($40),y ; set pixel colour at the address (pointer)+Y

iny ; increment index

  bne loopeight ; continue until done the page (256 pixels)

  inc $41 ; increment the page

  ldx $41 ; get the current page number

  cpx #$06 ; compare with 6

  bne loopeight ; continue until done all pages

jmp nexteight

;99999


nextnine:     ldx #$00


idlenine:     inx

           cpx #$10;

           bne checknine


           txa

           pha

           tya

           pha


           sec

           jsr PLOT

           eor #$80

  jsr CHROUT

           lda #$83    ; cursor left

           jsr CHROUT


           pla

           tay

           pla

           tax


 checknine:    lda $ff

           beq idlenine

           ldx #$00

           stx $ff


           cmp #$08 ; bs

           bne printnine

           lda $f000,y

           and #$7f

           sta $f000,y

           dey

           jmp nextnine


 printnine:    jsr CHROUT

           cmp #$39               ; Compare with 7

      beq truenine

  jmp notnine

           lda #$83    ; cursor left

  pla

           tay

           pla

           tax ;sta $f000,y

           

  iny

           jmp nextnine


truenine:   ldy #$00

charnine:   lda textnine,y

           beq greennine

           jsr CHROUT  ; put the character in A on to the screen

           iny

           bne charnine

 done:     brk

   textnine:

 dcb $0D, "T", "h", "a", "t", 32, "w", "a", "s", 32, "c", "o", "r", "r", "e", "c", "t", 32, "e", "n", "t", "e", "r",32, "y", "o", "u", 32, "w", "o", "n", 32, "e", "n", "t", "e", "r", 32, "a", "n", "y", 32, "k", "e", "y", 32, "t", "o", 32, "r", "e", "s", "t", "a", "r", "t", "!", 32,00


greennine: lda #$00 ; set a pointer in memory location $40 to point to $0200

  sta $40 ; ... low byte ($00) goes in address $40

  lda #$02

  sta $41 ; ... high byte ($02) goes into address $41

  lda #$05 ; colour number 2

  ldy #$00 ; set index to 0

 loopnine: sta ($40),y ; set pixel colour at the address (pointer)+Y

iny ; increment index

  bne loopnine ; continue until done the page (256 pixels)

  inc $41 ; increment the page

  ldx $41 ; get the current page number

  cpx #$06 ; compare with 6

  bne loopnine ; continue until done all pages

jmp restart


notnine:   ldy #$00

charnnine:   lda textnnine,y

           beq rednine

           jsr CHROUT  ; put the character in A on to the screen

           iny

           bne charnnine

 done:     brk

 textnnine:

 dcb $0D, "T", "h", "a", "t", 32, "w", "a", "s", 32, "i", "n", "c", "o", "r", "r", "e", "c", "t", 32, "e", "n", "t", "e", "r", 32,  "'", "N", "i", "n", "e", "'", 32, "A", "g", "a", "i", "n", ":", 32,00



rednine: lda #$00 ; set a pointer in memory location $40 to point to $0200

  sta $40 ; ... low byte ($00) goes in address $40

  lda #$02

  sta $41 ; ... high byte ($02) goes into address $41

  lda #$02 ; colour number 2

  ldy #$00 ; set index to 0

 loopnine: sta ($40),y ; set pixel colour at the address (pointer)+Y

iny ; increment index

  bne loopnine ; continue until done the page (256 pixels)

  inc $41 ; increment the page

  ldx $41 ; get the current page number

  cpx #$06 ; compare with 6

  bne loopnine ; continue until done all pages

jmp nextnine


restart:     ldx #$00


idler:     inx

           cpx #$10;

           bne checkr


           txa

           pha

           tya

           pha


           sec

           jsr PLOT

           eor #$80

  jsr CHROUT

           lda #$83    ; cursor left

           jsr CHROUT


           pla

           tay

           pla

           tax


 checkr:    lda $ff

           beq idler

           ldx #$00

           stx $ff


           cmp #$08 ; bs

           bne printr

           lda $f000,y

           and #$7f

           sta $f000,y

           dey

           jmp nextr


 printr:    jsr CHROUT

           cmp #$39     

  jmp beginOne


Conclusion:

In this lab session, we've explored the "Kids Learn Numbers" project, which serves as an excellent introduction to assembly language programming. By breaking down the code and explaining each instruction, I hope to have provided you with a better understanding of assembly language programming concepts. Stay tuned for more exciting projects and tutorials in future sessions!


Happy coding!

No comments:

Post a Comment

Project Stage 2 & 3: Command Line Parsing

Hey there, fellow tech enthusiasts! It's time for another update on my SPO600 Winter Project journey. Stage 2 has been quite a rollercoa...