small 65C02 optimizations in many places

This commit is contained in:
FeralChild64 committed 2019-10-10 19:45:40 +02:00
1 parent 3e5c80bbf1
commit ce8c84a20c
22 files changed
+102 -158

No files matched your search

+2 -2
View File
@@ -51,7 +51,7 @@ Choose if your CPU supports the Western Design Center 65C02 instruction set, lik
* CSG 65CE02 * CSG 65CE02
* CSG 4510 - used in the Commodore 65 prototypes * CSG 4510 - used in the Commodore 65 prototypes
It enables some speed/size code optimizations. Warning - this is untested! It enables some speed/size code optimizations.
### `CONFIG_CPU_WDC_65816` ### `CONFIG_CPU_WDC_65816`
@@ -60,7 +60,7 @@ Choose if your CPU supports the 16-bit Western Design Center 65816 instruction s
* WDC 65C816 - used in the Flash 8 accelerator * WDC 65C816 - used in the Flash 8 accelerator
* WDC 65C816S - used in the SuperCPU accelerator * WDC 65C816S - used in the SuperCPU accelerator
It enables some speed/size code optimizations. Warning - this is untested! It enables some speed/size code optimizations.
## Memory model ## Memory model
+45
View File
@@ -0,0 +1,45 @@
//
// Provide pseudocommands to make CPU optimizations easier
//
.pseudocommand _phx
{
#if CONFIG_CPU_WDC_65C02 || CONFIG_CPU_WDC_65816
phx
#else
txa
pha
#endif
}
.pseudocommand _phy
{
#if CONFIG_CPU_WDC_65C02 || CONFIG_CPU_WDC_65816
phy
#else
tya
pha
#endif
}
.pseudocommand _plx
{
#if CONFIG_CPU_WDC_65C02 || CONFIG_CPU_WDC_65816
plx
#else
pla
tax
#endif
}
.pseudocommand _ply
{
#if CONFIG_CPU_WDC_65C02 || CONFIG_CPU_WDC_65816
ply
#else
pla
tay
#endif
}
+2 -3
View File
@@ -8,8 +8,7 @@ STROUT:
sty FRESPC+1 sty FRESPC+1
sta FRESPC+0 sta FRESPC+0
txa _phx
pha
// Get offset ready // Get offset ready
ldy #$00 ldy #$00
@@ -29,6 +28,6 @@ STROUT:
iny iny
bne !- bne !-
!: !:
pla pla // XXX can we use _plx here?
tax tax
rts rts
+2 -4
View File
@@ -2,8 +2,7 @@
basic_do_error: basic_do_error:
// Save error number // Save error number
txa _phx
pha
// Print ? at start // Print ? at start
jsr print_return jsr print_return
@@ -11,8 +10,7 @@ basic_do_error:
jsr JCHROUT jsr JCHROUT
// Print main part of error message // Print main part of error message
pla _plx
tax
jsr print_packed_message jsr print_packed_message
// Print ERROR at end // Print ERROR at end
+2 -14
View File
@@ -98,15 +98,9 @@ list_not_quote:
// Display a token // Display a token
// Save registers // Save registers
#if CONFIG_CPU_MOS_6502
tax tax
pha pha
tya _phy
pha
#else
phx
phy
#endif
// Get pointer to compressed keyword list // Get pointer to compressed keyword list
lda #<packed_keywords lda #<packed_keywords
@@ -124,13 +118,7 @@ list_not_quote:
ldy #$ff ldy #$ff
jsr packed_word_search jsr packed_word_search
#if CONFIG_CPU_MOS_6502 _ply
pla
tay
#else
ply
#endif
pla pla
cmp #$8f cmp #$8f
+1 -2
View File
@@ -5,8 +5,7 @@
print_integer: print_integer:
pha pha
txa _phx
pha
// Clear temporary output // Clear temporary output
lda #$00 lda #$00
+8 -16
View File
@@ -32,15 +32,13 @@ packed_message_search:
found_message_in_token_stream: found_message_in_token_stream:
// Now print each word in the message // Now print each word in the message
tya _phy
pha
lda packed_message_tokens,y lda packed_message_tokens,y
cmp #$ff cmp #$ff
beq !+ beq !+
jsr print_packed_word jsr print_packed_word
jsr print_space jsr print_space
pla _ply
tay
iny iny
bne found_message_in_token_stream bne found_message_in_token_stream
!: !:
@@ -139,16 +137,14 @@ next_packed_word_char:
tax tax
// Save Y so it doesn't get clobbered by CHROUT // Save Y so it doesn't get clobbered by CHROUT
tya _phy
pha
// X=1-14 = first 14 chars, so subtract one // X=1-14 = first 14 chars, so subtract one
lda packed_message_chars-1,x lda packed_message_chars-1,x
jsr JCHROUT jsr JCHROUT
// See if there is a char in the low nybl to print // See if there is a char in the low nybl to print
pla _ply
tay
lda (FRESPC),y lda (FRESPC),y
and #$0f and #$0f
beq end_of_packed_word beq end_of_packed_word
@@ -158,8 +154,7 @@ next_packed_word_char:
has_lo_nybl_char: has_lo_nybl_char:
// We need to print the low nybl char as well // We need to print the low nybl char as well
tax tax
tya _phy
pha
// Skip lower nybls of $F or $0 in nybl packed // Skip lower nybls of $F or $0 in nybl packed
// bytes, as these do not encode characters // bytes, as these do not encode characters
@@ -173,8 +168,7 @@ has_nybl:
lda packed_message_chars-1,x lda packed_message_chars-1,x
jsr JCHROUT jsr JCHROUT
!: !:
pla _ply
tay
// FALLTHROUGH // FALLTHROUGH
no_lo_nybl_char: no_lo_nybl_char:
@@ -204,8 +198,7 @@ next_is_literal_char:
unpack_literal_char: unpack_literal_char:
// Output the literal char, and ready for next char // Output the literal char, and ready for next char
iny iny
tya _phy
pha
lda (FRESPC),y lda (FRESPC),y
jsr JCHROUT jsr JCHROUT
pla pla
@@ -222,7 +215,6 @@ is_uncommon_char:
// We need to print the low nybl char as well // We need to print the low nybl char as well
tax tax
tya _phy
pha
jmp has_nybl jmp has_nybl
+1 -2
View File
@@ -232,8 +232,7 @@ wedge_dos_clean_exit:
wedge_dos_basic_error: wedge_dos_basic_error:
pha pha
jsr JCLALL jsr JCLALL
pla _plx
tax
dex dex
jmp do_basic_error jmp do_basic_error
+2 -2
View File
@@ -14,8 +14,7 @@
chkin_real: chkin_real:
// Store Y for preservation // Store Y for preservation
tya _phy
pha
// Reset status // Reset status
jsr kernalstatus_reset jsr kernalstatus_reset
@@ -59,6 +58,7 @@ chkin_set_device:
// FALLTROUGH // FALLTROUGH
// Common part for booth CHKIN and CKOUT // Common part for booth CHKIN and CKOUT
// XXX add CPU-dependent optimizations here
chkinout_end: chkinout_end:
tax tax
+5 -10
View File
@@ -44,8 +44,7 @@ chrin_done_fail:
chrin_keyboard: chrin_keyboard:
// Save X // Save X
txa _phx
pha
chrin_repeat: chrin_repeat:
@@ -65,8 +64,7 @@ chrin_repeat:
// Return carriage return and clear pending input flag // Return carriage return and clear pending input flag
lda #$00 lda #$00
sta CRSW sta CRSW
pla _plx
tax
clc clc
lda #$0d lda #$0d
rts rts
@@ -74,8 +72,7 @@ chrin_repeat:
not_end_of_input: not_end_of_input:
// Return next byte of waiting input and advance index // Return next byte of waiting input and advance index
tay tay
pla _plx
tax
lda (LXSP),y lda (LXSP),y
jsr screen_code_to_petscii jsr screen_code_to_petscii
inc CRSW inc CRSW
@@ -126,8 +123,7 @@ read_from_keyboard:
sta CRSW sta CRSW
// Return first char of line // Return first char of line
ldy #$00 ldy #$00
pla _plx
tax
lda (LXSP),y lda (LXSP),y
jsr screen_code_to_petscii jsr screen_code_to_petscii
clc clc
@@ -137,8 +133,7 @@ empty_line:
// For an empty line, just return the carriage return // For an empty line, just return the carriage return
// (and don't forget to actually print the carriage return, so that // (and don't forget to actually print the carriage return, so that
// the cursor advances and screen scrolls as required) // the cursor advances and screen scrolls as required)
pla _plx
tax
clc clc
lda #$0d lda #$0d
rts rts
+2 -4
View File
@@ -12,8 +12,7 @@
clall_real: clall_real:
// Store .Y register // Store .Y register
tya _phy
pha
// Original routine probably just sets LDTND to 0, but this is not really safe, // Original routine probably just sets LDTND to 0, but this is not really safe,
// so we actually close all the channels; at least IDE64 does the same for // so we actually close all the channels; at least IDE64 does the same for
@@ -27,8 +26,7 @@ clall_real:
jmp !- jmp !-
!: !:
// Restore .Y register // Restore .Y register
pla _ply
tay
// 'C64 Programmers Reference Guide', page 281, claims it calls CLRCHN too // 'C64 Programmers Reference Guide', page 281, claims it calls CLRCHN too
jsr CLRCHN jsr CLRCHN
+8 -39
View File
@@ -17,15 +17,8 @@ CHROUT:
// don't get modified, in agreement with C64 PRG's // don't get modified, in agreement with C64 PRG's
// description of CHROUT) // description of CHROUT)
#if CONFIG_CPU_MOS_6502 _phx
txa _phy
pha
tya
pha
#else
phx
phy
#endif
php php
@@ -52,16 +45,8 @@ chrout_done_fail:
plp plp
// Restore X and Y // Restore X and Y
_ply
#if CONFIG_CPU_MOS_6502 _plx
pla
tay
pla
tax
#else
ply
plx
#endif
sec // indicate failure sec // indicate failure
rts rts
@@ -71,16 +56,8 @@ chrout_done_unknown_device:
plp plp
// Restore X and Y // Restore X and Y
_ply
#if CONFIG_CPU_MOS_6502 _plx
pla
tay
pla
tax
#else
ply
plx
#endif
// End wioth error // End wioth error
jmp lvs_device_not_found_error jmp lvs_device_not_found_error
@@ -90,16 +67,8 @@ chrout_done_success:
plp plp
// Restore X and Y // Restore X and Y
_ply
#if CONFIG_CPU_MOS_6502 _plx
pla
tay
pla
tax
#else
ply
plx
#endif
lda SCHAR lda SCHAR
clc // indicate success clc // indicate success
+4 -8
View File
@@ -14,10 +14,8 @@ iec_return_success:
lda #$00 lda #$00
sta C3PO sta C3PO
// Restore registers // Restore registers
pla _ply
tay _plx
pla
tax
// Report success // Report success
clc clc
rts rts
@@ -30,9 +28,7 @@ iec_return_DEVICE_NOT_FOUND:
lda #$00 lda #$00
sta C3PO sta C3PO
// Restore registers // Restore registers
pla _ply
tay _plx
pla
tax
// Report error // Report error
jmp kernalerror_DEVICE_NOT_FOUND jmp kernalerror_DEVICE_NOT_FOUND
+2 -4
View File
@@ -7,10 +7,8 @@
iec_rx_byte: iec_rx_byte:
// Store .X and .Y on the stack - preserve them // Store .X and .Y on the stack - preserve them
txa _phx
pha _phy
tya
pha
// Timing is critical here - execute on disabled IRQs // Timing is critical here - execute on disabled IRQs
// The best practice would be to do PHP first, but it seems this is not // The best practice would be to do PHP first, but it seems this is not
+2 -4
View File
@@ -5,10 +5,8 @@
iec_turnaround_to_listen: iec_turnaround_to_listen:
// Store .X and .Y on the stack - preserve them // Store .X and .Y on the stack - preserve them
txa _phx
pha _phy
tya
pha
// Timing is critical here - execute on disabled IRQs // Timing is critical here - execute on disabled IRQs
php php
+2 -4
View File
@@ -5,10 +5,8 @@
iec_turnaround_to_talk: iec_turnaround_to_talk:
// Store .X and .Y on the stack - preserve them // Store .X and .Y on the stack - preserve them
txa _phx
pha _phy
tya
pha
// Timing is critical here - execute on disabled IRQs // Timing is critical here - execute on disabled IRQs
php php
+2 -4
View File
@@ -10,10 +10,8 @@
iec_tx_byte: iec_tx_byte:
// Store .X and .Y on the stack - preserve them // Store .X and .Y on the stack - preserve them
txa _phx
pha _phy
tya
pha
// Notify all devices that we are going to send a byte // Notify all devices that we are going to send a byte
// and it is going to be a data byte (released ATN) // and it is going to be a data byte (released ATN)
+2 -4
View File
@@ -10,10 +10,8 @@
iec_tx_command: iec_tx_command:
// Store .X and .Y on the stack - preserve them // Store .X and .Y on the stack - preserve them
txa _phx
pha _phy
tya
pha
// Notify all devices that we are going to send a byte // Notify all devices that we are going to send a byte
// and it is going to be a command (pulled ATN) // and it is going to be a command (pulled ATN)
+2 -4
View File
@@ -6,10 +6,8 @@
iec_tx_command_finalize: iec_tx_command_finalize:
// Store .X and .Y on the stack - preserve them // Store .X and .Y on the stack - preserve them
txa _phx
pha _phy
tya
pha
// Give device some time to complete command reception, release ATN, // Give device some time to complete command reception, release ATN,
// give it some time again before (possible) next command // give it some time again before (possible) next command
@@ -12,15 +12,7 @@ return_from_interrupt:
// Restore registers and return // Restore registers and return
// Sequence according to Compute's Mapping the 64 p73 // Sequence according to Compute's Mapping the 64 p73
#if CONFIG_CPU_MOS_6502 _ply
pla _plx
tay
pla
tax
#else
ply
plx
#endif
pla pla
rti rti
@@ -6,15 +6,8 @@ default_nmi_handler:
// Save registers, sequence according to Compute's Mapping the Commodore 64, page 73 // Save registers, sequence according to Compute's Mapping the Commodore 64, page 73
pha pha
#if CONFIG_CPU_MOS_6502 _phx
txa _phy
pha
tya
pha
#else
phx
phy
#endif
// XXX: RS-232 support is not implemented // XXX: RS-232 support is not implemented
+2 -9
View File
@@ -11,15 +11,8 @@ hw_entry_irq:
// Save registers, sequence according to Compute's Mapping the Commodore 64, page 73 // Save registers, sequence according to Compute's Mapping the Commodore 64, page 73
pha pha
#if CONFIG_CPU_MOS_6502 _phx
txa _phy
pha
tya
pha
#else
phx
phy
#endif
#if CONFIG_CPU_MOS_6502 && CONFIG_BCD_SAFE_INTERRUPTS #if CONFIG_CPU_MOS_6502 && CONFIG_BCD_SAFE_INTERRUPTS
cld // clear decimal flag to allow using it without disabling interrupts cld // clear decimal flag to allow using it without disabling interrupts