In this lab 2, I will describe about 6502 Emulator https://wiki.cdot.senecacollege.ca/wiki/6502_Emulator. I add one bitmap code and describe how this bitmap code will work and how we can count run time of execution.
To run my bitmap code I am using 6502 Emulator http://6502.cdot.systems.
But emulator does not save work automatically, so we have to save our work after we complete.
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 #$07 ; colour number
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
To begin with, above bitmap code will fill pages with yellow color. We have four pages in this 6502 emulator. We can fill any pixel with an color. This is vey simple bitmap code. And this code have description with code so it tells that how each line work.
Calculating Performance
When we calculate execute time we assumes that clock speed is 1 MHz.
This is the excel data that how we count execution time.
Frit line is LDA #$00 which means load accumulator with memory and the # means immediate. So immediate LDA has 2 bytes and it has 2 cycles. We can see this in 6502 emulator instruction set https://www.masswerk.at/6502/6502_instruction_set.html.
Moreover, we can see hexdump in the emulator so it will help to count cycle.
Like, first line is LDA immediate so hexdump is a9 and we can see in the instruction set. In this instruction set have ever code cycles.
In emulator, it says that how man bytes our code used. So we just need to count that cycles to count total execute time.
This cod has 25 bytes and 2867 cycles. As I mentioned that we assume that clock speed is 1 MHz. so this code takes 2867 uS, and 2.867 mS and this code takes 0.002867 second to execute. as I shown you in above screenshot.
I did some changes in that code so code will run fast as compare to older version. I removed load accumulator and store part at the beginning of code.
lda #$07
ldy #$00
loop: sta ($01),y
iny
bne loop
inc $2
ldx $2
cpx #$06
bne loop
This code have only 17 bytes and 2857 cycles. So this code takes only 0.002757 Seconds.
Modifying the Code
We can fill emulator graphic with many colors. You can find color code on the 6502 Emulator page. So in our old code I changed color code to 0E. 0E is the code of light blue.
At last, I edited bitmap code which can fill different color in each page.
1page: lda #$0E
ldy #$00
loop: sta $0200,y
iny
bne loop
2page: lda #$07
ldy #$00
loop1: sta $0300,y
iny
bne loop1
3page: lda #$05
ldy #$00
loop2: sta $0400,y
iny
bne loop2
4page: lda #$08
ldy #$00
loop3: sta $0500,y
iny
bne loop3
In this lab I learned how 6502 Emulator works and how we can create our bitmap code according to requirement. Emulator helps us to reduce the size of photos, videos and so on. In photo there are many pixels with the same color, so we can remove these pixel and make it smaller. I also like that Emulator. It provides many features. Like, we can use debugger, execute speed, error, and so on.
Comments