1
0
mirror of https://github.com/stid/woz64.git synced 2024-06-02 07:41:46 +00:00

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
} }
@ -189,37 +191,34 @@ sendChar: {
sei sei
phx phx
cmp #CR cmp #CR
bne !+ bne notCR
jsr screenNewLine jsr screenNewLine
iny iny
jmp exit jmp exit
!:
notCR:
cmp #BS cmp #BS
bne !+ bne notBS
ldx MemMap.VIDEO.CursorCol ldx MemMap.VIDEO.CursorCol
cmp #0
beq exit beq exit
dec MemMap.VIDEO.CursorCol dec MemMap.VIDEO.CursorCol
!: jmp storeBaseVideoAddress
notBS:
// Store Base Video Address 16 bit // Store Base Video Address 16 bit
storeBaseVideoAddress:
ldx #<VIDEO_ADDR // Low byte ldx #<VIDEO_ADDR // Low byte
stx MemMap.VIDEO.TempVideoPointer stx MemMap.VIDEO.TempVideoPointer
ldx #>VIDEO_ADDR // High byte ldx #>VIDEO_ADDR // High byte
stx MemMap.VIDEO.TempVideoPointer+1 stx MemMap.VIDEO.TempVideoPointer+1
// Temp Save Y
phy
// CursorRow * 40 // CursorRow * 40
ldy MemMap.VIDEO.CursorRow ldy MemMap.VIDEO.CursorRow
sty MemMap.MATH.factor1 sty MemMap.MATH.factor1
ldy #COLUMN_NUM
sty MemMap.MATH.factor2
jsr Math.multiply jsr Math.multiply
// Add mul result to TempVideoPointer // Add mul result to TempVideoPointer
pha pha
clc clc
lda MemMap.MATH.result lda MemMap.MATH.result
adc MemMap.VIDEO.TempVideoPointer+1 adc MemMap.VIDEO.TempVideoPointer+1
@ -233,36 +232,33 @@ sendChar: {
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 !+ bne notBackspace
lda #' ' lda #' '
sta (MemMap.VIDEO.TempVideoPointer), y sta (MemMap.VIDEO.TempVideoPointer), y
ply
jmp exit jmp exit
!:
// insert into screen notBackspace:
sta (MemMap.VIDEO.TempVideoPointer), y sta (MemMap.VIDEO.TempVideoPointer), y
ply
iny iny
inc MemMap.VIDEO.CursorCol inc MemMap.VIDEO.CursorCol
exit: exit:
plx plx
cli cli
rts 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
.label CR2 = $D016 // Control register 2 // Control register 2
.label INTE = $D01A // Interrupt enabled .label CR2 = $D016
.label RCNT = $D012 // Raster counter
// Interrupt enabled register
.label INTE = $D01A
// 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

@ -127,8 +127,9 @@ clone: {
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:
lda (MemMap.MEMORY.from),y // move a page at a time
sta (MemMap.MEMORY.dest),y sta (MemMap.MEMORY.dest),y
iny iny
bne md1 bne md1
@ -136,15 +137,15 @@ clone: {
inc MemMap.MEMORY.dest+1 inc MemMap.MEMORY.dest+1
dex dex
bne md1 bne md1
md2: ldx MemMap.MEMORY.size+1 checkHighByte:
beq md4 ldx MemMap.MEMORY.size+1
md3: lda (MemMap.MEMORY.from),y // move the remaining bytes md3:
lda (MemMap.MEMORY.from),y // move the remaining bytes
sta (MemMap.MEMORY.dest),y sta (MemMap.MEMORY.dest),y
iny iny
dex dex
bne md3 bne md3
cli cli
md4:
plr plr
rts rts
} }
@ -165,23 +166,16 @@ fill: {
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
fillLoop:
sta (MemMap.MEMORY.dest),y sta (MemMap.MEMORY.dest),y
iny iny
bne md1 bne fillLoop
inc MemMap.MEMORY.dest+1 inc MemMap.MEMORY.dest+1
dex dex
bne md1 bne fillLoop
md2: ldx MemMap.MEMORY.size+1
beq md4
md3:
sta (MemMap.MEMORY.dest),y
iny
dex
bne md3
cli cli
md4:
plr plr
rts rts
} }

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
@ -99,22 +103,21 @@ printLine: {
// 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
tya // Restore the original byte from Y
lsr // Shift the upper 4 bits (nibble) to the right
lsr lsr
lsr lsr
lsr lsr
lsr tax // Transfer the upper nibble to X register
pha // Push the ASCII value of the least significant hex digit to stack
!: and #$0f lda hexTable, x // Load the ASCII value of the most significant hex digit
cmp #$0a tax // Transfer the ASCII value of the most significant hex digit to X
bcc !+ pla // Pop the ASCII value of the least significant hex digit from stack to A
adc #6 rts // Return from the function // Return from the function
!: adc #'0'
rts
} }
// -------------------------------------------------------- // --------------------------------------------------------

View File

@ -48,21 +48,28 @@ 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) loop1:
bne loop2 // which is out of the inner screen area lda #$fb // wait for vertical retrace
loop2:
cmp $d012 // until it reaches 251th raster line ($fb)
beq waitForNextLine
jmp loop2 // loop back if not yet at the 251th raster line
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 inc MemMap.TIMERS.counter // increase frame counter
lda MemMap.TIMERS.counter // check if counter lda MemMap.TIMERS.counter // check if counter
cmp #$32 // reached 50 cmp #$32 // reached 50
bne out // if not, pass the color changing routine bne loop1 // if not, jump back to the main loop
jmp exit
out: exit:
lda $d012 // make sure we reached
loop3: cmp $d012 // the next raster line so next time we
beq loop3
jmp loop1 // jump to main loop
exit:
pla pla
rts 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)