From 59e15a5c421e1d5e01474893420501017208c2b8 Mon Sep 17 00:00:00 2001 From: Kyle J Cardoza Date: Mon, 15 Jul 2024 19:26:07 -0400 Subject: [PATCH] VERA driver rewrite --- .vscode/settings.json | 8 +- config/config.mk | 4 +- config/kernel.scm | 8 +- include/kernel/hardware/vera.h | 954 +++++++++++++++++++++++++++++++- src/kernel/cstartup.s | 29 +- src/kernel/hardware/vera/vera.c | 103 +--- src/kernel/main.c | 2 +- 7 files changed, 1003 insertions(+), 105 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 2b616a7..109421b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,10 @@ { "C_Cpp.errorSquiggles": "disabled", - "C_Cpp.dimInactiveRegions": false + "C_Cpp.dimInactiveRegions": false, + "files.associations": { + "*.h": "c", + "*.s": "assembly", + "type_traits": "c", + "compare": "c" + } } \ No newline at end of file diff --git a/config/config.mk b/config/config.mk index 645b7aa..9999b1f 100755 --- a/config/config.mk +++ b/config/config.mk @@ -37,7 +37,9 @@ CFLAGS += --debug \ -Wno-gnu-conditional-omitted-operand \ -Wno-gnu-case-range \ -Wimplicit-fallthrough \ - -Wno-gnu-folding-constant + -Wno-gnu-folding-constant \ + -Wno-unused-parameter \ + -Wno-unused-variable ASFLAGS += --debug endif diff --git a/config/kernel.scm b/config/kernel.scm index 454f8c1..0d10c7e 100755 --- a/config/kernel.scm +++ b/config/kernel.scm @@ -1,7 +1,7 @@ (define memories '( (memory RAM - (address (#x000200 . #x001FFF)) + (address (#x001000 . #x002FFF)) (type RAM) (section zhuge) (section znear) @@ -31,8 +31,8 @@ ) (memory Stack - (address (#x000100 . #x0001FF)) - (section (stack #x00100)) + (address (#x000200 . #x000FFF)) + (section (stack #x00200)) ) (memory DirectPage @@ -43,7 +43,7 @@ ) ) - (block stack (size #x100)) ; machine stack size + (block stack (size #xE00)) ; machine stack size (base-address _DirectPageStart DirectPage 0) diff --git a/include/kernel/hardware/vera.h b/include/kernel/hardware/vera.h index c18353a..31b4c55 100755 --- a/include/kernel/hardware/vera.h +++ b/include/kernel/hardware/vera.h @@ -132,14 +132,958 @@ // The assembler can't handle this stuff. #ifdef __CALYPSI_CC__ +static inline uint8_t vera_addr_l_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda 0x00DF00 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_addr_l_write(uint8_t value) { + __asm(" sep #0x20 \n" + " sta 0x00DF00 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_addr_m_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda 0x00DF01 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_addr_m_write(uint8_t value) { + __asm(" sep #0x20 \n" + " sta 0x00DF01 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_addr_h_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda 0x00DF02 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_addr_h_write(uint8_t value) { + __asm(" sep #0x20 \n" + " sta 0x00DF02 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_data_0_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda 0x00DF03 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_data_0_write(uint8_t value) { + __asm(" sep #0x20 \n" + " sta 0x00DF03 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_data_1_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda 0x00DF04 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_data_1_write(uint8_t value) { + __asm(" sep #0x20 \n" + " sta 0x00DF04 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_ctrl_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda 0x00DF05 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_ctrl_write(uint8_t value) { + __asm(" sep #0x20 \n" + " sta 0x00DF05 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_ien_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda 0x00DF06 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_ien_write(uint8_t value) { + __asm(" sep #0x20 \n" + " sta 0x00DF06 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_isr_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda 0x00DF07 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_isr_write(uint8_t value) { + __asm(" sep #0x20 \n" + " sta 0x00DF07 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_scanline_l_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda 0x00DF08 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_irq_line_l_write(uint8_t value) { + __asm(" sep #0x20 \n" + " sta 0x00DF08 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_dc_video_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda #0b00000010 \n" + " trb 0x00DF05 \n" + " lda 0x00DF09 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_dc_video_write(uint8_t value) { + __asm(" sep #0x20 \n" + " pha \n" + " lda #0b00000010 \n" + " trb 0x00DF05 \n" + " pla \n" + " sta 0x00DF09 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_dc_hscale_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda #0b00000010 \n" + " trb 0x00DF05 \n" + " lda 0x00DF0A \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_dc_hscale_write(uint8_t value) { + __asm(" sep #0x20 \n" + " pha \n" + " lda #0b00000010 \n" + " trb 0x00DF05 \n" + " pla \n" + " sta 0x00DF0A \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_dc_vscale_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda #0b00000010 \n" + " trb 0x00DF05 \n" + " lda 0x00DF0B \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_dc_vscale_write(uint8_t value) { + __asm(" sep #0x20 \n" + " pha \n" + " lda #0b00000010 \n" + " trb 0x00DF05 \n" + " pla \n" + " sta 0x00DF0B \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_dc_border_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda #0b00000010 \n" + " trb 0x00DF05 \n" + " lda 0x00DF0C \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_dc_border_write(uint8_t value) { + __asm(" sep #0x20 \n" + " pha \n" + " lda #0b00000010 \n" + " trb 0x00DF05 \n" + " pla \n" + " sta 0x00DF0C \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_dc_hstart_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda #0b00000010 \n" + " tsb 0x00DF05 \n" + " lda 0x00DF09 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_dc_hstart_write(uint8_t value) { + __asm(" sep #0x20 \n" + " pha \n" + " lda #0b00000010 \n" + " tsb 0x00DF05 \n" + " pla \n" + " sta 0x00DF09 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_dc_hstop_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda #0b00000010 \n" + " tsb 0x00DF05 \n" + " lda 0x00DF0A \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_dc_hstop_write(uint8_t value) { + __asm(" sep #0x20 \n" + " pha \n" + " lda #0b00000010 \n" + " tsb 0x00DF05 \n" + " pla \n" + " sta 0x00DF0A \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_dc_vstart_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda #0b00000010 \n" + " tsb 0x00DF05 \n" + " lda 0x00DF0B \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_dc_vstart_write(uint8_t value) { + __asm(" sep #0x20 \n" + " pha \n" + " lda #0b00000010 \n" + " tsb 0x00DF05 \n" + " pla \n" + " sta 0x00DF0B \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_dc_vstop_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda #0b00000010 \n" + " tsb 0x00DF05 \n" + " lda 0x00DF0C \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_dc_vstop_write(uint8_t value) { + __asm(" sep #0x20 \n" + " pha \n" + " lda #0b00000010 \n" + " tsb 0x00DF05 \n" + " pla \n" + " sta 0x00DF0C \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_l0_config_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda 0x00DF0D \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_l0_config_write(uint8_t value) { + __asm(" sep #0x20 \n" + " sta 0x00DF0D \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_l0_mapbase_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda 0x00DF0E \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_l0_mapbase_write(uint8_t value) { + __asm(" sep #0x20 \n" + " sta 0x00DF0E \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_l0_tilebase_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda 0x00DF0F \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_l0_tilebase_write(uint8_t value) { + __asm(" sep #0x20 \n" + " sta 0x00DF0F \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_l0_hscroll_l_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda 0x00DF10 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_l0_hscroll_l_write(uint8_t value) { + __asm(" sep #0x20 \n" + " sta 0x00DF10 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_l0_hscroll_h_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda 0x00DF11 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_l0_hscroll_h_write(uint8_t value) { + __asm(" sep #0x20 \n" + " sta 0x00DF11 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_l0_vscroll_l_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda 0x00DF12 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_l0_vscroll_l_write(uint8_t value) { + __asm(" sep #0x20 \n" + " sta 0x00DF12 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_l0_vscroll_h_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda 0x00DF13 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_l0_vscroll_h_write(uint8_t value) { + __asm(" sep #0x20 \n" + " sta 0x00DF13 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_l1_config_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda 0x00DF14 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_l1_config_write(uint8_t value) { + __asm(" sep #0x20 \n" + " sta 0x00DF14 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_l1_mapbase_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda 0x00DF15 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_l1_mapbase_write(uint8_t value) { + __asm(" sep #0x20 \n" + " sta 0x00DF15 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_l1_tilebase_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda 0x00DF16 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_l1_tilebase_write(uint8_t value) { + __asm(" sep #0x20 \n" + " sta 0x00DF16 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_l1_hscroll_l_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda 0x00DF17 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_l1_hscroll_l_write(uint8_t value) { + __asm(" sep #0x20 \n" + " sta 0x00DF17 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_l1_hscroll_h_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda 0x00DF18 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_l1_hscroll_h_write(uint8_t value) { + __asm(" sep #0x20 \n" + " sta 0x00DF18 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_l1_vscroll_l_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda 0x00DF19 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_l1_vscroll_l_write(uint8_t value) { + __asm(" sep #0x20 \n" + " sta 0x00DF19 \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_l1_vscroll_h_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda 0x00DF1A \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_l1_vscroll_h_write(uint8_t value) { + __asm(" sep #0x20 \n" + " sta 0x00DF1A \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_audio_ctrl_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda 0x00DF1B \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_audio_ctrl_write(uint8_t value) { + __asm(" sep #0x20 \n" + " sta 0x00DF1B \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_audio_rate_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda 0x00DF1C \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_audio_rate_write(uint8_t value) { + __asm(" sep #0x20 \n" + " sta 0x00DF1C \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_audio_data_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda 0x00DF1D \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_audio_data_write(uint8_t value) { + __asm(" sep #0x20 \n" + " sta 0x00DF1D \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_spi_data_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda 0x00DF1E \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_l1_spi_data_write(uint8_t value) { + __asm(" sep #0x20 \n" + " sta 0x00DF1E \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + +static inline uint8_t vera_spi_ctrl_read(void) { + uint8_t result; + + __asm(" sep #0x20 \n" + " lda 0x00DF1F \n" + " rep #0x20 \n" + " and 0x00FF \n" + : "=Ka"(result) + : + : "c" + ); + return result; +} + +static inline void vera_l1_spi_ctrl_write(uint8_t value) { + __asm(" sep #0x20 \n" + " sta 0x00DF1F \n" + " rep #0x20 \n" + " and 0x00FF \n" + : + : "Ka"(value) + : "c" + ); +} + void vera_init(void); void vera_reset(void); -uint8_t vera_reg_read(uint32_t regnum); - -void vera_reg_write(uint32_t regnum, uint8_t value); - void vera_address_select(uint8_t value); void vera_address_set(uint32_t address); @@ -148,6 +1092,6 @@ void vera_mem_write(uint32_t dest, void *src, size_t length); void vera_mem_set(uint32_t dest, uint8_t value, size_t length); -void vera_mem_clear(uint32_t dest, size_t length); +void vera_mem_clear(uint32_t dest, size_t length); #endif diff --git a/src/kernel/cstartup.s b/src/kernel/cstartup.s index a49d57e..d410496 100755 --- a/src/kernel/cstartup.s +++ b/src/kernel/cstartup.s @@ -25,14 +25,19 @@ #include "kernel/hardware/w65c265s.h" .section boot, noreorder - .pubweak __program_root_section + .public __program_root_section __program_root_section: .asciz "WDC" + w65c265s_init: ; Begin tracing for the emulator. NOP for the real hardware. wdm #0x80 + ; native 16-bit mode + clc + xce + ; Disable interrupts sei stz UIER @@ -41,17 +46,16 @@ w65c265s_init: short_a long_i - ; We reset the VERA at boot. So P4.2 is an output, held - ; low until later in the boot sequence. + ; We reset the VERA at boot. So P4.2 is an output held high. lda #1 << 2 trb PD4 tsb PDD4 ; Now we delay a while. ldy ##0x0FFF -delay_y +delay_y1 dey - bne delay_y + bne delay_y1 fclk_start @@ -64,16 +68,19 @@ delay_y ; Disable the on-CPU ROM w65c265s_rom_off - ; Disable the on-CPU RAM - w65c265s_sram_off + jmp long:c_runtime_startup - clc - xce ; native 16-bit mode + .section code + .public c_runtime_startup +c_runtime_startup: rep #0x38 ; 16-bit registers, no decimal mode + ldx ##.sectionEnd stack txs ; set stack + lda ##_DirectPageStart tcd ; set direct page + lda ##.word2 _NearBaseAddress stz dp:.tiny(_Vfp+2) xba ; A upper half = data bank @@ -82,7 +89,6 @@ delay_y plb ; set data bank ;;; **** Initialize data sections if needed. - .section boot, noroot, noreorder .pubweak __data_initialization_needed .extern __initialize_sections @@ -98,7 +104,6 @@ __data_initialization_needed: jsl long:__initialize_sections ;;; **** Initialize streams if needed. - .section boot, noroot, noreorder .pubweak __call_initialize_global_streams .extern __initialize_global_streams @@ -106,7 +111,6 @@ __call_initialize_global_streams: jsl long:__initialize_global_streams ;;; **** Initialize heap if needed. - .section boot, noroot, noreorder .pubweak __call_heap_initialize .extern __heap_initialize, __default_heap @@ -123,7 +127,6 @@ __call_heap_initialize: lda ##.word0 (.sectionSize heap) jsl long:__heap_initialize - .section boot, root, noreorder lda ##0 ; argc = 0 jsl long:main stp diff --git a/src/kernel/hardware/vera/vera.c b/src/kernel/hardware/vera/vera.c index 5d149c5..30eccca 100644 --- a/src/kernel/hardware/vera/vera.c +++ b/src/kernel/hardware/vera/vera.c @@ -10,50 +10,36 @@ #include "kernel/hardware/vera.h" #include "kernel/util/delay.h" -static uint8_t *vera_ctrl = (uint8_t *)(VERA_CTRL); - -static uint8_t *vera_addr_l = (uint8_t *)(VERA_ADDRx_L); -static uint8_t *vera_addr_m = (uint8_t *)(VERA_ADDRx_M); -static uint8_t *vera_addr_h = (uint8_t *)(VERA_ADDRx_H); - -static uint8_t *vera_data_0 = (uint8_t *)(VERA_DATA_0); - extern uint16_t *vera_palette; -extern uint8_t vera_font_0[]; +extern uint8_t vera_font_0; void vera_address_select(uint8_t value) { - if (value % 2 == 0) { - *vera_ctrl &= 0b11111110; + uint8_t ctrl = vera_ctrl_read(); + + if ((value & 0b00000001) == 0) { + ctrl &= 0b11111110; } else { - *vera_ctrl |= 0b00000001; + ctrl |= 0b00000001; } + + vera_ctrl_write(ctrl); } void vera_address_set(uint32_t address) { - *vera_addr_l = (uint8_t)(address & 0x0000FF); - *vera_addr_m = (uint8_t)((address & 0x00FF00) >> 8); - *vera_addr_h = (uint8_t)(address >> 16); -} - -uint8_t vera_reg_read(uint32_t regnum) { - uint8_t *reg = (uint8_t *)((uint32_t)(regnum)); - return *reg; -} - -void vera_reg_write(uint32_t regnum, uint8_t value) { - uint8_t *reg = (uint8_t *)((uint32_t)(regnum)); - *reg = value; + vera_addr_l_write(address & 0x0000FF); + vera_addr_m_write((address & 0x00FF00) >> 8); + vera_addr_h_write((address & 0xFF0000) >> 16); } void vera_mem_read(void *dest, uint32_t src, size_t length) { + uint8_t *destination = dest; + vera_address_select(0); vera_address_set(src | AUTO_INC_1); - uint8_t *destination = dest; - - for (size_t i = 0; i < length; i += 1, destination += 1) { - *destination = *vera_data_0; + for (size_t count = 0; count < length; count += 1) { + *destination = vera_data_0_read(); } } @@ -61,10 +47,8 @@ void vera_mem_write(uint32_t dest, void *src, size_t length) { vera_address_select(0); vera_address_set(dest | AUTO_INC_1); - uint8_t *source = src; - - for (size_t i = 0; i < length; i += 1, source += 1) { - *vera_data_0 = *source; + for (size_t count = 0; count < length; count += 1) { + vera_data_0_write(*((uint8_t *)(src))); } } @@ -72,8 +56,8 @@ void vera_mem_set(uint32_t dest, uint8_t value, size_t length) { vera_address_select(0); vera_address_set(dest | AUTO_INC_1); - for (size_t i = 0; i < length; i += 1) { - *vera_data_0 = value; + for (size_t count = 0; count < length; count += 1) { + vera_data_0_write(value); } } @@ -81,57 +65,16 @@ void vera_mem_clear(uint32_t dest, size_t length) { vera_address_select(0); vera_address_set(dest | AUTO_INC_1); - for (size_t i = 0; i < length; i += 1) { - *vera_data_0 = 0x00; + for (size_t count = 0; count < length; count += 1) { + vera_data_0_write(0x00); } } -// Pull the VERA reset line (P4.2) low, hold it for a bit, then let it -// go high. void vera_reset(void) { - __asm("\n" - " sep #0x20\n" - " lda #1 << 2\n" - " trb 0x00DF20\n" - " rep #0x20\n" - ); - - delay(1); - - __asm("\n" - " sep #0x20\n" - " lda #1 << 2\n" - " tsb 0x00DF20\n" - " rep #0x20\n" - ); - - delay(1); + uint8_t ctrl = vera_ctrl_read(); + vera_ctrl_write(ctrl | (1 << 7)); } void vera_init(void) { vera_reset(); - - vera_mem_write(VERA_PALETTE_BASE, vera_palette, 0x200); - - vera_mem_write(TEXT_CONSOLE_TILES, vera_font_0, 0x1000); - - vera_reg_write(VERA_DC_HSCALE, 0x80); - vera_reg_write(VERA_DC_VSCALE, 0x80); - vera_reg_write(VERA_L0_CONFIG, VERA_L_BPP1 | VERA_L_64H | VERA_L_128W); - vera_reg_write(VERA_L0_MAPBASE, TEXT_CONSOLE0_VRAM >> 9); - vera_reg_write(VERA_L0_TILEBASE, ((TEXT_CONSOLE_TILES >> 9) & 0b11111100) | VERA_TILESIZE8x16); - vera_reg_write(VERA_L0_HSCROLL_H, 0); - vera_reg_write(VERA_L0_HSCROLL_L, 0); - vera_reg_write(VERA_L0_VSCROLL_H, 0); - vera_reg_write(VERA_L0_HSCROLL_L, 0); - - uint8_t ien_value = vera_reg_read(VERA_IEN) | 0b00000001; - vera_reg_write(VERA_IEN, ien_value); - - uint8_t isr_value = vera_reg_read(VERA_ISR) | 0b00000001; - vera_reg_write(VERA_ISR, isr_value); - - uint8_t dc_vid_value = vera_reg_read(VERA_DC_VIDEO) | 0b00010001; - vera_reg_write(VERA_DC_VIDEO, dc_vid_value); } - diff --git a/src/kernel/main.c b/src/kernel/main.c index aa2bbb1..e15b1d3 100755 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -16,7 +16,7 @@ void main(void) { led_init(); - vera_reset(); + vera_init(); for (;;) { led_red_on();