Skip to content

Commit

Permalink
A (non-flashing) cursor now works.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgiven committed Oct 27, 2024
1 parent 0d1d577 commit 151f13e
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 10 deletions.
93 changes: 84 additions & 9 deletions src/arch/snes/main.asm
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ MOD_SHIFT = %10000000 ; n bit
MOD_CTRL = %01000000 ; v bit
MOD_CAPS = %00000100

CURSOR_SHOWN = %10000000 ; n bit

.virtual $7f0000
cursor_addr: .word 0
sector: .long 0 ; 24 bits!
pending_key: .byte 0
modifier_state: .byte 0
cursorp: .word 0 ; character count from top left of screen
scrollp: .word 0 ; current scroll position
cursor_flags: .byte 0

vram_mirror_start:
map1_mirror: .fill 2*32*SCREEN_HEIGHT
Expand Down Expand Up @@ -166,6 +167,9 @@ start:

jml LOADER_ADDRESS ; ...and go

break:
rts

init_screen
.block
php
Expand Down Expand Up @@ -236,11 +240,11 @@ clear_screen:

a16
lda #0
sta cursor_addr
sta cursorp
sta scrollp
a8
sta cursor_flags

lda #0
a16
sta map1_mirror
lda #SCREEN_WIDTH*SCREEN_HEIGHT*2 - 3
ldx #<>map1_mirror
Expand All @@ -259,22 +263,39 @@ clear_screen:

load_palette_data:
php
a8
a8i8

stz CGADD
lda #2
sta CGADD

stz CGDATA
stz CGDATA
lda #$ff
sta CGDATA
sta CGDATA

ldx #4+2
stx CGADD

sta CGDATA
sta CGDATA
stz CGDATA
stz CGDATA

ldx #16+2
stx CGADD

sta CGDATA
sta CGDATA
stz CGDATA
stz CGDATA

plp
rts

load_font_data:
php
a16
a16i16

lda #%10000000 ; autoincrement by one word
sta VMAIN
Expand Down Expand Up @@ -559,6 +580,48 @@ calculate_screen_address:
rts
.endblock

show_cursor:
php
i16
a8
lda cursor_flags
bmi + ; if cursor is already shown
a16
jsr calculate_screen_address
tax
lda map1_mirror, x
and #$00ff
ora #$2400
sta map1_mirror, x

a8
lda #CURSOR_SHOWN
tsb cursor_flags
+
plp
rts

hide_cursor:
php
i16
a8
lda cursor_flags
bpl + ; if cursor is already hidden
a16
jsr calculate_screen_address
tax
lda map1_mirror, x
and #$00ff
ora #$2000
sta map1_mirror, x

a8
lda #CURSOR_SHOWN
trb cursor_flags
+
plp
rts

screen_putchar:
php
a16i16
Expand Down Expand Up @@ -737,6 +800,11 @@ tty_conout:
php
i8
a16

pha
jsr hide_cursor
pla

tax
cpx #13
bne +
Expand All @@ -747,7 +815,13 @@ tty_conout:
cpx #127
bne +
dec cursorp
; TODO: blank erased character

a16i16
jsr calculate_screen_address
tax
stz map1_mirror, x
i8

bra exit
+
cpx #10
Expand All @@ -774,6 +848,7 @@ maybescroll:
sta cursorp

exit:
jsr show_cursor
plp
clc
rts
Expand Down
3 changes: 2 additions & 1 deletion src/arch/snes/tools/mkfont.cc
Original file line number Diff line number Diff line change
Expand Up @@ -886,8 +886,9 @@ static void write_data(const std::string& filename, int planes)
for (int i = 0; i < 8; i++)
{
uint8_t r = cdata[i];
/* Write either colour 2 or 3. */
fd.put((char)r);
fd.put(0);
fd.put(0xff);
}
for (int j = 2; j < planes; j += 2)
{
Expand Down

0 comments on commit 151f13e

Please sign in to comment.