sam: video and stub fixes
authorAlan Cox <alan@linux.intel.com>
Sun, 19 Aug 2018 20:12:14 +0000 (21:12 +0100)
committerAlan Cox <alan@linux.intel.com>
Sun, 19 Aug 2018 20:12:14 +0000 (21:12 +0100)
Rearrange our logic a bit so we can copy the stubs where we need them
Copy stubs into the top of the video 32K so we can in theory at some point
re-arrange the video logic and maps to keep interrupts on by using a private
low stack and high mapping video.
Fix the last character on a line being corrupted
Add initial (not used) colour support for the console

Kernel/platform-sam/boot.s
Kernel/platform-sam/sam.s
Kernel/platform-sam/sam_vt.s

index fefb1dc..872e395 100644 (file)
@@ -1,5 +1,8 @@
 ;
 ;      Boot block, loaded at 0x8000 in the top bank that is free (varies)
+;      but this works so long as we are above bank 7. If that becomes
+;      an issue then instead of flipping banks we can always ldir ourself
+;      into bank 0 and run from there.
 ;
 ;      The boot block is trivial but it gets a bit fun once we've loaded
 ;      our 14 tracks
@@ -15,7 +18,6 @@
 ;      We then run from 0x8000 in bank 6, which will untangle everything
 ;      for us shuffling the kernel so that 0/1 is the low kernel in RAM
 ;      2/3 is the high kernel in RAM and 4/5 is the video
-;      (or maybe it'll be saner to use 4/5 for kernel 2/3 video..)
 ;
        .area BOOT(ABS)
        .org 0x0000
index dcc538c..e5fb77d 100644 (file)
@@ -67,7 +67,8 @@ _platform_reboot:
            rst 0                       ; bang
 
 ; -----------------------------------------------------------------------------
-; KERNEL MEMORY BANK (below common, only accessible when the kernel is mapped)
+;      We have discard mapped high up so we can map stuff under it
+;      during setup. All of discard gets reclaimed when init is run
 ; -----------------------------------------------------------------------------
             .area _DISCARD
 
@@ -91,11 +92,47 @@ init_early:
 
 init_hardware:
             ; set system RAM size (FIXME - check for 512/1M)
+           ld a,#0x10                  ; Upper 256K
+           call map_page_low
+           ld hl,#0x0000
+           ld (hl),#0xff
+           ld a,(hl)
+           inc a
+           jr nz, is256k
+           ld (hl),a
+           ld a,(hl)
+           or a
+           ld hl,#512
+           jr z, is512k
+is256k:            
             ld hl, #256
+is512k:
             ld (_ramsize), hl
-            ld hl, #(256-96)           ; 64K for kernel, 32K for video/font/etc
+           ld de,#96                   ; 64K for kernel, 32K for video etc
+           sbc hl,de                   ; C is always clear here
             ld (_procmem), hl
 
+           ld a,#VIDEO_LOW
+           call map_page_low           ; Map the video in the low 32K
+
+           ; Place a copy of the high stubs into the video bank so that we
+           ; can in future field interrupts with video mapped. Quite a bit
+           ; of other work is needed for this due to the stack situation.
+           ld hl,#0xFF00
+           ld de,#0x7F00
+           ld bc,#0x100
+           ldir
+
+           call map_kernel_low
+
+           ; Make a copy of the low page somewhere accessible. This may
+           ; change if we decide to make the kernel low page different - eg
+           ; to fast path interrupts in kernel mode. FIXME
+           ld hl,#0x0000
+           ld de,#lowstubs
+           ld bc,#0x0068
+           ldir
+
             im 1 ; set CPU interrupt mode
 
            ; interrupt mask
@@ -159,11 +196,9 @@ _program_vectors:
 
            exx
            ; Copy the stub page into place
-           ; FIXME: doesn't work because our stubs are at 0000. Maybe put
-           ; a copy somewhere else ?
-            ld hl, #stub_page_1 - 1
+            ld hl, #lowstubs
             ld de, #0x0000
-            ld bc, #0x0100
+            ld bc, #0x0068
             ldir
            exx
 
@@ -422,3 +457,7 @@ syscall_sighelp:
            pop hl
            ld h,#0             ; clear signal bit
            ret
+
+           .area _DATA
+lowstubs:
+           .ds 0x68
index 334852b..6eb46f3 100644 (file)
@@ -109,22 +109,67 @@ _plot_char:
        call map_video
        ld bc,#0x04FF           ; it gets decremented by DJNZ while the FF
                                ; ensures the ldi never decrements B
+;
+;      Need to add a slow path version that does colour and effects. Colour
+;      is a matter of masking with FF, CC, 33 or 00.
+;
 plot_loop:
-       ; FIXME: this trick doesn't work on the last row - need a better way
        ldi                     ; copy expanded char
-       ldi
-       dec e
+       ld a,(hl)
+       ld (de),a
+       inc hl
        dec e
        set 7,e                 ; de += 126
        ldi                     ; copy second char row
-       ldi
-       dec e                   ; Similar idea
+       ld a,(hl)
+       ld (de),a
+       inc hl
        dec e                   ; toggle the bit back and gives us
        res 7,e
        inc d                   ; de += 126
        djnz plot_loop
        jr pop_unmap
 
+;
+;      We will need this once we wire in colour support
+;
+plot_slow:
+       ld a,#4
+       exx
+       ld de,(colours)
+       exx
+plot_loop_slow:
+       ex af,af'
+       ld a,(hl)
+       exx
+       ld b,a
+       cpl                     ; background bits
+       and d                   ; to background colour
+       ld c,a
+       ld a,e                  ; foreground bits
+       and b                   ; to foreground colour
+       or c                    ; plus background
+       exx
+       ld (de),a
+       ld a,(hl)
+       inc de
+       inc hl
+       exx
+       ld b,a
+       cpl                     ; background bits
+       and d                   ; to background colour
+       ld c,a
+       ld a,e                  ; foreground bits
+       and b                   ; to foreground colour
+       or c                    ; plus background
+       exx
+       ld (de),a
+       add hl,bc
+       ex af,af'
+       dec a
+       jr nz, plot_loop_slow
+       jr pop_unmap
+
 _clear_lines:
        pop hl
        pop de
@@ -147,7 +192,7 @@ _clear_lines:
        inc de
        dec bc
        ld (hl),#0
-       jr ldir_pop
+       jp ldir_pop
 
 _clear_across:
        pop hl
@@ -198,3 +243,6 @@ _cursor_off:
 _cursor_disable:
 _vtattr_notify:
        ret
+
+colours:
+       .word 0