128k paging BASIC loader

The place for codemasters or beginners to talk about programming any language for the Spectrum.
User avatar
Seven.FFF
Dizzy
Posts: 97
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: 128k paging BASIC loader

Post by Seven.FFF » Fri Dec 08, 2017 6:46 pm

Ast A. Moore wrote:
Fri Dec 08, 2017 6:37 pm
However, if you OUT 32765,17: POKE 23388,17, it’ll page in bank 1 and reset into 48K BASIC, and the bank will stick.
So it does!

Is there a magic way to:
  • be in 128K basic
  • run a program
  • call m/c from the program
  • in that machine code, do the m/c equivalent of OUT 32765,17: POKE 23388,17
  • Frig the sysvars and stack (somehow) to...
  • return to 48K basic, with your program still running, without resetting?
0 x
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
seven-fff.com/blog

Woodster
Berk
Posts: 11
Joined: Mon Nov 13, 2017 12:17 pm

Re: 128k paging BASIC loader

Post by Woodster » Fri Dec 08, 2017 7:46 pm

Seven.FFF wrote:
Fri Dec 08, 2017 3:18 pm
Does Woody's technique stop BASIC changing the top bank back to bank 7, then?
Works fine with the stack in a safe place for paging.

Check out Amaurote's BASIC loader (128K version obviously!) :)

Edit: The bank won't stick if you return to the 128 editor. My original post in this thread was really a suggestion for line 20 of that specific program :)
1 x

User avatar
Ast A. Moore
Microbot
Posts: 150
Joined: Mon Nov 13, 2017 3:16 pm

Re: 128k paging BASIC loader

Post by Ast A. Moore » Fri Dec 08, 2017 8:59 pm

Seven.FFF wrote:
Fri Dec 08, 2017 6:46 pm
Is there a magic way to:
  • be in 128K basic
  • run a program
  • call m/c from the program
  • in that machine code, do the m/c equivalent of OUT 32765,17: POKE 23388,17
  • Frig the sysvars and stack (somehow) to...
  • return to 48K basic, with your program still running, without resetting?
That’s a tall order, brother!

Okay, so let’s doodle a bit:

Code: Select all

	ld a,(23388)	;fetch current value
	and %11111000	;clear bits 0–2 (bank #)
	or 1		;select new bank
	ld bc,32765	;our port
	di		;condom on
	ld (23388),a	;write new value back to sys. var
	out (c),a	;and to port
	ei		;condom off
	ret		;we should be back in BASIC now
This ought to cover everything except
Seven.FFF wrote:
Fri Dec 08, 2017 6:46 pm
  • return to 48K basic, with your program still running, without resetting?
Then again, I’m not sure why you’d want to do that. If you wanted to prevent further bank switching, you could simply set bit 5, but I presume you’re after something else.

Oh, yeah, and as Mark says, mind the ga— I mean, the stack.
1 x
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.

User avatar
R-Tape
Site Admin
Posts: 494
Joined: Thu Nov 09, 2017 11:46 am

Re: 128k paging BASIC loader

Post by R-Tape » Fri Dec 08, 2017 9:03 pm

Just wanted to say thanks all, I'll get the content finished and see if I can use this advice over the weekend.

I'd also like to prove I have tried! I have old notes, and today I added one:

Image

BTW - The main file is too big compressed and spills over 49152, so a simple one load is out. Though I did learn today that zx7 compresses more than just screens!
1 x

AndyC
Berk
Posts: 46
Joined: Mon Nov 13, 2017 5:12 am

Re: 128k paging BASIC loader

Post by AndyC » Sat Dec 09, 2017 12:31 pm

R-Tape wrote:
Fri Dec 08, 2017 12:47 pm
This is the scenario:

Stack below 24064, main code fills 24064 up to the top, including vector table at 65024 in main (=bank 0?) filled with db 253, JPs to interrupt routine at 32768.

Interrupt routine will page in bank 1, call AY music there, then page bank 0 back in.
If you're using an original 128 or +2 that can crash the machine as I will be pointing at contended RAM in the upper 16K, which triggers a hardware bug.
1 x

andydansby
Berk
Posts: 5
Joined: Fri Nov 24, 2017 5:09 pm

Re: 128k paging BASIC loader

Post by andydansby » Sat Dec 09, 2017 6:23 pm

The Mojon Twins have a 128k loader that I use in Xelda.

Code: Select all

; Relocator by Benway

org 25000
memory_to_change defb 0
org 25002

ld a, (memory_to_change)
ld b, a

ld A, (#5B5C)   ; in 5B5C is the current memory page
and #F8
or b
ld (#5B5C), A   ; you have to preserve it, or the BASIC goes crazy

ld BC, #7FFD
out (C), A

ld hl, 32768
ld de, 49152
ld bc, 16384   
ldir      ; we copy 16k from 32768 to 49152 (on the correct page)

; here you go back to 0


ld A, (#5B5C)
and #F8
ld (#5B5C), A

ld BC, #7FFD
out (C), A

ret

Code: Select all

10 BORDER NOT PI:PAPER NOT PI:INK NOT PI:CLEAR VAL "24199": LET D=VAL"25000":LET E=D+2:LOAD""SCREEN$:POKE VAL"23739",CODE"o":LOAD""CODE:LOAD""CODE:POKE D,VAL"1":RANDOMIZE USR E:LOAD""CODE:POKE D,VAL"3":RANDOMIZE USR E:LOAD""CODE:POKE D,VAL"4":RANDOMIZE USR E:LOAD""CODE:POKE D,VAL"6":RANDOMIZE USR E:LOAD""CODE:POKE D,VAL"7":RANDOMIZE USR E:LOAD""CODE:RANDOMIZE USR VAL"24200"
The first assembly part is loaded in after the screen$, followed by the game data in 16k blocks for each of the RAM banks, finally switching in the main RAM loading in 36k

Andy Dansby
2 x

User avatar
R-Tape
Site Admin
Posts: 494
Joined: Thu Nov 09, 2017 11:46 am

Re: 128k paging BASIC loader

Post by R-Tape » Sat Dec 09, 2017 10:14 pm

Hikaru, you have a PM!
0 x

User avatar
Seven.FFF
Dizzy
Posts: 97
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: 128k paging BASIC loader

Post by Seven.FFF » Sun Dec 10, 2017 3:55 pm

Thanks Andy. I’m playing around with your Mojon loader adapting it to TR-Dos.
0 x
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
seven-fff.com/blog

User avatar
Ast A. Moore
Microbot
Posts: 150
Joined: Mon Nov 13, 2017 3:16 pm

Re: 128k paging BASIC loader

Post by Ast A. Moore » Sun Dec 10, 2017 7:04 pm

Seven.FFF wrote:
Sun Dec 10, 2017 3:55 pm
Thanks Andy. I’m playing around with your Mojon loader adapting it to TR-Dos.
Seems a little convoluted to me, switching back and forth between BASIC and custom machine code. Like I said earlier,
Ast A. Moore wrote:
Fri Dec 08, 2017 1:21 pm
I recommend you write a small MC loader and stick it into BASIC. Then run the whole thing with RANDOMIZE USR (PEEK 23635+256*PEEK 23636+5).
NOTE: This is important, because TR-DOS reserves 112 bytes for its variables before the beginning of the BASIC program, so you need to fetch the start address from the PROG system variable (as it won’t be 23755). It’s generally good advice, because some other peripherals might change that value as well.
0 x
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.

User avatar
Seven.FFF
Dizzy
Posts: 97
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: 128k paging BASIC loader

Post by Seven.FFF » Sun Dec 10, 2017 7:45 pm

Ast A. Moore wrote:
Sun Dec 10, 2017 7:04 pm
Seems a little convoluted to me, switching back and forth between BASIC and custom machine code.
Ast A. Moore wrote:
Sun Dec 10, 2017 7:04 pm
NOTE: This is important, because TR-DOS reserves 112 bytes for its variables before the beginning of the BASIC program, so you need to fetch the start address from the PROG system variable (as it won’t be 23755). It’s generally good advice, because some other peripherals might change that value as well.
You could well be right - I;m still fiddling with everything. Cheers for the tip :)
0 x
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
seven-fff.com/blog

Post Reply