Skip to content

Commit

Permalink
pentagon: bit more work on this port
Browse files Browse the repository at this point in the history
This gets us to the point we start init, then everything goes a bit pear
shaped.

- Finish loader
- Sort of mappings
- Set video properties correctly for bank 7
- Enable NemoIDE
  • Loading branch information
EtchedPixels committed Jun 18, 2024
1 parent b30d8f2 commit 473dc58
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 62 deletions.
15 changes: 9 additions & 6 deletions Kernel/platform/platform-pentagon/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,18 @@ loader.bin: loader.s
dd if=loader.tmp bs=2048 skip=15 count=1 conv=sync of=loader.bin

image: loader.bin
# Low 16K (will end up in bank 0 0000-3FFF)
dd if=../../common.bin bs=16384 conv=sync skip=0 count=1 of=block0
# Bank 1 (C000-FFFF)
# Common memory 4000-7FFF - bank 5
dd if=../../common.bin bs=16384 conv=sync skip=1 count=1 of=block0
# CODE1 C000-FFFF - bank 0
dd if=../../bank1.bin bs=16384 conv=sync skip=3 count=1 of=block1
# Bank 2 (8000-BFFF)
# Common memory 8000-BFFF - bank 2
dd if=../../common.bin bs=16384 conv=sync skip=2 count=1 of=block2
# Bank 6 (C000-FFFF)
# CODE2 C000-FFFF - bank 6
dd if=../../bank2.bin bs=16384 conv=sync skip=3 count=1 of=block3
# Bank 7 (C000-FFFF)
# CODE3 C000-FFFF - bank 7 (video)
dd if=../../bank3.bin bs=16384 conv=sync skip=3 count=1 of=block4
# CODE4 C000-FFFF - bank 3
dd if=../../bank4.bin bs=16384 conv=sync skip=3 count=1 of=block5

cp base-image.trd fuzix.trd
# Insert 4K loader
Expand All @@ -76,6 +78,7 @@ image: loader.bin
../../tools/trdify fuzix.trd BLOCK2 block2
../../tools/trdify fuzix.trd BLOCK3 block3
../../tools/trdify fuzix.trd BLOCK4 block4
../../tools/trdify fuzix.trd BLOCK5 block5

IMAGES = $(FUZIX_ROOT)/Images/$(TARGET)

Expand Down
16 changes: 9 additions & 7 deletions Kernel/platform/platform-pentagon/README
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Then it gets more complicated (and the partial decode ports make it worse)

Pentagon uses bits 7/6 to allow for 512K RAM

ATM us FDFD bits 0-2
ATM uses FDFD bits 0-2

----
These machines all have the same basic problem, there is a 16K window at
Expand All @@ -25,16 +25,18 @@ We run with the following mapping
8400-BFFF _DISCARD area - blown away when we exec init
(tons of room in this space)
C000-FFFF
0: Kernel CODE4 (lot of room)
1: Kernel CODE (fairly full)
0: Kernel CODE1
1: Kernel CODE2
2: Mapped at 0x8000-0xBFFF (holds current process copy)
3: User process
3: kernel CODE4
4: User process
5: Mapped at 0x4000-0x7FFF (kernel data/common)
6: Kernel CODE2 (fairly full)
7: CODE3, Video (fairly full)
6: User process
7: Kernel CODE3, Video
8-15: User process
(32-63: User process on 512K machine)

User processes live in 3/4 and 8+. We have copy stuff back and forth
User processes live in 4/6 and 8+. We have copy stuff back and forth
to page 2 due to the memory manager limits.

To Do:
Expand Down
22 changes: 22 additions & 0 deletions Kernel/platform/platform-pentagon/crt0.s
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,29 @@
.include "kernel.def"
.include "../../cpu-z80/kernel-z80.def"

.area _DISCARD

; Discard starts with the initial bootstrap
ld bc,#0x7ffd
ld a,#0x14
out (c),a ; map the temporary buffer
ld hl,#0xC000
ld de,#0x4000
ld b,d
ld c,e
ldir ; into position 4000-7FFF

; Switch to bank 0 (code 1)
ld a,#0x08
ld bc,#0x7ffd
out (c),a

jp go


.area _CODE1

go:
; startup code
;
; Entered from the bootstrap with 0-3FFF mapped and loaded as
Expand Down
2 changes: 1 addition & 1 deletion Kernel/platform/platform-pentagon/devices.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ bool validdev(uint16_t dev)
void device_init(void)
{
#ifdef CONFIG_TD_IDE
// ide_probe();
ide_probe();
#endif
#ifdef CONFIG_TD_SD
sd_probe();
Expand Down
20 changes: 16 additions & 4 deletions Kernel/platform/platform-pentagon/discard.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ extern uint8_t fuller, kempston, kmouse, kempston_mbmask;
void pagemap_init(void)
{
uint8_t i;
pagemap_add(3);
pagemap_add(4);

/* Pentagon uses 7FFD as follows
7: 256K
Expand All @@ -21,11 +19,25 @@ void pagemap_init(void)
0: 16K
The 1MB one uses bit 5 for 512K */

/* Add the rest of the first 256K */
pagemap_add(0x04);
pagemap_add(0x06);

/* 128-256K */
for (i = 0; i < 8; i++)
pagemap_add(0x40|i);
/* If we deal with Scorpion and friends then we have to use
1FFD bits 4-7 for the high bits instead */

/* TODO: enable 512K support in pentagon.s */
if (ramsize == 512) {
for (i = 0; i < 8; i++) {
pagemap_add(0x80|i);
pagemap_add(0xC0|i);
}
}
/* TODO: 512K is more complex.
- Pentagon 512 uses bits 7/6/2/1/0
- ATM uses FDFD bits 2-0 */
}

/* string.c
Expand Down
4 changes: 2 additions & 2 deletions Kernel/platform/platform-pentagon/kernel.def
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ PROGLOAD .equ 0x8000

NBUFS .equ 5

BANK_BITS .equ 0x10 ; Spectrum ROM select
; Doesn't really matter!
BANK_BITS .equ 0x18 ; Spectrum ROM select
; Video at 0xC000
55 changes: 30 additions & 25 deletions Kernel/platform/platform-pentagon/loader.s
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
;
; The disk holds files of the format code{n} where n is the bank to
; place it in. TRDOS is asked to load the lot and then we launch
;
; The on disk layout is
;
; 16K common (0x4000-0x7FFF) Bank 5 (loaded via 4)
; 16K bank (0xC000-0xFFFF) Bank 0 (CODE1)
; 16K common (0x8000-0xBFFF) Bank 2
; 16K bank (0xC000-0xFFFF) Bank 1 (CODE2)
; 16K bank (0xC000-0xFFFF) Bank 7 (CODE3)
; 16K bank (0xC000-0xFFFF) Bank 3 (CODE4)
;
;

.module loader
Expand All @@ -11,39 +21,34 @@

start:
ld sp,#start
xor a

ld a,#4 ; common 4000-7FFF temporary copy
ld de,#0x0109
call trdos ; bank 0 (will appear at 0x0000)
inc a
call trdos

xor a ; code 1 into bank 0
ld de,#0x0509
call trdos ; bank 1 (high bank CODE1)
inc a
call trdos

ld a,#2 ; common 8000-BFFF into bank 2
ld de,#0x0909
call trdos ; bank 2 (0x8000-0xBFFF bank)
ld a,#6
call trdos

ld a,#1 ; code 2 into bank 1
ld de,#0x0D09
call trdos ; bank 6 (high bank CODE2)
inc a
call trdos

ld a,#7 ; code 3 into bank 7
ld de,#0x1109
call trdos ; bank 7 (high bank CODE3)
call trdos

ld a,#3 ; code 4 into bank 3
ld de,#0x1509
call trdos

di
; Turn off low ROM
; Some older systems want 0x1FFD bit 0 instead FIXME
ld bc,#0xeff7
ld a,#0x08
out (c),a
; The kernel is loaded into 1,6,7
; The low memory is loaded into bank 0
; The 8000-BFFF range is loaded by the loader
; The 4000-7FFF range is zero

; Switch ROM for bank 0
ld a,#0x01
ld bc,#0x7ffd
out (c),a
; FIXME - where is best to start up
jp 0xC000
jp 0x8400 ; into loaded bootstrap

trdos:
; Switch bank
Expand Down
60 changes: 44 additions & 16 deletions Kernel/platform/platform-pentagon/pentagon.s
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
; 7 CODE 3 + VIDEO + FONTS
; 2/5 4000-BFFF (common and user low buffer)
;
; 4 Free
; 4/6 Free
; 8+ Free
;

Expand Down Expand Up @@ -148,6 +148,44 @@ init_early:
out (0xFE),a
ret

.area _COMMONMEM
;
; Set interrupt vectors in each bank. Run from discard
; so we don't page ourself out

_program_vectors:
pop bc
pop de
pop hl ; task page ptr
push hl
push de
push bc
ld a, (hl) ; high page of the pair

setvectors:
call map_save_kernel
call switch_bank
ld a, #0x18
ld (0xffff), a ; JR (plus ROM at 0 gives JR $FFF4)
ld a, #0xC3 ; JP
ld (0xFFF4), a ; FFF4-6 are the interrupt vector
ld (0xFFF7), a ; FFF7-9 are syscall
ld hl, #interrupt_handler
ld (0xFFF5), hl ; to IRQ handler
call map_restore
ret

setallvectors:
xor a ; bank 0 (CODE 1)
call setvectors
ld a, #1 ; bank 1 (CODE 2)
call setvectors
ld a, #7 ; bank 7 (CODE 3 / VIDEO)
call setvectors
ld a, #3 ; bank 3 (CODE 4)
jr setvectors


.area _VIDEO

init_hardware:
Expand All @@ -161,24 +199,17 @@ init_hardware:
; 2: 4000-7FFF (screen and buffers)
; 3: fourth kernel bank at C000
; 5: 8000-BFFF (working 16K copy)
; 6: second kernel bank at C000
; 7: third kernel bank at C000
;
ld hl, #(256 - 96)
ld (_procmem), hl

;
; No low RAM so need IM2 and custom syscall interface
; (will need to tackle that nicely in libc too)
;
; Set up the vectors on all the kernel pages
; user will be set up as we go
push af
call setallvectors
pop af

ld a,#0xC3
ld (0xFFFD),a
ld (0xFFF4),a
ld hl,#unix_syscall_entry
ld (0xFFFE),hl
ld hl,#interrupt_handler
ld (0xFFF5),hl
; screen initialization
push af
call _vtinit
Expand All @@ -195,9 +226,6 @@ init_hardware:

.area _COMMONMEM

_program_vectors:
ret

; Swap helper. Map the page in A into the address space such
; that swap_map() gave the correct pointer to use. Undone by
; a map_kernel_{restore}
Expand Down
2 changes: 1 addition & 1 deletion Kernel/platform/platform-pentagon/zxvideo.s
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
; Build the video library as the only driver

ZXVID_ONLY .equ 1
SCREENBASE .equ 0x40
SCREENBASE .equ 0xC0

.area _VIDEO

Expand Down

0 comments on commit 473dc58

Please sign in to comment.