feat: optimizations

This commit is contained in:
Stefano Furiosi 2023-07-02 21:10:00 -07:00
parent b4ed402b31
commit 6e9d803dce
8 changed files with 194 additions and 183 deletions

View File

@ -1,7 +1,6 @@
#importonce #importonce
#import "../core/module.asm" #import "../core/module.asm"
#import "../libs/memory.asm" #import "../libs/memory.asm"
#import "../core/module.asm"
.filenamespace Keyboard .filenamespace Keyboard

View File

@ -145,6 +145,8 @@ init: {
sta MemMap.VIDEO.CursorRow sta MemMap.VIDEO.CursorRow
lda #%00000000 lda #%00000000
sta MemMap.VIDEO.StatusBitsA sta MemMap.VIDEO.StatusBitsA
lda #COLUMN_NUM
sta MemMap.MATH.factor2
rts rts
} }
@ -186,86 +188,80 @@ scrollUp: {
// A = Character to Print VIDEO ASCII // A = Character to Print VIDEO ASCII
// -------------------------------------------------------- // --------------------------------------------------------
sendChar: { sendChar: {
sei sei
phx phx
cmp #CR cmp #CR
bne !+ bne notCR
jsr screenNewLine jsr screenNewLine
iny iny
jmp exit jmp exit
!:
cmp #BS
bne !+
ldx MemMap.VIDEO.CursorCol
cmp #0
beq exit
dec MemMap.VIDEO.CursorCol
!:
// Store Base Video Address 16 bit
ldx #<VIDEO_ADDR // Low byte
stx MemMap.VIDEO.TempVideoPointer
ldx #>VIDEO_ADDR // High byte
stx MemMap.VIDEO.TempVideoPointer+1
// Temp Save Y notCR:
phy cmp #BS
bne notBS
ldx MemMap.VIDEO.CursorCol
beq exit
dec MemMap.VIDEO.CursorCol
jmp storeBaseVideoAddress
// CursorRow * 40 notBS:
ldy MemMap.VIDEO.CursorRow // Store Base Video Address 16 bit
sty MemMap.MATH.factor1 storeBaseVideoAddress:
ldy #COLUMN_NUM ldx #<VIDEO_ADDR // Low byte
sty MemMap.MATH.factor2 stx MemMap.VIDEO.TempVideoPointer
jsr Math.multiply ldx #>VIDEO_ADDR // High byte
stx MemMap.VIDEO.TempVideoPointer+1
// Add mul result to TempVideoPointer // CursorRow * 40
pha ldy MemMap.VIDEO.CursorRow
sty MemMap.MATH.factor1
jsr Math.multiply
clc // Add mul result to TempVideoPointer
lda MemMap.MATH.result pha
adc MemMap.VIDEO.TempVideoPointer+1 clc
sta MemMap.VIDEO.TempVideoPointer+1 lda MemMap.MATH.result
lda MemMap.MATH.result+1 adc MemMap.VIDEO.TempVideoPointer+1
adc MemMap.VIDEO.TempVideoPointer sta MemMap.VIDEO.TempVideoPointer+1
sta MemMap.VIDEO.TempVideoPointer lda MemMap.MATH.result+1
adc MemMap.VIDEO.TempVideoPointer
sta MemMap.VIDEO.TempVideoPointer
ldy MemMap.VIDEO.CursorCol ldy MemMap.VIDEO.CursorCol
cpy #COLUMN_NUM // Is this > col num? cpy #COLUMN_NUM // Is this > col num?
bcc noEndOfLine bcc noEndOfLine
jsr screenNewLine // Yes? Add new line first jsr screenNewLine // Yes? Add new line first
bitTest(%00000001, MemMap.VIDEO.StatusBitsA) lda MemMap.VIDEO.StatusBitsA
bne noScrollTriggered and #%00000001
beq noScrollTriggered
// Compensate Scroll // Compensate Scroll
sec sec
lda MemMap.VIDEO.TempVideoPointer lda MemMap.VIDEO.TempVideoPointer
sbc #40 sbc #40
sta MemMap.VIDEO.TempVideoPointer sta MemMap.VIDEO.TempVideoPointer
bcs !+ bcs noScrollTriggered
dec MemMap.VIDEO.TempVideoPointer+1 dec MemMap.VIDEO.TempVideoPointer+1
!:
noScrollTriggered: noScrollTriggered:
noEndOfLine: noEndOfLine:
pla pla
// This is a backspace cmp #BS
cmp #BS bne notBackspace
bne !+ lda #' '
lda #' ' sta (MemMap.VIDEO.TempVideoPointer), y
sta (MemMap.VIDEO.TempVideoPointer), y jmp exit
ply
jmp exit
!:
// insert into screen
sta (MemMap.VIDEO.TempVideoPointer), y
ply
iny
inc MemMap.VIDEO.CursorCol
exit: notBackspace:
plx sta (MemMap.VIDEO.TempVideoPointer), y
cli iny
rts inc MemMap.VIDEO.CursorCol
exit:
plx
cli
rts
} }
// -------------------------------------------------------- // --------------------------------------------------------

View File

@ -1,39 +1,45 @@
#importonce #importonce
.filenamespace Vic .filenamespace Vic
// VIC registers and constants
// For more information, refer to:
// https://www.c64-wiki.com/wiki/VIC // https://www.c64-wiki.com/wiki/VIC
// https://www.c64-wiki.com/wiki/Page_208-211 // https://www.c64-wiki.com/wiki/Page_208-211
// ======================================================== // Base address for VIC registers
// ////// CONSTANTS /////////////////////////////////////// .label VICREG = $D000
// ========================================================
.label VICREG = $D000 // Control register 2
.label CR2 = $D016
.label CR2 = $D016 // Control register 2 // Interrupt enabled register
.label INTE = $D01A // Interrupt enabled .label INTE = $D01A
.label RCNT = $D012 // Raster counter
// Raster counter register
.label RCNT = $D012
* = * "VIC Functions" * = * "VIC Functions"
// Initialize the VIC registers with values from the tvic array
init: { init: {
ldx #47 ldx #47 // Set index to 47 (the number of bytes in tvic)
px4: load_loop: // Start of loop to load tvic values into VIC registers
lda tvic-1, x lda tvic-1, x // Load the byte from tvic at position x into the accumulator
sta VICREG-1, x sta VICREG-1, x // Store the byte in the accumulator into the VIC register at position x
dex dex // Decrement the index
bne px4 bne load_loop // If the index is not zero, repeat the loop
rts rts // Return from subroutine
} }
* = * "VIC Init Data" * = * "VIC Init Data"
// Initial values for the VIC registers
tvic: tvic:
// The following bytes are loaded into the VIC registers in the init subroutine
.byte $00, $00, $00, $00, $00, $00, $00, $00 .byte $00, $00, $00, $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00, $00, $00, $00 .byte $00, $00, $00, $00, $00, $00, $00, $00
.byte $00, $9B, $37, $00, $00, $00, $08, $00 .byte $00, $9B, $37, $00, $00, $00, $08, $00
.byte $14, $0F, $00, $00 ,$00, $00, $00, $00 .byte $14, $0F, $00, $00 ,$00, $00, $00, $00
.byte $0E, $06, $01, $02, $03, $04, $00, $01 .byte $0E, $06, $01, $02, $03, $04, $00, $01
.byte $02, $03, $04, $05, $06, $07, $4C .byte $02, $03, $04, $05, $06, $07, $4C

View File

@ -123,30 +123,31 @@ toDebug: {
// copy // copy
// -------------------------------------------------------- // --------------------------------------------------------
clone: { clone: {
phr phr
sei sei
ldy #0 ldy #0
ldx MemMap.MEMORY.size ldx MemMap.MEMORY.size
beq md2 beq checkHighByte
md1: lda (MemMap.MEMORY.from),y // move a page at a time md1:
sta (MemMap.MEMORY.dest),y lda (MemMap.MEMORY.from),y // move a page at a time
iny sta (MemMap.MEMORY.dest),y
bne md1 iny
inc MemMap.MEMORY.from+1 bne md1
inc MemMap.MEMORY.dest+1 inc MemMap.MEMORY.from+1
dex inc MemMap.MEMORY.dest+1
bne md1 dex
md2: ldx MemMap.MEMORY.size+1 bne md1
beq md4 checkHighByte:
md3: lda (MemMap.MEMORY.from),y // move the remaining bytes ldx MemMap.MEMORY.size+1
sta (MemMap.MEMORY.dest),y md3:
iny lda (MemMap.MEMORY.from),y // move the remaining bytes
dex sta (MemMap.MEMORY.dest),y
bne md3 iny
cli dex
md4: bne md3
plr cli
rts plr
rts
} }
// -------------------------------------------------------- // --------------------------------------------------------
@ -161,29 +162,22 @@ clone: {
// A = The byte to fill memory with // A = The byte to fill memory with
// -------------------------------------------------------- // --------------------------------------------------------
fill: { fill: {
phr phr
sei sei
ldy #0 ldy #0
ldx MemMap.MEMORY.size ldx MemMap.MEMORY.size
beq md2 cpx MemMap.MEMORY.size+1
md1: stx MemMap.MEMORY.size+1
sta (MemMap.MEMORY.dest),y fillLoop:
iny sta (MemMap.MEMORY.dest),y
bne md1 iny
inc MemMap.MEMORY.dest+1 bne fillLoop
dex inc MemMap.MEMORY.dest+1
bne md1 dex
md2: ldx MemMap.MEMORY.size+1 bne fillLoop
beq md4 cli
md3: plr
sta (MemMap.MEMORY.dest),y rts
iny
dex
bne md3
cli
md4:
plr
rts
} }
// Clear Memory with 0 // Clear Memory with 0

View File

@ -87,6 +87,10 @@ printLine: {
rts rts
} }
// Hexadecimal lookup table
hexTable: .text "0123456789ABCDEF"
// -------------------------------------------------------- // --------------------------------------------------------
// byteToHex - // byteToHex -
// Convert a byte to an HEX value // Convert a byte to an HEX value
@ -98,23 +102,22 @@ printLine: {
// A = msn ascii char result // A = msn ascii char result
// X = lns ascii char result // X = lns ascii char result
// -------------------------------------------------------- // --------------------------------------------------------
byteToHex: { byteToHex: {
pha tay // Save the original byte in Y
jsr !+ and #$0F // Mask the lower 4 bits (nibble)
tax tax // Transfer the lower nibble to X register
pla lda hexTable, x // Load the ASCII value of the least significant hex digit
lsr tya // Restore the original byte from Y
lsr lsr // Shift the upper 4 bits (nibble) to the right
lsr lsr
lsr lsr
lsr
!: and #$0f tax // Transfer the upper nibble to X register
cmp #$0a pha // Push the ASCII value of the least significant hex digit to stack
bcc !+ lda hexTable, x // Load the ASCII value of the most significant hex digit
adc #6 tax // Transfer the ASCII value of the most significant hex digit to X
pla // Pop the ASCII value of the least significant hex digit from stack to A
!: adc #'0' rts // Return from the function // Return from the function
rts
} }
// -------------------------------------------------------- // --------------------------------------------------------

View File

@ -45,26 +45,33 @@ toDebug: {
// MemMap.MATH.result = 16 bit result // MemMap.MATH.result = 16 bit result
// -------------------------------------------------------- // --------------------------------------------------------
delayOne: { delayOne: {
pha pha
lda #$00 lda #$00
sta MemMap.TIMERS.counter sta MemMap.TIMERS.counter
loop1: lda #$fb // wait for vertical retrace
loop2: cmp $d012 // until it reaches 251th raster line ($fb)
bne loop2 // which is out of the inner screen area
inc MemMap.TIMERS.counter // increase frame counter
lda MemMap.TIMERS.counter // check if counter
cmp #$32 // reached 50
bne out // if not, pass the color changing routine
jmp exit
out: loop1:
lda $d012 // make sure we reached lda #$fb // wait for vertical retrace
loop3: cmp $d012 // the next raster line so next time we
beq loop3 loop2:
jmp loop1 // jump to main loop cmp $d012 // until it reaches 251th raster line ($fb)
exit: beq waitForNextLine
pla jmp loop2 // loop back if not yet at the 251th raster line
rts
waitForNextLine:
lda $d012 // make sure we reached
loop3:
cmp $d012 // the next raster line so next time we
beq loop1 // jump back to the main loop if still on the same raster line
inc MemMap.TIMERS.counter // increase frame counter
lda MemMap.TIMERS.counter // check if counter
cmp #$32 // reached 50
bne loop1 // if not, jump back to the main loop
exit:
pla
rts
} }

View File

@ -1,6 +1,6 @@
.cpu _6502 .cpu _6502
BasicUpstart2(Boot.warmStart) //BasicUpstart2(Boot.warmStart)
#import "./hardware/mem_map.asm" #import "./hardware/mem_map.asm"
* = $8000 "Main" * = $8000 "Main"

View File

@ -1,22 +1,28 @@
BUILD_PATH = ./bin BUILD_PATH = ./bin
KICKASS_BIN = /opt/develop/stid/c64/KickAssembler/KickAss.jar KICKASS_BIN = /Applications/KickAssembler/KickAss.jar
PRG_FILE = ${BUILD_PATH}/main.prg
CRT_FILE = ${BUILD_PATH}/woz.crt
.PHONY: all build eprom clean run
all: build all: build
build: build: ${PRG_FILE} ${CRT_FILE}
java -jar ${KICKASS_BIN} -odir ${BUILD_PATH} -log ${BUILD_PATH}/buildlog.txt -showmem ./main.asm
cartconv -t normal -name "woz" -i ${BUILD_PATH}/main.prg -o ${BUILD_PATH}/woz.crt
eprom: eprom: ${PRG_FILE} ${CRT_FILE}
java -jar ${KICKASS_BIN} -odir ${BUILD_PATH} -log ${BUILD_PATH}/buildlog.txt -showmem ./main.asm cartconv -i ${CRT_FILE} -o ${BUILD_PATH}/woz.bin
cartconv -t normal -name "woz" -i ${BUILD_PATH}/main.prg -o ${BUILD_PATH}/woz.crt
cartconv -i ${BUILD_PATH}/woz.crt -o ${BUILD_PATH}/woz.bin
clean: clean:
rm -Rf ./bin rm -Rf $(BUILD_PATH)
run: run: build
x64sc $(CRT_FILE)
${BUILD_PATH}:
mkdir -p $(BUILD_PATH)
${PRG_FILE}: ${BUILD_PATH}
java -jar ${KICKASS_BIN} -odir ${BUILD_PATH} -log ${BUILD_PATH}/buildlog.txt -showmem ./main.asm java -jar ${KICKASS_BIN} -odir ${BUILD_PATH} -log ${BUILD_PATH}/buildlog.txt -showmem ./main.asm
cartconv -t normal -name "woz" -i ${BUILD_PATH}/main.prg -o ${BUILD_PATH}/woz.crt
x64sc ${BUILD_PATH}/woz.crt
${CRT_FILE}: ${PRG_FILE}
cartconv -t normal -n "woz" -i $(PRG_FILE) -o $(CRT_FILE)