Ver código fonte

ufddos80, pun80: make autoinit safer, handle auxmem on stack

Make the autoinit function of ROMs safer by requiring a 0x3d byte
before the JP (0x3c.)

When calling auxilliary ROMs drop the stack to 0xe000 so that those
ROMs can choose to drop the stack further by simply changing (STACK).

Handle auxmem on the stack in PUN80.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
H. Peter Anvin 1 ano atrás
pai
commit
33631727b0

+ 8 - 1
rv32/roms/abc80/asmsrc/print80.inc

@@ -111,7 +111,9 @@ prb_jptable:
 
 	;; Fixed entry points, reserved for future use
 fixfunc:
-	.org 0x4b, 0xff
+	.org 0x4a, 0xff
+	;; Magic number that this entry point is valid
+	dec a
 	;; Init entry point, same offset as in DOS
 	jp start
 
@@ -941,6 +943,11 @@ init:
 	pop hl
 
 	ld de,voldevs
+	;; Are we running with auxram on the stack?
+	bit 7,d
+	jr z,1f
+	ld (STACK),de		; Move down the user stack
+1:
 mk_vols:
 	ld a,(hl)
 	and a

+ 52 - 37
rv32/roms/abc80/asmsrc/ufddos80.asm

@@ -289,6 +289,11 @@ STACK_BASE	= AUXRAM_UFDDOS_BASE
 STACK_BASE	= _DOSBUF0
 	.endif
 
+	;; Use this stack pointer during secondary ROM initialization, so
+	;; those ROMs can change STACK if they want to. This MUST be a
+	;; multiple of 256.
+TMPSTACK	= 0xe000
+
 INIT800:        jp _INIT800             ; 6000 ..d  c3 95 64
 RUNX:           jp _RUNX                ; 6003 ..`  c3 bd 60
 LOADX:          jp _LOADX               ; 6006 .w`  c3 77 60
@@ -1234,13 +1239,13 @@ dosinit80:      ;; 6543 <- 6862
                 ld hl,(DEVLIST)         ; 6567 *..  2a 0a fe
                 ld (DOSDEFDEV),hl       ; 656a "5.  22 35 fd
                 ld hl,(basdevtbl)       ; 656d *.f  2a e4 66
-                ld (DEVLIST),hl         ; 6570 "..  22 0a fe
-setup_stack:    ld hl,STACK_BASE
-                pop de                  ; 6576 .    d1
-                ld sp,hl                ; 6577 .    f9
-                ld (STACK),hl           ; 6578 "'.  22 27 fe
-                push de                 ; 657b .    d5
-                call setup_dosbufs      ; 657c ..h  cd 16 68
+		ld (DEVLIST),hl         ; 6570 "..  22 0a fe
+setup_stack:	pop de			; Copy return address
+		ld hl,TMPSTACK
+		ld sp,hl                ; 6577 .    f9
+		ld h,_DOSBUF0 >> 8	; HL -> DOSBUF0
+		push de			; Restore return address
+                call setup_memvars	; Continuation of this code
                 ld hl,.L65b2            ; 657f !.e  21 b2 65
                 call .L659a             ; 6582 ..e  cd 9a 65
                 ld de,basicerr_sys      ; 6585 .lg  11 6c 67
@@ -1308,6 +1313,7 @@ _BYE:           ;; 65e7 <- 604e 64a0
 ;;;
 ;;; This routine is called by PUN80.
 ;;;
+		.org 0x5f4, 0xff
 bufalloc:       ;; 65f4 <- 661a 6625
                 ld hl,F1_DRVSEL         ; 65f4 !Q.  21 51 fd
                 ld bc,0x0010            ; 65f7 ...  01 10 00
@@ -1343,7 +1349,8 @@ do_open:        ;; 661a <- 6653
                 jr bufinit              ; 6623 ..   18 06
 do_prepare:     ;; 6625 <- 6656
                 call bufalloc           ; 6625 ..e  cd f4 65
-                call PREP               ; 6628 ..`  cd 15 60
+		call PREP               ; 6628 ..`  cd 15 60
+		;;  fall through
 
 ;;;
 ;;; Initialize an IX map and DOS file descriptor
@@ -1351,15 +1358,17 @@ do_prepare:     ;; 6625 <- 6656
 ;;;
 ;;; This routine is called by PUN80.
 ;;;
+		.org 0x62b, 0
 bufinit:        ;; 662b <- 6623
                 ld (ix+12),b            ; 662b .p.  dd 70 0c
                 ld a,b                  ; 662e x    78
-                ;; PUN80 also calls here, so to not need to save/restore BC
+		;; PUN80 also calls here, so to not need to save/restore BC
+		.org 0x62f, 0
 bufreset:       rrca                    ; 662f .    0f
                 rrca                    ; 6630 .    0f
                 rrca                    ; 6631 .    0f
                 rrca                    ; 6632 .    0f
-                add a,0xf5              ; 6633 ..   c6 f5
+                add a,_DOSBUF0 >> 8     ; 6633 ..   c6 f5
                 ld h,a                  ; 6635 g    67
                 ld l,3                  ; 6636 ..   2e 03
                 ld (hl),l               ; 6638 u    75
@@ -1670,26 +1679,26 @@ find_string:    ;; 67fb <- 67e3
                 pop de                  ; 6813 .    d1
                 ld sp,hl                ; 6814 .    f9
                 ret                     ; 6815 .    c9
-setup_dosbufs:  ;; 6816 <- 657c
-                ld hl,_DOSBUF0          ; 6816 !..  21 00 f5
+setup_memvars:
+		;; Called with HL = _DOSBUF0
                 ld (DOSBUFS),hl         ; 6819 "..  22 12 fd
-                ret                     ; 681c .    c9
+		ld hl,STACK_BASE
+		ld (STACK),hl
+		ret                     ; 681c .    c9
 try_init_rom:   ;; 681d <- 6869
-                ld a,(hl)               ; 681d ~    7e
-                inc h                   ; 681e $    24
-                cp 0xc3                 ; 681f ..   fe c3
-                ret nz                  ; 6821 .    c0
-                dec h                   ; 6822 %    25
-                jp (hl)                 ; 6823 .    e9
-                ; Possibly unreachable
-                rst 56                  ; 6824 .    ff
-                rst 56                  ; 6825 .    ff
-                rst 56                  ; 6826 .    ff
-                rst 56                  ; 6827 .    ff
-                rst 56                  ; 6828 .    ff
-err52:          ;; 6829 <- 6fdd
-                basic_err 128+52        ; 6829 ..   d7 b4
+		;; L = 0x4a on entry
+		ld c,(hl)		; 0x3d = DEC A - used as magic number
+		inc l
+		ld a,(hl)
+		inc h
+		cp 0xc3			; 0xc3 = JP
+		ret nz
+		add a,c			; Verify 0x3d + 0xc3 = 0
+		ret nz
+		dec h
+		jp (hl)
 
+		.org 0x82b, 0xff
 ;;; Make space for a 15-byte IX map on the stack,
 ;;; and hack the stack so we return here and clean up
 ;;; the stack.
@@ -1710,20 +1719,20 @@ autostart_setup: ;; 683d <- 6597
                 ldir                    ; 6846 ..   ed b0
                 ret                     ; 6848 .    c9
 autostart:      ;; 6849 <- 686f
-                call S_SCRATCH          ; 6849 .p.  cd 70 0a
-                call S_CHECKCTRLC       ; 684c .>.  cd 3e 03
-                ld (iy+14),1            ; 684f .6.. fd 36 0e 01
+		ld hl,(STACK)
+		ld sp,hl
                 ei                      ; 6853 .    fb
+                call S_SCRATCH          ; 6849 .p.  cd 70 0a
+                call S_CHECKCTRLC       ; Clears ctrl-C, returns with A = 0
+		ld (iy+14),1            ; Command mode
                 ld hl,LINE_BUF          ; 6854 !@.  21 40 fe
-                cp (hl)                 ; 6857 .    be
-                jp nz,S_RUNCMD          ; 6858 ...  c2 f4 00
-                jp S_CMD                ; 685b ...  c3 cc 00
+                jp S_RUNCMD		; 6858 ...  c2 f4 00
 _INIT80:        ;; 685e <- 604b
                 ld (iy+42),0            ; 685e .6*. fd 36 2a 00
                 call dosinit80          ; 6862 .Ce  cd 43 65
                 ld h,0x40               ; 6865 &@   26 40
 .L_init_next:   ;; 6867 <- 6873 6877
-                ld l,0x4b               ; 6867 .K   2e 4b
+                ld l,0x4a               ; 6867 .K   2e 4b
                 call try_init_rom       ; 6869 ..h  cd 1d 68
                 ld a,h                  ; 686c |    7c
                 cp 0x7c                 ; 686d .|   fe 7c
@@ -2830,9 +2839,12 @@ _BLKTF:         ;; 6f75 <- 6042 62d3 6b5b 6c9b 6f79
                 dec a                   ; 6f96 =    3d
                 ret z                   ; 6f97 .    c8
                 add hl,hl               ; 6f98 )    29
-                jr .L6f96               ; 6f99 ..   18 fb
+		jr .L6f96               ; 6f99 ..   18 fb
+	;; To inhibit autostart, set the start command to "NEW" or ";;";
+	;; an empty string will work but will suppress the "ABC80" prompt.
 autostart_cmd:  ;; 6f9b <- 683d
-                .ascii "RUN START80\r"
+		.ascii "RUN START80"
+		.defb 13		; CR = end of command
 		.org 0xfaf, 13
 autostart_cmd_len = . - autostart_cmd
 
@@ -2874,7 +2886,7 @@ _RNDSETUP:
                 ld (RANDIX),ix          ; 6fd5 .".. dd 22 16 fd
                 ld a,(ix+9)             ; 6fd9 .~.  dd 7e 09
                 and a                   ; 6fdc .    a7
-                jp z,err52              ; 6fdd .)h  ca 29 68
+                jr z,err52
                 pop hl                  ; 6fe0 .    e1
                 pop de                  ; 6fe1 .    d1
                 call .L_q0len           ; 6fe2 ..o  cd eb 6f
@@ -2893,6 +2905,9 @@ _RNDSETUP:
                 ld (hl),d               ; 6fee r    72
                 ret                     ; 6fef .    c9
 
+err52:          ;; 6829 <- 6fdd
+                basic_err 128+52        ; 6829 ..   d7 b4
+
 ;;;
 ;;; CALL entry points for random access on ABC80
 ;;;